@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.js CHANGED
@@ -1,41 +1,12 @@
1
- // helpers/send-webview-event.ts
2
- var sendWebviewEvent = (payload) => {
3
- if (window.webkit) {
4
- window.webkit?.messageHandlers?.minikit?.postMessage?.(payload);
5
- } else if (window.Android) {
6
- window.Android.postMessage?.(JSON.stringify(payload));
7
- }
8
- };
9
-
10
- // types/commands.ts
11
- var Command = /* @__PURE__ */ ((Command2) => {
12
- Command2["Verify"] = "verify";
13
- Command2["Pay"] = "pay";
14
- Command2["WalletAuth"] = "wallet-auth";
15
- Command2["SendTransaction"] = "send-transaction";
16
- Command2["SignMessage"] = "sign-message";
17
- Command2["SignTypedData"] = "sign-typed-data";
18
- Command2["ShareContacts"] = "share-contacts";
19
- return Command2;
20
- })(Command || {});
21
-
22
- // types/responses.ts
23
- var ResponseEvent = /* @__PURE__ */ ((ResponseEvent2) => {
24
- ResponseEvent2["MiniAppVerifyAction"] = "miniapp-verify-action";
25
- ResponseEvent2["MiniAppPayment"] = "miniapp-payment";
26
- ResponseEvent2["MiniAppWalletAuth"] = "miniapp-wallet-auth";
27
- ResponseEvent2["MiniAppSendTransaction"] = "miniapp-send-transaction";
28
- ResponseEvent2["MiniAppSignMessage"] = "miniapp-sign-message";
29
- ResponseEvent2["MiniAppSignTypedData"] = "miniapp-sign-typed-data";
30
- ResponseEvent2["MiniAppShareContacts"] = "miniapp-share-contacts";
31
- return ResponseEvent2;
32
- })(ResponseEvent || {});
1
+ // minikit.ts
2
+ import { VerificationLevel } from "@worldcoin/idkit-core";
3
+ import { encodeAction, generateSignal } from "@worldcoin/idkit-core/hashing";
33
4
 
34
5
  // types/payment.ts
