@worldcoin/minikit-js 1.7.1 → 1.9.0
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 +325 -78
- package/build/index.d.cts +60 -29
- package/build/index.d.ts +60 -29
- package/build/index.js +46 -1069
- 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 +16 -3
package/build/index.cjs
CHANGED
|
@@ -34,13 +34,14 @@ __export(core_exports, {
|
|
|
34
34
|
RequestPermissionErrorCodes: () => RequestPermissionErrorCodes,
|
|
35
35
|
RequestPermissionErrorMessage: () => RequestPermissionErrorMessage,
|
|
36
36
|
ResponseEvent: () => ResponseEvent,
|
|
37
|
-
SAFE_CONTRACT_ABI: () => SAFE_CONTRACT_ABI,
|
|
38
37
|
SendHapticFeedbackErrorCodes: () => SendHapticFeedbackErrorCodes,
|
|
39
38
|
SendHapticFeedbackErrorMessage: () => SendHapticFeedbackErrorMessage,
|
|
40
39
|
SendTransactionErrorCodes: () => SendTransactionErrorCodes,
|
|
41
40
|
SendTransactionErrorMessage: () => SendTransactionErrorMessage,
|
|
42
41
|
ShareContactsErrorCodes: () => ShareContactsErrorCodes,
|
|
43
42
|
ShareContactsErrorMessage: () => ShareContactsErrorMessage,
|
|
43
|
+
ShareFilesErrorCodes: () => ShareFilesErrorCodes,
|
|
44
|
+
ShareFilesErrorMessage: () => ShareFilesErrorMessage,
|
|
44
45
|
SignMessageErrorCodes: () => SignMessageErrorCodes,
|
|
45
46
|
SignMessageErrorMessage: () => SignMessageErrorMessage,
|
|
46
47
|
SignTypedDataErrorCodes: () => SignTypedDataErrorCodes,
|
|
@@ -110,9 +111,63 @@ var validatePaymentPayload = (payload) => {
|
|
|
110
111
|
return true;
|
|
111
112
|
};
|
|
112
113
|
|
|
113
|
-
// helpers/
|
|
114
|
+
// helpers/proof/index.ts
|
|
114
115
|
var import_viem = require("viem");
|
|
115
116
|
var import_chains = require("viem/chains");
|
|
117
|
+
var semaphoreVerifierAddress = "0x79f46b94d134109EbcbbddBAeD0E88790409A0e4";
|
|
118
|
+
var semaphoreVerifierAbi = [
|
|
119
|
+
{
|
|
120
|
+
inputs: [
|
|
121
|
+
{
|
|
122
|
+
internalType: "uint256[8]",
|
|
123
|
+
name: "proof",
|
|
124
|
+
type: "uint256[8]"
|
|
125
|
+
}
|
|
126
|
+
],
|
|
127
|
+
name: "compressProof",
|
|
128
|
+
outputs: [
|
|
129
|
+
{
|
|
130
|
+
internalType: "uint256[4]",
|
|
131
|
+
name: "compressed",
|
|
132
|
+
type: "uint256[4]"
|
|
133
|
+
}
|
|
134
|
+
],
|
|
135
|
+
stateMutability: "view",
|
|
136
|
+
type: "function"
|
|
137
|
+
}
|
|
138
|
+
];
|
|
139
|
+
var compressAndPadProof = async (proof, rpcUrl) => {
|
|
140
|
+
try {
|
|
141
|
+
const publicClient = (0, import_viem.createPublicClient)({
|
|
142
|
+
chain: import_chains.worldchain,
|
|
143
|
+
transport: (0, import_viem.http)(
|
|
144
|
+
rpcUrl || "https://worldchain-mainnet.g.alchemy.com/public"
|
|
145
|
+
)
|
|
146
|
+
});
|
|
147
|
+
const decodedProof = (0, import_viem.decodeAbiParameters)(
|
|
148
|
+
[{ type: "uint256[8]" }],
|
|
149
|
+
proof
|
|
150
|
+
)[0];
|
|
151
|
+
const compressedProof = await publicClient.readContract({
|
|
152
|
+
address: semaphoreVerifierAddress,
|
|
153
|
+
abi: semaphoreVerifierAbi,
|
|
154
|
+
functionName: "compressProof",
|
|
155
|
+
args: [decodedProof]
|
|
156
|
+
});
|
|
157
|
+
const paddedProof = [...compressedProof, 0n, 0n, 0n, 0n];
|
|
158
|
+
return (0, import_viem.encodeAbiParameters)([{ type: "uint256[8]" }], [paddedProof]);
|
|
159
|
+
} catch (e) {
|
|
160
|
+
console.log("Failed to compress proof", {
|
|
161
|
+
e,
|
|
162
|
+
proof
|
|
163
|
+
});
|
|
164
|
+
return proof;
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
// helpers/siwe/siwe.ts
|
|
169
|
+
var import_viem2 = require("viem");
|
|
170
|
+
var import_chains2 = require("viem/chains");
|
|
116
171
|
var PREAMBLE = " wants you to sign in with your Ethereum account:";
|
|
117
172
|
var URI_TAG = "URI: ";
|
|
118
173
|
var VERSION_TAG = "Version: ";
|
|
@@ -123,6 +178,52 @@ var EXP_TAG = "Expiration Time: ";
|
|
|
123
178
|
var NBF_TAG = "Not Before: ";
|
|
124
179
|
var RID_TAG = "Request ID: ";
|
|
125
180
|
var ERC_191_PREFIX = "Ethereum Signed Message:\n";
|
|
181
|
+
var EIP1271_MAGICVALUE = "0x1626ba7e";
|
|
182
|
+
var SAFE_CONTRACT_ABI = [
|
|
183
|
+
{
|
|
184
|
+
inputs: [
|
|
185
|
+
{
|
|
186
|
+
internalType: "address",
|
|
187
|
+
name: "owner",
|
|
188
|
+
type: "address"
|
|
189
|
+
}
|
|
190
|
+
],
|
|
191
|
+
name: "isOwner",
|
|
192
|
+
outputs: [
|
|
193
|
+
{
|
|
194
|
+
internalType: "bool",
|
|
195
|
+
name: "",
|
|
196
|
+
type: "bool"
|
|
197
|
+
}
|
|
198
|
+
],
|
|
199
|
+
stateMutability: "view",
|
|
200
|
+
type: "function"
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
inputs: [
|
|
204
|
+
{
|
|
205
|
+
internalType: "bytes32",
|
|
206
|
+
name: "_message",
|
|
207
|
+
type: "bytes32"
|
|
208
|
+
},
|
|
209
|
+
{
|
|
210
|
+
internalType: "bytes",
|
|
211
|
+
name: "_signature",
|
|
212
|
+
type: "bytes"
|
|
213
|
+
}
|
|
214
|
+
],
|
|
215
|
+
name: "isValidSignature",
|
|
216
|
+
outputs: [
|
|
217
|
+
{
|
|
218
|
+
internalType: "bytes4",
|
|
219
|
+
name: "",
|
|
220
|
+
type: "bytes4"
|
|
221
|
+
}
|
|
222
|
+
],
|
|
223
|
+
stateMutability: "view",
|
|
224
|
+
type: "function"
|
|
225
|
+
}
|
|
226
|
+
];
|
|
126
227
|
var tagged = (line, tag) => {
|
|
127
228
|
if (line && line.includes(tag)) {
|
|
128
229
|
return line.replace(tag, "");
|
|
@@ -219,33 +320,26 @@ var generateSiweMessage = (siweMessageData) => {
|
|
|
219
320
|
}
|
|
220
321
|
return siweMessage;
|
|
221
322
|
};
|
|
222
|
-
var
|
|
223
|
-
{
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
stateMutability: "view",
|
|
240
|
-
type: "function"
|
|
241
|
-
}
|
|
242
|
-
];
|
|
243
|
-
var verifySiweMessage = async (payload, nonce, statement, requestId, userProvider) => {
|
|
244
|
-
if (typeof window !== "undefined") {
|
|
245
|
-
throw new Error("Verify can only be called in the backend");
|
|
323
|
+
var verifySiweMessage = (payload, nonce, statement, requestId, userProvider) => {
|
|
324
|
+
if (payload.version === 2) {
|
|
325
|
+
return verifySiweMessageV2(
|
|
326
|
+
payload,
|
|
327
|
+
nonce,
|
|
328
|
+
statement,
|
|
329
|
+
requestId,
|
|
330
|
+
userProvider
|
|
331
|
+
);
|
|
332
|
+
} else {
|
|
333
|
+
return verifySiweMessageV1(
|
|
334
|
+
payload,
|
|
335
|
+
nonce,
|
|
336
|
+
statement,
|
|
337
|
+
requestId,
|
|
338
|
+
userProvider
|
|
339
|
+
);
|
|
246
340
|
}
|
|
247
|
-
|
|
248
|
-
|
|
341
|
+
};
|
|
342
|
+
var validateMessage = (siweMessageData, nonce, statement, requestId) => {
|
|
249
343
|
if (siweMessageData.expiration_time) {
|
|
250
344
|
const expirationTime = new Date(siweMessageData.expiration_time);
|
|
251
345
|
if (expirationTime < /* @__PURE__ */ new Date()) {
|
|
@@ -273,16 +367,25 @@ var verifySiweMessage = async (payload, nonce, statement, requestId, userProvide
|
|
|
273
367
|
`Request ID mismatch. Got: ${siweMessageData.request_id}, Expected: ${requestId}`
|
|
274
368
|
);
|
|
275
369
|
}
|
|
276
|
-
|
|
370
|
+
return true;
|
|
371
|
+
};
|
|
372
|
+
var verifySiweMessageV1 = async (payload, nonce, statement, requestId, userProvider) => {
|
|
373
|
+
if (typeof window !== "undefined") {
|
|
374
|
+
throw new Error("Wallet auth payload can only be verified in the backend");
|
|
375
|
+
}
|
|
376
|
+
const { message, signature, address } = payload;
|
|
377
|
+
const siweMessageData = parseSiweMessage(message);
|
|
378
|
+
validateMessage(siweMessageData, nonce, statement, requestId);
|
|
379
|
+
let provider = userProvider || (0, import_viem2.createPublicClient)({ chain: import_chains2.worldchain, transport: (0, import_viem2.http)() });
|
|
277
380
|
const signedMessage = `${ERC_191_PREFIX}${message.length}${message}`;
|
|
278
|
-
const hashedMessage = (0,
|
|
279
|
-
const contract = (0,
|
|
381
|
+
const hashedMessage = (0, import_viem2.hashMessage)(signedMessage);
|
|
382
|
+
const contract = (0, import_viem2.getContract)({
|
|
280
383
|
address,
|
|
281
384
|
abi: SAFE_CONTRACT_ABI,
|
|
282
385
|
client: provider
|
|
283
386
|
});
|
|
284
387
|
try {
|
|
285
|
-
const recoveredAddress = await (0,
|
|
388
|
+
const recoveredAddress = await (0, import_viem2.recoverAddress)({
|
|
286
389
|
hash: hashedMessage,
|
|
287
390
|
signature: `0x${signature}`
|
|
288
391
|
});
|
|
@@ -295,6 +398,35 @@ var verifySiweMessage = async (payload, nonce, statement, requestId, userProvide
|
|
|
295
398
|
}
|
|
296
399
|
return { isValid: true, siweMessageData };
|
|
297
400
|
};
|
|
401
|
+
var verifySiweMessageV2 = async (payload, nonce, statement, requestId, userProvider) => {
|
|
402
|
+
if (typeof window !== "undefined") {
|
|
403
|
+
throw new Error("Wallet auth payload can only be verified in the backend");
|
|
404
|
+
}
|
|
405
|
+
const { message, signature, address } = payload;
|
|
406
|
+
const siweMessageData = parseSiweMessage(message);
|
|
407
|
+
if (!validateMessage(siweMessageData, nonce, statement, requestId)) {
|
|
408
|
+
throw new Error("Validation failed");
|
|
409
|
+
}
|
|
410
|
+
try {
|
|
411
|
+
const walletContract = (0, import_viem2.getContract)({
|
|
412
|
+
address,
|
|
413
|
+
abi: SAFE_CONTRACT_ABI,
|
|
414
|
+
client: userProvider || (0, import_viem2.createPublicClient)({ chain: import_chains2.worldchain, transport: (0, import_viem2.http)() })
|
|
415
|
+
});
|
|
416
|
+
const hashedMessage = (0, import_viem2.hashMessage)(message);
|
|
417
|
+
const res = await walletContract.read.isValidSignature([
|
|
418
|
+
hashedMessage,
|
|
419
|
+
signature
|
|
420
|
+
]);
|
|
421
|
+
return {
|
|
422
|
+
isValid: res === EIP1271_MAGICVALUE,
|
|
423
|
+
siweMessageData
|
|
424
|
+
};
|
|
425
|
+
} catch (error) {
|
|
426
|
+
console.log(error);
|
|
427
|
+
throw new Error("Signature verification failed");
|
|
428
|
+
}
|
|
429
|
+
};
|
|
298
430
|
|
|
299
431
|
// helpers/siwe/validate-wallet-auth-command-input.ts
|
|
300
432
|
var validateWalletAuthCommandInput = (params) => {
|
|
@@ -327,7 +459,7 @@ var processPayload = (payload) => {
|
|
|
327
459
|
if (typeof payload === "boolean" || typeof payload === "string" || payload === null || payload === void 0) {
|
|
328
460
|
return payload;
|
|
329
461
|
}
|
|
330
|
-
if (typeof payload === "number") {
|
|
462
|
+
if (typeof payload === "number" || typeof payload === "bigint") {
|
|
331
463
|
return String(payload);
|
|
332
464
|
}
|
|
333
465
|
if (Array.isArray(payload)) {
|
|
@@ -374,7 +506,7 @@ var getUserProfile = async (address) => {
|
|
|
374
506
|
})
|
|
375
507
|
});
|
|
376
508
|
const usernames = await res.json();
|
|
377
|
-
return usernames?.[0] ?? { username: null,
|
|
509
|
+
return usernames?.[0] ?? { username: null, profile_picture_url: null };
|
|
378
510
|
};
|
|
379
511
|
|
|
380
512
|
// types/commands.ts
|
|
@@ -393,6 +525,7 @@ var Command = /* @__PURE__ */ ((Command2) => {
|
|
|
393
525
|
})(Command || {});
|
|
394
526
|
var Permission = /* @__PURE__ */ ((Permission2) => {
|
|
395
527
|
Permission2["Notifications"] = "notifications";
|
|
528
|
+
Permission2["Contacts"] = "contacts";
|
|
396
529
|
return Permission2;
|
|
397
530
|
})(Permission || {});
|
|
398
531
|
|
|
@@ -414,6 +547,7 @@ var VerificationErrorMessage = {
|
|
|
414
547
|
};
|
|
415
548
|
var PaymentErrorCodes = /* @__PURE__ */ ((PaymentErrorCodes2) => {
|
|
416
549
|
PaymentErrorCodes2["InputError"] = "input_error";
|
|
550
|
+
PaymentErrorCodes2["UserRejected"] = "user_rejected";
|
|
417
551
|
PaymentErrorCodes2["PaymentRejected"] = "payment_rejected";
|
|
418
552
|
PaymentErrorCodes2["InvalidReceiver"] = "invalid_receiver";
|
|
419
553
|
PaymentErrorCodes2["InsufficientBalance"] = "insufficient_balance";
|
|
@@ -424,6 +558,7 @@ var PaymentErrorCodes = /* @__PURE__ */ ((PaymentErrorCodes2) => {
|
|
|
424
558
|
})(PaymentErrorCodes || {});
|
|
425
559
|
var PaymentErrorMessage = {
|
|
426
560
|
["input_error" /* InputError */]: "There was a problem with this request. Please try again or contact the app owner.",
|
|
561
|
+
["user_rejected" /* UserRejected */]: "You have cancelled the payment in World App.",
|
|
427
562
|
["payment_rejected" /* PaymentRejected */]: "You've cancelled the payment in World App.",
|
|
428
563
|
["invalid_receiver" /* InvalidReceiver */]: "The receiver address is invalid. Please contact the app owner.",
|
|
429
564
|
["insufficient_balance" /* InsufficientBalance */]: "You do not have enough balance to complete this transaction.",
|
|
@@ -567,6 +702,17 @@ var SendHapticFeedbackErrorMessage = {
|
|
|
567
702
|
["generic_error" /* GenericError */]: "Something unexpected went wrong.",
|
|
568
703
|
["user_rejected" /* UserRejected */]: "User rejected the request."
|
|
569
704
|
};
|
|
705
|
+
var ShareFilesErrorCodes = /* @__PURE__ */ ((ShareFilesErrorCodes2) => {
|
|
706
|
+
ShareFilesErrorCodes2["UserRejected"] = "user_rejected";
|
|
707
|
+
ShareFilesErrorCodes2["GenericError"] = "generic_error";
|
|
708
|
+
ShareFilesErrorCodes2["InvalidFileName"] = "invalid_file_name";
|
|
709
|
+
return ShareFilesErrorCodes2;
|
|
710
|
+
})(ShareFilesErrorCodes || {});
|
|
711
|
+
var ShareFilesErrorMessage = {
|
|
712
|
+
["user_rejected" /* UserRejected */]: "User rejected the request.",
|
|
713
|
+
["generic_error" /* GenericError */]: "Something unexpected went wrong.",
|
|
714
|
+
["invalid_file_name" /* InvalidFileName */]: "Invalid file name. Make sure you include the extension"
|
|
715
|
+
};
|
|
570
716
|
|
|
571
717
|
// helpers/send-webview-event.ts
|
|
572
718
|
var sendWebviewEvent = (payload) => {
|
|
@@ -589,6 +735,7 @@ var ResponseEvent = /* @__PURE__ */ ((ResponseEvent2) => {
|
|
|
589
735
|
ResponseEvent2["MiniAppRequestPermission"] = "miniapp-request-permission";
|
|
590
736
|
ResponseEvent2["MiniAppGetPermissions"] = "miniapp-get-permissions";
|
|
591
737
|
ResponseEvent2["MiniAppSendHapticFeedback"] = "miniapp-send-haptic-feedback";
|
|
738
|
+
ResponseEvent2["MiniAppShareFiles"] = "miniapp-share-files";
|
|
592
739
|
return ResponseEvent2;
|
|
593
740
|
})(ResponseEvent || {});
|
|
594
741
|
|
|
@@ -606,16 +753,34 @@ var _MiniKit = class _MiniKit {
|
|
|
606
753
|
static subscribe(event, handler) {
|
|
607
754
|
if (event === "miniapp-wallet-auth" /* MiniAppWalletAuth */) {
|
|
608
755
|
const originalHandler = handler;
|
|
609
|
-
const wrappedHandler = (payload) => {
|
|
756
|
+
const wrappedHandler = async (payload) => {
|
|
610
757
|
if (payload.status === "success") {
|
|
611
|
-
_MiniKit.walletAddress = payload.address;
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
758
|
+
_MiniKit.user.walletAddress = payload.address;
|
|
759
|
+
try {
|
|
760
|
+
const user = await _MiniKit.getUserByAddress(payload.address);
|
|
761
|
+
_MiniKit.user = { ..._MiniKit.user, ...user };
|
|
762
|
+
} catch (error) {
|
|
763
|
+
console.error("Failed to fetch user profile:", error);
|
|
764
|
+
}
|
|
615
765
|
}
|
|
616
766
|
originalHandler(payload);
|
|
617
767
|
};
|
|
618
768
|
this.listeners[event] = wrappedHandler;
|
|
769
|
+
} else if (event === "miniapp-verify-action" /* MiniAppVerifyAction */) {
|
|
770
|
+
const originalHandler = handler;
|
|
771
|
+
const wrappedHandler = (payload) => {
|
|
772
|
+
if (payload.status === "success" && payload.verification_level === import_idkit_core3.VerificationLevel.Orb) {
|
|
773
|
+
compressAndPadProof(payload.proof).then(
|
|
774
|
+
(compressedProof) => {
|
|
775
|
+
payload.proof = compressedProof;
|
|
776
|
+
originalHandler(payload);
|
|
777
|
+
}
|
|
778
|
+
);
|
|
779
|
+
} else {
|
|
780
|
+
originalHandler(payload);
|
|
781
|
+
}
|
|
782
|
+
};
|
|
783
|
+
this.listeners[event] = wrappedHandler;
|
|
619
784
|
} else {
|
|
620
785
|
this.listeners[event] = handler;
|
|
621
786
|
}
|
|
@@ -625,7 +790,9 @@ var _MiniKit = class _MiniKit {
|
|
|
625
790
|
}
|
|
626
791
|
static trigger(event, payload) {
|
|
627
792
|
if (!this.listeners[event]) {
|
|
628
|
-
console.error(
|
|
793
|
+
console.error(
|
|
794
|
+
`No handler for event ${event}, payload: ${JSON.stringify(payload)}`
|
|
795
|
+
);
|
|
629
796
|
return;
|
|
630
797
|
}
|
|
631
798
|
this.listeners[event](payload);
|
|
@@ -641,22 +808,35 @@ var _MiniKit = class _MiniKit {
|
|
|
641
808
|
commandPayload = executor();
|
|
642
809
|
});
|
|
643
810
|
}
|
|
644
|
-
static commandsValid(
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
811
|
+
static commandsValid(worldAppSupportedCommands) {
|
|
812
|
+
let allCommandsValid = true;
|
|
813
|
+
Object.entries(this.miniKitCommandVersion).forEach(
|
|
814
|
+
([minikitCommandName, version]) => {
|
|
815
|
+
const commandInput = worldAppSupportedCommands.find(
|
|
816
|
+
(command) => command.name === minikitCommandName
|
|
649
817
|
);
|
|
818
|
+
let isCommandValid = false;
|
|
650
819
|
if (!commandInput) {
|
|
651
820
|
console.error(
|
|
652
|
-
`Command ${
|
|
821
|
+
`Command ${minikitCommandName} is not supported by the app. Try updating the app version`
|
|
653
822
|
);
|
|
654
823
|
} else {
|
|
655
|
-
|
|
824
|
+
if (commandInput.supported_versions.includes(version)) {
|
|
825
|
+
_MiniKit.isCommandAvailable[minikitCommandName] = true;
|
|
826
|
+
isCommandValid = true;
|
|
827
|
+
} else {
|
|
828
|
+
console.error(
|
|
829
|
+
`Command ${minikitCommandName} version ${version} is not supported by the app. Supported versions: ${commandInput.supported_versions.join(", ")}`
|
|
830
|
+
);
|
|
831
|
+
_MiniKit.isCommandAvailable[minikitCommandName] = isCommandValid;
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
if (!isCommandValid) {
|
|
835
|
+
allCommandsValid = false;
|
|
656
836
|
}
|
|
657
|
-
return commandInput ? commandInput.supported_versions.includes(version) : false;
|
|
658
837
|
}
|
|
659
838
|
);
|
|
839
|
+
return allCommandsValid;
|
|
660
840
|
}
|
|
661
841
|
static install(appId) {
|
|
662
842
|
if (typeof window === "undefined" || Boolean(window.MiniKit)) {
|
|
@@ -678,6 +858,9 @@ var _MiniKit = class _MiniKit {
|
|
|
678
858
|
errorMessage: MiniKitInstallErrorMessage["outside_of_worldapp" /* OutsideOfWorldApp */]
|
|
679
859
|
};
|
|
680
860
|
}
|
|
861
|
+
_MiniKit.user.optedIntoOptionalAnalytics = window.WorldApp.is_optional_analytics;
|
|
862
|
+
_MiniKit.user.deviceOS = window.WorldApp.device_os;
|
|
863
|
+
_MiniKit.user.worldAppVersion = window.WorldApp.world_app_version;
|
|
681
864
|
try {
|
|
682
865
|
window.MiniKit = _MiniKit;
|
|
683
866
|
this.sendInit();
|
|
@@ -699,20 +882,21 @@ var _MiniKit = class _MiniKit {
|
|
|
699
882
|
errorMessage: MiniKitInstallErrorMessage["app_out_of_date" /* AppOutOfDate */]
|
|
700
883
|
};
|
|
701
884
|
}
|
|
885
|
+
_MiniKit.isReady = true;
|
|
702
886
|
return { success: true };
|
|
703
887
|
}
|
|
704
888
|
static isInstalled(debug) {
|
|
705
|
-
|
|
706
|
-
const isInstalled = Boolean(window.MiniKit);
|
|
889
|
+
const isInstalled = _MiniKit.isReady && Boolean(window.MiniKit);
|
|
707
890
|
if (!isInstalled)
|
|
708
891
|
console.error(
|
|
709
892
|
"MiniKit is not installed. Make sure you're running the application inside of World App"
|
|
710
893
|
);
|
|
894
|
+
if (debug && isInstalled) console.log("MiniKit is alive!");
|
|
711
895
|
return isInstalled;
|
|
712
896
|
}
|
|
713
897
|
};
|
|
714
898
|
_MiniKit.MINIKIT_VERSION = 1;
|
|
715
|
-
_MiniKit.
|
|
899
|
+
_MiniKit.miniKitCommandVersion = {
|
|
716
900
|
["verify" /* Verify */]: 1,
|
|
717
901
|
["pay" /* Pay */]: 1,
|
|
718
902
|
["wallet-auth" /* WalletAuth */]: 1,
|
|
@@ -723,6 +907,7 @@ _MiniKit.commandVersion = {
|
|
|
723
907
|
["request-permission" /* RequestPermission */]: 1,
|
|
724
908
|
["get-permissions" /* GetPermissions */]: 1,
|
|
725
909
|
["send-haptic-feedback" /* SendHapticFeedback */]: 1
|
|
910
|
+
// [Command.ShareFiles]: 1,
|
|
726
911
|
};
|
|
727
912
|
_MiniKit.isCommandAvailable = {
|
|
728
913
|
["verify" /* Verify */]: false,
|
|
@@ -735,6 +920,7 @@ _MiniKit.isCommandAvailable = {
|
|
|
735
920
|
["request-permission" /* RequestPermission */]: false,
|
|
736
921
|
["get-permissions" /* GetPermissions */]: false,
|
|
737
922
|
["send-haptic-feedback" /* SendHapticFeedback */]: false
|
|
923
|
+
// [Command.ShareFiles]: false,
|
|
738
924
|
};
|
|
739
925
|
_MiniKit.listeners = {
|
|
740
926
|
["miniapp-verify-action" /* MiniAppVerifyAction */]: () => {
|
|
@@ -756,22 +942,42 @@ _MiniKit.listeners = {
|
|
|
756
942
|
["miniapp-get-permissions" /* MiniAppGetPermissions */]: () => {
|
|
757
943
|
},
|
|
758
944
|
["miniapp-send-haptic-feedback" /* MiniAppSendHapticFeedback */]: () => {
|
|
945
|
+
},
|
|
946
|
+
["miniapp-share-files" /* MiniAppShareFiles */]: () => {
|
|
759
947
|
}
|
|
760
948
|
};
|
|
761
949
|
_MiniKit.appId = null;
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
*/
|
|
765
|
-
_MiniKit.walletAddress = null;
|
|
766
|
-
_MiniKit.user = null;
|
|
950
|
+
_MiniKit.user = {};
|
|
951
|
+
_MiniKit.isReady = false;
|
|
767
952
|
_MiniKit.getUserByAddress = async (address) => {
|
|
768
|
-
const userProfile = await getUserProfile(
|
|
953
|
+
const userProfile = await getUserProfile(
|
|
954
|
+
address ?? _MiniKit.user.walletAddress
|
|
955
|
+
);
|
|
769
956
|
return {
|
|
770
|
-
walletAddress: address,
|
|
957
|
+
walletAddress: address ?? _MiniKit.user.walletAddress,
|
|
771
958
|
username: userProfile.username,
|
|
772
|
-
profilePictureUrl: userProfile.
|
|
959
|
+
profilePictureUrl: userProfile.profile_picture_url
|
|
960
|
+
};
|
|
961
|
+
};
|
|
962
|
+
_MiniKit.getUserByUsername = async (username) => {
|
|
963
|
+
const res = await fetch(
|
|
964
|
+
`https://usernames.worldcoin.org/api/v1/${username}`,
|
|
965
|
+
{
|
|
966
|
+
method: "GET",
|
|
967
|
+
headers: {
|
|
968
|
+
"Content-Type": "application/json"
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
);
|
|
972
|
+
const user = await res.json();
|
|
973
|
+
return {
|
|
974
|
+
walletAddress: user.address,
|
|
975
|
+
username: user.username,
|
|
976
|
+
profilePictureUrl: user.profile_picture_url
|
|
773
977
|
};
|
|
774
978
|
};
|
|
979
|
+
// Simply re-exporting the existing function
|
|
980
|
+
_MiniKit.getUserInfo = _MiniKit.getUserByAddress;
|
|
775
981
|
_MiniKit.commands = {
|
|
776
982
|
verify: (payload) => {
|
|
777
983
|
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["verify" /* Verify */]) {
|
|
@@ -789,7 +995,7 @@ _MiniKit.commands = {
|
|
|
789
995
|
};
|
|
790
996
|
sendMiniKitEvent({
|
|
791
997
|
command: "verify" /* Verify */,
|
|
792
|
-
version: _MiniKit.
|
|
998
|
+
version: _MiniKit.miniKitCommandVersion["verify" /* Verify */],
|
|
793
999
|
payload: eventPayload
|
|
794
1000
|
});
|
|
795
1001
|
return eventPayload;
|
|
@@ -804,14 +1010,13 @@ _MiniKit.commands = {
|
|
|
804
1010
|
if (!validatePaymentPayload(payload)) {
|
|
805
1011
|
return null;
|
|
806
1012
|
}
|
|
807
|
-
const network = "worldchain" /* WorldChain */;
|
|
808
1013
|
const eventPayload = {
|
|
809
1014
|
...payload,
|
|
810
|
-
network
|
|
1015
|
+
network: "worldchain" /* WorldChain */
|
|
811
1016
|
};
|
|
812
1017
|
sendMiniKitEvent({
|
|
813
1018
|
command: "pay" /* Pay */,
|
|
814
|
-
version: _MiniKit.
|
|
1019
|
+
version: _MiniKit.miniKitCommandVersion["pay" /* Pay */],
|
|
815
1020
|
payload: eventPayload
|
|
816
1021
|
});
|
|
817
1022
|
return eventPayload;
|
|
@@ -844,7 +1049,7 @@ _MiniKit.commands = {
|
|
|
844
1049
|
domain: window.location.host,
|
|
845
1050
|
statement: payload.statement ?? void 0,
|
|
846
1051
|
uri: window.location.href,
|
|
847
|
-
version: 1,
|
|
1052
|
+
version: "1",
|
|
848
1053
|
chain_id: 480,
|
|
849
1054
|
nonce: payload.nonce,
|
|
850
1055
|
issued_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
@@ -855,7 +1060,7 @@ _MiniKit.commands = {
|
|
|
855
1060
|
const walletAuthPayload = { siweMessage };
|
|
856
1061
|
sendMiniKitEvent({
|
|
857
1062
|
command: "wallet-auth" /* WalletAuth */,
|
|
858
|
-
version: _MiniKit.
|
|
1063
|
+
version: _MiniKit.miniKitCommandVersion["wallet-auth" /* WalletAuth */],
|
|
859
1064
|
payload: walletAuthPayload
|
|
860
1065
|
});
|
|
861
1066
|
return walletAuthPayload;
|
|
@@ -870,7 +1075,7 @@ _MiniKit.commands = {
|
|
|
870
1075
|
const validatedPayload = validateSendTransactionPayload(payload);
|
|
871
1076
|
sendMiniKitEvent({
|
|
872
1077
|
command: "send-transaction" /* SendTransaction */,
|
|
873
|
-
version:
|
|
1078
|
+
version: _MiniKit.miniKitCommandVersion["send-transaction" /* SendTransaction */],
|
|
874
1079
|
payload: validatedPayload
|
|
875
1080
|
});
|
|
876
1081
|
return validatedPayload;
|
|
@@ -884,7 +1089,7 @@ _MiniKit.commands = {
|
|
|
884
1089
|
}
|
|
885
1090
|
sendMiniKitEvent({
|
|
886
1091
|
command: "sign-message" /* SignMessage */,
|
|
887
|
-
version:
|
|
1092
|
+
version: _MiniKit.miniKitCommandVersion["sign-message" /* SignMessage */],
|
|
888
1093
|
payload
|
|
889
1094
|
});
|
|
890
1095
|
return payload;
|
|
@@ -898,7 +1103,7 @@ _MiniKit.commands = {
|
|
|
898
1103
|
}
|
|
899
1104
|
sendMiniKitEvent({
|
|
900
1105
|
command: "sign-typed-data" /* SignTypedData */,
|
|
901
|
-
version:
|
|
1106
|
+
version: _MiniKit.miniKitCommandVersion["sign-typed-data" /* SignTypedData */],
|
|
902
1107
|
payload
|
|
903
1108
|
});
|
|
904
1109
|
return payload;
|
|
@@ -912,7 +1117,7 @@ _MiniKit.commands = {
|
|
|
912
1117
|
}
|
|
913
1118
|
sendMiniKitEvent({
|
|
914
1119
|
command: "share-contacts" /* ShareContacts */,
|
|
915
|
-
version:
|
|
1120
|
+
version: _MiniKit.miniKitCommandVersion["share-contacts" /* ShareContacts */],
|
|
916
1121
|
payload
|
|
917
1122
|
});
|
|
918
1123
|
return payload;
|
|
@@ -926,7 +1131,7 @@ _MiniKit.commands = {
|
|
|
926
1131
|
}
|
|
927
1132
|
sendMiniKitEvent({
|
|
928
1133
|
command: "request-permission" /* RequestPermission */,
|
|
929
|
-
version:
|
|
1134
|
+
version: _MiniKit.miniKitCommandVersion["request-permission" /* RequestPermission */],
|
|
930
1135
|
payload
|
|
931
1136
|
});
|
|
932
1137
|
return payload;
|
|
@@ -940,7 +1145,7 @@ _MiniKit.commands = {
|
|
|
940
1145
|
}
|
|
941
1146
|
sendMiniKitEvent({
|
|
942
1147
|
command: "get-permissions" /* GetPermissions */,
|
|
943
|
-
version:
|
|
1148
|
+
version: _MiniKit.miniKitCommandVersion["get-permissions" /* GetPermissions */],
|
|
944
1149
|
payload: {}
|
|
945
1150
|
});
|
|
946
1151
|
return {
|
|
@@ -956,11 +1161,28 @@ _MiniKit.commands = {
|
|
|
956
1161
|
}
|
|
957
1162
|
sendMiniKitEvent({
|
|
958
1163
|
command: "send-haptic-feedback" /* SendHapticFeedback */,
|
|
959
|
-
version:
|
|
1164
|
+
version: _MiniKit.miniKitCommandVersion["send-haptic-feedback" /* SendHapticFeedback */],
|
|
960
1165
|
payload
|
|
961
1166
|
});
|
|
962
1167
|
return payload;
|
|
963
1168
|
}
|
|
1169
|
+
// shareFiles: (payload: ShareFilesInput): ShareFilesPayload | null => {
|
|
1170
|
+
// if (
|
|
1171
|
+
// typeof window === 'undefined' ||
|
|
1172
|
+
// !this.isCommandAvailable[Command.ShareFiles]
|
|
1173
|
+
// ) {
|
|
1174
|
+
// console.error(
|
|
1175
|
+
// "'shareFiles' command is unavailable. Check MiniKit.install() or update the app version",
|
|
1176
|
+
// );
|
|
1177
|
+
// return null;
|
|
1178
|
+
// }
|
|
1179
|
+
// sendMiniKitEvent<WebViewBasePayload>({
|
|
1180
|
+
// command: Command.ShareFiles,
|
|
1181
|
+
// version: this.miniKitCommandVersion[Command.ShareFiles],
|
|
1182
|
+
// payload,
|
|
1183
|
+
// });
|
|
1184
|
+
// return payload;
|
|
1185
|
+
// },
|
|
964
1186
|
};
|
|
965
1187
|
/**
|
|
966
1188
|
* This object contains async versions of all the commands.
|
|
@@ -981,6 +1203,11 @@ _MiniKit.commandsAsync = {
|
|
|
981
1203
|
"verify" /* Verify */,
|
|
982
1204
|
() => _MiniKit.commands.verify(payload)
|
|
983
1205
|
);
|
|
1206
|
+
if (response.finalPayload.status === "success" && response.finalPayload.verification_level === import_idkit_core3.VerificationLevel.Orb) {
|
|
1207
|
+
response.finalPayload.proof = await compressAndPadProof(
|
|
1208
|
+
response.finalPayload.proof
|
|
1209
|
+
);
|
|
1210
|
+
}
|
|
984
1211
|
resolve(response);
|
|
985
1212
|
} catch (error) {
|
|
986
1213
|
reject(error);
|
|
@@ -1113,6 +1340,25 @@ _MiniKit.commandsAsync = {
|
|
|
1113
1340
|
}
|
|
1114
1341
|
});
|
|
1115
1342
|
}
|
|
1343
|
+
// shareFiles: async (
|
|
1344
|
+
// payload: ShareFilesInput,
|
|
1345
|
+
// ): AsyncHandlerReturn<
|
|
1346
|
+
// ShareFilesPayload | null,
|
|
1347
|
+
// MiniAppShareFilesPayload
|
|
1348
|
+
// > => {
|
|
1349
|
+
// return new Promise(async (resolve, reject) => {
|
|
1350
|
+
// try {
|
|
1351
|
+
// const response = await MiniKit.awaitCommand(
|
|
1352
|
+
// ResponseEvent.MiniAppShareFiles,
|
|
1353
|
+
// Command.ShareFiles,
|
|
1354
|
+
// () => this.commands.shareFiles(payload),
|
|
1355
|
+
// );
|
|
1356
|
+
// resolve(response);
|
|
1357
|
+
// } catch (error) {
|
|
1358
|
+
// reject(error);
|
|
1359
|
+
// }
|
|
1360
|
+
// });
|
|
1361
|
+
// },
|
|
1116
1362
|
};
|
|
1117
1363
|
var MiniKit = _MiniKit;
|
|
1118
1364
|
|
|
@@ -1121,8 +1367,8 @@ var import_idkit_core4 = require("@worldcoin/idkit-core");
|
|
|
1121
1367
|
var import_backend = require("@worldcoin/idkit-core/backend");
|
|
1122
1368
|
|
|
1123
1369
|
// helpers/address-book/index.ts
|
|
1124
|
-
var
|
|
1125
|
-
var
|
|
1370
|
+
var import_viem3 = require("viem");
|
|
1371
|
+
var import_chains3 = require("viem/chains");
|
|
1126
1372
|
var worldIdAddressBookContractAddress = "0x57b930D551e677CC36e2fA036Ae2fe8FdaE0330D";
|
|
1127
1373
|
var addressVerifiedUntilAbi = [
|
|
1128
1374
|
{
|
|
@@ -1146,9 +1392,9 @@ var addressVerifiedUntilAbi = [
|
|
|
1146
1392
|
}
|
|
1147
1393
|
];
|
|
1148
1394
|
var getIsUserVerified = async (walletAddress, rpcUrl) => {
|
|
1149
|
-
const publicClient = (0,
|
|
1150
|
-
chain:
|
|
1151
|
-
transport: (0,
|
|
1395
|
+
const publicClient = (0, import_viem3.createPublicClient)({
|
|
1396
|
+
chain: import_chains3.worldchain,
|
|
1397
|
+
transport: (0, import_viem3.http)(
|
|
1152
1398
|
rpcUrl || "https://worldchain-mainnet.g.alchemy.com/public"
|
|
1153
1399
|
)
|
|
1154
1400
|
});
|
|
@@ -1187,13 +1433,14 @@ var getIsUserVerified = async (walletAddress, rpcUrl) => {
|
|
|
1187
1433
|
RequestPermissionErrorCodes,
|
|
1188
1434
|
RequestPermissionErrorMessage,
|
|
1189
1435
|
ResponseEvent,
|
|
1190
|
-
SAFE_CONTRACT_ABI,
|
|
1191
1436
|
SendHapticFeedbackErrorCodes,
|
|
1192
1437
|
SendHapticFeedbackErrorMessage,
|
|
1193
1438
|
SendTransactionErrorCodes,
|
|
1194
1439
|
SendTransactionErrorMessage,
|
|
1195
1440
|
ShareContactsErrorCodes,
|
|
1196
1441
|
ShareContactsErrorMessage,
|
|
1442
|
+
ShareFilesErrorCodes,
|
|
1443
|
+
ShareFilesErrorMessage,
|
|
1197
1444
|
SignMessageErrorCodes,
|
|
1198
1445
|
SignMessageErrorMessage,
|
|
1199
1446
|
SignTypedDataErrorCodes,
|