UNPKG

did-jwt

Version:

Library for Signing and Verifying JWTs that use DIDs as issuers and JWEs that use DIDs as recipients

23 lines • 1.04 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createX25519ECDH = createX25519ECDH; const ed25519_js_1 = require("@noble/curves/ed25519.js"); /** * Wraps an X25519 secret key into an ECDH method that can be used to compute a shared secret with a public key. * @param mySecretKey A `Uint8Array` of length 32 representing the bytes of my secret key * @returns an `ECDH` method with the signature `(theirPublicKey: Uint8Array) => Promise<Uint8Array>` * * @throws 'invalid_argument:...' if the secret key size is wrong */ function createX25519ECDH(mySecretKey) { if (mySecretKey.length !== 32) { throw new Error('invalid_argument: incorrect secret key length for X25519'); } return async (theirPublicKey) => { if (theirPublicKey.length !== 32) { throw new Error('invalid_argument: incorrect publicKey key length for X25519'); } return ed25519_js_1.x25519.getSharedSecret(mySecretKey, theirPublicKey); }; } //# sourceMappingURL=ECDH.js.map