@bsv/wallet-toolbox 1.1.3 → 1.1.4
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/docs/README.md +1 -0
- package/docs/client.md +324 -84
- package/docs/setup.md +358 -67
- package/docs/wallet.md +324 -84
- package/out/src/Setup.d.ts +28 -30
- package/out/src/Setup.d.ts.map +1 -1
- package/out/src/Setup.js +14 -10
- package/out/src/Setup.js.map +1 -1
- package/out/src/SetupClient.d.ts +99 -41
- package/out/src/SetupClient.d.ts.map +1 -1
- package/out/src/SetupClient.js +124 -90
- package/out/src/SetupClient.js.map +1 -1
- package/out/src/Wallet.d.ts +10 -0
- package/out/src/Wallet.d.ts.map +1 -1
- package/out/src/Wallet.js.map +1 -1
- package/out/src/index.all.d.ts +1 -1
- package/out/src/index.all.d.ts.map +1 -1
- package/out/src/index.all.js +3 -2
- package/out/src/index.all.js.map +1 -1
- package/out/src/sdk/types.d.ts +5 -0
- package/out/src/sdk/types.d.ts.map +1 -1
- package/out/src/sdk/types.js.map +1 -1
- package/out/test/examples/README.man.test.js +8 -7
- package/out/test/examples/README.man.test.js.map +1 -1
- package/out/tsconfig.all.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/Setup.ts +41 -54
- package/src/SetupClient.ts +219 -150
- package/src/Wallet.ts +10 -0
- package/src/index.all.ts +9 -1
- package/src/sdk/types.ts +7 -0
- package/test/examples/README.man.test.ts +9 -9
- package/ts2md.json +0 -8
package/docs/setup.md
CHANGED
|
@@ -6,19 +6,42 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
|
|
|
6
6
|
|
|
7
7
|
| |
|
|
8
8
|
| --- |
|
|
9
|
+
| [SetupEnv](#interface-setupenv) |
|
|
9
10
|
| [SetupWallet](#interface-setupwallet) |
|
|
10
|
-
| [
|
|
11
|
+
| [SetupWalletArgs](#interface-setupwalletargs) |
|
|
12
|
+
| [SetupWalletClient](#interface-setupwalletclient) |
|
|
13
|
+
| [SetupWalletClientArgs](#interface-setupwalletclientargs) |
|
|
14
|
+
| [SetupWalletKnex](#interface-setupwalletknex) |
|
|
15
|
+
| [SetupWalletKnexArgs](#interface-setupwalletknexargs) |
|
|
16
|
+
| [SetupWalletMySQLArgs](#interface-setupwalletmysqlargs) |
|
|
17
|
+
| [SetupWalletSQLiteArgs](#interface-setupwalletsqliteargs) |
|
|
11
18
|
|
|
12
19
|
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
13
20
|
|
|
14
21
|
---
|
|
15
22
|
|
|
23
|
+
### Interface: SetupEnv
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
export interface SetupEnv {
|
|
27
|
+
chain: sdk.Chain;
|
|
28
|
+
identityKey: string;
|
|
29
|
+
identityKey2: string;
|
|
30
|
+
taalApiKey: string;
|
|
31
|
+
devKeys: Record<string, string>;
|
|
32
|
+
mySQLConnection: string;
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
See also: [Chain](#type-chain)
|
|
37
|
+
|
|
38
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
39
|
+
|
|
40
|
+
---
|
|
16
41
|
### Interface: SetupWallet
|
|
17
42
|
|
|
18
43
|
```ts
|
|
19
|
-
export interface SetupWallet
|
|
20
|
-
activeStorage: StorageKnex;
|
|
21
|
-
userId: number;
|
|
44
|
+
export interface SetupWallet {
|
|
22
45
|
rootKey: PrivateKey;
|
|
23
46
|
identityKey: string;
|
|
24
47
|
keyDeriver: KeyDeriver;
|
|
@@ -30,15 +53,63 @@ export interface SetupWallet extends SetupWalletOnly {
|
|
|
30
53
|
}
|
|
31
54
|
```
|
|
32
55
|
|
|
33
|
-
See also: [Chain](#type-chain), [Monitor](#class-monitor), [Services](#class-services), [
|
|
56
|
+
See also: [Chain](#type-chain), [Monitor](#class-monitor), [Services](#class-services), [Wallet](#class-wallet), [WalletStorageManager](#class-walletstoragemanager)
|
|
57
|
+
|
|
58
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
### Interface: SetupWalletArgs
|
|
62
|
+
|
|
63
|
+
Arguments used to construct a `Wallet`
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
export interface SetupWalletArgs {
|
|
67
|
+
env: SetupEnv;
|
|
68
|
+
chain?: sdk.Chain;
|
|
69
|
+
rootKeyHex?: string;
|
|
70
|
+
privKeyHex?: string;
|
|
71
|
+
active?: sdk.WalletStorageProvider;
|
|
72
|
+
backups?: sdk.WalletStorageProvider[];
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
See also: [Chain](#type-chain), [SetupEnv](#interface-setupenv), [WalletStorageProvider](#interface-walletstorageprovider)
|
|
77
|
+
|
|
78
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
79
|
+
|
|
80
|
+
---
|
|
81
|
+
### Interface: SetupWalletClient
|
|
82
|
+
|
|
83
|
+
```ts
|
|
84
|
+
export interface SetupWalletClient extends SetupWallet {
|
|
85
|
+
endpointUrl: string;
|
|
86
|
+
}
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
See also: [SetupWallet](#interface-setupwallet)
|
|
90
|
+
|
|
91
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
92
|
+
|
|
93
|
+
---
|
|
94
|
+
### Interface: SetupWalletClientArgs
|
|
95
|
+
|
|
96
|
+
```ts
|
|
97
|
+
export interface SetupWalletClientArgs extends SetupWalletArgs {
|
|
98
|
+
endpointUrl?: string;
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
See also: [SetupWalletArgs](#interface-setupwalletargs)
|
|
34
103
|
|
|
35
104
|
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
36
105
|
|
|
37
106
|
---
|
|
38
|
-
### Interface:
|
|
107
|
+
### Interface: SetupWalletKnex
|
|
39
108
|
|
|
40
109
|
```ts
|
|
41
|
-
export interface
|
|
110
|
+
export interface SetupWalletKnex extends SetupWallet {
|
|
111
|
+
activeStorage: StorageKnex;
|
|
112
|
+
userId: number;
|
|
42
113
|
rootKey: PrivateKey;
|
|
43
114
|
identityKey: string;
|
|
44
115
|
keyDeriver: KeyDeriver;
|
|
@@ -50,7 +121,48 @@ export interface SetupWalletOnly {
|
|
|
50
121
|
}
|
|
51
122
|
```
|
|
52
123
|
|
|
53
|
-
See also: [Chain](#type-chain), [Monitor](#class-monitor), [Services](#class-services), [Wallet](#class-wallet), [WalletStorageManager](#class-walletstoragemanager)
|
|
124
|
+
See also: [Chain](#type-chain), [Monitor](#class-monitor), [Services](#class-services), [SetupWallet](#interface-setupwallet), [StorageKnex](#class-storageknex), [Wallet](#class-wallet), [WalletStorageManager](#class-walletstoragemanager)
|
|
125
|
+
|
|
126
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
### Interface: SetupWalletKnexArgs
|
|
130
|
+
|
|
131
|
+
```ts
|
|
132
|
+
export interface SetupWalletKnexArgs extends SetupWalletArgs {
|
|
133
|
+
knex: Knex<any, any[]>;
|
|
134
|
+
databaseName: string;
|
|
135
|
+
}
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
See also: [SetupWalletArgs](#interface-setupwalletargs)
|
|
139
|
+
|
|
140
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
141
|
+
|
|
142
|
+
---
|
|
143
|
+
### Interface: SetupWalletMySQLArgs
|
|
144
|
+
|
|
145
|
+
```ts
|
|
146
|
+
export interface SetupWalletMySQLArgs extends SetupWalletArgs {
|
|
147
|
+
databaseName: string;
|
|
148
|
+
}
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
See also: [SetupWalletArgs](#interface-setupwalletargs)
|
|
152
|
+
|
|
153
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
### Interface: SetupWalletSQLiteArgs
|
|
157
|
+
|
|
158
|
+
```ts
|
|
159
|
+
export interface SetupWalletSQLiteArgs extends SetupWalletArgs {
|
|
160
|
+
filePath: string;
|
|
161
|
+
databaseName: string;
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
See also: [SetupWalletArgs](#interface-setupwalletargs)
|
|
54
166
|
|
|
55
167
|
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
56
168
|
|
|
@@ -60,6 +172,7 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
|
|
|
60
172
|
| |
|
|
61
173
|
| --- |
|
|
62
174
|
| [Setup](#class-setup) |
|
|
175
|
+
| [Setup](#class-setup) |
|
|
63
176
|
| [SetupClient](#class-setupclient) |
|
|
64
177
|
|
|
65
178
|
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
@@ -68,39 +181,59 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
|
|
|
68
181
|
|
|
69
182
|
### Class: Setup
|
|
70
183
|
|
|
71
|
-
|
|
184
|
+
Enables code that imports only from `SetupClient` to still reference everything as just `Setup`
|
|
185
|
+
|
|
186
|
+
```ts
|
|
187
|
+
export class Setup extends SetupClient {
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
See also: [SetupClient](#class-setupclient)
|
|
192
|
+
|
|
193
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
194
|
+
|
|
195
|
+
---
|
|
196
|
+
### Class: Setup
|
|
197
|
+
|
|
198
|
+
The 'Setup` class provides static setup functions to construct BRC-100 compatible
|
|
72
199
|
wallets in a variety of configurations.
|
|
73
200
|
|
|
74
201
|
It serves as a starting point for experimentation and customization.
|
|
75
202
|
|
|
203
|
+
`SetupClient` references only browser compatible code including storage via `StorageClient`.
|
|
204
|
+
`Setup` extends `SetupClient` adding database storage via `Knex` and `StorageKnex`.
|
|
205
|
+
|
|
76
206
|
```ts
|
|
77
207
|
export abstract class Setup extends SetupClient {
|
|
78
|
-
static async createKnexWallet(args: {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
208
|
+
static async createKnexWallet(args: SetupWalletKnexArgs): Promise<SetupWalletKnex> {
|
|
209
|
+
const wo = await Setup.createWallet(args);
|
|
210
|
+
const activeStorage = new StorageKnex({
|
|
211
|
+
chain: wo.chain,
|
|
212
|
+
knex: args.knex,
|
|
213
|
+
commissionSatoshis: 0,
|
|
214
|
+
commissionPubKeyHex: undefined,
|
|
215
|
+
feeModel: { model: "sat/kb", value: 1 }
|
|
216
|
+
});
|
|
217
|
+
await activeStorage.migrate(args.databaseName, wo.identityKey);
|
|
218
|
+
await activeStorage.makeAvailable();
|
|
219
|
+
await wo.storage.addWalletStorageProvider(activeStorage);
|
|
220
|
+
const { user, isNew } = await activeStorage.findOrInsertUser(wo.identityKey);
|
|
221
|
+
const userId = user.userId;
|
|
222
|
+
const r: SetupWalletKnex = {
|
|
223
|
+
...wo,
|
|
224
|
+
activeStorage,
|
|
225
|
+
userId
|
|
226
|
+
};
|
|
227
|
+
return r;
|
|
228
|
+
}
|
|
85
229
|
static createSQLiteKnex(filename: string): Knex
|
|
86
230
|
static createMySQLKnex(connection: string, database?: string): Knex
|
|
87
|
-
static async createMySQLWallet(args:
|
|
88
|
-
|
|
89
|
-
chain?: sdk.Chain;
|
|
90
|
-
rootKeyHex?: string;
|
|
91
|
-
privKeyHex?: string;
|
|
92
|
-
}): Promise<SetupWallet>
|
|
93
|
-
static async createSQLiteWallet(args: {
|
|
94
|
-
filePath: string;
|
|
95
|
-
databaseName: string;
|
|
96
|
-
chain?: sdk.Chain;
|
|
97
|
-
rootKeyHex?: string;
|
|
98
|
-
privKeyHex?: string;
|
|
99
|
-
}): Promise<SetupWallet>
|
|
231
|
+
static async createMySQLWallet(args: SetupWalletMySQLArgs): Promise<SetupWalletKnex>
|
|
232
|
+
static async createSQLiteWallet(args: SetupWalletSQLiteArgs): Promise<SetupWalletKnex>
|
|
100
233
|
}
|
|
101
234
|
```
|
|
102
235
|
|
|
103
|
-
See also: [
|
|
236
|
+
See also: [SetupClient](#class-setupclient), [SetupWalletKnex](#interface-setupwalletknex), [SetupWalletKnexArgs](#interface-setupwalletknexargs), [SetupWalletMySQLArgs](#interface-setupwalletmysqlargs), [SetupWalletSQLiteArgs](#interface-setupwalletsqliteargs), [StorageKnex](#class-storageknex)
|
|
104
237
|
|
|
105
238
|
<details>
|
|
106
239
|
|
|
@@ -111,15 +244,40 @@ See also: [Chain](#type-chain), [SetupClient](#class-setupclient), [SetupWallet]
|
|
|
111
244
|
Adds `Knex` based storage to a `Wallet` configured by `Setup.createWalletOnly`
|
|
112
245
|
|
|
113
246
|
```ts
|
|
114
|
-
static async createKnexWallet(args: {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
247
|
+
static async createKnexWallet(args: SetupWalletKnexArgs): Promise<SetupWalletKnex> {
|
|
248
|
+
const wo = await Setup.createWallet(args);
|
|
249
|
+
const activeStorage = new StorageKnex({
|
|
250
|
+
chain: wo.chain,
|
|
251
|
+
knex: args.knex,
|
|
252
|
+
commissionSatoshis: 0,
|
|
253
|
+
commissionPubKeyHex: undefined,
|
|
254
|
+
feeModel: { model: "sat/kb", value: 1 }
|
|
255
|
+
});
|
|
256
|
+
await activeStorage.migrate(args.databaseName, wo.identityKey);
|
|
257
|
+
await activeStorage.makeAvailable();
|
|
258
|
+
await wo.storage.addWalletStorageProvider(activeStorage);
|
|
259
|
+
const { user, isNew } = await activeStorage.findOrInsertUser(wo.identityKey);
|
|
260
|
+
const userId = user.userId;
|
|
261
|
+
const r: SetupWalletKnex = {
|
|
262
|
+
...wo,
|
|
263
|
+
activeStorage,
|
|
264
|
+
userId
|
|
265
|
+
};
|
|
266
|
+
return r;
|
|
267
|
+
}
|
|
121
268
|
```
|
|
122
|
-
See also: [
|
|
269
|
+
See also: [Setup](#class-setup), [SetupWalletKnex](#interface-setupwalletknex), [SetupWalletKnexArgs](#interface-setupwalletknexargs), [StorageKnex](#class-storageknex)
|
|
270
|
+
|
|
271
|
+
Argument Details
|
|
272
|
+
|
|
273
|
+
+ **args.knex**
|
|
274
|
+
+ `Knex` object configured for either MySQL or SQLite database access.
|
|
275
|
+
Schema will be created and migrated as needed.
|
|
276
|
+
For MySQL, a schema corresponding to databaseName must exist with full access permissions.
|
|
277
|
+
+ **args.databaseName**
|
|
278
|
+
+ Name for this storage. For MySQL, the schema name within the MySQL instance.
|
|
279
|
+
+ **args.chain**
|
|
280
|
+
+ Which chain this wallet is on: 'main' or 'test'. Defaults to 'test'.
|
|
123
281
|
|
|
124
282
|
</details>
|
|
125
283
|
|
|
@@ -128,14 +286,17 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
|
|
|
128
286
|
---
|
|
129
287
|
### Class: SetupClient
|
|
130
288
|
|
|
131
|
-
|
|
289
|
+
The `SetupClient` class provides static setup functions to construct BRC-100 compatible
|
|
132
290
|
wallets in a variety of configurations.
|
|
133
291
|
|
|
134
292
|
It serves as a starting point for experimentation and customization.
|
|
135
293
|
|
|
294
|
+
`SetupClient` references only browser compatible code including storage via `StorageClient`.
|
|
295
|
+
`Setup` extends `SetupClient` adding database storage via `Knex` and `StorageKnex`.
|
|
296
|
+
|
|
136
297
|
```ts
|
|
137
298
|
export abstract class SetupClient {
|
|
138
|
-
static makeEnv(
|
|
299
|
+
static makeEnv(): string {
|
|
139
300
|
const testPrivKey1 = PrivateKey.fromRandom();
|
|
140
301
|
const testIdentityKey1 = testPrivKey1.toPublicKey().toString();
|
|
141
302
|
const testPrivKey2 = PrivateKey.fromRandom();
|
|
@@ -161,39 +322,169 @@ export abstract class SetupClient {
|
|
|
161
322
|
MYSQL_CONNECTION='{"port":3306,"host":"127.0.0.1","user":"root","password":"<your_password>","database":"<your_database>", "timezone": "Z"}'
|
|
162
323
|
`;
|
|
163
324
|
console.log(log);
|
|
325
|
+
return log;
|
|
164
326
|
}
|
|
165
|
-
static getEnv(chain: sdk.Chain)
|
|
166
|
-
static async
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
327
|
+
static getEnv(chain: sdk.Chain): SetupEnv
|
|
328
|
+
static async createWallet(args: SetupWalletArgs): Promise<SetupWallet> {
|
|
329
|
+
args.chain ||= args.env.chain;
|
|
330
|
+
args.rootKeyHex ||= args.env.devKeys[args.env.identityKey];
|
|
331
|
+
const rootKey = PrivateKey.fromHex(args.rootKeyHex);
|
|
332
|
+
const identityKey = rootKey.toPublicKey().toString();
|
|
333
|
+
const keyDeriver = new KeyDeriver(rootKey);
|
|
334
|
+
const chain = args.chain;
|
|
335
|
+
const storage = new WalletStorageManager(identityKey, args.active, args.backups);
|
|
336
|
+
if (storage.stores.length > 0)
|
|
337
|
+
await storage.makeAvailable();
|
|
338
|
+
const serviceOptions = Services.createDefaultOptions(chain);
|
|
339
|
+
serviceOptions.taalApiKey = args.env.taalApiKey;
|
|
340
|
+
const services = new Services(args.chain);
|
|
341
|
+
const monopts = Monitor.createDefaultWalletMonitorOptions(chain, storage, services);
|
|
342
|
+
const monitor = new Monitor(monopts);
|
|
343
|
+
monitor.addDefaultTasks();
|
|
344
|
+
let privilegedKeyManager: sdk.PrivilegedKeyManager | undefined = undefined;
|
|
345
|
+
if (args.privKeyHex) {
|
|
346
|
+
const privKey = PrivateKey.fromString(args.privKeyHex);
|
|
347
|
+
privilegedKeyManager = new sdk.PrivilegedKeyManager(async () => privKey);
|
|
348
|
+
}
|
|
349
|
+
const wallet = new Wallet({
|
|
350
|
+
chain,
|
|
351
|
+
keyDeriver,
|
|
352
|
+
storage,
|
|
353
|
+
services,
|
|
354
|
+
monitor,
|
|
355
|
+
privilegedKeyManager
|
|
356
|
+
});
|
|
357
|
+
const r: SetupWallet = {
|
|
358
|
+
rootKey,
|
|
359
|
+
identityKey,
|
|
360
|
+
keyDeriver,
|
|
361
|
+
chain,
|
|
362
|
+
storage,
|
|
363
|
+
services,
|
|
364
|
+
monitor,
|
|
365
|
+
wallet
|
|
366
|
+
};
|
|
367
|
+
return r;
|
|
368
|
+
}
|
|
369
|
+
static async createWalletWithStorageClient(args: SetupWalletClientArgs): Promise<SetupWalletClient>
|
|
178
370
|
static getKeyPair(priv?: string | PrivateKey): KeyPairAddress
|
|
179
371
|
static getLockP2PKH(address: string)
|
|
180
|
-
static getUnlockP2PKH(priv: PrivateKey, satoshis: number)
|
|
181
|
-
static
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
}):
|
|
188
|
-
static async
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
372
|
+
static getUnlockP2PKH(priv: PrivateKey, satoshis: number): sdk.ScriptTemplateUnlock
|
|
373
|
+
static createP2PKHOutputs(outputs: {
|
|
374
|
+
address: string;
|
|
375
|
+
satoshis: number;
|
|
376
|
+
outputDescription?: string;
|
|
377
|
+
basket?: string;
|
|
378
|
+
tags?: string[];
|
|
379
|
+
}[]): CreateActionOutput[]
|
|
380
|
+
static async createP2PKHOutputsAction(wallet: WalletInterface, outputs: {
|
|
381
|
+
address: string;
|
|
382
|
+
satoshis: number;
|
|
383
|
+
outputDescription?: string;
|
|
384
|
+
basket?: string;
|
|
385
|
+
tags?: string[];
|
|
386
|
+
}[], options?: CreateActionOptions): Promise<{
|
|
387
|
+
cr: CreateActionResult;
|
|
388
|
+
outpoints: string[] | undefined;
|
|
389
|
+
}>
|
|
390
|
+
static async fundWalletFromP2PKHOutpoints(wallet: WalletInterface, outpoints: string[], p2pkhKey: KeyPairAddress, inputBEEF?: BEEF)
|
|
391
|
+
}
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
See also: [Chain](#type-chain), [KeyPairAddress](#type-keypairaddress), [Monitor](#class-monitor), [PrivilegedKeyManager](#class-privilegedkeymanager), [ScriptTemplateUnlock](#interface-scripttemplateunlock), [Services](#class-services), [SetupEnv](#interface-setupenv), [SetupWallet](#interface-setupwallet), [SetupWalletArgs](#interface-setupwalletargs), [SetupWalletClient](#interface-setupwalletclient), [SetupWalletClientArgs](#interface-setupwalletclientargs), [Wallet](#class-wallet), [WalletStorageManager](#class-walletstoragemanager)
|
|
395
|
+
|
|
396
|
+
<details>
|
|
397
|
+
|
|
398
|
+
<summary>Class SetupClient Details</summary>
|
|
399
|
+
|
|
400
|
+
#### Method createWallet
|
|
401
|
+
|
|
402
|
+
Create a `Wallet`. Storage can optionally be provided or configured later.
|
|
403
|
+
|
|
404
|
+
The following components are configured: KeyDeriver, WalletStorageManager, WalletService, WalletStorage.
|
|
405
|
+
Optionally, PrivilegedKeyManager is also configured.
|
|
406
|
+
|
|
407
|
+
```ts
|
|
408
|
+
static async createWallet(args: SetupWalletArgs): Promise<SetupWallet> {
|
|
409
|
+
args.chain ||= args.env.chain;
|
|
410
|
+
args.rootKeyHex ||= args.env.devKeys[args.env.identityKey];
|
|
411
|
+
const rootKey = PrivateKey.fromHex(args.rootKeyHex);
|
|
412
|
+
const identityKey = rootKey.toPublicKey().toString();
|
|
413
|
+
const keyDeriver = new KeyDeriver(rootKey);
|
|
414
|
+
const chain = args.chain;
|
|
415
|
+
const storage = new WalletStorageManager(identityKey, args.active, args.backups);
|
|
416
|
+
if (storage.stores.length > 0)
|
|
417
|
+
await storage.makeAvailable();
|
|
418
|
+
const serviceOptions = Services.createDefaultOptions(chain);
|
|
419
|
+
serviceOptions.taalApiKey = args.env.taalApiKey;
|
|
420
|
+
const services = new Services(args.chain);
|
|
421
|
+
const monopts = Monitor.createDefaultWalletMonitorOptions(chain, storage, services);
|
|
422
|
+
const monitor = new Monitor(monopts);
|
|
423
|
+
monitor.addDefaultTasks();
|
|
424
|
+
let privilegedKeyManager: sdk.PrivilegedKeyManager | undefined = undefined;
|
|
425
|
+
if (args.privKeyHex) {
|
|
426
|
+
const privKey = PrivateKey.fromString(args.privKeyHex);
|
|
427
|
+
privilegedKeyManager = new sdk.PrivilegedKeyManager(async () => privKey);
|
|
428
|
+
}
|
|
429
|
+
const wallet = new Wallet({
|
|
430
|
+
chain,
|
|
431
|
+
keyDeriver,
|
|
432
|
+
storage,
|
|
433
|
+
services,
|
|
434
|
+
monitor,
|
|
435
|
+
privilegedKeyManager
|
|
436
|
+
});
|
|
437
|
+
const r: SetupWallet = {
|
|
438
|
+
rootKey,
|
|
439
|
+
identityKey,
|
|
440
|
+
keyDeriver,
|
|
441
|
+
chain,
|
|
442
|
+
storage,
|
|
443
|
+
services,
|
|
444
|
+
monitor,
|
|
445
|
+
wallet
|
|
446
|
+
};
|
|
447
|
+
return r;
|
|
193
448
|
}
|
|
194
449
|
```
|
|
450
|
+
See also: [Monitor](#class-monitor), [PrivilegedKeyManager](#class-privilegedkeymanager), [Services](#class-services), [SetupWallet](#interface-setupwallet), [SetupWalletArgs](#interface-setupwalletargs), [Wallet](#class-wallet), [WalletStorageManager](#class-walletstoragemanager)
|
|
451
|
+
|
|
452
|
+
#### Method getEnv
|
|
453
|
+
|
|
454
|
+
Reads a .env file of the format created by `makeEnv`.
|
|
195
455
|
|
|
196
|
-
|
|
456
|
+
Returns values for designated `chain`.
|
|
457
|
+
|
|
458
|
+
Access private keys through the `devKeys` object: `devKeys[identityKey]`
|
|
459
|
+
|
|
460
|
+
```ts
|
|
461
|
+
static getEnv(chain: sdk.Chain): SetupEnv
|
|
462
|
+
```
|
|
463
|
+
See also: [Chain](#type-chain), [SetupEnv](#interface-setupenv)
|
|
464
|
+
|
|
465
|
+
Returns
|
|
466
|
+
|
|
467
|
+
with configuration environment secrets used by `Setup` functions.
|
|
468
|
+
|
|
469
|
+
Argument Details
|
|
470
|
+
|
|
471
|
+
+ **chain**
|
|
472
|
+
+ Which chain to use: 'test' or 'main'
|
|
473
|
+
|
|
474
|
+
#### Method makeEnv
|
|
475
|
+
|
|
476
|
+
Creates content for .env file with some private keys, identity keys, sample API keys, and sample MySQL connection string.
|
|
477
|
+
|
|
478
|
+
Two new, random private keys are generated each time, with their associated public identity keys.
|
|
479
|
+
|
|
480
|
+
Loading secrets from a .env file is intended only for experimentation and getting started.
|
|
481
|
+
Private keys should never be included directly in your source code.
|
|
482
|
+
|
|
483
|
+
```ts
|
|
484
|
+
static makeEnv(): string
|
|
485
|
+
```
|
|
486
|
+
|
|
487
|
+
</details>
|
|
197
488
|
|
|
198
489
|
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
199
490
|
|