@crossmint/wallets-sdk 0.18.2 → 0.18.4

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 (191) hide show
  1. package/dist/api/client.cjs +9 -1
  2. package/dist/api/client.d.cts +4 -4
  3. package/dist/api/client.d.ts +4 -4
  4. package/dist/api/client.js +9 -1
  5. package/dist/api/gen/client.gen.cjs +7 -1
  6. package/dist/api/gen/client.gen.js +7 -1
  7. package/dist/api/gen/index.cjs +179 -1
  8. package/dist/api/gen/index.js +179 -1
  9. package/dist/api/gen/sdk.gen.cjs +178 -1
  10. package/dist/api/gen/sdk.gen.js +178 -1
  11. package/dist/api/gen/types.gen.js +1 -1
  12. package/dist/api/index.cjs +11 -1
  13. package/dist/api/index.d.cts +1 -1
  14. package/dist/api/index.d.ts +1 -1
  15. package/dist/api/index.js +11 -1
  16. package/dist/api/types.d.cts +4 -2
  17. package/dist/api/types.d.ts +4 -2
  18. package/dist/api/types.js +1 -1
  19. package/dist/chains/chains.cjs +9 -1
  20. package/dist/chains/chains.js +9 -1
  21. package/dist/chains/definitions/story.cjs +7 -1
  22. package/dist/chains/definitions/story.js +7 -1
  23. package/dist/chains/definitions/storyTestnet.cjs +7 -1
  24. package/dist/chains/definitions/storyTestnet.js +7 -1
  25. package/dist/chunk-2DHIAP2S.js +58 -0
  26. package/dist/chunk-2T5HHKUI.js +19 -0
  27. package/dist/chunk-2VOEAAFA.cjs +200 -0
  28. package/dist/chunk-3U6UAYOV.js +25 -0
  29. package/dist/chunk-4BMNDPJ4.cjs +92 -0
  30. package/dist/chunk-4QGBVHV3.js +629 -0
  31. package/dist/chunk-55V4VMTX.cjs +25 -0
  32. package/dist/chunk-5H5YHSCK.js +200 -0
  33. package/dist/chunk-7ECQJFYM.cjs +63 -0
  34. package/dist/chunk-7GHQBCRV.cjs +57 -0
  35. package/dist/chunk-7JFVG4IY.js +59 -0
  36. package/dist/chunk-7QL5JVK4.js +262 -0
  37. package/dist/chunk-AJCWEEWH.js +73 -0
  38. package/dist/chunk-AL77JANE.js +36 -0
  39. package/dist/chunk-BAHU3KZE.cjs +75 -0
  40. package/dist/chunk-BAULM7A2.js +289 -0
  41. package/dist/chunk-BFAU2NL6.js +175 -0
  42. package/dist/chunk-BSC55MYK.cjs +43 -0
  43. package/dist/chunk-CHGPNMRL.cjs +36 -0
  44. package/dist/chunk-CN2GVFBU.cjs +138 -0
  45. package/dist/chunk-COVOGZ4S.js +80 -0
  46. package/dist/chunk-DPERJZBG.js +63 -0
  47. package/dist/chunk-DQCXGBZM.js +59 -0
  48. package/dist/chunk-E4LJ7252.cjs +289 -0
  49. package/dist/chunk-EM6H7EUU.cjs +80 -0
  50. package/dist/chunk-EYJQSDDI.js +43 -0
  51. package/dist/chunk-FAGFW4AR.js +16 -0
  52. package/dist/chunk-FK23BDCU.js +87 -0
  53. package/dist/chunk-FPMW7Q5O.js +55 -0
  54. package/dist/chunk-G5NYLGM5.cjs +55 -0
  55. package/dist/chunk-HHDDI3CS.js +75 -0
  56. package/dist/chunk-HNRM45KF.cjs +87 -0
  57. package/dist/chunk-JICSSJOK.js +57 -0
  58. package/dist/chunk-KS63YEQ4.js +138 -0
  59. package/dist/chunk-KT3CVXFG.js +9 -0
  60. package/dist/chunk-LLFD22UQ.cjs +36 -0
  61. package/dist/chunk-MPGPBFUZ.cjs +16 -0
  62. package/dist/chunk-MYKPHXUR.cjs +629 -0
  63. package/dist/chunk-MZBFXUHT.js +63 -0
  64. package/dist/chunk-NIBKCMQ2.cjs +19 -0
  65. package/dist/chunk-OD5RGQ4Z.js +92 -0
  66. package/dist/chunk-PSPNZEG4.cjs +175 -0
  67. package/dist/chunk-R2OY54EJ.cjs +59 -0
  68. package/dist/chunk-RHR6P2KP.cjs +15 -0
  69. package/dist/chunk-RSPJPRQW.cjs +262 -0
  70. package/dist/chunk-RTRDZB52.js +778 -0
  71. package/dist/chunk-SG7WIZLK.cjs +63 -0
  72. package/dist/chunk-SGINWAB6.js +155 -0
  73. package/dist/chunk-TK3EUCQ4.cjs +59 -0
  74. package/dist/chunk-V3QJQUT7.cjs +778 -0
  75. package/dist/chunk-WC7T2CR4.js +44 -0
  76. package/dist/chunk-WJUPOCKJ.js +15 -0
  77. package/dist/chunk-XC2V34TS.cjs +155 -0
  78. package/dist/chunk-XH3ARVJG.cjs +58 -0
  79. package/dist/chunk-YBA7WO32.cjs +44 -0
  80. package/dist/chunk-YOJETSLN.cjs +73 -0
  81. package/dist/chunk-ZT7EGOCI.cjs +9 -0
  82. package/dist/chunk-ZTGRDOOH.js +36 -0
  83. package/dist/index.cjs +55 -1
  84. package/dist/index.js +55 -1
  85. package/dist/sdk.cjs +31 -1
  86. package/dist/sdk.js +31 -1
  87. package/dist/signers/evm-api-key.cjs +7 -1
  88. package/dist/signers/evm-api-key.js +7 -1
  89. package/dist/signers/evm-external-wallet.cjs +7 -1
  90. package/dist/signers/evm-external-wallet.js +7 -1
  91. package/dist/signers/index.cjs +21 -1
  92. package/dist/signers/index.js +21 -1
  93. package/dist/signers/non-custodial/index.cjs +24 -1
  94. package/dist/signers/non-custodial/index.js +24 -1
  95. package/dist/signers/non-custodial/ncs-evm-signer.cjs +10 -1
  96. package/dist/signers/non-custodial/ncs-evm-signer.js +10 -1
  97. package/dist/signers/non-custodial/ncs-iframe-manager.cjs +7 -1
  98. package/dist/signers/non-custodial/ncs-iframe-manager.js +7 -1
  99. package/dist/signers/non-custodial/ncs-signer.cjs +11 -1
  100. package/dist/signers/non-custodial/ncs-signer.js +11 -1
  101. package/dist/signers/non-custodial/ncs-solana-signer.cjs +10 -1
  102. package/dist/signers/non-custodial/ncs-solana-signer.js +10 -1
  103. package/dist/signers/non-custodial/ncs-stellar-signer.cjs +10 -1
  104. package/dist/signers/non-custodial/ncs-stellar-signer.js +10 -1
  105. package/dist/signers/passkey.cjs +7 -1
  106. package/dist/signers/passkey.js +7 -1
  107. package/dist/signers/solana-api-key.cjs +7 -1
  108. package/dist/signers/solana-api-key.js +7 -1
  109. package/dist/signers/solana-external-wallet.cjs +8 -1
  110. package/dist/signers/solana-external-wallet.js +8 -1
  111. package/dist/signers/stellar-external-wallet.cjs +7 -1
  112. package/dist/signers/stellar-external-wallet.js +7 -1
  113. package/dist/signers/types.cjs +9 -1
  114. package/dist/signers/types.js +9 -1
  115. package/dist/utils/constants.cjs +13 -1
  116. package/dist/utils/constants.js +13 -1
  117. package/dist/utils/errors.cjs +55 -1
  118. package/dist/utils/errors.js +55 -1
  119. package/dist/utils/signer-validation.cjs +8 -1
  120. package/dist/utils/signer-validation.js +8 -1
  121. package/dist/wallets/evm.cjs +20 -1
  122. package/dist/wallets/evm.js +20 -1
  123. package/dist/wallets/solana.cjs +18 -1
  124. package/dist/wallets/solana.js +18 -1
  125. package/dist/wallets/stellar.cjs +17 -1
  126. package/dist/wallets/stellar.js +17 -1
  127. package/dist/wallets/wallet-factory.cjs +25 -1
  128. package/dist/wallets/wallet-factory.js +25 -1
  129. package/dist/wallets/wallet.cjs +16 -1
  130. package/dist/wallets/wallet.d.cts +12 -1
  131. package/dist/wallets/wallet.d.ts +12 -1
  132. package/dist/wallets/wallet.js +16 -1
  133. package/package.json +4 -4
  134. package/dist/chunk-23ZHV3VD.js +0 -1
  135. package/dist/chunk-2SHDBC47.js +0 -1
  136. package/dist/chunk-2XVV7Z43.cjs +0 -1
  137. package/dist/chunk-2YH3NVVK.cjs +0 -1
  138. package/dist/chunk-3APSOOE3.js +0 -1
  139. package/dist/chunk-3IZNWAZE.cjs +0 -1
  140. package/dist/chunk-4AJT6I6Q.js +0 -1
  141. package/dist/chunk-4KXOWU5E.cjs +0 -1
  142. package/dist/chunk-5M7IRODB.js +0 -1
  143. package/dist/chunk-5QIW67NU.cjs +0 -1
  144. package/dist/chunk-6PVKL5RC.js +0 -1
  145. package/dist/chunk-73RCBQG5.js +0 -1
  146. package/dist/chunk-7JIPYRKX.js +0 -1
  147. package/dist/chunk-7WKKOG6H.cjs +0 -3
  148. package/dist/chunk-BQZES4ST.js +0 -1
  149. package/dist/chunk-BW7YYVZE.js +0 -1
  150. package/dist/chunk-C3T63EC7.cjs +0 -1
  151. package/dist/chunk-CVZ3RNWV.cjs +0 -1
  152. package/dist/chunk-GEY574TH.cjs +0 -1
  153. package/dist/chunk-H4T4IXCF.js +0 -1
  154. package/dist/chunk-HJ5EDMTA.js +0 -1
  155. package/dist/chunk-HMPMFEPS.cjs +0 -1
  156. package/dist/chunk-HPHVJ6BA.cjs +0 -1
  157. package/dist/chunk-HRSVFJND.cjs +0 -1
  158. package/dist/chunk-IGBQEAD5.js +0 -1
  159. package/dist/chunk-IR5WN6FQ.cjs +0 -1
  160. package/dist/chunk-JUSY5XEE.js +0 -1
  161. package/dist/chunk-KHSWQE6W.js +0 -1
  162. package/dist/chunk-KKQBZXFE.js +0 -1
  163. package/dist/chunk-KO6QYKDX.cjs +0 -1
  164. package/dist/chunk-KRV3IXJU.cjs +0 -1
  165. package/dist/chunk-L5L64FWM.js +0 -1
  166. package/dist/chunk-LW6JSI4J.js +0 -1
  167. package/dist/chunk-M4TOGGLV.cjs +0 -1
  168. package/dist/chunk-MQP5VZCA.cjs +0 -1
  169. package/dist/chunk-NEJPPLYW.cjs +0 -1
  170. package/dist/chunk-NIKULSJK.cjs +0 -1
  171. package/dist/chunk-NT4EICOB.cjs +0 -1
  172. package/dist/chunk-O4FVTK7X.cjs +0 -1
  173. package/dist/chunk-P6JJHAAV.js +0 -1
  174. package/dist/chunk-PONCGT2H.cjs +0 -1
  175. package/dist/chunk-PSXRNSOE.js +0 -1
  176. package/dist/chunk-R6VFNNAA.js +0 -3
  177. package/dist/chunk-RJZV72YF.js +0 -1
  178. package/dist/chunk-S3DYQVRD.js +0 -1
  179. package/dist/chunk-SHVVA55W.js +0 -1
  180. package/dist/chunk-STYSP6KL.cjs +0 -1
  181. package/dist/chunk-UBOWSXW3.js +0 -1
  182. package/dist/chunk-UNBXKCNN.js +0 -1
  183. package/dist/chunk-VXFSSEA4.js +0 -1
  184. package/dist/chunk-VY634F3J.js +0 -1
  185. package/dist/chunk-WQP2FSVI.js +0 -1
  186. package/dist/chunk-WYYAPI4G.cjs +0 -1
  187. package/dist/chunk-WZFHEUWT.cjs +0 -1
  188. package/dist/chunk-XALFCQKD.cjs +0 -1
  189. package/dist/chunk-XIRT2EZN.cjs +0 -1
  190. package/dist/chunk-YWPTI2QO.cjs +0 -1
  191. package/dist/chunk-YZ4HRYSL.cjs +0 -1
