@worldcoin/minikit-js 2.0.0-dev.1 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  setFallbackAdapter
3
- } from "./chunk-Z2UGRZJ2.js";
3
+ } from "./chunk-XHYUUG6Y.js";
4
4
 
5
5
  // src/commands/wagmi-fallback.ts
6
6
  var SIWE_NONCE_REGEX = /^[a-zA-Z0-9]{8,}$/;
@@ -3,8 +3,7 @@ import {
3
3
  createPublicClient,
4
4
  getContract,
5
5
  hashMessage,
6
- http,
7
- recoverAddress
6
+ http
8
7
  } from "viem";
9
8
  import { worldchain } from "viem/chains";
10
9
  var PREAMBLE = " wants you to sign in with your Ethereum account:";
@@ -16,7 +15,6 @@ var IAT_TAG = "Issued At: ";
16
15
  var EXP_TAG = "Expiration Time: ";
17
16
  var NBF_TAG = "Not Before: ";
18
17
  var RID_TAG = "Request ID: ";
19
- var ERC_191_PREFIX = "Ethereum Signed Message:\n";
20
18
  var EIP1271_MAGICVALUE = "0x1626ba7e";
21
19
  var SAFE_CONTRACT_ABI = [
22
20
  {
@@ -160,14 +158,8 @@ var generateSiweMessage = (siweMessageData) => {
160
158
  return siweMessage;
161
159
  };
162
160
  var verifySiweMessage = (payload, nonce, statement, requestId, userProvider) => {
163
- if (payload.version === 1) {
164
- return verifySiweMessageV1(
165
- payload,
166
- nonce,
167
- statement,
168
- requestId,
169
- userProvider
170
- );
161
+ if (payload.version !== 2) {
162
+ throw new Error("Unsupported version returned");
171
163
  } else {
172
164
  return verifySiweMessageV2(
173
165
  payload,
@@ -208,39 +200,14 @@ var validateMessage = (siweMessageData, nonce, statement, requestId) => {
208
200
  }
209
201
  return true;
210
202
  };
211
- var verifySiweMessageV1 = async (payload, nonce, statement, requestId, userProvider) => {
212
- if (typeof window !== "undefined") {
213
- throw new Error("Wallet auth payload can only be verified in the backend");
214
- }
215
- const { message, signature, address } = payload;
216
- const siweMessageData = parseSiweMessage(message);
217
- validateMessage(siweMessageData, nonce, statement, requestId);
218
- let provider = userProvider || createPublicClient({ chain: worldchain, transport: http() });
219
- const signedMessage = `${ERC_191_PREFIX}${message.length}${message}`;
220
- const hashedMessage = hashMessage(signedMessage);
221
- const contract = getContract({
222
- address,
223
- abi: SAFE_CONTRACT_ABI,
224
- client: provider
225
- });
226
- try {
227
- const recoveredAddress = await recoverAddress({
228
- hash: hashedMessage,
229
- signature: `0x${signature}`
230
- });
231
- const isOwner = await contract.read.isOwner([recoveredAddress]);
232
- if (!isOwner) {
233
- throw new Error("Signature verification failed, invalid owner");
234
- }
235
- } catch (error) {
236
- throw new Error("Signature verification failed");
237
- }
238
- return { isValid: true, siweMessageData };
239
- };
240
203
  var verifySiweMessageV2 = async (payload, nonce, statement, requestId, userProvider) => {
241
204
  if (typeof window !== "undefined") {
242
205
  throw new Error("Wallet auth payload can only be verified in the backend");
243
206
  }
207
+ const NONCE_REGEX = /^[a-zA-Z0-9]+$/;
208
+ if (!NONCE_REGEX.test(nonce)) {
209
+ throw new Error("Invalid nonce: must be alphanumeric only (per ERC-4361)");
210
+ }
244
211
  const { message, signature, address } = payload;
245
212
  const siweMessageData = parseSiweMessage(message);
246
213
  if (!validateMessage(siweMessageData, nonce, statement, requestId)) {
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  MiniKit
3
- } from "./chunk-EHBM7OXH.js";
3
+ } from "./chunk-QOLIACKU.js";
4
4
 
5
5
  // src/provider.ts
6
6
  import { getAddress } from "viem";
@@ -17,7 +17,7 @@ import {
17
17
  signTypedData,
18
18
  validateCommands,
19
19
  walletAuth
20
- } from "./chunk-Z2UGRZJ2.js";
20
+ } from "./chunk-XHYUUG6Y.js";
21
21
 
22
22
  // src/helpers/microphone.ts
23
23
  var microphoneSetupDone = false;
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  generateSiweMessage
3
- } from "./chunk-LHHKY77D.js";
3
+ } from "./chunk-IYL4VCWR.js";
4
4
 
5
5
  // src/commands/types.ts
6
6
  var Command = /* @__PURE__ */ ((Command2) => {
@@ -1514,7 +1514,11 @@ async function nativeWalletAuth(options, ctx) {
1514
1514
  });
1515
1515
  const walletAuthPayload = { siweMessage };
1516
1516
  const worldAppVersion = ctx.state.deviceProperties.worldAppVersion;
1517
- const walletAuthVersion = worldAppVersion && worldAppVersion > 2087900 ? COMMAND_VERSIONS["wallet-auth" /* WalletAuth */] : 1;
1517
+ if (worldAppVersion && worldAppVersion <= 2087900) {
1518
+ throw new Error(
1519
+ "Wallet auth v1 is no longer supported. Please update World App to the latest version."
1520
+ );
1521
+ }
1518
1522
  const finalPayload = await new Promise(
1519
1523
  (resolve, reject) => {
1520
1524
  try {
@@ -1524,7 +1528,7 @@ async function nativeWalletAuth(options, ctx) {
1524
1528
  });
1525
1529
  sendMiniKitEvent({
1526
1530
  command: "wallet-auth" /* WalletAuth */,
1527
- version: walletAuthVersion,
1531
+ version: COMMAND_VERSIONS["wallet-auth" /* WalletAuth */],
1528
1532
  payload: walletAuthPayload
1529
1533
  });
1530
1534
  } catch (error) {
@@ -1643,7 +1643,11 @@ async function nativeWalletAuth(options, ctx) {
1643
1643
  });
1644
1644
  const walletAuthPayload = { siweMessage };
1645
1645
  const worldAppVersion = ctx.state.deviceProperties.worldAppVersion;
1646
- const walletAuthVersion = worldAppVersion && worldAppVersion > 2087900 ? COMMAND_VERSIONS["wallet-auth" /* WalletAuth */] : 1;
1646
+ if (worldAppVersion && worldAppVersion <= 2087900) {
1647
+ throw new Error(
1648
+ "Wallet auth v1 is no longer supported. Please update World App to the latest version."
1649
+ );
1650
+ }
1647
1651
  const finalPayload = await new Promise(
1648
1652
  (resolve, reject) => {
1649
1653
  try {
@@ -1653,7 +1657,7 @@ async function nativeWalletAuth(options, ctx) {
1653
1657
  });
1654
1658
  sendMiniKitEvent({
1655
1659
  command: "wallet-auth" /* WalletAuth */,
1656
- version: walletAuthVersion,
1660
+ version: COMMAND_VERSIONS["wallet-auth" /* WalletAuth */],
1657
1661
  payload: walletAuthPayload
1658
1662
  });
1659
1663
  } catch (error) {
@@ -61,8 +61,8 @@ import {
61
61
  tokenToDecimals,
62
62
  validateCommands,
63
63
  walletAuth
64
- } from "./chunk-Z2UGRZJ2.js";
65
- import "./chunk-LHHKY77D.js";
64
+ } from "./chunk-XHYUUG6Y.js";
65
+ import "./chunk-IYL4VCWR.js";
66
66
  export {
67
67
  AttestationError,
68
68
  AttestationErrorCodes,
@@ -1645,7 +1645,11 @@ async function nativeWalletAuth(options, ctx) {
1645
1645
  });
1646
1646
  const walletAuthPayload = { siweMessage };
1647
1647
  const worldAppVersion = ctx.state.deviceProperties.worldAppVersion;
1648
- const walletAuthVersion = worldAppVersion && worldAppVersion > 2087900 ? COMMAND_VERSIONS["wallet-auth" /* WalletAuth */] : 1;
1648
+ if (worldAppVersion && worldAppVersion <= 2087900) {
1649
+ throw new Error(
1650
+ "Wallet auth v1 is no longer supported. Please update World App to the latest version."
1651
+ );
1652
+ }
1649
1653
  const finalPayload = await new Promise(
1650
1654
  (resolve, reject) => {
1651
1655
  try {
@@ -1655,7 +1659,7 @@ async function nativeWalletAuth(options, ctx) {
1655
1659
  });
1656
1660
  sendMiniKitEvent({
1657
1661
  command: "wallet-auth" /* WalletAuth */,
1658
- version: walletAuthVersion,
1662
+ version: COMMAND_VERSIONS["wallet-auth" /* WalletAuth */],
1659
1663
  payload: walletAuthPayload
1660
1664
  });
1661
1665
  } catch (error) {
@@ -3,15 +3,15 @@ import {
3
3
  _getAddress,
4
4
  _setAddress,
5
5
  getWorldAppProvider
6
- } from "../chunk-TGXD24YD.js";
6
+ } from "../chunk-QOFVDR5F.js";
7
7
  import {
8
8
  setWagmiConfig
9
- } from "../chunk-2UPJKPQ6.js";
9
+ } from "../chunk-6SCI6OTQ.js";
10
10
  import {
11
11
  MiniKit
12
- } from "../chunk-EHBM7OXH.js";
13
- import "../chunk-Z2UGRZJ2.js";
14
- import "../chunk-LHHKY77D.js";
12
+ } from "../chunk-QOLIACKU.js";
13
+ import "../chunk-XHYUUG6Y.js";
14
+ import "../chunk-IYL4VCWR.js";
15
15
 
16
16
  // src/connector/connector.ts
17
17
  function worldApp(options = {}) {
package/build/index.cjs CHANGED
@@ -1368,7 +1368,11 @@ async function nativeWalletAuth(options, ctx) {
1368
1368
  });
1369
1369
  const walletAuthPayload = { siweMessage };
1370
1370
  const worldAppVersion = ctx.state.deviceProperties.worldAppVersion;
1371
- const walletAuthVersion = worldAppVersion && worldAppVersion > 2087900 ? COMMAND_VERSIONS["wallet-auth" /* WalletAuth */] : 1;
1371
+ if (worldAppVersion && worldAppVersion <= 2087900) {
1372
+ throw new Error(
1373
+ "Wallet auth v1 is no longer supported. Please update World App to the latest version."
1374
+ );
1375
+ }
1372
1376
  const finalPayload = await new Promise(
1373
1377
  (resolve, reject) => {
1374
1378
  try {
@@ -1378,7 +1382,7 @@ async function nativeWalletAuth(options, ctx) {
1378
1382
  });
1379
1383
  sendMiniKitEvent({
1380
1384
  command: "wallet-auth" /* WalletAuth */,
1381
- version: walletAuthVersion,
1385
+ version: COMMAND_VERSIONS["wallet-auth" /* WalletAuth */],
1382
1386
  payload: walletAuthPayload
1383
1387
  });
1384
1388
  } catch (error) {
package/build/index.js CHANGED
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  getWorldAppProvider
3
- } from "./chunk-TGXD24YD.js";
3
+ } from "./chunk-QOFVDR5F.js";
4
4
  import {
5
5
  MiniKit
6
- } from "./chunk-EHBM7OXH.js";
7
- import "./chunk-Z2UGRZJ2.js";
8
- import "./chunk-LHHKY77D.js";
6
+ } from "./chunk-QOLIACKU.js";
7
+ import "./chunk-XHYUUG6Y.js";
8
+ import "./chunk-IYL4VCWR.js";
9
9
  export {
10
10
  MiniKit,
11
11
  getWorldAppProvider
@@ -1648,7 +1648,11 @@ async function nativeWalletAuth(options, ctx) {
1648
1648
  });
1649
1649
  const walletAuthPayload = { siweMessage };
1650
1650
  const worldAppVersion = ctx.state.deviceProperties.worldAppVersion;
1651
- const walletAuthVersion = worldAppVersion && worldAppVersion > 2087900 ? COMMAND_VERSIONS["wallet-auth" /* WalletAuth */] : 1;
1651
+ if (worldAppVersion && worldAppVersion <= 2087900) {
1652
+ throw new Error(
1653
+ "Wallet auth v1 is no longer supported. Please update World App to the latest version."
1654
+ );
1655
+ }
1652
1656
  const finalPayload = await new Promise(
1653
1657
  (resolve, reject) => {
1654
1658
  try {
@@ -1658,7 +1662,7 @@ async function nativeWalletAuth(options, ctx) {
1658
1662
  });
1659
1663
  sendMiniKitEvent({
1660
1664
  command: "wallet-auth" /* WalletAuth */,
1661
- version: walletAuthVersion,
1665
+ version: COMMAND_VERSIONS["wallet-auth" /* WalletAuth */],
1662
1666
  payload: walletAuthPayload
1663
1667
  });
1664
1668
  } catch (error) {
@@ -1,12 +1,12 @@
1
1
  "use client";
2
2
  import {
3
3
  setWagmiConfig
4
- } from "./chunk-2UPJKPQ6.js";
4
+ } from "./chunk-6SCI6OTQ.js";
5
5
  import {
6
6
  MiniKit
7
- } from "./chunk-EHBM7OXH.js";
8
- import "./chunk-Z2UGRZJ2.js";
9
- import "./chunk-LHHKY77D.js";
7
+ } from "./chunk-QOLIACKU.js";
8
+ import "./chunk-XHYUUG6Y.js";
9
+ import "./chunk-IYL4VCWR.js";
10
10
 
11
11
  // src/minikit-provider.tsx
12
12
  import {
@@ -37,7 +37,6 @@ var IAT_TAG = "Issued At: ";
37
37
  var EXP_TAG = "Expiration Time: ";
38
38
  var NBF_TAG = "Not Before: ";
39
39
  var RID_TAG = "Request ID: ";
40
- var ERC_191_PREFIX = "Ethereum Signed Message:\n";
41
40
  var EIP1271_MAGICVALUE = "0x1626ba7e";
42
41
  var SAFE_CONTRACT_ABI = [
43
42
  {
@@ -136,14 +135,8 @@ var parseSiweMessage = (inputString) => {
136
135
  return siweMessageData;
137
136
  };
138
137
  var verifySiweMessage = (payload, nonce, statement, requestId, userProvider) => {
139
- if (payload.version === 1) {
140
- return verifySiweMessageV1(
141
- payload,
142
- nonce,
143
- statement,
144
- requestId,
145
- userProvider
146
- );
138
+ if (payload.version !== 2) {
139
+ throw new Error("Unsupported version returned");
147
140
  } else {
148
141
  return verifySiweMessageV2(
149
142
  payload,
@@ -184,39 +177,14 @@ var validateMessage = (siweMessageData, nonce, statement, requestId) => {
184
177
  }
185
178
  return true;
186
179
  };
187
- var verifySiweMessageV1 = async (payload, nonce, statement, requestId, userProvider) => {
188
- if (typeof window !== "undefined") {
189
- throw new Error("Wallet auth payload can only be verified in the backend");
190
- }
191
- const { message, signature, address } = payload;
192
- const siweMessageData = parseSiweMessage(message);
193
- validateMessage(siweMessageData, nonce, statement, requestId);
194
- let provider = userProvider || (0, import_viem.createPublicClient)({ chain: import_chains.worldchain, transport: (0, import_viem.http)() });
195
- const signedMessage = `${ERC_191_PREFIX}${message.length}${message}`;
196
- const hashedMessage = (0, import_viem.hashMessage)(signedMessage);
197
- const contract = (0, import_viem.getContract)({
198
- address,
199
- abi: SAFE_CONTRACT_ABI,
200
- client: provider
201
- });
202
- try {
203
- const recoveredAddress = await (0, import_viem.recoverAddress)({
204
- hash: hashedMessage,
205
- signature: `0x${signature}`
206
- });
207
- const isOwner = await contract.read.isOwner([recoveredAddress]);
208
- if (!isOwner) {
209
- throw new Error("Signature verification failed, invalid owner");
210
- }
211
- } catch (error) {
212
- throw new Error("Signature verification failed");
213
- }
214
- return { isValid: true, siweMessageData };
215
- };
216
180
  var verifySiweMessageV2 = async (payload, nonce, statement, requestId, userProvider) => {
217
181
  if (typeof window !== "undefined") {
218
182
  throw new Error("Wallet auth payload can only be verified in the backend");
219
183
  }
184
+ const NONCE_REGEX = /^[a-zA-Z0-9]+$/;
185
+ if (!NONCE_REGEX.test(nonce)) {
186
+ throw new Error("Invalid nonce: must be alphanumeric only (per ERC-4361)");
187
+ }
220
188
  const { message, signature, address } = payload;
221
189
  const siweMessageData = parseSiweMessage(message);
222
190
  if (!validateMessage(siweMessageData, nonce, statement, requestId)) {
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  parseSiweMessage,
3
3
  verifySiweMessage
4
- } from "./chunk-LHHKY77D.js";
4
+ } from "./chunk-IYL4VCWR.js";
5
5
  export {
6
6
  parseSiweMessage,
7
7
  verifySiweMessage
package/package.json CHANGED
@@ -140,7 +140,7 @@
140
140
  ]
141
141
  }
142
142
  },
143
- "version": "2.0.0-dev.1",
143
+ "version": "2.0.0",
144
144
  "scripts": {
145
145
  "build": "tsup",
146
146
  "dev": "tsup --watch",