@worldcoin/minikit-js 1.9.10 → 2.0.0-dev.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/README.md +104 -0
- package/build/address-book.cjs +81 -0
- package/build/address-book.d.cts +3 -0
- package/build/address-book.d.ts +3 -0
- package/build/address-book.js +54 -0
- package/build/chunk-DIACPBCB.js +1692 -0
- package/build/chunk-LHHKY77D.js +274 -0
- package/build/chunk-OTAA7OOI.js +835 -0
- package/build/command-exports.cjs +1825 -0
- package/build/command-exports.d.cts +102 -0
- package/build/command-exports.d.ts +102 -0
- package/build/command-exports.js +121 -0
- package/build/connector/index.cjs +2388 -0
- package/build/connector/index.d.cts +55 -0
- package/build/connector/index.d.ts +55 -0
- package/build/connector/index.js +86 -0
- package/build/index.cjs +1696 -1480
- package/build/index.d.cts +136 -622
- package/build/index.d.ts +136 -622
- package/build/index.js +5 -196
- package/build/minikit-provider.cjs +1465 -834
- package/build/minikit-provider.d.cts +2 -1
- package/build/minikit-provider.d.ts +2 -1
- package/build/minikit-provider.js +2046 -4
- package/build/provider-DeDUsLbs.d.cts +43 -0
- package/build/provider-DeDUsLbs.d.ts +43 -0
- package/build/siwe-exports.cjs +249 -0
- package/build/siwe-exports.d.cts +10 -0
- package/build/siwe-exports.d.ts +10 -0
- package/build/siwe-exports.js +8 -0
- package/build/types-CGVVuGiN.d.ts +438 -0
- package/build/types-CKn5C-Ro.d.cts +220 -0
- package/build/types-CKn5C-Ro.d.ts +220 -0
- package/build/types-DO2UGrgp.d.cts +438 -0
- package/package.json +81 -18
- package/build/chunk-XFGJKKI2.js +0 -1951
- package/index.ts +0 -29
package/build/index.cjs
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,128 +17,26 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
|
-
// index.ts
|
|
21
|
-
var
|
|
22
|
-
__export(
|
|
23
|
-
COMMAND_VERSIONS: () => COMMAND_VERSIONS,
|
|
24
|
-
ChatErrorCodes: () => ChatErrorCodes,
|
|
25
|
-
ChatErrorMessage: () => ChatErrorMessage,
|
|
26
|
-
Command: () => Command,
|
|
27
|
-
GetPermissionsErrorCodes: () => GetPermissionsErrorCodes,
|
|
28
|
-
GetPermissionsErrorMessage: () => GetPermissionsErrorMessage,
|
|
29
|
-
MiniAppLaunchLocation: () => MiniAppLaunchLocation,
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
30
33
|
MiniKit: () => MiniKit,
|
|
31
|
-
|
|
32
|
-
MiniKitInstallErrorMessage: () => MiniKitInstallErrorMessage,
|
|
33
|
-
Network: () => Network,
|
|
34
|
-
PaymentErrorCodes: () => PaymentErrorCodes,
|
|
35
|
-
PaymentErrorMessage: () => PaymentErrorMessage,
|
|
36
|
-
Permission: () => Permission,
|
|
37
|
-
RequestPermissionErrorCodes: () => RequestPermissionErrorCodes,
|
|
38
|
-
RequestPermissionErrorMessage: () => RequestPermissionErrorMessage,
|
|
39
|
-
ResponseEvent: () => ResponseEvent,
|
|
40
|
-
SendHapticFeedbackErrorCodes: () => SendHapticFeedbackErrorCodes,
|
|
41
|
-
SendHapticFeedbackErrorMessage: () => SendHapticFeedbackErrorMessage,
|
|
42
|
-
SendTransactionErrorCodes: () => SendTransactionErrorCodes,
|
|
43
|
-
SendTransactionErrorMessage: () => SendTransactionErrorMessage,
|
|
44
|
-
ShareContactsErrorCodes: () => ShareContactsErrorCodes,
|
|
45
|
-
ShareContactsErrorMessage: () => ShareContactsErrorMessage,
|
|
46
|
-
ShareFilesErrorCodes: () => ShareFilesErrorCodes,
|
|
47
|
-
ShareFilesErrorMessage: () => ShareFilesErrorMessage,
|
|
48
|
-
SignMessageErrorCodes: () => SignMessageErrorCodes,
|
|
49
|
-
SignMessageErrorMessage: () => SignMessageErrorMessage,
|
|
50
|
-
SignTypedDataErrorCodes: () => SignTypedDataErrorCodes,
|
|
51
|
-
SignTypedDataErrorMessage: () => SignTypedDataErrorMessage,
|
|
52
|
-
TokenDecimals: () => TokenDecimals,
|
|
53
|
-
Tokens: () => Tokens,
|
|
54
|
-
VerificationErrorCodes: () => import_idkit_core2.AppErrorCodes,
|
|
55
|
-
VerificationLevel: () => import_idkit_core6.VerificationLevel,
|
|
56
|
-
WalletAuthErrorCodes: () => WalletAuthErrorCodes,
|
|
57
|
-
WalletAuthErrorMessage: () => WalletAuthErrorMessage,
|
|
58
|
-
createAsyncCommands: () => createAsyncCommands,
|
|
59
|
-
createChatAsyncCommand: () => createChatAsyncCommand,
|
|
60
|
-
createChatCommand: () => createChatCommand,
|
|
61
|
-
createCommands: () => createCommands,
|
|
62
|
-
createGetPermissionsAsyncCommand: () => createGetPermissionsAsyncCommand,
|
|
63
|
-
createGetPermissionsCommand: () => createGetPermissionsCommand,
|
|
64
|
-
createPayAsyncCommand: () => createPayAsyncCommand,
|
|
65
|
-
createPayCommand: () => createPayCommand,
|
|
66
|
-
createRequestPermissionAsyncCommand: () => createRequestPermissionAsyncCommand,
|
|
67
|
-
createRequestPermissionCommand: () => createRequestPermissionCommand,
|
|
68
|
-
createSendHapticFeedbackAsyncCommand: () => createSendHapticFeedbackAsyncCommand,
|
|
69
|
-
createSendHapticFeedbackCommand: () => createSendHapticFeedbackCommand,
|
|
70
|
-
createSendTransactionAsyncCommand: () => createSendTransactionAsyncCommand,
|
|
71
|
-
createSendTransactionCommand: () => createSendTransactionCommand,
|
|
72
|
-
createShareAsyncCommand: () => createShareAsyncCommand,
|
|
73
|
-
createShareCommand: () => createShareCommand,
|
|
74
|
-
createShareContactsAsyncCommand: () => createShareContactsAsyncCommand,
|
|
75
|
-
createShareContactsCommand: () => createShareContactsCommand,
|
|
76
|
-
createSignMessageAsyncCommand: () => createSignMessageAsyncCommand,
|
|
77
|
-
createSignMessageCommand: () => createSignMessageCommand,
|
|
78
|
-
createSignTypedDataAsyncCommand: () => createSignTypedDataAsyncCommand,
|
|
79
|
-
createSignTypedDataCommand: () => createSignTypedDataCommand,
|
|
80
|
-
createVerifyAsyncCommand: () => createVerifyAsyncCommand,
|
|
81
|
-
createVerifyCommand: () => createVerifyCommand,
|
|
82
|
-
createWalletAuthAsyncCommand: () => createWalletAuthAsyncCommand,
|
|
83
|
-
createWalletAuthCommand: () => createWalletAuthCommand,
|
|
84
|
-
getIsUserVerified: () => getIsUserVerified,
|
|
85
|
-
isCommandAvailable: () => isCommandAvailable,
|
|
86
|
-
mapWorldAppLaunchLocation: () => mapWorldAppLaunchLocation,
|
|
87
|
-
parseSiweMessage: () => parseSiweMessage,
|
|
88
|
-
sendMiniKitEvent: () => sendMiniKitEvent,
|
|
89
|
-
setCommandAvailable: () => setCommandAvailable,
|
|
90
|
-
tokenToDecimals: () => tokenToDecimals,
|
|
91
|
-
validateCommands: () => validateCommands,
|
|
92
|
-
verifyCloudProof: () => import_backend.verifyCloudProof,
|
|
93
|
-
verifySiweMessage: () => verifySiweMessage
|
|
34
|
+
getWorldAppProvider: () => getWorldAppProvider
|
|
94
35
|
});
|
|
95
|
-
module.exports = __toCommonJS(
|
|
36
|
+
module.exports = __toCommonJS(src_exports);
|
|
96
37
|
|
|
97
|
-
//
|
|
98
|
-
var sendWebviewEvent = (payload) => {
|
|
99
|
-
if (window.webkit) {
|
|
100
|
-
window.webkit?.messageHandlers?.minikit?.postMessage?.(payload);
|
|
101
|
-
} else if (window.Android) {
|
|
102
|
-
window.Android.postMessage?.(JSON.stringify(payload));
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
// commands/types.ts
|
|
107
|
-
var Command = /* @__PURE__ */ ((Command2) => {
|
|
108
|
-
Command2["Verify"] = "verify";
|
|
109
|
-
Command2["Pay"] = "pay";
|
|
110
|
-
Command2["WalletAuth"] = "wallet-auth";
|
|
111
|
-
Command2["SendTransaction"] = "send-transaction";
|
|
112
|
-
Command2["SignMessage"] = "sign-message";
|
|
113
|
-
Command2["SignTypedData"] = "sign-typed-data";
|
|
114
|
-
Command2["ShareContacts"] = "share-contacts";
|
|
115
|
-
Command2["RequestPermission"] = "request-permission";
|
|
116
|
-
Command2["GetPermissions"] = "get-permissions";
|
|
117
|
-
Command2["SendHapticFeedback"] = "send-haptic-feedback";
|
|
118
|
-
Command2["Share"] = "share";
|
|
119
|
-
Command2["Chat"] = "chat";
|
|
120
|
-
return Command2;
|
|
121
|
-
})(Command || {});
|
|
122
|
-
var ResponseEvent = /* @__PURE__ */ ((ResponseEvent3) => {
|
|
123
|
-
ResponseEvent3["MiniAppVerifyAction"] = "miniapp-verify-action";
|
|
124
|
-
ResponseEvent3["MiniAppPayment"] = "miniapp-payment";
|
|
125
|
-
ResponseEvent3["MiniAppWalletAuth"] = "miniapp-wallet-auth";
|
|
126
|
-
ResponseEvent3["MiniAppSendTransaction"] = "miniapp-send-transaction";
|
|
127
|
-
ResponseEvent3["MiniAppSignMessage"] = "miniapp-sign-message";
|
|
128
|
-
ResponseEvent3["MiniAppSignTypedData"] = "miniapp-sign-typed-data";
|
|
129
|
-
ResponseEvent3["MiniAppShareContacts"] = "miniapp-share-contacts";
|
|
130
|
-
ResponseEvent3["MiniAppRequestPermission"] = "miniapp-request-permission";
|
|
131
|
-
ResponseEvent3["MiniAppGetPermissions"] = "miniapp-get-permissions";
|
|
132
|
-
ResponseEvent3["MiniAppSendHapticFeedback"] = "miniapp-send-haptic-feedback";
|
|
133
|
-
ResponseEvent3["MiniAppShare"] = "miniapp-share";
|
|
134
|
-
ResponseEvent3["MiniAppMicrophone"] = "miniapp-microphone";
|
|
135
|
-
ResponseEvent3["MiniAppChat"] = "miniapp-chat";
|
|
136
|
-
return ResponseEvent3;
|
|
137
|
-
})(ResponseEvent || {});
|
|
38
|
+
// src/commands/types.ts
|
|
138
39
|
var COMMAND_VERSIONS = {
|
|
139
|
-
["verify" /* Verify */]: 1,
|
|
140
40
|
["pay" /* Pay */]: 1,
|
|
141
41
|
["wallet-auth" /* WalletAuth */]: 2,
|
|
142
42
|
["send-transaction" /* SendTransaction */]: 1,
|
|
@@ -150,7 +50,6 @@ var COMMAND_VERSIONS = {
|
|
|
150
50
|
["chat" /* Chat */]: 1
|
|
151
51
|
};
|
|
152
52
|
var commandAvailability = {
|
|
153
|
-
["verify" /* Verify */]: false,
|
|
154
53
|
["pay" /* Pay */]: false,
|
|
155
54
|
["wallet-auth" /* WalletAuth */]: false,
|
|
156
55
|
["send-transaction" /* SendTransaction */]: false,
|
|
@@ -164,7 +63,7 @@ var commandAvailability = {
|
|
|
164
63
|
["chat" /* Chat */]: false
|
|
165
64
|
};
|
|
166
65
|
function isCommandAvailable(command) {
|
|
167
|
-
return commandAvailability[command];
|
|
66
|
+
return commandAvailability[command] ?? false;
|
|
168
67
|
}
|
|
169
68
|
function setCommandAvailable(command, available) {
|
|
170
69
|
commandAvailability[command] = available;
|
|
@@ -199,141 +98,447 @@ function validateCommands(worldAppSupportedCommands) {
|
|
|
199
98
|
return allCommandsValid;
|
|
200
99
|
}
|
|
201
100
|
function sendMiniKitEvent(payload) {
|
|
202
|
-
|
|
101
|
+
if (window.webkit) {
|
|
102
|
+
window.webkit?.messageHandlers?.minikit?.postMessage?.(payload);
|
|
103
|
+
} else if (window.Android) {
|
|
104
|
+
window.Android?.postMessage?.(JSON.stringify(payload));
|
|
105
|
+
}
|
|
203
106
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
107
|
+
function isInWorldApp() {
|
|
108
|
+
return typeof window !== "undefined" && Boolean(window.WorldApp);
|
|
109
|
+
}
|
|
110
|
+
var FallbackRequiredError = class extends Error {
|
|
111
|
+
constructor(command) {
|
|
112
|
+
super(
|
|
113
|
+
`${command} requires a fallback function when running outside World App. Provide a fallback option: MiniKit.${command}({ ..., fallback: () => yourFallback() })`
|
|
114
|
+
);
|
|
115
|
+
this.name = "FallbackRequiredError";
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
var CommandUnavailableError = class extends Error {
|
|
119
|
+
constructor(command, reason) {
|
|
120
|
+
const messages = {
|
|
121
|
+
notInWorldApp: "Not running inside World App",
|
|
122
|
+
commandNotSupported: "Command not supported in this environment",
|
|
123
|
+
oldAppVersion: "World App version does not support this command"
|
|
124
|
+
};
|
|
125
|
+
super(`${command} is unavailable: ${messages[reason]}`);
|
|
126
|
+
this.name = "CommandUnavailableError";
|
|
127
|
+
this.reason = reason;
|
|
128
|
+
}
|
|
216
129
|
};
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
130
|
+
|
|
131
|
+
// src/events.ts
|
|
132
|
+
var EventManager = class {
|
|
133
|
+
constructor() {
|
|
134
|
+
this.listeners = {
|
|
135
|
+
["miniapp-payment" /* MiniAppPayment */]: () => {
|
|
136
|
+
},
|
|
137
|
+
["miniapp-wallet-auth" /* MiniAppWalletAuth */]: () => {
|
|
138
|
+
},
|
|
139
|
+
["miniapp-send-transaction" /* MiniAppSendTransaction */]: () => {
|
|
140
|
+
},
|
|
141
|
+
["miniapp-sign-message" /* MiniAppSignMessage */]: () => {
|
|
142
|
+
},
|
|
143
|
+
["miniapp-sign-typed-data" /* MiniAppSignTypedData */]: () => {
|
|
144
|
+
},
|
|
145
|
+
["miniapp-share-contacts" /* MiniAppShareContacts */]: () => {
|
|
146
|
+
},
|
|
147
|
+
["miniapp-request-permission" /* MiniAppRequestPermission */]: () => {
|
|
148
|
+
},
|
|
149
|
+
["miniapp-get-permissions" /* MiniAppGetPermissions */]: () => {
|
|
150
|
+
},
|
|
151
|
+
["miniapp-send-haptic-feedback" /* MiniAppSendHapticFeedback */]: () => {
|
|
152
|
+
},
|
|
153
|
+
["miniapp-share" /* MiniAppShare */]: () => {
|
|
154
|
+
},
|
|
155
|
+
["miniapp-microphone" /* MiniAppMicrophone */]: () => {
|
|
156
|
+
},
|
|
157
|
+
["miniapp-chat" /* MiniAppChat */]: () => {
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
subscribe(event, handler) {
|
|
162
|
+
this.listeners[event] = handler;
|
|
163
|
+
}
|
|
164
|
+
unsubscribe(event) {
|
|
165
|
+
delete this.listeners[event];
|
|
166
|
+
}
|
|
167
|
+
trigger(event, payload) {
|
|
168
|
+
if (!this.listeners[event]) {
|
|
220
169
|
console.error(
|
|
221
|
-
|
|
170
|
+
`No handler for event ${event}, payload: ${JSON.stringify(payload)}`
|
|
222
171
|
);
|
|
223
|
-
return
|
|
172
|
+
return;
|
|
224
173
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
174
|
+
this.listeners[event](payload);
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
// src/commands/wagmi-fallback.ts
|
|
179
|
+
var SIWE_NONCE_REGEX = /^[a-zA-Z0-9]{8,}$/;
|
|
180
|
+
var WAGMI_KEY = "__minikit_wagmi_config__";
|
|
181
|
+
function getWagmiConfig() {
|
|
182
|
+
return globalThis[WAGMI_KEY];
|
|
183
|
+
}
|
|
184
|
+
function hasWagmiConfig() {
|
|
185
|
+
return globalThis[WAGMI_KEY] !== void 0;
|
|
186
|
+
}
|
|
187
|
+
async function ensureConnected(config) {
|
|
188
|
+
const { connect, getConnections } = await import("wagmi/actions");
|
|
189
|
+
const isWorldApp = typeof window !== "undefined" && Boolean(window.WorldApp);
|
|
190
|
+
const existingConnection = getConnections(config).find(
|
|
191
|
+
(connection) => connection.accounts && connection.accounts.length > 0 && (isWorldApp || connection.connector?.id !== "worldApp")
|
|
192
|
+
);
|
|
193
|
+
if (existingConnection && existingConnection.accounts) {
|
|
194
|
+
return existingConnection.accounts[0];
|
|
195
|
+
}
|
|
196
|
+
const connectors = config.connectors;
|
|
197
|
+
if (!connectors || connectors.length === 0) {
|
|
198
|
+
throw new Error("No Wagmi connectors configured");
|
|
199
|
+
}
|
|
200
|
+
const candidateConnectors = isWorldApp ? connectors : connectors.filter(
|
|
201
|
+
(connector) => connector.id !== "worldApp"
|
|
202
|
+
);
|
|
203
|
+
if (!isWorldApp && candidateConnectors.length === 0) {
|
|
204
|
+
throw new Error(
|
|
205
|
+
"No web Wagmi connectors configured. Add a web connector (e.g. injected or walletConnect) after worldApp()."
|
|
206
|
+
);
|
|
207
|
+
}
|
|
208
|
+
const selectedConnector = candidateConnectors[0];
|
|
209
|
+
try {
|
|
210
|
+
const result = await connect(config, { connector: selectedConnector });
|
|
211
|
+
if (result.accounts.length > 0) {
|
|
212
|
+
const account = result.accounts[0];
|
|
213
|
+
const address = typeof account === "string" ? account : account.address;
|
|
214
|
+
if (address) {
|
|
215
|
+
return address;
|
|
216
|
+
}
|
|
228
217
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
218
|
+
} catch (error) {
|
|
219
|
+
const connectorId = selectedConnector.id ?? "unknown";
|
|
220
|
+
const wrappedError = new Error(
|
|
221
|
+
`Failed to connect with connector "${connectorId}". Reorder connectors to change the default connector.`
|
|
222
|
+
);
|
|
223
|
+
wrappedError.cause = error;
|
|
224
|
+
throw wrappedError;
|
|
225
|
+
}
|
|
226
|
+
throw new Error("Failed to connect wallet");
|
|
227
|
+
}
|
|
228
|
+
async function wagmiWalletAuth(params) {
|
|
229
|
+
const config = getWagmiConfig();
|
|
230
|
+
if (!config) {
|
|
231
|
+
throw new Error(
|
|
232
|
+
"Wagmi config not available. Pass wagmiConfig to MiniKitProvider."
|
|
233
|
+
);
|
|
234
|
+
}
|
|
235
|
+
const { signMessage: signMessage2 } = await import("wagmi/actions");
|
|
236
|
+
const { SiweMessage } = await import("siwe");
|
|
237
|
+
const address = await ensureConnected(config);
|
|
238
|
+
if (!SIWE_NONCE_REGEX.test(params.nonce)) {
|
|
239
|
+
throw new Error(
|
|
240
|
+
"Invalid nonce: must be alphanumeric and at least 8 characters (EIP-4361)"
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
const siweMessage = new SiweMessage({
|
|
244
|
+
domain: typeof window !== "undefined" ? window.location.host : "localhost",
|
|
245
|
+
address,
|
|
246
|
+
statement: params.statement,
|
|
247
|
+
uri: typeof window !== "undefined" ? window.location.origin : "http://localhost",
|
|
248
|
+
version: "1",
|
|
249
|
+
chainId: 480,
|
|
250
|
+
// World Chain
|
|
251
|
+
nonce: params.nonce,
|
|
252
|
+
expirationTime: params.expirationTime?.toISOString()
|
|
253
|
+
});
|
|
254
|
+
const message = siweMessage.prepareMessage();
|
|
255
|
+
const signature = await signMessage2(config, { message });
|
|
256
|
+
return {
|
|
257
|
+
address,
|
|
258
|
+
message,
|
|
259
|
+
signature
|
|
235
260
|
};
|
|
236
261
|
}
|
|
237
|
-
function
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
262
|
+
async function wagmiSignMessage(params) {
|
|
263
|
+
const config = getWagmiConfig();
|
|
264
|
+
if (!config) {
|
|
265
|
+
throw new Error(
|
|
266
|
+
"Wagmi config not available. Pass wagmiConfig to MiniKitProvider."
|
|
267
|
+
);
|
|
268
|
+
}
|
|
269
|
+
const { signMessage: signMessage2 } = await import("wagmi/actions");
|
|
270
|
+
const address = await ensureConnected(config);
|
|
271
|
+
const signature = await signMessage2(config, {
|
|
272
|
+
account: address,
|
|
273
|
+
message: params.message
|
|
274
|
+
});
|
|
275
|
+
return {
|
|
276
|
+
status: "success",
|
|
277
|
+
version: 1,
|
|
278
|
+
signature,
|
|
279
|
+
address
|
|
252
280
|
};
|
|
253
281
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
282
|
+
async function wagmiSignTypedData(params) {
|
|
283
|
+
const config = getWagmiConfig();
|
|
284
|
+
if (!config) {
|
|
285
|
+
throw new Error(
|
|
286
|
+
"Wagmi config not available. Pass wagmiConfig to MiniKitProvider."
|
|
287
|
+
);
|
|
288
|
+
}
|
|
289
|
+
const { getChainId, signTypedData: signTypedData2, switchChain } = await import("wagmi/actions");
|
|
290
|
+
const address = await ensureConnected(config);
|
|
291
|
+
if (params.chainId !== void 0) {
|
|
292
|
+
const currentChainId = await getChainId(config);
|
|
293
|
+
if (currentChainId !== params.chainId) {
|
|
294
|
+
await switchChain(config, { chainId: params.chainId });
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
const signature = await signTypedData2(config, {
|
|
298
|
+
account: address,
|
|
299
|
+
types: params.types,
|
|
300
|
+
primaryType: params.primaryType,
|
|
301
|
+
domain: params.domain,
|
|
302
|
+
message: params.message
|
|
303
|
+
});
|
|
304
|
+
return {
|
|
305
|
+
status: "success",
|
|
306
|
+
version: 1,
|
|
307
|
+
signature,
|
|
308
|
+
address
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
function isChainMismatchError(error) {
|
|
312
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
313
|
+
return message.includes("does not match the target chain");
|
|
314
|
+
}
|
|
315
|
+
async function wagmiSendTransaction(params) {
|
|
316
|
+
const config = getWagmiConfig();
|
|
317
|
+
if (!config) {
|
|
318
|
+
throw new Error(
|
|
319
|
+
"Wagmi config not available. Pass wagmiConfig to MiniKitProvider."
|
|
320
|
+
);
|
|
321
|
+
}
|
|
322
|
+
const { getChainId, getWalletClient, sendTransaction: sendTransaction2, switchChain } = await import("wagmi/actions");
|
|
323
|
+
await ensureConnected(config);
|
|
324
|
+
const targetChainId = params.chainId ?? config.chains?.[0]?.id;
|
|
325
|
+
const ensureTargetChain = async () => {
|
|
326
|
+
if (targetChainId === void 0) return;
|
|
327
|
+
const currentChainId = await getChainId(config);
|
|
328
|
+
if (currentChainId !== targetChainId) {
|
|
329
|
+
await switchChain(config, { chainId: targetChainId });
|
|
330
|
+
}
|
|
331
|
+
const walletClient = await getWalletClient(config);
|
|
332
|
+
const providerChainId = walletClient ? await walletClient.getChainId() : await getChainId(config);
|
|
333
|
+
if (providerChainId !== targetChainId) {
|
|
334
|
+
throw new Error(
|
|
335
|
+
`Wallet network mismatch: expected chain ${targetChainId}, got ${providerChainId}. Please switch networks in your wallet and retry.`
|
|
274
336
|
);
|
|
275
|
-
return null;
|
|
276
337
|
}
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
338
|
+
};
|
|
339
|
+
await ensureTargetChain();
|
|
340
|
+
let transactionHash;
|
|
341
|
+
try {
|
|
342
|
+
transactionHash = await sendTransaction2(config, {
|
|
343
|
+
chainId: targetChainId,
|
|
344
|
+
to: params.transaction.address,
|
|
345
|
+
data: params.transaction.data,
|
|
346
|
+
value: params.transaction.value ? BigInt(params.transaction.value) : void 0
|
|
281
347
|
});
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
348
|
+
} catch (error) {
|
|
349
|
+
if (targetChainId === void 0 || !isChainMismatchError(error)) {
|
|
350
|
+
throw error;
|
|
351
|
+
}
|
|
352
|
+
await ensureTargetChain();
|
|
353
|
+
transactionHash = await sendTransaction2(config, {
|
|
354
|
+
chainId: targetChainId,
|
|
355
|
+
to: params.transaction.address,
|
|
356
|
+
data: params.transaction.data,
|
|
357
|
+
value: params.transaction.value ? BigInt(params.transaction.value) : void 0
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
return { transactionHash };
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
// src/commands/fallback.ts
|
|
364
|
+
async function executeWithFallback(options) {
|
|
365
|
+
const {
|
|
366
|
+
command,
|
|
367
|
+
nativeExecutor,
|
|
368
|
+
wagmiFallback,
|
|
369
|
+
customFallback,
|
|
370
|
+
requiresFallback = false
|
|
371
|
+
} = options;
|
|
372
|
+
const inWorldApp = isInWorldApp();
|
|
373
|
+
const commandAvailable = isCommandAvailable(command);
|
|
374
|
+
let nativeError;
|
|
375
|
+
if (inWorldApp && commandAvailable) {
|
|
376
|
+
try {
|
|
377
|
+
const data = await nativeExecutor();
|
|
378
|
+
return { data, executedWith: "minikit" };
|
|
379
|
+
} catch (error) {
|
|
380
|
+
nativeError = error;
|
|
381
|
+
console.warn(`Native ${command} failed, attempting fallback:`, error);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
if (!inWorldApp && wagmiFallback && hasWagmiConfig()) {
|
|
385
|
+
try {
|
|
386
|
+
const data = await wagmiFallback();
|
|
387
|
+
return { data, executedWith: "wagmi" };
|
|
388
|
+
} catch (error) {
|
|
389
|
+
console.warn(`Wagmi fallback for ${command} failed:`, error);
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
if (customFallback) {
|
|
393
|
+
const data = await customFallback();
|
|
394
|
+
return { data, executedWith: "fallback" };
|
|
395
|
+
}
|
|
396
|
+
if (nativeError) {
|
|
397
|
+
throw nativeError;
|
|
398
|
+
}
|
|
399
|
+
if (requiresFallback && !inWorldApp) {
|
|
400
|
+
throw new FallbackRequiredError(command);
|
|
401
|
+
}
|
|
402
|
+
throw new CommandUnavailableError(command, determineFallbackReason(command));
|
|
403
|
+
}
|
|
404
|
+
function determineFallbackReason(command) {
|
|
405
|
+
if (!isInWorldApp()) {
|
|
406
|
+
return "notInWorldApp";
|
|
407
|
+
}
|
|
408
|
+
if (!isCommandAvailable(command)) {
|
|
409
|
+
return "oldAppVersion";
|
|
410
|
+
}
|
|
411
|
+
return "commandNotSupported";
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
// src/commands/chat/types.ts
|
|
415
|
+
var ChatError = class extends Error {
|
|
416
|
+
constructor(error_code) {
|
|
417
|
+
super(`Chat failed: ${error_code}`);
|
|
418
|
+
this.error_code = error_code;
|
|
419
|
+
this.name = "ChatError";
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
// src/commands/chat/index.ts
|
|
424
|
+
async function chat(options, ctx) {
|
|
425
|
+
const result = await executeWithFallback({
|
|
426
|
+
command: "chat" /* Chat */,
|
|
427
|
+
nativeExecutor: () => nativeChat(options, ctx),
|
|
428
|
+
customFallback: options.fallback
|
|
429
|
+
});
|
|
430
|
+
if (result.executedWith === "fallback") {
|
|
431
|
+
return { executedWith: "fallback", data: result.data };
|
|
432
|
+
}
|
|
433
|
+
return {
|
|
434
|
+
executedWith: "minikit",
|
|
435
|
+
data: result.data
|
|
436
|
+
};
|
|
437
|
+
}
|
|
438
|
+
async function nativeChat(options, ctx) {
|
|
439
|
+
if (!ctx) {
|
|
440
|
+
ctx = { events: new EventManager(), state: { deviceProperties: {} } };
|
|
441
|
+
}
|
|
442
|
+
if (typeof window === "undefined" || !isCommandAvailable("chat" /* Chat */)) {
|
|
443
|
+
throw new Error(
|
|
444
|
+
"'chat' command is unavailable. Check MiniKit.install() or update the app version"
|
|
445
|
+
);
|
|
446
|
+
}
|
|
447
|
+
const payloadInput = {
|
|
448
|
+
message: options.message,
|
|
449
|
+
to: options.to
|
|
450
|
+
};
|
|
451
|
+
if (payloadInput.message.length === 0) {
|
|
452
|
+
throw new Error("'chat' command requires a non-empty message");
|
|
453
|
+
}
|
|
454
|
+
const payload = await new Promise((resolve, reject) => {
|
|
455
|
+
try {
|
|
456
|
+
ctx.events.subscribe("miniapp-chat" /* MiniAppChat */, (response) => {
|
|
457
|
+
ctx.events.unsubscribe("miniapp-chat" /* MiniAppChat */);
|
|
458
|
+
resolve(response);
|
|
459
|
+
});
|
|
460
|
+
sendMiniKitEvent({
|
|
461
|
+
command: "chat" /* Chat */,
|
|
462
|
+
version: COMMAND_VERSIONS["chat" /* Chat */],
|
|
463
|
+
payload: payloadInput
|
|
464
|
+
});
|
|
465
|
+
} catch (error) {
|
|
466
|
+
reject(error);
|
|
467
|
+
}
|
|
468
|
+
});
|
|
469
|
+
if (payload.status === "error") {
|
|
470
|
+
throw new ChatError(payload.error_code);
|
|
471
|
+
}
|
|
472
|
+
return payload;
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
// src/commands/get-permissions/types.ts
|
|
476
|
+
var GetPermissionsError = class extends Error {
|
|
477
|
+
constructor(error_code) {
|
|
478
|
+
super(`Get permissions failed: ${error_code}`);
|
|
479
|
+
this.error_code = error_code;
|
|
480
|
+
this.name = "GetPermissionsError";
|
|
481
|
+
}
|
|
482
|
+
};
|
|
483
|
+
|
|
484
|
+
// src/commands/get-permissions/index.ts
|
|
485
|
+
async function getPermissions(options, ctx) {
|
|
486
|
+
const resolvedOptions = options ?? {};
|
|
487
|
+
const result = await executeWithFallback({
|
|
488
|
+
command: "get-permissions" /* GetPermissions */,
|
|
489
|
+
nativeExecutor: () => nativeGetPermissions(ctx),
|
|
490
|
+
customFallback: resolvedOptions.fallback
|
|
491
|
+
});
|
|
492
|
+
if (result.executedWith === "fallback") {
|
|
493
|
+
return { executedWith: "fallback", data: result.data };
|
|
494
|
+
}
|
|
495
|
+
return {
|
|
496
|
+
executedWith: "minikit",
|
|
497
|
+
data: result.data
|
|
285
498
|
};
|
|
286
499
|
}
|
|
287
|
-
function
|
|
288
|
-
|
|
289
|
-
|
|
500
|
+
async function nativeGetPermissions(ctx) {
|
|
501
|
+
if (!ctx) {
|
|
502
|
+
ctx = { events: new EventManager(), state: { deviceProperties: {} } };
|
|
503
|
+
}
|
|
504
|
+
if (typeof window === "undefined" || !isCommandAvailable("get-permissions" /* GetPermissions */)) {
|
|
505
|
+
throw new Error(
|
|
506
|
+
"'getPermissions' command is unavailable. Check MiniKit.install() or update the app version"
|
|
507
|
+
);
|
|
508
|
+
}
|
|
509
|
+
const payload = await new Promise(
|
|
510
|
+
(resolve, reject) => {
|
|
290
511
|
try {
|
|
291
|
-
|
|
292
|
-
const handleResponse = (payload) => {
|
|
512
|
+
ctx.events.subscribe("miniapp-get-permissions" /* MiniAppGetPermissions */, (response) => {
|
|
293
513
|
ctx.events.unsubscribe("miniapp-get-permissions" /* MiniAppGetPermissions */);
|
|
294
|
-
resolve(
|
|
295
|
-
};
|
|
296
|
-
|
|
297
|
-
"
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
514
|
+
resolve(response);
|
|
515
|
+
});
|
|
516
|
+
sendMiniKitEvent({
|
|
517
|
+
command: "get-permissions" /* GetPermissions */,
|
|
518
|
+
version: COMMAND_VERSIONS["get-permissions" /* GetPermissions */],
|
|
519
|
+
payload: {}
|
|
520
|
+
});
|
|
301
521
|
} catch (error) {
|
|
302
522
|
reject(error);
|
|
303
523
|
}
|
|
304
|
-
}
|
|
305
|
-
|
|
524
|
+
}
|
|
525
|
+
);
|
|
526
|
+
if (payload.status === "error") {
|
|
527
|
+
throw new GetPermissionsError(payload.error_code);
|
|
528
|
+
}
|
|
529
|
+
return payload;
|
|
306
530
|
}
|
|
307
531
|
|
|
308
|
-
// types
|
|
309
|
-
var
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
["USDCE" /* USDC */]: 6,
|
|
316
|
-
["WLD" /* WLD */]: 18
|
|
532
|
+
// src/commands/pay/types.ts
|
|
533
|
+
var PayError = class extends Error {
|
|
534
|
+
constructor(code) {
|
|
535
|
+
super(`Payment failed: ${code}`);
|
|
536
|
+
this.name = "PayError";
|
|
537
|
+
this.code = code;
|
|
538
|
+
}
|
|
317
539
|
};
|
|
318
|
-
var Network = /* @__PURE__ */ ((Network2) => {
|
|
319
|
-
Network2["Optimism"] = "optimism";
|
|
320
|
-
Network2["WorldChain"] = "worldchain";
|
|
321
|
-
return Network2;
|
|
322
|
-
})(Network || {});
|
|
323
540
|
|
|
324
|
-
//
|
|
325
|
-
var tokenToDecimals = (amount, token) => {
|
|
326
|
-
const decimals = TokenDecimals[token];
|
|
327
|
-
if (decimals === void 0) {
|
|
328
|
-
throw new Error(`Invalid token: ${token}`);
|
|
329
|
-
}
|
|
330
|
-
const factor = 10 ** decimals;
|
|
331
|
-
const result = amount * factor;
|
|
332
|
-
if (!Number.isInteger(result)) {
|
|
333
|
-
throw new Error(`The resulting amount is not a whole number: ${result}`);
|
|
334
|
-
}
|
|
335
|
-
return result;
|
|
336
|
-
};
|
|
541
|
+
// src/commands/pay/validate.ts
|
|
337
542
|
var validatePaymentPayload = (payload) => {
|
|
338
543
|
if (payload.tokens.some(
|
|
339
544
|
(token) => token.symbol == "USDCE" /* USDC */ && parseFloat(token.token_amount) < 0.1
|
|
@@ -351,175 +556,204 @@ var validatePaymentPayload = (payload) => {
|
|
|
351
556
|
return true;
|
|
352
557
|
};
|
|
353
558
|
|
|
354
|
-
// commands/pay.ts
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
var PaymentErrorMessage = {
|
|
367
|
-
["input_error" /* InputError */]: "There was a problem with this request. Please try again or contact the app owner.",
|
|
368
|
-
["user_rejected" /* UserRejected */]: "You have cancelled the payment in World App.",
|
|
369
|
-
["payment_rejected" /* PaymentRejected */]: "You've cancelled the payment in World App.",
|
|
370
|
-
["invalid_receiver" /* InvalidReceiver */]: "The receiver address is invalid. Please contact the app owner.",
|
|
371
|
-
["insufficient_balance" /* InsufficientBalance */]: "You do not have enough balance to complete this transaction.",
|
|
372
|
-
["transaction_failed" /* TransactionFailed */]: "The transaction failed. Please try again.",
|
|
373
|
-
["generic_error" /* GenericError */]: "Something unexpected went wrong. Please try again.",
|
|
374
|
-
["user_blocked" /* UserBlocked */]: "User's region is blocked from making payments."
|
|
375
|
-
};
|
|
376
|
-
function createPayCommand(_ctx) {
|
|
377
|
-
return (payload) => {
|
|
378
|
-
if (typeof window === "undefined" || !isCommandAvailable("pay" /* Pay */)) {
|
|
379
|
-
console.error(
|
|
380
|
-
"'pay' command is unavailable. Check MiniKit.install() or update the app version"
|
|
381
|
-
);
|
|
382
|
-
return null;
|
|
383
|
-
}
|
|
384
|
-
if (!validatePaymentPayload(payload)) {
|
|
385
|
-
return null;
|
|
386
|
-
}
|
|
387
|
-
const eventPayload = {
|
|
388
|
-
...payload,
|
|
389
|
-
network: "worldchain" /* WorldChain */
|
|
390
|
-
};
|
|
391
|
-
sendMiniKitEvent({
|
|
392
|
-
command: "pay" /* Pay */,
|
|
393
|
-
version: COMMAND_VERSIONS["pay" /* Pay */],
|
|
394
|
-
payload: eventPayload
|
|
395
|
-
});
|
|
396
|
-
return eventPayload;
|
|
397
|
-
};
|
|
559
|
+
// src/commands/pay/index.ts
|
|
560
|
+
async function pay(options, ctx) {
|
|
561
|
+
const result = await executeWithFallback({
|
|
562
|
+
command: "pay" /* Pay */,
|
|
563
|
+
nativeExecutor: () => nativePay(options, ctx),
|
|
564
|
+
// No Wagmi fallback - pay is native only
|
|
565
|
+
customFallback: options.fallback
|
|
566
|
+
});
|
|
567
|
+
if (result.executedWith === "fallback") {
|
|
568
|
+
return { executedWith: "fallback", data: result.data };
|
|
569
|
+
}
|
|
570
|
+
return { executedWith: "minikit", data: result.data };
|
|
398
571
|
}
|
|
399
|
-
function
|
|
400
|
-
|
|
401
|
-
|
|
572
|
+
async function nativePay(options, ctx) {
|
|
573
|
+
if (!ctx) {
|
|
574
|
+
ctx = { events: new EventManager(), state: { deviceProperties: {} } };
|
|
575
|
+
}
|
|
576
|
+
if (typeof window === "undefined" || !isCommandAvailable("pay" /* Pay */)) {
|
|
577
|
+
throw new Error(
|
|
578
|
+
"'pay' command is unavailable. Check MiniKit.install() or update the app version"
|
|
579
|
+
);
|
|
580
|
+
}
|
|
581
|
+
const input = {
|
|
582
|
+
reference: options.reference,
|
|
583
|
+
to: options.to,
|
|
584
|
+
tokens: options.tokens,
|
|
585
|
+
description: options.description,
|
|
586
|
+
network: options.network
|
|
587
|
+
};
|
|
588
|
+
if (!validatePaymentPayload(input)) {
|
|
589
|
+
throw new Error("Invalid payment payload");
|
|
590
|
+
}
|
|
591
|
+
const eventPayload = {
|
|
592
|
+
...input,
|
|
593
|
+
network: "worldchain" /* WorldChain */
|
|
594
|
+
};
|
|
595
|
+
const finalPayload = await new Promise(
|
|
596
|
+
(resolve, reject) => {
|
|
402
597
|
try {
|
|
403
|
-
|
|
404
|
-
const handleResponse = (response) => {
|
|
598
|
+
ctx.events.subscribe("miniapp-payment" /* MiniAppPayment */, (response) => {
|
|
405
599
|
ctx.events.unsubscribe("miniapp-payment" /* MiniAppPayment */);
|
|
406
|
-
resolve(
|
|
407
|
-
};
|
|
408
|
-
|
|
409
|
-
"
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
600
|
+
resolve(response);
|
|
601
|
+
});
|
|
602
|
+
sendMiniKitEvent({
|
|
603
|
+
command: "pay" /* Pay */,
|
|
604
|
+
version: COMMAND_VERSIONS["pay" /* Pay */],
|
|
605
|
+
payload: eventPayload
|
|
606
|
+
});
|
|
413
607
|
} catch (error) {
|
|
414
608
|
reject(error);
|
|
415
609
|
}
|
|
416
|
-
}
|
|
610
|
+
}
|
|
611
|
+
);
|
|
612
|
+
if (finalPayload.status === "error") {
|
|
613
|
+
throw new PayError(finalPayload.error_code);
|
|
614
|
+
}
|
|
615
|
+
return {
|
|
616
|
+
transactionId: finalPayload.transaction_id,
|
|
617
|
+
reference: finalPayload.reference,
|
|
618
|
+
from: finalPayload.from,
|
|
619
|
+
chain: finalPayload.chain,
|
|
620
|
+
timestamp: finalPayload.timestamp
|
|
417
621
|
};
|
|
418
622
|
}
|
|
419
623
|
|
|
420
|
-
// commands/request-permission.ts
|
|
421
|
-
var
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
RequestPermissionErrorCodes2["UnsupportedPermission"] = "unsupported_permission";
|
|
428
|
-
return RequestPermissionErrorCodes2;
|
|
429
|
-
})(RequestPermissionErrorCodes || {});
|
|
430
|
-
var RequestPermissionErrorMessage = {
|
|
431
|
-
["user_rejected" /* UserRejected */]: "User declined sharing contacts",
|
|
432
|
-
["generic_error" /* GenericError */]: "Request failed for unknown reason.",
|
|
433
|
-
["already_requested" /* AlreadyRequested */]: "User has already declined turning on notifications once",
|
|
434
|
-
["permission_disabled" /* PermissionDisabled */]: "User does not have this permission enabled in World App",
|
|
435
|
-
["already_granted" /* AlreadyGranted */]: "If the user has already granted this mini app permission",
|
|
436
|
-
["unsupported_permission" /* UnsupportedPermission */]: "The permission requested is not supported by this mini app"
|
|
624
|
+
// src/commands/request-permission/types.ts
|
|
625
|
+
var RequestPermissionError = class extends Error {
|
|
626
|
+
constructor(error_code) {
|
|
627
|
+
super(`Request permission failed: ${error_code}`);
|
|
628
|
+
this.error_code = error_code;
|
|
629
|
+
this.name = "RequestPermissionError";
|
|
630
|
+
}
|
|
437
631
|
};
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
632
|
+
|
|
633
|
+
// src/commands/request-permission/index.ts
|
|
634
|
+
async function requestPermission(options, ctx) {
|
|
635
|
+
const result = await executeWithFallback({
|
|
636
|
+
command: "request-permission" /* RequestPermission */,
|
|
637
|
+
nativeExecutor: () => nativeRequestPermission(options, ctx),
|
|
638
|
+
customFallback: options.fallback
|
|
639
|
+
});
|
|
640
|
+
if (result.executedWith === "fallback") {
|
|
641
|
+
return { executedWith: "fallback", data: result.data };
|
|
642
|
+
}
|
|
643
|
+
return {
|
|
644
|
+
executedWith: "minikit",
|
|
645
|
+
data: result.data
|
|
452
646
|
};
|
|
453
647
|
}
|
|
454
|
-
function
|
|
455
|
-
|
|
456
|
-
|
|
648
|
+
async function nativeRequestPermission(options, ctx) {
|
|
649
|
+
if (!ctx) {
|
|
650
|
+
ctx = { events: new EventManager(), state: { deviceProperties: {} } };
|
|
651
|
+
}
|
|
652
|
+
if (typeof window === "undefined" || !isCommandAvailable("request-permission" /* RequestPermission */)) {
|
|
653
|
+
throw new Error(
|
|
654
|
+
"'requestPermission' command is unavailable. Check MiniKit.install() or update the app version"
|
|
655
|
+
);
|
|
656
|
+
}
|
|
657
|
+
const payload = await new Promise(
|
|
658
|
+
(resolve, reject) => {
|
|
457
659
|
try {
|
|
458
|
-
|
|
459
|
-
const handleResponse = (response) => {
|
|
660
|
+
ctx.events.subscribe("miniapp-request-permission" /* MiniAppRequestPermission */, (response) => {
|
|
460
661
|
ctx.events.unsubscribe("miniapp-request-permission" /* MiniAppRequestPermission */);
|
|
461
|
-
resolve(
|
|
462
|
-
};
|
|
463
|
-
|
|
464
|
-
"
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
662
|
+
resolve(response);
|
|
663
|
+
});
|
|
664
|
+
sendMiniKitEvent({
|
|
665
|
+
command: "request-permission" /* RequestPermission */,
|
|
666
|
+
version: COMMAND_VERSIONS["request-permission" /* RequestPermission */],
|
|
667
|
+
payload: { permission: options.permission }
|
|
668
|
+
});
|
|
468
669
|
} catch (error) {
|
|
469
670
|
reject(error);
|
|
470
671
|
}
|
|
471
|
-
}
|
|
472
|
-
|
|
672
|
+
}
|
|
673
|
+
);
|
|
674
|
+
if (payload.status === "error") {
|
|
675
|
+
throw new RequestPermissionError(payload.error_code);
|
|
676
|
+
}
|
|
677
|
+
return payload;
|
|
473
678
|
}
|
|
474
679
|
|
|
475
|
-
// commands/send-haptic-feedback.ts
|
|
476
|
-
var
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
["generic_error" /* GenericError */]: "Something unexpected went wrong.",
|
|
483
|
-
["user_rejected" /* UserRejected */]: "User rejected the request."
|
|
680
|
+
// src/commands/send-haptic-feedback/types.ts
|
|
681
|
+
var SendHapticFeedbackError = class extends Error {
|
|
682
|
+
constructor(error_code) {
|
|
683
|
+
super(`Send haptic feedback failed: ${error_code}`);
|
|
684
|
+
this.error_code = error_code;
|
|
685
|
+
this.name = "SendHapticFeedbackError";
|
|
686
|
+
}
|
|
484
687
|
};
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
};
|
|
500
|
-
}
|
|
501
|
-
function
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
688
|
+
|
|
689
|
+
// src/commands/send-haptic-feedback/index.ts
|
|
690
|
+
async function sendHapticFeedback(options, ctx) {
|
|
691
|
+
const result = await executeWithFallback({
|
|
692
|
+
command: "send-haptic-feedback" /* SendHapticFeedback */,
|
|
693
|
+
nativeExecutor: () => nativeSendHapticFeedback(options, ctx),
|
|
694
|
+
customFallback: options.fallback
|
|
695
|
+
});
|
|
696
|
+
if (result.executedWith === "fallback") {
|
|
697
|
+
return { executedWith: "fallback", data: result.data };
|
|
698
|
+
}
|
|
699
|
+
return {
|
|
700
|
+
executedWith: "minikit",
|
|
701
|
+
data: result.data
|
|
702
|
+
};
|
|
703
|
+
}
|
|
704
|
+
async function nativeSendHapticFeedback(options, ctx) {
|
|
705
|
+
if (!ctx) {
|
|
706
|
+
ctx = { events: new EventManager(), state: { deviceProperties: {} } };
|
|
707
|
+
}
|
|
708
|
+
if (typeof window === "undefined" || !isCommandAvailable("send-haptic-feedback" /* SendHapticFeedback */)) {
|
|
709
|
+
throw new Error(
|
|
710
|
+
"'sendHapticFeedback' command is unavailable. Check MiniKit.install() or update the app version"
|
|
711
|
+
);
|
|
712
|
+
}
|
|
713
|
+
const payloadInput = options.hapticsType === "selection-changed" ? { hapticsType: "selection-changed" } : options.hapticsType === "impact" ? {
|
|
714
|
+
hapticsType: "impact",
|
|
715
|
+
style: options.style
|
|
716
|
+
} : {
|
|
717
|
+
hapticsType: "notification",
|
|
718
|
+
style: options.style
|
|
719
|
+
};
|
|
720
|
+
const payload = await new Promise(
|
|
721
|
+
(resolve, reject) => {
|
|
722
|
+
try {
|
|
723
|
+
ctx.events.subscribe("miniapp-send-haptic-feedback" /* MiniAppSendHapticFeedback */, (response) => {
|
|
507
724
|
ctx.events.unsubscribe("miniapp-send-haptic-feedback" /* MiniAppSendHapticFeedback */);
|
|
508
|
-
resolve(
|
|
509
|
-
};
|
|
510
|
-
|
|
511
|
-
"
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
725
|
+
resolve(response);
|
|
726
|
+
});
|
|
727
|
+
sendMiniKitEvent({
|
|
728
|
+
command: "send-haptic-feedback" /* SendHapticFeedback */,
|
|
729
|
+
version: COMMAND_VERSIONS["send-haptic-feedback" /* SendHapticFeedback */],
|
|
730
|
+
payload: payloadInput
|
|
731
|
+
});
|
|
515
732
|
} catch (error) {
|
|
516
733
|
reject(error);
|
|
517
734
|
}
|
|
518
|
-
}
|
|
519
|
-
|
|
735
|
+
}
|
|
736
|
+
);
|
|
737
|
+
if (payload.status === "error") {
|
|
738
|
+
throw new SendHapticFeedbackError(payload.error_code);
|
|
739
|
+
}
|
|
740
|
+
return payload;
|
|
520
741
|
}
|
|
521
742
|
|
|
522
|
-
//
|
|
743
|
+
// src/commands/send-transaction/index.ts
|
|
744
|
+
var import_viem = require("viem");
|
|
745
|
+
|
|
746
|
+
// src/commands/send-transaction/types.ts
|
|
747
|
+
var SendTransactionError = class extends Error {
|
|
748
|
+
constructor(code, details) {
|
|
749
|
+
super(`Transaction failed: ${code}`);
|
|
750
|
+
this.name = "SendTransactionError";
|
|
751
|
+
this.code = code;
|
|
752
|
+
this.details = details;
|
|
753
|
+
}
|
|
754
|
+
};
|
|
755
|
+
|
|
756
|
+
// src/commands/send-transaction/validate.ts
|
|
523
757
|
var isValidHex = (str) => {
|
|
524
758
|
return /^0x[0-9A-Fa-f]+$/.test(str);
|
|
525
759
|
};
|
|
@@ -572,89 +806,160 @@ var validateSendTransactionPayload = (payload) => {
|
|
|
572
806
|
if (payload.formatPayload) {
|
|
573
807
|
const formattedPayload = processPayload(payload);
|
|
574
808
|
formattedPayload.transaction = formattedPayload.transaction.map((tx) => {
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
809
|
+
if ("args" in tx && tx.args !== void 0) {
|
|
810
|
+
const args = objectValuesToArrayRecursive(tx.args);
|
|
811
|
+
return {
|
|
812
|
+
...tx,
|
|
813
|
+
args
|
|
814
|
+
};
|
|
815
|
+
}
|
|
816
|
+
return tx;
|
|
580
817
|
});
|
|
581
818
|
return formattedPayload;
|
|
582
819
|
}
|
|
583
820
|
return payload;
|
|
584
821
|
};
|
|
585
822
|
|
|
586
|
-
// commands/send-transaction.ts
|
|
587
|
-
var
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
SendTransactionErrorCodes2["DisallowedOperation"] = "disallowed_operation";
|
|
595
|
-
SendTransactionErrorCodes2["ValidationError"] = "validation_error";
|
|
596
|
-
SendTransactionErrorCodes2["InvalidContract"] = "invalid_contract";
|
|
597
|
-
SendTransactionErrorCodes2["MaliciousOperation"] = "malicious_operation";
|
|
598
|
-
SendTransactionErrorCodes2["DailyTxLimitReached"] = "daily_tx_limit_reached";
|
|
599
|
-
SendTransactionErrorCodes2["PermittedAmountExceedsSlippage"] = "permitted_amount_exceeds_slippage";
|
|
600
|
-
SendTransactionErrorCodes2["PermittedAmountNotFound"] = "permitted_amount_not_found";
|
|
601
|
-
return SendTransactionErrorCodes2;
|
|
602
|
-
})(SendTransactionErrorCodes || {});
|
|
603
|
-
var SendTransactionErrorMessage = {
|
|
604
|
-
["invalid_operation" /* InvalidOperation */]: "Transaction included an operation that was invalid",
|
|
605
|
-
["user_rejected" /* UserRejected */]: "User rejected the request.",
|
|
606
|
-
["input_error" /* InputError */]: "Invalid payload.",
|
|
607
|
-
["simulation_failed" /* SimulationFailed */]: "The transaction simulation failed.",
|
|
608
|
-
["validation_error" /* ValidationError */]: "The transaction validation failed. Please try again.",
|
|
609
|
-
["transaction_failed" /* TransactionFailed */]: "The transaction failed. Please try again later.",
|
|
610
|
-
["generic_error" /* GenericError */]: "Something unexpected went wrong. Please try again.",
|
|
611
|
-
["disallowed_operation" /* DisallowedOperation */]: "The operation requested is not allowed. Please refer to the docs.",
|
|
612
|
-
["invalid_contract" /* InvalidContract */]: "The contract address is not allowed for your application. Please check your developer portal configurations",
|
|
613
|
-
["malicious_operation" /* MaliciousOperation */]: "The operation requested is considered malicious.",
|
|
614
|
-
["daily_tx_limit_reached" /* DailyTxLimitReached */]: "Daily transaction limit reached. Max 100 transactions per day. Wait until the next day.",
|
|
615
|
-
["permitted_amount_exceeds_slippage" /* PermittedAmountExceedsSlippage */]: "Permitted amount exceeds slippage. You must spend at least 90% of the permitted amount.",
|
|
616
|
-
["permitted_amount_not_found" /* PermittedAmountNotFound */]: "Permitted amount not found in permit2 payload."
|
|
617
|
-
};
|
|
618
|
-
function createSendTransactionCommand(_ctx) {
|
|
619
|
-
return (payload) => {
|
|
620
|
-
if (typeof window === "undefined" || !isCommandAvailable("send-transaction" /* SendTransaction */)) {
|
|
621
|
-
console.error(
|
|
622
|
-
"'sendTransaction' command is unavailable. Check MiniKit.install() or update the app version"
|
|
623
|
-
);
|
|
624
|
-
return null;
|
|
625
|
-
}
|
|
626
|
-
payload.formatPayload = payload.formatPayload !== false;
|
|
627
|
-
const validatedPayload = validateSendTransactionPayload(payload);
|
|
628
|
-
sendMiniKitEvent({
|
|
629
|
-
command: "send-transaction" /* SendTransaction */,
|
|
630
|
-
version: COMMAND_VERSIONS["send-transaction" /* SendTransaction */],
|
|
631
|
-
payload: validatedPayload
|
|
823
|
+
// src/commands/send-transaction/index.ts
|
|
824
|
+
var WORLD_CHAIN_ID = 480;
|
|
825
|
+
var WAGMI_MULTI_TX_ERROR_MESSAGE = "Wagmi fallback does not support multi-transaction execution. Pass a single transaction, run inside World App for batching, or provide a custom fallback.";
|
|
826
|
+
async function sendTransaction(options, ctx) {
|
|
827
|
+
const isWagmiFallbackPath = !isInWorldApp() && hasWagmiConfig();
|
|
828
|
+
if (isWagmiFallbackPath && options.transaction.length > 1 && !options.fallback) {
|
|
829
|
+
throw new SendTransactionError("invalid_operation" /* InvalidOperation */, {
|
|
830
|
+
reason: WAGMI_MULTI_TX_ERROR_MESSAGE
|
|
632
831
|
});
|
|
633
|
-
|
|
832
|
+
}
|
|
833
|
+
const result = await executeWithFallback({
|
|
834
|
+
command: "send-transaction" /* SendTransaction */,
|
|
835
|
+
nativeExecutor: () => nativeSendTransaction(options, ctx),
|
|
836
|
+
wagmiFallback: () => wagmiSendTransactionAdapter(options),
|
|
837
|
+
customFallback: options.fallback
|
|
838
|
+
});
|
|
839
|
+
if (result.executedWith === "fallback") {
|
|
840
|
+
return { executedWith: "fallback", data: result.data };
|
|
841
|
+
}
|
|
842
|
+
if (result.executedWith === "wagmi") {
|
|
843
|
+
return {
|
|
844
|
+
executedWith: "wagmi",
|
|
845
|
+
data: result.data
|
|
846
|
+
};
|
|
847
|
+
}
|
|
848
|
+
return {
|
|
849
|
+
executedWith: "minikit",
|
|
850
|
+
data: result.data
|
|
634
851
|
};
|
|
635
852
|
}
|
|
636
|
-
function
|
|
637
|
-
|
|
638
|
-
|
|
853
|
+
async function nativeSendTransaction(options, ctx) {
|
|
854
|
+
if (!ctx) {
|
|
855
|
+
ctx = { events: new EventManager(), state: { deviceProperties: {} } };
|
|
856
|
+
}
|
|
857
|
+
if (typeof window === "undefined" || !isCommandAvailable("send-transaction" /* SendTransaction */)) {
|
|
858
|
+
throw new Error(
|
|
859
|
+
"'sendTransaction' command is unavailable. Check MiniKit.install() or update the app version"
|
|
860
|
+
);
|
|
861
|
+
}
|
|
862
|
+
if (options.chainId !== void 0 && options.chainId !== WORLD_CHAIN_ID) {
|
|
863
|
+
throw new Error(
|
|
864
|
+
`World App only supports World Chain (chainId: ${WORLD_CHAIN_ID})`
|
|
865
|
+
);
|
|
866
|
+
}
|
|
867
|
+
const input = {
|
|
868
|
+
transaction: options.transaction,
|
|
869
|
+
permit2: options.permit2,
|
|
870
|
+
formatPayload: options.formatPayload !== false
|
|
871
|
+
};
|
|
872
|
+
const validatedPayload = validateSendTransactionPayload(input);
|
|
873
|
+
const finalPayload = await new Promise(
|
|
874
|
+
(resolve, reject) => {
|
|
639
875
|
try {
|
|
640
|
-
|
|
641
|
-
const handleResponse = (response) => {
|
|
876
|
+
ctx.events.subscribe("miniapp-send-transaction" /* MiniAppSendTransaction */, (response) => {
|
|
642
877
|
ctx.events.unsubscribe("miniapp-send-transaction" /* MiniAppSendTransaction */);
|
|
643
|
-
resolve(
|
|
644
|
-
};
|
|
645
|
-
|
|
646
|
-
"
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
878
|
+
resolve(response);
|
|
879
|
+
});
|
|
880
|
+
sendMiniKitEvent({
|
|
881
|
+
command: "send-transaction" /* SendTransaction */,
|
|
882
|
+
version: COMMAND_VERSIONS["send-transaction" /* SendTransaction */],
|
|
883
|
+
payload: validatedPayload
|
|
884
|
+
});
|
|
650
885
|
} catch (error) {
|
|
651
886
|
reject(error);
|
|
652
887
|
}
|
|
653
|
-
}
|
|
888
|
+
}
|
|
889
|
+
);
|
|
890
|
+
if (finalPayload.status === "error") {
|
|
891
|
+
throw new SendTransactionError(
|
|
892
|
+
finalPayload.error_code,
|
|
893
|
+
finalPayload.details
|
|
894
|
+
);
|
|
895
|
+
}
|
|
896
|
+
return {
|
|
897
|
+
transactionHash: null,
|
|
898
|
+
userOpHash: finalPayload.userOpHash ?? null,
|
|
899
|
+
mini_app_id: finalPayload.mini_app_id ?? null,
|
|
900
|
+
status: finalPayload.status,
|
|
901
|
+
version: finalPayload.version,
|
|
902
|
+
transactionId: finalPayload.transaction_id,
|
|
903
|
+
reference: finalPayload.reference,
|
|
904
|
+
from: finalPayload.from,
|
|
905
|
+
chain: finalPayload.chain,
|
|
906
|
+
timestamp: finalPayload.timestamp,
|
|
907
|
+
// Deprecated aliases
|
|
908
|
+
transaction_id: finalPayload.transaction_id,
|
|
909
|
+
transaction_status: "submitted"
|
|
910
|
+
};
|
|
911
|
+
}
|
|
912
|
+
async function wagmiSendTransactionAdapter(options) {
|
|
913
|
+
if (options.transaction.length > 1) {
|
|
914
|
+
throw new Error(WAGMI_MULTI_TX_ERROR_MESSAGE);
|
|
915
|
+
}
|
|
916
|
+
if (options.permit2 && options.permit2.length > 0) {
|
|
917
|
+
console.warn(
|
|
918
|
+
"Permit2 signature is not automatically supported via Wagmi fallback. Transactions will execute without permit2."
|
|
919
|
+
);
|
|
920
|
+
}
|
|
921
|
+
const transactions = options.transaction.map((tx) => ({
|
|
922
|
+
address: tx.address,
|
|
923
|
+
// Encode the function call data
|
|
924
|
+
data: encodeTransactionData(tx),
|
|
925
|
+
value: tx.value
|
|
926
|
+
}));
|
|
927
|
+
const firstTransaction = transactions[0];
|
|
928
|
+
if (!firstTransaction) {
|
|
929
|
+
throw new Error("At least one transaction is required");
|
|
930
|
+
}
|
|
931
|
+
const result = await wagmiSendTransaction({
|
|
932
|
+
transaction: firstTransaction,
|
|
933
|
+
chainId: options.chainId
|
|
934
|
+
});
|
|
935
|
+
return {
|
|
936
|
+
transactionHash: result.transactionHash,
|
|
937
|
+
userOpHash: null,
|
|
938
|
+
mini_app_id: null,
|
|
939
|
+
status: "success",
|
|
940
|
+
version: 1,
|
|
941
|
+
transactionId: null,
|
|
942
|
+
reference: null,
|
|
943
|
+
from: null,
|
|
944
|
+
chain: null,
|
|
945
|
+
timestamp: null
|
|
654
946
|
};
|
|
655
947
|
}
|
|
948
|
+
function encodeTransactionData(tx) {
|
|
949
|
+
if (tx.data) {
|
|
950
|
+
return tx.data;
|
|
951
|
+
}
|
|
952
|
+
if (!tx.abi || !tx.functionName) {
|
|
953
|
+
throw new Error("Transaction requires `data` or `abi` + `functionName`.");
|
|
954
|
+
}
|
|
955
|
+
return (0, import_viem.encodeFunctionData)({
|
|
956
|
+
abi: tx.abi,
|
|
957
|
+
functionName: tx.functionName,
|
|
958
|
+
args: tx.args ?? []
|
|
959
|
+
});
|
|
960
|
+
}
|
|
656
961
|
|
|
657
|
-
//
|
|
962
|
+
// src/commands/share/format.ts
|
|
658
963
|
var MAX_FILES = 10;
|
|
659
964
|
var MAX_TOTAL_SIZE_MB = 50;
|
|
660
965
|
var MAX_TOTAL_SIZE_BYTES = MAX_TOTAL_SIZE_MB * 1024 * 1024;
|
|
@@ -720,388 +1025,290 @@ var formatShareInput = async (input) => {
|
|
|
720
1025
|
};
|
|
721
1026
|
};
|
|
722
1027
|
|
|
723
|
-
// commands/share.ts
|
|
724
|
-
var
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
}
|
|
730
|
-
var ShareFilesErrorMessage = {
|
|
731
|
-
["user_rejected" /* UserRejected */]: "User rejected the request.",
|
|
732
|
-
["generic_error" /* GenericError */]: "Something unexpected went wrong.",
|
|
733
|
-
["invalid_file_name" /* InvalidFileName */]: "Invalid file name. Make sure you include the extension"
|
|
1028
|
+
// src/commands/share/types.ts
|
|
1029
|
+
var ShareError = class extends Error {
|
|
1030
|
+
constructor(error_code) {
|
|
1031
|
+
super(`Share failed: ${error_code}`);
|
|
1032
|
+
this.error_code = error_code;
|
|
1033
|
+
this.name = "ShareError";
|
|
1034
|
+
}
|
|
734
1035
|
};
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
1036
|
+
|
|
1037
|
+
// src/commands/share/index.ts
|
|
1038
|
+
async function share(options, ctx) {
|
|
1039
|
+
const result = await executeWithFallback({
|
|
1040
|
+
command: "share" /* Share */,
|
|
1041
|
+
nativeExecutor: () => nativeShare(options, ctx),
|
|
1042
|
+
customFallback: options.fallback
|
|
1043
|
+
});
|
|
1044
|
+
if (result.executedWith === "fallback") {
|
|
1045
|
+
return {
|
|
1046
|
+
executedWith: "fallback",
|
|
1047
|
+
data: result.data
|
|
1048
|
+
};
|
|
1049
|
+
}
|
|
1050
|
+
return {
|
|
1051
|
+
executedWith: "minikit",
|
|
1052
|
+
data: result.data
|
|
1053
|
+
};
|
|
1054
|
+
}
|
|
1055
|
+
async function nativeShare(options, ctx) {
|
|
1056
|
+
if (!ctx) {
|
|
1057
|
+
ctx = { events: new EventManager(), state: { deviceProperties: {} } };
|
|
1058
|
+
}
|
|
1059
|
+
if (typeof window === "undefined" || !isCommandAvailable("share" /* Share */)) {
|
|
1060
|
+
throw new Error(
|
|
1061
|
+
"'share' command is unavailable. Check MiniKit.install() or update the app version"
|
|
1062
|
+
);
|
|
1063
|
+
}
|
|
1064
|
+
const payloadInput = {
|
|
1065
|
+
files: options.files,
|
|
1066
|
+
title: options.title,
|
|
1067
|
+
text: options.text,
|
|
1068
|
+
url: options.url
|
|
1069
|
+
};
|
|
1070
|
+
if (ctx.state.deviceProperties.deviceOS === "ios" && typeof navigator !== "undefined") {
|
|
1071
|
+
sendMiniKitEvent({
|
|
1072
|
+
command: "share" /* Share */,
|
|
1073
|
+
version: COMMAND_VERSIONS["share" /* Share */],
|
|
1074
|
+
payload: payloadInput
|
|
1075
|
+
});
|
|
1076
|
+
await navigator.share(payloadInput);
|
|
1077
|
+
return {
|
|
1078
|
+
status: "success",
|
|
1079
|
+
version: COMMAND_VERSIONS["share" /* Share */],
|
|
1080
|
+
shared_files_count: payloadInput.files?.length ?? 0,
|
|
1081
|
+
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
1082
|
+
};
|
|
1083
|
+
}
|
|
1084
|
+
const formattedPayload = await formatShareInput(payloadInput);
|
|
1085
|
+
const payload = await new Promise((resolve, reject) => {
|
|
1086
|
+
try {
|
|
1087
|
+
ctx.events.subscribe("miniapp-share" /* MiniAppShare */, (response) => {
|
|
1088
|
+
ctx.events.unsubscribe("miniapp-share" /* MiniAppShare */);
|
|
1089
|
+
resolve(response);
|
|
1090
|
+
});
|
|
744
1091
|
sendMiniKitEvent({
|
|
745
1092
|
command: "share" /* Share */,
|
|
746
1093
|
version: COMMAND_VERSIONS["share" /* Share */],
|
|
747
|
-
payload
|
|
748
|
-
});
|
|
749
|
-
navigator.share(payload);
|
|
750
|
-
} else {
|
|
751
|
-
formatShareInput(payload).then((formattedResult) => {
|
|
752
|
-
sendMiniKitEvent({
|
|
753
|
-
command: "share" /* Share */,
|
|
754
|
-
version: COMMAND_VERSIONS["share" /* Share */],
|
|
755
|
-
payload: formattedResult
|
|
756
|
-
});
|
|
757
|
-
}).catch((error) => {
|
|
758
|
-
console.error("Failed to format share input", error);
|
|
759
|
-
});
|
|
760
|
-
ctx.events.subscribe("miniapp-share" /* MiniAppShare */, (response) => {
|
|
761
|
-
console.log("Share Response", response);
|
|
1094
|
+
payload: formattedPayload
|
|
762
1095
|
});
|
|
1096
|
+
} catch (error) {
|
|
1097
|
+
reject(error);
|
|
763
1098
|
}
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
return
|
|
769
|
-
return new Promise((resolve, reject) => {
|
|
770
|
-
try {
|
|
771
|
-
let commandPayload = null;
|
|
772
|
-
const handleResponse = (response) => {
|
|
773
|
-
ctx.events.unsubscribe("miniapp-share" /* MiniAppShare */);
|
|
774
|
-
resolve({ commandPayload, finalPayload: response });
|
|
775
|
-
};
|
|
776
|
-
ctx.events.subscribe("miniapp-share" /* MiniAppShare */, handleResponse);
|
|
777
|
-
commandPayload = syncCommand(payload);
|
|
778
|
-
} catch (error) {
|
|
779
|
-
reject(error);
|
|
780
|
-
}
|
|
781
|
-
});
|
|
782
|
-
};
|
|
1099
|
+
});
|
|
1100
|
+
if (payload.status === "error") {
|
|
1101
|
+
throw new ShareError(payload.error_code);
|
|
1102
|
+
}
|
|
1103
|
+
return payload;
|
|
783
1104
|
}
|
|
784
1105
|
|
|
785
|
-
// commands/share-contacts.ts
|
|
786
|
-
var
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
["user_rejected" /* UserRejected */]: "User rejected the request.",
|
|
793
|
-
["generic_error" /* GenericError */]: "Something unexpected went wrong."
|
|
1106
|
+
// src/commands/share-contacts/types.ts
|
|
1107
|
+
var ShareContactsError = class extends Error {
|
|
1108
|
+
constructor(code) {
|
|
1109
|
+
super(`Share contacts failed: ${code}`);
|
|
1110
|
+
this.name = "ShareContactsError";
|
|
1111
|
+
this.code = code;
|
|
1112
|
+
}
|
|
794
1113
|
};
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
};
|
|
1114
|
+
|
|
1115
|
+
// src/commands/share-contacts/index.ts
|
|
1116
|
+
async function shareContacts(options, ctx) {
|
|
1117
|
+
const resolvedOptions = options ?? {};
|
|
1118
|
+
const result = await executeWithFallback({
|
|
1119
|
+
command: "share-contacts" /* ShareContacts */,
|
|
1120
|
+
nativeExecutor: () => nativeShareContacts(resolvedOptions, ctx),
|
|
1121
|
+
// No Wagmi fallback - contacts is native only
|
|
1122
|
+
customFallback: resolvedOptions.fallback
|
|
1123
|
+
});
|
|
1124
|
+
if (result.executedWith === "fallback") {
|
|
1125
|
+
return { executedWith: "fallback", data: result.data };
|
|
1126
|
+
}
|
|
1127
|
+
return { executedWith: "minikit", data: result.data };
|
|
810
1128
|
}
|
|
811
|
-
function
|
|
812
|
-
|
|
813
|
-
|
|
1129
|
+
async function nativeShareContacts(options, ctx) {
|
|
1130
|
+
if (!ctx) {
|
|
1131
|
+
ctx = { events: new EventManager(), state: { deviceProperties: {} } };
|
|
1132
|
+
}
|
|
1133
|
+
if (typeof window === "undefined" || !isCommandAvailable("share-contacts" /* ShareContacts */)) {
|
|
1134
|
+
throw new Error(
|
|
1135
|
+
"'shareContacts' command is unavailable. Check MiniKit.install() or update the app version"
|
|
1136
|
+
);
|
|
1137
|
+
}
|
|
1138
|
+
const payload = {
|
|
1139
|
+
isMultiSelectEnabled: options.isMultiSelectEnabled ?? false,
|
|
1140
|
+
inviteMessage: options.inviteMessage
|
|
1141
|
+
};
|
|
1142
|
+
const finalPayload = await new Promise(
|
|
1143
|
+
(resolve, reject) => {
|
|
814
1144
|
try {
|
|
815
|
-
|
|
816
|
-
const handleResponse = (response) => {
|
|
1145
|
+
ctx.events.subscribe("miniapp-share-contacts" /* MiniAppShareContacts */, (response) => {
|
|
817
1146
|
ctx.events.unsubscribe("miniapp-share-contacts" /* MiniAppShareContacts */);
|
|
818
|
-
resolve(
|
|
819
|
-
};
|
|
820
|
-
|
|
821
|
-
"
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
1147
|
+
resolve(response);
|
|
1148
|
+
});
|
|
1149
|
+
sendMiniKitEvent({
|
|
1150
|
+
command: "share-contacts" /* ShareContacts */,
|
|
1151
|
+
version: COMMAND_VERSIONS["share-contacts" /* ShareContacts */],
|
|
1152
|
+
payload
|
|
1153
|
+
});
|
|
825
1154
|
} catch (error) {
|
|
826
1155
|
reject(error);
|
|
827
1156
|
}
|
|
828
|
-
}
|
|
1157
|
+
}
|
|
1158
|
+
);
|
|
1159
|
+
if (finalPayload.status === "error") {
|
|
1160
|
+
throw new ShareContactsError(finalPayload.error_code);
|
|
1161
|
+
}
|
|
1162
|
+
return {
|
|
1163
|
+
contacts: finalPayload.contacts,
|
|
1164
|
+
timestamp: finalPayload.timestamp
|
|
829
1165
|
};
|
|
830
1166
|
}
|
|
831
1167
|
|
|
832
|
-
// commands/sign-message.ts
|
|
833
|
-
var
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
}
|
|
839
|
-
var SignMessageErrorMessage = {
|
|
840
|
-
["invalid_message" /* InvalidMessage */]: "Invalid message requested",
|
|
841
|
-
["user_rejected" /* UserRejected */]: "User rejected the request.",
|
|
842
|
-
["generic_error" /* GenericError */]: "Something unexpected went wrong."
|
|
1168
|
+
// src/commands/sign-message/types.ts
|
|
1169
|
+
var SignMessageError = class extends Error {
|
|
1170
|
+
constructor(error_code) {
|
|
1171
|
+
super(`Sign message failed: ${error_code}`);
|
|
1172
|
+
this.error_code = error_code;
|
|
1173
|
+
this.name = "SignMessageError";
|
|
1174
|
+
}
|
|
843
1175
|
};
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
}
|
|
857
|
-
|
|
1176
|
+
|
|
1177
|
+
// src/commands/sign-message/index.ts
|
|
1178
|
+
async function signMessage(options, ctx) {
|
|
1179
|
+
const result = await executeWithFallback({
|
|
1180
|
+
command: "sign-message" /* SignMessage */,
|
|
1181
|
+
nativeExecutor: () => nativeSignMessage(options, ctx),
|
|
1182
|
+
wagmiFallback: () => wagmiSignMessage({
|
|
1183
|
+
message: options.message
|
|
1184
|
+
}),
|
|
1185
|
+
customFallback: options.fallback
|
|
1186
|
+
});
|
|
1187
|
+
if (result.executedWith === "fallback") {
|
|
1188
|
+
return { executedWith: "fallback", data: result.data };
|
|
1189
|
+
}
|
|
1190
|
+
if (result.executedWith === "wagmi") {
|
|
1191
|
+
return {
|
|
1192
|
+
executedWith: "wagmi",
|
|
1193
|
+
data: result.data
|
|
1194
|
+
};
|
|
1195
|
+
}
|
|
1196
|
+
return {
|
|
1197
|
+
executedWith: "minikit",
|
|
1198
|
+
data: result.data
|
|
858
1199
|
};
|
|
859
1200
|
}
|
|
860
|
-
function
|
|
861
|
-
|
|
862
|
-
|
|
1201
|
+
async function nativeSignMessage(options, ctx) {
|
|
1202
|
+
if (!ctx) {
|
|
1203
|
+
ctx = { events: new EventManager(), state: { deviceProperties: {} } };
|
|
1204
|
+
}
|
|
1205
|
+
if (typeof window === "undefined" || !isCommandAvailable("sign-message" /* SignMessage */)) {
|
|
1206
|
+
throw new Error(
|
|
1207
|
+
"'signMessage' command is unavailable. Check MiniKit.install() or update the app version"
|
|
1208
|
+
);
|
|
1209
|
+
}
|
|
1210
|
+
const payload = await new Promise(
|
|
1211
|
+
(resolve, reject) => {
|
|
863
1212
|
try {
|
|
864
|
-
|
|
865
|
-
const handleResponse = (response) => {
|
|
1213
|
+
ctx.events.subscribe("miniapp-sign-message" /* MiniAppSignMessage */, (response) => {
|
|
866
1214
|
ctx.events.unsubscribe("miniapp-sign-message" /* MiniAppSignMessage */);
|
|
867
|
-
resolve(
|
|
868
|
-
};
|
|
869
|
-
|
|
870
|
-
"
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
1215
|
+
resolve(response);
|
|
1216
|
+
});
|
|
1217
|
+
sendMiniKitEvent({
|
|
1218
|
+
command: "sign-message" /* SignMessage */,
|
|
1219
|
+
version: COMMAND_VERSIONS["sign-message" /* SignMessage */],
|
|
1220
|
+
payload: { message: options.message }
|
|
1221
|
+
});
|
|
874
1222
|
} catch (error) {
|
|
875
1223
|
reject(error);
|
|
876
1224
|
}
|
|
877
|
-
}
|
|
878
|
-
|
|
1225
|
+
}
|
|
1226
|
+
);
|
|
1227
|
+
if (payload.status === "error") {
|
|
1228
|
+
throw new SignMessageError(payload.error_code);
|
|
1229
|
+
}
|
|
1230
|
+
return payload;
|
|
879
1231
|
}
|
|
880
1232
|
|
|
881
|
-
// commands/sign-typed-data.ts
|
|
882
|
-
var
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
SignTypedDataErrorCodes2["DisallowedOperation"] = "disallowed_operation";
|
|
889
|
-
SignTypedDataErrorCodes2["InvalidContract"] = "invalid_contract";
|
|
890
|
-
SignTypedDataErrorCodes2["MaliciousOperation"] = "malicious_operation";
|
|
891
|
-
return SignTypedDataErrorCodes2;
|
|
892
|
-
})(SignTypedDataErrorCodes || {});
|
|
893
|
-
var SignTypedDataErrorMessage = {
|
|
894
|
-
["invalid_operation" /* InvalidOperation */]: "Transaction included an operation that was invalid",
|
|
895
|
-
["user_rejected" /* UserRejected */]: "User rejected the request.",
|
|
896
|
-
["input_error" /* InputError */]: "Invalid payload.",
|
|
897
|
-
["simulation_failed" /* SimulationFailed */]: "The transaction simulation failed.",
|
|
898
|
-
["generic_error" /* GenericError */]: "Something unexpected went wrong. Please try again.",
|
|
899
|
-
["disallowed_operation" /* DisallowedOperation */]: "The operation requested is not allowed. Please refer to the docs.",
|
|
900
|
-
["invalid_contract" /* InvalidContract */]: "The contract address is not allowed for your application. Please check your developer portal configurations",
|
|
901
|
-
["malicious_operation" /* MaliciousOperation */]: "The operation requested is considered malicious."
|
|
1233
|
+
// src/commands/sign-typed-data/types.ts
|
|
1234
|
+
var SignTypedDataError = class extends Error {
|
|
1235
|
+
constructor(error_code) {
|
|
1236
|
+
super(`Sign typed data failed: ${error_code}`);
|
|
1237
|
+
this.error_code = error_code;
|
|
1238
|
+
this.name = "SignTypedDataError";
|
|
1239
|
+
}
|
|
902
1240
|
};
|
|
903
|
-
function createSignTypedDataCommand(_ctx) {
|
|
904
|
-
return (payload) => {
|
|
905
|
-
if (typeof window === "undefined" || !isCommandAvailable("sign-typed-data" /* SignTypedData */)) {
|
|
906
|
-
console.error(
|
|
907
|
-
"'signTypedData' command is unavailable. Check MiniKit.install() or update the app version"
|
|
908
|
-
);
|
|
909
|
-
return null;
|
|
910
|
-
}
|
|
911
|
-
if (!payload.chainId) {
|
|
912
|
-
payload.chainId = 480;
|
|
913
|
-
}
|
|
914
|
-
sendMiniKitEvent({
|
|
915
|
-
command: "sign-typed-data" /* SignTypedData */,
|
|
916
|
-
version: COMMAND_VERSIONS["sign-typed-data" /* SignTypedData */],
|
|
917
|
-
payload
|
|
918
|
-
});
|
|
919
|
-
return payload;
|
|
920
|
-
};
|
|
921
|
-
}
|
|
922
|
-
function createSignTypedDataAsyncCommand(ctx, syncCommand) {
|
|
923
|
-
return async (payload) => {
|
|
924
|
-
return new Promise((resolve, reject) => {
|
|
925
|
-
try {
|
|
926
|
-
let commandPayload = null;
|
|
927
|
-
const handleResponse = (response) => {
|
|
928
|
-
ctx.events.unsubscribe("miniapp-sign-typed-data" /* MiniAppSignTypedData */);
|
|
929
|
-
resolve({ commandPayload, finalPayload: response });
|
|
930
|
-
};
|
|
931
|
-
ctx.events.subscribe(
|
|
932
|
-
"miniapp-sign-typed-data" /* MiniAppSignTypedData */,
|
|
933
|
-
handleResponse
|
|
934
|
-
);
|
|
935
|
-
commandPayload = syncCommand(payload);
|
|
936
|
-
} catch (error) {
|
|
937
|
-
reject(error);
|
|
938
|
-
}
|
|
939
|
-
});
|
|
940
|
-
};
|
|
941
|
-
}
|
|
942
1241
|
|
|
943
|
-
// commands/
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
}
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
}
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
timestamp
|
|
1242
|
+
// src/commands/sign-typed-data/index.ts
|
|
1243
|
+
async function signTypedData(options, ctx) {
|
|
1244
|
+
const result = await executeWithFallback({
|
|
1245
|
+
command: "sign-typed-data" /* SignTypedData */,
|
|
1246
|
+
nativeExecutor: () => nativeSignTypedData(options, ctx),
|
|
1247
|
+
wagmiFallback: () => wagmiSignTypedData({
|
|
1248
|
+
types: options.types,
|
|
1249
|
+
primaryType: options.primaryType,
|
|
1250
|
+
message: options.message,
|
|
1251
|
+
domain: options.domain,
|
|
1252
|
+
chainId: options.chainId
|
|
1253
|
+
}),
|
|
1254
|
+
customFallback: options.fallback
|
|
1255
|
+
});
|
|
1256
|
+
if (result.executedWith === "fallback") {
|
|
1257
|
+
return { executedWith: "fallback", data: result.data };
|
|
1258
|
+
}
|
|
1259
|
+
if (result.executedWith === "wagmi") {
|
|
1260
|
+
return {
|
|
1261
|
+
executedWith: "wagmi",
|
|
1262
|
+
data: result.data
|
|
965
1263
|
};
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
});
|
|
971
|
-
return eventPayload;
|
|
1264
|
+
}
|
|
1265
|
+
return {
|
|
1266
|
+
executedWith: "minikit",
|
|
1267
|
+
data: result.data
|
|
972
1268
|
};
|
|
973
1269
|
}
|
|
974
|
-
function
|
|
975
|
-
|
|
976
|
-
|
|
1270
|
+
async function nativeSignTypedData(options, ctx) {
|
|
1271
|
+
if (!ctx) {
|
|
1272
|
+
ctx = { events: new EventManager(), state: { deviceProperties: {} } };
|
|
1273
|
+
}
|
|
1274
|
+
if (typeof window === "undefined" || !isCommandAvailable("sign-typed-data" /* SignTypedData */)) {
|
|
1275
|
+
throw new Error(
|
|
1276
|
+
"'signTypedData' command is unavailable. Check MiniKit.install() or update the app version"
|
|
1277
|
+
);
|
|
1278
|
+
}
|
|
1279
|
+
const payloadInput = {
|
|
1280
|
+
types: options.types,
|
|
1281
|
+
primaryType: options.primaryType,
|
|
1282
|
+
message: options.message,
|
|
1283
|
+
domain: options.domain,
|
|
1284
|
+
chainId: options.chainId ?? 480
|
|
1285
|
+
};
|
|
1286
|
+
const payload = await new Promise(
|
|
1287
|
+
(resolve, reject) => {
|
|
977
1288
|
try {
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
"
|
|
985
|
-
|
|
986
|
-
);
|
|
987
|
-
commandPayload = syncCommand(payload);
|
|
1289
|
+
ctx.events.subscribe("miniapp-sign-typed-data" /* MiniAppSignTypedData */, (response) => {
|
|
1290
|
+
ctx.events.unsubscribe("miniapp-sign-typed-data" /* MiniAppSignTypedData */);
|
|
1291
|
+
resolve(response);
|
|
1292
|
+
});
|
|
1293
|
+
sendMiniKitEvent({
|
|
1294
|
+
command: "sign-typed-data" /* SignTypedData */,
|
|
1295
|
+
version: COMMAND_VERSIONS["sign-typed-data" /* SignTypedData */],
|
|
1296
|
+
payload: payloadInput
|
|
1297
|
+
});
|
|
988
1298
|
} catch (error) {
|
|
989
1299
|
reject(error);
|
|
990
1300
|
}
|
|
991
|
-
}
|
|
992
|
-
|
|
1301
|
+
}
|
|
1302
|
+
);
|
|
1303
|
+
if (payload.status === "error") {
|
|
1304
|
+
throw new SignTypedDataError(payload.error_code);
|
|
1305
|
+
}
|
|
1306
|
+
return payload;
|
|
993
1307
|
}
|
|
994
1308
|
|
|
995
|
-
//
|
|
996
|
-
var
|
|
1309
|
+
// src/commands/wallet-auth/siwe.ts
|
|
1310
|
+
var import_viem2 = require("viem");
|
|
997
1311
|
var import_chains = require("viem/chains");
|
|
998
|
-
var PREAMBLE = " wants you to sign in with your Ethereum account:";
|
|
999
|
-
var URI_TAG = "URI: ";
|
|
1000
|
-
var VERSION_TAG = "Version: ";
|
|
1001
|
-
var CHAIN_TAG = "Chain ID: ";
|
|
1002
|
-
var NONCE_TAG = "Nonce: ";
|
|
1003
|
-
var IAT_TAG = "Issued At: ";
|
|
1004
|
-
var EXP_TAG = "Expiration Time: ";
|
|
1005
|
-
var NBF_TAG = "Not Before: ";
|
|
1006
|
-
var RID_TAG = "Request ID: ";
|
|
1007
|
-
var ERC_191_PREFIX = "Ethereum Signed Message:\n";
|
|
1008
|
-
var EIP1271_MAGICVALUE = "0x1626ba7e";
|
|
1009
|
-
var SAFE_CONTRACT_ABI = [
|
|
1010
|
-
{
|
|
1011
|
-
inputs: [
|
|
1012
|
-
{
|
|
1013
|
-
internalType: "address",
|
|
1014
|
-
name: "owner",
|
|
1015
|
-
type: "address"
|
|
1016
|
-
}
|
|
1017
|
-
],
|
|
1018
|
-
name: "isOwner",
|
|
1019
|
-
outputs: [
|
|
1020
|
-
{
|
|
1021
|
-
internalType: "bool",
|
|
1022
|
-
name: "",
|
|
1023
|
-
type: "bool"
|
|
1024
|
-
}
|
|
1025
|
-
],
|
|
1026
|
-
stateMutability: "view",
|
|
1027
|
-
type: "function"
|
|
1028
|
-
},
|
|
1029
|
-
{
|
|
1030
|
-
inputs: [
|
|
1031
|
-
{
|
|
1032
|
-
internalType: "bytes32",
|
|
1033
|
-
name: "_message",
|
|
1034
|
-
type: "bytes32"
|
|
1035
|
-
},
|
|
1036
|
-
{
|
|
1037
|
-
internalType: "bytes",
|
|
1038
|
-
name: "_signature",
|
|
1039
|
-
type: "bytes"
|
|
1040
|
-
}
|
|
1041
|
-
],
|
|
1042
|
-
name: "isValidSignature",
|
|
1043
|
-
outputs: [
|
|
1044
|
-
{
|
|
1045
|
-
internalType: "bytes4",
|
|
1046
|
-
name: "",
|
|
1047
|
-
type: "bytes4"
|
|
1048
|
-
}
|
|
1049
|
-
],
|
|
1050
|
-
stateMutability: "view",
|
|
1051
|
-
type: "function"
|
|
1052
|
-
}
|
|
1053
|
-
];
|
|
1054
|
-
var tagged = (line, tag) => {
|
|
1055
|
-
if (line && line.includes(tag)) {
|
|
1056
|
-
return line.replace(tag, "");
|
|
1057
|
-
} else {
|
|
1058
|
-
throw new Error(`Missing '${tag}'`);
|
|
1059
|
-
}
|
|
1060
|
-
};
|
|
1061
|
-
var parseSiweMessage = (inputString) => {
|
|
1062
|
-
const lines = inputString.split("\n")[Symbol.iterator]();
|
|
1063
|
-
const domain = tagged(lines.next()?.value, PREAMBLE);
|
|
1064
|
-
const address = lines.next()?.value;
|
|
1065
|
-
lines.next();
|
|
1066
|
-
const nextValue = lines.next()?.value;
|
|
1067
|
-
let statement;
|
|
1068
|
-
if (nextValue) {
|
|
1069
|
-
statement = nextValue;
|
|
1070
|
-
lines.next();
|
|
1071
|
-
}
|
|
1072
|
-
const uri = tagged(lines.next()?.value, URI_TAG);
|
|
1073
|
-
const version = tagged(lines.next()?.value, VERSION_TAG);
|
|
1074
|
-
const chain_id = tagged(lines.next()?.value, CHAIN_TAG);
|
|
1075
|
-
const nonce = tagged(lines.next()?.value, NONCE_TAG);
|
|
1076
|
-
const issued_at = tagged(lines.next()?.value, IAT_TAG);
|
|
1077
|
-
let expiration_time, not_before, request_id;
|
|
1078
|
-
for (let line of lines) {
|
|
1079
|
-
if (line.startsWith(EXP_TAG)) {
|
|
1080
|
-
expiration_time = tagged(line, EXP_TAG);
|
|
1081
|
-
} else if (line.startsWith(NBF_TAG)) {
|
|
1082
|
-
not_before = tagged(line, NBF_TAG);
|
|
1083
|
-
} else if (line.startsWith(RID_TAG)) {
|
|
1084
|
-
request_id = tagged(line, RID_TAG);
|
|
1085
|
-
}
|
|
1086
|
-
}
|
|
1087
|
-
if (lines.next().done === false) {
|
|
1088
|
-
throw new Error("Extra lines in the input");
|
|
1089
|
-
}
|
|
1090
|
-
const siweMessageData = {
|
|
1091
|
-
domain,
|
|
1092
|
-
address,
|
|
1093
|
-
statement,
|
|
1094
|
-
uri,
|
|
1095
|
-
version,
|
|
1096
|
-
chain_id,
|
|
1097
|
-
nonce,
|
|
1098
|
-
issued_at,
|
|
1099
|
-
expiration_time,
|
|
1100
|
-
not_before,
|
|
1101
|
-
request_id
|
|
1102
|
-
};
|
|
1103
|
-
return siweMessageData;
|
|
1104
|
-
};
|
|
1105
1312
|
var generateSiweMessage = (siweMessageData) => {
|
|
1106
1313
|
let siweMessage = "";
|
|
1107
1314
|
if (siweMessageData.scheme) {
|
|
@@ -1141,561 +1348,150 @@ var generateSiweMessage = (siweMessageData) => {
|
|
|
1141
1348
|
siweMessage += `Not Before: ${siweMessageData.not_before}
|
|
1142
1349
|
`;
|
|
1143
1350
|
}
|
|
1144
|
-
if (siweMessageData.request_id) {
|
|
1145
|
-
siweMessage += `Request ID: ${siweMessageData.request_id}
|
|
1146
|
-
`;
|
|
1147
|
-
}
|
|
1148
|
-
return siweMessage;
|
|
1149
|
-
};
|
|
1150
|
-
var verifySiweMessage = (payload, nonce, statement, requestId, userProvider) => {
|
|
1151
|
-
if (payload.version === 1) {
|
|
1152
|
-
return verifySiweMessageV1(
|
|
1153
|
-
payload,
|
|
1154
|
-
nonce,
|
|
1155
|
-
statement,
|
|
1156
|
-
requestId,
|
|
1157
|
-
userProvider
|
|
1158
|
-
);
|
|
1159
|
-
} else {
|
|
1160
|
-
return verifySiweMessageV2(
|
|
1161
|
-
payload,
|
|
1162
|
-
nonce,
|
|
1163
|
-
statement,
|
|
1164
|
-
requestId,
|
|
1165
|
-
userProvider
|
|
1166
|
-
);
|
|
1167
|
-
}
|
|
1168
|
-
};
|
|
1169
|
-
var validateMessage = (siweMessageData, nonce, statement, requestId) => {
|
|
1170
|
-
if (siweMessageData.expiration_time) {
|
|
1171
|
-
const expirationTime = new Date(siweMessageData.expiration_time);
|
|
1172
|
-
if (expirationTime < /* @__PURE__ */ new Date()) {
|
|
1173
|
-
throw new Error("Expired message");
|
|
1174
|
-
}
|
|
1175
|
-
}
|
|
1176
|
-
if (siweMessageData.not_before) {
|
|
1177
|
-
const notBefore = new Date(siweMessageData.not_before);
|
|
1178
|
-
if (notBefore > /* @__PURE__ */ new Date()) {
|
|
1179
|
-
throw new Error("Not Before time has not passed");
|
|
1180
|
-
}
|
|
1181
|
-
}
|
|
1182
|
-
if (nonce && siweMessageData.nonce !== nonce) {
|
|
1183
|
-
throw new Error(
|
|
1184
|
-
`Nonce mismatch. Got: ${siweMessageData.nonce}, Expected: ${nonce}`
|
|
1185
|
-
);
|
|
1186
|
-
}
|
|
1187
|
-
if (statement && siweMessageData.statement !== statement) {
|
|
1188
|
-
throw new Error(
|
|
1189
|
-
`Statement mismatch. Got: ${siweMessageData.statement}, Expected: ${statement}`
|
|
1190
|
-
);
|
|
1191
|
-
}
|
|
1192
|
-
if (requestId && siweMessageData.request_id !== requestId) {
|
|
1193
|
-
throw new Error(
|
|
1194
|
-
`Request ID mismatch. Got: ${siweMessageData.request_id}, Expected: ${requestId}`
|
|
1195
|
-
);
|
|
1196
|
-
}
|
|
1197
|
-
return true;
|
|
1198
|
-
};
|
|
1199
|
-
var verifySiweMessageV1 = async (payload, nonce, statement, requestId, userProvider) => {
|
|
1200
|
-
if (typeof window !== "undefined") {
|
|
1201
|
-
throw new Error("Wallet auth payload can only be verified in the backend");
|
|
1202
|
-
}
|
|
1203
|
-
const { message, signature, address } = payload;
|
|
1204
|
-
const siweMessageData = parseSiweMessage(message);
|
|
1205
|
-
validateMessage(siweMessageData, nonce, statement, requestId);
|
|
1206
|
-
let provider = userProvider || (0, import_viem.createPublicClient)({ chain: import_chains.worldchain, transport: (0, import_viem.http)() });
|
|
1207
|
-
const signedMessage = `${ERC_191_PREFIX}${message.length}${message}`;
|
|
1208
|
-
const hashedMessage = (0, import_viem.hashMessage)(signedMessage);
|
|
1209
|
-
const contract = (0, import_viem.getContract)({
|
|
1210
|
-
address,
|
|
1211
|
-
abi: SAFE_CONTRACT_ABI,
|
|
1212
|
-
client: provider
|
|
1213
|
-
});
|
|
1214
|
-
try {
|
|
1215
|
-
const recoveredAddress = await (0, import_viem.recoverAddress)({
|
|
1216
|
-
hash: hashedMessage,
|
|
1217
|
-
signature: `0x${signature}`
|
|
1218
|
-
});
|
|
1219
|
-
const isOwner = await contract.read.isOwner([recoveredAddress]);
|
|
1220
|
-
if (!isOwner) {
|
|
1221
|
-
throw new Error("Signature verification failed, invalid owner");
|
|
1222
|
-
}
|
|
1223
|
-
} catch (error) {
|
|
1224
|
-
throw new Error("Signature verification failed");
|
|
1225
|
-
}
|
|
1226
|
-
return { isValid: true, siweMessageData };
|
|
1227
|
-
};
|
|
1228
|
-
var verifySiweMessageV2 = async (payload, nonce, statement, requestId, userProvider) => {
|
|
1229
|
-
if (typeof window !== "undefined") {
|
|
1230
|
-
throw new Error("Wallet auth payload can only be verified in the backend");
|
|
1231
|
-
}
|
|
1232
|
-
const { message, signature, address } = payload;
|
|
1233
|
-
const siweMessageData = parseSiweMessage(message);
|
|
1234
|
-
if (!validateMessage(siweMessageData, nonce, statement, requestId)) {
|
|
1235
|
-
throw new Error("Validation failed");
|
|
1236
|
-
}
|
|
1237
|
-
try {
|
|
1238
|
-
const walletContract = (0, import_viem.getContract)({
|
|
1239
|
-
address,
|
|
1240
|
-
abi: SAFE_CONTRACT_ABI,
|
|
1241
|
-
client: userProvider || (0, import_viem.createPublicClient)({ chain: import_chains.worldchain, transport: (0, import_viem.http)() })
|
|
1242
|
-
});
|
|
1243
|
-
const hashedMessage = (0, import_viem.hashMessage)(message);
|
|
1244
|
-
const res = await walletContract.read.isValidSignature([
|
|
1245
|
-
hashedMessage,
|
|
1246
|
-
signature
|
|
1247
|
-
]);
|
|
1248
|
-
return {
|
|
1249
|
-
isValid: res === EIP1271_MAGICVALUE,
|
|
1250
|
-
siweMessageData
|
|
1251
|
-
};
|
|
1252
|
-
} catch (error) {
|
|
1253
|
-
console.log(error);
|
|
1254
|
-
throw new Error("Signature verification failed");
|
|
1255
|
-
}
|
|
1256
|
-
};
|
|
1257
|
-
|
|
1258
|
-
// helpers/siwe/validate-wallet-auth-command-input.ts
|
|
1259
|
-
var validateWalletAuthCommandInput = (params) => {
|
|
1260
|
-
if (!params.nonce) {
|
|
1261
|
-
return { valid: false, message: "'nonce' is required" };
|
|
1262
|
-
}
|
|
1263
|
-
if (params.nonce.length < 8) {
|
|
1264
|
-
return { valid: false, message: "'nonce' must be at least 8 characters" };
|
|
1265
|
-
}
|
|
1266
|
-
if (params.statement && params.statement.includes("\n")) {
|
|
1267
|
-
return { valid: false, message: "'statement' must not contain newlines" };
|
|
1268
|
-
}
|
|
1269
|
-
if (params.expirationTime && new Date(params.expirationTime) < /* @__PURE__ */ new Date()) {
|
|
1270
|
-
return { valid: false, message: "'expirationTime' must be in the future" };
|
|
1271
|
-
}
|
|
1272
|
-
if (params.expirationTime && new Date(params.expirationTime) > new Date(Date.now() + 7 * 24 * 60 * 60 * 1e3)) {
|
|
1273
|
-
return { valid: false, message: "'expirationTime' must be within 7 days" };
|
|
1274
|
-
}
|
|
1275
|
-
if (params.notBefore && new Date(params.notBefore) > new Date(Date.now() + 7 * 24 * 60 * 60 * 1e3)) {
|
|
1276
|
-
return { valid: false, message: "'notBefore' must be within 7 days" };
|
|
1277
|
-
}
|
|
1278
|
-
return { valid: true };
|
|
1279
|
-
};
|
|
1280
|
-
|
|
1281
|
-
// commands/wallet-auth.ts
|
|
1282
|
-
var WalletAuthErrorCodes = /* @__PURE__ */ ((WalletAuthErrorCodes2) => {
|
|
1283
|
-
WalletAuthErrorCodes2["MalformedRequest"] = "malformed_request";
|
|
1284
|
-
WalletAuthErrorCodes2["UserRejected"] = "user_rejected";
|
|
1285
|
-
WalletAuthErrorCodes2["GenericError"] = "generic_error";
|
|
1286
|
-
return WalletAuthErrorCodes2;
|
|
1287
|
-
})(WalletAuthErrorCodes || {});
|
|
1288
|
-
var WalletAuthErrorMessage = {
|
|
1289
|
-
["malformed_request" /* MalformedRequest */]: "Provided parameters in the request are invalid.",
|
|
1290
|
-
["user_rejected" /* UserRejected */]: "User rejected the request.",
|
|
1291
|
-
["generic_error" /* GenericError */]: "Something unexpected went wrong."
|
|
1292
|
-
};
|
|
1293
|
-
function createWalletAuthCommand(ctx) {
|
|
1294
|
-
return (payload) => {
|
|
1295
|
-
if (typeof window === "undefined" || !isCommandAvailable("wallet-auth" /* WalletAuth */)) {
|
|
1296
|
-
console.error(
|
|
1297
|
-
"'walletAuth' command is unavailable. Check MiniKit.install() or update the app version"
|
|
1298
|
-
);
|
|
1299
|
-
return null;
|
|
1300
|
-
}
|
|
1301
|
-
const validationResult = validateWalletAuthCommandInput(payload);
|
|
1302
|
-
if (!validationResult.valid) {
|
|
1303
|
-
console.error(
|
|
1304
|
-
"Failed to validate wallet auth input:\n\n -->",
|
|
1305
|
-
validationResult.message
|
|
1306
|
-
);
|
|
1307
|
-
return null;
|
|
1308
|
-
}
|
|
1309
|
-
let protocol = null;
|
|
1310
|
-
try {
|
|
1311
|
-
const currentUrl = new URL(window.location.href);
|
|
1312
|
-
protocol = currentUrl.protocol.split(":")[0];
|
|
1313
|
-
} catch (error) {
|
|
1314
|
-
console.error("Failed to get current URL", error);
|
|
1315
|
-
return null;
|
|
1316
|
-
}
|
|
1317
|
-
const siweMessage = generateSiweMessage({
|
|
1318
|
-
scheme: protocol,
|
|
1319
|
-
domain: window.location.host,
|
|
1320
|
-
statement: payload.statement ?? void 0,
|
|
1321
|
-
uri: window.location.href,
|
|
1322
|
-
version: "1",
|
|
1323
|
-
chain_id: 480,
|
|
1324
|
-
nonce: payload.nonce,
|
|
1325
|
-
issued_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1326
|
-
expiration_time: payload.expirationTime?.toISOString() ?? void 0,
|
|
1327
|
-
not_before: payload.notBefore?.toISOString() ?? void 0,
|
|
1328
|
-
request_id: payload.requestId ?? void 0
|
|
1329
|
-
});
|
|
1330
|
-
const walletAuthPayload = { siweMessage };
|
|
1331
|
-
const walletAuthVersion = ctx.state.user.worldAppVersion && ctx.state.user.worldAppVersion > 2087900 ? COMMAND_VERSIONS["wallet-auth" /* WalletAuth */] : 1;
|
|
1332
|
-
sendMiniKitEvent({
|
|
1333
|
-
command: "wallet-auth" /* WalletAuth */,
|
|
1334
|
-
version: walletAuthVersion,
|
|
1335
|
-
payload: walletAuthPayload
|
|
1336
|
-
});
|
|
1337
|
-
return walletAuthPayload;
|
|
1338
|
-
};
|
|
1339
|
-
}
|
|
1340
|
-
function createWalletAuthAsyncCommand(ctx, syncCommand) {
|
|
1341
|
-
return async (payload) => {
|
|
1342
|
-
return new Promise((resolve, reject) => {
|
|
1343
|
-
try {
|
|
1344
|
-
let commandPayload = null;
|
|
1345
|
-
const handleResponse = async (response) => {
|
|
1346
|
-
ctx.events.unsubscribe("miniapp-wallet-auth" /* MiniAppWalletAuth */);
|
|
1347
|
-
if (response.status === "success") {
|
|
1348
|
-
await ctx.state.updateUserFromWalletAuth(response.address);
|
|
1349
|
-
}
|
|
1350
|
-
resolve({ commandPayload, finalPayload: response });
|
|
1351
|
-
};
|
|
1352
|
-
ctx.events.subscribe(
|
|
1353
|
-
"miniapp-wallet-auth" /* MiniAppWalletAuth */,
|
|
1354
|
-
handleResponse
|
|
1355
|
-
);
|
|
1356
|
-
commandPayload = syncCommand(payload);
|
|
1357
|
-
} catch (error) {
|
|
1358
|
-
reject(error);
|
|
1359
|
-
}
|
|
1360
|
-
});
|
|
1361
|
-
};
|
|
1362
|
-
}
|
|
1363
|
-
|
|
1364
|
-
// commands/index.ts
|
|
1365
|
-
function createCommands(ctx) {
|
|
1366
|
-
return {
|
|
1367
|
-
verify: createVerifyCommand(ctx),
|
|
1368
|
-
pay: createPayCommand(ctx),
|
|
1369
|
-
walletAuth: createWalletAuthCommand(ctx),
|
|
1370
|
-
sendTransaction: createSendTransactionCommand(ctx),
|
|
1371
|
-
signMessage: createSignMessageCommand(ctx),
|
|
1372
|
-
signTypedData: createSignTypedDataCommand(ctx),
|
|
1373
|
-
shareContacts: createShareContactsCommand(ctx),
|
|
1374
|
-
requestPermission: createRequestPermissionCommand(ctx),
|
|
1375
|
-
getPermissions: createGetPermissionsCommand(ctx),
|
|
1376
|
-
sendHapticFeedback: createSendHapticFeedbackCommand(ctx),
|
|
1377
|
-
share: createShareCommand(ctx),
|
|
1378
|
-
chat: createChatCommand(ctx)
|
|
1379
|
-
};
|
|
1380
|
-
}
|
|
1381
|
-
function createAsyncCommands(ctx, commands) {
|
|
1382
|
-
return {
|
|
1383
|
-
verify: createVerifyAsyncCommand(ctx, commands.verify),
|
|
1384
|
-
pay: createPayAsyncCommand(ctx, commands.pay),
|
|
1385
|
-
walletAuth: createWalletAuthAsyncCommand(ctx, commands.walletAuth),
|
|
1386
|
-
sendTransaction: createSendTransactionAsyncCommand(
|
|
1387
|
-
ctx,
|
|
1388
|
-
commands.sendTransaction
|
|
1389
|
-
),
|
|
1390
|
-
signMessage: createSignMessageAsyncCommand(ctx, commands.signMessage),
|
|
1391
|
-
signTypedData: createSignTypedDataAsyncCommand(ctx, commands.signTypedData),
|
|
1392
|
-
shareContacts: createShareContactsAsyncCommand(ctx, commands.shareContacts),
|
|
1393
|
-
requestPermission: createRequestPermissionAsyncCommand(
|
|
1394
|
-
ctx,
|
|
1395
|
-
commands.requestPermission
|
|
1396
|
-
),
|
|
1397
|
-
getPermissions: createGetPermissionsAsyncCommand(
|
|
1398
|
-
ctx,
|
|
1399
|
-
commands.getPermissions
|
|
1400
|
-
),
|
|
1401
|
-
sendHapticFeedback: createSendHapticFeedbackAsyncCommand(
|
|
1402
|
-
ctx,
|
|
1403
|
-
commands.sendHapticFeedback
|
|
1404
|
-
),
|
|
1405
|
-
share: createShareAsyncCommand(ctx, commands.share),
|
|
1406
|
-
chat: createChatAsyncCommand(ctx, commands.chat)
|
|
1407
|
-
};
|
|
1408
|
-
}
|
|
1409
|
-
|
|
1410
|
-
// core/events.ts
|
|
1411
|
-
var import_idkit_core3 = require("@worldcoin/idkit-core");
|
|
1412
|
-
|
|
1413
|
-
// helpers/proof/index.ts
|
|
1414
|
-
var import_viem2 = require("viem");
|
|
1415
|
-
var import_chains2 = require("viem/chains");
|
|
1416
|
-
var semaphoreVerifierAddress = "0x79f46b94d134109EbcbbddBAeD0E88790409A0e4";
|
|
1417
|
-
var semaphoreVerifierAbi = [
|
|
1418
|
-
{
|
|
1419
|
-
inputs: [
|
|
1420
|
-
{
|
|
1421
|
-
internalType: "uint256[8]",
|
|
1422
|
-
name: "proof",
|
|
1423
|
-
type: "uint256[8]"
|
|
1424
|
-
}
|
|
1425
|
-
],
|
|
1426
|
-
name: "compressProof",
|
|
1427
|
-
outputs: [
|
|
1428
|
-
{
|
|
1429
|
-
internalType: "uint256[4]",
|
|
1430
|
-
name: "compressed",
|
|
1431
|
-
type: "uint256[4]"
|
|
1432
|
-
}
|
|
1433
|
-
],
|
|
1434
|
-
stateMutability: "view",
|
|
1435
|
-
type: "function"
|
|
1436
|
-
}
|
|
1437
|
-
];
|
|
1438
|
-
var compressAndPadProof = async (proof, rpcUrl) => {
|
|
1439
|
-
try {
|
|
1440
|
-
const publicClient = (0, import_viem2.createPublicClient)({
|
|
1441
|
-
chain: import_chains2.worldchain,
|
|
1442
|
-
transport: (0, import_viem2.http)(
|
|
1443
|
-
rpcUrl || "https://worldchain-mainnet.g.alchemy.com/public"
|
|
1444
|
-
)
|
|
1445
|
-
});
|
|
1446
|
-
const decodedProof = (0, import_viem2.decodeAbiParameters)(
|
|
1447
|
-
[{ type: "uint256[8]" }],
|
|
1448
|
-
proof
|
|
1449
|
-
)[0];
|
|
1450
|
-
const compressedProof = await publicClient.readContract({
|
|
1451
|
-
address: semaphoreVerifierAddress,
|
|
1452
|
-
abi: semaphoreVerifierAbi,
|
|
1453
|
-
functionName: "compressProof",
|
|
1454
|
-
args: [decodedProof]
|
|
1455
|
-
});
|
|
1456
|
-
const paddedProof = [...compressedProof, 0n, 0n, 0n, 0n];
|
|
1457
|
-
return (0, import_viem2.encodeAbiParameters)([{ type: "uint256[8]" }], [paddedProof]);
|
|
1458
|
-
} catch (e) {
|
|
1459
|
-
return proof;
|
|
1460
|
-
}
|
|
1461
|
-
};
|
|
1462
|
-
|
|
1463
|
-
// core/events.ts
|
|
1464
|
-
var EventManager = class {
|
|
1465
|
-
constructor() {
|
|
1466
|
-
this.listeners = {
|
|
1467
|
-
["miniapp-verify-action" /* MiniAppVerifyAction */]: () => {
|
|
1468
|
-
},
|
|
1469
|
-
["miniapp-payment" /* MiniAppPayment */]: () => {
|
|
1470
|
-
},
|
|
1471
|
-
["miniapp-wallet-auth" /* MiniAppWalletAuth */]: () => {
|
|
1472
|
-
},
|
|
1473
|
-
["miniapp-send-transaction" /* MiniAppSendTransaction */]: () => {
|
|
1474
|
-
},
|
|
1475
|
-
["miniapp-sign-message" /* MiniAppSignMessage */]: () => {
|
|
1476
|
-
},
|
|
1477
|
-
["miniapp-sign-typed-data" /* MiniAppSignTypedData */]: () => {
|
|
1478
|
-
},
|
|
1479
|
-
["miniapp-share-contacts" /* MiniAppShareContacts */]: () => {
|
|
1480
|
-
},
|
|
1481
|
-
["miniapp-request-permission" /* MiniAppRequestPermission */]: () => {
|
|
1482
|
-
},
|
|
1483
|
-
["miniapp-get-permissions" /* MiniAppGetPermissions */]: () => {
|
|
1484
|
-
},
|
|
1485
|
-
["miniapp-send-haptic-feedback" /* MiniAppSendHapticFeedback */]: () => {
|
|
1486
|
-
},
|
|
1487
|
-
["miniapp-share" /* MiniAppShare */]: () => {
|
|
1488
|
-
},
|
|
1489
|
-
["miniapp-microphone" /* MiniAppMicrophone */]: () => {
|
|
1490
|
-
},
|
|
1491
|
-
["miniapp-chat" /* MiniAppChat */]: () => {
|
|
1492
|
-
}
|
|
1493
|
-
};
|
|
1494
|
-
}
|
|
1495
|
-
subscribe(event, handler) {
|
|
1496
|
-
this.listeners[event] = handler;
|
|
1497
|
-
}
|
|
1498
|
-
unsubscribe(event) {
|
|
1499
|
-
delete this.listeners[event];
|
|
1500
|
-
}
|
|
1501
|
-
trigger(event, payload) {
|
|
1502
|
-
if (!this.listeners[event]) {
|
|
1503
|
-
console.error(
|
|
1504
|
-
`No handler for event ${event}, payload: ${JSON.stringify(payload)}`
|
|
1505
|
-
);
|
|
1506
|
-
return;
|
|
1507
|
-
}
|
|
1508
|
-
if (event === "miniapp-verify-action" /* MiniAppVerifyAction */) {
|
|
1509
|
-
const handler = this.listeners[event];
|
|
1510
|
-
this.unsubscribe(event);
|
|
1511
|
-
this.processVerifyActionPayload(
|
|
1512
|
-
payload,
|
|
1513
|
-
handler
|
|
1514
|
-
);
|
|
1515
|
-
return;
|
|
1516
|
-
}
|
|
1517
|
-
this.listeners[event](payload);
|
|
1518
|
-
}
|
|
1519
|
-
async processVerifyActionPayload(payload, handler) {
|
|
1520
|
-
if (payload.status === "error" && payload.error_code === "user_rejected") {
|
|
1521
|
-
payload.error_code = import_idkit_core3.AppErrorCodes.VerificationRejected;
|
|
1522
|
-
}
|
|
1523
|
-
if (payload.status === "success") {
|
|
1524
|
-
if ("verifications" in payload) {
|
|
1525
|
-
const orbVerification = payload.verifications.find(
|
|
1526
|
-
(v) => v.verification_level === import_idkit_core3.VerificationLevel.Orb
|
|
1527
|
-
);
|
|
1528
|
-
if (orbVerification) {
|
|
1529
|
-
orbVerification.proof = await this.compressProofSafely(
|
|
1530
|
-
orbVerification.proof,
|
|
1531
|
-
{
|
|
1532
|
-
mode: "multi",
|
|
1533
|
-
payloadVersion: payload.version,
|
|
1534
|
-
verificationsCount: payload.verifications.length,
|
|
1535
|
-
verificationLevel: orbVerification.verification_level
|
|
1536
|
-
}
|
|
1537
|
-
);
|
|
1538
|
-
}
|
|
1539
|
-
} else if (payload.verification_level === import_idkit_core3.VerificationLevel.Orb) {
|
|
1540
|
-
payload.proof = await this.compressProofSafely(
|
|
1541
|
-
payload.proof,
|
|
1542
|
-
{
|
|
1543
|
-
mode: "single",
|
|
1544
|
-
payloadVersion: payload.version,
|
|
1545
|
-
verificationLevel: payload.verification_level
|
|
1546
|
-
}
|
|
1547
|
-
);
|
|
1548
|
-
}
|
|
1549
|
-
}
|
|
1550
|
-
handler(payload);
|
|
1551
|
-
}
|
|
1552
|
-
async compressProofSafely(proof, context) {
|
|
1553
|
-
try {
|
|
1554
|
-
return await compressAndPadProof(proof);
|
|
1555
|
-
} catch (error) {
|
|
1556
|
-
console.error(
|
|
1557
|
-
"Failed to compress verification proof. Delivering payload with uncompressed proof.",
|
|
1558
|
-
{
|
|
1559
|
-
...context,
|
|
1560
|
-
error
|
|
1561
|
-
}
|
|
1562
|
-
);
|
|
1563
|
-
return proof;
|
|
1564
|
-
}
|
|
1351
|
+
if (siweMessageData.request_id) {
|
|
1352
|
+
siweMessage += `Request ID: ${siweMessageData.request_id}
|
|
1353
|
+
`;
|
|
1565
1354
|
}
|
|
1355
|
+
return siweMessage;
|
|
1566
1356
|
};
|
|
1567
1357
|
|
|
1568
|
-
//
|
|
1569
|
-
var
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
addresses: [address]
|
|
1577
|
-
})
|
|
1578
|
-
});
|
|
1579
|
-
const usernames = await res.json();
|
|
1580
|
-
return usernames?.[0] ?? { username: null, profile_picture_url: null };
|
|
1581
|
-
};
|
|
1582
|
-
|
|
1583
|
-
// types/init.ts
|
|
1584
|
-
var MiniAppLaunchLocation = /* @__PURE__ */ ((MiniAppLaunchLocation3) => {
|
|
1585
|
-
MiniAppLaunchLocation3["Chat"] = "chat";
|
|
1586
|
-
MiniAppLaunchLocation3["Home"] = "home";
|
|
1587
|
-
MiniAppLaunchLocation3["AppStore"] = "app-store";
|
|
1588
|
-
MiniAppLaunchLocation3["DeepLink"] = "deep-link";
|
|
1589
|
-
MiniAppLaunchLocation3["WalletTab"] = "wallet-tab";
|
|
1590
|
-
return MiniAppLaunchLocation3;
|
|
1591
|
-
})(MiniAppLaunchLocation || {});
|
|
1592
|
-
var WORLD_APP_LAUNCH_LOCATION_MAP = {
|
|
1593
|
-
"app-store": "app-store" /* AppStore */,
|
|
1594
|
-
carousel: "app-store" /* AppStore */,
|
|
1595
|
-
explore: "app-store" /* AppStore */,
|
|
1596
|
-
app_details: "app-store" /* AppStore */,
|
|
1597
|
-
deeplink: "deep-link" /* DeepLink */,
|
|
1598
|
-
homepage: "home" /* Home */,
|
|
1599
|
-
wallet_tab: "wallet-tab" /* WalletTab */,
|
|
1600
|
-
world_chat: "chat" /* Chat */
|
|
1601
|
-
};
|
|
1602
|
-
var mapWorldAppLaunchLocation = (location) => {
|
|
1603
|
-
if (!location || typeof location !== "string") return null;
|
|
1604
|
-
console.log("MiniKit launch location mapped:", location);
|
|
1605
|
-
const normalizedLocation = location.toLowerCase();
|
|
1606
|
-
return WORLD_APP_LAUNCH_LOCATION_MAP[normalizedLocation] ?? null;
|
|
1358
|
+
// src/commands/wallet-auth/types.ts
|
|
1359
|
+
var WalletAuthError = class extends Error {
|
|
1360
|
+
constructor(code, details) {
|
|
1361
|
+
super(details || `Wallet auth failed: ${code}`);
|
|
1362
|
+
this.name = "WalletAuthError";
|
|
1363
|
+
this.code = code;
|
|
1364
|
+
this.details = details;
|
|
1365
|
+
}
|
|
1607
1366
|
};
|
|
1608
1367
|
|
|
1609
|
-
//
|
|
1610
|
-
var
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
this.deviceProperties = {};
|
|
1615
|
-
this.location = null;
|
|
1616
|
-
this.isReady = false;
|
|
1368
|
+
// src/commands/wallet-auth/validate.ts
|
|
1369
|
+
var SIWE_NONCE_REGEX2 = /^[a-zA-Z0-9]+$/;
|
|
1370
|
+
var validateWalletAuthCommandInput = (params) => {
|
|
1371
|
+
if (!params.nonce) {
|
|
1372
|
+
return { valid: false, message: "'nonce' is required" };
|
|
1617
1373
|
}
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
this.user.optedIntoOptionalAnalytics = worldApp.is_optional_analytics;
|
|
1621
|
-
this.user.deviceOS = worldApp.device_os;
|
|
1622
|
-
this.user.worldAppVersion = worldApp.world_app_version;
|
|
1623
|
-
this.deviceProperties.safeAreaInsets = worldApp.safe_area_insets;
|
|
1624
|
-
this.deviceProperties.deviceOS = worldApp.device_os;
|
|
1625
|
-
this.deviceProperties.worldAppVersion = worldApp.world_app_version;
|
|
1626
|
-
this.location = mapWorldAppLaunchLocation(worldApp.location);
|
|
1627
|
-
}
|
|
1628
|
-
async updateUserFromWalletAuth(address) {
|
|
1629
|
-
this.user.walletAddress = address;
|
|
1630
|
-
try {
|
|
1631
|
-
const userProfile = await getUserProfile(address);
|
|
1632
|
-
this.user.username = userProfile.username;
|
|
1633
|
-
this.user.profilePictureUrl = userProfile.profile_picture_url;
|
|
1634
|
-
} catch (error) {
|
|
1635
|
-
console.error("Failed to fetch user profile:", error);
|
|
1636
|
-
}
|
|
1374
|
+
if (params.nonce.length < 8) {
|
|
1375
|
+
return { valid: false, message: "'nonce' must be at least 8 characters" };
|
|
1637
1376
|
}
|
|
1638
|
-
|
|
1639
|
-
const walletAddress = address ?? this.user.walletAddress;
|
|
1640
|
-
const userProfile = await getUserProfile(walletAddress);
|
|
1377
|
+
if (!SIWE_NONCE_REGEX2.test(params.nonce)) {
|
|
1641
1378
|
return {
|
|
1642
|
-
|
|
1643
|
-
|
|
1644
|
-
profilePictureUrl: userProfile.profile_picture_url
|
|
1379
|
+
valid: false,
|
|
1380
|
+
message: "'nonce' must be alphanumeric (letters and numbers only)"
|
|
1645
1381
|
};
|
|
1646
1382
|
}
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
return {
|
|
1659
|
-
walletAddress: user.address,
|
|
1660
|
-
username: user.username,
|
|
1661
|
-
profilePictureUrl: user.profile_picture_url
|
|
1662
|
-
};
|
|
1383
|
+
if (params.statement && params.statement.includes("\n")) {
|
|
1384
|
+
return { valid: false, message: "'statement' must not contain newlines" };
|
|
1385
|
+
}
|
|
1386
|
+
if (params.expirationTime && new Date(params.expirationTime) < /* @__PURE__ */ new Date()) {
|
|
1387
|
+
return { valid: false, message: "'expirationTime' must be in the future" };
|
|
1388
|
+
}
|
|
1389
|
+
if (params.expirationTime && new Date(params.expirationTime) > new Date(Date.now() + 7 * 24 * 60 * 60 * 1e3)) {
|
|
1390
|
+
return { valid: false, message: "'expirationTime' must be within 7 days" };
|
|
1391
|
+
}
|
|
1392
|
+
if (params.notBefore && new Date(params.notBefore) > new Date(Date.now() + 7 * 24 * 60 * 60 * 1e3)) {
|
|
1393
|
+
return { valid: false, message: "'notBefore' must be within 7 days" };
|
|
1663
1394
|
}
|
|
1395
|
+
return { valid: true };
|
|
1664
1396
|
};
|
|
1665
1397
|
|
|
1666
|
-
//
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1398
|
+
// src/commands/wallet-auth/index.ts
|
|
1399
|
+
async function walletAuth(options, ctx) {
|
|
1400
|
+
const result = await executeWithFallback({
|
|
1401
|
+
command: "wallet-auth" /* WalletAuth */,
|
|
1402
|
+
nativeExecutor: () => nativeWalletAuth(options, ctx),
|
|
1403
|
+
wagmiFallback: () => wagmiWalletAuth({
|
|
1404
|
+
nonce: options.nonce,
|
|
1405
|
+
statement: options.statement,
|
|
1406
|
+
expirationTime: options.expirationTime
|
|
1407
|
+
}),
|
|
1408
|
+
customFallback: options.fallback
|
|
1409
|
+
});
|
|
1410
|
+
if (result.executedWith === "fallback") {
|
|
1411
|
+
return { executedWith: "fallback", data: result.data };
|
|
1412
|
+
}
|
|
1413
|
+
if (result.executedWith === "wagmi") {
|
|
1414
|
+
return {
|
|
1415
|
+
executedWith: "wagmi",
|
|
1416
|
+
data: result.data
|
|
1417
|
+
};
|
|
1418
|
+
}
|
|
1419
|
+
return {
|
|
1420
|
+
executedWith: "minikit",
|
|
1421
|
+
data: result.data
|
|
1422
|
+
};
|
|
1423
|
+
}
|
|
1424
|
+
async function nativeWalletAuth(options, ctx) {
|
|
1425
|
+
if (!ctx) {
|
|
1426
|
+
ctx = { events: new EventManager(), state: { deviceProperties: {} } };
|
|
1427
|
+
}
|
|
1428
|
+
if (typeof window === "undefined" || !isCommandAvailable("wallet-auth" /* WalletAuth */)) {
|
|
1429
|
+
throw new Error(
|
|
1430
|
+
"'walletAuth' command is unavailable. Check MiniKit.install() or update the app version"
|
|
1431
|
+
);
|
|
1432
|
+
}
|
|
1433
|
+
const input = {
|
|
1434
|
+
nonce: options.nonce,
|
|
1435
|
+
statement: options.statement,
|
|
1436
|
+
requestId: options.requestId,
|
|
1437
|
+
expirationTime: options.expirationTime,
|
|
1438
|
+
notBefore: options.notBefore
|
|
1439
|
+
};
|
|
1440
|
+
const validationResult = validateWalletAuthCommandInput(input);
|
|
1441
|
+
if (!validationResult.valid) {
|
|
1442
|
+
throw new Error(`Invalid wallet auth input: ${validationResult.message}`);
|
|
1443
|
+
}
|
|
1444
|
+
let protocol;
|
|
1445
|
+
try {
|
|
1446
|
+
const currentUrl = new URL(window.location.href);
|
|
1447
|
+
protocol = currentUrl.protocol.split(":")[0];
|
|
1448
|
+
} catch (error) {
|
|
1449
|
+
throw new Error("Failed to get current URL");
|
|
1450
|
+
}
|
|
1451
|
+
const siweMessage = generateSiweMessage({
|
|
1452
|
+
scheme: protocol,
|
|
1453
|
+
domain: window.location.host,
|
|
1454
|
+
statement: input.statement ?? void 0,
|
|
1455
|
+
uri: window.location.href,
|
|
1456
|
+
version: "1",
|
|
1457
|
+
chain_id: 480,
|
|
1458
|
+
nonce: input.nonce,
|
|
1459
|
+
issued_at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
1460
|
+
expiration_time: input.expirationTime?.toISOString() ?? void 0,
|
|
1461
|
+
not_before: input.notBefore?.toISOString() ?? void 0,
|
|
1462
|
+
request_id: input.requestId ?? void 0
|
|
1463
|
+
});
|
|
1464
|
+
const walletAuthPayload = { siweMessage };
|
|
1465
|
+
const worldAppVersion = ctx.state.deviceProperties.worldAppVersion;
|
|
1466
|
+
const walletAuthVersion = worldAppVersion && worldAppVersion > 2087900 ? COMMAND_VERSIONS["wallet-auth" /* WalletAuth */] : 1;
|
|
1467
|
+
const finalPayload = await new Promise(
|
|
1468
|
+
(resolve, reject) => {
|
|
1469
|
+
try {
|
|
1470
|
+
ctx.events.subscribe("miniapp-wallet-auth" /* MiniAppWalletAuth */, (response) => {
|
|
1471
|
+
ctx.events.unsubscribe("miniapp-wallet-auth" /* MiniAppWalletAuth */);
|
|
1472
|
+
resolve(response);
|
|
1473
|
+
});
|
|
1474
|
+
sendMiniKitEvent({
|
|
1475
|
+
command: "wallet-auth" /* WalletAuth */,
|
|
1476
|
+
version: walletAuthVersion,
|
|
1477
|
+
payload: walletAuthPayload
|
|
1478
|
+
});
|
|
1479
|
+
} catch (error) {
|
|
1480
|
+
reject(error);
|
|
1481
|
+
}
|
|
1482
|
+
}
|
|
1483
|
+
);
|
|
1484
|
+
if (finalPayload.status === "error") {
|
|
1485
|
+
throw new WalletAuthError(finalPayload.error_code, finalPayload.details);
|
|
1486
|
+
}
|
|
1487
|
+
return {
|
|
1488
|
+
address: finalPayload.address,
|
|
1489
|
+
message: finalPayload.message,
|
|
1490
|
+
signature: finalPayload.signature
|
|
1491
|
+
};
|
|
1492
|
+
}
|
|
1697
1493
|
|
|
1698
|
-
// helpers/microphone
|
|
1494
|
+
// src/helpers/microphone.ts
|
|
1699
1495
|
var microphoneSetupDone = false;
|
|
1700
1496
|
var setupMicrophone = () => {
|
|
1701
1497
|
if (microphoneSetupDone) {
|
|
@@ -1718,7 +1514,7 @@ var setupMicrophone = () => {
|
|
|
1718
1514
|
const stream = await realGUM(constraints);
|
|
1719
1515
|
const hasAudioTrack = stream.getAudioTracks().length > 0;
|
|
1720
1516
|
if (hasAudioTrack) {
|
|
1721
|
-
|
|
1517
|
+
sendMiniKitEvent({
|
|
1722
1518
|
command: "microphone-stream-started",
|
|
1723
1519
|
version: 1,
|
|
1724
1520
|
payload: {
|
|
@@ -1730,7 +1526,7 @@ var setupMicrophone = () => {
|
|
|
1730
1526
|
t.addEventListener("ended", () => {
|
|
1731
1527
|
const allAudioTracksEnded = stream.getAudioTracks().every((track) => track.readyState === "ended");
|
|
1732
1528
|
if (allAudioTracksEnded) {
|
|
1733
|
-
|
|
1529
|
+
sendMiniKitEvent({
|
|
1734
1530
|
command: "microphone-stream-ended",
|
|
1735
1531
|
version: 1,
|
|
1736
1532
|
payload: {
|
|
@@ -1758,7 +1554,7 @@ var setupMicrophone = () => {
|
|
|
1758
1554
|
audioTracks.forEach((t) => {
|
|
1759
1555
|
t.stop();
|
|
1760
1556
|
});
|
|
1761
|
-
|
|
1557
|
+
sendMiniKitEvent({
|
|
1762
1558
|
command: "microphone-stream-ended",
|
|
1763
1559
|
version: 1,
|
|
1764
1560
|
payload: {
|
|
@@ -1779,40 +1575,253 @@ var setupMicrophone = () => {
|
|
|
1779
1575
|
microphoneSetupDone = true;
|
|
1780
1576
|
};
|
|
1781
1577
|
|
|
1782
|
-
//
|
|
1578
|
+
// src/helpers/usernames.ts
|
|
1579
|
+
var getUserProfile = async (address) => {
|
|
1580
|
+
const res = await fetch("https://usernames.worldcoin.org/api/v1/query", {
|
|
1581
|
+
method: "POST",
|
|
1582
|
+
headers: {
|
|
1583
|
+
"Content-Type": "application/json"
|
|
1584
|
+
},
|
|
1585
|
+
body: JSON.stringify({
|
|
1586
|
+
addresses: [address]
|
|
1587
|
+
})
|
|
1588
|
+
});
|
|
1589
|
+
const usernames = await res.json();
|
|
1590
|
+
return usernames?.[0] ?? { username: null, profile_picture_url: null };
|
|
1591
|
+
};
|
|
1592
|
+
|
|
1593
|
+
// src/types.ts
|
|
1594
|
+
var MiniKitInstallErrorMessage = {
|
|
1595
|
+
["unknown" /* Unknown */]: "Failed to install MiniKit.",
|
|
1596
|
+
["already_installed" /* AlreadyInstalled */]: "MiniKit is already installed.",
|
|
1597
|
+
["outside_of_worldapp" /* OutsideOfWorldApp */]: "MiniApp launched outside of WorldApp.",
|
|
1598
|
+
["not_on_client" /* NotOnClient */]: "Window object is not available.",
|
|
1599
|
+
["app_out_of_date" /* AppOutOfDate */]: "WorldApp is out of date. Please update the app."
|
|
1600
|
+
};
|
|
1601
|
+
|
|
1602
|
+
// src/minikit.ts
|
|
1783
1603
|
var MINIKIT_VERSION = 1;
|
|
1784
1604
|
var MINIKIT_MINOR_VERSION = 96;
|
|
1605
|
+
var WORLD_APP_LAUNCH_LOCATION_MAP = {
|
|
1606
|
+
"app-store": "app-store" /* AppStore */,
|
|
1607
|
+
carousel: "app-store" /* AppStore */,
|
|
1608
|
+
explore: "app-store" /* AppStore */,
|
|
1609
|
+
app_details: "app-store" /* AppStore */,
|
|
1610
|
+
deeplink: "deep-link" /* DeepLink */,
|
|
1611
|
+
homepage: "home" /* Home */,
|
|
1612
|
+
wallet_tab: "wallet-tab" /* WalletTab */,
|
|
1613
|
+
world_chat: "chat" /* Chat */
|
|
1614
|
+
};
|
|
1615
|
+
function mapWorldAppLaunchLocation(location) {
|
|
1616
|
+
if (!location || typeof location !== "string") return null;
|
|
1617
|
+
console.log("MiniKit launch location mapped:", location);
|
|
1618
|
+
return WORLD_APP_LAUNCH_LOCATION_MAP[location.toLowerCase()] ?? null;
|
|
1619
|
+
}
|
|
1785
1620
|
var _MiniKit = class _MiniKit {
|
|
1621
|
+
static getActiveMiniKit() {
|
|
1622
|
+
if (typeof window === "undefined") return this;
|
|
1623
|
+
const candidate = window.MiniKit;
|
|
1624
|
+
if (candidate && typeof candidate.trigger === "function") {
|
|
1625
|
+
return candidate;
|
|
1626
|
+
}
|
|
1627
|
+
return this;
|
|
1628
|
+
}
|
|
1629
|
+
// ============================================================================
|
|
1630
|
+
// Unified API (auto-detects environment)
|
|
1631
|
+
// ============================================================================
|
|
1632
|
+
/**
|
|
1633
|
+
* Authenticate user via wallet signature (SIWE)
|
|
1634
|
+
*
|
|
1635
|
+
* Works in World App (native SIWE) and web (Wagmi + SIWE fallback).
|
|
1636
|
+
*
|
|
1637
|
+
* @example
|
|
1638
|
+
* ```typescript
|
|
1639
|
+
* const result = await MiniKit.walletAuth({ nonce: 'randomnonce123' });
|
|
1640
|
+
* console.log(result.data.address);
|
|
1641
|
+
* console.log(result.executedWith); // 'minikit' | 'wagmi' | 'fallback'
|
|
1642
|
+
* ```
|
|
1643
|
+
*/
|
|
1644
|
+
static walletAuth(options) {
|
|
1645
|
+
const active = this.getActiveMiniKit();
|
|
1646
|
+
if (active !== this) {
|
|
1647
|
+
return active.walletAuth(options);
|
|
1648
|
+
}
|
|
1649
|
+
return walletAuth(options, this.getContext());
|
|
1650
|
+
}
|
|
1651
|
+
/**
|
|
1652
|
+
* Send one or more transactions
|
|
1653
|
+
*
|
|
1654
|
+
* World App: batch + permit2 + gas sponsorship
|
|
1655
|
+
* Web: sequential execution via Wagmi
|
|
1656
|
+
*
|
|
1657
|
+
* @example
|
|
1658
|
+
* ```typescript
|
|
1659
|
+
* const result = await MiniKit.sendTransaction({
|
|
1660
|
+
* chainId: 480,
|
|
1661
|
+
* transaction: [{
|
|
1662
|
+
* address: '0x...',
|
|
1663
|
+
* abi: ContractABI,
|
|
1664
|
+
* functionName: 'mint',
|
|
1665
|
+
* args: [],
|
|
1666
|
+
* }],
|
|
1667
|
+
* });
|
|
1668
|
+
* ```
|
|
1669
|
+
*/
|
|
1670
|
+
static sendTransaction(options) {
|
|
1671
|
+
const active = this.getActiveMiniKit();
|
|
1672
|
+
if (active !== this) {
|
|
1673
|
+
return active.sendTransaction(options);
|
|
1674
|
+
}
|
|
1675
|
+
return sendTransaction(options, this.getContext());
|
|
1676
|
+
}
|
|
1677
|
+
/**
|
|
1678
|
+
* Send a payment (World App only)
|
|
1679
|
+
*
|
|
1680
|
+
* Requires custom fallback on web.
|
|
1681
|
+
*
|
|
1682
|
+
* @example
|
|
1683
|
+
* ```typescript
|
|
1684
|
+
* const result = await MiniKit.pay({
|
|
1685
|
+
* reference: crypto.randomUUID(),
|
|
1686
|
+
* to: '0x...',
|
|
1687
|
+
* tokens: [{ symbol: Tokens.WLD, token_amount: '1.0' }],
|
|
1688
|
+
* description: 'Payment for coffee',
|
|
1689
|
+
* fallback: () => showStripeCheckout(),
|
|
1690
|
+
* });
|
|
1691
|
+
* ```
|
|
1692
|
+
*/
|
|
1693
|
+
static pay(options) {
|
|
1694
|
+
const active = this.getActiveMiniKit();
|
|
1695
|
+
if (active !== this) {
|
|
1696
|
+
return active.pay(options);
|
|
1697
|
+
}
|
|
1698
|
+
return pay(options, this.getContext());
|
|
1699
|
+
}
|
|
1700
|
+
/**
|
|
1701
|
+
* Open the contact picker (World App only)
|
|
1702
|
+
*
|
|
1703
|
+
* Requires custom fallback on web.
|
|
1704
|
+
*
|
|
1705
|
+
* @example
|
|
1706
|
+
* ```typescript
|
|
1707
|
+
* const result = await MiniKit.shareContacts({
|
|
1708
|
+
* isMultiSelectEnabled: true,
|
|
1709
|
+
* fallback: () => showManualAddressInput(),
|
|
1710
|
+
* });
|
|
1711
|
+
* ```
|
|
1712
|
+
*/
|
|
1713
|
+
static shareContacts(options = {}) {
|
|
1714
|
+
const active = this.getActiveMiniKit();
|
|
1715
|
+
if (active !== this) {
|
|
1716
|
+
return active.shareContacts(options);
|
|
1717
|
+
}
|
|
1718
|
+
return shareContacts(options, this.getContext());
|
|
1719
|
+
}
|
|
1720
|
+
/**
|
|
1721
|
+
* Sign a message
|
|
1722
|
+
*/
|
|
1723
|
+
static signMessage(options) {
|
|
1724
|
+
const active = this.getActiveMiniKit();
|
|
1725
|
+
if (active !== this) {
|
|
1726
|
+
return active.signMessage(options);
|
|
1727
|
+
}
|
|
1728
|
+
return signMessage(options, this.getContext());
|
|
1729
|
+
}
|
|
1730
|
+
/**
|
|
1731
|
+
* Sign typed data (EIP-712)
|
|
1732
|
+
*/
|
|
1733
|
+
static signTypedData(options) {
|
|
1734
|
+
const active = this.getActiveMiniKit();
|
|
1735
|
+
if (active !== this) {
|
|
1736
|
+
return active.signTypedData(options);
|
|
1737
|
+
}
|
|
1738
|
+
return signTypedData(options, this.getContext());
|
|
1739
|
+
}
|
|
1740
|
+
/**
|
|
1741
|
+
* Send a chat message
|
|
1742
|
+
*/
|
|
1743
|
+
static chat(options) {
|
|
1744
|
+
const active = this.getActiveMiniKit();
|
|
1745
|
+
if (active !== this) {
|
|
1746
|
+
return active.chat(options);
|
|
1747
|
+
}
|
|
1748
|
+
return chat(options, this.getContext());
|
|
1749
|
+
}
|
|
1750
|
+
/**
|
|
1751
|
+
* Share files/text/URL
|
|
1752
|
+
*/
|
|
1753
|
+
static share(options) {
|
|
1754
|
+
const active = this.getActiveMiniKit();
|
|
1755
|
+
if (active !== this) {
|
|
1756
|
+
return active.share(options);
|
|
1757
|
+
}
|
|
1758
|
+
return share(options, this.getContext());
|
|
1759
|
+
}
|
|
1760
|
+
/**
|
|
1761
|
+
* Get current permission settings
|
|
1762
|
+
*/
|
|
1763
|
+
static getPermissions(options = {}) {
|
|
1764
|
+
const active = this.getActiveMiniKit();
|
|
1765
|
+
if (active !== this) {
|
|
1766
|
+
return active.getPermissions(options);
|
|
1767
|
+
}
|
|
1768
|
+
return getPermissions(options, this.getContext());
|
|
1769
|
+
}
|
|
1770
|
+
/**
|
|
1771
|
+
* Request a permission from the user
|
|
1772
|
+
*/
|
|
1773
|
+
static requestPermission(options) {
|
|
1774
|
+
const active = this.getActiveMiniKit();
|
|
1775
|
+
if (active !== this) {
|
|
1776
|
+
return active.requestPermission(options);
|
|
1777
|
+
}
|
|
1778
|
+
return requestPermission(options, this.getContext());
|
|
1779
|
+
}
|
|
1780
|
+
/**
|
|
1781
|
+
* Trigger haptic feedback
|
|
1782
|
+
*/
|
|
1783
|
+
static sendHapticFeedback(options) {
|
|
1784
|
+
const active = this.getActiveMiniKit();
|
|
1785
|
+
if (active !== this) {
|
|
1786
|
+
return active.sendHapticFeedback(options);
|
|
1787
|
+
}
|
|
1788
|
+
return sendHapticFeedback(options, this.getContext());
|
|
1789
|
+
}
|
|
1786
1790
|
// ============================================================================
|
|
1787
1791
|
// Public State Accessors
|
|
1788
1792
|
// ============================================================================
|
|
1789
1793
|
static get appId() {
|
|
1790
|
-
return this.
|
|
1794
|
+
return this._appId;
|
|
1791
1795
|
}
|
|
1792
1796
|
static set appId(value) {
|
|
1793
|
-
this.
|
|
1797
|
+
this._appId = value;
|
|
1794
1798
|
}
|
|
1795
1799
|
static get user() {
|
|
1796
|
-
return this.
|
|
1800
|
+
return this._user;
|
|
1797
1801
|
}
|
|
1798
1802
|
static set user(value) {
|
|
1799
|
-
this.
|
|
1803
|
+
this._user = value;
|
|
1800
1804
|
}
|
|
1801
1805
|
static get deviceProperties() {
|
|
1802
|
-
return this.
|
|
1806
|
+
return this._deviceProperties;
|
|
1803
1807
|
}
|
|
1804
1808
|
static get location() {
|
|
1805
|
-
return this.
|
|
1809
|
+
return this._location;
|
|
1806
1810
|
}
|
|
1807
1811
|
// ============================================================================
|
|
1808
1812
|
// Event System
|
|
1809
1813
|
// ============================================================================
|
|
1810
1814
|
static subscribe(event, handler) {
|
|
1815
|
+
const active = this.getActiveMiniKit();
|
|
1816
|
+
if (active !== this) {
|
|
1817
|
+
active.subscribe(event, handler);
|
|
1818
|
+
return;
|
|
1819
|
+
}
|
|
1811
1820
|
if (event === "miniapp-wallet-auth" /* MiniAppWalletAuth */) {
|
|
1812
1821
|
const originalHandler = handler;
|
|
1813
1822
|
const wrappedHandler = async (payload) => {
|
|
1814
1823
|
if (payload.status === "success") {
|
|
1815
|
-
await this.
|
|
1824
|
+
await this.updateUserFromWalletAuth(payload.address);
|
|
1816
1825
|
}
|
|
1817
1826
|
originalHandler(payload);
|
|
1818
1827
|
};
|
|
@@ -1822,16 +1831,26 @@ var _MiniKit = class _MiniKit {
|
|
|
1822
1831
|
}
|
|
1823
1832
|
}
|
|
1824
1833
|
static unsubscribe(event) {
|
|
1834
|
+
const active = this.getActiveMiniKit();
|
|
1835
|
+
if (active !== this) {
|
|
1836
|
+
active.unsubscribe(event);
|
|
1837
|
+
return;
|
|
1838
|
+
}
|
|
1825
1839
|
this.eventManager.unsubscribe(event);
|
|
1826
1840
|
}
|
|
1827
1841
|
static trigger(event, payload) {
|
|
1842
|
+
const active = this.getActiveMiniKit();
|
|
1843
|
+
if (active !== this) {
|
|
1844
|
+
active.trigger(event, payload);
|
|
1845
|
+
return;
|
|
1846
|
+
}
|
|
1828
1847
|
this.eventManager.trigger(event, payload);
|
|
1829
1848
|
}
|
|
1830
1849
|
// ============================================================================
|
|
1831
1850
|
// Installation
|
|
1832
1851
|
// ============================================================================
|
|
1833
1852
|
static sendInit() {
|
|
1834
|
-
|
|
1853
|
+
sendMiniKitEvent({
|
|
1835
1854
|
command: "init",
|
|
1836
1855
|
payload: {
|
|
1837
1856
|
version: MINIKIT_VERSION,
|
|
@@ -1840,7 +1859,11 @@ var _MiniKit = class _MiniKit {
|
|
|
1840
1859
|
});
|
|
1841
1860
|
}
|
|
1842
1861
|
static install(appId) {
|
|
1843
|
-
|
|
1862
|
+
const active = this.getActiveMiniKit();
|
|
1863
|
+
if (active !== this) {
|
|
1864
|
+
return active.install(appId);
|
|
1865
|
+
}
|
|
1866
|
+
if (typeof window === "undefined") {
|
|
1844
1867
|
return {
|
|
1845
1868
|
success: false,
|
|
1846
1869
|
errorCode: "already_installed" /* AlreadyInstalled */,
|
|
@@ -1850,7 +1873,7 @@ var _MiniKit = class _MiniKit {
|
|
|
1850
1873
|
if (!appId) {
|
|
1851
1874
|
console.warn("App ID not provided during install");
|
|
1852
1875
|
} else {
|
|
1853
|
-
this.
|
|
1876
|
+
this._appId = appId;
|
|
1854
1877
|
}
|
|
1855
1878
|
if (!window.WorldApp) {
|
|
1856
1879
|
return {
|
|
@@ -1859,9 +1882,9 @@ var _MiniKit = class _MiniKit {
|
|
|
1859
1882
|
errorMessage: MiniKitInstallErrorMessage["outside_of_worldapp" /* OutsideOfWorldApp */]
|
|
1860
1883
|
};
|
|
1861
1884
|
}
|
|
1862
|
-
this.
|
|
1885
|
+
this.initFromWorldApp(window.WorldApp);
|
|
1863
1886
|
try {
|
|
1864
|
-
window.MiniKit =
|
|
1887
|
+
window.MiniKit = this;
|
|
1865
1888
|
this.sendInit();
|
|
1866
1889
|
} catch (error) {
|
|
1867
1890
|
console.error(
|
|
@@ -1874,7 +1897,7 @@ var _MiniKit = class _MiniKit {
|
|
|
1874
1897
|
errorMessage: MiniKitInstallErrorMessage["unknown" /* Unknown */]
|
|
1875
1898
|
};
|
|
1876
1899
|
}
|
|
1877
|
-
this.
|
|
1900
|
+
this._isReady = true;
|
|
1878
1901
|
setupMicrophone();
|
|
1879
1902
|
if (!validateCommands(window.WorldApp.supported_commands)) {
|
|
1880
1903
|
return {
|
|
@@ -1886,9 +1909,9 @@ var _MiniKit = class _MiniKit {
|
|
|
1886
1909
|
return { success: true };
|
|
1887
1910
|
}
|
|
1888
1911
|
static isInstalled(debug) {
|
|
1889
|
-
const isInstalled = this.
|
|
1912
|
+
const isInstalled = this._isReady && Boolean(window.MiniKit);
|
|
1890
1913
|
if (!isInstalled) {
|
|
1891
|
-
console.
|
|
1914
|
+
console.warn(
|
|
1892
1915
|
"MiniKit is not installed. Make sure you're running the application inside of World App"
|
|
1893
1916
|
);
|
|
1894
1917
|
}
|
|
@@ -1898,42 +1921,106 @@ var _MiniKit = class _MiniKit {
|
|
|
1898
1921
|
return isInstalled;
|
|
1899
1922
|
}
|
|
1900
1923
|
// ============================================================================
|
|
1901
|
-
//
|
|
1924
|
+
// Internal
|
|
1902
1925
|
// ============================================================================
|
|
1926
|
+
static initFromWorldApp(worldApp) {
|
|
1927
|
+
if (!worldApp) return;
|
|
1928
|
+
this._user.optedIntoOptionalAnalytics = worldApp.is_optional_analytics;
|
|
1929
|
+
this._deviceProperties.safeAreaInsets = worldApp.safe_area_insets;
|
|
1930
|
+
this._deviceProperties.deviceOS = worldApp.device_os;
|
|
1931
|
+
this._deviceProperties.worldAppVersion = worldApp.world_app_version;
|
|
1932
|
+
this._location = mapWorldAppLaunchLocation(worldApp.location);
|
|
1933
|
+
}
|
|
1934
|
+
static async updateUserFromWalletAuth(address) {
|
|
1935
|
+
this._user.walletAddress = address;
|
|
1936
|
+
try {
|
|
1937
|
+
const userProfile = await getUserProfile(address);
|
|
1938
|
+
this._user.username = userProfile.username;
|
|
1939
|
+
this._user.profilePictureUrl = userProfile.profile_picture_url;
|
|
1940
|
+
} catch (error) {
|
|
1941
|
+
console.error("Failed to fetch user profile:", error);
|
|
1942
|
+
}
|
|
1943
|
+
}
|
|
1903
1944
|
static getContext() {
|
|
1904
1945
|
return {
|
|
1905
1946
|
events: this.eventManager,
|
|
1906
|
-
state: this.
|
|
1947
|
+
state: { deviceProperties: this._deviceProperties }
|
|
1907
1948
|
};
|
|
1908
1949
|
}
|
|
1950
|
+
// ============================================================================
|
|
1951
|
+
// Deprecated — remove in next major
|
|
1952
|
+
// ============================================================================
|
|
1953
|
+
/**
|
|
1954
|
+
* @deprecated Use `MiniKit.pay()`, `MiniKit.walletAuth()`, etc. directly.
|
|
1955
|
+
*
|
|
1956
|
+
* Migration guide:
|
|
1957
|
+
* - `MiniKit.commands.pay(payload)` → `await MiniKit.pay(options)`
|
|
1958
|
+
* - `MiniKit.commands.walletAuth(payload)` → `await MiniKit.walletAuth(options)`
|
|
1959
|
+
* - `MiniKit.commands.sendTransaction(payload)` → `await MiniKit.sendTransaction(options)`
|
|
1960
|
+
* - `MiniKit.commands.signMessage(payload)` → `await MiniKit.signMessage(input)`
|
|
1961
|
+
* - `MiniKit.commands.signTypedData(payload)` → `await MiniKit.signTypedData(input)`
|
|
1962
|
+
* - `MiniKit.commands.shareContacts(payload)` → `await MiniKit.shareContacts(options)`
|
|
1963
|
+
* - `MiniKit.commands.chat(payload)` → `await MiniKit.chat(input)`
|
|
1964
|
+
* - `MiniKit.commands.share(payload)` → `await MiniKit.share(input)`
|
|
1965
|
+
* - `MiniKit.commands.getPermissions()` → `await MiniKit.getPermissions()`
|
|
1966
|
+
* - `MiniKit.commands.requestPermission(payload)` → `await MiniKit.requestPermission(input)`
|
|
1967
|
+
* - `MiniKit.commands.sendHapticFeedback(payload)` → `await MiniKit.sendHapticFeedback(input)`
|
|
1968
|
+
*/
|
|
1909
1969
|
static get commands() {
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
return this.commandsInstance;
|
|
1970
|
+
throw new Error(
|
|
1971
|
+
"MiniKit.commands has been removed. Use MiniKit.pay(), MiniKit.walletAuth(), etc. directly."
|
|
1972
|
+
);
|
|
1914
1973
|
}
|
|
1974
|
+
/**
|
|
1975
|
+
* @deprecated Use `MiniKit.pay()`, `MiniKit.walletAuth()`, etc. directly. All commands are now async by default.
|
|
1976
|
+
*
|
|
1977
|
+
* See `MiniKit.commands` deprecation notice for the full migration guide.
|
|
1978
|
+
*/
|
|
1915
1979
|
static get commandsAsync() {
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
this.commands
|
|
1920
|
-
);
|
|
1921
|
-
}
|
|
1922
|
-
return this.asyncCommandsInstance;
|
|
1980
|
+
throw new Error(
|
|
1981
|
+
"MiniKit.commandsAsync has been removed. Use MiniKit.pay(), MiniKit.walletAuth(), etc. directly."
|
|
1982
|
+
);
|
|
1923
1983
|
}
|
|
1924
1984
|
};
|
|
1925
1985
|
_MiniKit.eventManager = new EventManager();
|
|
1926
|
-
|
|
1927
|
-
_MiniKit.
|
|
1928
|
-
_MiniKit.
|
|
1986
|
+
// State (was MiniKitState)
|
|
1987
|
+
_MiniKit._appId = null;
|
|
1988
|
+
_MiniKit._user = {};
|
|
1989
|
+
_MiniKit._deviceProperties = {};
|
|
1990
|
+
_MiniKit._location = null;
|
|
1991
|
+
_MiniKit._isReady = false;
|
|
1992
|
+
/**
|
|
1993
|
+
* Check if running inside World App
|
|
1994
|
+
*/
|
|
1995
|
+
_MiniKit.isInWorldApp = isInWorldApp;
|
|
1929
1996
|
// ============================================================================
|
|
1930
1997
|
// Utility Methods
|
|
1931
1998
|
// ============================================================================
|
|
1932
1999
|
_MiniKit.getUserByAddress = async (address) => {
|
|
1933
|
-
|
|
2000
|
+
const walletAddress = address ?? _MiniKit._user.walletAddress;
|
|
2001
|
+
const userProfile = await getUserProfile(walletAddress);
|
|
2002
|
+
return {
|
|
2003
|
+
walletAddress,
|
|
2004
|
+
username: userProfile.username,
|
|
2005
|
+
profilePictureUrl: userProfile.profile_picture_url
|
|
2006
|
+
};
|
|
1934
2007
|
};
|
|
1935
2008
|
_MiniKit.getUserByUsername = async (username) => {
|
|
1936
|
-
|
|
2009
|
+
const res = await fetch(
|
|
2010
|
+
`https://usernames.worldcoin.org/api/v1/${username}`,
|
|
2011
|
+
{
|
|
2012
|
+
method: "GET",
|
|
2013
|
+
headers: {
|
|
2014
|
+
"Content-Type": "application/json"
|
|
2015
|
+
}
|
|
2016
|
+
}
|
|
2017
|
+
);
|
|
2018
|
+
const user = await res.json();
|
|
2019
|
+
return {
|
|
2020
|
+
walletAddress: user.address,
|
|
2021
|
+
username: user.username,
|
|
2022
|
+
profilePictureUrl: user.profile_picture_url
|
|
2023
|
+
};
|
|
1937
2024
|
};
|
|
1938
2025
|
_MiniKit.getUserInfo = _MiniKit.getUserByAddress;
|
|
1939
2026
|
_MiniKit.getMiniAppUrl = (appId, path) => {
|
|
@@ -1964,132 +2051,261 @@ _MiniKit.showProfileCard = (username, walletAddress) => {
|
|
|
1964
2051
|
};
|
|
1965
2052
|
var MiniKit = _MiniKit;
|
|
1966
2053
|
|
|
1967
|
-
//
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
1987
|
-
|
|
1988
|
-
|
|
1989
|
-
|
|
1990
|
-
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2054
|
+
// src/provider.ts
|
|
2055
|
+
function _getAddress() {
|
|
2056
|
+
if (typeof window === "undefined") return void 0;
|
|
2057
|
+
return window.__worldapp_eip1193_address__;
|
|
2058
|
+
}
|
|
2059
|
+
function _setAddress(addr) {
|
|
2060
|
+
if (typeof window === "undefined") return;
|
|
2061
|
+
window.__worldapp_eip1193_address__ = addr;
|
|
2062
|
+
}
|
|
2063
|
+
function rpcError(code, message) {
|
|
2064
|
+
return Object.assign(new Error(message), { code });
|
|
2065
|
+
}
|
|
2066
|
+
function isHexString(value) {
|
|
2067
|
+
return /^0x[0-9a-fA-F]*$/.test(value);
|
|
2068
|
+
}
|
|
2069
|
+
function isAddressString(value) {
|
|
2070
|
+
return /^0x[0-9a-fA-F]{40}$/.test(value);
|
|
2071
|
+
}
|
|
2072
|
+
function decodeHexToUtf8(hex) {
|
|
2073
|
+
const raw = hex.slice(2);
|
|
2074
|
+
if (raw.length % 2 !== 0) {
|
|
2075
|
+
throw new Error("Invalid hex string length");
|
|
2076
|
+
}
|
|
2077
|
+
const bytes = new Uint8Array(raw.length / 2);
|
|
2078
|
+
for (let i = 0; i < raw.length; i += 2) {
|
|
2079
|
+
bytes[i / 2] = parseInt(raw.slice(i, i + 2), 16);
|
|
2080
|
+
}
|
|
2081
|
+
return new TextDecoder().decode(bytes);
|
|
2082
|
+
}
|
|
2083
|
+
function asArrayParams(params) {
|
|
2084
|
+
if (params === void 0) return [];
|
|
2085
|
+
return Array.isArray(params) ? params : [params];
|
|
2086
|
+
}
|
|
2087
|
+
function decodeMaybeHexMessage(value) {
|
|
2088
|
+
if (!isHexString(value)) {
|
|
2089
|
+
return value;
|
|
2090
|
+
}
|
|
2003
2091
|
try {
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2092
|
+
return decodeHexToUtf8(value);
|
|
2093
|
+
} catch {
|
|
2094
|
+
return value;
|
|
2095
|
+
}
|
|
2096
|
+
}
|
|
2097
|
+
function extractPersonalSignMessage(params) {
|
|
2098
|
+
const items = asArrayParams(params);
|
|
2099
|
+
if (items.length === 0) {
|
|
2100
|
+
throw new Error("Missing personal_sign params");
|
|
2101
|
+
}
|
|
2102
|
+
const [first, second] = items;
|
|
2103
|
+
const maybeMessage = typeof first === "string" && isAddressString(first) && typeof second === "string" ? second : first;
|
|
2104
|
+
if (typeof maybeMessage !== "string") {
|
|
2105
|
+
throw new Error("Invalid personal_sign message payload");
|
|
2106
|
+
}
|
|
2107
|
+
return decodeMaybeHexMessage(maybeMessage);
|
|
2108
|
+
}
|
|
2109
|
+
function extractEthSignMessage(params) {
|
|
2110
|
+
const items = asArrayParams(params);
|
|
2111
|
+
if (items.length === 0) {
|
|
2112
|
+
throw new Error("Missing eth_sign params");
|
|
2113
|
+
}
|
|
2114
|
+
const [first, second] = items;
|
|
2115
|
+
const maybeMessage = typeof second === "string" ? second : typeof first === "string" && !isAddressString(first) ? first : void 0;
|
|
2116
|
+
if (typeof maybeMessage !== "string") {
|
|
2117
|
+
throw new Error("Invalid eth_sign message payload");
|
|
2118
|
+
}
|
|
2119
|
+
return decodeMaybeHexMessage(maybeMessage);
|
|
2120
|
+
}
|
|
2121
|
+
function parseTypedDataInput(params) {
|
|
2122
|
+
const items = asArrayParams(params);
|
|
2123
|
+
const candidate = items.length > 1 ? items[1] : items[0];
|
|
2124
|
+
if (!candidate) {
|
|
2125
|
+
throw new Error("Missing typed data payload");
|
|
2126
|
+
}
|
|
2127
|
+
const parsed = typeof candidate === "string" ? JSON.parse(candidate) : candidate;
|
|
2128
|
+
if (!parsed || typeof parsed !== "object" || typeof parsed.primaryType !== "string" || typeof parsed.message !== "object" || !parsed.message || typeof parsed.types !== "object" || !parsed.types) {
|
|
2129
|
+
throw new Error("Invalid typed data payload");
|
|
2130
|
+
}
|
|
2131
|
+
const domainValue = parsed.domain;
|
|
2132
|
+
const chainIdValue = domainValue?.chainId ?? parsed.chainId;
|
|
2133
|
+
const parsedChainId = typeof chainIdValue === "string" ? Number(chainIdValue) : typeof chainIdValue === "number" ? chainIdValue : void 0;
|
|
2134
|
+
return {
|
|
2135
|
+
types: parsed.types,
|
|
2136
|
+
primaryType: parsed.primaryType,
|
|
2137
|
+
domain: domainValue,
|
|
2138
|
+
message: parsed.message,
|
|
2139
|
+
...Number.isFinite(parsedChainId) ? { chainId: parsedChainId } : {}
|
|
2140
|
+
};
|
|
2141
|
+
}
|
|
2142
|
+
function normalizeRpcValue(value) {
|
|
2143
|
+
if (value === void 0 || value === null) return void 0;
|
|
2144
|
+
if (typeof value === "string") return value;
|
|
2145
|
+
if (typeof value === "bigint") return `0x${value.toString(16)}`;
|
|
2146
|
+
if (typeof value === "number") return `0x${value.toString(16)}`;
|
|
2147
|
+
return String(value);
|
|
2148
|
+
}
|
|
2149
|
+
function extractTransactionParams(params) {
|
|
2150
|
+
const items = asArrayParams(params);
|
|
2151
|
+
const tx = items[0] ?? {};
|
|
2152
|
+
if (typeof tx.to !== "string" || !isAddressString(tx.to)) {
|
|
2153
|
+
throw new Error('Invalid transaction "to" address');
|
|
2154
|
+
}
|
|
2155
|
+
const chainId = typeof tx.chainId === "string" ? Number(tx.chainId) : typeof tx.chainId === "number" ? tx.chainId : void 0;
|
|
2156
|
+
const normalizedValue = normalizeRpcValue(tx.value);
|
|
2157
|
+
return {
|
|
2158
|
+
to: tx.to,
|
|
2159
|
+
...typeof tx.data === "string" ? { data: tx.data } : {},
|
|
2160
|
+
...normalizedValue !== void 0 ? { value: normalizedValue } : {},
|
|
2161
|
+
...Number.isFinite(chainId) ? { chainId } : {}
|
|
2162
|
+
};
|
|
2163
|
+
}
|
|
2164
|
+
function extractSwitchChainId(params) {
|
|
2165
|
+
const items = asArrayParams(params);
|
|
2166
|
+
const payload = items[0] ?? {};
|
|
2167
|
+
const rawChainId = payload.chainId;
|
|
2168
|
+
const chainId = typeof rawChainId === "string" ? Number(rawChainId) : typeof rawChainId === "number" ? rawChainId : NaN;
|
|
2169
|
+
if (!Number.isFinite(chainId)) {
|
|
2170
|
+
throw new Error("Invalid chainId for wallet_switchEthereumChain");
|
|
2171
|
+
}
|
|
2172
|
+
return chainId;
|
|
2173
|
+
}
|
|
2174
|
+
function createProvider() {
|
|
2175
|
+
const listeners = {};
|
|
2176
|
+
function emit(event, ...args) {
|
|
2177
|
+
listeners[event]?.forEach((fn) => fn(...args));
|
|
2178
|
+
}
|
|
2179
|
+
let authInFlight;
|
|
2180
|
+
async function doAuth() {
|
|
2181
|
+
if (!MiniKit.isInWorldApp()) {
|
|
2182
|
+
throw rpcError(4900, "World App provider only works inside World App");
|
|
2183
|
+
}
|
|
2184
|
+
try {
|
|
2185
|
+
const result = await MiniKit.walletAuth({
|
|
2186
|
+
nonce: crypto.randomUUID().replace(/-/g, ""),
|
|
2187
|
+
statement: "Sign in with World App"
|
|
2188
|
+
});
|
|
2189
|
+
const addr = result.data.address;
|
|
2190
|
+
_setAddress(addr);
|
|
2191
|
+
emit("accountsChanged", [addr]);
|
|
2192
|
+
return [addr];
|
|
2193
|
+
} catch (e) {
|
|
2194
|
+
throw rpcError(4001, `World App wallet auth failed: ${e.message}`);
|
|
2014
2195
|
}
|
|
2015
|
-
const currentTime = Math.floor(Date.now() / 1e3);
|
|
2016
|
-
return verifiedUntil > currentTime;
|
|
2017
|
-
} catch (error) {
|
|
2018
|
-
console.error("Error verifying user:", error);
|
|
2019
|
-
return false;
|
|
2020
2196
|
}
|
|
2021
|
-
|
|
2197
|
+
return {
|
|
2198
|
+
async request({ method, params }) {
|
|
2199
|
+
switch (method) {
|
|
2200
|
+
case "eth_requestAccounts": {
|
|
2201
|
+
const existing = _getAddress();
|
|
2202
|
+
if (existing) return [existing];
|
|
2203
|
+
if (!authInFlight) {
|
|
2204
|
+
authInFlight = doAuth().finally(() => {
|
|
2205
|
+
authInFlight = void 0;
|
|
2206
|
+
});
|
|
2207
|
+
}
|
|
2208
|
+
return authInFlight;
|
|
2209
|
+
}
|
|
2210
|
+
case "eth_accounts": {
|
|
2211
|
+
const addr = _getAddress();
|
|
2212
|
+
return addr ? [addr] : [];
|
|
2213
|
+
}
|
|
2214
|
+
case "eth_chainId":
|
|
2215
|
+
return "0x1e0";
|
|
2216
|
+
// 480 = World Chain
|
|
2217
|
+
case "personal_sign": {
|
|
2218
|
+
const message = extractPersonalSignMessage(params);
|
|
2219
|
+
try {
|
|
2220
|
+
const result = await MiniKit.signMessage({ message });
|
|
2221
|
+
return result.data.signature;
|
|
2222
|
+
} catch (e) {
|
|
2223
|
+
throw rpcError(4001, `Sign message failed: ${e.message}`);
|
|
2224
|
+
}
|
|
2225
|
+
}
|
|
2226
|
+
case "eth_sign": {
|
|
2227
|
+
const message = extractEthSignMessage(params);
|
|
2228
|
+
try {
|
|
2229
|
+
const result = await MiniKit.signMessage({ message });
|
|
2230
|
+
return result.data.signature;
|
|
2231
|
+
} catch (e) {
|
|
2232
|
+
throw rpcError(4001, `Sign message failed: ${e.message}`);
|
|
2233
|
+
}
|
|
2234
|
+
}
|
|
2235
|
+
case "eth_signTypedData":
|
|
2236
|
+
case "eth_signTypedData_v3":
|
|
2237
|
+
case "eth_signTypedData_v4": {
|
|
2238
|
+
try {
|
|
2239
|
+
const typedData = parseTypedDataInput(params);
|
|
2240
|
+
const result = await MiniKit.signTypedData({
|
|
2241
|
+
types: typedData.types,
|
|
2242
|
+
primaryType: typedData.primaryType,
|
|
2243
|
+
domain: typedData.domain,
|
|
2244
|
+
message: typedData.message,
|
|
2245
|
+
chainId: typedData.chainId
|
|
2246
|
+
});
|
|
2247
|
+
if (result.data.status === "error") {
|
|
2248
|
+
throw rpcError(
|
|
2249
|
+
4001,
|
|
2250
|
+
`Sign typed data failed: ${result.data.error_code}`
|
|
2251
|
+
);
|
|
2252
|
+
}
|
|
2253
|
+
return result.data.signature;
|
|
2254
|
+
} catch (e) {
|
|
2255
|
+
throw rpcError(4001, `Sign typed data failed: ${e.message}`);
|
|
2256
|
+
}
|
|
2257
|
+
}
|
|
2258
|
+
case "eth_sendTransaction": {
|
|
2259
|
+
const tx = extractTransactionParams(params);
|
|
2260
|
+
try {
|
|
2261
|
+
const result = await MiniKit.sendTransaction({
|
|
2262
|
+
...tx.chainId !== void 0 ? { chainId: tx.chainId } : {},
|
|
2263
|
+
transaction: [
|
|
2264
|
+
{
|
|
2265
|
+
address: tx.to,
|
|
2266
|
+
...tx.data && tx.data !== "0x" ? { data: tx.data } : {},
|
|
2267
|
+
value: tx.value
|
|
2268
|
+
}
|
|
2269
|
+
]
|
|
2270
|
+
});
|
|
2271
|
+
return result.data.transactionId;
|
|
2272
|
+
} catch (e) {
|
|
2273
|
+
throw rpcError(4001, `Send transaction failed: ${e.message}`);
|
|
2274
|
+
}
|
|
2275
|
+
}
|
|
2276
|
+
case "wallet_switchEthereumChain": {
|
|
2277
|
+
const chainId = extractSwitchChainId(params);
|
|
2278
|
+
if (chainId !== 480) {
|
|
2279
|
+
throw rpcError(4902, "World App only supports World Chain (480)");
|
|
2280
|
+
}
|
|
2281
|
+
return null;
|
|
2282
|
+
}
|
|
2283
|
+
case "wallet_addEthereumChain": {
|
|
2284
|
+
throw rpcError(4200, "World App only supports World Chain (480)");
|
|
2285
|
+
}
|
|
2286
|
+
default:
|
|
2287
|
+
throw rpcError(4200, `Unsupported method: ${method}`);
|
|
2288
|
+
}
|
|
2289
|
+
},
|
|
2290
|
+
on(event, fn) {
|
|
2291
|
+
(listeners[event] ?? (listeners[event] = /* @__PURE__ */ new Set())).add(fn);
|
|
2292
|
+
},
|
|
2293
|
+
removeListener(event, fn) {
|
|
2294
|
+
listeners[event]?.delete(fn);
|
|
2295
|
+
}
|
|
2296
|
+
};
|
|
2297
|
+
}
|
|
2298
|
+
function getWorldAppProvider() {
|
|
2299
|
+
if (typeof window === "undefined") {
|
|
2300
|
+
return createProvider();
|
|
2301
|
+
}
|
|
2302
|
+
if (!window.__worldapp_eip1193_provider__) {
|
|
2303
|
+
window.__worldapp_eip1193_provider__ = createProvider();
|
|
2304
|
+
}
|
|
2305
|
+
return window.__worldapp_eip1193_provider__;
|
|
2306
|
+
}
|
|
2022
2307
|
// Annotate the CommonJS export names for ESM import in node:
|
|
2023
2308
|
0 && (module.exports = {
|
|
2024
|
-
COMMAND_VERSIONS,
|
|
2025
|
-
ChatErrorCodes,
|
|
2026
|
-
ChatErrorMessage,
|
|
2027
|
-
Command,
|
|
2028
|
-
GetPermissionsErrorCodes,
|
|
2029
|
-
GetPermissionsErrorMessage,
|
|
2030
|
-
MiniAppLaunchLocation,
|
|
2031
2309
|
MiniKit,
|
|
2032
|
-
|
|
2033
|
-
MiniKitInstallErrorMessage,
|
|
2034
|
-
Network,
|
|
2035
|
-
PaymentErrorCodes,
|
|
2036
|
-
PaymentErrorMessage,
|
|
2037
|
-
Permission,
|
|
2038
|
-
RequestPermissionErrorCodes,
|
|
2039
|
-
RequestPermissionErrorMessage,
|
|
2040
|
-
ResponseEvent,
|
|
2041
|
-
SendHapticFeedbackErrorCodes,
|
|
2042
|
-
SendHapticFeedbackErrorMessage,
|
|
2043
|
-
SendTransactionErrorCodes,
|
|
2044
|
-
SendTransactionErrorMessage,
|
|
2045
|
-
ShareContactsErrorCodes,
|
|
2046
|
-
ShareContactsErrorMessage,
|
|
2047
|
-
ShareFilesErrorCodes,
|
|
2048
|
-
ShareFilesErrorMessage,
|
|
2049
|
-
SignMessageErrorCodes,
|
|
2050
|
-
SignMessageErrorMessage,
|
|
2051
|
-
SignTypedDataErrorCodes,
|
|
2052
|
-
SignTypedDataErrorMessage,
|
|
2053
|
-
TokenDecimals,
|
|
2054
|
-
Tokens,
|
|
2055
|
-
VerificationErrorCodes,
|
|
2056
|
-
VerificationLevel,
|
|
2057
|
-
WalletAuthErrorCodes,
|
|
2058
|
-
WalletAuthErrorMessage,
|
|
2059
|
-
createAsyncCommands,
|
|
2060
|
-
createChatAsyncCommand,
|
|
2061
|
-
createChatCommand,
|
|
2062
|
-
createCommands,
|
|
2063
|
-
createGetPermissionsAsyncCommand,
|
|
2064
|
-
createGetPermissionsCommand,
|
|
2065
|
-
createPayAsyncCommand,
|
|
2066
|
-
createPayCommand,
|
|
2067
|
-
createRequestPermissionAsyncCommand,
|
|
2068
|
-
createRequestPermissionCommand,
|
|
2069
|
-
createSendHapticFeedbackAsyncCommand,
|
|
2070
|
-
createSendHapticFeedbackCommand,
|
|
2071
|
-
createSendTransactionAsyncCommand,
|
|
2072
|
-
createSendTransactionCommand,
|
|
2073
|
-
createShareAsyncCommand,
|
|
2074
|
-
createShareCommand,
|
|
2075
|
-
createShareContactsAsyncCommand,
|
|
2076
|
-
createShareContactsCommand,
|
|
2077
|
-
createSignMessageAsyncCommand,
|
|
2078
|
-
createSignMessageCommand,
|
|
2079
|
-
createSignTypedDataAsyncCommand,
|
|
2080
|
-
createSignTypedDataCommand,
|
|
2081
|
-
createVerifyAsyncCommand,
|
|
2082
|
-
createVerifyCommand,
|
|
2083
|
-
createWalletAuthAsyncCommand,
|
|
2084
|
-
createWalletAuthCommand,
|
|
2085
|
-
getIsUserVerified,
|
|
2086
|
-
isCommandAvailable,
|
|
2087
|
-
mapWorldAppLaunchLocation,
|
|
2088
|
-
parseSiweMessage,
|
|
2089
|
-
sendMiniKitEvent,
|
|
2090
|
-
setCommandAvailable,
|
|
2091
|
-
tokenToDecimals,
|
|
2092
|
-
validateCommands,
|
|
2093
|
-
verifyCloudProof,
|
|
2094
|
-
verifySiweMessage
|
|
2310
|
+
getWorldAppProvider
|
|
2095
2311
|
});
|