UNPKG

wowok_agent

Version:

Create, collaborate, and transact on your own terms with the AI-driven web3 collaboration protocol.

1 lines 26.8 kB
"use strict";(this.webpackChunkwowok_agent=this.webpackChunkwowok_agent||[]).push([[305],{1548:(e,t,r)=>{r.d(t,{AX:()=>l,uS:()=>u,At:()=>p,yk:()=>w});var s=r(9440),n=r(5412),i=r(8740),a=r(7324),o=r(5762),c=r(1646);const u=32,d="suiprivkey";class h{async signWithIntent(e,t){const r=(0,o.i)(t,e),n=(0,i.S)(r,{dkLen:32});return{signature:function({signature:e,signatureScheme:t,publicKey:r}){if(!r)throw new Error("`publicKey` is required");const n=r.toRawBytes(),i=new Uint8Array(1+e.length+n.length);return i.set([c.uD[t]]),i.set(e,1),i.set(n,1+e.length),(0,s.nk)(i)}({signature:await this.sign(n),signatureScheme:this.getKeyScheme(),publicKey:this.getPublicKey()}),bytes:(0,s.nk)(e)}}async signTransaction(e){return this.signWithIntent(e,"TransactionData")}async signPersonalMessage(e){const{signature:t}=await this.signWithIntent(n.j.vector(n.j.u8()).serialize(e).toBytes(),"PersonalMessage");return{bytes:(0,s.nk)(e),signature:t}}toSuiAddress(){return this.getPublicKey().toSuiAddress()}}class l extends h{}function p(e){const{prefix:t,words:r}=a.I.decode(e);if(t!==d)throw new Error("invalid private key prefix");const s=new Uint8Array(a.I.fromWords(r)),n=s.slice(1);return{schema:c.y3[s[0]],secretKey:n}}function w(e,t){if(e.length!==u)throw new Error("Invalid bytes length");const r=c.uD[t],s=new Uint8Array(e.length+1);return s.set([r]),s.set(e,1),a.I.encode(d,a.I.toWords(s))}},1646:(e,t,r)=>{r.d(t,{Pz:()=>n,uD:()=>s,y3:()=>i});const s={ED25519:0,Secp256k1:1,Secp256r1:2,MultiSig:3,ZkLogin:5,Passkey:6},n={ED25519:32,Secp256k1:33,Secp256r1:33},i={0:"ED25519",1:"Secp256k1",2:"Secp256r1",3:"MultiSig",5:"ZkLogin",6:"Passkey"}},5744:(e,t,r)=>{r.d(t,{h:()=>T});var s=r(6216),n=r(1548),i=r(4329),a=r(9548);function o(e){return!!new RegExp("^m\\/44'\\/784'\\/[0-9]+'\\/[0-9]+'\\/[0-9]+'+$").test(e)}var c=r(1454),u=r(4443);const d=new RegExp("^m(\\/[0-9]+')+$"),h=e=>e.replace("'",""),l=(e,t,r=2147483648)=>{if(!(e=>!!d.test(e)&&!e.split("/").slice(1).map(h).some(isNaN))(e))throw new Error("Invalid derivation path");const{key:s,chainCode:n}=(e=>{const t=c.w.create(u.Zf,"ed25519 seed").update((0,i.aD)(e)).digest();return{key:t.slice(0,32),chainCode:t.slice(32)}})(t);return e.split("/").slice(1).map(h).map((e=>parseInt(e,10))).reduce(((e,t)=>(({key:e,chainCode:t},r)=>{const s=new ArrayBuffer(4);new DataView(s).setUint32(0,r);const n=new Uint8Array(1+e.length+s.byteLength);n.set(new Uint8Array(1).fill(0)),n.set(e,1),n.set(new Uint8Array(s,0,s.byteLength),e.length+1);const i=c.w.create(u.Zf,t).update(n).digest();return{key:i.slice(0,32),chainCode:i.slice(32)}})(e,t+r)),{key:s,chainCode:n})};var p=r(9440),w=r(8740),y=r(2531),g=r(6101),m=r(9298),f=r(5762),b=r(1646);function k(e,t){if(e===t)return!0;if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++)if(e[r]!==t[r])return!1;return!0}class v{equals(e){return k(this.toRawBytes(),e.toRawBytes())}toBase64(){return(0,p.nk)(this.toRawBytes())}toString(){throw new Error("`toString` is not implemented on public keys. Use `toBase64()` or `toRawBytes()` instead.")}toSuiPublicKey(){const e=this.toSuiBytes();return(0,p.nk)(e)}verifyWithIntent(e,t,r){const s=(0,f.i)(r,e),n=(0,w.S)(s,{dkLen:32});return this.verify(n,t)}verifyPersonalMessage(e,t){return this.verifyWithIntent(g.jy.vector(g.jy.u8()).serialize(e).toBytes(),t,"PersonalMessage")}verifyTransaction(e,t){return this.verifyWithIntent(e,t,"TransactionData")}verifyAddress(e){return this.toSuiAddress()===e}toSuiBytes(){const e=this.toRawBytes(),t=new Uint8Array(e.length+1);return t.set([this.flag()]),t.set(e,1),t}toSuiAddress(){return(0,m.t4)((0,y.My)((0,w.S)(this.toSuiBytes(),{dkLen:32})).slice(0,2*m.wn))}}class S extends v{constructor(e){if(super(),"string"==typeof e?this.data=(0,p.Ey)(e):e instanceof Uint8Array?this.data=e:this.data=Uint8Array.from(e),32!==this.data.length)throw new Error(`Invalid public key input. Expected 32 bytes, got ${this.data.length}`)}equals(e){return super.equals(e)}toRawBytes(){return this.data}flag(){return b.uD.ED25519}async verify(e,t){let r;if("string"==typeof t){const e=function(e){const t=(0,p.Ey)(e),r=b.y3[t[0]];switch(r){case"ED25519":case"Secp256k1":case"Secp256r1":const s=b.Pz[r],n=t.slice(1,t.length-s);return{serializedSignature:e,signatureScheme:r,signature:n,publicKey:t.slice(1+n.length),bytes:t};default:throw new Error("Unsupported signature scheme")}}(t);if("ED25519"!==e.signatureScheme)throw new Error("Invalid signature scheme");if(!k(this.toRawBytes(),e.publicKey))throw new Error("Signature does not match public key");r=e.signature}else r=t;return s.ev.verify(r,e,this.toRawBytes())}}S.SIZE=32;const E="m/44'/784'/0'/0'/0'";class T extends n.AX{constructor(e){if(super(),e)this.keypair={publicKey:e.publicKey,secretKey:e.secretKey.slice(0,32)};else{const e=s.ev.utils.randomPrivateKey();this.keypair={publicKey:s.ev.getPublicKey(e),secretKey:e}}}getKeyScheme(){return"ED25519"}static generate(){const e=s.ev.utils.randomPrivateKey();return new T({publicKey:s.ev.getPublicKey(e),secretKey:e})}static fromSecretKey(e,t){if("string"==typeof e){const r=(0,n.At)(e);if("ED25519"!==r.schema)throw new Error(`Expected a ED25519 keypair, got ${r.schema}`);return this.fromSecretKey(r.secretKey,t)}const r=e.length;if(r!==n.uS)throw new Error(`Wrong secretKey size. Expected ${n.uS} bytes, got ${r}.`);const i={publicKey:s.ev.getPublicKey(e),secretKey:e};if(!t||!t.skipValidation){const t=(new TextEncoder).encode("sui validation"),r=s.ev.sign(t,e);if(!s.ev.verify(r,t,i.publicKey))throw new Error("provided secretKey is invalid")}return new T(i)}getPublicKey(){return new S(this.keypair.publicKey)}getSecretKey(){return(0,n.yk)(this.keypair.secretKey.slice(0,n.uS),this.getKeyScheme())}async sign(e){return s.ev.sign(e,this.keypair.secretKey)}static deriveKeypair(e,t){if(null==t&&(t=E),!o(t))throw new Error("Invalid derivation path");const{key:r}=l(t,function(e){return(0,i.nj)(function(e){return(0,a.kw)(e,"")}(e))}(e));return T.fromSecretKey(r)}static deriveKeypairFromSeed(e,t){if(null==t&&(t=E),!o(t))throw new Error("Invalid derivation path");const{key:r}=l(t,e);return T.fromSecretKey(r)}}},5762:(e,t,r)=>{r.d(t,{i:()=>n});var s=r(6101);function n(e,t){return s.jy.IntentMessage(s.jy.fixedArray(t.length,s.jy.u8())).serialize({intent:{scope:{[e]:!0},version:{V0:!0},appId:{Sui:!0}},value:t}).toBytes()}},8338:(e,t,r)=>{r.d(t,{RJ:()=>i,Yl:()=>a,lG:()=>o});class s extends Error{}async function n({host:e,path:t,body:r,headers:n,method:i}){const a=new URL(t,e).toString(),o=await fetch(a,{method:i,body:r?JSON.stringify(r):void 0,headers:{"Content-Type":"application/json",...n||{}}});if(429===o.status)throw new s("Too many requests from this client have been sent to the faucet. Please retry later");try{const e=await o.json();if(e.error)throw new Error(`Faucet returns error: ${e.error}`);return e}catch(e){throw new Error(`Encountered error when parsing response from faucet, error: ${e}, status ${o.status}, response ${o}`)}}async function i(e){return n({host:e.host,path:"/gas",body:{FixedAmountRequest:{recipient:e.recipient}},headers:e.headers,method:"POST"})}async function a(e){return n({host:e.host,path:"/v1/gas",body:{FixedAmountRequest:{recipient:e.recipient}},headers:e.headers,method:"POST"})}function o(e){switch(e){case"testnet":return"https://faucet.testnet.sui.io";case"devnet":return"https://faucet.devnet.sui.io";case"localnet":return"http://127.0.0.1:9123";default:throw new Error(`Unknown network: ${e}`)}}},9919:(e,t,r)=>{r.d(t,{x:()=>ae});var s=r(9440),n=r(451),i=r(4329);class a{constructor({network:e}){this.network=e}$extend(...e){return Object.create(this,Object.fromEntries(e.map((e=>{if("experimental_asClientExtension"in e){const{name:t,register:r}=e.experimental_asClientExtension();return[t,{value:r(this)}]}return[e.name,{value:e.register(this)}]}))))}}var o=r(6101),c=r(6647),u=r(5316);class d extends a{constructor(){super(...arguments),this.core=this}}class h extends Error{}class l extends h{constructor(e,t){super(t),this.code=e}static fromResponse(e,t){switch(e.code){case"notExists":return new l(e.code,`Object ${e.object_id} does not exist`);case"dynamicFieldNotFound":return new l(e.code,`Dynamic field not found for object ${e.parent_object_id}`);case"deleted":return new l(e.code,`Object ${e.object_id} has been deleted`);case"displayError":return new l(e.code,`Display error: ${e.error}`);default:return new l(e.code,"Unknown error while loading object"+(t?` ${t}`:""))}}}var p,w=e=>{throw TypeError(e)},y=(e,t,r)=>t.has(e)||w("Cannot "+r),g=(e,t,r)=>(y(e,t,"read from private field"),r?r.call(e):t.get(e));class m extends d{constructor(e){var t,r;super({network:e.network}),t=this,(r=p).has(t)?w("Cannot add the same private member more than once"):r instanceof WeakSet?r.add(t):r.set(t,undefined),((e,t,r)=>{y(e,t,"write to private field"),t.set(e,r)})(this,p,e)}async getObjects(e){const t=(0,c.vA)(e.objectIds,50),r=[];for(const e of t){const t=await g(this,p).multiGetObjects({ids:e,options:{showOwner:!0,showType:!0}});for(const[s,n]of t.entries())n.error?r.push(l.fromResponse(n.error,e[s])):r.push(f(n.data))}return{objects:r}}async getOwnedObjects(e){const t=await g(this,p).getOwnedObjects({owner:e.address,limit:e.limit,cursor:e.cursor});return{objects:t.data.map((e=>{if(e.error)throw l.fromResponse(e.error);return f(e.data)})),hasNextPage:t.hasNextPage,cursor:t.nextCursor??null}}async getCoins(e){const t=await g(this,p).getCoins({owner:e.address,coinType:e.coinType});return{objects:t.data.map((t=>({id:t.coinObjectId,version:t.version,digest:t.digest,balance:BigInt(t.balance),type:`0x2::coin::Coin<${t.coinType}>`,content:S.serialize({id:t.coinObjectId,balance:{value:t.balance}}).toBytes(),owner:{$kind:"ObjectOwner",ObjectOwner:e.address}}))),hasNextPage:t.hasNextPage,cursor:t.nextCursor??null}}async getBalance(e){const t=await g(this,p).getBalance({owner:e.address,coinType:e.coinType});return{balance:{coinType:t.coinType,balance:BigInt(t.totalBalance)}}}async getAllBalances(e){return{balances:(await g(this,p).getAllBalances({owner:e.address})).map((e=>({coinType:e.coinType,balance:BigInt(e.totalBalance)}))),hasNextPage:!1,cursor:null}}async getTransaction(e){return{transaction:k(await g(this,p).getTransactionBlock({digest:e.digest,options:{showRawInput:!0,showObjectChanges:!0,showRawEffects:!0,showEvents:!0}}))}}async executeTransaction(e){return{transaction:k(await g(this,p).executeTransactionBlock({transactionBlock:e.transaction,signature:e.signatures,options:{showEffects:!0,showEvents:!0}}))}}async dryRunTransaction(e){const t=u.Z.from(e.transaction),r=await g(this,p).dryRunTransactionBlock({transactionBlock:e.transaction});return{transaction:{digest:await t.getDigest(),effects:r.effects,signatures:[],bcs:e.transaction}}}async getReferenceGasPrice(){return{referenceGasPrice:await g(this,p).getReferenceGasPrice()}}}function f(e){return{id:e.objectId,version:e.version,digest:e.digest,type:e.type,content:"moveObject"===e.bcs?.dataType?(0,s.Ey)(e.bcs.bcsBytes):new Uint8Array,owner:b(e.owner)}}function b(e){if("Immutable"===e)return{$kind:"Immutable",Immutable:!0};if("ConsensusV2"in e)return{$kind:"ConsensusV2",ConsensusV2Owner:{authenticator:{$kind:"SingleOwner",SingleOwner:e.ConsensusV2.authenticator.SingleOwner},startVersion:e.ConsensusV2.start_version}};if("AddressOwner"in e)return{$kind:"AddressOwner",AddressOwner:e.AddressOwner};if("ObjectOwner"in e)return{$kind:"ObjectOwner",ObjectOwner:e.ObjectOwner};if("Shared"in e)return{$kind:"Shared",Shared:{initialSharedVersion:e.Shared.initial_shared_version}};throw new Error(`Unknown owner type: ${JSON.stringify(e)}`)}function k(e){const t=o.jy.SenderSignedData.parse((0,s.Ey)(e.rawTransaction))[0];return{digest:e.digest,effects:new Uint8Array(e.rawEffects),bcs:o.jy.TransactionData.serialize(t.intentMessage.value).toBytes(),signatures:t.txSignatures}}p=new WeakMap;const v=o.jy.struct("Balance",{value:o.jy.u64()}),S=o.jy.struct("Coin",{id:o.jy.Address,balance:v});var E=r(9298),T=r(801),x=r(99);const B={"-32700":"ParseError","-32701":"OversizedRequest","-32702":"OversizedResponse","-32600":"InvalidRequest","-32601":"MethodNotFound","-32602":"InvalidParams","-32603":"InternalError","-32604":"ServerBusy","-32000":"CallExecutionFailed","-32001":"UnknownError","-32003":"SubscriptionClosed","-32004":"SubscriptionClosedWithError","-32005":"BatchesNotSupported","-32006":"TooManySubscriptions","-32050":"TransientError","-32002":"TransactionExecutionClientError"};class q extends Error{}class I extends q{constructor(e,t){super(e),this.code=t,this.type=B[t]??"ServerError"}}class C extends q{constructor(e,t,r){super(e),this.status=t,this.statusText=r}}var j,A,O,_,M,P,K,R,N,W=e=>{throw TypeError(e)},$=(e,t,r)=>t.has(e)||W("Cannot "+r),D=(e,t,r)=>($(e,t,"read from private field"),r?r.call(e):t.get(e)),U=(e,t,r)=>t.has(e)?W("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,r),z=(e,t,r,s)=>($(e,t,"write to private field"),s?s.call(e,r):t.set(e,r),r),F=(e,t,r)=>($(e,t,"access private method"),r);const L={WebSocketConstructor:"undefined"!=typeof WebSocket?WebSocket:void 0,callTimeout:3e4,reconnectTimeout:3e3,maxReconnects:5};class V{constructor(e,t={}){if(U(this,K),U(this,j,0),U(this,A,0),U(this,O,null),U(this,_,null),U(this,M,new Set),U(this,P,new Map),this.endpoint=e,this.options={...L,...t},!this.options.WebSocketConstructor)throw new Error("Missing WebSocket constructor");this.endpoint.startsWith("http")&&(this.endpoint=function(e){const t=new URL(e);return t.protocol=t.protocol.replace("http","ws"),t.toString()}(this.endpoint))}async makeRequest(e,t){const r=await F(this,K,R).call(this);return new Promise(((s,n)=>{z(this,j,D(this,j)+1),D(this,P).set(D(this,j),{resolve:s,reject:n,timeout:setTimeout((()=>{D(this,P).delete(D(this,j)),n(new Error(`Request timeout: ${e}`))}),this.options.callTimeout)}),r.send(JSON.stringify({jsonrpc:"2.0",id:D(this,j),method:e,params:t}))})).then((({error:e,result:t})=>{if(e)throw new I(e.message,e.code);return t}))}async subscribe(e){const t=new G(e);return D(this,M).add(t),await t.subscribe(this),()=>t.unsubscribe(this)}}j=new WeakMap,A=new WeakMap,O=new WeakMap,_=new WeakMap,M=new WeakMap,P=new WeakMap,K=new WeakSet,R=function(){return D(this,_)||z(this,_,new Promise((e=>{D(this,O)?.close(),z(this,O,new this.options.WebSocketConstructor(this.endpoint)),D(this,O).addEventListener("open",(()=>{z(this,A,0),e(D(this,O))})),D(this,O).addEventListener("close",(()=>{var e,t;(e=this,t=A,{set _(r){z(e,t,r,undefined)},get _(){return D(e,t,undefined)}})._++,D(this,A)<=this.options.maxReconnects&&setTimeout((()=>{F(this,K,N).call(this)}),this.options.reconnectTimeout)})),D(this,O).addEventListener("message",(({data:e})=>{let t;try{t=JSON.parse(e)}catch(t){return void console.error(new Error(`Failed to parse RPC message: ${e}`,{cause:t}))}if("id"in t&&null!=t.id&&D(this,P).has(t.id)){const{resolve:e,timeout:r}=D(this,P).get(t.id);clearTimeout(r),e(t)}else if("params"in t){const{params:e}=t;D(this,M).forEach((t=>{t.subscriptionId===e.subscription&&e.subscription===t.subscriptionId&&t.onMessage(e.result)}))}}))}))),D(this,_)},N=async function(){return D(this,O)?.close(),z(this,_,null),Promise.allSettled([...D(this,M)].map((e=>e.subscribe(this))))};class G{constructor(e){this.subscriptionId=null,this.subscribed=!1,this.input=e}onMessage(e){this.subscribed&&this.input.onMessage(e)}async unsubscribe(e){const{subscriptionId:t}=this;return this.subscribed=!1,null!=t&&(this.subscriptionId=null,e.makeRequest(this.input.unsubscribe,[t]))}async subscribe(e){this.subscriptionId=null,this.subscribed=!0;const t=await e.makeRequest(this.input.method,this.input.params);this.subscribed&&(this.subscriptionId=t)}}var J,Z,H,X,Y,Q=e=>{throw TypeError(e)},ee=(e,t,r)=>t.has(e)||Q("Cannot "+r),te=(e,t,r)=>(ee(e,t,"read from private field"),r?r.call(e):t.get(e)),re=(e,t,r)=>t.has(e)?Q("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(e):t.set(e,r),se=(e,t,r,s)=>(ee(e,t,"write to private field"),s?s.call(e,r):t.set(e,r),r);class ne{constructor(e){re(this,X),re(this,J,0),re(this,Z),re(this,H),se(this,Z,e)}fetch(e,t){const r=te(this,Z).fetch??fetch;if(!r)throw new Error("The current environment does not support fetch, you can provide a fetch implementation in the options for SuiHTTPTransport.");return r(e,t)}async request(e){se(this,J,te(this,J)+1);const t=await this.fetch(te(this,Z).rpc?.url??te(this,Z).url,{method:"POST",headers:{"Content-Type":"application/json","Client-Sdk-Type":"typescript","Client-Sdk-Version":x.i,"Client-Target-Api-Version":x.c,"Client-Request-Method":e.method,...te(this,Z).rpc?.headers},body:JSON.stringify({jsonrpc:"2.0",id:te(this,J),method:e.method,params:e.params})});if(!t.ok)throw new C(`Unexpected status code: ${t.status}`,t.status,t.statusText);const r=await t.json();if("error"in r&&null!=r.error)throw new I(r.error.message,r.error.code);return r.result}async subscribe(e){const t=await(r=X,s=Y,ee(this,r,"access private method"),s).call(this).subscribe(e);var r,s;return async()=>!!await t()}}J=new WeakMap,Z=new WeakMap,H=new WeakMap,X=new WeakSet,Y=function(){if(!te(this,H)){const e=te(this,Z).WebSocketConstructor??WebSocket;if(!e)throw new Error("The current environment does not support WebSocket, you can provide a WebSocketConstructor in the options for SuiHTTPTransport.");se(this,H,new V(te(this,Z).websocket?.url??te(this,Z).url,{WebSocketConstructor:e,...te(this,Z).websocket}))}return te(this,H)};const ie=Symbol.for("@mysten/SuiClient");class ae extends a{constructor(e){super({network:e.network??"unknown"}),this.core=new m(this),this.transport=e.transport??new ne({url:e.url})}get[ie](){return!0}async getRpcApiVersion(){return(await this.transport.request({method:"rpc.discover",params:[]})).info.version}async getCoins(e){if(!e.owner||!(0,E.AP)((0,E.t4)(e.owner)))throw new Error("Invalid Sui address");return await this.transport.request({method:"suix_getCoins",params:[e.owner,e.coinType,e.cursor,e.limit]})}async getAllCoins(e){if(!e.owner||!(0,E.AP)((0,E.t4)(e.owner)))throw new Error("Invalid Sui address");return await this.transport.request({method:"suix_getAllCoins",params:[e.owner,e.cursor,e.limit]})}async getBalance(e){if(!e.owner||!(0,E.AP)((0,E.t4)(e.owner)))throw new Error("Invalid Sui address");return await this.transport.request({method:"suix_getBalance",params:[e.owner,e.coinType]})}async getAllBalances(e){if(!e.owner||!(0,E.AP)((0,E.t4)(e.owner)))throw new Error("Invalid Sui address");return await this.transport.request({method:"suix_getAllBalances",params:[e.owner]})}async getCoinMetadata(e){return await this.transport.request({method:"suix_getCoinMetadata",params:[e.coinType]})}async getTotalSupply(e){return await this.transport.request({method:"suix_getTotalSupply",params:[e.coinType]})}async call(e,t){return await this.transport.request({method:e,params:t})}async getMoveFunctionArgTypes(e){return await this.transport.request({method:"sui_getMoveFunctionArgTypes",params:[e.package,e.module,e.function]})}async getNormalizedMoveModulesByPackage(e){return await this.transport.request({method:"sui_getNormalizedMoveModulesByPackage",params:[e.package]})}async getNormalizedMoveModule(e){return await this.transport.request({method:"sui_getNormalizedMoveModule",params:[e.package,e.module]})}async getNormalizedMoveFunction(e){return await this.transport.request({method:"sui_getNormalizedMoveFunction",params:[e.package,e.module,e.function]})}async getNormalizedMoveStruct(e){return await this.transport.request({method:"sui_getNormalizedMoveStruct",params:[e.package,e.module,e.struct]})}async getOwnedObjects(e){if(!e.owner||!(0,E.AP)((0,E.t4)(e.owner)))throw new Error("Invalid Sui address");return await this.transport.request({method:"suix_getOwnedObjects",params:[e.owner,{filter:e.filter,options:e.options},e.cursor,e.limit]})}async getObject(e){if(!e.id||!(0,E.qD)((0,E.fN)(e.id)))throw new Error("Invalid Sui Object id");return await this.transport.request({method:"sui_getObject",params:[e.id,e.options]})}async tryGetPastObject(e){return await this.transport.request({method:"sui_tryGetPastObject",params:[e.id,e.version,e.options]})}async multiGetObjects(e){if(e.ids.forEach((e=>{if(!e||!(0,E.qD)((0,E.fN)(e)))throw new Error(`Invalid Sui Object id ${e}`)})),e.ids.length!==new Set(e.ids).size)throw new Error(`Duplicate object ids in batch call ${e.ids}`);return await this.transport.request({method:"sui_multiGetObjects",params:[e.ids,e.options]})}async queryTransactionBlocks(e){return await this.transport.request({method:"suix_queryTransactionBlocks",params:[{filter:e.filter,options:e.options},e.cursor,e.limit,"descending"===(e.order||"descending")]})}async getTransactionBlock(e){if(!(0,E.n4)(e.digest))throw new Error("Invalid Transaction digest");return await this.transport.request({method:"sui_getTransactionBlock",params:[e.digest,e.options]})}async multiGetTransactionBlocks(e){if(e.digests.forEach((e=>{if(!(0,E.n4)(e))throw new Error(`Invalid Transaction digest ${e}`)})),e.digests.length!==new Set(e.digests).size)throw new Error(`Duplicate digests in batch call ${e.digests}`);return await this.transport.request({method:"sui_multiGetTransactionBlocks",params:[e.digests,e.options]})}async executeTransactionBlock({transactionBlock:e,signature:t,options:r,requestType:n}){const i=await this.transport.request({method:"sui_executeTransactionBlock",params:["string"==typeof e?e:(0,s.nk)(e),Array.isArray(t)?t:[t],r]});if("WaitForLocalExecution"===n)try{await this.waitForTransaction({digest:i.digest})}catch(e){}return i}async signAndExecuteTransaction({transaction:e,signer:t,...r}){let s;e instanceof Uint8Array?s=e:(e.setSenderIfNotSet(t.toSuiAddress()),s=await e.build({client:this}));const{signature:n,bytes:i}=await t.signTransaction(s);return this.executeTransactionBlock({transactionBlock:i,signature:n,...r})}async getTotalTransactionBlocks(){const e=await this.transport.request({method:"sui_getTotalTransactionBlocks",params:[]});return BigInt(e)}async getReferenceGasPrice(){const e=await this.transport.request({method:"suix_getReferenceGasPrice",params:[]});return BigInt(e)}async getStakes(e){if(!e.owner||!(0,E.AP)((0,E.t4)(e.owner)))throw new Error("Invalid Sui address");return await this.transport.request({method:"suix_getStakes",params:[e.owner]})}async getStakesByIds(e){return e.stakedSuiIds.forEach((e=>{if(!e||!(0,E.qD)((0,E.fN)(e)))throw new Error(`Invalid Sui Stake id ${e}`)})),await this.transport.request({method:"suix_getStakesByIds",params:[e.stakedSuiIds]})}async getLatestSuiSystemState(){return await this.transport.request({method:"suix_getLatestSuiSystemState",params:[]})}async queryEvents(e){return await this.transport.request({method:"suix_queryEvents",params:[e.query,e.cursor,e.limit,"descending"===(e.order||"descending")]})}async subscribeEvent(e){return this.transport.subscribe({method:"suix_subscribeEvent",unsubscribe:"suix_unsubscribeEvent",params:[e.filter],onMessage:e.onMessage})}async subscribeTransaction(e){return this.transport.subscribe({method:"suix_subscribeTransaction",unsubscribe:"suix_unsubscribeTransaction",params:[e.filter],onMessage:e.onMessage})}async devInspectTransactionBlock(e){let t;if((0,u.b)(e.transactionBlock))e.transactionBlock.setSenderIfNotSet(e.sender),t=(0,s.nk)(await e.transactionBlock.build({client:this,onlyTransactionKind:!0}));else if("string"==typeof e.transactionBlock)t=e.transactionBlock;else{if(!(e.transactionBlock instanceof Uint8Array))throw new Error("Unknown transaction block format.");t=(0,s.nk)(e.transactionBlock)}return await this.transport.request({method:"sui_devInspectTransactionBlock",params:[e.sender,t,e.gasPrice?.toString(),e.epoch]})}async dryRunTransactionBlock(e){return await this.transport.request({method:"sui_dryRunTransactionBlock",params:["string"==typeof e.transactionBlock?e.transactionBlock:(0,s.nk)(e.transactionBlock)]})}async getDynamicFields(e){if(!e.parentId||!(0,E.qD)((0,E.fN)(e.parentId)))throw new Error("Invalid Sui Object id");return await this.transport.request({method:"suix_getDynamicFields",params:[e.parentId,e.cursor,e.limit]})}async getDynamicFieldObject(e){return await this.transport.request({method:"suix_getDynamicFieldObject",params:[e.parentId,e.name]})}async getLatestCheckpointSequenceNumber(){const e=await this.transport.request({method:"sui_getLatestCheckpointSequenceNumber",params:[]});return String(e)}async getCheckpoint(e){return await this.transport.request({method:"sui_getCheckpoint",params:[e.id]})}async getCheckpoints(e){return await this.transport.request({method:"sui_getCheckpoints",params:[e.cursor,e?.limit,e.descendingOrder]})}async getCommitteeInfo(e){return await this.transport.request({method:"suix_getCommitteeInfo",params:[e?.epoch]})}async getNetworkMetrics(){return await this.transport.request({method:"suix_getNetworkMetrics",params:[]})}async getAddressMetrics(){return await this.transport.request({method:"suix_getLatestAddressMetrics",params:[]})}async getEpochMetrics(e){return await this.transport.request({method:"suix_getEpochMetrics",params:[e?.cursor,e?.limit,e?.descendingOrder]})}async getAllEpochAddressMetrics(e){return await this.transport.request({method:"suix_getAllEpochAddressMetrics",params:[e?.descendingOrder]})}async getEpochs(e){return await this.transport.request({method:"suix_getEpochs",params:[e?.cursor,e?.limit,e?.descendingOrder]})}async getMoveCallMetrics(){return await this.transport.request({method:"suix_getMoveCallMetrics",params:[]})}async getCurrentEpoch(){return await this.transport.request({method:"suix_getCurrentEpoch",params:[]})}async getValidatorsApy(){return await this.transport.request({method:"suix_getValidatorsApy",params:[]})}async getChainIdentifier(){const e=await this.getCheckpoint({id:"0"}),t=(0,n.n3)(e.digest);return(0,i.nj)(t.slice(0,4))}async resolveNameServiceAddress(e){return await this.transport.request({method:"suix_resolveNameServiceAddress",params:[e.name]})}async resolveNameServiceNames({format:e="dot",...t}){const{nextCursor:r,hasNextPage:s,data:n}=await this.transport.request({method:"suix_resolveNameServiceNames",params:[t.address,t.cursor,t.limit]});return{hasNextPage:s,nextCursor:r,data:n.map((t=>(0,T.n)(t,e)))}}async getProtocolConfig(e){return await this.transport.request({method:"sui_getProtocolConfig",params:[e?.version]})}async waitForTransaction({signal:e,timeout:t=6e4,pollInterval:r=2e3,...s}){const n=AbortSignal.timeout(t),i=new Promise(((e,t)=>{n.addEventListener("abort",(()=>t(n.reason)))}));for(i.catch((()=>{}));!n.aborted;){e?.throwIfAborted();try{return await this.getTransactionBlock(s)}catch(e){await Promise.race([new Promise((e=>setTimeout(e,r))),i])}}throw n.throwIfAborted(),new Error("Unexpected error while waiting for transaction block.")}experimental_asClientExtension(){return{name:"jsonRPC",register:()=>this}}}}}]);