@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.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,45 @@ 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" };
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}`);
185
26
  }
186
- if (params.statement && params.statement.includes("\n")) {
187
- return { valid: false, message: "'statement' must not contain newlines" };
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}`);
188
31
  }
189
- if (params.expirationTime && new Date(params.expirationTime) < /* @__PURE__ */ new Date()) {
190
- return { valid: false, message: "'expirationTime' must be in the future" };
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;
191
40
  }
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" };
41
+ if (payload.reference.length > 36) {
42
+ console.error("Reference must not exceed 36 characters");
43
+ return false;
194
44
  }
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" };
45
+ if (typeof payload.reference !== "string") {
46
+ throw new Error("Reference must be a string");
197
47
  }
198
- return { valid: true };
48
+ return true;
199
49
  };
200
50
 
201
51
  // helpers/siwe/siwe.ts
202
52
  import {
203
- hashMessage,
204
53
  createPublicClient,
54
+ getContract,
55
+ hashMessage,
205
56
  http,
206
- getContract
57
+ recoverAddress
207
58
  } from "viem";
208
- import { optimism } from "viem/chains";
59
+ import { worldchain } from "viem/chains";
209
60
  var PREAMBLE = " wants you to sign in with your Ethereum account:";
210
61
  var URI_TAG = "URI: ";
211
62
  var VERSION_TAG = "Version: ";
@@ -314,15 +165,23 @@ var generateSiweMessage = (siweMessageData) => {
314
165
  };
315
166
  var SAFE_CONTRACT_ABI = [
316
167
  {
317
- name: "checkSignatures",
318
- type: "function",
319
- stateMutability: "view",
320
168
  inputs: [
321
- { name: "dataHash", type: "bytes32" },
322
- { name: "data", type: "bytes" },
323
- { name: "signature", type: "bytes" }
169
+ {
170
+ internalType: "address",
171
+ name: "owner",
172
+ type: "address"
173
+ }
324
174
  ],
325
- outputs: []
175
+ name: "isOwner",
176
+ outputs: [
177
+ {
178
+ internalType: "bool",
179
+ name: "",
180
+ type: "bool"
181
+ }
182
+ ],
183
+ stateMutability: "view",
184
+ type: "function"
326
185
  }
327
186
  ];
328
187
  var verifySiweMessage = async (payload, nonce, statement, requestId, userProvider) => {
@@ -358,9 +217,8 @@ var verifySiweMessage = async (payload, nonce, statement, requestId, userProvide
358
217
  `Request ID mismatch. Got: ${siweMessageData.request_id}, Expected: ${requestId}`
359
218
  );
360
219
  }
361
- let provider = userProvider || createPublicClient({ chain: optimism, transport: http() });
220
+ let provider = userProvider || createPublicClient({ chain: worldchain, transport: http() });
362
221
  const signedMessage = `${ERC_191_PREFIX}${message.length}${message}`;
363
- const messageBytes = Buffer.from(signedMessage, "utf8").toString("hex");
364
222
  const hashedMessage = hashMessage(signedMessage);
365
223
  const contract = getContract({
366
224
  address,
@@ -368,43 +226,71 @@ var verifySiweMessage = async (payload, nonce, statement, requestId, userProvide
368
226
  client: provider
369
227
  });
370
228
  try {
371
- await contract.read.checkSignatures([
372
- hashedMessage,
373
- `0x${messageBytes}`,
374
- `0x${signature}`
375
- ]);
229
+ const recoveredAddress = await recoverAddress({
230
+ hash: hashedMessage,
231
+ signature: `0x${signature}`
232
+ });
233
+ const isOwner = await contract.read.isOwner([recoveredAddress]);
234
+ if (!isOwner) {
235
+ throw new Error("Signature verification failed, invalid owner");
236
+ }
376
237
  } catch (error) {
377
238
  throw new Error("Signature verification failed");
378
239
  }
379
240
  return { isValid: true, siweMessageData };
380
241
  };
