@meshsdk/common 1.6.1 → 1.6.3

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.
package/dist/index.js CHANGED
@@ -1 +1,1505 @@
1
- var S={epoch:0,coinsPerUtxoSize:4310,priceMem:.0577,priceStep:721e-7,minFeeA:44,minFeeB:155381,keyDeposit:2e6,maxTxSize:16384,maxValSize:5e3,poolDeposit:5e8,maxCollateralInputs:3,decentralisation:0,maxBlockSize:98304,collateralPercent:150,maxBlockHeaderSize:1100,minPoolCost:"340000000",maxTxExMem:"16000000",maxTxExSteps:"10000000000",maxBlockExMem:"80000000",maxBlockExSteps:"40000000000"},v=(e,t=S.minFeeA,r=S.minFeeB)=>(BigInt(t)*BigInt(e)+BigInt(r)).toString();var xe=["begin","eternl","flint","lace","nami","nufi","gerowallet","typhoncip30","vespr","yoroi"];var Se=[205665,812,1,1,1e3,571,0,1,1e3,24177,4,1,1e3,32,117366,10475,4,23e3,100,23e3,100,23e3,100,23e3,100,23e3,100,23e3,100,100,100,23e3,100,19537,32,175354,32,46417,4,221973,511,0,1,89141,32,497525,14068,4,2,196500,453240,220,0,1,1,1e3,28662,4,2,245e3,216773,62,1,1060367,12586,1,208512,421,1,187e3,1e3,52998,1,80436,32,43249,32,1e3,32,80556,1,57667,4,1e3,10,197145,156,1,197145,156,1,204924,473,1,208896,511,1,52467,32,64832,32,65493,32,22558,32,16563,32,76511,32,196500,453240,220,0,1,1,69522,11687,0,1,60091,32,196500,453240,220,0,1,1,196500,453240,220,0,1,1,806990,30482,4,1927926,82523,4,265318,0,4,0,85931,32,205665,812,1,1,41182,32,212342,32,31220,32,32696,32,43357,32,32247,32,38314,32,57996947,18975,10],he=[205665,812,1,1,1e3,571,0,1,1e3,24177,4,1,1e3,32,117366,10475,4,23e3,100,23e3,100,23e3,100,23e3,100,23e3,100,23e3,100,100,100,23e3,100,19537,32,175354,32,46417,4,221973,511,0,1,89141,32,497525,14068,4,2,196500,453240,220,0,1,1,1e3,28662,4,2,245e3,216773,62,1,1060367,12586,1,208512,421,1,187e3,1e3,52998,1,80436,32,43249,32,1e3,32,80556,1,57667,4,1e3,10,197145,156,1,197145,156,1,204924,473,1,208896,511,1,52467,32,64832,32,65493,32,22558,32,16563,32,76511,32,196500,453240,220,0,1,1,69522,11687,0,1,60091,32,196500,453240,220,0,1,1,196500,453240,220,0,1,1,1159724,392670,0,2,806990,30482,4,1927926,82523,4,265318,0,4,0,85931,32,205665,812,1,1,41182,32,212342,32,31220,32,32696,32,43357,32,32247,32,38314,32,35892428,10,57996947,18975,10,38887044,32947,10];var Z={ALONZO:{V1:"a141005901d59f1a000302590001011a00060bc719026d00011a000249f01903e800011a000249f018201a0025cea81971f70419744d186419744d186419744d186419744d186419744d186419744d18641864186419744d18641a000249f018201a000249f018201a000249f018201a000249f01903e800011a000249f018201a000249f01903e800081a000242201a00067e2318760001011a000249f01903e800081a000249f01a0001b79818f7011a000249f0192710011a0002155e19052e011903e81a000249f01903e8011a000249f018201a000249f018201a000249f0182001011a000249f0011a000249f0041a000194af18f8011a000194af18f8011a0002377c190556011a0002bdea1901f1011a000249f018201a000249f018201a000249f018201a000249f018201a000249f018201a000249f018201a000242201a00067e23187600010119f04c192bd200011a000249f018201a000242201a00067e2318760001011a000242201a00067e2318760001011a0025cea81971f704001a000141bb041a000249f019138800011a000249f018201a000302590001011a000249f018201a000249f018201a000249f018201a000249f018201a000249f018201a000249f018201a000249f018201a00330da70101ff"},BABBAGE:{V1:"a141005901b69f1a0003236119032c01011903e819023b00011903e8195e7104011903e818201a0001ca761928eb041959d818641959d818641959d818641959d818641959d818641959d81864186418641959d81864194c5118201a0002acfa182019b551041a000363151901ff00011a00015c3518201a000797751936f404021a0002ff941a0006ea7818dc0001011903e8196ff604021a0003bd081a00034ec5183e011a00102e0f19312a011a00032e801901a5011a0002da781903e819cf06011a00013a34182019a8f118201903e818201a00013aac0119e143041903e80a1a00030219189c011a00030219189c011a0003207c1901d9011a000330001901ff0119ccf3182019fd40182019ffd5182019581e18201940b318201a00012adf18201a0002ff941a0006ea7818dc0001011a00010f92192da7000119eabb18201a0002ff941a0006ea7818dc0001011a0002ff941a0006ea7818dc0001011a000c504e197712041a001d6af61a0001425b041a00040c660004001a00014fab18201a0003236119032c010119a0de18201a00033d7618201979f41820197fb8182019a95d1820197df718201995aa18201a009063b91903fd0aff",V2:"a20198af1a0003236119032c01011903e819023b00011903e8195e7104011903e818201a0001ca761928eb041959d818641959d818641959d818641959d818641959d818641959d81864186418641959d81864194c5118201a0002acfa182019b551041a000363151901ff00011a00015c3518201a000797751936f404021a0002ff941a0006ea7818dc0001011903e8196ff604021a0003bd081a00034ec5183e011a00102e0f19312a011a00032e801901a5011a0002da781903e819cf06011a00013a34182019a8f118201903e818201a00013aac0119e143041903e80a1a00030219189c011a00030219189c011a0003207c1901d9011a000330001901ff0119ccf3182019fd40182019ffd5182019581e18201940b318201a00012adf18201a0002ff941a0006ea7818dc0001011a00010f92192da7000119eabb18201a0002ff941a0006ea7818dc0001011a0002ff941a0006ea7818dc0001011a0011b22c1a0005fdde00021a000c504e197712041a001d6af61a0001425b041a00040c660004001a00014fab18201a0003236119032c010119a0de18201a00033d7618201979f41820197fb8182019a95d1820197df718201995aa18201b00000004a817c8001b00000004a817c8001a009063b91903fd0a1b00000004a817c800001b00000004a817c80041005901b69f1a0003236119032c01011903e819023b00011903e8195e7104011903e818201a0001ca761928eb041959d818641959d818641959d818641959d818641959d818641959d81864186418641959d81864194c5118201a0002acfa182019b551041a000363151901ff00011a00015c3518201a000797751936f404021a0002ff941a0006ea7818dc0001011903e8196ff604021a0003bd081a00034ec5183e011a00102e0f19312a011a00032e801901a5011a0002da781903e819cf06011a00013a34182019a8f118201903e818201a00013aac0119e143041903e80a1a00030219189c011a00030219189c011a0003207c1901d9011a000330001901ff0119ccf3182019fd40182019ffd5182019581e18201940b318201a00012adf18201a0002ff941a0006ea7818dc0001011a00010f92192da7000119eabb18201a0002ff941a0006ea7818dc0001011a0002ff941a0006ea7818dc0001011a000c504e197712041a001d6af61a0001425b041a00040c660004001a00014fab18201a0003236119032c010119a0de18201a00033d7618201979f41820197fb8182019a95d1820197df718201995aa18201a009063b91903fd0aff"}},Ae=(e,t)=>Z[e][t];var Ce={mem:7e6,steps:3e9},y=56,ve={V1:"V1",V2:"V2",V3:"V3"},ke=2147483648,Re={testnet:["74","1598400","1595967616","432000"],preview:["183","15811222","1682467200","86400"],preprod:["65","26438400","1682121600","432000"],mainnet:["208","4492800","1596059091","432000"]},Ie={0:"8d18d786e92776c824607fd8e193ec535c79dc61ea2405ddf3b09fe3",1:"f0ff48bbb7bbe9d59a40f1ce90e9e9d0ff5002ec48f232b49ca0fb9a"},He={mainnet:"wss://ogmios-api.mainnet.dandelion.link",preprod:"wss://ogmios-api.iohk-preprod.dandelion.link",preview:"__TBD_SOON_TM__",testnet:"wss://ogmios-api.testnet.dandelion.link"},Be={LQ:"da8c30857834c6ae7203935b89278c532b3995245295456f993e1d244c51",MIN:"29d222ce763455e3d7a09a665ce554f00ac89d2e99a1a83d267170c64d494e",NTX:"edfd7a1d77bcb8b884c474bdc92a16002d1fb720e454fa6e993444794e5458",iBTC:"f66d78b4a3cb3d37afa0ec36461e51ecbde00f26c8f0a68f94b6988069425443",iETH:"f66d78b4a3cb3d37afa0ec36461e51ecbde00f26c8f0a68f94b6988069455448",iUSD:"f66d78b4a3cb3d37afa0ec36461e51ecbde00f26c8f0a68f94b6988069555344",MILK:"8a1cfae21368b8bebbbed9800fec304e95cce39a2a57dc35e2e3ebaa4d494c4b",AGIX:"f43a62fdc3965df486de8a0d32fe800963589c41b38946602a0dc53541474958",MELD:"6ac8ef33b510ec004fe11585f7c5a9f0c07f0c23428ab4f29c1d7d104d454c44",INDY:"533bb94a8850ee3ccbe483106489399112b74c905342cb1792a797a0494e4459",CLAY:"38ad9dc3aec6a2f38e220142b9aa6ade63ebe71f65e7cc2b7d8a8535434c4159",MCOS:"6f46e1304b16d884c85c62fb0eef35028facdc41aaa0fd319a152ed64d434f53",DING:"ce5b9e0f8a88255b65f2e4d065c6e716e9fa9a8a86dfb86423dd1ac044494e47",GERO:"10a49b996e2402269af553a8a96fb8eb90d79e9eca79e2b4223057b64745524f",NMKR:"5dac8536653edc12f6f5e1045d8164b9f59998d3bdc300fc928434894e4d4b52",PAVIA:"884892bcdc360bcef87d6b3f806e7f9cd5ac30d999d49970e7a903ae5041564941",HOSKY:"a0028f350aaabe0545fdcb56b039bfb08e4bb4d8c4d7c3c7d481c235484f534b59",YUMMI:"078eafce5cd7edafdf63900edef2c1ea759e77f30ca81d6bbdeec92479756d6d69",C3:"8e51398904a5d3fc129fbf4f1589701de23c7824d5c90fdb9490e15a434841524c4933",GIMBAL:"2b0a04a7b60132b1805b296c7fcb3b217ff14413991bf76f72663c3067696d62616c",SUNDAE:"9a9693a9a37912a5097918f97918d15240c92ab729a0b7c4aa144d7753554e444145",GREENS:"4623ab311b7d982d8d26fcbe1a9439ca56661aafcdcd8d8a0ef31fd6475245454e53",GENS:"dda5fdb1002f7389b33e036b6afee82a8189becb6cba852e8b79b4fb0014df1047454e53",SOCIETY:"25f0fc240e91bd95dcdaebd2ba7713fc5168ac77234a3d79449fc20c534f4349455459",DJED:"8db269c3ec630e06ae29f74bc39edd1f87c819f1056206e879a1cd61446a65644d6963726f555344",SHEN:"8db269c3ec630e06ae29f74bc39edd1f87c819f1056206e879a1cd615368656e4d6963726f555344",WMT:"1d7f33bd23d85e1a25d87d86fac4f199c3197a2f7afeb662a0f34e1e776f726c646d6f62696c65746f6b656e",COPI:"b6a7467ea1deb012808ef4e87b5ff371e85f7142d7b356a40d9b42a0436f726e75636f70696173205b76696120436861696e506f72742e696f5d"},Oe=e=>`000643b0${e}`,Ke=e=>`000de140${e}`;var je=e=>{let t=[];return e.forEach(r=>{let o=t.find(n=>n.unit===r.unit);o?o.quantity=(BigInt(o.quantity)+BigInt(r.quantity)).toString():t.push(r)}),t};var Ge=["rate","address"],$e=["name","image","mediaType","description","instagram","twitter","discord","website"],We=["ticker","decimals"],D=e=>{switch(typeof e){case"object":if(e instanceof Array)return e.map(o=>D(o));let t=new Map;return Object.keys(e).forEach(o=>{t.set(o,D(e[o]))}),{alternative:0,fields:[t,1]};default:return e}};var ee=["testnet","preview","preprod","mainnet"],Xe=e=>ee.includes(e);var P=e=>{switch(e.type){case"SingleHostAddr":return{singleHostAddr:{ipv4:e.IPV4,ipv6:e.IPV6,port:e.port}};case"SingleHostName":return{singleHostName:{hostname:e.domainName,port:e.port}};case"MultiHostName":return{multiHostName:{dnsName:e.domainName}}}};var L=e=>({vrfKeyHash:e.vrfKeyHash,operator:e.operator,pledge:e.pledge,cost:e.cost,margin:e.margin,relays:e.relays.map(t=>P(t)),owners:e.owners,rewardAddress:e.rewardAddress,metadata:e.metadata?te(e.metadata):void 0}),te=e=>({url:e.URL,metadata:e.hash});var at=e=>{switch(e.type){case"RegisterPool":return{registerPool:{poolParams:L(e.poolParams)}};case"RegisterStake":return{registerStake:{stakeKeyHash:e.stakeKeyHash}};case"DelegateStake":return{delegateStake:{stakeKeyHash:e.stakeKeyHash,poolId:e.poolId}};case"DeregisterStake":return{deregisterStake:{stakeKeyHash:e.stakeKeyHash}};case"RetirePool":return{retirePool:{poolId:e.poolId,epoch:e.epoch}};case"VoteDelegation":return{voteDelegation:{stakeKeyHash:e.stakeKeyHash,drep:e.drep}};case"StakeAndVoteDelegation":return{stakeAndVoteDelegation:{stakeKeyHash:e.stakeKeyHash,poolKeyHash:e.poolKeyHash,drep:e.drep}};case"StakeRegistrationAndDelegation":return{stakeRegistrationAndDelegation:{stakeKeyHash:e.stakeKeyHash,poolKeyHash:e.poolKeyHash,coin:e.coin}};case"VoteRegistrationAndDelegation":return{voteRegistrationAndDelegation:{stakeKeyHash:e.stakeKeyHash,drep:e.drep,coin:e.coin}};case"StakeVoteRegistrationAndDelegation":return{stakeVoteRegistrationAndDelegation:{stakeKeyHash:e.stakeKeyHash,poolKeyHash:e.poolKeyHash,drep:e.drep,coin:e.coin}};case"CommitteeHotAuth":return{committeeHotAuth:{committeeColdKeyHash:e.committeeColdKeyHash,committeeHotKeyHash:e.committeeHotKeyHash}};case"CommitteeColdResign":return{committeeColdResign:{committeeColdKeyHash:e.committeeColdKeyHash,anchor:e.anchor??null}};case"DRepRegistration":return{dRepRegistration:{votingKeyHash:e.votingKeyHash,coin:e.coin,anchor:e.anchor??null}};case"DRepDeregistration":return{dRepDeregistration:{votingKeyHash:e.votingKeyHash,coin:e.coin}};case"DRepUpdate":return{dRepUpdate:{votingKeyHash:e.votingKeyHash,anchor:e.anchor}}}};var it=()=>({inputs:[],outputs:[],extraInputs:[],collaterals:[],requiredSignatures:[],referenceInputs:[],mints:[],changeAddress:"",metadata:[],validityRange:{},certificates:[],withdrawals:[],signingKey:[],selectionConfig:{threshold:"5000000",strategy:"experimental",includeTxFees:!0}}),ct=e=>({invalidBefore:e.invalidBefore??null,invalidHereafter:e.invalidHereafter??null});var Qt=(e,t)=>({alternative:e,fields:t}),l=e=>({alternative:0,fields:e}),A=e=>({alternative:1,fields:e}),qt=e=>({alternative:2,fields:e});var Wt=(e,t)=>{if(e.length!==56&&e!=="")throw new Error(`Invalid policy id for [${e}] - should be ${y} bytes long or empty string for lovelace`);if(t.length>64)throw new Error(`Invalid asset name for [${t}] - should be less than 32 bytes (64 hex length) long`);return l([e,t])},re=(e,t)=>{if(e.length!==64)throw new Error("Invalid transaction hash - should be 32 bytes long");return l([l([e]),t])},Yt=(e,t)=>re(e,t),Xt=(e,t)=>[e,t];var V=(e,t=!1)=>e===""?A([]):t?l([l([A([e])])]):l([l([l([e])])]),r0=(e,t)=>l([{alternative:0,fields:[e]},V(t||"")]),o0=(e,t)=>l([{alternative:1,fields:[e]},V(t||"")]);var c0=e=>e?A([]):l([]),p0=e=>{let t=[];for(let r=0;r<e.length;r+=64){let o=e.substring(r,r+64);t.push(o)}return t},d0=e=>e.join("");var B=(e,t)=>{if(!Array.isArray(t))throw new Error("fields of a constructor must be an array");return{constructor:e,fields:t}},u=e=>B(0,e),h=e=>B(1,e),x0=e=>B(2,e);var A0=e=>e?h([]):u([]),oe=e=>T(e),T=e=>{if(e.length%2!==0)throw new Error("Invalid hex string - odd length: "+e);if(!/^[0-9a-fA-F]*$/.test(e))throw new Error("Invalid hex string - non-hex string character: "+e);return{bytes:e}},k=e=>({int:e}),ne=(e,t=!0)=>(t&&e.forEach(r=>{if(typeof r!="object")throw new Error("List item of JSON Cardano data type must be an object - "+r)}),{list:e}),M0=e=>ne((r=>{let o=[];for(let n=0;n<r.length;n+=64){let s=r.substring(n,n+64);o.push(s)}return o})(e).map(oe)),C0=e=>e.list.map(t=>t.bytes).join(""),O=(e,t=!0)=>({map:e.map(([r,o])=>{if(t&&(typeof r!="object"||typeof o!="object"))throw new Error(`Map item of JSON Cardano data type must be an object - ${r}, ${o}`);return{k:r,v:o}})});var _=e=>{if(e.length!==56)throw new Error(`Invalid hash for [${e}] - should be 56 bytes long`);return T(e)},K=e=>_(e),N=e=>_(e),ae=e=>{if(e.length!==y&&e!=="")throw new Error(`Invalid policy id for [${e}] - should be ${y} bytes long or empty string for lovelace`);return T(e)},w=e=>ae(e),se=e=>{if(e.length>64)throw new Error(`Invalid asset name for [${e}] - should be less than 32 bytes (64 hex length) long`);return T(e)},U=e=>se(e),K0=(e,t)=>u([w(e),U(t)]),ie=(e,t)=>{if(e.length!==64)throw new Error("Invalid transaction hash - should be 32 bytes long");return u([u([T(e)]),k(t)])},N0=(e,t)=>ie(e,t),w0=e=>({int:e}),U0=e=>({map:e.map(([t,r])=>({k:t,v:r}))}),E0=(e,t)=>({list:[e,t]});var F=(e,t=!1)=>e===""?h([]):t?u([u([h([K(e)])])]):u([u([u([N(e)])])]),q0=(e,t,r=!1)=>u([u([N(e)]),F(t||"",r)]),j0=(e,t,r=!1)=>u([h([K(e)]),F(t||"",r)]);var ce=e=>Buffer.from(e).toString("hex"),Z0=e=>Buffer.from(e,"hex"),er=e=>Buffer.from(e,"utf8").toString("hex"),tr=e=>Buffer.from(e,"hex").toString("utf8"),E=e=>e.length%2===0&&/^[0-9A-F]*$/i.test(e)?Buffer.from(e,"hex"):Buffer.from(e,"utf-8"),pe=e=>e.length%2===0&&/^[0-9A-F]*$/i.test(e)?e:ce(Buffer.from(e,"utf-8")),rr=e=>Buffer.from(e,"hex").toString("utf-8"),or=e=>{let t=e.slice(0,y),r=e.includes(".")?pe(e.split(".")[1]):e.slice(y);return{policyId:t,assetName:r}};var Q={mainnet:{zeroTime:1596059091e3,zeroSlot:4492800,slotLength:1e3,startEpoch:208,epochLength:432e3},preview:{zeroTime:1666656e6,zeroSlot:0,slotLength:1e3,startEpoch:183,epochLength:86400},preprod:{zeroTime:16540416e5+1728e6,zeroSlot:86400,slotLength:1e3,startEpoch:65,epochLength:432e3},testnet:{zeroTime:0,zeroSlot:0,slotLength:0,startEpoch:0,epochLength:0}},ar=(e,t)=>{let r=(e-t.zeroSlot)*t.slotLength;return t.zeroTime+r},de=(e,t)=>{let r=e-t.zeroTime;return Math.floor(r/t.slotLength)+t.zeroSlot},sr=(e,t=Date.now())=>de(t,Q[e]).toString(),ir=(e,t=Date.now())=>{let r=Q[e],n=(BigInt(t)/1000n-BigInt(r.zeroTime))/BigInt(r.epochLength)+BigInt(r.startEpoch);return Number(n)};var mr=e=>{let t=[],r={};return e.forEach(o=>{let n=o.unit.replace("lovelace",""),s=n.slice(0,56)||"",d=n.slice(56)||"";r[s]||(r[s]={}),r[s][d]?r[s][d]+=Number(o.quantity):r[s][d]=Number(o.quantity)}),Object.keys(r).forEach(o=>{let n=w(o),s=Object.keys(r[o]).map(i=>[U(i),k(r[o][i])]),d=O(s);t.push([n,d])}),O(t)},gr=e=>{let t=[];return e.map.forEach(r=>{let o=r.k.bytes;r.v.map.forEach(n=>{let s=n.k.bytes,d=n.v.int.toString(),i=o+s,f=i===""?"lovelace":i;t.push({unit:f,quantity:d})})}),t};var p=class e{value;constructor(t){this.value=BigInt(t)}divFloor(t){return this.value=this.value/t.value,this}checkedMul(t){return this.value*=t.value,this}checkedAdd(t){return this.value+=t.value,this}checkedSub(t){return this.value-=t.value,this}clampedSub(t){let r=this.value-t.value;return this.value=r<0n?0n:r,this}lessThan(t){return this.value<t.value}compare(t){return this.value===t.value?0:this.value<t.value?-1:1}static new=t=>new e(t);toString(){return this.value.toString()}};import fe from"@emurgo/cip14-js";var ue=fe,kr=(e,t)=>ue.default.fromParts(E(e),E(t)).fingerprint();var q=(e,t,r)=>{let o=new Map(e);o.set("lovelace",String(Number(o.get("lovelace")||0)+Number(r)));let n=new Map;for(let a=0;a<t.length;a++)n.set(a,t[a]);let s=new Set,d=new Set,i=new Set,f=new Set,b=new Set;for(let a=0;a<t.length;a++)switch(t[a].output.amount.length){case 1:{d.add(a);break}case 2:{i.add(a);break}case 3:{f.add(a);break}default:{b.add(a);break}}let g=(a,c,m)=>{let I=n.get(a);if(!I)return;let J=le(I,c);if(Number(J)>0){s.add(a),m.delete(a);for(let H of I.output.amount)o.set(H.unit,String(Number(o.get(H.unit))-Number(H.quantity)))}};for(let a of o.keys())if(a!="lovelace"){for(let c of i){let m=o.get(a);if(!m||Number(m)<=0)break;g(c,a,i)}for(let c of f){let m=o.get(a);if(!m||Number(m)<=0)break;g(c,a,f)}for(let c of b){let m=o.get(a);if(!m||Number(m)<=0)break;g(c,a,b)}}for(let a of d){let c=o.get("lovelace");if(!c||Number(c)<=0)break;g(a,"lovelace",d)}for(let a of i){let c=o.get("lovelace");if(!c||Number(c)<=0)break;g(a,"lovelace",i)}for(let a of f){let c=o.get("lovelace");if(!c||Number(c)<=0)break;g(a,"lovelace",f)}for(let a of b){let c=o.get("lovelace");if(!c||Number(c)<=0)break;g(a,"lovelace",b)}for(let a of o.keys())if(Number(o.get(a))>0)return console.log("Insufficient funds for",a),console.log("Remaining quantity",Number(o.get(a))),[];let C=[];for(let a of s){let c=n.get(a);c&&C.push(c)}return C},le=(e,t)=>{for(let r of e.output.amount)if(r.unit==t)return r.quantity;return"0"};var me=(e,t)=>Array.from(t,r=>({unit:r[0],quantity:p.new(r[1])})).every(r=>e.filter(o=>o.output.amount.find(n=>n.unit===r.unit)!==void 0).reduce((o,n)=>{let s=n.output.amount.reduce((d,i)=>d.checkedAdd(p.new(r.unit===i.unit?i.quantity:"0")),p.new("0"));return o.checkedAdd(s)},p.new("0")).lessThan(r.quantity)===!1),M=(e,t)=>{let r=p.new(e.output.amount.find(n=>n.unit==="lovelace")?.quantity??"0");return p.new(t.output.amount.find(n=>n.unit==="lovelace")?.quantity??"0").compare(r)},j=e=>{let{maxTxSize:t,minFeeA:r,minFeeB:o}=e;return p.new(v(t,r,o))},R=e=>e.output.amount.length>1,z=e=>e.reduce((t,r)=>{let o=r.output.amount.find(n=>n.unit==="lovelace")?.quantity??"0";return t.checkedAdd(p.new(o))},p.new("0")),G=(e,t)=>{let r=t.sort(M);return x(r,new Map([["lovelace",e]]))},x=(e,t,r=[])=>e.length===0||me(r,t)?r:ge(e[0],t)?x(e.slice(1),t,[...r,e[0]]):x(e.slice(1),t,r),ge=(e,t)=>Array.from(t.keys()).some(r=>e.output.amount.find(o=>o.unit===r)!==void 0);var $=(e,t,r="5000000")=>{let o=p.new(e.get("lovelace")??"0").checkedAdd(p.new(r)),n=t.filter(i=>i.output.amount.filter(f=>f.unit!=="lovelace").some(f=>e.has(f.unit))),s=z(n);return[...s.lessThan(o)?G(o.clampedSub(s).toString(),t.filter(i=>!n.some(f=>f.input.txHash===i.input.txHash&&f.input.outputIndex===i.input.outputIndex))):[],...n]};var W=(e,t,r=!1,{maxTxSize:o,minFeeA:n,minFeeB:s}=S)=>{let d=t.filter(C=>R(C)===!1).sort(M),i=p.new(v(o,n,s)),f=r?p.new(e).checkedAdd(i).toString():e;return x(d,new Map([["lovelace",f]]))};var Y=(e,t,r=!1,o=S)=>{let n=t.filter(R).sort(M),s=j(o),d=e.get("lovelace")??"0",i=r?p.new(d).checkedAdd(s).toString():d;return e.set("lovelace",i),x(n,e)};var X=class{threshold;includeTxFees;constructor(t="5000000",r=!0){this.threshold=t,this.includeTxFees=r}largestFirst(t,r){let o=t.get("lovelace")??"0",n=BigInt(o)+BigInt(this.threshold);return W(n.toString(),r,this.includeTxFees)}keepRelevant(t,r){return $(t,r,this.threshold)}largestFirstMultiAsset(t,r){let o=t.get("lovelace")??"0";return t.set("lovelace",(BigInt(o)+BigInt(this.threshold)).toString()),Y(t,r,this.includeTxFees)}experimental(t,r){return q(t,r,this.threshold)}};import{generateMnemonic as yo,mnemonicToEntropy as xo}from"bip39";export{ue as AssetFingerprint,p as BigNum,Oe as CIP68_100,Ke as CIP68_222,S as DEFAULT_PROTOCOL_PARAMETERS,Ce as DEFAULT_REDEEMER_BUDGET,Se as DEFAULT_V1_COST_MODEL_LIST,he as DEFAULT_V2_COST_MODEL_LIST,ke as HARDENED_KEY_START,ve as LANGUAGE_VERSIONS,y as POLICY_ID_LENGTH,Q as SLOT_CONFIG_NETWORK,Re as SUPPORTED_CLOCKS,Ie as SUPPORTED_HANDLES,Z as SUPPORTED_LANGUAGE_VIEWS,He as SUPPORTED_OGMIOS_LINKS,Be as SUPPORTED_TOKENS,xe as SUPPORTED_WALLETS,X as UtxoSelection,K0 as assetClass,se as assetName,O as assocMap,A0 as bool,oe as builtinByteString,T as byteString,ce as bytesToHex,at as certificateToObj,B as conStr,u as conStr0,h as conStr1,x0 as conStr2,w as currencySymbol,U0 as dict,it as emptyTxBuilderBody,q as experimentalSelectUtxos,pe as fromUTF8,We as fungibleAssetKeys,yo as generateMnemonic,_ as hashByteString,Z0 as hexToBytes,tr as hexToString,k as integer,Xe as isNetwork,$ as keepRelevant,W as largestFirst,Y as largestFirstMultiAsset,ne as list,Wt as mAssetClass,c0 as mBool,Qt as mConStr,l as mConStr0,A as mConStr1,qt as mConStr2,V as mMaybeStakingHash,re as mOutputReference,d0 as mPlutusBSArrayToString,r0 as mPubKeyAddress,o0 as mScriptAddress,p0 as mStringToPlutusBSArray,Xt as mTuple,Yt as mTxOutRef,F as maybeStakingHash,je as mergeAssets,$e as metadataStandardKeys,D as metadataToCip68,xo as mnemonicToEntropy,ie as outputReference,or as parseAssetUnit,gr as parsePlutusValueToAssets,C0 as plutusBSArrayToString,ae as policyId,te as poolMetadataToObj,L as poolParamsToObj,w0 as posixTime,q0 as pubKeyAddress,N as pubKeyHash,P as relayToObj,ir as resolveEpochNo,kr as resolveFingerprint,Ae as resolveLanguageView,sr as resolveSlotNo,v as resolveTxFees,Ge as royaltiesStandardKeys,j0 as scriptAddress,K as scriptHash,ar as slotToBeginUnixTime,M0 as stringToBSArray,er as stringToHex,E as toBytes,rr as toUTF8,U as tokenName,E0 as tuple,N0 as txOutRef,de as unixTimeToEnclosingSlot,ct as validityRangeToObj,mr as value};
1
+ // src/constants/protocol-parameters.ts
2
+ var DEFAULT_PROTOCOL_PARAMETERS = {
3
+ epoch: 0,
4
+ coinsPerUtxoSize: 4310,
5
+ priceMem: 0.0577,
6
+ priceStep: 721e-7,
7
+ minFeeA: 44,
8
+ minFeeB: 155381,
9
+ keyDeposit: 2e6,
10
+ maxTxSize: 16384,
11
+ maxValSize: 5e3,
12
+ poolDeposit: 5e8,
13
+ maxCollateralInputs: 3,
14
+ decentralisation: 0,
15
+ maxBlockSize: 98304,
16
+ collateralPercent: 150,
17
+ maxBlockHeaderSize: 1100,
18
+ minPoolCost: "340000000",
19
+ maxTxExMem: "16000000",
20
+ maxTxExSteps: "10000000000",
21
+ maxBlockExMem: "80000000",
22
+ maxBlockExSteps: "40000000000"
23
+ };
24
+ var resolveTxFees = (txSize, minFeeA = DEFAULT_PROTOCOL_PARAMETERS.minFeeA, minFeeB = DEFAULT_PROTOCOL_PARAMETERS.minFeeB) => {
25
+ const fees = BigInt(minFeeA) * BigInt(txSize) + BigInt(minFeeB);
26
+ return fees.toString();
27
+ };
28
+
29
+ // src/constants/supported-wallets.ts
30
+ var SUPPORTED_WALLETS = [
31
+ "begin",
32
+ "eternl",
33
+ "flint",
34
+ "lace",
35
+ "nami",
36
+ "nufi",
37
+ "gerowallet",
38
+ "typhoncip30",
39
+ "vespr",
40
+ "yoroi"
41
+ ];
42
+
43
+ // src/constants/cost-models.ts
44
+ var DEFAULT_V1_COST_MODEL_LIST = [
45
+ 205665,
46
+ 812,
47
+ 1,
48
+ 1,
49
+ 1e3,
50
+ 571,
51
+ 0,
52
+ 1,
53
+ 1e3,
54
+ 24177,
55
+ 4,
56
+ 1,
57
+ 1e3,
58
+ 32,
59
+ 117366,
60
+ 10475,
61
+ 4,
62
+ 23e3,
63
+ 100,
64
+ 23e3,
65
+ 100,
66
+ 23e3,
67
+ 100,
68
+ 23e3,
69
+ 100,
70
+ 23e3,
71
+ 100,
72
+ 23e3,
73
+ 100,
74
+ 100,
75
+ 100,
76
+ 23e3,
77
+ 100,
78
+ 19537,
79
+ 32,
80
+ 175354,
81
+ 32,
82
+ 46417,
83
+ 4,
84
+ 221973,
85
+ 511,
86
+ 0,
87
+ 1,
88
+ 89141,
89
+ 32,
90
+ 497525,
91
+ 14068,
92
+ 4,
93
+ 2,
94
+ 196500,
95
+ 453240,
96
+ 220,
97
+ 0,
98
+ 1,
99
+ 1,
100
+ 1e3,
101
+ 28662,
102
+ 4,
103
+ 2,
104
+ 245e3,
105
+ 216773,
106
+ 62,
107
+ 1,
108
+ 1060367,
109
+ 12586,
110
+ 1,
111
+ 208512,
112
+ 421,
113
+ 1,
114
+ 187e3,
115
+ 1e3,
116
+ 52998,
117
+ 1,
118
+ 80436,
119
+ 32,
120
+ 43249,
121
+ 32,
122
+ 1e3,
123
+ 32,
124
+ 80556,
125
+ 1,
126
+ 57667,
127
+ 4,
128
+ 1e3,
129
+ 10,
130
+ 197145,
131
+ 156,
132
+ 1,
133
+ 197145,
134
+ 156,
135
+ 1,
136
+ 204924,
137
+ 473,
138
+ 1,
139
+ 208896,
140
+ 511,
141
+ 1,
142
+ 52467,
143
+ 32,
144
+ 64832,
145
+ 32,
146
+ 65493,
147
+ 32,
148
+ 22558,
149
+ 32,
150
+ 16563,
151
+ 32,
152
+ 76511,
153
+ 32,
154
+ 196500,
155
+ 453240,
156
+ 220,
157
+ 0,
158
+ 1,
159
+ 1,
160
+ 69522,
161
+ 11687,
162
+ 0,
163
+ 1,
164
+ 60091,
165
+ 32,
166
+ 196500,
167
+ 453240,
168
+ 220,
169
+ 0,
170
+ 1,
171
+ 1,
172
+ 196500,
173
+ 453240,
174
+ 220,
175
+ 0,
176
+ 1,
177
+ 1,
178
+ 806990,
179
+ 30482,
180
+ 4,
181
+ 1927926,
182
+ 82523,
183
+ 4,
184
+ 265318,
185
+ 0,
186
+ 4,
187
+ 0,
188
+ 85931,
189
+ 32,
190
+ 205665,
191
+ 812,
192
+ 1,
193
+ 1,
194
+ 41182,
195
+ 32,
196
+ 212342,
197
+ 32,
198
+ 31220,
199
+ 32,
200
+ 32696,
201
+ 32,
202
+ 43357,
203
+ 32,
204
+ 32247,
205
+ 32,
206
+ 38314,
207
+ 32,
208
+ 57996947,
209
+ 18975,
210
+ 10
211
+ ];
212
+ var DEFAULT_V2_COST_MODEL_LIST = [
213
+ 205665,
214
+ 812,
215
+ 1,
216
+ 1,
217
+ 1e3,
218
+ 571,
219
+ 0,
220
+ 1,
221
+ 1e3,
222
+ 24177,
223
+ 4,
224
+ 1,
225
+ 1e3,
226
+ 32,
227
+ 117366,
228
+ 10475,
229
+ 4,
230
+ 23e3,
231
+ 100,
232
+ 23e3,
233
+ 100,
234
+ 23e3,
235
+ 100,
236
+ 23e3,
237
+ 100,
238
+ 23e3,
239
+ 100,
240
+ 23e3,
241
+ 100,
242
+ 100,
243
+ 100,
244
+ 23e3,
245
+ 100,
246
+ 19537,
247
+ 32,
248
+ 175354,
249
+ 32,
250
+ 46417,
251
+ 4,
252
+ 221973,
253
+ 511,
254
+ 0,
255
+ 1,
256
+ 89141,
257
+ 32,
258
+ 497525,
259
+ 14068,
260
+ 4,
261
+ 2,
262
+ 196500,
263
+ 453240,
264
+ 220,
265
+ 0,
266
+ 1,
267
+ 1,
268
+ 1e3,
269
+ 28662,
270
+ 4,
271
+ 2,
272
+ 245e3,
273
+ 216773,
274
+ 62,
275
+ 1,
276
+ 1060367,
277
+ 12586,
278
+ 1,
279
+ 208512,
280
+ 421,
281
+ 1,
282
+ 187e3,
283
+ 1e3,
284
+ 52998,
285
+ 1,
286
+ 80436,
287
+ 32,
288
+ 43249,
289
+ 32,
290
+ 1e3,
291
+ 32,
292
+ 80556,
293
+ 1,
294
+ 57667,
295
+ 4,
296
+ 1e3,
297
+ 10,
298
+ 197145,
299
+ 156,
300
+ 1,
301
+ 197145,
302
+ 156,
303
+ 1,
304
+ 204924,
305
+ 473,
306
+ 1,
307
+ 208896,
308
+ 511,
309
+ 1,
310
+ 52467,
311
+ 32,
312
+ 64832,
313
+ 32,
314
+ 65493,
315
+ 32,
316
+ 22558,
317
+ 32,
318
+ 16563,
319
+ 32,
320
+ 76511,
321
+ 32,
322
+ 196500,
323
+ 453240,
324
+ 220,
325
+ 0,
326
+ 1,
327
+ 1,
328
+ 69522,
329
+ 11687,
330
+ 0,
331
+ 1,
332
+ 60091,
333
+ 32,
334
+ 196500,
335
+ 453240,
336
+ 220,
337
+ 0,
338
+ 1,
339
+ 1,
340
+ 196500,
341
+ 453240,
342
+ 220,
343
+ 0,
344
+ 1,
345
+ 1,
346
+ 1159724,
347
+ 392670,
348
+ 0,
349
+ 2,
350
+ 806990,
351
+ 30482,
352
+ 4,
353
+ 1927926,
354
+ 82523,
355
+ 4,
356
+ 265318,
357
+ 0,
358
+ 4,
359
+ 0,
360
+ 85931,
361
+ 32,
362
+ 205665,
363
+ 812,
364
+ 1,
365
+ 1,
366
+ 41182,
367
+ 32,
368
+ 212342,
369
+ 32,
370
+ 31220,
371
+ 32,
372
+ 32696,
373
+ 32,
374
+ 43357,
375
+ 32,
376
+ 32247,
377
+ 32,
378
+ 38314,
379
+ 32,
380
+ 35892428,
381
+ 10,
382
+ 57996947,
383
+ 18975,
384
+ 10,
385
+ 38887044,
386
+ 32947,
387
+ 10
388
+ ];
389
+
390
+ // src/constants/language-views.ts
391
+ var SUPPORTED_LANGUAGE_VIEWS = {
392
+ ALONZO: {
393
+ V1: "a141005901d59f1a000302590001011a00060bc719026d00011a000249f01903e800011a000249f018201a0025cea81971f70419744d186419744d186419744d186419744d186419744d186419744d18641864186419744d18641a000249f018201a000249f018201a000249f018201a000249f01903e800011a000249f018201a000249f01903e800081a000242201a00067e2318760001011a000249f01903e800081a000249f01a0001b79818f7011a000249f0192710011a0002155e19052e011903e81a000249f01903e8011a000249f018201a000249f018201a000249f0182001011a000249f0011a000249f0041a000194af18f8011a000194af18f8011a0002377c190556011a0002bdea1901f1011a000249f018201a000249f018201a000249f018201a000249f018201a000249f018201a000249f018201a000242201a00067e23187600010119f04c192bd200011a000249f018201a000242201a00067e2318760001011a000242201a00067e2318760001011a0025cea81971f704001a000141bb041a000249f019138800011a000249f018201a000302590001011a000249f018201a000249f018201a000249f018201a000249f018201a000249f018201a000249f018201a000249f018201a00330da70101ff"
394
+ },
395
+ BABBAGE: {
396
+ V1: "a141005901b69f1a0003236119032c01011903e819023b00011903e8195e7104011903e818201a0001ca761928eb041959d818641959d818641959d818641959d818641959d818641959d81864186418641959d81864194c5118201a0002acfa182019b551041a000363151901ff00011a00015c3518201a000797751936f404021a0002ff941a0006ea7818dc0001011903e8196ff604021a0003bd081a00034ec5183e011a00102e0f19312a011a00032e801901a5011a0002da781903e819cf06011a00013a34182019a8f118201903e818201a00013aac0119e143041903e80a1a00030219189c011a00030219189c011a0003207c1901d9011a000330001901ff0119ccf3182019fd40182019ffd5182019581e18201940b318201a00012adf18201a0002ff941a0006ea7818dc0001011a00010f92192da7000119eabb18201a0002ff941a0006ea7818dc0001011a0002ff941a0006ea7818dc0001011a000c504e197712041a001d6af61a0001425b041a00040c660004001a00014fab18201a0003236119032c010119a0de18201a00033d7618201979f41820197fb8182019a95d1820197df718201995aa18201a009063b91903fd0aff",
397
+ V2: "a20198af1a0003236119032c01011903e819023b00011903e8195e7104011903e818201a0001ca761928eb041959d818641959d818641959d818641959d818641959d818641959d81864186418641959d81864194c5118201a0002acfa182019b551041a000363151901ff00011a00015c3518201a000797751936f404021a0002ff941a0006ea7818dc0001011903e8196ff604021a0003bd081a00034ec5183e011a00102e0f19312a011a00032e801901a5011a0002da781903e819cf06011a00013a34182019a8f118201903e818201a00013aac0119e143041903e80a1a00030219189c011a00030219189c011a0003207c1901d9011a000330001901ff0119ccf3182019fd40182019ffd5182019581e18201940b318201a00012adf18201a0002ff941a0006ea7818dc0001011a00010f92192da7000119eabb18201a0002ff941a0006ea7818dc0001011a0002ff941a0006ea7818dc0001011a0011b22c1a0005fdde00021a000c504e197712041a001d6af61a0001425b041a00040c660004001a00014fab18201a0003236119032c010119a0de18201a00033d7618201979f41820197fb8182019a95d1820197df718201995aa18201b00000004a817c8001b00000004a817c8001a009063b91903fd0a1b00000004a817c800001b00000004a817c80041005901b69f1a0003236119032c01011903e819023b00011903e8195e7104011903e818201a0001ca761928eb041959d818641959d818641959d818641959d818641959d818641959d81864186418641959d81864194c5118201a0002acfa182019b551041a000363151901ff00011a00015c3518201a000797751936f404021a0002ff941a0006ea7818dc0001011903e8196ff604021a0003bd081a00034ec5183e011a00102e0f19312a011a00032e801901a5011a0002da781903e819cf06011a00013a34182019a8f118201903e818201a00013aac0119e143041903e80a1a00030219189c011a00030219189c011a0003207c1901d9011a000330001901ff0119ccf3182019fd40182019ffd5182019581e18201940b318201a00012adf18201a0002ff941a0006ea7818dc0001011a00010f92192da7000119eabb18201a0002ff941a0006ea7818dc0001011a0002ff941a0006ea7818dc0001011a000c504e197712041a001d6af61a0001425b041a00040c660004001a00014fab18201a0003236119032c010119a0de18201a00033d7618201979f41820197fb8182019a95d1820197df718201995aa18201a009063b91903fd0aff"
398
+ }
399
+ };
400
+ var resolveLanguageView = (era, version) => {
401
+ return SUPPORTED_LANGUAGE_VIEWS[era][version];
402
+ };
403
+
404
+ // src/constants/index.ts
405
+ var DEFAULT_REDEEMER_BUDGET = {
406
+ mem: 7e6,
407
+ steps: 3e9
408
+ };
409
+ var POLICY_ID_LENGTH = 56;
410
+ var LANGUAGE_VERSIONS = {
411
+ V1: "V1",
412
+ V2: "V2",
413
+ V3: "V3"
414
+ };
415
+ var HARDENED_KEY_START = 2147483648;
416
+ var SUPPORTED_CLOCKS = {
417
+ testnet: ["74", "1598400", "1595967616", "432000"],
418
+ preview: ["183", "15811222", "1682467200", "86400"],
419
+ preprod: ["65", "26438400", "1682121600", "432000"],
420
+ mainnet: ["208", "4492800", "1596059091", "432000"]
421
+ };
422
+ var SUPPORTED_HANDLES = {
423
+ 0: "8d18d786e92776c824607fd8e193ec535c79dc61ea2405ddf3b09fe3",
424
+ 1: "f0ff48bbb7bbe9d59a40f1ce90e9e9d0ff5002ec48f232b49ca0fb9a"
425
+ };
426
+ var SUPPORTED_OGMIOS_LINKS = {
427
+ mainnet: "wss://ogmios-api.mainnet.dandelion.link",
428
+ preprod: "wss://ogmios-api.iohk-preprod.dandelion.link",
429
+ preview: "__TBD_SOON_TM__",
430
+ testnet: "wss://ogmios-api.testnet.dandelion.link"
431
+ };
432
+ var SUPPORTED_TOKENS = {
433
+ LQ: "da8c30857834c6ae7203935b89278c532b3995245295456f993e1d244c51",
434
+ MIN: "29d222ce763455e3d7a09a665ce554f00ac89d2e99a1a83d267170c64d494e",
435
+ NTX: "edfd7a1d77bcb8b884c474bdc92a16002d1fb720e454fa6e993444794e5458",
436
+ iBTC: "f66d78b4a3cb3d37afa0ec36461e51ecbde00f26c8f0a68f94b6988069425443",
437
+ iETH: "f66d78b4a3cb3d37afa0ec36461e51ecbde00f26c8f0a68f94b6988069455448",
438
+ iUSD: "f66d78b4a3cb3d37afa0ec36461e51ecbde00f26c8f0a68f94b6988069555344",
439
+ MILK: "8a1cfae21368b8bebbbed9800fec304e95cce39a2a57dc35e2e3ebaa4d494c4b",
440
+ AGIX: "f43a62fdc3965df486de8a0d32fe800963589c41b38946602a0dc53541474958",
441
+ MELD: "6ac8ef33b510ec004fe11585f7c5a9f0c07f0c23428ab4f29c1d7d104d454c44",
442
+ INDY: "533bb94a8850ee3ccbe483106489399112b74c905342cb1792a797a0494e4459",
443
+ CLAY: "38ad9dc3aec6a2f38e220142b9aa6ade63ebe71f65e7cc2b7d8a8535434c4159",
444
+ MCOS: "6f46e1304b16d884c85c62fb0eef35028facdc41aaa0fd319a152ed64d434f53",
445
+ DING: "ce5b9e0f8a88255b65f2e4d065c6e716e9fa9a8a86dfb86423dd1ac044494e47",
446
+ GERO: "10a49b996e2402269af553a8a96fb8eb90d79e9eca79e2b4223057b64745524f",
447
+ NMKR: "5dac8536653edc12f6f5e1045d8164b9f59998d3bdc300fc928434894e4d4b52",
448
+ PAVIA: "884892bcdc360bcef87d6b3f806e7f9cd5ac30d999d49970e7a903ae5041564941",
449
+ HOSKY: "a0028f350aaabe0545fdcb56b039bfb08e4bb4d8c4d7c3c7d481c235484f534b59",
450
+ YUMMI: "078eafce5cd7edafdf63900edef2c1ea759e77f30ca81d6bbdeec92479756d6d69",
451
+ C3: "8e51398904a5d3fc129fbf4f1589701de23c7824d5c90fdb9490e15a434841524c4933",
452
+ GIMBAL: "2b0a04a7b60132b1805b296c7fcb3b217ff14413991bf76f72663c3067696d62616c",
453
+ SUNDAE: "9a9693a9a37912a5097918f97918d15240c92ab729a0b7c4aa144d7753554e444145",
454
+ GREENS: "4623ab311b7d982d8d26fcbe1a9439ca56661aafcdcd8d8a0ef31fd6475245454e53",
455
+ GENS: "dda5fdb1002f7389b33e036b6afee82a8189becb6cba852e8b79b4fb0014df1047454e53",
456
+ SOCIETY: "25f0fc240e91bd95dcdaebd2ba7713fc5168ac77234a3d79449fc20c534f4349455459",
457
+ DJED: "8db269c3ec630e06ae29f74bc39edd1f87c819f1056206e879a1cd61446a65644d6963726f555344",
458
+ SHEN: "8db269c3ec630e06ae29f74bc39edd1f87c819f1056206e879a1cd615368656e4d6963726f555344",
459
+ WMT: "1d7f33bd23d85e1a25d87d86fac4f199c3197a2f7afeb662a0f34e1e776f726c646d6f62696c65746f6b656e",
460
+ COPI: "b6a7467ea1deb012808ef4e87b5ff371e85f7142d7b356a40d9b42a0436f726e75636f70696173205b76696120436861696e506f72742e696f5d"
461
+ };
462
+ var CIP68_100 = (tokenNameHex) => {
463
+ return `000643b0${tokenNameHex}`;
464
+ };
465
+ var CIP68_222 = (tokenNameHex) => {
466
+ return `000de140${tokenNameHex}`;
467
+ };
468
+
469
+ // src/types/asset.ts
470
+ var mergeAssets = (assets) => {
471
+ const merged = [];
472
+ assets.forEach((asset) => {
473
+ const existing = merged.find((a) => a.unit === asset.unit);
474
+ if (existing) {
475
+ existing.quantity = (BigInt(existing.quantity) + BigInt(asset.quantity)).toString();
476
+ } else {
477
+ merged.push(asset);
478
+ }
479
+ });
480
+ return merged;
481
+ };
482
+
483
+ // src/types/asset-metadata.ts
484
+ var royaltiesStandardKeys = ["rate", "address"];
485
+ var metadataStandardKeys = [
486
+ "name",
487
+ "image",
488
+ "mediaType",
489
+ "description",
490
+ "instagram",
491
+ "twitter",
492
+ "discord",
493
+ "website"
494
+ ];
495
+ var fungibleAssetKeys = ["ticker", "decimals"];
496
+ var metadataToCip68 = (metadata) => {
497
+ switch (typeof metadata) {
498
+ case "object":
499
+ if (metadata instanceof Array) {
500
+ return metadata.map((item) => metadataToCip68(item));
501
+ }
502
+ const metadataMap = /* @__PURE__ */ new Map();
503
+ const keys = Object.keys(metadata);
504
+ keys.forEach((key) => {
505
+ metadataMap.set(key, metadataToCip68(metadata[key]));
506
+ });
507
+ return {
508
+ alternative: 0,
509
+ fields: [metadataMap, 1]
510
+ };
511
+ default:
512
+ return metadata;
513
+ }
514
+ };
515
+
516
+ // src/types/network.ts
517
+ var ALL_NETWORKS = ["testnet", "preview", "preprod", "mainnet"];
518
+ var isNetwork = (value2) => {
519
+ return ALL_NETWORKS.includes(value2);
520
+ };
521
+
522
+ // src/types/protocol.ts
523
+ var castProtocol = (data) => {
524
+ const result = {};
525
+ for (const rawKey in DEFAULT_PROTOCOL_PARAMETERS) {
526
+ const key = rawKey;
527
+ const defaultValue = DEFAULT_PROTOCOL_PARAMETERS[key];
528
+ const value2 = data[key];
529
+ if (typeof defaultValue === "number") {
530
+ result[key] = !value2 && value2 !== 0 ? defaultValue : Number(value2);
531
+ } else if (typeof defaultValue === "string") {
532
+ result[key] = !value2 && value2 !== "" ? defaultValue : value2.toString();
533
+ }
534
+ }
535
+ return result;
536
+ };
537
+
538
+ // src/types/transaction-builder/index.ts
539
+ var emptyTxBuilderBody = () => ({
540
+ inputs: [],
541
+ outputs: [],
542
+ extraInputs: [],
543
+ collaterals: [],
544
+ requiredSignatures: [],
545
+ referenceInputs: [],
546
+ mints: [],
547
+ changeAddress: "",
548
+ metadata: [],
549
+ validityRange: {},
550
+ certificates: [],
551
+ withdrawals: [],
552
+ signingKey: [],
553
+ selectionConfig: {
554
+ threshold: "5000000",
555
+ strategy: "experimental",
556
+ includeTxFees: true
557
+ }
558
+ });
559
+ var validityRangeToObj = (validityRange) => {
560
+ return {
561
+ invalidBefore: validityRange.invalidBefore ?? null,
562
+ invalidHereafter: validityRange.invalidHereafter ?? null
563
+ };
564
+ };
565
+
566
+ // src/data/mesh/constructors.ts
567
+ var mConStr = (alternative, fields) => ({
568
+ alternative,
569
+ fields
570
+ });
571
+ var mConStr0 = (fields) => ({
572
+ alternative: 0,
573
+ fields
574
+ });
575
+ var mConStr1 = (fields) => ({
576
+ alternative: 1,
577
+ fields
578
+ });
579
+ var mConStr2 = (fields) => ({
580
+ alternative: 2,
581
+ fields
582
+ });
583
+
584
+ // src/data/mesh/aliases.ts
585
+ var mAssetClass = (currencySymbolHex, tokenNameHex) => {
586
+ if (currencySymbolHex.length !== 56 && currencySymbolHex !== "") {
587
+ throw new Error(
588
+ `Invalid policy id for [${currencySymbolHex}] - should be ${POLICY_ID_LENGTH} bytes long or empty string for lovelace`
589
+ );
590
+ }
591
+ if (tokenNameHex.length > 64) {
592
+ throw new Error(
593
+ `Invalid asset name for [${tokenNameHex}] - should be less than 32 bytes (64 hex length) long`
594
+ );
595
+ }
596
+ return mConStr0([currencySymbolHex, tokenNameHex]);
597
+ };
598
+ var mOutputReference = (txHash, index) => {
599
+ if (txHash.length !== 64) {
600
+ throw new Error("Invalid transaction hash - should be 32 bytes long");
601
+ }
602
+ return mConStr0([mConStr0([txHash]), index]);
603
+ };
604
+ var mTxOutRef = (txHash, index) => mOutputReference(txHash, index);
605
+ var mTuple = (key, value2) => [key, value2];
606
+
607
+ // src/data/mesh/credentials.ts
608
+ var mMaybeStakingHash = (stakeCredential, isScriptCredential = false) => {
609
+ if (stakeCredential === "") {
610
+ return mConStr1([]);
611
+ }
612
+ if (isScriptCredential) {
613
+ return mConStr0([mConStr0([mConStr1([stakeCredential])])]);
614
+ }
615
+ return mConStr0([mConStr0([mConStr0([stakeCredential])])]);
616
+ };
617
+ var mPubKeyAddress = (bytes, stakeCredential, isScriptCredential = false) => mConStr0([
618
+ { alternative: 0, fields: [bytes] },
619
+ mMaybeStakingHash(stakeCredential || "", isScriptCredential)
620
+ ]);
621
+ var mScriptAddress = (bytes, stakeCredential, isScriptCredential = false) => mConStr0([
622
+ { alternative: 1, fields: [bytes] },
623
+ mMaybeStakingHash(stakeCredential || "", isScriptCredential)
624
+ ]);
625
+
626
+ // src/data/mesh/primitives.ts
627
+ var mBool = (b) => b ? mConStr1([]) : mConStr0([]);
628
+ var mStringToPlutusBSArray = (hexString) => {
629
+ const chunks = [];
630
+ for (let i = 0; i < hexString.length; i += 64) {
631
+ const chunk = hexString.substring(i, i + 64);
632
+ chunks.push(chunk);
633
+ }
634
+ return chunks;
635
+ };
636
+ var mPlutusBSArrayToString = (bsArray) => {
637
+ return bsArray.join("");
638
+ };
639
+
640
+ // src/data/json/constructors.ts
641
+ var conStr = (constructor, fields) => {
642
+ if (!Array.isArray(fields)) {
643
+ throw new Error("fields of a constructor must be an array");
644
+ }
645
+ return {
646
+ constructor,
647
+ fields
648
+ };
649
+ };
650
+ var conStr0 = (fields) => conStr(0, fields);
651
+ var conStr1 = (fields) => conStr(1, fields);
652
+ var conStr2 = (fields) => conStr(2, fields);
653
+
654
+ // src/data/json/primitives.ts
655
+ var bool = (b) => b ? conStr1([]) : conStr0([]);
656
+ var builtinByteString = (bytes) => {
657
+ return byteString(bytes);
658
+ };
659
+ var byteString = (bytes) => {
660
+ if (bytes.length % 2 !== 0) {
661
+ throw new Error("Invalid hex string - odd length: " + bytes);
662
+ }
663
+ if (!/^[0-9a-fA-F]*$/.test(bytes)) {
664
+ throw new Error("Invalid hex string - non-hex string character: " + bytes);
665
+ }
666
+ return {
667
+ bytes
668
+ };
669
+ };
670
+ var integer = (int) => ({ int });
671
+ var list = (pList, validation = true) => {
672
+ if (validation) {
673
+ pList.forEach((item) => {
674
+ if (typeof item !== "object") {
675
+ throw new Error(
676
+ "List item of JSON Cardano data type must be an object - " + item
677
+ );
678
+ }
679
+ });
680
+ }
681
+ return { list: pList };
682
+ };
683
+ var stringToBSArray = (hexString) => {
684
+ const processRawStringIntoPlutusByteArray = (hexString2) => {
685
+ const chunks = [];
686
+ for (let i = 0; i < hexString2.length; i += 64) {
687
+ const chunk = hexString2.substring(i, i + 64);
688
+ chunks.push(chunk);
689
+ }
690
+ return chunks;
691
+ };
692
+ return list(
693
+ processRawStringIntoPlutusByteArray(hexString).map(builtinByteString)
694
+ );
695
+ };
696
+ var plutusBSArrayToString = (bsArray) => {
697
+ return bsArray.list.map((bs) => bs.bytes).join("");
698
+ };
699
+ var assocMap = (mapItems, validation = true) => ({
700
+ map: mapItems.map(([k, v]) => {
701
+ if (validation) {
702
+ if (typeof k !== "object" || typeof v !== "object") {
703
+ throw new Error(
704
+ `Map item of JSON Cardano data type must be an object - ${k}, ${v}`
705
+ );
706
+ }
707
+ }
708
+ return { k, v };
709
+ })
710
+ });
711
+
712
+ // src/data/json/aliases.ts
713
+ var hashByteString = (bytes) => {
714
+ if (bytes.length !== 56) {
715
+ throw new Error(`Invalid hash for [${bytes}] - should be 56 bytes long`);
716
+ }
717
+ return byteString(bytes);
718
+ };
719
+ var scriptHash = (bytes) => hashByteString(bytes);
720
+ var pubKeyHash = (bytes) => hashByteString(bytes);
721
+ var policyId = (bytes) => {
722
+ if (bytes.length !== POLICY_ID_LENGTH && bytes !== "") {
723
+ throw new Error(
724
+ `Invalid policy id for [${bytes}] - should be ${POLICY_ID_LENGTH} bytes long or empty string for lovelace`
725
+ );
726
+ }
727
+ return byteString(bytes);
728
+ };
729
+ var currencySymbol = (bytes) => policyId(bytes);
730
+ var assetName = (bytes) => {
731
+ if (bytes.length > 64) {
732
+ throw new Error(
733
+ `Invalid asset name for [${bytes}] - should be less than 32 bytes (64 hex length) long`
734
+ );
735
+ }
736
+ return byteString(bytes);
737
+ };
738
+ var tokenName = (bytes) => assetName(bytes);
739
+ var assetClass = (currencySymbolHex, tokenNameHex) => conStr0([currencySymbol(currencySymbolHex), tokenName(tokenNameHex)]);
740
+ var outputReference = (txHash, index) => {
741
+ if (txHash.length !== 64) {
742
+ throw new Error("Invalid transaction hash - should be 32 bytes long");
743
+ }
744
+ return conStr0([conStr0([byteString(txHash)]), integer(index)]);
745
+ };
746
+ var txOutRef = (txHash, index) => outputReference(txHash, index);
747
+ var posixTime = (int) => ({ int });
748
+ var dict = (itemsMap) => ({
749
+ map: itemsMap.map(([k, v]) => ({ k, v }))
750
+ });
751
+ var tuple = (key, value2) => ({ list: [key, value2] });
752
+
753
+ // src/data/json/credentials.ts
754
+ var maybeStakingHash = (stakeCredential, isScriptCredential = false) => {
755
+ if (stakeCredential === "") {
756
+ return conStr1([]);
757
+ }
758
+ if (isScriptCredential) {
759
+ return conStr0([
760
+ conStr0([conStr1([scriptHash(stakeCredential)])])
761
+ ]);
762
+ }
763
+ return conStr0([
764
+ conStr0([conStr0([pubKeyHash(stakeCredential)])])
765
+ ]);
766
+ };
767
+ var pubKeyAddress = (bytes, stakeCredential, isScriptCredential = false) => conStr0([
768
+ conStr0([pubKeyHash(bytes)]),
769
+ maybeStakingHash(stakeCredential || "", isScriptCredential)
770
+ ]);
771
+ var scriptAddress = (bytes, stakeCredential, isScriptCredential = false) => conStr0([
772
+ conStr1([scriptHash(bytes)]),
773
+ maybeStakingHash(stakeCredential || "", isScriptCredential)
774
+ ]);
775
+
776
+ // src/data/parser.ts
777
+ var bytesToHex = (bytes) => Buffer.from(bytes).toString("hex");
778
+ var hexToBytes = (hex) => Buffer.from(hex, "hex");
779
+ var stringToHex = (str) => Buffer.from(str, "utf8").toString("hex");
780
+ var hexToString = (hex) => Buffer.from(hex, "hex").toString("utf8");
781
+ var toBytes = (hex) => {
782
+ if (hex.length % 2 === 0 && /^[0-9A-F]*$/i.test(hex))
783
+ return Buffer.from(hex, "hex");
784
+ return Buffer.from(hex, "utf-8");
785
+ };
786
+ var fromUTF8 = (utf8) => {
787
+ if (utf8.length % 2 === 0 && /^[0-9A-F]*$/i.test(utf8)) return utf8;
788
+ return bytesToHex(Buffer.from(utf8, "utf-8"));
789
+ };
790
+ var toUTF8 = (hex) => Buffer.from(hex, "hex").toString("utf-8");
791
+ var parseAssetUnit = (unit) => {
792
+ const policyId2 = unit.slice(0, POLICY_ID_LENGTH);
793
+ const assetName2 = unit.includes(".") ? fromUTF8(unit.split(".")[1]) : unit.slice(POLICY_ID_LENGTH);
794
+ return { policyId: policyId2, assetName: assetName2 };
795
+ };
796
+
797
+ // src/data/time.ts
798
+ var SLOT_CONFIG_NETWORK = {
799
+ mainnet: {
800
+ zeroTime: 1596059091e3,
801
+ zeroSlot: 4492800,
802
+ slotLength: 1e3,
803
+ startEpoch: 208,
804
+ epochLength: 432e3
805
+ },
806
+ // Starting at Shelley era
807
+ preview: {
808
+ zeroTime: 16824672e5,
809
+ zeroSlot: 0,
810
+ slotLength: 1e3,
811
+ startEpoch: 183,
812
+ epochLength: 86400
813
+ },
814
+ // Starting at Shelley era
815
+ preprod: {
816
+ zeroTime: 16821216e5,
817
+ zeroSlot: 86400,
818
+ slotLength: 1e3,
819
+ startEpoch: 65,
820
+ epochLength: 432e3
821
+ },
822
+ // Starting at Shelley era
823
+ /** Customizable slot config (Initialized with 0 values). */
824
+ testnet: {
825
+ zeroTime: 0,
826
+ zeroSlot: 0,
827
+ slotLength: 0,
828
+ startEpoch: 0,
829
+ epochLength: 0
830
+ }
831
+ };
832
+ var slotToBeginUnixTime = (slot, slotConfig) => {
833
+ const msAfterBegin = (slot - slotConfig.zeroSlot) * slotConfig.slotLength;
834
+ return slotConfig.zeroTime + msAfterBegin;
835
+ };
836
+ var unixTimeToEnclosingSlot = (unixTime, slotConfig) => {
837
+ const timePassed = unixTime - slotConfig.zeroTime;
838
+ const slotsPassed = Math.floor(timePassed / slotConfig.slotLength);
839
+ return slotsPassed + slotConfig.zeroSlot;
840
+ };
841
+ var resolveSlotNo = (network, milliseconds = Date.now()) => {
842
+ return unixTimeToEnclosingSlot(
843
+ milliseconds,
844
+ SLOT_CONFIG_NETWORK[network]
845
+ ).toString();
846
+ };
847
+ var resolveEpochNo = (network, milliseconds = Date.now()) => {
848
+ const config = SLOT_CONFIG_NETWORK[network];
849
+ const msBigInt = BigInt(milliseconds);
850
+ const epoch = (msBigInt - BigInt(config.zeroTime)) / 1000n / BigInt(config.epochLength) + BigInt(config.startEpoch);
851
+ return Number(epoch);
852
+ };
853
+
854
+ // src/utils/asset-fingerprint.ts
855
+ import CIP14 from "@emurgo/cip14-js";
856
+ var AssetFingerprint = CIP14;
857
+ var resolveFingerprint = (policyId2, assetName2) => {
858
+ return AssetFingerprint.default.fromParts(toBytes(policyId2), toBytes(assetName2)).fingerprint();
859
+ };
860
+
861
+ // src/utils/bigNum.ts
862
+ var BigNum = class _BigNum {
863
+ value;
864
+ constructor(value2) {
865
+ if (!value2) {
866
+ this.value = BigInt(0);
867
+ return;
868
+ }
869
+ this.value = BigInt(value2);
870
+ }
871
+ static new(value2) {
872
+ if (!value2) {
873
+ return new _BigNum(0);
874
+ }
875
+ return new _BigNum(value2);
876
+ }
877
+ // Operators
878
+ divFloor(other) {
879
+ this.value = this.value / other.value;
880
+ return this;
881
+ }
882
+ checkedMul(other) {
883
+ this.value *= other.value;
884
+ return this;
885
+ }
886
+ checkedAdd(other) {
887
+ this.value += other.value;
888
+ return this;
889
+ }
890
+ checkedSub(other) {
891
+ this.value -= other.value;
892
+ return this;
893
+ }
894
+ clampedSub(other) {
895
+ const result = this.value - other.value;
896
+ this.value = result < 0n ? 0n : result;
897
+ return this;
898
+ }
899
+ // Comparators
900
+ lessThan(other) {
901
+ return this.value < other.value;
902
+ }
903
+ compare(other) {
904
+ if (this.value === other.value) {
905
+ return 0;
906
+ } else if (this.value < other.value) {
907
+ return -1;
908
+ } else {
909
+ return 1;
910
+ }
911
+ }
912
+ // Override
913
+ toString() {
914
+ return this.value.toString();
915
+ }
916
+ };
917
+
918
+ // src/data/value.ts
919
+ var value = (assets) => {
920
+ return MeshValue.fromAssets(assets).toJSON();
921
+ };
922
+ var mValue = (assets) => {
923
+ return MeshValue.fromAssets(assets).toData();
924
+ };
925
+ var MeshValue = class _MeshValue {
926
+ value;
927
+ constructor(value2 = {}) {
928
+ this.value = value2;
929
+ }
930
+ /**
931
+ * Converting assets into MeshValue
932
+ * @param assets The assets to convert
933
+ * @returns MeshValue
934
+ */
935
+ static fromAssets = (assets) => {
936
+ const value2 = new _MeshValue();
937
+ value2.addAssets(assets);
938
+ return value2;
939
+ };
940
+ /**
941
+ * Converting Value (the JSON representation of Cardano data Value) into MeshValue
942
+ * @param plutusValue The Value to convert
943
+ * @returns MeshValue
944
+ */
945
+ static fromValue = (plutusValue) => {
946
+ const assets = [];
947
+ plutusValue.map.forEach((policyMap) => {
948
+ const policy = policyMap.k.bytes;
949
+ policyMap.v.map.forEach((tokenMap) => {
950
+ const token = tokenMap.k.bytes;
951
+ const quantity = tokenMap.v.int.toString();
952
+ const unsanitizedUnit = policy + token;
953
+ const unit = unsanitizedUnit === "" ? "lovelace" : unsanitizedUnit;
954
+ assets.push({ unit, quantity });
955
+ });
956
+ });
957
+ return _MeshValue.fromAssets(assets);
958
+ };
959
+ /**
960
+ * Add an asset to the Value class's value record.
961
+ * @param asset The asset to add
962
+ * @returns The updated MeshValue object
963
+ */
964
+ addAsset = (asset) => {
965
+ const quantity = BigInt(asset.quantity);
966
+ const { unit } = asset;
967
+ if (this.value[unit]) {
968
+ this.value[unit] += quantity;
969
+ } else {
970
+ this.value[unit] = quantity;
971
+ }
972
+ return this;
973
+ };
974
+ /**
975
+ * Add an array of assets to the Value class's value record.
976
+ * @param assets The assets to add
977
+ * @returns The updated MeshValue object
978
+ */
979
+ addAssets = (assets) => {
980
+ assets.forEach((asset) => {
981
+ this.addAsset(asset);
982
+ });
983
+ return this;
984
+ };
985
+ /**
986
+ * Substract an asset from the Value class's value record.
987
+ * @param asset The asset to subtract
988
+ * @returns The updated MeshValue object
989
+ */
990
+ negateAsset = (asset) => {
991
+ const { unit, quantity: assetQty } = asset;
992
+ const quantity = BigNum.new(this.value[unit]);
993
+ quantity.clampedSub(BigNum.new(assetQty));
994
+ if (quantity.value === BigInt(0)) {
995
+ delete this.value[unit];
996
+ } else {
997
+ this.value[unit] = quantity.value;
998
+ }
999
+ return this;
1000
+ };
1001
+ /**
1002
+ * Subtract an array of assets from the Value class's value record.
1003
+ * @param assets The assets to subtract
1004
+ * @returns The updated MeshValue object
1005
+ */
1006
+ negateAssets = (assets) => {
1007
+ assets.forEach((asset) => {
1008
+ this.negateAsset(asset);
1009
+ });
1010
+ return this;
1011
+ };
1012
+ /**
1013
+ * Get the quantity of asset object per unit
1014
+ * @param unit The unit to get the quantity of
1015
+ * @returns The quantity of the asset
1016
+ */
1017
+ get = (unit) => {
1018
+ return this.value[unit] ? BigInt(this.value[unit]) : BigInt(0);
1019
+ };
1020
+ /**
1021
+ * Get all asset units
1022
+ * @returns The asset units
1023
+ */
1024
+ units = () => {
1025
+ return Object.keys(this.value);
1026
+ };
1027
+ /**
1028
+ * Check if the value is greater than or equal to another value
1029
+ * @param other - The value to compare against
1030
+ * @returns boolean
1031
+ */
1032
+ geq = (other) => {
1033
+ return Object.keys(other.value).every((key) => this.geqUnit(key, other));
1034
+ };
1035
+ /**
1036
+ * Check if the specific unit of value is greater than or equal to that unit of another value
1037
+ * @param unit - The unit to compare
1038
+ * @param other - The value to compare against
1039
+ * @returns boolean
1040
+ */
1041
+ geqUnit = (unit, other) => {
1042
+ if (this.value[unit] === void 0 || other.value[unit] === void 0) {
1043
+ return false;
1044
+ }
1045
+ return BigInt(this.value[unit]) >= BigInt(other.value[unit]);
1046
+ };
1047
+ /**
1048
+ * Check if the value is less than or equal to another value
1049
+ * @param other - The value to compare against
1050
+ * @returns boolean
1051
+ */
1052
+ leq = (other) => {
1053
+ return Object.keys(other.value).every((key) => this.leqUnit(key, other));
1054
+ };
1055
+ /**
1056
+ * Check if the specific unit of value is less than or equal to that unit of another value
1057
+ * @param unit - The unit to compare
1058
+ * @param other - The value to compare against
1059
+ * @returns boolean
1060
+ */
1061
+ leqUnit = (unit, other) => {
1062
+ if (this.value[unit] === void 0 || other.value[unit] === void 0) {
1063
+ return false;
1064
+ }
1065
+ return BigInt(this.value[unit]) <= BigInt(other.value[unit]);
1066
+ };
1067
+ /**
1068
+ * Check if the value is empty
1069
+ * @returns boolean
1070
+ */
1071
+ isEmpty = () => {
1072
+ return Object.keys(this.value).length === 0;
1073
+ };
1074
+ /**
1075
+ * Merge the given values
1076
+ * @param values The other values to merge
1077
+ * @returns this
1078
+ */
1079
+ merge = (values) => {
1080
+ const valuesArray = Array.isArray(values) ? values : [values];
1081
+ valuesArray.forEach((other) => {
1082
+ Object.entries(other.value).forEach(([key, value2]) => {
1083
+ this.value[key] = (this.value[key] !== void 0 ? BigInt(this.value[key]) : BigInt(0)) + BigInt(value2);
1084
+ });
1085
+ });
1086
+ return this;
1087
+ };
1088
+ /**
1089
+ * Convert the MeshValue object into an array of Asset
1090
+ * @returns The array of Asset
1091
+ */
1092
+ toAssets = () => {
1093
+ const assets = [];
1094
+ Object.entries(this.value).forEach(([unit, quantity]) => {
1095
+ assets.push({ unit, quantity: quantity.toString() });
1096
+ });
1097
+ return assets;
1098
+ };
1099
+ /**
1100
+ * Convert the MeshValue object into Cardano data Value in Mesh Data type
1101
+ */
1102
+ toData = () => {
1103
+ const valueMap = /* @__PURE__ */ new Map();
1104
+ this.toAssets().forEach((asset) => {
1105
+ const policy = asset.unit.slice(0, 56) || "";
1106
+ const token = asset.unit.slice(56) || "";
1107
+ if (!valueMap.has(policy)) {
1108
+ valueMap.set(policy, /* @__PURE__ */ new Map());
1109
+ }
1110
+ const tokenMap = valueMap.get(policy);
1111
+ const quantity = tokenMap?.get(token);
1112
+ if (!quantity) {
1113
+ tokenMap.set(token, BigInt(asset.quantity));
1114
+ } else {
1115
+ tokenMap.set(token, quantity + BigInt(asset.quantity));
1116
+ }
1117
+ });
1118
+ return valueMap;
1119
+ };
1120
+ /**
1121
+ * Convert the MeshValue object into a JSON representation of Cardano data Value
1122
+ * @returns Cardano data Value in JSON
1123
+ */
1124
+ toJSON = () => {
1125
+ const valueMapToParse = [];
1126
+ const valueMap = {};
1127
+ this.toAssets().forEach((asset) => {
1128
+ const sanitizedName = asset.unit.replace("lovelace", "");
1129
+ const policy = sanitizedName.slice(0, 56) || "";
1130
+ const token = sanitizedName.slice(56) || "";
1131
+ if (!valueMap[policy]) {
1132
+ valueMap[policy] = {};
1133
+ }
1134
+ if (!valueMap[policy][token]) {
1135
+ valueMap[policy][token] = Number(asset.quantity);
1136
+ } else {
1137
+ valueMap[policy][token] += Number(asset.quantity);
1138
+ }
1139
+ });
1140
+ Object.keys(valueMap).forEach((policy) => {
1141
+ const policyByte = currencySymbol(policy);
1142
+ const tokens = Object.keys(valueMap[policy]).map(
1143
+ (name) => [tokenName(name), integer(valueMap[policy][name])]
1144
+ );
1145
+ const policyMap = assocMap(tokens);
1146
+ valueMapToParse.push([policyByte, policyMap]);
1147
+ });
1148
+ return assocMap(valueMapToParse);
1149
+ };
1150
+ };
1151
+
1152
+ // src/utxo-selection/experimental.ts
1153
+ var experimentalSelectUtxos = (requiredAssets, inputs, threshold) => {
1154
+ const totalRequiredAssets = new Map(requiredAssets);
1155
+ totalRequiredAssets.set(
1156
+ "lovelace",
1157
+ String(
1158
+ Number(totalRequiredAssets.get("lovelace") || 0) + Number(threshold)
1159
+ )
1160
+ );
1161
+ const utxoMap = /* @__PURE__ */ new Map();
1162
+ for (let i = 0; i < inputs.length; i++) {
1163
+ utxoMap.set(i, inputs[i]);
1164
+ }
1165
+ const selectedInputs = /* @__PURE__ */ new Set();
1166
+ const onlyLovelace = /* @__PURE__ */ new Set();
1167
+ const singletons = /* @__PURE__ */ new Set();
1168
+ const pairs = /* @__PURE__ */ new Set();
1169
+ const rest = /* @__PURE__ */ new Set();
1170
+ for (let i = 0; i < inputs.length; i++) {
1171
+ switch (inputs[i].output.amount.length) {
1172
+ case 1: {
1173
+ onlyLovelace.add(i);
1174
+ break;
1175
+ }
1176
+ case 2: {
1177
+ singletons.add(i);
1178
+ break;
1179
+ }
1180
+ case 3: {
1181
+ pairs.add(i);
1182
+ break;
1183
+ }
1184
+ default: {
1185
+ rest.add(i);
1186
+ break;
1187
+ }
1188
+ }
1189
+ }
1190
+ const addUtxoWithAssetAmount = (inputIndex, assetUnit, set) => {
1191
+ const utxo = utxoMap.get(inputIndex);
1192
+ if (!utxo) return;
1193
+ const amount = getAssetAmount(utxo, assetUnit);
1194
+ if (Number(amount) > 0) {
1195
+ selectedInputs.add(inputIndex);
1196
+ set.delete(inputIndex);
1197
+ for (const asset of utxo.output.amount) {
1198
+ totalRequiredAssets.set(
1199
+ asset.unit,
1200
+ String(
1201
+ Number(totalRequiredAssets.get(asset.unit)) - Number(asset.quantity)
1202
+ )
1203
+ );
1204
+ }
1205
+ }
1206
+ };
1207
+ for (const assetUnit of totalRequiredAssets.keys()) {
1208
+ if (assetUnit == "lovelace") continue;
1209
+ for (const inputIndex of singletons) {
1210
+ const assetRequired = totalRequiredAssets.get(assetUnit);
1211
+ if (!assetRequired || Number(assetRequired) <= 0) break;
1212
+ addUtxoWithAssetAmount(inputIndex, assetUnit, singletons);
1213
+ }
1214
+ for (const inputIndex of pairs) {
1215
+ const assetRequired = totalRequiredAssets.get(assetUnit);
1216
+ if (!assetRequired || Number(assetRequired) <= 0) break;
1217
+ addUtxoWithAssetAmount(inputIndex, assetUnit, pairs);
1218
+ }
1219
+ for (const inputIndex of rest) {
1220
+ const assetRequired = totalRequiredAssets.get(assetUnit);
1221
+ if (!assetRequired || Number(assetRequired) <= 0) break;
1222
+ addUtxoWithAssetAmount(inputIndex, assetUnit, rest);
1223
+ }
1224
+ }
1225
+ for (const inputIndex of onlyLovelace) {
1226
+ const assetRequired = totalRequiredAssets.get("lovelace");
1227
+ if (!assetRequired || Number(assetRequired) <= 0) break;
1228
+ addUtxoWithAssetAmount(inputIndex, "lovelace", onlyLovelace);
1229
+ }
1230
+ for (const inputIndex of singletons) {
1231
+ const assetRequired = totalRequiredAssets.get("lovelace");
1232
+ if (!assetRequired || Number(assetRequired) <= 0) break;
1233
+ addUtxoWithAssetAmount(inputIndex, "lovelace", singletons);
1234
+ }
1235
+ for (const inputIndex of pairs) {
1236
+ const assetRequired = totalRequiredAssets.get("lovelace");
1237
+ if (!assetRequired || Number(assetRequired) <= 0) break;
1238
+ addUtxoWithAssetAmount(inputIndex, "lovelace", pairs);
1239
+ }
1240
+ for (const inputIndex of rest) {
1241
+ const assetRequired = totalRequiredAssets.get("lovelace");
1242
+ if (!assetRequired || Number(assetRequired) <= 0) break;
1243
+ addUtxoWithAssetAmount(inputIndex, "lovelace", rest);
1244
+ }
1245
+ for (const assetUnit of totalRequiredAssets.keys()) {
1246
+ if (Number(totalRequiredAssets.get(assetUnit)) > 0) {
1247
+ console.warn("Insufficient funds for", assetUnit);
1248
+ console.warn(
1249
+ "Remaining quantity",
1250
+ Number(totalRequiredAssets.get(assetUnit))
1251
+ );
1252
+ return [];
1253
+ }
1254
+ }
1255
+ const selectedUtxos = [];
1256
+ for (const inputIndex of selectedInputs) {
1257
+ const utxo = utxoMap.get(inputIndex);
1258
+ if (utxo) {
1259
+ selectedUtxos.push(utxo);
1260
+ }
1261
+ }
1262
+ return selectedUtxos;
1263
+ };
1264
+ var getAssetAmount = (utxo, assetUnit) => {
1265
+ for (const utxoAsset of utxo.output.amount) {
1266
+ if (utxoAsset.unit == assetUnit) return utxoAsset.quantity;
1267
+ }
1268
+ return "0";
1269
+ };
1270
+
1271
+ // src/utxo-selection/common.ts
1272
+ var enoughValueHasBeenSelected = (selection, assets) => {
1273
+ return Array.from(assets, (asset) => ({
1274
+ unit: asset[0],
1275
+ quantity: BigNum.new(asset[1])
1276
+ })).every((asset) => {
1277
+ return selection.filter((utxo) => {
1278
+ return utxo.output.amount.find((a) => a.unit === asset.unit) !== void 0;
1279
+ }).reduce((selectedQuantity, utxo) => {
1280
+ const utxoQuantity = utxo.output.amount.reduce(
1281
+ (quantity, a) => quantity.checkedAdd(
1282
+ BigNum.new(asset.unit === a.unit ? a.quantity : "0")
1283
+ ),
1284
+ BigNum.new("0")
1285
+ );
1286
+ return selectedQuantity.checkedAdd(utxoQuantity);
1287
+ }, BigNum.new("0")).lessThan(asset.quantity) === false;
1288
+ });
1289
+ };
1290
+ var largestLovelaceQuantity = (utxoA, utxoB) => {
1291
+ const aLovelaceQuantity = BigNum.new(
1292
+ utxoA.output.amount.find((asset) => asset.unit === "lovelace")?.quantity ?? "0"
1293
+ );
1294
+ const bLovelaceQuantity = BigNum.new(
1295
+ utxoB.output.amount.find((asset) => asset.unit === "lovelace")?.quantity ?? "0"
1296
+ );
1297
+ return bLovelaceQuantity.compare(aLovelaceQuantity);
1298
+ };
1299
+ var maxTxFees = (parameters) => {
1300
+ const { maxTxSize, minFeeA, minFeeB } = parameters;
1301
+ return BigNum.new(resolveTxFees(maxTxSize, minFeeA, minFeeB));
1302
+ };
1303
+ var multiAssetUTxO = (utxo) => utxo.output.amount.length > 1;
1304
+ var selectedLovelaceQuantity = (multiAsset) => {
1305
+ return multiAsset.reduce((sum, utxo) => {
1306
+ const lovelace = utxo.output.amount.find((asset) => asset.unit === "lovelace")?.quantity ?? "0";
1307
+ return sum.checkedAdd(BigNum.new(lovelace));
1308
+ }, BigNum.new("0"));
1309
+ };
1310
+ var remainingLovelace = (quantity, initialUTxOSet) => {
1311
+ const sortedUTxOs = initialUTxOSet.sort(largestLovelaceQuantity);
1312
+ const requestedOutputSet = /* @__PURE__ */ new Map([["lovelace", quantity]]);
1313
+ const selection = selectValue(sortedUTxOs, requestedOutputSet);
1314
+ return selection;
1315
+ };
1316
+ var selectValue = (inputUTxO, outputSet, selection = []) => {
1317
+ if (inputUTxO.length === 0 || enoughValueHasBeenSelected(selection, outputSet)) {
1318
+ return selection;
1319
+ }
1320
+ if (valueCanBeSelected(inputUTxO[0], outputSet)) {
1321
+ return selectValue(inputUTxO.slice(1), outputSet, [
1322
+ ...selection,
1323
+ inputUTxO[0]
1324
+ ]);
1325
+ }
1326
+ return selectValue(inputUTxO.slice(1), outputSet, selection);
1327
+ };
1328
+ var valueCanBeSelected = (utxo, assets) => {
1329
+ return Array.from(assets.keys()).some((unit) => {
1330
+ return utxo.output.amount.find((asset) => asset.unit === unit) !== void 0;
1331
+ });
1332
+ };
1333
+
1334
+ // src/utxo-selection/keepRelevant.ts
1335
+ var keepRelevant = (requiredAssets, inputs, threshold = "5000000") => {
1336
+ const requestedLovelace = BigNum.new(
1337
+ requiredAssets.get("lovelace") ?? "0"
1338
+ ).checkedAdd(BigNum.new(threshold));
1339
+ const multiAsset = inputs.filter(
1340
+ (utxo) => utxo.output.amount.filter((asset) => asset.unit !== "lovelace").some((asset) => requiredAssets.has(asset.unit))
1341
+ );
1342
+ const selectedLovelace = selectedLovelaceQuantity(multiAsset);
1343
+ const lovelace = selectedLovelace.lessThan(requestedLovelace) ? remainingLovelace(
1344
+ requestedLovelace.clampedSub(selectedLovelace).toString(),
1345
+ inputs.filter((input) => {
1346
+ return !multiAsset.some(
1347
+ (selectedUtxo) => selectedUtxo.input.txHash === input.input.txHash && selectedUtxo.input.outputIndex === input.input.outputIndex
1348
+ );
1349
+ })
1350
+ ) : [];
1351
+ return [...lovelace, ...multiAsset];
1352
+ };
1353
+
1354
+ // src/utxo-selection/largestFirst.ts
1355
+ var largestFirst = (lovelace, initialUTxOSet, includeTxFees = false, { maxTxSize, minFeeA, minFeeB } = DEFAULT_PROTOCOL_PARAMETERS) => {
1356
+ const sortedUTxOs = initialUTxOSet.filter((utxo) => multiAssetUTxO(utxo) === false).sort(largestLovelaceQuantity);
1357
+ const maxTxFees2 = BigNum.new(resolveTxFees(maxTxSize, minFeeA, minFeeB));
1358
+ const quantity = includeTxFees ? BigNum.new(lovelace).checkedAdd(maxTxFees2).toString() : lovelace;
1359
+ const requestedOutputSet = /* @__PURE__ */ new Map([["lovelace", quantity]]);
1360
+ const selection = selectValue(sortedUTxOs, requestedOutputSet);
1361
+ return selection;
1362
+ };
1363
+
1364
+ // src/utxo-selection/largestFirstMultiAsset.ts
1365
+ var largestFirstMultiAsset = (requestedOutputSet, initialUTxOSet, includeTxFees = false, parameters = DEFAULT_PROTOCOL_PARAMETERS) => {
1366
+ const sortedMultiAssetUTxOs = initialUTxOSet.filter(multiAssetUTxO).sort(largestLovelaceQuantity);
1367
+ const txFees = maxTxFees(parameters);
1368
+ const lovelace = requestedOutputSet.get("lovelace") ?? "0";
1369
+ const quantity = includeTxFees ? BigNum.new(lovelace).checkedAdd(txFees).toString() : lovelace;
1370
+ requestedOutputSet.set("lovelace", quantity);
1371
+ const selection = selectValue(sortedMultiAssetUTxOs, requestedOutputSet);
1372
+ return selection;
1373
+ };
1374
+
1375
+ // src/utxo-selection/index.ts
1376
+ var UtxoSelection = class {
1377
+ threshold;
1378
+ includeTxFees;
1379
+ constructor(threshold = "5000000", includeTxFees = true) {
1380
+ this.threshold = threshold;
1381
+ this.includeTxFees = includeTxFees;
1382
+ }
1383
+ largestFirst(requiredAssets, inputs) {
1384
+ const lovelaceAmount = requiredAssets.get("lovelace") ?? "0";
1385
+ const requiredAssetWithThreshold = BigInt(lovelaceAmount) + BigInt(this.threshold);
1386
+ return largestFirst(
1387
+ requiredAssetWithThreshold.toString(),
1388
+ inputs,
1389
+ this.includeTxFees
1390
+ );
1391
+ }
1392
+ keepRelevant(requiredAssets, inputs) {
1393
+ return keepRelevant(requiredAssets, inputs, this.threshold);
1394
+ }
1395
+ largestFirstMultiAsset(requiredAssets, inputs) {
1396
+ const lovelaceAmount = requiredAssets.get("lovelace") ?? "0";
1397
+ requiredAssets.set(
1398
+ "lovelace",
1399
+ (BigInt(lovelaceAmount) + BigInt(this.threshold)).toString()
1400
+ );
1401
+ return largestFirstMultiAsset(requiredAssets, inputs, this.includeTxFees);
1402
+ }
1403
+ experimental(requiredAssets, inputs) {
1404
+ return experimentalSelectUtxos(requiredAssets, inputs, this.threshold);
1405
+ }
1406
+ };
1407
+
1408
+ // src/index.ts
1409
+ import { generateMnemonic, mnemonicToEntropy } from "bip39";
1410
+ export {
1411
+ AssetFingerprint,
1412
+ BigNum,
1413
+ CIP68_100,
1414
+ CIP68_222,
1415
+ DEFAULT_PROTOCOL_PARAMETERS,
1416
+ DEFAULT_REDEEMER_BUDGET,
1417
+ DEFAULT_V1_COST_MODEL_LIST,
1418
+ DEFAULT_V2_COST_MODEL_LIST,
1419
+ HARDENED_KEY_START,
1420
+ LANGUAGE_VERSIONS,
1421
+ MeshValue,
1422
+ POLICY_ID_LENGTH,
1423
+ SLOT_CONFIG_NETWORK,
1424
+ SUPPORTED_CLOCKS,
1425
+ SUPPORTED_HANDLES,
1426
+ SUPPORTED_LANGUAGE_VIEWS,
1427
+ SUPPORTED_OGMIOS_LINKS,
1428
+ SUPPORTED_TOKENS,
1429
+ SUPPORTED_WALLETS,
1430
+ UtxoSelection,
1431
+ assetClass,
1432
+ assetName,
1433
+ assocMap,
1434
+ bool,
1435
+ builtinByteString,
1436
+ byteString,
1437
+ bytesToHex,
1438
+ castProtocol,
1439
+ conStr,
1440
+ conStr0,
1441
+ conStr1,
1442
+ conStr2,
1443
+ currencySymbol,
1444
+ dict,
1445
+ emptyTxBuilderBody,
1446
+ experimentalSelectUtxos,
1447
+ fromUTF8,
1448
+ fungibleAssetKeys,
1449
+ generateMnemonic,
1450
+ hashByteString,
1451
+ hexToBytes,
1452
+ hexToString,
1453
+ integer,
1454
+ isNetwork,
1455
+ keepRelevant,
1456
+ largestFirst,
1457
+ largestFirstMultiAsset,
1458
+ list,
1459
+ mAssetClass,
1460
+ mBool,
1461
+ mConStr,
1462
+ mConStr0,
1463
+ mConStr1,
1464
+ mConStr2,
1465
+ mMaybeStakingHash,
1466
+ mOutputReference,
1467
+ mPlutusBSArrayToString,
1468
+ mPubKeyAddress,
1469
+ mScriptAddress,
1470
+ mStringToPlutusBSArray,
1471
+ mTuple,
1472
+ mTxOutRef,
1473
+ mValue,
1474
+ maybeStakingHash,
1475
+ mergeAssets,
1476
+ metadataStandardKeys,
1477
+ metadataToCip68,
1478
+ mnemonicToEntropy,
1479
+ outputReference,
1480
+ parseAssetUnit,
1481
+ plutusBSArrayToString,
1482
+ policyId,
1483
+ posixTime,
1484
+ pubKeyAddress,
1485
+ pubKeyHash,
1486
+ resolveEpochNo,
1487
+ resolveFingerprint,
1488
+ resolveLanguageView,
1489
+ resolveSlotNo,
1490
+ resolveTxFees,
1491
+ royaltiesStandardKeys,
1492
+ scriptAddress,
1493
+ scriptHash,
1494
+ slotToBeginUnixTime,
1495
+ stringToBSArray,
1496
+ stringToHex,
1497
+ toBytes,
1498
+ toUTF8,
1499
+ tokenName,
1500
+ tuple,
1501
+ txOutRef,
1502
+ unixTimeToEnclosingSlot,
1503
+ validityRangeToObj,
1504
+ value
1505
+ };