@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.
- package/es/bundle.js +1 -1
- package/es/bundle.js.LICENSE.txt +4 -4
- package/lib/address/index.js +50 -85
- package/lib/bitcoin-core.js +7 -37
- package/lib/constants.js +1 -4
- package/lib/error.js +6 -10
- package/lib/index.js +14 -43
- package/lib/keyring/hd-keyring.js +40 -79
- package/lib/keyring/index.js +4 -20
- package/lib/keyring/interfaces/SimpleKeyringOptions.js +16 -31
- package/lib/keyring/keystone-keyring.js +142 -201
- package/lib/keyring/simple-keyring.js +13 -18
- package/lib/message/bip322-simple.js +31 -71
- package/lib/message/deterministic-ecdsa.js +19 -40
- package/lib/message/ecdsa.js +10 -18
- package/lib/message/index.js +3 -19
- package/lib/network/index.js +12 -17
- package/lib/runes/index.js +1 -17
- package/lib/runes/rund_id.js +8 -13
- package/lib/runes/varint.js +6 -12
- package/lib/transaction/index.js +3 -19
- package/lib/transaction/inscription-utxo.js +45 -38
- package/lib/transaction/transaction.js +134 -139
- package/lib/transaction/utxo.js +13 -18
- package/lib/tx-helpers/index.js +8 -18
- package/lib/tx-helpers/send-atomicals-ft.js +45 -60
- package/lib/tx-helpers/send-atomicals-nft.js +29 -44
- package/lib/tx-helpers/send-btc.js +53 -71
- package/lib/tx-helpers/send-inscription.js +32 -47
- package/lib/tx-helpers/send-inscriptions.js +28 -43
- package/lib/tx-helpers/send-runes.js +83 -97
- package/lib/tx-helpers/split-inscription-utxo.js +39 -54
- package/lib/types.js +2 -5
- package/lib/utils.js +16 -29
- package/lib/wallet/abstract-wallet.js +1 -2
- package/lib/wallet/estimate-wallet.js +130 -147
- package/lib/wallet/index.js +3 -19
- package/lib/wallet/local-wallet.js +134 -150
- package/package.json +103 -95
- package/lib/address/index.d.ts +0 -37
- package/lib/bitcoin-core.d.ts +0 -5
- package/lib/constants.d.ts +0 -1
- package/lib/error.d.ts +0 -20
- package/lib/index.d.ts +0 -14
- package/lib/keyring/hd-keyring.d.ts +0 -50
- package/lib/keyring/index.d.ts +0 -4
- package/lib/keyring/interfaces/SimpleKeyringOptions.d.ts +0 -53
- package/lib/keyring/keystone-keyring.d.ts +0 -82
- package/lib/keyring/simple-keyring.d.ts +0 -11
- package/lib/message/bip322-simple.d.ts +0 -19
- package/lib/message/deterministic-ecdsa.d.ts +0 -2
- package/lib/message/ecdsa.d.ts +0 -3
- package/lib/message/index.d.ts +0 -3
- package/lib/network/index.d.ts +0 -14
- package/lib/runes/index.d.ts +0 -1
- package/lib/runes/rund_id.d.ts +0 -11
- package/lib/runes/varint.d.ts +0 -15
- package/lib/src/address/index.d.ts +0 -37
- package/lib/src/bitcoin-core.d.ts +0 -5
- package/lib/src/constants.d.ts +0 -1
- package/lib/src/error.d.ts +0 -20
- package/lib/src/index.d.ts +0 -14
- package/lib/src/keyring/hd-keyring.d.ts +0 -50
- package/lib/src/keyring/index.d.ts +0 -4
- package/lib/src/keyring/interfaces/SimpleKeyringOptions.d.ts +0 -53
- package/lib/src/keyring/keystone-keyring.d.ts +0 -82
- package/lib/src/keyring/simple-keyring.d.ts +0 -11
- package/lib/src/message/bip322-simple.d.ts +0 -19
- package/lib/src/message/deterministic-ecdsa.d.ts +0 -2
- package/lib/src/message/ecdsa.d.ts +0 -3
- package/lib/src/message/index.d.ts +0 -3
- package/lib/src/network/index.d.ts +0 -14
- package/lib/src/runes/index.d.ts +0 -1
- package/lib/src/runes/rund_id.d.ts +0 -11
- package/lib/src/runes/varint.d.ts +0 -15
- package/lib/src/transaction/index.d.ts +0 -3
- package/lib/src/transaction/inscription-utxo.d.ts +0 -33
- package/lib/src/transaction/transaction.d.ts +0 -52
- package/lib/src/transaction/utxo.d.ts +0 -35
- package/lib/src/tx-helpers/index.d.ts +0 -8
- package/lib/src/tx-helpers/send-atomicals-ft.d.ts +0 -16
- package/lib/src/tx-helpers/send-atomicals-nft.d.ts +0 -14
- package/lib/src/tx-helpers/send-btc.d.ts +0 -28
- package/lib/src/tx-helpers/send-inscription.d.ts +0 -16
- package/lib/src/tx-helpers/send-inscriptions.d.ts +0 -14
- package/lib/src/tx-helpers/send-runes.d.ts +0 -19
- package/lib/src/tx-helpers/split-inscription-utxo.d.ts +0 -15
- package/lib/src/types.d.ts +0 -59
- package/lib/src/utils.d.ts +0 -23
- package/lib/src/wallet/abstract-wallet.d.ts +0 -6
- package/lib/src/wallet/estimate-wallet.d.ts +0 -23
- package/lib/src/wallet/index.d.ts +0 -3
- package/lib/src/wallet/local-wallet.d.ts +0 -23
- package/lib/test/address/address.test.d.ts +0 -1
- package/lib/test/keyring/hd-keyring.test.d.ts +0 -1
- package/lib/test/keyring/keystone-keyring.test.d.ts +0 -1
- package/lib/test/keyring/simple-keyring.test.d.ts +0 -1
- package/lib/test/message/message.test.d.ts +0 -1
- package/lib/test/runes/varint.test.d.ts +0 -1
- package/lib/test/transaction/transaction.test.d.ts +0 -1
- package/lib/test/transaction/utxo.test.d.ts +0 -1
- package/lib/test/tx-helpers/send-atomicals-ft.test.d.ts +0 -1
- package/lib/test/tx-helpers/send-atomicals-nft.test.d.ts +0 -1
- package/lib/test/tx-helpers/send-btc.test.d.ts +0 -1
- package/lib/test/tx-helpers/send-inscription.test.d.ts +0 -1
- package/lib/test/tx-helpers/send-inscriptions.test.d.ts +0 -1
- package/lib/test/tx-helpers/send-runes.test.d.ts +0 -1
- package/lib/test/tx-helpers/split-inscription-utxo.test.d.ts +0 -1
- package/lib/test/tx-helpers/utils.d.ts +0 -217
- package/lib/test/utils.d.ts +0 -4
- package/lib/test/wallet/local-wallet.test.d.ts +0 -1
- package/lib/transaction/index.d.ts +0 -3
- package/lib/transaction/inscription-utxo.d.ts +0 -33
- package/lib/transaction/transaction.d.ts +0 -52
- package/lib/transaction/utxo.d.ts +0 -35
- package/lib/tx-helpers/index.d.ts +0 -8
- package/lib/tx-helpers/send-atomicals-ft.d.ts +0 -16
- package/lib/tx-helpers/send-atomicals-nft.d.ts +0 -14
- package/lib/tx-helpers/send-btc.d.ts +0 -28
- package/lib/tx-helpers/send-inscription.d.ts +0 -16
- package/lib/tx-helpers/send-inscriptions.d.ts +0 -14
- package/lib/tx-helpers/send-runes.d.ts +0 -19
- package/lib/tx-helpers/split-inscription-utxo.d.ts +0 -15
- package/lib/types.d.ts +0 -59
- package/lib/utils.d.ts +0 -23
- package/lib/wallet/abstract-wallet.d.ts +0 -6
- package/lib/wallet/estimate-wallet.d.ts +0 -23
- package/lib/wallet/index.d.ts +0 -3
- package/lib/wallet/local-wallet.d.ts +0 -23
package/es/bundle.js.LICENSE.txt
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* decimal.js v10.
|
|
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)
|
|
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
|
/**
|
package/lib/address/index.js
CHANGED
|
@@ -1,76 +1,48 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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 =
|
|
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 ===
|
|
40
|
-
return
|
|
13
|
+
if (type === AddressType.P2PKH) {
|
|
14
|
+
return payments.p2pkh({
|
|
41
15
|
pubkey,
|
|
42
16
|
network
|
|
43
17
|
});
|
|
44
18
|
}
|
|
45
|
-
else if (type ===
|
|
46
|
-
return
|
|
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 ===
|
|
52
|
-
return
|
|
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 ===
|
|
58
|
-
const data =
|
|
31
|
+
else if (type === AddressType.P2SH_P2WPKH) {
|
|
32
|
+
const data = payments.p2wpkh({
|
|
59
33
|
pubkey,
|
|
60
34
|
network
|
|
61
35
|
});
|
|
62
|
-
return
|
|
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
|
|
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 =
|
|
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 =
|
|
71
|
+
export function isValidAddress(address, networkType = NetworkType.MAINNET) {
|
|
103
72
|
let error;
|
|
104
73
|
try {
|
|
105
|
-
bitcoin.address.toOutputScript(address,
|
|
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
|
-
|
|
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 =
|
|
98
|
+
networkType = NetworkType.MAINNET;
|
|
131
99
|
}
|
|
132
100
|
else if (decodeBech32.prefix === testnet.bech32) {
|
|
133
|
-
networkType =
|
|
101
|
+
networkType = NetworkType.TESTNET;
|
|
134
102
|
}
|
|
135
103
|
else if (decodeBech32.prefix === regtest.bech32) {
|
|
136
|
-
networkType =
|
|
104
|
+
networkType = NetworkType.REGTEST;
|
|
137
105
|
}
|
|
138
106
|
if (decodeBech32.version === 0) {
|
|
139
107
|
if (decodeBech32.data.length === 20) {
|
|
140
|
-
addressType =
|
|
108
|
+
addressType = AddressType.P2WPKH;
|
|
141
109
|
}
|
|
142
110
|
else if (decodeBech32.data.length === 32) {
|
|
143
|
-
addressType =
|
|
111
|
+
addressType = AddressType.P2WSH;
|
|
144
112
|
}
|
|
145
113
|
}
|
|
146
114
|
else if (decodeBech32.version === 1) {
|
|
147
115
|
if (decodeBech32.data.length === 32) {
|
|
148
|
-
addressType =
|
|
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 =
|
|
164
|
-
addressType =
|
|
131
|
+
networkType = NetworkType.MAINNET;
|
|
132
|
+
addressType = AddressType.P2PKH;
|
|
165
133
|
}
|
|
166
134
|
else if (decodeBase58.version === testnet.pubKeyHash) {
|
|
167
|
-
networkType =
|
|
168
|
-
addressType =
|
|
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 =
|
|
173
|
-
addressType =
|
|
140
|
+
networkType = NetworkType.REGTEST;
|
|
141
|
+
addressType = AddressType.P2PKH;
|
|
174
142
|
}
|
|
175
143
|
else if (decodeBase58.version === mainnet.scriptHash) {
|
|
176
|
-
networkType =
|
|
177
|
-
addressType =
|
|
144
|
+
networkType = NetworkType.MAINNET;
|
|
145
|
+
addressType = AddressType.P2SH_P2WPKH;
|
|
178
146
|
}
|
|
179
147
|
else if (decodeBase58.version === testnet.scriptHash) {
|
|
180
|
-
networkType =
|
|
181
|
-
addressType =
|
|
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 =
|
|
186
|
-
addressType =
|
|
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:
|
|
198
|
-
addressType:
|
|
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 ===
|
|
171
|
+
if (addressType === AddressType.P2WPKH || addressType === AddressType.M44_P2WPKH) {
|
|
205
172
|
return 294;
|
|
206
173
|
}
|
|
207
|
-
else if (addressType ===
|
|
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 =
|
|
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 =
|
|
226
|
-
const network =
|
|
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;
|
package/lib/bitcoin-core.js
CHANGED
|
@@ -1,37 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
2
|
+
export const UTXO_DUST = 546;
|
package/lib/error.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
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
|
|
13
|
-
|
|
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
|
-
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
|
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(
|
|
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 =
|
|
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 =
|
|
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 =
|
|
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
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
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 =
|
|
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;
|
package/lib/keyring/index.js
CHANGED
|
@@ -1,20 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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';
|