Cryptid
The Cryptid client library provides functionality for signing transactions and managing Cryptid DID wallets.
Install
npm i --save @identity.com/cryptid
Usage
Creating a Cryptid instance
This example shows creating a new keypair, and a Cryptid instance.
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');
const key = Keypair.generate();
const did = util.publicKeyToDid(key.publicKey, 'devnet');
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
const pubKey = Keypair.generate().publicKey;
const keyAlias = 'mobile';
await cryptid.addKey(pubKey, keyAlias);
await cryptid.removeKey(keyAlias);
Managing Services
const serviceAlias = 'domains';
await cryptid.addService({
id: `${did}#${serviceAlias}`,
type: serviceAlias,
serviceEndpoint: 'https://example.com',
description: 'Domains'
});
await cryptid.removeService(serviceAlias);
Managing Controllers
const controllerDid = 'did:sol:devnet:GxsFhrQNMU4HDgJ69vvYUmnzwzXNEve4tskCqTx7SsHK';
await cryptid.addController(controllerDid);
await cryptid.removeController(controllerDid);
Retrieving the DID document
const didDocument = await cryptid.document();
Usage Examples
Signing a transaction
An example of using Cryptid to sign a transaction to send
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.
const cryptid = build(controllerDID, controllerDidKey, {
connection,
waitForConfirmation: true,
});
const controllerCryptid = cryptid.as(controlledDID);
const {blockhash: recentBlockhash} = await connection.getRecentBlockhash();
const tx = new Transaction({recentBlockhash, feePayer: controlledCryptidAddress}).add(
SystemProgram.transfer({
fromPubkey: controlledCryptidAddress,
toPubkey: recipient,
lamports: lamportsToTransfer,
})
);
const txSignedByController = await controllerCryptid.sign(tx);