beignet 0.0.52 → 0.0.53
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/dist/index.d.ts +1188 -0
- package/package.json +2 -2
- package/src/electrum/index.ts +2 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,1188 @@
|
|
|
1
|
+
import { BIP32Interface } from 'bip32';
|
|
2
|
+
import { Network, Psbt } from 'bitcoinjs-lib';
|
|
3
|
+
import { ECPairInterface } from 'ecpair';
|
|
4
|
+
import { TLSSocket } from 'tls';
|
|
5
|
+
import { Server } from 'net';
|
|
6
|
+
|
|
7
|
+
type Result<T> = Ok<T> | Err<T>;
|
|
8
|
+
declare class Ok<T> {
|
|
9
|
+
readonly value: T;
|
|
10
|
+
constructor(value: T);
|
|
11
|
+
isOk(): this is Ok<T>;
|
|
12
|
+
isErr(): this is Err<T>;
|
|
13
|
+
}
|
|
14
|
+
declare class Err<T> {
|
|
15
|
+
readonly error: Error;
|
|
16
|
+
constructor(error: Error);
|
|
17
|
+
isOk(): this is Ok<T>;
|
|
18
|
+
isErr(): this is Err<T>;
|
|
19
|
+
}
|
|
20
|
+
declare const ok: <T>(value: T) => Ok<T>;
|
|
21
|
+
declare const err: <T>(error: Error | string) => Err<T>;
|
|
22
|
+
|
|
23
|
+
declare const getDefaultWalletData: () => IWalletData;
|
|
24
|
+
declare const getDefaultWalletDataKeys: () => (keyof IWalletData)[];
|
|
25
|
+
declare const getKeyValue: (key: string) => string;
|
|
26
|
+
declare const objectKeys: <Type extends object>(value: Type) => `${Exclude<keyof Type, symbol>}`[];
|
|
27
|
+
declare const formatKeyDerivationPath: ({ path, purpose, network, changeAddress, index, addressType }: {
|
|
28
|
+
path: IKeyDerivationPath | string;
|
|
29
|
+
purpose?: string | undefined;
|
|
30
|
+
network: EAvailableNetworks;
|
|
31
|
+
changeAddress?: boolean | undefined;
|
|
32
|
+
index?: string | undefined;
|
|
33
|
+
addressType?: EAddressType | undefined;
|
|
34
|
+
}) => Result<IKeyDerivationPathData>;
|
|
35
|
+
declare const getHighestUsedIndexFromTxHashes: ({ txHashes, addresses, changeAddresses, addressIndex, changeAddressIndex }: {
|
|
36
|
+
txHashes: ITxHashes[];
|
|
37
|
+
addresses: IAddresses;
|
|
38
|
+
changeAddresses: IAddresses;
|
|
39
|
+
addressIndex: IAddress;
|
|
40
|
+
changeAddressIndex: IAddress;
|
|
41
|
+
}) => Result<IIndexes>;
|
|
42
|
+
declare const isValidBech32mEncodedString: (address: string) => {
|
|
43
|
+
isValid: boolean;
|
|
44
|
+
network: EAvailableNetworks;
|
|
45
|
+
};
|
|
46
|
+
declare const availableNetworks: () => EAvailableNetworks[];
|
|
47
|
+
declare const reduceValue: <T>({ arr, value }: {
|
|
48
|
+
arr: T[];
|
|
49
|
+
value: keyof T;
|
|
50
|
+
}) => Result<number>;
|
|
51
|
+
declare const shuffleArray: <T>(array: T[]) => T[];
|
|
52
|
+
declare const getDataFallback: TGetData;
|
|
53
|
+
declare const decodeOpReturnMessage: (opReturn?: string) => string[];
|
|
54
|
+
declare const getSeed: (mnemonic: any, bip39Passphrase: any) => Buffer;
|
|
55
|
+
declare const getSeedHash: (seed: Buffer) => string;
|
|
56
|
+
declare const generateWalletId: (seed: Buffer) => string;
|
|
57
|
+
declare const getWalletDataStorageKey: (name: string, network: EAvailableNetworks, key: keyof IWalletData) => string;
|
|
58
|
+
declare const getStorageKeyValues: (storageKey: string) => {
|
|
59
|
+
walletName: string;
|
|
60
|
+
network: EAvailableNetworks;
|
|
61
|
+
value: keyof IWalletData;
|
|
62
|
+
};
|
|
63
|
+
declare const getTxFee: ({ satsPerByte, transactionByteCount }: {
|
|
64
|
+
satsPerByte: number;
|
|
65
|
+
transactionByteCount: number;
|
|
66
|
+
}) => number;
|
|
67
|
+
declare const filterAddressesForGapLimit: ({ addresses, index, gapLimitOptions }: {
|
|
68
|
+
addresses: IAddress[];
|
|
69
|
+
index: number;
|
|
70
|
+
gapLimitOptions: TGapLimitOptions;
|
|
71
|
+
}) => IAddress[];
|
|
72
|
+
declare const filterAddressesObjForGapLimit: ({ addresses, index, gapLimitOptions }: {
|
|
73
|
+
addresses: IAddresses;
|
|
74
|
+
index: number;
|
|
75
|
+
gapLimitOptions: TGapLimitOptions;
|
|
76
|
+
}) => IAddresses;
|
|
77
|
+
declare const filterAddressesObjForStartingIndex: ({ addresses, index }: {
|
|
78
|
+
addresses: IAddresses;
|
|
79
|
+
index: number;
|
|
80
|
+
}) => IAddresses;
|
|
81
|
+
declare const filterAddressesObjForSingleIndex: ({ addresses, addressIndex }: {
|
|
82
|
+
addresses: IAddresses;
|
|
83
|
+
addressIndex: number;
|
|
84
|
+
}) => IAddresses;
|
|
85
|
+
|
|
86
|
+
declare const getAddressFromScriptPubKey: (scriptPubKey: string, selectedNetwork: EAvailableNetworks) => string;
|
|
87
|
+
declare const getSha256: (str: string) => string;
|
|
88
|
+
declare const validateAddress: ({ address, network }: {
|
|
89
|
+
address: string;
|
|
90
|
+
network?: EAvailableNetworks | undefined;
|
|
91
|
+
}) => {
|
|
92
|
+
isValid: boolean;
|
|
93
|
+
network: EAvailableNetworks;
|
|
94
|
+
};
|
|
95
|
+
declare const getKeyDerivationPath: ({ addressType, network }: {
|
|
96
|
+
addressType: EAddressType;
|
|
97
|
+
network: EAvailableNetworks;
|
|
98
|
+
}) => Result<IKeyDerivationPath>;
|
|
99
|
+
declare const getScriptHash: ({ address, network }: {
|
|
100
|
+
address: string;
|
|
101
|
+
network: EAvailableNetworks;
|
|
102
|
+
}) => string;
|
|
103
|
+
declare const generateMnemonic: (strength?: number, rng?: ((size: number) => Buffer) | undefined, wordlist?: string[]) => string;
|
|
104
|
+
declare const validateMnemonic: (mnemonic?: string) => boolean;
|
|
105
|
+
declare const objectsMatch: (obj1: any, obj2: any) => boolean;
|
|
106
|
+
declare const getAddressFromKeyPair: ({ keyPair, addressType, network }: {
|
|
107
|
+
keyPair: BIP32Interface | ECPairInterface;
|
|
108
|
+
addressType: EAddressType;
|
|
109
|
+
network: Network;
|
|
110
|
+
}) => Result<IGetAddressesFromKeyPair>;
|
|
111
|
+
declare const getTapRootAddressFromPublicKey: ({ publicKey, network }: {
|
|
112
|
+
publicKey: Buffer;
|
|
113
|
+
network: Network;
|
|
114
|
+
}) => Result<{
|
|
115
|
+
address: string;
|
|
116
|
+
output: Buffer;
|
|
117
|
+
internalPubkey: Buffer;
|
|
118
|
+
}>;
|
|
119
|
+
declare const getAddressesFromPrivateKey: ({ privateKey, addrTypes, network }: {
|
|
120
|
+
privateKey: string;
|
|
121
|
+
addrTypes?: EAddressType[] | undefined;
|
|
122
|
+
network?: Network | undefined;
|
|
123
|
+
}) => Result<IGetAddressesFromPrivateKey>;
|
|
124
|
+
declare const sleep: (ms: any) => Promise<void>;
|
|
125
|
+
declare const getAddressIndexDiff: (addrIndex1?: number, addrIndex2?: number) => number;
|
|
126
|
+
declare const isPositive: (num: number) => boolean;
|
|
127
|
+
|
|
128
|
+
declare const defaultElectrumPorts: string[];
|
|
129
|
+
declare const getDefaultPort: (selectedNetwork: EAvailableNetworks, protocol: TProtocol) => number;
|
|
130
|
+
declare const getProtocolForPort: (port: string, network: EAvailableNetworks) => TProtocol | undefined;
|
|
131
|
+
declare const formatPeerData: (data: [string, string, [
|
|
132
|
+
string,
|
|
133
|
+
string,
|
|
134
|
+
string
|
|
135
|
+
]]) => Result<IFormattedPeerData>;
|
|
136
|
+
declare const getPeers: ({ selectedNetwork }: {
|
|
137
|
+
selectedNetwork: EAvailableNetworks;
|
|
138
|
+
}) => Promise<Result<IFormattedPeerData[]>>;
|
|
139
|
+
declare const electrumConnection: ElectrumConnectionPubSub;
|
|
140
|
+
declare const getElectrumNetwork: (network: EAvailableNetworks) => EElectrumNetworks;
|
|
141
|
+
|
|
142
|
+
declare const getKeyDerivationPathObject: ({ path, purpose, changeAddress, index, network }: {
|
|
143
|
+
path: string;
|
|
144
|
+
purpose?: string | undefined;
|
|
145
|
+
changeAddress?: boolean | undefined;
|
|
146
|
+
index?: string | undefined;
|
|
147
|
+
network: EAvailableNetworks;
|
|
148
|
+
}) => Result<IKeyDerivationPath>;
|
|
149
|
+
declare const getKeyDerivationPathString: ({ addressType, path, purpose, accountType, changeAddress, index, network }: {
|
|
150
|
+
addressType: EAddressType;
|
|
151
|
+
path?: IKeyDerivationPath | undefined;
|
|
152
|
+
purpose?: string | undefined;
|
|
153
|
+
accountType?: string | number | undefined;
|
|
154
|
+
changeAddress?: boolean | undefined;
|
|
155
|
+
index?: string | number | undefined;
|
|
156
|
+
network: EAvailableNetworks;
|
|
157
|
+
}) => Result<string>;
|
|
158
|
+
declare const getAddressTypeFromPath: (path: string | IKeyDerivationPath) => Result<EAddressType>;
|
|
159
|
+
|
|
160
|
+
declare const setReplaceByFee: ({ psbt, setRbf }: {
|
|
161
|
+
psbt: Psbt;
|
|
162
|
+
setRbf: boolean;
|
|
163
|
+
}) => void;
|
|
164
|
+
declare const parseOnChainPaymentRequest: (data: string, network?: EAvailableNetworks) => Result<{
|
|
165
|
+
address: string;
|
|
166
|
+
network: EAvailableNetworks;
|
|
167
|
+
sats: number;
|
|
168
|
+
message: string;
|
|
169
|
+
}>;
|
|
170
|
+
declare const constructByteCountParam: (addresses: string[], increaseAddressCount?: {
|
|
171
|
+
addrType: EAddressType;
|
|
172
|
+
count: number;
|
|
173
|
+
}[]) => TGetByteCountInputs | TGetByteCountOutputs;
|
|
174
|
+
declare const getByteCount: (inputs: TGetByteCountInputs, outputs: TGetByteCountOutputs, message?: string, minByteCount?: number) => number;
|
|
175
|
+
declare const removeDustOutputs: (outputs: IOutput[]) => IOutput[];
|
|
176
|
+
declare const validateTransaction: (transaction: ISendTransaction) => Result<string>;
|
|
177
|
+
declare const decodeRawTransaction: (hex: string, _network: EAvailableNetworks) => Result<TDecodeRawTx>;
|
|
178
|
+
declare const isP2trPrefix: (address: string) => boolean;
|
|
179
|
+
|
|
180
|
+
type TElectrumNetworks = 'bitcoin' | 'bitcoinTestnet' | 'bitcoinRegtest';
|
|
181
|
+
declare enum EElectrumNetworks {
|
|
182
|
+
bitcoin = "bitcoin",
|
|
183
|
+
bitcoinTestnet = "bitcoinTestnet",
|
|
184
|
+
bitcoinRegtest = "bitcoinRegtest"
|
|
185
|
+
}
|
|
186
|
+
type TConnectToElectrumRes = string;
|
|
187
|
+
interface IElectrumGetAddressBalanceRes extends IGetAddressBalanceRes {
|
|
188
|
+
error: boolean;
|
|
189
|
+
}
|
|
190
|
+
type TServer = {
|
|
191
|
+
host: string;
|
|
192
|
+
ssl: number;
|
|
193
|
+
tcp: number;
|
|
194
|
+
protocol: EProtocol;
|
|
195
|
+
};
|
|
196
|
+
type TProtocol = 'tcp' | 'ssl';
|
|
197
|
+
declare enum EProtocol {
|
|
198
|
+
tcp = "tcp",
|
|
199
|
+
ssl = "ssl"
|
|
200
|
+
}
|
|
201
|
+
declare enum EScanningStrategy {
|
|
202
|
+
all = "all",
|
|
203
|
+
gapLimit = "gapLimit",
|
|
204
|
+
startingIndex = "startingIndex",
|
|
205
|
+
singleIndex = "singleIndex"
|
|
206
|
+
}
|
|
207
|
+
interface IGetUtxosResponse {
|
|
208
|
+
utxos: IUtxo[];
|
|
209
|
+
balance: number;
|
|
210
|
+
}
|
|
211
|
+
type TUnspentAddressScriptHashData = {
|
|
212
|
+
[x: string]: IUtxo | IAddress;
|
|
213
|
+
};
|
|
214
|
+
type TTxResult = {
|
|
215
|
+
tx_hash: string;
|
|
216
|
+
height: number;
|
|
217
|
+
};
|
|
218
|
+
interface IGetAddressScriptHashesHistoryResponse {
|
|
219
|
+
data: TTxResponse[];
|
|
220
|
+
error: boolean;
|
|
221
|
+
id: number;
|
|
222
|
+
method: string;
|
|
223
|
+
network: string;
|
|
224
|
+
}
|
|
225
|
+
type TTxResponse = {
|
|
226
|
+
data: IAddress;
|
|
227
|
+
id: number;
|
|
228
|
+
jsonrpc: string;
|
|
229
|
+
param: string;
|
|
230
|
+
result: TTxResult[];
|
|
231
|
+
};
|
|
232
|
+
interface IGetAddressScriptHashBalances {
|
|
233
|
+
error: boolean;
|
|
234
|
+
data: Array<{
|
|
235
|
+
id: number;
|
|
236
|
+
jsonrpc: string;
|
|
237
|
+
result: {
|
|
238
|
+
confirmed: number;
|
|
239
|
+
unconfirmed: number;
|
|
240
|
+
};
|
|
241
|
+
param: string;
|
|
242
|
+
data: Record<string, unknown>;
|
|
243
|
+
}> | string;
|
|
244
|
+
id: number;
|
|
245
|
+
method: string;
|
|
246
|
+
network: EElectrumNetworks;
|
|
247
|
+
}
|
|
248
|
+
interface IGetAddressHistoryResponse extends TTxResult, IAddress {
|
|
249
|
+
}
|
|
250
|
+
interface IHeader {
|
|
251
|
+
height: number;
|
|
252
|
+
hash: string;
|
|
253
|
+
hex: string;
|
|
254
|
+
}
|
|
255
|
+
interface INewBlock {
|
|
256
|
+
height: number;
|
|
257
|
+
hex: string;
|
|
258
|
+
}
|
|
259
|
+
interface IGetHeaderResponse {
|
|
260
|
+
id: number;
|
|
261
|
+
error: boolean;
|
|
262
|
+
method: 'getHeader';
|
|
263
|
+
data: string;
|
|
264
|
+
network: EAvailableNetworks;
|
|
265
|
+
}
|
|
266
|
+
interface IGetTransactionsFromInputs {
|
|
267
|
+
error: boolean;
|
|
268
|
+
id: number;
|
|
269
|
+
method: string;
|
|
270
|
+
network: string;
|
|
271
|
+
data: ITransaction<{
|
|
272
|
+
tx_hash: string;
|
|
273
|
+
vout: number;
|
|
274
|
+
}>[];
|
|
275
|
+
}
|
|
276
|
+
interface ISubscribeToHeader {
|
|
277
|
+
data: {
|
|
278
|
+
height: number;
|
|
279
|
+
hex: string;
|
|
280
|
+
};
|
|
281
|
+
error: boolean;
|
|
282
|
+
id: string;
|
|
283
|
+
method: string;
|
|
284
|
+
}
|
|
285
|
+
interface ISubscribeToAddress {
|
|
286
|
+
data: {
|
|
287
|
+
id: number;
|
|
288
|
+
jsonrpc: string;
|
|
289
|
+
result: null;
|
|
290
|
+
};
|
|
291
|
+
error: boolean;
|
|
292
|
+
id: number;
|
|
293
|
+
method: string;
|
|
294
|
+
}
|
|
295
|
+
type TSubscribedReceive = [string, string];
|
|
296
|
+
interface IFormattedPeerData {
|
|
297
|
+
ip?: string;
|
|
298
|
+
host: string;
|
|
299
|
+
version?: string;
|
|
300
|
+
ssl: string | number;
|
|
301
|
+
tcp: string | number;
|
|
302
|
+
}
|
|
303
|
+
interface IPeerData {
|
|
304
|
+
host: string;
|
|
305
|
+
port: string;
|
|
306
|
+
protocol: TProtocol;
|
|
307
|
+
}
|
|
308
|
+
type ElectrumConnectionPubSub = {
|
|
309
|
+
publish: (isConnected: boolean) => void;
|
|
310
|
+
subscribe: (callback: (isConnected: boolean) => void) => ElectrumConnectionSubscription;
|
|
311
|
+
};
|
|
312
|
+
type ElectrumConnectionSubscription = {
|
|
313
|
+
remove(): void;
|
|
314
|
+
};
|
|
315
|
+
type TGetAddressHistory = {
|
|
316
|
+
txid: string;
|
|
317
|
+
height: number;
|
|
318
|
+
};
|
|
319
|
+
|
|
320
|
+
interface ICreateTransaction {
|
|
321
|
+
transactionData?: ISendTransaction;
|
|
322
|
+
shuffleOutputs?: boolean;
|
|
323
|
+
}
|
|
324
|
+
interface IAddInput {
|
|
325
|
+
psbt: Psbt;
|
|
326
|
+
keyPair: BIP32Interface | ECPairInterface;
|
|
327
|
+
input: IUtxo;
|
|
328
|
+
}
|
|
329
|
+
interface ITargets {
|
|
330
|
+
value: number;
|
|
331
|
+
index: number;
|
|
332
|
+
address?: string;
|
|
333
|
+
script?: Buffer;
|
|
334
|
+
}
|
|
335
|
+
interface ISetupTransaction {
|
|
336
|
+
inputTxHashes?: string[];
|
|
337
|
+
utxos?: IUtxo[];
|
|
338
|
+
rbf?: boolean;
|
|
339
|
+
satsPerByte?: number;
|
|
340
|
+
outputs?: IOutput[];
|
|
341
|
+
}
|
|
342
|
+
declare enum EFeeId {
|
|
343
|
+
fast = "fast",
|
|
344
|
+
normal = "normal",
|
|
345
|
+
slow = "slow",
|
|
346
|
+
custom = "custom",
|
|
347
|
+
none = "none"
|
|
348
|
+
}
|
|
349
|
+
type TSetupTransactionResponse = Result<Partial<ISendTransaction>>;
|
|
350
|
+
type TDecodeRawTx = {
|
|
351
|
+
txid: string;
|
|
352
|
+
tx_hash: string;
|
|
353
|
+
size: number;
|
|
354
|
+
vsize: number;
|
|
355
|
+
weight: number;
|
|
356
|
+
version: number;
|
|
357
|
+
locktime: number;
|
|
358
|
+
vin: IVin[];
|
|
359
|
+
vout: IVout[];
|
|
360
|
+
};
|
|
361
|
+
type TGetTotalFeeObj = {
|
|
362
|
+
totalFee: number;
|
|
363
|
+
transactionByteCount: number;
|
|
364
|
+
satsPerByte: number;
|
|
365
|
+
maxSatPerByte: number;
|
|
366
|
+
};
|
|
367
|
+
type TGapLimitOptions = {
|
|
368
|
+
lookAhead: number;
|
|
369
|
+
lookBehind: number;
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
type TAvailableNetworks = 'bitcoin' | 'testnet' | 'regtest';
|
|
373
|
+
type TAddressType = 'p2wpkh' | 'p2sh' | 'p2pkh';
|
|
374
|
+
type TAddressLabel = 'bech32' | 'segwit' | 'legacy';
|
|
375
|
+
type TKeyDerivationPurpose = '84' | '49' | '44' | string;
|
|
376
|
+
type TKeyDerivationCoinType = '0' | '1' | string;
|
|
377
|
+
type TKeyDerivationAccount = '0' | string;
|
|
378
|
+
type TKeyDerivationChange = '0' | '1';
|
|
379
|
+
type TKeyDerivationIndex = string;
|
|
380
|
+
type TAddressTypes = {
|
|
381
|
+
[key in EAddressType]: Readonly<IAddressTypeData>;
|
|
382
|
+
};
|
|
383
|
+
declare enum EAvailableNetworks {
|
|
384
|
+
bitcoin = "bitcoin",
|
|
385
|
+
mainnet = "bitcoin",
|
|
386
|
+
bitcoinMainnet = "bitcoin",
|
|
387
|
+
testnet = "testnet",
|
|
388
|
+
bitcoinTestnet = "testnet",
|
|
389
|
+
regtest = "regtest",
|
|
390
|
+
bitcoinRegtest = "regtest"
|
|
391
|
+
}
|
|
392
|
+
declare enum EAddressType {
|
|
393
|
+
p2wpkh = "p2wpkh",
|
|
394
|
+
p2sh = "p2sh",
|
|
395
|
+
p2pkh = "p2pkh",
|
|
396
|
+
p2tr = "p2tr"
|
|
397
|
+
}
|
|
398
|
+
declare enum EPaymentType {
|
|
399
|
+
sent = "sent",
|
|
400
|
+
received = "received"
|
|
401
|
+
}
|
|
402
|
+
type TAddressTypeContent<T> = {
|
|
403
|
+
[key in EAddressType]: T;
|
|
404
|
+
};
|
|
405
|
+
interface IAddressTypeData {
|
|
406
|
+
type: EAddressType;
|
|
407
|
+
path: string;
|
|
408
|
+
name: string;
|
|
409
|
+
shortName: string;
|
|
410
|
+
description: string;
|
|
411
|
+
example: string;
|
|
412
|
+
}
|
|
413
|
+
interface IUtxo {
|
|
414
|
+
address: string;
|
|
415
|
+
index: number;
|
|
416
|
+
path: string;
|
|
417
|
+
scriptHash: string;
|
|
418
|
+
height: number;
|
|
419
|
+
tx_hash: string;
|
|
420
|
+
tx_pos: number;
|
|
421
|
+
value: number;
|
|
422
|
+
publicKey: string;
|
|
423
|
+
keyPair?: BIP32Interface | ECPairInterface;
|
|
424
|
+
}
|
|
425
|
+
interface IVin {
|
|
426
|
+
scriptSig: {
|
|
427
|
+
asm: string;
|
|
428
|
+
hex: string;
|
|
429
|
+
};
|
|
430
|
+
sequence: number;
|
|
431
|
+
txid: string;
|
|
432
|
+
txinwitness: string[];
|
|
433
|
+
vout: number;
|
|
434
|
+
}
|
|
435
|
+
interface IFormattedTransaction {
|
|
436
|
+
address: string;
|
|
437
|
+
height: number;
|
|
438
|
+
scriptHash: string;
|
|
439
|
+
totalInputValue: number;
|
|
440
|
+
matchedInputValue: number;
|
|
441
|
+
totalOutputValue: number;
|
|
442
|
+
matchedOutputValue: number;
|
|
443
|
+
fee: number;
|
|
444
|
+
satsPerByte: number;
|
|
445
|
+
type: EPaymentType;
|
|
446
|
+
value: number;
|
|
447
|
+
txid: string;
|
|
448
|
+
messages: string[];
|
|
449
|
+
vin: IVin[];
|
|
450
|
+
timestamp: number;
|
|
451
|
+
confirmTimestamp?: number;
|
|
452
|
+
exists?: boolean;
|
|
453
|
+
rbf?: boolean;
|
|
454
|
+
vsize: number;
|
|
455
|
+
}
|
|
456
|
+
interface IFormattedTransactions {
|
|
457
|
+
[key: string]: IFormattedTransaction;
|
|
458
|
+
}
|
|
459
|
+
interface IOutput {
|
|
460
|
+
address: string;
|
|
461
|
+
value: number;
|
|
462
|
+
index: number;
|
|
463
|
+
}
|
|
464
|
+
declare enum EBoostType {
|
|
465
|
+
rbf = "rbf",
|
|
466
|
+
cpfp = "cpfp"
|
|
467
|
+
}
|
|
468
|
+
interface ISendTransaction {
|
|
469
|
+
outputs: IOutput[];
|
|
470
|
+
inputs: IUtxo[];
|
|
471
|
+
changeAddress: string;
|
|
472
|
+
fiatAmount: number;
|
|
473
|
+
fee: number;
|
|
474
|
+
satsPerByte: number;
|
|
475
|
+
selectedFeeId: EFeeId;
|
|
476
|
+
message: string;
|
|
477
|
+
label: string;
|
|
478
|
+
rbf: boolean;
|
|
479
|
+
boostType: EBoostType;
|
|
480
|
+
minFee: number;
|
|
481
|
+
max: boolean;
|
|
482
|
+
tags: string[];
|
|
483
|
+
slashTagsUrl?: string;
|
|
484
|
+
lightningInvoice?: string;
|
|
485
|
+
}
|
|
486
|
+
interface IAddresses {
|
|
487
|
+
[scriptHash: string]: IAddress;
|
|
488
|
+
}
|
|
489
|
+
interface IAddress {
|
|
490
|
+
index: number;
|
|
491
|
+
path: string;
|
|
492
|
+
address: string;
|
|
493
|
+
scriptHash: string;
|
|
494
|
+
publicKey: string;
|
|
495
|
+
}
|
|
496
|
+
interface IWalletData {
|
|
497
|
+
id: string;
|
|
498
|
+
addressType: EAddressType;
|
|
499
|
+
header: IHeader;
|
|
500
|
+
addresses: TAddressTypeContent<IAddresses>;
|
|
501
|
+
changeAddresses: TAddressTypeContent<IAddresses>;
|
|
502
|
+
addressIndex: TAddressTypeContent<IAddress>;
|
|
503
|
+
changeAddressIndex: TAddressTypeContent<IAddress>;
|
|
504
|
+
lastUsedAddressIndex: TAddressTypeContent<IAddress>;
|
|
505
|
+
lastUsedChangeAddressIndex: TAddressTypeContent<IAddress>;
|
|
506
|
+
utxos: IUtxo[];
|
|
507
|
+
blacklistedUtxos: IUtxo[];
|
|
508
|
+
unconfirmedTransactions: IFormattedTransactions;
|
|
509
|
+
transactions: IFormattedTransactions;
|
|
510
|
+
boostedTransactions: IBoostedTransactions;
|
|
511
|
+
transaction: ISendTransaction;
|
|
512
|
+
balance: number;
|
|
513
|
+
selectedFeeId: EFeeId;
|
|
514
|
+
feeEstimates: IOnchainFees;
|
|
515
|
+
}
|
|
516
|
+
type TWalletDataKeys = keyof IWalletData;
|
|
517
|
+
type TGetData = <K extends keyof IWalletData>(key: string) => Promise<Result<IWalletData[K]>>;
|
|
518
|
+
type TSetData = <K extends keyof IWalletData>(key: string, value: IWalletData[K]) => Promise<Result<boolean>>;
|
|
519
|
+
interface IWallet {
|
|
520
|
+
mnemonic: string;
|
|
521
|
+
id?: string;
|
|
522
|
+
name?: string;
|
|
523
|
+
passphrase?: string;
|
|
524
|
+
network?: EAvailableNetworks;
|
|
525
|
+
addressType?: EAddressType;
|
|
526
|
+
data?: IWalletData;
|
|
527
|
+
storage?: TStorage;
|
|
528
|
+
electrumOptions?: {
|
|
529
|
+
servers?: TServer | TServer[];
|
|
530
|
+
tls?: TLSSocket;
|
|
531
|
+
net?: Server;
|
|
532
|
+
batchLimit?: number;
|
|
533
|
+
batchDelay?: number;
|
|
534
|
+
};
|
|
535
|
+
remainOffline?: boolean;
|
|
536
|
+
onMessage?: TOnMessage;
|
|
537
|
+
customGetAddress?: (data: ICustomGetAddress) => Promise<Result<IGetAddressResponse>>;
|
|
538
|
+
customGetScriptHash?: (data: ICustomGetScriptHash) => Promise<string>;
|
|
539
|
+
rbf?: boolean;
|
|
540
|
+
selectedFeeId?: EFeeId;
|
|
541
|
+
disableMessages?: boolean;
|
|
542
|
+
disableMessagesOnCreate?: boolean;
|
|
543
|
+
addressTypesToMonitor?: EAddressType[];
|
|
544
|
+
gapLimitOptions?: TGapLimitOptions;
|
|
545
|
+
addressLookBehind?: number;
|
|
546
|
+
addressLookAhead?: number;
|
|
547
|
+
}
|
|
548
|
+
interface IAddressData {
|
|
549
|
+
path: string;
|
|
550
|
+
type: 'p2wpkh' | 'p2sh' | 'p2pkh';
|
|
551
|
+
label: string;
|
|
552
|
+
}
|
|
553
|
+
interface IAddressType {
|
|
554
|
+
[key: string]: IAddressData;
|
|
555
|
+
}
|
|
556
|
+
interface IKeyDerivationPath {
|
|
557
|
+
purpose?: TKeyDerivationPurpose;
|
|
558
|
+
coinType?: TKeyDerivationCoinType;
|
|
559
|
+
account?: TKeyDerivationAccount;
|
|
560
|
+
change?: TKeyDerivationChange;
|
|
561
|
+
index?: TKeyDerivationIndex;
|
|
562
|
+
}
|
|
563
|
+
interface IGetDerivationPath extends IKeyDerivationPath {
|
|
564
|
+
addressType?: EAddressType;
|
|
565
|
+
}
|
|
566
|
+
interface IGetAddress {
|
|
567
|
+
index?: TKeyDerivationIndex;
|
|
568
|
+
changeAddress?: boolean;
|
|
569
|
+
addressType?: EAddressType;
|
|
570
|
+
}
|
|
571
|
+
interface ICustomGetAddress {
|
|
572
|
+
path: string;
|
|
573
|
+
type: EAddressType;
|
|
574
|
+
selectedNetwork: EElectrumNetworks;
|
|
575
|
+
}
|
|
576
|
+
interface ICustomGetScriptHash {
|
|
577
|
+
address: string;
|
|
578
|
+
selectedNetwork: EElectrumNetworks;
|
|
579
|
+
}
|
|
580
|
+
interface IGetAddressByPath {
|
|
581
|
+
path: string;
|
|
582
|
+
addressType?: EAddressType;
|
|
583
|
+
}
|
|
584
|
+
interface IGetAddressBalanceRes {
|
|
585
|
+
confirmed: number;
|
|
586
|
+
unconfirmed: number;
|
|
587
|
+
}
|
|
588
|
+
interface IGenerateAddresses {
|
|
589
|
+
addressAmount?: number;
|
|
590
|
+
changeAddressAmount?: number;
|
|
591
|
+
addressIndex?: number;
|
|
592
|
+
changeAddressIndex?: number;
|
|
593
|
+
keyDerivationPath?: IKeyDerivationPath;
|
|
594
|
+
addressType?: EAddressType;
|
|
595
|
+
saveAddresses?: boolean;
|
|
596
|
+
}
|
|
597
|
+
interface IKeyDerivationPathData {
|
|
598
|
+
pathString: string;
|
|
599
|
+
pathObject: IKeyDerivationPath;
|
|
600
|
+
}
|
|
601
|
+
interface IGenerateAddressesResponse {
|
|
602
|
+
addresses: IAddresses;
|
|
603
|
+
changeAddresses: IAddresses;
|
|
604
|
+
}
|
|
605
|
+
interface IGetAddressResponse {
|
|
606
|
+
address: string;
|
|
607
|
+
path: string;
|
|
608
|
+
publicKey: string;
|
|
609
|
+
}
|
|
610
|
+
interface IGetAddressesFromPrivateKey {
|
|
611
|
+
keyPair: BIP32Interface | ECPairInterface;
|
|
612
|
+
addresses: IGetAddressesFromKeyPair[];
|
|
613
|
+
}
|
|
614
|
+
interface IGetAddressesFromKeyPair {
|
|
615
|
+
address: string;
|
|
616
|
+
publicKey: string;
|
|
617
|
+
}
|
|
618
|
+
interface IGetNextAvailableAddressResponse {
|
|
619
|
+
addressIndex: IAddress;
|
|
620
|
+
lastUsedAddressIndex: IAddress;
|
|
621
|
+
changeAddressIndex: IAddress;
|
|
622
|
+
lastUsedChangeAddressIndex: IAddress;
|
|
623
|
+
}
|
|
624
|
+
interface ITxHashes extends TTxResult {
|
|
625
|
+
scriptHash: string;
|
|
626
|
+
}
|
|
627
|
+
interface IIndexes {
|
|
628
|
+
addressIndex: IAddress;
|
|
629
|
+
changeAddressIndex: IAddress;
|
|
630
|
+
foundAddressIndex: boolean;
|
|
631
|
+
foundChangeAddressIndex: boolean;
|
|
632
|
+
}
|
|
633
|
+
interface ITxHash {
|
|
634
|
+
tx_hash: string;
|
|
635
|
+
}
|
|
636
|
+
interface IGetTransactions {
|
|
637
|
+
error: boolean;
|
|
638
|
+
id: number;
|
|
639
|
+
method: string;
|
|
640
|
+
network: string;
|
|
641
|
+
data: ITransaction<IUtxo>[];
|
|
642
|
+
}
|
|
643
|
+
interface ITransaction<T> {
|
|
644
|
+
id: number;
|
|
645
|
+
jsonrpc: string;
|
|
646
|
+
param: string;
|
|
647
|
+
data: T;
|
|
648
|
+
result: {
|
|
649
|
+
blockhash: string;
|
|
650
|
+
confirmations: number;
|
|
651
|
+
hash: string;
|
|
652
|
+
hex: string;
|
|
653
|
+
locktime: number;
|
|
654
|
+
size: number;
|
|
655
|
+
txid: string;
|
|
656
|
+
version: number;
|
|
657
|
+
vin: IVin[];
|
|
658
|
+
vout: IVout[];
|
|
659
|
+
vsize: number;
|
|
660
|
+
weight: number;
|
|
661
|
+
blocktime?: number;
|
|
662
|
+
time?: number;
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
interface IVout {
|
|
666
|
+
n: number;
|
|
667
|
+
scriptPubKey: {
|
|
668
|
+
addresses?: string[];
|
|
669
|
+
address?: string;
|
|
670
|
+
asm: string;
|
|
671
|
+
hex: string;
|
|
672
|
+
reqSigs?: number;
|
|
673
|
+
type?: string;
|
|
674
|
+
};
|
|
675
|
+
value: number;
|
|
676
|
+
}
|
|
677
|
+
type TProcessUnconfirmedTransactions = {
|
|
678
|
+
unconfirmedTxs: IFormattedTransactions;
|
|
679
|
+
outdatedTxs: IUtxo[];
|
|
680
|
+
ghostTxs: string[];
|
|
681
|
+
};
|
|
682
|
+
declare enum EUnit {
|
|
683
|
+
satoshi = "satoshi",
|
|
684
|
+
BTC = "BTC",
|
|
685
|
+
fiat = "fiat"
|
|
686
|
+
}
|
|
687
|
+
type InputData = {
|
|
688
|
+
[key: string]: {
|
|
689
|
+
addresses: string[];
|
|
690
|
+
value: number;
|
|
691
|
+
};
|
|
692
|
+
};
|
|
693
|
+
type TGetByteCountInputs = {
|
|
694
|
+
[key in TGetByteCountInput]?: number;
|
|
695
|
+
};
|
|
696
|
+
type TGetByteCountOutputs = {
|
|
697
|
+
[key in TGetByteCountOutput]?: number;
|
|
698
|
+
};
|
|
699
|
+
type TGetByteCountInput = `MULTISIG-P2SH:${number}-${number}` | `MULTISIG-P2WSH:${number}-${number}` | `MULTISIG-P2SH-P2WSH:${number}-${number}` | 'P2SH-P2WPKH' | 'P2PKH' | 'p2pkh' | 'P2WPKH' | 'p2wpkh' | 'P2SH' | 'p2sh' | 'P2TR' | 'p2tr';
|
|
700
|
+
type TGetByteCountOutput = 'P2SH' | 'P2PKH' | 'P2WPKH' | 'P2WSH' | 'p2wpkh' | 'p2sh' | 'p2pkh' | 'P2TR' | 'p2tr';
|
|
701
|
+
interface IGetFeeEstimatesResponse {
|
|
702
|
+
fastestFee: number;
|
|
703
|
+
halfHourFee: number;
|
|
704
|
+
hourFee: number;
|
|
705
|
+
minimumFee: number;
|
|
706
|
+
}
|
|
707
|
+
interface IOnchainFees {
|
|
708
|
+
fast: number;
|
|
709
|
+
normal: number;
|
|
710
|
+
slow: number;
|
|
711
|
+
minimum: number;
|
|
712
|
+
timestamp: number;
|
|
713
|
+
}
|
|
714
|
+
type TMessageDataMap = {
|
|
715
|
+
newBlock: INewBlock;
|
|
716
|
+
transactionReceived: TTransactionMessage;
|
|
717
|
+
transactionConfirmed: TTransactionMessage;
|
|
718
|
+
transactionSent: TTransactionMessage;
|
|
719
|
+
reorg: IUtxo[];
|
|
720
|
+
rbf: string[];
|
|
721
|
+
connectedToElectrum: boolean;
|
|
722
|
+
};
|
|
723
|
+
type TTransactionMessage = {
|
|
724
|
+
transaction: IFormattedTransaction;
|
|
725
|
+
};
|
|
726
|
+
type ObjectKeys<T extends object> = `${Exclude<keyof T, symbol>}`;
|
|
727
|
+
type TOnMessage = <K extends keyof TMessageDataMap>(key: K, data: TMessageDataMap[K]) => void;
|
|
728
|
+
type TMessageKeys = keyof TMessageDataMap;
|
|
729
|
+
interface ISendTx {
|
|
730
|
+
address: string;
|
|
731
|
+
amount: number;
|
|
732
|
+
message?: string;
|
|
733
|
+
}
|
|
734
|
+
interface ISend {
|
|
735
|
+
txs: ISendTx | ISendTx[];
|
|
736
|
+
satsPerByte?: number;
|
|
737
|
+
}
|
|
738
|
+
type TAddressIndexInfo = {
|
|
739
|
+
addressIndex: IAddress;
|
|
740
|
+
changeAddressIndex: IAddress;
|
|
741
|
+
lastUsedAddressIndex: IAddress;
|
|
742
|
+
lastUsedChangeAddressIndex: IAddress;
|
|
743
|
+
};
|
|
744
|
+
type TStorage = {
|
|
745
|
+
getData?: TGetData;
|
|
746
|
+
setData?: TSetData;
|
|
747
|
+
};
|
|
748
|
+
interface IRbfData {
|
|
749
|
+
outputs: IOutput[];
|
|
750
|
+
balance: number;
|
|
751
|
+
addressType: EAddressType;
|
|
752
|
+
fee: number;
|
|
753
|
+
inputs: IUtxo[];
|
|
754
|
+
message: string;
|
|
755
|
+
}
|
|
756
|
+
interface IBoostedTransaction {
|
|
757
|
+
parentTransactions: string[];
|
|
758
|
+
childTransaction: string;
|
|
759
|
+
type: EBoostType;
|
|
760
|
+
fee: number;
|
|
761
|
+
}
|
|
762
|
+
interface IBoostedTransactions {
|
|
763
|
+
[txId: string]: IBoostedTransaction;
|
|
764
|
+
}
|
|
765
|
+
interface IPrivateKeyInfo {
|
|
766
|
+
balance: number;
|
|
767
|
+
utxos: IUtxo[];
|
|
768
|
+
keyPair: ECPairInterface | BIP32Interface;
|
|
769
|
+
addresses: IGetAddressesFromKeyPair[];
|
|
770
|
+
}
|
|
771
|
+
interface ISweepPrivateKey {
|
|
772
|
+
privateKey: string;
|
|
773
|
+
toAddress: string;
|
|
774
|
+
satsPerByte?: number;
|
|
775
|
+
broadcast?: boolean;
|
|
776
|
+
combineWithWalletUtxos?: boolean;
|
|
777
|
+
}
|
|
778
|
+
interface ISweepPrivateKeyRes {
|
|
779
|
+
balance: number;
|
|
780
|
+
id: string;
|
|
781
|
+
hex: string;
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
declare class Electrum {
|
|
785
|
+
private readonly _wallet;
|
|
786
|
+
private sendMessage;
|
|
787
|
+
private latestConnectionState;
|
|
788
|
+
private connectionPollingInterval;
|
|
789
|
+
private tls;
|
|
790
|
+
private net;
|
|
791
|
+
servers?: TServer | TServer[];
|
|
792
|
+
network: EAvailableNetworks;
|
|
793
|
+
electrumNetwork: EElectrumNetworks;
|
|
794
|
+
connectedToElectrum: boolean;
|
|
795
|
+
onReceive?: (data: unknown) => void;
|
|
796
|
+
batchLimit: number;
|
|
797
|
+
batchDelay: number;
|
|
798
|
+
constructor({ wallet, servers, network, onReceive, tls: _tls, net: _net, batchLimit, batchDelay }: {
|
|
799
|
+
wallet: Wallet;
|
|
800
|
+
servers?: TServer | TServer[];
|
|
801
|
+
network: EAvailableNetworks;
|
|
802
|
+
onReceive?: (data: unknown) => void;
|
|
803
|
+
tls?: TLSSocket;
|
|
804
|
+
net?: Server;
|
|
805
|
+
batchLimit?: number;
|
|
806
|
+
batchDelay?: number;
|
|
807
|
+
});
|
|
808
|
+
get wallet(): Wallet;
|
|
809
|
+
connectToElectrum({ network, servers, disableRegtestCheck }: {
|
|
810
|
+
network?: EAvailableNetworks;
|
|
811
|
+
servers?: TServer | TServer[];
|
|
812
|
+
disableRegtestCheck?: boolean;
|
|
813
|
+
}): Promise<Result<TConnectToElectrumRes>>;
|
|
814
|
+
isConnected(): Promise<boolean>;
|
|
815
|
+
getAddressBalance(scriptHash: string): Promise<IElectrumGetAddressBalanceRes>;
|
|
816
|
+
getAddressScriptHashBalances(scriptHashes: string[]): Promise<IGetAddressScriptHashBalances>;
|
|
817
|
+
getConnectedPeer(): Promise<Result<IPeerData>>;
|
|
818
|
+
listUnspentAddressScriptHashes({ addresses }: {
|
|
819
|
+
addresses: TUnspentAddressScriptHashData;
|
|
820
|
+
}): Promise<Result<IGetUtxosResponse>>;
|
|
821
|
+
getAddressHistory({ scriptHashes, scanAllAddresses }: {
|
|
822
|
+
scriptHashes?: IAddress[];
|
|
823
|
+
scanAllAddresses?: boolean;
|
|
824
|
+
}): Promise<Result<IGetAddressHistoryResponse[]>>;
|
|
825
|
+
getScriptPubKeyHistory(scriptPubkey: string): Promise<TGetAddressHistory[]>;
|
|
826
|
+
getUtxos({ scanningStrategy, addressIndex, changeAddressIndex, addressTypesToCheck }: {
|
|
827
|
+
scanningStrategy?: EScanningStrategy;
|
|
828
|
+
addressIndex?: number;
|
|
829
|
+
changeAddressIndex?: number;
|
|
830
|
+
addressTypesToCheck?: EAddressType[];
|
|
831
|
+
}): Promise<Result<IGetUtxosResponse>>;
|
|
832
|
+
getTransactions({ txHashes }: {
|
|
833
|
+
txHashes: ITxHash[];
|
|
834
|
+
}): Promise<Result<IGetTransactions>>;
|
|
835
|
+
transactionExists(txData: ITransaction<IUtxo>): boolean;
|
|
836
|
+
getBlockHex({ height }: {
|
|
837
|
+
height?: number;
|
|
838
|
+
}): Promise<Result<string>>;
|
|
839
|
+
getBlockHashFromHex({ blockHex }: {
|
|
840
|
+
blockHex?: string;
|
|
841
|
+
}): string;
|
|
842
|
+
getBlockHeader(): IHeader;
|
|
843
|
+
getTransactionsFromInputs({ txHashes }: {
|
|
844
|
+
txHashes: ITxHash[];
|
|
845
|
+
}): Promise<Result<IGetTransactionsFromInputs>>;
|
|
846
|
+
getTransactionMerkle({ tx_hash, height }: {
|
|
847
|
+
tx_hash: string;
|
|
848
|
+
height: number;
|
|
849
|
+
}): Promise<{
|
|
850
|
+
merkle: string[];
|
|
851
|
+
block_height: number;
|
|
852
|
+
pos: number;
|
|
853
|
+
}>;
|
|
854
|
+
subscribeToHeader(): Promise<Result<IHeader>>;
|
|
855
|
+
subscribeToAddresses({ scriptHashes, onReceive }?: {
|
|
856
|
+
scriptHashes?: string[];
|
|
857
|
+
onReceive?: (data: TSubscribedReceive) => void;
|
|
858
|
+
}): Promise<Result<string>>;
|
|
859
|
+
broadcastTransaction({ rawTx, subscribeToOutputAddress }: {
|
|
860
|
+
rawTx: string;
|
|
861
|
+
subscribeToOutputAddress?: boolean;
|
|
862
|
+
}): Promise<Result<string>>;
|
|
863
|
+
private checkConnection;
|
|
864
|
+
private publishConnectionChange;
|
|
865
|
+
disconnect(): Promise<void>;
|
|
866
|
+
startConnectionPolling(): void;
|
|
867
|
+
stopConnectionPolling(): void;
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
declare class Transaction {
|
|
871
|
+
private _data;
|
|
872
|
+
private readonly _wallet;
|
|
873
|
+
constructor({ wallet }: {
|
|
874
|
+
wallet: Wallet;
|
|
875
|
+
});
|
|
876
|
+
get data(): ISendTransaction;
|
|
877
|
+
setupTransaction({ inputTxHashes, utxos, rbf, satsPerByte, outputs }?: ISetupTransaction): Promise<TSetupTransactionResponse>;
|
|
878
|
+
resetSendTransaction(): Promise<Result<string>>;
|
|
879
|
+
removeBlackListedUtxos(utxos?: IUtxo[]): IUtxo[];
|
|
880
|
+
getTotalFee: ({ satsPerByte, message, transaction, fundingLightning }: {
|
|
881
|
+
satsPerByte: number;
|
|
882
|
+
message?: string | undefined;
|
|
883
|
+
transaction?: Partial<ISendTransaction> | undefined;
|
|
884
|
+
fundingLightning?: boolean | undefined;
|
|
885
|
+
}) => number;
|
|
886
|
+
getTotalFeeObj: ({ satsPerByte, message, transaction, fundingLightning }?: {
|
|
887
|
+
satsPerByte?: number | undefined;
|
|
888
|
+
message?: string | undefined;
|
|
889
|
+
transaction?: Partial<ISendTransaction> | undefined;
|
|
890
|
+
fundingLightning?: boolean | undefined;
|
|
891
|
+
}) => Result<TGetTotalFeeObj>;
|
|
892
|
+
getMaxSatsPerByte: ({ transactionByteCount, balance }: {
|
|
893
|
+
transactionByteCount: number;
|
|
894
|
+
balance?: number | undefined;
|
|
895
|
+
}) => number;
|
|
896
|
+
createTransaction: ({ transactionData, shuffleOutputs }?: ICreateTransaction) => Promise<Result<{
|
|
897
|
+
id: string;
|
|
898
|
+
hex: string;
|
|
899
|
+
}>>;
|
|
900
|
+
getTransactionInputValue: ({ inputs }: {
|
|
901
|
+
inputs?: IUtxo[] | undefined;
|
|
902
|
+
}) => number;
|
|
903
|
+
signPsbt: ({ psbt, bip32Interface }: {
|
|
904
|
+
psbt: Psbt;
|
|
905
|
+
bip32Interface: BIP32Interface;
|
|
906
|
+
}) => Promise<Result<Psbt>>;
|
|
907
|
+
createPsbtFromTransactionData: ({ transactionData, bip32Interface, shuffleTargets }: {
|
|
908
|
+
transactionData: ISendTransaction;
|
|
909
|
+
bip32Interface?: BIP32Interface | undefined;
|
|
910
|
+
shuffleTargets?: boolean | undefined;
|
|
911
|
+
}) => Promise<Result<Psbt>>;
|
|
912
|
+
addInput: ({ psbt, keyPair, input }: IAddInput) => Promise<Result<string>>;
|
|
913
|
+
addExternalInputs({ inputs, keyPair }: {
|
|
914
|
+
inputs: IUtxo[];
|
|
915
|
+
keyPair: BIP32Interface | ECPairInterface;
|
|
916
|
+
}): Result<IUtxo[]>;
|
|
917
|
+
addOutput: ({ address, value, index }: IOutput) => Promise<Result<string>>;
|
|
918
|
+
getTransactionOutputValue: ({ outputs }?: {
|
|
919
|
+
outputs?: IOutput[] | undefined;
|
|
920
|
+
}) => number;
|
|
921
|
+
updateSendTransaction: ({ transaction }: {
|
|
922
|
+
transaction: Partial<ISendTransaction>;
|
|
923
|
+
}) => Result<string>;
|
|
924
|
+
updateFee({ satsPerByte, selectedFeeId, index, transaction }: {
|
|
925
|
+
satsPerByte: number;
|
|
926
|
+
selectedFeeId?: EFeeId;
|
|
927
|
+
index?: number;
|
|
928
|
+
transaction?: ISendTransaction;
|
|
929
|
+
}): Result<{
|
|
930
|
+
fee: number;
|
|
931
|
+
}>;
|
|
932
|
+
sendMax: ({ address, transaction, index, satsPerByte, rbf }?: {
|
|
933
|
+
address?: string | undefined;
|
|
934
|
+
transaction?: ISendTransaction | undefined;
|
|
935
|
+
index?: number | undefined;
|
|
936
|
+
satsPerByte?: number | undefined;
|
|
937
|
+
rbf?: boolean | undefined;
|
|
938
|
+
}) => Promise<Result<string>>;
|
|
939
|
+
estimateTransactionCosts: ({ transaction, customFeeRate }: {
|
|
940
|
+
transaction?: ISendTransaction | undefined;
|
|
941
|
+
customFeeRate?: number | undefined;
|
|
942
|
+
}) => Result<{
|
|
943
|
+
amount: number;
|
|
944
|
+
fee: number;
|
|
945
|
+
satsPerByte: number;
|
|
946
|
+
}>;
|
|
947
|
+
getMaxSendAmount({ satsPerByte, selectedFeeId, transaction }: {
|
|
948
|
+
satsPerByte: number;
|
|
949
|
+
selectedFeeId?: EFeeId;
|
|
950
|
+
transaction?: ISendTransaction;
|
|
951
|
+
}): Result<{
|
|
952
|
+
amount: number;
|
|
953
|
+
fee: number;
|
|
954
|
+
}>;
|
|
955
|
+
setupCpfp({ txid, satsPerByte }: {
|
|
956
|
+
txid?: string;
|
|
957
|
+
satsPerByte?: number;
|
|
958
|
+
}): Promise<Result<ISendTransaction>>;
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
declare class Wallet {
|
|
962
|
+
private _network;
|
|
963
|
+
private readonly _mnemonic;
|
|
964
|
+
private readonly _passphrase;
|
|
965
|
+
private readonly _seed;
|
|
966
|
+
private readonly _root;
|
|
967
|
+
private _data;
|
|
968
|
+
private _getData;
|
|
969
|
+
private _setData?;
|
|
970
|
+
private _customGetAddress?;
|
|
971
|
+
private _customGetScriptHash?;
|
|
972
|
+
private _pendingRefreshPromises;
|
|
973
|
+
private _disableMessagesOnCreate;
|
|
974
|
+
addressTypesToMonitor: EAddressType[];
|
|
975
|
+
isRefreshing: boolean;
|
|
976
|
+
isSwitchingNetworks: boolean;
|
|
977
|
+
readonly id: string;
|
|
978
|
+
readonly name: string;
|
|
979
|
+
electrumOptions?: {
|
|
980
|
+
servers?: TServer | TServer[];
|
|
981
|
+
tls?: TLSSocket;
|
|
982
|
+
net?: Server;
|
|
983
|
+
batchLimit?: number;
|
|
984
|
+
batchDelay?: number;
|
|
985
|
+
};
|
|
986
|
+
electrum: Electrum;
|
|
987
|
+
addressType: EAddressType;
|
|
988
|
+
sendMessage: TOnMessage;
|
|
989
|
+
transaction: Transaction;
|
|
990
|
+
feeEstimates: IOnchainFees;
|
|
991
|
+
rbf: boolean;
|
|
992
|
+
selectedFeeId: EFeeId;
|
|
993
|
+
disableMessages: boolean;
|
|
994
|
+
gapLimitOptions: TGapLimitOptions;
|
|
995
|
+
private constructor();
|
|
996
|
+
get data(): IWalletData;
|
|
997
|
+
get network(): EAvailableNetworks;
|
|
998
|
+
static create(params: IWallet): Promise<Result<Wallet>>;
|
|
999
|
+
switchNetwork(network: EAvailableNetworks, servers?: TServer | TServer[]): Promise<Result<Wallet>>;
|
|
1000
|
+
updateAddressType(addressType: EAddressType): Promise<void>;
|
|
1001
|
+
refreshWallet({ scanAllAddresses }?: {
|
|
1002
|
+
scanAllAddresses?: boolean | undefined;
|
|
1003
|
+
}): Promise<Result<IWalletData>>;
|
|
1004
|
+
private _resolveAllPendingRefreshPromises;
|
|
1005
|
+
private _handleRefreshError;
|
|
1006
|
+
private setWalletData;
|
|
1007
|
+
private storageIdCheck;
|
|
1008
|
+
getWalletDataKey(key: keyof IWalletData): string;
|
|
1009
|
+
getWalletData(): Promise<Result<IWalletData>>;
|
|
1010
|
+
private getBitcoinNetwork;
|
|
1011
|
+
isValid(mnemonic: any): boolean;
|
|
1012
|
+
private _getAddress;
|
|
1013
|
+
getAddress({ index, changeAddress, addressType }?: IGetAddress): Promise<string>;
|
|
1014
|
+
getAddressByPath({ path, addressType }: IGetAddressByPath): Promise<Result<IGetAddressResponse>>;
|
|
1015
|
+
connectToElectrum(servers?: TServer | TServer[]): Promise<Result<string>>;
|
|
1016
|
+
getAddressBalance(address: string): Promise<Result<IGetAddressBalanceRes>>;
|
|
1017
|
+
getAddressesBalance(addresses?: string[]): Promise<Result<number>>;
|
|
1018
|
+
getScriptHash({ address, network }: {
|
|
1019
|
+
address: string;
|
|
1020
|
+
network: EAvailableNetworks;
|
|
1021
|
+
}): Promise<string>;
|
|
1022
|
+
getPrivateKey(path: string): string;
|
|
1023
|
+
getScriptHashBalance(scriptHash: string): Promise<Result<IGetAddressBalanceRes>>;
|
|
1024
|
+
getBalance(): number;
|
|
1025
|
+
generateAddresses({ addressAmount, changeAddressAmount, addressIndex, changeAddressIndex, keyDerivationPath, addressType }: IGenerateAddresses): Promise<Result<IGenerateAddressesResponse>>;
|
|
1026
|
+
checkElectrumConnection(): Promise<Result<string>>;
|
|
1027
|
+
getNextAvailableAddress(addressType?: EAddressType): Promise<Result<IGetNextAvailableAddressResponse>>;
|
|
1028
|
+
getHighestStoredAddressIndex({ addressType }: {
|
|
1029
|
+
addressType: EAddressType;
|
|
1030
|
+
}): Result<{
|
|
1031
|
+
addressIndex: IAddress;
|
|
1032
|
+
changeAddressIndex: IAddress;
|
|
1033
|
+
}>;
|
|
1034
|
+
private addAddresses;
|
|
1035
|
+
private removeDuplicateAddresses;
|
|
1036
|
+
private updateAddressIndexes;
|
|
1037
|
+
resetAddressIndexes(): Promise<void>;
|
|
1038
|
+
generateNewReceiveAddress({ addressType, keyDerivationPath }: {
|
|
1039
|
+
addressType?: EAddressType;
|
|
1040
|
+
keyDerivationPath?: IKeyDerivationPath;
|
|
1041
|
+
}): Promise<Result<IAddress>>;
|
|
1042
|
+
getGapLimit({ addressType }: {
|
|
1043
|
+
addressType?: EAddressType;
|
|
1044
|
+
}): Result<{
|
|
1045
|
+
addressDelta: number;
|
|
1046
|
+
changeAddressDelta: number;
|
|
1047
|
+
}>;
|
|
1048
|
+
getUtxos({ scanningStrategy, addressIndex, changeAddressIndex, addressTypesToCheck }: {
|
|
1049
|
+
scanningStrategy?: EScanningStrategy;
|
|
1050
|
+
addressIndex?: number;
|
|
1051
|
+
changeAddressIndex?: number;
|
|
1052
|
+
addressTypesToCheck?: EAddressType[];
|
|
1053
|
+
}): Promise<Result<IGetUtxosResponse>>;
|
|
1054
|
+
listUtxos(): IUtxo[];
|
|
1055
|
+
private savingOperations;
|
|
1056
|
+
saveWalletData<K extends keyof IWalletData>(key: TWalletDataKeys, data: IWalletData[K]): Promise<string>;
|
|
1057
|
+
private updateAndSaveWalletData;
|
|
1058
|
+
updateTransactions({ scanAllAddresses, replaceStoredTransactions }: {
|
|
1059
|
+
scanAllAddresses?: boolean;
|
|
1060
|
+
replaceStoredTransactions?: boolean;
|
|
1061
|
+
}): Promise<Result<string | undefined>>;
|
|
1062
|
+
private checkUnconfirmedTransactions;
|
|
1063
|
+
private processUnconfirmedTransactions;
|
|
1064
|
+
getUnconfirmedTransactions(): IFormattedTransactions;
|
|
1065
|
+
confirmationsToBlockHeight({ confirmations, currentHeight }: {
|
|
1066
|
+
confirmations: number;
|
|
1067
|
+
currentHeight?: number;
|
|
1068
|
+
}): number;
|
|
1069
|
+
updateHeader(headerData: IHeader): Promise<void>;
|
|
1070
|
+
private updateGhostTransactions;
|
|
1071
|
+
rescanAddresses({ shouldClearAddresses, shouldClearTransactions }: {
|
|
1072
|
+
shouldClearAddresses?: boolean;
|
|
1073
|
+
shouldClearTransactions?: boolean;
|
|
1074
|
+
}): Promise<Result<IWalletData>>;
|
|
1075
|
+
clearUtxos(): Promise<string>;
|
|
1076
|
+
private clearTransactions;
|
|
1077
|
+
private clearAddresses;
|
|
1078
|
+
private updateTransactionHeights;
|
|
1079
|
+
private addUnconfirmedTransactions;
|
|
1080
|
+
blockHeightToConfirmations({ blockHeight, currentHeight }: {
|
|
1081
|
+
blockHeight?: number;
|
|
1082
|
+
currentHeight?: number;
|
|
1083
|
+
}): number;
|
|
1084
|
+
formatTransactions({ transactions }: {
|
|
1085
|
+
transactions: ITransaction<IUtxo>[];
|
|
1086
|
+
}): Promise<Result<IFormattedTransactions>>;
|
|
1087
|
+
getInputData({ inputs }: {
|
|
1088
|
+
inputs: {
|
|
1089
|
+
tx_hash: string;
|
|
1090
|
+
vout: number;
|
|
1091
|
+
}[];
|
|
1092
|
+
}): Promise<Result<InputData>>;
|
|
1093
|
+
validateAddress(address: string): boolean;
|
|
1094
|
+
getChangeAddress(addressType?: EAddressType): Promise<Result<IAddress>>;
|
|
1095
|
+
getFeeEstimates(network?: EAvailableNetworks): Promise<IOnchainFees>;
|
|
1096
|
+
setupTransaction(params?: ISetupTransaction): Promise<TSetupTransactionResponse>;
|
|
1097
|
+
getFeeInfo({ satsPerByte, message, transaction, fundingLightning }?: {
|
|
1098
|
+
satsPerByte?: number;
|
|
1099
|
+
message?: string;
|
|
1100
|
+
transaction?: Partial<ISendTransaction>;
|
|
1101
|
+
fundingLightning?: boolean;
|
|
1102
|
+
}): Result<TGetTotalFeeObj>;
|
|
1103
|
+
sendMany({ txs, satsPerByte, rbf, broadcast, shuffleOutputs }: {
|
|
1104
|
+
txs: ISendTx[];
|
|
1105
|
+
satsPerByte?: number;
|
|
1106
|
+
rbf?: boolean;
|
|
1107
|
+
broadcast?: boolean;
|
|
1108
|
+
shuffleOutputs?: boolean;
|
|
1109
|
+
}): Promise<Result<string>>;
|
|
1110
|
+
sendMax({ address, satsPerByte, rbf, broadcast }?: {
|
|
1111
|
+
address?: string;
|
|
1112
|
+
satsPerByte?: number;
|
|
1113
|
+
rbf?: boolean;
|
|
1114
|
+
broadcast?: boolean;
|
|
1115
|
+
}): Promise<Result<string>>;
|
|
1116
|
+
send({ address, amount, message, satsPerByte, rbf, broadcast, shuffleOutputs }: {
|
|
1117
|
+
address: string;
|
|
1118
|
+
amount: number;
|
|
1119
|
+
message?: string;
|
|
1120
|
+
satsPerByte?: number;
|
|
1121
|
+
rbf?: boolean;
|
|
1122
|
+
broadcast?: boolean;
|
|
1123
|
+
shuffleOutputs?: boolean;
|
|
1124
|
+
}): Promise<Result<string>>;
|
|
1125
|
+
getAddressFromScriptHash(scriptHash: string): IAddress | undefined;
|
|
1126
|
+
private setZeroIndexAddresses;
|
|
1127
|
+
private updateAddressIndex;
|
|
1128
|
+
getAddressIndexInfo(): TAddressIndexInfo;
|
|
1129
|
+
getReceiveAddress: ({ addressType }: {
|
|
1130
|
+
addressType?: EAddressType | undefined;
|
|
1131
|
+
}) => Promise<Result<string>>;
|
|
1132
|
+
getRbfData({ txHash }: {
|
|
1133
|
+
txHash: ITxHash;
|
|
1134
|
+
}): Promise<Result<IRbfData>>;
|
|
1135
|
+
deleteOnChainTransactionById({ txid }: {
|
|
1136
|
+
txid: string;
|
|
1137
|
+
}): Promise<void>;
|
|
1138
|
+
addGhostTransaction({ txid }: {
|
|
1139
|
+
txid: string;
|
|
1140
|
+
}): Promise<void>;
|
|
1141
|
+
addBoostedTransaction({ newTxId, oldTxId, type, fee }: {
|
|
1142
|
+
newTxId: string;
|
|
1143
|
+
oldTxId: string;
|
|
1144
|
+
type?: EBoostType;
|
|
1145
|
+
fee: number;
|
|
1146
|
+
}): Promise<Result<IBoostedTransaction>>;
|
|
1147
|
+
getBoostedTransactionParents: ({ txid, boostedTransactions }: {
|
|
1148
|
+
txid: string;
|
|
1149
|
+
boostedTransactions?: IBoostedTransactions | undefined;
|
|
1150
|
+
}) => string[];
|
|
1151
|
+
getBoostedTransactions: () => IBoostedTransactions;
|
|
1152
|
+
resetSendTransaction(): Promise<Result<string>>;
|
|
1153
|
+
getBoostableTransactions(): {
|
|
1154
|
+
cpfp: IFormattedTransaction[];
|
|
1155
|
+
rbf: IFormattedTransaction[];
|
|
1156
|
+
};
|
|
1157
|
+
getBip32Interface: () => Promise<Result<BIP32Interface>>;
|
|
1158
|
+
addTxInput({ input }: {
|
|
1159
|
+
input: IUtxo;
|
|
1160
|
+
}): Result<IUtxo[]>;
|
|
1161
|
+
removeTxInput({ input }: {
|
|
1162
|
+
input: IUtxo;
|
|
1163
|
+
}): Result<IUtxo[]>;
|
|
1164
|
+
addTxTag({ tag }: {
|
|
1165
|
+
tag: string;
|
|
1166
|
+
}): Result<string>;
|
|
1167
|
+
removeTxTag({ tag }: {
|
|
1168
|
+
tag: string;
|
|
1169
|
+
}): Result<string>;
|
|
1170
|
+
setupFeeForOnChainTransaction({ satsPerByte, selectedFeeId }: {
|
|
1171
|
+
satsPerByte?: number;
|
|
1172
|
+
selectedFeeId?: EFeeId;
|
|
1173
|
+
}): Result<string>;
|
|
1174
|
+
updateWalletBalance({ balance }: {
|
|
1175
|
+
balance: number;
|
|
1176
|
+
}): Result<string>;
|
|
1177
|
+
updateFeeEstimates(forceUpdate?: boolean): Promise<Result<IOnchainFees>>;
|
|
1178
|
+
getAddressesFromPrivateKey(privateKey: string, _addressTypes?: EAddressType[]): Result<IGetAddressesFromPrivateKey>;
|
|
1179
|
+
getPrivateKeyInfo(privateKey: string): Promise<Result<IPrivateKeyInfo>>;
|
|
1180
|
+
sweepPrivateKey({ privateKey, toAddress, satsPerByte, broadcast, combineWithWalletUtxos }: ISweepPrivateKey): Promise<Result<ISweepPrivateKeyRes>>;
|
|
1181
|
+
getAddressInfoFromScriptHash(scriptHash: string): Result<{
|
|
1182
|
+
address: IAddress;
|
|
1183
|
+
addressType: EAddressType;
|
|
1184
|
+
}>;
|
|
1185
|
+
updateGapLimit(gapLimitOptions: TGapLimitOptions): Result<TGapLimitOptions>;
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
export { EAddressType, EAvailableNetworks, EBoostType, EElectrumNetworks, EFeeId, EPaymentType, EProtocol, EScanningStrategy, EUnit, Electrum, type ElectrumConnectionPubSub, type ElectrumConnectionSubscription, type IAddInput, type IAddress, type IAddressData, type IAddressType, type IAddressTypeData, type IAddresses, type IBoostedTransaction, type IBoostedTransactions, type ICreateTransaction, type ICustomGetAddress, type ICustomGetScriptHash, type IElectrumGetAddressBalanceRes, type IFormattedPeerData, type IFormattedTransaction, type IFormattedTransactions, type IGenerateAddresses, type IGenerateAddressesResponse, type IGetAddress, type IGetAddressBalanceRes, type IGetAddressByPath, type IGetAddressHistoryResponse, type IGetAddressResponse, type IGetAddressScriptHashBalances, type IGetAddressScriptHashesHistoryResponse, type IGetAddressesFromKeyPair, type IGetAddressesFromPrivateKey, type IGetDerivationPath, type IGetFeeEstimatesResponse, type IGetHeaderResponse, type IGetNextAvailableAddressResponse, type IGetTransactions, type IGetTransactionsFromInputs, type IGetUtxosResponse, type IHeader, type IIndexes, type IKeyDerivationPath, type IKeyDerivationPathData, type INewBlock, type IOnchainFees, type IOutput, type IPeerData, type IPrivateKeyInfo, type IRbfData, type ISend, type ISendTransaction, type ISendTx, type ISetupTransaction, type ISubscribeToAddress, type ISubscribeToHeader, type ISweepPrivateKey, type ISweepPrivateKeyRes, type ITargets, type ITransaction, type ITxHash, type ITxHashes, type IUtxo, type IVin, type IVout, type IWallet, type IWalletData, type InputData, type ObjectKeys, type Result, type TAddressIndexInfo, type TAddressLabel, type TAddressType, type TAddressTypeContent, type TAddressTypes, type TAvailableNetworks, type TConnectToElectrumRes, type TDecodeRawTx, type TElectrumNetworks, type TGapLimitOptions, type TGetAddressHistory, type TGetByteCountInput, type TGetByteCountInputs, type TGetByteCountOutput, type TGetByteCountOutputs, type TGetData, type TGetTotalFeeObj, type TKeyDerivationAccount, type TKeyDerivationChange, type TKeyDerivationCoinType, type TKeyDerivationIndex, type TKeyDerivationPurpose, type TMessageDataMap, type TMessageKeys, type TOnMessage, type TProcessUnconfirmedTransactions, type TProtocol, type TServer, type TSetData, type TSetupTransactionResponse, type TStorage, type TSubscribedReceive, type TTransactionMessage, type TTxResponse, type TTxResult, type TUnspentAddressScriptHashData, type TWalletDataKeys, Transaction, Wallet, availableNetworks, constructByteCountParam, decodeOpReturnMessage, decodeRawTransaction, defaultElectrumPorts, electrumConnection, err, filterAddressesForGapLimit, filterAddressesObjForGapLimit, filterAddressesObjForSingleIndex, filterAddressesObjForStartingIndex, formatKeyDerivationPath, formatPeerData, generateMnemonic, generateWalletId, getAddressFromKeyPair, getAddressFromScriptPubKey, getAddressIndexDiff, getAddressTypeFromPath, getAddressesFromPrivateKey, getByteCount, getDataFallback, getDefaultPort, getDefaultWalletData, getDefaultWalletDataKeys, getElectrumNetwork, getHighestUsedIndexFromTxHashes, getKeyDerivationPath, getKeyDerivationPathObject, getKeyDerivationPathString, getKeyValue, getPeers, getProtocolForPort, getScriptHash, getSeed, getSeedHash, getSha256, getStorageKeyValues, getTapRootAddressFromPublicKey, getTxFee, getWalletDataStorageKey, isP2trPrefix, isPositive, isValidBech32mEncodedString, objectKeys, objectsMatch, ok, parseOnChainPaymentRequest, reduceValue, removeDustOutputs, setReplaceByFee, shuffleArray, sleep, validateAddress, validateMnemonic, validateTransaction };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "beignet",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.53",
|
|
4
4
|
"description": "A self-custodial, JS Bitcoin wallet management library.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"ecpair": "2.1.0",
|
|
51
51
|
"lodash.clonedeep": "4.5.0",
|
|
52
52
|
"net": "1.0.2",
|
|
53
|
-
"rn-electrum-client": "0.0.
|
|
53
|
+
"rn-electrum-client": "0.0.22"
|
|
54
54
|
},
|
|
55
55
|
"devDependencies": {
|
|
56
56
|
"@types/chai": "4.3.0",
|
package/src/electrum/index.ts
CHANGED
|
@@ -137,6 +137,8 @@ export class Electrum {
|
|
|
137
137
|
return err('Regtest requires that you pre-specify a server.');
|
|
138
138
|
}
|
|
139
139
|
const startResponse = await electrum.start({
|
|
140
|
+
clientName: 'beignet',
|
|
141
|
+
protocolVersion: '1.4',
|
|
140
142
|
network: electrumNetwork,
|
|
141
143
|
net: this.net,
|
|
142
144
|
tls: this.tls,
|