Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@identity.com/cryptid

Package Overview
Dependencies
Maintainers
13
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@identity.com/cryptid

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

  • 0.1.2
  • npm
  • Socket score

Version published
Weekly downloads
222
decreased by-57.63%
Maintainers
13
Weekly downloads
 
Created
Source

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/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

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

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

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

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,
});

// 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);

FAQs

Package last updated on 03 Nov 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc