@bsv/wallet-toolbox 2.10.3 → 2.11.0

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.
Files changed (159) hide show
  1. package/CHANGELOG.md +68 -0
  2. package/LICENSES/Open-BSV-License-4-wallet-pre-2026.txt +28 -0
  3. package/README.md +50 -1
  4. package/THIRD_PARTY_NOTICES.md +35 -0
  5. package/docs/README.md +2 -3
  6. package/docs/managed-change-liquidity.md +7 -0
  7. package/docs/no-send-expiry.md +167 -0
  8. package/docs/prepared-beef.md +197 -0
  9. package/docs/setup.md +11 -0
  10. package/docs/storage.md +11 -0
  11. package/out/src/Setup.d.ts +3 -0
  12. package/out/src/Setup.d.ts.map +1 -1
  13. package/out/src/Setup.js +1 -0
  14. package/out/src/Setup.js.map +1 -1
  15. package/out/src/Wallet.d.ts.map +1 -1
  16. package/out/src/Wallet.js +11 -1
  17. package/out/src/Wallet.js.map +1 -1
  18. package/out/src/WalletPermissionsManager.d.ts +30 -6
  19. package/out/src/WalletPermissionsManager.d.ts.map +1 -1
  20. package/out/src/WalletPermissionsManager.js +84 -9
  21. package/out/src/WalletPermissionsManager.js.map +1 -1
  22. package/out/src/mockchain/MockServices.d.ts +2 -0
  23. package/out/src/mockchain/MockServices.d.ts.map +1 -1
  24. package/out/src/mockchain/MockServices.js +20 -0
  25. package/out/src/mockchain/MockServices.js.map +1 -1
  26. package/out/src/monitor/Monitor.d.ts +1 -0
  27. package/out/src/monitor/Monitor.d.ts.map +1 -1
  28. package/out/src/monitor/Monitor.js +19 -3
  29. package/out/src/monitor/Monitor.js.map +1 -1
  30. package/out/src/monitor/tasks/TaskNoSendExpiry.d.ts +19 -0
  31. package/out/src/monitor/tasks/TaskNoSendExpiry.d.ts.map +1 -0
  32. package/out/src/monitor/tasks/TaskNoSendExpiry.js +47 -0
  33. package/out/src/monitor/tasks/TaskNoSendExpiry.js.map +1 -0
  34. package/out/src/monitor/tasks/index.all.d.ts +1 -0
  35. package/out/src/monitor/tasks/index.all.d.ts.map +1 -1
  36. package/out/src/monitor/tasks/index.all.js +1 -0
  37. package/out/src/monitor/tasks/index.all.js.map +1 -1
  38. package/out/src/sdk/ActionBatch.interfaces.d.ts +4 -0
  39. package/out/src/sdk/ActionBatch.interfaces.d.ts.map +1 -1
  40. package/out/src/sdk/WalletStorage.interfaces.d.ts +35 -0
  41. package/out/src/sdk/WalletStorage.interfaces.d.ts.map +1 -1
  42. package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageKnex.d.ts +0 -1
  43. package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageKnex.d.ts.map +1 -1
  44. package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageKnex.js +23 -12
  45. package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageKnex.js.map +1 -1
  46. package/out/src/signer/methods/createNoSendExpiryAction.d.ts +7 -0
  47. package/out/src/signer/methods/createNoSendExpiryAction.d.ts.map +1 -0
  48. package/out/src/signer/methods/createNoSendExpiryAction.js +249 -0
  49. package/out/src/signer/methods/createNoSendExpiryAction.js.map +1 -0
  50. package/out/src/signer/methods/signAction.d.ts.map +1 -1
  51. package/out/src/signer/methods/signAction.js +9 -0
  52. package/out/src/signer/methods/signAction.js.map +1 -1
  53. package/out/src/storage/StorageIdb.d.ts +3 -0
  54. package/out/src/storage/StorageIdb.d.ts.map +1 -1
  55. package/out/src/storage/StorageIdb.js +37 -1
  56. package/out/src/storage/StorageIdb.js.map +1 -1
  57. package/out/src/storage/StorageKnex.d.ts +48 -3
  58. package/out/src/storage/StorageKnex.d.ts.map +1 -1
  59. package/out/src/storage/StorageKnex.js +234 -14
  60. package/out/src/storage/StorageKnex.js.map +1 -1
  61. package/out/src/storage/StorageProvider.d.ts +6 -1
  62. package/out/src/storage/StorageProvider.d.ts.map +1 -1
  63. package/out/src/storage/StorageProvider.js +147 -5
  64. package/out/src/storage/StorageProvider.js.map +1 -1
  65. package/out/src/storage/StorageReaderWriter.d.ts +2 -0
  66. package/out/src/storage/StorageReaderWriter.d.ts.map +1 -1
  67. package/out/src/storage/StorageReaderWriter.js +4 -0
  68. package/out/src/storage/StorageReaderWriter.js.map +1 -1
  69. package/out/src/storage/WalletStorageManager.d.ts +11 -0
  70. package/out/src/storage/WalletStorageManager.d.ts.map +1 -1
  71. package/out/src/storage/WalletStorageManager.js +77 -12
  72. package/out/src/storage/WalletStorageManager.js.map +1 -1
  73. package/out/src/storage/idbHelpers.d.ts.map +1 -1
  74. package/out/src/storage/idbHelpers.js +14 -2
  75. package/out/src/storage/idbHelpers.js.map +1 -1
  76. package/out/src/storage/index.all.d.ts +2 -0
  77. package/out/src/storage/index.all.d.ts.map +1 -1
  78. package/out/src/storage/index.all.js +2 -0
  79. package/out/src/storage/index.all.js.map +1 -1
  80. package/out/src/storage/methods/createAction.d.ts +57 -1
  81. package/out/src/storage/methods/createAction.d.ts.map +1 -1
  82. package/out/src/storage/methods/createAction.js +195 -49
  83. package/out/src/storage/methods/createAction.js.map +1 -1
  84. package/out/src/storage/methods/noSendExpiry.d.ts +11 -0
  85. package/out/src/storage/methods/noSendExpiry.d.ts.map +1 -0
  86. package/out/src/storage/methods/noSendExpiry.js +357 -0
  87. package/out/src/storage/methods/noSendExpiry.js.map +1 -0
  88. package/out/src/storage/methods/noSendExpiryLifecycle.d.ts +14 -0
  89. package/out/src/storage/methods/noSendExpiryLifecycle.d.ts.map +1 -0
  90. package/out/src/storage/methods/noSendExpiryLifecycle.js +691 -0
  91. package/out/src/storage/methods/noSendExpiryLifecycle.js.map +1 -0
  92. package/out/src/storage/methods/preparedBeef.d.ts +104 -0
  93. package/out/src/storage/methods/preparedBeef.d.ts.map +1 -0
  94. package/out/src/storage/methods/preparedBeef.js +525 -0
  95. package/out/src/storage/methods/preparedBeef.js.map +1 -0
  96. package/out/src/storage/methods/processAction.d.ts.map +1 -1
  97. package/out/src/storage/methods/processAction.js +109 -28
  98. package/out/src/storage/methods/processAction.js.map +1 -1
  99. package/out/src/storage/methods/purgeData.d.ts.map +1 -1
  100. package/out/src/storage/methods/purgeData.js +9 -0
  101. package/out/src/storage/methods/purgeData.js.map +1 -1
  102. package/out/src/storage/methods/validateSyncProof.d.ts +24 -0
  103. package/out/src/storage/methods/validateSyncProof.d.ts.map +1 -0
  104. package/out/src/storage/methods/validateSyncProof.js +116 -0
  105. package/out/src/storage/methods/validateSyncProof.js.map +1 -0
  106. package/out/src/storage/remoting/StorageClientBase.d.ts +4 -1
  107. package/out/src/storage/remoting/StorageClientBase.d.ts.map +1 -1
  108. package/out/src/storage/remoting/StorageClientBase.js +9 -0
  109. package/out/src/storage/remoting/StorageClientBase.js.map +1 -1
  110. package/out/src/storage/remoting/StorageServer.d.ts.map +1 -1
  111. package/out/src/storage/remoting/StorageServer.js +16 -3
  112. package/out/src/storage/remoting/StorageServer.js.map +1 -1
  113. package/out/src/storage/schema/KnexMigrations.d.ts +2 -0
  114. package/out/src/storage/schema/KnexMigrations.d.ts.map +1 -1
  115. package/out/src/storage/schema/KnexMigrations.js +66 -1
  116. package/out/src/storage/schema/KnexMigrations.js.map +1 -1
  117. package/out/src/storage/schema/StorageIdbSchema.d.ts +2 -0
  118. package/out/src/storage/schema/StorageIdbSchema.d.ts.map +1 -1
  119. package/out/src/storage/schema/entities/EntityOutput.d.ts.map +1 -1
  120. package/out/src/storage/schema/entities/EntityOutput.js +13 -0
  121. package/out/src/storage/schema/entities/EntityOutput.js.map +1 -1
  122. package/out/src/storage/schema/entities/EntityProvenTx.d.ts +2 -0
  123. package/out/src/storage/schema/entities/EntityProvenTx.d.ts.map +1 -1
  124. package/out/src/storage/schema/entities/EntityProvenTx.js +33 -3
  125. package/out/src/storage/schema/entities/EntityProvenTx.js.map +1 -1
  126. package/out/src/storage/schema/entities/EntityTransaction.d.ts +26 -0
  127. package/out/src/storage/schema/entities/EntityTransaction.d.ts.map +1 -1
  128. package/out/src/storage/schema/entities/EntityTransaction.js +221 -21
  129. package/out/src/storage/schema/entities/EntityTransaction.js.map +1 -1
  130. package/out/src/storage/schema/tables/TablePreparedBeef.interfaces.d.ts +23 -0
  131. package/out/src/storage/schema/tables/TablePreparedBeef.interfaces.d.ts.map +1 -0
  132. package/out/src/storage/schema/tables/TablePreparedBeef.interfaces.js +3 -0
  133. package/out/src/storage/schema/tables/TablePreparedBeef.interfaces.js.map +1 -0
  134. package/out/src/storage/schema/tables/TableTransaction.d.ts +16 -0
  135. package/out/src/storage/schema/tables/TableTransaction.d.ts.map +1 -1
  136. package/out/src/storage/schema/tables/TableTransaction.js +14 -1
  137. package/out/src/storage/schema/tables/TableTransaction.js.map +1 -1
  138. package/out/src/utility/Argon2idBackend.d.ts +36 -0
  139. package/out/src/utility/Argon2idBackend.d.ts.map +1 -0
  140. package/out/src/utility/Argon2idBackend.js +60 -0
  141. package/out/src/utility/Argon2idBackend.js.map +1 -0
  142. package/out/src/utility/brc177NoSendExpiry.d.ts +34 -0
  143. package/out/src/utility/brc177NoSendExpiry.d.ts.map +1 -0
  144. package/out/src/utility/brc177NoSendExpiry.js +81 -0
  145. package/out/src/utility/brc177NoSendExpiry.js.map +1 -0
  146. package/out/src/utility/hashWasm.d.ts +2 -1
  147. package/out/src/utility/hashWasm.d.ts.map +1 -1
  148. package/out/src/utility/hashWasm.js +83 -1
  149. package/out/src/utility/hashWasm.js.map +1 -1
  150. package/out/src/utility/index.all.d.ts +2 -0
  151. package/out/src/utility/index.all.d.ts.map +1 -1
  152. package/out/src/utility/index.all.js +2 -0
  153. package/out/src/utility/index.all.js.map +1 -1
  154. package/out/src/utility/index.client.d.ts +2 -0
  155. package/out/src/utility/index.client.d.ts.map +1 -1
  156. package/out/src/utility/index.client.js +2 -0
  157. package/out/src/utility/index.client.js.map +1 -1
  158. package/package.json +10 -7
  159. package/docs/open-rpc/index.html +0 -46
