( pubKey: CryptoKey, privKey?: CryptoKey )
| 62 | } |
| 63 | |
| 64 | export 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 | } |
no test coverage detected