1 | import { x25519 } from '@noble/curves/ed25519'
|
2 | import type { ECDH } from './types.js'
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | export function createX25519ECDH(mySecretKey: Uint8Array): ECDH {
|
12 | if (mySecretKey.length !== 32) {
|
13 | throw new Error('invalid_argument: incorrect secret key length for X25519')
|
14 | }
|
15 | return async (theirPublicKey: Uint8Array): Promise<Uint8Array> => {
|
16 | if (theirPublicKey.length !== 32) {
|
17 | throw new Error('invalid_argument: incorrect publicKey key length for X25519')
|
18 | }
|
19 | return x25519.getSharedSecret(mySecretKey, theirPublicKey)
|
20 | }
|
21 | }
|