@atomicfinance/bitcoin-wallet-provider 2.2.3
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/.nvmrc +1 -0
- package/LICENSE +674 -0
- package/dist/BitcoinWalletProvider.d.ts +87 -0
- package/dist/BitcoinWalletProvider.js +359 -0
- package/dist/BitcoinWalletProvider.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/lib/BitcoinWalletProvider.ts +542 -0
- package/lib/index.ts +1 -0
- package/package.json +35 -0
- package/tsconfig.json +7 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import Provider from '@atomicfinance/provider';
|
|
2
|
+
import { CreateMultisigResponse, finalizePSBTResponse, FinanceWalletProvider, Input, Output } from '@atomicfinance/types';
|
|
3
|
+
import { BitcoinNetwork } from '@liquality/bitcoin-networks';
|
|
4
|
+
import { Address, bitcoin as bT, Transaction } from '@liquality/types';
|
|
5
|
+
import * as bitcoin from 'bitcoinjs-lib';
|
|
6
|
+
declare type UnusedAddressesBlacklist = {
|
|
7
|
+
[address: string]: true;
|
|
8
|
+
};
|
|
9
|
+
export default class BitcoinWalletProvider extends Provider implements Partial<FinanceWalletProvider> {
|
|
10
|
+
_network: BitcoinNetwork;
|
|
11
|
+
_unusedAddressesBlacklist: UnusedAddressesBlacklist;
|
|
12
|
+
constructor(network: BitcoinNetwork);
|
|
13
|
+
buildSweepTransactionWithSetOutputs(externalChangeAddress: string, feePerByte: number, _outputs: Output[], fixedInputs: Input[]): Promise<{
|
|
14
|
+
hex: string;
|
|
15
|
+
fee: number;
|
|
16
|
+
}>;
|
|
17
|
+
getUnusedAddressesBlacklist(): UnusedAddressesBlacklist;
|
|
18
|
+
setUnusedAddressesBlacklist(unusedAddressesBlacklist: UnusedAddressesBlacklist): void;
|
|
19
|
+
_createMultisigPayment(m: number, pubkeys: string[]): bitcoin.Payment;
|
|
20
|
+
/**
|
|
21
|
+
* Creates a native-segwit multi-signature address (P2MS in P2WSH) with n signatures of m required keys
|
|
22
|
+
* https://developer.bitcoin.org/reference/rpc/createmultisig.html
|
|
23
|
+
* @param m the number of required signatures
|
|
24
|
+
* @param pubkeys n possible pubkeys in total
|
|
25
|
+
* @returns a json object containing the `address` and `redeemScript`
|
|
26
|
+
*/
|
|
27
|
+
createMultisig(m: number, pubkeys: string[]): CreateMultisigResponse;
|
|
28
|
+
/**
|
|
29
|
+
* Creates a PSBT of a native-segwit multi-signature address (P2MS in P2WSH) with n signatures of m required keys
|
|
30
|
+
* https://developer.bitcoin.org/reference/rpc/createmultisig.html
|
|
31
|
+
* https://developer.bitcoin.org/reference/rpc/createpsbt.html
|
|
32
|
+
* @param m the number of required signatures
|
|
33
|
+
* @param pubkeys n possible pubkeys in total
|
|
34
|
+
* @param inputs the Inputs to the PSBT
|
|
35
|
+
* @param ouputs the Outputs to the PSBT
|
|
36
|
+
* @returns a base64 encoded psbt string
|
|
37
|
+
*/
|
|
38
|
+
buildMultisigPSBT(m: number, pubkeys: string[], inputs: Input[], outputs: Output[]): string;
|
|
39
|
+
/**
|
|
40
|
+
* Update a PSBT with input information from our wallet and then sign inputs that we can sign for
|
|
41
|
+
* https://developer.bitcoin.org/reference/rpc/walletprocesspsbt.html
|
|
42
|
+
* @param psbt a base64 encoded psbt string (P2WSH only)
|
|
43
|
+
* @returns a base64 encoded signed psbt string
|
|
44
|
+
*/
|
|
45
|
+
walletProcessPSBT(psbtString: string): Promise<string>;
|
|
46
|
+
/**
|
|
47
|
+
* Finalize the inputs of a PSBT. If the transaction is fully signed, it will
|
|
48
|
+
* produce a network serialized transaction which can be broadcast with sendrawtransaction
|
|
49
|
+
* https://developer.bitcoin.org/reference/rpc/finalizepsbt.html
|
|
50
|
+
* @param psbt a base64 encoded psbt string
|
|
51
|
+
* @returns a json object containing `psbt` in base64, `hex` for transaction and `complete` for if
|
|
52
|
+
* the transaction has a complete set of signatures
|
|
53
|
+
*/
|
|
54
|
+
finalizePSBT(psbtString: string): finalizePSBTResponse;
|
|
55
|
+
getUnusedAddress(change?: boolean, numAddressPerCall?: number): Promise<any>;
|
|
56
|
+
_getUsedUnusedAddresses(numAddressPerCall: number, addressType: any): Promise<{
|
|
57
|
+
usedAddresses: any[];
|
|
58
|
+
unusedAddress: {
|
|
59
|
+
change: any;
|
|
60
|
+
nonChange: any;
|
|
61
|
+
};
|
|
62
|
+
firstUnusedAddress: any;
|
|
63
|
+
}>;
|
|
64
|
+
sendSweepTransactionWithSetOutputs(externalChangeAddress: string, feePerByte: number, _outputs: Output[], fixedInputs: Input[]): Promise<Transaction<bT.Transaction>>;
|
|
65
|
+
_buildSweepTransaction(externalChangeAddress: string, feePerByte: number, _outputs: Output[], fixedInputs: Input[]): Promise<{
|
|
66
|
+
hex: string;
|
|
67
|
+
fee: number;
|
|
68
|
+
}>;
|
|
69
|
+
_getInputForAmountWithoutUtxoCheck(_outputs: Output[], _feePerByte: number, fixedInputs: Input[]): {
|
|
70
|
+
inputs: bT.UTXO[];
|
|
71
|
+
outputs: {
|
|
72
|
+
value: number;
|
|
73
|
+
id?: string;
|
|
74
|
+
}[];
|
|
75
|
+
fee: number;
|
|
76
|
+
change: {
|
|
77
|
+
value: number;
|
|
78
|
+
id?: string;
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
_buildTransactionWithoutUtxoCheck(outputs: Output[], feePerByte: number, fixedInputs: Input[]): Promise<{
|
|
82
|
+
hex: string;
|
|
83
|
+
fee: number;
|
|
84
|
+
}>;
|
|
85
|
+
quickFindAddress(addresses: string[]): Promise<Address>;
|
|
86
|
+
}
|
|
87
|
+
export {};
|
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
10
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
11
|
+
}) : function(o, v) {
|
|
12
|
+
o["default"] = v;
|
|
13
|
+
});
|
|
14
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
15
|
+
if (mod && mod.__esModule) return mod;
|
|
16
|
+
var result = {};
|
|
17
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
18
|
+
__setModuleDefault(result, mod);
|
|
19
|
+
return result;
|
|
20
|
+
};
|
|
21
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
22
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
const provider_1 = __importDefault(require("@atomicfinance/provider"));
|
|
26
|
+
const types_1 = require("@atomicfinance/types");
|
|
27
|
+
const bitcoin_utils_1 = require("@liquality/bitcoin-utils");
|
|
28
|
+
const assert_1 = __importDefault(require("assert"));
|
|
29
|
+
const bitcoin = __importStar(require("bitcoinjs-lib"));
|
|
30
|
+
const secp256k1_1 = __importDefault(require("secp256k1"));
|
|
31
|
+
const FEE_PER_BYTE_FALLBACK = 5;
|
|
32
|
+
const ADDRESS_GAP = 20;
|
|
33
|
+
const NONCHANGE_ADDRESS = 0;
|
|
34
|
+
const CHANGE_ADDRESS = 1;
|
|
35
|
+
const NONCHANGE_OR_CHANGE_ADDRESS = 2;
|
|
36
|
+
class BitcoinWalletProvider extends provider_1.default {
|
|
37
|
+
constructor(network) {
|
|
38
|
+
super();
|
|
39
|
+
this._network = network;
|
|
40
|
+
this._unusedAddressesBlacklist = {};
|
|
41
|
+
}
|
|
42
|
+
async buildSweepTransactionWithSetOutputs(externalChangeAddress, feePerByte, _outputs, fixedInputs) {
|
|
43
|
+
return this._buildSweepTransaction(externalChangeAddress, feePerByte, _outputs, fixedInputs);
|
|
44
|
+
}
|
|
45
|
+
getUnusedAddressesBlacklist() {
|
|
46
|
+
return this._unusedAddressesBlacklist;
|
|
47
|
+
}
|
|
48
|
+
setUnusedAddressesBlacklist(unusedAddressesBlacklist) {
|
|
49
|
+
this._unusedAddressesBlacklist = unusedAddressesBlacklist;
|
|
50
|
+
}
|
|
51
|
+
_createMultisigPayment(m, pubkeys) {
|
|
52
|
+
if (m > pubkeys.length) {
|
|
53
|
+
throw new Error(`not enough keys supplied (got ${pubkeys.length} keys, but need at least ${m} to redeem)`);
|
|
54
|
+
}
|
|
55
|
+
// Create m-of-n multisig
|
|
56
|
+
const p2ms = bitcoin.payments.p2ms({
|
|
57
|
+
m: m,
|
|
58
|
+
pubkeys: pubkeys.map((key) => Buffer.from(key, 'hex')),
|
|
59
|
+
network: this._network,
|
|
60
|
+
});
|
|
61
|
+
// Create p2wsh for multisig
|
|
62
|
+
const p2wsh = bitcoin.payments.p2wsh({
|
|
63
|
+
redeem: p2ms,
|
|
64
|
+
network: this._network,
|
|
65
|
+
});
|
|
66
|
+
return p2wsh;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Creates a native-segwit multi-signature address (P2MS in P2WSH) with n signatures of m required keys
|
|
70
|
+
* https://developer.bitcoin.org/reference/rpc/createmultisig.html
|
|
71
|
+
* @param m the number of required signatures
|
|
72
|
+
* @param pubkeys n possible pubkeys in total
|
|
73
|
+
* @returns a json object containing the `address` and `redeemScript`
|
|
74
|
+
*/
|
|
75
|
+
createMultisig(m, pubkeys) {
|
|
76
|
+
const p2wsh = this._createMultisigPayment(m, pubkeys);
|
|
77
|
+
return {
|
|
78
|
+
address: p2wsh.address,
|
|
79
|
+
redeemScript: p2wsh.redeem?.output?.toString('hex'),
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Creates a PSBT of a native-segwit multi-signature address (P2MS in P2WSH) with n signatures of m required keys
|
|
84
|
+
* https://developer.bitcoin.org/reference/rpc/createmultisig.html
|
|
85
|
+
* https://developer.bitcoin.org/reference/rpc/createpsbt.html
|
|
86
|
+
* @param m the number of required signatures
|
|
87
|
+
* @param pubkeys n possible pubkeys in total
|
|
88
|
+
* @param inputs the Inputs to the PSBT
|
|
89
|
+
* @param ouputs the Outputs to the PSBT
|
|
90
|
+
* @returns a base64 encoded psbt string
|
|
91
|
+
*/
|
|
92
|
+
buildMultisigPSBT(m, pubkeys, inputs, outputs) {
|
|
93
|
+
assert_1.default(inputs.length > 0, 'no inputs found');
|
|
94
|
+
assert_1.default(outputs.length > 0, 'no outputs found');
|
|
95
|
+
const p2wsh = this._createMultisigPayment(m, pubkeys);
|
|
96
|
+
// Verify pubkeyhash for all inputs matches the p2wsh hash
|
|
97
|
+
assert_1.default(inputs.every((input) => p2wsh.output.toString('hex') === input.scriptPubKey), 'address pubkeyhash does not match input scriptPubKey');
|
|
98
|
+
// creator
|
|
99
|
+
const psbt = new bitcoin.Psbt({ network: this._network });
|
|
100
|
+
// updater
|
|
101
|
+
inputs.forEach((input) => {
|
|
102
|
+
psbt.addInput({
|
|
103
|
+
hash: input.txid,
|
|
104
|
+
index: input.vout,
|
|
105
|
+
witnessUtxo: { script: p2wsh.output, value: input.value },
|
|
106
|
+
witnessScript: p2wsh.redeem.output,
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
outputs.forEach((output) => {
|
|
110
|
+
psbt.addOutput({
|
|
111
|
+
address: output.to,
|
|
112
|
+
value: output.value,
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
return psbt.toBase64();
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Update a PSBT with input information from our wallet and then sign inputs that we can sign for
|
|
119
|
+
* https://developer.bitcoin.org/reference/rpc/walletprocesspsbt.html
|
|
120
|
+
* @param psbt a base64 encoded psbt string (P2WSH only)
|
|
121
|
+
* @returns a base64 encoded signed psbt string
|
|
122
|
+
*/
|
|
123
|
+
async walletProcessPSBT(psbtString) {
|
|
124
|
+
const psbt = bitcoin.Psbt.fromBase64(psbtString);
|
|
125
|
+
await Promise.all(psbt.data.inputs.map(async (input, i) => {
|
|
126
|
+
assert_1.default(psbt.getInputType(i).slice(0, 5) === 'p2wsh', 'only accepts P2WSH inputs');
|
|
127
|
+
const scriptStack = bitcoin.script.decompile(input.witnessScript);
|
|
128
|
+
const pubkeys = scriptStack.filter((data) => Buffer.isBuffer(data) && secp256k1_1.default.publicKeyVerify(data));
|
|
129
|
+
await Promise.all(pubkeys.map(async (key) => {
|
|
130
|
+
// create address using pubkey
|
|
131
|
+
const { address: addressString } = bitcoin.payments.p2wpkh({
|
|
132
|
+
pubkey: key,
|
|
133
|
+
network: this._network,
|
|
134
|
+
});
|
|
135
|
+
// Retrieve address object from wallet using address
|
|
136
|
+
const address = await this.quickFindAddress([
|
|
137
|
+
addressString,
|
|
138
|
+
]);
|
|
139
|
+
// exit if address doesn't exist in wallet
|
|
140
|
+
if (!address)
|
|
141
|
+
return;
|
|
142
|
+
// derive keypair
|
|
143
|
+
const keyPair = await this.getMethod('keyPair')(address.derivationPath);
|
|
144
|
+
// sign PSBT using keypair
|
|
145
|
+
psbt.signInput(i, keyPair);
|
|
146
|
+
}));
|
|
147
|
+
}));
|
|
148
|
+
psbt.validateSignaturesOfAllInputs(); // ensure all signatures are valid!
|
|
149
|
+
return psbt.toBase64();
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Finalize the inputs of a PSBT. If the transaction is fully signed, it will
|
|
153
|
+
* produce a network serialized transaction which can be broadcast with sendrawtransaction
|
|
154
|
+
* https://developer.bitcoin.org/reference/rpc/finalizepsbt.html
|
|
155
|
+
* @param psbt a base64 encoded psbt string
|
|
156
|
+
* @returns a json object containing `psbt` in base64, `hex` for transaction and `complete` for if
|
|
157
|
+
* the transaction has a complete set of signatures
|
|
158
|
+
*/
|
|
159
|
+
finalizePSBT(psbtString) {
|
|
160
|
+
const psbt = bitcoin.Psbt.fromBase64(psbtString);
|
|
161
|
+
try {
|
|
162
|
+
psbt.validateSignaturesOfAllInputs(); // ensure all signatures are valid!
|
|
163
|
+
psbt.finalizeAllInputs();
|
|
164
|
+
}
|
|
165
|
+
catch (error) {
|
|
166
|
+
return {
|
|
167
|
+
psbt: psbt.toBase64(),
|
|
168
|
+
complete: false,
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
return {
|
|
172
|
+
psbt: psbt.toBase64(),
|
|
173
|
+
hex: psbt.extractTransaction().toHex(),
|
|
174
|
+
complete: true,
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
async getUnusedAddress(change = false, numAddressPerCall = 100) {
|
|
178
|
+
const addressType = change ? CHANGE_ADDRESS : NONCHANGE_ADDRESS;
|
|
179
|
+
const key = change ? 'change' : 'nonChange';
|
|
180
|
+
const address = await this._getUsedUnusedAddresses(numAddressPerCall, addressType).then(({ unusedAddress }) => unusedAddress[key]);
|
|
181
|
+
this._unusedAddressesBlacklist[address.address] = true;
|
|
182
|
+
return address;
|
|
183
|
+
}
|
|
184
|
+
async _getUsedUnusedAddresses(numAddressPerCall = 100, addressType) {
|
|
185
|
+
const usedAddresses = [];
|
|
186
|
+
const addressCountMap = { change: 0, nonChange: 0 };
|
|
187
|
+
const unusedAddressMap = { change: null, nonChange: null };
|
|
188
|
+
let addrList;
|
|
189
|
+
let addressIndex = 0;
|
|
190
|
+
let changeAddresses = [];
|
|
191
|
+
let nonChangeAddresses = [];
|
|
192
|
+
/* eslint-disable no-unmodified-loop-condition */
|
|
193
|
+
while ((addressType === NONCHANGE_OR_CHANGE_ADDRESS &&
|
|
194
|
+
(addressCountMap.change < ADDRESS_GAP ||
|
|
195
|
+
addressCountMap.nonChange < ADDRESS_GAP)) ||
|
|
196
|
+
(addressType === NONCHANGE_ADDRESS &&
|
|
197
|
+
addressCountMap.nonChange < ADDRESS_GAP) ||
|
|
198
|
+
(addressType === CHANGE_ADDRESS && addressCountMap.change < ADDRESS_GAP)) {
|
|
199
|
+
/* eslint-enable no-unmodified-loop-condition */
|
|
200
|
+
addrList = [];
|
|
201
|
+
if ((addressType === NONCHANGE_OR_CHANGE_ADDRESS ||
|
|
202
|
+
addressType === CHANGE_ADDRESS) &&
|
|
203
|
+
addressCountMap.change < ADDRESS_GAP) {
|
|
204
|
+
// Scanning for change addr
|
|
205
|
+
changeAddresses = await this.client.wallet.getAddresses(addressIndex, numAddressPerCall, true);
|
|
206
|
+
addrList = addrList.concat(changeAddresses);
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
changeAddresses = [];
|
|
210
|
+
}
|
|
211
|
+
if ((addressType === NONCHANGE_OR_CHANGE_ADDRESS ||
|
|
212
|
+
addressType === NONCHANGE_ADDRESS) &&
|
|
213
|
+
addressCountMap.nonChange < ADDRESS_GAP) {
|
|
214
|
+
// Scanning for non change addr
|
|
215
|
+
nonChangeAddresses = await this.client.wallet.getAddresses(addressIndex, numAddressPerCall, false);
|
|
216
|
+
addrList = addrList.concat(nonChangeAddresses);
|
|
217
|
+
}
|
|
218
|
+
const transactionCounts = await this.getMethod('getAddressTransactionCounts')(addrList);
|
|
219
|
+
for (const address of addrList) {
|
|
220
|
+
const isUsed = transactionCounts[address.address] > 0 ||
|
|
221
|
+
this._unusedAddressesBlacklist[address.address];
|
|
222
|
+
const isChangeAddress = changeAddresses.find((a) => address.address === a.address);
|
|
223
|
+
const key = isChangeAddress ? 'change' : 'nonChange';
|
|
224
|
+
if (isUsed) {
|
|
225
|
+
usedAddresses.push(address);
|
|
226
|
+
addressCountMap[key] = 0;
|
|
227
|
+
unusedAddressMap[key] = null;
|
|
228
|
+
}
|
|
229
|
+
else {
|
|
230
|
+
addressCountMap[key]++;
|
|
231
|
+
if (!unusedAddressMap[key]) {
|
|
232
|
+
unusedAddressMap[key] = address;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
addressIndex += numAddressPerCall;
|
|
237
|
+
}
|
|
238
|
+
let firstUnusedAddress;
|
|
239
|
+
const indexNonChange = unusedAddressMap.nonChange
|
|
240
|
+
? unusedAddressMap.nonChange.index
|
|
241
|
+
: Infinity;
|
|
242
|
+
const indexChange = unusedAddressMap.change
|
|
243
|
+
? unusedAddressMap.change.index
|
|
244
|
+
: Infinity;
|
|
245
|
+
if (indexNonChange <= indexChange)
|
|
246
|
+
firstUnusedAddress = unusedAddressMap.nonChange;
|
|
247
|
+
else
|
|
248
|
+
firstUnusedAddress = unusedAddressMap.change;
|
|
249
|
+
return {
|
|
250
|
+
usedAddresses,
|
|
251
|
+
unusedAddress: unusedAddressMap,
|
|
252
|
+
firstUnusedAddress,
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
async sendSweepTransactionWithSetOutputs(externalChangeAddress, feePerByte, _outputs, fixedInputs) {
|
|
256
|
+
const { hex, fee } = await this._buildSweepTransaction(externalChangeAddress, feePerByte, _outputs, fixedInputs);
|
|
257
|
+
await this.getMethod('sendRawTransaction')(hex);
|
|
258
|
+
return bitcoin_utils_1.normalizeTransactionObject(bitcoin_utils_1.decodeRawTransaction(hex, this._network), fee);
|
|
259
|
+
}
|
|
260
|
+
async _buildSweepTransaction(externalChangeAddress, feePerByte, _outputs = [], fixedInputs) {
|
|
261
|
+
const _feePerByte = feePerByte ||
|
|
262
|
+
(await this.getMethod('getFeePerByte')()) ||
|
|
263
|
+
FEE_PER_BYTE_FALLBACK;
|
|
264
|
+
const inputs = [];
|
|
265
|
+
const outputs = [];
|
|
266
|
+
try {
|
|
267
|
+
const inputsForAmount = await this.getMethod('getInputsForAmount')(_outputs, _feePerByte, fixedInputs, 100, true);
|
|
268
|
+
if (inputsForAmount.change) {
|
|
269
|
+
throw Error('There should not be any change for sweeping transaction');
|
|
270
|
+
}
|
|
271
|
+
inputs.push(...(inputsForAmount.inputs || []));
|
|
272
|
+
outputs.push(...(inputsForAmount.outputs || []));
|
|
273
|
+
}
|
|
274
|
+
catch (e) {
|
|
275
|
+
if (fixedInputs.length === 0) {
|
|
276
|
+
throw Error(`Inputs for amount doesn't exist and no fixedInputs provided`);
|
|
277
|
+
}
|
|
278
|
+
const inputsForAmount = await this._getInputForAmountWithoutUtxoCheck(_outputs, _feePerByte, fixedInputs);
|
|
279
|
+
inputs.push(...(inputsForAmount.inputs.map((utxo) => types_1.Input.fromUTXO(utxo)) || []));
|
|
280
|
+
outputs.push(...(inputsForAmount.outputs || []));
|
|
281
|
+
}
|
|
282
|
+
_outputs.forEach((output) => {
|
|
283
|
+
const spliceIndex = outputs.findIndex((sweepOutput) => output.value === sweepOutput.value);
|
|
284
|
+
outputs.splice(spliceIndex, 1);
|
|
285
|
+
});
|
|
286
|
+
_outputs.push({
|
|
287
|
+
to: externalChangeAddress,
|
|
288
|
+
value: outputs[0].value,
|
|
289
|
+
});
|
|
290
|
+
return this._buildTransactionWithoutUtxoCheck(_outputs, _feePerByte, inputs);
|
|
291
|
+
}
|
|
292
|
+
_getInputForAmountWithoutUtxoCheck(_outputs, _feePerByte, fixedInputs) {
|
|
293
|
+
const utxoBalance = fixedInputs.reduce((a, b) => a + (b['value'] || 0), 0);
|
|
294
|
+
const outputBalance = _outputs.reduce((a, b) => a + (b['value'] || 0), 0);
|
|
295
|
+
const amountToSend = utxoBalance -
|
|
296
|
+
_feePerByte * ((_outputs.length + 1) * 39 + fixedInputs.length * 153); // todo better calculation
|
|
297
|
+
const targets = _outputs.map((target, i) => ({
|
|
298
|
+
id: 'main',
|
|
299
|
+
value: target.value,
|
|
300
|
+
}));
|
|
301
|
+
if (amountToSend - outputBalance > 0) {
|
|
302
|
+
targets.push({ id: 'main', value: amountToSend - outputBalance });
|
|
303
|
+
}
|
|
304
|
+
return bitcoin_utils_1.selectCoins(fixedInputs, targets, Math.ceil(_feePerByte), fixedInputs);
|
|
305
|
+
}
|
|
306
|
+
async _buildTransactionWithoutUtxoCheck(outputs, feePerByte, fixedInputs) {
|
|
307
|
+
const network = this._network;
|
|
308
|
+
const { fee } = this._getInputForAmountWithoutUtxoCheck(outputs, feePerByte, fixedInputs);
|
|
309
|
+
const inputs = fixedInputs;
|
|
310
|
+
const txb = new bitcoin.TransactionBuilder(network);
|
|
311
|
+
for (const output of outputs) {
|
|
312
|
+
const to = output.to; // Allow for OP_RETURN
|
|
313
|
+
txb.addOutput(to, output.value);
|
|
314
|
+
}
|
|
315
|
+
const prevOutScriptType = 'p2wpkh';
|
|
316
|
+
for (let i = 0; i < inputs.length; i++) {
|
|
317
|
+
const wallet = await this.getMethod('getWalletAddress')(inputs[i].address);
|
|
318
|
+
const keyPair = await this.getMethod('keyPair')(wallet.derivationPath);
|
|
319
|
+
const paymentVariant = this.getMethod('getPaymentVariantFromPublicKey')(keyPair.publicKey);
|
|
320
|
+
txb.addInput(inputs[i].txid, inputs[i].vout, 0, paymentVariant.output);
|
|
321
|
+
}
|
|
322
|
+
for (let i = 0; i < inputs.length; i++) {
|
|
323
|
+
const wallet = await this.getMethod('getWalletAddress')(inputs[i].address);
|
|
324
|
+
const keyPair = await this.getMethod('keyPair')(wallet.derivationPath);
|
|
325
|
+
const paymentVariant = this.getMethod('getPaymentVariantFromPublicKey')(keyPair.publicKey);
|
|
326
|
+
const needsWitness = true;
|
|
327
|
+
const signParams = {
|
|
328
|
+
prevOutScriptType,
|
|
329
|
+
vin: i,
|
|
330
|
+
keyPair,
|
|
331
|
+
witnessValue: 0,
|
|
332
|
+
};
|
|
333
|
+
if (needsWitness) {
|
|
334
|
+
signParams.witnessValue = inputs[i].value;
|
|
335
|
+
}
|
|
336
|
+
txb.sign(signParams);
|
|
337
|
+
}
|
|
338
|
+
return { hex: txb.build().toHex(), fee };
|
|
339
|
+
}
|
|
340
|
+
async quickFindAddress(addresses) {
|
|
341
|
+
const maxAddresses = 500;
|
|
342
|
+
const addressesPerCall = 5;
|
|
343
|
+
let index = 0;
|
|
344
|
+
while (index < maxAddresses) {
|
|
345
|
+
const walletNonChangeAddresses = await this.getMethod('getAddresses')(index, addressesPerCall, true);
|
|
346
|
+
const walletChangeAddresses = await this.getMethod('getAddresses')(index, addressesPerCall, false);
|
|
347
|
+
const walletAddresses = [
|
|
348
|
+
...walletNonChangeAddresses,
|
|
349
|
+
...walletChangeAddresses,
|
|
350
|
+
];
|
|
351
|
+
const walletAddress = walletAddresses.find((walletAddr) => addresses.find((addr) => walletAddr.address === addr));
|
|
352
|
+
if (walletAddress)
|
|
353
|
+
return walletAddress;
|
|
354
|
+
index += addressesPerCall;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
}
|
|
358
|
+
exports.default = BitcoinWalletProvider;
|
|
359
|
+
//# sourceMappingURL=BitcoinWalletProvider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BitcoinWalletProvider.js","sourceRoot":"","sources":["../lib/BitcoinWalletProvider.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,uEAA+C;AAC/C,gDAM8B;AAE9B,4DAIkC;AAElC,oDAA4B;AAC5B,uDAAyC;AACzC,0DAAkC;AAElC,MAAM,qBAAqB,GAAG,CAAC,CAAC;AAChC,MAAM,WAAW,GAAG,EAAE,CAAC;AACvB,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAC5B,MAAM,cAAc,GAAG,CAAC,CAAC;AACzB,MAAM,2BAA2B,GAAG,CAAC,CAAC;AAMtC,MAAqB,qBACnB,SAAQ,kBAAQ;IAKhB,YAAY,OAAuB;QACjC,KAAK,EAAE,CAAC;QAER,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC;QACxB,IAAI,CAAC,yBAAyB,GAAG,EAAE,CAAC;IACtC,CAAC;IAED,KAAK,CAAC,mCAAmC,CACvC,qBAA6B,EAC7B,UAAkB,EAClB,QAAkB,EAClB,WAAoB;QAEpB,OAAO,IAAI,CAAC,sBAAsB,CAChC,qBAAqB,EACrB,UAAU,EACV,QAAQ,E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AgB,CAAC;SAC3B;IACH,CAAC;CACF;AAhgBD,wCAggBC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './BitcoinWalletProvider';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var BitcoinWalletProvider_1 = require("./BitcoinWalletProvider");
|
|
8
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(BitcoinWalletProvider_1).default; } });
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":";;;;;;AAAA,iEAAkD;AAAzC,iIAAA,OAAO,OAAA"}
|