symbol/SharedKey.js

  1. /* eslint-disable no-unused-vars */
  2. import { KeyPair } from './KeyPair.js';
  3. import { PublicKey, SharedKey256 } from '../CryptoTypes.js';
  4. /* eslint-enable no-unused-vars */
  5. import { deriveSharedKeyFactory } from '../SharedKey.js';
  6. import { sha512 } from '@noble/hashes/sha512';
  7. const deriveSharedKeyImpl = deriveSharedKeyFactory('catapult', sha512);
  8. /**
  9. * Derives shared key from key pair and other party's public key.
  10. * @param {KeyPair} keyPair Key pair.
  11. * @param {PublicKey} otherPublicKey Other party's public key.
  12. * @returns {SharedKey256} Shared encryption key.
  13. */
  14. const deriveSharedKey = (keyPair, otherPublicKey) => deriveSharedKeyImpl(keyPair.privateKey.bytes, otherPublicKey);
  15. export { deriveSharedKey }; // eslint-disable-line import/prefer-default-export