@worldcoin/minikit-js 1.8.0 → 1.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/chunk-7FYGA6HX.js +1349 -0
- package/build/index.cjs +221 -51
- package/build/index.d.cts +56 -27
- package/build/index.d.ts +56 -27
- package/build/index.js +46 -1151
- package/build/minikit-provider.cjs +927 -0
- package/build/minikit-provider.d.cts +15 -0
- package/build/minikit-provider.d.ts +15 -0
- package/build/minikit-provider.js +46 -0
- package/index.ts +2 -5
- package/package.json +14 -1
|
@@ -0,0 +1,927 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// minikit-provider.tsx
|
|
22
|
+
var minikit_provider_exports = {};
|
|
23
|
+
__export(minikit_provider_exports, {
|
|
24
|
+
MiniKitProvider: () => MiniKitProvider,
|
|
25
|
+
useMiniKit: () => useMiniKit
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(minikit_provider_exports);
|
|
28
|
+
var import_react = require("react");
|
|
29
|
+
|
|
30
|
+
// minikit.ts
|
|
31
|
+
var import_idkit_core3 = require("@worldcoin/idkit-core");
|
|
32
|
+
var import_hashing = require("@worldcoin/idkit-core/hashing");
|
|
33
|
+
|
|
34
|
+
// helpers/payment/client.ts
|
|
35
|
+
var validatePaymentPayload = (payload) => {
|
|
36
|
+
if (payload.tokens.some(
|
|
37
|
+
(token) => token.symbol == "USDCE" && parseFloat(token.token_amount) < 0.1
|
|
38
|
+
)) {
|
|
39
|
+
console.error("USDCE amount should be greater than $0.1");
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
if (payload.reference.length > 36) {
|
|
43
|
+
console.error("Reference must not exceed 36 characters");
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
if (typeof payload.reference !== "string") {
|
|
47
|
+
throw new Error("Reference must be a string");
|
|
48
|
+
}
|
|
49
|
+
return true;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
// helpers/proof/index.ts
|
|
53
|
+
var import_viem = require("viem");
|
|
54
|
+
var import_chains = require("viem/chains");
|
|
55
|
+
var semaphoreVerifierAddress = "0x79f46b94d134109EbcbbddBAeD0E88790409A0e4";
|
|
56
|
+
var semaphoreVerifierAbi = [
|
|
57
|
+
{
|
|
58
|
+
inputs: [
|
|
59
|
+
{
|
|
60
|
+
internalType: "uint256[8]",
|
|
61
|
+
name: "proof",
|
|
62
|
+
type: "uint256[8]"
|
|
63
|
+
}
|
|
64
|
+
],
|
|
65
|
+
name: "compressProof",
|
|
66
|
+
outputs: [
|
|
67
|
+
{
|
|
68
|
+
internalType: "uint256[4]",
|
|
69
|
+
name: "compressed",
|
|
70
|
+
type: "uint256[4]"
|
|
71
|
+
}
|
|
72
|
+
],
|
|
73
|
+
stateMutability: "view",
|
|
74
|
+
type: "function"
|
|
75
|
+
}
|
|
76
|
+
];
|
|
77
|
+
var compressAndPadProof = async (proof, rpcUrl) => {
|
|
78
|
+
try {
|
|
79
|
+
const publicClient = (0, import_viem.createPublicClient)({
|
|
80
|
+
chain: import_chains.worldchain,
|
|
81
|
+
transport: (0, import_viem.http)(
|
|
82
|
+
rpcUrl || "https://worldchain-mainnet.g.alchemy.com/public"
|
|
83
|
+
)
|
|
84
|
+
});
|
|
85
|
+
const decodedProof = (0, import_viem.decodeAbiParameters)(
|
|
86
|
+
[{ type: "uint256[8]" }],
|
|
87
|
+
proof
|
|
88
|
+
)[0];
|
|
89
|
+
const compressedProof = await publicClient.readContract({
|
|
90
|
+
address: semaphoreVerifierAddress,
|
|
91
|
+
abi: semaphoreVerifierAbi,
|
|
92
|
+
functionName: "compressProof",
|
|
93
|
+
args: [decodedProof]
|
|
94
|
+
});
|
|
95
|
+
const paddedProof = [...compressedProof, 0n, 0n, 0n, 0n];
|
|
96
|
+
return (0, import_viem.encodeAbiParameters)([{ type: "uint256[8]" }], [paddedProof]);
|
|
97
|
+
} catch (e) {
|
|
98
|
+
console.log("Failed to compress proof", {
|
|
99
|
+
e,
|
|
100
|
+
proof
|
|
101
|
+
});
|
|
102
|
+
return proof;
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
// helpers/siwe/siwe.ts
|
|
107
|
+
var import_viem2 = require("viem");
|
|
108
|
+
var import_chains2 = require("viem/chains");
|
|
109
|
+
var generateSiweMessage = (siweMessageData) => {
|
|
110
|
+
let siweMessage = "";
|
|
111
|
+
if (siweMessageData.scheme) {
|
|
112
|
+
siweMessage += `${siweMessageData.scheme}://${siweMessageData.domain} wants you to sign in with your Ethereum account:
|
|
113
|
+
`;
|
|
114
|
+
} else {
|
|
115
|
+
siweMessage += `${siweMessageData.domain} wants you to sign in with your Ethereum account:
|
|
116
|
+
`;
|
|
117
|
+
}
|
|
118
|
+
if (siweMessageData.address) {
|
|
119
|
+
siweMessage += `${siweMessageData.address}
|
|
120
|
+
`;
|
|
121
|
+
} else {
|
|
122
|
+
siweMessage += "{address}\n";
|
|
123
|
+
}
|
|
124
|
+
siweMessage += "\n";
|
|
125
|
+
if (siweMessageData.statement) {
|
|
126
|
+
siweMessage += `${siweMessageData.statement}
|
|
127
|
+
`;
|
|
128
|
+
}
|
|
129
|
+
siweMessage += "\n";
|
|
130
|
+
siweMessage += `URI: ${siweMessageData.uri}
|
|
131
|
+
`;
|
|
132
|
+
siweMessage += `Version: ${siweMessageData.version}
|
|
133
|
+
`;
|
|
134
|
+
siweMessage += `Chain ID: ${siweMessageData.chain_id}
|
|
135
|
+
`;
|
|
136
|
+
siweMessage += `Nonce: ${siweMessageData.nonce}
|
|
137
|
+
`;
|
|
138
|
+
siweMessage += `Issued At: ${siweMessageData.issued_at}
|
|
139
|
+
`;
|
|
140
|
+
if (siweMessageData.expiration_time) {
|
|
141
|
+
siweMessage += `Expiration Time: ${siweMessageData.expiration_time}
|
|
142
|
+
`;
|
|
143
|
+
}
|
|
144
|
+
if (siweMessageData.not_before) {
|
|
145
|
+
siweMessage += `Not Before: ${siweMessageData.not_before}
|
|
146
|
+
`;
|
|
147
|
+
}
|
|
148
|
+
if (siweMessageData.request_id) {
|
|
149
|
+
siweMessage += `Request ID: ${siweMessageData.request_id}
|
|
150
|
+
`;
|
|
151
|
+
}
|
|
152
|
+
return siweMessage;
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
// helpers/siwe/validate-wallet-auth-command-input.ts
|
|
156
|
+
var validateWalletAuthCommandInput = (params) => {
|
|
157
|
+
if (!params.nonce) {
|
|
158
|
+
return { valid: false, message: "'nonce' is required" };
|
|
159
|
+
}
|
|
160
|
+
if (params.nonce.length < 8) {
|
|
161
|
+
return { valid: false, message: "'nonce' must be at least 8 characters" };
|
|
162
|
+
}
|
|
163
|
+
if (params.statement && params.statement.includes("\n")) {
|
|
164
|
+
return { valid: false, message: "'statement' must not contain newlines" };
|
|
165
|
+
}
|
|
166
|
+
if (params.expirationTime && new Date(params.expirationTime) < /* @__PURE__ */ new Date()) {
|
|
167
|
+
return { valid: false, message: "'expirationTime' must be in the future" };
|
|
168
|
+
}
|
|
169
|
+
if (params.expirationTime && new Date(params.expirationTime) > new Date(Date.now() + 7 * 24 * 60 * 60 * 1e3)) {
|
|
170
|
+
return { valid: false, message: "'expirationTime' must be within 7 days" };
|
|
171
|
+
}
|
|
172
|
+
if (params.notBefore && new Date(params.notBefore) > new Date(Date.now() + 7 * 24 * 60 * 60 * 1e3)) {
|
|
173
|
+
return { valid: false, message: "'notBefore' must be within 7 days" };
|
|
174
|
+
}
|
|
175
|
+
return { valid: true };
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
// helpers/transaction/validate-payload.ts
|
|
179
|
+
var isValidHex = (str) => {
|
|
180
|
+
return /^0x[0-9A-Fa-f]+$/.test(str);
|
|
181
|
+
};
|
|
182
|
+
var processPayload = (payload) => {
|
|
183
|
+
if (typeof payload === "boolean" || typeof payload === "string" || payload === null || payload === void 0) {
|
|
184
|
+
return payload;
|
|
185
|
+
}
|
|
186
|
+
if (typeof payload === "number" || typeof payload === "bigint") {
|
|
187
|
+
return String(payload);
|
|
188
|
+
}
|
|
189
|
+
if (Array.isArray(payload)) {
|
|
190
|
+
return payload.map((value) => processPayload(value));
|
|
191
|
+
}
|
|
192
|
+
if (typeof payload === "object") {
|
|
193
|
+
const result = { ...payload };
|
|
194
|
+
if ("value" in result && result.value !== void 0) {
|
|
195
|
+
if (typeof result.value !== "string") {
|
|
196
|
+
result.value = String(result.value);
|
|
197
|
+
}
|
|
198
|
+
if (!isValidHex(result.value)) {
|
|
199
|
+
console.error(
|
|
200
|
+
"Transaction value must be a valid hex string",
|
|
201
|
+
result.value
|
|
202
|
+
);
|
|
203
|
+
throw new Error(
|
|
204
|
+
`Transaction value must be a valid hex string: ${result.value}`
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
for (const key in result) {
|
|
209
|
+
if (Object.prototype.hasOwnProperty.call(result, key)) {
|
|
210
|
+
result[key] = processPayload(result[key]);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
return result;
|
|
214
|
+
}
|
|
215
|
+
return payload;
|
|
216
|
+
};
|
|
217
|
+
var validateSendTransactionPayload = (payload) => {
|
|
218
|
+
return processPayload(payload);
|
|
219
|
+
};
|
|
220
|
+
|
|
221
|
+
// helpers/usernames/index.ts
|
|
222
|
+
var getUserProfile = async (address) => {
|
|
223
|
+
const res = await fetch("https://usernames.worldcoin.org/api/v1/query", {
|
|
224
|
+
method: "POST",
|
|
225
|
+
headers: {
|
|
226
|
+
"Content-Type": "application/json"
|
|
227
|
+
},
|
|
228
|
+
body: JSON.stringify({
|
|
229
|
+
addresses: [address]
|
|
230
|
+
})
|
|
231
|
+
});
|
|
232
|
+
const usernames = await res.json();
|
|
233
|
+
return usernames?.[0] ?? { username: null, profile_picture_url: null };
|
|
234
|
+
};
|
|
235
|
+
|
|
236
|
+
// types/errors.ts
|
|
237
|
+
var import_idkit_core = require("@worldcoin/idkit-core");
|
|
238
|
+
var import_idkit_core2 = require("@worldcoin/idkit-core");
|
|
239
|
+
var VerificationErrorMessage = {
|
|
240
|
+
[import_idkit_core.AppErrorCodes.VerificationRejected]: "You've cancelled the request in World App.",
|
|
241
|
+
[import_idkit_core.AppErrorCodes.MaxVerificationsReached]: "You have already verified the maximum number of times for this action.",
|
|
242
|
+
[import_idkit_core.AppErrorCodes.CredentialUnavailable]: "It seems you do not have the verification level required by this app.",
|
|
243
|
+
[import_idkit_core.AppErrorCodes.MalformedRequest]: "There was a problem with this request. Please try again or contact the app owner.",
|
|
244
|
+
[import_idkit_core.AppErrorCodes.InvalidNetwork]: "Invalid network. If you are the app owner, visit docs.worldcoin.org/test for details.",
|
|
245
|
+
[import_idkit_core.AppErrorCodes.InclusionProofFailed]: "There was an issue fetching your credential. Please try again.",
|
|
246
|
+
[import_idkit_core.AppErrorCodes.InclusionProofPending]: "Your identity is still being registered. Please wait a few minutes and try again.",
|
|
247
|
+
[import_idkit_core.AppErrorCodes.UnexpectedResponse]: "Unexpected response from your wallet. Please try again.",
|
|
248
|
+
[import_idkit_core.AppErrorCodes.FailedByHostApp]: "Verification failed by the app. Please contact the app owner for details.",
|
|
249
|
+
[import_idkit_core.AppErrorCodes.GenericError]: "Something unexpected went wrong. Please try again.",
|
|
250
|
+
[import_idkit_core.AppErrorCodes.ConnectionFailed]: "Connection to your wallet failed. Please try again."
|
|
251
|
+
};
|
|
252
|
+
var MiniKitInstallErrorMessage = {
|
|
253
|
+
["unknown" /* Unknown */]: "Failed to install MiniKit.",
|
|
254
|
+
["already_installed" /* AlreadyInstalled */]: "MiniKit is already installed.",
|
|
255
|
+
["outside_of_worldapp" /* OutsideOfWorldApp */]: "MiniApp launched outside of WorldApp.",
|
|
256
|
+
["not_on_client" /* NotOnClient */]: "Window object is not available.",
|
|
257
|
+
["app_out_of_date" /* AppOutOfDate */]: "WorldApp is out of date. Please update the app."
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
// helpers/send-webview-event.ts
|
|
261
|
+
var sendWebviewEvent = (payload) => {
|
|
262
|
+
if (window.webkit) {
|
|
263
|
+
window.webkit?.messageHandlers?.minikit?.postMessage?.(payload);
|
|
264
|
+
} else if (window.Android) {
|
|
265
|
+
window.Android.postMessage?.(JSON.stringify(payload));
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
// minikit.ts
|
|
270
|
+
var sendMiniKitEvent = (payload) => {
|
|
271
|
+
sendWebviewEvent(payload);
|
|
272
|
+
};
|
|
273
|
+
var _MiniKit = class _MiniKit {
|
|
274
|
+
static sendInit() {
|
|
275
|
+
sendWebviewEvent({
|
|
276
|
+
command: "init",
|
|
277
|
+
payload: { version: this.MINIKIT_VERSION }
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
static subscribe(event, handler) {
|
|
281
|
+
if (event === "miniapp-wallet-auth" /* MiniAppWalletAuth */) {
|
|
282
|
+
const originalHandler = handler;
|
|
283
|
+
const wrappedHandler = async (payload) => {
|
|
284
|
+
if (payload.status === "success") {
|
|
285
|
+
_MiniKit.user.walletAddress = payload.address;
|
|
286
|
+
try {
|
|
287
|
+
const user = await _MiniKit.getUserByAddress(payload.address);
|
|
288
|
+
_MiniKit.user = { ..._MiniKit.user, ...user };
|
|
289
|
+
} catch (error) {
|
|
290
|
+
console.error("Failed to fetch user profile:", error);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
originalHandler(payload);
|
|
294
|
+
};
|
|
295
|
+
this.listeners[event] = wrappedHandler;
|
|
296
|
+
} else if (event === "miniapp-verify-action" /* MiniAppVerifyAction */) {
|
|
297
|
+
const originalHandler = handler;
|
|
298
|
+
const wrappedHandler = (payload) => {
|
|
299
|
+
if (payload.status === "success" && payload.verification_level === import_idkit_core3.VerificationLevel.Orb) {
|
|
300
|
+
compressAndPadProof(payload.proof).then(
|
|
301
|
+
(compressedProof) => {
|
|
302
|
+
payload.proof = compressedProof;
|
|
303
|
+
originalHandler(payload);
|
|
304
|
+
}
|
|
305
|
+
);
|
|
306
|
+
} else {
|
|
307
|
+
originalHandler(payload);
|
|
308
|
+
}
|
|
309
|
+
};
|
|
310
|
+
this.listeners[event] = wrappedHandler;
|
|
311
|
+
} else {
|
|
312
|
+
this.listeners[event] = handler;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
static unsubscribe(event) {
|
|
316
|
+
delete this.listeners[event];
|
|
317
|
+
}
|
|
318
|
+
static trigger(event, payload) {
|
|
319
|
+
if (!this.listeners[event]) {
|
|
320
|
+
console.error(
|
|
321
|
+
`No handler for event ${event}, payload: ${JSON.stringify(payload)}`
|
|
322
|
+
);
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
this.listeners[event](payload);
|
|
326
|
+
}
|
|
327
|
+
static async awaitCommand(event, command, executor) {
|
|
328
|
+
return new Promise((resolve) => {
|
|
329
|
+
let commandPayload = null;
|
|
330
|
+
const handleAndUnsubscribe = (payload) => {
|
|
331
|
+
this.unsubscribe(event);
|
|
332
|
+
resolve({ commandPayload, finalPayload: payload });
|
|
333
|
+
};
|
|
334
|
+
this.subscribe(event, handleAndUnsubscribe);
|
|
335
|
+
commandPayload = executor();
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
static commandsValid(worldAppSupportedCommands) {
|
|
339
|
+
let allCommandsValid = true;
|
|
340
|
+
Object.entries(this.miniKitCommandVersion).forEach(
|
|
341
|
+
([minikitCommandName, version]) => {
|
|
342
|
+
const commandInput = worldAppSupportedCommands.find(
|
|
343
|
+
(command) => command.name === minikitCommandName
|
|
344
|
+
);
|
|
345
|
+
let isCommandValid = false;
|
|
346
|
+
if (!commandInput) {
|
|
347
|
+
console.error(
|
|
348
|
+
`Command ${minikitCommandName} is not supported by the app. Try updating the app version`
|
|
349
|
+
);
|
|
350
|
+
} else {
|
|
351
|
+
if (commandInput.supported_versions.includes(version)) {
|
|
352
|
+
_MiniKit.isCommandAvailable[minikitCommandName] = true;
|
|
353
|
+
isCommandValid = true;
|
|
354
|
+
} else {
|
|
355
|
+
console.error(
|
|
356
|
+
`Command ${minikitCommandName} version ${version} is not supported by the app. Supported versions: ${commandInput.supported_versions.join(", ")}`
|
|
357
|
+
);
|
|
358
|
+
_MiniKit.isCommandAvailable[minikitCommandName] = isCommandValid;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
if (!isCommandValid) {
|
|
362
|
+
allCommandsValid = false;
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
);
|
|
366
|
+
return allCommandsValid;
|
|
367
|
+
}
|
|
368
|
+
static install(appId) {
|
|
369
|
+
if (typeof window === "undefined" || Boolean(window.MiniKit)) {
|
|
370
|
+
return {
|
|
371
|
+
success: false,
|
|
372
|
+
errorCode: "already_installed" /* AlreadyInstalled */,
|
|
373
|
+
errorMessage: MiniKitInstallErrorMessage["already_installed" /* AlreadyInstalled */]
|
|
374
|
+
};
|
|
375
|
+
}
|
|
376
|
+
if (!appId) {
|
|
377
|
+
console.warn("App ID not provided during install");
|
|
378
|
+
} else {
|
|
379
|
+
_MiniKit.appId = appId;
|
|
380
|
+
}
|
|
381
|
+
if (!window.WorldApp) {
|
|
382
|
+
return {
|
|
383
|
+
success: false,
|
|
384
|
+
errorCode: "outside_of_worldapp" /* OutsideOfWorldApp */,
|
|
385
|
+
errorMessage: MiniKitInstallErrorMessage["outside_of_worldapp" /* OutsideOfWorldApp */]
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
_MiniKit.user.optedIntoOptionalAnalytics = window.WorldApp.is_optional_analytics;
|
|
389
|
+
_MiniKit.user.deviceOS = window.WorldApp.device_os;
|
|
390
|
+
_MiniKit.user.worldAppVersion = window.WorldApp.world_app_version;
|
|
391
|
+
try {
|
|
392
|
+
window.MiniKit = _MiniKit;
|
|
393
|
+
this.sendInit();
|
|
394
|
+
} catch (error) {
|
|
395
|
+
console.error(
|
|
396
|
+
MiniKitInstallErrorMessage["unknown" /* Unknown */],
|
|
397
|
+
error
|
|
398
|
+
);
|
|
399
|
+
return {
|
|
400
|
+
success: false,
|
|
401
|
+
errorCode: "unknown" /* Unknown */,
|
|
402
|
+
errorMessage: MiniKitInstallErrorMessage["unknown" /* Unknown */]
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
if (!this.commandsValid(window.WorldApp.supported_commands)) {
|
|
406
|
+
return {
|
|
407
|
+
success: false,
|
|
408
|
+
errorCode: "app_out_of_date" /* AppOutOfDate */,
|
|
409
|
+
errorMessage: MiniKitInstallErrorMessage["app_out_of_date" /* AppOutOfDate */]
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
_MiniKit.isReady = true;
|
|
413
|
+
return { success: true };
|
|
414
|
+
}
|
|
415
|
+
static isInstalled(debug) {
|
|
416
|
+
const isInstalled = _MiniKit.isReady && Boolean(window.MiniKit);
|
|
417
|
+
if (!isInstalled)
|
|
418
|
+
console.error(
|
|
419
|
+
"MiniKit is not installed. Make sure you're running the application inside of World App"
|
|
420
|
+
);
|
|
421
|
+
if (debug && isInstalled) console.log("MiniKit is alive!");
|
|
422
|
+
return isInstalled;
|
|
423
|
+
}
|
|
424
|
+
};
|
|
425
|
+
_MiniKit.MINIKIT_VERSION = 1;
|
|
426
|
+
_MiniKit.miniKitCommandVersion = {
|
|
427
|
+
["verify" /* Verify */]: 1,
|
|
428
|
+
["pay" /* Pay */]: 1,
|
|
429
|
+
["wallet-auth" /* WalletAuth */]: 1,
|
|
430
|
+
["send-transaction" /* SendTransaction */]: 1,
|
|
431
|
+
["sign-message" /* SignMessage */]: 1,
|
|
432
|
+
["sign-typed-data" /* SignTypedData */]: 1,
|
|
433
|
+
["share-contacts" /* ShareContacts */]: 1,
|
|
434
|
+
["request-permission" /* RequestPermission */]: 1,
|
|
435
|
+
["get-permissions" /* GetPermissions */]: 1,
|
|
436
|
+
["send-haptic-feedback" /* SendHapticFeedback */]: 1
|
|
437
|
+
// [Command.ShareFiles]: 1,
|
|
438
|
+
};
|
|
439
|
+
_MiniKit.isCommandAvailable = {
|
|
440
|
+
["verify" /* Verify */]: false,
|
|
441
|
+
["pay" /* Pay */]: false,
|
|
442
|
+
["wallet-auth" /* WalletAuth */]: false,
|
|
443
|
+
["send-transaction" /* SendTransaction */]: false,
|
|
444
|
+
["sign-message" /* SignMessage */]: false,
|
|
445
|
+
["sign-typed-data" /* SignTypedData */]: false,
|
|
446
|
+
["share-contacts" /* ShareContacts */]: false,
|
|
447
|
+
["request-permission" /* RequestPermission */]: false,
|
|
448
|
+
["get-permissions" /* GetPermissions */]: false,
|
|
449
|
+
["send-haptic-feedback" /* SendHapticFeedback */]: false
|
|
450
|
+
// [Command.ShareFiles]: false,
|
|
451
|
+
};
|
|
452
|
+
_MiniKit.listeners = {
|
|
453
|
+
["miniapp-verify-action" /* MiniAppVerifyAction */]: () => {
|
|
454
|
+
},
|
|
455
|
+
["miniapp-payment" /* MiniAppPayment */]: () => {
|
|
456
|
+
},
|
|
457
|
+
["miniapp-wallet-auth" /* MiniAppWalletAuth */]: () => {
|
|
458
|
+
},
|
|
459
|
+
["miniapp-send-transaction" /* MiniAppSendTransaction */]: () => {
|
|
460
|
+
},
|
|
461
|
+
["miniapp-sign-message" /* MiniAppSignMessage */]: () => {
|
|
462
|
+
},
|
|
463
|
+
["miniapp-sign-typed-data" /* MiniAppSignTypedData */]: () => {
|
|
464
|
+
},
|
|
465
|
+
["miniapp-share-contacts" /* MiniAppShareContacts */]: () => {
|
|
466
|
+
},
|
|
467
|
+
["miniapp-request-permission" /* MiniAppRequestPermission */]: () => {
|
|
468
|
+
},
|
|
469
|
+
["miniapp-get-permissions" /* MiniAppGetPermissions */]: () => {
|
|
470
|
+
},
|
|
471
|
+
["miniapp-send-haptic-feedback" /* MiniAppSendHapticFeedback */]: () => {
|
|
472
|
+
},
|
|
473
|
+
["miniapp-share-files" /* MiniAppShareFiles */]: () => {
|
|
474
|
+
}
|
|
475
|
+
};
|
|
476
|
+
_MiniKit.appId = null;
|
|
477
|
+
_MiniKit.user = {};
|
|
478
|
+
_MiniKit.isReady = false;
|
|
479
|
+
_MiniKit.getUserByAddress = async (address) => {
|
|
480
|
+
const userProfile = await getUserProfile(
|
|
481
|
+
address ?? _MiniKit.user.walletAddress
|
|
482
|
+
);
|
|
483
|
+
return {
|
|
484
|
+
walletAddress: address ?? _MiniKit.user.walletAddress,
|
|
485
|
+
username: userProfile.username,
|
|
486
|
+
profilePictureUrl: userProfile.profile_picture_url
|
|
487
|
+
};
|
|
488
|
+
};
|
|
489
|
+
_MiniKit.getUserByUsername = async (username) => {
|
|
490
|
+
const res = await fetch(
|
|
491
|
+
`https://usernames.worldcoin.org/api/v1/${username}`,
|
|
492
|
+
{
|
|
493
|
+
method: "GET",
|
|
494
|
+
headers: {
|
|
495
|
+
"Content-Type": "application/json"
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
);
|
|
499
|
+
const user = await res.json();
|
|
500
|
+
return {
|
|
501
|
+
walletAddress: user.address,
|
|
502
|
+
username: user.username,
|
|
503
|
+
profilePictureUrl: user.profile_picture_url
|
|
504
|
+
};
|
|
505
|
+
};
|
|
506
|
+
// Simply re-exporting the existing function
|
|
507
|
+
_MiniKit.getUserInfo = _MiniKit.getUserByAddress;
|
|
508
|
+
_MiniKit.commands = {
|
|
509
|
+
verify: (payload) => {
|
|
510
|
+
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["verify" /* Verify */]) {
|
|
511
|
+
console.error(
|
|
512
|
+
"'verify' command is unavailable. Check MiniKit.install() or update the app version"
|
|
513
|
+
);
|
|
514
|
+
return null;
|
|
515
|
+
}
|
|
516
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
517
|
+
const eventPayload = {
|
|
518
|
+
action: (0, import_hashing.encodeAction)(payload.action),
|
|
519
|
+
signal: (0, import_hashing.generateSignal)(payload.signal).digest,
|
|
520
|
+
verification_level: payload.verification_level || import_idkit_core3.VerificationLevel.Orb,
|
|
521
|
+
timestamp
|
|
522
|
+
};
|
|
523
|
+
sendMiniKitEvent({
|
|
524
|
+
command: "verify" /* Verify */,
|
|
525
|
+
version: _MiniKit.miniKitCommandVersion["verify" /* Verify */],
|
|
526
|
+
payload: eventPayload
|
|
527
|
+
});
|
|
528
|
+
return eventPayload;
|
|
529
|
+
},
|
|
530
|
+
pay: (payload) => {
|
|
531
|
+
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["pay" /* Pay */]) {
|
|
532
|
+
console.error(
|
|
533
|
+
"'pay' command is unavailable. Check MiniKit.install() or update the app version"
|
|
534
|
+
);
|
|
535
|
+
return null;
|
|
536
|
+
}
|
|
537
|
+
if (!validatePaymentPayload(payload)) {
|
|
538
|
+
return null;
|
|
539
|
+
}
|
|
540
|
+
const eventPayload = {
|
|
541
|
+
...payload,
|
|
542
|
+
network: "worldchain" /* WorldChain */
|
|
543
|
+
};
|
|
544
|
+
sendMiniKitEvent({
|
|
545
|
+
command: "pay" /* Pay */,
|
|
546
|
+
version: _MiniKit.miniKitCommandVersion["pay" /* Pay */],
|
|
547
|
+
payload: eventPayload
|
|
548
|
+
});
|
|
549
|
+
return eventPayload;
|
|
550
|
+
},
|
|
551
|
+
walletAuth: (payload) => {
|
|
552
|
+
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["wallet-auth" /* WalletAuth */]) {
|
|
553
|
+
console.error(
|
|
554
|
+
"'walletAuth' command is unavailable. Check MiniKit.install() or update the app version"
|
|
555
|
+
);
|
|
556
|
+
return null;
|
|
557
|
+
}
|
|
558
|
+
const validationResult = validateWalletAuthCommandInput(payload);
|
|
559
|
+
if (!validationResult.valid) {
|
|
560
|
+
console.error(
|
|
561
|
+
"Failed to validate wallet auth input:\n\n -->",
|
|
562
|
+
validationResult.message
|
|
563
|
+
);
|
|
564
|
+
return null;
|
|
565
|
+
}
|
|
566
|
+
let protocol = null;
|
|
567
|
+
try {
|
|
568
|
+
const currentUrl = new URL(window.location.href);
|
|
569
|
+
protocol = currentUrl.protocol.split(":")[0];
|
|
570
|
+
} catch (error) {
|
|
571
|
+
console.error("Failed to get current URL", error);
|
|
572
|
+
return null;
|
|
573
|
+
}
|
|
574
|
+
const siweMessage = generateSiweMessage({
|
|
575
|
+
scheme: protocol,
|
|
576
|
+
domain: window.location.host,
|
|
577
|
+
statement: payload.statement ?? void 0,
|
|
578
|
+
uri: window.location.href,
|
|
579
|
+
version: "1",
|
|
580
|
+
chain_id: 480,
|
|
581
|
+
nonce: payload.nonce,
|
|
582
|
+
issued_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
583
|
+
expiration_time: payload.expirationTime?.toISOString() ?? void 0,
|
|
584
|
+
not_before: payload.notBefore?.toISOString() ?? void 0,
|
|
585
|
+
request_id: payload.requestId ?? void 0
|
|
586
|
+
});
|
|
587
|
+
const walletAuthPayload = { siweMessage };
|
|
588
|
+
sendMiniKitEvent({
|
|
589
|
+
command: "wallet-auth" /* WalletAuth */,
|
|
590
|
+
version: _MiniKit.miniKitCommandVersion["wallet-auth" /* WalletAuth */],
|
|
591
|
+
payload: walletAuthPayload
|
|
592
|
+
});
|
|
593
|
+
return walletAuthPayload;
|
|
594
|
+
},
|
|
595
|
+
sendTransaction: (payload) => {
|
|
596
|
+
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["send-transaction" /* SendTransaction */]) {
|
|
597
|
+
console.error(
|
|
598
|
+
"'sendTransaction' command is unavailable. Check MiniKit.install() or update the app version"
|
|
599
|
+
);
|
|
600
|
+
return null;
|
|
601
|
+
}
|
|
602
|
+
const validatedPayload = validateSendTransactionPayload(payload);
|
|
603
|
+
sendMiniKitEvent({
|
|
604
|
+
command: "send-transaction" /* SendTransaction */,
|
|
605
|
+
version: _MiniKit.miniKitCommandVersion["send-transaction" /* SendTransaction */],
|
|
606
|
+
payload: validatedPayload
|
|
607
|
+
});
|
|
608
|
+
return validatedPayload;
|
|
609
|
+
},
|
|
610
|
+
signMessage: (payload) => {
|
|
611
|
+
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["sign-message" /* SignMessage */]) {
|
|
612
|
+
console.error(
|
|
613
|
+
"'signMessage' command is unavailable. Check MiniKit.install() or update the app version"
|
|
614
|
+
);
|
|
615
|
+
return null;
|
|
616
|
+
}
|
|
617
|
+
sendMiniKitEvent({
|
|
618
|
+
command: "sign-message" /* SignMessage */,
|
|
619
|
+
version: _MiniKit.miniKitCommandVersion["sign-message" /* SignMessage */],
|
|
620
|
+
payload
|
|
621
|
+
});
|
|
622
|
+
return payload;
|
|
623
|
+
},
|
|
624
|
+
signTypedData: (payload) => {
|
|
625
|
+
if (typeof window === "undefined" || !_MiniKit.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
|
+
sendMiniKitEvent({
|
|
632
|
+
command: "sign-typed-data" /* SignTypedData */,
|
|
633
|
+
version: _MiniKit.miniKitCommandVersion["sign-typed-data" /* SignTypedData */],
|
|
634
|
+
payload
|
|
635
|
+
});
|
|
636
|
+
return payload;
|
|
637
|
+
},
|
|
638
|
+
shareContacts: (payload) => {
|
|
639
|
+
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["sign-typed-data" /* SignTypedData */]) {
|
|
640
|
+
console.error(
|
|
641
|
+
"'shareContacts' command is unavailable. Check MiniKit.install() or update the app version"
|
|
642
|
+
);
|
|
643
|
+
return null;
|
|
644
|
+
}
|
|
645
|
+
sendMiniKitEvent({
|
|
646
|
+
command: "share-contacts" /* ShareContacts */,
|
|
647
|
+
version: _MiniKit.miniKitCommandVersion["share-contacts" /* ShareContacts */],
|
|
648
|
+
payload
|
|
649
|
+
});
|
|
650
|
+
return payload;
|
|
651
|
+
},
|
|
652
|
+
requestPermission: (payload) => {
|
|
653
|
+
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["request-permission" /* RequestPermission */]) {
|
|
654
|
+
console.error(
|
|
655
|
+
"'requestPermission' command is unavailable. Check MiniKit.install() or update the app version"
|
|
656
|
+
);
|
|
657
|
+
return null;
|
|
658
|
+
}
|
|
659
|
+
sendMiniKitEvent({
|
|
660
|
+
command: "request-permission" /* RequestPermission */,
|
|
661
|
+
version: _MiniKit.miniKitCommandVersion["request-permission" /* RequestPermission */],
|
|
662
|
+
payload
|
|
663
|
+
});
|
|
664
|
+
return payload;
|
|
665
|
+
},
|
|
666
|
+
getPermissions: () => {
|
|
667
|
+
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["get-permissions" /* GetPermissions */]) {
|
|
668
|
+
console.error(
|
|
669
|
+
"'getPermissions' command is unavailable. Check MiniKit.install() or update the app version"
|
|
670
|
+
);
|
|
671
|
+
return null;
|
|
672
|
+
}
|
|
673
|
+
sendMiniKitEvent({
|
|
674
|
+
command: "get-permissions" /* GetPermissions */,
|
|
675
|
+
version: _MiniKit.miniKitCommandVersion["get-permissions" /* GetPermissions */],
|
|
676
|
+
payload: {}
|
|
677
|
+
});
|
|
678
|
+
return {
|
|
679
|
+
status: "sent"
|
|
680
|
+
};
|
|
681
|
+
},
|
|
682
|
+
sendHapticFeedback: (payload) => {
|
|
683
|
+
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["send-haptic-feedback" /* SendHapticFeedback */]) {
|
|
684
|
+
console.error(
|
|
685
|
+
"'sendHapticFeedback' command is unavailable. Check MiniKit.install() or update the app version"
|
|
686
|
+
);
|
|
687
|
+
return null;
|
|
688
|
+
}
|
|
689
|
+
sendMiniKitEvent({
|
|
690
|
+
command: "send-haptic-feedback" /* SendHapticFeedback */,
|
|
691
|
+
version: _MiniKit.miniKitCommandVersion["send-haptic-feedback" /* SendHapticFeedback */],
|
|
692
|
+
payload
|
|
693
|
+
});
|
|
694
|
+
return payload;
|
|
695
|
+
}
|
|
696
|
+
// shareFiles: (payload: ShareFilesInput): ShareFilesPayload | null => {
|
|
697
|
+
// if (
|
|
698
|
+
// typeof window === 'undefined' ||
|
|
699
|
+
// !this.isCommandAvailable[Command.ShareFiles]
|
|
700
|
+
// ) {
|
|
701
|
+
// console.error(
|
|
702
|
+
// "'shareFiles' command is unavailable. Check MiniKit.install() or update the app version",
|
|
703
|
+
// );
|
|
704
|
+
// return null;
|
|
705
|
+
// }
|
|
706
|
+
// sendMiniKitEvent<WebViewBasePayload>({
|
|
707
|
+
// command: Command.ShareFiles,
|
|
708
|
+
// version: this.miniKitCommandVersion[Command.ShareFiles],
|
|
709
|
+
// payload,
|
|
710
|
+
// });
|
|
711
|
+
// return payload;
|
|
712
|
+
// },
|
|
713
|
+
};
|
|
714
|
+
/**
|
|
715
|
+
* This object contains async versions of all the commands.
|
|
716
|
+
* Instead of using event listeners, you can just `await` these.
|
|
717
|
+
*
|
|
718
|
+
* They return a standardized object
|
|
719
|
+
*
|
|
720
|
+
* commandPayload - object returned by the command function
|
|
721
|
+
*
|
|
722
|
+
* finalPayload - object returned by the event listener, or in other words, WorldApp response
|
|
723
|
+
*/
|
|
724
|
+
_MiniKit.commandsAsync = {
|
|
725
|
+
verify: async (payload) => {
|
|
726
|
+
return new Promise(async (resolve, reject) => {
|
|
727
|
+
try {
|
|
728
|
+
const response = await _MiniKit.awaitCommand(
|
|
729
|
+
"miniapp-verify-action" /* MiniAppVerifyAction */,
|
|
730
|
+
"verify" /* Verify */,
|
|
731
|
+
() => _MiniKit.commands.verify(payload)
|
|
732
|
+
);
|
|
733
|
+
if (response.finalPayload.status === "success" && response.finalPayload.verification_level === import_idkit_core3.VerificationLevel.Orb) {
|
|
734
|
+
response.finalPayload.proof = await compressAndPadProof(
|
|
735
|
+
response.finalPayload.proof
|
|
736
|
+
);
|
|
737
|
+
}
|
|
738
|
+
resolve(response);
|
|
739
|
+
} catch (error) {
|
|
740
|
+
reject(error);
|
|
741
|
+
}
|
|
742
|
+
});
|
|
743
|
+
},
|
|
744
|
+
pay: async (payload) => {
|
|
745
|
+
return new Promise(async (resolve, reject) => {
|
|
746
|
+
try {
|
|
747
|
+
const response = await _MiniKit.awaitCommand(
|
|
748
|
+
"miniapp-payment" /* MiniAppPayment */,
|
|
749
|
+
"pay" /* Pay */,
|
|
750
|
+
() => _MiniKit.commands.pay(payload)
|
|
751
|
+
);
|
|
752
|
+
resolve(response);
|
|
753
|
+
} catch (error) {
|
|
754
|
+
reject(error);
|
|
755
|
+
}
|
|
756
|
+
});
|
|
757
|
+
},
|
|
758
|
+
walletAuth: async (payload) => {
|
|
759
|
+
return new Promise(async (resolve, reject) => {
|
|
760
|
+
try {
|
|
761
|
+
const response = await _MiniKit.awaitCommand(
|
|
762
|
+
"miniapp-wallet-auth" /* MiniAppWalletAuth */,
|
|
763
|
+
"wallet-auth" /* WalletAuth */,
|
|
764
|
+
() => _MiniKit.commands.walletAuth(payload)
|
|
765
|
+
);
|
|
766
|
+
return resolve(response);
|
|
767
|
+
} catch (error) {
|
|
768
|
+
reject(error);
|
|
769
|
+
}
|
|
770
|
+
});
|
|
771
|
+
},
|
|
772
|
+
sendTransaction: async (payload) => {
|
|
773
|
+
return new Promise(async (resolve, reject) => {
|
|
774
|
+
try {
|
|
775
|
+
const response = await _MiniKit.awaitCommand(
|
|
776
|
+
"miniapp-send-transaction" /* MiniAppSendTransaction */,
|
|
777
|
+
"send-transaction" /* SendTransaction */,
|
|
778
|
+
() => _MiniKit.commands.sendTransaction(payload)
|
|
779
|
+
);
|
|
780
|
+
return resolve(response);
|
|
781
|
+
} catch (error) {
|
|
782
|
+
reject(error);
|
|
783
|
+
}
|
|
784
|
+
});
|
|
785
|
+
},
|
|
786
|
+
signMessage: async (payload) => {
|
|
787
|
+
return new Promise(async (resolve, reject) => {
|
|
788
|
+
try {
|
|
789
|
+
const response = await _MiniKit.awaitCommand(
|
|
790
|
+
"miniapp-sign-message" /* MiniAppSignMessage */,
|
|
791
|
+
"sign-message" /* SignMessage */,
|
|
792
|
+
() => _MiniKit.commands.signMessage(payload)
|
|
793
|
+
);
|
|
794
|
+
return resolve(response);
|
|
795
|
+
} catch (error) {
|
|
796
|
+
reject(error);
|
|
797
|
+
}
|
|
798
|
+
});
|
|
799
|
+
},
|
|
800
|
+
signTypedData: async (payload) => {
|
|
801
|
+
return new Promise(async (resolve, reject) => {
|
|
802
|
+
try {
|
|
803
|
+
const response = await _MiniKit.awaitCommand(
|
|
804
|
+
"miniapp-sign-typed-data" /* MiniAppSignTypedData */,
|
|
805
|
+
"sign-typed-data" /* SignTypedData */,
|
|
806
|
+
() => _MiniKit.commands.signTypedData(payload)
|
|
807
|
+
);
|
|
808
|
+
return resolve(response);
|
|
809
|
+
} catch (error) {
|
|
810
|
+
reject(error);
|
|
811
|
+
}
|
|
812
|
+
});
|
|
813
|
+
},
|
|
814
|
+
shareContacts: async (payload) => {
|
|
815
|
+
return new Promise(async (resolve, reject) => {
|
|
816
|
+
try {
|
|
817
|
+
const response = await _MiniKit.awaitCommand(
|
|
818
|
+
"miniapp-share-contacts" /* MiniAppShareContacts */,
|
|
819
|
+
"share-contacts" /* ShareContacts */,
|
|
820
|
+
() => _MiniKit.commands.shareContacts(payload)
|
|
821
|
+
);
|
|
822
|
+
return resolve(response);
|
|
823
|
+
} catch (error) {
|
|
824
|
+
reject(error);
|
|
825
|
+
}
|
|
826
|
+
});
|
|
827
|
+
},
|
|
828
|
+
requestPermission: async (payload) => {
|
|
829
|
+
return new Promise(async (resolve, reject) => {
|
|
830
|
+
try {
|
|
831
|
+
const response = await _MiniKit.awaitCommand(
|
|
832
|
+
"miniapp-request-permission" /* MiniAppRequestPermission */,
|
|
833
|
+
"request-permission" /* RequestPermission */,
|
|
834
|
+
() => _MiniKit.commands.requestPermission(payload)
|
|
835
|
+
);
|
|
836
|
+
resolve(response);
|
|
837
|
+
} catch (error) {
|
|
838
|
+
reject(error);
|
|
839
|
+
}
|
|
840
|
+
});
|
|
841
|
+
},
|
|
842
|
+
getPermissions: async () => {
|
|
843
|
+
return new Promise(async (resolve, reject) => {
|
|
844
|
+
try {
|
|
845
|
+
const response = await _MiniKit.awaitCommand(
|
|
846
|
+
"miniapp-get-permissions" /* MiniAppGetPermissions */,
|
|
847
|
+
"get-permissions" /* GetPermissions */,
|
|
848
|
+
() => _MiniKit.commands.getPermissions()
|
|
849
|
+
);
|
|
850
|
+
resolve(response);
|
|
851
|
+
} catch (error) {
|
|
852
|
+
reject(error);
|
|
853
|
+
}
|
|
854
|
+
});
|
|
855
|
+
},
|
|
856
|
+
sendHapticFeedback: async (payload) => {
|
|
857
|
+
return new Promise(async (resolve, reject) => {
|
|
858
|
+
try {
|
|
859
|
+
const response = await _MiniKit.awaitCommand(
|
|
860
|
+
"miniapp-send-haptic-feedback" /* MiniAppSendHapticFeedback */,
|
|
861
|
+
"send-haptic-feedback" /* SendHapticFeedback */,
|
|
862
|
+
() => _MiniKit.commands.sendHapticFeedback(payload)
|
|
863
|
+
);
|
|
864
|
+
resolve(response);
|
|
865
|
+
} catch (error) {
|
|
866
|
+
reject(error);
|
|
867
|
+
}
|
|
868
|
+
});
|
|
869
|
+
}
|
|
870
|
+
// shareFiles: async (
|
|
871
|
+
// payload: ShareFilesInput,
|
|
872
|
+
// ): AsyncHandlerReturn<
|
|
873
|
+
// ShareFilesPayload | null,
|
|
874
|
+
// MiniAppShareFilesPayload
|
|
875
|
+
// > => {
|
|
876
|
+
// return new Promise(async (resolve, reject) => {
|
|
877
|
+
// try {
|
|
878
|
+
// const response = await MiniKit.awaitCommand(
|
|
879
|
+
// ResponseEvent.MiniAppShareFiles,
|
|
880
|
+
// Command.ShareFiles,
|
|
881
|
+
// () => this.commands.shareFiles(payload),
|
|
882
|
+
// );
|
|
883
|
+
// resolve(response);
|
|
884
|
+
// } catch (error) {
|
|
885
|
+
// reject(error);
|
|
886
|
+
// }
|
|
887
|
+
// });
|
|
888
|
+
// },
|
|
889
|
+
};
|
|
890
|
+
var MiniKit = _MiniKit;
|
|
891
|
+
|
|
892
|
+
// minikit-provider.tsx
|
|
893
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
894
|
+
var MiniKitContext = (0, import_react.createContext)({
|
|
895
|
+
isInstalled: false
|
|
896
|
+
});
|
|
897
|
+
var MiniKitProvider = ({
|
|
898
|
+
children,
|
|
899
|
+
props
|
|
900
|
+
}) => {
|
|
901
|
+
const [isInstalled, setIsInstalled] = (0, import_react.useState)(false);
|
|
902
|
+
(0, import_react.useEffect)(() => {
|
|
903
|
+
MiniKit.install(props?.appId);
|
|
904
|
+
MiniKit.commandsAsync.getPermissions().then(({ commandPayload: _, finalPayload }) => {
|
|
905
|
+
if (finalPayload.status === "success") {
|
|
906
|
+
MiniKit.user.permissions = {
|
|
907
|
+
notifications: finalPayload.permissions.notifications,
|
|
908
|
+
contacts: finalPayload.permissions.contacts
|
|
909
|
+
};
|
|
910
|
+
}
|
|
911
|
+
});
|
|
912
|
+
setIsInstalled(true);
|
|
913
|
+
}, [props?.appId]);
|
|
914
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MiniKitContext.Provider, { value: { isInstalled }, children });
|
|
915
|
+
};
|
|
916
|
+
var useMiniKit = () => {
|
|
917
|
+
const context = (0, import_react.useContext)(MiniKitContext);
|
|
918
|
+
if (context === void 0) {
|
|
919
|
+
throw new Error("useMiniKit must be used within a MiniKitProvider");
|
|
920
|
+
}
|
|
921
|
+
return context;
|
|
922
|
+
};
|
|
923
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
924
|
+
0 && (module.exports = {
|
|
925
|
+
MiniKitProvider,
|
|
926
|
+
useMiniKit
|
|
927
|
+
});
|