@@ -3,6 +3,39 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.WalletPermissionsManager = void 0;
4
4
  const sdk_1 = require("@bsv/sdk");
5
5
  const brc114ActionTimeLabels_1 = require("./utility/brc114ActionTimeLabels");
6
+ const brc177NoSendExpiry_1 = require("./utility/brc177NoSendExpiry");
7
+ function brc177PreflightSatoshis(args) {
8
+ const outputs = args.outputs ?? [];
9
+ let total = 0;
10
+ for (const output of outputs) {
11
+ if (typeof output.satoshis !== 'number' || !Number.isSafeInteger(output.satoshis) || output.satoshis < 0) {
12
+ throw new Error('BRC-177 outputs must contain valid satoshi amounts');
13
+ }
14
+ total += output.satoshis;
15
+ if (!Number.isSafeInteger(total))
16
+ throw new Error('BRC-177 output amount exceeds the safely supported range');
17
+ }
18
+ // Even an action funded entirely by caller-supplied inputs incurs a wallet
19
+ // prefunding fee. Require a spending grant before that fee can be broadcast.
20
+ return Math.max(1, total);
21
+ }
22
+ function validateBrc177CreateActionShape(args) {
23
+ const request = args;
24
+ if (!Array.isArray(request.outputs) || request.outputs.length === 0) {
25
+ throw new Error('BRC-177 protected actions require at least one output');
26
+ }
27
+ if (request.options?.noSend !== true)
28
+ throw new Error('BRC-177 protected actions require noSend');
29
+ if ((request.options.sendWith?.length ?? 0) > 0) {
30
+ throw new Error('BRC-177 protected actions cannot use sendWith');
31
+ }
32
+ if ((request.options.noSendChange?.length ?? 0) > 0) {
33
+ throw new Error('BRC-177 protected actions cannot supply noSendChange');
34
+ }
35
+ if (request.options.returnTXIDOnly === true) {
36
+ throw new Error('BRC-177 protected actions cannot use returnTXIDOnly');
37
+ }
38
+ }
6
39
  // Security invariant: only the configured admin originator bypasses permission
