@oracle-agent/oracle 0.28.27 → 0.28.29

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.
Files changed (57) hide show
  1. package/README.md +10 -3
  2. package/SETUP.md +3 -0
  3. package/dist/assets/skills/bankrbot/SKILL.md +24 -0
  4. package/dist/assets/skills/oracle-agentic-crypto/SKILL.md +39 -0
  5. package/dist/assets/skills/oracle-chain-graphs-telegram-cards/SKILL.md +2 -0
  6. package/dist/assets/skills/oracle-desk-product/SKILL.md +1 -1
  7. package/dist/assets/skills/oracle-uniswap-v4-hooks/SKILL.md +31 -0
  8. package/dist/assets/skills/oracle-x402/SKILL.md +30 -0
  9. package/dist/bin/desk-server.mjs +28 -26
  10. package/dist/bin/oracle-data-mcp.mjs +32 -12
  11. package/dist/bin/oracle-gateway.mjs +39 -26
  12. package/dist/bin/oracle-mev-arb-shadow.mjs +5 -5
  13. package/dist/bin/oracle-mev-shadow.mjs +5 -5
  14. package/dist/bin/oracle-public-server.mjs +4 -4
  15. package/dist/bin/oracle-route.mjs +15 -15
  16. package/dist/bin/oracle-scan.mjs +11 -11
  17. package/dist/bin/oracle.mjs +4 -3
  18. package/dist/cli/commands/auth.mjs +6 -6
  19. package/dist/cli/commands/chat.mjs +155 -155
  20. package/dist/cli/commands/doctor.mjs +1 -1
  21. package/dist/cli/commands/eval.mjs +77 -77
  22. package/dist/cli/commands/harness.mjs +4 -4
  23. package/dist/cli/commands/model.mjs +157 -157
  24. package/dist/cli/commands/receipt.mjs +1 -1
  25. package/dist/cli/commands/setup.mjs +23 -23
  26. package/dist/cli/commands/signer.mjs +8 -8
  27. package/dist/cli/commands/snipe.mjs +24 -0
  28. package/dist/cli/commands/swap.mjs +25 -25
  29. package/dist/cli/commands/venues.mjs +1 -1
  30. package/dist/control/approval-binding.mjs +1 -0
  31. package/dist/control/finality.mjs +1 -0
  32. package/dist/control-plane/index.mjs +6 -0
  33. package/dist/data/desk-data.mjs +26 -24
  34. package/dist/governance-prepare.mjs +2 -0
  35. package/dist/index.mjs +44 -31
  36. package/dist/local-marketplace.mjs +3 -0
  37. package/dist/local-pack-registry.mjs +3 -0
  38. package/dist/local-signer/index.mjs +3 -3
  39. package/dist/local-signer/runtime.mjs +8 -8
  40. package/dist/local-x402.mjs +3 -0
  41. package/dist/nft/index.mjs +1 -1
  42. package/dist/notifications/index.mjs +3 -0
  43. package/dist/position-health.mjs +2 -0
  44. package/dist/router/index.mjs +2 -2
  45. package/dist/router/prepare-bridge.mjs +2 -2
  46. package/dist/safety-intelligence.mjs +1 -0
  47. package/dist/scanner/index.mjs +3 -3
  48. package/dist/task.d.mts +130 -0
  49. package/dist/task.mjs +2 -0
  50. package/dist/tax-lots.mjs +5 -0
  51. package/dist/tenant-rbac.mjs +1 -0
  52. package/dist/workflow-telemetry.mjs +1 -0
  53. package/package.json +17 -2
  54. package/public/agent-connect/index.html +2 -2
  55. package/public/install.sh +2 -2
  56. package/public/oracle-splash/index.html +2 -2
  57. package/public/oracle-splash/install.sh +2 -2
