0.3.0-unstable.10 • Published 1 year ago
@transmute/did-key-x25519 v0.3.0-unstable.10
did-key-x25519
npm i @transmute/did-key-x25519@latest --save
Usage
Generate
import crypto from 'crypto';
import * as x25519 from '@transmute/did-key-x25519';
const { didDocument, keys } = await x25519.generate(
{
secureRandom: () => {
return crypto.randomBytes(32);
},
},
{ accept: 'application/did+json' }
);
Export
import { X25519KeyPair } from '@transmute/did-key-x25519';
const k = await X25519KeyPair.generate({
secureRandom: () => {
return Buffer.from(
'5a2b1f37ecc9fb7f27e1aa3daa4d66d9c3e54a4c0dcd53a4a5cacdfaf50578cb',
'hex'
);
},
});
const exportedKeyPair = await k.export({
type: 'JsonWebKey2020',
privateKey: true,
});
Resolve
import * as x25519 from '@transmute/did-key-x25519';
const {
didDocument,
} = await x25519.resolve(
'did:key:z6LScNhBGJJHGPgx9AMCHjxFew9qfbAZhsi1KyJYcfdcFQ9k',
{ accept: 'application/did+json' }
);
JOSE
ECDH-ES+A256KW
import { X25519KeyPair } from '@transmute/did-key-x25519';
import { JWE } from '@transmute/jose-ld';
const k = await X25519KeyPair.generate({
secureRandom: () => {
return Buffer.from(
'5a2b1f37ecc9fb7f27e1aa3daa4d66d9c3e54a4c0dcd53a4a5cacdfaf50578cb',
'hex'
);
},
});
const cipher = new JWE.Cipher(X25519KeyPair);
const document = { key1: 'value1', key2: 'value2' };
const recipients = [
{
header: {
kid: k.id,
alg: 'ECDH-ES+A256KW',
},
},
];
const jwe = await cipher.encryptObject({
obj: document,
recipients,
publicKeyResolver: async (id: string) => {
if (id === k.id) {
return k.export({ type: 'JsonWebKey2020' });
}
throw new Error(
'publicKeyResolver does not suppport IRI ' + JSON.stringify(id)
);
},
});
const plaintext = await cipher.decrypt({ jwe, keyAgreementKey: k });
console.log(JSON.parse(Buffer.from(plaintext).toString('utf-8')));
Representations
application/did+json
application/did+ld+json
0.3.0-unstable.10
1 year ago
0.3.0-unstable.9
2 years ago
0.3.0-unstable.8
2 years ago
0.3.0-unstable.6
2 years ago
0.3.0-unstable.7
2 years ago
0.3.0-unstable.5
2 years ago
0.3.0-unstable.4
3 years ago
0.3.0-unstable.3
3 years ago
0.3.0-unstable.2
3 years ago
0.3.0-unstable.0
3 years ago
0.3.0-unstable.1
3 years ago
0.2.1-unstable.42
3 years ago
0.2.1-unstable.41
3 years ago
0.2.1-unstable.40
3 years ago
0.2.1-unstable.39
3 years ago
0.2.1-unstable.37
3 years ago
0.2.1-unstable.38
3 years ago
0.2.1-unstable.36
3 years ago
0.2.1-unstable.35
3 years ago
0.2.1-unstable.34
3 years ago
0.2.1-unstable.32
3 years ago
0.2.1-unstable.33
3 years ago
0.2.1-unstable.31
3 years ago
0.2.1-unstable.30
3 years ago
0.2.1-unstable.29
3 years ago
0.2.1-unstable.28
3 years ago
0.2.1-unstable.27
3 years ago
0.2.1-unstable.26
3 years ago
0.2.1-unstable.25
3 years ago
0.2.1-unstable.24
4 years ago
0.2.1-unstable.23
4 years ago
0.2.1-unstable.22
4 years ago
0.2.1-unstable.21
4 years ago
0.2.1-unstable.19
4 years ago
0.2.1-unstable.20
4 years ago
0.2.1-unstable.18
4 years ago
0.2.1-unstable.17
4 years ago
0.2.1-unstable.16
4 years ago
0.2.1-unstable.15
4 years ago
0.2.1-unstable.14
4 years ago
0.2.1-unstable.13
4 years ago
0.2.1-unstable.12
4 years ago
0.2.1-unstable.11
4 years ago
0.2.1-unstable.9
4 years ago
0.2.1-unstable.10
4 years ago
0.2.1-unstable.8
4 years ago
0.2.1-unstable.7
4 years ago
0.2.1-unstable.4
4 years ago
0.2.1-unstable.5
4 years ago
0.2.1-unstable.6
4 years ago
0.2.1-unstable.2
4 years ago
0.2.1-unstable.3
4 years ago
0.2.1-unstable.1
4 years ago
0.2.1-unstable.0
4 years ago
0.2.0
4 years ago
0.1.0
4 years ago
0.0.1-alpha.32
4 years ago
0.0.1-alpha.26
4 years ago