@@ -0,0 +1,200 @@
1
+ import {
2
+ SDK_NAME,
3
+ SDK_VERSION
4
+ } from "./chunk-FAGFW4AR.js";
5
+ import {
6
+ InvalidApiKeyError
7
+ } from "./chunk-SGINWAB6.js";
8
+ import {
9
+ __async
10
+ } from "./chunk-FPMW7Q5O.js";
11
+
12
+ // src/api/client.ts
13
+ import {
14
+ APIKeyEnvironmentPrefix,
15
+ APIKeyUsageOrigin,
16
+ CrossmintApiClient
17
+ } from "@crossmint/common-sdk-base";
18
+ var ApiClient = class extends CrossmintApiClient {
19
+ constructor(crossmint) {
20
+ super(crossmint, {
21
+ internalConfig: {
22
+ sdkMetadata: { name: SDK_NAME, version: SDK_VERSION }
23
+ }
24
+ });
25
+ this.apiPrefix = "api/2025-06-09/wallets";
26
+ this.legacyApiPrefix = "api/2022-06-09/wallets";
27
+ }
28
+ createWallet(params) {
29
+ return __async(this, null, function* () {
30
+ const path = this.isServerSide ? `${this.apiPrefix}` : `${this.apiPrefix}/me`;
31
+ const response = yield this.post(path, {
32
+ body: JSON.stringify(params),
33
+ headers: this.headers
34
+ });
35
+ return response.json();
36
+ });
37
+ }
38
+ getWallet(locator) {
39
+ return __async(this, null, function* () {
40
+ const response = yield this.get(`${this.apiPrefix}/${locator}`, {
41
+ headers: this.headers
42
+ });
43
+ return response.json();
44
+ });
45
+ }
46
+ createTransaction(walletLocator, params) {
47
+ return __async(this, null, function* () {
48
+ const response = yield this.post(`${this.apiPrefix}/${walletLocator}/transactions`, {
49
+ body: JSON.stringify(params),
50
+ headers: this.headers
51
+ });
52
+ return response.json();
53
+ });
54
+ }
55
+ approveTransaction(walletLocator, transactionId, params) {
56
+ return __async(this, null, function* () {
57
+ const response = yield this.post(`${this.apiPrefix}/${walletLocator}/transactions/${transactionId}/approvals`, {
58
+ body: JSON.stringify(params),
59
+ headers: this.headers
60
+ });
61
+ return response.json();
62
+ });
63
+ }
64
+ getTransaction(walletLocator, transactionId) {
65
+ return __async(this, null, function* () {
66
+ const response = yield this.get(`${this.apiPrefix}/${walletLocator}/transactions/${transactionId}`, {
67
+ headers: this.headers
68
+ });
69
+ return response.json();
70
+ });
71
+ }
72
+ createSignature(walletLocator, params) {
73
+ return __async(this, null, function* () {
74
+ const response = yield this.post(`${this.apiPrefix}/${walletLocator}/signatures`, {
75
+ body: JSON.stringify(params),
76
+ headers: this.headers
77
+ });
78
+ return response.json();
79
+ });
80
+ }
81
+ approveSignature(walletLocator, signatureId, params) {
82
+ return __async(this, null, function* () {
83
+ const response = yield this.post(`${this.apiPrefix}/${walletLocator}/signatures/${signatureId}/approvals`, {
84
+ body: JSON.stringify(params),
85
+ headers: this.headers
86
+ });
87
+ return response.json();
88
+ });
89
+ }
90
+ getSignature(walletLocator, signatureId) {
91
+ return __async(this, null, function* () {
92
+ const response = yield this.get(`${this.apiPrefix}/${walletLocator}/signatures/${signatureId}`, {
93
+ headers: this.headers
94
+ });
95
+ return response.json();
96
+ });
97
+ }
98
+ getTransactions(walletLocator) {
99
+ return __async(this, null, function* () {
100
+ const response = yield this.get(`${this.apiPrefix}/${walletLocator}/transactions`, {
101
+ headers: this.headers
102
+ });
103
+ return response.json();
104
+ });
105
+ }
106
+ experimental_getNfts(params) {
107
+ return __async(this, null, function* () {
108
+ const queryParams = new URLSearchParams();
109
+ queryParams.append("page", params.page.toString());
110
+ queryParams.append("perPage", params.perPage.toString());
111
+ const identifier = `${params.chain}:${params.address}`;
112
+ const response = yield this.get(`${this.apiPrefix}/${identifier}/nfts?${queryParams.toString()}`, {
113
+ headers: this.headers
114
+ });
115
+ return response.json();
116
+ });
117
+ }
118
+ experimental_activity(walletLocator, params) {
119
+ return __async(this, null, function* () {
120
+ let legacyLocator = walletLocator;
121
+ if (!this.isServerSide) {
122
+ legacyLocator = `me:${params.chain === "solana" ? "solana-smart-wallet" : "evm-smart-wallet"}`;
123
+ }
124
+ const queryParams = new URLSearchParams();
125
+ queryParams.append("chain", params.chain.toString());
126
+ const response = yield this.get(`${this.legacyApiPrefix}/${legacyLocator}/activity?${queryParams.toString()}`, {
127
+ headers: this.headers
128
+ });
129
+ return response.json();
130
+ });
131
+ }
132
+ getBalance(walletLocator, params) {
133
+ return __async(this, null, function* () {
134
+ const queryParams = new URLSearchParams();
135
+ queryParams.append("tokens", params.tokens.join(","));
136
+ queryParams.append("chains", params.chains.join(","));
137
+ const response = yield this.get(`${this.apiPrefix}/${walletLocator}/balances?${queryParams.toString()}`, {
138
+ headers: this.headers
139
+ });
140
+ return response.json();
141
+ });
142
+ }
143
+ fundWallet(walletLocator, params) {
144
+ return __async(this, null, function* () {
145
+ if (this.environment === APIKeyEnvironmentPrefix.PRODUCTION) {
146
+ throw new Error("Funding wallets is only supported in staging environment");
147
+ }
148
+ const response = yield this.post(`api/v1-alpha2/wallets/${walletLocator}/balances`, {
149
+ body: JSON.stringify(params),
150
+ headers: this.headers
151
+ });
152
+ return response.json();
153
+ });
154
+ }
155
+ registerSigner(walletLocator, params) {
156
+ return __async(this, null, function* () {
157
+ const response = yield this.post(`${this.apiPrefix}/${walletLocator}/signers`, {
158
+ body: JSON.stringify(params),
159
+ headers: this.headers
160
+ });
161
+ return response.json();
162
+ });
163
+ }
164
+ getSigner(walletLocator, signer) {
165
+ return __async(this, null, function* () {
166
+ const response = yield this.get(`${this.apiPrefix}/${walletLocator}/signers/${signer}`, {
167
+ headers: this.headers
168
+ });
169
+ return response.json();
170
+ });
171
+ }
172
+ send(walletLocator, tokenLocator, params) {
173
+ return __async(this, null, function* () {
174
+ const response = yield this.post(`${this.apiPrefix}/${walletLocator}/tokens/${tokenLocator}/transfers`, {
175
+ body: JSON.stringify(params),
176
+ headers: this.headers
177
+ });
178
+ return response.json();
179
+ });
180
+ }
181
+ get isServerSide() {
182
+ return this.parsedAPIKey.usageOrigin === APIKeyUsageOrigin.SERVER;
183
+ }
184
+ get environment() {
185
+ if (!this.parsedAPIKey.isValid) {
186
+ throw new InvalidApiKeyError("Invalid API key");
187
+ }
188
+ return this.parsedAPIKey.environment;
189
+ }
190
+ get headers() {
191
+ const headers = {
192
+ "Content-Type": "application/json"
193
+ };
194
+ return headers;
195
+ }
196
+ };
197
+
198
+ export {
199
+ ApiClient
200
+ };
@@ -0,0 +1,63 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkG5NYLGM5cjs = require('./chunk-G5NYLGM5.cjs');
4
+
5
+ // src/signers/evm-external-wallet.ts
6
+ var EVMExternalWalletSigner = class {
7
+ constructor(config) {
8
+ this.config = config;
9
+ this.type = "external-wallet";
10
+ if (config.address == null) {
11
+ throw new Error("Please provide an address for the External Wallet Signer");
12
+ }
13
+ this._address = config.address;
14
+ this.provider = config.provider;
15
+ this.viemAccount = config.viemAccount;
16
+ }
17
+ address() {
18
+ return this._address;
19
+ }
20
+ locator() {
21
+ return this.config.locator;
22
+ }
23
+ signMessage(message) {
24
+ return _chunkG5NYLGM5cjs.__async.call(void 0, this, null, function* () {
25
+ var _a;
26
+ if (this.provider != null) {
27
+ const signature = yield this.provider.request({
28
+ method: "personal_sign",
29
+ params: [message, this._address]
30
+ });
31
+ if (signature == null) {
32
+ throw new Error(
33
+ "[EVMExternalWalletSigner] Failed to sign message: EIP1193 provider signMessage returned null"
34
+ );
35
+ }
36
+ return { signature };
37
+ }
38
+ if (((_a = this.viemAccount) == null ? void 0 : _a.signMessage) != null) {
39
+ const signature = yield this.viemAccount.signMessage({
40
+ message: {
41
+ raw: message
42
+ }
43
+ });
44
+ if (signature == null) {
45
+ throw new Error(
46
+ "[EVMExternalWalletSigner] Failed to sign message: Viem account signMessage returned null"
47
+ );
48
+ }
49
+ return { signature };
50
+ }
51
+ throw new Error("No signer provider or viem account provided");
52
+ });
53
+ }
54
+ signTransaction(transaction) {
55
+ return _chunkG5NYLGM5cjs.__async.call(void 0, this, null, function* () {
56
+ return yield this.signMessage(transaction);
57
+ });
58
+ }
59
+ };
60
+
61
+
62
+
63
+ exports.EVMExternalWalletSigner = EVMExternalWalletSigner;
@@ -0,0 +1,57 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkXC2V34TScjs = require('./chunk-XC2V34TS.cjs');
4
+
5
+ // src/utils/signer-validation.ts
6
+ var _commonsdkauth = require('@crossmint/common-sdk-auth');
7
+ var signerConfigMismatchErrorMessage = (fieldPath, newValue, existingValue) => `Wallet signer configuration mismatch at "${fieldPath}" - expected "${existingValue}" from existing wallet but found "${newValue}"`;
8
+ function normalizeEmail(email) {
9
+ const lowerCaseEmail = email.toLowerCase();
10
+ const emailParts = lowerCaseEmail.split("@");
11
+ const domain = emailParts[1];
12
+ const isGoogleMailDomain = domain === "googlemail.com";
13
+ const isGmail = isGoogleMailDomain || domain === "gmail.com";
14
+ const isGmailAndHasDots = isGmail && emailParts[0].includes(".");
15
+ if (isGoogleMailDomain) {
16
+ emailParts[1] = "gmail.com";
17
+ }
18
+ if (isGmailAndHasDots) {
19
+ emailParts[0] = emailParts[0].replace(/\./g, "");
20
+ }
21
+ return `${emailParts[0]}@${emailParts[1]}`;
22
+ }
23
+ function normalizeValueForComparison(value) {
24
+ if (typeof value === "string" && _commonsdkauth.isEmailValid.call(void 0, value)) {
25
+ return normalizeEmail(value);
26
+ }
27
+ return value;
28
+ }
29
+ function compareSignerConfigs(newSignerConfig, existingSignerConfig, path = "") {
30
+ if (newSignerConfig === existingSignerConfig) {
31
+ return;
32
+ }
33
+ if (newSignerConfig == null || existingSignerConfig == null) {
34
+ throw new Error(`Cannot compare null or undefined signer configs at path: ${path}`);
35
+ }
36
+ for (const key of Object.keys(newSignerConfig)) {
37
+ if (!(key in existingSignerConfig)) {
38
+ continue;
39
+ }
40
+ const fieldPath = path ? `${path}.${key}` : key;
41
+ const newValue = newSignerConfig[key];
42
+ const existingValue = existingSignerConfig[key];
43
+ if (typeof newValue === "object" && newValue !== null && typeof existingValue === "object" && existingValue !== null) {
44
+ compareSignerConfigs(
45
+ newValue,
46
+ existingValue,
47
+ fieldPath
48
+ );
49
+ } else if (normalizeValueForComparison(newValue) !== normalizeValueForComparison(existingValue)) {
50
+ throw new (0, _chunkXC2V34TScjs.WalletCreationError)(signerConfigMismatchErrorMessage(fieldPath, newValue, existingValue));
51
+ }
52
+ }
53
+ }
54
+
55
+
56
+
57
+ exports.compareSignerConfigs = compareSignerConfigs;
@@ -0,0 +1,59 @@
1
+ import {
2
+ __async
3
+ } from "./chunk-FPMW7Q5O.js";
4
+
5
+ // src/signers/non-custodial/ncs-iframe-manager.ts
6
+ import { IFrameWindow, SignersWindowTransport } from "@crossmint/client-sdk-window";
7
+ import { environmentUrlConfig, signerInboundEvents, signerOutboundEvents } from "@crossmint/client-signers";
8
+ var NcsIframeManager = class {
9
+ constructor(config) {
10
+ this.config = config;
11
+ this.handshakeParent = null;
12
+ }
13
+ initialize() {
14
+ return __async(this, null, function* () {
15
+ if (this.handshakeParent) {
16
+ return this.handshakeParent;
17
+ }
18
+ const iframeUrl = new URL(environmentUrlConfig[this.config.environment]);
19
+ iframeUrl.searchParams.set("targetOrigin", window.location.origin);
20
+ const iframeElement = yield this.createInvisibleIFrame(iframeUrl.toString());
21
+ this.handshakeParent = yield IFrameWindow.init(
22
+ iframeElement,
23
+ {
24
+ targetOrigin: iframeUrl.origin,
25
+ incomingEvents: signerOutboundEvents,
26
+ outgoingEvents: signerInboundEvents
27
+ },
28
+ SignersWindowTransport
29
+ );
30
+ yield this.handshakeParent.handshakeWithChild();
31
+ return this.handshakeParent;
32
+ });
33
+ }
34
+ createInvisibleIFrame(url) {
35
+ return __async(this, null, function* () {
36
+ const iframe = document.createElement("iframe");
37
+ iframe.src = url;
38
+ Object.assign(iframe.style, {
39
+ position: "absolute",
40
+ opacity: "0",
41
+ pointerEvents: "none",
42
+ width: "0",
43
+ height: "0",
44
+ border: "none",
45
+ top: "-9999px",
46
+ left: "-9999px"
47
+ });
48
+ return new Promise((resolve, reject) => {
49
+ iframe.onload = () => resolve(iframe);
50
+ iframe.onerror = () => reject(new Error("Failed to load iframe content"));
51
+ document.body.appendChild(iframe);
52
+ });
53
+ });
54
+ }
55
+ };
56
+
57
+ export {
58
+ NcsIframeManager
59
+ };
@@ -0,0 +1,262 @@
1
+ import {
2
+ compareSignerConfigs
3
+ } from "./chunk-JICSSJOK.js";
4
+ import {
5
+ Wallet
6
+ } from "./chunk-4QGBVHV3.js";
7
+ import {
8
+ assembleSigner
9
+ } from "./chunk-2DHIAP2S.js";
10
+ import {
11
+ WalletCreationError,
12
+ WalletNotAvailableError
13
+ } from "./chunk-SGINWAB6.js";
14
+ import {
15
+ __async,
16
+ __spreadValues
17
+ } from "./chunk-FPMW7Q5O.js";
18
+
19
+ // src/wallets/wallet-factory.ts
20
+ import { WebAuthnP256 } from "ox";
21
+ var DELEGATED_SIGNER_MISMATCH_ERROR = "When 'delegatedSigners' is provided to a method that may fetch an existing wallet, each specified delegated signer must exist in that wallet's configuration.";
22
+ var WalletFactory = class {
23
+ constructor(apiClient) {
24
+ this.apiClient = apiClient;
25
+ }
26
+ getOrCreateWallet(args) {
27
+ return __async(this, null, function* () {
28
+ if (this.apiClient.isServerSide) {
29
+ throw new WalletCreationError(
30
+ "getOrCreateWallet can only be called from client-side code.\n- Make sure you're running this in the browser (or another client environment), not on your server.\n- Use your Crossmint Client API Key (not a server key)."
31
+ );
32
+ }
33
+ const locator = this.getWalletLocator(args);
34
+ const existingWallet = yield this.apiClient.getWallet(locator);
35
+ if (existingWallet != null && !("error" in existingWallet)) {
36
+ return this.createWalletInstance(existingWallet, args);
37
+ }
38
+ return this.createWallet(args);
39
+ });
40
+ }
41
+ getWallet(walletLocator, args) {
42
+ return __async(this, null, function* () {
43
+ if (!this.apiClient.isServerSide) {
44
+ throw new WalletCreationError("getWallet is not supported on client side, use getOrCreateWallet instead");
45
+ }
46
+ const existingWallet = yield this.apiClient.getWallet(walletLocator);
47
+ if ("error" in existingWallet) {
48
+ throw new WalletNotAvailableError(JSON.stringify(existingWallet));
49
+ }
50
+ return this.createWalletInstance(existingWallet, args);
51
+ });
52
+ }
53
+ createWallet(args) {
54
+ return __async(this, null, function* () {
55
+ var _a, _b, _c, _d, _e;
56
+ yield (_c = (_b = (_a = args.options) == null ? void 0 : _a.experimental_callbacks) == null ? void 0 : _b.onWalletCreationStart) == null ? void 0 : _c.call(_b);
57
+ this.mutateSignerFromCustomAuth(args, true);
58
+ const adminSigner = args.signer.type === "passkey" ? yield this.createPasskeyAdminSigner(args.signer) : args.signer;
59
+ const walletResponse = yield this.apiClient.createWallet({
60
+ type: "smart",
61
+ chainType: this.getChainType(args.chain),
62
+ config: __spreadValues(__spreadValues({
63
+ adminSigner
64
+ }, (args == null ? void 0 : args.plugins) ? { plugins: args.plugins } : {}), args.delegatedSigners != null ? { delegatedSigners: args.delegatedSigners } : {}),
65
+ owner: (_d = args.owner) != null ? _d : void 0,
66
+ alias: (_e = args.alias) != null ? _e : void 0
67
+ });
68
+ if ("error" in walletResponse) {
69
+ throw new WalletCreationError(JSON.stringify(walletResponse));
70
+ }
71
+ return this.createWalletInstance(walletResponse, args);
72
+ });
73
+ }
74
+ createWalletInstance(walletResponse, args) {
75
+ this.validateExistingWalletConfig(walletResponse, args);
76
+ const signerConfig = this.toInternalSignerConfig(walletResponse, args.signer, args.options);
77
+ return new Wallet(
78
+ {
79
+ chain: args.chain,
80
+ address: walletResponse.address,
81
+ owner: walletResponse.owner,
82
+ signer: assembleSigner(args.chain, signerConfig),
83
+ options: args.options,
84
+ alias: args.alias
85
+ },
86
+ this.apiClient
87
+ );
88
+ }
89
+ toInternalSignerConfig(walletResponse, signerArgs, options) {
90
+ var _a, _b, _c, _d, _e, _f;
91
+ if (!(walletResponse.chainType === "evm" || walletResponse.chainType === "solana" || walletResponse.chainType === "stellar")) {
92
+ throw new WalletCreationError(`Wallet type ${walletResponse.chainType} is not supported`);
93
+ }
94
+ if (signerArgs == null && ((_a = walletResponse.config) == null ? void 0 : _a.adminSigner) == null) {
95
+ throw new WalletCreationError("Signer is required to create a wallet");
96
+ }
97
+ switch (signerArgs.type) {
98
+ case "api-key": {
99
+ if (((_b = walletResponse.config) == null ? void 0 : _b.adminSigner.type) !== "api-key") {
100
+ throw new WalletCreationError("API key signer does not match the wallet's signer type");
101
+ }
102
+ return {
103
+ type: "api-key",
104
+ address: walletResponse.config.adminSigner.address,
105
+ locator: walletResponse.config.adminSigner.locator
106
+ };
107
+ }
108
+ case "external-wallet":
109
+ if (((_c = walletResponse.config) == null ? void 0 : _c.adminSigner.type) !== "external-wallet") {
110
+ throw new WalletCreationError("External wallet signer does not match the wallet's signer type");
111
+ }
112
+ return __spreadValues(__spreadValues({}, walletResponse.config.adminSigner), signerArgs);
113
+ case "passkey":
114
+ if (((_d = walletResponse.config) == null ? void 0 : _d.adminSigner.type) !== "passkey") {
115
+ throw new WalletCreationError("Passkey signer does not match the wallet's signer type");
116
+ }
117
+ return {
118
+ type: "passkey",
119
+ id: walletResponse.config.adminSigner.id,
120
+ name: walletResponse.config.adminSigner.name,
121
+ locator: walletResponse.config.adminSigner.locator,
122
+ onCreatePasskey: signerArgs.onCreatePasskey,
123
+ onSignWithPasskey: signerArgs.onSignWithPasskey
124
+ };
125
+ case "email": {
126
+ if (((_e = walletResponse.config) == null ? void 0 : _e.adminSigner.type) !== "email") {
127
+ throw new WalletCreationError("Email signer does not match the wallet's signer type");
128
+ }
129
+ const { locator, email, address } = walletResponse.config.adminSigner;
130
+ return {
131
+ type: "email",
132
+ email,
133
+ locator,
134
+ address,
135
+ crossmint: this.apiClient.crossmint,
136
+ onAuthRequired: signerArgs.onAuthRequired,
137
+ clientTEEConnection: options == null ? void 0 : options.clientTEEConnection
138
+ };
139
+ }
140
+ case "phone": {
141
+ if (((_f = walletResponse.config) == null ? void 0 : _f.adminSigner.type) !== "phone") {
142
+ throw new WalletCreationError("Phone signer does not match the wallet's signer type");
143
+ }
144
+ const { locator, phone, address } = walletResponse.config.adminSigner;
145
+ return {
146
+ type: "phone",
147
+ phone,
148
+ locator,
149
+ address,
150
+ crossmint: this.apiClient.crossmint,
151
+ onAuthRequired: signerArgs.onAuthRequired,
152
+ clientTEEConnection: options == null ? void 0 : options.clientTEEConnection
153
+ };
154
+ }
155
+ default:
156
+ throw new Error("Invalid signer type");
157
+ }
158
+ }
159
+ getWalletLocator(args) {
160
+ return `me:${this.getChainType(args.chain)}:smart` + (args.alias != null ? `:alias:${args.alias}` : "");
161
+ }
162
+ createPasskeyAdminSigner(signer) {
163
+ return __async(this, null, function* () {
164
+ var _a;
165
+ if (signer.type !== "passkey") {
166
+ throw new Error("Signer is not a passkey");
167
+ }
168
+ const passkeyName = (_a = signer.name) != null ? _a : `Crossmint Wallet ${Date.now()}`;
169
+ const passkeyCredential = signer.onCreatePasskey ? yield signer.onCreatePasskey(passkeyName) : yield WebAuthnP256.createCredential({ name: passkeyName });
170
+ return {
171
+ type: "passkey",
172
+ id: passkeyCredential.id,
173
+ name: passkeyName,
174
+ publicKey: {
175
+ x: passkeyCredential.publicKey.x.toString(),
176
+ y: passkeyCredential.publicKey.y.toString()
177
+ }
178
+ };
179
+ });
180
+ }
181
+ mutateSignerFromCustomAuth(args, isNewWalletSigner = false) {
182
+ var _a, _b;
183
+ const { experimental_customAuth } = this.apiClient.crossmint;
184
+ if (args.signer.type === "email" && (experimental_customAuth == null ? void 0 : experimental_customAuth.email) != null) {
185
+ args.signer.email = (_a = args.signer.email) != null ? _a : experimental_customAuth.email;
186
+ }
187
+ if (args.signer.type === "phone" && (experimental_customAuth == null ? void 0 : experimental_customAuth.phone) != null) {
188
+ args.signer.phone = (_b = args.signer.phone) != null ? _b : experimental_customAuth.phone;
189
+ }
190
+ if (args.signer.type === "external-wallet" && (experimental_customAuth == null ? void 0 : experimental_customAuth.externalWalletSigner) != null) {
191
+ args.signer = isNewWalletSigner ? {
192
+ type: "external-wallet",
193
+ address: experimental_customAuth.externalWalletSigner.address
194
+ } : experimental_customAuth.externalWalletSigner;
195
+ }
196
+ return;
197
+ }
198
+ validateExistingWalletConfig(existingWallet, args) {
199
+ var _a;
200
+ this.mutateSignerFromCustomAuth(args);
201
+ if (args.owner != null && existingWallet.owner != null && args.owner !== existingWallet.owner) {
202
+ throw new WalletCreationError("Wallet owner does not match existing wallet's linked user");
203
+ }
204
+ if (args.chain === "solana" && existingWallet.chainType !== "solana" || args.chain !== "solana" && existingWallet.chainType === "solana" || args.chain === "stellar" && existingWallet.chainType !== "stellar" || args.chain !== "stellar" && existingWallet.chainType === "stellar") {
205
+ throw new WalletCreationError(
206
+ `Wallet chain does not match existing wallet's chain. You must use chain: ${existingWallet.chainType}.`
207
+ );
208
+ }
209
+ if (existingWallet.type !== "smart") {
210
+ return;
211
+ }
212
+ const adminSignerArgs = args.signer;
213
+ const existingWalletSigner = (_a = existingWallet == null ? void 0 : existingWallet.config) == null ? void 0 : _a.adminSigner;
214
+ if (adminSignerArgs != null && existingWalletSigner != null) {
215
+ if (adminSignerArgs.type !== existingWalletSigner.type) {
216
+ throw new WalletCreationError(
217
+ "The wallet signer type provided in the wallet config does not match the existing wallet's adminSigner type"
218
+ );
219
+ }
220
+ compareSignerConfigs(adminSignerArgs, existingWalletSigner);
221
+ }
222
+ if (args.delegatedSigners != null) {
223
+ this.validateDelegatedSigners(existingWallet, args.delegatedSigners);
224
+ }
225
+ }
226
+ validateDelegatedSigners(existingWallet, inputDelegatedSigners) {
227
+ var _a;
228
+ const existingDelegatedSigners = (_a = existingWallet == null ? void 0 : existingWallet.config) == null ? void 0 : _a.delegatedSigners;
229
+ if (inputDelegatedSigners.length === 0) {
230
+ return;
231
+ }
232
+ if (existingDelegatedSigners == null || existingDelegatedSigners.length === 0) {
233
+ throw new WalletCreationError(
234
+ `${inputDelegatedSigners.length} delegated signer(s) specified, but wallet "${existingWallet.address}" has no delegated signers. ${DELEGATED_SIGNER_MISMATCH_ERROR}`
235
+ );
236
+ }
237
+ for (const argSigner of inputDelegatedSigners) {
238
+ const matchingExistingSigner = existingDelegatedSigners.find(
239
+ (existingSigner) => existingSigner.locator === argSigner.signer
240
+ );
241
+ if (matchingExistingSigner == null) {
242
+ const walletSigners = existingDelegatedSigners.map((s) => s.locator).join(", ");
243
+ throw new WalletCreationError(
244
+ `Delegated signer '${argSigner.signer}' does not exist in wallet "${existingWallet.address}". Available delegated signers: ${walletSigners}. ${DELEGATED_SIGNER_MISMATCH_ERROR}`
245
+ );
246
+ }
247
+ }
248
+ }
249
+ getChainType(chain) {
250
+ if (chain === "solana") {
251
+ return "solana";
252
+ }
253
+ if (chain === "stellar") {
254
+ return "stellar";
255
+ }
256
+ return "evm";
257
+ }
258
+ };
259
+
260
+ export {
261
+ WalletFactory
262
+ };