381
242
 
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}`);
243
+ // helpers/siwe/validate-wallet-auth-command-input.ts
244
+ var validateWalletAuthCommandInput = (params) => {
245
+ if (!params.nonce) {
246
+ return { valid: false, message: "'nonce' is required" };
387
247
  }
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}`);
248
+ if (params.nonce.length < 8) {
249
+ return { valid: false, message: "'nonce' must be at least 8 characters" };
392
250
  }
393
- return result;
251
+ if (params.statement && params.statement.includes("\n")) {
252
+ return { valid: false, message: "'statement' must not contain newlines" };
253
+ }
254
+ if (params.expirationTime && new Date(params.expirationTime) < /* @__PURE__ */ new Date()) {
255
+ return { valid: false, message: "'expirationTime' must be in the future" };
256
+ }
257
+ if (params.expirationTime && new Date(params.expirationTime) > new Date(Date.now() + 7 * 24 * 60 * 60 * 1e3)) {
258
+ return { valid: false, message: "'expirationTime' must be within 7 days" };
259
+ }
260
+ if (params.notBefore && new Date(params.notBefore) > new Date(Date.now() + 7 * 24 * 60 * 60 * 1e3)) {
261
+ return { valid: false, message: "'notBefore' must be within 7 days" };
262
+ }
263
+ return { valid: true };
394
264
  };
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;
265
+
266
+ // helpers/transaction/validate-payload.ts
267
+ var isValidHex = (str) => {
268
+ return /^0x[0-9A-Fa-f]+$/.test(str);
269
+ };
270
+ var validate = (payload) => {
271
+ if (typeof payload === "string") return { isValid: true };
272
+ if (Array.isArray(payload)) {
273
+ const isValid = payload.every((value) => validate(value).isValid);
274
+ return { isValid };
401
275
  }
402
- if (payload.reference.length > 36) {
403
- console.error("Reference must not exceed 36 characters");
404
- return false;
276
+ if (typeof payload === "object" && payload !== null) {
277
+ if ("value" in payload && payload.value !== void 0) {
278
+ if (typeof payload.value !== "string" || !isValidHex(payload.value)) {
279
+ console.error(
280
+ "Transaction value must be a valid hex string",
281
+ payload.value
282
+ );
283
+ return { isValid: false };
284
+ }
285
+ }
286
+ const isValid = Object.values(payload).every(
287
+ (value) => validate(value).isValid
288
+ );
289
+ return { isValid };
405
290
  }
406
- return true;
291
+ return { isValid: false };
407
292
  };
293
+ var validateSendTransactionPayload = (payload) => validate(payload);
408
294
 
409
295
  // helpers/usernames/index.ts
410
296
  var getUserProfile = async (address) => {
@@ -418,9 +304,189 @@ var getUserProfile = async (address) => {
418
304
  })
419
305
  });
420
306
  const usernames = await res.json();
421
- return usernames[0] ?? { username: null, profilePictureUrl: null };
307
+ return usernames?.[0] ?? { username: null, profilePictureUrl: null };
422
308
  };
423
309
 
