@meshsdk/wallet 1.6.1 → 1.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +30 -1
- package/dist/index.d.ts +30 -1
- package/dist/index.js +1 -1
- package/package.json +8 -6
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";var P=Object.defineProperty;var V=Object.getOwnPropertyDescriptor;var z=Object.getOwnPropertyNames;var G=Object.prototype.hasOwnProperty;var F=(o,e)=>{for(var t in e)P(o,t,{get:e[t],enumerable:!0})},M=(o,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of z(e))!G.call(o,s)&&s!==t&&P(o,s,{get:()=>e[s],enumerable:!(r=V(e,s))||r.enumerable});return o};var q=o=>M(P({},"__esModule",{value:!0}),o);var te={};F(te,{AppWallet:()=>E,BrowserWallet:()=>C,EmbeddedWallet:()=>p,MeshWallet:()=>B,WalletStaticMethods:()=>y});module.exports=q(te);var A=require("@meshsdk/core-cst");function O(o){if(!Number.isSafeInteger(o))throw new Error(`Wrong integer: ${o}`)}function j(o){return o instanceof Uint8Array||o!=null&&typeof o=="object"&&o.constructor.name==="Uint8Array"}function J(...o){let e=n=>n,t=(n,c)=>d=>n(c(d)),r=o.map(n=>n.encode).reduceRight(t,e),s=o.map(n=>n.decode).reduce(t,e);return{encode:r,decode:s}}function Y(o){return{encode:e=>{if(!Array.isArray(e)||e.length&&typeof e[0]!="number")throw new Error("alphabet.encode input should be an array of numbers");return e.map(t=>{if(t<0||t>=o.length)throw new Error(`Digit index outside alphabet: ${t} (alphabet: ${o.length})`);return o[t]})},decode:e=>{if(!Array.isArray(e)||e.length&&typeof e[0]!="string")throw new Error("alphabet.decode input should be array of strings");return e.map(t=>{if(typeof t!="string")throw new Error(`alphabet.decode: not string element=${t}`);let r=o.indexOf(t);if(r===-1)throw new Error(`Unknown letter: "${t}". Allowed: ${o}`);return r})}}}function Q(o=""){if(typeof o!="string")throw new Error("join separator should be string");return{encode:e=>{if(!Array.isArray(e)||e.length&&typeof e[0]!="string")throw new Error("join.encode input should be array of strings");for(let t of e)if(typeof t!="string")throw new Error(`join.encode: non-string input=${t}`);return e.join(o)},decode:e=>{if(typeof e!="string")throw new Error("join.decode input should be string");return e.split(o)}}}var N=(o,e)=>e?N(e,o%e):o,U=(o,e)=>o+(e-N(o,e));function v(o,e,t,r){if(!Array.isArray(o))throw new Error("convertRadix2: data should be array");if(e<=0||e>32)throw new Error(`convertRadix2: wrong from=${e}`);if(t<=0||t>32)throw new Error(`convertRadix2: wrong to=${t}`);if(U(e,t)>32)throw new Error(`convertRadix2: carry overflow from=${e} to=${t} carryBits=${U(e,t)}`);let s=0,n=0,c=2**t-1,d=[];for(let u of o){if(u>=2**e)throw new Error(`convertRadix2: invalid data word=${u} from=${e}`);if(s=s<<e|u,n+e>32)throw new Error(`convertRadix2: carry overflow pos=${n} from=${e}`);for(n+=e;n>=t;n-=t)d.push((s>>n-t&c)>>>0);s&=2**n-1}if(s=s<<t-n&c,!r&&n>=e)throw new Error("Excess padding");if(!r&&s)throw new Error(`Non-zero padding: ${s}`);return r&&n>0&&d.push(s>>>0),d}function X(o,e=!1){if(o<=0||o>32)throw new Error("radix2: bits should be in (0..32]");if(U(8,o)>32||U(o,8)>32)throw new Error("radix2: carry overflow");return{encode:t=>{if(!j(t))throw new Error("radix2.encode input should be Uint8Array");return v(Array.from(t),8,o,!e)},decode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="number")throw new Error("radix2.decode input should be array of numbers");return Uint8Array.from(v(t,o,8,e))}}}function $(o){if(typeof o!="function")throw new Error("unsafeWrapper fn should be function");return function(...e){try{return o.apply(null,e)}catch{}}}var _=J(Y("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),Q("")),D=[996825010,642813549,513874426,1027748829,705979059];function I(o){let e=o>>25,t=(o&33554431)<<5;for(let r=0;r<D.length;r++)(e>>r&1)===1&&(t^=D[r]);return t}function H(o,e,t=1){let r=o.length,s=1;for(let n=0;n<r;n++){let c=o.charCodeAt(n);if(c<33||c>126)throw new Error(`Invalid prefix (${o})`);s=I(s)^c>>5}s=I(s);for(let n=0;n<r;n++)s=I(s)^o.charCodeAt(n)&31;for(let n of e)s=I(s)^n;for(let n=0;n<6;n++)s=I(s);return s^=t,_.encode(v([s%2**30],30,5,!1))}function Z(o){let e=o==="bech32"?1:734539939,t=X(5),r=t.decode,s=t.encode,n=$(r);function c(l,g,h=90){if(typeof l!="string")throw new Error(`bech32.encode prefix should be string, not ${typeof l}`);if(!Array.isArray(g)||g.length&&typeof g[0]!="number")throw new Error(`bech32.encode words should be array of numbers, not ${typeof g}`);if(l.length===0)throw new TypeError(`Invalid prefix length ${l.length}`);let x=l.length+7+g.length;if(h!==!1&&x>h)throw new TypeError(`Length ${x} exceeds limit ${h}`);let T=l.toLowerCase(),k=H(T,g,e);return`${T}1${_.encode(g)}${k}`}function d(l,g=90){if(typeof l!="string")throw new Error(`bech32.decode input should be string, not ${typeof l}`);if(l.length<8||g!==!1&&l.length>g)throw new TypeError(`Wrong string length: ${l.length} (${l}). Expected (8..${g})`);let h=l.toLowerCase();if(l!==h&&l!==l.toUpperCase())throw new Error("String must be lowercase or uppercase");let x=h.lastIndexOf("1");if(x===0||x===-1)throw new Error('Letter "1" must be present between prefix and data only');let T=h.slice(0,x),k=h.slice(x+1);if(k.length<6)throw new Error("Data must be at least 6 characters long");let W=_.decode(k).slice(0,-6),K=H(T,W,e);if(!k.endsWith(K))throw new Error(`Invalid checksum in ${l}: expected "${K}"`);return{prefix:T,words:W}}let u=$(d);function S(l){let{prefix:g,words:h}=d(l,!1);return{prefix:g,words:h,bytes:r(h)}}return{encode:c,decode:d,decodeToBytes:S,decodeUnsafe:u,fromWords:r,fromWordsUnsafe:n,toWords:s}}var R=Z("bech32");var b=require("@meshsdk/common"),i=require("@meshsdk/core-cst"),y=class{static privateKeyToEntropy(e){let t=R.decodeToBytes(e).bytes,r=i.Bip32PrivateKey.fromBytes(t);return(0,b.bytesToHex)(r.bytes())}static mnemonicToEntropy(e){let t=(0,b.mnemonicToEntropy)(e.join(" ")),r=(0,i.buildBip32PrivateKey)(t);return(0,b.bytesToHex)(r.bytes())}static signingKeyToEntropy(e,t){return[e.startsWith("5820")?e.slice(4):e,t.startsWith("5820")?t.slice(4):t]}static getAddresses(e,t,r=0){let s=(0,i.buildBaseAddress)(r,i.Hash28ByteBase16.fromEd25519KeyHashHex((0,i.Ed25519KeyHashHex)(e.toPublicKey().hash().toString("hex"))),i.Hash28ByteBase16.fromEd25519KeyHashHex((0,i.Ed25519KeyHashHex)(t.toPublicKey().hash().toString("hex")))),n=(0,i.buildEnterpriseAddress)(r,i.Hash28ByteBase16.fromEd25519KeyHashHex((0,i.Ed25519KeyHashHex)(e.toPublicKey().hash().toString("hex")))),c=(0,i.buildRewardAddress)(r,i.Hash28ByteBase16.fromEd25519KeyHashHex((0,i.Ed25519KeyHashHex)(t.toPublicKey().hash().toString("hex"))));return{baseAddress:s.toAddress(),enterpriseAddress:n.toAddress(),rewardAddress:c.toAddress()}}static generateMnemonic(e=256){return(0,b.generateMnemonic)(e).split(" ")}static addWitnessSets(e,t){let r=(0,i.deserializeTx)(e),s=r.witnessSet(),n=s.vkeys(),c=n?[...n.values(),...t]:t;return s.setVkeys(i.Serialization.CborSet.fromCore(c.map(d=>d.toCore()),i.VkeyWitness.fromCore)),new i.Transaction(r.body(),s,r.auxiliaryData()).toCbor()}},p=class extends y{_entropy;_networkId;constructor(e){switch(super(),this._networkId=e.networkId,e.key.type){case"mnemonic":this._entropy=y.mnemonicToEntropy(e.key.words);break;case"root":this._entropy=y.privateKeyToEntropy(e.key.bech32);break;case"cli":this._entropy=y.signingKeyToEntropy(e.key.payment,e.key.stake??"f0".repeat(32));break}}getAccount(e=0,t=0){if(this._entropy==null)throw new Error("[EmbeddedWallet] No keys initialized");let{paymentKey:r,stakeKey:s}=(0,i.buildKeys)(this._entropy,e,t),{baseAddress:n,enterpriseAddress:c,rewardAddress:d}=y.getAddresses(r,s,this._networkId);return{baseAddress:n,enterpriseAddress:c,rewardAddress:d,baseAddressBech32:n.toBech32(),enterpriseAddressBech32:c.toBech32(),rewardAddressBech32:d.toBech32(),paymentKey:r,stakeKey:s,paymentKeyHex:r.toBytes().toString("hex"),stakeKeyHex:s.toBytes().toString("hex")}}getNetworkId(){return this._networkId}signData(e,t,r=0,s=0){try{let n=this.getAccount(r,s);if([n.baseAddress,n.enterpriseAddress,n.rewardAddress].find(d=>d.toBech32()===e)===void 0)throw new Error(`[EmbeddedWallet] Address: ${e} doesn't belong to this account.`);return(0,i.signData)(t,n.paymentKey)}catch(n){throw new Error(`[EmbeddedWallet] An error occurred during signData: ${n}.`)}}signTx(e,t=0,r=0){try{let s=(0,i.deserializeTxHash)((0,i.resolveTxHash)(e)),n=this.getAccount(t,r);return new i.VkeyWitness((0,i.Ed25519PublicKeyHex)(n.paymentKey.toPublicKey().toBytes().toString("hex")),(0,i.Ed25519SignatureHex)(n.paymentKey.sign(Buffer.from(s,"hex")).toString("hex")))}catch(s){throw new Error(`[EmbeddedWallet] An error occurred during signTx: ${s}.`)}}};var E=class{_fetcher;_submitter;_wallet;constructor(e){switch(this._fetcher=e.fetcher,this._submitter=e.submitter,e.key.type){case"mnemonic":this._wallet=new p({networkId:e.networkId,key:{type:"mnemonic",words:e.key.words}});break;case"root":this._wallet=new p({networkId:e.networkId,key:{type:"root",bech32:e.key.bech32}});break;case"cli":this._wallet=new p({networkId:e.networkId,key:{type:"cli",payment:e.key.payment,stake:e.key.stake}})}}async getCollateralUnspentOutput(e=0,t="payment"){let s=(await this.getUnspentOutputs(e,t)).filter(n=>n.output().amount().multiasset()===void 0);s.sort((n,c)=>Number(n.output().amount().coin())-Number(c.output().amount().coin()));for(let n of s)if(Number(n.output().amount().coin())>=5e6)return[n];return[]}getEnterpriseAddress(e=0,t=0){return this._wallet.getAccount(e,t).enterpriseAddressBech32}getPaymentAddress(e=0,t=0){return this._wallet.getAccount(e,t).baseAddressBech32}getRewardAddress(e=0,t=0){return this._wallet.getAccount(e,t).rewardAddressBech32}getNetworkId(){return this._wallet.getNetworkId()}getUsedAddress(e=0,t=0,r="payment"){return r==="enterprise"?(0,A.toAddress)(this.getEnterpriseAddress(e,t)):(0,A.toAddress)(this.getPaymentAddress(e,t))}async getUnspentOutputs(e=0,t="payment"){if(!this._fetcher)throw new Error("[AppWallet] Fetcher is required to fetch UTxOs. Please provide a fetcher.");let r=this._wallet.getAccount(e);return(await this._fetcher.fetchAddressUTxOs(t=="enterprise"?r.enterpriseAddressBech32:r.baseAddressBech32)).map(n=>(0,A.toTxUnspentOutput)(n))}signData(e,t,r=0,s=0){try{return this._wallet.signData(e,t,r,s)}catch(n){throw new Error(`[AppWallet] An error occurred during signData: ${n}.`)}}signTx(e,t=!1,r=0,s=0){try{let n=(0,A.deserializeTx)(e);if(!t&&n.witnessSet().vkeys()!==void 0&&n.witnessSet().vkeys().size()!==0)throw new Error("Signatures already exist in the transaction in a non partial sign call");let c=this._wallet.signTx(e,r,s);return p.addWitnessSets(e,[c])}catch(n){throw new Error(`[AppWallet] An error occurred during signTx: ${n}.`)}}signTxSync(e,t=!1,r=0,s=0){try{return"signedTx"}catch(n){throw new Error(`[AppWallet] An error occurred during signTx: ${n}.`)}}async signTxs(e,t){throw new Error("[AppWallet] signTxs() is not implemented.")}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 p.generateMnemonic(e)}};var w=require("@meshsdk/common"),a=require("@meshsdk/core-cst"),C=class o{constructor(e,t){this._walletInstance=e;this._walletName=t;this.walletInstance={...e}}walletInstance;static getInstalledWallets(){if(window===void 0)return[];if(window.cardano===void 0)return[];let e=[];for(let t in window.cardano)try{let r=window.cardano[t];if(r===void 0||r.name===void 0||r.icon===void 0||r.apiVersion===void 0)continue;e.push({id:t,name:r.name,icon:r.icon,version:r.apiVersion})}catch{}return e}static async enable(e){try{let t=await o.resolveInstance(e);if(t!==void 0)return new o(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(){let e=await this._walletInstance.getBalance();return(0,a.fromValue)((0,a.deserializeValue)(e))}async getChangeAddress(){let e=await this._walletInstance.getChangeAddress();return(0,a.addressToBech32)((0,a.deserializeAddress)(e))}async getCollateral(){return(await this.getCollateralUnspentOutput()).map(t=>(0,a.fromTxUnspentOutput)(t))}getNetworkId(){return this._walletInstance.getNetworkId()}async getRewardAddresses(){return(await this._walletInstance.getRewardAddresses()).map(t=>(0,a.addressToBech32)((0,a.deserializeAddress)(t)))}async getUnusedAddresses(){return(await this._walletInstance.getUnusedAddresses()).map(t=>(0,a.addressToBech32)((0,a.deserializeAddress)(t)))}async getUsedAddresses(){return(await this._walletInstance.getUsedAddresses()).map(t=>(0,a.addressToBech32)((0,a.deserializeAddress)(t)))}async getUsedCollateral(e=w.DEFAULT_PROTOCOL_PARAMETERS.maxCollateralInputs){return(await this._walletInstance.experimental.getCollateral()??[]).map(r=>(0,a.deserializeTxUnspentOutput)(r)).slice(0,e)}async getUtxos(){return(await this.getUsedUTxOs()).map(t=>(0,a.fromTxUnspentOutput)(t))}signData(e,t){let r=(0,a.toAddress)(e).toBytes().toString();return this._walletInstance.signData(r,(0,w.fromUTF8)(t))}async signTx(e,t=!1){let r=await this._walletInstance.signTx(e,t);return console.log("witness",r),o.addBrowserWitnesses(e,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(n=>({cbor:n,partialSign:t}))):this._walletInstance.experimental.signTxs&&(r=await this._walletInstance.experimental.signTxs(e.map(n=>({cbor:n,partialSign:t}))));break}if(!r)throw new Error("Wallet does not support signTxs");let s=[];for(let n=0;n<r.length;n++){let c=e[n],d=r[n],u=o.addBrowserWitnesses(c,d);s.push(u)}return s}submitTx(e){return this._walletInstance.submitTx(e)}async getUsedAddress(){let e=await this._walletInstance.getUsedAddresses();if(e.length===0)throw new Error("No used addresses found");return(0,a.deserializeAddress)(e[0])}async getCollateralUnspentOutput(){return(await this._walletInstance.experimental.getCollateral()??[]).map(t=>(0,a.deserializeTxUnspentOutput)(t))}async getUsedUTxOs(){return(await this._walletInstance.getUtxos()??[]).map(t=>(0,a.deserializeTxUnspentOutput)(t))}async getAssets(){return(await this.getBalance()).filter(t=>t.unit!=="lovelace").map(t=>{let r=t.unit.slice(0,w.POLICY_ID_LENGTH),s=t.unit.slice(w.POLICY_ID_LENGTH),n=(0,w.resolveFingerprint)(r,s);return{unit:t.unit,policyId:r,assetName:s,fingerprint:n,quantity:t.quantity}})}async getLovelace(){let 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(){let e=await this.getBalance();return Array.from(new Set(e.map(t=>t.unit.slice(0,w.POLICY_ID_LENGTH)))).filter(t=>t!=="lovelace")}static resolveInstance(e){return window.cardano===void 0||window.cardano[e]===void 0?void 0:window.cardano[e]?.enable()}static addBrowserWitnesses(e,t){let r=a.Serialization.TransactionWitnessSet.fromCbor(a.CardanoSDKUtil.HexBlob(t)).vkeys()?.values();if(r===void 0)return e;let s=(0,a.deserializeTx)(e),n=s.witnessSet(),c=n.vkeys(),d=c?[...c.values(),...r]:[...r];return n.setVkeys(a.Serialization.CborSet.fromCore(d.map(u=>u.toCore()),a.VkeyWitness.fromCore)),new a.Transaction(s.body(),n,s.auxiliaryData()).toCbor()}};var f=require("@meshsdk/common"),m=require("@meshsdk/core-cst"),L=require("@meshsdk/transaction");var B=class{_wallet;constructor(e){switch(e.key.type){case"root":this._wallet=new E({networkId:e.networkId,fetcher:e.fetcher,submitter:e.submitter,key:{type:"root",bech32:e.key.bech32}});break;case"cli":this._wallet=new E({networkId:e.networkId,fetcher:e.fetcher,submitter:e.submitter,key:{type:"cli",payment:e.key.payment,stake:e.key.stake}});break;case"mnemonic":this._wallet=new E({networkId:e.networkId,fetcher:e.fetcher,submitter:e.submitter,key:{type:"mnemonic",words:e.key.words}});break}}async getBalance(){let e=await this.getUnspentOutputs(),t=new Map;return e.map(s=>{(0,m.fromTxUnspentOutput)(s).output.amount.map(c=>{let d=c.unit,u=Number(c.quantity);if(t.has(d)){let S=t.get(d);t.set(d,S+u)}else t.set(d,u)})}),Array.from(t,([s,n])=>({unit:s,quantity:n.toString()}))}getChangeAddress(){return this._wallet.getPaymentAddress()}async getCollateral(e="payment"){return(await this._wallet.getCollateralUnspentOutput(0,e)).map((r,s)=>(0,m.fromTxUnspentOutput)(r))}getNetworkId(){return this._wallet.getNetworkId()}getRewardAddresses(){return[this._wallet.getRewardAddress()]}getUnusedAddresses(){return[this.getChangeAddress()]}getUsedAddresses(){return[this.getChangeAddress()]}async getUsedCollateral(){return(await this.getCollateral()).map(r=>(0,m.toTxUnspentOutput)(r))}async getUsedUTxOs(e){return await this.getUnspentOutputs(e)}async getUtxos(e){return(await this.getUsedUTxOs(e)).map(r=>(0,m.fromTxUnspentOutput)(r))}signData(e){return this._wallet.signData(this.getChangeAddress(),e)}signTx(e,t=!1){return this._wallet.signTx(e,t)}signTxs(e,t=!1){let r=[];for(let s of e){let n=this.signTx(s,t);r.push(n)}return r}async submitTx(e){return await this._wallet.submitTx(e)}getUsedAddress(e){return this._wallet.getUsedAddress(0,0,e)}async getUnspentOutputs(e){return await this._wallet.getUnspentOutputs(0,e)}async getAssets(){return(await this.getBalance()).filter(t=>t.unit!=="lovelace").map(t=>{let r=t.unit.slice(0,f.POLICY_ID_LENGTH),s=t.unit.slice(f.POLICY_ID_LENGTH),n=(0,f.resolveFingerprint)(r,s);return{unit:t.unit,policyId:r,assetName:(0,f.toUTF8)(s),fingerprint:n,quantity:t.quantity}})}async getLovelace(){let 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(){let e=await this.getBalance();return Array.from(new Set(e.map(t=>t.unit.slice(0,f.POLICY_ID_LENGTH)))).filter(t=>t!=="lovelace")}async createCollateral(){let e=new L.Transaction({initiator:this});e.sendLovelace(this.getChangeAddress(),"5000000");let t=await e.build(),r=await this.signTx(t);return await this.submitTx(r)}static brew(e=!1,t=256){let r=p.generateMnemonic(t);return e?(0,m.resolvePrivateKey)(r):r}};0&&(module.exports={AppWallet,BrowserWallet,EmbeddedWallet,MeshWallet,WalletStaticMethods});
|
|
1
|
+
"use strict";var Z=Object.create;var D=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var J=Object.getPrototypeOf,V=Object.prototype.hasOwnProperty;var X=(i,e)=>{for(var t in e)D(i,t,{get:e[t],enumerable:!0})},Y=(i,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of $(e))!V.call(i,n)&&n!==t&&D(i,n,{get:()=>e[n],enumerable:!(r=R(e,n))||r.enumerable});return i};var q=(i,e,t)=>(t=i!=null?Z(J(i)):{},Y(e||!i||!i.__esModule?D(t,"default",{value:i,enumerable:!0}):t,i)),ee=i=>Y(D({},"__esModule",{value:!0}),i);var ue={};X(ue,{AppWallet:()=>b,BrowserWallet:()=>z,EmbeddedWallet:()=>M,MeshWallet:()=>k,WalletStaticMethods:()=>L});module.exports=ee(ue);var j=require("@meshsdk/core-cst");function S(i){if(!Number.isSafeInteger(i))throw new Error(`Wrong integer: ${i}`)}function te(i){return i instanceof Uint8Array||i!=null&&typeof i=="object"&&i.constructor.name==="Uint8Array"}function re(...i){let e=s=>s,t=(s,d)=>c=>s(d(c)),r=i.map(s=>s.encode).reduceRight(t,e),n=i.map(s=>s.decode).reduce(t,e);return{encode:r,decode:n}}function se(i){return{encode:e=>{if(!Array.isArray(e)||e.length&&typeof e[0]!="number")throw new Error("alphabet.encode input should be an array of numbers");return e.map(t=>{if(t<0||t>=i.length)throw new Error(`Digit index outside alphabet: ${t} (alphabet: ${i.length})`);return i[t]})},decode:e=>{if(!Array.isArray(e)||e.length&&typeof e[0]!="string")throw new Error("alphabet.decode input should be array of strings");return e.map(t=>{if(typeof t!="string")throw new Error(`alphabet.decode: not string element=${t}`);let r=i.indexOf(t);if(r===-1)throw new Error(`Unknown letter: "${t}". Allowed: ${i}`);return r})}}}function ne(i=""){if(typeof i!="string")throw new Error("join separator should be string");return{encode:e=>{if(!Array.isArray(e)||e.length&&typeof e[0]!="string")throw new Error("join.encode input should be array of strings");for(let t of e)if(typeof t!="string")throw new Error(`join.encode: non-string input=${t}`);return e.join(i)},decode:e=>{if(typeof e!="string")throw new Error("join.decode input should be string");return e.split(i)}}}var W=(i,e)=>e?W(e,i%e):i,T=(i,e)=>i+(e-W(i,e));function m(i,e,t,r){if(!Array.isArray(i))throw new Error("convertRadix2: data should be array");if(e<=0||e>32)throw new Error(`convertRadix2: wrong from=${e}`);if(t<=0||t>32)throw new Error(`convertRadix2: wrong to=${t}`);if(T(e,t)>32)throw new Error(`convertRadix2: carry overflow from=${e} to=${t} carryBits=${T(e,t)}`);let n=0,s=0,d=2**t-1,c=[];for(let y of i){if(y>=2**e)throw new Error(`convertRadix2: invalid data word=${y} from=${e}`);if(n=n<<e|y,s+e>32)throw new Error(`convertRadix2: carry overflow pos=${s} from=${e}`);for(s+=e;s>=t;s-=t)c.push((n>>s-t&d)>>>0);n&=2**s-1}if(n=n<<t-s&d,!r&&s>=e)throw new Error("Excess padding");if(!r&&n)throw new Error(`Non-zero padding: ${n}`);return r&&s>0&&c.push(n>>>0),c}function ie(i,e=!1){if(i<=0||i>32)throw new Error("radix2: bits should be in (0..32]");if(T(8,i)>32||T(i,8)>32)throw new Error("radix2: carry overflow");return{encode:t=>{if(!te(t))throw new Error("radix2.encode input should be Uint8Array");return m(Array.from(t),8,i,!e)},decode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="number")throw new Error("radix2.decode input should be array of numbers");return Uint8Array.from(m(t,i,8,e))}}}function B(i){if(typeof i!="function")throw new Error("unsafeWrapper fn should be function");return function(...e){try{return i.apply(null,e)}catch{}}}var f=re(se("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),ne("")),v=[996825010,642813549,513874426,1027748829,705979059];function C(i){let e=i>>25,t=(i&33554431)<<5;for(let r=0;r<v.length;r++)(e>>r&1)===1&&(t^=v[r]);return t}function P(i,e,t=1){let r=i.length,n=1;for(let s=0;s<r;s++){let d=i.charCodeAt(s);if(d<33||d>126)throw new Error(`Invalid prefix (${i})`);n=C(n)^d>>5}n=C(n);for(let s=0;s<r;s++)n=C(n)^i.charCodeAt(s)&31;for(let s of e)n=C(n)^s;for(let s=0;s<6;s++)n=C(n);return n^=t,f.encode(m([n%2**30],30,5,!1))}function oe(i){let e=i==="bech32"?1:734539939,t=ie(5),r=t.decode,n=t.encode,s=B(r);function d(g,I,l=90){if(typeof g!="string")throw new Error(`bech32.encode prefix should be string, not ${typeof g}`);if(!Array.isArray(I)||I.length&&typeof I[0]!="number")throw new Error(`bech32.encode words should be array of numbers, not ${typeof I}`);if(g.length===0)throw new TypeError(`Invalid prefix length ${g.length}`);let x=g.length+7+I.length;if(l!==!1&&x>l)throw new TypeError(`Length ${x} exceeds limit ${l}`);let N=g.toLowerCase(),p=P(N,I,e);return`${N}1${f.encode(I)}${p}`}function c(g,I=90){if(typeof g!="string")throw new Error(`bech32.decode input should be string, not ${typeof g}`);if(g.length<8||I!==!1&&g.length>I)throw new TypeError(`Wrong string length: ${g.length} (${g}). Expected (8..${I})`);let l=g.toLowerCase();if(g!==l&&g!==g.toUpperCase())throw new Error("String must be lowercase or uppercase");let x=l.lastIndexOf("1");if(x===0||x===-1)throw new Error('Letter "1" must be present between prefix and data only');let N=l.slice(0,x),p=l.slice(x+1);if(p.length<6)throw new Error("Data must be at least 6 characters long");let O=f.decode(p).slice(0,-6),U=P(N,O,e);if(!p.endsWith(U))throw new Error(`Invalid checksum in ${g}: expected "${U}"`);return{prefix:N,words:O}}let y=B(c);function E(g){let{prefix:I,words:l}=c(g,!1);return{prefix:I,words:l,bytes:r(l)}}return{encode:d,decode:c,decodeToBytes:E,decodeUnsafe:y,fromWords:r,fromWordsUnsafe:s,toWords:n}}var Q=oe("bech32");var h=require("@meshsdk/common"),o=require("@meshsdk/core-cst"),L=class{static privateKeyToEntropy(e){let t=Q.decodeToBytes(e).bytes,r=o.Bip32PrivateKey.fromBytes(t);return(0,h.bytesToHex)(r.bytes())}static mnemonicToEntropy(e){let t=(0,h.mnemonicToEntropy)(e.join(" ")),r=(0,o.buildBip32PrivateKey)(t);return(0,h.bytesToHex)(r.bytes())}static signingKeyToEntropy(e,t){return[e.startsWith("5820")?e.slice(4):e,t.startsWith("5820")?t.slice(4):t]}static getAddresses(e,t,r=0){let n=(0,o.buildBaseAddress)(r,o.Hash28ByteBase16.fromEd25519KeyHashHex((0,o.Ed25519KeyHashHex)(e.toPublicKey().hash().toString("hex"))),o.Hash28ByteBase16.fromEd25519KeyHashHex((0,o.Ed25519KeyHashHex)(t.toPublicKey().hash().toString("hex")))),s=(0,o.buildEnterpriseAddress)(r,o.Hash28ByteBase16.fromEd25519KeyHashHex((0,o.Ed25519KeyHashHex)(e.toPublicKey().hash().toString("hex")))),d=(0,o.buildRewardAddress)(r,o.Hash28ByteBase16.fromEd25519KeyHashHex((0,o.Ed25519KeyHashHex)(t.toPublicKey().hash().toString("hex"))));return{baseAddress:n.toAddress(),enterpriseAddress:s.toAddress(),rewardAddress:d.toAddress()}}static generateMnemonic(e=256){return(0,h.generateMnemonic)(e).split(" ")}static addWitnessSets(e,t){let r=(0,o.deserializeTx)(e),n=r.witnessSet(),s=n.vkeys(),d=s?[...s.values(),...t]:t;return n.setVkeys(o.Serialization.CborSet.fromCore(d.map(c=>c.toCore()),o.VkeyWitness.fromCore)),new o.Transaction(r.body(),n,r.auxiliaryData()).toCbor()}},M=class extends L{_entropy;_networkId;constructor(e){switch(super(),this._networkId=e.networkId,e.key.type){case"mnemonic":this._entropy=L.mnemonicToEntropy(e.key.words);break;case"root":this._entropy=L.privateKeyToEntropy(e.key.bech32);break;case"cli":this._entropy=L.signingKeyToEntropy(e.key.payment,e.key.stake??"f0".repeat(32));break}}getAccount(e=0,t=0){if(this._entropy==null)throw new Error("[EmbeddedWallet] No keys initialized");let{paymentKey:r,stakeKey:n}=(0,o.buildKeys)(this._entropy,e,t),{baseAddress:s,enterpriseAddress:d,rewardAddress:c}=L.getAddresses(r,n,this._networkId);return{baseAddress:s,enterpriseAddress:d,rewardAddress:c,baseAddressBech32:s.toBech32(),enterpriseAddressBech32:d.toBech32(),rewardAddressBech32:c.toBech32(),paymentKey:r,stakeKey:n,paymentKeyHex:r.toBytes().toString("hex"),stakeKeyHex:n.toBytes().toString("hex")}}getNetworkId(){return this._networkId}signData(e,t,r=0,n=0){try{let s=this.getAccount(r,n);if([s.baseAddress,s.enterpriseAddress,s.rewardAddress].find(c=>c.toBech32()===e)===void 0)throw new Error(`[EmbeddedWallet] Address: ${e} doesn't belong to this account.`);return(0,o.signData)(t,s.paymentKey)}catch(s){throw new Error(`[EmbeddedWallet] An error occurred during signData: ${s}.`)}}signTx(e,t=0,r=0){try{let n=(0,o.deserializeTxHash)((0,o.resolveTxHash)(e)),s=this.getAccount(t,r);return new o.VkeyWitness((0,o.Ed25519PublicKeyHex)(s.paymentKey.toPublicKey().toBytes().toString("hex")),(0,o.Ed25519SignatureHex)(s.paymentKey.sign(Buffer.from(n,"hex")).toString("hex")))}catch(n){throw new Error(`[EmbeddedWallet] An error occurred during signTx: ${n}.`)}}};var b=class{_fetcher;_submitter;_wallet;constructor(e){switch(this._fetcher=e.fetcher,this._submitter=e.submitter,e.key.type){case"mnemonic":this._wallet=new M({networkId:e.networkId,key:{type:"mnemonic",words:e.key.words}});break;case"root":this._wallet=new M({networkId:e.networkId,key:{type:"root",bech32:e.key.bech32}});break;case"cli":this._wallet=new M({networkId:e.networkId,key:{type:"cli",payment:e.key.payment,stake:e.key.stake}})}}async getCollateralUnspentOutput(e=0,t="payment"){let n=(await this.getUnspentOutputs(e,t)).filter(s=>s.output().amount().multiasset()===void 0);n.sort((s,d)=>Number(s.output().amount().coin())-Number(d.output().amount().coin()));for(let s of n)if(Number(s.output().amount().coin())>=5e6)return[s];return[]}getEnterpriseAddress(e=0,t=0){return this._wallet.getAccount(e,t).enterpriseAddressBech32}getPaymentAddress(e=0,t=0){return this._wallet.getAccount(e,t).baseAddressBech32}getRewardAddress(e=0,t=0){return this._wallet.getAccount(e,t).rewardAddressBech32}getNetworkId(){return this._wallet.getNetworkId()}getUsedAddress(e=0,t=0,r="payment"){return r==="enterprise"?(0,j.toAddress)(this.getEnterpriseAddress(e,t)):(0,j.toAddress)(this.getPaymentAddress(e,t))}async getUnspentOutputs(e=0,t="payment"){if(!this._fetcher)throw new Error("[AppWallet] Fetcher is required to fetch UTxOs. Please provide a fetcher.");let r=this._wallet.getAccount(e);return(await this._fetcher.fetchAddressUTxOs(t=="enterprise"?r.enterpriseAddressBech32:r.baseAddressBech32)).map(s=>(0,j.toTxUnspentOutput)(s))}signData(e,t,r=0,n=0){try{return this._wallet.signData(e,t,r,n)}catch(s){throw new Error(`[AppWallet] An error occurred during signData: ${s}.`)}}signTx(e,t=!1,r=0,n=0){try{let s=(0,j.deserializeTx)(e);if(!t&&s.witnessSet().vkeys()!==void 0&&s.witnessSet().vkeys().size()!==0)throw new Error("Signatures already exist in the transaction in a non partial sign call");let d=this._wallet.signTx(e,r,n);return M.addWitnessSets(e,[d])}catch(s){throw new Error(`[AppWallet] An error occurred during signTx: ${s}.`)}}signTxSync(e,t=!1,r=0,n=0){try{return"signedTx"}catch(s){throw new Error(`[AppWallet] An error occurred during signTx: ${s}.`)}}async signTxs(e,t){throw new Error("[AppWallet] signTxs() is not implemented.")}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 M.generateMnemonic(e)}};var w=require("@meshsdk/common"),a=require("@meshsdk/core-cst");var G=require("@nufi/dapp-client-cardano"),_=q(require("@nufi/dapp-client-core"),1),H={production:"https://wallet.nu.fi",mainnet:"https://wallet-staging.nu.fi",preprod:"https://wallet-testnet-staging.nu.fi",preview:"https://wallet-preview-staging.nu.fi"};function K(i="preprod"){try{let e=_.default.default;return Object.keys(H).includes(i)?e.init(H[i]):e.init(i),new Promise(t=>{e.getApi().isMetamaskInstalled().then(r=>{r?((0,G.initNufiDappCardanoSdk)(e,"snap"),t({id:"nufiSnap",name:"MetaMask",icon:"data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHN2ZyBpZD0iTGF5ZXJfMiIgZGF0YS1uYW1lPSJMYXllciAyIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxNjkuMiAxNjMuNzEiPgogIDxkZWZzPgogICAgPHN0eWxlPgogICAgICAuY2xzLTEgewogICAgICAgIGZpbGw6ICNlMjc2MjU7CiAgICAgIH0KCiAgICAgIC5jbHMtMSwgLmNscy0yLCAuY2xzLTMsIC5jbHMtNCwgLmNscy01LCAuY2xzLTYsIC5jbHMtNywgLmNscy04LCAuY2xzLTkgewogICAgICAgIHN0cm9rZS13aWR0aDogMHB4OwogICAgICB9CgogICAgICAuY2xzLTIgewogICAgICAgIGZpbGw6ICM3NjNlMWE7CiAgICAgIH0KCiAgICAgIC5jbHMtMyB7CiAgICAgICAgZmlsbDogI2MwYWQ5ZTsKICAgICAgfQoKICAgICAgLmNscy00IHsKICAgICAgICBmaWxsOiAjMzQ2OGQxOwogICAgICB9CgogICAgICAuY2xzLTUgewogICAgICAgIGZpbGw6ICNjYzYyMjg7CiAgICAgIH0KCiAgICAgIC5jbHMtNiB7CiAgICAgICAgZmlsbDogI2Y1ODQ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xLjQsMS40cy0uNjMsMS40LTEuNCwxLjQtMS40LS42My0xLjQtMS40aDBjMC0uNzguNjMtMS40LDEuNC0xLjRoMFoiLz4KICAgICAgPC9nPgogICAgPC9nPgogIDwvZz4KPC9zdmc+",version:"version"})):t(void 0)})})}catch{return Promise.resolve(void 0)}}var z=class i{constructor(e,t){this._walletInstance=e;this._walletName=t;this.walletInstance={...e}}walletInstance;static getInstalledWallets(){if(window===void 0)return[];if(window.cardano===void 0)return[];let e=[];for(let t in window.cardano)try{let r=window.cardano[t];if(r===void 0||r.name===void 0||r.icon===void 0||r.apiVersion===void 0)continue;e.push({id:t,name:t=="nufiSnap"?"MetaMask":r.name,icon:r.icon,version:r.apiVersion})}catch{}return e}static async getAvailableWallets({nufiNetwork:e="preprod"}={}){return window===void 0?[]:(await K(e),i.getInstalledWallets())}static async enable(e){try{let t=await i.resolveInstance(e);if(t!==void 0)return new i(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(){let e=await this._walletInstance.getBalance();return(0,a.fromValue)((0,a.deserializeValue)(e))}async getChangeAddress(){let e=await this._walletInstance.getChangeAddress();return(0,a.addressToBech32)((0,a.deserializeAddress)(e))}async getCollateral(){return(await this.getCollateralUnspentOutput()).map(t=>(0,a.fromTxUnspentOutput)(t))}getNetworkId(){return this._walletInstance.getNetworkId()}async getRewardAddresses(){return(await this._walletInstance.getRewardAddresses()).map(t=>(0,a.addressToBech32)((0,a.deserializeAddress)(t)))}async getUnusedAddresses(){return(await this._walletInstance.getUnusedAddresses()).map(t=>(0,a.addressToBech32)((0,a.deserializeAddress)(t)))}async getUsedAddresses(){return(await this._walletInstance.getUsedAddresses()).map(t=>(0,a.addressToBech32)((0,a.deserializeAddress)(t)))}async getUsedCollateral(e=w.DEFAULT_PROTOCOL_PARAMETERS.maxCollateralInputs){return(await this._walletInstance.experimental.getCollateral()??[]).map(r=>(0,a.deserializeTxUnspentOutput)(r)).slice(0,e)}async getUtxos(){return(await this.getUsedUTxOs()).map(t=>(0,a.fromTxUnspentOutput)(t))}signData(e,t){let r=(0,a.toAddress)(e).toBytes().toString();return this._walletInstance.signData(r,(0,w.fromUTF8)(t))}async signTx(e,t=!1){let r=await this._walletInstance.signTx(e,t);return i.addBrowserWitnesses(e,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(s=>({cbor:s,partialSign:t}))):this._walletInstance.experimental.signTxs&&(r=await this._walletInstance.experimental.signTxs(e.map(s=>({cbor:s,partialSign:t}))));break}if(!r)throw new Error("Wallet does not support signTxs");let n=[];for(let s=0;s<r.length;s++){let d=e[s],c=r[s],y=i.addBrowserWitnesses(d,c);n.push(y)}return n}submitTx(e){return this._walletInstance.submitTx(e)}async getUsedAddress(){let e=await this._walletInstance.getUsedAddresses();if(e.length===0)throw new Error("No used addresses found");return(0,a.deserializeAddress)(e[0])}async getCollateralUnspentOutput(){return(await this._walletInstance.experimental.getCollateral()??[]).map(t=>(0,a.deserializeTxUnspentOutput)(t))}async getUsedUTxOs(){return(await this._walletInstance.getUtxos()??[]).map(t=>(0,a.deserializeTxUnspentOutput)(t))}async getAssets(){return(await this.getBalance()).filter(t=>t.unit!=="lovelace").map(t=>{let r=t.unit.slice(0,w.POLICY_ID_LENGTH),n=t.unit.slice(w.POLICY_ID_LENGTH),s=(0,w.resolveFingerprint)(r,n);return{unit:t.unit,policyId:r,assetName:n,fingerprint:s,quantity:t.quantity}})}async getLovelace(){let 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(){let e=await this.getBalance();return Array.from(new Set(e.map(t=>t.unit.slice(0,w.POLICY_ID_LENGTH)))).filter(t=>t!=="lovelace")}static resolveInstance(e){return window.cardano===void 0||window.cardano[e]===void 0?void 0:window.cardano[e]?.enable()}static addBrowserWitnesses(e,t){let r=a.Serialization.TransactionWitnessSet.fromCbor(a.CardanoSDKUtil.HexBlob(t)).vkeys()?.values();if(r===void 0)return e;let n=(0,a.deserializeTx)(e),s=n.witnessSet(),d=s.vkeys(),c=d?[...d.values(),...r]:[...r];return s.setVkeys(a.Serialization.CborSet.fromCore(c.map(y=>y.toCore()),a.VkeyWitness.fromCore)),new a.Transaction(n.body(),s,n.auxiliaryData()).toCbor()}};var A=require("@meshsdk/common"),u=require("@meshsdk/core-cst"),F=require("@meshsdk/transaction");var k=class{_wallet;_accountIndex=0;_keyIndex=0;_fetcher;_submitter;_networkId;_addresses={};constructor(e){switch(e.key.type){case"root":this._wallet=new M({networkId:e.networkId,key:{type:"root",bech32:e.key.bech32}}),this.getAddressesFromWallet(this._wallet);break;case"cli":this._wallet=new M({networkId:e.networkId,key:{type:"cli",payment:e.key.payment,stake:e.key.stake}}),this.getAddressesFromWallet(this._wallet);break;case"mnemonic":this._wallet=new M({networkId:e.networkId,key:{type:"mnemonic",words:e.key.words}}),this.getAddressesFromWallet(this._wallet);break}this._networkId=e.networkId,e.fetcher&&(this._fetcher=e.fetcher),e.submitter&&(this._submitter=e.submitter),e.accountIndex&&(this._accountIndex=e.accountIndex),e.keyIndex&&(this._keyIndex=e.keyIndex)}async getBalance(){let e=await this.getUnspentOutputs(),t=new Map;return e.map(n=>{(0,u.fromTxUnspentOutput)(n).output.amount.map(d=>{let c=d.unit,y=Number(d.quantity);if(t.has(c)){let E=t.get(c);t.set(c,E+y)}else t.set(c,y)})}),Array.from(t,([n,s])=>({unit:n,quantity:s.toString()}))}getChangeAddress(){return this._addresses.baseAddressBech32}async getCollateral(e="payment"){return(await this.getCollateralUnspentOutput(e)).map((r,n)=>(0,u.fromTxUnspentOutput)(r))}async getCollateralUnspentOutput(e="payment"){let r=(await this.getUnspentOutputs(e)).filter(n=>n.output().amount().multiasset()===void 0);r.sort((n,s)=>Number(n.output().amount().coin())-Number(s.output().amount().coin()));for(let n of r)if(Number(n.output().amount().coin())>=5e6)return[n];return[]}getNetworkId(){return this._networkId}getRewardAddresses(){return[this._addresses.rewardAddressBech32]}getUnusedAddresses(){return[this.getChangeAddress()]}getUsedAddresses(){return[this.getChangeAddress()]}async getUsedCollateral(){return(await this.getCollateral()).map(r=>(0,u.toTxUnspentOutput)(r))}async getUsedUTxOs(e){return await this.getUnspentOutputs(e)}async getUtxos(e){return(await this.getUsedUTxOs(e)).map(r=>(0,u.fromTxUnspentOutput)(r))}signData(e){if(!this._wallet)throw new Error("[MeshWallet] Read only wallet does not support signing data.");return this._wallet.signData(this.getChangeAddress(),e)}signTx(e,t=!1){if(!this._wallet)throw new Error("[MeshWallet] Read only wallet does not support signing data.");let r=(0,u.deserializeTx)(e);if(!t&&r.witnessSet().vkeys()!==void 0&&r.witnessSet().vkeys().size()!==0)throw new Error("Signatures already exist in the transaction in a non partial sign call");let n=this._wallet.signTx(e,this._accountIndex,this._keyIndex);return M.addWitnessSets(e,[n])}signTxs(e,t=!1){let r=[];for(let n of e){let s=this.signTx(n,t);r.push(s)}return r}async submitTx(e){if(!this._submitter)throw new Error("[AppWallet] Submitter is required to submit transactions. Please provide a submitter.");return this._submitter.submitTx(e)}getUsedAddress(e){return e==="enterprise"?(0,u.toAddress)(this._addresses.enterpriseAddressBech32):(0,u.toAddress)(this._addresses.baseAddressBech32)}async getUnspentOutputs(e){if(!this._fetcher)throw new Error("[AppWallet] Fetcher is required to fetch UTxOs. Please provide a fetcher.");return(await this._fetcher.fetchAddressUTxOs(e=="enterprise"?this._addresses.enterpriseAddressBech32:this._addresses.baseAddressBech32)).map(r=>(0,u.toTxUnspentOutput)(r))}async getAssets(){return(await this.getBalance()).filter(t=>t.unit!=="lovelace").map(t=>{let r=t.unit.slice(0,A.POLICY_ID_LENGTH),n=t.unit.slice(A.POLICY_ID_LENGTH),s=(0,A.resolveFingerprint)(r,n);return{unit:t.unit,policyId:r,assetName:(0,A.toUTF8)(n),fingerprint:s,quantity:t.quantity}})}async getLovelace(){let 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(){let e=await this.getBalance();return Array.from(new Set(e.map(t=>t.unit.slice(0,A.POLICY_ID_LENGTH)))).filter(t=>t!=="lovelace")}async createCollateral(){let e=new F.Transaction({initiator:this});e.sendLovelace(this.getChangeAddress(),"5000000");let t=await e.build(),r=await this.signTx(t);return await this.submitTx(r)}static brew(e=!1,t=256){let r=M.generateMnemonic(t);return e?(0,u.resolvePrivateKey)(r):r}getAddressesFromWallet(e){let t=e.getAccount(this._accountIndex,this._keyIndex);this._addresses={baseAddress:t.baseAddress,enterpriseAddress:t.enterpriseAddress,rewardAddress:t.rewardAddress,baseAddressBech32:t.baseAddressBech32,enterpriseAddressBech32:t.enterpriseAddressBech32,rewardAddressBech32:t.rewardAddressBech32}}buildAddressFromBech32Address(e){let r=new u.CardanoSDKSerializer().deserializer.key.deserializeAddress(e);r.pubKeyHash&&r.stakeCredentialHash&&(this._addresses.baseAddress=(0,u.buildBaseAddress)(this._networkId,u.Hash28ByteBase16.fromEd25519KeyHashHex((0,u.Ed25519KeyHashHex)(r.pubKeyHash)),u.Hash28ByteBase16.fromEd25519KeyHashHex((0,u.Ed25519KeyHashHex)((0,u.Ed25519KeyHashHex)(r.stakeCredentialHash)))).toAddress(),this._addresses.baseAddressBech32=this._addresses.baseAddress.toBech32()),r.pubKeyHash&&(this._addresses.enterpriseAddress=(0,u.buildEnterpriseAddress)(this._networkId,u.Hash28ByteBase16.fromEd25519KeyHashHex((0,u.Ed25519KeyHashHex)(r.pubKeyHash))).toAddress(),this._addresses.enterpriseAddressBech32=this._addresses.enterpriseAddress.toBech32()),r.stakeCredentialHash&&(this._addresses.rewardAddress=(0,u.buildRewardAddress)(this._networkId,u.Hash28ByteBase16.fromEd25519KeyHashHex((0,u.Ed25519KeyHashHex)(r.stakeCredentialHash))).toAddress(),this._addresses.rewardAddressBech32=this._addresses.rewardAddress.toBech32())}};0&&(module.exports={AppWallet,BrowserWallet,EmbeddedWallet,MeshWallet,WalletStaticMethods});
|
|
2
2
|
/*! Bundled license information:
|
|
3
3
|
|
|
4
4
|
@scure/base/lib/esm/index.js:
|
package/dist/index.d.cts
CHANGED
|
@@ -98,6 +98,17 @@ declare class BrowserWallet implements IInitiator, ISigner, ISubmitter {
|
|
|
98
98
|
* @returns a list of wallet names
|
|
99
99
|
*/
|
|
100
100
|
static getInstalledWallets(): Wallet[];
|
|
101
|
+
/**
|
|
102
|
+
* Returns a list of wallets installed on user's device. Each wallet is an object with the following properties:
|
|
103
|
+
* - A name is provided to display wallet's name on the user interface.
|
|
104
|
+
* - A version is provided to display wallet's version on the user interface.
|
|
105
|
+
* - An icon is provided to display wallet's icon on the user interface.
|
|
106
|
+
*
|
|
107
|
+
* @returns a list of wallet names
|
|
108
|
+
*/
|
|
109
|
+
static getAvailableWallets({ nufiNetwork, }?: {
|
|
110
|
+
nufiNetwork?: string;
|
|
111
|
+
}): Promise<Wallet[]>;
|
|
101
112
|
/**
|
|
102
113
|
* This is the entrypoint to start communication with the user's wallet. The wallet should request the user's permission to connect the web page to the user's wallet, and if permission has been granted, the wallet will be returned and exposing the full API for the dApp to use.
|
|
103
114
|
*
|
|
@@ -310,7 +321,7 @@ declare class EmbeddedWallet extends WalletStaticMethods {
|
|
|
310
321
|
}
|
|
311
322
|
|
|
312
323
|
type CreateMeshWalletOptions = {
|
|
313
|
-
networkId:
|
|
324
|
+
networkId: 0 | 1;
|
|
314
325
|
fetcher?: IFetcher;
|
|
315
326
|
submitter?: ISubmitter;
|
|
316
327
|
key: {
|
|
@@ -324,6 +335,8 @@ type CreateMeshWalletOptions = {
|
|
|
324
335
|
type: "mnemonic";
|
|
325
336
|
words: string[];
|
|
326
337
|
};
|
|
338
|
+
accountIndex?: number;
|
|
339
|
+
keyIndex?: number;
|
|
327
340
|
};
|
|
328
341
|
/**
|
|
329
342
|
* Mesh Wallet provides a set of APIs to interact with the blockchain. This wallet is compatible with Mesh transaction builders.
|
|
@@ -348,6 +361,12 @@ type CreateMeshWalletOptions = {
|
|
|
348
361
|
*/
|
|
349
362
|
declare class MeshWallet implements IInitiator, ISigner, ISubmitter {
|
|
350
363
|
private readonly _wallet;
|
|
364
|
+
private readonly _accountIndex;
|
|
365
|
+
private readonly _keyIndex;
|
|
366
|
+
private readonly _fetcher?;
|
|
367
|
+
private readonly _submitter?;
|
|
368
|
+
private readonly _networkId;
|
|
369
|
+
private _addresses;
|
|
351
370
|
constructor(options: CreateMeshWalletOptions);
|
|
352
371
|
/**
|
|
353
372
|
* Returns a list of assets in the wallet. This API will return every assets in the wallet. Each asset is an object with the following properties:
|
|
@@ -371,6 +390,14 @@ declare class MeshWallet implements IInitiator, ISigner, ISubmitter {
|
|
|
371
390
|
* @returns a list of UTXOs
|
|
372
391
|
*/
|
|
373
392
|
getCollateral(addressType?: GetAddressType): Promise<UTxO[]>;
|
|
393
|
+
/**
|
|
394
|
+
* Get a list of UTXOs to be used as collateral inputs for transactions with plutus script inputs.
|
|
395
|
+
*
|
|
396
|
+
* This is used in transaction building.
|
|
397
|
+
*
|
|
398
|
+
* @returns a list of UTXOs
|
|
399
|
+
*/
|
|
400
|
+
getCollateralUnspentOutput(addressType?: GetAddressType): Promise<TransactionUnspentOutput[]>;
|
|
374
401
|
/**
|
|
375
402
|
* Returns the network ID of the currently connected account. 0 is testnet and 1 is mainnet but other networks can possibly be returned by wallets. Those other network ID values are not governed by CIP-30. This result will stay the same unless the connected account has changed.
|
|
376
403
|
*
|
|
@@ -506,6 +533,8 @@ declare class MeshWallet implements IInitiator, ISigner, ISubmitter {
|
|
|
506
533
|
* @returns a transaction hash
|
|
507
534
|
*/
|
|
508
535
|
static brew(privateKey?: boolean, strength?: number): string[] | string;
|
|
536
|
+
getAddressesFromWallet(wallet: EmbeddedWallet): void;
|
|
537
|
+
buildAddressFromBech32Address(address: string): void;
|
|
509
538
|
}
|
|
510
539
|
|
|
511
540
|
export { type Account, AppWallet, type AppWalletKeyType, BrowserWallet, type CreateAppWalletOptions, type CreateEmbeddedWalletOptions, type CreateMeshWalletOptions, EmbeddedWallet, type EmbeddedWalletKeyType, MeshWallet, WalletStaticMethods };
|
package/dist/index.d.ts
CHANGED
|
@@ -98,6 +98,17 @@ declare class BrowserWallet implements IInitiator, ISigner, ISubmitter {
|
|
|
98
98
|
* @returns a list of wallet names
|
|
99
99
|
*/
|
|
100
100
|
static getInstalledWallets(): Wallet[];
|
|
101
|
+
/**
|
|
102
|
+
* Returns a list of wallets installed on user's device. Each wallet is an object with the following properties:
|
|
103
|
+
* - A name is provided to display wallet's name on the user interface.
|
|
104
|
+
* - A version is provided to display wallet's version on the user interface.
|
|
105
|
+
* - An icon is provided to display wallet's icon on the user interface.
|
|
106
|
+
*
|
|
107
|
+
* @returns a list of wallet names
|
|
108
|
+
*/
|
|
109
|
+
static getAvailableWallets({ nufiNetwork, }?: {
|
|
110
|
+
nufiNetwork?: string;
|
|
111
|
+
}): Promise<Wallet[]>;
|
|
101
112
|
/**
|
|
102
113
|
* This is the entrypoint to start communication with the user's wallet. The wallet should request the user's permission to connect the web page to the user's wallet, and if permission has been granted, the wallet will be returned and exposing the full API for the dApp to use.
|
|
103
114
|
*
|
|
@@ -310,7 +321,7 @@ declare class EmbeddedWallet extends WalletStaticMethods {
|
|
|
310
321
|
}
|
|
311
322
|
|
|
312
323
|
type CreateMeshWalletOptions = {
|
|
313
|
-
networkId:
|
|
324
|
+
networkId: 0 | 1;
|
|
314
325
|
fetcher?: IFetcher;
|
|
315
326
|
submitter?: ISubmitter;
|
|
316
327
|
key: {
|
|
@@ -324,6 +335,8 @@ type CreateMeshWalletOptions = {
|
|
|
324
335
|
type: "mnemonic";
|
|
325
336
|
words: string[];
|
|
326
337
|
};
|
|
338
|
+
accountIndex?: number;
|
|
339
|
+
keyIndex?: number;
|
|
327
340
|
};
|
|
328
341
|
/**
|
|
329
342
|
* Mesh Wallet provides a set of APIs to interact with the blockchain. This wallet is compatible with Mesh transaction builders.
|
|
@@ -348,6 +361,12 @@ type CreateMeshWalletOptions = {
|
|
|
348
361
|
*/
|
|
349
362
|
declare class MeshWallet implements IInitiator, ISigner, ISubmitter {
|
|
350
363
|
private readonly _wallet;
|
|
364
|
+
private readonly _accountIndex;
|
|
365
|
+
private readonly _keyIndex;
|
|
366
|
+
private readonly _fetcher?;
|
|
367
|
+
private readonly _submitter?;
|
|
368
|
+
private readonly _networkId;
|
|
369
|
+
private _addresses;
|
|
351
370
|
constructor(options: CreateMeshWalletOptions);
|
|
352
371
|
/**
|
|
353
372
|
* Returns a list of assets in the wallet. This API will return every assets in the wallet. Each asset is an object with the following properties:
|
|
@@ -371,6 +390,14 @@ declare class MeshWallet implements IInitiator, ISigner, ISubmitter {
|
|
|
371
390
|
* @returns a list of UTXOs
|
|
372
391
|
*/
|
|
373
392
|
getCollateral(addressType?: GetAddressType): Promise<UTxO[]>;
|
|
393
|
+
/**
|
|
394
|
+
* Get a list of UTXOs to be used as collateral inputs for transactions with plutus script inputs.
|
|
395
|
+
*
|
|
396
|
+
* This is used in transaction building.
|
|
397
|
+
*
|
|
398
|
+
* @returns a list of UTXOs
|
|
399
|
+
*/
|
|
400
|
+
getCollateralUnspentOutput(addressType?: GetAddressType): Promise<TransactionUnspentOutput[]>;
|
|
374
401
|
/**
|
|
375
402
|
* Returns the network ID of the currently connected account. 0 is testnet and 1 is mainnet but other networks can possibly be returned by wallets. Those other network ID values are not governed by CIP-30. This result will stay the same unless the connected account has changed.
|
|
376
403
|
*
|
|
@@ -506,6 +533,8 @@ declare class MeshWallet implements IInitiator, ISigner, ISubmitter {
|
|
|
506
533
|
* @returns a transaction hash
|
|
507
534
|
*/
|
|
508
535
|
static brew(privateKey?: boolean, strength?: number): string[] | string;
|
|
536
|
+
getAddressesFromWallet(wallet: EmbeddedWallet): void;
|
|
537
|
+
buildAddressFromBech32Address(address: string): void;
|
|
509
538
|
}
|
|
510
539
|
|
|
511
540
|
export { type Account, AppWallet, type AppWalletKeyType, BrowserWallet, type CreateAppWalletOptions, type CreateEmbeddedWalletOptions, type CreateMeshWalletOptions, EmbeddedWallet, type EmbeddedWalletKeyType, MeshWallet, WalletStaticMethods };
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{deserializeTx as we,toAddress as L,toTxUnspentOutput as ye}from"@meshsdk/core-cst";function S(o){if(!Number.isSafeInteger(o))throw new Error(`Wrong integer: ${o}`)}function M(o){return o instanceof Uint8Array||o!=null&&typeof o=="object"&&o.constructor.name==="Uint8Array"}function q(...o){let e=n=>n,t=(n,i)=>a=>n(i(a)),r=o.map(n=>n.encode).reduceRight(t,e),s=o.map(n=>n.decode).reduce(t,e);return{encode:r,decode:s}}function j(o){return{encode:e=>{if(!Array.isArray(e)||e.length&&typeof e[0]!="number")throw new Error("alphabet.encode input should be an array of numbers");return e.map(t=>{if(t<0||t>=o.length)throw new Error(`Digit index outside alphabet: ${t} (alphabet: ${o.length})`);return o[t]})},decode:e=>{if(!Array.isArray(e)||e.length&&typeof e[0]!="string")throw new Error("alphabet.decode input should be array of strings");return e.map(t=>{if(typeof t!="string")throw new Error(`alphabet.decode: not string element=${t}`);let r=o.indexOf(t);if(r===-1)throw new Error(`Unknown letter: "${t}". Allowed: ${o}`);return r})}}}function J(o=""){if(typeof o!="string")throw new Error("join separator should be string");return{encode:e=>{if(!Array.isArray(e)||e.length&&typeof e[0]!="string")throw new Error("join.encode input should be array of strings");for(let t of e)if(typeof t!="string")throw new Error(`join.encode: non-string input=${t}`);return e.join(o)},decode:e=>{if(typeof e!="string")throw new Error("join.decode input should be string");return e.split(o)}}}var D=(o,e)=>e?D(e,o%e):o,b=(o,e)=>o+(e-D(o,e));function I(o,e,t,r){if(!Array.isArray(o))throw new Error("convertRadix2: data should be array");if(e<=0||e>32)throw new Error(`convertRadix2: wrong from=${e}`);if(t<=0||t>32)throw new Error(`convertRadix2: wrong to=${t}`);if(b(e,t)>32)throw new Error(`convertRadix2: carry overflow from=${e} to=${t} carryBits=${b(e,t)}`);let s=0,n=0,i=2**t-1,a=[];for(let d of o){if(d>=2**e)throw new Error(`convertRadix2: invalid data word=${d} from=${e}`);if(s=s<<e|d,n+e>32)throw new Error(`convertRadix2: carry overflow pos=${n} from=${e}`);for(n+=e;n>=t;n-=t)a.push((s>>n-t&i)>>>0);s&=2**n-1}if(s=s<<t-n&i,!r&&n>=e)throw new Error("Excess padding");if(!r&&s)throw new Error(`Non-zero padding: ${s}`);return r&&n>0&&a.push(s>>>0),a}function Y(o,e=!1){if(o<=0||o>32)throw new Error("radix2: bits should be in (0..32]");if(b(8,o)>32||b(o,8)>32)throw new Error("radix2: carry overflow");return{encode:t=>{if(!M(t))throw new Error("radix2.encode input should be Uint8Array");return I(Array.from(t),8,o,!e)},decode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="number")throw new Error("radix2.decode input should be array of numbers");return Uint8Array.from(I(t,o,8,e))}}}function W(o){if(typeof o!="function")throw new Error("unsafeWrapper fn should be function");return function(...e){try{return o.apply(null,e)}catch{}}}var U=q(j("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),J("")),K=[996825010,642813549,513874426,1027748829,705979059];function m(o){let e=o>>25,t=(o&33554431)<<5;for(let r=0;r<K.length;r++)(e>>r&1)===1&&(t^=K[r]);return t}function $(o,e,t=1){let r=o.length,s=1;for(let n=0;n<r;n++){let i=o.charCodeAt(n);if(i<33||i>126)throw new Error(`Invalid prefix (${o})`);s=m(s)^i>>5}s=m(s);for(let n=0;n<r;n++)s=m(s)^o.charCodeAt(n)&31;for(let n of e)s=m(s)^n;for(let n=0;n<6;n++)s=m(s);return s^=t,U.encode(I([s%2**30],30,5,!1))}function Q(o){let e=o==="bech32"?1:734539939,t=Y(5),r=t.decode,s=t.encode,n=W(r);function i(c,l,u=90){if(typeof c!="string")throw new Error(`bech32.encode prefix should be string, not ${typeof c}`);if(!Array.isArray(l)||l.length&&typeof l[0]!="number")throw new Error(`bech32.encode words should be array of numbers, not ${typeof l}`);if(c.length===0)throw new TypeError(`Invalid prefix length ${c.length}`);let h=c.length+7+l.length;if(u!==!1&&h>u)throw new TypeError(`Length ${h} exceeds limit ${u}`);let y=c.toLowerCase(),f=$(y,l,e);return`${y}1${U.encode(l)}${f}`}function a(c,l=90){if(typeof c!="string")throw new Error(`bech32.decode input should be string, not ${typeof c}`);if(c.length<8||l!==!1&&c.length>l)throw new TypeError(`Wrong string length: ${c.length} (${c}). Expected (8..${l})`);let u=c.toLowerCase();if(c!==u&&c!==c.toUpperCase())throw new Error("String must be lowercase or uppercase");let h=u.lastIndexOf("1");if(h===0||h===-1)throw new Error('Letter "1" must be present between prefix and data only');let y=u.slice(0,h),f=u.slice(h+1);if(f.length<6)throw new Error("Data must be at least 6 characters long");let C=U.decode(f).slice(0,-6),B=$(y,C,e);if(!f.endsWith(B))throw new Error(`Invalid checksum in ${c}: expected "${B}"`);return{prefix:y,words:C}}let d=W(a);function k(c){let{prefix:l,words:u}=a(c,!1);return{prefix:l,words:u,bytes:r(u)}}return{encode:i,decode:a,decodeToBytes:k,decodeUnsafe:d,fromWords:r,fromWordsUnsafe:n,toWords:s}}var H=Q("bech32");import{bytesToHex as N,generateMnemonic as Z,mnemonicToEntropy as ee}from"@meshsdk/common";import{Bip32PrivateKey as te,buildBaseAddress as re,buildBip32PrivateKey as ne,buildEnterpriseAddress as se,buildKeys as oe,buildRewardAddress as ie,deserializeTx as ae,deserializeTxHash as ce,Ed25519KeyHashHex as A,Ed25519PublicKeyHex as de,Ed25519SignatureHex as le,Hash28ByteBase16 as E,resolveTxHash as ue,Serialization as ge,signData as he,Transaction as pe,VkeyWitness as R}from"@meshsdk/core-cst";var p=class{static privateKeyToEntropy(e){let t=H.decodeToBytes(e).bytes,r=te.fromBytes(t);return N(r.bytes())}static mnemonicToEntropy(e){let t=ee(e.join(" ")),r=ne(t);return N(r.bytes())}static signingKeyToEntropy(e,t){return[e.startsWith("5820")?e.slice(4):e,t.startsWith("5820")?t.slice(4):t]}static getAddresses(e,t,r=0){let s=re(r,E.fromEd25519KeyHashHex(A(e.toPublicKey().hash().toString("hex"))),E.fromEd25519KeyHashHex(A(t.toPublicKey().hash().toString("hex")))),n=se(r,E.fromEd25519KeyHashHex(A(e.toPublicKey().hash().toString("hex")))),i=ie(r,E.fromEd25519KeyHashHex(A(t.toPublicKey().hash().toString("hex"))));return{baseAddress:s.toAddress(),enterpriseAddress:n.toAddress(),rewardAddress:i.toAddress()}}static generateMnemonic(e=256){return Z(e).split(" ")}static addWitnessSets(e,t){let r=ae(e),s=r.witnessSet(),n=s.vkeys(),i=n?[...n.values(),...t]:t;return s.setVkeys(ge.CborSet.fromCore(i.map(a=>a.toCore()),R.fromCore)),new pe(r.body(),s,r.auxiliaryData()).toCbor()}},g=class extends p{_entropy;_networkId;constructor(e){switch(super(),this._networkId=e.networkId,e.key.type){case"mnemonic":this._entropy=p.mnemonicToEntropy(e.key.words);break;case"root":this._entropy=p.privateKeyToEntropy(e.key.bech32);break;case"cli":this._entropy=p.signingKeyToEntropy(e.key.payment,e.key.stake??"f0".repeat(32));break}}getAccount(e=0,t=0){if(this._entropy==null)throw new Error("[EmbeddedWallet] No keys initialized");let{paymentKey:r,stakeKey:s}=oe(this._entropy,e,t),{baseAddress:n,enterpriseAddress:i,rewardAddress:a}=p.getAddresses(r,s,this._networkId);return{baseAddress:n,enterpriseAddress:i,rewardAddress:a,baseAddressBech32:n.toBech32(),enterpriseAddressBech32:i.toBech32(),rewardAddressBech32:a.toBech32(),paymentKey:r,stakeKey:s,paymentKeyHex:r.toBytes().toString("hex"),stakeKeyHex:s.toBytes().toString("hex")}}getNetworkId(){return this._networkId}signData(e,t,r=0,s=0){try{let n=this.getAccount(r,s);if([n.baseAddress,n.enterpriseAddress,n.rewardAddress].find(a=>a.toBech32()===e)===void 0)throw new Error(`[EmbeddedWallet] Address: ${e} doesn't belong to this account.`);return he(t,n.paymentKey)}catch(n){throw new Error(`[EmbeddedWallet] An error occurred during signData: ${n}.`)}}signTx(e,t=0,r=0){try{let s=ce(ue(e)),n=this.getAccount(t,r);return new R(de(n.paymentKey.toPublicKey().toBytes().toString("hex")),le(n.paymentKey.sign(Buffer.from(s,"hex")).toString("hex")))}catch(s){throw new Error(`[EmbeddedWallet] An error occurred during signTx: ${s}.`)}}};var w=class{_fetcher;_submitter;_wallet;constructor(e){switch(this._fetcher=e.fetcher,this._submitter=e.submitter,e.key.type){case"mnemonic":this._wallet=new g({networkId:e.networkId,key:{type:"mnemonic",words:e.key.words}});break;case"root":this._wallet=new g({networkId:e.networkId,key:{type:"root",bech32:e.key.bech32}});break;case"cli":this._wallet=new g({networkId:e.networkId,key:{type:"cli",payment:e.key.payment,stake:e.key.stake}})}}async getCollateralUnspentOutput(e=0,t="payment"){let s=(await this.getUnspentOutputs(e,t)).filter(n=>n.output().amount().multiasset()===void 0);s.sort((n,i)=>Number(n.output().amount().coin())-Number(i.output().amount().coin()));for(let n of s)if(Number(n.output().amount().coin())>=5e6)return[n];return[]}getEnterpriseAddress(e=0,t=0){return this._wallet.getAccount(e,t).enterpriseAddressBech32}getPaymentAddress(e=0,t=0){return this._wallet.getAccount(e,t).baseAddressBech32}getRewardAddress(e=0,t=0){return this._wallet.getAccount(e,t).rewardAddressBech32}getNetworkId(){return this._wallet.getNetworkId()}getUsedAddress(e=0,t=0,r="payment"){return r==="enterprise"?L(this.getEnterpriseAddress(e,t)):L(this.getPaymentAddress(e,t))}async getUnspentOutputs(e=0,t="payment"){if(!this._fetcher)throw new Error("[AppWallet] Fetcher is required to fetch UTxOs. Please provide a fetcher.");let r=this._wallet.getAccount(e);return(await this._fetcher.fetchAddressUTxOs(t=="enterprise"?r.enterpriseAddressBech32:r.baseAddressBech32)).map(n=>ye(n))}signData(e,t,r=0,s=0){try{return this._wallet.signData(e,t,r,s)}catch(n){throw new Error(`[AppWallet] An error occurred during signData: ${n}.`)}}signTx(e,t=!1,r=0,s=0){try{let n=we(e);if(!t&&n.witnessSet().vkeys()!==void 0&&n.witnessSet().vkeys().size()!==0)throw new Error("Signatures already exist in the transaction in a non partial sign call");let i=this._wallet.signTx(e,r,s);return g.addWitnessSets(e,[i])}catch(n){throw new Error(`[AppWallet] An error occurred during signTx: ${n}.`)}}signTxSync(e,t=!1,r=0,s=0){try{return"signedTx"}catch(n){throw new Error(`[AppWallet] An error occurred during signTx: ${n}.`)}}async signTxs(e,t){throw new Error("[AppWallet] signTxs() is not implemented.")}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 g.generateMnemonic(e)}};import{DEFAULT_PROTOCOL_PARAMETERS as fe,fromUTF8 as me,POLICY_ID_LENGTH as P,resolveFingerprint as xe}from"@meshsdk/common";import{addressToBech32 as T,CardanoSDKUtil as be,deserializeAddress as x,deserializeTx as Ae,deserializeTxUnspentOutput as v,deserializeValue as Ee,fromTxUnspentOutput as V,fromValue as Te,Serialization as z,toAddress as ke,Transaction as Ie,VkeyWitness as Ue}from"@meshsdk/core-cst";var G=class o{constructor(e,t){this._walletInstance=e;this._walletName=t;this.walletInstance={...e}}walletInstance;static getInstalledWallets(){if(window===void 0)return[];if(window.cardano===void 0)return[];let e=[];for(let t in window.cardano)try{let r=window.cardano[t];if(r===void 0||r.name===void 0||r.icon===void 0||r.apiVersion===void 0)continue;e.push({id:t,name:r.name,icon:r.icon,version:r.apiVersion})}catch{}return e}static async enable(e){try{let t=await o.resolveInstance(e);if(t!==void 0)return new o(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(){let e=await this._walletInstance.getBalance();return Te(Ee(e))}async getChangeAddress(){let e=await this._walletInstance.getChangeAddress();return T(x(e))}async getCollateral(){return(await this.getCollateralUnspentOutput()).map(t=>V(t))}getNetworkId(){return this._walletInstance.getNetworkId()}async getRewardAddresses(){return(await this._walletInstance.getRewardAddresses()).map(t=>T(x(t)))}async getUnusedAddresses(){return(await this._walletInstance.getUnusedAddresses()).map(t=>T(x(t)))}async getUsedAddresses(){return(await this._walletInstance.getUsedAddresses()).map(t=>T(x(t)))}async getUsedCollateral(e=fe.maxCollateralInputs){return(await this._walletInstance.experimental.getCollateral()??[]).map(r=>v(r)).slice(0,e)}async getUtxos(){return(await this.getUsedUTxOs()).map(t=>V(t))}signData(e,t){let r=ke(e).toBytes().toString();return this._walletInstance.signData(r,me(t))}async signTx(e,t=!1){let r=await this._walletInstance.signTx(e,t);return console.log("witness",r),o.addBrowserWitnesses(e,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(n=>({cbor:n,partialSign:t}))):this._walletInstance.experimental.signTxs&&(r=await this._walletInstance.experimental.signTxs(e.map(n=>({cbor:n,partialSign:t}))));break}if(!r)throw new Error("Wallet does not support signTxs");let s=[];for(let n=0;n<r.length;n++){let i=e[n],a=r[n],d=o.addBrowserWitnesses(i,a);s.push(d)}return s}submitTx(e){return this._walletInstance.submitTx(e)}async getUsedAddress(){let e=await this._walletInstance.getUsedAddresses();if(e.length===0)throw new Error("No used addresses found");return x(e[0])}async getCollateralUnspentOutput(){return(await this._walletInstance.experimental.getCollateral()??[]).map(t=>v(t))}async getUsedUTxOs(){return(await this._walletInstance.getUtxos()??[]).map(t=>v(t))}async getAssets(){return(await this.getBalance()).filter(t=>t.unit!=="lovelace").map(t=>{let r=t.unit.slice(0,P),s=t.unit.slice(P),n=xe(r,s);return{unit:t.unit,policyId:r,assetName:s,fingerprint:n,quantity:t.quantity}})}async getLovelace(){let 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(){let e=await this.getBalance();return Array.from(new Set(e.map(t=>t.unit.slice(0,P)))).filter(t=>t!=="lovelace")}static resolveInstance(e){return window.cardano===void 0||window.cardano[e]===void 0?void 0:window.cardano[e]?.enable()}static addBrowserWitnesses(e,t){let r=z.TransactionWitnessSet.fromCbor(be.HexBlob(t)).vkeys()?.values();if(r===void 0)return e;let s=Ae(e),n=s.witnessSet(),i=n.vkeys(),a=i?[...i.values(),...r]:[...r];return n.setVkeys(z.CborSet.fromCore(a.map(d=>d.toCore()),Ue.fromCore)),new Ie(s.body(),n,s.auxiliaryData()).toCbor()}};import{POLICY_ID_LENGTH as _,resolveFingerprint as Se,toUTF8 as Pe}from"@meshsdk/common";import{fromTxUnspentOutput as O,resolvePrivateKey as ve,toTxUnspentOutput as _e}from"@meshsdk/core-cst";import{Transaction as Oe}from"@meshsdk/transaction";var F=class{_wallet;constructor(e){switch(e.key.type){case"root":this._wallet=new w({networkId:e.networkId,fetcher:e.fetcher,submitter:e.submitter,key:{type:"root",bech32:e.key.bech32}});break;case"cli":this._wallet=new w({networkId:e.networkId,fetcher:e.fetcher,submitter:e.submitter,key:{type:"cli",payment:e.key.payment,stake:e.key.stake}});break;case"mnemonic":this._wallet=new w({networkId:e.networkId,fetcher:e.fetcher,submitter:e.submitter,key:{type:"mnemonic",words:e.key.words}});break}}async getBalance(){let e=await this.getUnspentOutputs(),t=new Map;return e.map(s=>{O(s).output.amount.map(i=>{let a=i.unit,d=Number(i.quantity);if(t.has(a)){let k=t.get(a);t.set(a,k+d)}else t.set(a,d)})}),Array.from(t,([s,n])=>({unit:s,quantity:n.toString()}))}getChangeAddress(){return this._wallet.getPaymentAddress()}async getCollateral(e="payment"){return(await this._wallet.getCollateralUnspentOutput(0,e)).map((r,s)=>O(r))}getNetworkId(){return this._wallet.getNetworkId()}getRewardAddresses(){return[this._wallet.getRewardAddress()]}getUnusedAddresses(){return[this.getChangeAddress()]}getUsedAddresses(){return[this.getChangeAddress()]}async getUsedCollateral(){return(await this.getCollateral()).map(r=>_e(r))}async getUsedUTxOs(e){return await this.getUnspentOutputs(e)}async getUtxos(e){return(await this.getUsedUTxOs(e)).map(r=>O(r))}signData(e){return this._wallet.signData(this.getChangeAddress(),e)}signTx(e,t=!1){return this._wallet.signTx(e,t)}signTxs(e,t=!1){let r=[];for(let s of e){let n=this.signTx(s,t);r.push(n)}return r}async submitTx(e){return await this._wallet.submitTx(e)}getUsedAddress(e){return this._wallet.getUsedAddress(0,0,e)}async getUnspentOutputs(e){return await this._wallet.getUnspentOutputs(0,e)}async getAssets(){return(await this.getBalance()).filter(t=>t.unit!=="lovelace").map(t=>{let r=t.unit.slice(0,_),s=t.unit.slice(_),n=Se(r,s);return{unit:t.unit,policyId:r,assetName:Pe(s),fingerprint:n,quantity:t.quantity}})}async getLovelace(){let 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(){let e=await this.getBalance();return Array.from(new Set(e.map(t=>t.unit.slice(0,_)))).filter(t=>t!=="lovelace")}async createCollateral(){let e=new Oe({initiator:this});e.sendLovelace(this.getChangeAddress(),"5000000");let t=await e.build(),r=await this.signTx(t);return await this.submitTx(r)}static brew(e=!1,t=256){let r=g.generateMnemonic(t);return e?ve(r):r}};export{w as AppWallet,G as BrowserWallet,g as EmbeddedWallet,F as MeshWallet,p as WalletStaticMethods};
|
|
1
|
+
import{deserializeTx as je,toAddress as H,toTxUnspentOutput as Ne}from"@meshsdk/core-cst";function m(i){if(!Number.isSafeInteger(i))throw new Error(`Wrong integer: ${i}`)}function X(i){return i instanceof Uint8Array||i!=null&&typeof i=="object"&&i.constructor.name==="Uint8Array"}function q(...i){let e=s=>s,t=(s,o)=>a=>s(o(a)),r=i.map(s=>s.encode).reduceRight(t,e),n=i.map(s=>s.decode).reduce(t,e);return{encode:r,decode:n}}function ee(i){return{encode:e=>{if(!Array.isArray(e)||e.length&&typeof e[0]!="number")throw new Error("alphabet.encode input should be an array of numbers");return e.map(t=>{if(t<0||t>=i.length)throw new Error(`Digit index outside alphabet: ${t} (alphabet: ${i.length})`);return i[t]})},decode:e=>{if(!Array.isArray(e)||e.length&&typeof e[0]!="string")throw new Error("alphabet.decode input should be array of strings");return e.map(t=>{if(typeof t!="string")throw new Error(`alphabet.decode: not string element=${t}`);let r=i.indexOf(t);if(r===-1)throw new Error(`Unknown letter: "${t}". Allowed: ${i}`);return r})}}}function te(i=""){if(typeof i!="string")throw new Error("join separator should be string");return{encode:e=>{if(!Array.isArray(e)||e.length&&typeof e[0]!="string")throw new Error("join.encode input should be array of strings");for(let t of e)if(typeof t!="string")throw new Error(`join.encode: non-string input=${t}`);return e.join(i)},decode:e=>{if(typeof e!="string")throw new Error("join.decode input should be string");return e.split(i)}}}var v=(i,e)=>e?v(e,i%e):i,h=(i,e)=>i+(e-v(i,e));function T(i,e,t,r){if(!Array.isArray(i))throw new Error("convertRadix2: data should be array");if(e<=0||e>32)throw new Error(`convertRadix2: wrong from=${e}`);if(t<=0||t>32)throw new Error(`convertRadix2: wrong to=${t}`);if(h(e,t)>32)throw new Error(`convertRadix2: carry overflow from=${e} to=${t} carryBits=${h(e,t)}`);let n=0,s=0,o=2**t-1,a=[];for(let c of i){if(c>=2**e)throw new Error(`convertRadix2: invalid data word=${c} from=${e}`);if(n=n<<e|c,s+e>32)throw new Error(`convertRadix2: carry overflow pos=${s} from=${e}`);for(s+=e;s>=t;s-=t)a.push((n>>s-t&o)>>>0);n&=2**s-1}if(n=n<<t-s&o,!r&&s>=e)throw new Error("Excess padding");if(!r&&n)throw new Error(`Non-zero padding: ${n}`);return r&&s>0&&a.push(n>>>0),a}function re(i,e=!1){if(i<=0||i>32)throw new Error("radix2: bits should be in (0..32]");if(h(8,i)>32||h(i,8)>32)throw new Error("radix2: carry overflow");return{encode:t=>{if(!X(t))throw new Error("radix2.encode input should be Uint8Array");return T(Array.from(t),8,i,!e)},decode:t=>{if(!Array.isArray(t)||t.length&&typeof t[0]!="number")throw new Error("radix2.decode input should be array of numbers");return Uint8Array.from(T(t,i,8,e))}}}function U(i){if(typeof i!="function")throw new Error("unsafeWrapper fn should be function");return function(...e){try{return i.apply(null,e)}catch{}}}var E=q(ee("qpzry9x8gf2tvdw0s3jn54khce6mua7l"),te("")),Y=[996825010,642813549,513874426,1027748829,705979059];function L(i){let e=i>>25,t=(i&33554431)<<5;for(let r=0;r<Y.length;r++)(e>>r&1)===1&&(t^=Y[r]);return t}function B(i,e,t=1){let r=i.length,n=1;for(let s=0;s<r;s++){let o=i.charCodeAt(s);if(o<33||o>126)throw new Error(`Invalid prefix (${i})`);n=L(n)^o>>5}n=L(n);for(let s=0;s<r;s++)n=L(n)^i.charCodeAt(s)&31;for(let s of e)n=L(n)^s;for(let s=0;s<6;s++)n=L(n);return n^=t,E.encode(T([n%2**30],30,5,!1))}function se(i){let e=i==="bech32"?1:734539939,t=re(5),r=t.decode,n=t.encode,s=U(r);function o(u,g,M=90){if(typeof u!="string")throw new Error(`bech32.encode prefix should be string, not ${typeof u}`);if(!Array.isArray(g)||g.length&&typeof g[0]!="number")throw new Error(`bech32.encode words should be array of numbers, not ${typeof g}`);if(u.length===0)throw new TypeError(`Invalid prefix length ${u.length}`);let y=u.length+7+g.length;if(M!==!1&&y>M)throw new TypeError(`Length ${y} exceeds limit ${M}`);let l=u.toLowerCase(),w=B(l,g,e);return`${l}1${E.encode(g)}${w}`}function a(u,g=90){if(typeof u!="string")throw new Error(`bech32.decode input should be string, not ${typeof u}`);if(u.length<8||g!==!1&&u.length>g)throw new TypeError(`Wrong string length: ${u.length} (${u}). Expected (8..${g})`);let M=u.toLowerCase();if(u!==M&&u!==u.toUpperCase())throw new Error("String must be lowercase or uppercase");let y=M.lastIndexOf("1");if(y===0||y===-1)throw new Error('Letter "1" must be present between prefix and data only');let l=M.slice(0,y),w=M.slice(y+1);if(w.length<6)throw new Error("Data must be at least 6 characters long");let k=E.decode(w).slice(0,-6),O=B(l,k,e);if(!w.endsWith(O))throw new Error(`Invalid checksum in ${u}: expected "${O}"`);return{prefix:l,words:k}}let c=U(a);function D(u){let{prefix:g,words:M}=a(u,!1);return{prefix:g,words:M,bytes:r(M)}}return{encode:o,decode:a,decodeToBytes:D,decodeUnsafe:c,fromWords:r,fromWordsUnsafe:s,toWords:n}}var P=se("bech32");import{bytesToHex as W,generateMnemonic as ie,mnemonicToEntropy as oe}from"@meshsdk/common";import{Bip32PrivateKey as ae,buildBaseAddress as ue,buildBip32PrivateKey as de,buildEnterpriseAddress as ce,buildKeys as ge,buildRewardAddress as Me,deserializeTx as ye,deserializeTxHash as Ie,Ed25519KeyHashHex as j,Ed25519PublicKeyHex as le,Ed25519SignatureHex as we,Hash28ByteBase16 as N,resolveTxHash as Le,Serialization as Ae,signData as xe,Transaction as he,VkeyWitness as Q}from"@meshsdk/core-cst";var I=class{static privateKeyToEntropy(e){let t=P.decodeToBytes(e).bytes,r=ae.fromBytes(t);return W(r.bytes())}static mnemonicToEntropy(e){let t=oe(e.join(" ")),r=de(t);return W(r.bytes())}static signingKeyToEntropy(e,t){return[e.startsWith("5820")?e.slice(4):e,t.startsWith("5820")?t.slice(4):t]}static getAddresses(e,t,r=0){let n=ue(r,N.fromEd25519KeyHashHex(j(e.toPublicKey().hash().toString("hex"))),N.fromEd25519KeyHashHex(j(t.toPublicKey().hash().toString("hex")))),s=ce(r,N.fromEd25519KeyHashHex(j(e.toPublicKey().hash().toString("hex")))),o=Me(r,N.fromEd25519KeyHashHex(j(t.toPublicKey().hash().toString("hex"))));return{baseAddress:n.toAddress(),enterpriseAddress:s.toAddress(),rewardAddress:o.toAddress()}}static generateMnemonic(e=256){return ie(e).split(" ")}static addWitnessSets(e,t){let r=ye(e),n=r.witnessSet(),s=n.vkeys(),o=s?[...s.values(),...t]:t;return n.setVkeys(Ae.CborSet.fromCore(o.map(a=>a.toCore()),Q.fromCore)),new he(r.body(),n,r.auxiliaryData()).toCbor()}},d=class extends I{_entropy;_networkId;constructor(e){switch(super(),this._networkId=e.networkId,e.key.type){case"mnemonic":this._entropy=I.mnemonicToEntropy(e.key.words);break;case"root":this._entropy=I.privateKeyToEntropy(e.key.bech32);break;case"cli":this._entropy=I.signingKeyToEntropy(e.key.payment,e.key.stake??"f0".repeat(32));break}}getAccount(e=0,t=0){if(this._entropy==null)throw new Error("[EmbeddedWallet] No keys initialized");let{paymentKey:r,stakeKey:n}=ge(this._entropy,e,t),{baseAddress:s,enterpriseAddress:o,rewardAddress:a}=I.getAddresses(r,n,this._networkId);return{baseAddress:s,enterpriseAddress:o,rewardAddress:a,baseAddressBech32:s.toBech32(),enterpriseAddressBech32:o.toBech32(),rewardAddressBech32:a.toBech32(),paymentKey:r,stakeKey:n,paymentKeyHex:r.toBytes().toString("hex"),stakeKeyHex:n.toBytes().toString("hex")}}getNetworkId(){return this._networkId}signData(e,t,r=0,n=0){try{let s=this.getAccount(r,n);if([s.baseAddress,s.enterpriseAddress,s.rewardAddress].find(a=>a.toBech32()===e)===void 0)throw new Error(`[EmbeddedWallet] Address: ${e} doesn't belong to this account.`);return xe(t,s.paymentKey)}catch(s){throw new Error(`[EmbeddedWallet] An error occurred during signData: ${s}.`)}}signTx(e,t=0,r=0){try{let n=Ie(Le(e)),s=this.getAccount(t,r);return new Q(le(s.paymentKey.toPublicKey().toBytes().toString("hex")),we(s.paymentKey.sign(Buffer.from(n,"hex")).toString("hex")))}catch(n){throw new Error(`[EmbeddedWallet] An error occurred during signTx: ${n}.`)}}};var G=class{_fetcher;_submitter;_wallet;constructor(e){switch(this._fetcher=e.fetcher,this._submitter=e.submitter,e.key.type){case"mnemonic":this._wallet=new d({networkId:e.networkId,key:{type:"mnemonic",words:e.key.words}});break;case"root":this._wallet=new d({networkId:e.networkId,key:{type:"root",bech32:e.key.bech32}});break;case"cli":this._wallet=new d({networkId:e.networkId,key:{type:"cli",payment:e.key.payment,stake:e.key.stake}})}}async getCollateralUnspentOutput(e=0,t="payment"){let n=(await this.getUnspentOutputs(e,t)).filter(s=>s.output().amount().multiasset()===void 0);n.sort((s,o)=>Number(s.output().amount().coin())-Number(o.output().amount().coin()));for(let s of n)if(Number(s.output().amount().coin())>=5e6)return[s];return[]}getEnterpriseAddress(e=0,t=0){return this._wallet.getAccount(e,t).enterpriseAddressBech32}getPaymentAddress(e=0,t=0){return this._wallet.getAccount(e,t).baseAddressBech32}getRewardAddress(e=0,t=0){return this._wallet.getAccount(e,t).rewardAddressBech32}getNetworkId(){return this._wallet.getNetworkId()}getUsedAddress(e=0,t=0,r="payment"){return r==="enterprise"?H(this.getEnterpriseAddress(e,t)):H(this.getPaymentAddress(e,t))}async getUnspentOutputs(e=0,t="payment"){if(!this._fetcher)throw new Error("[AppWallet] Fetcher is required to fetch UTxOs. Please provide a fetcher.");let r=this._wallet.getAccount(e);return(await this._fetcher.fetchAddressUTxOs(t=="enterprise"?r.enterpriseAddressBech32:r.baseAddressBech32)).map(s=>Ne(s))}signData(e,t,r=0,n=0){try{return this._wallet.signData(e,t,r,n)}catch(s){throw new Error(`[AppWallet] An error occurred during signData: ${s}.`)}}signTx(e,t=!1,r=0,n=0){try{let s=je(e);if(!t&&s.witnessSet().vkeys()!==void 0&&s.witnessSet().vkeys().size()!==0)throw new Error("Signatures already exist in the transaction in a non partial sign call");let o=this._wallet.signTx(e,r,n);return d.addWitnessSets(e,[o])}catch(s){throw new Error(`[AppWallet] An error occurred during signTx: ${s}.`)}}signTxSync(e,t=!1,r=0,n=0){try{return"signedTx"}catch(s){throw new Error(`[AppWallet] An error occurred during signTx: ${s}.`)}}async signTxs(e,t){throw new Error("[AppWallet] signTxs() is not implemented.")}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 d.generateMnemonic(e)}};import{DEFAULT_PROTOCOL_PARAMETERS as De,fromUTF8 as Te,POLICY_ID_LENGTH as f,resolveFingerprint as Ee}from"@meshsdk/common";import{addressToBech32 as p,CardanoSDKUtil as me,deserializeAddress as A,deserializeTx as fe,deserializeTxUnspentOutput as S,deserializeValue as Se,fromTxUnspentOutput as F,fromValue as be,Serialization as Z,toAddress as ze,Transaction as ke,VkeyWitness as Oe}from"@meshsdk/core-cst";import{initNufiDappCardanoSdk as pe}from"@nufi/dapp-client-cardano";import Ce from"@nufi/dapp-client-core";var _={production:"https://wallet.nu.fi",mainnet:"https://wallet-staging.nu.fi",preprod:"https://wallet-testnet-staging.nu.fi",preview:"https://wallet-preview-staging.nu.fi"};function K(i="preprod"){try{let e=Ce.default;return Object.keys(_).includes(i)?e.init(_[i]):e.init(i),new Promise(t=>{e.getApi().isMetamaskInstalled().then(r=>{r?(pe(e,"snap"),t({id:"nufiSnap",name:"MetaMask",icon:"data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHN2ZyBpZD0iTGF5ZXJfMiIgZGF0YS1uYW1lPSJMYXllciAyIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHZpZXdCb3g9IjAgMCAxNjkuMiAxNjMuNzEiPgogIDxkZWZzPgogICAgPHN0eWxlPgogICAgICAuY2xzLTEgewogICAgICAgIGZpbGw6ICNlMjc2MjU7CiAgICAgIH0KCiAgICAgIC5jbHMtMSwgLmNscy0yLCAuY2xzLTMsIC5jbHMtNCwgLmNscy01LCAuY2xzLTYsIC5jbHMtNywgLmNscy04LCAuY2xzLTkgewogICAgICAgIHN0cm9rZS13aWR0aDogMHB4OwogICAgICB9CgogICAgICAuY2xzLTIgewogICAgICAgIGZpbGw6ICM3NjNlMWE7CiAgICAgIH0KCiAgICAgIC5jbHMtMyB7CiAgICAgICAgZmlsbDogI2MwYWQ5ZTsKICAgICAgfQoKICAgICAgLmNscy00IHsKICAgICAgICBmaWxsOiAjMzQ2OGQxOwogICAgICB9CgogICAgICAuY2xzLTUgewogICAgICAgIGZpbGw6ICNjYzYyMjg7CiAgICAgIH0KCiAgIC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LjRoMFpNOTguOTEsMTIxLjE2Yy43NywwLDEuNC42MywxLjQsMS40cy0uNjMsMS40LTEuNCwxLjQtMS40LS42My0xLjQtMS40aDBjMC0uNzguNjMtMS40LDEuNC0xLjRoMFoiLz4KICAgICAgPC9nPgogICAgPC9nPgogIDwvZz4KPC9zdmc+",version:"version"})):t(void 0)})})}catch{return Promise.resolve(void 0)}}var R=class i{constructor(e,t){this._walletInstance=e;this._walletName=t;this.walletInstance={...e}}walletInstance;static getInstalledWallets(){if(window===void 0)return[];if(window.cardano===void 0)return[];let e=[];for(let t in window.cardano)try{let r=window.cardano[t];if(r===void 0||r.name===void 0||r.icon===void 0||r.apiVersion===void 0)continue;e.push({id:t,name:t=="nufiSnap"?"MetaMask":r.name,icon:r.icon,version:r.apiVersion})}catch{}return e}static async getAvailableWallets({nufiNetwork:e="preprod"}={}){return window===void 0?[]:(await K(e),i.getInstalledWallets())}static async enable(e){try{let t=await i.resolveInstance(e);if(t!==void 0)return new i(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(){let e=await this._walletInstance.getBalance();return be(Se(e))}async getChangeAddress(){let e=await this._walletInstance.getChangeAddress();return p(A(e))}async getCollateral(){return(await this.getCollateralUnspentOutput()).map(t=>F(t))}getNetworkId(){return this._walletInstance.getNetworkId()}async getRewardAddresses(){return(await this._walletInstance.getRewardAddresses()).map(t=>p(A(t)))}async getUnusedAddresses(){return(await this._walletInstance.getUnusedAddresses()).map(t=>p(A(t)))}async getUsedAddresses(){return(await this._walletInstance.getUsedAddresses()).map(t=>p(A(t)))}async getUsedCollateral(e=De.maxCollateralInputs){return(await this._walletInstance.experimental.getCollateral()??[]).map(r=>S(r)).slice(0,e)}async getUtxos(){return(await this.getUsedUTxOs()).map(t=>F(t))}signData(e,t){let r=ze(e).toBytes().toString();return this._walletInstance.signData(r,Te(t))}async signTx(e,t=!1){let r=await this._walletInstance.signTx(e,t);return i.addBrowserWitnesses(e,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(s=>({cbor:s,partialSign:t}))):this._walletInstance.experimental.signTxs&&(r=await this._walletInstance.experimental.signTxs(e.map(s=>({cbor:s,partialSign:t}))));break}if(!r)throw new Error("Wallet does not support signTxs");let n=[];for(let s=0;s<r.length;s++){let o=e[s],a=r[s],c=i.addBrowserWitnesses(o,a);n.push(c)}return n}submitTx(e){return this._walletInstance.submitTx(e)}async getUsedAddress(){let e=await this._walletInstance.getUsedAddresses();if(e.length===0)throw new Error("No used addresses found");return A(e[0])}async getCollateralUnspentOutput(){return(await this._walletInstance.experimental.getCollateral()??[]).map(t=>S(t))}async getUsedUTxOs(){return(await this._walletInstance.getUtxos()??[]).map(t=>S(t))}async getAssets(){return(await this.getBalance()).filter(t=>t.unit!=="lovelace").map(t=>{let r=t.unit.slice(0,f),n=t.unit.slice(f),s=Ee(r,n);return{unit:t.unit,policyId:r,assetName:n,fingerprint:s,quantity:t.quantity}})}async getLovelace(){let 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(){let e=await this.getBalance();return Array.from(new Set(e.map(t=>t.unit.slice(0,f)))).filter(t=>t!=="lovelace")}static resolveInstance(e){return window.cardano===void 0||window.cardano[e]===void 0?void 0:window.cardano[e]?.enable()}static addBrowserWitnesses(e,t){let r=Z.TransactionWitnessSet.fromCbor(me.HexBlob(t)).vkeys()?.values();if(r===void 0)return e;let n=fe(e),s=n.witnessSet(),o=s.vkeys(),a=o?[...o.values(),...r]:[...r];return s.setVkeys(Z.CborSet.fromCore(a.map(c=>c.toCore()),Oe.fromCore)),new ke(n.body(),s,n.auxiliaryData()).toCbor()}};import{POLICY_ID_LENGTH as b,resolveFingerprint as Ue,toUTF8 as Ye}from"@meshsdk/common";import{buildBaseAddress as Be,buildEnterpriseAddress as ve,buildRewardAddress as Pe,CardanoSDKSerializer as We,deserializeTx as Qe,Ed25519KeyHashHex as x,fromTxUnspentOutput as z,Hash28ByteBase16 as C,resolvePrivateKey as He,toAddress as $,toTxUnspentOutput as J}from"@meshsdk/core-cst";import{Transaction as Ge}from"@meshsdk/transaction";var V=class{_wallet;_accountIndex=0;_keyIndex=0;_fetcher;_submitter;_networkId;_addresses={};constructor(e){switch(e.key.type){case"root":this._wallet=new d({networkId:e.networkId,key:{type:"root",bech32:e.key.bech32}}),this.getAddressesFromWallet(this._wallet);break;case"cli":this._wallet=new d({networkId:e.networkId,key:{type:"cli",payment:e.key.payment,stake:e.key.stake}}),this.getAddressesFromWallet(this._wallet);break;case"mnemonic":this._wallet=new d({networkId:e.networkId,key:{type:"mnemonic",words:e.key.words}}),this.getAddressesFromWallet(this._wallet);break}this._networkId=e.networkId,e.fetcher&&(this._fetcher=e.fetcher),e.submitter&&(this._submitter=e.submitter),e.accountIndex&&(this._accountIndex=e.accountIndex),e.keyIndex&&(this._keyIndex=e.keyIndex)}async getBalance(){let e=await this.getUnspentOutputs(),t=new Map;return e.map(n=>{z(n).output.amount.map(o=>{let a=o.unit,c=Number(o.quantity);if(t.has(a)){let D=t.get(a);t.set(a,D+c)}else t.set(a,c)})}),Array.from(t,([n,s])=>({unit:n,quantity:s.toString()}))}getChangeAddress(){return this._addresses.baseAddressBech32}async getCollateral(e="payment"){return(await this.getCollateralUnspentOutput(e)).map((r,n)=>z(r))}async getCollateralUnspentOutput(e="payment"){let r=(await this.getUnspentOutputs(e)).filter(n=>n.output().amount().multiasset()===void 0);r.sort((n,s)=>Number(n.output().amount().coin())-Number(s.output().amount().coin()));for(let n of r)if(Number(n.output().amount().coin())>=5e6)return[n];return[]}getNetworkId(){return this._networkId}getRewardAddresses(){return[this._addresses.rewardAddressBech32]}getUnusedAddresses(){return[this.getChangeAddress()]}getUsedAddresses(){return[this.getChangeAddress()]}async getUsedCollateral(){return(await this.getCollateral()).map(r=>J(r))}async getUsedUTxOs(e){return await this.getUnspentOutputs(e)}async getUtxos(e){return(await this.getUsedUTxOs(e)).map(r=>z(r))}signData(e){if(!this._wallet)throw new Error("[MeshWallet] Read only wallet does not support signing data.");return this._wallet.signData(this.getChangeAddress(),e)}signTx(e,t=!1){if(!this._wallet)throw new Error("[MeshWallet] Read only wallet does not support signing data.");let r=Qe(e);if(!t&&r.witnessSet().vkeys()!==void 0&&r.witnessSet().vkeys().size()!==0)throw new Error("Signatures already exist in the transaction in a non partial sign call");let n=this._wallet.signTx(e,this._accountIndex,this._keyIndex);return d.addWitnessSets(e,[n])}signTxs(e,t=!1){let r=[];for(let n of e){let s=this.signTx(n,t);r.push(s)}return r}async submitTx(e){if(!this._submitter)throw new Error("[AppWallet] Submitter is required to submit transactions. Please provide a submitter.");return this._submitter.submitTx(e)}getUsedAddress(e){return e==="enterprise"?$(this._addresses.enterpriseAddressBech32):$(this._addresses.baseAddressBech32)}async getUnspentOutputs(e){if(!this._fetcher)throw new Error("[AppWallet] Fetcher is required to fetch UTxOs. Please provide a fetcher.");return(await this._fetcher.fetchAddressUTxOs(e=="enterprise"?this._addresses.enterpriseAddressBech32:this._addresses.baseAddressBech32)).map(r=>J(r))}async getAssets(){return(await this.getBalance()).filter(t=>t.unit!=="lovelace").map(t=>{let r=t.unit.slice(0,b),n=t.unit.slice(b),s=Ue(r,n);return{unit:t.unit,policyId:r,assetName:Ye(n),fingerprint:s,quantity:t.quantity}})}async getLovelace(){let 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(){let e=await this.getBalance();return Array.from(new Set(e.map(t=>t.unit.slice(0,b)))).filter(t=>t!=="lovelace")}async createCollateral(){let e=new Ge({initiator:this});e.sendLovelace(this.getChangeAddress(),"5000000");let t=await e.build(),r=await this.signTx(t);return await this.submitTx(r)}static brew(e=!1,t=256){let r=d.generateMnemonic(t);return e?He(r):r}getAddressesFromWallet(e){let t=e.getAccount(this._accountIndex,this._keyIndex);this._addresses={baseAddress:t.baseAddress,enterpriseAddress:t.enterpriseAddress,rewardAddress:t.rewardAddress,baseAddressBech32:t.baseAddressBech32,enterpriseAddressBech32:t.enterpriseAddressBech32,rewardAddressBech32:t.rewardAddressBech32}}buildAddressFromBech32Address(e){let r=new We().deserializer.key.deserializeAddress(e);r.pubKeyHash&&r.stakeCredentialHash&&(this._addresses.baseAddress=Be(this._networkId,C.fromEd25519KeyHashHex(x(r.pubKeyHash)),C.fromEd25519KeyHashHex(x(x(r.stakeCredentialHash)))).toAddress(),this._addresses.baseAddressBech32=this._addresses.baseAddress.toBech32()),r.pubKeyHash&&(this._addresses.enterpriseAddress=ve(this._networkId,C.fromEd25519KeyHashHex(x(r.pubKeyHash))).toAddress(),this._addresses.enterpriseAddressBech32=this._addresses.enterpriseAddress.toBech32()),r.stakeCredentialHash&&(this._addresses.rewardAddress=Pe(this._networkId,C.fromEd25519KeyHashHex(x(r.stakeCredentialHash))).toAddress(),this._addresses.rewardAddressBech32=this._addresses.rewardAddress.toBech32())}};export{G as AppWallet,R as BrowserWallet,d as EmbeddedWallet,V as MeshWallet,I as WalletStaticMethods};
|
|
2
2
|
/*! Bundled license information:
|
|
3
3
|
|
|
4
4
|
@scure/base/lib/esm/index.js:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meshsdk/wallet",
|
|
3
|
-
"version": "1.6.
|
|
3
|
+
"version": "1.6.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"module": "./dist/index.js",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"dev": "tsup src/index.ts --format esm,cjs --watch --dts",
|
|
22
22
|
"lint": "eslint",
|
|
23
23
|
"clean": "rm -rf .turbo && rm -rf dist && rm -rf node_modules",
|
|
24
|
-
"test": "jest
|
|
24
|
+
"test": "jest",
|
|
25
25
|
"format": "prettier --check . --ignore-path ../../.gitignore",
|
|
26
26
|
"build:docs": "typedoc src/index.ts --json ../../apps/docs/src/data/mesh-wallets.json"
|
|
27
27
|
},
|
|
@@ -29,13 +29,15 @@
|
|
|
29
29
|
"@meshsdk/typescript-config": "*",
|
|
30
30
|
"eslint": "^8.57.0",
|
|
31
31
|
"tsup": "^8.0.2",
|
|
32
|
-
"
|
|
33
|
-
"
|
|
32
|
+
"typedoc": "^0.26.3",
|
|
33
|
+
"typescript": "^5.3.3"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@meshsdk/common": "*",
|
|
37
37
|
"@meshsdk/core-cst": "*",
|
|
38
|
-
"@meshsdk/transaction": "*"
|
|
38
|
+
"@meshsdk/transaction": "*",
|
|
39
|
+
"@nufi/dapp-client-cardano": "^0.3.1",
|
|
40
|
+
"@nufi/dapp-client-core": "^0.3.1"
|
|
39
41
|
},
|
|
40
42
|
"prettier": "@meshsdk/prettier-config",
|
|
41
43
|
"publishConfig": {
|
|
@@ -49,4 +51,4 @@
|
|
|
49
51
|
"blockchain",
|
|
50
52
|
"sdk"
|
|
51
53
|
]
|
|
52
|
-
}
|
|
54
|
+
}
|