@bsv/wallet-toolbox 1.6.39 → 1.6.41
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 +4 -0
- package/docs/client.md +67 -29
- package/docs/services.md +1 -1
- package/docs/storage.md +34 -8
- package/docs/wallet.md +67 -29
- package/mobile/out/src/WalletPermissionsManager.d.ts +29 -0
- package/mobile/out/src/WalletPermissionsManager.d.ts.map +1 -1
- package/mobile/out/src/WalletPermissionsManager.js +581 -371
- package/mobile/out/src/WalletPermissionsManager.js.map +1 -1
- package/mobile/out/src/sdk/WalletError.d.ts.map +1 -1
- package/mobile/out/src/sdk/WalletError.js +3 -1
- package/mobile/out/src/sdk/WalletError.js.map +1 -1
- package/mobile/out/src/storage/WalletStorageManager.d.ts.map +1 -1
- package/mobile/out/src/storage/WalletStorageManager.js +3 -1
- package/mobile/out/src/storage/WalletStorageManager.js.map +1 -1
- package/mobile/out/src/storage/methods/createAction.d.ts.map +1 -1
- package/mobile/out/src/storage/methods/createAction.js +1 -1
- package/mobile/out/src/storage/methods/createAction.js.map +1 -1
- package/mobile/package-lock.json +6 -6
- package/mobile/package.json +2 -2
- package/out/src/WalletPermissionsManager.d.ts +29 -0
- package/out/src/WalletPermissionsManager.d.ts.map +1 -1
- package/out/src/WalletPermissionsManager.js +581 -371
- package/out/src/WalletPermissionsManager.js.map +1 -1
- package/out/src/__tests/WalletPermissionsManager.tokens.test.js +1 -80
- package/out/src/__tests/WalletPermissionsManager.tokens.test.js.map +1 -1
- package/out/src/sdk/WalletError.d.ts.map +1 -1
- package/out/src/sdk/WalletError.js +3 -1
- package/out/src/sdk/WalletError.js.map +1 -1
- package/out/src/storage/WalletStorageManager.d.ts.map +1 -1
- package/out/src/storage/WalletStorageManager.js +3 -1
- package/out/src/storage/WalletStorageManager.js.map +1 -1
- package/out/src/storage/methods/createAction.d.ts.map +1 -1
- package/out/src/storage/methods/createAction.js +1 -1
- package/out/src/storage/methods/createAction.js.map +1 -1
- package/out/tsconfig.all.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/WalletPermissionsManager.ts +674 -444
- package/src/__tests/WalletPermissionsManager.tokens.test.ts +1 -83
- package/src/sdk/WalletError.ts +9 -3
- package/src/storage/WalletStorageManager.ts +7 -5
- package/src/storage/methods/createAction.ts +2 -3
|
@@ -210,8 +210,7 @@ describe('WalletPermissionsManager - On-Chain Token Creation, Renewal & Revocati
|
|
|
210
210
|
'originator app.example',
|
|
211
211
|
'privileged false',
|
|
212
212
|
'protocolName testProto',
|
|
213
|
-
'protocolSecurityLevel 1'
|
|
214
|
-
'counterparty self'
|
|
213
|
+
'protocolSecurityLevel 1'
|
|
215
214
|
])
|
|
216
215
|
)
|
|
217
216
|
|
|
@@ -500,86 +499,5 @@ describe('WalletPermissionsManager - On-Chain Token Creation, Renewal & Revocati
|
|
|
500
499
|
// The content can be a mock, we just check it’s not empty
|
|
501
500
|
expect(signArgs.spends[0].unlockingScript).toBeDefined()
|
|
502
501
|
})
|
|
503
|
-
|
|
504
|
-
it('should remove the old token from listing after revocation', async () => {
|
|
505
|
-
jest.spyOn(MockedBSV_SDK.Transaction, 'fromBEEF').mockImplementation(() => {
|
|
506
|
-
const mockTx = new MockTransaction()
|
|
507
|
-
// Add outputs with lockingScript
|
|
508
|
-
mockTx.outputs = [
|
|
509
|
-
{
|
|
510
|
-
lockingScript: {
|
|
511
|
-
// Ensure this matches what PushDrop.decode expects to work with
|
|
512
|
-
toHex: () => 'some script'
|
|
513
|
-
}
|
|
514
|
-
}
|
|
515
|
-
]
|
|
516
|
-
// Add the toBEEF method
|
|
517
|
-
mockTx.toBEEF = () => []
|
|
518
|
-
return mockTx
|
|
519
|
-
})
|
|
520
|
-
// Add this to your test alongside the Transaction.fromBEEF mock
|
|
521
|
-
jest.spyOn(MockedBSV_SDK.PushDrop, 'decode').mockReturnValue({
|
|
522
|
-
fields: [
|
|
523
|
-
// Values that will decrypt to the expected values for domain, expiry, and basket
|
|
524
|
-
Utils.toArray('encoded-domain'),
|
|
525
|
-
Utils.toArray('encoded-expiry'),
|
|
526
|
-
Utils.toArray('encoded-basket')
|
|
527
|
-
]
|
|
528
|
-
})
|
|
529
|
-
|
|
530
|
-
// You'll also need to mock the decryptPermissionTokenField method
|
|
531
|
-
// to handle these encoded values
|
|
532
|
-
jest.spyOn(manager as any, 'decryptPermissionTokenField').mockImplementation(field => {
|
|
533
|
-
if (field === 'encoded-domain') return new Uint8Array([...Buffer.from('example.com')])
|
|
534
|
-
if (field === 'encoded-expiry') return new Uint8Array([...Buffer.from('1735689600')])
|
|
535
|
-
if (field === 'encoded-basket') return new Uint8Array([...Buffer.from('protocol-permission')])
|
|
536
|
-
return new Uint8Array()
|
|
537
|
-
})
|
|
538
|
-
|
|
539
|
-
// 1) Setup the underlying wallet to initially return the old token in listOutputs
|
|
540
|
-
const oldToken: PermissionToken = {
|
|
541
|
-
tx: [],
|
|
542
|
-
txid: 'aaaa1111',
|
|
543
|
-
outputIndex: 0,
|
|
544
|
-
outputScript: 'some script',
|
|
545
|
-
satoshis: 1,
|
|
546
|
-
originator: 'example.com',
|
|
547
|
-
expiry: 999999,
|
|
548
|
-
basketName: 'myBasket'
|
|
549
|
-
}
|
|
550
|
-
// We mock listOutputs so that it returns the old token before revocation
|
|
551
|
-
underlying.listOutputs.mockResolvedValueOnce({
|
|
552
|
-
totalOutputs: 1,
|
|
553
|
-
outputs: [
|
|
554
|
-
{
|
|
555
|
-
outpoint: 'aaaa1111.0',
|
|
556
|
-
lockingScript: 'some script',
|
|
557
|
-
satoshis: 1,
|
|
558
|
-
tags: ['originator example.com', 'basket myBasket']
|
|
559
|
-
}
|
|
560
|
-
]
|
|
561
|
-
})
|
|
562
|
-
|
|
563
|
-
// Confirm the manager sees it in listBasketAccess
|
|
564
|
-
const tokensBefore = await manager.listBasketAccess({
|
|
565
|
-
originator: 'example.com'
|
|
566
|
-
})
|
|
567
|
-
expect(tokensBefore).toHaveLength(1)
|
|
568
|
-
expect(tokensBefore[0].txid).toBe('aaaa1111')
|
|
569
|
-
|
|
570
|
-
// 2) Revoke the token
|
|
571
|
-
await manager.revokePermission(oldToken)
|
|
572
|
-
|
|
573
|
-
// 3) After revocation, mock the underlying wallet to show zero outputs
|
|
574
|
-
underlying.listOutputs.mockResolvedValue({
|
|
575
|
-
totalOutputs: 0,
|
|
576
|
-
outputs: []
|
|
577
|
-
})
|
|
578
|
-
|
|
579
|
-
const tokensAfter = await manager.listBasketAccess({
|
|
580
|
-
originator: 'example.com'
|
|
581
|
-
})
|
|
582
|
-
expect(tokensAfter).toHaveLength(0)
|
|
583
|
-
})
|
|
584
502
|
})
|
|
585
503
|
})
|
package/src/sdk/WalletError.ts
CHANGED
|
@@ -150,9 +150,15 @@ export class WalletError extends Error implements WalletErrorObject {
|
|
|
150
150
|
const t = typeof error
|
|
151
151
|
const ctor = t === 'object' && error !== null ? (error as any).constructor?.name : undefined
|
|
152
152
|
const name = t === 'object' && error !== null && typeof (error as any).name === 'string' ? (error as any).name : ''
|
|
153
|
-
const message =
|
|
154
|
-
|
|
155
|
-
|
|
153
|
+
const message =
|
|
154
|
+
t === 'object' && error !== null && typeof (error as any).message === 'string' ? (error as any).message : ''
|
|
155
|
+
const toJson =
|
|
156
|
+
t === 'object' && error !== null && typeof (error as any).toJson === 'function'
|
|
157
|
+
? (error as any).toJson
|
|
158
|
+
: undefined
|
|
159
|
+
console.log(
|
|
160
|
+
`WalletError.unknownToJson: error type=${t} ctor=${ctor} name=${name} message=${message} hasToJson=${toJson ? 'yes' : 'no'}`
|
|
161
|
+
)
|
|
156
162
|
if (ctor && ctor.startsWith('WERR_') && toJson !== undefined) {
|
|
157
163
|
json = (error as WalletError).toJson()
|
|
158
164
|
} else if (name && message) {
|
|
@@ -567,10 +567,10 @@ export class WalletStorageManager implements sdk.WalletStorage {
|
|
|
567
567
|
/**
|
|
568
568
|
* Extends the Beef `verify` function to handle BUMPs that have become invalid due to a chain reorg,
|
|
569
569
|
* and originated from proven_txs records tracked by this storage.
|
|
570
|
-
*
|
|
570
|
+
*
|
|
571
571
|
* This method is optimized for making sure outgoing beefs are valid before sharing them externally.
|
|
572
572
|
* In particular, it only "repairs" proofs previously tracked by this storage.
|
|
573
|
-
*
|
|
573
|
+
*
|
|
574
574
|
* Any merkle root that fails `isValidRootForHeight` triggers a reprove attempt for that block header.
|
|
575
575
|
* This results in proven_txs with invalid proofs being updated with new valid proofs where possible.
|
|
576
576
|
*
|
|
@@ -599,7 +599,9 @@ export class WalletStorageManager implements sdk.WalletStorage {
|
|
|
599
599
|
if (!isValid) {
|
|
600
600
|
// root is not currently the valid hash for this height according to the chaintracker.
|
|
601
601
|
// What beef txids depended on this root:
|
|
602
|
-
const txids = beef.txs
|
|
602
|
+
const txids = beef.txs
|
|
603
|
+
.filter(tx => tx.bumpIndex !== undefined && beef.bumps[tx.bumpIndex].blockHeight === height)
|
|
604
|
+
.map(tx => tx.txid)
|
|
603
605
|
const reproveResults = await this.reproveHeader(root)
|
|
604
606
|
r.invalidRoots[height] = { root, reproveResults }
|
|
605
607
|
}
|
|
@@ -938,5 +940,5 @@ export class WalletStorageManager implements sdk.WalletStorage {
|
|
|
938
940
|
export interface VerifyAndRepairBeefResult {
|
|
939
941
|
isStructurallyValid: boolean
|
|
940
942
|
originalRoots: Record<number, string>
|
|
941
|
-
invalidRoots: Record<number, { root: string
|
|
942
|
-
}
|
|
943
|
+
invalidRoots: Record<number, { root: string; reproveResults: sdk.ReproveHeaderResult }>
|
|
944
|
+
}
|
|
@@ -10,8 +10,7 @@ import {
|
|
|
10
10
|
Random,
|
|
11
11
|
ReviewActionResult,
|
|
12
12
|
Script,
|
|
13
|
-
Utils
|
|
14
|
-
WERR_REVIEW_ACTIONS
|
|
13
|
+
Utils
|
|
15
14
|
} from '@bsv/sdk'
|
|
16
15
|
import {
|
|
17
16
|
generateChangeSdk,
|
|
@@ -35,7 +34,7 @@ import {
|
|
|
35
34
|
ValidCreateActionOutput,
|
|
36
35
|
validateSatoshis
|
|
37
36
|
} from '../../sdk/validationHelpers'
|
|
38
|
-
import { WERR_INTERNAL, WERR_INVALID_PARAMETER } from '../../sdk/WERR_errors'
|
|
37
|
+
import { WERR_INTERNAL, WERR_INVALID_PARAMETER, WERR_REVIEW_ACTIONS } from '../../sdk/WERR_errors'
|
|
39
38
|
import {
|
|
40
39
|
randomBytesBase64,
|
|
41
40
|
sha256Hash,
|