From a5d3c8b06cba652b902fdfaa3f13ed40483e90c0 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Fri, 8 Oct 2021 20:59:36 +0530 Subject: feat(ext/crypto): implement deriveBits for ECDH (p256) (#11873) --- cli/tests/unit/webcrypto_test.ts | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'cli') diff --git a/cli/tests/unit/webcrypto_test.ts b/cli/tests/unit/webcrypto_test.ts index b38a9934f..80275b002 100644 --- a/cli/tests/unit/webcrypto_test.ts +++ b/cli/tests/unit/webcrypto_test.ts @@ -513,6 +513,31 @@ unitTest(async function testHkdfDeriveBits() { assertEquals(result.byteLength, 128 / 8); }); +// TODO(@littledivy): Enable WPT when we have importKey support +unitTest(async function testECDH() { + const namedCurve = "P-256"; + const keyPair = await crypto.subtle.generateKey( + { + name: "ECDH", + namedCurve, + }, + true, + ["deriveBits"], + ); + + const derivedKey = await crypto.subtle.deriveBits( + { + name: "ECDH", + public: keyPair.publicKey, + }, + keyPair.privateKey, + 256, + ); + + assert(derivedKey instanceof ArrayBuffer); + assertEquals(derivedKey.byteLength, 256 / 8); +}); + unitTest(async function testWrapKey() { // Test wrapKey const key = await crypto.subtle.generateKey( -- cgit v1.2.3