@worldcoin/minikit-js 1.11.0 → 2.0.0-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +107 -0
- package/build/address-book.cjs +81 -0
- package/build/address-book.d.cts +3 -0
- package/build/address-book.d.ts +3 -0
- package/build/address-book.js +54 -0
- package/build/chunk-2UPJKPQ6.js +272 -0
- package/build/chunk-EHBM7OXH.js +596 -0
- package/build/chunk-LHHKY77D.js +274 -0
- package/build/chunk-TGXD24YD.js +279 -0
- package/build/chunk-Z2UGRZJ2.js +1635 -0
- package/build/command-exports.cjs +1762 -0
- package/build/command-exports.d.cts +105 -0
- package/build/command-exports.d.ts +105 -0
- package/build/command-exports.js +129 -0
- package/build/connector/index.cjs +2601 -0
- package/build/connector/index.d.cts +55 -0
- package/build/connector/index.d.ts +55 -0
- package/build/connector/index.js +90 -0
- package/build/index.cjs +1634 -1627
- package/build/index.d.cts +143 -671
- package/build/index.d.ts +143 -671
- package/build/index.js +7 -206
- package/build/minikit-provider.cjs +1650 -948
- package/build/minikit-provider.d.cts +2 -1
- package/build/minikit-provider.d.ts +2 -1
- package/build/minikit-provider.js +13 -2
- package/build/provider-DeDUsLbs.d.cts +43 -0
- package/build/provider-DeDUsLbs.d.ts +43 -0
- package/build/siwe-exports.cjs +249 -0
- package/build/siwe-exports.d.cts +10 -0
- package/build/siwe-exports.d.ts +10 -0
- package/build/siwe-exports.js +8 -0
- package/build/types-CC2x79HX.d.ts +525 -0
- package/build/types-CSyzFDPt.d.cts +223 -0
- package/build/types-CSyzFDPt.d.ts +223 -0
- package/build/types-_jfLbcJW.d.cts +525 -0
- package/package.json +73 -11
- package/build/chunk-62NZ34E4.js +0 -2092
- package/index.ts +0 -29
|
@@ -0,0 +1,1635 @@
|
|
|
1
|
+
import {
|
|
2
|
+
generateSiweMessage
|
|
3
|
+
} from "./chunk-LHHKY77D.js";
|
|
4
|
+
|
|
5
|
+
// src/commands/types.ts
|
|
6
|
+
var Command = /* @__PURE__ */ ((Command2) => {
|
|
7
|
+
Command2["Attestation"] = "attestation";
|
|
8
|
+
Command2["Pay"] = "pay";
|
|
9
|
+
Command2["WalletAuth"] = "wallet-auth";
|
|
10
|
+
Command2["SendTransaction"] = "send-transaction";
|
|
11
|
+
Command2["SignMessage"] = "sign-message";
|
|
12
|
+
Command2["SignTypedData"] = "sign-typed-data";
|
|
13
|
+
Command2["ShareContacts"] = "share-contacts";
|
|
14
|
+
Command2["RequestPermission"] = "request-permission";
|
|
15
|
+
Command2["GetPermissions"] = "get-permissions";
|
|
16
|
+
Command2["SendHapticFeedback"] = "send-haptic-feedback";
|
|
17
|
+
Command2["Share"] = "share";
|
|
18
|
+
Command2["Chat"] = "chat";
|
|
19
|
+
Command2["CloseMiniApp"] = "close-miniapp";
|
|
20
|
+
return Command2;
|
|
21
|
+
})(Command || {});
|
|
22
|
+
var ResponseEvent = /* @__PURE__ */ ((ResponseEvent2) => {
|
|
23
|
+
ResponseEvent2["MiniAppAttestation"] = "miniapp-attestation";
|
|
24
|
+
ResponseEvent2["MiniAppPayment"] = "miniapp-payment";
|
|
25
|
+
ResponseEvent2["MiniAppWalletAuth"] = "miniapp-wallet-auth";
|
|
26
|
+
ResponseEvent2["MiniAppSendTransaction"] = "miniapp-send-transaction";
|
|
27
|
+
ResponseEvent2["MiniAppSignMessage"] = "miniapp-sign-message";
|
|
28
|
+
ResponseEvent2["MiniAppSignTypedData"] = "miniapp-sign-typed-data";
|
|
29
|
+
ResponseEvent2["MiniAppShareContacts"] = "miniapp-share-contacts";
|
|
30
|
+
ResponseEvent2["MiniAppRequestPermission"] = "miniapp-request-permission";
|
|
31
|
+
ResponseEvent2["MiniAppGetPermissions"] = "miniapp-get-permissions";
|
|
32
|
+
ResponseEvent2["MiniAppSendHapticFeedback"] = "miniapp-send-haptic-feedback";
|
|
33
|
+
ResponseEvent2["MiniAppShare"] = "miniapp-share";
|
|
34
|
+
ResponseEvent2["MiniAppMicrophone"] = "miniapp-microphone";
|
|
35
|
+
ResponseEvent2["MiniAppChat"] = "miniapp-chat";
|
|
36
|
+
return ResponseEvent2;
|
|
37
|
+
})(ResponseEvent || {});
|
|
38
|
+
var COMMAND_VERSIONS = {
|
|
39
|
+
["attestation" /* Attestation */]: 1,
|
|
40
|
+
["pay" /* Pay */]: 1,
|
|
41
|
+
["wallet-auth" /* WalletAuth */]: 2,
|
|
42
|
+
["send-transaction" /* SendTransaction */]: 2,
|
|
43
|
+
["sign-message" /* SignMessage */]: 1,
|
|
44
|
+
["sign-typed-data" /* SignTypedData */]: 1,
|
|
45
|
+
["share-contacts" /* ShareContacts */]: 1,
|
|
46
|
+
["request-permission" /* RequestPermission */]: 1,
|
|
47
|
+
["get-permissions" /* GetPermissions */]: 1,
|
|
48
|
+
["send-haptic-feedback" /* SendHapticFeedback */]: 1,
|
|
49
|
+
["share" /* Share */]: 1,
|
|
50
|
+
["chat" /* Chat */]: 1,
|
|
51
|
+
["close-miniapp" /* CloseMiniApp */]: 1
|
|
52
|
+
};
|
|
53
|
+
var commandAvailability = {
|
|
54
|
+
["attestation" /* Attestation */]: false,
|
|
55
|
+
["pay" /* Pay */]: false,
|
|
56
|
+
["wallet-auth" /* WalletAuth */]: false,
|
|
57
|
+
["send-transaction" /* SendTransaction */]: false,
|
|
58
|
+
["sign-message" /* SignMessage */]: false,
|
|
59
|
+
["sign-typed-data" /* SignTypedData */]: false,
|
|
60
|
+
["share-contacts" /* ShareContacts */]: false,
|
|
61
|
+
["request-permission" /* RequestPermission */]: false,
|
|
62
|
+
["get-permissions" /* GetPermissions */]: false,
|
|
63
|
+
["send-haptic-feedback" /* SendHapticFeedback */]: false,
|
|
64
|
+
["share" /* Share */]: false,
|
|
65
|
+
["chat" /* Chat */]: false,
|
|
66
|
+
["close-miniapp" /* CloseMiniApp */]: false
|
|
67
|
+
};
|
|
68
|
+
function isCommandAvailable(command) {
|
|
69
|
+
return commandAvailability[command] ?? false;
|
|
70
|
+
}
|
|
71
|
+
function setCommandAvailable(command, available) {
|
|
72
|
+
commandAvailability[command] = available;
|
|
73
|
+
}
|
|
74
|
+
function validateCommands(worldAppSupportedCommands) {
|
|
75
|
+
let allCommandsValid = true;
|
|
76
|
+
Object.entries(COMMAND_VERSIONS).forEach(([commandName, version]) => {
|
|
77
|
+
const commandInput = worldAppSupportedCommands.find(
|
|
78
|
+
(cmd) => cmd.name === commandName
|
|
79
|
+
);
|
|
80
|
+
let isCommandValid = false;
|
|
81
|
+
if (!commandInput) {
|
|
82
|
+
console.warn(
|
|
83
|
+
`Command ${commandName} is not supported by the app. Try updating the app version`
|
|
84
|
+
);
|
|
85
|
+
} else {
|
|
86
|
+
if (commandInput.supported_versions.includes(version)) {
|
|
87
|
+
setCommandAvailable(commandName, true);
|
|
88
|
+
isCommandValid = true;
|
|
89
|
+
} else {
|
|
90
|
+
isCommandValid = true;
|
|
91
|
+
console.warn(
|
|
92
|
+
`Command ${commandName} version ${version} is not supported by the app. Supported versions: ${commandInput.supported_versions.join(", ")}. This is not an error, but it is recommended to update the World App version.`
|
|
93
|
+
);
|
|
94
|
+
setCommandAvailable(commandName, true);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
if (!isCommandValid) {
|
|
98
|
+
allCommandsValid = false;
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
return allCommandsValid;
|
|
102
|
+
}
|
|
103
|
+
function sendMiniKitEvent(payload) {
|
|
104
|
+
if (window.webkit) {
|
|
105
|
+
window.webkit?.messageHandlers?.minikit?.postMessage?.(payload);
|
|
106
|
+
} else if (window.Android) {
|
|
107
|
+
window.Android?.postMessage?.(JSON.stringify(payload));
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
function isInWorldApp() {
|
|
111
|
+
return typeof window !== "undefined" && Boolean(window.WorldApp);
|
|
112
|
+
}
|
|
113
|
+
var FallbackRequiredError = class extends Error {
|
|
114
|
+
constructor(command) {
|
|
115
|
+
super(
|
|
116
|
+
`${command} requires a fallback function when running outside World App. Provide a fallback option: MiniKit.${command}({ ..., fallback: () => yourFallback() })`
|
|
117
|
+
);
|
|
118
|
+
this.name = "FallbackRequiredError";
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
var CommandUnavailableError = class extends Error {
|
|
122
|
+
constructor(command, reason) {
|
|
123
|
+
const messages = {
|
|
124
|
+
notInWorldApp: "Not running inside World App",
|
|
125
|
+
commandNotSupported: "Command not supported in this environment",
|
|
126
|
+
oldAppVersion: "World App version does not support this command"
|
|
127
|
+
};
|
|
128
|
+
super(`${command} is unavailable: ${messages[reason]}`);
|
|
129
|
+
this.name = "CommandUnavailableError";
|
|
130
|
+
this.reason = reason;
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
// src/commands/attestation/types.ts
|
|
135
|
+
var AttestationErrorCodes = /* @__PURE__ */ ((AttestationErrorCodes2) => {
|
|
136
|
+
AttestationErrorCodes2["Unauthorized"] = "unauthorized";
|
|
137
|
+
AttestationErrorCodes2["AttestationFailed"] = "attestation_failed";
|
|
138
|
+
AttestationErrorCodes2["IntegrityFailed"] = "integrity_failed";
|
|
139
|
+
AttestationErrorCodes2["InvalidInput"] = "invalid_input";
|
|
140
|
+
AttestationErrorCodes2["UnsupportedVersion"] = "unsupported_version";
|
|
141
|
+
return AttestationErrorCodes2;
|
|
142
|
+
})(AttestationErrorCodes || {});
|
|
143
|
+
var AttestationError = class extends Error {
|
|
144
|
+
constructor(error_code) {
|
|
145
|
+
super(`Attestation failed: ${error_code}`);
|
|
146
|
+
this.error_code = error_code;
|
|
147
|
+
this.name = "AttestationError";
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
// src/events.ts
|
|
152
|
+
var EventManager = class {
|
|
153
|
+
constructor() {
|
|
154
|
+
this.listeners = {
|
|
155
|
+
["miniapp-attestation" /* MiniAppAttestation */]: () => {
|
|
156
|
+
},
|
|
157
|
+
["miniapp-payment" /* MiniAppPayment */]: () => {
|
|
158
|
+
},
|
|
159
|
+
["miniapp-wallet-auth" /* MiniAppWalletAuth */]: () => {
|
|
160
|
+
},
|
|
161
|
+
["miniapp-send-transaction" /* MiniAppSendTransaction */]: () => {
|
|
162
|
+
},
|
|
163
|
+
["miniapp-sign-message" /* MiniAppSignMessage */]: () => {
|
|
164
|
+
},
|
|
165
|
+
["miniapp-sign-typed-data" /* MiniAppSignTypedData */]: () => {
|
|
166
|
+
},
|
|
167
|
+
["miniapp-share-contacts" /* MiniAppShareContacts */]: () => {
|
|
168
|
+
},
|
|
169
|
+
["miniapp-request-permission" /* MiniAppRequestPermission */]: () => {
|
|
170
|
+
},
|
|
171
|
+
["miniapp-get-permissions" /* MiniAppGetPermissions */]: () => {
|
|
172
|
+
},
|
|
173
|
+
["miniapp-send-haptic-feedback" /* MiniAppSendHapticFeedback */]: () => {
|
|
174
|
+
},
|
|
175
|
+
["miniapp-share" /* MiniAppShare */]: () => {
|
|
176
|
+
},
|
|
177
|
+
["miniapp-microphone" /* MiniAppMicrophone */]: () => {
|
|
178
|
+
},
|
|
179
|
+
["miniapp-chat" /* MiniAppChat */]: () => {
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
}
|
|
183
|
+
subscribe(event, handler) {
|
|
184
|
+
this.listeners[event] = handler;
|
|
185
|
+
}
|
|
186
|
+
unsubscribe(event) {
|
|
187
|
+
delete this.listeners[event];
|
|
188
|
+
}
|
|
189
|
+
trigger(event, payload) {
|
|
190
|
+
if (!this.listeners[event]) {
|
|
191
|
+
console.error(
|
|
192
|
+
`No handler for event ${event}, payload: ${JSON.stringify(payload)}`
|
|
193
|
+
);
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
this.listeners[event](payload);
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
// src/commands/fallback.ts
|
|
201
|
+
async function executeWithFallback(options) {
|
|
202
|
+
const {
|
|
203
|
+
command,
|
|
204
|
+
nativeExecutor,
|
|
205
|
+
wagmiFallback,
|
|
206
|
+
customFallback,
|
|
207
|
+
requiresFallback = false
|
|
208
|
+
} = options;
|
|
209
|
+
const inWorldApp = isInWorldApp();
|
|
210
|
+
const commandAvailable = isCommandAvailable(command);
|
|
211
|
+
let nativeError;
|
|
212
|
+
if (inWorldApp && commandAvailable) {
|
|
213
|
+
try {
|
|
214
|
+
const data = await nativeExecutor();
|
|
215
|
+
return { data, executedWith: "minikit" };
|
|
216
|
+
} catch (error) {
|
|
217
|
+
nativeError = error;
|
|
218
|
+
console.warn(`Native ${command} failed, attempting fallback:`, error);
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
if (!inWorldApp && wagmiFallback) {
|
|
222
|
+
try {
|
|
223
|
+
const data = await wagmiFallback();
|
|
224
|
+
return { data, executedWith: "wagmi" };
|
|
225
|
+
} catch (error) {
|
|
226
|
+
console.warn(`Wagmi fallback for ${command} failed:`, error);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
if (!inWorldApp && customFallback) {
|
|
230
|
+
const data = await customFallback();
|
|
231
|
+
return { data, executedWith: "fallback" };
|
|
232
|
+
}
|
|
233
|
+
if (nativeError) {
|
|
234
|
+
throw nativeError;
|
|
235
|
+
}
|
|
236
|
+
if (requiresFallback && !inWorldApp) {
|
|
237
|
+
throw new FallbackRequiredError(command);
|
|
238
|
+
}
|
|
239
|
+
throw new CommandUnavailableError(command, determineFallbackReason(command));
|
|
240
|
+
}
|
|
241
|
+
function determineFallbackReason(command) {
|
|
242
|
+
if (!isInWorldApp()) {
|
|
243
|
+
return "notInWorldApp";
|
|
244
|
+
}
|
|
245
|
+
if (!isCommandAvailable(command)) {
|
|
246
|
+
return "oldAppVersion";
|
|
247
|
+
}
|
|
248
|
+
return "commandNotSupported";
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
// src/commands/attestation/index.ts
|
|
252
|
+
async function attestation(options, ctx) {
|
|
253
|
+
const result = await executeWithFallback({
|
|
254
|
+
command: "attestation" /* Attestation */,
|
|
255
|
+
nativeExecutor: () => nativeAttestation(options, ctx),
|
|
256
|
+
customFallback: options.fallback
|
|
257
|
+
});
|
|
258
|
+
if (result.executedWith === "fallback") {
|
|
259
|
+
return { executedWith: "fallback", data: result.data };
|
|
260
|
+
}
|
|
261
|
+
return {
|
|
262
|
+
executedWith: "minikit",
|
|
263
|
+
data: result.data
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
async function nativeAttestation(options, ctx) {
|
|
267
|
+
if (!ctx) {
|
|
268
|
+
ctx = { events: new EventManager(), state: { deviceProperties: {} } };
|
|
269
|
+
}
|
|
270
|
+
if (typeof window === "undefined" || !isCommandAvailable("attestation" /* Attestation */)) {
|
|
271
|
+
throw new Error(
|
|
272
|
+
"'attestation' command is unavailable. Check MiniKit.install() or update the app version"
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
if (!options.requestHash || options.requestHash.length === 0) {
|
|
276
|
+
throw new Error("'attestation' command requires a non-empty requestHash");
|
|
277
|
+
}
|
|
278
|
+
const payload = await new Promise(
|
|
279
|
+
(resolve, reject) => {
|
|
280
|
+
try {
|
|
281
|
+
ctx.events.subscribe("miniapp-attestation" /* MiniAppAttestation */, (response) => {
|
|
282
|
+
ctx.events.unsubscribe("miniapp-attestation" /* MiniAppAttestation */);
|
|
283
|
+
resolve(response);
|
|
284
|
+
});
|
|
285
|
+
sendMiniKitEvent({
|
|
286
|
+
command: "attestation" /* Attestation */,
|
|
287
|
+
version: COMMAND_VERSIONS["attestation" /* Attestation */],
|
|
288
|
+
payload: {
|
|
289
|
+
request_hash: options.requestHash
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
} catch (error) {
|
|
293
|
+
reject(error);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
);
|
|
297
|
+
if (payload.status === "error") {
|
|
298
|
+
throw new AttestationError(payload.error_code);
|
|
299
|
+
}
|
|
300
|
+
return payload;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// src/commands/chat/types.ts
|
|
304
|
+
var ChatErrorCodes = /* @__PURE__ */ ((ChatErrorCodes2) => {
|
|
305
|
+
ChatErrorCodes2["UserRejected"] = "user_rejected";
|
|
306
|
+
ChatErrorCodes2["SendFailed"] = "send_failed";
|
|
307
|
+
ChatErrorCodes2["GenericError"] = "generic_error";
|
|
308
|
+
return ChatErrorCodes2;
|
|
309
|
+
})(ChatErrorCodes || {});
|
|
310
|
+
var ChatError = class extends Error {
|
|
311
|
+
constructor(error_code) {
|
|
312
|
+
super(`Chat failed: ${error_code}`);
|
|
313
|
+
this.error_code = error_code;
|
|
314
|
+
this.name = "ChatError";
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
// src/commands/chat/index.ts
|
|
319
|
+
async function chat(options, ctx) {
|
|
320
|
+
const result = await executeWithFallback({
|
|
321
|
+
command: "chat" /* Chat */,
|
|
322
|
+
nativeExecutor: () => nativeChat(options, ctx),
|
|
323
|
+
customFallback: options.fallback
|
|
324
|
+
});
|
|
325
|
+
if (result.executedWith === "fallback") {
|
|
326
|
+
return { executedWith: "fallback", data: result.data };
|
|
327
|
+
}
|
|
328
|
+
return {
|
|
329
|
+
executedWith: "minikit",
|
|
330
|
+
data: result.data
|
|
331
|
+
};
|
|
332
|
+
}
|
|
333
|
+
async function nativeChat(options, ctx) {
|
|
334
|
+
if (!ctx) {
|
|
335
|
+
ctx = { events: new EventManager(), state: { deviceProperties: {} } };
|
|
336
|
+
}
|
|
337
|
+
if (typeof window === "undefined" || !isCommandAvailable("chat" /* Chat */)) {
|
|
338
|
+
throw new Error(
|
|
339
|
+
"'chat' command is unavailable. Check MiniKit.install() or update the app version"
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
const payloadInput = {
|
|
343
|
+
message: options.message,
|
|
344
|
+
to: options.to
|
|
345
|
+
};
|
|
346
|
+
if (payloadInput.message.length === 0) {
|
|
347
|
+
throw new Error("'chat' command requires a non-empty message");
|
|
348
|
+
}
|
|
349
|
+
const payload = await new Promise((resolve, reject) => {
|
|
350
|
+
try {
|
|
351
|
+
ctx.events.subscribe("miniapp-chat" /* MiniAppChat */, (response) => {
|
|
352
|
+
ctx.events.unsubscribe("miniapp-chat" /* MiniAppChat */);
|
|
353
|
+
resolve(response);
|
|
354
|
+
});
|
|
355
|
+
sendMiniKitEvent({
|
|
356
|
+
command: "chat" /* Chat */,
|
|
357
|
+
version: COMMAND_VERSIONS["chat" /* Chat */],
|
|
358
|
+
payload: payloadInput
|
|
359
|
+
});
|
|
360
|
+
} catch (error) {
|
|
361
|
+
reject(error);
|
|
362
|
+
}
|
|
363
|
+
});
|
|
364
|
+
if (payload.status === "error") {
|
|
365
|
+
throw new ChatError(payload.error_code);
|
|
366
|
+
}
|
|
367
|
+
return payload;
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// src/commands/close-miniapp/index.ts
|
|
371
|
+
async function closeMiniApp(options = {}, _ctx) {
|
|
372
|
+
const result = await executeWithFallback({
|
|
373
|
+
command: "close-miniapp" /* CloseMiniApp */,
|
|
374
|
+
nativeExecutor: () => nativeCloseMiniApp(),
|
|
375
|
+
customFallback: options.fallback
|
|
376
|
+
});
|
|
377
|
+
if (result.executedWith === "fallback") {
|
|
378
|
+
return { executedWith: "fallback", data: result.data };
|
|
379
|
+
}
|
|
380
|
+
return {
|
|
381
|
+
executedWith: "minikit",
|
|
382
|
+
data: result.data
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
async function nativeCloseMiniApp() {
|
|
386
|
+
if (typeof window === "undefined" || !isCommandAvailable("close-miniapp" /* CloseMiniApp */)) {
|
|
387
|
+
throw new Error(
|
|
388
|
+
"'closeMiniApp' command is unavailable. Check MiniKit.install() or update the app version"
|
|
389
|
+
);
|
|
390
|
+
}
|
|
391
|
+
sendMiniKitEvent({
|
|
392
|
+
command: "close-miniapp" /* CloseMiniApp */,
|
|
393
|
+
version: COMMAND_VERSIONS["close-miniapp" /* CloseMiniApp */],
|
|
394
|
+
payload: {}
|
|
395
|
+
});
|
|
396
|
+
return {
|
|
397
|
+
status: "success",
|
|
398
|
+
version: COMMAND_VERSIONS["close-miniapp" /* CloseMiniApp */]
|
|
399
|
+
};
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
// src/commands/get-permissions/types.ts
|
|
403
|
+
var GetPermissionsErrorCodes = /* @__PURE__ */ ((GetPermissionsErrorCodes2) => {
|
|
404
|
+
GetPermissionsErrorCodes2["GenericError"] = "generic_error";
|
|
405
|
+
return GetPermissionsErrorCodes2;
|
|
406
|
+
})(GetPermissionsErrorCodes || {});
|
|
407
|
+
var Permission = /* @__PURE__ */ ((Permission2) => {
|
|
408
|
+
Permission2["Notifications"] = "notifications";
|
|
409
|
+
Permission2["Contacts"] = "contacts";
|
|
410
|
+
Permission2["Microphone"] = "microphone";
|
|
411
|
+
return Permission2;
|
|
412
|
+
})(Permission || {});
|
|
413
|
+
var GetPermissionsError = class extends Error {
|
|
414
|
+
constructor(error_code) {
|
|
415
|
+
super(`Get permissions failed: ${error_code}`);
|
|
416
|
+
this.error_code = error_code;
|
|
417
|
+
this.name = "GetPermissionsError";
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
|
|
421
|
+
// src/commands/get-permissions/index.ts
|
|
422
|
+
async function getPermissions(options, ctx) {
|
|
423
|
+
const resolvedOptions = options ?? {};
|
|
424
|
+
const result = await executeWithFallback({
|
|
425
|
+
command: "get-permissions" /* GetPermissions */,
|
|
426
|
+
nativeExecutor: () => nativeGetPermissions(ctx),
|
|
427
|
+
customFallback: resolvedOptions.fallback
|
|
428
|
+
});
|
|
429
|
+
if (result.executedWith === "fallback") {
|
|
430
|
+
return { executedWith: "fallback", data: result.data };
|
|
431
|
+
}
|
|
432
|
+
return {
|
|
433
|
+
executedWith: "minikit",
|
|
434
|
+
data: result.data
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
async function nativeGetPermissions(ctx) {
|
|
438
|
+
if (!ctx) {
|
|
439
|
+
ctx = { events: new EventManager(), state: { deviceProperties: {} } };
|
|
440
|
+
}
|
|
441
|
+
if (typeof window === "undefined" || !isCommandAvailable("get-permissions" /* GetPermissions */)) {
|
|
442
|
+
throw new Error(
|
|
443
|
+
"'getPermissions' command is unavailable. Check MiniKit.install() or update the app version"
|
|
444
|
+
);
|
|
445
|
+
}
|
|
446
|
+
const payload = await new Promise(
|
|
447
|
+
(resolve, reject) => {
|
|
448
|
+
try {
|
|
449
|
+
ctx.events.subscribe("miniapp-get-permissions" /* MiniAppGetPermissions */, (response) => {
|
|
450
|
+
ctx.events.unsubscribe("miniapp-get-permissions" /* MiniAppGetPermissions */);
|
|
451
|
+
resolve(response);
|
|
452
|
+
});
|
|
453
|
+
sendMiniKitEvent({
|
|
454
|
+
command: "get-permissions" /* GetPermissions */,
|
|
455
|
+
version: COMMAND_VERSIONS["get-permissions" /* GetPermissions */],
|
|
456
|
+
payload: {}
|
|
457
|
+
});
|
|
458
|
+
} catch (error) {
|
|
459
|
+
reject(error);
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
);
|
|
463
|
+
if (payload.status === "error") {
|
|
464
|
+
throw new GetPermissionsError(payload.error_code);
|
|
465
|
+
}
|
|
466
|
+
return payload;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
// src/commands/pay/types.ts
|
|
470
|
+
var Tokens = /* @__PURE__ */ ((Tokens2) => {
|
|
471
|
+
Tokens2["USDC"] = "USDCE";
|
|
472
|
+
Tokens2["WLD"] = "WLD";
|
|
473
|
+
Tokens2["WARS"] = "WARS";
|
|
474
|
+
Tokens2["WCOP"] = "WCOP";
|
|
475
|
+
Tokens2["WMXN"] = "WMXN";
|
|
476
|
+
Tokens2["WBRL"] = "WBRL";
|
|
477
|
+
Tokens2["WPEN"] = "WPEN";
|
|
478
|
+
Tokens2["WCLP"] = "WCLP";
|
|
479
|
+
Tokens2["EURC"] = "EURC";
|
|
480
|
+
return Tokens2;
|
|
481
|
+
})(Tokens || {});
|
|
482
|
+
var TokenDecimals = {
|
|
483
|
+
["USDCE" /* USDC */]: 6,
|
|
484
|
+
["WLD" /* WLD */]: 18,
|
|
485
|
+
["WARS" /* WARS */]: 18,
|
|
486
|
+
["WCOP" /* WCOP */]: 18,
|
|
487
|
+
["WMXN" /* WMXN */]: 18,
|
|
488
|
+
["WBRL" /* WBRL */]: 18,
|
|
489
|
+
["WPEN" /* WPEN */]: 18,
|
|
490
|
+
["WCLP" /* WCLP */]: 18,
|
|
491
|
+
["EURC" /* EURC */]: 6
|
|
492
|
+
};
|
|
493
|
+
var Network = /* @__PURE__ */ ((Network2) => {
|
|
494
|
+
Network2["WorldChain"] = "worldchain";
|
|
495
|
+
return Network2;
|
|
496
|
+
})(Network || {});
|
|
497
|
+
var PaymentErrorCodes = /* @__PURE__ */ ((PaymentErrorCodes2) => {
|
|
498
|
+
PaymentErrorCodes2["InputError"] = "input_error";
|
|
499
|
+
PaymentErrorCodes2["UserRejected"] = "user_rejected";
|
|
500
|
+
PaymentErrorCodes2["PaymentRejected"] = "payment_rejected";
|
|
501
|
+
PaymentErrorCodes2["InvalidReceiver"] = "invalid_receiver";
|
|
502
|
+
PaymentErrorCodes2["InsufficientBalance"] = "insufficient_balance";
|
|
503
|
+
PaymentErrorCodes2["TransactionFailed"] = "transaction_failed";
|
|
504
|
+
PaymentErrorCodes2["GenericError"] = "generic_error";
|
|
505
|
+
PaymentErrorCodes2["UserBlocked"] = "user_blocked";
|
|
506
|
+
return PaymentErrorCodes2;
|
|
507
|
+
})(PaymentErrorCodes || {});
|
|
508
|
+
var PaymentErrorMessage = {
|
|
509
|
+
["input_error" /* InputError */]: "There was a problem with this request. Please try again or contact the app owner.",
|
|
510
|
+
["user_rejected" /* UserRejected */]: "You have cancelled the payment in World App.",
|
|
511
|
+
["payment_rejected" /* PaymentRejected */]: "You've cancelled the payment in World App.",
|
|
512
|
+
["invalid_receiver" /* InvalidReceiver */]: "The receiver address is invalid. Please contact the app owner.",
|
|
513
|
+
["insufficient_balance" /* InsufficientBalance */]: "You do not have enough balance to complete this transaction.",
|
|
514
|
+
["transaction_failed" /* TransactionFailed */]: "The transaction failed. Please try again.",
|
|
515
|
+
["generic_error" /* GenericError */]: "Something unexpected went wrong. Please try again.",
|
|
516
|
+
["user_blocked" /* UserBlocked */]: "User's region is blocked from making payments."
|
|
517
|
+
};
|
|
518
|
+
var PayError = class extends Error {
|
|
519
|
+
constructor(code) {
|
|
520
|
+
super(`Payment failed: ${code}`);
|
|
521
|
+
this.name = "PayError";
|
|
522
|
+
this.code = code;
|
|
523
|
+
}
|
|
524
|
+
};
|
|
525
|
+
|
|
526
|
+
// src/commands/pay/validate.ts
|
|
527
|
+
var tokenToDecimals = (amount, token) => {
|
|
528
|
+
const decimals = TokenDecimals[token];
|
|
529
|
+
if (decimals === void 0) {
|
|
530
|
+
throw new Error(`Invalid token: ${token}`);
|
|
531
|
+
}
|
|
532
|
+
const factor = 10 ** decimals;
|
|
533
|
+
const result = amount * factor;
|
|
534
|
+
if (!Number.isInteger(result)) {
|
|
535
|
+
throw new Error(`The resulting amount is not a whole number: ${result}`);
|
|
536
|
+
}
|
|
537
|
+
return result;
|
|
538
|
+
};
|
|
539
|
+
var validatePaymentPayload = (payload) => {
|
|
540
|
+
if (payload.tokens.some(
|
|
541
|
+
(token) => token.symbol == "USDCE" /* USDC */ && parseFloat(token.token_amount) < 0.1
|
|
542
|
+
)) {
|
|
543
|
+
console.error("USDC amount should be greater than $0.1");
|
|
544
|
+
return false;
|
|
545
|
+
}
|
|
546
|
+
if (payload.reference.length > 36) {
|
|
547
|
+
console.error("Reference must not exceed 36 characters");
|
|
548
|
+
return false;
|
|
549
|
+
}
|
|
550
|
+
if (typeof payload.reference !== "string") {
|
|
551
|
+
throw new Error("Reference must be a string");
|
|
552
|
+
}
|
|
553
|
+
return true;
|
|
554
|
+
};
|
|
555
|
+
|
|
556
|
+
// src/commands/pay/index.ts
|
|
557
|
+
async function pay(options, ctx) {
|
|
558
|
+
const result = await executeWithFallback({
|
|
559
|
+
command: "pay" /* Pay */,
|
|
560
|
+
nativeExecutor: () => nativePay(options, ctx),
|
|
561
|
+
// No Wagmi fallback - pay is native only
|
|
562
|
+
customFallback: options.fallback
|
|
563
|
+
});
|
|
564
|
+
if (result.executedWith === "fallback") {
|
|
565
|
+
return { executedWith: "fallback", data: result.data };
|
|
566
|
+
}
|
|
567
|
+
return { executedWith: "minikit", data: result.data };
|
|
568
|
+
}
|
|
569
|
+
async function nativePay(options, ctx) {
|
|
570
|
+
if (!ctx) {
|
|
571
|
+
ctx = { events: new EventManager(), state: { deviceProperties: {} } };
|
|
572
|
+
}
|
|
573
|
+
if (typeof window === "undefined" || !isCommandAvailable("pay" /* Pay */)) {
|
|
574
|
+
throw new Error(
|
|
575
|
+
"'pay' command is unavailable. Check MiniKit.install() or update the app version"
|
|
576
|
+
);
|
|
577
|
+
}
|
|
578
|
+
const input = {
|
|
579
|
+
reference: options.reference,
|
|
580
|
+
to: options.to,
|
|
581
|
+
tokens: options.tokens,
|
|
582
|
+
description: options.description,
|
|
583
|
+
network: options.network
|
|
584
|
+
};
|
|
585
|
+
if (!validatePaymentPayload(input)) {
|
|
586
|
+
throw new Error("Invalid payment payload");
|
|
587
|
+
}
|
|
588
|
+
const eventPayload = {
|
|
589
|
+
...input,
|
|
590
|
+
network: "worldchain" /* WorldChain */
|
|
591
|
+
};
|
|
592
|
+
const finalPayload = await new Promise(
|
|
593
|
+
(resolve, reject) => {
|
|
594
|
+
try {
|
|
595
|
+
ctx.events.subscribe("miniapp-payment" /* MiniAppPayment */, (response) => {
|
|
596
|
+
ctx.events.unsubscribe("miniapp-payment" /* MiniAppPayment */);
|
|
597
|
+
resolve(response);
|
|
598
|
+
});
|
|
599
|
+
sendMiniKitEvent({
|
|
600
|
+
command: "pay" /* Pay */,
|
|
601
|
+
version: COMMAND_VERSIONS["pay" /* Pay */],
|
|
602
|
+
payload: eventPayload
|
|
603
|
+
});
|
|
604
|
+
} catch (error) {
|
|
605
|
+
reject(error);
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
);
|
|
609
|
+
if (finalPayload.status === "error") {
|
|
610
|
+
throw new PayError(finalPayload.error_code);
|
|
611
|
+
}
|
|
612
|
+
return {
|
|
613
|
+
transactionId: finalPayload.transaction_id,
|
|
614
|
+
reference: finalPayload.reference,
|
|
615
|
+
from: finalPayload.from,
|
|
616
|
+
chain: finalPayload.chain,
|
|
617
|
+
timestamp: finalPayload.timestamp
|
|
618
|
+
};
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
// src/commands/request-permission/types.ts
|
|
622
|
+
var RequestPermissionErrorCodes = /* @__PURE__ */ ((RequestPermissionErrorCodes2) => {
|
|
623
|
+
RequestPermissionErrorCodes2["UserRejected"] = "user_rejected";
|
|
624
|
+
RequestPermissionErrorCodes2["GenericError"] = "generic_error";
|
|
625
|
+
RequestPermissionErrorCodes2["AlreadyRequested"] = "already_requested";
|
|
626
|
+
RequestPermissionErrorCodes2["PermissionDisabled"] = "permission_disabled";
|
|
627
|
+
RequestPermissionErrorCodes2["AlreadyGranted"] = "already_granted";
|
|
628
|
+
RequestPermissionErrorCodes2["UnsupportedPermission"] = "unsupported_permission";
|
|
629
|
+
return RequestPermissionErrorCodes2;
|
|
630
|
+
})(RequestPermissionErrorCodes || {});
|
|
631
|
+
var RequestPermissionError = class extends Error {
|
|
632
|
+
constructor(error_code) {
|
|
633
|
+
super(`Request permission failed: ${error_code}`);
|
|
634
|
+
this.error_code = error_code;
|
|
635
|
+
this.name = "RequestPermissionError";
|
|
636
|
+
}
|
|
637
|
+
};
|
|
638
|
+
|
|
639
|
+
// src/commands/request-permission/index.ts
|
|
640
|
+
async function requestPermission(options, ctx) {
|
|
641
|
+
const result = await executeWithFallback({
|
|
642
|
+
command: "request-permission" /* RequestPermission */,
|
|
643
|
+
nativeExecutor: () => nativeRequestPermission(options, ctx),
|
|
644
|
+
customFallback: options.fallback
|
|
645
|
+
});
|
|
646
|
+
if (result.executedWith === "fallback") {
|
|
647
|
+
return { executedWith: "fallback", data: result.data };
|
|
648
|
+
}
|
|
649
|
+
return {
|
|
650
|
+
executedWith: "minikit",
|
|
651
|
+
data: result.data
|
|
652
|
+
};
|
|
653
|
+
}
|
|
654
|
+
async function nativeRequestPermission(options, ctx) {
|
|
655
|
+
if (!ctx) {
|
|
656
|
+
ctx = { events: new EventManager(), state: { deviceProperties: {} } };
|
|
657
|
+
}
|
|
658
|
+
if (typeof window === "undefined" || !isCommandAvailable("request-permission" /* RequestPermission */)) {
|
|
659
|
+
throw new Error(
|
|
660
|
+
"'requestPermission' command is unavailable. Check MiniKit.install() or update the app version"
|
|
661
|
+
);
|
|
662
|
+
}
|
|
663
|
+
const payload = await new Promise(
|
|
664
|
+
(resolve, reject) => {
|
|
665
|
+
try {
|
|
666
|
+
ctx.events.subscribe("miniapp-request-permission" /* MiniAppRequestPermission */, (response) => {
|
|
667
|
+
ctx.events.unsubscribe("miniapp-request-permission" /* MiniAppRequestPermission */);
|
|
668
|
+
resolve(response);
|
|
669
|
+
});
|
|
670
|
+
sendMiniKitEvent({
|
|
671
|
+
command: "request-permission" /* RequestPermission */,
|
|
672
|
+
version: COMMAND_VERSIONS["request-permission" /* RequestPermission */],
|
|
673
|
+
payload: { permission: options.permission }
|
|
674
|
+
});
|
|
675
|
+
} catch (error) {
|
|
676
|
+
reject(error);
|
|
677
|
+
}
|
|
678
|
+
}
|
|
679
|
+
);
|
|
680
|
+
if (payload.status === "error") {
|
|
681
|
+
throw new RequestPermissionError(payload.error_code);
|
|
682
|
+
}
|
|
683
|
+
return payload;
|
|
684
|
+
}
|
|
685
|
+
|
|
686
|
+
// src/commands/send-haptic-feedback/types.ts
|
|
687
|
+
var SendHapticFeedbackErrorCodes = /* @__PURE__ */ ((SendHapticFeedbackErrorCodes2) => {
|
|
688
|
+
SendHapticFeedbackErrorCodes2["GenericError"] = "generic_error";
|
|
689
|
+
SendHapticFeedbackErrorCodes2["UserRejected"] = "user_rejected";
|
|
690
|
+
return SendHapticFeedbackErrorCodes2;
|
|
691
|
+
})(SendHapticFeedbackErrorCodes || {});
|
|
692
|
+
var SendHapticFeedbackError = class extends Error {
|
|
693
|
+
constructor(error_code) {
|
|
694
|
+
super(`Send haptic feedback failed: ${error_code}`);
|
|
695
|
+
this.error_code = error_code;
|
|
696
|
+
this.name = "SendHapticFeedbackError";
|
|
697
|
+
}
|
|
698
|
+
};
|
|
699
|
+
|
|
700
|
+
// src/commands/send-haptic-feedback/index.ts
|
|
701
|
+
async function sendHapticFeedback(options, ctx) {
|
|
702
|
+
const result = await executeWithFallback({
|
|
703
|
+
command: "send-haptic-feedback" /* SendHapticFeedback */,
|
|
704
|
+
nativeExecutor: () => nativeSendHapticFeedback(options, ctx),
|
|
705
|
+
customFallback: options.fallback
|
|
706
|
+
});
|
|
707
|
+
if (result.executedWith === "fallback") {
|
|
708
|
+
return { executedWith: "fallback", data: result.data };
|
|
709
|
+
}
|
|
710
|
+
return {
|
|
711
|
+
executedWith: "minikit",
|
|
712
|
+
data: result.data
|
|
713
|
+
};
|
|
714
|
+
}
|
|
715
|
+
async function nativeSendHapticFeedback(options, ctx) {
|
|
716
|
+
if (!ctx) {
|
|
717
|
+
ctx = { events: new EventManager(), state: { deviceProperties: {} } };
|
|
718
|
+
}
|
|
719
|
+
if (typeof window === "undefined" || !isCommandAvailable("send-haptic-feedback" /* SendHapticFeedback */)) {
|
|
720
|
+
throw new Error(
|
|
721
|
+
"'sendHapticFeedback' command is unavailable. Check MiniKit.install() or update the app version"
|
|
722
|
+
);
|
|
723
|
+
}
|
|
724
|
+
const payloadInput = options.hapticsType === "selection-changed" ? { hapticsType: "selection-changed" } : options.hapticsType === "impact" ? {
|
|
725
|
+
hapticsType: "impact",
|
|
726
|
+
style: options.style
|
|
727
|
+
} : {
|
|
728
|
+
hapticsType: "notification",
|
|
729
|
+
style: options.style
|
|
730
|
+
};
|
|
731
|
+
const payload = await new Promise(
|
|
732
|
+
(resolve, reject) => {
|
|
733
|
+
try {
|
|
734
|
+
ctx.events.subscribe("miniapp-send-haptic-feedback" /* MiniAppSendHapticFeedback */, (response) => {
|
|
735
|
+
ctx.events.unsubscribe("miniapp-send-haptic-feedback" /* MiniAppSendHapticFeedback */);
|
|
736
|
+
resolve(response);
|
|
737
|
+
});
|
|
738
|
+
sendMiniKitEvent({
|
|
739
|
+
command: "send-haptic-feedback" /* SendHapticFeedback */,
|
|
740
|
+
version: COMMAND_VERSIONS["send-haptic-feedback" /* SendHapticFeedback */],
|
|
741
|
+
payload: payloadInput
|
|
742
|
+
});
|
|
743
|
+
} catch (error) {
|
|
744
|
+
reject(error);
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
);
|
|
748
|
+
if (payload.status === "error") {
|
|
749
|
+
throw new SendHapticFeedbackError(payload.error_code);
|
|
750
|
+
}
|
|
751
|
+
return payload;
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
// src/commands/send-transaction/types.ts
|
|
755
|
+
var SendTransactionErrorCodes = /* @__PURE__ */ ((SendTransactionErrorCodes2) => {
|
|
756
|
+
SendTransactionErrorCodes2["InvalidOperation"] = "invalid_operation";
|
|
757
|
+
SendTransactionErrorCodes2["UserRejected"] = "user_rejected";
|
|
758
|
+
SendTransactionErrorCodes2["InputError"] = "input_error";
|
|
759
|
+
SendTransactionErrorCodes2["SimulationFailed"] = "simulation_failed";
|
|
760
|
+
SendTransactionErrorCodes2["TransactionFailed"] = "transaction_failed";
|
|
761
|
+
SendTransactionErrorCodes2["GenericError"] = "generic_error";
|
|
762
|
+
SendTransactionErrorCodes2["DisallowedOperation"] = "disallowed_operation";
|
|
763
|
+
SendTransactionErrorCodes2["ValidationError"] = "validation_error";
|
|
764
|
+
SendTransactionErrorCodes2["InvalidContract"] = "invalid_contract";
|
|
765
|
+
SendTransactionErrorCodes2["MaliciousOperation"] = "malicious_operation";
|
|
766
|
+
SendTransactionErrorCodes2["DailyTxLimitReached"] = "daily_tx_limit_reached";
|
|
767
|
+
SendTransactionErrorCodes2["PermittedAmountExceedsSlippage"] = "permitted_amount_exceeds_slippage";
|
|
768
|
+
SendTransactionErrorCodes2["PermittedAmountNotFound"] = "permitted_amount_not_found";
|
|
769
|
+
return SendTransactionErrorCodes2;
|
|
770
|
+
})(SendTransactionErrorCodes || {});
|
|
771
|
+
var SendTransactionErrorMessage = {
|
|
772
|
+
["invalid_operation" /* InvalidOperation */]: "Transaction included an operation that was invalid",
|
|
773
|
+
["user_rejected" /* UserRejected */]: "User rejected the request.",
|
|
774
|
+
["input_error" /* InputError */]: "Invalid payload.",
|
|
775
|
+
["simulation_failed" /* SimulationFailed */]: "The transaction simulation failed.",
|
|
776
|
+
["validation_error" /* ValidationError */]: "The transaction validation failed. Please try again.",
|
|
777
|
+
["transaction_failed" /* TransactionFailed */]: "The transaction failed. Please try again later.",
|
|
778
|
+
["generic_error" /* GenericError */]: "Something unexpected went wrong. Please try again.",
|
|
779
|
+
["disallowed_operation" /* DisallowedOperation */]: "The operation requested is not allowed. Please refer to the docs.",
|
|
780
|
+
["invalid_contract" /* InvalidContract */]: "The contract address is not allowed for your application. Please check your developer portal configurations",
|
|
781
|
+
["malicious_operation" /* MaliciousOperation */]: "The operation requested is considered malicious.",
|
|
782
|
+
["daily_tx_limit_reached" /* DailyTxLimitReached */]: "Daily transaction limit reached. Max 100 transactions per day. Wait until the next day.",
|
|
783
|
+
["permitted_amount_exceeds_slippage" /* PermittedAmountExceedsSlippage */]: "Permitted amount exceeds slippage. You must spend at least 90% of the permitted amount.",
|
|
784
|
+
["permitted_amount_not_found" /* PermittedAmountNotFound */]: "Permitted amount not found in permit2 payload."
|
|
785
|
+
};
|
|
786
|
+
var WORLD_APP_FEATURES = {
|
|
787
|
+
batch: true,
|
|
788
|
+
permit2: true,
|
|
789
|
+
gasSponsorship: true
|
|
790
|
+
};
|
|
791
|
+
var WEB_FEATURES = {
|
|
792
|
+
batch: false,
|
|
793
|
+
permit2: false,
|
|
794
|
+
gasSponsorship: false
|
|
795
|
+
};
|
|
796
|
+
var SendTransactionError = class extends Error {
|
|
797
|
+
constructor(code, details) {
|
|
798
|
+
super(`Transaction failed: ${code}`);
|
|
799
|
+
this.name = "SendTransactionError";
|
|
800
|
+
this.code = code;
|
|
801
|
+
this.details = details;
|
|
802
|
+
}
|
|
803
|
+
};
|
|
804
|
+
|
|
805
|
+
// src/commands/fallback-adapter-registry.ts
|
|
806
|
+
var FALLBACK_ADAPTER_KEY = "__minikit_fallback_adapter__";
|
|
807
|
+
function setFallbackAdapter(adapter) {
|
|
808
|
+
globalThis[FALLBACK_ADAPTER_KEY] = adapter;
|
|
809
|
+
}
|
|
810
|
+
function getFallbackAdapter() {
|
|
811
|
+
return globalThis[FALLBACK_ADAPTER_KEY];
|
|
812
|
+
}
|
|
813
|
+
|
|
814
|
+
// src/commands/send-transaction/validate.ts
|
|
815
|
+
var isValidHex = (str) => {
|
|
816
|
+
return /^0x[0-9A-Fa-f]+$/.test(str);
|
|
817
|
+
};
|
|
818
|
+
var processPayload = (payload) => {
|
|
819
|
+
if (typeof payload === "boolean" || typeof payload === "string" || payload === null || payload === void 0) {
|
|
820
|
+
return payload;
|
|
821
|
+
}
|
|
822
|
+
if (typeof payload === "number" || typeof payload === "bigint") {
|
|
823
|
+
return String(payload);
|
|
824
|
+
}
|
|
825
|
+
if (Array.isArray(payload)) {
|
|
826
|
+
return payload.map((value) => processPayload(value));
|
|
827
|
+
}
|
|
828
|
+
if (typeof payload === "object") {
|
|
829
|
+
const result = { ...payload };
|
|
830
|
+
if ("chainId" in result && result.chainId !== void 0) {
|
|
831
|
+
if (typeof result.chainId === "string") {
|
|
832
|
+
const parsed = Number(result.chainId);
|
|
833
|
+
if (Number.isFinite(parsed)) {
|
|
834
|
+
result.chainId = parsed;
|
|
835
|
+
}
|
|
836
|
+
} else if (typeof result.chainId === "bigint") {
|
|
837
|
+
const parsed = Number(result.chainId);
|
|
838
|
+
if (!Number.isSafeInteger(parsed)) {
|
|
839
|
+
throw new Error(`Invalid chainId: ${String(result.chainId)}`);
|
|
840
|
+
}
|
|
841
|
+
result.chainId = parsed;
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
if ("value" in result && result.value !== void 0) {
|
|
845
|
+
if (typeof result.value !== "string") {
|
|
846
|
+
result.value = String(result.value);
|
|
847
|
+
}
|
|
848
|
+
if (!isValidHex(result.value)) {
|
|
849
|
+
console.error(
|
|
850
|
+
"Transaction value must be a valid hex string",
|
|
851
|
+
result.value
|
|
852
|
+
);
|
|
853
|
+
throw new Error(
|
|
854
|
+
`Transaction value must be a valid hex string: ${result.value}`
|
|
855
|
+
);
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
for (const key in result) {
|
|
859
|
+
if (Object.prototype.hasOwnProperty.call(result, key)) {
|
|
860
|
+
if (key === "chainId") continue;
|
|
861
|
+
result[key] = processPayload(result[key]);
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
return result;
|
|
865
|
+
}
|
|
866
|
+
return payload;
|
|
867
|
+
};
|
|
868
|
+
var validateSendTransactionPayload = (payload) => {
|
|
869
|
+
return processPayload(payload);
|
|
870
|
+
};
|
|
871
|
+
|
|
872
|
+
// src/commands/send-transaction/index.ts
|
|
873
|
+
var WORLD_CHAIN_ID = 480;
|
|
874
|
+
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.";
|
|
875
|
+
function resolveChainId(options) {
|
|
876
|
+
return options.chainId;
|
|
877
|
+
}
|
|
878
|
+
function resolveTransactions(options) {
|
|
879
|
+
if (options.transactions.length === 0) {
|
|
880
|
+
throw new SendTransactionError("input_error" /* InputError */, {
|
|
881
|
+
reason: "At least one transaction is required. Use `transactions: [{ to, data, value }]`."
|
|
882
|
+
});
|
|
883
|
+
}
|
|
884
|
+
return options.transactions;
|
|
885
|
+
}
|
|
886
|
+
function normalizeSendTransactionOptions(options) {
|
|
887
|
+
const chainId = resolveChainId(options);
|
|
888
|
+
if (chainId !== WORLD_CHAIN_ID) {
|
|
889
|
+
throw new SendTransactionError("invalid_operation" /* InvalidOperation */, {
|
|
890
|
+
reason: `World App only supports World Chain (chainId: ${WORLD_CHAIN_ID})`
|
|
891
|
+
});
|
|
892
|
+
}
|
|
893
|
+
return {
|
|
894
|
+
transactions: resolveTransactions(options),
|
|
895
|
+
chainId
|
|
896
|
+
};
|
|
897
|
+
}
|
|
898
|
+
async function sendTransaction(options, ctx) {
|
|
899
|
+
const normalizedOptions = normalizeSendTransactionOptions(options);
|
|
900
|
+
const fallbackAdapter = getFallbackAdapter();
|
|
901
|
+
const isWagmiFallbackPath = !isInWorldApp() && Boolean(fallbackAdapter?.sendTransaction);
|
|
902
|
+
if (isWagmiFallbackPath && normalizedOptions.transactions.length > 1 && !options.fallback) {
|
|
903
|
+
throw new SendTransactionError("invalid_operation" /* InvalidOperation */, {
|
|
904
|
+
reason: WAGMI_MULTI_TX_ERROR_MESSAGE
|
|
905
|
+
});
|
|
906
|
+
}
|
|
907
|
+
const result = await executeWithFallback({
|
|
908
|
+
command: "send-transaction" /* SendTransaction */,
|
|
909
|
+
nativeExecutor: () => nativeSendTransaction(normalizedOptions, ctx),
|
|
910
|
+
wagmiFallback: fallbackAdapter?.sendTransaction ? () => adapterSendTransactionFallback(normalizedOptions) : void 0,
|
|
911
|
+
customFallback: options.fallback
|
|
912
|
+
});
|
|
913
|
+
if (result.executedWith === "fallback") {
|
|
914
|
+
return { executedWith: "fallback", data: result.data };
|
|
915
|
+
}
|
|
916
|
+
if (result.executedWith === "wagmi") {
|
|
917
|
+
return {
|
|
918
|
+
executedWith: "wagmi",
|
|
919
|
+
data: result.data
|
|
920
|
+
};
|
|
921
|
+
}
|
|
922
|
+
return {
|
|
923
|
+
executedWith: "minikit",
|
|
924
|
+
data: result.data
|
|
925
|
+
};
|
|
926
|
+
}
|
|
927
|
+
async function nativeSendTransaction(options, ctx) {
|
|
928
|
+
if (!ctx) {
|
|
929
|
+
ctx = { events: new EventManager(), state: { deviceProperties: {} } };
|
|
930
|
+
}
|
|
931
|
+
if (typeof window === "undefined" || !isCommandAvailable("send-transaction" /* SendTransaction */)) {
|
|
932
|
+
throw new Error(
|
|
933
|
+
"'sendTransaction' command is unavailable. Check MiniKit.install() or update the app version"
|
|
934
|
+
);
|
|
935
|
+
}
|
|
936
|
+
if (options.chainId !== WORLD_CHAIN_ID) {
|
|
937
|
+
throw new Error(
|
|
938
|
+
`World App only supports World Chain (chainId: ${WORLD_CHAIN_ID})`
|
|
939
|
+
);
|
|
940
|
+
}
|
|
941
|
+
const commandInput = window.WorldApp?.supported_commands.find(
|
|
942
|
+
(command) => command.name === "send-transaction" /* SendTransaction */
|
|
943
|
+
);
|
|
944
|
+
if (commandInput && !commandInput.supported_versions.includes(
|
|
945
|
+
COMMAND_VERSIONS["send-transaction" /* SendTransaction */]
|
|
946
|
+
)) {
|
|
947
|
+
throw new CommandUnavailableError("send-transaction" /* SendTransaction */, "oldAppVersion");
|
|
948
|
+
}
|
|
949
|
+
const input = {
|
|
950
|
+
transactions: options.transactions,
|
|
951
|
+
chainId: options.chainId
|
|
952
|
+
};
|
|
953
|
+
const validatedPayload = validateSendTransactionPayload(input);
|
|
954
|
+
const finalPayload = await new Promise(
|
|
955
|
+
(resolve, reject) => {
|
|
956
|
+
try {
|
|
957
|
+
ctx.events.subscribe("miniapp-send-transaction" /* MiniAppSendTransaction */, (response) => {
|
|
958
|
+
ctx.events.unsubscribe("miniapp-send-transaction" /* MiniAppSendTransaction */);
|
|
959
|
+
resolve(response);
|
|
960
|
+
});
|
|
961
|
+
sendMiniKitEvent({
|
|
962
|
+
command: "send-transaction" /* SendTransaction */,
|
|
963
|
+
version: COMMAND_VERSIONS["send-transaction" /* SendTransaction */],
|
|
964
|
+
payload: validatedPayload
|
|
965
|
+
});
|
|
966
|
+
} catch (error) {
|
|
967
|
+
reject(error);
|
|
968
|
+
}
|
|
969
|
+
}
|
|
970
|
+
);
|
|
971
|
+
if (finalPayload.status === "error") {
|
|
972
|
+
throw new SendTransactionError(
|
|
973
|
+
finalPayload.error_code,
|
|
974
|
+
finalPayload.details
|
|
975
|
+
);
|
|
976
|
+
}
|
|
977
|
+
const successPayload = finalPayload;
|
|
978
|
+
return {
|
|
979
|
+
userOpHash: String(successPayload.userOpHash ?? ""),
|
|
980
|
+
status: finalPayload.status,
|
|
981
|
+
version: finalPayload.version,
|
|
982
|
+
from: String(successPayload.from ?? ""),
|
|
983
|
+
timestamp: String(successPayload.timestamp ?? (/* @__PURE__ */ new Date()).toISOString())
|
|
984
|
+
};
|
|
985
|
+
}
|
|
986
|
+
async function adapterSendTransactionFallback(options) {
|
|
987
|
+
if (options.transactions.length > 1) {
|
|
988
|
+
throw new Error(WAGMI_MULTI_TX_ERROR_MESSAGE);
|
|
989
|
+
}
|
|
990
|
+
const firstTransaction = options.transactions[0];
|
|
991
|
+
if (!firstTransaction) {
|
|
992
|
+
throw new Error("At least one transaction is required");
|
|
993
|
+
}
|
|
994
|
+
const fallbackAdapter = getFallbackAdapter();
|
|
995
|
+
if (!fallbackAdapter?.sendTransaction) {
|
|
996
|
+
throw new Error("Fallback adapter is not registered.");
|
|
997
|
+
}
|
|
998
|
+
const result = await fallbackAdapter.sendTransaction({
|
|
999
|
+
transaction: {
|
|
1000
|
+
address: firstTransaction.to,
|
|
1001
|
+
data: firstTransaction.data,
|
|
1002
|
+
value: firstTransaction.value
|
|
1003
|
+
},
|
|
1004
|
+
chainId: options.chainId
|
|
1005
|
+
});
|
|
1006
|
+
return {
|
|
1007
|
+
userOpHash: result.transactionHash,
|
|
1008
|
+
status: "success",
|
|
1009
|
+
version: COMMAND_VERSIONS["send-transaction" /* SendTransaction */],
|
|
1010
|
+
from: "",
|
|
1011
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
1012
|
+
};
|
|
1013
|
+
}
|
|
1014
|
+
|
|
1015
|
+
// src/commands/share/types.ts
|
|
1016
|
+
var ShareFilesErrorCodes = /* @__PURE__ */ ((ShareFilesErrorCodes2) => {
|
|
1017
|
+
ShareFilesErrorCodes2["UserRejected"] = "user_rejected";
|
|
1018
|
+
ShareFilesErrorCodes2["GenericError"] = "generic_error";
|
|
1019
|
+
ShareFilesErrorCodes2["InvalidFileName"] = "invalid_file_name";
|
|
1020
|
+
return ShareFilesErrorCodes2;
|
|
1021
|
+
})(ShareFilesErrorCodes || {});
|
|
1022
|
+
var ShareError = class extends Error {
|
|
1023
|
+
constructor(error_code) {
|
|
1024
|
+
super(`Share failed: ${error_code}`);
|
|
1025
|
+
this.error_code = error_code;
|
|
1026
|
+
this.name = "ShareError";
|
|
1027
|
+
}
|
|
1028
|
+
};
|
|
1029
|
+
|
|
1030
|
+
// src/commands/share/format.ts
|
|
1031
|
+
var MAX_FILES = 10;
|
|
1032
|
+
var MAX_TOTAL_SIZE_MB = 50;
|
|
1033
|
+
var MAX_TOTAL_SIZE_BYTES = MAX_TOTAL_SIZE_MB * 1024 * 1024;
|
|
1034
|
+
var processFile = async (file) => {
|
|
1035
|
+
const buffer = await file.arrayBuffer();
|
|
1036
|
+
const uint8Array = new Uint8Array(buffer);
|
|
1037
|
+
let binaryString = "";
|
|
1038
|
+
const K_CHUNK_SIZE = 32768;
|
|
1039
|
+
for (let i = 0; i < uint8Array.length; i += K_CHUNK_SIZE) {
|
|
1040
|
+
const chunk = uint8Array.subarray(
|
|
1041
|
+
i,
|
|
1042
|
+
Math.min(i + K_CHUNK_SIZE, uint8Array.length)
|
|
1043
|
+
);
|
|
1044
|
+
binaryString += String.fromCharCode.apply(
|
|
1045
|
+
null,
|
|
1046
|
+
Array.from(chunk)
|
|
1047
|
+
// Convert Uint8Array chunk to number[]
|
|
1048
|
+
);
|
|
1049
|
+
}
|
|
1050
|
+
const base64Data = btoa(binaryString);
|
|
1051
|
+
return {
|
|
1052
|
+
name: file.name,
|
|
1053
|
+
type: file.type,
|
|
1054
|
+
data: base64Data
|
|
1055
|
+
};
|
|
1056
|
+
};
|
|
1057
|
+
var formatShareInput = async (input) => {
|
|
1058
|
+
if (!input.files) {
|
|
1059
|
+
return {
|
|
1060
|
+
title: input.title,
|
|
1061
|
+
text: input.text,
|
|
1062
|
+
url: input.url
|
|
1063
|
+
};
|
|
1064
|
+
}
|
|
1065
|
+
if (!Array.isArray(input.files)) {
|
|
1066
|
+
throw new Error('The "files" property must be an array.');
|
|
1067
|
+
}
|
|
1068
|
+
if (input.files.length === 0) {
|
|
1069
|
+
} else {
|
|
1070
|
+
if (input.files.length > MAX_FILES) {
|
|
1071
|
+
throw new Error(`Cannot share more than ${MAX_FILES} files.`);
|
|
1072
|
+
}
|
|
1073
|
+
let totalSize = 0;
|
|
1074
|
+
for (const file of input.files) {
|
|
1075
|
+
if (!(file instanceof File)) {
|
|
1076
|
+
throw new Error(
|
|
1077
|
+
`Each item in the 'files' array must be a File object. Received: ${typeof file}`
|
|
1078
|
+
);
|
|
1079
|
+
}
|
|
1080
|
+
totalSize += file.size;
|
|
1081
|
+
}
|
|
1082
|
+
if (totalSize > MAX_TOTAL_SIZE_BYTES) {
|
|
1083
|
+
throw new Error(`Total file size cannot exceed ${MAX_TOTAL_SIZE_MB}MB.`);
|
|
1084
|
+
}
|
|
1085
|
+
}
|
|
1086
|
+
const fileProcessingPromises = input.files.map((file) => processFile(file));
|
|
1087
|
+
const processedFiles = await Promise.all(fileProcessingPromises);
|
|
1088
|
+
return {
|
|
1089
|
+
files: processedFiles,
|
|
1090
|
+
title: input.title,
|
|
1091
|
+
text: input.text,
|
|
1092
|
+
url: input.url
|
|
1093
|
+
};
|
|
1094
|
+
};
|
|
1095
|
+
|
|
1096
|
+
// src/commands/share/index.ts
|
|
1097
|
+
async function share(options, ctx) {
|
|
1098
|
+
const result = await executeWithFallback({
|
|
1099
|
+
command: "share" /* Share */,
|
|
1100
|
+
nativeExecutor: () => nativeShare(options, ctx),
|
|
1101
|
+
customFallback: options.fallback
|
|
1102
|
+
});
|
|
1103
|
+
if (result.executedWith === "fallback") {
|
|
1104
|
+
return {
|
|
1105
|
+
executedWith: "fallback",
|
|
1106
|
+
data: result.data
|
|
1107
|
+
};
|
|
1108
|
+
}
|
|
1109
|
+
return {
|
|
1110
|
+
executedWith: "minikit",
|
|
1111
|
+
data: result.data
|
|
1112
|
+
};
|
|
1113
|
+
}
|
|
1114
|
+
async function nativeShare(options, ctx) {
|
|
1115
|
+
if (!ctx) {
|
|
1116
|
+
ctx = { events: new EventManager(), state: { deviceProperties: {} } };
|
|
1117
|
+
}
|
|
1118
|
+
if (typeof window === "undefined" || !isCommandAvailable("share" /* Share */)) {
|
|
1119
|
+
throw new Error(
|
|
1120
|
+
"'share' command is unavailable. Check MiniKit.install() or update the app version"
|
|
1121
|
+
);
|
|
1122
|
+
}
|
|
1123
|
+
const payloadInput = {
|
|
1124
|
+
files: options.files,
|
|
1125
|
+
title: options.title,
|
|
1126
|
+
text: options.text,
|
|
1127
|
+
url: options.url
|
|
1128
|
+
};
|
|
1129
|
+
if (ctx.state.deviceProperties.deviceOS === "ios" && typeof navigator !== "undefined") {
|
|
1130
|
+
sendMiniKitEvent({
|
|
1131
|
+
command: "share" /* Share */,
|
|
1132
|
+
version: COMMAND_VERSIONS["share" /* Share */],
|
|
1133
|
+
payload: payloadInput
|
|
1134
|
+
});
|
|
1135
|
+
await navigator.share(payloadInput);
|
|
1136
|
+
return {
|
|
1137
|
+
status: "success",
|
|
1138
|
+
version: COMMAND_VERSIONS["share" /* Share */],
|
|
1139
|
+
shared_files_count: payloadInput.files?.length ?? 0,
|
|
1140
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
1141
|
+
};
|
|
1142
|
+
}
|
|
1143
|
+
const formattedPayload = await formatShareInput(payloadInput);
|
|
1144
|
+
const payload = await new Promise((resolve, reject) => {
|
|
1145
|
+
try {
|
|
1146
|
+
ctx.events.subscribe("miniapp-share" /* MiniAppShare */, (response) => {
|
|
1147
|
+
ctx.events.unsubscribe("miniapp-share" /* MiniAppShare */);
|
|
1148
|
+
resolve(response);
|
|
1149
|
+
});
|
|
1150
|
+
sendMiniKitEvent({
|
|
1151
|
+
command: "share" /* Share */,
|
|
1152
|
+
version: COMMAND_VERSIONS["share" /* Share */],
|
|
1153
|
+
payload: formattedPayload
|
|
1154
|
+
});
|
|
1155
|
+
} catch (error) {
|
|
1156
|
+
reject(error);
|
|
1157
|
+
}
|
|
1158
|
+
});
|
|
1159
|
+
if (payload.status === "error") {
|
|
1160
|
+
throw new ShareError(payload.error_code);
|
|
1161
|
+
}
|
|
1162
|
+
return payload;
|
|
1163
|
+
}
|
|
1164
|
+
|
|
1165
|
+
// src/commands/share-contacts/types.ts
|
|
1166
|
+
var ShareContactsErrorCodes = /* @__PURE__ */ ((ShareContactsErrorCodes2) => {
|
|
1167
|
+
ShareContactsErrorCodes2["UserRejected"] = "user_rejected";
|
|
1168
|
+
ShareContactsErrorCodes2["GenericError"] = "generic_error";
|
|
1169
|
+
return ShareContactsErrorCodes2;
|
|
1170
|
+
})(ShareContactsErrorCodes || {});
|
|
1171
|
+
var ShareContactsErrorMessage = {
|
|
1172
|
+
["user_rejected" /* UserRejected */]: "User rejected the request.",
|
|
1173
|
+
["generic_error" /* GenericError */]: "Something unexpected went wrong."
|
|
1174
|
+
};
|
|
1175
|
+
var ShareContactsError = class extends Error {
|
|
1176
|
+
constructor(code) {
|
|
1177
|
+
super(`Share contacts failed: ${code}`);
|
|
1178
|
+
this.name = "ShareContactsError";
|
|
1179
|
+
this.code = code;
|
|
1180
|
+
}
|
|
1181
|
+
};
|
|
1182
|
+
|
|
1183
|
+
// src/commands/share-contacts/index.ts
|
|
1184
|
+
async function shareContacts(options, ctx) {
|
|
1185
|
+
const resolvedOptions = options ?? {};
|
|
1186
|
+
const result = await executeWithFallback({
|
|
1187
|
+
command: "share-contacts" /* ShareContacts */,
|
|
1188
|
+
nativeExecutor: () => nativeShareContacts(resolvedOptions, ctx),
|
|
1189
|
+
// No Wagmi fallback - contacts is native only
|
|
1190
|
+
customFallback: resolvedOptions.fallback
|
|
1191
|
+
});
|
|
1192
|
+
if (result.executedWith === "fallback") {
|
|
1193
|
+
return { executedWith: "fallback", data: result.data };
|
|
1194
|
+
}
|
|
1195
|
+
return { executedWith: "minikit", data: result.data };
|
|
1196
|
+
}
|
|
1197
|
+
var getContacts = shareContacts;
|
|
1198
|
+
async function nativeShareContacts(options, ctx) {
|
|
1199
|
+
if (!ctx) {
|
|
1200
|
+
ctx = { events: new EventManager(), state: { deviceProperties: {} } };
|
|
1201
|
+
}
|
|
1202
|
+
if (typeof window === "undefined" || !isCommandAvailable("share-contacts" /* ShareContacts */)) {
|
|
1203
|
+
throw new Error(
|
|
1204
|
+
"'shareContacts' command is unavailable. Check MiniKit.install() or update the app version"
|
|
1205
|
+
);
|
|
1206
|
+
}
|
|
1207
|
+
const payload = {
|
|
1208
|
+
isMultiSelectEnabled: options.isMultiSelectEnabled ?? false,
|
|
1209
|
+
inviteMessage: options.inviteMessage
|
|
1210
|
+
};
|
|
1211
|
+
const finalPayload = await new Promise(
|
|
1212
|
+
(resolve, reject) => {
|
|
1213
|
+
try {
|
|
1214
|
+
ctx.events.subscribe("miniapp-share-contacts" /* MiniAppShareContacts */, (response) => {
|
|
1215
|
+
ctx.events.unsubscribe("miniapp-share-contacts" /* MiniAppShareContacts */);
|
|
1216
|
+
resolve(response);
|
|
1217
|
+
});
|
|
1218
|
+
sendMiniKitEvent({
|
|
1219
|
+
command: "share-contacts" /* ShareContacts */,
|
|
1220
|
+
version: COMMAND_VERSIONS["share-contacts" /* ShareContacts */],
|
|
1221
|
+
payload
|
|
1222
|
+
});
|
|
1223
|
+
} catch (error) {
|
|
1224
|
+
reject(error);
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
);
|
|
1228
|
+
if (finalPayload.status === "error") {
|
|
1229
|
+
throw new ShareContactsError(finalPayload.error_code);
|
|
1230
|
+
}
|
|
1231
|
+
return {
|
|
1232
|
+
contacts: finalPayload.contacts,
|
|
1233
|
+
timestamp: finalPayload.timestamp
|
|
1234
|
+
};
|
|
1235
|
+
}
|
|
1236
|
+
|
|
1237
|
+
// src/commands/sign-message/types.ts
|
|
1238
|
+
var SignMessageErrorCodes = /* @__PURE__ */ ((SignMessageErrorCodes2) => {
|
|
1239
|
+
SignMessageErrorCodes2["InvalidMessage"] = "invalid_message";
|
|
1240
|
+
SignMessageErrorCodes2["UserRejected"] = "user_rejected";
|
|
1241
|
+
SignMessageErrorCodes2["GenericError"] = "generic_error";
|
|
1242
|
+
return SignMessageErrorCodes2;
|
|
1243
|
+
})(SignMessageErrorCodes || {});
|
|
1244
|
+
var SignMessageError = class extends Error {
|
|
1245
|
+
constructor(error_code) {
|
|
1246
|
+
super(`Sign message failed: ${error_code}`);
|
|
1247
|
+
this.error_code = error_code;
|
|
1248
|
+
this.name = "SignMessageError";
|
|
1249
|
+
}
|
|
1250
|
+
};
|
|
1251
|
+
|
|
1252
|
+
// src/commands/sign-message/index.ts
|
|
1253
|
+
async function signMessage(options, ctx) {
|
|
1254
|
+
const fallbackAdapter = getFallbackAdapter();
|
|
1255
|
+
const result = await executeWithFallback({
|
|
1256
|
+
command: "sign-message" /* SignMessage */,
|
|
1257
|
+
nativeExecutor: () => nativeSignMessage(options, ctx),
|
|
1258
|
+
wagmiFallback: fallbackAdapter?.signMessage ? () => fallbackAdapter.signMessage({
|
|
1259
|
+
message: options.message
|
|
1260
|
+
}) : void 0,
|
|
1261
|
+
customFallback: options.fallback
|
|
1262
|
+
});
|
|
1263
|
+
if (result.executedWith === "fallback") {
|
|
1264
|
+
return { executedWith: "fallback", data: result.data };
|
|
1265
|
+
}
|
|
1266
|
+
if (result.executedWith === "wagmi") {
|
|
1267
|
+
return {
|
|
1268
|
+
executedWith: "wagmi",
|
|
1269
|
+
data: result.data
|
|
1270
|
+
};
|
|
1271
|
+
}
|
|
1272
|
+
return {
|
|
1273
|
+
executedWith: "minikit",
|
|
1274
|
+
data: result.data
|
|
1275
|
+
};
|
|
1276
|
+
}
|
|
1277
|
+
async function nativeSignMessage(options, ctx) {
|
|
1278
|
+
if (!ctx) {
|
|
1279
|
+
ctx = { events: new EventManager(), state: { deviceProperties: {} } };
|
|
1280
|
+
}
|
|
1281
|
+
if (typeof window === "undefined" || !isCommandAvailable("sign-message" /* SignMessage */)) {
|
|
1282
|
+
throw new Error(
|
|
1283
|
+
"'signMessage' command is unavailable. Check MiniKit.install() or update the app version"
|
|
1284
|
+
);
|
|
1285
|
+
}
|
|
1286
|
+
const payload = await new Promise(
|
|
1287
|
+
(resolve, reject) => {
|
|
1288
|
+
try {
|
|
1289
|
+
ctx.events.subscribe("miniapp-sign-message" /* MiniAppSignMessage */, (response) => {
|
|
1290
|
+
ctx.events.unsubscribe("miniapp-sign-message" /* MiniAppSignMessage */);
|
|
1291
|
+
resolve(response);
|
|
1292
|
+
});
|
|
1293
|
+
sendMiniKitEvent({
|
|
1294
|
+
command: "sign-message" /* SignMessage */,
|
|
1295
|
+
version: COMMAND_VERSIONS["sign-message" /* SignMessage */],
|
|
1296
|
+
payload: { message: options.message }
|
|
1297
|
+
});
|
|
1298
|
+
} catch (error) {
|
|
1299
|
+
reject(error);
|
|
1300
|
+
}
|
|
1301
|
+
}
|
|
1302
|
+
);
|
|
1303
|
+
if (payload.status === "error") {
|
|
1304
|
+
throw new SignMessageError(payload.error_code);
|
|
1305
|
+
}
|
|
1306
|
+
return payload;
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
// src/commands/sign-typed-data/types.ts
|
|
1310
|
+
var SignTypedDataErrorCodes = /* @__PURE__ */ ((SignTypedDataErrorCodes2) => {
|
|
1311
|
+
SignTypedDataErrorCodes2["InvalidOperation"] = "invalid_operation";
|
|
1312
|
+
SignTypedDataErrorCodes2["UserRejected"] = "user_rejected";
|
|
1313
|
+
SignTypedDataErrorCodes2["InputError"] = "input_error";
|
|
1314
|
+
SignTypedDataErrorCodes2["SimulationFailed"] = "simulation_failed";
|
|
1315
|
+
SignTypedDataErrorCodes2["GenericError"] = "generic_error";
|
|
1316
|
+
SignTypedDataErrorCodes2["DisallowedOperation"] = "disallowed_operation";
|
|
1317
|
+
SignTypedDataErrorCodes2["InvalidContract"] = "invalid_contract";
|
|
1318
|
+
SignTypedDataErrorCodes2["MaliciousOperation"] = "malicious_operation";
|
|
1319
|
+
return SignTypedDataErrorCodes2;
|
|
1320
|
+
})(SignTypedDataErrorCodes || {});
|
|
1321
|
+
var SignTypedDataError = class extends Error {
|
|
1322
|
+
constructor(error_code) {
|
|
1323
|
+
super(`Sign typed data failed: ${error_code}`);
|
|
1324
|
+
this.error_code = error_code;
|
|
1325
|
+
this.name = "SignTypedDataError";
|
|
1326
|
+
}
|
|
1327
|
+
};
|
|
1328
|
+
|
|
1329
|
+
// src/commands/sign-typed-data/index.ts
|
|
1330
|
+
async function signTypedData(options, ctx) {
|
|
1331
|
+
const fallbackAdapter = getFallbackAdapter();
|
|
1332
|
+
const result = await executeWithFallback({
|
|
1333
|
+
command: "sign-typed-data" /* SignTypedData */,
|
|
1334
|
+
nativeExecutor: () => nativeSignTypedData(options, ctx),
|
|
1335
|
+
wagmiFallback: fallbackAdapter?.signTypedData ? () => fallbackAdapter.signTypedData({
|
|
1336
|
+
types: options.types,
|
|
1337
|
+
primaryType: options.primaryType,
|
|
1338
|
+
message: options.message,
|
|
1339
|
+
domain: options.domain,
|
|
1340
|
+
chainId: options.chainId
|
|
1341
|
+
}) : void 0,
|
|
1342
|
+
customFallback: options.fallback
|
|
1343
|
+
});
|
|
1344
|
+
if (result.executedWith === "fallback") {
|
|
1345
|
+
return { executedWith: "fallback", data: result.data };
|
|
1346
|
+
}
|
|
1347
|
+
if (result.executedWith === "wagmi") {
|
|
1348
|
+
return {
|
|
1349
|
+
executedWith: "wagmi",
|
|
1350
|
+
data: result.data
|
|
1351
|
+
};
|
|
1352
|
+
}
|
|
1353
|
+
return {
|
|
1354
|
+
executedWith: "minikit",
|
|
1355
|
+
data: result.data
|
|
1356
|
+
};
|
|
1357
|
+
}
|
|
1358
|
+
async function nativeSignTypedData(options, ctx) {
|
|
1359
|
+
if (!ctx) {
|
|
1360
|
+
ctx = { events: new EventManager(), state: { deviceProperties: {} } };
|
|
1361
|
+
}
|
|
1362
|
+
if (typeof window === "undefined" || !isCommandAvailable("sign-typed-data" /* SignTypedData */)) {
|
|
1363
|
+
throw new Error(
|
|
1364
|
+
"'signTypedData' command is unavailable. Check MiniKit.install() or update the app version"
|
|
1365
|
+
);
|
|
1366
|
+
}
|
|
1367
|
+
const payloadInput = {
|
|
1368
|
+
types: options.types,
|
|
1369
|
+
primaryType: options.primaryType,
|
|
1370
|
+
message: options.message,
|
|
1371
|
+
domain: options.domain,
|
|
1372
|
+
chainId: options.chainId ?? 480
|
|
1373
|
+
};
|
|
1374
|
+
const payload = await new Promise(
|
|
1375
|
+
(resolve, reject) => {
|
|
1376
|
+
try {
|
|
1377
|
+
ctx.events.subscribe("miniapp-sign-typed-data" /* MiniAppSignTypedData */, (response) => {
|
|
1378
|
+
ctx.events.unsubscribe("miniapp-sign-typed-data" /* MiniAppSignTypedData */);
|
|
1379
|
+
resolve(response);
|
|
1380
|
+
});
|
|
1381
|
+
sendMiniKitEvent({
|
|
1382
|
+
command: "sign-typed-data" /* SignTypedData */,
|
|
1383
|
+
version: COMMAND_VERSIONS["sign-typed-data" /* SignTypedData */],
|
|
1384
|
+
payload: payloadInput
|
|
1385
|
+
});
|
|
1386
|
+
} catch (error) {
|
|
1387
|
+
reject(error);
|
|
1388
|
+
}
|
|
1389
|
+
}
|
|
1390
|
+
);
|
|
1391
|
+
if (payload.status === "error") {
|
|
1392
|
+
throw new SignTypedDataError(payload.error_code);
|
|
1393
|
+
}
|
|
1394
|
+
return payload;
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1397
|
+
// src/commands/wallet-auth/types.ts
|
|
1398
|
+
var WalletAuthErrorCodes = /* @__PURE__ */ ((WalletAuthErrorCodes2) => {
|
|
1399
|
+
WalletAuthErrorCodes2["MalformedRequest"] = "malformed_request";
|
|
1400
|
+
WalletAuthErrorCodes2["UserRejected"] = "user_rejected";
|
|
1401
|
+
WalletAuthErrorCodes2["GenericError"] = "generic_error";
|
|
1402
|
+
return WalletAuthErrorCodes2;
|
|
1403
|
+
})(WalletAuthErrorCodes || {});
|
|
1404
|
+
var WalletAuthErrorMessage = {
|
|
1405
|
+
["malformed_request" /* MalformedRequest */]: "Provided parameters in the request are invalid.",
|
|
1406
|
+
["user_rejected" /* UserRejected */]: "User rejected the request.",
|
|
1407
|
+
["generic_error" /* GenericError */]: "Something unexpected went wrong."
|
|
1408
|
+
};
|
|
1409
|
+
var WalletAuthError = class extends Error {
|
|
1410
|
+
constructor(code, details) {
|
|
1411
|
+
super(details || `Wallet auth failed: ${code}`);
|
|
1412
|
+
this.name = "WalletAuthError";
|
|
1413
|
+
this.code = code;
|
|
1414
|
+
this.details = details;
|
|
1415
|
+
}
|
|
1416
|
+
};
|
|
1417
|
+
|
|
1418
|
+
// src/commands/wallet-auth/validate.ts
|
|
1419
|
+
var SIWE_NONCE_REGEX = /^[a-zA-Z0-9]+$/;
|
|
1420
|
+
var validateWalletAuthCommandInput = (params) => {
|
|
1421
|
+
if (!params.nonce) {
|
|
1422
|
+
return { valid: false, message: "'nonce' is required" };
|
|
1423
|
+
}
|
|
1424
|
+
if (params.nonce.length < 8) {
|
|
1425
|
+
return { valid: false, message: "'nonce' must be at least 8 characters" };
|
|
1426
|
+
}
|
|
1427
|
+
if (!SIWE_NONCE_REGEX.test(params.nonce)) {
|
|
1428
|
+
return {
|
|
1429
|
+
valid: false,
|
|
1430
|
+
message: "'nonce' must be alphanumeric (letters and numbers only)"
|
|
1431
|
+
};
|
|
1432
|
+
}
|
|
1433
|
+
if (params.statement && params.statement.includes("\n")) {
|
|
1434
|
+
return { valid: false, message: "'statement' must not contain newlines" };
|
|
1435
|
+
}
|
|
1436
|
+
if (params.expirationTime && new Date(params.expirationTime) < /* @__PURE__ */ new Date()) {
|
|
1437
|
+
return { valid: false, message: "'expirationTime' must be in the future" };
|
|
1438
|
+
}
|
|
1439
|
+
if (params.expirationTime && new Date(params.expirationTime) > new Date(Date.now() + 7 * 24 * 60 * 60 * 1e3)) {
|
|
1440
|
+
return { valid: false, message: "'expirationTime' must be within 7 days" };
|
|
1441
|
+
}
|
|
1442
|
+
if (params.notBefore && new Date(params.notBefore) > new Date(Date.now() + 7 * 24 * 60 * 60 * 1e3)) {
|
|
1443
|
+
return { valid: false, message: "'notBefore' must be within 7 days" };
|
|
1444
|
+
}
|
|
1445
|
+
return { valid: true };
|
|
1446
|
+
};
|
|
1447
|
+
|
|
1448
|
+
// src/commands/wallet-auth/index.ts
|
|
1449
|
+
async function walletAuth(options, ctx) {
|
|
1450
|
+
const fallbackAdapter = getFallbackAdapter();
|
|
1451
|
+
const result = await executeWithFallback({
|
|
1452
|
+
command: "wallet-auth" /* WalletAuth */,
|
|
1453
|
+
nativeExecutor: () => nativeWalletAuth(options, ctx),
|
|
1454
|
+
wagmiFallback: fallbackAdapter?.walletAuth ? () => fallbackAdapter.walletAuth({
|
|
1455
|
+
nonce: options.nonce,
|
|
1456
|
+
statement: options.statement,
|
|
1457
|
+
expirationTime: options.expirationTime
|
|
1458
|
+
}) : void 0,
|
|
1459
|
+
customFallback: options.fallback
|
|
1460
|
+
});
|
|
1461
|
+
if (result.executedWith === "fallback") {
|
|
1462
|
+
return { executedWith: "fallback", data: result.data };
|
|
1463
|
+
}
|
|
1464
|
+
if (result.executedWith === "wagmi") {
|
|
1465
|
+
return {
|
|
1466
|
+
executedWith: "wagmi",
|
|
1467
|
+
data: result.data
|
|
1468
|
+
};
|
|
1469
|
+
}
|
|
1470
|
+
return {
|
|
1471
|
+
executedWith: "minikit",
|
|
1472
|
+
data: result.data
|
|
1473
|
+
};
|
|
1474
|
+
}
|
|
1475
|
+
async function nativeWalletAuth(options, ctx) {
|
|
1476
|
+
if (!ctx) {
|
|
1477
|
+
ctx = { events: new EventManager(), state: { deviceProperties: {} } };
|
|
1478
|
+
}
|
|
1479
|
+
if (typeof window === "undefined" || !isCommandAvailable("wallet-auth" /* WalletAuth */)) {
|
|
1480
|
+
throw new Error(
|
|
1481
|
+
"'walletAuth' command is unavailable. Check MiniKit.install() or update the app version"
|
|
1482
|
+
);
|
|
1483
|
+
}
|
|
1484
|
+
const input = {
|
|
1485
|
+
nonce: options.nonce,
|
|
1486
|
+
statement: options.statement,
|
|
1487
|
+
requestId: options.requestId,
|
|
1488
|
+
expirationTime: options.expirationTime,
|
|
1489
|
+
notBefore: options.notBefore
|
|
1490
|
+
};
|
|
1491
|
+
const validationResult = validateWalletAuthCommandInput(input);
|
|
1492
|
+
if (!validationResult.valid) {
|
|
1493
|
+
throw new Error(`Invalid wallet auth input: ${validationResult.message}`);
|
|
1494
|
+
}
|
|
1495
|
+
let protocol;
|
|
1496
|
+
try {
|
|
1497
|
+
const currentUrl = new URL(window.location.href);
|
|
1498
|
+
protocol = currentUrl.protocol.split(":")[0];
|
|
1499
|
+
} catch (error) {
|
|
1500
|
+
throw new Error("Failed to get current URL");
|
|
1501
|
+
}
|
|
1502
|
+
const siweMessage = generateSiweMessage({
|
|
1503
|
+
scheme: protocol,
|
|
1504
|
+
domain: window.location.host,
|
|
1505
|
+
statement: input.statement ?? void 0,
|
|
1506
|
+
uri: window.location.href,
|
|
1507
|
+
version: "1",
|
|
1508
|
+
chain_id: 480,
|
|
1509
|
+
nonce: input.nonce,
|
|
1510
|
+
issued_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1511
|
+
expiration_time: input.expirationTime?.toISOString() ?? void 0,
|
|
1512
|
+
not_before: input.notBefore?.toISOString() ?? void 0,
|
|
1513
|
+
request_id: input.requestId ?? void 0
|
|
1514
|
+
});
|
|
1515
|
+
const walletAuthPayload = { siweMessage };
|
|
1516
|
+
const worldAppVersion = ctx.state.deviceProperties.worldAppVersion;
|
|
1517
|
+
const walletAuthVersion = worldAppVersion && worldAppVersion > 2087900 ? COMMAND_VERSIONS["wallet-auth" /* WalletAuth */] : 1;
|
|
1518
|
+
const finalPayload = await new Promise(
|
|
1519
|
+
(resolve, reject) => {
|
|
1520
|
+
try {
|
|
1521
|
+
ctx.events.subscribe("miniapp-wallet-auth" /* MiniAppWalletAuth */, (response) => {
|
|
1522
|
+
ctx.events.unsubscribe("miniapp-wallet-auth" /* MiniAppWalletAuth */);
|
|
1523
|
+
resolve(response);
|
|
1524
|
+
});
|
|
1525
|
+
sendMiniKitEvent({
|
|
1526
|
+
command: "wallet-auth" /* WalletAuth */,
|
|
1527
|
+
version: walletAuthVersion,
|
|
1528
|
+
payload: walletAuthPayload
|
|
1529
|
+
});
|
|
1530
|
+
} catch (error) {
|
|
1531
|
+
reject(error);
|
|
1532
|
+
}
|
|
1533
|
+
}
|
|
1534
|
+
);
|
|
1535
|
+
if (finalPayload.status === "error") {
|
|
1536
|
+
throw new WalletAuthError(finalPayload.error_code, finalPayload.details);
|
|
1537
|
+
}
|
|
1538
|
+
return {
|
|
1539
|
+
address: finalPayload.address,
|
|
1540
|
+
message: finalPayload.message,
|
|
1541
|
+
signature: finalPayload.signature
|
|
1542
|
+
};
|
|
1543
|
+
}
|
|
1544
|
+
|
|
1545
|
+
// src/types.ts
|
|
1546
|
+
var MiniAppLaunchLocation = /* @__PURE__ */ ((MiniAppLaunchLocation2) => {
|
|
1547
|
+
MiniAppLaunchLocation2["Chat"] = "chat";
|
|
1548
|
+
MiniAppLaunchLocation2["Home"] = "home";
|
|
1549
|
+
MiniAppLaunchLocation2["AppStore"] = "app-store";
|
|
1550
|
+
MiniAppLaunchLocation2["DeepLink"] = "deep-link";
|
|
1551
|
+
MiniAppLaunchLocation2["WalletTab"] = "wallet-tab";
|
|
1552
|
+
return MiniAppLaunchLocation2;
|
|
1553
|
+
})(MiniAppLaunchLocation || {});
|
|
1554
|
+
var MiniKitInstallErrorCodes = /* @__PURE__ */ ((MiniKitInstallErrorCodes2) => {
|
|
1555
|
+
MiniKitInstallErrorCodes2["Unknown"] = "unknown";
|
|
1556
|
+
MiniKitInstallErrorCodes2["AlreadyInstalled"] = "already_installed";
|
|
1557
|
+
MiniKitInstallErrorCodes2["OutsideOfWorldApp"] = "outside_of_worldapp";
|
|
1558
|
+
MiniKitInstallErrorCodes2["NotOnClient"] = "not_on_client";
|
|
1559
|
+
MiniKitInstallErrorCodes2["AppOutOfDate"] = "app_out_of_date";
|
|
1560
|
+
return MiniKitInstallErrorCodes2;
|
|
1561
|
+
})(MiniKitInstallErrorCodes || {});
|
|
1562
|
+
var MiniKitInstallErrorMessage = {
|
|
1563
|
+
["unknown" /* Unknown */]: "Failed to install MiniKit.",
|
|
1564
|
+
["already_installed" /* AlreadyInstalled */]: "MiniKit is already installed.",
|
|
1565
|
+
["outside_of_worldapp" /* OutsideOfWorldApp */]: "MiniApp launched outside of WorldApp.",
|
|
1566
|
+
["not_on_client" /* NotOnClient */]: "Window object is not available.",
|
|
1567
|
+
["app_out_of_date" /* AppOutOfDate */]: "WorldApp is out of date. Please update the app."
|
|
1568
|
+
};
|
|
1569
|
+
|
|
1570
|
+
export {
|
|
1571
|
+
Command,
|
|
1572
|
+
ResponseEvent,
|
|
1573
|
+
COMMAND_VERSIONS,
|
|
1574
|
+
isCommandAvailable,
|
|
1575
|
+
setCommandAvailable,
|
|
1576
|
+
validateCommands,
|
|
1577
|
+
sendMiniKitEvent,
|
|
1578
|
+
isInWorldApp,
|
|
1579
|
+
FallbackRequiredError,
|
|
1580
|
+
CommandUnavailableError,
|
|
1581
|
+
EventManager,
|
|
1582
|
+
AttestationErrorCodes,
|
|
1583
|
+
AttestationError,
|
|
1584
|
+
attestation,
|
|
1585
|
+
ChatErrorCodes,
|
|
1586
|
+
ChatError,
|
|
1587
|
+
chat,
|
|
1588
|
+
closeMiniApp,
|
|
1589
|
+
GetPermissionsErrorCodes,
|
|
1590
|
+
Permission,
|
|
1591
|
+
GetPermissionsError,
|
|
1592
|
+
getPermissions,
|
|
1593
|
+
Tokens,
|
|
1594
|
+
TokenDecimals,
|
|
1595
|
+
Network,
|
|
1596
|
+
PaymentErrorCodes,
|
|
1597
|
+
PaymentErrorMessage,
|
|
1598
|
+
PayError,
|
|
1599
|
+
tokenToDecimals,
|
|
1600
|
+
pay,
|
|
1601
|
+
RequestPermissionErrorCodes,
|
|
1602
|
+
RequestPermissionError,
|
|
1603
|
+
requestPermission,
|
|
1604
|
+
SendHapticFeedbackErrorCodes,
|
|
1605
|
+
SendHapticFeedbackError,
|
|
1606
|
+
sendHapticFeedback,
|
|
1607
|
+
setFallbackAdapter,
|
|
1608
|
+
SendTransactionErrorCodes,
|
|
1609
|
+
SendTransactionErrorMessage,
|
|
1610
|
+
WORLD_APP_FEATURES,
|
|
1611
|
+
WEB_FEATURES,
|
|
1612
|
+
SendTransactionError,
|
|
1613
|
+
sendTransaction,
|
|
1614
|
+
ShareFilesErrorCodes,
|
|
1615
|
+
ShareError,
|
|
1616
|
+
share,
|
|
1617
|
+
ShareContactsErrorCodes,
|
|
1618
|
+
ShareContactsErrorMessage,
|
|
1619
|
+
ShareContactsError,
|
|
1620
|
+
shareContacts,
|
|
1621
|
+
getContacts,
|
|
1622
|
+
SignMessageErrorCodes,
|
|
1623
|
+
SignMessageError,
|
|
1624
|
+
signMessage,
|
|
1625
|
+
SignTypedDataErrorCodes,
|
|
1626
|
+
SignTypedDataError,
|
|
1627
|
+
signTypedData,
|
|
1628
|
+
WalletAuthErrorCodes,
|
|
1629
|
+
WalletAuthErrorMessage,
|
|
1630
|
+
WalletAuthError,
|
|
1631
|
+
walletAuth,
|
|
1632
|
+
MiniAppLaunchLocation,
|
|
1633
|
+
MiniKitInstallErrorCodes,
|
|
1634
|
+
MiniKitInstallErrorMessage
|
|
1635
|
+
};
|