@worldcoin/minikit-js 1.4.0 → 1.6.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,34 @@ 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" };
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}`);
240
84
  }
241
- if (params.statement && params.statement.includes("\n")) {
242
- return { valid: false, message: "'statement' must not contain newlines" };
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}`);
243
89
  }
244
- if (params.expirationTime && new Date(params.expirationTime) < /* @__PURE__ */ new Date()) {
245
- return { valid: false, message: "'expirationTime' must be in the future" };
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;
246
98
  }
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" };
99
+ if (payload.reference.length > 36) {
100
+ console.error("Reference must not exceed 36 characters");
101
+ return false;
249
102
  }
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" };
103
+ if (typeof payload.reference !== "string") {
104
+ throw new Error("Reference must be a string");
252
105
  }
253
- return { valid: true };
106
+ return true;
254
107
  };
255
108
 
256
109
  // helpers/siwe/siwe.ts
@@ -364,15 +217,23 @@ var generateSiweMessage = (siweMessageData) => {
364
217
  };
365
218
  var SAFE_CONTRACT_ABI = [
366
219
  {
367
- name: "checkSignatures",
368
- type: "function",
369
- stateMutability: "view",
370
220
  inputs: [
371
- { name: "dataHash", type: "bytes32" },
372
- { name: "data", type: "bytes" },
373
- { name: "signature", type: "bytes" }
221
+ {
222
+ internalType: "address",
223
+ name: "owner",
224
+ type: "address"
225
+ }
374
226
  ],
375
- outputs: []
227
+ name: "isOwner",
228
+ outputs: [
229
+ {
230
+ internalType: "bool",
231
+ name: "",
232
+ type: "bool"
233
+ }
234
+ ],
235
+ stateMutability: "view",
236
+ type: "function"
376
237
  }
377
238
  ];
378
239
  var verifySiweMessage = async (payload, nonce, statement, requestId, userProvider) => {
@@ -408,9 +269,8 @@ var verifySiweMessage = async (payload, nonce, statement, requestId, userProvide
408
269
  `Request ID mismatch. Got: ${siweMessageData.request_id}, Expected: ${requestId}`
409
270
  );
410
271
  }
411
- let provider = userProvider || (0, import_viem.createPublicClient)({ chain: import_chains.optimism, transport: (0, import_viem.http)() });
272
+ let provider = userProvider || (0, import_viem.createPublicClient)({ chain: import_chains.worldchain, transport: (0, import_viem.http)() });
412
273
  const signedMessage = `${ERC_191_PREFIX}${message.length}${message}`;
413
- const messageBytes = Buffer.from(signedMessage, "utf8").toString("hex");
414
274
  const hashedMessage = (0, import_viem.hashMessage)(signedMessage);
415
275
  const contract = (0, import_viem.getContract)({
416
276
  address,
@@ -418,43 +278,71 @@ var verifySiweMessage = async (payload, nonce, statement, requestId, userProvide
418
278
  client: provider
419
279
  });
420
280
  try {
421
- await contract.read.checkSignatures([
422
- hashedMessage,
423
- `0x${messageBytes}`,
424
- `0x${signature}`
425
- ]);
281
+ const recoveredAddress = await (0, import_viem.recoverAddress)({
282
+ hash: hashedMessage,
283
+ signature: `0x${signature}`
284
+ });
285
+ const isOwner = await contract.read.isOwner([recoveredAddress]);
286
+ if (!isOwner) {
287
+ throw new Error("Signature verification failed, invalid owner");
288
+ }
426
289
  } catch (error) {
427
290
  throw new Error("Signature verification failed");
428
291
  }
429
292
  return { isValid: true, siweMessageData };
430
293
  };
431
294
 
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}`);
295
+ // helpers/siwe/validate-wallet-auth-command-input.ts
296
+ var validateWalletAuthCommandInput = (params) => {
297
+ if (!params.nonce) {
298
+ return { valid: false, message: "'nonce' is required" };
437
299
  }
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}`);
300
+ if (params.nonce.length < 8) {
301
+ return { valid: false, message: "'nonce' must be at least 8 characters" };
442
302
  }
