@atbash/atbash-openclaw 0.1.13-dev.4 → 0.1.13-dev.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/context-mapper.js +79 -1
- package/dist/index.js +2 -2
- package/package.json +2 -2
package/dist/context-mapper.js
CHANGED
|
@@ -1,3 +1,81 @@
|
|
|
1
|
+
const ASSET_BY_CONTRACT = {
|
|
2
|
+
"0xdac17f958d2ee523a2206206994597c13d831ec7": "USDT",
|
|
3
|
+
"0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48": "USDC",
|
|
4
|
+
"0x6b175474e89094c44da98b954eedeac495271d0f": "DAI",
|
|
5
|
+
"0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2": "WETH",
|
|
6
|
+
"0x2260fac5e5542a773aa44fbcfedf7c193bc2c599": "WBTC",
|
|
7
|
+
"0x1f9840a85d5af5bf1d1762f925bdaddc4201f984": "UNI",
|
|
8
|
+
"0x514910771af9ca656af840dff83e8264ecf986ca": "LINK",
|
|
9
|
+
"0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9": "AAVE",
|
|
10
|
+
"0xb0df6379ba1692841965a0745ac1bd3046d79ba3": "ATBASH",
|
|
11
|
+
"0xe9c094187219d9a29382c1a36fc43619c9257777": "ATBASH",
|
|
12
|
+
"0xf8b071428558c657a7a9aa1c43e152e75dd77777": "ATBASH",
|
|
13
|
+
};
|
|
14
|
+
const ERC20_RE = /\b(0x[a-fA-F0-9]{40})\b/;
|
|
15
|
+
const ERC20_ADDR_RE = /(0x[a-fA-F0-9]{40})/;
|
|
16
|
+
const FINANCIAL_OP_RE = /\b(transfer|send|swap|approve|erc20)\b/i;
|
|
17
|
+
function resolveAsset(token) {
|
|
18
|
+
if (!token)
|
|
19
|
+
return "ETH";
|
|
20
|
+
const t = token.toLowerCase();
|
|
21
|
+
const m = ERC20_ADDR_RE.exec(t);
|
|
22
|
+
if (m)
|
|
23
|
+
return ASSET_BY_CONTRACT[m[1].toLowerCase()] ?? "other";
|
|
24
|
+
if (t === "c60" || t === "eth")
|
|
25
|
+
return "ETH";
|
|
26
|
+
if (t === "atbash")
|
|
27
|
+
return "ATBASH";
|
|
28
|
+
if (t === "usdt" || t === "tether")
|
|
29
|
+
return "USDT";
|
|
30
|
+
if (t === "usdc")
|
|
31
|
+
return "USDC";
|
|
32
|
+
return "other";
|
|
33
|
+
}
|
|
34
|
+
function strField(obj, ...keys) {
|
|
35
|
+
for (const k of keys) {
|
|
36
|
+
const v = obj[k];
|
|
37
|
+
if (typeof v === "string" && v.trim())
|
|
38
|
+
return v.trim();
|
|
39
|
+
}
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
function canonicalizeFinancial(toolName, args) {
|
|
43
|
+
const a = args !== null && typeof args === "object" && !Array.isArray(args)
|
|
44
|
+
? args
|
|
45
|
+
: undefined;
|
|
46
|
+
const cmdStr = a ? strField(a, "command", "cmd", "shell_command") : undefined;
|
|
47
|
+
const isFinancialTool = FINANCIAL_OP_RE.test(toolName);
|
|
48
|
+
const hasFinancialCmd = cmdStr ? FINANCIAL_OP_RE.test(cmdStr) : false;
|
|
49
|
+
const hasAddress = cmdStr ? ERC20_RE.test(cmdStr) : false;
|
|
50
|
+
if (!isFinancialTool && !hasFinancialCmd && !hasAddress)
|
|
51
|
+
return undefined;
|
|
52
|
+
const flagVal = (flag) => cmdStr ? new RegExp(`--${flag}[= ]+(\\S+)`).exec(cmdStr)?.[1] : undefined;
|
|
53
|
+
let token = (a ? strField(a, "token", "token_address", "asset", "currency") : undefined) ??
|
|
54
|
+
flagVal("token");
|
|
55
|
+
if (!token && cmdStr) {
|
|
56
|
+
const m = ERC20_RE.exec(cmdStr);
|
|
57
|
+
if (m)
|
|
58
|
+
token = m[1];
|
|
59
|
+
}
|
|
60
|
+
const to = (a ? strField(a, "to", "recipient", "destination") : undefined) ??
|
|
61
|
+
flagVal("to") ??
|
|
62
|
+
flagVal("recipient");
|
|
63
|
+
const amount = (a ? strField(a, "amount", "value", "qty") : undefined) ?? flagVal("amount");
|
|
64
|
+
const asset = resolveAsset(token ?? "");
|
|
65
|
+
const src = cmdStr ?? toolName;
|
|
66
|
+
const op = /\bswap\b/i.test(src)
|
|
67
|
+
? "swap"
|
|
68
|
+
: /\b(approve|erc20)\b/i.test(src)
|
|
69
|
+
? "approve"
|
|
70
|
+
: "transfer";
|
|
71
|
+
return {
|
|
72
|
+
operation: op,
|
|
73
|
+
asset,
|
|
74
|
+
amount,
|
|
75
|
+
recipient_status: to ? "external" : "unspecified",
|
|
76
|
+
note: "canonicalized pre-judge; raw 0x addresses omitted (redacted upstream)",
|
|
77
|
+
};
|
|
78
|
+
}
|
|
1
79
|
/** @internal */
|
|
2
80
|
export function mapEventToInput(event, ctx) {
|
|
3
81
|
const ev = (event ?? {});
|
|
@@ -15,5 +93,5 @@ export function mapEventToInput(event, ctx) {
|
|
|
15
93
|
channel_id: ctx.channelId ?? "",
|
|
16
94
|
account_id: ctx.accountId ?? "",
|
|
17
95
|
});
|
|
18
|
-
return { toolName, args, context };
|
|
96
|
+
return { toolName, args, context, resolved: canonicalizeFinancial(toolName, args) };
|
|
19
97
|
}
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`);return e.logger?.warn?.("[atbash] HOLD",{reason:
|
|
1
|
+
"use strict";var g=Object.defineProperty;var E=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var I=Object.prototype.hasOwnProperty;var R=(o,e)=>{for(var n in e)g(o,n,{get:e[n],enumerable:!0})},_=(o,e,n,a)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of T(e))!I.call(o,t)&&t!==n&&g(o,t,{get:()=>e[t],enumerable:!(a=E(e,t))||a.enumerable});return o};var v=o=>_(g({},"__esModule",{value:!0}),o);var j={};R(j,{default:()=>y});module.exports=v(j);var d=require("@atbash/sdk");var S="atbash-openclaw";function h(o){return o.config?.plugins?.entries?.[S]?.config??{}}var x={"0xdac17f958d2ee523a2206206994597c13d831ec7":"USDT","0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48":"USDC","0x6b175474e89094c44da98b954eedeac495271d0f":"DAI","0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2":"WETH","0x2260fac5e5542a773aa44fbcfedf7c193bc2c599":"WBTC","0x1f9840a85d5af5bf1d1762f925bdaddc4201f984":"UNI","0x514910771af9ca656af840dff83e8264ecf986ca":"LINK","0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9":"AAVE","0xb0df6379ba1692841965a0745ac1bd3046d79ba3":"ATBASH","0xe9c094187219d9a29382c1a36fc43619c9257777":"ATBASH","0xf8b071428558c657a7a9aa1c43e152e75dd77777":"ATBASH"},m=/\b(0x[a-fA-F0-9]{40})\b/,k=/(0x[a-fA-F0-9]{40})/,w=/\b(transfer|send|swap|approve|erc20)\b/i;function D(o){if(!o)return"ETH";let e=o.toLowerCase(),n=k.exec(e);return n?x[n[1].toLowerCase()]??"other":e==="c60"||e==="eth"?"ETH":e==="atbash"?"ATBASH":e==="usdt"||e==="tether"?"USDT":e==="usdc"?"USDC":"other"}function b(o,...e){for(let n of e){let a=o[n];if(typeof a=="string"&&a.trim())return a.trim()}}function L(o,e){let n=e!==null&&typeof e=="object"&&!Array.isArray(e)?e:void 0,a=n?b(n,"command","cmd","shell_command"):void 0,t=w.test(o),c=a?w.test(a):!1,f=a?m.test(a):!1;if(!t&&!c&&!f)return;let s=u=>a?new RegExp(`--${u}[= ]+(\\S+)`).exec(a)?.[1]:void 0,r=(n?b(n,"token","token_address","asset","currency"):void 0)??s("token");if(!r&&a){let u=m.exec(a);u&&(r=u[1])}let i=(n?b(n,"to","recipient","destination"):void 0)??s("to")??s("recipient"),l=(n?b(n,"amount","value","qty"):void 0)??s("amount"),C=D(r??""),p=a??o;return{operation:/\bswap\b/i.test(p)?"swap":/\b(approve|erc20)\b/i.test(p)?"approve":"transfer",asset:C,amount:l,recipient_status:i?"external":"unspecified",note:"canonicalized pre-judge; raw 0x addresses omitted (redacted upstream)"}}function A(o,e){let n=o??{},a=n.toolName??e.tool?.name??e.toolName??e.name??"unknown",t=n.params??e.params??n.args??e.args??n.arguments??e.arguments,c=JSON.stringify({tool_name:a,session_id:e.sessionKey??"",run_id:e.runId??"",agent_id:e.agentId??"",channel_id:e.channelId??"",account_id:e.accountId??""});return{toolName:a,args:t,context:c,resolved:L(a,t)}}function N(o){if(o.judgeEndpoint)return o.judgeEndpointPolicy==="self-hosted"?{policy:"self-hosted",endpoint:o.judgeEndpoint,verifyPubKey:o.judgeVerifyPubKey??""}:{policy:"default",endpoint:o.judgeEndpoint}}function y(o){let e=o,n=h(e);if(n.enabled===!1){e.logger?.info?.("[atbash] plugin disabled via config");return}(0,d.setupTelemetry)({enabled:!0,source:"plugin:openclaw"}),process.once("beforeExit",()=>(0,d.shutdownTelemetry)()),process.once("SIGINT",()=>(0,d.shutdownTelemetry)().finally(()=>process.exit(0))),process.once("SIGTERM",()=>(0,d.shutdownTelemetry)().finally(()=>process.exit(0)));let a;try{a=d.Atbash.fromConfig({judge:N(n),keyPath:n.chromiaSecretPath,orgName:n.orgName,failClosed:n.enforceDecision!==!1,logger:e.logger})}catch(c){let f=c instanceof Error?c.message:String(c);throw e.logger?.warn?.("[atbash] init failed",{error:f}),c}let t=n.enforceDecision!==!1;if(e.logger?.info?.("[atbash] plugin loaded",{enforceDecision:t}),!e.on){e.logger?.warn?.("[atbash] on() API not available");return}e.on("before_tool_call",async(c,f)=>{let s;try{s=await a.auditToolCall(A(c,f))}catch(i){let l=i instanceof Error?i.message:String(i);return e.logger?.warn?.("[atbash] unexpected error",{error:l}),t?{block:!0,blockReason:`Atbash unavailable: ${l}`,allow:!1,reason:`Atbash unavailable: ${l}`}:{allow:!0}}let r=s.reason??"";switch(s.verdict){case"BLOCK":return e.logger?.warn?.("[atbash] BLOCK",{reason:r}),t?{block:!0,blockReason:r,allow:!1,reason:r}:{allow:!0};case"HOLD":{let i=["Action held for operator review. The agent will not be jailed \u2014 please approve or reject this request from the Atbash dashboard, then ask the agent to try again.",`Reason: ${r}`];s.toolCallId&&i.push(`Tool Call ID: ${s.toolCallId}`);let l=i.join(`
|
|
2
|
+
`);return e.logger?.warn?.("[atbash] HOLD",{reason:r,toolCallId:s.toolCallId}),t?{block:!0,blockReason:l,allow:!1,reason:l}:{allow:!0}}case"ERROR":return e.logger?.warn?.("[atbash] ERROR",{reason:r}),t?{block:!0,blockReason:r,allow:!1,reason:r}:{allow:!0};case"ALLOW":default:return e.logger?.info?.("[atbash] ALLOW",{reason:r}),{allow:!0}}})}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atbash/atbash-openclaw",
|
|
3
|
-
"version": "0.1.13-dev.
|
|
3
|
+
"version": "0.1.13-dev.5",
|
|
4
4
|
"description": "OpenClaw ATBASH tool-audit plugin. Thin adapter that maps OpenClaw's before_tool_call hook onto @atbash/sdk.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
]
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@atbash/sdk": "0.5.
|
|
35
|
+
"@atbash/sdk": "0.5.8-dev.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@types/node": "^25.7.0",
|