@worldcoin/minikit-js 1.8.0 → 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 +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,1349 @@
|
|
|
1
|
+
// types/payment.ts
|
|
2
|
+
var Tokens = /* @__PURE__ */ ((Tokens3) => {
|
|
3
|
+
Tokens3["USDCE"] = "USDCE";
|
|
4
|
+
Tokens3["WLD"] = "WLD";
|
|
5
|
+
return Tokens3;
|
|
6
|
+
})(Tokens || {});
|
|
7
|
+
var TokenDecimals = {
|
|
8
|
+
["USDCE" /* USDCE */]: 6,
|
|
9
|
+
["WLD" /* WLD */]: 18
|
|
10
|
+
};
|
|
11
|
+
var Network = /* @__PURE__ */ ((Network2) => {
|
|
12
|
+
Network2["Optimism"] = "optimism";
|
|
13
|
+
Network2["WorldChain"] = "worldchain";
|
|
14
|
+
return Network2;
|
|
15
|
+
})(Network || {});
|
|
16
|
+
|
|
17
|
+
// helpers/payment/client.ts
|
|
18
|
+
var tokenToDecimals = (amount, token) => {
|
|
19
|
+
const decimals = TokenDecimals[token];
|
|
20
|
+
if (decimals === void 0) {
|
|
21
|
+
throw new Error(`Invalid token: ${token}`);
|
|
22
|
+
}
|
|
23
|
+
const factor = 10 ** decimals;
|
|
24
|
+
const result = amount * factor;
|
|
25
|
+
if (!Number.isInteger(result)) {
|
|
26
|
+
throw new Error(`The resulting amount is not a whole number: ${result}`);
|
|
27
|
+
}
|
|
28
|
+
return result;
|
|
29
|
+
};
|
|
30
|
+
var validatePaymentPayload = (payload) => {
|
|
31
|
+
if (payload.tokens.some(
|
|
32
|
+
(token) => token.symbol == "USDCE" && parseFloat(token.token_amount) < 0.1
|
|
33
|
+
)) {
|
|
34
|
+
console.error("USDCE amount should be greater than $0.1");
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
if (payload.reference.length > 36) {
|
|
38
|
+
console.error("Reference must not exceed 36 characters");
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
if (typeof payload.reference !== "string") {
|
|
42
|
+
throw new Error("Reference must be a string");
|
|
43
|
+
}
|
|
44
|
+
return true;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// helpers/siwe/siwe.ts
|
|
48
|
+
import {
|
|
49
|
+
createPublicClient,
|
|
50
|
+
getContract,
|
|
51
|
+
hashMessage,
|
|
52
|
+
http,
|
|
53
|
+
recoverAddress
|
|
54
|
+
} from "viem";
|
|
55
|
+
import { worldchain } from "viem/chains";
|
|
56
|
+
var PREAMBLE = " wants you to sign in with your Ethereum account:";
|
|
57
|
+
var URI_TAG = "URI: ";
|
|
58
|
+
var VERSION_TAG = "Version: ";
|
|
59
|
+
var CHAIN_TAG = "Chain ID: ";
|
|
60
|
+
var NONCE_TAG = "Nonce: ";
|
|
61
|
+
var IAT_TAG = "Issued At: ";
|
|
62
|
+
var EXP_TAG = "Expiration Time: ";
|
|
63
|
+
var NBF_TAG = "Not Before: ";
|
|
64
|
+
var RID_TAG = "Request ID: ";
|
|
65
|
+
var ERC_191_PREFIX = "Ethereum Signed Message:\n";
|
|
66
|
+
var EIP1271_MAGICVALUE = "0x1626ba7e";
|
|
67
|
+
var SAFE_CONTRACT_ABI = [
|
|
68
|
+
{
|
|
69
|
+
inputs: [
|
|
70
|
+
{
|
|
71
|
+
internalType: "address",
|
|
72
|
+
name: "owner",
|
|
73
|
+
type: "address"
|
|
74
|
+
}
|
|
75
|
+
],
|
|
76
|
+
name: "isOwner",
|
|
77
|
+
outputs: [
|
|
78
|
+
{
|
|
79
|
+
internalType: "bool",
|
|
80
|
+
name: "",
|
|
81
|
+
type: "bool"
|
|
82
|
+
}
|
|
83
|
+
],
|
|
84
|
+
stateMutability: "view",
|
|
85
|
+
type: "function"
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
inputs: [
|
|
89
|
+
{
|
|
90
|
+
internalType: "bytes32",
|
|
91
|
+
name: "_message",
|
|
92
|
+
type: "bytes32"
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
internalType: "bytes",
|
|
96
|
+
name: "_signature",
|
|
97
|
+
type: "bytes"
|
|
98
|
+
}
|
|
99
|
+
],
|
|
100
|
+
name: "isValidSignature",
|
|
101
|
+
outputs: [
|
|
102
|
+
{
|
|
103
|
+
internalType: "bytes4",
|
|
104
|
+
name: "",
|
|
105
|
+
type: "bytes4"
|
|
106
|
+
}
|
|
107
|
+
],
|
|
108
|
+
stateMutability: "view",
|
|
109
|
+
type: "function"
|
|
110
|
+
}
|
|
111
|
+
];
|
|
112
|
+
var tagged = (line, tag) => {
|
|
113
|
+
if (line && line.includes(tag)) {
|
|
114
|
+
return line.replace(tag, "");
|
|
115
|
+
} else {
|
|
116
|
+
throw new Error(`Missing '${tag}'`);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
var parseSiweMessage = (inputString) => {
|
|
120
|
+
const lines = inputString.split("\n")[Symbol.iterator]();
|
|
121
|
+
const domain = tagged(lines.next()?.value, PREAMBLE);
|
|
122
|
+
const address = lines.next()?.value;
|
|
123
|
+
lines.next();
|
|
124
|
+
const nextValue = lines.next()?.value;
|
|
125
|
+
let statement;
|
|
126
|
+
if (nextValue) {
|
|
127
|
+
statement = nextValue;
|
|
128
|
+
lines.next();
|
|
129
|
+
}
|
|
130
|
+
const uri = tagged(lines.next()?.value, URI_TAG);
|
|
131
|
+
const version = tagged(lines.next()?.value, VERSION_TAG);
|
|
132
|
+
const chain_id = tagged(lines.next()?.value, CHAIN_TAG);
|
|
133
|
+
const nonce = tagged(lines.next()?.value, NONCE_TAG);
|
|
134
|
+
const issued_at = tagged(lines.next()?.value, IAT_TAG);
|
|
135
|
+
let expiration_time, not_before, request_id;
|
|
136
|
+
for (let line of lines) {
|
|
137
|
+
if (line.startsWith(EXP_TAG)) {
|
|
138
|
+
expiration_time = tagged(line, EXP_TAG);
|
|
139
|
+
} else if (line.startsWith(NBF_TAG)) {
|
|
140
|
+
not_before = tagged(line, NBF_TAG);
|
|
141
|
+
} else if (line.startsWith(RID_TAG)) {
|
|
142
|
+
request_id = tagged(line, RID_TAG);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
if (lines.next().done === false) {
|
|
146
|
+
throw new Error("Extra lines in the input");
|
|
147
|
+
}
|
|
148
|
+
const siweMessageData = {
|
|
149
|
+
domain,
|
|
150
|
+
address,
|
|
151
|
+
statement,
|
|
152
|
+
uri,
|
|
153
|
+
version,
|
|
154
|
+
chain_id,
|
|
155
|
+
nonce,
|
|
156
|
+
issued_at,
|
|
157
|
+
expiration_time,
|
|
158
|
+
not_before,
|
|
159
|
+
request_id
|
|
160
|
+
};
|
|
161
|
+
return siweMessageData;
|
|
162
|
+
};
|
|
163
|
+
var generateSiweMessage = (siweMessageData) => {
|
|
164
|
+
let siweMessage = "";
|
|
165
|
+
if (siweMessageData.scheme) {
|
|
166
|
+
siweMessage += `${siweMessageData.scheme}://${siweMessageData.domain} wants you to sign in with your Ethereum account:
|
|
167
|
+
`;
|
|
168
|
+
} else {
|
|
169
|
+
siweMessage += `${siweMessageData.domain} wants you to sign in with your Ethereum account:
|
|
170
|
+
`;
|
|
171
|
+
}
|
|
172
|
+
if (siweMessageData.address) {
|
|
173
|
+
siweMessage += `${siweMessageData.address}
|
|
174
|
+
`;
|
|
175
|
+
} else {
|
|
176
|
+
siweMessage += "{address}\n";
|
|
177
|
+
}
|
|
178
|
+
siweMessage += "\n";
|
|
179
|
+
if (siweMessageData.statement) {
|
|
180
|
+
siweMessage += `${siweMessageData.statement}
|
|
181
|
+
`;
|
|
182
|
+
}
|
|
183
|
+
siweMessage += "\n";
|
|
184
|
+
siweMessage += `URI: ${siweMessageData.uri}
|
|
185
|
+
`;
|
|
186
|
+
siweMessage += `Version: ${siweMessageData.version}
|
|
187
|
+
`;
|
|
188
|
+
siweMessage += `Chain ID: ${siweMessageData.chain_id}
|
|
189
|
+
`;
|
|
190
|
+
siweMessage += `Nonce: ${siweMessageData.nonce}
|
|
191
|
+
`;
|
|
192
|
+
siweMessage += `Issued At: ${siweMessageData.issued_at}
|
|
193
|
+
`;
|
|
194
|
+
if (siweMessageData.expiration_time) {
|
|
195
|
+
siweMessage += `Expiration Time: ${siweMessageData.expiration_time}
|
|
196
|
+
`;
|
|
197
|
+
}
|
|
198
|
+
if (siweMessageData.not_before) {
|
|
199
|
+
siweMessage += `Not Before: ${siweMessageData.not_before}
|
|
200
|
+
`;
|
|
201
|
+
}
|
|
202
|
+
if (siweMessageData.request_id) {
|
|
203
|
+
siweMessage += `Request ID: ${siweMessageData.request_id}
|
|
204
|
+
`;
|
|
205
|
+
}
|
|
206
|
+
return siweMessage;
|
|
207
|
+
};
|
|
208
|
+
var verifySiweMessage = (payload, nonce, statement, requestId, userProvider) => {
|
|
209
|
+
if (payload.version === 2) {
|
|
210
|
+
return verifySiweMessageV2(
|
|
211
|
+
payload,
|
|
212
|
+
nonce,
|
|
213
|
+
statement,
|
|
214
|
+
requestId,
|
|
215
|
+
userProvider
|
|
216
|
+
);
|
|
217
|
+
} else {
|
|
218
|
+
return verifySiweMessageV1(
|
|
219
|
+
payload,
|
|
220
|
+
nonce,
|
|
221
|
+
statement,
|
|
222
|
+
requestId,
|
|
223
|
+
userProvider
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
};
|
|
227
|
+
var validateMessage = (siweMessageData, nonce, statement, requestId) => {
|
|
228
|
+
if (siweMessageData.expiration_time) {
|
|
229
|
+
const expirationTime = new Date(siweMessageData.expiration_time);
|
|
230
|
+
if (expirationTime < /* @__PURE__ */ new Date()) {
|
|
231
|
+
throw new Error("Expired message");
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
if (siweMessageData.not_before) {
|
|
235
|
+
const notBefore = new Date(siweMessageData.not_before);
|
|
236
|
+
if (notBefore > /* @__PURE__ */ new Date()) {
|
|
237
|
+
throw new Error("Not Before time has not passed");
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
if (nonce && siweMessageData.nonce !== nonce) {
|
|
241
|
+
throw new Error(
|
|
242
|
+
`Nonce mismatch. Got: ${siweMessageData.nonce}, Expected: ${nonce}`
|
|
243
|
+
);
|
|
244
|
+
}
|
|
245
|
+
if (statement && siweMessageData.statement !== statement) {
|
|
246
|
+
throw new Error(
|
|
247
|
+
`Statement mismatch. Got: ${siweMessageData.statement}, Expected: ${statement}`
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
if (requestId && siweMessageData.request_id !== requestId) {
|
|
251
|
+
throw new Error(
|
|
252
|
+
`Request ID mismatch. Got: ${siweMessageData.request_id}, Expected: ${requestId}`
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
return true;
|
|
256
|
+
};
|
|
257
|
+
var verifySiweMessageV1 = async (payload, nonce, statement, requestId, userProvider) => {
|
|
258
|
+
if (typeof window !== "undefined") {
|
|
259
|
+
throw new Error("Wallet auth payload can only be verified in the backend");
|
|
260
|
+
}
|
|
261
|
+
const { message, signature, address } = payload;
|
|
262
|
+
const siweMessageData = parseSiweMessage(message);
|
|
263
|
+
validateMessage(siweMessageData, nonce, statement, requestId);
|
|
264
|
+
let provider = userProvider || createPublicClient({ chain: worldchain, transport: http() });
|
|
265
|
+
const signedMessage = `${ERC_191_PREFIX}${message.length}${message}`;
|
|
266
|
+
const hashedMessage = hashMessage(signedMessage);
|
|
267
|
+
const contract = getContract({
|
|
268
|
+
address,
|
|
269
|
+
abi: SAFE_CONTRACT_ABI,
|
|
270
|
+
client: provider
|
|
271
|
+
});
|
|
272
|
+
try {
|
|
273
|
+
const recoveredAddress = await recoverAddress({
|
|
274
|
+
hash: hashedMessage,
|
|
275
|
+
signature: `0x${signature}`
|
|
276
|
+
});
|
|
277
|
+
const isOwner = await contract.read.isOwner([recoveredAddress]);
|
|
278
|
+
if (!isOwner) {
|
|
279
|
+
throw new Error("Signature verification failed, invalid owner");
|
|
280
|
+
}
|
|
281
|
+
} catch (error) {
|
|
282
|
+
throw new Error("Signature verification failed");
|
|
283
|
+
}
|
|
284
|
+
return { isValid: true, siweMessageData };
|
|
285
|
+
};
|
|
286
|
+
var verifySiweMessageV2 = async (payload, nonce, statement, requestId, userProvider) => {
|
|
287
|
+
if (typeof window !== "undefined") {
|
|
288
|
+
throw new Error("Wallet auth payload can only be verified in the backend");
|
|
289
|
+
}
|
|
290
|
+
const { message, signature, address } = payload;
|
|
291
|
+
const siweMessageData = parseSiweMessage(message);
|
|
292
|
+
if (!validateMessage(siweMessageData, nonce, statement, requestId)) {
|
|
293
|
+
throw new Error("Validation failed");
|
|
294
|
+
}
|
|
295
|
+
try {
|
|
296
|
+
const walletContract = getContract({
|
|
297
|
+
address,
|
|
298
|
+
abi: SAFE_CONTRACT_ABI,
|
|
299
|
+
client: userProvider || createPublicClient({ chain: worldchain, transport: http() })
|
|
300
|
+
});
|
|
301
|
+
const hashedMessage = hashMessage(message);
|
|
302
|
+
const res = await walletContract.read.isValidSignature([
|
|
303
|
+
hashedMessage,
|
|
304
|
+
signature
|
|
305
|
+
]);
|
|
306
|
+
return {
|
|
307
|
+
isValid: res === EIP1271_MAGICVALUE,
|
|
308
|
+
siweMessageData
|
|
309
|
+
};
|
|
310
|
+
} catch (error) {
|
|
311
|
+
console.log(error);
|
|
312
|
+
throw new Error("Signature verification failed");
|
|
313
|
+
}
|
|
314
|
+
};
|
|
315
|
+
|
|
316
|
+
// types/commands.ts
|
|
317
|
+
var Command = /* @__PURE__ */ ((Command2) => {
|
|
318
|
+
Command2["Verify"] = "verify";
|
|
319
|
+
Command2["Pay"] = "pay";
|
|
320
|
+
Command2["WalletAuth"] = "wallet-auth";
|
|
321
|
+
Command2["SendTransaction"] = "send-transaction";
|
|
322
|
+
Command2["SignMessage"] = "sign-message";
|
|
323
|
+
Command2["SignTypedData"] = "sign-typed-data";
|
|
324
|
+
Command2["ShareContacts"] = "share-contacts";
|
|
325
|
+
Command2["RequestPermission"] = "request-permission";
|
|
326
|
+
Command2["GetPermissions"] = "get-permissions";
|
|
327
|
+
Command2["SendHapticFeedback"] = "send-haptic-feedback";
|
|
328
|
+
return Command2;
|
|
329
|
+
})(Command || {});
|
|
330
|
+
var Permission = /* @__PURE__ */ ((Permission2) => {
|
|
331
|
+
Permission2["Notifications"] = "notifications";
|
|
332
|
+
Permission2["Contacts"] = "contacts";
|
|
333
|
+
return Permission2;
|
|
334
|
+
})(Permission || {});
|
|
335
|
+
|
|
336
|
+
// types/errors.ts
|
|
337
|
+
import { AppErrorCodes } from "@worldcoin/idkit-core";
|
|
338
|
+
import { AppErrorCodes as AppErrorCodes2 } from "@worldcoin/idkit-core";
|
|
339
|
+
var VerificationErrorMessage = {
|
|
340
|
+
[AppErrorCodes.VerificationRejected]: "You've cancelled the request in World App.",
|
|
341
|
+
[AppErrorCodes.MaxVerificationsReached]: "You have already verified the maximum number of times for this action.",
|
|
342
|
+
[AppErrorCodes.CredentialUnavailable]: "It seems you do not have the verification level required by this app.",
|
|
343
|
+
[AppErrorCodes.MalformedRequest]: "There was a problem with this request. Please try again or contact the app owner.",
|
|
344
|
+
[AppErrorCodes.InvalidNetwork]: "Invalid network. If you are the app owner, visit docs.worldcoin.org/test for details.",
|
|
345
|
+
[AppErrorCodes.InclusionProofFailed]: "There was an issue fetching your credential. Please try again.",
|
|
346
|
+
[AppErrorCodes.InclusionProofPending]: "Your identity is still being registered. Please wait a few minutes and try again.",
|
|
347
|
+
[AppErrorCodes.UnexpectedResponse]: "Unexpected response from your wallet. Please try again.",
|
|
348
|
+
[AppErrorCodes.FailedByHostApp]: "Verification failed by the app. Please contact the app owner for details.",
|
|
349
|
+
[AppErrorCodes.GenericError]: "Something unexpected went wrong. Please try again.",
|
|
350
|
+
[AppErrorCodes.ConnectionFailed]: "Connection to your wallet failed. Please try again."
|
|
351
|
+
};
|
|
352
|
+
var PaymentErrorCodes = /* @__PURE__ */ ((PaymentErrorCodes2) => {
|
|
353
|
+
PaymentErrorCodes2["InputError"] = "input_error";
|
|
354
|
+
PaymentErrorCodes2["UserRejected"] = "user_rejected";
|
|
355
|
+
PaymentErrorCodes2["PaymentRejected"] = "payment_rejected";
|
|
356
|
+
PaymentErrorCodes2["InvalidReceiver"] = "invalid_receiver";
|
|
357
|
+
PaymentErrorCodes2["InsufficientBalance"] = "insufficient_balance";
|
|
358
|
+
PaymentErrorCodes2["TransactionFailed"] = "transaction_failed";
|
|
359
|
+
PaymentErrorCodes2["GenericError"] = "generic_error";
|
|
360
|
+
PaymentErrorCodes2["UserBlocked"] = "user_blocked";
|
|
361
|
+
return PaymentErrorCodes2;
|
|
362
|
+
})(PaymentErrorCodes || {});
|
|
363
|
+
var PaymentErrorMessage = {
|
|
364
|
+
["input_error" /* InputError */]: "There was a problem with this request. Please try again or contact the app owner.",
|
|
365
|
+
["user_rejected" /* UserRejected */]: "You have cancelled the payment in World App.",
|
|
366
|
+
["payment_rejected" /* PaymentRejected */]: "You've cancelled the payment in World App.",
|
|
367
|
+
["invalid_receiver" /* InvalidReceiver */]: "The receiver address is invalid. Please contact the app owner.",
|
|
368
|
+
["insufficient_balance" /* InsufficientBalance */]: "You do not have enough balance to complete this transaction.",
|
|
369
|
+
["transaction_failed" /* TransactionFailed */]: "The transaction failed. Please try again.",
|
|
370
|
+
["generic_error" /* GenericError */]: "Something unexpected went wrong. Please try again.",
|
|
371
|
+
["user_blocked" /* UserBlocked */]: "User's region is blocked from making payments."
|
|
372
|
+
};
|
|
373
|
+
var PaymentValidationErrors = /* @__PURE__ */ ((PaymentValidationErrors2) => {
|
|
374
|
+
PaymentValidationErrors2["MalformedRequest"] = "There was a problem with this request. Please try again or contact the app owner.";
|
|
375
|
+
PaymentValidationErrors2["InvalidTokenAddress"] = "The token address is invalid. Please contact the app owner.";
|
|
376
|
+
PaymentValidationErrors2["InvalidAppId"] = "The app ID is invalid. Please contact the app owner.";
|
|
377
|
+
PaymentValidationErrors2["DuplicateReference"] = "This reference ID already exists please generate a new one and try again.";
|
|
378
|
+
return PaymentValidationErrors2;
|
|
379
|
+
})(PaymentValidationErrors || {});
|
|
380
|
+
var WalletAuthErrorCodes = /* @__PURE__ */ ((WalletAuthErrorCodes2) => {
|
|
381
|
+
WalletAuthErrorCodes2["MalformedRequest"] = "malformed_request";
|
|
382
|
+
WalletAuthErrorCodes2["UserRejected"] = "user_rejected";
|
|
383
|
+
WalletAuthErrorCodes2["GenericError"] = "generic_error";
|
|
384
|
+
return WalletAuthErrorCodes2;
|
|
385
|
+
})(WalletAuthErrorCodes || {});
|
|
386
|
+
var WalletAuthErrorMessage = {
|
|
387
|
+
["malformed_request" /* MalformedRequest */]: "Provided parameters in the request are invalid.",
|
|
388
|
+
["user_rejected" /* UserRejected */]: "User rejected the request.",
|
|
389
|
+
["generic_error" /* GenericError */]: "Something unexpected went wrong."
|
|
390
|
+
};
|
|
391
|
+
var SendTransactionErrorCodes = /* @__PURE__ */ ((SendTransactionErrorCodes2) => {
|
|
392
|
+
SendTransactionErrorCodes2["InvalidOperation"] = "invalid_operation";
|
|
393
|
+
SendTransactionErrorCodes2["UserRejected"] = "user_rejected";
|
|
394
|
+
SendTransactionErrorCodes2["InputError"] = "input_error";
|
|
395
|
+
SendTransactionErrorCodes2["SimulationFailed"] = "simulation_failed";
|
|
396
|
+
SendTransactionErrorCodes2["TransactionFailed"] = "transaction_failed";
|
|
397
|
+
SendTransactionErrorCodes2["GenericError"] = "generic_error";
|
|
398
|
+
SendTransactionErrorCodes2["DisallowedOperation"] = "disallowed_operation";
|
|
399
|
+
SendTransactionErrorCodes2["InvalidContract"] = "invalid_contract";
|
|
400
|
+
SendTransactionErrorCodes2["MaliciousOperation"] = "malicious_operation";
|
|
401
|
+
SendTransactionErrorCodes2["DailyTxLimitReached"] = "daily_tx_limit_reached";
|
|
402
|
+
SendTransactionErrorCodes2["PermittedAmountExceedsSlippage"] = "permitted_amount_exceeds_slippage";
|
|
403
|
+
SendTransactionErrorCodes2["PermittedAmountNotFound"] = "permitted_amount_not_found";
|
|
404
|
+
return SendTransactionErrorCodes2;
|
|
405
|
+
})(SendTransactionErrorCodes || {});
|
|
406
|
+
var SendTransactionErrorMessage = {
|
|
407
|
+
["invalid_operation" /* InvalidOperation */]: "Transaction included an operation that was invalid",
|
|
408
|
+
["user_rejected" /* UserRejected */]: "User rejected the request.",
|
|
409
|
+
["input_error" /* InputError */]: "Invalid payload.",
|
|
410
|
+
["simulation_failed" /* SimulationFailed */]: "The transaction simulation failed.",
|
|
411
|
+
["transaction_failed" /* TransactionFailed */]: "The transaction failed. Please try again later.",
|
|
412
|
+
["generic_error" /* GenericError */]: "Something unexpected went wrong. Please try again.",
|
|
413
|
+
["disallowed_operation" /* DisallowedOperation */]: "The operation requested is not allowed. Please refer to the docs.",
|
|
414
|
+
["invalid_contract" /* InvalidContract */]: "The contract address is not allowed for your application. Please check your developer portal configurations",
|
|
415
|
+
["malicious_operation" /* MaliciousOperation */]: "The operation requested is considered malicious.",
|
|
416
|
+
["daily_tx_limit_reached" /* DailyTxLimitReached */]: "Daily transaction limit reached. Max 100 transactions per day. Wait until the next day.",
|
|
417
|
+
["permitted_amount_exceeds_slippage" /* PermittedAmountExceedsSlippage */]: "Permitted amount exceeds slippage. You must spend at least 90% of the permitted amount.",
|
|
418
|
+
["permitted_amount_not_found" /* PermittedAmountNotFound */]: "Permitted amount not found in permit2 payload."
|
|
419
|
+
};
|
|
420
|
+
var SignMessageErrorCodes = /* @__PURE__ */ ((SignMessageErrorCodes2) => {
|
|
421
|
+
SignMessageErrorCodes2["InvalidMessage"] = "invalid_message";
|
|
422
|
+
SignMessageErrorCodes2["UserRejected"] = "user_rejected";
|
|
423
|
+
SignMessageErrorCodes2["GenericError"] = "generic_error";
|
|
424
|
+
return SignMessageErrorCodes2;
|
|
425
|
+
})(SignMessageErrorCodes || {});
|
|
426
|
+
var SignMessageErrorMessage = {
|
|
427
|
+
["invalid_message" /* InvalidMessage */]: "Invalid message requested",
|
|
428
|
+
["user_rejected" /* UserRejected */]: "User rejected the request.",
|
|
429
|
+
["generic_error" /* GenericError */]: "Something unexpected went wrong."
|
|
430
|
+
};
|
|
431
|
+
var SignTypedDataErrorCodes = /* @__PURE__ */ ((SignTypedDataErrorCodes2) => {
|
|
432
|
+
SignTypedDataErrorCodes2["InvalidOperation"] = "invalid_operation";
|
|
433
|
+
SignTypedDataErrorCodes2["UserRejected"] = "user_rejected";
|
|
434
|
+
SignTypedDataErrorCodes2["InputError"] = "input_error";
|
|
435
|
+
SignTypedDataErrorCodes2["SimulationFailed"] = "simulation_failed";
|
|
436
|
+
SignTypedDataErrorCodes2["GenericError"] = "generic_error";
|
|
437
|
+
SignTypedDataErrorCodes2["DisallowedOperation"] = "disallowed_operation";
|
|
438
|
+
SignTypedDataErrorCodes2["InvalidContract"] = "invalid_contract";
|
|
439
|
+
SignTypedDataErrorCodes2["MaliciousOperation"] = "malicious_operation";
|
|
440
|
+
return SignTypedDataErrorCodes2;
|
|
441
|
+
})(SignTypedDataErrorCodes || {});
|
|
442
|
+
var SignTypedDataErrorMessage = {
|
|
443
|
+
["invalid_operation" /* InvalidOperation */]: "Transaction included an operation that was invalid",
|
|
444
|
+
["user_rejected" /* UserRejected */]: "User rejected the request.",
|
|
445
|
+
["input_error" /* InputError */]: "Invalid payload.",
|
|
446
|
+
["simulation_failed" /* SimulationFailed */]: "The transaction simulation failed.",
|
|
447
|
+
["generic_error" /* GenericError */]: "Something unexpected went wrong. Please try again.",
|
|
448
|
+
["disallowed_operation" /* DisallowedOperation */]: "The operation requested is not allowed. Please refer to the docs.",
|
|
449
|
+
["invalid_contract" /* InvalidContract */]: "The contract address is not allowed for your application. Please check your developer portal configurations",
|
|
450
|
+
["malicious_operation" /* MaliciousOperation */]: "The operation requested is considered malicious."
|
|
451
|
+
};
|
|
452
|
+
var MiniKitInstallErrorCodes = /* @__PURE__ */ ((MiniKitInstallErrorCodes2) => {
|
|
453
|
+
MiniKitInstallErrorCodes2["Unknown"] = "unknown";
|
|
454
|
+
MiniKitInstallErrorCodes2["AlreadyInstalled"] = "already_installed";
|
|
455
|
+
MiniKitInstallErrorCodes2["OutsideOfWorldApp"] = "outside_of_worldapp";
|
|
456
|
+
MiniKitInstallErrorCodes2["NotOnClient"] = "not_on_client";
|
|
457
|
+
MiniKitInstallErrorCodes2["AppOutOfDate"] = "app_out_of_date";
|
|
458
|
+
return MiniKitInstallErrorCodes2;
|
|
459
|
+
})(MiniKitInstallErrorCodes || {});
|
|
460
|
+
var MiniKitInstallErrorMessage = {
|
|
461
|
+
["unknown" /* Unknown */]: "Failed to install MiniKit.",
|
|
462
|
+
["already_installed" /* AlreadyInstalled */]: "MiniKit is already installed.",
|
|
463
|
+
["outside_of_worldapp" /* OutsideOfWorldApp */]: "MiniApp launched outside of WorldApp.",
|
|
464
|
+
["not_on_client" /* NotOnClient */]: "Window object is not available.",
|
|
465
|
+
["app_out_of_date" /* AppOutOfDate */]: "WorldApp is out of date. Please update the app."
|
|
466
|
+
};
|
|
467
|
+
var ShareContactsErrorCodes = /* @__PURE__ */ ((ShareContactsErrorCodes2) => {
|
|
468
|
+
ShareContactsErrorCodes2["UserRejected"] = "user_rejected";
|
|
469
|
+
ShareContactsErrorCodes2["GenericError"] = "generic_error";
|
|
470
|
+
return ShareContactsErrorCodes2;
|
|
471
|
+
})(ShareContactsErrorCodes || {});
|
|
472
|
+
var ShareContactsErrorMessage = {
|
|
473
|
+
["user_rejected" /* UserRejected */]: "User rejected the request.",
|
|
474
|
+
["generic_error" /* GenericError */]: "Something unexpected went wrong."
|
|
475
|
+
};
|
|
476
|
+
var RequestPermissionErrorCodes = /* @__PURE__ */ ((RequestPermissionErrorCodes2) => {
|
|
477
|
+
RequestPermissionErrorCodes2["UserRejected"] = "user_rejected";
|
|
478
|
+
RequestPermissionErrorCodes2["GenericError"] = "generic_error";
|
|
479
|
+
RequestPermissionErrorCodes2["AlreadyRequested"] = "already_requested";
|
|
480
|
+
RequestPermissionErrorCodes2["PermissionDisabled"] = "permission_disabled";
|
|
481
|
+
RequestPermissionErrorCodes2["AlreadyGranted"] = "already_granted";
|
|
482
|
+
RequestPermissionErrorCodes2["UnsupportedPermission"] = "unsupported_permission";
|
|
483
|
+
return RequestPermissionErrorCodes2;
|
|
484
|
+
})(RequestPermissionErrorCodes || {});
|
|
485
|
+
var RequestPermissionErrorMessage = {
|
|
486
|
+
["user_rejected" /* UserRejected */]: "User declined sharing contacts",
|
|
487
|
+
["generic_error" /* GenericError */]: "Request failed for unknown reason.",
|
|
488
|
+
["already_requested" /* AlreadyRequested */]: "User has already declined turning on notifications once",
|
|
489
|
+
["permission_disabled" /* PermissionDisabled */]: "User does not have this permission enabled in World App",
|
|
490
|
+
["already_granted" /* AlreadyGranted */]: "If the user has already granted this mini app permission",
|
|
491
|
+
["unsupported_permission" /* UnsupportedPermission */]: "The permission requested is not supported by this mini app"
|
|
492
|
+
};
|
|
493
|
+
var GetPermissionsErrorCodes = /* @__PURE__ */ ((GetPermissionsErrorCodes2) => {
|
|
494
|
+
GetPermissionsErrorCodes2["GenericError"] = "generic_error";
|
|
495
|
+
return GetPermissionsErrorCodes2;
|
|
496
|
+
})(GetPermissionsErrorCodes || {});
|
|
497
|
+
var GetPermissionsErrorMessage = {
|
|
498
|
+
["generic_error" /* GenericError */]: "Something unexpected went wrong. Please try again."
|
|
499
|
+
};
|
|
500
|
+
var SendHapticFeedbackErrorCodes = /* @__PURE__ */ ((SendHapticFeedbackErrorCodes2) => {
|
|
501
|
+
SendHapticFeedbackErrorCodes2["GenericError"] = "generic_error";
|
|
502
|
+
SendHapticFeedbackErrorCodes2["UserRejected"] = "user_rejected";
|
|
503
|
+
return SendHapticFeedbackErrorCodes2;
|
|
504
|
+
})(SendHapticFeedbackErrorCodes || {});
|
|
505
|
+
var SendHapticFeedbackErrorMessage = {
|
|
506
|
+
["generic_error" /* GenericError */]: "Something unexpected went wrong.",
|
|
507
|
+
["user_rejected" /* UserRejected */]: "User rejected the request."
|
|
508
|
+
};
|
|
509
|
+
var ShareFilesErrorCodes = /* @__PURE__ */ ((ShareFilesErrorCodes2) => {
|
|
510
|
+
ShareFilesErrorCodes2["UserRejected"] = "user_rejected";
|
|
511
|
+
ShareFilesErrorCodes2["GenericError"] = "generic_error";
|
|
512
|
+
ShareFilesErrorCodes2["InvalidFileName"] = "invalid_file_name";
|
|
513
|
+
return ShareFilesErrorCodes2;
|
|
514
|
+
})(ShareFilesErrorCodes || {});
|
|
515
|
+
var ShareFilesErrorMessage = {
|
|
516
|
+
["user_rejected" /* UserRejected */]: "User rejected the request.",
|
|
517
|
+
["generic_error" /* GenericError */]: "Something unexpected went wrong.",
|
|
518
|
+
["invalid_file_name" /* InvalidFileName */]: "Invalid file name. Make sure you include the extension"
|
|
519
|
+
};
|
|
520
|
+
|
|
521
|
+
// types/responses.ts
|
|
522
|
+
var ResponseEvent = /* @__PURE__ */ ((ResponseEvent2) => {
|
|
523
|
+
ResponseEvent2["MiniAppVerifyAction"] = "miniapp-verify-action";
|
|
524
|
+
ResponseEvent2["MiniAppPayment"] = "miniapp-payment";
|
|
525
|
+
ResponseEvent2["MiniAppWalletAuth"] = "miniapp-wallet-auth";
|
|
526
|
+
ResponseEvent2["MiniAppSendTransaction"] = "miniapp-send-transaction";
|
|
527
|
+
ResponseEvent2["MiniAppSignMessage"] = "miniapp-sign-message";
|
|
528
|
+
ResponseEvent2["MiniAppSignTypedData"] = "miniapp-sign-typed-data";
|
|
529
|
+
ResponseEvent2["MiniAppShareContacts"] = "miniapp-share-contacts";
|
|
530
|
+
ResponseEvent2["MiniAppRequestPermission"] = "miniapp-request-permission";
|
|
531
|
+
ResponseEvent2["MiniAppGetPermissions"] = "miniapp-get-permissions";
|
|
532
|
+
ResponseEvent2["MiniAppSendHapticFeedback"] = "miniapp-send-haptic-feedback";
|
|
533
|
+
ResponseEvent2["MiniAppShareFiles"] = "miniapp-share-files";
|
|
534
|
+
return ResponseEvent2;
|
|
535
|
+
})(ResponseEvent || {});
|
|
536
|
+
|
|
537
|
+
// minikit.ts
|
|
538
|
+
import { VerificationLevel } from "@worldcoin/idkit-core";
|
|
539
|
+
import { encodeAction, generateSignal } from "@worldcoin/idkit-core/hashing";
|
|
540
|
+
|
|
541
|
+
// helpers/proof/index.ts
|
|
542
|
+
import {
|
|
543
|
+
createPublicClient as createPublicClient2,
|
|
544
|
+
decodeAbiParameters,
|
|
545
|
+
encodeAbiParameters,
|
|
546
|
+
http as http2
|
|
547
|
+
} from "viem";
|
|
548
|
+
import { worldchain as worldchain2 } from "viem/chains";
|
|
549
|
+
var semaphoreVerifierAddress = "0x79f46b94d134109EbcbbddBAeD0E88790409A0e4";
|
|
550
|
+
var semaphoreVerifierAbi = [
|
|
551
|
+
{
|
|
552
|
+
inputs: [
|
|
553
|
+
{
|
|
554
|
+
internalType: "uint256[8]",
|
|
555
|
+
name: "proof",
|
|
556
|
+
type: "uint256[8]"
|
|
557
|
+
}
|
|
558
|
+
],
|
|
559
|
+
name: "compressProof",
|
|
560
|
+
outputs: [
|
|
561
|
+
{
|
|
562
|
+
internalType: "uint256[4]",
|
|
563
|
+
name: "compressed",
|
|
564
|
+
type: "uint256[4]"
|
|
565
|
+
}
|
|
566
|
+
],
|
|
567
|
+
stateMutability: "view",
|
|
568
|
+
type: "function"
|
|
569
|
+
}
|
|
570
|
+
];
|
|
571
|
+
var compressAndPadProof = async (proof, rpcUrl) => {
|
|
572
|
+
try {
|
|
573
|
+
const publicClient = createPublicClient2({
|
|
574
|
+
chain: worldchain2,
|
|
575
|
+
transport: http2(
|
|
576
|
+
rpcUrl || "https://worldchain-mainnet.g.alchemy.com/public"
|
|
577
|
+
)
|
|
578
|
+
});
|
|
579
|
+
const decodedProof = decodeAbiParameters(
|
|
580
|
+
[{ type: "uint256[8]" }],
|
|
581
|
+
proof
|
|
582
|
+
)[0];
|
|
583
|
+
const compressedProof = await publicClient.readContract({
|
|
584
|
+
address: semaphoreVerifierAddress,
|
|
585
|
+
abi: semaphoreVerifierAbi,
|
|
586
|
+
functionName: "compressProof",
|
|
587
|
+
args: [decodedProof]
|
|
588
|
+
});
|
|
589
|
+
const paddedProof = [...compressedProof, 0n, 0n, 0n, 0n];
|
|
590
|
+
return encodeAbiParameters([{ type: "uint256[8]" }], [paddedProof]);
|
|
591
|
+
} catch (e) {
|
|
592
|
+
console.log("Failed to compress proof", {
|
|
593
|
+
e,
|
|
594
|
+
proof
|
|
595
|
+
});
|
|
596
|
+
return proof;
|
|
597
|
+
}
|
|
598
|
+
};
|
|
599
|
+
|
|
600
|
+
// helpers/siwe/validate-wallet-auth-command-input.ts
|
|
601
|
+
var validateWalletAuthCommandInput = (params) => {
|
|
602
|
+
if (!params.nonce) {
|
|
603
|
+
return { valid: false, message: "'nonce' is required" };
|
|
604
|
+
}
|
|
605
|
+
if (params.nonce.length < 8) {
|
|
606
|
+
return { valid: false, message: "'nonce' must be at least 8 characters" };
|
|
607
|
+
}
|
|
608
|
+
if (params.statement && params.statement.includes("\n")) {
|
|
609
|
+
return { valid: false, message: "'statement' must not contain newlines" };
|
|
610
|
+
}
|
|
611
|
+
if (params.expirationTime && new Date(params.expirationTime) < /* @__PURE__ */ new Date()) {
|
|
612
|
+
return { valid: false, message: "'expirationTime' must be in the future" };
|
|
613
|
+
}
|
|
614
|
+
if (params.expirationTime && new Date(params.expirationTime) > new Date(Date.now() + 7 * 24 * 60 * 60 * 1e3)) {
|
|
615
|
+
return { valid: false, message: "'expirationTime' must be within 7 days" };
|
|
616
|
+
}
|
|
617
|
+
if (params.notBefore && new Date(params.notBefore) > new Date(Date.now() + 7 * 24 * 60 * 60 * 1e3)) {
|
|
618
|
+
return { valid: false, message: "'notBefore' must be within 7 days" };
|
|
619
|
+
}
|
|
620
|
+
return { valid: true };
|
|
621
|
+
};
|
|
622
|
+
|
|
623
|
+
// helpers/transaction/validate-payload.ts
|
|
624
|
+
var isValidHex = (str) => {
|
|
625
|
+
return /^0x[0-9A-Fa-f]+$/.test(str);
|
|
626
|
+
};
|
|
627
|
+
var processPayload = (payload) => {
|
|
628
|
+
if (typeof payload === "boolean" || typeof payload === "string" || payload === null || payload === void 0) {
|
|
629
|
+
return payload;
|
|
630
|
+
}
|
|
631
|
+
if (typeof payload === "number" || typeof payload === "bigint") {
|
|
632
|
+
return String(payload);
|
|
633
|
+
}
|
|
634
|
+
if (Array.isArray(payload)) {
|
|
635
|
+
return payload.map((value) => processPayload(value));
|
|
636
|
+
}
|
|
637
|
+
if (typeof payload === "object") {
|
|
638
|
+
const result = { ...payload };
|
|
639
|
+
if ("value" in result && result.value !== void 0) {
|
|
640
|
+
if (typeof result.value !== "string") {
|
|
641
|
+
result.value = String(result.value);
|
|
642
|
+
}
|
|
643
|
+
if (!isValidHex(result.value)) {
|
|
644
|
+
console.error(
|
|
645
|
+
"Transaction value must be a valid hex string",
|
|
646
|
+
result.value
|
|
647
|
+
);
|
|
648
|
+
throw new Error(
|
|
649
|
+
`Transaction value must be a valid hex string: ${result.value}`
|
|
650
|
+
);
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
for (const key in result) {
|
|
654
|
+
if (Object.prototype.hasOwnProperty.call(result, key)) {
|
|
655
|
+
result[key] = processPayload(result[key]);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
return result;
|
|
659
|
+
}
|
|
660
|
+
return payload;
|
|
661
|
+
};
|
|
662
|
+
var validateSendTransactionPayload = (payload) => {
|
|
663
|
+
return processPayload(payload);
|
|
664
|
+
};
|
|
665
|
+
|
|
666
|
+
// helpers/usernames/index.ts
|
|
667
|
+
var getUserProfile = async (address) => {
|
|
668
|
+
const res = await fetch("https://usernames.worldcoin.org/api/v1/query", {
|
|
669
|
+
method: "POST",
|
|
670
|
+
headers: {
|
|
671
|
+
"Content-Type": "application/json"
|
|
672
|
+
},
|
|
673
|
+
body: JSON.stringify({
|
|
674
|
+
addresses: [address]
|
|
675
|
+
})
|
|
676
|
+
});
|
|
677
|
+
const usernames = await res.json();
|
|
678
|
+
return usernames?.[0] ?? { username: null, profile_picture_url: null };
|
|
679
|
+
};
|
|
680
|
+
|
|
681
|
+
// helpers/send-webview-event.ts
|
|
682
|
+
var sendWebviewEvent = (payload) => {
|
|
683
|
+
if (window.webkit) {
|
|
684
|
+
window.webkit?.messageHandlers?.minikit?.postMessage?.(payload);
|
|
685
|
+
} else if (window.Android) {
|
|
686
|
+
window.Android.postMessage?.(JSON.stringify(payload));
|
|
687
|
+
}
|
|
688
|
+
};
|
|
689
|
+
|
|
690
|
+
// minikit.ts
|
|
691
|
+
var sendMiniKitEvent = (payload) => {
|
|
692
|
+
sendWebviewEvent(payload);
|
|
693
|
+
};
|
|
694
|
+
var _MiniKit = class _MiniKit {
|
|
695
|
+
static sendInit() {
|
|
696
|
+
sendWebviewEvent({
|
|
697
|
+
command: "init",
|
|
698
|
+
payload: { version: this.MINIKIT_VERSION }
|
|
699
|
+
});
|
|
700
|
+
}
|
|
701
|
+
static subscribe(event, handler) {
|
|
702
|
+
if (event === "miniapp-wallet-auth" /* MiniAppWalletAuth */) {
|
|
703
|
+
const originalHandler = handler;
|
|
704
|
+
const wrappedHandler = async (payload) => {
|
|
705
|
+
if (payload.status === "success") {
|
|
706
|
+
_MiniKit.user.walletAddress = payload.address;
|
|
707
|
+
try {
|
|
708
|
+
const user = await _MiniKit.getUserByAddress(payload.address);
|
|
709
|
+
_MiniKit.user = { ..._MiniKit.user, ...user };
|
|
710
|
+
} catch (error) {
|
|
711
|
+
console.error("Failed to fetch user profile:", error);
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
originalHandler(payload);
|
|
715
|
+
};
|
|
716
|
+
this.listeners[event] = wrappedHandler;
|
|
717
|
+
} else if (event === "miniapp-verify-action" /* MiniAppVerifyAction */) {
|
|
718
|
+
const originalHandler = handler;
|
|
719
|
+
const wrappedHandler = (payload) => {
|
|
720
|
+
if (payload.status === "success" && payload.verification_level === VerificationLevel.Orb) {
|
|
721
|
+
compressAndPadProof(payload.proof).then(
|
|
722
|
+
(compressedProof) => {
|
|
723
|
+
payload.proof = compressedProof;
|
|
724
|
+
originalHandler(payload);
|
|
725
|
+
}
|
|
726
|
+
);
|
|
727
|
+
} else {
|
|
728
|
+
originalHandler(payload);
|
|
729
|
+
}
|
|
730
|
+
};
|
|
731
|
+
this.listeners[event] = wrappedHandler;
|
|
732
|
+
} else {
|
|
733
|
+
this.listeners[event] = handler;
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
static unsubscribe(event) {
|
|
737
|
+
delete this.listeners[event];
|
|
738
|
+
}
|
|
739
|
+
static trigger(event, payload) {
|
|
740
|
+
if (!this.listeners[event]) {
|
|
741
|
+
console.error(
|
|
742
|
+
`No handler for event ${event}, payload: ${JSON.stringify(payload)}`
|
|
743
|
+
);
|
|
744
|
+
return;
|
|
745
|
+
}
|
|
746
|
+
this.listeners[event](payload);
|
|
747
|
+
}
|
|
748
|
+
static async awaitCommand(event, command, executor) {
|
|
749
|
+
return new Promise((resolve) => {
|
|
750
|
+
let commandPayload = null;
|
|
751
|
+
const handleAndUnsubscribe = (payload) => {
|
|
752
|
+
this.unsubscribe(event);
|
|
753
|
+
resolve({ commandPayload, finalPayload: payload });
|
|
754
|
+
};
|
|
755
|
+
this.subscribe(event, handleAndUnsubscribe);
|
|
756
|
+
commandPayload = executor();
|
|
757
|
+
});
|
|
758
|
+
}
|
|
759
|
+
static commandsValid(worldAppSupportedCommands) {
|
|
760
|
+
let allCommandsValid = true;
|
|
761
|
+
Object.entries(this.miniKitCommandVersion).forEach(
|
|
762
|
+
([minikitCommandName, version]) => {
|
|
763
|
+
const commandInput = worldAppSupportedCommands.find(
|
|
764
|
+
(command) => command.name === minikitCommandName
|
|
765
|
+
);
|
|
766
|
+
let isCommandValid = false;
|
|
767
|
+
if (!commandInput) {
|
|
768
|
+
console.error(
|
|
769
|
+
`Command ${minikitCommandName} is not supported by the app. Try updating the app version`
|
|
770
|
+
);
|
|
771
|
+
} else {
|
|
772
|
+
if (commandInput.supported_versions.includes(version)) {
|
|
773
|
+
_MiniKit.isCommandAvailable[minikitCommandName] = true;
|
|
774
|
+
isCommandValid = true;
|
|
775
|
+
} else {
|
|
776
|
+
console.error(
|
|
777
|
+
`Command ${minikitCommandName} version ${version} is not supported by the app. Supported versions: ${commandInput.supported_versions.join(", ")}`
|
|
778
|
+
);
|
|
779
|
+
_MiniKit.isCommandAvailable[minikitCommandName] = isCommandValid;
|
|
780
|
+
}
|
|
781
|
+
}
|
|
782
|
+
if (!isCommandValid) {
|
|
783
|
+
allCommandsValid = false;
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
);
|
|
787
|
+
return allCommandsValid;
|
|
788
|
+
}
|
|
789
|
+
static install(appId) {
|
|
790
|
+
if (typeof window === "undefined" || Boolean(window.MiniKit)) {
|
|
791
|
+
return {
|
|
792
|
+
success: false,
|
|
793
|
+
errorCode: "already_installed" /* AlreadyInstalled */,
|
|
794
|
+
errorMessage: MiniKitInstallErrorMessage["already_installed" /* AlreadyInstalled */]
|
|
795
|
+
};
|
|
796
|
+
}
|
|
797
|
+
if (!appId) {
|
|
798
|
+
console.warn("App ID not provided during install");
|
|
799
|
+
} else {
|
|
800
|
+
_MiniKit.appId = appId;
|
|
801
|
+
}
|
|
802
|
+
if (!window.WorldApp) {
|
|
803
|
+
return {
|
|
804
|
+
success: false,
|
|
805
|
+
errorCode: "outside_of_worldapp" /* OutsideOfWorldApp */,
|
|
806
|
+
errorMessage: MiniKitInstallErrorMessage["outside_of_worldapp" /* OutsideOfWorldApp */]
|
|
807
|
+
};
|
|
808
|
+
}
|
|
809
|
+
_MiniKit.user.optedIntoOptionalAnalytics = window.WorldApp.is_optional_analytics;
|
|
810
|
+
_MiniKit.user.deviceOS = window.WorldApp.device_os;
|
|
811
|
+
_MiniKit.user.worldAppVersion = window.WorldApp.world_app_version;
|
|
812
|
+
try {
|
|
813
|
+
window.MiniKit = _MiniKit;
|
|
814
|
+
this.sendInit();
|
|
815
|
+
} catch (error) {
|
|
816
|
+
console.error(
|
|
817
|
+
MiniKitInstallErrorMessage["unknown" /* Unknown */],
|
|
818
|
+
error
|
|
819
|
+
);
|
|
820
|
+
return {
|
|
821
|
+
success: false,
|
|
822
|
+
errorCode: "unknown" /* Unknown */,
|
|
823
|
+
errorMessage: MiniKitInstallErrorMessage["unknown" /* Unknown */]
|
|
824
|
+
};
|
|
825
|
+
}
|
|
826
|
+
if (!this.commandsValid(window.WorldApp.supported_commands)) {
|
|
827
|
+
return {
|
|
828
|
+
success: false,
|
|
829
|
+
errorCode: "app_out_of_date" /* AppOutOfDate */,
|
|
830
|
+
errorMessage: MiniKitInstallErrorMessage["app_out_of_date" /* AppOutOfDate */]
|
|
831
|
+
};
|
|
832
|
+
}
|
|
833
|
+
_MiniKit.isReady = true;
|
|
834
|
+
return { success: true };
|
|
835
|
+
}
|
|
836
|
+
static isInstalled(debug) {
|
|
837
|
+
const isInstalled = _MiniKit.isReady && Boolean(window.MiniKit);
|
|
838
|
+
if (!isInstalled)
|
|
839
|
+
console.error(
|
|
840
|
+
"MiniKit is not installed. Make sure you're running the application inside of World App"
|
|
841
|
+
);
|
|
842
|
+
if (debug && isInstalled) console.log("MiniKit is alive!");
|
|
843
|
+
return isInstalled;
|
|
844
|
+
}
|
|
845
|
+
};
|
|
846
|
+
_MiniKit.MINIKIT_VERSION = 1;
|
|
847
|
+
_MiniKit.miniKitCommandVersion = {
|
|
848
|
+
["verify" /* Verify */]: 1,
|
|
849
|
+
["pay" /* Pay */]: 1,
|
|
850
|
+
["wallet-auth" /* WalletAuth */]: 1,
|
|
851
|
+
["send-transaction" /* SendTransaction */]: 1,
|
|
852
|
+
["sign-message" /* SignMessage */]: 1,
|
|
853
|
+
["sign-typed-data" /* SignTypedData */]: 1,
|
|
854
|
+
["share-contacts" /* ShareContacts */]: 1,
|
|
855
|
+
["request-permission" /* RequestPermission */]: 1,
|
|
856
|
+
["get-permissions" /* GetPermissions */]: 1,
|
|
857
|
+
["send-haptic-feedback" /* SendHapticFeedback */]: 1
|
|
858
|
+
// [Command.ShareFiles]: 1,
|
|
859
|
+
};
|
|
860
|
+
_MiniKit.isCommandAvailable = {
|
|
861
|
+
["verify" /* Verify */]: false,
|
|
862
|
+
["pay" /* Pay */]: false,
|
|
863
|
+
["wallet-auth" /* WalletAuth */]: false,
|
|
864
|
+
["send-transaction" /* SendTransaction */]: false,
|
|
865
|
+
["sign-message" /* SignMessage */]: false,
|
|
866
|
+
["sign-typed-data" /* SignTypedData */]: false,
|
|
867
|
+
["share-contacts" /* ShareContacts */]: false,
|
|
868
|
+
["request-permission" /* RequestPermission */]: false,
|
|
869
|
+
["get-permissions" /* GetPermissions */]: false,
|
|
870
|
+
["send-haptic-feedback" /* SendHapticFeedback */]: false
|
|
871
|
+
// [Command.ShareFiles]: false,
|
|
872
|
+
};
|
|
873
|
+
_MiniKit.listeners = {
|
|
874
|
+
["miniapp-verify-action" /* MiniAppVerifyAction */]: () => {
|
|
875
|
+
},
|
|
876
|
+
["miniapp-payment" /* MiniAppPayment */]: () => {
|
|
877
|
+
},
|
|
878
|
+
["miniapp-wallet-auth" /* MiniAppWalletAuth */]: () => {
|
|
879
|
+
},
|
|
880
|
+
["miniapp-send-transaction" /* MiniAppSendTransaction */]: () => {
|
|
881
|
+
},
|
|
882
|
+
["miniapp-sign-message" /* MiniAppSignMessage */]: () => {
|
|
883
|
+
},
|
|
884
|
+
["miniapp-sign-typed-data" /* MiniAppSignTypedData */]: () => {
|
|
885
|
+
},
|
|
886
|
+
["miniapp-share-contacts" /* MiniAppShareContacts */]: () => {
|
|
887
|
+
},
|
|
888
|
+
["miniapp-request-permission" /* MiniAppRequestPermission */]: () => {
|
|
889
|
+
},
|
|
890
|
+
["miniapp-get-permissions" /* MiniAppGetPermissions */]: () => {
|
|
891
|
+
},
|
|
892
|
+
["miniapp-send-haptic-feedback" /* MiniAppSendHapticFeedback */]: () => {
|
|
893
|
+
},
|
|
894
|
+
["miniapp-share-files" /* MiniAppShareFiles */]: () => {
|
|
895
|
+
}
|
|
896
|
+
};
|
|
897
|
+
_MiniKit.appId = null;
|
|
898
|
+
_MiniKit.user = {};
|
|
899
|
+
_MiniKit.isReady = false;
|
|
900
|
+
_MiniKit.getUserByAddress = async (address) => {
|
|
901
|
+
const userProfile = await getUserProfile(
|
|
902
|
+
address ?? _MiniKit.user.walletAddress
|
|
903
|
+
);
|
|
904
|
+
return {
|
|
905
|
+
walletAddress: address ?? _MiniKit.user.walletAddress,
|
|
906
|
+
username: userProfile.username,
|
|
907
|
+
profilePictureUrl: userProfile.profile_picture_url
|
|
908
|
+
};
|
|
909
|
+
};
|
|
910
|
+
_MiniKit.getUserByUsername = async (username) => {
|
|
911
|
+
const res = await fetch(
|
|
912
|
+
`https://usernames.worldcoin.org/api/v1/${username}`,
|
|
913
|
+
{
|
|
914
|
+
method: "GET",
|
|
915
|
+
headers: {
|
|
916
|
+
"Content-Type": "application/json"
|
|
917
|
+
}
|
|
918
|
+
}
|
|
919
|
+
);
|
|
920
|
+
const user = await res.json();
|
|
921
|
+
return {
|
|
922
|
+
walletAddress: user.address,
|
|
923
|
+
username: user.username,
|
|
924
|
+
profilePictureUrl: user.profile_picture_url
|
|
925
|
+
};
|
|
926
|
+
};
|
|
927
|
+
// Simply re-exporting the existing function
|
|
928
|
+
_MiniKit.getUserInfo = _MiniKit.getUserByAddress;
|
|
929
|
+
_MiniKit.commands = {
|
|
930
|
+
verify: (payload) => {
|
|
931
|
+
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["verify" /* Verify */]) {
|
|
932
|
+
console.error(
|
|
933
|
+
"'verify' command is unavailable. Check MiniKit.install() or update the app version"
|
|
934
|
+
);
|
|
935
|
+
return null;
|
|
936
|
+
}
|
|
937
|
+
const timestamp = (/* @__PURE__ */ new Date()).toISOString();
|
|
938
|
+
const eventPayload = {
|
|
939
|
+
action: encodeAction(payload.action),
|
|
940
|
+
signal: generateSignal(payload.signal).digest,
|
|
941
|
+
verification_level: payload.verification_level || VerificationLevel.Orb,
|
|
942
|
+
timestamp
|
|
943
|
+
};
|
|
944
|
+
sendMiniKitEvent({
|
|
945
|
+
command: "verify" /* Verify */,
|
|
946
|
+
version: _MiniKit.miniKitCommandVersion["verify" /* Verify */],
|
|
947
|
+
payload: eventPayload
|
|
948
|
+
});
|
|
949
|
+
return eventPayload;
|
|
950
|
+
},
|
|
951
|
+
pay: (payload) => {
|
|
952
|
+
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["pay" /* Pay */]) {
|
|
953
|
+
console.error(
|
|
954
|
+
"'pay' command is unavailable. Check MiniKit.install() or update the app version"
|
|
955
|
+
);
|
|
956
|
+
return null;
|
|
957
|
+
}
|
|
958
|
+
if (!validatePaymentPayload(payload)) {
|
|
959
|
+
return null;
|
|
960
|
+
}
|
|
961
|
+
const eventPayload = {
|
|
962
|
+
...payload,
|
|
963
|
+
network: "worldchain" /* WorldChain */
|
|
964
|
+
};
|
|
965
|
+
sendMiniKitEvent({
|
|
966
|
+
command: "pay" /* Pay */,
|
|
967
|
+
version: _MiniKit.miniKitCommandVersion["pay" /* Pay */],
|
|
968
|
+
payload: eventPayload
|
|
969
|
+
});
|
|
970
|
+
return eventPayload;
|
|
971
|
+
},
|
|
972
|
+
walletAuth: (payload) => {
|
|
973
|
+
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["wallet-auth" /* WalletAuth */]) {
|
|
974
|
+
console.error(
|
|
975
|
+
"'walletAuth' command is unavailable. Check MiniKit.install() or update the app version"
|
|
976
|
+
);
|
|
977
|
+
return null;
|
|
978
|
+
}
|
|
979
|
+
const validationResult = validateWalletAuthCommandInput(payload);
|
|
980
|
+
if (!validationResult.valid) {
|
|
981
|
+
console.error(
|
|
982
|
+
"Failed to validate wallet auth input:\n\n -->",
|
|
983
|
+
validationResult.message
|
|
984
|
+
);
|
|
985
|
+
return null;
|
|
986
|
+
}
|
|
987
|
+
let protocol = null;
|
|
988
|
+
try {
|
|
989
|
+
const currentUrl = new URL(window.location.href);
|
|
990
|
+
protocol = currentUrl.protocol.split(":")[0];
|
|
991
|
+
} catch (error) {
|
|
992
|
+
console.error("Failed to get current URL", error);
|
|
993
|
+
return null;
|
|
994
|
+
}
|
|
995
|
+
const siweMessage = generateSiweMessage({
|
|
996
|
+
scheme: protocol,
|
|
997
|
+
domain: window.location.host,
|
|
998
|
+
statement: payload.statement ?? void 0,
|
|
999
|
+
uri: window.location.href,
|
|
1000
|
+
version: "1",
|
|
1001
|
+
chain_id: 480,
|
|
1002
|
+
nonce: payload.nonce,
|
|
1003
|
+
issued_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1004
|
+
expiration_time: payload.expirationTime?.toISOString() ?? void 0,
|
|
1005
|
+
not_before: payload.notBefore?.toISOString() ?? void 0,
|
|
1006
|
+
request_id: payload.requestId ?? void 0
|
|
1007
|
+
});
|
|
1008
|
+
const walletAuthPayload = { siweMessage };
|
|
1009
|
+
sendMiniKitEvent({
|
|
1010
|
+
command: "wallet-auth" /* WalletAuth */,
|
|
1011
|
+
version: _MiniKit.miniKitCommandVersion["wallet-auth" /* WalletAuth */],
|
|
1012
|
+
payload: walletAuthPayload
|
|
1013
|
+
});
|
|
1014
|
+
return walletAuthPayload;
|
|
1015
|
+
},
|
|
1016
|
+
sendTransaction: (payload) => {
|
|
1017
|
+
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["send-transaction" /* SendTransaction */]) {
|
|
1018
|
+
console.error(
|
|
1019
|
+
"'sendTransaction' command is unavailable. Check MiniKit.install() or update the app version"
|
|
1020
|
+
);
|
|
1021
|
+
return null;
|
|
1022
|
+
}
|
|
1023
|
+
const validatedPayload = validateSendTransactionPayload(payload);
|
|
1024
|
+
sendMiniKitEvent({
|
|
1025
|
+
command: "send-transaction" /* SendTransaction */,
|
|
1026
|
+
version: _MiniKit.miniKitCommandVersion["send-transaction" /* SendTransaction */],
|
|
1027
|
+
payload: validatedPayload
|
|
1028
|
+
});
|
|
1029
|
+
return validatedPayload;
|
|
1030
|
+
},
|
|
1031
|
+
signMessage: (payload) => {
|
|
1032
|
+
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["sign-message" /* SignMessage */]) {
|
|
1033
|
+
console.error(
|
|
1034
|
+
"'signMessage' command is unavailable. Check MiniKit.install() or update the app version"
|
|
1035
|
+
);
|
|
1036
|
+
return null;
|
|
1037
|
+
}
|
|
1038
|
+
sendMiniKitEvent({
|
|
1039
|
+
command: "sign-message" /* SignMessage */,
|
|
1040
|
+
version: _MiniKit.miniKitCommandVersion["sign-message" /* SignMessage */],
|
|
1041
|
+
payload
|
|
1042
|
+
});
|
|
1043
|
+
return payload;
|
|
1044
|
+
},
|
|
1045
|
+
signTypedData: (payload) => {
|
|
1046
|
+
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["sign-typed-data" /* SignTypedData */]) {
|
|
1047
|
+
console.error(
|
|
1048
|
+
"'signTypedData' command is unavailable. Check MiniKit.install() or update the app version"
|
|
1049
|
+
);
|
|
1050
|
+
return null;
|
|
1051
|
+
}
|
|
1052
|
+
sendMiniKitEvent({
|
|
1053
|
+
command: "sign-typed-data" /* SignTypedData */,
|
|
1054
|
+
version: _MiniKit.miniKitCommandVersion["sign-typed-data" /* SignTypedData */],
|
|
1055
|
+
payload
|
|
1056
|
+
});
|
|
1057
|
+
return payload;
|
|
1058
|
+
},
|
|
1059
|
+
shareContacts: (payload) => {
|
|
1060
|
+
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["sign-typed-data" /* SignTypedData */]) {
|
|
1061
|
+
console.error(
|
|
1062
|
+
"'shareContacts' command is unavailable. Check MiniKit.install() or update the app version"
|
|
1063
|
+
);
|
|
1064
|
+
return null;
|
|
1065
|
+
}
|
|
1066
|
+
sendMiniKitEvent({
|
|
1067
|
+
command: "share-contacts" /* ShareContacts */,
|
|
1068
|
+
version: _MiniKit.miniKitCommandVersion["share-contacts" /* ShareContacts */],
|
|
1069
|
+
payload
|
|
1070
|
+
});
|
|
1071
|
+
return payload;
|
|
1072
|
+
},
|
|
1073
|
+
requestPermission: (payload) => {
|
|
1074
|
+
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["request-permission" /* RequestPermission */]) {
|
|
1075
|
+
console.error(
|
|
1076
|
+
"'requestPermission' command is unavailable. Check MiniKit.install() or update the app version"
|
|
1077
|
+
);
|
|
1078
|
+
return null;
|
|
1079
|
+
}
|
|
1080
|
+
sendMiniKitEvent({
|
|
1081
|
+
command: "request-permission" /* RequestPermission */,
|
|
1082
|
+
version: _MiniKit.miniKitCommandVersion["request-permission" /* RequestPermission */],
|
|
1083
|
+
payload
|
|
1084
|
+
});
|
|
1085
|
+
return payload;
|
|
1086
|
+
},
|
|
1087
|
+
getPermissions: () => {
|
|
1088
|
+
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["get-permissions" /* GetPermissions */]) {
|
|
1089
|
+
console.error(
|
|
1090
|
+
"'getPermissions' command is unavailable. Check MiniKit.install() or update the app version"
|
|
1091
|
+
);
|
|
1092
|
+
return null;
|
|
1093
|
+
}
|
|
1094
|
+
sendMiniKitEvent({
|
|
1095
|
+
command: "get-permissions" /* GetPermissions */,
|
|
1096
|
+
version: _MiniKit.miniKitCommandVersion["get-permissions" /* GetPermissions */],
|
|
1097
|
+
payload: {}
|
|
1098
|
+
});
|
|
1099
|
+
return {
|
|
1100
|
+
status: "sent"
|
|
1101
|
+
};
|
|
1102
|
+
},
|
|
1103
|
+
sendHapticFeedback: (payload) => {
|
|
1104
|
+
if (typeof window === "undefined" || !_MiniKit.isCommandAvailable["send-haptic-feedback" /* SendHapticFeedback */]) {
|
|
1105
|
+
console.error(
|
|
1106
|
+
"'sendHapticFeedback' command is unavailable. Check MiniKit.install() or update the app version"
|
|
1107
|
+
);
|
|
1108
|
+
return null;
|
|
1109
|
+
}
|
|
1110
|
+
sendMiniKitEvent({
|
|
1111
|
+
command: "send-haptic-feedback" /* SendHapticFeedback */,
|
|
1112
|
+
version: _MiniKit.miniKitCommandVersion["send-haptic-feedback" /* SendHapticFeedback */],
|
|
1113
|
+
payload
|
|
1114
|
+
});
|
|
1115
|
+
return payload;
|
|
1116
|
+
}
|
|
1117
|
+
// shareFiles: (payload: ShareFilesInput): ShareFilesPayload | null => {
|
|
1118
|
+
// if (
|
|
1119
|
+
// typeof window === 'undefined' ||
|
|
1120
|
+
// !this.isCommandAvailable[Command.ShareFiles]
|
|
1121
|
+
// ) {
|
|
1122
|
+
// console.error(
|
|
1123
|
+
// "'shareFiles' command is unavailable. Check MiniKit.install() or update the app version",
|
|
1124
|
+
// );
|
|
1125
|
+
// return null;
|
|
1126
|
+
// }
|
|
1127
|
+
// sendMiniKitEvent<WebViewBasePayload>({
|
|
1128
|
+
// command: Command.ShareFiles,
|
|
1129
|
+
// version: this.miniKitCommandVersion[Command.ShareFiles],
|
|
1130
|
+
// payload,
|
|
1131
|
+
// });
|
|
1132
|
+
// return payload;
|
|
1133
|
+
// },
|
|
1134
|
+
};
|
|
1135
|
+
/**
|
|
1136
|
+
* This object contains async versions of all the commands.
|
|
1137
|
+
* Instead of using event listeners, you can just `await` these.
|
|
1138
|
+
*
|
|
1139
|
+
* They return a standardized object
|
|
1140
|
+
*
|
|
1141
|
+
* commandPayload - object returned by the command function
|
|
1142
|
+
*
|
|
1143
|
+
* finalPayload - object returned by the event listener, or in other words, WorldApp response
|
|
1144
|
+
*/
|
|
1145
|
+
_MiniKit.commandsAsync = {
|
|
1146
|
+
verify: async (payload) => {
|
|
1147
|
+
return new Promise(async (resolve, reject) => {
|
|
1148
|
+
try {
|
|
1149
|
+
const response = await _MiniKit.awaitCommand(
|
|
1150
|
+
"miniapp-verify-action" /* MiniAppVerifyAction */,
|
|
1151
|
+
"verify" /* Verify */,
|
|
1152
|
+
() => _MiniKit.commands.verify(payload)
|
|
1153
|
+
);
|
|
1154
|
+
if (response.finalPayload.status === "success" && response.finalPayload.verification_level === VerificationLevel.Orb) {
|
|
1155
|
+
response.finalPayload.proof = await compressAndPadProof(
|
|
1156
|
+
response.finalPayload.proof
|
|
1157
|
+
);
|
|
1158
|
+
}
|
|
1159
|
+
resolve(response);
|
|
1160
|
+
} catch (error) {
|
|
1161
|
+
reject(error);
|
|
1162
|
+
}
|
|
1163
|
+
});
|
|
1164
|
+
},
|
|
1165
|
+
pay: async (payload) => {
|
|
1166
|
+
return new Promise(async (resolve, reject) => {
|
|
1167
|
+
try {
|
|
1168
|
+
const response = await _MiniKit.awaitCommand(
|
|
1169
|
+
"miniapp-payment" /* MiniAppPayment */,
|
|
1170
|
+
"pay" /* Pay */,
|
|
1171
|
+
() => _MiniKit.commands.pay(payload)
|
|
1172
|
+
);
|
|
1173
|
+
resolve(response);
|
|
1174
|
+
} catch (error) {
|
|
1175
|
+
reject(error);
|
|
1176
|
+
}
|
|
1177
|
+
});
|
|
1178
|
+
},
|
|
1179
|
+
walletAuth: async (payload) => {
|
|
1180
|
+
return new Promise(async (resolve, reject) => {
|
|
1181
|
+
try {
|
|
1182
|
+
const response = await _MiniKit.awaitCommand(
|
|
1183
|
+
"miniapp-wallet-auth" /* MiniAppWalletAuth */,
|
|
1184
|
+
"wallet-auth" /* WalletAuth */,
|
|
1185
|
+
() => _MiniKit.commands.walletAuth(payload)
|
|
1186
|
+
);
|
|
1187
|
+
return resolve(response);
|
|
1188
|
+
} catch (error) {
|
|
1189
|
+
reject(error);
|
|
1190
|
+
}
|
|
1191
|
+
});
|
|
1192
|
+
},
|
|
1193
|
+
sendTransaction: async (payload) => {
|
|
1194
|
+
return new Promise(async (resolve, reject) => {
|
|
1195
|
+
try {
|
|
1196
|
+
const response = await _MiniKit.awaitCommand(
|
|
1197
|
+
"miniapp-send-transaction" /* MiniAppSendTransaction */,
|
|
1198
|
+
"send-transaction" /* SendTransaction */,
|
|
1199
|
+
() => _MiniKit.commands.sendTransaction(payload)
|
|
1200
|
+
);
|
|
1201
|
+
return resolve(response);
|
|
1202
|
+
} catch (error) {
|
|
1203
|
+
reject(error);
|
|
1204
|
+
}
|
|
1205
|
+
});
|
|
1206
|
+
},
|
|
1207
|
+
signMessage: async (payload) => {
|
|
1208
|
+
return new Promise(async (resolve, reject) => {
|
|
1209
|
+
try {
|
|
1210
|
+
const response = await _MiniKit.awaitCommand(
|
|
1211
|
+
"miniapp-sign-message" /* MiniAppSignMessage */,
|
|
1212
|
+
"sign-message" /* SignMessage */,
|
|
1213
|
+
() => _MiniKit.commands.signMessage(payload)
|
|
1214
|
+
);
|
|
1215
|
+
return resolve(response);
|
|
1216
|
+
} catch (error) {
|
|
1217
|
+
reject(error);
|
|
1218
|
+
}
|
|
1219
|
+
});
|
|
1220
|
+
},
|
|
1221
|
+
signTypedData: async (payload) => {
|
|
1222
|
+
return new Promise(async (resolve, reject) => {
|
|
1223
|
+
try {
|
|
1224
|
+
const response = await _MiniKit.awaitCommand(
|
|
1225
|
+
"miniapp-sign-typed-data" /* MiniAppSignTypedData */,
|
|
1226
|
+
"sign-typed-data" /* SignTypedData */,
|
|
1227
|
+
() => _MiniKit.commands.signTypedData(payload)
|
|
1228
|
+
);
|
|
1229
|
+
return resolve(response);
|
|
1230
|
+
} catch (error) {
|
|
1231
|
+
reject(error);
|
|
1232
|
+
}
|
|
1233
|
+
});
|
|
1234
|
+
},
|
|
1235
|
+
shareContacts: async (payload) => {
|
|
1236
|
+
return new Promise(async (resolve, reject) => {
|
|
1237
|
+
try {
|
|
1238
|
+
const response = await _MiniKit.awaitCommand(
|
|
1239
|
+
"miniapp-share-contacts" /* MiniAppShareContacts */,
|
|
1240
|
+
"share-contacts" /* ShareContacts */,
|
|
1241
|
+
() => _MiniKit.commands.shareContacts(payload)
|
|
1242
|
+
);
|
|
1243
|
+
return resolve(response);
|
|
1244
|
+
} catch (error) {
|
|
1245
|
+
reject(error);
|
|
1246
|
+
}
|
|
1247
|
+
});
|
|
1248
|
+
},
|
|
1249
|
+
requestPermission: async (payload) => {
|
|
1250
|
+
return new Promise(async (resolve, reject) => {
|
|
1251
|
+
try {
|
|
1252
|
+
const response = await _MiniKit.awaitCommand(
|
|
1253
|
+
"miniapp-request-permission" /* MiniAppRequestPermission */,
|
|
1254
|
+
"request-permission" /* RequestPermission */,
|
|
1255
|
+
() => _MiniKit.commands.requestPermission(payload)
|
|
1256
|
+
);
|
|
1257
|
+
resolve(response);
|
|
1258
|
+
} catch (error) {
|
|
1259
|
+
reject(error);
|
|
1260
|
+
}
|
|
1261
|
+
});
|
|
1262
|
+
},
|
|
1263
|
+
getPermissions: async () => {
|
|
1264
|
+
return new Promise(async (resolve, reject) => {
|
|
1265
|
+
try {
|
|
1266
|
+
const response = await _MiniKit.awaitCommand(
|
|
1267
|
+
"miniapp-get-permissions" /* MiniAppGetPermissions */,
|
|
1268
|
+
"get-permissions" /* GetPermissions */,
|
|
1269
|
+
() => _MiniKit.commands.getPermissions()
|
|
1270
|
+
);
|
|
1271
|
+
resolve(response);
|
|
1272
|
+
} catch (error) {
|
|
1273
|
+
reject(error);
|
|
1274
|
+
}
|
|
1275
|
+
});
|
|
1276
|
+
},
|
|
1277
|
+
sendHapticFeedback: async (payload) => {
|
|
1278
|
+
return new Promise(async (resolve, reject) => {
|
|
1279
|
+
try {
|
|
1280
|
+
const response = await _MiniKit.awaitCommand(
|
|
1281
|
+
"miniapp-send-haptic-feedback" /* MiniAppSendHapticFeedback */,
|
|
1282
|
+
"send-haptic-feedback" /* SendHapticFeedback */,
|
|
1283
|
+
() => _MiniKit.commands.sendHapticFeedback(payload)
|
|
1284
|
+
);
|
|
1285
|
+
resolve(response);
|
|
1286
|
+
} catch (error) {
|
|
1287
|
+
reject(error);
|
|
1288
|
+
}
|
|
1289
|
+
});
|
|
1290
|
+
}
|
|
1291
|
+
// shareFiles: async (
|
|
1292
|
+
// payload: ShareFilesInput,
|
|
1293
|
+
// ): AsyncHandlerReturn<
|
|
1294
|
+
// ShareFilesPayload | null,
|
|
1295
|
+
// MiniAppShareFilesPayload
|
|
1296
|
+
// > => {
|
|
1297
|
+
// return new Promise(async (resolve, reject) => {
|
|
1298
|
+
// try {
|
|
1299
|
+
// const response = await MiniKit.awaitCommand(
|
|
1300
|
+
// ResponseEvent.MiniAppShareFiles,
|
|
1301
|
+
// Command.ShareFiles,
|
|
1302
|
+
// () => this.commands.shareFiles(payload),
|
|
1303
|
+
// );
|
|
1304
|
+
// resolve(response);
|
|
1305
|
+
// } catch (error) {
|
|
1306
|
+
// reject(error);
|
|
1307
|
+
// }
|
|
1308
|
+
// });
|
|
1309
|
+
// },
|
|
1310
|
+
};
|
|
1311
|
+
var MiniKit = _MiniKit;
|
|
1312
|
+
|
|
1313
|
+
export {
|
|
1314
|
+
Tokens,
|
|
1315
|
+
TokenDecimals,
|
|
1316
|
+
Network,
|
|
1317
|
+
tokenToDecimals,
|
|
1318
|
+
parseSiweMessage,
|
|
1319
|
+
verifySiweMessage,
|
|
1320
|
+
Command,
|
|
1321
|
+
Permission,
|
|
1322
|
+
VerificationErrorMessage,
|
|
1323
|
+
PaymentErrorCodes,
|
|
1324
|
+
PaymentErrorMessage,
|
|
1325
|
+
PaymentValidationErrors,
|
|
1326
|
+
WalletAuthErrorCodes,
|
|
1327
|
+
WalletAuthErrorMessage,
|
|
1328
|
+
SendTransactionErrorCodes,
|
|
1329
|
+
SendTransactionErrorMessage,
|
|
1330
|
+
SignMessageErrorCodes,
|
|
1331
|
+
SignMessageErrorMessage,
|
|
1332
|
+
SignTypedDataErrorCodes,
|
|
1333
|
+
SignTypedDataErrorMessage,
|
|
1334
|
+
MiniKitInstallErrorCodes,
|
|
1335
|
+
MiniKitInstallErrorMessage,
|
|
1336
|
+
ShareContactsErrorCodes,
|
|
1337
|
+
ShareContactsErrorMessage,
|
|
1338
|
+
RequestPermissionErrorCodes,
|
|
1339
|
+
RequestPermissionErrorMessage,
|
|
1340
|
+
GetPermissionsErrorCodes,
|
|
1341
|
+
GetPermissionsErrorMessage,
|
|
1342
|
+
SendHapticFeedbackErrorCodes,
|
|
1343
|
+
SendHapticFeedbackErrorMessage,
|
|
1344
|
+
ShareFilesErrorCodes,
|
|
1345
|
+
ShareFilesErrorMessage,
|
|
1346
|
+
AppErrorCodes2 as AppErrorCodes,
|
|
1347
|
+
ResponseEvent,
|
|
1348
|
+
MiniKit
|
|
1349
|
+
};
|