1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.secp256k1Expand = void 0;
|
4 | const secp256k1_1 = require("@noble/curves/secp256k1");
|
5 | const util_1 = require("@polkadot/util");
|
6 | const wasm_crypto_1 = require("@polkadot/wasm-crypto");
|
7 | const bn_js_1 = require("../bn.js");
|
8 | function 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 | }
|
21 | exports.secp256k1Expand = secp256k1Expand;
|