@bsv/wallet-toolbox 1.5.11 → 1.5.13
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 +189 -84
- package/docs/monitor.md +39 -2
- package/docs/setup.md +8 -8
- package/docs/wallet.md +189 -84
- package/mobile/out/src/SetupClient.d.ts +2 -2
- package/mobile/out/src/SetupClient.d.ts.map +1 -1
- package/mobile/out/src/SetupClient.js +2 -2
- package/mobile/out/src/SetupClient.js.map +1 -1
- package/mobile/out/src/SetupWallet.d.ts +2 -2
- package/mobile/out/src/SetupWallet.d.ts.map +1 -1
- package/mobile/out/src/Wallet.d.ts +3 -3
- package/mobile/out/src/Wallet.d.ts.map +1 -1
- package/mobile/out/src/Wallet.js.map +1 -1
- package/mobile/out/src/monitor/Monitor.d.ts +23 -0
- package/mobile/out/src/monitor/Monitor.d.ts.map +1 -1
- package/mobile/out/src/monitor/Monitor.js +26 -16
- package/mobile/out/src/monitor/Monitor.js.map +1 -1
- package/mobile/out/src/monitor/tasks/TaskCheckForProofs.d.ts.map +1 -1
- package/mobile/out/src/monitor/tasks/TaskCheckForProofs.js +8 -0
- package/mobile/out/src/monitor/tasks/TaskCheckForProofs.js.map +1 -1
- package/mobile/out/src/monitor/tasks/TaskSendWaiting.d.ts.map +1 -1
- package/mobile/out/src/monitor/tasks/TaskSendWaiting.js +9 -0
- package/mobile/out/src/monitor/tasks/TaskSendWaiting.js.map +1 -1
- package/mobile/out/src/sdk/types.d.ts +11 -0
- package/mobile/out/src/sdk/types.d.ts.map +1 -1
- package/mobile/out/src/sdk/types.js.map +1 -1
- package/mobile/out/src/signer/WalletSigner.d.ts +3 -3
- package/mobile/out/src/signer/WalletSigner.d.ts.map +1 -1
- package/mobile/out/src/signer/WalletSigner.js.map +1 -1
- package/mobile/out/src/storage/methods/processAction.d.ts.map +1 -1
- package/mobile/out/src/storage/methods/processAction.js +6 -64
- package/mobile/out/src/storage/methods/processAction.js.map +1 -1
- package/mobile/out/src/utility/ScriptTemplateBRC29.d.ts.map +1 -1
- package/mobile/out/src/utility/ScriptTemplateBRC29.js +1 -1
- package/mobile/out/src/utility/ScriptTemplateBRC29.js.map +1 -1
- package/mobile/out/src/utility/aggregateResults.d.ts +8 -0
- package/mobile/out/src/utility/aggregateResults.d.ts.map +1 -0
- package/mobile/out/src/utility/aggregateResults.js +59 -0
- package/mobile/out/src/utility/aggregateResults.js.map +1 -0
- package/mobile/package-lock.json +6 -7
- package/mobile/package.json +2 -2
- package/out/src/Setup.d.ts +2 -2
- package/out/src/Setup.d.ts.map +1 -1
- package/out/src/Setup.js +2 -2
- package/out/src/Setup.js.map +1 -1
- package/out/src/SetupClient.d.ts +2 -2
- package/out/src/SetupClient.d.ts.map +1 -1
- package/out/src/SetupClient.js +2 -2
- package/out/src/SetupClient.js.map +1 -1
- package/out/src/SetupWallet.d.ts +2 -2
- package/out/src/SetupWallet.d.ts.map +1 -1
- package/out/src/Wallet.d.ts +3 -3
- package/out/src/Wallet.d.ts.map +1 -1
- package/out/src/Wallet.js.map +1 -1
- package/out/src/__tests/WalletPermissionsManager.proxying.test.js +1 -1
- package/out/src/__tests/WalletPermissionsManager.proxying.test.js.map +1 -1
- package/out/src/monitor/Monitor.d.ts +23 -0
- package/out/src/monitor/Monitor.d.ts.map +1 -1
- package/out/src/monitor/Monitor.js +26 -16
- package/out/src/monitor/Monitor.js.map +1 -1
- package/out/src/monitor/tasks/TaskCheckForProofs.d.ts.map +1 -1
- package/out/src/monitor/tasks/TaskCheckForProofs.js +8 -0
- package/out/src/monitor/tasks/TaskCheckForProofs.js.map +1 -1
- package/out/src/monitor/tasks/TaskSendWaiting.d.ts.map +1 -1
- package/out/src/monitor/tasks/TaskSendWaiting.js +9 -0
- package/out/src/monitor/tasks/TaskSendWaiting.js.map +1 -1
- package/out/src/sdk/types.d.ts +11 -0
- package/out/src/sdk/types.d.ts.map +1 -1
- package/out/src/sdk/types.js.map +1 -1
- package/out/src/services/__tests/ARC.timeout.man.test.js +1 -1
- package/out/src/signer/WalletSigner.d.ts +3 -3
- package/out/src/signer/WalletSigner.d.ts.map +1 -1
- package/out/src/signer/WalletSigner.js.map +1 -1
- package/out/src/storage/methods/processAction.d.ts.map +1 -1
- package/out/src/storage/methods/processAction.js +6 -64
- package/out/src/storage/methods/processAction.js.map +1 -1
- package/out/src/utility/ScriptTemplateBRC29.d.ts.map +1 -1
- package/out/src/utility/ScriptTemplateBRC29.js +1 -1
- package/out/src/utility/ScriptTemplateBRC29.js.map +1 -1
- package/out/src/utility/aggregateResults.d.ts +8 -0
- package/out/src/utility/aggregateResults.d.ts.map +1 -0
- package/out/src/utility/aggregateResults.js +59 -0
- package/out/src/utility/aggregateResults.js.map +1 -0
- package/out/test/Wallet/live/walletLive.man.test.d.ts.map +1 -1
- package/out/test/Wallet/live/walletLive.man.test.js +1 -1
- package/out/test/Wallet/live/walletLive.man.test.js.map +1 -1
- package/out/test/monitor/Monitor.test.js +101 -0
- package/out/test/monitor/Monitor.test.js.map +1 -1
- package/out/test/utils/TestUtilsWalletStorage.d.ts +4 -4
- package/out/test/utils/TestUtilsWalletStorage.d.ts.map +1 -1
- package/out/test/utils/TestUtilsWalletStorage.js +3 -3
- package/out/test/utils/TestUtilsWalletStorage.js.map +1 -1
- package/out/tsconfig.all.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/Setup.ts +5 -3
- package/src/SetupClient.ts +5 -3
- package/src/SetupWallet.ts +2 -2
- package/src/Wallet.ts +4 -3
- package/src/__tests/WalletPermissionsManager.proxying.test.ts +1 -1
- package/src/monitor/Monitor.ts +36 -15
- package/src/monitor/tasks/TaskCheckForProofs.ts +9 -0
- package/src/monitor/tasks/TaskSendWaiting.ts +12 -1
- package/src/sdk/types.ts +12 -0
- package/src/services/__tests/ARC.timeout.man.test.ts +1 -1
- package/src/signer/WalletSigner.ts +3 -3
- package/src/storage/methods/processAction.ts +7 -78
- package/src/utility/ScriptTemplateBRC29.ts +3 -2
- package/src/utility/aggregateResults.ts +68 -0
- package/test/Wallet/live/walletLive.man.test.ts +2 -1
- package/test/monitor/Monitor.test.ts +123 -1
- package/test/utils/TestUtilsWalletStorage.ts +8 -6
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bsv/wallet-toolbox",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.13",
|
|
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.2.0",
|
|
34
34
|
"@bsv/payment-express-middleware": "^1.2.1",
|
|
35
|
-
"@bsv/sdk": "^1.6.
|
|
35
|
+
"@bsv/sdk": "^1.6.16",
|
|
36
36
|
"express": "^4.21.2",
|
|
37
37
|
"idb": "^8.0.2",
|
|
38
38
|
"knex": "^3.1.0",
|
package/src/Setup.ts
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { KeyPairAddress, SetupWallet, SetupWalletClient } from './SetupWallet'
|
|
2
2
|
import {
|
|
3
3
|
BEEF,
|
|
4
|
+
CachedKeyDeriver,
|
|
4
5
|
CreateActionArgs,
|
|
5
6
|
CreateActionOptions,
|
|
6
7
|
CreateActionOutput,
|
|
7
8
|
CreateActionResult,
|
|
8
9
|
KeyDeriver,
|
|
10
|
+
KeyDeriverApi,
|
|
9
11
|
LockingScript,
|
|
10
12
|
P2PKH,
|
|
11
13
|
PrivateKey,
|
|
@@ -142,7 +144,7 @@ DEV_KEYS = '{
|
|
|
142
144
|
args.rootKeyHex ||= args.env.devKeys[args.env.identityKey]
|
|
143
145
|
const rootKey = PrivateKey.fromHex(args.rootKeyHex)
|
|
144
146
|
const identityKey = rootKey.toPublicKey().toString()
|
|
145
|
-
const keyDeriver = new
|
|
147
|
+
const keyDeriver = new CachedKeyDeriver(rootKey)
|
|
146
148
|
const storage = new WalletStorageManager(identityKey, args.active, args.backups)
|
|
147
149
|
if (storage.canMakeAvailable()) await storage.makeAvailable()
|
|
148
150
|
const serviceOptions = Services.createDefaultOptions(chain)
|
|
@@ -196,7 +198,7 @@ DEV_KEYS = '{
|
|
|
196
198
|
const chain = args.chain
|
|
197
199
|
const endpointUrl = args.storageUrl || `https://${args.chain !== 'main' ? 'staging-' : ''}storage.babbage.systems`
|
|
198
200
|
const rootKey = PrivateKey.fromHex(args.rootKeyHex)
|
|
199
|
-
const keyDeriver = new
|
|
201
|
+
const keyDeriver = new CachedKeyDeriver(rootKey)
|
|
200
202
|
const storage = new WalletStorageManager(keyDeriver.identityKey)
|
|
201
203
|
const services = new Services(chain)
|
|
202
204
|
const privilegedKeyManager = args.privilegedKeyGetter
|
|
@@ -512,7 +514,7 @@ export interface SetupWalletKnex extends SetupWallet {
|
|
|
512
514
|
|
|
513
515
|
rootKey: PrivateKey
|
|
514
516
|
identityKey: string
|
|
515
|
-
keyDeriver:
|
|
517
|
+
keyDeriver: KeyDeriverApi
|
|
516
518
|
chain: sdk.Chain
|
|
517
519
|
storage: WalletStorageManager
|
|
518
520
|
services: Services
|
package/src/SetupClient.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
BEEF,
|
|
3
|
+
CachedKeyDeriver,
|
|
3
4
|
CreateActionArgs,
|
|
4
5
|
CreateActionOptions,
|
|
5
6
|
CreateActionOutput,
|
|
6
7
|
CreateActionResult,
|
|
7
8
|
KeyDeriver,
|
|
9
|
+
KeyDeriverApi,
|
|
8
10
|
LockingScript,
|
|
9
11
|
P2PKH,
|
|
10
12
|
PrivateKey,
|
|
@@ -34,7 +36,7 @@ export abstract class SetupClient {
|
|
|
34
36
|
const chain = args.chain
|
|
35
37
|
const rootKey = PrivateKey.fromHex(args.rootKeyHex)
|
|
36
38
|
const identityKey = rootKey.toPublicKey().toString()
|
|
37
|
-
const keyDeriver = new
|
|
39
|
+
const keyDeriver = new CachedKeyDeriver(rootKey)
|
|
38
40
|
const storage = new WalletStorageManager(identityKey, args.active, args.backups)
|
|
39
41
|
if (storage.canMakeAvailable()) await storage.makeAvailable()
|
|
40
42
|
const serviceOptions = Services.createDefaultOptions(chain)
|
|
@@ -84,7 +86,7 @@ export abstract class SetupClient {
|
|
|
84
86
|
const chain = args.chain
|
|
85
87
|
const endpointUrl = args.storageUrl || `https://${args.chain !== 'main' ? 'staging-' : ''}storage.babbage.systems`
|
|
86
88
|
const rootKey = PrivateKey.fromHex(args.rootKeyHex)
|
|
87
|
-
const keyDeriver = new
|
|
89
|
+
const keyDeriver = new CachedKeyDeriver(rootKey)
|
|
88
90
|
const storage = new WalletStorageManager(keyDeriver.identityKey)
|
|
89
91
|
const services = new Services(chain)
|
|
90
92
|
const privilegedKeyManager = args.privilegedKeyGetter
|
|
@@ -290,7 +292,7 @@ export interface SetupWalletIdb extends SetupWallet {
|
|
|
290
292
|
|
|
291
293
|
rootKey: PrivateKey
|
|
292
294
|
identityKey: string
|
|
293
|
-
keyDeriver:
|
|
295
|
+
keyDeriver: KeyDeriverApi
|
|
294
296
|
chain: sdk.Chain
|
|
295
297
|
storage: WalletStorageManager
|
|
296
298
|
services: Services
|
package/src/SetupWallet.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { PrivateKey, KeyDeriver, PublicKey } from '@bsv/sdk'
|
|
1
|
+
import { PrivateKey, KeyDeriver, PublicKey, KeyDeriverApi } from '@bsv/sdk'
|
|
2
2
|
import { WalletStorageManager, Monitor, sdk } from './index.client'
|
|
3
3
|
import { Services } from './services'
|
|
4
4
|
import { Wallet } from './Wallet'
|
|
@@ -23,7 +23,7 @@ export interface SetupWallet {
|
|
|
23
23
|
/**
|
|
24
24
|
* The `KeyDeriver` component used by the wallet for key derivation and cryptographic functions.
|
|
25
25
|
*/
|
|
26
|
-
keyDeriver:
|
|
26
|
+
keyDeriver: KeyDeriverApi
|
|
27
27
|
/**
|
|
28
28
|
* The chain ('main' or 'test') which the wallet accesses.
|
|
29
29
|
*/
|
package/src/Wallet.ts
CHANGED
|
@@ -65,7 +65,8 @@ import {
|
|
|
65
65
|
Certificate,
|
|
66
66
|
LookupResolver,
|
|
67
67
|
AtomicBEEF,
|
|
68
|
-
BEEF
|
|
68
|
+
BEEF,
|
|
69
|
+
KeyDeriverApi
|
|
69
70
|
} from '@bsv/sdk'
|
|
70
71
|
import * as sdk from './sdk'
|
|
71
72
|
import { acquireDirectCertificate } from './signer/methods/acquireDirectCertificate'
|
|
@@ -92,7 +93,7 @@ import { ScriptTemplateBRC29 } from './utility/ScriptTemplateBRC29'
|
|
|
92
93
|
|
|
93
94
|
export interface WalletArgs {
|
|
94
95
|
chain: sdk.Chain
|
|
95
|
-
keyDeriver:
|
|
96
|
+
keyDeriver: KeyDeriverApi
|
|
96
97
|
storage: WalletStorageManager
|
|
97
98
|
services?: sdk.WalletServices
|
|
98
99
|
monitor?: Monitor
|
|
@@ -107,7 +108,7 @@ function isWalletSigner(args: WalletArgs | WalletSigner): args is WalletSigner {
|
|
|
107
108
|
|
|
108
109
|
export class Wallet implements WalletInterface, ProtoWallet {
|
|
109
110
|
chain: sdk.Chain
|
|
110
|
-
keyDeriver:
|
|
111
|
+
keyDeriver: KeyDeriverApi
|
|
111
112
|
storage: WalletStorageManager
|
|
112
113
|
settingsManager: WalletSettingsManager
|
|
113
114
|
lookupResolver: LookupResolver
|
|
@@ -679,7 +679,7 @@ describe('WalletPermissionsManager - Regression & Integration with Underlying Wa
|
|
|
679
679
|
const result = await manager.waitForAuthentication({}, 'someone.com')
|
|
680
680
|
expect(result.authenticated).toBe(true)
|
|
681
681
|
expect(underlying.waitForAuthentication).toHaveBeenCalledTimes(1)
|
|
682
|
-
})
|
|
682
|
+
}, 30000)
|
|
683
683
|
|
|
684
684
|
it('should proxy getHeight', async () => {
|
|
685
685
|
const result = await manager.getHeight({}, 'someone.com')
|
package/src/monitor/Monitor.ts
CHANGED
|
@@ -42,6 +42,12 @@ export interface MonitorOptions {
|
|
|
42
42
|
unprovenAttemptsLimitTest: number
|
|
43
43
|
|
|
44
44
|
unprovenAttemptsLimitMain: number
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* These are hooks for a wallet-toolbox client to get transaction updates.
|
|
48
|
+
*/
|
|
49
|
+
onTransactionBroadcasted?: (broadcastResult: sdk.ReviewActionResult) => Promise<void>
|
|
50
|
+
onTransactionProven?: (txStatus: sdk.ProvenTransactionStatus) => Promise<void>
|
|
45
51
|
}
|
|
46
52
|
|
|
47
53
|
/**
|
|
@@ -75,6 +81,8 @@ export class Monitor {
|
|
|
75
81
|
chain: sdk.Chain
|
|
76
82
|
storage: MonitorStorage
|
|
77
83
|
chaintracks: ChaintracksServiceClient
|
|
84
|
+
onTransactionBroadcasted?: (broadcastResult: sdk.ReviewActionResult) => Promise<void>
|
|
85
|
+
onTransactionProven?: (txStatus: sdk.ProvenTransactionStatus) => Promise<void>
|
|
78
86
|
|
|
79
87
|
constructor(options: MonitorOptions) {
|
|
80
88
|
this.options = { ...options }
|
|
@@ -82,6 +90,8 @@ export class Monitor {
|
|
|
82
90
|
this.chain = this.services.chain
|
|
83
91
|
this.storage = options.storage
|
|
84
92
|
this.chaintracks = options.chaintracks
|
|
93
|
+
this.onTransactionProven = options.onTransactionProven
|
|
94
|
+
this.onTransactionBroadcasted = options.onTransactionBroadcasted
|
|
85
95
|
}
|
|
86
96
|
|
|
87
97
|
oneSecond = 1000
|
|
@@ -286,6 +296,32 @@ export class Monitor {
|
|
|
286
296
|
TaskCheckForProofs.checkNow = true
|
|
287
297
|
}
|
|
288
298
|
|
|
299
|
+
/**
|
|
300
|
+
* This is a function run from a TaskSendWaiting Monitor task.
|
|
301
|
+
*
|
|
302
|
+
* This allows the user of wallet-toolbox to 'subscribe' for transaction broadcast updates.
|
|
303
|
+
*
|
|
304
|
+
* @param broadcastResult
|
|
305
|
+
*/
|
|
306
|
+
callOnBroadcastedTransaction(broadcastResult: sdk.ReviewActionResult): void {
|
|
307
|
+
if (this.onTransactionBroadcasted) {
|
|
308
|
+
this.onTransactionBroadcasted(broadcastResult)
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* This is a function run from a TaskCheckForProofs Monitor task.
|
|
314
|
+
*
|
|
315
|
+
* This allows the user of wallet-toolbox to 'subscribe' for transaction updates.
|
|
316
|
+
*
|
|
317
|
+
* @param txStatus
|
|
318
|
+
*/
|
|
319
|
+
callOnProvenTransaction(txStatus: sdk.ProvenTransactionStatus): void {
|
|
320
|
+
if (this.onTransactionProven) {
|
|
321
|
+
this.onTransactionProven(txStatus)
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
289
325
|
/**
|
|
290
326
|
* Process reorg event received from Chaintracks
|
|
291
327
|
*
|
|
@@ -301,18 +337,3 @@ export class Monitor {
|
|
|
301
337
|
/* */
|
|
302
338
|
}
|
|
303
339
|
}
|
|
304
|
-
|
|
305
|
-
function sum<T>(a: T[], getNum: (v: T) => number): number {
|
|
306
|
-
let s = 0
|
|
307
|
-
for (const v of a) s += getNum(v)
|
|
308
|
-
return s
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
function filter<T>(a: T[], pred: (v: T) => boolean): { ts: T[]; fs: T[] } {
|
|
312
|
-
const ts: T[] = []
|
|
313
|
-
const fs: T[] = []
|
|
314
|
-
for (const v of a)
|
|
315
|
-
if (pred(v)) ts.push(v)
|
|
316
|
-
else fs.push(v)
|
|
317
|
-
return { ts, fs }
|
|
318
|
-
}
|
|
@@ -216,6 +216,15 @@ export async function getProofs(
|
|
|
216
216
|
req.apiHistory = r.history
|
|
217
217
|
req.provenTxId = r.provenTxId
|
|
218
218
|
req.notified = true
|
|
219
|
+
|
|
220
|
+
task.monitor.callOnProvenTransaction({
|
|
221
|
+
txid,
|
|
222
|
+
txIndex: index,
|
|
223
|
+
blockHeight: height,
|
|
224
|
+
blockHash,
|
|
225
|
+
merklePath,
|
|
226
|
+
merkleRoot
|
|
227
|
+
})
|
|
219
228
|
} else {
|
|
220
229
|
if (countsAsAttempt && req.status !== 'nosend') {
|
|
221
230
|
req.attempts++
|
|
@@ -3,7 +3,9 @@ import { verifyTruthy } from '../../utility/index.client'
|
|
|
3
3
|
import { Monitor } from '../Monitor'
|
|
4
4
|
import { WalletMonitorTask } from './WalletMonitorTask'
|
|
5
5
|
import { attemptToPostReqsToNetwork } from '../../storage/methods/attemptToPostReqsToNetwork'
|
|
6
|
-
import { ProvenTxReqStatus } from '../../sdk'
|
|
6
|
+
import { ProvenTxReqStatus, WERR_INTERNAL } from '../../sdk'
|
|
7
|
+
import { ReviewActionResult, SendWithResult } from '@bsv/sdk'
|
|
8
|
+
import { aggregateActionResults } from '../../utility/aggregateResults'
|
|
7
9
|
|
|
8
10
|
export class TaskSendWaiting extends WalletMonitorTask {
|
|
9
11
|
static taskName = 'SendWaiting'
|
|
@@ -103,6 +105,15 @@ export class TaskSendWaiting extends WalletMonitorTask {
|
|
|
103
105
|
return attemptToPostReqsToNetwork(sp, reqs)
|
|
104
106
|
})
|
|
105
107
|
|
|
108
|
+
if (this.monitor.onTransactionBroadcasted) {
|
|
109
|
+
const rar = await this.storage.runAsStorageProvider(async sp => {
|
|
110
|
+
const ars: SendWithResult[] = [{ txid: req.txid, status: 'sending' }]
|
|
111
|
+
const { rar } = await aggregateActionResults(sp, ars, r)
|
|
112
|
+
return rar
|
|
113
|
+
})
|
|
114
|
+
this.monitor.callOnBroadcastedTransaction(rar[0])
|
|
115
|
+
}
|
|
116
|
+
|
|
106
117
|
log += r.log
|
|
107
118
|
}
|
|
108
119
|
return log
|
package/src/sdk/types.ts
CHANGED
|
@@ -133,6 +133,18 @@ export type ReqHistoryNote = {
|
|
|
133
133
|
[key: string]: boolean | string | number | undefined
|
|
134
134
|
}
|
|
135
135
|
|
|
136
|
+
/**
|
|
137
|
+
* The transaction status that a client will receive when subscribing to transaction updates in the Monitor.
|
|
138
|
+
*/
|
|
139
|
+
export interface ProvenTransactionStatus {
|
|
140
|
+
txid: string
|
|
141
|
+
txIndex: number
|
|
142
|
+
blockHeight: number
|
|
143
|
+
blockHash: string
|
|
144
|
+
merklePath: number[]
|
|
145
|
+
merkleRoot: string
|
|
146
|
+
}
|
|
147
|
+
|
|
136
148
|
/**
|
|
137
149
|
* `listOutputs` special operation basket name value.
|
|
138
150
|
*
|
|
@@ -45,7 +45,7 @@ describe('ARC tests', () => {
|
|
|
45
45
|
|
|
46
46
|
const headers: Record<string, string> = {
|
|
47
47
|
'Content-Type': 'application/json',
|
|
48
|
-
'XDeployment-ID': 'wallet-toolbox-test11'
|
|
48
|
+
'XDeployment-ID': 'wallet-toolbox-test11'
|
|
49
49
|
//Authorization: `Bearer ${envMain.gorillaPoolApiKey}`
|
|
50
50
|
}
|
|
51
51
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { KeyDeriver } from '@bsv/sdk'
|
|
1
|
+
import { KeyDeriver, KeyDeriverApi } from '@bsv/sdk'
|
|
2
2
|
import { sdk } from '../index.client'
|
|
3
3
|
import { WalletStorageManager } from '../storage/WalletStorageManager'
|
|
4
4
|
|
|
@@ -6,10 +6,10 @@ export class WalletSigner {
|
|
|
6
6
|
isWalletSigner: true = true
|
|
7
7
|
|
|
8
8
|
chain: sdk.Chain
|
|
9
|
-
keyDeriver:
|
|
9
|
+
keyDeriver: KeyDeriverApi
|
|
10
10
|
storage: WalletStorageManager
|
|
11
11
|
|
|
12
|
-
constructor(chain: sdk.Chain, keyDeriver:
|
|
12
|
+
constructor(chain: sdk.Chain, keyDeriver: KeyDeriverApi, storage: WalletStorageManager) {
|
|
13
13
|
this.chain = chain
|
|
14
14
|
this.keyDeriver = keyDeriver
|
|
15
15
|
this.storage = storage
|
|
@@ -7,9 +7,7 @@ import {
|
|
|
7
7
|
parseTxScriptOffsets,
|
|
8
8
|
randomBytesBase64,
|
|
9
9
|
sdk,
|
|
10
|
-
sha256Hash,
|
|
11
10
|
stampLog,
|
|
12
|
-
stampLogFormat,
|
|
13
11
|
StorageProvider,
|
|
14
12
|
TableCommission,
|
|
15
13
|
TableOutput,
|
|
@@ -17,16 +15,14 @@ import {
|
|
|
17
15
|
TableProvenTxReq,
|
|
18
16
|
TableTransaction,
|
|
19
17
|
TxScriptOffsets,
|
|
20
|
-
validateStorageFeeModel,
|
|
21
18
|
verifyId,
|
|
22
19
|
verifyInteger,
|
|
23
|
-
verifyNumber,
|
|
24
20
|
verifyOne,
|
|
25
21
|
verifyOneOrNone,
|
|
26
22
|
verifyTruthy
|
|
27
23
|
} from '../../index.client'
|
|
28
|
-
import { ReviewActionResult
|
|
29
|
-
import {
|
|
24
|
+
import { ReviewActionResult } from '../../sdk'
|
|
25
|
+
import { aggregateActionResults } from '../../utility/aggregateResults'
|
|
30
26
|
|
|
31
27
|
export async function processAction(
|
|
32
28
|
storage: StorageProvider,
|
|
@@ -122,15 +118,6 @@ export async function shareReqsWithWorld(
|
|
|
122
118
|
// Collect what we know about these sendWith transaction txids from storage.
|
|
123
119
|
const r = await storage.getReqsAndBeefToShareWithWorld(txids, [])
|
|
124
120
|
|
|
125
|
-
// Initialize aggregate results for each txid
|
|
126
|
-
const ars: {
|
|
127
|
-
txid: string
|
|
128
|
-
status: SendWithResultStatus
|
|
129
|
-
getReq: GetReqsAndBeefDetail
|
|
130
|
-
postReq?: PostReqsToNetworkDetails
|
|
131
|
-
ndr?: ReviewActionResult
|
|
132
|
-
}[] = []
|
|
133
|
-
|
|
134
121
|
const readyToSendReqs: EntityProvenTxReq[] = []
|
|
135
122
|
for (const getReq of r.details) {
|
|
136
123
|
let status: SendWithResultStatus = 'failed'
|
|
@@ -139,9 +126,8 @@ export async function shareReqsWithWorld(
|
|
|
139
126
|
status = 'sending'
|
|
140
127
|
readyToSendReqs.push(new EntityProvenTxReq(getReq.req!))
|
|
141
128
|
}
|
|
142
|
-
|
|
129
|
+
swr.push({
|
|
143
130
|
txid: getReq.txid,
|
|
144
|
-
getReq,
|
|
145
131
|
status
|
|
146
132
|
})
|
|
147
133
|
}
|
|
@@ -171,11 +157,11 @@ export async function shareReqsWithWorld(
|
|
|
171
157
|
await storage.updateTransaction(transactionIds, { status: 'sending' }, trx)
|
|
172
158
|
})
|
|
173
159
|
}
|
|
174
|
-
return
|
|
160
|
+
return { swr, ndr }
|
|
175
161
|
}
|
|
176
162
|
|
|
177
163
|
if (readyToSendReqIds.length < 1) {
|
|
178
|
-
return
|
|
164
|
+
return { swr, ndr }
|
|
179
165
|
}
|
|
180
166
|
|
|
181
167
|
if (batch) {
|
|
@@ -189,53 +175,8 @@ export async function shareReqsWithWorld(
|
|
|
189
175
|
//
|
|
190
176
|
const prtn = await storage.attemptToPostReqsToNetwork(readyToSendReqs)
|
|
191
177
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
const txid = ar.txid
|
|
195
|
-
const d = prtn.details.find(d => d.txid === txid)
|
|
196
|
-
if (!d) throw new sdk.WERR_INTERNAL(`missing details for ${txid}`)
|
|
197
|
-
ar.ndr = { txid: d.txid, status: 'success', competingTxs: d.competingTxs }
|
|
198
|
-
switch (d.status) {
|
|
199
|
-
case 'success':
|
|
200
|
-
// processing network has accepted this transaction
|
|
201
|
-
ar.status = 'unproven'
|
|
202
|
-
break
|
|
203
|
-
case 'doubleSpend':
|
|
204
|
-
// confirmed double spend.
|
|
205
|
-
ar.status = 'failed'
|
|
206
|
-
ar.ndr.status = 'doubleSpend'
|
|
207
|
-
if (d.competingTxs) ar.ndr.competingBeef = await createMergedBeefOfTxids(d.competingTxs, storage)
|
|
208
|
-
break
|
|
209
|
-
case 'serviceError':
|
|
210
|
-
// services might improve
|
|
211
|
-
ar.status = 'sending'
|
|
212
|
-
ar.ndr.status = 'serviceError'
|
|
213
|
-
break
|
|
214
|
-
case 'invalidTx':
|
|
215
|
-
// nothing will fix this transaction
|
|
216
|
-
ar.status = 'failed'
|
|
217
|
-
ar.ndr.status = 'invalidTx'
|
|
218
|
-
break
|
|
219
|
-
case 'unknown':
|
|
220
|
-
case 'invalid':
|
|
221
|
-
default:
|
|
222
|
-
throw new sdk.WERR_INTERNAL(`processAction with notDelayed status ${d.status} should not occur.`)
|
|
223
|
-
}
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
return createResults()
|
|
227
|
-
|
|
228
|
-
function createResults(): { swr: SendWithResult[]; ndr: ReviewActionResult[] | undefined } {
|
|
229
|
-
swr = []
|
|
230
|
-
ndr = isDelayed ? undefined : []
|
|
231
|
-
for (const ar of ars) {
|
|
232
|
-
swr.push({ txid: ar.txid, status: ar.status })
|
|
233
|
-
if (ar.ndr && ndr) {
|
|
234
|
-
ndr.push(ar.ndr)
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
return { swr, ndr }
|
|
238
|
-
}
|
|
178
|
+
const { swr: swrRes, rar } = await aggregateActionResults(storage, swr, prtn)
|
|
179
|
+
return { swr: swrRes, ndr: rar }
|
|
239
180
|
}
|
|
240
181
|
|
|
241
182
|
interface ReqTxStatus {
|
|
@@ -452,15 +393,3 @@ async function commitNewTxToStorage(
|
|
|
452
393
|
|
|
453
394
|
return r
|
|
454
395
|
}
|
|
455
|
-
|
|
456
|
-
async function createMergedBeefOfTxids(txids: string[], storage: StorageProvider): Promise<number[]> {
|
|
457
|
-
const beef = new Beef()
|
|
458
|
-
const options: StorageGetBeefOptions = {
|
|
459
|
-
mergeToBeef: beef,
|
|
460
|
-
ignoreNewProven: true
|
|
461
|
-
}
|
|
462
|
-
for (const txid of txids) {
|
|
463
|
-
await storage.getBeefForTransaction(txid, options)
|
|
464
|
-
}
|
|
465
|
-
return beef.toBinary()
|
|
466
|
-
}
|
|
@@ -9,7 +9,8 @@ import {
|
|
|
9
9
|
LockingScript,
|
|
10
10
|
P2PKH,
|
|
11
11
|
PrivateKey,
|
|
12
|
-
Script
|
|
12
|
+
Script,
|
|
13
|
+
CachedKeyDeriver
|
|
13
14
|
} from '@bsv/sdk'
|
|
14
15
|
|
|
15
16
|
export const brc29ProtocolID: WalletProtocol = [2, '3241645161d8']
|
|
@@ -41,7 +42,7 @@ export class ScriptTemplateBRC29 implements ScriptTemplate {
|
|
|
41
42
|
getKeyDeriver(privKey: PrivateKey | HexString): KeyDeriverApi {
|
|
42
43
|
if (typeof privKey === 'string') privKey = PrivateKey.fromHex(privKey)
|
|
43
44
|
if (!this.params.keyDeriver || this.params.keyDeriver.rootKey.toHex() !== privKey.toHex())
|
|
44
|
-
return new
|
|
45
|
+
return new CachedKeyDeriver(privKey)
|
|
45
46
|
return this.params.keyDeriver
|
|
46
47
|
}
|
|
47
48
|
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { Beef, ReviewActionResult, SendWithResult } from '@bsv/sdk'
|
|
2
|
+
import { PostReqsToNetworkResult } from '../storage/methods/attemptToPostReqsToNetwork'
|
|
3
|
+
import { StorageGetBeefOptions, WERR_INTERNAL } from '../sdk'
|
|
4
|
+
import { StorageProvider } from '../index.client'
|
|
5
|
+
|
|
6
|
+
export const aggregateActionResults = async (
|
|
7
|
+
storage: StorageProvider,
|
|
8
|
+
sendWithResultReqs: SendWithResult[],
|
|
9
|
+
postToNetworkResult: PostReqsToNetworkResult
|
|
10
|
+
): Promise<{
|
|
11
|
+
swr: SendWithResult[]
|
|
12
|
+
rar: ReviewActionResult[]
|
|
13
|
+
}> => {
|
|
14
|
+
const swr: SendWithResult[] = []
|
|
15
|
+
const rar: ReviewActionResult[] = []
|
|
16
|
+
|
|
17
|
+
for (const ar of sendWithResultReqs) {
|
|
18
|
+
const txid = ar.txid
|
|
19
|
+
|
|
20
|
+
const d = postToNetworkResult.details.find(d => d.txid === txid)
|
|
21
|
+
if (!d) throw new WERR_INTERNAL(`missing details for ${txid}`)
|
|
22
|
+
|
|
23
|
+
const arNdr: ReviewActionResult = { txid: d.txid, status: 'success', competingTxs: d.competingTxs }
|
|
24
|
+
switch (d.status) {
|
|
25
|
+
case 'success':
|
|
26
|
+
// processing network has accepted this transaction
|
|
27
|
+
ar.status = 'unproven'
|
|
28
|
+
break
|
|
29
|
+
case 'doubleSpend':
|
|
30
|
+
// confirmed double spend.
|
|
31
|
+
ar.status = 'failed'
|
|
32
|
+
arNdr.status = 'doubleSpend'
|
|
33
|
+
if (d.competingTxs) arNdr.competingBeef = await createMergedBeefOfTxids(d.competingTxs, storage)
|
|
34
|
+
break
|
|
35
|
+
case 'serviceError':
|
|
36
|
+
// services might improve
|
|
37
|
+
ar.status = 'sending'
|
|
38
|
+
arNdr.status = 'serviceError'
|
|
39
|
+
break
|
|
40
|
+
case 'invalidTx':
|
|
41
|
+
// nothing will fix this transaction
|
|
42
|
+
ar.status = 'failed'
|
|
43
|
+
arNdr.status = 'invalidTx'
|
|
44
|
+
break
|
|
45
|
+
case 'unknown':
|
|
46
|
+
case 'invalid':
|
|
47
|
+
default:
|
|
48
|
+
throw new WERR_INTERNAL(`processAction with notDelayed status ${d.status} should not occur.`)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
swr.push({ txid, status: ar.status })
|
|
52
|
+
rar.push(arNdr)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
return { swr, rar }
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async function createMergedBeefOfTxids(txids: string[], storage: StorageProvider): Promise<number[]> {
|
|
59
|
+
const beef = new Beef()
|
|
60
|
+
const options: StorageGetBeefOptions = {
|
|
61
|
+
mergeToBeef: beef,
|
|
62
|
+
ignoreNewProven: true
|
|
63
|
+
}
|
|
64
|
+
for (const txid of txids) {
|
|
65
|
+
await storage.getBeefForTransaction(txid, options)
|
|
66
|
+
}
|
|
67
|
+
return beef.toBinary()
|
|
68
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
2
|
import {
|
|
3
3
|
Beef,
|
|
4
|
+
CachedKeyDeriver,
|
|
4
5
|
CreateActionArgs,
|
|
5
6
|
InternalizeActionArgs,
|
|
6
7
|
KeyDeriver,
|
|
@@ -426,7 +427,7 @@ export function createWalletPaymentOutput(args: {
|
|
|
426
427
|
const t = new ScriptTemplateBRC29({
|
|
427
428
|
derivationPrefix: randomBytesBase64(8),
|
|
428
429
|
derivationSuffix: randomBytesBase64(8),
|
|
429
|
-
keyDeriver: new
|
|
430
|
+
keyDeriver: new CachedKeyDeriver(PrivateKey.fromString(args.fromRootKeyHex))
|
|
430
431
|
})
|
|
431
432
|
|
|
432
433
|
const lockingScript = t.lock(args.fromRootKeyHex, args.toIdentityKey)
|