1 | import { ed25519 } from '@noble/curves/ed25519';
|
2 | import { hasBigInt, u8aToU8a } from '@polkadot/util';
|
3 | import { ed25519Sign as wasmSign, isReady } from '@polkadot/wasm-crypto';
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | export function ed25519Sign(message, { publicKey, secretKey }, onlyJs) {
|
19 | if (!secretKey) {
|
20 | throw new Error('Expected a valid secretKey');
|
21 | }
|
22 | else if (!publicKey) {
|
23 | throw new Error('Expected a valid publicKey');
|
24 | }
|
25 | const messageU8a = u8aToU8a(message);
|
26 | const privateU8a = secretKey.subarray(0, 32);
|
27 | return !hasBigInt || (!onlyJs && isReady())
|
28 | ? wasmSign(publicKey, privateU8a, messageU8a)
|
29 | : ed25519.sign(messageU8a, privateU8a);
|
30 | }
|