@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,596 @@
1
+ import {
2
+ EventManager,
3
+ MiniKitInstallErrorMessage,
4
+ attestation,
5
+ chat,
6
+ closeMiniApp,
7
+ getPermissions,
8
+ isInWorldApp,
9
+ pay,
10
+ requestPermission,
11
+ sendHapticFeedback,
12
+ sendMiniKitEvent,
13
+ sendTransaction,
14
+ share,
15
+ shareContacts,
16
+ signMessage,
17
+ signTypedData,
18
+ validateCommands,
19
+ walletAuth
20
+ } from "./chunk-Z2UGRZJ2.js";
21
+
22
+ // src/helpers/microphone.ts
23
+ var microphoneSetupDone = false;
24
+ var setupMicrophone = () => {
25
+ if (microphoneSetupDone) {
26
+ return;
27
+ }
28
+ if (typeof navigator !== "undefined" && !navigator.mediaDevices?.getUserMedia)
29
+ return;
30
+ const originalStop = MediaStreamTrack.prototype.stop;
31
+ MediaStreamTrack.prototype.stop = function() {
32
+ originalStop.call(this);
33
+ if (this.readyState === "ended") {
34
+ setTimeout(() => this.dispatchEvent(new Event("ended")), 0);
35
+ }
36
+ };
37
+ const realGUM = navigator.mediaDevices.getUserMedia.bind(
38
+ navigator.mediaDevices
39
+ );
40
+ const live = /* @__PURE__ */ new Set();
41
+ async function wrapped(constraints) {
42
+ const stream = await realGUM(constraints);
43
+ const hasAudioTrack = stream.getAudioTracks().length > 0;
44
+ if (hasAudioTrack) {
45
+ sendMiniKitEvent({
46
+ command: "microphone-stream-started",
47
+ version: 1,
48
+ payload: {
49
+ streamId: stream.id
50
+ }
51
+ });
52
+ live.add(stream);
53
+ stream.getAudioTracks().forEach((t) => {
54
+ t.addEventListener("ended", () => {
55
+ const allAudioTracksEnded = stream.getAudioTracks().every((track) => track.readyState === "ended");
56
+ if (allAudioTracksEnded) {
57
+ sendMiniKitEvent({
58
+ command: "microphone-stream-ended",
59
+ version: 1,
60
+ payload: {
61
+ streamId: stream.id
62
+ }
63
+ });
64
+ live.delete(stream);
65
+ }
66
+ });
67
+ });
68
+ }
69
+ return stream;
70
+ }
71
+ Object.defineProperty(navigator.mediaDevices, "getUserMedia", {
72
+ value: wrapped,
73
+ writable: false,
74
+ configurable: false,
75
+ enumerable: true
76
+ });
77
+ Object.freeze(navigator.mediaDevices);
78
+ const stopAllMiniAppMicrophoneStreams = () => {
79
+ live.forEach((s) => {
80
+ const audioTracks = s.getAudioTracks();
81
+ if (audioTracks.length > 0) {
82
+ audioTracks.forEach((t) => {
83
+ t.stop();
84
+ });
85
+ sendMiniKitEvent({
86
+ command: "microphone-stream-ended",
87
+ version: 1,
88
+ payload: {
89
+ streamId: s.id
90
+ }
91
+ });
92
+ }
93
+ });
94
+ live.clear();
95
+ };
96
+ MiniKit.subscribe("miniapp-microphone" /* MiniAppMicrophone */, (payload) => {
97
+ if (payload.status === "error" && (payload.error_code === "mini_app_permission_not_enabled" /* MiniAppPermissionNotEnabled */ || payload.error_code === "world_app_permission_not_enabled" /* WorldAppPermissionNotEnabled */)) {
98
+ console.log("stopping all microphone streams", payload);
99
+ stopAllMiniAppMicrophoneStreams();
100
+ }
101
+ });
102
+ window.__stopAllMiniAppMicrophoneStreams = stopAllMiniAppMicrophoneStreams;
103
+ microphoneSetupDone = true;
104
+ };
105
+
106
+ // src/helpers/usernames.ts
107
+ var getUserProfile = async (address) => {
108
+ const res = await fetch("https://usernames.worldcoin.org/api/v1/query", {
109
+ method: "POST",
110
+ headers: {
111
+ "Content-Type": "application/json"
112
+ },
113
+ body: JSON.stringify({
114
+ addresses: [address]
115
+ })
116
+ });
117
+ const usernames = await res.json();
118
+ return usernames?.[0] ?? { username: null, profile_picture_url: null };
119
+ };
120
+
121
+ // src/minikit.ts
122
+ var MINIKIT_VERSION = 1;
123
+ var MINIKIT_MINOR_VERSION = 96;
124
+ var WORLD_APP_LAUNCH_LOCATION_MAP = {
125
+ "app-store": "app-store" /* AppStore */,
126
+ carousel: "app-store" /* AppStore */,
127
+ explore: "app-store" /* AppStore */,
128
+ app_details: "app-store" /* AppStore */,
129
+ deeplink: "deep-link" /* DeepLink */,
130
+ homepage: "home" /* Home */,
131
+ wallet_tab: "wallet-tab" /* WalletTab */,
132
+ world_chat: "chat" /* Chat */
133
+ };
134
+ function mapWorldAppLaunchLocation(location) {
135
+ if (!location || typeof location !== "string") return null;
136
+ console.log("MiniKit launch location mapped:", location);
137
+ return WORLD_APP_LAUNCH_LOCATION_MAP[location.toLowerCase()] ?? null;
138
+ }
139
+ var _MiniKit = class _MiniKit {
140
+ static getActiveMiniKit() {
141
+ if (typeof window === "undefined") return this;
142
+ const candidate = window.MiniKit;
143
+ if (candidate && typeof candidate.trigger === "function") {
144
+ return candidate;
145
+ }
146
+ return this;
147
+ }
148
+ // ============================================================================
149
+ // Unified API (auto-detects environment)
150
+ // ============================================================================
151
+ /**
152
+ * Authenticate user via wallet signature (SIWE)
153
+ *
154
+ * Works in World App (native SIWE) and web (Wagmi + SIWE fallback).
155
+ *
156
+ * @example
157
+ * ```typescript
158
+ * const result = await MiniKit.walletAuth({ nonce: 'randomnonce123' });
159
+ * console.log(result.data.address);
160
+ * console.log(result.executedWith); // 'minikit' | 'wagmi' | 'fallback'
161
+ * ```
162
+ */
163
+ static walletAuth(options) {
164
+ const active = this.getActiveMiniKit();
165
+ if (active !== this) {
166
+ return active.walletAuth(options);
167
+ }
168
+ return walletAuth(options, this.getContext());
169
+ }
170
+ /**
171
+ * Send one or more transactions
172
+ *
173
+ * World App: batch + permit2 + gas sponsorship
174
+ * Web: sequential execution via Wagmi
175
+ *
176
+ * @example
177
+ * ```typescript
178
+ * const result = await MiniKit.sendTransaction({
179
+ * chainId: 480,
180
+ * transactions: [{
181
+ * to: '0x...',
182
+ * data: '0x...',
183
+ * value: '0x0',
184
+ * }],
185
+ * });
186
+ * ```
187
+ */
188
+ static sendTransaction(options) {
189
+ const active = this.getActiveMiniKit();
190
+ if (active !== this) {
191
+ return active.sendTransaction(options);
192
+ }
193
+ return sendTransaction(options, this.getContext());
194
+ }
195
+ /**
196
+ * Send a payment (World App only)
197
+ *
198
+ * Requires custom fallback on web.
199
+ *
200
+ * @example
201
+ * ```typescript
202
+ * const result = await MiniKit.pay({
203
+ * reference: crypto.randomUUID(),
204
+ * to: '0x...',
205
+ * tokens: [{ symbol: Tokens.WLD, token_amount: '1.0' }],
206
+ * description: 'Payment for coffee',
207
+ * fallback: () => showStripeCheckout(),
208
+ * });
209
+ * ```
210
+ */
211
+ static pay(options) {
212
+ const active = this.getActiveMiniKit();
213
+ if (active !== this) {
214
+ return active.pay(options);
215
+ }
216
+ return pay(options, this.getContext());
217
+ }
218
+ /**
219
+ * Open the contact picker (World App only)
220
+ *
221
+ * Requires custom fallback on web.
222
+ *
223
+ * @example
224
+ * ```typescript
225
+ * const result = await MiniKit.shareContacts({
226
+ * isMultiSelectEnabled: true,
227
+ * fallback: () => showManualAddressInput(),
228
+ * });
229
+ * ```
230
+ */
231
+ static shareContacts(options = {}) {
232
+ const active = this.getActiveMiniKit();
233
+ if (active !== this) {
234
+ return active.shareContacts(options);
235
+ }
236
+ return shareContacts(options, this.getContext());
237
+ }
238
+ /**
239
+ * Sign a message
240
+ */
241
+ static signMessage(options) {
242
+ const active = this.getActiveMiniKit();
243
+ if (active !== this) {
244
+ return active.signMessage(options);
245
+ }
246
+ return signMessage(options, this.getContext());
247
+ }
248
+ /**
249
+ * Sign typed data (EIP-712)
250
+ */
251
+ static signTypedData(options) {
252
+ const active = this.getActiveMiniKit();
253
+ if (active !== this) {
254
+ return active.signTypedData(options);
255
+ }
256
+ return signTypedData(options, this.getContext());
257
+ }
258
+ /**
259
+ * Send a chat message
260
+ */
261
+ static chat(options) {
262
+ const active = this.getActiveMiniKit();
263
+ if (active !== this) {
264
+ return active.chat(options);
265
+ }
266
+ return chat(options, this.getContext());
267
+ }
268
+ /**
269
+ * Share files/text/URL
270
+ */
271
+ static share(options) {
272
+ const active = this.getActiveMiniKit();
273
+ if (active !== this) {
274
+ return active.share(options);
275
+ }
276
+ return share(options, this.getContext());
277
+ }
278
+ /**
279
+ * Get current permission settings
280
+ */
281
+ static getPermissions(options = {}) {
282
+ const active = this.getActiveMiniKit();
283
+ if (active !== this) {
284
+ return active.getPermissions(options);
285
+ }
286
+ return getPermissions(options, this.getContext());
287
+ }
288
+ /**
289
+ * Request a permission from the user
290
+ */
291
+ static requestPermission(options) {
292
+ const active = this.getActiveMiniKit();
293
+ if (active !== this) {
294
+ return active.requestPermission(options);
295
+ }
296
+ return requestPermission(options, this.getContext());
297
+ }
298
+ /**
299
+ * Trigger haptic feedback
300
+ */
301
+ static sendHapticFeedback(options) {
302
+ const active = this.getActiveMiniKit();
303
+ if (active !== this) {
304
+ return active.sendHapticFeedback(options);
305
+ }
306
+ return sendHapticFeedback(options, this.getContext());
307
+ }
308
+ /**
309
+ * Request app attestation token for a request hash
310
+ */
311
+ static attestation(options) {
312
+ const active = this.getActiveMiniKit();
313
+ if (active !== this) {
314
+ return active.attestation(options);
315
+ }
316
+ return attestation(options, this.getContext());
317
+ }
318
+ /**
319
+ * Close the mini app
320
+ */
321
+ static closeMiniApp(options = {}) {
322
+ const active = this.getActiveMiniKit();
323
+ if (active !== this) {
324
+ return active.closeMiniApp(options);
325
+ }
326
+ return closeMiniApp(options, this.getContext());
327
+ }
328
+ // ============================================================================
329
+ // Public State Accessors
330
+ // ============================================================================
331
+ static get appId() {
332
+ return this._appId;
333
+ }
334
+ static set appId(value) {
335
+ this._appId = value;
336
+ }
337
+ static get user() {
338
+ return this._user;
339
+ }
340
+ static set user(value) {
341
+ this._user = value;
342
+ }
343
+ static get deviceProperties() {
344
+ return this._deviceProperties;
345
+ }
346
+ static get location() {
347
+ return this._location;
348
+ }
349
+ // ============================================================================
350
+ // Event System
351
+ // ============================================================================
352
+ static subscribe(event, handler) {
353
+ const active = this.getActiveMiniKit();
354
+ if (active !== this) {
355
+ active.subscribe(event, handler);
356
+ return;
357
+ }
358
+ if (event === "miniapp-wallet-auth" /* MiniAppWalletAuth */) {
359
+ const originalHandler = handler;
360
+ const wrappedHandler = async (payload) => {
361
+ if (payload.status === "success") {
362
+ await this.updateUserFromWalletAuth(payload.address);
363
+ }
364
+ originalHandler(payload);
365
+ };
366
+ this.eventManager.subscribe(event, wrappedHandler);
367
+ } else {
368
+ this.eventManager.subscribe(event, handler);
369
+ }
370
+ }
371
+ static unsubscribe(event) {
372
+ const active = this.getActiveMiniKit();
373
+ if (active !== this) {
374
+ active.unsubscribe(event);
375
+ return;
376
+ }
377
+ this.eventManager.unsubscribe(event);
378
+ }
379
+ static trigger(event, payload) {
380
+ const active = this.getActiveMiniKit();
381
+ if (active !== this) {
382
+ active.trigger(event, payload);
383
+ return;
384
+ }
385
+ this.eventManager.trigger(event, payload);
386
+ }
387
+ // ============================================================================
388
+ // Installation
389
+ // ============================================================================
390
+ static sendInit() {
391
+ sendMiniKitEvent({
392
+ command: "init",
393
+ payload: {
394
+ version: MINIKIT_VERSION,
395
+ minorVersion: MINIKIT_MINOR_VERSION
396
+ }
397
+ });
398
+ }
399
+ static install(appId) {
400
+ const active = this.getActiveMiniKit();
401
+ if (active !== this) {
402
+ return active.install(appId);
403
+ }
404
+ if (typeof window === "undefined") {
405
+ return {
406
+ success: false,
407
+ errorCode: "already_installed" /* AlreadyInstalled */,
408
+ errorMessage: MiniKitInstallErrorMessage["already_installed" /* AlreadyInstalled */]
409
+ };
410
+ }
411
+ if (!appId) {
412
+ console.warn("App ID not provided during install");
413
+ } else {
414
+ this._appId = appId;
415
+ }
416
+ if (!window.WorldApp) {
417
+ return {
418
+ success: false,
419
+ errorCode: "outside_of_worldapp" /* OutsideOfWorldApp */,
420
+ errorMessage: MiniKitInstallErrorMessage["outside_of_worldapp" /* OutsideOfWorldApp */]
421
+ };
422
+ }
423
+ this.initFromWorldApp(window.WorldApp);
424
+ try {
425
+ window.MiniKit = this;
426
+ this.sendInit();
427
+ } catch (error) {
428
+ console.error(
429
+ MiniKitInstallErrorMessage["unknown" /* Unknown */],
430
+ error
431
+ );
432
+ return {
433
+ success: false,
434
+ errorCode: "unknown" /* Unknown */,
435
+ errorMessage: MiniKitInstallErrorMessage["unknown" /* Unknown */]
436
+ };
437
+ }
438
+ this._isReady = true;
439
+ setupMicrophone();
440
+ if (!validateCommands(window.WorldApp.supported_commands)) {
441
+ return {
442
+ success: false,
443
+ errorCode: "app_out_of_date" /* AppOutOfDate */,
444
+ errorMessage: MiniKitInstallErrorMessage["app_out_of_date" /* AppOutOfDate */]
445
+ };
446
+ }
447
+ return { success: true };
448
+ }
449
+ static isInstalled(debug) {
450
+ const isInstalled = this._isReady && Boolean(window.MiniKit);
451
+ if (!isInstalled) {
452
+ console.warn(
453
+ "MiniKit is not installed. Make sure you're running the application inside of World App"
454
+ );
455
+ }
456
+ if (debug && isInstalled) {
457
+ console.log("MiniKit is alive!");
458
+ }
459
+ return isInstalled;
460
+ }
461
+ // ============================================================================
462
+ // Internal
463
+ // ============================================================================
464
+ static initFromWorldApp(worldApp) {
465
+ if (!worldApp) return;
466
+ this._user.optedIntoOptionalAnalytics = worldApp.is_optional_analytics;
467
+ this._deviceProperties.safeAreaInsets = worldApp.safe_area_insets;
468
+ this._deviceProperties.deviceOS = worldApp.device_os;
469
+ this._deviceProperties.worldAppVersion = worldApp.world_app_version;
470
+ this._location = mapWorldAppLaunchLocation(worldApp.location);
471
+ }
472
+ static async updateUserFromWalletAuth(address) {
473
+ this._user.walletAddress = address;
474
+ try {
475
+ const userProfile = await getUserProfile(address);
476
+ this._user.username = userProfile.username;
477
+ this._user.profilePictureUrl = userProfile.profile_picture_url;
478
+ } catch (error) {
479
+ console.error("Failed to fetch user profile:", error);
480
+ }
481
+ }
482
+ static getContext() {
483
+ return {
484
+ events: this.eventManager,
485
+ state: { deviceProperties: this._deviceProperties }
486
+ };
487
+ }
488
+ // ============================================================================
489
+ // Deprecated — remove in next major
490
+ // ============================================================================
491
+ /**
492
+ * @deprecated Use `MiniKit.pay()`, `MiniKit.walletAuth()`, etc. directly.
493
+ *
494
+ * Migration guide:
495
+ * - `MiniKit.commands.pay(payload)` → `await MiniKit.pay(options)`
496
+ * - `MiniKit.commands.walletAuth(payload)` → `await MiniKit.walletAuth(options)`
497
+ * - `MiniKit.commands.sendTransaction(payload)` → `await MiniKit.sendTransaction(options)`
498
+ * - `MiniKit.commands.signMessage(payload)` → `await MiniKit.signMessage(input)`
499
+ * - `MiniKit.commands.signTypedData(payload)` → `await MiniKit.signTypedData(input)`
500
+ * - `MiniKit.commands.shareContacts(payload)` → `await MiniKit.shareContacts(options)`
501
+ * - `MiniKit.commands.chat(payload)` → `await MiniKit.chat(input)`
502
+ * - `MiniKit.commands.share(payload)` → `await MiniKit.share(input)`
503
+ * - `MiniKit.commands.getPermissions()` → `await MiniKit.getPermissions()`
504
+ * - `MiniKit.commands.requestPermission(payload)` → `await MiniKit.requestPermission(input)`
505
+ * - `MiniKit.commands.sendHapticFeedback(payload)` → `await MiniKit.sendHapticFeedback(input)`
506
+ * - `MiniKit.commands.attestation(payload)` → `await MiniKit.attestation(options)`
507
+ * - `MiniKit.commands.closeMiniApp()` → `await MiniKit.closeMiniApp()`
508
+ */
509
+ static get commands() {
510
+ throw new Error(
511
+ "MiniKit.commands has been removed. Use MiniKit.pay(), MiniKit.walletAuth(), etc. directly."
512
+ );
513
+ }
514
+ /**
515
+ * @deprecated Use `MiniKit.pay()`, `MiniKit.walletAuth()`, etc. directly. All commands are now async by default.
516
+ *
517
+ * See `MiniKit.commands` deprecation notice for the full migration guide.
518
+ */
519
+ static get commandsAsync() {
520
+ throw new Error(
521
+ "MiniKit.commandsAsync has been removed. Use MiniKit.pay(), MiniKit.walletAuth(), etc. directly."
522
+ );
523
+ }
524
+ };
525
+ _MiniKit.eventManager = new EventManager();
526
+ // State (was MiniKitState)
527
+ _MiniKit._appId = null;
528
+ _MiniKit._user = {};
529
+ _MiniKit._deviceProperties = {};
530
+ _MiniKit._location = null;
531
+ _MiniKit._isReady = false;
532
+ /**
533
+ * Check if running inside World App
534
+ */
535
+ _MiniKit.isInWorldApp = isInWorldApp;
536
+ // ============================================================================
537
+ // Utility Methods
538
+ // ============================================================================
539
+ _MiniKit.getUserByAddress = async (address) => {
540
+ const walletAddress = address ?? _MiniKit._user.walletAddress;
541
+ const userProfile = await getUserProfile(walletAddress);
542
+ return {
543
+ walletAddress,
544
+ username: userProfile.username,
545
+ profilePictureUrl: userProfile.profile_picture_url
546
+ };
547
+ };
548
+ _MiniKit.getUserByUsername = async (username) => {
549
+ const res = await fetch(
550
+ `https://usernames.worldcoin.org/api/v1/${username}`,
551
+ {
552
+ method: "GET",
553
+ headers: {
554
+ "Content-Type": "application/json"
555
+ }
556
+ }
557
+ );
558
+ const user = await res.json();
559
+ return {
560
+ walletAddress: user.address,
561
+ username: user.username,
562
+ profilePictureUrl: user.profile_picture_url
563
+ };
564
+ };
565
+ _MiniKit.getUserInfo = _MiniKit.getUserByAddress;
566
+ _MiniKit.getMiniAppUrl = (appId, path) => {
567
+ const baseUrl = new URL("https://world.org/mini-app");
568
+ baseUrl.searchParams.append("app_id", appId);
569
+ if (path) {
570
+ const fullPath = path.startsWith("/") ? path : `/${path}`;
571
+ baseUrl.searchParams.append("path", encodeURIComponent(fullPath));
572
+ }
573
+ return baseUrl.toString();
574
+ };
575
+ _MiniKit.showProfileCard = (username, walletAddress) => {
576
+ if (!username && !walletAddress) {
577
+ console.error(
578
+ "Either username or walletAddress must be provided to show profile card"
579
+ );
580
+ return;
581
+ }
582
+ if (username) {
583
+ window.open(
584
+ `worldapp://profile?username=${encodeURIComponent(username)}`
585
+ );
586
+ } else {
587
+ window.open(
588
+ `worldapp://profile?address=${encodeURIComponent(walletAddress || "")}`
589
+ );
590
+ }
591
+ };
592
+ var MiniKit = _MiniKit;
593
+
594
+ export {
595
+ MiniKit
596
+ };