@aptos-labs/ts-sdk
Version:
Aptos TypeScript SDK
2 lines • 6.28 kB
JavaScript
import{a as D,c as tn,d as en,e as R}from"./chunk-LKVJZTBM.mjs";import{q as nn,t as y}from"./chunk-JHBMHOSV.mjs";import{b as Y}from"./chunk-R5NNAF5B.mjs";import{a as Q}from"./chunk-MEXWNZY6.mjs";import{a as J}from"./chunk-AH44UPM4.mjs";import{a as j}from"./chunk-OIH4KBXW.mjs";import{a as Z}from"./chunk-ROXFCLDT.mjs";import{e as F}from"./chunk-HYCGMFC2.mjs";import{a as L}from"./chunk-4D42AAH3.mjs";import{a as A}from"./chunk-EUUIYMYC.mjs";import{a as z}from"./chunk-A7J2UMLS.mjs";import{a as K,c as H,d as X}from"./chunk-LX53BIRN.mjs";import{c as _,d as k,e as O,f as S,g as V,h as q,i as v}from"./chunk-5SQAHWDI.mjs";import{b,d as x,e as B,f as E}from"./chunk-V3DEJBS6.mjs";import{a as C}from"./chunk-P2CIREOD.mjs";import{b as U,c as G}from"./chunk-CYNQRMO5.mjs";import{a as W,b as p,d as g}from"./chunk-LGOZUIGE.mjs";import{a as N,b as P}from"./chunk-43YYG5VO.mjs";import{a as w,c as I}from"./chunk-CX4BEIQT.mjs";import{a as $,c as M}from"./chunk-JWTZDA6A.mjs";import{b as u}from"./chunk-UEI62FBQ.mjs";import{b as h}from"./chunk-BCUSI3N6.mjs";import{sha3_256 as un}from"@noble/hashes/sha3";async function kn(n){if(nn(n))return An(n);let{moduleAddress:t,moduleName:e,functionName:i}=y(n.function),a=await rn({key:"entry-function",moduleAddress:t,moduleName:e,functionName:i,aptosConfig:n.aptosConfig,abi:n.abi,fetch:tn});return dn({...n,abi:a})}function dn(n){let t=n.abi,{moduleAddress:e,moduleName:i,functionName:a}=y(n.function),r=D(n.typeArguments);if(r.length!==t.typeParameters.length)throw new Error(`Type argument count mismatch, expected ${t.typeParameters.length}, received ${r.length}`);let o=n.functionArguments.map((s,d)=>R(n.function,t,s,d,r));if(o.length!==t.parameters.length)throw new Error(`Too few arguments for '${e}::${i}::${a}', expected ${t.parameters.length} but got ${o.length}`);let c=S.build(`${e}::${i}`,a,r,o);if("multisigAddress"in n){let s=u.from(n.multisigAddress);return new O(new q(s,new v(c)))}return new k(c)}async function On(n){let{moduleAddress:t,moduleName:e,functionName:i}=y(n.function),a=await rn({key:"view-function",moduleAddress:t,moduleName:e,functionName:i,aptosConfig:n.aptosConfig,abi:n.abi,fetch:en});return mn({abi:a,...n})}function mn(n){let t=n.abi,{moduleAddress:e,moduleName:i,functionName:a}=y(n.function),r=D(n.typeArguments);if(r.length!==t.typeParameters.length)throw new Error(`Type argument count mismatch, expected ${t.typeParameters.length}, received ${r.length}`);let o=n?.functionArguments?.map((c,s)=>R(n.function,t,c,s,r))??[];if(o.length!==t.parameters.length)throw new Error(`Too few arguments for '${e}::${i}::${a}', expected ${t.parameters.length} but got ${o.length}`);return S.build(`${e}::${i}`,a,r,o)}function An(n){return new _(new V(h.fromHexInput(n.bytecode).toUint8Array(),n.typeArguments??[],n.functionArguments))}async function yn(n){let{aptosConfig:t,sender:e,payload:i,options:a,feePayerAddress:r}=n,o=async()=>F[t.network]?{chainId:F[t.network]}:{chainId:(await j({aptosConfig:t})).chain_id},c=async()=>a?.gasUnitPrice?{gasEstimate:a.gasUnitPrice}:{gasEstimate:(await Y({aptosConfig:t})).gas_estimate},s=async()=>{let f=async()=>a?.accountSequenceNumber!==void 0?a.accountSequenceNumber:(await Q({aptosConfig:t,accountAddress:e})).sequence_number;if(r&&u.from(r).equals(u.ZERO))try{return await f()}catch{return 0}else return f()},[{chainId:d},{gasEstimate:m},T]=await Promise.all([o(),c(),s()]),{maxGasAmount:on,gasUnitPrice:sn,expireTimestamp:cn}={maxGasAmount:a?.maxGasAmount?BigInt(a.maxGasAmount):BigInt(2e5),gasUnitPrice:a?.gasUnitPrice??BigInt(m),expireTimestamp:a?.expireTimestamp??BigInt(Math.floor(Date.now()/1e3)+20)};return new K(u.from(e),BigInt(T),i,BigInt(on),BigInt(sn),BigInt(cn),new C(d))}async function Vn(n){let{aptosConfig:t,sender:e,payload:i,options:a,feePayerAddress:r}=n,o=await yn({aptosConfig:t,sender:e,payload:i,options:a,feePayerAddress:r});if("secondarySignerAddresses"in n){let c=n.secondarySignerAddresses?.map(s=>u.from(s))??[];return new L(o,c,n.feePayerAddress?u.from(n.feePayerAddress):void 0)}return new z(o,n.feePayerAddress?u.from(n.feePayerAddress):void 0)}function qn(n){let{signerPublicKey:t,transaction:e,secondarySignersPublicKeys:i,feePayerPublicKey:a}=n,r=l(t);if(e.feePayerAddress){let c=new X(e.rawTransaction,e.secondarySignerAddresses??[],e.feePayerAddress),s=[];i&&(s=i.map(T=>l(T)));let d=l(a),m=new B(r,e.secondarySignerAddresses??[],s,{address:e.feePayerAddress,authenticator:d});return new A(c.raw_txn,m).bcsToBytes()}if(e.secondarySignerAddresses){let c=new H(e.rawTransaction,e.secondarySignerAddresses),s=[];s=i.map(m=>l(m));let d=new x(r,e.secondarySignerAddresses,s);return new A(c.raw_txn,d).bcsToBytes()}let o;if(r instanceof p)o=new b(r.public_key,r.signature);else if(r instanceof g)o=new E(r);else throw new Error("Invalid public key");return new A(e.rawTransaction,o).bcsToBytes()}function l(n){if(n instanceof N){if(n.publicKey instanceof w)return new g(n,new P(new I(new Uint8Array(64))));if(n.publicKey instanceof $)return new g(n,new P(new M(new Uint8Array(64))))}return new p(new w(n.toUint8Array()),new I(new Uint8Array(64)))}function fn(n){let{transaction:t,feePayerAuthenticator:e,additionalSignersAuthenticators:i}=n,a=Z(W,n.senderAuthenticator),r;if(t.feePayerAddress){if(!e)throw new Error("Must provide a feePayerAuthenticator argument to generate a signed fee payer transaction");r=new B(a,t.secondarySignerAddresses??[],i??[],{address:t.feePayerAddress,authenticator:e})}else if(t.secondarySignerAddresses){if(!i)throw new Error("Must provide a additionalSignersAuthenticators argument to generate a signed multi agent transaction");r=new x(a,t.secondarySignerAddresses,i)}else a instanceof p?r=new b(a.public_key,a.signature):r=new E(a);return new A(t.rawTransaction,r).bcsToBytes()}function an(n){let t=un.create();for(let e of n)t.update(e);return t.digest()}var pn=an(["APTOS::Transaction"]);function vn(n){let t=fn(n);return new h(an([pn,new Uint8Array([0]),t])).toString()}async function rn({key:n,moduleAddress:t,moduleName:e,functionName:i,aptosConfig:a,abi:r,fetch:o}){return r!==void 0?r:J(async()=>o(t,e,i,a),`${n}-${a.network}-${t}-${e}-${i}`,1e3*60*5)()}export{kn as a,dn as b,On as c,mn as d,yn as e,Vn as f,qn as g,l as h,fn as i,an as j,vn as k};
//# sourceMappingURL=chunk-FWPK5KC2.mjs.map