multichain-address-validator 0.7.4 → 0.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/chain-validators.d.ts +2 -0
- package/dist/cjs/chain-validators.js +124 -0
- package/dist/cjs/crypto/base32.d.ts +5 -0
- package/dist/cjs/crypto/base32.js +66 -0
- package/dist/cjs/crypto/base58.d.ts +4 -0
- package/dist/cjs/crypto/base58.js +44 -0
- package/dist/cjs/crypto/bech32.d.ts +17 -0
- package/dist/cjs/crypto/bech32.js +126 -0
- package/dist/cjs/crypto/biginteger.d.ts +57 -0
- package/dist/cjs/crypto/biginteger.js +1313 -0
- package/dist/cjs/crypto/blake256.d.ts +22 -0
- package/dist/cjs/crypto/blake256.js +171 -0
- package/dist/cjs/crypto/blake2b.d.ts +13 -0
- package/dist/cjs/crypto/blake2b.js +243 -0
- package/dist/cjs/crypto/cnBase58.d.ts +7 -0
- package/dist/cjs/crypto/cnBase58.js +211 -0
- package/dist/cjs/crypto/segwit_addr.d.ts +12 -0
- package/dist/cjs/crypto/segwit_addr.js +107 -0
- package/dist/cjs/crypto/utils.d.ts +26 -0
- package/dist/cjs/crypto/utils.js +128 -0
- package/dist/cjs/helpers.d.ts +2 -0
- package/dist/cjs/helpers.js +8 -0
- package/dist/cjs/index.d.ts +8 -0
- package/dist/cjs/index.js +17 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/types.d.ts +15 -0
- package/dist/cjs/types.js +8 -0
- package/dist/cjs/validators/algorand_validator.d.ts +5 -0
- package/dist/cjs/validators/algorand_validator.js +28 -0
- package/dist/cjs/validators/base58_validator.d.ts +4 -0
- package/dist/cjs/validators/base58_validator.js +36 -0
- package/dist/cjs/validators/bch_validator.d.ts +13 -0
- package/dist/cjs/validators/bch_validator.js +55 -0
- package/dist/cjs/validators/bip173_validator.d.ts +7 -0
- package/dist/cjs/validators/bip173_validator.js +17 -0
- package/dist/cjs/validators/bitcoin_validator.d.ts +12 -0
- package/dist/cjs/validators/bitcoin_validator.js +73 -0
- package/dist/cjs/validators/cardano_validator.d.ts +5 -0
- package/dist/cjs/validators/cardano_validator.js +46 -0
- package/dist/cjs/validators/eos_validator.d.ts +5 -0
- package/dist/cjs/validators/eos_validator.js +12 -0
- package/dist/cjs/validators/ethereum_validator.d.ts +6 -0
- package/dist/cjs/validators/ethereum_validator.js +35 -0
- package/dist/cjs/validators/hedera_validator.d.ts +5 -0
- package/dist/cjs/validators/hedera_validator.js +10 -0
- package/dist/cjs/validators/index.d.ts +18 -0
- package/dist/cjs/validators/index.js +42 -0
- package/dist/cjs/validators/monero_validator.d.ts +5 -0
- package/dist/cjs/validators/monero_validator.js +63 -0
- package/dist/cjs/validators/move_validator.d.ts +5 -0
- package/dist/cjs/validators/move_validator.js +10 -0
- package/dist/cjs/validators/nano_validator.d.ts +6 -0
- package/dist/cjs/validators/nano_validator.js +28 -0
- package/dist/cjs/validators/nem_validator.d.ts +5 -0
- package/dist/cjs/validators/nem_validator.js +19 -0
- package/dist/cjs/validators/polkadot_validator.d.ts +5 -0
- package/dist/cjs/validators/polkadot_validator.js +54 -0
- package/dist/cjs/validators/ripple_validator.d.ts +10 -0
- package/dist/cjs/validators/ripple_validator.js +35 -0
- package/dist/cjs/validators/sia_validator.d.ts +5 -0
- package/dist/cjs/validators/sia_validator.js +32 -0
- package/dist/cjs/validators/solana_validator.d.ts +5 -0
- package/dist/cjs/validators/solana_validator.js +15 -0
- package/dist/cjs/validators/tezos_validator.d.ts +5 -0
- package/dist/cjs/validators/tezos_validator.js +35 -0
- package/dist/cjs/validators/tron_validator.d.ts +8 -0
- package/dist/cjs/validators/tron_validator.js +50 -0
- package/dist/cjs/validators/xlm_validator.d.ts +7 -0
- package/dist/cjs/validators/xlm_validator.js +43 -0
- package/dist/esm/chain-validators.d.ts +2 -0
- package/dist/esm/chain-validators.js +121 -0
- package/dist/esm/crypto/base32.d.ts +5 -0
- package/dist/esm/crypto/base32.js +64 -0
- package/dist/esm/crypto/base58.d.ts +4 -0
- package/dist/esm/crypto/base58.js +42 -0
- package/dist/esm/crypto/bech32.d.ts +17 -0
- package/dist/esm/crypto/bech32.js +124 -0
- package/dist/esm/crypto/biginteger.d.ts +57 -0
- package/dist/esm/crypto/biginteger.js +1311 -0
- package/dist/esm/crypto/blake256.d.ts +22 -0
- package/dist/esm/crypto/blake256.js +169 -0
- package/dist/esm/crypto/blake2b.d.ts +13 -0
- package/dist/esm/crypto/blake2b.js +242 -0
- package/dist/esm/crypto/cnBase58.d.ts +7 -0
- package/dist/esm/crypto/cnBase58.js +209 -0
- package/dist/esm/crypto/segwit_addr.d.ts +12 -0
- package/dist/esm/crypto/segwit_addr.js +102 -0
- package/dist/esm/crypto/utils.d.ts +26 -0
- package/dist/esm/crypto/utils.js +123 -0
- package/dist/esm/helpers.d.ts +2 -0
- package/dist/esm/helpers.js +5 -0
- package/dist/esm/index.d.ts +8 -0
- package/dist/esm/index.js +13 -0
- package/dist/esm/types.d.ts +15 -0
- package/dist/esm/types.js +5 -0
- package/dist/esm/validators/algorand_validator.d.ts +5 -0
- package/dist/esm/validators/algorand_validator.js +23 -0
- package/dist/esm/validators/base58_validator.d.ts +4 -0
- package/dist/esm/validators/base58_validator.js +31 -0
- package/dist/esm/validators/bch_validator.d.ts +13 -0
- package/dist/esm/validators/bch_validator.js +50 -0
- package/dist/esm/validators/bip173_validator.d.ts +7 -0
- package/dist/esm/validators/bip173_validator.js +12 -0
- package/dist/esm/validators/bitcoin_validator.d.ts +12 -0
- package/dist/esm/validators/bitcoin_validator.js +68 -0
- package/dist/esm/validators/cardano_validator.d.ts +5 -0
- package/dist/esm/validators/cardano_validator.js +41 -0
- package/dist/esm/validators/eos_validator.d.ts +5 -0
- package/dist/esm/validators/eos_validator.js +10 -0
- package/dist/esm/validators/ethereum_validator.d.ts +6 -0
- package/dist/esm/validators/ethereum_validator.js +30 -0
- package/dist/esm/validators/hedera_validator.d.ts +5 -0
- package/dist/esm/validators/hedera_validator.js +8 -0
- package/dist/esm/validators/index.d.ts +18 -0
- package/dist/esm/validators/index.js +18 -0
- package/dist/esm/validators/monero_validator.d.ts +5 -0
- package/dist/esm/validators/monero_validator.js +58 -0
- package/dist/esm/validators/move_validator.d.ts +5 -0
- package/dist/esm/validators/move_validator.js +8 -0
- package/dist/esm/validators/nano_validator.d.ts +6 -0
- package/dist/esm/validators/nano_validator.js +23 -0
- package/dist/esm/validators/nem_validator.d.ts +5 -0
- package/dist/esm/validators/nem_validator.js +14 -0
- package/dist/esm/validators/polkadot_validator.d.ts +5 -0
- package/dist/esm/validators/polkadot_validator.js +49 -0
- package/dist/esm/validators/ripple_validator.d.ts +10 -0
- package/dist/esm/validators/ripple_validator.js +30 -0
- package/dist/esm/validators/sia_validator.d.ts +5 -0
- package/dist/esm/validators/sia_validator.js +27 -0
- package/dist/esm/validators/solana_validator.d.ts +5 -0
- package/dist/esm/validators/solana_validator.js +10 -0
- package/dist/esm/validators/tezos_validator.d.ts +5 -0
- package/dist/esm/validators/tezos_validator.js +30 -0
- package/dist/esm/validators/tron_validator.d.ts +8 -0
- package/dist/esm/validators/tron_validator.js +45 -0
- package/dist/esm/validators/xlm_validator.d.ts +7 -0
- package/dist/esm/validators/xlm_validator.js +38 -0
- package/package.json +1 -1
- package/package-lock.json +0 -1704
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getValidatorForChain = getValidatorForChain;
|
|
4
|
+
const types_js_1 = require("./types.js");
|
|
5
|
+
const index_js_1 = require("./validators/index.js");
|
|
6
|
+
const chainValidators = {
|
|
7
|
+
algorand: { validator: index_js_1.AlgorandValidator },
|
|
8
|
+
aptos: { validator: index_js_1.MoveValidator },
|
|
9
|
+
bitcoin: {
|
|
10
|
+
alternatives: ['btc', 'omni'],
|
|
11
|
+
validator: {
|
|
12
|
+
mainnet: (0, index_js_1.BTCValidator)({
|
|
13
|
+
addressTypes: ['00', '05'],
|
|
14
|
+
bech32Hrp: ['bc'],
|
|
15
|
+
}),
|
|
16
|
+
testnet: (0, index_js_1.BTCValidator)({
|
|
17
|
+
addressTypes: ['6f', 'c4', '3c', '26'],
|
|
18
|
+
bech32Hrp: ['tb'],
|
|
19
|
+
}),
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
'bitcoincash': {
|
|
23
|
+
alternatives: ['bch', 'bitcoin-cash', 'bitcoin cash'],
|
|
24
|
+
validator: {
|
|
25
|
+
mainnet: (0, index_js_1.BCHValidator)({
|
|
26
|
+
addressTypes: ['00', '05'],
|
|
27
|
+
bech32Hrp: ['bc'],
|
|
28
|
+
networkType: types_js_1.NetworkType.MainNet,
|
|
29
|
+
}),
|
|
30
|
+
testnet: (0, index_js_1.BCHValidator)({
|
|
31
|
+
addressTypes: ['6f', 'c4', '3c', '26'],
|
|
32
|
+
bech32Hrp: ['tb'],
|
|
33
|
+
networkType: types_js_1.NetworkType.TestNet,
|
|
34
|
+
}),
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
cardano: {
|
|
38
|
+
alternatives: ['ada'],
|
|
39
|
+
validator: index_js_1.CardanoValidator,
|
|
40
|
+
},
|
|
41
|
+
doge: {
|
|
42
|
+
alternatives: ['dogecoin'],
|
|
43
|
+
validator: {
|
|
44
|
+
mainnet: (0, index_js_1.BTCValidator)({ addressTypes: ['1e', '16'] }),
|
|
45
|
+
testnet: (0, index_js_1.BTCValidator)({ addressTypes: ['71', 'c4'] }),
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
eos: { validator: index_js_1.EOSValidator },
|
|
49
|
+
ethereum: {
|
|
50
|
+
alternatives: [
|
|
51
|
+
'arbitrum',
|
|
52
|
+
'avalanche',
|
|
53
|
+
'avalanche-c',
|
|
54
|
+
'base',
|
|
55
|
+
'berachain',
|
|
56
|
+
'binance',
|
|
57
|
+
'BinanceSmartChain',
|
|
58
|
+
'bnb',
|
|
59
|
+
'bsc',
|
|
60
|
+
'eth',
|
|
61
|
+
'EthereumClassic',
|
|
62
|
+
'EthereumPow',
|
|
63
|
+
'erc20',
|
|
64
|
+
'flare',
|
|
65
|
+
'sonic',
|
|
66
|
+
'story',
|
|
67
|
+
],
|
|
68
|
+
validator: index_js_1.ETHValidator
|
|
69
|
+
},
|
|
70
|
+
hedera: {
|
|
71
|
+
alternatives: ['hbar'],
|
|
72
|
+
validator: index_js_1.HederaValidator
|
|
73
|
+
},
|
|
74
|
+
litecoin: {
|
|
75
|
+
alternatives: ['ltc'],
|
|
76
|
+
validator: {
|
|
77
|
+
mainnet: (0, index_js_1.BTCValidator)({
|
|
78
|
+
addressTypes: ['30', '32'],
|
|
79
|
+
bech32Hrp: ['ltc'],
|
|
80
|
+
}),
|
|
81
|
+
testnet: (0, index_js_1.BTCValidator)({
|
|
82
|
+
addressTypes: ['6f', 'c4', '3a'],
|
|
83
|
+
bech32Hrp: ['tltc']
|
|
84
|
+
})
|
|
85
|
+
}
|
|
86
|
+
},
|
|
87
|
+
monero: {
|
|
88
|
+
validator: {
|
|
89
|
+
mainnet: (0, index_js_1.MoneroValidator)(types_js_1.NetworkType.MainNet),
|
|
90
|
+
testnet: (0, index_js_1.MoneroValidator)(types_js_1.NetworkType.TestNet),
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
nem: { validator: index_js_1.NemValidator },
|
|
94
|
+
nano: { validator: index_js_1.NanoValidator },
|
|
95
|
+
polkadot: { validator: index_js_1.PolkadotValidator },
|
|
96
|
+
ripple: {
|
|
97
|
+
alternatives: ['xrp'],
|
|
98
|
+
validator: index_js_1.RippleValidator,
|
|
99
|
+
},
|
|
100
|
+
sia: { validator: index_js_1.SiaValidator },
|
|
101
|
+
solana: {
|
|
102
|
+
alternatives: ['spl'],
|
|
103
|
+
validator: index_js_1.SolanaValidator,
|
|
104
|
+
},
|
|
105
|
+
sui: { validator: index_js_1.MoveValidator },
|
|
106
|
+
tron: {
|
|
107
|
+
alternatives: ['trc20'],
|
|
108
|
+
validator: (0, index_js_1.TronValidator)(),
|
|
109
|
+
},
|
|
110
|
+
tezos: { validator: index_js_1.TezosValidator },
|
|
111
|
+
xlm: {
|
|
112
|
+
alternatives: ['stellar'],
|
|
113
|
+
validator: index_js_1.XLMValidator,
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
function getValidatorForChain(chain) {
|
|
117
|
+
const chainName = chain.chain || chain;
|
|
118
|
+
const networkType = chain.networkType || types_js_1.NetworkType.MainNet;
|
|
119
|
+
const key = Object.keys(chainValidators).find(key => key.toUpperCase() === chainName.toUpperCase() || chainValidators[key]
|
|
120
|
+
?.alternatives
|
|
121
|
+
?.map(alternative => alternative.toUpperCase())
|
|
122
|
+
?.includes(chainName.toUpperCase()));
|
|
123
|
+
return chainValidators[key]?.validator[networkType] || chainValidators[key]?.validator;
|
|
124
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
|
|
4
|
+
/**
|
|
5
|
+
* Encode a string to base32
|
|
6
|
+
*/
|
|
7
|
+
const b32encode = function (s) {
|
|
8
|
+
const parts = [];
|
|
9
|
+
let quanta = Math.floor((s.length / 5));
|
|
10
|
+
const leftover = s.length % 5;
|
|
11
|
+
if (leftover != 0) {
|
|
12
|
+
for (let i = 0; i < (5 - leftover); i++) {
|
|
13
|
+
s += '\x00';
|
|
14
|
+
}
|
|
15
|
+
quanta += 1;
|
|
16
|
+
}
|
|
17
|
+
for (let i = 0; i < quanta; i++) {
|
|
18
|
+
parts.push(alphabet.charAt(s.charCodeAt(i * 5) >> 3));
|
|
19
|
+
parts.push(alphabet.charAt(((s.charCodeAt(i * 5) & 0x07) << 2) | (s.charCodeAt(i * 5 + 1) >> 6)));
|
|
20
|
+
parts.push(alphabet.charAt(((s.charCodeAt(i * 5 + 1) & 0x3F) >> 1)));
|
|
21
|
+
parts.push(alphabet.charAt(((s.charCodeAt(i * 5 + 1) & 0x01) << 4) | (s.charCodeAt(i * 5 + 2) >> 4)));
|
|
22
|
+
parts.push(alphabet.charAt(((s.charCodeAt(i * 5 + 2) & 0x0F) << 1) | (s.charCodeAt(i * 5 + 3) >> 7)));
|
|
23
|
+
parts.push(alphabet.charAt(((s.charCodeAt(i * 5 + 3) & 0x7F) >> 2)));
|
|
24
|
+
parts.push(alphabet.charAt(((s.charCodeAt(i * 5 + 3) & 0x03) << 3) | (s.charCodeAt(i * 5 + 4) >> 5)));
|
|
25
|
+
parts.push(alphabet.charAt(((s.charCodeAt(i * 5 + 4) & 0x1F))));
|
|
26
|
+
}
|
|
27
|
+
let replace = 0;
|
|
28
|
+
if (leftover == 1)
|
|
29
|
+
replace = 6;
|
|
30
|
+
else if (leftover == 2)
|
|
31
|
+
replace = 4;
|
|
32
|
+
else if (leftover == 3)
|
|
33
|
+
replace = 3;
|
|
34
|
+
else if (leftover == 4)
|
|
35
|
+
replace = 1;
|
|
36
|
+
for (let i = 0; i < replace; i++)
|
|
37
|
+
parts.pop();
|
|
38
|
+
for (let i = 0; i < replace; i++)
|
|
39
|
+
parts.push("=");
|
|
40
|
+
return parts.join("");
|
|
41
|
+
};
|
|
42
|
+
/**
|
|
43
|
+
* Decode a base32 string.
|
|
44
|
+
* This is made specifically for our use, deals only with proper strings
|
|
45
|
+
*/
|
|
46
|
+
const b32decode = function (s) {
|
|
47
|
+
const r = new ArrayBuffer(s.length * 5 / 8);
|
|
48
|
+
const b = new Uint8Array(r);
|
|
49
|
+
for (let j = 0; j < s.length / 8; j++) {
|
|
50
|
+
const v = [0, 0, 0, 0, 0, 0, 0, 0];
|
|
51
|
+
for (let i = 0; i < 8; ++i) {
|
|
52
|
+
v[i] = alphabet.indexOf(s[j * 8 + i]);
|
|
53
|
+
}
|
|
54
|
+
const i = 0;
|
|
55
|
+
b[j * 5 + 0] = (v[i + 0] << 3) | (v[i + 1] >> 2);
|
|
56
|
+
b[j * 5 + 1] = ((v[i + 1] & 0x3) << 6) | (v[i + 2] << 1) | (v[i + 3] >> 4);
|
|
57
|
+
b[j * 5 + 2] = ((v[i + 3] & 0xf) << 4) | (v[i + 4] >> 1);
|
|
58
|
+
b[j * 5 + 3] = ((v[i + 4] & 0x1) << 7) | (v[i + 5] << 2) | (v[i + 6] >> 3);
|
|
59
|
+
b[j * 5 + 4] = ((v[i + 6] & 0x7) << 5) | (v[i + 7]);
|
|
60
|
+
}
|
|
61
|
+
return b;
|
|
62
|
+
};
|
|
63
|
+
exports.default = {
|
|
64
|
+
b32decode,
|
|
65
|
+
b32encode
|
|
66
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Base58 encoding/decoding
|
|
3
|
+
// Originally written by Mike Hearn for BitcoinJ
|
|
4
|
+
// Copyright (c) 2011 Google Inc
|
|
5
|
+
// Ported to JavaScript by Stefan Thomas
|
|
6
|
+
// Merged Buffer refactorings from base58-native by Stephen Pair
|
|
7
|
+
// Copyright (c) 2013 BitPay Inc
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
const ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
10
|
+
const ALPHABET_MAP = {};
|
|
11
|
+
for (let i = 0; i < ALPHABET.length; ++i) {
|
|
12
|
+
ALPHABET_MAP[ALPHABET.charAt(i)] = i;
|
|
13
|
+
}
|
|
14
|
+
const BASE = ALPHABET.length;
|
|
15
|
+
exports.default = {
|
|
16
|
+
decode: function (string) {
|
|
17
|
+
if (string.length === 0)
|
|
18
|
+
return [];
|
|
19
|
+
var i, j, bytes = [0];
|
|
20
|
+
for (i = 0; i < string.length; ++i) {
|
|
21
|
+
var c = string[i];
|
|
22
|
+
if (!(c in ALPHABET_MAP))
|
|
23
|
+
throw new Error('Non-base58 character');
|
|
24
|
+
for (j = 0; j < bytes.length; ++j)
|
|
25
|
+
bytes[j] *= BASE;
|
|
26
|
+
bytes[0] += ALPHABET_MAP[c];
|
|
27
|
+
var carry = 0;
|
|
28
|
+
for (j = 0; j < bytes.length; ++j) {
|
|
29
|
+
bytes[j] += carry;
|
|
30
|
+
carry = bytes[j] >> 8;
|
|
31
|
+
bytes[j] &= 0xff;
|
|
32
|
+
}
|
|
33
|
+
while (carry) {
|
|
34
|
+
bytes.push(carry & 0xff);
|
|
35
|
+
carry >>= 8;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
// deal with leading zeros
|
|
39
|
+
for (i = 0; string[i] === '1' && i < string.length - 1; ++i) {
|
|
40
|
+
bytes.push(0);
|
|
41
|
+
}
|
|
42
|
+
return bytes.reverse();
|
|
43
|
+
}
|
|
44
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
declare namespace _default {
|
|
2
|
+
export { decode };
|
|
3
|
+
export { encode };
|
|
4
|
+
export { encodings };
|
|
5
|
+
export { verifyChecksum };
|
|
6
|
+
}
|
|
7
|
+
export default _default;
|
|
8
|
+
declare function decode(bechString: any, enc: any): {
|
|
9
|
+
hrp: any;
|
|
10
|
+
data: number[];
|
|
11
|
+
};
|
|
12
|
+
declare function encode(hrp: any, data: any, enc: any): string;
|
|
13
|
+
declare namespace encodings {
|
|
14
|
+
let BECH32: string;
|
|
15
|
+
let BECH32M: string;
|
|
16
|
+
}
|
|
17
|
+
declare function verifyChecksum(hrp: any, data: any, enc: any): boolean;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) 2017, 2021 Pieter Wuille
|
|
3
|
+
//
|
|
4
|
+
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
// of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
// in the Software without restriction, including without limitation the rights
|
|
7
|
+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
// copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
// furnished to do so, subject to the following conditions:
|
|
10
|
+
//
|
|
11
|
+
// The above copyright notice and this permission notice shall be included in
|
|
12
|
+
// all copies or substantial portions of the Software.
|
|
13
|
+
//
|
|
14
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
20
|
+
// THE SOFTWARE.
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
var CHARSET = 'qpzry9x8gf2tvdw0s3jn54khce6mua7l';
|
|
23
|
+
var GENERATOR = [0x3b6a57b2, 0x26508e6d, 0x1ea119fa, 0x3d4233dd, 0x2a1462b3];
|
|
24
|
+
const encodings = {
|
|
25
|
+
BECH32: "bech32",
|
|
26
|
+
BECH32M: "bech32m",
|
|
27
|
+
};
|
|
28
|
+
exports.default = {
|
|
29
|
+
decode: decode,
|
|
30
|
+
encode: encode,
|
|
31
|
+
encodings: encodings,
|
|
32
|
+
verifyChecksum: verifyChecksum
|
|
33
|
+
};
|
|
34
|
+
function getEncodingConst(enc) {
|
|
35
|
+
if (enc == encodings.BECH32) {
|
|
36
|
+
return 1;
|
|
37
|
+
}
|
|
38
|
+
else if (enc == encodings.BECH32M) {
|
|
39
|
+
return 0x2bc830a3;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function polymod(values) {
|
|
46
|
+
var chk = 1;
|
|
47
|
+
for (var p = 0; p < values.length; ++p) {
|
|
48
|
+
var top = chk >> 25;
|
|
49
|
+
chk = (chk & 0x1ffffff) << 5 ^ values[p];
|
|
50
|
+
for (var i = 0; i < 5; ++i) {
|
|
51
|
+
if ((top >> i) & 1) {
|
|
52
|
+
chk ^= GENERATOR[i];
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return chk;
|
|
57
|
+
}
|
|
58
|
+
function hrpExpand(hrp) {
|
|
59
|
+
var ret = [];
|
|
60
|
+
var p;
|
|
61
|
+
for (p = 0; p < hrp.length; ++p) {
|
|
62
|
+
ret.push(hrp.charCodeAt(p) >> 5);
|
|
63
|
+
}
|
|
64
|
+
ret.push(0);
|
|
65
|
+
for (p = 0; p < hrp.length; ++p) {
|
|
66
|
+
ret.push(hrp.charCodeAt(p) & 31);
|
|
67
|
+
}
|
|
68
|
+
return ret;
|
|
69
|
+
}
|
|
70
|
+
function verifyChecksum(hrp, data, enc) {
|
|
71
|
+
return polymod(hrpExpand(hrp).concat(data)) === getEncodingConst(enc);
|
|
72
|
+
}
|
|
73
|
+
function createChecksum(hrp, data, enc) {
|
|
74
|
+
var values = hrpExpand(hrp).concat(data).concat([0, 0, 0, 0, 0, 0]);
|
|
75
|
+
var mod = polymod(values) ^ getEncodingConst(enc);
|
|
76
|
+
var ret = [];
|
|
77
|
+
for (var p = 0; p < 6; ++p) {
|
|
78
|
+
ret.push((mod >> 5 * (5 - p)) & 31);
|
|
79
|
+
}
|
|
80
|
+
return ret;
|
|
81
|
+
}
|
|
82
|
+
function encode(hrp, data, enc) {
|
|
83
|
+
var combined = data.concat(createChecksum(hrp, data, enc));
|
|
84
|
+
var ret = hrp + '1';
|
|
85
|
+
for (var p = 0; p < combined.length; ++p) {
|
|
86
|
+
ret += CHARSET.charAt(combined[p]);
|
|
87
|
+
}
|
|
88
|
+
return ret;
|
|
89
|
+
}
|
|
90
|
+
function decode(bechString, enc) {
|
|
91
|
+
var p;
|
|
92
|
+
var has_lower = false;
|
|
93
|
+
var has_upper = false;
|
|
94
|
+
for (p = 0; p < bechString.length; ++p) {
|
|
95
|
+
if (bechString.charCodeAt(p) < 33 || bechString.charCodeAt(p) > 126) {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
if (bechString.charCodeAt(p) >= 97 && bechString.charCodeAt(p) <= 122) {
|
|
99
|
+
has_lower = true;
|
|
100
|
+
}
|
|
101
|
+
if (bechString.charCodeAt(p) >= 65 && bechString.charCodeAt(p) <= 90) {
|
|
102
|
+
has_upper = true;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
if (has_lower && has_upper) {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
bechString = bechString.toLowerCase();
|
|
109
|
+
var pos = bechString.lastIndexOf('1');
|
|
110
|
+
if (pos < 1 || pos + 7 > bechString.length || bechString.length > 110) {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
var hrp = bechString.substring(0, pos);
|
|
114
|
+
var data = [];
|
|
115
|
+
for (p = pos + 1; p < bechString.length; ++p) {
|
|
116
|
+
var d = CHARSET.indexOf(bechString.charAt(p));
|
|
117
|
+
if (d === -1) {
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
data.push(d);
|
|
121
|
+
}
|
|
122
|
+
if (!verifyChecksum(hrp, data, enc)) {
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
return { hrp: hrp, data: data.slice(0, data.length - 6) };
|
|
126
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
export function BigInteger(n: any, s: any, token: any): BigInteger;
|
|
2
|
+
export class BigInteger {
|
|
3
|
+
constructor(n: any, s: any, token: any);
|
|
4
|
+
_d: any;
|
|
5
|
+
_s: any;
|
|
6
|
+
toString(base: any): any;
|
|
7
|
+
add(n: any): any;
|
|
8
|
+
negate(): BigInteger;
|
|
9
|
+
abs(): BigInteger;
|
|
10
|
+
subtract(n: any): any;
|
|
11
|
+
compareAbs(n: any): any;
|
|
12
|
+
compare(n: any): any;
|
|
13
|
+
isUnit(): boolean;
|
|
14
|
+
multiply(n: any): any;
|
|
15
|
+
multiplySingleDigit(n: any): any;
|
|
16
|
+
square(): BigInteger;
|
|
17
|
+
quotient(n: any): BigInteger;
|
|
18
|
+
divide: any;
|
|
19
|
+
remainder(n: any): BigInteger;
|
|
20
|
+
divRem(n: any): BigInteger[];
|
|
21
|
+
divRemSmall(n: any): BigInteger[];
|
|
22
|
+
isEven(): boolean;
|
|
23
|
+
isOdd(): boolean;
|
|
24
|
+
sign(): any;
|
|
25
|
+
isPositive(): boolean;
|
|
26
|
+
isNegative(): boolean;
|
|
27
|
+
isZero(): boolean;
|
|
28
|
+
exp10(n: any): BigInteger;
|
|
29
|
+
pow(n: any): BigInteger;
|
|
30
|
+
modPow(exponent: any, modulus: any): BigInteger;
|
|
31
|
+
log(): number;
|
|
32
|
+
valueOf(): any;
|
|
33
|
+
toJSValue(): number;
|
|
34
|
+
lowVal(): any;
|
|
35
|
+
}
|
|
36
|
+
export namespace BigInteger {
|
|
37
|
+
export function _construct(n: any, s: any): BigInteger;
|
|
38
|
+
export { BigInteger_base as base };
|
|
39
|
+
export { BigInteger_base_log10 as base_log10 };
|
|
40
|
+
export { ZERO };
|
|
41
|
+
export { ONE };
|
|
42
|
+
export { M_ONE };
|
|
43
|
+
export { ZERO as _0 };
|
|
44
|
+
export { ONE as _1 };
|
|
45
|
+
export let small: BigInteger[];
|
|
46
|
+
export let digits: string[];
|
|
47
|
+
export let radixRegex: RegExp[];
|
|
48
|
+
export function parse(s: any, base: any): BigInteger;
|
|
49
|
+
export { MAX_EXP };
|
|
50
|
+
}
|
|
51
|
+
declare var BigInteger_base: number;
|
|
52
|
+
declare var BigInteger_base_log10: number;
|
|
53
|
+
declare var ZERO: BigInteger;
|
|
54
|
+
declare var ONE: BigInteger;
|
|
55
|
+
declare var M_ONE: BigInteger;
|
|
56
|
+
declare var MAX_EXP: BigInteger;
|
|
57
|
+
export {};
|