@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,9 @@
1
+ // src/api/gen/client.gen.ts
2
+ import { createClient, createConfig } from "@hey-api/client-fetch";
3
+ var client = createClient(createConfig({
4
+ baseUrl: "https://staging.crossmint.com/api"
5
+ }));
6
+
7
+ export {
8
+ client
9
+ };
@@ -0,0 +1,36 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkG5NYLGM5cjs = require('./chunk-G5NYLGM5.cjs');
4
+
5
+ // src/signers/solana-api-key.ts
6
+ var SolanaApiKeySigner = class {
7
+ constructor(config) {
8
+ this.config = config;
9
+ this.type = "api-key";
10
+ }
11
+ locator() {
12
+ return this.config.locator;
13
+ }
14
+ signMessage() {
15
+ return _chunkG5NYLGM5cjs.__async.call(void 0, this, null, function* () {
16
+ return yield Promise.reject(
17
+ new Error(
18
+ "API key signers do not support direct message signing - signatures are handled automatically by the backend"
19
+ )
20
+ );
21
+ });
22
+ }
23
+ signTransaction() {
24
+ return _chunkG5NYLGM5cjs.__async.call(void 0, this, null, function* () {
25
+ return yield Promise.reject(
26
+ new Error(
27
+ "API key signers do not support direct transaction signing - transaction are handled automatically by the backend"
28
+ )
29
+ );
30
+ });
31
+ }
32
+ };
33
+
34
+
35
+
36
+ exports.SolanaApiKeySigner = SolanaApiKeySigner;
@@ -0,0 +1,16 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// package.json
2
+ var name = "@crossmint/wallets-sdk";
3
+ var version = "0.18.4";
4
+
5
+ // src/utils/constants.ts
6
+ var WALLETS_SERVICE = "WALLETS_SDK";
7
+ var SDK_VERSION = version;
8
+ var SDK_NAME = name;
9
+ var STATUS_POLLING_INTERVAL_MS = 500;
10
+
11
+
12
+
13
+
14
+
15
+
16
+ exports.WALLETS_SERVICE = WALLETS_SERVICE; exports.SDK_VERSION = SDK_VERSION; exports.SDK_NAME = SDK_NAME; exports.STATUS_POLLING_INTERVAL_MS = STATUS_POLLING_INTERVAL_MS;
@@ -0,0 +1,629 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunkE4LJ7252cjs = require('./chunk-E4LJ7252.cjs');
4
+
5
+
6
+ var _chunkMPGPBFUZcjs = require('./chunk-MPGPBFUZ.cjs');
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+ var _chunkXC2V34TScjs = require('./chunk-XC2V34TS.cjs');
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+ var _chunkG5NYLGM5cjs = require('./chunk-G5NYLGM5.cjs');
30
+
31
+ // src/wallets/wallet.ts
32
+ var _commonsdkbase = require('@crossmint/common-sdk-base');
33
+ var _options, _apiClient;
34
+ var Wallet = class {
35
+ constructor(args, apiClient) {
36
+ _chunkG5NYLGM5cjs.__privateAdd.call(void 0, this, _options);
37
+ _chunkG5NYLGM5cjs.__privateAdd.call(void 0, this, _apiClient);
38
+ const { chain, address, owner, signer, options, alias } = args;
39
+ _chunkG5NYLGM5cjs.__privateSet.call(void 0, this, _apiClient, apiClient);
40
+ this.chain = chain;
41
+ this.address = address;
42
+ this.owner = owner;
43
+ this.signer = signer;
44
+ _chunkG5NYLGM5cjs.__privateSet.call(void 0, this, _options, options);
45
+ this.alias = alias;
46
+ }
47
+ static getApiClient(wallet) {
48
+ return wallet.apiClient;
49
+ }
50
+ static getOptions(wallet) {
51
+ return wallet.options;
52
+ }
53
+ get apiClient() {
54
+ return _chunkG5NYLGM5cjs.__privateGet.call(void 0, this, _apiClient);
55
+ }
56
+ get options() {
57
+ return _chunkG5NYLGM5cjs.__privateGet.call(void 0, this, _options);
58
+ }
59
+ /**
60
+ * Get the API client
61
+ * @returns The API client
62
+ * @experimental This API is experimental and may change in the future
63
+ */
64
+ experimental_apiClient() {
65
+ return _chunkG5NYLGM5cjs.__privateGet.call(void 0, this, _apiClient);
66
+ }
67
+ /**
68
+ * Get the wallet balances - always includes USDC and native token (ETH/SOL)
69
+ * @param {string[]} tokens - Additional tokens to request (optional: native token and usdc are always included)
70
+ * @param {Chain[]} chains - The chains (optional)
71
+ * @returns {Promise<Balances<C>>} The balances returns nativeToken, usdc, tokens
72
+ * @throws {Error} If the balances cannot be retrieved
73
+ */
74
+ balances(tokens, chains) {
75
+ return _chunkG5NYLGM5cjs.__async.call(void 0, this, null, function* () {
76
+ let nativeToken;
77
+ switch (this.chain) {
78
+ case "solana":
79
+ nativeToken = "sol";
80
+ break;
81
+ case "stellar":
82
+ nativeToken = "xlm";
83
+ break;
84
+ default:
85
+ nativeToken = "eth";
86
+ break;
87
+ }
88
+ const allTokens = [nativeToken, "usdc", ...tokens != null ? tokens : []];
89
+ const response = yield _chunkG5NYLGM5cjs.__privateGet.call(void 0, this, _apiClient).getBalance(this.address, {
90
+ chains: chains != null ? chains : [this.chain],
91
+ tokens: allTokens
92
+ });
93
+ if ("error" in response) {
94
+ throw new Error(`Failed to get balances for wallet: ${JSON.stringify(response.message)}`);
95
+ }
96
+ return this.transformBalanceResponse(response, nativeToken, tokens);
97
+ });
98
+ }
99
+ /**
100
+ * Funds the wallet with Crossmint's stablecoin (USDXM).
101
+ *
102
+ * **Note:** This method is only available in staging environments and exclusively supports USDXM tokens.
103
+ * It cannot be used in production environments.
104
+ * @param amount - The amount of USDXM to fund the wallet with
105
+ * @param chain - Optional chain to fund on. If not provided, uses the wallet's default chain
106
+ * @returns The funding response
107
+ * @throws {Error} If the funding operation fails or if called in a production environment
108
+ */
109
+ stagingFund(amount, chain) {
110
+ return _chunkG5NYLGM5cjs.__async.call(void 0, this, null, function* () {
111
+ const response = yield this.apiClient.fundWallet(this.address, {
112
+ amount,
113
+ token: "usdxm",
114
+ // Type casting is necessary here due to a type mismatch between our DTO schema and server-side types
115
+ // (which only contains 10 testnet chains. Variable in main server is called EvmUsdcEnabledTestnetChains for reference).
116
+ chain: chain != null ? chain : this.chain
117
+ });
118
+ if ("error" in response) {
119
+ throw new Error(`Failed to fund wallet: ${JSON.stringify(response.message)}`);
120
+ }
121
+ return response;
122
+ });
123
+ }
124
+ /**
125
+ * Transform the API balance response to the new structure
126
+ * @private
127
+ */
128
+ transformBalanceResponse(apiResponse, nativeTokenSymbol, requestedTokens) {
129
+ const transformTokenBalance = (tokenData) => {
130
+ var _a, _b, _c, _d, _e;
131
+ const chainData = (_a = tokenData.chains) == null ? void 0 : _a[this.chain];
132
+ let chainSpecificField = {};
133
+ if (this.chain === "solana" && chainData != null && "mintHash" in chainData) {
134
+ chainSpecificField = { mintHash: chainData.mintHash };
135
+ } else if (this.chain === "stellar" && chainData != null && "contractId" in chainData) {
136
+ chainSpecificField = { contractId: chainData.contractId };
137
+ } else if (chainData != null && "contractAddress" in chainData) {
138
+ chainSpecificField = { contractAddress: chainData.contractAddress };
139
+ }
140
+ return _chunkG5NYLGM5cjs.__spreadValues.call(void 0, {
141
+ symbol: (_b = tokenData.symbol) != null ? _b : "",
142
+ name: (_c = tokenData.name) != null ? _c : "",
143
+ amount: (_d = tokenData.amount) != null ? _d : "0",
144
+ decimals: tokenData.decimals,
145
+ rawAmount: (_e = tokenData.rawAmount) != null ? _e : "0"
146
+ }, chainSpecificField);
147
+ };
148
+ const nativeTokenData = apiResponse.find((token) => token.symbol === nativeTokenSymbol);
149
+ const usdcData = apiResponse.find((token) => token.symbol === "usdc");
150
+ const otherTokens = apiResponse.filter((token) => {
151
+ return token.symbol !== nativeTokenSymbol && token.symbol !== "usdc";
152
+ });
153
+ const createDefaultToken = (symbol) => {
154
+ const baseToken = {
155
+ symbol,
156
+ name: symbol,
157
+ amount: "0",
158
+ decimals: 0,
159
+ rawAmount: "0"
160
+ };
161
+ let chainSpecificField = {};
162
+ if (this.chain === "solana") {
163
+ chainSpecificField = { mintHash: void 0 };
164
+ } else if (this.chain === "stellar") {
165
+ chainSpecificField = { contractId: void 0 };
166
+ } else {
167
+ chainSpecificField = { contractAddress: void 0 };
168
+ }
169
+ return _chunkG5NYLGM5cjs.__spreadValues.call(void 0, _chunkG5NYLGM5cjs.__spreadValues.call(void 0, {}, baseToken), chainSpecificField);
170
+ };
171
+ return {
172
+ nativeToken: nativeTokenData != null ? transformTokenBalance(nativeTokenData) : createDefaultToken(nativeTokenSymbol),
173
+ usdc: usdcData != null ? transformTokenBalance(usdcData) : createDefaultToken("usdc"),
174
+ tokens: otherTokens.map(transformTokenBalance)
175
+ };
176
+ }
177
+ /**
178
+ * Get the wallet NFTs
179
+ * @param {Object} params - The parameters
180
+ * @param {number} params.perPage - The number of NFTs per page
181
+ * @param {number} params.page - The page number
182
+ * @param {WalletLocator} [params.locator] - The locator
183
+ * @returns The NFTs
184
+ * @experimental This API is experimental and may change in the future
185
+ */
186
+ experimental_nfts(params) {
187
+ return _chunkG5NYLGM5cjs.__async.call(void 0, this, null, function* () {
188
+ return yield _chunkG5NYLGM5cjs.__privateGet.call(void 0, this, _apiClient).experimental_getNfts(_chunkG5NYLGM5cjs.__spreadProps.call(void 0, _chunkG5NYLGM5cjs.__spreadValues.call(void 0, {}, params), {
189
+ chain: this.chain,
190
+ address: this.address
191
+ }));
192
+ });
193
+ }
194
+ /**
195
+ * Get the wallet transactions
196
+ * @returns The transactions
197
+ * @throws {Error} If the transactions cannot be retrieved
198
+ */
199
+ experimental_transactions() {
200
+ return _chunkG5NYLGM5cjs.__async.call(void 0, this, null, function* () {
201
+ const response = yield _chunkG5NYLGM5cjs.__privateGet.call(void 0, this, _apiClient).getTransactions(this.walletLocator);
202
+ if ("error" in response) {
203
+ throw new Error(`Failed to get transactions: ${JSON.stringify(response.message)}`);
204
+ }
205
+ return response;
206
+ });
207
+ }
208
+ /**
209
+ * Get a transaction by id
210
+ * @returns The transaction
211
+ * @throws {Error} If the transaction cannot be retrieved
212
+ */
213
+ experimental_transaction(transactionId) {
214
+ return _chunkG5NYLGM5cjs.__async.call(void 0, this, null, function* () {
215
+ const response = yield _chunkG5NYLGM5cjs.__privateGet.call(void 0, this, _apiClient).getTransaction(this.walletLocator, transactionId);
216
+ if ("error" in response) {
217
+ throw new Error(`Failed to get transaction: ${JSON.stringify(response.error)}`);
218
+ }
219
+ return response;
220
+ });
221
+ }
222
+ /**
223
+ * Get the wallet activity
224
+ * @returns The activity
225
+ * @experimental This API is experimental and may change in the future
226
+ * @throws {Error} If the activity cannot be retrieved
227
+ */
228
+ experimental_activity() {
229
+ return _chunkG5NYLGM5cjs.__async.call(void 0, this, null, function* () {
230
+ const response = yield this.apiClient.experimental_activity(this.walletLocator, { chain: this.chain });
231
+ if ("error" in response) {
232
+ throw new Error(`Failed to get activity: ${JSON.stringify(response.message)}`);
233
+ }
234
+ return response;
235
+ });
236
+ }
237
+ /**
238
+ * Send a token to a wallet or user locator
239
+ * @param {string | UserLocator} to - The recipient (address or user locator)
240
+ * @param {string} token - The token (address or currency symbol)
241
+ * @param {string} amount - The amount to send (decimal units)
242
+ * @param {TransactionInputOptions} options - The options for the transaction
243
+ * @returns {Transaction} The transaction
244
+ */
245
+ send(to, token, amount, options) {
246
+ return _chunkG5NYLGM5cjs.__async.call(void 0, this, null, function* () {
247
+ yield this.preAuthIfNeeded();
248
+ const recipient = toRecipientLocator(to);
249
+ const tokenLocator = toTokenLocator(token, this.chain);
250
+ const sendParams = _chunkG5NYLGM5cjs.__spreadValues.call(void 0, {
251
+ recipient,
252
+ amount
253
+ }, (options == null ? void 0 : options.experimental_signer) != null ? { signer: options.experimental_signer } : {});
254
+ const transactionCreationResponse = yield _chunkG5NYLGM5cjs.__privateGet.call(void 0, this, _apiClient).send(this.walletLocator, tokenLocator, sendParams);
255
+ if ("message" in transactionCreationResponse) {
256
+ throw new (0, _chunkXC2V34TScjs.TransactionNotCreatedError)(
257
+ `Failed to send token: ${JSON.stringify(transactionCreationResponse.message)}`
258
+ );
259
+ }
260
+ if (options == null ? void 0 : options.experimental_prepareOnly) {
261
+ return {
262
+ hash: void 0,
263
+ explorerLink: void 0,
264
+ transactionId: transactionCreationResponse.id
265
+ };
266
+ }
267
+ return yield this.approveTransactionAndWait(transactionCreationResponse.id);
268
+ });
269
+ }
270
+ /**
271
+ * @deprecated Use `approve` instead.
272
+ * Approve a transaction
273
+ * @param params - The parameters
274
+ * @param params.transactionId - The transaction id
275
+ * @param params.options - The options for the transaction
276
+ * @param params.options.experimental_approval - The approval
277
+ * @param params.options.additionalSigners - The additional signers
278
+ * @returns The transaction
279
+ */
280
+ // TODO: Remove this method in the next major version
281
+ approveTransaction(params) {
282
+ return _chunkG5NYLGM5cjs.__async.call(void 0, this, null, function* () {
283
+ console.warn(
284
+ "approveTransaction is deprecated. Use approve instead. This method will be removed in the next major version."
285
+ );
286
+ return yield this.approve(params);
287
+ });
288
+ }
289
+ /**
290
+ * Approve a transaction or signature
291
+ * @param params - The parameters
292
+ * @param params.transactionId - The transaction id or
293
+ * @param params.signatureId - The signature id
294
+ * @param params.options - The options for the transaction
295
+ * @param params.options.experimental_approval - The approval
296
+ * @param params.options.additionalSigners - The additional signers
297
+ * @returns The transaction or signature
298
+ */
299
+ approve(params) {
300
+ return _chunkG5NYLGM5cjs.__async.call(void 0, this, null, function* () {
301
+ if (params.transactionId != null) {
302
+ return yield this.approveTransactionAndWait(params.transactionId, params.options);
303
+ }
304
+ if (params.signatureId != null) {
305
+ return yield this.approveSignatureAndWait(params.signatureId, params.options);
306
+ }
307
+ throw new Error("Either transactionId or signatureId must be provided");
308
+ });
309
+ }
310
+ /**
311
+ * Add a delegated signer to the wallet
312
+ * @param signer - The signer. For Solana, it must be a string. For EVM, it can be a string or a passkey.
313
+ * @param options - The options for the operation
314
+ * @param options.experimental_prepareOnly - If true, returns the transaction/signature ID without auto-approving
315
+ */
316
+ addDelegatedSigner(params) {
317
+ return _chunkG5NYLGM5cjs.__async.call(void 0, this, null, function* () {
318
+ var _a, _b, _c;
319
+ const response = yield _chunkG5NYLGM5cjs.__privateGet.call(void 0, this, _apiClient).registerSigner(this.walletLocator, {
320
+ signer: params.signer,
321
+ chain: this.chain === "solana" || this.chain === "stellar" ? void 0 : this.chain
322
+ });
323
+ if ("error" in response) {
324
+ throw new Error(`Failed to register signer: ${JSON.stringify(response.message)}`);
325
+ }
326
+ if (this.chain === "solana" || this.chain === "stellar") {
327
+ if (!("transaction" in response) || response.transaction == null) {
328
+ throw new Error("Expected transaction in response for Solana/Stellar chain");
329
+ }
330
+ const transactionId = response.transaction.id;
331
+ if ((_a = params.options) == null ? void 0 : _a.experimental_prepareOnly) {
332
+ return { transactionId };
333
+ }
334
+ yield this.approveTransactionAndWait(transactionId);
335
+ return void 0;
336
+ }
337
+ if (!("chains" in response)) {
338
+ throw new Error("Expected chains in response for EVM chain");
339
+ }
340
+ const chainResponse = (_b = response.chains) == null ? void 0 : _b[this.chain];
341
+ if ((_c = params.options) == null ? void 0 : _c.experimental_prepareOnly) {
342
+ const signatureId = (chainResponse == null ? void 0 : chainResponse.status) !== "success" ? chainResponse == null ? void 0 : chainResponse.id : void 0;
343
+ return { signatureId };
344
+ }
345
+ if ((chainResponse == null ? void 0 : chainResponse.status) === "awaiting-approval") {
346
+ yield this.approveSignatureAndWait(chainResponse.id);
347
+ return void 0;
348
+ }
349
+ if ((chainResponse == null ? void 0 : chainResponse.status) === "pending") {
350
+ yield this.waitForSignature(chainResponse.id);
351
+ return void 0;
352
+ }
353
+ return void 0;
354
+ });
355
+ }
356
+ delegatedSigners() {
357
+ return _chunkG5NYLGM5cjs.__async.call(void 0, this, null, function* () {
358
+ var _a, _b, _c;
359
+ const walletResponse = yield _chunkG5NYLGM5cjs.__privateGet.call(void 0, this, _apiClient).getWallet(this.walletLocator);
360
+ if ("error" in walletResponse) {
361
+ throw new (0, _chunkXC2V34TScjs.WalletNotAvailableError)(JSON.stringify(walletResponse));
362
+ }
363
+ if (walletResponse.type !== "smart" || walletResponse.chainType !== "evm" && walletResponse.chainType !== "solana" && walletResponse.chainType !== "stellar") {
364
+ throw new (0, _chunkXC2V34TScjs.WalletTypeNotSupportedError)(`Wallet type ${walletResponse.type} not supported`);
365
+ }
366
+ return (_c = (_b = (_a = walletResponse == null ? void 0 : walletResponse.config) == null ? void 0 : _a.delegatedSigners) == null ? void 0 : _b.map((signer) => {
367
+ const colonIndex = signer.locator.indexOf(":");
368
+ const address = colonIndex >= 0 ? signer.locator.slice(colonIndex + 1) : signer.locator;
369
+ return {
370
+ signer: `external-wallet:${address}`
371
+ };
372
+ })) != null ? _c : [];
373
+ });
374
+ }
375
+ get walletLocator() {
376
+ if (_chunkG5NYLGM5cjs.__privateGet.call(void 0, this, _apiClient).isServerSide) {
377
+ return this.address;
378
+ } else {
379
+ let baseLocator;
380
+ switch (this.chain) {
381
+ case "stellar":
382
+ baseLocator = `me:stellar:smart`;
383
+ break;
384
+ case "solana":
385
+ baseLocator = `me:solana:smart`;
386
+ break;
387
+ default:
388
+ baseLocator = `me:evm:smart`;
389
+ break;
390
+ }
391
+ const aliasLocatorPart = this.alias != null ? `:alias:${this.alias}` : "";
392
+ return baseLocator + aliasLocatorPart;
393
+ }
394
+ }
395
+ preAuthIfNeeded() {
396
+ return _chunkG5NYLGM5cjs.__async.call(void 0, this, null, function* () {
397
+ if (this.signer instanceof _chunkE4LJ7252cjs.NonCustodialSigner) {
398
+ yield this.signer.ensureAuthenticated();
399
+ }
400
+ });
401
+ }
402
+ get isSolanaWallet() {
403
+ return this.chain === "solana";
404
+ }
405
+ approveTransactionAndWait(transactionId, options) {
406
+ return _chunkG5NYLGM5cjs.__async.call(void 0, this, null, function* () {
407
+ yield this.approveTransactionInternal(transactionId, options);
408
+ yield this.sleep(1e3);
409
+ return yield this.waitForTransaction(transactionId);
410
+ });
411
+ }
412
+ approveSignatureAndWait(signatureId, options) {
413
+ return _chunkG5NYLGM5cjs.__async.call(void 0, this, null, function* () {
414
+ const signatureResponse = yield this.approveSignatureInternal(signatureId, options);
415
+ if (!("error" in signatureResponse) && signatureResponse.status === "success" && signatureResponse.outputSignature != null) {
416
+ return {
417
+ signature: signatureResponse.outputSignature,
418
+ signatureId
419
+ };
420
+ }
421
+ yield this.sleep(1e3);
422
+ return yield this.waitForSignature(signatureId);
423
+ });
424
+ }
425
+ approveSignatureInternal(signatureId, options) {
426
+ return _chunkG5NYLGM5cjs.__async.call(void 0, this, null, function* () {
427
+ var _a, _b;
428
+ if (this.isSolanaWallet) {
429
+ throw new Error("Approving signatures is only supported for EVM smart wallets");
430
+ }
431
+ const signature = yield _chunkG5NYLGM5cjs.__privateGet.call(void 0, this, _apiClient).getSignature(this.walletLocator, signatureId);
432
+ if ("error" in signature) {
433
+ throw new (0, _chunkXC2V34TScjs.SignatureNotAvailableError)(JSON.stringify(signature));
434
+ }
435
+ if (this.signer.type === "api-key") {
436
+ return signature;
437
+ }
438
+ if ((options == null ? void 0 : options.experimental_approval) != null) {
439
+ const approvals2 = [options.experimental_approval];
440
+ return yield this.executeApproveSignatureWithErrorHandling(signatureId, approvals2);
441
+ }
442
+ const pendingApprovals = (_a = signature.approvals) == null ? void 0 : _a.pending;
443
+ if (pendingApprovals == null) {
444
+ return signature;
445
+ }
446
+ const signers = [...(_b = options == null ? void 0 : options.additionalSigners) != null ? _b : [], this.signer];
447
+ const signedApprovals = yield Promise.all(
448
+ pendingApprovals.map((pendingApproval) => {
449
+ const signer = signers.find((s) => s.locator() === pendingApproval.signer.locator);
450
+ if (signer == null) {
451
+ throw new (0, _chunkXC2V34TScjs.InvalidSignerError)(`Signer ${pendingApproval.signer} not found in pending approvals`);
452
+ }
453
+ return signer.signMessage(pendingApproval.message);
454
+ })
455
+ );
456
+ const approvals = signedApprovals.map((signature2) => {
457
+ return _chunkG5NYLGM5cjs.__spreadProps.call(void 0, _chunkG5NYLGM5cjs.__spreadValues.call(void 0, {}, signature2), {
458
+ signer: this.signer.locator()
459
+ });
460
+ });
461
+ return yield this.executeApproveSignatureWithErrorHandling(signatureId, approvals);
462
+ });
463
+ }
464
+ approveTransactionInternal(transactionId, options) {
465
+ return _chunkG5NYLGM5cjs.__async.call(void 0, this, null, function* () {
466
+ var _a, _b, _c, _d, _e;
467
+ const transaction = yield _chunkG5NYLGM5cjs.__privateGet.call(void 0, this, _apiClient).getTransaction(this.walletLocator, transactionId);
468
+ if ("error" in transaction) {
469
+ throw new (0, _chunkXC2V34TScjs.TransactionNotAvailableError)(JSON.stringify(transaction));
470
+ }
471
+ yield (_c = (_b = (_a = _chunkG5NYLGM5cjs.__privateGet.call(void 0, this, _options)) == null ? void 0 : _a.experimental_callbacks) == null ? void 0 : _b.onTransactionStart) == null ? void 0 : _c.call(_b);
472
+ if (this.signer.type === "api-key") {
473
+ return transaction;
474
+ }
475
+ if ((options == null ? void 0 : options.experimental_approval) != null) {
476
+ const approvals2 = [options.experimental_approval];
477
+ return yield this.executeApproveTransactionWithErrorHandling(transactionId, approvals2);
478
+ }
479
+ const pendingApprovals = (_d = transaction.approvals) == null ? void 0 : _d.pending;
480
+ if (pendingApprovals == null) {
481
+ return transaction;
482
+ }
483
+ const signers = [...(_e = options == null ? void 0 : options.additionalSigners) != null ? _e : [], this.signer];
484
+ const signedApprovals = yield Promise.all(
485
+ pendingApprovals.map((pendingApproval) => {
486
+ const signer = signers.find((s) => s.locator() === pendingApproval.signer.locator);
487
+ if (signer == null) {
488
+ throw new (0, _chunkXC2V34TScjs.InvalidSignerError)(`Signer ${pendingApproval.signer} not found in pending approvals`);
489
+ }
490
+ const transactionToSign = transaction.chainType === "solana" && "transaction" in transaction.onChain ? transaction.onChain.transaction : pendingApproval.message;
491
+ return signer.signTransaction(transactionToSign);
492
+ })
493
+ );
494
+ const approvals = signedApprovals.map((signature) => {
495
+ return _chunkG5NYLGM5cjs.__spreadProps.call(void 0, _chunkG5NYLGM5cjs.__spreadValues.call(void 0, {}, signature), {
496
+ signer: this.signer.locator()
497
+ });
498
+ });
499
+ return yield this.executeApproveTransactionWithErrorHandling(transactionId, approvals);
500
+ });
501
+ }
502
+ executeApproveTransactionWithErrorHandling(transactionId, approvals) {
503
+ return _chunkG5NYLGM5cjs.__async.call(void 0, this, null, function* () {
504
+ const approvedTransaction = yield _chunkG5NYLGM5cjs.__privateGet.call(void 0, this, _apiClient).approveTransaction(this.walletLocator, transactionId, {
505
+ approvals
506
+ });
507
+ if (approvedTransaction.error) {
508
+ throw new (0, _chunkXC2V34TScjs.TransactionFailedError)(JSON.stringify(approvedTransaction));
509
+ }
510
+ return approvedTransaction;
511
+ });
512
+ }
513
+ executeApproveSignatureWithErrorHandling(signatureId, approvals) {
514
+ return _chunkG5NYLGM5cjs.__async.call(void 0, this, null, function* () {
515
+ const approvedSignature = yield _chunkG5NYLGM5cjs.__privateGet.call(void 0, this, _apiClient).approveSignature(this.walletLocator, signatureId, {
516
+ approvals
517
+ });
518
+ if (approvedSignature.error) {
519
+ throw new (0, _chunkXC2V34TScjs.SignatureFailedError)(JSON.stringify(approvedSignature));
520
+ }
521
+ return approvedSignature;
522
+ });
523
+ }
524
+ waitForSignature(signatureId) {
525
+ return _chunkG5NYLGM5cjs.__async.call(void 0, this, null, function* () {
526
+ let signatureResponse = null;
527
+ do {
528
+ yield new Promise((resolve) => setTimeout(resolve, _chunkMPGPBFUZcjs.STATUS_POLLING_INTERVAL_MS));
529
+ signatureResponse = yield _chunkG5NYLGM5cjs.__privateGet.call(void 0, this, _apiClient).getSignature(this.walletLocator, signatureId);
530
+ if ("error" in signatureResponse) {
531
+ throw new (0, _chunkXC2V34TScjs.SignatureNotAvailableError)(JSON.stringify(signatureResponse));
532
+ }
533
+ } while (signatureResponse === null || signatureResponse.status === "pending");
534
+ if (signatureResponse.status === "failed") {
535
+ throw new (0, _chunkXC2V34TScjs.SigningFailedError)("Signature signing failed");
536
+ }
537
+ if (!signatureResponse.outputSignature) {
538
+ throw new (0, _chunkXC2V34TScjs.SignatureNotAvailableError)("Signature not available");
539
+ }
540
+ return {
541
+ signature: signatureResponse.outputSignature,
542
+ signatureId
543
+ };
544
+ });
545
+ }
546
+ waitForTransaction(_0) {
547
+ return _chunkG5NYLGM5cjs.__async.call(void 0, this, arguments, function* (transactionId, timeoutMs = 6e4, {
548
+ backoffMultiplier = 1.1,
549
+ maxBackoffMs = 2e3,
550
+ initialBackoffMs = _chunkMPGPBFUZcjs.STATUS_POLLING_INTERVAL_MS
551
+ } = {}) {
552
+ var _a;
553
+ const startTime = Date.now();
554
+ let transactionResponse;
555
+ do {
556
+ if (Date.now() - startTime > timeoutMs) {
557
+ const error = new (0, _chunkXC2V34TScjs.TransactionConfirmationTimeoutError)("Transaction confirmation timeout");
558
+ throw error;
559
+ }
560
+ transactionResponse = yield _chunkG5NYLGM5cjs.__privateGet.call(void 0, this, _apiClient).getTransaction(this.walletLocator, transactionId);
561
+ if (transactionResponse.error) {
562
+ throw new (0, _chunkXC2V34TScjs.TransactionNotAvailableError)(JSON.stringify(transactionResponse));
563
+ }
564
+ yield this.sleep(initialBackoffMs);
565
+ initialBackoffMs = Math.min(initialBackoffMs * backoffMultiplier, maxBackoffMs);
566
+ } while (transactionResponse.status === "pending");
567
+ if (transactionResponse.status === "failed") {
568
+ const error = new (0, _chunkXC2V34TScjs.TransactionSendingFailedError)(
569
+ `Transaction sending failed: ${JSON.stringify(transactionResponse.error)}`
570
+ );
571
+ throw error;
572
+ }
573
+ if (transactionResponse.status === "awaiting-approval") {
574
+ const error = new (0, _chunkXC2V34TScjs.TransactionAwaitingApprovalError)(
575
+ `Transaction is awaiting approval. Please submit required approvals before waiting for completion.`
576
+ );
577
+ throw error;
578
+ }
579
+ const transactionHash = transactionResponse.onChain.txId;
580
+ if (transactionHash == null) {
581
+ const error = new (0, _chunkXC2V34TScjs.TransactionHashNotFoundError)("Transaction hash not found on transaction response");
582
+ throw error;
583
+ }
584
+ return {
585
+ hash: transactionHash,
586
+ explorerLink: (_a = transactionResponse.onChain.explorerLink) != null ? _a : "",
587
+ transactionId: transactionResponse.id
588
+ };
589
+ });
590
+ }
591
+ sleep(ms) {
592
+ return _chunkG5NYLGM5cjs.__async.call(void 0, this, null, function* () {
593
+ return new Promise((resolve) => setTimeout(resolve, ms));
594
+ });
595
+ }
596
+ };
597
+ _options = new WeakMap();
598
+ _apiClient = new WeakMap();
599
+ function toRecipientLocator(to) {
600
+ if (typeof to === "string") {
601
+ return to;
602
+ }
603
+ if ("email" in to) {
604
+ return `email:${to.email}`;
605
+ }
606
+ if ("x" in to) {
607
+ return `x:${to.x}`;
608
+ }
609
+ if ("twitter" in to) {
610
+ return `twitter:${to.twitter}`;
611
+ }
612
+ if ("phone" in to) {
613
+ return `phoneNumber:${to.phone}`;
614
+ }
615
+ if ("userId" in to) {
616
+ return `userId:${to.userId}`;
617
+ }
618
+ throw new Error("Invalid recipient locator");
619
+ }
620
+ function toTokenLocator(token, chain) {
621
+ if (_commonsdkbase.isValidAddress.call(void 0, token)) {
622
+ return `${chain}:${token}`;
623
+ }
624
+ return `${chain}:${token.toLowerCase()}`;
625
+ }
626
+
627
+
628
+
629
+ exports.Wallet = Wallet;