@worldcoin/minikit-js 1.4.0 → 1.5.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/build/index.cjs CHANGED
@@ -28,6 +28,9 @@ __export(core_exports, {
28
28
  PaymentErrorCodes: () => PaymentErrorCodes,
29
29
  PaymentErrorMessage: () => PaymentErrorMessage,
30
30
  PaymentValidationErrors: () => PaymentValidationErrors,
31
+ Permission: () => Permission,
32
+ RequestPermissionErrorCodes: () => RequestPermissionErrorCodes,
33
+ RequestPermissionErrorMessage: () => RequestPermissionErrorMessage,
31
34
  ResponseEvent: () => ResponseEvent,
32
35
  SAFE_CONTRACT_ABI: () => SAFE_CONTRACT_ABI,
33
36
  SendTransactionErrorCodes: () => SendTransactionErrorCodes,
@@ -53,44 +56,15 @@ __export(core_exports, {
53
56
  });
54
57
  module.exports = __toCommonJS(core_exports);
55
58
 
56
- // helpers/send-webview-event.ts
57
- var sendWebviewEvent = (payload) => {
58
- if (window.webkit) {
59
- window.webkit?.messageHandlers?.minikit?.postMessage?.(payload);
60
- } else if (window.Android) {
61
- window.Android.postMessage?.(JSON.stringify(payload));
62
- }
63
- };
64
-
65
- // types/commands.ts
66
- var Command = /* @__PURE__ */ ((Command2) => {
67
- Command2["Verify"] = "verify";
68
- Command2["Pay"] = "pay";
69
- Command2["WalletAuth"] = "wallet-auth";
70
- Command2["SendTransaction"] = "send-transaction";
71
- Command2["SignMessage"] = "sign-message";
72
- Command2["SignTypedData"] = "sign-typed-data";
73
- Command2["ShareContacts"] = "share-contacts";
74
- return Command2;
75
- })(Command || {});
76
-
77
- // types/responses.ts
78
- var ResponseEvent = /* @__PURE__ */ ((ResponseEvent2) => {
79
- ResponseEvent2["MiniAppVerifyAction"] = "miniapp-verify-action";
80
- ResponseEvent2["MiniAppPayment"] = "miniapp-payment";
81
- ResponseEvent2["MiniAppWalletAuth"] = "miniapp-wallet-auth";
82
- ResponseEvent2["MiniAppSendTransaction"] = "miniapp-send-transaction";
83
- ResponseEvent2["MiniAppSignMessage"] = "miniapp-sign-message";
84
- ResponseEvent2["MiniAppSignTypedData"] = "miniapp-sign-typed-data";
85
- ResponseEvent2["MiniAppShareContacts"] = "miniapp-share-contacts";
86
- return ResponseEvent2;
87
- })(ResponseEvent || {});
59
+ // minikit.ts
60
+ var import_idkit_core3 = require("@worldcoin/idkit-core");
61
+ var import_hashing = require("@worldcoin/idkit-core/hashing");
88
62
 
89
63
  // types/payment.ts
90
- var Tokens = /* @__PURE__ */ ((Tokens2) => {
91
- Tokens2["USDCE"] = "USDCE";
92
- Tokens2["WLD"] = "WLD";
93
- return Tokens2;
64
+ var Tokens = /* @__PURE__ */ ((Tokens3) => {
65
+ Tokens3["USDCE"] = "USDCE";
66
+ Tokens3["WLD"] = "WLD";
67
+ return Tokens3;
94
68
  })(Tokens || {});
95
69
  var TokenDecimals = {
96
70
  ["USDCE" /* USDCE */]: 6,
@@ -102,155 +76,31 @@ var Network = /* @__PURE__ */ ((Network2) => {
102
76
  return Network2;
103
77
  })(Network || {});
104
78
 
105
- // types/errors.ts
106
- var import_idkit_core = require("@worldcoin/idkit-core");
107
- var import_idkit_core2 = require("@worldcoin/idkit-core");
108
- var VerificationErrorMessage = {
109
- [import_idkit_core.AppErrorCodes.VerificationRejected]: "You\u2019ve cancelled the request in World App.",
110
- [import_idkit_core.AppErrorCodes.MaxVerificationsReached]: "You have already verified the maximum number of times for this action.",
111
- [import_idkit_core.AppErrorCodes.CredentialUnavailable]: "It seems you do not have the verification level required by this app.",
112
- [import_idkit_core.AppErrorCodes.MalformedRequest]: "There was a problem with this request. Please try again or contact the app owner.",
113
- [import_idkit_core.AppErrorCodes.InvalidNetwork]: "Invalid network. If you are the app owner, visit docs.worldcoin.org/test for details.",
114
- [import_idkit_core.AppErrorCodes.InclusionProofFailed]: "There was an issue fetching your credential. Please try again.",
115
- [import_idkit_core.AppErrorCodes.InclusionProofPending]: "Your identity is still being registered. Please wait a few minutes and try again.",
116
- [import_idkit_core.AppErrorCodes.UnexpectedResponse]: "Unexpected response from your wallet. Please try again.",
117
- [import_idkit_core.AppErrorCodes.FailedByHostApp]: "Verification failed by the app. Please contact the app owner for details.",
118
- [import_idkit_core.AppErrorCodes.GenericError]: "Something unexpected went wrong. Please try again.",
119
- [import_idkit_core.AppErrorCodes.ConnectionFailed]: "Connection to your wallet failed. Please try again."
120
- };
121
- var PaymentErrorCodes = /* @__PURE__ */ ((PaymentErrorCodes2) => {
122
- PaymentErrorCodes2["InputError"] = "input_error";
123
- PaymentErrorCodes2["PaymentRejected"] = "payment_rejected";
124
- PaymentErrorCodes2["InvalidReceiver"] = "invalid_receiver";
125
- PaymentErrorCodes2["InsufficientBalance"] = "insufficient_balance";
126
- PaymentErrorCodes2["TransactionFailed"] = "transaction_failed";
127
- PaymentErrorCodes2["GenericError"] = "generic_error";
128
- PaymentErrorCodes2["UserBlocked"] = "user_blocked";
129
- return PaymentErrorCodes2;
130
- })(PaymentErrorCodes || {});
131
- var PaymentErrorMessage = {
132
- ["input_error" /* InputError */]: "There was a problem with this request. Please try again or contact the app owner.",
133
- ["payment_rejected" /* PaymentRejected */]: "You\u2019ve cancelled the payment in World App.",
134
- ["invalid_receiver" /* InvalidReceiver */]: "The receiver address is invalid. Please contact the app owner.",
135
- ["insufficient_balance" /* InsufficientBalance */]: "You do not have enough balance to complete this transaction.",
136
- ["transaction_failed" /* TransactionFailed */]: "The transaction failed. Please try again.",
137
- ["generic_error" /* GenericError */]: "Something unexpected went wrong. Please try again.",
138
- ["user_blocked" /* UserBlocked */]: "User's region is blocked from making payments."
139
- };
140
- var PaymentValidationErrors = /* @__PURE__ */ ((PaymentValidationErrors2) => {
141
- PaymentValidationErrors2["MalformedRequest"] = "There was a problem with this request. Please try again or contact the app owner.";
142
- PaymentValidationErrors2["InvalidTokenAddress"] = "The token address is invalid. Please contact the app owner.";
143
- PaymentValidationErrors2["InvalidAppId"] = "The app ID is invalid. Please contact the app owner.";
144
- PaymentValidationErrors2["DuplicateReference"] = "This reference ID already exists please generate a new one and try again.";
145
- return PaymentValidationErrors2;
146
- })(PaymentValidationErrors || {});
147
- var WalletAuthErrorCodes = /* @__PURE__ */ ((WalletAuthErrorCodes2) => {
148
- WalletAuthErrorCodes2["MalformedRequest"] = "malformed_request";
149
- WalletAuthErrorCodes2["UserRejected"] = "user_rejected";
150
- WalletAuthErrorCodes2["GenericError"] = "generic_error";
151
- return WalletAuthErrorCodes2;
152
- })(WalletAuthErrorCodes || {});
153
- var WalletAuthErrorMessage = {
154
- ["malformed_request" /* MalformedRequest */]: "Provided parameters in the request are invalid.",
155
- ["user_rejected" /* UserRejected */]: "User rejected the request.",
156
- ["generic_error" /* GenericError */]: "Something unexpected went wrong."
157
- };
158
- var SendTransactionErrorCodes = /* @__PURE__ */ ((SendTransactionErrorCodes2) => {
159
- SendTransactionErrorCodes2["InvalidOperation"] = "invalid_operation";
160
- SendTransactionErrorCodes2["UserRejected"] = "user_rejected";
161
- SendTransactionErrorCodes2["InputError"] = "input_error";
162
- SendTransactionErrorCodes2["SimulationFailed"] = "simulation_failed";
163
- SendTransactionErrorCodes2["TransactionFailed"] = "transaction_failed";
164
- SendTransactionErrorCodes2["GenericError"] = "generic_error";
165
- SendTransactionErrorCodes2["DisallowedOperation"] = "disallowed_operation";
166
- SendTransactionErrorCodes2["InvalidContract"] = "invalid_contract";
167
- SendTransactionErrorCodes2["MaliciousOperation"] = "malicious_operation";
168
- return SendTransactionErrorCodes2;
169
- })(SendTransactionErrorCodes || {});
170
- var SendTransactionErrorMessage = {
171
- ["invalid_operation" /* InvalidOperation */]: "Transaction included an operation that was invalid",
172
- ["user_rejected" /* UserRejected */]: "User rejected the request.",
173
- ["input_error" /* InputError */]: "Invalid payload.",
174
- ["simulation_failed" /* SimulationFailed */]: "The transaction simulation failed.",
175
- ["transaction_failed" /* TransactionFailed */]: "The transaction failed. Please try again later.",
176
- ["generic_error" /* GenericError */]: "Something unexpected went wrong. Please try again.",
177
- ["disallowed_operation" /* DisallowedOperation */]: "The operation requested is not allowed. Please refer to the docs.",
178
- ["invalid_contract" /* InvalidContract */]: "The contract address is not allowed for your application. Please check your developer portal configurations",
179
- ["malicious_operation" /* MaliciousOperation */]: "The operation requested is considered malicious."
180
- };
181
- var SignMessageErrorCodes = /* @__PURE__ */ ((SignMessageErrorCodes2) => {
182
- SignMessageErrorCodes2["InvalidMessage"] = "invalid_message";
183
- SignMessageErrorCodes2["UserRejected"] = "user_rejected";
184
- SignMessageErrorCodes2["GenericError"] = "generic_error";
185
- return SignMessageErrorCodes2;
186
- })(SignMessageErrorCodes || {});
187
- var SignMessageErrorMessage = {
188
- ["invalid_message" /* InvalidMessage */]: "Invalid message requested",
189
- ["user_rejected" /* UserRejected */]: "User rejected the request.",
190
- ["generic_error" /* GenericError */]: "Something unexpected went wrong."
191
- };
192
- var SignTypedDataErrorCodes = /* @__PURE__ */ ((SignTypedDataErrorCodes2) => {
193
- SignTypedDataErrorCodes2["InvalidOperation"] = "invalid_operation";
194
- SignTypedDataErrorCodes2["UserRejected"] = "user_rejected";
195
- SignTypedDataErrorCodes2["InputError"] = "input_error";
196
- SignTypedDataErrorCodes2["SimulationFailed"] = "simulation_failed";
197
- SignTypedDataErrorCodes2["GenericError"] = "generic_error";
198
- SignTypedDataErrorCodes2["DisallowedOperation"] = "disallowed_operation";
199
- SignTypedDataErrorCodes2["InvalidContract"] = "invalid_contract";
200
- SignTypedDataErrorCodes2["MaliciousOperation"] = "malicious_operation";
201
- return SignTypedDataErrorCodes2;
202
- })(SignTypedDataErrorCodes || {});
203
- var SignTypedDataErrorMessage = SendTransactionErrorMessage;
204
- var MiniKitInstallErrorCodes = /* @__PURE__ */ ((MiniKitInstallErrorCodes2) => {
205
- MiniKitInstallErrorCodes2["Unknown"] = "unknown";
206
- MiniKitInstallErrorCodes2["AlreadyInstalled"] = "already_installed";
207
- MiniKitInstallErrorCodes2["OutsideOfWorldApp"] = "outside_of_worldapp";
208
- MiniKitInstallErrorCodes2["NotOnClient"] = "not_on_client";
209
- MiniKitInstallErrorCodes2["AppOutOfDate"] = "app_out_of_date";
210
- return MiniKitInstallErrorCodes2;
211
- })(MiniKitInstallErrorCodes || {});
212
- var MiniKitInstallErrorMessage = {
213
- ["unknown" /* Unknown */]: "Failed to install MiniKit.",
214
- ["already_installed" /* AlreadyInstalled */]: "MiniKit is already installed.",
215
- ["outside_of_worldapp" /* OutsideOfWorldApp */]: "MiniApp launched outside of WorldApp.",
216
- ["not_on_client" /* NotOnClient */]: "Window object is not available.",
217
- ["app_out_of_date" /* AppOutOfDate */]: "WorldApp is out of date. Please update the app."
218
- };
219
- var ShareContactsErrorCodes = /* @__PURE__ */ ((ShareContactsErrorCodes2) => {
220
- ShareContactsErrorCodes2["UserRejected"] = "user_rejected";
221
- ShareContactsErrorCodes2["GenericError"] = "generic_error";
222
- return ShareContactsErrorCodes2;
223
- })(ShareContactsErrorCodes || {});
224
- var ShareContactsErrorMessage = {
225
- ["user_rejected" /* UserRejected */]: "User rejected the request.",
226
- ["generic_error" /* GenericError */]: "Something unexpected went wrong."
227
- };
228
-
229
- // minikit.ts
230
- var import_idkit_core3 = require("@worldcoin/idkit-core");
231
- var import_hashing = require("@worldcoin/idkit-core/hashing");
232
-
233
- // helpers/siwe/validate-wallet-auth-command-input.ts
234
- var validateWalletAuthCommandInput = (params) => {
235
- if (!params.nonce) {
236
- return { valid: false, message: "'nonce' is required" };
237
- }
238
- if (params.nonce.length < 8) {
239
- return { valid: false, message: "'nonce' must be at least 8 characters" };
240
- }
241
- if (params.statement && params.statement.includes("\n")) {
242
- return { valid: false, message: "'statement' must not contain newlines" };
79
+ // helpers/payment/client.ts
80
+ var tokenToDecimals = (amount, token) => {
81
+ const decimals = TokenDecimals[token];
82
+ if (decimals === void 0) {
83
+ throw new Error(`Invalid token: ${token}`);
243
84
  }
244
- if (params.expirationTime && new Date(params.expirationTime) < /* @__PURE__ */ new Date()) {
245
- return { valid: false, message: "'expirationTime' must be in the future" };
85
+ const factor = 10 ** decimals;
86
+ const result = amount * factor;
87
+ if (!Number.isInteger(result)) {
88
+ throw new Error(`The resulting amount is not a whole number: ${result}`);
246
89
  }
247
- if (params.expirationTime && new Date(params.expirationTime) > new Date(Date.now() + 7 * 24 * 60 * 60 * 1e3)) {
248
- return { valid: false, message: "'expirationTime' must be within 7 days" };
90
+ return result;
91
+ };
92
+ var validatePaymentPayload = (payload) => {
93
+ if (payload.tokens.some(
94
+ (token) => token.symbol == "USDCE" && parseFloat(token.token_amount) < 0.1
95
+ )) {
96
+ console.error("USDCE amount should be greater than $0.1");
97
+ return false;
249
98
  }
250
- if (params.notBefore && new Date(params.notBefore) > new Date(Date.now() + 7 * 24 * 60 * 60 * 1e3)) {
251
- return { valid: false, message: "'notBefore' must be within 7 days" };
99
+ if (payload.reference.length > 36) {
100
+ console.error("Reference must not exceed 36 characters");
101
+ return false;
252
102
  }
253
- return { valid: true };
103
+ return true;
254
104
  };
255
105
 
256
106
  // helpers/siwe/siwe.ts
@@ -364,15 +214,23 @@ var generateSiweMessage = (siweMessageData) => {
364
214
  };
365
215
  var SAFE_CONTRACT_ABI = [
366
216
  {
367
- name: "checkSignatures",
368
- type: "function",
369
- stateMutability: "view",
370
217
  inputs: [
371
- { name: "dataHash", type: "bytes32" },
372
- { name: "data", type: "bytes" },
373
- { name: "signature", type: "bytes" }
218
+ {
219
+ internalType: "address",
220
+ name: "owner",
221
+ type: "address"
222
+ }
374
223
  ],
375
- outputs: []
224
+ name: "isOwner",
225
+ outputs: [
226
+ {
227
+ internalType: "bool",
228
+ name: "",
229
+ type: "bool"
230
+ }
231
+ ],
232
+ stateMutability: "view",
233
+ type: "function"
376
234
  }
377
235
  ];
378
236
  var verifySiweMessage = async (payload, nonce, statement, requestId, userProvider) => {
@@ -408,9 +266,8 @@ var verifySiweMessage = async (payload, nonce, statement, requestId, userProvide
408
266
  `Request ID mismatch. Got: ${siweMessageData.request_id}, Expected: ${requestId}`
409
267
  );
410
268
  }
411
- let provider = userProvider || (0, import_viem.createPublicClient)({ chain: import_chains.optimism, transport: (0, import_viem.http)() });
269
+ let provider = userProvider || (0, import_viem.createPublicClient)({ chain: import_chains.worldchain, transport: (0, import_viem.http)() });
412
270
  const signedMessage = `${ERC_191_PREFIX}${message.length}${message}`;
413
- const messageBytes = Buffer.from(signedMessage, "utf8").toString("hex");
414
271
  const hashedMessage = (0, import_viem.hashMessage)(signedMessage);
415
272
  const contract = (0, import_viem.getContract)({
416
273
  address,
@@ -418,43 +275,59 @@ var verifySiweMessage = async (payload, nonce, statement, requestId, userProvide
418
275
  client: provider
419
276
  });
420
277
  try {
421
- await contract.read.checkSignatures([
422
- hashedMessage,
423
- `0x${messageBytes}`,
424
- `0x${signature}`
425
- ]);
278
+ const recoveredAddress = await (0, import_viem.recoverAddress)({
279
+ hash: hashedMessage,
280
+ signature: `0x${signature}`
281
+ });
282
+ const isOwner = await contract.read.isOwner([recoveredAddress]);
283
+ if (!isOwner) {
284
+ throw new Error("Signature verification failed, invalid owner");
285
+ }
426
286
  } catch (error) {
427
287
  throw new Error("Signature verification failed");
428
288
  }
429
289
  return { isValid: true, siweMessageData };
430
290
  };
431
291
 
432
- // helpers/payment/client.ts
433
- var tokenToDecimals = (amount, token) => {
434
- const decimals = TokenDecimals[token];
435
- if (decimals === void 0) {
436
- throw new Error(`Invalid token: ${token}`);
292
+ // helpers/siwe/validate-wallet-auth-command-input.ts
293
+ var validateWalletAuthCommandInput = (params) => {
294
+ if (!params.nonce) {
295
+ return { valid: false, message: "'nonce' is required" };
437
296
  }
438
- const factor = 10 ** decimals;
439
- const result = amount * factor;
440
- if (!Number.isInteger(result)) {
441
- throw new Error(`The resulting amount is not a whole number: ${result}`);
297
+ if (params.nonce.length < 8) {
298
+ return { valid: false, message: "'nonce' must be at least 8 characters" };
442
299
  }
443
- return result;
300
+ if (params.statement && params.statement.includes("\n")) {
301
+ return { valid: false, message: "'statement' must not contain newlines" };
302
+ }
303
+ if (params.expirationTime && new Date(params.expirationTime) < /* @__PURE__ */ new Date()) {
304
+ return { valid: false, message: "'expirationTime' must be in the future" };
305
+ }
306
+ if (params.expirationTime && new Date(params.expirationTime) > new Date(Date.now() + 7 * 24 * 60 * 60 * 1e3)) {
307
+ return { valid: false, message: "'expirationTime' must be within 7 days" };
308
+ }
309
+ if (params.notBefore && new Date(params.notBefore) > new Date(Date.now() + 7 * 24 * 60 * 60 * 1e3)) {
310
+ return { valid: false, message: "'notBefore' must be within 7 days" };
311
+ }
312
+ return { valid: true };
444
313
  };
445
- var validatePaymentPayload = (payload) => {
446
- if (payload.tokens.some(
447
- (token) => token.symbol == "USDCE" && parseFloat(token.token_amount) < 0.1
448
- )) {
449
- console.error("USDCE amount should be greater than $0.1");
450
- return false;
314
+
315
+ // helpers/transaction/validate-payload.ts
316
+ var validate = (payload) => {
317
+ if (typeof payload === "string") return { isValid: true };
318
+ if (typeof payload === "object") {
319
+ const isValid = Object.values(payload).every(
320
+ (value) => validate(value).isValid
321
+ );
322
+ return { isValid };
451
323
  }
452
- if (payload.reference.length > 36) {
453
- console.error("Reference must not exceed 36 characters");
454
- return false;
324
+ if (Array.isArray(payload)) {
325
+ const isValid = payload.every((value) => validate(value).isValid);
326
+ return { isValid };
455
327
  }
456
- return true;
328
+ return { isValid: false };
457
329
  };
330
+ var validateSendTransactionPayload = (payload) => validate(payload);
458
331
 
459
332
  // helpers/usernames/index.ts
460
333
  var getUserProfile = async (address) => {
@@ -468,9 +341,189 @@ var getUserProfile = async (address) => {
468
341
  })
469
342
  });
470
343
  const usernames = await res.json();
471
- return usernames[0] ?? { username: null, profilePictureUrl: null };
344
+ return usernames?.[0] ?? { username: null, profilePictureUrl: null };
345
+ };
346
+
347
+ // types/commands.ts
348
+ var Command = /* @__PURE__ */ ((Command2) => {
349
+ Command2["Verify"] = "verify";
350
+ Command2["Pay"] = "pay";
351
+ Command2["WalletAuth"] = "wallet-auth";
352
+ Command2["SendTransaction"] = "send-transaction";
353
+ Command2["SignMessage"] = "sign-message";
354
+ Command2["SignTypedData"] = "sign-typed-data";
355
+ Command2["ShareContacts"] = "share-contacts";
356
+ Command2["RequestPermission"] = "request-permission";
357
+ return Command2;
358
+ })(Command || {});
359
+ var Permission = /* @__PURE__ */ ((Permission2) => {
360
+ Permission2["Notifications"] = "notifications";
361
+ return Permission2;
362
+ })(Permission || {});
363
+
364
+ // types/errors.ts
365
+ var import_idkit_core = require("@worldcoin/idkit-core");
366
+ var import_idkit_core2 = require("@worldcoin/idkit-core");
367
+ var VerificationErrorMessage = {
368
+ [import_idkit_core.AppErrorCodes.VerificationRejected]: "You\u2019ve cancelled the request in World App.",
369
+ [import_idkit_core.AppErrorCodes.MaxVerificationsReached]: "You have already verified the maximum number of times for this action.",
370
+ [import_idkit_core.AppErrorCodes.CredentialUnavailable]: "It seems you do not have the verification level required by this app.",
371
+ [import_idkit_core.AppErrorCodes.MalformedRequest]: "There was a problem with this request. Please try again or contact the app owner.",
372
+ [import_idkit_core.AppErrorCodes.InvalidNetwork]: "Invalid network. If you are the app owner, visit docs.worldcoin.org/test for details.",
373
+ [import_idkit_core.AppErrorCodes.InclusionProofFailed]: "There was an issue fetching your credential. Please try again.",
374
+ [import_idkit_core.AppErrorCodes.InclusionProofPending]: "Your identity is still being registered. Please wait a few minutes and try again.",
375
+ [import_idkit_core.AppErrorCodes.UnexpectedResponse]: "Unexpected response from your wallet. Please try again.",
376
+ [import_idkit_core.AppErrorCodes.FailedByHostApp]: "Verification failed by the app. Please contact the app owner for details.",
377
+ [import_idkit_core.AppErrorCodes.GenericError]: "Something unexpected went wrong. Please try again.",
378
+ [import_idkit_core.AppErrorCodes.ConnectionFailed]: "Connection to your wallet failed. Please try again."
379
+ };
380
+ var PaymentErrorCodes = /* @__PURE__ */ ((PaymentErrorCodes2) => {
381
+ PaymentErrorCodes2["InputError"] = "input_error";
382
+ PaymentErrorCodes2["PaymentRejected"] = "payment_rejected";
383
+ PaymentErrorCodes2["InvalidReceiver"] = "invalid_receiver";
384
+ PaymentErrorCodes2["InsufficientBalance"] = "insufficient_balance";
385
+ PaymentErrorCodes2["TransactionFailed"] = "transaction_failed";
386
+ PaymentErrorCodes2["GenericError"] = "generic_error";
387
+ PaymentErrorCodes2["UserBlocked"] = "user_blocked";
388
+ return PaymentErrorCodes2;
389
+ })(PaymentErrorCodes || {});
390
+ var PaymentErrorMessage = {
391
+ ["input_error" /* InputError */]: "There was a problem with this request. Please try again or contact the app owner.",
392
+ ["payment_rejected" /* PaymentRejected */]: "You\u2019ve cancelled the payment in World App.",
393
+ ["invalid_receiver" /* InvalidReceiver */]: "The receiver address is invalid. Please contact the app owner.",
394
+ ["insufficient_balance" /* InsufficientBalance */]: "You do not have enough balance to complete this transaction.",
395
+ ["transaction_failed" /* TransactionFailed */]: "The transaction failed. Please try again.",
396
+ ["generic_error" /* GenericError */]: "Something unexpected went wrong. Please try again.",
397
+ ["user_blocked" /* UserBlocked */]: "User's region is blocked from making payments."
398
+ };
399
+ var PaymentValidationErrors = /* @__PURE__ */ ((PaymentValidationErrors2) => {
400
+ PaymentValidationErrors2["MalformedRequest"] = "There was a problem with this request. Please try again or contact the app owner.";
401
+ PaymentValidationErrors2["InvalidTokenAddress"] = "The token address is invalid. Please contact the app owner.";
402
+ PaymentValidationErrors2["InvalidAppId"] = "The app ID is invalid. Please contact the app owner.";
403
+ PaymentValidationErrors2["DuplicateReference"] = "This reference ID already exists please generate a new one and try again.";
404
+ return PaymentValidationErrors2;
405
+ })(PaymentValidationErrors || {});
406
+ var WalletAuthErrorCodes = /* @__PURE__ */ ((WalletAuthErrorCodes2) => {
407
+ WalletAuthErrorCodes2["MalformedRequest"] = "malformed_request";
408
+ WalletAuthErrorCodes2["UserRejected"] = "user_rejected";
409
+ WalletAuthErrorCodes2["GenericError"] = "generic_error";
410
+ return WalletAuthErrorCodes2;
411
+ })(WalletAuthErrorCodes || {});
412
+ var WalletAuthErrorMessage = {
413
+ ["malformed_request" /* MalformedRequest */]: "Provided parameters in the request are invalid.",
414
+ ["user_rejected" /* UserRejected */]: "User rejected the request.",
415
+ ["generic_error" /* GenericError */]: "Something unexpected went wrong."
416
+ };
417
+ var SendTransactionErrorCodes = /* @__PURE__ */ ((SendTransactionErrorCodes2) => {
418
+ SendTransactionErrorCodes2["InvalidOperation"] = "invalid_operation";
419
+ SendTransactionErrorCodes2["UserRejected"] = "user_rejected";
420
+ SendTransactionErrorCodes2["InputError"] = "input_error";
421
+ SendTransactionErrorCodes2["SimulationFailed"] = "simulation_failed";
422
+ SendTransactionErrorCodes2["TransactionFailed"] = "transaction_failed";
423
+ SendTransactionErrorCodes2["GenericError"] = "generic_error";
424
+ SendTransactionErrorCodes2["DisallowedOperation"] = "disallowed_operation";
425
+ SendTransactionErrorCodes2["InvalidContract"] = "invalid_contract";
426
+ SendTransactionErrorCodes2["MaliciousOperation"] = "malicious_operation";
427
+ return SendTransactionErrorCodes2;
428
+ })(SendTransactionErrorCodes || {});
429
+ var SendTransactionErrorMessage = {
430
+ ["invalid_operation" /* InvalidOperation */]: "Transaction included an operation that was invalid",
431
+ ["user_rejected" /* UserRejected */]: "User rejected the request.",
432
+ ["input_error" /* InputError */]: "Invalid payload.",
433
+ ["simulation_failed" /* SimulationFailed */]: "The transaction simulation failed.",
434
+ ["transaction_failed" /* TransactionFailed */]: "The transaction failed. Please try again later.",
435
+ ["generic_error" /* GenericError */]: "Something unexpected went wrong. Please try again.",
436
+ ["disallowed_operation" /* DisallowedOperation */]: "The operation requested is not allowed. Please refer to the docs.",
437
+ ["invalid_contract" /* InvalidContract */]: "The contract address is not allowed for your application. Please check your developer portal configurations",
438
+ ["malicious_operation" /* MaliciousOperation */]: "The operation requested is considered malicious."
439
+ };
440
+ var SignMessageErrorCodes = /* @__PURE__ */ ((SignMessageErrorCodes2) => {
441
+ SignMessageErrorCodes2["InvalidMessage"] = "invalid_message";
442
+ SignMessageErrorCodes2["UserRejected"] = "user_rejected";
443
+ SignMessageErrorCodes2["GenericError"] = "generic_error";
444
+ return SignMessageErrorCodes2;
445
+ })(SignMessageErrorCodes || {});
446
+ var SignMessageErrorMessage = {
447
+ ["invalid_message" /* InvalidMessage */]: "Invalid message requested",
448
+ ["user_rejected" /* UserRejected */]: "User rejected the request.",
449
+ ["generic_error" /* GenericError */]: "Something unexpected went wrong."
450
+ };
451
+ var SignTypedDataErrorCodes = /* @__PURE__ */ ((SignTypedDataErrorCodes2) => {
452
+ SignTypedDataErrorCodes2["InvalidOperation"] = "invalid_operation";
453
+ SignTypedDataErrorCodes2["UserRejected"] = "user_rejected";
454
+ SignTypedDataErrorCodes2["InputError"] = "input_error";
455
+ SignTypedDataErrorCodes2["SimulationFailed"] = "simulation_failed";
456
+ SignTypedDataErrorCodes2["GenericError"] = "generic_error";
457
+ SignTypedDataErrorCodes2["DisallowedOperation"] = "disallowed_operation";
458
+ SignTypedDataErrorCodes2["InvalidContract"] = "invalid_contract";
459
+ SignTypedDataErrorCodes2["MaliciousOperation"] = "malicious_operation";
460
+ return SignTypedDataErrorCodes2;
461
+ })(SignTypedDataErrorCodes || {});
462
+ var SignTypedDataErrorMessage = SendTransactionErrorMessage;
463
+ var MiniKitInstallErrorCodes = /* @__PURE__ */ ((MiniKitInstallErrorCodes2) => {
464
+ MiniKitInstallErrorCodes2["Unknown"] = "unknown";
465
+ MiniKitInstallErrorCodes2["AlreadyInstalled"] = "already_installed";
466
+ MiniKitInstallErrorCodes2["OutsideOfWorldApp"] = "outside_of_worldapp";
467
+ MiniKitInstallErrorCodes2["NotOnClient"] = "not_on_client";
468
+ MiniKitInstallErrorCodes2["AppOutOfDate"] = "app_out_of_date";
469
+ return MiniKitInstallErrorCodes2;
470
+ })(MiniKitInstallErrorCodes || {});
471
+ var MiniKitInstallErrorMessage = {
472
+ ["unknown" /* Unknown */]: "Failed to install MiniKit.",
473
+ ["already_installed" /* AlreadyInstalled */]: "MiniKit is already installed.",
474
+ ["outside_of_worldapp" /* OutsideOfWorldApp */]: "MiniApp launched outside of WorldApp.",
475
+ ["not_on_client" /* NotOnClient */]: "Window object is not available.",
476
+ ["app_out_of_date" /* AppOutOfDate */]: "WorldApp is out of date. Please update the app."
477
+ };
478
+ var ShareContactsErrorCodes = /* @__PURE__ */ ((ShareContactsErrorCodes2) => {
479
+ ShareContactsErrorCodes2["UserRejected"] = "user_rejected";
480
+ ShareContactsErrorCodes2["GenericError"] = "generic_error";
481
+ return ShareContactsErrorCodes2;
482
+ })(ShareContactsErrorCodes || {});
483
+ var ShareContactsErrorMessage = {
484
+ ["user_rejected" /* UserRejected */]: "User rejected the request.",
485
+ ["generic_error" /* GenericError */]: "Something unexpected went wrong."
486
+ };
487
+ var RequestPermissionErrorCodes = /* @__PURE__ */ ((RequestPermissionErrorCodes2) => {
488
+ RequestPermissionErrorCodes2["UserRejected"] = "user_rejected";
489
+ RequestPermissionErrorCodes2["GenericError"] = "generic_error";
490
+ RequestPermissionErrorCodes2["AlreadyRequested"] = "already_requested";
491
+ RequestPermissionErrorCodes2["PermissionDisabled"] = "permission_disabled";
492
+ RequestPermissionErrorCodes2["AlreadyGranted"] = "already_granted";
493
+ RequestPermissionErrorCodes2["UnsupportedPermission"] = "unsupported_permission";
494
+ return RequestPermissionErrorCodes2;
495
+ })(RequestPermissionErrorCodes || {});
496
+ var RequestPermissionErrorMessage = {
497
+ ["user_rejected" /* UserRejected */]: "User declined sharing contacts",
498
+ ["generic_error" /* GenericError */]: "Request failed for unknown reason.",
499
+ ["already_requested" /* AlreadyRequested */]: "User has already declined turning on notifications once",
500
+ ["permission_disabled" /* PermissionDisabled */]: "User does not have this permission enabled in World App",
501
+ ["already_granted" /* AlreadyGranted */]: "If the user has already granted this mini app permission",
502
+ ["unsupported_permission" /* UnsupportedPermission */]: "The permission requested is not supported by this mini app"
503
+ };
504
+
505
+ // helpers/send-webview-event.ts
506
+ var sendWebviewEvent = (payload) => {
507
+ if (window.webkit) {
508
+ window.webkit?.messageHandlers?.minikit?.postMessage?.(payload);
509
+ } else if (window.Android) {
510
+ window.Android.postMessage?.(JSON.stringify(payload));
511
+ }
472
512
  };
473
513
 
514
+ // types/responses.ts
515
+ var ResponseEvent = /* @__PURE__ */ ((ResponseEvent2) => {
516
+ ResponseEvent2["MiniAppVerifyAction"] = "miniapp-verify-action";
517
+ ResponseEvent2["MiniAppPayment"] = "miniapp-payment";
518
+ ResponseEvent2["MiniAppWalletAuth"] = "miniapp-wallet-auth";
519
+ ResponseEvent2["MiniAppSendTransaction"] = "miniapp-send-transaction";
520
+ ResponseEvent2["MiniAppSignMessage"] = "miniapp-sign-message";
521
+ ResponseEvent2["MiniAppSignTypedData"] = "miniapp-sign-typed-data";
522
+ ResponseEvent2["MiniAppShareContacts"] = "miniapp-share-contacts";
523
+ ResponseEvent2["MiniAppRequestPermission"] = "miniapp-request-permission";
524
+ return ResponseEvent2;
525
+ })(ResponseEvent || {});
526
+
474
527
  // minikit.ts
475
528
  var sendMiniKitEvent = (payload) => {
476
529
  sendWebviewEvent(payload);
@@ -488,12 +541,8 @@ var _MiniKit = class _MiniKit {
488
541
  const wrappedHandler = (payload) => {
489
542
  if (payload.status === "success") {
490
543
  _MiniKit.walletAddress = payload.address;
491
- getUserProfile(payload.address).then((queryResponse) => {
492
- _MiniKit.user = {
493
- username: queryResponse.username,
494
- profilePictureUrl: queryResponse.profilePictureUrl,
495
- walletAddress: payload.address
496
- };
544
+ _MiniKit.getUserByAddress(payload.address).then((user) => {
545
+ _MiniKit.user = user;
497
546
  });
498
547
  }
499
548
  originalHandler(payload);
@@ -602,7 +651,8 @@ _MiniKit.commandVersion = {
602
651
  ["send-transaction" /* SendTransaction */]: 1,
603
652
  ["sign-message" /* SignMessage */]: 1,
604
653
  ["sign-typed-data" /* SignTypedData */]: 1,
605
- ["share-contacts" /* ShareContacts */]: 1
654
+ ["share-contacts" /* ShareContacts */]: 1,
655
+ ["request-permission" /* RequestPermission */]: 1
606
656
  };
607
657
  _MiniKit.isCommandAvailable = {
608
658
  ["verify" /* Verify */]: false,
@@ -611,7 +661,8 @@ _MiniKit.isCommandAvailable = {
611
661
  ["send-transaction" /* SendTransaction */]: false,
612
662
  ["sign-message" /* SignMessage */]: false,
613
663
  ["sign-typed-data" /* SignTypedData */]: false,
614
- ["share-contacts" /* ShareContacts */]: false
664
+ ["share-contacts" /* ShareContacts */]: false,
665
+ ["request-permission" /* RequestPermission */]: false
615
666
  };
616
667
  _MiniKit.listeners = {
617
668
  ["miniapp-verify-action" /* MiniAppVerifyAction */]: () => {
@@ -627,6 +678,8 @@ _MiniKit.listeners = {
627
678
  ["miniapp-sign-typed-data" /* MiniAppSignTypedData */]: () => {
628
679
  },
629
680
  ["miniapp-share-contacts" /* MiniAppShareContacts */]: () => {
681
+ },
682
+ ["miniapp-request-permission" /* MiniAppRequestPermission */]: () => {
630
683
  }
631
684
  };
632
685
  _MiniKit.appId = null;
@@ -635,6 +688,14 @@ _MiniKit.appId = null;
635
688
  */
636
689
  _MiniKit.walletAddress = null;
637
690
  _MiniKit.user = null;
691
+ _MiniKit.getUserByAddress = async (address) => {
692
+ const userProfile = await getUserProfile(address);
693
+ return {
694
+ walletAddress: address,
695
+ username: userProfile.username,
696
+ profilePictureUrl: userProfile.profilePictureUrl
697
+ };
698
+ };
638
699
  _MiniKit.commands = {
639
700
  verify: (payload) => {
640
701
  if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["verify" /* Verify */]) {
@@ -708,7 +769,7 @@ _MiniKit.commands = {
708
769
  statement: payload.statement ?? void 0,
709
770
  uri: window.location.href,
710
771
  version: 1,
711
- chain_id: 10,
772
+ chain_id: 480,
712
773
  nonce: payload.nonce,
713
774
  issued_at: (/* @__PURE__ */ new Date()).toISOString(),
714
775
  expiration_time: payload.expirationTime?.toISOString() ?? void 0,
@@ -730,6 +791,12 @@ _MiniKit.commands = {
730
791
  );
731
792
  return null;
732
793
  }
794
+ if (!validateSendTransactionPayload(payload).isValid) {
795
+ console.error(
796
+ "Invalid sendTransaction payload - some object properties are not strings"
797
+ );
798
+ return null;
799
+ }
733
800
  sendMiniKitEvent({
734
801
  command: "send-transaction" /* SendTransaction */,
735
802
  version: 1,
@@ -778,6 +845,20 @@ _MiniKit.commands = {
778
845
  payload
779
846
  });
780
847
  return payload;
848
+ },
849
+ requestPermission: (payload) => {
850
+ if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["request-permission" /* RequestPermission */]) {
851
+ console.error(
852
+ "'requestPermission' command is unavailable. Check MiniKit.install() or update the app version"
853
+ );
854
+ return null;
855
+ }
856
+ sendMiniKitEvent({
857
+ command: "request-permission" /* RequestPermission */,
858
+ version: 1,
859
+ payload
860
+ });
861
+ return payload;
781
862
  }
782
863
  };
783
864
  /**
@@ -888,6 +969,20 @@ _MiniKit.commandsAsync = {
888
969
  reject(error);
889
970
  }
890
971
  });
972
+ },
973
+ requestPermission: async (payload) => {
974
+ return new Promise(async (resolve, reject) => {
975
+ try {
976
+ const response = await _MiniKit.awaitCommand(
977
+ "miniapp-request-permission" /* MiniAppRequestPermission */,
978
+ "request-permission" /* RequestPermission */,
979
+ () => _MiniKit.commands.requestPermission(payload)
980
+ );
981
+ resolve(response);
982
+ } catch (error) {
983
+ reject(error);
984
+ }
985
+ });
891
986
  }
892
987
  };
893
988
  var MiniKit = _MiniKit;
@@ -957,6 +1052,9 @@ var getIsUserVerified = async (walletAddress, rpcUrl) => {
957
1052
  PaymentErrorCodes,
958
1053
  PaymentErrorMessage,
959
1054
  PaymentValidationErrors,
1055
+ Permission,
1056
+ RequestPermissionErrorCodes,
1057
+ RequestPermissionErrorMessage,
960
1058
  ResponseEvent,
961
1059
  SAFE_CONTRACT_ABI,
962
1060
  SendTransactionErrorCodes,