@swapkit/toolboxes 4.14.0 → 4.14.1

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.
@@ -1 +1 @@
1
- var $G=Object.create;var{getPrototypeOf:zG,defineProperty:v,getOwnPropertyNames:m,getOwnPropertyDescriptor:XG}=Object,c=Object.prototype.hasOwnProperty;function d(G){return this[G]}var jG,qG,FG=(G,J,Q)=>{var z=G!=null&&typeof G==="object";if(z){var U=J?jG??=new WeakMap:qG??=new WeakMap,W=U.get(G);if(W)return W}Q=G!=null?$G(zG(G)):{};let Z=J||!G||!G.__esModule?v(Q,"default",{value:G,enumerable:!0}):Q;for(let Y of m(G))if(!c.call(Z,Y))v(Z,Y,{get:d.bind(G,Y),enumerable:!0});if(z)U.set(G,Z);return Z},UG=(G)=>{var J=(l??=new WeakMap).get(G),Q;if(J)return J;if(J=v({},"__esModule",{value:!0}),G&&typeof G==="object"||typeof G==="function"){for(var z of m(G))if(!c.call(J,z))v(J,z,{get:d.bind(G,z),enumerable:!(Q=XG(G,z))||Q.enumerable})}return l.set(G,J),J},l;var WG=(G)=>G;function YG(G,J){this[G]=WG.bind(null,J)}var MG=(G,J)=>{for(var Q in J)v(G,Q,{get:J[Q],enumerable:!0,configurable:!0,set:YG.bind(J,Q)})};var i=(G,J)=>()=>(G&&(J=G(G=0)),J);async function g(G,J){let Q=await fetch(`${e}${G}`,{...J,headers:{project_id:a,...J?.headers}});if(!Q.ok)throw Error(`Blockfrost API error: ${Q.status} ${Q.statusText}`);return Q.json()}async function GG(G){try{return await g(`/addresses/${G}/utxos`)}catch{return[]}}async function RG(){return(await g("/blocks/latest")).slot}async function DG(){let G=await g("/epochs/latest/parameters"),J={PlutusScriptV1:G.cost_models.PlutusV1?Object.values(G.cost_models.PlutusV1):[],PlutusScriptV2:G.cost_models.PlutusV2?Object.values(G.cost_models.PlutusV2):[],PlutusScriptV3:G.cost_models.PlutusV3?Object.values(G.cost_models.PlutusV3):[]};return{collateralPercent:new F.default(G.collateral_percent),languageView:J,lovelacePerUtxoWord:new F.default(0),maxValueSize:Number.parseInt(G.max_val_size,10),minFeeA:new F.default(G.min_fee_a),minFeeB:new F.default(G.min_fee_b),minFeeRefScriptCostPerByte:new F.default(15),priceMem:new F.default(G.price_mem),priceSteps:new F.default(G.price_step),stakeKeyDeposit:new F.default(2000000),utxoCostPerByte:new F.default(G.coins_per_utxo_size)}}async function o(G){let J=await fetch(`${e}/tx/submit`,{body:Buffer.from(G,"hex"),headers:{"Content-Type":"application/cbor",project_id:a},method:"POST"});if(!J.ok){let Q=await J.text();throw Error(`Transaction submission failed: ${Q}`)}return J.json()}function OG(G,J){return G.map((Q)=>{let z=Q.amount.find((Z)=>Z.unit==="lovelace"),U=z?new F.default(z.quantity):new F.default(0),W=Q.amount.filter((Z)=>Z.unit!=="lovelace").map((Z)=>({amount:new F.default(Z.quantity),assetName:Z.unit.slice(56),policyId:Z.unit.slice(0,56)}));return{address:J,amount:U,index:Q.output_index,tokens:W,txId:Q.tx_hash}})}async function fG(G){try{let J=await GG(G),Q=0n,z=new Map;for(let Z of J){if(!Z.amount||!Array.isArray(Z.amount))continue;for(let Y of Z.amount){let{unit:R,quantity:O}=Y;if(R==="lovelace")Q+=BigInt(O);else{let f=z.get(R)||0n;z.set(R,f+BigInt(O))}}}let U=[],{baseDecimal:W}=$.getChainConfig($.Chain.Cardano);if(Q>0n)U.push($.AssetValue.from({chain:$.Chain.Cardano,fromBaseDecimal:W,value:Q.toString()}));for(let[Z,Y]of z)U.push($.AssetValue.from({asset:`${$.Chain.Cardano}.${Z}`,value:Y.toString()}));if(U.length===0)return[$.AssetValue.from({chain:$.Chain.Cardano})];return U}catch(J){let Q=J instanceof Error?J.message:String(J);return console.error(`Cardano balance fetch error: ${Q}`),[$.AssetValue.from({chain:$.Chain.Cardano})]}}function JG(G){if(!G||typeof G!=="string")return!1;try{let J=t.bech32.decode(G,120);return J.prefix==="addr"||J.prefix==="addr_test"}catch{return!1}}async function LG(G,J=0,Q=0){let z=await r.mnemonicToSeed(G,""),W=(await s.Bip32PrivateKey.fromEntropy(Buffer.from(z.slice(0,64)))).derive(x+1852).derive(x+1815).derive(x+J),Z=W.derive(0).derive(Q),Y=Z.toBip32PublicKey().toPublicKey().toBytes(),R=q.crypto.hash28(Y),f=W.derive(2).derive(0).toBip32PublicKey().toPublicKey().toBytes(),K=q.crypto.hash28(f),S={hash:R,type:q.types.HashType.ADDRESS},X={hash:K,type:q.types.HashType.ADDRESS},D=new q.address.BaseAddress(HG,S,X).getBech32(),H=Z.toPrivateKey();return{getAddress:()=>D,publicKey:Y,publicKeyHash:R,signTransaction:async(L)=>{try{let M=await import("@stricahq/cbors"),w=Buffer.from(L,"hex"),B=M.Decoder.decode(w),[V,N,E,A]=B.value,T=M.Encoder.encode(V),P=q.crypto.hash32(T),h=H.sign(P),I=N instanceof Map?N:new Map,y=I.get(n)||[];y.push([Y,h]),I.set(n,y);let C=[V,I,E,A];return M.Encoder.encode(C).toString("hex")}catch(M){throw new $.SwapKitError("toolbox_cardano_sign_transaction_failed",{message:String(M)})}}}}function _G(G){let J,Q,z;async function U(){if(!z)z=await DG();return z}async function W(){if(J!==void 0)return J;if(G&&"phrase"in G&&G.phrase){let X=G.index??0;return J=await LG(G.phrase,0,X),J}if(G&&"signer"in G&&G.signer)return J=G.signer,J;return}async function Z(){if(Q)return Q;let X=await W();if(!X)return"";if("getAddress"in X)return Q=await X.getAddress(),Q;return""}async function Y(X){let j=X||await Z();if(!j)throw new $.SwapKitError("core_wallet_connection_not_found");return fG(j)}async function R(X){if(X)try{let{tx:L}=await O(X),M=L.getFee();return $.AssetValue.from({chain:$.Chain.Cardano,fromBaseDecimal:6,value:M.toString()})}catch{}let j=await U(),D=400,H=j.minFeeB.plus(j.minFeeA.times(D));return $.AssetValue.from({chain:$.Chain.Cardano,fromBaseDecimal:6,value:H.toString()})}async function O({sender:X="",recipient:j,assetValue:D,memo:H,pureLovelaceOnly:L=!1}){let M=X||await Z();if(!M)throw new $.SwapKitError("core_wallet_connection_not_found");let[w,B,V]=await Promise.all([GG(M),RG(),U()]),N=w.filter((_)=>L?_.amount.every((k)=>k.unit==="lovelace"):_.amount.some((k)=>k.unit==="lovelace")).sort((_,k)=>{let p=_.amount.some((b)=>b.unit!=="lovelace"),ZG=k.amount.some((b)=>b.unit!=="lovelace");if(p===ZG)return 0;return p?1:-1}),E=q.utils.getAddressFromString(M),A=q.utils.getAddressFromString(j),T=OG(N,E),P=new F.default(D.getBaseValue("string")),h=[{address:A,amount:P,tokens:[]}],I;if(H){let _=new Map;_.set("msg",[H]),I={metadata:[{data:_,label:674}]}}let C=new q.Transaction({protocolParams:V}).paymentTransaction({auxiliaryData:I,changeAddress:E,inputs:T,outputs:h,ttl:B+3600}),{payload:u}=C.buildTransaction();return{tx:C,unsignedTx:u}}async function f(X){let j=await W();if(!j||!("signTransaction"in j))throw new $.SwapKitError("core_wallet_connection_not_found");return j.signTransaction(X)}async function K({recipient:X,assetValue:j,memo:D}){let H=await W();if(!H||!("signTransaction"in H))throw new $.SwapKitError("core_wallet_connection_not_found");let{unsignedTx:L}=await O({assetValue:j,memo:D,recipient:X,sender:await Z()}),M=await f(L);return await o(M)}async function S(X){let j=await f(X);return await o(j)}return{createTransaction:O,estimateTransactionFee:R,getAddress:Z,getBalance:Y,signAndBroadcastTransaction:S,signTransaction:f,transfer:K,validateAddress:JG}}var t,r,s,q,$,F,a="mainnet3YT7XK6NidLPlkHxxyBB5V0WzXUOTIJS",e="https://cardano-mainnet.blockfrost.io/api/v0",HG,x=2147483648,n=0;var QG=i(()=>{t=require("@scure/base"),r=require("@scure/bip39"),s=require("@stricahq/bip32ed25519"),q=require("@stricahq/typhonjs"),$=require("@swapkit/helpers"),F=FG(require("bignumber.js")),HG=q.types.NetworkId.MAINNET});var kG={};MG(kG,{validateCardanoAddress:()=>JG,getCardanoToolbox:()=>_G});module.exports=UG(kG);var vG=i(()=>{QG()});vG();
1
+ var zG=Object.create;var{getPrototypeOf:XG,defineProperty:w,getOwnPropertyNames:m,getOwnPropertyDescriptor:jG}=Object,c=Object.prototype.hasOwnProperty;function d(G){return this[G]}var qG,UG,WG=(G,J,Q)=>{var z=G!=null&&typeof G==="object";if(z){var W=J?qG??=new WeakMap:UG??=new WeakMap,Y=W.get(G);if(Y)return Y}Q=G!=null?zG(XG(G)):{};let Z=J||!G||!G.__esModule?w(Q,"default",{value:G,enumerable:!0}):Q;for(let M of m(G))if(!c.call(Z,M))w(Z,M,{get:d.bind(G,M),enumerable:!0});if(z)W.set(G,Z);return Z},YG=(G)=>{var J=(l??=new WeakMap).get(G),Q;if(J)return J;if(J=w({},"__esModule",{value:!0}),G&&typeof G==="object"||typeof G==="function"){for(var z of m(G))if(!c.call(J,z))w(J,z,{get:d.bind(G,z),enumerable:!(Q=jG(G,z))||Q.enumerable})}return l.set(G,J),J},l;var MG=(G)=>G;function FG(G,J){this[G]=MG.bind(null,J)}var HG=(G,J)=>{for(var Q in J)w(G,Q,{get:J[Q],enumerable:!0,configurable:!0,set:FG.bind(J,Q)})};var i=(G,J)=>()=>(G&&(J=G(G=0)),J);async function g(G,J){let Q=await fetch(`${e}${G}`,{...J,headers:{project_id:a,...J?.headers}});if(!Q.ok)throw Error(`Blockfrost API error: ${Q.status} ${Q.statusText}`);return Q.json()}async function GG(G){try{return await g(`/addresses/${G}/utxos`)}catch{return[]}}async function DG(){return(await g("/blocks/latest")).slot}async function OG(){let G=await g("/epochs/latest/parameters"),J={PlutusScriptV1:G.cost_models.PlutusV1?Object.values(G.cost_models.PlutusV1):[],PlutusScriptV2:G.cost_models.PlutusV2?Object.values(G.cost_models.PlutusV2):[],PlutusScriptV3:G.cost_models.PlutusV3?Object.values(G.cost_models.PlutusV3):[]};return{collateralPercent:new U.default(G.collateral_percent),languageView:J,lovelacePerUtxoWord:new U.default(0),maxValueSize:Number.parseInt(G.max_val_size,10),minFeeA:new U.default(G.min_fee_a),minFeeB:new U.default(G.min_fee_b),minFeeRefScriptCostPerByte:new U.default(15),priceMem:new U.default(G.price_mem),priceSteps:new U.default(G.price_step),stakeKeyDeposit:new U.default(2000000),utxoCostPerByte:new U.default(G.coins_per_utxo_size)}}async function o(G){let J=await fetch(`${e}/tx/submit`,{body:Buffer.from(G,"hex"),headers:{"Content-Type":"application/cbor",project_id:a},method:"POST"});if(!J.ok){let Q=await J.text();throw Error(`Transaction submission failed: ${Q}`)}return J.json()}function IG(G,J){return G.map((Q)=>{let z=Q.amount.find((Z)=>Z.unit==="lovelace"),W=z?new U.default(z.quantity):new U.default(0),Y=Q.amount.filter((Z)=>Z.unit!=="lovelace").map((Z)=>({amount:new U.default(Z.quantity),assetName:Z.unit.slice(56),policyId:Z.unit.slice(0,56)}));return{address:J,amount:W,index:Q.output_index,tokens:Y,txId:Q.tx_hash}})}async function LG(G){try{let J=await GG(G),Q=0n,z=new Map;for(let Z of J){if(!Z.amount||!Array.isArray(Z.amount))continue;for(let M of Z.amount){let{unit:R,quantity:O}=M;if(R==="lovelace")Q+=BigInt(O);else{let I=z.get(R)||0n;z.set(R,I+BigInt(O))}}}let W=[],{baseDecimal:Y}=$.getChainConfig($.Chain.Cardano);if(Q>0n)W.push($.AssetValue.from({chain:$.Chain.Cardano,fromBaseDecimal:Y,value:Q.toString()}));for(let[Z,M]of z)W.push($.AssetValue.from({asset:`${$.Chain.Cardano}.${Z}`,value:M.toString()}));if(W.length===0)return[$.AssetValue.from({chain:$.Chain.Cardano})];return W}catch(J){let Q=J instanceof Error?J.message:String(J);return console.error(`Cardano balance fetch error: ${Q}`),[$.AssetValue.from({chain:$.Chain.Cardano})]}}function JG(G){if(!G||typeof G!=="string")return!1;try{let J=t.bech32.decode(G,120);return J.prefix==="addr"||J.prefix==="addr_test"}catch{return!1}}async function _G(G,J=0,Q=0){let z=await r.mnemonicToSeed(G,""),Y=(await s.Bip32PrivateKey.fromEntropy(Buffer.from(z.slice(0,64)))).derive(x+1852).derive(x+1815).derive(x+J),Z=Y.derive(0).derive(Q),M=Z.toBip32PublicKey().toPublicKey().toBytes(),R=q.crypto.hash28(M),I=Y.derive(2).derive(0).toBip32PublicKey().toPublicKey().toBytes(),K=q.crypto.hash28(I),S={hash:R,type:q.types.HashType.ADDRESS},X={hash:K,type:q.types.HashType.ADDRESS},D=new q.address.BaseAddress(RG,S,X).getBech32(),H=Z.toPrivateKey();return{getAddress:()=>D,publicKey:M,publicKeyHash:R,signTransaction:async(L)=>{try{let F=await import("@stricahq/cbors"),V=Buffer.from(L,"hex"),B=F.Decoder.decode(V),[f,N,C,T]=B.value,A=F.Encoder.encode(f),P=q.crypto.hash32(A),h=H.sign(P),k=N instanceof Map?N:new Map,E=k.get(n)||[];E.push([M,h]),k.set(n,E);let u=[f,k,C,T];return F.Encoder.encode(u).toString("hex")}catch(F){throw new $.SwapKitError("toolbox_cardano_sign_transaction_failed",{message:String(F)})}}}}function fG(G){let J,Q,z;async function W(){if(!z)z=await OG();return z}async function Y(){if(J!==void 0)return J;if(G&&"phrase"in G&&G.phrase){let X=G.index??0;return J=await _G(G.phrase,0,X),J}if(G&&"signer"in G&&G.signer)return J=G.signer,J;return}async function Z(){if(Q)return Q;let X=await Y();if(!X)return"";if("getAddress"in X)return Q=await X.getAddress(),Q;return""}async function M(X){let j=X||await Z();if(!j)throw new $.SwapKitError("core_wallet_connection_not_found");return LG(j)}async function R(X){if(X)try{let{tx:L}=await O(X),F=L.getFee();return $.AssetValue.from({chain:$.Chain.Cardano,fromBaseDecimal:6,value:F.toString()})}catch{}let j=await W(),D=400,H=j.minFeeB.plus(j.minFeeA.times(D));return $.AssetValue.from({chain:$.Chain.Cardano,fromBaseDecimal:6,value:H.toString()})}async function O({sender:X="",recipient:j,assetValue:D,memo:H,pureLovelaceOnly:L=!1}){let F=X||await Z();if(!F)throw new $.SwapKitError("core_wallet_connection_not_found");let[V,B,f]=await Promise.all([GG(F),DG(),W()]),N=V.filter((_)=>L?_.amount.every((v)=>v.unit==="lovelace"):_.amount.some((v)=>v.unit==="lovelace")).sort((_,v)=>{let p=_.amount.some((b)=>b.unit!=="lovelace"),$G=v.amount.some((b)=>b.unit!=="lovelace");if(p===$G)return 0;return p?1:-1}),C=q.utils.getAddressFromString(F),T=q.utils.getAddressFromString(j),A=IG(N,C),P=new U.default(D.getBaseValue("string")),h=[{address:T,amount:P,tokens:[]}],k;if(H){let _=new Map;_.set("msg",[H]),k={metadata:[{data:_,label:674}]}}let E={...f,minFeeB:f.minFeeB.plus(f.minFeeA.times(4))},y=new q.Transaction({protocolParams:E}).paymentTransaction({auxiliaryData:k,changeAddress:C,inputs:A,outputs:h,ttl:B+3600}),{payload:ZG}=y.buildTransaction();return{tx:y,unsignedTx:ZG}}async function I(X){let j=await Y();if(!j||!("signTransaction"in j))throw new $.SwapKitError("core_wallet_connection_not_found");return j.signTransaction(X)}async function K({recipient:X,assetValue:j,memo:D}){let H=await Y();if(!H||!("signTransaction"in H))throw new $.SwapKitError("core_wallet_connection_not_found");let{unsignedTx:L}=await O({assetValue:j,memo:D,recipient:X,sender:await Z()}),F=await I(L);return await o(F)}async function S(X){let j=await I(X);return await o(j)}return{createTransaction:O,estimateTransactionFee:R,getAddress:Z,getBalance:M,signAndBroadcastTransaction:S,signTransaction:I,transfer:K,validateAddress:JG}}var t,r,s,q,$,U,a="mainnet3YT7XK6NidLPlkHxxyBB5V0WzXUOTIJS",e="https://cardano-mainnet.blockfrost.io/api/v0",RG,x=2147483648,n=0;var QG=i(()=>{t=require("@scure/base"),r=require("@scure/bip39"),s=require("@stricahq/bip32ed25519"),q=require("@stricahq/typhonjs"),$=require("@swapkit/helpers"),U=WG(require("bignumber.js")),RG=q.types.NetworkId.MAINNET});var vG={};HG(vG,{validateCardanoAddress:()=>JG,getCardanoToolbox:()=>fG});module.exports=YG(vG);var wG=i(()=>{QG()});wG();
@@ -1 +1 @@
1
- var GG=Object.defineProperty;var JG=(G)=>G;function QG(G,J){this[G]=JG.bind(null,J)}var ZG=(G,J)=>{for(var Q in J)GG(G,Q,{get:J[Q],enumerable:!0,configurable:!0,set:QG.bind(J,Q)})};var c=(G,J)=>()=>(G&&(J=G(G=0)),J);var $G=((G)=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(G,{get:(J,Q)=>(typeof require<"u"?require:J)[Q]}):G)(function(G){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+G+'" is not supported')});import{bech32 as zG}from"@scure/base";import{mnemonicToSeed as XG}from"@scure/bip39";import{Bip32PrivateKey as jG}from"@stricahq/bip32ed25519";import{Transaction as qG,types as u,address as FG,crypto as x,utils as d}from"@stricahq/typhonjs";import{AssetValue as I,Chain as L,getChainConfig as UG,SwapKitError as v}from"@swapkit/helpers";import j from"bignumber.js";async function p(G,J){let Q=await fetch(`${t}${G}`,{...J,headers:{project_id:o,...J?.headers}});if(!Q.ok)throw Error(`Blockfrost API error: ${Q.status} ${Q.statusText}`);return Q.json()}async function r(G){try{return await p(`/addresses/${G}/utxos`)}catch{return[]}}async function YG(){return(await p("/blocks/latest")).slot}async function MG(){let G=await p("/epochs/latest/parameters"),J={PlutusScriptV1:G.cost_models.PlutusV1?Object.values(G.cost_models.PlutusV1):[],PlutusScriptV2:G.cost_models.PlutusV2?Object.values(G.cost_models.PlutusV2):[],PlutusScriptV3:G.cost_models.PlutusV3?Object.values(G.cost_models.PlutusV3):[]};return{collateralPercent:new j(G.collateral_percent),languageView:J,lovelacePerUtxoWord:new j(0),maxValueSize:Number.parseInt(G.max_val_size,10),minFeeA:new j(G.min_fee_a),minFeeB:new j(G.min_fee_b),minFeeRefScriptCostPerByte:new j(15),priceMem:new j(G.price_mem),priceSteps:new j(G.price_step),stakeKeyDeposit:new j(2000000),utxoCostPerByte:new j(G.coins_per_utxo_size)}}async function n(G){let J=await fetch(`${t}/tx/submit`,{body:Buffer.from(G,"hex"),headers:{"Content-Type":"application/cbor",project_id:o},method:"POST"});if(!J.ok){let Q=await J.text();throw Error(`Transaction submission failed: ${Q}`)}return J.json()}function HG(G,J){return G.map((Q)=>{let q=Q.amount.find((Z)=>Z.unit==="lovelace"),F=q?new j(q.quantity):new j(0),U=Q.amount.filter((Z)=>Z.unit!=="lovelace").map((Z)=>({amount:new j(Z.quantity),assetName:Z.unit.slice(56),policyId:Z.unit.slice(0,56)}));return{address:J,amount:F,index:Q.output_index,tokens:U,txId:Q.tx_hash}})}async function RG(G){try{let J=await r(G),Q=0n,q=new Map;for(let Z of J){if(!Z.amount||!Array.isArray(Z.amount))continue;for(let W of Z.amount){let{unit:M,quantity:R}=W;if(M==="lovelace")Q+=BigInt(R);else{let D=q.get(M)||0n;q.set(M,D+BigInt(R))}}}let F=[],{baseDecimal:U}=UG(L.Cardano);if(Q>0n)F.push(I.from({chain:L.Cardano,fromBaseDecimal:U,value:Q.toString()}));for(let[Z,W]of q)F.push(I.from({asset:`${L.Cardano}.${Z}`,value:W.toString()}));if(F.length===0)return[I.from({chain:L.Cardano})];return F}catch(J){let Q=J instanceof Error?J.message:String(J);return console.error(`Cardano balance fetch error: ${Q}`),[I.from({chain:L.Cardano})]}}function s(G){if(!G||typeof G!=="string")return!1;try{let J=zG.decode(G,120);return J.prefix==="addr"||J.prefix==="addr_test"}catch{return!1}}async function DG(G,J=0,Q=0){let q=await XG(G,""),U=(await jG.fromEntropy(Buffer.from(q.slice(0,64)))).derive(g+1852).derive(g+1815).derive(g+J),Z=U.derive(0).derive(Q),W=Z.toBip32PublicKey().toPublicKey().toBytes(),M=x.hash28(W),D=U.derive(2).derive(0).toBip32PublicKey().toPublicKey().toBytes(),K=x.hash28(D),S={hash:M,type:u.HashType.ADDRESS},$={hash:K,type:u.HashType.ADDRESS},H=new FG.BaseAddress(WG,S,$).getBech32(),Y=Z.toPrivateKey();return{getAddress:()=>H,publicKey:W,publicKeyHash:M,signTransaction:async(O)=>{try{let X=await import("@stricahq/cbors"),w=Buffer.from(O,"hex"),B=X.Decoder.decode(w),[V,N,E,A]=B.value,T=X.Encoder.encode(V),P=x.hash32(T),h=Y.sign(P),_=N instanceof Map?N:new Map,y=_.get(i)||[];y.push([W,h]),_.set(i,y);let C=[V,_,E,A];return X.Encoder.encode(C).toString("hex")}catch(X){throw new v("toolbox_cardano_sign_transaction_failed",{message:String(X)})}}}}function OG(G){let J,Q,q;async function F(){if(!q)q=await MG();return q}async function U(){if(J!==void 0)return J;if(G&&"phrase"in G&&G.phrase){let $=G.index??0;return J=await DG(G.phrase,0,$),J}if(G&&"signer"in G&&G.signer)return J=G.signer,J;return}async function Z(){if(Q)return Q;let $=await U();if(!$)return"";if("getAddress"in $)return Q=await $.getAddress(),Q;return""}async function W($){let z=$||await Z();if(!z)throw new v("core_wallet_connection_not_found");return RG(z)}async function M($){if($)try{let{tx:O}=await R($),X=O.getFee();return I.from({chain:L.Cardano,fromBaseDecimal:6,value:X.toString()})}catch{}let z=await F(),H=400,Y=z.minFeeB.plus(z.minFeeA.times(H));return I.from({chain:L.Cardano,fromBaseDecimal:6,value:Y.toString()})}async function R({sender:$="",recipient:z,assetValue:H,memo:Y,pureLovelaceOnly:O=!1}){let X=$||await Z();if(!X)throw new v("core_wallet_connection_not_found");let[w,B,V]=await Promise.all([r(X),YG(),F()]),N=w.filter((f)=>O?f.amount.every((k)=>k.unit==="lovelace"):f.amount.some((k)=>k.unit==="lovelace")).sort((f,k)=>{let m=f.amount.some((b)=>b.unit!=="lovelace"),e=k.amount.some((b)=>b.unit!=="lovelace");if(m===e)return 0;return m?1:-1}),E=d.getAddressFromString(X),A=d.getAddressFromString(z),T=HG(N,E),P=new j(H.getBaseValue("string")),h=[{address:A,amount:P,tokens:[]}],_;if(Y){let f=new Map;f.set("msg",[Y]),_={metadata:[{data:f,label:674}]}}let C=new qG({protocolParams:V}).paymentTransaction({auxiliaryData:_,changeAddress:E,inputs:T,outputs:h,ttl:B+3600}),{payload:l}=C.buildTransaction();return{tx:C,unsignedTx:l}}async function D($){let z=await U();if(!z||!("signTransaction"in z))throw new v("core_wallet_connection_not_found");return z.signTransaction($)}async function K({recipient:$,assetValue:z,memo:H}){let Y=await U();if(!Y||!("signTransaction"in Y))throw new v("core_wallet_connection_not_found");let{unsignedTx:O}=await R({assetValue:z,memo:H,recipient:$,sender:await Z()}),X=await D(O);return await n(X)}async function S($){let z=await D($);return await n(z)}return{createTransaction:R,estimateTransactionFee:M,getAddress:Z,getBalance:W,signAndBroadcastTransaction:S,signTransaction:D,transfer:K,validateAddress:s}}var o="mainnet3YT7XK6NidLPlkHxxyBB5V0WzXUOTIJS",t="https://cardano-mainnet.blockfrost.io/api/v0",WG,g=2147483648,i=0;var a=c(()=>{WG=u.NetworkId.MAINNET});var LG={};ZG(LG,{validateCardanoAddress:()=>s,getCardanoToolbox:()=>OG});var _G=c(()=>{a()});_G();export{s as validateCardanoAddress,OG as getCardanoToolbox};
1
+ var JG=Object.defineProperty;var QG=(G)=>G;function ZG(G,J){this[G]=QG.bind(null,J)}var $G=(G,J)=>{for(var Q in J)JG(G,Q,{get:J[Q],enumerable:!0,configurable:!0,set:ZG.bind(J,Q)})};var c=(G,J)=>()=>(G&&(J=G(G=0)),J);var zG=((G)=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(G,{get:(J,Q)=>(typeof require<"u"?require:J)[Q]}):G)(function(G){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+G+'" is not supported')});import{bech32 as XG}from"@scure/base";import{mnemonicToSeed as jG}from"@scure/bip39";import{Bip32PrivateKey as qG}from"@stricahq/bip32ed25519";import{Transaction as UG,types as u,address as WG,crypto as x,utils as d}from"@stricahq/typhonjs";import{AssetValue as k,Chain as L,getChainConfig as YG,SwapKitError as w}from"@swapkit/helpers";import j from"bignumber.js";async function p(G,J){let Q=await fetch(`${t}${G}`,{...J,headers:{project_id:o,...J?.headers}});if(!Q.ok)throw Error(`Blockfrost API error: ${Q.status} ${Q.statusText}`);return Q.json()}async function r(G){try{return await p(`/addresses/${G}/utxos`)}catch{return[]}}async function FG(){return(await p("/blocks/latest")).slot}async function HG(){let G=await p("/epochs/latest/parameters"),J={PlutusScriptV1:G.cost_models.PlutusV1?Object.values(G.cost_models.PlutusV1):[],PlutusScriptV2:G.cost_models.PlutusV2?Object.values(G.cost_models.PlutusV2):[],PlutusScriptV3:G.cost_models.PlutusV3?Object.values(G.cost_models.PlutusV3):[]};return{collateralPercent:new j(G.collateral_percent),languageView:J,lovelacePerUtxoWord:new j(0),maxValueSize:Number.parseInt(G.max_val_size,10),minFeeA:new j(G.min_fee_a),minFeeB:new j(G.min_fee_b),minFeeRefScriptCostPerByte:new j(15),priceMem:new j(G.price_mem),priceSteps:new j(G.price_step),stakeKeyDeposit:new j(2000000),utxoCostPerByte:new j(G.coins_per_utxo_size)}}async function n(G){let J=await fetch(`${t}/tx/submit`,{body:Buffer.from(G,"hex"),headers:{"Content-Type":"application/cbor",project_id:o},method:"POST"});if(!J.ok){let Q=await J.text();throw Error(`Transaction submission failed: ${Q}`)}return J.json()}function RG(G,J){return G.map((Q)=>{let q=Q.amount.find((Z)=>Z.unit==="lovelace"),U=q?new j(q.quantity):new j(0),W=Q.amount.filter((Z)=>Z.unit!=="lovelace").map((Z)=>({amount:new j(Z.quantity),assetName:Z.unit.slice(56),policyId:Z.unit.slice(0,56)}));return{address:J,amount:U,index:Q.output_index,tokens:W,txId:Q.tx_hash}})}async function DG(G){try{let J=await r(G),Q=0n,q=new Map;for(let Z of J){if(!Z.amount||!Array.isArray(Z.amount))continue;for(let Y of Z.amount){let{unit:F,quantity:R}=Y;if(F==="lovelace")Q+=BigInt(R);else{let D=q.get(F)||0n;q.set(F,D+BigInt(R))}}}let U=[],{baseDecimal:W}=YG(L.Cardano);if(Q>0n)U.push(k.from({chain:L.Cardano,fromBaseDecimal:W,value:Q.toString()}));for(let[Z,Y]of q)U.push(k.from({asset:`${L.Cardano}.${Z}`,value:Y.toString()}));if(U.length===0)return[k.from({chain:L.Cardano})];return U}catch(J){let Q=J instanceof Error?J.message:String(J);return console.error(`Cardano balance fetch error: ${Q}`),[k.from({chain:L.Cardano})]}}function s(G){if(!G||typeof G!=="string")return!1;try{let J=XG.decode(G,120);return J.prefix==="addr"||J.prefix==="addr_test"}catch{return!1}}async function OG(G,J=0,Q=0){let q=await jG(G,""),W=(await qG.fromEntropy(Buffer.from(q.slice(0,64)))).derive(g+1852).derive(g+1815).derive(g+J),Z=W.derive(0).derive(Q),Y=Z.toBip32PublicKey().toPublicKey().toBytes(),F=x.hash28(Y),D=W.derive(2).derive(0).toBip32PublicKey().toPublicKey().toBytes(),K=x.hash28(D),S={hash:F,type:u.HashType.ADDRESS},$={hash:K,type:u.HashType.ADDRESS},H=new WG.BaseAddress(MG,S,$).getBech32(),M=Z.toPrivateKey();return{getAddress:()=>H,publicKey:Y,publicKeyHash:F,signTransaction:async(O)=>{try{let X=await import("@stricahq/cbors"),V=Buffer.from(O,"hex"),B=X.Decoder.decode(V),[_,N,C,T]=B.value,A=X.Encoder.encode(_),P=x.hash32(A),h=M.sign(P),f=N instanceof Map?N:new Map,E=f.get(i)||[];E.push([Y,h]),f.set(i,E);let l=[_,f,C,T];return X.Encoder.encode(l).toString("hex")}catch(X){throw new w("toolbox_cardano_sign_transaction_failed",{message:String(X)})}}}}function IG(G){let J,Q,q;async function U(){if(!q)q=await HG();return q}async function W(){if(J!==void 0)return J;if(G&&"phrase"in G&&G.phrase){let $=G.index??0;return J=await OG(G.phrase,0,$),J}if(G&&"signer"in G&&G.signer)return J=G.signer,J;return}async function Z(){if(Q)return Q;let $=await W();if(!$)return"";if("getAddress"in $)return Q=await $.getAddress(),Q;return""}async function Y($){let z=$||await Z();if(!z)throw new w("core_wallet_connection_not_found");return DG(z)}async function F($){if($)try{let{tx:O}=await R($),X=O.getFee();return k.from({chain:L.Cardano,fromBaseDecimal:6,value:X.toString()})}catch{}let z=await U(),H=400,M=z.minFeeB.plus(z.minFeeA.times(H));return k.from({chain:L.Cardano,fromBaseDecimal:6,value:M.toString()})}async function R({sender:$="",recipient:z,assetValue:H,memo:M,pureLovelaceOnly:O=!1}){let X=$||await Z();if(!X)throw new w("core_wallet_connection_not_found");let[V,B,_]=await Promise.all([r(X),FG(),U()]),N=V.filter((I)=>O?I.amount.every((v)=>v.unit==="lovelace"):I.amount.some((v)=>v.unit==="lovelace")).sort((I,v)=>{let m=I.amount.some((b)=>b.unit!=="lovelace"),GG=v.amount.some((b)=>b.unit!=="lovelace");if(m===GG)return 0;return m?1:-1}),C=d.getAddressFromString(X),T=d.getAddressFromString(z),A=RG(N,C),P=new j(H.getBaseValue("string")),h=[{address:T,amount:P,tokens:[]}],f;if(M){let I=new Map;I.set("msg",[M]),f={metadata:[{data:I,label:674}]}}let E={..._,minFeeB:_.minFeeB.plus(_.minFeeA.times(4))},y=new UG({protocolParams:E}).paymentTransaction({auxiliaryData:f,changeAddress:C,inputs:A,outputs:h,ttl:B+3600}),{payload:e}=y.buildTransaction();return{tx:y,unsignedTx:e}}async function D($){let z=await W();if(!z||!("signTransaction"in z))throw new w("core_wallet_connection_not_found");return z.signTransaction($)}async function K({recipient:$,assetValue:z,memo:H}){let M=await W();if(!M||!("signTransaction"in M))throw new w("core_wallet_connection_not_found");let{unsignedTx:O}=await R({assetValue:z,memo:H,recipient:$,sender:await Z()}),X=await D(O);return await n(X)}async function S($){let z=await D($);return await n(z)}return{createTransaction:R,estimateTransactionFee:F,getAddress:Z,getBalance:Y,signAndBroadcastTransaction:S,signTransaction:D,transfer:K,validateAddress:s}}var o="mainnet3YT7XK6NidLPlkHxxyBB5V0WzXUOTIJS",t="https://cardano-mainnet.blockfrost.io/api/v0",MG,g=2147483648,i=0;var a=c(()=>{MG=u.NetworkId.MAINNET});var _G={};$G(_G,{validateCardanoAddress:()=>s,getCardanoToolbox:()=>IG});var fG=c(()=>{a()});fG();export{s as validateCardanoAddress,IG as getCardanoToolbox};