🚀 DAY 4 OF LAUNCH WEEK:Introducing Socket Scanning for OpenVSX Extensions.Learn more →
Socket
Book a DemoInstallSign in
Socket

@transmute/did-key-x25519

Package Overview
Dependencies
Maintainers
2
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@transmute/did-key-x25519

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

latest
Source
npmnpm
Version
0.3.0-unstable.10
Version published
Maintainers
2
Created
Source

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

See application/did+json

application/did+ld+json

See application/did+ld+json

FAQs

Package last updated on 12 Dec 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts