Package detail

@digitalbazaar/ed25519-verification-key-2018

digitalbazaar12.3kBSD-3-Clause4.0.0

A library for generating and working with Ed25519 key pairs, for use with crypto-ld.

Decentralized, DID, Credential, Cryptography

readme

Ed25519VerificationKey2018 Key Pair Library for Linked Data (@digitalbazaar/ed25519-verification-key-2018)

Node.js CI

Javascript library for generating and working with Ed25519VerificationKey2018 key pairs, for use with crypto-ld.

Table of Contents

Background

See also (related specs):

Security

As with most security- and cryptography-related tools, the overall security of your system will largely depend on your design decisions.

Install

  • Node.js 14+ is required.

To install locally (for development):

git clone https://github.com/digitalbazaar/ed25519-verification-key-2018.git
cd ed25519-verification-key-2018
npm install

Usage

Generating a new public/private key pair

To generate a new public/private key pair:

  • {string} [controller] Optional controller URI or DID to initialize the generated key. (This will also init the key id.)
  • {string} [seed] Optional deterministic seed value from which to generate the key.
import {Ed25519VerificationKey2018} from '@digitalbazaar/ed25519-verification-key-2018';

const edKeyPair = await Ed25519VerificationKey2018.generate();

Importing a key pair from storage

To create an instance of a public/private key pair from data imported from storage, use .from():

const serializedKeyPair = { ... };

const keyPair = await Ed25519VerificationKey2018.from(serializedKeyPair);

Note that only installed key types are supported, if you try to create a key pair via from() for an unsupported type, an error will be thrown.

Exporting the public key only

To export just the public key of a pair:

await keyPair.export({publicKey: true});
// ->
{ 
  id: 'did:ex:123#z6MkumafR1duPR5FZgbVu8nzX3VyhULoXNpq9rpjhfaiMQmx',
  controller: 'did:ex:123',
  type: 'Ed25519VerificationKey2018',
  publicKeyBase58: 'GKKcpmPU3sanTBkoDZq9fwwysu4x7VaUTquosPchSBza'
}
*/

Exporting the full public-private key pair

To export the full key pair, including private key (warning: this should be a carefully considered operation, best left to dedicated Key Management Systems):

await keyPair.export({publicKey: true, privateKey: true});
// ->
{
  id: 'did:ex:123#z6Mks8wJbzhWdmkQZgw7z2qHwaxPVnFsFmEZSXzGkLkvhMvL',
  controller: 'did:ex:123',
  type: 'Ed25519VerificationKey2018',
  publicKeyBase58: 'DggG1kT5JEFwTC6RJTsT6VQPgCz1qszCkX5Lv4nun98x',
  privateKeyBase58: 'sSicNq6YBSzafzYDAcuduRmdHtnrZRJ7CbvjzdQhC45ewwvQeuqbM2dNwS9RCf6buUJGu6N3rBy6oLSpMwha8tc'
}

Generating and verifying key fingerprint

To generate a fingerprint:

keyPair.fingerprint();
// ->
'z6Mks8wJbzhWdmkQZgw7z2qHwaxPVnFsFmEZSXzGkLkvhMvL'

To verify a fingerprint:

const fingerprint = 'z6Mks8wJbzhWdmkQZgw7z2qHwaxPVnFsFmEZSXzGkLkvhMvL';
keyPair.verifyFingerprint({fingerprint});
// ->
{ valid: true }

Creating a signer function

In order to perform a cryptographic signature, you need to create a sign function, and then invoke it.

const keyPair = Ed25519VerificationKey2018.generate();

const {sign} = keyPair.signer();

const data = 'test data to sign';
const signatureValue = await sign({data});

Creating a verifier function

In order to verify a cryptographic signature, you need to create a verify function, and then invoke it (passing it the data to verify, and the signature).

const keyPair = Ed25519VerificationKey2018.generate();

const {verify} = keyPair.verifier();

const {valid} = await verify({data, signature});

Contribute

See the contribute file!

PRs accepted.

If editing the Readme, please conform to the standard-readme specification.

Commercial Support

Commercial support for this library is available upon request from Digital Bazaar: support@digitalbazaar.com

License

New BSD License (3-clause) © Digital Bazaar

changelog

ed25519-verification-key-2018 Changelog

4.0.0 - 2022-06-01

Changed

  • BREAKING: Convert to module (ESM).
  • BREAKING: Require Node.js >=14.
  • BREAKING: Use globalThis to access crypto in browsers.
  • Update dependencies.
  • Lint module.

3.2.0 - 2022-05-05

Changed

  • Replace underlying ed25519 implementation with @noble/ed25519. This should be a non-breaking change.

3.1.2 - 2022-02-15

Fixed

  • Fix seed generation if statement and test.

3.1.1 - 2021-04-08

Fixed

  • Ensure signer() and verifier() objects have an id property (for jsigs).

3.1.0 - 2021-04-02

Added

  • Add revoked export tests, SUITE_CONTEXT class property. (To support CryptoLD's new fromKeyId() method.) Also add requireContext flag to export().

3.0.0 - 2021-03-16

Changed

  • Update to use crypto-ld v5.0.
  • BREAKING: Removed helper methods addPublicKey and addPrivateKey.

2.0.0 - 2021-02-27

Added

  • BREAKING: Using @stablelib/ed25519 over node-forge.
  • BREAKING: Using base58-universal over bs58.
  • Added new files ed25519.js and ed25519-browser.js to /src.

Removed

  • BREAKING: Removed public export of privateKeyDerEncode & publicKeyDerEncode.
  • BREAKING: Removed node-forge from the project.
  • BREAKING: Removed semver from the project.
  • BREAKING: Removed bs58 from project.
  • BREAKING: Removed src/ed25519PrivateKeyNode12.js.
  • BREAKING: Removed src/ed25519PublicKeyNode12.js.

Changed

  • BREAKING: Browser must supply crypto.getRandomValues.
  • This library now switches between 2 different ed25519.js files for key generation when in node or the browser.
  • privateKeyDerEncode now only accepts Uint8Arrays.
  • publicKeyDerEncode now only accepts Uint8Arrays.

1.1.0 - 2020-10-20

Changed

  • Use node-forge@0.10.0.

1.0.2 - 2020-08-03

Changed

  • Fix karma tests, package.json export.

1.0.1 - 2020-08-01

Changed

  • Fix ESM import error.

1.0.0 - 2020-08-01

Added

  • Initial commit. Extracted from crypto-ld), for previous commit history, see that repo.

Changed

Purpose and Upgrade Instructions

See crypto-ld v4.0 Purpose and crypto-ld Upgrade from v3.7 notes