@digitalbazaar/ed25519-verification-key-2018
v4.0.0
Published
A library for generating and working with Ed25519 key pairs, for use with crypto-ld.
Downloads
13,341
Readme
Ed25519VerificationKey2018 Key Pair Library for Linked Data (@digitalbazaar/ed25519-verification-key-2018)
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: [email protected]
License
New BSD License (3-clause) © Digital Bazaar