@worldcoin/minikit-js 1.9.8 → 1.9.10
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-Q55KYUW6.js → chunk-XFGJKKI2.js} +1476 -1086
- package/build/index.cjs +1713 -1292
- package/build/index.d.cts +495 -486
- package/build/index.d.ts +495 -486
- package/build/index.js +71 -9
- package/build/minikit-provider.cjs +1174 -816
- package/build/minikit-provider.js +1 -1
- package/index.ts +12 -3
- package/package.json +5 -1
|
@@ -27,10 +27,6 @@ __export(minikit_provider_exports, {
|
|
|
27
27
|
module.exports = __toCommonJS(minikit_provider_exports);
|
|
28
28
|
var import_react = require("react");
|
|
29
29
|
|
|
30
|
-
// minikit.ts
|
|
31
|
-
var import_idkit_core3 = require("@worldcoin/idkit-core");
|
|
32
|
-
var import_hashing = require("@worldcoin/idkit-core/hashing");
|
|
33
|
-
|
|
34
30
|
// helpers/send-webview-event.ts
|
|
35
31
|
var sendWebviewEvent = (payload) => {
|
|
36
32
|
if (window.webkit) {
|
|
@@ -40,113 +36,152 @@ var sendWebviewEvent = (payload) => {
|
|
|
40
36
|
}
|
|
41
37
|
};
|
|
42
38
|
|
|
43
|
-
// types
|
|
44
|
-
var
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
[
|
|
48
|
-
[
|
|
49
|
-
[
|
|
50
|
-
[
|
|
51
|
-
[
|
|
52
|
-
[
|
|
53
|
-
[
|
|
54
|
-
[
|
|
55
|
-
[
|
|
56
|
-
[
|
|
57
|
-
[import_idkit_core.AppErrorCodes.ConnectionFailed]: "Connection to your wallet failed. Please try again."
|
|
39
|
+
// commands/types.ts
|
|
40
|
+
var COMMAND_VERSIONS = {
|
|
41
|
+
["verify" /* Verify */]: 1,
|
|
42
|
+
["pay" /* Pay */]: 1,
|
|
43
|
+
["wallet-auth" /* WalletAuth */]: 2,
|
|
44
|
+
["send-transaction" /* SendTransaction */]: 1,
|
|
45
|
+
["sign-message" /* SignMessage */]: 1,
|
|
46
|
+
["sign-typed-data" /* SignTypedData */]: 1,
|
|
47
|
+
["share-contacts" /* ShareContacts */]: 1,
|
|
48
|
+
["request-permission" /* RequestPermission */]: 1,
|
|
49
|
+
["get-permissions" /* GetPermissions */]: 1,
|
|
50
|
+
["send-haptic-feedback" /* SendHapticFeedback */]: 1,
|
|
51
|
+
["share" /* Share */]: 1,
|
|
52
|
+
["chat" /* Chat */]: 1
|
|
58
53
|
};
|
|
59
|
-
var
|
|
60
|
-
["
|
|
61
|
-
["
|
|
62
|
-
["
|
|
63
|
-
["
|
|
64
|
-
["
|
|
54
|
+
var commandAvailability = {
|
|
55
|
+
["verify" /* Verify */]: false,
|
|
56
|
+
["pay" /* Pay */]: false,
|
|
57
|
+
["wallet-auth" /* WalletAuth */]: false,
|
|
58
|
+
["send-transaction" /* SendTransaction */]: false,
|
|
59
|
+
["sign-message" /* SignMessage */]: false,
|
|
60
|
+
["sign-typed-data" /* SignTypedData */]: false,
|
|
61
|
+
["share-contacts" /* ShareContacts */]: false,
|
|
62
|
+
["request-permission" /* RequestPermission */]: false,
|
|
63
|
+
["get-permissions" /* GetPermissions */]: false,
|
|
64
|
+
["send-haptic-feedback" /* SendHapticFeedback */]: false,
|
|
65
|
+
["share" /* Share */]: false,
|
|
66
|
+
["chat" /* Chat */]: false
|
|
65
67
|
};
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
68
|
+
function isCommandAvailable(command) {
|
|
69
|
+
return commandAvailability[command];
|
|
70
|
+
}
|
|
71
|
+
function setCommandAvailable(command, available) {
|
|
72
|
+
commandAvailability[command] = available;
|
|
73
|
+
}
|
|
74
|
+
function validateCommands(worldAppSupportedCommands) {
|
|
75
|
+
let allCommandsValid = true;
|
|
76
|
+
Object.entries(COMMAND_VERSIONS).forEach(([commandName, version]) => {
|
|
77
|
+
const commandInput = worldAppSupportedCommands.find(
|
|
78
|
+
(cmd) => cmd.name === commandName
|
|
79
|
+
);
|
|
80
|
+
let isCommandValid = false;
|
|
81
|
+
if (!commandInput) {
|
|
82
|
+
console.warn(
|
|
83
|
+
`Command ${commandName} is not supported by the app. Try updating the app version`
|
|
84
|
+
);
|
|
85
|
+
} else {
|
|
86
|
+
if (commandInput.supported_versions.includes(version)) {
|
|
87
|
+
setCommandAvailable(commandName, true);
|
|
88
|
+
isCommandValid = true;
|
|
89
|
+
} else {
|
|
90
|
+
isCommandValid = true;
|
|
91
|
+
console.warn(
|
|
92
|
+
`Command ${commandName} version ${version} is not supported by the app. Supported versions: ${commandInput.supported_versions.join(", ")}. This is not an error, but it is recommended to update the World App version.`
|
|
93
|
+
);
|
|
94
|
+
setCommandAvailable(commandName, true);
|
|
95
|
+
}
|
|
80
96
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
navigator.mediaDevices
|
|
84
|
-
);
|
|
85
|
-
const live = /* @__PURE__ */ new Set();
|
|
86
|
-
async function wrapped(constraints) {
|
|
87
|
-
const stream = await realGUM(constraints);
|
|
88
|
-
const hasAudioTrack = stream.getAudioTracks().length > 0;
|
|
89
|
-
if (hasAudioTrack) {
|
|
90
|
-
sendWebviewEvent({
|
|
91
|
-
command: "microphone-stream-started",
|
|
92
|
-
version: 1,
|
|
93
|
-
payload: {
|
|
94
|
-
streamId: stream.id
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
live.add(stream);
|
|
98
|
-
stream.getAudioTracks().forEach((t) => {
|
|
99
|
-
t.addEventListener("ended", () => {
|
|
100
|
-
const allAudioTracksEnded = stream.getAudioTracks().every((track) => track.readyState === "ended");
|
|
101
|
-
if (allAudioTracksEnded) {
|
|
102
|
-
sendWebviewEvent({
|
|
103
|
-
command: "microphone-stream-ended",
|
|
104
|
-
version: 1,
|
|
105
|
-
payload: {
|
|
106
|
-
streamId: stream.id
|
|
107
|
-
}
|
|
108
|
-
});
|
|
109
|
-
live.delete(stream);
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
});
|
|
97
|
+
if (!isCommandValid) {
|
|
98
|
+
allCommandsValid = false;
|
|
113
99
|
}
|
|
114
|
-
return stream;
|
|
115
|
-
}
|
|
116
|
-
Object.defineProperty(navigator.mediaDevices, "getUserMedia", {
|
|
117
|
-
value: wrapped,
|
|
118
|
-
writable: false,
|
|
119
|
-
configurable: false,
|
|
120
|
-
enumerable: true
|
|
121
100
|
});
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
101
|
+
return allCommandsValid;
|
|
102
|
+
}
|
|
103
|
+
function sendMiniKitEvent(payload) {
|
|
104
|
+
sendWebviewEvent(payload);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// commands/chat.ts
|
|
108
|
+
function createChatCommand(_ctx) {
|
|
109
|
+
return (payload) => {
|
|
110
|
+
if (typeof window === "undefined" || !isCommandAvailable("chat" /* Chat */)) {
|
|
111
|
+
console.error(
|
|
112
|
+
"'chat' command is unavailable. Check MiniKit.install() or update the app version"
|
|
113
|
+
);
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
if (payload.message.length === 0) {
|
|
117
|
+
console.error("'chat' command requires a non-empty message");
|
|
118
|
+
return null;
|
|
119
|
+
}
|
|
120
|
+
sendMiniKitEvent({
|
|
121
|
+
command: "chat" /* Chat */,
|
|
122
|
+
version: COMMAND_VERSIONS["chat" /* Chat */],
|
|
123
|
+
payload
|
|
124
|
+
});
|
|
125
|
+
return payload;
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
function createChatAsyncCommand(ctx, syncCommand) {
|
|
129
|
+
return async (payload) => {
|
|
130
|
+
return new Promise((resolve, reject) => {
|
|
131
|
+
try {
|
|
132
|
+
let commandPayload = null;
|
|
133
|
+
const handleResponse = (response) => {
|
|
134
|
+
ctx.events.unsubscribe("miniapp-chat" /* MiniAppChat */);
|
|
135
|
+
resolve({ commandPayload, finalPayload: response });
|
|
136
|
+
};
|
|
137
|
+
ctx.events.subscribe("miniapp-chat" /* MiniAppChat */, handleResponse);
|
|
138
|
+
commandPayload = syncCommand(payload);
|
|
139
|
+
} catch (error) {
|
|
140
|
+
reject(error);
|
|
137
141
|
}
|
|
138
142
|
});
|
|
139
|
-
live.clear();
|
|
140
143
|
};
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// commands/get-permissions.ts
|
|
147
|
+
function createGetPermissionsCommand(_ctx) {
|
|
148
|
+
return () => {
|
|
149
|
+
if (typeof window === "undefined" || !isCommandAvailable("get-permissions" /* GetPermissions */)) {
|
|
150
|
+
console.error(
|
|
151
|
+
"'getPermissions' command is unavailable. Check MiniKit.install() or update the app version"
|
|
152
|
+
);
|
|
153
|
+
return null;
|
|
145
154
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
155
|
+
sendMiniKitEvent({
|
|
156
|
+
command: "get-permissions" /* GetPermissions */,
|
|
157
|
+
version: COMMAND_VERSIONS["get-permissions" /* GetPermissions */],
|
|
158
|
+
payload: {}
|
|
159
|
+
});
|
|
160
|
+
return {
|
|
161
|
+
status: "sent"
|
|
162
|
+
};
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
function createGetPermissionsAsyncCommand(ctx, syncCommand) {
|
|
166
|
+
return async () => {
|
|
167
|
+
return new Promise((resolve, reject) => {
|
|
168
|
+
try {
|
|
169
|
+
let commandPayload = null;
|
|
170
|
+
const handleResponse = (payload) => {
|
|
171
|
+
ctx.events.unsubscribe("miniapp-get-permissions" /* MiniAppGetPermissions */);
|
|
172
|
+
resolve({ commandPayload, finalPayload: payload });
|
|
173
|
+
};
|
|
174
|
+
ctx.events.subscribe(
|
|
175
|
+
"miniapp-get-permissions" /* MiniAppGetPermissions */,
|
|
176
|
+
handleResponse
|
|
177
|
+
);
|
|
178
|
+
commandPayload = syncCommand();
|
|
179
|
+
} catch (error) {
|
|
180
|
+
reject(error);
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
};
|
|
184
|
+
}
|
|
150
185
|
|
|
151
186
|
// helpers/payment/client.ts
|
|
152
187
|
var validatePaymentPayload = (payload) => {
|
|
@@ -166,57 +201,232 @@ var validatePaymentPayload = (payload) => {
|
|
|
166
201
|
return true;
|
|
167
202
|
};
|
|
168
203
|
|
|
169
|
-
//
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
204
|
+
// commands/pay.ts
|
|
205
|
+
function createPayCommand(_ctx) {
|
|
206
|
+
return (payload) => {
|
|
207
|
+
if (typeof window === "undefined" || !isCommandAvailable("pay" /* Pay */)) {
|
|
208
|
+
console.error(
|
|
209
|
+
"'pay' command is unavailable. Check MiniKit.install() or update the app version"
|
|
210
|
+
);
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
if (!validatePaymentPayload(payload)) {
|
|
214
|
+
return null;
|
|
215
|
+
}
|
|
216
|
+
const eventPayload = {
|
|
217
|
+
...payload,
|
|
218
|
+
network: "worldchain" /* WorldChain */
|
|
219
|
+
};
|
|
220
|
+
sendMiniKitEvent({
|
|
221
|
+
command: "pay" /* Pay */,
|
|
222
|
+
version: COMMAND_VERSIONS["pay" /* Pay */],
|
|
223
|
+
payload: eventPayload
|
|
224
|
+
});
|
|
225
|
+
return eventPayload;
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
function createPayAsyncCommand(ctx, syncCommand) {
|
|
229
|
+
return async (payload) => {
|
|
230
|
+
return new Promise((resolve, reject) => {
|
|
231
|
+
try {
|
|
232
|
+
let commandPayload = null;
|
|
233
|
+
const handleResponse = (response) => {
|
|
234
|
+
ctx.events.unsubscribe("miniapp-payment" /* MiniAppPayment */);
|
|
235
|
+
resolve({ commandPayload, finalPayload: response });
|
|
236
|
+
};
|
|
237
|
+
ctx.events.subscribe(
|
|
238
|
+
"miniapp-payment" /* MiniAppPayment */,
|
|
239
|
+
handleResponse
|
|
240
|
+
);
|
|
241
|
+
commandPayload = syncCommand(payload);
|
|
242
|
+
} catch (error) {
|
|
243
|
+
reject(error);
|
|
180
244
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
245
|
+
});
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// commands/request-permission.ts
|
|
250
|
+
function createRequestPermissionCommand(_ctx) {
|
|
251
|
+
return (payload) => {
|
|
252
|
+
if (typeof window === "undefined" || !isCommandAvailable("request-permission" /* RequestPermission */)) {
|
|
253
|
+
console.error(
|
|
254
|
+
"'requestPermission' command is unavailable. Check MiniKit.install() or update the app version"
|
|
255
|
+
);
|
|
256
|
+
return null;
|
|
257
|
+
}
|
|
258
|
+
sendMiniKitEvent({
|
|
259
|
+
command: "request-permission" /* RequestPermission */,
|
|
260
|
+
version: COMMAND_VERSIONS["request-permission" /* RequestPermission */],
|
|
261
|
+
payload
|
|
262
|
+
});
|
|
263
|
+
return payload;
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
function createRequestPermissionAsyncCommand(ctx, syncCommand) {
|
|
267
|
+
return async (payload) => {
|
|
268
|
+
return new Promise((resolve, reject) => {
|
|
269
|
+
try {
|
|
270
|
+
let commandPayload = null;
|
|
271
|
+
const handleResponse = (response) => {
|
|
272
|
+
ctx.events.unsubscribe("miniapp-request-permission" /* MiniAppRequestPermission */);
|
|
273
|
+
resolve({ commandPayload, finalPayload: response });
|
|
274
|
+
};
|
|
275
|
+
ctx.events.subscribe(
|
|
276
|
+
"miniapp-request-permission" /* MiniAppRequestPermission */,
|
|
277
|
+
handleResponse
|
|
278
|
+
);
|
|
279
|
+
commandPayload = syncCommand(payload);
|
|
280
|
+
} catch (error) {
|
|
281
|
+
reject(error);
|
|
188
282
|
}
|
|
189
|
-
],
|
|
190
|
-
stateMutability: "view",
|
|
191
|
-
type: "function"
|
|
192
|
-
}
|
|
193
|
-
];
|
|
194
|
-
var compressAndPadProof = async (proof, rpcUrl) => {
|
|
195
|
-
try {
|
|
196
|
-
const publicClient = (0, import_viem.createPublicClient)({
|
|
197
|
-
chain: import_chains.worldchain,
|
|
198
|
-
transport: (0, import_viem.http)(
|
|
199
|
-
rpcUrl || "https://worldchain-mainnet.g.alchemy.com/public"
|
|
200
|
-
)
|
|
201
283
|
});
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
284
|
+
};
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// commands/send-haptic-feedback.ts
|
|
288
|
+
function createSendHapticFeedbackCommand(_ctx) {
|
|
289
|
+
return (payload) => {
|
|
290
|
+
if (typeof window === "undefined" || !isCommandAvailable("send-haptic-feedback" /* SendHapticFeedback */)) {
|
|
291
|
+
console.error(
|
|
292
|
+
"'sendHapticFeedback' command is unavailable. Check MiniKit.install() or update the app version"
|
|
293
|
+
);
|
|
294
|
+
return null;
|
|
295
|
+
}
|
|
296
|
+
sendMiniKitEvent({
|
|
297
|
+
command: "send-haptic-feedback" /* SendHapticFeedback */,
|
|
298
|
+
version: COMMAND_VERSIONS["send-haptic-feedback" /* SendHapticFeedback */],
|
|
299
|
+
payload
|
|
211
300
|
});
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
301
|
+
return payload;
|
|
302
|
+
};
|
|
303
|
+
}
|
|
304
|
+
function createSendHapticFeedbackAsyncCommand(ctx, syncCommand) {
|
|
305
|
+
return async (payload) => {
|
|
306
|
+
return new Promise((resolve, reject) => {
|
|
307
|
+
try {
|
|
308
|
+
let commandPayload = null;
|
|
309
|
+
const handleResponse = (response) => {
|
|
310
|
+
ctx.events.unsubscribe("miniapp-send-haptic-feedback" /* MiniAppSendHapticFeedback */);
|
|
311
|
+
resolve({ commandPayload, finalPayload: response });
|
|
312
|
+
};
|
|
313
|
+
ctx.events.subscribe(
|
|
314
|
+
"miniapp-send-haptic-feedback" /* MiniAppSendHapticFeedback */,
|
|
315
|
+
handleResponse
|
|
316
|
+
);
|
|
317
|
+
commandPayload = syncCommand(payload);
|
|
318
|
+
} catch (error) {
|
|
319
|
+
reject(error);
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
};
|
|
323
|
+
}
|
|
218
324
|
|
|
219
|
-
// helpers/
|
|
325
|
+
// helpers/transaction/validate-payload.ts
|
|
326
|
+
var isValidHex = (str) => {
|
|
327
|
+
return /^0x[0-9A-Fa-f]+$/.test(str);
|
|
328
|
+
};
|
|
329
|
+
var objectValuesToArrayRecursive = (input) => {
|
|
330
|
+
if (input === null || typeof input !== "object") {
|
|
331
|
+
return input;
|
|
332
|
+
}
|
|
333
|
+
if (Array.isArray(input)) {
|
|
334
|
+
return input.map((item) => objectValuesToArrayRecursive(item));
|
|
335
|
+
}
|
|
336
|
+
const values = Object.values(input);
|
|
337
|
+
return values.map((value) => objectValuesToArrayRecursive(value));
|
|
338
|
+
};
|
|
339
|
+
var processPayload = (payload) => {
|
|
340
|
+
if (typeof payload === "boolean" || typeof payload === "string" || payload === null || payload === void 0) {
|
|
341
|
+
return payload;
|
|
342
|
+
}
|
|
343
|
+
if (typeof payload === "number" || typeof payload === "bigint") {
|
|
344
|
+
return String(payload);
|
|
345
|
+
}
|
|
346
|
+
if (Array.isArray(payload)) {
|
|
347
|
+
return payload.map((value) => processPayload(value));
|
|
348
|
+
}
|
|
349
|
+
if (typeof payload === "object") {
|
|
350
|
+
const result = { ...payload };
|
|
351
|
+
if ("value" in result && result.value !== void 0) {
|
|
352
|
+
if (typeof result.value !== "string") {
|
|
353
|
+
result.value = String(result.value);
|
|
354
|
+
}
|
|
355
|
+
if (!isValidHex(result.value)) {
|
|
356
|
+
console.error(
|
|
357
|
+
"Transaction value must be a valid hex string",
|
|
358
|
+
result.value
|
|
359
|
+
);
|
|
360
|
+
throw new Error(
|
|
361
|
+
`Transaction value must be a valid hex string: ${result.value}`
|
|
362
|
+
);
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
for (const key in result) {
|
|
366
|
+
if (Object.prototype.hasOwnProperty.call(result, key)) {
|
|
367
|
+
result[key] = processPayload(result[key]);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
return result;
|
|
371
|
+
}
|
|
372
|
+
return payload;
|
|
373
|
+
};
|
|
374
|
+
var validateSendTransactionPayload = (payload) => {
|
|
375
|
+
if (payload.formatPayload) {
|
|
376
|
+
const formattedPayload = processPayload(payload);
|
|
377
|
+
formattedPayload.transaction = formattedPayload.transaction.map((tx) => {
|
|
378
|
+
const args = objectValuesToArrayRecursive(tx.args);
|
|
379
|
+
return {
|
|
380
|
+
...tx,
|
|
381
|
+
args
|
|
382
|
+
};
|
|
383
|
+
});
|
|
384
|
+
return formattedPayload;
|
|
385
|
+
}
|
|
386
|
+
return payload;
|
|
387
|
+
};
|
|
388
|
+
|
|
389
|
+
// commands/send-transaction.ts
|
|
390
|
+
function createSendTransactionCommand(_ctx) {
|
|
391
|
+
return (payload) => {
|
|
392
|
+
if (typeof window === "undefined" || !isCommandAvailable("send-transaction" /* SendTransaction */)) {
|
|
393
|
+
console.error(
|
|
394
|
+
"'sendTransaction' command is unavailable. Check MiniKit.install() or update the app version"
|
|
395
|
+
);
|
|
396
|
+
return null;
|
|
397
|
+
}
|
|
398
|
+
payload.formatPayload = payload.formatPayload !== false;
|
|
399
|
+
const validatedPayload = validateSendTransactionPayload(payload);
|
|
400
|
+
sendMiniKitEvent({
|
|
401
|
+
command: "send-transaction" /* SendTransaction */,
|
|
402
|
+
version: COMMAND_VERSIONS["send-transaction" /* SendTransaction */],
|
|
403
|
+
payload: validatedPayload
|
|
404
|
+
});
|
|
405
|
+
return validatedPayload;
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
function createSendTransactionAsyncCommand(ctx, syncCommand) {
|
|
409
|
+
return async (payload) => {
|
|
410
|
+
return new Promise((resolve, reject) => {
|
|
411
|
+
try {
|
|
412
|
+
let commandPayload = null;
|
|
413
|
+
const handleResponse = (response) => {
|
|
414
|
+
ctx.events.unsubscribe("miniapp-send-transaction" /* MiniAppSendTransaction */);
|
|
415
|
+
resolve({ commandPayload, finalPayload: response });
|
|
416
|
+
};
|
|
417
|
+
ctx.events.subscribe(
|
|
418
|
+
"miniapp-send-transaction" /* MiniAppSendTransaction */,
|
|
419
|
+
handleResponse
|
|
420
|
+
);
|
|
421
|
+
commandPayload = syncCommand(payload);
|
|
422
|
+
} catch (error) {
|
|
423
|
+
reject(error);
|
|
424
|
+
}
|
|
425
|
+
});
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
// helpers/share/index.ts
|
|
220
430
|
var MAX_FILES = 10;
|
|
221
431
|
var MAX_TOTAL_SIZE_MB = 50;
|
|
222
432
|
var MAX_TOTAL_SIZE_BYTES = MAX_TOTAL_SIZE_MB * 1024 * 1024;
|
|
@@ -282,9 +492,229 @@ var formatShareInput = async (input) => {
|
|
|
282
492
|
};
|
|
283
493
|
};
|
|
284
494
|
|
|
495
|
+
// commands/share.ts
|
|
496
|
+
function createShareCommand(ctx) {
|
|
497
|
+
return (payload) => {
|
|
498
|
+
if (typeof window === "undefined" || !isCommandAvailable("share" /* Share */)) {
|
|
499
|
+
console.error(
|
|
500
|
+
"'share' command is unavailable. Check MiniKit.install() or update the app version"
|
|
501
|
+
);
|
|
502
|
+
return null;
|
|
503
|
+
}
|
|
504
|
+
if (ctx.state.deviceProperties.deviceOS === "ios" && typeof navigator !== "undefined") {
|
|
505
|
+
sendMiniKitEvent({
|
|
506
|
+
command: "share" /* Share */,
|
|
507
|
+
version: COMMAND_VERSIONS["share" /* Share */],
|
|
508
|
+
payload
|
|
509
|
+
});
|
|
510
|
+
navigator.share(payload);
|
|
511
|
+
} else {
|
|
512
|
+
formatShareInput(payload).then((formattedResult) => {
|
|
513
|
+
sendMiniKitEvent({
|
|
514
|
+
command: "share" /* Share */,
|
|
515
|
+
version: COMMAND_VERSIONS["share" /* Share */],
|
|
516
|
+
payload: formattedResult
|
|
517
|
+
});
|
|
518
|
+
}).catch((error) => {
|
|
519
|
+
console.error("Failed to format share input", error);
|
|
520
|
+
});
|
|
521
|
+
ctx.events.subscribe("miniapp-share" /* MiniAppShare */, (response) => {
|
|
522
|
+
console.log("Share Response", response);
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
return payload;
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
function createShareAsyncCommand(ctx, syncCommand) {
|
|
529
|
+
return async (payload) => {
|
|
530
|
+
return new Promise((resolve, reject) => {
|
|
531
|
+
try {
|
|
532
|
+
let commandPayload = null;
|
|
533
|
+
const handleResponse = (response) => {
|
|
534
|
+
ctx.events.unsubscribe("miniapp-share" /* MiniAppShare */);
|
|
535
|
+
resolve({ commandPayload, finalPayload: response });
|
|
536
|
+
};
|
|
537
|
+
ctx.events.subscribe("miniapp-share" /* MiniAppShare */, handleResponse);
|
|
538
|
+
commandPayload = syncCommand(payload);
|
|
539
|
+
} catch (error) {
|
|
540
|
+
reject(error);
|
|
541
|
+
}
|
|
542
|
+
});
|
|
543
|
+
};
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
// commands/share-contacts.ts
|
|
547
|
+
function createShareContactsCommand(_ctx) {
|
|
548
|
+
return (payload) => {
|
|
549
|
+
if (typeof window === "undefined" || !isCommandAvailable("share-contacts" /* ShareContacts */)) {
|
|
550
|
+
console.error(
|
|
551
|
+
"'shareContacts' command is unavailable. Check MiniKit.install() or update the app version"
|
|
552
|
+
);
|
|
553
|
+
return null;
|
|
554
|
+
}
|
|
555
|
+
sendMiniKitEvent({
|
|
556
|
+
command: "share-contacts" /* ShareContacts */,
|
|
557
|
+
version: COMMAND_VERSIONS["share-contacts" /* ShareContacts */],
|
|
558
|
+
payload
|
|
559
|
+
});
|
|
560
|
+
return payload;
|
|
561
|
+
};
|
|
562
|
+
}
|
|
563
|
+
function createShareContactsAsyncCommand(ctx, syncCommand) {
|
|
564
|
+
return async (payload) => {
|
|
565
|
+
return new Promise((resolve, reject) => {
|
|
566
|
+
try {
|
|
567
|
+
let commandPayload = null;
|
|
568
|
+
const handleResponse = (response) => {
|
|
569
|
+
ctx.events.unsubscribe("miniapp-share-contacts" /* MiniAppShareContacts */);
|
|
570
|
+
resolve({ commandPayload, finalPayload: response });
|
|
571
|
+
};
|
|
572
|
+
ctx.events.subscribe(
|
|
573
|
+
"miniapp-share-contacts" /* MiniAppShareContacts */,
|
|
574
|
+
handleResponse
|
|
575
|
+
);
|
|
576
|
+
commandPayload = syncCommand(payload);
|
|
577
|
+
} catch (error) {
|
|
578
|
+
reject(error);
|
|
579
|
+
}
|
|
580
|
+
});
|
|
581
|
+
};
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
// commands/sign-message.ts
|
|
585
|
+
function createSignMessageCommand(_ctx) {
|
|
586
|
+
return (payload) => {
|
|
587
|
+
if (typeof window === "undefined" || !isCommandAvailable("sign-message" /* SignMessage */)) {
|
|
588
|
+
console.error(
|
|
589
|
+
"'signMessage' command is unavailable. Check MiniKit.install() or update the app version"
|
|
590
|
+
);
|
|
591
|
+
return null;
|
|
592
|
+
}
|
|
593
|
+
sendMiniKitEvent({
|
|
594
|
+
command: "sign-message" /* SignMessage */,
|
|
595
|
+
version: COMMAND_VERSIONS["sign-message" /* SignMessage */],
|
|
596
|
+
payload
|
|
597
|
+
});
|
|
598
|
+
return payload;
|
|
599
|
+
};
|
|
600
|
+
}
|
|
601
|
+
function createSignMessageAsyncCommand(ctx, syncCommand) {
|
|
602
|
+
return async (payload) => {
|
|
603
|
+
return new Promise((resolve, reject) => {
|
|
604
|
+
try {
|
|
605
|
+
let commandPayload = null;
|
|
606
|
+
const handleResponse = (response) => {
|
|
607
|
+
ctx.events.unsubscribe("miniapp-sign-message" /* MiniAppSignMessage */);
|
|
608
|
+
resolve({ commandPayload, finalPayload: response });
|
|
609
|
+
};
|
|
610
|
+
ctx.events.subscribe(
|
|
611
|
+
"miniapp-sign-message" /* MiniAppSignMessage */,
|
|
612
|
+
handleResponse
|
|
613
|
+
);
|
|
614
|
+
commandPayload = syncCommand(payload);
|
|
615
|
+
} catch (error) {
|
|
616
|
+
reject(error);
|
|
617
|
+
}
|
|
618
|
+
});
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
|
|
622
|
+
// commands/sign-typed-data.ts
|
|
623
|
+
function createSignTypedDataCommand(_ctx) {
|
|
624
|
+
return (payload) => {
|
|
625
|
+
if (typeof window === "undefined" || !isCommandAvailable("sign-typed-data" /* SignTypedData */)) {
|
|
626
|
+
console.error(
|
|
627
|
+
"'signTypedData' command is unavailable. Check MiniKit.install() or update the app version"
|
|
628
|
+
);
|
|
629
|
+
return null;
|
|
630
|
+
}
|
|
631
|
+
if (!payload.chainId) {
|
|
632
|
+
payload.chainId = 480;
|
|
633
|
+
}
|
|
634
|
+
sendMiniKitEvent({
|
|
635
|
+
command: "sign-typed-data" /* SignTypedData */,
|
|
636
|
+
version: COMMAND_VERSIONS["sign-typed-data" /* SignTypedData */],
|
|
637
|
+
payload
|
|
638
|
+
});
|
|
639
|
+
return payload;
|
|
640
|
+
};
|
|
641
|
+
}
|
|
642
|
+
function createSignTypedDataAsyncCommand(ctx, syncCommand) {
|
|
643
|
+
return async (payload) => {
|
|
644
|
+
return new Promise((resolve, reject) => {
|
|
645
|
+
try {
|
|
646
|
+
let commandPayload = null;
|
|
647
|
+
const handleResponse = (response) => {
|
|
648
|
+
ctx.events.unsubscribe("miniapp-sign-typed-data" /* MiniAppSignTypedData */);
|
|
649
|
+
resolve({ commandPayload, finalPayload: response });
|
|
650
|
+
};
|
|
651
|
+
ctx.events.subscribe(
|
|
652
|
+
"miniapp-sign-typed-data" /* MiniAppSignTypedData */,
|
|
653
|
+
handleResponse
|
|
654
|
+
);
|
|
655
|
+
commandPayload = syncCommand(payload);
|
|
656
|
+
} catch (error) {
|
|
657
|
+
reject(error);
|
|
658
|
+
}
|
|
659
|
+
});
|
|
660
|
+
};
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
// commands/verify.ts
|
|
664
|
+
var import_idkit_core = require("@worldcoin/idkit-core");
|
|
665
|
+
var import_hashing = require("@worldcoin/idkit-core/hashing");
|
|
666
|
+
var import_idkit_core2 = require("@worldcoin/idkit-core");
|
|
667
|
+
function createVerifyCommand(_ctx) {
|
|
668
|
+
return (payload) => {
|
|
669
|
+
if (typeof window === "undefined" || !isCommandAvailable("verify" /* Verify */)) {
|
|
670
|
+
console.error(
|
|
671
|
+
"'verify' command is unavailable. Check MiniKit.install() or update the app version"
|
|
672
|
+
);
|
|
673
|
+
return null;
|
|
674
|
+
}
|
|
675
|
+
if (Array.isArray(payload.verification_level) && payload.verification_level.length === 0) {
|
|
676
|
+
console.error("'verification_level' must not be an empty array");
|
|
677
|
+
return null;
|
|
678
|
+
}
|
|
679
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
680
|
+
const eventPayload = {
|
|
681
|
+
action: (0, import_hashing.encodeAction)(payload.action),
|
|
682
|
+
signal: (0, import_hashing.generateSignal)(payload.signal).digest,
|
|
683
|
+
verification_level: payload.verification_level || import_idkit_core.VerificationLevel.Orb,
|
|
684
|
+
timestamp
|
|
685
|
+
};
|
|
686
|
+
sendMiniKitEvent({
|
|
687
|
+
command: "verify" /* Verify */,
|
|
688
|
+
version: COMMAND_VERSIONS["verify" /* Verify */],
|
|
689
|
+
payload: eventPayload
|
|
690
|
+
});
|
|
691
|
+
return eventPayload;
|
|
692
|
+
};
|
|
693
|
+
}
|
|
694
|
+
function createVerifyAsyncCommand(ctx, syncCommand) {
|
|
695
|
+
return async (payload) => {
|
|
696
|
+
return new Promise((resolve, reject) => {
|
|
697
|
+
try {
|
|
698
|
+
let commandPayload = null;
|
|
699
|
+
const handleResponse = (response) => {
|
|
700
|
+
ctx.events.unsubscribe("miniapp-verify-action" /* MiniAppVerifyAction */);
|
|
701
|
+
resolve({ commandPayload, finalPayload: response });
|
|
702
|
+
};
|
|
703
|
+
ctx.events.subscribe(
|
|
704
|
+
"miniapp-verify-action" /* MiniAppVerifyAction */,
|
|
705
|
+
handleResponse
|
|
706
|
+
);
|
|
707
|
+
commandPayload = syncCommand(payload);
|
|
708
|
+
} catch (error) {
|
|
709
|
+
reject(error);
|
|
710
|
+
}
|
|
711
|
+
});
|
|
712
|
+
};
|
|
713
|
+
}
|
|
714
|
+
|
|
285
715
|
// helpers/siwe/siwe.ts
|
|
286
|
-
var
|
|
287
|
-
var
|
|
716
|
+
var import_viem = require("viem");
|
|
717
|
+
var import_chains = require("viem/chains");
|
|
288
718
|
var generateSiweMessage = (siweMessageData) => {
|
|
289
719
|
let siweMessage = "";
|
|
290
720
|
if (siweMessageData.scheme) {
|
|
@@ -354,381 +784,10 @@ var validateWalletAuthCommandInput = (params) => {
|
|
|
354
784
|
return { valid: true };
|
|
355
785
|
};
|
|
356
786
|
|
|
357
|
-
//
|
|
358
|
-
|
|
359
|
-
return
|
|
360
|
-
|
|
361
|
-
var objectValuesToArrayRecursive = (input) => {
|
|
362
|
-
if (input === null || typeof input !== "object") {
|
|
363
|
-
return input;
|
|
364
|
-
}
|
|
365
|
-
if (Array.isArray(input)) {
|
|
366
|
-
return input.map((item) => objectValuesToArrayRecursive(item));
|
|
367
|
-
}
|
|
368
|
-
const values = Object.values(input);
|
|
369
|
-
return values.map((value) => objectValuesToArrayRecursive(value));
|
|
370
|
-
};
|
|
371
|
-
var processPayload = (payload) => {
|
|
372
|
-
if (typeof payload === "boolean" || typeof payload === "string" || payload === null || payload === void 0) {
|
|
373
|
-
return payload;
|
|
374
|
-
}
|
|
375
|
-
if (typeof payload === "number" || typeof payload === "bigint") {
|
|
376
|
-
return String(payload);
|
|
377
|
-
}
|
|
378
|
-
if (Array.isArray(payload)) {
|
|
379
|
-
return payload.map((value) => processPayload(value));
|
|
380
|
-
}
|
|
381
|
-
if (typeof payload === "object") {
|
|
382
|
-
const result = { ...payload };
|
|
383
|
-
if ("value" in result && result.value !== void 0) {
|
|
384
|
-
if (typeof result.value !== "string") {
|
|
385
|
-
result.value = String(result.value);
|
|
386
|
-
}
|
|
387
|
-
if (!isValidHex(result.value)) {
|
|
388
|
-
console.error(
|
|
389
|
-
"Transaction value must be a valid hex string",
|
|
390
|
-
result.value
|
|
391
|
-
);
|
|
392
|
-
throw new Error(
|
|
393
|
-
`Transaction value must be a valid hex string: ${result.value}`
|
|
394
|
-
);
|
|
395
|
-
}
|
|
396
|
-
}
|
|
397
|
-
for (const key in result) {
|
|
398
|
-
if (Object.prototype.hasOwnProperty.call(result, key)) {
|
|
399
|
-
result[key] = processPayload(result[key]);
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
return result;
|
|
403
|
-
}
|
|
404
|
-
return payload;
|
|
405
|
-
};
|
|
406
|
-
var validateSendTransactionPayload = (payload) => {
|
|
407
|
-
if (payload.formatPayload) {
|
|
408
|
-
const formattedPayload = processPayload(payload);
|
|
409
|
-
formattedPayload.transaction = formattedPayload.transaction.map((tx) => {
|
|
410
|
-
const args = objectValuesToArrayRecursive(tx.args);
|
|
411
|
-
return {
|
|
412
|
-
...tx,
|
|
413
|
-
args
|
|
414
|
-
};
|
|
415
|
-
});
|
|
416
|
-
return formattedPayload;
|
|
417
|
-
}
|
|
418
|
-
return payload;
|
|
419
|
-
};
|
|
420
|
-
|
|
421
|
-
// helpers/usernames/index.ts
|
|
422
|
-
var getUserProfile = async (address) => {
|
|
423
|
-
const res = await fetch("https://usernames.worldcoin.org/api/v1/query", {
|
|
424
|
-
method: "POST",
|
|
425
|
-
headers: {
|
|
426
|
-
"Content-Type": "application/json"
|
|
427
|
-
},
|
|
428
|
-
body: JSON.stringify({
|
|
429
|
-
addresses: [address]
|
|
430
|
-
})
|
|
431
|
-
});
|
|
432
|
-
const usernames = await res.json();
|
|
433
|
-
return usernames?.[0] ?? { username: null, profile_picture_url: null };
|
|
434
|
-
};
|
|
435
|
-
|
|
436
|
-
// minikit.ts
|
|
437
|
-
var sendMiniKitEvent = (payload) => {
|
|
438
|
-
sendWebviewEvent(payload);
|
|
439
|
-
};
|
|
440
|
-
var _MiniKit = class _MiniKit {
|
|
441
|
-
static sendInit() {
|
|
442
|
-
sendWebviewEvent({
|
|
443
|
-
command: "init",
|
|
444
|
-
payload: {
|
|
445
|
-
version: this.MINIKIT_VERSION,
|
|
446
|
-
minorVersion: this.MINIKIT_MINOR_VERSION
|
|
447
|
-
}
|
|
448
|
-
});
|
|
449
|
-
}
|
|
450
|
-
static subscribe(event, handler) {
|
|
451
|
-
if (event === "miniapp-wallet-auth" /* MiniAppWalletAuth */) {
|
|
452
|
-
const originalHandler = handler;
|
|
453
|
-
const wrappedHandler = async (payload) => {
|
|
454
|
-
if (payload.status === "success") {
|
|
455
|
-
_MiniKit.user.walletAddress = payload.address;
|
|
456
|
-
try {
|
|
457
|
-
const user = await _MiniKit.getUserByAddress(payload.address);
|
|
458
|
-
_MiniKit.user = { ..._MiniKit.user, ...user };
|
|
459
|
-
} catch (error) {
|
|
460
|
-
console.error("Failed to fetch user profile:", error);
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
originalHandler(payload);
|
|
464
|
-
};
|
|
465
|
-
this.listeners[event] = wrappedHandler;
|
|
466
|
-
} else if (event === "miniapp-verify-action" /* MiniAppVerifyAction */) {
|
|
467
|
-
const originalHandler = handler;
|
|
468
|
-
const wrappedHandler = (payload) => {
|
|
469
|
-
if (payload.status === "success" && payload.verification_level === import_idkit_core3.VerificationLevel.Orb) {
|
|
470
|
-
compressAndPadProof(payload.proof).then(
|
|
471
|
-
(compressedProof) => {
|
|
472
|
-
payload.proof = compressedProof;
|
|
473
|
-
originalHandler(payload);
|
|
474
|
-
}
|
|
475
|
-
);
|
|
476
|
-
} else {
|
|
477
|
-
originalHandler(payload);
|
|
478
|
-
}
|
|
479
|
-
};
|
|
480
|
-
this.listeners[event] = wrappedHandler;
|
|
481
|
-
} else {
|
|
482
|
-
this.listeners[event] = handler;
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
static unsubscribe(event) {
|
|
486
|
-
delete this.listeners[event];
|
|
487
|
-
}
|
|
488
|
-
static trigger(event, payload) {
|
|
489
|
-
if (!this.listeners[event]) {
|
|
490
|
-
console.error(
|
|
491
|
-
`No handler for event ${event}, payload: ${JSON.stringify(payload)}`
|
|
492
|
-
);
|
|
493
|
-
return;
|
|
494
|
-
}
|
|
495
|
-
this.listeners[event](payload);
|
|
496
|
-
}
|
|
497
|
-
static async awaitCommand(event, command, executor) {
|
|
498
|
-
return new Promise((resolve) => {
|
|
499
|
-
let commandPayload = null;
|
|
500
|
-
const handleAndUnsubscribe = (payload) => {
|
|
501
|
-
this.unsubscribe(event);
|
|
502
|
-
resolve({ commandPayload, finalPayload: payload });
|
|
503
|
-
};
|
|
504
|
-
this.subscribe(event, handleAndUnsubscribe);
|
|
505
|
-
commandPayload = executor();
|
|
506
|
-
});
|
|
507
|
-
}
|
|
508
|
-
static commandsValid(worldAppSupportedCommands) {
|
|
509
|
-
let allCommandsValid = true;
|
|
510
|
-
Object.entries(this.miniKitCommandVersion).forEach(
|
|
511
|
-
([minikitCommandName, version]) => {
|
|
512
|
-
const commandInput = worldAppSupportedCommands.find(
|
|
513
|
-
(command) => command.name === minikitCommandName
|
|
514
|
-
);
|
|
515
|
-
let isCommandValid = false;
|
|
516
|
-
if (!commandInput) {
|
|
517
|
-
console.warn(
|
|
518
|
-
`Command ${minikitCommandName} is not supported by the app. Try updating the app version`
|
|
519
|
-
);
|
|
520
|
-
} else {
|
|
521
|
-
if (commandInput.supported_versions.includes(version)) {
|
|
522
|
-
_MiniKit.isCommandAvailable[minikitCommandName] = true;
|
|
523
|
-
isCommandValid = true;
|
|
524
|
-
} else {
|
|
525
|
-
isCommandValid = true;
|
|
526
|
-
console.warn(
|
|
527
|
-
`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.`
|
|
528
|
-
);
|
|
529
|
-
_MiniKit.isCommandAvailable[minikitCommandName] = isCommandValid;
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
if (!isCommandValid) {
|
|
533
|
-
allCommandsValid = false;
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
);
|
|
537
|
-
return allCommandsValid;
|
|
538
|
-
}
|
|
539
|
-
static install(appId) {
|
|
540
|
-
if (typeof window === "undefined" || Boolean(window.MiniKit)) {
|
|
541
|
-
return {
|
|
542
|
-
success: false,
|
|
543
|
-
errorCode: "already_installed" /* AlreadyInstalled */,
|
|
544
|
-
errorMessage: MiniKitInstallErrorMessage["already_installed" /* AlreadyInstalled */]
|
|
545
|
-
};
|
|
546
|
-
}
|
|
547
|
-
if (!appId) {
|
|
548
|
-
console.warn("App ID not provided during install");
|
|
549
|
-
} else {
|
|
550
|
-
_MiniKit.appId = appId;
|
|
551
|
-
}
|
|
552
|
-
if (!window.WorldApp) {
|
|
553
|
-
return {
|
|
554
|
-
success: false,
|
|
555
|
-
errorCode: "outside_of_worldapp" /* OutsideOfWorldApp */,
|
|
556
|
-
errorMessage: MiniKitInstallErrorMessage["outside_of_worldapp" /* OutsideOfWorldApp */]
|
|
557
|
-
};
|
|
558
|
-
}
|
|
559
|
-
_MiniKit.user.optedIntoOptionalAnalytics = window.WorldApp.is_optional_analytics;
|
|
560
|
-
_MiniKit.user.deviceOS = window.WorldApp.device_os;
|
|
561
|
-
_MiniKit.user.worldAppVersion = window.WorldApp.world_app_version;
|
|
562
|
-
_MiniKit.deviceProperties.safeAreaInsets = window.WorldApp.safe_area_insets;
|
|
563
|
-
_MiniKit.deviceProperties.deviceOS = window.WorldApp.device_os;
|
|
564
|
-
_MiniKit.deviceProperties.worldAppVersion = window.WorldApp.world_app_version;
|
|
565
|
-
try {
|
|
566
|
-
window.MiniKit = _MiniKit;
|
|
567
|
-
this.sendInit();
|
|
568
|
-
} catch (error) {
|
|
569
|
-
console.error(
|
|
570
|
-
MiniKitInstallErrorMessage["unknown" /* Unknown */],
|
|
571
|
-
error
|
|
572
|
-
);
|
|
573
|
-
return {
|
|
574
|
-
success: false,
|
|
575
|
-
errorCode: "unknown" /* Unknown */,
|
|
576
|
-
errorMessage: MiniKitInstallErrorMessage["unknown" /* Unknown */]
|
|
577
|
-
};
|
|
578
|
-
}
|
|
579
|
-
_MiniKit.isReady = true;
|
|
580
|
-
setupMicrophone();
|
|
581
|
-
if (!this.commandsValid(window.WorldApp.supported_commands)) {
|
|
582
|
-
return {
|
|
583
|
-
success: false,
|
|
584
|
-
errorCode: "app_out_of_date" /* AppOutOfDate */,
|
|
585
|
-
errorMessage: MiniKitInstallErrorMessage["app_out_of_date" /* AppOutOfDate */]
|
|
586
|
-
};
|
|
587
|
-
}
|
|
588
|
-
return { success: true };
|
|
589
|
-
}
|
|
590
|
-
static isInstalled(debug) {
|
|
591
|
-
const isInstalled = _MiniKit.isReady && Boolean(window.MiniKit);
|
|
592
|
-
if (!isInstalled)
|
|
593
|
-
console.error(
|
|
594
|
-
"MiniKit is not installed. Make sure you're running the application inside of World App"
|
|
595
|
-
);
|
|
596
|
-
if (debug && isInstalled) console.log("MiniKit is alive!");
|
|
597
|
-
return isInstalled;
|
|
598
|
-
}
|
|
599
|
-
};
|
|
600
|
-
_MiniKit.MINIKIT_VERSION = 1;
|
|
601
|
-
_MiniKit.MINIKIT_MINOR_VERSION = 96;
|
|
602
|
-
_MiniKit.miniKitCommandVersion = {
|
|
603
|
-
["verify" /* Verify */]: 1,
|
|
604
|
-
["pay" /* Pay */]: 1,
|
|
605
|
-
["wallet-auth" /* WalletAuth */]: 2,
|
|
606
|
-
["send-transaction" /* SendTransaction */]: 1,
|
|
607
|
-
["sign-message" /* SignMessage */]: 1,
|
|
608
|
-
["sign-typed-data" /* SignTypedData */]: 1,
|
|
609
|
-
["share-contacts" /* ShareContacts */]: 1,
|
|
610
|
-
["request-permission" /* RequestPermission */]: 1,
|
|
611
|
-
["get-permissions" /* GetPermissions */]: 1,
|
|
612
|
-
["send-haptic-feedback" /* SendHapticFeedback */]: 1,
|
|
613
|
-
["share" /* Share */]: 1
|
|
614
|
-
};
|
|
615
|
-
_MiniKit.isCommandAvailable = {
|
|
616
|
-
["verify" /* Verify */]: false,
|
|
617
|
-
["pay" /* Pay */]: false,
|
|
618
|
-
["wallet-auth" /* WalletAuth */]: false,
|
|
619
|
-
["send-transaction" /* SendTransaction */]: false,
|
|
620
|
-
["sign-message" /* SignMessage */]: false,
|
|
621
|
-
["sign-typed-data" /* SignTypedData */]: false,
|
|
622
|
-
["share-contacts" /* ShareContacts */]: false,
|
|
623
|
-
["request-permission" /* RequestPermission */]: false,
|
|
624
|
-
["get-permissions" /* GetPermissions */]: false,
|
|
625
|
-
["send-haptic-feedback" /* SendHapticFeedback */]: false,
|
|
626
|
-
["share" /* Share */]: false
|
|
627
|
-
};
|
|
628
|
-
_MiniKit.listeners = {
|
|
629
|
-
["miniapp-verify-action" /* MiniAppVerifyAction */]: () => {
|
|
630
|
-
},
|
|
631
|
-
["miniapp-payment" /* MiniAppPayment */]: () => {
|
|
632
|
-
},
|
|
633
|
-
["miniapp-wallet-auth" /* MiniAppWalletAuth */]: () => {
|
|
634
|
-
},
|
|
635
|
-
["miniapp-send-transaction" /* MiniAppSendTransaction */]: () => {
|
|
636
|
-
},
|
|
637
|
-
["miniapp-sign-message" /* MiniAppSignMessage */]: () => {
|
|
638
|
-
},
|
|
639
|
-
["miniapp-sign-typed-data" /* MiniAppSignTypedData */]: () => {
|
|
640
|
-
},
|
|
641
|
-
["miniapp-share-contacts" /* MiniAppShareContacts */]: () => {
|
|
642
|
-
},
|
|
643
|
-
["miniapp-request-permission" /* MiniAppRequestPermission */]: () => {
|
|
644
|
-
},
|
|
645
|
-
["miniapp-get-permissions" /* MiniAppGetPermissions */]: () => {
|
|
646
|
-
},
|
|
647
|
-
["miniapp-send-haptic-feedback" /* MiniAppSendHapticFeedback */]: () => {
|
|
648
|
-
},
|
|
649
|
-
["miniapp-share" /* MiniAppShare */]: () => {
|
|
650
|
-
},
|
|
651
|
-
["miniapp-microphone" /* MiniAppMicrophone */]: () => {
|
|
652
|
-
}
|
|
653
|
-
};
|
|
654
|
-
_MiniKit.appId = null;
|
|
655
|
-
_MiniKit.user = {};
|
|
656
|
-
_MiniKit.deviceProperties = {};
|
|
657
|
-
_MiniKit.isReady = false;
|
|
658
|
-
_MiniKit.getUserByAddress = async (address) => {
|
|
659
|
-
const userProfile = await getUserProfile(
|
|
660
|
-
address ?? _MiniKit.user.walletAddress
|
|
661
|
-
);
|
|
662
|
-
return {
|
|
663
|
-
walletAddress: address ?? _MiniKit.user.walletAddress,
|
|
664
|
-
username: userProfile.username,
|
|
665
|
-
profilePictureUrl: userProfile.profile_picture_url
|
|
666
|
-
};
|
|
667
|
-
};
|
|
668
|
-
_MiniKit.getUserByUsername = async (username) => {
|
|
669
|
-
const res = await fetch(
|
|
670
|
-
`https://usernames.worldcoin.org/api/v1/${username}`,
|
|
671
|
-
{
|
|
672
|
-
method: "GET",
|
|
673
|
-
headers: {
|
|
674
|
-
"Content-Type": "application/json"
|
|
675
|
-
}
|
|
676
|
-
}
|
|
677
|
-
);
|
|
678
|
-
const user = await res.json();
|
|
679
|
-
return {
|
|
680
|
-
walletAddress: user.address,
|
|
681
|
-
username: user.username,
|
|
682
|
-
profilePictureUrl: user.profile_picture_url
|
|
683
|
-
};
|
|
684
|
-
};
|
|
685
|
-
// Simply re-exporting the existing function
|
|
686
|
-
_MiniKit.getUserInfo = _MiniKit.getUserByAddress;
|
|
687
|
-
_MiniKit.commands = {
|
|
688
|
-
verify: (payload) => {
|
|
689
|
-
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["verify" /* Verify */]) {
|
|
690
|
-
console.error(
|
|
691
|
-
"'verify' command is unavailable. Check MiniKit.install() or update the app version"
|
|
692
|
-
);
|
|
693
|
-
return null;
|
|
694
|
-
}
|
|
695
|
-
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
696
|
-
const eventPayload = {
|
|
697
|
-
action: (0, import_hashing.encodeAction)(payload.action),
|
|
698
|
-
signal: (0, import_hashing.generateSignal)(payload.signal).digest,
|
|
699
|
-
verification_level: payload.verification_level || import_idkit_core3.VerificationLevel.Orb,
|
|
700
|
-
timestamp
|
|
701
|
-
};
|
|
702
|
-
sendMiniKitEvent({
|
|
703
|
-
command: "verify" /* Verify */,
|
|
704
|
-
version: _MiniKit.miniKitCommandVersion["verify" /* Verify */],
|
|
705
|
-
payload: eventPayload
|
|
706
|
-
});
|
|
707
|
-
return eventPayload;
|
|
708
|
-
},
|
|
709
|
-
pay: (payload) => {
|
|
710
|
-
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["pay" /* Pay */]) {
|
|
711
|
-
console.error(
|
|
712
|
-
"'pay' command is unavailable. Check MiniKit.install() or update the app version"
|
|
713
|
-
);
|
|
714
|
-
return null;
|
|
715
|
-
}
|
|
716
|
-
if (!validatePaymentPayload(payload)) {
|
|
717
|
-
return null;
|
|
718
|
-
}
|
|
719
|
-
const eventPayload = {
|
|
720
|
-
...payload,
|
|
721
|
-
network: "worldchain" /* WorldChain */
|
|
722
|
-
};
|
|
723
|
-
sendMiniKitEvent({
|
|
724
|
-
command: "pay" /* Pay */,
|
|
725
|
-
version: _MiniKit.miniKitCommandVersion["pay" /* Pay */],
|
|
726
|
-
payload: eventPayload
|
|
727
|
-
});
|
|
728
|
-
return eventPayload;
|
|
729
|
-
},
|
|
730
|
-
walletAuth: (payload) => {
|
|
731
|
-
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["wallet-auth" /* WalletAuth */]) {
|
|
787
|
+
// commands/wallet-auth.ts
|
|
788
|
+
function createWalletAuthCommand(ctx) {
|
|
789
|
+
return (payload) => {
|
|
790
|
+
if (typeof window === "undefined" || !isCommandAvailable("wallet-auth" /* WalletAuth */)) {
|
|
732
791
|
console.error(
|
|
733
792
|
"'walletAuth' command is unavailable. Check MiniKit.install() or update the app version"
|
|
734
793
|
);
|
|
@@ -764,324 +823,623 @@ _MiniKit.commands = {
|
|
|
764
823
|
request_id: payload.requestId ?? void 0
|
|
765
824
|
});
|
|
766
825
|
const walletAuthPayload = { siweMessage };
|
|
767
|
-
const walletAuthVersion =
|
|
826
|
+
const walletAuthVersion = ctx.state.user.worldAppVersion && ctx.state.user.worldAppVersion > 2087900 ? COMMAND_VERSIONS["wallet-auth" /* WalletAuth */] : 1;
|
|
768
827
|
sendMiniKitEvent({
|
|
769
828
|
command: "wallet-auth" /* WalletAuth */,
|
|
770
829
|
version: walletAuthVersion,
|
|
771
830
|
payload: walletAuthPayload
|
|
772
831
|
});
|
|
773
832
|
return walletAuthPayload;
|
|
774
|
-
}
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
return null;
|
|
797
|
-
}
|
|
798
|
-
sendMiniKitEvent({
|
|
799
|
-
command: "sign-message" /* SignMessage */,
|
|
800
|
-
version: _MiniKit.miniKitCommandVersion["sign-message" /* SignMessage */],
|
|
801
|
-
payload
|
|
802
|
-
});
|
|
803
|
-
return payload;
|
|
804
|
-
},
|
|
805
|
-
signTypedData: (payload) => {
|
|
806
|
-
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["sign-typed-data" /* SignTypedData */]) {
|
|
807
|
-
console.error(
|
|
808
|
-
"'signTypedData' command is unavailable. Check MiniKit.install() or update the app version"
|
|
809
|
-
);
|
|
810
|
-
return null;
|
|
811
|
-
}
|
|
812
|
-
if (!payload.chainId) {
|
|
813
|
-
payload.chainId = 480;
|
|
814
|
-
}
|
|
815
|
-
sendMiniKitEvent({
|
|
816
|
-
command: "sign-typed-data" /* SignTypedData */,
|
|
817
|
-
version: _MiniKit.miniKitCommandVersion["sign-typed-data" /* SignTypedData */],
|
|
818
|
-
payload
|
|
833
|
+
};
|
|
834
|
+
}
|
|
835
|
+
function createWalletAuthAsyncCommand(ctx, syncCommand) {
|
|
836
|
+
return async (payload) => {
|
|
837
|
+
return new Promise((resolve, reject) => {
|
|
838
|
+
try {
|
|
839
|
+
let commandPayload = null;
|
|
840
|
+
const handleResponse = async (response) => {
|
|
841
|
+
ctx.events.unsubscribe("miniapp-wallet-auth" /* MiniAppWalletAuth */);
|
|
842
|
+
if (response.status === "success") {
|
|
843
|
+
await ctx.state.updateUserFromWalletAuth(response.address);
|
|
844
|
+
}
|
|
845
|
+
resolve({ commandPayload, finalPayload: response });
|
|
846
|
+
};
|
|
847
|
+
ctx.events.subscribe(
|
|
848
|
+
"miniapp-wallet-auth" /* MiniAppWalletAuth */,
|
|
849
|
+
handleResponse
|
|
850
|
+
);
|
|
851
|
+
commandPayload = syncCommand(payload);
|
|
852
|
+
} catch (error) {
|
|
853
|
+
reject(error);
|
|
854
|
+
}
|
|
819
855
|
});
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
856
|
+
};
|
|
857
|
+
}
|
|
858
|
+
|
|
859
|
+
// commands/index.ts
|
|
860
|
+
function createCommands(ctx) {
|
|
861
|
+
return {
|
|
862
|
+
verify: createVerifyCommand(ctx),
|
|
863
|
+
pay: createPayCommand(ctx),
|
|
864
|
+
walletAuth: createWalletAuthCommand(ctx),
|
|
865
|
+
sendTransaction: createSendTransactionCommand(ctx),
|
|
866
|
+
signMessage: createSignMessageCommand(ctx),
|
|
867
|
+
signTypedData: createSignTypedDataCommand(ctx),
|
|
868
|
+
shareContacts: createShareContactsCommand(ctx),
|
|
869
|
+
requestPermission: createRequestPermissionCommand(ctx),
|
|
870
|
+
getPermissions: createGetPermissionsCommand(ctx),
|
|
871
|
+
sendHapticFeedback: createSendHapticFeedbackCommand(ctx),
|
|
872
|
+
share: createShareCommand(ctx),
|
|
873
|
+
chat: createChatCommand(ctx)
|
|
874
|
+
};
|
|
875
|
+
}
|
|
876
|
+
function createAsyncCommands(ctx, commands) {
|
|
877
|
+
return {
|
|
878
|
+
verify: createVerifyAsyncCommand(ctx, commands.verify),
|
|
879
|
+
pay: createPayAsyncCommand(ctx, commands.pay),
|
|
880
|
+
walletAuth: createWalletAuthAsyncCommand(ctx, commands.walletAuth),
|
|
881
|
+
sendTransaction: createSendTransactionAsyncCommand(
|
|
882
|
+
ctx,
|
|
883
|
+
commands.sendTransaction
|
|
884
|
+
),
|
|
885
|
+
signMessage: createSignMessageAsyncCommand(ctx, commands.signMessage),
|
|
886
|
+
signTypedData: createSignTypedDataAsyncCommand(ctx, commands.signTypedData),
|
|
887
|
+
shareContacts: createShareContactsAsyncCommand(ctx, commands.shareContacts),
|
|
888
|
+
requestPermission: createRequestPermissionAsyncCommand(
|
|
889
|
+
ctx,
|
|
890
|
+
commands.requestPermission
|
|
891
|
+
),
|
|
892
|
+
getPermissions: createGetPermissionsAsyncCommand(
|
|
893
|
+
ctx,
|
|
894
|
+
commands.getPermissions
|
|
895
|
+
),
|
|
896
|
+
sendHapticFeedback: createSendHapticFeedbackAsyncCommand(
|
|
897
|
+
ctx,
|
|
898
|
+
commands.sendHapticFeedback
|
|
899
|
+
),
|
|
900
|
+
share: createShareAsyncCommand(ctx, commands.share),
|
|
901
|
+
chat: createChatAsyncCommand(ctx, commands.chat)
|
|
902
|
+
};
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
// core/events.ts
|
|
906
|
+
var import_idkit_core3 = require("@worldcoin/idkit-core");
|
|
907
|
+
|
|
908
|
+
// helpers/proof/index.ts
|
|
909
|
+
var import_viem2 = require("viem");
|
|
910
|
+
var import_chains2 = require("viem/chains");
|
|
911
|
+
var semaphoreVerifierAddress = "0x79f46b94d134109EbcbbddBAeD0E88790409A0e4";
|
|
912
|
+
var semaphoreVerifierAbi = [
|
|
913
|
+
{
|
|
914
|
+
inputs: [
|
|
915
|
+
{
|
|
916
|
+
internalType: "uint256[8]",
|
|
917
|
+
name: "proof",
|
|
918
|
+
type: "uint256[8]"
|
|
919
|
+
}
|
|
920
|
+
],
|
|
921
|
+
name: "compressProof",
|
|
922
|
+
outputs: [
|
|
923
|
+
{
|
|
924
|
+
internalType: "uint256[4]",
|
|
925
|
+
name: "compressed",
|
|
926
|
+
type: "uint256[4]"
|
|
927
|
+
}
|
|
928
|
+
],
|
|
929
|
+
stateMutability: "view",
|
|
930
|
+
type: "function"
|
|
931
|
+
}
|
|
932
|
+
];
|
|
933
|
+
var compressAndPadProof = async (proof, rpcUrl) => {
|
|
934
|
+
try {
|
|
935
|
+
const publicClient = (0, import_viem2.createPublicClient)({
|
|
936
|
+
chain: import_chains2.worldchain,
|
|
937
|
+
transport: (0, import_viem2.http)(
|
|
938
|
+
rpcUrl || "https://worldchain-mainnet.g.alchemy.com/public"
|
|
939
|
+
)
|
|
847
940
|
});
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
sendMiniKitEvent({
|
|
858
|
-
command: "get-permissions" /* GetPermissions */,
|
|
859
|
-
version: _MiniKit.miniKitCommandVersion["get-permissions" /* GetPermissions */],
|
|
860
|
-
payload: {}
|
|
941
|
+
const decodedProof = (0, import_viem2.decodeAbiParameters)(
|
|
942
|
+
[{ type: "uint256[8]" }],
|
|
943
|
+
proof
|
|
944
|
+
)[0];
|
|
945
|
+
const compressedProof = await publicClient.readContract({
|
|
946
|
+
address: semaphoreVerifierAddress,
|
|
947
|
+
abi: semaphoreVerifierAbi,
|
|
948
|
+
functionName: "compressProof",
|
|
949
|
+
args: [decodedProof]
|
|
861
950
|
});
|
|
862
|
-
|
|
863
|
-
|
|
951
|
+
const paddedProof = [...compressedProof, 0n, 0n, 0n, 0n];
|
|
952
|
+
return (0, import_viem2.encodeAbiParameters)([{ type: "uint256[8]" }], [paddedProof]);
|
|
953
|
+
} catch (e) {
|
|
954
|
+
return proof;
|
|
955
|
+
}
|
|
956
|
+
};
|
|
957
|
+
|
|
958
|
+
// core/events.ts
|
|
959
|
+
var EventManager = class {
|
|
960
|
+
constructor() {
|
|
961
|
+
this.listeners = {
|
|
962
|
+
["miniapp-verify-action" /* MiniAppVerifyAction */]: () => {
|
|
963
|
+
},
|
|
964
|
+
["miniapp-payment" /* MiniAppPayment */]: () => {
|
|
965
|
+
},
|
|
966
|
+
["miniapp-wallet-auth" /* MiniAppWalletAuth */]: () => {
|
|
967
|
+
},
|
|
968
|
+
["miniapp-send-transaction" /* MiniAppSendTransaction */]: () => {
|
|
969
|
+
},
|
|
970
|
+
["miniapp-sign-message" /* MiniAppSignMessage */]: () => {
|
|
971
|
+
},
|
|
972
|
+
["miniapp-sign-typed-data" /* MiniAppSignTypedData */]: () => {
|
|
973
|
+
},
|
|
974
|
+
["miniapp-share-contacts" /* MiniAppShareContacts */]: () => {
|
|
975
|
+
},
|
|
976
|
+
["miniapp-request-permission" /* MiniAppRequestPermission */]: () => {
|
|
977
|
+
},
|
|
978
|
+
["miniapp-get-permissions" /* MiniAppGetPermissions */]: () => {
|
|
979
|
+
},
|
|
980
|
+
["miniapp-send-haptic-feedback" /* MiniAppSendHapticFeedback */]: () => {
|
|
981
|
+
},
|
|
982
|
+
["miniapp-share" /* MiniAppShare */]: () => {
|
|
983
|
+
},
|
|
984
|
+
["miniapp-microphone" /* MiniAppMicrophone */]: () => {
|
|
985
|
+
},
|
|
986
|
+
["miniapp-chat" /* MiniAppChat */]: () => {
|
|
987
|
+
}
|
|
864
988
|
};
|
|
865
|
-
}
|
|
866
|
-
|
|
867
|
-
|
|
989
|
+
}
|
|
990
|
+
subscribe(event, handler) {
|
|
991
|
+
this.listeners[event] = handler;
|
|
992
|
+
}
|
|
993
|
+
unsubscribe(event) {
|
|
994
|
+
delete this.listeners[event];
|
|
995
|
+
}
|
|
996
|
+
trigger(event, payload) {
|
|
997
|
+
if (!this.listeners[event]) {
|
|
868
998
|
console.error(
|
|
869
|
-
|
|
999
|
+
`No handler for event ${event}, payload: ${JSON.stringify(payload)}`
|
|
870
1000
|
);
|
|
871
|
-
return
|
|
1001
|
+
return;
|
|
872
1002
|
}
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
},
|
|
880
|
-
// We return share input here because the payload is formatted asynchronously
|
|
881
|
-
share: (payload) => {
|
|
882
|
-
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["share" /* Share */]) {
|
|
883
|
-
console.error(
|
|
884
|
-
"'share' command is unavailable. Check MiniKit.install() or update the app version"
|
|
1003
|
+
if (event === "miniapp-verify-action" /* MiniAppVerifyAction */) {
|
|
1004
|
+
const handler = this.listeners[event];
|
|
1005
|
+
this.unsubscribe(event);
|
|
1006
|
+
this.processVerifyActionPayload(
|
|
1007
|
+
payload,
|
|
1008
|
+
handler
|
|
885
1009
|
);
|
|
886
|
-
return
|
|
887
|
-
}
|
|
888
|
-
if (_MiniKit.deviceProperties.deviceOS === "ios" && typeof navigator !== "undefined") {
|
|
889
|
-
sendMiniKitEvent({
|
|
890
|
-
command: "share" /* Share */,
|
|
891
|
-
version: _MiniKit.miniKitCommandVersion["share" /* Share */],
|
|
892
|
-
payload
|
|
893
|
-
});
|
|
894
|
-
navigator.share(payload);
|
|
895
|
-
} else {
|
|
896
|
-
formatShareInput(payload).then((formattedResult) => {
|
|
897
|
-
sendMiniKitEvent({
|
|
898
|
-
command: "share" /* Share */,
|
|
899
|
-
version: _MiniKit.miniKitCommandVersion["share" /* Share */],
|
|
900
|
-
payload: formattedResult
|
|
901
|
-
});
|
|
902
|
-
}).catch((error) => {
|
|
903
|
-
console.error("Failed to format share input", error);
|
|
904
|
-
});
|
|
905
|
-
_MiniKit.subscribe("miniapp-share" /* MiniAppShare */, (payload2) => {
|
|
906
|
-
console.log("Share Response", payload2);
|
|
907
|
-
});
|
|
1010
|
+
return;
|
|
908
1011
|
}
|
|
909
|
-
|
|
1012
|
+
this.listeners[event](payload);
|
|
910
1013
|
}
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
*
|
|
920
|
-
* finalPayload - object returned by the event listener, or in other words, WorldApp response
|
|
921
|
-
*/
|
|
922
|
-
_MiniKit.commandsAsync = {
|
|
923
|
-
verify: async (payload) => {
|
|
924
|
-
return new Promise(async (resolve, reject) => {
|
|
925
|
-
try {
|
|
926
|
-
const response = await _MiniKit.awaitCommand(
|
|
927
|
-
"miniapp-verify-action" /* MiniAppVerifyAction */,
|
|
928
|
-
"verify" /* Verify */,
|
|
929
|
-
() => _MiniKit.commands.verify(payload)
|
|
1014
|
+
async processVerifyActionPayload(payload, handler) {
|
|
1015
|
+
if (payload.status === "error" && payload.error_code === "user_rejected") {
|
|
1016
|
+
payload.error_code = import_idkit_core3.AppErrorCodes.VerificationRejected;
|
|
1017
|
+
}
|
|
1018
|
+
if (payload.status === "success") {
|
|
1019
|
+
if ("verifications" in payload) {
|
|
1020
|
+
const orbVerification = payload.verifications.find(
|
|
1021
|
+
(v) => v.verification_level === import_idkit_core3.VerificationLevel.Orb
|
|
930
1022
|
);
|
|
931
|
-
if (
|
|
932
|
-
|
|
933
|
-
|
|
1023
|
+
if (orbVerification) {
|
|
1024
|
+
orbVerification.proof = await this.compressProofSafely(
|
|
1025
|
+
orbVerification.proof,
|
|
1026
|
+
{
|
|
1027
|
+
mode: "multi",
|
|
1028
|
+
payloadVersion: payload.version,
|
|
1029
|
+
verificationsCount: payload.verifications.length,
|
|
1030
|
+
verificationLevel: orbVerification.verification_level
|
|
1031
|
+
}
|
|
934
1032
|
);
|
|
935
1033
|
}
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
try {
|
|
945
|
-
const response = await _MiniKit.awaitCommand(
|
|
946
|
-
"miniapp-payment" /* MiniAppPayment */,
|
|
947
|
-
"pay" /* Pay */,
|
|
948
|
-
() => _MiniKit.commands.pay(payload)
|
|
949
|
-
);
|
|
950
|
-
resolve(response);
|
|
951
|
-
} catch (error) {
|
|
952
|
-
reject(error);
|
|
953
|
-
}
|
|
954
|
-
});
|
|
955
|
-
},
|
|
956
|
-
walletAuth: async (payload) => {
|
|
957
|
-
return new Promise(async (resolve, reject) => {
|
|
958
|
-
try {
|
|
959
|
-
const response = await _MiniKit.awaitCommand(
|
|
960
|
-
"miniapp-wallet-auth" /* MiniAppWalletAuth */,
|
|
961
|
-
"wallet-auth" /* WalletAuth */,
|
|
962
|
-
() => _MiniKit.commands.walletAuth(payload)
|
|
963
|
-
);
|
|
964
|
-
return resolve(response);
|
|
965
|
-
} catch (error) {
|
|
966
|
-
reject(error);
|
|
967
|
-
}
|
|
968
|
-
});
|
|
969
|
-
},
|
|
970
|
-
sendTransaction: async (payload) => {
|
|
971
|
-
return new Promise(async (resolve, reject) => {
|
|
972
|
-
try {
|
|
973
|
-
const response = await _MiniKit.awaitCommand(
|
|
974
|
-
"miniapp-send-transaction" /* MiniAppSendTransaction */,
|
|
975
|
-
"send-transaction" /* SendTransaction */,
|
|
976
|
-
() => _MiniKit.commands.sendTransaction(payload)
|
|
977
|
-
);
|
|
978
|
-
return resolve(response);
|
|
979
|
-
} catch (error) {
|
|
980
|
-
reject(error);
|
|
981
|
-
}
|
|
982
|
-
});
|
|
983
|
-
},
|
|
984
|
-
signMessage: async (payload) => {
|
|
985
|
-
return new Promise(async (resolve, reject) => {
|
|
986
|
-
try {
|
|
987
|
-
const response = await _MiniKit.awaitCommand(
|
|
988
|
-
"miniapp-sign-message" /* MiniAppSignMessage */,
|
|
989
|
-
"sign-message" /* SignMessage */,
|
|
990
|
-
() => _MiniKit.commands.signMessage(payload)
|
|
991
|
-
);
|
|
992
|
-
return resolve(response);
|
|
993
|
-
} catch (error) {
|
|
994
|
-
reject(error);
|
|
995
|
-
}
|
|
996
|
-
});
|
|
997
|
-
},
|
|
998
|
-
signTypedData: async (payload) => {
|
|
999
|
-
return new Promise(async (resolve, reject) => {
|
|
1000
|
-
try {
|
|
1001
|
-
const response = await _MiniKit.awaitCommand(
|
|
1002
|
-
"miniapp-sign-typed-data" /* MiniAppSignTypedData */,
|
|
1003
|
-
"sign-typed-data" /* SignTypedData */,
|
|
1004
|
-
() => _MiniKit.commands.signTypedData(payload)
|
|
1005
|
-
);
|
|
1006
|
-
return resolve(response);
|
|
1007
|
-
} catch (error) {
|
|
1008
|
-
reject(error);
|
|
1009
|
-
}
|
|
1010
|
-
});
|
|
1011
|
-
},
|
|
1012
|
-
shareContacts: async (payload) => {
|
|
1013
|
-
return new Promise(async (resolve, reject) => {
|
|
1014
|
-
try {
|
|
1015
|
-
const response = await _MiniKit.awaitCommand(
|
|
1016
|
-
"miniapp-share-contacts" /* MiniAppShareContacts */,
|
|
1017
|
-
"share-contacts" /* ShareContacts */,
|
|
1018
|
-
() => _MiniKit.commands.shareContacts(payload)
|
|
1019
|
-
);
|
|
1020
|
-
return resolve(response);
|
|
1021
|
-
} catch (error) {
|
|
1022
|
-
reject(error);
|
|
1023
|
-
}
|
|
1024
|
-
});
|
|
1025
|
-
},
|
|
1026
|
-
requestPermission: async (payload) => {
|
|
1027
|
-
return new Promise(async (resolve, reject) => {
|
|
1028
|
-
try {
|
|
1029
|
-
const response = await _MiniKit.awaitCommand(
|
|
1030
|
-
"miniapp-request-permission" /* MiniAppRequestPermission */,
|
|
1031
|
-
"request-permission" /* RequestPermission */,
|
|
1032
|
-
() => _MiniKit.commands.requestPermission(payload)
|
|
1034
|
+
} else if (payload.verification_level === import_idkit_core3.VerificationLevel.Orb) {
|
|
1035
|
+
payload.proof = await this.compressProofSafely(
|
|
1036
|
+
payload.proof,
|
|
1037
|
+
{
|
|
1038
|
+
mode: "single",
|
|
1039
|
+
payloadVersion: payload.version,
|
|
1040
|
+
verificationLevel: payload.verification_level
|
|
1041
|
+
}
|
|
1033
1042
|
);
|
|
1034
|
-
resolve(response);
|
|
1035
|
-
} catch (error) {
|
|
1036
|
-
reject(error);
|
|
1037
1043
|
}
|
|
1038
|
-
}
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1044
|
+
}
|
|
1045
|
+
handler(payload);
|
|
1046
|
+
}
|
|
1047
|
+
async compressProofSafely(proof, context) {
|
|
1048
|
+
try {
|
|
1049
|
+
return await compressAndPadProof(proof);
|
|
1050
|
+
} catch (error) {
|
|
1051
|
+
console.error(
|
|
1052
|
+
"Failed to compress verification proof. Delivering payload with uncompressed proof.",
|
|
1053
|
+
{
|
|
1054
|
+
...context,
|
|
1055
|
+
error
|
|
1056
|
+
}
|
|
1057
|
+
);
|
|
1058
|
+
return proof;
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
};
|
|
1062
|
+
|
|
1063
|
+
// helpers/usernames/index.ts
|
|
1064
|
+
var getUserProfile = async (address) => {
|
|
1065
|
+
const res = await fetch("https://usernames.worldcoin.org/api/v1/query", {
|
|
1066
|
+
method: "POST",
|
|
1067
|
+
headers: {
|
|
1068
|
+
"Content-Type": "application/json"
|
|
1069
|
+
},
|
|
1070
|
+
body: JSON.stringify({
|
|
1071
|
+
addresses: [address]
|
|
1072
|
+
})
|
|
1073
|
+
});
|
|
1074
|
+
const usernames = await res.json();
|
|
1075
|
+
return usernames?.[0] ?? { username: null, profile_picture_url: null };
|
|
1076
|
+
};
|
|
1077
|
+
|
|
1078
|
+
// types/init.ts
|
|
1079
|
+
var WORLD_APP_LAUNCH_LOCATION_MAP = {
|
|
1080
|
+
"app-store": "app-store" /* AppStore */,
|
|
1081
|
+
carousel: "app-store" /* AppStore */,
|
|
1082
|
+
explore: "app-store" /* AppStore */,
|
|
1083
|
+
app_details: "app-store" /* AppStore */,
|
|
1084
|
+
deeplink: "deep-link" /* DeepLink */,
|
|
1085
|
+
homepage: "home" /* Home */,
|
|
1086
|
+
wallet_tab: "wallet-tab" /* WalletTab */,
|
|
1087
|
+
world_chat: "chat" /* Chat */
|
|
1088
|
+
};
|
|
1089
|
+
var mapWorldAppLaunchLocation = (location) => {
|
|
1090
|
+
if (!location || typeof location !== "string") return null;
|
|
1091
|
+
console.log("MiniKit launch location mapped:", location);
|
|
1092
|
+
const normalizedLocation = location.toLowerCase();
|
|
1093
|
+
return WORLD_APP_LAUNCH_LOCATION_MAP[normalizedLocation] ?? null;
|
|
1094
|
+
};
|
|
1095
|
+
|
|
1096
|
+
// core/state.ts
|
|
1097
|
+
var MiniKitState = class {
|
|
1098
|
+
constructor() {
|
|
1099
|
+
this.appId = null;
|
|
1100
|
+
this.user = {};
|
|
1101
|
+
this.deviceProperties = {};
|
|
1102
|
+
this.location = null;
|
|
1103
|
+
this.isReady = false;
|
|
1104
|
+
}
|
|
1105
|
+
initFromWorldApp(worldApp) {
|
|
1106
|
+
if (!worldApp) return;
|
|
1107
|
+
this.user.optedIntoOptionalAnalytics = worldApp.is_optional_analytics;
|
|
1108
|
+
this.user.deviceOS = worldApp.device_os;
|
|
1109
|
+
this.user.worldAppVersion = worldApp.world_app_version;
|
|
1110
|
+
this.deviceProperties.safeAreaInsets = worldApp.safe_area_insets;
|
|
1111
|
+
this.deviceProperties.deviceOS = worldApp.device_os;
|
|
1112
|
+
this.deviceProperties.worldAppVersion = worldApp.world_app_version;
|
|
1113
|
+
this.location = mapWorldAppLaunchLocation(worldApp.location);
|
|
1114
|
+
}
|
|
1115
|
+
async updateUserFromWalletAuth(address) {
|
|
1116
|
+
this.user.walletAddress = address;
|
|
1117
|
+
try {
|
|
1118
|
+
const userProfile = await getUserProfile(address);
|
|
1119
|
+
this.user.username = userProfile.username;
|
|
1120
|
+
this.user.profilePictureUrl = userProfile.profile_picture_url;
|
|
1121
|
+
} catch (error) {
|
|
1122
|
+
console.error("Failed to fetch user profile:", error);
|
|
1123
|
+
}
|
|
1124
|
+
}
|
|
1125
|
+
async getUserByAddress(address) {
|
|
1126
|
+
const walletAddress = address ?? this.user.walletAddress;
|
|
1127
|
+
const userProfile = await getUserProfile(walletAddress);
|
|
1128
|
+
return {
|
|
1129
|
+
walletAddress,
|
|
1130
|
+
username: userProfile.username,
|
|
1131
|
+
profilePictureUrl: userProfile.profile_picture_url
|
|
1132
|
+
};
|
|
1133
|
+
}
|
|
1134
|
+
async getUserByUsername(username) {
|
|
1135
|
+
const res = await fetch(
|
|
1136
|
+
`https://usernames.worldcoin.org/api/v1/${username}`,
|
|
1137
|
+
{
|
|
1138
|
+
method: "GET",
|
|
1139
|
+
headers: {
|
|
1140
|
+
"Content-Type": "application/json"
|
|
1141
|
+
}
|
|
1051
1142
|
}
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1143
|
+
);
|
|
1144
|
+
const user = await res.json();
|
|
1145
|
+
return {
|
|
1146
|
+
walletAddress: user.address,
|
|
1147
|
+
username: user.username,
|
|
1148
|
+
profilePictureUrl: user.profile_picture_url
|
|
1149
|
+
};
|
|
1150
|
+
}
|
|
1151
|
+
};
|
|
1152
|
+
|
|
1153
|
+
// types/errors.ts
|
|
1154
|
+
var import_idkit_core4 = require("@worldcoin/idkit-core");
|
|
1155
|
+
var import_idkit_core5 = require("@worldcoin/idkit-core");
|
|
1156
|
+
var VerificationErrorMessage = {
|
|
1157
|
+
[import_idkit_core4.AppErrorCodes.VerificationRejected]: "You've cancelled the request in World App.",
|
|
1158
|
+
[import_idkit_core4.AppErrorCodes.MaxVerificationsReached]: "You have already verified the maximum number of times for this action.",
|
|
1159
|
+
[import_idkit_core4.AppErrorCodes.CredentialUnavailable]: "It seems you do not have the verification level required by this app.",
|
|
1160
|
+
[import_idkit_core4.AppErrorCodes.MalformedRequest]: "There was a problem with this request. Please try again or contact the app owner.",
|
|
1161
|
+
[import_idkit_core4.AppErrorCodes.InvalidNetwork]: "Invalid network. If you are the app owner, visit docs.worldcoin.org/test for details.",
|
|
1162
|
+
[import_idkit_core4.AppErrorCodes.InclusionProofFailed]: "There was an issue fetching your credential. Please try again.",
|
|
1163
|
+
[import_idkit_core4.AppErrorCodes.InclusionProofPending]: "Your identity is still being registered. Please wait a few minutes and try again.",
|
|
1164
|
+
[import_idkit_core4.AppErrorCodes.UnexpectedResponse]: "Unexpected response from your wallet. Please try again.",
|
|
1165
|
+
[import_idkit_core4.AppErrorCodes.FailedByHostApp]: "Verification failed by the app. Please contact the app owner for details.",
|
|
1166
|
+
[import_idkit_core4.AppErrorCodes.GenericError]: "Something unexpected went wrong. Please try again.",
|
|
1167
|
+
[import_idkit_core4.AppErrorCodes.ConnectionFailed]: "Connection to your wallet failed. Please try again."
|
|
1168
|
+
};
|
|
1169
|
+
var MiniKitInstallErrorMessage = {
|
|
1170
|
+
["unknown" /* Unknown */]: "Failed to install MiniKit.",
|
|
1171
|
+
["already_installed" /* AlreadyInstalled */]: "MiniKit is already installed.",
|
|
1172
|
+
["outside_of_worldapp" /* OutsideOfWorldApp */]: "MiniApp launched outside of WorldApp.",
|
|
1173
|
+
["not_on_client" /* NotOnClient */]: "Window object is not available.",
|
|
1174
|
+
["app_out_of_date" /* AppOutOfDate */]: "WorldApp is out of date. Please update the app."
|
|
1175
|
+
};
|
|
1176
|
+
|
|
1177
|
+
// helpers/microphone/index.ts
|
|
1178
|
+
var microphoneSetupDone = false;
|
|
1179
|
+
var setupMicrophone = () => {
|
|
1180
|
+
if (microphoneSetupDone) {
|
|
1181
|
+
return;
|
|
1182
|
+
}
|
|
1183
|
+
if (typeof navigator !== "undefined" && !navigator.mediaDevices?.getUserMedia)
|
|
1184
|
+
return;
|
|
1185
|
+
const originalStop = MediaStreamTrack.prototype.stop;
|
|
1186
|
+
MediaStreamTrack.prototype.stop = function() {
|
|
1187
|
+
originalStop.call(this);
|
|
1188
|
+
if (this.readyState === "ended") {
|
|
1189
|
+
setTimeout(() => this.dispatchEvent(new Event("ended")), 0);
|
|
1190
|
+
}
|
|
1191
|
+
};
|
|
1192
|
+
const realGUM = navigator.mediaDevices.getUserMedia.bind(
|
|
1193
|
+
navigator.mediaDevices
|
|
1194
|
+
);
|
|
1195
|
+
const live = /* @__PURE__ */ new Set();
|
|
1196
|
+
async function wrapped(constraints) {
|
|
1197
|
+
const stream = await realGUM(constraints);
|
|
1198
|
+
const hasAudioTrack = stream.getAudioTracks().length > 0;
|
|
1199
|
+
if (hasAudioTrack) {
|
|
1200
|
+
sendWebviewEvent({
|
|
1201
|
+
command: "microphone-stream-started",
|
|
1202
|
+
version: 1,
|
|
1203
|
+
payload: {
|
|
1204
|
+
streamId: stream.id
|
|
1205
|
+
}
|
|
1206
|
+
});
|
|
1207
|
+
live.add(stream);
|
|
1208
|
+
stream.getAudioTracks().forEach((t) => {
|
|
1209
|
+
t.addEventListener("ended", () => {
|
|
1210
|
+
const allAudioTracksEnded = stream.getAudioTracks().every((track) => track.readyState === "ended");
|
|
1211
|
+
if (allAudioTracksEnded) {
|
|
1212
|
+
sendWebviewEvent({
|
|
1213
|
+
command: "microphone-stream-ended",
|
|
1214
|
+
version: 1,
|
|
1215
|
+
payload: {
|
|
1216
|
+
streamId: stream.id
|
|
1217
|
+
}
|
|
1218
|
+
});
|
|
1219
|
+
live.delete(stream);
|
|
1220
|
+
}
|
|
1221
|
+
});
|
|
1222
|
+
});
|
|
1223
|
+
}
|
|
1224
|
+
return stream;
|
|
1225
|
+
}
|
|
1226
|
+
Object.defineProperty(navigator.mediaDevices, "getUserMedia", {
|
|
1227
|
+
value: wrapped,
|
|
1228
|
+
writable: false,
|
|
1229
|
+
configurable: false,
|
|
1230
|
+
enumerable: true
|
|
1231
|
+
});
|
|
1232
|
+
Object.freeze(navigator.mediaDevices);
|
|
1233
|
+
const stopAllMiniAppMicrophoneStreams = () => {
|
|
1234
|
+
live.forEach((s) => {
|
|
1235
|
+
const audioTracks = s.getAudioTracks();
|
|
1236
|
+
if (audioTracks.length > 0) {
|
|
1237
|
+
audioTracks.forEach((t) => {
|
|
1238
|
+
t.stop();
|
|
1239
|
+
});
|
|
1240
|
+
sendWebviewEvent({
|
|
1241
|
+
command: "microphone-stream-ended",
|
|
1242
|
+
version: 1,
|
|
1243
|
+
payload: {
|
|
1244
|
+
streamId: s.id
|
|
1245
|
+
}
|
|
1246
|
+
});
|
|
1065
1247
|
}
|
|
1066
1248
|
});
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1249
|
+
live.clear();
|
|
1250
|
+
};
|
|
1251
|
+
MiniKit.subscribe("miniapp-microphone" /* MiniAppMicrophone */, (payload) => {
|
|
1252
|
+
if (payload.status === "error" && (payload.error_code === "mini_app_permission_not_enabled" /* MiniAppPermissionNotEnabled */ || payload.error_code === "world_app_permission_not_enabled" /* WorldAppPermissionNotEnabled */)) {
|
|
1253
|
+
console.log("stopping all microphone streams", payload);
|
|
1254
|
+
stopAllMiniAppMicrophoneStreams();
|
|
1255
|
+
}
|
|
1256
|
+
});
|
|
1257
|
+
window.__stopAllMiniAppMicrophoneStreams = stopAllMiniAppMicrophoneStreams;
|
|
1258
|
+
microphoneSetupDone = true;
|
|
1259
|
+
};
|
|
1260
|
+
|
|
1261
|
+
// minikit.ts
|
|
1262
|
+
var MINIKIT_VERSION = 1;
|
|
1263
|
+
var MINIKIT_MINOR_VERSION = 96;
|
|
1264
|
+
var _MiniKit = class _MiniKit {
|
|
1265
|
+
// ============================================================================
|
|
1266
|
+
// Public State Accessors
|
|
1267
|
+
// ============================================================================
|
|
1268
|
+
static get appId() {
|
|
1269
|
+
return this.stateManager.appId;
|
|
1270
|
+
}
|
|
1271
|
+
static set appId(value) {
|
|
1272
|
+
this.stateManager.appId = value;
|
|
1273
|
+
}
|
|
1274
|
+
static get user() {
|
|
1275
|
+
return this.stateManager.user;
|
|
1276
|
+
}
|
|
1277
|
+
static set user(value) {
|
|
1278
|
+
this.stateManager.user = value;
|
|
1279
|
+
}
|
|
1280
|
+
static get deviceProperties() {
|
|
1281
|
+
return this.stateManager.deviceProperties;
|
|
1282
|
+
}
|
|
1283
|
+
static get location() {
|
|
1284
|
+
return this.stateManager.location;
|
|
1285
|
+
}
|
|
1286
|
+
// ============================================================================
|
|
1287
|
+
// Event System
|
|
1288
|
+
// ============================================================================
|
|
1289
|
+
static subscribe(event, handler) {
|
|
1290
|
+
if (event === "miniapp-wallet-auth" /* MiniAppWalletAuth */) {
|
|
1291
|
+
const originalHandler = handler;
|
|
1292
|
+
const wrappedHandler = async (payload) => {
|
|
1293
|
+
if (payload.status === "success") {
|
|
1294
|
+
await this.stateManager.updateUserFromWalletAuth(payload.address);
|
|
1295
|
+
}
|
|
1296
|
+
originalHandler(payload);
|
|
1297
|
+
};
|
|
1298
|
+
this.eventManager.subscribe(event, wrappedHandler);
|
|
1299
|
+
} else {
|
|
1300
|
+
this.eventManager.subscribe(event, handler);
|
|
1301
|
+
}
|
|
1302
|
+
}
|
|
1303
|
+
static unsubscribe(event) {
|
|
1304
|
+
this.eventManager.unsubscribe(event);
|
|
1305
|
+
}
|
|
1306
|
+
static trigger(event, payload) {
|
|
1307
|
+
this.eventManager.trigger(event, payload);
|
|
1308
|
+
}
|
|
1309
|
+
// ============================================================================
|
|
1310
|
+
// Installation
|
|
1311
|
+
// ============================================================================
|
|
1312
|
+
static sendInit() {
|
|
1313
|
+
sendWebviewEvent({
|
|
1314
|
+
command: "init",
|
|
1315
|
+
payload: {
|
|
1316
|
+
version: MINIKIT_VERSION,
|
|
1317
|
+
minorVersion: MINIKIT_MINOR_VERSION
|
|
1082
1318
|
}
|
|
1083
1319
|
});
|
|
1084
1320
|
}
|
|
1321
|
+
static install(appId) {
|
|
1322
|
+
if (typeof window === "undefined" || Boolean(window.MiniKit)) {
|
|
1323
|
+
return {
|
|
1324
|
+
success: false,
|
|
1325
|
+
errorCode: "already_installed" /* AlreadyInstalled */,
|
|
1326
|
+
errorMessage: MiniKitInstallErrorMessage["already_installed" /* AlreadyInstalled */]
|
|
1327
|
+
};
|
|
1328
|
+
}
|
|
1329
|
+
if (!appId) {
|
|
1330
|
+
console.warn("App ID not provided during install");
|
|
1331
|
+
} else {
|
|
1332
|
+
this.stateManager.appId = appId;
|
|
1333
|
+
}
|
|
1334
|
+
if (!window.WorldApp) {
|
|
1335
|
+
return {
|
|
1336
|
+
success: false,
|
|
1337
|
+
errorCode: "outside_of_worldapp" /* OutsideOfWorldApp */,
|
|
1338
|
+
errorMessage: MiniKitInstallErrorMessage["outside_of_worldapp" /* OutsideOfWorldApp */]
|
|
1339
|
+
};
|
|
1340
|
+
}
|
|
1341
|
+
this.stateManager.initFromWorldApp(window.WorldApp);
|
|
1342
|
+
try {
|
|
1343
|
+
window.MiniKit = _MiniKit;
|
|
1344
|
+
this.sendInit();
|
|
1345
|
+
} catch (error) {
|
|
1346
|
+
console.error(
|
|
1347
|
+
MiniKitInstallErrorMessage["unknown" /* Unknown */],
|
|
1348
|
+
error
|
|
1349
|
+
);
|
|
1350
|
+
return {
|
|
1351
|
+
success: false,
|
|
1352
|
+
errorCode: "unknown" /* Unknown */,
|
|
1353
|
+
errorMessage: MiniKitInstallErrorMessage["unknown" /* Unknown */]
|
|
1354
|
+
};
|
|
1355
|
+
}
|
|
1356
|
+
this.stateManager.isReady = true;
|
|
1357
|
+
setupMicrophone();
|
|
1358
|
+
if (!validateCommands(window.WorldApp.supported_commands)) {
|
|
1359
|
+
return {
|
|
1360
|
+
success: false,
|
|
1361
|
+
errorCode: "app_out_of_date" /* AppOutOfDate */,
|
|
1362
|
+
errorMessage: MiniKitInstallErrorMessage["app_out_of_date" /* AppOutOfDate */]
|
|
1363
|
+
};
|
|
1364
|
+
}
|
|
1365
|
+
return { success: true };
|
|
1366
|
+
}
|
|
1367
|
+
static isInstalled(debug) {
|
|
1368
|
+
const isInstalled = this.stateManager.isReady && Boolean(window.MiniKit);
|
|
1369
|
+
if (!isInstalled) {
|
|
1370
|
+
console.error(
|
|
1371
|
+
"MiniKit is not installed. Make sure you're running the application inside of World App"
|
|
1372
|
+
);
|
|
1373
|
+
}
|
|
1374
|
+
if (debug && isInstalled) {
|
|
1375
|
+
console.log("MiniKit is alive!");
|
|
1376
|
+
}
|
|
1377
|
+
return isInstalled;
|
|
1378
|
+
}
|
|
1379
|
+
// ============================================================================
|
|
1380
|
+
// Commands
|
|
1381
|
+
// ============================================================================
|
|
1382
|
+
static getContext() {
|
|
1383
|
+
return {
|
|
1384
|
+
events: this.eventManager,
|
|
1385
|
+
state: this.stateManager
|
|
1386
|
+
};
|
|
1387
|
+
}
|
|
1388
|
+
static get commands() {
|
|
1389
|
+
if (!this.commandsInstance) {
|
|
1390
|
+
this.commandsInstance = createCommands(this.getContext());
|
|
1391
|
+
}
|
|
1392
|
+
return this.commandsInstance;
|
|
1393
|
+
}
|
|
1394
|
+
static get commandsAsync() {
|
|
1395
|
+
if (!this.asyncCommandsInstance) {
|
|
1396
|
+
this.asyncCommandsInstance = createAsyncCommands(
|
|
1397
|
+
this.getContext(),
|
|
1398
|
+
this.commands
|
|
1399
|
+
);
|
|
1400
|
+
}
|
|
1401
|
+
return this.asyncCommandsInstance;
|
|
1402
|
+
}
|
|
1403
|
+
};
|
|
1404
|
+
_MiniKit.eventManager = new EventManager();
|
|
1405
|
+
_MiniKit.stateManager = new MiniKitState();
|
|
1406
|
+
_MiniKit.commandsInstance = null;
|
|
1407
|
+
_MiniKit.asyncCommandsInstance = null;
|
|
1408
|
+
// ============================================================================
|
|
1409
|
+
// Utility Methods
|
|
1410
|
+
// ============================================================================
|
|
1411
|
+
_MiniKit.getUserByAddress = async (address) => {
|
|
1412
|
+
return _MiniKit.stateManager.getUserByAddress(address);
|
|
1413
|
+
};
|
|
1414
|
+
_MiniKit.getUserByUsername = async (username) => {
|
|
1415
|
+
return _MiniKit.stateManager.getUserByUsername(username);
|
|
1416
|
+
};
|
|
1417
|
+
_MiniKit.getUserInfo = _MiniKit.getUserByAddress;
|
|
1418
|
+
_MiniKit.getMiniAppUrl = (appId, path) => {
|
|
1419
|
+
const baseUrl = new URL("https://world.org/mini-app");
|
|
1420
|
+
baseUrl.searchParams.append("app_id", appId);
|
|
1421
|
+
if (path) {
|
|
1422
|
+
const fullPath = path.startsWith("/") ? path : `/${path}`;
|
|
1423
|
+
baseUrl.searchParams.append("path", encodeURIComponent(fullPath));
|
|
1424
|
+
}
|
|
1425
|
+
return baseUrl.toString();
|
|
1426
|
+
};
|
|
1427
|
+
_MiniKit.showProfileCard = (username, walletAddress) => {
|
|
1428
|
+
if (!username && !walletAddress) {
|
|
1429
|
+
console.error(
|
|
1430
|
+
"Either username or walletAddress must be provided to show profile card"
|
|
1431
|
+
);
|
|
1432
|
+
return;
|
|
1433
|
+
}
|
|
1434
|
+
if (username) {
|
|
1435
|
+
window.open(
|
|
1436
|
+
`worldapp://profile?username=${encodeURIComponent(username)}`
|
|
1437
|
+
);
|
|
1438
|
+
} else {
|
|
1439
|
+
window.open(
|
|
1440
|
+
`worldapp://profile?address=${encodeURIComponent(walletAddress || "")}`
|
|
1441
|
+
);
|
|
1442
|
+
}
|
|
1085
1443
|
};
|
|
1086
1444
|
var MiniKit = _MiniKit;
|
|
1087
1445
|
|