1 | import { secp256k1 } from '@noble/curves/secp256k1';
|
2 | import { hasBigInt } from '@polkadot/util';
|
3 | import { isReady, secp256k1Compress as wasm } from '@polkadot/wasm-crypto';
|
4 | export function secp256k1Compress(publicKey, onlyJs) {
|
5 | if (![33, 65].includes(publicKey.length)) {
|
6 | throw new Error(`Invalid publicKey provided, received ${publicKey.length} bytes input`);
|
7 | }
|
8 | if (publicKey.length === 33) {
|
9 | return publicKey;
|
10 | }
|
11 | return !hasBigInt || (!onlyJs && isReady())
|
12 | ? wasm(publicKey)
|
13 | : secp256k1.ProjectivePoint.fromHex(publicKey).toRawBytes(true);
|
14 | }
|