@moonpay/cli 1.96.0 → 1.96.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
1
  process.noDeprecation = true; import { createRequire as __createRequire } from "module"; const require = __createRequire(import.meta.url);
2
- import{b as m,d as b}from"./chunk-LMDE72OE.js";var G={};b(G,{decrypt:()=>k,encrypt:()=>T,encryptedFileSchema:()=>O});import{randomBytes as A,scryptSync as v,createCipheriv as X,createDecipheriv as $}from"crypto";import{z as i}from"zod";function T(n,t){let r=A(32),o=v(t,r,D,{N:R,r:L,p:F,maxmem:K}),s=A(12),c=X("aes-256-gcm",o,s),_=Buffer.concat([c.update(n,"utf8"),c.final()]);return{encryption:{cipher:"aes-256-gcm",kdf:"scrypt",kdfparams:{n:R,r:L,p:F},salt:r.toString("base64"),iv:s.toString("base64"),tag:c.getAuthTag().toString("base64")},data:_.toString("base64")}}function k(n,t){let{salt:r,iv:o,tag:s,kdfparams:c}=n.encryption,_=v(t,Buffer.from(r,"base64"),D,{N:c.n,r:c.r,p:c.p,maxmem:K}),x=$("aes-256-gcm",_,Buffer.from(o,"base64"),{authTagLength:16});return x.setAuthTag(Buffer.from(s,"base64")),Buffer.concat([x.update(Buffer.from(n.data,"base64")),x.final()]).toString("utf8")}var R,L,F,D,K,O,P=m(()=>{"use strict";R=2**18,L=8,F=1,D=32,K=512*1024*1024,O=i.object({encryption:i.object({cipher:i.literal("aes-256-gcm"),kdf:i.literal("scrypt"),kdfparams:i.object({n:i.number(),r:i.number(),p:i.number()}),salt:i.string(),iv:i.string(),tag:i.string()}),data:i.string()})});import{readFileSync as W}from"fs";import{join as z}from"path";import{homedir as q}from"os";function en(){if(f!==void 0)return f;try{f=JSON.parse(W(z(q(),".config","moonpay","consent.json"),"utf-8")).agentId??null}catch{f=null}return f??null}function rn(){return process.env.OPENCLAW_SHELL?"openclaw":process.env.CLAUDECODE?"claude-code":process.env.CODEX_CI?"codex":process.env.GEMINI_CLI?"gemini-cli":"human"}function U(){let n={"Content-Type":"application/json",[Z]:Q,[tn]:rn()},t=en();return t&&(n[nn]=t),n}var Q,Z,nn,f,tn,j=m(()=>{"use strict";Q="1.96.0",Z="X-CLI-Version",nn="X-Agent-Id";tn="X-Agent"});import*as e from"fs";import*as Y from"os";import*as g from"path";function d(){e.existsSync(l)||e.mkdirSync(l,{recursive:!0,mode:448})}function H(n,t,r){let o=n+`.tmp.${process.pid}`;e.writeFileSync(o,t,{encoding:"utf-8",mode:r}),e.renameSync(o,n)}function sn(){d();try{let n=e.openSync(u,e.constants.O_CREAT|e.constants.O_EXCL|e.constants.O_WRONLY,384);e.writeSync(n,JSON.stringify({pid:process.pid,ts:Date.now()})),e.closeSync(n)}catch(n){if(n.code!=="EEXIST")throw n;try{let t=JSON.parse(e.readFileSync(u,"utf-8"));if(Date.now()-t.ts<on)return null}catch{}try{e.unlinkSync(u)}catch{}try{let t=e.openSync(u,e.constants.O_CREAT|e.constants.O_EXCL|e.constants.O_WRONLY,384);e.writeSync(t,JSON.stringify({pid:process.pid,ts:Date.now()})),e.closeSync(t)}catch{return null}}return()=>{try{e.unlinkSync(u)}catch{}}}function B(){if(!e.existsSync(w))return null;try{let n=JSON.parse(e.readFileSync(w,"utf-8"));return n.baseUrl?n:null}catch{return null}}function Pn(){let n=B();return n||(an(N),N)}function S(){if(!e.existsSync(p))return null;let n=h();if(!n)return null;try{let t=JSON.parse(e.readFileSync(p,"utf-8")),r=O.parse(t),o=k(r,n),s=JSON.parse(o);return!s.accessToken||!s.baseUrl?null:s}catch{return null}}function cn(n){let t=I(),r=T(JSON.stringify(n),t);d(),H(p,JSON.stringify(r,null,2),384)}function an(n){d(),H(w,JSON.stringify(n,null,2),384)}function Un(){e.existsSync(p)&&e.unlinkSync(p)}function jn(){let n=B(),t=S();return n?.baseUrl??t?.baseUrl??N.baseUrl}async function fn(n,t,r){let o=await fetch(`${n}/api/tools/${encodeURIComponent(t)}`,{method:"POST",signal:AbortSignal.timeout(15e3),headers:U(),body:JSON.stringify(r)}),s=await o.json();if(!o.ok){let c=s;throw new Error(c?.error??`${t} failed (${o.status})`)}return s}async function un(n){if(!n.refreshToken)throw new Error("No refresh token available");let t=sn();if(!t){await new Promise(o=>setTimeout(o,2e3));let r=S();if(r&&r.expiresAt>Date.now())return r;throw new Error("Token refresh failed (concurrent refresh in progress)")}try{let r=S();if(r&&r.expiresAt>Date.now()+6e4)return r;let o=await fn(n.baseUrl,"refresh",{refreshToken:n.refreshToken}),s={accessToken:o.accessToken,refreshToken:o.refreshToken,expiresAt:o.expiresAt*1e3,baseUrl:n.baseUrl};return cn(s),s}finally{t()}}async function Jn(){let n=S();if(!n)return null;if(Date.now()>=n.expiresAt-ln){if(n.refreshToken)try{return(await un(n)).accessToken}catch{return null}return null}return n.accessToken}var l,w,p,u,N,on,ln,V=m(()=>{"use strict";P();J();j();l=g.join(Y.homedir(),".config","moonpay"),w=g.join(l,"config.json"),p=g.join(l,"credentials.json"),u=g.join(l,".credentials.lock"),N={baseUrl:"https://agents.moonpay.com"};on=3e4;ln=300*1e3});var Nn={};b(Nn,{ensureEncryptionKey:()=>I,getEncryptionKey:()=>h});import{execFileSync as C,execSync as pn}from"child_process";import{randomBytes as gn}from"crypto";import{existsSync as dn,readFileSync as yn,writeFileSync as mn}from"fs";import{homedir as Sn,platform as M}from"os";import{join as hn}from"path";function Cn(n){try{C("security",["delete-generic-password","-s",a,"-a",y],{stdio:"ignore"})}catch{}C("security",["add-generic-password","-s",a,"-a",y,"-w",n],{stdio:"ignore"})}function En(){try{return C("security",["find-generic-password","-s",a,"-a",y,"-w"],{encoding:"utf-8",stdio:["ignore","pipe","ignore"]}).trim()}catch{return null}}function _n(n){pn(`printf '%s' | secret-tool store --label="${a}" service "${a}" account "${y}"`,{input:n,stdio:["pipe","ignore","ignore"]})}function xn(){try{return C("secret-tool",["lookup","service",a,"account",y],{encoding:"utf-8",stdio:["ignore","pipe","ignore"]}).trim()}catch{return null}}function On(n){d(),mn(E,n,{encoding:"utf-8",mode:384})}function Tn(){try{return dn(E)&&yn(E,"utf-8").trim()||null}catch{return null}}function kn(n){try{let t=M();return t==="darwin"?(Cn(n),!0):t==="linux"?(_n(n),!0):!1}catch{return!1}}function wn(){let n=M();return n==="darwin"?En():n==="linux"?xn():null}function h(){let n=process.env.MOONPAY_ENCRYPTION_KEY;return n||(wn()??Tn())}function I(){let n=h();if(n)return n;let t=gn(32).toString("hex");return kn(t)||(On(t),process.stderr.write("Note: Keychain unavailable. Encryption key stored in "+E+`
2
+ import{b as m,d as b}from"./chunk-LMDE72OE.js";var G={};b(G,{decrypt:()=>k,encrypt:()=>T,encryptedFileSchema:()=>O});import{randomBytes as A,scryptSync as v,createCipheriv as X,createDecipheriv as $}from"crypto";import{z as i}from"zod";function T(n,t){let r=A(32),o=v(t,r,D,{N:R,r:L,p:F,maxmem:K}),s=A(12),c=X("aes-256-gcm",o,s),_=Buffer.concat([c.update(n,"utf8"),c.final()]);return{encryption:{cipher:"aes-256-gcm",kdf:"scrypt",kdfparams:{n:R,r:L,p:F},salt:r.toString("base64"),iv:s.toString("base64"),tag:c.getAuthTag().toString("base64")},data:_.toString("base64")}}function k(n,t){let{salt:r,iv:o,tag:s,kdfparams:c}=n.encryption,_=v(t,Buffer.from(r,"base64"),D,{N:c.n,r:c.r,p:c.p,maxmem:K}),x=$("aes-256-gcm",_,Buffer.from(o,"base64"),{authTagLength:16});return x.setAuthTag(Buffer.from(s,"base64")),Buffer.concat([x.update(Buffer.from(n.data,"base64")),x.final()]).toString("utf8")}var R,L,F,D,K,O,P=m(()=>{"use strict";R=2**18,L=8,F=1,D=32,K=512*1024*1024,O=i.object({encryption:i.object({cipher:i.literal("aes-256-gcm"),kdf:i.literal("scrypt"),kdfparams:i.object({n:i.number(),r:i.number(),p:i.number()}),salt:i.string(),iv:i.string(),tag:i.string()}),data:i.string()})});import{readFileSync as W}from"fs";import{join as z}from"path";import{homedir as q}from"os";function en(){if(f!==void 0)return f;try{f=JSON.parse(W(z(q(),".config","moonpay","consent.json"),"utf-8")).agentId??null}catch{f=null}return f??null}function rn(){return process.env.OPENCLAW_SHELL?"openclaw":process.env.CLAUDECODE?"claude-code":process.env.CODEX_CI?"codex":process.env.GEMINI_CLI?"gemini-cli":"human"}function U(){let n={"Content-Type":"application/json",[Z]:Q,[tn]:rn()},t=en();return t&&(n[nn]=t),n}var Q,Z,nn,f,tn,j=m(()=>{"use strict";Q="1.96.1",Z="X-CLI-Version",nn="X-Agent-Id";tn="X-Agent"});import*as e from"fs";import*as Y from"os";import*as g from"path";function d(){e.existsSync(l)||e.mkdirSync(l,{recursive:!0,mode:448})}function H(n,t,r){let o=n+`.tmp.${process.pid}`;e.writeFileSync(o,t,{encoding:"utf-8",mode:r}),e.renameSync(o,n)}function sn(){d();try{let n=e.openSync(u,e.constants.O_CREAT|e.constants.O_EXCL|e.constants.O_WRONLY,384);e.writeSync(n,JSON.stringify({pid:process.pid,ts:Date.now()})),e.closeSync(n)}catch(n){if(n.code!=="EEXIST")throw n;try{let t=JSON.parse(e.readFileSync(u,"utf-8"));if(Date.now()-t.ts<on)return null}catch{}try{e.unlinkSync(u)}catch{}try{let t=e.openSync(u,e.constants.O_CREAT|e.constants.O_EXCL|e.constants.O_WRONLY,384);e.writeSync(t,JSON.stringify({pid:process.pid,ts:Date.now()})),e.closeSync(t)}catch{return null}}return()=>{try{e.unlinkSync(u)}catch{}}}function B(){if(!e.existsSync(w))return null;try{let n=JSON.parse(e.readFileSync(w,"utf-8"));return n.baseUrl?n:null}catch{return null}}function Pn(){let n=B();return n||(an(N),N)}function S(){if(!e.existsSync(p))return null;let n=h();if(!n)return null;try{let t=JSON.parse(e.readFileSync(p,"utf-8")),r=O.parse(t),o=k(r,n),s=JSON.parse(o);return!s.accessToken||!s.baseUrl?null:s}catch{return null}}function cn(n){let t=I(),r=T(JSON.stringify(n),t);d(),H(p,JSON.stringify(r,null,2),384)}function an(n){d(),H(w,JSON.stringify(n,null,2),384)}function Un(){e.existsSync(p)&&e.unlinkSync(p)}function jn(){let n=B(),t=S();return n?.baseUrl??t?.baseUrl??N.baseUrl}async function fn(n,t,r){let o=await fetch(`${n}/api/tools/${encodeURIComponent(t)}`,{method:"POST",signal:AbortSignal.timeout(15e3),headers:U(),body:JSON.stringify(r)}),s=await o.json();if(!o.ok){let c=s;throw new Error(c?.error??`${t} failed (${o.status})`)}return s}async function un(n){if(!n.refreshToken)throw new Error("No refresh token available");let t=sn();if(!t){await new Promise(o=>setTimeout(o,2e3));let r=S();if(r&&r.expiresAt>Date.now())return r;throw new Error("Token refresh failed (concurrent refresh in progress)")}try{let r=S();if(r&&r.expiresAt>Date.now()+6e4)return r;let o=await fn(n.baseUrl,"refresh",{refreshToken:n.refreshToken}),s={accessToken:o.accessToken,refreshToken:o.refreshToken,expiresAt:o.expiresAt*1e3,baseUrl:n.baseUrl};return cn(s),s}finally{t()}}async function Jn(){let n=S();if(!n)return null;if(Date.now()>=n.expiresAt-ln){if(n.refreshToken)try{return(await un(n)).accessToken}catch{return null}return null}return n.accessToken}var l,w,p,u,N,on,ln,V=m(()=>{"use strict";P();J();j();l=g.join(Y.homedir(),".config","moonpay"),w=g.join(l,"config.json"),p=g.join(l,"credentials.json"),u=g.join(l,".credentials.lock"),N={baseUrl:"https://agents.moonpay.com"};on=3e4;ln=300*1e3});var Nn={};b(Nn,{ensureEncryptionKey:()=>I,getEncryptionKey:()=>h});import{execFileSync as C,execSync as pn}from"child_process";import{randomBytes as gn}from"crypto";import{existsSync as dn,readFileSync as yn,writeFileSync as mn}from"fs";import{homedir as Sn,platform as M}from"os";import{join as hn}from"path";function Cn(n){try{C("security",["delete-generic-password","-s",a,"-a",y],{stdio:"ignore"})}catch{}C("security",["add-generic-password","-s",a,"-a",y,"-w",n],{stdio:"ignore"})}function En(){try{return C("security",["find-generic-password","-s",a,"-a",y,"-w"],{encoding:"utf-8",stdio:["ignore","pipe","ignore"]}).trim()}catch{return null}}function _n(n){pn(`printf '%s' | secret-tool store --label="${a}" service "${a}" account "${y}"`,{input:n,stdio:["pipe","ignore","ignore"]})}function xn(){try{return C("secret-tool",["lookup","service",a,"account",y],{encoding:"utf-8",stdio:["ignore","pipe","ignore"]}).trim()}catch{return null}}function On(n){d(),mn(E,n,{encoding:"utf-8",mode:384})}function Tn(){try{return dn(E)&&yn(E,"utf-8").trim()||null}catch{return null}}function kn(n){try{let t=M();return t==="darwin"?(Cn(n),!0):t==="linux"?(_n(n),!0):!1}catch{return!1}}function wn(){let n=M();return n==="darwin"?En():n==="linux"?xn():null}function h(){let n=process.env.MOONPAY_ENCRYPTION_KEY;return n||(wn()??Tn())}function I(){let n=h();if(n)return n;let t=gn(32).toString("hex");return kn(t)||(On(t),process.stderr.write("Note: Keychain unavailable. Encryption key stored in "+E+`
3
3
  `)),t}var a,y,E,J=m(()=>{"use strict";V();a="moonpay-cli",y="encryption-key",E=hn(Sn(),".config","moonpay",".encryption-key")});export{G as a,P as b,Nn as c,J as d,Q as e,U as f,j as g,d as h,Pn as i,S as j,cn as k,Un as l,jn as m,un as n,Jn as o,V as p};
@@ -1,2 +1,2 @@
1
1
  process.noDeprecation = true; import { createRequire as __createRequire } from "module"; const require = __createRequire(import.meta.url);
2
- import{f as Ut,g as Gt,j as Wt,m as Et,n as Dt,o as Ft,p as Kt}from"./chunk-GEKUY6YQ.js";var i=class extends Error{constructor(r,u,n){super(r);this.status=u;this.toolName=n;this.name="MoonPayError"}},o=class extends i{constructor(t="Authentication required"){super(t,401),this.name="AuthError"}},c=class extends i{constructor(t="Rate limit exceeded"){super(t,429),this.name="RateLimitError"}},a=class extends i{constructor(t,r){super(t,400,r),this.name="ValidationError"}},l=class extends i{constructor(t){super(`Tool not found: ${t}`,404,t),this.name="ToolNotFoundError"}},s=class extends i{constructor(t,r){super(`Tool "${t}" has been renamed to "${r}"`,410,t),this.name="ToolRenamedError",this.newName=r}};var jt="https://agents.moonpay.com",Jt=36e4;function zt(e){return!!e&&typeof e=="object"}function d(e){if(typeof e=="string")return e.length>0&&e!=="[object Object]"?e:void 0;if(typeof e=="number"||typeof e=="boolean")return String(e);if(!zt(e))return;let t=d(e.error)??d(e.message)??d(e.errorMessage);if(t)return t;try{return JSON.stringify(e)}catch{return}}function Qt(e,t){if(!zt(e))return;let r=e[t];return typeof r=="string"?r:void 0}var h=class{constructor(t={}){this.baseUrl=(t.baseUrl??jt).replace(/\/$/,""),this.auth=t.auth??{type:"none"},this.timeout=t.timeout??Jt,this.headers=t.headers??{}}async _call(t,r){let u=`${this.baseUrl}/api/tools/${encodeURIComponent(t)}`,n=await this.buildHeaders(),_=await fetch(u,{method:"POST",headers:n,body:JSON.stringify(r),signal:AbortSignal.timeout(this.timeout)});if(_.status===401&&this.auth.type==="bearer"&&this.auth.refreshToken)try{let $t=await this.auth.refreshToken();n.Authorization=`Bearer ${$t}`,_=await fetch(u,{method:"POST",headers:n,body:JSON.stringify(r),signal:AbortSignal.timeout(this.timeout)})}catch{throw new o("Token refresh failed")}return this.handleResponse(_,t)}async buildHeaders(){let t={"Content-Type":"application/json",...this.headers};if(this.auth.type==="bearer"){let r=await this.auth.getToken();r&&(t.Authorization=`Bearer ${r}`)}return t}async handleResponse(t,r){if(t.ok)return t.json();let u;try{u=await t.json()}catch{u={error:t.statusText}}let n=d(u)??`Request failed with status ${t.status}`;switch(t.status){case 400:throw new a(n,r);case 401:throw new o(n);case 404:throw new l(r);case 410:throw new s(r,Qt(u,"newName")??"unknown");case 429:throw new c(n);default:throw new i(n,t.status,r)}}};var O=class{constructor(t){this.client=t}create(t){return this.client._call("app_activation_create",t)}},P=class{constructor(t){this.client=t}get activation(){return new O(this.client)}},v=class{constructor(t){this.client=t}build(t){return this.client._call("card_delegation_approve_transaction_build",t)}},C=class{constructor(t){this.client=t}get transaction(){return new v(this.client)}},y=class{constructor(t){this.client=t}build(t){return this.client._call("card_delegation_revoke_transaction_build",t)}},I=class{constructor(t){this.client=t}get transaction(){return new y(this.client)}},g=class{constructor(t){this.client=t}retrieve(t){return this.client._call("card_delegation_token_retrieve",t)}},k=class{constructor(t){this.client=t}get approve(){return new C(this.client)}get revoke(){return new I(this.client)}get token(){return new g(this.client)}},w=class{constructor(t){this.client=t}check(t){return this.client._call("card_onboarding_check",t)}finish(t){return this.client._call("card_onboarding_finish",t)}start(t){return this.client._call("card_onboarding_start",t)}},A=class{constructor(t){this.client=t}list(t){return this.client._call("card_transaction_list",t)}},f=class{constructor(t){this.client=t}retrieve(t){return this.client._call("card_user_retrieve",t)}},R=class{constructor(t){this.client=t}check(t){return this.client._call("card_wallet_check",t)}link(t){return this.client._call("card_wallet_link",t)}list(t){return this.client._call("card_wallet_list",t)}unlink(t){return this.client._call("card_wallet_unlink",t)}},L=class{constructor(t){this.client=t}get delegation(){return new k(this.client)}get onboarding(){return new w(this.client)}get transaction(){return new A(this.client)}get user(){return new f(this.client)}get wallet(){return new R(this.client)}create(t){return this.client._call("card_create",t)}freeze(t){return this.client._call("card_freeze",t)}retrieve(t){return this.client._call("card_retrieve",t)}reveal(t){return this.client._call("card_reveal",t)}unfreeze(t){return this.client._call("card_unfreeze",t)}},M=class{constructor(t){this.client=t}list(t){return this.client._call("chain_list",t)}retrieve(t){return this.client._call("chain_retrieve",t)}},T=class{constructor(t){this.client=t}create(t){return this.client._call("cli_activation_create",t)}update(t){return this.client._call("cli_activation_update",t)}},x=class{constructor(t){this.client=t}get activation(){return new T(this.client)}},V=class{constructor(t){this.client=t}add(t){return this.client._call("commerce_cart_add",t)}remove(t){return this.client._call("commerce_cart_remove",t)}retrieve(t){return this.client._call("commerce_cart_retrieve",t)}update(t){return this.client._call("commerce_cart_update",t)}},b=class{constructor(t){this.client=t}pay(t){return this.client._call("commerce_checkout_pay",t)}start(t){return this.client._call("commerce_checkout_start",t)}},S=class{constructor(t){this.client=t}retrieve(t){return this.client._call("commerce_product_retrieve",t)}search(t){return this.client._call("commerce_product_search",t)}},q=class{constructor(t){this.client=t}list(t){return this.client._call("commerce_store_list",t)}retrieve(t){return this.client._call("commerce_store_retrieve",t)}},B=class{constructor(t){this.client=t}get cart(){return new V(this.client)}get checkout(){return new b(this.client)}get product(){return new S(this.client)}get store(){return new q(this.client)}search(t){return this.client._call("commerce_search",t)}},H=class{constructor(t){this.client=t}list(t){return this.client._call("deposit_transaction_list",t)}},U=class{constructor(t){this.client=t}get transaction(){return new H(this.client)}create(t){return this.client._call("deposit_create",t)}retrieve(t){return this.client._call("deposit_retrieve",t)}},W=class{constructor(t){this.client=t}create(t){return this.client._call("feedback_create",t)}},E=class{constructor(t){this.client=t}buy(t){return this.client._call("gateway_buy",t)}search(t){return this.client._call("gateway_search",t)}},D=class{constructor(t){this.client=t}retrieve(t){return this.client._call("hyperliquid_balance_retrieve",t)}},F=class{constructor(t){this.client=t}list(t){return this.client._call("hyperliquid_candle_list",t)}},z=class{constructor(t){this.client=t}create(t){return this.client._call("hyperliquid_deposit_create",t)}},$=class{constructor(t){this.client=t}submit(t){return this.client._call("hyperliquid_exchange_submit",t)}},G=class{constructor(t){this.client=t}list(t){return this.client._call("hyperliquid_funding_payment_list",t)}},K=class{constructor(t){this.client=t}get payment(){return new G(this.client)}},j=class{constructor(t){this.client=t}list(t){return this.client._call("hyperliquid_market_list",t)}},J=class{constructor(t){this.client=t}create(t){return this.client._call("hyperliquid_order_create",t)}list(t){return this.client._call("hyperliquid_order_list",t)}},Q=class{constructor(t){this.client=t}retrieve(t){return this.client._call("hyperliquid_orderbook_retrieve",t)}},X=class{constructor(t){this.client=t}list(t){return this.client._call("hyperliquid_position_list",t)}},Y=class{constructor(t){this.client=t}list(t){return this.client._call("hyperliquid_predicted_funding_list",t)}},Z=class{constructor(t){this.client=t}get funding(){return new Y(this.client)}},N=class{constructor(t){this.client=t}list(t){return this.client._call("hyperliquid_price_list",t)}},tt=class{constructor(t){this.client=t}list(t){return this.client._call("hyperliquid_trade_list",t)}},et=class{constructor(t){this.client=t}create(t){return this.client._call("hyperliquid_withdraw_create",t)}},rt=class{constructor(t){this.client=t}get balance(){return new D(this.client)}get candle(){return new F(this.client)}get deposit(){return new z(this.client)}get exchange(){return new $(this.client)}get funding(){return new K(this.client)}get market(){return new j(this.client)}get order(){return new J(this.client)}get orderbook(){return new Q(this.client)}get position(){return new X(this.client)}get predicted(){return new Z(this.client)}get price(){return new N(this.client)}get trade(){return new tt(this.client)}get withdraw(){return new et(this.client)}},it=class{constructor(t){this.client=t}prepare(t){return this.client._call("polymarket_balance_withdraw_prepare",t)}submit(t){return this.client._call("polymarket_balance_withdraw_submit",t)}},nt=class{constructor(t){this.client=t}get withdraw(){return new it(this.client)}},ut=class{constructor(t){this.client=t}redeem(t){return this.client._call("polymarket_position_redeem",t)}sell(t){return this.client._call("polymarket_position_sell",t)}},ot=class{constructor(t){this.client=t}get balance(){return new nt(this.client)}get position(){return new ut(this.client)}},ct=class{constructor(t){this.client=t}list(t){return this.client._call("prediction-market_event_list",t)}retrieve(t){return this.client._call("prediction-market_event_retrieve",t)}search(t){return this.client._call("prediction-market_event_search",t)}},at=class{constructor(t){this.client=t}list(t){return this.client._call("prediction-market_market_ohlcv_list",t)}},lt=class{constructor(t){this.client=t}get ohlcv(){return new at(this.client)}},st=class{constructor(t){this.client=t}retrieve(t){return this.client._call("prediction-market_order_retrieve",t)}},pt=class{constructor(t){this.client=t}buy(t){return this.client._call("prediction-market_position_buy",t)}list(t){return this.client._call("prediction-market_position_list",t)}redeem(t){return this.client._call("prediction-market_position_redeem",t)}sell(t){return this.client._call("prediction-market_position_sell",t)}},dt=class{constructor(t){this.client=t}get event(){return new ct(this.client)}get market(){return new lt(this.client)}get order(){return new st(this.client)}get position(){return new pt(this.client)}},ht=class{constructor(t){this.client=t}check(t){return this.client._call("solana_balance_check",t)}},mt=class{constructor(t){this.client=t}get balance(){return new ht(this.client)}},_t=class{constructor(t){this.client=t}retrieve(t){return this.client._call("swaps_quote_retrieve",t)}},Ot=class{constructor(t){this.client=t}build(t){return this.client._call("swaps_transaction_build",t)}},Pt=class{constructor(t){this.client=t}get quote(){return new _t(this.client)}get transaction(){return new Ot(this.client)}},vt=class{constructor(t){this.client=t}list(t){return this.client._call("token_activity_list",t)}},Ct=class{constructor(t){this.client=t}list(t){return this.client._call("token_balance_list",t)}},yt=class{constructor(t){this.client=t}list(t){return this.client._call("token_holder_list",t)}},It=class{constructor(t){this.client=t}list(t){return this.client._call("token_ohlcv_list",t)}},gt=class{constructor(t){this.client=t}list(t){return this.client._call("token_trending_list",t)}},kt=class{constructor(t){this.client=t}get activity(){return new vt(this.client)}get balance(){return new Ct(this.client)}get holder(){return new yt(this.client)}get ohlcv(){return new It(this.client)}get trending(){return new gt(this.client)}check(t){return this.client._call("token_check",t)}list(t){return this.client._call("token_list",t)}retrieve(t){return this.client._call("token_retrieve",t)}search(t){return this.client._call("token_search",t)}},wt=class{constructor(t){this.client=t}list(t){return this.client._call("transaction_list",t)}prepare(t){return this.client._call("transaction_prepare",t)}register(t){return this.client._call("transaction_register",t)}retrieve(t){return this.client._call("transaction_retrieve",t)}send(t){return this.client._call("transaction_send",t)}},At=class{constructor(t){this.client=t}retrieve(t){return this.client._call("user_retrieve",t)}},ft=class{constructor(t){this.client=t}accept(t){return this.client._call("virtual-account_agreement_accept",t)}list(t){return this.client._call("virtual-account_agreement_list",t)}},Rt=class{constructor(t){this.client=t}delete(t){return this.client._call("virtual-account_bank-account_delete",t)}list(t){return this.client._call("virtual-account_bank-account_list",t)}register(t){return this.client._call("virtual-account_bank-account_register",t)}retrieve(t){return this.client._call("virtual-account_bank-account_retrieve",t)}},Lt=class{constructor(t){this.client=t}continue(t){return this.client._call("virtual-account_kyc_continue",t)}restart(t){return this.client._call("virtual-account_kyc_restart",t)}},Mt=class{constructor(t){this.client=t}cancel(t){return this.client._call("virtual-account_offramp_cancel",t)}create(t){return this.client._call("virtual-account_offramp_create",t)}initiate(t){return this.client._call("virtual-account_offramp_initiate",t)}list(t){return this.client._call("virtual-account_offramp_list",t)}retrieve(t){return this.client._call("virtual-account_offramp_retrieve",t)}update(t){return this.client._call("virtual-account_offramp_update",t)}},Tt=class{constructor(t){this.client=t}create(t){return this.client._call("virtual-account_onramp_payment_create",t)}retrieve(t){return this.client._call("virtual-account_onramp_payment_retrieve",t)}},xt=class{constructor(t){this.client=t}get payment(){return new Tt(this.client)}cancel(t){return this.client._call("virtual-account_onramp_cancel",t)}create(t){return this.client._call("virtual-account_onramp_create",t)}list(t){return this.client._call("virtual-account_onramp_list",t)}retrieve(t){return this.client._call("virtual-account_onramp_retrieve",t)}update(t){return this.client._call("virtual-account_onramp_update",t)}},Vt=class{constructor(t){this.client=t}list(t){return this.client._call("virtual-account_transaction_list",t)}},bt=class{constructor(t){this.client=t}list(t){return this.client._call("virtual-account_wallet_list",t)}register(t){return this.client._call("virtual-account_wallet_register",t)}},St=class{constructor(t){this.client=t}get agreement(){return new ft(this.client)}get bankAccount(){return new Rt(this.client)}get kyc(){return new Lt(this.client)}get offramp(){return new Mt(this.client)}get onramp(){return new xt(this.client)}get transaction(){return new Vt(this.client)}get wallet(){return new bt(this.client)}create(t){return this.client._call("virtual-account_create",t)}retrieve(t){return this.client._call("virtual-account_retrieve",t)}},qt=class{constructor(t){this.client=t}list(t){return this.client._call("wallet_activity_list",t)}},Bt=class{constructor(t){this.client=t}retrieve(t){return this.client._call("wallet_pnl_retrieve",t)}},Ht=class{constructor(t){this.client=t}get activity(){return new qt(this.client)}get pnl(){return new Bt(this.client)}discover(t){return this.client._call("wallet_discover",t)}},p=class extends h{constructor(t={}){super(t)}get app(){return new P(this)}get card(){return new L(this)}get chain(){return new M(this)}get cli(){return new x(this)}get commerce(){return new B(this)}get deposit(){return new U(this)}get feedback(){return new W(this)}get gateway(){return new E(this)}get hyperliquid(){return new rt(this)}get polymarket(){return new ot(this)}get predictionMarket(){return new dt(this)}get solana(){return new mt(this)}get swaps(){return new Pt(this)}get token(){return new kt(this)}get transaction(){return new wt(this)}get user(){return new At(this)}get virtualAccount(){return new St(this)}get wallet(){return new Ht(this)}buy(t){return this._call("buy",t)}login(t){return this._call("login",t)}refresh(t){return this._call("refresh",t)}verify(t){return this._call("verify",t)}};Kt();Gt();var m=null;function Xt(){return m||(m=new p({baseUrl:Et(),auth:{type:"bearer",getToken:Ft,refreshToken:async()=>{let e=Wt();if(!e?.refreshToken)throw new Error("No refresh token available");return(await Dt(e)).accessToken}},headers:Ut()})),m}var le=new Proxy({},{get(e,t){return Reflect.get(Xt(),t)}});function se(){m=null}export{p as a,le as b,se as c};
2
+ import{f as Ut,g as Gt,j as Wt,m as Et,n as Dt,o as Ft,p as Kt}from"./chunk-QDAWFEIX.js";var i=class extends Error{constructor(r,u,n){super(r);this.status=u;this.toolName=n;this.name="MoonPayError"}},o=class extends i{constructor(t="Authentication required"){super(t,401),this.name="AuthError"}},c=class extends i{constructor(t="Rate limit exceeded"){super(t,429),this.name="RateLimitError"}},a=class extends i{constructor(t,r){super(t,400,r),this.name="ValidationError"}},l=class extends i{constructor(t){super(`Tool not found: ${t}`,404,t),this.name="ToolNotFoundError"}},s=class extends i{constructor(t,r){super(`Tool "${t}" has been renamed to "${r}"`,410,t),this.name="ToolRenamedError",this.newName=r}};var jt="https://agents.moonpay.com",Jt=36e4;function zt(e){return!!e&&typeof e=="object"}function d(e){if(typeof e=="string")return e.length>0&&e!=="[object Object]"?e:void 0;if(typeof e=="number"||typeof e=="boolean")return String(e);if(!zt(e))return;let t=d(e.error)??d(e.message)??d(e.errorMessage);if(t)return t;try{return JSON.stringify(e)}catch{return}}function Qt(e,t){if(!zt(e))return;let r=e[t];return typeof r=="string"?r:void 0}var h=class{constructor(t={}){this.baseUrl=(t.baseUrl??jt).replace(/\/$/,""),this.auth=t.auth??{type:"none"},this.timeout=t.timeout??Jt,this.headers=t.headers??{}}async _call(t,r){let u=`${this.baseUrl}/api/tools/${encodeURIComponent(t)}`,n=await this.buildHeaders(),_=await fetch(u,{method:"POST",headers:n,body:JSON.stringify(r),signal:AbortSignal.timeout(this.timeout)});if(_.status===401&&this.auth.type==="bearer"&&this.auth.refreshToken)try{let $t=await this.auth.refreshToken();n.Authorization=`Bearer ${$t}`,_=await fetch(u,{method:"POST",headers:n,body:JSON.stringify(r),signal:AbortSignal.timeout(this.timeout)})}catch{throw new o("Token refresh failed")}return this.handleResponse(_,t)}async buildHeaders(){let t={"Content-Type":"application/json",...this.headers};if(this.auth.type==="bearer"){let r=await this.auth.getToken();r&&(t.Authorization=`Bearer ${r}`)}return t}async handleResponse(t,r){if(t.ok)return t.json();let u;try{u=await t.json()}catch{u={error:t.statusText}}let n=d(u)??`Request failed with status ${t.status}`;switch(t.status){case 400:throw new a(n,r);case 401:throw new o(n);case 404:throw new l(r);case 410:throw new s(r,Qt(u,"newName")??"unknown");case 429:throw new c(n);default:throw new i(n,t.status,r)}}};var O=class{constructor(t){this.client=t}create(t){return this.client._call("app_activation_create",t)}},P=class{constructor(t){this.client=t}get activation(){return new O(this.client)}},v=class{constructor(t){this.client=t}build(t){return this.client._call("card_delegation_approve_transaction_build",t)}},C=class{constructor(t){this.client=t}get transaction(){return new v(this.client)}},y=class{constructor(t){this.client=t}build(t){return this.client._call("card_delegation_revoke_transaction_build",t)}},I=class{constructor(t){this.client=t}get transaction(){return new y(this.client)}},g=class{constructor(t){this.client=t}retrieve(t){return this.client._call("card_delegation_token_retrieve",t)}},k=class{constructor(t){this.client=t}get approve(){return new C(this.client)}get revoke(){return new I(this.client)}get token(){return new g(this.client)}},w=class{constructor(t){this.client=t}check(t){return this.client._call("card_onboarding_check",t)}finish(t){return this.client._call("card_onboarding_finish",t)}start(t){return this.client._call("card_onboarding_start",t)}},A=class{constructor(t){this.client=t}list(t){return this.client._call("card_transaction_list",t)}},f=class{constructor(t){this.client=t}retrieve(t){return this.client._call("card_user_retrieve",t)}},R=class{constructor(t){this.client=t}check(t){return this.client._call("card_wallet_check",t)}link(t){return this.client._call("card_wallet_link",t)}list(t){return this.client._call("card_wallet_list",t)}unlink(t){return this.client._call("card_wallet_unlink",t)}},L=class{constructor(t){this.client=t}get delegation(){return new k(this.client)}get onboarding(){return new w(this.client)}get transaction(){return new A(this.client)}get user(){return new f(this.client)}get wallet(){return new R(this.client)}create(t){return this.client._call("card_create",t)}freeze(t){return this.client._call("card_freeze",t)}retrieve(t){return this.client._call("card_retrieve",t)}reveal(t){return this.client._call("card_reveal",t)}unfreeze(t){return this.client._call("card_unfreeze",t)}},M=class{constructor(t){this.client=t}list(t){return this.client._call("chain_list",t)}retrieve(t){return this.client._call("chain_retrieve",t)}},T=class{constructor(t){this.client=t}create(t){return this.client._call("cli_activation_create",t)}update(t){return this.client._call("cli_activation_update",t)}},x=class{constructor(t){this.client=t}get activation(){return new T(this.client)}},V=class{constructor(t){this.client=t}add(t){return this.client._call("commerce_cart_add",t)}remove(t){return this.client._call("commerce_cart_remove",t)}retrieve(t){return this.client._call("commerce_cart_retrieve",t)}update(t){return this.client._call("commerce_cart_update",t)}},b=class{constructor(t){this.client=t}pay(t){return this.client._call("commerce_checkout_pay",t)}start(t){return this.client._call("commerce_checkout_start",t)}},S=class{constructor(t){this.client=t}retrieve(t){return this.client._call("commerce_product_retrieve",t)}search(t){return this.client._call("commerce_product_search",t)}},q=class{constructor(t){this.client=t}list(t){return this.client._call("commerce_store_list",t)}retrieve(t){return this.client._call("commerce_store_retrieve",t)}},B=class{constructor(t){this.client=t}get cart(){return new V(this.client)}get checkout(){return new b(this.client)}get product(){return new S(this.client)}get store(){return new q(this.client)}search(t){return this.client._call("commerce_search",t)}},H=class{constructor(t){this.client=t}list(t){return this.client._call("deposit_transaction_list",t)}},U=class{constructor(t){this.client=t}get transaction(){return new H(this.client)}create(t){return this.client._call("deposit_create",t)}retrieve(t){return this.client._call("deposit_retrieve",t)}},W=class{constructor(t){this.client=t}create(t){return this.client._call("feedback_create",t)}},E=class{constructor(t){this.client=t}buy(t){return this.client._call("gateway_buy",t)}search(t){return this.client._call("gateway_search",t)}},D=class{constructor(t){this.client=t}retrieve(t){return this.client._call("hyperliquid_balance_retrieve",t)}},F=class{constructor(t){this.client=t}list(t){return this.client._call("hyperliquid_candle_list",t)}},z=class{constructor(t){this.client=t}create(t){return this.client._call("hyperliquid_deposit_create",t)}},$=class{constructor(t){this.client=t}submit(t){return this.client._call("hyperliquid_exchange_submit",t)}},G=class{constructor(t){this.client=t}list(t){return this.client._call("hyperliquid_funding_payment_list",t)}},K=class{constructor(t){this.client=t}get payment(){return new G(this.client)}},j=class{constructor(t){this.client=t}list(t){return this.client._call("hyperliquid_market_list",t)}},J=class{constructor(t){this.client=t}create(t){return this.client._call("hyperliquid_order_create",t)}list(t){return this.client._call("hyperliquid_order_list",t)}},Q=class{constructor(t){this.client=t}retrieve(t){return this.client._call("hyperliquid_orderbook_retrieve",t)}},X=class{constructor(t){this.client=t}list(t){return this.client._call("hyperliquid_position_list",t)}},Y=class{constructor(t){this.client=t}list(t){return this.client._call("hyperliquid_predicted_funding_list",t)}},Z=class{constructor(t){this.client=t}get funding(){return new Y(this.client)}},N=class{constructor(t){this.client=t}list(t){return this.client._call("hyperliquid_price_list",t)}},tt=class{constructor(t){this.client=t}list(t){return this.client._call("hyperliquid_trade_list",t)}},et=class{constructor(t){this.client=t}create(t){return this.client._call("hyperliquid_withdraw_create",t)}},rt=class{constructor(t){this.client=t}get balance(){return new D(this.client)}get candle(){return new F(this.client)}get deposit(){return new z(this.client)}get exchange(){return new $(this.client)}get funding(){return new K(this.client)}get market(){return new j(this.client)}get order(){return new J(this.client)}get orderbook(){return new Q(this.client)}get position(){return new X(this.client)}get predicted(){return new Z(this.client)}get price(){return new N(this.client)}get trade(){return new tt(this.client)}get withdraw(){return new et(this.client)}},it=class{constructor(t){this.client=t}prepare(t){return this.client._call("polymarket_balance_withdraw_prepare",t)}submit(t){return this.client._call("polymarket_balance_withdraw_submit",t)}},nt=class{constructor(t){this.client=t}get withdraw(){return new it(this.client)}},ut=class{constructor(t){this.client=t}redeem(t){return this.client._call("polymarket_position_redeem",t)}sell(t){return this.client._call("polymarket_position_sell",t)}},ot=class{constructor(t){this.client=t}get balance(){return new nt(this.client)}get position(){return new ut(this.client)}},ct=class{constructor(t){this.client=t}list(t){return this.client._call("prediction-market_event_list",t)}retrieve(t){return this.client._call("prediction-market_event_retrieve",t)}search(t){return this.client._call("prediction-market_event_search",t)}},at=class{constructor(t){this.client=t}list(t){return this.client._call("prediction-market_market_ohlcv_list",t)}},lt=class{constructor(t){this.client=t}get ohlcv(){return new at(this.client)}},st=class{constructor(t){this.client=t}retrieve(t){return this.client._call("prediction-market_order_retrieve",t)}},pt=class{constructor(t){this.client=t}buy(t){return this.client._call("prediction-market_position_buy",t)}list(t){return this.client._call("prediction-market_position_list",t)}redeem(t){return this.client._call("prediction-market_position_redeem",t)}sell(t){return this.client._call("prediction-market_position_sell",t)}},dt=class{constructor(t){this.client=t}get event(){return new ct(this.client)}get market(){return new lt(this.client)}get order(){return new st(this.client)}get position(){return new pt(this.client)}},ht=class{constructor(t){this.client=t}check(t){return this.client._call("solana_balance_check",t)}},mt=class{constructor(t){this.client=t}get balance(){return new ht(this.client)}},_t=class{constructor(t){this.client=t}retrieve(t){return this.client._call("swaps_quote_retrieve",t)}},Ot=class{constructor(t){this.client=t}build(t){return this.client._call("swaps_transaction_build",t)}},Pt=class{constructor(t){this.client=t}get quote(){return new _t(this.client)}get transaction(){return new Ot(this.client)}},vt=class{constructor(t){this.client=t}list(t){return this.client._call("token_activity_list",t)}},Ct=class{constructor(t){this.client=t}list(t){return this.client._call("token_balance_list",t)}},yt=class{constructor(t){this.client=t}list(t){return this.client._call("token_holder_list",t)}},It=class{constructor(t){this.client=t}list(t){return this.client._call("token_ohlcv_list",t)}},gt=class{constructor(t){this.client=t}list(t){return this.client._call("token_trending_list",t)}},kt=class{constructor(t){this.client=t}get activity(){return new vt(this.client)}get balance(){return new Ct(this.client)}get holder(){return new yt(this.client)}get ohlcv(){return new It(this.client)}get trending(){return new gt(this.client)}check(t){return this.client._call("token_check",t)}list(t){return this.client._call("token_list",t)}retrieve(t){return this.client._call("token_retrieve",t)}search(t){return this.client._call("token_search",t)}},wt=class{constructor(t){this.client=t}list(t){return this.client._call("transaction_list",t)}prepare(t){return this.client._call("transaction_prepare",t)}register(t){return this.client._call("transaction_register",t)}retrieve(t){return this.client._call("transaction_retrieve",t)}send(t){return this.client._call("transaction_send",t)}},At=class{constructor(t){this.client=t}retrieve(t){return this.client._call("user_retrieve",t)}},ft=class{constructor(t){this.client=t}accept(t){return this.client._call("virtual-account_agreement_accept",t)}list(t){return this.client._call("virtual-account_agreement_list",t)}},Rt=class{constructor(t){this.client=t}delete(t){return this.client._call("virtual-account_bank-account_delete",t)}list(t){return this.client._call("virtual-account_bank-account_list",t)}register(t){return this.client._call("virtual-account_bank-account_register",t)}retrieve(t){return this.client._call("virtual-account_bank-account_retrieve",t)}},Lt=class{constructor(t){this.client=t}continue(t){return this.client._call("virtual-account_kyc_continue",t)}restart(t){return this.client._call("virtual-account_kyc_restart",t)}},Mt=class{constructor(t){this.client=t}cancel(t){return this.client._call("virtual-account_offramp_cancel",t)}create(t){return this.client._call("virtual-account_offramp_create",t)}initiate(t){return this.client._call("virtual-account_offramp_initiate",t)}list(t){return this.client._call("virtual-account_offramp_list",t)}retrieve(t){return this.client._call("virtual-account_offramp_retrieve",t)}update(t){return this.client._call("virtual-account_offramp_update",t)}},Tt=class{constructor(t){this.client=t}create(t){return this.client._call("virtual-account_onramp_payment_create",t)}retrieve(t){return this.client._call("virtual-account_onramp_payment_retrieve",t)}},xt=class{constructor(t){this.client=t}get payment(){return new Tt(this.client)}cancel(t){return this.client._call("virtual-account_onramp_cancel",t)}create(t){return this.client._call("virtual-account_onramp_create",t)}list(t){return this.client._call("virtual-account_onramp_list",t)}retrieve(t){return this.client._call("virtual-account_onramp_retrieve",t)}update(t){return this.client._call("virtual-account_onramp_update",t)}},Vt=class{constructor(t){this.client=t}list(t){return this.client._call("virtual-account_transaction_list",t)}},bt=class{constructor(t){this.client=t}list(t){return this.client._call("virtual-account_wallet_list",t)}register(t){return this.client._call("virtual-account_wallet_register",t)}},St=class{constructor(t){this.client=t}get agreement(){return new ft(this.client)}get bankAccount(){return new Rt(this.client)}get kyc(){return new Lt(this.client)}get offramp(){return new Mt(this.client)}get onramp(){return new xt(this.client)}get transaction(){return new Vt(this.client)}get wallet(){return new bt(this.client)}create(t){return this.client._call("virtual-account_create",t)}retrieve(t){return this.client._call("virtual-account_retrieve",t)}},qt=class{constructor(t){this.client=t}list(t){return this.client._call("wallet_activity_list",t)}},Bt=class{constructor(t){this.client=t}retrieve(t){return this.client._call("wallet_pnl_retrieve",t)}},Ht=class{constructor(t){this.client=t}get activity(){return new qt(this.client)}get pnl(){return new Bt(this.client)}discover(t){return this.client._call("wallet_discover",t)}},p=class extends h{constructor(t={}){super(t)}get app(){return new P(this)}get card(){return new L(this)}get chain(){return new M(this)}get cli(){return new x(this)}get commerce(){return new B(this)}get deposit(){return new U(this)}get feedback(){return new W(this)}get gateway(){return new E(this)}get hyperliquid(){return new rt(this)}get polymarket(){return new ot(this)}get predictionMarket(){return new dt(this)}get solana(){return new mt(this)}get swaps(){return new Pt(this)}get token(){return new kt(this)}get transaction(){return new wt(this)}get user(){return new At(this)}get virtualAccount(){return new St(this)}get wallet(){return new Ht(this)}buy(t){return this._call("buy",t)}login(t){return this._call("login",t)}refresh(t){return this._call("refresh",t)}verify(t){return this._call("verify",t)}};Kt();Gt();var m=null;function Xt(){return m||(m=new p({baseUrl:Et(),auth:{type:"bearer",getToken:Ft,refreshToken:async()=>{let e=Wt();if(!e?.refreshToken)throw new Error("No refresh token available");return(await Dt(e)).accessToken}},headers:Ut()})),m}var le=new Proxy({},{get(e,t){return Reflect.get(Xt(),t)}});function se(){m=null}export{p as a,le as b,se as c};
@@ -1,4 +1,4 @@
1
1
  process.noDeprecation = true; import { createRequire as __createRequire } from "module"; const require = __createRequire(import.meta.url);
2
- import{a as G,b as T,c as L,d as Z,h as D,p as Q}from"./chunk-GEKUY6YQ.js";import{a as V,f as I}from"./chunk-LMDE72OE.js";import{existsSync as H,readFileSync as J,writeFileSync as ge,renameSync as Y}from"fs";import{join as S}from"path";import{homedir as we}from"os";import{randomBytes as ve}from"crypto";import*as i from"@open-wallet-standard/core";import q from"bs58";T();import{z as s}from"zod";var M={"eip155:1":"ethereum","solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp":"solana","bip122:000000000019d6689c085ae165831e93":"bitcoin","tron:mainnet":"tron","ton:mainnet":"ton","fil:mainnet":"filecoin"};function R(e){return e==="evm"?"ethereum":e}var E=s.object({solana:s.string().optional(),ethereum:s.string().optional(),bitcoin:s.string().optional(),tron:s.string().optional(),ton:s.string().optional(),filecoin:s.string().optional()}),X=["base","arbitrum","robinhood","polygon","optimism","bnb","bnb-testnet","avalanche","tempo","tempo-moderato","ethereum-sepolia","base-sepolia","arbitrum-sepolia","polygon-amoy"];function Te(e){let t={};if(e.solana&&(t.solana=e.solana,t["solana-devnet"]=e.solana),e.ethereum){t.ethereum=e.ethereum;for(let r of X)t[r]=e.ethereum}return e.bitcoin&&(t.bitcoin=e.bitcoin),e.tron&&(t.tron=e.tron),e.ton&&(t.ton=e.ton),e.filecoin&&(t.filecoin=e.filecoin),t}var ee=s.object({name:s.string(),type:s.literal("hd"),mnemonic:s.string().optional(),addresses:E,createdAt:s.string()}),te=s.object({name:s.string(),type:s.literal("imported"),chain:s.string().optional(),privateKey:s.string().optional(),addresses:E,createdAt:s.string()}),U=s.enum(["ledger"]),$=s.object({name:s.string(),type:s.literal("hardware"),device:U,addresses:E,createdAt:s.string()}),De=s.discriminatedUnion("type",[ee,te,$]),Me=s.object({name:s.string(),type:s.enum(["hd","imported","hardware"]),device:U.optional(),addresses:s.record(s.string(),s.string()),createdAt:s.string()});import{createHash as _}from"crypto";import{HDKey as x}from"@scure/bip32";import{mnemonicToSeedSync as y}from"@scure/bip39";import{keccak_256 as B}from"@noble/hashes/sha3";import{derivePath as j}from"ed25519-hd-key";import*as O from"bitcoinjs-lib";import re from"ecpair";import*as K from"@bitcoinerlab/secp256k1";import{Keypair as ne}from"@solana/web3.js";import oe from"bs58";import{WalletContractV5R1 as ie}from"@ton/ton";import{keyPairFromSeed as se}from"@ton/crypto";import*as z from"@open-wallet-standard/core";var ae=re(K);function N(e,t,r=0){switch(t){case"solana":return le(e,r);case"ethereum":return ce(e,r);case"bitcoin":return pe(e,r);case"tron":return ue(e,r);case"ton":return ye(e,r);case"filecoin":return he(e,r);default:throw new Error(`Unsupported key family for derivation: ${t}`)}}function le(e,t){let r=y(e),n=`m/44'/501'/${t}'/0'`,{key:o}=j(n,Buffer.from(r).toString("hex")),a=ne.fromSeed(Uint8Array.from(o));return{privateKey:a.secretKey,address:a.publicKey.toBase58()}}function ce(e,t){let r=y(e),n=x.fromMasterSeed(r),o=`m/44'/60'/${t}'/0/0`,a=n.derive(o);if(!a.privateKey)throw new Error("Failed to derive EVM private key");let l=de(a.publicKey);return{privateKey:a.privateKey,address:l}}function de(e){let t=K.pointCompress(e,!1),n=B(t.slice(1)).slice(-20),o="0x"+Buffer.from(n).toString("hex");return fe(o)}function fe(e){let t=e.toLowerCase().replace("0x",""),r=Buffer.from(B(Buffer.from(t,"utf8"))).toString("hex"),n="0x";for(let o=0;o<t.length;o++)n+=parseInt(r[o],16)>=8?t[o].toUpperCase():t[o];return n}function pe(e,t){let r=y(e),n=x.fromMasterSeed(r),o=`m/84'/0'/${t}'/0/0`,a=n.derive(o);if(!a.privateKey)throw new Error("Failed to derive Bitcoin private key");let l=ae.fromPrivateKey(Buffer.from(a.privateKey)),{address:f}=O.payments.p2wpkh({pubkey:Buffer.from(l.publicKey)});if(!f)throw new Error("Failed to derive Bitcoin address");return{privateKey:a.privateKey,address:f}}function ue(e,t){let r=y(e),n=x.fromMasterSeed(r),o=`m/44'/195'/${t}'/0/0`,a=n.derive(o);if(!a.privateKey)throw new Error("Failed to derive Tron private key");let l=me(a.publicKey);return{privateKey:a.privateKey,address:l}}function me(e){let t=K.pointCompress(e,!1),n=B(t.slice(1)).slice(-20),o=Buffer.concat([Buffer.from([65]),Buffer.from(n)]),a=_("sha256").update(o).digest(),l=_("sha256").update(a).digest(),f=Buffer.concat([o,l.slice(0,4)]);return oe.encode(f)}function ye(e,t){let r=y(e),n=`m/44'/607'/${t}'/0'`,{key:o}=j(n,Buffer.from(r).toString("hex")),a=se(Buffer.from(o)),l=ie.create({publicKey:Buffer.from(a.publicKey)});return{privateKey:a.secretKey,address:l.address.toString({bounceable:!1})}}function he(e,t){let r=y(e),n=x.fromMasterSeed(r),o=`m/44'/461'/${t}'/0/0`,a=n.derive(o);if(!a.privateKey)throw new Error("Failed to derive Filecoin private key");let l=z.deriveAddress(e,"filecoin",t);return{privateKey:a.privateKey,address:l}}Q();var b=S(we(),".config","moonpay"),C=S(b,"hardware-wallets.json");function c(){return b}function We(e){let t={};for(let r of e){let n=M[r.chainId];n&&(t[n]=r.address)}return t}function h(e){let t=We(e.accounts);if(!t.filecoin)try{let r=i.exportWallet(e.id,null,c());r&&!r.startsWith("{")&&(t.filecoin=i.deriveAddress(r,"filecoin"))}catch{}return{name:e.name,type:"hd",addresses:t,createdAt:e.createdAt}}function m(){if(!H(C))return[];try{return(JSON.parse(J(C,"utf-8")).wallets??[]).map(t=>$.parse(t))}catch{return[]}}function xe(e,t){D();let r=S(b,`.tmp.${ve(4).toString("hex")}`);ge(r,JSON.stringify(t,null,2),{mode:384}),Y(r,e)}function g(e){xe(C,{wallets:e})}var w=S(b,"wallets.json");function F(){if(H(w)){process.stderr.write(`Migrating legacy wallets...
2
+ import{a as G,b as T,c as L,d as Z,h as D,p as Q}from"./chunk-QDAWFEIX.js";import{a as V,f as I}from"./chunk-LMDE72OE.js";import{existsSync as H,readFileSync as J,writeFileSync as ge,renameSync as Y}from"fs";import{join as S}from"path";import{homedir as we}from"os";import{randomBytes as ve}from"crypto";import*as i from"@open-wallet-standard/core";import q from"bs58";T();import{z as s}from"zod";var M={"eip155:1":"ethereum","solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp":"solana","bip122:000000000019d6689c085ae165831e93":"bitcoin","tron:mainnet":"tron","ton:mainnet":"ton","fil:mainnet":"filecoin"};function R(e){return e==="evm"?"ethereum":e}var E=s.object({solana:s.string().optional(),ethereum:s.string().optional(),bitcoin:s.string().optional(),tron:s.string().optional(),ton:s.string().optional(),filecoin:s.string().optional()}),X=["base","arbitrum","robinhood","polygon","optimism","bnb","bnb-testnet","avalanche","tempo","tempo-moderato","ethereum-sepolia","base-sepolia","arbitrum-sepolia","polygon-amoy"];function Te(e){let t={};if(e.solana&&(t.solana=e.solana,t["solana-devnet"]=e.solana),e.ethereum){t.ethereum=e.ethereum;for(let r of X)t[r]=e.ethereum}return e.bitcoin&&(t.bitcoin=e.bitcoin),e.tron&&(t.tron=e.tron),e.ton&&(t.ton=e.ton),e.filecoin&&(t.filecoin=e.filecoin),t}var ee=s.object({name:s.string(),type:s.literal("hd"),mnemonic:s.string().optional(),addresses:E,createdAt:s.string()}),te=s.object({name:s.string(),type:s.literal("imported"),chain:s.string().optional(),privateKey:s.string().optional(),addresses:E,createdAt:s.string()}),U=s.enum(["ledger"]),$=s.object({name:s.string(),type:s.literal("hardware"),device:U,addresses:E,createdAt:s.string()}),De=s.discriminatedUnion("type",[ee,te,$]),Me=s.object({name:s.string(),type:s.enum(["hd","imported","hardware"]),device:U.optional(),addresses:s.record(s.string(),s.string()),createdAt:s.string()});import{createHash as _}from"crypto";import{HDKey as x}from"@scure/bip32";import{mnemonicToSeedSync as y}from"@scure/bip39";import{keccak_256 as B}from"@noble/hashes/sha3";import{derivePath as j}from"ed25519-hd-key";import*as O from"bitcoinjs-lib";import re from"ecpair";import*as K from"@bitcoinerlab/secp256k1";import{Keypair as ne}from"@solana/web3.js";import oe from"bs58";import{WalletContractV5R1 as ie}from"@ton/ton";import{keyPairFromSeed as se}from"@ton/crypto";import*as z from"@open-wallet-standard/core";var ae=re(K);function N(e,t,r=0){switch(t){case"solana":return le(e,r);case"ethereum":return ce(e,r);case"bitcoin":return pe(e,r);case"tron":return ue(e,r);case"ton":return ye(e,r);case"filecoin":return he(e,r);default:throw new Error(`Unsupported key family for derivation: ${t}`)}}function le(e,t){let r=y(e),n=`m/44'/501'/${t}'/0'`,{key:o}=j(n,Buffer.from(r).toString("hex")),a=ne.fromSeed(Uint8Array.from(o));return{privateKey:a.secretKey,address:a.publicKey.toBase58()}}function ce(e,t){let r=y(e),n=x.fromMasterSeed(r),o=`m/44'/60'/${t}'/0/0`,a=n.derive(o);if(!a.privateKey)throw new Error("Failed to derive EVM private key");let l=de(a.publicKey);return{privateKey:a.privateKey,address:l}}function de(e){let t=K.pointCompress(e,!1),n=B(t.slice(1)).slice(-20),o="0x"+Buffer.from(n).toString("hex");return fe(o)}function fe(e){let t=e.toLowerCase().replace("0x",""),r=Buffer.from(B(Buffer.from(t,"utf8"))).toString("hex"),n="0x";for(let o=0;o<t.length;o++)n+=parseInt(r[o],16)>=8?t[o].toUpperCase():t[o];return n}function pe(e,t){let r=y(e),n=x.fromMasterSeed(r),o=`m/84'/0'/${t}'/0/0`,a=n.derive(o);if(!a.privateKey)throw new Error("Failed to derive Bitcoin private key");let l=ae.fromPrivateKey(Buffer.from(a.privateKey)),{address:f}=O.payments.p2wpkh({pubkey:Buffer.from(l.publicKey)});if(!f)throw new Error("Failed to derive Bitcoin address");return{privateKey:a.privateKey,address:f}}function ue(e,t){let r=y(e),n=x.fromMasterSeed(r),o=`m/44'/195'/${t}'/0/0`,a=n.derive(o);if(!a.privateKey)throw new Error("Failed to derive Tron private key");let l=me(a.publicKey);return{privateKey:a.privateKey,address:l}}function me(e){let t=K.pointCompress(e,!1),n=B(t.slice(1)).slice(-20),o=Buffer.concat([Buffer.from([65]),Buffer.from(n)]),a=_("sha256").update(o).digest(),l=_("sha256").update(a).digest(),f=Buffer.concat([o,l.slice(0,4)]);return oe.encode(f)}function ye(e,t){let r=y(e),n=`m/44'/607'/${t}'/0'`,{key:o}=j(n,Buffer.from(r).toString("hex")),a=se(Buffer.from(o)),l=ie.create({publicKey:Buffer.from(a.publicKey)});return{privateKey:a.secretKey,address:l.address.toString({bounceable:!1})}}function he(e,t){let r=y(e),n=x.fromMasterSeed(r),o=`m/44'/461'/${t}'/0/0`,a=n.derive(o);if(!a.privateKey)throw new Error("Failed to derive Filecoin private key");let l=z.deriveAddress(e,"filecoin",t);return{privateKey:a.privateKey,address:l}}Q();var b=S(we(),".config","moonpay"),C=S(b,"hardware-wallets.json");function c(){return b}function We(e){let t={};for(let r of e){let n=M[r.chainId];n&&(t[n]=r.address)}return t}function h(e){let t=We(e.accounts);if(!t.filecoin)try{let r=i.exportWallet(e.id,null,c());r&&!r.startsWith("{")&&(t.filecoin=i.deriveAddress(r,"filecoin"))}catch{}return{name:e.name,type:"hd",addresses:t,createdAt:e.createdAt}}function m(){if(!H(C))return[];try{return(JSON.parse(J(C,"utf-8")).wallets??[]).map(t=>$.parse(t))}catch{return[]}}function xe(e,t){D();let r=S(b,`.tmp.${ve(4).toString("hex")}`);ge(r,JSON.stringify(t,null,2),{mode:384}),Y(r,e)}function g(e){xe(C,{wallets:e})}var w=S(b,"wallets.json");function F(){if(H(w)){process.stderr.write(`Migrating legacy wallets...
3
3
  `);let{migrated:e,skipped:t}=Ke();process.stderr.write(`Migrated ${e} wallet(s), skipped ${t}.
4
- `)}}function Ke(){if(!H(w))throw new Error("No legacy wallets.json found \u2014 nothing to migrate.");let{getEncryptionKey:e}=(Z(),I(L)),{decrypt:t,encryptedFileSchema:r}=(T(),I(G)),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(J(w,"utf-8")),a=r.parse(o),l=t(a,n),f=JSON.parse(l).wallets??[],p=c(),W=m(),P=0,k=0;for(let d of f){try{i.getWallet(d.name,p),k++;continue}catch{}if(W.some(u=>u.name===d.name)){k++;continue}if(d.type==="hardware")W.push({name:d.name,type:"hardware",device:d.device,addresses:d.addresses,createdAt:d.createdAt});else if(d.type==="hd"&&d.mnemonic)i.importWalletMnemonic(d.name,d.mnemonic,null,null,p);else if(d.type==="imported"&&d.privateKey){let u=d.privateKey;if(!/^[0-9a-fA-F]+$/.test(u)){let A=q.decode(u);u=Buffer.from(A.length===64?A.slice(0,32):A).toString("hex")}i.importWalletPrivateKey(d.name,u,null,p,null,u,u)}P++}return W.length>0&&g(W),Y(w,w+".migrated"),{migrated:P,skipped:k}}function Se(e){F(),v(e);let t=i.createWallet(e,null,24,c());return h(t)}function be(e,t){v(e);let r=i.importWalletMnemonic(e,t,null,null,c());return h(r)}function ke(e,t,r){return v(e),h(i.importWalletPrivateKey(e,t,null,c(),r))}function Ae(){F();let e=[];try{e=i.listWallets(c())}catch{}return[...e.map(r=>h(r)),...m()]}function Ee(e){F();let t=c();try{let r=i.getWallet(e,t);return h(r)}catch{}try{for(let r of i.listWallets(t))for(let n of r.accounts)if(n.address===e)return h(r)}catch{}for(let r of m()){if(r.name===e)return r;for(let n of Object.values(r.addresses))if(n===e)return r}return null}function ot(e){let t=Ee(e);if(!t)throw new Error(`Wallet "${e}" not found`);return t}function $e(e){try{i.deleteWallet(e,c());return}catch{}let t=m(),r=t.findIndex(n=>n.name===e);if(r===-1)throw new Error(`Wallet "${e}" not found`);t.splice(r,1),g(t)}function it(e,t){if(e===t)return;v(t);try{i.getWallet(e,c()),i.renameWallet(e,t,c());return}catch(o){if(o instanceof Error&&!o.message.includes("not found"))throw o}let r=m(),n=r.find(o=>o.name===e);if(!n)throw new Error(`Wallet "${e}" not found`);n.name=t,g(r)}function st(e){return i.exportWallet(e,null,c())}function Be(e){v(e.name);let t=m();t.push(e),g(t)}function at(e,t){let r=m(),n=r.find(o=>o.name===e);if(!n)throw new Error(`Hardware wallet "${e}" not found`);n.addresses=t,g(r)}function lt(e,t,r){return i.signTransaction(e,t,r,null,null,c())}function ct(e,t,r,n){return i.signMessage(e,t,r,null,n??null,null,c())}function dt(e,t,r){return i.signTypedData(e,t,r,null,null,c())}async function ft(e,t){if(e.type==="hardware")throw new Error(`Wallet "${e.name}" is a hardware wallet. Signing must happen on the device.`);let{moonpay:r}=await import("./client-PE3HHRO5.js"),n=await r.chain.retrieve({chain:t}),o=R(n.keyFamily),a=i.exportWallet(e.name,null,c());if(a.includes(" "))return N(a,o);let l;if(a.startsWith("{")){let p=JSON.parse(a);l=o==="solana"||o==="ton"?p.ed25519:p.secp256k1}else l=a;let f=Uint8Array.from(Buffer.from(l,"hex"));if(o==="solana"&&f.length===32){let p=V("tweetnacl");f=Uint8Array.from(p.sign.keyPair.fromSeed(f).secretKey)}return{privateKey:f,address:e.addresses[o]??""}}var Ce=Ae,pt=$e;function He(e){if(e.type==="hardware"){Be(e);return}if(e.type==="hd"&&e.mnemonic){be(e.name,e.mnemonic);return}if(e.type==="imported"&&e.privateKey){let t=e.privateKey;if(t.startsWith("0x"))t=t.slice(2);else if(!/^[0-9a-fA-F]+$/.test(t)){let r=q.decode(t);t=Buffer.from(r.length===64?r.slice(0,32):r).toString("hex")}ke(e.name,t,"solana");return}Se(e.name)}function ut(e){for(let t of e)He(t)}function mt(e){let t=Ce();e(t),g(t.filter(r=>r.type==="hardware"))}function v(e){try{throw i.getWallet(e,c()),new Error(`Wallet "${e}" already exists`)}catch(t){if(t instanceof Error&&t.message.includes("already exists"))throw t}if(m().some(t=>t.name===e))throw new Error(`Wallet "${e}" already exists`)}export{R as a,E as b,Te as c,U as d,Me as e,N as f,c as g,F as h,Ke as i,Se as j,be as k,ke as l,Ae as m,Ee as n,ot as o,$e as p,it as q,st as r,Be as s,at as t,lt as u,ct as v,dt as w,ft as x,Ce as y,pt as z,He as A,ut as B,mt as C};
4
+ `)}}function Ke(){if(!H(w))throw new Error("No legacy wallets.json found \u2014 nothing to migrate.");let{getEncryptionKey:e}=(Z(),I(L)),{decrypt:t,encryptedFileSchema:r}=(T(),I(G)),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(J(w,"utf-8")),a=r.parse(o),l=t(a,n),f=JSON.parse(l).wallets??[],p=c(),W=m(),P=0,k=0;for(let d of f){try{i.getWallet(d.name,p),k++;continue}catch{}if(W.some(u=>u.name===d.name)){k++;continue}if(d.type==="hardware")W.push({name:d.name,type:"hardware",device:d.device,addresses:d.addresses,createdAt:d.createdAt});else if(d.type==="hd"&&d.mnemonic)i.importWalletMnemonic(d.name,d.mnemonic,null,null,p);else if(d.type==="imported"&&d.privateKey){let u=d.privateKey;if(!/^[0-9a-fA-F]+$/.test(u)){let A=q.decode(u);u=Buffer.from(A.length===64?A.slice(0,32):A).toString("hex")}i.importWalletPrivateKey(d.name,u,null,p,null,u,u)}P++}return W.length>0&&g(W),Y(w,w+".migrated"),{migrated:P,skipped:k}}function Se(e){F(),v(e);let t=i.createWallet(e,null,24,c());return h(t)}function be(e,t){v(e);let r=i.importWalletMnemonic(e,t,null,null,c());return h(r)}function ke(e,t,r){return v(e),h(i.importWalletPrivateKey(e,t,null,c(),r))}function Ae(){F();let e=[];try{e=i.listWallets(c())}catch{}return[...e.map(r=>h(r)),...m()]}function Ee(e){F();let t=c();try{let r=i.getWallet(e,t);return h(r)}catch{}try{for(let r of i.listWallets(t))for(let n of r.accounts)if(n.address===e)return h(r)}catch{}for(let r of m()){if(r.name===e)return r;for(let n of Object.values(r.addresses))if(n===e)return r}return null}function ot(e){let t=Ee(e);if(!t)throw new Error(`Wallet "${e}" not found`);return t}function $e(e){try{i.deleteWallet(e,c());return}catch{}let t=m(),r=t.findIndex(n=>n.name===e);if(r===-1)throw new Error(`Wallet "${e}" not found`);t.splice(r,1),g(t)}function it(e,t){if(e===t)return;v(t);try{i.getWallet(e,c()),i.renameWallet(e,t,c());return}catch(o){if(o instanceof Error&&!o.message.includes("not found"))throw o}let r=m(),n=r.find(o=>o.name===e);if(!n)throw new Error(`Wallet "${e}" not found`);n.name=t,g(r)}function st(e){return i.exportWallet(e,null,c())}function Be(e){v(e.name);let t=m();t.push(e),g(t)}function at(e,t){let r=m(),n=r.find(o=>o.name===e);if(!n)throw new Error(`Hardware wallet "${e}" not found`);n.addresses=t,g(r)}function lt(e,t,r){return i.signTransaction(e,t,r,null,null,c())}function ct(e,t,r,n){return i.signMessage(e,t,r,null,n??null,null,c())}function dt(e,t,r){return i.signTypedData(e,t,r,null,null,c())}async function ft(e,t){if(e.type==="hardware")throw new Error(`Wallet "${e.name}" is a hardware wallet. Signing must happen on the device.`);let{moonpay:r}=await import("./client-YCF5Z2NY.js"),n=await r.chain.retrieve({chain:t}),o=R(n.keyFamily),a=i.exportWallet(e.name,null,c());if(a.includes(" "))return N(a,o);let l;if(a.startsWith("{")){let p=JSON.parse(a);l=o==="solana"||o==="ton"?p.ed25519:p.secp256k1}else l=a;let f=Uint8Array.from(Buffer.from(l,"hex"));if(o==="solana"&&f.length===32){let p=V("tweetnacl");f=Uint8Array.from(p.sign.keyPair.fromSeed(f).secretKey)}return{privateKey:f,address:e.addresses[o]??""}}var Ce=Ae,pt=$e;function He(e){if(e.type==="hardware"){Be(e);return}if(e.type==="hd"&&e.mnemonic){be(e.name,e.mnemonic);return}if(e.type==="imported"&&e.privateKey){let t=e.privateKey;if(t.startsWith("0x"))t=t.slice(2);else if(!/^[0-9a-fA-F]+$/.test(t)){let r=q.decode(t);t=Buffer.from(r.length===64?r.slice(0,32):r).toString("hex")}ke(e.name,t,"solana");return}Se(e.name)}function ut(e){for(let t of e)He(t)}function mt(e){let t=Ce();e(t),g(t.filter(r=>r.type==="hardware"))}function v(e){try{throw i.getWallet(e,c()),new Error(`Wallet "${e}" already exists`)}catch(t){if(t instanceof Error&&t.message.includes("already exists"))throw t}if(m().some(t=>t.name===e))throw new Error(`Wallet "${e}" already exists`)}export{R as a,E as b,Te as c,U as d,Me as e,N as f,c as g,F as h,Ke as i,Se as j,be as k,ke as l,Ae as m,Ee as n,ot as o,$e as p,it as q,st as r,Be as s,at as t,lt as u,ct as v,dt as w,ft as x,Ce as y,pt as z,He as A,ut as B,mt as C};
@@ -1,2 +1,2 @@
1
1
  process.noDeprecation = true; import { createRequire as __createRequire } from "module"; const require = __createRequire(import.meta.url);
2
- import{b as a,c as b}from"./chunk-ITDELALC.js";import"./chunk-GEKUY6YQ.js";import"./chunk-LMDE72OE.js";export{a as moonpay,b as resetClient};
2
+ import{b as a,c as b}from"./chunk-V7V6LCEH.js";import"./chunk-QDAWFEIX.js";import"./chunk-LMDE72OE.js";export{a as moonpay,b as resetClient};
package/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  process.noDeprecation = true; import { createRequire as __createRequire } from "module"; const require = __createRequire(import.meta.url);
3
- import{a as T,b,c as L,e as M,f as J,g as j}from"./chunk-BMSIPQ5W.js";import{b as C}from"./chunk-ITDELALC.js";import{a as I,n as D}from"./chunk-IWQWMA6B.js";import{e as E,g as oe}from"./chunk-GEKUY6YQ.js";import"./chunk-LMDE72OE.js";import{Command as ye}from"commander";var re=!process.env.NO_COLOR&&process.stdout.isTTY===!0;function _(e){return t=>re?`${e}${t}\x1B[0m`:t}var p={bold:_("\x1B[1m"),dim:_("\x1B[2m"),green:_("\x1B[32m"),yellow:_("\x1B[33m"),cyan:_("\x1B[36m"),red:_("\x1B[31m")};function S(e){if(e==null)return!0;let t=typeof e;return t==="string"||t==="number"||t==="boolean"}function k(e){return e==null?"-":String(e)}function v(e,t=0){let n=" ".repeat(t);return S(e)?`${n}${k(e)}`:Array.isArray(e)?e.length===0?`${n}${p.dim("(empty)")}`:e.every(S)?e.map(r=>`${n}- ${k(r)}`).join(`
3
+ import{a as T,b,c as L,e as M,f as J,g as j}from"./chunk-OYN4MVGH.js";import{b as C}from"./chunk-V7V6LCEH.js";import{a as I,n as D}from"./chunk-WFMM5XGD.js";import{e as E,g as oe}from"./chunk-QDAWFEIX.js";import"./chunk-LMDE72OE.js";import{Command as ye}from"commander";var re=!process.env.NO_COLOR&&process.stdout.isTTY===!0;function _(e){return t=>re?`${e}${t}\x1B[0m`:t}var p={bold:_("\x1B[1m"),dim:_("\x1B[2m"),green:_("\x1B[32m"),yellow:_("\x1B[33m"),cyan:_("\x1B[36m"),red:_("\x1B[31m")};function S(e){if(e==null)return!0;let t=typeof e;return t==="string"||t==="number"||t==="boolean"}function k(e){return e==null?"-":String(e)}function v(e,t=0){let n=" ".repeat(t);return S(e)?`${n}${k(e)}`:Array.isArray(e)?e.length===0?`${n}${p.dim("(empty)")}`:e.every(S)?e.map(r=>`${n}- ${k(r)}`).join(`
4
4
  `):e.map(r=>{if(typeof r!="object"||r===null)return`${n}- ${k(r)}`;let s=Object.entries(r),i=[],[a,f]=s[0];S(f)?i.push(`${n}- ${p.bold(a)}: ${k(f)}`):(i.push(`${n}- ${p.bold(a)}:`),i.push(v(f,t+2)));for(let[d,g]of s.slice(1))S(g)?i.push(`${n} ${p.bold(d)}: ${k(g)}`):(i.push(`${n} ${p.bold(d)}:`),i.push(v(g,t+2)));return i.join(`
5
5
  `)}).join(`
6
6
 
@@ -14,5 +14,5 @@ ${v(i,t+1)}`).join(`
14
14
 
15
15
  Run \`mp skill install\` to install AI skills for Claude Code.
16
16
 
17
- `+M).version(E).option("--json","Output as JSON instead of YAML");function x(){return h.opts().json?"json":"yaml"}function V(e){console.log(R(e,x()))}function Q(){let e=ge();e&&process.stderr.write(e)}h.command("mcp").description("Start MCP server over stdio (for Claude Desktop, Claude Code, etc.)").action(async()=>{let{startMcpServer:e}=await import("./mcp-4XS3JJGZ.js");await e()});h.command("serve").description("Local loopback mirror of agents.moonpay.com/api/tools \u2014 warm process for MoonAgents / UIs. GET /health \xB7 POST /api/tools/:tool").option("--port <port>","Port to bind (default 8787)",e=>Number(e),8787).option("--host <host>","Loopback host only (default 127.0.0.1)","127.0.0.1").option("--force","Bind even if something already answers on this port (skip idempotent check)",!1).action(async e=>{let{startServe:t}=await import("./serve-HB5QWUE7.js");try{await t({host:e.host,port:e.port,idempotent:!e.force})}catch(n){console.error(n instanceof Error?n.message:String(n)),process.exit(1)}});function ee(e,t){let n=e;for(let r of t){let s=n.commands.find(i=>i.name()===r);s||(s=n.command(r)),n=s}return n}function ne(e,t=""){let n=[];for(let[r,s]of Object.entries(e)){let i=t?`${t}-${r}`:r,a=s;for(;a._def.typeName==="ZodEffects";)a=a._def.schema;let f=a;f._def.typeName==="ZodNullable"&&(f=f._def.innerType),f._def.typeName==="ZodObject"&&f.shape?n.push(...ne(f.shape,i)):n.push({flatKey:i,field:s,path:i.split("-")})}return n}function he(e,t){let n={};for(let{flatKey:r,path:s}of t){let i=r.replace(/-([a-z])/g,(f,d)=>d.toUpperCase()),a=i in e?e[i]:e[r];if(s.length===1)n[s[0]]=a;else{let f=n;for(let d=0;d<s.length-1;d++)(!f[s[d]]||typeof f[s[d]]!="object")&&(f[s[d]]={}),f=f[s[d]];f[s[s.length-1]]=a}}return n}function be(e,t){for(let n of t){let r=n.schema.name.split("_"),s=r.pop(),a=ee(e,r).command(s).description(n.schema.description),f=n.schema.input.shape??{},d=ne(f),g=d.some(({flatKey:o})=>o===b),w=[],O=[],$=[],N=[];for(let{flatKey:o,field:c}of d){let l=c.description??o,u=c;for(;u._def.typeName==="ZodEffects";)u=u._def.schema;let y=u._def.typeName,m=u;m._def.typeName==="ZodNullable"&&(m=m._def.innerType),m._def.typeName==="ZodNumber"&&O.push(o),m._def.typeName==="ZodRecord"&&$.push(o),m._def.typeName==="ZodBoolean"&&N.push(o),y==="ZodBoolean"?a.option(`--${o} [${o}]`,l,!1):y==="ZodNullable"?(a.option(`--${o} <${o}>`,l),w.push(o)):a.requiredOption(`--${o} <${o}>`,l)}g||a.option(`--${b} <${b}>`,L),a.action(async o=>{n.schema.name.startsWith("consent_")||await J.handler({});for(let l of w){let u=l.replace(/-([a-z])/g,(y,m)=>m.toUpperCase());o[u]===void 0&&(o[u]=null)}for(let l of O){let u=l.replace(/-([a-z])/g,(y,m)=>m.toUpperCase());o[u]!=null&&typeof o[u]=="string"&&(o[u]=Number(o[u]))}for(let l of N){let u=l.replace(/-([a-z])/g,(m,A)=>A.toUpperCase()),y=o[u];if(typeof y=="string"){let m=y.toLowerCase();m==="true"||m==="1"?o[u]=!0:(m==="false"||m==="0")&&(o[u]=!1)}}for(let l of $){let u=l.replace(/-([a-z])/g,(y,m)=>m.toUpperCase());if(typeof o[u]=="string")try{o[u]=JSON.parse(o[u])}catch{console.error(`Invalid JSON for --${l}`),process.exit(1)}}let c=he(o,d);!g&&typeof o[b]=="string"&&(c[b]=o[b]);try{let l=await n.handler(c);V(l)}catch(l){console.error(F(l,x())),process.exit(1)}})}}function we(e){if(e.$ref&&e.definitions){let t=e.$ref.replace("#/definitions/","");return e.definitions[t]}return e}function _e(e){return Array.isArray(e.type)?e.type.includes("null"):e.anyOf?e.anyOf.some(t=>t.type==="null"):!1}function ke(e){return Array.isArray(e.type)?e.type.includes("object"):e.anyOf?e.anyOf.some(t=>t.type==="object"):e.type==="object"}function Oe(e){return Array.isArray(e.type)?e.type.some(t=>t==="number"||t==="integer"):e.anyOf?e.anyOf.some(t=>t.type==="number"||t.type==="integer"):e.type==="number"||e.type==="integer"}function $e(e){return Array.isArray(e.type)?e.type.includes("boolean"):e.anyOf?e.anyOf.some(t=>t.type==="boolean"):e.type==="boolean"}var te=new Set(["swaps_transaction_build","swaps_quote_retrieve","transaction_register","virtual-account_offramp_initiate","prediction-market_position_buy","prediction-market_position_sell","prediction-market_position_redeem","polymarket_balance_withdraw_prepare","polymarket_balance_withdraw_submit","commerce_cart_update","commerce_checkout_start","commerce_checkout_pay","card_delegation_approve_transaction_build","card_delegation_revoke_transaction_build","card_delegation_token_retrieve","card_wallet_link","card_wallet_unlink"]);function Ne(e,t){for(let n of t){if(te.has(n.name))continue;let r=n.name.split("_"),s=r.pop(),i=ee(e,r);if(i.commands.find(o=>o.name()===s))continue;let a=i.command(s).description(n.description),f=we(n.inputSchema),d=f.properties??{},g=new Set(f.required??[]),w=[],O=[],$=[],N=[];for(let[o,c]of Object.entries(d)){let l=c.description??o,u=_e(c),y=ke(c),m=Oe(c),A=$e(c);m&&O.push(o),A&&N.push(o),y?($.push(o),g.has(o)&&!u?a.requiredOption(`--${o} <json>`,`${l} (as JSON)`):(a.option(`--${o} <json>`,`${l} (as JSON)`),w.push(o))):u||!g.has(o)?(a.option(`--${o} <${o}>`,l),w.push(o)):a.requiredOption(`--${o} <${o}>`,l)}a.action(async o=>{await J.handler({});for(let c of w)o[c]===void 0&&(o[c]=null);for(let c of O)o[c]!=null&&typeof o[c]=="string"&&(o[c]=Number(o[c]));for(let c of N)if(typeof o[c]=="string"){let l=o[c].toLowerCase();l==="true"||l==="1"?o[c]=!0:(l==="false"||l==="0")&&(o[c]=!1)}for(let c of $)if(typeof o[c]=="string")try{o[c]=JSON.parse(o[c])}catch{console.error(`Invalid JSON for --${c}`),process.exit(1)}try{await H(o);let c=await C._call(n.name,o);V(c),Q()}catch(c){console.error(F(c,x())),process.exit(1)}})}}be(h,j);Ne(h,T);h.command("tools").description("List available tools").action(()=>{let e=[...j.map(n=>({name:n.schema.name,description:n.schema.description})),...T.filter(n=>!j.some(r=>r.schema.name===n.name)&&!te.has(n.name)).map(n=>({name:n.name,description:n.description}))].sort((n,r)=>n.name.localeCompare(r.name)),t=[];for(let n of e){let r=n.name.replace(/_/g," ");t.push(` ${p.green(r.padEnd(28))} ${p.dim(n.description)}`)}t.push(""),t.push(p.dim(`${e.length} tools`)),console.log(t.join(`
17
+ `+M).version(E).option("--json","Output as JSON instead of YAML");function x(){return h.opts().json?"json":"yaml"}function V(e){console.log(R(e,x()))}function Q(){let e=ge();e&&process.stderr.write(e)}h.command("mcp").description("Start MCP server over stdio (for Claude Desktop, Claude Code, etc.)").action(async()=>{let{startMcpServer:e}=await import("./mcp-MJ4WULTJ.js");await e()});h.command("serve").description("Local loopback mirror of agents.moonpay.com/api/tools \u2014 warm process for MoonAgents / UIs. GET /health \xB7 POST /api/tools/:tool").option("--port <port>","Port to bind (default 8787)",e=>Number(e),8787).option("--host <host>","Loopback host only (default 127.0.0.1)","127.0.0.1").option("--force","Bind even if something already answers on this port (skip idempotent check)",!1).action(async e=>{let{startServe:t}=await import("./serve-NMKWP2YQ.js");try{await t({host:e.host,port:e.port,idempotent:!e.force})}catch(n){console.error(n instanceof Error?n.message:String(n)),process.exit(1)}});function ee(e,t){let n=e;for(let r of t){let s=n.commands.find(i=>i.name()===r);s||(s=n.command(r)),n=s}return n}function ne(e,t=""){let n=[];for(let[r,s]of Object.entries(e)){let i=t?`${t}-${r}`:r,a=s;for(;a._def.typeName==="ZodEffects";)a=a._def.schema;let f=a;f._def.typeName==="ZodNullable"&&(f=f._def.innerType),f._def.typeName==="ZodObject"&&f.shape?n.push(...ne(f.shape,i)):n.push({flatKey:i,field:s,path:i.split("-")})}return n}function he(e,t){let n={};for(let{flatKey:r,path:s}of t){let i=r.replace(/-([a-z])/g,(f,d)=>d.toUpperCase()),a=i in e?e[i]:e[r];if(s.length===1)n[s[0]]=a;else{let f=n;for(let d=0;d<s.length-1;d++)(!f[s[d]]||typeof f[s[d]]!="object")&&(f[s[d]]={}),f=f[s[d]];f[s[s.length-1]]=a}}return n}function be(e,t){for(let n of t){let r=n.schema.name.split("_"),s=r.pop(),a=ee(e,r).command(s).description(n.schema.description),f=n.schema.input.shape??{},d=ne(f),g=d.some(({flatKey:o})=>o===b),w=[],O=[],$=[],N=[];for(let{flatKey:o,field:c}of d){let l=c.description??o,u=c;for(;u._def.typeName==="ZodEffects";)u=u._def.schema;let y=u._def.typeName,m=u;m._def.typeName==="ZodNullable"&&(m=m._def.innerType),m._def.typeName==="ZodNumber"&&O.push(o),m._def.typeName==="ZodRecord"&&$.push(o),m._def.typeName==="ZodBoolean"&&N.push(o),y==="ZodBoolean"?a.option(`--${o} [${o}]`,l,!1):y==="ZodNullable"?(a.option(`--${o} <${o}>`,l),w.push(o)):a.requiredOption(`--${o} <${o}>`,l)}g||a.option(`--${b} <${b}>`,L),a.action(async o=>{n.schema.name.startsWith("consent_")||await J.handler({});for(let l of w){let u=l.replace(/-([a-z])/g,(y,m)=>m.toUpperCase());o[u]===void 0&&(o[u]=null)}for(let l of O){let u=l.replace(/-([a-z])/g,(y,m)=>m.toUpperCase());o[u]!=null&&typeof o[u]=="string"&&(o[u]=Number(o[u]))}for(let l of N){let u=l.replace(/-([a-z])/g,(m,A)=>A.toUpperCase()),y=o[u];if(typeof y=="string"){let m=y.toLowerCase();m==="true"||m==="1"?o[u]=!0:(m==="false"||m==="0")&&(o[u]=!1)}}for(let l of $){let u=l.replace(/-([a-z])/g,(y,m)=>m.toUpperCase());if(typeof o[u]=="string")try{o[u]=JSON.parse(o[u])}catch{console.error(`Invalid JSON for --${l}`),process.exit(1)}}let c=he(o,d);!g&&typeof o[b]=="string"&&(c[b]=o[b]);try{let l=await n.handler(c);V(l)}catch(l){console.error(F(l,x())),process.exit(1)}})}}function we(e){if(e.$ref&&e.definitions){let t=e.$ref.replace("#/definitions/","");return e.definitions[t]}return e}function _e(e){return Array.isArray(e.type)?e.type.includes("null"):e.anyOf?e.anyOf.some(t=>t.type==="null"):!1}function ke(e){return Array.isArray(e.type)?e.type.includes("object"):e.anyOf?e.anyOf.some(t=>t.type==="object"):e.type==="object"}function Oe(e){return Array.isArray(e.type)?e.type.some(t=>t==="number"||t==="integer"):e.anyOf?e.anyOf.some(t=>t.type==="number"||t.type==="integer"):e.type==="number"||e.type==="integer"}function $e(e){return Array.isArray(e.type)?e.type.includes("boolean"):e.anyOf?e.anyOf.some(t=>t.type==="boolean"):e.type==="boolean"}var te=new Set(["swaps_transaction_build","swaps_quote_retrieve","transaction_register","virtual-account_offramp_initiate","prediction-market_position_buy","prediction-market_position_sell","prediction-market_position_redeem","polymarket_balance_withdraw_prepare","polymarket_balance_withdraw_submit","commerce_cart_update","commerce_checkout_start","commerce_checkout_pay","card_delegation_approve_transaction_build","card_delegation_revoke_transaction_build","card_delegation_token_retrieve","card_wallet_link","card_wallet_unlink"]);function Ne(e,t){for(let n of t){if(te.has(n.name))continue;let r=n.name.split("_"),s=r.pop(),i=ee(e,r);if(i.commands.find(o=>o.name()===s))continue;let a=i.command(s).description(n.description),f=we(n.inputSchema),d=f.properties??{},g=new Set(f.required??[]),w=[],O=[],$=[],N=[];for(let[o,c]of Object.entries(d)){let l=c.description??o,u=_e(c),y=ke(c),m=Oe(c),A=$e(c);m&&O.push(o),A&&N.push(o),y?($.push(o),g.has(o)&&!u?a.requiredOption(`--${o} <json>`,`${l} (as JSON)`):(a.option(`--${o} <json>`,`${l} (as JSON)`),w.push(o))):u||!g.has(o)?(a.option(`--${o} <${o}>`,l),w.push(o)):a.requiredOption(`--${o} <${o}>`,l)}a.action(async o=>{await J.handler({});for(let c of w)o[c]===void 0&&(o[c]=null);for(let c of O)o[c]!=null&&typeof o[c]=="string"&&(o[c]=Number(o[c]));for(let c of N)if(typeof o[c]=="string"){let l=o[c].toLowerCase();l==="true"||l==="1"?o[c]=!0:(l==="false"||l==="0")&&(o[c]=!1)}for(let c of $)if(typeof o[c]=="string")try{o[c]=JSON.parse(o[c])}catch{console.error(`Invalid JSON for --${c}`),process.exit(1)}try{await H(o);let c=await C._call(n.name,o);V(c),Q()}catch(c){console.error(F(c,x())),process.exit(1)}})}}be(h,j);Ne(h,T);h.command("tools").description("List available tools").action(()=>{let e=[...j.map(n=>({name:n.schema.name,description:n.schema.description})),...T.filter(n=>!j.some(r=>r.schema.name===n.name)&&!te.has(n.name)).map(n=>({name:n.name,description:n.description}))].sort((n,r)=>n.name.localeCompare(r.name)),t=[];for(let n of e){let r=n.name.replace(/_/g," ");t.push(` ${p.green(r.padEnd(28))} ${p.dim(n.description)}`)}t.push(""),t.push(p.dim(`${e.length} tools`)),console.log(t.join(`
18
18
  `)),Q()});h.parse();
@@ -7,6 +7,6 @@ Run: npm i -g @moonpay/cli --include=optional`;function y(){try{let e=S("@ledger
7
7
  `),p}async function U(){if(!p)return null;try{let e=y(),i=f().getDeviceSessionState({sessionId:p}),s=await e.firstValueFrom(i.pipe(e.take(1),e.timeout(3e3)));return s.sessionStateType>=1?s.currentApp?.name??null:null}catch{return null}}var M={evm:"Ethereum",solana:"Solana"};function _(e){let n=String(e);return n.includes("6807")||n.includes("6a15")||n.includes("UnknownDeviceExchangeError")}async function C(e){process.stderr.write(`Installing ${e} app on your Ledger...
8
8
  `);let{OpenAppWithDependenciesDeviceAction:n}=y(),i=new n({input:{appName:e}}),t=f().executeDeviceAction({sessionId:E(),deviceAction:i});await m(t,`Install ${e}`,18e4),process.stderr.write(`Installed ${e} app
9
9
  `)}async function R(e){let n=M[e];if(!n||await U()===n)return;process.stderr.write(`Opening ${n} app on your Ledger...
10
- `);let{OpenAppDeviceAction:s}=y(),t=new s({input:{appName:n}}),u=f().executeDeviceAction({sessionId:E(),deviceAction:t});try{await m(u,`Open ${n}`)}catch(c){if(_(c)){await D(),await C(n),await D();return}if(!String(c).includes("isconnect"))throw c}await D()}async function D(){try{await f().disconnect({sessionId:p})}catch{}p=null,await new Promise(e=>setTimeout(e,500)),await P()}function $(e,n=0){switch(e){case"evm":return`44'/60'/${n}'/0/0`;case"solana":return`44'/501'/${n}'/0'`;default:throw new Error(`${e} derivation via Ledger is not supported.`)}}function k(e){return e.startsWith("0x")?e.slice(2):e}function T(e){return e.startsWith("0x")?e:`0x${e}`}async function x(e){let{moonpay:n}=await import("./client-PE3HHRO5.js"),s=(await n.chain.retrieve({chain:e})).keyFamily;if(s==="bitcoin")throw new Error("Bitcoin address derivation via Ledger is not yet supported.");if(s==="tron")throw new Error("Tron address derivation via Ledger is not supported. The Ethereum signer cannot interact with the Tron Ledger app.");await R(s);let t=$(s),a=E(),u=f();switch(s){case"evm":{let{SignerEthBuilder:c}=I(),l=new c({dmk:u,sessionId:a}).build().getAddress(t,{skipOpenApp:!1});return(await m(l,"Get Ethereum address")).address}case"solana":{let{SignerSolanaBuilder:c}=L(),l=new c({dmk:u,sessionId:a}).build().getAddress(t,{skipOpenApp:!1});return await m(l,"Get Solana address")}default:throw new Error(`Ledger address derivation not supported for ${s}`)}}async function F(){let e={};try{e.ethereum=await x("ethereum")}catch(n){process.stderr.write(`Failed to get Ethereum address: ${n}
10
+ `);let{OpenAppDeviceAction:s}=y(),t=new s({input:{appName:n}}),u=f().executeDeviceAction({sessionId:E(),deviceAction:t});try{await m(u,`Open ${n}`)}catch(c){if(_(c)){await D(),await C(n),await D();return}if(!String(c).includes("isconnect"))throw c}await D()}async function D(){try{await f().disconnect({sessionId:p})}catch{}p=null,await new Promise(e=>setTimeout(e,500)),await P()}function $(e,n=0){switch(e){case"evm":return`44'/60'/${n}'/0/0`;case"solana":return`44'/501'/${n}'/0'`;default:throw new Error(`${e} derivation via Ledger is not supported.`)}}function k(e){return e.startsWith("0x")?e.slice(2):e}function T(e){return e.startsWith("0x")?e:`0x${e}`}async function x(e){let{moonpay:n}=await import("./client-YCF5Z2NY.js"),s=(await n.chain.retrieve({chain:e})).keyFamily;if(s==="bitcoin")throw new Error("Bitcoin address derivation via Ledger is not yet supported.");if(s==="tron")throw new Error("Tron address derivation via Ledger is not supported. The Ethereum signer cannot interact with the Tron Ledger app.");await R(s);let t=$(s),a=E(),u=f();switch(s){case"evm":{let{SignerEthBuilder:c}=I(),l=new c({dmk:u,sessionId:a}).build().getAddress(t,{skipOpenApp:!1});return(await m(l,"Get Ethereum address")).address}case"solana":{let{SignerSolanaBuilder:c}=L(),l=new c({dmk:u,sessionId:a}).build().getAddress(t,{skipOpenApp:!1});return await m(l,"Get Solana address")}default:throw new Error(`Ledger address derivation not supported for ${s}`)}}async function F(){let e={};try{e.ethereum=await x("ethereum")}catch(n){process.stderr.write(`Failed to get Ethereum address: ${n}
11
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 H(e,n){let{moonpay:i}=await import("./client-PE3HHRO5.js"),t=(await i.chain.retrieve({chain:e})).keyFamily;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(t);let a=$(t),u=E(),c=f();switch(t){case"evm":{let{SignerEthBuilder:d}=I(),l=new d({dmk:c,sessionId:u}).build(),w=T(n.startsWith("0x")?n:Buffer.from(n,"base64").toString("hex")),o=Uint8Array.from(Buffer.from(k(w),"hex")),r=l.signTransaction(a,o,{skipOpenApp:!1}),g=await m(r,"Sign transaction"),{parseTransaction:v,serializeTransaction:A}=await import("viem"),B=v(w);return{transaction:A(B,{r:T(k(g.r)),s:T(k(g.s)),v:BigInt(g.v)})}}case"solana":{let{SignerSolanaBuilder:d}=L(),l=new d({dmk:c,sessionId:u}).build(),{VersionedTransaction:w}=await import("@solana/web3.js"),o=Uint8Array.from(Buffer.from(n,"base64")),r=w.deserialize(o),g=r.message.serialize(),v=l.signTransaction(a,g,{skipOpenApp:!1}),A=await m(v,"Sign Solana transaction");return r.signatures[0]=A,{transaction:Buffer.from(r.serialize()).toString("base64")}}default:throw new Error(`Ledger transaction signing not supported for ${t}`)}}async function V(e,n){let{moonpay:i}=await import("./client-PE3HHRO5.js"),t=(await i.chain.retrieve({chain:e})).keyFamily;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(t);let a=$(t),u=E(),c=f();switch(t){case"evm":{let{SignerEthBuilder:d}=I(),w=new d({dmk:c,sessionId:u}).build().signMessage(a,n,{skipOpenApp:!1}),o=await m(w,"Sign message"),r=k(o.r),g=k(o.s),v=o.v.toString(16).padStart(2,"0");return{signature:`0x${r}${g}${v}`}}case"solana":{let{SignerSolanaBuilder:d}=L(),l=new d({dmk:c,sessionId:u}).build(),w=Buffer.from(n,"utf8").toString("hex"),o=l.signMessage(a,w,{skipOpenApp:!1}),r=await m(o,"Sign Solana message");return{signature:(await import("bs58")).default.encode(r)}}default:throw new Error(`Ledger message signing not supported for ${t}`)}}async function q(){if(p){try{await f().disconnect({sessionId:p})}catch{}p=null}if(h){try{h.close()}catch{}h=null}}export{P as connectLedger,q as disconnectLedger,x as ledgerGetAddress,F as ledgerGetAllAddresses,V as ledgerSignMessage,H as ledgerSignTransaction};
12
+ `)}if(!e.ethereum&&!e.solana)throw new Error("Could not derive any addresses from Ledger device");return e}async function H(e,n){let{moonpay:i}=await import("./client-YCF5Z2NY.js"),t=(await i.chain.retrieve({chain:e})).keyFamily;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(t);let a=$(t),u=E(),c=f();switch(t){case"evm":{let{SignerEthBuilder:d}=I(),l=new d({dmk:c,sessionId:u}).build(),w=T(n.startsWith("0x")?n:Buffer.from(n,"base64").toString("hex")),o=Uint8Array.from(Buffer.from(k(w),"hex")),r=l.signTransaction(a,o,{skipOpenApp:!1}),g=await m(r,"Sign transaction"),{parseTransaction:v,serializeTransaction:A}=await import("viem"),B=v(w);return{transaction:A(B,{r:T(k(g.r)),s:T(k(g.s)),v:BigInt(g.v)})}}case"solana":{let{SignerSolanaBuilder:d}=L(),l=new d({dmk:c,sessionId:u}).build(),{VersionedTransaction:w}=await import("@solana/web3.js"),o=Uint8Array.from(Buffer.from(n,"base64")),r=w.deserialize(o),g=r.message.serialize(),v=l.signTransaction(a,g,{skipOpenApp:!1}),A=await m(v,"Sign Solana transaction");return r.signatures[0]=A,{transaction:Buffer.from(r.serialize()).toString("base64")}}default:throw new Error(`Ledger transaction signing not supported for ${t}`)}}async function V(e,n){let{moonpay:i}=await import("./client-YCF5Z2NY.js"),t=(await i.chain.retrieve({chain:e})).keyFamily;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(t);let a=$(t),u=E(),c=f();switch(t){case"evm":{let{SignerEthBuilder:d}=I(),w=new d({dmk:c,sessionId:u}).build().signMessage(a,n,{skipOpenApp:!1}),o=await m(w,"Sign message"),r=k(o.r),g=k(o.s),v=o.v.toString(16).padStart(2,"0");return{signature:`0x${r}${g}${v}`}}case"solana":{let{SignerSolanaBuilder:d}=L(),l=new d({dmk:c,sessionId:u}).build(),w=Buffer.from(n,"utf8").toString("hex"),o=l.signMessage(a,w,{skipOpenApp:!1}),r=await m(o,"Sign Solana message");return{signature:(await import("bs58")).default.encode(r)}}default:throw new Error(`Ledger message signing not supported for ${t}`)}}async function q(){if(p){try{await f().disconnect({sessionId:p})}catch{}p=null}if(h){try{h.close()}catch{}h=null}}export{P as connectLedger,q as disconnectLedger,x as ledgerGetAddress,F as ledgerGetAllAddresses,V as ledgerSignMessage,H as ledgerSignTransaction};
@@ -1,2 +1,2 @@
1
1
  process.noDeprecation = true; import { createRequire as __createRequire } from "module"; const require = __createRequire(import.meta.url);
2
- import{a,c,d as i}from"./chunk-FAZG6O63.js";import"./chunk-BMSIPQ5W.js";import"./chunk-ITDELALC.js";import"./chunk-IWQWMA6B.js";import{e as s,g as u}from"./chunk-GEKUY6YQ.js";import"./chunk-LMDE72OE.js";u();import{Server as f}from"@modelcontextprotocol/sdk/server/index.js";import{StdioServerTransport as S}from"@modelcontextprotocol/sdk/server/stdio.js";import{CallToolRequestSchema as g,ListToolsRequestSchema as y}from"@modelcontextprotocol/sdk/types.js";async function v(){let o=new f({name:"moonpay",version:s},{capabilities:{tools:{listChanged:!0}}}),r=a(),m=new Map(r.map(t=>[t.name,t]));o.setRequestHandler(y,async()=>({tools:r.map(t=>({name:t.name,description:t.description,inputSchema:t.inputSchema}))})),o.setRequestHandler(g,async t=>{let{name:n,arguments:l={}}=t.params;if(!m.has(n))return{content:[{type:"text",text:`Unknown tool: ${n}`}],isError:!0};try{let e=await i(n,l);return{content:[{type:"text",text:JSON.stringify(e,null,2)}]}}catch(e){return{content:[{type:"text",text:e instanceof c||e instanceof Error?e.message:String(e)}],isError:!0}}});let p=new S;await o.connect(p)}export{v as startMcpServer};
2
+ import{a,c,d as i}from"./chunk-ACEFIMCT.js";import"./chunk-OYN4MVGH.js";import"./chunk-V7V6LCEH.js";import"./chunk-WFMM5XGD.js";import{e as s,g as u}from"./chunk-QDAWFEIX.js";import"./chunk-LMDE72OE.js";u();import{Server as f}from"@modelcontextprotocol/sdk/server/index.js";import{StdioServerTransport as S}from"@modelcontextprotocol/sdk/server/stdio.js";import{CallToolRequestSchema as g,ListToolsRequestSchema as y}from"@modelcontextprotocol/sdk/types.js";async function v(){let o=new f({name:"moonpay",version:s},{capabilities:{tools:{listChanged:!0}}}),r=a(),m=new Map(r.map(t=>[t.name,t]));o.setRequestHandler(y,async()=>({tools:r.map(t=>({name:t.name,description:t.description,inputSchema:t.inputSchema}))})),o.setRequestHandler(g,async t=>{let{name:n,arguments:l={}}=t.params;if(!m.has(n))return{content:[{type:"text",text:`Unknown tool: ${n}`}],isError:!0};try{let e=await i(n,l);return{content:[{type:"text",text:JSON.stringify(e,null,2)}]}}catch(e){return{content:[{type:"text",text:e instanceof c||e instanceof Error?e.message:String(e)}],isError:!0}}});let p=new S;await o.connect(p)}export{v as startMcpServer};
@@ -1,5 +1,5 @@
1
1
  process.noDeprecation = true; import { createRequire as __createRequire } from "module"; const require = __createRequire(import.meta.url);
2
- import{b as v,c as g,d as y}from"./chunk-FAZG6O63.js";import"./chunk-BMSIPQ5W.js";import"./chunk-ITDELALC.js";import"./chunk-IWQWMA6B.js";import{e as d,g as E,h as S,p as O}from"./chunk-GEKUY6YQ.js";import"./chunk-LMDE72OE.js";E();import{createServer as b}from"http";import{writeFileSync as k,unlinkSync as R,readFileSync as M,existsSync as $}from"fs";import{join as N}from"path";import{homedir as A}from"os";O();var h="127.0.0.1",x=8787,m=N(A(),".config","moonpay","serve.json"),f="/api/tools";function w(e){let t=e.trim().replace(/^v/,"").match(/^(\d+)\.(\d+)\.(\d+)/);return t?[Number(t[1]),Number(t[2]),Number(t[3])]:null}function I(e,t){let r=w(e),s=w(t);if(!r||!s)return!0;for(let i=0;i<3;i++){if(r[i]<s[i])return!0;if(r[i]>s[i])return!1}return!1}function J(e){if(!(!Number.isFinite(e)||e<=0))try{process.kill(e,"SIGTERM")}catch{}}function _(e){S(),k(m,JSON.stringify(e,null,2)+`
2
+ import{b as v,c as g,d as y}from"./chunk-ACEFIMCT.js";import"./chunk-OYN4MVGH.js";import"./chunk-V7V6LCEH.js";import"./chunk-WFMM5XGD.js";import{e as d,g as E,h as S,p as O}from"./chunk-QDAWFEIX.js";import"./chunk-LMDE72OE.js";E();import{createServer as b}from"http";import{writeFileSync as k,unlinkSync as R,readFileSync as M,existsSync as $}from"fs";import{join as N}from"path";import{homedir as A}from"os";O();var h="127.0.0.1",x=8787,m=N(A(),".config","moonpay","serve.json"),f="/api/tools";function w(e){let t=e.trim().replace(/^v/,"").match(/^(\d+)\.(\d+)\.(\d+)/);return t?[Number(t[1]),Number(t[2]),Number(t[3])]:null}function I(e,t){let r=w(e),s=w(t);if(!r||!s)return!0;for(let i=0;i<3;i++){if(r[i]<s[i])return!0;if(r[i]>s[i])return!1}return!1}function J(e){if(!(!Number.isFinite(e)||e<=0))try{process.kill(e,"SIGTERM")}catch{}}function _(e){S(),k(m,JSON.stringify(e,null,2)+`
3
3
  `,{encoding:"utf-8",mode:384})}function j(){try{$(m)&&R(m)}catch{}}function z(){try{return JSON.parse(M(m,"utf-8"))}catch{return null}}async function L(e){let t=[];for await(let s of e)t.push(typeof s=="string"?Buffer.from(s):s);if(t.length===0)return{};let r=Buffer.concat(t).toString("utf-8").trim();return r?JSON.parse(r):{}}function l(e,t,r){let s=JSON.stringify(r);e.writeHead(t,{"Content-Type":"application/json; charset=utf-8","Content-Length":Buffer.byteLength(s)}),e.end(s)}async function B(e,t,r=500){let s=new AbortController,i=setTimeout(()=>s.abort(),r);try{let u=await fetch(`http://${e}:${t}/health`,{signal:s.signal});if(!u.ok)return null;let a=await u.json();return a.ok?{pid:typeof a.pid=="number"?a.pid:-1,host:e,port:t,startedAt:typeof a.startedAt=="string"?a.startedAt:"",version:typeof a.version=="string"?a.version:"",toolsPath:typeof a.toolsPath=="string"?a.toolsPath:void 0}:null}catch{return null}finally{clearTimeout(i)}}async function P(e,t,r){let s=e.headers.host??`${h}`,i=new URL(e.url||"/",`http://${s}`),u=(e.method||"GET").toUpperCase();if(u==="GET"&&i.pathname==="/health"){l(t,200,{ok:!0,version:d,pid:process.pid,startedAt:r,toolsPath:f});return}let a=i.pathname.match(/^\/api\/tools\/([a-z0-9_]+)$/i);if(u==="POST"&&a){let c=a[1];if(!v(c)){l(t,404,{error:`Unknown tool: ${c}`,tool:c});return}let n={};try{let o=await L(e);if(o&&typeof o=="object"&&!Array.isArray(o))n=o;else if(o!=null){l(t,400,{error:"Body must be a JSON object"});return}}catch{l(t,400,{error:"Invalid JSON body"});return}try{let o=await y(c,n);l(t,200,o);return}catch(o){if(o instanceof g){l(t,404,{error:o.message,tool:c});return}let p=o instanceof Error?o.message:String(o);l(t,500,{error:p,tool:c});return}}l(t,404,{error:"Not found",hint:"GET /health or POST /api/tools/:tool"})}async function K(e={}){let t=e.host??h,r=e.port??x,s=e.idempotent!==!1;if(t!=="127.0.0.1"&&t!=="localhost"&&t!=="::1")throw new Error(`mp serve refuses non-loopback host '${t}' \u2014 bind 127.0.0.1 only`);if(s){let n=await B(t,r);if(n){let o=n.toolsPath===f,p=!I(n.version,d);if(o&&p)return process.stdout.write(JSON.stringify({ok:!0,alreadyRunning:!0,host:t,port:r,pid:n.pid,version:n.version,toolsPath:n.toolsPath},null,2)+`
4
4
  `),{host:t,port:r};process.stderr.write(`[mp serve] replacing incompatible daemon pid=${n.pid} v${n.version||"?"} toolsPath=${n.toolsPath??"\u2205"} \u2192 v${d}
5
5
  `),J(n.pid),await new Promise(T=>setTimeout(T,200))}}let i=new Date().toISOString(),u=b((n,o)=>{P(n,o,i).catch(p=>{l(o,500,{error:p instanceof Error?p.message:String(p)})})});await new Promise((n,o)=>{u.once("error",o),u.listen(r,t,()=>n())});let a={pid:process.pid,host:t,port:r,startedAt:i,version:d};_(a);let c=()=>{j(),u.close(()=>process.exit(0))};return process.once("SIGINT",c),process.once("SIGTERM",c),process.stdout.write(JSON.stringify({ok:!0,alreadyRunning:!1,host:t,port:r,pid:process.pid,version:d,endpoints:{health:`http://${t}:${r}/health`,tools:`http://${t}:${r}${f}/:tool`},toolsPath:f},null,2)+`
@@ -1,2 +1,2 @@
1
1
  process.noDeprecation = true; import { createRequire as __createRequire } from "module"; const require = __createRequire(import.meta.url);
2
- import{A as u,B as v,C as w,g as a,h as b,i as c,j as d,k as e,l as f,m as g,n as h,o as i,p as j,q as k,r as l,s as m,t as n,u as o,v as p,w as q,x as r,y as s,z as t}from"./chunk-IWQWMA6B.js";import"./chunk-GEKUY6YQ.js";import"./chunk-LMDE72OE.js";export{m as addHardwareWallet,u as addWallet,d as createWallet,j as deleteWallet,l as exportSecret,h as findWallet,i as findWalletOrThrow,a as getVaultPath,e as importMnemonic,f as importPrivateKey,g as listWallets,s as loadWallets,c as migrateWallets,w as mutateWallets,p as owsSignMessage,o as owsSignTransaction,q as owsSignTypedData,n as refreshHardwareAddresses,t as removeWallet,k as renameWallet,b as requireMigrationCheck,r as resolveSigningKey,v as saveWallets};
2
+ import{A as u,B as v,C as w,g as a,h as b,i as c,j as d,k as e,l as f,m as g,n as h,o as i,p as j,q as k,r as l,s as m,t as n,u as o,v as p,w as q,x as r,y as s,z as t}from"./chunk-WFMM5XGD.js";import"./chunk-QDAWFEIX.js";import"./chunk-LMDE72OE.js";export{m as addHardwareWallet,u as addWallet,d as createWallet,j as deleteWallet,l as exportSecret,h as findWallet,i as findWalletOrThrow,a as getVaultPath,e as importMnemonic,f as importPrivateKey,g as listWallets,s as loadWallets,c as migrateWallets,w as mutateWallets,p as owsSignMessage,o as owsSignTransaction,q as owsSignTypedData,n as refreshHardwareAddresses,t as removeWallet,k as renameWallet,b as requireMigrationCheck,r as resolveSigningKey,v as saveWallets};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@moonpay/cli",
3
- "version": "1.96.0",
3
+ "version": "1.96.1",
4
4
  "description": "MoonPay CLI — how agents move money",
5
5
  "homepage": "https://agents.moonpay.com",
6
6
  "publishConfig": {
@@ -38,7 +38,7 @@
38
38
  "@ton/core": "^0.63.1",
39
39
  "@ton/crypto": "^3.3.0",
40
40
  "@ton/ton": "^16.2.2",
41
- "axios": "1.13.5",
41
+ "axios": "1.20.0",
42
42
  "bitcoinjs-lib": "7.0.1",
43
43
  "bs58": "6.0.0",
44
44
  "commander": "12.1.0",