@crossmint/wallets-sdk 1.4.1 → 1.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (188) hide show
  1. package/dist/api/__tests__/constants.d.cts +1 -1
  2. package/dist/api/__tests__/constants.d.ts +1 -1
  3. package/dist/api/__tests__/test-utils.cjs +1 -1
  4. package/dist/api/__tests__/test-utils.d.cts +1 -1
  5. package/dist/api/__tests__/test-utils.d.ts +1 -1
  6. package/dist/api/__tests__/test-utils.js +1 -1
  7. package/dist/api/client.cjs +1 -1
  8. package/dist/api/client.d.cts +1 -1
  9. package/dist/api/client.d.ts +1 -1
  10. package/dist/api/client.js +1 -1
  11. package/dist/api/index.cjs +1 -1
  12. package/dist/api/index.d.cts +1 -1
  13. package/dist/api/index.d.ts +1 -1
  14. package/dist/api/index.js +1 -1
  15. package/dist/api/types.d.cts +1 -1
  16. package/dist/api/types.d.ts +1 -1
  17. package/dist/chains/chains.cjs +1 -1
  18. package/dist/chains/chains.d.cts +1 -1
  19. package/dist/chains/chains.d.ts +1 -1
  20. package/dist/chains/chains.js +1 -1
  21. package/dist/chunk-2FKIDTGK.js +1 -0
  22. package/dist/{chunk-6QCKGV44.cjs → chunk-2Y3AQN2S.cjs} +1 -1
  23. package/dist/{chunk-7FESCNM4.cjs → chunk-3AVTANVU.cjs} +1 -1
  24. package/dist/chunk-4B5WUVBN.cjs +1 -0
  25. package/dist/{chunk-YK3YZZ5F.cjs → chunk-4OR2XVWE.cjs} +1 -1
  26. package/dist/{chunk-IACFN22W.js → chunk-5G45T3H7.js} +1 -1
  27. package/dist/chunk-5UAALAXV.js +1 -0
  28. package/dist/{chunk-HJPVODRW.cjs → chunk-6562ESCJ.cjs} +1 -1
  29. package/dist/{chunk-5NP5DTTC.cjs → chunk-6O4RMHUQ.cjs} +1 -1
  30. package/dist/{chunk-WDLFZXBG.js → chunk-7M2KPJVJ.js} +1 -1
  31. package/dist/{chunk-SQW56WQT.js → chunk-7VFS3EJT.js} +1 -1
  32. package/dist/{chunk-3ISCHYRJ.js → chunk-ABNALSRA.js} +1 -1
  33. package/dist/{chunk-QTCM42EB.js → chunk-ACI6AVBC.js} +1 -1
  34. package/dist/chunk-CCW5NTUF.js +1 -0
  35. package/dist/{chunk-2SD7X4WK.js → chunk-DKKQWNW2.js} +1 -1
  36. package/dist/chunk-DTGCFFNW.js +0 -0
  37. package/dist/{chunk-7SSRCAY5.js → chunk-FWKQEP6I.js} +1 -1
  38. package/dist/{chunk-2ZRCE5CX.js → chunk-ITE2NCJQ.js} +1 -1
  39. package/dist/{chunk-LFUTA2C4.cjs → chunk-JCNK347W.cjs} +1 -1
  40. package/dist/{chunk-SFXFZ2J5.cjs → chunk-JLTD3KKU.cjs} +1 -1
  41. package/dist/{chunk-YKIPDFOB.cjs → chunk-KFXIIFEJ.cjs} +1 -1
  42. package/dist/{chunk-B2CQ3W4K.js → chunk-LOH2AUJ2.js} +1 -1
  43. package/dist/{chunk-F5NTM2RX.js → chunk-MDINF2FR.js} +1 -1
  44. package/dist/{chunk-UQ72BJGO.cjs → chunk-N3UCY2Y2.cjs} +1 -1
  45. package/dist/{chunk-4KGM7M2B.js → chunk-NBPZ3T3M.js} +1 -1
  46. package/dist/{chunk-SSQAEYUV.cjs → chunk-NXPEGMMQ.cjs} +1 -1
  47. package/dist/{chunk-COSMEPV7.js → chunk-Q2454TBL.js} +1 -1
  48. package/dist/{chunk-I3RWATD5.cjs → chunk-Q4EIDR3A.cjs} +1 -1
  49. package/dist/{chunk-IMF5Z7BC.cjs → chunk-QYWFJC7Q.cjs} +1 -1
  50. package/dist/{chunk-2K5HK56F.js → chunk-R6UUHH3F.js} +1 -1
  51. package/dist/{chunk-VOVJ4RNT.js → chunk-RFWG2QIH.js} +1 -1
  52. package/dist/chunk-RHAM7DUE.cjs +1 -0
  53. package/dist/{chunk-ALHK57YG.cjs → chunk-ROPXBIF4.cjs} +1 -1
  54. package/dist/{chunk-IR7XWJVH.js → chunk-RVECUVVA.js} +1 -1
  55. package/dist/{chunk-J4IMLBTS.cjs → chunk-SFYQFNRC.cjs} +2 -2
  56. package/dist/{chunk-VQ267WBR.cjs → chunk-UMYBTYNJ.cjs} +1 -1
  57. package/dist/{chunk-H7PU3STI.cjs → chunk-UXWIALMX.cjs} +1 -1
  58. package/dist/chunk-YRZHJB2T.cjs +1 -0
  59. package/dist/index.cjs +1 -1
  60. package/dist/index.d.cts +2 -1
  61. package/dist/index.d.ts +2 -1
  62. package/dist/index.js +1 -1
  63. package/dist/logger/index.cjs +1 -1
  64. package/dist/logger/index.js +1 -1
  65. package/dist/logger/init.cjs +1 -1
  66. package/dist/logger/init.js +1 -1
  67. package/dist/sdk.cjs +1 -1
  68. package/dist/sdk.d.cts +1 -1
  69. package/dist/sdk.d.ts +1 -1
  70. package/dist/sdk.js +1 -1
  71. package/dist/signers/device.d.cts +1 -1
  72. package/dist/signers/device.d.ts +1 -1
  73. package/dist/signers/evm-api-key.d.cts +1 -1
  74. package/dist/signers/evm-api-key.d.ts +1 -1
  75. package/dist/signers/evm-external-wallet.d.cts +1 -1
  76. package/dist/signers/evm-external-wallet.d.ts +1 -1
  77. package/dist/signers/external-wallet-signer.d.cts +1 -1
  78. package/dist/signers/external-wallet-signer.d.ts +1 -1
  79. package/dist/signers/index.cjs +1 -1
  80. package/dist/signers/index.d.cts +1 -1
  81. package/dist/signers/index.d.ts +1 -1
  82. package/dist/signers/index.js +1 -1
  83. package/dist/signers/non-custodial/index.cjs +1 -1
  84. package/dist/signers/non-custodial/index.d.cts +1 -1
  85. package/dist/signers/non-custodial/index.d.ts +1 -1
  86. package/dist/signers/non-custodial/index.js +1 -1
  87. package/dist/signers/non-custodial/ncs-evm-signer.cjs +1 -1
  88. package/dist/signers/non-custodial/ncs-evm-signer.d.cts +1 -1
  89. package/dist/signers/non-custodial/ncs-evm-signer.d.ts +1 -1
  90. package/dist/signers/non-custodial/ncs-evm-signer.js +1 -1
  91. package/dist/signers/non-custodial/ncs-signer.cjs +1 -1
  92. package/dist/signers/non-custodial/ncs-signer.d.cts +1 -1
  93. package/dist/signers/non-custodial/ncs-signer.d.ts +1 -1
  94. package/dist/signers/non-custodial/ncs-signer.js +1 -1
  95. package/dist/signers/non-custodial/ncs-solana-signer.cjs +1 -1
  96. package/dist/signers/non-custodial/ncs-solana-signer.d.cts +1 -1
  97. package/dist/signers/non-custodial/ncs-solana-signer.d.ts +1 -1
  98. package/dist/signers/non-custodial/ncs-solana-signer.js +1 -1
  99. package/dist/signers/non-custodial/ncs-stellar-signer.cjs +1 -1
  100. package/dist/signers/non-custodial/ncs-stellar-signer.d.cts +1 -1
  101. package/dist/signers/non-custodial/ncs-stellar-signer.d.ts +1 -1
  102. package/dist/signers/non-custodial/ncs-stellar-signer.js +1 -1
  103. package/dist/signers/passkey.d.cts +1 -1
  104. package/dist/signers/passkey.d.ts +1 -1
  105. package/dist/signers/server/assemble-server-signer.cjs +1 -1
  106. package/dist/signers/server/assemble-server-signer.d.cts +1 -1
  107. package/dist/signers/server/assemble-server-signer.d.ts +1 -1
  108. package/dist/signers/server/assemble-server-signer.js +1 -1
  109. package/dist/signers/server/evm-server-signer.d.cts +1 -1
  110. package/dist/signers/server/evm-server-signer.d.ts +1 -1
  111. package/dist/signers/server/helpers/derive-server-signer.cjs +1 -1
  112. package/dist/signers/server/helpers/derive-server-signer.d.cts +2 -6
  113. package/dist/signers/server/helpers/derive-server-signer.d.ts +2 -6
  114. package/dist/signers/server/helpers/derive-server-signer.js +1 -1
  115. package/dist/signers/server/helpers/index.cjs +1 -1
  116. package/dist/signers/server/helpers/index.d.cts +4 -4
  117. package/dist/signers/server/helpers/index.d.ts +4 -4
  118. package/dist/signers/server/helpers/index.js +1 -1
  119. package/dist/signers/server/index.cjs +1 -1
  120. package/dist/signers/server/index.d.cts +2 -2
  121. package/dist/signers/server/index.d.ts +2 -2
  122. package/dist/signers/server/index.js +1 -1
  123. package/dist/signers/server/solana-server-signer.d.cts +1 -1
  124. package/dist/signers/server/solana-server-signer.d.ts +1 -1
  125. package/dist/signers/server/stellar-server-signer.d.cts +1 -1
  126. package/dist/signers/server/stellar-server-signer.d.ts +1 -1
  127. package/dist/signers/solana-api-key.d.cts +1 -1
  128. package/dist/signers/solana-api-key.d.ts +1 -1
  129. package/dist/signers/solana-external-wallet.d.cts +1 -1
  130. package/dist/signers/solana-external-wallet.d.ts +1 -1
  131. package/dist/signers/stellar-external-wallet.d.cts +1 -1
  132. package/dist/signers/stellar-external-wallet.d.ts +1 -1
  133. package/dist/signers/types.d.cts +1 -1
  134. package/dist/signers/types.d.ts +1 -1
  135. package/dist/{types-Br5La8FI.d.ts → types-Dr1Gx-k4.d.ts} +5 -1
  136. package/dist/{types-Cc0Mr7mS.d.cts → types-DvahNo1f.d.cts} +5 -1
  137. package/dist/utils/constants.cjs +1 -1
  138. package/dist/utils/constants.js +1 -1
  139. package/dist/utils/device-signers/IframeDeviceSignerKeyStorage.cjs +1 -1
  140. package/dist/utils/device-signers/IframeDeviceSignerKeyStorage.js +1 -1
  141. package/dist/utils/device-signers/createDeviceSigner.d.cts +1 -1
  142. package/dist/utils/device-signers/createDeviceSigner.d.ts +1 -1
  143. package/dist/utils/device-signers/index.cjs +1 -1
  144. package/dist/utils/device-signers/index.d.cts +1 -1
  145. package/dist/utils/device-signers/index.d.ts +1 -1
  146. package/dist/utils/device-signers/index.js +1 -1
  147. package/dist/utils/server-signers/createServerSigner.cjs +1 -0
  148. package/dist/utils/server-signers/createServerSigner.d.cts +40 -0
  149. package/dist/utils/server-signers/createServerSigner.d.ts +40 -0
  150. package/dist/utils/server-signers/createServerSigner.js +1 -0
  151. package/dist/utils/server-signers/index.cjs +1 -0
  152. package/dist/utils/server-signers/index.d.cts +4 -0
  153. package/dist/utils/server-signers/index.d.ts +4 -0
  154. package/dist/utils/server-signers/index.js +1 -0
  155. package/dist/utils/signer-locator.d.cts +1 -1
  156. package/dist/utils/signer-locator.d.ts +1 -1
  157. package/dist/utils/signer-mapping.d.cts +1 -1
  158. package/dist/utils/signer-mapping.d.ts +1 -1
  159. package/dist/wallets/__tests__/test-helpers.cjs +1 -1
  160. package/dist/wallets/__tests__/test-helpers.d.cts +1 -1
  161. package/dist/wallets/__tests__/test-helpers.d.ts +1 -1
  162. package/dist/wallets/__tests__/test-helpers.js +1 -1
  163. package/dist/wallets/evm.cjs +1 -1
  164. package/dist/wallets/evm.d.cts +1 -1
  165. package/dist/wallets/evm.d.ts +1 -1
  166. package/dist/wallets/evm.js +1 -1
  167. package/dist/wallets/solana.cjs +1 -1
  168. package/dist/wallets/solana.d.cts +1 -1
  169. package/dist/wallets/solana.d.ts +1 -1
  170. package/dist/wallets/solana.js +1 -1
  171. package/dist/wallets/stellar.cjs +1 -1
  172. package/dist/wallets/stellar.d.cts +1 -1
  173. package/dist/wallets/stellar.d.ts +1 -1
  174. package/dist/wallets/stellar.js +1 -1
  175. package/dist/wallets/types.d.cts +1 -1
  176. package/dist/wallets/types.d.ts +1 -1
  177. package/dist/wallets/wallet-factory.cjs +1 -1
  178. package/dist/wallets/wallet-factory.d.cts +1 -1
  179. package/dist/wallets/wallet-factory.d.ts +1 -1
  180. package/dist/wallets/wallet-factory.js +1 -1
  181. package/dist/wallets/wallet.cjs +1 -1
  182. package/dist/wallets/wallet.d.cts +1 -1
  183. package/dist/wallets/wallet.d.ts +1 -1
  184. package/dist/wallets/wallet.js +1 -1
  185. package/package.json +2 -2
  186. package/dist/chunk-JJIGKUQA.cjs +0 -1
  187. package/dist/chunk-Q65NMVP3.js +0 -1
  188. package/dist/chunk-Y55LWZDS.js +0 -1
