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

Function getSubKeyAsCryptoKey

backend/src/webpush/message.ts:25–44  ·  view source on GitHub ↗
(subscription: WebPushInfos)

Source from the content-addressed store, hash-verified

23}
24
25async function getSubKeyAsCryptoKey(subscription: WebPushInfos): Promise<CryptoKey> {
26 const key = urlsafeBase64Decode(subscription.key)
27 const publicKey = await crypto.subtle.importKey(
28 'jwk',
29 {
30 kty: 'EC',
31 crv: 'P-256',
32 x: b64ToUrlEncoded(btoa(key.slice(1, 33))),
33 y: b64ToUrlEncoded(btoa(key.slice(33, 65))),
34 ext: true,
35 },
36 {
37 name: 'ECDH',
38 namedCurve: 'P-256',
39 },
40 true,
41 []
42 )
43 return publicKey
44}
45
46async function getSharedSecret(subscription: WebPushInfos, serverKeys: mKeyPair): Promise<ArrayBuffer> {
47 const publicKey = await getSubKeyAsCryptoKey(subscription)

Callers 2

getSharedSecretFunction · 0.85
generateContextFunction · 0.85

Calls 2

urlsafeBase64DecodeFunction · 0.90
b64ToUrlEncodedFunction · 0.90

Tested by

no test coverage detected