UNPKG

595 BJavaScriptView Raw
1import { secp256k1 } from '@noble/curves/secp256k1';
2import { hasBigInt } from '@polkadot/util';
3import { isReady, secp256k1Compress as wasm } from '@polkadot/wasm-crypto';
4export 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}