7
40
  // prompts. Admin-reserved protocols, baskets, and labels are rejected for all
8
41
  // other originators; counterparty bypasses require an explicit configuration
@@ -162,7 +195,41 @@ class WalletPermissionsManager {
162
195
  seekGroupedPermission: true,
163
196
  differentiatePrivilegedOperations: true,
164
197
  whitelistedCounterparties: {},
165
- ...config // override with user-specified config
198
+ ...config,
199
+ permissionModules: {
200
+ ...config.permissionModules,
201
+ // BRC-177 is a built-in reserved BRC-111 module in every Toolbox wallet.
202
+ nosend: {
203
+ onRequest: async (req) => {
204
+ const labels = req.args.labels;
205
+ (0, brc177NoSendExpiry_1.parseBrc177NoSendExpiryLabels)(labels);
206
+ if (req.method !== 'createAction' && req.method !== 'listActions') {
207
+ throw new Error('BRC-177 noSend expiry labels are only valid for createAction and listActions');
208
+ }
209
+ if (req.method === 'createAction')
210
+ validateBrc177CreateActionShape(req.args);
211
+ // Prefunding has a real miner fee, so authorize use of this
212
+ // module before the underlying wallet can broadcast it. This is
213
+ // deliberately separate from the later amount-specific spend
214
+ // authorization for the protected transaction.
215
+ await this.ensureLabelAccess({
216
+ originator: req.originator,
217
+ label: 'BRC-177 noSend expiry',
218
+ reason: req.method,
219
+ usageType: req.method === 'createAction' ? 'apply' : 'list'
220
+ });
221
+ if (req.method === 'createAction') {
222
+ await this.ensureSpendingAuthorization({
223
+ originator: req.originator,
224
+ satoshis: brc177PreflightSatoshis(req.args),
225
+ reason: 'BRC-177 protected action prefunding'
226
+ });
227
+ }
228
+ return { args: req.args };
229
+ },
230
+ onResponse: async (res) => res
231
+ }
232
+ }
166
233
  };
