MCPcopy Create free account
hub / github.com/cloudflare/wildebeest / cryptoKeysToUint8Array

Function cryptoKeysToUint8Array

backend/src/webpush/util.ts:64–81  ·  view source on GitHub ↗
(
	pubKey: CryptoKey,
	privKey?: CryptoKey
)

Source from the content-addressed store, hash-verified

62}
63
64export async function cryptoKeysToUint8Array(
65 pubKey: CryptoKey,
66 privKey?: CryptoKey
67): Promise<{ publicKey: Uint8Array; privateKey?: Uint8Array }> {
68 const jwk: any = await crypto.subtle.exportKey('jwk', pubKey)
69 const x = base64UrlToUint8Array(jwk.x as string)
70 const y = base64UrlToUint8Array(jwk.y as string)
71 const publicKey = new Uint8Array(65)
72 publicKey.set([0x04], 0)
73 publicKey.set(x, 1)
74 publicKey.set(y, 33)
75 if (privKey) {
76 const jwk: any = await crypto.subtle.exportKey('jwk', privKey)
77 const privateKey = base64UrlToUint8Array(jwk.d as string)
78 return { publicKey, privateKey }
79 }
80 return { publicKey }
81}

Callers 1

generateContextFunction · 0.90

Calls 2

base64UrlToUint8ArrayFunction · 0.85
setMethod · 0.80

Tested by

no test coverage detected