@@ -1,3 +1,3 @@
1
- import{a as pe}from"./chunk-N4IWDL6M.js";import{a as N}from"./chunk-GOXB2RBF.js";import{b as j,c as z}from"./chunk-KZMDZJGM.js";import{a as q}from"./chunk-2ZRCE5CX.js";import{c as he}from"./chunk-F5NTM2RX.js";import{a as ue}from"./chunk-4KGM7M2B.js";import{a as ge,b as Y,c as W}from"./chunk-PYIURK5B.js";import{f as de}from"./chunk-Q65NMVP3.js";import{A as oe,B as le,D as ce,d as Q,e as X,j as _,k as Z,l as V,p as ee,s as G,t as re,u as ie,v as te,w as M,x as ne,y as se,z as ae}from"./chunk-5OYPWGMX.js";import{a}from"./chunk-VOVJ4RNT.js";import{d as U}from"./chunk-Y55LWZDS.js";import{a as b,b as O,c as k,d as n,e as T,f as c,g as d}from"./chunk-J3R36SGJ.js";import{isValidAddress as Se,WithLoggerContext as P}from"@crossmint/common-sdk-base";var p,A,f,v,R,w,I,x,L,$,K,D,B,E=class{constructor(e,r){T(this,p);T(this,A);T(this,f);T(this,v);T(this,R);T(this,w,!1);T(this,I,!1);T(this,x,null);T(this,L,null);T(this,$,[]);T(this,K);T(this,D,null);T(this,B,!1);let{chain:i,address:t,owner:o,options:h,alias:s,recovery:l,apiRecoveryServerSignerAddress:g,apiDelegatedServerSignerAddresses:u,signers:S,signer:y}=e;c(this,f,r),this.chain=i,this.address=t,this.owner=o,c(this,A,h),this.alias=s,c(this,v,l),g!=null?c(this,L,g):l.type==="server"&&W(l)&&c(this,L,l.address),c(this,$,u!=null?u:[]),c(this,R,S!=null?S:[]),c(this,p,y),c(this,K,this.initDefaultSigner())}get signer(){return n(this,p)}waitForInit(){return d(this,null,function*(){yield n(this,K)})}initDeviceSigner(){return d(this,null,function*(){var t;let e=(t=n(this,A))==null?void 0:t.deviceSignerKeyStorage;if(e==null||n(this,B))return;let r={type:"device"};try{yield this.resolveDeviceSignerAvailability(r)}catch(o){a.error("wallet.initDeviceSigner.error",{error:o}),c(this,w,!0);return}if(n(this,w))return;let i=this.buildInternalSignerConfig(r);c(this,p,yield this.assembleFullSigner(i,e)),this.isApprovedSignerStatus(n(this,p).status)||(a.info("wallet.initDeviceSigner.pendingApproval",{signerLocator:n(this,p).locator(),status:n(this,p).status}),c(this,w,!0),c(this,I,!1))})}initDefaultSigner(){return d(this,null,function*(){if(n(this,p)!=null||(yield this.initDeviceSigner(),n(this,p)!=null||n(this,w)))return;let e=n(this,R).length===0?n(this,v):n(this,R).length===1?n(this,R)[0]:null;if(e==null||!this.isAutoAssemblableSignerConfig(e))return;let r=e===n(this,v);try{let i=this.buildInternalSignerConfig(e);c(this,p,yield this.assembleFullSigner(i,void 0,{isAdminSigner:r}))}catch(i){a.warn("wallet.initDefaultSigner.autoAssemblyFailed",{recoveryType:n(this,v).type,signerCount:n(this,R).length,error:i})}})}assembleRecoverySignerFallback(){return d(this,null,function*(){if(this.isAutoAssemblableSignerConfig(n(this,v)))try{let e=this.buildInternalSignerConfig(n(this,v));c(this,p,yield this.assembleFullSigner(e,void 0,{isAdminSigner:!0}))}catch(e){a.warn("wallet.recover.device.unsupportedFallback.autoAssemblyFailed",{recoveryType:n(this,v).type,error:e})}})}static getApiClient(e){return e.apiClient}static getOptions(e){return e.options}static getRecovery(e){return n(e,v)}static getInitialSigners(e){return n(e,R)}static getApiRecoveryServerSignerAddress(e){var r;return(r=n(e,L))!=null?r:void 0}static getApiDelegatedServerSignerAddresses(e){return n(e,$)}get apiClient(){return n(this,f)}get options(){return n(this,A)}deriveServerSignerCandidates(e){return he(e,this.chain,n(this,f).projectId,n(this,f).environment)}matchResolvedServerSigner(e){if(n(this,x)==null)return null;let{primary:r,legacy:i}=this.deriveServerSignerCandidates(e),t=n(this,x).derivedAddress;return t===r.derivedAddress||i!=null&&t===i.derivedAddress?n(this,x):null}resolveServerSignerDerivation(e){let r=this.matchResolvedServerSigner(e);if(r!=null)return r;let{primary:i,legacy:t}=this.deriveServerSignerCandidates(e);return t!=null&&(t.derivedAddress===n(this,L)||n(this,R).some(o=>o.type==="server"&&W(o)&&o.address===t.derivedAddress)||n(this,$).includes(t.derivedAddress))?t:i}resolveServerSignerApiLocator(e){return`server:${this.resolveServerSignerDerivation(e).derivedAddress}`}get recovery(){return n(this,v)}balances(e){return d(this,null,function*(){a.info("wallet.balances.start");let r=this.resolveChainForEnvironment(),i;switch(this.chain){case"solana":i="sol";break;case"stellar":i="xlm";break;default:i="eth";break}let t=[i,"usdc",...e!=null?e:[]],o=yield n(this,f).getBalance(this.address,{chains:[r],tokens:t});if("error"in o)throw a.error("wallet.balances.error",{error:o}),new Error(`Failed to get balances for wallet: ${JSON.stringify(o.message)}`);return a.info("wallet.balances.success"),this.transformBalanceResponse(o,i,e)})}stagingFund(e,r){return d(this,null,function*(){a.info("wallet.stagingFund.start",{amount:e,chain:r!=null?r:this.chain});let i=yield this.apiClient.fundWallet(this.address,{amount:e,token:"usdxm",chain:r!=null?r:this.chain});if("error"in i)throw a.error("wallet.stagingFund.error",{error:i}),new Error(`Failed to fund wallet: ${JSON.stringify(i.message)}`);return a.info("wallet.stagingFund.success"),i})}transformBalanceResponse(e,r,i){let t=g=>{var y,C,F,H,J;let u=(y=g.chains)==null?void 0:y[this.chain],S={};return this.chain==="solana"&&u!=null&&"mintHash"in u?S={mintHash:u.mintHash}:this.chain==="stellar"&&u!=null&&"contractId"in u?S={contractId:u.contractId}:u!=null&&"contractAddress"in u&&(S={contractAddress:u.contractAddress}),b({symbol:(C=g.symbol)!=null?C:"",name:(F=g.name)!=null?F:"",amount:(H=g.amount)!=null?H:"0",decimals:g.decimals,rawAmount:(J=g.rawAmount)!=null?J:"0"},S)},o=e.find(g=>g.symbol===r),h=e.find(g=>g.symbol==="usdc"),s=e.filter(g=>{var u;return g.symbol!==r&&g.symbol!=="usdc"&&(i==null||i.includes((u=g.symbol)!=null?u:""))}),l=g=>{let u={symbol:g,name:g,amount:"0",decimals:0,rawAmount:"0"},S={};return this.chain==="solana"?S={mintHash:void 0}:this.chain==="stellar"?S={contractId:void 0}:S={contractAddress:void 0},b(b({},u),S)};return{nativeToken:o!=null?t(o):l(r),usdc:h!=null?t(h):l("usdc"),tokens:s.map(t)}}nfts(e){return d(this,null,function*(){return yield n(this,f).getNfts(O(b({},e),{chain:this.chain,address:this.address}))})}transactions(){return d(this,null,function*(){let e=yield n(this,f).getTransactions(this.walletLocator);if("error"in e)throw new Error(`Failed to get transactions: ${JSON.stringify(e.message)}`);return e})}transaction(e){return d(this,null,function*(){let r=yield n(this,f).getTransaction(this.walletLocator,e);if("error"in r)throw new Error(`Failed to get transaction: ${JSON.stringify(r.error)}`);return r})}transfers(e){return d(this,null,function*(){let r=this.resolveChainForEnvironment(),i=yield this.apiClient.getTransfers(this.walletLocator,{chain:r,tokens:e.tokens,status:e.status});if("error"in i)throw new Error(`Failed to get transfers: ${JSON.stringify(i.message)}`);return i})}send(e,r,i,t){return d(this,null,function*(){let o=this.resolveChainForEnvironment(),h=we(e),s=ye(r,o),l=Number(i);if(Number.isNaN(l)||!Number.isFinite(l)||l<=0)throw new ie(`Invalid transfer amount: "${i}". Amount must be a positive number greater than zero.`);a.info("wallet.send.start",b({recipient:h,token:s,amount:i},(t==null?void 0:t.transactionType)!=null?{transactionType:t.transactionType}:{})),yield this.preAuthIfNeeded();let g=this.requireSigner(),u;(t==null?void 0:t.signer)==null?u=g.locator():typeof t.signer=="string"?u=t.signer:u=this.resolveServerSignerApiLocator(t.signer);let S=b({recipient:h,amount:i,signer:u},(t==null?void 0:t.transactionType)!=null?{transactionType:t.transactionType}:{}),y=yield n(this,f).send(this.walletLocator,s,S);if("message"in y)throw a.error("wallet.send.error",{error:y}),new te(`Failed to send token: ${JSON.stringify(y.message)}`);if((t==null?void 0:t.prepareOnly)===!0)return a.info("wallet.send.prepared",{transactionId:y.id}),{hash:void 0,explorerLink:void 0,transactionId:y.id};let C=yield this.approveTransactionAndWait(y.id);return a.info("wallet.send.success",{transactionId:y.id,hash:C.hash}),C})}approveTransaction(e){return d(this,null,function*(){return console.warn("approveTransaction is deprecated. Use approve instead. This method will be removed in the next major version."),yield this.approve(e)})}approve(e){return d(this,null,function*(){if(a.info("wallet.approve.start",{transactionId:e.transactionId,signatureId:e.signatureId}),yield this.preAuthIfNeeded(),e.transactionId!=null){let r=yield this.approveTransactionAndWait(e.transactionId,e.options);return a.info("wallet.approve.success",{transactionId:e.transactionId}),r}if(e.signatureId!=null){let r=yield this.approveSignatureAndWait(e.signatureId,e.options);return a.info("wallet.approve.success",{signatureId:e.signatureId}),r}throw a.error("wallet.approve.error",{error:"Either transactionId or signatureId must be provided"}),new Error("Either transactionId or signatureId must be provided")})}addSigner(e,r){return d(this,null,function*(){a.info("wallet.addSigner.start");let i=typeof e=="object"&&"type"in e&&e.type==="server"?this.resolveServerSignerApiLocator(e):e;return this.withRecoverySigner(()=>d(this,null,function*(){var u,S;let t=typeof i=="string"?i:N(i),o=yield this.getSignerState(t);if(o.signer!=null){if(this.isApprovedSignerStatus(o.signer.status))return a.info("wallet.addSigner.alreadyApproved"),this.completeSignerRegistration(o.signer,null,r);if(o.pendingOperation!=null)return a.info("wallet.addSigner.resuming",{operationType:o.pendingOperation.type,operationId:o.pendingOperation.id}),this.completeSignerRegistration(o.signer,o.pendingOperation,r)}let h=typeof i=="string"||i.type==="passkey"?i:i.type==="device"&&"publicKey"in i&&i.publicKey!=null?{type:"device",publicKey:i.publicKey,name:i.name}:N(i),s=yield n(this,f).registerSigner(this.walletLocator,b({signer:h,chain:this.getSignerRegistrationChain()},(r==null?void 0:r.scopes)!=null&&{scopes:r.scopes}));if("error"in s)throw a.error("wallet.addSigner.error",{error:s}),s.code===Z?new V(s.message):new _(`Failed to register signer: ${JSON.stringify(s.message)}`);let l=j(s,this.chain);if(l==null)throw new Error(`No approval found for chain ${this.chain} in register signer response`);let g=null;if(this.chain==="solana"||this.chain==="stellar"){if(!("transaction"in s)||s.transaction==null)throw a.error("wallet.addSigner.error",{error:"Expected transaction in response for Solana/Stellar chain"}),new Error("Expected transaction in response for Solana/Stellar chain");g={type:"transaction",id:s.transaction.id}}else{if(!("chains"in s))throw a.error("wallet.addSigner.error",{error:"Expected chains in response for EVM chain"}),new Error("Expected chains in response for EVM chain");if(((S=(u=s.chains)==null?void 0:u[this.chain])==null?void 0:S.status)==="failed")throw new Error(`Signer registration failed for chain ${this.chain}`);g=z(s,this.chain)}return this.completeSignerRegistration(l,g,r)}))})}completeSignerRegistration(e,r,i){return d(this,null,function*(){if(i!=null&&i.prepareOnly){if(r==null)return b({},e);switch(r.type){case"transaction":{let t={transactionId:r.id};return a.info("wallet.addSigner.prepared",t),b(b({},e),t)}case"signature":{let t={signatureId:r.id};return a.info("wallet.addSigner.prepared",t),b(b({},e),t)}default:{let t=r.type;throw new Error(`Unknown pending operation type: ${t}`)}}}if(r!=null)switch(r.type){case"transaction":yield this.approveTransactionAndWait(r.id),a.info("wallet.addSigner.success",{transactionId:r.id});break;case"signature":yield this.approveSignatureAndWait(r.id),a.info("wallet.addSigner.success",{signatureId:r.id});break;default:{let t=r.type;throw new Error(`Unknown pending operation type: ${t}`)}}else a.info("wallet.addSigner.success");return O(b({},e),{status:"success"})})}removeSigner(e,r){return d(this,null,function*(){let i=this.resolveSignerLocator(e);return a.info("wallet.removeSigner.start",{signerLocator:i}),this.withRecoverySigner(()=>d(this,null,function*(){let t=yield n(this,f).removeSigner(this.walletLocator,i,{chain:this.getSignerRegistrationChain()});if("error"in t)throw a.error("wallet.removeSigner.error",{error:t}),new Error(`Failed to remove signer: ${JSON.stringify(t)}`);let o=t.id;return r!=null&&r.prepareOnly?(a.info("wallet.removeSigner.prepared",{transactionId:o}),{transactionId:o,status:void 0}):(yield this.approveTransactionAndWait(o),a.info("wallet.removeSigner.success",{transactionId:o}),{transactionId:o,status:"success"})}))})}useSigner(e){return d(this,null,function*(){a.info("wallet.useSigner.start"),e.type==="server"&&c(this,x,null),this.validateSignerInput(e);let r=!1;e.type==="device"?yield this.resolveDeviceSignerAvailability(e):r=yield this.resolveNonDeviceSigner(e);let i=this.buildInternalSignerConfig(e),t=N(e);c(this,p,yield this.assembleFullSigner(i,void 0,{isAdminSigner:r})),a.info("wallet.useSigner.success",{signerLocator:t})})}resolveNonDeviceSigner(e){return d(this,null,function*(){if(e.type!=="passkey"&&e.type!=="server"&&this.isRecoverySigner(e))return c(this,w,!1),!0;if(e.type==="passkey"&&this.isPasskeyMissingId(e)&&!(yield this.tryAutoSelectPasskey(e))){if(this.isRecoverySigner(e))return c(this,w,!1),!0;throw new Error("No passkey signer is registered on this wallet.")}if(e.type==="server")return this.resolveServerSigner(e);let r=this.resolveSignerLocator(e);if(yield this.signerIsRegistered(r))return c(this,w,!1),!1;if(this.isRecoverySigner(e))return c(this,w,!1),!0;throw new Error(`Signer "${r}" is not registered in this wallet.`)})}resolveServerSigner(e){return d(this,null,function*(){let{primary:r,legacy:i}=this.deriveServerSignerCandidates(e),t=yield this.signers();if(t.some(h=>h.locator===`server:${r.derivedAddress}`))return c(this,x,r),c(this,w,!1),!1;if(i!=null&&t.some(h=>h.locator===`server:${i.derivedAddress}`))return c(this,x,i),c(this,w,!1),!1;if(this.isRecoverySigner(e))return n(this,L)!=null&&i!=null&&i.derivedAddress===n(this,L)?c(this,x,i):c(this,x,r),c(this,w,!1),!0;let o=i!=null?`"server:${r.derivedAddress}" or "server:${i.derivedAddress}"`:`"server:${r.derivedAddress}"`;throw new Error(`Signer ${o} is not registered in this wallet.`)})}tryAutoSelectPasskey(e){return d(this,null,function*(){let i=(yield this.signers()).filter(t=>t.type==="passkey");if(i.length===0)return!1;if(i.length>1)throw new Error('Multiple passkey signers are registered on this wallet. Please specify the credential id: wallet.useSigner({ type: "passkey", id: "<credential-id>" })');return e.id=i[0].locator.replace("passkey:",""),!0})}resolveSignerLocator(e){return e.type==="server"?this.resolveServerSignerApiLocator(e):N(e)}getSignerRegistrationChain(){if(!(this.chain==="solana"||this.chain==="stellar"))return this.chain}withRecoverySigner(e){return d(this,null,function*(){var t;let r=this.signer;if(W(n(this,v)))throw new Error('Cannot assemble server signer: no secret available. Call wallet.useSigner({ type: "server", secret: ... }) first with the recovery server secret.');if(n(this,v)!=null&&n(this,v).type==="external-wallet"&&!this.isAutoAssemblableSignerConfig(n(this,v)))throw new Error('Cannot assemble external wallet signer: no onSign callback available. Call wallet.useSigner({ type: "external-wallet", address: "0x...", onSign: async (tx) => ... }) first.');let i=this.buildInternalSignerConfig(n(this,v));c(this,p,q(this.chain,i,(t=n(this,A))==null?void 0:t.deviceSignerKeyStorage));try{return yield e()}finally{c(this,p,r)}})}isPasskeyMissingId(e){return e.id==null||e.id===""}signerIsRegistered(e){return d(this,null,function*(){return(yield this.signers()).some(i=>i.locator===e)})}isSignerApproved(e){return d(this,null,function*(){var i;let r=yield this.getSignerState(e);return this.isApprovedSignerStatus((i=r.signer)==null?void 0:i.status)})}isApprovedSignerStatus(e){return e==="success"||e==="active"}needsRecovery(){return n(this,w)}recover(){return d(this,null,function*(){var o,h;if(a.info("wallet.recover.start"),n(this,I)){a.info("wallet.recover.skipped",{reason:"Device signer already approved (cached)"});return}if(n(this,B)){a.info("wallet.recover.skipped",{reason:"device signer not supported (cached)"}),c(this,w,!1),c(this,I,!0);return}let e=()=>{c(this,w,!1),c(this,I,!0)};if(((o=n(this,p))==null?void 0:o.type)==="device"&&(yield this.checkAndResumeDeviceSigner(n(this,p)))){e();return}if(n(this,p)!=null&&n(this,p).type!=="device"){a.warn("wallet.recover.skipped",{reason:"Recovery is only supported for device signers"}),c(this,w,!1);return}let r=(h=n(this,A))==null?void 0:h.deviceSignerKeyStorage;if(r==null){if(!n(this,w))return;throw new Error("Device signer key storage is required to recover a device signer")}let i=yield this.findLocalDeviceSigner(r);if(i!=null&&(yield this.checkAndResumeDeviceSigner(i))){c(this,p,i),e();let s=i.locator().replace("device:","");try{yield r.mapAddressToKey(this.address,s)}catch(l){a.warn("wallet.recover.mapAddressToKey.error",{error:l})}return}let t=yield pe(r,this.address);try{yield this.addSigner(t)}catch(s){let l=s instanceof Error&&s.message.toLowerCase().includes("delegated signer")&&s.message.toLowerCase().includes("already")&&s.message.toLowerCase().includes("approved");if(s instanceof V){a.info("wallet.recover.device.unsupportedFallback",{signerLocator:t.locator}),yield r.deleteKey(this.address),c(this,B,!0),c(this,w,!1),c(this,I,!0),yield this.assembleRecoverySignerFallback();return}else if(l)a.info("wallet.recover.skipped",{reason:"Device signer already approved",signerLocator:t.locator});else throw s instanceof ge||s instanceof Error&&s.name==="AuthRejectedError"?(a.info("wallet.recover.device.authRejected",{signerLocator:t.locator}),s):s instanceof Y||s instanceof Error&&s.name==="OtpValidationError"?(a.warn("wallet.recover.device.otpValidationFailed",{signerLocator:t.locator,code:s instanceof Y?s.code:void 0}),s):(a.error("wallet.recover.device.error",{error:s}),yield r.deleteKey(this.address),s)}c(this,p,yield this.assembleFullSigner({type:"device",locator:t.locator,address:this.address},r)),n(this,p).type==="device"&&(n(this,p).status="success"),a.info("wallet.recover.device.success",{signerLocator:t.locator}),e()})}checkAndResumeDeviceSigner(e){return d(this,null,function*(){var i;if(this.isApprovedSignerStatus(e.status))return a.info("wallet.recover.skipped",{reason:"Device signer already approved"}),!0;let r=yield this.getSignerState(e.locator());return e.status=(i=r.signer)==null?void 0:i.status,r.pendingOperation!=null?(yield this.resumePendingDeviceSignerApproval(e,r.pendingOperation),!0):this.isApprovedSignerStatus(e.status)?(a.info("wallet.recover.skipped",{reason:"Device signer already approved"}),!0):!1})}resumePendingDeviceSignerApproval(e,r){return d(this,null,function*(){var o;let i=n(this,p);if(W(n(this,v)))throw new Error('Cannot resume pending approval: no secret available. Call wallet.useSigner({ type: "server", secret: ... }) first with the recovery server secret.');if(n(this,v)!=null&&n(this,v).type==="external-wallet"&&!this.isAutoAssemblableSignerConfig(n(this,v)))throw new Error('Cannot resume pending approval: no onSign callback available. Call wallet.useSigner({ type: "external-wallet", address: "0x...", onSign: async (tx) => ... }) first.');let t=this.buildInternalSignerConfig(n(this,v));c(this,p,q(this.chain,t,(o=n(this,A))==null?void 0:o.deviceSignerKeyStorage));try{r.type==="signature"?yield this.approveSignatureAndWait(r.id):yield this.approveTransactionAndWait(r.id)}catch(h){throw c(this,p,e),h}finally{n(this,p)!==e&&c(this,p,i)}e.status="success",a.info("wallet.recover.device.success",{signerLocator:e.locator(),resumed:!0})})}findLocalDeviceSigner(e){return d(this,null,function*(){let i=(yield this.signers()).filter(t=>t.locator.startsWith("device:"));for(let t of i){let o=t.locator.replace("device:","");try{if(yield e.hasKey(o)){let s=q(this.chain,{type:"device",locator:t.locator,address:this.address},e);return a.info("wallet.recover.foundLocalDeviceSigner",{signerLocator:t.locator}),s}}catch(h){a.warn("wallet.recover.findLocalDeviceSigner.keyCheckError",{signerLocator:t.locator,error:h})}}return null})}signers(){return d(this,null,function*(){var o,h;a.info("wallet.signers.start");let e=yield n(this,f).getWallet(this.walletLocator);if("error"in e)throw a.error("wallet.signers.error",{error:e}),new X(JSON.stringify(e));if(e.type!=="smart"||e.chainType!=="evm"&&e.chainType!=="solana"&&e.chainType!=="stellar")throw a.error("wallet.signers.error",{error:`Wallet type ${e.type} not supported`}),new Q(`Wallet type ${e.type} not supported`);let r=(h=(o=e==null?void 0:e.config)==null?void 0:o.delegatedSigners)!=null?h:[],t=(yield Promise.all(r.map(s=>d(this,null,function*(){try{return(yield this.getSignerState(s.locator)).signer}catch(l){return null}})))).filter(s=>s!=null);return a.info("wallet.signers.success",{count:t.length}),t})}get walletLocator(){if(n(this,f).isServerSide)return this.address;{let e;switch(this.chain){case"stellar":e="me:stellar:smart";break;case"solana":e="me:solana:smart";break;default:e="me:evm:smart";break}let r=this.alias!=null?`:alias:${this.alias}`:"";return e+r}}requireSigner(){if(n(this,p)==null)throw n(this,R).length>1?new Error("No signer is set. This wallet has multiple signers configured. Call wallet.useSigner() to select which signer to use before signing operations."):n(this,v).type==="server"?new Error(`No signer is set. Server wallets require calling wallet.useSigner() with the server secret before signing operations.
1
+ import{a as pe}from"./chunk-N4IWDL6M.js";import{a as N}from"./chunk-GOXB2RBF.js";import{b as j,c as z}from"./chunk-KZMDZJGM.js";import{a as q}from"./chunk-ITE2NCJQ.js";import{c as he}from"./chunk-MDINF2FR.js";import{a as ue}from"./chunk-NBPZ3T3M.js";import{a as ge,b as Y,c as W}from"./chunk-PYIURK5B.js";import{f as de}from"./chunk-5UAALAXV.js";import{A as oe,B as le,D as ce,d as Q,e as X,j as _,k as Z,l as V,p as ee,s as G,t as re,u as ie,v as te,w as M,x as ne,y as se,z as ae}from"./chunk-5OYPWGMX.js";import{a}from"./chunk-RFWG2QIH.js";import{d as U}from"./chunk-2FKIDTGK.js";import{a as b,b as O,c as k,d as n,e as T,f as c,g as d}from"./chunk-J3R36SGJ.js";import{isValidAddress as Se,WithLoggerContext as P}from"@crossmint/common-sdk-base";var p,A,f,v,R,w,I,x,L,$,K,D,B,E=class{constructor(e,r){T(this,p);T(this,A);T(this,f);T(this,v);T(this,R);T(this,w,!1);T(this,I,!1);T(this,x,null);T(this,L,null);T(this,$,[]);T(this,K);T(this,D,null);T(this,B,!1);let{chain:i,address:t,owner:o,options:h,alias:s,recovery:l,apiRecoveryServerSignerAddress:g,apiDelegatedServerSignerAddresses:u,signers:S,signer:y}=e;c(this,f,r),this.chain=i,this.address=t,this.owner=o,c(this,A,h),this.alias=s,c(this,v,l),g!=null?c(this,L,g):l.type==="server"&&W(l)&&c(this,L,l.address),c(this,$,u!=null?u:[]),c(this,R,S!=null?S:[]),c(this,p,y),c(this,K,this.initDefaultSigner())}get signer(){return n(this,p)}waitForInit(){return d(this,null,function*(){yield n(this,K)})}initDeviceSigner(){return d(this,null,function*(){var t;let e=(t=n(this,A))==null?void 0:t.deviceSignerKeyStorage;if(e==null||n(this,B))return;let r={type:"device"};try{yield this.resolveDeviceSignerAvailability(r)}catch(o){a.error("wallet.initDeviceSigner.error",{error:o}),c(this,w,!0);return}if(n(this,w))return;let i=this.buildInternalSignerConfig(r);c(this,p,yield this.assembleFullSigner(i,e)),this.isApprovedSignerStatus(n(this,p).status)||(a.info("wallet.initDeviceSigner.pendingApproval",{signerLocator:n(this,p).locator(),status:n(this,p).status}),c(this,w,!0),c(this,I,!1))})}initDefaultSigner(){return d(this,null,function*(){if(n(this,p)!=null||(yield this.initDeviceSigner(),n(this,p)!=null||n(this,w)))return;let e=n(this,R).length===0?n(this,v):n(this,R).length===1?n(this,R)[0]:null;if(e==null||!this.isAutoAssemblableSignerConfig(e))return;let r=e===n(this,v);try{let i=this.buildInternalSignerConfig(e);c(this,p,yield this.assembleFullSigner(i,void 0,{isAdminSigner:r}))}catch(i){a.warn("wallet.initDefaultSigner.autoAssemblyFailed",{recoveryType:n(this,v).type,signerCount:n(this,R).length,error:i})}})}assembleRecoverySignerFallback(){return d(this,null,function*(){if(this.isAutoAssemblableSignerConfig(n(this,v)))try{let e=this.buildInternalSignerConfig(n(this,v));c(this,p,yield this.assembleFullSigner(e,void 0,{isAdminSigner:!0}))}catch(e){a.warn("wallet.recover.device.unsupportedFallback.autoAssemblyFailed",{recoveryType:n(this,v).type,error:e})}})}static getApiClient(e){return e.apiClient}static getOptions(e){return e.options}static getRecovery(e){return n(e,v)}static getInitialSigners(e){return n(e,R)}static getApiRecoveryServerSignerAddress(e){var r;return(r=n(e,L))!=null?r:void 0}static getApiDelegatedServerSignerAddresses(e){return n(e,$)}get apiClient(){return n(this,f)}get options(){return n(this,A)}deriveServerSignerCandidates(e){return he(e,this.chain,n(this,f).projectId,n(this,f).environment)}matchResolvedServerSigner(e){if(n(this,x)==null)return null;let{primary:r,legacy:i}=this.deriveServerSignerCandidates(e),t=n(this,x).derivedAddress;return t===r.derivedAddress||i!=null&&t===i.derivedAddress?n(this,x):null}resolveServerSignerDerivation(e){let r=this.matchResolvedServerSigner(e);if(r!=null)return r;let{primary:i,legacy:t}=this.deriveServerSignerCandidates(e);return t!=null&&(t.derivedAddress===n(this,L)||n(this,R).some(o=>o.type==="server"&&W(o)&&o.address===t.derivedAddress)||n(this,$).includes(t.derivedAddress))?t:i}resolveServerSignerApiLocator(e){return`server:${this.resolveServerSignerDerivation(e).derivedAddress}`}get recovery(){return n(this,v)}balances(e){return d(this,null,function*(){a.info("wallet.balances.start");let r=this.resolveChainForEnvironment(),i;switch(this.chain){case"solana":i="sol";break;case"stellar":i="xlm";break;default:i="eth";break}let t=[i,"usdc",...e!=null?e:[]],o=yield n(this,f).getBalance(this.address,{chains:[r],tokens:t});if("error"in o)throw a.error("wallet.balances.error",{error:o}),new Error(`Failed to get balances for wallet: ${JSON.stringify(o.message)}`);return a.info("wallet.balances.success"),this.transformBalanceResponse(o,i,e)})}stagingFund(e,r){return d(this,null,function*(){a.info("wallet.stagingFund.start",{amount:e,chain:r!=null?r:this.chain});let i=yield this.apiClient.fundWallet(this.address,{amount:e,token:"usdxm",chain:r!=null?r:this.chain});if("error"in i)throw a.error("wallet.stagingFund.error",{error:i}),new Error(`Failed to fund wallet: ${JSON.stringify(i.message)}`);return a.info("wallet.stagingFund.success"),i})}transformBalanceResponse(e,r,i){let t=g=>{var y,C,F,H,J;let u=(y=g.chains)==null?void 0:y[this.chain],S={};return this.chain==="solana"&&u!=null&&"mintHash"in u?S={mintHash:u.mintHash}:this.chain==="stellar"&&u!=null&&"contractId"in u?S={contractId:u.contractId}:u!=null&&"contractAddress"in u&&(S={contractAddress:u.contractAddress}),b({symbol:(C=g.symbol)!=null?C:"",name:(F=g.name)!=null?F:"",amount:(H=g.amount)!=null?H:"0",decimals:g.decimals,rawAmount:(J=g.rawAmount)!=null?J:"0"},S)},o=e.find(g=>g.symbol===r),h=e.find(g=>g.symbol==="usdc"),s=e.filter(g=>{var u;return g.symbol!==r&&g.symbol!=="usdc"&&(i==null||i.includes((u=g.symbol)!=null?u:""))}),l=g=>{let u={symbol:g,name:g,amount:"0",decimals:0,rawAmount:"0"},S={};return this.chain==="solana"?S={mintHash:void 0}:this.chain==="stellar"?S={contractId:void 0}:S={contractAddress:void 0},b(b({},u),S)};return{nativeToken:o!=null?t(o):l(r),usdc:h!=null?t(h):l("usdc"),tokens:s.map(t)}}nfts(e){return d(this,null,function*(){return yield n(this,f).getNfts(O(b({},e),{chain:this.chain,address:this.address}))})}transactions(){return d(this,null,function*(){let e=yield n(this,f).getTransactions(this.walletLocator);if("error"in e)throw new Error(`Failed to get transactions: ${JSON.stringify(e.message)}`);return e})}transaction(e){return d(this,null,function*(){let r=yield n(this,f).getTransaction(this.walletLocator,e);if("error"in r)throw new Error(`Failed to get transaction: ${JSON.stringify(r.error)}`);return r})}transfers(e){return d(this,null,function*(){let r=this.resolveChainForEnvironment(),i=yield this.apiClient.getTransfers(this.walletLocator,{chain:r,tokens:e.tokens,status:e.status});if("error"in i)throw new Error(`Failed to get transfers: ${JSON.stringify(i.message)}`);return i})}send(e,r,i,t){return d(this,null,function*(){let o=this.resolveChainForEnvironment(),h=we(e),s=ye(r,o),l=Number(i);if(Number.isNaN(l)||!Number.isFinite(l)||l<=0)throw new ie(`Invalid transfer amount: "${i}". Amount must be a positive number greater than zero.`);a.info("wallet.send.start",b({recipient:h,token:s,amount:i},(t==null?void 0:t.transactionType)!=null?{transactionType:t.transactionType}:{})),yield this.preAuthIfNeeded();let g=this.requireSigner(),u;(t==null?void 0:t.signer)==null?u=g.locator():typeof t.signer=="string"?u=t.signer:u=this.resolveServerSignerApiLocator(t.signer);let S=b({recipient:h,amount:i,signer:u},(t==null?void 0:t.transactionType)!=null?{transactionType:t.transactionType}:{}),y=yield n(this,f).send(this.walletLocator,s,S);if("message"in y)throw a.error("wallet.send.error",{error:y}),new te(`Failed to send token: ${JSON.stringify(y.message)}`);if((t==null?void 0:t.prepareOnly)===!0)return a.info("wallet.send.prepared",{transactionId:y.id}),{hash:void 0,explorerLink:void 0,transactionId:y.id};let C=yield this.approveTransactionAndWait(y.id);return a.info("wallet.send.success",{transactionId:y.id,hash:C.hash}),C})}approveTransaction(e){return d(this,null,function*(){return console.warn("approveTransaction is deprecated. Use approve instead. This method will be removed in the next major version."),yield this.approve(e)})}approve(e){return d(this,null,function*(){if(a.info("wallet.approve.start",{transactionId:e.transactionId,signatureId:e.signatureId}),yield this.preAuthIfNeeded(),e.transactionId!=null){let r=yield this.approveTransactionAndWait(e.transactionId,e.options);return a.info("wallet.approve.success",{transactionId:e.transactionId}),r}if(e.signatureId!=null){let r=yield this.approveSignatureAndWait(e.signatureId,e.options);return a.info("wallet.approve.success",{signatureId:e.signatureId}),r}throw a.error("wallet.approve.error",{error:"Either transactionId or signatureId must be provided"}),new Error("Either transactionId or signatureId must be provided")})}addSigner(e,r){return d(this,null,function*(){a.info("wallet.addSigner.start");let i=typeof e=="object"&&"type"in e&&e.type==="server"?this.resolveServerSignerApiLocator(e):e;return this.withRecoverySigner(()=>d(this,null,function*(){var u,S;let t=typeof i=="string"?i:N(i),o=yield this.getSignerState(t);if(o.signer!=null){if(this.isApprovedSignerStatus(o.signer.status))return a.info("wallet.addSigner.alreadyApproved"),this.completeSignerRegistration(o.signer,null,r);if(o.pendingOperation!=null)return a.info("wallet.addSigner.resuming",{operationType:o.pendingOperation.type,operationId:o.pendingOperation.id}),this.completeSignerRegistration(o.signer,o.pendingOperation,r)}let h=typeof i=="string"||i.type==="passkey"?i:i.type==="device"&&"publicKey"in i&&i.publicKey!=null?{type:"device",publicKey:i.publicKey,name:i.name}:N(i),s=yield n(this,f).registerSigner(this.walletLocator,b({signer:h,chain:this.getSignerRegistrationChain()},(r==null?void 0:r.scopes)!=null&&{scopes:r.scopes}));if("error"in s)throw a.error("wallet.addSigner.error",{error:s}),s.code===Z?new V(s.message):new _(`Failed to register signer: ${JSON.stringify(s.message)}`);let l=j(s,this.chain);if(l==null)throw new Error(`No approval found for chain ${this.chain} in register signer response`);let g=null;if(this.chain==="solana"||this.chain==="stellar"){if(!("transaction"in s)||s.transaction==null)throw a.error("wallet.addSigner.error",{error:"Expected transaction in response for Solana/Stellar chain"}),new Error("Expected transaction in response for Solana/Stellar chain");g={type:"transaction",id:s.transaction.id}}else{if(!("chains"in s))throw a.error("wallet.addSigner.error",{error:"Expected chains in response for EVM chain"}),new Error("Expected chains in response for EVM chain");if(((S=(u=s.chains)==null?void 0:u[this.chain])==null?void 0:S.status)==="failed")throw new Error(`Signer registration failed for chain ${this.chain}`);g=z(s,this.chain)}return this.completeSignerRegistration(l,g,r)}))})}completeSignerRegistration(e,r,i){return d(this,null,function*(){if(i!=null&&i.prepareOnly){if(r==null)return b({},e);switch(r.type){case"transaction":{let t={transactionId:r.id};return a.info("wallet.addSigner.prepared",t),b(b({},e),t)}case"signature":{let t={signatureId:r.id};return a.info("wallet.addSigner.prepared",t),b(b({},e),t)}default:{let t=r.type;throw new Error(`Unknown pending operation type: ${t}`)}}}if(r!=null)switch(r.type){case"transaction":yield this.approveTransactionAndWait(r.id),a.info("wallet.addSigner.success",{transactionId:r.id});break;case"signature":yield this.approveSignatureAndWait(r.id),a.info("wallet.addSigner.success",{signatureId:r.id});break;default:{let t=r.type;throw new Error(`Unknown pending operation type: ${t}`)}}else a.info("wallet.addSigner.success");return O(b({},e),{status:"success"})})}removeSigner(e,r){return d(this,null,function*(){let i=this.resolveSignerLocator(e);return a.info("wallet.removeSigner.start",{signerLocator:i}),this.withRecoverySigner(()=>d(this,null,function*(){let t=yield n(this,f).removeSigner(this.walletLocator,i,{chain:this.getSignerRegistrationChain()});if("error"in t)throw a.error("wallet.removeSigner.error",{error:t}),new Error(`Failed to remove signer: ${JSON.stringify(t)}`);let o=t.id;return r!=null&&r.prepareOnly?(a.info("wallet.removeSigner.prepared",{transactionId:o}),{transactionId:o,status:void 0}):(yield this.approveTransactionAndWait(o),a.info("wallet.removeSigner.success",{transactionId:o}),{transactionId:o,status:"success"})}))})}useSigner(e){return d(this,null,function*(){a.info("wallet.useSigner.start"),e.type==="server"&&c(this,x,null),this.validateSignerInput(e);let r=!1;e.type==="device"?yield this.resolveDeviceSignerAvailability(e):r=yield this.resolveNonDeviceSigner(e);let i=this.buildInternalSignerConfig(e),t=N(e);c(this,p,yield this.assembleFullSigner(i,void 0,{isAdminSigner:r})),a.info("wallet.useSigner.success",{signerLocator:t})})}resolveNonDeviceSigner(e){return d(this,null,function*(){if(e.type!=="passkey"&&e.type!=="server"&&this.isRecoverySigner(e))return c(this,w,!1),!0;if(e.type==="passkey"&&this.isPasskeyMissingId(e)&&!(yield this.tryAutoSelectPasskey(e))){if(this.isRecoverySigner(e))return c(this,w,!1),!0;throw new Error("No passkey signer is registered on this wallet.")}if(e.type==="server")return this.resolveServerSigner(e);let r=this.resolveSignerLocator(e);if(yield this.signerIsRegistered(r))return c(this,w,!1),!1;if(this.isRecoverySigner(e))return c(this,w,!1),!0;throw new Error(`Signer "${r}" is not registered in this wallet.`)})}resolveServerSigner(e){return d(this,null,function*(){let{primary:r,legacy:i}=this.deriveServerSignerCandidates(e),t=yield this.signers();if(t.some(h=>h.locator===`server:${r.derivedAddress}`))return c(this,x,r),c(this,w,!1),!1;if(i!=null&&t.some(h=>h.locator===`server:${i.derivedAddress}`))return c(this,x,i),c(this,w,!1),!1;if(this.isRecoverySigner(e))return n(this,L)!=null&&i!=null&&i.derivedAddress===n(this,L)?c(this,x,i):c(this,x,r),c(this,w,!1),!0;let o=i!=null?`"server:${r.derivedAddress}" or "server:${i.derivedAddress}"`:`"server:${r.derivedAddress}"`;throw new Error(`Signer ${o} is not registered in this wallet.`)})}tryAutoSelectPasskey(e){return d(this,null,function*(){let i=(yield this.signers()).filter(t=>t.type==="passkey");if(i.length===0)return!1;if(i.length>1)throw new Error('Multiple passkey signers are registered on this wallet. Please specify the credential id: wallet.useSigner({ type: "passkey", id: "<credential-id>" })');return e.id=i[0].locator.replace("passkey:",""),!0})}resolveSignerLocator(e){return e.type==="server"?this.resolveServerSignerApiLocator(e):N(e)}getSignerRegistrationChain(){if(!(this.chain==="solana"||this.chain==="stellar"))return this.chain}withRecoverySigner(e){return d(this,null,function*(){var t;let r=this.signer;if(W(n(this,v)))throw new Error('Cannot assemble server signer: no secret available. Call wallet.useSigner({ type: "server", secret: ... }) first with the recovery server secret.');if(n(this,v)!=null&&n(this,v).type==="external-wallet"&&!this.isAutoAssemblableSignerConfig(n(this,v)))throw new Error('Cannot assemble external wallet signer: no onSign callback available. Call wallet.useSigner({ type: "external-wallet", address: "0x...", onSign: async (tx) => ... }) first.');let i=this.buildInternalSignerConfig(n(this,v));c(this,p,q(this.chain,i,(t=n(this,A))==null?void 0:t.deviceSignerKeyStorage));try{return yield e()}finally{c(this,p,r)}})}isPasskeyMissingId(e){return e.id==null||e.id===""}signerIsRegistered(e){return d(this,null,function*(){return(yield this.signers()).some(i=>i.locator===e)})}isSignerApproved(e){return d(this,null,function*(){var i;let r=yield this.getSignerState(e);return this.isApprovedSignerStatus((i=r.signer)==null?void 0:i.status)})}isApprovedSignerStatus(e){return e==="success"||e==="active"}needsRecovery(){return n(this,w)}recover(){return d(this,null,function*(){var o,h;if(a.info("wallet.recover.start"),n(this,I)){a.info("wallet.recover.skipped",{reason:"Device signer already approved (cached)"});return}if(n(this,B)){a.info("wallet.recover.skipped",{reason:"device signer not supported (cached)"}),c(this,w,!1),c(this,I,!0);return}let e=()=>{c(this,w,!1),c(this,I,!0)};if(((o=n(this,p))==null?void 0:o.type)==="device"&&(yield this.checkAndResumeDeviceSigner(n(this,p)))){e();return}if(n(this,p)!=null&&n(this,p).type!=="device"){a.warn("wallet.recover.skipped",{reason:"Recovery is only supported for device signers"}),c(this,w,!1);return}let r=(h=n(this,A))==null?void 0:h.deviceSignerKeyStorage;if(r==null){if(!n(this,w))return;throw new Error("Device signer key storage is required to recover a device signer")}let i=yield this.findLocalDeviceSigner(r);if(i!=null&&(yield this.checkAndResumeDeviceSigner(i))){c(this,p,i),e();let s=i.locator().replace("device:","");try{yield r.mapAddressToKey(this.address,s)}catch(l){a.warn("wallet.recover.mapAddressToKey.error",{error:l})}return}let t=yield pe(r,this.address);try{yield this.addSigner(t)}catch(s){let l=s instanceof Error&&s.message.toLowerCase().includes("delegated signer")&&s.message.toLowerCase().includes("already")&&s.message.toLowerCase().includes("approved");if(s instanceof V){a.info("wallet.recover.device.unsupportedFallback",{signerLocator:t.locator}),yield r.deleteKey(this.address),c(this,B,!0),c(this,w,!1),c(this,I,!0),yield this.assembleRecoverySignerFallback();return}else if(l)a.info("wallet.recover.skipped",{reason:"Device signer already approved",signerLocator:t.locator});else throw s instanceof ge||s instanceof Error&&s.name==="AuthRejectedError"?(a.info("wallet.recover.device.authRejected",{signerLocator:t.locator}),s):s instanceof Y||s instanceof Error&&s.name==="OtpValidationError"?(a.warn("wallet.recover.device.otpValidationFailed",{signerLocator:t.locator,code:s instanceof Y?s.code:void 0}),s):(a.error("wallet.recover.device.error",{error:s}),yield r.deleteKey(this.address),s)}c(this,p,yield this.assembleFullSigner({type:"device",locator:t.locator,address:this.address},r)),n(this,p).type==="device"&&(n(this,p).status="success"),a.info("wallet.recover.device.success",{signerLocator:t.locator}),e()})}checkAndResumeDeviceSigner(e){return d(this,null,function*(){var i;if(this.isApprovedSignerStatus(e.status))return a.info("wallet.recover.skipped",{reason:"Device signer already approved"}),!0;let r=yield this.getSignerState(e.locator());return e.status=(i=r.signer)==null?void 0:i.status,r.pendingOperation!=null?(yield this.resumePendingDeviceSignerApproval(e,r.pendingOperation),!0):this.isApprovedSignerStatus(e.status)?(a.info("wallet.recover.skipped",{reason:"Device signer already approved"}),!0):!1})}resumePendingDeviceSignerApproval(e,r){return d(this,null,function*(){var o;let i=n(this,p);if(W(n(this,v)))throw new Error('Cannot resume pending approval: no secret available. Call wallet.useSigner({ type: "server", secret: ... }) first with the recovery server secret.');if(n(this,v)!=null&&n(this,v).type==="external-wallet"&&!this.isAutoAssemblableSignerConfig(n(this,v)))throw new Error('Cannot resume pending approval: no onSign callback available. Call wallet.useSigner({ type: "external-wallet", address: "0x...", onSign: async (tx) => ... }) first.');let t=this.buildInternalSignerConfig(n(this,v));c(this,p,q(this.chain,t,(o=n(this,A))==null?void 0:o.deviceSignerKeyStorage));try{r.type==="signature"?yield this.approveSignatureAndWait(r.id):yield this.approveTransactionAndWait(r.id)}catch(h){throw c(this,p,e),h}finally{n(this,p)!==e&&c(this,p,i)}e.status="success",a.info("wallet.recover.device.success",{signerLocator:e.locator(),resumed:!0})})}findLocalDeviceSigner(e){return d(this,null,function*(){let i=(yield this.signers()).filter(t=>t.locator.startsWith("device:"));for(let t of i){let o=t.locator.replace("device:","");try{if(yield e.hasKey(o)){let s=q(this.chain,{type:"device",locator:t.locator,address:this.address},e);return a.info("wallet.recover.foundLocalDeviceSigner",{signerLocator:t.locator}),s}}catch(h){a.warn("wallet.recover.findLocalDeviceSigner.keyCheckError",{signerLocator:t.locator,error:h})}}return null})}signers(){return d(this,null,function*(){var o,h;a.info("wallet.signers.start");let e=yield n(this,f).getWallet(this.walletLocator);if("error"in e)throw a.error("wallet.signers.error",{error:e}),new X(JSON.stringify(e));if(e.type!=="smart"||e.chainType!=="evm"&&e.chainType!=="solana"&&e.chainType!=="stellar")throw a.error("wallet.signers.error",{error:`Wallet type ${e.type} not supported`}),new Q(`Wallet type ${e.type} not supported`);let r=(h=(o=e==null?void 0:e.config)==null?void 0:o.delegatedSigners)!=null?h:[],t=(yield Promise.all(r.map(s=>d(this,null,function*(){try{return(yield this.getSignerState(s.locator)).signer}catch(l){return null}})))).filter(s=>s!=null);return a.info("wallet.signers.success",{count:t.length}),t})}get walletLocator(){if(n(this,f).isServerSide)return this.address;{let e;switch(this.chain){case"stellar":e="me:stellar:smart";break;case"solana":e="me:solana:smart";break;default:e="me:evm:smart";break}let r=this.alias!=null?`:alias:${this.alias}`:"";return e+r}}requireSigner(){if(n(this,p)==null)throw n(this,R).length>1?new Error("No signer is set. This wallet has multiple signers configured. Call wallet.useSigner() to select which signer to use before signing operations."):n(this,v).type==="server"?new Error(`No signer is set. Server wallets require calling wallet.useSigner() with the server secret before signing operations.
2
2
  Example: wallet.useSigner({ type: "server", secret: process.env.YOUR_SERVER_SECRET })`):n(this,v).type==="external-wallet"||!this.isAutoAssemblableSignerConfig(n(this,v))?new Error(`No signer is set. External wallet signers require calling wallet.useSigner() with the onSign callback before signing operations.
3
3
  Example: wallet.useSigner({ type: "external-wallet", address: "0x...", onSign: async (tx) => ... })`):new Error("This wallet is read-only because no signer was provided. Operations that require signing (send, approve, addSigner, etc.) are not available.");return n(this,p)}preAuthIfNeeded(){return d(this,null,function*(){yield n(this,K),n(this,D)==null&&c(this,D,this.recover());try{yield n(this,D)}finally{c(this,D,null)}let e=this.requireSigner();e instanceof ue&&(yield e.ensureAuthenticated())})}isRecoverySigner(e){let r=n(this,v);if(r==null||r.type!==e.type||e.type==="device")return!1;if(e.type==="passkey")return!0;if(e.type==="server"&&r.type==="server"){let i=s=>{if(W(s))return[s.address];let{primary:l,legacy:g}=this.deriveServerSignerCandidates(s),u=[l.derivedAddress];return g!=null&&u.push(g.derivedAddress),u},t=i(e),o=i(r);if(!t.some(s=>o.includes(s)))return!1}else if(N(e)!==N(r))return!1;return c(this,v,e),!0}validateSignerInput(e){switch(e.type){case"email":if(!("email"in e)||e.email==null)throw new Error("Email signer requires an email address");break;case"phone":if(!("phone"in e)||e.phone==null)throw new Error("Phone signer requires a phone number");break;case"external-wallet":if(!("address"in e)||e.address==null)throw new Error("External wallet signer requires a wallet address");if(!("onSign"in e)||typeof e.onSign!="function")throw new Error("External wallet signer requires an onSign callback");break;case"passkey":case"device":case"api-key":break;default:break}}resolveDeviceSignerAvailability(e){return d(this,null,function*(){var h;let r=(h=n(this,A))==null?void 0:h.deviceSignerKeyStorage;if(r==null)throw new Error("Device signer key storage is required for device signers");let i=yield r.getKey(this.address);if(i!=null){e.locator=`device:${i}`;return}let o=(yield this.signers()).filter(s=>s.locator.startsWith("device:"));for(let s of o){let l=s.locator.replace("device:","");if(yield r.hasKey(l)){yield r.mapAddressToKey(this.address,l),e.locator=s.locator;return}}c(this,w,!0),c(this,I,!1)})}assembleFullSigner(o){return d(this,arguments,function*(e,r=(t=>(t=n(this,A))==null?void 0:t.deviceSignerKeyStorage)(),i){var s;let h=q(this.chain,e,r);if(i!=null&&i.isAdminSigner)h.status="active";else{let l=yield this.getSignerState(h.locator());h.status=(s=l.signer)==null?void 0:s.status}return h})}getSignerState(e){return d(this,null,function*(){let r=null;try{r=yield n(this,f).getSigner(this.walletLocator,e)}catch(t){return{response:null,signer:null,pendingOperation:null}}if(r==null||typeof r!="object"||"error"in r)return{response:null,signer:null,pendingOperation:null};let i=j(r,this.chain);return{response:r,signer:i,pendingOperation:z(r,this.chain)}})}buildInternalSignerConfig(e){var r,i,t,o,h,s;switch(e.type){case"email":return{type:"email",email:e.email,locator:`email:${e.email}`,address:this.address,crossmint:n(this,f).crossmint,clientTEEConnection:(r=n(this,A))==null?void 0:r.clientTEEConnection,onAuthRequired:(t=(i=n(this,A))==null?void 0:i.callbacks)==null?void 0:t.onAuthRequired};case"phone":return{type:"phone",phone:e.phone,locator:`phone:${e.phone}`,address:this.address,crossmint:n(this,f).crossmint,clientTEEConnection:(o=n(this,A))==null?void 0:o.clientTEEConnection,onAuthRequired:(s=(h=n(this,A))==null?void 0:h.callbacks)==null?void 0:s.onAuthRequired};case"passkey":{let l="id"in e&&e.id?e.id:"";return{type:"passkey",id:l,locator:`passkey:${l}`,name:"name"in e?e.name:void 0,publicKey:"publicKey"in e?e.publicKey:void 0,onCreatePasskey:e.onCreatePasskey,onSignWithPasskey:e.onSignWithPasskey}}case"device":return{type:"device",locator:"locator"in e&&e.locator?e.locator:void 0,address:this.address};case"external-wallet":return O(b({},e),{locator:`external-wallet:${e.address}`});case"api-key":return{type:"api-key",locator:"api-key",address:this.address};case"server":{let{derivedKeyBytes:l,derivedAddress:g}=this.resolveServerSignerDerivation(e);return{type:"server",derivedKeyBytes:l,locator:`server:${g}`,address:g}}default:throw new Error(`Unknown signer type: ${e==null?void 0:e.type}`)}}isAutoAssemblableSignerConfig(e){var r;switch(e.type){case"email":case"phone":case"passkey":case"api-key":return!0;case"device":return((r=n(this,A))==null?void 0:r.deviceSignerKeyStorage)!=null;case"server":return!W(e);case"external-wallet":return"onSign"in e&&typeof e.onSign=="function";default:return!1}}get isSolanaWallet(){return this.chain==="solana"}resolveChainForEnvironment(){let e=de(this.chain,n(this,f).environment);return e!==this.chain&&(this.chain=e),this.chain}approveTransactionAndWait(e,r){return d(this,null,function*(){return yield this.approveTransactionInternal(e,r),yield this.sleep(1e3),yield this.waitForTransaction(e)})}approveSignatureAndWait(e,r){return d(this,null,function*(){let i=yield this.approveSignatureInternal(e,r);return!("error"in i)&&i.status==="success"&&i.outputSignature!=null?{signature:i.outputSignature,signatureId:e}:(yield this.sleep(1e3),yield this.waitForSignature(e))})}approveSignatureInternal(e,r){return d(this,null,function*(){var l,g;if(this.isSolanaWallet)throw new Error("Approving signatures is only supported for EVM smart wallets");let i=this.requireSigner(),t=yield n(this,f).getSignature(this.walletLocator,e);if("error"in t)throw new G(JSON.stringify(t));if(i.type==="api-key")return t;if((r==null?void 0:r.approval)!=null){let u=[r.approval];return yield this.executeApproveSignatureWithErrorHandling(e,u)}let o=(l=t.approvals)==null?void 0:l.pending;if(o==null||o.length===0)return t;let h=[...(g=r==null?void 0:r.additionalSigners)!=null?g:[],i],s=yield Promise.all(o.map(u=>d(this,null,function*(){let S=h.find(C=>C.locator()===u.signer.locator);if(S==null)throw new _(`Signer ${u.signer.locator} not found in pending approvals`);let y=yield S.signMessage(u.message);return O(b({},y),{signer:S.locator()})})));return yield this.executeApproveSignatureWithErrorHandling(e,s)})}approveTransactionInternal(e,r){return d(this,null,function*(){var l,g,u,S,y;let i=yield n(this,f).getTransaction(this.walletLocator,e);if("error"in i)throw new M(JSON.stringify(i));yield(u=(g=(l=n(this,A))==null?void 0:l.callbacks)==null?void 0:g.onTransactionStart)==null?void 0:u.call(g);let t=this.requireSigner();if(t.type==="api-key")return i;if((r==null?void 0:r.approval)!=null){let C=[r.approval];return yield this.executeApproveTransactionWithErrorHandling(e,C)}let o=(S=i.approvals)==null?void 0:S.pending;if(o==null||o.length===0)return i;let h=[...(y=r==null?void 0:r.additionalSigners)!=null?y:[],t],s=yield Promise.all(o.map(C=>d(this,null,function*(){let F=h.find(fe=>fe.locator()===C.signer.locator);if(F==null)throw new _(`Signer ${C.signer.locator} not found in pending approvals`);let H=F.type==="device",J=i.chainType==="solana"&&"transaction"in i.onChain&&!H?i.onChain.transaction:C.message,ve=yield F.signTransaction(J);return O(b({},ve),{signer:F.locator()})})));return yield this.executeApproveTransactionWithErrorHandling(e,s)})}executeApproveTransactionWithErrorHandling(e,r){return d(this,null,function*(){a.info("wallet.approve: submitting approval to API",{transactionId:e});let i=yield n(this,f).approveTransaction(this.walletLocator,e,{approvals:r});if(i.error)throw new le(JSON.stringify(i));return i})}executeApproveSignatureWithErrorHandling(e,r){return d(this,null,function*(){let i=yield n(this,f).approveSignature(this.walletLocator,e,{approvals:r});if(i.error)throw new re(JSON.stringify(i));return i})}waitForSignature(e){return d(this,null,function*(){let r=null;do if(yield new Promise(i=>setTimeout(i,U)),r=yield n(this,f).getSignature(this.walletLocator,e),"error"in r)throw new G(JSON.stringify(r));while(r===null||r.status==="pending");if(r.status==="failed")throw new ee("Signature signing failed");if(!r.outputSignature)throw new G("Signature not available");return{signature:r.outputSignature,signatureId:e}})}waitForTransaction(h){return d(this,arguments,function*(e,r=6e4,{backoffMultiplier:i=1.1,maxBackoffMs:t=2e3,initialBackoffMs:o=U}={}){var S,y;a.info("wallet.approve: waiting for transaction confirmation",{transactionId:e,timeoutMs:r});let s=Date.now(),l;do{if(Date.now()-s>r)throw new ne("Transaction confirmation timeout");if(l=yield n(this,f).getTransaction(this.walletLocator,e),l.error)throw new M(JSON.stringify(l));yield this.sleep(o),o=Math.min(o*i,t)}while(l.status==="pending");if(l.status==="failed")throw new se(`Transaction sending failed: ${JSON.stringify(l.error)}`);if(l.status==="awaiting-approval")throw new ae("Transaction is awaiting approval. Please submit required approvals before waiting for completion.");let g="txHash"in l.onChain&&typeof l.onChain.txHash=="string"?l.onChain.txHash:void 0,u=(S=l.onChain.txId)!=null?S:g;if(u==null)throw new oe("Transaction hash not found on transaction response");return{hash:u,explorerLink:(y=l.onChain.explorerLink)!=null?y:"",transactionId:l.id}})}sleep(e){return d(this,null,function*(){return new Promise(r=>setTimeout(r,e))})}};p=new WeakMap,A=new WeakMap,f=new WeakMap,v=new WeakMap,R=new WeakMap,w=new WeakMap,I=new WeakMap,x=new WeakMap,L=new WeakMap,$=new WeakMap,K=new WeakMap,D=new WeakMap,B=new WeakMap,k([P({logger:a,methodName:"wallet.balances",buildContext(e){return{chain:e.chain,address:e.address}}})],E.prototype,"balances",1),k([P({logger:a,methodName:"wallet.stagingFund",buildContext(e){return{chain:e.chain,address:e.address}}})],E.prototype,"stagingFund",1),k([P({logger:a,methodName:"wallet.send",buildContext(e){return{chain:e.chain,address:e.address}}})],E.prototype,"send",1),k([P({logger:a,methodName:"wallet.approve",buildContext(e){return{chain:e.chain,address:e.address}}})],E.prototype,"approve",1),k([P({logger:a,methodName:"wallet.addSigner",buildContext(e){return{chain:e.chain,address:e.address}}})],E.prototype,"addSigner",1),k([P({logger:a,methodName:"wallet.removeSigner",buildContext(e){return{chain:e.chain,address:e.address}}})],E.prototype,"removeSigner",1),k([P({logger:a,methodName:"wallet.useSigner",buildContext(e){return{chain:e.chain,address:e.address}}})],E.prototype,"useSigner",1),k([P({logger:a,methodName:"wallet.recover",buildContext(e){return{chain:e.chain,address:e.address}}})],E.prototype,"recover",1),k([P({logger:a,methodName:"wallet.signers",buildContext(e){return{chain:e.chain,address:e.address}}})],E.prototype,"signers",1);function we(m){if(typeof m=="string"){if(!Se(m))throw new ce(`Invalid recipient address: "${m}". Expected a valid EVM (0x...), Solana (base58), or Stellar (G.../C...) address.`);return m}if("email"in m)return`email:${m.email}`;if("x"in m)return`x:${m.x}`;if("twitter"in m)return`twitter:${m.twitter}`;if("phone"in m)return`phoneNumber:${m.phone}`;if("userId"in m)return`userId:${m.userId}`;throw new Error("Invalid recipient locator")}function ye(m,e){return Se(m)?`${e}:${m}`:`${e}:${m.toLowerCase()}`}export{E as a};
@@ -0,0 +1 @@
1
+ import{a as i}from"./chunk-MDINF2FR.js";import{a as t}from"./chunk-OQZTL6ZG.js";import{a as n}from"./chunk-XNZLCUTY.js";function f(s){if(typeof window!="undefined")throw new Error("Server signers can only be used from server-side code.");let{secret:o,chain:e,projectId:a,environment:d}=s,c=t(e),r=n(o,a,d,c);return{type:"server",address:i(r,e),keyBytes:r}}export{f as a};
@@ -1 +1 @@
1
- import{a as i}from"./chunk-QTCM42EB.js";import{v as u}from"./chunk-5OYPWGMX.js";import{a as t}from"./chunk-VOVJ4RNT.js";import{a as f,c,g as s}from"./chunk-J3R36SGJ.js";import{isValidStellarAddress as T,WithLoggerContext as g}from"@crossmint/common-sdk-base";var m=409,l=class l extends i{constructor(e){super({chain:e.chain,address:e.address,owner:e.owner,options:i.getOptions(e),alias:e.alias,recovery:i.getRecovery(e),apiRecoveryServerSignerAddress:i.getApiRecoveryServerSignerAddress(e),apiDelegatedServerSignerAddresses:i.getApiDelegatedServerSignerAddresses(e),signer:e.signer,signers:i.getInitialSigners(e)},i.getApiClient(e))}static from(e){if(!T(e.address))throw new Error("Wallet is not a Stellar wallet");return new l(e)}sendTransaction(e){return s(this,null,function*(){var d;t.info("stellarWallet.sendTransaction.start"),yield this.preAuthIfNeeded();let r=yield this.createTransaction(e);if((d=e.options)!=null&&d.prepareOnly)return t.info("stellarWallet.sendTransaction.prepared",{transactionId:r.id}),{hash:void 0,explorerLink:void 0,transactionId:r.id};let a={},n=yield this.approveTransactionAndWait(r.id,a);return t.info("stellarWallet.sendTransaction.success",{transactionId:r.id,hash:n.hash}),n})}upgrade(e){return s(this,null,function*(){t.info("stellarWallet.upgrade.start"),yield this.preAuthIfNeeded();let r=yield this.createWalletLifecycleTransaction("upgrade-wallet",e);if(r!=null){if(e!=null&&e.prepareOnly)return t.info("stellarWallet.upgrade.prepared",{transactionId:r}),{hash:void 0,explorerLink:void 0,transactionId:r};yield this.approveTransactionAndWait(r),t.info("stellarWallet.upgrade.phase1.success",{transactionId:r})}else t.info("stellarWallet.upgrade.phase1.skipped",{reason:"wallet already locked from a prior upgrade"});let a=yield this.migrateInternal({signer:e==null?void 0:e.signer,prepareOnly:e==null?void 0:e.prepareOnly});return t.info("stellarWallet.upgrade.success",{transactionId:a.transactionId,hash:a.hash}),a})}migrate(e){return s(this,null,function*(){return yield this.preAuthIfNeeded(),yield this.migrateInternal(e)})}migrateInternal(e){return s(this,null,function*(){t.info("stellarWallet.migrate.start");let r=yield this.createWalletLifecycleTransaction("migrate-wallet",e);if(r==null)throw new u("Failed to create migrate-wallet transaction");if(e!=null&&e.prepareOnly)return t.info("stellarWallet.migrate.prepared",{transactionId:r}),{hash:void 0,explorerLink:void 0,transactionId:r};let a=yield this.approveTransactionAndWait(r);return t.info("stellarWallet.migrate.success",{transactionId:r,hash:a.hash}),a})}createTransaction(e){return s(this,null,function*(){let{contractId:r,options:a}=e,n=this.resolveStellarSigner(a==null?void 0:a.signer),d="transaction"in e?{type:"serialized-transaction",serializedTransaction:e.transaction,contractId:r}:{type:"contract-call",contractId:r,method:e.method,memo:e.memo!=null?{type:"text",value:e.memo}:void 0,args:e.args},p=yield this.apiClient.createTransaction(this.walletLocator,{params:{transaction:d,signer:n}});if("error"in p)throw new u(JSON.stringify(p));return p})}createWalletLifecycleTransaction(e,r){return s(this,null,function*(){let a=(r==null?void 0:r.signer)!=null?this.resolveStellarSigner(r.signer):void 0,n=yield this.apiClient.createTransaction(this.walletLocator,{params:f({transaction:{type:e}},a!=null?{signer:a}:{})});if("error"in n){if(e==="upgrade-wallet"&&y(n))return null;throw new u(JSON.stringify(n))}return n.id})}resolveStellarSigner(e){return e==null?this.requireSigner().locator():typeof e=="string"?e:this.resolveServerSignerApiLocator(e)}};c([g({logger:t,methodName:"stellarWallet.sendTransaction",buildContext(e){return{chain:e.chain,address:e.address}}})],l.prototype,"sendTransaction",1),c([g({logger:t,methodName:"stellarWallet.upgrade",buildContext(e){return{chain:e.chain,address:e.address}}})],l.prototype,"upgrade",1),c([g({logger:t,methodName:"stellarWallet.migrate",buildContext(e){return{chain:e.chain,address:e.address}}})],l.prototype,"migrate",1);var h=l;function y(o){return typeof o=="object"&&o!==null&&"statusCode"in o&&o.statusCode===m}export{h as a};
1
+ import{a as i}from"./chunk-ACI6AVBC.js";import{v as u}from"./chunk-5OYPWGMX.js";import{a as t}from"./chunk-RFWG2QIH.js";import{a as f,c,g as s}from"./chunk-J3R36SGJ.js";import{isValidStellarAddress as T,WithLoggerContext as g}from"@crossmint/common-sdk-base";var m=409,l=class l extends i{constructor(e){super({chain:e.chain,address:e.address,owner:e.owner,options:i.getOptions(e),alias:e.alias,recovery:i.getRecovery(e),apiRecoveryServerSignerAddress:i.getApiRecoveryServerSignerAddress(e),apiDelegatedServerSignerAddresses:i.getApiDelegatedServerSignerAddresses(e),signer:e.signer,signers:i.getInitialSigners(e)},i.getApiClient(e))}static from(e){if(!T(e.address))throw new Error("Wallet is not a Stellar wallet");return new l(e)}sendTransaction(e){return s(this,null,function*(){var d;t.info("stellarWallet.sendTransaction.start"),yield this.preAuthIfNeeded();let r=yield this.createTransaction(e);if((d=e.options)!=null&&d.prepareOnly)return t.info("stellarWallet.sendTransaction.prepared",{transactionId:r.id}),{hash:void 0,explorerLink:void 0,transactionId:r.id};let a={},n=yield this.approveTransactionAndWait(r.id,a);return t.info("stellarWallet.sendTransaction.success",{transactionId:r.id,hash:n.hash}),n})}upgrade(e){return s(this,null,function*(){t.info("stellarWallet.upgrade.start"),yield this.preAuthIfNeeded();let r=yield this.createWalletLifecycleTransaction("upgrade-wallet",e);if(r!=null){if(e!=null&&e.prepareOnly)return t.info("stellarWallet.upgrade.prepared",{transactionId:r}),{hash:void 0,explorerLink:void 0,transactionId:r};yield this.approveTransactionAndWait(r),t.info("stellarWallet.upgrade.phase1.success",{transactionId:r})}else t.info("stellarWallet.upgrade.phase1.skipped",{reason:"wallet already locked from a prior upgrade"});let a=yield this.migrateInternal({signer:e==null?void 0:e.signer,prepareOnly:e==null?void 0:e.prepareOnly});return t.info("stellarWallet.upgrade.success",{transactionId:a.transactionId,hash:a.hash}),a})}migrate(e){return s(this,null,function*(){return yield this.preAuthIfNeeded(),yield this.migrateInternal(e)})}migrateInternal(e){return s(this,null,function*(){t.info("stellarWallet.migrate.start");let r=yield this.createWalletLifecycleTransaction("migrate-wallet",e);if(r==null)throw new u("Failed to create migrate-wallet transaction");if(e!=null&&e.prepareOnly)return t.info("stellarWallet.migrate.prepared",{transactionId:r}),{hash:void 0,explorerLink:void 0,transactionId:r};let a=yield this.approveTransactionAndWait(r);return t.info("stellarWallet.migrate.success",{transactionId:r,hash:a.hash}),a})}createTransaction(e){return s(this,null,function*(){let{contractId:r,options:a}=e,n=this.resolveStellarSigner(a==null?void 0:a.signer),d="transaction"in e?{type:"serialized-transaction",serializedTransaction:e.transaction,contractId:r}:{type:"contract-call",contractId:r,method:e.method,memo:e.memo!=null?{type:"text",value:e.memo}:void 0,args:e.args},p=yield this.apiClient.createTransaction(this.walletLocator,{params:{transaction:d,signer:n}});if("error"in p)throw new u(JSON.stringify(p));return p})}createWalletLifecycleTransaction(e,r){return s(this,null,function*(){let a=(r==null?void 0:r.signer)!=null?this.resolveStellarSigner(r.signer):void 0,n=yield this.apiClient.createTransaction(this.walletLocator,{params:f({transaction:{type:e}},a!=null?{signer:a}:{})});if("error"in n){if(e==="upgrade-wallet"&&y(n))return null;throw new u(JSON.stringify(n))}return n.id})}resolveStellarSigner(e){return e==null?this.requireSigner().locator():typeof e=="string"?e:this.resolveServerSignerApiLocator(e)}};c([g({logger:t,methodName:"stellarWallet.sendTransaction",buildContext(e){return{chain:e.chain,address:e.address}}})],l.prototype,"sendTransaction",1),c([g({logger:t,methodName:"stellarWallet.upgrade",buildContext(e){return{chain:e.chain,address:e.address}}})],l.prototype,"upgrade",1),c([g({logger:t,methodName:"stellarWallet.migrate",buildContext(e){return{chain:e.chain,address:e.address}}})],l.prototype,"migrate",1);var h=l;function y(o){return typeof o=="object"&&o!==null&&"statusCode"in o&&o.statusCode===m}export{h as a};
File without changes
@@ -1 +1 @@
1
- import{a as s,b as o}from"./chunk-4KGM7M2B.js";import{a as r}from"./chunk-VOVJ4RNT.js";import{g as t}from"./chunk-J3R36SGJ.js";import{VersionedTransaction as u}from"@solana/web3.js";import a from"bs58";var g=class c extends s{constructor(n){super(n)}signMessage(){return t(this,null,function*(){return yield Promise.reject(new Error("signMessage method not implemented for email signer"))})}signTransaction(n){return t(this,null,function*(){var i;yield this.handleAuthRequired();let d=this.getJwtOrThrow(),m=a.decode(n),y=u.deserialize(m).message.serialize();r.info("sign: sending request",{keyType:"ed25519"});let l=Date.now(),e=yield(i=this.config.clientTEEConnection)==null?void 0:i.sendAction({event:"request:sign",responseEvent:"response:sign",data:{authData:{jwt:d,apiKey:this.config.crossmint.apiKey},data:{keyType:"ed25519",bytes:a.encode(new Uint8Array(y)),encoding:"base58"}},options:o});if(r.info("sign: response received",{status:e==null?void 0:e.status,durationMs:Date.now()-l}),(e==null?void 0:e.status)==="error")throw new Error(e.error);if((e==null?void 0:e.signature)==null)throw new Error("Failed to sign transaction");return c.verifyPublicKeyFormat(e.publicKey),{signature:e.signature.bytes}})}static verifyPublicKeyFormat(n){if(n==null)throw new Error("No public key found");if(n.encoding!=="base58"||n.keyType!=="ed25519"||n.bytes==null)throw new Error("Not supported. Expected public key to be in base58 encoding and ed25519 key type. Got: "+JSON.stringify(n))}getChainKeyParams(){return{scheme:"ed25519",encoding:"base58"}}};export{g as a};
1
+ import{a as s,b as o}from"./chunk-NBPZ3T3M.js";import{a as r}from"./chunk-RFWG2QIH.js";import{g as t}from"./chunk-J3R36SGJ.js";import{VersionedTransaction as u}from"@solana/web3.js";import a from"bs58";var g=class c extends s{constructor(n){super(n)}signMessage(){return t(this,null,function*(){return yield Promise.reject(new Error("signMessage method not implemented for email signer"))})}signTransaction(n){return t(this,null,function*(){var i;yield this.handleAuthRequired();let d=this.getJwtOrThrow(),m=a.decode(n),y=u.deserialize(m).message.serialize();r.info("sign: sending request",{keyType:"ed25519"});let l=Date.now(),e=yield(i=this.config.clientTEEConnection)==null?void 0:i.sendAction({event:"request:sign",responseEvent:"response:sign",data:{authData:{jwt:d,apiKey:this.config.crossmint.apiKey},data:{keyType:"ed25519",bytes:a.encode(new Uint8Array(y)),encoding:"base58"}},options:o});if(r.info("sign: response received",{status:e==null?void 0:e.status,durationMs:Date.now()-l}),(e==null?void 0:e.status)==="error")throw new Error(e.error);if((e==null?void 0:e.signature)==null)throw new Error("Failed to sign transaction");return c.verifyPublicKeyFormat(e.publicKey),{signature:e.signature.bytes}})}static verifyPublicKeyFormat(n){if(n==null)throw new Error("No public key found");if(n.encoding!=="base58"||n.keyType!=="ed25519"||n.bytes==null)throw new Error("Not supported. Expected public key to be in base58 encoding and ed25519 key type. Got: "+JSON.stringify(n))}getChainKeyParams(){return{scheme:"ed25519",encoding:"base58"}}};export{g as a};
@@ -1 +1 @@
1
- import{a as S}from"./chunk-6X5JEJD7.js";import{a as l}from"./chunk-WDLFZXBG.js";import{a as i}from"./chunk-3ISCHYRJ.js";import{a as t}from"./chunk-7SSRCAY5.js";import{a as C}from"./chunk-EE4ITUGS.js";import{a as u}from"./chunk-CKZYSQOK.js";import{a as p}from"./chunk-QVTKTDED.js";import{a as s}from"./chunk-XS5B3TUE.js";import{a as m}from"./chunk-M335XCYO.js";import{a as g}from"./chunk-YH7G2U6V.js";import{a as o}from"./chunk-2O6HQK34.js";import{g as a}from"./chunk-5OYPWGMX.js";function V(r,e,n){switch(e.type){case"email":case"phone":return r==="solana"?new t(e):r==="stellar"?new l(e):new i(e);case"api-key":return r==="solana"?new g(e):new p(e);case"external-wallet":return r==="solana"?new o(e):r==="stellar"?new C(e):new s(e);case"server":return S(r,e);case"passkey":return new m(e);case"device":if(n==null)throw new a("Device signer key storage is required for device signers");return new u(e,n)}}export{V as a};
1
+ import{a as S}from"./chunk-6X5JEJD7.js";import{a as l}from"./chunk-7M2KPJVJ.js";import{a as i}from"./chunk-ABNALSRA.js";import{a as t}from"./chunk-FWKQEP6I.js";import{a as C}from"./chunk-EE4ITUGS.js";import{a as u}from"./chunk-CKZYSQOK.js";import{a as p}from"./chunk-QVTKTDED.js";import{a as s}from"./chunk-XS5B3TUE.js";import{a as m}from"./chunk-M335XCYO.js";import{a as g}from"./chunk-YH7G2U6V.js";import{a as o}from"./chunk-2O6HQK34.js";import{g as a}from"./chunk-5OYPWGMX.js";function V(r,e,n){switch(e.type){case"email":case"phone":return r==="solana"?new t(e):r==="stellar"?new l(e):new i(e);case"api-key":return r==="solana"?new g(e):new p(e);case"external-wallet":return r==="solana"?new o(e):r==="stellar"?new C(e):new s(e);case"server":return S(r,e);case"passkey":return new m(e);case"device":if(n==null)throw new a("Device signer key storage is required for device signers");return new u(e,n)}}export{V as a};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunk6EUBBDIVcjs = require('./chunk-6EUBBDIV.cjs');var _chunkJ4IMLBTScjs = require('./chunk-J4IMLBTS.cjs');var _chunkYHV3672Rcjs = require('./chunk-YHV3672R.cjs');var _chunkNX256LAHcjs = require('./chunk-NX256LAH.cjs');var _chunkI3RWATD5cjs = require('./chunk-I3RWATD5.cjs');var _chunkJJIGKUQAcjs = require('./chunk-JJIGKUQA.cjs');var _chunkOWQZPI3Ucjs = require('./chunk-OWQZPI3U.cjs');var _chunkSFXFZ2J5cjs = require('./chunk-SFXFZ2J5.cjs');var _chunk2GKPWQBQcjs = require('./chunk-2GKPWQBQ.cjs');var _commonsdkbase = require('@crossmint/common-sdk-base');var _ox = require('ox');var $="When 'signers' is provided to a method that may fetch an existing wallet, each specified signer must exist in that wallet's configuration.",u= exports.a =class{constructor(r){this.apiClient=r}getWallet(r,e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){let i,t;if(typeof r=="string"){if(!this.apiClient.isServerSide)throw new (0, _chunkOWQZPI3Ucjs.g)("getWallet with walletLocator is only available on the server side. Use getWallet(args) instead.");if(e==null)throw new (0, _chunkOWQZPI3Ucjs.g)("Wallet configuration is required when using walletLocator: https://docs.crossmint.com/sdk-reference/wallets/type-aliases/WalletArgsFor");i=r,t=e}else{if(this.apiClient.isServerSide)throw new (0, _chunkOWQZPI3Ucjs.g)("getWallet on server side requires a walletLocator parameter. Use getWallet(walletLocator, args) instead.");t=r,i=this.getWalletLocator(t)}let a=_chunk2GKPWQBQcjs.b.call(void 0, _chunk2GKPWQBQcjs.a.call(void 0, {},t),{chain:_chunkJJIGKUQAcjs.f.call(void 0, t.chain,this.apiClient.environment)});_chunkSFXFZ2J5cjs.a.info("walletFactory.getWallet.start");let n=yield this.apiClient.getWallet(i);if("error"in n)throw _chunkSFXFZ2J5cjs.a.warn("walletFactory.getWallet.notFound",{error:n.error}),new (0, _chunkOWQZPI3Ucjs.e)(JSON.stringify(n));return _chunkSFXFZ2J5cjs.a.info("walletFactory.getWallet.success",{address:n.address}),yield this.createWalletInstance(n,a)})}createWallet(r){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){var o,c,d,h,C,p,F,P;let e=_chunk2GKPWQBQcjs.b.call(void 0, _chunk2GKPWQBQcjs.a.call(void 0, {},r),{chain:_chunkJJIGKUQAcjs.f.call(void 0, r.chain,this.apiClient.environment)});if(yield(d=(c=(o=e.options)==null?void 0:o.callbacks)==null?void 0:c.onWalletCreationStart)==null?void 0:d.call(c),_chunkSFXFZ2J5cjs.a.info("walletFactory.createWallet.start"),!this.apiClient.isServerSide&&e.owner!=null)throw _chunkSFXFZ2J5cjs.a.error("walletFactory.createWallet.error",{error:"Owner field cannot be specified in client-side createWallet calls"}),new (0, _chunkOWQZPI3Ucjs.g)("Owner field cannot be specified in client-side createWallet calls. Owner is determined from JWT authentication.");let t=((h=e.options)==null?void 0:h.deviceSignerKeyStorage)!=null&&e.chain!=="solana"?this.ensureDeviceSignerInSigners(e):(C=e.signers)!=null?C:[],a=yield this.registerSigners(t,e.chain,(p=e.options)==null?void 0:p.deviceSignerKeyStorage),n;if(e.recovery.type==="passkey"&&e.recovery.id==null)n=yield this.createPasskeySigner(e.recovery);else if(e.recovery.type==="server"){let{derivedAddress:I}=_chunkI3RWATD5cjs.b.call(void 0, e.recovery,e.chain,this.apiClient.projectId,this.apiClient.environment);n={type:"server",address:I}}else n=e.recovery;let s=yield this.apiClient.createWallet({type:"smart",chainType:this.getChainType(e.chain),config:_chunk2GKPWQBQcjs.a.call(void 0, _chunk2GKPWQBQcjs.a.call(void 0, {adminSigner:n},e.plugins?{plugins:e.plugins}:{}),a!=null?{delegatedSigners:a}:{}),owner:(F=e.owner)!=null?F:void 0,alias:(P=e.alias)!=null?P:void 0});if("error"in s)throw _chunkSFXFZ2J5cjs.a.error("walletFactory.createWallet.error",{error:s.error}),new (0, _chunkOWQZPI3Ucjs.g)(JSON.stringify(s));return _chunkSFXFZ2J5cjs.a.info("walletFactory.createWallet.success",{address:s.address}),yield this.createWalletInstance(s,e)})}createWalletInstance(r,e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){var h,C;this.validateExistingWalletConfig(r,e);let i=e,t=r.config.adminSigner,a=((h=i.recovery)==null?void 0:h.type)==="server"||((C=i.recovery)==null?void 0:C.type)==="external-wallet"?i.recovery:t,n=r.config.delegatedSigners,s=n;s!=null&&s.length===1&&(s[0].type==="server"||s[0].type==="external-wallet")&&(s=i.signers);let o=t.type==="server"&&"address"in t&&!("secret"in t)?t.address:void 0,c=(n!=null?n:[]).filter(p=>p.type==="server"&&"address"in p&&!("secret"in p)).map(p=>p.address),d=new (0, _chunkJ4IMLBTScjs.a)({chain:e.chain,address:r.address,owner:r.owner,options:e.options,alias:e.alias,recovery:a,apiRecoveryServerSignerAddress:o,apiDelegatedServerSignerAddresses:c,signers:s!=null?s:[]},this.apiClient);return yield d.waitForInit(),d})}getWalletLocator(r){return`me:${this.getChainType(r.chain)}:smart`+(r.alias!=null?`:alias:${r.alias}`:"")}createPasskeySigner(r){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){var t;if(r.type!=="passkey")throw new Error("Signer is not a passkey");let e=(t=r.name)!=null?t:`Crossmint Wallet ${Date.now()}`,i=r.onCreatePasskey?yield r.onCreatePasskey(e):yield _ox.WebAuthnP256.createCredential({name:e});return{type:"passkey",id:i.id,name:e,publicKey:{x:i.publicKey.x.toString(),y:i.publicKey.y.toString()}}})}ensureDeviceSignerInSigners(r){var t;let e=(t=r.signers)!=null?t:[];return e.some(a=>a.type==="device")?e:[...e,{type:"device"}]}validateExistingWalletConfig(r,e){if(e.owner!=null&&r.owner!=null&&_chunk6EUBBDIVcjs.a.call(void 0, e.owner)!==_chunk6EUBBDIVcjs.a.call(void 0, r.owner))throw new (0, _chunkOWQZPI3Ucjs.g)("Wallet owner does not match existing wallet's linked user");if(e.chain==="solana"&&r.chainType!=="solana"||e.chain!=="solana"&&r.chainType==="solana"||e.chain==="stellar"&&r.chainType!=="stellar"||e.chain!=="stellar"&&r.chainType==="stellar")throw new (0, _chunkOWQZPI3Ucjs.g)(`Wallet chain does not match existing wallet's chain. You must use chain: ${r.chainType}.`);if(r.type!=="smart")return;let i=e;if(i.recovery!=null||i.signers!=null){let t=r.config,a=t==null?void 0:t.adminSigner;if(i.recovery!=null&&a!=null){if(i.recovery.type!==a.type)throw new (0, _chunkOWQZPI3Ucjs.g)("The wallet recovery signer type does not match the existing wallet's recovery signer type");_chunk6EUBBDIVcjs.b.call(void 0, i.recovery,a)}let n=i.signers;n!=null&&this.validateSigners(r,n,e.chain)}}validateSigners(r,e,i){let t=r.config,a=t==null?void 0:t.delegatedSigners;if(e.length!==0){if(a==null||a.length===0)throw new (0, _chunkOWQZPI3Ucjs.g)(`${e.length} signer(s) specified, but wallet "${r.address}" has no signers. ${$}`);for(let n of e){let s=a.find(o=>{if(this.isMatchingPasskeySigner(n,o,t)||o.type==="device"&&n.type==="device")return!0;if(n.type==="server"){let{primary:c,legacy:d}=_chunkI3RWATD5cjs.c.call(void 0, n,i,this.apiClient.projectId,this.apiClient.environment);return o.locator===`server:${c.derivedAddress}`||d!=null&&o.locator===`server:${d.derivedAddress}`}return o.locator===_chunkNX256LAHcjs.a.call(void 0, n)});if(s==null){let o=a.map(c=>c.locator).join(", ");throw new (0, _chunkOWQZPI3Ucjs.g)(`Signer '${n.type}' does not exist in wallet "${r.address}". Available signers: ${o}. ${$}`)}_chunk6EUBBDIVcjs.b.call(void 0, n,s)}}}isMatchingPasskeySigner(r,e,i){var a,n;let t=((n=(a=i.delegatedSigners)==null?void 0:a.filter(s=>s.type==="passkey").length)!=null?n:0)+(i.adminSigner.type==="passkey"?1:0);if(r.type==="passkey"){if(r.id==null&&t===1)return e.type==="passkey";if(r.id==null&&t>1)throw new (0, _chunkOWQZPI3Ucjs.g)("When creating a wallet with multiple passkeys, you must provide the passkey ID for each passkey.")}return!1}registerSigners(r,e,i){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){var t;return yield Promise.all((t=r==null?void 0:r.map(a=>_chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){if(a.type==="passkey")return a.id==null?{signer:yield this.createPasskeySigner(a)}:{signer:a};if(a.type==="device"){if(a.publicKey!=null)return{signer:{type:"device",publicKey:a.publicKey,name:a.name}};if(a.locator!=null)return{signer:a.locator};if(i==null)throw new (0, _chunkOWQZPI3Ucjs.g)("Device signer key storage is required for device signers");let n=yield _chunkYHV3672Rcjs.a.call(void 0, i);return{signer:{type:"device",publicKey:n.publicKey,name:n.name}}}if(a.type==="server"&&e!=null){let{derivedAddress:n}=_chunkI3RWATD5cjs.b.call(void 0, a,e,this.apiClient.projectId,this.apiClient.environment);return{signer:`server:${n}`}}return{signer:_chunkNX256LAHcjs.a.call(void 0, a)}})))!=null?t:[])})}getChainType(r){return r==="solana"?"solana":r==="stellar"?"stellar":"evm"}};_chunk2GKPWQBQcjs.c.call(void 0, [_commonsdkbase.WithLoggerContext.call(void 0, {logger:_chunkSFXFZ2J5cjs.a,methodName:"walletFactory.getWallet",buildContext(r,e){if(typeof e[0]=="string"){let t=e[1];return{walletLocator:e[0],chain:t==null?void 0:t.chain}}let i=e[0];return{chain:i==null?void 0:i.chain}}})],u.prototype,"getWallet",1),_chunk2GKPWQBQcjs.c.call(void 0, [_commonsdkbase.WithLoggerContext.call(void 0, {logger:_chunkSFXFZ2J5cjs.a,methodName:"walletFactory.createWallet",buildContext(r,e){return{chain:e[0].chain}}})],u.prototype,"createWallet",1);exports.a = u;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunk6EUBBDIVcjs = require('./chunk-6EUBBDIV.cjs');var _chunkSFYQFNRCcjs = require('./chunk-SFYQFNRC.cjs');var _chunkYHV3672Rcjs = require('./chunk-YHV3672R.cjs');var _chunkNX256LAHcjs = require('./chunk-NX256LAH.cjs');var _chunkQ4EIDR3Acjs = require('./chunk-Q4EIDR3A.cjs');var _chunkRHAM7DUEcjs = require('./chunk-RHAM7DUE.cjs');var _chunkOWQZPI3Ucjs = require('./chunk-OWQZPI3U.cjs');var _chunkJLTD3KKUcjs = require('./chunk-JLTD3KKU.cjs');var _chunk2GKPWQBQcjs = require('./chunk-2GKPWQBQ.cjs');var _commonsdkbase = require('@crossmint/common-sdk-base');var _ox = require('ox');var $="When 'signers' is provided to a method that may fetch an existing wallet, each specified signer must exist in that wallet's configuration.",u= exports.a =class{constructor(r){this.apiClient=r}getWallet(r,e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){let i,t;if(typeof r=="string"){if(!this.apiClient.isServerSide)throw new (0, _chunkOWQZPI3Ucjs.g)("getWallet with walletLocator is only available on the server side. Use getWallet(args) instead.");if(e==null)throw new (0, _chunkOWQZPI3Ucjs.g)("Wallet configuration is required when using walletLocator: https://docs.crossmint.com/sdk-reference/wallets/type-aliases/WalletArgsFor");i=r,t=e}else{if(this.apiClient.isServerSide)throw new (0, _chunkOWQZPI3Ucjs.g)("getWallet on server side requires a walletLocator parameter. Use getWallet(walletLocator, args) instead.");t=r,i=this.getWalletLocator(t)}let a=_chunk2GKPWQBQcjs.b.call(void 0, _chunk2GKPWQBQcjs.a.call(void 0, {},t),{chain:_chunkRHAM7DUEcjs.f.call(void 0, t.chain,this.apiClient.environment)});_chunkJLTD3KKUcjs.a.info("walletFactory.getWallet.start");let n=yield this.apiClient.getWallet(i);if("error"in n)throw _chunkJLTD3KKUcjs.a.warn("walletFactory.getWallet.notFound",{error:n.error}),new (0, _chunkOWQZPI3Ucjs.e)(JSON.stringify(n));return _chunkJLTD3KKUcjs.a.info("walletFactory.getWallet.success",{address:n.address}),yield this.createWalletInstance(n,a)})}createWallet(r){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){var o,c,d,h,C,p,F,P;let e=_chunk2GKPWQBQcjs.b.call(void 0, _chunk2GKPWQBQcjs.a.call(void 0, {},r),{chain:_chunkRHAM7DUEcjs.f.call(void 0, r.chain,this.apiClient.environment)});if(yield(d=(c=(o=e.options)==null?void 0:o.callbacks)==null?void 0:c.onWalletCreationStart)==null?void 0:d.call(c),_chunkJLTD3KKUcjs.a.info("walletFactory.createWallet.start"),!this.apiClient.isServerSide&&e.owner!=null)throw _chunkJLTD3KKUcjs.a.error("walletFactory.createWallet.error",{error:"Owner field cannot be specified in client-side createWallet calls"}),new (0, _chunkOWQZPI3Ucjs.g)("Owner field cannot be specified in client-side createWallet calls. Owner is determined from JWT authentication.");let t=((h=e.options)==null?void 0:h.deviceSignerKeyStorage)!=null&&e.chain!=="solana"?this.ensureDeviceSignerInSigners(e):(C=e.signers)!=null?C:[],a=yield this.registerSigners(t,e.chain,(p=e.options)==null?void 0:p.deviceSignerKeyStorage),n;if(e.recovery.type==="passkey"&&e.recovery.id==null)n=yield this.createPasskeySigner(e.recovery);else if(e.recovery.type==="server"){let{derivedAddress:I}=_chunkQ4EIDR3Acjs.b.call(void 0, e.recovery,e.chain,this.apiClient.projectId,this.apiClient.environment);n={type:"server",address:I}}else n=e.recovery;let s=yield this.apiClient.createWallet({type:"smart",chainType:this.getChainType(e.chain),config:_chunk2GKPWQBQcjs.a.call(void 0, _chunk2GKPWQBQcjs.a.call(void 0, {adminSigner:n},e.plugins?{plugins:e.plugins}:{}),a!=null?{delegatedSigners:a}:{}),owner:(F=e.owner)!=null?F:void 0,alias:(P=e.alias)!=null?P:void 0});if("error"in s)throw _chunkJLTD3KKUcjs.a.error("walletFactory.createWallet.error",{error:s.error}),new (0, _chunkOWQZPI3Ucjs.g)(JSON.stringify(s));return _chunkJLTD3KKUcjs.a.info("walletFactory.createWallet.success",{address:s.address}),yield this.createWalletInstance(s,e)})}createWalletInstance(r,e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){var h,C;this.validateExistingWalletConfig(r,e);let i=e,t=r.config.adminSigner,a=((h=i.recovery)==null?void 0:h.type)==="server"||((C=i.recovery)==null?void 0:C.type)==="external-wallet"?i.recovery:t,n=r.config.delegatedSigners,s=n;s!=null&&s.length===1&&(s[0].type==="server"||s[0].type==="external-wallet")&&(s=i.signers);let o=t.type==="server"&&"address"in t&&!("secret"in t)?t.address:void 0,c=(n!=null?n:[]).filter(p=>p.type==="server"&&"address"in p&&!("secret"in p)).map(p=>p.address),d=new (0, _chunkSFYQFNRCcjs.a)({chain:e.chain,address:r.address,owner:r.owner,options:e.options,alias:e.alias,recovery:a,apiRecoveryServerSignerAddress:o,apiDelegatedServerSignerAddresses:c,signers:s!=null?s:[]},this.apiClient);return yield d.waitForInit(),d})}getWalletLocator(r){return`me:${this.getChainType(r.chain)}:smart`+(r.alias!=null?`:alias:${r.alias}`:"")}createPasskeySigner(r){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){var t;if(r.type!=="passkey")throw new Error("Signer is not a passkey");let e=(t=r.name)!=null?t:`Crossmint Wallet ${Date.now()}`,i=r.onCreatePasskey?yield r.onCreatePasskey(e):yield _ox.WebAuthnP256.createCredential({name:e});return{type:"passkey",id:i.id,name:e,publicKey:{x:i.publicKey.x.toString(),y:i.publicKey.y.toString()}}})}ensureDeviceSignerInSigners(r){var t;let e=(t=r.signers)!=null?t:[];return e.some(a=>a.type==="device")?e:[...e,{type:"device"}]}validateExistingWalletConfig(r,e){if(e.owner!=null&&r.owner!=null&&_chunk6EUBBDIVcjs.a.call(void 0, e.owner)!==_chunk6EUBBDIVcjs.a.call(void 0, r.owner))throw new (0, _chunkOWQZPI3Ucjs.g)("Wallet owner does not match existing wallet's linked user");if(e.chain==="solana"&&r.chainType!=="solana"||e.chain!=="solana"&&r.chainType==="solana"||e.chain==="stellar"&&r.chainType!=="stellar"||e.chain!=="stellar"&&r.chainType==="stellar")throw new (0, _chunkOWQZPI3Ucjs.g)(`Wallet chain does not match existing wallet's chain. You must use chain: ${r.chainType}.`);if(r.type!=="smart")return;let i=e;if(i.recovery!=null||i.signers!=null){let t=r.config,a=t==null?void 0:t.adminSigner;if(i.recovery!=null&&a!=null){if(i.recovery.type!==a.type)throw new (0, _chunkOWQZPI3Ucjs.g)("The wallet recovery signer type does not match the existing wallet's recovery signer type");_chunk6EUBBDIVcjs.b.call(void 0, i.recovery,a)}let n=i.signers;n!=null&&this.validateSigners(r,n,e.chain)}}validateSigners(r,e,i){let t=r.config,a=t==null?void 0:t.delegatedSigners;if(e.length!==0){if(a==null||a.length===0)throw new (0, _chunkOWQZPI3Ucjs.g)(`${e.length} signer(s) specified, but wallet "${r.address}" has no signers. ${$}`);for(let n of e){let s=a.find(o=>{if(this.isMatchingPasskeySigner(n,o,t)||o.type==="device"&&n.type==="device")return!0;if(n.type==="server"){let{primary:c,legacy:d}=_chunkQ4EIDR3Acjs.c.call(void 0, n,i,this.apiClient.projectId,this.apiClient.environment);return o.locator===`server:${c.derivedAddress}`||d!=null&&o.locator===`server:${d.derivedAddress}`}return o.locator===_chunkNX256LAHcjs.a.call(void 0, n)});if(s==null){let o=a.map(c=>c.locator).join(", ");throw new (0, _chunkOWQZPI3Ucjs.g)(`Signer '${n.type}' does not exist in wallet "${r.address}". Available signers: ${o}. ${$}`)}_chunk6EUBBDIVcjs.b.call(void 0, n,s)}}}isMatchingPasskeySigner(r,e,i){var a,n;let t=((n=(a=i.delegatedSigners)==null?void 0:a.filter(s=>s.type==="passkey").length)!=null?n:0)+(i.adminSigner.type==="passkey"?1:0);if(r.type==="passkey"){if(r.id==null&&t===1)return e.type==="passkey";if(r.id==null&&t>1)throw new (0, _chunkOWQZPI3Ucjs.g)("When creating a wallet with multiple passkeys, you must provide the passkey ID for each passkey.")}return!1}registerSigners(r,e,i){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){var t;return yield Promise.all((t=r==null?void 0:r.map(a=>_chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){if(a.type==="passkey")return a.id==null?{signer:yield this.createPasskeySigner(a)}:{signer:a};if(a.type==="device"){if(a.publicKey!=null)return{signer:{type:"device",publicKey:a.publicKey,name:a.name}};if(a.locator!=null)return{signer:a.locator};if(i==null)throw new (0, _chunkOWQZPI3Ucjs.g)("Device signer key storage is required for device signers");let n=yield _chunkYHV3672Rcjs.a.call(void 0, i);return{signer:{type:"device",publicKey:n.publicKey,name:n.name}}}if(a.type==="server"&&e!=null){let{derivedAddress:n}=_chunkQ4EIDR3Acjs.b.call(void 0, a,e,this.apiClient.projectId,this.apiClient.environment);return{signer:`server:${n}`}}return{signer:_chunkNX256LAHcjs.a.call(void 0, a)}})))!=null?t:[])})}getChainType(r){return r==="solana"?"solana":r==="stellar"?"stellar":"evm"}};_chunk2GKPWQBQcjs.c.call(void 0, [_commonsdkbase.WithLoggerContext.call(void 0, {logger:_chunkJLTD3KKUcjs.a,methodName:"walletFactory.getWallet",buildContext(r,e){if(typeof e[0]=="string"){let t=e[1];return{walletLocator:e[0],chain:t==null?void 0:t.chain}}let i=e[0];return{chain:i==null?void 0:i.chain}}})],u.prototype,"getWallet",1),_chunk2GKPWQBQcjs.c.call(void 0, [_commonsdkbase.WithLoggerContext.call(void 0, {logger:_chunkJLTD3KKUcjs.a,methodName:"walletFactory.createWallet",buildContext(r,e){return{chain:e[0].chain}}})],u.prototype,"createWallet",1);exports.a = u;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkUQ72BJGOcjs = require('./chunk-UQ72BJGO.cjs');var _commonsdkbase = require('@crossmint/common-sdk-base');var t=new _commonsdkbase.SdkLogger;function v(s){let o=_commonsdkbase.detectPlatform.call(void 0, ),e=_commonsdkbase.validateAPIKey.call(void 0, s);if(!e.isValid)throw new Error(`Invalid API key: ${e.message}`);let{environment:a,projectId:c}=e;switch(t.init({packageName:_chunkUQ72BJGOcjs.c,packageVersion:_chunkUQ72BJGOcjs.b,environment:a,projectId:c,platform:o}),o){case"browser":{let r=new (0, _commonsdkbase.BrowserDatadogSink)(a);t.addSink(r);break}case"react-native":break;case"server":{let r=new (0, _commonsdkbase.ServerDatadogSink)(a);t.addSink(r);break}default:break}}exports.a = t; exports.b = v;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkN3UCY2Y2cjs = require('./chunk-N3UCY2Y2.cjs');var _commonsdkbase = require('@crossmint/common-sdk-base');var t=new _commonsdkbase.SdkLogger;function v(s){let o=_commonsdkbase.detectPlatform.call(void 0, ),e=_commonsdkbase.validateAPIKey.call(void 0, s);if(!e.isValid)throw new Error(`Invalid API key: ${e.message}`);let{environment:a,projectId:c}=e;switch(t.init({packageName:_chunkN3UCY2Y2cjs.c,packageVersion:_chunkN3UCY2Y2cjs.b,environment:a,projectId:c,platform:o}),o){case"browser":{let r=new (0, _commonsdkbase.BrowserDatadogSink)(a);t.addSink(r);break}case"react-native":break;case"server":{let r=new (0, _commonsdkbase.ServerDatadogSink)(a);t.addSink(r);break}default:break}}exports.a = t; exports.b = v;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkGZP2JQ6Pcjs = require('./chunk-GZP2JQ6P.cjs');var _chunkYK3YZZ5Fcjs = require('./chunk-YK3YZZ5F.cjs');var _chunkSSQAEYUVcjs = require('./chunk-SSQAEYUV.cjs');var _chunkIMF5Z7BCcjs = require('./chunk-IMF5Z7BC.cjs');var _chunkSPTXAOFRcjs = require('./chunk-SPTXAOFR.cjs');var _chunkGEY3BU62cjs = require('./chunk-GEY3BU62.cjs');var _chunkPHPBBEXUcjs = require('./chunk-PHPBBEXU.cjs');var _chunkA33BEWR7cjs = require('./chunk-A33BEWR7.cjs');var _chunkOGP7B5O3cjs = require('./chunk-OGP7B5O3.cjs');var _chunkIJ632UXDcjs = require('./chunk-IJ632UXD.cjs');var _chunkE4EOD7MPcjs = require('./chunk-E4EOD7MP.cjs');var _chunkOWQZPI3Ucjs = require('./chunk-OWQZPI3U.cjs');function M(r,e,n){switch(e.type){case"email":case"phone":return r==="solana"?new (0, _chunkIMF5Z7BCcjs.a)(e):r==="stellar"?new (0, _chunkYK3YZZ5Fcjs.a)(e):new (0, _chunkSSQAEYUVcjs.a)(e);case"api-key":return r==="solana"?new (0, _chunkIJ632UXDcjs.a)(e):new (0, _chunkPHPBBEXUcjs.a)(e);case"external-wallet":return r==="solana"?new (0, _chunkE4EOD7MPcjs.a)(e):r==="stellar"?new (0, _chunkSPTXAOFRcjs.a)(e):new (0, _chunkA33BEWR7cjs.a)(e);case"server":return _chunkGZP2JQ6Pcjs.a.call(void 0, r,e);case"passkey":return new (0, _chunkOGP7B5O3cjs.a)(e);case"device":if(n==null)throw new (0, _chunkOWQZPI3Ucjs.g)("Device signer key storage is required for device signers");return new (0, _chunkGEY3BU62cjs.a)(e,n)}}exports.a = M;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkGZP2JQ6Pcjs = require('./chunk-GZP2JQ6P.cjs');var _chunk4OR2XVWEcjs = require('./chunk-4OR2XVWE.cjs');var _chunkNXPEGMMQcjs = require('./chunk-NXPEGMMQ.cjs');var _chunkQYWFJC7Qcjs = require('./chunk-QYWFJC7Q.cjs');var _chunkSPTXAOFRcjs = require('./chunk-SPTXAOFR.cjs');var _chunkGEY3BU62cjs = require('./chunk-GEY3BU62.cjs');var _chunkPHPBBEXUcjs = require('./chunk-PHPBBEXU.cjs');var _chunkA33BEWR7cjs = require('./chunk-A33BEWR7.cjs');var _chunkOGP7B5O3cjs = require('./chunk-OGP7B5O3.cjs');var _chunkIJ632UXDcjs = require('./chunk-IJ632UXD.cjs');var _chunkE4EOD7MPcjs = require('./chunk-E4EOD7MP.cjs');var _chunkOWQZPI3Ucjs = require('./chunk-OWQZPI3U.cjs');function M(r,e,n){switch(e.type){case"email":case"phone":return r==="solana"?new (0, _chunkQYWFJC7Qcjs.a)(e):r==="stellar"?new (0, _chunk4OR2XVWEcjs.a)(e):new (0, _chunkNXPEGMMQcjs.a)(e);case"api-key":return r==="solana"?new (0, _chunkIJ632UXDcjs.a)(e):new (0, _chunkPHPBBEXUcjs.a)(e);case"external-wallet":return r==="solana"?new (0, _chunkE4EOD7MPcjs.a)(e):r==="stellar"?new (0, _chunkSPTXAOFRcjs.a)(e):new (0, _chunkA33BEWR7cjs.a)(e);case"server":return _chunkGZP2JQ6Pcjs.a.call(void 0, r,e);case"passkey":return new (0, _chunkOGP7B5O3cjs.a)(e);case"device":if(n==null)throw new (0, _chunkOWQZPI3Ucjs.g)("Device signer key storage is required for device signers");return new (0, _chunkGEY3BU62cjs.a)(e,n)}}exports.a = M;
@@ -1 +1 @@
1
- import{a as o}from"./chunk-5OYPWGMX.js";import{a}from"./chunk-VOVJ4RNT.js";import{b as p,c}from"./chunk-Y55LWZDS.js";import{g as t}from"./chunk-J3R36SGJ.js";import{APIKeyEnvironmentPrefix as d,APIKeyUsageOrigin as g,CrossmintApiClient as P}from"@crossmint/common-sdk-base";var h=class extends P{constructor(e){super(e,{internalConfig:{sdkMetadata:{name:c,version:p}}});this.apiPrefix="api/2025-06-09/wallets";this.unstableApiPrefix="api/unstable/wallets"}createWallet(e){return t(this,null,function*(){let s=this.isServerSide?`${this.apiPrefix}`:`${this.apiPrefix}/me`;a.info("wallets.api.createWallet",{chainType:e.chainType,walletType:e.type});let n=yield(yield this.post(s,{body:JSON.stringify(e),headers:this.headers})).json();return"error"in n?a.error("wallets.api.createWallet.error",{error:n.error,chainType:e.chainType}):"address"in n&&a.info("wallets.api.createWallet.success",{address:n.address,chainType:e.chainType}),n})}getWallet(e){return t(this,null,function*(){a.info("wallets.api.getWallet",{locator:e});let r=yield(yield this.get(`${this.apiPrefix}/${e}`,{headers:this.headers})).json();return"error"in r?a.warn("wallets.api.getWallet.error",{locator:e,error:r.error}):"address"in r&&a.info("wallets.api.getWallet.success",{address:r.address,locator:e}),r})}createTransaction(e,s){return t(this,null,function*(){return(yield this.post(`${this.apiPrefix}/${e}/transactions`,{body:JSON.stringify(s),headers:this.headers})).json()})}approveTransaction(e,s,r){return t(this,null,function*(){return(yield this.post(`${this.apiPrefix}/${e}/transactions/${s}/approvals`,{body:JSON.stringify(r),headers:this.headers})).json()})}getTransaction(e,s){return t(this,null,function*(){return(yield this.get(`${this.apiPrefix}/${e}/transactions/${s}`,{headers:this.headers})).json()})}createSignature(e,s){return t(this,null,function*(){return(yield this.post(`${this.apiPrefix}/${e}/signatures`,{body:JSON.stringify(s),headers:this.headers})).json()})}approveSignature(e,s,r){return t(this,null,function*(){let n=yield this.post(`${this.apiPrefix}/${e}/signatures/${s}/approvals`,{body:JSON.stringify(r),headers:this.headers});return n.status===422?this.getSignature(e,s):n.json()})}getSignature(e,s){return t(this,null,function*(){return(yield this.get(`${this.apiPrefix}/${e}/signatures/${s}`,{headers:this.headers})).json()})}getTransactions(e){return t(this,null,function*(){return(yield this.get(`${this.apiPrefix}/${e}/transactions`,{headers:this.headers})).json()})}getNfts(e){return t(this,null,function*(){let s=new URLSearchParams;s.append("page",e.page.toString()),s.append("perPage",e.perPage.toString());let r=`${e.chain}:${e.address}`;return(yield this.get(`${this.apiPrefix}/${r}/nfts?${s.toString()}`,{headers:this.headers})).json()})}getTransfers(e,s){return t(this,null,function*(){let r=new URLSearchParams;return r.append("chain",s.chain.toString()),s.tokens!=null&&r.append("tokens",s.tokens),r.append("status",s.status),(yield this.get(`${this.unstableApiPrefix}/${e}/transfers?${r.toString()}`,{headers:this.headers})).json()})}getBalance(e,s){return t(this,null,function*(){let r=new URLSearchParams;return r.append("tokens",s.tokens.join(",")),r.append("chains",s.chains.join(",")),(yield this.get(`${this.apiPrefix}/${e}/balances?${r.toString()}`,{headers:this.headers})).json()})}fundWallet(e,s){return t(this,null,function*(){if(this.environment===d.PRODUCTION)throw new Error("Funding wallets is only supported in staging environment");return(yield this.post(`api/v1-alpha2/wallets/${e}/balances`,{body:JSON.stringify(s),headers:this.headers})).json()})}registerSigner(e,s){return t(this,null,function*(){return(yield this.post(`${this.apiPrefix}/${e}/signers`,{body:JSON.stringify(s),headers:this.headers})).json()})}removeSigner(e,s,r){return t(this,null,function*(){let n=encodeURIComponent(s),i=new URLSearchParams;r.chain&&i.append("chain",r.chain);let l=`${this.apiPrefix}/${e}/signers/${n}${i.size>0?`?${i.toString()}`:""}`;return(yield this.delete(l,{headers:this.headers})).json()})}getSigner(e,s){return t(this,null,function*(){let r=encodeURIComponent(s);return(yield this.get(`${this.apiPrefix}/${e}/signers/${r}`,{headers:this.headers})).json()})}send(e,s,r){return t(this,null,function*(){a.info("wallets.api.send",{walletLocator:e,tokenLocator:s,recipient:r.recipient});let i=yield(yield this.post(`${this.apiPrefix}/${e}/tokens/${s}/transfers`,{body:JSON.stringify(r),headers:this.headers})).json();return"error"in i?a.error("wallets.api.send.error",{walletLocator:e,tokenLocator:s,error:i.error}):"id"in i&&a.info("wallets.api.send.success",{walletLocator:e,transactionId:i.id}),i})}get isServerSide(){return this.parsedAPIKey.usageOrigin===g.SERVER}get environment(){if(!this.parsedAPIKey.isValid)throw new o("Invalid API key");return this.parsedAPIKey.environment}get projectId(){if(!this.parsedAPIKey.isValid)throw new o("Invalid API key");return this.parsedAPIKey.projectId}get headers(){return{"Content-Type":"application/json"}}};export{h as a};
1
+ import{a as o}from"./chunk-5OYPWGMX.js";import{a}from"./chunk-RFWG2QIH.js";import{b as p,c}from"./chunk-2FKIDTGK.js";import{g as t}from"./chunk-J3R36SGJ.js";import{APIKeyEnvironmentPrefix as d,APIKeyUsageOrigin as g,CrossmintApiClient as P}from"@crossmint/common-sdk-base";var h=class extends P{constructor(e){super(e,{internalConfig:{sdkMetadata:{name:c,version:p}}});this.apiPrefix="api/2025-06-09/wallets";this.unstableApiPrefix="api/unstable/wallets"}createWallet(e){return t(this,null,function*(){let s=this.isServerSide?`${this.apiPrefix}`:`${this.apiPrefix}/me`;a.info("wallets.api.createWallet",{chainType:e.chainType,walletType:e.type});let n=yield(yield this.post(s,{body:JSON.stringify(e),headers:this.headers})).json();return"error"in n?a.error("wallets.api.createWallet.error",{error:n.error,chainType:e.chainType}):"address"in n&&a.info("wallets.api.createWallet.success",{address:n.address,chainType:e.chainType}),n})}getWallet(e){return t(this,null,function*(){a.info("wallets.api.getWallet",{locator:e});let r=yield(yield this.get(`${this.apiPrefix}/${e}`,{headers:this.headers})).json();return"error"in r?a.warn("wallets.api.getWallet.error",{locator:e,error:r.error}):"address"in r&&a.info("wallets.api.getWallet.success",{address:r.address,locator:e}),r})}createTransaction(e,s){return t(this,null,function*(){return(yield this.post(`${this.apiPrefix}/${e}/transactions`,{body:JSON.stringify(s),headers:this.headers})).json()})}approveTransaction(e,s,r){return t(this,null,function*(){return(yield this.post(`${this.apiPrefix}/${e}/transactions/${s}/approvals`,{body:JSON.stringify(r),headers:this.headers})).json()})}getTransaction(e,s){return t(this,null,function*(){return(yield this.get(`${this.apiPrefix}/${e}/transactions/${s}`,{headers:this.headers})).json()})}createSignature(e,s){return t(this,null,function*(){return(yield this.post(`${this.apiPrefix}/${e}/signatures`,{body:JSON.stringify(s),headers:this.headers})).json()})}approveSignature(e,s,r){return t(this,null,function*(){let n=yield this.post(`${this.apiPrefix}/${e}/signatures/${s}/approvals`,{body:JSON.stringify(r),headers:this.headers});return n.status===422?this.getSignature(e,s):n.json()})}getSignature(e,s){return t(this,null,function*(){return(yield this.get(`${this.apiPrefix}/${e}/signatures/${s}`,{headers:this.headers})).json()})}getTransactions(e){return t(this,null,function*(){return(yield this.get(`${this.apiPrefix}/${e}/transactions`,{headers:this.headers})).json()})}getNfts(e){return t(this,null,function*(){let s=new URLSearchParams;s.append("page",e.page.toString()),s.append("perPage",e.perPage.toString());let r=`${e.chain}:${e.address}`;return(yield this.get(`${this.apiPrefix}/${r}/nfts?${s.toString()}`,{headers:this.headers})).json()})}getTransfers(e,s){return t(this,null,function*(){let r=new URLSearchParams;return r.append("chain",s.chain.toString()),s.tokens!=null&&r.append("tokens",s.tokens),r.append("status",s.status),(yield this.get(`${this.unstableApiPrefix}/${e}/transfers?${r.toString()}`,{headers:this.headers})).json()})}getBalance(e,s){return t(this,null,function*(){let r=new URLSearchParams;return r.append("tokens",s.tokens.join(",")),r.append("chains",s.chains.join(",")),(yield this.get(`${this.apiPrefix}/${e}/balances?${r.toString()}`,{headers:this.headers})).json()})}fundWallet(e,s){return t(this,null,function*(){if(this.environment===d.PRODUCTION)throw new Error("Funding wallets is only supported in staging environment");return(yield this.post(`api/v1-alpha2/wallets/${e}/balances`,{body:JSON.stringify(s),headers:this.headers})).json()})}registerSigner(e,s){return t(this,null,function*(){return(yield this.post(`${this.apiPrefix}/${e}/signers`,{body:JSON.stringify(s),headers:this.headers})).json()})}removeSigner(e,s,r){return t(this,null,function*(){let n=encodeURIComponent(s),i=new URLSearchParams;r.chain&&i.append("chain",r.chain);let l=`${this.apiPrefix}/${e}/signers/${n}${i.size>0?`?${i.toString()}`:""}`;return(yield this.delete(l,{headers:this.headers})).json()})}getSigner(e,s){return t(this,null,function*(){let r=encodeURIComponent(s);return(yield this.get(`${this.apiPrefix}/${e}/signers/${r}`,{headers:this.headers})).json()})}send(e,s,r){return t(this,null,function*(){a.info("wallets.api.send",{walletLocator:e,tokenLocator:s,recipient:r.recipient});let i=yield(yield this.post(`${this.apiPrefix}/${e}/tokens/${s}/transfers`,{body:JSON.stringify(r),headers:this.headers})).json();return"error"in i?a.error("wallets.api.send.error",{walletLocator:e,tokenLocator:s,error:i.error}):"id"in i&&a.info("wallets.api.send.success",{walletLocator:e,transactionId:i.id}),i})}get isServerSide(){return this.parsedAPIKey.usageOrigin===g.SERVER}get environment(){if(!this.parsedAPIKey.isValid)throw new o("Invalid API key");return this.parsedAPIKey.environment}get projectId(){if(!this.parsedAPIKey.isValid)throw new o("Invalid API key");return this.parsedAPIKey.projectId}get headers(){return{"Content-Type":"application/json"}}};export{h as a};
@@ -1 +1 @@
1
- import{a as d}from"./chunk-OQZTL6ZG.js";import{a as g,b as S}from"./chunk-EM3D5Q3A.js";import{a as o}from"./chunk-XNZLCUTY.js";import{privateKeyToAccount as f}from"viem/accounts";import{bytesToHex as l}from"@noble/hashes/utils";import{Keypair as u}from"@solana/web3.js";function a(r,e){switch(d(e)){case"evm":return f(`0x${l(r)}`).address;case"solana":return u.fromSeed(r).publicKey.toBase58();case"stellar":return g(S(r).publicKey)}}function B(r,e,i,t){if(typeof window!="undefined")throw new Error("Server signers can only be used from server-side code.");let s=d(e),n=o(r.secret,i,t,s),y=a(n,e);return{derivedKeyBytes:n,derivedAddress:y}}function D(r,e,i,t){if(typeof window!="undefined")throw new Error("Server signers can only be used from server-side code.");let s=d(e),n=o(r.secret,i,t,s),y=a(n,e),c={derivedKeyBytes:n,derivedAddress:y},p=typeof e=="string"?e:String(e);if(s==="evm"&&p!=="evm"){let v=o(r.secret,i,t,p),m=a(v,e);return{primary:c,legacy:{derivedKeyBytes:v,derivedAddress:m}}}return{primary:c,legacy:null}}export{a,B as b,D as c};
1
+ import{a as d}from"./chunk-OQZTL6ZG.js";import{a as S,b as g}from"./chunk-EM3D5Q3A.js";import{a as o}from"./chunk-XNZLCUTY.js";import{privateKeyToAccount as f}from"viem/accounts";import{bytesToHex as l}from"@noble/hashes/utils";import{Keypair as u}from"@solana/web3.js";function y(r,e){switch(d(e)){case"evm":return f(`0x${l(r)}`).address;case"solana":return u.fromSeed(r).publicKey.toBase58();case"stellar":return S(g(r).publicKey)}}function B(r,e,i,t){if(typeof window!="undefined")throw new Error("Server signers can only be used from server-side code.");let s=d(e),n=o(r.secret,i,t,s),a=y(n,e);return{derivedKeyBytes:n,derivedAddress:a}}function D(r,e,i,t){if(typeof window!="undefined")throw new Error("Server signers can only be used from server-side code.");let s=d(e),n=o(r.secret,i,t,s),a=y(n,e),c={derivedKeyBytes:n,derivedAddress:a},p=typeof e=="string"?e:String(e);if(s==="evm"&&p!=="evm"){let v=o(r.secret,i,t,p),m=y(v,e);return{primary:c,legacy:{derivedKeyBytes:v,derivedAddress:m}}}return{primary:c,legacy:null}}export{y as a,B as b,D as c};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var s="@crossmint/wallets-sdk",t="1.4.1";var p="WALLETS_SDK",c= exports.b =t,r= exports.c =s,a= exports.d =500;exports.a = p; exports.b = c; exports.c = r; exports.d = a;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var s="@crossmint/wallets-sdk",t="1.5.1";var p="WALLETS_SDK",c= exports.b =t,r= exports.c =s,a= exports.d =500;exports.a = p; exports.b = c; exports.c = r; exports.d = a;
@@ -1 +1 @@
1
- import{a as m}from"./chunk-O6VBO7KG.js";import{a as l,b as f}from"./chunk-PYIURK5B.js";import{a as n}from"./chunk-VOVJ4RNT.js";import{c as E,g as u}from"./chunk-J3R36SGJ.js";import{validateAPIKey as w,WithLoggerContext as y}from"@crossmint/common-sdk-base";var p=class{constructor(i){this.config=i;this._needsAuth=!0;this._authPromise=null;this._initializationPromise=null;typeof window!="undefined"&&(this._initializationPromise=this.initialize()),this.type=this.config.type}locator(){return this.config.locator}address(){return this.config.address}initialize(){return u(this,null,function*(){try{if(this.config.clientTEEConnection==null){let i=w(this.config.crossmint.apiKey);if(!i.isValid)throw new Error("Invalid API key");let t=new m({environment:i.environment});this.config.clientTEEConnection=yield t.initialize()}}finally{this._initializationPromise=null}})}getTEEConnection(){return u(this,null,function*(){if(this.config.clientTEEConnection==null){if(this._initializationPromise){if(yield this._initializationPromise,this.config.clientTEEConnection==null)throw new Error("Failed to initialize TEE connection");return this.config.clientTEEConnection}this._initializationPromise=this.initializeTEEConnection();try{yield this._initializationPromise}finally{this._initializationPromise=null}}if(this.config.clientTEEConnection==null)throw new Error("TEE connection is not initialized");return this.config.clientTEEConnection})}initializeTEEConnection(){return u(this,null,function*(){n.info("TEE connection not initialized, initializing now");let i=w(this.config.crossmint.apiKey);if(!i.isValid)throw new Error("Invalid API key");let t=new m({environment:i.environment});if(this.config.clientTEEConnection=yield t.initialize(),this.config.clientTEEConnection==null)throw new Error("Failed to initialize TEE connection");n.info("TEE connection initialized successfully")})}handleAuthRequired(){return u(this,null,function*(){var d;let i=yield this.getTEEConnection();if(this.config.onAuthRequired==null)throw new Error(`${this.type} signer requires the onAuthRequired callback to handle OTP verification. This callback manages the authentication flow (sending OTP and verifying user input). If using our React/React Native SDK, this is handled automatically by the provider. For other environments, implement: onAuthRequired: (needsAuth, sendOtp, verifyOtp, reject) => { /* your UI logic */ }`);n.info("get-status: sending request");let t=Date.now(),r=yield i.sendAction({event:"request:get-status",responseEvent:"response:get-status",data:{authData:{jwt:(d=this.config.crossmint.jwt)!=null?d:"",apiKey:this.config.crossmint.apiKey}},options:g}),e=Date.now()-t;if((r==null?void 0:r.status)!=="success")throw n.error("get-status: failed",{status:r==null?void 0:r.status,error:r==null?void 0:r.error,durationMs:e}),new Error(r==null?void 0:r.error);if(n.info("get-status: response received",{signerStatus:r.signerStatus,durationMs:e}),r.signerStatus==="ready"){this._needsAuth=!1;return}else this._needsAuth=!0;n.info("Auth required, initiating OTP flow",{needsAuth:this._needsAuth});let{promise:a,resolve:s,reject:c}=this.createAuthPromise();if(this._authPromise={promise:a,resolve:s,reject:c},this.config.onAuthRequired)try{yield this.config.onAuthRequired(this.config.type,this.locator(),this._needsAuth,()=>this.sendMessageWithOtp(),o=>this.verifyOtp(o),()=>u(this,null,function*(){n.info("Auth rejected",{authRejected:!0}),this._needsAuth=!1,this.config.onAuthRequired!=null&&(yield this.config.onAuthRequired(this.config.type,this.locator(),this._needsAuth,()=>this.sendMessageWithOtp(),o=>this.verifyOtp(o),()=>{var o;return(o=this._authPromise)==null?void 0:o.reject(new l)})),c(new l)}))}catch(o){n.error("handleAuthRequired error",{error:o}),c(o)}try{yield a}catch(o){throw n.error("handleAuthRequired promise error",{error:o}),o}})}ensureAuthenticated(){return u(this,null,function*(){yield this.handleAuthRequired()})}getJwtOrThrow(){let i=this.config.crossmint.jwt;if(i==null)throw new Error("JWT is required");return i}createAuthPromise(){let i,t;return{promise:new Promise((e,a)=>{i=e,t=a}),resolve:i,reject:t}}sendMessageWithOtp(){return u(this,null,function*(){var s,c;let i=yield this.getTEEConnection(),t=this.getAuthId();n.info("start-onboarding: sending request");let r=Date.now(),e=yield i.sendAction({event:"request:start-onboarding",responseEvent:"response:start-onboarding",data:{authData:{jwt:(s=this.config.crossmint.jwt)!=null?s:"",apiKey:this.config.crossmint.apiKey},data:{authId:t}},options:g}),a=Date.now()-r;if(n.info("start-onboarding: response received",{status:e==null?void 0:e.status,durationMs:a}),(e==null?void 0:e.status)==="success"&&e.signerStatus==="ready"){this._needsAuth=!1;return}if((e==null?void 0:e.status)==="error"){n.error("start-onboarding: failed",{error:e.error,code:e.code});let d=new f(e.error||"Failed to initiate OTP process.",e.code);(c=this._authPromise)==null||c.reject(d)}})}getAuthId(){return this.config.type==="email"?`email:${this.config.email}`:`phone:${this.config.phone}`}verifyOtp(i){return u(this,null,function*(){var s,c,d,o;let t;try{let h=yield this.getTEEConnection();n.info("complete-onboarding: sending request");let v=Date.now();t=yield h.sendAction({event:"request:complete-onboarding",responseEvent:"response:complete-onboarding",data:{authData:{jwt:(s=this.config.crossmint.jwt)!=null?s:"",apiKey:this.config.crossmint.apiKey},data:{onboardingAuthentication:{encryptedOtp:i}}},options:g}),n.info("complete-onboarding: response received",{status:t==null?void 0:t.status,durationMs:Date.now()-v})}catch(h){throw n.error("complete-onboarding: error",{error:h}),this._needsAuth=!0,(c=this._authPromise)==null||c.reject(h),h}if((t==null?void 0:t.status)==="success"){this._needsAuth=!1,this.config.onAuthRequired!=null&&(yield this.config.onAuthRequired(this.config.type,this.locator(),this._needsAuth,()=>this.sendMessageWithOtp(),h=>this.verifyOtp(h),()=>{var h;return(h=this._authPromise)==null?void 0:h.reject(new l)})),(d=this._authPromise)==null||d.resolve();return}n.error("complete-onboarding: OTP validation failed",{status:t==null?void 0:t.status,error:(t==null?void 0:t.status)==="error"?t.error:void 0,code:(t==null?void 0:t.status)==="error"?t.code:void 0}),this._needsAuth=!0;let r=(t==null?void 0:t.status)==="error"&&t.error||"Failed to validate encrypted OTP",e=(t==null?void 0:t.status)==="error"?t.code:void 0,a=new f(r,e);throw(o=this._authPromise)==null||o.reject(a),a})}_exportPrivateKey(i,t){return u(this,null,function*(){yield this.handleAuthRequired();let r=this.getJwtOrThrow(),{scheme:e,encoding:a}=this.getChainKeyParams();if(t!=null){let c=i.on("event:key-exported",d=>{i.off(c),d.status==="success"&&Promise.resolve().then(()=>t()).catch(()=>{console.error("[NCS Signer] onExport callback error")})})}let s=yield i.sendAction({event:"request:export-signer",responseEvent:"response:export-signer",data:{authData:{jwt:r,apiKey:this.config.crossmint.apiKey},data:{scheme:e,encoding:a}},options:g});if((s==null?void 0:s.status)==="error")throw new Error(s.error||"Failed to export private key")})}};E([y({logger:n,methodName:"handleAuthRequired"})],p.prototype,"handleAuthRequired",1);var g={timeoutMs:3e4};export{p as a,g as b};
1
+ import{a as m}from"./chunk-O6VBO7KG.js";import{a as l,b as f}from"./chunk-PYIURK5B.js";import{a as n}from"./chunk-RFWG2QIH.js";import{c as E,g as u}from"./chunk-J3R36SGJ.js";import{validateAPIKey as w,WithLoggerContext as y}from"@crossmint/common-sdk-base";var p=class{constructor(i){this.config=i;this._needsAuth=!0;this._authPromise=null;this._initializationPromise=null;typeof window!="undefined"&&(this._initializationPromise=this.initialize()),this.type=this.config.type}locator(){return this.config.locator}address(){return this.config.address}initialize(){return u(this,null,function*(){try{if(this.config.clientTEEConnection==null){let i=w(this.config.crossmint.apiKey);if(!i.isValid)throw new Error("Invalid API key");let t=new m({environment:i.environment});this.config.clientTEEConnection=yield t.initialize()}}finally{this._initializationPromise=null}})}getTEEConnection(){return u(this,null,function*(){if(this.config.clientTEEConnection==null){if(this._initializationPromise){if(yield this._initializationPromise,this.config.clientTEEConnection==null)throw new Error("Failed to initialize TEE connection");return this.config.clientTEEConnection}this._initializationPromise=this.initializeTEEConnection();try{yield this._initializationPromise}finally{this._initializationPromise=null}}if(this.config.clientTEEConnection==null)throw new Error("TEE connection is not initialized");return this.config.clientTEEConnection})}initializeTEEConnection(){return u(this,null,function*(){n.info("TEE connection not initialized, initializing now");let i=w(this.config.crossmint.apiKey);if(!i.isValid)throw new Error("Invalid API key");let t=new m({environment:i.environment});if(this.config.clientTEEConnection=yield t.initialize(),this.config.clientTEEConnection==null)throw new Error("Failed to initialize TEE connection");n.info("TEE connection initialized successfully")})}handleAuthRequired(){return u(this,null,function*(){var d;let i=yield this.getTEEConnection();if(this.config.onAuthRequired==null)throw new Error(`${this.type} signer requires the onAuthRequired callback to handle OTP verification. This callback manages the authentication flow (sending OTP and verifying user input). If using our React/React Native SDK, this is handled automatically by the provider. For other environments, implement: onAuthRequired: (needsAuth, sendOtp, verifyOtp, reject) => { /* your UI logic */ }`);n.info("get-status: sending request");let t=Date.now(),r=yield i.sendAction({event:"request:get-status",responseEvent:"response:get-status",data:{authData:{jwt:(d=this.config.crossmint.jwt)!=null?d:"",apiKey:this.config.crossmint.apiKey}},options:g}),e=Date.now()-t;if((r==null?void 0:r.status)!=="success")throw n.error("get-status: failed",{status:r==null?void 0:r.status,error:r==null?void 0:r.error,durationMs:e}),new Error(r==null?void 0:r.error);if(n.info("get-status: response received",{signerStatus:r.signerStatus,durationMs:e}),r.signerStatus==="ready"){this._needsAuth=!1;return}else this._needsAuth=!0;n.info("Auth required, initiating OTP flow",{needsAuth:this._needsAuth});let{promise:a,resolve:s,reject:c}=this.createAuthPromise();if(this._authPromise={promise:a,resolve:s,reject:c},this.config.onAuthRequired)try{yield this.config.onAuthRequired(this.config.type,this.locator(),this._needsAuth,()=>this.sendMessageWithOtp(),o=>this.verifyOtp(o),()=>u(this,null,function*(){n.info("Auth rejected",{authRejected:!0}),this._needsAuth=!1,this.config.onAuthRequired!=null&&(yield this.config.onAuthRequired(this.config.type,this.locator(),this._needsAuth,()=>this.sendMessageWithOtp(),o=>this.verifyOtp(o),()=>{var o;return(o=this._authPromise)==null?void 0:o.reject(new l)})),c(new l)}))}catch(o){n.error("handleAuthRequired error",{error:o}),c(o)}try{yield a}catch(o){throw n.error("handleAuthRequired promise error",{error:o}),o}})}ensureAuthenticated(){return u(this,null,function*(){yield this.handleAuthRequired()})}getJwtOrThrow(){let i=this.config.crossmint.jwt;if(i==null)throw new Error("JWT is required");return i}createAuthPromise(){let i,t;return{promise:new Promise((e,a)=>{i=e,t=a}),resolve:i,reject:t}}sendMessageWithOtp(){return u(this,null,function*(){var s,c;let i=yield this.getTEEConnection(),t=this.getAuthId();n.info("start-onboarding: sending request");let r=Date.now(),e=yield i.sendAction({event:"request:start-onboarding",responseEvent:"response:start-onboarding",data:{authData:{jwt:(s=this.config.crossmint.jwt)!=null?s:"",apiKey:this.config.crossmint.apiKey},data:{authId:t}},options:g}),a=Date.now()-r;if(n.info("start-onboarding: response received",{status:e==null?void 0:e.status,durationMs:a}),(e==null?void 0:e.status)==="success"&&e.signerStatus==="ready"){this._needsAuth=!1;return}if((e==null?void 0:e.status)==="error"){n.error("start-onboarding: failed",{error:e.error,code:e.code});let d=new f(e.error||"Failed to initiate OTP process.",e.code);(c=this._authPromise)==null||c.reject(d)}})}getAuthId(){return this.config.type==="email"?`email:${this.config.email}`:`phone:${this.config.phone}`}verifyOtp(i){return u(this,null,function*(){var s,c,d,o;let t;try{let h=yield this.getTEEConnection();n.info("complete-onboarding: sending request");let v=Date.now();t=yield h.sendAction({event:"request:complete-onboarding",responseEvent:"response:complete-onboarding",data:{authData:{jwt:(s=this.config.crossmint.jwt)!=null?s:"",apiKey:this.config.crossmint.apiKey},data:{onboardingAuthentication:{encryptedOtp:i}}},options:g}),n.info("complete-onboarding: response received",{status:t==null?void 0:t.status,durationMs:Date.now()-v})}catch(h){throw n.error("complete-onboarding: error",{error:h}),this._needsAuth=!0,(c=this._authPromise)==null||c.reject(h),h}if((t==null?void 0:t.status)==="success"){this._needsAuth=!1,this.config.onAuthRequired!=null&&(yield this.config.onAuthRequired(this.config.type,this.locator(),this._needsAuth,()=>this.sendMessageWithOtp(),h=>this.verifyOtp(h),()=>{var h;return(h=this._authPromise)==null?void 0:h.reject(new l)})),(d=this._authPromise)==null||d.resolve();return}n.error("complete-onboarding: OTP validation failed",{status:t==null?void 0:t.status,error:(t==null?void 0:t.status)==="error"?t.error:void 0,code:(t==null?void 0:t.status)==="error"?t.code:void 0}),this._needsAuth=!0;let r=(t==null?void 0:t.status)==="error"&&t.error||"Failed to validate encrypted OTP",e=(t==null?void 0:t.status)==="error"?t.code:void 0,a=new f(r,e);throw(o=this._authPromise)==null||o.reject(a),a})}_exportPrivateKey(i,t){return u(this,null,function*(){yield this.handleAuthRequired();let r=this.getJwtOrThrow(),{scheme:e,encoding:a}=this.getChainKeyParams();if(t!=null){let c=i.on("event:key-exported",d=>{i.off(c),d.status==="success"&&Promise.resolve().then(()=>t()).catch(()=>{console.error("[NCS Signer] onExport callback error")})})}let s=yield i.sendAction({event:"request:export-signer",responseEvent:"response:export-signer",data:{authData:{jwt:r,apiKey:this.config.crossmint.apiKey},data:{scheme:e,encoding:a}},options:g});if((s==null?void 0:s.status)==="error")throw new Error(s.error||"Failed to export private key")})}};E([y({logger:n,methodName:"handleAuthRequired"})],p.prototype,"handleAuthRequired",1);var g={timeoutMs:3e4};export{p as a,g as b};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunk6QCKGV44cjs = require('./chunk-6QCKGV44.cjs');var _chunkSFXFZ2J5cjs = require('./chunk-SFXFZ2J5.cjs');var _chunk2GKPWQBQcjs = require('./chunk-2GKPWQBQ.cjs');var _ox = require('ox');var _viem = require('viem');var c=class p extends _chunk6QCKGV44cjs.a{constructor(e){super(e)}signMessage(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){let i=_viem.isHex.call(void 0, e)?e:_viem.toHex.call(void 0, e),r=_ox.PersonalMessage.getSignPayload(i);return yield this.sign(r)})}signTransaction(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){return yield this.sign(e)})}sign(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){var o;yield this.handleAuthRequired();let i=this.getJwtOrThrow(),r=e.replace("0x","");_chunkSFXFZ2J5cjs.a.info("sign: sending request",{keyType:"secp256k1"});let y=Date.now(),n=yield(o=this.config.clientTEEConnection)==null?void 0:o.sendAction({event:"request:sign",responseEvent:"response:sign",data:{authData:{jwt:i,apiKey:this.config.crossmint.apiKey},data:{keyType:"secp256k1",bytes:r,encoding:"hex"}},options:_chunk6QCKGV44cjs.b});if(_chunkSFXFZ2J5cjs.a.info("sign: response received",{status:n==null?void 0:n.status,durationMs:Date.now()-y}),(n==null?void 0:n.status)==="error")throw new Error(n.error);if((n==null?void 0:n.signature)==null)throw new Error("Failed to sign transaction");return p.verifyPublicKeyFormat(n.publicKey),{signature:n.signature.bytes}})}static verifyPublicKeyFormat(e){if(e==null)throw new Error("No public key found");if(e.encoding!=="hex"||e.keyType!=="secp256k1"||e.bytes==null)throw new Error("Not supported. Expected public key to be in hex encoding and secp256k1 key type. Got: "+JSON.stringify(e))}getChainKeyParams(){return{scheme:"secp256k1",encoding:"hex"}}};exports.a = c;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunk2Y3AQN2Scjs = require('./chunk-2Y3AQN2S.cjs');var _chunkJLTD3KKUcjs = require('./chunk-JLTD3KKU.cjs');var _chunk2GKPWQBQcjs = require('./chunk-2GKPWQBQ.cjs');var _ox = require('ox');var _viem = require('viem');var c=class p extends _chunk2Y3AQN2Scjs.a{constructor(e){super(e)}signMessage(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){let i=_viem.isHex.call(void 0, e)?e:_viem.toHex.call(void 0, e),r=_ox.PersonalMessage.getSignPayload(i);return yield this.sign(r)})}signTransaction(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){return yield this.sign(e)})}sign(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){var o;yield this.handleAuthRequired();let i=this.getJwtOrThrow(),r=e.replace("0x","");_chunkJLTD3KKUcjs.a.info("sign: sending request",{keyType:"secp256k1"});let y=Date.now(),n=yield(o=this.config.clientTEEConnection)==null?void 0:o.sendAction({event:"request:sign",responseEvent:"response:sign",data:{authData:{jwt:i,apiKey:this.config.crossmint.apiKey},data:{keyType:"secp256k1",bytes:r,encoding:"hex"}},options:_chunk2Y3AQN2Scjs.b});if(_chunkJLTD3KKUcjs.a.info("sign: response received",{status:n==null?void 0:n.status,durationMs:Date.now()-y}),(n==null?void 0:n.status)==="error")throw new Error(n.error);if((n==null?void 0:n.signature)==null)throw new Error("Failed to sign transaction");return p.verifyPublicKeyFormat(n.publicKey),{signature:n.signature.bytes}})}static verifyPublicKeyFormat(e){if(e==null)throw new Error("No public key found");if(e.encoding!=="hex"||e.keyType!=="secp256k1"||e.bytes==null)throw new Error("Not supported. Expected public key to be in hex encoding and secp256k1 key type. Got: "+JSON.stringify(e))}getChainKeyParams(){return{scheme:"secp256k1",encoding:"hex"}}};exports.a = c;
@@ -1 +1 @@
1
- import{a as A,b as k}from"./chunk-JGWGYONV.js";import{a as E}from"./chunk-QTCM42EB.js";import{a as x}from"./chunk-N4IWDL6M.js";import{a as W}from"./chunk-GOXB2RBF.js";import{b as w,c as b}from"./chunk-F5NTM2RX.js";import{f as S}from"./chunk-Q65NMVP3.js";import{e as R,g as l}from"./chunk-5OYPWGMX.js";import{a as g}from"./chunk-VOVJ4RNT.js";import{a as f,b as m,c as v,g as y}from"./chunk-J3R36SGJ.js";import{WithLoggerContext as D}from"@crossmint/common-sdk-base";import{WebAuthnP256 as K}from"ox";var $="When 'signers' is provided to a method that may fetch an existing wallet, each specified signer must exist in that wallet's configuration.",u=class{constructor(r){this.apiClient=r}getWallet(r,e){return y(this,null,function*(){let i,t;if(typeof r=="string"){if(!this.apiClient.isServerSide)throw new l("getWallet with walletLocator is only available on the server side. Use getWallet(args) instead.");if(e==null)throw new l("Wallet configuration is required when using walletLocator: https://docs.crossmint.com/sdk-reference/wallets/type-aliases/WalletArgsFor");i=r,t=e}else{if(this.apiClient.isServerSide)throw new l("getWallet on server side requires a walletLocator parameter. Use getWallet(walletLocator, args) instead.");t=r,i=this.getWalletLocator(t)}let a=m(f({},t),{chain:S(t.chain,this.apiClient.environment)});g.info("walletFactory.getWallet.start");let n=yield this.apiClient.getWallet(i);if("error"in n)throw g.warn("walletFactory.getWallet.notFound",{error:n.error}),new R(JSON.stringify(n));return g.info("walletFactory.getWallet.success",{address:n.address}),yield this.createWalletInstance(n,a)})}createWallet(r){return y(this,null,function*(){var o,c,d,h,C,p,F,P;let e=m(f({},r),{chain:S(r.chain,this.apiClient.environment)});if(yield(d=(c=(o=e.options)==null?void 0:o.callbacks)==null?void 0:c.onWalletCreationStart)==null?void 0:d.call(c),g.info("walletFactory.createWallet.start"),!this.apiClient.isServerSide&&e.owner!=null)throw g.error("walletFactory.createWallet.error",{error:"Owner field cannot be specified in client-side createWallet calls"}),new l("Owner field cannot be specified in client-side createWallet calls. Owner is determined from JWT authentication.");let t=((h=e.options)==null?void 0:h.deviceSignerKeyStorage)!=null&&e.chain!=="solana"?this.ensureDeviceSignerInSigners(e):(C=e.signers)!=null?C:[],a=yield this.registerSigners(t,e.chain,(p=e.options)==null?void 0:p.deviceSignerKeyStorage),n;if(e.recovery.type==="passkey"&&e.recovery.id==null)n=yield this.createPasskeySigner(e.recovery);else if(e.recovery.type==="server"){let{derivedAddress:I}=w(e.recovery,e.chain,this.apiClient.projectId,this.apiClient.environment);n={type:"server",address:I}}else n=e.recovery;let s=yield this.apiClient.createWallet({type:"smart",chainType:this.getChainType(e.chain),config:f(f({adminSigner:n},e.plugins?{plugins:e.plugins}:{}),a!=null?{delegatedSigners:a}:{}),owner:(F=e.owner)!=null?F:void 0,alias:(P=e.alias)!=null?P:void 0});if("error"in s)throw g.error("walletFactory.createWallet.error",{error:s.error}),new l(JSON.stringify(s));return g.info("walletFactory.createWallet.success",{address:s.address}),yield this.createWalletInstance(s,e)})}createWalletInstance(r,e){return y(this,null,function*(){var h,C;this.validateExistingWalletConfig(r,e);let i=e,t=r.config.adminSigner,a=((h=i.recovery)==null?void 0:h.type)==="server"||((C=i.recovery)==null?void 0:C.type)==="external-wallet"?i.recovery:t,n=r.config.delegatedSigners,s=n;s!=null&&s.length===1&&(s[0].type==="server"||s[0].type==="external-wallet")&&(s=i.signers);let o=t.type==="server"&&"address"in t&&!("secret"in t)?t.address:void 0,c=(n!=null?n:[]).filter(p=>p.type==="server"&&"address"in p&&!("secret"in p)).map(p=>p.address),d=new E({chain:e.chain,address:r.address,owner:r.owner,options:e.options,alias:e.alias,recovery:a,apiRecoveryServerSignerAddress:o,apiDelegatedServerSignerAddresses:c,signers:s!=null?s:[]},this.apiClient);return yield d.waitForInit(),d})}getWalletLocator(r){return`me:${this.getChainType(r.chain)}:smart`+(r.alias!=null?`:alias:${r.alias}`:"")}createPasskeySigner(r){return y(this,null,function*(){var t;if(r.type!=="passkey")throw new Error("Signer is not a passkey");let e=(t=r.name)!=null?t:`Crossmint Wallet ${Date.now()}`,i=r.onCreatePasskey?yield r.onCreatePasskey(e):yield K.createCredential({name:e});return{type:"passkey",id:i.id,name:e,publicKey:{x:i.publicKey.x.toString(),y:i.publicKey.y.toString()}}})}ensureDeviceSignerInSigners(r){var t;let e=(t=r.signers)!=null?t:[];return e.some(a=>a.type==="device")?e:[...e,{type:"device"}]}validateExistingWalletConfig(r,e){if(e.owner!=null&&r.owner!=null&&A(e.owner)!==A(r.owner))throw new l("Wallet owner does not match existing wallet's linked user");if(e.chain==="solana"&&r.chainType!=="solana"||e.chain!=="solana"&&r.chainType==="solana"||e.chain==="stellar"&&r.chainType!=="stellar"||e.chain!=="stellar"&&r.chainType==="stellar")throw new l(`Wallet chain does not match existing wallet's chain. You must use chain: ${r.chainType}.`);if(r.type!=="smart")return;let i=e;if(i.recovery!=null||i.signers!=null){let t=r.config,a=t==null?void 0:t.adminSigner;if(i.recovery!=null&&a!=null){if(i.recovery.type!==a.type)throw new l("The wallet recovery signer type does not match the existing wallet's recovery signer type");k(i.recovery,a)}let n=i.signers;n!=null&&this.validateSigners(r,n,e.chain)}}validateSigners(r,e,i){let t=r.config,a=t==null?void 0:t.delegatedSigners;if(e.length!==0){if(a==null||a.length===0)throw new l(`${e.length} signer(s) specified, but wallet "${r.address}" has no signers. ${$}`);for(let n of e){let s=a.find(o=>{if(this.isMatchingPasskeySigner(n,o,t)||o.type==="device"&&n.type==="device")return!0;if(n.type==="server"){let{primary:c,legacy:d}=b(n,i,this.apiClient.projectId,this.apiClient.environment);return o.locator===`server:${c.derivedAddress}`||d!=null&&o.locator===`server:${d.derivedAddress}`}return o.locator===W(n)});if(s==null){let o=a.map(c=>c.locator).join(", ");throw new l(`Signer '${n.type}' does not exist in wallet "${r.address}". Available signers: ${o}. ${$}`)}k(n,s)}}}isMatchingPasskeySigner(r,e,i){var a,n;let t=((n=(a=i.delegatedSigners)==null?void 0:a.filter(s=>s.type==="passkey").length)!=null?n:0)+(i.adminSigner.type==="passkey"?1:0);if(r.type==="passkey"){if(r.id==null&&t===1)return e.type==="passkey";if(r.id==null&&t>1)throw new l("When creating a wallet with multiple passkeys, you must provide the passkey ID for each passkey.")}return!1}registerSigners(r,e,i){return y(this,null,function*(){var t;return yield Promise.all((t=r==null?void 0:r.map(a=>y(this,null,function*(){if(a.type==="passkey")return a.id==null?{signer:yield this.createPasskeySigner(a)}:{signer:a};if(a.type==="device"){if(a.publicKey!=null)return{signer:{type:"device",publicKey:a.publicKey,name:a.name}};if(a.locator!=null)return{signer:a.locator};if(i==null)throw new l("Device signer key storage is required for device signers");let n=yield x(i);return{signer:{type:"device",publicKey:n.publicKey,name:n.name}}}if(a.type==="server"&&e!=null){let{derivedAddress:n}=w(a,e,this.apiClient.projectId,this.apiClient.environment);return{signer:`server:${n}`}}return{signer:W(a)}})))!=null?t:[])})}getChainType(r){return r==="solana"?"solana":r==="stellar"?"stellar":"evm"}};v([D({logger:g,methodName:"walletFactory.getWallet",buildContext(r,e){if(typeof e[0]=="string"){let t=e[1];return{walletLocator:e[0],chain:t==null?void 0:t.chain}}let i=e[0];return{chain:i==null?void 0:i.chain}}})],u.prototype,"getWallet",1),v([D({logger:g,methodName:"walletFactory.createWallet",buildContext(r,e){return{chain:e[0].chain}}})],u.prototype,"createWallet",1);export{u as a};
1
+ import{a as A,b as k}from"./chunk-JGWGYONV.js";import{a as E}from"./chunk-ACI6AVBC.js";import{a as x}from"./chunk-N4IWDL6M.js";import{a as W}from"./chunk-GOXB2RBF.js";import{b as w,c as b}from"./chunk-MDINF2FR.js";import{f as S}from"./chunk-5UAALAXV.js";import{e as R,g as l}from"./chunk-5OYPWGMX.js";import{a as g}from"./chunk-RFWG2QIH.js";import{a as f,b as m,c as v,g as y}from"./chunk-J3R36SGJ.js";import{WithLoggerContext as D}from"@crossmint/common-sdk-base";import{WebAuthnP256 as K}from"ox";var $="When 'signers' is provided to a method that may fetch an existing wallet, each specified signer must exist in that wallet's configuration.",u=class{constructor(r){this.apiClient=r}getWallet(r,e){return y(this,null,function*(){let i,t;if(typeof r=="string"){if(!this.apiClient.isServerSide)throw new l("getWallet with walletLocator is only available on the server side. Use getWallet(args) instead.");if(e==null)throw new l("Wallet configuration is required when using walletLocator: https://docs.crossmint.com/sdk-reference/wallets/type-aliases/WalletArgsFor");i=r,t=e}else{if(this.apiClient.isServerSide)throw new l("getWallet on server side requires a walletLocator parameter. Use getWallet(walletLocator, args) instead.");t=r,i=this.getWalletLocator(t)}let a=m(f({},t),{chain:S(t.chain,this.apiClient.environment)});g.info("walletFactory.getWallet.start");let n=yield this.apiClient.getWallet(i);if("error"in n)throw g.warn("walletFactory.getWallet.notFound",{error:n.error}),new R(JSON.stringify(n));return g.info("walletFactory.getWallet.success",{address:n.address}),yield this.createWalletInstance(n,a)})}createWallet(r){return y(this,null,function*(){var o,c,d,h,C,p,F,P;let e=m(f({},r),{chain:S(r.chain,this.apiClient.environment)});if(yield(d=(c=(o=e.options)==null?void 0:o.callbacks)==null?void 0:c.onWalletCreationStart)==null?void 0:d.call(c),g.info("walletFactory.createWallet.start"),!this.apiClient.isServerSide&&e.owner!=null)throw g.error("walletFactory.createWallet.error",{error:"Owner field cannot be specified in client-side createWallet calls"}),new l("Owner field cannot be specified in client-side createWallet calls. Owner is determined from JWT authentication.");let t=((h=e.options)==null?void 0:h.deviceSignerKeyStorage)!=null&&e.chain!=="solana"?this.ensureDeviceSignerInSigners(e):(C=e.signers)!=null?C:[],a=yield this.registerSigners(t,e.chain,(p=e.options)==null?void 0:p.deviceSignerKeyStorage),n;if(e.recovery.type==="passkey"&&e.recovery.id==null)n=yield this.createPasskeySigner(e.recovery);else if(e.recovery.type==="server"){let{derivedAddress:I}=w(e.recovery,e.chain,this.apiClient.projectId,this.apiClient.environment);n={type:"server",address:I}}else n=e.recovery;let s=yield this.apiClient.createWallet({type:"smart",chainType:this.getChainType(e.chain),config:f(f({adminSigner:n},e.plugins?{plugins:e.plugins}:{}),a!=null?{delegatedSigners:a}:{}),owner:(F=e.owner)!=null?F:void 0,alias:(P=e.alias)!=null?P:void 0});if("error"in s)throw g.error("walletFactory.createWallet.error",{error:s.error}),new l(JSON.stringify(s));return g.info("walletFactory.createWallet.success",{address:s.address}),yield this.createWalletInstance(s,e)})}createWalletInstance(r,e){return y(this,null,function*(){var h,C;this.validateExistingWalletConfig(r,e);let i=e,t=r.config.adminSigner,a=((h=i.recovery)==null?void 0:h.type)==="server"||((C=i.recovery)==null?void 0:C.type)==="external-wallet"?i.recovery:t,n=r.config.delegatedSigners,s=n;s!=null&&s.length===1&&(s[0].type==="server"||s[0].type==="external-wallet")&&(s=i.signers);let o=t.type==="server"&&"address"in t&&!("secret"in t)?t.address:void 0,c=(n!=null?n:[]).filter(p=>p.type==="server"&&"address"in p&&!("secret"in p)).map(p=>p.address),d=new E({chain:e.chain,address:r.address,owner:r.owner,options:e.options,alias:e.alias,recovery:a,apiRecoveryServerSignerAddress:o,apiDelegatedServerSignerAddresses:c,signers:s!=null?s:[]},this.apiClient);return yield d.waitForInit(),d})}getWalletLocator(r){return`me:${this.getChainType(r.chain)}:smart`+(r.alias!=null?`:alias:${r.alias}`:"")}createPasskeySigner(r){return y(this,null,function*(){var t;if(r.type!=="passkey")throw new Error("Signer is not a passkey");let e=(t=r.name)!=null?t:`Crossmint Wallet ${Date.now()}`,i=r.onCreatePasskey?yield r.onCreatePasskey(e):yield K.createCredential({name:e});return{type:"passkey",id:i.id,name:e,publicKey:{x:i.publicKey.x.toString(),y:i.publicKey.y.toString()}}})}ensureDeviceSignerInSigners(r){var t;let e=(t=r.signers)!=null?t:[];return e.some(a=>a.type==="device")?e:[...e,{type:"device"}]}validateExistingWalletConfig(r,e){if(e.owner!=null&&r.owner!=null&&A(e.owner)!==A(r.owner))throw new l("Wallet owner does not match existing wallet's linked user");if(e.chain==="solana"&&r.chainType!=="solana"||e.chain!=="solana"&&r.chainType==="solana"||e.chain==="stellar"&&r.chainType!=="stellar"||e.chain!=="stellar"&&r.chainType==="stellar")throw new l(`Wallet chain does not match existing wallet's chain. You must use chain: ${r.chainType}.`);if(r.type!=="smart")return;let i=e;if(i.recovery!=null||i.signers!=null){let t=r.config,a=t==null?void 0:t.adminSigner;if(i.recovery!=null&&a!=null){if(i.recovery.type!==a.type)throw new l("The wallet recovery signer type does not match the existing wallet's recovery signer type");k(i.recovery,a)}let n=i.signers;n!=null&&this.validateSigners(r,n,e.chain)}}validateSigners(r,e,i){let t=r.config,a=t==null?void 0:t.delegatedSigners;if(e.length!==0){if(a==null||a.length===0)throw new l(`${e.length} signer(s) specified, but wallet "${r.address}" has no signers. ${$}`);for(let n of e){let s=a.find(o=>{if(this.isMatchingPasskeySigner(n,o,t)||o.type==="device"&&n.type==="device")return!0;if(n.type==="server"){let{primary:c,legacy:d}=b(n,i,this.apiClient.projectId,this.apiClient.environment);return o.locator===`server:${c.derivedAddress}`||d!=null&&o.locator===`server:${d.derivedAddress}`}return o.locator===W(n)});if(s==null){let o=a.map(c=>c.locator).join(", ");throw new l(`Signer '${n.type}' does not exist in wallet "${r.address}". Available signers: ${o}. ${$}`)}k(n,s)}}}isMatchingPasskeySigner(r,e,i){var a,n;let t=((n=(a=i.delegatedSigners)==null?void 0:a.filter(s=>s.type==="passkey").length)!=null?n:0)+(i.adminSigner.type==="passkey"?1:0);if(r.type==="passkey"){if(r.id==null&&t===1)return e.type==="passkey";if(r.id==null&&t>1)throw new l("When creating a wallet with multiple passkeys, you must provide the passkey ID for each passkey.")}return!1}registerSigners(r,e,i){return y(this,null,function*(){var t;return yield Promise.all((t=r==null?void 0:r.map(a=>y(this,null,function*(){if(a.type==="passkey")return a.id==null?{signer:yield this.createPasskeySigner(a)}:{signer:a};if(a.type==="device"){if(a.publicKey!=null)return{signer:{type:"device",publicKey:a.publicKey,name:a.name}};if(a.locator!=null)return{signer:a.locator};if(i==null)throw new l("Device signer key storage is required for device signers");let n=yield x(i);return{signer:{type:"device",publicKey:n.publicKey,name:n.name}}}if(a.type==="server"&&e!=null){let{derivedAddress:n}=w(a,e,this.apiClient.projectId,this.apiClient.environment);return{signer:`server:${n}`}}return{signer:W(a)}})))!=null?t:[])})}getChainType(r){return r==="solana"?"solana":r==="stellar"?"stellar":"evm"}};v([D({logger:g,methodName:"walletFactory.getWallet",buildContext(r,e){if(typeof e[0]=="string"){let t=e[1];return{walletLocator:e[0],chain:t==null?void 0:t.chain}}let i=e[0];return{chain:i==null?void 0:i.chain}}})],u.prototype,"getWallet",1),v([D({logger:g,methodName:"walletFactory.createWallet",buildContext(r,e){return{chain:e[0].chain}}})],u.prototype,"createWallet",1);export{u as a};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkENU3EKBGcjs = require('./chunk-ENU3EKBG.cjs');var _chunk5FH7WFWLcjs = require('./chunk-5FH7WFWL.cjs');var _chunkYGL4ITFKcjs = require('./chunk-YGL4ITFK.cjs');var _accounts = require('viem/accounts');var _utils = require('@noble/hashes/utils');var _web3js = require('@solana/web3.js');function a(r,e){switch(_chunkENU3EKBGcjs.a.call(void 0, e)){case"evm":return _accounts.privateKeyToAccount.call(void 0, `0x${_utils.bytesToHex.call(void 0, r)}`).address;case"solana":return _web3js.Keypair.fromSeed(r).publicKey.toBase58();case"stellar":return _chunk5FH7WFWLcjs.a.call(void 0, _chunk5FH7WFWLcjs.b.call(void 0, r).publicKey)}}function x(r,e,i,t){if(typeof window!="undefined")throw new Error("Server signers can only be used from server-side code.");let s=_chunkENU3EKBGcjs.a.call(void 0, e),n=_chunkYGL4ITFKcjs.a.call(void 0, r.secret,i,t,s),y=a(n,e);return{derivedKeyBytes:n,derivedAddress:y}}function B(r,e,i,t){if(typeof window!="undefined")throw new Error("Server signers can only be used from server-side code.");let s=_chunkENU3EKBGcjs.a.call(void 0, e),n=_chunkYGL4ITFKcjs.a.call(void 0, r.secret,i,t,s),y=a(n,e),c={derivedKeyBytes:n,derivedAddress:y},p=typeof e=="string"?e:String(e);if(s==="evm"&&p!=="evm"){let v=_chunkYGL4ITFKcjs.a.call(void 0, r.secret,i,t,p),m=a(v,e);return{primary:c,legacy:{derivedKeyBytes:v,derivedAddress:m}}}return{primary:c,legacy:null}}exports.a = a; exports.b = x; exports.c = B;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkENU3EKBGcjs = require('./chunk-ENU3EKBG.cjs');var _chunk5FH7WFWLcjs = require('./chunk-5FH7WFWL.cjs');var _chunkYGL4ITFKcjs = require('./chunk-YGL4ITFK.cjs');var _accounts = require('viem/accounts');var _utils = require('@noble/hashes/utils');var _web3js = require('@solana/web3.js');function y(r,e){switch(_chunkENU3EKBGcjs.a.call(void 0, e)){case"evm":return _accounts.privateKeyToAccount.call(void 0, `0x${_utils.bytesToHex.call(void 0, r)}`).address;case"solana":return _web3js.Keypair.fromSeed(r).publicKey.toBase58();case"stellar":return _chunk5FH7WFWLcjs.a.call(void 0, _chunk5FH7WFWLcjs.b.call(void 0, r).publicKey)}}function x(r,e,i,t){if(typeof window!="undefined")throw new Error("Server signers can only be used from server-side code.");let s=_chunkENU3EKBGcjs.a.call(void 0, e),n=_chunkYGL4ITFKcjs.a.call(void 0, r.secret,i,t,s),a=y(n,e);return{derivedKeyBytes:n,derivedAddress:a}}function B(r,e,i,t){if(typeof window!="undefined")throw new Error("Server signers can only be used from server-side code.");let s=_chunkENU3EKBGcjs.a.call(void 0, e),n=_chunkYGL4ITFKcjs.a.call(void 0, r.secret,i,t,s),a=y(n,e),c={derivedKeyBytes:n,derivedAddress:a},p=typeof e=="string"?e:String(e);if(s==="evm"&&p!=="evm"){let v=_chunkYGL4ITFKcjs.a.call(void 0, r.secret,i,t,p),m=y(v,e);return{primary:c,legacy:{derivedKeyBytes:v,derivedAddress:m}}}return{primary:c,legacy:null}}exports.a = y; exports.b = x; exports.c = B;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _chunk6QCKGV44cjs = require('./chunk-6QCKGV44.cjs');var _chunkSFXFZ2J5cjs = require('./chunk-SFXFZ2J5.cjs');var _chunk2GKPWQBQcjs = require('./chunk-2GKPWQBQ.cjs');var _web3js = require('@solana/web3.js');var _bs58 = require('bs58'); var _bs582 = _interopRequireDefault(_bs58);var g=class c extends _chunk6QCKGV44cjs.a{constructor(n){super(n)}signMessage(){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){return yield Promise.reject(new Error("signMessage method not implemented for email signer"))})}signTransaction(n){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){var i;yield this.handleAuthRequired();let d=this.getJwtOrThrow(),m=_bs582.default.decode(n),y=_web3js.VersionedTransaction.deserialize(m).message.serialize();_chunkSFXFZ2J5cjs.a.info("sign: sending request",{keyType:"ed25519"});let l=Date.now(),e=yield(i=this.config.clientTEEConnection)==null?void 0:i.sendAction({event:"request:sign",responseEvent:"response:sign",data:{authData:{jwt:d,apiKey:this.config.crossmint.apiKey},data:{keyType:"ed25519",bytes:_bs582.default.encode(new Uint8Array(y)),encoding:"base58"}},options:_chunk6QCKGV44cjs.b});if(_chunkSFXFZ2J5cjs.a.info("sign: response received",{status:e==null?void 0:e.status,durationMs:Date.now()-l}),(e==null?void 0:e.status)==="error")throw new Error(e.error);if((e==null?void 0:e.signature)==null)throw new Error("Failed to sign transaction");return c.verifyPublicKeyFormat(e.publicKey),{signature:e.signature.bytes}})}static verifyPublicKeyFormat(n){if(n==null)throw new Error("No public key found");if(n.encoding!=="base58"||n.keyType!=="ed25519"||n.bytes==null)throw new Error("Not supported. Expected public key to be in base58 encoding and ed25519 key type. Got: "+JSON.stringify(n))}getChainKeyParams(){return{scheme:"ed25519",encoding:"base58"}}};exports.a = g;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }var _chunk2Y3AQN2Scjs = require('./chunk-2Y3AQN2S.cjs');var _chunkJLTD3KKUcjs = require('./chunk-JLTD3KKU.cjs');var _chunk2GKPWQBQcjs = require('./chunk-2GKPWQBQ.cjs');var _web3js = require('@solana/web3.js');var _bs58 = require('bs58'); var _bs582 = _interopRequireDefault(_bs58);var g=class c extends _chunk2Y3AQN2Scjs.a{constructor(n){super(n)}signMessage(){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){return yield Promise.reject(new Error("signMessage method not implemented for email signer"))})}signTransaction(n){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){var i;yield this.handleAuthRequired();let d=this.getJwtOrThrow(),m=_bs582.default.decode(n),y=_web3js.VersionedTransaction.deserialize(m).message.serialize();_chunkJLTD3KKUcjs.a.info("sign: sending request",{keyType:"ed25519"});let l=Date.now(),e=yield(i=this.config.clientTEEConnection)==null?void 0:i.sendAction({event:"request:sign",responseEvent:"response:sign",data:{authData:{jwt:d,apiKey:this.config.crossmint.apiKey},data:{keyType:"ed25519",bytes:_bs582.default.encode(new Uint8Array(y)),encoding:"base58"}},options:_chunk2Y3AQN2Scjs.b});if(_chunkJLTD3KKUcjs.a.info("sign: response received",{status:e==null?void 0:e.status,durationMs:Date.now()-l}),(e==null?void 0:e.status)==="error")throw new Error(e.error);if((e==null?void 0:e.signature)==null)throw new Error("Failed to sign transaction");return c.verifyPublicKeyFormat(e.publicKey),{signature:e.signature.bytes}})}static verifyPublicKeyFormat(n){if(n==null)throw new Error("No public key found");if(n.encoding!=="base58"||n.keyType!=="ed25519"||n.bytes==null)throw new Error("Not supported. Expected public key to be in base58 encoding and ed25519 key type. Got: "+JSON.stringify(n))}getChainKeyParams(){return{scheme:"ed25519",encoding:"base58"}}};exports.a = g;
@@ -1 +1 @@
1
- import{a as v}from"./chunk-IOSADDL5.js";import{a as l}from"./chunk-VOVJ4RNT.js";import{c as d,g as n}from"./chunk-J3R36SGJ.js";import{getEnvironmentForKey as E,APIKeyEnvironmentPrefix as h,WithLoggerContext as u}from"@crossmint/common-sdk-base";import{WebAuthnP256 as w}from"ox";var b={[h.DEVELOPMENT]:"https://development.devicekey.store",[h.STAGING]:"https://staging.devicekey.store",[h.PRODUCTION]:"https://devicekey.store"},P=6e4,K="indexeddb-fatal",c=class extends v{constructor(e){super(e);this.iframePromise=null;this.reloading=null;this.biometricRequestHandler=null;this.biometricListener=null;let r=E(e);if(r==null)throw new Error("Unable to determine environment from API key");this.iframeUrl=b[r]}setBiometricRequestHandler(e){this.biometricRequestHandler=e}generateKey(){return n(this,arguments,function*(e={biometricPolicy:"none"}){return(yield this.rpc("generateKey",e)).publicKeyBase64})}mapAddressToKey(e,r){return n(this,null,function*(){yield this.rpc("mapAddressToKey",{address:e,publicKeyBase64:r})})}getKey(e){return n(this,null,function*(){return(yield this.rpc("getKey",{address:e})).publicKeyBase64})}hasKey(e){return n(this,null,function*(){return(yield this.rpc("hasKey",{publicKeyBase64:e})).hasKey})}signMessage(e,r){return n(this,null,function*(){return yield this.rpc("signMessage",{address:e,message:r})})}deleteKey(e){return n(this,null,function*(){yield this.rpc("deleteKey",{address:e})})}destroy(){this.biometricListener!=null&&(window.removeEventListener("message",this.biometricListener),this.biometricListener=null),this.iframePromise!=null&&(this.iframePromise.then(e=>e.remove()).catch(()=>{}),this.iframePromise=null)}rpc(e,r){return n(this,null,function*(){let i=yield this.sendRpc(e,r);if(i.fatal){l.warn(`[IframeDeviceSignerKeyStorage] Recoverable IDB error on "${e}", reloading iframe and retrying`),yield this.reloadIframe();let t=yield this.sendRpc(e,r);if(t.fatal)throw new Error(`Device signer IDB fatal error on "${e}" persisted after iframe reload`);return t.value}return i.value})}sendRpc(e,r){return n(this,null,function*(){let t=(yield this.getIframe()).contentWindow;if(t==null)throw new Error("Device signer iframe has no contentWindow");let g=crypto.randomUUID(),a=new URL(this.iframeUrl).origin;return new Promise((s,o)=>{let f=setTimeout(()=>{window.removeEventListener("message",p),o(new Error(`Device signer RPC "${e}" timed out after ${P}ms`))},P);function p(y){let m=y.data;m==null||m.id!==g||y.origin===a&&(clearTimeout(f),window.removeEventListener("message",p),m.type==="error"&&m.code===K?s({fatal:!0}):m.type==="error"?o(new Error(m.error)):s({value:m.result,fatal:!1}))}window.addEventListener("message",p),t.postMessage({type:e,id:g,payload:r},this.iframeUrl)})})}reloadIframe(){return n(this,null,function*(){if(this.reloading!=null)return this.reloading;let e=n(this,null,function*(){try{this.destroy(),yield this.getIframe()}finally{this.reloading=null}});return this.reloading=e,e})}setupBiometricListener(e){let r=new URL(this.iframeUrl).origin;this.biometricListener=i=>n(this,null,function*(){if(i.origin!==r)return;let t=i.data;if((t==null?void 0:t.type)!=="biometric-request")return;let g=e.contentWindow;if(g!=null)try{this.biometricRequestHandler!=null&&(yield this.biometricRequestHandler(t.action));let a=null;if(t.action==="createCredential"){let s=t.payload,o=yield w.createCredential({name:s.name});a={id:o.id,publicKey:{x:`0x${o.publicKey.x.toString(16)}`,y:`0x${o.publicKey.y.toString(16)}`}}}else if(t.action==="sign"){let s=t.payload,{signature:o,metadata:f}=yield w.sign({credentialId:s.credentialId,challenge:s.challenge});a={signature:{r:`0x${o.r.toString(16)}`,s:`0x${o.s.toString(16)}`},metadata:f}}g.postMessage({type:"biometric-response",id:t.id,result:a},this.iframeUrl)}catch(a){let s=a instanceof Error?a.message:"Unknown biometric error";g.postMessage({type:"biometric-response",id:t.id,error:s},this.iframeUrl)}}),window.addEventListener("message",this.biometricListener)}getIframe(){return this.iframePromise==null&&(this.iframePromise=this.createIframe().catch(e=>{throw this.iframePromise=null,e})),this.iframePromise}createIframe(){let e=document.createElement("iframe");return e.src=this.iframeUrl,Object.assign(e.style,{position:"absolute",opacity:"0",pointerEvents:"none",width:"0",height:"0",border:"none",top:"-9999px",left:"-9999px"}),new Promise((r,i)=>{e.onload=()=>{this.setupBiometricListener(e),r(e)},e.onerror=()=>i(new Error("Failed to load device signer iframe")),document.body.appendChild(e)})}getDeviceName(){var t;if(typeof navigator=="undefined")return"Unknown Device";let e=navigator.userAgent,r=this.parseDevice(e),i=this.parseBrowser(e);return r!=null&&i!=null?`${i} on ${r}`:(t=r!=null?r:i)!=null?t:"Unknown Device"}parseDevice(e){return/iPad/.test(e)?"iPad":/iPhone/.test(e)?"iPhone":/Macintosh|Mac OS X/.test(e)?"Mac":/Windows/.test(e)?"Windows":/Android/.test(e)?"Android":/Linux/.test(e)?"Linux":/CrOS/.test(e)?"ChromeOS":null}parseBrowser(e){return/Edg\//.test(e)?"Edge":/OPR\/|Opera/.test(e)?"Opera":typeof navigator!="undefined"&&"brave"in navigator?"Brave":/Chrome\//.test(e)?"Chrome":/Safari\//.test(e)&&!/Chrome\//.test(e)?"Safari":/Firefox\//.test(e)?"Firefox":null}};d([u({logger:l,methodName:"deviceSignerKeyStorage.generateKey"})],c.prototype,"generateKey",1),d([u({logger:l,methodName:"deviceSignerKeyStorage.mapAddressToKey"})],c.prototype,"mapAddressToKey",1),d([u({logger:l,methodName:"deviceSignerKeyStorage.getKey"})],c.prototype,"getKey",1),d([u({logger:l,methodName:"deviceSignerKeyStorage.hasKey"})],c.prototype,"hasKey",1),d([u({logger:l,methodName:"deviceSignerKeyStorage.signMessage"})],c.prototype,"signMessage",1),d([u({logger:l,methodName:"deviceSignerKeyStorage.deleteKey"})],c.prototype,"deleteKey",1);export{c as a};
1
+ import{a as v}from"./chunk-IOSADDL5.js";import{a as l}from"./chunk-RFWG2QIH.js";import{c as d,g as n}from"./chunk-J3R36SGJ.js";import{getEnvironmentForKey as E,APIKeyEnvironmentPrefix as h,WithLoggerContext as u}from"@crossmint/common-sdk-base";import{WebAuthnP256 as w}from"ox";var b={[h.DEVELOPMENT]:"https://development.devicekey.store",[h.STAGING]:"https://staging.devicekey.store",[h.PRODUCTION]:"https://devicekey.store"},P=6e4,K="indexeddb-fatal",c=class extends v{constructor(e){super(e);this.iframePromise=null;this.reloading=null;this.biometricRequestHandler=null;this.biometricListener=null;let r=E(e);if(r==null)throw new Error("Unable to determine environment from API key");this.iframeUrl=b[r]}setBiometricRequestHandler(e){this.biometricRequestHandler=e}generateKey(){return n(this,arguments,function*(e={biometricPolicy:"none"}){return(yield this.rpc("generateKey",e)).publicKeyBase64})}mapAddressToKey(e,r){return n(this,null,function*(){yield this.rpc("mapAddressToKey",{address:e,publicKeyBase64:r})})}getKey(e){return n(this,null,function*(){return(yield this.rpc("getKey",{address:e})).publicKeyBase64})}hasKey(e){return n(this,null,function*(){return(yield this.rpc("hasKey",{publicKeyBase64:e})).hasKey})}signMessage(e,r){return n(this,null,function*(){return yield this.rpc("signMessage",{address:e,message:r})})}deleteKey(e){return n(this,null,function*(){yield this.rpc("deleteKey",{address:e})})}destroy(){this.biometricListener!=null&&(window.removeEventListener("message",this.biometricListener),this.biometricListener=null),this.iframePromise!=null&&(this.iframePromise.then(e=>e.remove()).catch(()=>{}),this.iframePromise=null)}rpc(e,r){return n(this,null,function*(){let i=yield this.sendRpc(e,r);if(i.fatal){l.warn(`[IframeDeviceSignerKeyStorage] Recoverable IDB error on "${e}", reloading iframe and retrying`),yield this.reloadIframe();let t=yield this.sendRpc(e,r);if(t.fatal)throw new Error(`Device signer IDB fatal error on "${e}" persisted after iframe reload`);return t.value}return i.value})}sendRpc(e,r){return n(this,null,function*(){let t=(yield this.getIframe()).contentWindow;if(t==null)throw new Error("Device signer iframe has no contentWindow");let g=crypto.randomUUID(),a=new URL(this.iframeUrl).origin;return new Promise((s,o)=>{let f=setTimeout(()=>{window.removeEventListener("message",p),o(new Error(`Device signer RPC "${e}" timed out after ${P}ms`))},P);function p(y){let m=y.data;m==null||m.id!==g||y.origin===a&&(clearTimeout(f),window.removeEventListener("message",p),m.type==="error"&&m.code===K?s({fatal:!0}):m.type==="error"?o(new Error(m.error)):s({value:m.result,fatal:!1}))}window.addEventListener("message",p),t.postMessage({type:e,id:g,payload:r},this.iframeUrl)})})}reloadIframe(){return n(this,null,function*(){if(this.reloading!=null)return this.reloading;let e=n(this,null,function*(){try{this.destroy(),yield this.getIframe()}finally{this.reloading=null}});return this.reloading=e,e})}setupBiometricListener(e){let r=new URL(this.iframeUrl).origin;this.biometricListener=i=>n(this,null,function*(){if(i.origin!==r)return;let t=i.data;if((t==null?void 0:t.type)!=="biometric-request")return;let g=e.contentWindow;if(g!=null)try{this.biometricRequestHandler!=null&&(yield this.biometricRequestHandler(t.action));let a=null;if(t.action==="createCredential"){let s=t.payload,o=yield w.createCredential({name:s.name});a={id:o.id,publicKey:{x:`0x${o.publicKey.x.toString(16)}`,y:`0x${o.publicKey.y.toString(16)}`}}}else if(t.action==="sign"){let s=t.payload,{signature:o,metadata:f}=yield w.sign({credentialId:s.credentialId,challenge:s.challenge});a={signature:{r:`0x${o.r.toString(16)}`,s:`0x${o.s.toString(16)}`},metadata:f}}g.postMessage({type:"biometric-response",id:t.id,result:a},this.iframeUrl)}catch(a){let s=a instanceof Error?a.message:"Unknown biometric error";g.postMessage({type:"biometric-response",id:t.id,error:s},this.iframeUrl)}}),window.addEventListener("message",this.biometricListener)}getIframe(){return this.iframePromise==null&&(this.iframePromise=this.createIframe().catch(e=>{throw this.iframePromise=null,e})),this.iframePromise}createIframe(){let e=document.createElement("iframe");return e.src=this.iframeUrl,Object.assign(e.style,{position:"absolute",opacity:"0",pointerEvents:"none",width:"0",height:"0",border:"none",top:"-9999px",left:"-9999px"}),new Promise((r,i)=>{e.onload=()=>{this.setupBiometricListener(e),r(e)},e.onerror=()=>i(new Error("Failed to load device signer iframe")),document.body.appendChild(e)})}getDeviceName(){var t;if(typeof navigator=="undefined")return"Unknown Device";let e=navigator.userAgent,r=this.parseDevice(e),i=this.parseBrowser(e);return r!=null&&i!=null?`${i} on ${r}`:(t=r!=null?r:i)!=null?t:"Unknown Device"}parseDevice(e){return/iPad/.test(e)?"iPad":/iPhone/.test(e)?"iPhone":/Macintosh|Mac OS X/.test(e)?"Mac":/Windows/.test(e)?"Windows":/Android/.test(e)?"Android":/Linux/.test(e)?"Linux":/CrOS/.test(e)?"ChromeOS":null}parseBrowser(e){return/Edg\//.test(e)?"Edge":/OPR\/|Opera/.test(e)?"Opera":typeof navigator!="undefined"&&"brave"in navigator?"Brave":/Chrome\//.test(e)?"Chrome":/Safari\//.test(e)&&!/Chrome\//.test(e)?"Safari":/Firefox\//.test(e)?"Firefox":null}};d([u({logger:l,methodName:"deviceSignerKeyStorage.generateKey"})],c.prototype,"generateKey",1),d([u({logger:l,methodName:"deviceSignerKeyStorage.mapAddressToKey"})],c.prototype,"mapAddressToKey",1),d([u({logger:l,methodName:"deviceSignerKeyStorage.getKey"})],c.prototype,"getKey",1),d([u({logger:l,methodName:"deviceSignerKeyStorage.hasKey"})],c.prototype,"hasKey",1),d([u({logger:l,methodName:"deviceSignerKeyStorage.signMessage"})],c.prototype,"signMessage",1),d([u({logger:l,methodName:"deviceSignerKeyStorage.deleteKey"})],c.prototype,"deleteKey",1);export{c as a};
@@ -1 +1 @@
1
- import{b as n,c as i}from"./chunk-Y55LWZDS.js";import{SdkLogger as d,BrowserDatadogSink as k,detectPlatform as g,validateAPIKey as l,ServerDatadogSink as m}from"@crossmint/common-sdk-base";var t=new d;function f(s){let o=g(),e=l(s);if(!e.isValid)throw new Error(`Invalid API key: ${e.message}`);let{environment:a,projectId:c}=e;switch(t.init({packageName:i,packageVersion:n,environment:a,projectId:c,platform:o}),o){case"browser":{let r=new k(a);t.addSink(r);break}case"react-native":break;case"server":{let r=new m(a);t.addSink(r);break}default:break}}export{t as a,f as b};
1
+ import{b as n,c as i}from"./chunk-2FKIDTGK.js";import{SdkLogger as d,BrowserDatadogSink as k,detectPlatform as g,validateAPIKey as l,ServerDatadogSink as m}from"@crossmint/common-sdk-base";var t=new d;function f(s){let o=g(),e=l(s);if(!e.isValid)throw new Error(`Invalid API key: ${e.message}`);let{environment:a,projectId:c}=e;switch(t.init({packageName:i,packageVersion:n,environment:a,projectId:c,platform:o}),o){case"browser":{let r=new k(a);t.addSink(r);break}case"react-native":break;case"server":{let r=new m(a);t.addSink(r);break}default:break}}export{t as a,f as b};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkGEY574THcjs = require('./chunk-GEY574TH.cjs');var _chunkUE3WVHTMcjs = require('./chunk-UE3WVHTM.cjs');var _chunk5X4EOJFGcjs = require('./chunk-5X4EOJFG.cjs');var _chunkHRUMWG2Fcjs = require('./chunk-HRUMWG2F.cjs');var _chunkIR5WN6FQcjs = require('./chunk-IR5WN6FQ.cjs');var _chunkOWQZPI3Ucjs = require('./chunk-OWQZPI3U.cjs');var _chunkJLTD3KKUcjs = require('./chunk-JLTD3KKU.cjs');var _commonsdkbase = require('@crossmint/common-sdk-base');var _chains = require('viem/chains');var w=[_commonsdkbase.BlockchainIncludingTestnet.ABSTRACT_TESTNET,_commonsdkbase.BlockchainIncludingTestnet.ARBITRUM_SEPOLIA,_commonsdkbase.BlockchainIncludingTestnet.BASE_SEPOLIA,_commonsdkbase.BlockchainIncludingTestnet.CURTIS,_commonsdkbase.BlockchainIncludingTestnet.ETHEREUM_SEPOLIA,_commonsdkbase.BlockchainIncludingTestnet.FLOW_TESTNET,_commonsdkbase.BlockchainIncludingTestnet.MANTLE_SEPOLIA,_commonsdkbase.BlockchainIncludingTestnet.MODE_SEPOLIA,_commonsdkbase.BlockchainIncludingTestnet.OPTIMISM_SEPOLIA,_commonsdkbase.BlockchainIncludingTestnet.PLUME_TESTNET,_commonsdkbase.BlockchainIncludingTestnet.POLYGON_AMOY,_commonsdkbase.BlockchainIncludingTestnet.SCROLL_SEPOLIA,_commonsdkbase.BlockchainIncludingTestnet.SEI_ATLANTIC_2_TESTNET,_commonsdkbase.BlockchainIncludingTestnet.STORY_TESTNET,_commonsdkbase.BlockchainIncludingTestnet.WORLD_CHAIN_SEPOLIA,_commonsdkbase.BlockchainIncludingTestnet.ZORA_SEPOLIA,_commonsdkbase.BlockchainIncludingTestnet.ARC_TESTNET,_commonsdkbase.BlockchainIncludingTestnet.TEMPO_TESTNET],D=[_commonsdkbase.BlockchainIncludingTestnet.ABSTRACT,_commonsdkbase.BlockchainIncludingTestnet.APECHAIN,_commonsdkbase.BlockchainIncludingTestnet.ARBITRUM,_commonsdkbase.BlockchainIncludingTestnet.ARBITRUMNOVA,_commonsdkbase.BlockchainIncludingTestnet.BASE,_commonsdkbase.BlockchainIncludingTestnet.BSC,_commonsdkbase.BlockchainIncludingTestnet.ETHEREUM,_commonsdkbase.BlockchainIncludingTestnet.FLOW,_commonsdkbase.BlockchainIncludingTestnet.MANTLE,_commonsdkbase.BlockchainIncludingTestnet.MODE,_commonsdkbase.BlockchainIncludingTestnet.OPTIMISM,_commonsdkbase.BlockchainIncludingTestnet.PLUME,_commonsdkbase.BlockchainIncludingTestnet.POLYGON,_commonsdkbase.BlockchainIncludingTestnet.SCROLL,_commonsdkbase.BlockchainIncludingTestnet.SEI_PACIFIC_1,_commonsdkbase.BlockchainIncludingTestnet.SHAPE,_commonsdkbase.BlockchainIncludingTestnet.STORY,_commonsdkbase.BlockchainIncludingTestnet.TEMPO,_commonsdkbase.BlockchainIncludingTestnet.WORLDCHAIN,_commonsdkbase.BlockchainIncludingTestnet.ZORA];function X(t){switch(t){case _commonsdkbase.BlockchainIncludingTestnet.BASE_SEPOLIA:return _chains.baseSepolia;case _commonsdkbase.BlockchainIncludingTestnet.BASE:return _chains.base;case _commonsdkbase.BlockchainIncludingTestnet.POLYGON_AMOY:return _chains.polygonAmoy;case _commonsdkbase.BlockchainIncludingTestnet.POLYGON:return _chains.polygon;case _commonsdkbase.BlockchainIncludingTestnet.OPTIMISM_SEPOLIA:return _chains.optimismSepolia;case _commonsdkbase.BlockchainIncludingTestnet.OPTIMISM:return _chains.optimism;case _commonsdkbase.BlockchainIncludingTestnet.ARBITRUM_SEPOLIA:return _chains.arbitrumSepolia;case _commonsdkbase.BlockchainIncludingTestnet.ARBITRUM:return _chains.arbitrum;case _commonsdkbase.BlockchainIncludingTestnet.ARBITRUMNOVA:return _chains.arbitrumNova;case _commonsdkbase.BlockchainIncludingTestnet.STORY_TESTNET:return _chunkGEY574THcjs.a;case _commonsdkbase.BlockchainIncludingTestnet.STORY:return _chunkIR5WN6FQcjs.a;case _commonsdkbase.BlockchainIncludingTestnet.MODE_SEPOLIA:return _chains.modeTestnet;case _commonsdkbase.BlockchainIncludingTestnet.MODE:return _chains.mode;case _commonsdkbase.BlockchainIncludingTestnet.BSC:return _chains.bsc;case _commonsdkbase.BlockchainIncludingTestnet.SHAPE:return _chains.shape;case _commonsdkbase.BlockchainIncludingTestnet.ZORA:return _chains.zora;case _commonsdkbase.BlockchainIncludingTestnet.ZORA_SEPOLIA:return _chains.zoraSepolia;case _commonsdkbase.BlockchainIncludingTestnet.ETHEREUM_SEPOLIA:return _chains.sepolia;case _commonsdkbase.BlockchainIncludingTestnet.ETHEREUM:return _chains.mainnet;case _commonsdkbase.BlockchainIncludingTestnet.FLOW:return _chains.flowMainnet;case _commonsdkbase.BlockchainIncludingTestnet.FLOW_TESTNET:return _chains.flowTestnet;case _commonsdkbase.BlockchainIncludingTestnet.PLUME_TESTNET:return _chains.plumeTestnet;case _commonsdkbase.BlockchainIncludingTestnet.PLUME:return _chains.plume;case _commonsdkbase.BlockchainIncludingTestnet.ARC_TESTNET:return _chunkHRUMWG2Fcjs.a;case _commonsdkbase.BlockchainIncludingTestnet.TEMPO:return _chunkUE3WVHTMcjs.a;case _commonsdkbase.BlockchainIncludingTestnet.TEMPO_TESTNET:return _chunk5X4EOJFGcjs.a;case _commonsdkbase.BlockchainIncludingTestnet.ABSTRACT:case _commonsdkbase.BlockchainIncludingTestnet.ABSTRACT_TESTNET:case _commonsdkbase.BlockchainIncludingTestnet.APECHAIN:case _commonsdkbase.BlockchainIncludingTestnet.MANTLE:case _commonsdkbase.BlockchainIncludingTestnet.MANTLE_SEPOLIA:case _commonsdkbase.BlockchainIncludingTestnet.SCROLL:case _commonsdkbase.BlockchainIncludingTestnet.SCROLL_SEPOLIA:case _commonsdkbase.BlockchainIncludingTestnet.SEI_PACIFIC_1:case _commonsdkbase.BlockchainIncludingTestnet.SEI_ATLANTIC_2_TESTNET:case _commonsdkbase.BlockchainIncludingTestnet.CURTIS:case _commonsdkbase.BlockchainIncludingTestnet.WORLDCHAIN:case _commonsdkbase.BlockchainIncludingTestnet.WORLD_CHAIN_SEPOLIA:throw new Error(`Chain ${t} is not yet supported in toViemChain function. Please add the appropriate viem chain definition.`);default:throw new Error(`Unknown chain: ${t}`)}}function I(t){return w.includes(t)}function C(t){return D.includes(t)}var Y={[_commonsdkbase.BlockchainIncludingTestnet.ABSTRACT]:_commonsdkbase.BlockchainIncludingTestnet.ABSTRACT_TESTNET,[_commonsdkbase.BlockchainIncludingTestnet.APECHAIN]:_commonsdkbase.BlockchainIncludingTestnet.CURTIS,[_commonsdkbase.BlockchainIncludingTestnet.ARBITRUM]:_commonsdkbase.BlockchainIncludingTestnet.ARBITRUM_SEPOLIA,[_commonsdkbase.BlockchainIncludingTestnet.BASE]:_commonsdkbase.BlockchainIncludingTestnet.BASE_SEPOLIA,[_commonsdkbase.BlockchainIncludingTestnet.ETHEREUM]:_commonsdkbase.BlockchainIncludingTestnet.ETHEREUM_SEPOLIA,[_commonsdkbase.BlockchainIncludingTestnet.FLOW]:_commonsdkbase.BlockchainIncludingTestnet.FLOW_TESTNET,[_commonsdkbase.BlockchainIncludingTestnet.MANTLE]:_commonsdkbase.BlockchainIncludingTestnet.MANTLE_SEPOLIA,[_commonsdkbase.BlockchainIncludingTestnet.MODE]:_commonsdkbase.BlockchainIncludingTestnet.MODE_SEPOLIA,[_commonsdkbase.BlockchainIncludingTestnet.OPTIMISM]:_commonsdkbase.BlockchainIncludingTestnet.OPTIMISM_SEPOLIA,[_commonsdkbase.BlockchainIncludingTestnet.PLUME]:_commonsdkbase.BlockchainIncludingTestnet.PLUME_TESTNET,[_commonsdkbase.BlockchainIncludingTestnet.POLYGON]:_commonsdkbase.BlockchainIncludingTestnet.POLYGON_AMOY,[_commonsdkbase.BlockchainIncludingTestnet.SCROLL]:_commonsdkbase.BlockchainIncludingTestnet.SCROLL_SEPOLIA,[_commonsdkbase.BlockchainIncludingTestnet.SEI_PACIFIC_1]:_commonsdkbase.BlockchainIncludingTestnet.SEI_ATLANTIC_2_TESTNET,[_commonsdkbase.BlockchainIncludingTestnet.STORY]:_commonsdkbase.BlockchainIncludingTestnet.STORY_TESTNET,[_commonsdkbase.BlockchainIncludingTestnet.WORLDCHAIN]:_commonsdkbase.BlockchainIncludingTestnet.WORLD_CHAIN_SEPOLIA,[_commonsdkbase.BlockchainIncludingTestnet.ZORA]:_commonsdkbase.BlockchainIncludingTestnet.ZORA_SEPOLIA,[_commonsdkbase.BlockchainIncludingTestnet.TEMPO]:_commonsdkbase.BlockchainIncludingTestnet.TEMPO_TESTNET};function g(t){return Y[t]}function F(t){return t==="solana"||t==="stellar"||I(t)||C(t)}function ee(t,a){if(!F(t))throw new (0, _chunkOWQZPI3Ucjs.c)(`Unknown chain "${t}". Please use a supported chain name (e.g. "base-sepolia", "polygon", "solana", "stellar").`);if(t==="solana"||t==="stellar")return t;let r=t,T=a===_commonsdkbase.APIKeyEnvironmentPrefix.PRODUCTION;if(T&&I(r))throw new (0, _chunkOWQZPI3Ucjs.b)(`Chain "${t}" is a testnet chain and cannot be used in production. Please use a mainnet chain instead.`);if(!T&&C(r)){let n=g(r);if(n!=null)return _chunkJLTD3KKUcjs.a.debug("validateChainForEnvironment.autoConverted",{chain:t,convertedTo:n,environment:a,message:`Chain "${t}" is a mainnet chain and cannot be used in ${a} environment. Automatically converted to "${n}".`}),n;_chunkJLTD3KKUcjs.a.debug("validateChainForEnvironment.mismatch",{chain:t,environment:a,message:`Chain "${t}" is a mainnet chain and should not be used in ${a} environment. No testnet equivalent is available. Please use a testnet chain instead.`})}return t}exports.a = X; exports.b = I; exports.c = C; exports.d = g; exports.e = F; exports.f = ee;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkLFUTA2C4cjs = require('./chunk-LFUTA2C4.cjs');var _chunkYHV3672Rcjs = require('./chunk-YHV3672R.cjs');var _chunk5NP5DTTCcjs = require('./chunk-5NP5DTTC.cjs');var _chunkSFXFZ2J5cjs = require('./chunk-SFXFZ2J5.cjs');var _chunk2GKPWQBQcjs = require('./chunk-2GKPWQBQ.cjs');var _commonsdkbase = require('@crossmint/common-sdk-base');var _ox = require('ox');var o=class c{constructor(e){_chunkSFXFZ2J5cjs.b.call(void 0, e.apiKey);let t=new (0, _chunk5NP5DTTCcjs.a)(e);this.walletFactory=new (0, _chunkLFUTA2C4cjs.a)(t),_chunkSFXFZ2J5cjs.a.info("wallets.sdk.initialized")}static from(e){return new c(e)}getWallet(e,t){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){if(typeof e=="string"){if(t==null)throw new Error("Args parameter is required when walletLocator is provided");return yield this.walletFactory.getWallet(e,t)}return yield this.walletFactory.getWallet(e)})}createWallet(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){return yield this.walletFactory.createWallet(e)})}createDeviceSigner(e,t){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){return yield _chunkYHV3672Rcjs.a.call(void 0, e,t)})}createPasskeySigner(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){let t=yield _ox.WebAuthnP256.createCredential({name:e});return{type:"passkey",id:t.id,name:e,publicKey:{x:t.publicKey.x.toString(),y:t.publicKey.y.toString()}}})}};exports.a = _commonsdkbase.createCrossmint; exports.b = o;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var _chunkJCNK347Wcjs = require('./chunk-JCNK347W.cjs');var _chunkYHV3672Rcjs = require('./chunk-YHV3672R.cjs');var _chunk6O4RMHUQcjs = require('./chunk-6O4RMHUQ.cjs');var _chunkJLTD3KKUcjs = require('./chunk-JLTD3KKU.cjs');var _chunk2GKPWQBQcjs = require('./chunk-2GKPWQBQ.cjs');var _commonsdkbase = require('@crossmint/common-sdk-base');var _ox = require('ox');var o=class c{constructor(e){_chunkJLTD3KKUcjs.b.call(void 0, e.apiKey);let t=new (0, _chunk6O4RMHUQcjs.a)(e);this.walletFactory=new (0, _chunkJCNK347Wcjs.a)(t),_chunkJLTD3KKUcjs.a.info("wallets.sdk.initialized")}static from(e){return new c(e)}getWallet(e,t){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){if(typeof e=="string"){if(t==null)throw new Error("Args parameter is required when walletLocator is provided");return yield this.walletFactory.getWallet(e,t)}return yield this.walletFactory.getWallet(e)})}createWallet(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){return yield this.walletFactory.createWallet(e)})}createDeviceSigner(e,t){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){return yield _chunkYHV3672Rcjs.a.call(void 0, e,t)})}createPasskeySigner(e){return _chunk2GKPWQBQcjs.g.call(void 0, this,null,function*(){let t=yield _ox.WebAuthnP256.createCredential({name:e});return{type:"passkey",id:t.id,name:e,publicKey:{x:t.publicKey.x.toString(),y:t.publicKey.y.toString()}}})}};exports.a = _commonsdkbase.createCrossmint; exports.b = o;
@@ -1 +1 @@
1
- import{a as r}from"./chunk-QTCM42EB.js";import{a as h}from"./chunk-2O6HQK34.js";import{v as S}from"./chunk-5OYPWGMX.js";import{a as t}from"./chunk-VOVJ4RNT.js";import{c as u,g as c}from"./chunk-J3R36SGJ.js";import T from"bs58";import{isValidSolanaAddress as y,WithLoggerContext as m}from"@crossmint/common-sdk-base";var o=class o extends r{constructor(e){super({chain:e.chain,address:e.address,owner:e.owner,options:r.getOptions(e),alias:e.alias,recovery:r.getRecovery(e),apiRecoveryServerSignerAddress:r.getApiRecoveryServerSignerAddress(e),apiDelegatedServerSignerAddresses:r.getApiDelegatedServerSignerAddresses(e),signer:e.signer,signers:r.getInitialSigners(e)},r.getApiClient(e))}static from(e){if(!y(e.address))throw new Error("Wallet is not a Solana wallet");return new o(e)}sendTransaction(e){return c(this,null,function*(){var l,p;t.info("solanaWallet.sendTransaction.start"),yield this.preAuthIfNeeded();let n=yield this.createTransaction(e);if((l=e.options)!=null&&l.prepareOnly)return t.info("solanaWallet.sendTransaction.prepared",{transactionId:n.id}),{hash:void 0,explorerLink:void 0,transactionId:n.id};let i={additionalSigners:(p=e.additionalSigners)==null?void 0:p.map(d=>new h({type:"external-wallet",address:d.publicKey.toString(),locator:`external-wallet:${d.publicKey.toString()}`,onSign:g=>(g.sign([d]),Promise.resolve(g))}))},a=yield this.approveTransactionAndWait(n.id,i);return t.info("solanaWallet.sendTransaction.success",{transactionId:n.id,hash:a.hash}),a})}createTransaction(e){return c(this,null,function*(){var a;let n;((a=e.options)==null?void 0:a.signer)==null?n=this.requireSigner().locator():typeof e.options.signer=="string"?n=e.options.signer:n=this.resolveServerSignerApiLocator(e.options.signer);let s;"serializedTransaction"in e?s=e.serializedTransaction:s=T.encode(e.transaction.serialize());let i=yield this.apiClient.createTransaction(this.walletLocator,{params:{transaction:s,signer:n}});if("error"in i)throw new S(JSON.stringify(i));return i})}};u([m({logger:t,methodName:"solanaWallet.sendTransaction",buildContext(e){return{chain:e.chain,address:e.address}}})],o.prototype,"sendTransaction",1);var f=o;export{f as a};
1
+ import{a as r}from"./chunk-ACI6AVBC.js";import{a as h}from"./chunk-2O6HQK34.js";import{v as S}from"./chunk-5OYPWGMX.js";import{a as t}from"./chunk-RFWG2QIH.js";import{c as u,g as c}from"./chunk-J3R36SGJ.js";import T from"bs58";import{isValidSolanaAddress as y,WithLoggerContext as m}from"@crossmint/common-sdk-base";var o=class o extends r{constructor(e){super({chain:e.chain,address:e.address,owner:e.owner,options:r.getOptions(e),alias:e.alias,recovery:r.getRecovery(e),apiRecoveryServerSignerAddress:r.getApiRecoveryServerSignerAddress(e),apiDelegatedServerSignerAddresses:r.getApiDelegatedServerSignerAddresses(e),signer:e.signer,signers:r.getInitialSigners(e)},r.getApiClient(e))}static from(e){if(!y(e.address))throw new Error("Wallet is not a Solana wallet");return new o(e)}sendTransaction(e){return c(this,null,function*(){var l,p;t.info("solanaWallet.sendTransaction.start"),yield this.preAuthIfNeeded();let n=yield this.createTransaction(e);if((l=e.options)!=null&&l.prepareOnly)return t.info("solanaWallet.sendTransaction.prepared",{transactionId:n.id}),{hash:void 0,explorerLink:void 0,transactionId:n.id};let i={additionalSigners:(p=e.additionalSigners)==null?void 0:p.map(d=>new h({type:"external-wallet",address:d.publicKey.toString(),locator:`external-wallet:${d.publicKey.toString()}`,onSign:g=>(g.sign([d]),Promise.resolve(g))}))},a=yield this.approveTransactionAndWait(n.id,i);return t.info("solanaWallet.sendTransaction.success",{transactionId:n.id,hash:a.hash}),a})}createTransaction(e){return c(this,null,function*(){var a;let n;((a=e.options)==null?void 0:a.signer)==null?n=this.requireSigner().locator():typeof e.options.signer=="string"?n=e.options.signer:n=this.resolveServerSignerApiLocator(e.options.signer);let s;"serializedTransaction"in e?s=e.serializedTransaction:s=T.encode(e.transaction.serialize());let i=yield this.apiClient.createTransaction(this.walletLocator,{params:{transaction:s,signer:n}});if("error"in i)throw new S(JSON.stringify(i));return i})}};u([m({logger:t,methodName:"solanaWallet.sendTransaction",buildContext(e){return{chain:e.chain,address:e.address}}})],o.prototype,"sendTransaction",1);var f=o;export{f as a};