@worldcoin/minikit-js 1.11.0 → 2.0.0-dev.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 (39) hide show
  1. package/README.md +107 -0
  2. package/build/address-book.cjs +81 -0
  3. package/build/address-book.d.cts +3 -0
  4. package/build/address-book.d.ts +3 -0
  5. package/build/address-book.js +54 -0
  6. package/build/chunk-2UPJKPQ6.js +272 -0
  7. package/build/chunk-EHBM7OXH.js +596 -0
  8. package/build/chunk-LHHKY77D.js +274 -0
  9. package/build/chunk-TGXD24YD.js +279 -0
  10. package/build/chunk-Z2UGRZJ2.js +1635 -0
  11. package/build/command-exports.cjs +1762 -0
  12. package/build/command-exports.d.cts +105 -0
  13. package/build/command-exports.d.ts +105 -0
  14. package/build/command-exports.js +129 -0
  15. package/build/connector/index.cjs +2601 -0
  16. package/build/connector/index.d.cts +55 -0
  17. package/build/connector/index.d.ts +55 -0
  18. package/build/connector/index.js +90 -0
  19. package/build/index.cjs +1634 -1627
  20. package/build/index.d.cts +143 -671
  21. package/build/index.d.ts +143 -671
  22. package/build/index.js +7 -206
  23. package/build/minikit-provider.cjs +1650 -948
  24. package/build/minikit-provider.d.cts +2 -1
  25. package/build/minikit-provider.d.ts +2 -1
  26. package/build/minikit-provider.js +13 -2
  27. package/build/provider-DeDUsLbs.d.cts +43 -0
  28. package/build/provider-DeDUsLbs.d.ts +43 -0
  29. package/build/siwe-exports.cjs +249 -0
  30. package/build/siwe-exports.d.cts +10 -0
  31. package/build/siwe-exports.d.ts +10 -0
  32. package/build/siwe-exports.js +8 -0
  33. package/build/types-CC2x79HX.d.ts +525 -0
  34. package/build/types-CSyzFDPt.d.cts +223 -0
  35. package/build/types-CSyzFDPt.d.ts +223 -0
  36. package/build/types-_jfLbcJW.d.cts +525 -0
  37. package/package.json +73 -11
  38. package/build/chunk-62NZ34E4.js +0 -2092
  39. package/index.ts +0 -29
