@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.
@@ -1,4 +1,3 @@
1
- 'use client';
2
1
  "use strict";
3
2
  "use client";
4
3
  var __create = Object.create;
@@ -37,13 +36,22 @@ __export(minikit_provider_exports, {
37
36
  });
38
37
  module.exports = __toCommonJS(minikit_provider_exports);
39
38
  var import_react = require("react");
40
- var wagmi = __toESM(require("wagmi"), 1);
39
+
40
+ // src/commands/fallback-adapter-registry.ts
41
+ var FALLBACK_ADAPTER_KEY = "__minikit_fallback_adapter__";
42
+ function setFallbackAdapter(adapter) {
43
+ globalThis[FALLBACK_ADAPTER_KEY] = adapter;
44
+ }
45
+ function getFallbackAdapter() {
46
+ return globalThis[FALLBACK_ADAPTER_KEY];
47
+ }
41
48
 
42
49
  // src/commands/wagmi-fallback.ts
43
50
  var SIWE_NONCE_REGEX = /^[a-zA-Z0-9]{8,}$/;
44
51
  var WAGMI_KEY = "__minikit_wagmi_config__";
45
52
  function setWagmiConfig(config) {
46
53
  globalThis[WAGMI_KEY] = config;
54
+ registerWagmiFallbacks();
47
55
  }
