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