@btc-vision/wallet-sdk 1.0.0 → 1.0.4

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 (129) hide show
  1. package/es/bundle.js +1 -1
  2. package/es/bundle.js.LICENSE.txt +4 -4
  3. package/lib/address/index.js +50 -85
  4. package/lib/bitcoin-core.js +7 -37
  5. package/lib/constants.js +1 -4
  6. package/lib/error.js +6 -10
  7. package/lib/index.js +14 -43
  8. package/lib/keyring/hd-keyring.js +40 -79
  9. package/lib/keyring/index.js +4 -20
  10. package/lib/keyring/interfaces/SimpleKeyringOptions.js +16 -31
  11. package/lib/keyring/keystone-keyring.js +142 -201
  12. package/lib/keyring/simple-keyring.js +13 -18
  13. package/lib/message/bip322-simple.js +31 -71
  14. package/lib/message/deterministic-ecdsa.js +19 -40
  15. package/lib/message/ecdsa.js +10 -18
  16. package/lib/message/index.js +3 -19
  17. package/lib/network/index.js +12 -17
  18. package/lib/runes/index.js +1 -17
  19. package/lib/runes/rund_id.js +8 -13
  20. package/lib/runes/varint.js +6 -12
  21. package/lib/transaction/index.js +3 -19
  22. package/lib/transaction/inscription-utxo.js +45 -38
  23. package/lib/transaction/transaction.js +134 -139
  24. package/lib/transaction/utxo.js +13 -18
  25. package/lib/tx-helpers/index.js +8 -18
  26. package/lib/tx-helpers/send-atomicals-ft.js +45 -60
  27. package/lib/tx-helpers/send-atomicals-nft.js +29 -44
  28. package/lib/tx-helpers/send-btc.js +53 -71
  29. package/lib/tx-helpers/send-inscription.js +32 -47
  30. package/lib/tx-helpers/send-inscriptions.js +28 -43
  31. package/lib/tx-helpers/send-runes.js +83 -97
  32. package/lib/tx-helpers/split-inscription-utxo.js +39 -54
  33. package/lib/types.js +2 -5
  34. package/lib/utils.js +16 -29
  35. package/lib/wallet/abstract-wallet.js +1 -2
  36. package/lib/wallet/estimate-wallet.js +130 -147
  37. package/lib/wallet/index.js +3 -19
  38. package/lib/wallet/local-wallet.js +134 -150
  39. package/package.json +103 -95
  40. package/lib/address/index.d.ts +0 -37
  41. package/lib/bitcoin-core.d.ts +0 -5
  42. package/lib/constants.d.ts +0 -1
  43. package/lib/error.d.ts +0 -20
  44. package/lib/index.d.ts +0 -14
  45. package/lib/keyring/hd-keyring.d.ts +0 -50
  46. package/lib/keyring/index.d.ts +0 -4
  47. package/lib/keyring/interfaces/SimpleKeyringOptions.d.ts +0 -53
  48. package/lib/keyring/keystone-keyring.d.ts +0 -82
  49. package/lib/keyring/simple-keyring.d.ts +0 -11
  50. package/lib/message/bip322-simple.d.ts +0 -19
  51. package/lib/message/deterministic-ecdsa.d.ts +0 -2
  52. package/lib/message/ecdsa.d.ts +0 -3
  53. package/lib/message/index.d.ts +0 -3
  54. package/lib/network/index.d.ts +0 -14
  55. package/lib/runes/index.d.ts +0 -1
  56. package/lib/runes/rund_id.d.ts +0 -11
  57. package/lib/runes/varint.d.ts +0 -15
  58. package/lib/src/address/index.d.ts +0 -37
  59. package/lib/src/bitcoin-core.d.ts +0 -5
  60. package/lib/src/constants.d.ts +0 -1
  61. package/lib/src/error.d.ts +0 -20
  62. package/lib/src/index.d.ts +0 -14
  63. package/lib/src/keyring/hd-keyring.d.ts +0 -50
  64. package/lib/src/keyring/index.d.ts +0 -4
  65. package/lib/src/keyring/interfaces/SimpleKeyringOptions.d.ts +0 -53
  66. package/lib/src/keyring/keystone-keyring.d.ts +0 -82
  67. package/lib/src/keyring/simple-keyring.d.ts +0 -11
  68. package/lib/src/message/bip322-simple.d.ts +0 -19
  69. package/lib/src/message/deterministic-ecdsa.d.ts +0 -2
  70. package/lib/src/message/ecdsa.d.ts +0 -3
  71. package/lib/src/message/index.d.ts +0 -3
  72. package/lib/src/network/index.d.ts +0 -14
  73. package/lib/src/runes/index.d.ts +0 -1
  74. package/lib/src/runes/rund_id.d.ts +0 -11
  75. package/lib/src/runes/varint.d.ts +0 -15
  76. package/lib/src/transaction/index.d.ts +0 -3
  77. package/lib/src/transaction/inscription-utxo.d.ts +0 -33
  78. package/lib/src/transaction/transaction.d.ts +0 -52
  79. package/lib/src/transaction/utxo.d.ts +0 -35
  80. package/lib/src/tx-helpers/index.d.ts +0 -8
  81. package/lib/src/tx-helpers/send-atomicals-ft.d.ts +0 -16
  82. package/lib/src/tx-helpers/send-atomicals-nft.d.ts +0 -14
  83. package/lib/src/tx-helpers/send-btc.d.ts +0 -28
  84. package/lib/src/tx-helpers/send-inscription.d.ts +0 -16
  85. package/lib/src/tx-helpers/send-inscriptions.d.ts +0 -14
  86. package/lib/src/tx-helpers/send-runes.d.ts +0 -19
  87. package/lib/src/tx-helpers/split-inscription-utxo.d.ts +0 -15
  88. package/lib/src/types.d.ts +0 -59
  89. package/lib/src/utils.d.ts +0 -23
  90. package/lib/src/wallet/abstract-wallet.d.ts +0 -6
  91. package/lib/src/wallet/estimate-wallet.d.ts +0 -23
  92. package/lib/src/wallet/index.d.ts +0 -3
  93. package/lib/src/wallet/local-wallet.d.ts +0 -23
  94. package/lib/test/address/address.test.d.ts +0 -1
  95. package/lib/test/keyring/hd-keyring.test.d.ts +0 -1
  96. package/lib/test/keyring/keystone-keyring.test.d.ts +0 -1
  97. package/lib/test/keyring/simple-keyring.test.d.ts +0 -1
  98. package/lib/test/message/message.test.d.ts +0 -1
  99. package/lib/test/runes/varint.test.d.ts +0 -1
  100. package/lib/test/transaction/transaction.test.d.ts +0 -1
  101. package/lib/test/transaction/utxo.test.d.ts +0 -1
  102. package/lib/test/tx-helpers/send-atomicals-ft.test.d.ts +0 -1
  103. package/lib/test/tx-helpers/send-atomicals-nft.test.d.ts +0 -1
  104. package/lib/test/tx-helpers/send-btc.test.d.ts +0 -1
  105. package/lib/test/tx-helpers/send-inscription.test.d.ts +0 -1
  106. package/lib/test/tx-helpers/send-inscriptions.test.d.ts +0 -1
  107. package/lib/test/tx-helpers/send-runes.test.d.ts +0 -1
  108. package/lib/test/tx-helpers/split-inscription-utxo.test.d.ts +0 -1
  109. package/lib/test/tx-helpers/utils.d.ts +0 -217
  110. package/lib/test/utils.d.ts +0 -4
  111. package/lib/test/wallet/local-wallet.test.d.ts +0 -1
  112. package/lib/transaction/index.d.ts +0 -3
  113. package/lib/transaction/inscription-utxo.d.ts +0 -33
  114. package/lib/transaction/transaction.d.ts +0 -52
  115. package/lib/transaction/utxo.d.ts +0 -35
  116. package/lib/tx-helpers/index.d.ts +0 -8
  117. package/lib/tx-helpers/send-atomicals-ft.d.ts +0 -16
  118. package/lib/tx-helpers/send-atomicals-nft.d.ts +0 -14
  119. package/lib/tx-helpers/send-btc.d.ts +0 -28
  120. package/lib/tx-helpers/send-inscription.d.ts +0 -16
  121. package/lib/tx-helpers/send-inscriptions.d.ts +0 -14
  122. package/lib/tx-helpers/send-runes.d.ts +0 -19
  123. package/lib/tx-helpers/split-inscription-utxo.d.ts +0 -15
  124. package/lib/types.d.ts +0 -59
  125. package/lib/utils.d.ts +0 -23
  126. package/lib/wallet/abstract-wallet.d.ts +0 -6
  127. package/lib/wallet/estimate-wallet.d.ts +0 -23
  128. package/lib/wallet/index.d.ts +0 -3
  129. package/lib/wallet/local-wallet.d.ts +0 -23
