@btc-vision/wallet-sdk 1.0.0

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 (131) hide show
  1. package/LICENSE +15 -0
  2. package/README.md +24 -0
  3. package/es/bundle.js +2 -0
  4. package/es/bundle.js.LICENSE.txt +48 -0
  5. package/lib/address/index.d.ts +37 -0
  6. package/lib/address/index.js +235 -0
  7. package/lib/bitcoin-core.d.ts +5 -0
  8. package/lib/bitcoin-core.js +37 -0
  9. package/lib/constants.d.ts +1 -0
  10. package/lib/constants.js +5 -0
  11. package/lib/error.d.ts +20 -0
  12. package/lib/error.js +29 -0
  13. package/lib/index.d.ts +14 -0
  14. package/lib/index.js +50 -0
  15. package/lib/keyring/hd-keyring.d.ts +50 -0
  16. package/lib/keyring/hd-keyring.js +238 -0
  17. package/lib/keyring/index.d.ts +4 -0
  18. package/lib/keyring/index.js +20 -0
  19. package/lib/keyring/interfaces/SimpleKeyringOptions.d.ts +53 -0
  20. package/lib/keyring/interfaces/SimpleKeyringOptions.js +85 -0
  21. package/lib/keyring/keystone-keyring.d.ts +82 -0
  22. package/lib/keyring/keystone-keyring.js +377 -0
  23. package/lib/keyring/simple-keyring.d.ts +11 -0
  24. package/lib/keyring/simple-keyring.js +66 -0
  25. package/lib/message/bip322-simple.d.ts +19 -0
  26. package/lib/message/bip322-simple.js +182 -0
  27. package/lib/message/deterministic-ecdsa.d.ts +2 -0
  28. package/lib/message/deterministic-ecdsa.js +83 -0
  29. package/lib/message/ecdsa.d.ts +3 -0
  30. package/lib/message/ecdsa.js +32 -0
  31. package/lib/message/index.d.ts +3 -0
  32. package/lib/message/index.js +19 -0
  33. package/lib/network/index.d.ts +14 -0
  34. package/lib/network/index.js +40 -0
  35. package/lib/runes/index.d.ts +1 -0
  36. package/lib/runes/index.js +17 -0
  37. package/lib/runes/rund_id.d.ts +11 -0
  38. package/lib/runes/rund_id.js +30 -0
  39. package/lib/runes/varint.d.ts +15 -0
  40. package/lib/runes/varint.js +45 -0
  41. package/lib/src/address/index.d.ts +37 -0
  42. package/lib/src/bitcoin-core.d.ts +5 -0
  43. package/lib/src/constants.d.ts +1 -0
  44. package/lib/src/error.d.ts +20 -0
  45. package/lib/src/index.d.ts +14 -0
  46. package/lib/src/keyring/hd-keyring.d.ts +50 -0
  47. package/lib/src/keyring/index.d.ts +4 -0
  48. package/lib/src/keyring/interfaces/SimpleKeyringOptions.d.ts +53 -0
  49. package/lib/src/keyring/keystone-keyring.d.ts +82 -0
  50. package/lib/src/keyring/simple-keyring.d.ts +11 -0
  51. package/lib/src/message/bip322-simple.d.ts +19 -0
  52. package/lib/src/message/deterministic-ecdsa.d.ts +2 -0
  53. package/lib/src/message/ecdsa.d.ts +3 -0
  54. package/lib/src/message/index.d.ts +3 -0
  55. package/lib/src/network/index.d.ts +14 -0
  56. package/lib/src/runes/index.d.ts +1 -0
  57. package/lib/src/runes/rund_id.d.ts +11 -0
  58. package/lib/src/runes/varint.d.ts +15 -0
  59. package/lib/src/transaction/index.d.ts +3 -0
  60. package/lib/src/transaction/inscription-utxo.d.ts +33 -0
  61. package/lib/src/transaction/transaction.d.ts +52 -0
  62. package/lib/src/transaction/utxo.d.ts +35 -0
  63. package/lib/src/tx-helpers/index.d.ts +8 -0
  64. package/lib/src/tx-helpers/send-atomicals-ft.d.ts +16 -0
  65. package/lib/src/tx-helpers/send-atomicals-nft.d.ts +14 -0
  66. package/lib/src/tx-helpers/send-btc.d.ts +28 -0
  67. package/lib/src/tx-helpers/send-inscription.d.ts +16 -0
  68. package/lib/src/tx-helpers/send-inscriptions.d.ts +14 -0
  69. package/lib/src/tx-helpers/send-runes.d.ts +19 -0
  70. package/lib/src/tx-helpers/split-inscription-utxo.d.ts +15 -0
  71. package/lib/src/types.d.ts +59 -0
  72. package/lib/src/utils.d.ts +23 -0
  73. package/lib/src/wallet/abstract-wallet.d.ts +6 -0
  74. package/lib/src/wallet/estimate-wallet.d.ts +23 -0
  75. package/lib/src/wallet/index.d.ts +3 -0
  76. package/lib/src/wallet/local-wallet.d.ts +23 -0
  77. package/lib/test/address/address.test.d.ts +1 -0
  78. package/lib/test/keyring/hd-keyring.test.d.ts +1 -0
  79. package/lib/test/keyring/keystone-keyring.test.d.ts +1 -0
  80. package/lib/test/keyring/simple-keyring.test.d.ts +1 -0
  81. package/lib/test/message/message.test.d.ts +1 -0
  82. package/lib/test/runes/varint.test.d.ts +1 -0
  83. package/lib/test/transaction/transaction.test.d.ts +1 -0
  84. package/lib/test/transaction/utxo.test.d.ts +1 -0
  85. package/lib/test/tx-helpers/send-atomicals-ft.test.d.ts +1 -0
  86. package/lib/test/tx-helpers/send-atomicals-nft.test.d.ts +1 -0
  87. package/lib/test/tx-helpers/send-btc.test.d.ts +1 -0
  88. package/lib/test/tx-helpers/send-inscription.test.d.ts +1 -0
  89. package/lib/test/tx-helpers/send-inscriptions.test.d.ts +1 -0
  90. package/lib/test/tx-helpers/send-runes.test.d.ts +1 -0
  91. package/lib/test/tx-helpers/split-inscription-utxo.test.d.ts +1 -0
  92. package/lib/test/tx-helpers/utils.d.ts +217 -0
  93. package/lib/test/utils.d.ts +4 -0
  94. package/lib/test/wallet/local-wallet.test.d.ts +1 -0
  95. package/lib/transaction/index.d.ts +3 -0
  96. package/lib/transaction/index.js +19 -0
  97. package/lib/transaction/inscription-utxo.d.ts +33 -0
  98. package/lib/transaction/inscription-utxo.js +120 -0
  99. package/lib/transaction/transaction.d.ts +52 -0
  100. package/lib/transaction/transaction.js +358 -0
  101. package/lib/transaction/utxo.d.ts +35 -0
  102. package/lib/transaction/utxo.js +107 -0
  103. package/lib/tx-helpers/index.d.ts +8 -0
  104. package/lib/tx-helpers/index.js +18 -0
  105. package/lib/tx-helpers/send-atomicals-ft.d.ts +16 -0
  106. package/lib/tx-helpers/send-atomicals-ft.js +66 -0
  107. package/lib/tx-helpers/send-atomicals-nft.d.ts +14 -0
  108. package/lib/tx-helpers/send-atomicals-nft.js +45 -0
  109. package/lib/tx-helpers/send-btc.d.ts +28 -0
  110. package/lib/tx-helpers/send-btc.js +78 -0
  111. package/lib/tx-helpers/send-inscription.d.ts +16 -0
  112. package/lib/tx-helpers/send-inscription.js +49 -0
  113. package/lib/tx-helpers/send-inscriptions.d.ts +14 -0
  114. package/lib/tx-helpers/send-inscriptions.js +45 -0
  115. package/lib/tx-helpers/send-runes.d.ts +19 -0
  116. package/lib/tx-helpers/send-runes.js +101 -0
  117. package/lib/tx-helpers/split-inscription-utxo.d.ts +15 -0
  118. package/lib/tx-helpers/split-inscription-utxo.js +58 -0
  119. package/lib/types.d.ts +59 -0
  120. package/lib/types.js +15 -0
  121. package/lib/utils.d.ts +23 -0
  122. package/lib/utils.js +71 -0
  123. package/lib/wallet/abstract-wallet.d.ts +6 -0
  124. package/lib/wallet/abstract-wallet.js +2 -0
  125. package/lib/wallet/estimate-wallet.d.ts +23 -0
  126. package/lib/wallet/estimate-wallet.js +174 -0
  127. package/lib/wallet/index.d.ts +3 -0
  128. package/lib/wallet/index.js +19 -0
  129. package/lib/wallet/local-wallet.d.ts +23 -0
  130. package/lib/wallet/local-wallet.js +183 -0
  131. package/package.json +97 -0
