beignet 0.0.51 → 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/README.md +42 -37
- package/dist/index.d.ts +1188 -0
- package/dist/transaction/index.js +187 -10
- package/dist/transaction/index.js.map +1 -1
- package/dist/types/transaction/index.d.ts +16 -4
- package/dist/types/transaction.js +9 -1
- package/dist/types/transaction.js.map +1 -1
- package/dist/types/types/transaction.d.ts +22 -1
- package/dist/types/types/wallet.d.ts +2 -1
- package/dist/types/wallet/index.d.ts +5 -2
- package/dist/types/wallet.js.map +1 -1
- package/dist/wallet/index.js +10 -4
- package/dist/wallet/index.js.map +1 -1
- package/example/helpers.ts +1 -1
- package/example/index.ts +8 -2
- package/package.json +2 -2
- package/src/electrum/index.ts +2 -0
- package/src/transaction/index.ts +261 -10
- package/src/types/transaction.ts +32 -1
- package/src/types/wallet.ts +2 -1
- package/src/wallet/index.ts +19 -3
- package/tests/transaction.test.ts +247 -1
package/README.md
CHANGED
|
@@ -102,6 +102,7 @@ import { Wallet, generateMnemonic } from 'beignet';
|
|
|
102
102
|
import net from 'net'
|
|
103
103
|
import tls from 'tls'
|
|
104
104
|
import { TStorage } from './wallet';
|
|
105
|
+
import { ECoinSelectPreference } from "./transaction";
|
|
105
106
|
|
|
106
107
|
// Generate a mnemonic phrase
|
|
107
108
|
const mnemonic = generateMnemonic();
|
|
@@ -111,10 +112,10 @@ const passphrase = 'passphrase';
|
|
|
111
112
|
|
|
112
113
|
// Connect to custom electrum server
|
|
113
114
|
const servers: TServer = {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
115
|
+
host: '35.233.47.252',
|
|
116
|
+
ssl: 18484,
|
|
117
|
+
tcp: 18483,
|
|
118
|
+
protocol: EProtocol.ssl,
|
|
118
119
|
};
|
|
119
120
|
|
|
120
121
|
// Use a specific network (Defaults to mainnet)
|
|
@@ -128,8 +129,8 @@ const addressTypesToMonitor = [EAddressType.p2tr, EAddressType.p2wpkh];
|
|
|
128
129
|
|
|
129
130
|
// Subscribe to server messages (TOnMessage)
|
|
130
131
|
const onMessage: TOnMessage = (id, data) => {
|
|
131
|
-
|
|
132
|
-
|
|
132
|
+
console.log(id);
|
|
133
|
+
console.dir(data, { depth: null });
|
|
133
134
|
}
|
|
134
135
|
|
|
135
136
|
// Disable startup messages. Messages resume once startup is complete. (Defaults to false)
|
|
@@ -137,34 +138,38 @@ const disableMessagesOnCreate = true;
|
|
|
137
138
|
|
|
138
139
|
// Persist sessions by getting and setting data from storage
|
|
139
140
|
const storage: TStorage = {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
141
|
+
async getData<K extends keyof IWalletData>(
|
|
142
|
+
key: string
|
|
143
|
+
): Promise<Result<IWalletData[K]>> {
|
|
144
|
+
// Add your logic here
|
|
145
|
+
},
|
|
146
|
+
async setData<K extends keyof IWalletData>(
|
|
147
|
+
key: string,
|
|
148
|
+
value: IWalletData[K]
|
|
149
|
+
): Promise<Result<boolean>> {
|
|
150
|
+
// Add your logic here
|
|
151
|
+
}
|
|
151
152
|
};
|
|
152
153
|
|
|
154
|
+
// Set the auto coin selection preference. (Defaults to ECoinSelectPreference.consolidate)
|
|
155
|
+
const coinSelectPreference = ECoinSelectPreference.small;
|
|
156
|
+
|
|
153
157
|
// Create a wallet instance
|
|
154
158
|
const createWalletRes = await Wallet.create({
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
159
|
+
mnemonic,
|
|
160
|
+
passphrase,
|
|
161
|
+
electrumOptions: {
|
|
162
|
+
servers,
|
|
163
|
+
net,
|
|
164
|
+
tls
|
|
165
|
+
},
|
|
166
|
+
network,
|
|
167
|
+
onMessage,
|
|
168
|
+
storage,
|
|
169
|
+
addressType,
|
|
170
|
+
addressTypesToMonitor,
|
|
171
|
+
disableMessagesOnCreate,
|
|
172
|
+
coinSelectPreference
|
|
168
173
|
});
|
|
169
174
|
if (createWalletRes.isErr()) return;
|
|
170
175
|
const wallet = createWalletRes.value;
|
|
@@ -174,18 +179,18 @@ const utxos = wallet.listUtxos();
|
|
|
174
179
|
|
|
175
180
|
// Send sats to multiple outputs
|
|
176
181
|
const txs = [
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
182
|
+
{ address: 'address1', amount: 1000 },
|
|
183
|
+
{ address: 'address2', amount: 2000 },
|
|
184
|
+
{ address: 'address3', amount: 3000 },
|
|
180
185
|
];
|
|
181
186
|
const sendManyRes = await wallet.sendMany({ txs });
|
|
182
187
|
|
|
183
188
|
// Sweep from a private key
|
|
184
189
|
const sweepPrivateKeyRes = await wallet.sweepPrivateKey({
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
190
|
+
privateKey: 'privateKey',
|
|
191
|
+
toAddress: 'toAddress',
|
|
192
|
+
satsPerByte: 5,
|
|
193
|
+
broadcast: false
|
|
189
194
|
});
|
|
190
195
|
|
|
191
196
|
// Get tx history for a given address. { tx_hash: string; height: number; }[]
|