@meshsdk/core 1.5.19 → 1.5.21
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/core.cjs +1 -1
- package/dist/core.js +61 -55
- package/dist/wallet/app.service.d.ts +16 -15
- package/dist/wallet/mesh.service.d.ts +2 -2
- package/package.json +1 -1
package/dist/core.cjs
CHANGED
|
@@ -5,4 +5,4 @@
|
|
|
5
5
|
`+n+T.join(`,
|
|
6
6
|
`+n)+`
|
|
7
7
|
`+N+"}":"{"+T.join(",")+"}",n=N,P}}typeof t.stringify!="function"&&(t.stringify=function(B,b,w){var v;if(n="",i="",typeof w=="number")for(v=0;v<w;v+=1)i+=" ";else typeof w=="string"&&(i=w);if(l=b,b&&typeof b!="function"&&(typeof b!="object"||typeof b.length!="number"))throw new Error("JSON.stringify");return y("",{"":B})})})()})(Rr);var fe=null;const dn=/(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])/,fn=/(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)/;var gn=function(s){var e={strict:!1,storeAsString:!1,alwaysParseAsBig:!1,useNativeBigInt:!1,protoAction:"error",constructorAction:"error"};if(s!=null){if(s.strict===!0&&(e.strict=!0),s.storeAsString===!0&&(e.storeAsString=!0),e.alwaysParseAsBig=s.alwaysParseAsBig===!0?s.alwaysParseAsBig:!1,e.useNativeBigInt=s.useNativeBigInt===!0?s.useNativeBigInt:!1,typeof s.constructorAction<"u")if(s.constructorAction==="error"||s.constructorAction==="ignore"||s.constructorAction==="preserve")e.constructorAction=s.constructorAction;else throw new Error(`Incorrect value for constructorAction option, must be "error", "ignore" or undefined but passed ${s.constructorAction}`);if(typeof s.protoAction<"u")if(s.protoAction==="error"||s.protoAction==="ignore"||s.protoAction==="preserve")e.protoAction=s.protoAction;else throw new Error(`Incorrect value for protoAction option, must be "error", "ignore" or undefined but passed ${s.protoAction}`)}var t,r,n={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:`
|
|
8
|
-
`,r:"\r",t:" "},i,c=function(k){throw{name:"SyntaxError",message:k,at:t,text:i}},l=function(k){return k&&k!==r&&c("Expected '"+k+"' instead of '"+r+"'"),r=i.charAt(t),t+=1,r},p=function(){var k,N="";for(r==="-"&&(N="-",l("-"));r>="0"&&r<="9";)N+=r,l();if(r===".")for(N+=".";l()&&r>="0"&&r<="9";)N+=r;if(r==="e"||r==="E")for(N+=r,l(),(r==="-"||r==="+")&&(N+=r,l());r>="0"&&r<="9";)N+=r,l();if(k=+N,!isFinite(k))c("Bad number");else return fe==null&&(fe=Ye.exports),N.length>15?e.storeAsString?N:e.useNativeBigInt?BigInt(N):new fe(N):e.alwaysParseAsBig?e.useNativeBigInt?BigInt(k):new fe(k):k},y=function(){var k,N,T="",Q;if(r==='"')for(var R=t;l();){if(r==='"')return t-1>R&&(T+=i.substring(R,t-1)),l(),T;if(r==="\\"){if(t-1>R&&(T+=i.substring(R,t-1)),l(),r==="u"){for(Q=0,N=0;N<4&&(k=parseInt(l(),16),!!isFinite(k));N+=1)Q=Q*16+k;T+=String.fromCharCode(Q)}else if(typeof n[r]=="string")T+=n[r];else break;R=t}}c("Bad string")},B=function(){for(;r&&r<=" ";)l()},b=function(){switch(r){case"t":return l("t"),l("r"),l("u"),l("e"),!0;case"f":return l("f"),l("a"),l("l"),l("s"),l("e"),!1;case"n":return l("n"),l("u"),l("l"),l("l"),null}c("Unexpected '"+r+"'")},w,v=function(){var k=[];if(r==="["){if(l("["),B(),r==="]")return l("]"),k;for(;r;){if(k.push(w()),B(),r==="]")return l("]"),k;l(","),B()}}c("Bad array")},P=function(){var k,N=Object.create(null);if(r==="{"){if(l("{"),B(),r==="}")return l("}"),N;for(;r;){if(k=y(),B(),l(":"),e.strict===!0&&Object.hasOwnProperty.call(N,k)&&c('Duplicate key "'+k+'"'),dn.test(k)===!0?e.protoAction==="error"?c("Object contains forbidden prototype property"):e.protoAction==="ignore"?w():N[k]=w():fn.test(k)===!0?e.constructorAction==="error"?c("Object contains forbidden constructor property"):e.constructorAction==="ignore"?w():N[k]=w():N[k]=w(),B(),r==="}")return l("}"),N;l(","),B()}}c("Bad object")};return w=function(){switch(B(),r){case"{":return P();case"[":return v();case'"':return y();case"-":return p();default:return r>="0"&&r<="9"?p():b()}},function(k,N){var T;return i=k+"",t=0,r=" ",T=w(),B(),r&&c("Syntax error"),typeof N=="function"?function Q(R,X){var $,O=R[X];return O&&typeof O=="object"&&Object.keys(O).forEach(function(M){$=Q(O,M),$!==void 0?O[M]=$:delete O[M]}),N.call(R,X,O)}({"":T},""):T}},mn=gn,qr=Rr.exports.stringify,Vr=mn;zt.exports=function(s){return{parse:Vr(s),stringify:qr}};zt.exports.parse=Vr();zt.exports.stringify=qr;class An{txHex="";txBuilder=Ae();txEvaluationMultiplier=1.1;_protocolParams=mt;txOutput;addingScriptInput=!1;addingPlutusMint=!1;isHydra=!1;meshTxBuilderBody;mintItem;txInQueueItem;collateralQueueItem;refScriptTxInQueueItem;reset=()=>(this.txHex="",this.txBuilder=Ae(),this.txEvaluationMultiplier=1.1,this._protocolParams=mt,this.txOutput=void 0,this.addingScriptInput=!1,this.addingPlutusMint=!1,this.mintItem=void 0,this.txInQueueItem=void 0,this.collateralQueueItem=void 0,this.refScriptTxInQueueItem=void 0,this.meshTxBuilderBody=this.emptyTxBuilderBody(),this);emptyTxBuilderBody=()=>({inputs:[],outputs:[],extraInputs:[],selectionThreshold:0,collaterals:[],requiredSignatures:[],referenceInputs:[],mints:[],changeAddress:"",metadata:[],validityRange:{},certificates:[],signingKey:[]});constructor(){this.meshTxBuilderBody=this.emptyTxBuilderBody()}completeSync=e=>(e?this.meshTxBuilderBody=e:this.queueAllLastItem(),this.serializeTxBody(this.meshTxBuilderBody));completeSigning=()=>{const{signingKey:e}=this.meshTxBuilderBody;return e.length>0&&this.addAllSigningKeys(e),this.txHex};serializeTxBody=e=>{const{inputs:t,outputs:r,extraInputs:n,selectionThreshold:i,collaterals:c,referenceInputs:l,mints:p,changeAddress:y,certificates:B,validityRange:b,requiredSignatures:w,metadata:v}=e;if(this.isHydra?this.protocolParams({minFeeA:0,minFeeB:0,priceMem:0,priceStep:0,collateralPercent:0,coinsPerUTxOSize:"0"}):this.protocolParams({}),n.length>0&&this.addUtxosFrom(n,String(i)),this.removeDuplicateInputs(),this.meshTxBuilderBody.mints.sort((P,k)=>P.policyId.localeCompare(k.policyId)),this.meshTxBuilderBody.inputs.sort((P,k)=>P.txIn.txHash===k.txIn.txHash?P.txIn.txIndex-k.txIn.txIndex:P.txIn.txHash.localeCompare(k.txIn.txHash)),this.addAllInputs(t),this.addAllOutputs(r),this.addAllCollaterals(c),this.addAllReferenceInputs(l),this.addAllMints(p),this.addAllCertificates(B),this.addValidityRange(b),this.addAllRequiredSignatures(w),this.addAllMetadata(v),this.addCostModels(),y){const P=this.meshTxBuilderBody.collaterals.map(T=>{var Q,R;return((R=(Q=T.txIn.amount)==null?void 0:Q.find(X=>X.unit==="lovelace"))==null?void 0:R.quantity)||"0"}).reduce((T,Q)=>T+parseInt(Q),0),k=Math.ceil(this._protocolParams.collateralPercent*Number(Number(this.txBuilder.min_fee().checked_add(a.BigNum.from_str("10000")).to_js_value()))/100);let N=!1;if(P-k>0){const T=a.TransactionOutput.new(a.Address.from_bech32(y),a.Value.new(a.BigNum.from_str(String(k))));P-k>Number(a.min_ada_for_output(T,a.DataCost.new_coins_per_byte(a.BigNum.from_str(this._protocolParams.coinsPerUTxOSize))).to_js_value())&&(this.txBuilder.set_collateral_return(a.TransactionOutput.new(a.Address.from_bech32(y),a.Value.new(a.BigNum.from_str(String(P))))),this.txBuilder.set_total_collateral(a.BigNum.from_str(String(P))),N=!0)}this.addChange(y),N&&this.addCollateralReturn(y)}return this.buildTx(),this};txIn=(e,t,r,n)=>(this.txInQueueItem&&this.queueInput(),this.addingScriptInput?this.txInQueueItem={type:"Script",txIn:{txHash:e,txIndex:t,amount:r,address:n},scriptTxIn:{}}:this.txInQueueItem={type:"PubKey",txIn:{txHash:e,txIndex:t,amount:r,address:n}},this.addingScriptInput=!1,this);txInScript=(e,t="V2")=>{if(!this.txInQueueItem)throw Error("Undefined input");if(this.txInQueueItem.type==="PubKey")throw Error("Datum value attempted to be called a non script input");return this.txInQueueItem.scriptTxIn.scriptSource={type:"Provided",script:{code:e,version:t}},this};txInDatumValue=(e,t="Mesh")=>{if(!this.txInQueueItem)throw Error("Undefined input");if(this.txInQueueItem.type==="PubKey")throw Error("Datum value attempted to be called a non script input");let r=e;return t==="JSON"&&(r=this.castRawDataToJsonString(e)),t==="Mesh"?(this.txInQueueItem.scriptTxIn.datumSource={type:"Provided",data:{type:t,content:e}},this):(this.txInQueueItem.scriptTxIn.datumSource={type:"Provided",data:{type:t,content:r}},this)};txInInlineDatumPresent=()=>{if(!this.txInQueueItem)throw Error("Undefined input");if(this.txInQueueItem.type==="PubKey")throw Error("Inline datum present attempted to be called a non script input");const{txHash:e,txIndex:t}=this.txInQueueItem.txIn;return e&&t.toString()&&(this.txInQueueItem.scriptTxIn.datumSource={type:"Inline",txHash:e,txIndex:t}),this};txInRedeemerValue=(e,t={...Gt},r="Mesh")=>{if(!this.txInQueueItem)throw Error("Undefined input");if(this.txInQueueItem.type==="PubKey")throw Error("Spending tx in reference redeemer attempted to be called a non script input");let n=e;return r==="Mesh"?(this.txInQueueItem.scriptTxIn.redeemer={data:{type:r,content:e},exUnits:t},this):(r==="JSON"&&(n=this.castRawDataToJsonString(e)),this.txInQueueItem.scriptTxIn.redeemer={data:{type:r,content:n},exUnits:t},this)};txOut=(e,t)=>(this.txOutput&&(this.meshTxBuilderBody.outputs.push(this.txOutput),this.txOutput=void 0),this.txOutput={address:e,amount:t},this);txOutDatumHashValue=(e,t="Mesh")=>{let r=e;if(this.txOutput){if(t==="Mesh")return this.txOutput.datum={type:"Hash",data:{type:t,content:r}},this;t==="JSON"&&(r=this.castRawDataToJsonString(e)),this.txOutput.datum={type:"Hash",data:{type:t,content:r}}}return this};txOutInlineDatumValue=(e,t="Mesh")=>{let r=e;if(this.txOutput){if(t==="Mesh")return this.txOutput.datum={type:"Inline",data:{type:t,content:r}},this;t==="JSON"&&(r=this.castRawDataToJsonString(e)),this.txOutput.datum={type:"Inline",data:{type:t,content:r}}}return this};txOutReferenceScript=(e,t="V2")=>(this.txOutput&&(this.txOutput.referenceScript={code:e,version:t}),this);spendingPlutusScriptV2=()=>(this.addingScriptInput=!0,this);spendingTxInReference=(e,t,r,n="V2")=>{if(!this.txInQueueItem)throw Error("Undefined input");if(this.txInQueueItem.type==="PubKey")throw Error("Spending tx in reference attempted to be called a non script input");return this.txInQueueItem.scriptTxIn.scriptSource={type:"Inline",txInInfo:{txHash:e,txIndex:t,spendingScriptHash:r,version:n}},this};spendingReferenceTxInInlineDatumPresent=()=>(this.txInInlineDatumPresent(),this);spendingReferenceTxInRedeemerValue=(e,t={...Gt},r="Mesh")=>(this.txInRedeemerValue(e,t,r),this);readOnlyTxInReference=(e,t)=>(this.meshTxBuilderBody.referenceInputs.push({txHash:e,txIndex:t}),this);mintPlutusScriptV2=()=>(this.addingPlutusMint=!0,this);mint=(e,t,r)=>(this.mintItem&&this.queueMint(),this.mintItem={type:this.addingPlutusMint?"Plutus":"Native",policyId:t,assetName:r,amount:e},this.addingPlutusMint=!1,this);mintingScript=(e,t="V2")=>{if(!this.mintItem)throw Error("Undefined mint");if(!this.mintItem.type)throw Error("Mint information missing");return this.mintItem.scriptSource={type:"Provided",script:{code:e,version:t}},this};mintTxInReference=(e,t,r="V2")=>{if(!this.mintItem)throw Error("Undefined mint");if(!this.mintItem.type)throw Error("Mint information missing");if(this.mintItem.type=="Native")throw Error("Mint tx in reference can only be used on plutus script tokens");if(!this.mintItem.policyId)throw Error("PolicyId information missing from mint asset");return this.mintItem.scriptSource={type:"Reference Script",txHash:e,txIndex:t,version:r},this};mintReferenceTxInRedeemerValue=(e,t={...Gt},r="Mesh")=>{if(!this.mintItem)throw Error("Undefined mint");if(this.mintItem.type=="Native")throw Error("Mint tx in reference can only be used on plutus script tokens");if(this.mintItem.type=="Plutus"){if(!this.mintItem.policyId)throw Error("PolicyId information missing from mint asset");let n=e;if(r==="Mesh")return this.mintItem.redeemer={data:{type:r,content:n},exUnits:t},this;r==="JSON"&&(n=this.castRawDataToJsonString(e)),this.mintItem.redeemer={data:{type:r,content:n},exUnits:t}}return this};mintRedeemerValue=(e,t={...Gt},r="Mesh")=>(this.mintReferenceTxInRedeemerValue(e,t,r),this);requiredSignerHash=e=>(this.meshTxBuilderBody.requiredSignatures.push(e),this);txInCollateral=(e,t,r,n)=>(this.collateralQueueItem&&this.meshTxBuilderBody.collaterals.push(this.collateralQueueItem),this.collateralQueueItem={type:"PubKey",txIn:{txHash:e,txIndex:t,amount:r,address:n}},this);registerPoolCertificate=e=>(this.meshTxBuilderBody.certificates.push({type:"RegisterPool",poolParams:e}),this);registerStakeCertificate=e=>(this.meshTxBuilderBody.certificates.push({type:"RegisterStake",stakeKeyHash:e}),this);delegateStakeCertificate=(e,t)=>(this.meshTxBuilderBody.certificates.push({type:"DelegateStake",stakeKeyHash:e,poolId:t}),this);deregisterStakeCertificate=e=>(this.meshTxBuilderBody.certificates.push({type:"DeregisterStake",stakeKeyHash:e}),this);retirePoolCertificate=(e,t)=>(this.meshTxBuilderBody.certificates.push({type:"RetirePool",poolId:e,epoch:t}),this);changeAddress=e=>(this.meshTxBuilderBody.changeAddress=e,this);invalidBefore=e=>(this.meshTxBuilderBody.validityRange.invalidBefore=e,this);invalidHereafter=e=>(this.meshTxBuilderBody.validityRange.invalidHereafter=e,this);metadataValue=(e,t)=>(this.meshTxBuilderBody.metadata.push({tag:e,metadata:t}),this);protocolParams=e=>{const t={...mt,...e};return this._protocolParams=t,this.txBuilder=Ae(t),this};signingKey=e=>(this.meshTxBuilderBody.signingKey.push(e),this);selectUtxosFrom=(e,t=5e6)=>(this.meshTxBuilderBody.extraInputs=e,this.meshTxBuilderBody.selectionThreshold=t,this);addUtxosFrom=(e,t)=>{const r=this.meshTxBuilderBody.outputs.reduce((i,c)=>(c.amount.forEach(p=>{const{unit:y,quantity:B}=p,b=Number(i.get(y))||0;i.set(y,String(b+Number(B)))}),i),new Map);this.meshTxBuilderBody.inputs.reduce((i,c)=>{const l=c.txIn.amount;return l==null||l.forEach(p=>{const{unit:y,quantity:B}=p,b=Number(i.get(y))||0;i.set(y,String(b-Number(B)))}),i},r),this.meshTxBuilderBody.mints.reduce((i,c)=>{const l={unit:c.policyId+c.assetName,quantity:String(c.amount)},p=Number(i.get(l.unit))||0;return i.set(l.unit,String(p-Number(l.quantity))),i},r),ln(e,r,t).forEach(i=>{const c={type:"PubKey",txIn:{txHash:i.input.txHash,txIndex:i.input.outputIndex,amount:i.output.amount,address:i.output.address}};this.meshTxBuilderBody.inputs.push(c),this.addTxIn(c)})};addAllSigningKeys=e=>{if(e.length>0){const t=a.Vkeywitnesses.new(),r=a.Transaction.from_hex(this.txHex),n=r.body();e.forEach(l=>{const p=l.slice(0,4)==="5820"?l.slice(4):l,y=a.PrivateKey.from_hex(p),B=a.make_vkey_witness(a.hash_transaction(n),y);t.add(B)});const i=r.witness_set();i.set_vkeys(t);const c=a.Transaction.new(n,i,r.auxiliary_data());this.txHex=c.to_hex()}};buildTx=()=>{const e=this.txBuilder.build_tx();this.txHex=e.to_hex()};queueInput=()=>{if(!this.txInQueueItem)throw Error("Undefined input");if(this.txInQueueItem.type==="Script")if(this.txInQueueItem.scriptTxIn){if(!this.txInQueueItem.scriptTxIn.datumSource)throw Error("Script input does not contain datum information");if(!this.txInQueueItem.scriptTxIn.redeemer)throw Error("Script input does not contain redeemer information");if(!this.txInQueueItem.scriptTxIn.scriptSource)throw Error("Script input does not contain script information")}else throw Error("Script input does not contain script, datum, or redeemer information");this.meshTxBuilderBody.inputs.push(this.txInQueueItem),this.txInQueueItem=void 0};queueMint=()=>{if(!this.mintItem)throw Error("Undefined mint");if(!this.mintItem.scriptSource)throw Error("Missing mint script information");this.meshTxBuilderBody.mints.push(this.mintItem),this.mintItem=void 0};makePlutusScriptSource=e=>{const t=a.ScriptHash.from_hex(e.spendingScriptHash),r=a.TransactionInput.new(a.TransactionHash.from_hex(e.txHash),e.txIndex);return a.PlutusScriptSource.new_ref_input_with_lang_ver(t,r,bt[e.version])};removeDuplicateInputs=()=>{const e=this.meshTxBuilderBody.inputs,t=n=>`${n.txHash}#${n.txIndex}`,r=[];for(let n=0;n<e.length;n++){const i=t(e[n].txIn);r.includes(i)?(e.splice(n,1),n--):r.push(i)}};addAllInputs=e=>{for(let t=0;t<e.length;t++){const r=e[t];switch(r.type){case"PubKey":this.addTxIn(r);break;case"Script":this.addScriptTxIn(r);break}}};addTxIn=e=>{this.txBuilder.add_input(a.Address.from_bech32(e.txIn.address),a.TransactionInput.new(a.TransactionHash.from_hex(e.txIn.txHash),e.txIn.txIndex),Qt(e.txIn.amount))};addScriptTxIn=({scriptTxIn:e,txIn:t})=>{let r;const{datumSource:n,scriptSource:i,redeemer:c}=e;if(n.type==="Provided")r=a.DatumSource.new(this.castDataToPlutusData(n.data));else{const y=a.TransactionInput.new(a.TransactionHash.from_hex(n.txHash),n.txIndex);r=a.DatumSource.new_ref_input(y)}let l;i.type=="Inline"?l=this.makePlutusScriptSource(i.txInInfo):l=a.PlutusScriptSource.new(a.PlutusScript.from_hex_with_version(i.script.code,bt[i.script.version]));const p=a.Redeemer.new(a.RedeemerTag.new_spend(),a.BigNum.from_str("0"),this.castDataToPlutusData(c.data),a.ExUnits.new(a.BigNum.from_str(String(c.exUnits.mem)),a.BigNum.from_str(String(c.exUnits.steps))));this.txBuilder.add_plutus_script_input(a.PlutusWitness.new_with_ref(l,r,p),a.TransactionInput.new(a.TransactionHash.from_hex(t.txHash),t.txIndex),Qt(t.amount))};addAllOutputs=e=>{for(let t=0;t<e.length;t++){const r=e[t];this.addOutput(r)}};addOutput=({amount:e,address:t,datum:r,referenceScript:n})=>{const i=Qt(e),c=i.multiasset();if(i.is_zero()&&c===void 0)throw Error("Invalid output amount");let l=a.TransactionOutputBuilder.new().with_address(xt(t));r&&r.type==="Hash"&&(l=l.with_data_hash(a.hash_plutus_data(this.castDataToPlutusData(r.data)))),r&&r.type==="Inline"&&(l=l.with_plutus_data(this.castDataToPlutusData(r.data))),n&&(l=l.with_script_ref(a.ScriptRef.new_plutus_script(a.PlutusScript.from_hex_with_version(n.code,bt[n.version]))));const p=l.next();if(c){const y=i.coin().is_zero()?p.with_asset_and_min_required_coin_by_utxo_cost(c,Te(this._protocolParams.coinsPerUTxOSize)).build():p.with_coin_and_asset(i.coin(),c).build();this.txBuilder.add_output(y)}else{const y=p.with_coin(i.coin()).build();this.txBuilder.add_output(y)}};addAllCollaterals=e=>{const t=a.TxInputsBuilder.new();for(let r=0;r<e.length;r++){const n=e[r];this.addCollateral(t,n)}this.txBuilder.set_collateral(t)};addCollateral=(e,t)=>{e.add_input(a.Address.from_bech32(t.txIn.address),a.TransactionInput.new(a.TransactionHash.from_hex(t.txIn.txHash),t.txIn.txIndex),Qt(t.txIn.amount))};addCollateralReturn=e=>{var r;const t=(r=this.txBuilder.get_fee_if_set())==null?void 0:r.to_js_value();if(t){const n=Math.ceil(this._protocolParams.collateralPercent*Number(t)/100);this.txBuilder.set_total_collateral_and_return(a.BigNum.from_str(String(n)),a.Address.from_bech32(e))}};addAllReferenceInputs=e=>{e.forEach(t=>{this.addReferenceInput(t)})};addReferenceInput=({txHash:e,txIndex:t})=>{const r=a.TransactionInput.new(a.TransactionHash.from_hex(e),t);this.txBuilder.add_reference_input(r)};addAllMints=e=>{const t=a.MintBuilder.new();let r=0;for(let n=0;n<e.length;n++){const i=e[n];if(!i.scriptSource)throw Error("Mint script is expected to be provided");if(i.type==="Plutus"){if(!i.redeemer)throw Error("Missing mint redeemer information");this.addPlutusMint(t,i,r),r++}else i.type==="Native"&&this.addNativeMint(t,i)}this.txBuilder.set_mint_builder(t)};addPlutusMint=(e,{redeemer:t,policyId:r,scriptSource:n,assetName:i,amount:c},l)=>{const p=a.Redeemer.new(a.RedeemerTag.new_mint(),a.BigNum.from_str(String(l)),this.castDataToPlutusData(t.data),a.ExUnits.new(a.BigNum.from_str(String(t.exUnits.mem)),a.BigNum.from_str(String(t.exUnits.steps)))),y=n.type==="Reference Script"?a.PlutusScriptSource.new_ref_input_with_lang_ver(a.ScriptHash.from_hex(r),a.TransactionInput.new(a.TransactionHash.from_hex(n.txHash),n.txIndex),bt[n.version]):a.PlutusScriptSource.new(a.PlutusScript.from_hex_with_version(n.script.code,bt[n.script.version]));e.add_asset(a.MintWitness.new_plutus_script(y,p),a.AssetName.new(Buffer.from(i,"hex")),a.Int.from_str(c))};addNativeMint=(e,{scriptSource:t,assetName:r,amount:n})=>{if(t.type==="Reference Script")throw Error("Native mint cannot have reference script");e.add_asset(a.MintWitness.new_native_script(a.NativeScript.from_hex(t.script.code)),a.AssetName.new(Buffer.from(r,"hex")),a.Int.from_str(n))};decimalToFraction(e){const t=10**e.toString().split(".")[1].length;return[e*t,t]}toPoolParams=e=>{const t=this.decimalToFraction(e.margin),r=a.Relays.new();e.relays.forEach(c=>{r.add(Ur(c))});const n=a.RewardAddress.from_address(a.Address.from_bech32(e.rewardAddress));if(n===void 0)throw new Error("Reward address is invalid");const i=a.Ed25519KeyHashes.new();return e.owners.forEach(c=>{i.add(a.Ed25519KeyHash.from_hex(c))}),a.PoolParams.new(a.Ed25519KeyHash.from_hex(e.operator),a.VRFKeyHash.from_hex(e.VRFKeyHash),a.BigNum.from_str(e.pledge),a.BigNum.from_str(e.cost),a.UnitInterval.new(a.BigNum.from_str(t[0].toString()),a.BigNum.from_str(t[1].toString())),n,i,r,e.metadata?a.PoolMetadata.from_json(zt.exports.stringify(e.metadata)):void 0)};addCertificate=(e,t)=>{switch(t.type){case"RegisterPool":e.add(a.Certificate.new_pool_registration(a.PoolRegistration.new(this.toPoolParams(t.poolParams))));break;case"RegisterStake":e.add(a.Certificate.new_stake_registration(a.StakeRegistration.new(a.StakeCredential.from_keyhash(a.Ed25519KeyHash.from_hex(t.stakeKeyHash)))));break;case"DelegateStake":e.add(a.Certificate.new_stake_delegation(a.StakeDelegation.new(a.StakeCredential.from_keyhash(a.Ed25519KeyHash.from_hex(t.stakeKeyHash)),t.poolId.startsWith("pool")?a.Ed25519KeyHash.from_bech32(t.poolId):a.Ed25519KeyHash.from_hex(t.poolId))));break;case"DeregisterStake":e.add(a.Certificate.new_stake_deregistration(a.StakeDeregistration.new(a.StakeCredential.from_keyhash(a.Ed25519KeyHash.from_hex(t.stakeKeyHash)))));break;case"RetirePool":e.add(a.Certificate.new_pool_retirement(a.PoolRetirement.new(t.poolId.startsWith("pool")?a.Ed25519KeyHash.from_bech32(t.poolId):a.Ed25519KeyHash.from_hex(t.poolId),t.epoch)))}};queueAllLastItem=()=>{this.txOutput&&(this.meshTxBuilderBody.outputs.push(this.txOutput),this.txOutput=void 0),this.txInQueueItem&&this.queueInput(),this.collateralQueueItem&&(this.meshTxBuilderBody.collaterals.push(this.collateralQueueItem),this.collateralQueueItem=void 0),this.mintItem&&this.queueMint()};addAllCertificates=e=>{const t=a.Certificates.new();e.forEach(r=>{this.addCertificate(t,r)}),this.txBuilder.set_certs(t)};addCostModels=()=>{this.txBuilder.calc_script_data_hash(a.TxBuilderConstants.plutus_vasil_cost_models())};addChange=e=>{this.txBuilder.add_change_if_needed(a.Address.from_bech32(e))};addValidityRange=({invalidBefore:e,invalidHereafter:t})=>{e&&this.txBuilder.set_validity_start_interval_bignum(a.BigNum.from_str(e.toString())),t&&this.txBuilder.set_ttl_bignum(a.BigNum.from_str(t.toString()))};addAllRequiredSignatures=e=>{e.forEach(t=>{this.txBuilder.add_required_signer(a.Ed25519KeyHash.from_hex(t))})};addAllMetadata=e=>{e.forEach(({tag:t,metadata:r})=>{this.txBuilder.add_json_metadatum(a.BigNum.from_str(t),zt.exports.stringify(r))})};updateRedeemer=(e,t)=>{t.forEach(r=>{switch(r.tag){case"SPEND":{const n=e.inputs[r.index];n.type=="Script"&&n.scriptTxIn.redeemer&&(n.scriptTxIn.redeemer.exUnits.mem=Math.floor(r.budget.mem*this.txEvaluationMultiplier),n.scriptTxIn.redeemer.exUnits.steps=Math.floor(r.budget.steps*this.txEvaluationMultiplier));break}case"MINT":{const n=e.mints[r.index];n.type=="Plutus"&&n.redeemer&&(n.redeemer.exUnits.mem=Math.floor(r.budget.mem*this.txEvaluationMultiplier),n.redeemer.exUnits.steps=Math.floor(r.budget.steps*this.txEvaluationMultiplier));break}}})};castRawDataToJsonString=e=>typeof e=="object"?zt.exports.stringify(e):e;castDataToPlutusData=({type:e,content:t})=>e==="Mesh"?Ot(t):e==="CBOR"?a.PlutusData.from_hex(t):a.PlutusData.from_json(t,a.PlutusDatumSchema.DetailedSchema)}class pn extends An{_fetcher;_submitter;_evaluator;queriedTxHashes=new Set;queriedUTxOs={};constructor({fetcher:e,submitter:t,evaluator:r,isHydra:n=!1}){super(),e&&(this._fetcher=e),t&&(this._submitter=t),r&&(this._evaluator=r),n&&(this.isHydra=!0)}complete=async e=>{e?this.meshTxBuilderBody=e:this.queueAllLastItem();const{inputs:t,collaterals:r}=this.meshTxBuilderBody,n=[...t,...r].filter(i=>!this.isInputComplete(i));if(await this.queryAllTxInfo(n),n.forEach(i=>{this.completeTxInformation(i)}),this.completeSync(e),this._evaluator){const i=await this._evaluator.evaluateTx(this.txHex);this.updateRedeemer(this.meshTxBuilderBody,i),this.completeSync(e)}return this};submitTx=async e=>{var r;return await((r=this._submitter)==null?void 0:r.submitTx(e))};getUTxOInfo=async e=>{var r;let t=[];this.queriedTxHashes.has(e)||(this.queriedTxHashes.add(e),t=await((r=this._fetcher)==null?void 0:r.fetchUTxOs(e))||[],this.queriedUTxOs[e]=t)};queryAllTxInfo=e=>{var r;const t=[];if(e.length>0&&!this._fetcher)throw Error("Transaction information is incomplete while no fetcher instance is provided");for(let n=0;n<e.length;n++){const i=e[n];this.isInputInfoComplete(i)||t.push(this.getUTxOInfo(i.txIn.txHash)),i.type==="Script"&&((r=i.scriptTxIn.scriptSource)==null?void 0:r.type)==="Inline"&&!this.isRefScriptInfoComplete(i)&&t.push(this.getUTxOInfo(i.scriptTxIn.scriptSource.txInInfo.txHash))}return Promise.all(t)};completeTxInformation=e=>{var t;if(!this.isInputInfoComplete(e)){const r=this.queriedUTxOs[e.txIn.txHash],n=r==null?void 0:r.find(l=>l.input.outputIndex===e.txIn.txIndex),i=n==null?void 0:n.output.amount,c=n==null?void 0:n.output.address;if(!i||i.length===0)throw Error(`Couldn't find value information for ${e.txIn.txHash}#${e.txIn.txIndex}`);if(e.txIn.amount=i,e.type==="PubKey"){if(!c||c==="")throw Error(`Couldn't find address information for ${e.txIn.txHash}#${e.txIn.txIndex}`);e.txIn.address=c}}if(e.type==="Script"&&((t=e.scriptTxIn.scriptSource)==null?void 0:t.type)=="Inline"&&!this.isRefScriptInfoComplete(e)){const r=e.scriptTxIn.scriptSource.txInInfo,i=this.queriedUTxOs[r.txHash].find(c=>c.input.outputIndex===r.txIndex);if(!i)throw Error(`Couldn't find script reference utxo for ${r.txHash}#${r.txIndex}`);r.spendingScriptHash=i==null?void 0:i.output.scriptHash}};isInputComplete=e=>e.type==="PubKey"?this.isInputInfoComplete(e):e.type==="Script"?this.isInputInfoComplete(e)&&this.isRefScriptInfoComplete(e):!0;isInputInfoComplete=e=>{const{amount:t,address:r}=e.txIn;return!(e.type==="PubKey"&&(!t||!r)||e.type==="Script"&&!t)};isRefScriptInfoComplete=e=>{var r;const{scriptSource:t}=e.scriptTxIn;return!((t==null?void 0:t.type)==="Inline"&&!((r=t.txInInfo)!=null&&r.spendingScriptHash))}}class rt{_networkId;_encryptedSecret;constructor(e,t){this._networkId=e,this._encryptedSecret=t}getAccount(e,t){return this.accountContext(e,t,(r,n)=>{const i=fr(this._networkId,r.to_public().hash(),n.to_public().hash()).to_address().to_bech32(),c=gr(this._networkId,r.to_public().hash()).to_address().to_bech32(),l=Ne(this._networkId,n.to_public().hash()).to_address().to_bech32();return{baseAddress:i,enterpriseAddress:c,rewardAddress:l}})}signData(e,t,r,n){try{return this.accountContext(e,t,(i,c)=>{const l={payload:n},p={address:rt.resolveAddress(this._networkId,r,i,c),key:r.startsWith("stake")?c:i},{coseSign1:y,coseKey:B}=as(l,p);return{signature:y,key:B}})}catch(i){throw new Error(`An error occurred during signData: ${i}.`)}}signTx(e,t,r,n,i){try{const c=Tr(Fr(n));return this.accountContext(e,t,(l,p)=>{const y=a.Vkeywitnesses.new();return rt.resolveSigners(n,r,l.to_public().hash().to_hex()).forEach(b=>{if(b===l.to_public().hash().to_hex())y.add(a.make_vkey_witness(c,l));else if(b===p.to_public().hash().to_hex())y.add(a.make_vkey_witness(c,p));else if(i===!1)throw new Error(`Missing key witness for: ${b}`)}),y})}catch(c){throw new Error(`An error occurred during signTx: ${c}.`)}}static encryptMnemonic(e,t){const r=Qe.mnemonicToEntropy(e.join(" ")),n=Kr(r),i=lt(n.as_bytes());return n.free(),rt.encrypt(i,t)}static encryptPrivateKey(e,t){const r=a.Bip32PrivateKey.from_bech32(e),n=lt(r.as_bytes());return r.free(),rt.encrypt(n,t)}static encryptSigningKeys(e,t,r){const n=rt.encrypt(e.slice(4),r),i=rt.encrypt(t.slice(4),r);return[n,i]}static generateMnemonic(e=256){return Qe.generateMnemonic(e).split(" ")}accountContext(e,t,r){const{paymentKey:n,stakeKey:i}=rt.resolveKeys(e,t,this._encryptedSecret),c=r(n,i);return n.free(),i.free(),c}static decrypt(e,t){try{return a.decrypt_with_password(dt(t),e)}catch{throw new Error("The password is incorrect.")}}static encrypt(e,t){const r=pr.customAlphabet("0123456789abcdef"),n=r(64),i=r(24);return a.encrypt_with_password(dt(t),n,i,e)}static resolveAddress(e,t,r,n){const i=[fr(e,r.to_public().hash(),n.to_public().hash()),gr(e,r.to_public().hash()),Ne(e,n.to_public().hash())].find(c=>c.to_address().to_bech32()===t);if(i!==void 0)return i.to_address();throw new Error(`Address: ${t} doesn't belong to this account.`)}static resolveKeys(e,t,r){if(typeof r=="string"){const c=rt.decrypt(r,t);return Ts(c,e)}const n=rt.decrypt(r[0],t),i=rt.decrypt(r[1],t);return{paymentKey:a.PrivateKey.from_hex(n),stakeKey:a.PrivateKey.from_hex(i)}}static resolveSigners(e,t,r){const n=l=>{const p=(T,Q=[],R=0)=>{var O,M,W,Z,D;if(T===void 0||R>=T.len())return Q;const X=T.get(R),$=new Array;switch(X.kind()){case a.CertificateKind.StakeDeregistration:{const F=(O=X.as_stake_deregistration())==null?void 0:O.stake_credential(),q=(F==null?void 0:F.kind())===a.StakeCredKind.Key?F.to_keyhash():void 0;q&&$.push(q.to_hex());break}case a.CertificateKind.StakeDelegation:{const F=(M=X.as_stake_delegation())==null?void 0:M.stake_credential(),q=(F==null?void 0:F.kind())===a.StakeCredKind.Key?F.to_keyhash():void 0;q&&$.push(q.to_hex());break}case a.CertificateKind.PoolRegistration:{const F=(W=X.as_pool_registration())==null?void 0:W.pool_params().pool_owners();$.push(...B(F));break}case a.CertificateKind.PoolRetirement:{const F=(Z=X.as_pool_retirement())==null?void 0:Z.pool_keyhash();F&&$.push(F.to_hex());break}case a.CertificateKind.MoveInstantaneousRewardsCert:{const F=(D=X.as_move_instantaneous_rewards_cert())==null?void 0:D.move_instantaneous_reward().as_to_stake_creds();if(F)for(let q=0;q<F.len();q+=1){const j=F.keys().get(q),nt=j.kind()===a.StakeCredKind.Key?j.to_keyhash():void 0;nt&&$.push(nt.to_hex())}break}}return p(T,[...Q,...$],R+1)},y=(T,Q=[],R=0)=>{if(T===void 0||R>=T.len())return Q;const X=T.get(R).index(),$=T.get(R).transaction_id(),O=t.find(M=>M.input.outputIndex===X&&M.input.txHash===$.to_hex())!==void 0?r:"OUR_PRINCESS_IS_IN_ANOTHER_CASTLE";return y(T,[...Q,O],R+1)},B=(T,Q=[],R=0)=>T===void 0||R>=T.len()?Q:B(T,[...Q,T.get(R).to_hex()],R+1),b=(T,Q=[],R=0)=>{if(T===void 0||R>=T.len())return Q;const X=T.keys().get(R).payment_cred(),$=X.kind()===a.StakeCredKind.Key?X.to_keyhash():void 0;return b(T,$?[...Q,$.to_hex()]:Q,R+1)},w=l.certs(),v=l.collateral(),P=l.inputs(),k=l.required_signers(),N=l.withdrawals();return[...p(w),...y(v),...y(P),...B(k),...b(N)]},i=l=>{const p=(B,b=[])=>{var w,v,P,k;if(B)for(let N=0;N<B.len();N+=1){const T=B.get(N);switch(T.kind()){case a.NativeScriptKind.ScriptPubkey:{const Q=(w=T.as_script_pubkey())==null?void 0:w.addr_keyhash().to_hex();return Q?[...b,Q]:b}case a.NativeScriptKind.ScriptAll:return p((v=T.as_script_all())==null?void 0:v.native_scripts(),b);case a.NativeScriptKind.ScriptAny:return p((P=T.as_script_any())==null?void 0:P.native_scripts(),b);case a.NativeScriptKind.ScriptNOfK:return p((k=T.as_script_n_of_k())==null?void 0:k.native_scripts(),b)}}return b},y=l.native_scripts();return[...p(y)]},c=yt(e);return new Set([...n(c.body()),...i(c.witness_set())])}}const It="MARI0TIME";class pe{_fetcher;_submitter;_wallet;constructor(e){switch(this._fetcher=e.fetcher,this._submitter=e.submitter,e.key.type){case"mnemonic":this._wallet=new rt(e.networkId,rt.encryptMnemonic(e.key.words,It));break;case"root":this._wallet=new rt(e.networkId,rt.encryptPrivateKey(e.key.bech32,It));break;case"cli":this._wallet=new rt(e.networkId,rt.encryptSigningKeys(e.key.payment,e.key.stake??"f0".repeat(34),It))}}getBaseAddress(e=0){return this._wallet.getAccount(e,It).baseAddress}getPaymentAddress(e=0){return this._wallet.getAccount(e,It).enterpriseAddress}getRewardAddress(e=0){return this._wallet.getAccount(e,It).rewardAddress}getUsedAddress(e=0){const t=this._wallet.getAccount(e,It);return xt(t.enterpriseAddress)}getUsedCollateral(e=mt.maxCollateralInputs){throw new Error("getUsedCollateral not implemented.")}async getUsedUTxOs(e=0){const t=this._wallet.getAccount(e,It);return(await this._fetcher.fetchAddressUTxOs(t.enterpriseAddress)).map(n=>_t(n))}signData(e,t,r=0){try{return this._wallet.signData(r,It,e,t)}catch(n){throw new Error(`[AppWallet] An error occurred during signData: ${n}.`)}}async signTx(e,t=!1,r=0){try{const n=this._wallet.getAccount(r,It),i=await this._fetcher.fetchAddressUTxOs(n.enterpriseAddress),c=this._wallet.signTx(r,It,i,e,t),l=yt(e),p=l.witness_set(),y=Ue(p,c);return p.set_vkeys(y),a.Transaction.new(l.body(),p,l.auxiliary_data()).to_hex()}catch(n){throw new Error(`[AppWallet] An error occurred during signTx: ${n}.`)}}async signTxs(e,t){return console.log("unimplemented",e,t),[]}submitTx(e){return this._submitter.submitTx(e)}static brew(e=256){return rt.generateMnemonic(e)}async getUtxos(){return await this.getUsedUTxOs()}async getCollateral(){return(await this.getUsedUTxOs())[0]}async getUsedAddresses(){return console.log(1,await this.getPaymentAddress()),[await this.getPaymentAddress()]}}class ye{_walletInstance;_walletName;walletInstance;constructor(e,t){this._walletInstance=e,this._walletName=t,this.walletInstance={...e}}static getInstalledWallets(){return window.cardano===void 0?[]:We.filter(e=>window.cardano[e]!==void 0).map(e=>({name:window.cardano[e].name,icon:window.cardano[e].icon,version:window.cardano[e].apiVersion}))}static async enable(e){try{const t=await ye.resolveInstance(e);if(t!==void 0)return new ye(t,e);throw new Error(`Couldn't create an instance of wallet: ${e}`)}catch(t){throw new Error(`[BrowserWallet] An error occurred during enable: ${JSON.stringify(t)}.`)}}async getBalance(){const e=await this._walletInstance.getBalance();return Mr(Hs(e))}async getChangeAddress(){const e=await this._walletInstance.getChangeAddress();return Lt(e).to_bech32()}async getCollateral(e=mt.maxCollateralInputs){return(await this.getUsedCollateral(e)).map(r=>ie(r))}getNetworkId(){return this._walletInstance.getNetworkId()}async getRewardAddresses(){return(await this._walletInstance.getRewardAddresses()).map(t=>Lt(t).to_bech32())}async getUnusedAddresses(){return(await this._walletInstance.getUnusedAddresses()).map(t=>Lt(t).to_bech32())}async getUsedAddresses(){return(await this._walletInstance.getUsedAddresses()).map(t=>Lt(t).to_bech32())}async getUtxos(e=void 0){return(await this.getUsedUTxOs(e)).map(r=>ie(r))}signData(e,t){const r=xt(e).to_hex();return this._walletInstance.signData(r,dt(t))}async signTx(e,t=!1){try{const r=yt(e),n=r.witness_set(),i=await this._walletInstance.signTx(e,t),c=hr(i).vkeys()??a.Vkeywitnesses.new(),l=Ue(n,c);return n.set_vkeys(l),lt(a.Transaction.new(r.body(),n,r.auxiliary_data()).to_bytes())}catch(r){throw new Error(`[BrowserWallet] An error occurred during signTx: ${JSON.stringify(r)}.`)}}async signTxs(e,t=!1){let r;switch(this._walletName){case"Typhon Wallet":this._walletInstance.signTxs&&(r=await this._walletInstance.signTxs(e,t));break;default:this._walletInstance.signTxs?r=await this._walletInstance.signTxs(e.map(i=>({cbor:i,partialSign:t}))):this._walletInstance.experimental.signTxs&&(r=await this._walletInstance.experimental.signTxs(e.map(i=>({cbor:i,partialSign:t}))));break}if(!r)throw new Error("Wallet does not support signTxs");const n=[];for(let i=0;i<r.length;i++){const c=yt(e[i]),l=c.witness_set(),p=hr(r[i]).vkeys()??a.Vkeywitnesses.new(),y=Ue(l,p);l.set_vkeys(y);const B=lt(a.Transaction.new(c.body(),l,c.auxiliary_data()).to_bytes());n.push(B)}return n}submitTx(e){return this._walletInstance.submitTx(e)}async getUsedAddress(){const e=await this._walletInstance.getUsedAddresses();return Lt(e[0])}async getUsedCollateral(e=mt.maxCollateralInputs){return(await this._walletInstance.experimental.getCollateral()??[]).map(r=>lr(r)).slice(0,e)}async getUsedUTxOs(e=void 0){const t=e?Qt(e).to_hex():void 0;return(await this._walletInstance.getUtxos(t)??[]).map(n=>lr(n))}async getAssets(){return(await this.getBalance()).filter(t=>t.unit!=="lovelace").map(t=>{const r=t.unit.slice(0,ht),n=t.unit.slice(ht),i=Le(r,n);return{unit:t.unit,policyId:r,assetName:Ve(n),fingerprint:i,quantity:t.quantity}})}async getLovelace(){const t=(await this.getBalance()).find(r=>r.unit==="lovelace");return t!==void 0?t.quantity:"0"}async getPolicyIdAssets(e){return(await this.getAssets()).filter(r=>r.policyId===e)}async getPolicyIds(){const e=await this.getBalance();return Array.from(new Set(e.map(t=>t.unit.slice(0,ht)))).filter(t=>t!=="lovelace")}static resolveInstance(e){if(window.cardano===void 0)return;const t=We.map(r=>window.cardano[r]).filter(r=>r!==void 0).find(r=>r.name.toLowerCase()===e.toLowerCase());return t==null?void 0:t.enable()}}class In{_wallet;_network;constructor(e){switch(this._network=e.networkId,e.key.type){case"root":this._wallet=new pe({networkId:e.networkId,fetcher:e.fetcher,submitter:e.submitter,key:{type:"root",bech32:e.key.bech32}});break;case"cli":this._wallet=new pe({networkId:e.networkId,fetcher:e.fetcher,submitter:e.submitter,key:{type:"cli",payment:e.key.payment}});break;case"mnemonic":this._wallet=new pe({networkId:e.networkId,fetcher:e.fetcher,submitter:e.submitter,key:{type:"mnemonic",words:e.key.words}});break}}async getBalance(){const e=await this.getUtxos(),t=new Map;return e.map(n=>{n.output.amount.map(i=>{const c=i.unit,l=Number(i.quantity);if(t.has(c)){const p=t.get(c);t.set(c,p+l)}else t.set(c,l)})}),Array.from(t,([n,i])=>({unit:n,quantity:i.toString()}))}getChangeAddress(){return this._wallet.getPaymentAddress()}async getCollateral(){const t=(await this.getUtxos()).filter(r=>r.output.amount.length===1&&r.output.amount[0].unit==="lovelace");t.sort((r,n)=>Number(r.output.amount[0].quantity)-Number(n.output.amount[0].quantity));for(const r of t)if(Number(r.output.amount[0].quantity)>=5e6)return[r];return[]}getNetworkId(){return this._network}async getRewardAddresses(){return[await this._wallet.getRewardAddress()]}getUnusedAddresses(){return[this.getChangeAddress()]}async getUsedAddresses(){return[this.getChangeAddress()]}async getUtxos(){return(await this.getUsedUTxOs()).map(t=>ie(t))}signData(e){return this._wallet.signData(this.getChangeAddress(),e)}async signTx(e,t=!1){return await this._wallet.signTx(e,t)}async signTxs(e,t=!1){const r=[];for(const n of e){const i=await this.signTx(n,t);r.push(i)}return r}async submitTx(e){return await this._wallet.submitTx(e)}getUsedAddress(){return this._wallet.getUsedAddress()}async getUsedCollateral(){return(await this.getCollateral()).map(r=>_t(r))}async getUsedUTxOs(){return await this._wallet.getUtxos()}async getAssets(){return(await this.getBalance()).filter(t=>t.unit!=="lovelace").map(t=>{const r=t.unit.slice(0,ht),n=t.unit.slice(ht),i=Le(r,n);return{unit:t.unit,policyId:r,assetName:Ve(n),fingerprint:i,quantity:t.quantity}})}async getLovelace(){const t=(await this.getBalance()).find(r=>r.unit==="lovelace");return t!==void 0?t.quantity:"0"}async getPolicyIdAssets(e){return(await this.getAssets()).filter(r=>r.policyId===e)}async getPolicyIds(){const e=await this.getBalance();return Array.from(new Set(e.map(t=>t.unit.slice(0,ht)))).filter(t=>t!=="lovelace")}async createCollateral(){const t=await new exports.Transaction({initiator:this._wallet}).sendLovelace(this.getChangeAddress(),"5000000").build(),r=await this.signTx(t);return await this.submitTx(r)}static brew(e=!1,t=256){const r=rt.generateMnemonic(t);return e?Hr(r):r}}exports.AppWallet=pe;exports.BlockfrostProvider=en;exports.BrowserWallet=ye;exports.EmbeddedWallet=rt;exports.ForgeScript=cn;exports.InfuraProvider=rn;exports.KoiosProvider=sn;exports.MaestroProvider=an;exports.MeshTxBuilder=pn;exports.MeshWallet=In;exports.OgmiosProvider=nn;exports.YaciProvider=on;exports.checkSignature=os;exports.generateNonce=Xs;exports.isNetwork=Ir;exports.keepRelevant=_r;exports.largestFirst=ts;exports.largestFirstMultiAsset=yr;exports.mergeAssets=zr;exports.parseAssetUnit=kt;exports.parseHttpError=E;exports.readPlutusData=Zs;exports.readTransaction=tn;exports.resolveDataHash=qs;exports.resolveEpochNo=Vs;exports.resolveFingerprint=Le;exports.resolveLanguageView=Ls;exports.resolveNativeScriptAddress=Gs;exports.resolveNativeScriptHash=Ys;exports.resolvePaymentKeyHash=qt;exports.resolvePlutusScriptAddress=$s;exports.resolvePlutusScriptHash=zs;exports.resolvePoolId=Ws;exports.resolvePrivateKey=Hr;exports.resolveRewardAddress=oe;exports.resolveScriptRef=Js;exports.resolveSlotNo=js;exports.resolveStakeKeyHash=Yt;exports.resolveTxFees=Ge;exports.resolveTxHash=Fr;
|
|
8
|
+
`,r:"\r",t:" "},i,c=function(k){throw{name:"SyntaxError",message:k,at:t,text:i}},l=function(k){return k&&k!==r&&c("Expected '"+k+"' instead of '"+r+"'"),r=i.charAt(t),t+=1,r},p=function(){var k,N="";for(r==="-"&&(N="-",l("-"));r>="0"&&r<="9";)N+=r,l();if(r===".")for(N+=".";l()&&r>="0"&&r<="9";)N+=r;if(r==="e"||r==="E")for(N+=r,l(),(r==="-"||r==="+")&&(N+=r,l());r>="0"&&r<="9";)N+=r,l();if(k=+N,!isFinite(k))c("Bad number");else return fe==null&&(fe=Ye.exports),N.length>15?e.storeAsString?N:e.useNativeBigInt?BigInt(N):new fe(N):e.alwaysParseAsBig?e.useNativeBigInt?BigInt(k):new fe(k):k},y=function(){var k,N,T="",Q;if(r==='"')for(var R=t;l();){if(r==='"')return t-1>R&&(T+=i.substring(R,t-1)),l(),T;if(r==="\\"){if(t-1>R&&(T+=i.substring(R,t-1)),l(),r==="u"){for(Q=0,N=0;N<4&&(k=parseInt(l(),16),!!isFinite(k));N+=1)Q=Q*16+k;T+=String.fromCharCode(Q)}else if(typeof n[r]=="string")T+=n[r];else break;R=t}}c("Bad string")},B=function(){for(;r&&r<=" ";)l()},b=function(){switch(r){case"t":return l("t"),l("r"),l("u"),l("e"),!0;case"f":return l("f"),l("a"),l("l"),l("s"),l("e"),!1;case"n":return l("n"),l("u"),l("l"),l("l"),null}c("Unexpected '"+r+"'")},w,v=function(){var k=[];if(r==="["){if(l("["),B(),r==="]")return l("]"),k;for(;r;){if(k.push(w()),B(),r==="]")return l("]"),k;l(","),B()}}c("Bad array")},P=function(){var k,N=Object.create(null);if(r==="{"){if(l("{"),B(),r==="}")return l("}"),N;for(;r;){if(k=y(),B(),l(":"),e.strict===!0&&Object.hasOwnProperty.call(N,k)&&c('Duplicate key "'+k+'"'),dn.test(k)===!0?e.protoAction==="error"?c("Object contains forbidden prototype property"):e.protoAction==="ignore"?w():N[k]=w():fn.test(k)===!0?e.constructorAction==="error"?c("Object contains forbidden constructor property"):e.constructorAction==="ignore"?w():N[k]=w():N[k]=w(),B(),r==="}")return l("}"),N;l(","),B()}}c("Bad object")};return w=function(){switch(B(),r){case"{":return P();case"[":return v();case'"':return y();case"-":return p();default:return r>="0"&&r<="9"?p():b()}},function(k,N){var T;return i=k+"",t=0,r=" ",T=w(),B(),r&&c("Syntax error"),typeof N=="function"?function Q(R,X){var $,O=R[X];return O&&typeof O=="object"&&Object.keys(O).forEach(function(M){$=Q(O,M),$!==void 0?O[M]=$:delete O[M]}),N.call(R,X,O)}({"":T},""):T}},mn=gn,qr=Rr.exports.stringify,Vr=mn;zt.exports=function(s){return{parse:Vr(s),stringify:qr}};zt.exports.parse=Vr();zt.exports.stringify=qr;class An{txHex="";txBuilder=Ae();txEvaluationMultiplier=1.1;_protocolParams=mt;txOutput;addingScriptInput=!1;addingPlutusMint=!1;isHydra=!1;meshTxBuilderBody;mintItem;txInQueueItem;collateralQueueItem;refScriptTxInQueueItem;reset=()=>(this.txHex="",this.txBuilder=Ae(),this.txEvaluationMultiplier=1.1,this._protocolParams=mt,this.txOutput=void 0,this.addingScriptInput=!1,this.addingPlutusMint=!1,this.mintItem=void 0,this.txInQueueItem=void 0,this.collateralQueueItem=void 0,this.refScriptTxInQueueItem=void 0,this.meshTxBuilderBody=this.emptyTxBuilderBody(),this);emptyTxBuilderBody=()=>({inputs:[],outputs:[],extraInputs:[],selectionThreshold:0,collaterals:[],requiredSignatures:[],referenceInputs:[],mints:[],changeAddress:"",metadata:[],validityRange:{},certificates:[],signingKey:[]});constructor(){this.meshTxBuilderBody=this.emptyTxBuilderBody()}completeSync=e=>(e?this.meshTxBuilderBody=e:this.queueAllLastItem(),this.serializeTxBody(this.meshTxBuilderBody));completeSigning=()=>{const{signingKey:e}=this.meshTxBuilderBody;return e.length>0&&this.addAllSigningKeys(e),this.txHex};serializeTxBody=e=>{const{inputs:t,outputs:r,extraInputs:n,selectionThreshold:i,collaterals:c,referenceInputs:l,mints:p,changeAddress:y,certificates:B,validityRange:b,requiredSignatures:w,metadata:v}=e;if(this.isHydra?this.protocolParams({minFeeA:0,minFeeB:0,priceMem:0,priceStep:0,collateralPercent:0,coinsPerUTxOSize:"0"}):this.protocolParams({}),n.length>0&&this.addUtxosFrom(n,String(i)),this.removeDuplicateInputs(),this.meshTxBuilderBody.mints.sort((P,k)=>P.policyId.localeCompare(k.policyId)),this.meshTxBuilderBody.inputs.sort((P,k)=>P.txIn.txHash===k.txIn.txHash?P.txIn.txIndex-k.txIn.txIndex:P.txIn.txHash.localeCompare(k.txIn.txHash)),this.addAllInputs(t),this.addAllOutputs(r),this.addAllCollaterals(c),this.addAllReferenceInputs(l),this.addAllMints(p),this.addAllCertificates(B),this.addValidityRange(b),this.addAllRequiredSignatures(w),this.addAllMetadata(v),this.addCostModels(),y){const P=this.meshTxBuilderBody.collaterals.map(T=>{var Q,R;return((R=(Q=T.txIn.amount)==null?void 0:Q.find(X=>X.unit==="lovelace"))==null?void 0:R.quantity)||"0"}).reduce((T,Q)=>T+parseInt(Q),0),k=Math.ceil(this._protocolParams.collateralPercent*Number(Number(this.txBuilder.min_fee().checked_add(a.BigNum.from_str("10000")).to_js_value()))/100);let N=!1;if(P-k>0){const T=a.TransactionOutput.new(a.Address.from_bech32(y),a.Value.new(a.BigNum.from_str(String(k))));P-k>Number(a.min_ada_for_output(T,a.DataCost.new_coins_per_byte(a.BigNum.from_str(this._protocolParams.coinsPerUTxOSize))).to_js_value())&&(this.txBuilder.set_collateral_return(a.TransactionOutput.new(a.Address.from_bech32(y),a.Value.new(a.BigNum.from_str(String(P))))),this.txBuilder.set_total_collateral(a.BigNum.from_str(String(P))),N=!0)}this.addChange(y),N&&this.addCollateralReturn(y)}return this.buildTx(),this};txIn=(e,t,r,n)=>(this.txInQueueItem&&this.queueInput(),this.addingScriptInput?this.txInQueueItem={type:"Script",txIn:{txHash:e,txIndex:t,amount:r,address:n},scriptTxIn:{}}:this.txInQueueItem={type:"PubKey",txIn:{txHash:e,txIndex:t,amount:r,address:n}},this.addingScriptInput=!1,this);txInScript=(e,t="V2")=>{if(!this.txInQueueItem)throw Error("Undefined input");if(this.txInQueueItem.type==="PubKey")throw Error("Datum value attempted to be called a non script input");return this.txInQueueItem.scriptTxIn.scriptSource={type:"Provided",script:{code:e,version:t}},this};txInDatumValue=(e,t="Mesh")=>{if(!this.txInQueueItem)throw Error("Undefined input");if(this.txInQueueItem.type==="PubKey")throw Error("Datum value attempted to be called a non script input");let r=e;return t==="JSON"&&(r=this.castRawDataToJsonString(e)),t==="Mesh"?(this.txInQueueItem.scriptTxIn.datumSource={type:"Provided",data:{type:t,content:e}},this):(this.txInQueueItem.scriptTxIn.datumSource={type:"Provided",data:{type:t,content:r}},this)};txInInlineDatumPresent=()=>{if(!this.txInQueueItem)throw Error("Undefined input");if(this.txInQueueItem.type==="PubKey")throw Error("Inline datum present attempted to be called a non script input");const{txHash:e,txIndex:t}=this.txInQueueItem.txIn;return e&&t.toString()&&(this.txInQueueItem.scriptTxIn.datumSource={type:"Inline",txHash:e,txIndex:t}),this};txInRedeemerValue=(e,t={...Gt},r="Mesh")=>{if(!this.txInQueueItem)throw Error("Undefined input");if(this.txInQueueItem.type==="PubKey")throw Error("Spending tx in reference redeemer attempted to be called a non script input");let n=e;return r==="Mesh"?(this.txInQueueItem.scriptTxIn.redeemer={data:{type:r,content:e},exUnits:t},this):(r==="JSON"&&(n=this.castRawDataToJsonString(e)),this.txInQueueItem.scriptTxIn.redeemer={data:{type:r,content:n},exUnits:t},this)};txOut=(e,t)=>(this.txOutput&&(this.meshTxBuilderBody.outputs.push(this.txOutput),this.txOutput=void 0),this.txOutput={address:e,amount:t},this);txOutDatumHashValue=(e,t="Mesh")=>{let r=e;if(this.txOutput){if(t==="Mesh")return this.txOutput.datum={type:"Hash",data:{type:t,content:r}},this;t==="JSON"&&(r=this.castRawDataToJsonString(e)),this.txOutput.datum={type:"Hash",data:{type:t,content:r}}}return this};txOutInlineDatumValue=(e,t="Mesh")=>{let r=e;if(this.txOutput){if(t==="Mesh")return this.txOutput.datum={type:"Inline",data:{type:t,content:r}},this;t==="JSON"&&(r=this.castRawDataToJsonString(e)),this.txOutput.datum={type:"Inline",data:{type:t,content:r}}}return this};txOutReferenceScript=(e,t="V2")=>(this.txOutput&&(this.txOutput.referenceScript={code:e,version:t}),this);spendingPlutusScriptV2=()=>(this.addingScriptInput=!0,this);spendingTxInReference=(e,t,r,n="V2")=>{if(!this.txInQueueItem)throw Error("Undefined input");if(this.txInQueueItem.type==="PubKey")throw Error("Spending tx in reference attempted to be called a non script input");return this.txInQueueItem.scriptTxIn.scriptSource={type:"Inline",txInInfo:{txHash:e,txIndex:t,spendingScriptHash:r,version:n}},this};spendingReferenceTxInInlineDatumPresent=()=>(this.txInInlineDatumPresent(),this);spendingReferenceTxInRedeemerValue=(e,t={...Gt},r="Mesh")=>(this.txInRedeemerValue(e,t,r),this);readOnlyTxInReference=(e,t)=>(this.meshTxBuilderBody.referenceInputs.push({txHash:e,txIndex:t}),this);mintPlutusScriptV2=()=>(this.addingPlutusMint=!0,this);mint=(e,t,r)=>(this.mintItem&&this.queueMint(),this.mintItem={type:this.addingPlutusMint?"Plutus":"Native",policyId:t,assetName:r,amount:e},this.addingPlutusMint=!1,this);mintingScript=(e,t="V2")=>{if(!this.mintItem)throw Error("Undefined mint");if(!this.mintItem.type)throw Error("Mint information missing");return this.mintItem.scriptSource={type:"Provided",script:{code:e,version:t}},this};mintTxInReference=(e,t,r="V2")=>{if(!this.mintItem)throw Error("Undefined mint");if(!this.mintItem.type)throw Error("Mint information missing");if(this.mintItem.type=="Native")throw Error("Mint tx in reference can only be used on plutus script tokens");if(!this.mintItem.policyId)throw Error("PolicyId information missing from mint asset");return this.mintItem.scriptSource={type:"Reference Script",txHash:e,txIndex:t,version:r},this};mintReferenceTxInRedeemerValue=(e,t={...Gt},r="Mesh")=>{if(!this.mintItem)throw Error("Undefined mint");if(this.mintItem.type=="Native")throw Error("Mint tx in reference can only be used on plutus script tokens");if(this.mintItem.type=="Plutus"){if(!this.mintItem.policyId)throw Error("PolicyId information missing from mint asset");let n=e;if(r==="Mesh")return this.mintItem.redeemer={data:{type:r,content:n},exUnits:t},this;r==="JSON"&&(n=this.castRawDataToJsonString(e)),this.mintItem.redeemer={data:{type:r,content:n},exUnits:t}}return this};mintRedeemerValue=(e,t={...Gt},r="Mesh")=>(this.mintReferenceTxInRedeemerValue(e,t,r),this);requiredSignerHash=e=>(this.meshTxBuilderBody.requiredSignatures.push(e),this);txInCollateral=(e,t,r,n)=>(this.collateralQueueItem&&this.meshTxBuilderBody.collaterals.push(this.collateralQueueItem),this.collateralQueueItem={type:"PubKey",txIn:{txHash:e,txIndex:t,amount:r,address:n}},this);registerPoolCertificate=e=>(this.meshTxBuilderBody.certificates.push({type:"RegisterPool",poolParams:e}),this);registerStakeCertificate=e=>(this.meshTxBuilderBody.certificates.push({type:"RegisterStake",stakeKeyHash:e}),this);delegateStakeCertificate=(e,t)=>(this.meshTxBuilderBody.certificates.push({type:"DelegateStake",stakeKeyHash:e,poolId:t}),this);deregisterStakeCertificate=e=>(this.meshTxBuilderBody.certificates.push({type:"DeregisterStake",stakeKeyHash:e}),this);retirePoolCertificate=(e,t)=>(this.meshTxBuilderBody.certificates.push({type:"RetirePool",poolId:e,epoch:t}),this);changeAddress=e=>(this.meshTxBuilderBody.changeAddress=e,this);invalidBefore=e=>(this.meshTxBuilderBody.validityRange.invalidBefore=e,this);invalidHereafter=e=>(this.meshTxBuilderBody.validityRange.invalidHereafter=e,this);metadataValue=(e,t)=>(this.meshTxBuilderBody.metadata.push({tag:e,metadata:t}),this);protocolParams=e=>{const t={...mt,...e};return this._protocolParams=t,this.txBuilder=Ae(t),this};signingKey=e=>(this.meshTxBuilderBody.signingKey.push(e),this);selectUtxosFrom=(e,t=5e6)=>(this.meshTxBuilderBody.extraInputs=e,this.meshTxBuilderBody.selectionThreshold=t,this);addUtxosFrom=(e,t)=>{const r=this.meshTxBuilderBody.outputs.reduce((i,c)=>(c.amount.forEach(p=>{const{unit:y,quantity:B}=p,b=Number(i.get(y))||0;i.set(y,String(b+Number(B)))}),i),new Map);this.meshTxBuilderBody.inputs.reduce((i,c)=>{const l=c.txIn.amount;return l==null||l.forEach(p=>{const{unit:y,quantity:B}=p,b=Number(i.get(y))||0;i.set(y,String(b-Number(B)))}),i},r),this.meshTxBuilderBody.mints.reduce((i,c)=>{const l={unit:c.policyId+c.assetName,quantity:String(c.amount)},p=Number(i.get(l.unit))||0;return i.set(l.unit,String(p-Number(l.quantity))),i},r),ln(e,r,t).forEach(i=>{const c={type:"PubKey",txIn:{txHash:i.input.txHash,txIndex:i.input.outputIndex,amount:i.output.amount,address:i.output.address}};this.meshTxBuilderBody.inputs.push(c),this.addTxIn(c)})};addAllSigningKeys=e=>{if(e.length>0){const t=a.Vkeywitnesses.new(),r=a.Transaction.from_hex(this.txHex),n=r.body();e.forEach(l=>{const p=l.slice(0,4)==="5820"?l.slice(4):l,y=a.PrivateKey.from_hex(p),B=a.make_vkey_witness(a.hash_transaction(n),y);t.add(B)});const i=r.witness_set();i.set_vkeys(t);const c=a.Transaction.new(n,i,r.auxiliary_data());this.txHex=c.to_hex()}};buildTx=()=>{const e=this.txBuilder.build_tx();this.txHex=e.to_hex()};queueInput=()=>{if(!this.txInQueueItem)throw Error("Undefined input");if(this.txInQueueItem.type==="Script")if(this.txInQueueItem.scriptTxIn){if(!this.txInQueueItem.scriptTxIn.datumSource)throw Error("Script input does not contain datum information");if(!this.txInQueueItem.scriptTxIn.redeemer)throw Error("Script input does not contain redeemer information");if(!this.txInQueueItem.scriptTxIn.scriptSource)throw Error("Script input does not contain script information")}else throw Error("Script input does not contain script, datum, or redeemer information");this.meshTxBuilderBody.inputs.push(this.txInQueueItem),this.txInQueueItem=void 0};queueMint=()=>{if(!this.mintItem)throw Error("Undefined mint");if(!this.mintItem.scriptSource)throw Error("Missing mint script information");this.meshTxBuilderBody.mints.push(this.mintItem),this.mintItem=void 0};makePlutusScriptSource=e=>{const t=a.ScriptHash.from_hex(e.spendingScriptHash),r=a.TransactionInput.new(a.TransactionHash.from_hex(e.txHash),e.txIndex);return a.PlutusScriptSource.new_ref_input_with_lang_ver(t,r,bt[e.version])};removeDuplicateInputs=()=>{const e=this.meshTxBuilderBody.inputs,t=n=>`${n.txHash}#${n.txIndex}`,r=[];for(let n=0;n<e.length;n++){const i=t(e[n].txIn);r.includes(i)?(e.splice(n,1),n--):r.push(i)}};addAllInputs=e=>{for(let t=0;t<e.length;t++){const r=e[t];switch(r.type){case"PubKey":this.addTxIn(r);break;case"Script":this.addScriptTxIn(r);break}}};addTxIn=e=>{this.txBuilder.add_input(a.Address.from_bech32(e.txIn.address),a.TransactionInput.new(a.TransactionHash.from_hex(e.txIn.txHash),e.txIn.txIndex),Qt(e.txIn.amount))};addScriptTxIn=({scriptTxIn:e,txIn:t})=>{let r;const{datumSource:n,scriptSource:i,redeemer:c}=e;if(n.type==="Provided")r=a.DatumSource.new(this.castDataToPlutusData(n.data));else{const y=a.TransactionInput.new(a.TransactionHash.from_hex(n.txHash),n.txIndex);r=a.DatumSource.new_ref_input(y)}let l;i.type=="Inline"?l=this.makePlutusScriptSource(i.txInInfo):l=a.PlutusScriptSource.new(a.PlutusScript.from_hex_with_version(i.script.code,bt[i.script.version]));const p=a.Redeemer.new(a.RedeemerTag.new_spend(),a.BigNum.from_str("0"),this.castDataToPlutusData(c.data),a.ExUnits.new(a.BigNum.from_str(String(c.exUnits.mem)),a.BigNum.from_str(String(c.exUnits.steps))));this.txBuilder.add_plutus_script_input(a.PlutusWitness.new_with_ref(l,r,p),a.TransactionInput.new(a.TransactionHash.from_hex(t.txHash),t.txIndex),Qt(t.amount))};addAllOutputs=e=>{for(let t=0;t<e.length;t++){const r=e[t];this.addOutput(r)}};addOutput=({amount:e,address:t,datum:r,referenceScript:n})=>{const i=Qt(e),c=i.multiasset();if(i.is_zero()&&c===void 0)throw Error("Invalid output amount");let l=a.TransactionOutputBuilder.new().with_address(xt(t));r&&r.type==="Hash"&&(l=l.with_data_hash(a.hash_plutus_data(this.castDataToPlutusData(r.data)))),r&&r.type==="Inline"&&(l=l.with_plutus_data(this.castDataToPlutusData(r.data))),n&&(l=l.with_script_ref(a.ScriptRef.new_plutus_script(a.PlutusScript.from_hex_with_version(n.code,bt[n.version]))));const p=l.next();if(c){const y=i.coin().is_zero()?p.with_asset_and_min_required_coin_by_utxo_cost(c,Te(this._protocolParams.coinsPerUTxOSize)).build():p.with_coin_and_asset(i.coin(),c).build();this.txBuilder.add_output(y)}else{const y=p.with_coin(i.coin()).build();this.txBuilder.add_output(y)}};addAllCollaterals=e=>{const t=a.TxInputsBuilder.new();for(let r=0;r<e.length;r++){const n=e[r];this.addCollateral(t,n)}this.txBuilder.set_collateral(t)};addCollateral=(e,t)=>{e.add_input(a.Address.from_bech32(t.txIn.address),a.TransactionInput.new(a.TransactionHash.from_hex(t.txIn.txHash),t.txIn.txIndex),Qt(t.txIn.amount))};addCollateralReturn=e=>{var r;const t=(r=this.txBuilder.get_fee_if_set())==null?void 0:r.to_js_value();if(t){const n=Math.ceil(this._protocolParams.collateralPercent*Number(t)/100);this.txBuilder.set_total_collateral_and_return(a.BigNum.from_str(String(n)),a.Address.from_bech32(e))}};addAllReferenceInputs=e=>{e.forEach(t=>{this.addReferenceInput(t)})};addReferenceInput=({txHash:e,txIndex:t})=>{const r=a.TransactionInput.new(a.TransactionHash.from_hex(e),t);this.txBuilder.add_reference_input(r)};addAllMints=e=>{const t=a.MintBuilder.new();let r=0;for(let n=0;n<e.length;n++){const i=e[n];if(!i.scriptSource)throw Error("Mint script is expected to be provided");if(i.type==="Plutus"){if(!i.redeemer)throw Error("Missing mint redeemer information");this.addPlutusMint(t,i,r),r++}else i.type==="Native"&&this.addNativeMint(t,i)}this.txBuilder.set_mint_builder(t)};addPlutusMint=(e,{redeemer:t,policyId:r,scriptSource:n,assetName:i,amount:c},l)=>{const p=a.Redeemer.new(a.RedeemerTag.new_mint(),a.BigNum.from_str(String(l)),this.castDataToPlutusData(t.data),a.ExUnits.new(a.BigNum.from_str(String(t.exUnits.mem)),a.BigNum.from_str(String(t.exUnits.steps)))),y=n.type==="Reference Script"?a.PlutusScriptSource.new_ref_input_with_lang_ver(a.ScriptHash.from_hex(r),a.TransactionInput.new(a.TransactionHash.from_hex(n.txHash),n.txIndex),bt[n.version]):a.PlutusScriptSource.new(a.PlutusScript.from_hex_with_version(n.script.code,bt[n.script.version]));e.add_asset(a.MintWitness.new_plutus_script(y,p),a.AssetName.new(Buffer.from(i,"hex")),a.Int.from_str(c))};addNativeMint=(e,{scriptSource:t,assetName:r,amount:n})=>{if(t.type==="Reference Script")throw Error("Native mint cannot have reference script");e.add_asset(a.MintWitness.new_native_script(a.NativeScript.from_hex(t.script.code)),a.AssetName.new(Buffer.from(r,"hex")),a.Int.from_str(n))};decimalToFraction(e){const t=10**e.toString().split(".")[1].length;return[e*t,t]}toPoolParams=e=>{const t=this.decimalToFraction(e.margin),r=a.Relays.new();e.relays.forEach(c=>{r.add(Ur(c))});const n=a.RewardAddress.from_address(a.Address.from_bech32(e.rewardAddress));if(n===void 0)throw new Error("Reward address is invalid");const i=a.Ed25519KeyHashes.new();return e.owners.forEach(c=>{i.add(a.Ed25519KeyHash.from_hex(c))}),a.PoolParams.new(a.Ed25519KeyHash.from_hex(e.operator),a.VRFKeyHash.from_hex(e.VRFKeyHash),a.BigNum.from_str(e.pledge),a.BigNum.from_str(e.cost),a.UnitInterval.new(a.BigNum.from_str(t[0].toString()),a.BigNum.from_str(t[1].toString())),n,i,r,e.metadata?a.PoolMetadata.from_json(zt.exports.stringify(e.metadata)):void 0)};addCertificate=(e,t)=>{switch(t.type){case"RegisterPool":e.add(a.Certificate.new_pool_registration(a.PoolRegistration.new(this.toPoolParams(t.poolParams))));break;case"RegisterStake":e.add(a.Certificate.new_stake_registration(a.StakeRegistration.new(a.StakeCredential.from_keyhash(a.Ed25519KeyHash.from_hex(t.stakeKeyHash)))));break;case"DelegateStake":e.add(a.Certificate.new_stake_delegation(a.StakeDelegation.new(a.StakeCredential.from_keyhash(a.Ed25519KeyHash.from_hex(t.stakeKeyHash)),t.poolId.startsWith("pool")?a.Ed25519KeyHash.from_bech32(t.poolId):a.Ed25519KeyHash.from_hex(t.poolId))));break;case"DeregisterStake":e.add(a.Certificate.new_stake_deregistration(a.StakeDeregistration.new(a.StakeCredential.from_keyhash(a.Ed25519KeyHash.from_hex(t.stakeKeyHash)))));break;case"RetirePool":e.add(a.Certificate.new_pool_retirement(a.PoolRetirement.new(t.poolId.startsWith("pool")?a.Ed25519KeyHash.from_bech32(t.poolId):a.Ed25519KeyHash.from_hex(t.poolId),t.epoch)))}};queueAllLastItem=()=>{this.txOutput&&(this.meshTxBuilderBody.outputs.push(this.txOutput),this.txOutput=void 0),this.txInQueueItem&&this.queueInput(),this.collateralQueueItem&&(this.meshTxBuilderBody.collaterals.push(this.collateralQueueItem),this.collateralQueueItem=void 0),this.mintItem&&this.queueMint()};addAllCertificates=e=>{const t=a.Certificates.new();e.forEach(r=>{this.addCertificate(t,r)}),this.txBuilder.set_certs(t)};addCostModels=()=>{this.txBuilder.calc_script_data_hash(a.TxBuilderConstants.plutus_vasil_cost_models())};addChange=e=>{this.txBuilder.add_change_if_needed(a.Address.from_bech32(e))};addValidityRange=({invalidBefore:e,invalidHereafter:t})=>{e&&this.txBuilder.set_validity_start_interval_bignum(a.BigNum.from_str(e.toString())),t&&this.txBuilder.set_ttl_bignum(a.BigNum.from_str(t.toString()))};addAllRequiredSignatures=e=>{e.forEach(t=>{this.txBuilder.add_required_signer(a.Ed25519KeyHash.from_hex(t))})};addAllMetadata=e=>{e.forEach(({tag:t,metadata:r})=>{this.txBuilder.add_json_metadatum(a.BigNum.from_str(t),zt.exports.stringify(r))})};updateRedeemer=(e,t)=>{t.forEach(r=>{switch(r.tag){case"SPEND":{const n=e.inputs[r.index];n.type=="Script"&&n.scriptTxIn.redeemer&&(n.scriptTxIn.redeemer.exUnits.mem=Math.floor(r.budget.mem*this.txEvaluationMultiplier),n.scriptTxIn.redeemer.exUnits.steps=Math.floor(r.budget.steps*this.txEvaluationMultiplier));break}case"MINT":{const n=e.mints[r.index];n.type=="Plutus"&&n.redeemer&&(n.redeemer.exUnits.mem=Math.floor(r.budget.mem*this.txEvaluationMultiplier),n.redeemer.exUnits.steps=Math.floor(r.budget.steps*this.txEvaluationMultiplier));break}}})};castRawDataToJsonString=e=>typeof e=="object"?zt.exports.stringify(e):e;castDataToPlutusData=({type:e,content:t})=>e==="Mesh"?Ot(t):e==="CBOR"?a.PlutusData.from_hex(t):a.PlutusData.from_json(t,a.PlutusDatumSchema.DetailedSchema)}class pn extends An{_fetcher;_submitter;_evaluator;queriedTxHashes=new Set;queriedUTxOs={};constructor({fetcher:e,submitter:t,evaluator:r,isHydra:n=!1}){super(),e&&(this._fetcher=e),t&&(this._submitter=t),r&&(this._evaluator=r),n&&(this.isHydra=!0)}complete=async e=>{e?this.meshTxBuilderBody=e:this.queueAllLastItem();const{inputs:t,collaterals:r}=this.meshTxBuilderBody,n=[...t,...r].filter(i=>!this.isInputComplete(i));if(await this.queryAllTxInfo(n),n.forEach(i=>{this.completeTxInformation(i)}),this.completeSync(e),this._evaluator){const i=await this._evaluator.evaluateTx(this.txHex);this.updateRedeemer(this.meshTxBuilderBody,i),this.completeSync(e)}return this};submitTx=async e=>{var r;return await((r=this._submitter)==null?void 0:r.submitTx(e))};getUTxOInfo=async e=>{var r;let t=[];this.queriedTxHashes.has(e)||(this.queriedTxHashes.add(e),t=await((r=this._fetcher)==null?void 0:r.fetchUTxOs(e))||[],this.queriedUTxOs[e]=t)};queryAllTxInfo=e=>{var r;const t=[];if(e.length>0&&!this._fetcher)throw Error("Transaction information is incomplete while no fetcher instance is provided");for(let n=0;n<e.length;n++){const i=e[n];this.isInputInfoComplete(i)||t.push(this.getUTxOInfo(i.txIn.txHash)),i.type==="Script"&&((r=i.scriptTxIn.scriptSource)==null?void 0:r.type)==="Inline"&&!this.isRefScriptInfoComplete(i)&&t.push(this.getUTxOInfo(i.scriptTxIn.scriptSource.txInInfo.txHash))}return Promise.all(t)};completeTxInformation=e=>{var t;if(!this.isInputInfoComplete(e)){const r=this.queriedUTxOs[e.txIn.txHash],n=r==null?void 0:r.find(l=>l.input.outputIndex===e.txIn.txIndex),i=n==null?void 0:n.output.amount,c=n==null?void 0:n.output.address;if(!i||i.length===0)throw Error(`Couldn't find value information for ${e.txIn.txHash}#${e.txIn.txIndex}`);if(e.txIn.amount=i,e.type==="PubKey"){if(!c||c==="")throw Error(`Couldn't find address information for ${e.txIn.txHash}#${e.txIn.txIndex}`);e.txIn.address=c}}if(e.type==="Script"&&((t=e.scriptTxIn.scriptSource)==null?void 0:t.type)=="Inline"&&!this.isRefScriptInfoComplete(e)){const r=e.scriptTxIn.scriptSource.txInInfo,i=this.queriedUTxOs[r.txHash].find(c=>c.input.outputIndex===r.txIndex);if(!i)throw Error(`Couldn't find script reference utxo for ${r.txHash}#${r.txIndex}`);r.spendingScriptHash=i==null?void 0:i.output.scriptHash}};isInputComplete=e=>e.type==="PubKey"?this.isInputInfoComplete(e):e.type==="Script"?this.isInputInfoComplete(e)&&this.isRefScriptInfoComplete(e):!0;isInputInfoComplete=e=>{const{amount:t,address:r}=e.txIn;return!(e.type==="PubKey"&&(!t||!r)||e.type==="Script"&&!t)};isRefScriptInfoComplete=e=>{var r;const{scriptSource:t}=e.scriptTxIn;return!((t==null?void 0:t.type)==="Inline"&&!((r=t.txInInfo)!=null&&r.spendingScriptHash))}}class rt{_networkId;_encryptedSecret;constructor(e,t){this._networkId=e,this._encryptedSecret=t}getAccount(e,t){return this.accountContext(e,t,(r,n)=>{const i=fr(this._networkId,r.to_public().hash(),n.to_public().hash()).to_address().to_bech32(),c=gr(this._networkId,r.to_public().hash()).to_address().to_bech32(),l=Ne(this._networkId,n.to_public().hash()).to_address().to_bech32();return{baseAddress:i,enterpriseAddress:c,rewardAddress:l}})}signData(e,t,r,n){try{return this.accountContext(e,t,(i,c)=>{const l={payload:n},p={address:rt.resolveAddress(this._networkId,r,i,c),key:r.startsWith("stake")?c:i},{coseSign1:y,coseKey:B}=as(l,p);return{signature:y,key:B}})}catch(i){throw new Error(`An error occurred during signData: ${i}.`)}}signTx(e,t,r,n,i){try{const c=Tr(Fr(n));return this.accountContext(e,t,(l,p)=>{const y=a.Vkeywitnesses.new();return rt.resolveSigners(n,r,l.to_public().hash().to_hex()).forEach(b=>{if(b===l.to_public().hash().to_hex())y.add(a.make_vkey_witness(c,l));else if(b===p.to_public().hash().to_hex())y.add(a.make_vkey_witness(c,p));else if(i===!1)throw new Error(`Missing key witness for: ${b}`)}),y})}catch(c){throw new Error(`An error occurred during signTx: ${c}.`)}}static encryptMnemonic(e,t){const r=Qe.mnemonicToEntropy(e.join(" ")),n=Kr(r),i=lt(n.as_bytes());return n.free(),rt.encrypt(i,t)}static encryptPrivateKey(e,t){const r=a.Bip32PrivateKey.from_bech32(e),n=lt(r.as_bytes());return r.free(),rt.encrypt(n,t)}static encryptSigningKeys(e,t,r){const n=rt.encrypt(e.slice(4),r),i=rt.encrypt(t.slice(4),r);return[n,i]}static generateMnemonic(e=256){return Qe.generateMnemonic(e).split(" ")}accountContext(e,t,r){const{paymentKey:n,stakeKey:i}=rt.resolveKeys(e,t,this._encryptedSecret),c=r(n,i);return n.free(),i.free(),c}static decrypt(e,t){try{return a.decrypt_with_password(dt(t),e)}catch{throw new Error("The password is incorrect.")}}static encrypt(e,t){const r=pr.customAlphabet("0123456789abcdef"),n=r(64),i=r(24);return a.encrypt_with_password(dt(t),n,i,e)}static resolveAddress(e,t,r,n){const i=[fr(e,r.to_public().hash(),n.to_public().hash()),gr(e,r.to_public().hash()),Ne(e,n.to_public().hash())].find(c=>c.to_address().to_bech32()===t);if(i!==void 0)return i.to_address();throw new Error(`Address: ${t} doesn't belong to this account.`)}static resolveKeys(e,t,r){if(typeof r=="string"){const c=rt.decrypt(r,t);return Ts(c,e)}const n=rt.decrypt(r[0],t),i=rt.decrypt(r[1],t);return{paymentKey:a.PrivateKey.from_hex(n),stakeKey:a.PrivateKey.from_hex(i)}}static resolveSigners(e,t,r){const n=l=>{const p=(T,Q=[],R=0)=>{var O,M,W,Z,D;if(T===void 0||R>=T.len())return Q;const X=T.get(R),$=new Array;switch(X.kind()){case a.CertificateKind.StakeDeregistration:{const F=(O=X.as_stake_deregistration())==null?void 0:O.stake_credential(),q=(F==null?void 0:F.kind())===a.StakeCredKind.Key?F.to_keyhash():void 0;q&&$.push(q.to_hex());break}case a.CertificateKind.StakeDelegation:{const F=(M=X.as_stake_delegation())==null?void 0:M.stake_credential(),q=(F==null?void 0:F.kind())===a.StakeCredKind.Key?F.to_keyhash():void 0;q&&$.push(q.to_hex());break}case a.CertificateKind.PoolRegistration:{const F=(W=X.as_pool_registration())==null?void 0:W.pool_params().pool_owners();$.push(...B(F));break}case a.CertificateKind.PoolRetirement:{const F=(Z=X.as_pool_retirement())==null?void 0:Z.pool_keyhash();F&&$.push(F.to_hex());break}case a.CertificateKind.MoveInstantaneousRewardsCert:{const F=(D=X.as_move_instantaneous_rewards_cert())==null?void 0:D.move_instantaneous_reward().as_to_stake_creds();if(F)for(let q=0;q<F.len();q+=1){const j=F.keys().get(q),nt=j.kind()===a.StakeCredKind.Key?j.to_keyhash():void 0;nt&&$.push(nt.to_hex())}break}}return p(T,[...Q,...$],R+1)},y=(T,Q=[],R=0)=>{if(T===void 0||R>=T.len())return Q;const X=T.get(R).index(),$=T.get(R).transaction_id(),O=t.find(M=>M.input.outputIndex===X&&M.input.txHash===$.to_hex())!==void 0?r:"OUR_PRINCESS_IS_IN_ANOTHER_CASTLE";return y(T,[...Q,O],R+1)},B=(T,Q=[],R=0)=>T===void 0||R>=T.len()?Q:B(T,[...Q,T.get(R).to_hex()],R+1),b=(T,Q=[],R=0)=>{if(T===void 0||R>=T.len())return Q;const X=T.keys().get(R).payment_cred(),$=X.kind()===a.StakeCredKind.Key?X.to_keyhash():void 0;return b(T,$?[...Q,$.to_hex()]:Q,R+1)},w=l.certs(),v=l.collateral(),P=l.inputs(),k=l.required_signers(),N=l.withdrawals();return[...p(w),...y(v),...y(P),...B(k),...b(N)]},i=l=>{const p=(B,b=[])=>{var w,v,P,k;if(B)for(let N=0;N<B.len();N+=1){const T=B.get(N);switch(T.kind()){case a.NativeScriptKind.ScriptPubkey:{const Q=(w=T.as_script_pubkey())==null?void 0:w.addr_keyhash().to_hex();return Q?[...b,Q]:b}case a.NativeScriptKind.ScriptAll:return p((v=T.as_script_all())==null?void 0:v.native_scripts(),b);case a.NativeScriptKind.ScriptAny:return p((P=T.as_script_any())==null?void 0:P.native_scripts(),b);case a.NativeScriptKind.ScriptNOfK:return p((k=T.as_script_n_of_k())==null?void 0:k.native_scripts(),b)}}return b},y=l.native_scripts();return[...p(y)]},c=yt(e);return new Set([...n(c.body()),...i(c.witness_set())])}}const It="MARI0TIME";class pe{_fetcher;_submitter;_wallet;constructor(e){switch(this._fetcher=e.fetcher,this._submitter=e.submitter,e.key.type){case"mnemonic":this._wallet=new rt(e.networkId,rt.encryptMnemonic(e.key.words,It));break;case"root":this._wallet=new rt(e.networkId,rt.encryptPrivateKey(e.key.bech32,It));break;case"cli":this._wallet=new rt(e.networkId,rt.encryptSigningKeys(e.key.payment,e.key.stake??"f0".repeat(34),It))}}getBaseAddress(e=0){return this._wallet.getAccount(e,It).baseAddress}getPaymentAddress(e=0){return this._wallet.getAccount(e,It).enterpriseAddress}getRewardAddress(e=0){return this._wallet.getAccount(e,It).rewardAddress}getUsedAddress(e=0){const t=this._wallet.getAccount(e,It);return xt(t.enterpriseAddress)}getUsedCollateral(e=mt.maxCollateralInputs){throw new Error("getUsedCollateral not implemented.")}async getUsedUTxOs(e=0){if(!this._fetcher)throw new Error("[AppWallet] Fetcher is required to fetch UTxOs. Please provide a fetcher.");const t=this._wallet.getAccount(e,It);return(await this._fetcher.fetchAddressUTxOs(t.enterpriseAddress)).map(n=>_t(n))}signData(e,t,r=0){try{return this._wallet.signData(r,It,e,t)}catch(n){throw new Error(`[AppWallet] An error occurred during signData: ${n}.`)}}async signTx(e,t=!1,r=0){try{if(!this._fetcher)throw new Error("[AppWallet] Fetcher is required to fetch UTxOs. Please provide a fetcher.");const n=this._wallet.getAccount(r,It),i=await this._fetcher.fetchAddressUTxOs(n.enterpriseAddress),c=this._wallet.signTx(r,It,i,e,t),l=yt(e),p=l.witness_set(),y=Ue(p,c);return p.set_vkeys(y),a.Transaction.new(l.body(),p,l.auxiliary_data()).to_hex()}catch(n){throw new Error(`[AppWallet] An error occurred during signTx: ${n}.`)}}async signTxs(e,t){return console.log("unimplemented",e,t),[]}submitTx(e){if(!this._submitter)throw new Error("[AppWallet] Submitter is required to submit transactions. Please provide a submitter.");return this._submitter.submitTx(e)}static brew(e=256){return rt.generateMnemonic(e)}async getUtxos(){return await this.getUsedUTxOs()}async getCollateral(){return(await this.getUsedUTxOs())[0]}async getUsedAddresses(){return console.log(1,await this.getPaymentAddress()),[await this.getPaymentAddress()]}}class ye{_walletInstance;_walletName;walletInstance;constructor(e,t){this._walletInstance=e,this._walletName=t,this.walletInstance={...e}}static getInstalledWallets(){return window.cardano===void 0?[]:We.filter(e=>window.cardano[e]!==void 0).map(e=>({name:window.cardano[e].name,icon:window.cardano[e].icon,version:window.cardano[e].apiVersion}))}static async enable(e){try{const t=await ye.resolveInstance(e);if(t!==void 0)return new ye(t,e);throw new Error(`Couldn't create an instance of wallet: ${e}`)}catch(t){throw new Error(`[BrowserWallet] An error occurred during enable: ${JSON.stringify(t)}.`)}}async getBalance(){const e=await this._walletInstance.getBalance();return Mr(Hs(e))}async getChangeAddress(){const e=await this._walletInstance.getChangeAddress();return Lt(e).to_bech32()}async getCollateral(e=mt.maxCollateralInputs){return(await this.getUsedCollateral(e)).map(r=>ie(r))}getNetworkId(){return this._walletInstance.getNetworkId()}async getRewardAddresses(){return(await this._walletInstance.getRewardAddresses()).map(t=>Lt(t).to_bech32())}async getUnusedAddresses(){return(await this._walletInstance.getUnusedAddresses()).map(t=>Lt(t).to_bech32())}async getUsedAddresses(){return(await this._walletInstance.getUsedAddresses()).map(t=>Lt(t).to_bech32())}async getUtxos(e=void 0){return(await this.getUsedUTxOs(e)).map(r=>ie(r))}signData(e,t){const r=xt(e).to_hex();return this._walletInstance.signData(r,dt(t))}async signTx(e,t=!1){try{const r=yt(e),n=r.witness_set(),i=await this._walletInstance.signTx(e,t),c=hr(i).vkeys()??a.Vkeywitnesses.new(),l=Ue(n,c);return n.set_vkeys(l),lt(a.Transaction.new(r.body(),n,r.auxiliary_data()).to_bytes())}catch(r){throw new Error(`[BrowserWallet] An error occurred during signTx: ${JSON.stringify(r)}.`)}}async signTxs(e,t=!1){let r;switch(this._walletName){case"Typhon Wallet":this._walletInstance.signTxs&&(r=await this._walletInstance.signTxs(e,t));break;default:this._walletInstance.signTxs?r=await this._walletInstance.signTxs(e.map(i=>({cbor:i,partialSign:t}))):this._walletInstance.experimental.signTxs&&(r=await this._walletInstance.experimental.signTxs(e.map(i=>({cbor:i,partialSign:t}))));break}if(!r)throw new Error("Wallet does not support signTxs");const n=[];for(let i=0;i<r.length;i++){const c=yt(e[i]),l=c.witness_set(),p=hr(r[i]).vkeys()??a.Vkeywitnesses.new(),y=Ue(l,p);l.set_vkeys(y);const B=lt(a.Transaction.new(c.body(),l,c.auxiliary_data()).to_bytes());n.push(B)}return n}submitTx(e){return this._walletInstance.submitTx(e)}async getUsedAddress(){const e=await this._walletInstance.getUsedAddresses();return Lt(e[0])}async getUsedCollateral(e=mt.maxCollateralInputs){return(await this._walletInstance.experimental.getCollateral()??[]).map(r=>lr(r)).slice(0,e)}async getUsedUTxOs(e=void 0){const t=e?Qt(e).to_hex():void 0;return(await this._walletInstance.getUtxos(t)??[]).map(n=>lr(n))}async getAssets(){return(await this.getBalance()).filter(t=>t.unit!=="lovelace").map(t=>{const r=t.unit.slice(0,ht),n=t.unit.slice(ht),i=Le(r,n);return{unit:t.unit,policyId:r,assetName:Ve(n),fingerprint:i,quantity:t.quantity}})}async getLovelace(){const t=(await this.getBalance()).find(r=>r.unit==="lovelace");return t!==void 0?t.quantity:"0"}async getPolicyIdAssets(e){return(await this.getAssets()).filter(r=>r.policyId===e)}async getPolicyIds(){const e=await this.getBalance();return Array.from(new Set(e.map(t=>t.unit.slice(0,ht)))).filter(t=>t!=="lovelace")}static resolveInstance(e){if(window.cardano===void 0)return;const t=We.map(r=>window.cardano[r]).filter(r=>r!==void 0).find(r=>r.name.toLowerCase()===e.toLowerCase());return t==null?void 0:t.enable()}}class In{_wallet;_network;constructor(e){switch(this._network=e.networkId,e.key.type){case"root":this._wallet=new pe({networkId:e.networkId,fetcher:e.fetcher,submitter:e.submitter,key:{type:"root",bech32:e.key.bech32}});break;case"cli":this._wallet=new pe({networkId:e.networkId,fetcher:e.fetcher,submitter:e.submitter,key:{type:"cli",payment:e.key.payment}});break;case"mnemonic":this._wallet=new pe({networkId:e.networkId,fetcher:e.fetcher,submitter:e.submitter,key:{type:"mnemonic",words:e.key.words}});break}}async getBalance(){const e=await this.getUtxos(),t=new Map;return e.map(n=>{n.output.amount.map(i=>{const c=i.unit,l=Number(i.quantity);if(t.has(c)){const p=t.get(c);t.set(c,p+l)}else t.set(c,l)})}),Array.from(t,([n,i])=>({unit:n,quantity:i.toString()}))}getChangeAddress(){return this._wallet.getPaymentAddress()}async getCollateral(){const t=(await this.getUtxos()).filter(r=>r.output.amount.length===1&&r.output.amount[0].unit==="lovelace");t.sort((r,n)=>Number(r.output.amount[0].quantity)-Number(n.output.amount[0].quantity));for(const r of t)if(Number(r.output.amount[0].quantity)>=5e6)return[r];return[]}getNetworkId(){return this._network}async getRewardAddresses(){return[await this._wallet.getRewardAddress()]}getUnusedAddresses(){return[this.getChangeAddress()]}async getUsedAddresses(){return[this.getChangeAddress()]}async getUtxos(){return(await this.getUsedUTxOs()).map(t=>ie(t))}signData(e){return this._wallet.signData(this.getChangeAddress(),e)}async signTx(e,t=!1){return await this._wallet.signTx(e,t)}async signTxs(e,t=!1){const r=[];for(const n of e){const i=await this.signTx(n,t);r.push(i)}return r}async submitTx(e){return await this._wallet.submitTx(e)}getUsedAddress(){return this._wallet.getUsedAddress()}async getUsedCollateral(){return(await this.getCollateral()).map(r=>_t(r))}async getUsedUTxOs(){return await this._wallet.getUtxos()}async getAssets(){return(await this.getBalance()).filter(t=>t.unit!=="lovelace").map(t=>{const r=t.unit.slice(0,ht),n=t.unit.slice(ht),i=Le(r,n);return{unit:t.unit,policyId:r,assetName:Ve(n),fingerprint:i,quantity:t.quantity}})}async getLovelace(){const t=(await this.getBalance()).find(r=>r.unit==="lovelace");return t!==void 0?t.quantity:"0"}async getPolicyIdAssets(e){return(await this.getAssets()).filter(r=>r.policyId===e)}async getPolicyIds(){const e=await this.getBalance();return Array.from(new Set(e.map(t=>t.unit.slice(0,ht)))).filter(t=>t!=="lovelace")}async createCollateral(){const t=await new exports.Transaction({initiator:this._wallet}).sendLovelace(this.getChangeAddress(),"5000000").build(),r=await this.signTx(t);return await this.submitTx(r)}static brew(e=!1,t=256){const r=rt.generateMnemonic(t);return e?Hr(r):r}}exports.AppWallet=pe;exports.BlockfrostProvider=en;exports.BrowserWallet=ye;exports.EmbeddedWallet=rt;exports.ForgeScript=cn;exports.InfuraProvider=rn;exports.KoiosProvider=sn;exports.MaestroProvider=an;exports.MeshTxBuilder=pn;exports.MeshWallet=In;exports.OgmiosProvider=nn;exports.YaciProvider=on;exports.checkSignature=os;exports.generateNonce=Xs;exports.isNetwork=Ir;exports.keepRelevant=_r;exports.largestFirst=ts;exports.largestFirstMultiAsset=yr;exports.mergeAssets=zr;exports.parseAssetUnit=kt;exports.parseHttpError=E;exports.readPlutusData=Zs;exports.readTransaction=tn;exports.resolveDataHash=qs;exports.resolveEpochNo=Vs;exports.resolveFingerprint=Le;exports.resolveLanguageView=Ls;exports.resolveNativeScriptAddress=Gs;exports.resolveNativeScriptHash=Ys;exports.resolvePaymentKeyHash=qt;exports.resolvePlutusScriptAddress=$s;exports.resolvePlutusScriptHash=zs;exports.resolvePoolId=Ws;exports.resolvePrivateKey=Hr;exports.resolveRewardAddress=oe;exports.resolveScriptRef=Js;exports.resolveSlotNo=js;exports.resolveStakeKeyHash=Yt;exports.resolveTxFees=Ge;exports.resolveTxHash=Fr;
|
package/dist/core.js
CHANGED
|
@@ -2,7 +2,7 @@ import { customAlphabet as _r } from "nanoid";
|
|
|
2
2
|
import * as a from "@emurgo/cardano-serialization-lib-nodejs";
|
|
3
3
|
import Mt from "axios";
|
|
4
4
|
import { mnemonicToEntropy as yr, generateMnemonic as Yr } from "bip39";
|
|
5
|
-
import { COSEKey as xr, COSESign1 as $r, Label as Pt, Int as ge, BigNum as De, KeyType as zr, AlgorithmId as wr, CBORValue as ke, HeaderMap as
|
|
5
|
+
import { COSEKey as xr, COSESign1 as $r, Label as Pt, Int as ge, BigNum as De, KeyType as zr, AlgorithmId as wr, CBORValue as ke, HeaderMap as We, Headers as Wr, ProtectedHeaderMap as Jr, COSESign1Builder as jr } from "@emurgo/cardano-message-signing-nodejs";
|
|
6
6
|
const on = (s) => {
|
|
7
7
|
const e = [];
|
|
8
8
|
return s.forEach((t) => {
|
|
@@ -46,7 +46,7 @@ const on = (s) => {
|
|
|
46
46
|
preview: ["183", "15811222", "1682467200", "86400"],
|
|
47
47
|
preprod: ["65", "26438400", "1682121600", "432000"],
|
|
48
48
|
mainnet: ["208", "4492800", "1596059091", "432000"]
|
|
49
|
-
},
|
|
49
|
+
}, Je = {
|
|
50
50
|
ALONZO: a.TxBuilderConstants.plutus_alonzo_cost_models(),
|
|
51
51
|
BABBAGE: (() => {
|
|
52
52
|
const s = a.Costmdls.new(), e = a.CostModel.new();
|
|
@@ -526,9 +526,9 @@ const on = (s) => {
|
|
|
526
526
|
const e = xr.new(Pt.from_key_type(zr.OKP));
|
|
527
527
|
return e.set_algorithm_id(Pt.from_algorithm_id(wr.EdDSA)), e.set_header(Pt.new_int(ge.new_negative(De.from_str("1"))), ke.new_int(ge.new_i32(6))), e.set_header(Pt.new_int(ge.new_negative(De.from_str("2"))), ke.new_bytes(s.key.to_public().as_bytes())), e;
|
|
528
528
|
}, gs = (s, e) => {
|
|
529
|
-
const t =
|
|
529
|
+
const t = We.new(), r = We.new();
|
|
530
530
|
t.set_algorithm_id(Pt.from_algorithm_id(wr.EdDSA)), t.set_header(Pt.new_text("address"), ke.new_bytes(e.address.to_bytes()));
|
|
531
|
-
const n =
|
|
531
|
+
const n = Wr.new(Jr.new(t), r), i = jr.new(n, G(s.payload), !1);
|
|
532
532
|
s.externalAAD !== void 0 && i.set_external_aad(G(s.externalAAD));
|
|
533
533
|
const c = i.make_data_to_sign(), l = e.key.sign(c.to_bytes());
|
|
534
534
|
return i.build(l.to_bytes());
|
|
@@ -599,7 +599,7 @@ function ys(s) {
|
|
|
599
599
|
function xs(s) {
|
|
600
600
|
return s.charCodeAt(0);
|
|
601
601
|
}
|
|
602
|
-
var wt = Er,
|
|
602
|
+
var wt = Er, W = _s(), vt = 64, me = [];
|
|
603
603
|
Et.exports = mt;
|
|
604
604
|
var Xe = Et.exports.BYTES_MIN = 16, Ze = Et.exports.BYTES_MAX = 64;
|
|
605
605
|
Et.exports.BYTES = 32;
|
|
@@ -609,31 +609,31 @@ var rr = Et.exports.SALTBYTES = 16, sr = Et.exports.PERSONALBYTES = 16;
|
|
|
609
609
|
function mt(s, e, t, r, n) {
|
|
610
610
|
if (!(this instanceof mt))
|
|
611
611
|
return new mt(s, e, t, r, n);
|
|
612
|
-
if (!(
|
|
612
|
+
if (!(W && W.exports))
|
|
613
613
|
throw new Error("WASM not loaded. Wait for Blake2b.ready(cb)");
|
|
614
|
-
s || (s = 32), n !== !0 && (wt(s >= Xe, "digestLength must be at least " + Xe + ", was given " + s), wt(s <= Ze, "digestLength must be at most " + Ze + ", was given " + s), e != null && wt(e.length >= tr, "key must be at least " + tr + ", was given " + e.length), e != null && wt(e.length <= er, "key must be at least " + er + ", was given " + e.length), t != null && wt(t.length === rr, "salt must be exactly " + rr + ", was given " + t.length), r != null && wt(r.length === sr, "personal must be exactly " + sr + ", was given " + r.length)), me.length || (me.push(vt), vt += 216), this.digestLength = s, this.finalized = !1, this.pointer = me.pop(),
|
|
614
|
+
s || (s = 32), n !== !0 && (wt(s >= Xe, "digestLength must be at least " + Xe + ", was given " + s), wt(s <= Ze, "digestLength must be at most " + Ze + ", was given " + s), e != null && wt(e.length >= tr, "key must be at least " + tr + ", was given " + e.length), e != null && wt(e.length <= er, "key must be at least " + er + ", was given " + e.length), t != null && wt(t.length === rr, "salt must be exactly " + rr + ", was given " + t.length), r != null && wt(r.length === sr, "personal must be exactly " + sr + ", was given " + r.length)), me.length || (me.push(vt), vt += 216), this.digestLength = s, this.finalized = !1, this.pointer = me.pop(), W.memory.fill(0, 0, 64), W.memory[0] = this.digestLength, W.memory[1] = e ? e.length : 0, W.memory[2] = 1, W.memory[3] = 1, t && W.memory.set(t, 32), r && W.memory.set(r, 48), this.pointer + 216 > W.memory.length && W.realloc(this.pointer + 216), W.exports.blake2b_init(this.pointer, this.digestLength), e && (this.update(e), W.memory.fill(0, vt, vt + e.length), W.memory[this.pointer + 200] = 128);
|
|
615
615
|
}
|
|
616
616
|
mt.prototype.update = function(s) {
|
|
617
|
-
return wt(this.finalized === !1, "Hash instance finalized"), wt(s, "input must be TypedArray or Buffer"), vt + s.length >
|
|
617
|
+
return wt(this.finalized === !1, "Hash instance finalized"), wt(s, "input must be TypedArray or Buffer"), vt + s.length > W.memory.length && W.realloc(vt + s.length), W.memory.set(s, vt), W.exports.blake2b_update(this.pointer, vt, vt + s.length), this;
|
|
618
618
|
};
|
|
619
619
|
mt.prototype.digest = function(s) {
|
|
620
|
-
if (wt(this.finalized === !1, "Hash instance finalized"), this.finalized = !0, me.push(this.pointer),
|
|
621
|
-
return
|
|
620
|
+
if (wt(this.finalized === !1, "Hash instance finalized"), this.finalized = !0, me.push(this.pointer), W.exports.blake2b_final(this.pointer), !s || s === "binary")
|
|
621
|
+
return W.memory.slice(this.pointer + 128, this.pointer + 128 + this.digestLength);
|
|
622
622
|
if (s === "hex")
|
|
623
|
-
return Cs(
|
|
623
|
+
return Cs(W.memory, this.pointer + 128, this.digestLength);
|
|
624
624
|
wt(s.length >= this.digestLength, "input must be TypedArray or Buffer");
|
|
625
625
|
for (var e = 0; e < this.digestLength; e++)
|
|
626
|
-
s[e] =
|
|
626
|
+
s[e] = W.memory[this.pointer + 128 + e];
|
|
627
627
|
return s;
|
|
628
628
|
};
|
|
629
629
|
mt.prototype.final = mt.prototype.digest;
|
|
630
|
-
mt.WASM =
|
|
630
|
+
mt.WASM = W && W.buffer;
|
|
631
631
|
mt.SUPPORTED = typeof WebAssembly < "u";
|
|
632
632
|
mt.ready = function(s) {
|
|
633
|
-
if (s || (s = ws), !
|
|
633
|
+
if (s || (s = ws), !W)
|
|
634
634
|
return s(new Error("WebAssembly not supported"));
|
|
635
635
|
var e = new Promise(function(t, r) {
|
|
636
|
-
|
|
636
|
+
W.onload(function(n) {
|
|
637
637
|
n ? r() : t(), s(n);
|
|
638
638
|
});
|
|
639
639
|
});
|
|
@@ -960,21 +960,21 @@ var Nt = new Uint8Array([
|
|
|
960
960
|
0,
|
|
961
961
|
0
|
|
962
962
|
]);
|
|
963
|
-
function
|
|
963
|
+
function Wt(s, e, t, r) {
|
|
964
964
|
Nt.fill(0), this.b = new Uint8Array(128), this.h = new Uint32Array(16), this.t = 0, this.c = 0, this.outlen = s, Nt[0] = s, e && (Nt[1] = e.length), Nt[2] = 1, Nt[3] = 1, t && Nt.set(t, 32), r && Nt.set(r, 48);
|
|
965
965
|
for (var n = 0; n < 16; n++)
|
|
966
966
|
this.h[n] = br[n] ^ Sr(Nt, n * 4);
|
|
967
967
|
e && (Qr(this, e), this.c = 128);
|
|
968
968
|
}
|
|
969
|
-
|
|
969
|
+
Wt.prototype.update = function(s) {
|
|
970
970
|
return Ut(s != null, "input must be Uint8Array or Buffer"), Qr(this, s), this;
|
|
971
971
|
};
|
|
972
|
-
|
|
972
|
+
Wt.prototype.digest = function(s) {
|
|
973
973
|
var e = !s || s === "binary" || s === "hex" ? new Uint8Array(this.outlen) : s;
|
|
974
974
|
return Ut(e.length >= this.outlen, "out must have at least outlen bytes of space"), Ss(this, e), s === "hex" ? bs(e) : e;
|
|
975
975
|
};
|
|
976
|
-
|
|
977
|
-
|
|
976
|
+
Wt.prototype.final = Wt.prototype.digest;
|
|
977
|
+
Wt.ready = function(s) {
|
|
978
978
|
ie.ready(function() {
|
|
979
979
|
s();
|
|
980
980
|
});
|
|
@@ -999,7 +999,7 @@ function bs(s) {
|
|
|
999
999
|
function vs(s) {
|
|
1000
1000
|
return s < 16 ? "0" + s.toString(16) : s.toString(16);
|
|
1001
1001
|
}
|
|
1002
|
-
var Dr =
|
|
1002
|
+
var Dr = Wt;
|
|
1003
1003
|
ot.exports = function(e, t, r, n, i) {
|
|
1004
1004
|
return i !== !0 && (Ut(e >= ir, "outlen must be at least " + ir + ", was given " + e), Ut(e <= ar, "outlen must be at most " + ar + ", was given " + e), t != null && Ut(t.length >= or, "key must be at least " + or + ", was given " + t.length), t != null && Ut(t.length <= cr, "key must be at most " + cr + ", was given " + t.length), r != null && Ut(r.length === ur, "salt must be exactly " + ur + ", was given " + r.length), n != null && Ut(n.length === lr, "personal must be exactly " + lr + ", was given " + n.length)), new Dr(e, t, r, n);
|
|
1005
1005
|
};
|
|
@@ -1018,9 +1018,9 @@ var ur = ot.exports.SALTBYTES = 16, lr = ot.exports.PERSONALBYTES = 16;
|
|
|
1018
1018
|
ie.ready(function(s) {
|
|
1019
1019
|
s || (ot.exports.WASM_LOADED = !0, Dr = ie);
|
|
1020
1020
|
});
|
|
1021
|
-
var
|
|
1022
|
-
Object.defineProperty(
|
|
1023
|
-
|
|
1021
|
+
var Jt = {};
|
|
1022
|
+
Object.defineProperty(Jt, "__esModule", { value: !0 });
|
|
1023
|
+
Jt.bech32m = Jt.bech32 = void 0;
|
|
1024
1024
|
const _e = "qpzry9x8gf2tvdw0s3jn54khce6mua7l", kr = {};
|
|
1025
1025
|
for (let s = 0; s < _e.length; s++) {
|
|
1026
1026
|
const e = _e.charAt(s);
|
|
@@ -1150,13 +1150,13 @@ function Tr(s) {
|
|
|
1150
1150
|
fromWords: ks
|
|
1151
1151
|
};
|
|
1152
1152
|
}
|
|
1153
|
-
|
|
1154
|
-
|
|
1153
|
+
Jt.bech32 = Tr("bech32");
|
|
1154
|
+
Jt.bech32m = Tr("bech32m");
|
|
1155
1155
|
var Ts = Te && Te.__importDefault || function(s) {
|
|
1156
1156
|
return s && s.__esModule ? s : { default: s };
|
|
1157
1157
|
};
|
|
1158
1158
|
Object.defineProperty(Br, "__esModule", { value: !0 });
|
|
1159
|
-
const Ns = Ts(ot.exports), le =
|
|
1159
|
+
const Ns = Ts(ot.exports), le = Jt, ve = "asset";
|
|
1160
1160
|
class se {
|
|
1161
1161
|
constructor(e) {
|
|
1162
1162
|
this.hashBuf = e;
|
|
@@ -2971,7 +2971,7 @@ let Bt = class {
|
|
|
2971
2971
|
});
|
|
2972
2972
|
}
|
|
2973
2973
|
if (this._txBuilder.set_inputs(this._txInputsBuilder), (this._mintBuilder.has_native_scripts() || this._mintBuilder.has_plutus_scripts()) && this._txBuilder.set_mint_builder(this._mintBuilder), this._txCertificates.len() > 0 && this._txBuilder.set_certs(this._txCertificates), this._txWithdrawals.len() > 0 && this._txBuilder.set_withdrawals(this._txWithdrawals), this._txBuilder.get_mint_builder() || this.notVisited("redeemValue") === !1) {
|
|
2974
|
-
const e = this._era !== void 0 ?
|
|
2974
|
+
const e = this._era !== void 0 ? Je[this._era] : Je.BABBAGE;
|
|
2975
2975
|
this._txBuilder.calc_script_data_hash(e);
|
|
2976
2976
|
}
|
|
2977
2977
|
}
|
|
@@ -3052,7 +3052,7 @@ Ht([
|
|
|
3052
3052
|
Bt = Ht([
|
|
3053
3053
|
zs
|
|
3054
3054
|
], Bt);
|
|
3055
|
-
const
|
|
3055
|
+
const Ws = (s, e, t) => {
|
|
3056
3056
|
const r = new Map(e);
|
|
3057
3057
|
r.set("lovelace", String(Number(r.get("lovelace")) + Number(t)));
|
|
3058
3058
|
const n = /* @__PURE__ */ new Map();
|
|
@@ -3082,7 +3082,7 @@ const Js = (s, e, t) => {
|
|
|
3082
3082
|
const k = n.get(w);
|
|
3083
3083
|
if (!k)
|
|
3084
3084
|
return;
|
|
3085
|
-
const N =
|
|
3085
|
+
const N = Js(k, v);
|
|
3086
3086
|
if (Number(N) > 0) {
|
|
3087
3087
|
i.add(w), U.delete(w);
|
|
3088
3088
|
for (const T of k.output.amount)
|
|
@@ -3143,7 +3143,7 @@ const Js = (s, e, t) => {
|
|
|
3143
3143
|
v && b.push(v);
|
|
3144
3144
|
}
|
|
3145
3145
|
return b;
|
|
3146
|
-
},
|
|
3146
|
+
}, Js = (s, e) => {
|
|
3147
3147
|
for (const t of s.output.amount)
|
|
3148
3148
|
if (t.unit == e)
|
|
3149
3149
|
return t.quantity;
|
|
@@ -3154,7 +3154,7 @@ var zt = { exports: {} }, Vr = { exports: {} }, $e = { exports: {} };
|
|
|
3154
3154
|
(function(e) {
|
|
3155
3155
|
var t, r = /^-?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/i, n = Math.ceil, i = Math.floor, c = "[BigNumber Error] ", l = c + "Number primitive has more than 15 significant digits: ", p = 1e14, y = 14, B = 9007199254740991, b = [1, 10, 100, 1e3, 1e4, 1e5, 1e6, 1e7, 1e8, 1e9, 1e10, 1e11, 1e12, 1e13], w = 1e7, v = 1e9;
|
|
3156
3156
|
function U(O) {
|
|
3157
|
-
var M, z, X, D = S.prototype = { constructor: S, toString: null, valueOf: null }, F = new S(1), q = 20,
|
|
3157
|
+
var M, z, X, D = S.prototype = { constructor: S, toString: null, valueOf: null }, F = new S(1), q = 20, J = 4, st = -7, ct = 21, Ft = -1e7, At = 1e7, Rt = !1, Zt = 1, kt = 0, xe = {
|
|
3158
3158
|
prefix: "",
|
|
3159
3159
|
groupSize: 3,
|
|
3160
3160
|
secondaryGroupSize: 0,
|
|
@@ -3189,7 +3189,7 @@ var zt = { exports: {} }, Vr = { exports: {} }, $e = { exports: {} };
|
|
|
3189
3189
|
(m = _.indexOf(".")) > -1 && (_ = _.replace(".", "")), (x = _.search(/e/i)) > 0 ? (m < 0 && (m = x), m += +_.slice(x + 1), _ = _.substring(0, x)) : m < 0 && (m = _.length);
|
|
3190
3190
|
} else {
|
|
3191
3191
|
if (Q(u, 2, qt.length, "Base"), u == 10 && we)
|
|
3192
|
-
return A = new S(o), dt(A, q + A.e + 1,
|
|
3192
|
+
return A = new S(o), dt(A, q + A.e + 1, J);
|
|
3193
3193
|
if (_ = String(o), d = typeof o == "number") {
|
|
3194
3194
|
if (o * 0 != 0)
|
|
3195
3195
|
return X(A, _, d, u);
|
|
@@ -3241,7 +3241,7 @@ var zt = { exports: {} }, Vr = { exports: {} }, $e = { exports: {} };
|
|
|
3241
3241
|
var u, h;
|
|
3242
3242
|
if (o != null)
|
|
3243
3243
|
if (typeof o == "object") {
|
|
3244
|
-
if (o.hasOwnProperty(u = "DECIMAL_PLACES") && (h = o[u], Q(h, 0, v, u), q = h), o.hasOwnProperty(u = "ROUNDING_MODE") && (h = o[u], Q(h, 0, 8, u),
|
|
3244
|
+
if (o.hasOwnProperty(u = "DECIMAL_PLACES") && (h = o[u], Q(h, 0, v, u), q = h), o.hasOwnProperty(u = "ROUNDING_MODE") && (h = o[u], Q(h, 0, 8, u), J = h), o.hasOwnProperty(u = "EXPONENTIAL_AT") && (h = o[u], h && h.pop ? (Q(h[0], -v, 0, u), Q(h[1], 0, v, u), st = h[0], ct = h[1]) : (Q(h, -v, v, u), st = -(ct = h < 0 ? -h : h))), o.hasOwnProperty(u = "RANGE"))
|
|
3245
3245
|
if (h = o[u], h && h.pop)
|
|
3246
3246
|
Q(h[0], -v, -1, u), Q(h[1], 1, v, u), Ft = h[0], At = h[1];
|
|
3247
3247
|
else if (Q(h, -v, v, u), h)
|
|
@@ -3273,7 +3273,7 @@ var zt = { exports: {} }, Vr = { exports: {} }, $e = { exports: {} };
|
|
|
3273
3273
|
throw Error(c + "Object expected: " + o);
|
|
3274
3274
|
return {
|
|
3275
3275
|
DECIMAL_PLACES: q,
|
|
3276
|
-
ROUNDING_MODE:
|
|
3276
|
+
ROUNDING_MODE: J,
|
|
3277
3277
|
EXPONENTIAL_AT: [st, ct],
|
|
3278
3278
|
RANGE: [Ft, At],
|
|
3279
3279
|
CRYPTO: Rt,
|
|
@@ -3362,7 +3362,7 @@ var zt = { exports: {} }, Vr = { exports: {} }, $e = { exports: {} };
|
|
|
3362
3362
|
return d.reverse();
|
|
3363
3363
|
}
|
|
3364
3364
|
return function(h, I, f, m, x) {
|
|
3365
|
-
var d, g, _, A, C, P, K, L, Z = h.indexOf("."), et = q, V =
|
|
3365
|
+
var d, g, _, A, C, P, K, L, Z = h.indexOf("."), et = q, V = J;
|
|
3366
3366
|
for (Z >= 0 && (A = kt, kt = 0, h = h.replace(".", ""), L = new S(I), P = L.pow(h.length - Z), kt = A, L.c = u(
|
|
3367
3367
|
Y(N(P.c), P.e, "0"),
|
|
3368
3368
|
10,
|
|
@@ -3452,7 +3452,7 @@ var zt = { exports: {} }, Vr = { exports: {} }, $e = { exports: {} };
|
|
|
3452
3452
|
}();
|
|
3453
3453
|
function Ce(o, u, h, I) {
|
|
3454
3454
|
var f, m, x, d, g;
|
|
3455
|
-
if (h == null ? h =
|
|
3455
|
+
if (h == null ? h = J : Q(h, 0, 8), !o.c)
|
|
3456
3456
|
return o.toString();
|
|
3457
3457
|
if (f = o.c[0], x = o.e, u == null)
|
|
3458
3458
|
g = N(o.c), g = I == 1 || I == 2 && (x <= st || x >= ct) ? j(g, x) : Y(g, x, "0");
|
|
@@ -3554,7 +3554,7 @@ var zt = { exports: {} }, Vr = { exports: {} }, $e = { exports: {} };
|
|
|
3554
3554
|
}, D.decimalPlaces = D.dp = function(o, u) {
|
|
3555
3555
|
var h, I, f, m = this;
|
|
3556
3556
|
if (o != null)
|
|
3557
|
-
return Q(o, 0, v), u == null ? u =
|
|
3557
|
+
return Q(o, 0, v), u == null ? u = J : Q(u, 0, 8), dt(new S(m), o + m.e + 1, u);
|
|
3558
3558
|
if (!(h = m.c))
|
|
3559
3559
|
return null;
|
|
3560
3560
|
if (I = ((f = h.length - 1) - k(this.e / y)) * y, f = h[f])
|
|
@@ -3562,7 +3562,7 @@ var zt = { exports: {} }, Vr = { exports: {} }, $e = { exports: {} };
|
|
|
3562
3562
|
;
|
|
3563
3563
|
return I < 0 && (I = 0), I;
|
|
3564
3564
|
}, D.dividedBy = D.div = function(o, u) {
|
|
3565
|
-
return M(this, new S(o, u), q,
|
|
3565
|
+
return M(this, new S(o, u), q, J);
|
|
3566
3566
|
}, D.dividedToIntegerBy = D.idiv = function(o, u) {
|
|
3567
3567
|
return M(this, new S(o, u), 0, 1);
|
|
3568
3568
|
}, D.exponentiatedBy = D.pow = function(o, u) {
|
|
@@ -3599,10 +3599,10 @@ var zt = { exports: {} }, Vr = { exports: {} }, $e = { exports: {} };
|
|
|
3599
3599
|
}
|
|
3600
3600
|
C = C.times(C), m ? C.c && C.c.length > m && (C.c.length = m) : I && (C = C.mod(u));
|
|
3601
3601
|
}
|
|
3602
|
-
return I ? A : (g && (A = F.div(A)), u ? A.mod(u) : m ? dt(A, kt,
|
|
3602
|
+
return I ? A : (g && (A = F.div(A)), u ? A.mod(u) : m ? dt(A, kt, J, x) : A);
|
|
3603
3603
|
}, D.integerValue = function(o) {
|
|
3604
3604
|
var u = new S(this);
|
|
3605
|
-
return o == null ? o =
|
|
3605
|
+
return o == null ? o = J : Q(o, 0, 8), dt(u, u.e + 1, o);
|
|
3606
3606
|
}, D.isEqualTo = D.eq = function(o, u) {
|
|
3607
3607
|
return T(this, new S(o, u)) === 0;
|
|
3608
3608
|
}, D.isFinite = function() {
|
|
@@ -3636,7 +3636,7 @@ var zt = { exports: {} }, Vr = { exports: {} }, $e = { exports: {} };
|
|
|
3636
3636
|
if (!A || !C)
|
|
3637
3637
|
return A ? (o.s = -u, o) : new S(C ? x : NaN);
|
|
3638
3638
|
if (!A[0] || !C[0])
|
|
3639
|
-
return C[0] ? (o.s = -u, o) : new S(A[0] ? x :
|
|
3639
|
+
return C[0] ? (o.s = -u, o) : new S(A[0] ? x : J == 3 ? -0 : 0);
|
|
3640
3640
|
}
|
|
3641
3641
|
if (g = k(g), _ = k(_), A = A.slice(), d = g - _) {
|
|
3642
3642
|
for ((m = d < 0) ? (d = -d, f = A) : (_ = g, f = C), f.reverse(), u = d; u--; f.push(0))
|
|
@@ -3661,7 +3661,7 @@ var zt = { exports: {} }, Vr = { exports: {} }, $e = { exports: {} };
|
|
|
3661
3661
|
}
|
|
3662
3662
|
for (; A[0] == 0; A.splice(0, 1), --_)
|
|
3663
3663
|
;
|
|
3664
|
-
return A[0] ? Be(o, A, _) : (o.s =
|
|
3664
|
+
return A[0] ? Be(o, A, _) : (o.s = J == 3 ? -1 : 1, o.c = [o.e = 0], o);
|
|
3665
3665
|
}, D.modulo = D.mod = function(o, u) {
|
|
3666
3666
|
var h, I, f = this;
|
|
3667
3667
|
return o = new S(o, u), !f.c || !o.s || o.c && !o.c[0] ? new S(NaN) : !o.c || f.c && !f.c[0] ? new S(f) : (Zt == 9 ? (I = o.s, o.s = 1, h = M(f, o, 0, 3), o.s = I, h.s *= I) : h = M(f, o, 0, Zt), o = f.minus(h.times(o)), !o.c[0] && Zt == 1 && (o.s = f.s), o);
|
|
@@ -3704,7 +3704,7 @@ var zt = { exports: {} }, Vr = { exports: {} }, $e = { exports: {} };
|
|
|
3704
3704
|
}, D.precision = D.sd = function(o, u) {
|
|
3705
3705
|
var h, I, f, m = this;
|
|
3706
3706
|
if (o != null && o !== !!o)
|
|
3707
|
-
return Q(o, 1, v), u == null ? u =
|
|
3707
|
+
return Q(o, 1, v), u == null ? u = J : Q(u, 0, 8), dt(new S(m), o, u);
|
|
3708
3708
|
if (!(h = m.c))
|
|
3709
3709
|
return null;
|
|
3710
3710
|
if (f = h.length - 1, I = f * y + 1, f = h[f]) {
|
|
@@ -3734,7 +3734,7 @@ var zt = { exports: {} }, Vr = { exports: {} }, $e = { exports: {} };
|
|
|
3734
3734
|
break;
|
|
3735
3735
|
}
|
|
3736
3736
|
}
|
|
3737
|
-
return dt(h, h.e + q + 1,
|
|
3737
|
+
return dt(h, h.e + q + 1, J, o);
|
|
3738
3738
|
}, D.toExponential = function(o, u) {
|
|
3739
3739
|
return o != null && (Q(o, 0, v), o++), Ce(this, o, u, 1);
|
|
3740
3740
|
}, D.toFixed = function(o, u) {
|
|
@@ -3766,8 +3766,8 @@ var zt = { exports: {} }, Vr = { exports: {} }, $e = { exports: {} };
|
|
|
3766
3766
|
return new S(K);
|
|
3767
3767
|
for (u = new S(F), _ = h = new S(F), I = g = new S(F), P = N(L), m = u.e = P.length - K.e - 1, u.c[0] = b[(x = m % y) < 0 ? y + x : x], o = !o || d.comparedTo(u) > 0 ? m > 0 ? u : _ : d, x = At, At = 1 / 0, d = new S(P), g.c[0] = 0; A = M(d, u, 0, 1), f = h.plus(A.times(I)), f.comparedTo(o) != 1; )
|
|
3768
3768
|
h = I, I = f, _ = g.plus(A.times(f = _)), g = f, u = d.minus(A.times(f = u)), d = f;
|
|
3769
|
-
return f = M(o.minus(h), I, 0, 1), g = g.plus(f.times(_)), h = h.plus(f.times(I)), g.s = _.s = K.s, m = m * 2, C = M(_, I, m,
|
|
3770
|
-
M(g, h, m,
|
|
3769
|
+
return f = M(o.minus(h), I, 0, 1), g = g.plus(f.times(_)), h = h.plus(f.times(I)), g.s = _.s = K.s, m = m * 2, C = M(_, I, m, J).minus(K).abs().comparedTo(
|
|
3770
|
+
M(g, h, m, J).minus(K).abs()
|
|
3771
3771
|
) < 1 ? [_, I] : [g, h], At = x, C;
|
|
3772
3772
|
}, D.toNumber = function() {
|
|
3773
3773
|
return +St(this);
|
|
@@ -3775,7 +3775,7 @@ var zt = { exports: {} }, Vr = { exports: {} }, $e = { exports: {} };
|
|
|
3775
3775
|
return o != null && Q(o, 1, v), Ce(this, o, u, 2);
|
|
3776
3776
|
}, D.toString = function(o) {
|
|
3777
3777
|
var u, h = this, I = h.s, f = h.e;
|
|
3778
|
-
return f === null ? I ? (u = "Infinity", I < 0 && (u = "-" + u)) : u = "NaN" : (o == null ? u = f <= st || f >= ct ? j(N(h.c), f) : Y(N(h.c), f, "0") : o === 10 && we ? (h = dt(new S(h), q + f + 1,
|
|
3778
|
+
return f === null ? I ? (u = "Infinity", I < 0 && (u = "-" + u)) : u = "NaN" : (o == null ? u = f <= st || f >= ct ? j(N(h.c), f) : Y(N(h.c), f, "0") : o === 10 && we ? (h = dt(new S(h), q + f + 1, J), u = Y(N(h.c), h.e, "0")) : (Q(o, 2, qt.length, "Base"), u = z(Y(N(h.c), f, "0"), 10, o, I, !0)), I < 0 && h.c[0] && (u = "-" + u)), u;
|
|
3779
3779
|
}, D.valueOf = D.toJSON = function() {
|
|
3780
3780
|
return St(this);
|
|
3781
3781
|
}, D._isBigNumber = !0, O != null && S.set(O), S;
|
|
@@ -3795,18 +3795,18 @@ var zt = { exports: {} }, Vr = { exports: {} }, $e = { exports: {} };
|
|
|
3795
3795
|
return F.slice(0, D + 1 || 1);
|
|
3796
3796
|
}
|
|
3797
3797
|
function T(O, M) {
|
|
3798
|
-
var z, X, D = O.c, F = M.c, q = O.s,
|
|
3799
|
-
if (!q || !
|
|
3798
|
+
var z, X, D = O.c, F = M.c, q = O.s, J = M.s, st = O.e, ct = M.e;
|
|
3799
|
+
if (!q || !J)
|
|
3800
3800
|
return null;
|
|
3801
3801
|
if (z = D && !D[0], X = F && !F[0], z || X)
|
|
3802
|
-
return z ? X ? 0 : -
|
|
3803
|
-
if (q !=
|
|
3802
|
+
return z ? X ? 0 : -J : q;
|
|
3803
|
+
if (q != J)
|
|
3804
3804
|
return q;
|
|
3805
3805
|
if (z = q < 0, X = st == ct, !D || !F)
|
|
3806
3806
|
return X ? 0 : !D ^ z ? 1 : -1;
|
|
3807
3807
|
if (!X)
|
|
3808
3808
|
return st > ct ^ z ? 1 : -1;
|
|
3809
|
-
for (
|
|
3809
|
+
for (J = (st = D.length) < (ct = F.length) ? st : ct, q = 0; q < J; q++)
|
|
3810
3810
|
if (D[q] != F[q])
|
|
3811
3811
|
return D[q] > F[q] ^ z ? 1 : -1;
|
|
3812
3812
|
return st == ct ? 0 : st > ct ^ z ? 1 : -1;
|
|
@@ -4384,7 +4384,7 @@ class en {
|
|
|
4384
4384
|
quantity: String(c.amount)
|
|
4385
4385
|
}, p = Number(i.get(l.unit)) || 0;
|
|
4386
4386
|
return i.set(l.unit, String(p - Number(l.quantity))), i;
|
|
4387
|
-
}, r),
|
|
4387
|
+
}, r), Ws(e, r, t).forEach((i) => {
|
|
4388
4388
|
const c = {
|
|
4389
4389
|
type: "PubKey",
|
|
4390
4390
|
txIn: {
|
|
@@ -4833,7 +4833,7 @@ class rt {
|
|
|
4833
4833
|
const F = (D = j.as_move_instantaneous_rewards_cert()) == null ? void 0 : D.move_instantaneous_reward().as_to_stake_creds();
|
|
4834
4834
|
if (F)
|
|
4835
4835
|
for (let q = 0; q < F.len(); q += 1) {
|
|
4836
|
-
const
|
|
4836
|
+
const J = F.keys().get(q), st = J.kind() === a.StakeCredKind.Key ? J.to_keyhash() : void 0;
|
|
4837
4837
|
st && Y.push(st.to_hex());
|
|
4838
4838
|
}
|
|
4839
4839
|
break;
|
|
@@ -4923,6 +4923,8 @@ class Qe {
|
|
|
4923
4923
|
throw new Error("getUsedCollateral not implemented.");
|
|
4924
4924
|
}
|
|
4925
4925
|
async getUsedUTxOs(e = 0) {
|
|
4926
|
+
if (!this._fetcher)
|
|
4927
|
+
throw new Error("[AppWallet] Fetcher is required to fetch UTxOs. Please provide a fetcher.");
|
|
4926
4928
|
const t = this._wallet.getAccount(e, pt);
|
|
4927
4929
|
return (await this._fetcher.fetchAddressUTxOs(t.enterpriseAddress)).map((n) => It(n));
|
|
4928
4930
|
}
|
|
@@ -4935,6 +4937,8 @@ class Qe {
|
|
|
4935
4937
|
}
|
|
4936
4938
|
async signTx(e, t = !1, r = 0) {
|
|
4937
4939
|
try {
|
|
4940
|
+
if (!this._fetcher)
|
|
4941
|
+
throw new Error("[AppWallet] Fetcher is required to fetch UTxOs. Please provide a fetcher.");
|
|
4938
4942
|
const n = this._wallet.getAccount(r, pt), i = await this._fetcher.fetchAddressUTxOs(n.enterpriseAddress), c = this._wallet.signTx(r, pt, i, e, t), l = _t(e), p = l.witness_set(), y = Me(p, c);
|
|
4939
4943
|
return p.set_vkeys(y), a.Transaction.new(l.body(), p, l.auxiliary_data()).to_hex();
|
|
4940
4944
|
} catch (n) {
|
|
@@ -4945,6 +4949,8 @@ class Qe {
|
|
|
4945
4949
|
return console.log("unimplemented", e, t), [];
|
|
4946
4950
|
}
|
|
4947
4951
|
submitTx(e) {
|
|
4952
|
+
if (!this._submitter)
|
|
4953
|
+
throw new Error("[AppWallet] Submitter is required to submit transactions. Please provide a submitter.");
|
|
4948
4954
|
return this._submitter.submitTx(e);
|
|
4949
4955
|
}
|
|
4950
4956
|
static brew(e = 256) {
|
|
@@ -2,25 +2,26 @@ import { csl } from '@mesh/core';
|
|
|
2
2
|
import { IFetcher, IInitiator, ISigner, ISubmitter } from '@mesh/common/contracts';
|
|
3
3
|
import type { Address, TransactionUnspentOutput } from '@mesh/core';
|
|
4
4
|
import type { DataSignature } from '@mesh/common/types';
|
|
5
|
+
export declare type AppWalletKeyType = {
|
|
6
|
+
type: 'root';
|
|
7
|
+
bech32: string;
|
|
8
|
+
} | {
|
|
9
|
+
type: 'cli';
|
|
10
|
+
payment: string;
|
|
11
|
+
stake?: string;
|
|
12
|
+
} | {
|
|
13
|
+
type: 'mnemonic';
|
|
14
|
+
words: string[];
|
|
15
|
+
};
|
|
5
16
|
export declare type CreateAppWalletOptions = {
|
|
6
17
|
networkId: number;
|
|
7
|
-
fetcher
|
|
8
|
-
submitter
|
|
9
|
-
key:
|
|
10
|
-
type: 'root';
|
|
11
|
-
bech32: string;
|
|
12
|
-
} | {
|
|
13
|
-
type: 'cli';
|
|
14
|
-
payment: string;
|
|
15
|
-
stake?: string;
|
|
16
|
-
} | {
|
|
17
|
-
type: 'mnemonic';
|
|
18
|
-
words: string[];
|
|
19
|
-
};
|
|
18
|
+
fetcher?: IFetcher;
|
|
19
|
+
submitter?: ISubmitter;
|
|
20
|
+
key: AppWalletKeyType;
|
|
20
21
|
};
|
|
21
22
|
export declare class AppWallet implements IInitiator, ISigner, ISubmitter {
|
|
22
|
-
private readonly _fetcher
|
|
23
|
-
private readonly _submitter
|
|
23
|
+
private readonly _fetcher?;
|
|
24
|
+
private readonly _submitter?;
|
|
24
25
|
private readonly _wallet;
|
|
25
26
|
constructor(options: CreateAppWalletOptions);
|
|
26
27
|
getBaseAddress(accountIndex?: number): string;
|
|
@@ -3,8 +3,8 @@ import type { Address, TransactionUnspentOutput } from '@mesh/core';
|
|
|
3
3
|
import type { Asset, AssetExtended, DataSignature, UTxO } from '@mesh/common/types';
|
|
4
4
|
export declare type CreateMeshWalletOptions = {
|
|
5
5
|
networkId: number;
|
|
6
|
-
fetcher
|
|
7
|
-
submitter
|
|
6
|
+
fetcher?: IFetcher;
|
|
7
|
+
submitter?: ISubmitter;
|
|
8
8
|
key: {
|
|
9
9
|
type: 'root';
|
|
10
10
|
bech32: string;
|
package/package.json
CHANGED