sigild 0.0.12 → 0.0.13
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 +15 -2
- package/THREAT_MODEL.md +2 -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 +37 -3
- package/dist/src/audit/log.d.ts.map +1 -1
- package/dist/src/audit/log.js +224 -40
- package/dist/src/audit/log.js.map +1 -1
- package/dist/src/bin/sigil-mcp.js +11 -2
- 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 +2 -0
- package/dist/src/cli/paths.d.ts.map +1 -1
- package/dist/src/cli/paths.js +1 -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/daemon/methods.d.ts +8 -1
- package/dist/src/daemon/methods.d.ts.map +1 -1
- package/dist/src/daemon/methods.js +121 -7
- package/dist/src/daemon/methods.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/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 +83 -0
- package/dist/src/policy/ledger.d.ts.map +1 -0
- package/dist/src/policy/ledger.js +250 -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 +45 -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 +32 -0
- package/dist/src/policy/template.js.map +1 -1
- package/dist/src/policy/types.d.ts +26 -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/package.json +5 -5
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { closeSync, fsyncSync, mkdirSync, openSync, readFileSync, renameSync } from 'node:fs';
|
|
2
|
+
import { dirname, join } from 'node:path';
|
|
3
|
+
import { withFileLock, writeAllSync } from '../fs/index.js';
|
|
4
|
+
import { checkWindowCaps, DAY_MS } from './window.js';
|
|
5
|
+
export class SpendLedgerError extends Error {
|
|
6
|
+
constructor(message) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = 'SpendLedgerError';
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
/** A negative spend is a caller bug, never a credit: refuse without touching the file. */
|
|
12
|
+
const NEGATIVE_REASON = 'denied — negative amount is not a valid spend';
|
|
13
|
+
function sumWindow(entries, asset, windowMs, now) {
|
|
14
|
+
const floor = now - windowMs;
|
|
15
|
+
let total = 0n;
|
|
16
|
+
for (const e of entries) {
|
|
17
|
+
if (e.asset === asset && e.ts > floor)
|
|
18
|
+
total += e.amount;
|
|
19
|
+
}
|
|
20
|
+
return total;
|
|
21
|
+
}
|
|
22
|
+
/** In-memory ledger for tests and for callers that don't persist. */
|
|
23
|
+
export class MemorySpendLedger {
|
|
24
|
+
#entries = new Map();
|
|
25
|
+
#now;
|
|
26
|
+
constructor(opts = {}) {
|
|
27
|
+
this.#now = opts.now ?? (() => Date.now());
|
|
28
|
+
}
|
|
29
|
+
#for(handle) {
|
|
30
|
+
let list = this.#entries.get(handle);
|
|
31
|
+
if (!list) {
|
|
32
|
+
list = [];
|
|
33
|
+
this.#entries.set(handle, list);
|
|
34
|
+
}
|
|
35
|
+
return list;
|
|
36
|
+
}
|
|
37
|
+
spent(handle, asset, windowMs) {
|
|
38
|
+
return sumWindow(this.#for(handle), asset, windowMs, this.#now());
|
|
39
|
+
}
|
|
40
|
+
reserve(handle, asset, amount, caps) {
|
|
41
|
+
if (amount < 0n)
|
|
42
|
+
return NEGATIVE_REASON;
|
|
43
|
+
const list = this.#for(handle);
|
|
44
|
+
const now = this.#now();
|
|
45
|
+
const reason = checkWindowCaps(caps, amount, (w) => sumWindow(list, asset, w, now), asset);
|
|
46
|
+
if (reason !== null)
|
|
47
|
+
return reason;
|
|
48
|
+
if (amount > 0n)
|
|
49
|
+
list.push({ ts: now, asset, amount });
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* File-backed ledger: one append-only JSONL file per portal at
|
|
55
|
+
* `<stateDir>/<handle>.ledger`, lines of `{"ts":…,"asset":"wei","amount":"…"}`.
|
|
56
|
+
*
|
|
57
|
+
* Every read and write runs under the cross-process file lock, the clock is
|
|
58
|
+
* sampled inside it, and each `reserve` re-reads the file before deciding,
|
|
59
|
+
* so the decision is always made against the union of every window's
|
|
60
|
+
* spends.
|
|
61
|
+
*
|
|
62
|
+
* Integrity is fail-closed: a line that does not parse makes every reserve
|
|
63
|
+
* for that portal deny with a message naming the file, until a human fixes
|
|
64
|
+
* or removes it. Skipping bad lines would silently loosen the cap, which is
|
|
65
|
+
* the one thing a rate limit must not do. A crash can leave a torn final
|
|
66
|
+
* line (writes are complete and fsynced, so only power loss does this); the
|
|
67
|
+
* next append starts on a fresh line so the torn fragment stays isolated —
|
|
68
|
+
* and still trips the check, on purpose.
|
|
69
|
+
*
|
|
70
|
+
* Entries older than the longest window sigil supports (24h) can never
|
|
71
|
+
* influence a decision again; when more than COMPACT_AFTER of them have
|
|
72
|
+
* piled up the file is rewritten (tmp + fsync + rename + directory fsync,
|
|
73
|
+
* under the same lock) with only the live tail. Entries dated in the future
|
|
74
|
+
* are always kept.
|
|
75
|
+
*
|
|
76
|
+
* Threat model: an attacker who can delete or rewrite this file can also
|
|
77
|
+
* rewrite the policy file beside it and remove the cap outright, so the
|
|
78
|
+
* ledger earns no extra protection beyond its 0600 mode inside the 0700
|
|
79
|
+
* sigil home; a missing file is an empty ledger. What it does defend
|
|
80
|
+
* against is the prompt-injected *agent*, which never touches the
|
|
81
|
+
* filesystem directly. The hash-chained audit log is the record.
|
|
82
|
+
*/
|
|
83
|
+
export class FileSpendLedger {
|
|
84
|
+
static COMPACT_AFTER = 256;
|
|
85
|
+
#dir;
|
|
86
|
+
#now;
|
|
87
|
+
constructor(stateDir, opts = {}) {
|
|
88
|
+
this.#dir = stateDir;
|
|
89
|
+
this.#now = opts.now ?? (() => Date.now());
|
|
90
|
+
}
|
|
91
|
+
pathFor(handle) {
|
|
92
|
+
return join(this.#dir, `${handle}.ledger`);
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Create the state dir and make its directory entry durable. Not cached:
|
|
96
|
+
* a sync that failed must not be remembered as done, and a reservation
|
|
97
|
+
* from another daemon must not mistake the directory's existence for
|
|
98
|
+
* established durability. One mkdir + one fsync per reserve is cheap.
|
|
99
|
+
*/
|
|
100
|
+
#ensureDir() {
|
|
101
|
+
mkdirSync(this.#dir, { recursive: true, mode: 0o700 });
|
|
102
|
+
fsyncDirOrFail(dirname(this.#dir));
|
|
103
|
+
}
|
|
104
|
+
spent(handle, asset, windowMs) {
|
|
105
|
+
const path = this.pathFor(handle);
|
|
106
|
+
mkdirSync(this.#dir, { recursive: true, mode: 0o700 });
|
|
107
|
+
return withFileLock(path, () => sumWindow(readEntries(path).entries, asset, windowMs, this.#now()));
|
|
108
|
+
}
|
|
109
|
+
reserve(handle, asset, amount, caps) {
|
|
110
|
+
if (amount < 0n)
|
|
111
|
+
return NEGATIVE_REASON;
|
|
112
|
+
this.#ensureDir();
|
|
113
|
+
const path = this.pathFor(handle);
|
|
114
|
+
return withFileLock(path, () => {
|
|
115
|
+
const { entries, endsWithNewline, size } = readEntries(path);
|
|
116
|
+
const now = this.#now();
|
|
117
|
+
const reason = checkWindowCaps(caps, amount, (w) => sumWindow(entries, asset, w, now), asset);
|
|
118
|
+
if (reason !== null)
|
|
119
|
+
return reason;
|
|
120
|
+
if (amount === 0n)
|
|
121
|
+
return null;
|
|
122
|
+
const entry = { ts: now, asset, amount };
|
|
123
|
+
const stale = entries.filter((e) => e.ts <= now - DAY_MS).length;
|
|
124
|
+
if (stale > FileSpendLedger.COMPACT_AFTER) {
|
|
125
|
+
const live = entries.filter((e) => e.ts > now - DAY_MS);
|
|
126
|
+
live.push(entry);
|
|
127
|
+
const tmp = `${path}.tmp`;
|
|
128
|
+
const fd = openSync(tmp, 'w', 0o600);
|
|
129
|
+
try {
|
|
130
|
+
writeAllSync(fd, live.map(serialize).join(''));
|
|
131
|
+
fsyncSync(fd);
|
|
132
|
+
}
|
|
133
|
+
finally {
|
|
134
|
+
closeSync(fd);
|
|
135
|
+
}
|
|
136
|
+
renameSync(tmp, path);
|
|
137
|
+
fsyncDirOrFail(dirname(path));
|
|
138
|
+
}
|
|
139
|
+
else {
|
|
140
|
+
const fd = openSync(path, 'a', 0o600);
|
|
141
|
+
try {
|
|
142
|
+
// Never merge with a torn fragment: start on a fresh line.
|
|
143
|
+
writeAllSync(fd, (size > 0 && !endsWithNewline ? '\n' : '') + serialize(entry));
|
|
144
|
+
fsyncSync(fd);
|
|
145
|
+
}
|
|
146
|
+
finally {
|
|
147
|
+
closeSync(fd);
|
|
148
|
+
}
|
|
149
|
+
// The directory entry needs its own fsync, or a power cut right after
|
|
150
|
+
// a signature can lose a brand-new ledger and hand back a fresh
|
|
151
|
+
// allowance on reboot. Done on every append rather than only the
|
|
152
|
+
// first: if a previous attempt's sync failed, the file's mere
|
|
153
|
+
// existence proves nothing about durability.
|
|
154
|
+
fsyncDirOrFail(dirname(path));
|
|
155
|
+
}
|
|
156
|
+
return null;
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Test-only seam: replaces the directory fsync so a test can make it fail.
|
|
162
|
+
* Never set by production code.
|
|
163
|
+
*/
|
|
164
|
+
export const _ledgerTestHooks = {};
|
|
165
|
+
/**
|
|
166
|
+
* fsync a directory, converting any failure into a SpendLedgerError. The
|
|
167
|
+
* spend may already be on disk at this point; refusing to sign then errs
|
|
168
|
+
* on the side of over-counting, never under-counting. Nothing is swallowed:
|
|
169
|
+
* a filesystem that can't confirm durability can't back a rate limit.
|
|
170
|
+
*/
|
|
171
|
+
function fsyncDirOrFail(dir) {
|
|
172
|
+
try {
|
|
173
|
+
if (_ledgerTestHooks.fsyncDir) {
|
|
174
|
+
_ledgerTestHooks.fsyncDir(dir);
|
|
175
|
+
return;
|
|
176
|
+
}
|
|
177
|
+
const fd = openSync(dir, 'r');
|
|
178
|
+
try {
|
|
179
|
+
fsyncSync(fd);
|
|
180
|
+
}
|
|
181
|
+
finally {
|
|
182
|
+
closeSync(fd);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
catch (err) {
|
|
186
|
+
throw new SpendLedgerError(`spend ledger: could not make ${dir} durable (${err.message}) — refusing to sign`);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
function serialize(e) {
|
|
190
|
+
return JSON.stringify({ ts: e.ts, asset: e.asset, amount: e.amount.toString() }) + '\n';
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Parse the ledger. Any line that does not parse — including a torn final
|
|
194
|
+
* line — throws SpendLedgerError naming the file: the cap cannot be
|
|
195
|
+
* evaluated against unknown history, so every reserve denies until a human
|
|
196
|
+
* repairs or removes the file. A missing file is an empty ledger.
|
|
197
|
+
*/
|
|
198
|
+
function readEntries(path) {
|
|
199
|
+
let text;
|
|
200
|
+
try {
|
|
201
|
+
text = readFileSync(path, 'utf8');
|
|
202
|
+
}
|
|
203
|
+
catch (err) {
|
|
204
|
+
if (err.code === 'ENOENT') {
|
|
205
|
+
return { entries: [], endsWithNewline: true, size: 0 };
|
|
206
|
+
}
|
|
207
|
+
throw err;
|
|
208
|
+
}
|
|
209
|
+
const out = [];
|
|
210
|
+
const lines = text.split('\n');
|
|
211
|
+
const endsWithNewline = text === '' || text.endsWith('\n');
|
|
212
|
+
for (let i = 0; i < lines.length; i++) {
|
|
213
|
+
const line = lines[i];
|
|
214
|
+
if (line === '') {
|
|
215
|
+
// Blank lines (the split's trailing empty string, or a separator we
|
|
216
|
+
// wrote to isolate a torn fragment) carry no information.
|
|
217
|
+
continue;
|
|
218
|
+
}
|
|
219
|
+
const e = parseEntry(line);
|
|
220
|
+
if (!e) {
|
|
221
|
+
throw new SpendLedgerError(`spend ledger ${path} has an unreadable line ${i + 1} — refusing to sign against ` +
|
|
222
|
+
`unknown history; inspect and repair or remove the file (this resets the allowance)`);
|
|
223
|
+
}
|
|
224
|
+
out.push(e);
|
|
225
|
+
}
|
|
226
|
+
return { entries: out, endsWithNewline, size: Buffer.byteLength(text, 'utf8') };
|
|
227
|
+
}
|
|
228
|
+
function parseEntry(line) {
|
|
229
|
+
let obj;
|
|
230
|
+
try {
|
|
231
|
+
obj = JSON.parse(line);
|
|
232
|
+
}
|
|
233
|
+
catch {
|
|
234
|
+
return null;
|
|
235
|
+
}
|
|
236
|
+
if (typeof obj !== 'object' || obj === null)
|
|
237
|
+
return null;
|
|
238
|
+
const r = obj;
|
|
239
|
+
const ts = r['ts'];
|
|
240
|
+
const asset = r['asset'];
|
|
241
|
+
const amount = r['amount'];
|
|
242
|
+
if (typeof ts !== 'number' || !Number.isFinite(ts))
|
|
243
|
+
return null;
|
|
244
|
+
if (asset !== 'wei' && asset !== 'lamports')
|
|
245
|
+
return null;
|
|
246
|
+
if (typeof amount !== 'string' || !/^[0-9]+$/.test(amount))
|
|
247
|
+
return null;
|
|
248
|
+
return { ts, asset, amount: BigInt(amount) };
|
|
249
|
+
}
|
|
250
|
+
//# sourceMappingURL=ledger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ledger.js","sourceRoot":"","sources":["../../../src/policy/ledger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC9F,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EAAE,eAAe,EAAE,MAAM,EAAmC,MAAM,aAAa,CAAC;AA8BvF,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACzC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACjC,CAAC;CACF;AAED,0FAA0F;AAC1F,MAAM,eAAe,GAAG,+CAA+C,CAAC;AAaxE,SAAS,SAAS,CAChB,OAA+B,EAC/B,KAAiB,EACjB,QAAgB,EAChB,GAAW;IAEX,MAAM,KAAK,GAAG,GAAG,GAAG,QAAQ,CAAC;IAC7B,IAAI,KAAK,GAAG,EAAE,CAAC;IACf,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;QACxB,IAAI,CAAC,CAAC,KAAK,KAAK,KAAK,IAAI,CAAC,CAAC,EAAE,GAAG,KAAK;YAAE,KAAK,IAAI,CAAC,CAAC,MAAM,CAAC;IAC3D,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,qEAAqE;AAC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I,KAAK,KAAK,KAAK,IAAI,KAAK,KAAK,UAAU;QAAE,OAAO,IAAI,CAAC;IACzD,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC;QAAE,OAAO,IAAI,CAAC;IACxE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;AAC/C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../../src/policy/loader.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,MAAM,EAAmB,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;AAM/E;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../../src/policy/loader.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,MAAM,EAAmB,KAAK,cAAc,EAAE,MAAM,YAAY,CAAC;AAM/E;;;;;;;;;;;;GAYG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CA6KlD;AAmCD;;;;GAIG;AACH,wBAAgB,wBAAwB,IAAI,cAAc,CAiBzD;AAED;;;;;GAKG;AACH,qBAAa,wBAAyB,YAAW,cAAc;;gBAEjD,SAAS,EAAE,MAAM;IAG7B,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;CAehC"}
|
|
@@ -35,6 +35,8 @@ export function parsePolicy(source) {
|
|
|
35
35
|
// that applies whether or not the rest of the file is strict.
|
|
36
36
|
const requireConfirmAboveWei = parseOptionalWei(raw['require_confirm_above_wei'], 'require_confirm_above_wei');
|
|
37
37
|
const requireConfirmAboveLamports = parseOptionalDec(raw['require_confirm_above_lamports'], 'require_confirm_above_lamports');
|
|
38
|
+
// Rolling-window caps are mode-independent too.
|
|
39
|
+
const windows = parseWindowCaps(raw);
|
|
38
40
|
if (mode === 'permissive') {
|
|
39
41
|
return {
|
|
40
42
|
mode: 'permissive',
|
|
@@ -48,8 +50,11 @@ export function parsePolicy(source) {
|
|
|
48
50
|
allowSvmMessageSigning: true,
|
|
49
51
|
svmAllowTo: [],
|
|
50
52
|
svmMaxLamports: 0n,
|
|
53
|
+
typedDataVerifyingContracts: [],
|
|
54
|
+
typedDataPrimaryTypes: [],
|
|
51
55
|
...(requireConfirmAboveWei !== undefined ? { requireConfirmAboveWei } : {}),
|
|
52
56
|
...(requireConfirmAboveLamports !== undefined ? { requireConfirmAboveLamports } : {}),
|
|
57
|
+
...windows,
|
|
53
58
|
};
|
|
54
59
|
}
|
|
55
60
|
// strict mode — every field is consulted; apply defaults for absent ones.
|
|
@@ -77,6 +82,18 @@ export function parsePolicy(source) {
|
|
|
77
82
|
const allowContractCreation = asBool(raw['allow_contract_creation'], 'allow_contract_creation', false);
|
|
78
83
|
const allowMessageSigning = asBool(raw['allow_message_signing'], 'allow_message_signing', false);
|
|
79
84
|
const allowTypedData = asBool(raw['allow_typed_data'], 'allow_typed_data', false);
|
|
85
|
+
const typedDataVerifyingContracts = asStringArray(raw['typed_data_verifying_contracts'], 'typed_data_verifying_contracts').map((s, i) => {
|
|
86
|
+
if (!ADDR_RE.test(s)) {
|
|
87
|
+
throw new PolicyLoadError(`policy.typed_data_verifying_contracts[${i}] must be 0x-prefixed 20-byte address`);
|
|
88
|
+
}
|
|
89
|
+
return s.toLowerCase();
|
|
90
|
+
});
|
|
91
|
+
const typedDataPrimaryTypes = asStringArray(raw['typed_data_primary_types'], 'typed_data_primary_types').map((s, i) => {
|
|
92
|
+
if (s.trim() === '') {
|
|
93
|
+
throw new PolicyLoadError(`policy.typed_data_primary_types[${i}] must be a non-empty string`);
|
|
94
|
+
}
|
|
95
|
+
return s;
|
|
96
|
+
});
|
|
80
97
|
const allowSvmMessageSigning = asBool(raw['allow_svm_message_signing'], 'allow_svm_message_signing', false);
|
|
81
98
|
const svmAllowToRaw = asStringArray(raw['svm_allow_to'], 'svm_allow_to');
|
|
82
99
|
const svmAllowTo = svmAllowToRaw.map((s, i) => {
|
|
@@ -122,8 +139,34 @@ export function parsePolicy(source) {
|
|
|
122
139
|
allowSvmMessageSigning,
|
|
123
140
|
svmAllowTo,
|
|
124
141
|
svmMaxLamports,
|
|
142
|
+
typedDataVerifyingContracts,
|
|
143
|
+
typedDataPrimaryTypes,
|
|
125
144
|
...(requireConfirmAboveWei !== undefined ? { requireConfirmAboveWei } : {}),
|
|
126
145
|
...(requireConfirmAboveLamports !== undefined ? { requireConfirmAboveLamports } : {}),
|
|
146
|
+
...windows,
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Parse the four optional rolling-window caps. An hourly cap above the daily
|
|
151
|
+
* cap for the same asset can never bind, so it is rejected as a
|
|
152
|
+
* misconfiguration rather than silently ignored.
|
|
153
|
+
*/
|
|
154
|
+
function parseWindowCaps(raw) {
|
|
155
|
+
const hourWei = parseOptionalDec(raw['max_value_per_hour_wei'], 'max_value_per_hour_wei');
|
|
156
|
+
const dayWei = parseOptionalDec(raw['max_value_per_day_wei'], 'max_value_per_day_wei');
|
|
157
|
+
const hourLam = parseOptionalDec(raw['svm_max_lamports_per_hour'], 'svm_max_lamports_per_hour');
|
|
158
|
+
const dayLam = parseOptionalDec(raw['svm_max_lamports_per_day'], 'svm_max_lamports_per_day');
|
|
159
|
+
if (hourWei !== undefined && dayWei !== undefined && hourWei > dayWei) {
|
|
160
|
+
throw new PolicyLoadError(`policy.max_value_per_hour_wei (${hourWei}) must not exceed max_value_per_day_wei (${dayWei})`);
|
|
161
|
+
}
|
|
162
|
+
if (hourLam !== undefined && dayLam !== undefined && hourLam > dayLam) {
|
|
163
|
+
throw new PolicyLoadError(`policy.svm_max_lamports_per_hour (${hourLam}) must not exceed svm_max_lamports_per_day (${dayLam})`);
|
|
164
|
+
}
|
|
165
|
+
return {
|
|
166
|
+
...(hourWei !== undefined ? { maxValuePerHourWei: hourWei } : {}),
|
|
167
|
+
...(dayWei !== undefined ? { maxValuePerDayWei: dayWei } : {}),
|
|
168
|
+
...(hourLam !== undefined ? { svmMaxLamportsPerHour: hourLam } : {}),
|
|
169
|
+
...(dayLam !== undefined ? { svmMaxLamportsPerDay: dayLam } : {}),
|
|
127
170
|
};
|
|
128
171
|
}
|
|
129
172
|
/**
|
|
@@ -144,6 +187,8 @@ export function permissivePolicyResolver() {
|
|
|
144
187
|
allowSvmMessageSigning: true,
|
|
145
188
|
svmAllowTo: [],
|
|
146
189
|
svmMaxLamports: 0n,
|
|
190
|
+
typedDataVerifyingContracts: [],
|
|
191
|
+
typedDataPrimaryTypes: [],
|
|
147
192
|
};
|
|
148
193
|
return { resolve: () => policy };
|
|
149
194
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../../../src/policy/loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,IAAI,MAAM,aAAa,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAe,eAAe,EAAuB,MAAM,YAAY,CAAC;AAE/E,MAAM,OAAO,GAAG,qBAAqB,CAAC;AACtC,MAAM,WAAW,GAAG,oBAAoB,CAAC;AACzC,MAAM,MAAM,GAAG,UAAU,CAAC;AAE1B;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,WAAW,CAAC,MAAc;IACxC,IAAI,GAAiB,CAAC;IACtB,IAAI,CAAC;QACH,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAC3B,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,MAAM,IAAI,eAAe,CAAC,0BAA2B,GAAa,CAAC,OAAO,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C,CAAC,CAAC,EAAE,CAAC;QACpB,MAAM,IAAI,eAAe,CACvB,UAAU,IAAI,0CAA0C,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAC7E,CAAC;IACJ,CAAC;IACD,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC;AACnB,CAAC"}
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* than serialized so we can include explanatory comments — TOML serializers
|
|
4
4
|
* generally strip those.
|
|
5
5
|
*/
|
|
6
|
-
export declare const PERMISSIVE_TEMPLATE = "# sigil policy file \u2014 permissive mode (default)\n#\n# This portal will sign anything the agent asks for. Your private key is\n# still encrypted at rest and never enters Claude's context, but signing\n# authority is unbounded.\n#\n# To restrict what this portal can sign, run:\n#\n# sigil portal remove <handle>\n# sigil portal add <handle> --key-file <path> --strict\n#\n# ...and edit the resulting policy file. Or just change \"permissive\" below\n# to \"strict\" and add the rules in the commented template at:\n# https://github.com/cdrn/sigil#policy-engine\n\nmode = \"permissive\"\n";
|
|
7
|
-
export declare const STRICT_TEMPLATE = "# sigil policy file \u2014 strict mode\n#\n# Every sign request is checked against the rules below before the key is\n# used. Edit the values to fit your portal. Anything you leave at the\n# default-zero/empty state will deny.\n\nmode = \"strict\"\n\n# Allowed chain IDs (decimal). At least one is required.\n# 1 = ethereum mainnet\n# 8453 = base\n# 42161 = arbitrum one\n# 10 = optimism\n# 11155111 = sepolia testnet\nchain_ids = [1]\n\n# Allowed destination addresses (lowercase 0x-prefixed). Empty = no tx allowed.\n# Example:\n# allow_to = [\"0x000000000000000000000000000000000000dead\"]\nallow_to = []\n\n# Per-tx value cap in wei. Default 0 = no ETH sends allowed at all.\n# 0.1 ether = \"100000000000000000\"\n# 1 ether = \"1000000000000000000\"\n# Quoted because uint256 doesn't fit in a TOML integer.\nmax_value_wei = \"0\"\n\n# 4-byte function selectors that are callable. Empty = pure ETH sends only.\n# Common selectors:\n# \"0xa9059cbb\" ERC-20 transfer(address,uint256)\n# \"0x095ea7b3\" ERC-20 approve(address,uint256)\n# \"0x23b872dd\" ERC-20 transferFrom(address,address,uint256)\nallowed_selectors = []\n\n# Contract creation (deploys, to = null). Initcode is arbitrary code that no\n# allowlist can vet, so even when enabled every deploy still respects\n# max_value_wei and ALWAYS routes to the out-of-band confirm gate \u2014 a\n# [confirm.ntfy] block in ~/.sigil/config.toml is required, otherwise\n# sigil-mcp refuses to start.\nallow_contract_creation = false\n\n# EIP-191 personal_sign \u2014 typically safe (used by Sign-In With Ethereum and\n# similar login flows). Set true to permit.\nallow_message_signing = false\n\n# EIP-712 typed data \u2014 CAN authorize off-chain financial actions (Permit,\n# OpenSea orders, gasless approvals). Treat with the same care as signing\n# transactions. Set true to permit.\nallow_typed_data = false\n\n# Optional: above this wei amount, sigil pushes a notification to your\n# phone and waits for an explicit approve/deny tap before signing. Must be\n# strictly less than max_value_wei. Requires a [confirm.ntfy] block in\n# ~/.sigil/config.toml; without one, sigil-mcp refuses to start.\n# Example: confirm anything above 0.01 ETH.\n# require_confirm_above_wei = \"10000000000000000\"\n\n# --- Solana (SVM) ----------------------------------------------------------\n# The same key also controls a Solana (ed25519) address \u2014 see its base58 in\n# \"sigil portal list\". These rules gate signing with it.\n\n# Sign arbitrary off-chain ed25519 messages (e.g. Sign-In With Solana).\nallow_svm_message_signing = false\n\n# Allowed recipients for native SOL transfers (base58). Empty = none.\n# sigil only decodes System-Program SOL transfers offline; any Solana tx it\n# can't fully decode (SPL tokens, program calls, address-lookup-table\n# accounts) is routed to the confirm gate instead of auto-allowed.\n# Example: svm_allow_to = [\"So11111111111111111111111111111111111111112\"]\nsvm_allow_to = []\n\n# Per-tx cap on total transferred lamports (1 SOL = 1000000000). Default 0 =\n# no SOL transfers allowed. Quoted to stay clear of TOML int limits.\nsvm_max_lamports = \"0\"\n\n# Optional: above this lamport total \u2014 OR for any tx sigil can't fully decode\n# \u2014 push a confirm to your phone. Must be strictly less than svm_max_lamports.\n# Example: confirm anything above 0.1 SOL.\n# require_confirm_above_lamports = \"100000000\"\n";
|
|
6
|
+
export declare const PERMISSIVE_TEMPLATE = "# sigil policy file \u2014 permissive mode (default)\n#\n# This portal will sign anything the agent asks for. Your private key is\n# still encrypted at rest and never enters Claude's context, but signing\n# authority is unbounded.\n#\n# To restrict what this portal can sign, run:\n#\n# sigil portal remove <handle>\n# sigil portal add <handle> --key-file <path> --strict\n#\n# ...and edit the resulting policy file. Or just change \"permissive\" below\n# to \"strict\" and add the rules in the commented template at:\n# https://github.com/cdrn/sigil#policy-engine\n\nmode = \"permissive\"\n\n# Optional rolling-window caps on native value signed by this portal \u2014 the\n# one restriction that still makes sense on a permissive portal (\"a bot with\n# an allowance\"). Decimal strings in wei; either or both may be set; an\n# hourly cap must not exceed the daily one. Only tx.value is counted (token\n# transfers are calldata) \u2014 see the README.\n# max_value_per_hour_wei = \"100000000000000000\" # 0.1 ETH / hour\n# max_value_per_day_wei = \"1000000000000000000\" # 1 ETH / day\n#\n# Same for native SOL transfers, in lamports (1 SOL = 1000000000):\n# svm_max_lamports_per_hour = \"100000000\"\n# svm_max_lamports_per_day = \"1000000000\"\n";
|
|
7
|
+
export declare const STRICT_TEMPLATE = "# sigil policy file \u2014 strict mode\n#\n# Every sign request is checked against the rules below before the key is\n# used. Edit the values to fit your portal. Anything you leave at the\n# default-zero/empty state will deny.\n\nmode = \"strict\"\n\n# Allowed chain IDs (decimal). At least one is required.\n# 1 = ethereum mainnet\n# 8453 = base\n# 42161 = arbitrum one\n# 10 = optimism\n# 11155111 = sepolia testnet\nchain_ids = [1]\n\n# Allowed destination addresses (lowercase 0x-prefixed). Empty = no tx allowed.\n# Example:\n# allow_to = [\"0x000000000000000000000000000000000000dead\"]\nallow_to = []\n\n# Per-tx value cap in wei. Default 0 = no ETH sends allowed at all.\n# 0.1 ether = \"100000000000000000\"\n# 1 ether = \"1000000000000000000\"\n# Quoted because uint256 doesn't fit in a TOML integer.\nmax_value_wei = \"0\"\n\n# 4-byte function selectors that are callable. Empty = pure ETH sends only.\n# Common selectors:\n# \"0xa9059cbb\" ERC-20 transfer(address,uint256)\n# \"0x095ea7b3\" ERC-20 approve(address,uint256)\n# \"0x23b872dd\" ERC-20 transferFrom(address,address,uint256)\nallowed_selectors = []\n\n# Contract creation (deploys, to = null). Initcode is arbitrary code that no\n# allowlist can vet, so even when enabled every deploy still respects\n# max_value_wei and ALWAYS routes to the out-of-band confirm gate \u2014 a\n# [confirm.ntfy] block in ~/.sigil/config.toml is required, otherwise\n# sigil-mcp refuses to start.\nallow_contract_creation = false\n\n# EIP-191 personal_sign \u2014 typically safe (used by Sign-In With Ethereum and\n# similar login flows). Set true to permit.\nallow_message_signing = false\n\n# EIP-712 typed data \u2014 CAN authorize off-chain financial actions (Permit,\n# OpenSea orders, gasless approvals). Treat with the same care as signing\n# transactions. Set true to permit.\nallow_typed_data = false\n\n# When allow_typed_data = true, these refine what may be signed. Each empty\n# list means \"no restriction on that axis\". Independently, a domain that\n# must carry a chainId naming one of chain_ids above (chain-less domains are\n# refused in strict mode \u2014 they can't be checked).\n# typed_data_verifying_contracts \u2014 lowercase 0x addresses the domain's\n# verifyingContract must be one of (e.g. Permit2, an exchange).\n# typed_data_primary_types \u2014 primaryType names, e.g. [\"Permit\", \"Order\"].\ntyped_data_verifying_contracts = []\ntyped_data_primary_types = []\n\n# Optional rolling-window caps on tx.value (mode-independent). Decimal\n# strings in wei; hourly must not exceed daily. Enforced against a\n# per-portal ledger in ~/.sigil/state; see \"sigil policy spend <handle>\".\n# max_value_per_hour_wei = \"100000000000000000\" # 0.1 ETH / hour\n# max_value_per_day_wei = \"1000000000000000000\" # 1 ETH / day\n\n# Optional: above this wei amount, sigil pushes a notification to your\n# phone and waits for an explicit approve/deny tap before signing. Must be\n# strictly less than max_value_wei. Requires a [confirm.ntfy] block in\n# ~/.sigil/config.toml; without one, sigil-mcp refuses to start.\n# Example: confirm anything above 0.01 ETH.\n# require_confirm_above_wei = \"10000000000000000\"\n\n# --- Solana (SVM) ----------------------------------------------------------\n# The same key also controls a Solana (ed25519) address \u2014 see its base58 in\n# \"sigil portal list\". These rules gate signing with it.\n\n# Sign arbitrary off-chain ed25519 messages (e.g. Sign-In With Solana).\nallow_svm_message_signing = false\n\n# Allowed recipients for native SOL transfers (base58). Empty = none.\n# sigil only decodes System-Program SOL transfers offline; any Solana tx it\n# can't fully decode (SPL tokens, program calls, address-lookup-table\n# accounts) is routed to the confirm gate instead of auto-allowed.\n# Example: svm_allow_to = [\"So11111111111111111111111111111111111111112\"]\nsvm_allow_to = []\n\n# Per-tx cap on total transferred lamports (1 SOL = 1000000000). Default 0 =\n# no SOL transfers allowed. Quoted to stay clear of TOML int limits.\nsvm_max_lamports = \"0\"\n\n# Optional: above this lamport total \u2014 OR for any tx sigil can't fully decode\n# \u2014 push a confirm to your phone. Must be strictly less than svm_max_lamports.\n# Example: confirm anything above 0.1 SOL.\n# require_confirm_above_lamports = \"100000000\"\n\n# Optional rolling-window caps on decoded native SOL transfers, in lamports.\n# svm_max_lamports_per_hour = \"100000000\"\n# svm_max_lamports_per_day = \"1000000000\"\n";
|
|
8
8
|
export type PolicyMode = 'permissive' | 'strict';
|
|
9
9
|
export declare function policyTemplate(mode: PolicyMode): string;
|
|
10
10
|
//# sourceMappingURL=template.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"template.d.ts","sourceRoot":"","sources":["../../../src/policy/template.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,eAAO,MAAM,mBAAmB,
|
|
1
|
+
{"version":3,"file":"template.d.ts","sourceRoot":"","sources":["../../../src/policy/template.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,eAAO,MAAM,mBAAmB,gvCA4B/B,CAAC;AAEF,eAAO,MAAM,eAAe,+8IAmG3B,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,YAAY,GAAG,QAAQ,CAAC;AAEjD,wBAAgB,cAAc,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAEvD"}
|
|
@@ -19,6 +19,18 @@ export const PERMISSIVE_TEMPLATE = `# sigil policy file — permissive mode (def
|
|
|
19
19
|
# https://github.com/cdrn/sigil#policy-engine
|
|
20
20
|
|
|
21
21
|
mode = "permissive"
|
|
22
|
+
|
|
23
|
+
# Optional rolling-window caps on native value signed by this portal — the
|
|
24
|
+
# one restriction that still makes sense on a permissive portal ("a bot with
|
|
25
|
+
# an allowance"). Decimal strings in wei; either or both may be set; an
|
|
26
|
+
# hourly cap must not exceed the daily one. Only tx.value is counted (token
|
|
27
|
+
# transfers are calldata) — see the README.
|
|
28
|
+
# max_value_per_hour_wei = "100000000000000000" # 0.1 ETH / hour
|
|
29
|
+
# max_value_per_day_wei = "1000000000000000000" # 1 ETH / day
|
|
30
|
+
#
|
|
31
|
+
# Same for native SOL transfers, in lamports (1 SOL = 1000000000):
|
|
32
|
+
# svm_max_lamports_per_hour = "100000000"
|
|
33
|
+
# svm_max_lamports_per_day = "1000000000"
|
|
22
34
|
`;
|
|
23
35
|
export const STRICT_TEMPLATE = `# sigil policy file — strict mode
|
|
24
36
|
#
|
|
@@ -70,6 +82,22 @@ allow_message_signing = false
|
|
|
70
82
|
# transactions. Set true to permit.
|
|
71
83
|
allow_typed_data = false
|
|
72
84
|
|
|
85
|
+
# When allow_typed_data = true, these refine what may be signed. Each empty
|
|
86
|
+
# list means "no restriction on that axis". Independently, a domain that
|
|
87
|
+
# must carry a chainId naming one of chain_ids above (chain-less domains are
|
|
88
|
+
# refused in strict mode — they can't be checked).
|
|
89
|
+
# typed_data_verifying_contracts — lowercase 0x addresses the domain's
|
|
90
|
+
# verifyingContract must be one of (e.g. Permit2, an exchange).
|
|
91
|
+
# typed_data_primary_types — primaryType names, e.g. ["Permit", "Order"].
|
|
92
|
+
typed_data_verifying_contracts = []
|
|
93
|
+
typed_data_primary_types = []
|
|
94
|
+
|
|
95
|
+
# Optional rolling-window caps on tx.value (mode-independent). Decimal
|
|
96
|
+
# strings in wei; hourly must not exceed daily. Enforced against a
|
|
97
|
+
# per-portal ledger in ~/.sigil/state; see "sigil policy spend <handle>".
|
|
98
|
+
# max_value_per_hour_wei = "100000000000000000" # 0.1 ETH / hour
|
|
99
|
+
# max_value_per_day_wei = "1000000000000000000" # 1 ETH / day
|
|
100
|
+
|
|
73
101
|
# Optional: above this wei amount, sigil pushes a notification to your
|
|
74
102
|
# phone and waits for an explicit approve/deny tap before signing. Must be
|
|
75
103
|
# strictly less than max_value_wei. Requires a [confirm.ntfy] block in
|
|
@@ -99,6 +127,10 @@ svm_max_lamports = "0"
|
|
|
99
127
|
# — push a confirm to your phone. Must be strictly less than svm_max_lamports.
|
|
100
128
|
# Example: confirm anything above 0.1 SOL.
|
|
101
129
|
# require_confirm_above_lamports = "100000000"
|
|
130
|
+
|
|
131
|
+
# Optional rolling-window caps on decoded native SOL transfers, in lamports.
|
|
132
|
+
# svm_max_lamports_per_hour = "100000000"
|
|
133
|
+
# svm_max_lamports_per_day = "1000000000"
|
|
102
134
|
`;
|
|
103
135
|
export function policyTemplate(mode) {
|
|
104
136
|
return mode === 'permissive' ? PERMISSIVE_TEMPLATE : STRICT_TEMPLATE;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"template.js","sourceRoot":"","sources":["../../../src/policy/template.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,CAAC,MAAM,mBAAmB,GAAG
|
|
1
|
+
{"version":3,"file":"template.js","sourceRoot":"","sources":["../../../src/policy/template.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,MAAM,CAAC,MAAM,mBAAmB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4BlC,CAAC;AAEF,MAAM,CAAC,MAAM,eAAe,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmG9B,CAAC;AAIF,MAAM,UAAU,cAAc,CAAC,IAAgB;IAC7C,OAAO,IAAI,KAAK,YAAY,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,eAAe,CAAC;AACvE,CAAC"}
|
|
@@ -43,6 +43,29 @@ export interface Policy {
|
|
|
43
43
|
* fires first); validation catches that misconfiguration at load time.
|
|
44
44
|
*/
|
|
45
45
|
requireConfirmAboveWei?: bigint;
|
|
46
|
+
/**
|
|
47
|
+
* Rolling-window caps on the total native value (tx.value, in wei) this
|
|
48
|
+
* portal may sign in any trailing hour / day. Mode-independent, like
|
|
49
|
+
* requireConfirmAboveWei: a permissive portal with a daily ceiling is the
|
|
50
|
+
* most common "bot with an allowance" setup. Enforced against the
|
|
51
|
+
* per-portal spend ledger (see ledger.ts); a breach is a hard deny.
|
|
52
|
+
* `undefined` = no cap for that window. Token transfers are calldata, not
|
|
53
|
+
* value, and are not counted — use allowed_selectors for those.
|
|
54
|
+
*/
|
|
55
|
+
maxValuePerHourWei?: bigint;
|
|
56
|
+
maxValuePerDayWei?: bigint;
|
|
57
|
+
/**
|
|
58
|
+
* Strict mode, EIP-712 only. When allow_typed_data is true these refine
|
|
59
|
+
* what may be signed; each empty list means "no restriction on that axis"
|
|
60
|
+
* so an existing `allow_typed_data = true` policy keeps working.
|
|
61
|
+
* - typedDataVerifyingContracts: lowercase 0x addresses the domain's
|
|
62
|
+
* verifyingContract must be one of.
|
|
63
|
+
* - typedDataPrimaryTypes: primaryType names (e.g. "Permit").
|
|
64
|
+
* Independently, the domain must carry a chainId naming one of chain_ids;
|
|
65
|
+
* strict mode refuses chain-less domains (they can't be checked).
|
|
66
|
+
*/
|
|
67
|
+
typedDataVerifyingContracts: readonly string[];
|
|
68
|
+
typedDataPrimaryTypes: readonly string[];
|
|
46
69
|
/** Allow signing arbitrary off-chain ed25519 messages with this key. */
|
|
47
70
|
allowSvmMessageSigning: boolean;
|
|
48
71
|
/** base58 recipient allowlist for native SOL transfers (strict). */
|
|
@@ -56,6 +79,9 @@ export interface Policy {
|
|
|
56
79
|
* confirm only applies in strict mode (permissive allows them outright).
|
|
57
80
|
*/
|
|
58
81
|
requireConfirmAboveLamports?: bigint;
|
|
82
|
+
/** Rolling-window caps on decoded native SOL transfers, in lamports. */
|
|
83
|
+
svmMaxLamportsPerHour?: bigint;
|
|
84
|
+
svmMaxLamportsPerDay?: bigint;
|
|
59
85
|
}
|
|
60
86
|
/** A native SOL transfer the evaluator was handed, pre-decoded by the caller. */
|
|
61
87
|
export interface SvmTransferView {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/policy/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE7D;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,MAAM;IACrB,IAAI,EAAE,YAAY,GAAG,QAAQ,CAAC;IAC9B,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5B,gEAAgE;IAChE,OAAO,EAAE,SAAS,MAAM,EAAE,CAAC;IAC3B,0EAA0E;IAC1E,WAAW,EAAE,MAAM,CAAC;IACpB,iFAAiF;IACjF,gBAAgB,EAAE,SAAS,MAAM,EAAE,CAAC;IACpC;;;;;;;OAOG;IACH,qBAAqB,EAAE,OAAO,CAAC;IAC/B,mBAAmB,EAAE,OAAO,CAAC;IAC7B,cAAc,EAAE,OAAO,CAAC;IACxB;;;;;;OAMG;IACH,sBAAsB,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/policy/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE7D;;;;;;;;;;;;;;;GAeG;AACH,MAAM,WAAW,MAAM;IACrB,IAAI,EAAE,YAAY,GAAG,QAAQ,CAAC;IAC9B,QAAQ,EAAE,SAAS,MAAM,EAAE,CAAC;IAC5B,gEAAgE;IAChE,OAAO,E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AAC,YAAY,EAAE,MAAM,CAAA;CAAE,GAC7C;IACE,IAAI,EAAE,iBAAiB,CAAC;IACxB,6EAA6E;IAC7E,SAAS,EAAE,SAAS,eAAe,EAAE,CAAC;IACtC,0EAA0E;IAC1E,UAAU,EAAE,OAAO,CAAC;IACpB,wDAAwD;IACxD,gBAAgB,EAAE,MAAM,CAAC;CAC1B,CAAC;AAEN;;;;;;;;;GASG;AACH,MAAM,MAAM,cAAc,GACxB;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,IAAI,EAAE,SAAS,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC;AAE9F;;;;;;GAMG;AACH,MAAM,WAAW,cAAc;IAC7B,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAAC;CACjC;AAED,qBAAa,eAAgB,SAAQ,KAAK;IACxC,SAAkB,KAAK,CAAC,EAAE,OAAO,CAAC;gBACtB,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO;CAK7C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/policy/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/policy/types.ts"],"names":[],"mappings":"AA4IA,MAAM,OAAO,eAAgB,SAAQ,KAAK;IACtB,KAAK,CAAW;IAClC,YAAY,OAAe,EAAE,KAAe;QAC1C,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;QAC9B,IAAI,KAAK,KAAK,SAAS;YAAE,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;IAC9C,CAAC;CACF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Policy } from './types.js';
|
|
2
|
+
/** Which per-portal running total a signed amount counts against. */
|
|
3
|
+
export type SpendAsset = 'wei' | 'lamports';
|
|
4
|
+
export interface WindowCap {
|
|
5
|
+
/** TOML field name, for the deny reason. */
|
|
6
|
+
label: string;
|
|
7
|
+
windowMs: number;
|
|
8
|
+
cap: bigint;
|
|
9
|
+
}
|
|
10
|
+
export declare const HOUR_MS: number;
|
|
11
|
+
export declare const DAY_MS: number;
|
|
12
|
+
/** The rolling-window caps a policy sets for one asset, longest window last. */
|
|
13
|
+
export declare function windowCapsFor(policy: Policy, asset: SpendAsset): WindowCap[];
|
|
14
|
+
/**
|
|
15
|
+
* Pure check: would signing `amount` now push any window over its cap?
|
|
16
|
+
* `spent(windowMs)` returns what the ledger already holds for that trailing
|
|
17
|
+
* window. Returns a human-readable deny reason, or null if every cap holds.
|
|
18
|
+
* A zero amount never breaches (a cap of 0 means "no value at all", and
|
|
19
|
+
* value-less calls carry no value).
|
|
20
|
+
*/
|
|
21
|
+
export declare function checkWindowCaps(caps: readonly WindowCap[], amount: bigint, spent: (windowMs: number) => bigint, unit: SpendAsset): string | null;
|
|
22
|
+
//# sourceMappingURL=window.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"window.d.ts","sourceRoot":"","sources":["../../../src/policy/window.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEzC,qEAAqE;AACrE,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,UAAU,CAAC;AAE5C,MAAM,WAAW,SAAS;IACxB,4CAA4C;IAC5C,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;CACb;AAED,eAAO,MAAM,OAAO,QAAiB,CAAC;AACtC,eAAO,MAAM,MAAM,QAAe,CAAC;AAEnC,gFAAgF;AAChF,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU,GAAG,SAAS,EAAE,CAkC5E;AAED;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,SAAS,SAAS,EAAE,EAC1B,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,MAAM,EACnC,IAAI,EAAE,UAAU,GACf,MAAM,GAAG,IAAI,CAYf"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export const HOUR_MS = 60 * 60 * 1000;
|
|
2
|
+
export const DAY_MS = 24 * HOUR_MS;
|
|
3
|
+
/** The rolling-window caps a policy sets for one asset, longest window last. */
|
|
4
|
+
export function windowCapsFor(policy, asset) {
|
|
5
|
+
const caps = [];
|
|
6
|
+
if (asset === 'wei') {
|
|
7
|
+
if (policy.maxValuePerHourWei !== undefined) {
|
|
8
|
+
caps.push({
|
|
9
|
+
label: 'max_value_per_hour_wei',
|
|
10
|
+
windowMs: HOUR_MS,
|
|
11
|
+
cap: policy.maxValuePerHourWei,
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
if (policy.maxValuePerDayWei !== undefined) {
|
|
15
|
+
caps.push({
|
|
16
|
+
label: 'max_value_per_day_wei',
|
|
17
|
+
windowMs: DAY_MS,
|
|
18
|
+
cap: policy.maxValuePerDayWei,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
if (policy.svmMaxLamportsPerHour !== undefined) {
|
|
24
|
+
caps.push({
|
|
25
|
+
label: 'svm_max_lamports_per_hour',
|
|
26
|
+
windowMs: HOUR_MS,
|
|
27
|
+
cap: policy.svmMaxLamportsPerHour,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
if (policy.svmMaxLamportsPerDay !== undefined) {
|
|
31
|
+
caps.push({
|
|
32
|
+
label: 'svm_max_lamports_per_day',
|
|
33
|
+
windowMs: DAY_MS,
|
|
34
|
+
cap: policy.svmMaxLamportsPerDay,
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return caps;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Pure check: would signing `amount` now push any window over its cap?
|
|
42
|
+
* `spent(windowMs)` returns what the ledger already holds for that trailing
|
|
43
|
+
* window. Returns a human-readable deny reason, or null if every cap holds.
|
|
44
|
+
* A zero amount never breaches (a cap of 0 means "no value at all", and
|
|
45
|
+
* value-less calls carry no value).
|
|
46
|
+
*/
|
|
47
|
+
export function checkWindowCaps(caps, amount, spent, unit) {
|
|
48
|
+
if (amount === 0n)
|
|
49
|
+
return null;
|
|
50
|
+
for (const c of caps) {
|
|
51
|
+
const used = spent(c.windowMs);
|
|
52
|
+
if (used + amount > c.cap) {
|
|
53
|
+
return (`denied — ${amount} ${unit} would bring the trailing ${describe(c.windowMs)} total to ` +
|
|
54
|
+
`${used + amount} ${unit}, over ${c.label} = ${c.cap}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return null;
|
|
58
|
+
}
|
|
59
|
+
function describe(windowMs) {
|
|
60
|
+
if (windowMs === HOUR_MS)
|
|
61
|
+
return '1h';
|
|
62
|
+
if (windowMs === DAY_MS)
|
|
63
|
+
return '24h';
|
|
64
|
+
return `${windowMs}ms`;
|
|
65
|
+
}
|
|
66
|
+
//# sourceMappingURL=window.js.map
|