beignet 0.0.39 → 0.0.41
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/README.md +18 -1
- package/dist/electrum/index.js +6 -16
- package/dist/electrum/index.js.map +1 -1
- package/dist/index.d.ts +1188 -0
- package/dist/types/electrum/index.d.ts +8 -8
- package/dist/types/electrum.js.map +1 -1
- package/dist/types/types/electrum.d.ts +2 -0
- package/dist/types/types/wallet.d.ts +5 -5
- package/dist/types/wallet/index.d.ts +3 -7
- package/dist/wallet/index.js +1 -1
- package/dist/wallet/index.js.map +1 -1
- package/package.json +3 -2
- package/src/electrum/index.ts +24 -35
- package/src/types/electrum.ts +3 -0
- package/src/types/wallet.ts +6 -6
- package/src/wallet/index.ts +5 -5
package/src/electrum/index.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { Block } from 'bitcoinjs-lib';
|
|
2
|
+
import * as electrum from 'rn-electrum-client/helpers';
|
|
3
|
+
|
|
1
4
|
import {
|
|
2
5
|
EAddressType,
|
|
3
6
|
EAvailableNetworks,
|
|
@@ -22,6 +25,7 @@ import {
|
|
|
22
25
|
ITransaction,
|
|
23
26
|
ITxHash,
|
|
24
27
|
IUtxo,
|
|
28
|
+
Net,
|
|
25
29
|
TAddressTypeContent,
|
|
26
30
|
TConnectToElectrumRes,
|
|
27
31
|
TGetAddressHistory,
|
|
@@ -31,9 +35,9 @@ import {
|
|
|
31
35
|
TTxResponse,
|
|
32
36
|
TTxResult,
|
|
33
37
|
TUnspentAddressScriptHashData,
|
|
34
|
-
TUnspentAddressScriptHashResponse
|
|
38
|
+
TUnspentAddressScriptHashResponse,
|
|
39
|
+
Tls
|
|
35
40
|
} from '../types';
|
|
36
|
-
import * as electrum from 'rn-electrum-client/helpers';
|
|
37
41
|
import {
|
|
38
42
|
err,
|
|
39
43
|
filterAddressesForGapLimit,
|
|
@@ -50,25 +54,14 @@ import {
|
|
|
50
54
|
} from '../utils';
|
|
51
55
|
import { Wallet } from '../wallet';
|
|
52
56
|
import { onMessageKeys, POLLING_INTERVAL } from '../shapes';
|
|
53
|
-
import { Block } from 'bitcoinjs-lib';
|
|
54
|
-
import { Server } from 'net';
|
|
55
|
-
import { TLSSocket } from 'tls';
|
|
56
|
-
|
|
57
|
-
let tls, net;
|
|
58
|
-
try {
|
|
59
|
-
tls = require('tls');
|
|
60
|
-
net = require('net');
|
|
61
|
-
} catch {
|
|
62
|
-
// Modules not available, will attempt to use passed instances, if any.
|
|
63
|
-
}
|
|
64
57
|
|
|
65
58
|
export class Electrum {
|
|
66
59
|
private readonly _wallet: Wallet;
|
|
67
60
|
private sendMessage: TOnMessage;
|
|
68
61
|
private latestConnectionState: boolean | null = null;
|
|
69
62
|
private connectionPollingInterval: NodeJS.Timeout | null;
|
|
70
|
-
private
|
|
71
|
-
private
|
|
63
|
+
private net: Net;
|
|
64
|
+
private tls: Tls;
|
|
72
65
|
|
|
73
66
|
public servers?: TServer | TServer[];
|
|
74
67
|
public network: EAvailableNetworks;
|
|
@@ -77,24 +70,25 @@ export class Electrum {
|
|
|
77
70
|
public onReceive?: (data: unknown) => void;
|
|
78
71
|
public batchLimit: number;
|
|
79
72
|
public batchDelay: number;
|
|
73
|
+
|
|
80
74
|
constructor({
|
|
81
75
|
wallet,
|
|
82
|
-
servers,
|
|
83
76
|
network,
|
|
84
|
-
|
|
85
|
-
tls
|
|
86
|
-
|
|
77
|
+
net,
|
|
78
|
+
tls,
|
|
79
|
+
servers,
|
|
87
80
|
batchLimit = 20,
|
|
88
|
-
batchDelay = 50
|
|
81
|
+
batchDelay = 50,
|
|
82
|
+
onReceive
|
|
89
83
|
}: {
|
|
90
84
|
wallet: Wallet;
|
|
91
|
-
servers?: TServer | TServer[];
|
|
92
85
|
network: EAvailableNetworks;
|
|
93
|
-
|
|
94
|
-
tls
|
|
95
|
-
|
|
86
|
+
net: Net;
|
|
87
|
+
tls: Tls;
|
|
88
|
+
servers?: TServer | TServer[];
|
|
96
89
|
batchLimit?: number;
|
|
97
90
|
batchDelay?: number;
|
|
91
|
+
onReceive?: (data: unknown) => void;
|
|
98
92
|
}) {
|
|
99
93
|
this._wallet = wallet;
|
|
100
94
|
this.sendMessage = wallet.sendMessage;
|
|
@@ -103,15 +97,10 @@ export class Electrum {
|
|
|
103
97
|
this.electrumNetwork = getElectrumNetwork(this.network);
|
|
104
98
|
this.connectedToElectrum = false;
|
|
105
99
|
this.onReceive = onReceive;
|
|
106
|
-
this.
|
|
107
|
-
this.
|
|
100
|
+
this.net = net;
|
|
101
|
+
this.tls = tls;
|
|
108
102
|
this.batchLimit = batchLimit;
|
|
109
103
|
this.batchDelay = batchDelay;
|
|
110
|
-
if (!this.tls || !this.net) {
|
|
111
|
-
throw new Error(
|
|
112
|
-
'TLS and NET modules are not available and were not passed as instances'
|
|
113
|
-
);
|
|
114
|
-
}
|
|
115
104
|
this.connectionPollingInterval = setInterval(
|
|
116
105
|
(): Promise<void> => this.checkConnection(),
|
|
117
106
|
POLLING_INTERVAL
|
|
@@ -148,8 +137,8 @@ export class Electrum {
|
|
|
148
137
|
}
|
|
149
138
|
const startResponse = await electrum.start({
|
|
150
139
|
network: electrumNetwork,
|
|
151
|
-
tls: this.tls,
|
|
152
140
|
net: this.net,
|
|
141
|
+
tls: this.tls,
|
|
153
142
|
customPeers
|
|
154
143
|
});
|
|
155
144
|
if (startResponse.error && !this.wallet.isSwitchingNetworks)
|
|
@@ -858,7 +847,7 @@ export class Electrum {
|
|
|
858
847
|
}
|
|
859
848
|
|
|
860
849
|
// Subscribe to all provided script hashes.
|
|
861
|
-
const
|
|
850
|
+
const allScriptHashesPromises = scriptHashes.map(async (scriptHash) => {
|
|
862
851
|
const response: ISubscribeToAddress = await electrum.subscribeAddress({
|
|
863
852
|
scriptHash,
|
|
864
853
|
network: this.electrumNetwork,
|
|
@@ -872,7 +861,7 @@ export class Electrum {
|
|
|
872
861
|
}
|
|
873
862
|
});
|
|
874
863
|
|
|
875
|
-
const
|
|
864
|
+
const allUtxosPromises = allUtxos.map(async (utxo) => {
|
|
876
865
|
const response: ISubscribeToAddress = await electrum.subscribeAddress({
|
|
877
866
|
scriptHash: utxo.scriptHash,
|
|
878
867
|
network: this.electrumNetwork,
|
|
@@ -892,7 +881,7 @@ export class Electrum {
|
|
|
892
881
|
});
|
|
893
882
|
|
|
894
883
|
try {
|
|
895
|
-
await Promise.all([
|
|
884
|
+
await Promise.all([...allScriptHashesPromises, ...allUtxosPromises]);
|
|
896
885
|
} catch (e) {
|
|
897
886
|
return err(e);
|
|
898
887
|
}
|
package/src/types/electrum.ts
CHANGED
|
@@ -6,6 +6,9 @@ import {
|
|
|
6
6
|
IUtxo
|
|
7
7
|
} from './wallet';
|
|
8
8
|
|
|
9
|
+
export type Net = typeof import('net');
|
|
10
|
+
export type Tls = typeof import('tls');
|
|
11
|
+
|
|
9
12
|
export type TElectrumNetworks = 'bitcoin' | 'bitcoinTestnet' | 'bitcoinRegtest';
|
|
10
13
|
export enum EElectrumNetworks {
|
|
11
14
|
bitcoin = 'bitcoin',
|
package/src/types/wallet.ts
CHANGED
|
@@ -3,12 +3,12 @@ import {
|
|
|
3
3
|
EElectrumNetworks,
|
|
4
4
|
IHeader,
|
|
5
5
|
INewBlock,
|
|
6
|
+
Net,
|
|
6
7
|
TServer,
|
|
7
|
-
TTxResult
|
|
8
|
+
TTxResult,
|
|
9
|
+
Tls
|
|
8
10
|
} from './electrum';
|
|
9
11
|
import { EFeeId, TGapLimitOptions } from './transaction';
|
|
10
|
-
import { TLSSocket } from 'tls';
|
|
11
|
-
import { Server } from 'net';
|
|
12
12
|
import { ECPairInterface } from 'ecpair';
|
|
13
13
|
import { BIP32Interface } from 'bip32';
|
|
14
14
|
|
|
@@ -190,10 +190,10 @@ export interface IWallet {
|
|
|
190
190
|
addressType?: EAddressType;
|
|
191
191
|
data?: IWalletData;
|
|
192
192
|
storage?: TStorage;
|
|
193
|
-
electrumOptions
|
|
193
|
+
electrumOptions: {
|
|
194
|
+
net: Net;
|
|
195
|
+
tls: Tls;
|
|
194
196
|
servers?: TServer | TServer[];
|
|
195
|
-
tls?: TLSSocket;
|
|
196
|
-
net?: Server;
|
|
197
197
|
batchLimit?: number; // Maximum number of requests to be sent in a single batch
|
|
198
198
|
batchDelay?: number; // Delay (in milliseconds) between each batch of requests
|
|
199
199
|
};
|
package/src/wallet/index.ts
CHANGED
|
@@ -46,12 +46,14 @@ import {
|
|
|
46
46
|
IVout,
|
|
47
47
|
IWallet,
|
|
48
48
|
IWalletData,
|
|
49
|
+
Net,
|
|
49
50
|
TAddressIndexInfo,
|
|
50
51
|
TAddressTypeContent,
|
|
51
52
|
TAvailableNetworks,
|
|
52
53
|
TGapLimitOptions,
|
|
53
54
|
TGetData,
|
|
54
55
|
TGetTotalFeeObj,
|
|
56
|
+
Tls,
|
|
55
57
|
TMessageDataMap,
|
|
56
58
|
TOnMessage,
|
|
57
59
|
TProcessUnconfirmedTransactions,
|
|
@@ -107,8 +109,6 @@ import { GAP_LIMIT, TRANSACTION_DEFAULTS } from './constants';
|
|
|
107
109
|
import cloneDeep from 'lodash.clonedeep';
|
|
108
110
|
import { btcToSats } from '../utils/conversion';
|
|
109
111
|
import * as bip39 from 'bip39';
|
|
110
|
-
import { TLSSocket } from 'tls';
|
|
111
|
-
import { Server } from 'net';
|
|
112
112
|
|
|
113
113
|
const bip32 = BIP32Factory(ecc);
|
|
114
114
|
|
|
@@ -138,9 +138,9 @@ export class Wallet {
|
|
|
138
138
|
public readonly id: string;
|
|
139
139
|
public readonly name: string;
|
|
140
140
|
public electrumOptions?: {
|
|
141
|
+
net: Net;
|
|
142
|
+
tls: Tls;
|
|
141
143
|
servers?: TServer | TServer[];
|
|
142
|
-
tls?: TLSSocket;
|
|
143
|
-
net?: Server;
|
|
144
144
|
batchLimit?: number; // Maximum number of requests to be sent in a single batch
|
|
145
145
|
batchDelay?: number; // Delay (in milliseconds) between each batch of requests
|
|
146
146
|
};
|
|
@@ -160,7 +160,7 @@ export class Wallet {
|
|
|
160
160
|
network = EAvailableNetworks.mainnet,
|
|
161
161
|
addressType = EAddressType.p2wpkh,
|
|
162
162
|
storage,
|
|
163
|
-
electrumOptions
|
|
163
|
+
electrumOptions,
|
|
164
164
|
onMessage = (): null => null,
|
|
165
165
|
customGetAddress,
|
|
166
166
|
customGetScriptHash,
|