@@ -1,8 +1,8 @@
1
1
  /*!
2
- * decimal.js v10.4.3
2
+ * decimal.js v10.5.0
3
3
  * An arbitrary-precision Decimal type for JavaScript.
4
4
  * https://github.com/MikeMcl/decimal.js
5
- * Copyright (c) 2022 Michael Mclaughlin <M8ch88l@gmail.com>
5
+ * Copyright (c) 2025 Michael Mclaughlin <M8ch88l@gmail.com>
6
6
  * MIT Licence
7
7
  */
8
8
 
@@ -20,6 +20,8 @@
20
20
  * @license MIT
21
21
  */
22
22
 
23
+ /*! For license information please see index.js.LICENSE.txt */
24
+
23
25
  /*! https://mths.be/punycode v1.4.1 by @mathias */
24
26
 
25
27
  /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
@@ -28,8 +30,6 @@
28
30
 
29
31
  /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
30
32
 
31
- /*! noble-secp256k1 - MIT License (c) 2019 Paul Miller (paulmillr.com) */
32
-
33
33
  /*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
34
34
 
35
35
  /**
@@ -1,76 +1,48 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.scriptPkToAddress = exports.getAddressType = exports.decodeAddress = exports.isValidAddress = exports.addressToScriptPk = exports.publicKeyToScriptPk = exports.publicKeyToAddress = exports.publicKeyToPayment = void 0;
27
- const network_1 = require("../network");
28
- const types_1 = require("../types");
29
- const bitcoin = __importStar(require("bitcoinjs-lib"));
30
- const bitcoinjs_lib_1 = require("bitcoinjs-lib");
1
+ import * as bitcoin from '@btc-vision/bitcoin';
2
+ import { payments } from '@btc-vision/bitcoin';
3
+ import { NetworkType, toPsbtNetwork } from '../network';
4
+ import { AddressType } from '../types';
31
5
  /**
32
6
  * Convert public key to bitcoin payment object.
33
7
  */
