@moonpay/cli 0.12.5 → 0.12.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-YCWUFUSB.js → chunk-OOGFUAYE.js} +1 -1
- package/dist/{chunk-5RZNEJ6M.js → chunk-P44YXZ4V.js} +14 -14
- package/dist/index.js +2 -2
- package/dist/ledger-RME3PLAL.js +12 -0
- package/dist/{mcp-VVJO3BGV.js → mcp-VB3TCF7B.js} +1 -1
- package/dist/{store-VYHIZL3G.js → store-BGAIPERP.js} +1 -1
- package/package.json +1 -1
- package/dist/ledger-PQV6HB6Q.js +0 -12
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
process.noDeprecation = true; import { createRequire as __createRequire } from "module"; const require = __createRequire(import.meta.url);
|
|
2
|
-
import{a as C,b as x,c as v,e as R,i as D}from"./chunk-INE4OXJA.js";import{existsSync as De,readFileSync as Ue,writeFileSync as We,renameSync as Le}from"fs";import{join as F}from"path";import{homedir as Pe}from"os";import{randomBytes as Be}from"crypto";import{execFileSync as K,execSync as ae}from"child_process";import{randomBytes as fe}from"crypto";import{existsSync as le,readFileSync as ue,writeFileSync as de}from"fs";import{homedir as pe,platform as B}from"os";import{join as ye}from"path";import*as o from"fs";import*as W from"os";import*as g from"path";import{readFileSync as X}from"fs";import{join as G}from"path";import{homedir as q}from"os";var z="0.12.
|
|
2
|
+
import{a as C,b as x,c as v,e as R,i as D}from"./chunk-INE4OXJA.js";import{existsSync as De,readFileSync as Ue,writeFileSync as We,renameSync as Le}from"fs";import{join as F}from"path";import{homedir as Pe}from"os";import{randomBytes as Be}from"crypto";import{execFileSync as K,execSync as ae}from"child_process";import{randomBytes as fe}from"crypto";import{existsSync as le,readFileSync as ue,writeFileSync as de}from"fs";import{homedir as pe,platform as B}from"os";import{join as ye}from"path";import*as o from"fs";import*as W from"os";import*as g from"path";import{readFileSync as X}from"fs";import{join as G}from"path";import{homedir as q}from"os";var z="0.12.6",Q="X-CLI-Version",Z="X-Agent-Id",u;function ee(){if(u!==void 0)return u;try{u=JSON.parse(X(G(q(),".config","moonpay","consent.json"),"utf-8")).agentId??null}catch{u=null}return u??null}function U(){let e={"Content-Type":"application/json",[Q]:z},r=ee();return r&&(e[Z]=r),e}var p=g.join(W.homedir(),".config","moonpay"),b=g.join(p,"config.json"),y=g.join(p,"credentials.json"),d=g.join(p,".credentials.lock"),A={baseUrl:"https://agents.moonpay.com"};function a(){o.existsSync(p)||o.mkdirSync(p,{recursive:!0,mode:448})}function L(e,r,n){let t=e+`.tmp.${process.pid}`;o.writeFileSync(t,r,{encoding:"utf-8",mode:n}),o.renameSync(t,e)}var re=3e4;function ne(){a();try{let e=o.openSync(d,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 r=JSON.parse(o.readFileSync(d,"utf-8"));if(Date.now()-r.ts<re)return null}catch{}try{o.unlinkSync(d)}catch{}try{let r=o.openSync(d,o.constants.O_CREAT|o.constants.O_EXCL|o.constants.O_WRONLY,384);o.writeSync(r,JSON.stringify({pid:process.pid,ts:Date.now()})),o.closeSync(r)}catch{return null}}return()=>{try{o.unlinkSync(d)}catch{}}}function P(){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 Qe(){let e=P();return e||(oe(A),A)}function w(){if(!o.existsSync(y))return null;let e=m();if(!e)return null;try{let r=JSON.parse(o.readFileSync(y,"utf-8")),n=C.parse(r),t=v(n,e),s=JSON.parse(t);return!s.accessToken||!s.baseUrl?null:s}catch{return null}}function te(e){let r=E(),n=x(JSON.stringify(e),r);a(),L(y,JSON.stringify(n,null,2),384)}function oe(e){a(),L(b,JSON.stringify(e,null,2),384)}function Ze(){o.existsSync(y)&&o.unlinkSync(y)}function er(){let e=P(),r=w();return e?.baseUrl??r?.baseUrl??A.baseUrl}async function se(e,r,n){let t=await fetch(`${e}/api/tools/${encodeURIComponent(r)}`,{method:"POST",signal:AbortSignal.timeout(15e3),headers:U(),body:JSON.stringify(n)}),s=await t.json();if(!t.ok){let i=s;throw new Error(i?.error??`${r} failed (${t.status})`)}return s}async function ie(e){if(!e.refreshToken)throw new Error("No refresh token available");let r=ne();if(!r){await new Promise(t=>setTimeout(t,2e3));let n=w();if(n&&n.expiresAt>Date.now())return n;throw new Error("Token refresh failed (concurrent refresh in progress)")}try{let n=w();if(n&&n.expiresAt>Date.now()+6e4)return n;let t=await se(e.baseUrl,"refresh",{refreshToken:e.refreshToken}),s={accessToken:t.accessToken,refreshToken:t.refreshToken,expiresAt:t.expiresAt*1e3,baseUrl:e.baseUrl};return te(s),s}finally{r()}}var ce=300*1e3;async function rr(){let e=w();if(!e)return null;if(Date.now()>=e.expiresAt-ce){if(e.refreshToken)try{return(await ie(e)).accessToken}catch{return null}return null}return e.accessToken}var f="moonpay-cli",h="encryption-key",k=ye(pe(),".config","moonpay",".encryption-key");function me(e){try{K("security",["delete-generic-password","-s",f,"-a",h],{stdio:"ignore"})}catch{}K("security",["add-generic-password","-s",f,"-a",h,"-w",e],{stdio:"ignore"})}function ge(){try{return K("security",["find-generic-password","-s",f,"-a",h,"-w"],{encoding:"utf-8",stdio:["ignore","pipe","ignore"]}).trim()}catch{return null}}function he(e){ae(`printf '%s' | secret-tool store --label="${f}" service "${f}" account "${h}"`,{input:e,stdio:["pipe","ignore","ignore"]})}function Se(){try{return K("secret-tool",["lookup","service",f,"account",h],{encoding:"utf-8",stdio:["ignore","pipe","ignore"]}).trim()}catch{return null}}function Ce(e){a(),de(k,e,{encoding:"utf-8",mode:384})}function xe(){try{return le(k)&&ue(k,"utf-8").trim()||null}catch{return null}}function ve(e){try{let r=B();return r==="darwin"?(me(e),!0):r==="linux"?(he(e),!0):!1}catch{return!1}}function we(){let e=B();return e==="darwin"?ge():e==="linux"?Se():null}function m(){let e=process.env.MOONPAY_ENCRYPTION_KEY;return e||(we()??xe())}function E(){let e=m();if(e)return e;let r=fe(32).toString("hex");return ve(r)||(Ce(r),process.stderr.write("Note: Keychain unavailable. Encryption key stored in "+k+`
|
|
3
3
|
`)),r}import{createHash as $}from"crypto";import{HDKey as N}from"@scure/bip32";import{mnemonicToSeedSync as _}from"@scure/bip39";import{keccak_256 as J}from"@noble/hashes/sha3";import{derivePath as Ee}from"ed25519-hd-key";import*as j from"bitcoinjs-lib";import Ke from"ecpair";import*as O from"tiny-secp256k1";import{Keypair as ke}from"@solana/web3.js";import _e from"bs58";var Oe=Ke(O);function T(e,r=0){switch(e){case"solana":return`m/44'/501'/${r}'/0'`;case"ethereum":return`m/44'/60'/${r}'/0/0`;case"bitcoin":return`m/84'/0'/${r}'/0/0`;case"tron":return`m/44'/195'/${r}'/0/0`}}function l(e,r,n=0){switch(r){case"solana":return Te(e,n);case"ethereum":return be(e,n);case"bitcoin":return Ie(e,n);case"tron":return Fe(e,n)}}function Sr(e,r=0){return{solana:l(e,"solana",r).address,ethereum:l(e,"ethereum",r).address,bitcoin:l(e,"bitcoin",r).address,tron:l(e,"tron",r).address}}function Te(e,r){let n=_(e),t=T("solana",r),{key:s}=Ee(t,Buffer.from(n).toString("hex")),i=ke.fromSeed(Uint8Array.from(s));return{privateKey:i.secretKey,address:i.publicKey.toBase58()}}function be(e,r){let n=_(e),t=N.fromMasterSeed(n),s=T("ethereum",r),i=t.derive(s);if(!i.privateKey)throw new Error("Failed to derive EVM private key");let c=Ae(i.publicKey);return{privateKey:i.privateKey,address:c}}function Ae(e){let r=O.pointCompress(e,!1),t=H(r.slice(1)).slice(-20),s="0x"+Buffer.from(t).toString("hex");return Ne(s)}function H(e){return J(e)}function Ne(e){let r=e.toLowerCase().replace("0x",""),n=Buffer.from(J(Buffer.from(r,"utf8"))).toString("hex"),t="0x";for(let s=0;s<r.length;s++)t+=parseInt(n[s],16)>=8?r[s].toUpperCase():r[s];return t}function Ie(e,r){let n=_(e),t=N.fromMasterSeed(n),s=T("bitcoin",r),i=t.derive(s);if(!i.privateKey)throw new Error("Failed to derive Bitcoin private key");let c=Oe.fromPrivateKey(Buffer.from(i.privateKey)),{address:S}=j.payments.p2wpkh({pubkey:Buffer.from(c.publicKey)});if(!S)throw new Error("Failed to derive Bitcoin address");return{privateKey:i.privateKey,address:S}}function Fe(e,r){let n=_(e),t=N.fromMasterSeed(n),s=T("tron",r),i=t.derive(s);if(!i.privateKey)throw new Error("Failed to derive Tron private key");let c=Re(i.publicKey);return{privateKey:i.privateKey,address:c}}function Re(e){let r=O.pointCompress(e,!1),t=H(r.slice(1)).slice(-20),s=Buffer.concat([Buffer.from([65]),Buffer.from(t)]),i=$("sha256").update(s).digest(),c=$("sha256").update(i).digest(),S=Buffer.concat([s,c.slice(0,4)]);return _e.encode(S)}import $e from"bs58";var M=F(Pe(),".config","moonpay"),I=F(M,"wallets.json");function V(){if(!De(I))return[];let e=m();if(!e)throw new Error("Encryption key not found. Set MOONPAY_ENCRYPTION_KEY or ensure OS keychain is accessible.");let r=JSON.parse(Ue(I,"utf-8")),n=C.parse(r),t=v(n,e);return(JSON.parse(t).wallets??[]).map(i=>D.parse(i))}function Je(e){let r=E(),n=JSON.stringify({wallets:e}),t=x(n,r);a();let s=F(M,`.wallets.${Be(4).toString("hex")}.tmp`);We(s,JSON.stringify(t,null,2),{mode:384}),Le(s,I)}function Y(e){let r=V();e(r),Je(r)}function je(e){let r=V();for(let n of r){if(n.name===e)return n;for(let t of Object.values(n.addresses))if(t===e)return n}return null}function Ar(e){let r=je(e);if(!r)throw new Error(`Wallet "${e}" not found`);return r}function Nr(e){Y(r=>{if(r.some(n=>n.name===e.name))throw new Error(`Wallet "${e.name}" already exists`);r.push(e)})}function Ir(e){Y(r=>{let n=r.findIndex(t=>t.name===e);if(n===-1)throw new Error(`Wallet "${e}" not found`);r.splice(n,1)})}function Fr(e,r){if(e.type==="hardware")throw new Error(`Wallet "${e.name}" is a hardware wallet. Signing must happen on the device \u2014 use ledgerSignTransaction/ledgerSignMessage instead.`);let n=R[r];if(e.type==="imported"){if(e.chain!==n)throw new Error(`Wallet "${e.name}" was imported for ${e.chain}, cannot sign for ${r}.`);return{privateKey:He(e.privateKey,n),address:e.addresses[n]}}let t=l(e.mnemonic,n);return{privateKey:t.privateKey,address:t.address}}function He(e,r){if(r==="solana")return $e.decode(e);let n=e.startsWith("0x")?e.slice(2):e;return Uint8Array.from(Buffer.from(n,"hex"))}export{z as a,U as b,a as c,Qe as d,w as e,te as f,Ze as g,er as h,se as i,ie as j,rr as k,Sr as l,V as m,Je as n,Y as o,je as p,Ar as q,Nr as r,Ir as s,Fr as t};
|