@worldcoin/minikit-js 2.0.0-dev.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -1
- package/build/chunk-6SCI6OTQ.js +272 -0
- package/build/{chunk-LHHKY77D.js → chunk-IYL4VCWR.js} +7 -40
- package/build/chunk-QOFVDR5F.js +279 -0
- package/build/{chunk-OTAA7OOI.js → chunk-QOLIACKU.js} +30 -269
- package/build/{chunk-DIACPBCB.js → chunk-XHYUUG6Y.js} +248 -301
- package/build/command-exports.cjs +238 -297
- package/build/command-exports.d.cts +14 -11
- package/build/command-exports.d.ts +14 -11
- package/build/command-exports.js +10 -2
- package/build/connector/index.cjs +339 -122
- package/build/connector/index.js +9 -5
- package/build/index.cjs +250 -309
- package/build/index.d.cts +16 -7
- package/build/index.d.ts +16 -7
- package/build/index.js +6 -4
- package/build/minikit-provider.cjs +318 -125
- package/build/minikit-provider.js +9 -2040
- package/build/siwe-exports.cjs +6 -38
- package/build/siwe-exports.d.cts +1 -1
- package/build/siwe-exports.d.ts +1 -1
- package/build/siwe-exports.js +1 -1
- package/build/{types-DO2UGrgp.d.cts → types-CC2x79HX.d.ts} +125 -38
- package/build/{types-CKn5C-Ro.d.cts → types-CSyzFDPt.d.cts} +4 -1
- package/build/{types-CKn5C-Ro.d.ts → types-CSyzFDPt.d.ts} +4 -1
- package/build/{types-CGVVuGiN.d.ts → types-_jfLbcJW.d.cts} +125 -38
- package/package.json +12 -13
|
@@ -34,11 +34,21 @@ __export(connector_exports, {
|
|
|
34
34
|
});
|
|
35
35
|
module.exports = __toCommonJS(connector_exports);
|
|
36
36
|
|
|
37
|
+
// src/commands/fallback-adapter-registry.ts
|
|
38
|
+
var FALLBACK_ADAPTER_KEY = "__minikit_fallback_adapter__";
|
|
39
|
+
function setFallbackAdapter(adapter) {
|
|
40
|
+
globalThis[FALLBACK_ADAPTER_KEY] = adapter;
|
|
41
|
+
}
|
|
42
|
+
function getFallbackAdapter() {
|
|
43
|
+
return globalThis[FALLBACK_ADAPTER_KEY];
|
|
44
|
+
}
|
|
45
|
+
|
|
37
46
|
// src/commands/wagmi-fallback.ts
|
|
38
47
|
var SIWE_NONCE_REGEX = /^[a-zA-Z0-9]{8,}$/;
|
|
39
48
|
var WAGMI_KEY = "__minikit_wagmi_config__";
|
|
40
49
|
function setWagmiConfig(config) {
|
|
41
50
|
globalThis[WAGMI_KEY] = config;
|
|
51
|
+
registerWagmiFallbacks();
|
|
42
52
|
}
|
|
43
53
|
function getWagmiConfig() {
|
|
44
54
|
return globalThis[WAGMI_KEY];
|
|
@@ -46,14 +56,70 @@ function getWagmiConfig() {
|
|
|
46
56
|
function hasWagmiConfig() {
|
|
47
57
|
return globalThis[WAGMI_KEY] !== void 0;
|
|
48
58
|
}
|
|
59
|
+
function registerWagmiFallbacks() {
|
|
60
|
+
setFallbackAdapter({
|
|
61
|
+
walletAuth: wagmiWalletAuth,
|
|
62
|
+
signMessage: wagmiSignMessage,
|
|
63
|
+
signTypedData: wagmiSignTypedData,
|
|
64
|
+
sendTransaction: wagmiSendTransaction
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
async function loadWagmiActions() {
|
|
68
|
+
console.log("[MiniKit WagmiFallback] loadWagmiActions:start", {
|
|
69
|
+
hasWindow: typeof window !== "undefined",
|
|
70
|
+
hasWagmiConfig: hasWagmiConfig()
|
|
71
|
+
});
|
|
72
|
+
try {
|
|
73
|
+
const actions = await import(
|
|
74
|
+
/* webpackIgnore: true */
|
|
75
|
+
"wagmi/actions"
|
|
76
|
+
);
|
|
77
|
+
console.log("[MiniKit WagmiFallback] loadWagmiActions:success");
|
|
78
|
+
return actions;
|
|
79
|
+
} catch (error) {
|
|
80
|
+
console.log("[MiniKit WagmiFallback] loadWagmiActions:error", {
|
|
81
|
+
message: error instanceof Error ? error.message : String(error)
|
|
82
|
+
});
|
|
83
|
+
const wrappedError = new Error(
|
|
84
|
+
'Wagmi fallback requires the "wagmi" package. Install wagmi or provide a custom fallback.'
|
|
85
|
+
);
|
|
86
|
+
wrappedError.cause = error;
|
|
87
|
+
throw wrappedError;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
async function loadSiwe() {
|
|
91
|
+
try {
|
|
92
|
+
return await import(
|
|
93
|
+
/* webpackIgnore: true */
|
|
94
|
+
"siwe"
|
|
95
|
+
);
|
|
96
|
+
} catch (error) {
|
|
97
|
+
const wrappedError = new Error(
|
|
98
|
+
'Wagmi walletAuth fallback requires the "siwe" package. Install siwe or provide a custom fallback.'
|
|
99
|
+
);
|
|
100
|
+
wrappedError.cause = error;
|
|
101
|
+
throw wrappedError;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
async function checksumAddress(addr) {
|
|
105
|
+
try {
|
|
106
|
+
const { getAddress: getAddress2 } = await import(
|
|
107
|
+
/* webpackIgnore: true */
|
|
108
|
+
"viem"
|
|
109
|
+
);
|
|
110
|
+
return getAddress2(addr);
|
|
111
|
+
} catch {
|
|
112
|
+
return addr;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
49
115
|
async function ensureConnected(config) {
|
|
50
|
-
const { connect, getConnections } = await
|
|
116
|
+
const { connect, getConnections } = await loadWagmiActions();
|
|
51
117
|
const isWorldApp = typeof window !== "undefined" && Boolean(window.WorldApp);
|
|
52
118
|
const existingConnection = getConnections(config).find(
|
|
53
119
|
(connection) => connection.accounts && connection.accounts.length > 0 && (isWorldApp || connection.connector?.id !== "worldApp")
|
|
54
120
|
);
|
|
55
121
|
if (existingConnection && existingConnection.accounts) {
|
|
56
|
-
return existingConnection.accounts[0];
|
|
122
|
+
return checksumAddress(existingConnection.accounts[0]);
|
|
57
123
|
}
|
|
58
124
|
const connectors = config.connectors;
|
|
59
125
|
if (!connectors || connectors.length === 0) {
|
|
@@ -74,7 +140,7 @@ async function ensureConnected(config) {
|
|
|
74
140
|
const account = result.accounts[0];
|
|
75
141
|
const address = typeof account === "string" ? account : account.address;
|
|
76
142
|
if (address) {
|
|
77
|
-
return address;
|
|
143
|
+
return checksumAddress(address);
|
|
78
144
|
}
|
|
79
145
|
}
|
|
80
146
|
} catch (error) {
|
|
@@ -88,14 +154,19 @@ async function ensureConnected(config) {
|
|
|
88
154
|
throw new Error("Failed to connect wallet");
|
|
89
155
|
}
|
|
90
156
|
async function wagmiWalletAuth(params) {
|
|
157
|
+
console.log("[MiniKit WagmiFallback] walletAuth:start", {
|
|
158
|
+
hasWagmiConfig: hasWagmiConfig(),
|
|
159
|
+
nonceLength: params.nonce?.length ?? 0
|
|
160
|
+
});
|
|
91
161
|
const config = getWagmiConfig();
|
|
92
162
|
if (!config) {
|
|
163
|
+
console.log("[MiniKit WagmiFallback] walletAuth:error:no-config");
|
|
93
164
|
throw new Error(
|
|
94
165
|
"Wagmi config not available. Pass wagmiConfig to MiniKitProvider."
|
|
95
166
|
);
|
|
96
167
|
}
|
|
97
|
-
const { signMessage: signMessage2 } = await
|
|
98
|
-
const { SiweMessage } = await
|
|
168
|
+
const { signMessage: signMessage2 } = await loadWagmiActions();
|
|
169
|
+
const { SiweMessage } = await loadSiwe();
|
|
99
170
|
const address = await ensureConnected(config);
|
|
100
171
|
if (!SIWE_NONCE_REGEX.test(params.nonce)) {
|
|
101
172
|
throw new Error(
|
|
@@ -122,13 +193,17 @@ async function wagmiWalletAuth(params) {
|
|
|
122
193
|
};
|
|
123
194
|
}
|
|
124
195
|
async function wagmiSignMessage(params) {
|
|
196
|
+
console.log("[MiniKit WagmiFallback] signMessage:start", {
|
|
197
|
+
hasWagmiConfig: hasWagmiConfig()
|
|
198
|
+
});
|
|
125
199
|
const config = getWagmiConfig();
|
|
126
200
|
if (!config) {
|
|
201
|
+
console.log("[MiniKit WagmiFallback] signMessage:error:no-config");
|
|
127
202
|
throw new Error(
|
|
128
203
|
"Wagmi config not available. Pass wagmiConfig to MiniKitProvider."
|
|
129
204
|
);
|
|
130
205
|
}
|
|
131
|
-
const { signMessage: signMessage2 } = await
|
|
206
|
+
const { signMessage: signMessage2 } = await loadWagmiActions();
|
|
132
207
|
const address = await ensureConnected(config);
|
|
133
208
|
const signature = await signMessage2(config, {
|
|
134
209
|
account: address,
|
|
@@ -142,13 +217,18 @@ async function wagmiSignMessage(params) {
|
|
|
142
217
|
};
|
|
143
218
|
}
|
|
144
219
|
async function wagmiSignTypedData(params) {
|
|
220
|
+
console.log("[MiniKit WagmiFallback] signTypedData:start", {
|
|
221
|
+
hasWagmiConfig: hasWagmiConfig(),
|
|
222
|
+
hasChainId: params.chainId !== void 0
|
|
223
|
+
});
|
|
145
224
|
const config = getWagmiConfig();
|
|
146
225
|
if (!config) {
|
|
226
|
+
console.log("[MiniKit WagmiFallback] signTypedData:error:no-config");
|
|
147
227
|
throw new Error(
|
|
148
228
|
"Wagmi config not available. Pass wagmiConfig to MiniKitProvider."
|
|
149
229
|
);
|
|
150
230
|
}
|
|
151
|
-
const { getChainId, signTypedData: signTypedData2, switchChain } = await
|
|
231
|
+
const { getChainId, signTypedData: signTypedData2, switchChain } = await loadWagmiActions();
|
|
152
232
|
const address = await ensureConnected(config);
|
|
153
233
|
if (params.chainId !== void 0) {
|
|
154
234
|
const currentChainId = await getChainId(config);
|
|
@@ -175,13 +255,19 @@ function isChainMismatchError(error) {
|
|
|
175
255
|
return message.includes("does not match the target chain");
|
|
176
256
|
}
|
|
177
257
|
async function wagmiSendTransaction(params) {
|
|
258
|
+
console.log("[MiniKit WagmiFallback] sendTransaction:start", {
|
|
259
|
+
hasWagmiConfig: hasWagmiConfig(),
|
|
260
|
+
chainId: params.chainId,
|
|
261
|
+
hasData: Boolean(params.transaction.data)
|
|
262
|
+
});
|
|
178
263
|
const config = getWagmiConfig();
|
|
179
264
|
if (!config) {
|
|
265
|
+
console.log("[MiniKit WagmiFallback] sendTransaction:error:no-config");
|
|
180
266
|
throw new Error(
|
|
181
267
|
"Wagmi config not available. Pass wagmiConfig to MiniKitProvider."
|
|
182
268
|
);
|
|
183
269
|
}
|
|
184
|
-
const { getChainId, getWalletClient, sendTransaction: sendTransaction2, switchChain } = await
|
|
270
|
+
const { getChainId, getWalletClient, sendTransaction: sendTransaction2, switchChain } = await loadWagmiActions();
|
|
185
271
|
await ensureConnected(config);
|
|
186
272
|
const targetChainId = params.chainId ?? config.chains?.[0]?.id;
|
|
187
273
|
const ensureTargetChain = async () => {
|
|
@@ -224,9 +310,10 @@ async function wagmiSendTransaction(params) {
|
|
|
224
310
|
|
|
225
311
|
// src/commands/types.ts
|
|
226
312
|
var COMMAND_VERSIONS = {
|
|
313
|
+
["attestation" /* Attestation */]: 1,
|
|
227
314
|
["pay" /* Pay */]: 1,
|
|
228
315
|
["wallet-auth" /* WalletAuth */]: 2,
|
|
229
|
-
["send-transaction" /* SendTransaction */]:
|
|
316
|
+
["send-transaction" /* SendTransaction */]: 2,
|
|
230
317
|
["sign-message" /* SignMessage */]: 1,
|
|
231
318
|
["sign-typed-data" /* SignTypedData */]: 1,
|
|
232
319
|
["share-contacts" /* ShareContacts */]: 1,
|
|
@@ -234,9 +321,11 @@ var COMMAND_VERSIONS = {
|
|
|
234
321
|
["get-permissions" /* GetPermissions */]: 1,
|
|
235
322
|
["send-haptic-feedback" /* SendHapticFeedback */]: 1,
|
|
236
323
|
["share" /* Share */]: 1,
|
|
237
|
-
["chat" /* Chat */]: 1
|
|
324
|
+
["chat" /* Chat */]: 1,
|
|
325
|
+
["close-miniapp" /* CloseMiniApp */]: 1
|
|
238
326
|
};
|
|
239
327
|
var commandAvailability = {
|
|
328
|
+
["attestation" /* Attestation */]: false,
|
|
240
329
|
["pay" /* Pay */]: false,
|
|
241
330
|
["wallet-auth" /* WalletAuth */]: false,
|
|
242
331
|
["send-transaction" /* SendTransaction */]: false,
|
|
@@ -247,7 +336,8 @@ var commandAvailability = {
|
|
|
247
336
|
["get-permissions" /* GetPermissions */]: false,
|
|
248
337
|
["send-haptic-feedback" /* SendHapticFeedback */]: false,
|
|
249
338
|
["share" /* Share */]: false,
|
|
250
|
-
["chat" /* Chat */]: false
|
|
339
|
+
["chat" /* Chat */]: false,
|
|
340
|
+
["close-miniapp" /* CloseMiniApp */]: false
|
|
251
341
|
};
|
|
252
342
|
function isCommandAvailable(command) {
|
|
253
343
|
return commandAvailability[command] ?? false;
|
|
@@ -319,6 +409,8 @@ var CommandUnavailableError = class extends Error {
|
|
|
319
409
|
var EventManager = class {
|
|
320
410
|
constructor() {
|
|
321
411
|
this.listeners = {
|
|
412
|
+
["miniapp-attestation" /* MiniAppAttestation */]: () => {
|
|
413
|
+
},
|
|
322
414
|
["miniapp-payment" /* MiniAppPayment */]: () => {
|
|
323
415
|
},
|
|
324
416
|
["miniapp-wallet-auth" /* MiniAppWalletAuth */]: () => {
|
|
@@ -383,7 +475,7 @@ async function executeWithFallback(options) {
|
|
|
383
475
|
console.warn(`Native ${command} failed, attempting fallback:`, error);
|
|
384
476
|
}
|
|
385
477
|
}
|
|
386
|
-
if (!inWorldApp && wagmiFallback
|
|
478
|
+
if (!inWorldApp && wagmiFallback) {
|
|
387
479
|
try {
|
|
388
480
|
const data = await wagmiFallback();
|
|
389
481
|
return { data, executedWith: "wagmi" };
|
|
@@ -391,7 +483,7 @@ async function executeWithFallback(options) {
|
|
|
391
483
|
console.warn(`Wagmi fallback for ${command} failed:`, error);
|
|
392
484
|
}
|
|
393
485
|
}
|
|
394
|
-
if (customFallback) {
|
|
486
|
+
if (!inWorldApp && customFallback) {
|
|
395
487
|
const data = await customFallback();
|
|
396
488
|
return { data, executedWith: "fallback" };
|
|
397
489
|
}
|
|
@@ -413,6 +505,67 @@ function determineFallbackReason(command) {
|
|
|
413
505
|
return "commandNotSupported";
|
|
414
506
|
}
|
|
415
507
|
|
|
508
|
+
// src/commands/attestation/types.ts
|
|
509
|
+
var AttestationError = class extends Error {
|
|
510
|
+
constructor(error_code) {
|
|
511
|
+
super(`Attestation failed: ${error_code}`);
|
|
512
|
+
this.error_code = error_code;
|
|
513
|
+
this.name = "AttestationError";
|
|
514
|
+
}
|
|
515
|
+
};
|
|
516
|
+
|
|
517
|
+
// src/commands/attestation/index.ts
|
|
518
|
+
async function attestation(options, ctx) {
|
|
519
|
+
const result = await executeWithFallback({
|
|
520
|
+
command: "attestation" /* Attestation */,
|
|
521
|
+
nativeExecutor: () => nativeAttestation(options, ctx),
|
|
522
|
+
customFallback: options.fallback
|
|
523
|
+
});
|
|
524
|
+
if (result.executedWith === "fallback") {
|
|
525
|
+
return { executedWith: "fallback", data: result.data };
|
|
526
|
+
}
|
|
527
|
+
return {
|
|
528
|
+
executedWith: "minikit",
|
|
529
|
+
data: result.data
|
|
530
|
+
};
|
|
531
|
+
}
|
|
532
|
+
async function nativeAttestation(options, ctx) {
|
|
533
|
+
if (!ctx) {
|
|
534
|
+
ctx = { events: new EventManager(), state: { deviceProperties: {} } };
|
|
535
|
+
}
|
|
536
|
+
if (typeof window === "undefined" || !isCommandAvailable("attestation" /* Attestation */)) {
|
|
537
|
+
throw new Error(
|
|
538
|
+
"'attestation' command is unavailable. Check MiniKit.install() or update the app version"
|
|
539
|
+
);
|
|
540
|
+
}
|
|
541
|
+
if (!options.requestHash || options.requestHash.length === 0) {
|
|
542
|
+
throw new Error("'attestation' command requires a non-empty requestHash");
|
|
543
|
+
}
|
|
544
|
+
const payload = await new Promise(
|
|
545
|
+
(resolve, reject) => {
|
|
546
|
+
try {
|
|
547
|
+
ctx.events.subscribe("miniapp-attestation" /* MiniAppAttestation */, (response) => {
|
|
548
|
+
ctx.events.unsubscribe("miniapp-attestation" /* MiniAppAttestation */);
|
|
549
|
+
resolve(response);
|
|
550
|
+
});
|
|
551
|
+
sendMiniKitEvent({
|
|
552
|
+
command: "attestation" /* Attestation */,
|
|
553
|
+
version: COMMAND_VERSIONS["attestation" /* Attestation */],
|
|
554
|
+
payload: {
|
|
555
|
+
request_hash: options.requestHash
|
|
556
|
+
}
|
|
557
|
+
});
|
|
558
|
+
} catch (error) {
|
|
559
|
+
reject(error);
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
);
|
|
563
|
+
if (payload.status === "error") {
|
|
564
|
+
throw new AttestationError(payload.error_code);
|
|
565
|
+
}
|
|
566
|
+
return payload;
|
|
567
|
+
}
|
|
568
|
+
|
|
416
569
|
// src/commands/chat/types.ts
|
|
417
570
|
var ChatError = class extends Error {
|
|
418
571
|
constructor(error_code) {
|
|
@@ -474,6 +627,38 @@ async function nativeChat(options, ctx) {
|
|
|
474
627
|
return payload;
|
|
475
628
|
}
|
|
476
629
|
|
|
630
|
+
// src/commands/close-miniapp/index.ts
|
|
631
|
+
async function closeMiniApp(options = {}, _ctx) {
|
|
632
|
+
const result = await executeWithFallback({
|
|
633
|
+
command: "close-miniapp" /* CloseMiniApp */,
|
|
634
|
+
nativeExecutor: () => nativeCloseMiniApp(),
|
|
635
|
+
customFallback: options.fallback
|
|
636
|
+
});
|
|
637
|
+
if (result.executedWith === "fallback") {
|
|
638
|
+
return { executedWith: "fallback", data: result.data };
|
|
639
|
+
}
|
|
640
|
+
return {
|
|
641
|
+
executedWith: "minikit",
|
|
642
|
+
data: result.data
|
|
643
|
+
};
|
|
644
|
+
}
|
|
645
|
+
async function nativeCloseMiniApp() {
|
|
646
|
+
if (typeof window === "undefined" || !isCommandAvailable("close-miniapp" /* CloseMiniApp */)) {
|
|
647
|
+
throw new Error(
|
|
648
|
+
"'closeMiniApp' command is unavailable. Check MiniKit.install() or update the app version"
|
|
649
|
+
);
|
|
650
|
+
}
|
|
651
|
+
sendMiniKitEvent({
|
|
652
|
+
command: "close-miniapp" /* CloseMiniApp */,
|
|
653
|
+
version: COMMAND_VERSIONS["close-miniapp" /* CloseMiniApp */],
|
|
654
|
+
payload: {}
|
|
655
|
+
});
|
|
656
|
+
return {
|
|
657
|
+
status: "success",
|
|
658
|
+
version: COMMAND_VERSIONS["close-miniapp" /* CloseMiniApp */]
|
|
659
|
+
};
|
|
660
|
+
}
|
|
661
|
+
|
|
477
662
|
// src/commands/get-permissions/types.ts
|
|
478
663
|
var GetPermissionsError = class extends Error {
|
|
479
664
|
constructor(error_code) {
|
|
@@ -742,9 +927,6 @@ async function nativeSendHapticFeedback(options, ctx) {
|
|
|
742
927
|
return payload;
|
|
743
928
|
}
|
|
744
929
|
|
|
745
|
-
// src/commands/send-transaction/index.ts
|
|
746
|
-
var import_viem = require("viem");
|
|
747
|
-
|
|
748
930
|
// src/commands/send-transaction/types.ts
|
|
749
931
|
var SendTransactionError = class extends Error {
|
|
750
932
|
constructor(code, details) {
|
|
@@ -759,16 +941,6 @@ var SendTransactionError = class extends Error {
|
|
|
759
941
|
var isValidHex = (str) => {
|
|
760
942
|
return /^0x[0-9A-Fa-f]+$/.test(str);
|
|
761
943
|
};
|
|
762
|
-
var objectValuesToArrayRecursive = (input) => {
|
|
763
|
-
if (input === null || typeof input !== "object") {
|
|
764
|
-
return input;
|
|
765
|
-
}
|
|
766
|
-
if (Array.isArray(input)) {
|
|
767
|
-
return input.map((item) => objectValuesToArrayRecursive(item));
|
|
768
|
-
}
|
|
769
|
-
const values = Object.values(input);
|
|
770
|
-
return values.map((value) => objectValuesToArrayRecursive(value));
|
|
771
|
-
};
|
|
772
944
|
var processPayload = (payload) => {
|
|
773
945
|
if (typeof payload === "boolean" || typeof payload === "string" || payload === null || payload === void 0) {
|
|
774
946
|
return payload;
|
|
@@ -781,6 +953,20 @@ var processPayload = (payload) => {
|
|
|
781
953
|
}
|
|
782
954
|
if (typeof payload === "object") {
|
|
783
955
|
const result = { ...payload };
|
|
956
|
+
if ("chainId" in result && result.chainId !== void 0) {
|
|
957
|
+
if (typeof result.chainId === "string") {
|
|
958
|
+
const parsed = Number(result.chainId);
|
|
959
|
+
if (Number.isFinite(parsed)) {
|
|
960
|
+
result.chainId = parsed;
|
|
961
|
+
}
|
|
962
|
+
} else if (typeof result.chainId === "bigint") {
|
|
963
|
+
const parsed = Number(result.chainId);
|
|
964
|
+
if (!Number.isSafeInteger(parsed)) {
|
|
965
|
+
throw new Error(`Invalid chainId: ${String(result.chainId)}`);
|
|
966
|
+
}
|
|
967
|
+
result.chainId = parsed;
|
|
968
|
+
}
|
|
969
|
+
}
|
|
784
970
|
if ("value" in result && result.value !== void 0) {
|
|
785
971
|
if (typeof result.value !== "string") {
|
|
786
972
|
result.value = String(result.value);
|
|
@@ -797,6 +983,7 @@ var processPayload = (payload) => {
|
|
|
797
983
|
}
|
|
798
984
|
for (const key in result) {
|
|
799
985
|
if (Object.prototype.hasOwnProperty.call(result, key)) {
|
|
986
|
+
if (key === "chainId") continue;
|
|
800
987
|
result[key] = processPayload(result[key]);
|
|
801
988
|
}
|
|
802
989
|
}
|
|
@@ -805,37 +992,48 @@ var processPayload = (payload) => {
|
|
|
805
992
|
return payload;
|
|
806
993
|
};
|
|
807
994
|
var validateSendTransactionPayload = (payload) => {
|
|
808
|
-
|
|
809
|
-
const formattedPayload = processPayload(payload);
|
|
810
|
-
formattedPayload.transaction = formattedPayload.transaction.map((tx) => {
|
|
811
|
-
if ("args" in tx && tx.args !== void 0) {
|
|
812
|
-
const args = objectValuesToArrayRecursive(tx.args);
|
|
813
|
-
return {
|
|
814
|
-
...tx,
|
|
815
|
-
args
|
|
816
|
-
};
|
|
817
|
-
}
|
|
818
|
-
return tx;
|
|
819
|
-
});
|
|
820
|
-
return formattedPayload;
|
|
821
|
-
}
|
|
822
|
-
return payload;
|
|
995
|
+
return processPayload(payload);
|
|
823
996
|
};
|
|
824
997
|
|
|
825
998
|
// src/commands/send-transaction/index.ts
|
|
826
999
|
var WORLD_CHAIN_ID = 480;
|
|
827
1000
|
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.";
|
|
1001
|
+
function resolveChainId(options) {
|
|
1002
|
+
return options.chainId;
|
|
1003
|
+
}
|
|
1004
|
+
function resolveTransactions(options) {
|
|
1005
|
+
if (options.transactions.length === 0) {
|
|
1006
|
+
throw new SendTransactionError("input_error" /* InputError */, {
|
|
1007
|
+
reason: "At least one transaction is required. Use `transactions: [{ to, data, value }]`."
|
|
1008
|
+
});
|
|
1009
|
+
}
|
|
1010
|
+
return options.transactions;
|
|
1011
|
+
}
|
|
1012
|
+
function normalizeSendTransactionOptions(options) {
|
|
1013
|
+
const chainId = resolveChainId(options);
|
|
1014
|
+
if (chainId !== WORLD_CHAIN_ID) {
|
|
1015
|
+
throw new SendTransactionError("invalid_operation" /* InvalidOperation */, {
|
|
1016
|
+
reason: `World App only supports World Chain (chainId: ${WORLD_CHAIN_ID})`
|
|
1017
|
+
});
|
|
1018
|
+
}
|
|
1019
|
+
return {
|
|
1020
|
+
transactions: resolveTransactions(options),
|
|
1021
|
+
chainId
|
|
1022
|
+
};
|
|
1023
|
+
}
|
|
828
1024
|
async function sendTransaction(options, ctx) {
|
|
829
|
-
const
|
|
830
|
-
|
|
1025
|
+
const normalizedOptions = normalizeSendTransactionOptions(options);
|
|
1026
|
+
const fallbackAdapter = getFallbackAdapter();
|
|
1027
|
+
const isWagmiFallbackPath = !isInWorldApp() && Boolean(fallbackAdapter?.sendTransaction);
|
|
1028
|
+
if (isWagmiFallbackPath && normalizedOptions.transactions.length > 1 && !options.fallback) {
|
|
831
1029
|
throw new SendTransactionError("invalid_operation" /* InvalidOperation */, {
|
|
832
1030
|
reason: WAGMI_MULTI_TX_ERROR_MESSAGE
|
|
833
1031
|
});
|
|
834
1032
|
}
|
|
835
1033
|
const result = await executeWithFallback({
|
|
836
1034
|
command: "send-transaction" /* SendTransaction */,
|
|
837
|
-
nativeExecutor: () => nativeSendTransaction(
|
|
838
|
-
wagmiFallback: () =>
|
|
1035
|
+
nativeExecutor: () => nativeSendTransaction(normalizedOptions, ctx),
|
|
1036
|
+
wagmiFallback: fallbackAdapter?.sendTransaction ? () => adapterSendTransactionFallback(normalizedOptions) : void 0,
|
|
839
1037
|
customFallback: options.fallback
|
|
840
1038
|
});
|
|
841
1039
|
if (result.executedWith === "fallback") {
|
|
@@ -861,15 +1059,22 @@ async function nativeSendTransaction(options, ctx) {
|
|
|
861
1059
|
"'sendTransaction' command is unavailable. Check MiniKit.install() or update the app version"
|
|
862
1060
|
);
|
|
863
1061
|
}
|
|
864
|
-
if (options.chainId !==
|
|
1062
|
+
if (options.chainId !== WORLD_CHAIN_ID) {
|
|
865
1063
|
throw new Error(
|
|
866
1064
|
`World App only supports World Chain (chainId: ${WORLD_CHAIN_ID})`
|
|
867
1065
|
);
|
|
868
1066
|
}
|
|
1067
|
+
const commandInput = window.WorldApp?.supported_commands.find(
|
|
1068
|
+
(command) => command.name === "send-transaction" /* SendTransaction */
|
|
1069
|
+
);
|
|
1070
|
+
if (commandInput && !commandInput.supported_versions.includes(
|
|
1071
|
+
COMMAND_VERSIONS["send-transaction" /* SendTransaction */]
|
|
1072
|
+
)) {
|
|
1073
|
+
throw new CommandUnavailableError("send-transaction" /* SendTransaction */, "oldAppVersion");
|
|
1074
|
+
}
|
|
869
1075
|
const input = {
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
formatPayload: options.formatPayload !== false
|
|
1076
|
+
transactions: options.transactions,
|
|
1077
|
+
chainId: options.chainId
|
|
873
1078
|
};
|
|
874
1079
|
const validatedPayload = validateSendTransactionPayload(input);
|
|
875
1080
|
const finalPayload = await new Promise(
|
|
@@ -895,71 +1100,43 @@ async function nativeSendTransaction(options, ctx) {
|
|
|
895
1100
|
finalPayload.details
|
|
896
1101
|
);
|
|
897
1102
|
}
|
|
1103
|
+
const successPayload = finalPayload;
|
|
898
1104
|
return {
|
|
899
|
-
|
|
900
|
-
userOpHash: finalPayload.userOpHash ?? null,
|
|
901
|
-
mini_app_id: finalPayload.mini_app_id ?? null,
|
|
1105
|
+
userOpHash: String(successPayload.userOpHash ?? ""),
|
|
902
1106
|
status: finalPayload.status,
|
|
903
1107
|
version: finalPayload.version,
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
from: finalPayload.from,
|
|
907
|
-
chain: finalPayload.chain,
|
|
908
|
-
timestamp: finalPayload.timestamp,
|
|
909
|
-
// Deprecated aliases
|
|
910
|
-
transaction_id: finalPayload.transaction_id,
|
|
911
|
-
transaction_status: "submitted"
|
|
1108
|
+
from: String(successPayload.from ?? ""),
|
|
1109
|
+
timestamp: String(successPayload.timestamp ?? (/* @__PURE__ */ new Date()).toISOString())
|
|
912
1110
|
};
|
|
913
1111
|
}
|
|
914
|
-
async function
|
|
915
|
-
if (options.
|
|
1112
|
+
async function adapterSendTransactionFallback(options) {
|
|
1113
|
+
if (options.transactions.length > 1) {
|
|
916
1114
|
throw new Error(WAGMI_MULTI_TX_ERROR_MESSAGE);
|
|
917
1115
|
}
|
|
918
|
-
|
|
919
|
-
console.warn(
|
|
920
|
-
"Permit2 signature is not automatically supported via Wagmi fallback. Transactions will execute without permit2."
|
|
921
|
-
);
|
|
922
|
-
}
|
|
923
|
-
const transactions = options.transaction.map((tx) => ({
|
|
924
|
-
address: tx.address,
|
|
925
|
-
// Encode the function call data
|
|
926
|
-
data: encodeTransactionData(tx),
|
|
927
|
-
value: tx.value
|
|
928
|
-
}));
|
|
929
|
-
const firstTransaction = transactions[0];
|
|
1116
|
+
const firstTransaction = options.transactions[0];
|
|
930
1117
|
if (!firstTransaction) {
|
|
931
1118
|
throw new Error("At least one transaction is required");
|
|
932
1119
|
}
|
|
933
|
-
const
|
|
934
|
-
|
|
1120
|
+
const fallbackAdapter = getFallbackAdapter();
|
|
1121
|
+
if (!fallbackAdapter?.sendTransaction) {
|
|
1122
|
+
throw new Error("Fallback adapter is not registered.");
|
|
1123
|
+
}
|
|
1124
|
+
const result = await fallbackAdapter.sendTransaction({
|
|
1125
|
+
transaction: {
|
|
1126
|
+
address: firstTransaction.to,
|
|
1127
|
+
data: firstTransaction.data,
|
|
1128
|
+
value: firstTransaction.value
|
|
1129
|
+
},
|
|
935
1130
|
chainId: options.chainId
|
|
936
1131
|
});
|
|
937
1132
|
return {
|
|
938
|
-
|
|
939
|
-
userOpHash: null,
|
|
940
|
-
mini_app_id: null,
|
|
1133
|
+
userOpHash: result.transactionHash,
|
|
941
1134
|
status: "success",
|
|
942
|
-
version:
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
from: null,
|
|
946
|
-
chain: null,
|
|
947
|
-
timestamp: null
|
|
1135
|
+
version: COMMAND_VERSIONS["send-transaction" /* SendTransaction */],
|
|
1136
|
+
from: "",
|
|
1137
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
948
1138
|
};
|
|
949
1139
|
}
|
|
950
|
-
function encodeTransactionData(tx) {
|
|
951
|
-
if (tx.data) {
|
|
952
|
-
return tx.data;
|
|
953
|
-
}
|
|
954
|
-
if (!tx.abi || !tx.functionName) {
|
|
955
|
-
throw new Error("Transaction requires `data` or `abi` + `functionName`.");
|
|
956
|
-
}
|
|
957
|
-
return (0, import_viem.encodeFunctionData)({
|
|
958
|
-
abi: tx.abi,
|
|
959
|
-
functionName: tx.functionName,
|
|
960
|
-
args: tx.args ?? []
|
|
961
|
-
});
|
|
962
|
-
}
|
|
963
1140
|
|
|
964
1141
|
// src/commands/share/format.ts
|
|
965
1142
|
var MAX_FILES = 10;
|
|
@@ -1178,12 +1355,13 @@ var SignMessageError = class extends Error {
|
|
|
1178
1355
|
|
|
1179
1356
|
// src/commands/sign-message/index.ts
|
|
1180
1357
|
async function signMessage(options, ctx) {
|
|
1358
|
+
const fallbackAdapter = getFallbackAdapter();
|
|
1181
1359
|
const result = await executeWithFallback({
|
|
1182
1360
|
command: "sign-message" /* SignMessage */,
|
|
1183
1361
|
nativeExecutor: () => nativeSignMessage(options, ctx),
|
|
1184
|
-
wagmiFallback: () =>
|
|
1362
|
+
wagmiFallback: fallbackAdapter?.signMessage ? () => fallbackAdapter.signMessage({
|
|
1185
1363
|
message: options.message
|
|
1186
|
-
}),
|
|
1364
|
+
}) : void 0,
|
|
1187
1365
|
customFallback: options.fallback
|
|
1188
1366
|
});
|
|
1189
1367
|
if (result.executedWith === "fallback") {
|
|
@@ -1243,16 +1421,17 @@ var SignTypedDataError = class extends Error {
|
|
|
1243
1421
|
|
|
1244
1422
|
// src/commands/sign-typed-data/index.ts
|
|
1245
1423
|
async function signTypedData(options, ctx) {
|
|
1424
|
+
const fallbackAdapter = getFallbackAdapter();
|
|
1246
1425
|
const result = await executeWithFallback({
|
|
1247
1426
|
command: "sign-typed-data" /* SignTypedData */,
|
|
1248
1427
|
nativeExecutor: () => nativeSignTypedData(options, ctx),
|
|
1249
|
-
wagmiFallback: () =>
|
|
1428
|
+
wagmiFallback: fallbackAdapter?.signTypedData ? () => fallbackAdapter.signTypedData({
|
|
1250
1429
|
types: options.types,
|
|
1251
1430
|
primaryType: options.primaryType,
|
|
1252
1431
|
message: options.message,
|
|
1253
1432
|
domain: options.domain,
|
|
1254
1433
|
chainId: options.chainId
|
|
1255
|
-
}),
|
|
1434
|
+
}) : void 0,
|
|
1256
1435
|
customFallback: options.fallback
|
|
1257
1436
|
});
|
|
1258
1437
|
if (result.executedWith === "fallback") {
|
|
@@ -1309,7 +1488,7 @@ async function nativeSignTypedData(options, ctx) {
|
|
|
1309
1488
|
}
|
|
1310
1489
|
|
|
1311
1490
|
// src/commands/wallet-auth/siwe.ts
|
|
1312
|
-
var
|
|
1491
|
+
var import_viem = require("viem");
|
|
1313
1492
|
var import_chains = require("viem/chains");
|
|
1314
1493
|
var generateSiweMessage = (siweMessageData) => {
|
|
1315
1494
|
let siweMessage = "";
|
|
@@ -1399,14 +1578,15 @@ var validateWalletAuthCommandInput = (params) => {
|
|
|
1399
1578
|
|
|
1400
1579
|
// src/commands/wallet-auth/index.ts
|
|
1401
1580
|
async function walletAuth(options, ctx) {
|
|
1581
|
+
const fallbackAdapter = getFallbackAdapter();
|
|
1402
1582
|
const result = await executeWithFallback({
|
|
1403
1583
|
command: "wallet-auth" /* WalletAuth */,
|
|
1404
1584
|
nativeExecutor: () => nativeWalletAuth(options, ctx),
|
|
1405
|
-
wagmiFallback: () =>
|
|
1585
|
+
wagmiFallback: fallbackAdapter?.walletAuth ? () => fallbackAdapter.walletAuth({
|
|
1406
1586
|
nonce: options.nonce,
|
|
1407
1587
|
statement: options.statement,
|
|
1408
1588
|
expirationTime: options.expirationTime
|
|
1409
|
-
}),
|
|
1589
|
+
}) : void 0,
|
|
1410
1590
|
customFallback: options.fallback
|
|
1411
1591
|
});
|
|
1412
1592
|
if (result.executedWith === "fallback") {
|
|
@@ -1465,7 +1645,11 @@ async function nativeWalletAuth(options, ctx) {
|
|
|
1465
1645
|
});
|
|
1466
1646
|
const walletAuthPayload = { siweMessage };
|
|
1467
1647
|
const worldAppVersion = ctx.state.deviceProperties.worldAppVersion;
|
|
1468
|
-
|
|
1648
|
+
if (worldAppVersion && worldAppVersion <= 2087900) {
|
|
1649
|
+
throw new Error(
|
|
1650
|
+
"Wallet auth v1 is no longer supported. Please update World App to the latest version."
|
|
1651
|
+
);
|
|
1652
|
+
}
|
|
1469
1653
|
const finalPayload = await new Promise(
|
|
1470
1654
|
(resolve, reject) => {
|
|
1471
1655
|
try {
|
|
@@ -1475,7 +1659,7 @@ async function nativeWalletAuth(options, ctx) {
|
|
|
1475
1659
|
});
|
|
1476
1660
|
sendMiniKitEvent({
|
|
1477
1661
|
command: "wallet-auth" /* WalletAuth */,
|
|
1478
|
-
version:
|
|
1662
|
+
version: COMMAND_VERSIONS["wallet-auth" /* WalletAuth */],
|
|
1479
1663
|
payload: walletAuthPayload
|
|
1480
1664
|
});
|
|
1481
1665
|
} catch (error) {
|
|
@@ -1660,11 +1844,10 @@ var _MiniKit = class _MiniKit {
|
|
|
1660
1844
|
* ```typescript
|
|
1661
1845
|
* const result = await MiniKit.sendTransaction({
|
|
1662
1846
|
* chainId: 480,
|
|
1663
|
-
*
|
|
1664
|
-
*
|
|
1665
|
-
*
|
|
1666
|
-
*
|
|
1667
|
-
* args: [],
|
|
1847
|
+
* transactions: [{
|
|
1848
|
+
* to: '0x...',
|
|
1849
|
+
* data: '0x...',
|
|
1850
|
+
* value: '0x0',
|
|
1668
1851
|
* }],
|
|
1669
1852
|
* });
|
|
1670
1853
|
* ```
|
|
@@ -1789,6 +1972,26 @@ var _MiniKit = class _MiniKit {
|
|
|
1789
1972
|
}
|
|
1790
1973
|
return sendHapticFeedback(options, this.getContext());
|
|
1791
1974
|
}
|
|
1975
|
+
/**
|
|
1976
|
+
* Request app attestation token for a request hash
|
|
1977
|
+
*/
|
|
1978
|
+
static attestation(options) {
|
|
1979
|
+
const active = this.getActiveMiniKit();
|
|
1980
|
+
if (active !== this) {
|
|
1981
|
+
return active.attestation(options);
|
|
1982
|
+
}
|
|
1983
|
+
return attestation(options, this.getContext());
|
|
1984
|
+
}
|
|
1985
|
+
/**
|
|
1986
|
+
* Close the mini app
|
|
1987
|
+
*/
|
|
1988
|
+
static closeMiniApp(options = {}) {
|
|
1989
|
+
const active = this.getActiveMiniKit();
|
|
1990
|
+
if (active !== this) {
|
|
1991
|
+
return active.closeMiniApp(options);
|
|
1992
|
+
}
|
|
1993
|
+
return closeMiniApp(options, this.getContext());
|
|
1994
|
+
}
|
|
1792
1995
|
// ============================================================================
|
|
1793
1996
|
// Public State Accessors
|
|
1794
1997
|
// ============================================================================
|
|
@@ -1967,6 +2170,8 @@ var _MiniKit = class _MiniKit {
|
|
|
1967
2170
|
* - `MiniKit.commands.getPermissions()` → `await MiniKit.getPermissions()`
|
|
1968
2171
|
* - `MiniKit.commands.requestPermission(payload)` → `await MiniKit.requestPermission(input)`
|
|
1969
2172
|
* - `MiniKit.commands.sendHapticFeedback(payload)` → `await MiniKit.sendHapticFeedback(input)`
|
|
2173
|
+
* - `MiniKit.commands.attestation(payload)` → `await MiniKit.attestation(options)`
|
|
2174
|
+
* - `MiniKit.commands.closeMiniApp()` → `await MiniKit.closeMiniApp()`
|
|
1970
2175
|
*/
|
|
1971
2176
|
static get commands() {
|
|
1972
2177
|
throw new Error(
|
|
@@ -2054,13 +2259,18 @@ _MiniKit.showProfileCard = (username, walletAddress) => {
|
|
|
2054
2259
|
var MiniKit = _MiniKit;
|
|
2055
2260
|
|
|
2056
2261
|
// src/provider.ts
|
|
2262
|
+
var import_viem2 = require("viem");
|
|
2057
2263
|
function _getAddress() {
|
|
2058
2264
|
if (typeof window === "undefined") return void 0;
|
|
2059
2265
|
return window.__worldapp_eip1193_address__;
|
|
2060
2266
|
}
|
|
2061
2267
|
function _setAddress(addr) {
|
|
2062
2268
|
if (typeof window === "undefined") return;
|
|
2063
|
-
|
|
2269
|
+
try {
|
|
2270
|
+
window.__worldapp_eip1193_address__ = (0, import_viem2.getAddress)(addr);
|
|
2271
|
+
} catch {
|
|
2272
|
+
window.__worldapp_eip1193_address__ = addr;
|
|
2273
|
+
}
|
|
2064
2274
|
}
|
|
2065
2275
|
function _clearAddress() {
|
|
2066
2276
|
if (typeof window === "undefined") return;
|
|
@@ -2184,16 +2394,19 @@ function createProvider() {
|
|
|
2184
2394
|
}
|
|
2185
2395
|
let authInFlight;
|
|
2186
2396
|
async function doAuth() {
|
|
2187
|
-
if (!MiniKit.isInWorldApp()) {
|
|
2188
|
-
throw rpcError(
|
|
2397
|
+
if (!MiniKit.isInWorldApp() || !MiniKit.isInstalled()) {
|
|
2398
|
+
throw rpcError(
|
|
2399
|
+
4900,
|
|
2400
|
+
"World App provider only works inside World App and must be installed"
|
|
2401
|
+
);
|
|
2189
2402
|
}
|
|
2190
2403
|
try {
|
|
2191
2404
|
const result = await MiniKit.walletAuth({
|
|
2192
2405
|
nonce: crypto.randomUUID().replace(/-/g, ""),
|
|
2193
2406
|
statement: "Sign in with World App"
|
|
2194
2407
|
});
|
|
2195
|
-
|
|
2196
|
-
|
|
2408
|
+
_setAddress(result.data.address);
|
|
2409
|
+
const addr = _getAddress();
|
|
2197
2410
|
emit("accountsChanged", [addr]);
|
|
2198
2411
|
return [addr];
|
|
2199
2412
|
} catch (e) {
|
|
@@ -2263,18 +2476,21 @@ function createProvider() {
|
|
|
2263
2476
|
}
|
|
2264
2477
|
case "eth_sendTransaction": {
|
|
2265
2478
|
const tx = extractTransactionParams(params);
|
|
2479
|
+
if (tx.chainId !== void 0 && tx.chainId !== 480) {
|
|
2480
|
+
throw rpcError(4902, "World App only supports World Chain (480)");
|
|
2481
|
+
}
|
|
2266
2482
|
try {
|
|
2267
2483
|
const result = await MiniKit.sendTransaction({
|
|
2268
|
-
|
|
2269
|
-
|
|
2484
|
+
chainId: tx.chainId ?? 480,
|
|
2485
|
+
transactions: [
|
|
2270
2486
|
{
|
|
2271
|
-
|
|
2487
|
+
to: tx.to,
|
|
2272
2488
|
...tx.data && tx.data !== "0x" ? { data: tx.data } : {},
|
|
2273
2489
|
value: tx.value
|
|
2274
2490
|
}
|
|
2275
2491
|
]
|
|
2276
2492
|
});
|
|
2277
|
-
return result.data.
|
|
2493
|
+
return result.data.userOpHash;
|
|
2278
2494
|
} catch (e) {
|
|
2279
2495
|
throw rpcError(4001, `Send transaction failed: ${e.message}`);
|
|
2280
2496
|
}
|
|
@@ -2352,7 +2568,8 @@ function createConnectorFn(name) {
|
|
|
2352
2568
|
method: "eth_requestAccounts"
|
|
2353
2569
|
});
|
|
2354
2570
|
if (Array.isArray(accounts) && accounts.length > 0 && typeof accounts[0] === "string") {
|
|
2355
|
-
|
|
2571
|
+
_setAddress(accounts[0]);
|
|
2572
|
+
return [_getAddress()];
|
|
2356
2573
|
}
|
|
2357
2574
|
} catch {
|
|
2358
2575
|
}
|