@worldcoin/minikit-js 1.9.9 → 1.9.11
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 +7 -0
- package/build/{chunk-VWX7SELF.js → chunk-YDNDO45D.js} +1452 -1146
- package/build/index.cjs +1573 -1240
- package/build/index.d.cts +494 -527
- package/build/index.d.ts +494 -527
- package/build/index.js +63 -9
- package/build/minikit-provider.cjs +1151 -852
- package/build/minikit-provider.js +1 -1
- package/index.ts +12 -3
- package/package.json +1 -1
package/build/index.cjs
CHANGED
|
@@ -20,13 +20,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// index.ts
|
|
21
21
|
var core_exports = {};
|
|
22
22
|
__export(core_exports, {
|
|
23
|
+
COMMAND_VERSIONS: () => COMMAND_VERSIONS,
|
|
23
24
|
ChatErrorCodes: () => ChatErrorCodes,
|
|
24
25
|
ChatErrorMessage: () => ChatErrorMessage,
|
|
25
26
|
Command: () => Command,
|
|
26
27
|
GetPermissionsErrorCodes: () => GetPermissionsErrorCodes,
|
|
27
28
|
GetPermissionsErrorMessage: () => GetPermissionsErrorMessage,
|
|
28
|
-
MicrophoneErrorCodes: () => MicrophoneErrorCodes,
|
|
29
|
-
MicrophoneErrorMessage: () => MicrophoneErrorMessage,
|
|
30
29
|
MiniAppLaunchLocation: () => MiniAppLaunchLocation,
|
|
31
30
|
MiniKit: () => MiniKit,
|
|
32
31
|
MiniKitInstallErrorCodes: () => MiniKitInstallErrorCodes,
|
|
@@ -34,7 +33,6 @@ __export(core_exports, {
|
|
|
34
33
|
Network: () => Network,
|
|
35
34
|
PaymentErrorCodes: () => PaymentErrorCodes,
|
|
36
35
|
PaymentErrorMessage: () => PaymentErrorMessage,
|
|
37
|
-
PaymentValidationErrors: () => PaymentValidationErrors,
|
|
38
36
|
Permission: () => Permission,
|
|
39
37
|
RequestPermissionErrorCodes: () => RequestPermissionErrorCodes,
|
|
40
38
|
RequestPermissionErrorMessage: () => RequestPermissionErrorMessage,
|
|
@@ -54,23 +52,48 @@ __export(core_exports, {
|
|
|
54
52
|
TokenDecimals: () => TokenDecimals,
|
|
55
53
|
Tokens: () => Tokens,
|
|
56
54
|
VerificationErrorCodes: () => import_idkit_core2.AppErrorCodes,
|
|
57
|
-
|
|
58
|
-
VerificationLevel: () => import_idkit_core4.VerificationLevel,
|
|
55
|
+
VerificationLevel: () => import_idkit_core6.VerificationLevel,
|
|
59
56
|
WalletAuthErrorCodes: () => WalletAuthErrorCodes,
|
|
60
57
|
WalletAuthErrorMessage: () => WalletAuthErrorMessage,
|
|
58
|
+
createAsyncCommands: () => createAsyncCommands,
|
|
59
|
+
createChatAsyncCommand: () => createChatAsyncCommand,
|
|
60
|
+
createChatCommand: () => createChatCommand,
|
|
61
|
+
createCommands: () => createCommands,
|
|
62
|
+
createGetPermissionsAsyncCommand: () => createGetPermissionsAsyncCommand,
|
|
63
|
+
createGetPermissionsCommand: () => createGetPermissionsCommand,
|
|
64
|
+
createPayAsyncCommand: () => createPayAsyncCommand,
|
|
65
|
+
createPayCommand: () => createPayCommand,
|
|
66
|
+
createRequestPermissionAsyncCommand: () => createRequestPermissionAsyncCommand,
|
|
67
|
+
createRequestPermissionCommand: () => createRequestPermissionCommand,
|
|
68
|
+
createSendHapticFeedbackAsyncCommand: () => createSendHapticFeedbackAsyncCommand,
|
|
69
|
+
createSendHapticFeedbackCommand: () => createSendHapticFeedbackCommand,
|
|
70
|
+
createSendTransactionAsyncCommand: () => createSendTransactionAsyncCommand,
|
|
71
|
+
createSendTransactionCommand: () => createSendTransactionCommand,
|
|
72
|
+
createShareAsyncCommand: () => createShareAsyncCommand,
|
|
73
|
+
createShareCommand: () => createShareCommand,
|
|
74
|
+
createShareContactsAsyncCommand: () => createShareContactsAsyncCommand,
|
|
75
|
+
createShareContactsCommand: () => createShareContactsCommand,
|
|
76
|
+
createSignMessageAsyncCommand: () => createSignMessageAsyncCommand,
|
|
77
|
+
createSignMessageCommand: () => createSignMessageCommand,
|
|
78
|
+
createSignTypedDataAsyncCommand: () => createSignTypedDataAsyncCommand,
|
|
79
|
+
createSignTypedDataCommand: () => createSignTypedDataCommand,
|
|
80
|
+
createVerifyAsyncCommand: () => createVerifyAsyncCommand,
|
|
81
|
+
createVerifyCommand: () => createVerifyCommand,
|
|
82
|
+
createWalletAuthAsyncCommand: () => createWalletAuthAsyncCommand,
|
|
83
|
+
createWalletAuthCommand: () => createWalletAuthCommand,
|
|
61
84
|
getIsUserVerified: () => getIsUserVerified,
|
|
85
|
+
isCommandAvailable: () => isCommandAvailable,
|
|
62
86
|
mapWorldAppLaunchLocation: () => mapWorldAppLaunchLocation,
|
|
63
87
|
parseSiweMessage: () => parseSiweMessage,
|
|
88
|
+
sendMiniKitEvent: () => sendMiniKitEvent,
|
|
89
|
+
setCommandAvailable: () => setCommandAvailable,
|
|
64
90
|
tokenToDecimals: () => tokenToDecimals,
|
|
91
|
+
validateCommands: () => validateCommands,
|
|
65
92
|
verifyCloudProof: () => import_backend.verifyCloudProof,
|
|
66
93
|
verifySiweMessage: () => verifySiweMessage
|
|
67
94
|
});
|
|
68
95
|
module.exports = __toCommonJS(core_exports);
|
|
69
96
|
|
|
70
|
-
// minikit.ts
|
|
71
|
-
var import_idkit_core3 = require("@worldcoin/idkit-core");
|
|
72
|
-
var import_hashing = require("@worldcoin/idkit-core/hashing");
|
|
73
|
-
|
|
74
97
|
// helpers/send-webview-event.ts
|
|
75
98
|
var sendWebviewEvent = (payload) => {
|
|
76
99
|
if (window.webkit) {
|
|
@@ -80,22 +103,255 @@ var sendWebviewEvent = (payload) => {
|
|
|
80
103
|
}
|
|
81
104
|
};
|
|
82
105
|
|
|
83
|
-
// types
|
|
84
|
-
var
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
[
|
|
88
|
-
[
|
|
89
|
-
[
|
|
90
|
-
[
|
|
91
|
-
[
|
|
92
|
-
[
|
|
93
|
-
[
|
|
94
|
-
[
|
|
95
|
-
[
|
|
96
|
-
[
|
|
97
|
-
|
|
106
|
+
// commands/types.ts
|
|
107
|
+
var Command = /* @__PURE__ */ ((Command2) => {
|
|
108
|
+
Command2["Verify"] = "verify";
|
|
109
|
+
Command2["Pay"] = "pay";
|
|
110
|
+
Command2["WalletAuth"] = "wallet-auth";
|
|
111
|
+
Command2["SendTransaction"] = "send-transaction";
|
|
112
|
+
Command2["SignMessage"] = "sign-message";
|
|
113
|
+
Command2["SignTypedData"] = "sign-typed-data";
|
|
114
|
+
Command2["ShareContacts"] = "share-contacts";
|
|
115
|
+
Command2["RequestPermission"] = "request-permission";
|
|
116
|
+
Command2["GetPermissions"] = "get-permissions";
|
|
117
|
+
Command2["SendHapticFeedback"] = "send-haptic-feedback";
|
|
118
|
+
Command2["Share"] = "share";
|
|
119
|
+
Command2["Chat"] = "chat";
|
|
120
|
+
return Command2;
|
|
121
|
+
})(Command || {});
|
|
122
|
+
var ResponseEvent = /* @__PURE__ */ ((ResponseEvent3) => {
|
|
123
|
+
ResponseEvent3["MiniAppVerifyAction"] = "miniapp-verify-action";
|
|
124
|
+
ResponseEvent3["MiniAppPayment"] = "miniapp-payment";
|
|
125
|
+
ResponseEvent3["MiniAppWalletAuth"] = "miniapp-wallet-auth";
|
|
126
|
+
ResponseEvent3["MiniAppSendTransaction"] = "miniapp-send-transaction";
|
|
127
|
+
ResponseEvent3["MiniAppSignMessage"] = "miniapp-sign-message";
|
|
128
|
+
ResponseEvent3["MiniAppSignTypedData"] = "miniapp-sign-typed-data";
|
|
129
|
+
ResponseEvent3["MiniAppShareContacts"] = "miniapp-share-contacts";
|
|
130
|
+
ResponseEvent3["MiniAppRequestPermission"] = "miniapp-request-permission";
|
|
131
|
+
ResponseEvent3["MiniAppGetPermissions"] = "miniapp-get-permissions";
|
|
132
|
+
ResponseEvent3["MiniAppSendHapticFeedback"] = "miniapp-send-haptic-feedback";
|
|
133
|
+
ResponseEvent3["MiniAppShare"] = "miniapp-share";
|
|
134
|
+
ResponseEvent3["MiniAppMicrophone"] = "miniapp-microphone";
|
|
135
|
+
ResponseEvent3["MiniAppChat"] = "miniapp-chat";
|
|
136
|
+
return ResponseEvent3;
|
|
137
|
+
})(ResponseEvent || {});
|
|
138
|
+
var COMMAND_VERSIONS = {
|
|
139
|
+
["verify" /* Verify */]: 1,
|
|
140
|
+
["pay" /* Pay */]: 1,
|
|
141
|
+
["wallet-auth" /* WalletAuth */]: 2,
|
|
142
|
+
["send-transaction" /* SendTransaction */]: 1,
|
|
143
|
+
["sign-message" /* SignMessage */]: 1,
|
|
144
|
+
["sign-typed-data" /* SignTypedData */]: 1,
|
|
145
|
+
["share-contacts" /* ShareContacts */]: 1,
|
|
146
|
+
["request-permission" /* RequestPermission */]: 1,
|
|
147
|
+
["get-permissions" /* GetPermissions */]: 1,
|
|
148
|
+
["send-haptic-feedback" /* SendHapticFeedback */]: 1,
|
|
149
|
+
["share" /* Share */]: 1,
|
|
150
|
+
["chat" /* Chat */]: 1
|
|
151
|
+
};
|
|
152
|
+
var commandAvailability = {
|
|
153
|
+
["verify" /* Verify */]: false,
|
|
154
|
+
["pay" /* Pay */]: false,
|
|
155
|
+
["wallet-auth" /* WalletAuth */]: false,
|
|
156
|
+
["send-transaction" /* SendTransaction */]: false,
|
|
157
|
+
["sign-message" /* SignMessage */]: false,
|
|
158
|
+
["sign-typed-data" /* SignTypedData */]: false,
|
|
159
|
+
["share-contacts" /* ShareContacts */]: false,
|
|
160
|
+
["request-permission" /* RequestPermission */]: false,
|
|
161
|
+
["get-permissions" /* GetPermissions */]: false,
|
|
162
|
+
["send-haptic-feedback" /* SendHapticFeedback */]: false,
|
|
163
|
+
["share" /* Share */]: false,
|
|
164
|
+
["chat" /* Chat */]: false
|
|
165
|
+
};
|
|
166
|
+
function isCommandAvailable(command) {
|
|
167
|
+
return commandAvailability[command];
|
|
168
|
+
}
|
|
169
|
+
function setCommandAvailable(command, available) {
|
|
170
|
+
commandAvailability[command] = available;
|
|
171
|
+
}
|
|
172
|
+
function validateCommands(worldAppSupportedCommands) {
|
|
173
|
+
let allCommandsValid = true;
|
|
174
|
+
Object.entries(COMMAND_VERSIONS).forEach(([commandName, version]) => {
|
|
175
|
+
const commandInput = worldAppSupportedCommands.find(
|
|
176
|
+
(cmd) => cmd.name === commandName
|
|
177
|
+
);
|
|
178
|
+
let isCommandValid = false;
|
|
179
|
+
if (!commandInput) {
|
|
180
|
+
console.warn(
|
|
181
|
+
`Command ${commandName} is not supported by the app. Try updating the app version`
|
|
182
|
+
);
|
|
183
|
+
} else {
|
|
184
|
+
if (commandInput.supported_versions.includes(version)) {
|
|
185
|
+
setCommandAvailable(commandName, true);
|
|
186
|
+
isCommandValid = true;
|
|
187
|
+
} else {
|
|
188
|
+
isCommandValid = true;
|
|
189
|
+
console.warn(
|
|
190
|
+
`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.`
|
|
191
|
+
);
|
|
192
|
+
setCommandAvailable(commandName, true);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
if (!isCommandValid) {
|
|
196
|
+
allCommandsValid = false;
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
return allCommandsValid;
|
|
200
|
+
}
|
|
201
|
+
function sendMiniKitEvent(payload) {
|
|
202
|
+
sendWebviewEvent(payload);
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
// commands/chat.ts
|
|
206
|
+
var ChatErrorCodes = /* @__PURE__ */ ((ChatErrorCodes2) => {
|
|
207
|
+
ChatErrorCodes2["UserRejected"] = "user_rejected";
|
|
208
|
+
ChatErrorCodes2["SendFailed"] = "send_failed";
|
|
209
|
+
ChatErrorCodes2["GenericError"] = "generic_error";
|
|
210
|
+
return ChatErrorCodes2;
|
|
211
|
+
})(ChatErrorCodes || {});
|
|
212
|
+
var ChatErrorMessage = {
|
|
213
|
+
["user_rejected" /* UserRejected */]: "User rejected the request.",
|
|
214
|
+
["send_failed" /* SendFailed */]: "Failed to send the message.",
|
|
215
|
+
["generic_error" /* GenericError */]: "Something unexpected went wrong."
|
|
216
|
+
};
|
|
217
|
+
function createChatCommand(_ctx) {
|
|
218
|
+
return (payload) => {
|
|
219
|
+
if (typeof window === "undefined" || !isCommandAvailable("chat" /* Chat */)) {
|
|
220
|
+
console.error(
|
|
221
|
+
"'chat' command is unavailable. Check MiniKit.install() or update the app version"
|
|
222
|
+
);
|
|
223
|
+
return null;
|
|
224
|
+
}
|
|
225
|
+
if (payload.message.length === 0) {
|
|
226
|
+
console.error("'chat' command requires a non-empty message");
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
sendMiniKitEvent({
|
|
230
|
+
command: "chat" /* Chat */,
|
|
231
|
+
version: COMMAND_VERSIONS["chat" /* Chat */],
|
|
232
|
+
payload
|
|
233
|
+
});
|
|
234
|
+
return payload;
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
function createChatAsyncCommand(ctx, syncCommand) {
|
|
238
|
+
return async (payload) => {
|
|
239
|
+
return new Promise((resolve, reject) => {
|
|
240
|
+
try {
|
|
241
|
+
let commandPayload = null;
|
|
242
|
+
const handleResponse = (response) => {
|
|
243
|
+
ctx.events.unsubscribe("miniapp-chat" /* MiniAppChat */);
|
|
244
|
+
resolve({ commandPayload, finalPayload: response });
|
|
245
|
+
};
|
|
246
|
+
ctx.events.subscribe("miniapp-chat" /* MiniAppChat */, handleResponse);
|
|
247
|
+
commandPayload = syncCommand(payload);
|
|
248
|
+
} catch (error) {
|
|
249
|
+
reject(error);
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
};
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
// commands/get-permissions.ts
|
|
256
|
+
var GetPermissionsErrorCodes = /* @__PURE__ */ ((GetPermissionsErrorCodes2) => {
|
|
257
|
+
GetPermissionsErrorCodes2["GenericError"] = "generic_error";
|
|
258
|
+
return GetPermissionsErrorCodes2;
|
|
259
|
+
})(GetPermissionsErrorCodes || {});
|
|
260
|
+
var GetPermissionsErrorMessage = {
|
|
261
|
+
["generic_error" /* GenericError */]: "Something unexpected went wrong. Please try again."
|
|
262
|
+
};
|
|
263
|
+
var Permission = /* @__PURE__ */ ((Permission2) => {
|
|
264
|
+
Permission2["Notifications"] = "notifications";
|
|
265
|
+
Permission2["Contacts"] = "contacts";
|
|
266
|
+
Permission2["Microphone"] = "microphone";
|
|
267
|
+
return Permission2;
|
|
268
|
+
})(Permission || {});
|
|
269
|
+
function createGetPermissionsCommand(_ctx) {
|
|
270
|
+
return () => {
|
|
271
|
+
if (typeof window === "undefined" || !isCommandAvailable("get-permissions" /* GetPermissions */)) {
|
|
272
|
+
console.error(
|
|
273
|
+
"'getPermissions' command is unavailable. Check MiniKit.install() or update the app version"
|
|
274
|
+
);
|
|
275
|
+
return null;
|
|
276
|
+
}
|
|
277
|
+
sendMiniKitEvent({
|
|
278
|
+
command: "get-permissions" /* GetPermissions */,
|
|
279
|
+
version: COMMAND_VERSIONS["get-permissions" /* GetPermissions */],
|
|
280
|
+
payload: {}
|
|
281
|
+
});
|
|
282
|
+
return {
|
|
283
|
+
status: "sent"
|
|
284
|
+
};
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
function createGetPermissionsAsyncCommand(ctx, syncCommand) {
|
|
288
|
+
return async () => {
|
|
289
|
+
return new Promise((resolve, reject) => {
|
|
290
|
+
try {
|
|
291
|
+
let commandPayload = null;
|
|
292
|
+
const handleResponse = (payload) => {
|
|
293
|
+
ctx.events.unsubscribe("miniapp-get-permissions" /* MiniAppGetPermissions */);
|
|
294
|
+
resolve({ commandPayload, finalPayload: payload });
|
|
295
|
+
};
|
|
296
|
+
ctx.events.subscribe(
|
|
297
|
+
"miniapp-get-permissions" /* MiniAppGetPermissions */,
|
|
298
|
+
handleResponse
|
|
299
|
+
);
|
|
300
|
+
commandPayload = syncCommand();
|
|
301
|
+
} catch (error) {
|
|
302
|
+
reject(error);
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
// types/payment.ts
|
|
309
|
+
var Tokens = /* @__PURE__ */ ((Tokens3) => {
|
|
310
|
+
Tokens3["USDC"] = "USDCE";
|
|
311
|
+
Tokens3["WLD"] = "WLD";
|
|
312
|
+
return Tokens3;
|
|
313
|
+
})(Tokens || {});
|
|
314
|
+
var TokenDecimals = {
|
|
315
|
+
["USDCE" /* USDC */]: 6,
|
|
316
|
+
["WLD" /* WLD */]: 18
|
|
317
|
+
};
|
|
318
|
+
var Network = /* @__PURE__ */ ((Network2) => {
|
|
319
|
+
Network2["Optimism"] = "optimism";
|
|
320
|
+
Network2["WorldChain"] = "worldchain";
|
|
321
|
+
return Network2;
|
|
322
|
+
})(Network || {});
|
|
323
|
+
|
|
324
|
+
// helpers/payment/client.ts
|
|
325
|
+
var tokenToDecimals = (amount, token) => {
|
|
326
|
+
const decimals = TokenDecimals[token];
|
|
327
|
+
if (decimals === void 0) {
|
|
328
|
+
throw new Error(`Invalid token: ${token}`);
|
|
329
|
+
}
|
|
330
|
+
const factor = 10 ** decimals;
|
|
331
|
+
const result = amount * factor;
|
|
332
|
+
if (!Number.isInteger(result)) {
|
|
333
|
+
throw new Error(`The resulting amount is not a whole number: ${result}`);
|
|
334
|
+
}
|
|
335
|
+
return result;
|
|
336
|
+
};
|
|
337
|
+
var validatePaymentPayload = (payload) => {
|
|
338
|
+
if (payload.tokens.some(
|
|
339
|
+
(token) => token.symbol == "USDCE" /* USDC */ && parseFloat(token.token_amount) < 0.1
|
|
340
|
+
)) {
|
|
341
|
+
console.error("USDC amount should be greater than $0.1");
|
|
342
|
+
return false;
|
|
343
|
+
}
|
|
344
|
+
if (payload.reference.length > 36) {
|
|
345
|
+
console.error("Reference must not exceed 36 characters");
|
|
346
|
+
return false;
|
|
347
|
+
}
|
|
348
|
+
if (typeof payload.reference !== "string") {
|
|
349
|
+
throw new Error("Reference must be a string");
|
|
350
|
+
}
|
|
351
|
+
return true;
|
|
98
352
|
};
|
|
353
|
+
|
|
354
|
+
// commands/pay.ts
|
|
99
355
|
var PaymentErrorCodes = /* @__PURE__ */ ((PaymentErrorCodes2) => {
|
|
100
356
|
PaymentErrorCodes2["InputError"] = "input_error";
|
|
101
357
|
PaymentErrorCodes2["UserRejected"] = "user_rejected";
|
|
@@ -117,135 +373,106 @@ var PaymentErrorMessage = {
|
|
|
117
373
|
["generic_error" /* GenericError */]: "Something unexpected went wrong. Please try again.",
|
|
118
374
|
["user_blocked" /* UserBlocked */]: "User's region is blocked from making payments."
|
|
119
375
|
};
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
["
|
|
167
|
-
["
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
["
|
|
177
|
-
["
|
|
178
|
-
["
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
SignTypedDataErrorCodes2["InvalidOperation"] = "invalid_operation";
|
|
182
|
-
SignTypedDataErrorCodes2["UserRejected"] = "user_rejected";
|
|
183
|
-
SignTypedDataErrorCodes2["InputError"] = "input_error";
|
|
184
|
-
SignTypedDataErrorCodes2["SimulationFailed"] = "simulation_failed";
|
|
185
|
-
SignTypedDataErrorCodes2["GenericError"] = "generic_error";
|
|
186
|
-
SignTypedDataErrorCodes2["DisallowedOperation"] = "disallowed_operation";
|
|
187
|
-
SignTypedDataErrorCodes2["InvalidContract"] = "invalid_contract";
|
|
188
|
-
SignTypedDataErrorCodes2["MaliciousOperation"] = "malicious_operation";
|
|
189
|
-
return SignTypedDataErrorCodes2;
|
|
190
|
-
})(SignTypedDataErrorCodes || {});
|
|
191
|
-
var SignTypedDataErrorMessage = {
|
|
192
|
-
["invalid_operation" /* InvalidOperation */]: "Transaction included an operation that was invalid",
|
|
193
|
-
["user_rejected" /* UserRejected */]: "User rejected the request.",
|
|
194
|
-
["input_error" /* InputError */]: "Invalid payload.",
|
|
195
|
-
["simulation_failed" /* SimulationFailed */]: "The transaction simulation failed.",
|
|
196
|
-
["generic_error" /* GenericError */]: "Something unexpected went wrong. Please try again.",
|
|
197
|
-
["disallowed_operation" /* DisallowedOperation */]: "The operation requested is not allowed. Please refer to the docs.",
|
|
198
|
-
["invalid_contract" /* InvalidContract */]: "The contract address is not allowed for your application. Please check your developer portal configurations",
|
|
199
|
-
["malicious_operation" /* MaliciousOperation */]: "The operation requested is considered malicious."
|
|
200
|
-
};
|
|
201
|
-
var MiniKitInstallErrorCodes = /* @__PURE__ */ ((MiniKitInstallErrorCodes2) => {
|
|
202
|
-
MiniKitInstallErrorCodes2["Unknown"] = "unknown";
|
|
203
|
-
MiniKitInstallErrorCodes2["AlreadyInstalled"] = "already_installed";
|
|
204
|
-
MiniKitInstallErrorCodes2["OutsideOfWorldApp"] = "outside_of_worldapp";
|
|
205
|
-
MiniKitInstallErrorCodes2["NotOnClient"] = "not_on_client";
|
|
206
|
-
MiniKitInstallErrorCodes2["AppOutOfDate"] = "app_out_of_date";
|
|
207
|
-
return MiniKitInstallErrorCodes2;
|
|
208
|
-
})(MiniKitInstallErrorCodes || {});
|
|
209
|
-
var MiniKitInstallErrorMessage = {
|
|
210
|
-
["unknown" /* Unknown */]: "Failed to install MiniKit.",
|
|
211
|
-
["already_installed" /* AlreadyInstalled */]: "MiniKit is already installed.",
|
|
212
|
-
["outside_of_worldapp" /* OutsideOfWorldApp */]: "MiniApp launched outside of WorldApp.",
|
|
213
|
-
["not_on_client" /* NotOnClient */]: "Window object is not available.",
|
|
214
|
-
["app_out_of_date" /* AppOutOfDate */]: "WorldApp is out of date. Please update the app."
|
|
215
|
-
};
|
|
216
|
-
var ShareContactsErrorCodes = /* @__PURE__ */ ((ShareContactsErrorCodes2) => {
|
|
217
|
-
ShareContactsErrorCodes2["UserRejected"] = "user_rejected";
|
|
218
|
-
ShareContactsErrorCodes2["GenericError"] = "generic_error";
|
|
219
|
-
return ShareContactsErrorCodes2;
|
|
220
|
-
})(ShareContactsErrorCodes || {});
|
|
221
|
-
var ShareContactsErrorMessage = {
|
|
222
|
-
["user_rejected" /* UserRejected */]: "User rejected the request.",
|
|
223
|
-
["generic_error" /* GenericError */]: "Something unexpected went wrong."
|
|
224
|
-
};
|
|
225
|
-
var RequestPermissionErrorCodes = /* @__PURE__ */ ((RequestPermissionErrorCodes2) => {
|
|
226
|
-
RequestPermissionErrorCodes2["UserRejected"] = "user_rejected";
|
|
227
|
-
RequestPermissionErrorCodes2["GenericError"] = "generic_error";
|
|
228
|
-
RequestPermissionErrorCodes2["AlreadyRequested"] = "already_requested";
|
|
229
|
-
RequestPermissionErrorCodes2["PermissionDisabled"] = "permission_disabled";
|
|
230
|
-
RequestPermissionErrorCodes2["AlreadyGranted"] = "already_granted";
|
|
231
|
-
RequestPermissionErrorCodes2["UnsupportedPermission"] = "unsupported_permission";
|
|
232
|
-
return RequestPermissionErrorCodes2;
|
|
233
|
-
})(RequestPermissionErrorCodes || {});
|
|
234
|
-
var RequestPermissionErrorMessage = {
|
|
235
|
-
["user_rejected" /* UserRejected */]: "User declined sharing contacts",
|
|
236
|
-
["generic_error" /* GenericError */]: "Request failed for unknown reason.",
|
|
237
|
-
["already_requested" /* AlreadyRequested */]: "User has already declined turning on notifications once",
|
|
238
|
-
["permission_disabled" /* PermissionDisabled */]: "User does not have this permission enabled in World App",
|
|
239
|
-
["already_granted" /* AlreadyGranted */]: "If the user has already granted this mini app permission",
|
|
240
|
-
["unsupported_permission" /* UnsupportedPermission */]: "The permission requested is not supported by this mini app"
|
|
241
|
-
};
|
|
242
|
-
var GetPermissionsErrorCodes = /* @__PURE__ */ ((GetPermissionsErrorCodes2) => {
|
|
243
|
-
GetPermissionsErrorCodes2["GenericError"] = "generic_error";
|
|
244
|
-
return GetPermissionsErrorCodes2;
|
|
245
|
-
})(GetPermissionsErrorCodes || {});
|
|
246
|
-
var GetPermissionsErrorMessage = {
|
|
247
|
-
["generic_error" /* GenericError */]: "Something unexpected went wrong. Please try again."
|
|
376
|
+
function createPayCommand(_ctx) {
|
|
377
|
+
return (payload) => {
|
|
378
|
+
if (typeof window === "undefined" || !isCommandAvailable("pay" /* Pay */)) {
|
|
379
|
+
console.error(
|
|
380
|
+
"'pay' command is unavailable. Check MiniKit.install() or update the app version"
|
|
381
|
+
);
|
|
382
|
+
return null;
|
|
383
|
+
}
|
|
384
|
+
if (!validatePaymentPayload(payload)) {
|
|
385
|
+
return null;
|
|
386
|
+
}
|
|
387
|
+
const eventPayload = {
|
|
388
|
+
...payload,
|
|
389
|
+
network: "worldchain" /* WorldChain */
|
|
390
|
+
};
|
|
391
|
+
sendMiniKitEvent({
|
|
392
|
+
command: "pay" /* Pay */,
|
|
393
|
+
version: COMMAND_VERSIONS["pay" /* Pay */],
|
|
394
|
+
payload: eventPayload
|
|
395
|
+
});
|
|
396
|
+
return eventPayload;
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
function createPayAsyncCommand(ctx, syncCommand) {
|
|
400
|
+
return async (payload) => {
|
|
401
|
+
return new Promise((resolve, reject) => {
|
|
402
|
+
try {
|
|
403
|
+
let commandPayload = null;
|
|
404
|
+
const handleResponse = (response) => {
|
|
405
|
+
ctx.events.unsubscribe("miniapp-payment" /* MiniAppPayment */);
|
|
406
|
+
resolve({ commandPayload, finalPayload: response });
|
|
407
|
+
};
|
|
408
|
+
ctx.events.subscribe(
|
|
409
|
+
"miniapp-payment" /* MiniAppPayment */,
|
|
410
|
+
handleResponse
|
|
411
|
+
);
|
|
412
|
+
commandPayload = syncCommand(payload);
|
|
413
|
+
} catch (error) {
|
|
414
|
+
reject(error);
|
|
415
|
+
}
|
|
416
|
+
});
|
|
417
|
+
};
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
// commands/request-permission.ts
|
|
421
|
+
var RequestPermissionErrorCodes = /* @__PURE__ */ ((RequestPermissionErrorCodes2) => {
|
|
422
|
+
RequestPermissionErrorCodes2["UserRejected"] = "user_rejected";
|
|
423
|
+
RequestPermissionErrorCodes2["GenericError"] = "generic_error";
|
|
424
|
+
RequestPermissionErrorCodes2["AlreadyRequested"] = "already_requested";
|
|
425
|
+
RequestPermissionErrorCodes2["PermissionDisabled"] = "permission_disabled";
|
|
426
|
+
RequestPermissionErrorCodes2["AlreadyGranted"] = "already_granted";
|
|
427
|
+
RequestPermissionErrorCodes2["UnsupportedPermission"] = "unsupported_permission";
|
|
428
|
+
return RequestPermissionErrorCodes2;
|
|
429
|
+
})(RequestPermissionErrorCodes || {});
|
|
430
|
+
var RequestPermissionErrorMessage = {
|
|
431
|
+
["user_rejected" /* UserRejected */]: "User declined sharing contacts",
|
|
432
|
+
["generic_error" /* GenericError */]: "Request failed for unknown reason.",
|
|
433
|
+
["already_requested" /* AlreadyRequested */]: "User has already declined turning on notifications once",
|
|
434
|
+
["permission_disabled" /* PermissionDisabled */]: "User does not have this permission enabled in World App",
|
|
435
|
+
["already_granted" /* AlreadyGranted */]: "If the user has already granted this mini app permission",
|
|
436
|
+
["unsupported_permission" /* UnsupportedPermission */]: "The permission requested is not supported by this mini app"
|
|
248
437
|
};
|
|
438
|
+
function createRequestPermissionCommand(_ctx) {
|
|
439
|
+
return (payload) => {
|
|
440
|
+
if (typeof window === "undefined" || !isCommandAvailable("request-permission" /* RequestPermission */)) {
|
|
441
|
+
console.error(
|
|
442
|
+
"'requestPermission' command is unavailable. Check MiniKit.install() or update the app version"
|
|
443
|
+
);
|
|
444
|
+
return null;
|
|
445
|
+
}
|
|
446
|
+
sendMiniKitEvent({
|
|
447
|
+
command: "request-permission" /* RequestPermission */,
|
|
448
|
+
version: COMMAND_VERSIONS["request-permission" /* RequestPermission */],
|
|
449
|
+
payload
|
|
450
|
+
});
|
|
451
|
+
return payload;
|
|
452
|
+
};
|
|
453
|
+
}
|
|
454
|
+
function createRequestPermissionAsyncCommand(ctx, syncCommand) {
|
|
455
|
+
return async (payload) => {
|
|
456
|
+
return new Promise((resolve, reject) => {
|
|
457
|
+
try {
|
|
458
|
+
let commandPayload = null;
|
|
459
|
+
const handleResponse = (response) => {
|
|
460
|
+
ctx.events.unsubscribe("miniapp-request-permission" /* MiniAppRequestPermission */);
|
|
461
|
+
resolve({ commandPayload, finalPayload: response });
|
|
462
|
+
};
|
|
463
|
+
ctx.events.subscribe(
|
|
464
|
+
"miniapp-request-permission" /* MiniAppRequestPermission */,
|
|
465
|
+
handleResponse
|
|
466
|
+
);
|
|
467
|
+
commandPayload = syncCommand(payload);
|
|
468
|
+
} catch (error) {
|
|
469
|
+
reject(error);
|
|
470
|
+
}
|
|
471
|
+
});
|
|
472
|
+
};
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
// commands/send-haptic-feedback.ts
|
|
249
476
|
var SendHapticFeedbackErrorCodes = /* @__PURE__ */ ((SendHapticFeedbackErrorCodes2) => {
|
|
250
477
|
SendHapticFeedbackErrorCodes2["GenericError"] = "generic_error";
|
|
251
478
|
SendHapticFeedbackErrorCodes2["UserRejected"] = "user_rejected";
|
|
@@ -255,235 +482,177 @@ var SendHapticFeedbackErrorMessage = {
|
|
|
255
482
|
["generic_error" /* GenericError */]: "Something unexpected went wrong.",
|
|
256
483
|
["user_rejected" /* UserRejected */]: "User rejected the request."
|
|
257
484
|
};
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
["user_rejected" /* UserRejected */]: "User rejected the request.",
|
|
266
|
-
["generic_error" /* GenericError */]: "Something unexpected went wrong.",
|
|
267
|
-
["invalid_file_name" /* InvalidFileName */]: "Invalid file name. Make sure you include the extension"
|
|
268
|
-
};
|
|
269
|
-
var MicrophoneErrorCodes = /* @__PURE__ */ ((MicrophoneErrorCodes2) => {
|
|
270
|
-
MicrophoneErrorCodes2["MiniAppPermissionNotEnabled"] = "mini_app_permission_not_enabled";
|
|
271
|
-
MicrophoneErrorCodes2["WorldAppPermissionNotEnabled"] = "world_app_permission_not_enabled";
|
|
272
|
-
return MicrophoneErrorCodes2;
|
|
273
|
-
})(MicrophoneErrorCodes || {});
|
|
274
|
-
var MicrophoneErrorMessage = {
|
|
275
|
-
["mini_app_permission_not_enabled" /* MiniAppPermissionNotEnabled */]: "Microphone permission not enabled for your Mini App",
|
|
276
|
-
["world_app_permission_not_enabled" /* WorldAppPermissionNotEnabled */]: "Microphone permission not enabled in World App"
|
|
277
|
-
};
|
|
278
|
-
var ChatErrorCodes = /* @__PURE__ */ ((ChatErrorCodes2) => {
|
|
279
|
-
ChatErrorCodes2["UserRejected"] = "user_rejected";
|
|
280
|
-
ChatErrorCodes2["SendFailed"] = "send_failed";
|
|
281
|
-
ChatErrorCodes2["GenericError"] = "generic_error";
|
|
282
|
-
return ChatErrorCodes2;
|
|
283
|
-
})(ChatErrorCodes || {});
|
|
284
|
-
var ChatErrorMessage = {
|
|
285
|
-
["user_rejected" /* UserRejected */]: "User rejected the request.",
|
|
286
|
-
["send_failed" /* SendFailed */]: "Failed to send the message.",
|
|
287
|
-
["generic_error" /* GenericError */]: "Something unexpected went wrong."
|
|
288
|
-
};
|
|
289
|
-
|
|
290
|
-
// types/responses.ts
|
|
291
|
-
var ResponseEvent = /* @__PURE__ */ ((ResponseEvent2) => {
|
|
292
|
-
ResponseEvent2["MiniAppVerifyAction"] = "miniapp-verify-action";
|
|
293
|
-
ResponseEvent2["MiniAppPayment"] = "miniapp-payment";
|
|
294
|
-
ResponseEvent2["MiniAppWalletAuth"] = "miniapp-wallet-auth";
|
|
295
|
-
ResponseEvent2["MiniAppSendTransaction"] = "miniapp-send-transaction";
|
|
296
|
-
ResponseEvent2["MiniAppSignMessage"] = "miniapp-sign-message";
|
|
297
|
-
ResponseEvent2["MiniAppSignTypedData"] = "miniapp-sign-typed-data";
|
|
298
|
-
ResponseEvent2["MiniAppShareContacts"] = "miniapp-share-contacts";
|
|
299
|
-
ResponseEvent2["MiniAppRequestPermission"] = "miniapp-request-permission";
|
|
300
|
-
ResponseEvent2["MiniAppGetPermissions"] = "miniapp-get-permissions";
|
|
301
|
-
ResponseEvent2["MiniAppSendHapticFeedback"] = "miniapp-send-haptic-feedback";
|
|
302
|
-
ResponseEvent2["MiniAppShare"] = "miniapp-share";
|
|
303
|
-
ResponseEvent2["MiniAppMicrophone"] = "miniapp-microphone";
|
|
304
|
-
ResponseEvent2["MiniAppChat"] = "miniapp-chat";
|
|
305
|
-
return ResponseEvent2;
|
|
306
|
-
})(ResponseEvent || {});
|
|
307
|
-
|
|
308
|
-
// helpers/microphone/index.ts
|
|
309
|
-
var microphoneSetupDone = false;
|
|
310
|
-
var setupMicrophone = () => {
|
|
311
|
-
if (microphoneSetupDone) {
|
|
312
|
-
return;
|
|
313
|
-
}
|
|
314
|
-
if (typeof navigator !== "undefined" && !navigator.mediaDevices?.getUserMedia)
|
|
315
|
-
return;
|
|
316
|
-
const originalStop = MediaStreamTrack.prototype.stop;
|
|
317
|
-
MediaStreamTrack.prototype.stop = function() {
|
|
318
|
-
originalStop.call(this);
|
|
319
|
-
if (this.readyState === "ended") {
|
|
320
|
-
setTimeout(() => this.dispatchEvent(new Event("ended")), 0);
|
|
485
|
+
function createSendHapticFeedbackCommand(_ctx) {
|
|
486
|
+
return (payload) => {
|
|
487
|
+
if (typeof window === "undefined" || !isCommandAvailable("send-haptic-feedback" /* SendHapticFeedback */)) {
|
|
488
|
+
console.error(
|
|
489
|
+
"'sendHapticFeedback' command is unavailable. Check MiniKit.install() or update the app version"
|
|
490
|
+
);
|
|
491
|
+
return null;
|
|
321
492
|
}
|
|
493
|
+
sendMiniKitEvent({
|
|
494
|
+
command: "send-haptic-feedback" /* SendHapticFeedback */,
|
|
495
|
+
version: COMMAND_VERSIONS["send-haptic-feedback" /* SendHapticFeedback */],
|
|
496
|
+
payload
|
|
497
|
+
});
|
|
498
|
+
return payload;
|
|
322
499
|
};
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
)
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
t.addEventListener("ended", () => {
|
|
341
|
-
const allAudioTracksEnded = stream.getAudioTracks().every((track) => track.readyState === "ended");
|
|
342
|
-
if (allAudioTracksEnded) {
|
|
343
|
-
sendWebviewEvent({
|
|
344
|
-
command: "microphone-stream-ended",
|
|
345
|
-
version: 1,
|
|
346
|
-
payload: {
|
|
347
|
-
streamId: stream.id
|
|
348
|
-
}
|
|
349
|
-
});
|
|
350
|
-
live.delete(stream);
|
|
351
|
-
}
|
|
352
|
-
});
|
|
353
|
-
});
|
|
354
|
-
}
|
|
355
|
-
return stream;
|
|
356
|
-
}
|
|
357
|
-
Object.defineProperty(navigator.mediaDevices, "getUserMedia", {
|
|
358
|
-
value: wrapped,
|
|
359
|
-
writable: false,
|
|
360
|
-
configurable: false,
|
|
361
|
-
enumerable: true
|
|
362
|
-
});
|
|
363
|
-
Object.freeze(navigator.mediaDevices);
|
|
364
|
-
const stopAllMiniAppMicrophoneStreams = () => {
|
|
365
|
-
live.forEach((s) => {
|
|
366
|
-
const audioTracks = s.getAudioTracks();
|
|
367
|
-
if (audioTracks.length > 0) {
|
|
368
|
-
audioTracks.forEach((t) => {
|
|
369
|
-
t.stop();
|
|
370
|
-
});
|
|
371
|
-
sendWebviewEvent({
|
|
372
|
-
command: "microphone-stream-ended",
|
|
373
|
-
version: 1,
|
|
374
|
-
payload: {
|
|
375
|
-
streamId: s.id
|
|
376
|
-
}
|
|
377
|
-
});
|
|
500
|
+
}
|
|
501
|
+
function createSendHapticFeedbackAsyncCommand(ctx, syncCommand) {
|
|
502
|
+
return async (payload) => {
|
|
503
|
+
return new Promise((resolve, reject) => {
|
|
504
|
+
try {
|
|
505
|
+
let commandPayload = null;
|
|
506
|
+
const handleResponse = (response) => {
|
|
507
|
+
ctx.events.unsubscribe("miniapp-send-haptic-feedback" /* MiniAppSendHapticFeedback */);
|
|
508
|
+
resolve({ commandPayload, finalPayload: response });
|
|
509
|
+
};
|
|
510
|
+
ctx.events.subscribe(
|
|
511
|
+
"miniapp-send-haptic-feedback" /* MiniAppSendHapticFeedback */,
|
|
512
|
+
handleResponse
|
|
513
|
+
);
|
|
514
|
+
commandPayload = syncCommand(payload);
|
|
515
|
+
} catch (error) {
|
|
516
|
+
reject(error);
|
|
378
517
|
}
|
|
379
518
|
});
|
|
380
|
-
live.clear();
|
|
381
519
|
};
|
|
382
|
-
|
|
383
|
-
if (payload.status === "error" && (payload.error_code === "mini_app_permission_not_enabled" /* MiniAppPermissionNotEnabled */ || payload.error_code === "world_app_permission_not_enabled" /* WorldAppPermissionNotEnabled */)) {
|
|
384
|
-
console.log("stopping all microphone streams", payload);
|
|
385
|
-
stopAllMiniAppMicrophoneStreams();
|
|
386
|
-
}
|
|
387
|
-
});
|
|
388
|
-
window.__stopAllMiniAppMicrophoneStreams = stopAllMiniAppMicrophoneStreams;
|
|
389
|
-
microphoneSetupDone = true;
|
|
390
|
-
};
|
|
520
|
+
}
|
|
391
521
|
|
|
392
|
-
//
|
|
393
|
-
var
|
|
394
|
-
|
|
395
|
-
Tokens2["WLD"] = "WLD";
|
|
396
|
-
return Tokens2;
|
|
397
|
-
})(Tokens || {});
|
|
398
|
-
var TokenDecimals = {
|
|
399
|
-
["USDCE" /* USDC */]: 6,
|
|
400
|
-
["WLD" /* WLD */]: 18
|
|
522
|
+
// helpers/transaction/validate-payload.ts
|
|
523
|
+
var isValidHex = (str) => {
|
|
524
|
+
return /^0x[0-9A-Fa-f]+$/.test(str);
|
|
401
525
|
};
|
|
402
|
-
var
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
return Network2;
|
|
406
|
-
})(Network || {});
|
|
407
|
-
|
|
408
|
-
// helpers/payment/client.ts
|
|
409
|
-
var tokenToDecimals = (amount, token) => {
|
|
410
|
-
const decimals = TokenDecimals[token];
|
|
411
|
-
if (decimals === void 0) {
|
|
412
|
-
throw new Error(`Invalid token: ${token}`);
|
|
526
|
+
var objectValuesToArrayRecursive = (input) => {
|
|
527
|
+
if (input === null || typeof input !== "object") {
|
|
528
|
+
return input;
|
|
413
529
|
}
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
if (!Number.isInteger(result)) {
|
|
417
|
-
throw new Error(`The resulting amount is not a whole number: ${result}`);
|
|
530
|
+
if (Array.isArray(input)) {
|
|
531
|
+
return input.map((item) => objectValuesToArrayRecursive(item));
|
|
418
532
|
}
|
|
419
|
-
|
|
533
|
+
const values = Object.values(input);
|
|
534
|
+
return values.map((value) => objectValuesToArrayRecursive(value));
|
|
420
535
|
};
|
|
421
|
-
var
|
|
422
|
-
if (payload
|
|
423
|
-
|
|
424
|
-
)) {
|
|
425
|
-
console.error("USDC amount should be greater than $0.1");
|
|
426
|
-
return false;
|
|
536
|
+
var processPayload = (payload) => {
|
|
537
|
+
if (typeof payload === "boolean" || typeof payload === "string" || payload === null || payload === void 0) {
|
|
538
|
+
return payload;
|
|
427
539
|
}
|
|
428
|
-
if (payload
|
|
429
|
-
|
|
430
|
-
return false;
|
|
540
|
+
if (typeof payload === "number" || typeof payload === "bigint") {
|
|
541
|
+
return String(payload);
|
|
431
542
|
}
|
|
432
|
-
if (
|
|
433
|
-
|
|
543
|
+
if (Array.isArray(payload)) {
|
|
544
|
+
return payload.map((value) => processPayload(value));
|
|
434
545
|
}
|
|
435
|
-
|
|
436
|
-
};
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
var import_chains = require("viem/chains");
|
|
441
|
-
var semaphoreVerifierAddress = "0x79f46b94d134109EbcbbddBAeD0E88790409A0e4";
|
|
442
|
-
var semaphoreVerifierAbi = [
|
|
443
|
-
{
|
|
444
|
-
inputs: [
|
|
445
|
-
{
|
|
446
|
-
internalType: "uint256[8]",
|
|
447
|
-
name: "proof",
|
|
448
|
-
type: "uint256[8]"
|
|
546
|
+
if (typeof payload === "object") {
|
|
547
|
+
const result = { ...payload };
|
|
548
|
+
if ("value" in result && result.value !== void 0) {
|
|
549
|
+
if (typeof result.value !== "string") {
|
|
550
|
+
result.value = String(result.value);
|
|
449
551
|
}
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
552
|
+
if (!isValidHex(result.value)) {
|
|
553
|
+
console.error(
|
|
554
|
+
"Transaction value must be a valid hex string",
|
|
555
|
+
result.value
|
|
556
|
+
);
|
|
557
|
+
throw new Error(
|
|
558
|
+
`Transaction value must be a valid hex string: ${result.value}`
|
|
559
|
+
);
|
|
457
560
|
}
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
561
|
+
}
|
|
562
|
+
for (const key in result) {
|
|
563
|
+
if (Object.prototype.hasOwnProperty.call(result, key)) {
|
|
564
|
+
result[key] = processPayload(result[key]);
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
return result;
|
|
461
568
|
}
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
proof
|
|
474
|
-
)[0];
|
|
475
|
-
const compressedProof = await publicClient.readContract({
|
|
476
|
-
address: semaphoreVerifierAddress,
|
|
477
|
-
abi: semaphoreVerifierAbi,
|
|
478
|
-
functionName: "compressProof",
|
|
479
|
-
args: [decodedProof]
|
|
569
|
+
return payload;
|
|
570
|
+
};
|
|
571
|
+
var validateSendTransactionPayload = (payload) => {
|
|
572
|
+
if (payload.formatPayload) {
|
|
573
|
+
const formattedPayload = processPayload(payload);
|
|
574
|
+
formattedPayload.transaction = formattedPayload.transaction.map((tx) => {
|
|
575
|
+
const args = objectValuesToArrayRecursive(tx.args);
|
|
576
|
+
return {
|
|
577
|
+
...tx,
|
|
578
|
+
args
|
|
579
|
+
};
|
|
480
580
|
});
|
|
481
|
-
|
|
482
|
-
return (0, import_viem.encodeAbiParameters)([{ type: "uint256[8]" }], [paddedProof]);
|
|
483
|
-
} catch (e) {
|
|
484
|
-
return proof;
|
|
581
|
+
return formattedPayload;
|
|
485
582
|
}
|
|
583
|
+
return payload;
|
|
584
|
+
};
|
|
585
|
+
|
|
586
|
+
// commands/send-transaction.ts
|
|
587
|
+
var SendTransactionErrorCodes = /* @__PURE__ */ ((SendTransactionErrorCodes2) => {
|
|
588
|
+
SendTransactionErrorCodes2["InvalidOperation"] = "invalid_operation";
|
|
589
|
+
SendTransactionErrorCodes2["UserRejected"] = "user_rejected";
|
|
590
|
+
SendTransactionErrorCodes2["InputError"] = "input_error";
|
|
591
|
+
SendTransactionErrorCodes2["SimulationFailed"] = "simulation_failed";
|
|
592
|
+
SendTransactionErrorCodes2["TransactionFailed"] = "transaction_failed";
|
|
593
|
+
SendTransactionErrorCodes2["GenericError"] = "generic_error";
|
|
594
|
+
SendTransactionErrorCodes2["DisallowedOperation"] = "disallowed_operation";
|
|
595
|
+
SendTransactionErrorCodes2["ValidationError"] = "validation_error";
|
|
596
|
+
SendTransactionErrorCodes2["InvalidContract"] = "invalid_contract";
|
|
597
|
+
SendTransactionErrorCodes2["MaliciousOperation"] = "malicious_operation";
|
|
598
|
+
SendTransactionErrorCodes2["DailyTxLimitReached"] = "daily_tx_limit_reached";
|
|
599
|
+
SendTransactionErrorCodes2["PermittedAmountExceedsSlippage"] = "permitted_amount_exceeds_slippage";
|
|
600
|
+
SendTransactionErrorCodes2["PermittedAmountNotFound"] = "permitted_amount_not_found";
|
|
601
|
+
return SendTransactionErrorCodes2;
|
|
602
|
+
})(SendTransactionErrorCodes || {});
|
|
603
|
+
var SendTransactionErrorMessage = {
|
|
604
|
+
["invalid_operation" /* InvalidOperation */]: "Transaction included an operation that was invalid",
|
|
605
|
+
["user_rejected" /* UserRejected */]: "User rejected the request.",
|
|
606
|
+
["input_error" /* InputError */]: "Invalid payload.",
|
|
607
|
+
["simulation_failed" /* SimulationFailed */]: "The transaction simulation failed.",
|
|
608
|
+
["validation_error" /* ValidationError */]: "The transaction validation failed. Please try again.",
|
|
609
|
+
["transaction_failed" /* TransactionFailed */]: "The transaction failed. Please try again later.",
|
|
610
|
+
["generic_error" /* GenericError */]: "Something unexpected went wrong. Please try again.",
|
|
611
|
+
["disallowed_operation" /* DisallowedOperation */]: "The operation requested is not allowed. Please refer to the docs.",
|
|
612
|
+
["invalid_contract" /* InvalidContract */]: "The contract address is not allowed for your application. Please check your developer portal configurations",
|
|
613
|
+
["malicious_operation" /* MaliciousOperation */]: "The operation requested is considered malicious.",
|
|
614
|
+
["daily_tx_limit_reached" /* DailyTxLimitReached */]: "Daily transaction limit reached. Max 100 transactions per day. Wait until the next day.",
|
|
615
|
+
["permitted_amount_exceeds_slippage" /* PermittedAmountExceedsSlippage */]: "Permitted amount exceeds slippage. You must spend at least 90% of the permitted amount.",
|
|
616
|
+
["permitted_amount_not_found" /* PermittedAmountNotFound */]: "Permitted amount not found in permit2 payload."
|
|
486
617
|
};
|
|
618
|
+
function createSendTransactionCommand(_ctx) {
|
|
619
|
+
return (payload) => {
|
|
620
|
+
if (typeof window === "undefined" || !isCommandAvailable("send-transaction" /* SendTransaction */)) {
|
|
621
|
+
console.error(
|
|
622
|
+
"'sendTransaction' command is unavailable. Check MiniKit.install() or update the app version"
|
|
623
|
+
);
|
|
624
|
+
return null;
|
|
625
|
+
}
|
|
626
|
+
payload.formatPayload = payload.formatPayload !== false;
|
|
627
|
+
const validatedPayload = validateSendTransactionPayload(payload);
|
|
628
|
+
sendMiniKitEvent({
|
|
629
|
+
command: "send-transaction" /* SendTransaction */,
|
|
630
|
+
version: COMMAND_VERSIONS["send-transaction" /* SendTransaction */],
|
|
631
|
+
payload: validatedPayload
|
|
632
|
+
});
|
|
633
|
+
return validatedPayload;
|
|
634
|
+
};
|
|
635
|
+
}
|
|
636
|
+
function createSendTransactionAsyncCommand(ctx, syncCommand) {
|
|
637
|
+
return async (payload) => {
|
|
638
|
+
return new Promise((resolve, reject) => {
|
|
639
|
+
try {
|
|
640
|
+
let commandPayload = null;
|
|
641
|
+
const handleResponse = (response) => {
|
|
642
|
+
ctx.events.unsubscribe("miniapp-send-transaction" /* MiniAppSendTransaction */);
|
|
643
|
+
resolve({ commandPayload, finalPayload: response });
|
|
644
|
+
};
|
|
645
|
+
ctx.events.subscribe(
|
|
646
|
+
"miniapp-send-transaction" /* MiniAppSendTransaction */,
|
|
647
|
+
handleResponse
|
|
648
|
+
);
|
|
649
|
+
commandPayload = syncCommand(payload);
|
|
650
|
+
} catch (error) {
|
|
651
|
+
reject(error);
|
|
652
|
+
}
|
|
653
|
+
});
|
|
654
|
+
};
|
|
655
|
+
}
|
|
487
656
|
|
|
488
657
|
// helpers/share/index.ts
|
|
489
658
|
var MAX_FILES = 10;
|
|
@@ -551,115 +720,410 @@ var formatShareInput = async (input) => {
|
|
|
551
720
|
};
|
|
552
721
|
};
|
|
553
722
|
|
|
554
|
-
//
|
|
555
|
-
var
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
var
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
var RID_TAG = "Request ID: ";
|
|
566
|
-
var ERC_191_PREFIX = "Ethereum Signed Message:\n";
|
|
567
|
-
var EIP1271_MAGICVALUE = "0x1626ba7e";
|
|
568
|
-
var SAFE_CONTRACT_ABI = [
|
|
569
|
-
{
|
|
570
|
-
inputs: [
|
|
571
|
-
{
|
|
572
|
-
internalType: "address",
|
|
573
|
-
name: "owner",
|
|
574
|
-
type: "address"
|
|
575
|
-
}
|
|
576
|
-
],
|
|
577
|
-
name: "isOwner",
|
|
578
|
-
outputs: [
|
|
579
|
-
{
|
|
580
|
-
internalType: "bool",
|
|
581
|
-
name: "",
|
|
582
|
-
type: "bool"
|
|
583
|
-
}
|
|
584
|
-
],
|
|
585
|
-
stateMutability: "view",
|
|
586
|
-
type: "function"
|
|
587
|
-
},
|
|
588
|
-
{
|
|
589
|
-
inputs: [
|
|
590
|
-
{
|
|
591
|
-
internalType: "bytes32",
|
|
592
|
-
name: "_message",
|
|
593
|
-
type: "bytes32"
|
|
594
|
-
},
|
|
595
|
-
{
|
|
596
|
-
internalType: "bytes",
|
|
597
|
-
name: "_signature",
|
|
598
|
-
type: "bytes"
|
|
599
|
-
}
|
|
600
|
-
],
|
|
601
|
-
name: "isValidSignature",
|
|
602
|
-
outputs: [
|
|
603
|
-
{
|
|
604
|
-
internalType: "bytes4",
|
|
605
|
-
name: "",
|
|
606
|
-
type: "bytes4"
|
|
607
|
-
}
|
|
608
|
-
],
|
|
609
|
-
stateMutability: "view",
|
|
610
|
-
type: "function"
|
|
611
|
-
}
|
|
612
|
-
];
|
|
613
|
-
var tagged = (line, tag) => {
|
|
614
|
-
if (line && line.includes(tag)) {
|
|
615
|
-
return line.replace(tag, "");
|
|
616
|
-
} else {
|
|
617
|
-
throw new Error(`Missing '${tag}'`);
|
|
618
|
-
}
|
|
723
|
+
// commands/share.ts
|
|
724
|
+
var ShareFilesErrorCodes = /* @__PURE__ */ ((ShareFilesErrorCodes2) => {
|
|
725
|
+
ShareFilesErrorCodes2["UserRejected"] = "user_rejected";
|
|
726
|
+
ShareFilesErrorCodes2["GenericError"] = "generic_error";
|
|
727
|
+
ShareFilesErrorCodes2["InvalidFileName"] = "invalid_file_name";
|
|
728
|
+
return ShareFilesErrorCodes2;
|
|
729
|
+
})(ShareFilesErrorCodes || {});
|
|
730
|
+
var ShareFilesErrorMessage = {
|
|
731
|
+
["user_rejected" /* UserRejected */]: "User rejected the request.",
|
|
732
|
+
["generic_error" /* GenericError */]: "Something unexpected went wrong.",
|
|
733
|
+
["invalid_file_name" /* InvalidFileName */]: "Invalid file name. Make sure you include the extension"
|
|
619
734
|
};
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
if (nextValue) {
|
|
628
|
-
statement = nextValue;
|
|
629
|
-
lines.next();
|
|
630
|
-
}
|
|
631
|
-
const uri = tagged(lines.next()?.value, URI_TAG);
|
|
632
|
-
const version = tagged(lines.next()?.value, VERSION_TAG);
|
|
633
|
-
const chain_id = tagged(lines.next()?.value, CHAIN_TAG);
|
|
634
|
-
const nonce = tagged(lines.next()?.value, NONCE_TAG);
|
|
635
|
-
const issued_at = tagged(lines.next()?.value, IAT_TAG);
|
|
636
|
-
let expiration_time, not_before, request_id;
|
|
637
|
-
for (let line of lines) {
|
|
638
|
-
if (line.startsWith(EXP_TAG)) {
|
|
639
|
-
expiration_time = tagged(line, EXP_TAG);
|
|
640
|
-
} else if (line.startsWith(NBF_TAG)) {
|
|
641
|
-
not_before = tagged(line, NBF_TAG);
|
|
642
|
-
} else if (line.startsWith(RID_TAG)) {
|
|
643
|
-
request_id = tagged(line, RID_TAG);
|
|
735
|
+
function createShareCommand(ctx) {
|
|
736
|
+
return (payload) => {
|
|
737
|
+
if (typeof window === "undefined" || !isCommandAvailable("share" /* Share */)) {
|
|
738
|
+
console.error(
|
|
739
|
+
"'share' command is unavailable. Check MiniKit.install() or update the app version"
|
|
740
|
+
);
|
|
741
|
+
return null;
|
|
644
742
|
}
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
743
|
+
if (ctx.state.deviceProperties.deviceOS === "ios" && typeof navigator !== "undefined") {
|
|
744
|
+
sendMiniKitEvent({
|
|
745
|
+
command: "share" /* Share */,
|
|
746
|
+
version: COMMAND_VERSIONS["share" /* Share */],
|
|
747
|
+
payload
|
|
748
|
+
});
|
|
749
|
+
navigator.share(payload);
|
|
750
|
+
} else {
|
|
751
|
+
formatShareInput(payload).then((formattedResult) => {
|
|
752
|
+
sendMiniKitEvent({
|
|
753
|
+
command: "share" /* Share */,
|
|
754
|
+
version: COMMAND_VERSIONS["share" /* Share */],
|
|
755
|
+
payload: formattedResult
|
|
756
|
+
});
|
|
757
|
+
}).catch((error) => {
|
|
758
|
+
console.error("Failed to format share input", error);
|
|
759
|
+
});
|
|
760
|
+
ctx.events.subscribe("miniapp-share" /* MiniAppShare */, (response) => {
|
|
761
|
+
console.log("Share Response", response);
|
|
762
|
+
});
|
|
763
|
+
}
|
|
764
|
+
return payload;
|
|
765
|
+
};
|
|
766
|
+
}
|
|
767
|
+
function createShareAsyncCommand(ctx, syncCommand) {
|
|
768
|
+
return async (payload) => {
|
|
769
|
+
return new Promise((resolve, reject) => {
|
|
770
|
+
try {
|
|
771
|
+
let commandPayload = null;
|
|
772
|
+
const handleResponse = (response) => {
|
|
773
|
+
ctx.events.unsubscribe("miniapp-share" /* MiniAppShare */);
|
|
774
|
+
resolve({ commandPayload, finalPayload: response });
|
|
775
|
+
};
|
|
776
|
+
ctx.events.subscribe("miniapp-share" /* MiniAppShare */, handleResponse);
|
|
777
|
+
commandPayload = syncCommand(payload);
|
|
778
|
+
} catch (error) {
|
|
779
|
+
reject(error);
|
|
780
|
+
}
|
|
781
|
+
});
|
|
782
|
+
};
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
// commands/share-contacts.ts
|
|
786
|
+
var ShareContactsErrorCodes = /* @__PURE__ */ ((ShareContactsErrorCodes2) => {
|
|
787
|
+
ShareContactsErrorCodes2["UserRejected"] = "user_rejected";
|
|
788
|
+
ShareContactsErrorCodes2["GenericError"] = "generic_error";
|
|
789
|
+
return ShareContactsErrorCodes2;
|
|
790
|
+
})(ShareContactsErrorCodes || {});
|
|
791
|
+
var ShareContactsErrorMessage = {
|
|
792
|
+
["user_rejected" /* UserRejected */]: "User rejected the request.",
|
|
793
|
+
["generic_error" /* GenericError */]: "Something unexpected went wrong."
|
|
794
|
+
};
|
|
795
|
+
function createShareContactsCommand(_ctx) {
|
|
796
|
+
return (payload) => {
|
|
797
|
+
if (typeof window === "undefined" || !isCommandAvailable("share-contacts" /* ShareContacts */)) {
|
|
798
|
+
console.error(
|
|
799
|
+
"'shareContacts' command is unavailable. Check MiniKit.install() or update the app version"
|
|
800
|
+
);
|
|
801
|
+
return null;
|
|
802
|
+
}
|
|
803
|
+
sendMiniKitEvent({
|
|
804
|
+
command: "share-contacts" /* ShareContacts */,
|
|
805
|
+
version: COMMAND_VERSIONS["share-contacts" /* ShareContacts */],
|
|
806
|
+
payload
|
|
807
|
+
});
|
|
808
|
+
return payload;
|
|
809
|
+
};
|
|
810
|
+
}
|
|
811
|
+
function createShareContactsAsyncCommand(ctx, syncCommand) {
|
|
812
|
+
return async (payload) => {
|
|
813
|
+
return new Promise((resolve, reject) => {
|
|
814
|
+
try {
|
|
815
|
+
let commandPayload = null;
|
|
816
|
+
const handleResponse = (response) => {
|
|
817
|
+
ctx.events.unsubscribe("miniapp-share-contacts" /* MiniAppShareContacts */);
|
|
818
|
+
resolve({ commandPayload, finalPayload: response });
|
|
819
|
+
};
|
|
820
|
+
ctx.events.subscribe(
|
|
821
|
+
"miniapp-share-contacts" /* MiniAppShareContacts */,
|
|
822
|
+
handleResponse
|
|
823
|
+
);
|
|
824
|
+
commandPayload = syncCommand(payload);
|
|
825
|
+
} catch (error) {
|
|
826
|
+
reject(error);
|
|
827
|
+
}
|
|
828
|
+
});
|
|
829
|
+
};
|
|
830
|
+
}
|
|
831
|
+
|
|
832
|
+
// commands/sign-message.ts
|
|
833
|
+
var SignMessageErrorCodes = /* @__PURE__ */ ((SignMessageErrorCodes2) => {
|
|
834
|
+
SignMessageErrorCodes2["InvalidMessage"] = "invalid_message";
|
|
835
|
+
SignMessageErrorCodes2["UserRejected"] = "user_rejected";
|
|
836
|
+
SignMessageErrorCodes2["GenericError"] = "generic_error";
|
|
837
|
+
return SignMessageErrorCodes2;
|
|
838
|
+
})(SignMessageErrorCodes || {});
|
|
839
|
+
var SignMessageErrorMessage = {
|
|
840
|
+
["invalid_message" /* InvalidMessage */]: "Invalid message requested",
|
|
841
|
+
["user_rejected" /* UserRejected */]: "User rejected the request.",
|
|
842
|
+
["generic_error" /* GenericError */]: "Something unexpected went wrong."
|
|
843
|
+
};
|
|
844
|
+
function createSignMessageCommand(_ctx) {
|
|
845
|
+
return (payload) => {
|
|
846
|
+
if (typeof window === "undefined" || !isCommandAvailable("sign-message" /* SignMessage */)) {
|
|
847
|
+
console.error(
|
|
848
|
+
"'signMessage' command is unavailable. Check MiniKit.install() or update the app version"
|
|
849
|
+
);
|
|
850
|
+
return null;
|
|
851
|
+
}
|
|
852
|
+
sendMiniKitEvent({
|
|
853
|
+
command: "sign-message" /* SignMessage */,
|
|
854
|
+
version: COMMAND_VERSIONS["sign-message" /* SignMessage */],
|
|
855
|
+
payload
|
|
856
|
+
});
|
|
857
|
+
return payload;
|
|
858
|
+
};
|
|
859
|
+
}
|
|
860
|
+
function createSignMessageAsyncCommand(ctx, syncCommand) {
|
|
861
|
+
return async (payload) => {
|
|
862
|
+
return new Promise((resolve, reject) => {
|
|
863
|
+
try {
|
|
864
|
+
let commandPayload = null;
|
|
865
|
+
const handleResponse = (response) => {
|
|
866
|
+
ctx.events.unsubscribe("miniapp-sign-message" /* MiniAppSignMessage */);
|
|
867
|
+
resolve({ commandPayload, finalPayload: response });
|
|
868
|
+
};
|
|
869
|
+
ctx.events.subscribe(
|
|
870
|
+
"miniapp-sign-message" /* MiniAppSignMessage */,
|
|
871
|
+
handleResponse
|
|
872
|
+
);
|
|
873
|
+
commandPayload = syncCommand(payload);
|
|
874
|
+
} catch (error) {
|
|
875
|
+
reject(error);
|
|
876
|
+
}
|
|
877
|
+
});
|
|
878
|
+
};
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
// commands/sign-typed-data.ts
|
|
882
|
+
var SignTypedDataErrorCodes = /* @__PURE__ */ ((SignTypedDataErrorCodes2) => {
|
|
883
|
+
SignTypedDataErrorCodes2["InvalidOperation"] = "invalid_operation";
|
|
884
|
+
SignTypedDataErrorCodes2["UserRejected"] = "user_rejected";
|
|
885
|
+
SignTypedDataErrorCodes2["InputError"] = "input_error";
|
|
886
|
+
SignTypedDataErrorCodes2["SimulationFailed"] = "simulation_failed";
|
|
887
|
+
SignTypedDataErrorCodes2["GenericError"] = "generic_error";
|
|
888
|
+
SignTypedDataErrorCodes2["DisallowedOperation"] = "disallowed_operation";
|
|
889
|
+
SignTypedDataErrorCodes2["InvalidContract"] = "invalid_contract";
|
|
890
|
+
SignTypedDataErrorCodes2["MaliciousOperation"] = "malicious_operation";
|
|
891
|
+
return SignTypedDataErrorCodes2;
|
|
892
|
+
})(SignTypedDataErrorCodes || {});
|
|
893
|
+
var SignTypedDataErrorMessage = {
|
|
894
|
+
["invalid_operation" /* InvalidOperation */]: "Transaction included an operation that was invalid",
|
|
895
|
+
["user_rejected" /* UserRejected */]: "User rejected the request.",
|
|
896
|
+
["input_error" /* InputError */]: "Invalid payload.",
|
|
897
|
+
["simulation_failed" /* SimulationFailed */]: "The transaction simulation failed.",
|
|
898
|
+
["generic_error" /* GenericError */]: "Something unexpected went wrong. Please try again.",
|
|
899
|
+
["disallowed_operation" /* DisallowedOperation */]: "The operation requested is not allowed. Please refer to the docs.",
|
|
900
|
+
["invalid_contract" /* InvalidContract */]: "The contract address is not allowed for your application. Please check your developer portal configurations",
|
|
901
|
+
["malicious_operation" /* MaliciousOperation */]: "The operation requested is considered malicious."
|
|
902
|
+
};
|
|
903
|
+
function createSignTypedDataCommand(_ctx) {
|
|
904
|
+
return (payload) => {
|
|
905
|
+
if (typeof window === "undefined" || !isCommandAvailable("sign-typed-data" /* SignTypedData */)) {
|
|
906
|
+
console.error(
|
|
907
|
+
"'signTypedData' command is unavailable. Check MiniKit.install() or update the app version"
|
|
908
|
+
);
|
|
909
|
+
return null;
|
|
910
|
+
}
|
|
911
|
+
if (!payload.chainId) {
|
|
912
|
+
payload.chainId = 480;
|
|
913
|
+
}
|
|
914
|
+
sendMiniKitEvent({
|
|
915
|
+
command: "sign-typed-data" /* SignTypedData */,
|
|
916
|
+
version: COMMAND_VERSIONS["sign-typed-data" /* SignTypedData */],
|
|
917
|
+
payload
|
|
918
|
+
});
|
|
919
|
+
return payload;
|
|
920
|
+
};
|
|
921
|
+
}
|
|
922
|
+
function createSignTypedDataAsyncCommand(ctx, syncCommand) {
|
|
923
|
+
return async (payload) => {
|
|
924
|
+
return new Promise((resolve, reject) => {
|
|
925
|
+
try {
|
|
926
|
+
let commandPayload = null;
|
|
927
|
+
const handleResponse = (response) => {
|
|
928
|
+
ctx.events.unsubscribe("miniapp-sign-typed-data" /* MiniAppSignTypedData */);
|
|
929
|
+
resolve({ commandPayload, finalPayload: response });
|
|
930
|
+
};
|
|
931
|
+
ctx.events.subscribe(
|
|
932
|
+
"miniapp-sign-typed-data" /* MiniAppSignTypedData */,
|
|
933
|
+
handleResponse
|
|
934
|
+
);
|
|
935
|
+
commandPayload = syncCommand(payload);
|
|
936
|
+
} catch (error) {
|
|
937
|
+
reject(error);
|
|
938
|
+
}
|
|
939
|
+
});
|
|
940
|
+
};
|
|
941
|
+
}
|
|
942
|
+
|
|
943
|
+
// commands/verify.ts
|
|
944
|
+
var import_idkit_core = require("@worldcoin/idkit-core");
|
|
945
|
+
var import_hashing = require("@worldcoin/idkit-core/hashing");
|
|
946
|
+
var import_idkit_core2 = require("@worldcoin/idkit-core");
|
|
947
|
+
function createVerifyCommand(ctx) {
|
|
948
|
+
return (payload) => {
|
|
949
|
+
if (typeof window === "undefined" || !isCommandAvailable("verify" /* Verify */)) {
|
|
950
|
+
console.error(
|
|
951
|
+
"'verify' command is unavailable. Check MiniKit.install() or update the app version"
|
|
952
|
+
);
|
|
953
|
+
return null;
|
|
954
|
+
}
|
|
955
|
+
if (Array.isArray(payload.verification_level) && payload.verification_level.length === 0) {
|
|
956
|
+
console.error("'verification_level' must not be an empty array");
|
|
957
|
+
return null;
|
|
958
|
+
}
|
|
959
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
960
|
+
const eventPayload = {
|
|
961
|
+
action: (0, import_hashing.encodeAction)(payload.action),
|
|
962
|
+
signal: (0, import_hashing.generateSignal)(payload.signal).digest,
|
|
963
|
+
verification_level: payload.verification_level || import_idkit_core.VerificationLevel.Orb,
|
|
964
|
+
timestamp
|
|
965
|
+
};
|
|
966
|
+
ctx.events.setVerifyActionProcessingOptions({
|
|
967
|
+
skip_proof_compression: payload.skip_proof_compression
|
|
968
|
+
});
|
|
969
|
+
sendMiniKitEvent({
|
|
970
|
+
command: "verify" /* Verify */,
|
|
971
|
+
version: COMMAND_VERSIONS["verify" /* Verify */],
|
|
972
|
+
payload: eventPayload
|
|
973
|
+
});
|
|
974
|
+
return eventPayload;
|
|
975
|
+
};
|
|
976
|
+
}
|
|
977
|
+
function createVerifyAsyncCommand(ctx, syncCommand) {
|
|
978
|
+
let hasInFlightVerifyRequest = false;
|
|
979
|
+
return async (payload) => {
|
|
980
|
+
if (hasInFlightVerifyRequest) {
|
|
981
|
+
return Promise.reject(
|
|
982
|
+
new Error(
|
|
983
|
+
"A verify request is already in flight. Wait for the current request to complete before sending another."
|
|
984
|
+
)
|
|
985
|
+
);
|
|
986
|
+
}
|
|
987
|
+
return new Promise((resolve, reject) => {
|
|
988
|
+
try {
|
|
989
|
+
hasInFlightVerifyRequest = true;
|
|
990
|
+
let commandPayload = null;
|
|
991
|
+
const handleResponse = (response) => {
|
|
992
|
+
ctx.events.unsubscribe("miniapp-verify-action" /* MiniAppVerifyAction */);
|
|
993
|
+
hasInFlightVerifyRequest = false;
|
|
994
|
+
resolve({ commandPayload, finalPayload: response });
|
|
995
|
+
};
|
|
996
|
+
ctx.events.subscribe(
|
|
997
|
+
"miniapp-verify-action" /* MiniAppVerifyAction */,
|
|
998
|
+
handleResponse
|
|
999
|
+
);
|
|
1000
|
+
commandPayload = syncCommand(payload);
|
|
1001
|
+
if (commandPayload === null) {
|
|
1002
|
+
ctx.events.unsubscribe("miniapp-verify-action" /* MiniAppVerifyAction */);
|
|
1003
|
+
hasInFlightVerifyRequest = false;
|
|
1004
|
+
reject(
|
|
1005
|
+
new Error(
|
|
1006
|
+
"Failed to send verify command. Ensure MiniKit is installed and the verify command is available."
|
|
1007
|
+
)
|
|
1008
|
+
);
|
|
1009
|
+
}
|
|
1010
|
+
} catch (error) {
|
|
1011
|
+
hasInFlightVerifyRequest = false;
|
|
1012
|
+
reject(error);
|
|
1013
|
+
}
|
|
1014
|
+
});
|
|
1015
|
+
};
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
// helpers/siwe/siwe.ts
|
|
1019
|
+
var import_viem = require("viem");
|
|
1020
|
+
var import_chains = require("viem/chains");
|
|
1021
|
+
var PREAMBLE = " wants you to sign in with your Ethereum account:";
|
|
1022
|
+
var URI_TAG = "URI: ";
|
|
1023
|
+
var VERSION_TAG = "Version: ";
|
|
1024
|
+
var CHAIN_TAG = "Chain ID: ";
|
|
1025
|
+
var NONCE_TAG = "Nonce: ";
|
|
1026
|
+
var IAT_TAG = "Issued At: ";
|
|
1027
|
+
var EXP_TAG = "Expiration Time: ";
|
|
1028
|
+
var NBF_TAG = "Not Before: ";
|
|
1029
|
+
var RID_TAG = "Request ID: ";
|
|
1030
|
+
var ERC_191_PREFIX = "Ethereum Signed Message:\n";
|
|
1031
|
+
var EIP1271_MAGICVALUE = "0x1626ba7e";
|
|
1032
|
+
var SAFE_CONTRACT_ABI = [
|
|
1033
|
+
{
|
|
1034
|
+
inputs: [
|
|
1035
|
+
{
|
|
1036
|
+
internalType: "address",
|
|
1037
|
+
name: "owner",
|
|
1038
|
+
type: "address"
|
|
1039
|
+
}
|
|
1040
|
+
],
|
|
1041
|
+
name: "isOwner",
|
|
1042
|
+
outputs: [
|
|
1043
|
+
{
|
|
1044
|
+
internalType: "bool",
|
|
1045
|
+
name: "",
|
|
1046
|
+
type: "bool"
|
|
1047
|
+
}
|
|
1048
|
+
],
|
|
1049
|
+
stateMutability: "view",
|
|
1050
|
+
type: "function"
|
|
1051
|
+
},
|
|
1052
|
+
{
|
|
1053
|
+
inputs: [
|
|
1054
|
+
{
|
|
1055
|
+
internalType: "bytes32",
|
|
1056
|
+
name: "_message",
|
|
1057
|
+
type: "bytes32"
|
|
1058
|
+
},
|
|
1059
|
+
{
|
|
1060
|
+
internalType: "bytes",
|
|
1061
|
+
name: "_signature",
|
|
1062
|
+
type: "bytes"
|
|
1063
|
+
}
|
|
1064
|
+
],
|
|
1065
|
+
name: "isValidSignature",
|
|
1066
|
+
outputs: [
|
|
1067
|
+
{
|
|
1068
|
+
internalType: "bytes4",
|
|
1069
|
+
name: "",
|
|
1070
|
+
type: "bytes4"
|
|
1071
|
+
}
|
|
1072
|
+
],
|
|
1073
|
+
stateMutability: "view",
|
|
1074
|
+
type: "function"
|
|
1075
|
+
}
|
|
1076
|
+
];
|
|
1077
|
+
var tagged = (line, tag) => {
|
|
1078
|
+
if (line && line.includes(tag)) {
|
|
1079
|
+
return line.replace(tag, "");
|
|
1080
|
+
} else {
|
|
1081
|
+
throw new Error(`Missing '${tag}'`);
|
|
1082
|
+
}
|
|
1083
|
+
};
|
|
1084
|
+
var parseSiweMessage = (inputString) => {
|
|
1085
|
+
const lines = inputString.split("\n")[Symbol.iterator]();
|
|
1086
|
+
const domain = tagged(lines.next()?.value, PREAMBLE);
|
|
1087
|
+
const address = lines.next()?.value;
|
|
1088
|
+
lines.next();
|
|
1089
|
+
const nextValue = lines.next()?.value;
|
|
1090
|
+
let statement;
|
|
1091
|
+
if (nextValue) {
|
|
1092
|
+
statement = nextValue;
|
|
1093
|
+
lines.next();
|
|
1094
|
+
}
|
|
1095
|
+
const uri = tagged(lines.next()?.value, URI_TAG);
|
|
1096
|
+
const version = tagged(lines.next()?.value, VERSION_TAG);
|
|
1097
|
+
const chain_id = tagged(lines.next()?.value, CHAIN_TAG);
|
|
1098
|
+
const nonce = tagged(lines.next()?.value, NONCE_TAG);
|
|
1099
|
+
const issued_at = tagged(lines.next()?.value, IAT_TAG);
|
|
1100
|
+
let expiration_time, not_before, request_id;
|
|
1101
|
+
for (let line of lines) {
|
|
1102
|
+
if (line.startsWith(EXP_TAG)) {
|
|
1103
|
+
expiration_time = tagged(line, EXP_TAG);
|
|
1104
|
+
} else if (line.startsWith(NBF_TAG)) {
|
|
1105
|
+
not_before = tagged(line, NBF_TAG);
|
|
1106
|
+
} else if (line.startsWith(RID_TAG)) {
|
|
1107
|
+
request_id = tagged(line, RID_TAG);
|
|
1108
|
+
}
|
|
1109
|
+
}
|
|
1110
|
+
if (lines.next().done === false) {
|
|
1111
|
+
throw new Error("Extra lines in the input");
|
|
1112
|
+
}
|
|
1113
|
+
const siweMessageData = {
|
|
1114
|
+
domain,
|
|
1115
|
+
address,
|
|
1116
|
+
statement,
|
|
1117
|
+
uri,
|
|
1118
|
+
version,
|
|
1119
|
+
chain_id,
|
|
1120
|
+
nonce,
|
|
1121
|
+
issued_at,
|
|
1122
|
+
expiration_time,
|
|
1123
|
+
not_before,
|
|
1124
|
+
request_id
|
|
1125
|
+
};
|
|
1126
|
+
return siweMessageData;
|
|
663
1127
|
};
|
|
664
1128
|
var generateSiweMessage = (siweMessageData) => {
|
|
665
1129
|
let siweMessage = "";
|
|
@@ -762,16 +1226,16 @@ var verifySiweMessageV1 = async (payload, nonce, statement, requestId, userProvi
|
|
|
762
1226
|
const { message, signature, address } = payload;
|
|
763
1227
|
const siweMessageData = parseSiweMessage(message);
|
|
764
1228
|
validateMessage(siweMessageData, nonce, statement, requestId);
|
|
765
|
-
let provider = userProvider || (0,
|
|
1229
|
+
let provider = userProvider || (0, import_viem.createPublicClient)({ chain: import_chains.worldchain, transport: (0, import_viem.http)() });
|
|
766
1230
|
const signedMessage = `${ERC_191_PREFIX}${message.length}${message}`;
|
|
767
|
-
const hashedMessage = (0,
|
|
768
|
-
const contract = (0,
|
|
1231
|
+
const hashedMessage = (0, import_viem.hashMessage)(signedMessage);
|
|
1232
|
+
const contract = (0, import_viem.getContract)({
|
|
769
1233
|
address,
|
|
770
1234
|
abi: SAFE_CONTRACT_ABI,
|
|
771
1235
|
client: provider
|
|
772
1236
|
});
|
|
773
1237
|
try {
|
|
774
|
-
const recoveredAddress = await (0,
|
|
1238
|
+
const recoveredAddress = await (0, import_viem.recoverAddress)({
|
|
775
1239
|
hash: hashedMessage,
|
|
776
1240
|
signature: `0x${signature}`
|
|
777
1241
|
});
|
|
@@ -794,12 +1258,12 @@ var verifySiweMessageV2 = async (payload, nonce, statement, requestId, userProvi
|
|
|
794
1258
|
throw new Error("Validation failed");
|
|
795
1259
|
}
|
|
796
1260
|
try {
|
|
797
|
-
const walletContract = (0,
|
|
1261
|
+
const walletContract = (0, import_viem.getContract)({
|
|
798
1262
|
address,
|
|
799
1263
|
abi: SAFE_CONTRACT_ABI,
|
|
800
|
-
client: userProvider || (0,
|
|
1264
|
+
client: userProvider || (0, import_viem.createPublicClient)({ chain: import_chains.worldchain, transport: (0, import_viem.http)() })
|
|
801
1265
|
});
|
|
802
|
-
const hashedMessage = (0,
|
|
1266
|
+
const hashedMessage = (0, import_viem.hashMessage)(message);
|
|
803
1267
|
const res = await walletContract.read.isValidSignature([
|
|
804
1268
|
hashedMessage,
|
|
805
1269
|
signature
|
|
@@ -834,71 +1298,303 @@ var validateWalletAuthCommandInput = (params) => {
|
|
|
834
1298
|
if (params.notBefore && new Date(params.notBefore) > new Date(Date.now() + 7 * 24 * 60 * 60 * 1e3)) {
|
|
835
1299
|
return { valid: false, message: "'notBefore' must be within 7 days" };
|
|
836
1300
|
}
|
|
837
|
-
return { valid: true };
|
|
1301
|
+
return { valid: true };
|
|
1302
|
+
};
|
|
1303
|
+
|
|
1304
|
+
// commands/wallet-auth.ts
|
|
1305
|
+
var WalletAuthErrorCodes = /* @__PURE__ */ ((WalletAuthErrorCodes2) => {
|
|
1306
|
+
WalletAuthErrorCodes2["MalformedRequest"] = "malformed_request";
|
|
1307
|
+
WalletAuthErrorCodes2["UserRejected"] = "user_rejected";
|
|
1308
|
+
WalletAuthErrorCodes2["GenericError"] = "generic_error";
|
|
1309
|
+
return WalletAuthErrorCodes2;
|
|
1310
|
+
})(WalletAuthErrorCodes || {});
|
|
1311
|
+
var WalletAuthErrorMessage = {
|
|
1312
|
+
["malformed_request" /* MalformedRequest */]: "Provided parameters in the request are invalid.",
|
|
1313
|
+
["user_rejected" /* UserRejected */]: "User rejected the request.",
|
|
1314
|
+
["generic_error" /* GenericError */]: "Something unexpected went wrong."
|
|
1315
|
+
};
|
|
1316
|
+
function createWalletAuthCommand(ctx) {
|
|
1317
|
+
return (payload) => {
|
|
1318
|
+
if (typeof window === "undefined" || !isCommandAvailable("wallet-auth" /* WalletAuth */)) {
|
|
1319
|
+
console.error(
|
|
1320
|
+
"'walletAuth' command is unavailable. Check MiniKit.install() or update the app version"
|
|
1321
|
+
);
|
|
1322
|
+
return null;
|
|
1323
|
+
}
|
|
1324
|
+
const validationResult = validateWalletAuthCommandInput(payload);
|
|
1325
|
+
if (!validationResult.valid) {
|
|
1326
|
+
console.error(
|
|
1327
|
+
"Failed to validate wallet auth input:\n\n -->",
|
|
1328
|
+
validationResult.message
|
|
1329
|
+
);
|
|
1330
|
+
return null;
|
|
1331
|
+
}
|
|
1332
|
+
let protocol = null;
|
|
1333
|
+
try {
|
|
1334
|
+
const currentUrl = new URL(window.location.href);
|
|
1335
|
+
protocol = currentUrl.protocol.split(":")[0];
|
|
1336
|
+
} catch (error) {
|
|
1337
|
+
console.error("Failed to get current URL", error);
|
|
1338
|
+
return null;
|
|
1339
|
+
}
|
|
1340
|
+
const siweMessage = generateSiweMessage({
|
|
1341
|
+
scheme: protocol,
|
|
1342
|
+
domain: window.location.host,
|
|
1343
|
+
statement: payload.statement ?? void 0,
|
|
1344
|
+
uri: window.location.href,
|
|
1345
|
+
version: "1",
|
|
1346
|
+
chain_id: 480,
|
|
1347
|
+
nonce: payload.nonce,
|
|
1348
|
+
issued_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1349
|
+
expiration_time: payload.expirationTime?.toISOString() ?? void 0,
|
|
1350
|
+
not_before: payload.notBefore?.toISOString() ?? void 0,
|
|
1351
|
+
request_id: payload.requestId ?? void 0
|
|
1352
|
+
});
|
|
1353
|
+
const walletAuthPayload = { siweMessage };
|
|
1354
|
+
const walletAuthVersion = ctx.state.user.worldAppVersion && ctx.state.user.worldAppVersion > 2087900 ? COMMAND_VERSIONS["wallet-auth" /* WalletAuth */] : 1;
|
|
1355
|
+
sendMiniKitEvent({
|
|
1356
|
+
command: "wallet-auth" /* WalletAuth */,
|
|
1357
|
+
version: walletAuthVersion,
|
|
1358
|
+
payload: walletAuthPayload
|
|
1359
|
+
});
|
|
1360
|
+
return walletAuthPayload;
|
|
1361
|
+
};
|
|
1362
|
+
}
|
|
1363
|
+
function createWalletAuthAsyncCommand(ctx, syncCommand) {
|
|
1364
|
+
return async (payload) => {
|
|
1365
|
+
return new Promise((resolve, reject) => {
|
|
1366
|
+
try {
|
|
1367
|
+
let commandPayload = null;
|
|
1368
|
+
const handleResponse = async (response) => {
|
|
1369
|
+
ctx.events.unsubscribe("miniapp-wallet-auth" /* MiniAppWalletAuth */);
|
|
1370
|
+
if (response.status === "success") {
|
|
1371
|
+
await ctx.state.updateUserFromWalletAuth(response.address);
|
|
1372
|
+
}
|
|
1373
|
+
resolve({ commandPayload, finalPayload: response });
|
|
1374
|
+
};
|
|
1375
|
+
ctx.events.subscribe(
|
|
1376
|
+
"miniapp-wallet-auth" /* MiniAppWalletAuth */,
|
|
1377
|
+
handleResponse
|
|
1378
|
+
);
|
|
1379
|
+
commandPayload = syncCommand(payload);
|
|
1380
|
+
} catch (error) {
|
|
1381
|
+
reject(error);
|
|
1382
|
+
}
|
|
1383
|
+
});
|
|
1384
|
+
};
|
|
1385
|
+
}
|
|
1386
|
+
|
|
1387
|
+
// commands/index.ts
|
|
1388
|
+
function createCommands(ctx) {
|
|
1389
|
+
return {
|
|
1390
|
+
verify: createVerifyCommand(ctx),
|
|
1391
|
+
pay: createPayCommand(ctx),
|
|
1392
|
+
walletAuth: createWalletAuthCommand(ctx),
|
|
1393
|
+
sendTransaction: createSendTransactionCommand(ctx),
|
|
1394
|
+
signMessage: createSignMessageCommand(ctx),
|
|
1395
|
+
signTypedData: createSignTypedDataCommand(ctx),
|
|
1396
|
+
shareContacts: createShareContactsCommand(ctx),
|
|
1397
|
+
requestPermission: createRequestPermissionCommand(ctx),
|
|
1398
|
+
getPermissions: createGetPermissionsCommand(ctx),
|
|
1399
|
+
sendHapticFeedback: createSendHapticFeedbackCommand(ctx),
|
|
1400
|
+
share: createShareCommand(ctx),
|
|
1401
|
+
chat: createChatCommand(ctx)
|
|
1402
|
+
};
|
|
1403
|
+
}
|
|
1404
|
+
function createAsyncCommands(ctx, commands) {
|
|
1405
|
+
return {
|
|
1406
|
+
verify: createVerifyAsyncCommand(ctx, commands.verify),
|
|
1407
|
+
pay: createPayAsyncCommand(ctx, commands.pay),
|
|
1408
|
+
walletAuth: createWalletAuthAsyncCommand(ctx, commands.walletAuth),
|
|
1409
|
+
sendTransaction: createSendTransactionAsyncCommand(
|
|
1410
|
+
ctx,
|
|
1411
|
+
commands.sendTransaction
|
|
1412
|
+
),
|
|
1413
|
+
signMessage: createSignMessageAsyncCommand(ctx, commands.signMessage),
|
|
1414
|
+
signTypedData: createSignTypedDataAsyncCommand(ctx, commands.signTypedData),
|
|
1415
|
+
shareContacts: createShareContactsAsyncCommand(ctx, commands.shareContacts),
|
|
1416
|
+
requestPermission: createRequestPermissionAsyncCommand(
|
|
1417
|
+
ctx,
|
|
1418
|
+
commands.requestPermission
|
|
1419
|
+
),
|
|
1420
|
+
getPermissions: createGetPermissionsAsyncCommand(
|
|
1421
|
+
ctx,
|
|
1422
|
+
commands.getPermissions
|
|
1423
|
+
),
|
|
1424
|
+
sendHapticFeedback: createSendHapticFeedbackAsyncCommand(
|
|
1425
|
+
ctx,
|
|
1426
|
+
commands.sendHapticFeedback
|
|
1427
|
+
),
|
|
1428
|
+
share: createShareAsyncCommand(ctx, commands.share),
|
|
1429
|
+
chat: createChatAsyncCommand(ctx, commands.chat)
|
|
1430
|
+
};
|
|
1431
|
+
}
|
|
1432
|
+
|
|
1433
|
+
// core/events.ts
|
|
1434
|
+
var import_idkit_core3 = require("@worldcoin/idkit-core");
|
|
1435
|
+
|
|
1436
|
+
// helpers/proof/index.ts
|
|
1437
|
+
var import_viem2 = require("viem");
|
|
1438
|
+
var import_chains2 = require("viem/chains");
|
|
1439
|
+
var semaphoreVerifierAddress = "0x79f46b94d134109EbcbbddBAeD0E88790409A0e4";
|
|
1440
|
+
var semaphoreVerifierAbi = [
|
|
1441
|
+
{
|
|
1442
|
+
inputs: [
|
|
1443
|
+
{
|
|
1444
|
+
internalType: "uint256[8]",
|
|
1445
|
+
name: "proof",
|
|
1446
|
+
type: "uint256[8]"
|
|
1447
|
+
}
|
|
1448
|
+
],
|
|
1449
|
+
name: "compressProof",
|
|
1450
|
+
outputs: [
|
|
1451
|
+
{
|
|
1452
|
+
internalType: "uint256[4]",
|
|
1453
|
+
name: "compressed",
|
|
1454
|
+
type: "uint256[4]"
|
|
1455
|
+
}
|
|
1456
|
+
],
|
|
1457
|
+
stateMutability: "view",
|
|
1458
|
+
type: "function"
|
|
1459
|
+
}
|
|
1460
|
+
];
|
|
1461
|
+
var compressAndPadProof = async (proof, rpcUrl) => {
|
|
1462
|
+
try {
|
|
1463
|
+
const publicClient = (0, import_viem2.createPublicClient)({
|
|
1464
|
+
chain: import_chains2.worldchain,
|
|
1465
|
+
transport: (0, import_viem2.http)(
|
|
1466
|
+
rpcUrl || "https://worldchain-mainnet.g.alchemy.com/public"
|
|
1467
|
+
)
|
|
1468
|
+
});
|
|
1469
|
+
const decodedProof = (0, import_viem2.decodeAbiParameters)(
|
|
1470
|
+
[{ type: "uint256[8]" }],
|
|
1471
|
+
proof
|
|
1472
|
+
)[0];
|
|
1473
|
+
const compressedProof = await publicClient.readContract({
|
|
1474
|
+
address: semaphoreVerifierAddress,
|
|
1475
|
+
abi: semaphoreVerifierAbi,
|
|
1476
|
+
functionName: "compressProof",
|
|
1477
|
+
args: [decodedProof]
|
|
1478
|
+
});
|
|
1479
|
+
const paddedProof = [...compressedProof, 0n, 0n, 0n, 0n];
|
|
1480
|
+
return (0, import_viem2.encodeAbiParameters)([{ type: "uint256[8]" }], [paddedProof]);
|
|
1481
|
+
} catch (e) {
|
|
1482
|
+
return proof;
|
|
1483
|
+
}
|
|
838
1484
|
};
|
|
839
1485
|
|
|
840
|
-
//
|
|
841
|
-
var
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
1486
|
+
// core/events.ts
|
|
1487
|
+
var EventManager = class {
|
|
1488
|
+
constructor() {
|
|
1489
|
+
this.listeners = {
|
|
1490
|
+
["miniapp-verify-action" /* MiniAppVerifyAction */]: () => {
|
|
1491
|
+
},
|
|
1492
|
+
["miniapp-payment" /* MiniAppPayment */]: () => {
|
|
1493
|
+
},
|
|
1494
|
+
["miniapp-wallet-auth" /* MiniAppWalletAuth */]: () => {
|
|
1495
|
+
},
|
|
1496
|
+
["miniapp-send-transaction" /* MiniAppSendTransaction */]: () => {
|
|
1497
|
+
},
|
|
1498
|
+
["miniapp-sign-message" /* MiniAppSignMessage */]: () => {
|
|
1499
|
+
},
|
|
1500
|
+
["miniapp-sign-typed-data" /* MiniAppSignTypedData */]: () => {
|
|
1501
|
+
},
|
|
1502
|
+
["miniapp-share-contacts" /* MiniAppShareContacts */]: () => {
|
|
1503
|
+
},
|
|
1504
|
+
["miniapp-request-permission" /* MiniAppRequestPermission */]: () => {
|
|
1505
|
+
},
|
|
1506
|
+
["miniapp-get-permissions" /* MiniAppGetPermissions */]: () => {
|
|
1507
|
+
},
|
|
1508
|
+
["miniapp-send-haptic-feedback" /* MiniAppSendHapticFeedback */]: () => {
|
|
1509
|
+
},
|
|
1510
|
+
["miniapp-share" /* MiniAppShare */]: () => {
|
|
1511
|
+
},
|
|
1512
|
+
["miniapp-microphone" /* MiniAppMicrophone */]: () => {
|
|
1513
|
+
},
|
|
1514
|
+
["miniapp-chat" /* MiniAppChat */]: () => {
|
|
1515
|
+
}
|
|
1516
|
+
};
|
|
1517
|
+
this.verifyActionProcessingOptionsQueue = [];
|
|
847
1518
|
}
|
|
848
|
-
|
|
849
|
-
|
|
1519
|
+
subscribe(event, handler) {
|
|
1520
|
+
this.listeners[event] = handler;
|
|
850
1521
|
}
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
};
|
|
854
|
-
var processPayload = (payload) => {
|
|
855
|
-
if (typeof payload === "boolean" || typeof payload === "string" || payload === null || payload === void 0) {
|
|
856
|
-
return payload;
|
|
1522
|
+
unsubscribe(event) {
|
|
1523
|
+
delete this.listeners[event];
|
|
857
1524
|
}
|
|
858
|
-
|
|
859
|
-
|
|
1525
|
+
setVerifyActionProcessingOptions(options) {
|
|
1526
|
+
this.verifyActionProcessingOptionsQueue.push({
|
|
1527
|
+
skip_proof_compression: Boolean(options?.skip_proof_compression ?? false)
|
|
1528
|
+
});
|
|
860
1529
|
}
|
|
861
|
-
|
|
862
|
-
|
|
1530
|
+
trigger(event, payload) {
|
|
1531
|
+
if (!this.listeners[event]) {
|
|
1532
|
+
console.error(
|
|
1533
|
+
`No handler for event ${event}, payload: ${JSON.stringify(payload)}`
|
|
1534
|
+
);
|
|
1535
|
+
return;
|
|
1536
|
+
}
|
|
1537
|
+
if (event === "miniapp-verify-action" /* MiniAppVerifyAction */) {
|
|
1538
|
+
const handler = this.listeners[event];
|
|
1539
|
+
const processingOptions = this.verifyActionProcessingOptionsQueue.shift() ?? {
|
|
1540
|
+
skip_proof_compression: false
|
|
1541
|
+
};
|
|
1542
|
+
this.processVerifyActionPayload(
|
|
1543
|
+
payload,
|
|
1544
|
+
handler,
|
|
1545
|
+
processingOptions
|
|
1546
|
+
);
|
|
1547
|
+
return;
|
|
1548
|
+
}
|
|
1549
|
+
this.listeners[event](payload);
|
|
863
1550
|
}
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
"Transaction value must be a valid hex string",
|
|
873
|
-
result.value
|
|
1551
|
+
async processVerifyActionPayload(payload, handler, processingOptions) {
|
|
1552
|
+
if (payload.status === "error" && payload.error_code === "user_rejected") {
|
|
1553
|
+
payload.error_code = import_idkit_core3.AppErrorCodes.VerificationRejected;
|
|
1554
|
+
}
|
|
1555
|
+
if (payload.status === "success" && !processingOptions.skip_proof_compression) {
|
|
1556
|
+
if ("verifications" in payload) {
|
|
1557
|
+
const orbVerification = payload.verifications.find(
|
|
1558
|
+
(v) => v.verification_level === import_idkit_core3.VerificationLevel.Orb
|
|
874
1559
|
);
|
|
875
|
-
|
|
876
|
-
|
|
1560
|
+
if (orbVerification) {
|
|
1561
|
+
orbVerification.proof = await this.compressProofSafely(
|
|
1562
|
+
orbVerification.proof,
|
|
1563
|
+
{
|
|
1564
|
+
mode: "multi",
|
|
1565
|
+
payloadVersion: payload.version,
|
|
1566
|
+
verificationsCount: payload.verifications.length,
|
|
1567
|
+
verificationLevel: orbVerification.verification_level
|
|
1568
|
+
}
|
|
1569
|
+
);
|
|
1570
|
+
}
|
|
1571
|
+
} else if (payload.verification_level === import_idkit_core3.VerificationLevel.Orb) {
|
|
1572
|
+
payload.proof = await this.compressProofSafely(
|
|
1573
|
+
payload.proof,
|
|
1574
|
+
{
|
|
1575
|
+
mode: "single",
|
|
1576
|
+
payloadVersion: payload.version,
|
|
1577
|
+
verificationLevel: payload.verification_level
|
|
1578
|
+
}
|
|
877
1579
|
);
|
|
878
1580
|
}
|
|
879
1581
|
}
|
|
880
|
-
|
|
881
|
-
if (Object.prototype.hasOwnProperty.call(result, key)) {
|
|
882
|
-
result[key] = processPayload(result[key]);
|
|
883
|
-
}
|
|
884
|
-
}
|
|
885
|
-
return result;
|
|
1582
|
+
handler(payload);
|
|
886
1583
|
}
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
1584
|
+
async compressProofSafely(proof, context) {
|
|
1585
|
+
try {
|
|
1586
|
+
return await compressAndPadProof(proof);
|
|
1587
|
+
} catch (error) {
|
|
1588
|
+
console.error(
|
|
1589
|
+
"Failed to compress verification proof. Delivering payload with uncompressed proof.",
|
|
1590
|
+
{
|
|
1591
|
+
...context,
|
|
1592
|
+
error
|
|
1593
|
+
}
|
|
1594
|
+
);
|
|
1595
|
+
return proof;
|
|
1596
|
+
}
|
|
900
1597
|
}
|
|
901
|
-
return payload;
|
|
902
1598
|
};
|
|
903
1599
|
|
|
904
1600
|
// helpers/usernames/index.ts
|
|
@@ -916,29 +1612,6 @@ var getUserProfile = async (address) => {
|
|
|
916
1612
|
return usernames?.[0] ?? { username: null, profile_picture_url: null };
|
|
917
1613
|
};
|
|
918
1614
|
|
|
919
|
-
// types/commands.ts
|
|
920
|
-
var Command = /* @__PURE__ */ ((Command2) => {
|
|
921
|
-
Command2["Verify"] = "verify";
|
|
922
|
-
Command2["Pay"] = "pay";
|
|
923
|
-
Command2["WalletAuth"] = "wallet-auth";
|
|
924
|
-
Command2["SendTransaction"] = "send-transaction";
|
|
925
|
-
Command2["SignMessage"] = "sign-message";
|
|
926
|
-
Command2["SignTypedData"] = "sign-typed-data";
|
|
927
|
-
Command2["ShareContacts"] = "share-contacts";
|
|
928
|
-
Command2["RequestPermission"] = "request-permission";
|
|
929
|
-
Command2["GetPermissions"] = "get-permissions";
|
|
930
|
-
Command2["SendHapticFeedback"] = "send-haptic-feedback";
|
|
931
|
-
Command2["Share"] = "share";
|
|
932
|
-
Command2["Chat"] = "chat";
|
|
933
|
-
return Command2;
|
|
934
|
-
})(Command || {});
|
|
935
|
-
var Permission = /* @__PURE__ */ ((Permission2) => {
|
|
936
|
-
Permission2["Notifications"] = "notifications";
|
|
937
|
-
Permission2["Contacts"] = "contacts";
|
|
938
|
-
Permission2["Microphone"] = "microphone";
|
|
939
|
-
return Permission2;
|
|
940
|
-
})(Permission || {});
|
|
941
|
-
|
|
942
1615
|
// types/init.ts
|
|
943
1616
|
var MiniAppLaunchLocation = /* @__PURE__ */ ((MiniAppLaunchLocation3) => {
|
|
944
1617
|
MiniAppLaunchLocation3["Chat"] = "chat";
|
|
@@ -965,733 +1638,366 @@ var mapWorldAppLaunchLocation = (location) => {
|
|
|
965
1638
|
return WORLD_APP_LAUNCH_LOCATION_MAP[normalizedLocation] ?? null;
|
|
966
1639
|
};
|
|
967
1640
|
|
|
968
|
-
//
|
|
969
|
-
var
|
|
970
|
-
|
|
1641
|
+
// core/state.ts
|
|
1642
|
+
var MiniKitState = class {
|
|
1643
|
+
constructor() {
|
|
1644
|
+
this.appId = null;
|
|
1645
|
+
this.user = {};
|
|
1646
|
+
this.deviceProperties = {};
|
|
1647
|
+
this.location = null;
|
|
1648
|
+
this.isReady = false;
|
|
1649
|
+
}
|
|
1650
|
+
initFromWorldApp(worldApp) {
|
|
1651
|
+
if (!worldApp) return;
|
|
1652
|
+
this.user.optedIntoOptionalAnalytics = worldApp.is_optional_analytics;
|
|
1653
|
+
this.user.deviceOS = worldApp.device_os;
|
|
1654
|
+
this.user.worldAppVersion = worldApp.world_app_version;
|
|
1655
|
+
this.deviceProperties.safeAreaInsets = worldApp.safe_area_insets;
|
|
1656
|
+
this.deviceProperties.deviceOS = worldApp.device_os;
|
|
1657
|
+
this.deviceProperties.worldAppVersion = worldApp.world_app_version;
|
|
1658
|
+
this.location = mapWorldAppLaunchLocation(worldApp.location);
|
|
1659
|
+
}
|
|
1660
|
+
async updateUserFromWalletAuth(address) {
|
|
1661
|
+
this.user.walletAddress = address;
|
|
1662
|
+
try {
|
|
1663
|
+
const userProfile = await getUserProfile(address);
|
|
1664
|
+
this.user.username = userProfile.username;
|
|
1665
|
+
this.user.profilePictureUrl = userProfile.profile_picture_url;
|
|
1666
|
+
} catch (error) {
|
|
1667
|
+
console.error("Failed to fetch user profile:", error);
|
|
1668
|
+
}
|
|
1669
|
+
}
|
|
1670
|
+
async getUserByAddress(address) {
|
|
1671
|
+
const walletAddress = address ?? this.user.walletAddress;
|
|
1672
|
+
const userProfile = await getUserProfile(walletAddress);
|
|
1673
|
+
return {
|
|
1674
|
+
walletAddress,
|
|
1675
|
+
username: userProfile.username,
|
|
1676
|
+
profilePictureUrl: userProfile.profile_picture_url
|
|
1677
|
+
};
|
|
1678
|
+
}
|
|
1679
|
+
async getUserByUsername(username) {
|
|
1680
|
+
const res = await fetch(
|
|
1681
|
+
`https://usernames.worldcoin.org/api/v1/${username}`,
|
|
1682
|
+
{
|
|
1683
|
+
method: "GET",
|
|
1684
|
+
headers: {
|
|
1685
|
+
"Content-Type": "application/json"
|
|
1686
|
+
}
|
|
1687
|
+
}
|
|
1688
|
+
);
|
|
1689
|
+
const user = await res.json();
|
|
1690
|
+
return {
|
|
1691
|
+
walletAddress: user.address,
|
|
1692
|
+
username: user.username,
|
|
1693
|
+
profilePictureUrl: user.profile_picture_url
|
|
1694
|
+
};
|
|
1695
|
+
}
|
|
971
1696
|
};
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
1697
|
+
|
|
1698
|
+
// types/errors.ts
|
|
1699
|
+
var import_idkit_core4 = require("@worldcoin/idkit-core");
|
|
1700
|
+
var import_idkit_core5 = require("@worldcoin/idkit-core");
|
|
1701
|
+
var VerificationErrorMessage = {
|
|
1702
|
+
[import_idkit_core4.AppErrorCodes.VerificationRejected]: "You've cancelled the request in World App.",
|
|
1703
|
+
[import_idkit_core4.AppErrorCodes.MaxVerificationsReached]: "You have already verified the maximum number of times for this action.",
|
|
1704
|
+
[import_idkit_core4.AppErrorCodes.CredentialUnavailable]: "It seems you do not have the verification level required by this app.",
|
|
1705
|
+
[import_idkit_core4.AppErrorCodes.MalformedRequest]: "There was a problem with this request. Please try again or contact the app owner.",
|
|
1706
|
+
[import_idkit_core4.AppErrorCodes.InvalidNetwork]: "Invalid network. If you are the app owner, visit docs.worldcoin.org/test for details.",
|
|
1707
|
+
[import_idkit_core4.AppErrorCodes.InclusionProofFailed]: "There was an issue fetching your credential. Please try again.",
|
|
1708
|
+
[import_idkit_core4.AppErrorCodes.InclusionProofPending]: "Your identity is still being registered. Please wait a few minutes and try again.",
|
|
1709
|
+
[import_idkit_core4.AppErrorCodes.UnexpectedResponse]: "Unexpected response from your wallet. Please try again.",
|
|
1710
|
+
[import_idkit_core4.AppErrorCodes.FailedByHostApp]: "Verification failed by the app. Please contact the app owner for details.",
|
|
1711
|
+
[import_idkit_core4.AppErrorCodes.GenericError]: "Something unexpected went wrong. Please try again.",
|
|
1712
|
+
[import_idkit_core4.AppErrorCodes.ConnectionFailed]: "Connection to your wallet failed. Please try again."
|
|
1713
|
+
};
|
|
1714
|
+
var MiniKitInstallErrorCodes = /* @__PURE__ */ ((MiniKitInstallErrorCodes2) => {
|
|
1715
|
+
MiniKitInstallErrorCodes2["Unknown"] = "unknown";
|
|
1716
|
+
MiniKitInstallErrorCodes2["AlreadyInstalled"] = "already_installed";
|
|
1717
|
+
MiniKitInstallErrorCodes2["OutsideOfWorldApp"] = "outside_of_worldapp";
|
|
1718
|
+
MiniKitInstallErrorCodes2["NotOnClient"] = "not_on_client";
|
|
1719
|
+
MiniKitInstallErrorCodes2["AppOutOfDate"] = "app_out_of_date";
|
|
1720
|
+
return MiniKitInstallErrorCodes2;
|
|
1721
|
+
})(MiniKitInstallErrorCodes || {});
|
|
1722
|
+
var MiniKitInstallErrorMessage = {
|
|
1723
|
+
["unknown" /* Unknown */]: "Failed to install MiniKit.",
|
|
1724
|
+
["already_installed" /* AlreadyInstalled */]: "MiniKit is already installed.",
|
|
1725
|
+
["outside_of_worldapp" /* OutsideOfWorldApp */]: "MiniApp launched outside of WorldApp.",
|
|
1726
|
+
["not_on_client" /* NotOnClient */]: "Window object is not available.",
|
|
1727
|
+
["app_out_of_date" /* AppOutOfDate */]: "WorldApp is out of date. Please update the app."
|
|
1728
|
+
};
|
|
1729
|
+
|
|
1730
|
+
// helpers/microphone/index.ts
|
|
1731
|
+
var microphoneSetupDone = false;
|
|
1732
|
+
var setupMicrophone = () => {
|
|
1733
|
+
if (microphoneSetupDone) {
|
|
1734
|
+
return;
|
|
1735
|
+
}
|
|
1736
|
+
if (typeof navigator !== "undefined" && !navigator.mediaDevices?.getUserMedia)
|
|
1737
|
+
return;
|
|
1738
|
+
const originalStop = MediaStreamTrack.prototype.stop;
|
|
1739
|
+
MediaStreamTrack.prototype.stop = function() {
|
|
1740
|
+
originalStop.call(this);
|
|
1741
|
+
if (this.readyState === "ended") {
|
|
1742
|
+
setTimeout(() => this.dispatchEvent(new Event("ended")), 0);
|
|
1743
|
+
}
|
|
1744
|
+
};
|
|
1745
|
+
const realGUM = navigator.mediaDevices.getUserMedia.bind(
|
|
1746
|
+
navigator.mediaDevices
|
|
1747
|
+
);
|
|
1748
|
+
const live = /* @__PURE__ */ new Set();
|
|
1749
|
+
async function wrapped(constraints) {
|
|
1750
|
+
const stream = await realGUM(constraints);
|
|
1751
|
+
const hasAudioTrack = stream.getAudioTracks().length > 0;
|
|
1752
|
+
if (hasAudioTrack) {
|
|
1753
|
+
sendWebviewEvent({
|
|
1754
|
+
command: "microphone-stream-started",
|
|
1755
|
+
version: 1,
|
|
1756
|
+
payload: {
|
|
1757
|
+
streamId: stream.id
|
|
1758
|
+
}
|
|
1759
|
+
});
|
|
1760
|
+
live.add(stream);
|
|
1761
|
+
stream.getAudioTracks().forEach((t) => {
|
|
1762
|
+
t.addEventListener("ended", () => {
|
|
1763
|
+
const allAudioTracksEnded = stream.getAudioTracks().every((track) => track.readyState === "ended");
|
|
1764
|
+
if (allAudioTracksEnded) {
|
|
1765
|
+
sendWebviewEvent({
|
|
1766
|
+
command: "microphone-stream-ended",
|
|
1767
|
+
version: 1,
|
|
1768
|
+
payload: {
|
|
1769
|
+
streamId: stream.id
|
|
1770
|
+
}
|
|
1771
|
+
});
|
|
1772
|
+
live.delete(stream);
|
|
1773
|
+
}
|
|
1774
|
+
});
|
|
1775
|
+
});
|
|
1776
|
+
}
|
|
1777
|
+
return stream;
|
|
1778
|
+
}
|
|
1779
|
+
Object.defineProperty(navigator.mediaDevices, "getUserMedia", {
|
|
1780
|
+
value: wrapped,
|
|
1781
|
+
writable: false,
|
|
1782
|
+
configurable: false,
|
|
1783
|
+
enumerable: true
|
|
1784
|
+
});
|
|
1785
|
+
Object.freeze(navigator.mediaDevices);
|
|
1786
|
+
const stopAllMiniAppMicrophoneStreams = () => {
|
|
1787
|
+
live.forEach((s) => {
|
|
1788
|
+
const audioTracks = s.getAudioTracks();
|
|
1789
|
+
if (audioTracks.length > 0) {
|
|
1790
|
+
audioTracks.forEach((t) => {
|
|
1791
|
+
t.stop();
|
|
1792
|
+
});
|
|
1793
|
+
sendWebviewEvent({
|
|
1794
|
+
command: "microphone-stream-ended",
|
|
1795
|
+
version: 1,
|
|
1796
|
+
payload: {
|
|
1797
|
+
streamId: s.id
|
|
1798
|
+
}
|
|
1799
|
+
});
|
|
979
1800
|
}
|
|
980
1801
|
});
|
|
1802
|
+
live.clear();
|
|
1803
|
+
};
|
|
1804
|
+
MiniKit.subscribe("miniapp-microphone" /* MiniAppMicrophone */, (payload) => {
|
|
1805
|
+
if (payload.status === "error" && (payload.error_code === "mini_app_permission_not_enabled" /* MiniAppPermissionNotEnabled */ || payload.error_code === "world_app_permission_not_enabled" /* WorldAppPermissionNotEnabled */)) {
|
|
1806
|
+
console.log("stopping all microphone streams", payload);
|
|
1807
|
+
stopAllMiniAppMicrophoneStreams();
|
|
1808
|
+
}
|
|
1809
|
+
});
|
|
1810
|
+
window.__stopAllMiniAppMicrophoneStreams = stopAllMiniAppMicrophoneStreams;
|
|
1811
|
+
microphoneSetupDone = true;
|
|
1812
|
+
};
|
|
1813
|
+
|
|
1814
|
+
// minikit.ts
|
|
1815
|
+
var MINIKIT_VERSION = 1;
|
|
1816
|
+
var MINIKIT_MINOR_VERSION = 96;
|
|
1817
|
+
var _MiniKit = class _MiniKit {
|
|
1818
|
+
// ============================================================================
|
|
1819
|
+
// Public State Accessors
|
|
1820
|
+
// ============================================================================
|
|
1821
|
+
static get appId() {
|
|
1822
|
+
return this.stateManager.appId;
|
|
1823
|
+
}
|
|
1824
|
+
static set appId(value) {
|
|
1825
|
+
this.stateManager.appId = value;
|
|
1826
|
+
}
|
|
1827
|
+
static get user() {
|
|
1828
|
+
return this.stateManager.user;
|
|
1829
|
+
}
|
|
1830
|
+
static set user(value) {
|
|
1831
|
+
this.stateManager.user = value;
|
|
1832
|
+
}
|
|
1833
|
+
static get deviceProperties() {
|
|
1834
|
+
return this.stateManager.deviceProperties;
|
|
1835
|
+
}
|
|
1836
|
+
static get location() {
|
|
1837
|
+
return this.stateManager.location;
|
|
981
1838
|
}
|
|
1839
|
+
// ============================================================================
|
|
1840
|
+
// Event System
|
|
1841
|
+
// ============================================================================
|
|
982
1842
|
static subscribe(event, handler) {
|
|
983
1843
|
if (event === "miniapp-wallet-auth" /* MiniAppWalletAuth */) {
|
|
984
1844
|
const originalHandler = handler;
|
|
985
1845
|
const wrappedHandler = async (payload) => {
|
|
986
1846
|
if (payload.status === "success") {
|
|
987
|
-
|
|
988
|
-
try {
|
|
989
|
-
const user = await _MiniKit.getUserByAddress(payload.address);
|
|
990
|
-
_MiniKit.user = { ..._MiniKit.user, ...user };
|
|
991
|
-
} catch (error) {
|
|
992
|
-
console.error("Failed to fetch user profile:", error);
|
|
993
|
-
}
|
|
1847
|
+
await this.stateManager.updateUserFromWalletAuth(payload.address);
|
|
994
1848
|
}
|
|
995
1849
|
originalHandler(payload);
|
|
996
1850
|
};
|
|
997
|
-
this.
|
|
998
|
-
} else if (event === "miniapp-verify-action" /* MiniAppVerifyAction */) {
|
|
999
|
-
const originalHandler = handler;
|
|
1000
|
-
const wrappedHandler = (payload) => {
|
|
1001
|
-
if (payload.status === "error" && payload.error_code == "user_rejected") {
|
|
1002
|
-
payload.error_code = import_idkit_core2.AppErrorCodes.VerificationRejected;
|
|
1003
|
-
}
|
|
1004
|
-
if (payload.status === "success" && payload.verification_level === import_idkit_core3.VerificationLevel.Orb) {
|
|
1005
|
-
compressAndPadProof(payload.proof).then(
|
|
1006
|
-
(compressedProof) => {
|
|
1007
|
-
payload.proof = compressedProof;
|
|
1008
|
-
originalHandler(payload);
|
|
1009
|
-
}
|
|
1010
|
-
);
|
|
1011
|
-
} else {
|
|
1012
|
-
originalHandler(payload);
|
|
1013
|
-
}
|
|
1014
|
-
};
|
|
1015
|
-
this.listeners[event] = wrappedHandler;
|
|
1851
|
+
this.eventManager.subscribe(event, wrappedHandler);
|
|
1016
1852
|
} else {
|
|
1017
|
-
this.
|
|
1853
|
+
this.eventManager.subscribe(event, handler);
|
|
1018
1854
|
}
|
|
1019
1855
|
}
|
|
1020
1856
|
static unsubscribe(event) {
|
|
1021
|
-
|
|
1857
|
+
this.eventManager.unsubscribe(event);
|
|
1022
1858
|
}
|
|
1023
1859
|
static trigger(event, payload) {
|
|
1024
|
-
|
|
1025
|
-
console.error(
|
|
1026
|
-
`No handler for event ${event}, payload: ${JSON.stringify(payload)}`
|
|
1027
|
-
);
|
|
1028
|
-
return;
|
|
1029
|
-
}
|
|
1030
|
-
this.listeners[event](payload);
|
|
1031
|
-
}
|
|
1032
|
-
static async awaitCommand(event, command, executor) {
|
|
1033
|
-
return new Promise((resolve) => {
|
|
1034
|
-
let commandPayload = null;
|
|
1035
|
-
const handleAndUnsubscribe = (payload) => {
|
|
1036
|
-
this.unsubscribe(event);
|
|
1037
|
-
resolve({ commandPayload, finalPayload: payload });
|
|
1038
|
-
};
|
|
1039
|
-
this.subscribe(event, handleAndUnsubscribe);
|
|
1040
|
-
commandPayload = executor();
|
|
1041
|
-
});
|
|
1042
|
-
}
|
|
1043
|
-
static commandsValid(worldAppSupportedCommands) {
|
|
1044
|
-
let allCommandsValid = true;
|
|
1045
|
-
Object.entries(this.miniKitCommandVersion).forEach(
|
|
1046
|
-
([minikitCommandName, version]) => {
|
|
1047
|
-
const commandInput = worldAppSupportedCommands.find(
|
|
1048
|
-
(command) => command.name === minikitCommandName
|
|
1049
|
-
);
|
|
1050
|
-
let isCommandValid = false;
|
|
1051
|
-
if (!commandInput) {
|
|
1052
|
-
console.warn(
|
|
1053
|
-
`Command ${minikitCommandName} is not supported by the app. Try updating the app version`
|
|
1054
|
-
);
|
|
1055
|
-
} else {
|
|
1056
|
-
if (commandInput.supported_versions.includes(version)) {
|
|
1057
|
-
_MiniKit.isCommandAvailable[minikitCommandName] = true;
|
|
1058
|
-
isCommandValid = true;
|
|
1059
|
-
} else {
|
|
1060
|
-
isCommandValid = true;
|
|
1061
|
-
console.warn(
|
|
1062
|
-
`Command ${minikitCommandName} 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.`
|
|
1063
|
-
);
|
|
1064
|
-
_MiniKit.isCommandAvailable[minikitCommandName] = isCommandValid;
|
|
1065
|
-
}
|
|
1066
|
-
}
|
|
1067
|
-
if (!isCommandValid) {
|
|
1068
|
-
allCommandsValid = false;
|
|
1069
|
-
}
|
|
1070
|
-
}
|
|
1071
|
-
);
|
|
1072
|
-
return allCommandsValid;
|
|
1073
|
-
}
|
|
1074
|
-
static install(appId) {
|
|
1075
|
-
if (typeof window === "undefined" || Boolean(window.MiniKit)) {
|
|
1076
|
-
return {
|
|
1077
|
-
success: false,
|
|
1078
|
-
errorCode: "already_installed" /* AlreadyInstalled */,
|
|
1079
|
-
errorMessage: MiniKitInstallErrorMessage["already_installed" /* AlreadyInstalled */]
|
|
1080
|
-
};
|
|
1081
|
-
}
|
|
1082
|
-
if (!appId) {
|
|
1083
|
-
console.warn("App ID not provided during install");
|
|
1084
|
-
} else {
|
|
1085
|
-
_MiniKit.appId = appId;
|
|
1086
|
-
}
|
|
1087
|
-
if (!window.WorldApp) {
|
|
1088
|
-
return {
|
|
1089
|
-
success: false,
|
|
1090
|
-
errorCode: "outside_of_worldapp" /* OutsideOfWorldApp */,
|
|
1091
|
-
errorMessage: MiniKitInstallErrorMessage["outside_of_worldapp" /* OutsideOfWorldApp */]
|
|
1092
|
-
};
|
|
1093
|
-
}
|
|
1094
|
-
_MiniKit.user.optedIntoOptionalAnalytics = window.WorldApp.is_optional_analytics;
|
|
1095
|
-
_MiniKit.user.deviceOS = window.WorldApp.device_os;
|
|
1096
|
-
_MiniKit.user.worldAppVersion = window.WorldApp.world_app_version;
|
|
1097
|
-
_MiniKit.deviceProperties.safeAreaInsets = window.WorldApp.safe_area_insets;
|
|
1098
|
-
_MiniKit.deviceProperties.deviceOS = window.WorldApp.device_os;
|
|
1099
|
-
_MiniKit.deviceProperties.worldAppVersion = window.WorldApp.world_app_version;
|
|
1100
|
-
_MiniKit.location = mapWorldAppLaunchLocation(window.WorldApp.location);
|
|
1101
|
-
try {
|
|
1102
|
-
window.MiniKit = _MiniKit;
|
|
1103
|
-
this.sendInit();
|
|
1104
|
-
} catch (error) {
|
|
1105
|
-
console.error(
|
|
1106
|
-
MiniKitInstallErrorMessage["unknown" /* Unknown */],
|
|
1107
|
-
error
|
|
1108
|
-
);
|
|
1109
|
-
return {
|
|
1110
|
-
success: false,
|
|
1111
|
-
errorCode: "unknown" /* Unknown */,
|
|
1112
|
-
errorMessage: MiniKitInstallErrorMessage["unknown" /* Unknown */]
|
|
1113
|
-
};
|
|
1114
|
-
}
|
|
1115
|
-
_MiniKit.isReady = true;
|
|
1116
|
-
setupMicrophone();
|
|
1117
|
-
if (!this.commandsValid(window.WorldApp.supported_commands)) {
|
|
1118
|
-
return {
|
|
1119
|
-
success: false,
|
|
1120
|
-
errorCode: "app_out_of_date" /* AppOutOfDate */,
|
|
1121
|
-
errorMessage: MiniKitInstallErrorMessage["app_out_of_date" /* AppOutOfDate */]
|
|
1122
|
-
};
|
|
1123
|
-
}
|
|
1124
|
-
return { success: true };
|
|
1125
|
-
}
|
|
1126
|
-
static isInstalled(debug) {
|
|
1127
|
-
const isInstalled = _MiniKit.isReady && Boolean(window.MiniKit);
|
|
1128
|
-
if (!isInstalled)
|
|
1129
|
-
console.error(
|
|
1130
|
-
"MiniKit is not installed. Make sure you're running the application inside of World App"
|
|
1131
|
-
);
|
|
1132
|
-
if (debug && isInstalled) console.log("MiniKit is alive!");
|
|
1133
|
-
return isInstalled;
|
|
1134
|
-
}
|
|
1135
|
-
};
|
|
1136
|
-
_MiniKit.MINIKIT_VERSION = 1;
|
|
1137
|
-
_MiniKit.MINIKIT_MINOR_VERSION = 96;
|
|
1138
|
-
_MiniKit.miniKitCommandVersion = {
|
|
1139
|
-
["verify" /* Verify */]: 1,
|
|
1140
|
-
["pay" /* Pay */]: 1,
|
|
1141
|
-
["wallet-auth" /* WalletAuth */]: 2,
|
|
1142
|
-
["send-transaction" /* SendTransaction */]: 1,
|
|
1143
|
-
["sign-message" /* SignMessage */]: 1,
|
|
1144
|
-
["sign-typed-data" /* SignTypedData */]: 1,
|
|
1145
|
-
["share-contacts" /* ShareContacts */]: 1,
|
|
1146
|
-
["request-permission" /* RequestPermission */]: 1,
|
|
1147
|
-
["get-permissions" /* GetPermissions */]: 1,
|
|
1148
|
-
["send-haptic-feedback" /* SendHapticFeedback */]: 1,
|
|
1149
|
-
["share" /* Share */]: 1,
|
|
1150
|
-
["chat" /* Chat */]: 1
|
|
1151
|
-
};
|
|
1152
|
-
_MiniKit.isCommandAvailable = {
|
|
1153
|
-
["verify" /* Verify */]: false,
|
|
1154
|
-
["pay" /* Pay */]: false,
|
|
1155
|
-
["wallet-auth" /* WalletAuth */]: false,
|
|
1156
|
-
["send-transaction" /* SendTransaction */]: false,
|
|
1157
|
-
["sign-message" /* SignMessage */]: false,
|
|
1158
|
-
["sign-typed-data" /* SignTypedData */]: false,
|
|
1159
|
-
["share-contacts" /* ShareContacts */]: false,
|
|
1160
|
-
["request-permission" /* RequestPermission */]: false,
|
|
1161
|
-
["get-permissions" /* GetPermissions */]: false,
|
|
1162
|
-
["send-haptic-feedback" /* SendHapticFeedback */]: false,
|
|
1163
|
-
["share" /* Share */]: false,
|
|
1164
|
-
["chat" /* Chat */]: false
|
|
1165
|
-
};
|
|
1166
|
-
_MiniKit.listeners = {
|
|
1167
|
-
["miniapp-verify-action" /* MiniAppVerifyAction */]: () => {
|
|
1168
|
-
},
|
|
1169
|
-
["miniapp-payment" /* MiniAppPayment */]: () => {
|
|
1170
|
-
},
|
|
1171
|
-
["miniapp-wallet-auth" /* MiniAppWalletAuth */]: () => {
|
|
1172
|
-
},
|
|
1173
|
-
["miniapp-send-transaction" /* MiniAppSendTransaction */]: () => {
|
|
1174
|
-
},
|
|
1175
|
-
["miniapp-sign-message" /* MiniAppSignMessage */]: () => {
|
|
1176
|
-
},
|
|
1177
|
-
["miniapp-sign-typed-data" /* MiniAppSignTypedData */]: () => {
|
|
1178
|
-
},
|
|
1179
|
-
["miniapp-share-contacts" /* MiniAppShareContacts */]: () => {
|
|
1180
|
-
},
|
|
1181
|
-
["miniapp-request-permission" /* MiniAppRequestPermission */]: () => {
|
|
1182
|
-
},
|
|
1183
|
-
["miniapp-get-permissions" /* MiniAppGetPermissions */]: () => {
|
|
1184
|
-
},
|
|
1185
|
-
["miniapp-send-haptic-feedback" /* MiniAppSendHapticFeedback */]: () => {
|
|
1186
|
-
},
|
|
1187
|
-
["miniapp-share" /* MiniAppShare */]: () => {
|
|
1188
|
-
},
|
|
1189
|
-
["miniapp-microphone" /* MiniAppMicrophone */]: () => {
|
|
1190
|
-
},
|
|
1191
|
-
["miniapp-chat" /* MiniAppChat */]: () => {
|
|
1860
|
+
this.eventManager.trigger(event, payload);
|
|
1192
1861
|
}
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
);
|
|
1203
|
-
return {
|
|
1204
|
-
walletAddress: address ?? _MiniKit.user.walletAddress,
|
|
1205
|
-
username: userProfile.username,
|
|
1206
|
-
profilePictureUrl: userProfile.profile_picture_url
|
|
1207
|
-
};
|
|
1208
|
-
};
|
|
1209
|
-
_MiniKit.getUserByUsername = async (username) => {
|
|
1210
|
-
const res = await fetch(
|
|
1211
|
-
`https://usernames.worldcoin.org/api/v1/${username}`,
|
|
1212
|
-
{
|
|
1213
|
-
method: "GET",
|
|
1214
|
-
headers: {
|
|
1215
|
-
"Content-Type": "application/json"
|
|
1862
|
+
// ============================================================================
|
|
1863
|
+
// Installation
|
|
1864
|
+
// ============================================================================
|
|
1865
|
+
static sendInit() {
|
|
1866
|
+
sendWebviewEvent({
|
|
1867
|
+
command: "init",
|
|
1868
|
+
payload: {
|
|
1869
|
+
version: MINIKIT_VERSION,
|
|
1870
|
+
minorVersion: MINIKIT_MINOR_VERSION
|
|
1216
1871
|
}
|
|
1217
|
-
}
|
|
1218
|
-
);
|
|
1219
|
-
const user = await res.json();
|
|
1220
|
-
return {
|
|
1221
|
-
walletAddress: user.address,
|
|
1222
|
-
username: user.username,
|
|
1223
|
-
profilePictureUrl: user.profile_picture_url
|
|
1224
|
-
};
|
|
1225
|
-
};
|
|
1226
|
-
// This is a helper function for developers to generate MiniApp URLs
|
|
1227
|
-
_MiniKit.getMiniAppUrl = (appId, path) => {
|
|
1228
|
-
const baseUrl = new URL("https://world.org/mini-app");
|
|
1229
|
-
baseUrl.searchParams.append("app_id", appId);
|
|
1230
|
-
if (path) {
|
|
1231
|
-
const fullPath = path.startsWith("/") ? path : `/${path}`;
|
|
1232
|
-
baseUrl.searchParams.append("path", encodeURIComponent(fullPath));
|
|
1233
|
-
}
|
|
1234
|
-
return baseUrl.toString();
|
|
1235
|
-
};
|
|
1236
|
-
// Opens the profile card for a given username or wallet address
|
|
1237
|
-
_MiniKit.showProfileCard = (username, walletAddress) => {
|
|
1238
|
-
if (!username && !walletAddress) {
|
|
1239
|
-
console.error(
|
|
1240
|
-
"Either username or walletAddress must be provided to show profile card"
|
|
1241
|
-
);
|
|
1242
|
-
return;
|
|
1243
|
-
}
|
|
1244
|
-
if (username) {
|
|
1245
|
-
window.open(
|
|
1246
|
-
`worldapp://profile?username=${encodeURIComponent(username)}`
|
|
1247
|
-
);
|
|
1248
|
-
return;
|
|
1249
|
-
} else {
|
|
1250
|
-
window.open(
|
|
1251
|
-
`worldapp://profile?address=${encodeURIComponent(walletAddress || "")}`
|
|
1252
|
-
);
|
|
1253
|
-
}
|
|
1254
|
-
};
|
|
1255
|
-
// Simply re-exporting the existing function
|
|
1256
|
-
_MiniKit.getUserInfo = _MiniKit.getUserByAddress;
|
|
1257
|
-
_MiniKit.commands = {
|
|
1258
|
-
verify: (payload) => {
|
|
1259
|
-
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["verify" /* Verify */]) {
|
|
1260
|
-
console.error(
|
|
1261
|
-
"'verify' command is unavailable. Check MiniKit.install() or update the app version"
|
|
1262
|
-
);
|
|
1263
|
-
return null;
|
|
1264
|
-
}
|
|
1265
|
-
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
1266
|
-
const eventPayload = {
|
|
1267
|
-
action: (0, import_hashing.encodeAction)(payload.action),
|
|
1268
|
-
signal: (0, import_hashing.generateSignal)(payload.signal).digest,
|
|
1269
|
-
verification_level: payload.verification_level || import_idkit_core3.VerificationLevel.Orb,
|
|
1270
|
-
timestamp
|
|
1271
|
-
};
|
|
1272
|
-
sendMiniKitEvent({
|
|
1273
|
-
command: "verify" /* Verify */,
|
|
1274
|
-
version: _MiniKit.miniKitCommandVersion["verify" /* Verify */],
|
|
1275
|
-
payload: eventPayload
|
|
1276
|
-
});
|
|
1277
|
-
return eventPayload;
|
|
1278
|
-
},
|
|
1279
|
-
pay: (payload) => {
|
|
1280
|
-
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["pay" /* Pay */]) {
|
|
1281
|
-
console.error(
|
|
1282
|
-
"'pay' command is unavailable. Check MiniKit.install() or update the app version"
|
|
1283
|
-
);
|
|
1284
|
-
return null;
|
|
1285
|
-
}
|
|
1286
|
-
if (!validatePaymentPayload(payload)) {
|
|
1287
|
-
return null;
|
|
1288
|
-
}
|
|
1289
|
-
const eventPayload = {
|
|
1290
|
-
...payload,
|
|
1291
|
-
network: "worldchain" /* WorldChain */
|
|
1292
|
-
};
|
|
1293
|
-
sendMiniKitEvent({
|
|
1294
|
-
command: "pay" /* Pay */,
|
|
1295
|
-
version: _MiniKit.miniKitCommandVersion["pay" /* Pay */],
|
|
1296
|
-
payload: eventPayload
|
|
1297
|
-
});
|
|
1298
|
-
return eventPayload;
|
|
1299
|
-
},
|
|
1300
|
-
walletAuth: (payload) => {
|
|
1301
|
-
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["wallet-auth" /* WalletAuth */]) {
|
|
1302
|
-
console.error(
|
|
1303
|
-
"'walletAuth' command is unavailable. Check MiniKit.install() or update the app version"
|
|
1304
|
-
);
|
|
1305
|
-
return null;
|
|
1306
|
-
}
|
|
1307
|
-
const validationResult = validateWalletAuthCommandInput(payload);
|
|
1308
|
-
if (!validationResult.valid) {
|
|
1309
|
-
console.error(
|
|
1310
|
-
"Failed to validate wallet auth input:\n\n -->",
|
|
1311
|
-
validationResult.message
|
|
1312
|
-
);
|
|
1313
|
-
return null;
|
|
1314
|
-
}
|
|
1315
|
-
let protocol = null;
|
|
1316
|
-
try {
|
|
1317
|
-
const currentUrl = new URL(window.location.href);
|
|
1318
|
-
protocol = currentUrl.protocol.split(":")[0];
|
|
1319
|
-
} catch (error) {
|
|
1320
|
-
console.error("Failed to get current URL", error);
|
|
1321
|
-
return null;
|
|
1322
|
-
}
|
|
1323
|
-
const siweMessage = generateSiweMessage({
|
|
1324
|
-
scheme: protocol,
|
|
1325
|
-
domain: window.location.host,
|
|
1326
|
-
statement: payload.statement ?? void 0,
|
|
1327
|
-
uri: window.location.href,
|
|
1328
|
-
version: "1",
|
|
1329
|
-
chain_id: 480,
|
|
1330
|
-
nonce: payload.nonce,
|
|
1331
|
-
issued_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1332
|
-
expiration_time: payload.expirationTime?.toISOString() ?? void 0,
|
|
1333
|
-
not_before: payload.notBefore?.toISOString() ?? void 0,
|
|
1334
|
-
request_id: payload.requestId ?? void 0
|
|
1335
|
-
});
|
|
1336
|
-
const walletAuthPayload = { siweMessage };
|
|
1337
|
-
const walletAuthVersion = _MiniKit.user.worldAppVersion && _MiniKit.user.worldAppVersion > 2087900 ? _MiniKit.miniKitCommandVersion["wallet-auth" /* WalletAuth */] : 1;
|
|
1338
|
-
sendMiniKitEvent({
|
|
1339
|
-
command: "wallet-auth" /* WalletAuth */,
|
|
1340
|
-
version: walletAuthVersion,
|
|
1341
|
-
payload: walletAuthPayload
|
|
1342
|
-
});
|
|
1343
|
-
return walletAuthPayload;
|
|
1344
|
-
},
|
|
1345
|
-
sendTransaction: (payload) => {
|
|
1346
|
-
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["send-transaction" /* SendTransaction */]) {
|
|
1347
|
-
console.error(
|
|
1348
|
-
"'sendTransaction' command is unavailable. Check MiniKit.install() or update the app version"
|
|
1349
|
-
);
|
|
1350
|
-
return null;
|
|
1351
|
-
}
|
|
1352
|
-
payload.formatPayload = payload.formatPayload !== false;
|
|
1353
|
-
const validatedPayload = validateSendTransactionPayload(payload);
|
|
1354
|
-
sendMiniKitEvent({
|
|
1355
|
-
command: "send-transaction" /* SendTransaction */,
|
|
1356
|
-
version: _MiniKit.miniKitCommandVersion["send-transaction" /* SendTransaction */],
|
|
1357
|
-
payload: validatedPayload
|
|
1358
|
-
});
|
|
1359
|
-
return validatedPayload;
|
|
1360
|
-
},
|
|
1361
|
-
signMessage: (payload) => {
|
|
1362
|
-
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["sign-message" /* SignMessage */]) {
|
|
1363
|
-
console.error(
|
|
1364
|
-
"'signMessage' command is unavailable. Check MiniKit.install() or update the app version"
|
|
1365
|
-
);
|
|
1366
|
-
return null;
|
|
1367
|
-
}
|
|
1368
|
-
sendMiniKitEvent({
|
|
1369
|
-
command: "sign-message" /* SignMessage */,
|
|
1370
|
-
version: _MiniKit.miniKitCommandVersion["sign-message" /* SignMessage */],
|
|
1371
|
-
payload
|
|
1372
1872
|
});
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
"
|
|
1379
|
-
|
|
1380
|
-
|
|
1873
|
+
}
|
|
1874
|
+
static install(appId) {
|
|
1875
|
+
if (typeof window === "undefined" || Boolean(window.MiniKit)) {
|
|
1876
|
+
return {
|
|
1877
|
+
success: false,
|
|
1878
|
+
errorCode: "already_installed" /* AlreadyInstalled */,
|
|
1879
|
+
errorMessage: MiniKitInstallErrorMessage["already_installed" /* AlreadyInstalled */]
|
|
1880
|
+
};
|
|
1381
1881
|
}
|
|
1382
|
-
if (!
|
|
1383
|
-
|
|
1882
|
+
if (!appId) {
|
|
1883
|
+
console.warn("App ID not provided during install");
|
|
1884
|
+
} else {
|
|
1885
|
+
this.stateManager.appId = appId;
|
|
1384
1886
|
}
|
|
1385
|
-
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
},
|
|
1392
|
-
shareContacts: (payload) => {
|
|
1393
|
-
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["share-contacts" /* ShareContacts */]) {
|
|
1394
|
-
console.error(
|
|
1395
|
-
"'shareContacts' command is unavailable. Check MiniKit.install() or update the app version"
|
|
1396
|
-
);
|
|
1397
|
-
return null;
|
|
1887
|
+
if (!window.WorldApp) {
|
|
1888
|
+
return {
|
|
1889
|
+
success: false,
|
|
1890
|
+
errorCode: "outside_of_worldapp" /* OutsideOfWorldApp */,
|
|
1891
|
+
errorMessage: MiniKitInstallErrorMessage["outside_of_worldapp" /* OutsideOfWorldApp */]
|
|
1892
|
+
};
|
|
1398
1893
|
}
|
|
1399
|
-
|
|
1400
|
-
|
|
1401
|
-
|
|
1402
|
-
|
|
1403
|
-
})
|
|
1404
|
-
return payload;
|
|
1405
|
-
},
|
|
1406
|
-
requestPermission: (payload) => {
|
|
1407
|
-
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["request-permission" /* RequestPermission */]) {
|
|
1894
|
+
this.stateManager.initFromWorldApp(window.WorldApp);
|
|
1895
|
+
try {
|
|
1896
|
+
window.MiniKit = _MiniKit;
|
|
1897
|
+
this.sendInit();
|
|
1898
|
+
} catch (error) {
|
|
1408
1899
|
console.error(
|
|
1409
|
-
"
|
|
1900
|
+
MiniKitInstallErrorMessage["unknown" /* Unknown */],
|
|
1901
|
+
error
|
|
1410
1902
|
);
|
|
1411
|
-
return
|
|
1903
|
+
return {
|
|
1904
|
+
success: false,
|
|
1905
|
+
errorCode: "unknown" /* Unknown */,
|
|
1906
|
+
errorMessage: MiniKitInstallErrorMessage["unknown" /* Unknown */]
|
|
1907
|
+
};
|
|
1412
1908
|
}
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["get-permissions" /* GetPermissions */]) {
|
|
1422
|
-
console.error(
|
|
1423
|
-
"'getPermissions' command is unavailable. Check MiniKit.install() or update the app version"
|
|
1424
|
-
);
|
|
1425
|
-
return null;
|
|
1909
|
+
this.stateManager.isReady = true;
|
|
1910
|
+
setupMicrophone();
|
|
1911
|
+
if (!validateCommands(window.WorldApp.supported_commands)) {
|
|
1912
|
+
return {
|
|
1913
|
+
success: false,
|
|
1914
|
+
errorCode: "app_out_of_date" /* AppOutOfDate */,
|
|
1915
|
+
errorMessage: MiniKitInstallErrorMessage["app_out_of_date" /* AppOutOfDate */]
|
|
1916
|
+
};
|
|
1426
1917
|
}
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1431
|
-
|
|
1432
|
-
return {
|
|
1433
|
-
status: "sent"
|
|
1434
|
-
};
|
|
1435
|
-
},
|
|
1436
|
-
sendHapticFeedback: (payload) => {
|
|
1437
|
-
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["send-haptic-feedback" /* SendHapticFeedback */]) {
|
|
1918
|
+
return { success: true };
|
|
1919
|
+
}
|
|
1920
|
+
static isInstalled(debug) {
|
|
1921
|
+
const isInstalled = this.stateManager.isReady && Boolean(window.MiniKit);
|
|
1922
|
+
if (!isInstalled) {
|
|
1438
1923
|
console.error(
|
|
1439
|
-
"
|
|
1924
|
+
"MiniKit is not installed. Make sure you're running the application inside of World App"
|
|
1440
1925
|
);
|
|
1441
|
-
return null;
|
|
1442
1926
|
}
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
version: _MiniKit.miniKitCommandVersion["send-haptic-feedback" /* SendHapticFeedback */],
|
|
1446
|
-
payload
|
|
1447
|
-
});
|
|
1448
|
-
return payload;
|
|
1449
|
-
},
|
|
1450
|
-
// We return share input here because the payload is formatted asynchronously
|
|
1451
|
-
share: (payload) => {
|
|
1452
|
-
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["share" /* Share */]) {
|
|
1453
|
-
console.error(
|
|
1454
|
-
"'share' command is unavailable. Check MiniKit.install() or update the app version"
|
|
1455
|
-
);
|
|
1456
|
-
return null;
|
|
1927
|
+
if (debug && isInstalled) {
|
|
1928
|
+
console.log("MiniKit is alive!");
|
|
1457
1929
|
}
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
}).catch((error) => {
|
|
1473
|
-
console.error("Failed to format share input", error);
|
|
1474
|
-
});
|
|
1475
|
-
_MiniKit.subscribe("miniapp-share" /* MiniAppShare */, (payload2) => {
|
|
1476
|
-
console.log("Share Response", payload2);
|
|
1477
|
-
});
|
|
1930
|
+
return isInstalled;
|
|
1931
|
+
}
|
|
1932
|
+
// ============================================================================
|
|
1933
|
+
// Commands
|
|
1934
|
+
// ============================================================================
|
|
1935
|
+
static getContext() {
|
|
1936
|
+
return {
|
|
1937
|
+
events: this.eventManager,
|
|
1938
|
+
state: this.stateManager
|
|
1939
|
+
};
|
|
1940
|
+
}
|
|
1941
|
+
static get commands() {
|
|
1942
|
+
if (!this.commandsInstance) {
|
|
1943
|
+
this.commandsInstance = createCommands(this.getContext());
|
|
1478
1944
|
}
|
|
1479
|
-
return
|
|
1480
|
-
}
|
|
1481
|
-
|
|
1482
|
-
if (
|
|
1483
|
-
|
|
1484
|
-
|
|
1945
|
+
return this.commandsInstance;
|
|
1946
|
+
}
|
|
1947
|
+
static get commandsAsync() {
|
|
1948
|
+
if (!this.asyncCommandsInstance) {
|
|
1949
|
+
this.asyncCommandsInstance = createAsyncCommands(
|
|
1950
|
+
this.getContext(),
|
|
1951
|
+
this.commands
|
|
1485
1952
|
);
|
|
1486
|
-
return null;
|
|
1487
1953
|
}
|
|
1488
|
-
|
|
1489
|
-
console.error("'chat' command requires a non-empty message");
|
|
1490
|
-
return null;
|
|
1491
|
-
}
|
|
1492
|
-
sendMiniKitEvent({
|
|
1493
|
-
command: "chat" /* Chat */,
|
|
1494
|
-
version: _MiniKit.miniKitCommandVersion["chat" /* Chat */],
|
|
1495
|
-
payload
|
|
1496
|
-
});
|
|
1497
|
-
return payload;
|
|
1954
|
+
return this.asyncCommandsInstance;
|
|
1498
1955
|
}
|
|
1499
1956
|
};
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
1504
|
-
|
|
1505
|
-
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
_MiniKit.
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
}
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
resolve(response);
|
|
1539
|
-
} catch (error) {
|
|
1540
|
-
reject(error);
|
|
1541
|
-
}
|
|
1542
|
-
});
|
|
1543
|
-
},
|
|
1544
|
-
walletAuth: async (payload) => {
|
|
1545
|
-
return new Promise(async (resolve, reject) => {
|
|
1546
|
-
try {
|
|
1547
|
-
const response = await _MiniKit.awaitCommand(
|
|
1548
|
-
"miniapp-wallet-auth" /* MiniAppWalletAuth */,
|
|
1549
|
-
"wallet-auth" /* WalletAuth */,
|
|
1550
|
-
() => _MiniKit.commands.walletAuth(payload)
|
|
1551
|
-
);
|
|
1552
|
-
return resolve(response);
|
|
1553
|
-
} catch (error) {
|
|
1554
|
-
reject(error);
|
|
1555
|
-
}
|
|
1556
|
-
});
|
|
1557
|
-
},
|
|
1558
|
-
sendTransaction: async (payload) => {
|
|
1559
|
-
return new Promise(async (resolve, reject) => {
|
|
1560
|
-
try {
|
|
1561
|
-
const response = await _MiniKit.awaitCommand(
|
|
1562
|
-
"miniapp-send-transaction" /* MiniAppSendTransaction */,
|
|
1563
|
-
"send-transaction" /* SendTransaction */,
|
|
1564
|
-
() => _MiniKit.commands.sendTransaction(payload)
|
|
1565
|
-
);
|
|
1566
|
-
return resolve(response);
|
|
1567
|
-
} catch (error) {
|
|
1568
|
-
reject(error);
|
|
1569
|
-
}
|
|
1570
|
-
});
|
|
1571
|
-
},
|
|
1572
|
-
signMessage: async (payload) => {
|
|
1573
|
-
return new Promise(async (resolve, reject) => {
|
|
1574
|
-
try {
|
|
1575
|
-
const response = await _MiniKit.awaitCommand(
|
|
1576
|
-
"miniapp-sign-message" /* MiniAppSignMessage */,
|
|
1577
|
-
"sign-message" /* SignMessage */,
|
|
1578
|
-
() => _MiniKit.commands.signMessage(payload)
|
|
1579
|
-
);
|
|
1580
|
-
return resolve(response);
|
|
1581
|
-
} catch (error) {
|
|
1582
|
-
reject(error);
|
|
1583
|
-
}
|
|
1584
|
-
});
|
|
1585
|
-
},
|
|
1586
|
-
signTypedData: async (payload) => {
|
|
1587
|
-
return new Promise(async (resolve, reject) => {
|
|
1588
|
-
try {
|
|
1589
|
-
const response = await _MiniKit.awaitCommand(
|
|
1590
|
-
"miniapp-sign-typed-data" /* MiniAppSignTypedData */,
|
|
1591
|
-
"sign-typed-data" /* SignTypedData */,
|
|
1592
|
-
() => _MiniKit.commands.signTypedData(payload)
|
|
1593
|
-
);
|
|
1594
|
-
return resolve(response);
|
|
1595
|
-
} catch (error) {
|
|
1596
|
-
reject(error);
|
|
1597
|
-
}
|
|
1598
|
-
});
|
|
1599
|
-
},
|
|
1600
|
-
shareContacts: async (payload) => {
|
|
1601
|
-
return new Promise(async (resolve, reject) => {
|
|
1602
|
-
try {
|
|
1603
|
-
const response = await _MiniKit.awaitCommand(
|
|
1604
|
-
"miniapp-share-contacts" /* MiniAppShareContacts */,
|
|
1605
|
-
"share-contacts" /* ShareContacts */,
|
|
1606
|
-
() => _MiniKit.commands.shareContacts(payload)
|
|
1607
|
-
);
|
|
1608
|
-
return resolve(response);
|
|
1609
|
-
} catch (error) {
|
|
1610
|
-
reject(error);
|
|
1611
|
-
}
|
|
1612
|
-
});
|
|
1613
|
-
},
|
|
1614
|
-
requestPermission: async (payload) => {
|
|
1615
|
-
return new Promise(async (resolve, reject) => {
|
|
1616
|
-
try {
|
|
1617
|
-
const response = await _MiniKit.awaitCommand(
|
|
1618
|
-
"miniapp-request-permission" /* MiniAppRequestPermission */,
|
|
1619
|
-
"request-permission" /* RequestPermission */,
|
|
1620
|
-
() => _MiniKit.commands.requestPermission(payload)
|
|
1621
|
-
);
|
|
1622
|
-
resolve(response);
|
|
1623
|
-
} catch (error) {
|
|
1624
|
-
reject(error);
|
|
1625
|
-
}
|
|
1626
|
-
});
|
|
1627
|
-
},
|
|
1628
|
-
getPermissions: async () => {
|
|
1629
|
-
return new Promise(async (resolve, reject) => {
|
|
1630
|
-
try {
|
|
1631
|
-
const response = await _MiniKit.awaitCommand(
|
|
1632
|
-
"miniapp-get-permissions" /* MiniAppGetPermissions */,
|
|
1633
|
-
"get-permissions" /* GetPermissions */,
|
|
1634
|
-
() => _MiniKit.commands.getPermissions()
|
|
1635
|
-
);
|
|
1636
|
-
resolve(response);
|
|
1637
|
-
} catch (error) {
|
|
1638
|
-
reject(error);
|
|
1639
|
-
}
|
|
1640
|
-
});
|
|
1641
|
-
},
|
|
1642
|
-
sendHapticFeedback: async (payload) => {
|
|
1643
|
-
return new Promise(async (resolve, reject) => {
|
|
1644
|
-
try {
|
|
1645
|
-
const response = await _MiniKit.awaitCommand(
|
|
1646
|
-
"miniapp-send-haptic-feedback" /* MiniAppSendHapticFeedback */,
|
|
1647
|
-
"send-haptic-feedback" /* SendHapticFeedback */,
|
|
1648
|
-
() => _MiniKit.commands.sendHapticFeedback(payload)
|
|
1649
|
-
);
|
|
1650
|
-
resolve(response);
|
|
1651
|
-
} catch (error) {
|
|
1652
|
-
reject(error);
|
|
1653
|
-
}
|
|
1654
|
-
});
|
|
1655
|
-
},
|
|
1656
|
-
share: async (payload) => {
|
|
1657
|
-
return new Promise(async (resolve, reject) => {
|
|
1658
|
-
try {
|
|
1659
|
-
const response = await _MiniKit.awaitCommand(
|
|
1660
|
-
"miniapp-share" /* MiniAppShare */,
|
|
1661
|
-
"share" /* Share */,
|
|
1662
|
-
() => _MiniKit.commands.share(payload)
|
|
1663
|
-
);
|
|
1664
|
-
resolve({
|
|
1665
|
-
commandPayload: response.commandPayload,
|
|
1666
|
-
finalPayload: response.finalPayload
|
|
1667
|
-
});
|
|
1668
|
-
} catch (error) {
|
|
1669
|
-
reject(error);
|
|
1670
|
-
}
|
|
1671
|
-
});
|
|
1672
|
-
},
|
|
1673
|
-
chat: async (payload) => {
|
|
1674
|
-
return new Promise(async (resolve, reject) => {
|
|
1675
|
-
try {
|
|
1676
|
-
const response = await _MiniKit.awaitCommand(
|
|
1677
|
-
"miniapp-chat" /* MiniAppChat */,
|
|
1678
|
-
"chat" /* Chat */,
|
|
1679
|
-
() => _MiniKit.commands.chat(payload)
|
|
1680
|
-
);
|
|
1681
|
-
resolve({
|
|
1682
|
-
commandPayload: response.commandPayload,
|
|
1683
|
-
finalPayload: response.finalPayload
|
|
1684
|
-
});
|
|
1685
|
-
} catch (error) {
|
|
1686
|
-
reject(error);
|
|
1687
|
-
}
|
|
1688
|
-
});
|
|
1957
|
+
_MiniKit.eventManager = new EventManager();
|
|
1958
|
+
_MiniKit.stateManager = new MiniKitState();
|
|
1959
|
+
_MiniKit.commandsInstance = null;
|
|
1960
|
+
_MiniKit.asyncCommandsInstance = null;
|
|
1961
|
+
// ============================================================================
|
|
1962
|
+
// Utility Methods
|
|
1963
|
+
// ============================================================================
|
|
1964
|
+
_MiniKit.getUserByAddress = async (address) => {
|
|
1965
|
+
return _MiniKit.stateManager.getUserByAddress(address);
|
|
1966
|
+
};
|
|
1967
|
+
_MiniKit.getUserByUsername = async (username) => {
|
|
1968
|
+
return _MiniKit.stateManager.getUserByUsername(username);
|
|
1969
|
+
};
|
|
1970
|
+
_MiniKit.getUserInfo = _MiniKit.getUserByAddress;
|
|
1971
|
+
_MiniKit.getMiniAppUrl = (appId, path) => {
|
|
1972
|
+
const baseUrl = new URL("https://world.org/mini-app");
|
|
1973
|
+
baseUrl.searchParams.append("app_id", appId);
|
|
1974
|
+
if (path) {
|
|
1975
|
+
const fullPath = path.startsWith("/") ? path : `/${path}`;
|
|
1976
|
+
baseUrl.searchParams.append("path", encodeURIComponent(fullPath));
|
|
1977
|
+
}
|
|
1978
|
+
return baseUrl.toString();
|
|
1979
|
+
};
|
|
1980
|
+
_MiniKit.showProfileCard = (username, walletAddress) => {
|
|
1981
|
+
if (!username && !walletAddress) {
|
|
1982
|
+
console.error(
|
|
1983
|
+
"Either username or walletAddress must be provided to show profile card"
|
|
1984
|
+
);
|
|
1985
|
+
return;
|
|
1986
|
+
}
|
|
1987
|
+
if (username) {
|
|
1988
|
+
window.open(
|
|
1989
|
+
`worldapp://profile?username=${encodeURIComponent(username)}`
|
|
1990
|
+
);
|
|
1991
|
+
} else {
|
|
1992
|
+
window.open(
|
|
1993
|
+
`worldapp://profile?address=${encodeURIComponent(walletAddress || "")}`
|
|
1994
|
+
);
|
|
1689
1995
|
}
|
|
1690
1996
|
};
|
|
1691
1997
|
var MiniKit = _MiniKit;
|
|
1692
1998
|
|
|
1693
1999
|
// index.ts
|
|
1694
|
-
var
|
|
2000
|
+
var import_idkit_core6 = require("@worldcoin/idkit-core");
|
|
1695
2001
|
var import_backend = require("@worldcoin/idkit-core/backend");
|
|
1696
2002
|
|
|
1697
2003
|
// helpers/address-book/index.ts
|
|
@@ -1747,13 +2053,12 @@ var getIsUserVerified = async (walletAddress, rpcUrl) => {
|
|
|
1747
2053
|
};
|
|
1748
2054
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1749
2055
|
0 && (module.exports = {
|
|
2056
|
+
COMMAND_VERSIONS,
|
|
1750
2057
|
ChatErrorCodes,
|
|
1751
2058
|
ChatErrorMessage,
|
|
1752
2059
|
Command,
|
|
1753
2060
|
GetPermissionsErrorCodes,
|
|
1754
2061
|
GetPermissionsErrorMessage,
|
|
1755
|
-
MicrophoneErrorCodes,
|
|
1756
|
-
MicrophoneErrorMessage,
|
|
1757
2062
|
MiniAppLaunchLocation,
|
|
1758
2063
|
MiniKit,
|
|
1759
2064
|
MiniKitInstallErrorCodes,
|
|
@@ -1761,7 +2066,6 @@ var getIsUserVerified = async (walletAddress, rpcUrl) => {
|
|
|
1761
2066
|
Network,
|
|
1762
2067
|
PaymentErrorCodes,
|
|
1763
2068
|
PaymentErrorMessage,
|
|
1764
|
-
PaymentValidationErrors,
|
|
1765
2069
|
Permission,
|
|
1766
2070
|
RequestPermissionErrorCodes,
|
|
1767
2071
|
RequestPermissionErrorMessage,
|
|
@@ -1781,14 +2085,43 @@ var getIsUserVerified = async (walletAddress, rpcUrl) => {
|
|
|
1781
2085
|
TokenDecimals,
|
|
1782
2086
|
Tokens,
|
|
1783
2087
|
VerificationErrorCodes,
|
|
1784
|
-
VerificationErrorMessage,
|
|
1785
2088
|
VerificationLevel,
|
|
1786
2089
|
WalletAuthErrorCodes,
|
|
1787
2090
|
WalletAuthErrorMessage,
|
|
2091
|
+
createAsyncCommands,
|
|
2092
|
+
createChatAsyncCommand,
|
|
2093
|
+
createChatCommand,
|
|
2094
|
+
createCommands,
|
|
2095
|
+
createGetPermissionsAsyncCommand,
|
|
2096
|
+
createGetPermissionsCommand,
|
|
2097
|
+
createPayAsyncCommand,
|
|
2098
|
+
createPayCommand,
|
|
2099
|
+
createRequestPermissionAsyncCommand,
|
|
2100
|
+
createRequestPermissionCommand,
|
|
2101
|
+
createSendHapticFeedbackAsyncCommand,
|
|
2102
|
+
createSendHapticFeedbackCommand,
|
|
2103
|
+
createSendTransactionAsyncCommand,
|
|
2104
|
+
createSendTransactionCommand,
|
|
2105
|
+
createShareAsyncCommand,
|
|
2106
|
+
createShareCommand,
|
|
2107
|
+
createShareContactsAsyncCommand,
|
|
2108
|
+
createShareContactsCommand,
|
|
2109
|
+
createSignMessageAsyncCommand,
|
|
2110
|
+
createSignMessageCommand,
|
|
2111
|
+
createSignTypedDataAsyncCommand,
|
|
2112
|
+
createSignTypedDataCommand,
|
|
2113
|
+
createVerifyAsyncCommand,
|
|
2114
|
+
createVerifyCommand,
|
|
2115
|
+
createWalletAuthAsyncCommand,
|
|
2116
|
+
createWalletAuthCommand,
|
|
1788
2117
|
getIsUserVerified,
|
|
2118
|
+
isCommandAvailable,
|
|
1789
2119
|
mapWorldAppLaunchLocation,
|
|
1790
2120
|
parseSiweMessage,
|
|
2121
|
+
sendMiniKitEvent,
|
|
2122
|
+
setCommandAvailable,
|
|
1791
2123
|
tokenToDecimals,
|
|
2124
|
+
validateCommands,
|
|
1792
2125
|
verifyCloudProof,
|
|
1793
2126
|
verifySiweMessage
|
|
1794
2127
|
});
|