multichain-address-validator 0.7.9 → 0.8.1
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/README.md +0 -1
- package/dist/cjs/chain-validators.js +23 -1
- package/dist/cjs/crypto/segwit_addr.js +8 -3
- package/dist/cjs/validators/bitcoin_validator.d.ts +5 -0
- package/dist/cjs/validators/bitcoin_validator.js +6 -5
- package/dist/cjs/validators/bittensor_validator.d.ts +2 -0
- package/dist/cjs/validators/bittensor_validator.js +11 -0
- package/dist/cjs/validators/index.d.ts +2 -0
- package/dist/cjs/validators/index.js +5 -1
- package/dist/cjs/validators/polkadot_validator.d.ts +1 -4
- package/dist/cjs/validators/polkadot_validator.js +5 -49
- package/dist/cjs/validators/ss58_validator.d.ts +11 -0
- package/dist/cjs/validators/ss58_validator.js +70 -0
- package/dist/cjs/validators/zcash_validator.d.ts +5 -0
- package/dist/cjs/validators/zcash_validator.js +52 -0
- package/dist/esm/chain-validators.js +24 -2
- package/dist/esm/crypto/segwit_addr.js +8 -3
- package/dist/esm/validators/bitcoin_validator.d.ts +5 -0
- package/dist/esm/validators/bitcoin_validator.js +5 -5
- package/dist/esm/validators/bittensor_validator.d.ts +2 -0
- package/dist/esm/validators/bittensor_validator.js +6 -0
- package/dist/esm/validators/index.d.ts +2 -0
- package/dist/esm/validators/index.js +2 -0
- package/dist/esm/validators/polkadot_validator.d.ts +1 -4
- package/dist/esm/validators/polkadot_validator.js +5 -49
- package/dist/esm/validators/ss58_validator.d.ts +11 -0
- package/dist/esm/validators/ss58_validator.js +64 -0
- package/dist/esm/validators/zcash_validator.d.ts +5 -0
- package/dist/esm/validators/zcash_validator.js +47 -0
- package/package.json +3 -2
- package/.editorconfig +0 -10
- package/.travis.yml +0 -11
- package/.vscode/launch.json +0 -23
- package/index.html +0 -12
- package/src/chain-validators.ts +0 -161
- package/src/crypto/base32.ts +0 -66
- package/src/crypto/base58.ts +0 -46
- package/src/crypto/bech32.js +0 -132
- package/src/crypto/biginteger.js +0 -1426
- package/src/crypto/blake256.js +0 -188
- package/src/crypto/blake2b.js +0 -276
- package/src/crypto/cnBase58.js +0 -226
- package/src/crypto/segwit_addr.js +0 -112
- package/src/crypto/utils.ts +0 -133
- package/src/helpers.ts +0 -13
- package/src/index.ts +0 -28
- package/src/types.ts +0 -19
- package/src/validators/algorand_validator.ts +0 -28
- package/src/validators/base58_validator.ts +0 -32
- package/src/validators/bch_validator.ts +0 -66
- package/src/validators/bip173_validator.ts +0 -19
- package/src/validators/bitcoin_validator.ts +0 -94
- package/src/validators/cardano_validator.ts +0 -50
- package/src/validators/eos_validator.ts +0 -13
- package/src/validators/ethereum_validator.ts +0 -37
- package/src/validators/hedera_validator.ts +0 -10
- package/src/validators/index.ts +0 -18
- package/src/validators/monero_validator.ts +0 -72
- package/src/validators/move_validator.ts +0 -11
- package/src/validators/nano_validator.ts +0 -32
- package/src/validators/nem_validator.ts +0 -18
- package/src/validators/polkadot_validator.ts +0 -57
- package/src/validators/ripple_validator.ts +0 -44
- package/src/validators/sia_validator.ts +0 -33
- package/src/validators/solana_validator.ts +0 -21
- package/src/validators/tezos_validator.ts +0 -36
- package/src/validators/tron_validator.ts +0 -59
- package/src/validators/xlm_validator.ts +0 -54
- package/test/addresses/addresses.ts +0 -59
- package/test/addresses/algorand.json +0 -6
- package/test/addresses/aptos.json +0 -6
- package/test/addresses/bch-testnet.json +0 -4
- package/test/addresses/bch.json +0 -7
- package/test/addresses/btc-testnet.json +0 -13
- package/test/addresses/btc.json +0 -14
- package/test/addresses/cardano.json +0 -8
- package/test/addresses/doge-testnet.json +0 -3
- package/test/addresses/doge.json +0 -7
- package/test/addresses/eos.json +0 -6
- package/test/addresses/evm.json +0 -20
- package/test/addresses/hbar.json +0 -11
- package/test/addresses/ltc-testnet.json +0 -10
- package/test/addresses/ltc.json +0 -8
- package/test/addresses/monero-testnet.json +0 -5
- package/test/addresses/monero.json +0 -7
- package/test/addresses/nano.json +0 -12
- package/test/addresses/nem.json +0 -4
- package/test/addresses/polkadot.json +0 -8
- package/test/addresses/ripple.json +0 -20
- package/test/addresses/sia.json +0 -5
- package/test/addresses/solana.json +0 -12
- package/test/addresses/sui.json +0 -6
- package/test/addresses/tezos.json +0 -9
- package/test/addresses/tron.json +0 -6
- package/test/addresses/xlm.json +0 -21
- package/test/multichain-address-validator.test.ts +0 -225
- package/tsconfig.cjs.json +0 -7
- package/tsconfig.esm.json +0 -7
- package/tsconfig.json +0 -24
|
@@ -1,49 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
{ addressLength: 4, accountIndexLength: 2, checkSumLength: 1 },
|
|
7
|
-
{ addressLength: 5, accountIndexLength: 2, checkSumLength: 2 },
|
|
8
|
-
{ addressLength: 6, accountIndexLength: 4, checkSumLength: 1 },
|
|
9
|
-
{ addressLength: 7, accountIndexLength: 4, checkSumLength: 2 },
|
|
10
|
-
{ addressLength: 8, accountIndexLength: 4, checkSumLength: 3 },
|
|
11
|
-
{ addressLength: 9, accountIndexLength: 4, checkSumLength: 4 },
|
|
12
|
-
{ addressLength: 10, accountIndexLength: 8, checkSumLength: 1 },
|
|
13
|
-
{ addressLength: 11, accountIndexLength: 8, checkSumLength: 2 },
|
|
14
|
-
{ addressLength: 12, accountIndexLength: 8, checkSumLength: 3 },
|
|
15
|
-
{ addressLength: 13, accountIndexLength: 8, checkSumLength: 4 },
|
|
16
|
-
{ addressLength: 14, accountIndexLength: 8, checkSumLength: 5 },
|
|
17
|
-
{ addressLength: 15, accountIndexLength: 8, checkSumLength: 6 },
|
|
18
|
-
{ addressLength: 16, accountIndexLength: 8, checkSumLength: 7 },
|
|
19
|
-
{ addressLength: 17, accountIndexLength: 8, checkSumLength: 8 },
|
|
20
|
-
{ addressLength: 34, accountIndexLength: 32, checkSumLength: 2 },
|
|
21
|
-
];
|
|
22
|
-
function verifyChecksum(address) {
|
|
23
|
-
try {
|
|
24
|
-
const preImage = '53533538505245';
|
|
25
|
-
const decoded = cryptoUtils.base58(address);
|
|
26
|
-
const addressType = cryptoUtils.byteArray2hexStr(decoded.slice(0, 1));
|
|
27
|
-
const addressAndChecksum = decoded.slice(1);
|
|
28
|
-
// get the address format
|
|
29
|
-
const addressFormat = addressFormats.find(af => af.addressLength === addressAndChecksum.length);
|
|
30
|
-
if (!addressFormat) {
|
|
31
|
-
throw new Error('Invalid address length');
|
|
32
|
-
}
|
|
33
|
-
const decodedAddress = cryptoUtils.byteArray2hexStr(addressAndChecksum.slice(0, addressFormat.accountIndexLength));
|
|
34
|
-
const checksum = cryptoUtils.byteArray2hexStr(addressAndChecksum.slice(-addressFormat.checkSumLength));
|
|
35
|
-
const calculatedHash = cryptoUtils
|
|
36
|
-
.blake2b(preImage + addressType + decodedAddress, 64)
|
|
37
|
-
.substr(0, addressFormat.checkSumLength * 2)
|
|
38
|
-
.toUpperCase();
|
|
39
|
-
return calculatedHash == checksum;
|
|
40
|
-
}
|
|
41
|
-
catch (err) {
|
|
42
|
-
return false;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
export default {
|
|
46
|
-
isValidAddress(address) {
|
|
47
|
-
return verifyChecksum(getAddress(address));
|
|
48
|
-
},
|
|
49
|
-
};
|
|
1
|
+
import createSS58Validator from './ss58_validator.js';
|
|
2
|
+
// Polkadot uses SS58 address format (Substrate-based)
|
|
3
|
+
// SS58 Registry: https://github.com/paritytech/ss58-registry
|
|
4
|
+
// Accepts any valid SS58 address (no network prefix restriction)
|
|
5
|
+
export default createSS58Validator();
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Validator } from '../types.js';
|
|
2
|
+
interface SS58ValidatorOptions {
|
|
3
|
+
networkPrefix?: number;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Creates an SS58 validator with optional network prefix filtering
|
|
7
|
+
* @param options Configuration options including optional network prefix
|
|
8
|
+
* @returns Validator instance for SS58 addresses
|
|
9
|
+
*/
|
|
10
|
+
export default function createSS58Validator(options?: SS58ValidatorOptions): Validator;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import cryptoUtils from '../crypto/utils.js';
|
|
2
|
+
import { getAddress } from '../helpers.js';
|
|
3
|
+
// SS58 address format (Substrate-based)
|
|
4
|
+
// SS58 Registry: https://github.com/paritytech/ss58-registry
|
|
5
|
+
const addressFormats = [
|
|
6
|
+
{ addressLength: 3, accountIndexLength: 1, checkSumLength: 1 },
|
|
7
|
+
{ addressLength: 4, accountIndexLength: 2, checkSumLength: 1 },
|
|
8
|
+
{ addressLength: 5, accountIndexLength: 2, checkSumLength: 2 },
|
|
9
|
+
{ addressLength: 6, accountIndexLength: 4, checkSumLength: 1 },
|
|
10
|
+
{ addressLength: 7, accountIndexLength: 4, checkSumLength: 2 },
|
|
11
|
+
{ addressLength: 8, accountIndexLength: 4, checkSumLength: 3 },
|
|
12
|
+
{ addressLength: 9, accountIndexLength: 4, checkSumLength: 4 },
|
|
13
|
+
{ addressLength: 10, accountIndexLength: 8, checkSumLength: 1 },
|
|
14
|
+
{ addressLength: 11, accountIndexLength: 8, checkSumLength: 2 },
|
|
15
|
+
{ addressLength: 12, accountIndexLength: 8, checkSumLength: 3 },
|
|
16
|
+
{ addressLength: 13, accountIndexLength: 8, checkSumLength: 4 },
|
|
17
|
+
{ addressLength: 14, accountIndexLength: 8, checkSumLength: 5 },
|
|
18
|
+
{ addressLength: 15, accountIndexLength: 8, checkSumLength: 6 },
|
|
19
|
+
{ addressLength: 16, accountIndexLength: 8, checkSumLength: 7 },
|
|
20
|
+
{ addressLength: 17, accountIndexLength: 8, checkSumLength: 8 },
|
|
21
|
+
{ addressLength: 34, accountIndexLength: 32, checkSumLength: 2 },
|
|
22
|
+
];
|
|
23
|
+
/**
|
|
24
|
+
* Creates an SS58 validator with optional network prefix filtering
|
|
25
|
+
* @param options Configuration options including optional network prefix
|
|
26
|
+
* @returns Validator instance for SS58 addresses
|
|
27
|
+
*/
|
|
28
|
+
export default function createSS58Validator(options = {}) {
|
|
29
|
+
function verifyChecksum(address) {
|
|
30
|
+
try {
|
|
31
|
+
const preImage = '53533538505245';
|
|
32
|
+
const decoded = cryptoUtils.base58(address);
|
|
33
|
+
const addressType = cryptoUtils.byteArray2hexStr(decoded.slice(0, 1));
|
|
34
|
+
// If a specific network prefix is required, validate it
|
|
35
|
+
if (options.networkPrefix !== undefined) {
|
|
36
|
+
const expectedPrefix = options.networkPrefix.toString(16).padStart(2, '0').toUpperCase();
|
|
37
|
+
if (addressType.toUpperCase() !== expectedPrefix) {
|
|
38
|
+
return false;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const addressAndChecksum = decoded.slice(1);
|
|
42
|
+
// get the address format
|
|
43
|
+
const addressFormat = addressFormats.find(af => af.addressLength === addressAndChecksum.length);
|
|
44
|
+
if (!addressFormat) {
|
|
45
|
+
throw new Error('Invalid address length');
|
|
46
|
+
}
|
|
47
|
+
const decodedAddress = cryptoUtils.byteArray2hexStr(addressAndChecksum.slice(0, addressFormat.accountIndexLength));
|
|
48
|
+
const checksum = cryptoUtils.byteArray2hexStr(addressAndChecksum.slice(-addressFormat.checkSumLength));
|
|
49
|
+
const calculatedHash = cryptoUtils
|
|
50
|
+
.blake2b(preImage + addressType + decodedAddress, 64)
|
|
51
|
+
.substr(0, addressFormat.checkSumLength * 2)
|
|
52
|
+
.toUpperCase();
|
|
53
|
+
return calculatedHash == checksum;
|
|
54
|
+
}
|
|
55
|
+
catch (err) {
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
isValidAddress(address) {
|
|
61
|
+
return verifyChecksum(getAddress(address));
|
|
62
|
+
},
|
|
63
|
+
};
|
|
64
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import base58 from '../crypto/base58.js';
|
|
2
|
+
import cryptoUtils from '../crypto/utils.js';
|
|
3
|
+
import { NetworkType } from '../types.js';
|
|
4
|
+
import { getAddress } from '../helpers.js';
|
|
5
|
+
function getDecoded(address) {
|
|
6
|
+
try {
|
|
7
|
+
return base58.decode(address);
|
|
8
|
+
}
|
|
9
|
+
catch (e) {
|
|
10
|
+
// if decoding fails, assume invalid address
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function getChecksum(payload) {
|
|
15
|
+
return cryptoUtils.sha256Checksum(payload);
|
|
16
|
+
}
|
|
17
|
+
function isValidTransparentAddress(address, networkType) {
|
|
18
|
+
// Zcash transparent addresses use 2-byte version prefixes
|
|
19
|
+
// Expected length: 26 bytes (2 bytes version + 20 bytes payload + 4 bytes checksum)
|
|
20
|
+
const expectedLength = 26;
|
|
21
|
+
const decoded = getDecoded(address);
|
|
22
|
+
if (!decoded || decoded.length !== expectedLength) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
const checksum = cryptoUtils.toHex(decoded.slice(expectedLength - 4, expectedLength));
|
|
26
|
+
const body = cryptoUtils.toHex(decoded.slice(0, expectedLength - 4));
|
|
27
|
+
const goodChecksum = getChecksum(body);
|
|
28
|
+
if (checksum !== goodChecksum) {
|
|
29
|
+
return false;
|
|
30
|
+
}
|
|
31
|
+
// Get the 2-byte version prefix
|
|
32
|
+
const versionPrefix = cryptoUtils.toHex(decoded.slice(0, 2));
|
|
33
|
+
// Define valid version prefixes for each network
|
|
34
|
+
// Only supporting transparent addresses (t1/t3 for mainnet, tm/t2 for testnet)
|
|
35
|
+
const validPrefixes = networkType === NetworkType.MainNet
|
|
36
|
+
? ['1cb8', '1cbd'] // t1 (P2PKH) and t3 (P2SH) for mainnet
|
|
37
|
+
: ['1d25', '1cba']; // tm (P2PKH) and t2 (P2SH) for testnet
|
|
38
|
+
return validPrefixes.includes(versionPrefix);
|
|
39
|
+
}
|
|
40
|
+
export default (networkType) => ({
|
|
41
|
+
isValidAddress(address) {
|
|
42
|
+
const addr = getAddress(address);
|
|
43
|
+
// Only validate transparent addresses (t1/t3 for mainnet, tm/t2 for testnet)
|
|
44
|
+
// Sapling (zs) and Unified (u) addresses are NOT supported
|
|
45
|
+
return isValidTransparentAddress(addr, networkType);
|
|
46
|
+
}
|
|
47
|
+
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "multichain-address-validator",
|
|
3
3
|
"description": "Multichain address validator for Bitcoin and other blockchains.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.8.1",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"0x",
|
|
7
7
|
"zrx",
|
|
@@ -344,7 +344,8 @@
|
|
|
344
344
|
"build": "npm run clean && npm run build:esm && npm run build:cjs",
|
|
345
345
|
"clean": "npx rimraf dist",
|
|
346
346
|
"test": "mocha --import=tsx test/**.test.ts",
|
|
347
|
-
"start": "npm run build && npm test"
|
|
347
|
+
"start": "npm run build && npm test",
|
|
348
|
+
"release": "node scripts/release.mjs"
|
|
348
349
|
},
|
|
349
350
|
"dependencies": {
|
|
350
351
|
"@noble/hashes": "^1.4.0",
|
package/.editorconfig
DELETED
package/.travis.yml
DELETED
package/.vscode/launch.json
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
// Use IntelliSense to learn about possible attributes.
|
|
3
|
-
// Hover to view descriptions of existing attributes.
|
|
4
|
-
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
5
|
-
"version": "0.2.0",
|
|
6
|
-
"configurations": [
|
|
7
|
-
{
|
|
8
|
-
"type": "node",
|
|
9
|
-
"request": "launch",
|
|
10
|
-
"name": "Mocha Tests",
|
|
11
|
-
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
|
|
12
|
-
"args": [
|
|
13
|
-
"-u",
|
|
14
|
-
"tdd",
|
|
15
|
-
"--timeout",
|
|
16
|
-
"999999",
|
|
17
|
-
"--colors",
|
|
18
|
-
"${workspaceFolder}/test"
|
|
19
|
-
],
|
|
20
|
-
"internalConsoleOptions": "openOnSessionStart"
|
|
21
|
-
}
|
|
22
|
-
]
|
|
23
|
-
}
|
package/index.html
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
<html>
|
|
2
|
-
<body>
|
|
3
|
-
<script src="./dist/multichain-address-validator.bundle.min.js"></script>
|
|
4
|
-
<script type="module">
|
|
5
|
-
const valid = MCAV.validate('1KFzzGtDdnq5hrwxXGjwVnKzRbvf8WVxck', 'BTC');
|
|
6
|
-
if (valid)
|
|
7
|
-
console.log('This is a valid address');
|
|
8
|
-
else
|
|
9
|
-
console.log('Address INVALID');
|
|
10
|
-
</script>
|
|
11
|
-
</body>
|
|
12
|
-
</html>
|
package/src/chain-validators.ts
DELETED
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import type {Chain, Validator} from './types.js'
|
|
2
|
-
import { NetworkType } from './types.js'
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
AlgorandValidator,
|
|
6
|
-
BCHValidator,
|
|
7
|
-
BTCValidator,
|
|
8
|
-
CardanoValidator,
|
|
9
|
-
EOSValidator,
|
|
10
|
-
ETHValidator,
|
|
11
|
-
HederaValidator,
|
|
12
|
-
MoneroValidator,
|
|
13
|
-
MoveValidator,
|
|
14
|
-
NanoValidator,
|
|
15
|
-
NemValidator,
|
|
16
|
-
PolkadotValidator,
|
|
17
|
-
RippleValidator,
|
|
18
|
-
SiaValidator,
|
|
19
|
-
SolanaValidator,
|
|
20
|
-
TezosValidator,
|
|
21
|
-
TronValidator,
|
|
22
|
-
XLMValidator,
|
|
23
|
-
} from './validators/index.js'
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
type ChainValidators = Record<string, {
|
|
27
|
-
alternatives?: string[],
|
|
28
|
-
validator: Validator | {
|
|
29
|
-
mainnet: Validator,
|
|
30
|
-
testnet: Validator,
|
|
31
|
-
},
|
|
32
|
-
}>
|
|
33
|
-
|
|
34
|
-
const chainValidators: ChainValidators = {
|
|
35
|
-
algorand: {validator: AlgorandValidator},
|
|
36
|
-
aptos: {validator: MoveValidator},
|
|
37
|
-
bitcoin: {
|
|
38
|
-
alternatives: ['btc', 'omni'],
|
|
39
|
-
validator: {
|
|
40
|
-
mainnet: BTCValidator({
|
|
41
|
-
addressTypes: ['00', '05'],
|
|
42
|
-
bech32Hrp: ['bc'],
|
|
43
|
-
}),
|
|
44
|
-
testnet: BTCValidator({
|
|
45
|
-
addressTypes: ['6f', 'c4', '3c', '26'],
|
|
46
|
-
bech32Hrp: ['tb'],
|
|
47
|
-
}),
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
'bitcoincash': {
|
|
51
|
-
alternatives: ['bch', 'bitcoin-cash', 'bitcoin cash'],
|
|
52
|
-
validator: {
|
|
53
|
-
mainnet: BCHValidator({
|
|
54
|
-
addressTypes: ['00', '05'],
|
|
55
|
-
bech32Hrp: ['bc'],
|
|
56
|
-
networkType: NetworkType.MainNet,
|
|
57
|
-
}),
|
|
58
|
-
testnet: BCHValidator({
|
|
59
|
-
addressTypes: ['6f', 'c4', '3c', '26'],
|
|
60
|
-
bech32Hrp: ['tb'],
|
|
61
|
-
networkType: NetworkType.TestNet,
|
|
62
|
-
}),
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
cardano: {
|
|
66
|
-
alternatives: ['ada'],
|
|
67
|
-
validator: CardanoValidator,
|
|
68
|
-
},
|
|
69
|
-
doge: {
|
|
70
|
-
alternatives: ['dogecoin'],
|
|
71
|
-
validator: {
|
|
72
|
-
mainnet: BTCValidator({addressTypes: ['1e', '16']}),
|
|
73
|
-
testnet: BTCValidator({addressTypes: ['71', 'c4']}),
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
eos: {validator: EOSValidator},
|
|
77
|
-
ethereum: {
|
|
78
|
-
alternatives: [
|
|
79
|
-
'arbitrum',
|
|
80
|
-
'avalanche',
|
|
81
|
-
'avalanche-c',
|
|
82
|
-
'base',
|
|
83
|
-
'berachain',
|
|
84
|
-
'binance',
|
|
85
|
-
'BinanceSmartChain',
|
|
86
|
-
'bnb',
|
|
87
|
-
'bsc',
|
|
88
|
-
'eth',
|
|
89
|
-
'EthereumClassic',
|
|
90
|
-
'EthereumPow',
|
|
91
|
-
'erc20',
|
|
92
|
-
'flare',
|
|
93
|
-
'optimism',
|
|
94
|
-
'sonic',
|
|
95
|
-
'story',
|
|
96
|
-
],
|
|
97
|
-
validator: ETHValidator
|
|
98
|
-
},
|
|
99
|
-
hedera: {
|
|
100
|
-
alternatives: ['hbar'],
|
|
101
|
-
validator: HederaValidator
|
|
102
|
-
},
|
|
103
|
-
litecoin: {
|
|
104
|
-
alternatives: ['ltc'],
|
|
105
|
-
validator: {
|
|
106
|
-
mainnet: BTCValidator({
|
|
107
|
-
addressTypes: ['30', '32'],
|
|
108
|
-
bech32Hrp: ['ltc'],
|
|
109
|
-
}),
|
|
110
|
-
testnet: BTCValidator({
|
|
111
|
-
addressTypes: ['6f', 'c4', '3a'],
|
|
112
|
-
bech32Hrp: ['tltc']
|
|
113
|
-
})
|
|
114
|
-
}
|
|
115
|
-
},
|
|
116
|
-
monero: {
|
|
117
|
-
validator: {
|
|
118
|
-
mainnet: MoneroValidator(NetworkType.MainNet),
|
|
119
|
-
testnet: MoneroValidator(NetworkType.TestNet),
|
|
120
|
-
}
|
|
121
|
-
},
|
|
122
|
-
nem: {validator: NemValidator},
|
|
123
|
-
nano: {validator: NanoValidator},
|
|
124
|
-
polkadot: {validator: PolkadotValidator},
|
|
125
|
-
ripple: {
|
|
126
|
-
alternatives: ['xrp'],
|
|
127
|
-
validator: RippleValidator,
|
|
128
|
-
},
|
|
129
|
-
sia: {
|
|
130
|
-
alternatives: ['SiaCoin'],
|
|
131
|
-
validator: SiaValidator
|
|
132
|
-
},
|
|
133
|
-
solana: {
|
|
134
|
-
alternatives: ['sol','spl'],
|
|
135
|
-
validator: SolanaValidator,
|
|
136
|
-
},
|
|
137
|
-
sui: {validator: MoveValidator},
|
|
138
|
-
tron: {
|
|
139
|
-
alternatives: ['trc20'],
|
|
140
|
-
validator: TronValidator(),
|
|
141
|
-
},
|
|
142
|
-
tezos: {validator: TezosValidator},
|
|
143
|
-
xlm: {
|
|
144
|
-
alternatives: ['stellar', 'stellarlumens'],
|
|
145
|
-
validator: XLMValidator,
|
|
146
|
-
},
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export function getValidatorForChain(chain: Chain): Validator | undefined {
|
|
150
|
-
const chainName = (chain as any).chain || chain
|
|
151
|
-
const networkType = (chain as any).networkType || NetworkType.MainNet
|
|
152
|
-
|
|
153
|
-
const key = Object.keys(chainValidators).find(key =>
|
|
154
|
-
key.toUpperCase() === chainName.toUpperCase() || chainValidators[key]
|
|
155
|
-
?.alternatives
|
|
156
|
-
?.map(alternative => alternative.toUpperCase())
|
|
157
|
-
?.includes(chainName.toUpperCase())
|
|
158
|
-
)
|
|
159
|
-
|
|
160
|
-
return chainValidators[key]?.validator[networkType] || chainValidators[key]?.validator
|
|
161
|
-
}
|
package/src/crypto/base32.ts
DELETED
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Encode a string to base32
|
|
5
|
-
*/
|
|
6
|
-
const b32encode = function(s: string) {
|
|
7
|
-
const parts = [];
|
|
8
|
-
let quanta = Math.floor((s.length / 5));
|
|
9
|
-
const leftover = s.length % 5;
|
|
10
|
-
|
|
11
|
-
if (leftover != 0) {
|
|
12
|
-
for (let i = 0; i < (5 - leftover); i++) {
|
|
13
|
-
s += '\x00';
|
|
14
|
-
}
|
|
15
|
-
quanta += 1;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
for (let i = 0; i < quanta; i++) {
|
|
19
|
-
parts.push(alphabet.charAt(s.charCodeAt(i * 5) >> 3));
|
|
20
|
-
parts.push(alphabet.charAt(((s.charCodeAt(i * 5) & 0x07) << 2) | (s.charCodeAt(i * 5 + 1) >> 6)));
|
|
21
|
-
parts.push(alphabet.charAt(((s.charCodeAt(i * 5 + 1) & 0x3F) >> 1)));
|
|
22
|
-
parts.push(alphabet.charAt(((s.charCodeAt(i * 5 + 1) & 0x01) << 4) | (s.charCodeAt(i * 5 + 2) >> 4)));
|
|
23
|
-
parts.push(alphabet.charAt(((s.charCodeAt(i * 5 + 2) & 0x0F) << 1) | (s.charCodeAt(i * 5 + 3) >> 7)));
|
|
24
|
-
parts.push(alphabet.charAt(((s.charCodeAt(i * 5 + 3) & 0x7F) >> 2)));
|
|
25
|
-
parts.push(alphabet.charAt(((s.charCodeAt(i * 5 + 3) & 0x03) << 3) | (s.charCodeAt(i * 5 + 4) >> 5)));
|
|
26
|
-
parts.push(alphabet.charAt(((s.charCodeAt(i * 5 + 4) & 0x1F))));
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
let replace = 0;
|
|
30
|
-
if (leftover == 1) replace = 6;
|
|
31
|
-
else if (leftover == 2) replace = 4;
|
|
32
|
-
else if (leftover == 3) replace = 3;
|
|
33
|
-
else if (leftover == 4) replace = 1;
|
|
34
|
-
|
|
35
|
-
for (let i = 0; i < replace; i++) parts.pop();
|
|
36
|
-
for (let i = 0; i < replace; i++) parts.push("=");
|
|
37
|
-
|
|
38
|
-
return parts.join("");
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* Decode a base32 string.
|
|
43
|
-
* This is made specifically for our use, deals only with proper strings
|
|
44
|
-
*/
|
|
45
|
-
const b32decode = function(s: string) {
|
|
46
|
-
const r = new ArrayBuffer(s.length * 5 / 8);
|
|
47
|
-
const b = new Uint8Array(r);
|
|
48
|
-
for (let j = 0; j < s.length / 8; j++) {
|
|
49
|
-
const v = [0, 0, 0, 0, 0, 0, 0, 0];
|
|
50
|
-
for (let i = 0; i < 8; ++i) {
|
|
51
|
-
v[i] = alphabet.indexOf(s[j * 8 + i]);
|
|
52
|
-
}
|
|
53
|
-
const i = 0;
|
|
54
|
-
b[j * 5 + 0] = (v[i + 0] << 3) | (v[i + 1] >> 2);
|
|
55
|
-
b[j * 5 + 1] = ((v[i + 1] & 0x3) << 6) | (v[i + 2] << 1) | (v[i + 3] >> 4);
|
|
56
|
-
b[j * 5 + 2] = ((v[i + 3] & 0xf) << 4) | (v[i + 4] >> 1);
|
|
57
|
-
b[j * 5 + 3] = ((v[i + 4] & 0x1) << 7) | (v[i + 5] << 2) | (v[i + 6] >> 3);
|
|
58
|
-
b[j * 5 + 4] = ((v[i + 6] & 0x7) << 5) | (v[i + 7]);
|
|
59
|
-
}
|
|
60
|
-
return b;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export default {
|
|
64
|
-
b32decode,
|
|
65
|
-
b32encode
|
|
66
|
-
};
|
package/src/crypto/base58.ts
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
// Base58 encoding/decoding
|
|
2
|
-
// Originally written by Mike Hearn for BitcoinJ
|
|
3
|
-
// Copyright (c) 2011 Google Inc
|
|
4
|
-
// Ported to JavaScript by Stefan Thomas
|
|
5
|
-
// Merged Buffer refactorings from base58-native by Stephen Pair
|
|
6
|
-
// Copyright (c) 2013 BitPay Inc
|
|
7
|
-
|
|
8
|
-
const ALPHABET = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
|
|
9
|
-
const ALPHABET_MAP = {};
|
|
10
|
-
for (let i = 0; i < ALPHABET.length; ++i) {
|
|
11
|
-
ALPHABET_MAP[ALPHABET.charAt(i)] = i;
|
|
12
|
-
}
|
|
13
|
-
const BASE = ALPHABET.length;
|
|
14
|
-
|
|
15
|
-
export default {
|
|
16
|
-
decode: function(string: string) {
|
|
17
|
-
if (string.length === 0) return [];
|
|
18
|
-
|
|
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)) throw new Error('Non-base58 character');
|
|
23
|
-
|
|
24
|
-
for (j = 0; j < bytes.length; ++j) bytes[j] *= BASE
|
|
25
|
-
bytes[0] += ALPHABET_MAP[c];
|
|
26
|
-
|
|
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
|
-
|
|
34
|
-
while (carry) {
|
|
35
|
-
bytes.push(carry & 0xff);
|
|
36
|
-
carry >>= 8;
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
// deal with leading zeros
|
|
40
|
-
for (i = 0; string[i] === '1' && i < string.length - 1; ++i){
|
|
41
|
-
bytes.push(0);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return bytes.reverse();
|
|
45
|
-
}
|
|
46
|
-
};
|
package/src/crypto/bech32.js
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
// Copyright (c) 2017, 2021 Pieter Wuille
|
|
2
|
-
//
|
|
3
|
-
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
-
// of this software and associated documentation files (the "Software"), to deal
|
|
5
|
-
// in the Software without restriction, including without limitation the rights
|
|
6
|
-
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
-
// copies of the Software, and to permit persons to whom the Software is
|
|
8
|
-
// furnished to do so, subject to the following conditions:
|
|
9
|
-
//
|
|
10
|
-
// The above copyright notice and this permission notice shall be included in
|
|
11
|
-
// all copies or substantial portions of the Software.
|
|
12
|
-
//
|
|
13
|
-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
-
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
-
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
-
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
-
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
-
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
19
|
-
// THE SOFTWARE.
|
|
20
|
-
|
|
21
|
-
var CHARSET = 'qpzry9x8gf2tvdw0s3jn54khce6mua7l';
|
|
22
|
-
var GENERATOR = [0x3b6a57b2, 0x26508e6d, 0x1ea119fa, 0x3d4233dd, 0x2a1462b3];
|
|
23
|
-
|
|
24
|
-
const encodings = {
|
|
25
|
-
BECH32: "bech32",
|
|
26
|
-
BECH32M: "bech32m",
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export default {
|
|
30
|
-
decode: decode,
|
|
31
|
-
encode: encode,
|
|
32
|
-
encodings: encodings,
|
|
33
|
-
verifyChecksum: verifyChecksum
|
|
34
|
-
};
|
|
35
|
-
|
|
36
|
-
function getEncodingConst (enc) {
|
|
37
|
-
if (enc == encodings.BECH32) {
|
|
38
|
-
return 1;
|
|
39
|
-
} else if (enc == encodings.BECH32M) {
|
|
40
|
-
return 0x2bc830a3;
|
|
41
|
-
} else {
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
function polymod (values) {
|
|
47
|
-
var chk = 1;
|
|
48
|
-
for (var p = 0; p < values.length; ++p) {
|
|
49
|
-
var top = chk >> 25;
|
|
50
|
-
chk = (chk & 0x1ffffff) << 5 ^ values[p];
|
|
51
|
-
for (var i = 0; i < 5; ++i) {
|
|
52
|
-
if ((top >> i) & 1) {
|
|
53
|
-
chk ^= GENERATOR[i];
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
return chk;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
function hrpExpand (hrp) {
|
|
61
|
-
var ret = [];
|
|
62
|
-
var p;
|
|
63
|
-
for (p = 0; p < hrp.length; ++p) {
|
|
64
|
-
ret.push(hrp.charCodeAt(p) >> 5);
|
|
65
|
-
}
|
|
66
|
-
ret.push(0);
|
|
67
|
-
for (p = 0; p < hrp.length; ++p) {
|
|
68
|
-
ret.push(hrp.charCodeAt(p) & 31);
|
|
69
|
-
}
|
|
70
|
-
return ret;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function verifyChecksum (hrp, data, enc) {
|
|
74
|
-
return polymod(hrpExpand(hrp).concat(data)) === getEncodingConst(enc);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function createChecksum (hrp, data, enc) {
|
|
78
|
-
var values = hrpExpand(hrp).concat(data).concat([0, 0, 0, 0, 0, 0]);
|
|
79
|
-
var mod = polymod(values) ^ getEncodingConst(enc);
|
|
80
|
-
var ret = [];
|
|
81
|
-
for (var p = 0; p < 6; ++p) {
|
|
82
|
-
ret.push((mod >> 5 * (5 - p)) & 31);
|
|
83
|
-
}
|
|
84
|
-
return ret;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function encode (hrp, data, enc) {
|
|
88
|
-
var combined = data.concat(createChecksum(hrp, data, enc));
|
|
89
|
-
var ret = hrp + '1';
|
|
90
|
-
for (var p = 0; p < combined.length; ++p) {
|
|
91
|
-
ret += CHARSET.charAt(combined[p]);
|
|
92
|
-
}
|
|
93
|
-
return ret;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function decode (bechString, enc) {
|
|
97
|
-
var p;
|
|
98
|
-
var has_lower = false;
|
|
99
|
-
var has_upper = false;
|
|
100
|
-
for (p = 0; p < bechString.length; ++p) {
|
|
101
|
-
if (bechString.charCodeAt(p) < 33 || bechString.charCodeAt(p) > 126) {
|
|
102
|
-
return null;
|
|
103
|
-
}
|
|
104
|
-
if (bechString.charCodeAt(p) >= 97 && bechString.charCodeAt(p) <= 122) {
|
|
105
|
-
has_lower = true;
|
|
106
|
-
}
|
|
107
|
-
if (bechString.charCodeAt(p) >= 65 && bechString.charCodeAt(p) <= 90) {
|
|
108
|
-
has_upper = true;
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
if (has_lower && has_upper) {
|
|
112
|
-
return null;
|
|
113
|
-
}
|
|
114
|
-
bechString = bechString.toLowerCase();
|
|
115
|
-
var pos = bechString.lastIndexOf('1');
|
|
116
|
-
if (pos < 1 || pos + 7 > bechString.length || bechString.length > 110) {
|
|
117
|
-
return null;
|
|
118
|
-
}
|
|
119
|
-
var hrp = bechString.substring(0, pos);
|
|
120
|
-
var data = [];
|
|
121
|
-
for (p = pos + 1; p < bechString.length; ++p) {
|
|
122
|
-
var d = CHARSET.indexOf(bechString.charAt(p));
|
|
123
|
-
if (d === -1) {
|
|
124
|
-
return null;
|
|
125
|
-
}
|
|
126
|
-
data.push(d);
|
|
127
|
-
}
|
|
128
|
-
if (!verifyChecksum(hrp, data, enc)) {
|
|
129
|
-
return null;
|
|
130
|
-
}
|
|
131
|
-
return {hrp: hrp, data: data.slice(0, data.length - 6)};
|
|
132
|
-
}
|