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
+5
View File
@@ -0,0 +1,5 @@
/**
* @name addressToEvm
* @summary Converts an SS58 address to its corresponding EVM address.
*/
export declare function addressToEvm(address: string | Uint8Array, ignoreChecksum?: boolean): Uint8Array;
@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.addressToEvm = addressToEvm;
const decode_js_1 = require("./decode.js");
/**
* @name addressToEvm
* @summary Converts an SS58 address to its corresponding EVM address.
*/
function addressToEvm(address, ignoreChecksum) {
return (0, decode_js_1.decodeAddress)(address, ignoreChecksum).subarray(0, 20);
}
+8
View File
@@ -0,0 +1,8 @@
import type { Prefix } from './types.js';
/**
* @name checkAddress
* @summary Validates an ss58 address.
* @description
* From the provided input, validate that the address is a valid input.
*/
export declare function checkAddress(address: string, prefix: Prefix): [boolean, string | null];
+29
View File
@@ -0,0 +1,29 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkAddress = checkAddress;
const index_js_1 = require("../base58/index.js");
const checksum_js_1 = require("./checksum.js");
const defaults_js_1 = require("./defaults.js");
/**
* @name checkAddress
* @summary Validates an ss58 address.
* @description
* From the provided input, validate that the address is a valid input.
*/
function checkAddress(address, prefix) {
let decoded;
try {
decoded = (0, index_js_1.base58Decode)(address);
}
catch (error) {
return [false, error.message];
}
const [isValid, , , ss58Decoded] = (0, checksum_js_1.checkAddressChecksum)(decoded);
if (ss58Decoded !== prefix) {
return [false, `Prefix mismatch, expected ${prefix}, found ${ss58Decoded}`];
}
else if (!defaults_js_1.defaults.allowedEncodedLengths.includes(decoded.length)) {
return [false, 'Invalid decoded address length'];
}
return [isValid, isValid ? null : 'Invalid decoded address checksum'];
}
+1
View File
@@ -0,0 +1 @@
export declare function checkAddressChecksum(decoded: Uint8Array): [boolean, number, number, number];
@@ -0,0 +1,19 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkAddressChecksum = checkAddressChecksum;
const sshash_js_1 = require("./sshash.js");
function checkAddressChecksum(decoded) {
const ss58Length = (decoded[0] & 0b0100_0000) ? 2 : 1;
const ss58Decoded = ss58Length === 1
? decoded[0]
: ((decoded[0] & 0b0011_1111) << 2) | (decoded[1] >> 6) | ((decoded[1] & 0b0011_1111) << 8);
// 32/33 bytes public + 2 bytes checksum + prefix
const isPublicKey = [34 + ss58Length, 35 + ss58Length].includes(decoded.length);
const length = decoded.length - (isPublicKey ? 2 : 1);
// calculate the hash and do the checksum byte checks
const hash = (0, sshash_js_1.sshash)(decoded.subarray(0, length));
const isValid = (decoded[0] & 0b1000_0000) === 0 && ![46, 47].includes(decoded[0]) && (isPublicKey
? decoded[decoded.length - 2] === hash[0] && decoded[decoded.length - 1] === hash[1]
: decoded[decoded.length - 1] === hash[0]);
return [isValid, length, ss58Length, ss58Decoded];
}
+2
View File
@@ -0,0 +1,2 @@
import type { Prefix } from './types.js';
export declare function decodeAddress(encoded?: string | Uint8Array | null, ignoreChecksum?: boolean, ss58Format?: Prefix): Uint8Array;
@@ -0,0 +1,32 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.decodeAddress = decodeAddress;
const util_1 = require("@pezkuwi/util");
const index_js_1 = require("../base58/index.js");
const checksum_js_1 = require("./checksum.js");
const defaults_js_1 = require("./defaults.js");
function decodeAddress(encoded, ignoreChecksum, ss58Format = -1) {
if (!encoded) {
throw new Error('Invalid empty address passed');
}
if ((0, util_1.isU8a)(encoded) || (0, util_1.isHex)(encoded)) {
return (0, util_1.u8aToU8a)(encoded);
}
try {
const decoded = (0, index_js_1.base58Decode)(encoded);
if (!defaults_js_1.defaults.allowedEncodedLengths.includes(decoded.length)) {
throw new Error('Invalid decoded address length');
}
const [isValid, endPos, ss58Length, ss58Decoded] = (0, checksum_js_1.checkAddressChecksum)(decoded);
if (!isValid && !ignoreChecksum) {
throw new Error('Invalid decoded address checksum');
}
else if (ss58Format !== -1 && ss58Format !== ss58Decoded) {
throw new Error(`Expected ss58Format ${ss58Format}, received ${ss58Decoded}`);
}
return decoded.slice(ss58Length, endPos);
}
catch (error) {
throw new Error(`Decoding ${encoded}: ${error.message}`);
}
}
+6
View File
@@ -0,0 +1,6 @@
export declare const defaults: {
allowedDecodedLengths: number[];
allowedEncodedLengths: number[];
allowedPrefix: number[];
prefix: number;
};
@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.defaults = void 0;
const networks_js_1 = require("../networks.js");
exports.defaults = {
allowedDecodedLengths: [1, 2, 4, 8, 32, 33],
// publicKey has prefix + 2 checksum bytes, short only prefix + 1 checksum byte
allowedEncodedLengths: [3, 4, 6, 10, 35, 36, 37, 38],
allowedPrefix: networks_js_1.availableNetworks.map(({ prefix }) => prefix),
prefix: 42
};
+8
View File
@@ -0,0 +1,8 @@
import type { Prefix } from './types.js';
/**
* @name deriveAddress
* @summary Creates a sr25519 derived address from the supplied and path.
* @description
* Creates a sr25519 derived address based on the input address/publicKey and the uri supplied.
*/
export declare function deriveAddress(who: string | Uint8Array, suri: string, ss58Format?: Prefix): string;
@@ -0,0 +1,27 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.deriveAddress = deriveAddress;
const index_js_1 = require("../key/index.js");
const index_js_2 = require("../sr25519/index.js");
const decode_js_1 = require("./decode.js");
const encode_js_1 = require("./encode.js");
function filterHard({ isHard }) {
return isHard;
}
/**
* @name deriveAddress
* @summary Creates a sr25519 derived address from the supplied and path.
* @description
* Creates a sr25519 derived address based on the input address/publicKey and the uri supplied.
*/
function deriveAddress(who, suri, ss58Format) {
const { path } = (0, index_js_1.keyExtractPath)(suri);
if (!path.length || path.every(filterHard)) {
throw new Error('Expected suri to contain a combination of non-hard paths');
}
let publicKey = (0, decode_js_1.decodeAddress)(who);
for (const { chainCode } of path) {
publicKey = (0, index_js_2.sr25519DerivePublic)(publicKey, chainCode);
}
return (0, encode_js_1.encodeAddress)(publicKey, ss58Format);
}
+2
View File
@@ -0,0 +1,2 @@
import type { Prefix } from './types.js';
export declare function encodeAddress(key: string | Uint8Array, ss58Format?: Prefix): string;
@@ -0,0 +1,26 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.encodeAddress = encodeAddress;
const util_1 = require("@pezkuwi/util");
const index_js_1 = require("../base58/index.js");
const decode_js_1 = require("./decode.js");
const defaults_js_1 = require("./defaults.js");
const sshash_js_1 = require("./sshash.js");
function encodeAddress(key, ss58Format = defaults_js_1.defaults.prefix) {
// decode it, this means we can re-encode an address
const u8a = (0, decode_js_1.decodeAddress)(key);
if ((ss58Format < 0) || (ss58Format > 16383 && !ss58Exceptions.includes(ss58Format)) || [46, 47].includes(ss58Format)) {
throw new Error('Out of range ss58Format specified');
}
else if (!defaults_js_1.defaults.allowedDecodedLengths.includes(u8a.length)) {
throw new Error(`Expected a valid key to convert, with length ${defaults_js_1.defaults.allowedDecodedLengths.join(', ')}`);
}
const input = (0, util_1.u8aConcat)(ss58Format < 64
? [ss58Format]
: [
((ss58Format & 0b0000_0000_1111_1100) >> 2) | 0b0100_0000,
(ss58Format >> 8) | ((ss58Format & 0b0000_0000_0000_0011) << 6)
], u8a);
return (0, index_js_1.base58Encode)((0, util_1.u8aConcat)(input, (0, sshash_js_1.sshash)(input).subarray(0, [32, 33].includes(u8a.length) ? 2 : 1)));
}
const ss58Exceptions = [29972];
+9
View File
@@ -0,0 +1,9 @@
import type { BN } from '@pezkuwi/util';
import type { Prefix } from './types.js';
/**
* @name encodeDerivedAddress
* @summary Creates a derived address as used in Substrate utility.
* @description
* Creates a Substrate derived address based on the input address/publicKey and the index supplied.
*/
export declare function encodeDerivedAddress(who: string | Uint8Array, index: bigint | BN | number, ss58Format?: Prefix): string;
@@ -0,0 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.encodeDerivedAddress = encodeDerivedAddress;
const decode_js_1 = require("./decode.js");
const encode_js_1 = require("./encode.js");
const keyDerived_js_1 = require("./keyDerived.js");
/**
* @name encodeDerivedAddress
* @summary Creates a derived address as used in Substrate utility.
* @description
* Creates a Substrate derived address based on the input address/publicKey and the index supplied.
*/
function encodeDerivedAddress(who, index, ss58Format) {
return (0, encode_js_1.encodeAddress)((0, keyDerived_js_1.createKeyDerived)((0, decode_js_1.decodeAddress)(who), index), ss58Format);
}
+9
View File
@@ -0,0 +1,9 @@
import type { BN } from '@pezkuwi/util';
import type { Prefix } from './types.js';
/**
* @name encodeMultiAddress
* @summary Creates a multisig address.
* @description
* Creates a Substrate multisig address based on the input address and the required threshold.
*/
export declare function encodeMultiAddress(who: (string | Uint8Array)[], threshold: bigint | BN | number, ss58Format?: Prefix): string;
@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.encodeMultiAddress = encodeMultiAddress;
const encode_js_1 = require("./encode.js");
const keyMulti_js_1 = require("./keyMulti.js");
/**
* @name encodeMultiAddress
* @summary Creates a multisig address.
* @description
* Creates a Substrate multisig address based on the input address and the required threshold.
*/
function encodeMultiAddress(who, threshold, ss58Format) {
return (0, encode_js_1.encodeAddress)((0, keyMulti_js_1.createKeyMulti)(who, threshold), ss58Format);
}
+15
View File
@@ -0,0 +1,15 @@
/**
* @name addressEq
* @summary Compares two addresses, either in ss58, Uint8Array or hex format.
* @description
* For the input values, return true is the underlying public keys do match.
* @example
* <BR>
*
* ```javascript
* import { u8aEq } from '@pezkuwi/util';
*
* u8aEq(new Uint8Array([0x68, 0x65]), new Uint8Array([0x68, 0x65])); // true
* ```
*/
export declare function addressEq(a: string | Uint8Array, b: string | Uint8Array): boolean;
+22
View File
@@ -0,0 +1,22 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.addressEq = addressEq;
const util_1 = require("@pezkuwi/util");
const decode_js_1 = require("./decode.js");
/**
* @name addressEq
* @summary Compares two addresses, either in ss58, Uint8Array or hex format.
* @description
* For the input values, return true is the underlying public keys do match.
* @example
* <BR>
*
* ```javascript
* import { u8aEq } from '@pezkuwi/util';
*
* u8aEq(new Uint8Array([0x68, 0x65]), new Uint8Array([0x68, 0x65])); // true
* ```
*/
function addressEq(a, b) {
return (0, util_1.u8aEq)((0, decode_js_1.decodeAddress)(a), (0, decode_js_1.decodeAddress)(b));
}
+7
View File
@@ -0,0 +1,7 @@
import type { HashType } from '../secp256k1/types.js';
import type { Prefix } from './types.js';
/**
* @name evmToAddress
* @summary Converts an EVM address to its corresponding SS58 address.
*/
export declare function evmToAddress(evmAddress: string | Uint8Array, ss58Format?: Prefix, hashType?: HashType): string;
@@ -0,0 +1,17 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.evmToAddress = evmToAddress;
const util_1 = require("@pezkuwi/util");
const hasher_js_1 = require("../secp256k1/hasher.js");
const encode_js_1 = require("./encode.js");
/**
* @name evmToAddress
* @summary Converts an EVM address to its corresponding SS58 address.
*/
function evmToAddress(evmAddress, ss58Format, hashType = 'blake2') {
const message = (0, util_1.u8aConcat)('evm:', evmAddress);
if (message.length !== 24) {
throw new Error(`Converting ${evmAddress}: Invalid evm address length`);
}
return (0, encode_js_1.encodeAddress)((0, hasher_js_1.hasher)(hashType, message), ss58Format);
}
+16
View File
@@ -0,0 +1,16 @@
export { addressToEvm } from './addressToEvm.js';
export { checkAddress } from './check.js';
export { checkAddressChecksum } from './checksum.js';
export { decodeAddress } from './decode.js';
export { deriveAddress } from './derive.js';
export { encodeAddress } from './encode.js';
export { encodeDerivedAddress } from './encodeDerived.js';
export { encodeMultiAddress } from './encodeMulti.js';
export { addressEq } from './eq.js';
export { evmToAddress } from './evmToAddress.js';
export { isAddress } from './is.js';
export { createKeyDerived } from './keyDerived.js';
export { createKeyMulti } from './keyMulti.js';
export { sortAddresses } from './sort.js';
export { validateAddress } from './validate.js';
export { setSS58Format } from './setSS58Format.js';
+35
View File
@@ -0,0 +1,35 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.setSS58Format = exports.validateAddress = exports.sortAddresses = exports.createKeyMulti = exports.createKeyDerived = exports.isAddress = exports.evmToAddress = exports.addressEq = exports.encodeMultiAddress = exports.encodeDerivedAddress = exports.encodeAddress = exports.deriveAddress = exports.decodeAddress = exports.checkAddressChecksum = exports.checkAddress = exports.addressToEvm = void 0;
var addressToEvm_js_1 = require("./addressToEvm.js");
Object.defineProperty(exports, "addressToEvm", { enumerable: true, get: function () { return addressToEvm_js_1.addressToEvm; } });
var check_js_1 = require("./check.js");
Object.defineProperty(exports, "checkAddress", { enumerable: true, get: function () { return check_js_1.checkAddress; } });
var checksum_js_1 = require("./checksum.js");
Object.defineProperty(exports, "checkAddressChecksum", { enumerable: true, get: function () { return checksum_js_1.checkAddressChecksum; } });
var decode_js_1 = require("./decode.js");
Object.defineProperty(exports, "decodeAddress", { enumerable: true, get: function () { return decode_js_1.decodeAddress; } });
var derive_js_1 = require("./derive.js");
Object.defineProperty(exports, "deriveAddress", { enumerable: true, get: function () { return derive_js_1.deriveAddress; } });
var encode_js_1 = require("./encode.js");
Object.defineProperty(exports, "encodeAddress", { enumerable: true, get: function () { return encode_js_1.encodeAddress; } });
var encodeDerived_js_1 = require("./encodeDerived.js");
Object.defineProperty(exports, "encodeDerivedAddress", { enumerable: true, get: function () { return encodeDerived_js_1.encodeDerivedAddress; } });
var encodeMulti_js_1 = require("./encodeMulti.js");
Object.defineProperty(exports, "encodeMultiAddress", { enumerable: true, get: function () { return encodeMulti_js_1.encodeMultiAddress; } });
var eq_js_1 = require("./eq.js");
Object.defineProperty(exports, "addressEq", { enumerable: true, get: function () { return eq_js_1.addressEq; } });
var evmToAddress_js_1 = require("./evmToAddress.js");
Object.defineProperty(exports, "evmToAddress", { enumerable: true, get: function () { return evmToAddress_js_1.evmToAddress; } });
var is_js_1 = require("./is.js");
Object.defineProperty(exports, "isAddress", { enumerable: true, get: function () { return is_js_1.isAddress; } });
var keyDerived_js_1 = require("./keyDerived.js");
Object.defineProperty(exports, "createKeyDerived", { enumerable: true, get: function () { return keyDerived_js_1.createKeyDerived; } });
var keyMulti_js_1 = require("./keyMulti.js");
Object.defineProperty(exports, "createKeyMulti", { enumerable: true, get: function () { return keyMulti_js_1.createKeyMulti; } });
var sort_js_1 = require("./sort.js");
Object.defineProperty(exports, "sortAddresses", { enumerable: true, get: function () { return sort_js_1.sortAddresses; } });
var validate_js_1 = require("./validate.js");
Object.defineProperty(exports, "validateAddress", { enumerable: true, get: function () { return validate_js_1.validateAddress; } });
var setSS58Format_js_1 = require("./setSS58Format.js");
Object.defineProperty(exports, "setSS58Format", { enumerable: true, get: function () { return setSS58Format_js_1.setSS58Format; } });
+2
View File
@@ -0,0 +1,2 @@
import type { Prefix } from './types.js';
export declare function isAddress(address?: string | null, ignoreChecksum?: boolean, ss58Format?: Prefix): address is string;
+12
View File
@@ -0,0 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isAddress = isAddress;
const validate_js_1 = require("./validate.js");
function isAddress(address, ignoreChecksum, ss58Format) {
try {
return (0, validate_js_1.validateAddress)(address, ignoreChecksum, ss58Format);
}
catch {
return false;
}
}
+2
View File
@@ -0,0 +1,2 @@
import type { BN } from '@pezkuwi/util';
export declare function createKeyDerived(who: string | Uint8Array, index: bigint | BN | number): Uint8Array;
@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createKeyDerived = createKeyDerived;
const util_1 = require("@pezkuwi/util");
const asU8a_js_1 = require("../blake2/asU8a.js");
const bn_js_1 = require("../bn.js");
const decode_js_1 = require("./decode.js");
const PREFIX = (0, util_1.stringToU8a)('modlpy/utilisuba');
function createKeyDerived(who, index) {
return (0, asU8a_js_1.blake2AsU8a)((0, util_1.u8aConcat)(PREFIX, (0, decode_js_1.decodeAddress)(who), (0, util_1.bnToU8a)(index, bn_js_1.BN_LE_16_OPTS)));
}
+2
View File
@@ -0,0 +1,2 @@
import type { BN } from '@pezkuwi/util';
export declare function createKeyMulti(who: (string | Uint8Array)[], threshold: bigint | BN | number): Uint8Array;
@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createKeyMulti = createKeyMulti;
const util_1 = require("@pezkuwi/util");
const asU8a_js_1 = require("../blake2/asU8a.js");
const bn_js_1 = require("../bn.js");
const util_js_1 = require("./util.js");
const PREFIX = (0, util_1.stringToU8a)('modlpy/utilisuba');
function createKeyMulti(who, threshold) {
return (0, asU8a_js_1.blake2AsU8a)((0, util_1.u8aConcat)(PREFIX, (0, util_1.compactToU8a)(who.length), ...(0, util_1.u8aSorted)(who.map(util_js_1.addressToU8a)), (0, util_1.bnToU8a)(threshold, bn_js_1.BN_LE_16_OPTS)));
}
+6
View File
@@ -0,0 +1,6 @@
import type { Prefix } from './types.js';
/**
* @description Sets the global SS58 format to use for address encoding
* @deprecated Use keyring.setSS58Format
*/
export declare function setSS58Format(prefix: Prefix): void;
@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.setSS58Format = setSS58Format;
const util_1 = require("@pezkuwi/util");
const defaults_js_1 = require("./defaults.js");
const l = (0, util_1.logger)('setSS58Format');
/**
* @description Sets the global SS58 format to use for address encoding
* @deprecated Use keyring.setSS58Format
*/
function setSS58Format(prefix) {
l.warn('Global setting of the ss58Format is deprecated and not recommended. Set format on the keyring (if used) or as part of the address encode function');
defaults_js_1.defaults.prefix = prefix;
}
+2
View File
@@ -0,0 +1,2 @@
import type { Prefix } from './types.js';
export declare function sortAddresses(addresses: (string | Uint8Array)[], ss58Format?: Prefix): string[];
+10
View File
@@ -0,0 +1,10 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.sortAddresses = sortAddresses;
const util_1 = require("@pezkuwi/util");
const encode_js_1 = require("./encode.js");
const util_js_1 = require("./util.js");
function sortAddresses(addresses, ss58Format) {
const u8aToAddress = (u8a) => (0, encode_js_1.encodeAddress)(u8a, ss58Format);
return (0, util_1.u8aSorted)(addresses.map(util_js_1.addressToU8a)).map(u8aToAddress);
}
+1
View File
@@ -0,0 +1 @@
export declare function sshash(key: Uint8Array): Uint8Array;
@@ -0,0 +1,9 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.sshash = sshash;
const util_1 = require("@pezkuwi/util");
const asU8a_js_1 = require("../blake2/asU8a.js");
const SS58_PREFIX = (0, util_1.stringToU8a)('SS58PRE');
function sshash(key) {
return (0, asU8a_js_1.blake2AsU8a)((0, util_1.u8aConcat)(SS58_PREFIX, key), 512);
}
+1
View File
@@ -0,0 +1 @@
export type Prefix = number;
@@ -0,0 +1,2 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
+1
View File
@@ -0,0 +1 @@
export declare function addressToU8a(who: string | Uint8Array): Uint8Array;
+7
View File
@@ -0,0 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.addressToU8a = addressToU8a;
const decode_js_1 = require("./decode.js");
function addressToU8a(who) {
return (0, decode_js_1.decodeAddress)(who);
}
+2
View File
@@ -0,0 +1,2 @@
import type { Prefix } from './types.js';
export declare function validateAddress(encoded?: string | null, ignoreChecksum?: boolean, ss58Format?: Prefix): encoded is string;
@@ -0,0 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateAddress = validateAddress;
const decode_js_1 = require("./decode.js");
function validateAddress(encoded, ignoreChecksum, ss58Format) {
return !!(0, decode_js_1.decodeAddress)(encoded, ignoreChecksum, ss58Format);
}
+26
View File
@@ -0,0 +1,26 @@
/**
* @name base32Validate
* @summary Validates a base32 value.
* @description
* Validates that the supplied value is valid base32, throwing exceptions if not
*/
export declare const base32Validate: (value?: unknown, ipfsCompat?: boolean) => value is string;
/**
* @name isBase32
* @description Checks if the input is in base32, returning true/false
*/
export declare const isBase32: (value?: unknown, ipfsCompat?: boolean) => value is string;
/**
* @name base32Decode
* @summary Delookup a base32 value.
* @description
* From the provided input, decode the base32 and return the result as an `Uint8Array`.
*/
export declare const base32Decode: (value: string, ipfsCompat?: boolean) => Uint8Array;
/**
* @name base32Encode
* @summary Creates a base32 value.
* @description
* From the provided input, create the base32 and return the result as a string.
*/
export declare const base32Encode: (value: import("@pezkuwi/util/types").U8aLike, ipfsCompat?: boolean) => string;
+43
View File
@@ -0,0 +1,43 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.base32Encode = exports.base32Decode = exports.isBase32 = exports.base32Validate = void 0;
const base_1 = require("@scure/base");
const helpers_js_1 = require("./helpers.js");
const chars = 'abcdefghijklmnopqrstuvwxyz234567';
const config = {
chars,
coder: base_1.utils.chain(
// We define our own chain, the default base32 has padding
base_1.utils.radix2(5), base_1.utils.alphabet(chars), {
decode: (input) => input.split(''),
encode: (input) => input.join('')
}),
ipfs: 'b',
type: 'base32'
};
/**
* @name base32Validate
* @summary Validates a base32 value.
* @description
* Validates that the supplied value is valid base32, throwing exceptions if not
*/
exports.base32Validate = (0, helpers_js_1.createValidate)(config);
/**
* @name isBase32
* @description Checks if the input is in base32, returning true/false
*/
exports.isBase32 = (0, helpers_js_1.createIs)(exports.base32Validate);
/**
* @name base32Decode
* @summary Delookup a base32 value.
* @description
* From the provided input, decode the base32 and return the result as an `Uint8Array`.
*/
exports.base32Decode = (0, helpers_js_1.createDecode)(config, exports.base32Validate);
/**
* @name base32Encode
* @summary Creates a base32 value.
* @description
* From the provided input, create the base32 and return the result as a string.
*/
exports.base32Encode = (0, helpers_js_1.createEncode)(config);
+25
View File
@@ -0,0 +1,25 @@
import type { U8aLike } from '@pezkuwi/util/types';
export type { U8aLike } from '@pezkuwi/util/types';
interface Coder {
decode: (value: string) => Uint8Array;
encode: (value: Uint8Array) => string;
}
interface Config {
chars: string;
coder: Coder;
ipfs?: string;
regex?: RegExp;
type: string;
withPadding?: boolean;
}
type DecodeFn = (value: string, ipfsCompat?: boolean) => Uint8Array;
type EncodeFn = (value: U8aLike, ipfsCompat?: boolean) => string;
type ValidateFn = (value?: unknown, ipfsCompat?: boolean) => value is string;
/** @internal */
export declare function createDecode({ coder, ipfs }: Config, validate: ValidateFn): DecodeFn;
/** @internal */
export declare function createEncode({ coder, ipfs }: Config): EncodeFn;
/** @internal */
export declare function createIs(validate: ValidateFn): ValidateFn;
/** @internal */
export declare function createValidate({ chars, ipfs, type, withPadding }: Config): ValidateFn;
@@ -0,0 +1,67 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createDecode = createDecode;
exports.createEncode = createEncode;
exports.createIs = createIs;
exports.createValidate = createValidate;
const util_1 = require("@pezkuwi/util");
/** @internal */
function createDecode({ coder, ipfs }, validate) {
return (value, ipfsCompat) => {
validate(value, ipfsCompat);
return coder.decode(ipfs && ipfsCompat
? value.substring(1)
: value);
};
}
/** @internal */
function createEncode({ coder, ipfs }) {
return (value, ipfsCompat) => {
const out = coder.encode((0, util_1.u8aToU8a)(value));
return ipfs && ipfsCompat
? `${ipfs}${out}`
: out;
};
}
/** @internal */
function createIs(validate) {
return (value, ipfsCompat) => {
try {
return validate(value, ipfsCompat);
}
catch {
return false;
}
};
}
/** @internal */
function createValidate({ chars, ipfs, type, withPadding }) {
return (value, ipfsCompat) => {
if (typeof value !== 'string') {
throw new Error(`Expected ${type} string input`);
}
else if (ipfs && ipfsCompat && !value.startsWith(ipfs)) {
throw new Error(`Expected ipfs-compatible ${type} to start with '${ipfs}'`);
}
for (let i = (ipfsCompat ? 1 : 0), count = value.length; i < count; i++) {
if (chars.includes(value[i])) {
// all ok, character found
}
else if (withPadding && value[i] === '=') {
if (i === count - 1) {
// last character, everything ok
}
else if (value[i + 1] === '=') {
// next one is also padding, sequence ok
}
else {
throw new Error(`Invalid ${type} padding sequence "${value[i]}${value[i + 1]}" at index ${i}`);
}
}
else {
throw new Error(`Invalid ${type} character "${value[i]}" (0x${value.charCodeAt(i).toString(16)}) at index ${i}`);
}
}
return true;
};
}
+4
View File
@@ -0,0 +1,4 @@
/**
* @summary Encode and decode base32 values
*/
export { base32Decode, base32Encode, base32Validate, isBase32 } from './bs32.js';
+11
View File
@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isBase32 = exports.base32Validate = exports.base32Encode = exports.base32Decode = void 0;
/**
* @summary Encode and decode base32 values
*/
var bs32_js_1 = require("./bs32.js");
Object.defineProperty(exports, "base32Decode", { enumerable: true, get: function () { return bs32_js_1.base32Decode; } });
Object.defineProperty(exports, "base32Encode", { enumerable: true, get: function () { return bs32_js_1.base32Encode; } });
Object.defineProperty(exports, "base32Validate", { enumerable: true, get: function () { return bs32_js_1.base32Validate; } });
Object.defineProperty(exports, "isBase32", { enumerable: true, get: function () { return bs32_js_1.isBase32; } });
+26
View File
@@ -0,0 +1,26 @@
/**
* @name base58Validate
* @summary Validates a base58 value.
* @description
* Validates that the supplied value is valid base58, throwing exceptions if not
*/
export declare const base58Validate: (value?: unknown, ipfsCompat?: boolean) => value is string;
/**
* @name base58Decode
* @summary Decodes a base58 value.
* @description
* From the provided input, decode the base58 and return the result as an `Uint8Array`.
*/
export declare const base58Decode: (value: string, ipfsCompat?: boolean) => Uint8Array;
/**
* @name base58Encode
* @summary Creates a base58 value.
* @description
* From the provided input, create the base58 and return the result as a string.
*/
export declare const base58Encode: (value: import("@pezkuwi/util/types").U8aLike, ipfsCompat?: boolean) => string;
/**
* @name isBase58
* @description Checks if the input is in base58, returning true/false
*/
export declare const isBase58: (value?: unknown, ipfsCompat?: boolean) => value is string;
+37
View File
@@ -0,0 +1,37 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isBase58 = exports.base58Encode = exports.base58Decode = exports.base58Validate = void 0;
const base_1 = require("@scure/base");
const helpers_js_1 = require("../base32/helpers.js");
const config = {
chars: '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz',
coder: base_1.base58,
ipfs: 'z',
type: 'base58'
};
/**
* @name base58Validate
* @summary Validates a base58 value.
* @description
* Validates that the supplied value is valid base58, throwing exceptions if not
*/
exports.base58Validate = (0, helpers_js_1.createValidate)(config);
/**
* @name base58Decode
* @summary Decodes a base58 value.
* @description
* From the provided input, decode the base58 and return the result as an `Uint8Array`.
*/
exports.base58Decode = (0, helpers_js_1.createDecode)(config, exports.base58Validate);
/**
* @name base58Encode
* @summary Creates a base58 value.
* @description
* From the provided input, create the base58 and return the result as a string.
*/
exports.base58Encode = (0, helpers_js_1.createEncode)(config);
/**
* @name isBase58
* @description Checks if the input is in base58, returning true/false
*/
exports.isBase58 = (0, helpers_js_1.createIs)(exports.base58Validate);
+4
View File
@@ -0,0 +1,4 @@
/**
* @summary Encode and decode base58 values
*/
export { base58Decode, base58Encode, base58Validate, isBase58 } from './bs58.js';
+11
View File
@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isBase58 = exports.base58Validate = exports.base58Encode = exports.base58Decode = void 0;
/**
* @summary Encode and decode base58 values
*/
var bs58_js_1 = require("./bs58.js");
Object.defineProperty(exports, "base58Decode", { enumerable: true, get: function () { return bs58_js_1.base58Decode; } });
Object.defineProperty(exports, "base58Encode", { enumerable: true, get: function () { return bs58_js_1.base58Encode; } });
Object.defineProperty(exports, "base58Validate", { enumerable: true, get: function () { return bs58_js_1.base58Validate; } });
Object.defineProperty(exports, "isBase58", { enumerable: true, get: function () { return bs58_js_1.isBase58; } });
+26
View File
@@ -0,0 +1,26 @@
/**
* @name base64Validate
* @summary Validates a base64 value.
* @description
* Validates that the supplied value is valid base64
*/
export declare const base64Validate: (value?: unknown, ipfsCompat?: boolean) => value is string;
/**
* @name isBase64
* @description Checks if the input is in base64, returning true/false
*/
export declare const isBase64: (value?: unknown, ipfsCompat?: boolean) => value is string;
/**
* @name base64Decode
* @summary Decodes a base64 value.
* @description
* From the provided input, decode the base64 and return the result as an `Uint8Array`.
*/
export declare const base64Decode: (value: string, ipfsCompat?: boolean) => Uint8Array;
/**
* @name base64Encode
* @summary Creates a base64 value.
* @description
* From the provided input, create the base64 and return the result as a string.
*/
export declare const base64Encode: (value: import("@pezkuwi/util/types").U8aLike, ipfsCompat?: boolean) => string;
+37
View File
@@ -0,0 +1,37 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.base64Encode = exports.base64Decode = exports.isBase64 = exports.base64Validate = void 0;
const base_1 = require("@scure/base");
const helpers_js_1 = require("../base32/helpers.js");
const config = {
chars: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/',
coder: base_1.base64,
type: 'base64',
withPadding: true
};
/**
* @name base64Validate
* @summary Validates a base64 value.
* @description
* Validates that the supplied value is valid base64
*/
exports.base64Validate = (0, helpers_js_1.createValidate)(config);
/**
* @name isBase64
* @description Checks if the input is in base64, returning true/false
*/
exports.isBase64 = (0, helpers_js_1.createIs)(exports.base64Validate);
/**
* @name base64Decode
* @summary Decodes a base64 value.
* @description
* From the provided input, decode the base64 and return the result as an `Uint8Array`.
*/
exports.base64Decode = (0, helpers_js_1.createDecode)(config, exports.base64Validate);
/**
* @name base64Encode
* @summary Creates a base64 value.
* @description
* From the provided input, create the base64 and return the result as a string.
*/
exports.base64Encode = (0, helpers_js_1.createEncode)(config);
+6
View File
@@ -0,0 +1,6 @@
/**
* @summary Encode and decode base64 values
*/
export { base64Decode, base64Encode, base64Validate, isBase64 } from './bs64.js';
export { base64Pad } from './pad.js';
export { base64Trim } from './trim.js';
+15
View File
@@ -0,0 +1,15 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.base64Trim = exports.base64Pad = exports.isBase64 = exports.base64Validate = exports.base64Encode = exports.base64Decode = void 0;
/**
* @summary Encode and decode base64 values
*/
var bs64_js_1 = require("./bs64.js");
Object.defineProperty(exports, "base64Decode", { enumerable: true, get: function () { return bs64_js_1.base64Decode; } });
Object.defineProperty(exports, "base64Encode", { enumerable: true, get: function () { return bs64_js_1.base64Encode; } });
Object.defineProperty(exports, "base64Validate", { enumerable: true, get: function () { return bs64_js_1.base64Validate; } });
Object.defineProperty(exports, "isBase64", { enumerable: true, get: function () { return bs64_js_1.isBase64; } });
var pad_js_1 = require("./pad.js");
Object.defineProperty(exports, "base64Pad", { enumerable: true, get: function () { return pad_js_1.base64Pad; } });
var trim_js_1 = require("./trim.js");
Object.defineProperty(exports, "base64Trim", { enumerable: true, get: function () { return trim_js_1.base64Trim; } });
+5
View File
@@ -0,0 +1,5 @@
/**
* @name base64Pad
* @description Adds padding characters for correct length
*/
export declare function base64Pad(value: string): string;
+10
View File
@@ -0,0 +1,10 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.base64Pad = base64Pad;
/**
* @name base64Pad
* @description Adds padding characters for correct length
*/
function base64Pad(value) {
return value.padEnd(value.length + (value.length % 4), '=');
}
+5
View File
@@ -0,0 +1,5 @@
/**
* @name base64Trim
* @description Trims padding characters
*/
export declare function base64Trim(value: string): string;
+13
View File
@@ -0,0 +1,13 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.base64Trim = base64Trim;
/**
* @name base64Trim
* @description Trims padding characters
*/
function base64Trim(value) {
while (value.length && value.endsWith('=')) {
value = value.slice(0, -1);
}
return value;
}
+20
View File
@@ -0,0 +1,20 @@
/**
* @name blake2AsU8a
* @summary Creates a blake2b u8a from the input.
* @description
* From a `Uint8Array` input, create the blake2b and return the result as a u8a with the specified `bitLength`.
* @example
* <BR>
*
* ```javascript
* import { blake2AsU8a } from '@pezkuwi/util-crypto';
*
* blake2AsU8a('abc'); // => [0xba, 0x80, 0xa5, 0x3f, 0x98, 0x1c, 0x4d, 0x0d]
* ```
*/
export declare function blake2AsU8a(data: string | Uint8Array, bitLength?: 64 | 128 | 256 | 384 | 512, key?: Uint8Array | null, onlyJs?: boolean): Uint8Array;
/**
* @name blake2AsHex
* @description Creates a blake2b hex from the input.
*/
export declare const blake2AsHex: (data: string | Uint8Array, bitLength?: 256 | 512 | 64 | 128 | 384 | undefined, key?: Uint8Array | null | undefined, onlyJs?: boolean | undefined) => import("@pezkuwi/util/types").HexString;
+36
View File
@@ -0,0 +1,36 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.blake2AsHex = void 0;
exports.blake2AsU8a = blake2AsU8a;
const blake2b_1 = require("@noble/hashes/blake2b");
const util_1 = require("@pezkuwi/util");
const wasm_crypto_1 = require("@pezkuwi/wasm-crypto");
const helpers_js_1 = require("../helpers.js");
/**
* @name blake2AsU8a
* @summary Creates a blake2b u8a from the input.
* @description
* From a `Uint8Array` input, create the blake2b and return the result as a u8a with the specified `bitLength`.
* @example
* <BR>
*
* ```javascript
* import { blake2AsU8a } from '@pezkuwi/util-crypto';
*
* blake2AsU8a('abc'); // => [0xba, 0x80, 0xa5, 0x3f, 0x98, 0x1c, 0x4d, 0x0d]
* ```
*/
function blake2AsU8a(data, bitLength = 256, key, onlyJs) {
const byteLength = Math.ceil(bitLength / 8);
const u8a = (0, util_1.u8aToU8a)(data);
return !util_1.hasBigInt || (!onlyJs && (0, wasm_crypto_1.isReady)())
? (0, wasm_crypto_1.blake2b)(u8a, (0, util_1.u8aToU8a)(key), byteLength)
: key
? (0, blake2b_1.blake2b)(u8a, { dkLen: byteLength, key })
: (0, blake2b_1.blake2b)(u8a, { dkLen: byteLength });
}
/**
* @name blake2AsHex
* @description Creates a blake2b hex from the input.
*/
exports.blake2AsHex = (0, helpers_js_1.createAsHex)(blake2AsU8a);
+4
View File
@@ -0,0 +1,4 @@
/**
* @summary Create blake2b values with specified bitlengths
*/
export { blake2AsHex, blake2AsU8a } from './asU8a.js';
+9
View File
@@ -0,0 +1,9 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.blake2AsU8a = exports.blake2AsHex = void 0;
/**
* @summary Create blake2b values with specified bitlengths
*/
var asU8a_js_1 = require("./asU8a.js");
Object.defineProperty(exports, "blake2AsHex", { enumerable: true, get: function () { return asU8a_js_1.blake2AsHex; } });
Object.defineProperty(exports, "blake2AsU8a", { enumerable: true, get: function () { return asU8a_js_1.blake2AsU8a; } });
+30
View File
@@ -0,0 +1,30 @@
export declare const BN_BE_OPTS: {
isLe: boolean;
};
export declare const BN_LE_OPTS: {
isLe: boolean;
};
export declare const BN_LE_16_OPTS: {
bitLength: number;
isLe: boolean;
};
export declare const BN_BE_32_OPTS: {
bitLength: number;
isLe: boolean;
};
export declare const BN_LE_32_OPTS: {
bitLength: number;
isLe: boolean;
};
export declare const BN_BE_256_OPTS: {
bitLength: number;
isLe: boolean;
};
export declare const BN_LE_256_OPTS: {
bitLength: number;
isLe: boolean;
};
export declare const BN_LE_512_OPTS: {
bitLength: number;
isLe: boolean;
};
+11
View File
@@ -0,0 +1,11 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BN_LE_512_OPTS = exports.BN_LE_256_OPTS = exports.BN_BE_256_OPTS = exports.BN_LE_32_OPTS = exports.BN_BE_32_OPTS = exports.BN_LE_16_OPTS = exports.BN_LE_OPTS = exports.BN_BE_OPTS = void 0;
exports.BN_BE_OPTS = { isLe: false };
exports.BN_LE_OPTS = { isLe: true };
exports.BN_LE_16_OPTS = { bitLength: 16, isLe: true };
exports.BN_BE_32_OPTS = { bitLength: 32, isLe: false };
exports.BN_LE_32_OPTS = { bitLength: 32, isLe: true };
exports.BN_BE_256_OPTS = { bitLength: 256, isLe: false };
exports.BN_LE_256_OPTS = { bitLength: 256, isLe: true };
exports.BN_LE_512_OPTS = { bitLength: 512, isLe: true };
+26
View File
@@ -0,0 +1,26 @@
import './bundleInit.js';
export { packageInfo } from './packageInfo.js';
export * from './address/index.js';
export * from './base32/index.js';
export * from './base58/index.js';
export * from './base64/index.js';
export * from './blake2/index.js';
export * from './crypto.js';
export * from './ed25519/index.js';
export * from './ethereum/index.js';
export * from './hd/index.js';
export * from './hmac/index.js';
export * from './json/index.js';
export * from './keccak/index.js';
export * from './key/index.js';
export * from './mnemonic/index.js';
export * from './nacl/index.js';
export * from './networks.js';
export * from './pbkdf2/index.js';
export * from './random/index.js';
export * from './scrypt/index.js';
export * from './secp256k1/index.js';
export * from './sha/index.js';
export * from './signature/index.js';
export * from './sr25519/index.js';
export * from './xxhash/index.js';
+31
View File
@@ -0,0 +1,31 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.packageInfo = void 0;
const tslib_1 = require("tslib");
require("./bundleInit.js");
var packageInfo_js_1 = require("./packageInfo.js");
Object.defineProperty(exports, "packageInfo", { enumerable: true, get: function () { return packageInfo_js_1.packageInfo; } });
tslib_1.__exportStar(require("./address/index.js"), exports);
tslib_1.__exportStar(require("./base32/index.js"), exports);
tslib_1.__exportStar(require("./base58/index.js"), exports);
tslib_1.__exportStar(require("./base64/index.js"), exports);
tslib_1.__exportStar(require("./blake2/index.js"), exports);
tslib_1.__exportStar(require("./crypto.js"), exports);
tslib_1.__exportStar(require("./ed25519/index.js"), exports);
tslib_1.__exportStar(require("./ethereum/index.js"), exports);
tslib_1.__exportStar(require("./hd/index.js"), exports);
tslib_1.__exportStar(require("./hmac/index.js"), exports);
tslib_1.__exportStar(require("./json/index.js"), exports);
tslib_1.__exportStar(require("./keccak/index.js"), exports);
tslib_1.__exportStar(require("./key/index.js"), exports);
tslib_1.__exportStar(require("./mnemonic/index.js"), exports);
tslib_1.__exportStar(require("./nacl/index.js"), exports);
tslib_1.__exportStar(require("./networks.js"), exports);
tslib_1.__exportStar(require("./pbkdf2/index.js"), exports);
tslib_1.__exportStar(require("./random/index.js"), exports);
tslib_1.__exportStar(require("./scrypt/index.js"), exports);
tslib_1.__exportStar(require("./secp256k1/index.js"), exports);
tslib_1.__exportStar(require("./sha/index.js"), exports);
tslib_1.__exportStar(require("./signature/index.js"), exports);
tslib_1.__exportStar(require("./sr25519/index.js"), exports);
tslib_1.__exportStar(require("./xxhash/index.js"), exports);
+1
View File
@@ -0,0 +1 @@
import '@pezkuwi/x-bigint/shim';
+7
View File
@@ -0,0 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
require("@pezkuwi/x-bigint/shim");
const crypto_js_1 = require("./crypto.js");
(0, crypto_js_1.cryptoWaitReady)().catch(() => {
// shouldn't happen, logged and caught inside cryptoWaitReady
});
+3
View File
@@ -0,0 +1,3 @@
import { isReady } from '@pezkuwi/wasm-crypto';
export declare const cryptoIsReady: typeof isReady;
export declare function cryptoWaitReady(): Promise<boolean>;
+16
View File
@@ -0,0 +1,16 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.cryptoIsReady = void 0;
exports.cryptoWaitReady = cryptoWaitReady;
const wasm_crypto_1 = require("@pezkuwi/wasm-crypto");
exports.cryptoIsReady = wasm_crypto_1.isReady;
function cryptoWaitReady() {
return (0, wasm_crypto_1.waitReady)()
.then(() => {
if (!(0, wasm_crypto_1.isReady)()) {
throw new Error('Unable to initialize @pezkuwi/util-crypto');
}
return true;
})
.catch(() => false);
}
+1
View File
@@ -0,0 +1 @@
export declare function ed25519DeriveHard(seed: Uint8Array, chainCode: Uint8Array): Uint8Array;
@@ -0,0 +1,12 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ed25519DeriveHard = ed25519DeriveHard;
const util_1 = require("@pezkuwi/util");
const asU8a_js_1 = require("../blake2/asU8a.js");
const HDKD = (0, util_1.compactAddLength)((0, util_1.stringToU8a)('Ed25519HDKD'));
function ed25519DeriveHard(seed, chainCode) {
if (!(0, util_1.isU8a)(chainCode) || chainCode.length !== 32) {
throw new Error('Invalid chainCode passed to derive');
}
return (0, asU8a_js_1.blake2AsU8a)((0, util_1.u8aConcat)(HDKD, seed, chainCode));
}
+10
View File
@@ -0,0 +1,10 @@
/**
* @summary Implements ed25519 operations
*/
export { ed25519DeriveHard } from './deriveHard.js';
export { ed25519PairFromRandom } from './pair/fromRandom.js';
export { ed25519PairFromSecret } from './pair/fromSecret.js';
export { ed25519PairFromSeed } from './pair/fromSeed.js';
export { ed25519PairFromString } from './pair/fromString.js';
export { ed25519Sign } from './sign.js';
export { ed25519Verify } from './verify.js';
+20
View File
@@ -0,0 +1,20 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ed25519Verify = exports.ed25519Sign = exports.ed25519PairFromString = exports.ed25519PairFromSeed = exports.ed25519PairFromSecret = exports.ed25519PairFromRandom = exports.ed25519DeriveHard = void 0;
/**
* @summary Implements ed25519 operations
*/
var deriveHard_js_1 = require("./deriveHard.js");
Object.defineProperty(exports, "ed25519DeriveHard", { enumerable: true, get: function () { return deriveHard_js_1.ed25519DeriveHard; } });
var fromRandom_js_1 = require("./pair/fromRandom.js");
Object.defineProperty(exports, "ed25519PairFromRandom", { enumerable: true, get: function () { return fromRandom_js_1.ed25519PairFromRandom; } });
var fromSecret_js_1 = require("./pair/fromSecret.js");
Object.defineProperty(exports, "ed25519PairFromSecret", { enumerable: true, get: function () { return fromSecret_js_1.ed25519PairFromSecret; } });
var fromSeed_js_1 = require("./pair/fromSeed.js");
Object.defineProperty(exports, "ed25519PairFromSeed", { enumerable: true, get: function () { return fromSeed_js_1.ed25519PairFromSeed; } });
var fromString_js_1 = require("./pair/fromString.js");
Object.defineProperty(exports, "ed25519PairFromString", { enumerable: true, get: function () { return fromString_js_1.ed25519PairFromString; } });
var sign_js_1 = require("./sign.js");
Object.defineProperty(exports, "ed25519Sign", { enumerable: true, get: function () { return sign_js_1.ed25519Sign; } });
var verify_js_1 = require("./verify.js");
Object.defineProperty(exports, "ed25519Verify", { enumerable: true, get: function () { return verify_js_1.ed25519Verify; } });
+16
View File
@@ -0,0 +1,16 @@
import type { Keypair } from '../../types.js';
/**
* @name ed25519PairFromRandom
* @summary Creates a new public/secret keypair.
* @description
* Returns a new generate object containing a `publicKey` & `secretKey`.
* @example
* <BR>
*
* ```javascript
* import { ed25519PairFromRandom } from '@pezkuwi/util-crypto';
*
* ed25519PairFromRandom(); // => { secretKey: [...], publicKey: [...] }
* ```
*/
export declare function ed25519PairFromRandom(): Keypair;
@@ -0,0 +1,22 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ed25519PairFromRandom = ed25519PairFromRandom;
const index_js_1 = require("../../random/index.js");
const fromSeed_js_1 = require("./fromSeed.js");
/**
* @name ed25519PairFromRandom
* @summary Creates a new public/secret keypair.
* @description
* Returns a new generate object containing a `publicKey` & `secretKey`.
* @example
* <BR>
*
* ```javascript
* import { ed25519PairFromRandom } from '@pezkuwi/util-crypto';
*
* ed25519PairFromRandom(); // => { secretKey: [...], publicKey: [...] }
* ```
*/
function ed25519PairFromRandom() {
return (0, fromSeed_js_1.ed25519PairFromSeed)((0, index_js_1.randomAsU8a)());
}
+16
View File
@@ -0,0 +1,16 @@
import type { Keypair } from '../../types.js';
/**
* @name ed25519PairFromSecret
* @summary Creates a new public/secret keypair from a secret.
* @description
* Returns a object containing a `publicKey` & `secretKey` generated from the supplied secret.
* @example
* <BR>
*
* ```javascript
* import { ed25519PairFromSecret } from '@pezkuwi/util-crypto';
*
* ed25519PairFromSecret(...); // => { secretKey: [...], publicKey: [...] }
* ```
*/
export declare function ed25519PairFromSecret(secretKey: Uint8Array): Keypair;
@@ -0,0 +1,26 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ed25519PairFromSecret = ed25519PairFromSecret;
/**
* @name ed25519PairFromSecret
* @summary Creates a new public/secret keypair from a secret.
* @description
* Returns a object containing a `publicKey` & `secretKey` generated from the supplied secret.
* @example
* <BR>
*
* ```javascript
* import { ed25519PairFromSecret } from '@pezkuwi/util-crypto';
*
* ed25519PairFromSecret(...); // => { secretKey: [...], publicKey: [...] }
* ```
*/
function ed25519PairFromSecret(secretKey) {
if (secretKey.length !== 64) {
throw new Error('Invalid secretKey provided');
}
return {
publicKey: secretKey.slice(32),
secretKey
};
}
+16
View File
@@ -0,0 +1,16 @@
import type { Keypair } from '../../types.js';
/**
* @name ed25519PairFromSeed
* @summary Creates a new public/secret keypair from a seed.
* @description
* Returns a object containing a `publicKey` & `secretKey` generated from the supplied seed.
* @example
* <BR>
*
* ```javascript
* import { ed25519PairFromSeed } from '@pezkuwi/util-crypto';
*
* ed25519PairFromSeed(...); // => { secretKey: [...], publicKey: [...] }
* ```
*/
export declare function ed25519PairFromSeed(seed: Uint8Array, onlyJs?: boolean): Keypair;
@@ -0,0 +1,34 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ed25519PairFromSeed = ed25519PairFromSeed;
const ed25519_1 = require("@noble/curves/ed25519");
const util_1 = require("@pezkuwi/util");
const wasm_crypto_1 = require("@pezkuwi/wasm-crypto");
/**
* @name ed25519PairFromSeed
* @summary Creates a new public/secret keypair from a seed.
* @description
* Returns a object containing a `publicKey` & `secretKey` generated from the supplied seed.
* @example
* <BR>
*
* ```javascript
* import { ed25519PairFromSeed } from '@pezkuwi/util-crypto';
*
* ed25519PairFromSeed(...); // => { secretKey: [...], publicKey: [...] }
* ```
*/
function ed25519PairFromSeed(seed, onlyJs) {
if (!util_1.hasBigInt || (!onlyJs && (0, wasm_crypto_1.isReady)())) {
const full = (0, wasm_crypto_1.ed25519KeypairFromSeed)(seed);
return {
publicKey: full.slice(32),
secretKey: full.slice(0, 64)
};
}
const publicKey = ed25519_1.ed25519.getPublicKey(seed);
return {
publicKey,
secretKey: (0, util_1.u8aConcatStrict)([seed, publicKey])
};
}
+16
View File
@@ -0,0 +1,16 @@
import type { Keypair } from '../../types.js';
/**
* @name ed25519PairFromString
* @summary Creates a new public/secret keypair from a string.
* @description
* Returns a object containing a `publicKey` & `secretKey` generated from the supplied string. The string is hashed and the value used as the input seed.
* @example
* <BR>
*
* ```javascript
* import { ed25519PairFromString } from '@pezkuwi/util-crypto';
*
* ed25519PairFromString('test'); // => { secretKey: [...], publicKey: [...] }
* ```
*/
export declare function ed25519PairFromString(value: string): Keypair;
@@ -0,0 +1,23 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ed25519PairFromString = ed25519PairFromString;
const util_1 = require("@pezkuwi/util");
const asU8a_js_1 = require("../../blake2/asU8a.js");
const fromSeed_js_1 = require("./fromSeed.js");
/**
* @name ed25519PairFromString
* @summary Creates a new public/secret keypair from a string.
* @description
* Returns a object containing a `publicKey` & `secretKey` generated from the supplied string. The string is hashed and the value used as the input seed.
* @example
* <BR>
*
* ```javascript
* import { ed25519PairFromString } from '@pezkuwi/util-crypto';
*
* ed25519PairFromString('test'); // => { secretKey: [...], publicKey: [...] }
* ```
*/
function ed25519PairFromString(value) {
return (0, fromSeed_js_1.ed25519PairFromSeed)((0, asU8a_js_1.blake2AsU8a)((0, util_1.stringToU8a)(value)));
}
+16
View File
@@ -0,0 +1,16 @@
import type { Keypair } from '../types.js';
/**
* @name ed25519Sign
* @summary Signs a message using the supplied secretKey
* @description
* Returns message signature of `message`, using the `secretKey`.
* @example
* <BR>
*
* ```javascript
* import { ed25519Sign } from '@pezkuwi/util-crypto';
*
* ed25519Sign([...], [...]); // => [...]
* ```
*/
export declare function ed25519Sign(message: string | Uint8Array, { publicKey, secretKey }: Partial<Keypair>, onlyJs?: boolean): Uint8Array;
+33
View File
@@ -0,0 +1,33 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ed25519Sign = ed25519Sign;
const ed25519_1 = require("@noble/curves/ed25519");
const util_1 = require("@pezkuwi/util");
const wasm_crypto_1 = require("@pezkuwi/wasm-crypto");
/**
* @name ed25519Sign
* @summary Signs a message using the supplied secretKey
* @description
* Returns message signature of `message`, using the `secretKey`.
* @example
* <BR>
*
* ```javascript
* import { ed25519Sign } from '@pezkuwi/util-crypto';
*
* ed25519Sign([...], [...]); // => [...]
* ```
*/
function ed25519Sign(message, { publicKey, secretKey }, onlyJs) {
if (!secretKey) {
throw new Error('Expected a valid secretKey');
}
else if (!publicKey) {
throw new Error('Expected a valid publicKey');
}
const messageU8a = (0, util_1.u8aToU8a)(message);
const privateU8a = secretKey.subarray(0, 32);
return !util_1.hasBigInt || (!onlyJs && (0, wasm_crypto_1.isReady)())
? (0, wasm_crypto_1.ed25519Sign)(publicKey, privateU8a, messageU8a)
: ed25519_1.ed25519.sign(messageU8a, privateU8a);
}
+15
View File
@@ -0,0 +1,15 @@
/**
* @name ed25519Sign
* @summary Verifies the signature on the supplied message.
* @description
* Verifies the `signature` on `message` with the supplied `publicKey`. Returns `true` on sucess, `false` otherwise.
* @example
* <BR>
*
* ```javascript
* import { ed25519Verify } from '@pezkuwi/util-crypto';
*
* ed25519Verify([...], [...], [...]); // => true/false
* ```
*/
export declare function ed25519Verify(message: string | Uint8Array, signature: string | Uint8Array, publicKey: string | Uint8Array, onlyJs?: boolean): boolean;
@@ -0,0 +1,39 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ed25519Verify = ed25519Verify;
const ed25519_1 = require("@noble/curves/ed25519");
const util_1 = require("@pezkuwi/util");
const wasm_crypto_1 = require("@pezkuwi/wasm-crypto");
/**
* @name ed25519Sign
* @summary Verifies the signature on the supplied message.
* @description
* Verifies the `signature` on `message` with the supplied `publicKey`. Returns `true` on sucess, `false` otherwise.
* @example
* <BR>
*
* ```javascript
* import { ed25519Verify } from '@pezkuwi/util-crypto';
*
* ed25519Verify([...], [...], [...]); // => true/false
* ```
*/
function ed25519Verify(message, signature, publicKey, onlyJs) {
const messageU8a = (0, util_1.u8aToU8a)(message);
const publicKeyU8a = (0, util_1.u8aToU8a)(publicKey);
const signatureU8a = (0, util_1.u8aToU8a)(signature);
if (publicKeyU8a.length !== 32) {
throw new Error(`Invalid publicKey, received ${publicKeyU8a.length}, expected 32`);
}
else if (signatureU8a.length !== 64) {
throw new Error(`Invalid signature, received ${signatureU8a.length} bytes, expected 64`);
}
try {
return !util_1.hasBigInt || (!onlyJs && (0, wasm_crypto_1.isReady)())
? (0, wasm_crypto_1.ed25519Verify)(signatureU8a, messageU8a, publicKeyU8a)
: ed25519_1.ed25519.verify(signatureU8a, messageU8a, publicKeyU8a);
}
catch {
return false;
}
}
+2
View File
@@ -0,0 +1,2 @@
import type { HexString } from '@pezkuwi/util/types';
export declare function ethereumEncode(addressOrPublic?: string | Uint8Array): HexString;
@@ -0,0 +1,28 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ethereumEncode = ethereumEncode;
const util_1 = require("@pezkuwi/util");
const index_js_1 = require("../keccak/index.js");
const index_js_2 = require("../secp256k1/index.js");
function getH160(u8a) {
if ([33, 65].includes(u8a.length)) {
u8a = (0, index_js_1.keccakAsU8a)((0, index_js_2.secp256k1Expand)(u8a));
}
return u8a.slice(-20);
}
function ethereumEncode(addressOrPublic) {
if (!addressOrPublic) {
return '0x';
}
const u8aAddress = (0, util_1.u8aToU8a)(addressOrPublic);
if (![20, 32, 33, 65].includes(u8aAddress.length)) {
throw new Error(`Invalid address or publicKey provided, received ${u8aAddress.length} bytes input`);
}
const address = (0, util_1.u8aToHex)(getH160(u8aAddress), -1, false);
const hash = (0, util_1.u8aToHex)((0, index_js_1.keccakAsU8a)(address), -1, false);
let result = '';
for (let i = 0; i < 40; i++) {
result = `${result}${parseInt(hash[i], 16) > 7 ? address[i].toUpperCase() : address[i]}`;
}
return `0x${result}`;
}
+3
View File
@@ -0,0 +1,3 @@
export { ethereumEncode } from './encode.js';
export { isEthereumAddress } from './isAddress.js';
export { isEthereumChecksum } from './isChecksum.js';
@@ -0,0 +1,9 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isEthereumChecksum = exports.isEthereumAddress = exports.ethereumEncode = void 0;
var encode_js_1 = require("./encode.js");
Object.defineProperty(exports, "ethereumEncode", { enumerable: true, get: function () { return encode_js_1.ethereumEncode; } });
var isAddress_js_1 = require("./isAddress.js");
Object.defineProperty(exports, "isEthereumAddress", { enumerable: true, get: function () { return isAddress_js_1.isEthereumAddress; } });
var isChecksum_js_1 = require("./isChecksum.js");
Object.defineProperty(exports, "isEthereumChecksum", { enumerable: true, get: function () { return isChecksum_js_1.isEthereumChecksum; } });
+1
View File
@@ -0,0 +1 @@
export declare function isEthereumAddress(address?: string): boolean;
@@ -0,0 +1,14 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isEthereumAddress = isEthereumAddress;
const util_1 = require("@pezkuwi/util");
const isChecksum_js_1 = require("./isChecksum.js");
function isEthereumAddress(address) {
if (!address || address.length !== 42 || !(0, util_1.isHex)(address)) {
return false;
}
else if (/^(0x)?[0-9a-f]{40}$/.test(address) || /^(0x)?[0-9A-F]{40}$/.test(address)) {
return true;
}
return (0, isChecksum_js_1.isEthereumChecksum)(address);
}
+1
View File
@@ -0,0 +1 @@
export declare function isEthereumChecksum(_address: string): boolean;
@@ -0,0 +1,20 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.isEthereumChecksum = isEthereumChecksum;
const util_1 = require("@pezkuwi/util");
const index_js_1 = require("../keccak/index.js");
function isInvalidChar(char, byte) {
return char !== (byte > 7
? char.toUpperCase()
: char.toLowerCase());
}
function isEthereumChecksum(_address) {
const address = _address.replace('0x', '');
const hash = (0, util_1.u8aToHex)((0, index_js_1.keccakAsU8a)(address.toLowerCase()), -1, false);
for (let i = 0; i < 40; i++) {
if (isInvalidChar(address[i], parseInt(hash[i], 16))) {
return false;
}
}
return true;
}
+2
View File
@@ -0,0 +1,2 @@
import type { Keypair } from '../../types.js';
export declare function hdEthereum(seed: Uint8Array, path?: string): Keypair;
@@ -0,0 +1,47 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.hdEthereum = hdEthereum;
const util_1 = require("@pezkuwi/util");
const bn_js_1 = require("../../bn.js");
const index_js_1 = require("../../hmac/index.js");
const index_js_2 = require("../../secp256k1/index.js");
const validatePath_js_1 = require("../validatePath.js");
const MASTER_SECRET = (0, util_1.stringToU8a)('Bitcoin seed');
function createCoded(secretKey, chainCode) {
return {
chainCode,
publicKey: (0, index_js_2.secp256k1PairFromSeed)(secretKey).publicKey,
secretKey
};
}
function deriveChild(hd, index) {
const indexBuffer = (0, util_1.bnToU8a)(index, bn_js_1.BN_BE_32_OPTS);
const data = index >= validatePath_js_1.HARDENED
? (0, util_1.u8aConcat)(new Uint8Array(1), hd.secretKey, indexBuffer)
: (0, util_1.u8aConcat)(hd.publicKey, indexBuffer);
try {
const I = (0, index_js_1.hmacShaAsU8a)(hd.chainCode, data, 512);
return createCoded((0, index_js_2.secp256k1PrivateKeyTweakAdd)(hd.secretKey, I.slice(0, 32)), I.slice(32));
}
catch {
// In case parse256(IL) >= n or ki == 0, proceed with the next value for i
return deriveChild(hd, index + 1);
}
}
function hdEthereum(seed, path = '') {
const I = (0, index_js_1.hmacShaAsU8a)(MASTER_SECRET, seed, 512);
let hd = createCoded(I.slice(0, 32), I.slice(32));
if (!path || path === 'm' || path === 'M' || path === "m'" || path === "M'") {
return hd;
}
if (!(0, validatePath_js_1.hdValidatePath)(path)) {
throw new Error('Invalid derivation path');
}
const parts = path.split('/').slice(1);
for (const p of parts) {
hd = deriveChild(hd, parseInt(p, 10) + ((p.length > 1) && p.endsWith("'")
? validatePath_js_1.HARDENED
: 0));
}
return hd;
}
+3
View File
@@ -0,0 +1,3 @@
export { hdEthereum } from './ethereum/index.js';
export { hdLedger } from './ledger/index.js';
export { hdValidatePath } from './validatePath.js';
+9
View File
@@ -0,0 +1,9 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.hdValidatePath = exports.hdLedger = exports.hdEthereum = void 0;
var index_js_1 = require("./ethereum/index.js");
Object.defineProperty(exports, "hdEthereum", { enumerable: true, get: function () { return index_js_1.hdEthereum; } });
var index_js_2 = require("./ledger/index.js");
Object.defineProperty(exports, "hdLedger", { enumerable: true, get: function () { return index_js_2.hdLedger; } });
var validatePath_js_1 = require("./validatePath.js");
Object.defineProperty(exports, "hdValidatePath", { enumerable: true, get: function () { return validatePath_js_1.hdValidatePath; } });

Some files were not shown because too many files have changed in this diff Show More