chore: update to version 14.0.11 and align website URLs

This commit is contained in:
2026-01-11 11:34:13 +03:00
parent ef74383349
commit 19c8d69bd8
1499 changed files with 53633 additions and 89 deletions
+1
View File
@@ -0,0 +1 @@
export declare function secp256k1Compress(publicKey: Uint8Array, onlyJs?: boolean): Uint8Array;
@@ -0,0 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.secp256k1Compress = secp256k1Compress;
const secp256k1_1 = require("@noble/curves/secp256k1");
const util_1 = require("@pezkuwi/util");
const wasm_crypto_1 = require("@pezkuwi/wasm-crypto");
function secp256k1Compress(publicKey, onlyJs) {
if (![33, 65].includes(publicKey.length)) {
throw new Error(`Invalid publicKey provided, received ${publicKey.length} bytes input`);
}
if (publicKey.length === 33) {
return publicKey;
}
return !util_1.hasBigInt || (!onlyJs && (0, wasm_crypto_1.isReady)())
? (0, wasm_crypto_1.secp256k1Compress)(publicKey)
: secp256k1_1.secp256k1.ProjectivePoint.fromHex(publicKey).toRawBytes(true);
}
+1
View File
@@ -0,0 +1 @@
export declare function secp256k1DeriveHard(seed: Uint8Array, chainCode: Uint8Array): Uint8Array;
@@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.secp256k1DeriveHard = secp256k1DeriveHard;
const util_1 = require("@pezkuwi/util");
const asU8a_js_1 = require("../blake2/asU8a.js");
const HDKD = (0, util_1.compactAddLength)((0, util_1.stringToU8a)('Secp256k1HDKD'));
function secp256k1DeriveHard(seed, chainCode) {
if (!(0, util_1.isU8a)(chainCode) || chainCode.length !== 32) {
throw new Error('Invalid chainCode passed to derive');
}
// NOTE This is specific to the Substrate HDD derivation, so always use the blake2 hasher
return (0, asU8a_js_1.blake2AsU8a)((0, util_1.u8aConcat)(HDKD, seed, chainCode), 256);
}
+1
View File
@@ -0,0 +1 @@
export declare function secp256k1Expand(publicKey: Uint8Array, onlyJs?: boolean): Uint8Array;
@@ -0,0 +1,20 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.secp256k1Expand = secp256k1Expand;
const secp256k1_1 = require("@noble/curves/secp256k1");
const util_1 = require("@pezkuwi/util");
const wasm_crypto_1 = require("@pezkuwi/wasm-crypto");
const bn_js_1 = require("../bn.js");
function secp256k1Expand(publicKey, onlyJs) {
if (![33, 65].includes(publicKey.length)) {
throw new Error(`Invalid publicKey provided, received ${publicKey.length} bytes input`);
}
if (publicKey.length === 65) {
return publicKey.subarray(1);
}
if (!util_1.hasBigInt || (!onlyJs && (0, wasm_crypto_1.isReady)())) {
return (0, wasm_crypto_1.secp256k1Expand)(publicKey).subarray(1);
}
const { px, py } = secp256k1_1.secp256k1.ProjectivePoint.fromHex(publicKey);
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));
}
+2
View File
@@ -0,0 +1,2 @@
import type { HashType } from './types.js';
export declare function hasher(hashType: HashType, data: Uint8Array | string, onlyJs?: boolean): Uint8Array;
@@ -0,0 +1,10 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.hasher = hasher;
const index_js_1 = require("../blake2/index.js");
const index_js_2 = require("../keccak/index.js");
function hasher(hashType, data, onlyJs) {
return hashType === 'keccak'
? (0, index_js_2.keccakAsU8a)(data, undefined, onlyJs)
: (0, index_js_1.blake2AsU8a)(data, undefined, undefined, onlyJs);
}
+7
View File
@@ -0,0 +1,7 @@
export { secp256k1Compress } from './compress.js';
export { secp256k1Expand } from './expand.js';
export { secp256k1PairFromSeed } from './pair/fromSeed.js';
export { secp256k1Recover } from './recover.js';
export { secp256k1Sign } from './sign.js';
export { secp256k1PrivateKeyTweakAdd } from './tweakAdd.js';
export { secp256k1Verify } from './verify.js';
@@ -0,0 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.secp256k1Verify = exports.secp256k1PrivateKeyTweakAdd = exports.secp256k1Sign = exports.secp256k1Recover = exports.secp256k1PairFromSeed = exports.secp256k1Expand = exports.secp256k1Compress = void 0;
var compress_js_1 = require("./compress.js");
Object.defineProperty(exports, "secp256k1Compress", { enumerable: true, get: function () { return compress_js_1.secp256k1Compress; } });
var expand_js_1 = require("./expand.js");
Object.defineProperty(exports, "secp256k1Expand", { enumerable: true, get: function () { return expand_js_1.secp256k1Expand; } });
var fromSeed_js_1 = require("./pair/fromSeed.js");
Object.defineProperty(exports, "secp256k1PairFromSeed", { enumerable: true, get: function () { return fromSeed_js_1.secp256k1PairFromSeed; } });
var recover_js_1 = require("./recover.js");
Object.defineProperty(exports, "secp256k1Recover", { enumerable: true, get: function () { return recover_js_1.secp256k1Recover; } });
var sign_js_1 = require("./sign.js");
Object.defineProperty(exports, "secp256k1Sign", { enumerable: true, get: function () { return sign_js_1.secp256k1Sign; } });
var tweakAdd_js_1 = require("./tweakAdd.js");
Object.defineProperty(exports, "secp256k1PrivateKeyTweakAdd", { enumerable: true, get: function () { return tweakAdd_js_1.secp256k1PrivateKeyTweakAdd; } });
var verify_js_1 = require("./verify.js");
Object.defineProperty(exports, "secp256k1Verify", { enumerable: true, get: function () { return verify_js_1.secp256k1Verify; } });
+6
View File
@@ -0,0 +1,6 @@
import type { Keypair } from '../../types.js';
/**
* @name secp256k1PairFromSeed
* @description Returns a object containing a `publicKey` & `secretKey` generated from the supplied seed.
*/
export declare function secp256k1PairFromSeed(seed: Uint8Array, onlyJs?: boolean): Keypair;
@@ -0,0 +1,34 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.secp256k1PairFromSeed = secp256k1PairFromSeed;
const secp256k1_1 = require("@noble/curves/secp256k1");
const util_1 = require("@pezkuwi/util");
const wasm_crypto_1 = require("@pezkuwi/wasm-crypto");
/**
* @name secp256k1PairFromSeed
* @description Returns a object containing a `publicKey` & `secretKey` generated from the supplied seed.
*/
function secp256k1PairFromSeed(seed, onlyJs) {
if (seed.length !== 32) {
throw new Error('Expected valid 32-byte private key as a seed');
}
if (!util_1.hasBigInt || (!onlyJs && (0, wasm_crypto_1.isReady)())) {
const full = (0, wasm_crypto_1.secp256k1FromSeed)(seed);
const publicKey = full.slice(32);
// There is an issue with the secp256k1 when running in an ASM.js environment where
// it seems that the lazy static section yields invalid results on the _first_ run.
// If this happens, fail outright, we cannot allow invalid return values
// https://github.com/polkadot-js/wasm/issues/307
if ((0, util_1.u8aEmpty)(publicKey)) {
throw new Error('Invalid publicKey generated from WASM interface');
}
return {
publicKey,
secretKey: full.slice(0, 32)
};
}
return {
publicKey: secp256k1_1.secp256k1.getPublicKey(seed, true),
secretKey: seed
};
}
+6
View File
@@ -0,0 +1,6 @@
import type { HashType } from './types.js';
/**
* @name secp256k1Recover
* @description Recovers a publicKey from the supplied signature
*/
export declare function secp256k1Recover(msgHash: string | Uint8Array, signature: string | Uint8Array, recovery: number, hashType?: HashType, onlyJs?: boolean): Uint8Array;
@@ -0,0 +1,29 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.secp256k1Recover = secp256k1Recover;
const secp256k1_1 = require("@noble/curves/secp256k1");
const util_1 = require("@pezkuwi/util");
const wasm_crypto_1 = require("@pezkuwi/wasm-crypto");
const compress_js_1 = require("./compress.js");
const expand_js_1 = require("./expand.js");
/**
* @name secp256k1Recover
* @description Recovers a publicKey from the supplied signature
*/
function secp256k1Recover(msgHash, signature, recovery, hashType = 'blake2', onlyJs) {
const sig = (0, util_1.u8aToU8a)(signature).subarray(0, 64);
const msg = (0, util_1.u8aToU8a)(msgHash);
const publicKey = !util_1.hasBigInt || (!onlyJs && (0, wasm_crypto_1.isReady)())
? (0, wasm_crypto_1.secp256k1Recover)(msg, sig, recovery)
: secp256k1_1.secp256k1.Signature
.fromCompact(sig)
.addRecoveryBit(recovery)
.recoverPublicKey(msg)
.toRawBytes();
if (!publicKey) {
throw new Error('Unable to recover publicKey from signature');
}
return hashType === 'keccak'
? (0, expand_js_1.secp256k1Expand)(publicKey, onlyJs)
: (0, compress_js_1.secp256k1Compress)(publicKey, onlyJs);
}
+7
View File
@@ -0,0 +1,7 @@
import type { Keypair } from '../types.js';
import type { HashType } from './types.js';
/**
* @name secp256k1Sign
* @description Returns message signature of `message`, using the supplied pair
*/
export declare function secp256k1Sign(message: Uint8Array | string, { secretKey }: Partial<Keypair>, hashType?: HashType, onlyJs?: boolean): Uint8Array;
@@ -0,0 +1,23 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.secp256k1Sign = secp256k1Sign;
const secp256k1_1 = require("@noble/curves/secp256k1");
const util_1 = require("@pezkuwi/util");
const wasm_crypto_1 = require("@pezkuwi/wasm-crypto");
const bn_js_1 = require("../bn.js");
const hasher_js_1 = require("./hasher.js");
/**
* @name secp256k1Sign
* @description Returns message signature of `message`, using the supplied pair
*/
function secp256k1Sign(message, { secretKey }, hashType = 'blake2', onlyJs) {
if (secretKey?.length !== 32) {
throw new Error('Expected valid secp256k1 secretKey, 32-bytes');
}
const data = (0, hasher_js_1.hasher)(hashType, message, onlyJs);
if (!util_1.hasBigInt || (!onlyJs && (0, wasm_crypto_1.isReady)())) {
return (0, wasm_crypto_1.secp256k1Sign)(data, secretKey);
}
const signature = secp256k1_1.secp256k1.sign(data, secretKey, { lowS: true });
return (0, util_1.u8aConcat)((0, util_1.bnToU8a)(signature.r, bn_js_1.BN_BE_256_OPTS), (0, util_1.bnToU8a)(signature.s, bn_js_1.BN_BE_256_OPTS), new Uint8Array([signature.recovery || 0]));
}
+1
View File
@@ -0,0 +1 @@
export declare function secp256k1PrivateKeyTweakAdd(seckey: Uint8Array, tweak: Uint8Array, onlyBn?: boolean): Uint8Array;
@@ -0,0 +1,48 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.secp256k1PrivateKeyTweakAdd = secp256k1PrivateKeyTweakAdd;
const util_1 = require("@pezkuwi/util");
const x_bigint_1 = require("@pezkuwi/x-bigint");
const bn_js_1 = require("../bn.js");
const N = 'ffffffff ffffffff ffffffff fffffffe baaedce6 af48a03b bfd25e8c d0364141'.replace(/ /g, '');
const N_BI = (0, x_bigint_1.BigInt)(`0x${N}`);
const N_BN = new util_1.BN(N, 'hex');
function addBi(seckey, tweak) {
let res = (0, util_1.u8aToBigInt)(tweak, bn_js_1.BN_BE_OPTS);
if (res >= N_BI) {
throw new Error('Tweak parameter is out of range');
}
res += (0, util_1.u8aToBigInt)(seckey, bn_js_1.BN_BE_OPTS);
if (res >= N_BI) {
res -= N_BI;
}
if (res === util_1._0n) {
throw new Error('Invalid resulting private key');
}
return (0, util_1.nToU8a)(res, bn_js_1.BN_BE_256_OPTS);
}
function addBn(seckey, tweak) {
const res = new util_1.BN(tweak);
if (res.cmp(N_BN) >= 0) {
throw new Error('Tweak parameter is out of range');
}
res.iadd(new util_1.BN(seckey));
if (res.cmp(N_BN) >= 0) {
res.isub(N_BN);
}
if (res.isZero()) {
throw new Error('Invalid resulting private key');
}
return (0, util_1.bnToU8a)(res, bn_js_1.BN_BE_256_OPTS);
}
function secp256k1PrivateKeyTweakAdd(seckey, tweak, onlyBn) {
if (!(0, util_1.isU8a)(seckey) || seckey.length !== 32) {
throw new Error('Expected seckey to be an Uint8Array with length 32');
}
else if (!(0, util_1.isU8a)(tweak) || tweak.length !== 32) {
throw new Error('Expected tweak to be an Uint8Array with length 32');
}
return !util_1.hasBigInt || onlyBn
? addBn(seckey, tweak)
: addBi(seckey, tweak);
}
+1
View File
@@ -0,0 +1 @@
export type HashType = 'blake2' | 'keccak';
@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
+6
View File
@@ -0,0 +1,6 @@
import type { HashType } from './types.js';
/**
* @name secp256k1Verify
* @description Verifies the signature of `message`, using the supplied pair
*/
export declare function secp256k1Verify(msgHash: string | Uint8Array, signature: string | Uint8Array, address: string | Uint8Array, hashType?: HashType, onlyJs?: boolean): boolean;
@@ -0,0 +1,23 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.secp256k1Verify = secp256k1Verify;
const util_1 = require("@pezkuwi/util");
const hasher_js_1 = require("./hasher.js");
const recover_js_1 = require("./recover.js");
/**
* @name secp256k1Verify
* @description Verifies the signature of `message`, using the supplied pair
*/
function secp256k1Verify(msgHash, signature, address, hashType = 'blake2', onlyJs) {
const sig = (0, util_1.u8aToU8a)(signature);
if (sig.length !== 65) {
throw new Error(`Expected signature with 65 bytes, ${sig.length} found instead`);
}
const publicKey = (0, recover_js_1.secp256k1Recover)((0, hasher_js_1.hasher)(hashType, msgHash), sig, sig[64], hashType, onlyJs);
const signerAddr = (0, hasher_js_1.hasher)(hashType, publicKey, onlyJs);
const inputAddr = (0, util_1.u8aToU8a)(address);
// for Ethereum (keccak) the last 20 bytes is the address
return (0, util_1.u8aEq)(publicKey, inputAddr) || (hashType === 'keccak'
? (0, util_1.u8aEq)(signerAddr.slice(-20), inputAddr.slice(-20))
: (0, util_1.u8aEq)(signerAddr, inputAddr));
}