35
- var Tokens = /* @__PURE__ */ ((Tokens2) => {
36
- Tokens2["USDCE"] = "USDCE";
37
- Tokens2["WLD"] = "WLD";
38
- return Tokens2;
6
+ var Tokens = /* @__PURE__ */ ((Tokens3) => {
7
+ Tokens3["USDCE"] = "USDCE";
8
+ Tokens3["WLD"] = "WLD";
9
+ return Tokens3;
39
10
  })(Tokens || {});
40
11
  var TokenDecimals = {
41
12
  ["USDCE" /* USDCE */]: 6,
@@ -47,165 +18,42 @@ var Network = /* @__PURE__ */ ((Network2) => {
47
18
  return Network2;
48
19
  })(Network || {});
49
20
 
50
- // types/errors.ts
51
- import { AppErrorCodes } from "@worldcoin/idkit-core";
52
- import { AppErrorCodes as AppErrorCodes2 } from "@worldcoin/idkit-core";
53
- var VerificationErrorMessage = {
54
- [AppErrorCodes.VerificationRejected]: "You\u2019ve cancelled the request in World App.",
55
- [AppErrorCodes.MaxVerificationsReached]: "You have already verified the maximum number of times for this action.",
56
- [AppErrorCodes.CredentialUnavailable]: "It seems you do not have the verification level required by this app.",
57
- [AppErrorCodes.MalformedRequest]: "There was a problem with this request. Please try again or contact the app owner.",
58
- [AppErrorCodes.InvalidNetwork]: "Invalid network. If you are the app owner, visit docs.worldcoin.org/test for details.",
59
- [AppErrorCodes.InclusionProofFailed]: "There was an issue fetching your credential. Please try again.",
60
- [AppErrorCodes.InclusionProofPending]: "Your identity is still being registered. Please wait a few minutes and try again.",
61
- [AppErrorCodes.UnexpectedResponse]: "Unexpected response from your wallet. Please try again.",
62
- [AppErrorCodes.FailedByHostApp]: "Verification failed by the app. Please contact the app owner for details.",
63
- [AppErrorCodes.GenericError]: "Something unexpected went wrong. Please try again.",
64
- [AppErrorCodes.ConnectionFailed]: "Connection to your wallet failed. Please try again."
65
- };
66
- var PaymentErrorCodes = /* @__PURE__ */ ((PaymentErrorCodes2) => {
67
- PaymentErrorCodes2["InputError"] = "input_error";
68
- PaymentErrorCodes2["PaymentRejected"] = "payment_rejected";
69
- PaymentErrorCodes2["InvalidReceiver"] = "invalid_receiver";
70
- PaymentErrorCodes2["InsufficientBalance"] = "insufficient_balance";
71
- PaymentErrorCodes2["TransactionFailed"] = "transaction_failed";
72
- PaymentErrorCodes2["GenericError"] = "generic_error";
73
- PaymentErrorCodes2["UserBlocked"] = "user_blocked";
74
- return PaymentErrorCodes2;
75
- })(PaymentErrorCodes || {});
76
- var PaymentErrorMessage = {
77
- ["input_error" /* InputError */]: "There was a problem with this request. Please try again or contact the app owner.",
78
- ["payment_rejected" /* PaymentRejected */]: "You\u2019ve cancelled the payment in World App.",
79
- ["invalid_receiver" /* InvalidReceiver */]: "The receiver address is invalid. Please contact the app owner.",
80
- ["insufficient_balance" /* InsufficientBalance */]: "You do not have enough balance to complete this transaction.",
81
- ["transaction_failed" /* TransactionFailed */]: "The transaction failed. Please try again.",
82
- ["generic_error" /* GenericError */]: "Something unexpected went wrong. Please try again.",
83
- ["user_blocked" /* UserBlocked */]: "User's region is blocked from making payments."
84
- };
85
- var PaymentValidationErrors = /* @__PURE__ */ ((PaymentValidationErrors2) => {
86
- PaymentValidationErrors2["MalformedRequest"] = "There was a problem with this request. Please try again or contact the app owner.";
87
- PaymentValidationErrors2["InvalidTokenAddress"] = "The token address is invalid. Please contact the app owner.";
88
- PaymentValidationErrors2["InvalidAppId"] = "The app ID is invalid. Please contact the app owner.";
89
- PaymentValidationErrors2["DuplicateReference"] = "This reference ID already exists please generate a new one and try again.";
90
- return PaymentValidationErrors2;
91
- })(PaymentValidationErrors || {});
92
- var WalletAuthErrorCodes = /* @__PURE__ */ ((WalletAuthErrorCodes2) => {
93
- WalletAuthErrorCodes2["MalformedRequest"] = "malformed_request";
94
- WalletAuthErrorCodes2["UserRejected"] = "user_rejected";
95
- WalletAuthErrorCodes2["GenericError"] = "generic_error";
96
- return WalletAuthErrorCodes2;
97
- })(WalletAuthErrorCodes || {});
98
- var WalletAuthErrorMessage = {
99
- ["malformed_request" /* MalformedRequest */]: "Provided parameters in the request are invalid.",
100
- ["user_rejected" /* UserRejected */]: "User rejected the request.",
101
- ["generic_error" /* GenericError */]: "Something unexpected went wrong."
102
- };
103
- var SendTransactionErrorCodes = /* @__PURE__ */ ((SendTransactionErrorCodes2) => {
104
- SendTransactionErrorCodes2["InvalidOperation"] = "invalid_operation";
105
- SendTransactionErrorCodes2["UserRejected"] = "user_rejected";
106
- SendTransactionErrorCodes2["InputError"] = "input_error";
107
- SendTransactionErrorCodes2["SimulationFailed"] = "simulation_failed";
108
- SendTransactionErrorCodes2["TransactionFailed"] = "transaction_failed";
109
- SendTransactionErrorCodes2["GenericError"] = "generic_error";
110
- SendTransactionErrorCodes2["DisallowedOperation"] = "disallowed_operation";
111
- SendTransactionErrorCodes2["InvalidContract"] = "invalid_contract";
112
- SendTransactionErrorCodes2["MaliciousOperation"] = "malicious_operation";
113
- return SendTransactionErrorCodes2;
114
- })(SendTransactionErrorCodes || {});
115
- var SendTransactionErrorMessage = {
116
- ["invalid_operation" /* InvalidOperation */]: "Transaction included an operation that was invalid",
117
- ["user_rejected" /* UserRejected */]: "User rejected the request.",
118
- ["input_error" /* InputError */]: "Invalid payload.",
119
- ["simulation_failed" /* SimulationFailed */]: "The transaction simulation failed.",
120
- ["transaction_failed" /* TransactionFailed */]: "The transaction failed. Please try again later.",
121
- ["generic_error" /* GenericError */]: "Something unexpected went wrong. Please try again.",
122
- ["disallowed_operation" /* DisallowedOperation */]: "The operation requested is not allowed. Please refer to the docs.",
123
- ["invalid_contract" /* InvalidContract */]: "The contract address is not allowed for your application. Please check your developer portal configurations",
124
- ["malicious_operation" /* MaliciousOperation */]: "The operation requested is considered malicious."
125
- };
126
- var SignMessageErrorCodes = /* @__PURE__ */ ((SignMessageErrorCodes2) => {
127
- SignMessageErrorCodes2["InvalidMessage"] = "invalid_message";
128
- SignMessageErrorCodes2["UserRejected"] = "user_rejected";
129
- SignMessageErrorCodes2["GenericError"] = "generic_error";
130
- return SignMessageErrorCodes2;
131
- })(SignMessageErrorCodes || {});
132
- var SignMessageErrorMessage = {
133
- ["invalid_message" /* InvalidMessage */]: "Invalid message requested",
134
- ["user_rejected" /* UserRejected */]: "User rejected the request.",
135
- ["generic_error" /* GenericError */]: "Something unexpected went wrong."
136
- };
137
- var SignTypedDataErrorCodes = /* @__PURE__ */ ((SignTypedDataErrorCodes2) => {
138
- SignTypedDataErrorCodes2["InvalidOperation"] = "invalid_operation";
139
- SignTypedDataErrorCodes2["UserRejected"] = "user_rejected";
140
- SignTypedDataErrorCodes2["InputError"] = "input_error";
141
- SignTypedDataErrorCodes2["SimulationFailed"] = "simulation_failed";
142
- SignTypedDataErrorCodes2["GenericError"] = "generic_error";
143
- SignTypedDataErrorCodes2["DisallowedOperation"] = "disallowed_operation";
144
- SignTypedDataErrorCodes2["InvalidContract"] = "invalid_contract";
145
- SignTypedDataErrorCodes2["MaliciousOperation"] = "malicious_operation";
146
- return SignTypedDataErrorCodes2;
147
- })(SignTypedDataErrorCodes || {});
148
- var SignTypedDataErrorMessage = SendTransactionErrorMessage;
149
- var MiniKitInstallErrorCodes = /* @__PURE__ */ ((MiniKitInstallErrorCodes2) => {
150
- MiniKitInstallErrorCodes2["Unknown"] = "unknown";
151
- MiniKitInstallErrorCodes2["AlreadyInstalled"] = "already_installed";
152
- MiniKitInstallErrorCodes2["OutsideOfWorldApp"] = "outside_of_worldapp";
153
- MiniKitInstallErrorCodes2["NotOnClient"] = "not_on_client";
154
- MiniKitInstallErrorCodes2["AppOutOfDate"] = "app_out_of_date";
155
- return MiniKitInstallErrorCodes2;
156
- })(MiniKitInstallErrorCodes || {});
157
- var MiniKitInstallErrorMessage = {
158
- ["unknown" /* Unknown */]: "Failed to install MiniKit.",
159
- ["already_installed" /* AlreadyInstalled */]: "MiniKit is already installed.",
160
- ["outside_of_worldapp" /* OutsideOfWorldApp */]: "MiniApp launched outside of WorldApp.",
161
- ["not_on_client" /* NotOnClient */]: "Window object is not available.",
162
- ["app_out_of_date" /* AppOutOfDate */]: "WorldApp is out of date. Please update the app."
163
- };
164
- var ShareContactsErrorCodes = /* @__PURE__ */ ((ShareContactsErrorCodes2) => {
165
- ShareContactsErrorCodes2["UserRejected"] = "user_rejected";
166
- ShareContactsErrorCodes2["GenericError"] = "generic_error";
167
- return ShareContactsErrorCodes2;
168
- })(ShareContactsErrorCodes || {});
169
- var ShareContactsErrorMessage = {
170
- ["user_rejected" /* UserRejected */]: "User rejected the request.",
171
- ["generic_error" /* GenericError */]: "Something unexpected went wrong."
172
- };
173
-
174
- // minikit.ts
175
- import { VerificationLevel } from "@worldcoin/idkit-core";
176
- import { generateSignal, encodeAction } from "@worldcoin/idkit-core/hashing";
177
-
178
- // helpers/siwe/validate-wallet-auth-command-input.ts
179
- var validateWalletAuthCommandInput = (params) => {
180
- if (!params.nonce) {
181
- return { valid: false, message: "'nonce' is required" };
182
- }
183
- if (params.nonce.length < 8) {
184
- return { valid: false, message: "'nonce' must be at least 8 characters" };
185
- }
186
- if (params.statement && params.statement.includes("\n")) {
187
- return { valid: false, message: "'statement' must not contain newlines" };
21
+ // helpers/payment/client.ts
22
+ var tokenToDecimals = (amount, token) => {
23
+ const decimals = TokenDecimals[token];
24
+ if (decimals === void 0) {
25
+ throw new Error(`Invalid token: ${token}`);
188
26
  }
189
- if (params.expirationTime && new Date(params.expirationTime) < /* @__PURE__ */ new Date()) {
190
- return { valid: false, message: "'expirationTime' must be in the future" };
27
+ const factor = 10 ** decimals;
28
+ const result = amount * factor;
29
+ if (!Number.isInteger(result)) {
30
+ throw new Error(`The resulting amount is not a whole number: ${result}`);
191
31
  }
192
- if (params.expirationTime && new Date(params.expirationTime) > new Date(Date.now() + 7 * 24 * 60 * 60 * 1e3)) {
193
- return { valid: false, message: "'expirationTime' must be within 7 days" };
32
+ return result;
33
+ };
34
+ var validatePaymentPayload = (payload) => {
35
+ if (payload.tokens.some(
36
+ (token) => token.symbol == "USDCE" && parseFloat(token.token_amount) < 0.1
37
+ )) {
38
+ console.error("USDCE amount should be greater than $0.1");
39
+ return false;
194
40
  }
195
- if (params.notBefore && new Date(params.notBefore) > new Date(Date.now() + 7 * 24 * 60 * 60 * 1e3)) {
196
- return { valid: false, message: "'notBefore' must be within 7 days" };
41
+ if (payload.reference.length > 36) {
42
+ console.error("Reference must not exceed 36 characters");
43
+ return false;
197
44
  }
198
- return { valid: true };
45
+ return true;
199
46
  };
200
47
 
201
48
  // helpers/siwe/siwe.ts
202
49
  import {
203
- hashMessage,
204
50
  createPublicClient,
51
+ getContract,
52
+ hashMessage,
205
53
  http,
206
- getContract
54
+ recoverAddress
207
55
  } from "viem";
208
- import { optimism } from "viem/chains";
56
+ import { worldchain } from "viem/chains";
209
57
  var PREAMBLE = " wants you to sign in with your Ethereum account:";
210
58
  var URI_TAG = "URI: ";
211
59
  var VERSION_TAG = "Version: ";
@@ -314,15 +162,23 @@ var generateSiweMessage = (siweMessageData) => {
314
162
  };
315
163
  var SAFE_CONTRACT_ABI = [
316
164
  {
317
- name: "checkSignatures",
318
- type: "function",
319
- stateMutability: "view",
320
165
  inputs: [
321
- { name: "dataHash", type: "bytes32" },
322
- { name: "data", type: "bytes" },
323
- { name: "signature", type: "bytes" }
166
+ {
167
+ internalType: "address",
168
+ name: "owner",
169
+ type: "address"
170
+ }
324
171
  ],
325
- outputs: []
172
+ name: "isOwner",
173
+ outputs: [
174
+ {
175
+ internalType: "bool",
176
+ name: "",
177
+ type: "bool"
178
+ }
179
+ ],
180
+ stateMutability: "view",
181
+ type: "function"
326
182
  }
327
183
  ];
328
184
  var verifySiweMessage = async (payload, nonce, statement, requestId, userProvider) => {
@@ -358,9 +214,8 @@ var verifySiweMessage = async (payload, nonce, statement, requestId, userProvide
358
214
  `Request ID mismatch. Got: ${siweMessageData.request_id}, Expected: ${requestId}`
359
215
  );
360
216
  }
361
- let provider = userProvider || createPublicClient({ chain: optimism, transport: http() });
217
+ let provider = userProvider || createPublicClient({ chain: worldchain, transport: http() });
362
218
  const signedMessage = `${ERC_191_PREFIX}${message.length}${message}`;
363
- const messageBytes = Buffer.from(signedMessage, "utf8").toString("hex");
364
219
  const hashedMessage = hashMessage(signedMessage);
365
220
  const contract = getContract({
366
221
  address,
@@ -368,43 +223,59 @@ var verifySiweMessage = async (payload, nonce, statement, requestId, userProvide
368
223
  client: provider
369
224
  });
370
225
  try {
371
- await contract.read.checkSignatures([
372
- hashedMessage,
373
- `0x${messageBytes}`,
374
- `0x${signature}`
375
- ]);
226
+ const recoveredAddress = await recoverAddress({
227
+ hash: hashedMessage,
228
+ signature: `0x${signature}`
229
+ });
230
+ const isOwner = await contract.read.isOwner([recoveredAddress]);
231
+ if (!isOwner) {
232
+ throw new Error("Signature verification failed, invalid owner");
233
+ }
376
234
  } catch (error) {
377
235
  throw new Error("Signature verification failed");
378
236
  }
379
237
  return { isValid: true, siweMessageData };
380
238
  };
381
239
 
382
- // helpers/payment/client.ts
383
- var tokenToDecimals = (amount, token) => {
384
- const decimals = TokenDecimals[token];
385
- if (decimals === void 0) {
386
- throw new Error(`Invalid token: ${token}`);
240
+ // helpers/siwe/validate-wallet-auth-command-input.ts
241
+ var validateWalletAuthCommandInput = (params) => {
242
+ if (!params.nonce) {
243
+ return { valid: false, message: "'nonce' is required" };
387
244
  }
388
- const factor = 10 ** decimals;
389
- const result = amount * factor;
390
- if (!Number.isInteger(result)) {
391
- throw new Error(`The resulting amount is not a whole number: ${result}`);
245
+ if (params.nonce.length < 8) {
246
+ return { valid: false, message: "'nonce' must be at least 8 characters" };
392
247
  }
393
- return result;
248
+ if (params.statement && params.statement.includes("\n")) {
249
+ return { valid: false, message: "'statement' must not contain newlines" };
250
+ }
251
+ if (params.expirationTime && new Date(params.expirationTime) < /* @__PURE__ */ new Date()) {
252
+ return { valid: false, message: "'expirationTime' must be in the future" };
253
+ }
254
+ if (params.expirationTime && new Date(params.expirationTime) > new Date(Date.now() + 7 * 24 * 60 * 60 * 1e3)) {
255
+ return { valid: false, message: "'expirationTime' must be within 7 days" };
256
+ }
257
+ if (params.notBefore && new Date(params.notBefore) > new Date(Date.now() + 7 * 24 * 60 * 60 * 1e3)) {
258
+ return { valid: false, message: "'notBefore' must be within 7 days" };
259
+ }
260
+ return { valid: true };
394
261
  };
395
- var validatePaymentPayload = (payload) => {
396
- if (payload.tokens.some(
397
- (token) => token.symbol == "USDCE" && parseFloat(token.token_amount) < 0.1
398
- )) {
399
- console.error("USDCE amount should be greater than $0.1");
400
- return false;
262
+
263
+ // helpers/transaction/validate-payload.ts
264
+ var validate = (payload) => {
265
+ if (typeof payload === "string") return { isValid: true };
266
+ if (typeof payload === "object") {
267
+ const isValid = Object.values(payload).every(
268
+ (value) => validate(value).isValid
269
+ );
270
+ return { isValid };
401
271
  }
402
- if (payload.reference.length > 36) {
403
- console.error("Reference must not exceed 36 characters");
404
- return false;
272
+ if (Array.isArray(payload)) {
273
+ const isValid = payload.every((value) => validate(value).isValid);
274
+ return { isValid };
405
275
  }
406
- return true;
276
+ return { isValid: false };
407
277
  };
278
+ var validateSendTransactionPayload = (payload) => validate(payload);
408
279
 
409
280
  // helpers/usernames/index.ts
410
281
  var getUserProfile = async (address) => {
@@ -418,9 +289,189 @@ var getUserProfile = async (address) => {
418
289
  })
419
290
  });
420
291
  const usernames = await res.json();
421
- return usernames[0] ?? { username: null, profilePictureUrl: null };
292
+ return usernames?.[0] ?? { username: null, profilePictureUrl: null };
422
293
  };
423
294
 
295
+ // types/commands.ts
296
+ var Command = /* @__PURE__ */ ((Command2) => {
297
+ Command2["Verify"] = "verify";
298
+ Command2["Pay"] = "pay";
299
+ Command2["WalletAuth"] = "wallet-auth";
300
+ Command2["SendTransaction"] = "send-transaction";
301
+ Command2["SignMessage"] = "sign-message";
302
+ Command2["SignTypedData"] = "sign-typed-data";
303
+ Command2["ShareContacts"] = "share-contacts";
304
+ Command2["RequestPermission"] = "request-permission";
305
+ return Command2;
306
+ })(Command || {});
307
+ var Permission = /* @__PURE__ */ ((Permission2) => {
308
+ Permission2["Notifications"] = "notifications";
309
+ return Permission2;
310
+ })(Permission || {});
311
+
312
+ // types/errors.ts
313
+ import { AppErrorCodes } from "@worldcoin/idkit-core";
314
+ import { AppErrorCodes as AppErrorCodes2 } from "@worldcoin/idkit-core";
315
+ var VerificationErrorMessage = {
316
+ [AppErrorCodes.VerificationRejected]: "You\u2019ve cancelled the request in World App.",
317
+ [AppErrorCodes.MaxVerificationsReached]: "You have already verified the maximum number of times for this action.",
318
+ [AppErrorCodes.CredentialUnavailable]: "It seems you do not have the verification level required by this app.",
319
+ [AppErrorCodes.MalformedRequest]: "There was a problem with this request. Please try again or contact the app owner.",
320
+ [AppErrorCodes.InvalidNetwork]: "Invalid network. If you are the app owner, visit docs.worldcoin.org/test for details.",
321
+ [AppErrorCodes.InclusionProofFailed]: "There was an issue fetching your credential. Please try again.",
322
+ [AppErrorCodes.InclusionProofPending]: "Your identity is still being registered. Please wait a few minutes and try again.",
323
+ [AppErrorCodes.UnexpectedResponse]: "Unexpected response from your wallet. Please try again.",
324
+ [AppErrorCodes.FailedByHostApp]: "Verification failed by the app. Please contact the app owner for details.",
325
+ [AppErrorCodes.GenericError]: "Something unexpected went wrong. Please try again.",
326
+ [AppErrorCodes.ConnectionFailed]: "Connection to your wallet failed. Please try again."
327
+ };
328
+ var PaymentErrorCodes = /* @__PURE__ */ ((PaymentErrorCodes2) => {
329
+ PaymentErrorCodes2["InputError"] = "input_error";
330
+ PaymentErrorCodes2["PaymentRejected"] = "payment_rejected";
331
+ PaymentErrorCodes2["InvalidReceiver"] = "invalid_receiver";
332
+ PaymentErrorCodes2["InsufficientBalance"] = "insufficient_balance";
333
+ PaymentErrorCodes2["TransactionFailed"] = "transaction_failed";
334
+ PaymentErrorCodes2["GenericError"] = "generic_error";
335
+ PaymentErrorCodes2["UserBlocked"] = "user_blocked";
336
+ return PaymentErrorCodes2;
337
+ })(PaymentErrorCodes || {});
338
+ var PaymentErrorMessage = {
339
+ ["input_error" /* InputError */]: "There was a problem with this request. Please try again or contact the app owner.",
340
+ ["payment_rejected" /* PaymentRejected */]: "You\u2019ve cancelled the payment in World App.",
341
+ ["invalid_receiver" /* InvalidReceiver */]: "The receiver address is invalid. Please contact the app owner.",
342
+ ["insufficient_balance" /* InsufficientBalance */]: "You do not have enough balance to complete this transaction.",
343
+ ["transaction_failed" /* TransactionFailed */]: "The transaction failed. Please try again.",
344
+ ["generic_error" /* GenericError */]: "Something unexpected went wrong. Please try again.",
345
+ ["user_blocked" /* UserBlocked */]: "User's region is blocked from making payments."
346
+ };
347
+ var PaymentValidationErrors = /* @__PURE__ */ ((PaymentValidationErrors2) => {
348
+ PaymentValidationErrors2["MalformedRequest"] = "There was a problem with this request. Please try again or contact the app owner.";
349
+ PaymentValidationErrors2["InvalidTokenAddress"] = "The token address is invalid. Please contact the app owner.";
350
+ PaymentValidationErrors2["InvalidAppId"] = "The app ID is invalid. Please contact the app owner.";
351
+ PaymentValidationErrors2["DuplicateReference"] = "This reference ID already exists please generate a new one and try again.";
352
+ return PaymentValidationErrors2;
353
+ })(PaymentValidationErrors || {});
354
+ var WalletAuthErrorCodes = /* @__PURE__ */ ((WalletAuthErrorCodes2) => {
355
+ WalletAuthErrorCodes2["MalformedRequest"] = "malformed_request";
356
+ WalletAuthErrorCodes2["UserRejected"] = "user_rejected";
357
+ WalletAuthErrorCodes2["GenericError"] = "generic_error";
358
+ return WalletAuthErrorCodes2;
359
+ })(WalletAuthErrorCodes || {});
360
+ var WalletAuthErrorMessage = {
361
+ ["malformed_request" /* MalformedRequest */]: "Provided parameters in the request are invalid.",
362
+ ["user_rejected" /* UserRejected */]: "User rejected the request.",
363
+ ["generic_error" /* GenericError */]: "Something unexpected went wrong."
364
+ };
365
+ var SendTransactionErrorCodes = /* @__PURE__ */ ((SendTransactionErrorCodes2) => {
366
+ SendTransactionErrorCodes2["InvalidOperation"] = "invalid_operation";
367
+ SendTransactionErrorCodes2["UserRejected"] = "user_rejected";
368
+ SendTransactionErrorCodes2["InputError"] = "input_error";
369
+ SendTransactionErrorCodes2["SimulationFailed"] = "simulation_failed";
370
+ SendTransactionErrorCodes2["TransactionFailed"] = "transaction_failed";
371
+ SendTransactionErrorCodes2["GenericError"] = "generic_error";
372
+ SendTransactionErrorCodes2["DisallowedOperation"] = "disallowed_operation";
373
+ SendTransactionErrorCodes2["InvalidContract"] = "invalid_contract";
374
+ SendTransactionErrorCodes2["MaliciousOperation"] = "malicious_operation";
375
+ return SendTransactionErrorCodes2;
376
+ })(SendTransactionErrorCodes || {});
377
+ var SendTransactionErrorMessage = {
378
+ ["invalid_operation" /* InvalidOperation */]: "Transaction included an operation that was invalid",
379
+ ["user_rejected" /* UserRejected */]: "User rejected the request.",
380
+ ["input_error" /* InputError */]: "Invalid payload.",
381
+ ["simulation_failed" /* SimulationFailed */]: "The transaction simulation failed.",
382
+ ["transaction_failed" /* TransactionFailed */]: "The transaction failed. Please try again later.",
383
+ ["generic_error" /* GenericError */]: "Something unexpected went wrong. Please try again.",
384
+ ["disallowed_operation" /* DisallowedOperation */]: "The operation requested is not allowed. Please refer to the docs.",
385
+ ["invalid_contract" /* InvalidContract */]: "The contract address is not allowed for your application. Please check your developer portal configurations",
386
+ ["malicious_operation" /* MaliciousOperation */]: "The operation requested is considered malicious."
387
+ };
388
+ var SignMessageErrorCodes = /* @__PURE__ */ ((SignMessageErrorCodes2) => {
389
+ SignMessageErrorCodes2["InvalidMessage"] = "invalid_message";
390
+ SignMessageErrorCodes2["UserRejected"] = "user_rejected";
391
+ SignMessageErrorCodes2["GenericError"] = "generic_error";
392
+ return SignMessageErrorCodes2;
393
+ })(SignMessageErrorCodes || {});
394
+ var SignMessageErrorMessage = {
395
+ ["invalid_message" /* InvalidMessage */]: "Invalid message requested",
396
+ ["user_rejected" /* UserRejected */]: "User rejected the request.",
397
+ ["generic_error" /* GenericError */]: "Something unexpected went wrong."
398
+ };
399
+ var SignTypedDataErrorCodes = /* @__PURE__ */ ((SignTypedDataErrorCodes2) => {
400
+ SignTypedDataErrorCodes2["InvalidOperation"] = "invalid_operation";
401
+ SignTypedDataErrorCodes2["UserRejected"] = "user_rejected";
402
+ SignTypedDataErrorCodes2["InputError"] = "input_error";
403
+ SignTypedDataErrorCodes2["SimulationFailed"] = "simulation_failed";
404
+ SignTypedDataErrorCodes2["GenericError"] = "generic_error";
405
+ SignTypedDataErrorCodes2["DisallowedOperation"] = "disallowed_operation";
406
+ SignTypedDataErrorCodes2["InvalidContract"] = "invalid_contract";
407
+ SignTypedDataErrorCodes2["MaliciousOperation"] = "malicious_operation";
408
+ return SignTypedDataErrorCodes2;
409
+ })(SignTypedDataErrorCodes || {});
410
+ var SignTypedDataErrorMessage = SendTransactionErrorMessage;
411
+ var MiniKitInstallErrorCodes = /* @__PURE__ */ ((MiniKitInstallErrorCodes2) => {
412
+ MiniKitInstallErrorCodes2["Unknown"] = "unknown";
413
+ MiniKitInstallErrorCodes2["AlreadyInstalled"] = "already_installed";
414
+ MiniKitInstallErrorCodes2["OutsideOfWorldApp"] = "outside_of_worldapp";
415
+ MiniKitInstallErrorCodes2["NotOnClient"] = "not_on_client";
416
+ MiniKitInstallErrorCodes2["AppOutOfDate"] = "app_out_of_date";
417
+ return MiniKitInstallErrorCodes2;
418
+ })(MiniKitInstallErrorCodes || {});
419
+ var MiniKitInstallErrorMessage = {
420
+ ["unknown" /* Unknown */]: "Failed to install MiniKit.",
421
+ ["already_installed" /* AlreadyInstalled */]: "MiniKit is already installed.",
422
+ ["outside_of_worldapp" /* OutsideOfWorldApp */]: "MiniApp launched outside of WorldApp.",
423
+ ["not_on_client" /* NotOnClient */]: "Window object is not available.",
424
+ ["app_out_of_date" /* AppOutOfDate */]: "WorldApp is out of date. Please update the app."
425
+ };
426
+ var ShareContactsErrorCodes = /* @__PURE__ */ ((ShareContactsErrorCodes2) => {
427
+ ShareContactsErrorCodes2["UserRejected"] = "user_rejected";
428
+ ShareContactsErrorCodes2["GenericError"] = "generic_error";
429
+ return ShareContactsErrorCodes2;
430
+ })(ShareContactsErrorCodes || {});
431
+ var ShareContactsErrorMessage = {
432
+ ["user_rejected" /* UserRejected */]: "User rejected the request.",
433
+ ["generic_error" /* GenericError */]: "Something unexpected went wrong."
434
+ };
435
+ var RequestPermissionErrorCodes = /* @__PURE__ */ ((RequestPermissionErrorCodes2) => {
436
+ RequestPermissionErrorCodes2["UserRejected"] = "user_rejected";
437
+ RequestPermissionErrorCodes2["GenericError"] = "generic_error";
438
+ RequestPermissionErrorCodes2["AlreadyRequested"] = "already_requested";
439
+ RequestPermissionErrorCodes2["PermissionDisabled"] = "permission_disabled";
440
+ RequestPermissionErrorCodes2["AlreadyGranted"] = "already_granted";
441
+ RequestPermissionErrorCodes2["UnsupportedPermission"] = "unsupported_permission";
442
+ return RequestPermissionErrorCodes2;
443
+ })(RequestPermissionErrorCodes || {});
444
+ var RequestPermissionErrorMessage = {
445
+ ["user_rejected" /* UserRejected */]: "User declined sharing contacts",
446
+ ["generic_error" /* GenericError */]: "Request failed for unknown reason.",
447
+ ["already_requested" /* AlreadyRequested */]: "User has already declined turning on notifications once",
448
+ ["permission_disabled" /* PermissionDisabled */]: "User does not have this permission enabled in World App",
449
+ ["already_granted" /* AlreadyGranted */]: "If the user has already granted this mini app permission",
450
+ ["unsupported_permission" /* UnsupportedPermission */]: "The permission requested is not supported by this mini app"
451
+ };
452
+
453
+ // helpers/send-webview-event.ts
454
+ var sendWebviewEvent = (payload) => {
455
+ if (window.webkit) {
456
+ window.webkit?.messageHandlers?.minikit?.postMessage?.(payload);
457
+ } else if (window.Android) {
458
+ window.Android.postMessage?.(JSON.stringify(payload));
459
+ }
460
+ };
461
+
462
+ // types/responses.ts
463
+ var ResponseEvent = /* @__PURE__ */ ((ResponseEvent2) => {
464
+ ResponseEvent2["MiniAppVerifyAction"] = "miniapp-verify-action";
465
+ ResponseEvent2["MiniAppPayment"] = "miniapp-payment";
466
+ ResponseEvent2["MiniAppWalletAuth"] = "miniapp-wallet-auth";
467
+ ResponseEvent2["MiniAppSendTransaction"] = "miniapp-send-transaction";
468
+ ResponseEvent2["MiniAppSignMessage"] = "miniapp-sign-message";
469
+ ResponseEvent2["MiniAppSignTypedData"] = "miniapp-sign-typed-data";
470
+ ResponseEvent2["MiniAppShareContacts"] = "miniapp-share-contacts";
471
+ ResponseEvent2["MiniAppRequestPermission"] = "miniapp-request-permission";
472
+ return ResponseEvent2;
473
+ })(ResponseEvent || {});
474
+
424
475
  // minikit.ts
425
476
  var sendMiniKitEvent = (payload) => {
426
477
  sendWebviewEvent(payload);
@@ -438,12 +489,8 @@ var _MiniKit = class _MiniKit {
438
489
  const wrappedHandler = (payload) => {
439
490
  if (payload.status === "success") {
440
491
  _MiniKit.walletAddress = payload.address;
441
- getUserProfile(payload.address).then((queryResponse) => {
442
- _MiniKit.user = {
443
- username: queryResponse.username,
444
- profilePictureUrl: queryResponse.profilePictureUrl,
445
- walletAddress: payload.address
446
- };
492
+ _MiniKit.getUserByAddress(payload.address).then((user) => {
493
+ _MiniKit.user = user;
447
494
  });
448
495
  }
449
496
  originalHandler(payload);
@@ -552,7 +599,8 @@ _MiniKit.commandVersion = {
552
599
  ["send-transaction" /* SendTransaction */]: 1,
553
600
  ["sign-message" /* SignMessage */]: 1,
554
601
  ["sign-typed-data" /* SignTypedData */]: 1,
555
- ["share-contacts" /* ShareContacts */]: 1
602
+ ["share-contacts" /* ShareContacts */]: 1,
603
+ ["request-permission" /* RequestPermission */]: 1
556
604
  };
557
605
  _MiniKit.isCommandAvailable = {
558
606
  ["verify" /* Verify */]: false,
@@ -561,7 +609,8 @@ _MiniKit.isCommandAvailable = {
561
609
  ["send-transaction" /* SendTransaction */]: false,
562
610
  ["sign-message" /* SignMessage */]: false,
563
611
  ["sign-typed-data" /* SignTypedData */]: false,
564
- ["share-contacts" /* ShareContacts */]: false
612
+ ["share-contacts" /* ShareContacts */]: false,
613
+ ["request-permission" /* RequestPermission */]: false
565
614
  };
566
615
  _MiniKit.listeners = {
567
616
  ["miniapp-verify-action" /* MiniAppVerifyAction */]: () => {
@@ -577,6 +626,8 @@ _MiniKit.listeners = {
577
626
  ["miniapp-sign-typed-data" /* MiniAppSignTypedData */]: () => {
578
627
  },
579
628
  ["miniapp-share-contacts" /* MiniAppShareContacts */]: () => {
629
+ },
630
+ ["miniapp-request-permission" /* MiniAppRequestPermission */]: () => {
580
631
  }
581
632
  };
582
633
  _MiniKit.appId = null;
@@ -585,6 +636,14 @@ _MiniKit.appId = null;
585
636
  */
586
637
  _MiniKit.walletAddress = null;
587
638
  _MiniKit.user = null;
639
+ _MiniKit.getUserByAddress = async (address) => {
640
+ const userProfile = await getUserProfile(address);
641
+ return {
642
+ walletAddress: address,
643
+ username: userProfile.username,
644
+ profilePictureUrl: userProfile.profilePictureUrl
645
+ };
646
+ };
588
647
  _MiniKit.commands = {
589
648
  verify: (payload) => {
590
649
  if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["verify" /* Verify */]) {
@@ -658,7 +717,7 @@ _MiniKit.commands = {
658
717
  statement: payload.statement ?? void 0,
659
718
  uri: window.location.href,
660
719
  version: 1,
661
- chain_id: 10,
720
+ chain_id: 480,
662
721
  nonce: payload.nonce,
663
722
  issued_at: (/* @__PURE__ */ new Date()).toISOString(),
664
723
  expiration_time: payload.expirationTime?.toISOString() ?? void 0,
@@ -680,6 +739,12 @@ _MiniKit.commands = {
680
739
  );
681
740
  return null;
682
741
  }
742
+ if (!validateSendTransactionPayload(payload).isValid) {
743
+ console.error(
744
+ "Invalid sendTransaction payload - some object properties are not strings"
745
+ );
746
+ return null;
747
+ }
683
748
  sendMiniKitEvent({
684
749
  command: "send-transaction" /* SendTransaction */,
685
750
  version: 1,
@@ -728,6 +793,20 @@ _MiniKit.commands = {
728
793
  payload
729
794
  });
730
795
  return payload;
796
+ },
797
+ requestPermission: (payload) => {
798
+ if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["request-permission" /* RequestPermission */]) {
799
+ console.error(
800
+ "'requestPermission' command is unavailable. Check MiniKit.install() or update the app version"
801
+ );
802
+ return null;
803
+ }
804
+ sendMiniKitEvent({
805
+ command: "request-permission" /* RequestPermission */,
806
+ version: 1,
807
+ payload
808
+ });
809
+ return payload;
731
810
  }
732
811
  };
733
812
  /**
@@ -838,6 +917,20 @@ _MiniKit.commandsAsync = {
838
917
  reject(error);
839
918
  }
840
919
  });
920
+ },
921
+ requestPermission: async (payload) => {
922
+ return new Promise(async (resolve, reject) => {
923
+ try {
924
+ const response = await _MiniKit.awaitCommand(
925
+ "miniapp-request-permission" /* MiniAppRequestPermission */,
926
+ "request-permission" /* RequestPermission */,
927
+ () => _MiniKit.commands.requestPermission(payload)
928
+ );
929
+ resolve(response);
930
+ } catch (error) {
931
+ reject(error);
932
+ }
933
+ });
841
934
  }
842
935
  };
843
936
  var MiniKit = _MiniKit;
@@ -850,7 +943,7 @@ import {
850
943
 
851
944
  // helpers/address-book/index.ts
852
945
  import { createPublicClient as createPublicClient2, http as http2 } from "viem";
853
- import { worldchain } from "viem/chains";
946
+ import { worldchain as worldchain2 } from "viem/chains";
854
947
  var worldIdAddressBookContractAddress = "0x57b930D551e677CC36e2fA036Ae2fe8FdaE0330D";
855
948
  var addressVerifiedUntilAbi = [
856
949
  {
@@ -875,7 +968,7 @@ var addressVerifiedUntilAbi = [
875
968
  ];
876
969
  var getIsUserVerified = async (walletAddress, rpcUrl) => {
877
970
  const publicClient = createPublicClient2({
878
- chain: worldchain,
971
+ chain: worldchain2,
879
972
  transport: http2(
880
973
  rpcUrl || "https://worldchain-mainnet.g.alchemy.com/public"
881
974
  )
@@ -908,6 +1001,9 @@ export {
908
1001
  PaymentErrorCodes,
909
1002
  PaymentErrorMessage,
910
1003
  PaymentValidationErrors,
1004
+ Permission,
1005
+ RequestPermissionErrorCodes,
1006
+ RequestPermissionErrorMessage,
911
1007
  ResponseEvent,
912
1008
  SAFE_CONTRACT_ABI,
913
1009
  SendTransactionErrorCodes,