310
+ // types/commands.ts
311
+ var Command = /* @__PURE__ */ ((Command2) => {
312
+ Command2["Verify"] = "verify";
313
+ Command2["Pay"] = "pay";
314
+ Command2["WalletAuth"] = "wallet-auth";
315
+ Command2["SendTransaction"] = "send-transaction";
316
+ Command2["SignMessage"] = "sign-message";
317
+ Command2["SignTypedData"] = "sign-typed-data";
318
+ Command2["ShareContacts"] = "share-contacts";
319
+ Command2["RequestPermission"] = "request-permission";
320
+ return Command2;
321
+ })(Command || {});
322
+ var Permission = /* @__PURE__ */ ((Permission2) => {
323
+ Permission2["Notifications"] = "notifications";
324
+ return Permission2;
325
+ })(Permission || {});
326
+
327
+ // types/errors.ts
328
+ import { AppErrorCodes } from "@worldcoin/idkit-core";
329
+ import { AppErrorCodes as AppErrorCodes2 } from "@worldcoin/idkit-core";
330
+ var VerificationErrorMessage = {
331
+ [AppErrorCodes.VerificationRejected]: "You\u2019ve cancelled the request in World App.",
332
+ [AppErrorCodes.MaxVerificationsReached]: "You have already verified the maximum number of times for this action.",
333
+ [AppErrorCodes.CredentialUnavailable]: "It seems you do not have the verification level required by this app.",
334
+ [AppErrorCodes.MalformedRequest]: "There was a problem with this request. Please try again or contact the app owner.",
335
+ [AppErrorCodes.InvalidNetwork]: "Invalid network. If you are the app owner, visit docs.worldcoin.org/test for details.",
336
+ [AppErrorCodes.InclusionProofFailed]: "There was an issue fetching your credential. Please try again.",
337
+ [AppErrorCodes.InclusionProofPending]: "Your identity is still being registered. Please wait a few minutes and try again.",
338
+ [AppErrorCodes.UnexpectedResponse]: "Unexpected response from your wallet. Please try again.",
339
+ [AppErrorCodes.FailedByHostApp]: "Verification failed by the app. Please contact the app owner for details.",
340
+ [AppErrorCodes.GenericError]: "Something unexpected went wrong. Please try again.",
341
+ [AppErrorCodes.ConnectionFailed]: "Connection to your wallet failed. Please try again."
342
+ };
343
+ var PaymentErrorCodes = /* @__PURE__ */ ((PaymentErrorCodes2) => {
344
+ PaymentErrorCodes2["InputError"] = "input_error";
345
+ PaymentErrorCodes2["PaymentRejected"] = "payment_rejected";
346
+ PaymentErrorCodes2["InvalidReceiver"] = "invalid_receiver";
347
+ PaymentErrorCodes2["InsufficientBalance"] = "insufficient_balance";
348
+ PaymentErrorCodes2["TransactionFailed"] = "transaction_failed";
349
+ PaymentErrorCodes2["GenericError"] = "generic_error";
350
+ PaymentErrorCodes2["UserBlocked"] = "user_blocked";
351
+ return PaymentErrorCodes2;
352
+ })(PaymentErrorCodes || {});
353
+ var PaymentErrorMessage = {
354
+ ["input_error" /* InputError */]: "There was a problem with this request. Please try again or contact the app owner.",
355
+ ["payment_rejected" /* PaymentRejected */]: "You\u2019ve cancelled the payment in World App.",
356
+ ["invalid_receiver" /* InvalidReceiver */]: "The receiver address is invalid. Please contact the app owner.",
357
+ ["insufficient_balance" /* InsufficientBalance */]: "You do not have enough balance to complete this transaction.",
358
+ ["transaction_failed" /* TransactionFailed */]: "The transaction failed. Please try again.",
359
+ ["generic_error" /* GenericError */]: "Something unexpected went wrong. Please try again.",
360
+ ["user_blocked" /* UserBlocked */]: "User's region is blocked from making payments."
361
+ };
362
+ var PaymentValidationErrors = /* @__PURE__ */ ((PaymentValidationErrors2) => {
363
+ PaymentValidationErrors2["MalformedRequest"] = "There was a problem with this request. Please try again or contact the app owner.";
364
+ PaymentValidationErrors2["InvalidTokenAddress"] = "The token address is invalid. Please contact the app owner.";
365
+ PaymentValidationErrors2["InvalidAppId"] = "The app ID is invalid. Please contact the app owner.";
366
+ PaymentValidationErrors2["DuplicateReference"] = "This reference ID already exists please generate a new one and try again.";
367
+ return PaymentValidationErrors2;
368
+ })(PaymentValidationErrors || {});
369
+ var WalletAuthErrorCodes = /* @__PURE__ */ ((WalletAuthErrorCodes2) => {
370
+ WalletAuthErrorCodes2["MalformedRequest"] = "malformed_request";
371
+ WalletAuthErrorCodes2["UserRejected"] = "user_rejected";
372
+ WalletAuthErrorCodes2["GenericError"] = "generic_error";
373
+ return WalletAuthErrorCodes2;
374
+ })(WalletAuthErrorCodes || {});
375
+ var WalletAuthErrorMessage = {
376
+ ["malformed_request" /* MalformedRequest */]: "Provided parameters in the request are invalid.",
377
+ ["user_rejected" /* UserRejected */]: "User rejected the request.",
378
+ ["generic_error" /* GenericError */]: "Something unexpected went wrong."
379
+ };
380
+ var SendTransactionErrorCodes = /* @__PURE__ */ ((SendTransactionErrorCodes2) => {
381
+ SendTransactionErrorCodes2["InvalidOperation"] = "invalid_operation";
382
+ SendTransactionErrorCodes2["UserRejected"] = "user_rejected";
383
+ SendTransactionErrorCodes2["InputError"] = "input_error";
384
+ SendTransactionErrorCodes2["SimulationFailed"] = "simulation_failed";
385
+ SendTransactionErrorCodes2["TransactionFailed"] = "transaction_failed";
386
+ SendTransactionErrorCodes2["GenericError"] = "generic_error";
387
+ SendTransactionErrorCodes2["DisallowedOperation"] = "disallowed_operation";
388
+ SendTransactionErrorCodes2["InvalidContract"] = "invalid_contract";
389
+ SendTransactionErrorCodes2["MaliciousOperation"] = "malicious_operation";
390
+ return SendTransactionErrorCodes2;
391
+ })(SendTransactionErrorCodes || {});
392
+ var SendTransactionErrorMessage = {
393
+ ["invalid_operation" /* InvalidOperation */]: "Transaction included an operation that was invalid",
394
+ ["user_rejected" /* UserRejected */]: "User rejected the request.",
395
+ ["input_error" /* InputError */]: "Invalid payload.",
396
+ ["simulation_failed" /* SimulationFailed */]: "The transaction simulation failed.",
397
+ ["transaction_failed" /* TransactionFailed */]: "The transaction failed. Please try again later.",
398
+ ["generic_error" /* GenericError */]: "Something unexpected went wrong. Please try again.",
399
+ ["disallowed_operation" /* DisallowedOperation */]: "The operation requested is not allowed. Please refer to the docs.",
400
+ ["invalid_contract" /* InvalidContract */]: "The contract address is not allowed for your application. Please check your developer portal configurations",
401
+ ["malicious_operation" /* MaliciousOperation */]: "The operation requested is considered malicious."
402
+ };
403
+ var SignMessageErrorCodes = /* @__PURE__ */ ((SignMessageErrorCodes2) => {
404
+ SignMessageErrorCodes2["InvalidMessage"] = "invalid_message";
405
+ SignMessageErrorCodes2["UserRejected"] = "user_rejected";
406
+ SignMessageErrorCodes2["GenericError"] = "generic_error";
407
+ return SignMessageErrorCodes2;
408
+ })(SignMessageErrorCodes || {});
409
+ var SignMessageErrorMessage = {
410
+ ["invalid_message" /* InvalidMessage */]: "Invalid message requested",
411
+ ["user_rejected" /* UserRejected */]: "User rejected the request.",
412
+ ["generic_error" /* GenericError */]: "Something unexpected went wrong."
413
+ };
414
+ var SignTypedDataErrorCodes = /* @__PURE__ */ ((SignTypedDataErrorCodes2) => {
415
+ SignTypedDataErrorCodes2["InvalidOperation"] = "invalid_operation";
416
+ SignTypedDataErrorCodes2["UserRejected"] = "user_rejected";
417
+ SignTypedDataErrorCodes2["InputError"] = "input_error";
418
+ SignTypedDataErrorCodes2["SimulationFailed"] = "simulation_failed";
419
+ SignTypedDataErrorCodes2["GenericError"] = "generic_error";
420
+ SignTypedDataErrorCodes2["DisallowedOperation"] = "disallowed_operation";
421
+ SignTypedDataErrorCodes2["InvalidContract"] = "invalid_contract";
422
+ SignTypedDataErrorCodes2["MaliciousOperation"] = "malicious_operation";
423
+ return SignTypedDataErrorCodes2;
424
+ })(SignTypedDataErrorCodes || {});
425
+ var SignTypedDataErrorMessage = SendTransactionErrorMessage;
426
+ var MiniKitInstallErrorCodes = /* @__PURE__ */ ((MiniKitInstallErrorCodes2) => {
427
+ MiniKitInstallErrorCodes2["Unknown"] = "unknown";
428
+ MiniKitInstallErrorCodes2["AlreadyInstalled"] = "already_installed";
429
+ MiniKitInstallErrorCodes2["OutsideOfWorldApp"] = "outside_of_worldapp";
430
+ MiniKitInstallErrorCodes2["NotOnClient"] = "not_on_client";
431
+ MiniKitInstallErrorCodes2["AppOutOfDate"] = "app_out_of_date";
432
+ return MiniKitInstallErrorCodes2;
433
+ })(MiniKitInstallErrorCodes || {});
434
+ var MiniKitInstallErrorMessage = {
435
+ ["unknown" /* Unknown */]: "Failed to install MiniKit.",
436
+ ["already_installed" /* AlreadyInstalled */]: "MiniKit is already installed.",
437
+ ["outside_of_worldapp" /* OutsideOfWorldApp */]: "MiniApp launched outside of WorldApp.",
438
+ ["not_on_client" /* NotOnClient */]: "Window object is not available.",
439
+ ["app_out_of_date" /* AppOutOfDate */]: "WorldApp is out of date. Please update the app."
440
+ };
441
+ var ShareContactsErrorCodes = /* @__PURE__ */ ((ShareContactsErrorCodes2) => {
442
+ ShareContactsErrorCodes2["UserRejected"] = "user_rejected";
443
+ ShareContactsErrorCodes2["GenericError"] = "generic_error";
444
+ return ShareContactsErrorCodes2;
445
+ })(ShareContactsErrorCodes || {});
446
+ var ShareContactsErrorMessage = {
447
+ ["user_rejected" /* UserRejected */]: "User rejected the request.",
448
+ ["generic_error" /* GenericError */]: "Something unexpected went wrong."
449
+ };
450
+ var RequestPermissionErrorCodes = /* @__PURE__ */ ((RequestPermissionErrorCodes2) => {
451
+ RequestPermissionErrorCodes2["UserRejected"] = "user_rejected";
452
+ RequestPermissionErrorCodes2["GenericError"] = "generic_error";
453
+ RequestPermissionErrorCodes2["AlreadyRequested"] = "already_requested";
454
+ RequestPermissionErrorCodes2["PermissionDisabled"] = "permission_disabled";
455
+ RequestPermissionErrorCodes2["AlreadyGranted"] = "already_granted";
456
+ RequestPermissionErrorCodes2["UnsupportedPermission"] = "unsupported_permission";
457
+ return RequestPermissionErrorCodes2;
458
+ })(RequestPermissionErrorCodes || {});
459
+ var RequestPermissionErrorMessage = {
460
+ ["user_rejected" /* UserRejected */]: "User declined sharing contacts",
461
+ ["generic_error" /* GenericError */]: "Request failed for unknown reason.",
462
+ ["already_requested" /* AlreadyRequested */]: "User has already declined turning on notifications once",
463
+ ["permission_disabled" /* PermissionDisabled */]: "User does not have this permission enabled in World App",
464
+ ["already_granted" /* AlreadyGranted */]: "If the user has already granted this mini app permission",
465
+ ["unsupported_permission" /* UnsupportedPermission */]: "The permission requested is not supported by this mini app"
466
+ };
467
+
468
+ // helpers/send-webview-event.ts
469
+ var sendWebviewEvent = (payload) => {
470
+ if (window.webkit) {
471
+ window.webkit?.messageHandlers?.minikit?.postMessage?.(payload);
472
+ } else if (window.Android) {
473
+ window.Android.postMessage?.(JSON.stringify(payload));
474
+ }
475
+ };
476
+
477
+ // types/responses.ts
478
+ var ResponseEvent = /* @__PURE__ */ ((ResponseEvent2) => {
479
+ ResponseEvent2["MiniAppVerifyAction"] = "miniapp-verify-action";
480
+ ResponseEvent2["MiniAppPayment"] = "miniapp-payment";
481
+ ResponseEvent2["MiniAppWalletAuth"] = "miniapp-wallet-auth";
482
+ ResponseEvent2["MiniAppSendTransaction"] = "miniapp-send-transaction";
483
+ ResponseEvent2["MiniAppSignMessage"] = "miniapp-sign-message";
484
+ ResponseEvent2["MiniAppSignTypedData"] = "miniapp-sign-typed-data";
485
+ ResponseEvent2["MiniAppShareContacts"] = "miniapp-share-contacts";
486
+ ResponseEvent2["MiniAppRequestPermission"] = "miniapp-request-permission";
487
+ return ResponseEvent2;
488
+ })(ResponseEvent || {});
489
+
424
490
  // minikit.ts