34
- function publicKeyToPayment(publicKey, type, networkType) {
35
- const network = (0, network_1.toPsbtNetwork)(networkType);
8
+ export function publicKeyToPayment(publicKey, type, networkType) {
9
+ const network = toPsbtNetwork(networkType);
36
10
  if (!publicKey)
37
11
  return null;
38
12
  const pubkey = Buffer.from(publicKey, 'hex');
39
- if (type === types_1.AddressType.P2PKH) {
40
- return bitcoinjs_lib_1.payments.p2pkh({
13
+ if (type === AddressType.P2PKH) {
14
+ return payments.p2pkh({
41
15
  pubkey,
42
16
  network
43
17
  });
44
18
  }
45
- else if (type === types_1.AddressType.P2WPKH || type === types_1.AddressType.M44_P2WPKH) {
46
- return bitcoinjs_lib_1.payments.p2wpkh({
19
+ else if (type === AddressType.P2WPKH || type === AddressType.M44_P2WPKH) {
20
+ return payments.p2wpkh({
47
21
  pubkey,
48
22
  network
49
23
  });
50
24
  }
51
- else if (type === types_1.AddressType.P2TR || type === types_1.AddressType.M44_P2TR) {
52
- return bitcoinjs_lib_1.payments.p2tr({
25
+ else if (type === AddressType.P2TR || type === AddressType.M44_P2TR) {
26
+ return payments.p2tr({
53
27
  internalPubkey: pubkey.slice(1, 33),
54
28
  network
55
29
  });
56
30
  }
57
- else if (type === types_1.AddressType.P2SH_P2WPKH) {
58
- const data = bitcoinjs_lib_1.payments.p2wpkh({
31
+ else if (type === AddressType.P2SH_P2WPKH) {
32
+ const data = payments.p2wpkh({
59
33
  pubkey,
60
34
  network
61
35
  });
62
- return bitcoinjs_lib_1.payments.p2sh({
63
- pubkey,
36
+ return payments.p2sh({
64
37
  network,
65
38
  redeem: data
66
39
  });
67
40
  }
68
41
  }
69
- exports.publicKeyToPayment = publicKeyToPayment;
70
42
  /**
71
43
  * Convert public key to bitcoin address.
72
44
  */
73
- function publicKeyToAddress(publicKey, type, networkType) {
45
+ export function publicKeyToAddress(publicKey, type, networkType) {
74
46
  const payment = publicKeyToPayment(publicKey, type, networkType);
75
47
  if (payment && payment.address) {
76
48
  return payment.address;
@@ -79,30 +51,27 @@ function publicKeyToAddress(publicKey, type, networkType) {
79
51
  return '';
80
52
  }
81
53
  }
82
- exports.publicKeyToAddress = publicKeyToAddress;
83
54
  /**
84
55
  * Convert public key to bitcoin scriptPk.
85
56
  */
86
- function publicKeyToScriptPk(publicKey, type, networkType) {
57
+ export function publicKeyToScriptPk(publicKey, type, networkType) {
87
58
  const payment = publicKeyToPayment(publicKey, type, networkType);
88
- return payment.output.toString('hex');
59
+ return payment?.output?.toString('hex');
89
60
  }
90
- exports.publicKeyToScriptPk = publicKeyToScriptPk;
91
61
  /**
92
62
  * Convert bitcoin address to scriptPk.
93
63
  */
94
- function addressToScriptPk(address, networkType) {
95
- const network = (0, network_1.toPsbtNetwork)(networkType);
64
+ export function addressToScriptPk(address, networkType) {
65
+ const network = toPsbtNetwork(networkType);
96
66
  return bitcoin.address.toOutputScript(address, network);
97
67
  }
98
- exports.addressToScriptPk = addressToScriptPk;
99
68
  /**
100
69
  * Check if the address is valid.
101
70
  */
102
- function isValidAddress(address, networkType = network_1.NetworkType.MAINNET) {
71
+ export function isValidAddress(address, networkType = NetworkType.MAINNET) {
103
72
  let error;
104
73
  try {
105
- bitcoin.address.toOutputScript(address, (0, network_1.toPsbtNetwork)(networkType));
74
+ bitcoin.address.toOutputScript(address, toPsbtNetwork(networkType));
106
75
  }
107
76
  catch (e) {
108
77
  error = e;
@@ -114,38 +83,37 @@ function isValidAddress(address, networkType = network_1.NetworkType.MAINNET) {
114
83
  return true;
115
84
  }
116
85
  }
117
- exports.isValidAddress = isValidAddress;
118
- function decodeAddress(address) {
86
+ export function decodeAddress(address) {
119
87
  const mainnet = bitcoin.networks.bitcoin;
120
88
  const testnet = bitcoin.networks.testnet;
121
89
  const regtest = bitcoin.networks.regtest;
122
90
  let decodeBase58;
123
91
  let decodeBech32;
124
- let networkType;
125
- let addressType;
92
+ let networkType = NetworkType.MAINNET;
93
+ let addressType = AddressType.UNKNOWN;
126
94
  if (address.startsWith('bc1') || address.startsWith('tb1') || address.startsWith('bcrt1')) {
127
95
  try {
128
96
  decodeBech32 = bitcoin.address.fromBech32(address);
129
97
  if (decodeBech32.prefix === mainnet.bech32) {
130
- networkType = network_1.NetworkType.MAINNET;
98
+ networkType = NetworkType.MAINNET;
131
99
  }
132
100
  else if (decodeBech32.prefix === testnet.bech32) {
133
- networkType = network_1.NetworkType.TESTNET;
101
+ networkType = NetworkType.TESTNET;
134
102
  }
135
103
  else if (decodeBech32.prefix === regtest.bech32) {
136
- networkType = network_1.NetworkType.REGTEST;
104
+ networkType = NetworkType.REGTEST;
137
105
  }
138
106
  if (decodeBech32.version === 0) {
139
107
  if (decodeBech32.data.length === 20) {
140
- addressType = types_1.AddressType.P2WPKH;
108
+ addressType = AddressType.P2WPKH;
141
109
  }
142
110
  else if (decodeBech32.data.length === 32) {
143
- addressType = types_1.AddressType.P2WSH;
111
+ addressType = AddressType.P2WSH;
144
112
  }
145
113
  }
146
114
  else if (decodeBech32.version === 1) {
147
115
  if (decodeBech32.data.length === 32) {
148
- addressType = types_1.AddressType.P2TR;
116
+ addressType = AddressType.P2TR;
149
117
  }
150
118
  }
151
119
  return {
@@ -160,30 +128,30 @@ function decodeAddress(address) {
160
128
  try {
161
129
  decodeBase58 = bitcoin.address.fromBase58Check(address);
162
130
  if (decodeBase58.version === mainnet.pubKeyHash) {
163
- networkType = network_1.NetworkType.MAINNET;
164
- addressType = types_1.AddressType.P2PKH;
131
+ networkType = NetworkType.MAINNET;
132
+ addressType = AddressType.P2PKH;
165
133
  }
166
134
  else if (decodeBase58.version === testnet.pubKeyHash) {
167
- networkType = network_1.NetworkType.TESTNET;
168
- addressType = types_1.AddressType.P2PKH;
135
+ networkType = NetworkType.TESTNET;
136
+ addressType = AddressType.P2PKH;
169
137
  }
170
138
  else if (decodeBase58.version === regtest.pubKeyHash) {
171
139
  // do not work
172
- networkType = network_1.NetworkType.REGTEST;
173
- addressType = types_1.AddressType.P2PKH;
140
+ networkType = NetworkType.REGTEST;
141
+ addressType = AddressType.P2PKH;
174
142
  }
175
143
  else if (decodeBase58.version === mainnet.scriptHash) {
176
- networkType = network_1.NetworkType.MAINNET;
177
- addressType = types_1.AddressType.P2SH_P2WPKH;
144
+ networkType = NetworkType.MAINNET;
145
+ addressType = AddressType.P2SH_P2WPKH;
178
146
  }
179
147
  else if (decodeBase58.version === testnet.scriptHash) {
180
- networkType = network_1.NetworkType.TESTNET;
181
- addressType = types_1.AddressType.P2SH_P2WPKH;
148
+ networkType = NetworkType.TESTNET;
149
+ addressType = AddressType.P2SH_P2WPKH;
182
150
  }
183
151
  else if (decodeBase58.version === regtest.scriptHash) {
184
152
  // do not work
185
- networkType = network_1.NetworkType.REGTEST;
186
- addressType = types_1.AddressType.P2SH_P2WPKH;
153
+ networkType = NetworkType.REGTEST;
154
+ addressType = AddressType.P2SH_P2WPKH;
187
155
  }
188
156
  return {
189
157
  networkType,
@@ -194,17 +162,16 @@ function decodeAddress(address) {
194
162
  catch (e) { }
195
163
  }
196
164
  return {
197
- networkType: network_1.NetworkType.MAINNET,
198
- addressType: types_1.AddressType.UNKNOWN,
165
+ networkType: NetworkType.MAINNET,
166
+ addressType: AddressType.UNKNOWN,
199
167
  dust: 546
200
168
  };
201
169
  }
202
- exports.decodeAddress = decodeAddress;
203
170
  function getAddressTypeDust(addressType) {
204
- if (addressType === types_1.AddressType.P2WPKH || addressType === types_1.AddressType.M44_P2WPKH) {
171
+ if (addressType === AddressType.P2WPKH || addressType === AddressType.M44_P2WPKH) {
205
172
  return 294;
206
173
  }
207
- else if (addressType === types_1.AddressType.P2TR || addressType === types_1.AddressType.M44_P2TR) {
174
+ else if (addressType === AddressType.P2TR || addressType === AddressType.M44_P2TR) {
208
175
  return 330;
209
176
  }
210
177
  else {
@@ -215,15 +182,14 @@ function getAddressTypeDust(addressType) {
215
182
  * Get address type.
216
183
  */
217
184
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
218
- function getAddressType(address, networkType = network_1.NetworkType.MAINNET) {
185
+ export function getAddressType(address, networkType = NetworkType.MAINNET) {
219
186
  return decodeAddress(address).addressType;
220
187
  }
221
- exports.getAddressType = getAddressType;
222
188
  /**
223
189
  * Convert scriptPk to address.
224
190
  */
225
- function scriptPkToAddress(scriptPk, networkType = network_1.NetworkType.MAINNET) {
226
- const network = (0, network_1.toPsbtNetwork)(networkType);
191
+ export function scriptPkToAddress(scriptPk, networkType = NetworkType.MAINNET) {
192
+ const network = toPsbtNetwork(networkType);
227
193
  try {
228
194
  const address = bitcoin.address.fromOutputScript(typeof scriptPk === 'string' ? Buffer.from(scriptPk, 'hex') : scriptPk, network);
229
195
  return address;
@@ -232,4 +198,3 @@ function scriptPkToAddress(scriptPk, networkType = network_1.NetworkType.MAINNET
232
198
  return '';
233
199
  }
234
200
  }
235
- exports.scriptPkToAddress = scriptPkToAddress;
@@ -1,37 +1,7 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.bitcoin = exports.ecc = exports.ECPair = void 0;
30
- const ecpair_1 = __importDefault(require("ecpair"));
31
- const ecc = __importStar(require("@bitcoinerlab/secp256k1"));
32
- exports.ecc = ecc;
33
- const bitcoin = __importStar(require("bitcoinjs-lib"));
34
- exports.bitcoin = bitcoin;
35
- const bitcoinjs_lib_1 = require("bitcoinjs-lib");
36
- (0, bitcoinjs_lib_1.initEccLib)(ecc);
37
- exports.ECPair = (0, ecpair_1.default)(ecc);
1
+ import ECPairFactory from 'ecpair';
2
+ import * as ecc from '@bitcoinerlab/secp256k1';
3
+ import * as bitcoin from '@btc-vision/bitcoin';
4
+ import { initEccLib } from '@btc-vision/bitcoin';
5
+ initEccLib(ecc);
6
+ export const ECPair = ECPairFactory(ecc);
7
+ export { ecc, bitcoin };
package/lib/constants.js CHANGED
@@ -1,5 +1,2 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UTXO_DUST = void 0;
4
1
  // Default UTXO_DUST, this is usually sufficient, but for more precise cases, please use the getAddressUtxoDust method to obtain
5
- exports.UTXO_DUST = 546;
2
+ export const UTXO_DUST = 546;
package/lib/error.js CHANGED
@@ -1,7 +1,4 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WalletUtilsError = exports.ErrorMessages = exports.ErrorCodes = void 0;
4
- var ErrorCodes;
1
+ export var ErrorCodes;
5
2
  (function (ErrorCodes) {
6
3
  ErrorCodes[ErrorCodes["UNKNOWN"] = -1] = "UNKNOWN";
7
4
  ErrorCodes[ErrorCodes["INSUFFICIENT_BTC_UTXO"] = -2] = "INSUFFICIENT_BTC_UTXO";
@@ -9,8 +6,8 @@ var ErrorCodes;
9
6
  ErrorCodes[ErrorCodes["NOT_SAFE_UTXOS"] = -4] = "NOT_SAFE_UTXOS";
10
7
  ErrorCodes[ErrorCodes["ASSET_MAYBE_LOST"] = -5] = "ASSET_MAYBE_LOST";
11
8
  ErrorCodes[ErrorCodes["ONLY_ONE_ARC20_CAN_BE_SENT"] = -6] = "ONLY_ONE_ARC20_CAN_BE_SENT";
12
- })(ErrorCodes = exports.ErrorCodes || (exports.ErrorCodes = {}));
13
- exports.ErrorMessages = {
9
+ })(ErrorCodes || (ErrorCodes = {}));
10
+ export const ErrorMessages = {
14
11
  [ErrorCodes.UNKNOWN]: 'Unknown error',
15
12
  [ErrorCodes.INSUFFICIENT_BTC_UTXO]: 'Insufficient btc utxo',
16
13
  [ErrorCodes.INSUFFICIENT_ASSET_UTXO]: 'Insufficient asset utxo',
@@ -18,12 +15,11 @@ exports.ErrorMessages = {
18
15
  [ErrorCodes.ASSET_MAYBE_LOST]: 'Asset maybe lost',
19
16
  [ErrorCodes.ONLY_ONE_ARC20_CAN_BE_SENT]: 'Only one arc20 can be sent'
20
17
  };
21
- class WalletUtilsError extends Error {
22
- constructor(code, message = exports.ErrorMessages[code] || 'Unknown error') {
18
+ export class WalletUtilsError extends Error {
19
+ code = ErrorCodes.UNKNOWN;
20
+ constructor(code, message = ErrorMessages[code] || 'Unknown error') {
23
21
  super(message);
24
- this.code = ErrorCodes.UNKNOWN;
25
22
  this.code = code;
26
23
  Object.setPrototypeOf(this, WalletUtilsError.prototype);
27
24
  }
28
25
  }
29
- exports.WalletUtilsError = WalletUtilsError;
package/lib/index.js CHANGED
@@ -1,50 +1,21 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.wallet = exports.utils = exports.txHelpers = exports.transaction = exports.message = exports.keyring = exports.core = exports.address = void 0;
30
1
  Object.defineProperty(global, '_bitcore', {
31
2
  get() {
32
3
  return undefined;
33
4
  },
34
5
  set() { }
35
6
  });
36
- exports.address = __importStar(require("./address"));
37
- exports.core = __importStar(require("./bitcoin-core"));
38
- __exportStar(require("./constants"), exports);
39
- exports.keyring = __importStar(require("./keyring"));
40
- exports.message = __importStar(require("./message"));
41
- exports.transaction = __importStar(require("./transaction"));
42
- exports.txHelpers = __importStar(require("./tx-helpers"));
43
- __exportStar(require("./types"), exports);
44
- exports.utils = __importStar(require("./utils"));
45
- exports.wallet = __importStar(require("./wallet"));
7
+ export * as address from './address';
8
+ export * as core from './bitcoin-core';
9
+ export * from './constants';
10
+ export * as keyring from './keyring';
11
+ export * as message from './message';
12
+ export * as transaction from './transaction';
13
+ export * as txHelpers from './tx-helpers';
14
+ export * from './types';
15
+ export * as utils from './utils';
16
+ export * as wallet from './wallet';
46
17
  // Export with types.
47
- __exportStar(require("./keyring/interfaces/SimpleKeyringOptions"), exports);
48
- __exportStar(require("./keyring/hd-keyring"), exports);
49
- __exportStar(require("./keyring/keystone-keyring"), exports);
50
- __exportStar(require("./keyring/simple-keyring"), exports);
18
+ export * from './keyring/interfaces/SimpleKeyringOptions';
19
+ export * from './keyring/hd-keyring';
20
+ export * from './keyring/keystone-keyring';
21
+ export * from './keyring/simple-keyring';
@@ -1,62 +1,27 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
- var __importDefault = (this && this.__importDefault) || function (mod) {
35
- return (mod && mod.__esModule) ? mod : { "default": mod };
36
- };
37
- Object.defineProperty(exports, "__esModule", { value: true });
38
- exports.HdKeyring = void 0;
39
- const bip39 = __importStar(require("bip39"));
40
- const hdkey_1 = __importDefault(require("hdkey"));
41
- const bitcoin_core_1 = require("../bitcoin-core");
42
- const SimpleKeyringOptions_1 = require("./interfaces/SimpleKeyringOptions");
43
- const bitcoinjs_lib_1 = require("bitcoinjs-lib");
1
+ import { networks } from '@btc-vision/bitcoin';
2
+ import * as bip39 from 'bip39';
3
+ import hdkey from 'hdkey';
4
+ import { ECPair } from '../bitcoin-core';
5
+ import { IKeyringBase } from './interfaces/SimpleKeyringOptions';
44
6
  const hdPathString = "m/44'/0'/0'/0";
45
7
  const type = 'HD Key Tree';
46
- class HdKeyring extends SimpleKeyringOptions_1.IKeyringBase {
8
+ export class HdKeyring extends IKeyringBase {
9
+ static type = type;
10
+ type = type;
11
+ mnemonic = null;
12
+ xpriv = null;
13
+ passphrase = null;
14
+ hdPath = hdPathString;
15
+ root = null;
16
+ hdWallet;
17
+ wallets = [];
18
+ activeIndexes = [];
19
+ page = 0;
20
+ perPage = 5;
21
+ _index2wallet = {};
47
22
  /* PUBLIC METHODS */
48
23
  constructor(opts) {
49
- super((opts === null || opts === void 0 ? void 0 : opts.network) || bitcoinjs_lib_1.networks.bitcoin);
50
- this.type = type;
51
- this.mnemonic = null;
52
- this.xpriv = null;
53
- this.hdPath = hdPathString;
54
- this.root = null;
55
- this.wallets = [];
56
- this.activeIndexes = [];
57
- this.page = 0;
58
- this.perPage = 5;
59
- this._index2wallet = {};
24
+ super(opts?.network || networks.bitcoin);
60
25
  if (opts) {
61
26
  this.deserialize(opts);
62
27
  }
@@ -100,7 +65,7 @@ class HdKeyring extends SimpleKeyringOptions_1.IKeyringBase {
100
65
  this.xpriv = xpriv;
101
66
  this._index2wallet = {};
102
67
  // @ts-ignore
103
- this.hdWallet = hdkey_1.default.fromJSON({ xpriv });
68
+ this.hdWallet = hdkey.fromJSON({ xpriv });
104
69
  this.root = this.hdWallet;
105
70
  }
106
71
  initFromMnemonic(mnemonic) {
@@ -110,7 +75,7 @@ class HdKeyring extends SimpleKeyringOptions_1.IKeyringBase {
110
75
  this.mnemonic = mnemonic;
111
76
  this._index2wallet = {};
112
77
  const seed = bip39.mnemonicToSeedSync(mnemonic, this.passphrase);
113
- this.hdWallet = hdkey_1.default.fromMasterSeed(seed);
78
+ this.hdWallet = hdkey.fromMasterSeed(seed);
114
79
  this.root = this.hdWallet.derive(this.hdPath);
115
80
  }
116
81
  changeHdPath(hdPath) {
@@ -131,7 +96,7 @@ class HdKeyring extends SimpleKeyringOptions_1.IKeyringBase {
131
96
  }
132
97
  const root = this.hdWallet.derive(hdPath);
133
98
  const child = root.deriveChild(index);
134
- const ecpair = bitcoin_core_1.ECPair.fromPrivateKey(child.privateKey, {
99
+ const ecpair = ECPair.fromPrivateKey(child.privateKey, {
135
100
  network: this.network
136
101
  });
137
102
  return ecpair.publicKey.toString('hex');
@@ -189,24 +154,22 @@ class HdKeyring extends SimpleKeyringOptions_1.IKeyringBase {
189
154
  }
190
155
  return accounts;
191
156
  }
192
- __getPage(increment) {
193
- return __awaiter(this, void 0, void 0, function* () {
194
- this.page += increment;
195
- if (!this.page || this.page <= 0) {
196
- this.page = 1;
197
- }
198
- const from = (this.page - 1) * this.perPage;
199
- const to = from + this.perPage;
200
- const accounts = [];
201
- for (let i = from; i < to; i++) {
202
- const [address] = this._addressFromIndex(i);
203
- accounts.push({
204
- address,
205
- index: i + 1
206
- });
207
- }
208
- return accounts;
209
- });
157
+ async __getPage(increment) {
158
+ this.page += increment;
159
+ if (!this.page || this.page <= 0) {
160
+ this.page = 1;
161
+ }
162
+ const from = (this.page - 1) * this.perPage;
163
+ const to = from + this.perPage;
164
+ const accounts = [];
165
+ for (let i = from; i < to; i++) {
166
+ const [address] = this._addressFromIndex(i);
167
+ accounts.push({
168
+ address,
169
+ index: i + 1
170
+ });
171
+ }
172
+ return accounts;
210
173
  }
211
174
  getAccounts() {
212
175
  return this.wallets.map((w) => {
@@ -225,7 +188,7 @@ class HdKeyring extends SimpleKeyringOptions_1.IKeyringBase {
225
188
  if (!this._index2wallet[i]) {
226
189
  const child = this.root.deriveChild(i);
227
190
  // @ts-ignore
228
- const ecpair = bitcoin_core_1.ECPair.fromPrivateKey(child.privateKey || Buffer.from(child.toString(), 'hex'), {
191
+ const ecpair = ECPair.fromPrivateKey(child.privateKey || Buffer.from(child.toString(), 'hex'), {
229
192
  network: this.network
230
193
  });
231
194
  const address = ecpair.publicKey.toString('hex');
@@ -234,5 +197,3 @@ class HdKeyring extends SimpleKeyringOptions_1.IKeyringBase {
234
197
  return this._index2wallet[i];
235
198
  }
236
199
  }
237
- exports.HdKeyring = HdKeyring;
238
- HdKeyring.type = type;
@@ -1,20 +1,4 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./hd-keyring"), exports);
18
- __exportStar(require("./keystone-keyring"), exports);
19
- __exportStar(require("./simple-keyring"), exports);
20
- __exportStar(require("./interfaces/SimpleKeyringOptions"), exports);
1
+ export * from './hd-keyring';
2
+ export * from './keystone-keyring';
3
+ export * from './simple-keyring';
4
+ export * from './interfaces/SimpleKeyringOptions';