sigild 0.0.8 → 0.0.9
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 +74 -22
- package/THREAT_MODEL.md +6 -4
- package/dist/src/bin/sigil-mcp.js +59 -16
- package/dist/src/bin/sigil-mcp.js.map +1 -1
- package/dist/src/cli/index.d.ts +2 -2
- package/dist/src/cli/index.d.ts.map +1 -1
- package/dist/src/cli/index.js.map +1 -1
- package/dist/src/cli/main.d.ts.map +1 -1
- package/dist/src/cli/main.js +10 -8
- package/dist/src/cli/main.js.map +1 -1
- package/dist/src/cli/paths.d.ts +15 -5
- package/dist/src/cli/paths.d.ts.map +1 -1
- package/dist/src/cli/paths.js +11 -1
- package/dist/src/cli/paths.js.map +1 -1
- package/dist/src/cli/portal.d.ts +3 -0
- package/dist/src/cli/portal.d.ts.map +1 -1
- package/dist/src/cli/portal.js +7 -1
- package/dist/src/cli/portal.js.map +1 -1
- package/dist/src/cli/status.d.ts +15 -12
- package/dist/src/cli/status.d.ts.map +1 -1
- package/dist/src/cli/status.js +17 -30
- package/dist/src/cli/status.js.map +1 -1
- package/dist/src/cli/unlock.d.ts +15 -15
- package/dist/src/cli/unlock.d.ts.map +1 -1
- package/dist/src/cli/unlock.js +83 -60
- package/dist/src/cli/unlock.js.map +1 -1
- package/dist/src/confirm/ack-server.d.ts +53 -0
- package/dist/src/confirm/ack-server.d.ts.map +1 -0
- package/dist/src/confirm/ack-server.js +87 -0
- package/dist/src/confirm/ack-server.js.map +1 -0
- package/dist/src/confirm/config.d.ts +54 -0
- package/dist/src/confirm/config.d.ts.map +1 -0
- package/dist/src/confirm/config.js +139 -0
- package/dist/src/confirm/config.js.map +1 -0
- package/dist/src/confirm/gate.d.ts +38 -0
- package/dist/src/confirm/gate.d.ts.map +1 -0
- package/dist/src/confirm/gate.js +66 -0
- package/dist/src/confirm/gate.js.map +1 -0
- package/dist/src/confirm/index.d.ts +6 -0
- package/dist/src/confirm/index.d.ts.map +1 -0
- package/dist/src/confirm/index.js +5 -0
- package/dist/src/confirm/index.js.map +1 -0
- package/dist/src/confirm/ntfy.d.ts +38 -0
- package/dist/src/confirm/ntfy.d.ts.map +1 -0
- package/dist/src/confirm/ntfy.js +47 -0
- package/dist/src/confirm/ntfy.js.map +1 -0
- package/dist/src/confirm/types.d.ts +66 -0
- package/dist/src/confirm/types.d.ts.map +1 -0
- package/dist/src/confirm/types.js +12 -0
- package/dist/src/confirm/types.js.map +1 -0
- package/dist/src/control/broadcast.d.ts +29 -0
- package/dist/src/control/broadcast.d.ts.map +1 -0
- package/dist/src/control/broadcast.js +88 -0
- package/dist/src/control/broadcast.js.map +1 -0
- package/dist/src/control/client.d.ts.map +1 -1
- package/dist/src/control/client.js +4 -1
- package/dist/src/control/client.js.map +1 -1
- package/dist/src/control/index.d.ts +1 -0
- package/dist/src/control/index.d.ts.map +1 -1
- package/dist/src/control/index.js +1 -0
- package/dist/src/control/index.js.map +1 -1
- package/dist/src/control/protocol.d.ts +5 -1
- package/dist/src/control/protocol.d.ts.map +1 -1
- package/dist/src/control/protocol.js +2 -1
- package/dist/src/control/protocol.js.map +1 -1
- package/dist/src/control/server.js +6 -6
- package/dist/src/control/server.js.map +1 -1
- package/dist/src/daemon/handles.d.ts +3 -0
- package/dist/src/daemon/handles.d.ts.map +1 -1
- package/dist/src/daemon/handles.js +3 -1
- package/dist/src/daemon/handles.js.map +1 -1
- package/dist/src/daemon/methods.d.ts +13 -3
- package/dist/src/daemon/methods.d.ts.map +1 -1
- package/dist/src/daemon/methods.js +121 -16
- package/dist/src/daemon/methods.js.map +1 -1
- package/dist/src/mcp/server.d.ts +14 -2
- package/dist/src/mcp/server.d.ts.map +1 -1
- package/dist/src/mcp/server.js +28 -14
- package/dist/src/mcp/server.js.map +1 -1
- package/dist/src/mcp/tools.d.ts +1 -1
- package/dist/src/mcp/tools.d.ts.map +1 -1
- package/dist/src/mcp/tools.js +37 -3
- package/dist/src/mcp/tools.js.map +1 -1
- package/dist/src/policy/evaluate.d.ts +10 -4
- package/dist/src/policy/evaluate.d.ts.map +1 -1
- package/dist/src/policy/evaluate.js +161 -20
- package/dist/src/policy/evaluate.js.map +1 -1
- package/dist/src/policy/loader.d.ts.map +1 -1
- package/dist/src/policy/loader.js +70 -0
- package/dist/src/policy/loader.js.map +1 -1
- package/dist/src/policy/template.d.ts +1 -1
- package/dist/src/policy/template.d.ts.map +1 -1
- package/dist/src/policy/template.js +30 -0
- package/dist/src/policy/template.js.map +1 -1
- package/dist/src/policy/types.d.ts +53 -3
- package/dist/src/policy/types.d.ts.map +1 -1
- package/dist/src/policy/types.js.map +1 -1
- package/dist/src/svm/address.d.ts +14 -0
- package/dist/src/svm/address.d.ts.map +1 -0
- package/dist/src/svm/address.js +18 -0
- package/dist/src/svm/address.js.map +1 -0
- package/dist/src/svm/base58.d.ts +15 -0
- package/dist/src/svm/base58.d.ts.map +1 -0
- package/dist/src/svm/base58.js +60 -0
- package/dist/src/svm/base58.js.map +1 -0
- package/dist/src/svm/ed25519.d.ts +19 -0
- package/dist/src/svm/ed25519.d.ts.map +1 -0
- package/dist/src/svm/ed25519.js +32 -0
- package/dist/src/svm/ed25519.js.map +1 -0
- package/dist/src/svm/index.d.ts +5 -0
- package/dist/src/svm/index.d.ts.map +1 -0
- package/dist/src/svm/index.js +5 -0
- package/dist/src/svm/index.js.map +1 -0
- package/dist/src/svm/transaction.d.ts +56 -0
- package/dist/src/svm/transaction.d.ts.map +1 -0
- package/dist/src/svm/transaction.js +182 -0
- package/dist/src/svm/transaction.js.map +1 -0
- package/package.json +2 -1
package/dist/src/mcp/server.js
CHANGED
|
@@ -4,8 +4,11 @@ import { encodeError, encodeSuccess, MCP_INTERNAL_ERROR, MCP_INVALID_PARAMS, MCP
|
|
|
4
4
|
* Handle a single received line by dispatching it through the MCP protocol.
|
|
5
5
|
* Returns either a response string to send back, or `null` if the line was a
|
|
6
6
|
* notification (no response expected).
|
|
7
|
+
*
|
|
8
|
+
* Async because tools/call can perform an out-of-band confirm round-trip
|
|
9
|
+
* (sign_transaction → ConfirmGate → human ack) that may take seconds.
|
|
7
10
|
*/
|
|
8
|
-
export function handleLine(line, opts) {
|
|
11
|
+
export async function handleLine(line, opts) {
|
|
9
12
|
const parsed = parseMessage(line);
|
|
10
13
|
const log = (e) => opts.onLog?.(e);
|
|
11
14
|
if (parsed.kind === 'parse_error') {
|
|
@@ -26,7 +29,7 @@ export function handleLine(line, opts) {
|
|
|
26
29
|
const req = parsed.request;
|
|
27
30
|
log({ kind: 'recv', method: req.method, id: req.id });
|
|
28
31
|
try {
|
|
29
|
-
const result = dispatch(req, opts);
|
|
32
|
+
const result = await dispatch(req, opts);
|
|
30
33
|
log({ kind: 'send_ok', id: req.id });
|
|
31
34
|
return encodeSuccess(req.id, result);
|
|
32
35
|
}
|
|
@@ -40,7 +43,7 @@ export function handleLine(line, opts) {
|
|
|
40
43
|
return encodeError(req.id, MCP_INTERNAL_ERROR, message);
|
|
41
44
|
}
|
|
42
45
|
}
|
|
43
|
-
function dispatch(req, opts) {
|
|
46
|
+
async function dispatch(req, opts) {
|
|
44
47
|
switch (req.method) {
|
|
45
48
|
case 'initialize':
|
|
46
49
|
return {
|
|
@@ -51,14 +54,14 @@ function dispatch(req, opts) {
|
|
|
51
54
|
case 'tools/list':
|
|
52
55
|
return { tools: TOOLS.map((t) => t.definition) };
|
|
53
56
|
case 'tools/call':
|
|
54
|
-
return invokeTool(req.params, opts);
|
|
57
|
+
return await invokeTool(req.params, opts);
|
|
55
58
|
case 'ping':
|
|
56
59
|
return {};
|
|
57
60
|
default:
|
|
58
61
|
throw new ToolError(MCP_METHOD_NOT_FOUND, `method not found: ${req.method}`);
|
|
59
62
|
}
|
|
60
63
|
}
|
|
61
|
-
function invokeTool(params, opts) {
|
|
64
|
+
async function invokeTool(params, opts) {
|
|
62
65
|
if (typeof params !== 'object' || params === null || Array.isArray(params)) {
|
|
63
66
|
throw new ToolError(MCP_INVALID_PARAMS, 'tools/call: params must be an object');
|
|
64
67
|
}
|
|
@@ -72,18 +75,27 @@ function invokeTool(params, opts) {
|
|
|
72
75
|
throw new ToolError(MCP_METHOD_NOT_FOUND, `unknown tool: ${name}`);
|
|
73
76
|
}
|
|
74
77
|
const args = obj['arguments'] ?? {};
|
|
75
|
-
return tool.handler(args, opts.context);
|
|
78
|
+
return await tool.handler(args, opts.context);
|
|
76
79
|
}
|
|
77
80
|
/**
|
|
78
81
|
* Run the MCP server over arbitrary streams (stdin/stdout in production,
|
|
79
|
-
* mock streams in tests). Resolves when stdin closes
|
|
82
|
+
* mock streams in tests). Resolves when stdin closes AND any in-flight
|
|
83
|
+
* requests have finished — so a slow confirm round-trip doesn't get
|
|
84
|
+
* truncated by an early resolve.
|
|
85
|
+
*
|
|
86
|
+
* Concurrency: handlers run serially, chained through a processing promise.
|
|
87
|
+
* That preserves response ordering (matches sync behavior pre-confirm) and
|
|
88
|
+
* keeps stdout writes ordered without needing a separate write queue.
|
|
89
|
+
* Trade-off: a long-pending confirm on request A blocks request B until A
|
|
90
|
+
* resolves. Acceptable for sigil — agents don't pipeline tool calls in
|
|
91
|
+
* practice, and serial is the simpler correctness story.
|
|
80
92
|
*/
|
|
81
93
|
export function runMcpStdio(opts) {
|
|
82
94
|
const { stdin, stdout } = opts;
|
|
83
95
|
stdin.setEncoding?.('utf8');
|
|
84
96
|
return new Promise((resolve, reject) => {
|
|
85
97
|
let buf = '';
|
|
86
|
-
let
|
|
98
|
+
let processing = Promise.resolve();
|
|
87
99
|
stdin.on('data', (chunk) => {
|
|
88
100
|
buf += typeof chunk === 'string' ? chunk : chunk.toString('utf8');
|
|
89
101
|
let nl;
|
|
@@ -92,15 +104,17 @@ export function runMcpStdio(opts) {
|
|
|
92
104
|
buf = buf.slice(nl + 1);
|
|
93
105
|
if (line.length === 0)
|
|
94
106
|
continue;
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
107
|
+
processing = processing.then(async () => {
|
|
108
|
+
const resp = await handleLine(line, opts);
|
|
109
|
+
if (resp !== null)
|
|
110
|
+
stdout.write(resp + '\n');
|
|
111
|
+
});
|
|
98
112
|
}
|
|
99
113
|
});
|
|
100
114
|
stdin.on('end', () => {
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
115
|
+
// Drain the processing chain before resolving — otherwise a confirm
|
|
116
|
+
// mid-flight when stdin closes would lose its response.
|
|
117
|
+
processing.then(() => resolve(), reject);
|
|
104
118
|
});
|
|
105
119
|
stdin.on('error', reject);
|
|
106
120
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/mcp/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExD,OAAO,EACL,WAAW,EACX,aAAa,EACb,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,WAAW,GAGZ,MAAM,eAAe,CAAC;AAsBvB
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/mcp/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAExD,OAAO,EACL,WAAW,EACX,aAAa,EACb,kBAAkB,EAClB,kBAAkB,EAClB,mBAAmB,EACnB,oBAAoB,EACpB,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,WAAW,GAGZ,MAAM,eAAe,CAAC;AAsBvB;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,IAAY,EAAE,IAAmB;IAChE,MAAM,MAAM,GAAG,YAAY,CAAC,IAAI,CAAC,CAAC;IAClC,MAAM,GAAG,GAAG,CAAC,CAAc,EAAQ,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;IAEtD,IAAI,MAAM,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,MAAM,CAAC,CAAC;IAC5B,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/src/mcp/tools.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type MethodContext } from '../daemon/methods.js';
|
|
2
2
|
import { type ToolDefinition, type ToolResult } from './protocol.js';
|
|
3
3
|
export type ToolHandlerCtx = MethodContext;
|
|
4
|
-
export type ToolHandler = (args: unknown, ctx: ToolHandlerCtx) => ToolResult
|
|
4
|
+
export type ToolHandler = (args: unknown, ctx: ToolHandlerCtx) => Promise<ToolResult>;
|
|
5
5
|
export interface Tool {
|
|
6
6
|
definition: ToolDefinition;
|
|
7
7
|
handler: ToolHandler;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../../src/mcp/tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,aAAa,EAAkB,MAAM,sBAAsB,CAAC;AACpF,OAAO,EAAsB,KAAK,cAAc,EAAE,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAEzF,MAAM,MAAM,cAAc,GAAG,aAAa,CAAC;AAE3C,MAAM,MAAM,WAAW,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,cAAc,KAAK,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"tools.d.ts","sourceRoot":"","sources":["../../../src/mcp/tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,KAAK,aAAa,EAAkB,MAAM,sBAAsB,CAAC;AACpF,OAAO,EAAsB,KAAK,cAAc,EAAE,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAEzF,MAAM,MAAM,cAAc,GAAG,aAAa,CAAC;AAE3C,MAAM,MAAM,WAAW,GAAG,CAAC,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,cAAc,KAAK,OAAO,CAAC,UAAU,CAAC,CAAC;AAEtF,MAAM,WAAW,IAAI;IACnB,UAAU,EAAE,cAAc,CAAC;IAC3B,OAAO,EAAE,WAAW,CAAC;CACtB;AAiHD,eAAO,MAAM,KAAK,EAAE,SAAS,IAAI,EAO/B,CAAC;AAEH,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAEvD;AAMD,qBAAa,SAAU,SAAQ,KAAK;IAClC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;gBACX,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO;CAM1D"}
|
package/dist/src/mcp/tools.js
CHANGED
|
@@ -6,7 +6,7 @@ import { MCP_INTERNAL_ERROR } from './protocol.js';
|
|
|
6
6
|
const listPortals = {
|
|
7
7
|
definition: {
|
|
8
8
|
name: 'sigil_list_portals',
|
|
9
|
-
description: 'List the signing portals currently loaded in sigil. Returns each portal handle (e.g. "evm:executor"), its kind, and the
|
|
9
|
+
description: 'List the signing portals currently loaded in sigil. Returns each portal handle (e.g. "evm:executor"), its kind, the EVM address (`address`, secp256k1, 0x-prefixed) and the Solana address (`svmAddress`, ed25519, base58) — both controlled by the same key.',
|
|
10
10
|
inputSchema: { type: 'object', properties: {}, additionalProperties: false },
|
|
11
11
|
},
|
|
12
12
|
handler: (args, ctx) => callMethod('sigil_list_portals', args, ctx),
|
|
@@ -65,11 +65,45 @@ const ethSignTypedData = {
|
|
|
65
65
|
},
|
|
66
66
|
handler: (args, ctx) => callMethod('sigil_eth_sign_typed_data', args, ctx),
|
|
67
67
|
};
|
|
68
|
+
const svmSignMessage = {
|
|
69
|
+
definition: {
|
|
70
|
+
name: 'sigil_svm_sign_message',
|
|
71
|
+
description: 'Sign an arbitrary off-chain message with the portal\'s Solana (ed25519) key — the same key whose address is `svmAddress`. The message is base64-encoded bytes. Returns the 64-byte signature as a base58 string.',
|
|
72
|
+
inputSchema: {
|
|
73
|
+
type: 'object',
|
|
74
|
+
properties: {
|
|
75
|
+
portal: { type: 'string', description: 'Portal handle, e.g. "evm:executor".' },
|
|
76
|
+
message: { type: 'string', description: 'base64 of the bytes to sign.' },
|
|
77
|
+
},
|
|
78
|
+
required: ['portal', 'message'],
|
|
79
|
+
additionalProperties: false,
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
handler: (args, ctx) => callMethod('sigil_svm_sign_message', args, ctx),
|
|
83
|
+
};
|
|
84
|
+
const svmSignTransaction = {
|
|
85
|
+
definition: {
|
|
86
|
+
name: 'sigil_svm_sign_transaction',
|
|
87
|
+
description: 'Sign a Solana transaction message with the portal\'s ed25519 key. Pass the SERIALIZED transaction message (the bytes between the signature array and that you build with your Solana SDK, e.g. message.serialize()) as base64. sigil ed25519-signs those exact bytes and returns the signature as base58 — assemble it into the transaction yourself. Policy decodes native SOL transfers to gate destination/amount; anything it can\'t decode offline is routed to out-of-band confirm. Supports legacy and v0 messages.',
|
|
88
|
+
inputSchema: {
|
|
89
|
+
type: 'object',
|
|
90
|
+
properties: {
|
|
91
|
+
portal: { type: 'string', description: 'Portal handle.' },
|
|
92
|
+
message: { type: 'string', description: 'base64 of the serialized Solana transaction message.' },
|
|
93
|
+
},
|
|
94
|
+
required: ['portal', 'message'],
|
|
95
|
+
additionalProperties: false,
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
handler: (args, ctx) => callMethod('sigil_svm_sign_transaction', args, ctx),
|
|
99
|
+
};
|
|
68
100
|
export const TOOLS = Object.freeze([
|
|
69
101
|
listPortals,
|
|
70
102
|
ethSignMessage,
|
|
71
103
|
ethSignTransaction,
|
|
72
104
|
ethSignTypedData,
|
|
105
|
+
svmSignMessage,
|
|
106
|
+
svmSignTransaction,
|
|
73
107
|
]);
|
|
74
108
|
export function findTool(name) {
|
|
75
109
|
return TOOLS.find((t) => t.definition.name === name);
|
|
@@ -93,9 +127,9 @@ export class ToolError extends Error {
|
|
|
93
127
|
* not-found method) into `ToolError` with the same code, so the original
|
|
94
128
|
* error semantics flow through to the MCP client unchanged.
|
|
95
129
|
*/
|
|
96
|
-
function callMethod(methodName, args, ctx) {
|
|
130
|
+
async function callMethod(methodName, args, ctx) {
|
|
97
131
|
try {
|
|
98
|
-
const result = dispatch(methodName, args, ctx);
|
|
132
|
+
const result = await dispatch(methodName, args, ctx);
|
|
99
133
|
return textResult(result);
|
|
100
134
|
}
|
|
101
135
|
catch (err) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../../src/mcp/tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAsB,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACpF,OAAO,EAAE,kBAAkB,EAAwC,MAAM,eAAe,CAAC;AAWzF,8EAA8E;AAC9E,mBAAmB;AACnB,8EAA8E;AAE9E,MAAM,WAAW,GAAS;IACxB,UAAU,EAAE;QACV,IAAI,EAAE,oBAAoB;QAC1B,WAAW,EACT
|
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../../src/mcp/tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAsB,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACpF,OAAO,EAAE,kBAAkB,EAAwC,MAAM,eAAe,CAAC;AAWzF,8EAA8E;AAC9E,mBAAmB;AACnB,8EAA8E;AAE9E,MAAM,WAAW,GAAS;IACxB,UAAU,EAAE;QACV,IAAI,EAAE,oBAAoB;QAC1B,WAAW,EACT,+PAA+P;QACjQ,WAAW,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,EAAE,oBAAoB,EAAE,KAAK,EAAE;KAC7E;IACD,OAAO,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,CAAC,UAAU,CAAC,oBAAoB,EAAE,IAAI,EAAE,GAAG,CAAC;CACpE,CAAC;AAEF,MAAM,cAAc,GAAS;IAC3B,UAAU,EAAE;QACV,IAAI,EAAE,wBAAwB;QAC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CAAC,OAAO,EAAE,CAAC,CAAC;IACjF,CAAC;AACH,CAAC;AAED,SAAS,UAAU,CAAC,OAAgB;IAClC,8DAA8D;IAC9D,uEAAuE;IACvE,wDAAwD;IACxD,OAAO;QACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,CAAC;QAC1D,iBAAiB,EAAE,OAAO;KAC3B,CAAC;AACJ,CAAC"}
|
|
@@ -1,13 +1,19 @@
|
|
|
1
1
|
import type { Policy, PolicyDecision, PolicyRequest } from './types.js';
|
|
2
2
|
/**
|
|
3
|
-
* Pure evaluator.
|
|
3
|
+
* Pure evaluator. Returns Allow, Deny(reason), or ConfirmRequired(summary).
|
|
4
4
|
*
|
|
5
5
|
* The reason string is what the caller writes into the audit log and surfaces
|
|
6
6
|
* as the RPC_POLICY_DENIED error message — write it for a human.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* Order of checks for transactions:
|
|
9
|
+
* 1. strict-mode static deny rules (chain, allow_to, value cap, selector)
|
|
10
|
+
* 2. require_confirm_above_wei — independent of mode
|
|
11
|
+
* 3. allow
|
|
12
|
+
*
|
|
13
|
+
* Step 2 runs even in permissive mode: if the user wrote a confirm threshold
|
|
14
|
+
* into their TOML, honour it regardless of whether the rest of the file is
|
|
15
|
+
* permissive. Personal_sign and EIP-712 don't carry a `value` field and so
|
|
16
|
+
* never trigger the confirm path; that's tracked as a follow-up.
|
|
11
17
|
*/
|
|
12
18
|
export declare function evaluate(request: PolicyRequest, policy: Policy): PolicyDecision;
|
|
13
19
|
//# sourceMappingURL=evaluate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluate.d.ts","sourceRoot":"","sources":["../../../src/policy/evaluate.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"evaluate.d.ts","sourceRoot":"","sources":["../../../src/policy/evaluate.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,aAAa,EAAmB,MAAM,YAAY,CAAC;AAEzF;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,GAAG,cAAc,CAiD/E"}
|
|
@@ -1,56 +1,163 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Pure evaluator.
|
|
2
|
+
* Pure evaluator. Returns Allow, Deny(reason), or ConfirmRequired(summary).
|
|
3
3
|
*
|
|
4
4
|
* The reason string is what the caller writes into the audit log and surfaces
|
|
5
5
|
* as the RPC_POLICY_DENIED error message — write it for a human.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* Order of checks for transactions:
|
|
8
|
+
* 1. strict-mode static deny rules (chain, allow_to, value cap, selector)
|
|
9
|
+
* 2. require_confirm_above_wei — independent of mode
|
|
10
|
+
* 3. allow
|
|
11
|
+
*
|
|
12
|
+
* Step 2 runs even in permissive mode: if the user wrote a confirm threshold
|
|
13
|
+
* into their TOML, honour it regardless of whether the rest of the file is
|
|
14
|
+
* permissive. Personal_sign and EIP-712 don't carry a `value` field and so
|
|
15
|
+
* never trigger the confirm path; that's tracked as a follow-up.
|
|
10
16
|
*/
|
|
11
17
|
export function evaluate(request, policy) {
|
|
12
|
-
if (policy.mode === 'permissive')
|
|
13
|
-
|
|
18
|
+
if (policy.mode === 'permissive') {
|
|
19
|
+
if (request.kind === 'transaction') {
|
|
20
|
+
const confirm = confirmForTx(request.tx, policy);
|
|
21
|
+
if (confirm)
|
|
22
|
+
return confirm;
|
|
23
|
+
}
|
|
24
|
+
if (request.kind === 'svm_transaction') {
|
|
25
|
+
const confirm = confirmForSvmTx(request, policy);
|
|
26
|
+
if (confirm)
|
|
27
|
+
return confirm;
|
|
28
|
+
}
|
|
29
|
+
return { kind: 'allow' };
|
|
30
|
+
}
|
|
14
31
|
switch (request.kind) {
|
|
15
|
-
case 'transaction':
|
|
16
|
-
|
|
32
|
+
case 'transaction': {
|
|
33
|
+
const deny = evaluateTransactionStrict(request.tx, policy);
|
|
34
|
+
if (deny)
|
|
35
|
+
return deny;
|
|
36
|
+
const confirm = confirmForTx(request.tx, policy);
|
|
37
|
+
if (confirm)
|
|
38
|
+
return confirm;
|
|
39
|
+
return { kind: 'allow' };
|
|
40
|
+
}
|
|
17
41
|
case 'message':
|
|
18
42
|
return policy.allowMessageSigning
|
|
19
|
-
? {
|
|
43
|
+
? { kind: 'allow' }
|
|
20
44
|
: {
|
|
21
|
-
|
|
45
|
+
kind: 'deny',
|
|
22
46
|
reason: 'personal_sign denied — strict mode + allow_message_signing=false',
|
|
23
47
|
};
|
|
24
48
|
case 'typed_data':
|
|
25
49
|
return policy.allowTypedData
|
|
26
|
-
? {
|
|
50
|
+
? { kind: 'allow' }
|
|
27
51
|
: {
|
|
28
|
-
|
|
52
|
+
kind: 'deny',
|
|
29
53
|
reason: 'EIP-712 typed-data denied — strict mode + allow_typed_data=false',
|
|
30
54
|
};
|
|
55
|
+
case 'svm_message':
|
|
56
|
+
return policy.allowSvmMessageSigning
|
|
57
|
+
? { kind: 'allow' }
|
|
58
|
+
: {
|
|
59
|
+
kind: 'deny',
|
|
60
|
+
reason: 'svm message signing denied — strict mode + allow_svm_message_signing=false',
|
|
61
|
+
};
|
|
62
|
+
case 'svm_transaction': {
|
|
63
|
+
const decision = evaluateSvmTxStrict(request, policy);
|
|
64
|
+
if (decision)
|
|
65
|
+
return decision;
|
|
66
|
+
const confirm = confirmForSvmTx(request, policy);
|
|
67
|
+
if (confirm)
|
|
68
|
+
return confirm;
|
|
69
|
+
return { kind: 'allow' };
|
|
70
|
+
}
|
|
31
71
|
}
|
|
32
72
|
}
|
|
33
|
-
|
|
73
|
+
/**
|
|
74
|
+
* Strict-mode Solana transaction check. All-or-nothing decode:
|
|
75
|
+
* - if any instruction couldn't be decoded offline, we can't reason about
|
|
76
|
+
* what it does → route to a human confirm (NOT a silent allow);
|
|
77
|
+
* - otherwise every transfer's destination must be allowlisted and the
|
|
78
|
+
* total must be within the cap, else hard deny.
|
|
79
|
+
* Returns a deny/confirm decision, or null when the static checks pass (the
|
|
80
|
+
* caller then applies the value-based confirm threshold).
|
|
81
|
+
*/
|
|
82
|
+
function evaluateSvmTxStrict(req, policy) {
|
|
83
|
+
if (!req.allDecoded) {
|
|
84
|
+
return {
|
|
85
|
+
kind: 'confirm',
|
|
86
|
+
summary: `unrecognized Solana tx — ${req.instructionCount} instruction${req.instructionCount === 1 ? '' : 's'}, contents not decodable offline`,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
let total = 0n;
|
|
90
|
+
for (const t of req.transfers) {
|
|
91
|
+
if (!policy.svmAllowTo.includes(t.to)) {
|
|
92
|
+
return { kind: 'deny', reason: `svm tx denied — recipient ${t.to} not in svm_allow_to` };
|
|
93
|
+
}
|
|
94
|
+
total += t.lamports;
|
|
95
|
+
}
|
|
96
|
+
if (total > policy.svmMaxLamports) {
|
|
97
|
+
return {
|
|
98
|
+
kind: 'deny',
|
|
99
|
+
reason: `svm tx denied — total ${total} lamports exceeds svm_max_lamports ${policy.svmMaxLamports}`,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* If require_confirm_above_lamports is set and the total transferred exceeds
|
|
106
|
+
* it, return a Confirm. Only sums the decoded transfers — in permissive mode
|
|
107
|
+
* an undecoded tx contributes nothing here (permissive allows it outright).
|
|
108
|
+
*/
|
|
109
|
+
function confirmForSvmTx(req, policy) {
|
|
110
|
+
if (policy.requireConfirmAboveLamports === undefined)
|
|
111
|
+
return null;
|
|
112
|
+
let total = 0n;
|
|
113
|
+
for (const t of req.transfers)
|
|
114
|
+
total += t.lamports;
|
|
115
|
+
if (total <= policy.requireConfirmAboveLamports)
|
|
116
|
+
return null;
|
|
117
|
+
return { kind: 'confirm', summary: `${formatSol(total)} SOL → ${svmDest(req.transfers)}` };
|
|
118
|
+
}
|
|
119
|
+
function svmDest(transfers) {
|
|
120
|
+
if (transfers.length === 1)
|
|
121
|
+
return shortB58(transfers[0].to);
|
|
122
|
+
return `${transfers.length} recipients`;
|
|
123
|
+
}
|
|
124
|
+
function shortB58(addr) {
|
|
125
|
+
return addr.length > 12 ? `${addr.slice(0, 4)}…${addr.slice(-4)}` : addr;
|
|
126
|
+
}
|
|
127
|
+
function formatSol(lamports) {
|
|
128
|
+
const LAMPORTS_PER_SOL = 1000000000n;
|
|
129
|
+
const whole = lamports / LAMPORTS_PER_SOL;
|
|
130
|
+
const frac = lamports % LAMPORTS_PER_SOL;
|
|
131
|
+
if (frac === 0n)
|
|
132
|
+
return whole.toString();
|
|
133
|
+
const fracStr = frac.toString().padStart(9, '0').slice(0, 6).replace(/0+$/, '');
|
|
134
|
+
return fracStr === '' ? whole.toString() : `${whole}.${fracStr}`;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Strict-mode static checks. Returns a Deny decision on the first failure, or
|
|
138
|
+
* `null` if everything passes (the caller then runs the confirm check).
|
|
139
|
+
*/
|
|
140
|
+
function evaluateTransactionStrict(tx, policy) {
|
|
34
141
|
// 1. chain ID
|
|
35
142
|
if (!policy.chainIds.includes(Number(tx.chainId))) {
|
|
36
143
|
return {
|
|
37
|
-
|
|
144
|
+
kind: 'deny',
|
|
38
145
|
reason: `tx denied — chain ${tx.chainId} not in chain_ids ${JSON.stringify(policy.chainIds)}`,
|
|
39
146
|
};
|
|
40
147
|
}
|
|
41
148
|
// 2. contract creation (to: null) — denied by default; future "allow_contract_creation" toggle
|
|
42
149
|
if (tx.to === null) {
|
|
43
|
-
return {
|
|
150
|
+
return { kind: 'deny', reason: 'tx denied — contract creation not allowed' };
|
|
44
151
|
}
|
|
45
152
|
// 3. destination allowlist (case-insensitive; allow_to is pre-lowercased)
|
|
46
153
|
const to = tx.to.toLowerCase();
|
|
47
154
|
if (!policy.allowTo.includes(to)) {
|
|
48
|
-
return {
|
|
155
|
+
return { kind: 'deny', reason: `tx denied — destination ${to} not in allow_to` };
|
|
49
156
|
}
|
|
50
157
|
// 4. per-tx value cap
|
|
51
158
|
if (tx.value > policy.maxValueWei) {
|
|
52
159
|
return {
|
|
53
|
-
|
|
160
|
+
kind: 'deny',
|
|
54
161
|
reason: `tx denied — value ${tx.value} wei exceeds max_value_wei ${policy.maxValueWei}`,
|
|
55
162
|
};
|
|
56
163
|
}
|
|
@@ -58,16 +165,50 @@ function evaluateTransaction(tx, policy) {
|
|
|
58
165
|
const dataHex = typeof tx.data === 'string' ? tx.data : ('0x' + tx.data.toString('hex'));
|
|
59
166
|
if (dataHex.length > 2) {
|
|
60
167
|
if (dataHex.length < 10) {
|
|
61
|
-
return {
|
|
168
|
+
return { kind: 'deny', reason: `tx denied — calldata too short to extract selector` };
|
|
62
169
|
}
|
|
63
170
|
const selector = dataHex.slice(0, 10).toLowerCase();
|
|
64
171
|
if (!policy.allowedSelectors.includes(selector)) {
|
|
65
172
|
return {
|
|
66
|
-
|
|
173
|
+
kind: 'deny',
|
|
67
174
|
reason: `tx denied — selector ${selector} not in allowed_selectors`,
|
|
68
175
|
};
|
|
69
176
|
}
|
|
70
177
|
}
|
|
71
|
-
return
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* If require_confirm_above_wei is set and this tx exceeds it, return a
|
|
182
|
+
* Confirm decision. Otherwise null.
|
|
183
|
+
*
|
|
184
|
+
* The summary is what the human sees on their phone. The destination is
|
|
185
|
+
* shortened so the notification preview isn't dominated by hex.
|
|
186
|
+
*/
|
|
187
|
+
function confirmForTx(tx, policy) {
|
|
188
|
+
if (policy.requireConfirmAboveWei === undefined)
|
|
189
|
+
return null;
|
|
190
|
+
const value = BigInt(tx.value);
|
|
191
|
+
if (value <= policy.requireConfirmAboveWei)
|
|
192
|
+
return null;
|
|
193
|
+
const dest = tx.to === null ? 'contract creation' : shortAddr(tx.to);
|
|
194
|
+
return {
|
|
195
|
+
kind: 'confirm',
|
|
196
|
+
summary: `${formatWei(value)} ETH → ${dest} on chain ${BigInt(tx.chainId)}`,
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
function shortAddr(addr) {
|
|
200
|
+
const a = addr.toLowerCase();
|
|
201
|
+
return a.length === 42 ? `${a.slice(0, 6)}…${a.slice(-4)}` : a;
|
|
202
|
+
}
|
|
203
|
+
function formatWei(v) {
|
|
204
|
+
// Render with up to 6 fractional digits, trimming trailing zeros. The push
|
|
205
|
+
// notification is a glance, not a settlement statement.
|
|
206
|
+
const WEI_PER_ETH = 1000000000000000000n;
|
|
207
|
+
const whole = v / WEI_PER_ETH;
|
|
208
|
+
const frac = v % WEI_PER_ETH;
|
|
209
|
+
if (frac === 0n)
|
|
210
|
+
return whole.toString();
|
|
211
|
+
const fracStr = frac.toString().padStart(18, '0').slice(0, 6).replace(/0+$/, '');
|
|
212
|
+
return fracStr === '' ? whole.toString() : `${whole}.${fracStr}`;
|
|
72
213
|
}
|
|
73
214
|
//# sourceMappingURL=evaluate.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"evaluate.js","sourceRoot":"","sources":["../../../src/policy/evaluate.ts"],"names":[],"mappings":"AAGA
|
|
1
|
+
{"version":3,"file":"evaluate.js","sourceRoot":"","sources":["../../../src/policy/evaluate.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,QAAQ,CAAC,OAAsB,EAAE,MAAc;IAC7D,IAAI,MAAM,CAAC,IAAI,KAAK,YAAY,EAAE,CAAC;QACjC,IAAI,OAAO,CAAC,IAAI,KAAK,aAAa,EAAE,CAAC;YACnC,MAAM,OAAO,GAAG,YAAY,CAAC,OAAO,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;YACjD,IAAI,OAAO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,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE;KAC5E,CAAC;AACJ,CAAC;AAED,SAAS,SAAS,CAAC,IAAY;IAC7B,MAAM,CAAC,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IAC7B,OAAO,CAAC,CAAC,MAAM,KAAK,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AACjE,CAAC;AAED,SAAS,SAAS,CAAC,CAAS;IAC1B,2EAA2E;IAC3E,wDAAwD;IACxD,MAAM,WAAW,GAAG,oBAA0B,CAAC;IAC/C,MAAM,KAAK,GAAG,CAAC,GAAG,WAAW,CAAC;IAC9B,MAAM,IAAI,GAAG,CAAC,GAAG,WAAW,CAAC;IAC7B,IAAI,IAAI,KAAK,EAAE;QAAE,OAAO,KAAK,CAAC,QAAQ,EAAE,CAAC;IACzC,MAAM,OAAO,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,EAAE,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACjF,OAAO,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC,GAAG,KAAK,IAAI,OAAO,EAAE,CAAC;AACnE,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../../src/policy/loader.ts"],"names":[],"mappings":"
|
|
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,CA8HlD;AAED;;;;GAIG;AACH,wBAAgB,wBAAwB,IAAI,cAAc,CAczD;AAED;;;;;GAKG;AACH,qBAAa,wBAAyB,YAAW,cAAc;;gBAEjD,SAAS,EAAE,MAAM;IAG7B,OAAO,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;CAehC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { readFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import toml from '@iarna/toml';
|
|
4
|
+
import { base58Decode } from '../svm/index.js';
|
|
4
5
|
import { PolicyLoadError } from './types.js';
|
|
5
6
|
const ADDR_RE = /^0x[0-9a-fA-F]{40}$/;
|
|
6
7
|
const SELECTOR_RE = /^0x[0-9a-fA-F]{8}$/;
|
|
@@ -30,6 +31,10 @@ export function parsePolicy(source) {
|
|
|
30
31
|
if (mode !== 'permissive' && mode !== 'strict') {
|
|
31
32
|
throw new PolicyLoadError(`policy.mode must be "permissive" or "strict" (got ${JSON.stringify(mode)})`);
|
|
32
33
|
}
|
|
34
|
+
// require_confirm_above_wei is mode-independent: it's an opt-in safety net
|
|
35
|
+
// that applies whether or not the rest of the file is strict.
|
|
36
|
+
const requireConfirmAboveWei = parseOptionalWei(raw['require_confirm_above_wei'], 'require_confirm_above_wei');
|
|
37
|
+
const requireConfirmAboveLamports = parseOptionalDec(raw['require_confirm_above_lamports'], 'require_confirm_above_lamports');
|
|
33
38
|
if (mode === 'permissive') {
|
|
34
39
|
return {
|
|
35
40
|
mode: 'permissive',
|
|
@@ -39,6 +44,11 @@ export function parsePolicy(source) {
|
|
|
39
44
|
allowedSelectors: [],
|
|
40
45
|
allowMessageSigning: true,
|
|
41
46
|
allowTypedData: true,
|
|
47
|
+
allowSvmMessageSigning: true,
|
|
48
|
+
svmAllowTo: [],
|
|
49
|
+
svmMaxLamports: 0n,
|
|
50
|
+
...(requireConfirmAboveWei !== undefined ? { requireConfirmAboveWei } : {}),
|
|
51
|
+
...(requireConfirmAboveLamports !== undefined ? { requireConfirmAboveLamports } : {}),
|
|
42
52
|
};
|
|
43
53
|
}
|
|
44
54
|
// strict mode — every field is consulted; apply defaults for absent ones.
|
|
@@ -65,6 +75,39 @@ export function parsePolicy(source) {
|
|
|
65
75
|
});
|
|
66
76
|
const allowMessageSigning = asBool(raw['allow_message_signing'], 'allow_message_signing', false);
|
|
67
77
|
const allowTypedData = asBool(raw['allow_typed_data'], 'allow_typed_data', false);
|
|
78
|
+
const allowSvmMessageSigning = asBool(raw['allow_svm_message_signing'], 'allow_svm_message_signing', false);
|
|
79
|
+
const svmAllowToRaw = asStringArray(raw['svm_allow_to'], 'svm_allow_to');
|
|
80
|
+
const svmAllowTo = svmAllowToRaw.map((s, i) => {
|
|
81
|
+
let decoded;
|
|
82
|
+
try {
|
|
83
|
+
decoded = base58Decode(s);
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
throw new PolicyLoadError(`policy.svm_allow_to[${i}] is not valid base58: ${JSON.stringify(s)}`);
|
|
87
|
+
}
|
|
88
|
+
if (decoded.length !== 32) {
|
|
89
|
+
throw new PolicyLoadError(`policy.svm_allow_to[${i}] must decode to a 32-byte address (got ${decoded.length} bytes)`);
|
|
90
|
+
}
|
|
91
|
+
return s;
|
|
92
|
+
});
|
|
93
|
+
const svmMaxLamports = parseOptionalDec(raw['svm_max_lamports'], 'svm_max_lamports') ?? 0n;
|
|
94
|
+
// Catch the misconfiguration where the confirm threshold sits above the
|
|
95
|
+
// hard cap: nothing would ever trigger the confirm path, the deny would
|
|
96
|
+
// fire first. Easier to surface at load time than to wonder why your
|
|
97
|
+
// phone never buzzed.
|
|
98
|
+
if (requireConfirmAboveWei !== undefined &&
|
|
99
|
+
requireConfirmAboveWei >= maxValueWei &&
|
|
100
|
+
maxValueWei !== 0n) {
|
|
101
|
+
throw new PolicyLoadError(`policy.require_confirm_above_wei (${requireConfirmAboveWei}) must be less than ` +
|
|
102
|
+
`max_value_wei (${maxValueWei}) — otherwise the value cap fires first and the ` +
|
|
103
|
+
`confirm gate never triggers`);
|
|
104
|
+
}
|
|
105
|
+
if (requireConfirmAboveLamports !== undefined &&
|
|
106
|
+
requireConfirmAboveLamports >= svmMaxLamports &&
|
|
107
|
+
svmMaxLamports !== 0n) {
|
|
108
|
+
throw new PolicyLoadError(`policy.require_confirm_above_lamports (${requireConfirmAboveLamports}) must be less than ` +
|
|
109
|
+
`svm_max_lamports (${svmMaxLamports}) — otherwise the cap denies first and the confirm never triggers`);
|
|
110
|
+
}
|
|
68
111
|
return {
|
|
69
112
|
mode: 'strict',
|
|
70
113
|
chainIds,
|
|
@@ -73,6 +116,11 @@ export function parsePolicy(source) {
|
|
|
73
116
|
allowedSelectors,
|
|
74
117
|
allowMessageSigning,
|
|
75
118
|
allowTypedData,
|
|
119
|
+
allowSvmMessageSigning,
|
|
120
|
+
svmAllowTo,
|
|
121
|
+
svmMaxLamports,
|
|
122
|
+
...(requireConfirmAboveWei !== undefined ? { requireConfirmAboveWei } : {}),
|
|
123
|
+
...(requireConfirmAboveLamports !== undefined ? { requireConfirmAboveLamports } : {}),
|
|
76
124
|
};
|
|
77
125
|
}
|
|
78
126
|
/**
|
|
@@ -89,6 +137,9 @@ export function permissivePolicyResolver() {
|
|
|
89
137
|
allowedSelectors: [],
|
|
90
138
|
allowMessageSigning: true,
|
|
91
139
|
allowTypedData: true,
|
|
140
|
+
allowSvmMessageSigning: true,
|
|
141
|
+
svmAllowTo: [],
|
|
142
|
+
svmMaxLamports: 0n,
|
|
92
143
|
};
|
|
93
144
|
return { resolve: () => policy };
|
|
94
145
|
}
|
|
@@ -167,4 +218,23 @@ function parseMaxValue(v) {
|
|
|
167
218
|
}
|
|
168
219
|
return BigInt(v);
|
|
169
220
|
}
|
|
221
|
+
function parseOptionalWei(v, name) {
|
|
222
|
+
return parseOptionalDec(v, name);
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Parse an optional non-negative integer supplied as a decimal string (TOML
|
|
226
|
+
* int64 can't hold uint256 wei or, for safety, large lamport totals). Returns
|
|
227
|
+
* undefined when the field is absent.
|
|
228
|
+
*/
|
|
229
|
+
function parseOptionalDec(v, name) {
|
|
230
|
+
if (v === undefined)
|
|
231
|
+
return undefined;
|
|
232
|
+
if (typeof v !== 'string') {
|
|
233
|
+
throw new PolicyLoadError(`policy.${name} must be a decimal string (e.g. "1000000000"); got ${typeof v}`);
|
|
234
|
+
}
|
|
235
|
+
if (!DEC_RE.test(v)) {
|
|
236
|
+
throw new PolicyLoadError(`policy.${name} must be a decimal integer string (got ${JSON.stringify(v)})`);
|
|
237
|
+
}
|
|
238
|
+
return BigInt(v);
|
|
239
|
+
}
|
|
170
240
|
//# sourceMappingURL=loader.js.map
|