@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
|
|
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
|
|
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};
|