# @identity.com/cryptid

> The Cryptid client library provides functionality for signing transactions and managing Cryptid DID wallets.

Latest version **0.2.0** (published 2022-06-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install @identity.com/cryptid
pnpm add @identity.com/cryptid
yarn add @identity.com/cryptid
bun add @identity.com/cryptid
```

## Health

**Score 30/100 (F)** — status: abandoned.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2022-06-01 |
| First published | 2021-10-15 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=10 |
| Dependencies | 7 |
| Unpacked size | 915.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | identity.com |
| Maintainers | diosakhilleus, chriteixeira, rado0x54, araptarchis, mitchcivic, identity.com-ci, dankelleher, flippiescholtz, kevinhcolgan, pbshoemaker, tyronemichael, lucmir, william-identity |

## Links

- npm: https://www.npmjs.com/package/@identity.com/cryptid
- npm.io page: https://npm.io/package/@identity.com/cryptid

## Dependencies (7)

- [borsh](https://npm.io/package/borsh.md) ^0.6.0
- [ramda](https://npm.io/package/ramda.md) ^0.28.0
- [uint8arrays](https://npm.io/package/uint8arrays.md) ^3.0.0
- [@types/ramda](https://npm.io/package/@types/ramda.md) ^0.28.0
- [did-resolver](https://npm.io/package/did-resolver.md) ^3.1.0
- [@solana/web3.js](https://npm.io/package/@solana/web3.js.md) ^1.27.0
- [@identity.com/sol-did-client](https://npm.io/package/@identity.com/sol-did-client.md) ^2.0.0

## Recent versions

- 0.2.0 (latest) — 2022-06-01
- 0.3.0-alpha.11 (alpha) — 2022-11-02
- 0.3.0-alpha.10 — 2022-10-26
- 0.3.0-alpha.9 — 2022-10-03
- 0.3.0-alpha.8 — 2022-09-26
- 0.3.0-alpha.7 — 2022-09-26
- 0.3.0-alpha.6 — 2022-09-26
- 0.3.0-alpha.5 — 2022-09-22
- 0.3.0-alpha.4 — 2022-09-22
- 0.3.0-alpha.3 — 2022-09-20
- 0.3.0-alpha.2 — 2022-09-20
- 0.3.0-alpha.1 — 2022-09-20
- 0.1.2 — 2021-11-03
- 0.1.1 — 2021-10-28
- 0.1.0 — 2021-10-15

## README

# Cryptid

The Cryptid client library provides functionality for signing transactions and managing Cryptid DID wallets.

# Install

```sh
npm i --save @identity.com/cryptid
```

# Usage

## Creating a Cryptid instance

This example shows creating a new keypair, and a Cryptid instance.

```javascript
import {Connection, Keypair, LAMPORTS_PER_SOL, SystemProgram, Transaction} from '@solana/web3.js';
import { build, util } from '@identity.com/cryptid';

const connection = new Connection(clusterApiUrl('devnet'), 'confirmed');

// Create (or provide) a Solana keypair
const key = Keypair.generate();
const did = util.publicKeyToDid(key.publicKey, 'devnet');

// Create the Cryptid instance
const cryptid = build(did, key, {
  connection,
  waitForConfirmation: true,
});
```

*Note* both accounts would need to be funded (e.g. via an Airdrop)

## Cryptid Account Management

### Managing Keys

```javascript
const pubKey = Keypair.generate().publicKey;
const keyAlias = 'mobile';

// Add a key to the Cryptid account
await cryptid.addKey(pubKey, keyAlias);

// Remove a key from the Cryptid account
await cryptid.removeKey(keyAlias);
```

### Managing Services

```javascript
const serviceAlias = 'domains';

// Add a service to a Cryptid account
await cryptid.addService({
  id: `${did}#${serviceAlias}`,
  type: serviceAlias,
  serviceEndpoint: 'https://example.com',
  description: 'Domains'
});

// Remove a service from the Cryptid account
await cryptid.removeService(serviceAlias);
```

### Managing Controllers

```javascript
const controllerDid = 'did:sol:devnet:GxsFhrQNMU4HDgJ69vvYUmnzwzXNEve4tskCqTx7SsHK';

// Add a controller to the Cryptid account
await cryptid.addController(controllerDid);

// Remove a controller from Cryptid acccount
await cryptid.removeController(controllerDid);
```

### Retrieving the DID document

```javascript
const didDocument = await cryptid.document();
```

## Usage Examples

### Signing a transaction
An example of using Cryptid to sign a transaction to send
```javascript
const {blockhash: recentBlockhash} = await connection.getRecentBlockhash();
const transferTx = new Transaction({recentBlockhash, feePayer: cryptidAddress}).add(SystemProgram.transfer({
  fromPubkey: cryptidAddress,
  toPubkey: recipient,
  lamports: lamportsToTransfer,
}));

const [cryptidTransferTx] = await cryptid.sign(transferTx);

const transferTxSignature = await connection.sendRawTransaction(cryptidTransferTx.serialize());
await connection.confirmTransaction(transferTxSignature);
```

### Controller relationship
This example shows how a Cryptid account can control and transact on behalf of another Cryptid account.

```javascript
const cryptid = build(controllerDID, controllerDidKey, {
  connection,
  waitForConfirmation: true,
});

// Create the controller Cryptid instance
const controllerCryptid = cryptid.as(controlledDID);

// Create a transaction from the controlled Cryptid instance
const {blockhash: recentBlockhash} = await connection.getRecentBlockhash();
const tx = new Transaction({recentBlockhash, feePayer: controlledCryptidAddress}).add(
  SystemProgram.transfer({
    fromPubkey: controlledCryptidAddress,
    toPubkey: recipient,
    lamports: lamportsToTransfer,
  })
);

// Sign the transaction with the controller Cryptid instance
const txSignedByController = await controllerCryptid.sign(tx);
```

---
_Source: https://npm.io/package/@identity.com/cryptid · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
