@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
|
@@ -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,67 +201,242 @@ var validatePaymentPayload = (payload) => {
|
|
|
166
201
|
return true;
|
|
167
202
|
};
|
|
168
203
|
|
|
169
|
-
//
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
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);
|
|
188
244
|
}
|
|
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
245
|
});
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
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
|
|
211
262
|
});
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
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);
|
|
282
|
+
}
|
|
283
|
+
});
|
|
284
|
+
};
|
|
285
|
+
}
|
|
218
286
|
|
|
219
|
-
//
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
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
|
|
300
|
+
});
|
|
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
|
+
}
|
|
324
|
+
|
|
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
|
|
430
|
+
var MAX_FILES = 10;
|
|
431
|
+
var MAX_TOTAL_SIZE_MB = 50;
|
|
432
|
+
var MAX_TOTAL_SIZE_BYTES = MAX_TOTAL_SIZE_MB * 1024 * 1024;
|
|
433
|
+
var processFile = async (file) => {
|
|
434
|
+
const buffer = await file.arrayBuffer();
|
|
435
|
+
const uint8Array = new Uint8Array(buffer);
|
|
436
|
+
let binaryString = "";
|
|
437
|
+
const K_CHUNK_SIZE = 32768;
|
|
438
|
+
for (let i = 0; i < uint8Array.length; i += K_CHUNK_SIZE) {
|
|
439
|
+
const chunk = uint8Array.subarray(
|
|
230
440
|
i,
|
|
231
441
|
Math.min(i + K_CHUNK_SIZE, uint8Array.length)
|
|
232
442
|
);
|
|
@@ -282,9 +492,252 @@ 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
|
+
ctx.events.setVerifyActionProcessingOptions({
|
|
687
|
+
skip_proof_compression: payload.skip_proof_compression
|
|
688
|
+
});
|
|
689
|
+
sendMiniKitEvent({
|
|
690
|
+
command: "verify" /* Verify */,
|
|
691
|
+
version: COMMAND_VERSIONS["verify" /* Verify */],
|
|
692
|
+
payload: eventPayload
|
|
693
|
+
});
|
|
694
|
+
return eventPayload;
|
|
695
|
+
};
|
|
696
|
+
}
|
|
697
|
+
function createVerifyAsyncCommand(ctx, syncCommand) {
|
|
698
|
+
let hasInFlightVerifyRequest = false;
|
|
699
|
+
return async (payload) => {
|
|
700
|
+
if (hasInFlightVerifyRequest) {
|
|
701
|
+
return Promise.reject(
|
|
702
|
+
new Error(
|
|
703
|
+
"A verify request is already in flight. Wait for the current request to complete before sending another."
|
|
704
|
+
)
|
|
705
|
+
);
|
|
706
|
+
}
|
|
707
|
+
return new Promise((resolve, reject) => {
|
|
708
|
+
try {
|
|
709
|
+
hasInFlightVerifyRequest = true;
|
|
710
|
+
let commandPayload = null;
|
|
711
|
+
const handleResponse = (response) => {
|
|
712
|
+
ctx.events.unsubscribe("miniapp-verify-action" /* MiniAppVerifyAction */);
|
|
713
|
+
hasInFlightVerifyRequest = false;
|
|
714
|
+
resolve({ commandPayload, finalPayload: response });
|
|
715
|
+
};
|
|
716
|
+
ctx.events.subscribe(
|
|
717
|
+
"miniapp-verify-action" /* MiniAppVerifyAction */,
|
|
718
|
+
handleResponse
|
|
719
|
+
);
|
|
720
|
+
commandPayload = syncCommand(payload);
|
|
721
|
+
if (commandPayload === null) {
|
|
722
|
+
ctx.events.unsubscribe("miniapp-verify-action" /* MiniAppVerifyAction */);
|
|
723
|
+
hasInFlightVerifyRequest = false;
|
|
724
|
+
reject(
|
|
725
|
+
new Error(
|
|
726
|
+
"Failed to send verify command. Ensure MiniKit is installed and the verify command is available."
|
|
727
|
+
)
|
|
728
|
+
);
|
|
729
|
+
}
|
|
730
|
+
} catch (error) {
|
|
731
|
+
hasInFlightVerifyRequest = false;
|
|
732
|
+
reject(error);
|
|
733
|
+
}
|
|
734
|
+
});
|
|
735
|
+
};
|
|
736
|
+
}
|
|
737
|
+
|
|
285
738
|
// helpers/siwe/siwe.ts
|
|
286
|
-
var
|
|
287
|
-
var
|
|
739
|
+
var import_viem = require("viem");
|
|
740
|
+
var import_chains = require("viem/chains");
|
|
288
741
|
var generateSiweMessage = (siweMessageData) => {
|
|
289
742
|
let siweMessage = "";
|
|
290
743
|
if (siweMessageData.scheme) {
|
|
@@ -354,68 +807,289 @@ var validateWalletAuthCommandInput = (params) => {
|
|
|
354
807
|
return { valid: true };
|
|
355
808
|
};
|
|
356
809
|
|
|
357
|
-
//
|
|
358
|
-
|
|
359
|
-
return
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
810
|
+
// commands/wallet-auth.ts
|
|
811
|
+
function createWalletAuthCommand(ctx) {
|
|
812
|
+
return (payload) => {
|
|
813
|
+
if (typeof window === "undefined" || !isCommandAvailable("wallet-auth" /* WalletAuth */)) {
|
|
814
|
+
console.error(
|
|
815
|
+
"'walletAuth' command is unavailable. Check MiniKit.install() or update the app version"
|
|
816
|
+
);
|
|
817
|
+
return null;
|
|
818
|
+
}
|
|
819
|
+
const validationResult = validateWalletAuthCommandInput(payload);
|
|
820
|
+
if (!validationResult.valid) {
|
|
821
|
+
console.error(
|
|
822
|
+
"Failed to validate wallet auth input:\n\n -->",
|
|
823
|
+
validationResult.message
|
|
824
|
+
);
|
|
825
|
+
return null;
|
|
826
|
+
}
|
|
827
|
+
let protocol = null;
|
|
828
|
+
try {
|
|
829
|
+
const currentUrl = new URL(window.location.href);
|
|
830
|
+
protocol = currentUrl.protocol.split(":")[0];
|
|
831
|
+
} catch (error) {
|
|
832
|
+
console.error("Failed to get current URL", error);
|
|
833
|
+
return null;
|
|
834
|
+
}
|
|
835
|
+
const siweMessage = generateSiweMessage({
|
|
836
|
+
scheme: protocol,
|
|
837
|
+
domain: window.location.host,
|
|
838
|
+
statement: payload.statement ?? void 0,
|
|
839
|
+
uri: window.location.href,
|
|
840
|
+
version: "1",
|
|
841
|
+
chain_id: 480,
|
|
842
|
+
nonce: payload.nonce,
|
|
843
|
+
issued_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
844
|
+
expiration_time: payload.expirationTime?.toISOString() ?? void 0,
|
|
845
|
+
not_before: payload.notBefore?.toISOString() ?? void 0,
|
|
846
|
+
request_id: payload.requestId ?? void 0
|
|
847
|
+
});
|
|
848
|
+
const walletAuthPayload = { siweMessage };
|
|
849
|
+
const walletAuthVersion = ctx.state.user.worldAppVersion && ctx.state.user.worldAppVersion > 2087900 ? COMMAND_VERSIONS["wallet-auth" /* WalletAuth */] : 1;
|
|
850
|
+
sendMiniKitEvent({
|
|
851
|
+
command: "wallet-auth" /* WalletAuth */,
|
|
852
|
+
version: walletAuthVersion,
|
|
853
|
+
payload: walletAuthPayload
|
|
854
|
+
});
|
|
855
|
+
return walletAuthPayload;
|
|
856
|
+
};
|
|
857
|
+
}
|
|
858
|
+
function createWalletAuthAsyncCommand(ctx, syncCommand) {
|
|
859
|
+
return async (payload) => {
|
|
860
|
+
return new Promise((resolve, reject) => {
|
|
861
|
+
try {
|
|
862
|
+
let commandPayload = null;
|
|
863
|
+
const handleResponse = async (response) => {
|
|
864
|
+
ctx.events.unsubscribe("miniapp-wallet-auth" /* MiniAppWalletAuth */);
|
|
865
|
+
if (response.status === "success") {
|
|
866
|
+
await ctx.state.updateUserFromWalletAuth(response.address);
|
|
867
|
+
}
|
|
868
|
+
resolve({ commandPayload, finalPayload: response });
|
|
869
|
+
};
|
|
870
|
+
ctx.events.subscribe(
|
|
871
|
+
"miniapp-wallet-auth" /* MiniAppWalletAuth */,
|
|
872
|
+
handleResponse
|
|
873
|
+
);
|
|
874
|
+
commandPayload = syncCommand(payload);
|
|
875
|
+
} catch (error) {
|
|
876
|
+
reject(error);
|
|
877
|
+
}
|
|
878
|
+
});
|
|
879
|
+
};
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
// commands/index.ts
|
|
883
|
+
function createCommands(ctx) {
|
|
884
|
+
return {
|
|
885
|
+
verify: createVerifyCommand(ctx),
|
|
886
|
+
pay: createPayCommand(ctx),
|
|
887
|
+
walletAuth: createWalletAuthCommand(ctx),
|
|
888
|
+
sendTransaction: createSendTransactionCommand(ctx),
|
|
889
|
+
signMessage: createSignMessageCommand(ctx),
|
|
890
|
+
signTypedData: createSignTypedDataCommand(ctx),
|
|
891
|
+
shareContacts: createShareContactsCommand(ctx),
|
|
892
|
+
requestPermission: createRequestPermissionCommand(ctx),
|
|
893
|
+
getPermissions: createGetPermissionsCommand(ctx),
|
|
894
|
+
sendHapticFeedback: createSendHapticFeedbackCommand(ctx),
|
|
895
|
+
share: createShareCommand(ctx),
|
|
896
|
+
chat: createChatCommand(ctx)
|
|
897
|
+
};
|
|
898
|
+
}
|
|
899
|
+
function createAsyncCommands(ctx, commands) {
|
|
900
|
+
return {
|
|
901
|
+
verify: createVerifyAsyncCommand(ctx, commands.verify),
|
|
902
|
+
pay: createPayAsyncCommand(ctx, commands.pay),
|
|
903
|
+
walletAuth: createWalletAuthAsyncCommand(ctx, commands.walletAuth),
|
|
904
|
+
sendTransaction: createSendTransactionAsyncCommand(
|
|
905
|
+
ctx,
|
|
906
|
+
commands.sendTransaction
|
|
907
|
+
),
|
|
908
|
+
signMessage: createSignMessageAsyncCommand(ctx, commands.signMessage),
|
|
909
|
+
signTypedData: createSignTypedDataAsyncCommand(ctx, commands.signTypedData),
|
|
910
|
+
shareContacts: createShareContactsAsyncCommand(ctx, commands.shareContacts),
|
|
911
|
+
requestPermission: createRequestPermissionAsyncCommand(
|
|
912
|
+
ctx,
|
|
913
|
+
commands.requestPermission
|
|
914
|
+
),
|
|
915
|
+
getPermissions: createGetPermissionsAsyncCommand(
|
|
916
|
+
ctx,
|
|
917
|
+
commands.getPermissions
|
|
918
|
+
),
|
|
919
|
+
sendHapticFeedback: createSendHapticFeedbackAsyncCommand(
|
|
920
|
+
ctx,
|
|
921
|
+
commands.sendHapticFeedback
|
|
922
|
+
),
|
|
923
|
+
share: createShareAsyncCommand(ctx, commands.share),
|
|
924
|
+
chat: createChatAsyncCommand(ctx, commands.chat)
|
|
925
|
+
};
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
// core/events.ts
|
|
929
|
+
var import_idkit_core3 = require("@worldcoin/idkit-core");
|
|
930
|
+
|
|
931
|
+
// helpers/proof/index.ts
|
|
932
|
+
var import_viem2 = require("viem");
|
|
933
|
+
var import_chains2 = require("viem/chains");
|
|
934
|
+
var semaphoreVerifierAddress = "0x79f46b94d134109EbcbbddBAeD0E88790409A0e4";
|
|
935
|
+
var semaphoreVerifierAbi = [
|
|
936
|
+
{
|
|
937
|
+
inputs: [
|
|
938
|
+
{
|
|
939
|
+
internalType: "uint256[8]",
|
|
940
|
+
name: "proof",
|
|
941
|
+
type: "uint256[8]"
|
|
942
|
+
}
|
|
943
|
+
],
|
|
944
|
+
name: "compressProof",
|
|
945
|
+
outputs: [
|
|
946
|
+
{
|
|
947
|
+
internalType: "uint256[4]",
|
|
948
|
+
name: "compressed",
|
|
949
|
+
type: "uint256[4]"
|
|
950
|
+
}
|
|
951
|
+
],
|
|
952
|
+
stateMutability: "view",
|
|
953
|
+
type: "function"
|
|
364
954
|
}
|
|
365
|
-
|
|
366
|
-
|
|
955
|
+
];
|
|
956
|
+
var compressAndPadProof = async (proof, rpcUrl) => {
|
|
957
|
+
try {
|
|
958
|
+
const publicClient = (0, import_viem2.createPublicClient)({
|
|
959
|
+
chain: import_chains2.worldchain,
|
|
960
|
+
transport: (0, import_viem2.http)(
|
|
961
|
+
rpcUrl || "https://worldchain-mainnet.g.alchemy.com/public"
|
|
962
|
+
)
|
|
963
|
+
});
|
|
964
|
+
const decodedProof = (0, import_viem2.decodeAbiParameters)(
|
|
965
|
+
[{ type: "uint256[8]" }],
|
|
966
|
+
proof
|
|
967
|
+
)[0];
|
|
968
|
+
const compressedProof = await publicClient.readContract({
|
|
969
|
+
address: semaphoreVerifierAddress,
|
|
970
|
+
abi: semaphoreVerifierAbi,
|
|
971
|
+
functionName: "compressProof",
|
|
972
|
+
args: [decodedProof]
|
|
973
|
+
});
|
|
974
|
+
const paddedProof = [...compressedProof, 0n, 0n, 0n, 0n];
|
|
975
|
+
return (0, import_viem2.encodeAbiParameters)([{ type: "uint256[8]" }], [paddedProof]);
|
|
976
|
+
} catch (e) {
|
|
977
|
+
return proof;
|
|
367
978
|
}
|
|
368
|
-
const values = Object.values(input);
|
|
369
|
-
return values.map((value) => objectValuesToArrayRecursive(value));
|
|
370
979
|
};
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
980
|
+
|
|
981
|
+
// core/events.ts
|
|
982
|
+
var EventManager = class {
|
|
983
|
+
constructor() {
|
|
984
|
+
this.listeners = {
|
|
985
|
+
["miniapp-verify-action" /* MiniAppVerifyAction */]: () => {
|
|
986
|
+
},
|
|
987
|
+
["miniapp-payment" /* MiniAppPayment */]: () => {
|
|
988
|
+
},
|
|
989
|
+
["miniapp-wallet-auth" /* MiniAppWalletAuth */]: () => {
|
|
990
|
+
},
|
|
991
|
+
["miniapp-send-transaction" /* MiniAppSendTransaction */]: () => {
|
|
992
|
+
},
|
|
993
|
+
["miniapp-sign-message" /* MiniAppSignMessage */]: () => {
|
|
994
|
+
},
|
|
995
|
+
["miniapp-sign-typed-data" /* MiniAppSignTypedData */]: () => {
|
|
996
|
+
},
|
|
997
|
+
["miniapp-share-contacts" /* MiniAppShareContacts */]: () => {
|
|
998
|
+
},
|
|
999
|
+
["miniapp-request-permission" /* MiniAppRequestPermission */]: () => {
|
|
1000
|
+
},
|
|
1001
|
+
["miniapp-get-permissions" /* MiniAppGetPermissions */]: () => {
|
|
1002
|
+
},
|
|
1003
|
+
["miniapp-send-haptic-feedback" /* MiniAppSendHapticFeedback */]: () => {
|
|
1004
|
+
},
|
|
1005
|
+
["miniapp-share" /* MiniAppShare */]: () => {
|
|
1006
|
+
},
|
|
1007
|
+
["miniapp-microphone" /* MiniAppMicrophone */]: () => {
|
|
1008
|
+
},
|
|
1009
|
+
["miniapp-chat" /* MiniAppChat */]: () => {
|
|
1010
|
+
}
|
|
1011
|
+
};
|
|
1012
|
+
this.verifyActionProcessingOptionsQueue = [];
|
|
374
1013
|
}
|
|
375
|
-
|
|
376
|
-
|
|
1014
|
+
subscribe(event, handler) {
|
|
1015
|
+
this.listeners[event] = handler;
|
|
377
1016
|
}
|
|
378
|
-
|
|
379
|
-
|
|
1017
|
+
unsubscribe(event) {
|
|
1018
|
+
delete this.listeners[event];
|
|
380
1019
|
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
1020
|
+
setVerifyActionProcessingOptions(options) {
|
|
1021
|
+
this.verifyActionProcessingOptionsQueue.push({
|
|
1022
|
+
skip_proof_compression: Boolean(options?.skip_proof_compression ?? false)
|
|
1023
|
+
});
|
|
1024
|
+
}
|
|
1025
|
+
trigger(event, payload) {
|
|
1026
|
+
if (!this.listeners[event]) {
|
|
1027
|
+
console.error(
|
|
1028
|
+
`No handler for event ${event}, payload: ${JSON.stringify(payload)}`
|
|
1029
|
+
);
|
|
1030
|
+
return;
|
|
1031
|
+
}
|
|
1032
|
+
if (event === "miniapp-verify-action" /* MiniAppVerifyAction */) {
|
|
1033
|
+
const handler = this.listeners[event];
|
|
1034
|
+
const processingOptions = this.verifyActionProcessingOptionsQueue.shift() ?? {
|
|
1035
|
+
skip_proof_compression: false
|
|
1036
|
+
};
|
|
1037
|
+
this.processVerifyActionPayload(
|
|
1038
|
+
payload,
|
|
1039
|
+
handler,
|
|
1040
|
+
processingOptions
|
|
1041
|
+
);
|
|
1042
|
+
return;
|
|
1043
|
+
}
|
|
1044
|
+
this.listeners[event](payload);
|
|
1045
|
+
}
|
|
1046
|
+
async processVerifyActionPayload(payload, handler, processingOptions) {
|
|
1047
|
+
if (payload.status === "error" && payload.error_code === "user_rejected") {
|
|
1048
|
+
payload.error_code = import_idkit_core3.AppErrorCodes.VerificationRejected;
|
|
1049
|
+
}
|
|
1050
|
+
if (payload.status === "success" && !processingOptions.skip_proof_compression) {
|
|
1051
|
+
if ("verifications" in payload) {
|
|
1052
|
+
const orbVerification = payload.verifications.find(
|
|
1053
|
+
(v) => v.verification_level === import_idkit_core3.VerificationLevel.Orb
|
|
391
1054
|
);
|
|
392
|
-
|
|
393
|
-
|
|
1055
|
+
if (orbVerification) {
|
|
1056
|
+
orbVerification.proof = await this.compressProofSafely(
|
|
1057
|
+
orbVerification.proof,
|
|
1058
|
+
{
|
|
1059
|
+
mode: "multi",
|
|
1060
|
+
payloadVersion: payload.version,
|
|
1061
|
+
verificationsCount: payload.verifications.length,
|
|
1062
|
+
verificationLevel: orbVerification.verification_level
|
|
1063
|
+
}
|
|
1064
|
+
);
|
|
1065
|
+
}
|
|
1066
|
+
} else if (payload.verification_level === import_idkit_core3.VerificationLevel.Orb) {
|
|
1067
|
+
payload.proof = await this.compressProofSafely(
|
|
1068
|
+
payload.proof,
|
|
1069
|
+
{
|
|
1070
|
+
mode: "single",
|
|
1071
|
+
payloadVersion: payload.version,
|
|
1072
|
+
verificationLevel: payload.verification_level
|
|
1073
|
+
}
|
|
394
1074
|
);
|
|
395
1075
|
}
|
|
396
1076
|
}
|
|
397
|
-
|
|
398
|
-
if (Object.prototype.hasOwnProperty.call(result, key)) {
|
|
399
|
-
result[key] = processPayload(result[key]);
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
return result;
|
|
1077
|
+
handler(payload);
|
|
403
1078
|
}
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
1079
|
+
async compressProofSafely(proof, context) {
|
|
1080
|
+
try {
|
|
1081
|
+
return await compressAndPadProof(proof);
|
|
1082
|
+
} catch (error) {
|
|
1083
|
+
console.error(
|
|
1084
|
+
"Failed to compress verification proof. Delivering payload with uncompressed proof.",
|
|
1085
|
+
{
|
|
1086
|
+
...context,
|
|
1087
|
+
error
|
|
1088
|
+
}
|
|
1089
|
+
);
|
|
1090
|
+
return proof;
|
|
1091
|
+
}
|
|
417
1092
|
}
|
|
418
|
-
return payload;
|
|
419
1093
|
};
|
|
420
1094
|
|
|
421
1095
|
// helpers/usernames/index.ts
|
|
@@ -451,124 +1125,243 @@ var mapWorldAppLaunchLocation = (location) => {
|
|
|
451
1125
|
return WORLD_APP_LAUNCH_LOCATION_MAP[normalizedLocation] ?? null;
|
|
452
1126
|
};
|
|
453
1127
|
|
|
454
|
-
//
|
|
455
|
-
var
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
payload: {
|
|
463
|
-
version: this.MINIKIT_VERSION,
|
|
464
|
-
minorVersion: this.MINIKIT_MINOR_VERSION
|
|
465
|
-
}
|
|
466
|
-
});
|
|
467
|
-
}
|
|
468
|
-
static subscribe(event, handler) {
|
|
469
|
-
if (event === "miniapp-wallet-auth" /* MiniAppWalletAuth */) {
|
|
470
|
-
const originalHandler = handler;
|
|
471
|
-
const wrappedHandler = async (payload) => {
|
|
472
|
-
if (payload.status === "success") {
|
|
473
|
-
_MiniKit.user.walletAddress = payload.address;
|
|
474
|
-
try {
|
|
475
|
-
const user = await _MiniKit.getUserByAddress(payload.address);
|
|
476
|
-
_MiniKit.user = { ..._MiniKit.user, ...user };
|
|
477
|
-
} catch (error) {
|
|
478
|
-
console.error("Failed to fetch user profile:", error);
|
|
479
|
-
}
|
|
480
|
-
}
|
|
481
|
-
originalHandler(payload);
|
|
482
|
-
};
|
|
483
|
-
this.listeners[event] = wrappedHandler;
|
|
484
|
-
} else if (event === "miniapp-verify-action" /* MiniAppVerifyAction */) {
|
|
485
|
-
const originalHandler = handler;
|
|
486
|
-
const wrappedHandler = (payload) => {
|
|
487
|
-
if (payload.status === "error" && payload.error_code == "user_rejected") {
|
|
488
|
-
payload.error_code = import_idkit_core2.AppErrorCodes.VerificationRejected;
|
|
489
|
-
}
|
|
490
|
-
if (payload.status === "success" && payload.verification_level === import_idkit_core3.VerificationLevel.Orb) {
|
|
491
|
-
compressAndPadProof(payload.proof).then(
|
|
492
|
-
(compressedProof) => {
|
|
493
|
-
payload.proof = compressedProof;
|
|
494
|
-
originalHandler(payload);
|
|
495
|
-
}
|
|
496
|
-
);
|
|
497
|
-
} else {
|
|
498
|
-
originalHandler(payload);
|
|
499
|
-
}
|
|
500
|
-
};
|
|
501
|
-
this.listeners[event] = wrappedHandler;
|
|
502
|
-
} else {
|
|
503
|
-
this.listeners[event] = handler;
|
|
504
|
-
}
|
|
1128
|
+
// core/state.ts
|
|
1129
|
+
var MiniKitState = class {
|
|
1130
|
+
constructor() {
|
|
1131
|
+
this.appId = null;
|
|
1132
|
+
this.user = {};
|
|
1133
|
+
this.deviceProperties = {};
|
|
1134
|
+
this.location = null;
|
|
1135
|
+
this.isReady = false;
|
|
505
1136
|
}
|
|
506
|
-
|
|
507
|
-
|
|
1137
|
+
initFromWorldApp(worldApp) {
|
|
1138
|
+
if (!worldApp) return;
|
|
1139
|
+
this.user.optedIntoOptionalAnalytics = worldApp.is_optional_analytics;
|
|
1140
|
+
this.user.deviceOS = worldApp.device_os;
|
|
1141
|
+
this.user.worldAppVersion = worldApp.world_app_version;
|
|
1142
|
+
this.deviceProperties.safeAreaInsets = worldApp.safe_area_insets;
|
|
1143
|
+
this.deviceProperties.deviceOS = worldApp.device_os;
|
|
1144
|
+
this.deviceProperties.worldAppVersion = worldApp.world_app_version;
|
|
1145
|
+
this.location = mapWorldAppLaunchLocation(worldApp.location);
|
|
508
1146
|
}
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
1147
|
+
async updateUserFromWalletAuth(address) {
|
|
1148
|
+
this.user.walletAddress = address;
|
|
1149
|
+
try {
|
|
1150
|
+
const userProfile = await getUserProfile(address);
|
|
1151
|
+
this.user.username = userProfile.username;
|
|
1152
|
+
this.user.profilePictureUrl = userProfile.profile_picture_url;
|
|
1153
|
+
} catch (error) {
|
|
1154
|
+
console.error("Failed to fetch user profile:", error);
|
|
515
1155
|
}
|
|
516
|
-
this.listeners[event](payload);
|
|
517
1156
|
}
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
commandPayload = executor();
|
|
527
|
-
});
|
|
1157
|
+
async getUserByAddress(address) {
|
|
1158
|
+
const walletAddress = address ?? this.user.walletAddress;
|
|
1159
|
+
const userProfile = await getUserProfile(walletAddress);
|
|
1160
|
+
return {
|
|
1161
|
+
walletAddress,
|
|
1162
|
+
username: userProfile.username,
|
|
1163
|
+
profilePictureUrl: userProfile.profile_picture_url
|
|
1164
|
+
};
|
|
528
1165
|
}
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
let isCommandValid = false;
|
|
537
|
-
if (!commandInput) {
|
|
538
|
-
console.warn(
|
|
539
|
-
`Command ${minikitCommandName} is not supported by the app. Try updating the app version`
|
|
540
|
-
);
|
|
541
|
-
} else {
|
|
542
|
-
if (commandInput.supported_versions.includes(version)) {
|
|
543
|
-
_MiniKit.isCommandAvailable[minikitCommandName] = true;
|
|
544
|
-
isCommandValid = true;
|
|
545
|
-
} else {
|
|
546
|
-
isCommandValid = true;
|
|
547
|
-
console.warn(
|
|
548
|
-
`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.`
|
|
549
|
-
);
|
|
550
|
-
_MiniKit.isCommandAvailable[minikitCommandName] = isCommandValid;
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
if (!isCommandValid) {
|
|
554
|
-
allCommandsValid = false;
|
|
1166
|
+
async getUserByUsername(username) {
|
|
1167
|
+
const res = await fetch(
|
|
1168
|
+
`https://usernames.worldcoin.org/api/v1/${username}`,
|
|
1169
|
+
{
|
|
1170
|
+
method: "GET",
|
|
1171
|
+
headers: {
|
|
1172
|
+
"Content-Type": "application/json"
|
|
555
1173
|
}
|
|
556
1174
|
}
|
|
557
1175
|
);
|
|
558
|
-
|
|
1176
|
+
const user = await res.json();
|
|
1177
|
+
return {
|
|
1178
|
+
walletAddress: user.address,
|
|
1179
|
+
username: user.username,
|
|
1180
|
+
profilePictureUrl: user.profile_picture_url
|
|
1181
|
+
};
|
|
559
1182
|
}
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
1183
|
+
};
|
|
1184
|
+
|
|
1185
|
+
// types/errors.ts
|
|
1186
|
+
var import_idkit_core4 = require("@worldcoin/idkit-core");
|
|
1187
|
+
var import_idkit_core5 = require("@worldcoin/idkit-core");
|
|
1188
|
+
var VerificationErrorMessage = {
|
|
1189
|
+
[import_idkit_core4.AppErrorCodes.VerificationRejected]: "You've cancelled the request in World App.",
|
|
1190
|
+
[import_idkit_core4.AppErrorCodes.MaxVerificationsReached]: "You have already verified the maximum number of times for this action.",
|
|
1191
|
+
[import_idkit_core4.AppErrorCodes.CredentialUnavailable]: "It seems you do not have the verification level required by this app.",
|
|
1192
|
+
[import_idkit_core4.AppErrorCodes.MalformedRequest]: "There was a problem with this request. Please try again or contact the app owner.",
|
|
1193
|
+
[import_idkit_core4.AppErrorCodes.InvalidNetwork]: "Invalid network. If you are the app owner, visit docs.worldcoin.org/test for details.",
|
|
1194
|
+
[import_idkit_core4.AppErrorCodes.InclusionProofFailed]: "There was an issue fetching your credential. Please try again.",
|
|
1195
|
+
[import_idkit_core4.AppErrorCodes.InclusionProofPending]: "Your identity is still being registered. Please wait a few minutes and try again.",
|
|
1196
|
+
[import_idkit_core4.AppErrorCodes.UnexpectedResponse]: "Unexpected response from your wallet. Please try again.",
|
|
1197
|
+
[import_idkit_core4.AppErrorCodes.FailedByHostApp]: "Verification failed by the app. Please contact the app owner for details.",
|
|
1198
|
+
[import_idkit_core4.AppErrorCodes.GenericError]: "Something unexpected went wrong. Please try again.",
|
|
1199
|
+
[import_idkit_core4.AppErrorCodes.ConnectionFailed]: "Connection to your wallet failed. Please try again."
|
|
1200
|
+
};
|
|
1201
|
+
var MiniKitInstallErrorMessage = {
|
|
1202
|
+
["unknown" /* Unknown */]: "Failed to install MiniKit.",
|
|
1203
|
+
["already_installed" /* AlreadyInstalled */]: "MiniKit is already installed.",
|
|
1204
|
+
["outside_of_worldapp" /* OutsideOfWorldApp */]: "MiniApp launched outside of WorldApp.",
|
|
1205
|
+
["not_on_client" /* NotOnClient */]: "Window object is not available.",
|
|
1206
|
+
["app_out_of_date" /* AppOutOfDate */]: "WorldApp is out of date. Please update the app."
|
|
1207
|
+
};
|
|
1208
|
+
|
|
1209
|
+
// helpers/microphone/index.ts
|
|
1210
|
+
var microphoneSetupDone = false;
|
|
1211
|
+
var setupMicrophone = () => {
|
|
1212
|
+
if (microphoneSetupDone) {
|
|
1213
|
+
return;
|
|
1214
|
+
}
|
|
1215
|
+
if (typeof navigator !== "undefined" && !navigator.mediaDevices?.getUserMedia)
|
|
1216
|
+
return;
|
|
1217
|
+
const originalStop = MediaStreamTrack.prototype.stop;
|
|
1218
|
+
MediaStreamTrack.prototype.stop = function() {
|
|
1219
|
+
originalStop.call(this);
|
|
1220
|
+
if (this.readyState === "ended") {
|
|
1221
|
+
setTimeout(() => this.dispatchEvent(new Event("ended")), 0);
|
|
1222
|
+
}
|
|
1223
|
+
};
|
|
1224
|
+
const realGUM = navigator.mediaDevices.getUserMedia.bind(
|
|
1225
|
+
navigator.mediaDevices
|
|
1226
|
+
);
|
|
1227
|
+
const live = /* @__PURE__ */ new Set();
|
|
1228
|
+
async function wrapped(constraints) {
|
|
1229
|
+
const stream = await realGUM(constraints);
|
|
1230
|
+
const hasAudioTrack = stream.getAudioTracks().length > 0;
|
|
1231
|
+
if (hasAudioTrack) {
|
|
1232
|
+
sendWebviewEvent({
|
|
1233
|
+
command: "microphone-stream-started",
|
|
1234
|
+
version: 1,
|
|
1235
|
+
payload: {
|
|
1236
|
+
streamId: stream.id
|
|
1237
|
+
}
|
|
1238
|
+
});
|
|
1239
|
+
live.add(stream);
|
|
1240
|
+
stream.getAudioTracks().forEach((t) => {
|
|
1241
|
+
t.addEventListener("ended", () => {
|
|
1242
|
+
const allAudioTracksEnded = stream.getAudioTracks().every((track) => track.readyState === "ended");
|
|
1243
|
+
if (allAudioTracksEnded) {
|
|
1244
|
+
sendWebviewEvent({
|
|
1245
|
+
command: "microphone-stream-ended",
|
|
1246
|
+
version: 1,
|
|
1247
|
+
payload: {
|
|
1248
|
+
streamId: stream.id
|
|
1249
|
+
}
|
|
1250
|
+
});
|
|
1251
|
+
live.delete(stream);
|
|
1252
|
+
}
|
|
1253
|
+
});
|
|
1254
|
+
});
|
|
1255
|
+
}
|
|
1256
|
+
return stream;
|
|
1257
|
+
}
|
|
1258
|
+
Object.defineProperty(navigator.mediaDevices, "getUserMedia", {
|
|
1259
|
+
value: wrapped,
|
|
1260
|
+
writable: false,
|
|
1261
|
+
configurable: false,
|
|
1262
|
+
enumerable: true
|
|
1263
|
+
});
|
|
1264
|
+
Object.freeze(navigator.mediaDevices);
|
|
1265
|
+
const stopAllMiniAppMicrophoneStreams = () => {
|
|
1266
|
+
live.forEach((s) => {
|
|
1267
|
+
const audioTracks = s.getAudioTracks();
|
|
1268
|
+
if (audioTracks.length > 0) {
|
|
1269
|
+
audioTracks.forEach((t) => {
|
|
1270
|
+
t.stop();
|
|
1271
|
+
});
|
|
1272
|
+
sendWebviewEvent({
|
|
1273
|
+
command: "microphone-stream-ended",
|
|
1274
|
+
version: 1,
|
|
1275
|
+
payload: {
|
|
1276
|
+
streamId: s.id
|
|
1277
|
+
}
|
|
1278
|
+
});
|
|
1279
|
+
}
|
|
1280
|
+
});
|
|
1281
|
+
live.clear();
|
|
1282
|
+
};
|
|
1283
|
+
MiniKit.subscribe("miniapp-microphone" /* MiniAppMicrophone */, (payload) => {
|
|
1284
|
+
if (payload.status === "error" && (payload.error_code === "mini_app_permission_not_enabled" /* MiniAppPermissionNotEnabled */ || payload.error_code === "world_app_permission_not_enabled" /* WorldAppPermissionNotEnabled */)) {
|
|
1285
|
+
console.log("stopping all microphone streams", payload);
|
|
1286
|
+
stopAllMiniAppMicrophoneStreams();
|
|
1287
|
+
}
|
|
1288
|
+
});
|
|
1289
|
+
window.__stopAllMiniAppMicrophoneStreams = stopAllMiniAppMicrophoneStreams;
|
|
1290
|
+
microphoneSetupDone = true;
|
|
1291
|
+
};
|
|
1292
|
+
|
|
1293
|
+
// minikit.ts
|
|
1294
|
+
var MINIKIT_VERSION = 1;
|
|
1295
|
+
var MINIKIT_MINOR_VERSION = 96;
|
|
1296
|
+
var _MiniKit = class _MiniKit {
|
|
1297
|
+
// ============================================================================
|
|
1298
|
+
// Public State Accessors
|
|
1299
|
+
// ============================================================================
|
|
1300
|
+
static get appId() {
|
|
1301
|
+
return this.stateManager.appId;
|
|
1302
|
+
}
|
|
1303
|
+
static set appId(value) {
|
|
1304
|
+
this.stateManager.appId = value;
|
|
1305
|
+
}
|
|
1306
|
+
static get user() {
|
|
1307
|
+
return this.stateManager.user;
|
|
1308
|
+
}
|
|
1309
|
+
static set user(value) {
|
|
1310
|
+
this.stateManager.user = value;
|
|
1311
|
+
}
|
|
1312
|
+
static get deviceProperties() {
|
|
1313
|
+
return this.stateManager.deviceProperties;
|
|
1314
|
+
}
|
|
1315
|
+
static get location() {
|
|
1316
|
+
return this.stateManager.location;
|
|
1317
|
+
}
|
|
1318
|
+
// ============================================================================
|
|
1319
|
+
// Event System
|
|
1320
|
+
// ============================================================================
|
|
1321
|
+
static subscribe(event, handler) {
|
|
1322
|
+
if (event === "miniapp-wallet-auth" /* MiniAppWalletAuth */) {
|
|
1323
|
+
const originalHandler = handler;
|
|
1324
|
+
const wrappedHandler = async (payload) => {
|
|
1325
|
+
if (payload.status === "success") {
|
|
1326
|
+
await this.stateManager.updateUserFromWalletAuth(payload.address);
|
|
1327
|
+
}
|
|
1328
|
+
originalHandler(payload);
|
|
1329
|
+
};
|
|
1330
|
+
this.eventManager.subscribe(event, wrappedHandler);
|
|
1331
|
+
} else {
|
|
1332
|
+
this.eventManager.subscribe(event, handler);
|
|
1333
|
+
}
|
|
1334
|
+
}
|
|
1335
|
+
static unsubscribe(event) {
|
|
1336
|
+
this.eventManager.unsubscribe(event);
|
|
1337
|
+
}
|
|
1338
|
+
static trigger(event, payload) {
|
|
1339
|
+
this.eventManager.trigger(event, payload);
|
|
1340
|
+
}
|
|
1341
|
+
// ============================================================================
|
|
1342
|
+
// Installation
|
|
1343
|
+
// ============================================================================
|
|
1344
|
+
static sendInit() {
|
|
1345
|
+
sendWebviewEvent({
|
|
1346
|
+
command: "init",
|
|
1347
|
+
payload: {
|
|
1348
|
+
version: MINIKIT_VERSION,
|
|
1349
|
+
minorVersion: MINIKIT_MINOR_VERSION
|
|
1350
|
+
}
|
|
1351
|
+
});
|
|
1352
|
+
}
|
|
1353
|
+
static install(appId) {
|
|
1354
|
+
if (typeof window === "undefined" || Boolean(window.MiniKit)) {
|
|
1355
|
+
return {
|
|
1356
|
+
success: false,
|
|
1357
|
+
errorCode: "already_installed" /* AlreadyInstalled */,
|
|
1358
|
+
errorMessage: MiniKitInstallErrorMessage["already_installed" /* AlreadyInstalled */]
|
|
1359
|
+
};
|
|
567
1360
|
}
|
|
568
1361
|
if (!appId) {
|
|
569
1362
|
console.warn("App ID not provided during install");
|
|
570
1363
|
} else {
|
|
571
|
-
|
|
1364
|
+
this.stateManager.appId = appId;
|
|
572
1365
|
}
|
|
573
1366
|
if (!window.WorldApp) {
|
|
574
1367
|
return {
|
|
@@ -577,13 +1370,7 @@ var _MiniKit = class _MiniKit {
|
|
|
577
1370
|
errorMessage: MiniKitInstallErrorMessage["outside_of_worldapp" /* OutsideOfWorldApp */]
|
|
578
1371
|
};
|
|
579
1372
|
}
|
|
580
|
-
|
|
581
|
-
_MiniKit.user.deviceOS = window.WorldApp.device_os;
|
|
582
|
-
_MiniKit.user.worldAppVersion = window.WorldApp.world_app_version;
|
|
583
|
-
_MiniKit.deviceProperties.safeAreaInsets = window.WorldApp.safe_area_insets;
|
|
584
|
-
_MiniKit.deviceProperties.deviceOS = window.WorldApp.device_os;
|
|
585
|
-
_MiniKit.deviceProperties.worldAppVersion = window.WorldApp.world_app_version;
|
|
586
|
-
_MiniKit.location = mapWorldAppLaunchLocation(window.WorldApp.location);
|
|
1373
|
+
this.stateManager.initFromWorldApp(window.WorldApp);
|
|
587
1374
|
try {
|
|
588
1375
|
window.MiniKit = _MiniKit;
|
|
589
1376
|
this.sendInit();
|
|
@@ -598,9 +1385,9 @@ var _MiniKit = class _MiniKit {
|
|
|
598
1385
|
errorMessage: MiniKitInstallErrorMessage["unknown" /* Unknown */]
|
|
599
1386
|
};
|
|
600
1387
|
}
|
|
601
|
-
|
|
1388
|
+
this.stateManager.isReady = true;
|
|
602
1389
|
setupMicrophone();
|
|
603
|
-
if (!
|
|
1390
|
+
if (!validateCommands(window.WorldApp.supported_commands)) {
|
|
604
1391
|
return {
|
|
605
1392
|
success: false,
|
|
606
1393
|
errorCode: "app_out_of_date" /* AppOutOfDate */,
|
|
@@ -610,106 +1397,56 @@ var _MiniKit = class _MiniKit {
|
|
|
610
1397
|
return { success: true };
|
|
611
1398
|
}
|
|
612
1399
|
static isInstalled(debug) {
|
|
613
|
-
const isInstalled =
|
|
614
|
-
if (!isInstalled)
|
|
1400
|
+
const isInstalled = this.stateManager.isReady && Boolean(window.MiniKit);
|
|
1401
|
+
if (!isInstalled) {
|
|
615
1402
|
console.error(
|
|
616
1403
|
"MiniKit is not installed. Make sure you're running the application inside of World App"
|
|
617
1404
|
);
|
|
618
|
-
|
|
1405
|
+
}
|
|
1406
|
+
if (debug && isInstalled) {
|
|
1407
|
+
console.log("MiniKit is alive!");
|
|
1408
|
+
}
|
|
619
1409
|
return isInstalled;
|
|
620
1410
|
}
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
["sign-typed-data" /* SignTypedData */]: false,
|
|
645
|
-
["share-contacts" /* ShareContacts */]: false,
|
|
646
|
-
["request-permission" /* RequestPermission */]: false,
|
|
647
|
-
["get-permissions" /* GetPermissions */]: false,
|
|
648
|
-
["send-haptic-feedback" /* SendHapticFeedback */]: false,
|
|
649
|
-
["share" /* Share */]: false,
|
|
650
|
-
["chat" /* Chat */]: false
|
|
651
|
-
};
|
|
652
|
-
_MiniKit.listeners = {
|
|
653
|
-
["miniapp-verify-action" /* MiniAppVerifyAction */]: () => {
|
|
654
|
-
},
|
|
655
|
-
["miniapp-payment" /* MiniAppPayment */]: () => {
|
|
656
|
-
},
|
|
657
|
-
["miniapp-wallet-auth" /* MiniAppWalletAuth */]: () => {
|
|
658
|
-
},
|
|
659
|
-
["miniapp-send-transaction" /* MiniAppSendTransaction */]: () => {
|
|
660
|
-
},
|
|
661
|
-
["miniapp-sign-message" /* MiniAppSignMessage */]: () => {
|
|
662
|
-
},
|
|
663
|
-
["miniapp-sign-typed-data" /* MiniAppSignTypedData */]: () => {
|
|
664
|
-
},
|
|
665
|
-
["miniapp-share-contacts" /* MiniAppShareContacts */]: () => {
|
|
666
|
-
},
|
|
667
|
-
["miniapp-request-permission" /* MiniAppRequestPermission */]: () => {
|
|
668
|
-
},
|
|
669
|
-
["miniapp-get-permissions" /* MiniAppGetPermissions */]: () => {
|
|
670
|
-
},
|
|
671
|
-
["miniapp-send-haptic-feedback" /* MiniAppSendHapticFeedback */]: () => {
|
|
672
|
-
},
|
|
673
|
-
["miniapp-share" /* MiniAppShare */]: () => {
|
|
674
|
-
},
|
|
675
|
-
["miniapp-microphone" /* MiniAppMicrophone */]: () => {
|
|
676
|
-
},
|
|
677
|
-
["miniapp-chat" /* MiniAppChat */]: () => {
|
|
1411
|
+
// ============================================================================
|
|
1412
|
+
// Commands
|
|
1413
|
+
// ============================================================================
|
|
1414
|
+
static getContext() {
|
|
1415
|
+
return {
|
|
1416
|
+
events: this.eventManager,
|
|
1417
|
+
state: this.stateManager
|
|
1418
|
+
};
|
|
1419
|
+
}
|
|
1420
|
+
static get commands() {
|
|
1421
|
+
if (!this.commandsInstance) {
|
|
1422
|
+
this.commandsInstance = createCommands(this.getContext());
|
|
1423
|
+
}
|
|
1424
|
+
return this.commandsInstance;
|
|
1425
|
+
}
|
|
1426
|
+
static get commandsAsync() {
|
|
1427
|
+
if (!this.asyncCommandsInstance) {
|
|
1428
|
+
this.asyncCommandsInstance = createAsyncCommands(
|
|
1429
|
+
this.getContext(),
|
|
1430
|
+
this.commands
|
|
1431
|
+
);
|
|
1432
|
+
}
|
|
1433
|
+
return this.asyncCommandsInstance;
|
|
678
1434
|
}
|
|
679
1435
|
};
|
|
680
|
-
_MiniKit.
|
|
681
|
-
_MiniKit.
|
|
682
|
-
_MiniKit.
|
|
683
|
-
_MiniKit.
|
|
684
|
-
|
|
1436
|
+
_MiniKit.eventManager = new EventManager();
|
|
1437
|
+
_MiniKit.stateManager = new MiniKitState();
|
|
1438
|
+
_MiniKit.commandsInstance = null;
|
|
1439
|
+
_MiniKit.asyncCommandsInstance = null;
|
|
1440
|
+
// ============================================================================
|
|
1441
|
+
// Utility Methods
|
|
1442
|
+
// ============================================================================
|
|
685
1443
|
_MiniKit.getUserByAddress = async (address) => {
|
|
686
|
-
|
|
687
|
-
address ?? _MiniKit.user.walletAddress
|
|
688
|
-
);
|
|
689
|
-
return {
|
|
690
|
-
walletAddress: address ?? _MiniKit.user.walletAddress,
|
|
691
|
-
username: userProfile.username,
|
|
692
|
-
profilePictureUrl: userProfile.profile_picture_url
|
|
693
|
-
};
|
|
1444
|
+
return _MiniKit.stateManager.getUserByAddress(address);
|
|
694
1445
|
};
|
|
695
1446
|
_MiniKit.getUserByUsername = async (username) => {
|
|
696
|
-
|
|
697
|
-
`https://usernames.worldcoin.org/api/v1/${username}`,
|
|
698
|
-
{
|
|
699
|
-
method: "GET",
|
|
700
|
-
headers: {
|
|
701
|
-
"Content-Type": "application/json"
|
|
702
|
-
}
|
|
703
|
-
}
|
|
704
|
-
);
|
|
705
|
-
const user = await res.json();
|
|
706
|
-
return {
|
|
707
|
-
walletAddress: user.address,
|
|
708
|
-
username: user.username,
|
|
709
|
-
profilePictureUrl: user.profile_picture_url
|
|
710
|
-
};
|
|
1447
|
+
return _MiniKit.stateManager.getUserByUsername(username);
|
|
711
1448
|
};
|
|
712
|
-
|
|
1449
|
+
_MiniKit.getUserInfo = _MiniKit.getUserByAddress;
|
|
713
1450
|
_MiniKit.getMiniAppUrl = (appId, path) => {
|
|
714
1451
|
const baseUrl = new URL("https://world.org/mini-app");
|
|
715
1452
|
baseUrl.searchParams.append("app_id", appId);
|
|
@@ -719,7 +1456,6 @@ _MiniKit.getMiniAppUrl = (appId, path) => {
|
|
|
719
1456
|
}
|
|
720
1457
|
return baseUrl.toString();
|
|
721
1458
|
};
|
|
722
|
-
// Opens the profile card for a given username or wallet address
|
|
723
1459
|
_MiniKit.showProfileCard = (username, walletAddress) => {
|
|
724
1460
|
if (!username && !walletAddress) {
|
|
725
1461
|
console.error(
|
|
@@ -731,449 +1467,12 @@ _MiniKit.showProfileCard = (username, walletAddress) => {
|
|
|
731
1467
|
window.open(
|
|
732
1468
|
`worldapp://profile?username=${encodeURIComponent(username)}`
|
|
733
1469
|
);
|
|
734
|
-
return;
|
|
735
1470
|
} else {
|
|
736
1471
|
window.open(
|
|
737
1472
|
`worldapp://profile?address=${encodeURIComponent(walletAddress || "")}`
|
|
738
1473
|
);
|
|
739
1474
|
}
|
|
740
1475
|
};
|
|
741
|
-
// Simply re-exporting the existing function
|
|
742
|
-
_MiniKit.getUserInfo = _MiniKit.getUserByAddress;
|
|
743
|
-
_MiniKit.commands = {
|
|
744
|
-
verify: (payload) => {
|
|
745
|
-
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["verify" /* Verify */]) {
|
|
746
|
-
console.error(
|
|
747
|
-
"'verify' command is unavailable. Check MiniKit.install() or update the app version"
|
|
748
|
-
);
|
|
749
|
-
return null;
|
|
750
|
-
}
|
|
751
|
-
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
752
|
-
const eventPayload = {
|
|
753
|
-
action: (0, import_hashing.encodeAction)(payload.action),
|
|
754
|
-
signal: (0, import_hashing.generateSignal)(payload.signal).digest,
|
|
755
|
-
verification_level: payload.verification_level || import_idkit_core3.VerificationLevel.Orb,
|
|
756
|
-
timestamp
|
|
757
|
-
};
|
|
758
|
-
sendMiniKitEvent({
|
|
759
|
-
command: "verify" /* Verify */,
|
|
760
|
-
version: _MiniKit.miniKitCommandVersion["verify" /* Verify */],
|
|
761
|
-
payload: eventPayload
|
|
762
|
-
});
|
|
763
|
-
return eventPayload;
|
|
764
|
-
},
|
|
765
|
-
pay: (payload) => {
|
|
766
|
-
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["pay" /* Pay */]) {
|
|
767
|
-
console.error(
|
|
768
|
-
"'pay' command is unavailable. Check MiniKit.install() or update the app version"
|
|
769
|
-
);
|
|
770
|
-
return null;
|
|
771
|
-
}
|
|
772
|
-
if (!validatePaymentPayload(payload)) {
|
|
773
|
-
return null;
|
|
774
|
-
}
|
|
775
|
-
const eventPayload = {
|
|
776
|
-
...payload,
|
|
777
|
-
network: "worldchain" /* WorldChain */
|
|
778
|
-
};
|
|
779
|
-
sendMiniKitEvent({
|
|
780
|
-
command: "pay" /* Pay */,
|
|
781
|
-
version: _MiniKit.miniKitCommandVersion["pay" /* Pay */],
|
|
782
|
-
payload: eventPayload
|
|
783
|
-
});
|
|
784
|
-
return eventPayload;
|
|
785
|
-
},
|
|
786
|
-
walletAuth: (payload) => {
|
|
787
|
-
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["wallet-auth" /* WalletAuth */]) {
|
|
788
|
-
console.error(
|
|
789
|
-
"'walletAuth' command is unavailable. Check MiniKit.install() or update the app version"
|
|
790
|
-
);
|
|
791
|
-
return null;
|
|
792
|
-
}
|
|
793
|
-
const validationResult = validateWalletAuthCommandInput(payload);
|
|
794
|
-
if (!validationResult.valid) {
|
|
795
|
-
console.error(
|
|
796
|
-
"Failed to validate wallet auth input:\n\n -->",
|
|
797
|
-
validationResult.message
|
|
798
|
-
);
|
|
799
|
-
return null;
|
|
800
|
-
}
|
|
801
|
-
let protocol = null;
|
|
802
|
-
try {
|
|
803
|
-
const currentUrl = new URL(window.location.href);
|
|
804
|
-
protocol = currentUrl.protocol.split(":")[0];
|
|
805
|
-
} catch (error) {
|
|
806
|
-
console.error("Failed to get current URL", error);
|
|
807
|
-
return null;
|
|
808
|
-
}
|
|
809
|
-
const siweMessage = generateSiweMessage({
|
|
810
|
-
scheme: protocol,
|
|
811
|
-
domain: window.location.host,
|
|
812
|
-
statement: payload.statement ?? void 0,
|
|
813
|
-
uri: window.location.href,
|
|
814
|
-
version: "1",
|
|
815
|
-
chain_id: 480,
|
|
816
|
-
nonce: payload.nonce,
|
|
817
|
-
issued_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
818
|
-
expiration_time: payload.expirationTime?.toISOString() ?? void 0,
|
|
819
|
-
not_before: payload.notBefore?.toISOString() ?? void 0,
|
|
820
|
-
request_id: payload.requestId ?? void 0
|
|
821
|
-
});
|
|
822
|
-
const walletAuthPayload = { siweMessage };
|
|
823
|
-
const walletAuthVersion = _MiniKit.user.worldAppVersion && _MiniKit.user.worldAppVersion > 2087900 ? _MiniKit.miniKitCommandVersion["wallet-auth" /* WalletAuth */] : 1;
|
|
824
|
-
sendMiniKitEvent({
|
|
825
|
-
command: "wallet-auth" /* WalletAuth */,
|
|
826
|
-
version: walletAuthVersion,
|
|
827
|
-
payload: walletAuthPayload
|
|
828
|
-
});
|
|
829
|
-
return walletAuthPayload;
|
|
830
|
-
},
|
|
831
|
-
sendTransaction: (payload) => {
|
|
832
|
-
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["send-transaction" /* SendTransaction */]) {
|
|
833
|
-
console.error(
|
|
834
|
-
"'sendTransaction' command is unavailable. Check MiniKit.install() or update the app version"
|
|
835
|
-
);
|
|
836
|
-
return null;
|
|
837
|
-
}
|
|
838
|
-
payload.formatPayload = payload.formatPayload !== false;
|
|
839
|
-
const validatedPayload = validateSendTransactionPayload(payload);
|
|
840
|
-
sendMiniKitEvent({
|
|
841
|
-
command: "send-transaction" /* SendTransaction */,
|
|
842
|
-
version: _MiniKit.miniKitCommandVersion["send-transaction" /* SendTransaction */],
|
|
843
|
-
payload: validatedPayload
|
|
844
|
-
});
|
|
845
|
-
return validatedPayload;
|
|
846
|
-
},
|
|
847
|
-
signMessage: (payload) => {
|
|
848
|
-
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["sign-message" /* SignMessage */]) {
|
|
849
|
-
console.error(
|
|
850
|
-
"'signMessage' command is unavailable. Check MiniKit.install() or update the app version"
|
|
851
|
-
);
|
|
852
|
-
return null;
|
|
853
|
-
}
|
|
854
|
-
sendMiniKitEvent({
|
|
855
|
-
command: "sign-message" /* SignMessage */,
|
|
856
|
-
version: _MiniKit.miniKitCommandVersion["sign-message" /* SignMessage */],
|
|
857
|
-
payload
|
|
858
|
-
});
|
|
859
|
-
return payload;
|
|
860
|
-
},
|
|
861
|
-
signTypedData: (payload) => {
|
|
862
|
-
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["sign-typed-data" /* SignTypedData */]) {
|
|
863
|
-
console.error(
|
|
864
|
-
"'signTypedData' command is unavailable. Check MiniKit.install() or update the app version"
|
|
865
|
-
);
|
|
866
|
-
return null;
|
|
867
|
-
}
|
|
868
|
-
if (!payload.chainId) {
|
|
869
|
-
payload.chainId = 480;
|
|
870
|
-
}
|
|
871
|
-
sendMiniKitEvent({
|
|
872
|
-
command: "sign-typed-data" /* SignTypedData */,
|
|
873
|
-
version: _MiniKit.miniKitCommandVersion["sign-typed-data" /* SignTypedData */],
|
|
874
|
-
payload
|
|
875
|
-
});
|
|
876
|
-
return payload;
|
|
877
|
-
},
|
|
878
|
-
shareContacts: (payload) => {
|
|
879
|
-
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["share-contacts" /* ShareContacts */]) {
|
|
880
|
-
console.error(
|
|
881
|
-
"'shareContacts' command is unavailable. Check MiniKit.install() or update the app version"
|
|
882
|
-
);
|
|
883
|
-
return null;
|
|
884
|
-
}
|
|
885
|
-
sendMiniKitEvent({
|
|
886
|
-
command: "share-contacts" /* ShareContacts */,
|
|
887
|
-
version: _MiniKit.miniKitCommandVersion["share-contacts" /* ShareContacts */],
|
|
888
|
-
payload
|
|
889
|
-
});
|
|
890
|
-
return payload;
|
|
891
|
-
},
|
|
892
|
-
requestPermission: (payload) => {
|
|
893
|
-
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["request-permission" /* RequestPermission */]) {
|
|
894
|
-
console.error(
|
|
895
|
-
"'requestPermission' command is unavailable. Check MiniKit.install() or update the app version"
|
|
896
|
-
);
|
|
897
|
-
return null;
|
|
898
|
-
}
|
|
899
|
-
sendMiniKitEvent({
|
|
900
|
-
command: "request-permission" /* RequestPermission */,
|
|
901
|
-
version: _MiniKit.miniKitCommandVersion["request-permission" /* RequestPermission */],
|
|
902
|
-
payload
|
|
903
|
-
});
|
|
904
|
-
return payload;
|
|
905
|
-
},
|
|
906
|
-
getPermissions: () => {
|
|
907
|
-
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["get-permissions" /* GetPermissions */]) {
|
|
908
|
-
console.error(
|
|
909
|
-
"'getPermissions' command is unavailable. Check MiniKit.install() or update the app version"
|
|
910
|
-
);
|
|
911
|
-
return null;
|
|
912
|
-
}
|
|
913
|
-
sendMiniKitEvent({
|
|
914
|
-
command: "get-permissions" /* GetPermissions */,
|
|
915
|
-
version: _MiniKit.miniKitCommandVersion["get-permissions" /* GetPermissions */],
|
|
916
|
-
payload: {}
|
|
917
|
-
});
|
|
918
|
-
return {
|
|
919
|
-
status: "sent"
|
|
920
|
-
};
|
|
921
|
-
},
|
|
922
|
-
sendHapticFeedback: (payload) => {
|
|
923
|
-
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["send-haptic-feedback" /* SendHapticFeedback */]) {
|
|
924
|
-
console.error(
|
|
925
|
-
"'sendHapticFeedback' command is unavailable. Check MiniKit.install() or update the app version"
|
|
926
|
-
);
|
|
927
|
-
return null;
|
|
928
|
-
}
|
|
929
|
-
sendMiniKitEvent({
|
|
930
|
-
command: "send-haptic-feedback" /* SendHapticFeedback */,
|
|
931
|
-
version: _MiniKit.miniKitCommandVersion["send-haptic-feedback" /* SendHapticFeedback */],
|
|
932
|
-
payload
|
|
933
|
-
});
|
|
934
|
-
return payload;
|
|
935
|
-
},
|
|
936
|
-
// We return share input here because the payload is formatted asynchronously
|
|
937
|
-
share: (payload) => {
|
|
938
|
-
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["share" /* Share */]) {
|
|
939
|
-
console.error(
|
|
940
|
-
"'share' command is unavailable. Check MiniKit.install() or update the app version"
|
|
941
|
-
);
|
|
942
|
-
return null;
|
|
943
|
-
}
|
|
944
|
-
if (_MiniKit.deviceProperties.deviceOS === "ios" && typeof navigator !== "undefined") {
|
|
945
|
-
sendMiniKitEvent({
|
|
946
|
-
command: "share" /* Share */,
|
|
947
|
-
version: _MiniKit.miniKitCommandVersion["share" /* Share */],
|
|
948
|
-
payload
|
|
949
|
-
});
|
|
950
|
-
navigator.share(payload);
|
|
951
|
-
} else {
|
|
952
|
-
formatShareInput(payload).then((formattedResult) => {
|
|
953
|
-
sendMiniKitEvent({
|
|
954
|
-
command: "share" /* Share */,
|
|
955
|
-
version: _MiniKit.miniKitCommandVersion["share" /* Share */],
|
|
956
|
-
payload: formattedResult
|
|
957
|
-
});
|
|
958
|
-
}).catch((error) => {
|
|
959
|
-
console.error("Failed to format share input", error);
|
|
960
|
-
});
|
|
961
|
-
_MiniKit.subscribe("miniapp-share" /* MiniAppShare */, (payload2) => {
|
|
962
|
-
console.log("Share Response", payload2);
|
|
963
|
-
});
|
|
964
|
-
}
|
|
965
|
-
return payload;
|
|
966
|
-
},
|
|
967
|
-
chat: (payload) => {
|
|
968
|
-
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["chat" /* Chat */]) {
|
|
969
|
-
console.error(
|
|
970
|
-
"'chat' command is unavailable. Check MiniKit.install() or update the app version"
|
|
971
|
-
);
|
|
972
|
-
return null;
|
|
973
|
-
}
|
|
974
|
-
if (payload.message.length === 0) {
|
|
975
|
-
console.error("'chat' command requires a non-empty message");
|
|
976
|
-
return null;
|
|
977
|
-
}
|
|
978
|
-
sendMiniKitEvent({
|
|
979
|
-
command: "chat" /* Chat */,
|
|
980
|
-
version: _MiniKit.miniKitCommandVersion["chat" /* Chat */],
|
|
981
|
-
payload
|
|
982
|
-
});
|
|
983
|
-
return payload;
|
|
984
|
-
}
|
|
985
|
-
};
|
|
986
|
-
/**
|
|
987
|
-
* This object contains async versions of all the commands.
|
|
988
|
-
* Instead of using event listeners, you can just `await` these.
|
|
989
|
-
*
|
|
990
|
-
* They return a standardized object
|
|
991
|
-
*
|
|
992
|
-
* commandPayload - object returned by the command function
|
|
993
|
-
*
|
|
994
|
-
* finalPayload - object returned by the event listener, or in other words, WorldApp response
|
|
995
|
-
*/
|
|
996
|
-
_MiniKit.commandsAsync = {
|
|
997
|
-
verify: async (payload) => {
|
|
998
|
-
return new Promise(async (resolve, reject) => {
|
|
999
|
-
try {
|
|
1000
|
-
const response = await _MiniKit.awaitCommand(
|
|
1001
|
-
"miniapp-verify-action" /* MiniAppVerifyAction */,
|
|
1002
|
-
"verify" /* Verify */,
|
|
1003
|
-
() => _MiniKit.commands.verify(payload)
|
|
1004
|
-
);
|
|
1005
|
-
if (response.finalPayload.status === "success" && response.finalPayload.verification_level === import_idkit_core3.VerificationLevel.Orb) {
|
|
1006
|
-
response.finalPayload.proof = await compressAndPadProof(
|
|
1007
|
-
response.finalPayload.proof
|
|
1008
|
-
);
|
|
1009
|
-
}
|
|
1010
|
-
resolve(response);
|
|
1011
|
-
} catch (error) {
|
|
1012
|
-
reject(error);
|
|
1013
|
-
}
|
|
1014
|
-
});
|
|
1015
|
-
},
|
|
1016
|
-
pay: async (payload) => {
|
|
1017
|
-
return new Promise(async (resolve, reject) => {
|
|
1018
|
-
try {
|
|
1019
|
-
const response = await _MiniKit.awaitCommand(
|
|
1020
|
-
"miniapp-payment" /* MiniAppPayment */,
|
|
1021
|
-
"pay" /* Pay */,
|
|
1022
|
-
() => _MiniKit.commands.pay(payload)
|
|
1023
|
-
);
|
|
1024
|
-
resolve(response);
|
|
1025
|
-
} catch (error) {
|
|
1026
|
-
reject(error);
|
|
1027
|
-
}
|
|
1028
|
-
});
|
|
1029
|
-
},
|
|
1030
|
-
walletAuth: async (payload) => {
|
|
1031
|
-
return new Promise(async (resolve, reject) => {
|
|
1032
|
-
try {
|
|
1033
|
-
const response = await _MiniKit.awaitCommand(
|
|
1034
|
-
"miniapp-wallet-auth" /* MiniAppWalletAuth */,
|
|
1035
|
-
"wallet-auth" /* WalletAuth */,
|
|
1036
|
-
() => _MiniKit.commands.walletAuth(payload)
|
|
1037
|
-
);
|
|
1038
|
-
return resolve(response);
|
|
1039
|
-
} catch (error) {
|
|
1040
|
-
reject(error);
|
|
1041
|
-
}
|
|
1042
|
-
});
|
|
1043
|
-
},
|
|
1044
|
-
sendTransaction: async (payload) => {
|
|
1045
|
-
return new Promise(async (resolve, reject) => {
|
|
1046
|
-
try {
|
|
1047
|
-
const response = await _MiniKit.awaitCommand(
|
|
1048
|
-
"miniapp-send-transaction" /* MiniAppSendTransaction */,
|
|
1049
|
-
"send-transaction" /* SendTransaction */,
|
|
1050
|
-
() => _MiniKit.commands.sendTransaction(payload)
|
|
1051
|
-
);
|
|
1052
|
-
return resolve(response);
|
|
1053
|
-
} catch (error) {
|
|
1054
|
-
reject(error);
|
|
1055
|
-
}
|
|
1056
|
-
});
|
|
1057
|
-
},
|
|
1058
|
-
signMessage: async (payload) => {
|
|
1059
|
-
return new Promise(async (resolve, reject) => {
|
|
1060
|
-
try {
|
|
1061
|
-
const response = await _MiniKit.awaitCommand(
|
|
1062
|
-
"miniapp-sign-message" /* MiniAppSignMessage */,
|
|
1063
|
-
"sign-message" /* SignMessage */,
|
|
1064
|
-
() => _MiniKit.commands.signMessage(payload)
|
|
1065
|
-
);
|
|
1066
|
-
return resolve(response);
|
|
1067
|
-
} catch (error) {
|
|
1068
|
-
reject(error);
|
|
1069
|
-
}
|
|
1070
|
-
});
|
|
1071
|
-
},
|
|
1072
|
-
signTypedData: async (payload) => {
|
|
1073
|
-
return new Promise(async (resolve, reject) => {
|
|
1074
|
-
try {
|
|
1075
|
-
const response = await _MiniKit.awaitCommand(
|
|
1076
|
-
"miniapp-sign-typed-data" /* MiniAppSignTypedData */,
|
|
1077
|
-
"sign-typed-data" /* SignTypedData */,
|
|
1078
|
-
() => _MiniKit.commands.signTypedData(payload)
|
|
1079
|
-
);
|
|
1080
|
-
return resolve(response);
|
|
1081
|
-
} catch (error) {
|
|
1082
|
-
reject(error);
|
|
1083
|
-
}
|
|
1084
|
-
});
|
|
1085
|
-
},
|
|
1086
|
-
shareContacts: async (payload) => {
|
|
1087
|
-
return new Promise(async (resolve, reject) => {
|
|
1088
|
-
try {
|
|
1089
|
-
const response = await _MiniKit.awaitCommand(
|
|
1090
|
-
"miniapp-share-contacts" /* MiniAppShareContacts */,
|
|
1091
|
-
"share-contacts" /* ShareContacts */,
|
|
1092
|
-
() => _MiniKit.commands.shareContacts(payload)
|
|
1093
|
-
);
|
|
1094
|
-
return resolve(response);
|
|
1095
|
-
} catch (error) {
|
|
1096
|
-
reject(error);
|
|
1097
|
-
}
|
|
1098
|
-
});
|
|
1099
|
-
},
|
|
1100
|
-
requestPermission: async (payload) => {
|
|
1101
|
-
return new Promise(async (resolve, reject) => {
|
|
1102
|
-
try {
|
|
1103
|
-
const response = await _MiniKit.awaitCommand(
|
|
1104
|
-
"miniapp-request-permission" /* MiniAppRequestPermission */,
|
|
1105
|
-
"request-permission" /* RequestPermission */,
|
|
1106
|
-
() => _MiniKit.commands.requestPermission(payload)
|
|
1107
|
-
);
|
|
1108
|
-
resolve(response);
|
|
1109
|
-
} catch (error) {
|
|
1110
|
-
reject(error);
|
|
1111
|
-
}
|
|
1112
|
-
});
|
|
1113
|
-
},
|
|
1114
|
-
getPermissions: async () => {
|
|
1115
|
-
return new Promise(async (resolve, reject) => {
|
|
1116
|
-
try {
|
|
1117
|
-
const response = await _MiniKit.awaitCommand(
|
|
1118
|
-
"miniapp-get-permissions" /* MiniAppGetPermissions */,
|
|
1119
|
-
"get-permissions" /* GetPermissions */,
|
|
1120
|
-
() => _MiniKit.commands.getPermissions()
|
|
1121
|
-
);
|
|
1122
|
-
resolve(response);
|
|
1123
|
-
} catch (error) {
|
|
1124
|
-
reject(error);
|
|
1125
|
-
}
|
|
1126
|
-
});
|
|
1127
|
-
},
|
|
1128
|
-
sendHapticFeedback: async (payload) => {
|
|
1129
|
-
return new Promise(async (resolve, reject) => {
|
|
1130
|
-
try {
|
|
1131
|
-
const response = await _MiniKit.awaitCommand(
|
|
1132
|
-
"miniapp-send-haptic-feedback" /* MiniAppSendHapticFeedback */,
|
|
1133
|
-
"send-haptic-feedback" /* SendHapticFeedback */,
|
|
1134
|
-
() => _MiniKit.commands.sendHapticFeedback(payload)
|
|
1135
|
-
);
|
|
1136
|
-
resolve(response);
|
|
1137
|
-
} catch (error) {
|
|
1138
|
-
reject(error);
|
|
1139
|
-
}
|
|
1140
|
-
});
|
|
1141
|
-
},
|
|
1142
|
-
share: async (payload) => {
|
|
1143
|
-
return new Promise(async (resolve, reject) => {
|
|
1144
|
-
try {
|
|
1145
|
-
const response = await _MiniKit.awaitCommand(
|
|
1146
|
-
"miniapp-share" /* MiniAppShare */,
|
|
1147
|
-
"share" /* Share */,
|
|
1148
|
-
() => _MiniKit.commands.share(payload)
|
|
1149
|
-
);
|
|
1150
|
-
resolve({
|
|
1151
|
-
commandPayload: response.commandPayload,
|
|
1152
|
-
finalPayload: response.finalPayload
|
|
1153
|
-
});
|
|
1154
|
-
} catch (error) {
|
|
1155
|
-
reject(error);
|
|
1156
|
-
}
|
|
1157
|
-
});
|
|
1158
|
-
},
|
|
1159
|
-
chat: async (payload) => {
|
|
1160
|
-
return new Promise(async (resolve, reject) => {
|
|
1161
|
-
try {
|
|
1162
|
-
const response = await _MiniKit.awaitCommand(
|
|
1163
|
-
"miniapp-chat" /* MiniAppChat */,
|
|
1164
|
-
"chat" /* Chat */,
|
|
1165
|
-
() => _MiniKit.commands.chat(payload)
|
|
1166
|
-
);
|
|
1167
|
-
resolve({
|
|
1168
|
-
commandPayload: response.commandPayload,
|
|
1169
|
-
finalPayload: response.finalPayload
|
|
1170
|
-
});
|
|
1171
|
-
} catch (error) {
|
|
1172
|
-
reject(error);
|
|
1173
|
-
}
|
|
1174
|
-
});
|
|
1175
|
-
}
|
|
1176
|
-
};
|
|
1177
1476
|
var MiniKit = _MiniKit;
|
|
1178
1477
|
|
|
1179
1478
|
// minikit-provider.tsx
|