@bsv/wallet-toolbox 1.2.32 → 1.2.35
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/client.md +489 -1742
- package/docs/monitor.md +7 -7
- package/docs/services.md +236 -2
- package/docs/wallet.md +489 -1742
- package/out/src/Setup.d.ts +1 -2
- package/out/src/Setup.d.ts.map +1 -1
- package/out/src/Setup.js +17 -18
- package/out/src/Setup.js.map +1 -1
- package/out/src/Wallet.d.ts +4 -1
- package/out/src/Wallet.d.ts.map +1 -1
- package/out/src/Wallet.js +111 -51
- package/out/src/Wallet.js.map +1 -1
- package/out/src/WalletSettingsManager.d.ts +2 -9
- package/out/src/WalletSettingsManager.d.ts.map +1 -1
- package/out/src/WalletSettingsManager.js +7 -113
- package/out/src/WalletSettingsManager.js.map +1 -1
- package/out/src/index.client.d.ts +5 -6
- package/out/src/index.client.d.ts.map +1 -1
- package/out/src/index.client.js +5 -6
- package/out/src/index.client.js.map +1 -1
- package/out/src/monitor/Monitor.d.ts +4 -2
- package/out/src/monitor/Monitor.d.ts.map +1 -1
- package/out/src/monitor/Monitor.js +45 -13
- package/out/src/monitor/Monitor.js.map +1 -1
- package/out/src/monitor/MonitorDaemon.d.ts.map +1 -1
- package/out/src/monitor/MonitorDaemon.js +3 -0
- package/out/src/monitor/MonitorDaemon.js.map +1 -1
- package/out/src/monitor/tasks/TaskCheckForProofs.d.ts +1 -1
- package/out/src/monitor/tasks/TaskCheckForProofs.d.ts.map +1 -1
- package/out/src/monitor/tasks/TaskCheckForProofs.js +6 -4
- package/out/src/monitor/tasks/TaskCheckForProofs.js.map +1 -1
- package/out/src/monitor/tasks/TaskCheckNoSends.d.ts.map +1 -1
- package/out/src/monitor/tasks/TaskCheckNoSends.js.map +1 -1
- package/out/src/monitor/tasks/TaskNewHeader.d.ts +3 -3
- package/out/src/monitor/tasks/TaskNewHeader.d.ts.map +1 -1
- package/out/src/monitor/tasks/TaskNewHeader.js.map +1 -1
- package/out/src/monitor/tasks/TaskPurge.d.ts +2 -2
- package/out/src/monitor/tasks/TaskPurge.d.ts.map +1 -1
- package/out/src/monitor/tasks/TaskReviewStatus.d.ts.map +1 -1
- package/out/src/monitor/tasks/TaskReviewStatus.js.map +1 -1
- package/out/src/monitor/tasks/TaskUnFail.d.ts +2 -1
- package/out/src/monitor/tasks/TaskUnFail.d.ts.map +1 -1
- package/out/src/monitor/tasks/TaskUnFail.js +2 -2
- package/out/src/monitor/tasks/TaskUnFail.js.map +1 -1
- package/out/src/sdk/WalletServices.interfaces.d.ts +19 -18
- package/out/src/sdk/WalletServices.interfaces.d.ts.map +1 -1
- package/out/src/sdk/WalletSigner.interfaces.d.ts +2 -2
- package/out/src/sdk/WalletSigner.interfaces.d.ts.map +1 -1
- package/out/src/sdk/WalletStorage.interfaces.d.ts +57 -53
- package/out/src/sdk/WalletStorage.interfaces.d.ts.map +1 -1
- package/out/src/sdk/types.d.ts +12 -0
- package/out/src/sdk/types.d.ts.map +1 -1
- package/out/src/sdk/types.js +16 -1
- package/out/src/sdk/types.js.map +1 -1
- package/out/src/storage/StorageKnex.d.ts.map +1 -1
- package/out/src/storage/WalletStorageManager.d.ts +3 -1
- package/out/src/storage/WalletStorageManager.d.ts.map +1 -1
- package/out/src/storage/WalletStorageManager.js +58 -23
- package/out/src/storage/WalletStorageManager.js.map +1 -1
- package/out/src/storage/methods/attemptToPostReqsToNetwork.d.ts +1 -1
- package/out/src/storage/methods/attemptToPostReqsToNetwork.d.ts.map +1 -1
- package/out/src/storage/methods/attemptToPostReqsToNetwork.js +40 -6
- package/out/src/storage/methods/attemptToPostReqsToNetwork.js.map +1 -1
- package/out/test/Wallet/local/localWallet.man.test.js +1 -1
- package/out/test/Wallet/local/localWallet.man.test.js.map +1 -1
- package/out/test/Wallet/local/localWallet2.man.test.js +59 -1
- package/out/test/Wallet/local/localWallet2.man.test.js.map +1 -1
- package/out/test/Wallet/specOps/specOps.man.test.js +37 -5
- package/out/test/Wallet/specOps/specOps.man.test.js.map +1 -1
- package/out/test/WalletClient/LocalKVStore.man.test.d.ts +2 -0
- package/out/test/WalletClient/LocalKVStore.man.test.d.ts.map +1 -0
- package/out/test/WalletClient/LocalKVStore.man.test.js +99 -0
- package/out/test/WalletClient/LocalKVStore.man.test.js.map +1 -0
- package/out/test/WalletClient/WERR.man.test.d.ts +2 -0
- package/out/test/WalletClient/WERR.man.test.d.ts.map +1 -0
- package/out/test/WalletClient/WERR.man.test.js +21 -0
- package/out/test/WalletClient/WERR.man.test.js.map +1 -0
- package/out/test/services/Services.test.js +3 -1
- package/out/test/services/Services.test.js.map +1 -1
- package/out/test/{Wallet/local → utils}/localWalletMethods.d.ts +2 -2
- package/out/test/utils/localWalletMethods.d.ts.map +1 -0
- package/out/test/{Wallet/local → utils}/localWalletMethods.js +4 -4
- package/out/test/utils/localWalletMethods.js.map +1 -0
- package/out/tsconfig.all.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/Setup.ts +2 -2
- package/src/Wallet.ts +41 -9
- package/src/WalletSettingsManager.ts +12 -144
- package/src/index.client.ts +5 -6
- package/src/monitor/Monitor.ts +10 -9
- package/src/monitor/MonitorDaemon.ts +4 -0
- package/src/monitor/tasks/TaskCheckForProofs.ts +6 -2
- package/src/monitor/tasks/TaskCheckNoSends.ts +0 -1
- package/src/monitor/tasks/TaskNewHeader.ts +3 -4
- package/src/monitor/tasks/TaskPurge.ts +2 -2
- package/src/monitor/tasks/TaskReviewStatus.ts +0 -1
- package/src/monitor/tasks/TaskUnFail.ts +2 -1
- package/src/sdk/WalletServices.interfaces.ts +19 -18
- package/src/sdk/WalletSigner.interfaces.ts +3 -30
- package/src/sdk/WalletStorage.interfaces.ts +74 -66
- package/src/sdk/types.ts +16 -0
- package/src/storage/StorageKnex.ts +1 -1
- package/src/storage/WalletStorageManager.ts +6 -10
- package/src/storage/methods/attemptToPostReqsToNetwork.ts +2 -1
- package/test/Wallet/local/localWallet.man.test.ts +1 -3
- package/test/Wallet/local/localWallet2.man.test.ts +60 -4
- package/test/Wallet/specOps/specOps.man.test.ts +41 -1
- package/test/WalletClient/LocalKVStore.man.test.ts +114 -0
- package/test/WalletClient/WERR.man.test.ts +20 -0
- package/test/services/Services.test.ts +3 -1
- package/test/{Wallet/local → utils}/localWalletMethods.ts +4 -5
- package/out/test/Wallet/local/localWalletMethods.d.ts.map +0 -1
- package/out/test/Wallet/local/localWalletMethods.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bsv/wallet-toolbox",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.35",
|
|
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",
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
"homepage": "https://github.com/bitcoin-sv/wallet-toolbox#readme",
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@bsv/auth-express-middleware": "^1.1.2",
|
|
34
|
-
"@bsv/payment-express-middleware": "^1.0.
|
|
35
|
-
"@bsv/sdk": "^1.4.
|
|
34
|
+
"@bsv/payment-express-middleware": "^1.0.5",
|
|
35
|
+
"@bsv/sdk": "^1.4.18",
|
|
36
36
|
"express": "^4.21.2",
|
|
37
37
|
"knex": "^3.1.0",
|
|
38
38
|
"mysql2": "^3.12.0",
|
package/src/Setup.ts
CHANGED
|
@@ -17,12 +17,12 @@ import {
|
|
|
17
17
|
sdk,
|
|
18
18
|
Services,
|
|
19
19
|
StorageClient,
|
|
20
|
+
StorageKnex,
|
|
20
21
|
verifyTruthy,
|
|
21
22
|
Wallet,
|
|
22
23
|
WalletStorageManager
|
|
23
|
-
} from './index.
|
|
24
|
+
} from './index.all'
|
|
24
25
|
import { Knex, knex as makeKnex } from 'knex'
|
|
25
|
-
import { StorageKnex } from './index.all'
|
|
26
26
|
|
|
27
27
|
import * as dotenv from 'dotenv'
|
|
28
28
|
dotenv.config()
|
package/src/Wallet.ts
CHANGED
|
@@ -67,15 +67,7 @@ import {
|
|
|
67
67
|
AtomicBEEF,
|
|
68
68
|
BEEF
|
|
69
69
|
} from '@bsv/sdk'
|
|
70
|
-
import
|
|
71
|
-
sdk,
|
|
72
|
-
toWalletNetwork,
|
|
73
|
-
Monitor,
|
|
74
|
-
WalletStorageManager,
|
|
75
|
-
WalletSigner,
|
|
76
|
-
randomBytesBase64,
|
|
77
|
-
ScriptTemplateBRC29
|
|
78
|
-
} from './index.client'
|
|
70
|
+
import * as sdk from './sdk'
|
|
79
71
|
import { acquireDirectCertificate } from './signer/methods/acquireDirectCertificate'
|
|
80
72
|
import { proveCertificate } from './signer/methods/proveCertificate'
|
|
81
73
|
import { createAction, CreateActionResultX } from './signer/methods/createAction'
|
|
@@ -89,8 +81,14 @@ import {
|
|
|
89
81
|
specOpInvalidChange,
|
|
90
82
|
specOpNoSendActions,
|
|
91
83
|
specOpSetWalletChangeParams,
|
|
84
|
+
specOpThrowReviewActions,
|
|
92
85
|
specOpWalletBalance
|
|
93
86
|
} from './sdk'
|
|
87
|
+
import { WalletStorageManager } from './storage/WalletStorageManager'
|
|
88
|
+
import { Monitor } from './monitor/Monitor'
|
|
89
|
+
import { WalletSigner } from './signer/WalletSigner'
|
|
90
|
+
import { randomBytesBase64, toWalletNetwork } from './utility/utilityHelpers'
|
|
91
|
+
import { ScriptTemplateBRC29 } from './utility/ScriptTemplateBRC29'
|
|
94
92
|
|
|
95
93
|
export interface WalletArgs {
|
|
96
94
|
chain: sdk.Chain
|
|
@@ -682,6 +680,9 @@ export class Wallet implements WalletInterface, ProtoWallet {
|
|
|
682
680
|
}
|
|
683
681
|
|
|
684
682
|
const { auth, vargs } = this.validateAuthAndArgs(args, sdk.validateCreateActionArgs)
|
|
683
|
+
|
|
684
|
+
if (vargs.labels.indexOf(specOpThrowReviewActions) >= 0) throwDummyReviewActions()
|
|
685
|
+
|
|
685
686
|
vargs.includeAllSourceTransactions = this.includeAllSourceTransactions
|
|
686
687
|
if (this.randomVals && this.randomVals.length > 1) {
|
|
687
688
|
vargs.randomVals = [...this.randomVals]
|
|
@@ -994,3 +995,34 @@ function throwIfAnyUnsuccessfulSignActions(r: SignActionResultX) {
|
|
|
994
995
|
|
|
995
996
|
throw new sdk.WERR_REVIEW_ACTIONS(ndrs, swrs, r.txid, r.tx)
|
|
996
997
|
}
|
|
998
|
+
|
|
999
|
+
/**
|
|
1000
|
+
* Throws a WERR_REVIEW_ACTIONS with a full set of properties to test data formats and propagation.
|
|
1001
|
+
*/
|
|
1002
|
+
function throwDummyReviewActions() {
|
|
1003
|
+
const b58Beef =
|
|
1004
|
+
'gno9MC7VXii1KoCkc2nsVyYJpqzN3dhBzYATETJcys62emMKfpBof4R7GozwYEaSapUtnNvqQ57aaYYjm3U2dv9eUJ1sV46boHkQgppYmAz9YH8FdZduV8aJayPViaKcyPmbDhEw6UW8TM5iFZLXNs7HBnJHUKCeTdNK4FUEL7vAugxAV9WUUZ43BZjJk2SmSeps9TCXjt1Ci9fKWp3d9QSoYvTpxwzyUFHjRKtbUgwq55ZfkBp5bV2Bpz9qSuKywKewW7Hh4S1nCUScwwzpKDozb3zic1V9p2k8rQxoPsRxjUJ8bjhNDdsN8d7KukFuc3n47fXzdWttvnxwsujLJRGnQbgJuknQqx3KLf5kJXHzwjG6TzigZk2t24qeB6d3hbYiaDr2fFkUJBL3tukTHhfNkQYRXuz3kucVDzvejHyqJaF51mXG8BjMN5aQj91ZJXCaPVqkMWCzmvyaqmXMdRiJdSAynhXbQK91xf6RwdNhz1tg5f9B6oJJMhsi9UYSVymmax8VLKD9AKzBCBDcfyD83m3jyS1VgKGZn3SkQmr6bsoWq88L3GsMnnmYUGogvdAYarTqg3pzkjCMxHzmJBMN6ofnUk8c1sRTXQue7BbyUaN5uZu3KW6CmFsEfpuqVvnqFW93TU1jrPP2S8yz8AexAnARPCKE8Yz7RfVaT6RCavwQKL3u5iookwRWEZXW1QWmM37yJWHD87SjVynyg327a1CLwcBxmE2CB48QeNVGyQki4CTQMqw2o8TMhDPJej1g68oniAjBcxBLSCs7KGvK3k7AfrHbCMULX9CTibYhCjdFjbsbBoocqJpxxcvkMo1fEEiAzZuiBVZQDYktDdTVbhKHvYkW25HcYX75NJrpNAhm7AjFeKLzEVxqAQkMfvTufpESNRZF4kQqg2Rg8h2ajcKTd5cpEPwXCrZLHm4EaZEmZVbg3QNfGhn7BJu1bHMtLqPD4y8eJxm2uGrW6saf6qKYmmu64F8A667NbD4yskPRQ1S863VzwGpxxmgLc1Ta3R46jEqsAoRDoZVUaCgBBZG3Yg1CTgi1EVBMXU7qvY4n3h8o2FLCEMWY4KadnV3iD4FbcdCmg4yxBosNAZgbPjhgGjCimjh4YsLd9zymGLmivmz2ZBg5m3xaiXT9NN81X9C1JUujd'
|
|
1005
|
+
const beef = Beef.fromBinary(Utils.fromBase58(b58Beef))
|
|
1006
|
+
const btx = beef.txs.slice(-1)[0]
|
|
1007
|
+
const txid = btx.txid
|
|
1008
|
+
debugger
|
|
1009
|
+
throw new sdk.WERR_REVIEW_ACTIONS(
|
|
1010
|
+
[
|
|
1011
|
+
{
|
|
1012
|
+
txid, // only care that it is syntactically a txid
|
|
1013
|
+
status: 'doubleSpend',
|
|
1014
|
+
competingTxs: [txid], // a txid in the beef
|
|
1015
|
+
competingBeef: beef.toBinary()
|
|
1016
|
+
}
|
|
1017
|
+
],
|
|
1018
|
+
[
|
|
1019
|
+
{
|
|
1020
|
+
txid,
|
|
1021
|
+
status: 'failed'
|
|
1022
|
+
}
|
|
1023
|
+
],
|
|
1024
|
+
txid,
|
|
1025
|
+
beef.toBinaryAtomic(txid),
|
|
1026
|
+
[`${txid}.0`]
|
|
1027
|
+
)
|
|
1028
|
+
}
|
|
@@ -1,13 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
CreateActionInput,
|
|
3
|
-
LockingScript,
|
|
4
|
-
PubKeyHex,
|
|
5
|
-
PushDrop,
|
|
6
|
-
Transaction,
|
|
7
|
-
Utils,
|
|
8
|
-
WalletInterface,
|
|
9
|
-
WalletProtocol
|
|
10
|
-
} from '@bsv/sdk'
|
|
1
|
+
import { LocalKVStore, PubKeyHex, WalletInterface } from '@bsv/sdk'
|
|
11
2
|
|
|
12
3
|
export interface Certifier {
|
|
13
4
|
name: string
|
|
@@ -33,10 +24,7 @@ export interface WalletSettingsManagerConfig {
|
|
|
33
24
|
defaultSettings: WalletSettings
|
|
34
25
|
}
|
|
35
26
|
|
|
36
|
-
const PROTOCOL_ID: WalletProtocol = [2, 'wallet settings']
|
|
37
|
-
const KEY_ID = '1'
|
|
38
27
|
const SETTINGS_BASKET = 'wallet settings'
|
|
39
|
-
const TOKEN_AMOUNT = 1
|
|
40
28
|
|
|
41
29
|
// Defaults can be overridden as needed
|
|
42
30
|
export const DEFAULT_SETTINGS = {
|
|
@@ -44,19 +32,12 @@ export const DEFAULT_SETTINGS = {
|
|
|
44
32
|
trustLevel: 2,
|
|
45
33
|
trustedCertifiers: [
|
|
46
34
|
{
|
|
47
|
-
name: '
|
|
48
|
-
description: '
|
|
49
|
-
iconUrl: 'https://
|
|
35
|
+
name: 'Metanet Trust Services',
|
|
36
|
+
description: 'Registry for protocols, baskets, and certificates types',
|
|
37
|
+
iconUrl: 'https://bsvblockchain.org/favicon.ico',
|
|
50
38
|
identityKey: '03daf815fe38f83da0ad83b5bedc520aa488aef5cbc93a93c67a7fe60406cbffe8',
|
|
51
39
|
trust: 4
|
|
52
40
|
},
|
|
53
|
-
{
|
|
54
|
-
name: 'IdentiCert',
|
|
55
|
-
description: 'Certifies legal first and last name, and photos',
|
|
56
|
-
iconUrl: 'https://identicert.me/favicon.ico',
|
|
57
|
-
trust: 5,
|
|
58
|
-
identityKey: '0295bf1c7842d14babf60daf2c733956c331f9dcb2c79e41f85fd1dda6a3fa4549'
|
|
59
|
-
},
|
|
60
41
|
{
|
|
61
42
|
name: 'SocialCert',
|
|
62
43
|
description: 'Certifies social media handles, phone numbers and emails',
|
|
@@ -93,12 +74,16 @@ export const TESTNET_DEFAULT_SETTINGS: WalletSettings = {
|
|
|
93
74
|
* Manages wallet settings
|
|
94
75
|
*/
|
|
95
76
|
export class WalletSettingsManager {
|
|
77
|
+
kv: LocalKVStore
|
|
78
|
+
|
|
96
79
|
constructor(
|
|
97
80
|
private wallet: WalletInterface,
|
|
98
81
|
private config: WalletSettingsManagerConfig = {
|
|
99
82
|
defaultSettings: DEFAULT_SETTINGS
|
|
100
83
|
}
|
|
101
|
-
) {
|
|
84
|
+
) {
|
|
85
|
+
this.kv = new LocalKVStore(wallet, SETTINGS_BASKET, true)
|
|
86
|
+
}
|
|
102
87
|
|
|
103
88
|
/**
|
|
104
89
|
* Returns a user's wallet settings
|
|
@@ -106,23 +91,7 @@ export class WalletSettingsManager {
|
|
|
106
91
|
* @returns - Wallet settings object
|
|
107
92
|
*/
|
|
108
93
|
async get(): Promise<WalletSettings> {
|
|
109
|
-
|
|
110
|
-
// There should only be one settings token
|
|
111
|
-
const results = await this.wallet.listOutputs({
|
|
112
|
-
basket: SETTINGS_BASKET,
|
|
113
|
-
include: 'locking scripts'
|
|
114
|
-
})
|
|
115
|
-
|
|
116
|
-
// Return defaults if no settings token is found
|
|
117
|
-
if (!results.outputs.length) {
|
|
118
|
-
return this.config.defaultSettings
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
const { fields } = PushDrop.decode(
|
|
122
|
-
LockingScript.fromHex(results.outputs[results.outputs.length - 1].lockingScript!)
|
|
123
|
-
)
|
|
124
|
-
// Parse and return settings token
|
|
125
|
-
return JSON.parse(Utils.toUTF8(fields[0]))
|
|
94
|
+
return JSON.parse((await this.kv.get('settings', JSON.stringify(this.config.defaultSettings))) as string)
|
|
126
95
|
}
|
|
127
96
|
|
|
128
97
|
/**
|
|
@@ -131,114 +100,13 @@ export class WalletSettingsManager {
|
|
|
131
100
|
* @param settings - The wallet settings to be stored.
|
|
132
101
|
*/
|
|
133
102
|
async set(settings: WalletSettings): Promise<void> {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
// Build the new locking script with the updated settings JSON.
|
|
137
|
-
const lockingScript = await pushdrop.lock(
|
|
138
|
-
[Utils.toArray(JSON.stringify(settings), 'utf8')],
|
|
139
|
-
PROTOCOL_ID,
|
|
140
|
-
KEY_ID,
|
|
141
|
-
'self'
|
|
142
|
-
)
|
|
143
|
-
|
|
144
|
-
// Consume any existing token and create a new one with the new locking script.
|
|
145
|
-
await this.updateToken(lockingScript)
|
|
103
|
+
await this.kv.set('settings', JSON.stringify(settings))
|
|
146
104
|
}
|
|
147
105
|
|
|
148
106
|
/**
|
|
149
107
|
* Deletes the user's settings token.
|
|
150
108
|
*/
|
|
151
109
|
async delete(): Promise<void> {
|
|
152
|
-
|
|
153
|
-
await this.updateToken()
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Updates a settings token. Any previous token is consumed, and if a new locking script
|
|
158
|
-
* is provided, it replaces what (if anything) was there before.
|
|
159
|
-
*
|
|
160
|
-
* @param newLockingScript - Optional locking script for replacing the settings token.
|
|
161
|
-
* @returns {Promise<boolean>} - True if operation succeeded, throws an error otherwise.
|
|
162
|
-
*/
|
|
163
|
-
private async updateToken(newLockingScript?: LockingScript): Promise<boolean> {
|
|
164
|
-
const pushdrop = new PushDrop(this.wallet)
|
|
165
|
-
|
|
166
|
-
// 1. List the existing token UTXO(s) for the settings basket.
|
|
167
|
-
const existingUtxos = await this.wallet.listOutputs({
|
|
168
|
-
basket: SETTINGS_BASKET,
|
|
169
|
-
include: 'entire transactions'
|
|
170
|
-
})
|
|
171
|
-
|
|
172
|
-
// This is the "create a new token" path — no signAction, just a new locking script.
|
|
173
|
-
if (!existingUtxos.outputs.length) {
|
|
174
|
-
if (!newLockingScript) {
|
|
175
|
-
return true
|
|
176
|
-
}
|
|
177
|
-
await this.wallet.createAction({
|
|
178
|
-
description: 'Create a user settings token',
|
|
179
|
-
outputs: [
|
|
180
|
-
{
|
|
181
|
-
satoshis: TOKEN_AMOUNT,
|
|
182
|
-
lockingScript: newLockingScript.toHex(),
|
|
183
|
-
outputDescription: 'Wallet settings token',
|
|
184
|
-
basket: SETTINGS_BASKET
|
|
185
|
-
}
|
|
186
|
-
],
|
|
187
|
-
options: {
|
|
188
|
-
randomizeOutputs: false,
|
|
189
|
-
acceptDelayedBroadcast: false
|
|
190
|
-
}
|
|
191
|
-
})
|
|
192
|
-
return true
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
// 2. Prepare the token UTXO for consumption.
|
|
196
|
-
const tokenOutput = existingUtxos.outputs[existingUtxos.outputs.length - 1]
|
|
197
|
-
const inputToConsume: CreateActionInput = {
|
|
198
|
-
outpoint: tokenOutput.outpoint,
|
|
199
|
-
unlockingScriptLength: 73,
|
|
200
|
-
inputDescription: 'Consume old wallet settings token'
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// 3. Build the outputs array: if a new locking script is provided, add an output.
|
|
204
|
-
const outputs = newLockingScript
|
|
205
|
-
? [
|
|
206
|
-
{
|
|
207
|
-
satoshis: TOKEN_AMOUNT,
|
|
208
|
-
lockingScript: newLockingScript.toHex(),
|
|
209
|
-
outputDescription: 'Wallet settings token',
|
|
210
|
-
basket: SETTINGS_BASKET
|
|
211
|
-
}
|
|
212
|
-
]
|
|
213
|
-
: []
|
|
214
|
-
|
|
215
|
-
// 4. Create a signable transaction action using the inputs and (optionally) outputs.
|
|
216
|
-
const { signableTransaction } = await this.wallet.createAction({
|
|
217
|
-
description: `${newLockingScript ? 'Update' : 'Delete'} a user settings token`,
|
|
218
|
-
inputBEEF: existingUtxos.BEEF!,
|
|
219
|
-
inputs: [inputToConsume], // input index 0
|
|
220
|
-
outputs,
|
|
221
|
-
options: {
|
|
222
|
-
randomizeOutputs: false,
|
|
223
|
-
acceptDelayedBroadcast: false
|
|
224
|
-
}
|
|
225
|
-
})
|
|
226
|
-
const tx = Transaction.fromBEEF(signableTransaction!.tx)
|
|
227
|
-
|
|
228
|
-
// 5. Build and sign the unlocking script for the token being consumed.
|
|
229
|
-
const unlocker = pushdrop.unlock(PROTOCOL_ID, KEY_ID, 'self')
|
|
230
|
-
const unlockingScript = await unlocker.sign(tx, 0)
|
|
231
|
-
|
|
232
|
-
// 6. Sign the transaction using our unlocking script.
|
|
233
|
-
await this.wallet.signAction({
|
|
234
|
-
reference: signableTransaction!.reference,
|
|
235
|
-
spends: {
|
|
236
|
-
0: {
|
|
237
|
-
unlockingScript: unlockingScript.toHex()
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
})
|
|
241
|
-
|
|
242
|
-
return true
|
|
110
|
+
await this.kv.remove('settings')
|
|
243
111
|
}
|
|
244
112
|
}
|
package/src/index.client.ts
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
export * as sdk from './sdk/index'
|
|
2
2
|
export * from './utility/index.client'
|
|
3
|
-
export * from './Wallet'
|
|
4
3
|
export * from './signer/WalletSigner'
|
|
5
|
-
export * from './storage/index.client'
|
|
6
|
-
export * from './services/Services'
|
|
7
|
-
export * from './monitor/Monitor'
|
|
8
4
|
export * from './WalletPermissionsManager'
|
|
9
5
|
export * from './CWIStyleWalletManager'
|
|
10
6
|
export * from './WalletAuthenticationManager'
|
|
11
|
-
export * from './sdk/PrivilegedKeyManager'
|
|
12
|
-
export * from './SimpleWalletManager'
|
|
13
7
|
export * from './wab-client/WABClient'
|
|
14
8
|
export * from './wab-client/auth-method-interactors/TwilioPhoneInteractor'
|
|
15
9
|
export * from './wab-client/auth-method-interactors/PersonaIDInteractor'
|
|
16
10
|
export * from './wab-client/auth-method-interactors/AuthMethodInteractor'
|
|
11
|
+
export * from './services/Services'
|
|
12
|
+
export * from './sdk/PrivilegedKeyManager'
|
|
13
|
+
export * from './SimpleWalletManager'
|
|
14
|
+
export * from './storage/index.client'
|
|
15
|
+
export * from './Wallet'
|
package/src/monitor/Monitor.ts
CHANGED
|
@@ -1,20 +1,23 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as sdk from '../sdk'
|
|
2
|
+
import { Services } from '../services'
|
|
3
|
+
import { wait } from '../utility/utilityHelpers'
|
|
2
4
|
import { BlockHeader, ChaintracksServiceClient } from '../services/chaintracker'
|
|
5
|
+
|
|
6
|
+
import { WalletMonitorTask } from './tasks/WalletMonitorTask'
|
|
7
|
+
import { WalletStorageManager } from '../storage/WalletStorageManager'
|
|
8
|
+
|
|
3
9
|
import { TaskPurge, TaskPurgeParams } from './tasks/TaskPurge'
|
|
4
10
|
import { TaskReviewStatus } from './tasks/TaskReviewStatus'
|
|
5
11
|
import { TaskSyncWhenIdle } from './tasks/TaskSyncWhenIdle'
|
|
6
12
|
import { TaskFailAbandoned } from './tasks/TaskFailAbandoned'
|
|
7
13
|
import { TaskCheckForProofs } from './tasks/TaskCheckForProofs'
|
|
8
|
-
import { TaskSendWaiting } from './tasks/TaskSendWaiting'
|
|
9
|
-
import { WalletMonitorTask } from './tasks/WalletMonitorTask'
|
|
10
14
|
import { TaskClock } from './tasks/TaskClock'
|
|
11
|
-
import { TaskNewHeader
|
|
12
|
-
|
|
15
|
+
import { TaskNewHeader } from './tasks/TaskNewHeader'
|
|
16
|
+
|
|
17
|
+
import { TaskSendWaiting } from './tasks/TaskSendWaiting'
|
|
13
18
|
import { TaskCheckNoSends } from './tasks/TaskCheckNoSends'
|
|
14
19
|
|
|
15
20
|
export type MonitorStorage = WalletStorageManager
|
|
16
|
-
//export type MonitorStorage = sdk.WalletStorage
|
|
17
|
-
//export type MonitorStorage = sdk.WalletStorage
|
|
18
21
|
|
|
19
22
|
export interface MonitorOptions {
|
|
20
23
|
chain: sdk.Chain
|
|
@@ -130,7 +133,6 @@ export class Monitor {
|
|
|
130
133
|
// No purging until invalid transactions are really invalid...
|
|
131
134
|
//this._tasks.push(new TaskPurge(this, this.defaultPurgeParams, 6 * this.oneHour))
|
|
132
135
|
this._tasks.push(new TaskReviewStatus(this))
|
|
133
|
-
this._tasks.push(new TaskUnFail(this))
|
|
134
136
|
}
|
|
135
137
|
|
|
136
138
|
/**
|
|
@@ -147,7 +149,6 @@ export class Monitor {
|
|
|
147
149
|
// No purging until invalid transactions are really invalid...
|
|
148
150
|
//this._tasks.push(new TaskPurge(this, this.defaultPurgeParams, 6 * this.oneHour))
|
|
149
151
|
this._tasks.push(new TaskReviewStatus(this))
|
|
150
|
-
this._tasks.push(new TaskUnFail(this))
|
|
151
152
|
}
|
|
152
153
|
|
|
153
154
|
addTask(task: WalletMonitorTask): void {
|
|
@@ -9,6 +9,9 @@ import {
|
|
|
9
9
|
WalletStorageManager
|
|
10
10
|
} from '../index.all'
|
|
11
11
|
|
|
12
|
+
// This task is not "client" compatible as it imports StorageKnex
|
|
13
|
+
import { TaskUnFail } from './tasks/TaskUnFail'
|
|
14
|
+
|
|
12
15
|
import { Knex, knex as makeKnex } from 'knex'
|
|
13
16
|
|
|
14
17
|
import dotenv from 'dotenv'
|
|
@@ -115,6 +118,7 @@ export class MonitorDaemon {
|
|
|
115
118
|
|
|
116
119
|
if (a.monitor._tasks.length === 0) {
|
|
117
120
|
a.monitor.addMultiUserTasks()
|
|
121
|
+
a.monitor.addTask(new TaskUnFail(a.monitor))
|
|
118
122
|
}
|
|
119
123
|
}
|
|
120
124
|
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { GetMerklePathResult } from '../../sdk'
|
|
2
|
+
import { EntityProvenTx, EntityProvenTxReq } from '../../storage/schema/entities'
|
|
3
|
+
import { TableProvenTxReq } from '../../storage/schema/tables'
|
|
4
|
+
import { doubleSha256BE } from '../../utility/utilityHelpers'
|
|
5
|
+
import { asString } from '../../utility/utilityHelpers.noBuffer'
|
|
2
6
|
import { Monitor } from '../Monitor'
|
|
3
7
|
import { WalletMonitorTask } from './WalletMonitorTask'
|
|
4
8
|
|
|
@@ -156,7 +160,7 @@ export async function getProofs(
|
|
|
156
160
|
|
|
157
161
|
const since = new Date()
|
|
158
162
|
|
|
159
|
-
let r:
|
|
163
|
+
let r: GetMerklePathResult
|
|
160
164
|
let ptx: EntityProvenTx | undefined
|
|
161
165
|
|
|
162
166
|
// External services will try multiple providers until one returns a proof,
|
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BlockHeader } from '../../services/chaintracker/chaintracks/BlockHeaderApi'
|
|
2
2
|
import { Monitor } from '../Monitor'
|
|
3
|
-
import { TaskCheckForProofs } from './TaskCheckForProofs'
|
|
4
3
|
import { WalletMonitorTask } from './WalletMonitorTask'
|
|
5
4
|
|
|
6
5
|
export class TaskNewHeader extends WalletMonitorTask {
|
|
7
6
|
static taskName = 'NewHeader'
|
|
8
|
-
header?:
|
|
7
|
+
header?: BlockHeader
|
|
9
8
|
|
|
10
9
|
constructor(
|
|
11
10
|
monitor: Monitor,
|
|
@@ -14,7 +13,7 @@ export class TaskNewHeader extends WalletMonitorTask {
|
|
|
14
13
|
super(monitor, TaskNewHeader.taskName)
|
|
15
14
|
}
|
|
16
15
|
|
|
17
|
-
async getHeader(): Promise<
|
|
16
|
+
async getHeader(): Promise<BlockHeader> {
|
|
18
17
|
return await this.monitor.chaintracks.findChainTipHeader()
|
|
19
18
|
}
|
|
20
19
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { PurgeParams } from '../../sdk/WalletStorage.interfaces'
|
|
2
2
|
import { Monitor } from '../Monitor'
|
|
3
3
|
import { WalletMonitorTask } from './WalletMonitorTask'
|
|
4
4
|
|
|
@@ -27,7 +27,7 @@ import { WalletMonitorTask } from './WalletMonitorTask'
|
|
|
27
27
|
* + Delete mapi_responses records
|
|
28
28
|
* + proven_tx_reqs table delete records
|
|
29
29
|
*/
|
|
30
|
-
export interface TaskPurgeParams extends
|
|
30
|
+
export interface TaskPurgeParams extends PurgeParams {}
|
|
31
31
|
|
|
32
32
|
export class TaskPurge extends WalletMonitorTask {
|
|
33
33
|
static taskName = 'Purge'
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { Transaction, Utils } from '@bsv/sdk'
|
|
2
|
-
import { EntityProvenTxReq, sdk, TableProvenTxReq } from '../../index.client'
|
|
3
2
|
import { Monitor } from '../Monitor'
|
|
4
3
|
import { WalletMonitorTask } from './WalletMonitorTask'
|
|
5
4
|
import { StorageKnex } from '../../storage/StorageKnex'
|
|
5
|
+
import { TableProvenTxReq } from '../../storage/schema/tables'
|
|
6
|
+
import { EntityProvenTxReq } from '../../storage/schema/entities'
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* Setting provenTxReq status to 'unfail' when 'invalid' will attempt to find a merklePath, and if successful:
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ArcConfig, Beef, Transaction as BsvTransaction, ChainTracker, MerklePath } from '@bsv/sdk'
|
|
2
|
-
import { sdk } from '../index.client'
|
|
3
2
|
import { ChaintracksServiceClient } from '../services/chaintracker'
|
|
3
|
+
import { Chain, ReqHistoryNote } from './types'
|
|
4
|
+
import { WalletError } from './WalletError'
|
|
4
5
|
/**
|
|
5
6
|
* Defines standard interfaces to access functionality implemented by external transaction processing services.
|
|
6
7
|
*/
|
|
@@ -8,7 +9,7 @@ export interface WalletServices {
|
|
|
8
9
|
/**
|
|
9
10
|
* The chain being serviced.
|
|
10
11
|
*/
|
|
11
|
-
chain:
|
|
12
|
+
chain: Chain
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* @returns standard `ChainTracker` service which requires `options.chaintracks` be valid.
|
|
@@ -107,7 +108,7 @@ export interface WalletServices {
|
|
|
107
108
|
* @param txids
|
|
108
109
|
* @param useNext
|
|
109
110
|
*/
|
|
110
|
-
getStatusForTxids(txids: string[], useNext?: boolean): Promise<
|
|
111
|
+
getStatusForTxids(txids: string[], useNext?: boolean): Promise<GetStatusForTxidsResult>
|
|
111
112
|
|
|
112
113
|
/**
|
|
113
114
|
* Attempts to determine the UTXO status of a transaction output.
|
|
@@ -131,13 +132,13 @@ export interface WalletServices {
|
|
|
131
132
|
useNext?: boolean
|
|
132
133
|
): Promise<GetUtxoStatusResult>
|
|
133
134
|
|
|
134
|
-
getScriptHashHistory(hash: string, useNext?: boolean): Promise<
|
|
135
|
+
getScriptHashHistory(hash: string, useNext?: boolean): Promise<GetScriptHashHistoryResult>
|
|
135
136
|
|
|
136
137
|
/**
|
|
137
138
|
* @returns a block header
|
|
138
139
|
* @param hash block hash
|
|
139
140
|
*/
|
|
140
|
-
hashToHeader(hash: string): Promise<
|
|
141
|
+
hashToHeader(hash: string): Promise<BlockHeader>
|
|
141
142
|
|
|
142
143
|
/**
|
|
143
144
|
* @returns whether the locktime value allows the transaction to be mined at the current chain height
|
|
@@ -162,7 +163,7 @@ export interface FiatExchangeRates {
|
|
|
162
163
|
}
|
|
163
164
|
|
|
164
165
|
export interface WalletServicesOptions {
|
|
165
|
-
chain:
|
|
166
|
+
chain: Chain
|
|
166
167
|
taalApiKey?: string
|
|
167
168
|
bitailsApiKey?: string
|
|
168
169
|
whatsOnChainApiKey?: string
|
|
@@ -187,8 +188,8 @@ export interface GetStatusForTxidsResult {
|
|
|
187
188
|
/**
|
|
188
189
|
* The first exception error that occurred during processing, if any.
|
|
189
190
|
*/
|
|
190
|
-
error?:
|
|
191
|
-
results:
|
|
191
|
+
error?: WalletError
|
|
192
|
+
results: StatusForTxidResult[]
|
|
192
193
|
}
|
|
193
194
|
|
|
194
195
|
export interface StatusForTxidResult {
|
|
@@ -225,7 +226,7 @@ export interface GetRawTxResult {
|
|
|
225
226
|
/**
|
|
226
227
|
* The first exception error that occurred during processing, if any.
|
|
227
228
|
*/
|
|
228
|
-
error?:
|
|
229
|
+
error?: WalletError
|
|
229
230
|
}
|
|
230
231
|
|
|
231
232
|
/**
|
|
@@ -247,9 +248,9 @@ export interface GetMerklePathResult {
|
|
|
247
248
|
/**
|
|
248
249
|
* The first exception error that occurred during processing, if any.
|
|
249
250
|
*/
|
|
250
|
-
error?:
|
|
251
|
+
error?: WalletError
|
|
251
252
|
|
|
252
|
-
notes?:
|
|
253
|
+
notes?: ReqHistoryNote[]
|
|
253
254
|
}
|
|
254
255
|
|
|
255
256
|
export interface PostTxResultForTxid {
|
|
@@ -281,7 +282,7 @@ export interface PostTxResultForTxid {
|
|
|
281
282
|
|
|
282
283
|
data?: object | string | PostTxResultForTxidError
|
|
283
284
|
|
|
284
|
-
notes?:
|
|
285
|
+
notes?: ReqHistoryNote[]
|
|
285
286
|
|
|
286
287
|
/**
|
|
287
288
|
* true iff service was unable to process a potentially valid transaction
|
|
@@ -311,7 +312,7 @@ export interface PostTxsResult {
|
|
|
311
312
|
*/
|
|
312
313
|
status: 'success' | 'error'
|
|
313
314
|
|
|
314
|
-
error?:
|
|
315
|
+
error?: WalletError
|
|
315
316
|
|
|
316
317
|
txidResults: PostTxResultForTxid[]
|
|
317
318
|
|
|
@@ -320,7 +321,7 @@ export interface PostTxsResult {
|
|
|
320
321
|
*/
|
|
321
322
|
data?: object
|
|
322
323
|
|
|
323
|
-
notes?:
|
|
324
|
+
notes?: ReqHistoryNote[]
|
|
324
325
|
}
|
|
325
326
|
|
|
326
327
|
export interface GetUtxoStatusDetails {
|
|
@@ -363,7 +364,7 @@ export interface GetUtxoStatusResult {
|
|
|
363
364
|
/**
|
|
364
365
|
* When status is 'error', provides code and description
|
|
365
366
|
*/
|
|
366
|
-
error?:
|
|
367
|
+
error?: WalletError
|
|
367
368
|
/**
|
|
368
369
|
* true if the output is associated with at least one unspent transaction output
|
|
369
370
|
*/
|
|
@@ -395,7 +396,7 @@ export interface GetScriptHashHistoryResult {
|
|
|
395
396
|
/**
|
|
396
397
|
* When status is 'error', provides code and description
|
|
397
398
|
*/
|
|
398
|
-
error?:
|
|
399
|
+
error?: WalletError
|
|
399
400
|
/**
|
|
400
401
|
* Transaction txid (and height if mined) that consumes the script hash. May not be a complete history.
|
|
401
402
|
*/
|
|
@@ -455,13 +456,13 @@ export type GetUtxoStatusService = (
|
|
|
455
456
|
outpoint?: string
|
|
456
457
|
) => Promise<GetUtxoStatusResult>
|
|
457
458
|
|
|
458
|
-
export type GetStatusForTxidsService = (txids: string[]) => Promise<
|
|
459
|
+
export type GetStatusForTxidsService = (txids: string[]) => Promise<GetStatusForTxidsResult>
|
|
459
460
|
|
|
460
461
|
export type GetScriptHashHistoryService = (hash: string) => Promise<GetScriptHashHistoryResult>
|
|
461
462
|
|
|
462
463
|
export type GetMerklePathService = (txid: string, services: WalletServices) => Promise<GetMerklePathResult>
|
|
463
464
|
|
|
464
|
-
export type GetRawTxService = (txid: string, chain:
|
|
465
|
+
export type GetRawTxService = (txid: string, chain: Chain) => Promise<GetRawTxResult>
|
|
465
466
|
|
|
466
467
|
export type PostTxsService = (beef: Beef, txids: string[], services: WalletServices) => Promise<PostTxsResult>
|
|
467
468
|
|
|
@@ -1,38 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
AbortActionResult,
|
|
4
|
-
AcquireCertificateArgs,
|
|
5
|
-
AcquireCertificateResult,
|
|
6
|
-
CreateActionArgs,
|
|
7
|
-
CreateActionResult,
|
|
8
|
-
DiscoverByAttributesArgs,
|
|
9
|
-
DiscoverByIdentityKeyArgs,
|
|
10
|
-
DiscoverCertificatesResult,
|
|
11
|
-
InternalizeActionArgs,
|
|
12
|
-
InternalizeActionResult,
|
|
13
|
-
KeyDeriverApi,
|
|
14
|
-
ListActionsArgs,
|
|
15
|
-
ListActionsResult,
|
|
16
|
-
ListCertificatesArgs,
|
|
17
|
-
ListCertificatesResult,
|
|
18
|
-
ListOutputsArgs,
|
|
19
|
-
ListOutputsResult,
|
|
20
|
-
ProveCertificateArgs,
|
|
21
|
-
ProveCertificateResult,
|
|
22
|
-
RelinquishCertificateArgs,
|
|
23
|
-
RelinquishCertificateResult,
|
|
24
|
-
RelinquishOutputArgs,
|
|
25
|
-
RelinquishOutputResult,
|
|
26
|
-
SignActionArgs,
|
|
27
|
-
SignActionResult
|
|
28
|
-
} from '@bsv/sdk'
|
|
29
|
-
import { sdk } from '../index.client'
|
|
1
|
+
import { KeyDeriverApi } from '@bsv/sdk'
|
|
2
|
+
import { Chain } from './types'
|
|
30
3
|
|
|
31
4
|
/**
|
|
32
5
|
*/
|
|
33
6
|
export interface WalletSigner {
|
|
34
7
|
isWalletSigner: true
|
|
35
8
|
|
|
36
|
-
chain:
|
|
9
|
+
chain: Chain
|
|
37
10
|
keyDeriver: KeyDeriverApi
|
|
38
11
|
}
|