1import { B as Buffer } from './polyfill-buffer-BWpSmsqZ.js'; 2import { h } from './chunk-xdkdc1f0-CEkXNZAQ.js'; 3import './chunk-exyqap7m-BotEe9A8.js'; 4import { p as p$1, a as b, bc as Y, bN as j$1, D, ck as M$1, cl as z } from './wallet-keystore-BVM_ybiA.js'; 5 6function R(e){return e.length>=2&&e.length<=64&&/^(([a-z\d]+[-_])*[a-z\d]+\.)*([a-z\d]+[-_])*[a-z\d]+$/.test(e)}async function M(e){if(e.derivationPath&&(e.derivationPath[3]||e.derivationPath[4]))throw new b("toolbox_derivation_slot_unsupported",{chain:p$1.Near,derivationPath:e.derivationPath});let{KeyPair:s}=await import('./index-C9tg5R4m.js'),c=e.derivationPath?Y(e.derivationPath.slice(0,3)):`m/44'/397'/${e.index??0}'`,{parseSeedPhrase:g}=await import('./index-DvWjuoVt.js').then(n => n.i),{secretKey:_}=g(e.phrase,c),y=s.fromString(_);return at(y)}async function et(e){let{KeyPair:s}=await import('./index-C9tg5R4m.js'),c=s.fromString(e);return at(c)}async function at(e){let{KeyPairSigner:s}=await import('./index-BPNPcSH5.js');class c extends s{#t;constructor(g){super(g);this.#t=g;}getAddress(){let g=this.#t.getPublicKey(),_=Buffer.from(g.data).toString("hex");return Promise.resolve(_)}}return new c(e)}async function j(e,s){let g=(await e.query({account_id:s,finality:"final",request_type:"view_access_key_list"})).keys.find((K)=>K.access_key.permission==="FullAccess");if(!g)throw new b("toolbox_near_no_public_key_found");let{PublicKey:_}=await import('./index-C9tg5R4m.js'),y=_.fromString(g.public_key);return {nonce:g.access_key.nonce||0,publicKey:y}}var p={ACCESS_KEY_ADDITION:"5",ACCESS_KEY_DELETION:"5",ACCOUNT_CREATION:"30",CONTRACT_CALL:"150",CONTRACT_DEPLOYMENT:"200",SIMPLE_TRANSFER:"1",STAKE:"10",STORAGE_DEPOSIT:"150",TOKEN_TRANSFER:"150"};function ot(e){return "recipient"in e&&"amount"in e&&!("contractId"in e)}function it(e){return "contractId"in e&&"methodName"in e}function st(e){return "actions"in e}function ct(e){return "newAccountId"in e}function gt(e){return "contractCode"in e}function mt(e){return "customEstimator"in e}function ut(e){let s=0;for(let c of e)switch(c.enum){case "transfer":s+=Number(p.SIMPLE_TRANSFER);break;case "functionCall":s+=Number(p.CONTRACT_CALL);break;case "createAccount":s+=Number(p.ACCOUNT_CREATION);break;case "deployContract":s+=Number(p.CONTRACT_DEPLOYMENT);break;case "addKey":s+=Number(p.ACCESS_KEY_ADDITION);break;case "deleteKey":s+=Number(p.ACCESS_KEY_DELETION);break;case "stake":s+=Number(p.STAKE);break;default:s+=Number(p.CONTRACT_CALL);}return s.toString()}function dt(e){if(e==="ft_transfer"||e==="ft_transfer_call")return p.TOKEN_TRANSFER;if(e==="storage_deposit")return p.STORAGE_DEPOSIT;return p.CONTRACT_CALL}async function lt({account:e,contractId:s,viewMethods:c,changeMethods:g}){let{Contract:_}=await import('./index-9v-yOB7b.js');return new _(e,s,{changeMethods:g,useLocalViewExecution:true,viewMethods:c})}var Pt=1250000000000000000000n,yt=150000000000000n,Gt=150000000000000n,Ft=250000000000000n,Dt=250000000000000n,Ot=500n,U=10000n;function Qt(e){let s;async function c(){if(s)return s;return s=await M$1(e).with({phrase:z.string},async(t)=>await M(t)).with({signer:z.any},({signer:t})=>t).otherwise(()=>{return}),s}async function g(){let{JsonRpcProvider:t}=await import('./index-QdnmQ6ah.js'),n=await j$1(p$1.Near);return new t({url:n})}async function _(t){let{Account:n}=await import('./index-9v-yOB7b.js'),r=await g(),a=await c(),o=await y();return new n(o,r,a)}async function y(){let t=await c();if(!t)throw new b("toolbox_near_no_signer");return await t.getAddress()}async function V(t,n){return (n||await g()).callFunction(t.contractId,"storage_balance_of",{account_id:t.accountId},{finality:"final"})}async function K(t,n){try{let r=await n.callFunction(t,"storage_balance_bounds",{},{finality:"final"});return r?.min?BigInt(r.min):Pt}catch{return Pt}}function k(t){return (t*(U+Ot)+U-1n)/U}function J(t,n){return BigInt(t)*BigInt(n.runtime_config.storage_amount_per_byte)}function z$1(t,n){if(t<=0n)throw new b({errorKey:"toolbox_sweep_amount_too_low",info:n});return t}async function G(t){return await(t||await g()).experimental_protocolConfig({finality:"final"})}async function Tt(t,n,r){let o=await(r||await g()).callFunction(t,"ft_balance_of",{account_id:n},{finality:"final"});return BigInt(o||"0")}async function ht(t){if(!await c())throw new b("toolbox_near_no_signer");let{assetValue:r,recipient:a,memo:o,sweep:i}=t,m=await y(),d=await Y({assetValue:r,memo:o,recipient:a,sender:m,sweep:i});return X(d)}async function St({assetValue:t,attachedDeposit:n,memo:r,provider:a,recipient:o,sender:i,sweep:m}){let d=t.address;if(!d)throw new b("toolbox_near_missing_contract_address");let f=await V({accountId:o,contractId:d},a),P=f?0n:await K(d,a),w=f?Ft:Gt,T=BigInt(n||"1"),N=t.getBaseValue("bigint");if(m){let[S,A,b$1,I]=await Promise.all([Tt(d,i,a),a.viewAccount(i,{finality:"final"}),G(a),O(a)]);N=z$1(S,{asset:t.toString(),balance:S.toString()});let E=J(A.storage_usage,b$1),C=A.amount-E,B=P,nt=(w+(f?0n:yt))*k(I)+B+T;if(C<nt)throw new b("toolbox_sweep_amount_too_low",{asset:t.toString(),availableNear:C.toString(),reason:"Insufficient NEAR to cover token transfer gas and storage deposit",requiredNear:nt.toString()})}let h=[];if(!f)h.push(await v({args:{account_id:o},attachedDeposit:P.toString(),gas:yt.toString(),methodName:"storage_deposit"}));return h.push(await v({args:{amount:N.toString(),memo:r||null,receiver_id:o},attachedDeposit:T.toString(),gas:w.toString(),methodName:"ft_transfer"})),W({actions:h,receiverId:d,sender:i})}async function Nt({assetValue:t,attachedDeposit:n,memo:r,provider:a,recipient:o,sender:i,sweep:m}){let d=t.getBaseValue("bigint");if(m){let[b,I]=await Promise.all([a.viewAccount(i,{finality:"final"}),G(a)]),E=await Z({assetValue:t,memo:r,recipient:o,sweep:m},I),C=J(b.storage_usage,I),B=0n;
6if(r&&n){let tt=await O(a);B=Dt*k(tt)+BigInt(n);}d=z$1(b.amount-E.getBaseValue("bigint")-C-B,{asset:t.toString(),balance:b.amount.toString(),fee:E.getBaseValue("bigint").toString(),storageStakeReserve:C.toString()});}let[{publicKey:f,nonce:P},w,{actionCreators:T,createTransaction:N},{baseDecode:h}]=await Promise.all([j(a,i),a.block({finality:"final"}),import('./index-CE00CTQA.js'),import('./index-lzA1skZ1.js').then(n => n.l)]),S=[T.transfer(d)];if(r&&n)S.push(T.functionCall("memo",{memo:r},BigInt("250000000000000"),BigInt(n)));let A=h(w.header.hash);return N(i,f,o,P+1,S,A)}async function Y({recipient:t,assetValue:n,memo:r,attachedDeposit:a,sender:o,functionCall:i,sweep:m}){if(!R(t))throw new b("toolbox_near_invalid_address",{recipient:t});if(!R(o))throw new b("toolbox_near_invalid_address",{sender:o});if(i)return H({...i,sender:o});if(m&&!await c())throw new b("toolbox_near_no_signer");let d=await g(),f={assetValue:n,attachedDeposit:a,memo:r,provider:d,recipient:t,sender:o,sweep:m};return n.isGasAsset?Nt(f):St(f)}function At(t){let n=t.encode();return Buffer.from(n).toString("base64")}async function H({args:t,attachedDeposit:n,contractId:r,gas:a,methodName:o,sender:i}){let m=await v({args:t,attachedDeposit:n,gas:a,methodName:o});return W({actions:[m],receiverId:r,sender:i})}async function W({actions:t,receiverId:n,sender:r}){let a=await g(),[{publicKey:o,nonce:i},m,{createTransaction:d},{baseDecode:f}]=await Promise.all([j(a,r),a.block({finality:"final"}),import('./index-CE00CTQA.js'),import('./index-lzA1skZ1.js').then(n => n.l)]),P=f(m.header.hash);return d(r,o,n,i+1,t,P)}async function v(t){let{actionCreators:n}=await import('./index-CE00CTQA.js');return n.functionCall(t.methodName,Buffer.from(JSON.stringify(t.args)),BigInt(t.gas),BigInt(t.attachedDeposit))}async function q(t){let n=await c();if(!n)throw new b("toolbox_near_no_signer");await bt(t);let[r,a]=await n.signTransaction(t);return a}async function bt(t){let n=t.publicKey;if(n.toString?.().startsWith("ed25519:")||n.toString?.().startsWith("secp256k1:"))return;let{KeyType:r,PublicKey:a}=await import('./index-C9tg5R4m.js'),o=n.data||n.ed25519Key?.data,i=n.secp256k1Key?.data;if(o){t.publicKey=new a({data:Uint8Array.from(o),keyType:r.ED25519});return}if(i)t.publicKey=new a({data:Uint8Array.from(i),keyType:r.SECP256K1});}function F(t){if(typeof t==="string")return t;if(Array.isArray(t))return t.map(F).find(Boolean);if(!(t&&typeof t==="object"))return;let n=t;return n.transaction?.hash||n.transaction_outcome?.id}function D$1(t){return t instanceof Error?t.message:String(t)}async function Q(t){let r=await(await g()).sendTransaction(t),a=F(r);if(!a)throw new b("toolbox_near_transfer_failed",{result:r});return a}async function X(t){let n=await c();if(!n)throw new b("toolbox_near_no_signer");let r;try{r=await q(t);}catch(a){let o;try{o=n.signAndSendTransaction?await n.signAndSendTransaction({actions:t.actions,receiverId:t.receiverId,signerId:t.signerId}):await n.signAndSendTransactions?.({transactions:[t]});}catch(m){throw new b({errorKey:"toolbox_near_sign_transaction_failed",info:{directSignError:D$1(a),signAndSendError:D$1(m)}},m)}let i=F(o);if(i)return i;throw a}return Q(r)}async function Z(t,n){let r=await c();if("assetValue"in t){if(t.sweep&&!r)throw new b("toolbox_near_no_signer");try{let[o,i]=await Promise.all([O(),n?Promise.resolve(n):G()]),{runtime_config:m}=i,{execution:d,send_sir:f}=m.transaction_costs.action_receipt_creation_config,{execution:P,send_sir:w}=m.transaction_costs.action_creation_config.transfer_cost,T=BigInt(w)+BigInt(P),N=BigInt(f)+BigInt(d),h=T+N,S=t.sweep?k(o):o,A=h*S;return D.from({chain:p$1.Near,value:A})}catch(o){throw new b({errorKey:"toolbox_fee_estimation_failed",info:{chain:p$1.Near,message:D$1(o)}},o)}}let a=r?await _():void 0;return L(t,a)}async function O(t){let r=await(t||await g()).gasPrice(null);return BigInt(r.gas_price)}async function Ct(t,n,r){if(!await c())throw new b("toolbox_near_no_signer");let o=await _(),{formatNearAmount:i}=await import('./index-lzA1skZ1.js').then(n => n.l),{PublicKey:m}=await import('./index-C9tg5R4m.js'),d=i(r)||"0";return (await o.createAccount(t,m.fromString(n),BigInt(d))).transaction.hash}async function xt(t){let n=await c();try{if(!n)throw new b("toolbox_near_no_signer");let{actionCreators:r}=await import('./index-CE00CTQA.js'),{contractId:a,methodName:o,args:i,deposit:m}=t,d=await _(),f=await L({args:i||{},contractId:a,methodName:o}),P=r.functionCall(o,i||{},f.getBaseValue("bigint"),BigInt(m||"1"));return (await d.signAndSendTransaction({actions:[P],receiverId:a})).transaction_outcome.id}catch(r){throw new b("toolbox_near_transfer_failed",{error:r})}}async function vt(t){let n=await _();return lt({account:n,changeMethods:t.changeMethods,contractId:t.contractId,viewMethods:t.viewMethods})}async function It(t){if(!await c())throw new b("toolbox_near_no_signer");if(t.actions.length===0)throw new b("toolbox_near_empty_batch");return (await(await _()).signAndSendTransaction({actions:t.actions,receiverId:t.receiverId})).transaction.hash}async function L(t,n){let r=await M$1(t).when(ot,()=>p.SIMPLE_TRANSFER).when(it,(o)=>dt(o.methodName)).when(st,(o)=>ut(o.actions)).when(ct,()=>p.ACCOUNT_CREATION).when(gt,()=>p.CONTRACT_DEPLOYMENT).when(mt,(o)=>{if(!n)throw new b("toolbox_near_no_account");return o.customEstimator(n)}).otherwise(()=>{throw new b("toolbox_near_invalid_gas_params")}),a=BigInt(r)*BigInt(1000000000000);return D.from({chain:p$1.Near,value:a})}async function Et(){let t=await g();try{return (await t.gasPrice(null)).gas_price||"100000000"}catch{return "100000000"}}async function Bt(){let t=await c();return t?(await t.getPublicKey()).toString():""}return {broadcastTransaction:Q,callFunction:xt,createAction:v,createContract:vt,createContractFunctionCall:H,createSubAccount:Ct,createTransaction:Y,estimateGasLimit:L,estimateTransactionFee:Z,executeBatchTransaction:It,getAddress:y,getBalance:h(p$1.Near),getGasPrice:Et,getNearProvider:g,getPublicKey:Bt,getSignerFromPhrase:M,getSignerFromPrivateKey:et,serializeTransaction:At,signAndBroadcastTransaction:X,signTransaction:q,transfer:ht,validateAddress:R}} 7 8export { p as GAS_COSTS, lt as createNearContract, ut as estimateBatchGas, dt as getContractMethodGas, j as getFullAccessPublicKey, M as getNearSignerFromPhrase, et as getNearSignerFromPrivateKey, Qt as getNearToolbox, ct as isAccountCreation, st as isBatchTransaction, it as isContractCall, gt as isContractDeployment, mt as isCustomEstimator, ot as isSimpleTransfer, R as validateNearAddress };
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.