@@ -0,0 +1,48 @@
1
+ /*!
2
+ * decimal.js v10.4.3
3
+ * An arbitrary-precision Decimal type for JavaScript.
4
+ * https://github.com/MikeMcl/decimal.js
5
+ * Copyright (c) 2022 Michael Mclaughlin <M8ch88l@gmail.com>
6
+ * MIT Licence
7
+ */
8
+
9
+ /*!
10
+ * The buffer module from node.js, for the browser.
11
+ *
12
+ * @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
13
+ * @license MIT
14
+ */
15
+
16
+ /*!
17
+ * The buffer module from node.js, for the browser.
18
+ *
19
+ * @author Feross Aboukhadijeh <https://feross.org>
20
+ * @license MIT
21
+ */
22
+
23
+ /*! https://mths.be/punycode v1.4.1 by @mathias */
24
+
25
+ /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
26
+
27
+ /*! noble-curves - MIT License (c) 2022 Paul Miller (paulmillr.com) */
28
+
29
+ /*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) */
30
+
31
+ /*! noble-secp256k1 - MIT License (c) 2019 Paul Miller (paulmillr.com) */
32
+
33
+ /*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
34
+
35
+ /**
36
+ * @license
37
+ * Lodash <https://lodash.com/>
38
+ * Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
39
+ * Released under MIT license <https://lodash.com/license>
40
+ * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
41
+ * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
42
+ */
43
+
44
+ //! The internal pubkey (x-only, so no Y coordinate parity).
45
+
46
+ //! The output pubkey (taken from the scriptPubKey).
47
+
48
+ //!< Taproot only; implied when sighash byte is missing, and equivalent to SIGHASH_ALL
@@ -0,0 +1,37 @@
1
+ /// <reference types="node" />
2
+ import { NetworkType } from '../network';
3
+ import { AddressType } from '../types';
4
+ import * as bitcoin from 'bitcoinjs-lib';
5
+ /**
6
+ * Convert public key to bitcoin payment object.
7
+ */
8
+ export declare function publicKeyToPayment(publicKey: string, type: AddressType, networkType: NetworkType): bitcoin.payments.Payment;
9
+ /**
10
+ * Convert public key to bitcoin address.
11
+ */
12
+ export declare function publicKeyToAddress(publicKey: string, type: AddressType, networkType: NetworkType): string;
13
+ /**
14
+ * Convert public key to bitcoin scriptPk.
15
+ */
16
+ export declare function publicKeyToScriptPk(publicKey: string, type: AddressType, networkType: NetworkType): string;
17
+ /**
18
+ * Convert bitcoin address to scriptPk.
19
+ */
20
+ export declare function addressToScriptPk(address: string, networkType: NetworkType): Buffer;
21
+ /**
22
+ * Check if the address is valid.
23
+ */
24
+ export declare function isValidAddress(address: string, networkType?: NetworkType): boolean;
25
+ export declare function decodeAddress(address: string): {
26
+ networkType: NetworkType;
27
+ addressType: AddressType;
28
+ dust: number;
29
+ };
30
+ /**
31
+ * Get address type.
32
+ */
33
+ export declare function getAddressType(address: string, networkType?: NetworkType): AddressType;
34
+ /**
35
+ * Convert scriptPk to address.
36
+ */
37
+ export declare function scriptPkToAddress(scriptPk: string | Buffer, networkType?: NetworkType): string;
@@ -0,0 +1,235 @@
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");
31
+ /**
32
+ * Convert public key to bitcoin payment object.
33
+ */
34
+ function publicKeyToPayment(publicKey, type, networkType) {
35
+ const network = (0, network_1.toPsbtNetwork)(networkType);
36
+ if (!publicKey)
37
+ return null;
38
+ const pubkey = Buffer.from(publicKey, 'hex');
39
+ if (type === types_1.AddressType.P2PKH) {
40
+ return bitcoinjs_lib_1.payments.p2pkh({
41
+ pubkey,
42
+ network
43
+ });
44
+ }
45
+ else if (type === types_1.AddressType.P2WPKH || type === types_1.AddressType.M44_P2WPKH) {
46
+ return bitcoinjs_lib_1.payments.p2wpkh({
47
+ pubkey,
48
+ network
49
+ });
50
+ }
51
+ else if (type === types_1.AddressType.P2TR || type === types_1.AddressType.M44_P2TR) {
52
+ return bitcoinjs_lib_1.payments.p2tr({
53
+ internalPubkey: pubkey.slice(1, 33),
54
+ network
55
+ });
56
+ }
57
+ else if (type === types_1.AddressType.P2SH_P2WPKH) {
58
+ const data = bitcoinjs_lib_1.payments.p2wpkh({
59
+ pubkey,
60
+ network
61
+ });
62
+ return bitcoinjs_lib_1.payments.p2sh({
63
+ pubkey,
64
+ network,
65
+ redeem: data
66
+ });
67
+ }
68
+ }
69
+ exports.publicKeyToPayment = publicKeyToPayment;
70
+ /**
71
+ * Convert public key to bitcoin address.
72
+ */
73
+ function publicKeyToAddress(publicKey, type, networkType) {
74
+ const payment = publicKeyToPayment(publicKey, type, networkType);
75
+ if (payment && payment.address) {
76
+ return payment.address;
77
+ }
78
+ else {
79
+ return '';
80
+ }
81
+ }
82
+ exports.publicKeyToAddress = publicKeyToAddress;
83
+ /**
84
+ * Convert public key to bitcoin scriptPk.
85
+ */
86
+ function publicKeyToScriptPk(publicKey, type, networkType) {
87
+ const payment = publicKeyToPayment(publicKey, type, networkType);
88
+ return payment.output.toString('hex');
89
+ }
90
+ exports.publicKeyToScriptPk = publicKeyToScriptPk;
91
+ /**
92
+ * Convert bitcoin address to scriptPk.
93
+ */
94
+ function addressToScriptPk(address, networkType) {
95
+ const network = (0, network_1.toPsbtNetwork)(networkType);
96
+ return bitcoin.address.toOutputScript(address, network);
97
+ }
98
+ exports.addressToScriptPk = addressToScriptPk;
99
+ /**
100
+ * Check if the address is valid.
101
+ */
102
+ function isValidAddress(address, networkType = network_1.NetworkType.MAINNET) {
103
+ let error;
104
+ try {
105
+ bitcoin.address.toOutputScript(address, (0, network_1.toPsbtNetwork)(networkType));
106
+ }
107
+ catch (e) {
108
+ error = e;
109
+ }
110
+ if (error) {
111
+ return false;
112
+ }
113
+ else {
114
+ return true;
115
+ }
116
+ }
117
+ exports.isValidAddress = isValidAddress;
118
+ function decodeAddress(address) {
119
+ const mainnet = bitcoin.networks.bitcoin;
120
+ const testnet = bitcoin.networks.testnet;
121
+ const regtest = bitcoin.networks.regtest;
122
+ let decodeBase58;
123
+ let decodeBech32;
124
+ let networkType;
125
+ let addressType;
126
+ if (address.startsWith('bc1') || address.startsWith('tb1') || address.startsWith('bcrt1')) {
127
+ try {
128
+ decodeBech32 = bitcoin.address.fromBech32(address);
129
+ if (decodeBech32.prefix === mainnet.bech32) {
130
+ networkType = network_1.NetworkType.MAINNET;
131
+ }
132
+ else if (decodeBech32.prefix === testnet.bech32) {
133
+ networkType = network_1.NetworkType.TESTNET;
134
+ }
135
+ else if (decodeBech32.prefix === regtest.bech32) {
136
+ networkType = network_1.NetworkType.REGTEST;
137
+ }
138
+ if (decodeBech32.version === 0) {
139
+ if (decodeBech32.data.length === 20) {
140
+ addressType = types_1.AddressType.P2WPKH;
141
+ }
142
+ else if (decodeBech32.data.length === 32) {
143
+ addressType = types_1.AddressType.P2WSH;
144
+ }
145
+ }
146
+ else if (decodeBech32.version === 1) {
147
+ if (decodeBech32.data.length === 32) {
148
+ addressType = types_1.AddressType.P2TR;
149
+ }
150
+ }
151
+ return {
152
+ networkType,
153
+ addressType,
154
+ dust: getAddressTypeDust(addressType)
155
+ };
156
+ }
157
+ catch (e) { }
158
+ }
159
+ else {
160
+ try {
161
+ decodeBase58 = bitcoin.address.fromBase58Check(address);
162
+ if (decodeBase58.version === mainnet.pubKeyHash) {
163
+ networkType = network_1.NetworkType.MAINNET;
164
+ addressType = types_1.AddressType.P2PKH;
165
+ }
166
+ else if (decodeBase58.version === testnet.pubKeyHash) {
167
+ networkType = network_1.NetworkType.TESTNET;
168
+ addressType = types_1.AddressType.P2PKH;
169
+ }
170
+ else if (decodeBase58.version === regtest.pubKeyHash) {
171
+ // do not work
172
+ networkType = network_1.NetworkType.REGTEST;
173
+ addressType = types_1.AddressType.P2PKH;
174
+ }
175
+ else if (decodeBase58.version === mainnet.scriptHash) {
176
+ networkType = network_1.NetworkType.MAINNET;
177
+ addressType = types_1.AddressType.P2SH_P2WPKH;
178
+ }
179
+ else if (decodeBase58.version === testnet.scriptHash) {
180
+ networkType = network_1.NetworkType.TESTNET;
181
+ addressType = types_1.AddressType.P2SH_P2WPKH;
182
+ }
183
+ else if (decodeBase58.version === regtest.scriptHash) {
184
+ // do not work
185
+ networkType = network_1.NetworkType.REGTEST;
186
+ addressType = types_1.AddressType.P2SH_P2WPKH;
187
+ }
188
+ return {
189
+ networkType,
190
+ addressType,
191
+ dust: getAddressTypeDust(addressType)
192
+ };
193
+ }
194
+ catch (e) { }
195
+ }
196
+ return {
197
+ networkType: network_1.NetworkType.MAINNET,
198
+ addressType: types_1.AddressType.UNKNOWN,
199
+ dust: 546
200
+ };
201
+ }
202
+ exports.decodeAddress = decodeAddress;
203
+ function getAddressTypeDust(addressType) {
204
+ if (addressType === types_1.AddressType.P2WPKH || addressType === types_1.AddressType.M44_P2WPKH) {
205
+ return 294;
206
+ }
207
+ else if (addressType === types_1.AddressType.P2TR || addressType === types_1.AddressType.M44_P2TR) {
208
+ return 330;
209
+ }
210
+ else {
211
+ return 546;
212
+ }
213
+ }
214
+ /**
215
+ * Get address type.
216
+ */
217
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
218
+ function getAddressType(address, networkType = network_1.NetworkType.MAINNET) {
219
+ return decodeAddress(address).addressType;
220
+ }
221
+ exports.getAddressType = getAddressType;
222
+ /**
223
+ * Convert scriptPk to address.
224
+ */
225
+ function scriptPkToAddress(scriptPk, networkType = network_1.NetworkType.MAINNET) {
226
+ const network = (0, network_1.toPsbtNetwork)(networkType);
227
+ try {
228
+ const address = bitcoin.address.fromOutputScript(typeof scriptPk === 'string' ? Buffer.from(scriptPk, 'hex') : scriptPk, network);
229
+ return address;
230
+ }
231
+ catch (e) {
232
+ return '';
233
+ }
234
+ }
235
+ exports.scriptPkToAddress = scriptPkToAddress;
@@ -0,0 +1,5 @@
1
+ import * as ecc from '@bitcoinerlab/secp256k1';
2
+ import * as bitcoin from 'bitcoinjs-lib';
3
+ export declare const ECPair: import("ecpair").ECPairAPI;
4
+ export { ECPairInterface } from 'ecpair';
5
+ export { ecc, bitcoin };
@@ -0,0 +1,37 @@
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);
@@ -0,0 +1 @@
1
+ export declare const UTXO_DUST = 546;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UTXO_DUST = void 0;
4
+ // Default UTXO_DUST, this is usually sufficient, but for more precise cases, please use the getAddressUtxoDust method to obtain
5
+ exports.UTXO_DUST = 546;
package/lib/error.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ export declare enum ErrorCodes {
2
+ UNKNOWN = -1,
3
+ INSUFFICIENT_BTC_UTXO = -2,
4
+ INSUFFICIENT_ASSET_UTXO = -3,
5
+ NOT_SAFE_UTXOS = -4,
6
+ ASSET_MAYBE_LOST = -5,
7
+ ONLY_ONE_ARC20_CAN_BE_SENT = -6
8
+ }
9
+ export declare const ErrorMessages: {
10
+ [-1]: string;
11
+ [-2]: string;
12
+ [-3]: string;
13
+ [-4]: string;
14
+ [-5]: string;
15
+ [-6]: string;
16
+ };
17
+ export declare class WalletUtilsError extends Error {
18
+ code: ErrorCodes;
19
+ constructor(code: ErrorCodes, message?: string);
20
+ }
package/lib/error.js ADDED
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WalletUtilsError = exports.ErrorMessages = exports.ErrorCodes = void 0;
4
+ var ErrorCodes;
5
+ (function (ErrorCodes) {
6
+ ErrorCodes[ErrorCodes["UNKNOWN"] = -1] = "UNKNOWN";
7
+ ErrorCodes[ErrorCodes["INSUFFICIENT_BTC_UTXO"] = -2] = "INSUFFICIENT_BTC_UTXO";
8
+ ErrorCodes[ErrorCodes["INSUFFICIENT_ASSET_UTXO"] = -3] = "INSUFFICIENT_ASSET_UTXO";
9
+ ErrorCodes[ErrorCodes["NOT_SAFE_UTXOS"] = -4] = "NOT_SAFE_UTXOS";
10
+ ErrorCodes[ErrorCodes["ASSET_MAYBE_LOST"] = -5] = "ASSET_MAYBE_LOST";
11
+ ErrorCodes[ErrorCodes["ONLY_ONE_ARC20_CAN_BE_SENT"] = -6] = "ONLY_ONE_ARC20_CAN_BE_SENT";
12
+ })(ErrorCodes = exports.ErrorCodes || (exports.ErrorCodes = {}));
13
+ exports.ErrorMessages = {
14
+ [ErrorCodes.UNKNOWN]: 'Unknown error',
15
+ [ErrorCodes.INSUFFICIENT_BTC_UTXO]: 'Insufficient btc utxo',
16
+ [ErrorCodes.INSUFFICIENT_ASSET_UTXO]: 'Insufficient asset utxo',
17
+ [ErrorCodes.NOT_SAFE_UTXOS]: 'Not safe utxos',
18
+ [ErrorCodes.ASSET_MAYBE_LOST]: 'Asset maybe lost',
19
+ [ErrorCodes.ONLY_ONE_ARC20_CAN_BE_SENT]: 'Only one arc20 can be sent'
20
+ };
21
+ class WalletUtilsError extends Error {
22
+ constructor(code, message = exports.ErrorMessages[code] || 'Unknown error') {
23
+ super(message);
24
+ this.code = ErrorCodes.UNKNOWN;
25
+ this.code = code;
26
+ Object.setPrototypeOf(this, WalletUtilsError.prototype);
27
+ }
28
+ }
29
+ exports.WalletUtilsError = WalletUtilsError;
package/lib/index.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ export * as address from './address';
2
+ export * as core from './bitcoin-core';
3
+ export * from './constants';
4
+ export * as keyring from './keyring';
5
+ export * as message from './message';
6
+ export * as transaction from './transaction';
7
+ export * as txHelpers from './tx-helpers';
8
+ export * from './types';
9
+ export * as utils from './utils';
10
+ export * as wallet from './wallet';
11
+ export * from './keyring/interfaces/SimpleKeyringOptions';
12
+ export * from './keyring/hd-keyring';
13
+ export * from './keyring/keystone-keyring';
14
+ export * from './keyring/simple-keyring';
package/lib/index.js ADDED
@@ -0,0 +1,50 @@
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
+ Object.defineProperty(global, '_bitcore', {
31
+ get() {
32
+ return undefined;
33
+ },
34
+ set() { }
35
+ });
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"));
46
+ // 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);
@@ -0,0 +1,50 @@
1
+ import bitcore from 'bitcore-lib';
2
+ import { ECPairInterface } from '../bitcoin-core';
3
+ import { DeserializeOption, IKeyringBase } from './interfaces/SimpleKeyringOptions';
4
+ export declare class HdKeyring extends IKeyringBase<DeserializeOption> {
5
+ static type: string;
6
+ type: string;
7
+ mnemonic: string;
8
+ xpriv: string;
9
+ passphrase: string;
10
+ hdPath: string;
11
+ root: bitcore.HDPrivateKey;
12
+ hdWallet?: any;
13
+ wallets: ECPairInterface[];
14
+ activeIndexes: number[];
15
+ page: number;
16
+ perPage: number;
17
+ private _index2wallet;
18
+ constructor(opts?: DeserializeOption);
19
+ serialize(): DeserializeOption;
20
+ deserialize(_opts?: DeserializeOption): void;
21
+ initFromXpriv(xpriv: string): void;
22
+ initFromMnemonic(mnemonic: string): void;
23
+ changeHdPath(hdPath: string): void;
24
+ getAccountByHdPath(hdPath: string, index: number): string;
25
+ addAccounts(numberOfAccounts?: number): string[];
26
+ activeAccounts(indexes: number[]): string[];
27
+ getFirstPage(): Promise<{
28
+ address: string;
29
+ index: number;
30
+ }[]>;
31
+ getNextPage(): Promise<{
32
+ address: string;
33
+ index: number;
34
+ }[]>;
35
+ getPreviousPage(): Promise<{
36
+ address: string;
37
+ index: number;
38
+ }[]>;
39
+ getAddresses(start: number, end: number): {
40
+ address: string;
41
+ index: number;
42
+ }[];
43
+ __getPage(increment: number): Promise<{
44
+ address: string;
45
+ index: number;
46
+ }[]>;
47
+ getAccounts(): string[];
48
+ getIndexByAddress(address: string): number;
49
+ private _addressFromIndex;
50
+ }