@bitpay-labs/crypto-wallet-core 11.11.4 → 11.11.6
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/package.json +9 -3
- package/ts_build/src/constants/index.d.ts +18 -1
- package/ts_build/src/constants/index.d.ts.map +1 -1
- package/ts_build/src/constants/tokens.d.ts +14 -2
- package/ts_build/src/constants/tokens.d.ts.map +1 -1
- package/ts_build/src/constants/tokens.js +8 -2
- package/ts_build/src/constants/tokens.js.map +1 -1
- package/ts_build/src/constants/units.d.ts +11 -0
- package/ts_build/src/constants/units.d.ts.map +1 -1
- package/ts_build/src/constants/units.js +11 -0
- package/ts_build/src/constants/units.js.map +1 -1
- package/ts_build/src/transactions/index.d.ts +1 -1
- package/ts_build/src/transactions/index.d.ts.map +1 -1
- package/ts_build/src/transactions/index.js.map +1 -1
- package/ts_build/src/types/derivation.d.ts +1 -0
- package/ts_build/src/types/derivation.d.ts.map +1 -1
- package/.mocharc.json +0 -6
- package/LICENSE +0 -21
- package/mcr.config.js +0 -17
- package/src/constants/address.ts +0 -7
- package/src/constants/algorithms.ts +0 -9
- package/src/constants/arc.ts +0 -4
- package/src/constants/chains.ts +0 -68
- package/src/constants/feeMinimums.ts +0 -23
- package/src/constants/index.ts +0 -40
- package/src/constants/tokens.ts +0 -227
- package/src/constants/units.ts +0 -300
- package/src/derivation/arb/index.ts +0 -3
- package/src/derivation/base/index.ts +0 -3
- package/src/derivation/bch/index.ts +0 -11
- package/src/derivation/btc/index.ts +0 -68
- package/src/derivation/doge/index.ts +0 -6
- package/src/derivation/eth/index.ts +0 -86
- package/src/derivation/index.ts +0 -140
- package/src/derivation/ltc/index.ts +0 -6
- package/src/derivation/matic/index.ts +0 -3
- package/src/derivation/op/index.ts +0 -3
- package/src/derivation/paths.ts +0 -45
- package/src/derivation/sol/index.ts +0 -81
- package/src/derivation/xrp/index.ts +0 -63
- package/src/index.ts +0 -48
- package/src/message/btc.ts +0 -28
- package/src/message/eth.ts +0 -47
- package/src/message/index.ts +0 -71
- package/src/message/sol.ts +0 -3
- package/src/message/xrp.ts +0 -4
- package/src/transactions/arb/index.ts +0 -14
- package/src/transactions/base/index.ts +0 -13
- package/src/transactions/bch/index.ts +0 -25
- package/src/transactions/btc/index.ts +0 -316
- package/src/transactions/doge/index.ts +0 -31
- package/src/transactions/erc20/abi.ts +0 -418
- package/src/transactions/erc20/index.ts +0 -57
- package/src/transactions/eth/index.ts +0 -192
- package/src/transactions/eth-multisig/abi.ts +0 -724
- package/src/transactions/eth-multisig/index.ts +0 -172
- package/src/transactions/index.ts +0 -85
- package/src/transactions/ltc/index.ts +0 -31
- package/src/transactions/matic/index.ts +0 -14
- package/src/transactions/matic-multisig/index.ts +0 -172
- package/src/transactions/op/index.ts +0 -14
- package/src/transactions/sol/index.ts +0 -306
- package/src/transactions/spl/index.ts +0 -192
- package/src/transactions/xrp/index.ts +0 -167
- package/src/types/derivation.ts +0 -34
- package/src/types/index.ts +0 -3
- package/src/types/message.ts +0 -15
- package/src/types/utils.ts +0 -1
- package/src/types/validation.ts +0 -4
- package/src/utils/bigint.ts +0 -238
- package/src/utils/index.ts +0 -188
- package/src/validation/arb/index.ts +0 -8
- package/src/validation/arc/index.ts +0 -8
- package/src/validation/base/index.ts +0 -8
- package/src/validation/bch/index.ts +0 -17
- package/src/validation/btc/index.ts +0 -17
- package/src/validation/doge/index.ts +0 -16
- package/src/validation/eth/index.ts +0 -29
- package/src/validation/index.ts +0 -45
- package/src/validation/ltc/index.ts +0 -16
- package/src/validation/matic/index.ts +0 -8
- package/src/validation/op/index.ts +0 -8
- package/src/validation/sol/index.ts +0 -34
- package/src/validation/xrp/index.ts +0 -50
- package/test/address.test.ts +0 -190
- package/test/bigint.test.ts +0 -373
- package/test/deriver.test.ts +0 -126
- package/test/transactions.test.ts +0 -2103
- package/test/utils.test.ts +0 -446
- package/test/validation.test.ts +0 -282
- package/tsconfig.json +0 -29
package/src/derivation/index.ts
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { ArbDeriver } from './arb';
|
|
2
|
-
import { BaseDeriver } from './base';
|
|
3
|
-
import { BchDeriver } from './bch';
|
|
4
|
-
import { BtcDeriver } from './btc';
|
|
5
|
-
import { DogeDeriver } from './doge';
|
|
6
|
-
import { EthDeriver } from './eth';
|
|
7
|
-
import { LtcDeriver } from './ltc';
|
|
8
|
-
import { MaticDeriver } from './matic';
|
|
9
|
-
import { OpDeriver } from './op';
|
|
10
|
-
import { Paths } from './paths';
|
|
11
|
-
import { SolDeriver } from './sol';
|
|
12
|
-
import { XrpDeriver } from './xrp';
|
|
13
|
-
import type { IDeriver } from '../types/derivation';
|
|
14
|
-
|
|
15
|
-
const derivers: { [chain: string]: IDeriver } = {
|
|
16
|
-
BTC: new BtcDeriver(),
|
|
17
|
-
BCH: new BchDeriver(),
|
|
18
|
-
ETH: new EthDeriver(),
|
|
19
|
-
XRP: new XrpDeriver(),
|
|
20
|
-
DOGE: new DogeDeriver(),
|
|
21
|
-
LTC: new LtcDeriver(),
|
|
22
|
-
MATIC: new MaticDeriver(),
|
|
23
|
-
ARB: new ArbDeriver(),
|
|
24
|
-
BASE: new BaseDeriver(),
|
|
25
|
-
OP: new OpDeriver(),
|
|
26
|
-
ARC: new EthDeriver(),
|
|
27
|
-
SOL: new SolDeriver()
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export class DeriverProxy {
|
|
31
|
-
private get(chain) {
|
|
32
|
-
const normalizedChain = chain.toUpperCase();
|
|
33
|
-
return derivers[normalizedChain];
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* This is derives addresses using the conventional paths.
|
|
38
|
-
* @param chain
|
|
39
|
-
* @param network
|
|
40
|
-
* @param xpubKey
|
|
41
|
-
* @param addressIndex
|
|
42
|
-
* @param isChange
|
|
43
|
-
* @param addressType
|
|
44
|
-
* @returns
|
|
45
|
-
*/
|
|
46
|
-
deriveAddress(chain, network, xpubKey, addressIndex, isChange, addressType?) {
|
|
47
|
-
return this.get(chain).deriveAddress(network, xpubKey, addressIndex, isChange, addressType);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* This derives keys/addresses using the conventional paths.
|
|
52
|
-
* @param chain
|
|
53
|
-
* @param network
|
|
54
|
-
* @param privKey
|
|
55
|
-
* @param addressIndex
|
|
56
|
-
* @param isChange
|
|
57
|
-
* @param addressType
|
|
58
|
-
* @returns
|
|
59
|
-
*/
|
|
60
|
-
derivePrivateKey(chain, network, privKey, addressIndex, isChange, addressType?) {
|
|
61
|
-
return this.get(chain).derivePrivateKey(network, privKey, addressIndex, isChange, addressType);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* This derives addresses on a specific path.
|
|
66
|
-
* This should probably only be used when importing from another wallet
|
|
67
|
-
* where known paths are provided with their keys. Most of the BitPay
|
|
68
|
-
* codebase uses `deriveAddress()`
|
|
69
|
-
* @param chain
|
|
70
|
-
* @param network
|
|
71
|
-
* @param xpubKey
|
|
72
|
-
* @param path
|
|
73
|
-
* @param addressType
|
|
74
|
-
* @returns
|
|
75
|
-
*/
|
|
76
|
-
deriveAddressWithPath(chain, network, xpubKey, path, addressType) {
|
|
77
|
-
return this.get(chain).deriveAddressWithPath(network, xpubKey, path, addressType);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* This derives keys/addresses on a specific path.
|
|
82
|
-
* This should probably only be used when importing from another wallet
|
|
83
|
-
* where known paths are provided with their keys. Most of the BitPay
|
|
84
|
-
* codebase uses `derivePrivateKey()`
|
|
85
|
-
* @param chain
|
|
86
|
-
* @param network
|
|
87
|
-
* @param xprivKey
|
|
88
|
-
* @param path
|
|
89
|
-
* @param addressType
|
|
90
|
-
* @returns
|
|
91
|
-
*/
|
|
92
|
-
derivePrivateKeyWithPath(chain, network, xprivKey, path, addressType) {
|
|
93
|
-
return this.get(chain).derivePrivateKeyWithPath(network, xprivKey, path, addressType);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* This is a simple function for getting an address from a
|
|
98
|
-
* given pub key and chain. There is no derivation happening.
|
|
99
|
-
* @param chain
|
|
100
|
-
* @param network
|
|
101
|
-
* @param pubKey
|
|
102
|
-
* @param addressType
|
|
103
|
-
* @returns
|
|
104
|
-
*/
|
|
105
|
-
getAddress(chain, network, pubKey, addressType?) {
|
|
106
|
-
return this.get(chain).getAddress(network, pubKey, addressType);
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
* Caller responsible for cleaning up privKey buffer
|
|
111
|
-
*/
|
|
112
|
-
getPublicKey(chain, network, privKey: Buffer) {
|
|
113
|
-
return this.get(chain).getPublicKey(network, privKey);
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
pathFor(chain, network, account = 0) {
|
|
117
|
-
const normalizedChain = chain.toUpperCase();
|
|
118
|
-
const accountStr = `${account}'`;
|
|
119
|
-
const chainConfig = Paths[normalizedChain];
|
|
120
|
-
if (chainConfig) {
|
|
121
|
-
if (chainConfig[network]) {
|
|
122
|
-
return chainConfig[network] + accountStr;
|
|
123
|
-
} else {
|
|
124
|
-
return chainConfig.default + accountStr;
|
|
125
|
-
}
|
|
126
|
-
} else {
|
|
127
|
-
return Paths.BTC.default + accountStr;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
privateKeyToBuffer(chain, privateKey: Buffer | string): Buffer {
|
|
132
|
-
return this.get(chain).privateKeyToBuffer(privateKey);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
bufferToPrivateKey_TEMP(chain: string, network: string, buf: Buffer): string {
|
|
136
|
-
return this.get(chain).bufferToPrivateKey_TEMP(buf, network);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
export default new DeriverProxy();
|
package/src/derivation/paths.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
export const Paths = {
|
|
2
|
-
BTC: {
|
|
3
|
-
mainnet: "m/44'/0'/",
|
|
4
|
-
livenet: "m/44'/0'/",
|
|
5
|
-
default: "m/44'/1'/"
|
|
6
|
-
},
|
|
7
|
-
BCH: {
|
|
8
|
-
mainnet: "m/44'/145'/",
|
|
9
|
-
livenet: "m/44'/145'/",
|
|
10
|
-
default: "m/44'/1'/"
|
|
11
|
-
},
|
|
12
|
-
ETH: {
|
|
13
|
-
default: "m/44'/60'/"
|
|
14
|
-
},
|
|
15
|
-
XRP: {
|
|
16
|
-
default: "m/44'/144'/"
|
|
17
|
-
},
|
|
18
|
-
DOGE: {
|
|
19
|
-
default: "m/44'/3'/"
|
|
20
|
-
},
|
|
21
|
-
LTC: {
|
|
22
|
-
default: "m/44'/2'/"
|
|
23
|
-
},
|
|
24
|
-
MATIC: {
|
|
25
|
-
default: "m/44'/60'/", // the official matic derivation path is 966 but users will expect address to be same as ETH
|
|
26
|
-
},
|
|
27
|
-
ARB: {
|
|
28
|
-
default: "m/44'/60'/",
|
|
29
|
-
},
|
|
30
|
-
OP: {
|
|
31
|
-
default: "m/44'/60'/",
|
|
32
|
-
},
|
|
33
|
-
BASE: {
|
|
34
|
-
default: "m/44'/60'/",
|
|
35
|
-
},
|
|
36
|
-
ARC: {
|
|
37
|
-
default: "m/44'/60'/",
|
|
38
|
-
},
|
|
39
|
-
SOL: {
|
|
40
|
-
default: "m/44'/501'/",
|
|
41
|
-
},
|
|
42
|
-
default: {
|
|
43
|
-
testnet: "m/44'/1'/"
|
|
44
|
-
}
|
|
45
|
-
};
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { HDPrivateKey, encoding } from '@bitpay-labs/bitcore-lib';
|
|
2
|
-
import * as ed25519 from 'ed25519-hd-key';
|
|
3
|
-
import { Paths } from '../paths';
|
|
4
|
-
import type { IDeriver, Key } from '../../types/derivation';
|
|
5
|
-
|
|
6
|
-
export class SolDeriver implements IDeriver {
|
|
7
|
-
deriveAddress(_network, _xpubkey, _addressIndex, _isChange): string {
|
|
8
|
-
throw new Error('Cannot derive Solana addresses from just xpubkey, need to use derivePrivateKeyWithPath');
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
deriveAddressWithPath(_network: string, _xpubKey: string, _path: string): string {
|
|
12
|
-
throw new Error('Cannot derive Solana addresses from just xpubkey, need to use derivePrivateKeyWithPath');
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
getAddress(_network: string, pubKey: string) {
|
|
16
|
-
return this.addressFromPublicKeyBuffer(Buffer.from(pubKey, 'hex'));
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
getPublicKey(_network: string, privKey: Buffer): string {
|
|
20
|
-
if (!Buffer.isBuffer(privKey)) {
|
|
21
|
-
throw new Error('Expected privKey to be a Buffer');
|
|
22
|
-
}
|
|
23
|
-
const pubKey = ed25519.getPublicKey(privKey, false);
|
|
24
|
-
return Buffer.from(pubKey).toString('hex');
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
addressFromPublicKeyBuffer(pubKey: Buffer): string {
|
|
28
|
-
if (pubKey.length > 32) {
|
|
29
|
-
pubKey = pubKey.subarray(pubKey.length - 32);
|
|
30
|
-
}
|
|
31
|
-
return encoding.Base58.encode(pubKey);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
derivePrivateKey(network, xPriv, addressIndex, isChange, addressType) {
|
|
35
|
-
const changeNum = isChange ? 1 : 0;
|
|
36
|
-
const path = `${Paths['SOL'].default}${addressIndex}'/${changeNum}'`;
|
|
37
|
-
return this.derivePrivateKeyWithPath(network, xPriv, path, addressType);
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
deriveChild(masterKey: { key: Buffer; chainCode: Buffer }, path: string) {
|
|
41
|
-
const HARDENED_OFFSET = 0x80000000;
|
|
42
|
-
const segmented = path
|
|
43
|
-
.split('/')
|
|
44
|
-
.slice(1)
|
|
45
|
-
.map((val) => val.replace("'", ''))
|
|
46
|
-
.map(el => parseInt(el, 10));
|
|
47
|
-
return segmented.reduce((parentKeys, segment) => ed25519.CKDPriv(parentKeys, segment + HARDENED_OFFSET), masterKey);
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
derivePrivateKeyWithPath(network: string, xprivKey: string, path: string, _addressType: string) {
|
|
51
|
-
const xpriv = new HDPrivateKey(xprivKey, network);
|
|
52
|
-
const child = this.deriveChild({ key: xpriv._buffers.privateKey, chainCode: xpriv._buffers.chainCode }, path);
|
|
53
|
-
const pubKey = ed25519.getPublicKey(child.key, false);
|
|
54
|
-
const address = encoding.Base58.encode(pubKey);
|
|
55
|
-
// Solana wallets often represent the private key as a KeyPair consisting of the private key + address/public key.
|
|
56
|
-
// The Keypair is usually found in two formats: Base58 or Uint8Array.
|
|
57
|
-
// Here, we represent the keys separately in Base58, which is fine since a keypair can be built or converted by createKeyPairFromPrivateKeyBytes.
|
|
58
|
-
// Public Key is synonymous with Address. Here they are reprsented in two different formats.
|
|
59
|
-
return {
|
|
60
|
-
address,
|
|
61
|
-
privKey: encoding.Base58.encode(child.key),
|
|
62
|
-
pubKey: Buffer.from(pubKey).toString('hex')
|
|
63
|
-
} as Key;
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* @param {Buffer | string} privKey - expects base 58 encoded string
|
|
68
|
-
* @returns {Buffer}
|
|
69
|
-
* @throws {Error} If privKey is not a Buffer (planned forwards compatibility) or string. Propagates all other errors
|
|
70
|
-
*/
|
|
71
|
-
privateKeyToBuffer(privKey: Buffer | string): Buffer {
|
|
72
|
-
if (Buffer.isBuffer(privKey)) return privKey;
|
|
73
|
-
if (typeof privKey !== 'string') throw new Error(`Expected string, got ${typeof privKey}`);
|
|
74
|
-
// Expects to match return from derivePrivateKey's privKey.
|
|
75
|
-
return encoding.Base58.decode(privKey);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
bufferToPrivateKey_TEMP(buf: Buffer, _network: string): string {
|
|
79
|
-
return encoding.Base58.encode(buf);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
import BitcoreLib from '@bitpay-labs/bitcore-lib';
|
|
2
|
-
import { deriveAddress } from 'xrpl';
|
|
3
|
-
import type { IDeriver } from '../../types/derivation';
|
|
4
|
-
|
|
5
|
-
export class XrpDeriver implements IDeriver {
|
|
6
|
-
deriveAddress(network, xpubkey, addressIndex, isChange) {
|
|
7
|
-
const changeNum = isChange ? 1 : 0;
|
|
8
|
-
const path = `m/${changeNum}/${addressIndex}`;
|
|
9
|
-
return this.deriveAddressWithPath(network, xpubkey, path);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
derivePrivateKey(network, xPriv, addressIndex, isChange) {
|
|
13
|
-
const changeNum = isChange ? 1 : 0;
|
|
14
|
-
const path = `m/${changeNum}/${addressIndex}`;
|
|
15
|
-
return this.derivePrivateKeyWithPath(network, xPriv, path);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
deriveAddressWithPath(network: string, xpubKey: string, path: string) {
|
|
19
|
-
const xpub = new BitcoreLib.HDPublicKey(xpubKey, network);
|
|
20
|
-
const pubKey = xpub.derive(path).toObject().publicKey;
|
|
21
|
-
const address = deriveAddress(pubKey);
|
|
22
|
-
return address;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
derivePrivateKeyWithPath(network: string, xprivKey: string, path: string) {
|
|
26
|
-
const xpriv = new BitcoreLib.HDPrivateKey(xprivKey, network);
|
|
27
|
-
const derivedXPriv = xpriv.derive(path);
|
|
28
|
-
const privKey = derivedXPriv.toObject().privateKey.toUpperCase();
|
|
29
|
-
const pubKey = derivedXPriv.hdPublicKey.toObject().publicKey.toUpperCase();
|
|
30
|
-
const address = deriveAddress(pubKey);
|
|
31
|
-
return { address, privKey, pubKey, path };
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
getAddress(network: string, pubKey: string) {
|
|
35
|
-
const address = deriveAddress(pubKey);
|
|
36
|
-
return address;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
getPublicKey(network: string, privKey: Buffer): string {
|
|
40
|
-
if (!Buffer.isBuffer(privKey)) {
|
|
41
|
-
throw new Error('Expected privKey to be a Buffer');
|
|
42
|
-
}
|
|
43
|
-
const bn = BitcoreLib.crypto.BN.fromBuffer(privKey);
|
|
44
|
-
const key = new BitcoreLib.PrivateKey({ bn, network, compressed: true });
|
|
45
|
-
return key.publicKey.toString('hex').toUpperCase();
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* @param {Buffer | string} privKey - expects hex-encoded string, as returned from XrpDeriver.derivePrivateKey privKey
|
|
50
|
-
* @returns {Buffer}
|
|
51
|
-
* @throws {Error} If privKey is not a Buffer (planned forwards compatibility) or string. Propagates all other errors
|
|
52
|
-
*/
|
|
53
|
-
privateKeyToBuffer(privKey: Buffer | string): Buffer {
|
|
54
|
-
if (Buffer.isBuffer(privKey)) return privKey;
|
|
55
|
-
if (typeof privKey !== 'string') throw new Error(`Expected string, got ${typeof privKey}`);
|
|
56
|
-
// Expects to match return from derivePrivateKey's privKey.
|
|
57
|
-
return Buffer.from(privKey, 'hex');
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
bufferToPrivateKey_TEMP(buf: Buffer, _network: string): string {
|
|
61
|
-
return buf.toString('hex').toUpperCase();
|
|
62
|
-
}
|
|
63
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import * as BitcoreLib from '@bitpay-labs/bitcore-lib';
|
|
2
|
-
import * as BitcoreLibCash from '@bitpay-labs/bitcore-lib-cash';
|
|
3
|
-
import * as BitcoreLibDoge from '@bitpay-labs/bitcore-lib-doge';
|
|
4
|
-
import * as BitcoreLibLtc from '@bitpay-labs/bitcore-lib-ltc';
|
|
5
|
-
import * as SolKit from '@solana/kit';
|
|
6
|
-
import * as ComputeBudget from '@solana-program/compute-budget';
|
|
7
|
-
import * as Memo from '@solana-program/memo';
|
|
8
|
-
import * as System from '@solana-program/system';
|
|
9
|
-
import * as Token from '@solana-program/token';
|
|
10
|
-
import * as HDKey from 'ed25519-hd-key';
|
|
11
|
-
import { ethers } from 'ethers';
|
|
12
|
-
import Web3 from 'web3';
|
|
13
|
-
import * as xrpl from 'xrpl';
|
|
14
|
-
import { Constants } from './constants';
|
|
15
|
-
import Deriver from './derivation';
|
|
16
|
-
import Message from './message';
|
|
17
|
-
import Transactions from './transactions';
|
|
18
|
-
import * as Utils from './utils';
|
|
19
|
-
import Validation from './validation';
|
|
20
|
-
|
|
21
|
-
export type * as Types from './types';
|
|
22
|
-
export type * as Web3Types from 'web3-types';
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const SolanaProgram = {
|
|
26
|
-
ComputeBudget,
|
|
27
|
-
Memo,
|
|
28
|
-
System,
|
|
29
|
-
Token,
|
|
30
|
-
HDKey
|
|
31
|
-
};
|
|
32
|
-
export {
|
|
33
|
-
BitcoreLib,
|
|
34
|
-
BitcoreLibCash,
|
|
35
|
-
BitcoreLibDoge,
|
|
36
|
-
BitcoreLibLtc,
|
|
37
|
-
Deriver,
|
|
38
|
-
Message,
|
|
39
|
-
Transactions,
|
|
40
|
-
Validation,
|
|
41
|
-
ethers,
|
|
42
|
-
Web3,
|
|
43
|
-
SolKit,
|
|
44
|
-
SolanaProgram,
|
|
45
|
-
Constants,
|
|
46
|
-
xrpl,
|
|
47
|
-
Utils
|
|
48
|
-
};
|
package/src/message/btc.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import BitcoreLib from '@bitpay-labs/bitcore-lib';
|
|
2
|
-
import { encodeBuffer } from '../utils';
|
|
3
|
-
import type { Encoding, HDKeyType, IMessageClass, ISignedMessage, KeyType } from '../types/message';
|
|
4
|
-
|
|
5
|
-
export class BtcMessage implements IMessageClass {
|
|
6
|
-
getMessageHash(args: { message: string; encoding?: Encoding }): Buffer | string {
|
|
7
|
-
const { message, encoding } = args;
|
|
8
|
-
const buf = Buffer.from(new BitcoreLib.Message(message).magicHash());
|
|
9
|
-
return encodeBuffer(buf, encoding);
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
signMessage(args: { message: string; privateKey: KeyType; encoding?: Encoding }): ISignedMessage {
|
|
13
|
-
const { message, encoding } = args;
|
|
14
|
-
let { privateKey } = args;
|
|
15
|
-
privateKey = new BitcoreLib.PrivateKey(privateKey);
|
|
16
|
-
const buf = Buffer.from(new BitcoreLib.Message(message).sign(privateKey), 'base64');
|
|
17
|
-
return {
|
|
18
|
-
signature: encodeBuffer(buf, encoding),
|
|
19
|
-
publicKey: privateKey.publicKey.toString()
|
|
20
|
-
};
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
signMessageWithPath(args: { message: string; hdPrivateKey: HDKeyType; derivationPath: string; encoding?: Encoding }): ISignedMessage {
|
|
24
|
-
const { message, hdPrivateKey, derivationPath, encoding } = args;
|
|
25
|
-
const privateKey = new BitcoreLib.HDPrivateKey(hdPrivateKey).deriveChild(derivationPath).privateKey;
|
|
26
|
-
return this.signMessage({ message, privateKey, encoding });
|
|
27
|
-
}
|
|
28
|
-
}
|
package/src/message/eth.ts
DELETED
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import BitcoreLib from '@bitpay-labs/bitcore-lib';
|
|
2
|
-
import { ethers } from 'ethers';
|
|
3
|
-
import { encodeBuffer } from '../utils';
|
|
4
|
-
import type { Encoding, HDKeyType, IMessageClass, ISignedMessage, KeyType } from '../types/message';
|
|
5
|
-
|
|
6
|
-
export class EthMessage implements IMessageClass {
|
|
7
|
-
getMessageHash(args: {
|
|
8
|
-
message: string;
|
|
9
|
-
encoding?: Encoding;
|
|
10
|
-
}): Buffer | string {
|
|
11
|
-
const { message, encoding } = args;
|
|
12
|
-
const prefix = '\x19Ethereum Signed Message:\n' + message.length;
|
|
13
|
-
const messageHash = ethers.keccak256(ethers.toUtf8Bytes(prefix + message));
|
|
14
|
-
const buf = Buffer.from(messageHash.slice(2), 'hex');
|
|
15
|
-
return encodeBuffer(buf, encoding);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
signMessage(args: {
|
|
19
|
-
message: string;
|
|
20
|
-
privateKey: KeyType;
|
|
21
|
-
encoding?: Encoding;
|
|
22
|
-
}): ISignedMessage {
|
|
23
|
-
const { message, encoding } = args;
|
|
24
|
-
let { privateKey } = args;
|
|
25
|
-
privateKey = typeof privateKey === 'string' && privateKey.startsWith('0x') ? privateKey.slice(2) : privateKey;
|
|
26
|
-
privateKey = new BitcoreLib.PrivateKey(privateKey);
|
|
27
|
-
const messageHash = this.getMessageHash({ message });
|
|
28
|
-
const signingKey = new ethers.SigningKey('0x' + privateKey.toString('hex'));
|
|
29
|
-
const sig = signingKey.sign(messageHash);
|
|
30
|
-
const buf = Buffer.from(sig.serialized.slice(2), 'hex');
|
|
31
|
-
return {
|
|
32
|
-
signature: encodeBuffer(buf, encoding),
|
|
33
|
-
publicKey: privateKey.publicKey.toString()
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
signMessageWithPath(args: {
|
|
38
|
-
message: string;
|
|
39
|
-
hdPrivateKey: HDKeyType;
|
|
40
|
-
derivationPath: string;
|
|
41
|
-
encoding?: Encoding;
|
|
42
|
-
}): ISignedMessage {
|
|
43
|
-
const { message, hdPrivateKey, derivationPath, encoding } = args;
|
|
44
|
-
const privateKey = new BitcoreLib.HDPrivateKey(hdPrivateKey).deriveChild(derivationPath).privateKey;
|
|
45
|
-
return this.signMessage({ message, privateKey, encoding });
|
|
46
|
-
}
|
|
47
|
-
}
|
package/src/message/index.ts
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { BtcMessage } from './btc';
|
|
2
|
-
import { EthMessage } from './eth';
|
|
3
|
-
import { SolMessage } from './sol';
|
|
4
|
-
import { XrpMessage } from './xrp';
|
|
5
|
-
import type { Encoding, HDKeyType, IMessageClass, ISignedMessage, KeyType } from '../types/message';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const MessageClasses: Record<string, IMessageClass> = {
|
|
9
|
-
btc: new BtcMessage(),
|
|
10
|
-
bch: new BtcMessage(),
|
|
11
|
-
doge: new BtcMessage(),
|
|
12
|
-
ltc: new BtcMessage(),
|
|
13
|
-
eth: new EthMessage(),
|
|
14
|
-
matic: new EthMessage(),
|
|
15
|
-
arb: new EthMessage(),
|
|
16
|
-
base: new EthMessage(),
|
|
17
|
-
op: new EthMessage(),
|
|
18
|
-
arc: new EthMessage(),
|
|
19
|
-
sol: new SolMessage(),
|
|
20
|
-
xrp: new XrpMessage()
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
export class MessageProxy {
|
|
24
|
-
private get(chain: string): IMessageClass {
|
|
25
|
-
const normalizedChain = chain.toLowerCase();
|
|
26
|
-
const messageClass = MessageClasses[normalizedChain];
|
|
27
|
-
if (!messageClass) {
|
|
28
|
-
throw new Error(`Unsupported chain: ${chain}`);
|
|
29
|
-
}
|
|
30
|
-
return messageClass;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
getMessageHash(args: {
|
|
34
|
-
chain: string;
|
|
35
|
-
message: string;
|
|
36
|
-
/** The encoding to use for the output. Will return a Buffer if not specified. */
|
|
37
|
-
encoding?: Encoding;
|
|
38
|
-
}): Buffer | string {
|
|
39
|
-
const { message, chain, encoding } = args;
|
|
40
|
-
const messageClass = this.get(chain);
|
|
41
|
-
return messageClass.getMessageHash({ message, encoding });
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
signMessage(args: {
|
|
45
|
-
chain: string;
|
|
46
|
-
message: string;
|
|
47
|
-
privateKey: KeyType;
|
|
48
|
-
/** The encoding to use for the output. Will return a Buffer if not specified. */
|
|
49
|
-
encoding?: Encoding;
|
|
50
|
-
}): ISignedMessage {
|
|
51
|
-
const { message, chain, privateKey, encoding } = args;
|
|
52
|
-
const messageClass = this.get(chain);
|
|
53
|
-
if (!messageClass) throw new Error(`Unsupported chain: ${chain}`);
|
|
54
|
-
return messageClass.signMessage({ message, privateKey, encoding });
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
signMessageWithPath(args: {
|
|
58
|
-
chain: string;
|
|
59
|
-
message: string;
|
|
60
|
-
hdPrivateKey: HDKeyType;
|
|
61
|
-
derivationPath: string;
|
|
62
|
-
/** The encoding to use for the output. Will return a Buffer if not specified. */
|
|
63
|
-
encoding?: Encoding;
|
|
64
|
-
}): ISignedMessage {
|
|
65
|
-
const { message, chain, hdPrivateKey, derivationPath, encoding } = args;
|
|
66
|
-
const messageClass = this.get(chain);
|
|
67
|
-
return messageClass.signMessageWithPath({ message, hdPrivateKey, derivationPath, encoding });
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export default new MessageProxy();
|
package/src/message/sol.ts
DELETED
package/src/message/xrp.ts
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { ERC20TxProvider } from '../erc20';
|
|
2
|
-
import { ETHTxProvider } from '../eth';
|
|
3
|
-
|
|
4
|
-
export class ARBTxProvider extends ETHTxProvider {
|
|
5
|
-
constructor() {
|
|
6
|
-
super('ARB');
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export class ARBERC20TxProvider extends ERC20TxProvider {
|
|
11
|
-
constructor() {
|
|
12
|
-
super('ARB');
|
|
13
|
-
}
|
|
14
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { OPERC20TxProvider, OPTxProvider } from '../op';
|
|
2
|
-
|
|
3
|
-
export class BASETxProvider extends OPTxProvider {
|
|
4
|
-
constructor() {
|
|
5
|
-
super('BASE');
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export class BASEERC20TxProvider extends OPERC20TxProvider {
|
|
10
|
-
constructor() {
|
|
11
|
-
super('BASE');
|
|
12
|
-
}
|
|
13
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import BitcoreLibCash from '@bitpay-labs/bitcore-lib-cash';
|
|
2
|
-
import { BTCTxProvider, EveryUtxoType } from '../btc';
|
|
3
|
-
|
|
4
|
-
export class BCHTxProvider extends BTCTxProvider {
|
|
5
|
-
lib = BitcoreLibCash;
|
|
6
|
-
create(params: {
|
|
7
|
-
recipients: Array<{ address: string; amount: number | string }>;
|
|
8
|
-
utxos?: EveryUtxoType[];
|
|
9
|
-
change?: string;
|
|
10
|
-
fee?: number | string;
|
|
11
|
-
isSweep?: boolean;
|
|
12
|
-
}): string {
|
|
13
|
-
const { recipients, utxos = [], change, fee = 20000, isSweep } = params;
|
|
14
|
-
const filteredUtxos = isSweep ? utxos : this.selectCoins(recipients, utxos, Number(fee));
|
|
15
|
-
const btcUtxos = filteredUtxos.map(utxo => this.standardizeUtxo(utxo));
|
|
16
|
-
const tx = new this.lib.Transaction().from(btcUtxos).feePerByte(Number(fee) + 2);
|
|
17
|
-
if (change) {
|
|
18
|
-
tx.change(change);
|
|
19
|
-
}
|
|
20
|
-
for (const recipient of recipients) {
|
|
21
|
-
tx.to(recipient.address, Number(recipient.amount));
|
|
22
|
-
}
|
|
23
|
-
return tx.uncheckedSerialize();
|
|
24
|
-
}
|
|
25
|
-
}
|