@1sat/permission-module 0.0.1
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/dist/commitmentCache.d.ts +36 -0
- package/dist/commitmentCache.d.ts.map +1 -0
- package/dist/commitmentCache.js +0 -0
- package/dist/commitmentCache.js.map +1 -0
- package/dist/createOneSatPermissionModule.d.ts +38 -0
- package/dist/createOneSatPermissionModule.d.ts.map +1 -0
- package/dist/createOneSatPermissionModule.js +54 -0
- package/dist/createOneSatPermissionModule.js.map +1 -0
- package/dist/handlers.d.ts +45 -0
- package/dist/handlers.d.ts.map +1 -0
- package/dist/handlers.js +156 -0
- package/dist/handlers.js.map +1 -0
- package/dist/hashOutputs.d.ts +13 -0
- package/dist/hashOutputs.d.ts.map +1 -0
- package/dist/hashOutputs.js +51 -0
- package/dist/hashOutputs.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -0
- package/dist/placeholder.d.ts +50 -0
- package/dist/placeholder.d.ts.map +1 -0
- package/dist/placeholder.js +108 -0
- package/dist/placeholder.js.map +1 -0
- package/dist/sighashParser.d.ts +28 -0
- package/dist/sighashParser.d.ts.map +1 -0
- package/dist/sighashParser.js +85 -0
- package/dist/sighashParser.js.map +1 -0
- package/dist/types.d.ts +67 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +10 -0
- package/dist/types.js.map +1 -0
- package/package.json +43 -0
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { CapturedCommitment } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* In-memory cache of approved-transaction commitments, keyed by
|
|
4
|
+
* `(originator, reference)`. Entries expire after `ttlSeconds` and are
|
|
5
|
+
* swept periodically.
|
|
6
|
+
*
|
|
7
|
+
* Lookup also supports finding by `(originator, hashOutputs)` so a
|
|
8
|
+
* createSignature whose preimage encodes a known hashOutputs can be
|
|
9
|
+
* verified without knowing which reference produced it.
|
|
10
|
+
*/
|
|
11
|
+
export declare class CommitmentCache {
|
|
12
|
+
private readonly entries;
|
|
13
|
+
private readonly ttlMs;
|
|
14
|
+
private sweepHandle;
|
|
15
|
+
constructor(ttlSeconds: number);
|
|
16
|
+
/** Begin periodic eviction. Idempotent. */
|
|
17
|
+
start(): void;
|
|
18
|
+
stop(): void;
|
|
19
|
+
/** Store a commitment under (originator, reference). */
|
|
20
|
+
put(originator: string, commitment: CapturedCommitment): void;
|
|
21
|
+
/** Look up by (originator, reference). Returns null if expired or missing. */
|
|
22
|
+
getByReference(originator: string, reference: string): CapturedCommitment | null;
|
|
23
|
+
/**
|
|
24
|
+
* Find any non-expired commitment for `originator` whose `hashOutputs`
|
|
25
|
+
* matches. Returns null if nothing matches.
|
|
26
|
+
*/
|
|
27
|
+
findByHashOutputs(originator: string, hashOutputs: string): CapturedCommitment | null;
|
|
28
|
+
/** Drop all commitments for an originator (e.g. session ended). */
|
|
29
|
+
deleteOriginator(originator: string): void;
|
|
30
|
+
/** For tests/diagnostics. */
|
|
31
|
+
size(): number;
|
|
32
|
+
private key;
|
|
33
|
+
private isExpired;
|
|
34
|
+
private evictExpired;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=commitmentCache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"commitmentCache.d.ts","sourceRoot":"","sources":["../src/commitmentCache.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAEjD;;;;;;;;GAQG;AACH,qBAAa,eAAe;IAC3B,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAwC;IAChE,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAQ;IAC9B,OAAO,CAAC,WAAW,CAA8C;gBAErD,UAAU,EAAE,MAAM;IAI9B,2CAA2C;IAC3C,KAAK,IAAI,IAAI;IASb,IAAI,IAAI,IAAI;IAMZ,wDAAwD;IACxD,GAAG,CA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K,CAAA;QACpD,CAAC;QACD,OAAO,IAAI,CAAA;IACZ,CAAC;IAED,mEAAmE;IACnE,gBAAgB,CAAC,UAAkB;QAClC,MAAM,MAAM,GAAG,GAAG,UAAU,GAAG,CAAA;QAC/B,KAAK,MAAM,CAAC,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,EAAE,CAAC;YACjD,IAAI,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC;gBAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;QACjD,CAAC;IACF,CAAC;IAED,6BAA6B;IAC7B,IAAI;QACH,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAA;IACzB,CAAC;IAEO,GAAG,CAAC,UAAkB,EAAE,SAAiB;QAChD,OAAO,GAAG,UAAU,IAAI,SAAS,EAAE,CAAA;IACpC,CAAC;IAEO,SAAS,CAAC,KAAyB;QAC1C,OAAO,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,UAAU,GAAG,IAAI,CAAC,KAAK,CAAA;IAClD,CAAC;IAEO,YAAY;QACnB,KAAK,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACvC,IAAI,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;gBAAE,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;QAClD,CAAC;IACF,CAAC;CACD"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type CreateOneSatPermissionModuleArgs } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Mirror of the `PermissionsModule` interface from `@bsv/wallet-toolbox`.
|
|
4
|
+
* Duplicated here to keep this package free of a hard dependency on the
|
|
5
|
+
* toolbox at type-level — consumers register the returned object under
|
|
6
|
+
* `permissionModules['1sat']` in their `WalletPermissionsManager` config.
|
|
7
|
+
*/
|
|
8
|
+
export interface PermissionsModule {
|
|
9
|
+
onRequest(req: {
|
|
10
|
+
method: string;
|
|
11
|
+
args: object;
|
|
12
|
+
originator: string;
|
|
13
|
+
}): Promise<{
|
|
14
|
+
args: object;
|
|
15
|
+
}>;
|
|
16
|
+
onResponse(res: unknown, context: {
|
|
17
|
+
method: string;
|
|
18
|
+
originator: string;
|
|
19
|
+
}): Promise<unknown>;
|
|
20
|
+
}
|
|
21
|
+
/** Returned by the factory; lets callers stop the cache eviction timer. */
|
|
22
|
+
export interface OneSatPermissionModule extends PermissionsModule {
|
|
23
|
+
/** Stop the periodic cache eviction. */
|
|
24
|
+
dispose(): void;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Build a permission module that gates 1Sat-asset signing via hashOutputs
|
|
28
|
+
* commitments captured at createAction time.
|
|
29
|
+
*
|
|
30
|
+
* Register the returned object in `WalletPermissionsManager` config:
|
|
31
|
+
*
|
|
32
|
+
* const oneSat = createOneSatPermissionModule({ wallet, promptHandler });
|
|
33
|
+
* new WalletPermissionsManager(wallet, adminOriginator, {
|
|
34
|
+
* permissionModules: { '1sat': oneSat },
|
|
35
|
+
* });
|
|
36
|
+
*/
|
|
37
|
+
export declare function createOneSatPermissionModule(args: CreateOneSatPermissionModuleArgs): OneSatPermissionModule;
|
|
38
|
+
//# sourceMappingURL=createOneSatPermissionModule.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createOneSatPermissionModule.d.ts","sourceRoot":"","sources":["../src/createOneSatPermissionModule.ts"],"names":[],"mappings":"AAaA,OAAO,EACN,KAAK,gCAAgC,EAErC,MAAM,SAAS,CAAA;AAEhB;;;;;GAKG;AACH,MAAM,WAAW,iBAAiB;IACjC,SAAS,CAAC,GAAG,EAAE;QACd,MAAM,EAAE,MAAM,CAAA;QACd,IAAI,EAAE,MAAM,CAAA;QACZ,UAAU,EAAE,MAAM,CAAA;KAClB,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IAC7B,UAAU,CACT,GAAG,EAAE,OAAO,EACZ,OAAO,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,GAC7C,OAAO,CAAC,OAAO,CAAC,CAAA;CACnB;AAED,2EAA2E;AAC3E,MAAM,WAAW,sBAAuB,SAAQ,iBAAiB;IAChE,wCAAwC;IACxC,OAAO,IAAI,IAAI,CAAA;CACf;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,4BAA4B,CAC3C,IAAI,EAAE,gCAAgC,GACpC,sBAAsB,CA4DxB"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { CommitmentCache } from './commitmentCache';
|
|
2
|
+
import { handleCreateActionRequest, handleCreateActionResponse, handleCreateSignatureRequest, handleGetPublicKeyRequest, } from './handlers';
|
|
3
|
+
import { DEFAULT_COMMITMENT_TTL_SECONDS, } from './types';
|
|
4
|
+
/**
|
|
5
|
+
* Build a permission module that gates 1Sat-asset signing via hashOutputs
|
|
6
|
+
* commitments captured at createAction time.
|
|
7
|
+
*
|
|
8
|
+
* Register the returned object in `WalletPermissionsManager` config:
|
|
9
|
+
*
|
|
10
|
+
* const oneSat = createOneSatPermissionModule({ wallet, promptHandler });
|
|
11
|
+
* new WalletPermissionsManager(wallet, adminOriginator, {
|
|
12
|
+
* permissionModules: { '1sat': oneSat },
|
|
13
|
+
* });
|
|
14
|
+
*/
|
|
15
|
+
export function createOneSatPermissionModule(args) {
|
|
16
|
+
const cache = new CommitmentCache(args.commitmentTtlSeconds ?? DEFAULT_COMMITMENT_TTL_SECONDS);
|
|
17
|
+
cache.start();
|
|
18
|
+
const deps = {
|
|
19
|
+
wallet: args.wallet,
|
|
20
|
+
promptHandler: args.promptHandler,
|
|
21
|
+
cache,
|
|
22
|
+
adminOriginator: args.adminOriginator,
|
|
23
|
+
};
|
|
24
|
+
return {
|
|
25
|
+
async onRequest(req) {
|
|
26
|
+
switch (req.method) {
|
|
27
|
+
case 'createAction': {
|
|
28
|
+
const next = await handleCreateActionRequest(deps, req.args, req.originator);
|
|
29
|
+
return { args: next };
|
|
30
|
+
}
|
|
31
|
+
case 'createSignature': {
|
|
32
|
+
const next = await handleCreateSignatureRequest(deps, req.args, req.originator);
|
|
33
|
+
return { args: next };
|
|
34
|
+
}
|
|
35
|
+
case 'getPublicKey': {
|
|
36
|
+
const next = handleGetPublicKeyRequest(deps, req.args, req.originator);
|
|
37
|
+
return { args: next };
|
|
38
|
+
}
|
|
39
|
+
default:
|
|
40
|
+
return { args: req.args };
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
async onResponse(res, context) {
|
|
44
|
+
if (context.method === 'createAction') {
|
|
45
|
+
return handleCreateActionResponse(deps, res, context.originator);
|
|
46
|
+
}
|
|
47
|
+
return res;
|
|
48
|
+
},
|
|
49
|
+
dispose() {
|
|
50
|
+
cache.stop();
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=createOneSatPermissionModule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createOneSatPermissionModule.js","sourceRoot":"","sources":["../src/createOneSatPermissionModule.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EACN,yBAAyB,EACzB,0BAA0B,EAC1B,4BAA4B,EAC5B,yBAAyB,GACzB,MAAM,YAAY,CAAA;AACnB,OAAO,EAEN,8BAA8B,GAC9B,MAAM,SAAS,CAAA;AA0BhB;;;;;;;;;;GAUG;AACH,MAAM,UAAU,4BAA4B,CAC3C,IAAsC;IAEtC,MAAM,KAAK,GAAG,IAAI,eAAe,CAChC,IAAI,CAAC,oBAAoB,IAAI,8BAA8B,CAC3D,CAAA;IACD,KAAK,CAAC,KAAK,EAAE,CAAA;IAEb,MAAM,IAAI,GAAG;QACZ,MAAM,EAAE,IAAI,CAAC,MAAM;QACnB,aAAa,E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|
1
|
+
import type { CreateActionArgs, CreateActionResult, CreateSignatureArgs, GetPublicKeyArgs, WalletInterface } from '@bsv/sdk';
|
|
2
|
+
import { CommitmentCache } from './commitmentCache';
|
|
3
|
+
import type { PromptHandler } from './types';
|
|
4
|
+
interface HandlerDeps {
|
|
5
|
+
wallet: WalletInterface;
|
|
6
|
+
promptHandler: PromptHandler;
|
|
7
|
+
cache: CommitmentCache;
|
|
8
|
+
adminOriginator?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* createAction onRequest:
|
|
12
|
+
* 1. Admin originator → return args unchanged.
|
|
13
|
+
* 2. Substitute placeholder markers in outputs (AIP/Sigma).
|
|
14
|
+
* 3. Prompt user with structured intent. Reject throws.
|
|
15
|
+
*/
|
|
16
|
+
export declare function handleCreateActionRequest(deps: HandlerDeps, args: CreateActionArgs, originator: string): Promise<CreateActionArgs>;
|
|
17
|
+
/**
|
|
18
|
+
* createAction onResponse:
|
|
19
|
+
* Extract the signable transaction's hashOutputs and authorized outpoint
|
|
20
|
+
* set, store under (originator, reference).
|
|
21
|
+
*
|
|
22
|
+
* Admin-originator calls return without capturing — admin operations
|
|
23
|
+
* don't need commitment binding because subsequent createSignature calls
|
|
24
|
+
* will also auto-grant.
|
|
25
|
+
*/
|
|
26
|
+
export declare function handleCreateActionResponse(deps: HandlerDeps, res: CreateActionResult, originator: string): Promise<CreateActionResult>;
|
|
27
|
+
/**
|
|
28
|
+
* createSignature onRequest:
|
|
29
|
+
* 1. Admin → auto-grant.
|
|
30
|
+
* 2. If args.data is a BIP-143 preimage and its hashOutputs +
|
|
31
|
+
* outpoint match a captured commitment → auto-grant.
|
|
32
|
+
* 3. Else prompt with sighash-decoded context.
|
|
33
|
+
*/
|
|
34
|
+
export declare function handleCreateSignatureRequest(deps: HandlerDeps, args: CreateSignatureArgs, originator: string): Promise<CreateSignatureArgs>;
|
|
35
|
+
/**
|
|
36
|
+
* getPublicKey onRequest:
|
|
37
|
+
* Admin → allow. External → reject. There is no use case where an
|
|
38
|
+
* external dApp needs a derived pubkey under the 'p 1sat' protocol
|
|
39
|
+
* on the user's wallet (BRC-29 sender derivation is done locally by
|
|
40
|
+
* the sender from the recipient's identity key). Rejecting closes
|
|
41
|
+
* the surface entirely.
|
|
42
|
+
*/
|
|
43
|
+
export declare function handleGetPublicKeyRequest(deps: HandlerDeps, args: GetPublicKeyArgs, originator: string): GetPublicKeyArgs;
|
|
44
|
+
export {};
|
|
45
|
+
//# sourceMappingURL=handlers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../src/handlers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,gBAAgB,EAGhB,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,EAChB,eAAe,EACf,MAAM,UAAU,CAAA;AAEjB,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAInD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAE5C,UAAU,WAAW;IACpB,MAAM,EAAE,eAAe,CAAA;IACvB,aAAa,EAAE,aAAa,CAAA;IAC5B,KAAK,EAAE,eAAe,CAAA;IACtB,eAAe,CAAC,EAAE,MAAM,CAAA;CACxB;AAED;;;;;GAKG;AACH,wBAAsB,yBAAyB,CAC9C,IAAI,EAAE,WAAW,EACjB,IAAI,EAAE,gBAAgB,EACtB,UAAU,EAAE,MAAM,GAChB,OAAO,CAAC,gBAAgB,CAAC,CA6B3B;AAED;;;;;;;;GAQG;AACH,wBAAsB,0BAA0B,CAC/C,IAAI,EAAE,WAAW,EACjB,GAAG,EAAE,kBAAkB,EACvB,UAAU,EAAE,MAAM,GAChB,OAAO,CAAC,kBAAkB,CAAC,CAsB7B;AAED;;;;;;GAMG;AACH,wBAAsB,4BAA4B,CACjD,IAAI,EAAE,WAAW,EACjB,IAAI,EAAE,mBAAmB,EACzB,UAAU,EAAE,MAAM,GAChB,OAAO,CAAC,mBAAmB,CAAC,CAkC9B;AAED;;;;;;;GAOG;AACH,wBAAgB,yBAAyB,CACxC,IAAI,EAAE,WAAW,EACjB,IAAI,EAAE,gBAAgB,EACtB,UAAU,EAAE,MAAM,GAChB,gBAAgB,CAKlB"}
|
package/dist/handlers.js
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { Transaction } from '@bsv/sdk';
|
|
2
|
+
import { computeHashOutputs } from './hashOutputs';
|
|
3
|
+
import { substitutePlaceholders } from './placeholder';
|
|
4
|
+
import { MIN_BIP143_PREIMAGE_BYTES, parsePreimage } from './sighashParser';
|
|
5
|
+
/**
|
|
6
|
+
* createAction onRequest:
|
|
7
|
+
* 1. Admin originator → return args unchanged.
|
|
8
|
+
* 2. Substitute placeholder markers in outputs (AIP/Sigma).
|
|
9
|
+
* 3. Prompt user with structured intent. Reject throws.
|
|
10
|
+
*/
|
|
11
|
+
export async function handleCreateActionRequest(deps, args, originator) {
|
|
12
|
+
if (isAdmin(deps, originator))
|
|
13
|
+
return args;
|
|
14
|
+
let outputs = args.outputs ?? [];
|
|
15
|
+
if (outputs.length > 0) {
|
|
16
|
+
outputs = await substitutePlaceholders(outputs, deps.wallet, (refVin) => resolveInputOutpoint(args.inputs ?? [], refVin));
|
|
17
|
+
}
|
|
18
|
+
const summary = summarizeIntent(args);
|
|
19
|
+
const approved = await deps.promptHandler({
|
|
20
|
+
kind: 'transaction',
|
|
21
|
+
originator,
|
|
22
|
+
intent: {
|
|
23
|
+
description: args.description,
|
|
24
|
+
inputs: args.inputs?.map(stripInputForPrompt) ?? [],
|
|
25
|
+
outputs: outputs.map(stripOutputForPrompt),
|
|
26
|
+
labels: args.labels ?? [],
|
|
27
|
+
},
|
|
28
|
+
summary,
|
|
29
|
+
});
|
|
30
|
+
if (!approved) {
|
|
31
|
+
throw new Error('1Sat permission module: user rejected the transaction.');
|
|
32
|
+
}
|
|
33
|
+
return { ...args, outputs };
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* createAction onResponse:
|
|
37
|
+
* Extract the signable transaction's hashOutputs and authorized outpoint
|
|
38
|
+
* set, store under (originator, reference).
|
|
39
|
+
*
|
|
40
|
+
* Admin-originator calls return without capturing — admin operations
|
|
41
|
+
* don't need commitment binding because subsequent createSignature calls
|
|
42
|
+
* will also auto-grant.
|
|
43
|
+
*/
|
|
44
|
+
export async function handleCreateActionResponse(deps, res, originator) {
|
|
45
|
+
if (isAdmin(deps, originator))
|
|
46
|
+
return res;
|
|
47
|
+
const signable = res.signableTransaction;
|
|
48
|
+
if (!signable?.tx || !signable.reference)
|
|
49
|
+
return res;
|
|
50
|
+
const tx = Transaction.fromAtomicBEEF(signable.tx);
|
|
51
|
+
const hashOutputs = computeHashOutputs(tx);
|
|
52
|
+
const authorizedOutpoints = new Set();
|
|
53
|
+
for (const inp of tx.inputs) {
|
|
54
|
+
const txid = inp.sourceTXID ?? inp.sourceTransaction?.id('hex');
|
|
55
|
+
if (!txid)
|
|
56
|
+
continue;
|
|
57
|
+
authorizedOutpoints.add(`${txid}.${inp.sourceOutputIndex}`);
|
|
58
|
+
}
|
|
59
|
+
deps.cache.put(originator, {
|
|
60
|
+
hashOutputs,
|
|
61
|
+
authorizedOutpoints,
|
|
62
|
+
approvedAt: Date.now(),
|
|
63
|
+
reference: signable.reference,
|
|
64
|
+
});
|
|
65
|
+
return res;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* createSignature onRequest:
|
|
69
|
+
* 1. Admin → auto-grant.
|
|
70
|
+
* 2. If args.data is a BIP-143 preimage and its hashOutputs +
|
|
71
|
+
* outpoint match a captured commitment → auto-grant.
|
|
72
|
+
* 3. Else prompt with sighash-decoded context.
|
|
73
|
+
*/
|
|
74
|
+
export async function handleCreateSignatureRequest(deps, args, originator) {
|
|
75
|
+
if (isAdmin(deps, originator))
|
|
76
|
+
return args;
|
|
77
|
+
const data = args.hashToDirectlySign ?? args.data;
|
|
78
|
+
if (data && data.length >= MIN_BIP143_PREIMAGE_BYTES) {
|
|
79
|
+
const parsed = parsePreimage(data);
|
|
80
|
+
if (parsed) {
|
|
81
|
+
const commitment = deps.cache.findByHashOutputs(originator, parsed.hashOutputs);
|
|
82
|
+
if (commitment && commitment.authorizedOutpoints.has(parsed.outpoint)) {
|
|
83
|
+
return args;
|
|
84
|
+
}
|
|
85
|
+
if (commitment) {
|
|
86
|
+
throw new Error(`1Sat permission module: signature requested for outpoint ${parsed.outpoint} which was not part of the approved transaction.`);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
const approved = await deps.promptHandler({
|
|
91
|
+
kind: 'signature',
|
|
92
|
+
originator,
|
|
93
|
+
intent: {
|
|
94
|
+
protocolID: args.protocolID,
|
|
95
|
+
keyID: args.keyID,
|
|
96
|
+
counterparty: args.counterparty,
|
|
97
|
+
dataLength: data?.length ?? 0,
|
|
98
|
+
},
|
|
99
|
+
summary: 'Sign payload',
|
|
100
|
+
});
|
|
101
|
+
if (!approved) {
|
|
102
|
+
throw new Error('1Sat permission module: user rejected the signature.');
|
|
103
|
+
}
|
|
104
|
+
return args;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* getPublicKey onRequest:
|
|
108
|
+
* Admin → allow. External → reject. There is no use case where an
|
|
109
|
+
* external dApp needs a derived pubkey under the 'p 1sat' protocol
|
|
110
|
+
* on the user's wallet (BRC-29 sender derivation is done locally by
|
|
111
|
+
* the sender from the recipient's identity key). Rejecting closes
|
|
112
|
+
* the surface entirely.
|
|
113
|
+
*/
|
|
114
|
+
export function handleGetPublicKeyRequest(deps, args, originator) {
|
|
115
|
+
if (isAdmin(deps, originator))
|
|
116
|
+
return args;
|
|
117
|
+
throw new Error("1Sat permission module: getPublicKey under 'p 1sat' is not available to external originators.");
|
|
118
|
+
}
|
|
119
|
+
// ---------------------------------------------------------------------------
|
|
120
|
+
// Helpers
|
|
121
|
+
// ---------------------------------------------------------------------------
|
|
122
|
+
function isAdmin(deps, originator) {
|
|
123
|
+
return !!deps.adminOriginator && originator === deps.adminOriginator;
|
|
124
|
+
}
|
|
125
|
+
function resolveInputOutpoint(inputs, refVin) {
|
|
126
|
+
const inp = inputs[refVin];
|
|
127
|
+
if (!inp?.outpoint)
|
|
128
|
+
return null;
|
|
129
|
+
const [txid, voutStr] = inp.outpoint.split('.');
|
|
130
|
+
const vout = Number.parseInt(voutStr, 10);
|
|
131
|
+
if (!txid || Number.isNaN(vout))
|
|
132
|
+
return null;
|
|
133
|
+
return { txid, vout };
|
|
134
|
+
}
|
|
135
|
+
function stripInputForPrompt(input) {
|
|
136
|
+
return {
|
|
137
|
+
outpoint: input.outpoint,
|
|
138
|
+
inputDescription: input.inputDescription,
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
function stripOutputForPrompt(output) {
|
|
142
|
+
return {
|
|
143
|
+
satoshis: output.satoshis,
|
|
144
|
+
outputDescription: output.outputDescription,
|
|
145
|
+
basket: output.basket,
|
|
146
|
+
lockingScriptLength: output.lockingScript.length / 2,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
function summarizeIntent(args) {
|
|
150
|
+
if (args.description)
|
|
151
|
+
return args.description;
|
|
152
|
+
const ins = args.inputs?.length ?? 0;
|
|
153
|
+
const outs = args.outputs?.length ?? 0;
|
|
154
|
+
return `Transaction with ${ins} input(s) and ${outs} output(s)`;
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=handlers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"handlers.js","sourceRoot":"","sources":["../src/handlers.ts"],"names":[],"mappings":"AASA,OAAO,EAAQ,WAAW,EAAE,MAAM,UAAU,CAAA;AAE5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAClD,OAAO,EAAE,sBAAsB,EAAE,MAAM,eAAe,CAAA;AACtD,OAAO,EAAE,yBAAyB,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAU1E;;;;;GAKG;AACH,MAAM,CA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/sdk';
|
|
2
|
+
/**
|
|
3
|
+
* Compute the BIP-143 `hashOutputs` (double-SHA256 of the serialized output
|
|
4
|
+
* set) for a transaction. This is the value the module captures at
|
|
5
|
+
* `createAction` onResponse and verifies against `createSignature` preimages.
|
|
6
|
+
*
|
|
7
|
+
* Serialization per output:
|
|
8
|
+
* - 8 bytes value (little-endian)
|
|
9
|
+
* - varint locking-script length
|
|
10
|
+
* - locking-script bytes
|
|
11
|
+
*/
|
|
12
|
+
export declare function computeHashOutputs(tx: Transaction): string;
|
|
13
|
+
//# sourceMappingURL=hashOutputs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hashOutputs.d.ts","sourceRoot":"","sources":["../src/hashOutputs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,WAAW,EAAS,MAAM,UAAU,CAAA;AAExD;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,EAAE,EAAE,WAAW,GAAG,MAAM,CAS1D"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Hash, Utils } from '@bsv/sdk';
|
|
2
|
+
/**
|
|
3
|
+
* Compute the BIP-143 `hashOutputs` (double-SHA256 of the serialized output
|
|
4
|
+
* set) for a transaction. This is the value the module captures at
|
|
5
|
+
* `createAction` onResponse and verifies against `createSignature` preimages.
|
|
6
|
+
*
|
|
7
|
+
* Serialization per output:
|
|
8
|
+
* - 8 bytes value (little-endian)
|
|
9
|
+
* - varint locking-script length
|
|
10
|
+
* - locking-script bytes
|
|
11
|
+
*/
|
|
12
|
+
export function computeHashOutputs(tx) {
|
|
13
|
+
const buf = [];
|
|
14
|
+
for (const out of tx.outputs) {
|
|
15
|
+
writeUint64LE(buf, BigInt(out.satoshis ?? 0));
|
|
16
|
+
const scriptBytes = out.lockingScript.toBinary();
|
|
17
|
+
writeVarint(buf, scriptBytes.length);
|
|
18
|
+
for (const b of scriptBytes)
|
|
19
|
+
buf.push(b);
|
|
20
|
+
}
|
|
21
|
+
return Utils.toHex(Hash.hash256(buf));
|
|
22
|
+
}
|
|
23
|
+
function writeUint64LE(buf, value) {
|
|
24
|
+
let v = value;
|
|
25
|
+
for (let i = 0; i < 8; i++) {
|
|
26
|
+
buf.push(Number(v & 0xffn));
|
|
27
|
+
v >>= 8n;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function writeVarint(buf, n) {
|
|
31
|
+
if (n < 0xfd) {
|
|
32
|
+
buf.push(n);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
if (n <= 0xffff) {
|
|
36
|
+
buf.push(0xfd, n & 0xff, (n >> 8) & 0xff);
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
if (n <= 0xffffffff) {
|
|
40
|
+
buf.push(0xfe, n & 0xff, (n >> 8) & 0xff, (n >> 16) & 0xff, (n >> 24) & 0xff);
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
// > 4 GB script length — implausible in practice.
|
|
44
|
+
buf.push(0xff);
|
|
45
|
+
let v = BigInt(n);
|
|
46
|
+
for (let i = 0; i < 8; i++) {
|
|
47
|
+
buf.push(Number(v & 0xffn));
|
|
48
|
+
v >>= 8n;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=hashOutputs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hashOutputs.js","sourceRoot":"","sources":["../src/hashOutputs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAoB,KAAK,EAAE,MAAM,UAAU,CAAA;AAExD;;;;;;;;;GASG;AACH,MAAM,UAAU,kBAAkB,CAAC,EAAe;IACjD,MAAM,GAAG,GAAa,EAAE,CAAA;IACxB,KAAK,MAAM,GAAG,IAAI,EAAE,CAAC,OAAO,EAAE,CAAC;QAC9B,aAAa,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,CAAC,QAAQ,IAAI,CAAC,CAAC,CAAC,CAAA;QAC7C,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AkD;IAClD,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IACd,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAAA;IACjB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC5B,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAAA;QAC3B,CAAC,KAAK,EAAE,CAAA;IACT,CAAC;AACF,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { createOneSatPermissionModule, type OneSatPermissionModule, type PermissionsModule, } from './createOneSatPermissionModule';
|
|
2
|
+
export { CommitmentCache } from './commitmentCache';
|
|
3
|
+
export { computeHashOutputs } from './hashOutputs';
|
|
4
|
+
export { aipPlaceholderBytes, sigmaPlaceholderBytes, substitutePlaceholders, } from './placeholder';
|
|
5
|
+
export { MIN_BIP143_PREIMAGE_BYTES, parsePreimage, type ParsedPreimage, } from './sighashParser';
|
|
6
|
+
export { DEFAULT_COMMITMENT_TTL_SECONDS, type CapturedCommitment, type CreateOneSatPermissionModuleArgs, type PromptHandler, type PromptKind, type PromptRequest, } from './types';
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,4BAA4B,EAC5B,KAAK,sBAAsB,EAC3B,KAAK,iBAAiB,GACtB,MAAM,gCAAgC,CAAA;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAClD,OAAO,EACN,mBAAmB,EACnB,qBAAqB,EACrB,sBAAsB,GACtB,MAAM,eAAe,CAAA;AACtB,OAAO,EACN,yBAAyB,EACzB,aAAa,EACb,KAAK,cAAc,GACnB,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACN,8BAA8B,EAC9B,KAAK,kBAAkB,EACvB,KAAK,gCAAgC,EACrC,KAAK,aAAa,EAClB,KAAK,UAAU,EACf,KAAK,aAAa,GAClB,MAAM,SAAS,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { createOneSatPermissionModule, } from './createOneSatPermissionModule';
|
|
2
|
+
export { CommitmentCache } from './commitmentCache';
|
|
3
|
+
export { computeHashOutputs } from './hashOutputs';
|
|
4
|
+
export { aipPlaceholderBytes, sigmaPlaceholderBytes, substitutePlaceholders, } from './placeholder';
|
|
5
|
+
export { MIN_BIP143_PREIMAGE_BYTES, parsePreimage, } from './sighashParser';
|
|
6
|
+
export { DEFAULT_COMMITMENT_TTL_SECONDS, } from './types';
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,4BAA4B,GAG5B,MAAM,gCAAgC,CAAA;AACvC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAA;AAClD,OAAO,EACN,mBAAmB,EACnB,qBAAqB,EACrB,sBAAsB,GACtB,MAAM,eAAe,CAAA;AACtB,OAAO,EACN,yBAAyB,EACzB,aAAa,GAEb,MAAM,iBAAiB,CAAA;AACxB,OAAO,EACN,8BAA8B,GAM9B,MAAM,SAAS,CAAA"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Placeholder substitution: SDK actions that need an AIP or Sigma signature
|
|
3
|
+
* embedded in an output script append a marker push at the script tail.
|
|
4
|
+
* The module detects the marker, strips it, and runs the appropriate
|
|
5
|
+
* signing helper to produce the real trailing pushes — using the underlying
|
|
6
|
+
* wallet directly so the inner signature call doesn't re-prompt.
|
|
7
|
+
*
|
|
8
|
+
* Marker format (UTF-8 bytes pushed as a single data push at the script tail):
|
|
9
|
+
*
|
|
10
|
+
* 1SATPM:AIP — needs BAP-AIP signature
|
|
11
|
+
* 1SATPM:SIGMA:<targetVout>:<refVin> — needs Sigma signature
|
|
12
|
+
*
|
|
13
|
+
* Example: a BSocial post action constructs the OP_RETURN with all data
|
|
14
|
+
* pushes, then appends a single push of `'1SATPM:AIP'`. The module sees
|
|
15
|
+
* this trailing push, removes it, calls `applyBapAip` on the resulting
|
|
16
|
+
* script, and writes the modified locking script back to the createAction
|
|
17
|
+
* args before passing them to the underlying wallet.
|
|
18
|
+
*/
|
|
19
|
+
import type { CreateActionOutput, WalletInterface } from '@bsv/sdk';
|
|
20
|
+
/**
|
|
21
|
+
* Build the AIP placeholder bytes the SDK should append.
|
|
22
|
+
*
|
|
23
|
+
* @param keyID - Optional explicit BAP keyID to sign with. Omit to use
|
|
24
|
+
* the current rotated signing key (resolved by the module
|
|
25
|
+
* via `resolveCurrentKeyId`).
|
|
26
|
+
*/
|
|
27
|
+
export declare const aipPlaceholderBytes: (keyID?: string) => number[];
|
|
28
|
+
/**
|
|
29
|
+
* Build the Sigma placeholder bytes the SDK should append.
|
|
30
|
+
*
|
|
31
|
+
* @param targetVout - which output of the new tx the signature covers
|
|
32
|
+
* @param refVin - which input of the new tx anchors the input hash
|
|
33
|
+
*/
|
|
34
|
+
export declare const sigmaPlaceholderBytes: (targetVout: number, refVin: number) => number[];
|
|
35
|
+
/**
|
|
36
|
+
* Inspect every output in `outputs` and substitute placeholder markers with
|
|
37
|
+
* real signatures. Mutation is returned via a fresh array; the caller writes
|
|
38
|
+
* it back into the createAction args before forwarding to the underlying
|
|
39
|
+
* wallet.
|
|
40
|
+
*
|
|
41
|
+
* For Sigma placeholders, the source-input outpoint is needed to compute
|
|
42
|
+
* the input hash. The caller supplies a `resolveSigmaInputOutpoint(refVin)`
|
|
43
|
+
* function that maps a vin index to `{ txid, vout }` (typically by reading
|
|
44
|
+
* `args.inputs[refVin].outpoint`).
|
|
45
|
+
*/
|
|
46
|
+
export declare function substitutePlaceholders(outputs: CreateActionOutput[], wallet: WalletInterface, resolveSigmaInputOutpoint: (refVin: number) => {
|
|
47
|
+
txid: string;
|
|
48
|
+
vout: number;
|
|
49
|
+
} | null): Promise<CreateActionOutput[]>;
|
|
50
|
+
//# sourceMappingURL=placeholder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"placeholder.d.ts","sourceRoot":"","sources":["../src/placeholder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAUH,OAAO,KAAK,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAGnE;;;;;;GAMG;AACH,eAAO,MAAM,mBAAmB,GAAI,QAAQ,MAAM,KAAG,MAAM,EAIzD,CAAA;AAEF;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,GACjC,YAAY,MAAM,EAClB,QAAQ,MAAM,KACZ,MAAM,EAIP,CAAA;AA0CF;;;;;;;;;;GAUG;AACH,wBAAsB,sBAAsB,CAC3C,OAAO,EAAE,kBAAkB,EAAE,EAC7B,MAAM,EAAE,eAAe,EACvB,yBAAyB,EAAE,CAC1B,MAAM,EAAE,MAAM,KACV;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,GACxC,OAAO,CAAC,kBAAkB,EAAE,CAAC,CA2B/B"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Placeholder substitution: SDK actions that need an AIP or Sigma signature
|
|
3
|
+
* embedded in an output script append a marker push at the script tail.
|
|
4
|
+
* The module detects the marker, strips it, and runs the appropriate
|
|
5
|
+
* signing helper to produce the real trailing pushes — using the underlying
|
|
6
|
+
* wallet directly so the inner signature call doesn't re-prompt.
|
|
7
|
+
*
|
|
8
|
+
* Marker format (UTF-8 bytes pushed as a single data push at the script tail):
|
|
9
|
+
*
|
|
10
|
+
* 1SATPM:AIP — needs BAP-AIP signature
|
|
11
|
+
* 1SATPM:SIGMA:<targetVout>:<refVin> — needs Sigma signature
|
|
12
|
+
*
|
|
13
|
+
* Example: a BSocial post action constructs the OP_RETURN with all data
|
|
14
|
+
* pushes, then appends a single push of `'1SATPM:AIP'`. The module sees
|
|
15
|
+
* this trailing push, removes it, calls `applyBapAip` on the resulting
|
|
16
|
+
* script, and writes the modified locking script back to the createAction
|
|
17
|
+
* args before passing them to the underlying wallet.
|
|
18
|
+
*/
|
|
19
|
+
import { applyBapAip, applySigma } from '@1sat/actions';
|
|
20
|
+
import { P1SAT_AIP_PLACEHOLDER, P1SAT_AIP_PLACEHOLDER_PREFIX, P1SAT_PLACEHOLDER_PREFIX, P1SAT_SIGMA_PLACEHOLDER_PREFIX, } from '@1sat/types';
|
|
21
|
+
import { Script, Utils } from '@bsv/sdk';
|
|
22
|
+
/**
|
|
23
|
+
* Build the AIP placeholder bytes the SDK should append.
|
|
24
|
+
*
|
|
25
|
+
* @param keyID - Optional explicit BAP keyID to sign with. Omit to use
|
|
26
|
+
* the current rotated signing key (resolved by the module
|
|
27
|
+
* via `resolveCurrentKeyId`).
|
|
28
|
+
*/
|
|
29
|
+
export const aipPlaceholderBytes = (keyID) => Utils.toArray(keyID ? `${P1SAT_AIP_PLACEHOLDER_PREFIX}${keyID}` : P1SAT_AIP_PLACEHOLDER, 'utf8');
|
|
30
|
+
/**
|
|
31
|
+
* Build the Sigma placeholder bytes the SDK should append.
|
|
32
|
+
*
|
|
33
|
+
* @param targetVout - which output of the new tx the signature covers
|
|
34
|
+
* @param refVin - which input of the new tx anchors the input hash
|
|
35
|
+
*/
|
|
36
|
+
export const sigmaPlaceholderBytes = (targetVout, refVin) => Utils.toArray(`${P1SAT_SIGMA_PLACEHOLDER_PREFIX}${targetVout}:${refVin}`, 'utf8');
|
|
37
|
+
/** Read the trailing placeholder marker (if any) from a locking script. */
|
|
38
|
+
function readPlaceholder(scriptHex) {
|
|
39
|
+
const script = Script.fromHex(scriptHex);
|
|
40
|
+
const lastChunk = script.chunks[script.chunks.length - 1];
|
|
41
|
+
if (!lastChunk?.data || lastChunk.data.length === 0)
|
|
42
|
+
return null;
|
|
43
|
+
const text = Utils.toUTF8(Array.from(lastChunk.data));
|
|
44
|
+
if (!text.startsWith(P1SAT_PLACEHOLDER_PREFIX))
|
|
45
|
+
return null;
|
|
46
|
+
if (text === P1SAT_AIP_PLACEHOLDER)
|
|
47
|
+
return { kind: 'aip' };
|
|
48
|
+
if (text.startsWith(P1SAT_AIP_PLACEHOLDER_PREFIX)) {
|
|
49
|
+
const keyID = text.slice(P1SAT_AIP_PLACEHOLDER_PREFIX.length);
|
|
50
|
+
if (!keyID)
|
|
51
|
+
return { kind: 'aip' };
|
|
52
|
+
return { kind: 'aip', keyID };
|
|
53
|
+
}
|
|
54
|
+
if (text.startsWith(P1SAT_SIGMA_PLACEHOLDER_PREFIX)) {
|
|
55
|
+
const rest = text.slice(P1SAT_SIGMA_PLACEHOLDER_PREFIX.length);
|
|
56
|
+
const [voutStr, vinStr] = rest.split(':');
|
|
57
|
+
const targetVout = Number.parseInt(voutStr, 10);
|
|
58
|
+
const refVin = Number.parseInt(vinStr, 10);
|
|
59
|
+
if (Number.isNaN(targetVout) || Number.isNaN(refVin))
|
|
60
|
+
return null;
|
|
61
|
+
return { kind: 'sigma', targetVout, refVin };
|
|
62
|
+
}
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
/** Strip the trailing placeholder push from a script. */
|
|
66
|
+
function stripPlaceholder(scriptHex) {
|
|
67
|
+
const script = Script.fromHex(scriptHex);
|
|
68
|
+
return new Script(script.chunks.slice(0, -1));
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Inspect every output in `outputs` and substitute placeholder markers with
|
|
72
|
+
* real signatures. Mutation is returned via a fresh array; the caller writes
|
|
73
|
+
* it back into the createAction args before forwarding to the underlying
|
|
74
|
+
* wallet.
|
|
75
|
+
*
|
|
76
|
+
* For Sigma placeholders, the source-input outpoint is needed to compute
|
|
77
|
+
* the input hash. The caller supplies a `resolveSigmaInputOutpoint(refVin)`
|
|
78
|
+
* function that maps a vin index to `{ txid, vout }` (typically by reading
|
|
79
|
+
* `args.inputs[refVin].outpoint`).
|
|
80
|
+
*/
|
|
81
|
+
export async function substitutePlaceholders(outputs, wallet, resolveSigmaInputOutpoint) {
|
|
82
|
+
const ctx = { wallet, chain: 'main' };
|
|
83
|
+
const next = [];
|
|
84
|
+
for (const out of outputs) {
|
|
85
|
+
const info = readPlaceholder(out.lockingScript);
|
|
86
|
+
if (!info) {
|
|
87
|
+
next.push(out);
|
|
88
|
+
continue;
|
|
89
|
+
}
|
|
90
|
+
const stripped = stripPlaceholder(out.lockingScript);
|
|
91
|
+
let signed;
|
|
92
|
+
if (info.kind === 'aip') {
|
|
93
|
+
signed = await applyBapAip(ctx, stripped, info.keyID);
|
|
94
|
+
}
|
|
95
|
+
else {
|
|
96
|
+
const refVin = info.refVin ?? 0;
|
|
97
|
+
const targetVout = info.targetVout ?? next.length;
|
|
98
|
+
const outpoint = resolveSigmaInputOutpoint(refVin);
|
|
99
|
+
if (!outpoint) {
|
|
100
|
+
throw new Error(`1Sat permission module: cannot resolve input outpoint for Sigma placeholder (refVin=${refVin})`);
|
|
101
|
+
}
|
|
102
|
+
signed = await applySigma(ctx, stripped, outpoint, targetVout, refVin);
|
|
103
|
+
}
|
|
104
|
+
next.push({ ...out, lockingScript: signed.toHex() });
|
|
105
|
+
}
|
|
106
|
+
return next;
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=placeholder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"placeholder.js","sourceRoot":"","sources":["../src/placeholder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,eAAe,CA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
4
|
+
export interface ParsedPreimage {
|
|
5
|
+
/** `txid.vout` of the input being signed. */
|
|
6
|
+
outpoint: string;
|
|
7
|
+
/** 32-byte hashOutputs (hex). */
|
|
8
|
+
hashOutputs: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Minimum size for a BIP-143 preimage:
|
|
12
|
+
* 4 (version) + 32 (hashPrevouts) + 32 (hashSequence)
|
|
13
|
+
* + 36 (outpoint) + 1 (varint scriptCodeLen, min) + 0 (empty scriptCode allowed)
|
|
14
|
+
* + 8 (value) + 4 (nSequence) + 32 (hashOutputs) + 4 (nLockTime) + 4 (nHashType)
|
|
15
|
+
* = 157 bytes.
|
|
16
|
+
*
|
|
17
|
+
* Anything shorter cannot be a BIP-143 preimage; treat as standalone signing.
|
|
18
|
+
*/
|
|
19
|
+
export declare const MIN_BIP143_PREIMAGE_BYTES = 157;
|
|
20
|
+
/**
|
|
21
|
+
* Parse a BIP-143 preimage and extract the input outpoint and hashOutputs.
|
|
22
|
+
*
|
|
23
|
+
* Returns null if the buffer is shorter than {@link MIN_BIP143_PREIMAGE_BYTES}
|
|
24
|
+
* or if varint decoding runs off the end. The caller treats null as
|
|
25
|
+
* "not a BIP-143 preimage; prompt the user."
|
|
26
|
+
*/
|
|
27
|
+
export declare function parsePreimage(data: number[] | Uint8Array): ParsedPreimage | null;
|
|
28
|
+
//# sourceMappingURL=sighashParser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sighashParser.d.ts","sourceRoot":"","sources":["../src/sighashParser.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,WAAW,cAAc;IAC9B,6CAA6C;IAC7C,QAAQ,EAAE,MAAM,CAAA;IAChB,iCAAiC;IACjC,WAAW,EAAE,MAAM,CAAA;CACnB;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,yBAAyB,MAAM,CAAA;AAE5C;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,UAAU,GAAG,cAAc,GAAG,IAAI,CA2BhF"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { Utils } from '@bsv/sdk';
|
|
2
|
+
/**
|
|
3
|
+
* Minimum size for a BIP-143 preimage:
|
|
4
|
+
* 4 (version) + 32 (hashPrevouts) + 32 (hashSequence)
|
|
5
|
+
* + 36 (outpoint) + 1 (varint scriptCodeLen, min) + 0 (empty scriptCode allowed)
|
|
6
|
+
* + 8 (value) + 4 (nSequence) + 32 (hashOutputs) + 4 (nLockTime) + 4 (nHashType)
|
|
7
|
+
* = 157 bytes.
|
|
8
|
+
*
|
|
9
|
+
* Anything shorter cannot be a BIP-143 preimage; treat as standalone signing.
|
|
10
|
+
*/
|
|
11
|
+
export const MIN_BIP143_PREIMAGE_BYTES = 157;
|
|
12
|
+
/**
|
|
13
|
+
* Parse a BIP-143 preimage and extract the input outpoint and hashOutputs.
|
|
14
|
+
*
|
|
15
|
+
* Returns null if the buffer is shorter than {@link MIN_BIP143_PREIMAGE_BYTES}
|
|
16
|
+
* or if varint decoding runs off the end. The caller treats null as
|
|
17
|
+
* "not a BIP-143 preimage; prompt the user."
|
|
18
|
+
*/
|
|
19
|
+
export function parsePreimage(data) {
|
|
20
|
+
const buf = data instanceof Uint8Array ? Array.from(data) : data;
|
|
21
|
+
if (buf.length < MIN_BIP143_PREIMAGE_BYTES)
|
|
22
|
+
return null;
|
|
23
|
+
// Outpoint at offset 68: 32-byte txid (LE) + 4-byte vout (LE).
|
|
24
|
+
const txidBytes = buf.slice(68, 100).reverse();
|
|
25
|
+
const txid = Utils.toHex(txidBytes);
|
|
26
|
+
const vout = buf[100] | (buf[101] << 8) | (buf[102] << 16) | (buf[103] << 24);
|
|
27
|
+
// Varint scriptCode length at offset 104.
|
|
28
|
+
const varint = readVarint(buf, 104);
|
|
29
|
+
if (!varint)
|
|
30
|
+
return null;
|
|
31
|
+
const scriptCodeStart = 104 + varint.size;
|
|
32
|
+
const scriptCodeEnd = scriptCodeStart + varint.value;
|
|
33
|
+
if (scriptCodeEnd > buf.length)
|
|
34
|
+
return null;
|
|
35
|
+
// After scriptCode: 8 bytes value, 4 bytes nSequence, 32 bytes hashOutputs.
|
|
36
|
+
const hashOutputsStart = scriptCodeEnd + 8 + 4;
|
|
37
|
+
const hashOutputsEnd = hashOutputsStart + 32;
|
|
38
|
+
if (hashOutputsEnd > buf.length)
|
|
39
|
+
return null;
|
|
40
|
+
const hashOutputs = Utils.toHex(buf.slice(hashOutputsStart, hashOutputsEnd));
|
|
41
|
+
return {
|
|
42
|
+
outpoint: `${txid}.${vout >>> 0}`,
|
|
43
|
+
hashOutputs,
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
function readVarint(buf, offset) {
|
|
47
|
+
if (offset >= buf.length)
|
|
48
|
+
return null;
|
|
49
|
+
const first = buf[offset];
|
|
50
|
+
if (first < 0xfd)
|
|
51
|
+
return { value: first, size: 1 };
|
|
52
|
+
if (first === 0xfd) {
|
|
53
|
+
if (offset + 2 >= buf.length)
|
|
54
|
+
return null;
|
|
55
|
+
return {
|
|
56
|
+
value: buf[offset + 1] | (buf[offset + 2] << 8),
|
|
57
|
+
size: 3,
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
if (first === 0xfe) {
|
|
61
|
+
if (offset + 4 >= buf.length)
|
|
62
|
+
return null;
|
|
63
|
+
return {
|
|
64
|
+
value: (buf[offset + 1] |
|
|
65
|
+
(buf[offset + 2] << 8) |
|
|
66
|
+
(buf[offset + 3] << 16) |
|
|
67
|
+
(buf[offset + 4] << 24)) >>>
|
|
68
|
+
0,
|
|
69
|
+
size: 5,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
// 0xff — 8-byte varint. JS numbers safely represent up to 2^53. ScriptCode
|
|
73
|
+
// lengths in the wild won't approach that; reject if it would.
|
|
74
|
+
if (offset + 8 >= buf.length)
|
|
75
|
+
return null;
|
|
76
|
+
let value = 0;
|
|
77
|
+
for (let i = 0; i < 8; i++) {
|
|
78
|
+
const byte = buf[offset + 1 + i];
|
|
79
|
+
if (i >= 6 && byte !== 0)
|
|
80
|
+
return null;
|
|
81
|
+
value += byte * 2 ** (8 * i);
|
|
82
|
+
}
|
|
83
|
+
return { value, size: 9 };
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=sighashParser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sighashParser.js","sourceRoot":"","sources":["../src/sighashParser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAA;AAYhC;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,GAAG,CAAA;AAE5C;;;;;;GAMG;AACH,MAAM,UAAU,aAAa,CAAC,IAA2B;IACxD,MAAM,GAAG,GAAG,IAAI,YAAY,UAAU,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;IAChE,IAAI,GAAG,CAAC,MAAM,GAAG,yBAAyB;QAAE,OAAO,IAAI,CAAA;IAEvD,+DAA+D;IAC/D,MAAM,SAAS,GAAG,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,OAAO,EAAE,CAAA;IAC9C,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,CAAA;IACnC,MAAM,IAAI,GACT,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAA;IAEjE,0CAA0C;IAC1C,MAAM,MAAM,GAAG,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,CAAA;IACnC,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAA;IACxB,M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AAI,GAAG,CAAC,MAAM;YAAE,OAAO,IAAI,CAAA;QACzC,OAAO;YACN,KAAK,EACJ,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC;gBACf,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC;gBACtB,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;gBACvB,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;gBACzB,CAAC;YACF,IAAI,EAAE,CAAC;SACP,CAAA;IACF,CAAC;IACD,2EAA2E;IAC3E,+DAA+D;IAC/D,IAAI,MAAM,GAAG,CAAC,IAAI,GAAG,CAAC,MAAM;QAAE,OAAO,IAAI,CAAA;IACzC,IAAI,KAAK,GAAG,CAAC,CAAA;IACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;QAC5B,MAAM,IAAI,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;QAChC,IAAI,CAAC,IAAI,CAAC,IAAI,IAAI,KAAK,CAAC;YAAE,OAAO,IAAI,CAAA;QACrC,KAAK,IAAI,IAAI,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAA;IAC7B,CAAC;IACD,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,EAAE,CAAA;AAC1B,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { WalletInterface } from '@bsv/sdk';
|
|
2
|
+
/**
|
|
3
|
+
* Default commitment cache TTL (seconds). After this window the captured
|
|
4
|
+
* hashOutputs commitment expires and any subsequent createSignature for
|
|
5
|
+
* the same originator will be treated as standalone (re-prompt) instead
|
|
6
|
+
* of auto-granted.
|
|
7
|
+
*
|
|
8
|
+
* Configurable per-module-instance via factory args.
|
|
9
|
+
*/
|
|
10
|
+
export declare const DEFAULT_COMMITMENT_TTL_SECONDS = 60;
|
|
11
|
+
/** A single captured commitment from a createAction approval. */
|
|
12
|
+
export interface CapturedCommitment {
|
|
13
|
+
/** BIP-143 hashOutputs (32 bytes, hex) of the approved transaction. */
|
|
14
|
+
hashOutputs: string;
|
|
15
|
+
/** `txid.vout` strings for every input the user authorized. */
|
|
16
|
+
authorizedOutpoints: Set<string>;
|
|
17
|
+
/** Wall-clock ms when the user approved. */
|
|
18
|
+
approvedAt: number;
|
|
19
|
+
/** WalletPermissionsManager reference returned from createAction. */
|
|
20
|
+
reference: string;
|
|
21
|
+
}
|
|
22
|
+
/** Kinds of prompts the module asks the host wallet to show. */
|
|
23
|
+
export type PromptKind = 'transaction' | 'signature';
|
|
24
|
+
/**
|
|
25
|
+
* Structured request handed to the wallet's promptHandler.
|
|
26
|
+
*
|
|
27
|
+
* The host wallet renders this via `@1sat/permission-module-ui`'s component
|
|
28
|
+
* (or its own UI) and resolves the returned Promise with `true` (approve)
|
|
29
|
+
* or `false` (reject).
|
|
30
|
+
*/
|
|
31
|
+
export interface PromptRequest {
|
|
32
|
+
kind: PromptKind;
|
|
33
|
+
originator: string;
|
|
34
|
+
/**
|
|
35
|
+
* Free-form context payload describing the operation. Shape is
|
|
36
|
+
* intentionally permissive so the SDK actions can ride additional
|
|
37
|
+
* detail through to the prompt without locking the schema.
|
|
38
|
+
*/
|
|
39
|
+
intent: Record<string, unknown>;
|
|
40
|
+
/** Short human-readable summary line. Filled in by the module. */
|
|
41
|
+
summary: string;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Callback the host wallet provides for showing prompts and awaiting
|
|
45
|
+
* the user's decision.
|
|
46
|
+
*/
|
|
47
|
+
export type PromptHandler = (request: PromptRequest) => Promise<boolean>;
|
|
48
|
+
/** Args accepted by `createOneSatPermissionModule`. */
|
|
49
|
+
export interface CreateOneSatPermissionModuleArgs {
|
|
50
|
+
/**
|
|
51
|
+
* The underlying wallet (NOT the WalletPermissionsManager wrapper).
|
|
52
|
+
* The module uses this for placeholder substitution and any internal
|
|
53
|
+
* derivations that should bypass the permission flow.
|
|
54
|
+
*/
|
|
55
|
+
wallet: WalletInterface;
|
|
56
|
+
/** UI callback for prompting the user. */
|
|
57
|
+
promptHandler: PromptHandler;
|
|
58
|
+
/** Optional override for commitment cache TTL (seconds). */
|
|
59
|
+
commitmentTtlSeconds?: number;
|
|
60
|
+
/**
|
|
61
|
+
* Originator string treated as the wallet itself. Calls from this
|
|
62
|
+
* originator auto-grant. Defaults to the WalletPermissionsManager
|
|
63
|
+
* `adminOriginator` value if your wallet wires it through.
|
|
64
|
+
*/
|
|
65
|
+
adminOriginator?: string;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAE/C;;;;;;;GAOG;AACH,eAAO,MAAM,8BAA8B,KAAK,CAAA;AAEhD,iEAAiE;AACjE,MAAM,WAAW,kBAAkB;IAClC,uEAAuE;IACvE,WAAW,EAAE,MAAM,CAAA;IACnB,+DAA+D;IAC/D,mBAAmB,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IAChC,4CAA4C;IAC5C,UAAU,EAAE,MAAM,CAAA;IAClB,qEAAqE;IACrE,SAAS,EAAE,MAAM,CAAA;CACjB;AAED,gEAAgE;AAChE,MAAM,MAAM,UAAU,GAAG,aAAa,GAAG,WAAW,CAAA;AAEpD;;;;;;GAMG;AACH,MAAM,WAAW,aAAa;IAC7B,IAAI,EAAE,UAAU,CAAA;IAChB,UAAU,EAAE,MAAM,CAAA;IAClB;;;;OAIG;IACH,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IAC/B,kEAAkE;IAClE,OAAO,EAAE,MAAM,CAAA;CACf;AAED;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,EAAE,aAAa,KAAK,OAAO,CAAC,OAAO,CAAC,CAAA;AAExE,uDAAuD;AACvD,MAAM,WAAW,gCAAgC;IAChD;;;;OAIG;IACH,MAAM,EAAE,eAAe,CAAA;IACvB,0CAA0C;IAC1C,aAAa,EAAE,aAAa,CAAA;IAC5B,4DAA4D;IAC5D,oBAAoB,CAAC,EAAE,MAAM,CAAA;IAC7B;;;;OAIG;IACH,eAAe,CAAC,EAAE,MAAM,CAAA;CACxB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default commitment cache TTL (seconds). After this window the captured
|
|
3
|
+
* hashOutputs commitment expires and any subsequent createSignature for
|
|
4
|
+
* the same originator will be treated as standalone (re-prompt) instead
|
|
5
|
+
* of auto-granted.
|
|
6
|
+
*
|
|
7
|
+
* Configurable per-module-instance via factory args.
|
|
8
|
+
*/
|
|
9
|
+
export const DEFAULT_COMMITMENT_TTL_SECONDS = 60;
|
|
10
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAEA;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAG,EAAE,CAAA"}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@1sat/permission-module",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "1Sat permission module for WalletPermissionsManager — gates createSignature with hashOutputs commitments captured at createAction time",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist"
|
|
16
|
+
],
|
|
17
|
+
"scripts": {
|
|
18
|
+
"build": "tsc",
|
|
19
|
+
"dev": "tsc --watch",
|
|
20
|
+
"clean": "rm -rf dist",
|
|
21
|
+
"test": "bun test"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"1sat",
|
|
25
|
+
"bsv",
|
|
26
|
+
"wallet",
|
|
27
|
+
"permissions",
|
|
28
|
+
"brc-0098"
|
|
29
|
+
],
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@1sat/types": "0.0.22",
|
|
33
|
+
"@1sat/actions": "0.0.133"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"@bsv/sdk": "^2.0.13",
|
|
37
|
+
"@bsv/wallet-toolbox": "npm:@bopen-io/wallet-toolbox@2.1.21-parity-fix.2"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@bsv/sdk": "^2.0.13",
|
|
41
|
+
"typescript": "^5.9.3"
|
|
42
|
+
}
|
|
43
|
+
}
|