@bsv/wallet-toolbox 1.1.26 → 1.1.28
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/setup.md +15 -19
- package/out/src/Setup.d.ts +4 -0
- package/out/src/Setup.d.ts.map +1 -1
- package/out/src/Setup.js +19 -9
- package/out/src/Setup.js.map +1 -1
- package/out/src/storage/WalletStorageManager.d.ts.map +1 -1
- package/out/src/storage/WalletStorageManager.js +2 -0
- package/out/src/storage/WalletStorageManager.js.map +1 -1
- package/out/test/examples/backup.test.d.ts +14 -0
- package/out/test/examples/backup.test.d.ts.map +1 -0
- package/out/test/examples/backup.test.js +59 -0
- package/out/test/examples/backup.test.js.map +1 -0
- package/out/test/wallet/action/abortAction.test.d.ts.map +1 -0
- package/out/test/{Wallet → wallet}/action/abortAction.test.js.map +1 -1
- package/out/test/wallet/action/createAction.test.d.ts.map +1 -0
- package/out/test/{Wallet → wallet}/action/createAction.test.js.map +1 -1
- package/out/test/{Wallet → wallet}/action/createAction2.test.d.ts.map +1 -1
- package/out/test/{Wallet → wallet}/action/createAction2.test.js.map +1 -1
- package/out/test/wallet/action/createActionToGenerateBeefs.man.test.d.ts.map +1 -0
- package/out/test/{Wallet → wallet}/action/createActionToGenerateBeefs.man.test.js.map +1 -1
- package/out/test/wallet/action/internalizeAction.test.d.ts.map +1 -0
- package/out/test/{Wallet → wallet}/action/internalizeAction.test.js.map +1 -1
- package/out/test/wallet/action/relinquishOutput.test.d.ts.map +1 -0
- package/out/test/{Wallet → wallet}/action/relinquishOutput.test.js.map +1 -1
- package/out/test/wallet/construct/Wallet.constructor.test.d.ts.map +1 -0
- package/out/test/{Wallet → wallet}/construct/Wallet.constructor.test.js.map +1 -1
- package/out/test/wallet/list/listActions.test.d.ts.map +1 -0
- package/out/test/{Wallet → wallet}/list/listActions.test.js.map +1 -1
- package/out/test/wallet/list/listActions2.test.d.ts.map +1 -0
- package/out/test/{Wallet → wallet}/list/listActions2.test.js.map +1 -1
- package/out/test/wallet/list/listCertificates.test.d.ts.map +1 -0
- package/out/test/{Wallet → wallet}/list/listCertificates.test.js.map +1 -1
- package/out/test/wallet/list/listOutputs.test.d.ts.map +1 -0
- package/out/test/{Wallet → wallet}/list/listOutputs.test.js.map +1 -1
- package/out/test/wallet/sync/Wallet.sync.test.d.ts.map +1 -0
- package/out/test/{Wallet → wallet}/sync/Wallet.sync.test.js.map +1 -1
- package/out/tsconfig.all.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/Setup.ts +22 -9
- package/src/storage/WalletStorageManager.ts +1 -0
- package/test/examples/backup.test.ts +66 -0
- package/out/test/Wallet/action/abortAction.test.d.ts.map +0 -1
- package/out/test/Wallet/action/createAction.test.d.ts.map +0 -1
- package/out/test/Wallet/action/createActionToGenerateBeefs.man.test.d.ts.map +0 -1
- package/out/test/Wallet/action/internalizeAction.test.d.ts.map +0 -1
- package/out/test/Wallet/action/relinquishOutput.test.d.ts.map +0 -1
- package/out/test/Wallet/construct/Wallet.constructor.test.d.ts.map +0 -1
- package/out/test/Wallet/list/listActions.test.d.ts.map +0 -1
- package/out/test/Wallet/list/listActions2.test.d.ts.map +0 -1
- package/out/test/Wallet/list/listCertificates.test.d.ts.map +0 -1
- package/out/test/Wallet/list/listOutputs.test.d.ts.map +0 -1
- package/out/test/Wallet/sync/Wallet.sync.test.d.ts.map +0 -1
- /package/out/test/{Wallet → wallet}/action/abortAction.test.d.ts +0 -0
- /package/out/test/{Wallet → wallet}/action/abortAction.test.js +0 -0
- /package/out/test/{Wallet → wallet}/action/createAction.test.d.ts +0 -0
- /package/out/test/{Wallet → wallet}/action/createAction.test.js +0 -0
- /package/out/test/{Wallet → wallet}/action/createAction2.test.d.ts +0 -0
- /package/out/test/{Wallet → wallet}/action/createAction2.test.js +0 -0
- /package/out/test/{Wallet → wallet}/action/createActionToGenerateBeefs.man.test.d.ts +0 -0
- /package/out/test/{Wallet → wallet}/action/createActionToGenerateBeefs.man.test.js +0 -0
- /package/out/test/{Wallet → wallet}/action/internalizeAction.test.d.ts +0 -0
- /package/out/test/{Wallet → wallet}/action/internalizeAction.test.js +0 -0
- /package/out/test/{Wallet → wallet}/action/relinquishOutput.test.d.ts +0 -0
- /package/out/test/{Wallet → wallet}/action/relinquishOutput.test.js +0 -0
- /package/out/test/{Wallet → wallet}/construct/Wallet.constructor.test.d.ts +0 -0
- /package/out/test/{Wallet → wallet}/construct/Wallet.constructor.test.js +0 -0
- /package/out/test/{Wallet → wallet}/list/listActions.test.d.ts +0 -0
- /package/out/test/{Wallet → wallet}/list/listActions.test.js +0 -0
- /package/out/test/{Wallet → wallet}/list/listActions2.test.d.ts +0 -0
- /package/out/test/{Wallet → wallet}/list/listActions2.test.js +0 -0
- /package/out/test/{Wallet → wallet}/list/listCertificates.test.d.ts +0 -0
- /package/out/test/{Wallet → wallet}/list/listCertificates.test.js +0 -0
- /package/out/test/{Wallet → wallet}/list/listOutputs.test.d.ts +0 -0
- /package/out/test/{Wallet → wallet}/list/listOutputs.test.js +0 -0
- /package/out/test/{Wallet → wallet}/sync/Wallet.sync.test.d.ts +0 -0
- /package/out/test/{Wallet → wallet}/sync/Wallet.sync.test.js +0 -0
- /package/test/{Wallet → wallet}/action/abortAction.test.ts +0 -0
- /package/test/{Wallet → wallet}/action/createAction.test.ts +0 -0
- /package/test/{Wallet → wallet}/action/createAction2.test.ts +0 -0
- /package/test/{Wallet → wallet}/action/createActionToGenerateBeefs.man.test.ts +0 -0
- /package/test/{Wallet → wallet}/action/internalizeAction.test.ts +0 -0
- /package/test/{Wallet → wallet}/action/relinquishOutput.test.ts +0 -0
- /package/test/{Wallet → wallet}/construct/Wallet.constructor.test.ts +0 -0
- /package/test/{Wallet → wallet}/list/listActions.test.ts +0 -0
- /package/test/{Wallet → wallet}/list/listActions2.test.ts +0 -0
- /package/test/{Wallet → wallet}/list/listCertificates.test.ts +0 -0
- /package/test/{Wallet → wallet}/list/listOutputs.test.ts +0 -0
- /package/test/{Wallet → wallet}/sync/Wallet.sync.test.ts +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bsv/wallet-toolbox",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.28",
|
|
4
4
|
"description": "BRC100 conforming wallet, wallet storage and wallet signer components",
|
|
5
5
|
"main": "./out/src/index.js",
|
|
6
6
|
"types": "./out/src/index.d.ts",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@bsv/auth-express-middleware": "^1.0.1",
|
|
34
34
|
"@bsv/payment-express-middleware": "^1.0.1",
|
|
35
|
-
"@bsv/sdk": "^1.3.
|
|
35
|
+
"@bsv/sdk": "^1.3.22",
|
|
36
36
|
"axios": "^0.29.0",
|
|
37
37
|
"express": "^4.21.2",
|
|
38
38
|
"knex": "^3.1.0",
|
package/src/Setup.ts
CHANGED
|
@@ -384,15 +384,7 @@ DEV_KEYS = '{
|
|
|
384
384
|
args: SetupWalletKnexArgs
|
|
385
385
|
): Promise<SetupWalletKnex> {
|
|
386
386
|
const wo = await Setup.createWallet(args)
|
|
387
|
-
const activeStorage =
|
|
388
|
-
chain: wo.chain,
|
|
389
|
-
knex: args.knex,
|
|
390
|
-
commissionSatoshis: 0,
|
|
391
|
-
commissionPubKeyHex: undefined,
|
|
392
|
-
feeModel: { model: 'sat/kb', value: 1 }
|
|
393
|
-
})
|
|
394
|
-
await activeStorage.migrate(args.databaseName, wo.identityKey)
|
|
395
|
-
await activeStorage.makeAvailable()
|
|
387
|
+
const activeStorage = await Setup.createStorageKnex(args)
|
|
396
388
|
await wo.storage.addWalletStorageProvider(activeStorage)
|
|
397
389
|
const { user, isNew } = await activeStorage.findOrInsertUser(wo.identityKey)
|
|
398
390
|
const userId = user.userId
|
|
@@ -404,6 +396,27 @@ DEV_KEYS = '{
|
|
|
404
396
|
return r
|
|
405
397
|
}
|
|
406
398
|
|
|
399
|
+
/**
|
|
400
|
+
* @returns {StorageKnex} - `Knex` based storage provider for a wallet. May be used for either active storage or backup storage.
|
|
401
|
+
*/
|
|
402
|
+
static async createStorageKnex(
|
|
403
|
+
args: SetupWalletKnexArgs
|
|
404
|
+
): Promise<StorageKnex> {
|
|
405
|
+
// Create a temporary wallet setup to consistently resolve optional args.
|
|
406
|
+
const wo = await Setup.createWallet(args)
|
|
407
|
+
const storage = new StorageKnex({
|
|
408
|
+
chain: wo.chain,
|
|
409
|
+
knex: args.knex,
|
|
410
|
+
commissionSatoshis: 0,
|
|
411
|
+
commissionPubKeyHex: undefined,
|
|
412
|
+
feeModel: { model: 'sat/kb', value: 1 }
|
|
413
|
+
})
|
|
414
|
+
await storage.migrate(args.databaseName, wo.identityKey)
|
|
415
|
+
await storage.makeAvailable()
|
|
416
|
+
await wo.wallet.destroy()
|
|
417
|
+
return storage
|
|
418
|
+
}
|
|
419
|
+
|
|
407
420
|
/**
|
|
408
421
|
* @publicbody
|
|
409
422
|
*/
|
|
@@ -277,6 +277,7 @@ export class WalletStorageManager implements sdk.WalletStorage {
|
|
|
277
277
|
}
|
|
278
278
|
|
|
279
279
|
async destroy(): Promise<void> {
|
|
280
|
+
if (this.stores.length < 1) return
|
|
280
281
|
return await this.runAsWriter(async writer => {
|
|
281
282
|
for (const store of this.stores) await store.destroy()
|
|
282
283
|
})
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Setup, SetupEnv, SetupWallet } from '../../src'
|
|
2
|
+
import dotenv from 'dotenv'
|
|
3
|
+
dotenv.config()
|
|
4
|
+
|
|
5
|
+
describe('backup example tests', () => {
|
|
6
|
+
jest.setTimeout(99999999)
|
|
7
|
+
|
|
8
|
+
test('0', () => {})
|
|
9
|
+
if (Setup.noEnv('test')) return
|
|
10
|
+
const env = Setup.getEnv('test')
|
|
11
|
+
|
|
12
|
+
test('1 backup MY_TEST_IDENTITY', async () => {
|
|
13
|
+
await backupWalletClient(env, process.env.MY_TEST_IDENTITY || '')
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
test('2 backup MY_TEST_IDENTITY2', async () => {
|
|
17
|
+
await backupWalletClient(env, process.env.MY_TEST_IDENTITY2 || '')
|
|
18
|
+
})
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @publicbody
|
|
23
|
+
*/
|
|
24
|
+
export async function backup(): Promise<void> {
|
|
25
|
+
const env = Setup.getEnv('test')
|
|
26
|
+
await backupWalletClient(env, env.identityKey)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* @publicbody
|
|
31
|
+
*/
|
|
32
|
+
export async function backupWalletClient(
|
|
33
|
+
env: SetupEnv,
|
|
34
|
+
identityKey: string
|
|
35
|
+
): Promise<void> {
|
|
36
|
+
const setup = await Setup.createWalletClient({
|
|
37
|
+
env,
|
|
38
|
+
rootKeyHex: env.devKeys[identityKey]
|
|
39
|
+
})
|
|
40
|
+
await backupToSQLite(setup)
|
|
41
|
+
await setup.wallet.destroy()
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @publicbody
|
|
46
|
+
*/
|
|
47
|
+
export async function backupToSQLite(
|
|
48
|
+
setup: SetupWallet,
|
|
49
|
+
filePath?: string,
|
|
50
|
+
databaseName?: string
|
|
51
|
+
): Promise<void> {
|
|
52
|
+
const env = Setup.getEnv(setup.chain)
|
|
53
|
+
filePath ||= `backup_${setup.identityKey}.sqlite`
|
|
54
|
+
databaseName ||= `${setup.identityKey} backup`
|
|
55
|
+
|
|
56
|
+
const backup = await Setup.createStorageKnex({
|
|
57
|
+
env,
|
|
58
|
+
knex: Setup.createSQLiteKnex(filePath),
|
|
59
|
+
databaseName,
|
|
60
|
+
rootKeyHex: setup.keyDeriver.rootKey.toHex()
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
await setup.storage.addWalletStorageProvider(backup)
|
|
64
|
+
|
|
65
|
+
await setup.storage.updateBackups()
|
|
66
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"abortAction.test.d.ts","sourceRoot":"","sources":["../../../../test/Wallet/action/abortAction.test.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createAction.test.d.ts","sourceRoot":"","sources":["../../../../test/Wallet/action/createAction.test.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createActionToGenerateBeefs.man.test.d.ts","sourceRoot":"","sources":["../../../../test/Wallet/action/createActionToGenerateBeefs.man.test.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"internalizeAction.test.d.ts","sourceRoot":"","sources":["../../../../test/Wallet/action/internalizeAction.test.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"relinquishOutput.test.d.ts","sourceRoot":"","sources":["../../../../test/Wallet/action/relinquishOutput.test.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Wallet.constructor.test.d.ts","sourceRoot":"","sources":["../../../../test/Wallet/construct/Wallet.constructor.test.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"listActions.test.d.ts","sourceRoot":"","sources":["../../../../test/Wallet/list/listActions.test.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"listActions2.test.d.ts","sourceRoot":"","sources":["../../../../test/Wallet/list/listActions2.test.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"listCertificates.test.d.ts","sourceRoot":"","sources":["../../../../test/Wallet/list/listCertificates.test.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"listOutputs.test.d.ts","sourceRoot":"","sources":["../../../../test/Wallet/list/listOutputs.test.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Wallet.sync.test.d.ts","sourceRoot":"","sources":["../../../../test/Wallet/sync/Wallet.sync.test.ts"],"names":[],"mappings":""}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|