@magicnewton/newton-protocol-sdk 0.2.10 → 0.2.11--canary.91.20238525318.0
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/const.js +1 -1
- package/dist/cjs/modules/avs/index.js +1 -1
- package/dist/cjs/utils/https.js +1 -1
- package/dist/es/const.js +1 -1
- package/dist/es/modules/avs/index.js +1 -1
- package/dist/es/utils/https.js +1 -1
- package/dist/types/const.d.ts +3 -5
- package/dist/types/modules/avs/index.d.ts +3 -5
- package/package.json +1 -1
package/dist/cjs/const.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const A="https://
|
|
1
|
+
"use strict";const A="https://gateway-avs.sepolia.newt.foundation/",T="https://gateway-avs.newt.foundation/",E={createTask:"newt_createTask"},_="0xb9758d9d03e6dfb8001cadf63b87ba519a618e13",a="0xc8da20766a6baaa7daeea1be8006f10c0fa4b7a0",N="0x2010dbaa5438801bdc3f08174a799fe344f544ee",I="0x263c275c15867a4611a44c600e77144a23012a06";exports.GATEWAY_METHODS=E,exports.MAINNET_ATTESTATION_VALIDATOR=I,exports.MAINNET_GATEWAY_API=T,exports.MAINNET_NEWTON_PROVER_TASK_MANAGER=N,exports.SEPOLIA_ATTESTATION_VALIDATOR=a,exports.SEPOLIA_NEWTON_PROVER_TASK_MANAGER=_,exports.TESTNET_GATEWAY_API=A;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var l=require("../../abis/newtonAbi.js"),C=require("../../const.js"),p=require("../../types/task.js"),P=require("../../utils/https.js"),v=require("../../utils/intent.js"),b=require("../../utils/task.js"),o=require("viem"),M=require("viem/accounts"),q=require("viem/chains");const R={[q.sepolia.id]:BigInt(9223883),[q.mainnet.id]:BigInt(23385048)},A=async(t,e,a,w)=>{if(!e.taskId)throw new Error("Newton SDK: waitForTaskResponded requires taskId");const m=o.padHex(e.taskId,{size:32}),i=R[t.chain?.id??1],r=w??i,u=(await t.getContractEvents({address:a,abi:l.NewtonProverTaskManagerAbi,eventName:"TaskResponded",fromBlock:r,toBlock:"latest"})).find(s=>o.padHex(s.args.taskResponse.taskId,{size:32})===m);return u?b.convertLogToTaskResponse(u):new Promise((s,T)=>{let g,d;const c=n=>{g?.(),d&&clearTimeout(d),n&&T(n)};if(e.timeoutMs&&e.timeoutMs>0&&(d=setTimeout(()=>c(new Error("waitForTaskResponded: timeout")),e.timeoutMs)),e.abortSignal){if(e.abortSignal.aborted){c(new Error("waitForTaskResponded: aborted"));return}e.abortSignal.addEventListener("abort",()=>c(new Error("waitForTaskResponded: aborted")),{once:!0})}g=t.watchContractEvent({address:a,abi:l.NewtonProverTaskManagerAbi,eventName:"TaskResponded",onLogs:n=>{for(const h of n)if(o.padHex(h.args.taskResponse.taskId,{size:32})===m){const f=b.convertLogToTaskResponse(h);c(),s(f);return}},onError:n=>{c(n)}})})},_=(t,e,a)=>t.readContract({address:a,abi:l.NewtonProverTaskManagerAbi,functionName:"allTaskHashes",args:[e.taskId]}),F=async(t,e,a,w)=>{const m=await t.readContract({address:a,abi:l.NewtonProverTaskManagerAbi,functionName:"allTaskHashes",args:[e.taskId]});if(!o.hexToBigInt(m))throw new Error(`Failed to retrieve task status for taskId ${e.taskId}`);const i=await t.readContract({address:a,abi:l.NewtonProverTaskManagerAbi,functionName:"allTaskResponses",args:[e.taskId]}),r=!!o.hexToBigInt(i);if(!r)return p.TaskStatus.Created;const u=(await t.getContractEvents({address:a,abi:l.NewtonProverTaskManagerAbi,eventName:"TaskResponded",fromBlock:R[t.chain?.id??1],toBlock:"latest"})).find(d=>o.padHex(d.args.taskResponse.taskId,{size:32})===e.taskId);if(!u)throw new Error(`Failed to retrieve task status for taskId ${e.taskId}`);const s=b.convertLogToTaskResponse(u),T=await t.getBlockNumber();if(s?.responseCertificate?.responseExpireBlock&&T>s.responseCertificate.responseExpireBlock)return p.TaskStatus.AttestationExpired;const g=await t.readContract({address:w,abi:l.AttestationValidatorAbi,functionName:"attestations",args:[e.taskId]});return o.hexToBigInt(g)?r?p.TaskStatus.Responded:p.TaskStatus.Created:p.TaskStatus.AttestationSpent};async function y(t,e,a,w,m){const i=t.extend(o.publicActions),r={taskRequestedAtBlock:await i.getBlockNumber()},u=new P.AvsHttpService(!!i?.chain?.testnet,m),{policyClient:s,intentSignature:T,quorumNumber:g,quorumThresholdPercentage:d,wasmArgs:c,timeout:n}=e,h=v.normalizeIntent(e.intent),f=b.getEvaluationRequestHash({policyClient:s,intent:h,intentSignature:T,quorumNumber:g,quorumThresholdPercentage:d,wasmArgs:c,timeout:n}),I=await M.privateKeyToAccount(w).sign({hash:f}),N=v.sanitizeIntentForRequest(e.intent),x={policy_client:e.policyClient,intent:N,intent_signature:e.intentSignature?v.removeHexPrefix(e.intentSignature):null,quorum_number:e.quorumNumber?v.removeHexPrefix(e.quorumNumber):null,quorum_threshold_percentage:e.quorumThresholdPercentage??null,wasm_args:e.wasmArgs?v.removeHexPrefix(e.wasmArgs):null,timeout:e.timeout,request_signature:I},k=await u.Post(C.
|
|
1
|
+
"use strict";var l=require("../../abis/newtonAbi.js"),C=require("../../const.js"),p=require("../../types/task.js"),P=require("../../utils/https.js"),v=require("../../utils/intent.js"),b=require("../../utils/task.js"),o=require("viem"),M=require("viem/accounts"),q=require("viem/chains");const R={[q.sepolia.id]:BigInt(9223883),[q.mainnet.id]:BigInt(23385048)},A=async(t,e,a,w)=>{if(!e.taskId)throw new Error("Newton SDK: waitForTaskResponded requires taskId");const m=o.padHex(e.taskId,{size:32}),i=R[t.chain?.id??1],r=w??i,u=(await t.getContractEvents({address:a,abi:l.NewtonProverTaskManagerAbi,eventName:"TaskResponded",fromBlock:r,toBlock:"latest"})).find(s=>o.padHex(s.args.taskResponse.taskId,{size:32})===m);return u?b.convertLogToTaskResponse(u):new Promise((s,T)=>{let g,d;const c=n=>{g?.(),d&&clearTimeout(d),n&&T(n)};if(e.timeoutMs&&e.timeoutMs>0&&(d=setTimeout(()=>c(new Error("waitForTaskResponded: timeout")),e.timeoutMs)),e.abortSignal){if(e.abortSignal.aborted){c(new Error("waitForTaskResponded: aborted"));return}e.abortSignal.addEventListener("abort",()=>c(new Error("waitForTaskResponded: aborted")),{once:!0})}g=t.watchContractEvent({address:a,abi:l.NewtonProverTaskManagerAbi,eventName:"TaskResponded",onLogs:n=>{for(const h of n)if(o.padHex(h.args.taskResponse.taskId,{size:32})===m){const f=b.convertLogToTaskResponse(h);c(),s(f);return}},onError:n=>{c(n)}})})},_=(t,e,a)=>t.readContract({address:a,abi:l.NewtonProverTaskManagerAbi,functionName:"allTaskHashes",args:[e.taskId]}),F=async(t,e,a,w)=>{const m=await t.readContract({address:a,abi:l.NewtonProverTaskManagerAbi,functionName:"allTaskHashes",args:[e.taskId]});if(!o.hexToBigInt(m))throw new Error(`Failed to retrieve task status for taskId ${e.taskId}`);const i=await t.readContract({address:a,abi:l.NewtonProverTaskManagerAbi,functionName:"allTaskResponses",args:[e.taskId]}),r=!!o.hexToBigInt(i);if(!r)return p.TaskStatus.Created;const u=(await t.getContractEvents({address:a,abi:l.NewtonProverTaskManagerAbi,eventName:"TaskResponded",fromBlock:R[t.chain?.id??1],toBlock:"latest"})).find(d=>o.padHex(d.args.taskResponse.taskId,{size:32})===e.taskId);if(!u)throw new Error(`Failed to retrieve task status for taskId ${e.taskId}`);const s=b.convertLogToTaskResponse(u),T=await t.getBlockNumber();if(s?.responseCertificate?.responseExpireBlock&&T>s.responseCertificate.responseExpireBlock)return p.TaskStatus.AttestationExpired;const g=await t.readContract({address:w,abi:l.AttestationValidatorAbi,functionName:"attestations",args:[e.taskId]});return o.hexToBigInt(g)?r?p.TaskStatus.Responded:p.TaskStatus.Created:p.TaskStatus.AttestationSpent};async function y(t,e,a,w,m){const i=t.extend(o.publicActions),r={taskRequestedAtBlock:await i.getBlockNumber()},u=new P.AvsHttpService(!!i?.chain?.testnet,m),{policyClient:s,intentSignature:T,quorumNumber:g,quorumThresholdPercentage:d,wasmArgs:c,timeout:n}=e,h=v.normalizeIntent(e.intent),f=b.getEvaluationRequestHash({policyClient:s,intent:h,intentSignature:T,quorumNumber:g,quorumThresholdPercentage:d,wasmArgs:c,timeout:n}),I=await M.privateKeyToAccount(w).sign({hash:f}),N=v.sanitizeIntentForRequest(e.intent),x={policy_client:e.policyClient,intent:N,intent_signature:e.intentSignature?v.removeHexPrefix(e.intentSignature):null,quorum_number:e.quorumNumber?v.removeHexPrefix(e.quorumNumber):null,quorum_threshold_percentage:e.quorumThresholdPercentage??null,wasm_args:e.wasmArgs?v.removeHexPrefix(e.wasmArgs):null,timeout:e.timeout,request_signature:I},k=await u.Post(C.GATEWAY_METHODS.createTask,[x],I);if(k.error)throw k.error;if(k.result.error)throw new Error(k.result.error);const E=k.result;r.taskId=E.task_id;const S={get taskId(){return r.taskId},waitForTaskResponded:async({timeoutMs:B})=>{const H=r.taskId;return A(i,{taskId:H,timeoutMs:B},a,r.taskRequestedAtBlock)}};return{result:{taskId:k.result.task_id,txHash:k.result.tx_hash},...S}}exports.getTaskResponseHash=_,exports.getTaskStatus=F,exports.submitEvaluationRequest=y,exports.waitForTaskResponded=A;
|
package/dist/cjs/utils/https.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var s=require("../const.js"),n=require("./json-rpc.js"),c=Object.defineProperty,o=(t,e,r)=>e in t?c(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,u=(t,e,r)=>o(t,e+"",r);class l{constructor(e,r){u(this,"baseUrl"),this.baseUrl=r||(e?s.
|
|
1
|
+
"use strict";var s=require("../const.js"),n=require("./json-rpc.js"),c=Object.defineProperty,o=(t,e,r)=>e in t?c(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,u=(t,e,r)=>o(t,e+"",r);class l{constructor(e,r){u(this,"baseUrl"),this.baseUrl=r||(e?s.TESTNET_GATEWAY_API:s.MAINNET_GATEWAY_API)}async Post(e,r,a){const i=n.createJsonRpcRequestPayload(e,r);return(await fetch(this.baseUrl,{method:"POST",headers:{"Content-Type":"application/json",...a?{Authorization:`Bearer ${a}`}:{}},body:JSON.stringify(i)})).json()}}exports.AvsHttpService=l;
|
package/dist/es/const.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
const a="https://
|
|
1
|
+
const a="https://gateway-avs.sepolia.newt.foundation/",A="https://gateway-avs.newt.foundation/",T={createTask:"newt_createTask"},e="0xb9758d9d03e6dfb8001cadf63b87ba519a618e13",E="0xc8da20766a6baaa7daeea1be8006f10c0fa4b7a0",_="0x2010dbaa5438801bdc3f08174a799fe344f544ee",t="0x263c275c15867a4611a44c600e77144a23012a06";export{T as GATEWAY_METHODS,t as MAINNET_ATTESTATION_VALIDATOR,A as MAINNET_GATEWAY_API,_ as MAINNET_NEWTON_PROVER_TASK_MANAGER,E as SEPOLIA_ATTESTATION_VALIDATOR,e as SEPOLIA_NEWTON_PROVER_TASK_MANAGER,a as TESTNET_GATEWAY_API};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{NewtonProverTaskManagerAbi as l,AttestationValidatorAbi as _}from"../../abis/newtonAbi.js";import{
|
|
1
|
+
import{NewtonProverTaskManagerAbi as l,AttestationValidatorAbi as _}from"../../abis/newtonAbi.js";import{GATEWAY_METHODS as F}from"../../const.js";import{TaskStatus as w}from"../../types/task.js";import{AvsHttpService as H}from"../../utils/https.js";import{normalizeIntent as y,sanitizeIntentForRequest as M,removeHexPrefix as I}from"../../utils/intent.js";import{convertLogToTaskResponse as b,getEvaluationRequestHash as P}from"../../utils/task.js";import{hexToBigInt as R,padHex as T,publicActions as z}from"viem";import{privateKeyToAccount as L}from"viem/accounts";import{mainnet as $,sepolia as D}from"viem/chains";const q={[D.id]:BigInt(9223883),[$.id]:BigInt(23385048)},v=async(e,t,r,p)=>{if(!t.taskId)throw new Error("Newton SDK: waitForTaskResponded requires taskId");const c=T(t.taskId,{size:32}),n=q[e.chain?.id??1],a=p??n,i=(await e.getContractEvents({address:r,abi:l,eventName:"TaskResponded",fromBlock:a,toBlock:"latest"})).find(s=>T(s.args.taskResponse.taskId,{size:32})===c);return i?b(i):new Promise((s,g)=>{let k,d;const u=o=>{k?.(),d&&clearTimeout(d),o&&g(o)};if(t.timeoutMs&&t.timeoutMs>0&&(d=setTimeout(()=>u(new Error("waitForTaskResponded: timeout")),t.timeoutMs)),t.abortSignal){if(t.abortSignal.aborted){u(new Error("waitForTaskResponded: aborted"));return}t.abortSignal.addEventListener("abort",()=>u(new Error("waitForTaskResponded: aborted")),{once:!0})}k=e.watchContractEvent({address:r,abi:l,eventName:"TaskResponded",onLogs:o=>{for(const f of o)if(T(f.args.taskResponse.taskId,{size:32})===c){const h=b(f);u(),s(h);return}},onError:o=>{u(o)}})})},G=(e,t,r)=>e.readContract({address:r,abi:l,functionName:"allTaskHashes",args:[t.taskId]}),K=async(e,t,r,p)=>{const c=await e.readContract({address:r,abi:l,functionName:"allTaskHashes",args:[t.taskId]});if(!R(c))throw new Error(`Failed to retrieve task status for taskId ${t.taskId}`);const n=await e.readContract({address:r,abi:l,functionName:"allTaskResponses",args:[t.taskId]}),a=!!R(n);if(!a)return w.Created;const i=(await e.getContractEvents({address:r,abi:l,eventName:"TaskResponded",fromBlock:q[e.chain?.id??1],toBlock:"latest"})).find(d=>T(d.args.taskResponse.taskId,{size:32})===t.taskId);if(!i)throw new Error(`Failed to retrieve task status for taskId ${t.taskId}`);const s=b(i),g=await e.getBlockNumber();if(s?.responseCertificate?.responseExpireBlock&&g>s.responseCertificate.responseExpireBlock)return w.AttestationExpired;const k=await e.readContract({address:p,abi:_,functionName:"attestations",args:[t.taskId]});return R(k)?a?w.Responded:w.Created:w.AttestationSpent};async function O(e,t,r,p,c){const n=e.extend(z),a={taskRequestedAtBlock:await n.getBlockNumber()},i=new H(!!n?.chain?.testnet,c),{policyClient:s,intentSignature:g,quorumNumber:k,quorumThresholdPercentage:d,wasmArgs:u,timeout:o}=t,f=y(t.intent),h=P({policyClient:s,intent:f,intentSignature:g,quorumNumber:k,quorumThresholdPercentage:d,wasmArgs:u,timeout:o}),E=await L(p).sign({hash:h}),A=M(t.intent),N={policy_client:t.policyClient,intent:A,intent_signature:t.intentSignature?I(t.intentSignature):null,quorum_number:t.quorumNumber?I(t.quorumNumber):null,quorum_threshold_percentage:t.quorumThresholdPercentage??null,wasm_args:t.wasmArgs?I(t.wasmArgs):null,timeout:t.timeout,request_signature:E},m=await i.Post(F.createTask,[N],E);if(m.error)throw m.error;if(m.result.error)throw new Error(m.result.error);const B=m.result;a.taskId=B.task_id;const C={get taskId(){return a.taskId},waitForTaskResponded:async({timeoutMs:S})=>{const x=a.taskId;return v(n,{taskId:x,timeoutMs:S},r,a.taskRequestedAtBlock)}};return{result:{taskId:m.result.task_id,txHash:m.result.tx_hash},...C}}export{G as getTaskResponseHash,K as getTaskStatus,O as submitEvaluationRequest,v as waitForTaskResponded};
|
package/dist/es/utils/https.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{
|
|
1
|
+
import{TESTNET_GATEWAY_API as s,MAINNET_GATEWAY_API as i}from"../const.js";import{createJsonRpcRequestPayload as n}from"./json-rpc.js";var c=Object.defineProperty,l=(t,r,e)=>r in t?c(t,r,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[r]=e,u=(t,r,e)=>l(t,r+"",e);class p{constructor(r,e){u(this,"baseUrl"),this.baseUrl=e||(r?s:i)}async Post(r,e,a){const o=n(r,e);return(await fetch(this.baseUrl,{method:"POST",headers:{"Content-Type":"application/json",...a?{Authorization:`Bearer ${a}`}:{}},body:JSON.stringify(o)})).json()}}export{p as AvsHttpService};
|
package/dist/types/const.d.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
export declare const
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const
|
|
1
|
+
export declare const TESTNET_GATEWAY_API = "https://gateway-avs.sepolia.newt.foundation/";
|
|
2
|
+
export declare const MAINNET_GATEWAY_API = "https://gateway-avs.newt.foundation/";
|
|
3
|
+
export declare const GATEWAY_METHODS: {
|
|
4
4
|
createTask: string;
|
|
5
|
-
waitForTaskId: string;
|
|
6
|
-
createTaskAndWait: string;
|
|
7
5
|
};
|
|
8
6
|
export declare const SEPOLIA_NEWTON_PROVER_TASK_MANAGER = "0xb9758d9d03e6dfb8001cadf63b87ba519a618e13";
|
|
9
7
|
export declare const SEPOLIA_ATTESTATION_VALIDATOR = "0xc8da20766a6baaa7daeea1be8006f10c0fa4b7a0";
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { SubmitEvaluationRequestParams, TaskId, TaskResponseResult, TaskStatus } from '../../types/task';
|
|
2
2
|
import { PublicClient as Client, WalletClient, Hex, Address } from 'viem';
|
|
3
|
-
export interface
|
|
3
|
+
export interface CreateTaskResult {
|
|
4
4
|
task_id: Hex;
|
|
5
5
|
task_request: any;
|
|
6
6
|
status: 'Completed' | 'Failed';
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
};
|
|
7
|
+
aggregation_response: any;
|
|
8
|
+
timestamp: number;
|
|
10
9
|
error?: unknown;
|
|
11
|
-
processing_time_ms?: number;
|
|
12
10
|
}
|
|
13
11
|
export interface PendingTaskBuilder {
|
|
14
12
|
readonly taskId?: TaskId;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@magicnewton/newton-protocol-sdk",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.11--canary.91.20238525318.0",
|
|
4
4
|
"description": "Official SDK for the Newton Protocol.",
|
|
5
5
|
"author": "Newton Foundation <https://x.com/newtfoundation> (https://newton.foundation)",
|
|
6
6
|
"private": false,
|