mirror of
https://github.com/pezkuwichain/pezkuwi-common.git
synced 2026-04-30 13:07:57 +00:00
chore: update to version 14.0.11 and align website URLs
This commit is contained in:
@@ -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
@@ -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];
|
||||
@@ -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'];
|
||||
}
|
||||
@@ -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];
|
||||
}
|
||||
@@ -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}`);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
};
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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];
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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
@@ -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;
|
||||
@@ -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));
|
||||
}
|
||||
@@ -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
@@ -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';
|
||||
@@ -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
@@ -0,0 +1,2 @@
|
||||
import type { Prefix } from './types.js';
|
||||
export declare function isAddress(address?: string | null, ignoreChecksum?: boolean, ss58Format?: Prefix): address is string;
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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)));
|
||||
}
|
||||
@@ -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)));
|
||||
}
|
||||
@@ -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
@@ -0,0 +1,2 @@
|
||||
import type { Prefix } from './types.js';
|
||||
export declare function sortAddresses(addresses: (string | Uint8Array)[], ss58Format?: Prefix): string[];
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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
@@ -0,0 +1 @@
|
||||
export type Prefix = number;
|
||||
@@ -0,0 +1,2 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
+1
@@ -0,0 +1 @@
|
||||
export declare function addressToU8a(who: string | Uint8Array): Uint8Array;
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
Reference in New Issue
Block a user