@worldcoin/minikit-js 0.0.21-internal-alpha → 0.0.23-internal-alpha

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/build/index.cjs CHANGED
@@ -22,9 +22,12 @@ var src_exports = {};
22
22
  __export(src_exports, {
23
23
  Command: () => Command,
24
24
  MiniKit: () => MiniKit,
25
+ MiniKitInstallErrorCode: () => MiniKitInstallErrorCode,
26
+ MiniKitInstallErrorMessage: () => MiniKitInstallErrorMessage,
25
27
  Network: () => Network,
26
28
  PaymentErrorCodes: () => PaymentErrorCodes,
27
29
  PaymentErrorMessage: () => PaymentErrorMessage,
30
+ PaymentValidationErrors: () => PaymentValidationErrors,
28
31
  ResponseEvent: () => ResponseEvent,
29
32
  SAFE_CONTRACT_ABI: () => SAFE_CONTRACT_ABI,
30
33
  TokenDecimals: () => TokenDecimals,
@@ -37,6 +40,7 @@ __export(src_exports, {
37
40
  generateNonce: () => generateNonce,
38
41
  parseSiweMessage: () => parseSiweMessage,
39
42
  tokenToDecimals: () => tokenToDecimals,
43
+ verifyCloudProof: () => import_backend.verifyCloudProof,
40
44
  verifySiweMessage: () => verifySiweMessage
41
45
  });
42
46
  module.exports = __toCommonJS(src_exports);
@@ -243,30 +247,50 @@ var PaymentErrorCodes = /* @__PURE__ */ ((PaymentErrorCodes2) => {
243
247
  PaymentErrorCodes2["InsufficientBalance"] = "insufficient_balance";
244
248
  PaymentErrorCodes2["TransactionFailed"] = "transaction_failed";
245
249
  PaymentErrorCodes2["GenericError"] = "generic_error";
250
+ PaymentErrorCodes2["UserBlocked"] = "user_blocked";
246
251
  return PaymentErrorCodes2;
247
252
  })(PaymentErrorCodes || {});
248
- var PaymentErrorMessage = /* @__PURE__ */ ((PaymentErrorMessage2) => {
249
- PaymentErrorMessage2["MalformedRequest"] = "There was a problem with this request. Please try again or contact the app owner.";
250
- PaymentErrorMessage2["PaymentRejected"] = "You\u2019ve cancelled the payment in World App.";
251
- PaymentErrorMessage2["InvalidReceiver"] = "The receiver address is invalid. Please contact the app owner.";
252
- PaymentErrorMessage2["InsufficientBalance"] = "You do not have enough balance to complete this transaction.";
253
- PaymentErrorMessage2["TransactionFailed"] = "The transaction failed. Please try again.";
254
- PaymentErrorMessage2["InvalidTokenAddress"] = "The token address is invalid. Please contact the app owner.";
255
- PaymentErrorMessage2["InvalidAppId"] = "The app ID is invalid. Please contact the app owner.";
256
- PaymentErrorMessage2["GenericError"] = "Something unexpected went wrong. Please try again.";
257
- PaymentErrorMessage2["DuplicateReference"] = "This reference ID already exists please generate a new one and try again.";
258
- return PaymentErrorMessage2;
259
- })(PaymentErrorMessage || {});
253
+ var PaymentErrorMessage = {
254
+ ["input_error" /* InputError */]: "There was a problem with this request. Please try again or contact the app owner.",
255
+ ["payment_rejected" /* PaymentRejected */]: "You\u2019ve cancelled the payment in World App.",
256
+ ["invalid_receiver" /* InvalidReceiver */]: "The receiver address is invalid. Please contact the app owner.",
257
+ ["insufficient_balance" /* InsufficientBalance */]: "You do not have enough balance to complete this transaction.",
258
+ ["transaction_failed" /* TransactionFailed */]: "The transaction failed. Please try again.",
259
+ ["generic_error" /* GenericError */]: "Something unexpected went wrong. Please try again.",
260
+ ["user_blocked" /* UserBlocked */]: "User's region is blocked from making payments."
261
+ };
262
+ var PaymentValidationErrors = /* @__PURE__ */ ((PaymentValidationErrors2) => {
263
+ PaymentValidationErrors2["MalformedRequest"] = "There was a problem with this request. Please try again or contact the app owner.";
264
+ PaymentValidationErrors2["InvalidTokenAddress"] = "The token address is invalid. Please contact the app owner.";
265
+ PaymentValidationErrors2["InvalidAppId"] = "The app ID is invalid. Please contact the app owner.";
266
+ PaymentValidationErrors2["DuplicateReference"] = "This reference ID already exists please generate a new one and try again.";
267
+ return PaymentValidationErrors2;
268
+ })(PaymentValidationErrors || {});
260
269
  var WalletAuthErrorCodes = /* @__PURE__ */ ((WalletAuthErrorCodes2) => {
261
- WalletAuthErrorCodes2["InvalidAddress"] = "invalid_address";
262
270
  WalletAuthErrorCodes2["MalformedRequest"] = "malformed_request";
263
271
  WalletAuthErrorCodes2["UserRejected"] = "user_rejected";
272
+ WalletAuthErrorCodes2["GenericError"] = "generic_error";
264
273
  return WalletAuthErrorCodes2;
265
274
  })(WalletAuthErrorCodes || {});
266
275
  var WalletAuthErrorMessage = {
267
- ["invalid_address" /* InvalidAddress */]: "The specified address is not valid for the connected wallet.",
268
276
  ["malformed_request" /* MalformedRequest */]: "Provided parameters in the request are invalid.",
269
- ["user_rejected" /* UserRejected */]: "User rejected the request."
277
+ ["user_rejected" /* UserRejected */]: "User rejected the request.",
278
+ ["generic_error" /* GenericError */]: "Something unexpected went wrong."
279
+ };
280
+ var MiniKitInstallErrorCode = /* @__PURE__ */ ((MiniKitInstallErrorCode2) => {
281
+ MiniKitInstallErrorCode2["Unknown"] = "unknown";
282
+ MiniKitInstallErrorCode2["AlreadyInstalled"] = "already_installed";
283
+ MiniKitInstallErrorCode2["OutsideOfWorldApp"] = "outside_of_worldapp";
284
+ MiniKitInstallErrorCode2["NotOnClient"] = "not_on_client";
285
+ MiniKitInstallErrorCode2["AppOutOfDate"] = "app_out_of_date";
286
+ return MiniKitInstallErrorCode2;
287
+ })(MiniKitInstallErrorCode || {});
288
+ var MiniKitInstallErrorMessage = {
289
+ ["unknown" /* Unknown */]: "Failed to install MiniKit.",
290
+ ["already_installed" /* AlreadyInstalled */]: "MiniKit is already installed.",
291
+ ["outside_of_worldapp" /* OutsideOfWorldApp */]: "MiniApp launched outside of WorldApp.",
292
+ ["not_on_client" /* NotOnClient */]: "Window object is not available.",
293
+ ["app_out_of_date" /* AppOutOfDate */]: "WorldApp is out of date. Please update the app."
270
294
  };
271
295
 
272
296
  // helpers/send-webview-event.ts
@@ -335,11 +359,44 @@ var validateWalletAuthCommandInput = (params) => {
335
359
  return { valid: true };
336
360
  };
337
361
 
362
+ // helpers/payment/client.ts
363
+ var tokenToDecimals = (amount, token) => {
364
+ const decimals = TokenDecimals[token];
365
+ if (decimals === void 0) {
366
+ throw new Error(`Invalid token: ${token}`);
367
+ }
368
+ const factor = 10 ** decimals;
369
+ const result = amount * factor;
370
+ if (!Number.isInteger(result)) {
371
+ throw new Error(`The resulting amount is not a whole number: ${result}`);
372
+ }
373
+ return result;
374
+ };
375
+ var validatePaymentPayload = (payload) => {
376
+ if (payload.tokens.some(
377
+ (token) => token.symbol == "USDCE" && parseFloat(token.token_amount) < 0.1
378
+ )) {
379
+ console.error("USDCE amount should be greater than $0.1");
380
+ return false;
381
+ }
382
+ if (payload.reference.length > 36) {
383
+ console.error("Reference must not exceed 36 characters");
384
+ return false;
385
+ }
386
+ return true;
387
+ };
388
+
338
389
  // minikit.ts
339
390
  var sendMiniKitEvent = (payload) => {
340
391
  sendWebviewEvent(payload);
341
392
  };
342
393
  var _MiniKit = class _MiniKit {
394
+ static sendInit() {
395
+ sendWebviewEvent({
396
+ command: "init",
397
+ payload: { version: this.MINIKIT_VERSION }
398
+ });
399
+ }
343
400
  static subscribe(event, handler) {
344
401
  this.listeners[event] = handler;
345
402
  }
@@ -353,14 +410,46 @@ var _MiniKit = class _MiniKit {
353
410
  }
354
411
  this.listeners[event](payload);
355
412
  }
413
+ static commandsValid(input) {
414
+ return input.every(
415
+ (command) => command.supported_versions.includes(this.commandVersion[command.name])
416
+ );
417
+ }
356
418
  static install() {
357
- if (typeof window !== "undefined" && !Boolean(window.MiniKit)) {
358
- try {
359
- window.MiniKit = _MiniKit;
360
- } catch (error) {
361
- console.error("Failed to install MiniKit", error);
362
- return { success: false, error };
363
- }
419
+ if (typeof window === "undefined" || Boolean(window.MiniKit)) {
420
+ return {
421
+ success: false,
422
+ errorCode: "already_installed" /* AlreadyInstalled */,
423
+ errorMessage: MiniKitInstallErrorMessage["already_installed" /* AlreadyInstalled */]
424
+ };
425
+ }
426
+ if (!window.WorldApp) {
427
+ return {
428
+ success: false,
429
+ errorCode: "outside_of_worldapp" /* OutsideOfWorldApp */,
430
+ errorMessage: MiniKitInstallErrorMessage["outside_of_worldapp" /* OutsideOfWorldApp */]
431
+ };
432
+ }
433
+ if (!this.commandsValid(window.WorldApp.supported_commands)) {
434
+ return {
435
+ success: false,
436
+ errorCode: "app_out_of_date" /* AppOutOfDate */,
437
+ errorMessage: MiniKitInstallErrorMessage["app_out_of_date" /* AppOutOfDate */]
438
+ };
439
+ }
440
+ try {
441
+ window.MiniKit = _MiniKit;
442
+ this.sendInit();
443
+ } catch (error) {
444
+ console.error(
445
+ MiniKitInstallErrorMessage["unknown" /* Unknown */],
446
+ error
447
+ );
448
+ return {
449
+ success: false,
450
+ errorCode: "unknown" /* Unknown */,
451
+ errorMessage: MiniKitInstallErrorMessage["unknown" /* Unknown */]
452
+ };
364
453
  }
365
454
  return { success: true };
366
455
  }
@@ -370,6 +459,12 @@ var _MiniKit = class _MiniKit {
370
459
  return true;
371
460
  }
372
461
  };
462
+ _MiniKit.MINIKIT_VERSION = 1;
463
+ _MiniKit.commandVersion = {
464
+ ["verify" /* Verify */]: 1,
465
+ ["pay" /* Pay */]: 1,
466
+ ["wallet-auth" /* WalletAuth */]: 1
467
+ };
373
468
  _MiniKit.listeners = {
374
469
  ["miniapp-verify-action" /* MiniAppVerifyAction */]: () => {
375
470
  },
@@ -387,7 +482,11 @@ _MiniKit.commands = {
387
482
  verification_level: payload.verification_level || import_idkit_core3.VerificationLevel.Orb,
388
483
  timestamp
389
484
  };
390
- sendMiniKitEvent({ command: "verify" /* Verify */, payload: eventPayload });
485
+ sendMiniKitEvent({
486
+ command: "verify" /* Verify */,
487
+ version: _MiniKit.commandVersion["verify" /* Verify */],
488
+ payload: eventPayload
489
+ });
391
490
  return eventPayload;
392
491
  },
393
492
  pay: (payload) => {
@@ -397,8 +496,7 @@ _MiniKit.commands = {
397
496
  );
398
497
  return null;
399
498
  }
400
- if (payload.reference.length > 36) {
401
- console.error("Reference must not exceed 36 characters");
499
+ if (!validatePaymentPayload(payload)) {
402
500
  return null;
403
501
  }
404
502
  const network = "optimism" /* Optimism */;
@@ -408,6 +506,7 @@ _MiniKit.commands = {
408
506
  };
409
507
  sendMiniKitEvent({
410
508
  command: "pay" /* Pay */,
509
+ version: _MiniKit.commandVersion["pay" /* Pay */],
411
510
  payload: eventPayload
412
511
  });
413
512
  return eventPayload;
@@ -451,6 +550,7 @@ _MiniKit.commands = {
451
550
  const walletAuthPayload = { siweMessage };
452
551
  sendMiniKitEvent({
453
552
  command: "wallet-auth" /* WalletAuth */,
553
+ version: _MiniKit.commandVersion["wallet-auth" /* WalletAuth */],
454
554
  payload: walletAuthPayload
455
555
  });
456
556
  return walletAuthPayload;
@@ -461,29 +561,19 @@ _MiniKit.commands = {
461
561
  };
462
562
  var MiniKit = _MiniKit;
463
563
 
464
- // helpers/payment/client.ts
465
- var tokenToDecimals = (amount, token) => {
466
- const decimals = TokenDecimals[token];
467
- if (decimals === void 0) {
468
- throw new Error(`Invalid token: ${token}`);
469
- }
470
- const factor = 10 ** decimals;
471
- const result = amount * factor;
472
- if (!Number.isInteger(result)) {
473
- throw new Error(`The resulting amount is not a whole number: ${result}`);
474
- }
475
- return result;
476
- };
477
-
478
564
  // index.ts
479
565
  var import_idkit_core4 = require("@worldcoin/idkit-core");
566
+ var import_backend = require("@worldcoin/idkit-core/backend");
480
567
  // Annotate the CommonJS export names for ESM import in node:
481
568
  0 && (module.exports = {
482
569
  Command,
483
570
  MiniKit,
571
+ MiniKitInstallErrorCode,
572
+ MiniKitInstallErrorMessage,
484
573
  Network,
485
574
  PaymentErrorCodes,
486
575
  PaymentErrorMessage,
576
+ PaymentValidationErrors,
487
577
  ResponseEvent,
488
578
  SAFE_CONTRACT_ABI,
489
579
  TokenDecimals,
@@ -496,5 +586,6 @@ var import_idkit_core4 = require("@worldcoin/idkit-core");
496
586
  generateNonce,
497
587
  parseSiweMessage,
498
588
  tokenToDecimals,
589
+ verifyCloudProof,
499
590
  verifySiweMessage
500
591
  });
package/build/index.d.cts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { ethers } from 'ethers';
2
2
  import { AppErrorCodes, VerificationLevel } from '@worldcoin/idkit-core';
3
- export { AppErrorCodes as VerificationErrorCodes, VerificationLevel } from '@worldcoin/idkit-core';
3
+ export { ISuccessResult, AppErrorCodes as VerificationErrorCodes, VerificationLevel } from '@worldcoin/idkit-core';
4
4
  import { IDKitConfig, VerificationLevel as VerificationLevel$1 } from '@worldcoin/idkit-core/*';
5
+ export { IVerifyResponse, verifyCloudProof } from '@worldcoin/idkit-core/backend';
5
6
 
6
7
  type SiweMessage = {
7
8
  scheme?: string;
@@ -36,28 +37,39 @@ declare enum PaymentErrorCodes {
36
37
  InvalidReceiver = "invalid_receiver",
37
38
  InsufficientBalance = "insufficient_balance",
38
39
  TransactionFailed = "transaction_failed",
39
- GenericError = "generic_error"
40
+ GenericError = "generic_error",
41
+ UserBlocked = "user_blocked"
40
42
  }
41
- declare enum PaymentErrorMessage {
43
+ declare const PaymentErrorMessage: Record<PaymentErrorCodes, string>;
44
+ declare enum PaymentValidationErrors {
42
45
  MalformedRequest = "There was a problem with this request. Please try again or contact the app owner.",
43
- PaymentRejected = "You\u2019ve cancelled the payment in World App.",
44
- InvalidReceiver = "The receiver address is invalid. Please contact the app owner.",
45
- InsufficientBalance = "You do not have enough balance to complete this transaction.",
46
- TransactionFailed = "The transaction failed. Please try again.",
47
46
  InvalidTokenAddress = "The token address is invalid. Please contact the app owner.",
48
47
  InvalidAppId = "The app ID is invalid. Please contact the app owner.",
49
- GenericError = "Something unexpected went wrong. Please try again.",
50
48
  DuplicateReference = "This reference ID already exists please generate a new one and try again."
51
49
  }
52
50
  declare enum WalletAuthErrorCodes {
53
- InvalidAddress = "invalid_address",
54
51
  MalformedRequest = "malformed_request",
55
- UserRejected = "user_rejected"
52
+ UserRejected = "user_rejected",
53
+ GenericError = "generic_error"
56
54
  }
57
55
  declare const WalletAuthErrorMessage: {
58
- invalid_address: string;
59
56
  malformed_request: string;
60
57
  user_rejected: string;
58
+ generic_error: string;
59
+ };
60
+ declare enum MiniKitInstallErrorCode {
61
+ Unknown = "unknown",
62
+ AlreadyInstalled = "already_installed",
63
+ OutsideOfWorldApp = "outside_of_worldapp",
64
+ NotOnClient = "not_on_client",
65
+ AppOutOfDate = "app_out_of_date"
66
+ }
67
+ declare const MiniKitInstallErrorMessage: {
68
+ unknown: string;
69
+ already_installed: string;
70
+ outside_of_worldapp: string;
71
+ not_on_client: string;
72
+ app_out_of_date: string;
61
73
  };
62
74
 
63
75
  declare enum ResponseEvent {
@@ -71,10 +83,12 @@ type MiniAppVerifyActionSuccessPayload = {
71
83
  merkle_root: string;
72
84
  nullifier_hash: string;
73
85
  verification_level: VerificationLevel;
86
+ version: number;
74
87
  };
75
88
  type MiniAppVerifyActionErrorPayload = {
76
89
  status: "error";
77
90
  error_code: AppErrorCodes;
91
+ version: number;
78
92
  };
79
93
  type MiniAppVerifyActionPayload = MiniAppVerifyActionSuccessPayload | MiniAppVerifyActionErrorPayload;
80
94
  type MiniAppPaymentSuccessEventPayload = {
@@ -85,10 +99,12 @@ type MiniAppPaymentSuccessEventPayload = {
85
99
  from: string;
86
100
  chain: Network;
87
101
  timestamp: string;
102
+ version: number;
88
103
  };
89
104
  type MiniAppPaymentErrorPayload = {
90
105
  status: "error";
91
106
  error_code: PaymentErrorCodes;
107
+ version: number;
92
108
  };
93
109
  type MiniAppPaymentPayload = MiniAppPaymentSuccessEventPayload | MiniAppPaymentErrorPayload;
94
110
  type MiniAppWalletAuthSuccessPayload = {
@@ -96,11 +112,13 @@ type MiniAppWalletAuthSuccessPayload = {
96
112
  message: string;
97
113
  signature: string;
98
114
  address: string;
115
+ version: number;
99
116
  };
100
117
  type MiniAppWalletAuthErrorPayload = {
101
118
  status: "error";
102
119
  error_code: WalletAuthErrorCodes;
103
120
  details: (typeof WalletAuthErrorMessage)[WalletAuthErrorCodes];
121
+ version: number;
104
122
  };
105
123
  type EventPayload<T extends ResponseEvent = ResponseEvent> = T extends ResponseEvent.MiniAppVerifyAction ? MiniAppVerifyActionPayload : MiniAppPaymentPayload;
106
124
  type EventHandler<E extends ResponseEvent = ResponseEvent> = <T extends EventPayload<E>>(data: T) => void;
@@ -132,11 +150,14 @@ type VerifyCommandInput = {
132
150
  signal?: IDKitConfig["signal"];
133
151
  verification_level?: VerificationLevel$1;
134
152
  };
153
+ type TokensPayload = {
154
+ symbol: Tokens;
155
+ token_amount: string;
156
+ };
135
157
  type PayCommandInput = {
136
158
  reference: string;
137
159
  to: string;
138
- token_amount: string;
139
- token: Tokens;
160
+ tokens: TokensPayload[];
140
161
  network?: Network;
141
162
  description: string;
142
163
  };
@@ -156,19 +177,24 @@ type PayCommandPayload = PayCommandInput & {
156
177
  type WalletAuthPayload = {
157
178
  siweMessage: string;
158
179
  };
180
+ type MiniKitInstallReturnType = {
181
+ success: true;
182
+ } | {
183
+ success: false;
184
+ errorCode: MiniKitInstallErrorCode;
185
+ errorMessage: (typeof MiniKitInstallErrorMessage)[MiniKitInstallErrorCode];
186
+ };
159
187
 
160
188
  declare class MiniKit {
189
+ private static readonly MINIKIT_VERSION;
190
+ private static readonly commandVersion;
161
191
  private static listeners;
192
+ private static sendInit;
162
193
  static subscribe<E extends ResponseEvent>(event: E, handler: EventHandler<E>): void;
163
194
  static unsubscribe(event: ResponseEvent): void;
164
195
  static trigger(event: ResponseEvent, payload: EventPayload): void;
165
- static install(): {
166
- success: boolean;
167
- error: unknown;
168
- } | {
169
- success: boolean;
170
- error?: undefined;
171
- };
196
+ private static commandsValid;
197
+ static install(): MiniKitInstallReturnType;
172
198
  static isInstalled(debug?: boolean): boolean;
173
199
  static commands: {
174
200
  verify: (payload: VerifyCommandInput) => VerifyCommandPayload;
@@ -180,4 +206,4 @@ declare class MiniKit {
180
206
 
181
207
  declare const tokenToDecimals: (amount: number, token: Tokens) => number;
182
208
 
183
- export { Command, type MiniAppPaymentErrorPayload, type MiniAppPaymentPayload, type MiniAppPaymentSuccessEventPayload, type MiniAppVerifyActionErrorPayload, type MiniAppVerifyActionPayload, type MiniAppVerifyActionSuccessPayload, type MiniAppWalletAuthErrorPayload, type MiniAppWalletAuthSuccessPayload, MiniKit, Network, type PayCommandInput, PaymentErrorCodes, PaymentErrorMessage, ResponseEvent, SAFE_CONTRACT_ABI, type SiweMessage, TokenDecimals, Tokens, VerificationErrorMessage, type VerifyCommandInput, WalletAuthErrorCodes, WalletAuthErrorMessage, generateNonce, parseSiweMessage, tokenToDecimals, verifySiweMessage };
209
+ export { Command, type MiniAppPaymentErrorPayload, type MiniAppPaymentPayload, type MiniAppPaymentSuccessEventPayload, type MiniAppVerifyActionErrorPayload, type MiniAppVerifyActionPayload, type MiniAppVerifyActionSuccessPayload, type MiniAppWalletAuthErrorPayload, type MiniAppWalletAuthSuccessPayload, MiniKit, MiniKitInstallErrorCode, MiniKitInstallErrorMessage, Network, type PayCommandInput, PaymentErrorCodes, PaymentErrorMessage, PaymentValidationErrors, ResponseEvent, SAFE_CONTRACT_ABI, type SiweMessage, TokenDecimals, Tokens, VerificationErrorMessage, type VerifyCommandInput, WalletAuthErrorCodes, WalletAuthErrorMessage, generateNonce, parseSiweMessage, tokenToDecimals, verifySiweMessage };
package/build/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { ethers } from 'ethers';
2
2
  import { AppErrorCodes, VerificationLevel } from '@worldcoin/idkit-core';
3
- export { AppErrorCodes as VerificationErrorCodes, VerificationLevel } from '@worldcoin/idkit-core';
3
+ export { ISuccessResult, AppErrorCodes as VerificationErrorCodes, VerificationLevel } from '@worldcoin/idkit-core';
4
4
  import { IDKitConfig, VerificationLevel as VerificationLevel$1 } from '@worldcoin/idkit-core/*';
5
+ export { IVerifyResponse, verifyCloudProof } from '@worldcoin/idkit-core/backend';
5
6
 
6
7
  type SiweMessage = {
7
8
  scheme?: string;
@@ -36,28 +37,39 @@ declare enum PaymentErrorCodes {
36
37
  InvalidReceiver = "invalid_receiver",
37
38
  InsufficientBalance = "insufficient_balance",
38
39
  TransactionFailed = "transaction_failed",
39
- GenericError = "generic_error"
40
+ GenericError = "generic_error",
41
+ UserBlocked = "user_blocked"
40
42
  }
41
- declare enum PaymentErrorMessage {
43
+ declare const PaymentErrorMessage: Record<PaymentErrorCodes, string>;
44
+ declare enum PaymentValidationErrors {
42
45
  MalformedRequest = "There was a problem with this request. Please try again or contact the app owner.",
43
- PaymentRejected = "You\u2019ve cancelled the payment in World App.",
44
- InvalidReceiver = "The receiver address is invalid. Please contact the app owner.",
45
- InsufficientBalance = "You do not have enough balance to complete this transaction.",
46
- TransactionFailed = "The transaction failed. Please try again.",
47
46
  InvalidTokenAddress = "The token address is invalid. Please contact the app owner.",
48
47
  InvalidAppId = "The app ID is invalid. Please contact the app owner.",
49
- GenericError = "Something unexpected went wrong. Please try again.",
50
48
  DuplicateReference = "This reference ID already exists please generate a new one and try again."
51
49
  }
52
50
  declare enum WalletAuthErrorCodes {
53
- InvalidAddress = "invalid_address",
54
51
  MalformedRequest = "malformed_request",
55
- UserRejected = "user_rejected"
52
+ UserRejected = "user_rejected",
53
+ GenericError = "generic_error"
56
54
  }
57
55
  declare const WalletAuthErrorMessage: {
58
- invalid_address: string;
59
56
  malformed_request: string;
60
57
  user_rejected: string;
58
+ generic_error: string;
59
+ };
60
+ declare enum MiniKitInstallErrorCode {
61
+ Unknown = "unknown",
62
+ AlreadyInstalled = "already_installed",
63
+ OutsideOfWorldApp = "outside_of_worldapp",
64
+ NotOnClient = "not_on_client",
65
+ AppOutOfDate = "app_out_of_date"
66
+ }
67
+ declare const MiniKitInstallErrorMessage: {
68
+ unknown: string;
69
+ already_installed: string;
70
+ outside_of_worldapp: string;
71
+ not_on_client: string;
72
+ app_out_of_date: string;
61
73
  };
62
74
 
63
75
  declare enum ResponseEvent {
@@ -71,10 +83,12 @@ type MiniAppVerifyActionSuccessPayload = {
71
83
  merkle_root: string;
72
84
  nullifier_hash: string;
73
85
  verification_level: VerificationLevel;
86
+ version: number;
74
87
  };
75
88
  type MiniAppVerifyActionErrorPayload = {
76
89
  status: "error";
77
90
  error_code: AppErrorCodes;
91
+ version: number;
78
92
  };
79
93
  type MiniAppVerifyActionPayload = MiniAppVerifyActionSuccessPayload | MiniAppVerifyActionErrorPayload;
80
94
  type MiniAppPaymentSuccessEventPayload = {
@@ -85,10 +99,12 @@ type MiniAppPaymentSuccessEventPayload = {
85
99
  from: string;
86
100
  chain: Network;
87
101
  timestamp: string;
102
+ version: number;
88
103
  };
89
104
  type MiniAppPaymentErrorPayload = {
90
105
  status: "error";
91
106
  error_code: PaymentErrorCodes;
107
+ version: number;
92
108
  };
93
109
  type MiniAppPaymentPayload = MiniAppPaymentSuccessEventPayload | MiniAppPaymentErrorPayload;
94
110
  type MiniAppWalletAuthSuccessPayload = {
@@ -96,11 +112,13 @@ type MiniAppWalletAuthSuccessPayload = {
96
112
  message: string;
97
113
  signature: string;
98
114
  address: string;
115
+ version: number;
99
116
  };
100
117
  type MiniAppWalletAuthErrorPayload = {
101
118
  status: "error";
102
119
  error_code: WalletAuthErrorCodes;
103
120
  details: (typeof WalletAuthErrorMessage)[WalletAuthErrorCodes];
121
+ version: number;
104
122
  };
105
123
  type EventPayload<T extends ResponseEvent = ResponseEvent> = T extends ResponseEvent.MiniAppVerifyAction ? MiniAppVerifyActionPayload : MiniAppPaymentPayload;
106
124
  type EventHandler<E extends ResponseEvent = ResponseEvent> = <T extends EventPayload<E>>(data: T) => void;
@@ -132,11 +150,14 @@ type VerifyCommandInput = {
132
150
  signal?: IDKitConfig["signal"];
133
151
  verification_level?: VerificationLevel$1;
134
152
  };
153
+ type TokensPayload = {
154
+ symbol: Tokens;
155
+ token_amount: string;
156
+ };
135
157
  type PayCommandInput = {
136
158
  reference: string;
137
159
  to: string;
138
- token_amount: string;
139
- token: Tokens;
160
+ tokens: TokensPayload[];
140
161
  network?: Network;
141
162
  description: string;
142
163
  };
@@ -156,19 +177,24 @@ type PayCommandPayload = PayCommandInput & {
156
177
  type WalletAuthPayload = {
157
178
  siweMessage: string;
158
179
  };
180
+ type MiniKitInstallReturnType = {
181
+ success: true;
182
+ } | {
183
+ success: false;
184
+ errorCode: MiniKitInstallErrorCode;
185
+ errorMessage: (typeof MiniKitInstallErrorMessage)[MiniKitInstallErrorCode];
186
+ };
159
187
 
160
188
  declare class MiniKit {
189
+ private static readonly MINIKIT_VERSION;
190
+ private static readonly commandVersion;
161
191
  private static listeners;
192
+ private static sendInit;
162
193
  static subscribe<E extends ResponseEvent>(event: E, handler: EventHandler<E>): void;
163
194
  static unsubscribe(event: ResponseEvent): void;
164
195
  static trigger(event: ResponseEvent, payload: EventPayload): void;
165
- static install(): {
166
- success: boolean;
167
- error: unknown;
168
- } | {
169
- success: boolean;
170
- error?: undefined;
171
- };
196
+ private static commandsValid;
197
+ static install(): MiniKitInstallReturnType;
172
198
  static isInstalled(debug?: boolean): boolean;
173
199
  static commands: {
174
200
  verify: (payload: VerifyCommandInput) => VerifyCommandPayload;
@@ -180,4 +206,4 @@ declare class MiniKit {
180
206
 
181
207
  declare const tokenToDecimals: (amount: number, token: Tokens) => number;
182
208
 
183
- export { Command, type MiniAppPaymentErrorPayload, type MiniAppPaymentPayload, type MiniAppPaymentSuccessEventPayload, type MiniAppVerifyActionErrorPayload, type MiniAppVerifyActionPayload, type MiniAppVerifyActionSuccessPayload, type MiniAppWalletAuthErrorPayload, type MiniAppWalletAuthSuccessPayload, MiniKit, Network, type PayCommandInput, PaymentErrorCodes, PaymentErrorMessage, ResponseEvent, SAFE_CONTRACT_ABI, type SiweMessage, TokenDecimals, Tokens, VerificationErrorMessage, type VerifyCommandInput, WalletAuthErrorCodes, WalletAuthErrorMessage, generateNonce, parseSiweMessage, tokenToDecimals, verifySiweMessage };
209
+ export { Command, type MiniAppPaymentErrorPayload, type MiniAppPaymentPayload, type MiniAppPaymentSuccessEventPayload, type MiniAppVerifyActionErrorPayload, type MiniAppVerifyActionPayload, type MiniAppVerifyActionSuccessPayload, type MiniAppWalletAuthErrorPayload, type MiniAppWalletAuthSuccessPayload, MiniKit, MiniKitInstallErrorCode, MiniKitInstallErrorMessage, Network, type PayCommandInput, PaymentErrorCodes, PaymentErrorMessage, PaymentValidationErrors, ResponseEvent, SAFE_CONTRACT_ABI, type SiweMessage, TokenDecimals, Tokens, VerificationErrorMessage, type VerifyCommandInput, WalletAuthErrorCodes, WalletAuthErrorMessage, generateNonce, parseSiweMessage, tokenToDecimals, verifySiweMessage };
package/build/index.js CHANGED
@@ -200,30 +200,50 @@ var PaymentErrorCodes = /* @__PURE__ */ ((PaymentErrorCodes2) => {
200
200
  PaymentErrorCodes2["InsufficientBalance"] = "insufficient_balance";
201
201
  PaymentErrorCodes2["TransactionFailed"] = "transaction_failed";
202
202
  PaymentErrorCodes2["GenericError"] = "generic_error";
203
+ PaymentErrorCodes2["UserBlocked"] = "user_blocked";
203
204
  return PaymentErrorCodes2;
204
205
  })(PaymentErrorCodes || {});
205
- var PaymentErrorMessage = /* @__PURE__ */ ((PaymentErrorMessage2) => {
206
- PaymentErrorMessage2["MalformedRequest"] = "There was a problem with this request. Please try again or contact the app owner.";
207
- PaymentErrorMessage2["PaymentRejected"] = "You\u2019ve cancelled the payment in World App.";
208
- PaymentErrorMessage2["InvalidReceiver"] = "The receiver address is invalid. Please contact the app owner.";
209
- PaymentErrorMessage2["InsufficientBalance"] = "You do not have enough balance to complete this transaction.";
210
- PaymentErrorMessage2["TransactionFailed"] = "The transaction failed. Please try again.";
211
- PaymentErrorMessage2["InvalidTokenAddress"] = "The token address is invalid. Please contact the app owner.";
212
- PaymentErrorMessage2["InvalidAppId"] = "The app ID is invalid. Please contact the app owner.";
213
- PaymentErrorMessage2["GenericError"] = "Something unexpected went wrong. Please try again.";
214
- PaymentErrorMessage2["DuplicateReference"] = "This reference ID already exists please generate a new one and try again.";
215
- return PaymentErrorMessage2;
216
- })(PaymentErrorMessage || {});
206
+ var PaymentErrorMessage = {
207
+ ["input_error" /* InputError */]: "There was a problem with this request. Please try again or contact the app owner.",
208
+ ["payment_rejected" /* PaymentRejected */]: "You\u2019ve cancelled the payment in World App.",
209
+ ["invalid_receiver" /* InvalidReceiver */]: "The receiver address is invalid. Please contact the app owner.",
210
+ ["insufficient_balance" /* InsufficientBalance */]: "You do not have enough balance to complete this transaction.",
211
+ ["transaction_failed" /* TransactionFailed */]: "The transaction failed. Please try again.",
212
+ ["generic_error" /* GenericError */]: "Something unexpected went wrong. Please try again.",
213
+ ["user_blocked" /* UserBlocked */]: "User's region is blocked from making payments."
214
+ };
215
+ var PaymentValidationErrors = /* @__PURE__ */ ((PaymentValidationErrors2) => {
216
+ PaymentValidationErrors2["MalformedRequest"] = "There was a problem with this request. Please try again or contact the app owner.";
217
+ PaymentValidationErrors2["InvalidTokenAddress"] = "The token address is invalid. Please contact the app owner.";
218
+ PaymentValidationErrors2["InvalidAppId"] = "The app ID is invalid. Please contact the app owner.";
219
+ PaymentValidationErrors2["DuplicateReference"] = "This reference ID already exists please generate a new one and try again.";
220
+ return PaymentValidationErrors2;
221
+ })(PaymentValidationErrors || {});
217
222
  var WalletAuthErrorCodes = /* @__PURE__ */ ((WalletAuthErrorCodes2) => {
218
- WalletAuthErrorCodes2["InvalidAddress"] = "invalid_address";
219
223
  WalletAuthErrorCodes2["MalformedRequest"] = "malformed_request";
220
224
  WalletAuthErrorCodes2["UserRejected"] = "user_rejected";
225
+ WalletAuthErrorCodes2["GenericError"] = "generic_error";
221
226
  return WalletAuthErrorCodes2;
222
227
  })(WalletAuthErrorCodes || {});
223
228
  var WalletAuthErrorMessage = {
224
- ["invalid_address" /* InvalidAddress */]: "The specified address is not valid for the connected wallet.",
225
229
  ["malformed_request" /* MalformedRequest */]: "Provided parameters in the request are invalid.",
226
- ["user_rejected" /* UserRejected */]: "User rejected the request."
230
+ ["user_rejected" /* UserRejected */]: "User rejected the request.",
231
+ ["generic_error" /* GenericError */]: "Something unexpected went wrong."
232
+ };
233
+ var MiniKitInstallErrorCode = /* @__PURE__ */ ((MiniKitInstallErrorCode2) => {
234
+ MiniKitInstallErrorCode2["Unknown"] = "unknown";
235
+ MiniKitInstallErrorCode2["AlreadyInstalled"] = "already_installed";
236
+ MiniKitInstallErrorCode2["OutsideOfWorldApp"] = "outside_of_worldapp";
237
+ MiniKitInstallErrorCode2["NotOnClient"] = "not_on_client";
238
+ MiniKitInstallErrorCode2["AppOutOfDate"] = "app_out_of_date";
239
+ return MiniKitInstallErrorCode2;
240
+ })(MiniKitInstallErrorCode || {});
241
+ var MiniKitInstallErrorMessage = {
242
+ ["unknown" /* Unknown */]: "Failed to install MiniKit.",
243
+ ["already_installed" /* AlreadyInstalled */]: "MiniKit is already installed.",
244
+ ["outside_of_worldapp" /* OutsideOfWorldApp */]: "MiniApp launched outside of WorldApp.",
245
+ ["not_on_client" /* NotOnClient */]: "Window object is not available.",
246
+ ["app_out_of_date" /* AppOutOfDate */]: "WorldApp is out of date. Please update the app."
227
247
  };
228
248
 
229
249
  // helpers/send-webview-event.ts
@@ -292,11 +312,44 @@ var validateWalletAuthCommandInput = (params) => {
292
312
  return { valid: true };
293
313
  };
294
314
 
315
+ // helpers/payment/client.ts
316
+ var tokenToDecimals = (amount, token) => {
317
+ const decimals = TokenDecimals[token];
318
+ if (decimals === void 0) {
319
+ throw new Error(`Invalid token: ${token}`);
320
+ }
321
+ const factor = 10 ** decimals;
322
+ const result = amount * factor;
323
+ if (!Number.isInteger(result)) {
324
+ throw new Error(`The resulting amount is not a whole number: ${result}`);
325
+ }
326
+ return result;
327
+ };
328
+ var validatePaymentPayload = (payload) => {
329
+ if (payload.tokens.some(
330
+ (token) => token.symbol == "USDCE" && parseFloat(token.token_amount) < 0.1
331
+ )) {
332
+ console.error("USDCE amount should be greater than $0.1");
333
+ return false;
334
+ }
335
+ if (payload.reference.length > 36) {
336
+ console.error("Reference must not exceed 36 characters");
337
+ return false;
338
+ }
339
+ return true;
340
+ };
341
+
295
342
  // minikit.ts
296
343
  var sendMiniKitEvent = (payload) => {
297
344
  sendWebviewEvent(payload);
298
345
  };
299
346
  var _MiniKit = class _MiniKit {
347
+ static sendInit() {
348
+ sendWebviewEvent({
349
+ command: "init",
350
+ payload: { version: this.MINIKIT_VERSION }
351
+ });
352
+ }
300
353
  static subscribe(event, handler) {
301
354
  this.listeners[event] = handler;
302
355
  }
@@ -310,14 +363,46 @@ var _MiniKit = class _MiniKit {
310
363
  }
311
364
  this.listeners[event](payload);
312
365
  }
366
+ static commandsValid(input) {
367
+ return input.every(
368
+ (command) => command.supported_versions.includes(this.commandVersion[command.name])
369
+ );
370
+ }
313
371
  static install() {
314
- if (typeof window !== "undefined" && !Boolean(window.MiniKit)) {
315
- try {
316
- window.MiniKit = _MiniKit;
317
- } catch (error) {
318
- console.error("Failed to install MiniKit", error);
319
- return { success: false, error };
320
- }
372
+ if (typeof window === "undefined" || Boolean(window.MiniKit)) {
373
+ return {
374
+ success: false,
375
+ errorCode: "already_installed" /* AlreadyInstalled */,
376
+ errorMessage: MiniKitInstallErrorMessage["already_installed" /* AlreadyInstalled */]
377
+ };
378
+ }
379
+ if (!window.WorldApp) {
380
+ return {
381
+ success: false,
382
+ errorCode: "outside_of_worldapp" /* OutsideOfWorldApp */,
383
+ errorMessage: MiniKitInstallErrorMessage["outside_of_worldapp" /* OutsideOfWorldApp */]
384
+ };
385
+ }
386
+ if (!this.commandsValid(window.WorldApp.supported_commands)) {
387
+ return {
388
+ success: false,
389
+ errorCode: "app_out_of_date" /* AppOutOfDate */,
390
+ errorMessage: MiniKitInstallErrorMessage["app_out_of_date" /* AppOutOfDate */]
391
+ };
392
+ }
393
+ try {
394
+ window.MiniKit = _MiniKit;
395
+ this.sendInit();
396
+ } catch (error) {
397
+ console.error(
398
+ MiniKitInstallErrorMessage["unknown" /* Unknown */],
399
+ error
400
+ );
401
+ return {
402
+ success: false,
403
+ errorCode: "unknown" /* Unknown */,
404
+ errorMessage: MiniKitInstallErrorMessage["unknown" /* Unknown */]
405
+ };
321
406
  }
322
407
  return { success: true };
323
408
  }
@@ -327,6 +412,12 @@ var _MiniKit = class _MiniKit {
327
412
  return true;
328
413
  }
329
414
  };
415
+ _MiniKit.MINIKIT_VERSION = 1;
416
+ _MiniKit.commandVersion = {
417
+ ["verify" /* Verify */]: 1,
418
+ ["pay" /* Pay */]: 1,
419
+ ["wallet-auth" /* WalletAuth */]: 1
420
+ };
330
421
  _MiniKit.listeners = {
331
422
  ["miniapp-verify-action" /* MiniAppVerifyAction */]: () => {
332
423
  },
@@ -344,7 +435,11 @@ _MiniKit.commands = {
344
435
  verification_level: payload.verification_level || VerificationLevel.Orb,
345
436
  timestamp
346
437
  };
347
- sendMiniKitEvent({ command: "verify" /* Verify */, payload: eventPayload });
438
+ sendMiniKitEvent({
439
+ command: "verify" /* Verify */,
440
+ version: _MiniKit.commandVersion["verify" /* Verify */],
441
+ payload: eventPayload
442
+ });
348
443
  return eventPayload;
349
444
  },
350
445
  pay: (payload) => {
@@ -354,8 +449,7 @@ _MiniKit.commands = {
354
449
  );
355
450
  return null;
356
451
  }
357
- if (payload.reference.length > 36) {
358
- console.error("Reference must not exceed 36 characters");
452
+ if (!validatePaymentPayload(payload)) {
359
453
  return null;
360
454
  }
361
455
  const network = "optimism" /* Optimism */;
@@ -365,6 +459,7 @@ _MiniKit.commands = {
365
459
  };
366
460
  sendMiniKitEvent({
367
461
  command: "pay" /* Pay */,
462
+ version: _MiniKit.commandVersion["pay" /* Pay */],
368
463
  payload: eventPayload
369
464
  });
370
465
  return eventPayload;
@@ -408,6 +503,7 @@ _MiniKit.commands = {
408
503
  const walletAuthPayload = { siweMessage };
409
504
  sendMiniKitEvent({
410
505
  command: "wallet-auth" /* WalletAuth */,
506
+ version: _MiniKit.commandVersion["wallet-auth" /* WalletAuth */],
411
507
  payload: walletAuthPayload
412
508
  });
413
509
  return walletAuthPayload;
@@ -418,28 +514,20 @@ _MiniKit.commands = {
418
514
  };
419
515
  var MiniKit = _MiniKit;
420
516
 
421
- // helpers/payment/client.ts
422
- var tokenToDecimals = (amount, token) => {
423
- const decimals = TokenDecimals[token];
424
- if (decimals === void 0) {
425
- throw new Error(`Invalid token: ${token}`);
426
- }
427
- const factor = 10 ** decimals;
428
- const result = amount * factor;
429
- if (!Number.isInteger(result)) {
430
- throw new Error(`The resulting amount is not a whole number: ${result}`);
431
- }
432
- return result;
433
- };
434
-
435
517
  // index.ts
436
518
  import { VerificationLevel as VerificationLevel2 } from "@worldcoin/idkit-core";
519
+ import {
520
+ verifyCloudProof
521
+ } from "@worldcoin/idkit-core/backend";
437
522
  export {
438
523
  Command,
439
524
  MiniKit,
525
+ MiniKitInstallErrorCode,
526
+ MiniKitInstallErrorMessage,
440
527
  Network,
441
528
  PaymentErrorCodes,
442
529
  PaymentErrorMessage,
530
+ PaymentValidationErrors,
443
531
  ResponseEvent,
444
532
  SAFE_CONTRACT_ABI,
445
533
  TokenDecimals,
@@ -452,5 +540,6 @@ export {
452
540
  generateNonce,
453
541
  parseSiweMessage,
454
542
  tokenToDecimals,
543
+ verifyCloudProof,
455
544
  verifySiweMessage
456
545
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@worldcoin/minikit-js",
3
- "version": "0.0.21-internal-alpha",
3
+ "version": "0.0.23-internal-alpha",
4
4
  "homepage": "https://docs.worldcoin.org/id/minikit",
5
5
  "description": "Internal Alpha: Mini-kit JS is a lightweight sdk for building mini-apps compatible with World App",
6
6
  "license": "MIT",
@@ -24,6 +24,13 @@
24
24
  "minikit",
25
25
  "miniapps"
26
26
  ],
27
+ "scripts": {
28
+ "build": "tsup",
29
+ "dev": "tsup --watch",
30
+ "lint": "eslint ./ --ext .ts",
31
+ "prepublishOnly": "npm run build",
32
+ "typecheck": "tsc --noEmit"
33
+ },
27
34
  "dependencies": {
28
35
  "@worldcoin/idkit-core": "^1.2.0"
29
36
  },
@@ -37,12 +44,6 @@
37
44
  "typescript": "^5.4.5"
38
45
  },
39
46
  "peerDependencies": {
40
- "ethers": "^5.6.8 || ^6.0.8"
41
- },
42
- "scripts": {
43
- "build": "tsup",
44
- "dev": "tsup --watch",
45
- "lint": "eslint ./ --ext .ts",
46
- "typecheck": "tsc --noEmit"
47
+ "ethers": "^6.0.8"
47
48
  }
48
- }
49
+ }