@@ -0,0 +1,3 @@
1
+ import ut from"node:path";import{homedir as _t}from"node:os";import{createHash as xt,randomUUID as Rt}from"node:crypto";import l from"node:fs";import z from"node:path";import{createHash as gt,randomUUID as it}from"node:crypto";var Q=1,w=class extends Error{constructor(e,n="DURABLE_STORE_ERROR"){super(e),this.name="DurableStoreError",this.code=n}};function j(t){if(t===null)return"null";if(typeof t=="string"||typeof t=="boolean")return JSON.stringify(t);if(typeof t=="number"){if(!Number.isFinite(t))throw new TypeError("durable store values must contain finite numbers");return JSON.stringify(t)}if(Array.isArray(t))return`[${t.map(j).join(",")}]`;if(t&&typeof t=="object")return`{${Object.keys(t).sort().map(n=>`${JSON.stringify(n)}:${j(t[n])}`).join(",")}}`;throw new TypeError(`durable store values must be JSON-safe, got ${typeof t}`)}function ot(t){return gt("sha256").update(j(t)).digest("hex")}function q(t){let e=t(),n=e instanceof Date?e.getTime():typeof e=="string"?Date.parse(e):Number(e);if(!Number.isFinite(n))throw new TypeError("clock must return epoch milliseconds, an ISO string, or a Date");return Math.trunc(n)}function B(t){return t===void 0?void 0:JSON.parse(JSON.stringify(t))}function at(t){l.mkdirSync(t,{recursive:!0,mode:448});try{l.chmodSync(t,448)}catch{}}function v(t){try{let e=l.statSync(t);return{...JSON.parse(l.readFileSync(t,"utf8")),mtimeMs:e.mtimeMs}}catch{return null}}function ct({filePath:t,kind:e,initialData:n,validateData:s,clock:p=()=>Date.now(),maxBytes:y=4*1024*1024,lockStaleMs:x=3e4,lockWaitMs:D=2e3,lockIdFactory:G=()=>it()}={}){if(typeof t!="string"||t==="")throw new TypeError("filePath is required");if(!/^[a-z][a-z0-9._-]{0,63}$/i.test(String(e)))throw new TypeError("a bounded store kind is required");if(typeof n!="function"||typeof s!="function")throw new TypeError("initialData and validateData are required");if(!Number.isSafeInteger(y)||y<1024)throw new TypeError("maxBytes must be at least 1024");if(!Number.isSafeInteger(x)||x<1e3)throw new TypeError("lockStaleMs must be at least 1000");if(!Number.isSafeInteger(D)||D<0||D>3e4)throw new TypeError("lockWaitMs must be between 0 and 30000");let N=`${t}.lock`;function F(){let o=n();return s(o),{schemaVersion:Q,kind:e,generation:0,data:o}}function X(o){let c;try{c=JSON.parse(o)}catch(a){throw new w(`corrupt ${e} snapshot: invalid JSON (${a.message})`,"STORE_CORRUPT")}if(!c||typeof c!="object"||Array.isArray(c))throw new w(`corrupt ${e} snapshot: root must be an object`,"STORE_CORRUPT");if(c.schemaVersion!==Q)throw new w(`unsupported ${e} schemaVersion ${String(c.schemaVersion)}`,"STORE_SCHEMA");if(c.kind!==e||!Number.isSafeInteger(c.generation)||c.generation<0)throw new w(`corrupt ${e} snapshot metadata`,"STORE_CORRUPT");let{integrity:d,...f}=c;if(typeof d!="string"||!/^[a-f0-9]{64}$/.test(d)||ot(f)!==d)throw new w(`corrupt ${e} snapshot: checksum mismatch`,"STORE_CORRUPT");try{s(c.data)}catch(a){throw new w(`corrupt ${e} snapshot: ${a.message}`,"STORE_CORRUPT")}return f}function k(){if(!l.existsSync(t))return F();let o=l.statSync(t);if(!o.isFile()||o.size>y)throw new w(`${e} snapshot is not a bounded regular file`,"STORE_BOUNDS");try{l.chmodSync(t,384)}catch{}return X(l.readFileSync(t,"utf8"))}function Y(){at(z.dirname(t));let o=q(p),c=String(G()),d=`${JSON.stringify({schemaVersion:1,lockId:c,pid:process.pid,acquiredAt:o})}
2
+ `,f=()=>{let g;try{return g=l.openSync(N,"wx",384),l.writeFileSync(g,d,"utf8"),l.fsyncSync(g),l.closeSync(g),{lockId:c}}catch(O){let A=g!==void 0;if(A)try{l.closeSync(g)}catch{}if(A)try{l.unlinkSync(N)}catch{}if(O?.code!=="EEXIST")throw O;return null}},u=q(p)+D,b=new Int32Array(new SharedArrayBuffer(4));for(;;){let g=f();if(g)return g;let O=q(p),A=v(N),R=!1;if(A){let _=O-Number(A.acquiredAt??A.mtimeMs);R=Number.isFinite(_)&&_>=x}else try{R=O-l.statSync(N).mtimeMs>=x}catch{R=!1}if(R){let _=v(N);if(A?_?.lockId===A.lockId:_===null){try{l.unlinkSync(N)}catch(E){if(E?.code!=="ENOENT")throw E}continue}}let $=u-O;if($<=0)throw new w(`${e} store is busy`,"STORE_BUSY");Atomics.wait(b,0,0,Math.min(10,$))}}function Z(o){if(v(N)?.lockId===o.lockId)try{l.unlinkSync(N)}catch(d){if(d?.code!=="ENOENT")throw d}}function i(o){s(o.data);let c={...o,integrity:ot(o)},d=`${j(c)}
3
+ `;if(Buffer.byteLength(d)>y)throw new w(`${e} snapshot exceeds ${y} bytes`,"STORE_BOUNDS");let f=z.dirname(t);at(f);let a=z.join(f,`.${z.basename(t)}.${process.pid}.${it()}.tmp`),u;try{u=l.openSync(a,"wx",384),l.writeFileSync(u,d,"utf8"),l.fsyncSync(u),l.closeSync(u),u=void 0,l.renameSync(a,t);try{l.chmodSync(t,384)}catch{}try{let b=l.openSync(f,"r");try{l.fsyncSync(b)}finally{l.closeSync(b)}}catch{}}finally{if(u!==void 0)try{l.closeSync(u)}catch{}try{l.unlinkSync(a)}catch(b){if(b?.code!=="ENOENT")throw b}}}function m(){return B(k().data)}function I(){let o=k();return{schemaVersion:o.schemaVersion,kind:o.kind,generation:o.generation,data:B(o.data)}}function h(o){if(typeof o!="function")throw new TypeError("mutator must be a function");let c=Y();try{let d=k(),f=B(d.data),a=o(f,{generation:d.generation,now:q(p)});return s(f),i({schemaVersion:Q,kind:e,generation:d.generation+1,data:f}),B(a)}finally{Z(c)}}return Object.freeze({filePath:t,read:m,inspect:I,mutate:h})}import{wordlists as ht}from"ethers";var yt=new Set(["privatekey","privkey","secretkey","seedphrase","seed","mnemonic","passphrase","password","keystore","keymaterial","wif","xprv","xpriv","bearer","authorization","signature","apikey","credential"]),It=[/\b[5KL][1-9A-HJ-NP-Za-km-z]{50,51}\b/,/\bxprv[0-9A-Za-z]{50,}\b/],bt=new Set([12,15,18,21,24]);function St(t){let e=String(t).trim().toLowerCase().split(/\s+/).filter(Boolean);return bt.has(e.length)&&e.every(n=>ht.en.getWordIndex(n)>=0)}var At=/^\s*(?:0x)?[0-9a-fA-F]{64}\s*$/,Ot=/(hash|digest|root|salt|nonce|proof|commitment|sig|id)(?:e?s)?$/i,Et=new Set(["calldata","data","publickey","pubkey","message","payload","input","extradata"]);function Tt(t){let e=ft(t);return Et.has(e)||Ot.test(e)}var V=class extends Error{constructor(e){super(`action receipt refused: secret-bearing field at ${e}`),this.name="ActionReceiptSecretError",this.code="ACTION_RECEIPT_SECRET"}};function ft(t){return String(t).replace(/[^a-z0-9]/gi,"").toLowerCase()}function wt(t){let e=ft(t);return[...yt].some(n=>e.includes(n))}function Nt(t,e,n){if(typeof e=="string"){if(It.some(s=>s.test(e))||St(e))throw new V(n);if(At.test(e)&&!Tt(t))throw new V(n)}}function tt(t,e="$",n=""){if(t==null||typeof t=="boolean")return t;if(typeof t=="string")return Nt(n,t,e),t;if(typeof t=="number"){if(!Number.isFinite(t))throw new TypeError(`action receipt: non-finite number at ${e}`);return t}if(typeof t=="bigint")return t.toString();if(Array.isArray(t))return t.map((p,y)=>tt(p,`${e}[${y}]`,n));if(typeof t!="object"||Object.getPrototypeOf(t)!==Object.prototype)throw new TypeError(`action receipt: JSON-like value required at ${e}`);let s={};for(let p of Object.keys(t).sort()){let y=`${e}.${p}`;if(wt(p))throw new V(y);t[p]!==void 0&&(s[p]=tt(t[p],y,p))}return s}function et(t){return tt(t)}var K=1,dt="Local catalog only; existing marketplace providers are unchanged. Armed for the owner-local signer. Sign/broadcast require an explicit instruction.",te=Object.freeze(["listing","offer","arm","instruct"]),$t=Object.freeze(["open","cancelled","expired","armed","submitted"]),ee=Object.freeze(["arm","sign-and-broadcast"]),lt=Object.freeze({protocol:"oracle-a2a/1",name:"oracle-local-marketplace",brand:"Oracle",publisher:"Oracle",product:"Oracle",role:"Oracle owner-local P2 catalog",consultOnly:!0,remoteDelegation:!1,pluginExecution:!1,refusesSignHash:!0,skills:Object.freeze(["list-local-listings"]),note:"Oracle consult-only local Agent Card. Untrusted A2A text cannot create, fill, cancel, sign, or broadcast listings. Existing marketplace providers are unchanged. No plugin pack loader."}),Ht=/^(?:0|[1-9][0-9]*)$/,Ct=/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/,Lt=/^0x[a-fA-F0-9]{40}$/,Dt=/^0x[a-fA-F0-9]{64}$/,jt=/[\u0000-\u001f\u007f]/,Ft=new Set($t),st=class extends Error{constructor(e,n="LOCAL_MARKETPLACE_INVALID"){super(`local-marketplace: ${e}`),this.name="LocalMarketplaceError",this.code=n}};function r(t,e){throw new st(t,e)}function L(t){if(t&&typeof t=="object"&&!Object.isFrozen(t)){for(let e of Object.values(t))L(e);Object.freeze(t)}return t}function M(t,e,{max:n=256,lower:s=!1}={}){typeof t!="string"&&r(`${e} must be a string`);let p=t.trim();return(!p||p.length>n||jt.test(p))&&r(`${e} is invalid`),s?p.toLowerCase():p}function S(t,e){let n=M(t,e,{max:128});return Ct.test(n)||r(`${e} must be a bounded id`),n}function P(t,e,{positive:n=!1}={}){typeof t=="number"&&r(`${e} must be an exact integer string`);let s=typeof t=="bigint"?t.toString():String(t??"");return Ht.test(s)||r(`${e} must be a canonical integer string`),n&&s==="0"&&r(`${e} must be positive`),s}function C(t,e){let n=M(t,e,{max:42,lower:!0});return Lt.test(n)||r(`${e} must be a 20-byte EVM address`),n}function pt(t,e){return(!t||typeof t!="object"||Array.isArray(t)||Object.getPrototypeOf(t)!==Object.prototype)&&r(`${e} must be a plain object`),t}function H(t){let e=t(),n=e instanceof Date?e.getTime():typeof e=="string"?Date.parse(e):Number(e);return(!Number.isSafeInteger(n)||n<0)&&r("clock must return a safe integer millisecond timestamp","CLOCK_INVALID"),n}function nt(t){return new Date(t).toISOString()}function kt(t){return xt("sha256").update(j(t),"utf8").digest("hex")}function Ut(t=process.env){let e=t.ORACLE_CONFIG_DIR||ut.join(_t(),".config","oracle");return ut.join(e,"local-marketplace.v1.json")}function J(t){let e=t.status==="submitted";return L({schemaVersion:K,listingId:t.listingId,tenantId:t.tenantId,seller:t.seller,asset:t.asset,amount:t.amount,price:t.price,chainId:t.chainId,status:Ft.has(t.status)?t.status:r("invalid listing status","STORE_INVALID"),createdAt:t.createdAt,expiresAt:t.expiresAt,listingHash:t.listingHash,offers:(t.offers||[]).map(n=>L({offerId:n.offerId,buyer:n.buyer,amount:n.amount,status:n.status,createdAt:n.createdAt})),transactionHash:t.transactionHash||null,label:dt,custody:"none",execution:e?"local-signer-instructed":"armed-local",armed:!e,signed:e,broadcast:e})}function Vt(t){(!t||t.schemaVersion!==K||!Array.isArray(t.listings))&&r("invalid marketplace snapshot","STORE_INVALID"),t.listings.length>1e4&&r("marketplace capacity exceeded","STORE_LIMIT")}function rt(t,e){return L({schemaVersion:K,recordType:"local-marketplace-armed",listingId:t.listingId,offerId:e.offerId,tenantId:t.tenantId,seller:t.seller,buyer:e.buyer,asset:t.asset,amount:e.amount,price:t.price,chainId:t.chainId,listingHash:t.listingHash,unsigned:{kind:"local-p2-fill",from:t.seller,to:e.buyer,asset:t.asset,amount:e.amount,price:t.price,chainId:t.chainId},review:`Local P2 fill ${t.listingId} is armed for the owner-local signer: seller ${t.seller} transfers ${e.amount} ${t.asset} to ${e.buyer} at ${t.price} on chain ${t.chainId}. Sign and broadcast still require an explicit instruction.`,label:dt,custody:"none",execution:"armed-local",armed:!0,signed:!1,broadcast:!1,requiresWalletSignature:!0,backendSigner:!1,refusesSignHash:!0})}function Pt(t,e,n){typeof t=="string"&&r("raw hash artifacts are refused; pass a typed local-signer artifact","SIGNHASH_REFUSED");let s=pt(t,"instruction.artifact");(Object.prototype.hasOwnProperty.call(s,"signHash")||Object.prototype.hasOwnProperty.call(s,"hashToSign"))&&r("generic signHash is refused","SIGNHASH_REFUSED");let p=C(s.from??s.offerer??e.seller,"artifact.from"),y=C(s.to??s.recipient??n.buyer,"artifact.to"),x=P(s.chainId??e.chainId,"artifact.chainId",{positive:!0});return p!==e.seller&&r("artifact.from must match the seller","ARTIFACT_MISMATCH"),y!==n.buyer&&r("artifact.to must match the buyer","ARTIFACT_MISMATCH"),x!==e.chainId&&r("artifact.chainId must match the listing","ARTIFACT_MISMATCH"),s.listingHash&&s.listingHash!==e.listingHash&&r("artifact.listingHash must match the listing","ARTIFACT_MISMATCH"),s}function Mt(t,e){if(t==null)return{action:"arm"};let n=pt(t,"instruction");Object.prototype.hasOwnProperty.call(n,"signHash")&&n.signHash!==!1&&r("generic signHash is refused","SIGNHASH_REFUSED");let s=M(n.action??"arm","instruction.action",{max:64});return s==="arm"?{action:"arm"}:(s==="prepare"&&r("prepare is refused; arm the listing, then instruct sign-and-broadcast","INSTRUCTION_INVALID"),s!=="sign-and-broadcast"&&r("instruction.action must be arm or sign-and-broadcast","INSTRUCTION_INVALID"),n.confirm!==!0&&r("sign-and-broadcast requires confirm: true","INSTRUCTION_INVALID"),n.sign!==!0&&r("sign-and-broadcast requires sign: true","INSTRUCTION_INVALID"),n.broadcast!==!0&&r("sign-and-broadcast requires broadcast: true","INSTRUCTION_INVALID"),n.listingHash&&n.listingHash!==e.listingHash&&r("instruction.listingHash must match the listing","ARTIFACT_MISMATCH"),n)}function zt({filePath:t=Ut(),clock:e=()=>Date.now(),idFactory:n=()=>Rt()}={}){let s=ct({filePath:t,kind:"oracle-local-marketplace",clock:e,maxBytes:4194304,initialData:()=>({schemaVersion:K,listings:[]}),validateData:Vt});function p(i,m){return i.tenantId===m}function y(i,m){return i.status==="open"&&Date.parse(i.expiresAt)<=m&&(i.status="expired"),i}function x(i={}){et(i);let m=S(i.tenantId,"tenantId"),I=C(i.seller,"seller"),h=M(i.asset,"asset",{max:128}),o=P(i.amount,"amount",{positive:!0}),c=P(i.price,"price",{positive:!0}),d=P(i.chainId,"chainId",{positive:!0}),f=H(e),a=nt(f),u=i.expiresAt==null?nt(f+864e5):M(i.expiresAt,"expiresAt",{max:64});(!Number.isFinite(Date.parse(u))||Date.parse(u)<=f)&&r("expiresAt must be after now");let b=S(String(i.listingId??`listing-${n()}`),"listingId");return s.mutate(g=>{g.listings.some(R=>R.listingId===b)&&r("listingId already exists","DUPLICATE");let O={listingId:b,tenantId:m,seller:I,asset:h,amount:o,price:c,chainId:d,status:"open",createdAt:a,expiresAt:u,offers:[],custody:"none",execution:"armed-local"},A={...O,listingHash:kt(O)};return g.listings.push(A),J(A)})}function D({tenantId:i}={}){let m=S(i,"tenantId"),I=H(e);return L(s.read().listings.filter(h=>p(h,m)).map(h=>J(y({...h,offers:h.offers.map(o=>({...o}))},I))))}function G({tenantId:i,listingId:m,actor:I}={}){let h=S(i,"tenantId"),o=S(m,"listingId"),c=C(I,"actor"),d=H(e);return s.mutate(f=>{let a=f.listings.find(u=>p(u,h)&&u.listingId===o);return a||r("listing not found","NOT_FOUND"),y(a,d),a.seller!==c&&r("only the seller can cancel","FORBIDDEN"),a.status!=="open"&&r("listing is not open","NOT_OPEN"),a.status="cancelled",J(a)})}function N(i={}){et(i);let m=S(i.tenantId,"tenantId"),I=S(i.listingId,"listingId"),h=C(i.buyer,"buyer"),o=P(i.amount,"amount",{positive:!0}),c=H(e),d=S(String(i.offerId??`offer-${n()}`),"offerId");return s.mutate(f=>{let a=f.listings.find(u=>p(u,m)&&u.listingId===I);return a||r("listing not found","NOT_FOUND"),y(a,c),a.status!=="open"&&r("listing is not open","NOT_OPEN"),a.seller===h&&r("seller cannot offer on their own listing","FORBIDDEN"),a.offers.some(u=>u.offerId===d)&&r("offerId already exists","DUPLICATE"),a.offers.push({offerId:d,buyer:h,amount:o,status:"open",createdAt:nt(c)}),J(a)})}function F(i,{tenantId:m,listingId:I,offerId:h,actor:o,now:c,allowed:d=["open","armed"]}){let f=i.listings.find(u=>p(u,m)&&u.listingId===I);f||r("listing not found","NOT_FOUND"),y(f,c),d.includes(f.status)||r("listing is not open","NOT_OPEN"),f.seller!==o&&r("only the seller can arm a fill","FORBIDDEN");let a=f.offers.find(u=>u.offerId===h);return(!a||!["open","armed"].includes(a.status))&&r("offer not found","NOT_FOUND"),{row:f,offer:a}}function X({tenantId:i,listingId:m,offerId:I,actor:h}={}){let o=S(i,"tenantId"),c=S(m,"listingId"),d=S(I,"offerId"),f=C(h,"actor"),a=H(e);return s.mutate(u=>{let{row:b,offer:g}=F(u,{tenantId:o,listingId:c,offerId:d,actor:f,now:a});return b.status="armed",g.status="armed",rt(b,g)})}async function k({tenantId:i,listingId:m,offerId:I,actor:h,instruction:o,executor:c}={}){let d=S(i,"tenantId"),f=S(m,"listingId"),a=S(I,"offerId"),u=C(h,"actor"),b=H(e),g=s.mutate(E=>{let{row:T,offer:U}=F(E,{tenantId:d,listingId:f,offerId:a,actor:u,now:b,allowed:["open","armed"]}),mt=Mt(o,T);return T.status="armed",U.status="armed",{armed:rt(T,U),instruction:mt,listingHash:T.listingHash}});if(g.instruction.action==="arm")return g.armed;let O=s.read().listings.find(E=>E.listingId===f&&E.tenantId===d),A=O?.offers.find(E=>E.offerId===a),R=Pt(g.instruction.artifact,O,A);(!c||typeof c.executeConfirmedArtifact!="function")&&r("sign-and-broadcast requires an injected local-signer executor","EXECUTOR_REQUIRED"),typeof c.signHash=="function"&&r("generic signHash executors are refused","SIGNHASH_REFUSED");let $=await c.executeConfirmedArtifact(R,g.instruction.nonce,c),_=$?.receipt?.transactionHash??$?.transactionHash;(typeof _!="string"||!Dt.test(_))&&r("local-signer receipt must include a 32-byte transaction hash","RECEIPT_INVALID");let W=$?.receipt?.status??$?.status;return W!==1&&W!=="0x1"&&r("local-signer broadcast did not return a successful receipt","RECEIPT_INVALID"),s.mutate(E=>{let{row:T,offer:U}=F(E,{tenantId:d,listingId:f,offerId:a,actor:u,now:H(e),allowed:["armed"]});return T.status="submitted",U.status="submitted",T.transactionHash=_.toLowerCase(),L({...rt(T,U),recordType:"local-marketplace-submitted",execution:"local-signer-instructed",armed:!1,signed:!0,broadcast:!0,backendSigner:!0,requiresWalletSignature:!1,refusesSignHash:!0,transactionHash:T.transactionHash,review:`Local P2 fill ${T.listingId} signed and broadcast through the instructed local signer. transactionHash=${T.transactionHash}`})})}function Y({tenantId:i,text:m}={}){return S(i,"tenantId"),(typeof m!="string"||m.trim()==="")&&r("consult text required"),L({accepted:!1,reason:"untrusted consult text cannot create, fill, or cancel listings",custody:"none",execution:"armed-local",armed:!0,signed:!1,broadcast:!1})}function Z(){return lt}return Object.freeze({createListing:x,listListings:D,cancelListing:G,createOffer:N,armFill:X,instructFill:k,ingestUntrustedConsult:Y,agentCard:Z})}function ne(){return lt}var re=zt;export{lt as LOCAL_MARKETPLACE_AGENT_CARD,ee as LOCAL_MARKETPLACE_INSTRUCTIONS,te as LOCAL_MARKETPLACE_KINDS,dt as LOCAL_MARKETPLACE_LABEL,$t as LOCAL_MARKETPLACE_STATES,K as LOCAL_MARKETPLACE_VERSION,st as LocalMarketplaceError,zt as createLocalMarketplace,re as createLocalP2Marketplace,ne as localMarketplaceAgentCard};
@@ -0,0 +1,3 @@
1
+ import ne from"node:path";import{homedir as be}from"node:os";import{randomUUID as ge}from"node:crypto";import o from"node:fs";import j from"node:path";import{createHash as ie,randomUUID as Z}from"node:crypto";var V=1,y=class extends Error{constructor(t,n="DURABLE_STORE_ERROR"){super(t),this.name="DurableStoreError",this.code=n}};function z(e){if(e===null)return"null";if(typeof e=="string"||typeof e=="boolean")return JSON.stringify(e);if(typeof e=="number"){if(!Number.isFinite(e))throw new TypeError("durable store values must contain finite numbers");return JSON.stringify(e)}if(Array.isArray(e))return`[${e.map(z).join(",")}]`;if(e&&typeof e=="object")return`{${Object.keys(e).sort().map(n=>`${JSON.stringify(n)}:${z(e[n])}`).join(",")}}`;throw new TypeError(`durable store values must be JSON-safe, got ${typeof e}`)}function Q(e){return ie("sha256").update(z(e)).digest("hex")}function H(e){let t=e(),n=t instanceof Date?t.getTime():typeof t=="string"?Date.parse(t):Number(t);if(!Number.isFinite(n))throw new TypeError("clock must return epoch milliseconds, an ISO string, or a Date");return Math.trunc(n)}function P(e){return e===void 0?void 0:JSON.parse(JSON.stringify(e))}function W(e){o.mkdirSync(e,{recursive:!0,mode:448});try{o.chmodSync(e,448)}catch{}}function J(e){try{let t=o.statSync(e);return{...JSON.parse(o.readFileSync(e,"utf8")),mtimeMs:t.mtimeMs}}catch{return null}}function v({filePath:e,kind:t,initialData:n,validateData:r,clock:d=()=>Date.now(),maxBytes:l=4*1024*1024,lockStaleMs:k=3e4,lockWaitMs:I=2e3,lockIdFactory:U=()=>Z()}={}){if(typeof e!="string"||e==="")throw new TypeError("filePath is required");if(!/^[a-z][a-z0-9._-]{0,63}$/i.test(String(t)))throw new TypeError("a bounded store kind is required");if(typeof n!="function"||typeof r!="function")throw new TypeError("initialData and validateData are required");if(!Number.isSafeInteger(l)||l<1024)throw new TypeError("maxBytes must be at least 1024");if(!Number.isSafeInteger(k)||k<1e3)throw new TypeError("lockStaleMs must be at least 1000");if(!Number.isSafeInteger(I)||I<0||I>3e4)throw new TypeError("lockWaitMs must be between 0 and 30000");let s=`${e}.lock`;function b(){let i=n();return r(i),{schemaVersion:V,kind:t,generation:0,data:i}}function g(i){let c;try{c=JSON.parse(i)}catch(u){throw new y(`corrupt ${t} snapshot: invalid JSON (${u.message})`,"STORE_CORRUPT")}if(!c||typeof c!="object"||Array.isArray(c))throw new y(`corrupt ${t} snapshot: root must be an object`,"STORE_CORRUPT");if(c.schemaVersion!==V)throw new y(`unsupported ${t} schemaVersion ${String(c.schemaVersion)}`,"STORE_SCHEMA");if(c.kind!==t||!Number.isSafeInteger(c.generation)||c.generation<0)throw new y(`corrupt ${t} snapshot metadata`,"STORE_CORRUPT");let{integrity:f,...p}=c;if(typeof f!="string"||!/^[a-f0-9]{64}$/.test(f)||Q(p)!==f)throw new y(`corrupt ${t} snapshot: checksum mismatch`,"STORE_CORRUPT");try{r(c.data)}catch(u){throw new y(`corrupt ${t} snapshot: ${u.message}`,"STORE_CORRUPT")}return p}function w(){if(!o.existsSync(e))return b();let i=o.statSync(e);if(!i.isFile()||i.size>l)throw new y(`${t} snapshot is not a bounded regular file`,"STORE_BOUNDS");try{o.chmodSync(e,384)}catch{}return g(o.readFileSync(e,"utf8"))}function R(){W(j.dirname(e));let i=H(d),c=String(U()),f=`${JSON.stringify({schemaVersion:1,lockId:c,pid:process.pid,acquiredAt:i})}
2
+ `,p=()=>{let S;try{return S=o.openSync(s,"wx",384),o.writeFileSync(S,f,"utf8"),o.fsyncSync(S),o.closeSync(S),{lockId:c}}catch(x){let E=S!==void 0;if(E)try{o.closeSync(S)}catch{}if(E)try{o.unlinkSync(s)}catch{}if(x?.code!=="EEXIST")throw x;return null}},h=H(d)+I,A=new Int32Array(new SharedArrayBuffer(4));for(;;){let S=p();if(S)return S;let x=H(d),E=J(s),L=!1;if(E){let N=x-Number(E.acquiredAt??E.mtimeMs);L=Number.isFinite(N)&&N>=k}else try{L=x-o.statSync(s).mtimeMs>=k}catch{L=!1}if(L){let N=J(s);if(E?N?.lockId===E.lockId:N===null){try{o.unlinkSync(s)}catch(G){if(G?.code!=="ENOENT")throw G}continue}}let X=h-x;if(X<=0)throw new y(`${t} store is busy`,"STORE_BUSY");Atomics.wait(A,0,0,Math.min(10,X))}}function _(i){if(J(s)?.lockId===i.lockId)try{o.unlinkSync(s)}catch(f){if(f?.code!=="ENOENT")throw f}}function m(i){r(i.data);let c={...i,integrity:Q(i)},f=`${z(c)}
3
+ `;if(Buffer.byteLength(f)>l)throw new y(`${t} snapshot exceeds ${l} bytes`,"STORE_BOUNDS");let p=j.dirname(e);W(p);let u=j.join(p,`.${j.basename(e)}.${process.pid}.${Z()}.tmp`),h;try{h=o.openSync(u,"wx",384),o.writeFileSync(h,f,"utf8"),o.fsyncSync(h),o.closeSync(h),h=void 0,o.renameSync(u,e);try{o.chmodSync(e,384)}catch{}try{let A=o.openSync(p,"r");try{o.fsyncSync(A)}finally{o.closeSync(A)}}catch{}}finally{if(h!==void 0)try{o.closeSync(h)}catch{}try{o.unlinkSync(u)}catch(A){if(A?.code!=="ENOENT")throw A}}}function $(){return P(w().data)}function F(){let i=w();return{schemaVersion:i.schemaVersion,kind:i.kind,generation:i.generation,data:P(i.data)}}function T(i){if(typeof i!="function")throw new TypeError("mutator must be a function");let c=R();try{let f=w(),p=P(f.data),u=i(p,{generation:f.generation,now:H(d)});return r(p),m({schemaVersion:V,kind:t,generation:f.generation+1,data:p}),P(u)}finally{_(c)}}return Object.freeze({filePath:e,read:$,inspect:F,mutate:T})}import{wordlists as ce}from"ethers";var ae=new Set(["privatekey","privkey","secretkey","seedphrase","seed","mnemonic","passphrase","password","keystore","keymaterial","wif","xprv","xpriv","bearer","authorization","signature","apikey","credential"]),fe=[/\b[5KL][1-9A-HJ-NP-Za-km-z]{50,51}\b/,/\bxprv[0-9A-Za-z]{50,}\b/],ue=new Set([12,15,18,21,24]);function de(e){let t=String(e).trim().toLowerCase().split(/\s+/).filter(Boolean);return ue.has(t.length)&&t.every(n=>ce.en.getWordIndex(n)>=0)}var pe=/^\s*(?:0x)?[0-9a-fA-F]{64}\s*$/,le=/(hash|digest|root|salt|nonce|proof|commitment|sig|id)(?:e?s)?$/i,ye=new Set(["calldata","data","publickey","pubkey","message","payload","input","extradata"]);function me(e){let t=ee(e);return ye.has(t)||le.test(t)}var C=class extends Error{constructor(t){super(`action receipt refused: secret-bearing field at ${t}`),this.name="ActionReceiptSecretError",this.code="ACTION_RECEIPT_SECRET"}};function ee(e){return String(e).replace(/[^a-z0-9]/gi,"").toLowerCase()}function he(e){let t=ee(e);return[...ae].some(n=>t.includes(n))}function Se(e,t,n){if(typeof t=="string"){if(fe.some(r=>r.test(t))||de(t))throw new C(n);if(pe.test(t)&&!me(e))throw new C(n)}}function B(e,t="$",n=""){if(e==null||typeof e=="boolean")return e;if(typeof e=="string")return Se(n,e,t),e;if(typeof e=="number"){if(!Number.isFinite(e))throw new TypeError(`action receipt: non-finite number at ${t}`);return e}if(typeof e=="bigint")return e.toString();if(Array.isArray(e))return e.map((d,l)=>B(d,`${t}[${l}]`,n));if(typeof e!="object"||Object.getPrototypeOf(e)!==Object.prototype)throw new TypeError(`action receipt: JSON-like value required at ${t}`);let r={};for(let d of Object.keys(e).sort()){let l=`${t}.${d}`;if(he(d))throw new C(l);e[d]!==void 0&&(r[d]=B(e[d],l,d))}return r}function te(e){return B(e)}var M=1,we="Oracle local pack registry. Catalog only. Packs are never executed. Not Telegram A2A.",Ke=Object.freeze(["listed","revoked"]),Ee=/^[A-Za-z0-9][A-Za-z0-9._:-]{0,127}$/,Oe=/[\u0000-\u001f\u007f]/,Ae=/^[a-f0-9]{64}$/,ke=/^(?:localhost|(?:\*\.)?(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z]{2,}|(?:\d{1,3}\.){3}\d{1,3})$/i,Ie=new Set(["read","prepare","none"]),K=class extends Error{constructor(t,n="LOCAL_PACK_INVALID"){super(`local-pack-registry: ${t}`),this.name="LocalPackRegistryError",this.code=n}};function a(e,t){throw new K(e,t)}function Y(e){if(e&&typeof e=="object"&&!Object.isFrozen(e)){for(let t of Object.values(e))Y(t);Object.freeze(e)}return e}function O(e,t,{max:n=256}={}){typeof e!="string"&&a(`${t} must be a string`);let r=e.trim();return(!r||r.length>n||Oe.test(r))&&a(`${t} is invalid`),r}function D(e,t){let n=O(e,t,{max:128});return Ee.test(n)||a(`${t} must be a bounded id`),n}function re(e,t){let n=O(e,t,{max:64}).toLowerCase();return Ae.test(n)||a(`${t} must be 64 lowercase hex`),n}function $e(e,t){let n=O(e,t,{max:2048}),r;try{r=new URL(n)}catch{a(`${t} must be an https URL`)}return r.protocol!=="https:"&&a(`${t} must be https`),(r.username||r.password)&&a(`${t} must not contain credentials`),r.toString()}function Te(e){return e==null?[]:((!Array.isArray(e)||e.length>16)&&a("outboundHosts must be a bounded array"),e.map((t,n)=>{let r=O(t,`outboundHosts[${n}]`,{max:253}).toLowerCase();return(!ke.test(r)||r==="0.0.0.0")&&a(`outboundHosts[${n}] is not an allowlisted host`),r}))}function oe(e){let t=e(),n=t instanceof Date?t.getTime():typeof t=="string"?Date.parse(t):Number(t);return(!Number.isSafeInteger(n)||n<0)&&a("clock invalid","CLOCK_INVALID"),n}function se(e){return new Date(e).toISOString()}function xe(e=process.env){let t=e.ORACLE_CONFIG_DIR||ne.join(be(),".config","oracle");return ne.join(t,"local-pack-registry.v1.json")}function q(e){return Y({schemaVersion:M,packId:e.packId,tenantId:e.tenantId,name:e.name,version:e.version,publisher:e.publisher,manifestDigest:e.manifestDigest,sbomDigest:e.sbomDigest,homepage:e.homepage,outboundHosts:e.outboundHosts,spendScope:e.spendScope,status:e.status,createdAt:e.createdAt,revokedAt:e.revokedAt,label:we,custody:"none",execution:"none",pluginExecution:!1,loaded:!1,spawned:!1,telegram:!1})}function Re(e){(!e||e.schemaVersion!==M||!Array.isArray(e.packs))&&a("invalid pack registry snapshot","STORE_INVALID"),e.packs.length>1e3&&a("pack registry capacity exceeded","STORE_LIMIT")}function _e({filePath:e=xe(),clock:t=()=>Date.now(),idFactory:n=()=>ge()}={}){let r=v({filePath:e,kind:"oracle-local-pack-registry",clock:t,maxBytes:2097152,initialData:()=>({schemaVersion:M,packs:[]}),validateData:Re});function d(s={}){te(s);let b=D(s.tenantId,"tenantId"),g=O(s.name,"name",{max:128}),w=O(s.version,"version",{max:64}),R=O(s.publisher,"publisher",{max:128}),_=re(s.manifestDigest,"manifestDigest"),m=s.sbomDigest==null?null:re(s.sbomDigest,"sbomDigest"),$=s.homepage==null?null:$e(s.homepage,"homepage"),F=Te(s.outboundHosts),T=O(s.spendScope??"none","spendScope",{max:16});Ie.has(T)||a("spendScope must be read, prepare, or none"),T!=="none"&&T!=="read"&&a("write/spend pack scopes are refused; registry is catalog-only","SCOPE_REFUSED");let i=oe(t),c=D(String(s.packId??`pack-${n()}`),"packId");return r.mutate(f=>{f.packs.some(u=>u.packId===c||u.tenantId===b&&u.name===g&&u.version===w&&u.status==="listed")&&a("pack already listed","DUPLICATE");let p={packId:c,tenantId:b,name:g,version:w,publisher:R,manifestDigest:_,sbomDigest:m,homepage:$,outboundHosts:F,spendScope:T,status:"listed",createdAt:se(i),revokedAt:null,execution:"none",pluginExecution:!1};return f.packs.push(p),q(p)})}function l({tenantId:s}={}){let b=D(s,"tenantId");return Y(r.read().packs.filter(g=>g.tenantId===b).map(q))}function k({tenantId:s,packId:b}={}){let g=D(s,"tenantId"),w=D(b,"packId"),R=oe(t);return r.mutate(_=>{let m=_.packs.find($=>$.tenantId===g&&$.packId===w);return m||a("pack not found","NOT_FOUND"),m.status!=="listed"&&a("pack is not listed","NOT_OPEN"),m.status="revoked",m.revokedAt=se(R),q(m)})}function I(){a("pack execution is refused; this registry is catalog-only","EXECUTION_REFUSED")}function U(){a("pack execution is refused; this registry is catalog-only","EXECUTION_REFUSED")}return Object.freeze({registerPack:d,listPacks:l,revokePack:k,loadPack:I,executePack:U})}var Me=_e;export{we as LOCAL_PACK_REGISTRY_LABEL,M as LOCAL_PACK_REGISTRY_VERSION,Ke as LOCAL_PACK_STATES,K as LocalPackRegistryError,_e as createLocalPackRegistry,Me as createLocalPluginPackRegistry};