@trustvc/w3c-issuer
TypeScript icon, indicating that this package has built-in type declarations

1.2.1 • Public • Published

TrustVC W3C Issuer

A library to facilitate the creation of Decentralized Identifiers DIDs v1, specifically did:web, for the signing of Verifiable Credentials v1.1.

Installation

To install the package, use:

npm install @trustvc/w3c-issuer

Features

  • Create private key pairs for specific Signature Suites used for signing Verifiable Credentials (e.g., BBS).
  • Generate DID private key pairs and DID documents.


Usage

1. Create Private Key

generateKeyPair function helps to generate a signature Key Pair.

import { generateKeyPair, VerificationType } from '@trustvc/w3c-issuer';

/**
 * Parameters:
 * - options (GenerateKeyPairOptions)
 * - options.type (VerificationType): Key Pair algo type for Signature
 * - options.seedBase58? (string): 32 byte base58 encoded seed (e.g. FVj12jBiBUqYFaEUkTuwAD73p9Hx5NzCJBge74nTguQN) (optional)
 * - options.privateKeyBase58? (string): private key value (optional)
 * - options.publicKeyBase58? (string): public key value (optional)
 * 
 * Returns:
 * - A Promise that resolves to:
 *   - generatedKeyPair.type (VerificationType): Key Pair algo.
 *   - generatedKeyPair.seedBase58 (string): 32 byte base58 encoded seed
 *   - generatedKeyPair.privateKeyBase58 (string): Derieve private key from seed
 *   - generatedKeyPair.publicKeyBase58 (string): Detrieve public key from seed
 */ 

const options = {
  type: VerificationType.Bls12381G2Key2020,
  seedBase58: undefined
}

const generatedKeyPair = await generateKeyPair(options);
console.log('generatedKeyPair: ', generatedKeyPair)
generatedKeyPair Result
generatedKeyPair: {
  type: 'Bls12381G2Key2020',
  seedBase58: '<seedBase58>',
  privateKeyBase58: '<privateKeyBase58',
  publicKeyBase58: 'oRfEeWFresvhRtXCkihZbxyoi2JER7gHTJ5psXhHsdCoU1MttRMi3Yp9b9fpjmKh7bMgfWKLESiK2YovRd8KGzJsGuamoAXfqDDVhckxuc9nmsJ84skCSTijKeU4pfAcxeJ'
}

2. Generate DID Key Pair and DID Document

issueDID function helps to generate did:web DID Document, together with the DID Private Key Pair.

(wellKnownDid) did:web DID Document needs to be hosted.
Read here for more instructions.

(didKeyPairs) DID Private Key Pair needs to be kept securely. Required for signing Verifiable Credential.
Read here for more signing instructions.

import { VerificationType, issueDID } from '@trustvc/w3c-issuer';

/**
 * Parameters:
 * - options (IssuedDIDOption)
 * - options.domain (string): URL where the DID Document will be located
 * - options.type (VerificationType): Key Pair algo.
 * - options.seedBase58? (string): 32 byte base58 encoded seed (optional)
 * - options.privateKeyBase58? (string): Derieved private key from seed (optional)
 * - options.publicKeyBase58? (string): Detrieved public key from seed (optional)
 *
 * Returns:
 * - A Promise that resolves to:
 *   - issuedDID.wellKnownDid (DidWellKnownDocument): DID Document generated for the specified domain
 *   - issuedDID.didKeyPairs (PrivateKeyPair): DID Key Pair containing key id and controller
 */

const options = {
  domain: 'https://example.com/.well-known/did.json',
  type: VerificationType.Bls12381G2Key2020,
  seedBase58: '<seedBase58>',
  privateKeyBase58: '<privateKeyBase58>',
  publicKeyBase58: 'oRfEeWFresvhRtXCkihZbxyoi2JER7gHTJ5psXhHsdCoU1MttRMi3Yp9b9fpjmKh7bMgfWKLESiK2YovRd8KGzJsGuamoAXfqDDVhckxuc9nmsJ84skCSTijKeU4pfAcxeJ'
}

const issuedDID = await issueDID(options);

const { wellKnownDid, didKeyPairs } = issuedDID;
console.log("wellKnownDid:", wellKnownDid)
console.log("didKeyPairs:", didKeyPairs)
issueDID Result
wellKnownDid: {
  id: 'did:web:example.com',
  verificationMethod: [
    {
      type: 'Bls12381G2Key2020',
      id: 'did:web:example.com#keys-1',
      controller: 'did:web:example.com',
      publicKeyBase58: 'oRfEeWFresvhRtXCkihZbxyoi2JER7gHTJ5psXhHsdCoU1MttRMi3Yp9b9fpjmKh7bMgfWKLESiK2YovRd8KGzJsGuamoAXfqDDVhckxuc9nmsJ84skCSTijKeU4pfAcxeJ'
    }
  ],
  '@context': [
    'https://www.w3.org/ns/did/v1',
    'https://w3id.org/security/suites/bls12381-2020/v1'
  ],
  authentication: [ 'did:web:example.com#keys-1' ],
  assertionMethod: [ 'did:web:example.com#keys-1' ],
  capabilityInvocation: [ 'did:web:example.com#keys-1' ],
  capabilityDelegation: [ 'did:web:example.com#keys-1' ]
}
didKeyPairs: {
  id: 'did:web:example.com#keys-1',
  type: 'Bls12381G2Key2020',
  controller: 'did:web:example.com',
  seedBase58: '<seedBase58>',
  privateKeyBase58: '<privateKeyBase58>',
  publicKeyBase58: 'oRfEeWFresvhRtXCkihZbxyoi2JER7gHTJ5psXhHsdCoU1MttRMi3Yp9b9fpjmKh7bMgfWKLESiK2YovRd8KGzJsGuamoAXfqDDVhckxuc9nmsJ84skCSTijKeU4pfAcxeJ'
}

Dependencies (5)

Dev Dependencies (0)

    Package Sidebar

    Install

    npm i @trustvc/w3c-issuer

    Weekly Downloads

    309

    Version

    1.2.1

    License

    Apache-2.0

    Unpacked Size

    45.1 kB

    Total Files

    48

    Last publish

    Collaborators

    • imda.trustvc
    • nghaninn