@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.
Files changed (39) hide show
  1. package/README.md +107 -0
  2. package/build/address-book.cjs +81 -0
  3. package/build/address-book.d.cts +3 -0
  4. package/build/address-book.d.ts +3 -0
  5. package/build/address-book.js +54 -0
  6. package/build/chunk-2UPJKPQ6.js +272 -0
  7. package/build/chunk-EHBM7OXH.js +596 -0
  8. package/build/chunk-LHHKY77D.js +274 -0
  9. package/build/chunk-TGXD24YD.js +279 -0
  10. package/build/chunk-Z2UGRZJ2.js +1635 -0
  11. package/build/command-exports.cjs +1762 -0
  12. package/build/command-exports.d.cts +105 -0
  13. package/build/command-exports.d.ts +105 -0
  14. package/build/command-exports.js +129 -0
  15. package/build/connector/index.cjs +2601 -0
  16. package/build/connector/index.d.cts +55 -0
  17. package/build/connector/index.d.ts +55 -0
  18. package/build/connector/index.js +90 -0
  19. package/build/index.cjs +1634 -1627
  20. package/build/index.d.cts +143 -671
  21. package/build/index.d.ts +143 -671
  22. package/build/index.js +7 -206
  23. package/build/minikit-provider.cjs +1650 -948
  24. package/build/minikit-provider.d.cts +2 -1
  25. package/build/minikit-provider.d.ts +2 -1
  26. package/build/minikit-provider.js +13 -2
  27. package/build/provider-DeDUsLbs.d.cts +43 -0
  28. package/build/provider-DeDUsLbs.d.ts +43 -0
  29. package/build/siwe-exports.cjs +249 -0
  30. package/build/siwe-exports.d.cts +10 -0
  31. package/build/siwe-exports.d.ts +10 -0
  32. package/build/siwe-exports.js +8 -0
  33. package/build/types-CC2x79HX.d.ts +525 -0
  34. package/build/types-CSyzFDPt.d.cts +223 -0
  35. package/build/types-CSyzFDPt.d.ts +223 -0
  36. package/build/types-_jfLbcJW.d.cts +525 -0
  37. package/package.json +73 -11
  38. package/build/chunk-62NZ34E4.js +0 -2092
  39. package/index.ts +0 -29
package/README.md CHANGED
@@ -10,6 +10,113 @@ or use the CDN:
10
10
 
