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