@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.
- package/CHANGELOG.md +68 -0
- package/LICENSES/Open-BSV-License-4-wallet-pre-2026.txt +28 -0
- package/README.md +50 -1
- package/THIRD_PARTY_NOTICES.md +35 -0
- package/docs/README.md +2 -3
- package/docs/managed-change-liquidity.md +7 -0
- package/docs/no-send-expiry.md +167 -0
- package/docs/prepared-beef.md +197 -0
- package/docs/setup.md +11 -0
- package/docs/storage.md +11 -0
- package/out/src/Setup.d.ts +3 -0
- package/out/src/Setup.d.ts.map +1 -1
- package/out/src/Setup.js +1 -0
- package/out/src/Setup.js.map +1 -1
- package/out/src/Wallet.d.ts.map +1 -1
- package/out/src/Wallet.js +11 -1
- package/out/src/Wallet.js.map +1 -1
- package/out/src/WalletPermissionsManager.d.ts +30 -6
- package/out/src/WalletPermissionsManager.d.ts.map +1 -1
- package/out/src/WalletPermissionsManager.js +84 -9
- package/out/src/WalletPermissionsManager.js.map +1 -1
- package/out/src/mockchain/MockServices.d.ts +2 -0
- package/out/src/mockchain/MockServices.d.ts.map +1 -1
- package/out/src/mockchain/MockServices.js +20 -0
- package/out/src/mockchain/MockServices.js.map +1 -1
- package/out/src/monitor/Monitor.d.ts +1 -0
- package/out/src/monitor/Monitor.d.ts.map +1 -1
- package/out/src/monitor/Monitor.js +19 -3
- package/out/src/monitor/Monitor.js.map +1 -1
- package/out/src/monitor/tasks/TaskNoSendExpiry.d.ts +19 -0
- package/out/src/monitor/tasks/TaskNoSendExpiry.d.ts.map +1 -0
- package/out/src/monitor/tasks/TaskNoSendExpiry.js +47 -0
- package/out/src/monitor/tasks/TaskNoSendExpiry.js.map +1 -0
- package/out/src/monitor/tasks/index.all.d.ts +1 -0
- package/out/src/monitor/tasks/index.all.d.ts.map +1 -1
- package/out/src/monitor/tasks/index.all.js +1 -0
- package/out/src/monitor/tasks/index.all.js.map +1 -1
- package/out/src/sdk/ActionBatch.interfaces.d.ts +4 -0
- package/out/src/sdk/ActionBatch.interfaces.d.ts.map +1 -1
- package/out/src/sdk/WalletStorage.interfaces.d.ts +35 -0
- package/out/src/sdk/WalletStorage.interfaces.d.ts.map +1 -1
- package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageKnex.d.ts +0 -1
- package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageKnex.d.ts.map +1 -1
- package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageKnex.js +23 -12
- package/out/src/services/chaintracker/chaintracks/Storage/ChaintracksStorageKnex.js.map +1 -1
- package/out/src/signer/methods/createNoSendExpiryAction.d.ts +7 -0
- package/out/src/signer/methods/createNoSendExpiryAction.d.ts.map +1 -0
- package/out/src/signer/methods/createNoSendExpiryAction.js +249 -0
- package/out/src/signer/methods/createNoSendExpiryAction.js.map +1 -0
- package/out/src/signer/methods/signAction.d.ts.map +1 -1
- package/out/src/signer/methods/signAction.js +9 -0
- package/out/src/signer/methods/signAction.js.map +1 -1
- package/out/src/storage/StorageIdb.d.ts +3 -0
- package/out/src/storage/StorageIdb.d.ts.map +1 -1
- package/out/src/storage/StorageIdb.js +37 -1
- package/out/src/storage/StorageIdb.js.map +1 -1
- package/out/src/storage/StorageKnex.d.ts +48 -3
- package/out/src/storage/StorageKnex.d.ts.map +1 -1
- package/out/src/storage/StorageKnex.js +234 -14
- package/out/src/storage/StorageKnex.js.map +1 -1
- package/out/src/storage/StorageProvider.d.ts +6 -1
- package/out/src/storage/StorageProvider.d.ts.map +1 -1
- package/out/src/storage/StorageProvider.js +147 -5
- package/out/src/storage/StorageProvider.js.map +1 -1
- package/out/src/storage/StorageReaderWriter.d.ts +2 -0
- package/out/src/storage/StorageReaderWriter.d.ts.map +1 -1
- package/out/src/storage/StorageReaderWriter.js +4 -0
- package/out/src/storage/StorageReaderWriter.js.map +1 -1
- package/out/src/storage/WalletStorageManager.d.ts +11 -0
- package/out/src/storage/WalletStorageManager.d.ts.map +1 -1
- package/out/src/storage/WalletStorageManager.js +77 -12
- package/out/src/storage/WalletStorageManager.js.map +1 -1
- package/out/src/storage/idbHelpers.d.ts.map +1 -1
- package/out/src/storage/idbHelpers.js +14 -2
- package/out/src/storage/idbHelpers.js.map +1 -1
- package/out/src/storage/index.all.d.ts +2 -0
- package/out/src/storage/index.all.d.ts.map +1 -1
- package/out/src/storage/index.all.js +2 -0
- package/out/src/storage/index.all.js.map +1 -1
- package/out/src/storage/methods/createAction.d.ts +57 -1
- package/out/src/storage/methods/createAction.d.ts.map +1 -1
- package/out/src/storage/methods/createAction.js +195 -49
- package/out/src/storage/methods/createAction.js.map +1 -1
- package/out/src/storage/methods/noSendExpiry.d.ts +11 -0
- package/out/src/storage/methods/noSendExpiry.d.ts.map +1 -0
- package/out/src/storage/methods/noSendExpiry.js +357 -0
- package/out/src/storage/methods/noSendExpiry.js.map +1 -0
- package/out/src/storage/methods/noSendExpiryLifecycle.d.ts +14 -0
- package/out/src/storage/methods/noSendExpiryLifecycle.d.ts.map +1 -0
- package/out/src/storage/methods/noSendExpiryLifecycle.js +691 -0
- package/out/src/storage/methods/noSendExpiryLifecycle.js.map +1 -0
- package/out/src/storage/methods/preparedBeef.d.ts +104 -0
- package/out/src/storage/methods/preparedBeef.d.ts.map +1 -0
- package/out/src/storage/methods/preparedBeef.js +525 -0
- package/out/src/storage/methods/preparedBeef.js.map +1 -0
- package/out/src/storage/methods/processAction.d.ts.map +1 -1
- package/out/src/storage/methods/processAction.js +109 -28
- package/out/src/storage/methods/processAction.js.map +1 -1
- package/out/src/storage/methods/purgeData.d.ts.map +1 -1
- package/out/src/storage/methods/purgeData.js +9 -0
- package/out/src/storage/methods/purgeData.js.map +1 -1
- package/out/src/storage/methods/validateSyncProof.d.ts +24 -0
- package/out/src/storage/methods/validateSyncProof.d.ts.map +1 -0
- package/out/src/storage/methods/validateSyncProof.js +116 -0
- package/out/src/storage/methods/validateSyncProof.js.map +1 -0
- package/out/src/storage/remoting/StorageClientBase.d.ts +4 -1
- package/out/src/storage/remoting/StorageClientBase.d.ts.map +1 -1
- package/out/src/storage/remoting/StorageClientBase.js +9 -0
- package/out/src/storage/remoting/StorageClientBase.js.map +1 -1
- package/out/src/storage/remoting/StorageServer.d.ts.map +1 -1
- package/out/src/storage/remoting/StorageServer.js +16 -3
- package/out/src/storage/remoting/StorageServer.js.map +1 -1
- package/out/src/storage/schema/KnexMigrations.d.ts +2 -0
- package/out/src/storage/schema/KnexMigrations.d.ts.map +1 -1
- package/out/src/storage/schema/KnexMigrations.js +66 -1
- package/out/src/storage/schema/KnexMigrations.js.map +1 -1
- package/out/src/storage/schema/StorageIdbSchema.d.ts +2 -0
- package/out/src/storage/schema/StorageIdbSchema.d.ts.map +1 -1
- package/out/src/storage/schema/entities/EntityOutput.d.ts.map +1 -1
- package/out/src/storage/schema/entities/EntityOutput.js +13 -0
- package/out/src/storage/schema/entities/EntityOutput.js.map +1 -1
- package/out/src/storage/schema/entities/EntityProvenTx.d.ts +2 -0
- package/out/src/storage/schema/entities/EntityProvenTx.d.ts.map +1 -1
- package/out/src/storage/schema/entities/EntityProvenTx.js +33 -3
- package/out/src/storage/schema/entities/EntityProvenTx.js.map +1 -1
- package/out/src/storage/schema/entities/EntityTransaction.d.ts +26 -0
- package/out/src/storage/schema/entities/EntityTransaction.d.ts.map +1 -1
- package/out/src/storage/schema/entities/EntityTransaction.js +221 -21
- package/out/src/storage/schema/entities/EntityTransaction.js.map +1 -1
- package/out/src/storage/schema/tables/TablePreparedBeef.interfaces.d.ts +23 -0
- package/out/src/storage/schema/tables/TablePreparedBeef.interfaces.d.ts.map +1 -0
- package/out/src/storage/schema/tables/TablePreparedBeef.interfaces.js +3 -0
- package/out/src/storage/schema/tables/TablePreparedBeef.interfaces.js.map +1 -0
- package/out/src/storage/schema/tables/TableTransaction.d.ts +16 -0
- package/out/src/storage/schema/tables/TableTransaction.d.ts.map +1 -1
- package/out/src/storage/schema/tables/TableTransaction.js +14 -1
- package/out/src/storage/schema/tables/TableTransaction.js.map +1 -1
- package/out/src/utility/Argon2idBackend.d.ts +36 -0
- package/out/src/utility/Argon2idBackend.d.ts.map +1 -0
- package/out/src/utility/Argon2idBackend.js +60 -0
- package/out/src/utility/Argon2idBackend.js.map +1 -0
- package/out/src/utility/brc177NoSendExpiry.d.ts +34 -0
- package/out/src/utility/brc177NoSendExpiry.d.ts.map +1 -0
- package/out/src/utility/brc177NoSendExpiry.js +81 -0
- package/out/src/utility/brc177NoSendExpiry.js.map +1 -0
- package/out/src/utility/hashWasm.d.ts +2 -1
- package/out/src/utility/hashWasm.d.ts.map +1 -1
- package/out/src/utility/hashWasm.js +83 -1
- package/out/src/utility/hashWasm.js.map +1 -1
- package/out/src/utility/index.all.d.ts +2 -0
- package/out/src/utility/index.all.d.ts.map +1 -1
- package/out/src/utility/index.all.js +2 -0
- package/out/src/utility/index.all.js.map +1 -1
- package/out/src/utility/index.client.d.ts +2 -0
- package/out/src/utility/index.client.d.ts.map +1 -1
- package/out/src/utility/index.client.js +2 -0
- package/out/src/utility/index.client.js.map +1 -1
- package/package.json +10 -7
- 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
|
|
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) {
|