425
491
  var sendMiniKitEvent = (payload) => {
426
492
  sendWebviewEvent(payload);
@@ -438,12 +504,8 @@ var _MiniKit = class _MiniKit {
438
504
  const wrappedHandler = (payload) => {
439
505
  if (payload.status === "success") {
440
506
  _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
- };
507
+ _MiniKit.getUserByAddress(payload.address).then((user) => {
508
+ _MiniKit.user = user;
447
509
  });
448
510
  }
449
511
  originalHandler(payload);
@@ -552,7 +614,8 @@ _MiniKit.commandVersion = {
552
614
  ["send-transaction" /* SendTransaction */]: 1,
553
615
  ["sign-message" /* SignMessage */]: 1,
554
616
  ["sign-typed-data" /* SignTypedData */]: 1,
555
- ["share-contacts" /* ShareContacts */]: 1
617
+ ["share-contacts" /* ShareContacts */]: 1,
618
+ ["request-permission" /* RequestPermission */]: 1
556
619
  };
557
620
  _MiniKit.isCommandAvailable = {
558
621
  ["verify" /* Verify */]: false,
@@ -561,7 +624,8 @@ _MiniKit.isCommandAvailable = {
561
624
  ["send-transaction" /* SendTransaction */]: false,
562
625
  ["sign-message" /* SignMessage */]: false,
563
626
  ["sign-typed-data" /* SignTypedData */]: false,
564
- ["share-contacts" /* ShareContacts */]: false
627
+ ["share-contacts" /* ShareContacts */]: false,
628
+ ["request-permission" /* RequestPermission */]: false
565
629
  };
566
630
  _MiniKit.listeners = {
567
631
  ["miniapp-verify-action" /* MiniAppVerifyAction */]: () => {
@@ -577,6 +641,8 @@ _MiniKit.listeners = {
577
641
  ["miniapp-sign-typed-data" /* MiniAppSignTypedData */]: () => {
578
642
  },
579
643
  ["miniapp-share-contacts" /* MiniAppShareContacts */]: () => {
644
+ },
645
+ ["miniapp-request-permission" /* MiniAppRequestPermission */]: () => {
580
646
  }
581
647
  };
582
648
  _MiniKit.appId = null;
@@ -585,6 +651,14 @@ _MiniKit.appId = null;
585
651
  */
586
652
  _MiniKit.walletAddress = null;
587
653
  _MiniKit.user = null;
654
+ _MiniKit.getUserByAddress = async (address) => {
655
+ const userProfile = await getUserProfile(address);
656
+ return {
657
+ walletAddress: address,
658
+ username: userProfile.username,
659
+ profilePictureUrl: userProfile.profilePictureUrl
660
+ };
661
+ };
588
662
  _MiniKit.commands = {
589
663
  verify: (payload) => {
590
664
  if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["verify" /* Verify */]) {
@@ -658,7 +732,7 @@ _MiniKit.commands = {
658
732
  statement: payload.statement ?? void 0,
659
733
  uri: window.location.href,
660
734
  version: 1,
661
- chain_id: 10,
735
+ chain_id: 480,
662
736
  nonce: payload.nonce,
663
737
  issued_at: (/* @__PURE__ */ new Date()).toISOString(),
664
738
  expiration_time: payload.expirationTime?.toISOString() ?? void 0,
@@ -680,6 +754,12 @@ _MiniKit.commands = {
680
754
  );
681
755
  return null;
682
756
  }
757
+ if (!validateSendTransactionPayload(payload).isValid) {
758
+ console.error(
759
+ "Invalid sendTransaction payload - some object properties are not strings"
760
+ );
761
+ return null;
762
+ }
683
763
  sendMiniKitEvent({
684
764
  command: "send-transaction" /* SendTransaction */,
685
765
  version: 1,
@@ -728,6 +808,20 @@ _MiniKit.commands = {
728
808
  payload
729
809
  });
730
810
  return payload;
811
+ },
812
+ requestPermission: (payload) => {
813
+ if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["request-permission" /* RequestPermission */]) {
814
+ console.error(
815
+ "'requestPermission' command is unavailable. Check MiniKit.install() or update the app version"
816
+ );
817
+ return null;
818
+ }
819
+ sendMiniKitEvent({
820
+ command: "request-permission" /* RequestPermission */,
821
+ version: 1,
822
+ payload
823
+ });
824
+ return payload;
731
825
  }
732
826
  };
733
827
  /**
@@ -838,6 +932,20 @@ _MiniKit.commandsAsync = {
838
932
  reject(error);
839
933
  }
840
934
  });
935
+ },
936
+ requestPermission: async (payload) => {
937
+ return new Promise(async (resolve, reject) => {
938
+ try {
939
+ const response = await _MiniKit.awaitCommand(
940
+ "miniapp-request-permission" /* MiniAppRequestPermission */,
941
+ "request-permission" /* RequestPermission */,
942
+ () => _MiniKit.commands.requestPermission(payload)
943
+ );
944
+ resolve(response);
945
+ } catch (error) {
946
+ reject(error);
947
+ }
948
+ });
841
949
  }