48
56
  function getWagmiConfig() {
49
57
  return globalThis[WAGMI_KEY];
@@ -51,14 +59,70 @@ function getWagmiConfig() {
51
59
  function hasWagmiConfig() {
52
60
  return globalThis[WAGMI_KEY] !== void 0;
53
61
  }
62
+ function registerWagmiFallbacks() {
63
+ setFallbackAdapter({
64
+ walletAuth: wagmiWalletAuth,
65
+ signMessage: wagmiSignMessage,
66
+ signTypedData: wagmiSignTypedData,
67
+ sendTransaction: wagmiSendTransaction
68
+ });
69
+ }
70
+ async function loadWagmiActions() {
71
+ console.log("[MiniKit WagmiFallback] loadWagmiActions:start", {
72
+ hasWindow: typeof window !== "undefined",
73
+ hasWagmiConfig: hasWagmiConfig()
74
+ });
75
+ try {
76
+ const actions = await import(
77
+ /* webpackIgnore: true */
78
+ "wagmi/actions"
79
+ );
80
+ console.log("[MiniKit WagmiFallback] loadWagmiActions:success");
81
+ return actions;
82
+ } catch (error) {
83
+ console.log("[MiniKit WagmiFallback] loadWagmiActions:error", {
84
+ message: error instanceof Error ? error.message : String(error)
85
+ });
86
+ const wrappedError = new Error(
87
+ 'Wagmi fallback requires the "wagmi" package. Install wagmi or provide a custom fallback.'
88
+ );
89
+ wrappedError.cause = error;
90
+ throw wrappedError;
91
+ }
92
+ }
93
+ async function loadSiwe() {
94
+ try {
95
+ return await import(
96
+ /* webpackIgnore: true */
97
+ "siwe"
98
+ );
99
+ } catch (error) {
100
+ const wrappedError = new Error(
101
+ 'Wagmi walletAuth fallback requires the "siwe" package. Install siwe or provide a custom fallback.'
102
+ );
103
+ wrappedError.cause = error;
104
+ throw wrappedError;
105
+ }
106
+ }
107
+ async function checksumAddress(addr) {
108
+ try {
109
+ const { getAddress } = await import(
110
+ /* webpackIgnore: true */
111
+ "viem"
112
+ );
113
+ return getAddress(addr);
114
+ } catch {
115
+ return addr;
116
+ }
117
+ }
54
118
  async function ensureConnected(config) {
55
- const { connect, getConnections } = await import("wagmi/actions");
119
+ const { connect, getConnections } = await loadWagmiActions();
56
120
  const isWorldApp = typeof window !== "undefined" && Boolean(window.WorldApp);
57
121
  const existingConnection = getConnections(config).find(
58
122
  (connection) => connection.accounts && connection.accounts.length > 0 && (isWorldApp || connection.connector?.id !== "worldApp")
59
123
  );
60
124
  if (existingConnection && existingConnection.accounts) {
61
- return existingConnection.accounts[0];
125
+ return checksumAddress(existingConnection.accounts[0]);
62
126
  }
63
127
  const connectors = config.connectors;
64
128
  if (!connectors || connectors.length === 0) {
@@ -79,7 +143,7 @@ async function ensureConnected(config) {
79
143
  const account = result.accounts[0];
80
144
  const address = typeof account === "string" ? account : account.address;
81
145
  if (address) {
82
- return address;
146
+ return checksumAddress(address);
83
147
  }
84
148
  }
85
149
  } catch (error) {
@@ -93,14 +157,19 @@ async function ensureConnected(config) {
93
157
  throw new Error("Failed to connect wallet");
94
158
  }
95
159
  async function wagmiWalletAuth(params) {
160
+ console.log("[MiniKit WagmiFallback] walletAuth:start", {
161
+ hasWagmiConfig: hasWagmiConfig(),
162
+ nonceLength: params.nonce?.length ?? 0
163
+ });
96
164
  const config = getWagmiConfig();
97
165
  if (!config) {
166
+ console.log("[MiniKit WagmiFallback] walletAuth:error:no-config");
98
167
  throw new Error(
99
168
  "Wagmi config not available. Pass wagmiConfig to MiniKitProvider."
100
169
  );
101
170
  }
102
- const { signMessage: signMessage2 } = await import("wagmi/actions");
103
- const { SiweMessage } = await import("siwe");
171
+ const { signMessage: signMessage2 } = await loadWagmiActions();
172
+ const { SiweMessage } = await loadSiwe();
104
173
  const address = await ensureConnected(config);
105
174
  if (!SIWE_NONCE_REGEX.test(params.nonce)) {
106
175
  throw new Error(
@@ -127,13 +196,17 @@ async function wagmiWalletAuth(params) {
127
196
  };
128
197
  }
129
198
  async function wagmiSignMessage(params) {
199
+ console.log("[MiniKit WagmiFallback] signMessage:start", {
200
+ hasWagmiConfig: hasWagmiConfig()
201
+ });
130
202
  const config = getWagmiConfig();
131
203
  if (!config) {
204
+ console.log("[MiniKit WagmiFallback] signMessage:error:no-config");
132
205
  throw new Error(
133
206
  "Wagmi config not available. Pass wagmiConfig to MiniKitProvider."
134
207
  );
135
208
  }
136
- const { signMessage: signMessage2 } = await import("wagmi/actions");
209
+ const { signMessage: signMessage2 } = await loadWagmiActions();
137
210
  const address = await ensureConnected(config);
138
211
  const signature = await signMessage2(config, {
139
212
  account: address,
@@ -147,13 +220,18 @@ async function wagmiSignMessage(params) {
147
220
  };
148
221
  }
149
222
  async function wagmiSignTypedData(params) {
223
+ console.log("[MiniKit WagmiFallback] signTypedData:start", {
224
+ hasWagmiConfig: hasWagmiConfig(),
225
+ hasChainId: params.chainId !== void 0
226
+ });
150
227
  const config = getWagmiConfig();
151
228
  if (!config) {
229
+ console.log("[MiniKit WagmiFallback] signTypedData:error:no-config");
152
230
  throw new Error(
153
231
  "Wagmi config not available. Pass wagmiConfig to MiniKitProvider."
154
232
  );
155
233
  }
156
- const { getChainId, signTypedData: signTypedData2, switchChain } = await import("wagmi/actions");
234
+ const { getChainId, signTypedData: signTypedData2, switchChain } = await loadWagmiActions();
157
235
  const address = await ensureConnected(config);
158
236
  if (params.chainId !== void 0) {
159
237
  const currentChainId = await getChainId(config);
@@ -180,13 +258,19 @@ function isChainMismatchError(error) {
180
258
  return message.includes("does not match the target chain");
181
259
  }
182
260
  async function wagmiSendTransaction(params) {
261
+ console.log("[MiniKit WagmiFallback] sendTransaction:start", {
262
+ hasWagmiConfig: hasWagmiConfig(),
263
+ chainId: params.chainId,
264
+ hasData: Boolean(params.transaction.data)
265
+ });
183
266
  const config = getWagmiConfig();
184
267
  if (!config) {
268
+ console.log("[MiniKit WagmiFallback] sendTransaction:error:no-config");
185
269
  throw new Error(
186
270
  "Wagmi config not available. Pass wagmiConfig to MiniKitProvider."
187
271
  );
188
272
  }
189
- const { getChainId, getWalletClient, sendTransaction: sendTransaction2, switchChain } = await import("wagmi/actions");
273
+ const { getChainId, getWalletClient, sendTransaction: sendTransaction2, switchChain } = await loadWagmiActions();
190
274
  await ensureConnected(config);
191
275
  const targetChainId = params.chainId ?? config.chains?.[0]?.id;
192
276
  const ensureTargetChain = async () => {
@@ -229,9 +313,10 @@ async function wagmiSendTransaction(params) {
229
313
 
230
314
  // src/commands/types.ts
231
315
  var COMMAND_VERSIONS = {
316
+ ["attestation" /* Attestation */]: 1,
232
317
  ["pay" /* Pay */]: 1,
233
318
  ["wallet-auth" /* WalletAuth */]: 2,
234
- ["send-transaction" /* SendTransaction */]: 1,
319
+ ["send-transaction" /* SendTransaction */]: 2,
235
320
  ["sign-message" /* SignMessage */]: 1,
236
321
  ["sign-typed-data" /* SignTypedData */]: 1,
237
322
  ["share-contacts" /* ShareContacts */]: 1,
@@ -239,9 +324,11 @@ var COMMAND_VERSIONS = {
239
324
  ["get-permissions" /* GetPermissions */]: 1,
240
325
  ["send-haptic-feedback" /* SendHapticFeedback */]: 1,
241
326
  ["share" /* Share */]: 1,
242
- ["chat" /* Chat */]: 1
327
+ ["chat" /* Chat */]: 1,
328
+ ["close-miniapp" /* CloseMiniApp */]: 1
243
329
  };
244
330
  var commandAvailability = {
331
+ ["attestation" /* Attestation */]: false,
245
332
  ["pay" /* Pay */]: false,
246
333
  ["wallet-auth" /* WalletAuth */]: false,
247
334
  ["send-transaction" /* SendTransaction */]: false,
@@ -252,7 +339,8 @@ var commandAvailability = {
252
339
  ["get-permissions" /* GetPermissions */]: false,
253
340
  ["send-haptic-feedback" /* SendHapticFeedback */]: false,
254
341
  ["share" /* Share */]: false,
255
- ["chat" /* Chat */]: false
342
+ ["chat" /* Chat */]: false,
343
+ ["close-miniapp" /* CloseMiniApp */]: false
256
344
  };
257
345
  function isCommandAvailable(command) {
258
346
  return commandAvailability[command] ?? false;
@@ -324,6 +412,8 @@ var CommandUnavailableError = class extends Error {
324
412
  var EventManager = class {
325
413
  constructor() {
326
414
  this.listeners = {
415
+ ["miniapp-attestation" /* MiniAppAttestation */]: () => {
416
+ },
327
417
  ["miniapp-payment" /* MiniAppPayment */]: () => {
328
418
  },
329
419
  ["miniapp-wallet-auth" /* MiniAppWalletAuth */]: () => {
@@ -388,7 +478,7 @@ async function executeWithFallback(options) {
388
478
  console.warn(`Native ${command} failed, attempting fallback:`, error);
389
479
  }
390
480
  }
391
- if (!inWorldApp && wagmiFallback && hasWagmiConfig()) {
481
+ if (!inWorldApp && wagmiFallback) {
392
482
  try {
393
483
  const data = await wagmiFallback();
394
484
  return { data, executedWith: "wagmi" };
@@ -396,7 +486,7 @@ async function executeWithFallback(options) {
396
486
  console.warn(`Wagmi fallback for ${command} failed:`, error);
397
487
  }
398
488
  }
399
- if (customFallback) {
489
+ if (!inWorldApp && customFallback) {
400
490
  const data = await customFallback();
401
491
  return { data, executedWith: "fallback" };
402
492
  }
@@ -418,6 +508,67 @@ function determineFallbackReason(command) {
418
508
  return "commandNotSupported";
419
509
  }
420
510
 
511
+ // src/commands/attestation/types.ts
512
+ var AttestationError = class extends Error {
513
+ constructor(error_code) {
514
+ super(`Attestation failed: ${error_code}`);
515
+ this.error_code = error_code;
516
+ this.name = "AttestationError";
517
+ }
518
+ };
519
+
520
+ // src/commands/attestation/index.ts
521
+ async function attestation(options, ctx) {
522
+ const result = await executeWithFallback({
523
+ command: "attestation" /* Attestation */,
524
+ nativeExecutor: () => nativeAttestation(options, ctx),
525
+ customFallback: options.fallback
526
+ });
527
+ if (result.executedWith === "fallback") {
528
+ return { executedWith: "fallback", data: result.data };
529
+ }
530
+ return {
531
+ executedWith: "minikit",
532
+ data: result.data
533
+ };
534
+ }
535
+ async function nativeAttestation(options, ctx) {
536
+ if (!ctx) {
537
+ ctx = { events: new EventManager(), state: { deviceProperties: {} } };
538
+ }
539
+ if (typeof window === "undefined" || !isCommandAvailable("attestation" /* Attestation */)) {
540
+ throw new Error(
541
+ "'attestation' command is unavailable. Check MiniKit.install() or update the app version"
542
+ );
543
+ }
544
+ if (!options.requestHash || options.requestHash.length === 0) {
545
+ throw new Error("'attestation' command requires a non-empty requestHash");
546
+ }
547
+ const payload = await new Promise(
548
+ (resolve, reject) => {
549
+ try {
550
+ ctx.events.subscribe("miniapp-attestation" /* MiniAppAttestation */, (response) => {
551
+ ctx.events.unsubscribe("miniapp-attestation" /* MiniAppAttestation */);
552
+ resolve(response);
553
+ });
554
+ sendMiniKitEvent({
555
+ command: "attestation" /* Attestation */,
556
+ version: COMMAND_VERSIONS["attestation" /* Attestation */],
557
+ payload: {
558
+ request_hash: options.requestHash
559
+ }
560
+ });
561
+ } catch (error) {
562
+ reject(error);
563
+ }
564
+ }
565
+ );
566
+ if (payload.status === "error") {
567
+ throw new AttestationError(payload.error_code);
568
+ }
569
+ return payload;
570
+ }
571
+
421
572
  // src/commands/chat/types.ts
422
573
  var ChatError = class extends Error {
423
574
  constructor(error_code) {
@@ -479,6 +630,38 @@ async function nativeChat(options, ctx) {
479
630
  return payload;
480
631
  }
481
632
 
633
+ // src/commands/close-miniapp/index.ts
634
+ async function closeMiniApp(options = {}, _ctx) {
635
+ const result = await executeWithFallback({
636
+ command: "close-miniapp" /* CloseMiniApp */,
637
+ nativeExecutor: () => nativeCloseMiniApp(),
638
+ customFallback: options.fallback
639
+ });
640
+ if (result.executedWith === "fallback") {
641
+ return { executedWith: "fallback", data: result.data };
642
+ }
643
+ return {
644
+ executedWith: "minikit",
645
+ data: result.data
646
+ };
647
+ }
648
+ async function nativeCloseMiniApp() {
649
+ if (typeof window === "undefined" || !isCommandAvailable("close-miniapp" /* CloseMiniApp */)) {
650
+ throw new Error(
651
+ "'closeMiniApp' command is unavailable. Check MiniKit.install() or update the app version"
652
+ );
653
+ }
654
+ sendMiniKitEvent({
655
+ command: "close-miniapp" /* CloseMiniApp */,
656
+ version: COMMAND_VERSIONS["close-miniapp" /* CloseMiniApp */],
657
+ payload: {}
658
+ });
659
+ return {
660
+ status: "success",
661
+ version: COMMAND_VERSIONS["close-miniapp" /* CloseMiniApp */]
662
+ };
663
+ }
664
+
482
665
  // src/commands/get-permissions/types.ts
483
666
  var GetPermissionsError = class extends Error {
484
667
  constructor(error_code) {
@@ -747,9 +930,6 @@ async function nativeSendHapticFeedback(options, ctx) {
747
930
  return payload;
748
931
  }
749
932
 
750
- // src/commands/send-transaction/index.ts
751
- var import_viem = require("viem");
752
-
753
933
  // src/commands/send-transaction/types.ts
754
934
  var SendTransactionError = class extends Error {
755
935
  constructor(code, details) {
@@ -764,16 +944,6 @@ var SendTransactionError = class extends Error {
764
944
  var isValidHex = (str) => {
765
945
  return /^0x[0-9A-Fa-f]+$/.test(str);
766
946
  };
767
- var objectValuesToArrayRecursive = (input) => {
768
- if (input === null || typeof input !== "object") {
769
- return input;
770
- }
771
- if (Array.isArray(input)) {
772
- return input.map((item) => objectValuesToArrayRecursive(item));
773
- }
774
- const values = Object.values(input);
775
- return values.map((value) => objectValuesToArrayRecursive(value));
776
- };
777
947
  var processPayload = (payload) => {
778
948
  if (typeof payload === "boolean" || typeof payload === "string" || payload === null || payload === void 0) {
779
949
  return payload;
@@ -786,6 +956,20 @@ var processPayload = (payload) => {
786
956
  }
787
957
  if (typeof payload === "object") {
788
958
  const result = { ...payload };
959
+ if ("chainId" in result && result.chainId !== void 0) {
960
+ if (typeof result.chainId === "string") {
961
+ const parsed = Number(result.chainId);
962
+ if (Number.isFinite(parsed)) {
963
+ result.chainId = parsed;
964
+ }
965
+ } else if (typeof result.chainId === "bigint") {
966
+ const parsed = Number(result.chainId);
967
+ if (!Number.isSafeInteger(parsed)) {
968
+ throw new Error(`Invalid chainId: ${String(result.chainId)}`);
969
+ }
970
+ result.chainId = parsed;
971
+ }
972
+ }
789
973
  if ("value" in result && result.value !== void 0) {
790
974
  if (typeof result.value !== "string") {
791
975
  result.value = String(result.value);
@@ -802,6 +986,7 @@ var processPayload = (payload) => {
802
986
  }
803
987
  for (const key in result) {
804
988
  if (Object.prototype.hasOwnProperty.call(result, key)) {
989
+ if (key === "chainId") continue;
805
990
  result[key] = processPayload(result[key]);
806
991
  }
807
992
  }
@@ -810,37 +995,48 @@ var processPayload = (payload) => {
810
995
  return payload;
811
996
  };
812
997
  var validateSendTransactionPayload = (payload) => {
813
- if (payload.formatPayload) {
814
- const formattedPayload = processPayload(payload);
815
- formattedPayload.transaction = formattedPayload.transaction.map((tx) => {
816
- if ("args" in tx && tx.args !== void 0) {
817
- const args = objectValuesToArrayRecursive(tx.args);
818
- return {
819
- ...tx,
820
- args
821
- };
822
- }
823
- return tx;
824
- });
825
- return formattedPayload;
826
- }
827
- return payload;
998
+ return processPayload(payload);
828
999
  };
829
1000
 
830
1001
  // src/commands/send-transaction/index.ts
831
1002
  var WORLD_CHAIN_ID = 480;
832
1003
  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.";
1004
+ function resolveChainId(options) {
1005
+ return options.chainId;
1006
+ }
1007
+ function resolveTransactions(options) {
1008
+ if (options.transactions.length === 0) {
1009
+ throw new SendTransactionError("input_error" /* InputError */, {
1010
+ reason: "At least one transaction is required. Use `transactions: [{ to, data, value }]`."
1011
+ });
1012
+ }
1013
+ return options.transactions;
1014
+ }
1015
+ function normalizeSendTransactionOptions(options) {
1016
+ const chainId = resolveChainId(options);
1017
+ if (chainId !== WORLD_CHAIN_ID) {
1018
+ throw new SendTransactionError("invalid_operation" /* InvalidOperation */, {
1019
+ reason: `World App only supports World Chain (chainId: ${WORLD_CHAIN_ID})`
1020
+ });
1021
+ }
1022
+ return {
1023
+ transactions: resolveTransactions(options),
1024
+ chainId
1025
+ };
1026
+ }
833
1027
  async function sendTransaction(options, ctx) {
834
- const isWagmiFallbackPath = !isInWorldApp() && hasWagmiConfig();
835
- if (isWagmiFallbackPath && options.transaction.length > 1 && !options.fallback) {
1028
+ const normalizedOptions = normalizeSendTransactionOptions(options);
1029
+ const fallbackAdapter = getFallbackAdapter();
1030
+ const isWagmiFallbackPath = !isInWorldApp() && Boolean(fallbackAdapter?.sendTransaction);
1031
+ if (isWagmiFallbackPath && normalizedOptions.transactions.length > 1 && !options.fallback) {
836
1032
  throw new SendTransactionError("invalid_operation" /* InvalidOperation */, {
837
1033
  reason: WAGMI_MULTI_TX_ERROR_MESSAGE
838
1034
  });
839
1035
  }
840
1036
  const result = await executeWithFallback({
841
1037
  command: "send-transaction" /* SendTransaction */,
842
- nativeExecutor: () => nativeSendTransaction(options, ctx),
843
- wagmiFallback: () => wagmiSendTransactionAdapter(options),
1038
+ nativeExecutor: () => nativeSendTransaction(normalizedOptions, ctx),
1039
+ wagmiFallback: fallbackAdapter?.sendTransaction ? () => adapterSendTransactionFallback(normalizedOptions) : void 0,
844
1040
  customFallback: options.fallback
845
1041
  });
846
1042
  if (result.executedWith === "fallback") {
@@ -866,15 +1062,22 @@ async function nativeSendTransaction(options, ctx) {
866
1062
  "'sendTransaction' command is unavailable. Check MiniKit.install() or update the app version"
867
1063
  );
868
1064
  }
869
- if (options.chainId !== void 0 && options.chainId !== WORLD_CHAIN_ID) {
1065
+ if (options.chainId !== WORLD_CHAIN_ID) {
870
1066
  throw new Error(
871
1067
  `World App only supports World Chain (chainId: ${WORLD_CHAIN_ID})`
872
1068
  );
873
1069
  }
1070
+ const commandInput = window.WorldApp?.supported_commands.find(
1071
+ (command) => command.name === "send-transaction" /* SendTransaction */
1072
+ );
1073
+ if (commandInput && !commandInput.supported_versions.includes(
1074
+ COMMAND_VERSIONS["send-transaction" /* SendTransaction */]
1075
+ )) {
1076
+ throw new CommandUnavailableError("send-transaction" /* SendTransaction */, "oldAppVersion");
1077
+ }
874
1078
  const input = {
875
- transaction: options.transaction,
876
- permit2: options.permit2,
877
- formatPayload: options.formatPayload !== false
1079
+ transactions: options.transactions,
1080
+ chainId: options.chainId
878
1081
  };
879
1082
  const validatedPayload = validateSendTransactionPayload(input);
880
1083
  const finalPayload = await new Promise(
@@ -900,71 +1103,43 @@ async function nativeSendTransaction(options, ctx) {
900
1103
  finalPayload.details
901
1104
  );
902
1105
  }
1106
+ const successPayload = finalPayload;
903
1107
  return {
904
- transactionHash: null,
905
- userOpHash: finalPayload.userOpHash ?? null,
906
- mini_app_id: finalPayload.mini_app_id ?? null,
1108
+ userOpHash: String(successPayload.userOpHash ?? ""),
907
1109
  status: finalPayload.status,
908
1110
  version: finalPayload.version,
909
- transactionId: finalPayload.transaction_id,
910
- reference: finalPayload.reference,
911
- from: finalPayload.from,
912
- chain: finalPayload.chain,
913
- timestamp: finalPayload.timestamp,
914
- // Deprecated aliases
915
- transaction_id: finalPayload.transaction_id,
916
- transaction_status: "submitted"
1111
+ from: String(successPayload.from ?? ""),
1112
+ timestamp: String(successPayload.timestamp ?? (/* @__PURE__ */ new Date()).toISOString())
917
1113
  };
918
1114
  }
919
- async function wagmiSendTransactionAdapter(options) {
920
- if (options.transaction.length > 1) {
1115
+ async function adapterSendTransactionFallback(options) {
1116
+ if (options.transactions.length > 1) {
921
1117
  throw new Error(WAGMI_MULTI_TX_ERROR_MESSAGE);
922
1118
  }
923
- if (options.permit2 && options.permit2.length > 0) {
924
- console.warn(
925
- "Permit2 signature is not automatically supported via Wagmi fallback. Transactions will execute without permit2."
926
- );
927
- }
928
- const transactions = options.transaction.map((tx) => ({
929
- address: tx.address,
930
- // Encode the function call data
931
- data: encodeTransactionData(tx),
932
- value: tx.value
933
- }));
934
- const firstTransaction = transactions[0];
1119
+ const firstTransaction = options.transactions[0];
935
1120
  if (!firstTransaction) {
936
1121
  throw new Error("At least one transaction is required");
937
1122
  }
938
- const result = await wagmiSendTransaction({
939
- transaction: firstTransaction,
1123
+ const fallbackAdapter = getFallbackAdapter();
1124
+ if (!fallbackAdapter?.sendTransaction) {
1125
+ throw new Error("Fallback adapter is not registered.");
1126
+ }
1127
+ const result = await fallbackAdapter.sendTransaction({
1128
+ transaction: {
1129
+ address: firstTransaction.to,
1130
+ data: firstTransaction.data,
1131
+ value: firstTransaction.value
1132
+ },
940
1133
  chainId: options.chainId
941
1134
  });
942
1135
  return {
943
- transactionHash: result.transactionHash,
944
- userOpHash: null,
945
- mini_app_id: null,
1136
+ userOpHash: result.transactionHash,
946
1137
  status: "success",
947
- version: 1,
948
- transactionId: null,
949
- reference: null,
950
- from: null,
951
- chain: null,
952
- timestamp: null
1138
+ version: COMMAND_VERSIONS["send-transaction" /* SendTransaction */],
1139
+ from: "",
1140
+ timestamp: (/* @__PURE__ */ new Date()).toISOString()
953
1141
  };
954
1142
  }
955
- function encodeTransactionData(tx) {
956
- if (tx.data) {
957
- return tx.data;
958
- }
959
- if (!tx.abi || !tx.functionName) {
960
- throw new Error("Transaction requires `data` or `abi` + `functionName`.");
961
- }
962
- return (0, import_viem.encodeFunctionData)({
963
- abi: tx.abi,
964
- functionName: tx.functionName,
965
- args: tx.args ?? []
966
- });
967
- }
968
1143
 
969
1144
  // src/commands/share/format.ts
970
1145
  var MAX_FILES = 10;
@@ -1183,12 +1358,13 @@ var SignMessageError = class extends Error {
1183
1358
 
1184
1359
  // src/commands/sign-message/index.ts
1185
1360
  async function signMessage(options, ctx) {
1361
+ const fallbackAdapter = getFallbackAdapter();
1186
1362
  const result = await executeWithFallback({
1187
1363
  command: "sign-message" /* SignMessage */,
1188
1364
  nativeExecutor: () => nativeSignMessage(options, ctx),
1189
- wagmiFallback: () => wagmiSignMessage({
1365
+ wagmiFallback: fallbackAdapter?.signMessage ? () => fallbackAdapter.signMessage({
1190
1366
  message: options.message
1191
- }),
1367
+ }) : void 0,
1192
1368
  customFallback: options.fallback
1193
1369
  });
1194
1370
  if (result.executedWith === "fallback") {
@@ -1248,16 +1424,17 @@ var SignTypedDataError = class extends Error {
1248
1424
 
1249
1425
  // src/commands/sign-typed-data/index.ts
1250
1426
  async function signTypedData(options, ctx) {
1427
+ const fallbackAdapter = getFallbackAdapter();
1251
1428
  const result = await executeWithFallback({
1252
1429
  command: "sign-typed-data" /* SignTypedData */,
1253
1430
  nativeExecutor: () => nativeSignTypedData(options, ctx),
1254
- wagmiFallback: () => wagmiSignTypedData({
1431
+ wagmiFallback: fallbackAdapter?.signTypedData ? () => fallbackAdapter.signTypedData({
1255
1432
  types: options.types,
1256
1433
  primaryType: options.primaryType,
1257
1434
  message: options.message,
1258
1435
  domain: options.domain,
1259
1436
  chainId: options.chainId
1260
- }),
1437
+ }) : void 0,
1261
1438
  customFallback: options.fallback
1262
1439
  });
1263
1440
  if (result.executedWith === "fallback") {
@@ -1314,7 +1491,7 @@ async function nativeSignTypedData(options, ctx) {
1314
1491
  }
1315
1492
 
1316
1493
  // src/commands/wallet-auth/siwe.ts
1317
- var import_viem2 = require("viem");
1494
+ var import_viem = require("viem");
1318
1495
  var import_chains = require("viem/chains");
1319
1496
  var generateSiweMessage = (siweMessageData) => {
1320
1497
  let siweMessage = "";
@@ -1404,14 +1581,15 @@ var validateWalletAuthCommandInput = (params) => {
1404
1581
 
1405
1582
  // src/commands/wallet-auth/index.ts
1406
1583
  async function walletAuth(options, ctx) {
1584
+ const fallbackAdapter = getFallbackAdapter();
1407
1585
  const result = await executeWithFallback({
1408
1586
  command: "wallet-auth" /* WalletAuth */,
1409
1587
  nativeExecutor: () => nativeWalletAuth(options, ctx),
1410
- wagmiFallback: () => wagmiWalletAuth({
1588
+ wagmiFallback: fallbackAdapter?.walletAuth ? () => fallbackAdapter.walletAuth({
1411
1589
  nonce: options.nonce,
1412
1590
  statement: options.statement,
1413
1591
  expirationTime: options.expirationTime
1414
- }),
1592
+ }) : void 0,
1415
1593
  customFallback: options.fallback
1416
1594
  });
1417
1595
  if (result.executedWith === "fallback") {
@@ -1665,11 +1843,10 @@ var _MiniKit = class _MiniKit {
1665
1843
  * ```typescript
1666
1844
  * const result = await MiniKit.sendTransaction({
1667
1845
  * chainId: 480,
1668
- * transaction: [{
1669
- * address: '0x...',
1670
- * abi: ContractABI,
1671
- * functionName: 'mint',
1672
- * args: [],
1846
+ * transactions: [{
1847
+ * to: '0x...',
1848
+ * data: '0x...',
1849
+ * value: '0x0',
1673
1850
  * }],
1674
1851
  * });
1675
1852
  * ```
@@ -1794,6 +1971,26 @@ var _MiniKit = class _MiniKit {
1794
1971
  }
1795
1972
  return sendHapticFeedback(options, this.getContext());
1796
1973
  }
1974
+ /**
1975
+ * Request app attestation token for a request hash
1976
+ */
1977
+ static attestation(options) {
1978
+ const active = this.getActiveMiniKit();
1979
+ if (active !== this) {
1980
+ return active.attestation(options);
1981
+ }
1982
+ return attestation(options, this.getContext());
1983
+ }
1984
+ /**
1985
+ * Close the mini app
1986
+ */
1987
+ static closeMiniApp(options = {}) {
1988
+ const active = this.getActiveMiniKit();
1989
+ if (active !== this) {
1990
+ return active.closeMiniApp(options);
1991
+ }
1992
+ return closeMiniApp(options, this.getContext());
1993
+ }
1797
1994
  // ============================================================================
1798
1995
  // Public State Accessors
1799
1996
  // ============================================================================
@@ -1972,6 +2169,8 @@ var _MiniKit = class _MiniKit {
1972
2169
  * - `MiniKit.commands.getPermissions()` → `await MiniKit.getPermissions()`
1973
2170
  * - `MiniKit.commands.requestPermission(payload)` → `await MiniKit.requestPermission(input)`
1974
2171
  * - `MiniKit.commands.sendHapticFeedback(payload)` → `await MiniKit.sendHapticFeedback(input)`
2172
+ * - `MiniKit.commands.attestation(payload)` → `await MiniKit.attestation(options)`
2173
+ * - `MiniKit.commands.closeMiniApp()` → `await MiniKit.closeMiniApp()`
1975
2174
  */
1976
2175
  static get commands() {
1977
2176
  throw new Error(
@@ -2063,24 +2262,14 @@ var import_jsx_runtime = require("react/jsx-runtime");
2063
2262
  var MiniKitContext = (0, import_react.createContext)(
2064
2263
  void 0
2065
2264
  );
2066
- function useWagmiConfigSafe() {
2067
- const useConfig2 = wagmi.useConfig;
2068
- if (!useConfig2) return void 0;
2069
- try {
2070
- return useConfig2();
2071
- } catch {
2072
- return void 0;
2073
- }
2074
- }
2075
2265
  var MiniKitProvider = ({
2076
2266
  children,
2077
2267
  props
2078
2268
  }) => {
2079
- const detectedWagmiConfig = useWagmiConfigSafe();
2080
2269
  const [isInstalled, setIsInstalled] = (0, import_react.useState)(
2081
2270
  void 0
2082
2271
  );
2083
- const wagmiConfig = props?.wagmiConfig ?? detectedWagmiConfig;
2272
+ const wagmiConfig = props?.wagmiConfig;
2084
2273
  (0, import_react.useEffect)(() => {
2085
2274
  const { success } = MiniKit.install(props?.appId);
2086
2275
  if (!success) return setIsInstalled(false);