mirror of
https://gitlab.com/soapbox-pub/ditto.git
synced 2025-12-06 11:29:46 +00:00
28 lines
740 B
TypeScript
28 lines
740 B
TypeScript
import { assertEquals } from '@std/assert';
|
|
|
|
import { getEcdsaPublicKey } from '@/utils/crypto.ts';
|
|
|
|
Deno.test('getEcdsaPublicKey', async () => {
|
|
const { publicKey, privateKey } = await crypto.subtle.generateKey(
|
|
{
|
|
name: 'ECDSA',
|
|
namedCurve: 'P-256',
|
|
},
|
|
true,
|
|
['sign', 'verify'],
|
|
);
|
|
|
|
const result = await getEcdsaPublicKey(privateKey, true);
|
|
|
|
assertKeysEqual(result, publicKey);
|
|
});
|
|
|
|
/** Assert that two CryptoKey objects are equal by value. Keys must be exportable. */
|
|
async function assertKeysEqual(a: CryptoKey, b: CryptoKey): Promise<void> {
|
|
const [jwk1, jwk2] = await Promise.all([
|
|
crypto.subtle.exportKey('jwk', a),
|
|
crypto.subtle.exportKey('jwk', b),
|
|
]);
|
|
|
|
assertEquals(jwk1, jwk2);
|
|
}
|