sigild 0.0.12 → 0.0.14
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/README.md +63 -3
- package/THREAT_MODEL.md +4 -0
- package/dist/src/audit/index.d.ts +2 -1
- package/dist/src/audit/index.d.ts.map +1 -1
- package/dist/src/audit/index.js +1 -0
- package/dist/src/audit/index.js.map +1 -1
- package/dist/src/audit/log.d.ts +52 -3
- package/dist/src/audit/log.d.ts.map +1 -1
- package/dist/src/audit/log.js +226 -40
- package/dist/src/audit/log.js.map +1 -1
- package/dist/src/bin/sigil-mcp.js +79 -9
- package/dist/src/bin/sigil-mcp.js.map +1 -1
- package/dist/src/cli/main.d.ts.map +1 -1
- package/dist/src/cli/main.js +35 -1
- package/dist/src/cli/main.js.map +1 -1
- package/dist/src/cli/paths.d.ts +4 -0
- package/dist/src/cli/paths.d.ts.map +1 -1
- package/dist/src/cli/paths.js +2 -0
- package/dist/src/cli/paths.js.map +1 -1
- package/dist/src/cli/portal.d.ts.map +1 -1
- package/dist/src/cli/portal.js +11 -1
- package/dist/src/cli/portal.js.map +1 -1
- package/dist/src/confirm/config.d.ts +19 -0
- package/dist/src/confirm/config.d.ts.map +1 -1
- package/dist/src/confirm/config.js +48 -0
- package/dist/src/confirm/config.js.map +1 -1
- package/dist/src/confirm/index.d.ts +1 -1
- package/dist/src/confirm/index.d.ts.map +1 -1
- package/dist/src/confirm/index.js.map +1 -1
- package/dist/src/daemon/handles.d.ts +6 -0
- package/dist/src/daemon/handles.d.ts.map +1 -1
- package/dist/src/daemon/handles.js +11 -0
- package/dist/src/daemon/handles.js.map +1 -1
- package/dist/src/daemon/index.d.ts +1 -1
- package/dist/src/daemon/index.d.ts.map +1 -1
- package/dist/src/daemon/index.js.map +1 -1
- package/dist/src/daemon/methods.d.ts +29 -1
- package/dist/src/daemon/methods.d.ts.map +1 -1
- package/dist/src/daemon/methods.js +293 -27
- package/dist/src/daemon/methods.js.map +1 -1
- package/dist/src/eth/abi.d.ts +82 -0
- package/dist/src/eth/abi.d.ts.map +1 -0
- package/dist/src/eth/abi.js +328 -0
- package/dist/src/eth/abi.js.map +1 -0
- package/dist/src/eth/index.d.ts +1 -0
- package/dist/src/eth/index.d.ts.map +1 -1
- package/dist/src/eth/index.js +1 -0
- package/dist/src/eth/index.js.map +1 -1
- package/dist/src/fs/index.d.ts +2 -0
- package/dist/src/fs/index.d.ts.map +1 -0
- package/dist/src/fs/index.js +2 -0
- package/dist/src/fs/index.js.map +1 -0
- package/dist/src/fs/lock.d.ts +84 -0
- package/dist/src/fs/lock.d.ts.map +1 -0
- package/dist/src/fs/lock.js +329 -0
- package/dist/src/fs/lock.js.map +1 -0
- package/dist/src/mcp/parent-watchdog.d.ts +31 -0
- package/dist/src/mcp/parent-watchdog.d.ts.map +1 -0
- package/dist/src/mcp/parent-watchdog.js +35 -0
- package/dist/src/mcp/parent-watchdog.js.map +1 -0
- package/dist/src/mcp/server.d.ts +7 -0
- package/dist/src/mcp/server.d.ts.map +1 -1
- package/dist/src/mcp/server.js +13 -2
- package/dist/src/mcp/server.js.map +1 -1
- package/dist/src/mcp/tools.d.ts.map +1 -1
- package/dist/src/mcp/tools.js +21 -1
- package/dist/src/mcp/tools.js.map +1 -1
- package/dist/src/policy/evaluate.d.ts.map +1 -1
- package/dist/src/policy/evaluate.js +69 -4
- package/dist/src/policy/evaluate.js.map +1 -1
- package/dist/src/policy/index.d.ts +2 -0
- package/dist/src/policy/index.d.ts.map +1 -1
- package/dist/src/policy/index.js +2 -0
- package/dist/src/policy/index.js.map +1 -1
- package/dist/src/policy/ledger.d.ts +84 -0
- package/dist/src/policy/ledger.d.ts.map +1 -0
- package/dist/src/policy/ledger.js +276 -0
- package/dist/src/policy/ledger.js.map +1 -0
- package/dist/src/policy/loader.d.ts.map +1 -1
- package/dist/src/policy/loader.js +54 -0
- package/dist/src/policy/loader.js.map +1 -1
- package/dist/src/policy/template.d.ts +2 -2
- package/dist/src/policy/template.d.ts.map +1 -1
- package/dist/src/policy/template.js +52 -0
- package/dist/src/policy/template.js.map +1 -1
- package/dist/src/policy/types.d.ts +42 -0
- package/dist/src/policy/types.d.ts.map +1 -1
- package/dist/src/policy/types.js.map +1 -1
- package/dist/src/policy/window.d.ts +22 -0
- package/dist/src/policy/window.d.ts.map +1 -0
- package/dist/src/policy/window.js +66 -0
- package/dist/src/policy/window.js.map +1 -0
- package/dist/src/preview/abi-dir.d.ts +50 -0
- package/dist/src/preview/abi-dir.d.ts.map +1 -0
- package/dist/src/preview/abi-dir.js +175 -0
- package/dist/src/preview/abi-dir.js.map +1 -0
- package/dist/src/preview/decode.d.ts +26 -0
- package/dist/src/preview/decode.d.ts.map +1 -0
- package/dist/src/preview/decode.js +110 -0
- package/dist/src/preview/decode.js.map +1 -0
- package/dist/src/preview/format.d.ts +45 -0
- package/dist/src/preview/format.d.ts.map +1 -0
- package/dist/src/preview/format.js +222 -0
- package/dist/src/preview/format.js.map +1 -0
- package/dist/src/preview/index.d.ts +60 -0
- package/dist/src/preview/index.d.ts.map +1 -0
- package/dist/src/preview/index.js +163 -0
- package/dist/src/preview/index.js.map +1 -0
- package/dist/src/preview/known.d.ts +74 -0
- package/dist/src/preview/known.d.ts.map +1 -0
- package/dist/src/preview/known.js +425 -0
- package/dist/src/preview/known.js.map +1 -0
- package/dist/src/preview/simulate.d.ts +156 -0
- package/dist/src/preview/simulate.d.ts.map +1 -0
- package/dist/src/preview/simulate.js +768 -0
- package/dist/src/preview/simulate.js.map +1 -0
- package/dist/src/preview/simulators.d.ts +39 -0
- package/dist/src/preview/simulators.d.ts.map +1 -0
- package/dist/src/preview/simulators.js +71 -0
- package/dist/src/preview/simulators.js.map +1 -0
- package/dist/src/preview/trust.d.ts +49 -0
- package/dist/src/preview/trust.d.ts.map +1 -0
- package/dist/src/preview/trust.js +279 -0
- package/dist/src/preview/trust.js.map +1 -0
- package/dist/src/preview/types.d.ts +69 -0
- package/dist/src/preview/types.d.ts.map +1 -0
- package/dist/src/preview/types.js +11 -0
- package/dist/src/preview/types.js.map +1 -0
- package/dist/src/preview/units.d.ts +75 -0
- package/dist/src/preview/units.d.ts.map +1 -0
- package/dist/src/preview/units.js +228 -0
- package/dist/src/preview/units.js.map +1 -0
- package/package.json +5 -5
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal Solidity ABI decoder (no encoder): enough to turn calldata, event
|
|
3
|
+
* data and revert payloads into values for the transaction preview. Hand-
|
|
4
|
+
* rolled on top of the existing keccak so the runtime dependency set stays
|
|
5
|
+
* at the pinned @noble/* + @iarna/toml.
|
|
6
|
+
*
|
|
7
|
+
* Every byte this module reads is attacker-supplied (the agent hands sigil
|
|
8
|
+
* calldata; a contract under simulation picks its own logs and revert data),
|
|
9
|
+
* so decoding is strict and bounded:
|
|
10
|
+
* - every offset and length is checked against the buffer before use, and
|
|
11
|
+
* any violation is an AbiDecodeError — never a raw RangeError or a
|
|
12
|
+
* silently short read;
|
|
13
|
+
* - static values must be canonically padded (a uint8 with high bits set,
|
|
14
|
+
* an address with a dirty upper word, a bool of 2) — non-canonical
|
|
15
|
+
* encodings are how two decoders get made to disagree about one payload;
|
|
16
|
+
* - total decoded output is budgeted against the input size, so offsets
|
|
17
|
+
* that alias one large element many times can't amplify a small payload
|
|
18
|
+
* into a huge allocation.
|
|
19
|
+
*/
|
|
20
|
+
export type AbiType = {
|
|
21
|
+
kind: 'uint';
|
|
22
|
+
bits: number;
|
|
23
|
+
} | {
|
|
24
|
+
kind: 'int';
|
|
25
|
+
bits: number;
|
|
26
|
+
} | {
|
|
27
|
+
kind: 'address';
|
|
28
|
+
} | {
|
|
29
|
+
kind: 'bool';
|
|
30
|
+
} | {
|
|
31
|
+
kind: 'fixedBytes';
|
|
32
|
+
size: number;
|
|
33
|
+
} | {
|
|
34
|
+
kind: 'bytes';
|
|
35
|
+
} | {
|
|
36
|
+
kind: 'string';
|
|
37
|
+
} | {
|
|
38
|
+
kind: 'array';
|
|
39
|
+
inner: AbiType;
|
|
40
|
+
length: number | null;
|
|
41
|
+
} | {
|
|
42
|
+
kind: 'tuple';
|
|
43
|
+
components: AbiType[];
|
|
44
|
+
};
|
|
45
|
+
export declare class AbiDecodeError extends Error {
|
|
46
|
+
constructor(message: string);
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Parse a canonical Solidity type string: `uint256`, `int8`, `address`,
|
|
50
|
+
* `bool`, `bytes32`, `bytes`, `string`, `T[k]`, `T[]`, `(T1,T2,…)` and any
|
|
51
|
+
* nesting of those. `uint`/`int` are accepted as aliases for the 256-bit
|
|
52
|
+
* forms. Whitespace is not allowed (canonical signatures have none).
|
|
53
|
+
*/
|
|
54
|
+
export declare function parseAbiType(t: string): AbiType;
|
|
55
|
+
/**
|
|
56
|
+
* Parse a function or event signature `name(T1,T2,…)` into its name and
|
|
57
|
+
* parameter types. The name must be a Solidity identifier.
|
|
58
|
+
*/
|
|
59
|
+
export declare function parseSignature(signature: string): {
|
|
60
|
+
name: string;
|
|
61
|
+
inputs: AbiType[];
|
|
62
|
+
};
|
|
63
|
+
/** The canonical string for a parsed type (round-trips through parseAbiType). */
|
|
64
|
+
export declare function canonicalType(t: AbiType): string;
|
|
65
|
+
/** True when the type's encoding lives in the tail (has an offset in the head). */
|
|
66
|
+
export declare function isDynamic(t: AbiType): boolean;
|
|
67
|
+
/**
|
|
68
|
+
* Decode `data` as the ABI encoding of a parameter list. Values:
|
|
69
|
+
* uint/int → bigint (two's complement for int), address → lowercase 0x
|
|
70
|
+
* hex, bool → boolean, bytesN/bytes → lowercase 0x hex, string → string
|
|
71
|
+
* (UTF-8, invalid sequences replaced), arrays and tuples → unknown[].
|
|
72
|
+
* Trailing bytes after the encoding are tolerated (calldata commonly carries
|
|
73
|
+
* them); everything the types reference must be in bounds.
|
|
74
|
+
*/
|
|
75
|
+
export declare function decodeAbiParameters(types: readonly string[], data: Uint8Array): unknown[];
|
|
76
|
+
/** Same as decodeAbiParameters, for pre-parsed types. */
|
|
77
|
+
export declare function decodeAbiTypes(types: readonly AbiType[], data: Uint8Array): unknown[];
|
|
78
|
+
/** Lowercase 0x + 8 hex: the first four bytes of keccak256(signature). */
|
|
79
|
+
export declare function functionSelector(signature: string): string;
|
|
80
|
+
/** Lowercase 0x + 64 hex: keccak256(signature), the log's topic0. */
|
|
81
|
+
export declare function eventTopic(signature: string): string;
|
|
82
|
+
//# sourceMappingURL=abi.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abi.d.ts","sourceRoot":"","sources":["../../../src/eth/abi.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,MAAM,MAAM,OAAO,GACf;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC9B;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GAC7B;IAAE,IAAI,EAAE,SAAS,CAAA;CAAE,GACnB;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAChB;IAAE,IAAI,EAAE,YAAY,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,GACpC;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,GACjB;IAAE,IAAI,EAAE,QAAQ,CAAA;CAAE,GAClB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,OAAO,CAAC;IAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,GACxD;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,UAAU,EAAE,OAAO,EAAE,CAAA;CAAE,CAAC;AAE7C,qBAAa,cAAe,SAAQ,KAAK;gBAC3B,OAAO,EAAE,MAAM;CAI5B;AAoBD;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,GAAG,OAAO,CAU/C;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,OAAO,EAAE,CAAA;CAAE,CAWrF;AAED,iFAAiF;AACjF,wBAAgB,aAAa,CAAC,CAAC,EAAE,OAAO,GAAG,MAAM,CAchD;AA2ED,mFAAmF;AACnF,wBAAgB,SAAS,CAAC,CAAC,EAAE,OAAO,GAAG,OAAO,CAY7C;AAUD;;;;;;;GAOG;AACH,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,IAAI,EAAE,UAAU,GAAG,OAAO,EAAE,CAEzF;AAED,yDAAyD;AACzD,wBAAgB,cAAc,CAAC,KAAK,EAAE,SAAS,OAAO,EAAE,EAAE,IAAI,EAAE,UAAU,GAAG,OAAO,EAAE,CAGrF;AA+ID,0EAA0E;AAC1E,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAE1D;AAED,qEAAqE;AACrE,wBAAgB,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAEpD"}
|
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import { keccak256 } from './keccak.js';
|
|
2
|
+
export class AbiDecodeError extends Error {
|
|
3
|
+
constructor(message) {
|
|
4
|
+
super(message);
|
|
5
|
+
this.name = 'AbiDecodeError';
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
/** Fixed-array lengths above this are refused at parse time: no real ABI
|
|
9
|
+
* uses them, and the head size would overflow any calldata anyway. */
|
|
10
|
+
const MAX_FIXED_ARRAY = 1 << 16;
|
|
11
|
+
/**
|
|
12
|
+
* Nesting depth cap for type strings. Tuple levels AND array suffixes both
|
|
13
|
+
* count: `uint256[1][1]…` nests just as deeply as `((…))`, and every helper
|
|
14
|
+
* that walks a type (isDynamic, headSize, canonicalType, the decoder)
|
|
15
|
+
* recurses once per level.
|
|
16
|
+
*/
|
|
17
|
+
const MAX_TYPE_DEPTH = 32;
|
|
18
|
+
/** Longest type string accepted at all — real signatures are far shorter. */
|
|
19
|
+
const MAX_TYPE_LENGTH = 4096;
|
|
20
|
+
/** A type string for an error message, clipped so a huge input stays small. */
|
|
21
|
+
function show(s) {
|
|
22
|
+
return s.length > 80 ? `${s.slice(0, 80)}…(${s.length} chars)` : s;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Parse a canonical Solidity type string: `uint256`, `int8`, `address`,
|
|
26
|
+
* `bool`, `bytes32`, `bytes`, `string`, `T[k]`, `T[]`, `(T1,T2,…)` and any
|
|
27
|
+
* nesting of those. `uint`/`int` are accepted as aliases for the 256-bit
|
|
28
|
+
* forms. Whitespace is not allowed (canonical signatures have none).
|
|
29
|
+
*/
|
|
30
|
+
export function parseAbiType(t) {
|
|
31
|
+
if (t.length > MAX_TYPE_LENGTH) {
|
|
32
|
+
throw new AbiDecodeError(`ABI type longer than ${MAX_TYPE_LENGTH} chars: "${show(t)}"`);
|
|
33
|
+
}
|
|
34
|
+
const p = { s: t, i: 0 };
|
|
35
|
+
const type = parseTypeAt(p, 0);
|
|
36
|
+
if (p.i !== t.length) {
|
|
37
|
+
throw new AbiDecodeError(`invalid ABI type "${t}": unexpected "${t.slice(p.i)}"`);
|
|
38
|
+
}
|
|
39
|
+
return type;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Parse a function or event signature `name(T1,T2,…)` into its name and
|
|
43
|
+
* parameter types. The name must be a Solidity identifier.
|
|
44
|
+
*/
|
|
45
|
+
export function parseSignature(signature) {
|
|
46
|
+
const open = signature.indexOf('(');
|
|
47
|
+
const name = open === -1 ? '' : signature.slice(0, open);
|
|
48
|
+
if (!/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(name)) {
|
|
49
|
+
throw new AbiDecodeError(`invalid signature "${signature}"`);
|
|
50
|
+
}
|
|
51
|
+
const params = parseAbiType(signature.slice(open));
|
|
52
|
+
if (params.kind !== 'tuple') {
|
|
53
|
+
throw new AbiDecodeError(`invalid signature "${signature}": parameters must be a list`);
|
|
54
|
+
}
|
|
55
|
+
return { name, inputs: params.components };
|
|
56
|
+
}
|
|
57
|
+
/** The canonical string for a parsed type (round-trips through parseAbiType). */
|
|
58
|
+
export function canonicalType(t) {
|
|
59
|
+
switch (t.kind) {
|
|
60
|
+
case 'uint':
|
|
61
|
+
case 'int':
|
|
62
|
+
return `${t.kind}${t.bits}`;
|
|
63
|
+
case 'fixedBytes':
|
|
64
|
+
return `bytes${t.size}`;
|
|
65
|
+
case 'array':
|
|
66
|
+
return `${canonicalType(t.inner)}[${t.length ?? ''}]`;
|
|
67
|
+
case 'tuple':
|
|
68
|
+
return `(${t.components.map(canonicalType).join(',')})`;
|
|
69
|
+
default:
|
|
70
|
+
return t.kind;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
function parseTypeAt(p, depth) {
|
|
74
|
+
if (depth > MAX_TYPE_DEPTH) {
|
|
75
|
+
throw new AbiDecodeError(`ABI type nested too deeply: "${show(p.s)}"`);
|
|
76
|
+
}
|
|
77
|
+
let base;
|
|
78
|
+
if (p.s[p.i] === '(') {
|
|
79
|
+
p.i++;
|
|
80
|
+
const components = [];
|
|
81
|
+
if (p.s[p.i] === ')') {
|
|
82
|
+
p.i++;
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
for (;;) {
|
|
86
|
+
components.push(parseTypeAt(p, depth + 1));
|
|
87
|
+
const c = p.s[p.i];
|
|
88
|
+
p.i++;
|
|
89
|
+
if (c === ')')
|
|
90
|
+
break;
|
|
91
|
+
if (c !== ',')
|
|
92
|
+
throw new AbiDecodeError(`invalid ABI type "${p.s}": expected , or )`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
base = { kind: 'tuple', components };
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
const m = /^[a-z]+[0-9]*/.exec(p.s.slice(p.i));
|
|
99
|
+
if (!m)
|
|
100
|
+
throw new AbiDecodeError(`invalid ABI type "${p.s}"`);
|
|
101
|
+
p.i += m[0].length;
|
|
102
|
+
base = parseElementary(m[0], p.s);
|
|
103
|
+
}
|
|
104
|
+
// Array suffixes, applied left to right: uint256[2][] is a dynamic array
|
|
105
|
+
// of uint256[2].
|
|
106
|
+
while (p.s[p.i] === '[') {
|
|
107
|
+
const close = p.s.indexOf(']', p.i);
|
|
108
|
+
if (close === -1)
|
|
109
|
+
throw new AbiDecodeError(`invalid ABI type "${p.s}": unclosed [`);
|
|
110
|
+
const inner = p.s.slice(p.i + 1, close);
|
|
111
|
+
let length = null;
|
|
112
|
+
if (inner !== '') {
|
|
113
|
+
if (!/^[1-9][0-9]*$/.test(inner) || Number(inner) > MAX_FIXED_ARRAY) {
|
|
114
|
+
throw new AbiDecodeError(`invalid ABI type "${p.s}": bad array length "${inner}"`);
|
|
115
|
+
}
|
|
116
|
+
length = Number(inner);
|
|
117
|
+
}
|
|
118
|
+
base = { kind: 'array', inner: base, length };
|
|
119
|
+
p.i = close + 1;
|
|
120
|
+
if (++depth > MAX_TYPE_DEPTH) {
|
|
121
|
+
throw new AbiDecodeError(`ABI type nested too deeply: "${show(p.s)}"`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return base;
|
|
125
|
+
}
|
|
126
|
+
function parseElementary(name, whole) {
|
|
127
|
+
if (name === 'address')
|
|
128
|
+
return { kind: 'address' };
|
|
129
|
+
if (name === 'bool')
|
|
130
|
+
return { kind: 'bool' };
|
|
131
|
+
if (name === 'string')
|
|
132
|
+
return { kind: 'string' };
|
|
133
|
+
if (name === 'bytes')
|
|
134
|
+
return { kind: 'bytes' };
|
|
135
|
+
if (name === 'uint' || name === 'int')
|
|
136
|
+
return { kind: name, bits: 256 };
|
|
137
|
+
let m = /^(u?int)([0-9]+)$/.exec(name);
|
|
138
|
+
if (m) {
|
|
139
|
+
const bits = Number(m[2]);
|
|
140
|
+
if (bits < 8 || bits > 256 || bits % 8 !== 0 || String(bits) !== m[2]) {
|
|
141
|
+
throw new AbiDecodeError(`invalid ABI type "${whole}": bad integer width ${m[2]}`);
|
|
142
|
+
}
|
|
143
|
+
return { kind: m[1], bits };
|
|
144
|
+
}
|
|
145
|
+
m = /^bytes([0-9]+)$/.exec(name);
|
|
146
|
+
if (m) {
|
|
147
|
+
const size = Number(m[1]);
|
|
148
|
+
if (size < 1 || size > 32 || String(size) !== m[1]) {
|
|
149
|
+
throw new AbiDecodeError(`invalid ABI type "${whole}": bad bytes width ${m[1]}`);
|
|
150
|
+
}
|
|
151
|
+
return { kind: 'fixedBytes', size };
|
|
152
|
+
}
|
|
153
|
+
throw new AbiDecodeError(`unsupported ABI type "${name}" in "${whole}"`);
|
|
154
|
+
}
|
|
155
|
+
/** True when the type's encoding lives in the tail (has an offset in the head). */
|
|
156
|
+
export function isDynamic(t) {
|
|
157
|
+
switch (t.kind) {
|
|
158
|
+
case 'bytes':
|
|
159
|
+
case 'string':
|
|
160
|
+
return true;
|
|
161
|
+
case 'array':
|
|
162
|
+
return t.length === null || isDynamic(t.inner);
|
|
163
|
+
case 'tuple':
|
|
164
|
+
return t.components.some(isDynamic);
|
|
165
|
+
default:
|
|
166
|
+
return false;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
/** Bytes the type occupies in its enclosing head. */
|
|
170
|
+
function headSize(t) {
|
|
171
|
+
if (isDynamic(t))
|
|
172
|
+
return 32;
|
|
173
|
+
if (t.kind === 'array')
|
|
174
|
+
return t.length * headSize(t.inner);
|
|
175
|
+
if (t.kind === 'tuple')
|
|
176
|
+
return t.components.reduce((n, c) => n + headSize(c), 0);
|
|
177
|
+
return 32;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Decode `data` as the ABI encoding of a parameter list. Values:
|
|
181
|
+
* uint/int → bigint (two's complement for int), address → lowercase 0x
|
|
182
|
+
* hex, bool → boolean, bytesN/bytes → lowercase 0x hex, string → string
|
|
183
|
+
* (UTF-8, invalid sequences replaced), arrays and tuples → unknown[].
|
|
184
|
+
* Trailing bytes after the encoding are tolerated (calldata commonly carries
|
|
185
|
+
* them); everything the types reference must be in bounds.
|
|
186
|
+
*/
|
|
187
|
+
export function decodeAbiParameters(types, data) {
|
|
188
|
+
return decodeAbiTypes(types.map(parseAbiType), data);
|
|
189
|
+
}
|
|
190
|
+
/** Same as decodeAbiParameters, for pre-parsed types. */
|
|
191
|
+
export function decodeAbiTypes(types, data) {
|
|
192
|
+
const budget = { left: data.length * 4 + 4096 };
|
|
193
|
+
return decodeTuple(types, data, 0, budget, 0);
|
|
194
|
+
}
|
|
195
|
+
function spend(budget, n) {
|
|
196
|
+
budget.left -= n;
|
|
197
|
+
if (budget.left < 0) {
|
|
198
|
+
throw new AbiDecodeError('decoded output exceeds budget (aliased offsets?)');
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
function word(data, pos) {
|
|
202
|
+
if (pos < 0 || pos + 32 > data.length) {
|
|
203
|
+
throw new AbiDecodeError(`read of 32 bytes at ${pos} past end of ${data.length}-byte data`);
|
|
204
|
+
}
|
|
205
|
+
return data.subarray(pos, pos + 32);
|
|
206
|
+
}
|
|
207
|
+
function wordToBigint(w) {
|
|
208
|
+
let hex = '';
|
|
209
|
+
for (let i = 0; i < w.length; i++)
|
|
210
|
+
hex += w[i].toString(16).padStart(2, '0');
|
|
211
|
+
return hex === '' ? 0n : BigInt('0x' + hex);
|
|
212
|
+
}
|
|
213
|
+
/** Read a word as an offset/length; must fit comfortably within the data. */
|
|
214
|
+
function readSize(data, pos, what) {
|
|
215
|
+
const v = wordToBigint(word(data, pos));
|
|
216
|
+
if (v > BigInt(data.length)) {
|
|
217
|
+
throw new AbiDecodeError(`${what} ${v} at ${pos} exceeds ${data.length}-byte data`);
|
|
218
|
+
}
|
|
219
|
+
return Number(v);
|
|
220
|
+
}
|
|
221
|
+
function toHex(b) {
|
|
222
|
+
return '0x' + Buffer.from(b.buffer, b.byteOffset, b.byteLength).toString('hex');
|
|
223
|
+
}
|
|
224
|
+
function decodeTuple(types, data, base, budget, depth) {
|
|
225
|
+
if (depth > MAX_TYPE_DEPTH)
|
|
226
|
+
throw new AbiDecodeError('ABI value nested too deeply');
|
|
227
|
+
const out = [];
|
|
228
|
+
let head = base;
|
|
229
|
+
for (const t of types) {
|
|
230
|
+
if (isDynamic(t)) {
|
|
231
|
+
const off = readSize(data, head, 'offset');
|
|
232
|
+
const at = base + off;
|
|
233
|
+
if (at >= data.length) {
|
|
234
|
+
throw new AbiDecodeError(`offset ${off} (from ${base}) points past end of data`);
|
|
235
|
+
}
|
|
236
|
+
out.push(decodeAt(t, data, at, budget, depth));
|
|
237
|
+
}
|
|
238
|
+
else {
|
|
239
|
+
out.push(decodeAt(t, data, head, budget, depth));
|
|
240
|
+
}
|
|
241
|
+
head += headSize(t);
|
|
242
|
+
}
|
|
243
|
+
return out;
|
|
244
|
+
}
|
|
245
|
+
function decodeAt(t, data, pos, budget, depth) {
|
|
246
|
+
spend(budget, 32);
|
|
247
|
+
switch (t.kind) {
|
|
248
|
+
case 'uint': {
|
|
249
|
+
const v = wordToBigint(word(data, pos));
|
|
250
|
+
if (t.bits < 256 && v >> BigInt(t.bits) !== 0n) {
|
|
251
|
+
throw new AbiDecodeError(`uint${t.bits} at ${pos} has non-zero high bits`);
|
|
252
|
+
}
|
|
253
|
+
return v;
|
|
254
|
+
}
|
|
255
|
+
case 'int': {
|
|
256
|
+
const raw = wordToBigint(word(data, pos));
|
|
257
|
+
const v = raw >= 1n << 255n ? raw - (1n << 256n) : raw;
|
|
258
|
+
const lim = 1n << BigInt(t.bits - 1);
|
|
259
|
+
if (v < -lim || v >= lim) {
|
|
260
|
+
throw new AbiDecodeError(`int${t.bits} at ${pos} is not canonically sign-extended`);
|
|
261
|
+
}
|
|
262
|
+
return v;
|
|
263
|
+
}
|
|
264
|
+
case 'address': {
|
|
265
|
+
const w = word(data, pos);
|
|
266
|
+
for (let i = 0; i < 12; i++) {
|
|
267
|
+
if (w[i] !== 0)
|
|
268
|
+
throw new AbiDecodeError(`address at ${pos} has a dirty upper word`);
|
|
269
|
+
}
|
|
270
|
+
return toHex(w.subarray(12));
|
|
271
|
+
}
|
|
272
|
+
case 'bool': {
|
|
273
|
+
const v = wordToBigint(word(data, pos));
|
|
274
|
+
if (v > 1n)
|
|
275
|
+
throw new AbiDecodeError(`bool at ${pos} is ${v}, not 0 or 1`);
|
|
276
|
+
return v === 1n;
|
|
277
|
+
}
|
|
278
|
+
case 'fixedBytes': {
|
|
279
|
+
const w = word(data, pos);
|
|
280
|
+
for (let i = t.size; i < 32; i++) {
|
|
281
|
+
if (w[i] !== 0)
|
|
282
|
+
throw new AbiDecodeError(`bytes${t.size} at ${pos} has non-zero padding`);
|
|
283
|
+
}
|
|
284
|
+
return toHex(w.subarray(0, t.size));
|
|
285
|
+
}
|
|
286
|
+
case 'bytes':
|
|
287
|
+
case 'string': {
|
|
288
|
+
const len = readSize(data, pos, 'length');
|
|
289
|
+
const start = pos + 32;
|
|
290
|
+
if (start + len > data.length) {
|
|
291
|
+
throw new AbiDecodeError(`${t.kind} of ${len} bytes at ${pos} runs past end of data`);
|
|
292
|
+
}
|
|
293
|
+
spend(budget, len);
|
|
294
|
+
const raw = data.subarray(start, start + len);
|
|
295
|
+
return t.kind === 'bytes' ? toHex(raw) : new TextDecoder('utf-8').decode(raw);
|
|
296
|
+
}
|
|
297
|
+
case 'array': {
|
|
298
|
+
let length;
|
|
299
|
+
let base;
|
|
300
|
+
if (t.length === null) {
|
|
301
|
+
length = readSize(data, pos, 'array length');
|
|
302
|
+
base = pos + 32;
|
|
303
|
+
}
|
|
304
|
+
else {
|
|
305
|
+
length = t.length;
|
|
306
|
+
base = pos;
|
|
307
|
+
}
|
|
308
|
+
// Each element occupies at least one head word; refuse lengths the
|
|
309
|
+
// remaining data cannot possibly hold before allocating anything.
|
|
310
|
+
const elemHead = headSize(t.inner);
|
|
311
|
+
if (base + length * elemHead > data.length) {
|
|
312
|
+
throw new AbiDecodeError(`array of ${length} at ${pos} runs past end of data`);
|
|
313
|
+
}
|
|
314
|
+
return decodeTuple(new Array(length).fill(t.inner), data, base, budget, depth + 1);
|
|
315
|
+
}
|
|
316
|
+
case 'tuple':
|
|
317
|
+
return decodeTuple(t.components, data, pos, budget, depth + 1);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
/** Lowercase 0x + 8 hex: the first four bytes of keccak256(signature). */
|
|
321
|
+
export function functionSelector(signature) {
|
|
322
|
+
return '0x' + keccak256(Buffer.from(signature, 'utf8')).subarray(0, 4).toString('hex');
|
|
323
|
+
}
|
|
324
|
+
/** Lowercase 0x + 64 hex: keccak256(signature), the log's topic0. */
|
|
325
|
+
export function eventTopic(signature) {
|
|
326
|
+
return '0x' + keccak256(Buffer.from(signature, 'utf8')).toString('hex');
|
|
327
|
+
}
|
|
328
|
+
//# sourceMappingURL=abi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abi.js","sourceRoot":"","sources":["../../../src/eth/abi.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAiCxC,MAAM,OAAO,cAAe,SAAQ,KAAK;IACvC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,gBAAgB,CAAC;IAC/B,CAAC;CACF;AAED;uEACuE;AACvE,MAAM,eAAe,GAAG,CAAC,IAAI,EAAE,CAAC;AAChC;;;;;GAKG;AACH,MAAM,cAAc,GAAG,EAAE,CAAC;AAC1B,6EAA6E;AAC7E,MAAM,eAAe,GAAG,IAAI,CAAC;AAE7B,+EAA+E;AAC/E,SAAS,IAAI,CAAC,CAAS;IACrB,OAAO,CAAC,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,CAAC,MAAM,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC;AACrE,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,CAAS;IACpC,IAAI,CAAC,CA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AC,CAAC,CAAC;IACnE,CAAC;AACH,CAAC;AAED,0EAA0E;AAC1E,MAAM,UAAU,gBAAgB,CAAC,SAAiB;IAChD,OAAO,IAAI,GAAG,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACzF,CAAC;AAED,qEAAqE;AACrE,MAAM,UAAU,UAAU,CAAC,SAAiB;IAC1C,OAAO,IAAI,GAAG,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AAC1E,CAAC"}
|
package/dist/src/eth/index.d.ts
CHANGED
|
@@ -5,4 +5,5 @@ export { type RlpInput, rlpEncode, rlpDecode, encodeInt } from './rlp.js';
|
|
|
5
5
|
export { personalSign, personalSignDigest, serializeEthSignature, deserializeEthSignature, } from './sign-message.js';
|
|
6
6
|
export { type Hex, type LegacyTx, type Eip1559Tx, type SignableTx, type AccessListItem, txDigest, signTransaction, } from './sign-tx.js';
|
|
7
7
|
export { type TypedData, type TypedDataDomain, type TypedDataField, type TypedDataTypes, encodeType, typeHash, hashStruct, typedDataDigest, signTypedData, } from './sign-typed.js';
|
|
8
|
+
export { type AbiType, AbiDecodeError, parseAbiType, parseSignature, canonicalType, isDynamic, decodeAbiParameters, decodeAbiTypes, functionSelector, eventTopic, } from './abi.js';
|
|
8
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/eth/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EACL,KAAK,YAAY,EACjB,wBAAwB,EACxB,eAAe,EACf,UAAU,EACV,gBAAgB,GACjB,MAAM,WAAW,CAAC;AAC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ACL,KAAK,SAAS,EACd,KAAK,eAAe,EACpB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,UAAU,EACV,QAAQ,EACR,UAAU,EACV,eAAe,EACf,aAAa,GACd,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,KAAK,OAAO,EACZ,cAAc,EACd,YAAY,EACZ,cAAc,EACd,aAAa,EACb,SAAS,EACT,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,UAAU,GACX,MAAM,UAAU,CAAC"}
|
package/dist/src/eth/index.js
CHANGED
|
@@ -5,4 +5,5 @@ export { rlpEncode, rlpDecode, encodeInt } from './rlp.js';
|
|
|
5
5
|
export { personalSign, personalSignDigest, serializeEthSignature, deserializeEthSignature, } from './sign-message.js';
|
|
6
6
|
export { txDigest, signTransaction, } from './sign-tx.js';
|
|
7
7
|
export { encodeType, typeHash, hashStruct, typedDataDigest, signTypedData, } from './sign-typed.js';
|
|
8
|
+
export { AbiDecodeError, parseAbiType, parseSignature, canonicalType, isDynamic, decodeAbiParameters, decodeAbiTypes, functionSelector, eventTopic, } from './abi.js';
|
|
8
9
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/eth/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAEL,wBAAwB,EACxB,eAAe,EACf,UAAU,EACV,gBAAgB,GACjB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAC9F,OAAO,EAAiB,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAC1E,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,qBAAqB,EACrB,uBAAuB,GACxB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAML,QAAQ,EACR,eAAe,GAChB,MAAM,cAAc,CAAC;AACtB,OAAO,EAKL,UAAU,EACV,QAAQ,EACR,UAAU,EACV,eAAe,EACf,aAAa,GACd,MAAM,iBAAiB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/eth/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAEL,wBAAwB,EACxB,eAAe,EACf,UAAU,EACV,gBAAgB,GACjB,MAAM,WAAW,CAAC;AACnB,OAAO,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAC9F,OAAO,EAAiB,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAC1E,OAAO,EACL,YAAY,EACZ,kBAAkB,EAClB,qBAAqB,EACrB,uBAAuB,GACxB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAML,QAAQ,EACR,eAAe,GAChB,MAAM,cAAc,CAAC;AACtB,OAAO,EAKL,UAAU,EACV,QAAQ,EACR,UAAU,EACV,eAAe,EACf,aAAa,GACd,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAEL,cAAc,EACd,YAAY,EACZ,cAAc,EACd,aAAa,EACb,SAAS,EACT,mBAAmB,EACnB,cAAc,EACd,gBAAgB,EAChB,UAAU,GACX,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fs/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,kBAAkB,EACvB,cAAc,EACd,aAAa,EACb,eAAe,EACf,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,YAAY,GACb,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/fs/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,cAAc,EACd,aAAa,EACb,eAAe,EACf,WAAW,EACX,gBAAgB,EAChB,YAAY,EACZ,YAAY,GACb,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cross-process mutex for the files several `sigil-mcp` instances append
|
|
3
|
+
* to concurrently (one per Claude window: the audit log, the per-portal
|
|
4
|
+
* spend ledgers). Node core has no flock(2) and sigil takes no native
|
|
5
|
+
* deps, so this is built from two atomic filesystem operations only:
|
|
6
|
+
* exclusive create and unlink of a process's *own* files.
|
|
7
|
+
*
|
|
8
|
+
* It is Lamport's bakery algorithm on a directory:
|
|
9
|
+
*
|
|
10
|
+
* 1. create c-<pid>-<token> "I am choosing a number"
|
|
11
|
+
* 2. read the directory; my number is 1 + the largest ticket number
|
|
12
|
+
* 3. create t-<number>-<pid>-<token> my ticket
|
|
13
|
+
* 4. unlink c-<pid>-<token>
|
|
14
|
+
* 5. wait until no other live process is choosing, and no other live
|
|
15
|
+
* process holds a ticket ordered before mine (number, pid, token)
|
|
16
|
+
* 6. critical section
|
|
17
|
+
* 7. unlink my ticket
|
|
18
|
+
*
|
|
19
|
+
* Why this and not a single lock file: with one file, recovering from a
|
|
20
|
+
* holder that died means deleting a path some other process may just
|
|
21
|
+
* have re-created, and every "check, then unlink" sequence is a race —
|
|
22
|
+
* in the lock, and again in any sidecar used to serialise the breaking.
|
|
23
|
+
* Here no process ever unlinks a live process's file. Tickets of dead
|
|
24
|
+
* pids are simply ignored (and swept, which is safe because their owner
|
|
25
|
+
* cannot act), so a crashed holder costs nothing and there is nothing to
|
|
26
|
+
* "break". Correctness needs only that a file present for the whole of a
|
|
27
|
+
* readdir is listed, which every filesystem gives.
|
|
28
|
+
*
|
|
29
|
+
* A process also recognises files carrying its own pid that no live
|
|
30
|
+
* acquisition in it holds: an orphan of its own (a release that failed)
|
|
31
|
+
* or a dead predecessor that had this pid. Both are swept.
|
|
32
|
+
*
|
|
33
|
+
* Residual gap, documented rather than hidden: pid reuse across
|
|
34
|
+
* *different* processes. A dead holder whose pid was recycled by an
|
|
35
|
+
* unrelated live process looks alive, and its ticket blocks everyone
|
|
36
|
+
* until that process exits or a human removes the file. That is an
|
|
37
|
+
* availability limit, not an exclusion failure; closing it needs OS-level
|
|
38
|
+
* locking.
|
|
39
|
+
*
|
|
40
|
+
* Upgrading: a daemon built before this change locks a single file
|
|
41
|
+
* `<target>.lock` and knows nothing of this directory, and its writer also
|
|
42
|
+
* has a currency check that a fresh chain can fool. Running old and new
|
|
43
|
+
* daemons against one log is therefore unsupported, and no bridge here can
|
|
44
|
+
* make it safe. This is not a new requirement: a running sigil-mcp never
|
|
45
|
+
* reloads code, so every Claude window must restart its sigil-mcp after any
|
|
46
|
+
* upgrade anyway (see README, "Multi-window behaviour").
|
|
47
|
+
*/
|
|
48
|
+
export declare class FileLockError extends Error {
|
|
49
|
+
constructor(msg: string);
|
|
50
|
+
}
|
|
51
|
+
/** @deprecated alias kept for the audit module's public surface. */
|
|
52
|
+
export declare const AuditLockError: typeof FileLockError;
|
|
53
|
+
export interface AcquireLockOptions {
|
|
54
|
+
timeoutMs?: number;
|
|
55
|
+
pollMs?: number;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Test-only seams. `afterTicket` runs once our ticket exists (before the
|
|
59
|
+
* choosing marker is withdrawn); `betweenScans` runs between the marker
|
|
60
|
+
* scan and the ticket scan of each admission check. Either may throw to
|
|
61
|
+
* simulate a failure at that point. Never set by production code.
|
|
62
|
+
*/
|
|
63
|
+
export declare const _testHooks: {
|
|
64
|
+
afterTicket?: (lockDir: string) => void;
|
|
65
|
+
betweenScans?: (lockDir: string) => void;
|
|
66
|
+
};
|
|
67
|
+
export declare function writeAllSync(fd: number, data: string): void;
|
|
68
|
+
/**
|
|
69
|
+
* Acquire an exclusive cross-process lock over `lockDir` (created if
|
|
70
|
+
* absent). Returns an idempotent, retryable release function. Throws
|
|
71
|
+
* FileLockError if the lock cannot be acquired within `timeoutMs`. Any
|
|
72
|
+
* failure to acquire — timeout or error — withdraws our files first.
|
|
73
|
+
*/
|
|
74
|
+
export declare function acquireLockSync(lockDir: string, opts?: AcquireLockOptions): () => void;
|
|
75
|
+
/** Sidecar lock directory for a data file: `<target>.lock.d`. */
|
|
76
|
+
export declare function lockPathFor(target: string): string;
|
|
77
|
+
/**
|
|
78
|
+
* Run `fn` while holding the sidecar lock for `target`. Synchronous by
|
|
79
|
+
* design (callers are synchronous append paths) and therefore not
|
|
80
|
+
* re-entrant: a nested acquire of the same target times out.
|
|
81
|
+
*/
|
|
82
|
+
export declare function withFileLock<T>(target: string, fn: () => T, opts?: AcquireLockOptions): T;
|
|
83
|
+
export declare function releaseWithRetry(release: () => void, lockDir: string): void;
|
|
84
|
+
//# sourceMappingURL=lock.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lock.d.ts","sourceRoot":"","sources":["../../../src/fs/lock.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,qBAAa,aAAc,SAAQ,KAAK;gBAC1B,GAAG,EAAE,MAAM;CAIxB;AACD,oEAAoE;AACpE,eAAO,MAAM,cAAc,sBAAgB,CAAC;AAE5C,MAAM,WAAW,kBAAkB;IACjC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAKD;;;;;GAKG;AACH,eAAO,MAAM,UAAU,EAAE;IACvB,WAAW,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;IACxC,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CACrC,CAAC;AAaP,wBAAgB,YAAY,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAQ3D;AAmHD;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,kBAAuB,GAAG,MAAM,IAAI,CA+E1F;AAED,iEAAiE;AACjE,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAElD;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,IAAI,GAAE,kBAAuB,GAAG,CAAC,CAQ7F;AAaD,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,IAAI,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAgB3E"}
|