@oracle-agent/oracle 0.35.6 → 0.35.8

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.
@@ -0,0 +1,2 @@
1
+ import{createHash as je}from"node:crypto";var C=1,te=Object.freeze(["chainId","agentAddress","accountAddress","actions","targets","maxValueWei","maxGasWei","maxSlippageBps","expiresAt","nonce","revocationKey"]),Ve=Object.freeze(["read","simulate"]),ne=1e4,re=1440*60,se=128,ie=256,oe=64,ae=256,ce=/^0x[0-9a-fA-F]{40}$/,We=/^[a-z][a-z0-9_-]*:[a-z0-9._-]+$/,Ce=/^[a-z][a-z0-9_-]*:\*$/,Pe=/^[A-Za-z0-9._:-]+$/,Le=/^[A-Za-z0-9._:-]+$/,ue=/^(0|[1-9][0-9]*)$/,b=class extends Error{constructor(t){let n=t.map(r=>`${r.field}: ${r.message}`);super(`invalid grant (${t.length} error${t.length===1?"":"s"}): ${n.join("; ")}`),this.name="GrantValidationError",this.errors=t}};function de(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)}function Fe(e){if(typeof e=="bigint")return e>=0n?e.toString(10):null;if(typeof e=="number")return!Number.isSafeInteger(e)||e<0?null:String(e);if(typeof e=="string"){let t=e.trim();return ue.test(t)?t:null}return null}function N(e){if(typeof e=="bigint")return e<0n||e>BigInt(Number.MAX_SAFE_INTEGER)?null:Number(e);if(typeof e=="number")return!Number.isSafeInteger(e)||e<0?null:e;if(typeof e=="string"){let t=e.trim();if(!ue.test(t))return null;let n=Number(t);return Number.isSafeInteger(n)?n:null}return null}function q(e){let t=String(e).split(":")[0];return Ve.includes(t)}function P(e,t={}){let n=[],r=(i,a)=>n.push({field:i,message:a});if(!de(e))return r("grant","grant must be a plain object"),{ok:!1,errors:n,grant:null};for(let i of Object.keys(e))te.includes(i)||r(i,"unknown field is not allowed");for(let i of te)(!(i in e)||e[i]==null)&&r(i,"required field is missing");if(n.length)return{ok:!1,errors:n,grant:null};let s={},o=N(e.chainId);o==null||o<=0?r("chainId","must be a positive integer chain id"):s.chainId=o;for(let i of["agentAddress","accountAddress"]){let a=e[i];typeof a!="string"||!ce.test(a.trim())?r(i,"must be a 0x-prefixed 20-byte hex address"):s[i]=a.trim().toLowerCase()}if(!Array.isArray(e.actions)||e.actions.length===0)r("actions","must be a non-empty array of action scopes");else if(e.actions.length>oe)r("actions",`too many actions (max ${oe})`);else{let i=[];for(let a of e.actions){let f=typeof a=="string"?a.trim():null;if(!f){r("actions","action entries must be non-empty strings");continue}if(f.includes("*")){t.allowWildcardActions===!0&&Ce.test(f)?i.push(f):r("actions",`broad wildcard action "${f}" is rejected (fail closed)`);continue}if(!We.test(f)){r("actions",`malformed action "${f}" (expected verb:resource)`);continue}i.push(f)}s.actions=[...new Set(i)].sort()}if(!Array.isArray(e.targets))r("targets","must be an array of contract addresses");else if(e.targets.length>ae)r("targets",`too many targets (max ${ae})`);else{let i=[];for(let a of e.targets){let f=typeof a=="string"?a.trim():null;if(!f||!ce.test(f)){r("targets",`target "${a}" must be a 0x-prefixed 20-byte hex address (wildcards not allowed)`);continue}i.push(f.toLowerCase())}if(s.targets=[...new Set(i)].sort(),s.targets.length===0&&Array.isArray(s.actions)){let a=s.actions.filter(f=>!q(f));(a.length>0||s.actions.length===0)&&r("targets",`empty targets are only allowed for read/simulate scopes (blocked by: ${a.join(", ")||"no valid actions"})`)}}for(let i of["maxValueWei","maxGasWei"]){let a=Fe(e[i]);a==null?r(i,"must be a non-negative integer wei amount"):s[i]=a}let c=N(e.maxSlippageBps);c==null||c>ne?r("maxSlippageBps",`must be an integer between 0 and ${ne}`):s.maxSlippageBps=c;let m=864e10,l=N(e.expiresAt);if(l==null||l<=0)r("expiresAt","must be a positive unix-seconds timestamp");else if(l>m)r("expiresAt","exceeds the max unix-seconds timestamp (pass seconds, not milliseconds)");else if(s.expiresAt=l,t.now!=null){let i=N(t.now);i==null?r("expiresAt","opts.now must be a unix-seconds integer"):l<=i?r("expiresAt",`grant is expired (expiresAt ${l} <= now ${i})`):l-i>re&&r("expiresAt",`grant exceeds the hard 24-hour TTL (${re} seconds)`)}let u=typeof e.nonce=="string"?e.nonce.trim():N(e.nonce)!=null?String(N(e.nonce)):null;!u||u.length>se||!Pe.test(u)?r("nonce",`must be a non-empty string (max ${se} chars, [A-Za-z0-9._:-])`):s.nonce=u;let d=typeof e.revocationKey=="string"?e.revocationKey.trim():null;return!d||d.length>ie||!Le.test(d)?r("revocationKey",`must be a non-empty public identifier (max ${ie} chars, [A-Za-z0-9._:-])`):s.revocationKey=d,n.length?{ok:!1,errors:n,grant:null}:{ok:!0,errors:[],grant:s}}function z(e,t={}){let{ok:n,errors:r,grant:s}=P(e,t);if(!n)throw new b(r);return s}function H(e,t={}){let n=z(e,t),s=Object.keys(n).sort().map(o=>`${JSON.stringify(o)}:${JSON.stringify(n[o])}`);return`{"version":${C},${s.join(",")}}`}function v(e,t={}){return je("sha256").update(H(e,t),"utf8").digest("hex")}function fe(e,t){let n=N(t),r=N(de(e)?e.expiresAt:null);return n==null||r==null?!0:r<=n}var Be="oracle-connect-request",Ke="oracle-unsigned-grant",me="oracle-grant-canonical-json-utf8-v1",D=class extends Error{constructor(t,n){super(`secret material must never appear in a public API object (at ${t}, rule: ${n})`),this.name="SecretLeakError",this.path=t,this.rule=n}},Ue=/(private[_-]?key|secret|bearer|keystore|mnemonic|seed[_-]?phrase|passphrase|password|api[_-]?key|access[_-]?token|auth[_-]?token|session[_-]?token|signer[_-]?url|signature)/i,qe=Object.freeze(["privkey","wif","xprv","seed"]);function le(e){let t=String(e),n=t.toLowerCase().replace(/[\s._-]+/g,"");return Ue.test(t)||qe.includes(n)}var He=Object.freeze([{rule:"raw-32-byte-hex-key",re:/^0x[0-9a-fA-F]{64}$/},{rule:"raw-32-byte-hex-bare",re:/^[0-9a-fA-F]{64}$/},{rule:"extended-private-key",re:/\b(?:xprv|tprv|yprv|zprv)[1-9A-HJ-NP-Za-km-z]{107}\b/},{rule:"bitcoin-wif",re:/\b[59KLc][1-9A-HJ-NP-Za-km-z]{50,51}\b/},{rule:"bip39-mnemonic",re:/\b(?:[a-z]{3,8}\s+){11,23}[a-z]{3,8}\b/},{rule:"bearer-token",re:/bearer\s+[A-Za-z0-9._~+/=-]+/i},{rule:"pem-private-key",re:/-----BEGIN[A-Z ]*PRIVATE KEY-----/},{rule:"keystore-path",re:/keystore/i},{rule:"signer-url",re:/https?:\/\/\S*sign/i},{rule:"authorization-header",re:/authorization\s*:/i}]),Xe=Object.freeze(["grantid","id","hash","sha256","sha256hex","checksum","txhash","transactionhash","blockhash","digest","userophash","commithash","prevhash","intenthash","canonicalhash","payloadhash","requestid"]);function $(e,t="$",n=new Set,r=""){if(e==null)return e;if(typeof e=="string"){let s=Xe.includes(String(r).toLowerCase().replace(/[_-]/g,""));for(let{rule:o,re:c}of He)if(!(s&&o.startsWith("raw-32-byte-hex"))&&c.test(e))throw new D(t,o);return e}if(typeof e!="object"||n.has(e)||(n.add(e),ArrayBuffer.isView(e)||e instanceof ArrayBuffer))return e;if(e instanceof Map){for(let[s,o]of e.entries()){if(typeof s=="string"&&le(s))throw new D(`${t}[${JSON.stringify(s)}]`,"forbidden-key-name");$(s,`${t}[key]`,n),$(o,`${t}[${String(s)}]`,n)}return e}if(e instanceof Set){let s=0;for(let o of e.values())$(o,`${t}[${s++}]`,n);return e}if(Array.isArray(e))return e.forEach((s,o)=>$(s,`${t}[${o}]`,n)),e;for(let[s,o]of Object.entries(e)){if(le(s))throw new D(`${t}.${s}`,"forbidden-key-name");$(o,`${t}.${s}`,n,s)}return e}function L(e){if(e&&typeof e=="object"&&!Object.isFrozen(e)){Object.freeze(e);for(let t of Object.values(e))L(t)}return e}function Ye(e,t){let n=Number(typeof e=="string"?e.trim():e);if(!Number.isSafeInteger(n)||n<=0)throw new b([{field:t,message:"must be a positive unix-seconds integer"}]);return n}function Je(e){if(e?.now==null)throw new b([{field:"opts.now",message:"explicit reference time is required for live grant construction"}]);return Ye(e.now,"opts.now")}function Ze(e){return new Date(e*1e3).toISOString()}function Qe(e,t){let n=e.actions.every(r=>q(r));return["ORACLE \u2014 CONNECT AGENT (unsigned grant, you sign it, we never do)","=================================================================",`Grant ID: ${t}`,`Version: ${C}`,`Chain: ${e.chainId}`,`Agent: ${e.agentAddress}`,`Your account: ${e.accountAddress}`,`Actions: ${e.actions.join(", ")}`,`Targets: ${e.targets.length?e.targets.join(", "):"(none \u2014 read/simulate only)"}`,`Max value: ${e.maxValueWei} wei`,`Max gas: ${e.maxGasWei} wei`,`Max slippage: ${e.maxSlippageBps} bps`,`Expires: ${Ze(e.expiresAt)} (unix ${e.expiresAt})`,`Nonce: ${e.nonce}`,`Revocation: ${e.revocationKey}`,"-----------------------------------------------------------------",n?"Scope: read/simulate only \u2014 this grant cannot move funds.":"Scope: includes state-changing actions bounded by the caps above.","Self-custodial: this payload is UNSIGNED and contains public data only.","Sign the bytes below with YOUR wallet; Oracle never holds your keys."].join(`
2
+ `)}function X(e={},t={}){let n=Je(t),r=e&&e.kind===Be?e.grant:e,s=z(r,{now:n,allowWildcardActions:t.allowWildcardActions===!0}),o=H(s),c=v(s),m=Buffer.from(o,"utf8"),l=L({kind:Ke,unsigned:!0,payload:L({version:C,grantId:c,grant:s,canonical:o}),signing:L({scheme:me,message:o,bytesHex:`0x${m.toString("hex")}`,byteLength:m.length,sha256:c}),render:Qe(s,c)});return $(l)}var et=Object.freeze(["grantCreated","grantActivated","grantRevoked","grantExpired"]),G=Object.freeze({ACTIVE:"active",PENDING:"pending",REVOKED:"revoked",EXPIRED:"expired",UNKNOWN:"unknown",INVALID:"invalid"}),tt=Object.freeze(["chainId","agentAddress","accountAddress","actions","targets","maxValueWei","maxGasWei","maxSlippageBps","expiresAt","nonce","revocationKey"]);function pe(e){return e!=null&&typeof e=="object"&&!Array.isArray(e)}function ge(e){return typeof e=="bigint"?Number(e):typeof e=="number"&&Number.isFinite(e)?e:typeof e=="string"&&e.trim()!==""&&Number.isFinite(Number(e.trim()))?Number(e.trim()):null}function ye(e,t=512){if(typeof e!="string")return null;let n=e.trim();return n?n.length>t?n.slice(0,t):n:null}function nt(e){let t={};for(let n of tt)t[n]=e[n];return t}function rt(e,t){if(!pe(e))return{ok:!1,error:{type:null,at:null,grantId:null,message:"event must be a plain object"}};let n=typeof e.type=="string"?e.type:null,r=ge(e.at),s=typeof e.grantId=="string"&&e.grantId.trim()?e.grantId.trim():null;if(!et.includes(n))return{ok:!1,error:{type:n,at:r,grantId:s,message:`unknown event type "${String(n)}"`}};if(r==null)return{ok:!1,error:{type:n,at:null,grantId:s,message:"event.at must be a unix-seconds number"}};if(n==="grantCreated"){if(!pe(e.grant))return{ok:!1,error:{type:n,at:r,grantId:s,message:"grantCreated requires a grant payload"}};let c;try{c=z(e.grant,{allowWildcardActions:t.allowWildcardActions})}catch(l){let u=l instanceof b?l.message:String(l?.message||l);return{ok:!1,error:{type:n,at:r,grantId:s,message:u}}}let m=v(e.grant,{allowWildcardActions:t.allowWildcardActions});return s&&s!==m?{ok:!1,error:{type:n,at:r,grantId:s,message:"grantId does not match content-derived grant identity (fail closed)"}}:{ok:!0,event:{type:n,at:r,grantId:m,grant:c}}}if(!s)return{ok:!1,error:{type:n,at:r,grantId:null,message:`${n} requires a grantId`}};let o=n==="grantRevoked"?ye(e.reason):null;return{ok:!0,event:{type:n,at:r,grantId:s,reason:o}}}function Y(e){return e.length?e.reduce((t,n)=>Math.min(t,n)):null}function xe(e,t={}){let n=ge(t.now);if(n==null)throw new Error("grant-indexer: opts.now (unix seconds) is required");if(!Array.isArray(e))throw new Error("grant-indexer: events must be an array");let r=[],s=new Map;function o(u){return s.has(u)||s.set(u,{created:[],activated:[],revoked:[],expired:[]}),s.get(u)}for(let u of e){let d=rt(u,t);if(!d.ok){r.push(d.error);continue}let i=d.event;if(i.at>n)continue;let a=o(i.grantId);if(i.type==="grantCreated"){let f=a.created[0];(!f||i.at<f.at)&&(a.created=[i])}else i.type==="grantActivated"?a.activated.push(i):i.type==="grantRevoked"?a.revoked.push(i):i.type==="grantExpired"&&a.expired.push(i)}let c=[];for(let[u,d]of s.entries()){let i=d.created[0]||null,a=i?i.at:null,f=Y(d.activated.map(g=>g.at)),I=Y(d.revoked.map(g=>g.at)),A=Y(d.expired.map(g=>g.at)),x=i?i.grant:null,R=x?fe(x,n):!1,M=A??(R?x.expiresAt:null),w;i?d.revoked.length>0?w=G.REVOKED:A!=null||R?w=G.EXPIRED:d.activated.length>0?w=G.ACTIVE:w=G.PENDING:w=G.UNKNOWN;let h={grantId:u,status:w,createdAt:a,activatedAt:f,revokedAt:I,expiredAt:M,reason:d.revoked.length>0?ye(d.revoked.map(g=>g.reason).find(Boolean)||null):null,grant:x?nt(x):null};c.push(h)}c.sort((u,d)=>u.grantId<d.grantId?-1:u.grantId>d.grantId?1:0),r.sort((u,d)=>{let i=(u.at??-1/0)-(d.at??-1/0);if(i!==0)return i;let a=u.grantId||"",f=d.grantId||"";return a<f?-1:a>f?1:0});let m=c.filter(u=>u.status===G.ACTIVE),l=c.filter(u=>u.status!==G.ACTIVE);return Object.freeze({active:Object.freeze(m),historical:Object.freeze(l),all:Object.freeze(c),invalidEvents:Object.freeze(r)})}import{createHash as at}from"node:crypto";function st(e,t="value"){if(typeof e=="number"){if(!Number.isFinite(e))throw new Error(`${t} must be a finite number`);if(Math.abs(e)>Number.MAX_SAFE_INTEGER)throw new Error(`${t} exceeds safe integer precision \u2014 pass it as a decimal string or BigInt so the exact value is preserved`);if(Number.isInteger(e)&&!Number.isSafeInteger(e))throw new Error(`${t} exceeds safe integer precision \u2014 pass it as a decimal string or BigInt so the exact value is preserved`);return String(e)}if(typeof e=="string"){if(e!==e.trim())throw new Error(`${t} must be a number or decimal string`);return e}throw new Error(`${t} must be a number or decimal string`)}function he(e,t="amount"){if(typeof e=="bigint")return e;if(typeof e=="number"){if(!Number.isInteger(e))throw new Error(`${t} must be an integer`);if(!Number.isSafeInteger(e))throw new Error(`${t} exceeds safe integer precision \u2014 pass it as a decimal string or BigInt so the exact value is preserved`);return BigInt(e)}let n=st(e,t);if(n==="")throw new Error(`${t} is required`);if(!/^-?\d+$/.test(n)&&!/^0x[0-9a-fA-F]+$/.test(n))throw new Error(`${t} must be an integer in decimal or 0x-hex form, got ${JSON.stringify(n)}`);try{return BigInt(n)}catch{throw new Error(`${t} must be an integer, got ${JSON.stringify(n)}`)}}function it(e,t,n="guard"){if(typeof t!="number"||!Number.isFinite(t))throw new Error(`${n}: current time must be a finite number (got ${ot(t)})`);let r=t,s=Number(e?.issuedAtMs),o=Number(e?.expiresAtMs);if(!Number.isFinite(o))throw new Error(`${n}: expiresAtMs is required and must be a finite number`);if(r>o)throw new Error(`${n} expired at ${o}, now ${r}`);if(e?.issuedAtMs!=null){if(!Number.isFinite(s))throw new Error(`${n}: issuedAtMs must be a finite number when present`);if(o<=s)throw new Error(`${n}: expiry must be after issuance`)}return{now:r,issuedAtMs:s,expiresAtMs:o}}function be(e,t,{inclusive:n=!1}={}){try{let{now:r,expiresAtMs:s}=it(e,t);return!(n&&r>=s)}catch{return!1}}function ot(e){return e===null?"null":e===void 0?"undefined":typeof e=="number"?String(e):`${typeof e} ${JSON.stringify(String(e)).slice(0,24)}`}var Z=Object.freeze({SAFE:"safe",KERNEL_ZERODEV:"kernel-zerodev",BICONOMY_NEXUS:"biconomy-nexus",PERMISSIONLESS_VIEM:"permissionless-viem"}),Ae=Object.freeze(Object.values(Z)),T=Object.freeze({ACTIVE:"active",EXPIRED:"expired",REVOKED:"revoked"}),we=1440*60*1e3,ct=["read:","simulate:"],ut=/^0x[0-9a-fA-F]{40}$/;function dt(e){let t=String(e||"");return ct.some(n=>t.startsWith(n))}function y(e){throw new Error(`session: ${e}`)}function J(e,t){let n=String(e??"").trim().toLowerCase();return ut.test(n)||y(`${t} must be a 0x-prefixed 20-byte address`),n}function ft(e){let t=String(e??"").trim().toLowerCase();return t||y("action ids must be non-empty strings"),t.length>128&&y("action id too long"),t}function lt(e,t){let n=Number(e);return(!Number.isFinite(n)||!Number.isInteger(n)||n<=0)&&y(`${t} must be a positive integer`),n}function Se(e,t,{allowZero:n=!0}={}){if(e==null||e==="")return"0";let r;try{r=he(e,t)}catch(s){y(s.message)}return r<0n&&y(`${t} must not be negative`),!n&&r===0n&&y(`${t} must be greater than zero`),r.toString()}function j(e){return e==null?"null":typeof e!="object"?JSON.stringify(e):Array.isArray(e)?"["+e.map(j).join(",")+"]":"{"+Object.keys(e).sort().map(n=>JSON.stringify(n)+":"+j(e[n])).join(",")+"}"}function Q(e){let t=at("sha256");return t.update(j(e),"utf8"),`0x${t.digest("hex")}`}function Ee({provider:e,owner:t,agent:n,chainId:r,actions:s,targets:o=[],maxValueWei:c="0",maxGasWei:m,expiresAtMs:l,nonce:u=0,issuedAtMs:d=Date.now()}={}){let i=String(e??"").trim().toLowerCase();Ae.includes(i)||y(`provider must be one of ${Ae.join(", ")}`);let a=J(t,"owner"),f=J(n,"agent");a===f&&y("agent key must differ from owner wallet");let I=lt(r,"chainId");(!Array.isArray(s)||s.length===0)&&y("actions must be a non-empty array");let A=[...new Set(s.map(ft))].sort();Array.isArray(o)||y("targets must be an array");let x=[...new Set(o.map(Te=>J(Te,"target")))].sort(),R=A.every(dt);x.length===0&&!R&&y("empty target allowlist is only allowed when every action is read/simulate");let M=Se(c,"maxValueWei"),w=m==null?null:Se(m,"maxGasWei"),h=Number(d);Number.isFinite(h)||y("issuedAtMs must be a finite number");let g=Number(l);Number.isFinite(g)||y("expiresAtMs must be a finite number"),g<=h&&y("expiresAtMs must be after issuedAtMs"),g-h>we&&y(`session grant exceeds the hard 24-hour TTL (${we} ms)`);let U=String(u??0),k={mode:"oracle-session-grant",version:1,provider:i,owner:a,agent:f,chainId:I,actions:A,targets:x,maxValueWei:M,maxGasWei:w,issuedAtMs:h,expiresAtMs:g,nonce:U},De={id:Q(k),...k};return Object.freeze(De)}function Ie(){let e=new Map;return{revoke(t,{nowMs:n=Date.now(),reason:r=null}={}){return t||y("revoke requires a sessionId"),e.has(t)||e.set(t,{revokedAtMs:Number(n),reason:r}),e.get(t)},isRevoked(t){return e.has(t)},revokedAt(t){return e.get(t)?.revokedAtMs??null},get size(){return e.size}}}function mt(e,t){return t?typeof t.isRevoked=="function"?t.isRevoked(e.id):t instanceof Set?t.has(e.id):Array.isArray(t)?t.includes(e.id):!1:!1}function Ne(e,{nowMs:t=Date.now(),revocation:n}={}){return(!e||e.mode!=="oracle-session-grant")&&y("invalid session grant"),mt(e,n)?T.REVOKED:be({expiresAtMs:e.expiresAtMs},t,{inclusive:!0})?T.ACTIVE:T.EXPIRED}import{encodeFunctionData as Oe,keccak256 as pt,stringToHex as gt,numberToHex as O,isAddress as V,isHex as F,getAddress as _}from"viem";var yt="0x0000000071727De22E5E9d8BAf0edAc6f37da032",xt=[{type:"function",name:"getNonce",stateMutability:"view",inputs:[{name:"sender",type:"address"},{name:"key",type:"uint192"}],outputs:[{name:"nonce",type:"uint256"}]}],ke=[{type:"function",name:"installSessionKey",stateMutability:"nonpayable",inputs:[{name:"sessionId",type:"bytes32"},{name:"agent",type:"address"},{name:"validAfter",type:"uint48"},{name:"validUntil",type:"uint48"},{name:"actionsHash",type:"bytes32"},{name:"targets",type:"address[]"},{name:"maxValueWei",type:"uint256"},{name:"maxGasWei",type:"uint256"}],outputs:[]},{type:"function",name:"revokeSessionKey",stateMutability:"nonpayable",inputs:[{name:"sessionId",type:"bytes32"}],outputs:[]}];function p(e){throw new Error(`aa-adapter: ${e}`)}function Ge(e){return(typeof e!="string"||!V(e))&&p("opts.moduleAddress is required and must be a valid 0x address of the deployed session-key module on the owner's smart account (this adapter never guesses/hardcodes a contract address)"),_(e)}function _e(e){(!e||e.mode!=="oracle-session-grant")&&p("input is not a valid session-key-model grant (missing/wrong mode)");let{id:t,...n}=e;Q(n)!==t&&p("grant integrity check failed: id does not match grant fields (tampered or hand-built object)")}function ht(e,t={}){_e(e);let n=Ne(e,t);n!==T.ACTIVE&&p(`refusing to encode calldata for a ${n} session (${e.id})`)}function $e(e,t){let n=Math.floor(Number(e)/1e3);return(!Number.isFinite(n)||n<0||n>0xffffffffffff)&&p(`${t} does not fit a uint48 seconds timestamp`),BigInt(n)}function Re(e,t={}){ht(e,t);let n=Ge(t.moduleAddress),r=t.abi??ke,s=_(e.agent),o=e.targets.map(a=>_(a)),c=$e(e.issuedAtMs,"issuedAtMs"),m=$e(e.expiresAtMs,"expiresAtMs"),l=pt(gt(j(e.actions))),u=BigInt(e.maxValueWei),d=e.maxGasWei==null?0n:BigInt(e.maxGasWei),i=Oe({abi:r,functionName:"installSessionKey",args:[e.id,s,c,m,l,o,u,d]});return{to:n,data:i,value:"0x0"}}function ve(e,t={}){let n;typeof e=="string"?n=e:e&&e.mode==="oracle-session-grant"?(_e(e),n=e.id):p("revokeSessionKey requires a session-key-model grant object or a raw session id string"),(!F(n)||n.length!==66)&&p("session id must be a 0x-prefixed 32-byte hash (as produced by computeSessionId)");let r=Ge(t.moduleAddress),s=t.abi??ke,o=Oe({abi:s,functionName:"revokeSessionKey",args:[n]});return{to:r,data:o,value:"0x0"}}var bt=["callGasLimit","verificationGasLimit","preVerificationGas","maxFeePerGas","maxPriorityFeePerGas"];function S(e,t){e==null&&p(`${t} is required`);let n;try{n=typeof e=="bigint"?e:BigInt(e)}catch{p(`${t} must be an integer, bigint, or 0x-hex string`)}return n<0n&&p(`${t} must not be negative`),n}async function Me(e={}){let{client:t,entryPoint:n=yt,sender:r,callData:s,nonce:o,nonceKey:c=0n,factory:m,factoryData:l,paymaster:u,paymasterVerificationGasLimit:d,paymasterPostOpGasLimit:i,paymasterData:a="0x"}=e;(typeof r!="string"||!V(r))&&p("params.sender must be a valid 0x address"),(typeof s!="string"||!F(s))&&p("params.callData must be 0x-prefixed hex"),(typeof n!="string"||!V(n))&&p("params.entryPoint must be a valid 0x address");let f=_(r),I=_(n);for(let k of bt)e[k]==null&&p(`params.${k} is required (this adapter does not estimate gas)`);let A=S(e.callGasLimit,"callGasLimit"),x=S(e.verificationGasLimit,"verificationGasLimit"),R=S(e.preVerificationGas,"preVerificationGas"),M=S(e.maxFeePerGas,"maxFeePerGas"),w=S(e.maxPriorityFeePerGas,"maxPriorityFeePerGas");m==null!=(l==null)&&p("factory and factoryData must both be set (counterfactual deploy) or both omitted"),m!=null&&(typeof m!="string"||!V(m))&&p("params.factory must be a valid 0x address"),l!=null&&(typeof l!="string"||!F(l))&&p("params.factoryData must be 0x-prefixed hex");let h=u!=null;h&&((typeof u!="string"||!V(u))&&p("params.paymaster must be a valid 0x address"),(d==null||i==null)&&p("paymasterVerificationGasLimit and paymasterPostOpGasLimit are required when paymaster is set")),a!=null&&(typeof a!="string"||!F(a))&&p("params.paymasterData must be 0x-prefixed hex");let g;if(o!=null)g=S(o,"nonce");else{(!t||typeof t.readContract!="function")&&p("params.nonce was omitted and no usable client was provided \u2014 pass an explicit nonce or a client with an async readContract({address, abi, functionName, args}) method (a real viem PublicClient in production, a mock in tests; this adapter makes no network call itself)");let k=S(c,"nonceKey");g=await t.readContract({address:I,abi:xt,functionName:"getNonce",args:[f,k]}),g=S(g,"resolved nonce")}let U={sender:f,nonce:O(g),factory:m!=null?_(m):null,factoryData:l??null,callData:s,callGasLimit:O(A),verificationGasLimit:O(x),preVerificationGas:O(R),maxFeePerGas:O(M),maxPriorityFeePerGas:O(w),paymaster:h?_(u):null,paymasterVerificationGasLimit:h?O(S(d,"paymasterVerificationGasLimit")):null,paymasterPostOpGasLimit:h?O(S(i,"paymasterPostOpGasLimit")):null,paymasterData:h?a:null,signature:"0x"};return Object.freeze(U)}import{getBytes as At,verifyMessage as wt}from"ethers";var B=Object.freeze({PLAN:"oracle-session-plan",ACTIVATION:"oracle-session-activation",REVOCATION:"oracle-session-revocation",DESCRIPTION:"oracle-session-description"});function E(e){throw new Error(`session-orchestrator: ${e}`)}var St=Object.freeze(["id","sessionId"]),Et=/^0x[0-9a-fA-F]{64}$/;function ee(e,t){if(e==null||typeof e!="object")return typeof e=="string"&&St.includes(t)&&Et.test(e)?`session-id:${e.slice(2)}`:e;if(Array.isArray(e))return e.map(r=>ee(r,null));let n={};for(let[r,s]of Object.entries(e)){if(r==="signature"){s!=="0x"&&E('refusing to return a userOp whose signature is not the empty "0x" placeholder (this module never signs)');continue}n[r]=ee(s,r)}return n}function K(e){return $(ee(e,null)),e}function W(e){if(e&&typeof e=="object"&&!Object.isFrozen(e)){Object.freeze(e);for(let t of Object.values(e))W(t)}return e}function Ht(e,t={}){let n=P(e,{now:t.now});if(!n.ok)throw new b(n.errors);let r=X(n.grant,{now:t.now}),s=W({kind:B.PLAN,unsigned:!0,grantId:r.payload.grantId,grant:n.grant,unsignedGrant:r,signingBytes:r.signing,render:r.render});return K(s)}function It(e){(typeof e!="string"||e.trim()==="")&&E("ownerSignature is required (the owner must have signed the grant in their own wallet)");let t=e.trim();return(!/^0x[0-9a-fA-F]+$/.test(t)||t==="0x")&&E("ownerSignature must be non-empty 0x-prefixed hex"),t}async function Nt({grant:e,ownerSignature:t,verifyOwnerSignature:n,nowSeconds:r}){let s=It(t),o=X(e,{now:r});if(typeof n=="function"){await n({grant:e,ownerSignature:s,signingBytes:o.signing})!==!0&&E("ownerSignature verification failed");return}try{wt(At(o.signing.bytesHex),s).toLowerCase()!==e.accountAddress.toLowerCase()&&E("ownerSignature signer does not match grant accountAddress")}catch(c){if(String(c?.message||"").startsWith("session-orchestrator:"))throw c;E("ownerSignature could not be verified; smart accounts must provide verifyOwnerSignature")}}async function ze({grant:e,ownerSignature:t,sessionKeyModel:n}={},r){(n==null||typeof n!="object")&&E("sessionKeyModel is required ({ provider?, moduleAddress, issuedAtMs, userOp })");let{provider:s=Z.PERMISSIONLESS_VIEM,moduleAddress:o,issuedAtMs:c,abi:m,userOp:l}=n;Number.isFinite(Number(c))||E("sessionKeyModel.issuedAtMs (epoch MILLISECONDS) is required for a deterministic session grant"),(l==null||typeof l!="object")&&E("sessionKeyModel.userOp (gas/fee/nonce params for buildUserOperation) is required");let u=Math.floor(Number(c)/1e3),d=P(e,{now:u});if(!d.ok)throw new b(d.errors);let i=d.grant;await Nt({grant:i,ownerSignature:t,verifyOwnerSignature:r,nowSeconds:u});let a=i.expiresAt*1e3,f=Ee({provider:s,owner:i.accountAddress,agent:i.agentAddress,chainId:i.chainId,actions:i.actions,targets:i.targets,maxValueWei:i.maxValueWei,maxGasWei:i.maxGasWei,expiresAtMs:a,nonce:i.nonce,issuedAtMs:Number(c)}),I=Re(f,{moduleAddress:o,abi:m,nowMs:Number(c)}),A=await Me({...l,sender:i.accountAddress,callData:I.data}),x=W({kind:B.ACTIVATION,unsigned:!0,grantId:v(i),sessionId:f.id,sessionGrant:f,install:I,userOp:A,units:{expiresAtSeconds:i.expiresAt,expiresAtMs:f.expiresAtMs}});return K(x)}async function Xt(e={}){return ze(e,void 0)}function Yt({verifyOwnerSignature:e}={}){typeof e!="function"&&E("createSessionOrchestrator requires a trusted verifyOwnerSignature function");let t=e;return Object.freeze({activateSession(n={}){return ze(n,t)}})}function Jt(e,t={}){let n=ve(e,{moduleAddress:t.moduleAddress,abi:t.abi}),r=typeof e=="string"?e:e.id,s=t.registry??Ie(),o=s.revoke(r,{nowMs:t.nowMs??Date.now(),reason:t.reason??null}),c={kind:B.REVOCATION,sessionId:r,revoke:n,revocation:Object.freeze({revokedAtMs:o.revokedAtMs,reason:o.reason}),registry:s};return Object.freeze(c),W(c.revoke),K(c)}function Zt(e,t){let n=xe(e,{now:t}),r=W({kind:B.DESCRIPTION,now:t,active:n.active,count:n.active.length,index:n});return K(r)}export{B as ORCHESTRATOR_KINDS,me as SIGNING_SCHEME,Xt as activateSession,Yt as createSessionOrchestrator,Zt as describeActive,Ht as planConnection,Jt as revokeSession,K as scanPublicReturn};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oracle-agent/oracle",
3
- "version": "0.35.6",
3
+ "version": "0.35.8",
4
4
  "description": "Oracle: standalone multichain agent control plane with an optional encrypted, loopback-only self-hosted signer.",
