@worldcoin/minikit-js 2.0.0-dev.0 → 2.0.0-dev.1

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
@@ -1,9 +1,7 @@
1
1
  "use strict";
2
- var __create = Object.create;
3
2
  var __defProp = Object.defineProperty;
4
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
6
  var __export = (target, all) => {
9
7
  for (var name in all)
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
 
30
20
  // src/index.ts
@@ -37,9 +27,10 @@ module.exports = __toCommonJS(src_exports);
37
27
 
38
28
  // src/commands/types.ts
39
29
  var COMMAND_VERSIONS = {
30
+ ["attestation" /* Attestation */]: 1,
40
31
  ["pay" /* Pay */]: 1,
41
32
  ["wallet-auth" /* WalletAuth */]: 2,
42
- ["send-transaction" /* SendTransaction */]: 1,
33
+ ["send-transaction" /* SendTransaction */]: 2,
43
34
  ["sign-message" /* SignMessage */]: 1,
44
35
  ["sign-typed-data" /* SignTypedData */]: 1,
45
36
  ["share-contacts" /* ShareContacts */]: 1,
@@ -47,9 +38,11 @@ var COMMAND_VERSIONS = {
47
38
  ["get-permissions" /* GetPermissions */]: 1,
48
39
  ["send-haptic-feedback" /* SendHapticFeedback */]: 1,
49
40
  ["share" /* Share */]: 1,
50
- ["chat" /* Chat */]: 1
41
+ ["chat" /* Chat */]: 1,
42
+ ["close-miniapp" /* CloseMiniApp */]: 1
51
43
  };
52
44
  var commandAvailability = {
45
+ ["attestation" /* Attestation */]: false,
53
46
  ["pay" /* Pay */]: false,
54
47
  ["wallet-auth" /* WalletAuth */]: false,
55
48
  ["send-transaction" /* SendTransaction */]: false,
@@ -60,7 +53,8 @@ var commandAvailability = {
60
53
  ["get-permissions" /* GetPermissions */]: false,
61
54
  ["send-haptic-feedback" /* SendHapticFeedback */]: false,
62
55
  ["share" /* Share */]: false,
63
- ["chat" /* Chat */]: false
56
+ ["chat" /* Chat */]: false,
57
+ ["close-miniapp" /* CloseMiniApp */]: false
64
58
  };
65
59
  function isCommandAvailable(command) {
66
60
  return commandAvailability[command] ?? false;
@@ -132,6 +126,8 @@ var CommandUnavailableError = class extends Error {
132
126
  var EventManager = class {
133
127
  constructor() {
134
128
  this.listeners = {
129
+ ["miniapp-attestation" /* MiniAppAttestation */]: () => {
130
+ },
135
131
  ["miniapp-payment" /* MiniAppPayment */]: () => {
136
132
  },
137
133
  ["miniapp-wallet-auth" /* MiniAppWalletAuth */]: () => {
@@ -175,191 +171,6 @@ var EventManager = class {
175
171
  }
176
172
  };
177
173
 
178
- // src/commands/wagmi-fallback.ts
179
- var SIWE_NONCE_REGEX = /^[a-zA-Z0-9]{8,}$/;
180
- var WAGMI_KEY = "__minikit_wagmi_config__";
181
- function getWagmiConfig() {
182
- return globalThis[WAGMI_KEY];
183
- }
184
- function hasWagmiConfig() {
185
- return globalThis[WAGMI_KEY] !== void 0;
186
- }
187
- async function ensureConnected(config) {
188
- const { connect, getConnections } = await import("wagmi/actions");
189
- const isWorldApp = typeof window !== "undefined" && Boolean(window.WorldApp);
190
- const existingConnection = getConnections(config).find(
191
- (connection) => connection.accounts && connection.accounts.length > 0 && (isWorldApp || connection.connector?.id !== "worldApp")
192
- );
193
- if (existingConnection && existingConnection.accounts) {
194
- return existingConnection.accounts[0];
195
- }
196
- const connectors = config.connectors;
197
- if (!connectors || connectors.length === 0) {
198
- throw new Error("No Wagmi connectors configured");
199
- }
200
- const candidateConnectors = isWorldApp ? connectors : connectors.filter(
201
- (connector) => connector.id !== "worldApp"
202
- );
203
- if (!isWorldApp && candidateConnectors.length === 0) {
204
- throw new Error(
205
- "No web Wagmi connectors configured. Add a web connector (e.g. injected or walletConnect) after worldApp()."
206
- );
207
- }
208
- const selectedConnector = candidateConnectors[0];
209
- try {
210
- const result = await connect(config, { connector: selectedConnector });
211
- if (result.accounts.length > 0) {
212
- const account = result.accounts[0];
213
- const address = typeof account === "string" ? account : account.address;
214
- if (address) {
215
- return address;
216
- }
217
- }
218
- } catch (error) {
219
- const connectorId = selectedConnector.id ?? "unknown";
220
- const wrappedError = new Error(
221
- `Failed to connect with connector "${connectorId}". Reorder connectors to change the default connector.`
222
- );
223
- wrappedError.cause = error;
224
- throw wrappedError;
225
- }
226
- throw new Error("Failed to connect wallet");
227
- }
228
- async function wagmiWalletAuth(params) {
229
- const config = getWagmiConfig();
230
- if (!config) {
231
- throw new Error(
232
- "Wagmi config not available. Pass wagmiConfig to MiniKitProvider."
233
- );
234
- }
235
- const { signMessage: signMessage2 } = await import("wagmi/actions");
236
- const { SiweMessage } = await import("siwe");
237
- const address = await ensureConnected(config);
238
- if (!SIWE_NONCE_REGEX.test(params.nonce)) {
239
- throw new Error(
240
- "Invalid nonce: must be alphanumeric and at least 8 characters (EIP-4361)"
241
- );
242
- }
243
- const siweMessage = new SiweMessage({
244
- domain: typeof window !== "undefined" ? window.location.host : "localhost",
245
- address,
246
- statement: params.statement,
247
- uri: typeof window !== "undefined" ? window.location.origin : "http://localhost",
248
- version: "1",
249
- chainId: 480,
250
- // World Chain
251
- nonce: params.nonce,
252
- expirationTime: params.expirationTime?.toISOString()
253
- });
254
- const message = siweMessage.prepareMessage();
255
- const signature = await signMessage2(config, { message });
256
- return {
257
- address,
258
- message,
259
- signature
260
- };
261
- }
262
- async function wagmiSignMessage(params) {
263
- const config = getWagmiConfig();
264
- if (!config) {
265
- throw new Error(
266
- "Wagmi config not available. Pass wagmiConfig to MiniKitProvider."
267
- );
268
- }
269
- const { signMessage: signMessage2 } = await import("wagmi/actions");
270
- const address = await ensureConnected(config);
271
- const signature = await signMessage2(config, {
272
- account: address,
273
- message: params.message
274
- });
275
- return {
276
- status: "success",
277
- version: 1,
278
- signature,
279
- address
280
- };
281
- }
282
- async function wagmiSignTypedData(params) {
283
- const config = getWagmiConfig();
284
- if (!config) {
285
- throw new Error(
286
- "Wagmi config not available. Pass wagmiConfig to MiniKitProvider."
287
- );
288
- }
289
- const { getChainId, signTypedData: signTypedData2, switchChain } = await import("wagmi/actions");
290
- const address = await ensureConnected(config);
291
- if (params.chainId !== void 0) {
292
- const currentChainId = await getChainId(config);
293
- if (currentChainId !== params.chainId) {
294
- await switchChain(config, { chainId: params.chainId });
295
- }
296
- }
297
- const signature = await signTypedData2(config, {
298
- account: address,
299
- types: params.types,
300
- primaryType: params.primaryType,
301
- domain: params.domain,
302
- message: params.message
303
- });
304
- return {
305
- status: "success",
306
- version: 1,
307
- signature,
308
- address
309
- };
310
- }
311
- function isChainMismatchError(error) {
312
- const message = error instanceof Error ? error.message : String(error);
313
- return message.includes("does not match the target chain");
314
- }
315
- async function wagmiSendTransaction(params) {
316
- const config = getWagmiConfig();
317
- if (!config) {
318
- throw new Error(
319
- "Wagmi config not available. Pass wagmiConfig to MiniKitProvider."
320
- );
321
- }
322
- const { getChainId, getWalletClient, sendTransaction: sendTransaction2, switchChain } = await import("wagmi/actions");
323
- await ensureConnected(config);
324
- const targetChainId = params.chainId ?? config.chains?.[0]?.id;
325
- const ensureTargetChain = async () => {
326
- if (targetChainId === void 0) return;
327
- const currentChainId = await getChainId(config);
328
- if (currentChainId !== targetChainId) {
329
- await switchChain(config, { chainId: targetChainId });
330
- }
331
- const walletClient = await getWalletClient(config);
332
- const providerChainId = walletClient ? await walletClient.getChainId() : await getChainId(config);
333
- if (providerChainId !== targetChainId) {
334
- throw new Error(
335
- `Wallet network mismatch: expected chain ${targetChainId}, got ${providerChainId}. Please switch networks in your wallet and retry.`
336
- );
337
- }
338
- };
339
- await ensureTargetChain();
340
- let transactionHash;
341
- try {
342
- transactionHash = await sendTransaction2(config, {
343
- chainId: targetChainId,
344
- to: params.transaction.address,
345
- data: params.transaction.data,
346
- value: params.transaction.value ? BigInt(params.transaction.value) : void 0
347
- });
348
- } catch (error) {
349
- if (targetChainId === void 0 || !isChainMismatchError(error)) {
350
- throw error;
351
- }
352
- await ensureTargetChain();
353
- transactionHash = await sendTransaction2(config, {
354
- chainId: targetChainId,
355
- to: params.transaction.address,
356
- data: params.transaction.data,
357
- value: params.transaction.value ? BigInt(params.transaction.value) : void 0
358
- });
359
- }
360
- return { transactionHash };
361
- }
362
-
363
174
  // src/commands/fallback.ts
364
175
  async function executeWithFallback(options) {
365
176
  const {
@@ -381,7 +192,7 @@ async function executeWithFallback(options) {
381
192
  console.warn(`Native ${command} failed, attempting fallback:`, error);
382
193
  }
383
194
  }
384
- if (!inWorldApp && wagmiFallback && hasWagmiConfig()) {
195
+ if (!inWorldApp && wagmiFallback) {
385
196
  try {
386
197
  const data = await wagmiFallback();
387
198
  return { data, executedWith: "wagmi" };
@@ -389,7 +200,7 @@ async function executeWithFallback(options) {
389
200
  console.warn(`Wagmi fallback for ${command} failed:`, error);
390
201
  }
391
202
  }
392
- if (customFallback) {
203
+ if (!inWorldApp && customFallback) {
393
204
  const data = await customFallback();
394
205
  return { data, executedWith: "fallback" };
395
206
  }
@@ -411,6 +222,67 @@ function determineFallbackReason(command) {
411
222
  return "commandNotSupported";
412
223
  }
413
224
 
225
+ // src/commands/attestation/types.ts
226
+ var AttestationError = class extends Error {
227
+ constructor(error_code) {
228
+ super(`Attestation failed: ${error_code}`);
229
+ this.error_code = error_code;
230
+ this.name = "AttestationError";
231
+ }
232
+ };
233
+
234
+ // src/commands/attestation/index.ts
235
+ async function attestation(options, ctx) {
236
+ const result = await executeWithFallback({
237
+ command: "attestation" /* Attestation */,
238
+ nativeExecutor: () => nativeAttestation(options, ctx),
239
+ customFallback: options.fallback
240
+ });
241
+ if (result.executedWith === "fallback") {
242
+ return { executedWith: "fallback", data: result.data };
243
+ }
244
+ return {
245
+ executedWith: "minikit",
246
+ data: result.data
247
+ };
248
+ }
249
+ async function nativeAttestation(options, ctx) {
250
+ if (!ctx) {
251
+ ctx = { events: new EventManager(), state: { deviceProperties: {} } };
252
+ }
253
+ if (typeof window === "undefined" || !isCommandAvailable("attestation" /* Attestation */)) {
254
+ throw new Error(
255
+ "'attestation' command is unavailable. Check MiniKit.install() or update the app version"
256
+ );
257
+ }
258
+ if (!options.requestHash || options.requestHash.length === 0) {
259
+ throw new Error("'attestation' command requires a non-empty requestHash");
260
+ }
261
+ const payload = await new Promise(
262
+ (resolve, reject) => {
263
+ try {
264
+ ctx.events.subscribe("miniapp-attestation" /* MiniAppAttestation */, (response) => {
265
+ ctx.events.unsubscribe("miniapp-attestation" /* MiniAppAttestation */);
266
+ resolve(response);
267
+ });
268
+ sendMiniKitEvent({
269
+ command: "attestation" /* Attestation */,
270
+ version: COMMAND_VERSIONS["attestation" /* Attestation */],
271
+ payload: {
272
+ request_hash: options.requestHash
273
+ }
274
+ });
275
+ } catch (error) {
276
+ reject(error);
277
+ }
278
+ }
279
+ );
280
+ if (payload.status === "error") {
281
+ throw new AttestationError(payload.error_code);
282
+ }
283
+ return payload;
284
+ }
285
+
414
286
  // src/commands/chat/types.ts
415
287
  var ChatError = class extends Error {
416
288
  constructor(error_code) {
@@ -472,6 +344,38 @@ async function nativeChat(options, ctx) {
472
344
  return payload;
473
345
  }
474
346
 
347
+ // src/commands/close-miniapp/index.ts
348
+ async function closeMiniApp(options = {}, _ctx) {
349
+ const result = await executeWithFallback({
350
+ command: "close-miniapp" /* CloseMiniApp */,
351
+ nativeExecutor: () => nativeCloseMiniApp(),
352
+ customFallback: options.fallback
353
+ });
354
+ if (result.executedWith === "fallback") {
355
+ return { executedWith: "fallback", data: result.data };
356
+ }
357
+ return {
358
+ executedWith: "minikit",
359
+ data: result.data
360
+ };
361
+ }
362
+ async function nativeCloseMiniApp() {
363
+ if (typeof window === "undefined" || !isCommandAvailable("close-miniapp" /* CloseMiniApp */)) {
364
+ throw new Error(
365
+ "'closeMiniApp' command is unavailable. Check MiniKit.install() or update the app version"
366
+ );
367
+ }
368
+ sendMiniKitEvent({
369
+ command: "close-miniapp" /* CloseMiniApp */,
370
+ version: COMMAND_VERSIONS["close-miniapp" /* CloseMiniApp */],
371
+ payload: {}
372
+ });
373
+ return {
374
+ status: "success",
375
+ version: COMMAND_VERSIONS["close-miniapp" /* CloseMiniApp */]
376
+ };
377
+ }
378
+
475
379
  // src/commands/get-permissions/types.ts
476
380
  var GetPermissionsError = class extends Error {
477
381
  constructor(error_code) {
@@ -740,8 +644,11 @@ async function nativeSendHapticFeedback(options, ctx) {
740
644
  return payload;
741
645
  }
742
646
 
743
- // src/commands/send-transaction/index.ts
744
- var import_viem = require("viem");
647
+ // src/commands/fallback-adapter-registry.ts
648
+ var FALLBACK_ADAPTER_KEY = "__minikit_fallback_adapter__";
649
+ function getFallbackAdapter() {
650
+ return globalThis[FALLBACK_ADAPTER_KEY];
651
+ }
745
652
 
746
653
  // src/commands/send-transaction/types.ts
747
654
  var SendTransactionError = class extends Error {
@@ -757,16 +664,6 @@ var SendTransactionError = class extends Error {
757
664
  var isValidHex = (str) => {
758
665
  return /^0x[0-9A-Fa-f]+$/.test(str);
759
666
  };
760
- var objectValuesToArrayRecursive = (input) => {
761
- if (input === null || typeof input !== "object") {
762
- return input;
763
- }
764
- if (Array.isArray(input)) {
765
- return input.map((item) => objectValuesToArrayRecursive(item));
766
- }
767
- const values = Object.values(input);
768
- return values.map((value) => objectValuesToArrayRecursive(value));
769
- };
770
667
  var processPayload = (payload) => {
771
668
  if (typeof payload === "boolean" || typeof payload === "string" || payload === null || payload === void 0) {
772
669
  return payload;
@@ -779,6 +676,20 @@ var processPayload = (payload) => {
779
676
  }
780
677
  if (typeof payload === "object") {
781
678
  const result = { ...payload };
679
+ if ("chainId" in result && result.chainId !== void 0) {
680
+ if (typeof result.chainId === "string") {
681
+ const parsed = Number(result.chainId);
682
+ if (Number.isFinite(parsed)) {
683
+ result.chainId = parsed;
684
+ }
685
+ } else if (typeof result.chainId === "bigint") {
686
+ const parsed = Number(result.chainId);
687
+ if (!Number.isSafeInteger(parsed)) {
688
+ throw new Error(`Invalid chainId: ${String(result.chainId)}`);
689
+ }
690
+ result.chainId = parsed;
691
+ }
692
+ }
782
693
  if ("value" in result && result.value !== void 0) {
783
694
  if (typeof result.value !== "string") {
784
695
  result.value = String(result.value);
@@ -795,6 +706,7 @@ var processPayload = (payload) => {
795
706
  }
796
707
  for (const key in result) {
797
708
  if (Object.prototype.hasOwnProperty.call(result, key)) {
709
+ if (key === "chainId") continue;
798
710
  result[key] = processPayload(result[key]);
799
711
  }
800
712
  }
@@ -803,37 +715,48 @@ var processPayload = (payload) => {
803
715
  return payload;
804
716
  };
805
717
  var validateSendTransactionPayload = (payload) => {
806
- if (payload.formatPayload) {
807
- const formattedPayload = processPayload(payload);
808
- formattedPayload.transaction = formattedPayload.transaction.map((tx) => {
809
- if ("args" in tx && tx.args !== void 0) {
810
- const args = objectValuesToArrayRecursive(tx.args);
811
- return {
812
- ...tx,
813
- args
814
- };
815
- }
816
- return tx;
817
- });
818
- return formattedPayload;
819
- }
820
- return payload;
718
+ return processPayload(payload);
821
719
  };
822
720
 
823
721
  // src/commands/send-transaction/index.ts
824
722
  var WORLD_CHAIN_ID = 480;
825
723
  var WAGMI_MULTI_TX_ERROR_MESSAGE = "Wagmi fallback does not support multi-transaction execution. Pass a single transaction, run inside World App for batching, or provide a custom fallback.";
724
+ function resolveChainId(options) {
725
+ return options.chainId;
726
+ }
727
+ function resolveTransactions(options) {
728
+ if (options.transactions.length === 0) {
729
+ throw new SendTransactionError("input_error" /* InputError */, {
730
+ reason: "At least one transaction is required. Use `transactions: [{ to, data, value }]`."
731
+ });
732
+ }
733
+ return options.transactions;
734
+ }
735
+ function normalizeSendTransactionOptions(options) {
736
+ const chainId = resolveChainId(options);
737
+ if (chainId !== WORLD_CHAIN_ID) {
738
+ throw new SendTransactionError("invalid_operation" /* InvalidOperation */, {
739
+ reason: `World App only supports World Chain (chainId: ${WORLD_CHAIN_ID})`
740
+ });
741
+ }
742
+ return {
743
+ transactions: resolveTransactions(options),
744
+ chainId
745
+ };
746
+ }
826
747
  async function sendTransaction(options, ctx) {
827
- const isWagmiFallbackPath = !isInWorldApp() && hasWagmiConfig();
828
- if (isWagmiFallbackPath && options.transaction.length > 1 && !options.fallback) {
748
+ const normalizedOptions = normalizeSendTransactionOptions(options);
749
+ const fallbackAdapter = getFallbackAdapter();
750
+ const isWagmiFallbackPath = !isInWorldApp() && Boolean(fallbackAdapter?.sendTransaction);
751
+ if (isWagmiFallbackPath && normalizedOptions.transactions.length > 1 && !options.fallback) {
829
752
  throw new SendTransactionError("invalid_operation" /* InvalidOperation */, {
830
753
  reason: WAGMI_MULTI_TX_ERROR_MESSAGE
831
754
  });
832
755
  }
833
756
  const result = await executeWithFallback({
834
757
  command: "send-transaction" /* SendTransaction */,
835
- nativeExecutor: () => nativeSendTransaction(options, ctx),
836
- wagmiFallback: () => wagmiSendTransactionAdapter(options),
758
+ nativeExecutor: () => nativeSendTransaction(normalizedOptions, ctx),
759
+ wagmiFallback: fallbackAdapter?.sendTransaction ? () => adapterSendTransactionFallback(normalizedOptions) : void 0,
837
760
  customFallback: options.fallback
838
761
  });
839
762
  if (result.executedWith === "fallback") {
@@ -859,15 +782,22 @@ async function nativeSendTransaction(options, ctx) {
859
782
  "'sendTransaction' command is unavailable. Check MiniKit.install() or update the app version"
860
783
  );
861
784
  }
862
- if (options.chainId !== void 0 && options.chainId !== WORLD_CHAIN_ID) {
785
+ if (options.chainId !== WORLD_CHAIN_ID) {
863
786
  throw new Error(
864
787
  `World App only supports World Chain (chainId: ${WORLD_CHAIN_ID})`
865
788
  );
866
789
  }
790
+ const commandInput = window.WorldApp?.supported_commands.find(
791
+ (command) => command.name === "send-transaction" /* SendTransaction */
792
+ );
793
+ if (commandInput && !commandInput.supported_versions.includes(
794
+ COMMAND_VERSIONS["send-transaction" /* SendTransaction */]
795
+ )) {
796
+ throw new CommandUnavailableError("send-transaction" /* SendTransaction */, "oldAppVersion");
797
+ }
867
798
  const input = {
868
- transaction: options.transaction,
869
- permit2: options.permit2,
870
- formatPayload: options.formatPayload !== false
799
+ transactions: options.transactions,
800
+ chainId: options.chainId
871
801
  };
872
802
  const validatedPayload = validateSendTransactionPayload(input);
873
803
  const finalPayload = await new Promise(
@@ -893,71 +823,43 @@ async function nativeSendTransaction(options, ctx) {
893
823
  finalPayload.details
894
824
  );
895
825
  }
826
+ const successPayload = finalPayload;
896
827
  return {
897
- transactionHash: null,
898
- userOpHash: finalPayload.userOpHash ?? null,
899
- mini_app_id: finalPayload.mini_app_id ?? null,
828
+ userOpHash: String(successPayload.userOpHash ?? ""),
900
829
  status: finalPayload.status,
901
830
  version: finalPayload.version,
902
- transactionId: finalPayload.transaction_id,
903
- reference: finalPayload.reference,
904
- from: finalPayload.from,
905
- chain: finalPayload.chain,
906
- timestamp: finalPayload.timestamp,
907
- // Deprecated aliases
908
- transaction_id: finalPayload.transaction_id,
909
- transaction_status: "submitted"
831
+ from: String(successPayload.from ?? ""),
832
+ timestamp: String(successPayload.timestamp ?? (/* @__PURE__ */ new Date()).toISOString())
910
833
  };
911
834
  }
912
- async function wagmiSendTransactionAdapter(options) {
913
- if (options.transaction.length > 1) {
835
+ async function adapterSendTransactionFallback(options) {
836
+ if (options.transactions.length > 1) {
914
837
  throw new Error(WAGMI_MULTI_TX_ERROR_MESSAGE);
915
838
  }
916
- if (options.permit2 && options.permit2.length > 0) {
917
- console.warn(
918
- "Permit2 signature is not automatically supported via Wagmi fallback. Transactions will execute without permit2."
919
- );
920
- }
921
- const transactions = options.transaction.map((tx) => ({
922
- address: tx.address,
923
- // Encode the function call data
924
- data: encodeTransactionData(tx),
925
- value: tx.value
926
- }));
927
- const firstTransaction = transactions[0];
839
+ const firstTransaction = options.transactions[0];
928
840
  if (!firstTransaction) {
929
841
  throw new Error("At least one transaction is required");
930
842
  }
931
- const result = await wagmiSendTransaction({
932
- transaction: firstTransaction,
843
+ const fallbackAdapter = getFallbackAdapter();
844
+ if (!fallbackAdapter?.sendTransaction) {
845
+ throw new Error("Fallback adapter is not registered.");
846
+ }
847
+ const result = await fallbackAdapter.sendTransaction({
848
+ transaction: {
849
+ address: firstTransaction.to,
850
+ data: firstTransaction.data,
851
+ value: firstTransaction.value
852
+ },
933
853
  chainId: options.chainId
934
854
  });
935
855
  return {
936
- transactionHash: result.transactionHash,
937
- userOpHash: null,
938
- mini_app_id: null,
856
+ userOpHash: result.transactionHash,
939
857
  status: "success",
940
- version: 1,
941
- transactionId: null,
942
- reference: null,
943
- from: null,
944
- chain: null,
945
- timestamp: null
858
+ version: COMMAND_VERSIONS["send-transaction" /* SendTransaction */],
859
+ from: "",
860
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
946
861
  };
947
862
  }
948
- function encodeTransactionData(tx) {
949
- if (tx.data) {
950
- return tx.data;
951
- }
952
- if (!tx.abi || !tx.functionName) {
953
- throw new Error("Transaction requires `data` or `abi` + `functionName`.");
954
- }
955
- return (0, import_viem.encodeFunctionData)({
956
- abi: tx.abi,
957
- functionName: tx.functionName,
958
- args: tx.args ?? []
959
- });
960
- }
961
863
 
962
864
  // src/commands/share/format.ts
963
865
  var MAX_FILES = 10;
@@ -1176,12 +1078,13 @@ var SignMessageError = class extends Error {
1176
1078
 
1177
1079
  // src/commands/sign-message/index.ts
1178
1080
  async function signMessage(options, ctx) {
1081
+ const fallbackAdapter = getFallbackAdapter();
1179
1082
  const result = await executeWithFallback({
1180
1083
  command: "sign-message" /* SignMessage */,
1181
1084
  nativeExecutor: () => nativeSignMessage(options, ctx),
1182
- wagmiFallback: () => wagmiSignMessage({
1085
+ wagmiFallback: fallbackAdapter?.signMessage ? () => fallbackAdapter.signMessage({
1183
1086
  message: options.message
1184
- }),
1087
+ }) : void 0,
1185
1088
  customFallback: options.fallback
1186
1089
  });
1187
1090
  if (result.executedWith === "fallback") {
@@ -1241,16 +1144,17 @@ var SignTypedDataError = class extends Error {
1241
1144
 
1242
1145
  // src/commands/sign-typed-data/index.ts
1243
1146
  async function signTypedData(options, ctx) {
1147
+ const fallbackAdapter = getFallbackAdapter();
1244
1148
  const result = await executeWithFallback({
1245
1149
  command: "sign-typed-data" /* SignTypedData */,
1246
1150
  nativeExecutor: () => nativeSignTypedData(options, ctx),
1247
- wagmiFallback: () => wagmiSignTypedData({
1151
+ wagmiFallback: fallbackAdapter?.signTypedData ? () => fallbackAdapter.signTypedData({
1248
1152
  types: options.types,
1249
1153
  primaryType: options.primaryType,
1250
1154
  message: options.message,
1251
1155
  domain: options.domain,
1252
1156
  chainId: options.chainId
1253
- }),
1157
+ }) : void 0,
1254
1158
  customFallback: options.fallback
1255
1159
  });
1256
1160
  if (result.executedWith === "fallback") {
@@ -1307,7 +1211,7 @@ async function nativeSignTypedData(options, ctx) {
1307
1211
  }
1308
1212
 
1309
1213
  // src/commands/wallet-auth/siwe.ts
1310
- var import_viem2 = require("viem");
1214
+ var import_viem = require("viem");
1311
1215
  var import_chains = require("viem/chains");
1312
1216
  var generateSiweMessage = (siweMessageData) => {
1313
1217
  let siweMessage = "";
@@ -1366,7 +1270,7 @@ var WalletAuthError = class extends Error {
1366
1270
  };
1367
1271
 
1368
1272
  // src/commands/wallet-auth/validate.ts
1369
- var SIWE_NONCE_REGEX2 = /^[a-zA-Z0-9]+$/;
1273
+ var SIWE_NONCE_REGEX = /^[a-zA-Z0-9]+$/;
1370
1274
  var validateWalletAuthCommandInput = (params) => {
1371
1275
  if (!params.nonce) {
1372
1276
  return { valid: false, message: "'nonce' is required" };
@@ -1374,7 +1278,7 @@ var validateWalletAuthCommandInput = (params) => {
1374
1278
  if (params.nonce.length < 8) {
1375
1279
  return { valid: false, message: "'nonce' must be at least 8 characters" };
1376
1280
  }
1377
- if (!SIWE_NONCE_REGEX2.test(params.nonce)) {
1281
+ if (!SIWE_NONCE_REGEX.test(params.nonce)) {
1378
1282
  return {
1379
1283
  valid: false,
1380
1284
  message: "'nonce' must be alphanumeric (letters and numbers only)"
@@ -1397,14 +1301,15 @@ var validateWalletAuthCommandInput = (params) => {
1397
1301
 
1398
1302
  // src/commands/wallet-auth/index.ts
1399
1303
  async function walletAuth(options, ctx) {
1304
+ const fallbackAdapter = getFallbackAdapter();
1400
1305
  const result = await executeWithFallback({
1401
1306
  command: "wallet-auth" /* WalletAuth */,
1402
1307
  nativeExecutor: () => nativeWalletAuth(options, ctx),
1403
- wagmiFallback: () => wagmiWalletAuth({
1308
+ wagmiFallback: fallbackAdapter?.walletAuth ? () => fallbackAdapter.walletAuth({
1404
1309
  nonce: options.nonce,
1405
1310
  statement: options.statement,
1406
1311
  expirationTime: options.expirationTime
1407
- }),
1312
+ }) : void 0,
1408
1313
  customFallback: options.fallback
1409
1314
  });
1410
1315
  if (result.executedWith === "fallback") {
@@ -1658,11 +1563,10 @@ var _MiniKit = class _MiniKit {
1658
1563
  * ```typescript
1659
1564
  * const result = await MiniKit.sendTransaction({
1660
1565
  * chainId: 480,
1661
- * transaction: [{
1662
- * address: '0x...',
1663
- * abi: ContractABI,
1664
- * functionName: 'mint',
1665
- * args: [],
1566
+ * transactions: [{
1567
+ * to: '0x...',
1568
+ * data: '0x...',
1569
+ * value: '0x0',
1666
1570
  * }],
1667
1571
  * });
1668
1572
  * ```
@@ -1787,6 +1691,26 @@ var _MiniKit = class _MiniKit {
1787
1691
  }
1788
1692
  return sendHapticFeedback(options, this.getContext());
1789
1693
  }
1694
+ /**
1695
+ * Request app attestation token for a request hash
1696
+ */
1697
+ static attestation(options) {
1698
+ const active = this.getActiveMiniKit();
1699
+ if (active !== this) {
1700
+ return active.attestation(options);
1701
+ }
1702
+ return attestation(options, this.getContext());
1703
+ }
1704
+ /**
1705
+ * Close the mini app
1706
+ */
1707
+ static closeMiniApp(options = {}) {
1708
+ const active = this.getActiveMiniKit();
1709
+ if (active !== this) {
1710
+ return active.closeMiniApp(options);
1711
+ }
1712
+ return closeMiniApp(options, this.getContext());
1713
+ }
1790
1714
  // ============================================================================
1791
1715
  // Public State Accessors
1792
1716
  // ============================================================================
@@ -1965,6 +1889,8 @@ var _MiniKit = class _MiniKit {
1965
1889
  * - `MiniKit.commands.getPermissions()` → `await MiniKit.getPermissions()`
1966
1890
  * - `MiniKit.commands.requestPermission(payload)` → `await MiniKit.requestPermission(input)`
1967
1891
  * - `MiniKit.commands.sendHapticFeedback(payload)` → `await MiniKit.sendHapticFeedback(input)`
1892
+ * - `MiniKit.commands.attestation(payload)` → `await MiniKit.attestation(options)`
1893
+ * - `MiniKit.commands.closeMiniApp()` → `await MiniKit.closeMiniApp()`
1968
1894
  */
1969
1895
  static get commands() {
1970
1896
  throw new Error(
@@ -2052,13 +1978,18 @@ _MiniKit.showProfileCard = (username, walletAddress) => {
2052
1978
  var MiniKit = _MiniKit;
2053
1979
 
2054
1980
  // src/provider.ts
1981
+ var import_viem2 = require("viem");
2055
1982
  function _getAddress() {
2056
1983
  if (typeof window === "undefined") return void 0;
2057
1984
  return window.__worldapp_eip1193_address__;
2058
1985
  }
2059
1986
  function _setAddress(addr) {
2060
1987
  if (typeof window === "undefined") return;
2061
- window.__worldapp_eip1193_address__ = addr;
1988
+ try {
1989
+ window.__worldapp_eip1193_address__ = (0, import_viem2.getAddress)(addr);
1990
+ } catch {
1991
+ window.__worldapp_eip1193_address__ = addr;
1992
+ }
2062
1993
  }
2063
1994
  function rpcError(code, message) {
2064
1995
  return Object.assign(new Error(message), { code });
@@ -2178,16 +2109,19 @@ function createProvider() {
2178
2109
  }
2179
2110
  let authInFlight;
2180
2111
  async function doAuth() {
2181
- if (!MiniKit.isInWorldApp()) {
2182
- throw rpcError(4900, "World App provider only works inside World App");
2112
+ if (!MiniKit.isInWorldApp() || !MiniKit.isInstalled()) {
2113
+ throw rpcError(
2114
+ 4900,
2115
+ "World App provider only works inside World App and must be installed"
2116
+ );
2183
2117
  }
2184
2118
  try {
2185
2119
  const result = await MiniKit.walletAuth({
2186
2120
  nonce: crypto.randomUUID().replace(/-/g, ""),
2187
2121
  statement: "Sign in with World App"
2188
2122
  });
2189
- const addr = result.data.address;
2190
- _setAddress(addr);
2123
+ _setAddress(result.data.address);
2124
+ const addr = _getAddress();
2191
2125
  emit("accountsChanged", [addr]);
2192
2126
  return [addr];
2193
2127
  } catch (e) {
@@ -2257,18 +2191,21 @@ function createProvider() {
2257
2191
  }
2258
2192
  case "eth_sendTransaction": {
2259
2193
  const tx = extractTransactionParams(params);
2194
+ if (tx.chainId !== void 0 && tx.chainId !== 480) {
2195
+ throw rpcError(4902, "World App only supports World Chain (480)");
2196
+ }
2260
2197
  try {
2261
2198
  const result = await MiniKit.sendTransaction({
2262
- ...tx.chainId !== void 0 ? { chainId: tx.chainId } : {},
2263
- transaction: [
2199
+ chainId: tx.chainId ?? 480,
2200
+ transactions: [
2264
2201
  {
2265
- address: tx.to,
2202
+ to: tx.to,
2266
2203
  ...tx.data && tx.data !== "0x" ? { data: tx.data } : {},
2267
2204
  value: tx.value
2268
2205
  }
2269
2206
  ]
2270
2207
  });
2271
- return result.data.transactionId;
2208
+ return result.data.userOpHash;
2272
2209
  } catch (e) {
2273
2210
  throw rpcError(4001, `Send transaction failed: ${e.message}`);
2274
2211
  }