@moonpay/cli 1.96.3 → 1.96.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -20,7 +20,9 @@ mp wallet create --name "main"
20
20
 
21
21
  ## Wallets
22
22
 
23
- Local wallets stored encrypted in `~/.config/moonpay/wallets.json`. Keys never leave the machine.
23
+ Local wallets stored encrypted in `~/.config/moonpay/wallets/`, one file per wallet, under a random passphrase held in your OS keychain. Keys never leave the machine. Record your mnemonic somewhere off the machine — it is the only recovery path if the keychain entry is lost.
24
+
25
+ First-time key creation waits for any other initializer to finish. If it times out, stop all MoonPay CLI processes using that configuration directory before removing only the `.lock` file named in the error, then retry. Locks are never reclaimed automatically: a slow keychain prompt must not allow a second process to replace the key. Do not remove the key file itself. If a fallback key file is unreadable or empty, restore access to the original file or recover it from a backup; the CLI refuses to generate a replacement.
24
26
 
25
27
  ```bash
26
28
  mp wallet create --name "main"
@@ -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-PG4E65EW.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{g as Ut,h as Gt,k as Wt,n as Et,o as Dt,p as Ft,q as Kt}from"./chunk-JMUBF7HA.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};
@@ -0,0 +1,4 @@
1
+ process.noDeprecation = true; import { createRequire as __createRequire } from "module"; const require = __createRequire(import.meta.url);
2
+ import{a as ne,b as _,c as y,d as oe,e as D,i as U,q as se}from"./chunk-JMUBF7HA.js";import{a as re,f as M}from"./chunk-LMDE72OE.js";import{existsSync as I,readFileSync as X,writeFileSync as Ke,renameSync as Z}from"fs";import{join as $}from"path";import{homedir as ke}from"os";import{randomBytes as Ee}from"crypto";import*as s from"@open-wallet-standard/core";import Q from"bs58";_();import{z as a}from"zod";var O={"eip155:1":"ethereum","solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp":"solana","bip122:000000000019d6689c085ae165831e93":"bitcoin","tron:mainnet":"tron","ton:mainnet":"ton","fil:mainnet":"filecoin"};function J(e){return e==="evm"?"ethereum":e}var R=a.object({solana:a.string().optional(),ethereum:a.string().optional(),bitcoin:a.string().optional(),tron:a.string().optional(),ton:a.string().optional(),filecoin:a.string().optional()}),ie=["base","arbitrum","robinhood","polygon","optimism","bnb","bnb-testnet","avalanche","tempo","tempo-moderato","ethereum-sepolia","base-sepolia","arbitrum-sepolia","polygon-amoy"];function je(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 ie)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 ae=a.object({name:a.string(),type:a.literal("hd"),mnemonic:a.string().optional(),addresses:R,createdAt:a.string()}),le=a.object({name:a.string(),type:a.literal("imported"),chain:a.string().optional(),privateKey:a.string().optional(),addresses:R,createdAt:a.string()}),N=a.enum(["ledger"]),C=a.object({name:a.string(),type:a.literal("hardware"),device:N,addresses:R,createdAt:a.string()}),ze=a.discriminatedUnion("type",[ae,le,C]),Ye=a.object({name:a.string(),type:a.enum(["hd","imported","hardware"]),device:N.optional(),addresses:a.record(a.string(),a.string()),createdAt:a.string()});import{createHash as j}from"crypto";import{HDKey as E}from"@scure/bip32";import{mnemonicToSeedSync as w}from"@scure/bip39";import{keccak_256 as B}from"@noble/hashes/sha3";import{derivePath as z}from"ed25519-hd-key";import*as Y from"bitcoinjs-lib";import ce from"ecpair";import*as A from"@bitcoinerlab/secp256k1";import{Keypair as de}from"@solana/web3.js";import pe from"bs58";import{WalletContractV5R1 as fe}from"@ton/ton";import{keyPairFromSeed as ue}from"@ton/crypto";import*as V from"@open-wallet-standard/core";var he=ce(A);function q(e,t,r=0){switch(t){case"solana":return ye(e,r);case"ethereum":return me(e,r);case"bitcoin":return ve(e,r);case"tron":return We(e,r);case"ton":return Se(e,r);case"filecoin":return be(e,r);default:throw new Error(`Unsupported key family for derivation: ${t}`)}}function ye(e,t){let r=w(e),n=`m/44'/501'/${t}'/0'`,{key:o}=z(n,Buffer.from(r).toString("hex")),i=de.fromSeed(Uint8Array.from(o));return{privateKey:i.secretKey,address:i.publicKey.toBase58()}}function me(e,t){let r=w(e),n=E.fromMasterSeed(r),o=`m/44'/60'/${t}'/0/0`,i=n.derive(o);if(!i.privateKey)throw new Error("Failed to derive EVM private key");let l=ge(i.publicKey);return{privateKey:i.privateKey,address:l}}function ge(e){let t=A.pointCompress(e,!1),n=B(t.slice(1)).slice(-20),o="0x"+Buffer.from(n).toString("hex");return we(o)}function we(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 ve(e,t){let r=w(e),n=E.fromMasterSeed(r),o=`m/84'/0'/${t}'/0/0`,i=n.derive(o);if(!i.privateKey)throw new Error("Failed to derive Bitcoin private key");let l=he.fromPrivateKey(Buffer.from(i.privateKey)),{address:c}=Y.payments.p2wpkh({pubkey:Buffer.from(l.publicKey)});if(!c)throw new Error("Failed to derive Bitcoin address");return{privateKey:i.privateKey,address:c}}function We(e,t){let r=w(e),n=E.fromMasterSeed(r),o=`m/44'/195'/${t}'/0/0`,i=n.derive(o);if(!i.privateKey)throw new Error("Failed to derive Tron private key");let l=xe(i.publicKey);return{privateKey:i.privateKey,address:l}}function xe(e){let t=A.pointCompress(e,!1),n=B(t.slice(1)).slice(-20),o=Buffer.concat([Buffer.from([65]),Buffer.from(n)]),i=j("sha256").update(o).digest(),l=j("sha256").update(i).digest(),c=Buffer.concat([o,l.slice(0,4)]);return pe.encode(c)}function Se(e,t){let r=w(e),n=`m/44'/607'/${t}'/0'`,{key:o}=z(n,Buffer.from(r).toString("hex")),i=ue(Buffer.from(o)),l=fe.create({publicKey:Buffer.from(i.publicKey)});return{privateKey:i.secretKey,address:l.address.toString({bounceable:!1})}}function be(e,t){let r=w(e),n=E.fromMasterSeed(r),o=`m/44'/461'/${t}'/0/0`,i=n.derive(o);if(!i.privateKey)throw new Error("Failed to derive Filecoin private key");let l=V.deriveAddress(e,"filecoin",t);return{privateKey:i.privateKey,address:l}}se();D();var P=$(ke(),".config","moonpay"),H=$(P,"hardware-wallets.json");function d(){return P}var ee="__reencrypting";function L(e){return/decryption failed|aead/i.test(String(e?.message??e))}function G(e,t,r,n){if(!t.trim().startsWith("{")){s.importWalletMnemonic(e,t,r,null,n);return}let o=JSON.parse(t),i=o.secp256k1??o.ed25519;if(!i)throw new Error("Exported key material carries no usable key.");s.importWalletPrivateKey(e,i,r,n,null,o.ed25519??null,o.secp256k1??null)}function te(e,t,r){try{s.getWallet(e,r)}catch{return}for(let n of[y(),null])try{if(s.exportWallet(e,n,r)===t){s.deleteWallet(e,r);return}}catch{}throw new Error(`Aborted: a wallet named ${JSON.stringify(e)} already exists and holds different keys. Rename or remove it first \u2014 it was left untouched.`)}function Ae(e,t){let r=d(),n=s.exportWallet(e,null,r),o=`${e}${ee}`;te(o,n,r),G(o,n,t,r),s.deleteWallet(e,r);try{s.renameWallet(o,e,r)}catch{G(e,n,t,r),s.deleteWallet(o,r)}}function $e(e){try{return s.getWallet(e,d()),!0}catch{return!1}}function S(e,t){let r=y();try{return t(r)}catch(n){if(!L(n))throw n;try{Ae(e,r)}catch(o){throw L(o)?new Error(`Wallet ${JSON.stringify(e)} could not be decrypted. Its vault passphrase is not this machine's \u2014 restore the keychain entry or set MOONPAY_VAULT_PASSPHRASE.`):o}return t(r)}}function Pe(e){let t={};for(let r of e){let n=O[r.chainId];n&&(t[n]=r.address)}return t}function v(e){return{name:e.name,type:"hd",addresses:Pe(e.accounts),createdAt:e.createdAt}}function m(){if(!I(H))return[];try{return(JSON.parse(X(H,"utf-8")).wallets??[]).map(t=>C.parse(t))}catch{return[]}}function Fe(e,t){U();let r=$(P,`.tmp.${Ee(4).toString("hex")}`);Ke(r,JSON.stringify(t,null,2),{mode:384}),Z(r,e)}function b(e){Fe(H,{wallets:e})}var x=$(P,"wallets.json");function T(){if(I(x)){process.stderr.write(`Migrating legacy wallets...
3
+ `);let{migrated:e,skipped:t}=Re();process.stderr.write(`Migrated ${e} wallet(s), skipped ${t}.
4
+ `)}}function Re(){if(!I(x))throw new Error("No legacy wallets.json found \u2014 nothing to migrate.");let{getEncryptionKey:e}=(D(),M(oe)),{decrypt:t,encryptedFileSchema:r}=(_(),M(ne)),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(X(x,"utf-8")),i=r.parse(o),l=t(i,n),c=JSON.parse(l).wallets??[],f=d(),k=y(),g=m(),W=0,u=0;for(let p of c){try{s.getWallet(p.name,f),u++;continue}catch{}if(g.some(h=>h.name===p.name)){u++;continue}if(p.type==="hardware")g.push({name:p.name,type:"hardware",device:p.device,addresses:p.addresses,createdAt:p.createdAt});else if(p.type==="hd"&&p.mnemonic)s.importWalletMnemonic(p.name,p.mnemonic,k,null,f);else if(p.type==="imported"&&p.privateKey){let h=p.privateKey;if(!/^[0-9a-fA-F]+$/.test(h)){let F=Q.decode(h);h=Buffer.from(F.length===64?F.slice(0,32):F).toString("hex")}s.importWalletPrivateKey(p.name,h,k,f,null,h,h)}W++}return g.length>0&&b(g),Z(x,x+".migrated"),{migrated:W,skipped:u}}function Ce(e){T(),K(e);let t=s.createWallet(e,y(),24,d());return v(t)}function Be(e,t){K(e);let r=s.importWalletMnemonic(e,t,y(),null,d());return v(r)}function He(e,t,r){return K(e),v(s.importWalletPrivateKey(e,t,y(),d(),r))}function Ie(){T();let e=[];try{e=s.listWallets(d())}catch{}return[...e.map(r=>v(r)),...m()]}function Te(e){T();let t=d();try{let r=s.getWallet(e,t);return v(r)}catch{}try{for(let r of s.listWallets(t))for(let n of r.accounts)if(n.address===e)return v(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 ht(e){let t=Te(e);if(t)return t;let r=`${e}${ee}`;throw $e(r)?new Error(`Wallet "${e}" not found, but "${r}" exists \u2014 a re-encryption was interrupted. Check that it holds the keys you expect, then rename it to "${e}".`):new Error(`Wallet "${e}" not found`)}function Me(e){try{s.deleteWallet(e,d());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),b(t)}function yt(e,t){if(e===t)return;K(t);try{s.getWallet(e,d()),s.renameWallet(e,t,d());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,b(r)}function _e(e){return S(e,t=>s.exportWallet(e,t,d()))}var De="__repairing";function mt(e){let t=d(),r=s.getWallet(e,t),n=r.accounts.length,o=u=>({name:e,before:n,after:n,repaired:!1,reason:u}),i=_e(e);if(i.trim().startsWith("{"))return o("imported from a private key \u2014 repair rebuilds from a mnemonic");let l=y(),c=`${e}${De}`;te(c,i,t);let f=s.importWalletMnemonic(c,i,l,null,t),k=new Set(f.accounts.map(u=>`${u.chainId}=${u.address}`)),g=r.accounts.filter(u=>!k.has(`${u.chainId}=${u.address}`));if(g.length>0)throw s.deleteWallet(c,t),new Error(`Repair aborted for ${JSON.stringify(e)}: re-derivation did not reproduce ${g.length} existing address(es). The wallet was left untouched.`);if(f.accounts.length<=n)return s.deleteWallet(c,t),o("already has every account this vault derives");s.deleteWallet(e,t);let W=f.accounts.length;try{s.renameWallet(c,e,t)}catch{W=s.importWalletMnemonic(e,i,l,null,t).accounts.length,s.deleteWallet(c,t)}return{name:e,before:n,after:W,repaired:!0,reason:null}}function Ue(e){K(e.name);let t=m();t.push(e),b(t)}function gt(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,b(r)}function wt(e,t,r){return S(e,n=>s.signTransaction(e,t,r,n,null,d()))}function vt(e,t,r,n){return S(e,o=>s.signMessage(e,t,r,o,n??null,null,d()))}function Wt(e,t,r){return S(e,n=>s.signTypedData(e,t,r,n,null,d()))}async function xt(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-GGELOIUF.js"),n=await r.chain.retrieve({chain:t}),o=J(n.keyFamily),i=S(e.name,f=>s.exportWallet(e.name,f,d()));if(i.includes(" "))return q(i,o);let l;if(i.startsWith("{")){let f=JSON.parse(i);l=o==="solana"||o==="ton"?f.ed25519:f.secp256k1}else l=i;let c=Uint8Array.from(Buffer.from(l,"hex"));if(o==="solana"&&c.length===32){let f=re("tweetnacl");c=Uint8Array.from(f.sign.keyPair.fromSeed(c).secretKey)}return{privateKey:c,address:e.addresses[o]??""}}var St=Ie,bt=Me;function Kt(e){if(e.type==="hardware"){Ue(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")}He(e.name,t,"solana");return}Ce(e.name)}function K(e){try{throw s.getWallet(e,d()),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{J as a,R as b,je as c,N as d,Ye as e,q as f,d as g,Re as h,Ce as i,Be as j,He as k,Ie as l,Te as m,ht as n,Me as o,yt as p,_e as q,mt as r,Ue as s,gt as t,wt as u,vt as v,Wt as w,xt as x,St as y,bt as z,Kt as A};
@@ -0,0 +1,6 @@
1
+ process.noDeprecation = true; import { createRequire as __createRequire } from "module"; const require = __createRequire(import.meta.url);
2
+ import{b as m,d as v}from"./chunk-LMDE72OE.js";var ce={};v(ce,{decrypt:()=>T,encrypt:()=>_,encryptedFileSchema:()=>C});import{randomBytes as R,scryptSync as P,createCipheriv as ie,createDecipheriv as ae}from"crypto";import{z as i}from"zod";function _(e,t){let n=R(32),r=P(t,n,$,{N:F,r:D,p:U,maxmem:M}),s=R(12),a=ie("aes-256-gcm",r,s),k=Buffer.concat([a.update(e,"utf8"),a.final()]);return{encryption:{cipher:"aes-256-gcm",kdf:"scrypt",kdfparams:{n:F,r:D,p:U},salt:n.toString("base64"),iv:s.toString("base64"),tag:a.getAuthTag().toString("base64")},data:k.toString("base64")}}function T(e,t){let{salt:n,iv:r,tag:s,kdfparams:a}=e.encryption,k=P(t,Buffer.from(n,"base64"),$,{N:a.n,r:a.r,p:a.p,maxmem:M}),w=ae("aes-256-gcm",k,Buffer.from(r,"base64"),{authTagLength:16});return w.setAuthTag(Buffer.from(s,"base64")),Buffer.concat([w.update(Buffer.from(e.data,"base64")),w.final()]).toString("utf8")}var F,D,U,$,M,C,K=m(()=>{"use strict";F=2**18,D=8,U=1,$=32,M=512*1024*1024,C=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 ue}from"fs";import{join as fe}from"path";import{homedir as le}from"os";function ye(){if(f!==void 0)return f;try{f=JSON.parse(ue(fe(le(),".config","moonpay","consent.json"),"utf-8")).agentId??null}catch{f=null}return f??null}function he(){return process.env.OPENCLAW_SHELL?"openclaw":process.env.CLAUDECODE?"claude-code":process.env.CODEX_CI?"codex":process.env.GEMINI_CLI?"gemini-cli":"human"}function V(){let e={"Content-Type":"application/json",[de]:pe,[me]:he()},t=ye();return t&&(e[ge]=t),e}var pe,de,ge,f,me,Y=m(()=>{"use strict";pe="1.96.5",de="X-CLI-Version",ge="X-Agent-Id";me="X-Agent"});import*as o from"fs";import*as B from"os";import*as g from"path";function c(){o.existsSync(p)||o.mkdirSync(p,{recursive:!0,mode:448})}function H(e,t,n){let r=e+`.tmp.${process.pid}`;o.writeFileSync(r,t,{encoding:"utf-8",mode:n}),o.renameSync(r,e)}function Ee(){c();try{let e=o.openSync(l,o.constants.O_CREAT|o.constants.O_EXCL|o.constants.O_WRONLY,384);o.writeSync(e,JSON.stringify({pid:process.pid,ts:Date.now()})),o.closeSync(e)}catch(e){if(e.code!=="EEXIST")throw e;try{let t=JSON.parse(o.readFileSync(l,"utf-8"));if(Date.now()-t.ts<Se)return null}catch{}try{o.unlinkSync(l)}catch{}try{let t=o.openSync(l,o.constants.O_CREAT|o.constants.O_EXCL|o.constants.O_WRONLY,384);o.writeSync(t,JSON.stringify({pid:process.pid,ts:Date.now()})),o.closeSync(t)}catch{return null}}return()=>{try{o.unlinkSync(l)}catch{}}}function J(){if(!o.existsSync(b))return null;try{let e=JSON.parse(o.readFileSync(b,"utf-8"));return e.baseUrl?e:null}catch{return null}}function et(){let e=J();return e||(we(O),O)}function h(){if(!o.existsSync(d))return null;let e=x();if(!e)return null;try{let t=JSON.parse(o.readFileSync(d,"utf-8")),n=C.parse(t),r=T(n,e),s=JSON.parse(r);return!s.accessToken||!s.baseUrl?null:s}catch{return null}}function ke(e){let t=N(),n=_(JSON.stringify(e),t);c(),H(d,JSON.stringify(n,null,2),384)}function we(e){c(),H(b,JSON.stringify(e,null,2),384)}function tt(){o.existsSync(d)&&o.unlinkSync(d)}function nt(){let e=J(),t=h();return e?.baseUrl??t?.baseUrl??O.baseUrl}async function Ce(e,t,n){let r=await fetch(`${e}/api/tools/${encodeURIComponent(t)}`,{method:"POST",signal:AbortSignal.timeout(15e3),headers:V(),body:JSON.stringify(n)}),s=await r.json();if(!r.ok){let a=s;throw new Error(a?.error??`${t} failed (${r.status})`)}return s}async function _e(e){if(!e.refreshToken)throw new Error("No refresh token available");let t=Ee();if(!t){await new Promise(r=>setTimeout(r,2e3));let n=h();if(n&&n.expiresAt>Date.now())return n;throw new Error("Token refresh failed (concurrent refresh in progress)")}try{let n=h();if(n&&n.expiresAt>Date.now()+6e4)return n;let r=await Ce(e.baseUrl,"refresh",{refreshToken:e.refreshToken}),s={accessToken:r.accessToken,refreshToken:r.refreshToken,expiresAt:r.expiresAt*1e3,baseUrl:e.baseUrl};return ke(s),s}finally{t()}}async function rt(){let e=h();if(!e)return null;if(Date.now()>=e.expiresAt-Te){if(e.refreshToken)try{return(await _e(e)).accessToken}catch{return null}return null}return e.accessToken}var p,b,d,l,O,Se,Te,X=m(()=>{"use strict";K();j();Y();p=g.join(B.homedir(),".config","moonpay"),b=g.join(p,"config.json"),d=g.join(p,"credentials.json"),l=g.join(p,".credentials.lock"),O={baseUrl:"https://agents.moonpay.com"};Se=3e4;Te=300*1e3});var Be={};v(Be,{ensureEncryptionKey:()=>N,ensureVaultPassphrase:()=>je,getEncryptionKey:()=>x});import{execFileSync as S}from"child_process";import{randomBytes as W}from"crypto";import{readFileSync as z,writeFileSync as q,unlinkSync as be}from"fs";import{homedir as Oe,platform as Q}from"os";import{join as xe}from"path";function A(e){let t=e?.status;return typeof t=="number"?t:null}function Ie(e,t){S("security",["add-generic-password","-s",u,"-a",e,"-w"],{input:`${t}
3
+ ${t}
4
+ `,stdio:["pipe","ignore","ignore"]})}function Le(e){try{let t=S("security",["find-generic-password","-s",u,"-a",e,"-w"],{encoding:"utf-8",stdio:["ignore","pipe","pipe"]}).trim();return t?{state:"found",value:t}:{state:"absent"}}catch(t){return ee(t)?{state:"unavailable"}:A(t)===Ne?{state:"absent"}:{state:"error",detail:`security exited ${A(t)??"abnormally"}`}}}function ve(e,t){S("secret-tool",["store",`--label=${u}`,"service",u,"account",e],{input:t,stdio:["pipe","ignore","ignore"]})}function te(e){try{let t=S("secret-tool",["lookup","service",u,"account",e],{encoding:"utf-8",stdio:["ignore","pipe","pipe"]}).trim();return t?{state:"found",value:t}:{state:"absent"}}catch(t){if(ee(t))return{state:"unavailable"};let n=String(t?.stderr??"").trim();return n?{state:"error",detail:n.split(`
5
+ `)[0]}:{state:"absent"}}}function Re(e,t){c();try{return q(E(e),t,{encoding:"utf-8",mode:384,flag:"wx"}),t}catch(n){if(n?.code!=="EEXIST")throw n;let r=ne(e);if(!r)throw n;return r}}function ne(e){let t=E(e),n="the file is empty";try{let r=z(t,"utf-8").trim();if(r)return r}catch(r){let s=r?.code;if(s==="ENOENT")return null;n=typeof s=="string"?s:"read failed"}throw new Error(`The fallback key at ${t} could not be read (${n}). Refusing to generate a replacement, because data encrypted under the existing key would stop decrypting. Restore the key file and access to it, or set ${y[e]} to the existing key.`)}function G(e){return new Error(`The OS keychain already holds an entry for ${u}/${e} but it could not be read. Unlock the keychain and retry, or set ${y[e]}.`)}function Fe(e,t){let n=Q();if(n!=="darwin"&&n!=="linux")return!1;if(n==="linux"&&te(e).state!=="absent")throw G(e);try{return n==="darwin"?Ie(e,t):ve(e,t),!0}catch(r){if(A(r)===Ae)throw G(e);return!1}}function De(e){let t=Q();return t==="darwin"?Le(e):t==="linux"?te(e):{state:"unavailable"}}function L(e){let t=process.env[y[e]];if(t)return{state:"found",value:t};let n=De(e);if(n.state==="found"||n.state==="error")return n;let r=ne(e);return r?{state:"found",value:r}:n}function re(e,t,n){return new Error(`${t} could not be read from the OS keychain (${n}). Refusing to generate a replacement, because wallets already encrypted under the existing one would stop decrypting. Unlock the keychain and retry, or set ${y[e]}.`)}function Pe(){let e=Number(process.env.MOONPAY_VAULT_LOCK_TIMEOUT_MS);return Number.isFinite(e)&&e>0?e:12e4}function $e(e){Atomics.wait(new Int32Array(new SharedArrayBuffer(4)),0,0,e)}function oe(e){return`${E(e)}.lock`}function Me(e){let t=oe(e),n=`${process.pid}:${W(8).toString("hex")}`,r=Date.now()+Pe();for(;;)try{return q(t,n,{flag:"wx",mode:384}),n}catch(s){if(s?.code!=="EEXIST")throw s;if(Date.now()>=r)throw new Error(`Timed out waiting for another MoonPay CLI process to initialize the vault passphrase. Stop all MoonPay CLI processes, remove only ${t}, then retry.`);$e(Ue)}}function Ke(e,t){c();let n=Me(e);try{return t()}finally{let r=oe(e);try{z(r,"utf-8")===n&&be(r)}catch{}}}function Ve(e){let t=L(e);return t.state==="found"?t.value:null}function se(e,t){let n=L(e);if(n.state==="found")return n.value;if(n.state==="error")throw re(e,t,n.detail);return Ke(e,()=>Ye(e,t))}function Ye(e,t){let n=L(e);if(n.state==="found")return n.value;if(n.state==="error")throw re(e,t,n.detail);let r=W(32).toString("hex");if(n.state!=="unavailable"&&Fe(e,r))return r;let s=Re(e,r);return process.stderr.write(`Note: Keychain unavailable. ${t} stored in ${E(e)}. A file-backed key sits beside the data it protects, so a copy of ~/.config/moonpay carries both \u2014 set ${y[e]} instead to keep the key out of the vault's storage.
6
+ `),s}function x(){return Ve(I)}function N(){return se(I,"Encryption key")}function je(){return se(Z,"Vault passphrase")}var u,I,Z,y,E,Ne,Ae,ee,Ue,j=m(()=>{"use strict";X();u="moonpay-cli",I="encryption-key",Z="vault-passphrase",y={[I]:"MOONPAY_ENCRYPTION_KEY",[Z]:"MOONPAY_VAULT_PASSPHRASE"},E=e=>xe(Oe(),".config","moonpay",`.${e}`),Ne=44,Ae=45;ee=e=>e?.code==="ENOENT";Ue=50});export{ce as a,K as b,je as c,Be as d,j as e,pe as f,V as g,Y as h,c as i,et as j,h as k,ke as l,tt as m,nt as n,_e as o,rt as p,X as q};