5
5
  "license": "BUSL-1.1",
6
6
  "type": "module",
@@ -68,8 +68,10 @@
68
68
  "./universal-ordinals-transfer": "./dist/data/providers/universal-ordinals-transfer.mjs",
69
69
  "./prepare-envelope": "./dist/prepare-envelope.mjs",
70
70
  "./approval-binding": "./dist/control/approval-binding.mjs",
71
+ "./sign-time-review": "./dist/control/sign-time-review.mjs",
71
72
  "./connect": "./dist/onboarding/harness-configs.mjs",
72
73
  "./finality": "./dist/control/finality.mjs",
74
+ "./verified-receipts": "./dist/control/verified-receipts.mjs",
73
75
  "./receipts": "./dist/action-receipts.mjs",
74
76
  "./tax-lots": "./dist/tax-lots.mjs",
75
77
  "./position-health": "./dist/position-health.mjs",
@@ -80,6 +82,7 @@
80
82
  "./signals": "./dist/signals/index.mjs",
81
83
  "./strategy": "./dist/strategy/index.mjs",
82
84
  "./agent-grants": "./dist/public-api/agent-grants.mjs",
85
+ "./session-orchestrator": "./dist/public-control/session-orchestrator.mjs",
83
86
  "./control-plane": "./dist/control-plane/index.mjs",
84
87
  "./tenant-rbac": "./dist/tenant-rbac.mjs",
85
88
  "./workflow-telemetry": "./dist/workflow-telemetry.mjs",