UNPKG

foundry-primitives

Version:
30 lines 1.18 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const utility_1 = require("../utility"); /** * @hidden */ const nacl = require("tweetnacl"); /** * Gets an ECDH session key for encryption and decryption between two parties * @param otherPublic 32 byte hexadecimal string of the other side public key * @param myPrivate 32 byte hexadecimal string of my side private key * @returns 32 byte hexadecimal string of the shared secret */ exports.exchange = (otherPublic, myPrivate) => { const groupElement = utility_1.toArray(otherPublic); const scalar = utility_1.toArray(myPrivate); const sharedSecret = nacl.scalarMult(scalar, groupElement); return utility_1.toHex(sharedSecret); }; /** * Gets the X25519 public key(on Curve25519) for a private key * @param x25519Private 32 byte hexadecimal string of a secret key * @returns 32 byte hexadecimal string of the public key */ exports.x25519GetPublicFromPrivate = (x25519Private) => { const scalar = utility_1.toArray(x25519Private); const x25519Public = nacl.scalarMult.base(scalar); return utility_1.toHex(x25519Public); }; //# sourceMappingURL=keyExchange.js.map