mol_crypto_lib 0.0.744 → 0.0.746

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/node.test.js CHANGED
@@ -839,6 +839,28 @@ var $;
839
839
  }
840
840
  return new this(await $mol_crypto_native.subtle.importKey('raw', serial, algorithm, true, ['encrypt', 'decrypt']));
841
841
  }
842
+ static async derive(private_serial, public_serial) {
843
+ const ecdh = { name: "ECDH", namedCurve: "P-256" };
844
+ const jwk = { crv: 'P-256', ext: true, kty: 'EC' };
845
+ const private_key = await $mol_crypto_native.subtle.importKey('jwk', {
846
+ ...jwk,
847
+ key_ops: ['deriveKey'],
848
+ x: private_serial.slice(0, 43),
849
+ y: private_serial.slice(43, 86),
850
+ d: private_serial.slice(86, 129),
851
+ }, ecdh, true, ['deriveKey']);
852
+ const public_key = await $mol_crypto_native.subtle.importKey('jwk', {
853
+ ...jwk,
854
+ key_ops: [],
855
+ x: public_serial.slice(0, 43),
856
+ y: public_serial.slice(43, 86),
857
+ }, ecdh, true, []);
858
+ const secret = await $mol_crypto_native.subtle.deriveKey({
859
+ name: "ECDH",
860
+ public: public_key,
861
+ }, private_key, algorithm, true, ["encrypt", "decrypt"]);
862
+ return new this(secret);
863
+ }
842
864
  async serial() {
843
865
  return await $mol_crypto_native.subtle.exportKey('raw', this.native);
844
866
  }
@@ -2215,6 +2237,13 @@ var $;
2215
2237
  const opened = await Bob.decrypt(closed, salt);
2216
2238
  $mol_assert_like(data, new Uint8Array(opened));
2217
2239
  },
2240
+ async 'derivation from public & private keys'() {
2241
+ const A = await $$.$mol_crypto_auditor_pair();
2242
+ const B = await $$.$mol_crypto_auditor_pair();
2243
+ const AK = await $mol_crypto_secret.derive(await A.private.serial(), await B.public.serial());
2244
+ const BK = await $mol_crypto_secret.derive(await B.private.serial(), await A.public.serial());
2245
+ $mol_assert_like(new Uint8Array(await AK.serial()), new Uint8Array(await BK.serial()));
2246
+ },
2218
2247
  });
2219
2248
  })($ || ($ = {}));
2220
2249
  //mol/crypto/secret/secret.test.ts