@@ -0,0 +1,1762 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/command-exports.ts
21
+ var command_exports_exports = {};
22
+ __export(command_exports_exports, {
23
+ AttestationError: () => AttestationError,
24
+ AttestationErrorCodes: () => AttestationErrorCodes,
25
+ COMMAND_VERSIONS: () => COMMAND_VERSIONS,
26
+ ChatError: () => ChatError,
27
+ ChatErrorCodes: () => ChatErrorCodes,
28
+ Command: () => Command,
29
+ CommandUnavailableError: () => CommandUnavailableError,
30
+ FallbackRequiredError: () => FallbackRequiredError,
31
+ GetPermissionsError: () => GetPermissionsError,
32
+ GetPermissionsErrorCodes: () => GetPermissionsErrorCodes,
33
+ MiniAppLaunchLocation: () => MiniAppLaunchLocation,
34
+ MiniKitInstallErrorCodes: () => MiniKitInstallErrorCodes,
35
+ MiniKitInstallErrorMessage: () => MiniKitInstallErrorMessage,
36
+ Network: () => Network,
37
+ PayError: () => PayError,
38
+ PaymentErrorCodes: () => PaymentErrorCodes,
39
+ PaymentErrorMessage: () => PaymentErrorMessage,
40
+ Permission: () => Permission,
41
+ RequestPermissionError: () => RequestPermissionError,
42
+ RequestPermissionErrorCodes: () => RequestPermissionErrorCodes,
43
+ ResponseEvent: () => ResponseEvent,
44
+ SendHapticFeedbackError: () => SendHapticFeedbackError,
45
+ SendHapticFeedbackErrorCodes: () => SendHapticFeedbackErrorCodes,
46
+ SendTransactionError: () => SendTransactionError,
47
+ SendTransactionErrorCodes: () => SendTransactionErrorCodes,
48
+ SendTransactionErrorMessage: () => SendTransactionErrorMessage,
49
+ ShareContactsError: () => ShareContactsError,
50
+ ShareContactsErrorCodes: () => ShareContactsErrorCodes,
51
+ ShareContactsErrorMessage: () => ShareContactsErrorMessage,
52
+ ShareError: () => ShareError,
53
+ ShareFilesErrorCodes: () => ShareFilesErrorCodes,
54
+ SignMessageError: () => SignMessageError,
55
+ SignMessageErrorCodes: () => SignMessageErrorCodes,
56
+ SignTypedDataError: () => SignTypedDataError,
57
+ SignTypedDataErrorCodes: () => SignTypedDataErrorCodes,
58
+ TokenDecimals: () => TokenDecimals,
59
+ Tokens: () => Tokens,
60
+ WEB_FEATURES: () => WEB_FEATURES,
61
+ WORLD_APP_FEATURES: () => WORLD_APP_FEATURES,
62
+ WalletAuthError: () => WalletAuthError,
63
+ WalletAuthErrorCodes: () => WalletAuthErrorCodes,
64
+ WalletAuthErrorMessage: () => WalletAuthErrorMessage,
65
+ attestation: () => attestation,
66
+ chat: () => chat,
67
+ closeMiniApp: () => closeMiniApp,
68
+ getContacts: () => getContacts,
69
+ getPermissions: () => getPermissions,
70
+ isCommandAvailable: () => isCommandAvailable,
71
+ isInWorldApp: () => isInWorldApp,
72
+ pay: () => pay,
73
+ requestPermission: () => requestPermission,
74
+ sendHapticFeedback: () => sendHapticFeedback,
75
+ sendMiniKitEvent: () => sendMiniKitEvent,
76
+ sendTransaction: () => sendTransaction,
77
+ setCommandAvailable: () => setCommandAvailable,
78
+ share: () => share,
79
+ shareContacts: () => shareContacts,
80
+ signMessage: () => signMessage,
81
+ signTypedData: () => signTypedData,
82
+ tokenToDecimals: () => tokenToDecimals,
83
+ validateCommands: () => validateCommands,
84
+ walletAuth: () => walletAuth
85
+ });
86
+ module.exports = __toCommonJS(command_exports_exports);
87
+
88
+ // src/commands/types.ts
89
+ var Command = /* @__PURE__ */ ((Command2) => {
90
+ Command2["Attestation"] = "attestation";
91
+ Command2["Pay"] = "pay";
92
+ Command2["WalletAuth"] = "wallet-auth";
93
+ Command2["SendTransaction"] = "send-transaction";
94
+ Command2["SignMessage"] = "sign-message";
95
+ Command2["SignTypedData"] = "sign-typed-data";
96
+ Command2["ShareContacts"] = "share-contacts";
97
+ Command2["RequestPermission"] = "request-permission";
98
+ Command2["GetPermissions"] = "get-permissions";
99
+ Command2["SendHapticFeedback"] = "send-haptic-feedback";
100
+ Command2["Share"] = "share";
101
+ Command2["Chat"] = "chat";
102
+ Command2["CloseMiniApp"] = "close-miniapp";
103
+ return Command2;
104
+ })(Command || {});
105
+ var ResponseEvent = /* @__PURE__ */ ((ResponseEvent2) => {
106
+ ResponseEvent2["MiniAppAttestation"] = "miniapp-attestation";
107
+ ResponseEvent2["MiniAppPayment"] = "miniapp-payment";
108
+ ResponseEvent2["MiniAppWalletAuth"] = "miniapp-wallet-auth";
109
+ ResponseEvent2["MiniAppSendTransaction"] = "miniapp-send-transaction";
110
+ ResponseEvent2["MiniAppSignMessage"] = "miniapp-sign-message";
111
+ ResponseEvent2["MiniAppSignTypedData"] = "miniapp-sign-typed-data";
112
+ ResponseEvent2["MiniAppShareContacts"] = "miniapp-share-contacts";
113
+ ResponseEvent2["MiniAppRequestPermission"] = "miniapp-request-permission";
114
+ ResponseEvent2["MiniAppGetPermissions"] = "miniapp-get-permissions";
115
+ ResponseEvent2["MiniAppSendHapticFeedback"] = "miniapp-send-haptic-feedback";
116
+ ResponseEvent2["MiniAppShare"] = "miniapp-share";
117
+ ResponseEvent2["MiniAppMicrophone"] = "miniapp-microphone";
118
+ ResponseEvent2["MiniAppChat"] = "miniapp-chat";
119
+ return ResponseEvent2;
120
+ })(ResponseEvent || {});
121
+ var COMMAND_VERSIONS = {
122
+ ["attestation" /* Attestation */]: 1,
123
+ ["pay" /* Pay */]: 1,
124
+ ["wallet-auth" /* WalletAuth */]: 2,
125
+ ["send-transaction" /* SendTransaction */]: 2,
126
+ ["sign-message" /* SignMessage */]: 1,
127
+ ["sign-typed-data" /* SignTypedData */]: 1,
128
+ ["share-contacts" /* ShareContacts */]: 1,
129
+ ["request-permission" /* RequestPermission */]: 1,
130
+ ["get-permissions" /* GetPermissions */]: 1,
131
+ ["send-haptic-feedback" /* SendHapticFeedback */]: 1,
132
+ ["share" /* Share */]: 1,
133
+ ["chat" /* Chat */]: 1,
134
+ ["close-miniapp" /* CloseMiniApp */]: 1
135
+ };
136
+ var commandAvailability = {
137
+ ["attestation" /* Attestation */]: false,
138
+ ["pay" /* Pay */]: false,
139
+ ["wallet-auth" /* WalletAuth */]: false,
140
+ ["send-transaction" /* SendTransaction */]: false,
141
+ ["sign-message" /* SignMessage */]: false,
142
+ ["sign-typed-data" /* SignTypedData */]: false,
143
+ ["share-contacts" /* ShareContacts */]: false,
144
+ ["request-permission" /* RequestPermission */]: false,
145
+ ["get-permissions" /* GetPermissions */]: false,
146
+ ["send-haptic-feedback" /* SendHapticFeedback */]: false,
147
+ ["share" /* Share */]: false,
148
+ ["chat" /* Chat */]: false,
149
+ ["close-miniapp" /* CloseMiniApp */]: false
150
+ };
151
+ function isCommandAvailable(command) {
152
+ return commandAvailability[command] ?? false;
153
+ }
154
+ function setCommandAvailable(command, available) {
155
+ commandAvailability[command] = available;
156
+ }
157
+ function validateCommands(worldAppSupportedCommands) {
158
+ let allCommandsValid = true;
159
+ Object.entries(COMMAND_VERSIONS).forEach(([commandName, version]) => {
160
+ const commandInput = worldAppSupportedCommands.find(
161
+ (cmd) => cmd.name === commandName
162
+ );
163
+ let isCommandValid = false;
164
+ if (!commandInput) {
165
+ console.warn(
166
+ `Command ${commandName} is not supported by the app. Try updating the app version`
167
+ );
168
+ } else {
169
+ if (commandInput.supported_versions.includes(version)) {
170
+ setCommandAvailable(commandName, true);
171
+ isCommandValid = true;
172
+ } else {
173
+ isCommandValid = true;
174
+ console.warn(
175
+ `Command ${commandName} version ${version} is not supported by the app. Supported versions: ${commandInput.supported_versions.join(", ")}. This is not an error, but it is recommended to update the World App version.`
176
+ );
177
+ setCommandAvailable(commandName, true);
178
+ }
179
+ }
180
+ if (!isCommandValid) {
181
+ allCommandsValid = false;
182
+ }
183
+ });
184
+ return allCommandsValid;
185
+ }
186
+ function sendMiniKitEvent(payload) {
187
+ if (window.webkit) {
188
+ window.webkit?.messageHandlers?.minikit?.postMessage?.(payload);
189
+ } else if (window.Android) {
190
+ window.Android?.postMessage?.(JSON.stringify(payload));
191
+ }
192
+ }
193
+ function isInWorldApp() {
194
+ return typeof window !== "undefined" && Boolean(window.WorldApp);
195
+ }
196
+ var FallbackRequiredError = class extends Error {
197
+ constructor(command) {
198
+ super(
199
+ `${command} requires a fallback function when running outside World App. Provide a fallback option: MiniKit.${command}({ ..., fallback: () => yourFallback() })`
200
+ );
201
+ this.name = "FallbackRequiredError";
202
+ }
203
+ };
204
+ var CommandUnavailableError = class extends Error {
205
+ constructor(command, reason) {
206
+ const messages = {
207
+ notInWorldApp: "Not running inside World App",
208
+ commandNotSupported: "Command not supported in this environment",
209
+ oldAppVersion: "World App version does not support this command"
210
+ };
211
+ super(`${command} is unavailable: ${messages[reason]}`);
212
+ this.name = "CommandUnavailableError";
213
+ this.reason = reason;
214
+ }
215
+ };
216
+
217
+ // src/events.ts
218
+ var EventManager = class {
219
+ constructor() {
220
+ this.listeners = {
221
+ ["miniapp-attestation" /* MiniAppAttestation */]: () => {
222
+ },
223
+ ["miniapp-payment" /* MiniAppPayment */]: () => {
224
+ },
225
+ ["miniapp-wallet-auth" /* MiniAppWalletAuth */]: () => {
226
+ },
227
+ ["miniapp-send-transaction" /* MiniAppSendTransaction */]: () => {
228
+ },
229
+ ["miniapp-sign-message" /* MiniAppSignMessage */]: () => {
230
+ },
231
+ ["miniapp-sign-typed-data" /* MiniAppSignTypedData */]: () => {
232
+ },
233
+ ["miniapp-share-contacts" /* MiniAppShareContacts */]: () => {
234
+ },
235
+ ["miniapp-request-permission" /* MiniAppRequestPermission */]: () => {
236
+ },
237
+ ["miniapp-get-permissions" /* MiniAppGetPermissions */]: () => {
238
+ },
239
+ ["miniapp-send-haptic-feedback" /* MiniAppSendHapticFeedback */]: () => {
240
+ },
241
+ ["miniapp-share" /* MiniAppShare */]: () => {
242
+ },
243
+ ["miniapp-microphone" /* MiniAppMicrophone */]: () => {
244
+ },
245
+ ["miniapp-chat" /* MiniAppChat */]: () => {
246
+ }
247
+ };
248
+ }
249
+ subscribe(event, handler) {
250
+ this.listeners[event] = handler;
251
+ }
252
+ unsubscribe(event) {
253
+ delete this.listeners[event];
254
+ }
255
+ trigger(event, payload) {
256
+ if (!this.listeners[event]) {
257
+ console.error(
258
+ `No handler for event ${event}, payload: ${JSON.stringify(payload)}`
259
+ );
260
+ return;
261
+ }
262
+ this.listeners[event](payload);
263
+ }
264
+ };
265
+
266
+ // src/commands/fallback.ts
267
+ async function executeWithFallback(options) {
268
+ const {
269
+ command,
270
+ nativeExecutor,
271
+ wagmiFallback,
272
+ customFallback,
273
+ requiresFallback = false
274
+ } = options;
275
+ const inWorldApp = isInWorldApp();
276
+ const commandAvailable = isCommandAvailable(command);
277
+ let nativeError;
278
+ if (inWorldApp && commandAvailable) {
279
+ try {
280
+ const data = await nativeExecutor();
281
+ return { data, executedWith: "minikit" };
282
+ } catch (error) {
283
+ nativeError = error;
284
+ console.warn(`Native ${command} failed, attempting fallback:`, error);
285
+ }
286
+ }
287
+ if (!inWorldApp && wagmiFallback) {
288
+ try {
289
+ const data = await wagmiFallback();
290
+ return { data, executedWith: "wagmi" };
291
+ } catch (error) {
292
+ console.warn(`Wagmi fallback for ${command} failed:`, error);
293
+ }
294
+ }
295
+ if (!inWorldApp && customFallback) {
296
+ const data = await customFallback();
297
+ return { data, executedWith: "fallback" };
298
+ }
299
+ if (nativeError) {
300
+ throw nativeError;
301
+ }
302
+ if (requiresFallback && !inWorldApp) {
303
+ throw new FallbackRequiredError(command);
304
+ }
305
+ throw new CommandUnavailableError(command, determineFallbackReason(command));
306
+ }
307
+ function determineFallbackReason(command) {
308
+ if (!isInWorldApp()) {
309
+ return "notInWorldApp";
310
+ }
311
+ if (!isCommandAvailable(command)) {
312
+ return "oldAppVersion";
313
+ }
314
+ return "commandNotSupported";
315
+ }
316
+
317
+ // src/commands/attestation/types.ts
318
+ var AttestationErrorCodes = /* @__PURE__ */ ((AttestationErrorCodes2) => {
319
+ AttestationErrorCodes2["Unauthorized"] = "unauthorized";
320
+ AttestationErrorCodes2["AttestationFailed"] = "attestation_failed";
321
+ AttestationErrorCodes2["IntegrityFailed"] = "integrity_failed";
322
+ AttestationErrorCodes2["InvalidInput"] = "invalid_input";
323
+ AttestationErrorCodes2["UnsupportedVersion"] = "unsupported_version";
324
+ return AttestationErrorCodes2;
325
+ })(AttestationErrorCodes || {});
326
+ var AttestationError = class extends Error {
327
+ constructor(error_code) {
328
+ super(`Attestation failed: ${error_code}`);
329
+ this.error_code = error_code;
330
+ this.name = "AttestationError";
331
+ }
332
+ };
333
+
334
+ // src/commands/attestation/index.ts
335
+ async function attestation(options, ctx) {
336
+ const result = await executeWithFallback({
337
+ command: "attestation" /* Attestation */,
338
+ nativeExecutor: () => nativeAttestation(options, ctx),
339
+ customFallback: options.fallback
340
+ });
341
+ if (result.executedWith === "fallback") {
342
+ return { executedWith: "fallback", data: result.data };
343
+ }
344
+ return {
345
+ executedWith: "minikit",
346
+ data: result.data
347
+ };
348
+ }
349
+ async function nativeAttestation(options, ctx) {
350
+ if (!ctx) {
351
+ ctx = { events: new EventManager(), state: { deviceProperties: {} } };
352
+ }
353
+ if (typeof window === "undefined" || !isCommandAvailable("attestation" /* Attestation */)) {
354
+ throw new Error(
355
+ "'attestation' command is unavailable. Check MiniKit.install() or update the app version"
356
+ );
357
+ }
358
+ if (!options.requestHash || options.requestHash.length === 0) {
359
+ throw new Error("'attestation' command requires a non-empty requestHash");
360
+ }
361
+ const payload = await new Promise(
362
+ (resolve, reject) => {
363
+ try {
364
+ ctx.events.subscribe("miniapp-attestation" /* MiniAppAttestation */, (response) => {
365
+ ctx.events.unsubscribe("miniapp-attestation" /* MiniAppAttestation */);
366
+ resolve(response);
367
+ });
368
+ sendMiniKitEvent({
369
+ command: "attestation" /* Attestation */,
370
+ version: COMMAND_VERSIONS["attestation" /* Attestation */],
371
+ payload: {
372
+ request_hash: options.requestHash
373
+ }
374
+ });
375
+ } catch (error) {
376
+ reject(error);
377
+ }
378
+ }
379
+ );
380
+ if (payload.status === "error") {
381
+ throw new AttestationError(payload.error_code);
382
+ }
383
+ return payload;
384
+ }
385
+
386
+ // src/commands/chat/types.ts
387
+ var ChatErrorCodes = /* @__PURE__ */ ((ChatErrorCodes2) => {
388
+ ChatErrorCodes2["UserRejected"] = "user_rejected";
389
+ ChatErrorCodes2["SendFailed"] = "send_failed";
390
+ ChatErrorCodes2["GenericError"] = "generic_error";
391
+ return ChatErrorCodes2;
392
+ })(ChatErrorCodes || {});
393
+ var ChatError = class extends Error {
394
+ constructor(error_code) {
395
+ super(`Chat failed: ${error_code}`);
396
+ this.error_code = error_code;
397
+ this.name = "ChatError";
398
+ }
399
+ };
400
+
401
+ // src/commands/chat/index.ts
402
+ async function chat(options, ctx) {
403
+ const result = await executeWithFallback({
404
+ command: "chat" /* Chat */,
405
+ nativeExecutor: () => nativeChat(options, ctx),
406
+ customFallback: options.fallback
407
+ });
408
+ if (result.executedWith === "fallback") {
409
+ return { executedWith: "fallback", data: result.data };
410
+ }
411
+ return {
412
+ executedWith: "minikit",
413
+ data: result.data
414
+ };
415
+ }
416
+ async function nativeChat(options, ctx) {
417
+ if (!ctx) {
418
+ ctx = { events: new EventManager(), state: { deviceProperties: {} } };
419
+ }
420
+ if (typeof window === "undefined" || !isCommandAvailable("chat" /* Chat */)) {
421
+ throw new Error(
422
+ "'chat' command is unavailable. Check MiniKit.install() or update the app version"
423
+ );
424
+ }
425
+ const payloadInput = {
426
+ message: options.message,
427
+ to: options.to
428
+ };
429
+ if (payloadInput.message.length === 0) {
430
+ throw new Error("'chat' command requires a non-empty message");
431
+ }
432
+ const payload = await new Promise((resolve, reject) => {
433
+ try {
434
+ ctx.events.subscribe("miniapp-chat" /* MiniAppChat */, (response) => {
435
+ ctx.events.unsubscribe("miniapp-chat" /* MiniAppChat */);
436
+ resolve(response);
437
+ });
438
+ sendMiniKitEvent({
439
+ command: "chat" /* Chat */,
440
+ version: COMMAND_VERSIONS["chat" /* Chat */],
441
+ payload: payloadInput
442
+ });
443
+ } catch (error) {
444
+ reject(error);
445
+ }
446
+ });
447
+ if (payload.status === "error") {
448
+ throw new ChatError(payload.error_code);
449
+ }
450
+ return payload;
451
+ }
452
+
453
+ // src/commands/close-miniapp/index.ts
454
+ async function closeMiniApp(options = {}, _ctx) {
455
+ const result = await executeWithFallback({
456
+ command: "close-miniapp" /* CloseMiniApp */,
457
+ nativeExecutor: () => nativeCloseMiniApp(),
458
+ customFallback: options.fallback
459
+ });
460
+ if (result.executedWith === "fallback") {
461
+ return { executedWith: "fallback", data: result.data };
462
+ }
463
+ return {
464
+ executedWith: "minikit",
465
+ data: result.data
466
+ };
467
+ }
468
+ async function nativeCloseMiniApp() {
469
+ if (typeof window === "undefined" || !isCommandAvailable("close-miniapp" /* CloseMiniApp */)) {
470
+ throw new Error(
471
+ "'closeMiniApp' command is unavailable. Check MiniKit.install() or update the app version"
472
+ );
473
+ }
474
+ sendMiniKitEvent({
475
+ command: "close-miniapp" /* CloseMiniApp */,
476
+ version: COMMAND_VERSIONS["close-miniapp" /* CloseMiniApp */],
477
+ payload: {}
478
+ });
479
+ return {
480
+ status: "success",
481
+ version: COMMAND_VERSIONS["close-miniapp" /* CloseMiniApp */]
482
+ };
483
+ }
484
+
485
+ // src/commands/get-permissions/types.ts
486
+ var GetPermissionsErrorCodes = /* @__PURE__ */ ((GetPermissionsErrorCodes2) => {
487
+ GetPermissionsErrorCodes2["GenericError"] = "generic_error";
488
+ return GetPermissionsErrorCodes2;
489
+ })(GetPermissionsErrorCodes || {});
490
+ var Permission = /* @__PURE__ */ ((Permission2) => {
491
+ Permission2["Notifications"] = "notifications";
492
+ Permission2["Contacts"] = "contacts";
493
+ Permission2["Microphone"] = "microphone";
494
+ return Permission2;
495
+ })(Permission || {});
496
+ var GetPermissionsError = class extends Error {
497
+ constructor(error_code) {
498
+ super(`Get permissions failed: ${error_code}`);
499
+ this.error_code = error_code;
500
+ this.name = "GetPermissionsError";
501
+ }
502
+ };
503
+
504
+ // src/commands/get-permissions/index.ts
505
+ async function getPermissions(options, ctx) {
506
+ const resolvedOptions = options ?? {};
507
+ const result = await executeWithFallback({
508
+ command: "get-permissions" /* GetPermissions */,
509
+ nativeExecutor: () => nativeGetPermissions(ctx),
510
+ customFallback: resolvedOptions.fallback
511
+ });
512
+ if (result.executedWith === "fallback") {
513
+ return { executedWith: "fallback", data: result.data };
514
+ }
515
+ return {
516
+ executedWith: "minikit",
517
+ data: result.data
518
+ };
519
+ }
520
+ async function nativeGetPermissions(ctx) {
521
+ if (!ctx) {
522
+ ctx = { events: new EventManager(), state: { deviceProperties: {} } };
523
+ }
524
+ if (typeof window === "undefined" || !isCommandAvailable("get-permissions" /* GetPermissions */)) {
525
+ throw new Error(
526
+ "'getPermissions' command is unavailable. Check MiniKit.install() or update the app version"
527
+ );
528
+ }
529
+ const payload = await new Promise(
530
+ (resolve, reject) => {
531
+ try {
532
+ ctx.events.subscribe("miniapp-get-permissions" /* MiniAppGetPermissions */, (response) => {
533
+ ctx.events.unsubscribe("miniapp-get-permissions" /* MiniAppGetPermissions */);
534
+ resolve(response);
535
+ });
536
+ sendMiniKitEvent({
537
+ command: "get-permissions" /* GetPermissions */,
538
+ version: COMMAND_VERSIONS["get-permissions" /* GetPermissions */],
539
+ payload: {}
540
+ });
541
+ } catch (error) {
542
+ reject(error);
543
+ }
544
+ }
545
+ );
546
+ if (payload.status === "error") {
547
+ throw new GetPermissionsError(payload.error_code);
548
+ }
549
+ return payload;
550
+ }
551
+
552
+ // src/commands/pay/types.ts
553
+ var Tokens = /* @__PURE__ */ ((Tokens2) => {
554
+ Tokens2["USDC"] = "USDCE";
555
+ Tokens2["WLD"] = "WLD";
556
+ Tokens2["WARS"] = "WARS";
557
+ Tokens2["WCOP"] = "WCOP";
558
+ Tokens2["WMXN"] = "WMXN";
559
+ Tokens2["WBRL"] = "WBRL";
560
+ Tokens2["WPEN"] = "WPEN";
561
+ Tokens2["WCLP"] = "WCLP";
562
+ Tokens2["EURC"] = "EURC";
563
+ return Tokens2;
564
+ })(Tokens || {});
565
+ var TokenDecimals = {
566
+ ["USDCE" /* USDC */]: 6,
567
+ ["WLD" /* WLD */]: 18,
568
+ ["WARS" /* WARS */]: 18,
569
+ ["WCOP" /* WCOP */]: 18,
570
+ ["WMXN" /* WMXN */]: 18,
571
+ ["WBRL" /* WBRL */]: 18,
572
+ ["WPEN" /* WPEN */]: 18,
573
+ ["WCLP" /* WCLP */]: 18,
574
+ ["EURC" /* EURC */]: 6
575
+ };
576
+ var Network = /* @__PURE__ */ ((Network2) => {
577
+ Network2["WorldChain"] = "worldchain";
578
+ return Network2;
579
+ })(Network || {});
580
+ var PaymentErrorCodes = /* @__PURE__ */ ((PaymentErrorCodes2) => {
581
+ PaymentErrorCodes2["InputError"] = "input_error";
582
+ PaymentErrorCodes2["UserRejected"] = "user_rejected";
583
+ PaymentErrorCodes2["PaymentRejected"] = "payment_rejected";
584
+ PaymentErrorCodes2["InvalidReceiver"] = "invalid_receiver";
585
+ PaymentErrorCodes2["InsufficientBalance"] = "insufficient_balance";
586
+ PaymentErrorCodes2["TransactionFailed"] = "transaction_failed";
587
+ PaymentErrorCodes2["GenericError"] = "generic_error";
588
+ PaymentErrorCodes2["UserBlocked"] = "user_blocked";
589
+ return PaymentErrorCodes2;
590
+ })(PaymentErrorCodes || {});
591
+ var PaymentErrorMessage = {
592
+ ["input_error" /* InputError */]: "There was a problem with this request. Please try again or contact the app owner.",
593
+ ["user_rejected" /* UserRejected */]: "You have cancelled the payment in World App.",
594
+ ["payment_rejected" /* PaymentRejected */]: "You've cancelled the payment in World App.",
595
+ ["invalid_receiver" /* InvalidReceiver */]: "The receiver address is invalid. Please contact the app owner.",
596
+ ["insufficient_balance" /* InsufficientBalance */]: "You do not have enough balance to complete this transaction.",
597
+ ["transaction_failed" /* TransactionFailed */]: "The transaction failed. Please try again.",
598
+ ["generic_error" /* GenericError */]: "Something unexpected went wrong. Please try again.",
599
+ ["user_blocked" /* UserBlocked */]: "User's region is blocked from making payments."
600
+ };
601
+ var PayError = class extends Error {
602
+ constructor(code) {
603
+ super(`Payment failed: ${code}`);
604
+ this.name = "PayError";
605
+ this.code = code;
606
+ }
607
+ };
608
+
609
+ // src/commands/pay/validate.ts
610
+ var tokenToDecimals = (amount, token) => {
611
+ const decimals = TokenDecimals[token];
612
+ if (decimals === void 0) {
613
+ throw new Error(`Invalid token: ${token}`);
614
+ }
615
+ const factor = 10 ** decimals;
616
+ const result = amount * factor;
617
+ if (!Number.isInteger(result)) {
618
+ throw new Error(`The resulting amount is not a whole number: ${result}`);
619
+ }
620
+ return result;
621
+ };
622
+ var validatePaymentPayload = (payload) => {
623
+ if (payload.tokens.some(
624
+ (token) => token.symbol == "USDCE" /* USDC */ && parseFloat(token.token_amount) < 0.1
625
+ )) {
626
+ console.error("USDC amount should be greater than $0.1");
627
+ return false;
628
+ }
629
+ if (payload.reference.length > 36) {
630
+ console.error("Reference must not exceed 36 characters");
631
+ return false;
632
+ }
633
+ if (typeof payload.reference !== "string") {
634
+ throw new Error("Reference must be a string");
635
+ }
636
+ return true;
637
+ };
638
+
639
+ // src/commands/pay/index.ts
640
+ async function pay(options, ctx) {
641
+ const result = await executeWithFallback({
642
+ command: "pay" /* Pay */,
643
+ nativeExecutor: () => nativePay(options, ctx),
644
+ // No Wagmi fallback - pay is native only
645
+ customFallback: options.fallback
646
+ });
647
+ if (result.executedWith === "fallback") {
648
+ return { executedWith: "fallback", data: result.data };
649
+ }
650
+ return { executedWith: "minikit", data: result.data };
651
+ }
652
+ async function nativePay(options, ctx) {
653
+ if (!ctx) {
654
+ ctx = { events: new EventManager(), state: { deviceProperties: {} } };
655
+ }
656
+ if (typeof window === "undefined" || !isCommandAvailable("pay" /* Pay */)) {
657
+ throw new Error(
658
+ "'pay' command is unavailable. Check MiniKit.install() or update the app version"
659
+ );
660
+ }
661
+ const input = {
662
+ reference: options.reference,
663
+ to: options.to,
664
+ tokens: options.tokens,
665
+ description: options.description,
666
+ network: options.network
667
+ };
668
+ if (!validatePaymentPayload(input)) {
669
+ throw new Error("Invalid payment payload");
670
+ }
671
+ const eventPayload = {
672
+ ...input,
673
+ network: "worldchain" /* WorldChain */
674
+ };
675
+ const finalPayload = await new Promise(
676
+ (resolve, reject) => {
677
+ try {
678
+ ctx.events.subscribe("miniapp-payment" /* MiniAppPayment */, (response) => {
679
+ ctx.events.unsubscribe("miniapp-payment" /* MiniAppPayment */);
680
+ resolve(response);
681
+ });
682
+ sendMiniKitEvent({
683
+ command: "pay" /* Pay */,
684
+ version: COMMAND_VERSIONS["pay" /* Pay */],
685
+ payload: eventPayload
686
+ });
687
+ } catch (error) {
688
+ reject(error);
689
+ }
690
+ }
691
+ );
692
+ if (finalPayload.status === "error") {
693
+ throw new PayError(finalPayload.error_code);
694
+ }
695
+ return {
696
+ transactionId: finalPayload.transaction_id,
697
+ reference: finalPayload.reference,
698
+ from: finalPayload.from,
699
+ chain: finalPayload.chain,
700
+ timestamp: finalPayload.timestamp
701
+ };
702
+ }
703
+
704
+ // src/commands/request-permission/types.ts
705
+ var RequestPermissionErrorCodes = /* @__PURE__ */ ((RequestPermissionErrorCodes2) => {
706
+ RequestPermissionErrorCodes2["UserRejected"] = "user_rejected";
707
+ RequestPermissionErrorCodes2["GenericError"] = "generic_error";
708
+ RequestPermissionErrorCodes2["AlreadyRequested"] = "already_requested";
709
+ RequestPermissionErrorCodes2["PermissionDisabled"] = "permission_disabled";
710
+ RequestPermissionErrorCodes2["AlreadyGranted"] = "already_granted";
711
+ RequestPermissionErrorCodes2["UnsupportedPermission"] = "unsupported_permission";
712
+ return RequestPermissionErrorCodes2;
713
+ })(RequestPermissionErrorCodes || {});
714
+ var RequestPermissionError = class extends Error {
715
+ constructor(error_code) {
716
+ super(`Request permission failed: ${error_code}`);
717
+ this.error_code = error_code;
718
+ this.name = "RequestPermissionError";
719
+ }
720
+ };
721
+
722
+ // src/commands/request-permission/index.ts
723
+ async function requestPermission(options, ctx) {
724
+ const result = await executeWithFallback({
725
+ command: "request-permission" /* RequestPermission */,
726
+ nativeExecutor: () => nativeRequestPermission(options, ctx),
727
+ customFallback: options.fallback
728
+ });
729
+ if (result.executedWith === "fallback") {
730
+ return { executedWith: "fallback", data: result.data };
731
+ }
732
+ return {
733
+ executedWith: "minikit",
734
+ data: result.data
735
+ };
736
+ }
737
+ async function nativeRequestPermission(options, ctx) {
738
+ if (!ctx) {
739
+ ctx = { events: new EventManager(), state: { deviceProperties: {} } };
740
+ }
741
+ if (typeof window === "undefined" || !isCommandAvailable("request-permission" /* RequestPermission */)) {
742
+ throw new Error(
743
+ "'requestPermission' command is unavailable. Check MiniKit.install() or update the app version"
744
+ );
745
+ }
746
+ const payload = await new Promise(
747
+ (resolve, reject) => {
748
+ try {
749
+ ctx.events.subscribe("miniapp-request-permission" /* MiniAppRequestPermission */, (response) => {
750
+ ctx.events.unsubscribe("miniapp-request-permission" /* MiniAppRequestPermission */);
751
+ resolve(response);
752
+ });
753
+ sendMiniKitEvent({
754
+ command: "request-permission" /* RequestPermission */,
755
+ version: COMMAND_VERSIONS["request-permission" /* RequestPermission */],
756
+ payload: { permission: options.permission }
757
+ });
758
+ } catch (error) {
759
+ reject(error);
760
+ }
761
+ }
762
+ );
763
+ if (payload.status === "error") {
764
+ throw new RequestPermissionError(payload.error_code);
765
+ }
766
+ return payload;
767
+ }
768
+
769
+ // src/commands/send-haptic-feedback/types.ts
770
+ var SendHapticFeedbackErrorCodes = /* @__PURE__ */ ((SendHapticFeedbackErrorCodes2) => {
771
+ SendHapticFeedbackErrorCodes2["GenericError"] = "generic_error";
772
+ SendHapticFeedbackErrorCodes2["UserRejected"] = "user_rejected";
773
+ return SendHapticFeedbackErrorCodes2;
774
+ })(SendHapticFeedbackErrorCodes || {});
775
+ var SendHapticFeedbackError = class extends Error {
776
+ constructor(error_code) {
777
+ super(`Send haptic feedback failed: ${error_code}`);
778
+ this.error_code = error_code;
779
+ this.name = "SendHapticFeedbackError";
780
+ }
781
+ };
782
+
783
+ // src/commands/send-haptic-feedback/index.ts
784
+ async function sendHapticFeedback(options, ctx) {
785
+ const result = await executeWithFallback({
786
+ command: "send-haptic-feedback" /* SendHapticFeedback */,
787
+ nativeExecutor: () => nativeSendHapticFeedback(options, ctx),
788
+ customFallback: options.fallback
789
+ });
790
+ if (result.executedWith === "fallback") {
791
+ return { executedWith: "fallback", data: result.data };
792
+ }
793
+ return {
794
+ executedWith: "minikit",
795
+ data: result.data
796
+ };
797
+ }
798
+ async function nativeSendHapticFeedback(options, ctx) {
799
+ if (!ctx) {
800
+ ctx = { events: new EventManager(), state: { deviceProperties: {} } };
801
+ }
802
+ if (typeof window === "undefined" || !isCommandAvailable("send-haptic-feedback" /* SendHapticFeedback */)) {
803
+ throw new Error(
804
+ "'sendHapticFeedback' command is unavailable. Check MiniKit.install() or update the app version"
805
+ );
806
+ }
807
+ const payloadInput = options.hapticsType === "selection-changed" ? { hapticsType: "selection-changed" } : options.hapticsType === "impact" ? {
808
+ hapticsType: "impact",
809
+ style: options.style
810
+ } : {
811
+ hapticsType: "notification",
812
+ style: options.style
813
+ };
814
+ const payload = await new Promise(
815
+ (resolve, reject) => {
816
+ try {
817
+ ctx.events.subscribe("miniapp-send-haptic-feedback" /* MiniAppSendHapticFeedback */, (response) => {
818
+ ctx.events.unsubscribe("miniapp-send-haptic-feedback" /* MiniAppSendHapticFeedback */);
819
+ resolve(response);
820
+ });
821
+ sendMiniKitEvent({
822
+ command: "send-haptic-feedback" /* SendHapticFeedback */,
823
+ version: COMMAND_VERSIONS["send-haptic-feedback" /* SendHapticFeedback */],
824
+ payload: payloadInput
825
+ });
826
+ } catch (error) {
827
+ reject(error);
828
+ }
829
+ }
830
+ );
831
+ if (payload.status === "error") {
832
+ throw new SendHapticFeedbackError(payload.error_code);
833
+ }
834
+ return payload;
835
+ }
836
+
837
+ // src/commands/fallback-adapter-registry.ts
838
+ var FALLBACK_ADAPTER_KEY = "__minikit_fallback_adapter__";
839
+ function getFallbackAdapter() {
840
+ return globalThis[FALLBACK_ADAPTER_KEY];
841
+ }
842
+
843
+ // src/commands/send-transaction/types.ts
844
+ var SendTransactionErrorCodes = /* @__PURE__ */ ((SendTransactionErrorCodes2) => {
845
+ SendTransactionErrorCodes2["InvalidOperation"] = "invalid_operation";
846
+ SendTransactionErrorCodes2["UserRejected"] = "user_rejected";
847
+ SendTransactionErrorCodes2["InputError"] = "input_error";
848
+ SendTransactionErrorCodes2["SimulationFailed"] = "simulation_failed";
849
+ SendTransactionErrorCodes2["TransactionFailed"] = "transaction_failed";
850
+ SendTransactionErrorCodes2["GenericError"] = "generic_error";
851
+ SendTransactionErrorCodes2["DisallowedOperation"] = "disallowed_operation";
852
+ SendTransactionErrorCodes2["ValidationError"] = "validation_error";
853
+ SendTransactionErrorCodes2["InvalidContract"] = "invalid_contract";
854
+ SendTransactionErrorCodes2["MaliciousOperation"] = "malicious_operation";
855
+ SendTransactionErrorCodes2["DailyTxLimitReached"] = "daily_tx_limit_reached";
856
+ SendTransactionErrorCodes2["PermittedAmountExceedsSlippage"] = "permitted_amount_exceeds_slippage";
857
+ SendTransactionErrorCodes2["PermittedAmountNotFound"] = "permitted_amount_not_found";
858
+ return SendTransactionErrorCodes2;
859
+ })(SendTransactionErrorCodes || {});
860
+ var SendTransactionErrorMessage = {
861
+ ["invalid_operation" /* InvalidOperation */]: "Transaction included an operation that was invalid",
862
+ ["user_rejected" /* UserRejected */]: "User rejected the request.",
863
+ ["input_error" /* InputError */]: "Invalid payload.",
864
+ ["simulation_failed" /* SimulationFailed */]: "The transaction simulation failed.",
865
+ ["validation_error" /* ValidationError */]: "The transaction validation failed. Please try again.",
866
+ ["transaction_failed" /* TransactionFailed */]: "The transaction failed. Please try again later.",
867
+ ["generic_error" /* GenericError */]: "Something unexpected went wrong. Please try again.",
868
+ ["disallowed_operation" /* DisallowedOperation */]: "The operation requested is not allowed. Please refer to the docs.",
869
+ ["invalid_contract" /* InvalidContract */]: "The contract address is not allowed for your application. Please check your developer portal configurations",
870
+ ["malicious_operation" /* MaliciousOperation */]: "The operation requested is considered malicious.",
871
+ ["daily_tx_limit_reached" /* DailyTxLimitReached */]: "Daily transaction limit reached. Max 100 transactions per day. Wait until the next day.",
872
+ ["permitted_amount_exceeds_slippage" /* PermittedAmountExceedsSlippage */]: "Permitted amount exceeds slippage. You must spend at least 90% of the permitted amount.",
873
+ ["permitted_amount_not_found" /* PermittedAmountNotFound */]: "Permitted amount not found in permit2 payload."
874
+ };
875
+ var WORLD_APP_FEATURES = {
876
+ batch: true,
877
+ permit2: true,
878
+ gasSponsorship: true
879
+ };
880
+ var WEB_FEATURES = {
881
+ batch: false,
882
+ permit2: false,
883
+ gasSponsorship: false
884
+ };
885
+ var SendTransactionError = class extends Error {
886
+ constructor(code, details) {
887
+ super(`Transaction failed: ${code}`);
888
+ this.name = "SendTransactionError";
889
+ this.code = code;
890
+ this.details = details;
891
+ }
892
+ };
893
+
894
+ // src/commands/send-transaction/validate.ts
895
+ var isValidHex = (str) => {
896
+ return /^0x[0-9A-Fa-f]+$/.test(str);
897
+ };
898
+ var processPayload = (payload) => {
899
+ if (typeof payload === "boolean" || typeof payload === "string" || payload === null || payload === void 0) {
900
+ return payload;
901
+ }
902
+ if (typeof payload === "number" || typeof payload === "bigint") {
903
+ return String(payload);
904
+ }
905
+ if (Array.isArray(payload)) {
906
+ return payload.map((value) => processPayload(value));
907
+ }
908
+ if (typeof payload === "object") {
909
+ const result = { ...payload };
910
+ if ("chainId" in result && result.chainId !== void 0) {
911
+ if (typeof result.chainId === "string") {
912
+ const parsed = Number(result.chainId);
913
+ if (Number.isFinite(parsed)) {
914
+ result.chainId = parsed;
915
+ }
916
+ } else if (typeof result.chainId === "bigint") {
917
+ const parsed = Number(result.chainId);
918
+ if (!Number.isSafeInteger(parsed)) {
919
+ throw new Error(`Invalid chainId: ${String(result.chainId)}`);
920
+ }
921
+ result.chainId = parsed;
922
+ }
923
+ }
924
+ if ("value" in result && result.value !== void 0) {
925
+ if (typeof result.value !== "string") {
926
+ result.value = String(result.value);
927
+ }
928
+ if (!isValidHex(result.value)) {
929
+ console.error(
930
+ "Transaction value must be a valid hex string",
931
+ result.value
932
+ );
933
+ throw new Error(
934
+ `Transaction value must be a valid hex string: ${result.value}`
935
+ );
936
+ }
937
+ }
938
+ for (const key in result) {
939
+ if (Object.prototype.hasOwnProperty.call(result, key)) {
940
+ if (key === "chainId") continue;
941
+ result[key] = processPayload(result[key]);
942
+ }
943
+ }
944
+ return result;
945
+ }
946
+ return payload;
947
+ };
948
+ var validateSendTransactionPayload = (payload) => {
949
+ return processPayload(payload);
950
+ };
951
+
952
+ // src/commands/send-transaction/index.ts
953
+ var WORLD_CHAIN_ID = 480;
954
+ var WAGMI_MULTI_TX_ERROR_MESSAGE = "Wagmi fallback does not support multi-transaction execution. Pass a single transaction, run inside World App for batching, or provide a custom fallback.";
955
+ function resolveChainId(options) {
956
+ return options.chainId;
957
+ }
958
+ function resolveTransactions(options) {
959
+ if (options.transactions.length === 0) {
960
+ throw new SendTransactionError("input_error" /* InputError */, {
961
+ reason: "At least one transaction is required. Use `transactions: [{ to, data, value }]`."
962
+ });
963
+ }
964
+ return options.transactions;
965
+ }
966
+ function normalizeSendTransactionOptions(options) {
967
+ const chainId = resolveChainId(options);
968
+ if (chainId !== WORLD_CHAIN_ID) {
969
+ throw new SendTransactionError("invalid_operation" /* InvalidOperation */, {
970
+ reason: `World App only supports World Chain (chainId: ${WORLD_CHAIN_ID})`
971
+ });
972
+ }
973
+ return {
974
+ transactions: resolveTransactions(options),
975
+ chainId
976
+ };
977
+ }
978
+ async function sendTransaction(options, ctx) {
979
+ const normalizedOptions = normalizeSendTransactionOptions(options);
980
+ const fallbackAdapter = getFallbackAdapter();
981
+ const isWagmiFallbackPath = !isInWorldApp() && Boolean(fallbackAdapter?.sendTransaction);
982
+ if (isWagmiFallbackPath && normalizedOptions.transactions.length > 1 && !options.fallback) {
983
+ throw new SendTransactionError("invalid_operation" /* InvalidOperation */, {
984
+ reason: WAGMI_MULTI_TX_ERROR_MESSAGE
985
+ });
986
+ }
987
+ const result = await executeWithFallback({
988
+ command: "send-transaction" /* SendTransaction */,
989
+ nativeExecutor: () => nativeSendTransaction(normalizedOptions, ctx),
990
+ wagmiFallback: fallbackAdapter?.sendTransaction ? () => adapterSendTransactionFallback(normalizedOptions) : void 0,
991
+ customFallback: options.fallback
992
+ });
993
+ if (result.executedWith === "fallback") {
994
+ return { executedWith: "fallback", data: result.data };
995
+ }
996
+ if (result.executedWith === "wagmi") {
997
+ return {
998
+ executedWith: "wagmi",
999
+ data: result.data
1000
+ };
1001
+ }
1002
+ return {
1003
+ executedWith: "minikit",
1004
+ data: result.data
1005
+ };
1006
+ }
1007
+ async function nativeSendTransaction(options, ctx) {
1008
+ if (!ctx) {
1009
+ ctx = { events: new EventManager(), state: { deviceProperties: {} } };
1010
+ }
1011
+ if (typeof window === "undefined" || !isCommandAvailable("send-transaction" /* SendTransaction */)) {
1012
+ throw new Error(
1013
+ "'sendTransaction' command is unavailable. Check MiniKit.install() or update the app version"
1014
+ );
1015
+ }
1016
+ if (options.chainId !== WORLD_CHAIN_ID) {
1017
+ throw new Error(
1018
+ `World App only supports World Chain (chainId: ${WORLD_CHAIN_ID})`
1019
+ );
1020
+ }
1021
+ const commandInput = window.WorldApp?.supported_commands.find(
1022
+ (command) => command.name === "send-transaction" /* SendTransaction */
1023
+ );
1024
+ if (commandInput && !commandInput.supported_versions.includes(
1025
+ COMMAND_VERSIONS["send-transaction" /* SendTransaction */]
1026
+ )) {
1027
+ throw new CommandUnavailableError("send-transaction" /* SendTransaction */, "oldAppVersion");
1028
+ }
1029
+ const input = {
1030
+ transactions: options.transactions,
1031
+ chainId: options.chainId
1032
+ };
1033
+ const validatedPayload = validateSendTransactionPayload(input);
1034
+ const finalPayload = await new Promise(
1035
+ (resolve, reject) => {
1036
+ try {
1037
+ ctx.events.subscribe("miniapp-send-transaction" /* MiniAppSendTransaction */, (response) => {
1038
+ ctx.events.unsubscribe("miniapp-send-transaction" /* MiniAppSendTransaction */);
1039
+ resolve(response);
1040
+ });
1041
+ sendMiniKitEvent({
1042
+ command: "send-transaction" /* SendTransaction */,
1043
+ version: COMMAND_VERSIONS["send-transaction" /* SendTransaction */],
1044
+ payload: validatedPayload
1045
+ });
1046
+ } catch (error) {
1047
+ reject(error);
1048
+ }
1049
+ }
1050
+ );
1051
+ if (finalPayload.status === "error") {
1052
+ throw new SendTransactionError(
1053
+ finalPayload.error_code,
1054
+ finalPayload.details
1055
+ );
1056
+ }
1057
+ const successPayload = finalPayload;
1058
+ return {
1059
+ userOpHash: String(successPayload.userOpHash ?? ""),
1060
+ status: finalPayload.status,
1061
+ version: finalPayload.version,
1062
+ from: String(successPayload.from ?? ""),
1063
+ timestamp: String(successPayload.timestamp ?? (/* @__PURE__ */ new Date()).toISOString())
1064
+ };
1065
+ }
1066
+ async function adapterSendTransactionFallback(options) {
1067
+ if (options.transactions.length > 1) {
1068
+ throw new Error(WAGMI_MULTI_TX_ERROR_MESSAGE);
1069
+ }
1070
+ const firstTransaction = options.transactions[0];
1071
+ if (!firstTransaction) {
1072
+ throw new Error("At least one transaction is required");
1073
+ }
1074
+ const fallbackAdapter = getFallbackAdapter();
1075
+ if (!fallbackAdapter?.sendTransaction) {
1076
+ throw new Error("Fallback adapter is not registered.");
1077
+ }
1078
+ const result = await fallbackAdapter.sendTransaction({
1079
+ transaction: {
1080
+ address: firstTransaction.to,
1081
+ data: firstTransaction.data,
1082
+ value: firstTransaction.value
1083
+ },
1084
+ chainId: options.chainId
1085
+ });
1086
+ return {
1087
+ userOpHash: result.transactionHash,
1088
+ status: "success",
1089
+ version: COMMAND_VERSIONS["send-transaction" /* SendTransaction */],
1090
+ from: "",
1091
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
1092
+ };
1093
+ }
1094
+
1095
+ // src/commands/share/format.ts
1096
+ var MAX_FILES = 10;
1097
+ var MAX_TOTAL_SIZE_MB = 50;
1098
+ var MAX_TOTAL_SIZE_BYTES = MAX_TOTAL_SIZE_MB * 1024 * 1024;
1099
+ var processFile = async (file) => {
1100
+ const buffer = await file.arrayBuffer();
1101
+ const uint8Array = new Uint8Array(buffer);
1102
+ let binaryString = "";
1103
+ const K_CHUNK_SIZE = 32768;
1104
+ for (let i = 0; i < uint8Array.length; i += K_CHUNK_SIZE) {
1105
+ const chunk = uint8Array.subarray(
1106
+ i,
1107
+ Math.min(i + K_CHUNK_SIZE, uint8Array.length)
1108
+ );
1109
+ binaryString += String.fromCharCode.apply(
1110
+ null,
1111
+ Array.from(chunk)
1112
+ // Convert Uint8Array chunk to number[]
1113
+ );
1114
+ }
1115
+ const base64Data = btoa(binaryString);
1116
+ return {
1117
+ name: file.name,
1118
+ type: file.type,
1119
+ data: base64Data
1120
+ };
1121
+ };
1122
+ var formatShareInput = async (input) => {
1123
+ if (!input.files) {
1124
+ return {
1125
+ title: input.title,
1126
+ text: input.text,
1127
+ url: input.url
1128
+ };
1129
+ }
1130
+ if (!Array.isArray(input.files)) {
1131
+ throw new Error('The "files" property must be an array.');
1132
+ }
1133
+ if (input.files.length === 0) {
1134
+ } else {
1135
+ if (input.files.length > MAX_FILES) {
1136
+ throw new Error(`Cannot share more than ${MAX_FILES} files.`);
1137
+ }
1138
+ let totalSize = 0;
1139
+ for (const file of input.files) {
1140
+ if (!(file instanceof File)) {
1141
+ throw new Error(
1142
+ `Each item in the 'files' array must be a File object. Received: ${typeof file}`
1143
+ );
1144
+ }
1145
+ totalSize += file.size;
1146
+ }
1147
+ if (totalSize > MAX_TOTAL_SIZE_BYTES) {
1148
+ throw new Error(`Total file size cannot exceed ${MAX_TOTAL_SIZE_MB}MB.`);
1149
+ }
1150
+ }
1151
+ const fileProcessingPromises = input.files.map((file) => processFile(file));
1152
+ const processedFiles = await Promise.all(fileProcessingPromises);
1153
+ return {
1154
+ files: processedFiles,
1155
+ title: input.title,
1156
+ text: input.text,
1157
+ url: input.url
1158
+ };
1159
+ };
1160
+
1161
+ // src/commands/share/types.ts
1162
+ var ShareFilesErrorCodes = /* @__PURE__ */ ((ShareFilesErrorCodes2) => {
1163
+ ShareFilesErrorCodes2["UserRejected"] = "user_rejected";
1164
+ ShareFilesErrorCodes2["GenericError"] = "generic_error";
1165
+ ShareFilesErrorCodes2["InvalidFileName"] = "invalid_file_name";
1166
+ return ShareFilesErrorCodes2;
1167
+ })(ShareFilesErrorCodes || {});
1168
+ var ShareError = class extends Error {
1169
+ constructor(error_code) {
1170
+ super(`Share failed: ${error_code}`);
1171
+ this.error_code = error_code;
1172
+ this.name = "ShareError";
1173
+ }
1174
+ };
1175
+
1176
+ // src/commands/share/index.ts
1177
+ async function share(options, ctx) {
1178
+ const result = await executeWithFallback({
1179
+ command: "share" /* Share */,
1180
+ nativeExecutor: () => nativeShare(options, ctx),
1181
+ customFallback: options.fallback
1182
+ });
1183
+ if (result.executedWith === "fallback") {
1184
+ return {
1185
+ executedWith: "fallback",
1186
+ data: result.data
1187
+ };
1188
+ }
1189
+ return {
1190
+ executedWith: "minikit",
1191
+ data: result.data
1192
+ };
1193
+ }
1194
+ async function nativeShare(options, ctx) {
1195
+ if (!ctx) {
1196
+ ctx = { events: new EventManager(), state: { deviceProperties: {} } };
1197
+ }
1198
+ if (typeof window === "undefined" || !isCommandAvailable("share" /* Share */)) {
1199
+ throw new Error(
1200
+ "'share' command is unavailable. Check MiniKit.install() or update the app version"
1201
+ );
1202
+ }
1203
+ const payloadInput = {
1204
+ files: options.files,
1205
+ title: options.title,
1206
+ text: options.text,
1207
+ url: options.url
1208
+ };
1209
+ if (ctx.state.deviceProperties.deviceOS === "ios" && typeof navigator !== "undefined") {
1210
+ sendMiniKitEvent({
1211
+ command: "share" /* Share */,
1212
+ version: COMMAND_VERSIONS["share" /* Share */],
1213
+ payload: payloadInput
1214
+ });
1215
+ await navigator.share(payloadInput);
1216
+ return {
1217
+ status: "success",
1218
+ version: COMMAND_VERSIONS["share" /* Share */],
1219
+ shared_files_count: payloadInput.files?.length ?? 0,
1220
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
1221
+ };
1222
+ }
1223
+ const formattedPayload = await formatShareInput(payloadInput);
1224
+ const payload = await new Promise((resolve, reject) => {
1225
+ try {
1226
+ ctx.events.subscribe("miniapp-share" /* MiniAppShare */, (response) => {
1227
+ ctx.events.unsubscribe("miniapp-share" /* MiniAppShare */);
1228
+ resolve(response);
1229
+ });
1230
+ sendMiniKitEvent({
1231
+ command: "share" /* Share */,
1232
+ version: COMMAND_VERSIONS["share" /* Share */],
1233
+ payload: formattedPayload
1234
+ });
1235
+ } catch (error) {
1236
+ reject(error);
1237
+ }
1238
+ });
1239
+ if (payload.status === "error") {
1240
+ throw new ShareError(payload.error_code);
1241
+ }
1242
+ return payload;
1243
+ }
1244
+
1245
+ // src/commands/share-contacts/types.ts
1246
+ var ShareContactsErrorCodes = /* @__PURE__ */ ((ShareContactsErrorCodes2) => {
1247
+ ShareContactsErrorCodes2["UserRejected"] = "user_rejected";
1248
+ ShareContactsErrorCodes2["GenericError"] = "generic_error";
1249
+ return ShareContactsErrorCodes2;
1250
+ })(ShareContactsErrorCodes || {});
1251
+ var ShareContactsErrorMessage = {
1252
+ ["user_rejected" /* UserRejected */]: "User rejected the request.",
1253
+ ["generic_error" /* GenericError */]: "Something unexpected went wrong."
1254
+ };
1255
+ var ShareContactsError = class extends Error {
1256
+ constructor(code) {
1257
+ super(`Share contacts failed: ${code}`);
1258
+ this.name = "ShareContactsError";
1259
+ this.code = code;
1260
+ }
1261
+ };
1262
+
1263
+ // src/commands/share-contacts/index.ts
1264
+ async function shareContacts(options, ctx) {
1265
+ const resolvedOptions = options ?? {};
1266
+ const result = await executeWithFallback({
1267
+ command: "share-contacts" /* ShareContacts */,
1268
+ nativeExecutor: () => nativeShareContacts(resolvedOptions, ctx),
1269
+ // No Wagmi fallback - contacts is native only
1270
+ customFallback: resolvedOptions.fallback
1271
+ });
1272
+ if (result.executedWith === "fallback") {
1273
+ return { executedWith: "fallback", data: result.data };
1274
+ }
1275
+ return { executedWith: "minikit", data: result.data };
1276
+ }
1277
+ var getContacts = shareContacts;
1278
+ async function nativeShareContacts(options, ctx) {
1279
+ if (!ctx) {
1280
+ ctx = { events: new EventManager(), state: { deviceProperties: {} } };
1281
+ }
1282
+ if (typeof window === "undefined" || !isCommandAvailable("share-contacts" /* ShareContacts */)) {
1283
+ throw new Error(
1284
+ "'shareContacts' command is unavailable. Check MiniKit.install() or update the app version"
1285
+ );
1286
+ }
1287
+ const payload = {
1288
+ isMultiSelectEnabled: options.isMultiSelectEnabled ?? false,
1289
+ inviteMessage: options.inviteMessage
1290
+ };
1291
+ const finalPayload = await new Promise(
1292
+ (resolve, reject) => {
1293
+ try {
1294
+ ctx.events.subscribe("miniapp-share-contacts" /* MiniAppShareContacts */, (response) => {
1295
+ ctx.events.unsubscribe("miniapp-share-contacts" /* MiniAppShareContacts */);
1296
+ resolve(response);
1297
+ });
1298
+ sendMiniKitEvent({
1299
+ command: "share-contacts" /* ShareContacts */,
1300
+ version: COMMAND_VERSIONS["share-contacts" /* ShareContacts */],
1301
+ payload
1302
+ });
1303
+ } catch (error) {
1304
+ reject(error);
1305
+ }
1306
+ }
1307
+ );
1308
+ if (finalPayload.status === "error") {
1309
+ throw new ShareContactsError(finalPayload.error_code);
1310
+ }
1311
+ return {
1312
+ contacts: finalPayload.contacts,
1313
+ timestamp: finalPayload.timestamp
1314
+ };
1315
+ }
1316
+
1317
+ // src/commands/sign-message/types.ts
1318
+ var SignMessageErrorCodes = /* @__PURE__ */ ((SignMessageErrorCodes2) => {
1319
+ SignMessageErrorCodes2["InvalidMessage"] = "invalid_message";
1320
+ SignMessageErrorCodes2["UserRejected"] = "user_rejected";
1321
+ SignMessageErrorCodes2["GenericError"] = "generic_error";
1322
+ return SignMessageErrorCodes2;
1323
+ })(SignMessageErrorCodes || {});
1324
+ var SignMessageError = class extends Error {
1325
+ constructor(error_code) {
1326
+ super(`Sign message failed: ${error_code}`);
1327
+ this.error_code = error_code;
1328
+ this.name = "SignMessageError";
1329
+ }
1330
+ };
1331
+
1332
+ // src/commands/sign-message/index.ts
1333
+ async function signMessage(options, ctx) {
1334
+ const fallbackAdapter = getFallbackAdapter();
1335
+ const result = await executeWithFallback({
1336
+ command: "sign-message" /* SignMessage */,
1337
+ nativeExecutor: () => nativeSignMessage(options, ctx),
1338
+ wagmiFallback: fallbackAdapter?.signMessage ? () => fallbackAdapter.signMessage({
1339
+ message: options.message
1340
+ }) : void 0,
1341
+ customFallback: options.fallback
1342
+ });
1343
+ if (result.executedWith === "fallback") {
1344
+ return { executedWith: "fallback", data: result.data };
1345
+ }
1346
+ if (result.executedWith === "wagmi") {
1347
+ return {
1348
+ executedWith: "wagmi",
1349
+ data: result.data
1350
+ };
1351
+ }
1352
+ return {
1353
+ executedWith: "minikit",
1354
+ data: result.data
1355
+ };
1356
+ }
1357
+ async function nativeSignMessage(options, ctx) {
1358
+ if (!ctx) {
1359
+ ctx = { events: new EventManager(), state: { deviceProperties: {} } };
1360
+ }
1361
+ if (typeof window === "undefined" || !isCommandAvailable("sign-message" /* SignMessage */)) {
1362
+ throw new Error(
1363
+ "'signMessage' command is unavailable. Check MiniKit.install() or update the app version"
1364
+ );
1365
+ }
1366
+ const payload = await new Promise(
1367
+ (resolve, reject) => {
1368
+ try {
1369
+ ctx.events.subscribe("miniapp-sign-message" /* MiniAppSignMessage */, (response) => {
1370
+ ctx.events.unsubscribe("miniapp-sign-message" /* MiniAppSignMessage */);
1371
+ resolve(response);
1372
+ });
1373
+ sendMiniKitEvent({
1374
+ command: "sign-message" /* SignMessage */,
1375
+ version: COMMAND_VERSIONS["sign-message" /* SignMessage */],
1376
+ payload: { message: options.message }
1377
+ });
1378
+ } catch (error) {
1379
+ reject(error);
1380
+ }
1381
+ }
1382
+ );
1383
+ if (payload.status === "error") {
1384
+ throw new SignMessageError(payload.error_code);
1385
+ }
1386
+ return payload;
1387
+ }
1388
+
1389
+ // src/commands/sign-typed-data/types.ts
1390
+ var SignTypedDataErrorCodes = /* @__PURE__ */ ((SignTypedDataErrorCodes2) => {
1391
+ SignTypedDataErrorCodes2["InvalidOperation"] = "invalid_operation";
1392
+ SignTypedDataErrorCodes2["UserRejected"] = "user_rejected";
1393
+ SignTypedDataErrorCodes2["InputError"] = "input_error";
1394
+ SignTypedDataErrorCodes2["SimulationFailed"] = "simulation_failed";
1395
+ SignTypedDataErrorCodes2["GenericError"] = "generic_error";
1396
+ SignTypedDataErrorCodes2["DisallowedOperation"] = "disallowed_operation";
1397
+ SignTypedDataErrorCodes2["InvalidContract"] = "invalid_contract";
1398
+ SignTypedDataErrorCodes2["MaliciousOperation"] = "malicious_operation";
1399
+ return SignTypedDataErrorCodes2;
1400
+ })(SignTypedDataErrorCodes || {});
1401
+ var SignTypedDataError = class extends Error {
1402
+ constructor(error_code) {
1403
+ super(`Sign typed data failed: ${error_code}`);
1404
+ this.error_code = error_code;
1405
+ this.name = "SignTypedDataError";
1406
+ }
1407
+ };
1408
+
1409
+ // src/commands/sign-typed-data/index.ts
1410
+ async function signTypedData(options, ctx) {
1411
+ const fallbackAdapter = getFallbackAdapter();
1412
+ const result = await executeWithFallback({
1413
+ command: "sign-typed-data" /* SignTypedData */,
1414
+ nativeExecutor: () => nativeSignTypedData(options, ctx),
1415
+ wagmiFallback: fallbackAdapter?.signTypedData ? () => fallbackAdapter.signTypedData({
1416
+ types: options.types,
1417
+ primaryType: options.primaryType,
1418
+ message: options.message,
1419
+ domain: options.domain,
1420
+ chainId: options.chainId
1421
+ }) : void 0,
1422
+ customFallback: options.fallback
1423
+ });
1424
+ if (result.executedWith === "fallback") {
1425
+ return { executedWith: "fallback", data: result.data };
1426
+ }
1427
+ if (result.executedWith === "wagmi") {
1428
+ return {
1429
+ executedWith: "wagmi",
1430
+ data: result.data
1431
+ };
1432
+ }
1433
+ return {
1434
+ executedWith: "minikit",
1435
+ data: result.data
1436
+ };
1437
+ }
1438
+ async function nativeSignTypedData(options, ctx) {
1439
+ if (!ctx) {
1440
+ ctx = { events: new EventManager(), state: { deviceProperties: {} } };
1441
+ }
1442
+ if (typeof window === "undefined" || !isCommandAvailable("sign-typed-data" /* SignTypedData */)) {
1443
+ throw new Error(
1444
+ "'signTypedData' command is unavailable. Check MiniKit.install() or update the app version"
1445
+ );
1446
+ }
1447
+ const payloadInput = {
1448
+ types: options.types,
1449
+ primaryType: options.primaryType,
1450
+ message: options.message,
1451
+ domain: options.domain,
1452
+ chainId: options.chainId ?? 480
1453
+ };
1454
+ const payload = await new Promise(
1455
+ (resolve, reject) => {
1456
+ try {
1457
+ ctx.events.subscribe("miniapp-sign-typed-data" /* MiniAppSignTypedData */, (response) => {
1458
+ ctx.events.unsubscribe("miniapp-sign-typed-data" /* MiniAppSignTypedData */);
1459
+ resolve(response);
1460
+ });
1461
+ sendMiniKitEvent({
1462
+ command: "sign-typed-data" /* SignTypedData */,
1463
+ version: COMMAND_VERSIONS["sign-typed-data" /* SignTypedData */],
1464
+ payload: payloadInput
1465
+ });
1466
+ } catch (error) {
1467
+ reject(error);
1468
+ }
1469
+ }
1470
+ );
1471
+ if (payload.status === "error") {
1472
+ throw new SignTypedDataError(payload.error_code);
1473
+ }
1474
+ return payload;
1475
+ }
1476
+
1477
+ // src/commands/wallet-auth/siwe.ts
1478
+ var import_viem = require("viem");
1479
+ var import_chains = require("viem/chains");
1480
+ var generateSiweMessage = (siweMessageData) => {
1481
+ let siweMessage = "";
1482
+ if (siweMessageData.scheme) {
1483
+ siweMessage += `${siweMessageData.scheme}://${siweMessageData.domain} wants you to sign in with your Ethereum account:
1484
+ `;
1485
+ } else {
1486
+ siweMessage += `${siweMessageData.domain} wants you to sign in with your Ethereum account:
1487
+ `;
1488
+ }
1489
+ if (siweMessageData.address) {
1490
+ siweMessage += `${siweMessageData.address}
1491
+ `;
1492
+ } else {
1493
+ siweMessage += "{address}\n";
1494
+ }
1495
+ siweMessage += "\n";
1496
+ if (siweMessageData.statement) {
1497
+ siweMessage += `${siweMessageData.statement}
1498
+ `;
1499
+ }
1500
+ siweMessage += "\n";
1501
+ siweMessage += `URI: ${siweMessageData.uri}
1502
+ `;
1503
+ siweMessage += `Version: ${siweMessageData.version}
1504
+ `;
1505
+ siweMessage += `Chain ID: ${siweMessageData.chain_id}
1506
+ `;
1507
+ siweMessage += `Nonce: ${siweMessageData.nonce}
1508
+ `;
1509
+ siweMessage += `Issued At: ${siweMessageData.issued_at}
1510
+ `;
1511
+ if (siweMessageData.expiration_time) {
1512
+ siweMessage += `Expiration Time: ${siweMessageData.expiration_time}
1513
+ `;
1514
+ }
1515
+ if (siweMessageData.not_before) {
1516
+ siweMessage += `Not Before: ${siweMessageData.not_before}
1517
+ `;
1518
+ }
1519
+ if (siweMessageData.request_id) {
1520
+ siweMessage += `Request ID: ${siweMessageData.request_id}
1521
+ `;
1522
+ }
1523
+ return siweMessage;
1524
+ };
1525
+
1526
+ // src/commands/wallet-auth/types.ts
1527
+ var WalletAuthErrorCodes = /* @__PURE__ */ ((WalletAuthErrorCodes2) => {
1528
+ WalletAuthErrorCodes2["MalformedRequest"] = "malformed_request";
1529
+ WalletAuthErrorCodes2["UserRejected"] = "user_rejected";
1530
+ WalletAuthErrorCodes2["GenericError"] = "generic_error";
1531
+ return WalletAuthErrorCodes2;
1532
+ })(WalletAuthErrorCodes || {});
1533
+ var WalletAuthErrorMessage = {
1534
+ ["malformed_request" /* MalformedRequest */]: "Provided parameters in the request are invalid.",
1535
+ ["user_rejected" /* UserRejected */]: "User rejected the request.",
1536
+ ["generic_error" /* GenericError */]: "Something unexpected went wrong."
1537
+ };
1538
+ var WalletAuthError = class extends Error {
1539
+ constructor(code, details) {
1540
+ super(details || `Wallet auth failed: ${code}`);
1541
+ this.name = "WalletAuthError";
1542
+ this.code = code;
1543
+ this.details = details;
1544
+ }
1545
+ };
1546
+
1547
+ // src/commands/wallet-auth/validate.ts
1548
+ var SIWE_NONCE_REGEX = /^[a-zA-Z0-9]+$/;
1549
+ var validateWalletAuthCommandInput = (params) => {
1550
+ if (!params.nonce) {
1551
+ return { valid: false, message: "'nonce' is required" };
1552
+ }
1553
+ if (params.nonce.length < 8) {
1554
+ return { valid: false, message: "'nonce' must be at least 8 characters" };
1555
+ }
1556
+ if (!SIWE_NONCE_REGEX.test(params.nonce)) {
1557
+ return {
1558
+ valid: false,
1559
+ message: "'nonce' must be alphanumeric (letters and numbers only)"
1560
+ };
1561
+ }
1562
+ if (params.statement && params.statement.includes("\n")) {
1563
+ return { valid: false, message: "'statement' must not contain newlines" };
1564
+ }
1565
+ if (params.expirationTime && new Date(params.expirationTime) < /* @__PURE__ */ new Date()) {
1566
+ return { valid: false, message: "'expirationTime' must be in the future" };
1567
+ }
1568
+ if (params.expirationTime && new Date(params.expirationTime) > new Date(Date.now() + 7 * 24 * 60 * 60 * 1e3)) {
1569
+ return { valid: false, message: "'expirationTime' must be within 7 days" };
1570
+ }
1571
+ if (params.notBefore && new Date(params.notBefore) > new Date(Date.now() + 7 * 24 * 60 * 60 * 1e3)) {
1572
+ return { valid: false, message: "'notBefore' must be within 7 days" };
1573
+ }
1574
+ return { valid: true };
1575
+ };
1576
+
1577
+ // src/commands/wallet-auth/index.ts
1578
+ async function walletAuth(options, ctx) {
1579
+ const fallbackAdapter = getFallbackAdapter();
1580
+ const result = await executeWithFallback({
1581
+ command: "wallet-auth" /* WalletAuth */,
1582
+ nativeExecutor: () => nativeWalletAuth(options, ctx),
1583
+ wagmiFallback: fallbackAdapter?.walletAuth ? () => fallbackAdapter.walletAuth({
1584
+ nonce: options.nonce,
1585
+ statement: options.statement,
1586
+ expirationTime: options.expirationTime
1587
+ }) : void 0,
1588
+ customFallback: options.fallback
1589
+ });
1590
+ if (result.executedWith === "fallback") {
1591
+ return { executedWith: "fallback", data: result.data };
1592
+ }
1593
+ if (result.executedWith === "wagmi") {
1594
+ return {
1595
+ executedWith: "wagmi",
1596
+ data: result.data
1597
+ };
1598
+ }
1599
+ return {
1600
+ executedWith: "minikit",
1601
+ data: result.data
1602
+ };
1603
+ }
1604
+ async function nativeWalletAuth(options, ctx) {
1605
+ if (!ctx) {
1606
+ ctx = { events: new EventManager(), state: { deviceProperties: {} } };
1607
+ }
1608
+ if (typeof window === "undefined" || !isCommandAvailable("wallet-auth" /* WalletAuth */)) {
1609
+ throw new Error(
1610
+ "'walletAuth' command is unavailable. Check MiniKit.install() or update the app version"
1611
+ );
1612
+ }
1613
+ const input = {
1614
+ nonce: options.nonce,
1615
+ statement: options.statement,
1616
+ requestId: options.requestId,
1617
+ expirationTime: options.expirationTime,
1618
+ notBefore: options.notBefore
1619
+ };
1620
+ const validationResult = validateWalletAuthCommandInput(input);
1621
+ if (!validationResult.valid) {
1622
+ throw new Error(`Invalid wallet auth input: ${validationResult.message}`);
1623
+ }
1624
+ let protocol;
1625
+ try {
1626
+ const currentUrl = new URL(window.location.href);
1627
+ protocol = currentUrl.protocol.split(":")[0];
1628
+ } catch (error) {
1629
+ throw new Error("Failed to get current URL");
1630
+ }
1631
+ const siweMessage = generateSiweMessage({
1632
+ scheme: protocol,
1633
+ domain: window.location.host,
1634
+ statement: input.statement ?? void 0,
1635
+ uri: window.location.href,
1636
+ version: "1",
1637
+ chain_id: 480,
1638
+ nonce: input.nonce,
1639
+ issued_at: (/* @__PURE__ */ new Date()).toISOString(),
1640
+ expiration_time: input.expirationTime?.toISOString() ?? void 0,
1641
+ not_before: input.notBefore?.toISOString() ?? void 0,
1642
+ request_id: input.requestId ?? void 0
1643
+ });
1644
+ const walletAuthPayload = { siweMessage };
1645
+ const worldAppVersion = ctx.state.deviceProperties.worldAppVersion;
1646
+ const walletAuthVersion = worldAppVersion && worldAppVersion > 2087900 ? COMMAND_VERSIONS["wallet-auth" /* WalletAuth */] : 1;
1647
+ const finalPayload = await new Promise(
1648
+ (resolve, reject) => {
1649
+ try {
1650
+ ctx.events.subscribe("miniapp-wallet-auth" /* MiniAppWalletAuth */, (response) => {
1651
+ ctx.events.unsubscribe("miniapp-wallet-auth" /* MiniAppWalletAuth */);
1652
+ resolve(response);
1653
+ });
1654
+ sendMiniKitEvent({
1655
+ command: "wallet-auth" /* WalletAuth */,
1656
+ version: walletAuthVersion,
1657
+ payload: walletAuthPayload
1658
+ });
1659
+ } catch (error) {
1660
+ reject(error);
1661
+ }
1662
+ }
1663
+ );
1664
+ if (finalPayload.status === "error") {
1665
+ throw new WalletAuthError(finalPayload.error_code, finalPayload.details);
1666
+ }
1667
+ return {
1668
+ address: finalPayload.address,
1669
+ message: finalPayload.message,
1670
+ signature: finalPayload.signature
1671
+ };
1672
+ }
1673
+
1674
+ // src/types.ts
1675
+ var MiniAppLaunchLocation = /* @__PURE__ */ ((MiniAppLaunchLocation2) => {
1676
+ MiniAppLaunchLocation2["Chat"] = "chat";
1677
+ MiniAppLaunchLocation2["Home"] = "home";
1678
+ MiniAppLaunchLocation2["AppStore"] = "app-store";
1679
+ MiniAppLaunchLocation2["DeepLink"] = "deep-link";
1680
+ MiniAppLaunchLocation2["WalletTab"] = "wallet-tab";
1681
+ return MiniAppLaunchLocation2;
1682
+ })(MiniAppLaunchLocation || {});
1683
+ var MiniKitInstallErrorCodes = /* @__PURE__ */ ((MiniKitInstallErrorCodes2) => {
1684
+ MiniKitInstallErrorCodes2["Unknown"] = "unknown";
1685
+ MiniKitInstallErrorCodes2["AlreadyInstalled"] = "already_installed";
1686
+ MiniKitInstallErrorCodes2["OutsideOfWorldApp"] = "outside_of_worldapp";
1687
+ MiniKitInstallErrorCodes2["NotOnClient"] = "not_on_client";
1688
+ MiniKitInstallErrorCodes2["AppOutOfDate"] = "app_out_of_date";
1689
+ return MiniKitInstallErrorCodes2;
1690
+ })(MiniKitInstallErrorCodes || {});
1691
+ var MiniKitInstallErrorMessage = {
1692
+ ["unknown" /* Unknown */]: "Failed to install MiniKit.",
1693
+ ["already_installed" /* AlreadyInstalled */]: "MiniKit is already installed.",
1694
+ ["outside_of_worldapp" /* OutsideOfWorldApp */]: "MiniApp launched outside of WorldApp.",
1695
+ ["not_on_client" /* NotOnClient */]: "Window object is not available.",
1696
+ ["app_out_of_date" /* AppOutOfDate */]: "WorldApp is out of date. Please update the app."
1697
+ };
1698
+ // Annotate the CommonJS export names for ESM import in node:
1699
+ 0 && (module.exports = {
1700
+ AttestationError,
1701
+ AttestationErrorCodes,
1702
+ COMMAND_VERSIONS,
1703
+ ChatError,
1704
+ ChatErrorCodes,
1705
+ Command,
1706
+ CommandUnavailableError,
1707
+ FallbackRequiredError,
1708
+ GetPermissionsError,
1709
+ GetPermissionsErrorCodes,
1710
+ MiniAppLaunchLocation,
1711
+ MiniKitInstallErrorCodes,
1712
+ MiniKitInstallErrorMessage,
1713
+ Network,
1714
+ PayError,
1715
+ PaymentErrorCodes,
1716
+ PaymentErrorMessage,
1717
+ Permission,
1718
+ RequestPermissionError,
1719
+ RequestPermissionErrorCodes,
1720
+ ResponseEvent,
1721
+ SendHapticFeedbackError,
1722
+ SendHapticFeedbackErrorCodes,
1723
+ SendTransactionError,
1724
+ SendTransactionErrorCodes,
1725
+ SendTransactionErrorMessage,
1726
+ ShareContactsError,
1727
+ ShareContactsErrorCodes,
1728
+ ShareContactsErrorMessage,
1729
+ ShareError,
1730
+ ShareFilesErrorCodes,
1731
+ SignMessageError,
1732
+ SignMessageErrorCodes,
1733
+ SignTypedDataError,
1734
+ SignTypedDataErrorCodes,
1735
+ TokenDecimals,
1736
+ Tokens,
1737
+ WEB_FEATURES,
1738
+ WORLD_APP_FEATURES,
1739
+ WalletAuthError,
1740
+ WalletAuthErrorCodes,
1741
+ WalletAuthErrorMessage,
1742
+ attestation,
1743
+ chat,
1744
+ closeMiniApp,
1745
+ getContacts,
1746
+ getPermissions,
1747
+ isCommandAvailable,
1748
+ isInWorldApp,
1749
+ pay,
1750
+ requestPermission,
1751
+ sendHapticFeedback,
1752
+ sendMiniKitEvent,
1753
+ sendTransaction,
1754
+ setCommandAvailable,
1755
+ share,
1756
+ shareContacts,
1757
+ signMessage,
1758
+ signTypedData,
1759
+ tokenToDecimals,
1760
+ validateCommands,
1761
+ walletAuth
1762
+ });