@worldcoin/minikit-js 2.0.2 → 2.0.3
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/chunk-2ADHLH4F.js +14 -0
- package/build/{chunk-OLN2PAHM.js → chunk-5B6BPEWR.js} +105 -73
- package/build/chunk-6E2XIIO6.js +8 -0
- package/build/{chunk-363XY57O.js → chunk-7RB4UJBW.js} +6 -4
- package/build/{chunk-7SC4LSCB.js → chunk-AH3WTRZY.js} +14 -220
- package/build/chunk-DZ2YRSIU.js +216 -0
- package/build/{chunk-XO2TC2R4.js → chunk-MXMNPAOF.js} +8 -10
- package/build/{chunk-4HSRVHAU.js → chunk-YPZEODWL.js} +23 -2
- package/build/command-exports.cjs +16 -19
- package/build/command-exports.js +14 -12
- package/build/connector/index.cjs +273 -245
- package/build/connector/index.js +10 -7
- package/build/index.cjs +31 -28
- package/build/index.js +6 -4
- package/build/minikit-provider.cjs +34 -306
- package/build/minikit-provider.js +15 -8
- package/build/siwe-exports.cjs +21 -1
- package/build/siwe-exports.js +1 -1
- package/build/wagmi-fallback-register.cjs +362 -0
- package/build/wagmi-fallback-register.d.cts +10 -0
- package/build/wagmi-fallback-register.d.ts +10 -0
- package/build/wagmi-fallback-register.js +14 -0
- package/package.json +11 -1
package/build/connector/index.js
CHANGED
|
@@ -3,15 +3,18 @@ import {
|
|
|
3
3
|
_getAddress,
|
|
4
4
|
_setAddress,
|
|
5
5
|
getWorldAppProvider
|
|
6
|
-
} from "../chunk-
|
|
7
|
-
import {
|
|
8
|
-
setWagmiConfig
|
|
9
|
-
} from "../chunk-OLN2PAHM.js";
|
|
6
|
+
} from "../chunk-MXMNPAOF.js";
|
|
10
7
|
import {
|
|
11
8
|
MiniKit
|
|
12
|
-
} from "../chunk-
|
|
13
|
-
import "../chunk-
|
|
14
|
-
import "../chunk-
|
|
9
|
+
} from "../chunk-7RB4UJBW.js";
|
|
10
|
+
import "../chunk-AH3WTRZY.js";
|
|
11
|
+
import "../chunk-YPZEODWL.js";
|
|
12
|
+
import {
|
|
13
|
+
setWagmiConfig
|
|
14
|
+
} from "../chunk-5B6BPEWR.js";
|
|
15
|
+
import "../chunk-2ADHLH4F.js";
|
|
16
|
+
import "../chunk-6E2XIIO6.js";
|
|
17
|
+
import "../chunk-DZ2YRSIU.js";
|
|
15
18
|
|
|
16
19
|
// src/connector/connector.ts
|
|
17
20
|
function worldApp(options = {}) {
|
package/build/index.cjs
CHANGED
|
@@ -172,6 +172,14 @@ var EventManager = class {
|
|
|
172
172
|
};
|
|
173
173
|
|
|
174
174
|
// src/commands/fallback.ts
|
|
175
|
+
var PartialExecutionError = class extends Error {
|
|
176
|
+
constructor(message, submitted, cause) {
|
|
177
|
+
super(message);
|
|
178
|
+
this.name = "PartialExecutionError";
|
|
179
|
+
this.submitted = submitted;
|
|
180
|
+
this.cause = cause;
|
|
181
|
+
}
|
|
182
|
+
};
|
|
175
183
|
async function executeWithFallback(options) {
|
|
176
184
|
const {
|
|
177
185
|
command,
|
|
@@ -197,6 +205,9 @@ async function executeWithFallback(options) {
|
|
|
197
205
|
const data = await wagmiFallback();
|
|
198
206
|
return { data, executedWith: "wagmi" };
|
|
199
207
|
} catch (error) {
|
|
208
|
+
if (error instanceof PartialExecutionError || error instanceof Error && error.name === "PartialExecutionError") {
|
|
209
|
+
throw error;
|
|
210
|
+
}
|
|
200
211
|
console.warn(`Wagmi fallback for ${command} failed:`, error);
|
|
201
212
|
}
|
|
202
213
|
}
|
|
@@ -720,7 +731,6 @@ var validateSendTransactionPayload = (payload) => {
|
|
|
720
731
|
|
|
721
732
|
// src/commands/send-transaction/index.ts
|
|
722
733
|
var WORLD_CHAIN_ID = 480;
|
|
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
734
|
function resolveChainId(options) {
|
|
725
735
|
return options.chainId;
|
|
726
736
|
}
|
|
@@ -747,12 +757,6 @@ function normalizeSendTransactionOptions(options) {
|
|
|
747
757
|
async function sendTransaction(options, ctx) {
|
|
748
758
|
const normalizedOptions = normalizeSendTransactionOptions(options);
|
|
749
759
|
const fallbackAdapter = getFallbackAdapter();
|
|
750
|
-
const isWagmiFallbackPath = !isInWorldApp() && Boolean(fallbackAdapter?.sendTransaction);
|
|
751
|
-
if (isWagmiFallbackPath && normalizedOptions.transactions.length > 1 && !options.fallback) {
|
|
752
|
-
throw new SendTransactionError("invalid_operation" /* InvalidOperation */, {
|
|
753
|
-
reason: WAGMI_MULTI_TX_ERROR_MESSAGE
|
|
754
|
-
});
|
|
755
|
-
}
|
|
756
760
|
const result = await executeWithFallback({
|
|
757
761
|
command: "send-transaction" /* SendTransaction */,
|
|
758
762
|
nativeExecutor: () => nativeSendTransaction(normalizedOptions, ctx),
|
|
@@ -833,23 +837,16 @@ async function nativeSendTransaction(options, ctx) {
|
|
|
833
837
|
};
|
|
834
838
|
}
|
|
835
839
|
async function adapterSendTransactionFallback(options) {
|
|
836
|
-
if (options.transactions.length > 1) {
|
|
837
|
-
throw new Error(WAGMI_MULTI_TX_ERROR_MESSAGE);
|
|
838
|
-
}
|
|
839
|
-
const firstTransaction = options.transactions[0];
|
|
840
|
-
if (!firstTransaction) {
|
|
841
|
-
throw new Error("At least one transaction is required");
|
|
842
|
-
}
|
|
843
840
|
const fallbackAdapter = getFallbackAdapter();
|
|
844
841
|
if (!fallbackAdapter?.sendTransaction) {
|
|
845
842
|
throw new Error("Fallback adapter is not registered.");
|
|
846
843
|
}
|
|
847
844
|
const result = await fallbackAdapter.sendTransaction({
|
|
848
|
-
|
|
849
|
-
address:
|
|
850
|
-
data:
|
|
851
|
-
value:
|
|
852
|
-
},
|
|
845
|
+
transactions: options.transactions.map((tx) => ({
|
|
846
|
+
address: tx.to,
|
|
847
|
+
data: tx.data,
|
|
848
|
+
value: tx.value
|
|
849
|
+
})),
|
|
853
850
|
chainId: options.chainId
|
|
854
851
|
});
|
|
855
852
|
return {
|
|
@@ -1998,6 +1995,18 @@ var MiniKit = _MiniKit;
|
|
|
1998
1995
|
|
|
1999
1996
|
// src/provider.ts
|
|
2000
1997
|
var import_viem2 = require("viem");
|
|
1998
|
+
|
|
1999
|
+
// src/helpers/hex.ts
|
|
2000
|
+
var HEX_ADDRESS_REGEX = /^0x[0-9a-fA-F]{40}$/;
|
|
2001
|
+
var HEX_STRING_REGEX = /^0x[0-9a-fA-F]*$/;
|
|
2002
|
+
function isHexAddress(value) {
|
|
2003
|
+
return typeof value === "string" && HEX_ADDRESS_REGEX.test(value);
|
|
2004
|
+
}
|
|
2005
|
+
function isHexString(value) {
|
|
2006
|
+
return typeof value === "string" && HEX_STRING_REGEX.test(value);
|
|
2007
|
+
}
|
|
2008
|
+
|
|
2009
|
+
// src/provider.ts
|
|
2001
2010
|
function _getAddress() {
|
|
2002
2011
|
if (typeof window === "undefined") return void 0;
|
|
2003
2012
|
return window.__worldapp_eip1193_address__;
|
|
@@ -2013,12 +2022,6 @@ function _setAddress(addr) {
|
|
|
2013
2022
|
function rpcError(code, message) {
|
|
2014
2023
|
return Object.assign(new Error(message), { code });
|
|
2015
2024
|
}
|
|
2016
|
-
function isHexString(value) {
|
|
2017
|
-
return /^0x[0-9a-fA-F]*$/.test(value);
|
|
2018
|
-
}
|
|
2019
|
-
function isAddressString(value) {
|
|
2020
|
-
return /^0x[0-9a-fA-F]{40}$/.test(value);
|
|
2021
|
-
}
|
|
2022
2025
|
function decodeHexToUtf8(hex) {
|
|
2023
2026
|
const raw = hex.slice(2);
|
|
2024
2027
|
if (raw.length % 2 !== 0) {
|
|
@@ -2050,7 +2053,7 @@ function extractPersonalSignMessage(params) {
|
|
|
2050
2053
|
throw new Error("Missing personal_sign params");
|
|
2051
2054
|
}
|
|
2052
2055
|
const [first, second] = items;
|
|
2053
|
-
const maybeMessage = typeof first === "string" &&
|
|
2056
|
+
const maybeMessage = typeof first === "string" && isHexAddress(first) && typeof second === "string" ? second : first;
|
|
2054
2057
|
if (typeof maybeMessage !== "string") {
|
|
2055
2058
|
throw new Error("Invalid personal_sign message payload");
|
|
2056
2059
|
}
|
|
@@ -2062,7 +2065,7 @@ function extractEthSignMessage(params) {
|
|
|
2062
2065
|
throw new Error("Missing eth_sign params");
|
|
2063
2066
|
}
|
|
2064
2067
|
const [first, second] = items;
|
|
2065
|
-
const maybeMessage = typeof second === "string" ? second : typeof first === "string" && !
|
|
2068
|
+
const maybeMessage = typeof second === "string" ? second : typeof first === "string" && !isHexAddress(first) ? first : void 0;
|
|
2066
2069
|
if (typeof maybeMessage !== "string") {
|
|
2067
2070
|
throw new Error("Invalid eth_sign message payload");
|
|
2068
2071
|
}
|
|
@@ -2099,7 +2102,7 @@ function normalizeRpcValue(value) {
|
|
|
2099
2102
|
function extractTransactionParams(params) {
|
|
2100
2103
|
const items = asArrayParams(params);
|
|
2101
2104
|
const tx = items[0] ?? {};
|
|
2102
|
-
if (typeof tx.to !== "string" || !
|
|
2105
|
+
if (typeof tx.to !== "string" || !isHexAddress(tx.to)) {
|
|
2103
2106
|
throw new Error('Invalid transaction "to" address');
|
|
2104
2107
|
}
|
|
2105
2108
|
const chainId = typeof tx.chainId === "string" ? Number(tx.chainId) : typeof tx.chainId === "number" ? tx.chainId : void 0;
|
package/build/index.js
CHANGED
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getWorldAppProvider
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-MXMNPAOF.js";
|
|
4
4
|
import {
|
|
5
5
|
MiniKit
|
|
6
|
-
} from "./chunk-
|
|
7
|
-
import "./chunk-
|
|
8
|
-
import "./chunk-
|
|
6
|
+
} from "./chunk-7RB4UJBW.js";
|
|
7
|
+
import "./chunk-AH3WTRZY.js";
|
|
8
|
+
import "./chunk-YPZEODWL.js";
|
|
9
|
+
import "./chunk-2ADHLH4F.js";
|
|
10
|
+
import "./chunk-DZ2YRSIU.js";
|
|
9
11
|
export {
|
|
10
12
|
MiniKit,
|
|
11
13
|
getWorldAppProvider
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
"use client";
|
|
3
|
-
var __create = Object.create;
|
|
4
3
|
var __defProp = Object.defineProperty;
|
|
5
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
8
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
7
|
var __export = (target, all) => {
|
|
10
8
|
for (var name in all)
|
|
@@ -18,14 +16,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
16
|
}
|
|
19
17
|
return to;
|
|
20
18
|
};
|
|
21
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
-
mod
|
|
28
|
-
));
|
|
29
19
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
20
|
|
|
31
21
|
// src/minikit-provider.tsx
|
|
@@ -37,279 +27,8 @@ __export(minikit_provider_exports, {
|
|
|
37
27
|
module.exports = __toCommonJS(minikit_provider_exports);
|
|
38
28
|
var import_react = require("react");
|
|
39
29
|
|
|
40
|
-
// src/
|
|
41
|
-
var
|
|
42
|
-
function setFallbackAdapter(adapter) {
|
|
43
|
-
globalThis[FALLBACK_ADAPTER_KEY] = adapter;
|
|
44
|
-
}
|
|
45
|
-
function getFallbackAdapter() {
|
|
46
|
-
return globalThis[FALLBACK_ADAPTER_KEY];
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// src/commands/wagmi-fallback.ts
|
|
50
|
-
var SIWE_NONCE_REGEX = /^[a-zA-Z0-9]{8,}$/;
|
|
51
|
-
var WAGMI_KEY = "__minikit_wagmi_config__";
|
|
52
|
-
function setWagmiConfig(config) {
|
|
53
|
-
globalThis[WAGMI_KEY] = config;
|
|
54
|
-
registerWagmiFallbacks();
|
|
55
|
-
}
|
|
56
|
-
function getWagmiConfig() {
|
|
57
|
-
return globalThis[WAGMI_KEY];
|
|
58
|
-
}
|
|
59
|
-
function hasWagmiConfig() {
|
|
60
|
-
return globalThis[WAGMI_KEY] !== void 0;
|
|
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
|
-
}
|
|
118
|
-
async function ensureConnected(config) {
|
|
119
|
-
const { connect, getConnections } = await loadWagmiActions();
|
|
120
|
-
const isWorldApp = typeof window !== "undefined" && Boolean(window.WorldApp);
|
|
121
|
-
const existingConnection = getConnections(config).find(
|
|
122
|
-
(connection) => connection.accounts && connection.accounts.length > 0 && (isWorldApp || connection.connector?.id !== "worldApp")
|
|
123
|
-
);
|
|
124
|
-
if (existingConnection && existingConnection.accounts) {
|
|
125
|
-
return checksumAddress(existingConnection.accounts[0]);
|
|
126
|
-
}
|
|
127
|
-
const connectors = config.connectors;
|
|
128
|
-
if (!connectors || connectors.length === 0) {
|
|
129
|
-
throw new Error("No Wagmi connectors configured");
|
|
130
|
-
}
|
|
131
|
-
const candidateConnectors = isWorldApp ? connectors : connectors.filter(
|
|
132
|
-
(connector) => connector.id !== "worldApp"
|
|
133
|
-
);
|
|
134
|
-
if (!isWorldApp && candidateConnectors.length === 0) {
|
|
135
|
-
throw new Error(
|
|
136
|
-
"No web Wagmi connectors configured. Add a web connector (e.g. injected or walletConnect) after worldApp()."
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
const selectedConnector = candidateConnectors[0];
|
|
140
|
-
try {
|
|
141
|
-
const result = await connect(config, { connector: selectedConnector });
|
|
142
|
-
if (result.accounts.length > 0) {
|
|
143
|
-
const account = result.accounts[0];
|
|
144
|
-
const address = typeof account === "string" ? account : account.address;
|
|
145
|
-
if (address) {
|
|
146
|
-
return checksumAddress(address);
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
} catch (error) {
|
|
150
|
-
const connectorId = selectedConnector.id ?? "unknown";
|
|
151
|
-
const wrappedError = new Error(
|
|
152
|
-
`Failed to connect with connector "${connectorId}". Reorder connectors to change the default connector.`
|
|
153
|
-
);
|
|
154
|
-
wrappedError.cause = error;
|
|
155
|
-
throw wrappedError;
|
|
156
|
-
}
|
|
157
|
-
throw new Error("Failed to connect wallet");
|
|
158
|
-
}
|
|
159
|
-
async function wagmiWalletAuth(params) {
|
|
160
|
-
console.log("[MiniKit WagmiFallback] walletAuth:start", {
|
|
161
|
-
hasWagmiConfig: hasWagmiConfig(),
|
|
162
|
-
nonceLength: params.nonce?.length ?? 0
|
|
163
|
-
});
|
|
164
|
-
const config = getWagmiConfig();
|
|
165
|
-
if (!config) {
|
|
166
|
-
console.log("[MiniKit WagmiFallback] walletAuth:error:no-config");
|
|
167
|
-
throw new Error(
|
|
168
|
-
"Wagmi config not available. Pass wagmiConfig to MiniKitProvider."
|
|
169
|
-
);
|
|
170
|
-
}
|
|
171
|
-
const { signMessage: signMessage2 } = await loadWagmiActions();
|
|
172
|
-
const { SiweMessage } = await loadSiwe();
|
|
173
|
-
const address = await ensureConnected(config);
|
|
174
|
-
if (!SIWE_NONCE_REGEX.test(params.nonce)) {
|
|
175
|
-
throw new Error(
|
|
176
|
-
"Invalid nonce: must be alphanumeric and at least 8 characters (EIP-4361)"
|
|
177
|
-
);
|
|
178
|
-
}
|
|
179
|
-
const siweMessage = new SiweMessage({
|
|
180
|
-
domain: typeof window !== "undefined" ? window.location.host : "localhost",
|
|
181
|
-
address,
|
|
182
|
-
statement: params.statement,
|
|
183
|
-
uri: typeof window !== "undefined" ? window.location.origin : "http://localhost",
|
|
184
|
-
version: "1",
|
|
185
|
-
chainId: 480,
|
|
186
|
-
// World Chain
|
|
187
|
-
nonce: params.nonce,
|
|
188
|
-
expirationTime: params.expirationTime?.toISOString()
|
|
189
|
-
});
|
|
190
|
-
const message = siweMessage.prepareMessage();
|
|
191
|
-
const signature = await signMessage2(config, { message });
|
|
192
|
-
return {
|
|
193
|
-
address,
|
|
194
|
-
message,
|
|
195
|
-
signature
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
async function wagmiSignMessage(params) {
|
|
199
|
-
console.log("[MiniKit WagmiFallback] signMessage:start", {
|
|
200
|
-
hasWagmiConfig: hasWagmiConfig()
|
|
201
|
-
});
|
|
202
|
-
const config = getWagmiConfig();
|
|
203
|
-
if (!config) {
|
|
204
|
-
console.log("[MiniKit WagmiFallback] signMessage:error:no-config");
|
|
205
|
-
throw new Error(
|
|
206
|
-
"Wagmi config not available. Pass wagmiConfig to MiniKitProvider."
|
|
207
|
-
);
|
|
208
|
-
}
|
|
209
|
-
const { signMessage: signMessage2 } = await loadWagmiActions();
|
|
210
|
-
const address = await ensureConnected(config);
|
|
211
|
-
const signature = await signMessage2(config, {
|
|
212
|
-
account: address,
|
|
213
|
-
message: params.message
|
|
214
|
-
});
|
|
215
|
-
return {
|
|
216
|
-
status: "success",
|
|
217
|
-
version: 1,
|
|
218
|
-
signature,
|
|
219
|
-
address
|
|
220
|
-
};
|
|
221
|
-
}
|
|
222
|
-
async function wagmiSignTypedData(params) {
|
|
223
|
-
console.log("[MiniKit WagmiFallback] signTypedData:start", {
|
|
224
|
-
hasWagmiConfig: hasWagmiConfig(),
|
|
225
|
-
hasChainId: params.chainId !== void 0
|
|
226
|
-
});
|
|
227
|
-
const config = getWagmiConfig();
|
|
228
|
-
if (!config) {
|
|
229
|
-
console.log("[MiniKit WagmiFallback] signTypedData:error:no-config");
|
|
230
|
-
throw new Error(
|
|
231
|
-
"Wagmi config not available. Pass wagmiConfig to MiniKitProvider."
|
|
232
|
-
);
|
|
233
|
-
}
|
|
234
|
-
const { getChainId, signTypedData: signTypedData2, switchChain } = await loadWagmiActions();
|
|
235
|
-
const address = await ensureConnected(config);
|
|
236
|
-
if (params.chainId !== void 0) {
|
|
237
|
-
const currentChainId = await getChainId(config);
|
|
238
|
-
if (currentChainId !== params.chainId) {
|
|
239
|
-
await switchChain(config, { chainId: params.chainId });
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
const signature = await signTypedData2(config, {
|
|
243
|
-
account: address,
|
|
244
|
-
types: params.types,
|
|
245
|
-
primaryType: params.primaryType,
|
|
246
|
-
domain: params.domain,
|
|
247
|
-
message: params.message
|
|
248
|
-
});
|
|
249
|
-
return {
|
|
250
|
-
status: "success",
|
|
251
|
-
version: 1,
|
|
252
|
-
signature,
|
|
253
|
-
address
|
|
254
|
-
};
|
|
255
|
-
}
|
|
256
|
-
function isChainMismatchError(error) {
|
|
257
|
-
const message = error instanceof Error ? error.message : String(error);
|
|
258
|
-
return message.includes("does not match the target chain");
|
|
259
|
-
}
|
|
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
|
-
});
|
|
266
|
-
const config = getWagmiConfig();
|
|
267
|
-
if (!config) {
|
|
268
|
-
console.log("[MiniKit WagmiFallback] sendTransaction:error:no-config");
|
|
269
|
-
throw new Error(
|
|
270
|
-
"Wagmi config not available. Pass wagmiConfig to MiniKitProvider."
|
|
271
|
-
);
|
|
272
|
-
}
|
|
273
|
-
const { getChainId, getWalletClient, sendTransaction: sendTransaction2, switchChain } = await loadWagmiActions();
|
|
274
|
-
await ensureConnected(config);
|
|
275
|
-
const targetChainId = params.chainId ?? config.chains?.[0]?.id;
|
|
276
|
-
const ensureTargetChain = async () => {
|
|
277
|
-
if (targetChainId === void 0) return;
|
|
278
|
-
const currentChainId = await getChainId(config);
|
|
279
|
-
if (currentChainId !== targetChainId) {
|
|
280
|
-
await switchChain(config, { chainId: targetChainId });
|
|
281
|
-
}
|
|
282
|
-
const walletClient = await getWalletClient(config);
|
|
283
|
-
const providerChainId = walletClient ? await walletClient.getChainId() : await getChainId(config);
|
|
284
|
-
if (providerChainId !== targetChainId) {
|
|
285
|
-
throw new Error(
|
|
286
|
-
`Wallet network mismatch: expected chain ${targetChainId}, got ${providerChainId}. Please switch networks in your wallet and retry.`
|
|
287
|
-
);
|
|
288
|
-
}
|
|
289
|
-
};
|
|
290
|
-
await ensureTargetChain();
|
|
291
|
-
let transactionHash;
|
|
292
|
-
try {
|
|
293
|
-
transactionHash = await sendTransaction2(config, {
|
|
294
|
-
chainId: targetChainId,
|
|
295
|
-
to: params.transaction.address,
|
|
296
|
-
data: params.transaction.data,
|
|
297
|
-
value: params.transaction.value ? BigInt(params.transaction.value) : void 0
|
|
298
|
-
});
|
|
299
|
-
} catch (error) {
|
|
300
|
-
if (targetChainId === void 0 || !isChainMismatchError(error)) {
|
|
301
|
-
throw error;
|
|
302
|
-
}
|
|
303
|
-
await ensureTargetChain();
|
|
304
|
-
transactionHash = await sendTransaction2(config, {
|
|
305
|
-
chainId: targetChainId,
|
|
306
|
-
to: params.transaction.address,
|
|
307
|
-
data: params.transaction.data,
|
|
308
|
-
value: params.transaction.value ? BigInt(params.transaction.value) : void 0
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
return { transactionHash };
|
|
312
|
-
}
|
|
30
|
+
// src/global-keys.ts
|
|
31
|
+
var WAGMI_INSTALL_HOOK_KEY = "__minikit_install_wagmi_fallback__";
|
|
313
32
|
|
|
314
33
|
// src/commands/types.ts
|
|
315
34
|
var COMMAND_VERSIONS = {
|
|
@@ -458,6 +177,14 @@ var EventManager = class {
|
|
|
458
177
|
};
|
|
459
178
|
|
|
460
179
|
// src/commands/fallback.ts
|
|
180
|
+
var PartialExecutionError = class extends Error {
|
|
181
|
+
constructor(message, submitted, cause) {
|
|
182
|
+
super(message);
|
|
183
|
+
this.name = "PartialExecutionError";
|
|
184
|
+
this.submitted = submitted;
|
|
185
|
+
this.cause = cause;
|
|
186
|
+
}
|
|
187
|
+
};
|
|
461
188
|
async function executeWithFallback(options) {
|
|
462
189
|
const {
|
|
463
190
|
command,
|
|
@@ -483,6 +210,9 @@ async function executeWithFallback(options) {
|
|
|
483
210
|
const data = await wagmiFallback();
|
|
484
211
|
return { data, executedWith: "wagmi" };
|
|
485
212
|
} catch (error) {
|
|
213
|
+
if (error instanceof PartialExecutionError || error instanceof Error && error.name === "PartialExecutionError") {
|
|
214
|
+
throw error;
|
|
215
|
+
}
|
|
486
216
|
console.warn(`Wagmi fallback for ${command} failed:`, error);
|
|
487
217
|
}
|
|
488
218
|
}
|
|
@@ -930,6 +660,12 @@ async function nativeSendHapticFeedback(options, ctx) {
|
|
|
930
660
|
return payload;
|
|
931
661
|
}
|
|
932
662
|
|
|
663
|
+
// src/commands/fallback-adapter-registry.ts
|
|
664
|
+
var FALLBACK_ADAPTER_KEY = "__minikit_fallback_adapter__";
|
|
665
|
+
function getFallbackAdapter() {
|
|
666
|
+
return globalThis[FALLBACK_ADAPTER_KEY];
|
|
667
|
+
}
|
|
668
|
+
|
|
933
669
|
// src/commands/send-transaction/types.ts
|
|
934
670
|
var SendTransactionError = class extends Error {
|
|
935
671
|
constructor(code, details) {
|
|
@@ -1000,7 +736,6 @@ var validateSendTransactionPayload = (payload) => {
|
|
|
1000
736
|
|
|
1001
737
|
// src/commands/send-transaction/index.ts
|
|
1002
738
|
var WORLD_CHAIN_ID = 480;
|
|
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
739
|
function resolveChainId(options) {
|
|
1005
740
|
return options.chainId;
|
|
1006
741
|
}
|
|
@@ -1027,12 +762,6 @@ function normalizeSendTransactionOptions(options) {
|
|
|
1027
762
|
async function sendTransaction(options, ctx) {
|
|
1028
763
|
const normalizedOptions = normalizeSendTransactionOptions(options);
|
|
1029
764
|
const fallbackAdapter = getFallbackAdapter();
|
|
1030
|
-
const isWagmiFallbackPath = !isInWorldApp() && Boolean(fallbackAdapter?.sendTransaction);
|
|
1031
|
-
if (isWagmiFallbackPath && normalizedOptions.transactions.length > 1 && !options.fallback) {
|
|
1032
|
-
throw new SendTransactionError("invalid_operation" /* InvalidOperation */, {
|
|
1033
|
-
reason: WAGMI_MULTI_TX_ERROR_MESSAGE
|
|
1034
|
-
});
|
|
1035
|
-
}
|
|
1036
765
|
const result = await executeWithFallback({
|
|
1037
766
|
command: "send-transaction" /* SendTransaction */,
|
|
1038
767
|
nativeExecutor: () => nativeSendTransaction(normalizedOptions, ctx),
|
|
@@ -1113,23 +842,16 @@ async function nativeSendTransaction(options, ctx) {
|
|
|
1113
842
|
};
|
|
1114
843
|
}
|
|
1115
844
|
async function adapterSendTransactionFallback(options) {
|
|
1116
|
-
if (options.transactions.length > 1) {
|
|
1117
|
-
throw new Error(WAGMI_MULTI_TX_ERROR_MESSAGE);
|
|
1118
|
-
}
|
|
1119
|
-
const firstTransaction = options.transactions[0];
|
|
1120
|
-
if (!firstTransaction) {
|
|
1121
|
-
throw new Error("At least one transaction is required");
|
|
1122
|
-
}
|
|
1123
845
|
const fallbackAdapter = getFallbackAdapter();
|
|
1124
846
|
if (!fallbackAdapter?.sendTransaction) {
|
|
1125
847
|
throw new Error("Fallback adapter is not registered.");
|
|
1126
848
|
}
|
|
1127
849
|
const result = await fallbackAdapter.sendTransaction({
|
|
1128
|
-
|
|
1129
|
-
address:
|
|
1130
|
-
data:
|
|
1131
|
-
value:
|
|
1132
|
-
},
|
|
850
|
+
transactions: options.transactions.map((tx) => ({
|
|
851
|
+
address: tx.to,
|
|
852
|
+
data: tx.data,
|
|
853
|
+
value: tx.value
|
|
854
|
+
})),
|
|
1133
855
|
chainId: options.chainId
|
|
1134
856
|
});
|
|
1135
857
|
return {
|
|
@@ -1550,7 +1272,7 @@ var WalletAuthError = class extends Error {
|
|
|
1550
1272
|
};
|
|
1551
1273
|
|
|
1552
1274
|
// src/commands/wallet-auth/validate.ts
|
|
1553
|
-
var
|
|
1275
|
+
var SIWE_NONCE_REGEX = /^[a-zA-Z0-9]+$/;
|
|
1554
1276
|
var validateWalletAuthCommandInput = (params) => {
|
|
1555
1277
|
if (!params.nonce) {
|
|
1556
1278
|
return { valid: false, message: "'nonce' is required" };
|
|
@@ -1558,7 +1280,7 @@ var validateWalletAuthCommandInput = (params) => {
|
|
|
1558
1280
|
if (params.nonce.length < 8) {
|
|
1559
1281
|
return { valid: false, message: "'nonce' must be at least 8 characters" };
|
|
1560
1282
|
}
|
|
1561
|
-
if (!
|
|
1283
|
+
if (!SIWE_NONCE_REGEX.test(params.nonce)) {
|
|
1562
1284
|
return {
|
|
1563
1285
|
valid: false,
|
|
1564
1286
|
message: "'nonce' must be alphanumeric (letters and numbers only)"
|
|
@@ -2298,8 +2020,14 @@ var MiniKitProvider = ({
|
|
|
2298
2020
|
setIsInstalled(success);
|
|
2299
2021
|
}, [props?.appId]);
|
|
2300
2022
|
(0, import_react.useEffect)(() => {
|
|
2301
|
-
if (wagmiConfig)
|
|
2302
|
-
|
|
2023
|
+
if (!wagmiConfig) return;
|
|
2024
|
+
const install = globalThis[WAGMI_INSTALL_HOOK_KEY];
|
|
2025
|
+
if (typeof install === "function") {
|
|
2026
|
+
install(wagmiConfig);
|
|
2027
|
+
} else {
|
|
2028
|
+
console.warn(
|
|
2029
|
+
'MiniKitProvider received wagmiConfig but the wagmi fallback module is not imported. Add this once in your app: import "@worldcoin/minikit-js/wagmi-fallback"'
|
|
2030
|
+
);
|
|
2303
2031
|
}
|
|
2304
2032
|
}, [wagmiConfig]);
|
|
2305
2033
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MiniKitContext.Provider, { value: { isInstalled }, children });
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import {
|
|
3
|
-
setWagmiConfig
|
|
4
|
-
} from "./chunk-OLN2PAHM.js";
|
|
5
2
|
import {
|
|
6
3
|
MiniKit
|
|
7
|
-
} from "./chunk-
|
|
8
|
-
import "./chunk-
|
|
9
|
-
import "./chunk-
|
|
4
|
+
} from "./chunk-7RB4UJBW.js";
|
|
5
|
+
import "./chunk-AH3WTRZY.js";
|
|
6
|
+
import "./chunk-YPZEODWL.js";
|
|
7
|
+
import {
|
|
8
|
+
WAGMI_INSTALL_HOOK_KEY
|
|
9
|
+
} from "./chunk-6E2XIIO6.js";
|
|
10
|
+
import "./chunk-DZ2YRSIU.js";
|
|
10
11
|
|
|
11
12
|
// src/minikit-provider.tsx
|
|
12
13
|
import {
|
|
@@ -36,8 +37,14 @@ var MiniKitProvider = ({
|
|
|
36
37
|
setIsInstalled(success);
|
|
37
38
|
}, [props?.appId]);
|
|
38
39
|
useEffect(() => {
|
|
39
|
-
if (wagmiConfig)
|
|
40
|
-
|
|
40
|
+
if (!wagmiConfig) return;
|
|
41
|
+
const install = globalThis[WAGMI_INSTALL_HOOK_KEY];
|
|
42
|
+
if (typeof install === "function") {
|
|
43
|
+
install(wagmiConfig);
|
|
44
|
+
} else {
|
|
45
|
+
console.warn(
|
|
46
|
+
'MiniKitProvider received wagmiConfig but the wagmi fallback module is not imported. Add this once in your app: import "@worldcoin/minikit-js/wagmi-fallback"'
|
|
47
|
+
);
|
|
41
48
|
}
|
|
42
49
|
}, [wagmiConfig]);
|
|
43
50
|
return /* @__PURE__ */ jsx(MiniKitContext.Provider, { value: { isInstalled }, children });
|
package/build/siwe-exports.cjs
CHANGED
|
@@ -186,11 +186,31 @@ var verifySiweMessageV2 = async (payload, nonce, statement, requestId, userProvi
|
|
|
186
186
|
if (!validateMessage(siweMessageData, nonce, statement, requestId)) {
|
|
187
187
|
throw new Error("Validation failed");
|
|
188
188
|
}
|
|
189
|
+
if (siweMessageData.address && siweMessageData.address.toLowerCase() !== address.toLowerCase()) {
|
|
190
|
+
throw new Error(
|
|
191
|
+
"Address mismatch: payload address does not match SIWE message address"
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
const expectedAddress = (siweMessageData.address ?? address).toLowerCase();
|
|
195
|
+
try {
|
|
196
|
+
const recoveredAddress = await (0, import_viem.recoverMessageAddress)({
|
|
197
|
+
message,
|
|
198
|
+
signature
|
|
199
|
+
});
|
|
200
|
+
if (recoveredAddress.toLowerCase() === expectedAddress) {
|
|
201
|
+
return {
|
|
202
|
+
isValid: true,
|
|
203
|
+
siweMessageData
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
} catch {
|
|
207
|
+
}
|
|
189
208
|
try {
|
|
209
|
+
const client = userProvider || (0, import_viem.createPublicClient)({ chain: import_chains.worldchain, transport: (0, import_viem.http)() });
|
|
190
210
|
const walletContract = (0, import_viem.getContract)({
|
|
191
211
|
address,
|
|
192
212
|
abi: SAFE_CONTRACT_ABI,
|
|
193
|
-
client
|
|
213
|
+
client
|
|
194
214
|
});
|
|
195
215
|
const hashedMessage = (0, import_viem.hashMessage)(message);
|
|
196
216
|
const res = await walletContract.read.isValidSignature([
|