@bsv/wallet-toolbox 1.6.1 → 1.6.3
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 +8 -0
- package/docs/client.md +330 -2502
- package/docs/services.md +15 -4
- package/docs/wallet.md +330 -2502
- package/mobile/out/src/services/Services.d.ts.map +1 -1
- package/mobile/out/src/services/Services.js +7 -3
- package/mobile/out/src/services/Services.js.map +1 -1
- package/mobile/out/src/services/chaintracker/chaintracks/Ingest/BulkIngestorCDN.d.ts.map +1 -1
- package/mobile/out/src/services/chaintracker/chaintracks/Ingest/BulkIngestorCDN.js +1 -2
- package/mobile/out/src/services/chaintracker/chaintracks/Ingest/BulkIngestorCDN.js.map +1 -1
- package/mobile/out/src/services/chaintracker/chaintracks/Ingest/LiveIngestorWhatsOnChainPoll.d.ts.map +1 -1
- package/mobile/out/src/services/chaintracker/chaintracks/Ingest/LiveIngestorWhatsOnChainPoll.js +1 -14
- package/mobile/out/src/services/chaintracker/chaintracks/Ingest/LiveIngestorWhatsOnChainPoll.js.map +1 -1
- package/mobile/out/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainServices.d.ts +1 -0
- package/mobile/out/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainServices.d.ts.map +1 -1
- package/mobile/out/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainServices.js +18 -0
- package/mobile/out/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainServices.js.map +1 -1
- package/mobile/out/src/services/chaintracker/chaintracks/util/BulkFileDataManager.d.ts.map +1 -1
- package/mobile/out/src/services/chaintracker/chaintracks/util/BulkFileDataManager.js +2 -3
- package/mobile/out/src/services/chaintracker/chaintracks/util/BulkFileDataManager.js.map +1 -1
- package/mobile/out/src/services/createDefaultWalletServicesOptions.js +4 -2
- package/mobile/out/src/services/createDefaultWalletServicesOptions.js.map +1 -1
- package/mobile/out/src/signer/methods/internalizeAction.js +2 -2
- package/mobile/out/src/signer/methods/internalizeAction.js.map +1 -1
- package/mobile/out/src/storage/StorageProvider.d.ts.map +1 -1
- package/mobile/out/src/storage/StorageProvider.js +1 -0
- package/mobile/out/src/storage/StorageProvider.js.map +1 -1
- package/mobile/out/src/utility/utilityHelpers.d.ts +2 -0
- package/mobile/out/src/utility/utilityHelpers.d.ts.map +1 -1
- package/mobile/out/src/utility/utilityHelpers.js +7 -0
- package/mobile/out/src/utility/utilityHelpers.js.map +1 -1
- package/mobile/package-lock.json +2 -2
- package/mobile/package.json +1 -1
- package/out/src/services/Services.d.ts.map +1 -1
- package/out/src/services/Services.js +7 -3
- package/out/src/services/Services.js.map +1 -1
- package/out/src/services/chaintracker/__tests/ChaintracksServiceClient.test.js +3 -1
- package/out/src/services/chaintracker/__tests/ChaintracksServiceClient.test.js.map +1 -1
- package/out/src/services/chaintracker/chaintracks/Ingest/BulkIngestorCDN.d.ts.map +1 -1
- package/out/src/services/chaintracker/chaintracks/Ingest/BulkIngestorCDN.js +1 -2
- package/out/src/services/chaintracker/chaintracks/Ingest/BulkIngestorCDN.js.map +1 -1
- package/out/src/services/chaintracker/chaintracks/Ingest/LiveIngestorWhatsOnChainPoll.d.ts.map +1 -1
- package/out/src/services/chaintracker/chaintracks/Ingest/LiveIngestorWhatsOnChainPoll.js +1 -14
- package/out/src/services/chaintracker/chaintracks/Ingest/LiveIngestorWhatsOnChainPoll.js.map +1 -1
- package/out/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainServices.d.ts +1 -0
- package/out/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainServices.d.ts.map +1 -1
- package/out/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainServices.js +18 -0
- package/out/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainServices.js.map +1 -1
- package/out/src/services/chaintracker/chaintracks/__tests/ChaintracksClientApi.test.js +24 -15
- package/out/src/services/chaintracker/chaintracks/__tests/ChaintracksClientApi.test.js.map +1 -1
- package/out/src/services/chaintracker/chaintracks/__tests/LocalCdnServer.d.ts.map +1 -1
- package/out/src/services/chaintracker/chaintracks/__tests/LocalCdnServer.js +9 -2
- package/out/src/services/chaintracker/chaintracks/__tests/LocalCdnServer.js.map +1 -1
- package/out/src/services/chaintracker/chaintracks/util/BulkFileDataManager.d.ts.map +1 -1
- package/out/src/services/chaintracker/chaintracks/util/BulkFileDataManager.js +2 -3
- package/out/src/services/chaintracker/chaintracks/util/BulkFileDataManager.js.map +1 -1
- package/out/src/services/createDefaultWalletServicesOptions.js +4 -2
- package/out/src/services/createDefaultWalletServicesOptions.js.map +1 -1
- package/out/src/signer/methods/internalizeAction.js +2 -2
- package/out/src/signer/methods/internalizeAction.js.map +1 -1
- package/out/src/storage/StorageProvider.d.ts.map +1 -1
- package/out/src/storage/StorageProvider.js +1 -0
- package/out/src/storage/StorageProvider.js.map +1 -1
- package/out/src/storage/__test/getBeefForTransaction.test.js +8 -6
- package/out/src/storage/__test/getBeefForTransaction.test.js.map +1 -1
- package/out/src/utility/Format.js +2 -2
- package/out/src/utility/utilityHelpers.d.ts +2 -0
- package/out/src/utility/utilityHelpers.d.ts.map +1 -1
- package/out/src/utility/utilityHelpers.js +7 -0
- package/out/src/utility/utilityHelpers.js.map +1 -1
- package/out/test/storage/idb/update.test.js +1 -1
- package/out/test/storage/idb/update.test.js.map +1 -1
- package/out/tsconfig.all.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/services/Services.ts +6 -2
- package/src/services/chaintracker/__tests/ChaintracksServiceClient.test.ts +3 -1
- package/src/services/chaintracker/chaintracks/Ingest/BulkIngestorCDN.ts +1 -2
- package/src/services/chaintracker/chaintracks/Ingest/LiveIngestorWhatsOnChainPoll.ts +3 -17
- package/src/services/chaintracker/chaintracks/Ingest/WhatsOnChainServices.ts +19 -0
- package/src/services/chaintracker/chaintracks/__tests/ChaintracksClientApi.test.ts +26 -16
- package/src/services/chaintracker/chaintracks/__tests/LocalCdnServer.ts +10 -2
- package/src/services/chaintracker/chaintracks/util/BulkFileDataManager.ts +2 -3
- package/src/services/createDefaultWalletServicesOptions.ts +5 -5
- package/src/signer/methods/internalizeAction.ts +2 -2
- package/src/storage/StorageProvider.ts +1 -0
- package/src/storage/__test/getBeefForTransaction.test.ts +34 -35
- package/src/utility/Format.ts +2 -2
- package/src/utility/utilityHelpers.ts +7 -0
- package/test/storage/idb/update.test.ts +1 -1
- package/mobile/out/src/Setup.d.ts +0 -267
- package/mobile/out/src/Setup.d.ts.map +0 -1
- package/mobile/out/src/Setup.js +0 -408
- package/mobile/out/src/Setup.js.map +0 -1
- package/mobile/out/src/storage/StorageKnex.d.ts +0 -179
- package/mobile/out/src/storage/StorageKnex.d.ts.map +0 -1
- package/mobile/out/src/storage/StorageKnex.js +0 -1215
- package/mobile/out/src/storage/StorageKnex.js.map +0 -1
- package/mobile/out/src/storage/methods/listActionsKnex.d.ts +0 -6
- package/mobile/out/src/storage/methods/listActionsKnex.d.ts.map +0 -1
- package/mobile/out/src/storage/methods/listActionsKnex.js +0 -198
- package/mobile/out/src/storage/methods/listActionsKnex.js.map +0 -1
- package/mobile/out/src/storage/methods/listOutputsKnex.d.ts +0 -6
- package/mobile/out/src/storage/methods/listOutputsKnex.d.ts.map +0 -1
- package/mobile/out/src/storage/methods/listOutputsKnex.js +0 -241
- package/mobile/out/src/storage/methods/listOutputsKnex.js.map +0 -1
- package/mobile/out/src/storage/methods/purgeData.d.ts +0 -4
- package/mobile/out/src/storage/methods/purgeData.d.ts.map +0 -1
- package/mobile/out/src/storage/methods/purgeData.js +0 -207
- package/mobile/out/src/storage/methods/purgeData.js.map +0 -1
- package/mobile/out/src/storage/methods/reviewStatus.d.ts +0 -20
- package/mobile/out/src/storage/methods/reviewStatus.d.ts.map +0 -1
- package/mobile/out/src/storage/methods/reviewStatus.js +0 -84
- package/mobile/out/src/storage/methods/reviewStatus.js.map +0 -1
- package/mobile/out/src/storage/schema/KnexMigrations.d.ts +0 -39
- package/mobile/out/src/storage/schema/KnexMigrations.d.ts.map +0 -1
- package/mobile/out/src/storage/schema/KnexMigrations.js +0 -410
- package/mobile/out/src/storage/schema/KnexMigrations.js.map +0 -1
- package/mobile/out/test/utils/TestUtilsWalletStorage.d.ts +0 -522
- package/mobile/out/test/utils/TestUtilsWalletStorage.d.ts.map +0 -1
- package/mobile/out/test/utils/TestUtilsWalletStorage.js +0 -1956
- package/mobile/out/test/utils/TestUtilsWalletStorage.js.map +0 -1
|
@@ -1,267 +0,0 @@
|
|
|
1
|
-
import { Knex } from 'knex';
|
|
2
|
-
import { KeyPairAddress, SetupWallet, SetupWalletClient } from './SetupWallet';
|
|
3
|
-
import { BEEF, CreateActionOptions, CreateActionOutput, CreateActionResult, KeyDeriverApi, LockingScript, PrivateKey, ScriptTemplateUnlock, WalletInterface } from '@bsv/sdk';
|
|
4
|
-
import { Chain } from './sdk/types';
|
|
5
|
-
import { WalletStorageManager } from './storage/WalletStorageManager';
|
|
6
|
-
import { Services } from './services/Services';
|
|
7
|
-
import { Monitor } from './monitor/Monitor';
|
|
8
|
-
import { Wallet } from './Wallet';
|
|
9
|
-
import { StorageKnex } from './storage/StorageKnex';
|
|
10
|
-
import { WalletStorageProvider } from './sdk/WalletStorage.interfaces';
|
|
11
|
-
/**
|
|
12
|
-
* The 'Setup` class provides static setup functions to construct BRC-100 compatible
|
|
13
|
-
* wallets in a variety of configurations.
|
|
14
|
-
*
|
|
15
|
-
* It serves as a starting point for experimentation and customization.
|
|
16
|
-
*/
|
|
17
|
-
export declare abstract class Setup {
|
|
18
|
-
/**
|
|
19
|
-
* @param chain
|
|
20
|
-
* @returns true if .env is not valid for chain
|
|
21
|
-
*/
|
|
22
|
-
static noEnv(chain: Chain): boolean;
|
|
23
|
-
/**
|
|
24
|
-
* Creates content for .env file with some private keys, identity keys, sample API keys, and sample MySQL connection string.
|
|
25
|
-
*
|
|
26
|
-
* Two new, random private keys are generated each time, with their associated public identity keys.
|
|
27
|
-
*
|
|
28
|
-
* Loading secrets from a .env file is intended only for experimentation and getting started.
|
|
29
|
-
* Private keys should never be included directly in your source code.
|
|
30
|
-
*
|
|
31
|
-
* @publicbody
|
|
32
|
-
*/
|
|
33
|
-
static makeEnv(): string;
|
|
34
|
-
/**
|
|
35
|
-
* Reads a .env file of the format created by `makeEnv`.
|
|
36
|
-
*
|
|
37
|
-
* Returns values for designated `chain`.
|
|
38
|
-
*
|
|
39
|
-
* Access private keys through the `devKeys` object: `devKeys[identityKey]`
|
|
40
|
-
*
|
|
41
|
-
* @param chain Which chain to use: 'test' or 'main'
|
|
42
|
-
* @returns {SetupEnv} with configuration environment secrets used by `Setup` functions.
|
|
43
|
-
*
|
|
44
|
-
* @publicbody
|
|
45
|
-
*/
|
|
46
|
-
static getEnv(chain: Chain): SetupEnv;
|
|
47
|
-
/**
|
|
48
|
-
* Create a `Wallet`. Storage can optionally be provided or configured later.
|
|
49
|
-
*
|
|
50
|
-
* The following components are configured: KeyDeriver, WalletStorageManager, WalletService, WalletStorage.
|
|
51
|
-
* Optionally, PrivilegedKeyManager is also configured.
|
|
52
|
-
*
|
|
53
|
-
* @publicbody
|
|
54
|
-
*/
|
|
55
|
-
static createWallet(args: SetupWalletArgs): Promise<SetupWallet>;
|
|
56
|
-
/**
|
|
57
|
-
* Setup a new `Wallet` without requiring a .env file.
|
|
58
|
-
*
|
|
59
|
-
* @param args.chain - 'main' or 'test'
|
|
60
|
-
* @param args.rootKeyHex - Root private key for wallet's key deriver.
|
|
61
|
-
* @param args.storageUrl - Optional. `StorageClient` and `chain` compatible endpoint URL.
|
|
62
|
-
* @param args.privilegedKeyGetter - Optional. Method that will return the privileged `PrivateKey`, on demand.
|
|
63
|
-
*/
|
|
64
|
-
static createWalletClientNoEnv(args: {
|
|
65
|
-
chain: Chain;
|
|
66
|
-
rootKeyHex: string;
|
|
67
|
-
storageUrl?: string;
|
|
68
|
-
privilegedKeyGetter?: () => Promise<PrivateKey>;
|
|
69
|
-
}): Promise<Wallet>;
|
|
70
|
-
/**
|
|
71
|
-
* @publicbody
|
|
72
|
-
*/
|
|
73
|
-
static createWalletClient(args: SetupWalletClientArgs): Promise<SetupWalletClient>;
|
|
74
|
-
/**
|
|
75
|
-
* @publicbody
|
|
76
|
-
*/
|
|
77
|
-
static getKeyPair(priv?: string | PrivateKey): KeyPairAddress;
|
|
78
|
-
/**
|
|
79
|
-
* @publicbody
|
|
80
|
-
*/
|
|
81
|
-
static getLockP2PKH(address: string): LockingScript;
|
|
82
|
-
/**
|
|
83
|
-
* @publicbody
|
|
84
|
-
*/
|
|
85
|
-
static getUnlockP2PKH(priv: PrivateKey, satoshis: number): ScriptTemplateUnlock;
|
|
86
|
-
/**
|
|
87
|
-
* @publicbody
|
|
88
|
-
*/
|
|
89
|
-
static createP2PKHOutputs(outputs: {
|
|
90
|
-
address: string;
|
|
91
|
-
satoshis: number;
|
|
92
|
-
outputDescription?: string;
|
|
93
|
-
basket?: string;
|
|
94
|
-
tags?: string[];
|
|
95
|
-
}[]): CreateActionOutput[];
|
|
96
|
-
/**
|
|
97
|
-
* @publicbody
|
|
98
|
-
*/
|
|
99
|
-
static createP2PKHOutputsAction(wallet: WalletInterface, outputs: {
|
|
100
|
-
address: string;
|
|
101
|
-
satoshis: number;
|
|
102
|
-
outputDescription?: string;
|
|
103
|
-
basket?: string;
|
|
104
|
-
tags?: string[];
|
|
105
|
-
}[], options?: CreateActionOptions): Promise<{
|
|
106
|
-
cr: CreateActionResult;
|
|
107
|
-
outpoints: string[] | undefined;
|
|
108
|
-
}>;
|
|
109
|
-
/**
|
|
110
|
-
* @publicbody
|
|
111
|
-
*/
|
|
112
|
-
static fundWalletFromP2PKHOutpoints(wallet: WalletInterface, outpoints: string[], p2pkhKey: KeyPairAddress, inputBEEF?: BEEF): Promise<void>;
|
|
113
|
-
/**
|
|
114
|
-
* Adds `Knex` based storage to a `Wallet` configured by `Setup.createWalletOnly`
|
|
115
|
-
*
|
|
116
|
-
* @param args.knex `Knex` object configured for either MySQL or SQLite database access.
|
|
117
|
-
* Schema will be created and migrated as needed.
|
|
118
|
-
* For MySQL, a schema corresponding to databaseName must exist with full access permissions.
|
|
119
|
-
* @param args.databaseName Name for this storage. For MySQL, the schema name within the MySQL instance.
|
|
120
|
-
* @param args.chain Which chain this wallet is on: 'main' or 'test'. Defaults to 'test'.
|
|
121
|
-
* @param args.rootKeyHex
|
|
122
|
-
*
|
|
123
|
-
* @publicbody
|
|
124
|
-
*/
|
|
125
|
-
static createWalletKnex(args: SetupWalletKnexArgs): Promise<SetupWalletKnex>;
|
|
126
|
-
/**
|
|
127
|
-
* @returns {StorageKnex} - `Knex` based storage provider for a wallet. May be used for either active storage or backup storage.
|
|
128
|
-
*/
|
|
129
|
-
static createStorageKnex(args: SetupWalletKnexArgs): Promise<StorageKnex>;
|
|
130
|
-
/**
|
|
131
|
-
* @publicbody
|
|
132
|
-
*/
|
|
133
|
-
static createSQLiteKnex(filename: string): Knex;
|
|
134
|
-
/**
|
|
135
|
-
* @publicbody
|
|
136
|
-
*/
|
|
137
|
-
static createMySQLKnex(connection: string, database?: string): Knex;
|
|
138
|
-
/**
|
|
139
|
-
* @publicbody
|
|
140
|
-
*/
|
|
141
|
-
static createWalletMySQL(args: SetupWalletMySQLArgs): Promise<SetupWalletKnex>;
|
|
142
|
-
/**
|
|
143
|
-
* @publicbody
|
|
144
|
-
*/
|
|
145
|
-
static createWalletSQLite(args: SetupWalletSQLiteArgs): Promise<SetupWalletKnex>;
|
|
146
|
-
}
|
|
147
|
-
/**
|
|
148
|
-
* Arguments used by `createWallet` to construct a `SetupWallet`.
|
|
149
|
-
*
|
|
150
|
-
* Extension `SetupWalletClientArgs` used by `createWalletClient` to construct a `SetupWalletClient`.
|
|
151
|
-
*
|
|
152
|
-
* Extension `SetupWalletKnexArgs` used by `createWalletKnex` to construct a `SetupWalletKnex`.
|
|
153
|
-
*
|
|
154
|
-
* Extension `SetupWalletMySQLArgs` used by `createWalletMySQL` to construct a `SetupWalletKnex`.
|
|
155
|
-
*
|
|
156
|
-
* Extension `SetupWalletSQLiteArgs` used by `createWalletSQLite` to construct a `SetupWalletKnex`.
|
|
157
|
-
*/
|
|
158
|
-
export interface SetupWalletArgs {
|
|
159
|
-
/**
|
|
160
|
-
* Configuration "secrets" typically obtained by `Setup.makeEnv` and `Setup.getEnv` functions.
|
|
161
|
-
*/
|
|
162
|
-
env: SetupEnv;
|
|
163
|
-
/**
|
|
164
|
-
* Optional. The non-privileged private key used to initialize the `KeyDeriver` and determine the `identityKey`.
|
|
165
|
-
* Defaults to `env.devKeys[env.identityKey]
|
|
166
|
-
*/
|
|
167
|
-
rootKeyHex?: string;
|
|
168
|
-
/**
|
|
169
|
-
* Optional. The privileged private key getter used to initialize the `PrivilegedKeyManager`.
|
|
170
|
-
* Defaults to undefined.
|
|
171
|
-
*/
|
|
172
|
-
privilegedKeyGetter?: () => Promise<PrivateKey>;
|
|
173
|
-
/**
|
|
174
|
-
* Optional. Active wallet storage. Can be added later.
|
|
175
|
-
*/
|
|
176
|
-
active?: WalletStorageProvider;
|
|
177
|
-
/**
|
|
178
|
-
* Optional. One or more storage providers managed as backup destinations. Can be added later.
|
|
179
|
-
*/
|
|
180
|
-
backups?: WalletStorageProvider[];
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
*
|
|
184
|
-
*/
|
|
185
|
-
export interface SetupWalletKnexArgs extends SetupWalletArgs {
|
|
186
|
-
knex: Knex<any, any[]>;
|
|
187
|
-
databaseName: string;
|
|
188
|
-
}
|
|
189
|
-
/**
|
|
190
|
-
*
|
|
191
|
-
*/
|
|
192
|
-
export interface SetupWalletMySQLArgs extends SetupWalletArgs {
|
|
193
|
-
databaseName: string;
|
|
194
|
-
}
|
|
195
|
-
/**
|
|
196
|
-
*
|
|
197
|
-
*/
|
|
198
|
-
export interface SetupWalletSQLiteArgs extends SetupWalletArgs {
|
|
199
|
-
filePath: string;
|
|
200
|
-
databaseName: string;
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
*
|
|
204
|
-
*/
|
|
205
|
-
export interface SetupWalletKnex extends SetupWallet {
|
|
206
|
-
activeStorage: StorageKnex;
|
|
207
|
-
userId: number;
|
|
208
|
-
rootKey: PrivateKey;
|
|
209
|
-
identityKey: string;
|
|
210
|
-
keyDeriver: KeyDeriverApi;
|
|
211
|
-
chain: Chain;
|
|
212
|
-
storage: WalletStorageManager;
|
|
213
|
-
services: Services;
|
|
214
|
-
monitor: Monitor;
|
|
215
|
-
wallet: Wallet;
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* `SetupEnv` provides a starting point for managing secrets that
|
|
219
|
-
* must not appear in source code.
|
|
220
|
-
*
|
|
221
|
-
* The `makeEnv` and `getEnv` functions of the `Setup` and `SetupClient` classes
|
|
222
|
-
* provide an easy way to create and import these secrets and related properties.
|
|
223
|
-
*/
|
|
224
|
-
export interface SetupEnv {
|
|
225
|
-
/**
|
|
226
|
-
* The chan being accessed: 'main' for mainnet, 'test' for 'testnet'.
|
|
227
|
-
*/
|
|
228
|
-
chain: Chain;
|
|
229
|
-
/**
|
|
230
|
-
* The user's primary identity key (public key).
|
|
231
|
-
*/
|
|
232
|
-
identityKey: string;
|
|
233
|
-
/**
|
|
234
|
-
* A secondary identity key (public key), used to test exchanges with other users.
|
|
235
|
-
*/
|
|
236
|
-
identityKey2: string;
|
|
237
|
-
/**
|
|
238
|
-
* Filepath to sqlite file to be used for identityKey wallet.
|
|
239
|
-
*/
|
|
240
|
-
filePath: string | undefined;
|
|
241
|
-
/**
|
|
242
|
-
* A vaild TAAL API key for use by `Services`
|
|
243
|
-
*/
|
|
244
|
-
taalApiKey: string;
|
|
245
|
-
/**
|
|
246
|
-
* A map of public keys (identity keys, hex strings) to private keys (hex strings).
|
|
247
|
-
*/
|
|
248
|
-
devKeys: Record<string, string>;
|
|
249
|
-
/**
|
|
250
|
-
* A MySQL connection string including user and password properties.
|
|
251
|
-
* Must be valid to make use of MySQL `Setup` class support.
|
|
252
|
-
*/
|
|
253
|
-
mySQLConnection: string;
|
|
254
|
-
}
|
|
255
|
-
/**
|
|
256
|
-
* Extension `SetupWalletClientArgs` of `SetupWalletArgs` is used by `createWalletClient`
|
|
257
|
-
* to construct a `SetupWalletClient`.
|
|
258
|
-
*/
|
|
259
|
-
export interface SetupWalletClientArgs extends SetupWalletArgs {
|
|
260
|
-
/**
|
|
261
|
-
* The endpoint URL of a service hosting the `StorageServer` JSON-RPC service to
|
|
262
|
-
* which a `StorageClient` instance should connect to function as
|
|
263
|
-
* the active storage provider of the newly created wallet.
|
|
264
|
-
*/
|
|
265
|
-
endpointUrl?: string;
|
|
266
|
-
}
|
|
267
|
-
//# sourceMappingURL=Setup.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Setup.d.ts","sourceRoot":"","sources":["../../../src/Setup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAoB,MAAM,MAAM,CAAA;AAC7C,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAC9E,OAAO,EACL,IAAI,EAGJ,mBAAmB,EACnB,kBAAkB,EAClB,kBAAkB,EAElB,aAAa,EACb,aAAa,EAEb,UAAU,EAEV,oBAAoB,EACpB,eAAe,EAChB,MAAM,UAAU,CAAA;AACjB,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAA;AAGnC,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAA;AACrE,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAA;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAA;AAE3C,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAEjC,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACnD,OAAO,EAAE,qBAAqB,EAAE,MAAM,gCAAgC,CAAA;AAQtE;;;;;GAKG;AACH,8BAAsB,KAAK;IACzB;;;OAGG;IACH,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO;IASn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AAM,CAAA;CACrB"}
|
package/mobile/out/src/Setup.js
DELETED
|
@@ -1,408 +0,0 @@
|
|
|
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 () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.Setup = void 0;
|
|
37
|
-
const knex_1 = require("knex");
|
|
38
|
-
const sdk_1 = require("@bsv/sdk");
|
|
39
|
-
const utilityHelpers_1 = require("./utility/utilityHelpers");
|
|
40
|
-
const WERR_errors_1 = require("./sdk/WERR_errors");
|
|
41
|
-
const WalletStorageManager_1 = require("./storage/WalletStorageManager");
|
|
42
|
-
const Services_1 = require("./services/Services");
|
|
43
|
-
const Monitor_1 = require("./monitor/Monitor");
|
|
44
|
-
const PrivilegedKeyManager_1 = require("./sdk/PrivilegedKeyManager");
|
|
45
|
-
const Wallet_1 = require("./Wallet");
|
|
46
|
-
const StorageClient_1 = require("./storage/remoting/StorageClient");
|
|
47
|
-
const StorageKnex_1 = require("./storage/StorageKnex");
|
|
48
|
-
// To rely on your own headers service, uncomment the following line:
|
|
49
|
-
// import { BHServiceClient } from './services/chaintracker'
|
|
50
|
-
const dotenv = __importStar(require("dotenv"));
|
|
51
|
-
dotenv.config();
|
|
52
|
-
/**
|
|
53
|
-
* The 'Setup` class provides static setup functions to construct BRC-100 compatible
|
|
54
|
-
* wallets in a variety of configurations.
|
|
55
|
-
*
|
|
56
|
-
* It serves as a starting point for experimentation and customization.
|
|
57
|
-
*/
|
|
58
|
-
class Setup {
|
|
59
|
-
/**
|
|
60
|
-
* @param chain
|
|
61
|
-
* @returns true if .env is not valid for chain
|
|
62
|
-
*/
|
|
63
|
-
static noEnv(chain) {
|
|
64
|
-
try {
|
|
65
|
-
Setup.getEnv(chain);
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
catch (_a) {
|
|
69
|
-
return true;
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* Creates content for .env file with some private keys, identity keys, sample API keys, and sample MySQL connection string.
|
|
74
|
-
*
|
|
75
|
-
* Two new, random private keys are generated each time, with their associated public identity keys.
|
|
76
|
-
*
|
|
77
|
-
* Loading secrets from a .env file is intended only for experimentation and getting started.
|
|
78
|
-
* Private keys should never be included directly in your source code.
|
|
79
|
-
*
|
|
80
|
-
* @publicbody
|
|
81
|
-
*/
|
|
82
|
-
static makeEnv() {
|
|
83
|
-
const testPrivKey1 = sdk_1.PrivateKey.fromRandom();
|
|
84
|
-
const testIdentityKey1 = testPrivKey1.toPublicKey().toString();
|
|
85
|
-
const testPrivKey2 = sdk_1.PrivateKey.fromRandom();
|
|
86
|
-
const testIdentityKey2 = testPrivKey2.toPublicKey().toString();
|
|
87
|
-
const mainPrivKey1 = sdk_1.PrivateKey.fromRandom();
|
|
88
|
-
const mainIdentityKey1 = mainPrivKey1.toPublicKey().toString();
|
|
89
|
-
const mainPrivKey2 = sdk_1.PrivateKey.fromRandom();
|
|
90
|
-
const mainIdentityKey2 = mainPrivKey2.toPublicKey().toString();
|
|
91
|
-
const log = `
|
|
92
|
-
# .env file template for working with wallet-toolbox Setup functions.
|
|
93
|
-
MY_TEST_IDENTITY = '${testIdentityKey1}'
|
|
94
|
-
MY_TEST_IDENTITY2 = '${testIdentityKey2}'
|
|
95
|
-
MY_MAIN_IDENTITY = '${mainIdentityKey1}'
|
|
96
|
-
MY_MAIN_IDENTITY2 = '${mainIdentityKey2}'
|
|
97
|
-
MAIN_TAAL_API_KEY='mainnet_9596de07e92300c6287e4393594ae39c'
|
|
98
|
-
TEST_TAAL_API_KEY='testnet_0e6cf72133b43ea2d7861da2a38684e3'
|
|
99
|
-
MYSQL_CONNECTION='{"port":3306,"host":"127.0.0.1","user":"root","password":"your_password","database":"your_database", "timezone": "Z"}'
|
|
100
|
-
DEV_KEYS = '{
|
|
101
|
-
"${testIdentityKey1}": "${testPrivKey1.toString()}",
|
|
102
|
-
"${testIdentityKey2}": "${testPrivKey2.toString()}",
|
|
103
|
-
"${mainIdentityKey1}": "${mainPrivKey1.toString()}",
|
|
104
|
-
"${mainIdentityKey2}": "${mainPrivKey2.toString()}"
|
|
105
|
-
}'
|
|
106
|
-
`;
|
|
107
|
-
console.log(log);
|
|
108
|
-
return log;
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Reads a .env file of the format created by `makeEnv`.
|
|
112
|
-
*
|
|
113
|
-
* Returns values for designated `chain`.
|
|
114
|
-
*
|
|
115
|
-
* Access private keys through the `devKeys` object: `devKeys[identityKey]`
|
|
116
|
-
*
|
|
117
|
-
* @param chain Which chain to use: 'test' or 'main'
|
|
118
|
-
* @returns {SetupEnv} with configuration environment secrets used by `Setup` functions.
|
|
119
|
-
*
|
|
120
|
-
* @publicbody
|
|
121
|
-
*/
|
|
122
|
-
static getEnv(chain) {
|
|
123
|
-
// Identity keys of the lead maintainer of this repo...
|
|
124
|
-
const identityKey = chain === 'main' ? process.env.MY_MAIN_IDENTITY : process.env.MY_TEST_IDENTITY;
|
|
125
|
-
const identityKey2 = chain === 'main' ? process.env.MY_MAIN_IDENTITY2 : process.env.MY_TEST_IDENTITY2;
|
|
126
|
-
const filePath = chain === 'main' ? process.env.MY_MAIN_FILEPATH : process.env.MY_TEST_FILEPATH;
|
|
127
|
-
const DEV_KEYS = process.env.DEV_KEYS || '{}';
|
|
128
|
-
const mySQLConnection = process.env.MYSQL_CONNECTION || '{}';
|
|
129
|
-
const taalApiKey = (0, utilityHelpers_1.verifyTruthy)(chain === 'main' ? process.env.MAIN_TAAL_API_KEY : process.env.TEST_TAAL_API_KEY, `.env value for '${chain.toUpperCase()}_TAAL_API_KEY' is required.`);
|
|
130
|
-
if (!identityKey || !identityKey2)
|
|
131
|
-
throw new WERR_errors_1.WERR_INVALID_OPERATION('.env is not a valid SetupEnv configuration.');
|
|
132
|
-
return {
|
|
133
|
-
chain,
|
|
134
|
-
identityKey,
|
|
135
|
-
identityKey2,
|
|
136
|
-
filePath,
|
|
137
|
-
taalApiKey,
|
|
138
|
-
devKeys: JSON.parse(DEV_KEYS),
|
|
139
|
-
mySQLConnection
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Create a `Wallet`. Storage can optionally be provided or configured later.
|
|
144
|
-
*
|
|
145
|
-
* The following components are configured: KeyDeriver, WalletStorageManager, WalletService, WalletStorage.
|
|
146
|
-
* Optionally, PrivilegedKeyManager is also configured.
|
|
147
|
-
*
|
|
148
|
-
* @publicbody
|
|
149
|
-
*/
|
|
150
|
-
static async createWallet(args) {
|
|
151
|
-
const chain = args.env.chain;
|
|
152
|
-
args.rootKeyHex || (args.rootKeyHex = args.env.devKeys[args.env.identityKey]);
|
|
153
|
-
const rootKey = sdk_1.PrivateKey.fromHex(args.rootKeyHex);
|
|
154
|
-
const identityKey = rootKey.toPublicKey().toString();
|
|
155
|
-
const keyDeriver = new sdk_1.CachedKeyDeriver(rootKey);
|
|
156
|
-
const storage = new WalletStorageManager_1.WalletStorageManager(identityKey, args.active, args.backups);
|
|
157
|
-
if (storage.canMakeAvailable())
|
|
158
|
-
await storage.makeAvailable();
|
|
159
|
-
const serviceOptions = Services_1.Services.createDefaultOptions(chain);
|
|
160
|
-
serviceOptions.taalApiKey = args.env.taalApiKey;
|
|
161
|
-
// To rely on your own headers service, uncomment the following line, updating the url and apiKey to your own values.
|
|
162
|
-
// serviceOptions.chaintracks = new BHServiceClient('main', 'https://headers.spv.money', 'fC42F069YJs30FaWBAgikfDFEfIW1j4q')
|
|
163
|
-
const services = new Services_1.Services(serviceOptions);
|
|
164
|
-
const monopts = Monitor_1.Monitor.createDefaultWalletMonitorOptions(chain, storage, services);
|
|
165
|
-
const monitor = new Monitor_1.Monitor(monopts);
|
|
166
|
-
monitor.addDefaultTasks();
|
|
167
|
-
const privilegedKeyManager = args.privilegedKeyGetter
|
|
168
|
-
? new PrivilegedKeyManager_1.PrivilegedKeyManager(args.privilegedKeyGetter)
|
|
169
|
-
: undefined;
|
|
170
|
-
const wallet = new Wallet_1.Wallet({
|
|
171
|
-
chain,
|
|
172
|
-
keyDeriver,
|
|
173
|
-
storage,
|
|
174
|
-
services,
|
|
175
|
-
monitor,
|
|
176
|
-
privilegedKeyManager
|
|
177
|
-
});
|
|
178
|
-
const r = {
|
|
179
|
-
rootKey,
|
|
180
|
-
identityKey,
|
|
181
|
-
keyDeriver,
|
|
182
|
-
chain,
|
|
183
|
-
storage,
|
|
184
|
-
services,
|
|
185
|
-
monitor,
|
|
186
|
-
wallet
|
|
187
|
-
};
|
|
188
|
-
return r;
|
|
189
|
-
}
|
|
190
|
-
/**
|
|
191
|
-
* Setup a new `Wallet` without requiring a .env file.
|
|
192
|
-
*
|
|
193
|
-
* @param args.chain - 'main' or 'test'
|
|
194
|
-
* @param args.rootKeyHex - Root private key for wallet's key deriver.
|
|
195
|
-
* @param args.storageUrl - Optional. `StorageClient` and `chain` compatible endpoint URL.
|
|
196
|
-
* @param args.privilegedKeyGetter - Optional. Method that will return the privileged `PrivateKey`, on demand.
|
|
197
|
-
*/
|
|
198
|
-
static async createWalletClientNoEnv(args) {
|
|
199
|
-
const chain = args.chain;
|
|
200
|
-
const endpointUrl = args.storageUrl || `https://${args.chain !== 'main' ? 'staging-' : ''}storage.babbage.systems`;
|
|
201
|
-
const rootKey = sdk_1.PrivateKey.fromHex(args.rootKeyHex);
|
|
202
|
-
const keyDeriver = new sdk_1.CachedKeyDeriver(rootKey);
|
|
203
|
-
const storage = new WalletStorageManager_1.WalletStorageManager(keyDeriver.identityKey);
|
|
204
|
-
const services = new Services_1.Services(chain);
|
|
205
|
-
const privilegedKeyManager = args.privilegedKeyGetter
|
|
206
|
-
? new PrivilegedKeyManager_1.PrivilegedKeyManager(args.privilegedKeyGetter)
|
|
207
|
-
: undefined;
|
|
208
|
-
const wallet = new Wallet_1.Wallet({
|
|
209
|
-
chain,
|
|
210
|
-
keyDeriver,
|
|
211
|
-
storage,
|
|
212
|
-
services,
|
|
213
|
-
privilegedKeyManager
|
|
214
|
-
});
|
|
215
|
-
const client = new StorageClient_1.StorageClient(wallet, endpointUrl);
|
|
216
|
-
await storage.addWalletStorageProvider(client);
|
|
217
|
-
await storage.makeAvailable();
|
|
218
|
-
return wallet;
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* @publicbody
|
|
222
|
-
*/
|
|
223
|
-
static async createWalletClient(args) {
|
|
224
|
-
const wo = await Setup.createWallet(args);
|
|
225
|
-
const endpointUrl = args.endpointUrl || `https://${args.env.chain !== 'main' ? 'staging-' : ''}storage.babbage.systems`;
|
|
226
|
-
const client = new StorageClient_1.StorageClient(wo.wallet, endpointUrl);
|
|
227
|
-
await wo.storage.addWalletStorageProvider(client);
|
|
228
|
-
await wo.storage.makeAvailable();
|
|
229
|
-
return {
|
|
230
|
-
...wo,
|
|
231
|
-
endpointUrl
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
/**
|
|
235
|
-
* @publicbody
|
|
236
|
-
*/
|
|
237
|
-
static getKeyPair(priv) {
|
|
238
|
-
if (priv === undefined)
|
|
239
|
-
priv = sdk_1.PrivateKey.fromRandom();
|
|
240
|
-
else if (typeof priv === 'string')
|
|
241
|
-
priv = new sdk_1.PrivateKey(priv, 'hex');
|
|
242
|
-
const pub = sdk_1.PublicKey.fromPrivateKey(priv);
|
|
243
|
-
const address = pub.toAddress();
|
|
244
|
-
return { privateKey: priv, publicKey: pub, address };
|
|
245
|
-
}
|
|
246
|
-
/**
|
|
247
|
-
* @publicbody
|
|
248
|
-
*/
|
|
249
|
-
static getLockP2PKH(address) {
|
|
250
|
-
const p2pkh = new sdk_1.P2PKH();
|
|
251
|
-
const lock = p2pkh.lock(address);
|
|
252
|
-
return lock;
|
|
253
|
-
}
|
|
254
|
-
/**
|
|
255
|
-
* @publicbody
|
|
256
|
-
*/
|
|
257
|
-
static getUnlockP2PKH(priv, satoshis) {
|
|
258
|
-
const p2pkh = new sdk_1.P2PKH();
|
|
259
|
-
const lock = Setup.getLockP2PKH(Setup.getKeyPair(priv).address);
|
|
260
|
-
// Prepare to pay with SIGHASH_ALL and without ANYONE_CAN_PAY.
|
|
261
|
-
// In otherwords:
|
|
262
|
-
// - all outputs must remain in the current order, amount and locking scripts.
|
|
263
|
-
// - all inputs must remain from the current outpoints and sequence numbers.
|
|
264
|
-
// (unlock scripts are never signed)
|
|
265
|
-
const unlock = p2pkh.unlock(priv, 'all', false, satoshis, lock);
|
|
266
|
-
return unlock;
|
|
267
|
-
}
|
|
268
|
-
/**
|
|
269
|
-
* @publicbody
|
|
270
|
-
*/
|
|
271
|
-
static createP2PKHOutputs(outputs) {
|
|
272
|
-
const os = [];
|
|
273
|
-
const count = outputs.length;
|
|
274
|
-
for (let i = 0; i < count; i++) {
|
|
275
|
-
const o = outputs[i];
|
|
276
|
-
os.push({
|
|
277
|
-
basket: o.basket,
|
|
278
|
-
tags: o.tags,
|
|
279
|
-
satoshis: o.satoshis,
|
|
280
|
-
lockingScript: Setup.getLockP2PKH(o.address).toHex(),
|
|
281
|
-
outputDescription: o.outputDescription || `p2pkh ${i}`
|
|
282
|
-
});
|
|
283
|
-
}
|
|
284
|
-
return os;
|
|
285
|
-
}
|
|
286
|
-
/**
|
|
287
|
-
* @publicbody
|
|
288
|
-
*/
|
|
289
|
-
static async createP2PKHOutputsAction(wallet, outputs, options) {
|
|
290
|
-
const os = Setup.createP2PKHOutputs(outputs);
|
|
291
|
-
const createArgs = {
|
|
292
|
-
description: `createP2PKHOutputs`,
|
|
293
|
-
outputs: os,
|
|
294
|
-
options: {
|
|
295
|
-
...options,
|
|
296
|
-
// Don't randomize so we can simplify outpoint creation
|
|
297
|
-
randomizeOutputs: false
|
|
298
|
-
}
|
|
299
|
-
};
|
|
300
|
-
const cr = await wallet.createAction(createArgs);
|
|
301
|
-
let outpoints;
|
|
302
|
-
if (cr.txid) {
|
|
303
|
-
outpoints = os.map((o, i) => `${cr.txid}.${i}`);
|
|
304
|
-
}
|
|
305
|
-
return { cr, outpoints };
|
|
306
|
-
}
|
|
307
|
-
/**
|
|
308
|
-
* @publicbody
|
|
309
|
-
*/
|
|
310
|
-
static async fundWalletFromP2PKHOutpoints(wallet, outpoints, p2pkhKey, inputBEEF) {
|
|
311
|
-
// TODO
|
|
312
|
-
}
|
|
313
|
-
/**
|
|
314
|
-
* Adds `Knex` based storage to a `Wallet` configured by `Setup.createWalletOnly`
|
|
315
|
-
*
|
|
316
|
-
* @param args.knex `Knex` object configured for either MySQL or SQLite database access.
|
|
317
|
-
* Schema will be created and migrated as needed.
|
|
318
|
-
* For MySQL, a schema corresponding to databaseName must exist with full access permissions.
|
|
319
|
-
* @param args.databaseName Name for this storage. For MySQL, the schema name within the MySQL instance.
|
|
320
|
-
* @param args.chain Which chain this wallet is on: 'main' or 'test'. Defaults to 'test'.
|
|
321
|
-
* @param args.rootKeyHex
|
|
322
|
-
*
|
|
323
|
-
* @publicbody
|
|
324
|
-
*/
|
|
325
|
-
static async createWalletKnex(args) {
|
|
326
|
-
const wo = await Setup.createWallet(args);
|
|
327
|
-
const activeStorage = await Setup.createStorageKnex(args);
|
|
328
|
-
await wo.storage.addWalletStorageProvider(activeStorage);
|
|
329
|
-
const { user, isNew } = await activeStorage.findOrInsertUser(wo.identityKey);
|
|
330
|
-
const userId = user.userId;
|
|
331
|
-
const r = {
|
|
332
|
-
...wo,
|
|
333
|
-
activeStorage,
|
|
334
|
-
userId
|
|
335
|
-
};
|
|
336
|
-
return r;
|
|
337
|
-
}
|
|
338
|
-
/**
|
|
339
|
-
* @returns {StorageKnex} - `Knex` based storage provider for a wallet. May be used for either active storage or backup storage.
|
|
340
|
-
*/
|
|
341
|
-
static async createStorageKnex(args) {
|
|
342
|
-
// Create a temporary wallet setup to consistently resolve optional args.
|
|
343
|
-
const wo = await Setup.createWallet(args);
|
|
344
|
-
const storage = new StorageKnex_1.StorageKnex({
|
|
345
|
-
chain: wo.chain,
|
|
346
|
-
knex: args.knex,
|
|
347
|
-
commissionSatoshis: 0,
|
|
348
|
-
commissionPubKeyHex: undefined,
|
|
349
|
-
feeModel: { model: 'sat/kb', value: 1 }
|
|
350
|
-
});
|
|
351
|
-
await storage.migrate(args.databaseName, randomBytesHex(33));
|
|
352
|
-
await storage.makeAvailable();
|
|
353
|
-
await wo.wallet.destroy();
|
|
354
|
-
return storage;
|
|
355
|
-
}
|
|
356
|
-
/**
|
|
357
|
-
* @publicbody
|
|
358
|
-
*/
|
|
359
|
-
static createSQLiteKnex(filename) {
|
|
360
|
-
const config = {
|
|
361
|
-
client: 'sqlite3',
|
|
362
|
-
connection: { filename },
|
|
363
|
-
useNullAsDefault: true
|
|
364
|
-
};
|
|
365
|
-
const knex = (0, knex_1.knex)(config);
|
|
366
|
-
return knex;
|
|
367
|
-
}
|
|
368
|
-
/**
|
|
369
|
-
* @publicbody
|
|
370
|
-
*/
|
|
371
|
-
static createMySQLKnex(connection, database) {
|
|
372
|
-
const c = JSON.parse(connection);
|
|
373
|
-
if (database) {
|
|
374
|
-
c.database = database;
|
|
375
|
-
}
|
|
376
|
-
const config = {
|
|
377
|
-
client: 'mysql2',
|
|
378
|
-
connection: c,
|
|
379
|
-
useNullAsDefault: true,
|
|
380
|
-
pool: { min: 0, max: 7, idleTimeoutMillis: 15000 }
|
|
381
|
-
};
|
|
382
|
-
const knex = (0, knex_1.knex)(config);
|
|
383
|
-
return knex;
|
|
384
|
-
}
|
|
385
|
-
/**
|
|
386
|
-
* @publicbody
|
|
387
|
-
*/
|
|
388
|
-
static async createWalletMySQL(args) {
|
|
389
|
-
return await this.createWalletKnex({
|
|
390
|
-
...args,
|
|
391
|
-
knex: Setup.createMySQLKnex(args.env.mySQLConnection, args.databaseName)
|
|
392
|
-
});
|
|
393
|
-
}
|
|
394
|
-
/**
|
|
395
|
-
* @publicbody
|
|
396
|
-
*/
|
|
397
|
-
static async createWalletSQLite(args) {
|
|
398
|
-
return await this.createWalletKnex({
|
|
399
|
-
...args,
|
|
400
|
-
knex: Setup.createSQLiteKnex(args.filePath)
|
|
401
|
-
});
|
|
402
|
-
}
|
|
403
|
-
}
|
|
404
|
-
exports.Setup = Setup;
|
|
405
|
-
function randomBytesHex(arg0) {
|
|
406
|
-
throw new Error('Function not implemented.');
|
|
407
|
-
}
|
|
408
|
-
//# sourceMappingURL=Setup.js.map
|