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

v0.3.0-unstable.10

Published

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

Downloads

10,267

Readme

did-key-ed25519

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

Usage

Generate

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

Export

import { Ed25519KeyPair } from '@transmute/did-key-ed25519';
const k = await Ed25519KeyPair.generate({
  secureRandom: () => {
    return Buffer.from(
      '4f66b355aa7b0980ff901f2295b9c562ac3061be4df86703eb28c612faae6578',
      'hex'
    );
  },
});
const exportedKeyPair = await k.export({
  type: 'JsonWebKey2020',
  privateKey: true,
});

Resolve

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

Verifiable Credentials

Ed25519Signature2018

This suite shipped in https://www.w3.org/2018/credentials/v1 so no additional context is needed.

import { ld as vcjs } from '@transmute/vc.js';
import { Ed25519KeyPair } from '@transmute/did-key-ed25519';
import {
  Ed25519Signature2018,
  Ed25519VerificationKey2018,
} from '@transmute/ed25519-signature-2018';

const k = await Ed25519KeyPair.generate({
  secureRandom: () => {
    return Buffer.from(
      '4f66b355aa7b0980ff901f2295b9c562ac3061be4df86703eb28c612faae6578',
      'hex'
    );
  },
});

const suite = new Ed25519Signature2018({
  key: await Ed25519VerificationKey2018.from(
    await k.export({
      type: 'Ed25519VerificationKey2018',
      privateKey: true,
    })
  ),
  date: '2020-03-10T04:24:12Z',
});

const vc = await vcjs.issue({
  credential: {
    '@context': ['https://www.w3.org/2018/credentials/v1'],
    id: 'http://example.gov/credentials/3732',
    type: ['VerifiableCredential'],
    issuer: {
      id: k.controller,
    },
    issuanceDate: '2020-03-10T04:24:12.164Z',
    credentialSubject: {
      id: 'did:example:ebfeb1f712ebc6f1c276e12ec21',
    },
  },
  suite,
  documentLoader,
});

JsonWebSignature2020

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 { Ed25519KeyPair } from '@transmute/did-key-ed25519';
import { JsonWebSignature, JsonWebKey } from '@transmute/json-web-signature';

const k = await Ed25519KeyPair.generate({
  secureRandom: () => {
    return Buffer.from(
      '4f66b355aa7b0980ff901f2295b9c562ac3061be4df86703eb28c612faae6578',
      'hex'
    );
  },
});

const suite = new JsonWebSignature({
  key: await JsonWebKey.from(
    await k.export({
      type: 'Ed25519VerificationKey2018',
      privateKey: true,
    })
  ),
  date: '2020-03-10T04:24:12Z',
});

const vc = await vcjs.issue({
  credential: {
    '@context': [
      'https://www.w3.org/2018/credentials/v1',
      // 🧙‍♂️ This extension context is required.
      'https://w3id.org/security/suites/jws-2020/v1',
    ],
    id: 'http://example.gov/credentials/3732',
    type: ['VerifiableCredential'],
    issuer: {
      id: k.controller,
    },
    issuanceDate: '2020-03-10T04:24:12.164Z',
    credentialSubject: {
      id: 'did:example:ebfeb1f712ebc6f1c276e12ec21',
    },
  },
  suite,
  documentLoader,
});

JOSE

EdDSA

import { Ed25519KeyPair } from '@transmute/did-key-ed25519';
import { JWS } from '@transmute/jose-ld';

const k = await Ed25519KeyPair.generate({
  secureRandom: () => {
    return Buffer.from(
      '4e61bc1918ea6a47ae3307331be7798196a1a8e7cfe4b6e8f7c9a5f36017d929',
      'hex'
    );
  },
});
const JWA_ALG = 'EdDSA';
const signer = JWS.createSigner(k.signer('EdDsa'), JWA_ALG);
const verifier = JWS.createVerifier(k.verifier('EdDsa'), JWA_ALG);
const message = Uint8Array.from(Buffer.from('hello'));
const signature = await signer.sign({ data: message });
const verified = await verifier.verify({
  signature,
});

Representations

application/did+json

See application/did+json

application/did+ld+json

See application/did+ld+json