443
- return result;
303
+ if (params.statement && params.statement.includes("\n")) {
304
+ return { valid: false, message: "'statement' must not contain newlines" };
305
+ }
306
+ if (params.expirationTime && new Date(params.expirationTime) < /* @__PURE__ */ new Date()) {
307
+ return { valid: false, message: "'expirationTime' must be in the future" };
308
+ }
309
+ if (params.expirationTime && new Date(params.expirationTime) > new Date(Date.now() + 7 * 24 * 60 * 60 * 1e3)) {
310
+ return { valid: false, message: "'expirationTime' must be within 7 days" };
311
+ }
312
+ if (params.notBefore && new Date(params.notBefore) > new Date(Date.now() + 7 * 24 * 60 * 60 * 1e3)) {
313
+ return { valid: false, message: "'notBefore' must be within 7 days" };
314
+ }
315
+ return { valid: true };
444
316
  };
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;
317
+
318
+ // helpers/transaction/validate-payload.ts
319
+ var isValidHex = (str) => {
320
+ return /^0x[0-9A-Fa-f]+$/.test(str);
321
+ };
322
+ var validate = (payload) => {
323
+ if (typeof payload === "string") return { isValid: true };
324
+ if (Array.isArray(payload)) {
325
+ const isValid = payload.every((value) => validate(value).isValid);
326
+ return { isValid };
451
327
  }
452
- if (payload.reference.length > 36) {
453
- console.error("Reference must not exceed 36 characters");
454
- return false;
328
+ if (typeof payload === "object" && payload !== null) {
329
+ if ("value" in payload && payload.value !== void 0) {
330
+ if (typeof payload.value !== "string" || !isValidHex(payload.value)) {
331
+ console.error(
332
+ "Transaction value must be a valid hex string",
333
+ payload.value
334
+ );
335
+ return { isValid: false };
336
+ }
337
+ }
338
+ const isValid = Object.values(payload).every(
339
+ (value) => validate(value).isValid
340
+ );
341
+ return { isValid };
455
342
  }
456
- return true;
343
+ return { isValid: false };
457
344
  };
345
+ var validateSendTransactionPayload = (payload) => validate(payload);
458
346
 
459
347
  // helpers/usernames/index.ts
460
348
  var getUserProfile = async (address) => {
@@ -468,8 +356,188 @@ var getUserProfile = async (address) => {
468
356
  })
469
357
  });
470
358
  const usernames = await res.json();
