1 | import { secp256k1 } from '@noble/curves/secp256k1';
|
2 | import { bnToU8a, hasBigInt, u8aConcat } from '@polkadot/util';
|
3 | import { isReady, secp256k1Expand as wasm } from '@polkadot/wasm-crypto';
|
4 | import { BN_BE_256_OPTS } from '../bn.js';
|
5 | export function secp256k1Expand(publicKey, onlyJs) {
|
6 | if (![33, 65].includes(publicKey.length)) {
|
7 | throw new Error(`Invalid publicKey provided, received ${publicKey.length} bytes input`);
|
8 | }
|
9 | if (publicKey.length === 65) {
|
10 | return publicKey.subarray(1);
|
11 | }
|
12 | if (!hasBigInt || (!onlyJs && isReady())) {
|
13 | return wasm(publicKey).subarray(1);
|
14 | }
|
15 | const { px, py } = secp256k1.ProjectivePoint.fromHex(publicKey);
|
16 | return u8aConcat(bnToU8a(px, BN_BE_256_OPTS), bnToU8a(py, BN_BE_256_OPTS));
|
17 | }
|