@getpara/user-management-client 1.4.3 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/index.js CHANGED
@@ -1 +1,1002 @@
1
- var te=Object.create;var P=Object.defineProperty;var re=Object.getOwnPropertyDescriptor;var ae=Object.getOwnPropertyNames;var ne=Object.getPrototypeOf,ie=Object.prototype.hasOwnProperty;var oe=(r,e)=>{for(var s in e)P(r,s,{get:e[s],enumerable:!0})},A=(r,e,s,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let a of ae(e))!ie.call(r,a)&&a!==s&&P(r,a,{get:()=>e[a],enumerable:!(t=re(e,a))||t.enumerable});return r};var x=(r,e,s)=>(s=r!=null?te(ne(r)):{},A(e||!r||!r.__esModule?P(s,"default",{value:r,enumerable:!0}):s,r)),le=r=>A(P({},"__esModule",{value:!0}),r);var pe={};oe(pe,{AuthMethod:()=>_,Chain:()=>Z,EmailTheme:()=>V,EncryptorType:()=>k,KeyShareType:()=>N,NON_ED25519:()=>ge,Network:()=>j,OAuthMethod:()=>H,OnRampAsset:()=>Y,OnRampProvider:()=>F,OnRampPurchaseStatus:()=>z,OnRampPurchaseType:()=>Q,PREGEN_IDENTIFIER_TYPES:()=>ye,PasswordStatus:()=>D,PublicKeyStatus:()=>M,PublicKeyType:()=>G,WalletScheme:()=>J,WalletType:()=>X,default:()=>de,extractAuthInfo:()=>ce,extractWalletRef:()=>f,handleResponseError:()=>K,handleResponseSuccess:()=>L,isEmail:()=>$,isExternalWalletAddress:()=>S,isFarcaster:()=>q,isPhone:()=>O,isTelegram:()=>C,isUserId:()=>W,isWalletId:()=>T});module.exports=le(pe);var y=x(require("axios")),w=x(require("qs"));function T(r){return!!r.walletId&&!r.externalWalletAddress}function S(r){return!!r.externalWalletAddress&&!r.walletId}function f(r){if(T(r))return["walletId",r.walletId];if(S(r))return["externalWalletAddress",r.externalWalletAddress];throw new Error("invalid wallet params")}function l(r){return!!r&&r!=="null"&&r!=="undefined"&&r!==""}function $(r){return l(r.email)&&!l(r.phone)&&!l(r.countryCode)&&!l(r.farcasterUsername)&&!l(r.telegramUserId)}function O(r){return l(r.phone)&&l(r.countryCode)&&!l(r.email)&&!l(r.farcasterUsername)&&!l(r.telegramUserId)}function q(r){return l(r.farcasterUsername)&&!l(r.email)&&!l(r.phone)&&!l(r.countryCode)&&!l(r.telegramUserId)}function C(r){return l(r.telegramUserId)&&!l(r.email)&&!l(r.phone)&&!l(r.countryCode)&&!l(r.farcasterUsername)}function W(r){return l(r.userId)&&!l(r.email)&&!l(r.phone)&&!l(r.countryCode)&&!l(r.farcasterUsername)&&!l(r.telegramUserId)}function ce(r,{allowUserId:e=!1,isRequired:s=!1}={}){switch(!0){case $(r):return{auth:{email:r.email},authType:"email",identifier:r.email,publicKeyIdentifier:r.email};case O(r):return{auth:{phone:r.phone,countryCode:r.countryCode},authType:"phone",identifier:`${r.countryCode}${r.phone}`,publicKeyIdentifier:`${r.countryCode}${r.phone}`};case q(r):return{auth:{farcasterUsername:r.farcasterUsername},authType:"farcaster",identifier:r.farcasterUsername,publicKeyIdentifier:`${r.farcasterUsername}-farcaster`};case C(r):return{auth:{telegramUserId:r.telegramUserId},authType:"telegram",identifier:r.telegramUserId,publicKeyIdentifier:`${r.telegramUserId}-telegram`};case(W(r)&&e):return{auth:{userId:r.userId},authType:"userId",identifier:r.userId,publicKeyIdentifier:r.userId};default:if(s)throw new Error("invalid auth object");return}}var E="x-capsule-sid",v="x-para-version",h="x-partner-id",U="X-External-API-Key";function m(r,e,s,t){Error.call(this),Error.captureStackTrace?Error.captureStackTrace(this,this.constructor):this.stack=new Error().stack,this.message=r,this.name="ParaApiError",e&&(this.code=e),s&&(this.status=s),t&&(this.responseURL=t)}var ue=m.prototype;Object.defineProperty(ue,"isParaApiError",{value:!0});var L=r=>{if(r.status===200)return r;throw new m("Invalid status code")},K=r=>{if(r===null)throw new m("Error is null");if(y.default.isAxiosError(r)){let e=r.response?.data??"Unknown error";throw r.code==="ERR_NETWORK"?e="Connection error":r.code==="ERR_CANCELED"&&(e="Connection canceled"),new m(e,r.code,r.response.status,r.request?.responseURL)}throw new m("Unknown error")},b=class{constructor({userManagementHost:e,apiKey:s,partnerId:t,version:a,opts:i,retrieveSessionCookie:o,persistSessionCookie:c}){this.createUser=async e=>(await this.baseRequest.post("/users",e)).data;this.checkUserExists=async e=>await this.baseRequest.get("/users/exists",{params:{...e}});this.verifyTelegram=async e=>(await this.baseRequest.post("/users/telegram",{authObject:e})).data;this.externalWalletLogin=async e=>(await this.baseRequest.post("/users/external-wallets/login",e)).data;this.verifyEmail=async(e,s)=>await this.baseRequest.post(`/users/${e}/verify-email`,s);this.verifyPhone=async(e,s)=>await this.baseRequest.post(`/users/${e}/verify-identifier`,s);this.verifyExternalWallet=async(e,s)=>await this.baseRequest.post(`/users/${e}/external-wallets/verify`,s);this.addSessionPublicKey=async(e,s)=>await this.baseRequest.post(`/users/${e}/biometrics/key`,s);this.getSessionPublicKeys=async e=>await this.baseRequest.get(`/users/${e}/biometrics/keys`);this.getBiometricLocationHints=async e=>(await this.baseRequest.get("/biometrics/location-hints",{params:e})).data.hints;this.getSessionPublicKey=async(e,s)=>await this.baseRequest.get(`/users/${e}/biometrics/${s}`);this.patchSessionPublicKey=async(e,s,t,a)=>await this.baseRequest.patch(`/users/${s}/biometrics/${t}`,a,{headers:{[h]:e}});this.getWebChallenge=async e=>(await this.baseRequest.get("/biometrics/challenge",{params:{...e||{}}})).data;this.touchSession=async e=>await this.baseRequest.post(`/touch?regenerate=${!!e}`);this.sessionOrigin=async e=>(await this.baseRequest.get(`/sessions/${e}/origin`)).data;this.verifyWebChallenge=async(e,s)=>await this.baseRequest.post("/biometrics/verify",s,{headers:{[h]:e}});this.getSessionChallenge=async e=>await this.baseRequest.get(`/users/${e}/biometrics/challenge`);this.verifySessionChallenge=async(e,s)=>await this.baseRequest.post(`/users/${e}/biometrics/verify`,s);this.createWallet=async(e,s)=>(await this.baseRequest.post(`/users/${e}/wallets`,s)).data;this.createPregenWallet=async e=>(await this.baseRequest.post("/wallets/pregen",e)).data;this.getPregenWallets=async(e,s=!1,t)=>(await this.baseRequest.get("/wallets/pregen",{params:{ids:e,expand:s,userId:t}})).data;this.claimPregenWallets=async e=>(await this.baseRequest.post("/wallets/pregen/claim",e)).data;this.sendTransaction=async(e,s,t)=>await this.baseRequest.post(`/users/${e}/wallets/${s}/transactions/send`,t);this.signTransaction=async(e,s,t)=>await this.baseRequest.post(`/users/${e}/wallets/${s}/transactions/sign`,t);this.refreshKeys=async(e,s,t,a,i)=>{let o={oldPartnerId:t,newPartnerId:a,keyShareProtocolId:i};return await this.baseRequest.post(`/users/${e}/wallets/${s}/refresh`,o)};this.updatePregenWallet=async(e,s)=>(await this.baseRequest.patch(`/wallets/pregen/${e}`,s)).data;this.getWallets=async(e,s)=>await this.baseRequest.get(`/users/${e}/wallets${s?`?includePartnerData=${encodeURIComponent(s)}`:""}`);this.getAllWallets=async e=>await this.baseRequest.get(`/users/${e}/all-wallets`);this.setCurrentWalletIds=async(e,s,t=!1,a,i)=>await this.baseRequest.post(`/users/${e}/wallets/set`,{walletIds:s,needsWallet:t,sessionLookupId:a,newDeviceSessionLookupId:i});this.login=async e=>{let s=e;return await this.baseRequest.post("/login",s)};this.verifyLogin=async e=>{let s={verificationCode:e};return await this.baseRequest.post("/login/verify-email",s)};this.logout=async()=>await this.baseRequest.get("/logout");this.recoveryVerification=async(e,s)=>{let t={email:e,verificationCode:s};return await this.baseRequest.post("/recovery/verification",t)};this.recoveryInit=async e=>{let s={email:e};return await this.baseRequest.post("/recovery",s)};this.preSignMessage=async(e,s,t,a,i)=>{let o={message:t,scheme:a,cosmosSignDoc:i};return(await this.baseRequest.post(`/users/${e}/wallets/${s}/messages/sign`,o)).data};this.deleteSelf=async e=>await this.baseRequest.delete(`/users/${e}`);this.getParaShare=async(e,s)=>(await this.baseRequest.get(`/users/${e}/wallets/${s}/capsule-share`)).data.share;this.getBackupKit=async e=>await this.baseRequest.get(`/download-backup-kit/${e}`,{responseType:"blob"});this.patchSessionPassword=async(e,s,t,a)=>await this.baseRequest.patch(`/users/${s}/passwords/${t}`,a,{headers:{[h]:e}});let d={...s&&{[U]:s},...t&&{[h]:t}},p={baseURL:e,withCredentials:!0,headers:d};if(o){let n=Array.isArray(y.default.defaults.transformRequest)?y.default.defaults.transformRequest:[y.default.defaults.transformRequest];p.transformRequest=[function(u,g){let R=o();return R&&(g[E]=R),a&&(g[v]=a),u},...n]}if(c){let n=Array.isArray(y.default.defaults.transformResponse)?y.default.defaults.transformResponse:[y.default.defaults.transformResponse];p.transformResponse=[...n,function(u,g,R){return g?.[E]&&c(g[E]),u}]}this.baseRequest=y.default.create(p),i?.useFetchAdapter&&(y.default.defaults.adapter=function(n){return fetch(n.baseURL+n.url.substring(1),{method:n.method,headers:n.headers,body:n.data,credentials:n.withCredentials?"include":void 0}).then(u=>u.text().then(g=>({data:g,status:u.status,statusText:u.statusText,headers:u.headers,config:n,request:fetch}))).catch(function(u){throw u})}),this.baseRequest.interceptors.response.use(L,K)}async uploadKeyshares(e,s,t){let a={keyShares:t};return await this.baseRequest.post(`/users/${e}/wallets/${s}/key-shares`,a)}async uploadUserKeyShares(e,s){let t={keyShares:s};return await this.baseRequest.post(`/users/${e}/key-shares`,t)}async getKeyshare(e,s,t,a){return await this.baseRequest.get(`/users/${e}/wallets/${s}/key-shares?type=${t}${a?`&encryptor=${a}`:""}`)}async getBiometricKeyshares(e,s,t){return await this.baseRequest.get(`/users/${e}/biometrics/key-shares?publicKey=${s}&all=${!!t}`)}async getPasswordKeyshares(e,s,t){return await this.baseRequest.get(`/users/${e}/passwords/key-shares?passwordId=${s}&all=${!!t}`)}async uploadTransmissionKeyshares(e,s){let t={shares:s};return await this.baseRequest.post(`/users/${e}/temporary-shares`,t)}async getTransmissionKeyshares(e,s){return await this.baseRequest.get(`/users/${e}/temporary-shares?sessionLookupId=${s}`)}async resendVerificationCode({userId:e,...s}){return await this.baseRequest.post(`/users/${e}/resend-verification-code`,s)}async resendVerificationCodeByPhone({userId:e,...s}){return await this.baseRequest.post(`/users/${e}/resend-verification-code-by-phone`,s)}async cancelRecoveryAttempt(e){return await this.baseRequest.post("/recovery/cancel",{email:e})}async check2FAStatus(e){return await this.baseRequest.get(`/2fa/users/${e}/check-status`)}async enable2FA(e,s){return await this.baseRequest.post(`/2fa/users/${e}/enable`,{verificationCode:s})}async setup2FA(e){return await this.baseRequest.post(`/2fa/users/${e}/setup`)}async initializeRecovery(e){return await this.baseRequest.post("/recovery/init",{email:e})}async initializeFarcasterLogin(){return await this.baseRequest.post("/auth/farcaster/init")}async getFarcasterAuthStatus(){return await this.baseRequest.post("/auth/farcaster/status")}async initializeRecoveryForPhone(e,s){return await this.baseRequest.post("/recovery/init",{phone:e,countryCode:s})}async finalizeRecovery(e,s){return await this.baseRequest.post(`/recovery/users/${e}/wallets/${s}/finish`)}async recoverUserShares(e,s){return await this.baseRequest.get(`/recovery/users/${e}/wallets/${s}/key-shares?type=USER&encryptor=RECOVERY`)}async verifyEmailForRecovery(e,s){let t={email:e,verificationCode:s};return await this.baseRequest.post("/recovery/verify-email",t)}async verifyPhoneForRecovery(e,s,t){let a={phone:e,countryCode:s,verificationCode:t};return await this.baseRequest.post("/recovery/verify-identifier",a)}async verify2FA(e,s){let t={email:e,verificationCode:s};return await this.baseRequest.post("/2fa/verify",t)}async verify2FAForPhone(e,s,t){let a={phone:e,countryCode:s,verificationCode:t};return await this.baseRequest.post("/2fa/verify",a)}async tempTrasmissionInit(e,s){let t={message:e,userId:s};return await this.baseRequest.post("/temporary-transmissions",t)}async tempTrasmission(e){return await this.baseRequest.get(`/temporary-transmissions/${e}`)}async getPartner(e){return await this.baseRequest.get(`/partners/${e}`)}async acceptScopes(e,s,t){return await this.baseRequest.post(`/users/${e}/wallets/${s}/scopes/accept`,t)}async getPendingTransaction(e,s){return await this.baseRequest.get(`/users/${e}/pending-transactions/${s}`)}async acceptPendingTransaction(e,s){return await this.baseRequest.post(`/users/${e}/pending-transactions/${s}/accept`)}async getOnRampConfig(){return(await this.baseRequest.get("/on-ramp-config")).data}async createOnRampPurchase({userId:e,params:{type:s,walletType:t,address:a,provider:i,networks:o,assets:c,defaultNetwork:d,defaultAsset:p,fiat:n,fiatQuantity:u,testMode:g=!1},...R}){let[ee,I]=f(R),se=ee==="walletId"?`wallets/${I}`:`external-wallets/${I}`;return(await this.baseRequest.post(`/users/${e}/${se}/purchases`,{type:s,provider:i,walletType:t,address:a,networks:o,assets:c,defaultAsset:p,defaultNetwork:d,fiat:n,fiatQuantity:u,testMode:g})).data}async updateOnRampPurchase({userId:e,purchaseId:s,updates:t,...a}){let[i,o]=f(a),c=i==="walletId"?`wallets/${o}`:`external-wallets/${o}`;return(await this.baseRequest.patch(`/users/${e}/${c}/purchases/${s}`,t)).data}async getOnRampPurchase({userId:e,purchaseId:s,...t}){let[a,i]=f(t),o=a==="walletId"?`wallets/${i}`:`external-wallets/${i}`;return await this.baseRequest.get(`/users/${e}/${o}/purchases/${s}`)}async signMoonPayUrl(e,{url:s,type:t,cosmosPrefix:a,testMode:i,walletId:o,externalWalletAddress:c}){let d=o?`wallets/${o}`:`external-wallets/${c}`;return await this.baseRequest.post(`/users/${e}/${d}/moonpay-sign`,{url:s,type:t,cosmosPrefix:a,testMode:i})}async generateOffRampTx(e,{provider:s,chainId:t,contractAddress:a,testMode:i,walletId:o,walletType:c,destinationAddress:d,sourceAddress:p,assetQuantity:n}){return(await this.baseRequest.post(`/users/${e}/wallets/${o}/offramp-generate`,{provider:s,testMode:i,chainId:t,contractAddress:a,walletId:o,walletType:c,destinationAddress:d,sourceAddress:p,assetQuantity:n})).data}async sendOffRampTx(e,{tx:s,signature:t,network:a,walletId:i,walletType:o}){return(await this.baseRequest.post(`/users/${e}/wallets/${i}/offramp-send`,{tx:s,signature:t,network:a,walletType:o})).data}async distributeParaShare({userId:e,walletId:s,...t}){let a=t;return await this.baseRequest.post(`/users/${e}/wallets/${s}/capsule-share/distribute`,a)}async keepSessionAlive(e){return(await this.baseRequest.post(`/users/${e}/session/keep-alive`)).data}async persistRecoveryPublicKeys(e,s){return(await this.baseRequest.post(`/users/${e}/recovery-public-keys`,{publicKeys:s})).data}async getRecoveryPublicKeys(e){return(await this.baseRequest.get(`/users/${e}/recovery-public-keys`)).data}async uploadEncryptedWalletPrivateKey(e,s,t,a,i){let o={encryptedWalletPrivateKey:s,encryptionKeyHash:t,biometricPublicKey:a,passwordId:i};return(await this.baseRequest.post(`/users/${e}/encrypted-wallet-private-keys`,o)).data}async getEncryptedWalletPrivateKeys(e,s){return(await this.baseRequest.get(`/users/${e}/encrypted-wallet-private-keys/${s}`)).data}async getConversionRate(e,s,t){let a={symbol:s,currency:t};return(await this.baseRequest.get(`/chains/${e}/conversion-rate`,{params:a})).data}async getGasEstimate(e,s){let t={totalGasPrice:s};return(await this.baseRequest.get(`/chains/${e}/gas-estimate`,{params:t})).data}async getGasOracle(e){return(await this.baseRequest.get(`/chains/${e}/gas-oracle`)).data}async isRefreshDone(e,s,t,a){let i={};t&&(i.partnerId=t),a&&(i.protocolId=a);let o=w.default.stringify(i);return(await this.baseRequest.get(`/users/${e}/wallets/${s}/refresh-done?${o}`)).data}async deletePendingTransaction(e,s){return(await this.baseRequest.delete(`/users/${e}/pending-transactions/${s}`)).data}async addSessionPasswordPublicKey(e,s){return await this.baseRequest.post(`/users/${e}/passwords/key`,s)}async getSupportedAuthMethods(e){return(await this.baseRequest.get("/users/supported-auth-methods",{params:{...e}})).data}async getPasswords(e){return(await this.baseRequest.get("/users/passwords",{params:{...e}})).data.passwords}async verifyPasswordChallenge(e,s){return await this.baseRequest.post("/passwords/verify",s,{headers:{[h]:e}})}async getEncryptedWalletPrivateKey(e){let s={};s.passwordId=e;let t=w.default.stringify(s);return await this.baseRequest.get(`/encrypted-wallet-private-keys?${t}`)}async getUser(e){return(await this.baseRequest.get(`/users/${e}`)).data}},B=b;var k=(a=>(a.USER="USER",a.RECOVERY="RECOVERY",a.BIOMETRICS="BIOMETRICS",a.PASSWORD="PASSWORD",a))(k||{}),N=(s=>(s.USER="USER",s.RECOVERY="RECOVERY",s))(N||{}),D=(s=>(s.PENDING="PENDING",s.COMPLETE="COMPLETE",s))(D||{}),M=(s=>(s.PENDING="PENDING",s.COMPLETE="COMPLETE",s))(M||{}),G=(s=>(s.MOBILE="MOBILE",s.WEB="WEB",s))(G||{}),H=(c=>(c.GOOGLE="GOOGLE",c.TWITTER="TWITTER",c.APPLE="APPLE",c.DISCORD="DISCORD",c.FACEBOOK="FACEBOOK",c.FARCASTER="FARCASTER",c.TELEGRAM="TELEGRAM",c))(H||{}),_=(s=>(s.PASSWORD="PASSWORD",s.PASSKEY="PASSKEY",s))(_||{});var V=(s=>(s.LIGHT="light",s.DARK="dark",s))(V||{});var F=(t=>(t.RAMP="RAMP",t.STRIPE="STRIPE",t.MOONPAY="MOONPAY",t))(F||{}),Y=(n=>(n.ETHEREUM="ETHEREUM",n.USDC="USDC",n.TETHER="TETHER",n.POLYGON="POLYGON",n.SOLANA="SOLANA",n.ATOM="ATOM",n.CELO="CELO",n.CUSD="CUSD",n.CEUR="CEUR",n.CREAL="CREAL",n))(Y||{}),z=(t=>(t.INITIATED="INITIATED",t.FINISHED="FINISHED",t.CANCELLED="CANCELLED",t))(z||{}),Q=(s=>(s.BUY="BUY",s.SELL="SELL",s))(Q||{});var J=(t=>(t.DKLS="DKLS",t.CGGMP="CGGMP",t.ED25519="ED25519",t))(J||{}),X=(t=>(t.EVM="EVM",t.SOLANA="SOLANA",t.COSMOS="COSMOS",t))(X||{}),Z=(t=>(t.ETH="ETH",t.CELO="CELO",t.MATIC="MATIC",t))(Z||{}),j=(n=>(n.ETHEREUM="ETHEREUM",n.SEPOLIA="SEPOLIA",n.ARBITRUM="ARBITRUM",n.BASE="BASE",n.OPTIMISM="OPTIMISM",n.POLYGON="POLYGON",n.SOLANA="SOLANA",n.COSMOS="COSMOS",n.CELO="CELO",n.NOBLE="NOBLE",n))(j||{}),ye=["EMAIL","PHONE","CUSTOM_ID","DISCORD","TWITTER","TELEGRAM"],ge=["DKLS","CGGMP"];var de=B;0&&(module.exports={AuthMethod,Chain,EmailTheme,EncryptorType,KeyShareType,NON_ED25519,Network,OAuthMethod,OnRampAsset,OnRampProvider,OnRampPurchaseStatus,OnRampPurchaseType,PREGEN_IDENTIFIER_TYPES,PasswordStatus,PublicKeyStatus,PublicKeyType,WalletScheme,WalletType,extractAuthInfo,extractWalletRef,handleResponseError,handleResponseSuccess,isEmail,isExternalWalletAddress,isFarcaster,isPhone,isTelegram,isUserId,isWalletId});
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/index.ts
30
+ var src_exports = {};
31
+ __export(src_exports, {
32
+ AuthMethod: () => AuthMethod,
33
+ Chain: () => Chain,
34
+ EmailTheme: () => EmailTheme,
35
+ EncryptorType: () => EncryptorType,
36
+ KeyShareType: () => KeyShareType,
37
+ NON_ED25519: () => NON_ED25519,
38
+ Network: () => Network,
39
+ OAuthMethod: () => OAuthMethod,
40
+ OnRampAsset: () => OnRampAsset,
41
+ OnRampProvider: () => OnRampProvider,
42
+ OnRampPurchaseStatus: () => OnRampPurchaseStatus,
43
+ OnRampPurchaseType: () => OnRampPurchaseType,
44
+ PREGEN_IDENTIFIER_TYPES: () => PREGEN_IDENTIFIER_TYPES,
45
+ PasswordStatus: () => PasswordStatus,
46
+ PublicKeyStatus: () => PublicKeyStatus,
47
+ PublicKeyType: () => PublicKeyType,
48
+ WalletScheme: () => WalletScheme,
49
+ WalletType: () => WalletType,
50
+ default: () => src_default,
51
+ extractAuthInfo: () => extractAuthInfo,
52
+ extractWalletRef: () => extractWalletRef,
53
+ handleResponseError: () => handleResponseError,
54
+ handleResponseSuccess: () => handleResponseSuccess,
55
+ isEmail: () => isEmail,
56
+ isExternalWalletAddress: () => isExternalWalletAddress,
57
+ isFarcaster: () => isFarcaster,
58
+ isPhone: () => isPhone,
59
+ isTelegram: () => isTelegram,
60
+ isUserId: () => isUserId,
61
+ isWalletId: () => isWalletId
62
+ });
63
+ module.exports = __toCommonJS(src_exports);
64
+
65
+ // src/client.ts
66
+ var import_axios = __toESM(require("axios"));
67
+ var import_qs = __toESM(require("qs"));
68
+
69
+ // src/utils.ts
70
+ function isWalletId(params) {
71
+ return !!params.walletId && !params.externalWalletAddress;
72
+ }
73
+ function isExternalWalletAddress(params) {
74
+ return !!params.externalWalletAddress && !params.walletId;
75
+ }
76
+ function extractWalletRef(params) {
77
+ if (isWalletId(params)) {
78
+ return ["walletId", params.walletId];
79
+ } else if (isExternalWalletAddress(params)) {
80
+ return ["externalWalletAddress", params.externalWalletAddress];
81
+ }
82
+ throw new Error("invalid wallet params");
83
+ }
84
+ function isValid(s) {
85
+ return !!s && s !== "null" && s !== "undefined" && s !== "";
86
+ }
87
+ function isEmail(params) {
88
+ return isValid(params.email) && !isValid(params.phone) && !isValid(params.countryCode) && !isValid(params.farcasterUsername) && !isValid(params.telegramUserId);
89
+ }
90
+ function isPhone(params) {
91
+ return isValid(params.phone) && isValid(params.countryCode) && !isValid(params.email) && !isValid(params.farcasterUsername) && !isValid(params.telegramUserId);
92
+ }
93
+ function isFarcaster(params) {
94
+ return isValid(params.farcasterUsername) && !isValid(params.email) && !isValid(params.phone) && !isValid(params.countryCode) && !isValid(params.telegramUserId);
95
+ }
96
+ function isTelegram(params) {
97
+ return isValid(params.telegramUserId) && !isValid(params.email) && !isValid(params.phone) && !isValid(params.countryCode) && !isValid(params.farcasterUsername);
98
+ }
99
+ function isUserId(params) {
100
+ return isValid(params.userId) && !isValid(params.email) && !isValid(params.phone) && !isValid(params.countryCode) && !isValid(params.farcasterUsername) && !isValid(params.telegramUserId);
101
+ }
102
+ function extractAuthInfo(obj, { allowUserId = false, isRequired = false } = {}) {
103
+ switch (true) {
104
+ case isEmail(obj):
105
+ return { auth: { email: obj.email }, authType: "email", identifier: obj.email, publicKeyIdentifier: obj.email };
106
+ case isPhone(obj):
107
+ return {
108
+ auth: { phone: obj.phone, countryCode: obj.countryCode },
109
+ authType: "phone",
110
+ identifier: `${obj.countryCode}${obj.phone}`,
111
+ publicKeyIdentifier: `${obj.countryCode}${obj.phone}`
112
+ };
113
+ case isFarcaster(obj):
114
+ return {
115
+ auth: { farcasterUsername: obj.farcasterUsername },
116
+ authType: "farcaster",
117
+ identifier: obj.farcasterUsername,
118
+ publicKeyIdentifier: `${obj.farcasterUsername}-farcaster`
119
+ };
120
+ case isTelegram(obj):
121
+ return {
122
+ auth: { telegramUserId: obj.telegramUserId },
123
+ authType: "telegram",
124
+ identifier: obj.telegramUserId,
125
+ publicKeyIdentifier: `${obj.telegramUserId}-telegram`
126
+ };
127
+ case (isUserId(obj) && allowUserId):
128
+ return { auth: { userId: obj.userId }, authType: "userId", identifier: obj.userId, publicKeyIdentifier: obj.userId };
129
+ default:
130
+ if (isRequired) {
131
+ throw new Error("invalid auth object");
132
+ }
133
+ return void 0;
134
+ }
135
+ }
136
+
137
+ // src/consts.ts
138
+ var SESSION_COOKIE_HEADER_NAME = "x-capsule-sid";
139
+ var VERSION_HEADER_NAME = "x-para-version";
140
+ var PARTNER_ID_HEADER_NAME = "x-partner-id";
141
+ var API_KEY_HEADER_NAME = "X-External-API-Key";
142
+
143
+ // src/error.ts
144
+ function ParaApiError(message, code, status, responseURL) {
145
+ Error.call(this);
146
+ if (Error.captureStackTrace) {
147
+ Error.captureStackTrace(this, this.constructor);
148
+ } else {
149
+ this.stack = new Error().stack;
150
+ }
151
+ this.message = message;
152
+ this.name = "ParaApiError";
153
+ code && (this.code = code);
154
+ status && (this.status = status);
155
+ responseURL && (this.responseURL = responseURL);
156
+ }
157
+ var prototype = ParaApiError.prototype;
158
+ Object.defineProperty(prototype, "isParaApiError", { value: true });
159
+
160
+ // src/client.ts
161
+ var handleResponseSuccess = (response) => {
162
+ if (response.status === 200) {
163
+ return response;
164
+ }
165
+ throw new ParaApiError("Invalid status code");
166
+ };
167
+ var handleResponseError = (error) => {
168
+ if (error === null) throw new ParaApiError("Error is null");
169
+ if (import_axios.default.isAxiosError(error)) {
170
+ let message = error.response?.data ?? "Unknown error";
171
+ if (error.code === "ERR_NETWORK") {
172
+ message = "Connection error";
173
+ } else if (error.code === "ERR_CANCELED") {
174
+ message = "Connection canceled";
175
+ }
176
+ throw new ParaApiError(message, error.code, error.response.status, error.request?.responseURL);
177
+ }
178
+ throw new ParaApiError("Unknown error");
179
+ };
180
+ var Client = class {
181
+ constructor({
182
+ userManagementHost,
183
+ apiKey,
184
+ partnerId,
185
+ version,
186
+ opts,
187
+ retrieveSessionCookie,
188
+ persistSessionCookie
189
+ }) {
190
+ this.createUser = async (body) => {
191
+ const res = await this.baseRequest.post(`/users`, body);
192
+ return res.data;
193
+ };
194
+ this.checkUserExists = async (auth) => {
195
+ const res = await this.baseRequest.get("/users/exists", {
196
+ params: { ...auth }
197
+ });
198
+ return res;
199
+ };
200
+ this.verifyTelegram = async (authObject) => {
201
+ return (await this.baseRequest.post("/users/telegram", {
202
+ authObject
203
+ })).data;
204
+ };
205
+ this.externalWalletLogin = async (body) => {
206
+ const res = await this.baseRequest.post(`/users/external-wallets/login`, body);
207
+ return res.data;
208
+ };
209
+ // POST /users/:userId/verify-email
210
+ this.verifyEmail = async (userId, body) => {
211
+ const res = await this.baseRequest.post(`/users/${userId}/verify-email`, body);
212
+ return res;
213
+ };
214
+ this.verifyPhone = async (userId, body) => {
215
+ const res = await this.baseRequest.post(`/users/${userId}/verify-identifier`, body);
216
+ return res;
217
+ };
218
+ this.verifyExternalWallet = async (userId, body) => {
219
+ const res = await this.baseRequest.post(`/users/${userId}/external-wallets/verify`, body);
220
+ return res;
221
+ };
222
+ // POST /users/:userId/biometrics/key
223
+ this.addSessionPublicKey = async (userId, body) => {
224
+ const res = await this.baseRequest.post(`/users/${userId}/biometrics/key`, body);
225
+ return res;
226
+ };
227
+ // GET /users/:userId/biometrics/keys
228
+ this.getSessionPublicKeys = async (userId) => {
229
+ const res = await this.baseRequest.get(`/users/${userId}/biometrics/keys`);
230
+ return res;
231
+ };
232
+ // GET /biometrics/location-hints
233
+ this.getBiometricLocationHints = async (params) => {
234
+ const res = await this.baseRequest.get(`/biometrics/location-hints`, { params });
235
+ return res.data.hints;
236
+ };
237
+ // GET /users/:userId/biometrics/:biometricId
238
+ this.getSessionPublicKey = async (userId, biometricId) => {
239
+ const res = await this.baseRequest.get(`/users/${userId}/biometrics/${biometricId}`);
240
+ return res;
241
+ };
242
+ // PATCH /users/:userId/biometrics/:biometricId
243
+ this.patchSessionPublicKey = async (partnerId, userId, biometricId, body) => {
244
+ const res = await this.baseRequest.patch(`/users/${userId}/biometrics/${biometricId}`, body, {
245
+ headers: {
246
+ [PARTNER_ID_HEADER_NAME]: partnerId
247
+ }
248
+ });
249
+ return res;
250
+ };
251
+ // GET /biometrics/challenge?email&publicKey
252
+ this.getWebChallenge = async (auth) => {
253
+ const res = await this.baseRequest.get("/biometrics/challenge", {
254
+ params: { ...auth || {} }
255
+ });
256
+ return res.data;
257
+ };
258
+ // POST /touch
259
+ this.touchSession = async (regenerate) => {
260
+ const res = await this.baseRequest.post(
261
+ `/touch?regenerate=${!!regenerate}`
262
+ );
263
+ return res;
264
+ };
265
+ // GET /session/origin
266
+ this.sessionOrigin = async (sessionLookupId) => {
267
+ const res = await this.baseRequest.get(`/sessions/${sessionLookupId}/origin`);
268
+ return res.data;
269
+ };
270
+ // POST /biometrics/verify
271
+ this.verifyWebChallenge = async (partnerId, body) => {
272
+ const res = await this.baseRequest.post(`/biometrics/verify`, body, {
273
+ headers: {
274
+ [PARTNER_ID_HEADER_NAME]: partnerId
275
+ }
276
+ });
277
+ return res;
278
+ };
279
+ // GET /users/:userId/biometrics/challenge
280
+ this.getSessionChallenge = async (userId) => {
281
+ const res = await this.baseRequest.get(`/users/${userId}/biometrics/challenge`);
282
+ return res;
283
+ };
284
+ // POST /users/:userId/biometrics/verify
285
+ this.verifySessionChallenge = async (userId, body) => {
286
+ const res = await this.baseRequest.post(`/users/${userId}/biometrics/verify`, body);
287
+ return res;
288
+ };
289
+ // POST /users/:userId/wallets
290
+ this.createWallet = async (userId, body) => {
291
+ const res = await this.baseRequest.post(`/users/${userId}/wallets`, body);
292
+ return res.data;
293
+ };
294
+ // POST /wallets/pregen
295
+ this.createPregenWallet = async (body) => {
296
+ const res = await this.baseRequest.post(`/wallets/pregen`, body);
297
+ return res.data;
298
+ };
299
+ // GET /wallets/pregen?pregenIdentifier={pregenIdentifier}&pregenIdentifierType={pregenIdentifierType}
300
+ this.getPregenWallets = async (pregenIds, isPortal = false, userId) => {
301
+ const res = await this.baseRequest.get("/wallets/pregen", {
302
+ params: { ids: pregenIds, expand: isPortal, userId }
303
+ });
304
+ return res.data;
305
+ };
306
+ // POST /wallets/pregen/claim
307
+ this.claimPregenWallets = async (body) => {
308
+ const res = await this.baseRequest.post(`/wallets/pregen/claim`, body);
309
+ return res.data;
310
+ };
311
+ // POST /users/:userId/wallets/:walletId/transactions/send
312
+ this.sendTransaction = async (userId, walletId, body) => {
313
+ const res = await this.baseRequest.post(`/users/${userId}/wallets/${walletId}/transactions/send`, body);
314
+ return res;
315
+ };
316
+ // functionality changed to only sign transactions and not send them
317
+ // POST /users/:userId/wallets/:walletId/transactions/sign
318
+ this.signTransaction = async (userId, walletId, body) => {
319
+ const res = await this.baseRequest.post(`/users/${userId}/wallets/${walletId}/transactions/sign`, body);
320
+ return res;
321
+ };
322
+ // POST /users/:userId/wallets/:walletId/refresh
323
+ this.refreshKeys = async (userId, walletId, oldPartnerId, newPartnerId, keyShareProtocolId) => {
324
+ const body = { oldPartnerId, newPartnerId, keyShareProtocolId };
325
+ const res = await this.baseRequest.post(`/users/${userId}/wallets/${walletId}/refresh`, body);
326
+ return res;
327
+ };
328
+ // PATCH /wallets/pregen/:walletId
329
+ this.updatePregenWallet = async (walletId, body) => {
330
+ const res = await this.baseRequest.patch(`/wallets/pregen/${walletId}`, body);
331
+ return res.data;
332
+ };
333
+ // GET /users/:userId/wallets
334
+ this.getWallets = async (userId, includePartnerData) => {
335
+ const res = await this.baseRequest.get(
336
+ `/users/${userId}/wallets${includePartnerData ? `?includePartnerData=${encodeURIComponent(includePartnerData)}` : ""}`
337
+ );
338
+ return res;
339
+ };
340
+ // GET /users/:userId/all-wallets
341
+ this.getAllWallets = async (userId) => {
342
+ const res = await this.baseRequest.get(`/users/${userId}/all-wallets`);
343
+ return res;
344
+ };
345
+ // POST /users/:userId/wallets/set
346
+ this.setCurrentWalletIds = async (userId, walletIds, needsWallet = false, sessionLookupId, newDeviceSessionLookupId) => {
347
+ const res = await this.baseRequest.post(`/users/${userId}/wallets/set`, {
348
+ walletIds,
349
+ needsWallet,
350
+ sessionLookupId,
351
+ newDeviceSessionLookupId
352
+ });
353
+ return res;
354
+ };
355
+ // POST /login
356
+ this.login = async (props) => {
357
+ const body = props;
358
+ const res = await this.baseRequest.post("/login", body);
359
+ return res;
360
+ };
361
+ // POST /login
362
+ this.verifyLogin = async (verificationCode) => {
363
+ const body = { verificationCode };
364
+ const res = await this.baseRequest.post("/login/verify-email", body);
365
+ return res;
366
+ };
367
+ // GET /logout
368
+ this.logout = async () => {
369
+ const res = await this.baseRequest.get("/logout");
370
+ return res;
371
+ };
372
+ // POST /recovery/verification
373
+ this.recoveryVerification = async (email, verificationCode) => {
374
+ const body = { email, verificationCode };
375
+ const res = await this.baseRequest.post("/recovery/verification", body);
376
+ return res;
377
+ };
378
+ // POST /recovery
379
+ this.recoveryInit = async (email) => {
380
+ const body = { email };
381
+ const res = await this.baseRequest.post("/recovery", body);
382
+ return res;
383
+ };
384
+ this.preSignMessage = async (userId, walletId, message, scheme, cosmosSignDoc) => {
385
+ const body = { message, scheme, cosmosSignDoc };
386
+ const res = await this.baseRequest.post(`/users/${userId}/wallets/${walletId}/messages/sign`, body);
387
+ return res.data;
388
+ };
389
+ //DELETE /users/:userId
390
+ this.deleteSelf = async (userId) => {
391
+ const res = await this.baseRequest.delete(`/users/${userId}`);
392
+ return res;
393
+ };
394
+ // GET /users/:userId/wallets/:walletId/capsule-share
395
+ this.getParaShare = async (userId, walletId) => {
396
+ const res = await this.baseRequest.get(`/users/${userId}/wallets/${walletId}/capsule-share`);
397
+ return res.data.share;
398
+ };
399
+ // GET /download-backup-kit/:userId
400
+ this.getBackupKit = async (userId) => {
401
+ const res = await this.baseRequest.get(`/download-backup-kit/${userId}`, { responseType: "blob" });
402
+ return res;
403
+ };
404
+ // PATCH /users/:userId/biometrics/:biometricId
405
+ this.patchSessionPassword = async (partnerId, userId, passwordId, body) => {
406
+ const res = await this.baseRequest.patch(`/users/${userId}/passwords/${passwordId}`, body, {
407
+ headers: {
408
+ [PARTNER_ID_HEADER_NAME]: partnerId
409
+ }
410
+ });
411
+ return res;
412
+ };
413
+ const headers = {
414
+ ...apiKey && { [API_KEY_HEADER_NAME]: apiKey },
415
+ ...partnerId && { [PARTNER_ID_HEADER_NAME]: partnerId }
416
+ };
417
+ const axiosConfig = {
418
+ baseURL: userManagementHost,
419
+ withCredentials: true,
420
+ headers
421
+ };
422
+ if (retrieveSessionCookie) {
423
+ const defaultTransformRequest = Array.isArray(import_axios.default.defaults.transformRequest) ? import_axios.default.defaults.transformRequest : [import_axios.default.defaults.transformRequest];
424
+ axiosConfig.transformRequest = [
425
+ function(data, headers2) {
426
+ const currentSessionCookie = retrieveSessionCookie();
427
+ if (currentSessionCookie) {
428
+ headers2[SESSION_COOKIE_HEADER_NAME] = currentSessionCookie;
429
+ }
430
+ if (version) {
431
+ headers2[VERSION_HEADER_NAME] = version;
432
+ }
433
+ return data;
434
+ },
435
+ ...defaultTransformRequest
436
+ ];
437
+ }
438
+ if (persistSessionCookie) {
439
+ const defaultTransformResponse = Array.isArray(import_axios.default.defaults.transformResponse) ? import_axios.default.defaults.transformResponse : [import_axios.default.defaults.transformResponse];
440
+ axiosConfig.transformResponse = [
441
+ ...defaultTransformResponse,
442
+ function(data, headers2, _status) {
443
+ if (headers2?.[SESSION_COOKIE_HEADER_NAME]) {
444
+ persistSessionCookie(headers2[SESSION_COOKIE_HEADER_NAME]);
445
+ }
446
+ return data;
447
+ }
448
+ ];
449
+ }
450
+ this.baseRequest = import_axios.default.create(axiosConfig);
451
+ if (opts?.useFetchAdapter) {
452
+ import_axios.default.defaults.adapter = function(config) {
453
+ return fetch(config.baseURL + config.url.substring(1), {
454
+ method: config.method,
455
+ headers: config.headers,
456
+ body: config.data,
457
+ credentials: config.withCredentials ? "include" : void 0
458
+ }).then(
459
+ (response) => response.text().then((text) => ({
460
+ data: text,
461
+ status: response.status,
462
+ statusText: response.statusText,
463
+ headers: response.headers,
464
+ config,
465
+ request: fetch
466
+ }))
467
+ ).catch(function(reason) {
468
+ throw reason;
469
+ });
470
+ };
471
+ }
472
+ this.baseRequest.interceptors.response.use(handleResponseSuccess, handleResponseError);
473
+ }
474
+ // DEPRECATED: use uploadUserKeyShares instead
475
+ // POST /users/:userId/wallets/:walletId/key-shares
476
+ async uploadKeyshares(userId, walletId, encryptedKeyshares) {
477
+ const body = { keyShares: encryptedKeyshares };
478
+ const res = await this.baseRequest.post(`/users/${userId}/wallets/${walletId}/key-shares`, body);
479
+ return res;
480
+ }
481
+ // POST /users/:userId/key-shares
482
+ async uploadUserKeyShares(userId, encryptedKeyshares) {
483
+ const body = { keyShares: encryptedKeyshares };
484
+ const res = await this.baseRequest.post(`/users/${userId}/key-shares`, body);
485
+ return res;
486
+ }
487
+ // GET /users/:userId/wallets/:walletId/key-shares
488
+ async getKeyshare(userId, walletId, type, encryptor) {
489
+ const res = await this.baseRequest.get(
490
+ `/users/${userId}/wallets/${walletId}/key-shares?type=${type}${encryptor ? `&encryptor=${encryptor}` : ""}`
491
+ );
492
+ return res;
493
+ }
494
+ // GET /users/:userId/biometrics/key-shares
495
+ async getBiometricKeyshares(userId, biometricPublicKey, getAll) {
496
+ const res = await this.baseRequest.get(
497
+ `/users/${userId}/biometrics/key-shares?publicKey=${biometricPublicKey}&all=${!!getAll}`
498
+ );
499
+ return res;
500
+ }
501
+ // GET /users/:userId/key-shares
502
+ async getPasswordKeyshares(userId, passwordId, getAll) {
503
+ const res = await this.baseRequest.get(
504
+ `/users/${userId}/passwords/key-shares?passwordId=${passwordId}&all=${!!getAll}`
505
+ );
506
+ return res;
507
+ }
508
+ // POST '/users/:userId/temporary-shares',
509
+ async uploadTransmissionKeyshares(userId, shares) {
510
+ const body = { shares };
511
+ const res = await this.baseRequest.post(`/users/${userId}/temporary-shares`, body);
512
+ return res;
513
+ }
514
+ // GET /users/:userId/temporary-shares returns { temporaryShares: { userId: string, walletId: string, encryptedShare: string, encryptedKey?: string }[] }
515
+ async getTransmissionKeyshares(userId, sessionLookupId) {
516
+ const res = await this.baseRequest.get(`/users/${userId}/temporary-shares?sessionLookupId=${sessionLookupId}`);
517
+ return res;
518
+ }
519
+ // POST '/users/:userId/resend-verification-code
520
+ async resendVerificationCode({ userId, ...rest }) {
521
+ const res = await this.baseRequest.post(`/users/${userId}/resend-verification-code`, rest);
522
+ return res;
523
+ }
524
+ // POST '/users/:userId/resend-verification-code-by-phone
525
+ async resendVerificationCodeByPhone({ userId, ...rest }) {
526
+ const res = await this.baseRequest.post(`/users/${userId}/resend-verification-code-by-phone`, rest);
527
+ return res;
528
+ }
529
+ // POST recovery/cancel
530
+ async cancelRecoveryAttempt(email) {
531
+ const res = await this.baseRequest.post(`/recovery/cancel`, { email });
532
+ return res;
533
+ }
534
+ // GET '/2fa/users/:userId/check-status'
535
+ async check2FAStatus(userId) {
536
+ const res = await this.baseRequest.get(`/2fa/users/${userId}/check-status`);
537
+ return res;
538
+ }
539
+ // POST '/2fa/users/:userId/enable'
540
+ async enable2FA(userId, verificationCode) {
541
+ const res = await this.baseRequest.post(`/2fa/users/${userId}/enable`, { verificationCode });
542
+ return res;
543
+ }
544
+ // POST '/2fa/users/:userId/setup'
545
+ async setup2FA(userId) {
546
+ const res = await this.baseRequest.post(`/2fa/users/${userId}/setup`);
547
+ return res;
548
+ }
549
+ // POST /recovery/init
550
+ async initializeRecovery(email) {
551
+ const res = await this.baseRequest.post(`/recovery/init`, { email });
552
+ return res;
553
+ }
554
+ // POST /auth/farcaster/init
555
+ async initializeFarcasterLogin() {
556
+ const res = await this.baseRequest.post(`/auth/farcaster/init`);
557
+ return res;
558
+ }
559
+ // POST /auth/farcaster/status
560
+ async getFarcasterAuthStatus() {
561
+ const res = await this.baseRequest.post(`/auth/farcaster/status`);
562
+ return res;
563
+ }
564
+ // POST /recovery/init
565
+ async initializeRecoveryForPhone(phone, countryCode) {
566
+ const res = await this.baseRequest.post(`/recovery/init`, { phone, countryCode });
567
+ return res;
568
+ }
569
+ // POST /recovery/users/:userId/wallets/:walletId/finish
570
+ async finalizeRecovery(userId, walletId) {
571
+ const res = await this.baseRequest.post(`/recovery/users/${userId}/wallets/${walletId}/finish`);
572
+ return res;
573
+ }
574
+ // GET /recovery/users/:userId/wallets/:walletId/key-shares
575
+ async recoverUserShares(userId, walletId) {
576
+ const res = await this.baseRequest.get(`/recovery/users/${userId}/wallets/${walletId}/key-shares?type=USER&encryptor=RECOVERY`);
577
+ return res;
578
+ }
579
+ // POST /recovery/verify-email
580
+ async verifyEmailForRecovery(email, verificationCode) {
581
+ const body = { email, verificationCode };
582
+ const res = await this.baseRequest.post(`/recovery/verify-email`, body);
583
+ return res;
584
+ }
585
+ // POST /recovery/verify-identifier
586
+ async verifyPhoneForRecovery(phone, countryCode, verificationCode) {
587
+ const body = { phone, countryCode, verificationCode };
588
+ const res = await this.baseRequest.post(`/recovery/verify-identifier`, body);
589
+ return res;
590
+ }
591
+ // POST /2fa/verify
592
+ async verify2FA(email, verificationCode) {
593
+ const body = { email, verificationCode };
594
+ const res = await this.baseRequest.post("/2fa/verify", body);
595
+ return res;
596
+ }
597
+ // POST /2fa/phone/verify
598
+ async verify2FAForPhone(phone, countryCode, verificationCode) {
599
+ const body = { phone, countryCode, verificationCode };
600
+ const res = await this.baseRequest.post("/2fa/verify", body);
601
+ return res;
602
+ }
603
+ async tempTrasmissionInit(message, userId) {
604
+ const body = { message, userId };
605
+ const res = await this.baseRequest.post("/temporary-transmissions", body);
606
+ return res;
607
+ }
608
+ async tempTrasmission(id) {
609
+ const res = await this.baseRequest.get(`/temporary-transmissions/${id}`);
610
+ return res;
611
+ }
612
+ async getPartner(partnerId) {
613
+ const res = await this.baseRequest.get(`/partners/${partnerId}`);
614
+ return res;
615
+ }
616
+ async acceptScopes(userId, walletId, body) {
617
+ const res = await this.baseRequest.post(`/users/${userId}/wallets/${walletId}/scopes/accept`, body);
618
+ return res;
619
+ }
620
+ async getPendingTransaction(userId, pendingTransactionId) {
621
+ const res = await this.baseRequest.get(`/users/${userId}/pending-transactions/${pendingTransactionId}`);
622
+ return res;
623
+ }
624
+ async acceptPendingTransaction(userId, pendingTransactionId) {
625
+ const res = await this.baseRequest.post(`/users/${userId}/pending-transactions/${pendingTransactionId}/accept`);
626
+ return res;
627
+ }
628
+ async getOnRampConfig() {
629
+ const res = await this.baseRequest.get(`/on-ramp-config`);
630
+ return res.data;
631
+ }
632
+ async createOnRampPurchase({
633
+ userId,
634
+ params: {
635
+ type,
636
+ walletType,
637
+ address,
638
+ provider,
639
+ networks,
640
+ assets,
641
+ defaultNetwork,
642
+ defaultAsset,
643
+ fiat,
644
+ fiatQuantity,
645
+ testMode = false
646
+ },
647
+ ...params
648
+ }) {
649
+ const [key, identifier] = extractWalletRef(params);
650
+ const walletString = key === "walletId" ? `wallets/${identifier}` : `external-wallets/${identifier}`;
651
+ const res = await this.baseRequest.post(`/users/${userId}/${walletString}/purchases`, {
652
+ type,
653
+ provider,
654
+ walletType,
655
+ address,
656
+ networks,
657
+ assets,
658
+ defaultAsset,
659
+ defaultNetwork,
660
+ fiat,
661
+ fiatQuantity,
662
+ testMode
663
+ });
664
+ return res.data;
665
+ }
666
+ async updateOnRampPurchase({
667
+ userId,
668
+ purchaseId,
669
+ updates,
670
+ ...params
671
+ }) {
672
+ const [key, identifier] = extractWalletRef(params);
673
+ const walletString = key === "walletId" ? `wallets/${identifier}` : `external-wallets/${identifier}`;
674
+ const res = await this.baseRequest.patch(
675
+ `/users/${userId}/${walletString}/purchases/${purchaseId}`,
676
+ updates
677
+ );
678
+ return res.data;
679
+ }
680
+ async getOnRampPurchase({
681
+ userId,
682
+ purchaseId,
683
+ ...params
684
+ }) {
685
+ const [key, identifier] = extractWalletRef(params);
686
+ const walletString = key === "walletId" ? `wallets/${identifier}` : `external-wallets/${identifier}`;
687
+ const res = await this.baseRequest.get(`/users/${userId}/${walletString}/purchases/${purchaseId}`);
688
+ return res;
689
+ }
690
+ async signMoonPayUrl(userId, {
691
+ url,
692
+ type,
693
+ cosmosPrefix,
694
+ testMode,
695
+ walletId,
696
+ externalWalletAddress
697
+ }) {
698
+ const walletString = walletId ? `wallets/${walletId}` : `external-wallets/${externalWalletAddress}`;
699
+ const res = await this.baseRequest.post(`/users/${userId}/${walletString}/moonpay-sign`, {
700
+ url,
701
+ type,
702
+ cosmosPrefix,
703
+ testMode
704
+ });
705
+ return res;
706
+ }
707
+ async generateOffRampTx(userId, {
708
+ provider,
709
+ chainId,
710
+ contractAddress,
711
+ testMode,
712
+ walletId,
713
+ walletType,
714
+ destinationAddress,
715
+ sourceAddress,
716
+ assetQuantity
717
+ }) {
718
+ const res = await this.baseRequest.post(`/users/${userId}/wallets/${walletId}/offramp-generate`, {
719
+ provider,
720
+ testMode,
721
+ chainId,
722
+ contractAddress,
723
+ walletId,
724
+ walletType,
725
+ destinationAddress,
726
+ sourceAddress,
727
+ assetQuantity
728
+ });
729
+ return res.data;
730
+ }
731
+ async sendOffRampTx(userId, {
732
+ tx,
733
+ signature,
734
+ network,
735
+ walletId,
736
+ walletType
737
+ }) {
738
+ const res = await this.baseRequest.post(`/users/${userId}/wallets/${walletId}/offramp-send`, {
739
+ tx,
740
+ signature,
741
+ network,
742
+ walletType
743
+ });
744
+ return res.data;
745
+ }
746
+ async distributeParaShare({
747
+ userId,
748
+ walletId,
749
+ ...rest
750
+ }) {
751
+ const body = rest;
752
+ const res = await this.baseRequest.post(`/users/${userId}/wallets/${walletId}/capsule-share/distribute`, body);
753
+ return res;
754
+ }
755
+ async keepSessionAlive(userId) {
756
+ const res = await this.baseRequest.post(`/users/${userId}/session/keep-alive`);
757
+ return res.data;
758
+ }
759
+ async persistRecoveryPublicKeys(userId, publicKeys) {
760
+ const res = await this.baseRequest.post(`/users/${userId}/recovery-public-keys`, { publicKeys });
761
+ return res.data;
762
+ }
763
+ async getRecoveryPublicKeys(userId) {
764
+ const res = await this.baseRequest.get(`/users/${userId}/recovery-public-keys`);
765
+ return res.data;
766
+ }
767
+ async uploadEncryptedWalletPrivateKey(userId, encryptedWalletPrivateKey, encryptionKeyHash, biometricPublicKey, passwordId) {
768
+ const body = { encryptedWalletPrivateKey, encryptionKeyHash, biometricPublicKey, passwordId };
769
+ const res = await this.baseRequest.post(`/users/${userId}/encrypted-wallet-private-keys`, body);
770
+ return res.data;
771
+ }
772
+ async getEncryptedWalletPrivateKeys(userId, encryptionKeyHash) {
773
+ const res = await this.baseRequest.get(`/users/${userId}/encrypted-wallet-private-keys/${encryptionKeyHash}`);
774
+ return res.data;
775
+ }
776
+ async getConversionRate(chainId, symbol, currency) {
777
+ const params = { symbol, currency };
778
+ const res = await this.baseRequest.get(`/chains/${chainId}/conversion-rate`, { params });
779
+ return res.data;
780
+ }
781
+ async getGasEstimate(chainId, totalGasPrice) {
782
+ const params = { totalGasPrice };
783
+ const res = await this.baseRequest.get(`/chains/${chainId}/gas-estimate`, { params });
784
+ return res.data;
785
+ }
786
+ async getGasOracle(chainId) {
787
+ const res = await this.baseRequest.get(`/chains/${chainId}/gas-oracle`);
788
+ return res.data;
789
+ }
790
+ // GET /users/:userId/wallets/:walletId/refresh-done
791
+ async isRefreshDone(userId, walletId, partnerId, protocolId) {
792
+ const queryParams = {};
793
+ if (partnerId) queryParams["partnerId"] = partnerId;
794
+ if (protocolId) queryParams["protocolId"] = protocolId;
795
+ const query = import_qs.default.stringify(queryParams);
796
+ const res = await this.baseRequest.get(`/users/${userId}/wallets/${walletId}/refresh-done?${query}`);
797
+ return res.data;
798
+ }
799
+ async deletePendingTransaction(userId, pendingTransactionId) {
800
+ const res = await this.baseRequest.delete(`/users/${userId}/pending-transactions/${pendingTransactionId}`);
801
+ return res.data;
802
+ }
803
+ // POST /users/:userId/passwords/key
804
+ async addSessionPasswordPublicKey(userId, body) {
805
+ const res = await this.baseRequest.post(`/users/${userId}/passwords/key`, body);
806
+ return res;
807
+ }
808
+ async getSupportedAuthMethods(auth) {
809
+ const res = await this.baseRequest.get("/users/supported-auth-methods", {
810
+ params: { ...auth }
811
+ });
812
+ return res.data;
813
+ }
814
+ async getPasswords(auth) {
815
+ const res = await this.baseRequest.get("/users/passwords", {
816
+ params: { ...auth }
817
+ });
818
+ return res.data.passwords;
819
+ }
820
+ // POST /passwords/verify
821
+ async verifyPasswordChallenge(partnerId, body) {
822
+ const res = await this.baseRequest.post(`/passwords/verify`, body, {
823
+ headers: {
824
+ [PARTNER_ID_HEADER_NAME]: partnerId
825
+ }
826
+ });
827
+ return res;
828
+ }
829
+ async getEncryptedWalletPrivateKey(passwordId) {
830
+ const queryParams = {};
831
+ queryParams["passwordId"] = passwordId;
832
+ const query = import_qs.default.stringify(queryParams);
833
+ const res = await this.baseRequest.get(`/encrypted-wallet-private-keys?${query}`);
834
+ return res;
835
+ }
836
+ // GET /users/:userId
837
+ async getUser(userId) {
838
+ const res = await this.baseRequest.get(`/users/${userId}`);
839
+ return res.data;
840
+ }
841
+ };
842
+ var client_default = Client;
843
+
844
+ // src/types/auth.ts
845
+ var EncryptorType = /* @__PURE__ */ ((EncryptorType2) => {
846
+ EncryptorType2["USER"] = "USER";
847
+ EncryptorType2["RECOVERY"] = "RECOVERY";
848
+ EncryptorType2["BIOMETRICS"] = "BIOMETRICS";
849
+ EncryptorType2["PASSWORD"] = "PASSWORD";
850
+ return EncryptorType2;
851
+ })(EncryptorType || {});
852
+ var KeyShareType = /* @__PURE__ */ ((KeyShareType2) => {
853
+ KeyShareType2["USER"] = "USER";
854
+ KeyShareType2["RECOVERY"] = "RECOVERY";
855
+ return KeyShareType2;
856
+ })(KeyShareType || {});
857
+ var PasswordStatus = /* @__PURE__ */ ((PasswordStatus2) => {
858
+ PasswordStatus2["PENDING"] = "PENDING";
859
+ PasswordStatus2["COMPLETE"] = "COMPLETE";
860
+ return PasswordStatus2;
861
+ })(PasswordStatus || {});
862
+ var PublicKeyStatus = /* @__PURE__ */ ((PublicKeyStatus2) => {
863
+ PublicKeyStatus2["PENDING"] = "PENDING";
864
+ PublicKeyStatus2["COMPLETE"] = "COMPLETE";
865
+ return PublicKeyStatus2;
866
+ })(PublicKeyStatus || {});
867
+ var PublicKeyType = /* @__PURE__ */ ((PublicKeyType2) => {
868
+ PublicKeyType2["MOBILE"] = "MOBILE";
869
+ PublicKeyType2["WEB"] = "WEB";
870
+ return PublicKeyType2;
871
+ })(PublicKeyType || {});
872
+ var OAuthMethod = /* @__PURE__ */ ((OAuthMethod2) => {
873
+ OAuthMethod2["GOOGLE"] = "GOOGLE";
874
+ OAuthMethod2["TWITTER"] = "TWITTER";
875
+ OAuthMethod2["APPLE"] = "APPLE";
876
+ OAuthMethod2["DISCORD"] = "DISCORD";
877
+ OAuthMethod2["FACEBOOK"] = "FACEBOOK";
878
+ OAuthMethod2["FARCASTER"] = "FARCASTER";
879
+ OAuthMethod2["TELEGRAM"] = "TELEGRAM";
880
+ return OAuthMethod2;
881
+ })(OAuthMethod || {});
882
+ var AuthMethod = /* @__PURE__ */ ((AuthMethod2) => {
883
+ AuthMethod2["PASSWORD"] = "PASSWORD";
884
+ AuthMethod2["PASSKEY"] = "PASSKEY";
885
+ return AuthMethod2;
886
+ })(AuthMethod || {});
887
+
888
+ // src/types/email.ts
889
+ var EmailTheme = /* @__PURE__ */ ((EmailTheme2) => {
890
+ EmailTheme2["LIGHT"] = "light";
891
+ EmailTheme2["DARK"] = "dark";
892
+ return EmailTheme2;
893
+ })(EmailTheme || {});
894
+
895
+ // src/types/onRamp.ts
896
+ var OnRampProvider = /* @__PURE__ */ ((OnRampProvider2) => {
897
+ OnRampProvider2["RAMP"] = "RAMP";
898
+ OnRampProvider2["STRIPE"] = "STRIPE";
899
+ OnRampProvider2["MOONPAY"] = "MOONPAY";
900
+ return OnRampProvider2;
901
+ })(OnRampProvider || {});
902
+ var OnRampAsset = /* @__PURE__ */ ((OnRampAsset2) => {
903
+ OnRampAsset2["ETHEREUM"] = "ETHEREUM";
904
+ OnRampAsset2["USDC"] = "USDC";
905
+ OnRampAsset2["TETHER"] = "TETHER";
906
+ OnRampAsset2["POLYGON"] = "POLYGON";
907
+ OnRampAsset2["SOLANA"] = "SOLANA";
908
+ OnRampAsset2["ATOM"] = "ATOM";
909
+ OnRampAsset2["CELO"] = "CELO";
910
+ OnRampAsset2["CUSD"] = "CUSD";
911
+ OnRampAsset2["CEUR"] = "CEUR";
912
+ OnRampAsset2["CREAL"] = "CREAL";
913
+ return OnRampAsset2;
914
+ })(OnRampAsset || {});
915
+ var OnRampPurchaseStatus = /* @__PURE__ */ ((OnRampPurchaseStatus2) => {
916
+ OnRampPurchaseStatus2["INITIATED"] = "INITIATED";
917
+ OnRampPurchaseStatus2["FINISHED"] = "FINISHED";
918
+ OnRampPurchaseStatus2["CANCELLED"] = "CANCELLED";
919
+ return OnRampPurchaseStatus2;
920
+ })(OnRampPurchaseStatus || {});
921
+ var OnRampPurchaseType = /* @__PURE__ */ ((OnRampPurchaseType2) => {
922
+ OnRampPurchaseType2["BUY"] = "BUY";
923
+ OnRampPurchaseType2["SELL"] = "SELL";
924
+ return OnRampPurchaseType2;
925
+ })(OnRampPurchaseType || {});
926
+
927
+ // src/types/wallet.ts
928
+ var WalletScheme = /* @__PURE__ */ ((WalletScheme2) => {
929
+ WalletScheme2["DKLS"] = "DKLS";
930
+ WalletScheme2["CGGMP"] = "CGGMP";
931
+ WalletScheme2["ED25519"] = "ED25519";
932
+ return WalletScheme2;
933
+ })(WalletScheme || {});
934
+ var WalletType = /* @__PURE__ */ ((WalletType2) => {
935
+ WalletType2["EVM"] = "EVM";
936
+ WalletType2["SOLANA"] = "SOLANA";
937
+ WalletType2["COSMOS"] = "COSMOS";
938
+ return WalletType2;
939
+ })(WalletType || {});
940
+ var Chain = /* @__PURE__ */ ((Chain2) => {
941
+ Chain2["ETH"] = "ETH";
942
+ Chain2["CELO"] = "CELO";
943
+ Chain2["MATIC"] = "MATIC";
944
+ return Chain2;
945
+ })(Chain || {});
946
+ var Network = /* @__PURE__ */ ((Network2) => {
947
+ Network2["ETHEREUM"] = "ETHEREUM";
948
+ Network2["SEPOLIA"] = "SEPOLIA";
949
+ Network2["ARBITRUM"] = "ARBITRUM";
950
+ Network2["BASE"] = "BASE";
951
+ Network2["OPTIMISM"] = "OPTIMISM";
952
+ Network2["POLYGON"] = "POLYGON";
953
+ Network2["SOLANA"] = "SOLANA";
954
+ Network2["COSMOS"] = "COSMOS";
955
+ Network2["CELO"] = "CELO";
956
+ Network2["NOBLE"] = "NOBLE";
957
+ return Network2;
958
+ })(Network || {});
959
+ var PREGEN_IDENTIFIER_TYPES = [
960
+ "EMAIL",
961
+ "PHONE",
962
+ "CUSTOM_ID",
963
+ "DISCORD" /* DISCORD */,
964
+ "TWITTER" /* TWITTER */,
965
+ "TELEGRAM" /* TELEGRAM */
966
+ ];
967
+ var NON_ED25519 = ["DKLS" /* DKLS */, "CGGMP" /* CGGMP */];
968
+
969
+ // src/index.ts
970
+ var src_default = client_default;
971
+ // Annotate the CommonJS export names for ESM import in node:
972
+ 0 && (module.exports = {
973
+ AuthMethod,
974
+ Chain,
975
+ EmailTheme,
976
+ EncryptorType,
977
+ KeyShareType,
978
+ NON_ED25519,
979
+ Network,
980
+ OAuthMethod,
981
+ OnRampAsset,
982
+ OnRampProvider,
983
+ OnRampPurchaseStatus,
984
+ OnRampPurchaseType,
985
+ PREGEN_IDENTIFIER_TYPES,
986
+ PasswordStatus,
987
+ PublicKeyStatus,
988
+ PublicKeyType,
989
+ WalletScheme,
990
+ WalletType,
991
+ extractAuthInfo,
992
+ extractWalletRef,
993
+ handleResponseError,
994
+ handleResponseSuccess,
995
+ isEmail,
996
+ isExternalWalletAddress,
997
+ isFarcaster,
998
+ isPhone,
999
+ isTelegram,
1000
+ isUserId,
1001
+ isWalletId
1002
+ });