471
- return usernames[0] ?? { username: null, profilePictureUrl: null };
359
+ return usernames?.[0] ?? { username: null, profilePictureUrl: null };
360
+ };
361
+
362
+ // types/commands.ts
363
+ var Command = /* @__PURE__ */ ((Command2) => {
364
+ Command2["Verify"] = "verify";
365
+ Command2["Pay"] = "pay";
366
+ Command2["WalletAuth"] = "wallet-auth";
367
+ Command2["SendTransaction"] = "send-transaction";
368
+ Command2["SignMessage"] = "sign-message";
369
+ Command2["SignTypedData"] = "sign-typed-data";
370
+ Command2["ShareContacts"] = "share-contacts";
371
+ Command2["RequestPermission"] = "request-permission";
372
+ return Command2;
373
+ })(Command || {});
374
+ var Permission = /* @__PURE__ */ ((Permission2) => {
375
+ Permission2["Notifications"] = "notifications";
376
+ return Permission2;
377
+ })(Permission || {});
378
+
379
+ // types/errors.ts
380
+ var import_idkit_core = require("@worldcoin/idkit-core");
381
+ var import_idkit_core2 = require("@worldcoin/idkit-core");
382
+ var VerificationErrorMessage = {
383
+ [import_idkit_core.AppErrorCodes.VerificationRejected]: "You\u2019ve cancelled the request in World App.",
384
+ [import_idkit_core.AppErrorCodes.MaxVerificationsReached]: "You have already verified the maximum number of times for this action.",
385
+ [import_idkit_core.AppErrorCodes.CredentialUnavailable]: "It seems you do not have the verification level required by this app.",
386
+ [import_idkit_core.AppErrorCodes.MalformedRequest]: "There was a problem with this request. Please try again or contact the app owner.",
387
+ [import_idkit_core.AppErrorCodes.InvalidNetwork]: "Invalid network. If you are the app owner, visit docs.worldcoin.org/test for details.",
388
+ [import_idkit_core.AppErrorCodes.InclusionProofFailed]: "There was an issue fetching your credential. Please try again.",
389
+ [import_idkit_core.AppErrorCodes.InclusionProofPending]: "Your identity is still being registered. Please wait a few minutes and try again.",
390
+ [import_idkit_core.AppErrorCodes.UnexpectedResponse]: "Unexpected response from your wallet. Please try again.",
391
+ [import_idkit_core.AppErrorCodes.FailedByHostApp]: "Verification failed by the app. Please contact the app owner for details.",
392
+ [import_idkit_core.AppErrorCodes.GenericError]: "Something unexpected went wrong. Please try again.",
393
+ [import_idkit_core.AppErrorCodes.ConnectionFailed]: "Connection to your wallet failed. Please try again."
394
+ };
395
+ var PaymentErrorCodes = /* @__PURE__ */ ((PaymentErrorCodes2) => {
396
+ PaymentErrorCodes2["InputError"] = "input_error";
397
+ PaymentErrorCodes2["PaymentRejected"] = "payment_rejected";
398
+ PaymentErrorCodes2["InvalidReceiver"] = "invalid_receiver";
399
+ PaymentErrorCodes2["InsufficientBalance"] = "insufficient_balance";
400
+ PaymentErrorCodes2["TransactionFailed"] = "transaction_failed";
401
+ PaymentErrorCodes2["GenericError"] = "generic_error";
402
+ PaymentErrorCodes2["UserBlocked"] = "user_blocked";
403
+ return PaymentErrorCodes2;
404
+ })(PaymentErrorCodes || {});
405
+ var PaymentErrorMessage = {
406
+ ["input_error" /* InputError */]: "There was a problem with this request. Please try again or contact the app owner.",
407
+ ["payment_rejected" /* PaymentRejected */]: "You\u2019ve cancelled the payment in World App.",
408
+ ["invalid_receiver" /* InvalidReceiver */]: "The receiver address is invalid. Please contact the app owner.",
409
+ ["insufficient_balance" /* InsufficientBalance */]: "You do not have enough balance to complete this transaction.",
410
+ ["transaction_failed" /* TransactionFailed */]: "The transaction failed. Please try again.",
411
+ ["generic_error" /* GenericError */]: "Something unexpected went wrong. Please try again.",
412
+ ["user_blocked" /* UserBlocked */]: "User's region is blocked from making payments."
413
+ };
414
+ var PaymentValidationErrors = /* @__PURE__ */ ((PaymentValidationErrors2) => {
415
+ PaymentValidationErrors2["MalformedRequest"] = "There was a problem with this request. Please try again or contact the app owner.";
416
+ PaymentValidationErrors2["InvalidTokenAddress"] = "The token address is invalid. Please contact the app owner.";
417
+ PaymentValidationErrors2["InvalidAppId"] = "The app ID is invalid. Please contact the app owner.";
418
+ PaymentValidationErrors2["DuplicateReference"] = "This reference ID already exists please generate a new one and try again.";
419
+ return PaymentValidationErrors2;
420
+ })(PaymentValidationErrors || {});
421
+ var WalletAuthErrorCodes = /* @__PURE__ */ ((WalletAuthErrorCodes2) => {
422
+ WalletAuthErrorCodes2["MalformedRequest"] = "malformed_request";
423
+ WalletAuthErrorCodes2["UserRejected"] = "user_rejected";
424
+ WalletAuthErrorCodes2["GenericError"] = "generic_error";
425
+ return WalletAuthErrorCodes2;
426
+ })(WalletAuthErrorCodes || {});
427
+ var WalletAuthErrorMessage = {
428
+ ["malformed_request" /* MalformedRequest */]: "Provided parameters in the request are invalid.",
429
+ ["user_rejected" /* UserRejected */]: "User rejected the request.",
430
+ ["generic_error" /* GenericError */]: "Something unexpected went wrong."
431
+ };
432
+ var SendTransactionErrorCodes = /* @__PURE__ */ ((SendTransactionErrorCodes2) => {
433
+ SendTransactionErrorCodes2["InvalidOperation"] = "invalid_operation";
434
+ SendTransactionErrorCodes2["UserRejected"] = "user_rejected";
435
+ SendTransactionErrorCodes2["InputError"] = "input_error";
436
+ SendTransactionErrorCodes2["SimulationFailed"] = "simulation_failed";
437
+ SendTransactionErrorCodes2["TransactionFailed"] = "transaction_failed";
438
+ SendTransactionErrorCodes2["GenericError"] = "generic_error";
439
+ SendTransactionErrorCodes2["DisallowedOperation"] = "disallowed_operation";
440
+ SendTransactionErrorCodes2["InvalidContract"] = "invalid_contract";
441
+ SendTransactionErrorCodes2["MaliciousOperation"] = "malicious_operation";
442
+ return SendTransactionErrorCodes2;
443
+ })(SendTransactionErrorCodes || {});
444
+ var SendTransactionErrorMessage = {
445
+ ["invalid_operation" /* InvalidOperation */]: "Transaction included an operation that was invalid",
446
+ ["user_rejected" /* UserRejected */]: "User rejected the request.",
447
+ ["input_error" /* InputError */]: "Invalid payload.",
448
+ ["simulation_failed" /* SimulationFailed */]: "The transaction simulation failed.",
449
+ ["transaction_failed" /* TransactionFailed */]: "The transaction failed. Please try again later.",
450
+ ["generic_error" /* GenericError */]: "Something unexpected went wrong. Please try again.",
451
+ ["disallowed_operation" /* DisallowedOperation */]: "The operation requested is not allowed. Please refer to the docs.",
452
+ ["invalid_contract" /* InvalidContract */]: "The contract address is not allowed for your application. Please check your developer portal configurations",
453
+ ["malicious_operation" /* MaliciousOperation */]: "The operation requested is considered malicious."
454
+ };
455
+ var SignMessageErrorCodes = /* @__PURE__ */ ((SignMessageErrorCodes2) => {
456
+ SignMessageErrorCodes2["InvalidMessage"] = "invalid_message";
457
+ SignMessageErrorCodes2["UserRejected"] = "user_rejected";
458
+ SignMessageErrorCodes2["GenericError"] = "generic_error";
459
+ return SignMessageErrorCodes2;
460
+ })(SignMessageErrorCodes || {});
461
+ var SignMessageErrorMessage = {
462
+ ["invalid_message" /* InvalidMessage */]: "Invalid message requested",
463
+ ["user_rejected" /* UserRejected */]: "User rejected the request.",
464
+ ["generic_error" /* GenericError */]: "Something unexpected went wrong."
465
+ };
466
+ var SignTypedDataErrorCodes = /* @__PURE__ */ ((SignTypedDataErrorCodes2) => {
467
+ SignTypedDataErrorCodes2["InvalidOperation"] = "invalid_operation";
468
+ SignTypedDataErrorCodes2["UserRejected"] = "user_rejected";
469
+ SignTypedDataErrorCodes2["InputError"] = "input_error";
470
+ SignTypedDataErrorCodes2["SimulationFailed"] = "simulation_failed";
471
+ SignTypedDataErrorCodes2["GenericError"] = "generic_error";
472
+ SignTypedDataErrorCodes2["DisallowedOperation"] = "disallowed_operation";
473
+ SignTypedDataErrorCodes2["InvalidContract"] = "invalid_contract";
474
+ SignTypedDataErrorCodes2["MaliciousOperation"] = "malicious_operation";
475
+ return SignTypedDataErrorCodes2;
476
+ })(SignTypedDataErrorCodes || {});
477
+ var SignTypedDataErrorMessage = SendTransactionErrorMessage;
478
+ var MiniKitInstallErrorCodes = /* @__PURE__ */ ((MiniKitInstallErrorCodes2) => {
479
+ MiniKitInstallErrorCodes2["Unknown"] = "unknown";
480
+ MiniKitInstallErrorCodes2["AlreadyInstalled"] = "already_installed";
481
+ MiniKitInstallErrorCodes2["OutsideOfWorldApp"] = "outside_of_worldapp";
482
+ MiniKitInstallErrorCodes2["NotOnClient"] = "not_on_client";
483
+ MiniKitInstallErrorCodes2["AppOutOfDate"] = "app_out_of_date";
484
+ return MiniKitInstallErrorCodes2;
485
+ })(MiniKitInstallErrorCodes || {});
486
+ var MiniKitInstallErrorMessage = {
487
+ ["unknown" /* Unknown */]: "Failed to install MiniKit.",
488
+ ["already_installed" /* AlreadyInstalled */]: "MiniKit is already installed.",
489
+ ["outside_of_worldapp" /* OutsideOfWorldApp */]: "MiniApp launched outside of WorldApp.",
490
+ ["not_on_client" /* NotOnClient */]: "Window object is not available.",
491
+ ["app_out_of_date" /* AppOutOfDate */]: "WorldApp is out of date. Please update the app."
472
492
  };
