@bitpay-labs/crypto-wallet-core 11.11.5 → 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.
Files changed (81) hide show
  1. package/package.json +9 -3
  2. package/ts_build/src/transactions/index.d.ts +1 -1
  3. package/ts_build/src/transactions/index.d.ts.map +1 -1
  4. package/ts_build/src/transactions/index.js.map +1 -1
  5. package/ts_build/src/types/derivation.d.ts +1 -0
  6. package/ts_build/src/types/derivation.d.ts.map +1 -1
  7. package/.mocharc.json +0 -6
  8. package/LICENSE +0 -21
  9. package/mcr.config.js +0 -17
  10. package/src/constants/address.ts +0 -7
  11. package/src/constants/algorithms.ts +0 -9
  12. package/src/constants/arc.ts +0 -4
  13. package/src/constants/chains.ts +0 -68
  14. package/src/constants/feeMinimums.ts +0 -23
  15. package/src/constants/index.ts +0 -40
  16. package/src/constants/tokens.ts +0 -233
  17. package/src/constants/units.ts +0 -311
  18. package/src/derivation/arb/index.ts +0 -3
  19. package/src/derivation/base/index.ts +0 -3
  20. package/src/derivation/bch/index.ts +0 -11
  21. package/src/derivation/btc/index.ts +0 -68
  22. package/src/derivation/doge/index.ts +0 -6
  23. package/src/derivation/eth/index.ts +0 -86
  24. package/src/derivation/index.ts +0 -140
  25. package/src/derivation/ltc/index.ts +0 -6
  26. package/src/derivation/matic/index.ts +0 -3
  27. package/src/derivation/op/index.ts +0 -3
  28. package/src/derivation/paths.ts +0 -45
  29. package/src/derivation/sol/index.ts +0 -81
  30. package/src/derivation/xrp/index.ts +0 -63
  31. package/src/index.ts +0 -48
  32. package/src/message/btc.ts +0 -28
  33. package/src/message/eth.ts +0 -47
  34. package/src/message/index.ts +0 -71
  35. package/src/message/sol.ts +0 -3
  36. package/src/message/xrp.ts +0 -4
  37. package/src/transactions/arb/index.ts +0 -14
  38. package/src/transactions/base/index.ts +0 -13
  39. package/src/transactions/bch/index.ts +0 -25
  40. package/src/transactions/btc/index.ts +0 -316
  41. package/src/transactions/doge/index.ts +0 -31
  42. package/src/transactions/erc20/abi.ts +0 -418
  43. package/src/transactions/erc20/index.ts +0 -57
  44. package/src/transactions/eth/index.ts +0 -192
  45. package/src/transactions/eth-multisig/abi.ts +0 -724
  46. package/src/transactions/eth-multisig/index.ts +0 -172
  47. package/src/transactions/index.ts +0 -85
  48. package/src/transactions/ltc/index.ts +0 -31
  49. package/src/transactions/matic/index.ts +0 -14
  50. package/src/transactions/matic-multisig/index.ts +0 -172
  51. package/src/transactions/op/index.ts +0 -14
  52. package/src/transactions/sol/index.ts +0 -306
  53. package/src/transactions/spl/index.ts +0 -192
  54. package/src/transactions/xrp/index.ts +0 -167
  55. package/src/types/derivation.ts +0 -34
  56. package/src/types/index.ts +0 -3
  57. package/src/types/message.ts +0 -15
  58. package/src/types/utils.ts +0 -1
  59. package/src/types/validation.ts +0 -4
  60. package/src/utils/bigint.ts +0 -238
  61. package/src/utils/index.ts +0 -188
  62. package/src/validation/arb/index.ts +0 -8
  63. package/src/validation/arc/index.ts +0 -8
  64. package/src/validation/base/index.ts +0 -8
  65. package/src/validation/bch/index.ts +0 -17
  66. package/src/validation/btc/index.ts +0 -17
  67. package/src/validation/doge/index.ts +0 -16
  68. package/src/validation/eth/index.ts +0 -29
  69. package/src/validation/index.ts +0 -45
  70. package/src/validation/ltc/index.ts +0 -16
  71. package/src/validation/matic/index.ts +0 -8
  72. package/src/validation/op/index.ts +0 -8
  73. package/src/validation/sol/index.ts +0 -34
  74. package/src/validation/xrp/index.ts +0 -50
  75. package/test/address.test.ts +0 -190
  76. package/test/bigint.test.ts +0 -373
  77. package/test/deriver.test.ts +0 -126
  78. package/test/transactions.test.ts +0 -2103
  79. package/test/utils.test.ts +0 -446
  80. package/test/validation.test.ts +0 -282
  81. package/tsconfig.json +0 -29
@@ -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
- };
@@ -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
- }
@@ -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
- }
@@ -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();
@@ -1,3 +0,0 @@
1
- import { EthMessage } from './eth';
2
-
3
- export class SolMessage extends EthMessage {}; // TODO
@@ -1,4 +0,0 @@
1
- import { EthMessage } from './eth';
2
-
3
- // XRP reuses Ethereum-compatible message signing format
4
- export class XrpMessage extends EthMessage {};
@@ -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
- }