@worldcoin/minikit-js 1.9.9 → 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-VWX7SELF.js → chunk-XFGJKKI2.js} +1431 -1157
- package/build/index.cjs +1542 -1241
- package/build/index.d.cts +489 -527
- package/build/index.d.ts +489 -527
- package/build/index.js +63 -9
- package/build/minikit-provider.cjs +1125 -858
- 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,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,68 +784,280 @@ var validateWalletAuthCommandInput = (params) => {
|
|
|
354
784
|
return { valid: true };
|
|
355
785
|
};
|
|
356
786
|
|
|
357
|
-
//
|
|
358
|
-
|
|
359
|
-
return
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
787
|
+
// commands/wallet-auth.ts
|
|
788
|
+
function createWalletAuthCommand(ctx) {
|
|
789
|
+
return (payload) => {
|
|
790
|
+
if (typeof window === "undefined" || !isCommandAvailable("wallet-auth" /* WalletAuth */)) {
|
|
791
|
+
console.error(
|
|
792
|
+
"'walletAuth' command is unavailable. Check MiniKit.install() or update the app version"
|
|
793
|
+
);
|
|
794
|
+
return null;
|
|
795
|
+
}
|
|
796
|
+
const validationResult = validateWalletAuthCommandInput(payload);
|
|
797
|
+
if (!validationResult.valid) {
|
|
798
|
+
console.error(
|
|
799
|
+
"Failed to validate wallet auth input:\n\n -->",
|
|
800
|
+
validationResult.message
|
|
801
|
+
);
|
|
802
|
+
return null;
|
|
803
|
+
}
|
|
804
|
+
let protocol = null;
|
|
805
|
+
try {
|
|
806
|
+
const currentUrl = new URL(window.location.href);
|
|
807
|
+
protocol = currentUrl.protocol.split(":")[0];
|
|
808
|
+
} catch (error) {
|
|
809
|
+
console.error("Failed to get current URL", error);
|
|
810
|
+
return null;
|
|
811
|
+
}
|
|
812
|
+
const siweMessage = generateSiweMessage({
|
|
813
|
+
scheme: protocol,
|
|
814
|
+
domain: window.location.host,
|
|
815
|
+
statement: payload.statement ?? void 0,
|
|
816
|
+
uri: window.location.href,
|
|
817
|
+
version: "1",
|
|
818
|
+
chain_id: 480,
|
|
819
|
+
nonce: payload.nonce,
|
|
820
|
+
issued_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
821
|
+
expiration_time: payload.expirationTime?.toISOString() ?? void 0,
|
|
822
|
+
not_before: payload.notBefore?.toISOString() ?? void 0,
|
|
823
|
+
request_id: payload.requestId ?? void 0
|
|
824
|
+
});
|
|
825
|
+
const walletAuthPayload = { siweMessage };
|
|
826
|
+
const walletAuthVersion = ctx.state.user.worldAppVersion && ctx.state.user.worldAppVersion > 2087900 ? COMMAND_VERSIONS["wallet-auth" /* WalletAuth */] : 1;
|
|
827
|
+
sendMiniKitEvent({
|
|
828
|
+
command: "wallet-auth" /* WalletAuth */,
|
|
829
|
+
version: walletAuthVersion,
|
|
830
|
+
payload: walletAuthPayload
|
|
831
|
+
});
|
|
832
|
+
return walletAuthPayload;
|
|
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
|
+
}
|
|
855
|
+
});
|
|
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
|
+
)
|
|
940
|
+
});
|
|
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]
|
|
950
|
+
});
|
|
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
|
+
}
|
|
370
956
|
};
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
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
|
+
}
|
|
988
|
+
};
|
|
374
989
|
}
|
|
375
|
-
|
|
376
|
-
|
|
990
|
+
subscribe(event, handler) {
|
|
991
|
+
this.listeners[event] = handler;
|
|
377
992
|
}
|
|
378
|
-
|
|
379
|
-
|
|
993
|
+
unsubscribe(event) {
|
|
994
|
+
delete this.listeners[event];
|
|
380
995
|
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
996
|
+
trigger(event, payload) {
|
|
997
|
+
if (!this.listeners[event]) {
|
|
998
|
+
console.error(
|
|
999
|
+
`No handler for event ${event}, payload: ${JSON.stringify(payload)}`
|
|
1000
|
+
);
|
|
1001
|
+
return;
|
|
1002
|
+
}
|
|
1003
|
+
if (event === "miniapp-verify-action" /* MiniAppVerifyAction */) {
|
|
1004
|
+
const handler = this.listeners[event];
|
|
1005
|
+
this.unsubscribe(event);
|
|
1006
|
+
this.processVerifyActionPayload(
|
|
1007
|
+
payload,
|
|
1008
|
+
handler
|
|
1009
|
+
);
|
|
1010
|
+
return;
|
|
1011
|
+
}
|
|
1012
|
+
this.listeners[event](payload);
|
|
1013
|
+
}
|
|
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
|
|
391
1022
|
);
|
|
392
|
-
|
|
393
|
-
|
|
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
|
+
}
|
|
1032
|
+
);
|
|
1033
|
+
}
|
|
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
|
+
}
|
|
394
1042
|
);
|
|
395
1043
|
}
|
|
396
1044
|
}
|
|
397
|
-
|
|
398
|
-
if (Object.prototype.hasOwnProperty.call(result, key)) {
|
|
399
|
-
result[key] = processPayload(result[key]);
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
return result;
|
|
1045
|
+
handler(payload);
|
|
403
1046
|
}
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
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
|
+
}
|
|
417
1060
|
}
|
|
418
|
-
return payload;
|
|
419
1061
|
};
|
|
420
1062
|
|
|
421
1063
|
// helpers/usernames/index.ts
|
|
@@ -451,124 +1093,243 @@ var mapWorldAppLaunchLocation = (location) => {
|
|
|
451
1093
|
return WORLD_APP_LAUNCH_LOCATION_MAP[normalizedLocation] ?? null;
|
|
452
1094
|
};
|
|
453
1095
|
|
|
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
|
-
}
|
|
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;
|
|
505
1104
|
}
|
|
506
|
-
|
|
507
|
-
|
|
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);
|
|
508
1114
|
}
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
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);
|
|
515
1123
|
}
|
|
516
|
-
this.listeners[event](payload);
|
|
517
1124
|
}
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
commandPayload = executor();
|
|
527
|
-
});
|
|
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
|
+
};
|
|
528
1133
|
}
|
|
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;
|
|
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"
|
|
555
1141
|
}
|
|
556
1142
|
}
|
|
557
1143
|
);
|
|
558
|
-
|
|
1144
|
+
const user = await res.json();
|
|
1145
|
+
return {
|
|
1146
|
+
walletAddress: user.address,
|
|
1147
|
+
username: user.username,
|
|
1148
|
+
profilePictureUrl: user.profile_picture_url
|
|
1149
|
+
};
|
|
559
1150
|
}
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
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
|
+
});
|
|
1247
|
+
}
|
|
1248
|
+
});
|
|
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
|
|
1318
|
+
}
|
|
1319
|
+
});
|
|
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;
|
|
572
1333
|
}
|
|
573
1334
|
if (!window.WorldApp) {
|
|
574
1335
|
return {
|
|
@@ -577,13 +1338,7 @@ var _MiniKit = class _MiniKit {
|
|
|
577
1338
|
errorMessage: MiniKitInstallErrorMessage["outside_of_worldapp" /* OutsideOfWorldApp */]
|
|
578
1339
|
};
|
|
579
1340
|
}
|
|
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);
|
|
1341
|
+
this.stateManager.initFromWorldApp(window.WorldApp);
|
|
587
1342
|
try {
|
|
588
1343
|
window.MiniKit = _MiniKit;
|
|
589
1344
|
this.sendInit();
|
|
@@ -598,9 +1353,9 @@ var _MiniKit = class _MiniKit {
|
|
|
598
1353
|
errorMessage: MiniKitInstallErrorMessage["unknown" /* Unknown */]
|
|
599
1354
|
};
|
|
600
1355
|
}
|
|
601
|
-
|
|
1356
|
+
this.stateManager.isReady = true;
|
|
602
1357
|
setupMicrophone();
|
|
603
|
-
if (!
|
|
1358
|
+
if (!validateCommands(window.WorldApp.supported_commands)) {
|
|
604
1359
|
return {
|
|
605
1360
|
success: false,
|
|
606
1361
|
errorCode: "app_out_of_date" /* AppOutOfDate */,
|
|
@@ -610,106 +1365,56 @@ var _MiniKit = class _MiniKit {
|
|
|
610
1365
|
return { success: true };
|
|
611
1366
|
}
|
|
612
1367
|
static isInstalled(debug) {
|
|
613
|
-
const isInstalled =
|
|
614
|
-
if (!isInstalled)
|
|
1368
|
+
const isInstalled = this.stateManager.isReady && Boolean(window.MiniKit);
|
|
1369
|
+
if (!isInstalled) {
|
|
615
1370
|
console.error(
|
|
616
1371
|
"MiniKit is not installed. Make sure you're running the application inside of World App"
|
|
617
1372
|
);
|
|
618
|
-
|
|
1373
|
+
}
|
|
1374
|
+
if (debug && isInstalled) {
|
|
1375
|
+
console.log("MiniKit is alive!");
|
|
1376
|
+
}
|
|
619
1377
|
return isInstalled;
|
|
620
1378
|
}
|
|
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 */]: () => {
|
|
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;
|
|
678
1402
|
}
|
|
679
1403
|
};
|
|
680
|
-
_MiniKit.
|
|
681
|
-
_MiniKit.
|
|
682
|
-
_MiniKit.
|
|
683
|
-
_MiniKit.
|
|
684
|
-
|
|
1404
|
+
_MiniKit.eventManager = new EventManager();
|
|
1405
|
+
_MiniKit.stateManager = new MiniKitState();
|
|
1406
|
+
_MiniKit.commandsInstance = null;
|
|
1407
|
+
_MiniKit.asyncCommandsInstance = null;
|
|
1408
|
+
// ============================================================================
|
|
1409
|
+
// Utility Methods
|
|
1410
|
+
// ============================================================================
|
|
685
1411
|
_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
|
-
};
|
|
1412
|
+
return _MiniKit.stateManager.getUserByAddress(address);
|
|
694
1413
|
};
|
|
695
1414
|
_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
|
-
};
|
|
1415
|
+
return _MiniKit.stateManager.getUserByUsername(username);
|
|
711
1416
|
};
|
|
712
|
-
|
|
1417
|
+
_MiniKit.getUserInfo = _MiniKit.getUserByAddress;
|
|
713
1418
|
_MiniKit.getMiniAppUrl = (appId, path) => {
|
|
714
1419
|
const baseUrl = new URL("https://world.org/mini-app");
|
|
715
1420
|
baseUrl.searchParams.append("app_id", appId);
|
|
@@ -719,7 +1424,6 @@ _MiniKit.getMiniAppUrl = (appId, path) => {
|
|
|
719
1424
|
}
|
|
720
1425
|
return baseUrl.toString();
|
|
721
1426
|
};
|
|
722
|
-
// Opens the profile card for a given username or wallet address
|
|
723
1427
|
_MiniKit.showProfileCard = (username, walletAddress) => {
|
|
724
1428
|
if (!username && !walletAddress) {
|
|
725
1429
|
console.error(
|
|
@@ -731,449 +1435,12 @@ _MiniKit.showProfileCard = (username, walletAddress) => {
|
|
|
731
1435
|
window.open(
|
|
732
1436
|
`worldapp://profile?username=${encodeURIComponent(username)}`
|
|
733
1437
|
);
|
|
734
|
-
return;
|
|
735
1438
|
} else {
|
|
736
1439
|
window.open(
|
|
737
1440
|
`worldapp://profile?address=${encodeURIComponent(walletAddress || "")}`
|
|
738
1441
|
);
|
|
739
1442
|
}
|
|
740
1443
|
};
|
|
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
1444
|
var MiniKit = _MiniKit;
|
|
1178
1445
|
|
|
1179
1446
|
// minikit-provider.tsx
|