167
234
  }
168
235
  /* ---------------------------------------------------------------------
@@ -189,12 +256,19 @@ class WalletPermissionsManager {
189
256
  if (module == null) {
190
257
  throw new Error(`Unsupported P-module scheme: p ${schemeID}`);
191
258
  }
259
+ const request = { method, args, originator };
260
+ if (module.handleRequest != null) {
261
+ let nextCalled = false;
262
+ return (await module.handleRequest(request, async (transformedArgs) => {
263
+ if (nextCalled) {
264
+ throw new Error(`P-module p ${schemeID} called its underlying wallet operation more than once`);
265
+ }
266
+ nextCalled = true;
267
+ return await underlyingCall(transformedArgs, originator);
268
+ }));
269
+ }
192
270
  // Transform request with module
193
- const transformedReq = await module.onRequest({
194
- method,
195
- args,
196
- originator
197
- });
271
+ const transformedReq = await module.onRequest(request);
198
272
  // Call underlying method with transformed request
199
273
  const results = await underlyingCall(transformedReq.args, originator);
200
274
  // Transform response with module
@@ -871,7 +945,7 @@ class WalletPermissionsManager {
871
945
  * Ensures the originator has spending authorization (DSAP) for a certain satoshi amount.
872
946
  * If the existing token limit is insufficient, attempts to renew. If no token, attempts to create one.
873
947
  */
874
- async ensureSpendingAuthorization({ originator, satoshis, lineItems, reason, seekPermission = true }) {
948
+ async ensureSpendingAuthorization({ originator, satoshis, lineItems, reason, seekPermission = true, allowRecentGrant = true }) {
875
949
  const { normalized: normalizedOriginator, lookupValues } = this.prepareOriginator(originator);
876
950
  originator = normalizedOriginator;
877
951
  if (this.isAdminOriginator(originator))
@@ -884,7 +958,7 @@ class WalletPermissionsManager {
884
958
  // Spending keys are amount-scoped. The recent-grant window this adds sits
885
959
  // inside the pre-existing permissionCache window grantPermission already
886
960
  // wrote for spending, so accounting exposure is unchanged.
887
- if (await this.hasRecentOrPendingGrant(cacheKey)) {
961
+ if (allowRecentGrant && (await this.hasRecentOrPendingGrant(cacheKey))) {
888
962
  return true;
889
963
  }
890
964
  const token = await this.findSpendingToken(originator, lookupValues);
@@ -2980,7 +3054,8 @@ class WalletPermissionsManager {
2980
3054
  originator: originator,
2981
3055
  satoshis: netSpent,
2982
3056
  lineItems,
2983
- reason: originalDescription
3057
+ reason: originalDescription,
3058
+ allowRecentGrant: (0, brc177NoSendExpiry_1.parseBrc177NoSendExpiryLabels)(args.labels) == null
2984
3059
  });
2985
3060
  }
2986
3061
  catch (err) {