842
950
  };
843
951
  var MiniKit = _MiniKit;
@@ -850,7 +958,7 @@ import {
850
958
 
851
959
  // helpers/address-book/index.ts
852
960
  import { createPublicClient as createPublicClient2, http as http2 } from "viem";
853
- import { worldchain } from "viem/chains";
961
+ import { worldchain as worldchain2 } from "viem/chains";
854
962
  var worldIdAddressBookContractAddress = "0x57b930D551e677CC36e2fA036Ae2fe8FdaE0330D";
855
963
  var addressVerifiedUntilAbi = [
856
964
  {
@@ -875,7 +983,7 @@ var addressVerifiedUntilAbi = [
875
983
  ];
876
984
  var getIsUserVerified = async (walletAddress, rpcUrl) => {
877
985
  const publicClient = createPublicClient2({
878
- chain: worldchain,
986
+ chain: worldchain2,
879
987
  transport: http2(
880
988
  rpcUrl || "https://worldchain-mainnet.g.alchemy.com/public"
881
989
  )
@@ -908,6 +1016,9 @@ export {
908
1016
  PaymentErrorCodes,
909
1017
  PaymentErrorMessage,
910
1018
  PaymentValidationErrors,
1019
+ Permission,
1020
+ RequestPermissionErrorCodes,
1021
+ RequestPermissionErrorMessage,
911
1022
  ResponseEvent,
912
1023
  SAFE_CONTRACT_ABI,
913
1024
  SendTransactionErrorCodes,