@worldcoin/minikit-js 1.1.0 → 1.2.0

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.
package/README.md CHANGED
@@ -1,8 +1,8 @@
1
- # Minikit-JS
1
+ # minikit-js
2
2
 
3
3
  ## 🚀 Getting Started
4
4
 
5
- Minikit is currently available on npm. To install, run:
5
+ MiniKit is currently available on npm. To install, run:
6
6
  `pnpm i @worldcoin/minikit-js`
7
7
 
8
8
  or use the CDN:
package/build/index.cjs CHANGED
@@ -442,6 +442,21 @@ var validatePaymentPayload = (payload) => {
442
442
  return true;
443
443
  };
444
444
 
445
+ // helpers/usernames/index.ts
446
+ var getUserProfile = async (address) => {
447
+ const res = await fetch("https://usernames.worldcoin.org/api/v1/query", {
448
+ method: "POST",
449
+ headers: {
450
+ "Content-Type": "application/json"
451
+ },
452
+ body: JSON.stringify({
453
+ addresses: [address]
454
+ })
455
+ });
456
+ const usernames = await res.json();
457
+ return usernames[0] ?? { username: null, profilePictureUrl: null };
458
+ };
459
+
445
460
  // minikit.ts
446
461
  var sendMiniKitEvent = (payload) => {
447
462
  sendWebviewEvent(payload);
@@ -459,6 +474,13 @@ var _MiniKit = class _MiniKit {
459
474
  const wrappedHandler = (payload) => {
460
475
  if (payload.status === "success") {
461
476
  _MiniKit.walletAddress = payload.address;
477
+ getUserProfile(payload.address).then((queryResponse) => {
478
+ _MiniKit.user = {
479
+ username: queryResponse.username,
480
+ profilePictureUrl: queryResponse.profilePictureUrl,
481
+ walletAddress: payload.address
482
+ };
483
+ });
462
484
  }
463
485
  originalHandler(payload);
464
486
  };
@@ -591,6 +613,7 @@ _MiniKit.listeners = {
591
613
  };
592
614
  _MiniKit.appId = null;
593
615
  _MiniKit.walletAddress = null;
616
+ _MiniKit.user = null;
594
617
  _MiniKit.commands = {
595
618
  verify: (payload) => {
596
619
  if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["verify" /* Verify */]) {
package/build/index.d.cts CHANGED
@@ -337,6 +337,11 @@ declare class MiniKit {
337
337
  private static listeners;
338
338
  static appId: string | null;
339
339
  static walletAddress: string | null;
340
+ static user: {
341
+ walletAddress: string | null;
342
+ username: string | null;
343
+ profilePictureUrl: string | null;
344
+ } | null;
340
345
  private static sendInit;
341
346
  static subscribe<E extends ResponseEvent>(event: E, handler: EventHandler<E>): void;
342
347
  static unsubscribe(event: ResponseEvent): void;
package/build/index.d.ts CHANGED
@@ -337,6 +337,11 @@ declare class MiniKit {
337
337
  private static listeners;
338
338
  static appId: string | null;
339
339
  static walletAddress: string | null;
340
+ static user: {
341
+ walletAddress: string | null;
342
+ username: string | null;
343
+ profilePictureUrl: string | null;
344
+ } | null;
340
345
  private static sendInit;
341
346
  static subscribe<E extends ResponseEvent>(event: E, handler: EventHandler<E>): void;
342
347
  static unsubscribe(event: ResponseEvent): void;
package/build/index.js CHANGED
@@ -395,6 +395,21 @@ var validatePaymentPayload = (payload) => {
395
395
  return true;
396
396
  };
397
397
 
398
+ // helpers/usernames/index.ts
399
+ var getUserProfile = async (address) => {
400
+ const res = await fetch("https://usernames.worldcoin.org/api/v1/query", {
401
+ method: "POST",
402
+ headers: {
403
+ "Content-Type": "application/json"
404
+ },
405
+ body: JSON.stringify({
406
+ addresses: [address]
407
+ })
408
+ });
409
+ const usernames = await res.json();
410
+ return usernames[0] ?? { username: null, profilePictureUrl: null };
411
+ };
412
+
398
413
  // minikit.ts
399
414
  var sendMiniKitEvent = (payload) => {
400
415
  sendWebviewEvent(payload);
@@ -412,6 +427,13 @@ var _MiniKit = class _MiniKit {
412
427
  const wrappedHandler = (payload) => {
413
428
  if (payload.status === "success") {
414
429
  _MiniKit.walletAddress = payload.address;
430
+ getUserProfile(payload.address).then((queryResponse) => {
431
+ _MiniKit.user = {
432
+ username: queryResponse.username,
433
+ profilePictureUrl: queryResponse.profilePictureUrl,
434
+ walletAddress: payload.address
435
+ };
436
+ });
415
437
  }
416
438
  originalHandler(payload);
417
439
  };
@@ -544,6 +566,7 @@ _MiniKit.listeners = {
544
566
  };
545
567
  _MiniKit.appId = null;
546
568
  _MiniKit.walletAddress = null;
569
+ _MiniKit.user = null;
547
570
  _MiniKit.commands = {
548
571
  verify: (payload) => {
549
572
  if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["verify" /* Verify */]) {
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@worldcoin/minikit-js",
3
- "version": "1.1.0",
3
+ "version": "1.2.0",
4
4
  "homepage": "https://docs.worldcoin.org/mini-apps",
5
- "description": "Minikit-js is our SDK for building mini-apps.",
5
+ "description": "minikit-js is our SDK for building mini-apps.",
6
6
  "license": "MIT",
7
7
  "private": false,
8
8
  "type": "module",