493
+ var ShareContactsErrorCodes = /* @__PURE__ */ ((ShareContactsErrorCodes2) => {
494
+ ShareContactsErrorCodes2["UserRejected"] = "user_rejected";
495
+ ShareContactsErrorCodes2["GenericError"] = "generic_error";
496
+ return ShareContactsErrorCodes2;
497
+ })(ShareContactsErrorCodes || {});
498
+ var ShareContactsErrorMessage = {
499
+ ["user_rejected" /* UserRejected */]: "User rejected the request.",
500
+ ["generic_error" /* GenericError */]: "Something unexpected went wrong."
501
+ };
502
+ var RequestPermissionErrorCodes = /* @__PURE__ */ ((RequestPermissionErrorCodes2) => {
503
+ RequestPermissionErrorCodes2["UserRejected"] = "user_rejected";
504
+ RequestPermissionErrorCodes2["GenericError"] = "generic_error";
505
+ RequestPermissionErrorCodes2["AlreadyRequested"] = "already_requested";
506
+ RequestPermissionErrorCodes2["PermissionDisabled"] = "permission_disabled";
507
+ RequestPermissionErrorCodes2["AlreadyGranted"] = "already_granted";
508
+ RequestPermissionErrorCodes2["UnsupportedPermission"] = "unsupported_permission";
509
+ return RequestPermissionErrorCodes2;
510
+ })(RequestPermissionErrorCodes || {});
511
+ var RequestPermissionErrorMessage = {
512
+ ["user_rejected" /* UserRejected */]: "User declined sharing contacts",
513
+ ["generic_error" /* GenericError */]: "Request failed for unknown reason.",
514
+ ["already_requested" /* AlreadyRequested */]: "User has already declined turning on notifications once",
515
+ ["permission_disabled" /* PermissionDisabled */]: "User does not have this permission enabled in World App",
516
+ ["already_granted" /* AlreadyGranted */]: "If the user has already granted this mini app permission",
517
+ ["unsupported_permission" /* UnsupportedPermission */]: "The permission requested is not supported by this mini app"
518
+ };
519
+
520
+ // helpers/send-webview-event.ts
521
+ var sendWebviewEvent = (payload) => {
522
+ if (window.webkit) {
523
+ window.webkit?.messageHandlers?.minikit?.postMessage?.(payload);
524
+ } else if (window.Android) {
525
+ window.Android.postMessage?.(JSON.stringify(payload));
526
+ }
527
+ };
528
+
529
+ // types/responses.ts
530
+ var ResponseEvent = /* @__PURE__ */ ((ResponseEvent2) => {
531
+ ResponseEvent2["MiniAppVerifyAction"] = "miniapp-verify-action";
532
+ ResponseEvent2["MiniAppPayment"] = "miniapp-payment";
533
+ ResponseEvent2["MiniAppWalletAuth"] = "miniapp-wallet-auth";
534
+ ResponseEvent2["MiniAppSendTransaction"] = "miniapp-send-transaction";
535
+ ResponseEvent2["MiniAppSignMessage"] = "miniapp-sign-message";
536
+ ResponseEvent2["MiniAppSignTypedData"] = "miniapp-sign-typed-data";
537
+ ResponseEvent2["MiniAppShareContacts"] = "miniapp-share-contacts";
538
+ ResponseEvent2["MiniAppRequestPermission"] = "miniapp-request-permission";
539
+ return ResponseEvent2;
540
+ })(ResponseEvent || {});
473
541
 
