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