@moonpay/cli 1.17.0 → 1.18.0
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/chunk-6YOIZGHC.js +2 -0
- package/dist/chunk-DSMS3WZQ.js +48 -0
- package/dist/chunk-NNUDE3AO.js +4 -0
- package/dist/chunk-WKRUTTKX.js +3 -0
- package/dist/client-FQ3KSDK6.js +2 -0
- package/dist/{esm-FE2LDJCN.js → esm-L7XME6SN.js} +1 -1
- package/dist/index.js +6 -6
- package/dist/ledger-VGAMLABY.js +12 -0
- package/dist/mcp-UH5Y6G25.js +2 -0
- package/dist/{store-ZHNI5WHE.js → store-GXDGLPKN.js} +1 -1
- package/package.json +1 -1
- package/dist/chunk-PB5YB5HQ.js +0 -48
- package/dist/chunk-PL4KOOBO.js +0 -5
- package/dist/chunk-TPAYGT4L.js +0 -2
- package/dist/ledger-BESZMQUM.js +0 -12
- package/dist/mcp-MQ5G475D.js +0 -2
package/dist/chunk-PL4KOOBO.js
DELETED
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
process.noDeprecation = true; import { createRequire as __createRequire } from "module"; const require = __createRequire(import.meta.url);
|
|
2
|
-
import{a as z,b as Q,c as Z,d as xe,e as ee,g as re,h as te,l as ne}from"./chunk-TPAYGT4L.js";import{a as ve,b as H,d as Se,f as q}from"./chunk-LMDE72OE.js";var fe={};Se(fe,{ensureEncryptionKey:()=>U,getEncryptionKey:()=>I});import{execFileSync as T,execSync as $e}from"child_process";import{randomBytes as De}from"crypto";import{existsSync as He,readFileSync as Be,writeFileSync as Ue}from"fs";import{homedir as Le,platform as le}from"os";import{join as Me}from"path";function Je(e){try{T("security",["delete-generic-password","-s",g,"-a",v],{stdio:"ignore"})}catch{}T("security",["add-generic-password","-s",g,"-a",v,"-w",e],{stdio:"ignore"})}function je(){try{return T("security",["find-generic-password","-s",g,"-a",v,"-w"],{encoding:"utf-8",stdio:["ignore","pipe","ignore"]}).trim()}catch{return null}}function Ve(e){$e(`printf '%s' | secret-tool store --label="${g}" service "${g}" account "${v}"`,{input:e,stdio:["pipe","ignore","ignore"]})}function Ye(){try{return T("secret-tool",["lookup","service",g,"account",v],{encoding:"utf-8",stdio:["ignore","pipe","ignore"]}).trim()}catch{return null}}function Ge(e){p(),Ue(O,e,{encoding:"utf-8",mode:384})}function Xe(){try{return He(O)&&Be(O,"utf-8").trim()||null}catch{return null}}function qe(e){try{let r=le();return r==="darwin"?(Je(e),!0):r==="linux"?(Ve(e),!0):!1}catch{return!1}}function ze(){let e=le();return e==="darwin"?je():e==="linux"?Ye():null}function I(){let e=process.env.MOONPAY_ENCRYPTION_KEY;return e||(ze()??Xe())}function U(){let e=I();if(e)return e;let r=De(32).toString("hex");return qe(r)||(Ge(r),process.stderr.write("Note: Keychain unavailable. Encryption key stored in "+O+`
|
|
3
|
-
`)),r}var g,v,O,L=H(()=>{"use strict";M();g="moonpay-cli",v="encryption-key",O=Me(Le(),".config","moonpay",".encryption-key")});import{readFileSync as Qe}from"fs";import{join as Ze}from"path";import{homedir as er}from"os";function or(){if(S!==void 0)return S;try{S=JSON.parse(Qe(Ze(er(),".config","moonpay","consent.json"),"utf-8")).agentId??null}catch{S=null}return S??null}function de(){let e={"Content-Type":"application/json",[tr]:rr},r=or();return r&&(e[nr]=r),e}var rr,tr,nr,S,ue=H(()=>{"use strict";rr="1.17.0",tr="X-CLI-Version",nr="X-Agent-Id"});import*as s from"fs";import*as pe from"os";import*as K from"path";function p(){s.existsSync(C)||s.mkdirSync(C,{recursive:!0,mode:448})}function ye(e,r,t){let n=e+`.tmp.${process.pid}`;s.writeFileSync(n,r,{encoding:"utf-8",mode:t}),s.renameSync(n,e)}function ir(){p();try{let e=s.openSync(x,s.constants.O_CREAT|s.constants.O_EXCL|s.constants.O_WRONLY,384);s.writeSync(e,JSON.stringify({pid:process.pid,ts:Date.now()})),s.closeSync(e)}catch(e){if(e.code!=="EEXIST")throw e;try{let r=JSON.parse(s.readFileSync(x,"utf-8"));if(Date.now()-r.ts<sr)return null}catch{}try{s.unlinkSync(x)}catch{}try{let r=s.openSync(x,s.constants.O_CREAT|s.constants.O_EXCL|s.constants.O_WRONLY,384);s.writeSync(r,JSON.stringify({pid:process.pid,ts:Date.now()})),s.closeSync(r)}catch{return null}}return()=>{try{s.unlinkSync(x)}catch{}}}function me(){if(!s.existsSync(J))return null;try{let e=JSON.parse(s.readFileSync(J,"utf-8"));return e.baseUrl?e:null}catch{return null}}function zr(){let e=me();return e||(cr(j),j)}function F(){if(!s.existsSync(k))return null;let e=I();if(!e)return null;try{let r=JSON.parse(s.readFileSync(k,"utf-8")),t=z.parse(r),n=Z(t,e),o=JSON.parse(n);return!o.accessToken||!o.baseUrl?null:o}catch{return null}}function ar(e){let r=U(),t=Q(JSON.stringify(e),r);p(),ye(k,JSON.stringify(t,null,2),384)}function cr(e){p(),ye(J,JSON.stringify(e,null,2),384)}function Qr(){s.existsSync(k)&&s.unlinkSync(k)}function Zr(){let e=me(),r=F();return e?.baseUrl??r?.baseUrl??j.baseUrl}async function lr(e,r,t){let n=await fetch(`${e}/api/tools/${encodeURIComponent(r)}`,{method:"POST",signal:AbortSignal.timeout(15e3),headers:de(),body:JSON.stringify(t)}),o=await n.json();if(!n.ok){let a=o;throw new Error(a?.error??`${r} failed (${n.status})`)}return o}async function fr(e){if(!e.refreshToken)throw new Error("No refresh token available");let r=ir();if(!r){await new Promise(n=>setTimeout(n,2e3));let t=F();if(t&&t.expiresAt>Date.now())return t;throw new Error("Token refresh failed (concurrent refresh in progress)")}try{let t=F();if(t&&t.expiresAt>Date.now()+6e4)return t;let n=await lr(e.baseUrl,"refresh",{refreshToken:e.refreshToken}),o={accessToken:n.accessToken,refreshToken:n.refreshToken,expiresAt:n.expiresAt*1e3,baseUrl:e.baseUrl};return ar(o),o}finally{r()}}async function et(){let e=F();if(!e)return null;if(Date.now()>=e.expiresAt-dr){if(e.refreshToken)try{return(await fr(e)).accessToken}catch{return null}return null}return e.accessToken}var C,J,k,x,j,sr,dr,M=H(()=>{"use strict";ee();L();ue();C=K.join(pe.homedir(),".config","moonpay"),J=K.join(C,"config.json"),k=K.join(C,"credentials.json"),x=K.join(C,".credentials.lock"),j={baseUrl:"https://agents.moonpay.com"};sr=3e4;dr=300*1e3});import{existsSync as Y,readFileSync as ge,writeFileSync as ur,renameSync as he}from"fs";import{join as N}from"path";import{homedir as pr}from"os";import{randomBytes as yr}from"crypto";import*as i from"@open-wallet-standard/core";import we from"bs58";import{createHash as oe}from"crypto";import{HDKey as _}from"@scure/bip32";import{mnemonicToSeedSync as m}from"@scure/bip39";import{keccak_256 as B}from"@noble/hashes/sha3";import{derivePath as se}from"ed25519-hd-key";import*as ie from"bitcoinjs-lib";import Ce from"ecpair";import*as b from"tiny-secp256k1";import{Keypair as ke}from"@solana/web3.js";import Ke from"bs58";import{WalletContractV5R1 as Ee}from"@ton/ton";import{keyPairFromSeed as We}from"@ton/crypto";import*as ae from"@open-wallet-standard/core";var Ae=Ce(b);function ce(e,r,t=0){switch(r){case"solana":return _e(e,t);case"ethereum":return be(e,t);case"bitcoin":return Ie(e,t);case"tron":return Fe(e,t);case"ton":return Re(e,t);case"filecoin":return Pe(e,t)}}function _e(e,r){let t=m(e),n=`m/44'/501'/${r}'/0'`,{key:o}=se(n,Buffer.from(t).toString("hex")),a=ke.fromSeed(Uint8Array.from(o));return{privateKey:a.secretKey,address:a.publicKey.toBase58()}}function be(e,r){let t=m(e),n=_.fromMasterSeed(t),o=`m/44'/60'/${r}'/0/0`,a=n.derive(o);if(!a.privateKey)throw new Error("Failed to derive EVM private key");let c=Te(a.publicKey);return{privateKey:a.privateKey,address:c}}function Te(e){let r=b.pointCompress(e,!1),n=B(r.slice(1)).slice(-20),o="0x"+Buffer.from(n).toString("hex");return Oe(o)}function Oe(e){let r=e.toLowerCase().replace("0x",""),t=Buffer.from(B(Buffer.from(r,"utf8"))).toString("hex"),n="0x";for(let o=0;o<r.length;o++)n+=parseInt(t[o],16)>=8?r[o].toUpperCase():r[o];return n}function Ie(e,r){let t=m(e),n=_.fromMasterSeed(t),o=`m/84'/0'/${r}'/0/0`,a=n.derive(o);if(!a.privateKey)throw new Error("Failed to derive Bitcoin private key");let c=Ae.fromPrivateKey(Buffer.from(a.privateKey)),{address:y}=ie.payments.p2wpkh({pubkey:Buffer.from(c.publicKey)});if(!y)throw new Error("Failed to derive Bitcoin address");return{privateKey:a.privateKey,address:y}}function Fe(e,r){let t=m(e),n=_.fromMasterSeed(t),o=`m/44'/195'/${r}'/0/0`,a=n.derive(o);if(!a.privateKey)throw new Error("Failed to derive Tron private key");let c=Ne(a.publicKey);return{privateKey:a.privateKey,address:c}}function Ne(e){let r=b.pointCompress(e,!1),n=B(r.slice(1)).slice(-20),o=Buffer.concat([Buffer.from([65]),Buffer.from(n)]),a=oe("sha256").update(o).digest(),c=oe("sha256").update(a).digest(),y=Buffer.concat([o,c.slice(0,4)]);return Ke.encode(y)}function Re(e,r){let t=m(e),n=`m/44'/607'/${r}'/0'`,{key:o}=se(n,Buffer.from(t).toString("hex")),a=We(Buffer.from(o)),c=Ee.create({publicKey:Buffer.from(a.publicKey)});return{privateKey:a.secretKey,address:c.address.toString({bounceable:!1})}}function Pe(e,r){let t=m(e),n=_.fromMasterSeed(t),o=`m/44'/461'/${r}'/0/0`,a=n.derive(o);if(!a.privateKey)throw new Error("Failed to derive Filecoin private key");let c=ae.deriveAddress(e,"filecoin",r);return{privateKey:a.privateKey,address:c}}M();var R=N(pr(),".config","moonpay"),V=N(R,"hardware-wallets.json");function l(){return R}function mr(e){let r={};for(let t of e){let n=te[t.chainId];n&&(r[n]=t.address)}return r}function h(e){let r=mr(e.accounts);if(!r.filecoin)try{let t=i.exportWallet(e.id,null,l());t&&!t.startsWith("{")&&(r.filecoin=i.deriveAddress(t,"filecoin"))}catch{}return{name:e.name,type:"hd",addresses:r,createdAt:e.createdAt}}function u(){if(!Y(V))return[];try{return(JSON.parse(ge(V,"utf-8")).wallets??[]).map(r=>ne.parse(r))}catch{return[]}}function gr(e,r){p();let t=N(R,`.tmp.${yr(4).toString("hex")}`);ur(t,JSON.stringify(r,null,2),{mode:384}),he(t,e)}function w(e){gr(V,{wallets:e})}var E=N(R,"wallets.json");function G(){if(Y(E)){process.stderr.write(`Migrating legacy wallets...
|
|
4
|
-
`);let{migrated:e,skipped:r}=hr();process.stderr.write(`Migrated ${e} wallet(s), skipped ${r}.
|
|
5
|
-
`)}}function hr(){if(!Y(E))throw new Error("No legacy wallets.json found \u2014 nothing to migrate.");let{getEncryptionKey:e}=(L(),q(fe)),{decrypt:r,encryptedFileSchema:t}=(ee(),q(xe)),n=e();if(!n)throw new Error("Encryption key not found. Set MOONPAY_ENCRYPTION_KEY or ensure OS keychain is accessible.");let o=JSON.parse(ge(E,"utf-8")),a=t.parse(o),c=r(a,n),y=JSON.parse(c).wallets??[],P=l(),A=u(),X=0,$=0;for(let f of y){try{i.getWallet(f.name,P),$++;continue}catch{}if(A.some(d=>d.name===f.name)){$++;continue}if(f.type==="hardware")A.push({name:f.name,type:"hardware",device:f.device,addresses:f.addresses,createdAt:f.createdAt});else if(f.type==="hd"&&f.mnemonic)i.importWalletMnemonic(f.name,f.mnemonic,null,null,P);else if(f.type==="imported"&&f.privateKey){let d=f.privateKey;if(!/^[0-9a-fA-F]+$/.test(d)){let D=we.decode(d);d=Buffer.from(D.length===64?D.slice(0,32):D).toString("hex")}i.importWalletPrivateKey(f.name,d,null,P,null,d,d)}X++}return A.length>0&&w(A),he(E,E+".migrated"),{migrated:X,skipped:$}}function wr(e){G(),W(e);let r=i.createWallet(e,null,24,l());return h(r)}function vr(e,r){W(e);let t=i.importWalletMnemonic(e,r,null,null,l());return h(t)}function Sr(e,r){return W(e),h(i.importWalletPrivateKey(e,r,null,l()))}function xr(){G();let e=[];try{e=i.listWallets(l())}catch{}return[...e.map(t=>h(t)),...u()]}function Cr(e){G();let r=l();try{let t=i.getWallet(e,r);return h(t)}catch{}try{for(let t of i.listWallets(r))for(let n of t.accounts)if(n.address===e)return h(t)}catch{}for(let t of u()){if(t.name===e)return t;for(let n of Object.values(t.addresses))if(n===e)return t}return null}function ft(e){let r=Cr(e);if(!r)throw new Error(`Wallet "${e}" not found`);return r}function kr(e){try{i.deleteWallet(e,l());return}catch{}let r=u(),t=r.findIndex(n=>n.name===e);if(t===-1)throw new Error(`Wallet "${e}" not found`);r.splice(t,1),w(r)}function dt(e,r){if(e===r)return;W(r);try{i.getWallet(e,l()),i.renameWallet(e,r,l());return}catch(o){if(o instanceof Error&&!o.message.includes("not found"))throw o}let t=u(),n=t.find(o=>o.name===e);if(!n)throw new Error(`Wallet "${e}" not found`);n.name=r,w(t)}function ut(e){return i.exportWallet(e,null,l())}function Kr(e){W(e.name);let r=u();r.push(e),w(r)}function pt(e,r){let t=u(),n=t.find(o=>o.name===e);if(!n)throw new Error(`Hardware wallet "${e}" not found`);n.addresses=r,w(t)}function yt(e,r,t){return i.signTransaction(e,r,t,null,null,l())}function mt(e,r,t,n){return i.signMessage(e,r,t,null,n??null,null,l())}function gt(e,r,t){return i.signTypedData(e,r,t,null,null,l())}function ht(e,r){if(e.type==="hardware")throw new Error(`Wallet "${e.name}" is a hardware wallet. Signing must happen on the device.`);let t=re[r],n=i.exportWallet(e.name,null,l());if(n.includes(" "))return ce(n,t);let o;if(n.startsWith("{")){let c=JSON.parse(n);o=t==="solana"||t==="ton"?c.ed25519:c.secp256k1}else o=n;let a=Uint8Array.from(Buffer.from(o,"hex"));if(t==="solana"&&a.length===32){let c=ve("tweetnacl");a=Uint8Array.from(c.sign.keyPair.fromSeed(a).secretKey)}return{privateKey:a,address:e.addresses[t]??""}}var Er=xr,wt=kr;function Wr(e){if(e.type==="hardware"){Kr(e);return}if(e.type==="hd"&&e.mnemonic){vr(e.name,e.mnemonic);return}if(e.type==="imported"&&e.privateKey){let r=e.privateKey;if(r.startsWith("0x"))r=r.slice(2);else if(!/^[0-9a-fA-F]+$/.test(r)){let t=we.decode(r);r=Buffer.from(t.length===64?t.slice(0,32):t).toString("hex")}Sr(e.name,r);return}wr(e.name)}function vt(e){for(let r of e)Wr(r)}function St(e){let r=Er();e(r),w(r.filter(t=>t.type==="hardware"))}function W(e){try{throw i.getWallet(e,l()),new Error(`Wallet "${e}" already exists`)}catch(r){if(r instanceof Error&&r.message.includes("already exists"))throw r}if(u().some(r=>r.name===e))throw new Error(`Wallet "${e}" already exists`)}export{rr as a,de as b,ue as c,p as d,zr as e,F as f,ar as g,Qr as h,Zr as i,fr as j,et as k,M as l,ce as m,l as n,G as o,hr as p,wr as q,vr as r,Sr as s,xr as t,Cr as u,ft as v,kr as w,dt as x,ut as y,Kr as z,pt as A,yt as B,mt as C,gt as D,ht as E,Er as F,wt as G,Wr as H,vt as I,St as J};
|
package/dist/chunk-TPAYGT4L.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
process.noDeprecation = true; import { createRequire as __createRequire } from "module"; const require = __createRequire(import.meta.url);
|
|
2
|
-
import{b as v,d as C}from"./chunk-LMDE72OE.js";var F={};C(F,{decrypt:()=>W,encrypt:()=>E,encryptedFileSchema:()=>b});import{randomBytes as s,scryptSync as u,createCipheriv as A,createDecipheriv as z}from"crypto";import{z as n}from"zod";function E(t,o){let a=s(32),c=u(o,a,d,{N:h,r:f,p:y,maxmem:g}),i=s(12),r=A("aes-256-gcm",c,i),p=Buffer.concat([r.update(t,"utf8"),r.final()]);return{encryption:{cipher:"aes-256-gcm",kdf:"scrypt",kdfparams:{n:h,r:f,p:y},salt:a.toString("base64"),iv:i.toString("base64"),tag:r.getAuthTag().toString("base64")},data:p.toString("base64")}}function W(t,o){let{salt:a,iv:c,tag:i,kdfparams:r}=t.encryption,p=u(o,Buffer.from(a,"base64"),d,{N:r.n,r:r.r,p:r.p,maxmem:g}),m=z("aes-256-gcm",p,Buffer.from(c,"base64"),{authTagLength:16});return m.setAuthTag(Buffer.from(i,"base64")),Buffer.concat([m.update(Buffer.from(t.data,"base64")),m.final()]).toString("utf8")}var h,f,y,d,g,b,S=v(()=>{"use strict";h=2**18,f=8,y=1,d=32,g=512*1024*1024,b=n.object({encryption:n.object({cipher:n.literal("aes-256-gcm"),kdf:n.literal("scrypt"),kdfparams:n.object({n:n.number(),r:n.number(),p:n.number()}),salt:n.string(),iv:n.string(),tag:n.string()}),data:n.string()})});S();import{z as e}from"zod";var P=e.enum(["solana","ethereum","base","arbitrum","polygon","optimism","bnb","avalanche","bitcoin","tron","ton","filecoin","tempo","tempo-moderato","ethereum-sepolia","base-sepolia","arbitrum-sepolia","polygon-amoy","solana-devnet"]),K=e.enum(["solana","ethereum","bitcoin","tron","ton","filecoin"]),Y={solana:"solana",ethereum:"ethereum",base:"ethereum",arbitrum:"ethereum",polygon:"ethereum",optimism:"ethereum",bnb:"ethereum",avalanche:"ethereum",bitcoin:"bitcoin",tron:"tron",ton:"ton",filecoin:"filecoin",tempo:"ethereum","tempo-moderato":"ethereum","ethereum-sepolia":"ethereum","base-sepolia":"ethereum","arbitrum-sepolia":"ethereum","polygon-amoy":"ethereum","solana-devnet":"solana"},B={"eip155:1":"ethereum","solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp":"solana","bip122:000000000019d6689c085ae165831e93":"bitcoin","tron:mainnet":"tron","ton:mainnet":"ton","fil:mainnet":"filecoin"},l=e.object({solana:e.string().optional(),ethereum:e.string().optional(),bitcoin:e.string().optional(),tron:e.string().optional(),ton:e.string().optional(),filecoin:e.string().optional()}),w=["base","arbitrum","polygon","optimism","bnb","avalanche","tempo","tempo-moderato","ethereum-sepolia","base-sepolia","arbitrum-sepolia","polygon-amoy"];function H(t){let o={};if(t.solana&&(o.solana=t.solana,o["solana-devnet"]=t.solana),t.ethereum){o.ethereum=t.ethereum;for(let a of w)o[a]=t.ethereum}return t.bitcoin&&(o.bitcoin=t.bitcoin),t.tron&&(o.tron=t.tron),t.ton&&(o.ton=t.ton),t.filecoin&&(o.filecoin=t.filecoin),o}var R=e.object({name:e.string(),type:e.literal("hd"),mnemonic:e.string().optional(),addresses:l,createdAt:e.string()}),T=e.object({name:e.string(),type:e.literal("imported"),chain:K.optional(),privateKey:e.string().optional(),addresses:l,createdAt:e.string()}),x=e.enum(["ledger"]),_=e.object({name:e.string(),type:e.literal("hardware"),device:x,addresses:l,createdAt:e.string()}),M=e.discriminatedUnion("type",[R,T,_]),q=e.object({name:e.string(),type:e.enum(["hd","imported","hardware"]),device:x.optional(),addresses:e.record(e.string(),e.string()),createdAt:e.string()});export{b as a,E as b,W as c,F as d,S as e,P as f,Y as g,B as h,l as i,H as j,x as k,_ as l,q as m};
|
package/dist/ledger-BESZMQUM.js
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
process.noDeprecation = true; import { createRequire as __createRequire } from "module"; const require = __createRequire(import.meta.url);
|
|
2
|
-
import{g as S}from"./chunk-TPAYGT4L.js";import{a as v}from"./chunk-LMDE72OE.js";var B=3e4;var T=`Ledger support requires additional packages.
|
|
3
|
-
Run: npm i -g @moonpay/cli --include=optional`;function y(){try{let e=v("@ledgerhq/device-management-kit"),n=v("@ledgerhq/device-transport-kit-node-hid"),t=v("rxjs");return{...e,...n,...t}}catch{throw new Error(T)}}function I(){try{return v("@ledgerhq/device-signer-kit-ethereum")}catch{throw new Error(T)}}function D(){try{return v("@ledgerhq/device-signer-kit-solana")}catch{throw new Error(T)}}var h=null,l=null;function w(){if(!h){let e=y();h=new e.DeviceManagementKitBuilder().addTransport(e.nodeHidTransportFactory).build()}return h}function A(){if(!l)throw new Error("No Ledger device connected. Connect first.");return l}var C={"unlock-device":"ACTION REQUIRED: Unlock your Ledger device by entering your PIN","confirm-open-app":"ACTION REQUIRED: Confirm opening the app on your Ledger device screen","sign-transaction":"ACTION REQUIRED: Review and approve the transaction on your Ledger device screen","sign-personal-message":"ACTION REQUIRED: Review and approve the message on your Ledger device screen","verify-address":"ACTION REQUIRED: Verify the address shown on your Ledger device screen"};async function f(e,n,t=6e4){let{DeviceActionStatus:r}=y();return new Promise((a,o)=>{let d="",u=!1,i=c=>{u||(u=!0,clearTimeout(g),p.unsubscribe(),c())},g=setTimeout(()=>{i(()=>{e.cancel(),o(new Error(`${n} timed out after ${t/1e3}s. Make sure the correct app is open on your Ledger and try again.`))})},t),p=e.observable.subscribe({next:c=>{switch(c.status){case r.Pending:{let s=c.intermediateValue?.requiredUserInteraction??"";if(s&&s!=="none"&&s!==d){d=s;let m=C[s]??s;m&&process.stderr.write(` ${m}
|
|
4
|
-
`)}break}case r.Completed:i(()=>a(c.output));break;case r.Error:i(()=>{let s=c.error,m=s instanceof Error?s.message:s&&typeof s=="object"?s._tag??s.message??JSON.stringify(s):String(s);o(new Error(`${n} failed: ${m}`))});break;case r.Stopped:i(()=>o(new Error(`${n} was cancelled`)));break}},error:c=>i(()=>o(c))})})}async function O(){let e=y(),n=w().startDiscovering({});process.stderr.write(`Scanning for Ledger devices via USB...
|
|
5
|
-
`);let t=await e.firstValueFrom(n.pipe(e.take(1),e.timeout(B))).finally(()=>{w().stopDiscovering()}),r=t.deviceModel.model??t.deviceModel.id;process.stderr.write(`Connecting to Ledger ${r}...
|
|
6
|
-
`);let a=w();l=await a.connect({device:t});let o=a.getDeviceSessionState({sessionId:l});return await e.firstValueFrom(o.pipe(e.filter(d=>d.sessionStateType>=1),e.take(1),e.timeout(1e4))),process.stderr.write(`Connected to Ledger ${r}
|
|
7
|
-
`),l}async function P(){if(!l)return null;try{let e=y(),t=w().getDeviceSessionState({sessionId:l}),r=await e.firstValueFrom(t.pipe(e.take(1),e.timeout(3e3)));return r.sessionStateType>=1?r.currentApp?.name??null:null}catch{return null}}var U={ethereum:"Ethereum",solana:"Solana"};function M(e){let n=String(e);return n.includes("6807")||n.includes("6a15")||n.includes("UnknownDeviceExchangeError")}async function _(e){process.stderr.write(`Installing ${e} app on your Ledger...
|
|
8
|
-
`);let{OpenAppWithDependenciesDeviceAction:n}=y(),t=new n({input:{appName:e}}),a=w().executeDeviceAction({sessionId:A(),deviceAction:t});await f(a,`Install ${e}`,18e4),process.stderr.write(`Installed ${e} app
|
|
9
|
-
`)}async function R(e){let n=S[e],t=U[n];if(!t||await P()===t)return;process.stderr.write(`Opening ${t} app on your Ledger...
|
|
10
|
-
`);let{OpenAppDeviceAction:a}=y(),o=new a({input:{appName:t}}),u=w().executeDeviceAction({sessionId:A(),deviceAction:o});try{await f(u,`Open ${t}`)}catch(i){if(M(i)){await E(),await _(t),await E();return}if(!String(i).includes("isconnect"))throw i}await E()}async function E(){try{await w().disconnect({sessionId:l})}catch{}l=null,await new Promise(e=>setTimeout(e,500)),await O()}function L(e,n=0){switch(e){case"ethereum":return`44'/60'/${n}'/0/0`;case"solana":return`44'/501'/${n}'/0'`;case"bitcoin":case"tron":throw new Error(`${e} derivation via Ledger is not supported.`)}}function k(e){return e.startsWith("0x")?e.slice(2):e}function b(e){return e.startsWith("0x")?e:`0x${e}`}async function x(e){let n=S[e];if(n==="bitcoin")throw new Error("Bitcoin address derivation via Ledger is not yet supported.");if(n==="tron")throw new Error("Tron address derivation via Ledger is not supported. The Ethereum signer cannot interact with the Tron Ledger app.");await R(e);let t=L(n),r=A(),a=w();switch(n){case"ethereum":{let{SignerEthBuilder:o}=I(),u=new o({dmk:a,sessionId:r}).build().getAddress(t,{skipOpenApp:!1});return(await f(u,"Get Ethereum address")).address}case"solana":{let{SignerSolanaBuilder:o}=D(),u=new o({dmk:a,sessionId:r}).build().getAddress(t,{skipOpenApp:!1});return await f(u,"Get Solana address")}}}async function q(){let e={};try{e.ethereum=await x("ethereum")}catch(n){process.stderr.write(`Failed to get Ethereum address: ${n}
|
|
11
|
-
`)}try{e.solana=await x("solana")}catch(n){process.stderr.write(`Failed to get Solana address: ${n}
|
|
12
|
-
`)}if(!e.ethereum&&!e.solana)throw new Error("Could not derive any addresses from Ledger device");return e}async function F(e,n){let t=S[e];if(t==="bitcoin")throw new Error("Bitcoin transaction signing via Ledger is not yet supported. Use a software wallet for Bitcoin transactions.");if(t==="tron")throw new Error("Tron transaction signing via Ledger is not supported. Use a software wallet for Tron transactions.");await R(e);let r=L(t),a=A(),o=w();switch(t){case"ethereum":{let{SignerEthBuilder:d}=I(),u=new d({dmk:o,sessionId:a}).build(),i=b(n.startsWith("0x")?n:Buffer.from(n,"base64").toString("hex")),g=Uint8Array.from(Buffer.from(k(i),"hex")),p=u.signTransaction(r,g,{skipOpenApp:!1}),c=await f(p,"Sign transaction"),{parseTransaction:s,serializeTransaction:m}=await import("viem"),$=s(i);return{transaction:m($,{r:b(k(c.r)),s:b(k(c.s)),v:BigInt(c.v)})}}case"solana":{let{SignerSolanaBuilder:d}=D(),u=new d({dmk:o,sessionId:a}).build(),{VersionedTransaction:i}=await import("@solana/web3.js"),g=Uint8Array.from(Buffer.from(n,"base64")),p=i.deserialize(g),c=p.message.serialize(),s=u.signTransaction(r,c,{skipOpenApp:!1}),m=await f(s,"Sign Solana transaction");return p.signatures[0]=m,{transaction:Buffer.from(p.serialize()).toString("base64")}}}}async function V(e,n){let t=S[e];if(t==="bitcoin")throw new Error("Bitcoin message signing via Ledger is not yet supported. Use a software wallet for Bitcoin message signing.");if(t==="tron")throw new Error("Tron message signing via Ledger is not supported. Use a software wallet for Tron message signing.");await R(e);let r=L(t),a=A(),o=w();switch(t){case"ethereum":{let{SignerEthBuilder:d}=I(),i=new d({dmk:o,sessionId:a}).build().signMessage(r,n,{skipOpenApp:!1}),g=await f(i,"Sign message"),p=k(g.r),c=k(g.s),s=g.v.toString(16).padStart(2,"0");return{signature:`0x${p}${c}${s}`}}case"solana":{let{SignerSolanaBuilder:d}=D(),u=new d({dmk:o,sessionId:a}).build(),i=Buffer.from(n,"utf8").toString("hex"),g=u.signMessage(r,i,{skipOpenApp:!1}),p=await f(g,"Sign Solana message");return{signature:(await import("bs58")).default.encode(p)}}}}async function G(){if(l){try{await w().disconnect({sessionId:l})}catch{}l=null}if(h){try{h.close()}catch{}h=null}}export{O as connectLedger,G as disconnectLedger,x as ledgerGetAddress,q as ledgerGetAllAddresses,V as ledgerSignMessage,F as ledgerSignTransaction};
|
package/dist/mcp-MQ5G475D.js
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
process.noDeprecation = true; import { createRequire as __createRequire } from "module"; const require = __createRequire(import.meta.url);
|
|
2
|
-
import{a as d,b as f,e as u}from"./chunk-PB5YB5HQ.js";import{a as l,c as R}from"./chunk-PL4KOOBO.js";import"./chunk-TPAYGT4L.js";import"./chunk-LMDE72OE.js";import{Server as N}from"@modelcontextprotocol/sdk/server/index.js";import{StdioServerTransport as O}from"@modelcontextprotocol/sdk/server/stdio.js";import{CallToolRequestSchema as T,ListToolsRequestSchema as x}from"@modelcontextprotocol/sdk/types.js";import{zodToJsonSchema as k}from"zod-to-json-schema";R();var y=new Map(u.map(s=>[s.schema.name,s]));function q(s){let n=s.inputSchema;if(n.$ref&&n.definitions){let c=n.$ref.replace("#/definitions/","");return n.definitions[c]??n}return n}async function P(){let s=new N({name:"moonpay",version:l},{capabilities:{tools:{listChanged:!0}}}),n=u.map(e=>({name:e.schema.name,description:e.schema.description,inputSchema:k(e.schema.input)})),c=new Map;for(let e of f){if(y.has(e.name))continue;let t=q(e);c.set(e.name,t.properties??{}),n.push({name:e.name,description:e.description,inputSchema:{type:"object",properties:t.properties??{},...t.required?{required:t.required}:{},...t.additionalProperties!==void 0?{additionalProperties:t.additionalProperties}:{}}})}let h=new Map(n.map(e=>[e.name,e]));s.setRequestHandler(x,async()=>({tools:n.map(e=>({name:e.name,description:e.description,inputSchema:e.inputSchema}))})),s.setRequestHandler(T,async e=>{let{name:t,arguments:o={}}=e.params;if(!h.has(t))return{content:[{type:"text",text:`Unknown tool: ${t}`}],isError:!0};try{let i=y.get(t);if(i){let p=i.schema.input.shape??{};for(let[m,a]of Object.entries(p))o[m]===void 0&&a._def.typeName==="ZodNullable"&&(o[m]=null);let r=await i.handler(o);return{content:[{type:"text",text:JSON.stringify(r,null,2)}]}}let S=c.get(t)??{};for(let[p,r]of Object.entries(S))o[p]===void 0&&(Array.isArray(r.type)?r.type.includes("null"):r.anyOf?.some(w=>w.type==="null"))&&(o[p]=null),(r.type==="number"||r.type==="integer"||Array.isArray(r.type)&&r.type.some(a=>a==="number"||a==="integer")||r.anyOf?.some(a=>a.type==="number"||a.type==="integer"))&&typeof o[p]=="string"&&(o[p]=Number(o[p]));let b=await d._call(t,o);return{content:[{type:"text",text:JSON.stringify(b,null,2)}]}}catch(i){return{content:[{type:"text",text:i instanceof Error?i.message:String(i)}],isError:!0}}});let g=new O;await s.connect(g)}export{P as startMcpServer};
|