@yaswap/yacoin 2.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.
- package/CHANGELOG.md +5 -0
- package/dist/lib/chain/YacoinBaseChainProvider.d.ts +12 -0
- package/dist/lib/chain/YacoinBaseChainProvider.js +7 -0
- package/dist/lib/chain/YacoinBaseChainProvider.js.map +1 -0
- package/dist/lib/chain/esplora/YacoinEsploraApiProvider.d.ts +19 -0
- package/dist/lib/chain/esplora/YacoinEsploraApiProvider.js +135 -0
- package/dist/lib/chain/esplora/YacoinEsploraApiProvider.js.map +1 -0
- package/dist/lib/chain/esplora/YacoinEsploraBaseProvider.d.ts +20 -0
- package/dist/lib/chain/esplora/YacoinEsploraBaseProvider.js +138 -0
- package/dist/lib/chain/esplora/YacoinEsploraBaseProvider.js.map +1 -0
- package/dist/lib/chain/esplora/YacoinEsploraBatchBaseProvider.d.ts +12 -0
- package/dist/lib/chain/esplora/YacoinEsploraBatchBaseProvider.js +48 -0
- package/dist/lib/chain/esplora/YacoinEsploraBatchBaseProvider.js.map +1 -0
- package/dist/lib/chain/esplora/types.d.ts +80 -0
- package/dist/lib/chain/esplora/types.js +3 -0
- package/dist/lib/chain/esplora/types.js.map +1 -0
- package/dist/lib/fee/YacoinFeeApiProvider.d.ts +6 -0
- package/dist/lib/fee/YacoinFeeApiProvider.js +45 -0
- package/dist/lib/fee/YacoinFeeApiProvider.js.map +1 -0
- package/dist/lib/index.d.ts +12 -0
- package/dist/lib/index.js +49 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/networks.d.ts +7 -0
- package/dist/lib/networks.js +14 -0
- package/dist/lib/networks.js.map +1 -0
- package/dist/lib/swap/YacoinSwapBaseProvider.d.ts +48 -0
- package/dist/lib/swap/YacoinSwapBaseProvider.js +320 -0
- package/dist/lib/swap/YacoinSwapBaseProvider.js.map +1 -0
- package/dist/lib/swap/YacoinSwapEsploraProvider.d.ts +11 -0
- package/dist/lib/swap/YacoinSwapEsploraProvider.js +56 -0
- package/dist/lib/swap/YacoinSwapEsploraProvider.js.map +1 -0
- package/dist/lib/swap/types.d.ts +12 -0
- package/dist/lib/swap/types.js +4 -0
- package/dist/lib/swap/types.js.map +1 -0
- package/dist/lib/types.d.ts +84 -0
- package/dist/lib/types.js +40 -0
- package/dist/lib/types.js.map +1 -0
- package/dist/lib/utils.d.ts +30 -0
- package/dist/lib/utils.js +216 -0
- package/dist/lib/utils.js.map +1 -0
- package/dist/lib/wallet/IYacoinWallet.d.ts +11 -0
- package/dist/lib/wallet/IYacoinWallet.js +3 -0
- package/dist/lib/wallet/IYacoinWallet.js.map +1 -0
- package/dist/lib/wallet/YacoinBaseWallet.d.ts +68 -0
- package/dist/lib/wallet/YacoinBaseWallet.js +426 -0
- package/dist/lib/wallet/YacoinBaseWallet.js.map +1 -0
- package/dist/lib/wallet/YacoinHDWallet.d.ts +43 -0
- package/dist/lib/wallet/YacoinHDWallet.js +250 -0
- package/dist/lib/wallet/YacoinHDWallet.js.map +1 -0
- package/package.json +36 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { AddressType, Transaction } from '@yaswap/types';
|
|
3
|
+
import { YacoinNetwork, Transaction as YacoinTransaction, UTXO } from './types';
|
|
4
|
+
declare const AddressTypes: string[];
|
|
5
|
+
declare function calculateFee(numInputs: number, numOutputs: number, feePerByte: number): number;
|
|
6
|
+
/**
|
|
7
|
+
* Get compressed pubKey from pubKey.
|
|
8
|
+
* @param pubKey - 65 byte string with prefix, x, y.
|
|
9
|
+
* @returns the compressed pubKey of uncompressed pubKey.
|
|
10
|
+
*/
|
|
11
|
+
declare function compressPubKey(pubKey: string): string;
|
|
12
|
+
declare type CoinSelectTarget = {
|
|
13
|
+
value: number;
|
|
14
|
+
script?: Buffer;
|
|
15
|
+
id?: string;
|
|
16
|
+
};
|
|
17
|
+
declare function selectCoins(utxos: UTXO[], targets: CoinSelectTarget[], feePerByte: number, fixedInputs?: UTXO[]): {
|
|
18
|
+
inputs: UTXO[];
|
|
19
|
+
outputs: CoinSelectTarget[];
|
|
20
|
+
fee: number;
|
|
21
|
+
change: CoinSelectTarget;
|
|
22
|
+
};
|
|
23
|
+
declare function decodeRawTransaction(hex: string, network: YacoinNetwork): YacoinTransaction;
|
|
24
|
+
declare function normalizeTransactionObject(tx: YacoinTransaction, fee: number, block?: {
|
|
25
|
+
number: number;
|
|
26
|
+
hash: string;
|
|
27
|
+
}): Transaction<YacoinTransaction>;
|
|
28
|
+
declare function getPubKeyHash(address: string, network: YacoinNetwork): Buffer;
|
|
29
|
+
declare function validateAddress(_address: AddressType, network: YacoinNetwork): void;
|
|
30
|
+
export { calculateFee, compressPubKey, CoinSelectTarget, selectCoins, decodeRawTransaction, normalizeTransactionObject, AddressTypes, getPubKeyHash, validateAddress, };
|
|
@@ -0,0 +1,216 @@
|
|
|
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.validateAddress = exports.getPubKeyHash = exports.AddressTypes = exports.normalizeTransactionObject = exports.decodeRawTransaction = exports.selectCoins = exports.compressPubKey = exports.calculateFee = void 0;
|
|
30
|
+
const errors_1 = require("@yaswap/errors");
|
|
31
|
+
const types_1 = require("@yaswap/types");
|
|
32
|
+
const yacoin = __importStar(require("@yaswap/yacoinjs-lib"));
|
|
33
|
+
const classify = __importStar(require("@yaswap/yacoinjs-lib/src/classify"));
|
|
34
|
+
const coinselect_1 = __importDefault(require("coinselect"));
|
|
35
|
+
const accumulative_1 = __importDefault(require("coinselect/accumulative"));
|
|
36
|
+
const AddressTypes = ['legacy', 'p2sh-segwit', 'bech32'];
|
|
37
|
+
exports.AddressTypes = AddressTypes;
|
|
38
|
+
function calculateFee(numInputs, numOutputs, feePerByte) {
|
|
39
|
+
// {
|
|
40
|
+
// "txid" : "bc744444f5410e5b03639a0a92d37737b4fa2d6d6f1e97c5a6ed0390e2acfbcf",
|
|
41
|
+
// "version" : 2, // 4 bytes
|
|
42
|
+
// "time" : 1653219764, // 8 bytes
|
|
43
|
+
// "locktime" : 0, // 4 bytes
|
|
44
|
+
// "vin" : [ // 1 byte indicates the upcoming number of inputs
|
|
45
|
+
// {
|
|
46
|
+
// "txid" : "bc2295b664e6cfe57cb0c228a7ec31ff243e177fc28b4f127b32f435ae1a13a7", // 32 bytes
|
|
47
|
+
// "vout" : 0, // 4 bytes
|
|
48
|
+
// "scriptSig" : { // total 240 bytes
|
|
49
|
+
// "asm" : "3045022100879e9310e63842164f585937a94bc4f4209056fec50f3b8e7c353d58bc6335c9022008c520fe57a6e6e7181f428b61c56fb439980db4e9ba745d799a3505297e86a001 021b0fb94962e76fca82bac5c2737bd805e8c8b4830d5f2209b1637a2758f0cad4 9619bad9da984eda018c722024073263167c366112e3bdd32349d08f1fd84d0c 1 6382012088a820d0602bf11c7f3c9d6ea5c4395e497d31b791ec817e9e9c9a9f6523b3a51ccc258876a9147dce63154e07772ff7a6b71c78c434f939c8a7c1670460ec8862b17576a9141a2e6ad533096f6f5bc4e420be190f7e9942d4306888ac",
|
|
50
|
+
// "hex" : "483045022100879e9310e63842164f585937a94bc4f4209056fec50f3b8e7c353d58bc6335c9022008c520fe57a6e6e7181f428b61c56fb439980db4e9ba745d799a3505297e86a00121021b0fb94962e76fca82bac5c2737bd805e8c8b4830d5f2209b1637a2758f0cad4209619bad9da984eda018c722024073263167c366112e3bdd32349d08f1fd84d0c514c616382012088a820d0602bf11c7f3c9d6ea5c4395e497d31b791ec817e9e9c9a9f6523b3a51ccc258876a9147dce63154e07772ff7a6b71c78c434f939c8a7c1670460ec8862b17576a9141a2e6ad533096f6f5bc4e420be190f7e9942d4306888ac"
|
|
51
|
+
// },
|
|
52
|
+
// "sequence" : 0 // 4 bytes
|
|
53
|
+
// }
|
|
54
|
+
// ],
|
|
55
|
+
// "vout" : [ // 1 byte indicates the upcoming number of outputs
|
|
56
|
+
// {
|
|
57
|
+
// "value" : 1.9978880000000001, // 8 bytes
|
|
58
|
+
// "n" : 0,
|
|
59
|
+
// "scriptPubKey" : { // total 25 bytes (24 bytes data + 1 byte size)
|
|
60
|
+
// "asm" : "OP_DUP OP_HASH160 7dce63154e07772ff7a6b71c78c434f939c8a7c1 OP_EQUALVERIFY OP_CHECKSIG",
|
|
61
|
+
// "hex" : "76a9147dce63154e07772ff7a6b71c78c434f939c8a7c188ac",
|
|
62
|
+
// "reqSigs" : 1,
|
|
63
|
+
// "type" : "pubkeyhash",
|
|
64
|
+
// "addresses" : [
|
|
65
|
+
// "YBVeXN4vzg9HC4QywKZHkmC147LtuCFV2A"
|
|
66
|
+
// ]
|
|
67
|
+
// }
|
|
68
|
+
// }
|
|
69
|
+
// ],
|
|
70
|
+
// "size" : 333
|
|
71
|
+
// }
|
|
72
|
+
// 18 bytes are version + time + locktime + 2 byte indicates the upcoming number of inputs, output
|
|
73
|
+
return (numInputs * 280 + numOutputs * 33 + 18) * feePerByte;
|
|
74
|
+
}
|
|
75
|
+
exports.calculateFee = calculateFee;
|
|
76
|
+
/**
|
|
77
|
+
* Get compressed pubKey from pubKey.
|
|
78
|
+
* @param pubKey - 65 byte string with prefix, x, y.
|
|
79
|
+
* @returns the compressed pubKey of uncompressed pubKey.
|
|
80
|
+
*/
|
|
81
|
+
function compressPubKey(pubKey) {
|
|
82
|
+
const x = pubKey.substring(2, 66);
|
|
83
|
+
const y = pubKey.substring(66, 130);
|
|
84
|
+
const even = parseInt(y.substring(62, 64), 16) % 2 === 0;
|
|
85
|
+
const prefix = even ? '02' : '03';
|
|
86
|
+
return prefix + x;
|
|
87
|
+
}
|
|
88
|
+
exports.compressPubKey = compressPubKey;
|
|
89
|
+
function selectCoins(utxos, targets, feePerByte, fixedInputs = []) {
|
|
90
|
+
let selectUtxos = utxos;
|
|
91
|
+
// Default coinselect won't accumulate some inputs
|
|
92
|
+
// TODO: does coinselect need to be modified to ABSOLUTELY not skip an input?
|
|
93
|
+
const coinselectStrat = fixedInputs.length ? accumulative_1.default : coinselect_1.default;
|
|
94
|
+
if (fixedInputs.length) {
|
|
95
|
+
selectUtxos = [
|
|
96
|
+
// Order fixed inputs to the start of the list so they are used
|
|
97
|
+
...fixedInputs,
|
|
98
|
+
...utxos.filter((utxo) => !fixedInputs.find((input) => input.vout === utxo.vout && input.txid === utxo.txid)),
|
|
99
|
+
];
|
|
100
|
+
}
|
|
101
|
+
const { inputs, outputs, fee } = coinselectStrat(selectUtxos, targets, Math.ceil(feePerByte));
|
|
102
|
+
let change;
|
|
103
|
+
if (inputs && outputs) {
|
|
104
|
+
change = outputs.find((output) => output.id !== 'main');
|
|
105
|
+
}
|
|
106
|
+
return { inputs, outputs, fee, change };
|
|
107
|
+
}
|
|
108
|
+
exports.selectCoins = selectCoins;
|
|
109
|
+
const OUTPUT_TYPES_MAP = {
|
|
110
|
+
[classify.types.P2WPKH]: 'witness_v0_keyhash',
|
|
111
|
+
[classify.types.P2WSH]: 'witness_v0_scripthash',
|
|
112
|
+
};
|
|
113
|
+
function decodeRawTransaction(hex, network) {
|
|
114
|
+
const bjsTx = yacoin.Transaction.fromHex(hex);
|
|
115
|
+
const vin = bjsTx.ins.map((input) => {
|
|
116
|
+
return {
|
|
117
|
+
txid: Buffer.from(input.hash).reverse().toString('hex'),
|
|
118
|
+
vout: input.index,
|
|
119
|
+
scriptSig: {
|
|
120
|
+
asm: yacoin.script.toASM(input.script),
|
|
121
|
+
hex: input.script.toString('hex'),
|
|
122
|
+
},
|
|
123
|
+
sequence: input.sequence,
|
|
124
|
+
};
|
|
125
|
+
});
|
|
126
|
+
const vout = bjsTx.outs.map((output, n) => {
|
|
127
|
+
const type = classify.output(output.script);
|
|
128
|
+
const vout = {
|
|
129
|
+
value: output.value / 1e6,
|
|
130
|
+
n,
|
|
131
|
+
scriptPubKey: {
|
|
132
|
+
asm: yacoin.script.toASM(output.script),
|
|
133
|
+
hex: output.script.toString('hex'),
|
|
134
|
+
reqSigs: 1,
|
|
135
|
+
type: OUTPUT_TYPES_MAP[type] || type,
|
|
136
|
+
addresses: [],
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
try {
|
|
140
|
+
const address = yacoin.address.fromOutputScript(output.script, network);
|
|
141
|
+
vout.scriptPubKey.addresses.push(address);
|
|
142
|
+
}
|
|
143
|
+
catch (e) {
|
|
144
|
+
/** If output script is not parasable, we just skip it */
|
|
145
|
+
}
|
|
146
|
+
return vout;
|
|
147
|
+
});
|
|
148
|
+
return {
|
|
149
|
+
txid: bjsTx.getHash().reverse().toString('hex'),
|
|
150
|
+
hash: bjsTx.getHash().reverse().toString('hex'),
|
|
151
|
+
version: bjsTx.version,
|
|
152
|
+
time: bjsTx.time,
|
|
153
|
+
locktime: bjsTx.locktime,
|
|
154
|
+
size: bjsTx.byteLength(),
|
|
155
|
+
vsize: bjsTx.virtualSize(),
|
|
156
|
+
weight: bjsTx.weight(),
|
|
157
|
+
vin,
|
|
158
|
+
vout,
|
|
159
|
+
hex,
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
exports.decodeRawTransaction = decodeRawTransaction;
|
|
163
|
+
function normalizeTransactionObject(tx, fee, block) {
|
|
164
|
+
const value = tx.vout.reduce((p, n) => p.plus(new types_1.BigNumber(n.value).times(1e6)), new types_1.BigNumber(0));
|
|
165
|
+
const result = {
|
|
166
|
+
hash: tx.txid,
|
|
167
|
+
value: value.toNumber(),
|
|
168
|
+
_raw: tx,
|
|
169
|
+
confirmations: 0,
|
|
170
|
+
status: tx.confirmations > 0 ? types_1.TxStatus.Success : types_1.TxStatus.Pending,
|
|
171
|
+
};
|
|
172
|
+
if (fee) {
|
|
173
|
+
const feePrice = Math.round(fee / tx.vsize);
|
|
174
|
+
Object.assign(result, {
|
|
175
|
+
fee,
|
|
176
|
+
feePrice,
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
if (block) {
|
|
180
|
+
Object.assign(result, {
|
|
181
|
+
blockHash: block.hash,
|
|
182
|
+
blockNumber: block.number,
|
|
183
|
+
confirmations: tx.confirmations,
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
return result;
|
|
187
|
+
}
|
|
188
|
+
exports.normalizeTransactionObject = normalizeTransactionObject;
|
|
189
|
+
function getPubKeyHash(address, network) {
|
|
190
|
+
const outputScript = yacoin.address.toOutputScript(address, network);
|
|
191
|
+
const type = classify.output(outputScript);
|
|
192
|
+
if (type !== classify.types.P2PKH) {
|
|
193
|
+
throw new Error(`Yacoin swap doesn't support the address ${address} type of ${type}. Not possible to derive public key hash.`);
|
|
194
|
+
}
|
|
195
|
+
const base58 = yacoin.address.fromBase58Check(address);
|
|
196
|
+
return base58.hash;
|
|
197
|
+
}
|
|
198
|
+
exports.getPubKeyHash = getPubKeyHash;
|
|
199
|
+
function validateAddress(_address, network) {
|
|
200
|
+
const address = _address.toString();
|
|
201
|
+
if (typeof address !== 'string') {
|
|
202
|
+
throw new errors_1.InvalidAddressError(`Invalid address: ${address}`);
|
|
203
|
+
}
|
|
204
|
+
let pubKeyHash;
|
|
205
|
+
try {
|
|
206
|
+
pubKeyHash = getPubKeyHash(address, network);
|
|
207
|
+
}
|
|
208
|
+
catch (e) {
|
|
209
|
+
throw new errors_1.InvalidAddressError(`Invalid Address. Failed to parse: ${address}`);
|
|
210
|
+
}
|
|
211
|
+
if (!pubKeyHash) {
|
|
212
|
+
throw new errors_1.InvalidAddressError(`Invalid Address: ${address}`);
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
exports.validateAddress = validateAddress;
|
|
216
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../lib/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2CAAqD;AACrD,yCAA8E;AAC9E,6DAA+C;AAC/C,4EAA8D;AAC9D,4DAAoC;AACpC,2EAA6D;AAG7D,MAAM,YAAY,GAAG,CAAC,QAAQ,EAAE,aAAa,EAAE,QAAQ,CAAC,CAAC;AA+NrD,oCAAY;AA7NhB,SAAS,YAAY,CAAC,SAAiB,EAAE,UAAkB,EAAE,UAAkB;IAC/E,MAAM;IACN,mFAAmF;IACnF,gCAAgC;IAChC,sCAAsC;IACtC,iCAAiC;IACjC,kEAAkE;IAClE,YAAY;IACZ,uGAAuG;IACvG,qCAAqC;IACrC,iDAAiD;IACjD,ufAAuf;IACvf,6fAA6f;IAC7f,iBAAiB;IACjB,wCAAwC;IACxC,YAAY;IACZ,SAAS;IACT,oEAAoE;IACpE,YAAY;I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
+
import { PsbtInputTarget } from '../types';
|
|
4
|
+
export interface IYacoinWallet<T, S = any> extends Wallet<T, S> {
|
|
5
|
+
getChainProvider(): Chain<T>;
|
|
6
|
+
sendTransaction(txRequest: TransactionRequest): Promise<Transaction>;
|
|
7
|
+
updateTransactionFee(tx: string | Transaction, newFee: FeeType): Promise<Transaction>;
|
|
8
|
+
getWalletAddress(address: string): Promise<Address>;
|
|
9
|
+
signPSBT(data: string, inputs: PsbtInputTarget[]): Promise<string>;
|
|
10
|
+
signTx(transaction: string, hash: string, derivationPath: string, txfee: number): Promise<string>;
|
|
11
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IYacoinWallet.js","sourceRoot":"","sources":["../../../lib/wallet/IYacoinWallet.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Chain, Wallet } from '@yaswap/client';
|
|
3
|
+
import { Address, AddressType, Asset, Transaction, TransactionRequest } from '@yaswap/types';
|
|
4
|
+
import { BIP32Interface } from 'bip32';
|
|
5
|
+
import { payments } from '@yaswap/yacoinjs-lib';
|
|
6
|
+
import { YacoinBaseChainProvider } from '../chain/YacoinBaseChainProvider';
|
|
7
|
+
import { AddressType as YaAddressType, YacoinNetwork, YacoinWalletProviderOptions, Input, OutputTarget, P2SHInput, PsbtInputTarget, Transaction as YaTransaction, UTXO } from '../types';
|
|
8
|
+
import { CoinSelectTarget } from '../utils';
|
|
9
|
+
export declare enum AddressSearchType {
|
|
10
|
+
EXTERNAL = 0,
|
|
11
|
+
CHANGE = 1,
|
|
12
|
+
EXTERNAL_OR_CHANGE = 2
|
|
13
|
+
}
|
|
14
|
+
declare type DerivationCache = {
|
|
15
|
+
[index: string]: Address;
|
|
16
|
+
};
|
|
17
|
+
export declare abstract class YacoinBaseWalletProvider<T extends YacoinBaseChainProvider = any, S = any> extends Wallet<T, S> {
|
|
18
|
+
protected _baseDerivationPath: string;
|
|
19
|
+
protected _network: YacoinNetwork;
|
|
20
|
+
protected _addressType: YaAddressType;
|
|
21
|
+
protected _derivationCache: DerivationCache;
|
|
22
|
+
constructor(options: YacoinWalletProviderOptions, chainProvider?: Chain<T>);
|
|
23
|
+
protected onChainProviderUpdate(chainProvider: Chain<T>): void;
|
|
24
|
+
protected abstract baseDerivationNode(): Promise<BIP32Interface>;
|
|
25
|
+
protected abstract buildTransaction(targets: OutputTarget[], feePerByte?: number, fixedInputs?: Input[]): Promise<{
|
|
26
|
+
hex: string;
|
|
27
|
+
fee: number;
|
|
28
|
+
}>;
|
|
29
|
+
protected abstract buildSweepTransaction(externalChangeAddress: string, feePerByte?: number): Promise<{
|
|
30
|
+
hex: string;
|
|
31
|
+
fee: number;
|
|
32
|
+
}>;
|
|
33
|
+
abstract signPSBT(data: string, inputs: PsbtInputTarget[]): Promise<string>;
|
|
34
|
+
abstract signTx(transaction: string, hash: string, derivationPath: string, txfee: number): Promise<string>;
|
|
35
|
+
abstract signBatchP2SHTransaction(inputs: P2SHInput[], addresses: string, tx: any, lockTime?: number, segwit?: boolean): Promise<Buffer[]>;
|
|
36
|
+
getDerivationCache(): DerivationCache;
|
|
37
|
+
getUnusedAddress(change?: boolean, numAddressPerCall?: number): Promise<Address>;
|
|
38
|
+
getUsedAddresses(numAddressPerCall?: number): Promise<Address[]>;
|
|
39
|
+
getAddresses(startingIndex?: number, numAddresses?: number, change?: boolean): Promise<Address[]>;
|
|
40
|
+
sendTransaction(options: TransactionRequest): Promise<Transaction<YaTransaction>>;
|
|
41
|
+
sendBatchTransaction(transactions: TransactionRequest[]): Promise<Transaction<YaTransaction>[]>;
|
|
42
|
+
sendSweepTransaction(externalChangeAddress: AddressType, _asset: Asset, feePerByte: number): Promise<Transaction<YaTransaction>>;
|
|
43
|
+
updateTransactionFee(tx: Transaction<YaTransaction> | string, newFeePerByte: number): Promise<Transaction<YaTransaction>>;
|
|
44
|
+
getTotalFees(transactions: TransactionRequest[], max: boolean): Promise<any>;
|
|
45
|
+
protected _sendTransaction(transactions: OutputTarget[], feePerByte?: number): Promise<Transaction<YaTransaction>>;
|
|
46
|
+
protected findAddress(addresses: string[], change?: boolean): Promise<Address>;
|
|
47
|
+
getWalletAddress(address: string): Promise<Address>;
|
|
48
|
+
protected getDerivationPathAddress(path: string): Promise<Address>;
|
|
49
|
+
protected _getUsedUnusedAddresses(numAddressPerCall: number, addressType: AddressSearchType): Promise<{
|
|
50
|
+
usedAddresses: Address[];
|
|
51
|
+
unusedAddress: {
|
|
52
|
+
change: Address;
|
|
53
|
+
external: Address;
|
|
54
|
+
};
|
|
55
|
+
}>;
|
|
56
|
+
protected withCachedUtxos(func: () => any): Promise<any>;
|
|
57
|
+
protected getTotalFee(opts: TransactionRequest, max: boolean): Promise<number>;
|
|
58
|
+
protected getInputsForAmount(_targets: OutputTarget[], feePerByte?: number, fixedInputs?: Input[], numAddressPerCall?: number, sweep?: boolean): Promise<{
|
|
59
|
+
inputs: UTXO[];
|
|
60
|
+
change: CoinSelectTarget;
|
|
61
|
+
outputs: CoinSelectTarget[];
|
|
62
|
+
fee: number;
|
|
63
|
+
}>;
|
|
64
|
+
protected sendOptionsToOutputs(transactions: TransactionRequest[]): OutputTarget[];
|
|
65
|
+
protected getAddressFromPublicKey(publicKey: Buffer): string;
|
|
66
|
+
protected getPaymentVariantFromPublicKey(publicKey: Buffer): payments.Payment;
|
|
67
|
+
}
|
|
68
|
+
export {};
|