11
11
  For comprehensive setup instructions and usage examples, visit our [developer documentation](https://docs.world.org/mini-apps).
12
12
 
13
+ ## Scope
14
+
15
+ `@worldcoin/minikit-js` is the mini-app command SDK:
16
+
17
+ - `MiniKit.walletAuth()`
18
+ - `MiniKit.sendTransaction()`
19
+ - `MiniKit.pay()`
20
+ - `MiniKit.shareContacts()`
21
+ - `MiniKit.signMessage()`
22
+ - `MiniKit.signTypedData()`
23
+ - and related mini-app commands
24
+
25
+ World ID verification belongs to IDKit:
26
+
27
+ - Use `@worldcoin/idkit` for verification requests and widget UI
28
+ - Use `@worldcoin/idkit-core` for backend signing helpers such as `signRequest`
29
+
30
+ ## v2 -> v3 Migration Highlights
31
+
32
+ - `MiniKit.commands.*` / `MiniKit.commandsAsync.*` are removed. Use `await MiniKit.<command>(...)`.
33
+ - Command responses now use `{ executedWith, data }`.
34
+ - Verify flows moved to IDKit (`@worldcoin/idkit`), not MiniKit.
35
+ - `walletAuth` nonce validation is stricter (alphanumeric SIWE nonce).
36
+ - Tree-shakeable subpath exports are available for commands and helpers.
37
+
38
+ ### `sendTransaction` uses one flexible transaction type
39
+
40
+ When `transaction[i].data` is provided, MiniKit prioritizes raw calldata over
41
+ `abi` / `functionName` / `args`.
42
+
43
+ Example:
44
+
45
+ ```ts
46
+ await MiniKit.sendTransaction({
47
+ transaction: [
48
+ {
49
+ address: tokenAddress,
50
+ data: '0xa9059cbb...', // takes priority when present
51
+ abi: erc20Abi,
52
+ functionName: 'transfer',
53
+ args: [to, amount],
54
+ },
55
+ ],
56
+ });
57
+ ```
58
+
59
+ Type shape:
60
+
61
+ ```ts
62
+ type Transaction = {
63
+ address: string;
64
+ value?: string;
65
+ data?: string;
66
+ abi?: Abi | readonly unknown[];
67
+ functionName?: ContractFunctionName<...>;
68
+ args?: ContractFunctionArgs<...>;
69
+ };
70
+
71
+ interface MiniKitSendTransactionOptions<TCustomFallback = SendTransactionResult> {
72
+ transaction: Transaction[];
73
+ chainId?: number; // defaults to 480 on World App
74
+ permit2?: Permit2[];
75
+ formatPayload?: boolean;
76
+ }
77
+ ```
78
+
79
+ ### Tree-shakeable subpath exports
80
+
81
+ Use subpaths to import only what you need:
82
+
83
+ ```ts
84
+ import {
85
+ MiniKitSendTransactionOptions,
86
+ SendTransactionErrorCodes,
87
+ } from '@worldcoin/minikit-js/commands';
88
+ import { getIsUserVerified } from '@worldcoin/minikit-js/address-book';
89
+ import {
90
+ parseSiweMessage,
91
+ verifySiweMessage,
92
+ } from '@worldcoin/minikit-js/siwe';
93
+ ```
94
+
95
+ You can still import `MiniKit` itself from the package root:
96
+
97
+ ```ts
98
+ import { MiniKit } from '@worldcoin/minikit-js';
99
+ ```
100
+
101
+ ### Commands now support custom fallbacks
102
+
103
+ Use `fallback` to run equivalent logic outside World App:
104
+
105
+ ```ts
106
+ const result = await MiniKit.sendHapticFeedback({
107
+ hapticsType: 'impact',
108
+ style: 'light',
109
+ fallback: () => {
110
+ navigator.vibrate?.(20);
111
+ return {
112
+ status: 'success',
113
+ version: 1,
114
+ timestamp: new Date().toISOString(),
115
+ };
116
+ },
117
+ });
118
+ ```
119
+
13
120
  ## 🛠 ️Developing Locally
14
121
 
15
122
  To run the example mini app locally:
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/address-book.ts
21
+ var address_book_exports = {};
22
+ __export(address_book_exports, {
23
+ getIsUserVerified: () => getIsUserVerified
24
+ });
25
+ module.exports = __toCommonJS(address_book_exports);
26
+
27
+ // src/helpers/address-book.ts
28
+ var import_viem = require("viem");
29
+ var import_chains = require("viem/chains");
30
+ var worldIdAddressBookContractAddress = "0x57b930D551e677CC36e2fA036Ae2fe8FdaE0330D";
31
+ var addressVerifiedUntilAbi = [
32
+ {
33
+ inputs: [
34
+ {
35
+ internalType: "address",
36
+ name: "",
37
+ type: "address"
38
+ }
39
+ ],
40
+ name: "addressVerifiedUntil",
41
+ outputs: [
42
+ {
43
+ internalType: "uint256",
44
+ name: "",
45
+ type: "uint256"
46
+ }
47
+ ],
48
+ stateMutability: "view",
49
+ type: "function"
50
+ }
51
+ ];
52
+ var getIsUserVerified = async (walletAddress, rpcUrl) => {
53
+ const publicClient = (0, import_viem.createPublicClient)({
54
+ chain: import_chains.worldchain,
55
+ transport: (0, import_viem.http)(
56
+ rpcUrl || "https://worldchain-mainnet.g.alchemy.com/public"
57
+ )
58
+ });
59
+ try {
60
+ const verifiedUntilResponse = await publicClient.readContract({
61
+ address: worldIdAddressBookContractAddress,
62
+ abi: addressVerifiedUntilAbi,
63
+ functionName: "addressVerifiedUntil",
64
+ args: [walletAddress]
65
+ });
66
+ const verifiedUntil = Number(verifiedUntilResponse.toString());
67
+ if (!Number.isFinite(verifiedUntil)) {
68
+ console.warn("Invalid verifiedUntil value:", verifiedUntil);
69
+ return false;
70
+ }
71
+ const currentTime = Math.floor(Date.now() / 1e3);
72
+ return verifiedUntil > currentTime;
73
+ } catch (error) {
74
+ console.error("Error verifying user:", error);
75
+ return false;
76
+ }
77
+ };
78
+ // Annotate the CommonJS export names for ESM import in node:
79
+ 0 && (module.exports = {
80
+ getIsUserVerified
81
+ });
@@ -0,0 +1,3 @@
1
+ declare const getIsUserVerified: (walletAddress: string, rpcUrl?: string) => Promise<boolean>;
2
+
3
+ export { getIsUserVerified };
@@ -0,0 +1,3 @@
1
+ declare const getIsUserVerified: (walletAddress: string, rpcUrl?: string) => Promise<boolean>;
2
+
3
+ export { getIsUserVerified };
@@ -0,0 +1,54 @@
1
+ // src/helpers/address-book.ts
2
+ import { createPublicClient, http } from "viem";
3
+ import { worldchain } from "viem/chains";
4
+ var worldIdAddressBookContractAddress = "0x57b930D551e677CC36e2fA036Ae2fe8FdaE0330D";
5
+ var addressVerifiedUntilAbi = [
6
+ {
7
+ inputs: [
8
+ {
9
+ internalType: "address",
10
+ name: "",
11
+ type: "address"
12
+ }
13
+ ],
14
+ name: "addressVerifiedUntil",
15
+ outputs: [
16
+ {
17
+ internalType: "uint256",
18
+ name: "",
19
+ type: "uint256"
20
+ }
21
+ ],
22
+ stateMutability: "view",
23
+ type: "function"
24
+ }
25
+ ];
26
+ var getIsUserVerified = async (walletAddress, rpcUrl) => {
27
+ const publicClient = createPublicClient({
28
+ chain: worldchain,
29
+ transport: http(
30
+ rpcUrl || "https://worldchain-mainnet.g.alchemy.com/public"
31
+ )
32
+ });
33
+ try {
34
+ const verifiedUntilResponse = await publicClient.readContract({
35
+ address: worldIdAddressBookContractAddress,
36
+ abi: addressVerifiedUntilAbi,
37
+ functionName: "addressVerifiedUntil",
38
+ args: [walletAddress]
39
+ });
40
+ const verifiedUntil = Number(verifiedUntilResponse.toString());
41
+ if (!Number.isFinite(verifiedUntil)) {
42
+ console.warn("Invalid verifiedUntil value:", verifiedUntil);
43
+ return false;
44
+ }
45
+ const currentTime = Math.floor(Date.now() / 1e3);
46
+ return verifiedUntil > currentTime;
47
+ } catch (error) {
48
+ console.error("Error verifying user:", error);
49
+ return false;
50
+ }
51
+ };
52
+ export {
53
+ getIsUserVerified
54
+ };
@@ -0,0 +1,272 @@
1
+ import {
2
+ setFallbackAdapter
3
+ } from "./chunk-Z2UGRZJ2.js";
4
+
5
+ // src/commands/wagmi-fallback.ts
6
+ var SIWE_NONCE_REGEX = /^[a-zA-Z0-9]{8,}$/;
7
+ var WAGMI_KEY = "__minikit_wagmi_config__";
8
+ function setWagmiConfig(config) {
9
+ globalThis[WAGMI_KEY] = config;
10
+ registerWagmiFallbacks();
11
+ }
12
+ function getWagmiConfig() {
13
+ return globalThis[WAGMI_KEY];
14
+ }
15
+ function hasWagmiConfig() {
16
+ return globalThis[WAGMI_KEY] !== void 0;
17
+ }
18
+ function registerWagmiFallbacks() {
19
+ setFallbackAdapter({
20
+ walletAuth: wagmiWalletAuth,
21
+ signMessage: wagmiSignMessage,
22
+ signTypedData: wagmiSignTypedData,
23
+ sendTransaction: wagmiSendTransaction
24
+ });
25
+ }
26
+ async function loadWagmiActions() {
27
+ console.log("[MiniKit WagmiFallback] loadWagmiActions:start", {
28
+ hasWindow: typeof window !== "undefined",
29
+ hasWagmiConfig: hasWagmiConfig()
30
+ });
31
+ try {
32
+ const actions = await import(
33
+ /* webpackIgnore: true */
34
+ "wagmi/actions"
35
+ );
36
+ console.log("[MiniKit WagmiFallback] loadWagmiActions:success");
37
+ return actions;
38
+ } catch (error) {
39
+ console.log("[MiniKit WagmiFallback] loadWagmiActions:error", {
40
+ message: error instanceof Error ? error.message : String(error)
41
+ });
42
+ const wrappedError = new Error(
43
+ 'Wagmi fallback requires the "wagmi" package. Install wagmi or provide a custom fallback.'
44
+ );
45
+ wrappedError.cause = error;
46
+ throw wrappedError;
47
+ }
48
+ }
49
+ async function loadSiwe() {
50
+ try {
51
+ return await import(
52
+ /* webpackIgnore: true */
53
+ "siwe"
54
+ );
55
+ } catch (error) {
56
+ const wrappedError = new Error(
57
+ 'Wagmi walletAuth fallback requires the "siwe" package. Install siwe or provide a custom fallback.'
58
+ );
59
+ wrappedError.cause = error;
60
+ throw wrappedError;
61
+ }
62
+ }
63
+ async function checksumAddress(addr) {
64
+ try {
65
+ const { getAddress } = await import(
66
+ /* webpackIgnore: true */
67
+ "viem"
68
+ );
69
+ return getAddress(addr);
70
+ } catch {
71
+ return addr;
72
+ }
73
+ }
74
+ async function ensureConnected(config) {
75
+ const { connect, getConnections } = await loadWagmiActions();
76
+ const isWorldApp = typeof window !== "undefined" && Boolean(window.WorldApp);
77
+ const existingConnection = getConnections(config).find(
78
+ (connection) => connection.accounts && connection.accounts.length > 0 && (isWorldApp || connection.connector?.id !== "worldApp")
79
+ );
80
+ if (existingConnection && existingConnection.accounts) {
81
+ return checksumAddress(existingConnection.accounts[0]);
82
+ }
83
+ const connectors = config.connectors;
84
+ if (!connectors || connectors.length === 0) {
85
+ throw new Error("No Wagmi connectors configured");
86
+ }
87
+ const candidateConnectors = isWorldApp ? connectors : connectors.filter(
88
+ (connector) => connector.id !== "worldApp"
89
+ );
90
+ if (!isWorldApp && candidateConnectors.length === 0) {
91
+ throw new Error(
92
+ "No web Wagmi connectors configured. Add a web connector (e.g. injected or walletConnect) after worldApp()."
93
+ );
94
+ }
95
+ const selectedConnector = candidateConnectors[0];
96
+ try {
97
+ const result = await connect(config, { connector: selectedConnector });
98
+ if (result.accounts.length > 0) {
99
+ const account = result.accounts[0];
100
+ const address = typeof account === "string" ? account : account.address;
101
+ if (address) {
102
+ return checksumAddress(address);
103
+ }
104
+ }
105
+ } catch (error) {
106
+ const connectorId = selectedConnector.id ?? "unknown";
107
+ const wrappedError = new Error(
108
+ `Failed to connect with connector "${connectorId}". Reorder connectors to change the default connector.`
109
+ );
110
+ wrappedError.cause = error;
111
+ throw wrappedError;
112
+ }
113
+ throw new Error("Failed to connect wallet");
114
+ }
115
+ async function wagmiWalletAuth(params) {
116
+ console.log("[MiniKit WagmiFallback] walletAuth:start", {
117
+ hasWagmiConfig: hasWagmiConfig(),
118
+ nonceLength: params.nonce?.length ?? 0
119
+ });
120
+ const config = getWagmiConfig();
121
+ if (!config) {
122
+ console.log("[MiniKit WagmiFallback] walletAuth:error:no-config");
123
+ throw new Error(
124
+ "Wagmi config not available. Pass wagmiConfig to MiniKitProvider."
125
+ );
126
+ }
127
+ const { signMessage } = await loadWagmiActions();
128
+ const { SiweMessage } = await loadSiwe();
129
+ const address = await ensureConnected(config);
130
+ if (!SIWE_NONCE_REGEX.test(params.nonce)) {
131
+ throw new Error(
132
+ "Invalid nonce: must be alphanumeric and at least 8 characters (EIP-4361)"
133
+ );
134
+ }
135
+ const siweMessage = new SiweMessage({
136
+ domain: typeof window !== "undefined" ? window.location.host : "localhost",
137
+ address,
138
+ statement: params.statement,
139
+ uri: typeof window !== "undefined" ? window.location.origin : "http://localhost",
140
+ version: "1",
141
+ chainId: 480,
142
+ // World Chain
143
+ nonce: params.nonce,
144
+ expirationTime: params.expirationTime?.toISOString()
145
+ });
146
+ const message = siweMessage.prepareMessage();
147
+ const signature = await signMessage(config, { message });
148
+ return {
149
+ address,
150
+ message,
151
+ signature
152
+ };
153
+ }
154
+ async function wagmiSignMessage(params) {
155
+ console.log("[MiniKit WagmiFallback] signMessage:start", {
156
+ hasWagmiConfig: hasWagmiConfig()
157
+ });
158
+ const config = getWagmiConfig();
159
+ if (!config) {
160
+ console.log("[MiniKit WagmiFallback] signMessage:error:no-config");
161
+ throw new Error(
162
+ "Wagmi config not available. Pass wagmiConfig to MiniKitProvider."
163
+ );
164
+ }
165
+ const { signMessage } = await loadWagmiActions();
166
+ const address = await ensureConnected(config);
167
+ const signature = await signMessage(config, {
168
+ account: address,
169
+ message: params.message
170
+ });
171
+ return {
172
+ status: "success",
173
+ version: 1,
174
+ signature,
175
+ address
176
+ };
177
+ }
178
+ async function wagmiSignTypedData(params) {
179
+ console.log("[MiniKit WagmiFallback] signTypedData:start", {
180
+ hasWagmiConfig: hasWagmiConfig(),
181
+ hasChainId: params.chainId !== void 0
182
+ });
183
+ const config = getWagmiConfig();
184
+ if (!config) {
185
+ console.log("[MiniKit WagmiFallback] signTypedData:error:no-config");
186
+ throw new Error(
187
+ "Wagmi config not available. Pass wagmiConfig to MiniKitProvider."
188
+ );
189
+ }
190
+ const { getChainId, signTypedData, switchChain } = await loadWagmiActions();
191
+ const address = await ensureConnected(config);
192
+ if (params.chainId !== void 0) {
193
+ const currentChainId = await getChainId(config);
194
+ if (currentChainId !== params.chainId) {
195
+ await switchChain(config, { chainId: params.chainId });
196
+ }
197
+ }
198
+ const signature = await signTypedData(config, {
199
+ account: address,
200
+ types: params.types,
201
+ primaryType: params.primaryType,
202
+ domain: params.domain,
203
+ message: params.message
204
+ });
205
+ return {
206
+ status: "success",
207
+ version: 1,
208
+ signature,
209
+ address
210
+ };
211
+ }
212
+ function isChainMismatchError(error) {
213
+ const message = error instanceof Error ? error.message : String(error);
214
+ return message.includes("does not match the target chain");
215
+ }
216
+ async function wagmiSendTransaction(params) {
217
+ console.log("[MiniKit WagmiFallback] sendTransaction:start", {
218
+ hasWagmiConfig: hasWagmiConfig(),
219
+ chainId: params.chainId,
220
+ hasData: Boolean(params.transaction.data)
221
+ });
222
+ const config = getWagmiConfig();
223
+ if (!config) {
224
+ console.log("[MiniKit WagmiFallback] sendTransaction:error:no-config");
225
+ throw new Error(
226
+ "Wagmi config not available. Pass wagmiConfig to MiniKitProvider."
227
+ );
228
+ }
229
+ const { getChainId, getWalletClient, sendTransaction, switchChain } = await loadWagmiActions();
230
+ await ensureConnected(config);
231
+ const targetChainId = params.chainId ?? config.chains?.[0]?.id;
232
+ const ensureTargetChain = async () => {
233
+ if (targetChainId === void 0) return;
234
+ const currentChainId = await getChainId(config);
235
+ if (currentChainId !== targetChainId) {
236
+ await switchChain(config, { chainId: targetChainId });
237
+ }
238
+ const walletClient = await getWalletClient(config);
239
+ const providerChainId = walletClient ? await walletClient.getChainId() : await getChainId(config);
240
+ if (providerChainId !== targetChainId) {
241
+ throw new Error(
242
+ `Wallet network mismatch: expected chain ${targetChainId}, got ${providerChainId}. Please switch networks in your wallet and retry.`
243
+ );
244
+ }
245
+ };
246
+ await ensureTargetChain();
247
+ let transactionHash;
248
+ try {
249
+ transactionHash = await sendTransaction(config, {
250
+ chainId: targetChainId,
251
+ to: params.transaction.address,
252
+ data: params.transaction.data,
253
+ value: params.transaction.value ? BigInt(params.transaction.value) : void 0
254
+ });
255
+ } catch (error) {
256
+ if (targetChainId === void 0 || !isChainMismatchError(error)) {
257
+ throw error;
258
+ }
259
+ await ensureTargetChain();
260
+ transactionHash = await sendTransaction(config, {
261
+ chainId: targetChainId,
262
+ to: params.transaction.address,
263
+ data: params.transaction.data,
264
+ value: params.transaction.value ? BigInt(params.transaction.value) : void 0
265
+ });
266
+ }
267
+ return { transactionHash };
268
+ }
269
+
270
+ export {
271
+ setWagmiConfig
272
+ };