@magicnewton/newton-protocol-sdk 0.0.9 → 0.0.10
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/cjs/index.js +1 -1
- package/dist/cjs/modules/avs/index.js +1 -1
- package/dist/cjs/modules/policy/index.js +1 -1
- package/dist/cjs/utils/intent.js +1 -1
- package/dist/cjs/utils/task.js +1 -1
- package/dist/es/index.js +1 -1
- package/dist/es/modules/avs/index.js +1 -1
- package/dist/es/modules/policy/index.js +1 -1
- package/dist/es/utils/intent.js +1 -1
- package/dist/es/utils/task.js +1 -1
- package/dist/types/index.d.ts +13 -23
- package/dist/types/modules/policy/index.d.ts +0 -48
- package/dist/types/types/task.d.ts +8 -8
- package/dist/types/utils/intent.d.ts +5 -3
- package/package.json +1 -1
- package/dist/cjs/utils/bytes.js +0 -1
- package/dist/es/utils/bytes.js +0 -1
- package/dist/types/utils/bytes.d.ts +0 -2
package/dist/cjs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var r=require("viem/chains"),s=require("./modules/avs/index.js"),o=require("./modules/policy/index.js");const a=l=>n=>{const c=l?.policyContractAddress,e=()=>{if(c)return c;throw new Error('Newton SDK: policyContractAddress is required. Ensure you instantiate viem client actions extension with policyContractAddress parameter. Example: newtonWalletClientActions({ policyContractAddress: "0x123..." })')};if(n?.chain?.id!==r.mainnet.id&&n?.chain?.id!==r.sepolia.id)throw new Error("Newton SDK: Invalid network specified for newtonWalletClientActions. Only mainnet and sepolia are supported");return{submitEvaluationRequest:t=>s.submitEvaluationRequest(n,t),initialize:t=>{const i=e();return o.policyWriteFunctions.initialize({walletClient:n,policyContractAddress:i,...t})},renounceOwnership:()=>{const t=e();return o.policyWriteFunctions.renounceOwnership({walletClient:n,policyContractAddress:t})},transferOwnership:t=>{const i=e();return o.policyWriteFunctions.transferOwnership({walletClient:n,policyContractAddress:i,...t})}}},d=l=>n=>{if(n?.chain?.id!==r.mainnet.id&&n?.chain?.id!==r.sepolia.id)throw new Error("Newton SDK: Invalid network specified for newtonPublicActions. Only mainnet and sepolia are supported");const c=l?.policyContractAddress,e=()=>{if(!c)throw new Error('Newton SDK: policyContractAddress is required. Ensure you instantiate viem client actions extension with policyContractAddress parameter. Example: newtonPublicClientActions({ policyContractAddress: "0x123..." })');return c};return{waitForTaskResponded:t=>s.waitForTaskResponded(n,t),getTaskResponseHash:t=>s.getTaskResponseHash(n,t),getTaskStatus:t=>s.getTaskStatus(n,t),policyUri:()=>{const t=e();return o.policyReadFunctions.policyUri({publicClient:n,policyContractAddress:t})},supportsInterface:t=>{const i=e();return o.policyReadFunctions.supportsInterface({publicClient:n,policyContractAddress:i,...t})},owner:()=>{const t=e();return o.policyReadFunctions.owner({publicClient:n,policyContractAddress:t})},factory:()=>{const t=e();return o.policyReadFunctions.factory({publicClient:n,policyContractAddress:t})},entrypoint:()=>{const t=e();return o.policyReadFunctions.entrypoint({publicClient:n,policyContractAddress:t})},schemaUri:()=>{const t=e();return o.policyReadFunctions.schemaUri({publicClient:n,policyContractAddress:t})},policyData:t=>{const i=e();return o.policyReadFunctions.policyData({publicClient:n,policyContractAddress:i,...t})},clientToPolicyId:t=>{const i=e();return o.policyReadFunctions.clientToPolicyId({publicClient:n,policyContractAddress:i,...t})},getPolicyId:t=>{const i=e();return o.policyReadFunctions.getPolicyId({publicClient:n,policyContractAddress:i,...t})},getPolicyConfig:t=>{const i=e();return o.policyReadFunctions.getPolicyConfig({publicClient:n,policyContractAddress:i,...t})},precomputePolicyId:t=>{const i=e();return o.policyReadFunctions.precomputePolicyId({publicClient:n,policyContractAddress:i,...t})}}};exports.newtonPublicClientActions=d,exports.newtonWalletClientActions=a;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var u=require("../../abis/newtonAbi.js"),a=require("../../const.js"),A=require("../../types/task.js"),
|
|
1
|
+
"use strict";var u=require("../../abis/newtonAbi.js"),a=require("../../const.js"),A=require("../../types/task.js"),M=require("../../utils/https.js"),g=require("../../utils/intent.js"),w=require("../../utils/task.js"),d=require("viem"),h=require("viem/chains");const p={[h.sepolia.id]:BigInt(9223883),[h.mainnet.id]:BigInt(23385048)},I=async(t,e,s)=>{if(!e.taskId)throw new Error("Newton SDK: waitForTaskResponded requires taskId");const r=d.padHex(e.taskId,{size:32}),E=p[t.chain?.id??1],n=s??E,c=(await t.getContractEvents({address:t.chain?.testnet?a.SEPOLIA_NEWTON_PROVER_TASK_MANAGER:a.MAINNET_NEWTON_PROVER_TASK_MANAGER,abi:u.NewtonProverTaskManagerAbi,eventName:"TaskResponded",fromBlock:n,toBlock:"latest"})).find(o=>d.padHex(o.args.taskResponse.taskId,{size:32})===r);return c?w.convertLogToTaskResponse(c):new Promise((o,m)=>{let N,k;const l=i=>{N?.(),k&&clearTimeout(k),i&&m(i)};if(e.timeoutMs&&e.timeoutMs>0&&(k=setTimeout(()=>l(new Error("waitForTaskResponded: timeout")),e.timeoutMs)),e.abortSignal){if(e.abortSignal.aborted){l(new Error("waitForTaskResponded: aborted"));return}e.abortSignal.addEventListener("abort",()=>l(new Error("waitForTaskResponded: aborted")),{once:!0})}N=t.watchContractEvent({address:t.chain?.testnet?a.SEPOLIA_NEWTON_PROVER_TASK_MANAGER:a.MAINNET_NEWTON_PROVER_TASK_MANAGER,abi:u.NewtonProverTaskManagerAbi,eventName:"TaskResponded",onLogs:i=>{for(const R of i)if(d.padHex(R.args.taskResponse.taskId,{size:32})===r){const _=w.convertLogToTaskResponse(R);l(),o(_);return}},onError:i=>{l(i)}})})},O=(t,e)=>t.readContract({address:t.chain?.testnet?a.SEPOLIA_NEWTON_PROVER_TASK_MANAGER:a.MAINNET_NEWTON_PROVER_TASK_MANAGER,abi:u.NewtonProverTaskManagerAbi,functionName:"allTaskHashes",args:[e.taskId]}),q=async(t,e)=>{const s=t.chain?.testnet?a.SEPOLIA_NEWTON_PROVER_TASK_MANAGER:a.MAINNET_NEWTON_PROVER_TASK_MANAGER,r=await t.readContract({address:s,abi:u.NewtonProverTaskManagerAbi,functionName:"allTaskHashes",args:[e.taskId]});if(!d.hexToBigInt(r))throw new Error(`Failed to retrieve task status for taskId ${e.taskId}`);const E=await t.readContract({address:s,abi:u.NewtonProverTaskManagerAbi,functionName:"allTaskResponses",args:[e.taskId]}),n=!!d.hexToBigInt(E);if(!n)return A.TaskStatus.Created;const c=(await t.getContractEvents({address:t.chain?.testnet?a.SEPOLIA_NEWTON_PROVER_TASK_MANAGER:a.MAINNET_NEWTON_PROVER_TASK_MANAGER,abi:u.NewtonProverTaskManagerAbi,eventName:"TaskResponded",fromBlock:p[t.chain?.id??1],toBlock:"latest"})).find(k=>d.padHex(k.args.taskResponse.taskId,{size:32})===e.taskId);if(!c)throw new Error(`Failed to retrieve task status for taskId ${e.taskId}`);const o=w.convertLogToTaskResponse(c),m=await t.getBlockNumber();if(o?.responseCertificate?.responseExpireBlock&&m>o.responseCertificate.responseExpireBlock)return A.TaskStatus.AttestationExpired;const N=await t.readContract({address:s,abi:u.NewtonProverTaskManagerAbi,functionName:"attestations",args:[e.taskId]});return d.hexToBigInt(N)?await t.readContract({address:s,abi:u.NewtonProverTaskManagerAbi,functionName:"taskSuccesfullyChallenged",args:[e.taskId]})?A.TaskStatus.SuccessfullyChallenged:n?A.TaskStatus.Responded:A.TaskStatus.Created:A.TaskStatus.AttestationSpent};async function C(t,e){const s=t.extend(d.publicActions),r={taskRequestedAtBlock:await s.getBlockNumber()},E=new M.AvsHttpService(!!s?.chain?.testnet),n=t.account;if(!n||!n.sign)throw new Error("Newton SDK: walletClient must have a local account to sign the request");const{policyClient:c,quorumNumber:o,quorumThresholdPercentage:m,wasmArgs:N,timeout:k}=e,l=g.normalizeIntent(e.intent),i=w.getEvaluationRequestHash({policyClient:c,intent:l,quorumNumber:o,quorumThresholdPercentage:m,wasmArgs:N,timeout:k}),R=await n.sign({hash:i}),_=g.sanitizeIntentForRequest(e.intent),v={policy_client:e.policyClient,intent:_,quorum_number:e.quorumNumber?g.removeHexPrefix(e.quorumNumber):null,quorum_threshold_percentage:e.quorumThresholdPercentage??null,wasm_args:e.wasmArgs?g.removeHexPrefix(e.wasmArgs):null,timeout:e.timeout,signature:R},T=await E.Post(a.AVS_METHODS.createTaskAndWait,[v],R);if(T.error)throw T.error;if(T.result.error)throw new Error(T.result.error);const b=T.result;r.taskId=b.result.task_id;const S={get taskId(){return r.taskId},waitForTaskResponded:async({timeoutMs:f})=>{const P=r.taskId;return I(s,{taskId:P,timeoutMs:f},r.taskRequestedAtBlock)}};return{result:{taskId:T.result.task_id,txHash:T.result.tx_hash},...S}}exports.getTaskResponseHash=O,exports.getTaskStatus=q,exports.submitEvaluationRequest=C,exports.waitForTaskResponded=I;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var o=require("../../abis/newtonPolicyAbi.js"),c=require("viem");const w=async({publicClient:e,policyContractAddress:n})=>{try{return await e.readContract({address:n,abi:o.NewtonPolicyAbi,functionName:"policyUri"})}catch(r){throw new Error(`Newton SDK: Failed to get policyUri - ${r instanceof Error?r.message:"Unknown error"}`)}},d=async({publicClient:e,policyContractAddress:n
|
|
1
|
+
"use strict";var o=require("../../abis/newtonPolicyAbi.js"),c=require("viem");const w=async({publicClient:e,policyContractAddress:n})=>{try{return await e.readContract({address:n,abi:o.NewtonPolicyAbi,functionName:"policyUri"})}catch(r){throw new Error(`Newton SDK: Failed to get policyUri - ${r instanceof Error?r.message:"Unknown error"}`)}},d=async({publicClient:e,policyContractAddress:n,client:r})=>{try{return await e.readContract({address:n,abi:o.NewtonPolicyAbi,functionName:"getPolicyId",args:[r]})}catch(t){throw new Error(`Newton SDK: Failed to get getPolicyId - ${t instanceof Error?t.message:"Unknown error"}`)}},y=async({publicClient:e,policyContractAddress:n,policyId:r})=>{try{const t=await e.readContract({address:n,abi:o.NewtonPolicyAbi,functionName:"getPolicyConfig",args:[r]}),a=c.fromHex(t.policyParams,"string");let i;try{i=JSON.parse(a)}catch{i=a}return{policyParams:i??a,policyParamsHex:t.policyParams,expireAfter:t.expireAfter}}catch(t){throw new Error(`Newton SDK: Failed to get getPolicyConfig - ${t instanceof Error?t.message:"Unknown error"}`)}},p=async({publicClient:e,policyContractAddress:n,interfaceId:r})=>{try{return await e.readContract({address:n,abi:o.NewtonPolicyAbi,functionName:"supportsInterface",args:[r]})}catch(t){throw new Error(`Newton SDK: Failed to get supportsInterface - ${t instanceof Error?t.message:"Unknown error"}`)}},u=async({publicClient:e,policyContractAddress:n})=>{try{return await e.readContract({address:n,abi:o.NewtonPolicyAbi,functionName:"owner"})}catch(r){throw new Error(`Newton SDK: Failed to get owner - ${r instanceof Error?r.message:"Unknown error"}`)}},h=async({publicClient:e,policyContractAddress:n})=>{try{return await e.readContract({address:n,abi:o.NewtonPolicyAbi,functionName:"factory"})}catch(r){throw new Error(`Newton SDK: Failed to get factory - ${r instanceof Error?r.message:"Unknown error"}`)}},f=async({publicClient:e,policyContractAddress:n})=>{try{return await e.readContract({address:n,abi:o.NewtonPolicyAbi,functionName:"entrypoint"})}catch(r){throw new Error(`Newton SDK: Failed to get entrypoint - ${r instanceof Error?r.message:"Unknown error"}`)}},g=async({publicClient:e,policyContractAddress:n})=>{try{return await e.readContract({address:n,abi:o.NewtonPolicyAbi,functionName:"schemaUri"})}catch(r){throw new Error(`Newton SDK: Failed to get schemaUri - ${r instanceof Error?r.message:"Unknown error"}`)}},m=async({publicClient:e,policyContractAddress:n,client:r})=>{try{return await e.readContract({address:n,abi:o.NewtonPolicyAbi,functionName:"clientToPolicyId",args:[r]})}catch(t){throw new Error(`Newton SDK: Failed to get clientToPolicyId - ${t instanceof Error?t.message:"Unknown error"}`)}},N=async({publicClient:e,policyContractAddress:n,index:r})=>{try{return await e.readContract({address:n,abi:o.NewtonPolicyAbi,functionName:"policyData",args:[BigInt(r)]})}catch(t){throw new Error(`Newton SDK: Failed to get policyData - ${t instanceof Error?t.message:"Unknown error"}`)}},b=({publicClient:e,policyContractAddress:n,...r})=>{try{const t=r.blockTimestamp||BigInt(Math.floor(Date.now()/1e3)),a={policyParams:`0x${new TextEncoder().encode(JSON.stringify(r.params)).reduce((s,l)=>s+l.toString(16).padStart(2,"0"),"")}`,expireAfter:r.expireAfter||0},i=c.encodePacked(["address","address[]","string","string","string","tuple(bytes,uint32)","uint256"],[r.client,r.policyData,r.policyUri,r.schemaUri,r.entrypoint,a,t]);return c.keccak256(i)}catch(t){throw new Error(`Newton SDK: Failed to precompute policy ID - ${t instanceof Error?t.message:"Unknown error"}`)}},C=async({walletClient:e,policyContractAddress:n,...r})=>{try{if(!e.chain)throw new Error("Newton SDK: account and chain must be set on Wallet client");const t=e.account??(await e.getAddresses())[0];return await e.writeContract({address:n,abi:o.NewtonPolicyAbi,functionName:"initialize",args:[r.factory,r.entrypoint,r.policyUri,r.schemaUri,r.policyData],chain:e.chain,account:t})}catch(t){throw new Error(`Newton SDK: Failed to initialize - ${t instanceof Error?t.message:"Unknown error"}`)}},A=async({walletClient:e,policyContractAddress:n})=>{try{if(!e.chain)throw new Error("Newton SDK: account and chain must be set on Wallet client");const r=e.account??(await e.getAddresses())[0];return await e.writeContract({address:n,abi:o.NewtonPolicyAbi,functionName:"renounceOwnership",chain:e.chain,account:r})}catch(r){throw new Error(`Newton SDK: Failed to renounce ownership - ${r instanceof Error?r.message:"Unknown error"}`)}},E=async({walletClient:e,policyContractAddress:n,...r})=>{try{if(!e.chain)throw new Error("Newton SDK: account and chain must be set on Wallet client");const t=e.account??(await e.getAddresses())[0];return await e.writeContract({address:n,abi:o.NewtonPolicyAbi,functionName:"transferOwnership",args:[r.newOwner],chain:e.chain,account:t})}catch(t){throw new Error(`Newton SDK: Failed to transfer ownership - ${t instanceof Error?t.message:"Unknown error"}`)}},P={initialize:C,renounceOwnership:A,transferOwnership:E},D={policyUri:w,getPolicyId:d,getPolicyConfig:y,supportsInterface:p,owner:u,factory:h,entrypoint:f,schemaUri:g,clientToPolicyId:m,policyData:N,precomputePolicyId:b};exports.policyReadFunctions=D,exports.policyWriteFunctions=P;
|
package/dist/cjs/utils/intent.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var a=require("viem");const e=t=>t.startsWith("0x")?t.slice(2):t;function o(t){let i;typeof t.value=="bigint"?i=t.value:i=a.hexToBigInt(t.value);let n;return typeof t.chainId=="bigint"?n=t.chainId:typeof t.chainId=="number"?n=BigInt(t.chainId):n=a.hexToBigInt(t.chainId),{...t,value:i,chainId:n}}function r(t){let i;typeof t.value=="bigint"?i=a.toHex(t.value):i=t.value;let n;return typeof t.chainId=="bigint"||typeof t.chainId=="number"?n=a.toHex(t.chainId):n=t.chainId,{from:t.from,to:t.to,value:i,data:e(t.data),chain_id:n,function_signature:e(t.functionSignature)}}exports.normalizeIntent=o,exports.removeHexPrefix=e,exports.sanitizeIntentForRequest=r;
|
package/dist/cjs/utils/task.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var i=require("viem"),
|
|
1
|
+
"use strict";var i=require("viem"),u=require("./intent.js");const c=e=>{const{policyClient:s,quorumNumber:n,quorumThresholdPercentage:a,wasmArgs:o,timeout:r}=e,t=u.normalizeIntent(e.intent);return i.keccak256(i.encodePacked(["address","address","address","uint256","bytes","uint256","bytes","bytes","uint32","bytes","uint64"],[s,t.from,t.to,t.value,t.data,t.chainId,t.functionSignature,n||"0x",a??0,o||"0x",BigInt(r)]))};function p(e){const s={...e.args.taskResponse,intent:{...e.args.taskResponse.intent,value:BigInt(e.args.taskResponse.intent.value),data:e.args.taskResponse.intent.data,chainId:BigInt(e.args.taskResponse.intent.chainId)},evaluationResult:!!(e.args.taskResponse.evaluationResult&&i.hexToBigInt(e.args.taskResponse.evaluationResult))},n={taskResponsedBlock:Number(e.args.responseCertificate.taskResponsedBlock),responseExpireBlock:Number(e.args.responseCertificate.responseExpireBlock),hashOfNonSigners:e.args.responseCertificate.hashOfNonSigners},a={taskId:s.taskId,policyId:s.policyId,policyClient:s.policyClient,intent:s.intent,expiration:n.responseExpireBlock};return{taskResponse:s,responseCertificate:n,attestation:a}}exports.convertLogToTaskResponse=p,exports.getEvaluationRequestHash=c;
|
package/dist/es/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{mainnet as l,sepolia as a}from"viem/chains";import{getTaskStatus as
|
|
1
|
+
import{mainnet as l,sepolia as a}from"viem/chains";import{getTaskStatus as p,getTaskResponseHash as d,waitForTaskResponded as u,submitEvaluationRequest as y}from"./modules/avs/index.js";import{policyReadFunctions as o,policyWriteFunctions as c}from"./modules/policy/index.js";const C=s=>e=>{const r=s?.policyContractAddress,n=()=>{if(r)return r;throw new Error('Newton SDK: policyContractAddress is required. Ensure you instantiate viem client actions extension with policyContractAddress parameter. Example: newtonWalletClientActions({ policyContractAddress: "0x123..." })')};if(e?.chain?.id!==l.id&&e?.chain?.id!==a.id)throw new Error("Newton SDK: Invalid network specified for newtonWalletClientActions. Only mainnet and sepolia are supported");return{submitEvaluationRequest:t=>y(e,t),initialize:t=>{const i=n();return c.initialize({walletClient:e,policyContractAddress:i,...t})},renounceOwnership:()=>{const t=n();return c.renounceOwnership({walletClient:e,policyContractAddress:t})},transferOwnership:t=>{const i=n();return c.transferOwnership({walletClient:e,policyContractAddress:i,...t})}}},w=s=>e=>{if(e?.chain?.id!==l.id&&e?.chain?.id!==a.id)throw new Error("Newton SDK: Invalid network specified for newtonPublicActions. Only mainnet and sepolia are supported");const r=s?.policyContractAddress,n=()=>{if(!r)throw new Error('Newton SDK: policyContractAddress is required. Ensure you instantiate viem client actions extension with policyContractAddress parameter. Example: newtonPublicClientActions({ policyContractAddress: "0x123..." })');return r};return{waitForTaskResponded:t=>u(e,t),getTaskResponseHash:t=>d(e,t),getTaskStatus:t=>p(e,t),policyUri:()=>{const t=n();return o.policyUri({publicClient:e,policyContractAddress:t})},supportsInterface:t=>{const i=n();return o.supportsInterface({publicClient:e,policyContractAddress:i,...t})},owner:()=>{const t=n();return o.owner({publicClient:e,policyContractAddress:t})},factory:()=>{const t=n();return o.factory({publicClient:e,policyContractAddress:t})},entrypoint:()=>{const t=n();return o.entrypoint({publicClient:e,policyContractAddress:t})},schemaUri:()=>{const t=n();return o.schemaUri({publicClient:e,policyContractAddress:t})},policyData:t=>{const i=n();return o.policyData({publicClient:e,policyContractAddress:i,...t})},clientToPolicyId:t=>{const i=n();return o.clientToPolicyId({publicClient:e,policyContractAddress:i,...t})},getPolicyId:t=>{const i=n();return o.getPolicyId({publicClient:e,policyContractAddress:i,...t})},getPolicyConfig:t=>{const i=n();return o.getPolicyConfig({publicClient:e,policyContractAddress:i,...t})},precomputePolicyId:t=>{const i=n();return o.precomputePolicyId({publicClient:e,policyContractAddress:i,...t})}}};export{w as newtonPublicClientActions,C as newtonWalletClientActions};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{NewtonProverTaskManagerAbi as i}from"../../abis/newtonAbi.js";import{SEPOLIA_NEWTON_PROVER_TASK_MANAGER as
|
|
1
|
+
import{NewtonProverTaskManagerAbi as i}from"../../abis/newtonAbi.js";import{SEPOLIA_NEWTON_PROVER_TASK_MANAGER as h,MAINNET_NEWTON_PROVER_TASK_MANAGER as f,AVS_METHODS as B}from"../../const.js";import{TaskStatus as k}from"../../types/task.js";import{AvsHttpService as x}from"../../utils/https.js";import{normalizeIntent as y,sanitizeIntentForRequest as M,removeHexPrefix as b}from"../../utils/intent.js";import{convertLogToTaskResponse as E,getEvaluationRequestHash as P}from"../../utils/task.js";import{hexToBigInt as R,padHex as T,publicActions as F}from"viem";import{mainnet as H,sepolia as z}from"viem/chains";const N={[z.id]:BigInt(9223883),[H.id]:BigInt(23385048)},A=async(e,t,s)=>{if(!t.taskId)throw new Error("Newton SDK: waitForTaskResponded requires taskId");const a=T(t.taskId,{size:32}),p=N[e.chain?.id??1],r=s??p,d=(await e.getContractEvents({address:e.chain?.testnet?h:f,abi:i,eventName:"TaskResponded",fromBlock:r,toBlock:"latest"})).find(o=>T(o.args.taskResponse.taskId,{size:32})===a);return d?E(d):new Promise((o,w)=>{let m,u;const c=n=>{m?.(),u&&clearTimeout(u),n&&w(n)};if(t.timeoutMs&&t.timeoutMs>0&&(u=setTimeout(()=>c(new Error("waitForTaskResponded: timeout")),t.timeoutMs)),t.abortSignal){if(t.abortSignal.aborted){c(new Error("waitForTaskResponded: aborted"));return}t.abortSignal.addEventListener("abort",()=>c(new Error("waitForTaskResponded: aborted")),{once:!0})}m=e.watchContractEvent({address:e.chain?.testnet?h:f,abi:i,eventName:"TaskResponded",onLogs:n=>{for(const g of n)if(T(g.args.taskResponse.taskId,{size:32})===a){const I=E(g);c(),o(I);return}},onError:n=>{c(n)}})})},O=(e,t)=>e.readContract({address:e.chain?.testnet?h:f,abi:i,functionName:"allTaskHashes",args:[t.taskId]}),K=async(e,t)=>{const s=e.chain?.testnet?h:f,a=await e.readContract({address:s,abi:i,functionName:"allTaskHashes",args:[t.taskId]});if(!R(a))throw new Error(`Failed to retrieve task status for taskId ${t.taskId}`);const p=await e.readContract({address:s,abi:i,functionName:"allTaskResponses",args:[t.taskId]}),r=!!R(p);if(!r)return k.Created;const d=(await e.getContractEvents({address:e.chain?.testnet?h:f,abi:i,eventName:"TaskResponded",fromBlock:N[e.chain?.id??1],toBlock:"latest"})).find(u=>T(u.args.taskResponse.taskId,{size:32})===t.taskId);if(!d)throw new Error(`Failed to retrieve task status for taskId ${t.taskId}`);const o=E(d),w=await e.getBlockNumber();if(o?.responseCertificate?.responseExpireBlock&&w>o.responseCertificate.responseExpireBlock)return k.AttestationExpired;const m=await e.readContract({address:s,abi:i,functionName:"attestations",args:[t.taskId]});return R(m)?await e.readContract({address:s,abi:i,functionName:"taskSuccesfullyChallenged",args:[t.taskId]})?k.SuccessfullyChallenged:r?k.Responded:k.Created:k.AttestationSpent};async function L(e,t){const s=e.extend(F),a={taskRequestedAtBlock:await s.getBlockNumber()},p=new x(!!s?.chain?.testnet),r=e.account;if(!r||!r.sign)throw new Error("Newton SDK: walletClient must have a local account to sign the request");const{policyClient:d,quorumNumber:o,quorumThresholdPercentage:w,wasmArgs:m,timeout:u}=t,c=y(t.intent),n=P({policyClient:d,intent:c,quorumNumber:o,quorumThresholdPercentage:w,wasmArgs:m,timeout:u}),g=await r.sign({hash:n}),I=M(t.intent),C={policy_client:t.policyClient,intent:I,quorum_number:t.quorumNumber?b(t.quorumNumber):null,quorum_threshold_percentage:t.quorumThresholdPercentage??null,wasm_args:t.wasmArgs?b(t.wasmArgs):null,timeout:t.timeout,signature:g},l=await p.Post(B.createTaskAndWait,[C],g);if(l.error)throw l.error;if(l.result.error)throw new Error(l.result.error);const v=l.result;a.taskId=v.result.task_id;const _={get taskId(){return a.taskId},waitForTaskResponded:async({timeoutMs:S})=>{const q=a.taskId;return A(s,{taskId:q,timeoutMs:S},a.taskRequestedAtBlock)}};return{result:{taskId:l.result.task_id,txHash:l.result.tx_hash},..._}}export{O as getTaskResponseHash,K as getTaskStatus,L as submitEvaluationRequest,A as waitForTaskResponded};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{NewtonPolicyAbi as
|
|
1
|
+
import{NewtonPolicyAbi as o}from"../../abis/newtonPolicyAbi.js";import{encodePacked as l,keccak256 as d,fromHex as w}from"viem";const y=async({publicClient:e,policyContractAddress:n})=>{try{return await e.readContract({address:n,abi:o,functionName:"policyUri"})}catch(r){throw new Error(`Newton SDK: Failed to get policyUri - ${r instanceof Error?r.message:"Unknown error"}`)}},p=async({publicClient:e,policyContractAddress:n,client:r})=>{try{return await e.readContract({address:n,abi:o,functionName:"getPolicyId",args:[r]})}catch(t){throw new Error(`Newton SDK: Failed to get getPolicyId - ${t instanceof Error?t.message:"Unknown error"}`)}},u=async({publicClient:e,policyContractAddress:n,policyId:r})=>{try{const t=await e.readContract({address:n,abi:o,functionName:"getPolicyConfig",args:[r]}),a=w(t.policyParams,"string");let c;try{c=JSON.parse(a)}catch{c=a}return{policyParams:c??a,policyParamsHex:t.policyParams,expireAfter:t.expireAfter}}catch(t){throw new Error(`Newton SDK: Failed to get getPolicyConfig - ${t instanceof Error?t.message:"Unknown error"}`)}},h=async({publicClient:e,policyContractAddress:n,interfaceId:r})=>{try{return await e.readContract({address:n,abi:o,functionName:"supportsInterface",args:[r]})}catch(t){throw new Error(`Newton SDK: Failed to get supportsInterface - ${t instanceof Error?t.message:"Unknown error"}`)}},f=async({publicClient:e,policyContractAddress:n})=>{try{return await e.readContract({address:n,abi:o,functionName:"owner"})}catch(r){throw new Error(`Newton SDK: Failed to get owner - ${r instanceof Error?r.message:"Unknown error"}`)}},g=async({publicClient:e,policyContractAddress:n})=>{try{return await e.readContract({address:n,abi:o,functionName:"factory"})}catch(r){throw new Error(`Newton SDK: Failed to get factory - ${r instanceof Error?r.message:"Unknown error"}`)}},m=async({publicClient:e,policyContractAddress:n})=>{try{return await e.readContract({address:n,abi:o,functionName:"entrypoint"})}catch(r){throw new Error(`Newton SDK: Failed to get entrypoint - ${r instanceof Error?r.message:"Unknown error"}`)}},C=async({publicClient:e,policyContractAddress:n})=>{try{return await e.readContract({address:n,abi:o,functionName:"schemaUri"})}catch(r){throw new Error(`Newton SDK: Failed to get schemaUri - ${r instanceof Error?r.message:"Unknown error"}`)}},N=async({publicClient:e,policyContractAddress:n,client:r})=>{try{return await e.readContract({address:n,abi:o,functionName:"clientToPolicyId",args:[r]})}catch(t){throw new Error(`Newton SDK: Failed to get clientToPolicyId - ${t instanceof Error?t.message:"Unknown error"}`)}},E=async({publicClient:e,policyContractAddress:n,index:r})=>{try{return await e.readContract({address:n,abi:o,functionName:"policyData",args:[BigInt(r)]})}catch(t){throw new Error(`Newton SDK: Failed to get policyData - ${t instanceof Error?t.message:"Unknown error"}`)}},b=({publicClient:e,policyContractAddress:n,...r})=>{try{const t=r.blockTimestamp||BigInt(Math.floor(Date.now()/1e3)),a={policyParams:`0x${new TextEncoder().encode(JSON.stringify(r.params)).reduce((i,s)=>i+s.toString(16).padStart(2,"0"),"")}`,expireAfter:r.expireAfter||0},c=l(["address","address[]","string","string","string","tuple(bytes,uint32)","uint256"],[r.client,r.policyData,r.policyUri,r.schemaUri,r.entrypoint,a,t]);return d(c)}catch(t){throw new Error(`Newton SDK: Failed to precompute policy ID - ${t instanceof Error?t.message:"Unknown error"}`)}},D=async({walletClient:e,policyContractAddress:n,...r})=>{try{if(!e.chain)throw new Error("Newton SDK: account and chain must be set on Wallet client");const t=e.account??(await e.getAddresses())[0];return await e.writeContract({address:n,abi:o,functionName:"initialize",args:[r.factory,r.entrypoint,r.policyUri,r.schemaUri,r.policyData],chain:e.chain,account:t})}catch(t){throw new Error(`Newton SDK: Failed to initialize - ${t instanceof Error?t.message:"Unknown error"}`)}},U=async({walletClient:e,policyContractAddress:n})=>{try{if(!e.chain)throw new Error("Newton SDK: account and chain must be set on Wallet client");const r=e.account??(await e.getAddresses())[0];return await e.writeContract({address:n,abi:o,functionName:"renounceOwnership",chain:e.chain,account:r})}catch(r){throw new Error(`Newton SDK: Failed to renounce ownership - ${r instanceof Error?r.message:"Unknown error"}`)}},A=async({walletClient:e,policyContractAddress:n,...r})=>{try{if(!e.chain)throw new Error("Newton SDK: account and chain must be set on Wallet client");const t=e.account??(await e.getAddresses())[0];return await e.writeContract({address:n,abi:o,functionName:"transferOwnership",args:[r.newOwner],chain:e.chain,account:t})}catch(t){throw new Error(`Newton SDK: Failed to transfer ownership - ${t instanceof Error?t.message:"Unknown error"}`)}},S={initialize:D,renounceOwnership:U,transferOwnership:A},k={policyUri:y,getPolicyId:p,getPolicyConfig:u,supportsInterface:h,owner:f,factory:g,entrypoint:m,schemaUri:C,clientToPolicyId:N,policyData:E,precomputePolicyId:b};export{k as policyReadFunctions,S as policyWriteFunctions};
|
package/dist/es/utils/intent.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{hexToBigInt as
|
|
1
|
+
import{hexToBigInt as u,toHex as a}from"viem";const o=t=>t.startsWith("0x")?t.slice(2):t;function c(t){let i;typeof t.value=="bigint"?i=t.value:i=u(t.value);let n;return typeof t.chainId=="bigint"?n=t.chainId:typeof t.chainId=="number"?n=BigInt(t.chainId):n=u(t.chainId),{...t,value:i,chainId:n}}function r(t){let i;typeof t.value=="bigint"?i=a(t.value):i=t.value;let n;return typeof t.chainId=="bigint"?n=a(t.chainId):typeof t.chainId=="number"?n=a(t.chainId):n=t.chainId,{from:t.from,to:t.to,value:i,data:o(t.data),chain_id:n,function_signature:o(t.functionSignature)}}export{c as normalizeIntent,o as removeHexPrefix,r as sanitizeIntentForRequest};
|
package/dist/es/utils/task.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{hexToBigInt as
|
|
1
|
+
import{hexToBigInt as r,keccak256 as p,encodePacked as c}from"viem";import{normalizeIntent as u}from"./intent.js";const l=e=>{const{policyClient:t,quorumNumber:n,quorumThresholdPercentage:a,wasmArgs:o,timeout:i}=e,s=u(e.intent);return p(c(["address","address","address","uint256","bytes","uint256","bytes","bytes","uint32","bytes","uint64"],[t,s.from,s.to,s.value,s.data,s.chainId,s.functionSignature,n||"0x",a??0,o||"0x",BigInt(i)]))};function d(e){const t={...e.args.taskResponse,intent:{...e.args.taskResponse.intent,value:BigInt(e.args.taskResponse.intent.value),data:e.args.taskResponse.intent.data,chainId:BigInt(e.args.taskResponse.intent.chainId)},evaluationResult:!!(e.args.taskResponse.evaluationResult&&r(e.args.taskResponse.evaluationResult))},n={taskResponsedBlock:Number(e.args.responseCertificate.taskResponsedBlock),responseExpireBlock:Number(e.args.responseCertificate.responseExpireBlock),hashOfNonSigners:e.args.responseCertificate.hashOfNonSigners},a={taskId:t.taskId,policyId:t.policyId,policyClient:t.policyClient,intent:t.intent,expiration:n.responseExpireBlock};return{taskResponse:t,responseCertificate:n,attestation:a}}export{d as convertLogToTaskResponse,l as getEvaluationRequestHash};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -11,12 +11,6 @@ declare const newtonWalletClientActions: (options?: {
|
|
|
11
11
|
txHash: Hex;
|
|
12
12
|
};
|
|
13
13
|
} & PendingTaskBuilder>;
|
|
14
|
-
setPolicy: (args: {
|
|
15
|
-
policyConfig: {
|
|
16
|
-
policyParams: object;
|
|
17
|
-
expireAfter: number;
|
|
18
|
-
};
|
|
19
|
-
}) => Promise<`0x${string}`>;
|
|
20
14
|
initialize: (args: {
|
|
21
15
|
factory: Address;
|
|
22
16
|
entrypoint: string;
|
|
@@ -44,20 +38,6 @@ declare const newtonPublicClientActions: (options?: {
|
|
|
44
38
|
taskId: TaskId;
|
|
45
39
|
}) => Promise<TaskStatus>;
|
|
46
40
|
policyUri: () => Promise<string>;
|
|
47
|
-
getPolicyData: () => Promise<Address[]>;
|
|
48
|
-
getPolicyUri: () => Promise<string>;
|
|
49
|
-
getSchemaUri: () => Promise<string>;
|
|
50
|
-
getEntrypoint: () => Promise<string>;
|
|
51
|
-
getPolicyId: (args: {
|
|
52
|
-
client: Address;
|
|
53
|
-
}) => Promise<`0x${string}`>;
|
|
54
|
-
getPolicyConfig: (args: {
|
|
55
|
-
policyId: `0x${string}`;
|
|
56
|
-
}) => Promise<{
|
|
57
|
-
policyParams: string | object;
|
|
58
|
-
policyParamsHex: `0x${string}`;
|
|
59
|
-
expireAfter: number;
|
|
60
|
-
}>;
|
|
61
41
|
supportsInterface: (args: {
|
|
62
42
|
interfaceId: `0x${string}`;
|
|
63
43
|
}) => Promise<boolean>;
|
|
@@ -65,12 +45,22 @@ declare const newtonPublicClientActions: (options?: {
|
|
|
65
45
|
factory: () => Promise<Address>;
|
|
66
46
|
entrypoint: () => Promise<string>;
|
|
67
47
|
schemaUri: () => Promise<string>;
|
|
68
|
-
clientToPolicyId: (args: {
|
|
69
|
-
client: Address;
|
|
70
|
-
}) => Promise<`0x${string}`>;
|
|
71
48
|
policyData: (args: {
|
|
72
49
|
index: number;
|
|
73
50
|
}) => Promise<Address>;
|
|
51
|
+
clientToPolicyId: (args: {
|
|
52
|
+
client: Address;
|
|
53
|
+
}) => Promise<`0x${string}`>;
|
|
54
|
+
getPolicyId: (args: {
|
|
55
|
+
client: Address;
|
|
56
|
+
}) => Promise<`0x${string}`>;
|
|
57
|
+
getPolicyConfig: (args: {
|
|
58
|
+
policyId: `0x${string}`;
|
|
59
|
+
}) => Promise<{
|
|
60
|
+
policyParams: string | object;
|
|
61
|
+
policyParamsHex: `0x${string}`;
|
|
62
|
+
expireAfter: number;
|
|
63
|
+
}>;
|
|
74
64
|
precomputePolicyId: (args: {
|
|
75
65
|
policyContract: Address;
|
|
76
66
|
policyData: Address[];
|
|
@@ -1,14 +1,6 @@
|
|
|
1
1
|
import { PolicyId, PolicyParamsJson } from '../../types/policy';
|
|
2
2
|
import { PublicClient, WalletClient, Address } from 'viem';
|
|
3
3
|
export declare const policyWriteFunctions: {
|
|
4
|
-
setPolicy: ({ walletClient, policyContractAddress, ...args }: {
|
|
5
|
-
walletClient: WalletClient;
|
|
6
|
-
policyContractAddress: Address;
|
|
7
|
-
policyConfig: {
|
|
8
|
-
policyParams: object;
|
|
9
|
-
expireAfter: number;
|
|
10
|
-
};
|
|
11
|
-
}) => Promise<`0x${string}`>;
|
|
12
4
|
initialize: ({ walletClient, policyContractAddress, ...args }: {
|
|
13
5
|
walletClient: WalletClient;
|
|
14
6
|
policyContractAddress: Address;
|
|
@@ -33,22 +25,6 @@ export declare const policyReadFunctions: {
|
|
|
33
25
|
publicClient: PublicClient;
|
|
34
26
|
policyContractAddress: Address;
|
|
35
27
|
}) => Promise<string>;
|
|
36
|
-
getPolicyData: ({ publicClient, policyContractAddress, }: {
|
|
37
|
-
publicClient: PublicClient;
|
|
38
|
-
policyContractAddress: Address;
|
|
39
|
-
}) => Promise<Address[]>;
|
|
40
|
-
getPolicyUri: ({ publicClient, policyContractAddress, }: {
|
|
41
|
-
publicClient: PublicClient;
|
|
42
|
-
policyContractAddress: Address;
|
|
43
|
-
}) => Promise<string>;
|
|
44
|
-
getSchemaUri: ({ publicClient, policyContractAddress, }: {
|
|
45
|
-
publicClient: PublicClient;
|
|
46
|
-
policyContractAddress: Address;
|
|
47
|
-
}) => Promise<string>;
|
|
48
|
-
getEntrypoint: ({ publicClient, policyContractAddress, }: {
|
|
49
|
-
publicClient: PublicClient;
|
|
50
|
-
policyContractAddress: Address;
|
|
51
|
-
}) => Promise<string>;
|
|
52
28
|
getPolicyId: ({ publicClient, policyContractAddress, client, }: {
|
|
53
29
|
publicClient: PublicClient;
|
|
54
30
|
policyContractAddress: Address;
|
|
@@ -109,14 +85,6 @@ export declare const policyReadFunctions: {
|
|
|
109
85
|
}) => PolicyId;
|
|
110
86
|
};
|
|
111
87
|
export declare const policyFunctions: {
|
|
112
|
-
setPolicy: ({ walletClient, policyContractAddress, ...args }: {
|
|
113
|
-
walletClient: WalletClient;
|
|
114
|
-
policyContractAddress: Address;
|
|
115
|
-
policyConfig: {
|
|
116
|
-
policyParams: object;
|
|
117
|
-
expireAfter: number;
|
|
118
|
-
};
|
|
119
|
-
}) => Promise<`0x${string}`>;
|
|
120
88
|
initialize: ({ walletClient, policyContractAddress, ...args }: {
|
|
121
89
|
walletClient: WalletClient;
|
|
122
90
|
policyContractAddress: Address;
|
|
@@ -139,22 +107,6 @@ export declare const policyFunctions: {
|
|
|
139
107
|
publicClient: PublicClient;
|
|
140
108
|
policyContractAddress: Address;
|
|
141
109
|
}) => Promise<string>;
|
|
142
|
-
getPolicyData: ({ publicClient, policyContractAddress, }: {
|
|
143
|
-
publicClient: PublicClient;
|
|
144
|
-
policyContractAddress: Address;
|
|
145
|
-
}) => Promise<Address[]>;
|
|
146
|
-
getPolicyUri: ({ publicClient, policyContractAddress, }: {
|
|
147
|
-
publicClient: PublicClient;
|
|
148
|
-
policyContractAddress: Address;
|
|
149
|
-
}) => Promise<string>;
|
|
150
|
-
getSchemaUri: ({ publicClient, policyContractAddress, }: {
|
|
151
|
-
publicClient: PublicClient;
|
|
152
|
-
policyContractAddress: Address;
|
|
153
|
-
}) => Promise<string>;
|
|
154
|
-
getEntrypoint: ({ publicClient, policyContractAddress, }: {
|
|
155
|
-
publicClient: PublicClient;
|
|
156
|
-
policyContractAddress: Address;
|
|
157
|
-
}) => Promise<string>;
|
|
158
110
|
getPolicyId: ({ publicClient, policyContractAddress, client, }: {
|
|
159
111
|
publicClient: PublicClient;
|
|
160
112
|
policyContractAddress: Address;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Address, Hex } from 'viem';
|
|
2
2
|
export type TaskId = Hex;
|
|
3
|
-
export interface
|
|
3
|
+
export interface IntentFromParams {
|
|
4
4
|
from: Address;
|
|
5
5
|
to: Address;
|
|
6
6
|
value: Hex | bigint;
|
|
@@ -10,10 +10,10 @@ export interface Intent {
|
|
|
10
10
|
}
|
|
11
11
|
export interface SubmitEvaluationRequestParams {
|
|
12
12
|
policyClient: Address;
|
|
13
|
-
intent:
|
|
14
|
-
quorumNumber?: Hex
|
|
13
|
+
intent: IntentFromParams;
|
|
14
|
+
quorumNumber?: Hex;
|
|
15
15
|
quorumThresholdPercentage?: number;
|
|
16
|
-
wasmArgs?: Hex
|
|
16
|
+
wasmArgs?: Hex;
|
|
17
17
|
timeout: number;
|
|
18
18
|
}
|
|
19
19
|
export interface NormalizedIntent {
|
|
@@ -28,9 +28,9 @@ export interface HexlifiedIntent {
|
|
|
28
28
|
from: Address;
|
|
29
29
|
to: Address;
|
|
30
30
|
value: Hex;
|
|
31
|
-
data:
|
|
31
|
+
data: string;
|
|
32
32
|
chain_id: Hex;
|
|
33
|
-
function_signature:
|
|
33
|
+
function_signature: string;
|
|
34
34
|
}
|
|
35
35
|
interface TaskResponse {
|
|
36
36
|
taskId: Hex;
|
|
@@ -41,9 +41,9 @@ interface TaskResponse {
|
|
|
41
41
|
from: Address;
|
|
42
42
|
to: Address;
|
|
43
43
|
value: bigint;
|
|
44
|
-
data:
|
|
44
|
+
data: string;
|
|
45
45
|
chainId: bigint;
|
|
46
|
-
functionSignature:
|
|
46
|
+
functionSignature: string;
|
|
47
47
|
};
|
|
48
48
|
evaluationResult: boolean;
|
|
49
49
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
import { HexlifiedIntent,
|
|
2
|
-
|
|
3
|
-
export declare
|
|
1
|
+
import { HexlifiedIntent, IntentFromParams, NormalizedIntent } from '../types/task';
|
|
2
|
+
import { Hex } from 'viem';
|
|
3
|
+
export declare const removeHexPrefix: (input: Hex) => string;
|
|
4
|
+
export declare function normalizeIntent(intent: IntentFromParams): NormalizedIntent;
|
|
5
|
+
export declare function sanitizeIntentForRequest(intent: IntentFromParams): HexlifiedIntent;
|
package/package.json
CHANGED
package/dist/cjs/utils/bytes.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";var r=require("viem");function t(e){return typeof e=="string"?e:r.toHex(e)}exports.normalizeBytes=t;
|
package/dist/es/utils/bytes.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{toHex as r}from"viem";function e(t){return typeof t=="string"?t:r(t)}export{e as normalizeBytes};
|