474
542
  // minikit.ts
475
543
  var sendMiniKitEvent = (payload) => {
@@ -488,12 +556,8 @@ var _MiniKit = class _MiniKit {
488
556
  const wrappedHandler = (payload) => {
489
557
  if (payload.status === "success") {
490
558
  _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
- };
559
+ _MiniKit.getUserByAddress(payload.address).then((user) => {
560
+ _MiniKit.user = user;
497
561
  });
498
562
  }
499
563
  originalHandler(payload);
@@ -602,7 +666,8 @@ _MiniKit.commandVersion = {
602
666
  ["send-transaction" /* SendTransaction */]: 1,
603
667
  ["sign-message" /* SignMessage */]: 1,
604
668
  ["sign-typed-data" /* SignTypedData */]: 1,
605
- ["share-contacts" /* ShareContacts */]: 1
669
+ ["share-contacts" /* ShareContacts */]: 1,
670
+ ["request-permission" /* RequestPermission */]: 1
606
671
  };
607
672
  _MiniKit.isCommandAvailable = {
608
673
  ["verify" /* Verify */]: false,
@@ -611,7 +676,8 @@ _MiniKit.isCommandAvailable = {
611
676
  ["send-transaction" /* SendTransaction */]: false,
612
677
  ["sign-message" /* SignMessage */]: false,
613
678
  ["sign-typed-data" /* SignTypedData */]: false,
614
- ["share-contacts" /* ShareContacts */]: false
679
+ ["share-contacts" /* ShareContacts */]: false,
680
+ ["request-permission" /* RequestPermission */]: false
615
681
  };
616
682
  _MiniKit.listeners = {
617
683
  ["miniapp-verify-action" /* MiniAppVerifyAction */]: () => {
@@ -627,6 +693,8 @@ _MiniKit.listeners = {
627
693
  ["miniapp-sign-typed-data" /* MiniAppSignTypedData */]: () => {
628
694
  },
629
695
  ["miniapp-share-contacts" /* MiniAppShareContacts */]: () => {
696
+ },
697
+ ["miniapp-request-permission" /* MiniAppRequestPermission */]: () => {
630
698
  }
631
699
  };
632
700
  _MiniKit.appId = null;
@@ -635,6 +703,14 @@ _MiniKit.appId = null;
635
703
  */
636
704
  _MiniKit.walletAddress = null;
637
705
  _MiniKit.user = null;
706
+ _MiniKit.getUserByAddress = async (address) => {
707
+ const userProfile = await getUserProfile(address);
708
+ return {
709
+ walletAddress: address,
710
+ username: userProfile.username,
711
+ profilePictureUrl: userProfile.profilePictureUrl
712
+ };
713
+ };
638
714
  _MiniKit.commands = {
639
715
  verify: (payload) => {
640
716
  if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["verify" /* Verify */]) {
@@ -708,7 +784,7 @@ _MiniKit.commands = {
708
784
  statement: payload.statement ?? void 0,
709
785
  uri: window.location.href,
710
786
  version: 1,
711
- chain_id: 10,
787
+ chain_id: 480,
712
788
  nonce: payload.nonce,
713
789
  issued_at: (/* @__PURE__ */ new Date()).toISOString(),
714
790
  expiration_time: payload.expirationTime?.toISOString() ?? void 0,
@@ -730,6 +806,12 @@ _MiniKit.commands = {
730
806
  );
731
807
  return null;
732
808
  }
809
+ if (!validateSendTransactionPayload(payload).isValid) {
810
+ console.error(
811
+ "Invalid sendTransaction payload - some object properties are not strings"
812
+ );
813
+ return null;
814
+ }
733
815
  sendMiniKitEvent({
734
816
  command: "send-transaction" /* SendTransaction */,
735
817
  version: 1,
@@ -778,6 +860,20 @@ _MiniKit.commands = {
778
860
  payload
779
861
  });
780
862
  return payload;
863
+ },
864
+ requestPermission: (payload) => {
865
+ if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["request-permission" /* RequestPermission */]) {
866
+ console.error(
867
+ "'requestPermission' command is unavailable. Check MiniKit.install() or update the app version"
868
+ );
869
+ return null;
870
+ }
871
+ sendMiniKitEvent({
872
+ command: "request-permission" /* RequestPermission */,
873
+ version: 1,
874
+ payload
875
+ });
876
+ return payload;
781
877
  }
782
878
  };
783
879
  /**
@@ -888,6 +984,20 @@ _MiniKit.commandsAsync = {
888
984
  reject(error);
889
985
  }
890
986
  });
987
+ },
988
+ requestPermission: async (payload) => {
989
+ return new Promise(async (resolve, reject) => {
990
+ try {
991
+ const response = await _MiniKit.awaitCommand(
992
+ "miniapp-request-permission" /* MiniAppRequestPermission */,
993
+ "request-permission" /* RequestPermission */,
994
+ () => _MiniKit.commands.requestPermission(payload)
995
+ );
996
+ resolve(response);
997
+ } catch (error) {
998
+ reject(error);
999
+ }
1000
+ });
891
1001
  }
892
1002
  };
893
1003
  var MiniKit = _MiniKit;
@@ -957,6 +1067,9 @@ var getIsUserVerified = async (walletAddress, rpcUrl) => {
957
1067
  PaymentErrorCodes,
958
1068
  PaymentErrorMessage,
959
1069
  PaymentValidationErrors,
1070
+ Permission,
1071
+ RequestPermissionErrorCodes,
1072
+ RequestPermissionErrorMessage,
960
1073
  ResponseEvent,
961
1074
  SAFE_CONTRACT_ABI,
962
1075
  SendTransactionErrorCodes,