@worldcoin/minikit-js 0.0.27-internal-alpha → 0.0.29-internal-alpha

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/build/index.cjs CHANGED
@@ -22,7 +22,7 @@ var src_exports = {};
22
22
  __export(src_exports, {
23
23
  Command: () => Command,
24
24
  MiniKit: () => MiniKit,
25
- MiniKitInstallErrorCode: () => MiniKitInstallErrorCode,
25
+ MiniKitInstallErrorCodes: () => MiniKitInstallErrorCodes,
26
26
  MiniKitInstallErrorMessage: () => MiniKitInstallErrorMessage,
27
27
  Network: () => Network,
28
28
  PaymentErrorCodes: () => PaymentErrorCodes,
@@ -30,6 +30,12 @@ __export(src_exports, {
30
30
  PaymentValidationErrors: () => PaymentValidationErrors,
31
31
  ResponseEvent: () => ResponseEvent,
32
32
  SAFE_CONTRACT_ABI: () => SAFE_CONTRACT_ABI,
33
+ SendTransactionErrorCodes: () => SendTransactionErrorCodes,
34
+ SendTransactionErrorMessage: () => SendTransactionErrorMessage,
35
+ SignMessageErrorCodes: () => SignMessageErrorCodes,
36
+ SignMessageErrorMessage: () => SignMessageErrorMessage,
37
+ SignTypedDataErrorCodes: () => SignTypedDataErrorCodes,
38
+ SignTypedDataErrorMessage: () => SignTypedDataErrorMessage,
33
39
  TokenDecimals: () => TokenDecimals,
34
40
  Tokens: () => Tokens,
35
41
  VerificationErrorCodes: () => import_idkit_core2.AppErrorCodes,
@@ -44,8 +50,197 @@ __export(src_exports, {
44
50
  });
45
51
  module.exports = __toCommonJS(src_exports);
46
52
 
53
+ // types/errors.ts
54
+ var import_idkit_core = require("@worldcoin/idkit-core");
55
+ var import_idkit_core2 = require("@worldcoin/idkit-core");
56
+ var VerificationErrorMessage = {
57
+ [import_idkit_core.AppErrorCodes.VerificationRejected]: "You\u2019ve cancelled the request in World App.",
58
+ [import_idkit_core.AppErrorCodes.MaxVerificationsReached]: "You have already verified the maximum number of times for this action.",
59
+ [import_idkit_core.AppErrorCodes.CredentialUnavailable]: "It seems you do not have the verification level required by this app.",
60
+ [import_idkit_core.AppErrorCodes.MalformedRequest]: "There was a problem with this request. Please try again or contact the app owner.",
61
+ [import_idkit_core.AppErrorCodes.InvalidNetwork]: "Invalid network. If you are the app owner, visit docs.worldcoin.org/test for details.",
62
+ [import_idkit_core.AppErrorCodes.InclusionProofFailed]: "There was an issue fetching your credential. Please try again.",
63
+ [import_idkit_core.AppErrorCodes.InclusionProofPending]: "Your identity is still being registered. Please wait a few minutes and try again.",
64
+ [import_idkit_core.AppErrorCodes.UnexpectedResponse]: "Unexpected response from your wallet. Please try again.",
65
+ [import_idkit_core.AppErrorCodes.FailedByHostApp]: "Verification failed by the app. Please contact the app owner for details.",
66
+ [import_idkit_core.AppErrorCodes.GenericError]: "Something unexpected went wrong. Please try again.",
67
+ [import_idkit_core.AppErrorCodes.ConnectionFailed]: "Connection to your wallet failed. Please try again."
68
+ };
69
+ var PaymentErrorCodes = /* @__PURE__ */ ((PaymentErrorCodes2) => {
70
+ PaymentErrorCodes2["InputError"] = "input_error";
71
+ PaymentErrorCodes2["PaymentRejected"] = "payment_rejected";
72
+ PaymentErrorCodes2["InvalidReceiver"] = "invalid_receiver";
73
+ PaymentErrorCodes2["InsufficientBalance"] = "insufficient_balance";
74
+ PaymentErrorCodes2["TransactionFailed"] = "transaction_failed";
75
+ PaymentErrorCodes2["GenericError"] = "generic_error";
76
+ PaymentErrorCodes2["UserBlocked"] = "user_blocked";
77
+ return PaymentErrorCodes2;
78
+ })(PaymentErrorCodes || {});
79
+ var PaymentErrorMessage = {
80
+ ["input_error" /* InputError */]: "There was a problem with this request. Please try again or contact the app owner.",
81
+ ["payment_rejected" /* PaymentRejected */]: "You\u2019ve cancelled the payment in World App.",
82
+ ["invalid_receiver" /* InvalidReceiver */]: "The receiver address is invalid. Please contact the app owner.",
83
+ ["insufficient_balance" /* InsufficientBalance */]: "You do not have enough balance to complete this transaction.",
84
+ ["transaction_failed" /* TransactionFailed */]: "The transaction failed. Please try again.",
85
+ ["generic_error" /* GenericError */]: "Something unexpected went wrong. Please try again.",
86
+ ["user_blocked" /* UserBlocked */]: "User's region is blocked from making payments."
87
+ };
88
+ var PaymentValidationErrors = /* @__PURE__ */ ((PaymentValidationErrors2) => {
89
+ PaymentValidationErrors2["MalformedRequest"] = "There was a problem with this request. Please try again or contact the app owner.";
90
+ PaymentValidationErrors2["InvalidTokenAddress"] = "The token address is invalid. Please contact the app owner.";
91
+ PaymentValidationErrors2["InvalidAppId"] = "The app ID is invalid. Please contact the app owner.";
92
+ PaymentValidationErrors2["DuplicateReference"] = "This reference ID already exists please generate a new one and try again.";
93
+ return PaymentValidationErrors2;
94
+ })(PaymentValidationErrors || {});
95
+ var WalletAuthErrorCodes = /* @__PURE__ */ ((WalletAuthErrorCodes2) => {
96
+ WalletAuthErrorCodes2["MalformedRequest"] = "malformed_request";
97
+ WalletAuthErrorCodes2["UserRejected"] = "user_rejected";
98
+ WalletAuthErrorCodes2["GenericError"] = "generic_error";
99
+ return WalletAuthErrorCodes2;
100
+ })(WalletAuthErrorCodes || {});
101
+ var WalletAuthErrorMessage = {
102
+ ["malformed_request" /* MalformedRequest */]: "Provided parameters in the request are invalid.",
103
+ ["user_rejected" /* UserRejected */]: "User rejected the request.",
104
+ ["generic_error" /* GenericError */]: "Something unexpected went wrong."
105
+ };
106
+ var SendTransactionErrorCodes = /* @__PURE__ */ ((SendTransactionErrorCodes2) => {
107
+ SendTransactionErrorCodes2["InvalidOperation"] = "invalid_operation";
108
+ SendTransactionErrorCodes2["UserRejected"] = "user_rejected";
109
+ SendTransactionErrorCodes2["InputError"] = "input_error";
110
+ SendTransactionErrorCodes2["SimulationFailed"] = "simulation_failed";
111
+ SendTransactionErrorCodes2["TransactionFailed"] = "transaction_failed";
112
+ SendTransactionErrorCodes2["GenericError"] = "generic_error";
113
+ SendTransactionErrorCodes2["DisallowedOperation"] = "disallowed_operation";
114
+ SendTransactionErrorCodes2["InvalidContract"] = "invalid_contract";
115
+ SendTransactionErrorCodes2["MaliciousOperation"] = "malicious_operation";
116
+ return SendTransactionErrorCodes2;
117
+ })(SendTransactionErrorCodes || {});
118
+ var SendTransactionErrorMessage = {
119
+ ["invalid_operation" /* InvalidOperation */]: "Transaction included an operation that was invalid",
120
+ ["user_rejected" /* UserRejected */]: "User rejected the request.",
121
+ ["input_error" /* InputError */]: "Invalid payload.",
122
+ ["simulation_failed" /* SimulationFailed */]: "The transaction simulation failed.",
123
+ ["transaction_failed" /* TransactionFailed */]: "The transaction failed. Please try again later.",
124
+ ["generic_error" /* GenericError */]: "Something unexpected went wrong. Please try again.",
125
+ ["disallowed_operation" /* DisallowedOperation */]: "The operation requested is not allowed. Please refer to the docs.",
126
+ ["invalid_contract" /* InvalidContract */]: "The contract address is not allowed for your application. Please check your developer portal configurations",
127
+ ["malicious_operation" /* MaliciousOperation */]: "The operation requested is considered malicious."
128
+ };
129
+ var SignMessageErrorCodes = /* @__PURE__ */ ((SignMessageErrorCodes2) => {
130
+ SignMessageErrorCodes2["InvalidMessage"] = "invalid_message";
131
+ SignMessageErrorCodes2["UserRejected"] = "user_rejected";
132
+ SignMessageErrorCodes2["GenericError"] = "generic_error";
133
+ return SignMessageErrorCodes2;
134
+ })(SignMessageErrorCodes || {});
135
+ var SignMessageErrorMessage = {
136
+ ["invalid_message" /* InvalidMessage */]: "Invalid message requested",
137
+ ["user_rejected" /* UserRejected */]: "User rejected the request.",
138
+ ["generic_error" /* GenericError */]: "Something unexpected went wrong."
139
+ };
140
+ var SignTypedDataErrorCodes = /* @__PURE__ */ ((SignTypedDataErrorCodes2) => {
141
+ SignTypedDataErrorCodes2["InvalidOperation"] = "invalid_operation";
142
+ SignTypedDataErrorCodes2["UserRejected"] = "user_rejected";
143
+ SignTypedDataErrorCodes2["InputError"] = "input_error";
144
+ SignTypedDataErrorCodes2["SimulationFailed"] = "simulation_failed";
145
+ SignTypedDataErrorCodes2["GenericError"] = "generic_error";
146
+ SignTypedDataErrorCodes2["DisallowedOperation"] = "disallowed_operation";
147
+ SignTypedDataErrorCodes2["InvalidContract"] = "invalid_contract";
148
+ SignTypedDataErrorCodes2["MaliciousOperation"] = "malicious_operation";
149
+ return SignTypedDataErrorCodes2;
150
+ })(SignTypedDataErrorCodes || {});
151
+ var SignTypedDataErrorMessage = SendTransactionErrorMessage;
152
+ var MiniKitInstallErrorCodes = /* @__PURE__ */ ((MiniKitInstallErrorCodes2) => {
153
+ MiniKitInstallErrorCodes2["Unknown"] = "unknown";
154
+ MiniKitInstallErrorCodes2["AlreadyInstalled"] = "already_installed";
155
+ MiniKitInstallErrorCodes2["OutsideOfWorldApp"] = "outside_of_worldapp";
156
+ MiniKitInstallErrorCodes2["NotOnClient"] = "not_on_client";
157
+ MiniKitInstallErrorCodes2["AppOutOfDate"] = "app_out_of_date";
158
+ return MiniKitInstallErrorCodes2;
159
+ })(MiniKitInstallErrorCodes || {});
160
+ var MiniKitInstallErrorMessage = {
161
+ ["unknown" /* Unknown */]: "Failed to install MiniKit.",
162
+ ["already_installed" /* AlreadyInstalled */]: "MiniKit is already installed.",
163
+ ["outside_of_worldapp" /* OutsideOfWorldApp */]: "MiniApp launched outside of WorldApp.",
164
+ ["not_on_client" /* NotOnClient */]: "Window object is not available.",
165
+ ["app_out_of_date" /* AppOutOfDate */]: "WorldApp is out of date. Please update the app."
166
+ };
167
+
168
+ // helpers/send-webview-event.ts
169
+ var sendWebviewEvent = (payload) => {
170
+ if (window.webkit) {
171
+ window.webkit?.messageHandlers?.minikit?.postMessage?.(payload);
172
+ } else if (window.Android) {
173
+ window.Android.postMessage?.(JSON.stringify(payload));
174
+ }
175
+ };
176
+
177
+ // types/commands.ts
178
+ var Command = /* @__PURE__ */ ((Command2) => {
179
+ Command2["Verify"] = "verify";
180
+ Command2["Pay"] = "pay";
181
+ Command2["WalletAuth"] = "wallet-auth";
182
+ Command2["SendTransaction"] = "send-transaction";
183
+ Command2["SignMessage"] = "sign-message";
184
+ Command2["SignTypedData"] = "sign-typed-data";
185
+ return Command2;
186
+ })(Command || {});
187
+
188
+ // types/responses.ts
189
+ var ResponseEvent = /* @__PURE__ */ ((ResponseEvent2) => {
190
+ ResponseEvent2["MiniAppVerifyAction"] = "miniapp-verify-action";
191
+ ResponseEvent2["MiniAppPayment"] = "miniapp-payment";
192
+ ResponseEvent2["MiniAppWalletAuth"] = "miniapp-wallet-auth";
193
+ ResponseEvent2["MiniAppSendTransaction"] = "miniapp-send-transaction";
194
+ ResponseEvent2["MiniAppSignMessage"] = "miniapp-sign-message";
195
+ ResponseEvent2["MiniAppSignTypedData"] = "miniapp-sign-typed-data";
196
+ return ResponseEvent2;
197
+ })(ResponseEvent || {});
198
+
199
+ // types/payment.ts
200
+ var Tokens = /* @__PURE__ */ ((Tokens2) => {
201
+ Tokens2["USDCE"] = "USDCE";
202
+ Tokens2["WLD"] = "WLD";
203
+ return Tokens2;
204
+ })(Tokens || {});
205
+ var TokenDecimals = {
206
+ ["USDCE" /* USDCE */]: 6,
207
+ ["WLD" /* WLD */]: 18
208
+ };
209
+ var Network = /* @__PURE__ */ ((Network2) => {
210
+ Network2["Optimism"] = "optimism";
211
+ Network2["WorldChain"] = "worldchain";
212
+ return Network2;
213
+ })(Network || {});
214
+
215
+ // minikit.ts
216
+ var import_idkit_core3 = require("@worldcoin/idkit-core");
217
+
218
+ // helpers/siwe/validate-wallet-auth-command-input.ts
219
+ var validateWalletAuthCommandInput = (params) => {
220
+ if (!params.nonce) {
221
+ return { valid: false, message: "'nonce' is required" };
222
+ }
223
+ if (params.nonce.length < 8) {
224
+ return { valid: false, message: "'nonce' must be at least 8 characters" };
225
+ }
226
+ if (params.statement && params.statement.includes("\n")) {
227
+ return { valid: false, message: "'statement' must not contain newlines" };
228
+ }
229
+ if (params.expirationTime && new Date(params.expirationTime) < /* @__PURE__ */ new Date()) {
230
+ return { valid: false, message: "'expirationTime' must be in the future" };
231
+ }
232
+ if (params.expirationTime && new Date(params.expirationTime) > new Date(Date.now() + 7 * 24 * 60 * 60 * 1e3)) {
233
+ return { valid: false, message: "'expirationTime' must be within 7 days" };
234
+ }
235
+ if (params.notBefore && new Date(params.notBefore) > new Date(Date.now() + 7 * 24 * 60 * 60 * 1e3)) {
236
+ return { valid: false, message: "'notBefore' must be within 7 days" };
237
+ }
238
+ return { valid: true };
239
+ };
240
+
47
241
  // helpers/siwe/siwe.ts
48
- var import_ethers = require("ethers");
242
+ var import_viem = require("viem");
243
+ var import_chains = require("viem/chains");
49
244
  var PREAMBLE = " wants you to sign in with your Ethereum account:";
50
245
  var URI_TAG = "URI: ";
51
246
  var VERSION_TAG = "Version: ";
@@ -198,158 +393,27 @@ var verifySiweMessage = async (payload, nonce, statement, requestId, userProvide
198
393
  `Request ID mismatch. Got: ${siweMessageData.request_id}, Expected: ${requestId}`
199
394
  );
200
395
  }
201
- let provider = userProvider || import_ethers.ethers.getDefaultProvider("https://mainnet.optimism.io");
396
+ let provider = userProvider || (0, import_viem.createPublicClient)({ chain: import_chains.optimism, transport: (0, import_viem.http)() });
202
397
  const signedMessage = `${ERC_191_PREFIX}${message.length}${message}`;
203
398
  const messageBytes = Buffer.from(signedMessage, "utf8").toString("hex");
204
- const hashedMessage = import_ethers.ethers.hashMessage(signedMessage);
205
- const contract = new import_ethers.ethers.Contract(address, SAFE_CONTRACT_ABI, provider);
399
+ const hashedMessage = (0, import_viem.hashMessage)(signedMessage);
400
+ const contract = (0, import_viem.getContract)({
401
+ address,
402
+ abi: SAFE_CONTRACT_ABI,
403
+ client: provider
404
+ });
206
405
  try {
207
- await contract.checkSignatures(
406
+ await contract.read.checkSignatures([
208
407
  hashedMessage,
209
408
  `0x${messageBytes}`,
210
409
  `0x${signature}`
211
- );
410
+ ]);
212
411
  } catch (error) {
213
412
  throw new Error("Signature verification failed");
214
413
  }
215
414
  return { isValid: true, siweMessageData };
216
415
  };
217
416
 
218
- // types/errors.ts
219
- var import_idkit_core = require("@worldcoin/idkit-core");
220
- var import_idkit_core2 = require("@worldcoin/idkit-core");
221
- var VerificationErrorMessage = {
222
- [import_idkit_core.AppErrorCodes.VerificationRejected]: "You\u2019ve cancelled the request in World App.",
223
- [import_idkit_core.AppErrorCodes.MaxVerificationsReached]: "You have already verified the maximum number of times for this action.",
224
- [import_idkit_core.AppErrorCodes.CredentialUnavailable]: "It seems you do not have the verification level required by this app.",
225
- [import_idkit_core.AppErrorCodes.MalformedRequest]: "There was a problem with this request. Please try again or contact the app owner.",
226
- [import_idkit_core.AppErrorCodes.InvalidNetwork]: "Invalid network. If you are the app owner, visit docs.worldcoin.org/test for details.",
227
- [import_idkit_core.AppErrorCodes.InclusionProofFailed]: "There was an issue fetching your credential. Please try again.",
228
- [import_idkit_core.AppErrorCodes.InclusionProofPending]: "Your identity is still being registered. Please wait a few minutes and try again.",
229
- [import_idkit_core.AppErrorCodes.UnexpectedResponse]: "Unexpected response from your wallet. Please try again.",
230
- [import_idkit_core.AppErrorCodes.FailedByHostApp]: "Verification failed by the app. Please contact the app owner for details.",
231
- [import_idkit_core.AppErrorCodes.GenericError]: "Something unexpected went wrong. Please try again.",
232
- [import_idkit_core.AppErrorCodes.ConnectionFailed]: "Connection to your wallet failed. Please try again."
233
- };
234
- var PaymentErrorCodes = /* @__PURE__ */ ((PaymentErrorCodes2) => {
235
- PaymentErrorCodes2["InputError"] = "input_error";
236
- PaymentErrorCodes2["PaymentRejected"] = "payment_rejected";
237
- PaymentErrorCodes2["InvalidReceiver"] = "invalid_receiver";
238
- PaymentErrorCodes2["InsufficientBalance"] = "insufficient_balance";
239
- PaymentErrorCodes2["TransactionFailed"] = "transaction_failed";
240
- PaymentErrorCodes2["GenericError"] = "generic_error";
241
- PaymentErrorCodes2["UserBlocked"] = "user_blocked";
242
- return PaymentErrorCodes2;
243
- })(PaymentErrorCodes || {});
244
- var PaymentErrorMessage = {
245
- ["input_error" /* InputError */]: "There was a problem with this request. Please try again or contact the app owner.",
246
- ["payment_rejected" /* PaymentRejected */]: "You\u2019ve cancelled the payment in World App.",
247
- ["invalid_receiver" /* InvalidReceiver */]: "The receiver address is invalid. Please contact the app owner.",
248
- ["insufficient_balance" /* InsufficientBalance */]: "You do not have enough balance to complete this transaction.",
249
- ["transaction_failed" /* TransactionFailed */]: "The transaction failed. Please try again.",
250
- ["generic_error" /* GenericError */]: "Something unexpected went wrong. Please try again.",
251
- ["user_blocked" /* UserBlocked */]: "User's region is blocked from making payments."
252
- };
253
- var PaymentValidationErrors = /* @__PURE__ */ ((PaymentValidationErrors2) => {
254
- PaymentValidationErrors2["MalformedRequest"] = "There was a problem with this request. Please try again or contact the app owner.";
255
- PaymentValidationErrors2["InvalidTokenAddress"] = "The token address is invalid. Please contact the app owner.";
256
- PaymentValidationErrors2["InvalidAppId"] = "The app ID is invalid. Please contact the app owner.";
257
- PaymentValidationErrors2["DuplicateReference"] = "This reference ID already exists please generate a new one and try again.";
258
- return PaymentValidationErrors2;
259
- })(PaymentValidationErrors || {});
260
- var WalletAuthErrorCodes = /* @__PURE__ */ ((WalletAuthErrorCodes2) => {
261
- WalletAuthErrorCodes2["MalformedRequest"] = "malformed_request";
262
- WalletAuthErrorCodes2["UserRejected"] = "user_rejected";
263
- WalletAuthErrorCodes2["GenericError"] = "generic_error";
264
- return WalletAuthErrorCodes2;
265
- })(WalletAuthErrorCodes || {});
266
- var WalletAuthErrorMessage = {
267
- ["malformed_request" /* MalformedRequest */]: "Provided parameters in the request are invalid.",
268
- ["user_rejected" /* UserRejected */]: "User rejected the request.",
269
- ["generic_error" /* GenericError */]: "Something unexpected went wrong."
270
- };
271
- var MiniKitInstallErrorCode = /* @__PURE__ */ ((MiniKitInstallErrorCode2) => {
272
- MiniKitInstallErrorCode2["Unknown"] = "unknown";
273
- MiniKitInstallErrorCode2["AlreadyInstalled"] = "already_installed";
274
- MiniKitInstallErrorCode2["OutsideOfWorldApp"] = "outside_of_worldapp";
275
- MiniKitInstallErrorCode2["NotOnClient"] = "not_on_client";
276
- MiniKitInstallErrorCode2["AppOutOfDate"] = "app_out_of_date";
277
- return MiniKitInstallErrorCode2;
278
- })(MiniKitInstallErrorCode || {});
279
- var MiniKitInstallErrorMessage = {
280
- ["unknown" /* Unknown */]: "Failed to install MiniKit.",
281
- ["already_installed" /* AlreadyInstalled */]: "MiniKit is already installed.",
282
- ["outside_of_worldapp" /* OutsideOfWorldApp */]: "MiniApp launched outside of WorldApp.",
283
- ["not_on_client" /* NotOnClient */]: "Window object is not available.",
284
- ["app_out_of_date" /* AppOutOfDate */]: "WorldApp is out of date. Please update the app."
285
- };
286
-
287
- // helpers/send-webview-event.ts
288
- var sendWebviewEvent = (payload) => {
289
- if (window.webkit) {
290
- window.webkit?.messageHandlers?.minikit?.postMessage?.(payload);
291
- } else if (window.Android) {
292
- window.Android.postMessage?.(JSON.stringify(payload));
293
- }
294
- };
295
-
296
- // types/commands.ts
297
- var Command = /* @__PURE__ */ ((Command2) => {
298
- Command2["Verify"] = "verify";
299
- Command2["Pay"] = "pay";
300
- Command2["WalletAuth"] = "wallet-auth";
301
- return Command2;
302
- })(Command || {});
303
-
304
- // types/responses.ts
305
- var ResponseEvent = /* @__PURE__ */ ((ResponseEvent2) => {
306
- ResponseEvent2["MiniAppVerifyAction"] = "miniapp-verify-action";
307
- ResponseEvent2["MiniAppPayment"] = "miniapp-payment";
308
- ResponseEvent2["MiniAppWalletAuth"] = "miniapp-wallet-auth";
309
- return ResponseEvent2;
310
- })(ResponseEvent || {});
311
-
312
- // types/payment.ts
313
- var Tokens = /* @__PURE__ */ ((Tokens2) => {
314
- Tokens2["USDCE"] = "USDCE";
315
- Tokens2["WLD"] = "WLD";
316
- return Tokens2;
317
- })(Tokens || {});
318
- var TokenDecimals = {
319
- ["USDCE" /* USDCE */]: 6,
320
- ["WLD" /* WLD */]: 18
321
- };
322
- var Network = /* @__PURE__ */ ((Network2) => {
323
- Network2["Optimism"] = "optimism";
324
- return Network2;
325
- })(Network || {});
326
-
327
- // minikit.ts
328
- var import_idkit_core3 = require("@worldcoin/idkit-core");
329
-
330
- // helpers/siwe/validate-wallet-auth-command-input.ts
331
- var validateWalletAuthCommandInput = (params) => {
332
- if (!params.nonce) {
333
- return { valid: false, message: "'nonce' is required" };
334
- }
335
- if (params.nonce.length < 8) {
336
- return { valid: false, message: "'nonce' must be at least 8 characters" };
337
- }
338
- if (params.statement && params.statement.includes("\n")) {
339
- return { valid: false, message: "'statement' must not contain newlines" };
340
- }
341
- if (params.expirationTime && new Date(params.expirationTime) < /* @__PURE__ */ new Date()) {
342
- return { valid: false, message: "'expirationTime' must be in the future" };
343
- }
344
- if (params.expirationTime && new Date(params.expirationTime) > new Date(Date.now() + 7 * 24 * 60 * 60 * 1e3)) {
345
- return { valid: false, message: "'expirationTime' must be within 7 days" };
346
- }
347
- if (params.notBefore && new Date(params.notBefore) > new Date(Date.now() + 7 * 24 * 60 * 60 * 1e3)) {
348
- return { valid: false, message: "'notBefore' must be within 7 days" };
349
- }
350
- return { valid: true };
351
- };
352
-
353
417
  // helpers/payment/client.ts
354
418
  var tokenToDecimals = (amount, token) => {
355
419
  const decimals = TokenDecimals[token];
@@ -389,7 +453,18 @@ var _MiniKit = class _MiniKit {
389
453
  });
390
454
  }
391
455
  static subscribe(event, handler) {
392
- this.listeners[event] = handler;
456
+ if (event === "miniapp-wallet-auth" /* MiniAppWalletAuth */) {
457
+ const originalHandler = handler;
458
+ const wrappedHandler = (payload) => {
459
+ if (payload.status === "success") {
460
+ _MiniKit.walletAddress = payload.address;
461
+ }
462
+ originalHandler(payload);
463
+ };
464
+ this.listeners[event] = wrappedHandler;
465
+ } else {
466
+ this.listeners[event] = handler;
467
+ }
393
468
  }
394
469
  static unsubscribe(event) {
395
470
  delete this.listeners[event];
@@ -445,8 +520,7 @@ var _MiniKit = class _MiniKit {
445
520
  return { success: true };
446
521
  }
447
522
  static isInstalled(debug) {
448
- if (debug)
449
- console.log("MiniKit is alive!");
523
+ if (debug) console.log("MiniKit is alive!");
450
524
  return Boolean(window.MiniKit);
451
525
  }
452
526
  };
@@ -454,7 +528,10 @@ _MiniKit.MINIKIT_VERSION = 1;
454
528
  _MiniKit.commandVersion = {
455
529
  ["verify" /* Verify */]: 1,
456
530
  ["pay" /* Pay */]: 1,
457
- ["wallet-auth" /* WalletAuth */]: 1
531
+ ["wallet-auth" /* WalletAuth */]: 1,
532
+ ["send-transaction" /* SendTransaction */]: 1,
533
+ ["sign-message" /* SignMessage */]: 1,
534
+ ["sign-typed-data" /* SignTypedData */]: 1
458
535
  };
459
536
  _MiniKit.listeners = {
460
537
  ["miniapp-verify-action" /* MiniAppVerifyAction */]: () => {
@@ -462,8 +539,15 @@ _MiniKit.listeners = {
462
539
  ["miniapp-payment" /* MiniAppPayment */]: () => {
463
540
  },
464
541
  ["miniapp-wallet-auth" /* MiniAppWalletAuth */]: () => {
542
+ },
543
+ ["miniapp-send-transaction" /* MiniAppSendTransaction */]: () => {
544
+ },
545
+ ["miniapp-sign-message" /* MiniAppSignMessage */]: () => {
546
+ },
547
+ ["miniapp-sign-typed-data" /* MiniAppSignTypedData */]: () => {
465
548
  }
466
549
  };
550
+ _MiniKit.walletAddress = null;
467
551
  _MiniKit.commands = {
468
552
  verify: (payload) => {
469
553
  const timestamp = (/* @__PURE__ */ new Date()).toISOString();
@@ -546,8 +630,29 @@ _MiniKit.commands = {
546
630
  });
547
631
  return walletAuthPayload;
548
632
  },
549
- closeWebview: () => {
550
- sendWebviewEvent({ command: "close" });
633
+ sendTransaction: (payload) => {
634
+ sendMiniKitEvent({
635
+ command: "send-transaction" /* SendTransaction */,
636
+ version: 1,
637
+ payload
638
+ });
639
+ return payload;
640
+ },
641
+ signMessage: (payload) => {
642
+ sendMiniKitEvent({
643
+ command: "sign-message" /* SignMessage */,
644
+ version: 1,
645
+ payload
646
+ });
647
+ return payload;
648
+ },
649
+ signTypedData: (payload) => {
650
+ sendMiniKitEvent({
651
+ command: "sign-typed-data" /* SignTypedData */,
652
+ version: 1,
653
+ payload
654
+ });
655
+ return payload;
551
656
  }
552
657
  };
553
658
  var MiniKit = _MiniKit;
@@ -559,7 +664,7 @@ var import_backend = require("@worldcoin/idkit-core/backend");
559
664
  0 && (module.exports = {
560
665
  Command,
561
666
  MiniKit,
562
- MiniKitInstallErrorCode,
667
+ MiniKitInstallErrorCodes,
563
668
  MiniKitInstallErrorMessage,
564
669
  Network,
565
670
  PaymentErrorCodes,
@@ -567,6 +672,12 @@ var import_backend = require("@worldcoin/idkit-core/backend");
567
672
  PaymentValidationErrors,
568
673
  ResponseEvent,
569
674
  SAFE_CONTRACT_ABI,
675
+ SendTransactionErrorCodes,
676
+ SendTransactionErrorMessage,
677
+ SignMessageErrorCodes,
678
+ SignMessageErrorMessage,
679
+ SignTypedDataErrorCodes,
680
+ SignTypedDataErrorMessage,
570
681
  TokenDecimals,
571
682
  Tokens,
572
683
  VerificationErrorCodes,