990 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.secp256k1Expand = void 0;
4const secp256k1_1 = require("@noble/curves/secp256k1");
5const util_1 = require("@polkadot/util");
6const wasm_crypto_1 = require("@polkadot/wasm-crypto");
7const bn_js_1 = require("../bn.js");
8function secp256k1Expand(publicKey, onlyJs) {
9 if (![33, 65].includes(publicKey.length)) {
10 throw new Error(`Invalid publicKey provided, received ${publicKey.length} bytes input`);
11 }
12 if (publicKey.length === 65) {
13 return publicKey.subarray(1);
14 }
15 if (!util_1.hasBigInt || (!onlyJs && (0, wasm_crypto_1.isReady)())) {
16 return (0, wasm_crypto_1.secp256k1Expand)(publicKey).subarray(1);
17 }
18 const { px, py } = secp256k1_1.secp256k1.ProjectivePoint.fromHex(publicKey);
19 return (0, util_1.u8aConcat)((0, util_1.bnToU8a)(px, bn_js_1.BN_BE_256_OPTS), (0, util_1.bnToU8a)(py, bn_js_1.BN_BE_256_OPTS));
20}
21exports.secp256k1Expand = secp256k1Expand;