npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@transmute/did-key-bls12381

v0.3.0-unstable.10

Published

``` npm i @transmute/did-key-bls12381@latest --save ```

Downloads

1,367

Readme

did-key-bls12381

npm i @transmute/did-key-bls12381@latest --save

Usage

Generate

import crypto from 'crypto';
import * as bls12381 from '@transmute/did-key-bls12381';
const { didDocument, keys } = await bls12381.generate(
  {
    secureRandom: () => {
      return Uint8Array.from(crypto.randomBytes(32));
    },
  },
  { accept: 'application/did+json' }
);

Export

import { Bls12381KeyPairs } from '@transmute/did-key-bls12381';
const keys = await Bls12381KeyPairs.generate({
  secureRandom: () => {
    return Uint8Array.from(
      Buffer.from(
        '5a2b1f37ecc9fb7f27e1aa3daa4d66d9c3e54a4c0dcd53a4a5cacdfaf50578cb',
        'hex'
      )
    );
  },
});
const g1 = await keys.g1KeyPair.export({
  type: 'JsonWebKey2020',
  privateKey: true,
});
const g2 = await keys.g2KeyPair.export({
  type: 'JsonWebKey2020',
  privateKey: true,
});

BbsBlsSignature2020 and BbsBlsSignatureProof2020

This suite was created after https://www.w3.org/2018/credentials/v1 so it must be added to the credential context.

import { ld as vcjs } from '@transmute/vc.js';
import * as bls12381 from '@transmute/did-key-bls12381';

import {
  Bls12381G2KeyPair,
  BbsBlsSignature2020,
  BbsBlsSignatureProof2020,
  deriveProof,
} from '@mattrglobal/jsonld-signatures-bbs';

const keys = await bls12381.Bls12381KeyPairs.generate({
  secureRandom: () => {
    return Uint8Array.from(
      Buffer.from(
        '5a2b1f37ecc9fb7f27e1aa3daa4d66d9c3e54a4c0dcd53a4a5cacdfaf50578cb',
        'hex'
      )
    );
  },
});
const g2 = await keys.g2KeyPair.export({
  type: 'Bls12381G2Key2020',
  privateKey: true,
});

const key = await Bls12381G2KeyPair.from(g2);

const suite = new BbsBlsSignature2020({
  key,
  date: '2021-06-19T18:53:11Z',
});

const verifiableCredential = await vcjs.issue({
  credential: {
    '@context': [
      'https://www.w3.org/2018/credentials/v1',
      // 🧙‍♂️ This extension context is required.
      'https://w3id.org/security/suites/bls12381-2020/v1',
    ],
    id: 'http://example.gov/credentials/3732',
    type: ['VerifiableCredential'],
    issuer:
      'did:key:z5TcEUwEFkVuVhRpBinQrCgAtSmtQxyajQvpjma5TnWedYqJNXKYvS3UA4rrAkqfMm9VnhiZAf9gpqj7DJDsUJTAJkisUNbenUy64kitTduKihxQb4ScGb1XfRHzMMJWBQa7o7ar46ACzdfW4oqzpnj8gqLH2fjQF82LQACATNc3pXem8chkM7vEQKHKcK2HHK8tbVdfP',
    issuanceDate: '2021-06-19T18:53:11Z',
    credentialSubject: {
      id: 'did:example:ebfeb1f712ebc6f1c276e12ec21',
    },
  },
  suite,
  documentLoader,
});

const frame = {
  '@context': [
    'https://www.w3.org/2018/credentials/v1',
    'https://w3id.org/security/suites/bls12381-2020/v1',
  ],
  type: ['VerifiableCredential'],
  credentialSubject: {
    '@explicit': true,
    id: {},
  },
};

const derivedVerifiableCredential = await deriveProof(
  verifiableCredential,
  frame,
  {
    suite: new BbsBlsSignatureProof2020(),
    documentLoader: async (iri: string) => {
      if (iri.startsWith('did:key:z5T')) {
        const { didDocument } = await bls12381.resolve(iri, {
          accept: 'application/did+ld+json',
        });
        return {
          document: didDocument,
        };
      }
      return documentLoader(iri);
    },
  }
);

const verifiablePresentation = await vcjs.signPresentation({
  presentation: {
    // note that this is required because BBS+ is not in credentials/v1
    '@context': derivedVerifiableCredential['@context'],
    type: ['VerifiablePresentation'],
    holder: g2.controller,
    verifiableCredential: [derivedVerifiableCredential],
  },
  challenge: 'nonce-123',
  domain: 'example.com',
  suite, // BbsBlsSignature2020 NOT BbsBlsSignatureProof2020
  documentLoader,
});

const verification = await vcjs.verify({
  presentation: verifiablePresentation,
  challenge: 'nonce-123',
  domain: 'example.com',
  suiteMap: {
    BbsBlsSignature2020,
    BbsBlsSignatureProof2020,
  },
  documentLoader: async (iri: string) => {
    if (iri.startsWith('did:key:z5T')) {
      const { didDocument } = await bls12381.resolve(iri, {
        accept: 'application/did+ld+json',
      });
      return {
        document: didDocument,
      };
    }
    return documentLoader(iri);
  },
});

Resolve

import * as bls12381 from '@transmute/did-key-bls12381';
const {
  didDocument,
} = await bls12381.resolve(
  'did:key:z5TcEUwEFkVuVhRpBinQrCgAtSmtQxyajQvpjma5TnWedYqJNXKYvS3UA4rrAkqfMm9VnhiZAf9gpqj7DJDsUJTAJkisUNbenUy64kitTduKihxQb4ScGb1XfRHzMMJWBQa7o7ar46ACzdfW4oqzpnj8gqLH2fjQF82LQACATNc3pXem8chkM7vEQKHKcK2HHK8tbVdfP',
  { accept: 'application/did+json' }
);

Representations

application/did+json

See application/did+json

application/did+ld+json

See application/did+ld+json