diff --git a/demo/with-next/abi/USDC.json b/demo/with-next/abi/USDC.json new file mode 100644 index 00000000..b7b388e8 --- /dev/null +++ b/demo/with-next/abi/USDC.json @@ -0,0 +1,96 @@ +[ + { + "inputs": [ + { + "internalType": "address", + "name": "implementationContract", + "type": "address" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "previousAdmin", + "type": "address" + }, + { + "indexed": false, + "internalType": "address", + "name": "newAdmin", + "type": "address" + } + ], + "name": "AdminChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "address", + "name": "implementation", + "type": "address" + } + ], + "name": "Upgraded", + "type": "event" + }, + { "stateMutability": "payable", "type": "fallback" }, + { + "inputs": [], + "name": "admin", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { "internalType": "address", "name": "newAdmin", "type": "address" } + ], + "name": "changeAdmin", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "implementation", + "outputs": [{ "internalType": "address", "name": "", "type": "address" }], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newImplementation", + "type": "address" + } + ], + "name": "upgradeTo", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newImplementation", + "type": "address" + }, + { "internalType": "bytes", "name": "data", "type": "bytes" } + ], + "name": "upgradeToAndCall", + "outputs": [], + "stateMutability": "payable", + "type": "function" + } +] diff --git a/demo/with-next/app/layout.tsx b/demo/with-next/app/layout.tsx index 75ca0f47..c42bbff5 100644 --- a/demo/with-next/app/layout.tsx +++ b/demo/with-next/app/layout.tsx @@ -21,11 +21,9 @@ export default async function RootLayout({ return ( - - - {children} - - + + {children} + ); } diff --git a/demo/with-next/components/ClientContent/SignMessage.tsx b/demo/with-next/components/ClientContent/SignMessage.tsx new file mode 100644 index 00000000..090e4c71 --- /dev/null +++ b/demo/with-next/components/ClientContent/SignMessage.tsx @@ -0,0 +1,166 @@ +import { + MiniKit, + SignMessageErrorCodes, + ResponseEvent, +} from "@worldcoin/minikit-js"; +import { useCallback, useEffect, useState } from "react"; +import { validateSchema } from "./helpers/validate-schema"; +import * as yup from "yup"; +import { SignMessageInput } from "../../../../src/types/commands"; +import { verifyMessage } from "@wagmi/core"; +import { config } from "../config"; +import { optimism } from "@wagmi/core/chains"; + +const signMessageSuccessPayloadSchema = yup.object({ + message: yup.string().required(), + status: yup.string<"success">().oneOf(["success"]), + signature: yup.string().required(), + address: yup.string().required(), +}); + +const signMessageErrorPayloadSchema = yup.object({ + error_code: yup + .string() + .oneOf(Object.values(SignMessageErrorCodes)) + .required(), + status: yup.string<"error">().equals(["error"]).required(), + version: yup.number().required(), +}); + +export const SignMessage = () => { + const [signMessageAppPayload, setSignMessageAppPayload] = useState< + string | undefined + >(); + + const [ + signMessagePayloadValidationMessage, + setSignMessagePayloadValidationMessage, + ] = useState(); + + const [ + signMessagePayloadVerificaitonMessage, + setSignMessagePayloadVerificationMessage, + ] = useState(); + + const [sentSignMessagePayload, setSentSignMessagePayload] = useState | null>(null); + + useEffect(() => { + if (!MiniKit.isInstalled()) { + return; + } + + MiniKit.subscribe(ResponseEvent.MiniAppSignMessage, async (payload) => { + console.log("MiniAppSignMessage, SUBSCRIBE PAYLOAD", payload); + + if (payload.status === "error") { + const errorMessage = await validateSchema( + signMessageErrorPayloadSchema, + payload + ); + + if (!errorMessage) { + setSignMessagePayloadValidationMessage("Payload is valid"); + } else { + setSignMessagePayloadValidationMessage(errorMessage); + } + } else { + const errorMessage = await validateSchema( + signMessageSuccessPayloadSchema, + payload + ); + + if (!errorMessage) { + setSignMessagePayloadValidationMessage("Payload is valid"); + } else { + setSignMessagePayloadValidationMessage(errorMessage); + } + } + + const isValid = await verifyMessage(config, { + address: "0x4564420674EA68fcc61b463C0494807C759d47e6", + message: "hello world", + signature: + "0x654c6c04ba9496731e26f92b74a0de100e2dc72e0ae646698d5f8ed68c2b9db03bb46a772843608717d8ba3d8ae1d4a330bc97315b14397d9216b45b3834351d1b", + }); + + setSignMessageAppPayload(JSON.stringify(payload, null, 2)); + setSignMessagePayloadVerificationMessage( + isValid ? "Signature is valid" : "Signature is invalid" + ); + }); + + return () => { + MiniKit.unsubscribe(ResponseEvent.MiniAppSignMessage); + }; + }, []); + + const onSignMessage = useCallback(async () => { + const signMessagePayload: SignMessageInput = { + message: "hello world", + }; + + const payload = MiniKit.commands.signMessage(signMessagePayload); + console.log( + await verifyMessage(config, { + address: "0x4564420674EA68fcc61b463C0494807C759d47e6", + message: "hello world", + chainId: optimism.id, + signature: + "0x654c6c04ba9496731e26f92b74a0de100e2dc72e0ae646698d5f8ed68c2b9db03bb46a772843608717d8ba3d8ae1d4a330bc97315b14397d9216b45b3834351d1b", + }) + ); + setSentSignMessagePayload({ + payload, + }); + }, []); + + return ( +
+
+

Sign Message

+ +
+
+
+              {JSON.stringify(sentSignMessagePayload, null, 2)}
+            
+
+
+ +
+ +
+ +
+

Message from "{ResponseEvent.MiniAppSignMessage}"

+ +
+
+            {signMessageAppPayload ?? JSON.stringify(null)}
+          
+
+ +
+

Validation message:

+

+ {signMessagePayloadValidationMessage ?? "No validation"} +

+
+
+

Verification message:

+

+ {signMessagePayloadValidationMessage ?? "No validation"} +

+
+
+
+ ); +}; diff --git a/demo/with-next/components/ClientContent/SignTypedMessage.tsx b/demo/with-next/components/ClientContent/SignTypedMessage.tsx new file mode 100644 index 00000000..44b4e30a --- /dev/null +++ b/demo/with-next/components/ClientContent/SignTypedMessage.tsx @@ -0,0 +1,178 @@ +import { + MiniKit, + SignTypedDataErrorCodes, + ResponseEvent, +} from "@worldcoin/minikit-js"; +import { useCallback, useEffect, useState } from "react"; +import { validateSchema } from "./helpers/validate-schema"; +import * as yup from "yup"; +import { SignTypedDataInput } from "../../../../src/types/commands"; +import { verifyMessage } from "@wagmi/core"; +import { config } from "../config"; +import { optimism } from "@wagmi/core/chains"; + +const signTypedDataSuccessPayloadSchema = yup.object({ + message: yup.string().required(), + status: yup.string<"success">().oneOf(["success"]), + signature: yup.string().required(), + address: yup.string().required(), +}); + +const signTypedDataErrorPayloadSchema = yup.object({ + error_code: yup + .string() + .oneOf(Object.values(SignTypedDataErrorCodes)) + .required(), + status: yup.string<"error">().equals(["error"]).required(), + version: yup.number().required(), +}); + +export const SignTypedData = () => { + const [signTypedDataAppPayload, setSignTypedDataAppPayload] = useState< + string | undefined + >(); + + const [ + signTypedDataPayloadValidationMessage, + setSignTypedDataPayloadValidationMessage, + ] = useState(); + + const [ + signTypedDataPayloadVerificaitonMessage, + setSignTypedDataPayloadVerificationMessage, + ] = useState(); + + const [sentSignTypedDataPayload, setSentSignTypedDataPayload] = + useState | null>(null); + + useEffect(() => { + if (!MiniKit.isInstalled()) { + return; + } + + MiniKit.subscribe(ResponseEvent.MiniAppSignTypedData, async (payload) => { + console.log("MiniAppSignTypedData, SUBSCRIBE PAYLOAD", payload); + + if (payload.status === "error") { + const errorMessage = await validateSchema( + signTypedDataErrorPayloadSchema, + payload + ); + + if (!errorMessage) { + setSignTypedDataPayloadValidationMessage("Payload is valid"); + } else { + setSignTypedDataPayloadValidationMessage(errorMessage); + } + } else { + const errorMessage = await validateSchema( + signTypedDataSuccessPayloadSchema, + payload + ); + + if (!errorMessage) { + setSignTypedDataPayloadValidationMessage("Payload is valid"); + } else { + setSignTypedDataPayloadValidationMessage(errorMessage); + } + } + + const isValid = await verifyMessage(config, { + address: "0x4564420674EA68fcc61b463C0494807C759d47e6", + message: "hello world", + signature: + "0x654c6c04ba9496731e26f92b74a0de100e2dc72e0ae646698d5f8ed68c2b9db03bb46a772843608717d8ba3d8ae1d4a330bc97315b14397d9216b45b3834351d1b", + }); + + setSignTypedDataAppPayload(JSON.stringify(payload, null, 2)); + setSignTypedDataPayloadVerificationMessage( + isValid ? "Signature is valid" : "Signature is invalid" + ); + }); + + return () => { + MiniKit.unsubscribe(ResponseEvent.MiniAppSignTypedData); + }; + }, []); + + const onSignTypedData = useCallback(async () => { + const signTypedDataPayload: SignTypedDataInput = { + types: { + Person: [ + { name: "name", type: "string" }, + { name: "wallet", type: "address" }, + ], + Mail: [ + { name: "from", type: "Person" }, + { name: "to", type: "Person" }, + { name: "contents", type: "string" }, + ], + }, + primaryType: "Mail", + message: { + from: { + name: "Cow", + wallet: "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826", + }, + to: { + name: "Bob", + wallet: "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB", + }, + contents: "Hello, Bob!", + }, + }; + + const payload = MiniKit.commands.signTypedData(signTypedDataPayload); + + setSentSignTypedDataPayload({ + payload, + }); + }, []); + + return ( +
+
+

Sign Typed Data

+ +
+
+
+              {JSON.stringify(sentSignTypedDataPayload, null, 2)}
+            
+
+
+ +
+ +
+ +
+

Message from "{ResponseEvent.MiniAppSignTypedData}"

+ +
+
+            {signTypedDataAppPayload ?? JSON.stringify(null)}
+          
+
+ +
+

Validation message:

+

+ {signTypedDataPayloadValidationMessage ?? "No validation"} +

+
+
+

Verification message:

+

+ {signTypedDataPayloadValidationMessage ?? "No validation"} +

+
+
+
+ ); +}; diff --git a/demo/with-next/components/ClientContent/Transaction.tsx b/demo/with-next/components/ClientContent/Transaction.tsx new file mode 100644 index 00000000..f9a9a6b6 --- /dev/null +++ b/demo/with-next/components/ClientContent/Transaction.tsx @@ -0,0 +1,196 @@ +import { + MiniKit, + ResponseEvent, + SendTransactionErrorCodes, +} from "@worldcoin/minikit-js"; +import { useCallback, useEffect, useState } from "react"; +import * as yup from "yup"; +import { validateSchema } from "./helpers/validate-schema"; +import USDCABI from "../../abi/USDC.json"; + +const sendTransactionSuccessPayloadSchema = yup.object({ + status: yup.string<"success">().oneOf(["success"]), + transaction_status: yup.string<"submitted">().oneOf(["submitted"]), + transaction_id: yup.string().required(), + reference: yup.string().required(), + from: yup.string().optional(), + chain: yup.string().required(), + timestamp: yup.string().required(), +}); + +const sendTransactionErrorPayloadSchema = yup.object({ + error_code: yup + .string() + .oneOf(Object.values(SendTransactionErrorCodes)) + .required(), + status: yup.string<"error">().equals(["error"]).required(), +}); + +const testTokens = { + optimism: { + USDC: "0x0b2c639c533813f4aa9d7837caf62653d097ff85", + }, +}; + +export const SendTransaction = () => { + const [transactionData, setTransactionData] = useState | null>(null); + const [receivedSendTransactionPayload, setReceivedSendTransactionPayload] = + useState | null>(null); + + const [ + sendTransactionPayloadValidationMessage, + setSendTransactionPayloadValidationMessage, + ] = useState(); + + const [ + sendTransactionVerificationMessage, + setSendTransactionVerificationMessage, + ] = useState(); + + useEffect(() => { + if (!MiniKit.isInstalled()) { + return; + } + + MiniKit.subscribe(ResponseEvent.MiniAppSendTransaction, async (payload) => { + console.log("MiniAppSendTransaction, SUBSCRIBE PAYLOAD", payload); + + if (payload.status === "error") { + const errorMessage = await validateSchema( + sendTransactionErrorPayloadSchema, + payload + ); + + if (!errorMessage) { + setSendTransactionPayloadValidationMessage("Payload is valid"); + } else { + setSendTransactionPayloadValidationMessage(errorMessage); + } + } else { + const errorMessage = await validateSchema( + sendTransactionSuccessPayloadSchema, + payload + ); + + if (!errorMessage) { + setSendTransactionPayloadValidationMessage("Payload is valid"); + } else { + setSendTransactionPayloadValidationMessage(errorMessage); + } + + // // Call the API to verify the message + // const response = await fetch("/api/verify-siwe", { + // method: "POST", + // headers: { + // "Content-Type": "application/json", + // }, + // body: JSON.stringify({ + // siweResponsePayload: payload, + // }), + // }); + + // const responseJson = await response.json(); + + // setSendTransactionVerificationMessage( + // responseJson.isValid + // ? "Valid! Successful Transaction" + // : `Failed: ${responseJson.message}` + // ); + } + setSendTransactionVerificationMessage("TODO"); + + setReceivedSendTransactionPayload(payload); + }); + + return () => { + MiniKit.unsubscribe(ResponseEvent.MiniAppSendTransaction); + }; + }, []); + + const onSendTransactionClick = useCallback(() => { + const deadline = new Date(Date.now() + 30 * 60 * 1000).toISOString(); + + const payload = MiniKit.commands.sendTransaction({ + payload: [ + { + to: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045", + abi: USDCABI, + functionName: "transferFrom", + args: [2000000, "PERMIT2_SIGNATURE_PLACEHOLDER_1"], + }, + { + to: "0xd8dA6BF26964aF9D7eEd9e03E53415D37aA96045", + abi: USDCABI, + functionName: "transferFrom", + args: [100000, "PERMIT2_SIGNATURE_PLACEHOLDER_2"], + }, + ], + permit2: [ + { + deadline: deadline, + token_address: testTokens.optimism.USDC, + amount: "100000000", + }, + { + deadline: deadline, + token_address: testTokens.optimism.USDC, + amount: "100000000", + }, + ], + }); + setTransactionData(payload); + }, []); + + return ( +
+

Transaction

+ +
+

Raw string:

+ +
+
+            {transactionData
+              ? JSON.stringify(transactionData, null, 3)
+              : JSON.stringify(null)}
+          
+
+
+ + + +
+

+ Received from "{ResponseEvent.MiniAppSendTransaction}":{" "} +

+
+
+            {JSON.stringify(receivedSendTransactionPayload, null, 2)}
+          
+
+ +
+

Validation message:

+

+ {sendTransactionPayloadValidationMessage ?? "No validation"} +

+
+ +
+

Verification:

+

+ {sendTransactionVerificationMessage ?? "No verification yet"} +

+
+
+
+ ); +}; diff --git a/demo/with-next/components/ClientContent/Versions.tsx b/demo/with-next/components/ClientContent/Versions.tsx index 436ccbc6..d201af1e 100644 --- a/demo/with-next/components/ClientContent/Versions.tsx +++ b/demo/with-next/components/ClientContent/Versions.tsx @@ -2,7 +2,7 @@ import { MiniKit, - MiniKitInstallErrorCode, + MiniKitInstallErrorCodes, MiniKitInstallErrorMessage, } from "@worldcoin/minikit-js"; @@ -23,7 +23,7 @@ export const Versions = () => { return { isValid: false, error: - MiniKitInstallErrorMessage[MiniKitInstallErrorCode.AppOutOfDate], + MiniKitInstallErrorMessage[MiniKitInstallErrorCodes.AppOutOfDate], }; } } catch (error) { diff --git a/demo/with-next/components/ClientContent/index.tsx b/demo/with-next/components/ClientContent/index.tsx index eca5f240..fe839621 100644 --- a/demo/with-next/components/ClientContent/index.tsx +++ b/demo/with-next/components/ClientContent/index.tsx @@ -8,6 +8,9 @@ import { WalletAuth } from "./WalletAuth"; import { ExternalLinks } from "./ExternalLinks"; import dynamic from "next/dynamic"; import { CameraComponent } from "./Camera"; +import { SendTransaction } from "./Transaction"; +import { SignMessage } from "./SignMessage"; +import { SignTypedData } from "./SignTypedMessage"; const VersionsNoSSR = dynamic( () => import("./Versions").then((comp) => comp.Versions), @@ -33,6 +36,12 @@ export const ClientContent = () => {

+ +
+ +
+ +

diff --git a/demo/with-next/components/config.ts b/demo/with-next/components/config.ts new file mode 100644 index 00000000..52142237 --- /dev/null +++ b/demo/with-next/components/config.ts @@ -0,0 +1,11 @@ +import { http, createConfig } from '@wagmi/core' +import { mainnet, optimism, sepolia } from '@wagmi/core/chains' + +export const config = createConfig({ + chains: [mainnet, sepolia, optimism], + transports: { + [mainnet.id]: http(), + [sepolia.id]: http(), + [optimism.id]: http(), + }, +}) \ No newline at end of file diff --git a/demo/with-next/package.json b/demo/with-next/package.json index d7ba0cb0..c533a61b 100644 --- a/demo/with-next/package.json +++ b/demo/with-next/package.json @@ -7,9 +7,10 @@ "build": "next build", "start": "next start", "lint": "next lint", - "typecheck": "tsc" + "type-check": "tsc" }, "dependencies": { + "@wagmi/core": "^2.13.4", "@worldcoin/minikit-js": "workspace:*", "clsx": "^2.1.1", "next": "14.2.1", diff --git a/package.json b/package.json index 2d9ad2c2..b9eee47c 100644 --- a/package.json +++ b/package.json @@ -8,10 +8,11 @@ "build": "turbo run build", "prepublishOnly": "npm run build" }, - "devDependencies": { - "turbo": "^1.11.1" + "dependencies": { + "turbo": "^2.1.1" }, "engines": { "node": ">=18" - } + }, + "packageManager": "pnpm@9.9.0" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 89fec189..648df4ce 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -7,13 +7,16 @@ settings: importers: .: - devDependencies: + dependencies: turbo: - specifier: ^1.11.1 - version: 1.13.2 + specifier: ^2.1.1 + version: 2.1.1 demo/with-next: dependencies: + '@wagmi/core': + specifier: ^2.13.4 + version: 2.13.4(@types/react@18.2.79)(react@18.2.0)(typescript@5.4.5)(viem@2.17.3(typescript@5.4.5)) '@worldcoin/minikit-js': specifier: workspace:* version: link:../../src @@ -67,14 +70,17 @@ importers: src: dependencies: '@worldcoin/idkit-core': - specifier: ^1.2.2 - version: 1.2.2(@types/react@18.2.79)(react@18.2.0)(typescript@5.4.5) + specifier: ^1.3.0 + version: 1.3.0(@types/react@18.2.79)(react@18.2.0)(typescript@5.4.5) abitype: specifier: ^1.0.6 version: 1.0.6(typescript@5.4.5) ethers: specifier: ^6.0.8 version: 6.12.1 + turbo: + specifier: ^2.1.1 + version: 2.1.1 devDependencies: '@typescript-eslint/eslint-plugin': specifier: ^7.7.0 @@ -91,9 +97,6 @@ importers: tsup: specifier: ^8.0.2 version: 8.0.2(postcss@8.4.38)(typescript@5.4.5) - turbo: - specifier: ^1.13.2 - version: 1.13.2 typescript: specifier: ^5.4.5 version: 5.4.5 @@ -894,6 +897,7 @@ packages: '@humanwhocodes/config-array@0.11.14': resolution: {integrity: sha512-3T8LkOmg45BV5FICb15QQMsyUSWrQ8AygVfC7ZG32zOalnqrilm018ZVCw0eapXux8FtA33q8PSRSstjee3jSg==} engines: {node: '>=10.10.0'} + deprecated: Use @eslint/config-array instead '@humanwhocodes/module-importer@1.0.1': resolution: {integrity: sha512-bxveV4V8v5Yb4ncFTT3rPSgZBOpCkjfK0y4oVVVJwIuDVBRMDXrPyXRL988i5ap9m9bnyEEjWfm5WkBmtffLfA==} @@ -901,6 +905,7 @@ packages: '@humanwhocodes/object-schema@2.0.3': resolution: {integrity: sha512-93zYdMES/c1D69yZiKDBj0V24vqNzB/koF26KPaagAfd3P/4gUlh3Dys5ogAK+Exi9QyzlD8x/08Zt7wIKcDcA==} + deprecated: Use @eslint/object-schema instead '@isaacs/cliui@8.0.2': resolution: {integrity: sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==} @@ -1350,8 +1355,20 @@ packages: '@ungap/structured-clone@1.2.0': resolution: {integrity: sha512-zuVdFrMJiuCDQUMCzQaD6KL28MjnqqN8XnAqiEq9PNm/hCPTSGfrXCOfwj1ow4LFb/tNymJPwsNbVePc1xFqrQ==} - '@worldcoin/idkit-core@1.2.2': - resolution: {integrity: sha512-zc+DG1iZrQZ1LI1B3b+skb9K4TvvI55KDxWcKzdL83N8Xr1PNZ9icOWrwndufpp6IbEz+BNJFZV0hVf/KS2Zgg==} + '@wagmi/core@2.13.4': + resolution: {integrity: sha512-J6gfxHYr8SCc/BzEa712LnI+qLFs5K2nBLupwQqQl4WiAlCu8SdcpbZokqiwfCMYhIRMj0+YFEP9qe4ypcexmw==} + peerDependencies: + '@tanstack/query-core': '>=5.0.0' + typescript: '>=5.0.4' + viem: 2.x + peerDependenciesMeta: + '@tanstack/query-core': + optional: true + typescript: + optional: true + + '@worldcoin/idkit-core@1.3.0': + resolution: {integrity: sha512-HAgaZl8rmKq5aKeNAOXIbvhDwtpxTM4Wsy8F26LH1vMBgTe3tx/wHXmV7jsNl1p2k8XRhGmrAdqeRVK5QPhBfg==} engines: {node: '>=12.4'} abitype@1.0.5: @@ -1963,6 +1980,9 @@ packages: resolution: {integrity: sha512-j6wcVoZf06nqEcBbDWkKg8Fp895SS96dSnTCjiXT+8vt2o02raTn4Lo9ERUuIVU5bAjoPYeA+7ytQFexFmLuVw==} engines: {node: '>=14.0.0'} + eventemitter3@5.0.1: + resolution: {integrity: sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA==} + execa@5.1.1: resolution: {integrity: sha512-8uSpZZocAZRBAPIEINJj3Lo9HyGitllczc27Eh5YYojjMFMn8yHMDMaUHE2Jqfq05D/wucwI4JGURyXt1vchyg==} engines: {node: '>=10'} @@ -2089,6 +2109,7 @@ packages: glob@7.2.3: resolution: {integrity: sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==} + deprecated: Glob versions prior to v9 are no longer supported globals@11.12.0: resolution: {integrity: sha512-WOBp/EEGUiIsJSp7wcv/y6MO+lV9UoncWqxuFfm8eBwzWNgyfBd6Gz+IeKQ9jCmyhoH99g15M3T+QaVHFjizVA==} @@ -2174,6 +2195,7 @@ packages: inflight@1.0.6: resolution: {integrity: sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==} + deprecated: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful. inherits@2.0.4: resolution: {integrity: sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==} @@ -2637,6 +2659,14 @@ packages: resolution: {integrity: sha512-jYofLM5Dam9279rdkWzqHozUo4ybjdZmCsDHePy5V/PbBcVMiSZR97gmAy45aqi8CK1lG2ECd356FU86avfwUQ==} engines: {node: '>=16 || 14 >=14.17'} + mipd@0.0.7: + resolution: {integrity: sha512-aAPZPNDQ3uMTdKbuO2YmAw2TxLHO0moa4YKAyETM/DTj5FloZo+a+8tU+iv4GmW+sOxKLSRwcSFuczk+Cpt6fg==} + peerDependencies: + typescript: '>=5.0.4' + peerDependenciesMeta: + typescript: + optional: true + ms@2.1.2: resolution: {integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==} @@ -3017,6 +3047,7 @@ packages: rimraf@3.0.2: resolution: {integrity: sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==} + deprecated: Rimraf versions prior to v4 are no longer supported hasBin: true rollup@4.14.3: @@ -3276,38 +3307,38 @@ packages: typescript: optional: true - turbo-darwin-64@1.13.2: - resolution: {integrity: sha512-CCSuD8CfmtncpohCuIgq7eAzUas0IwSbHfI8/Q3vKObTdXyN8vAo01gwqXjDGpzG9bTEVedD0GmLbD23dR0MLA==} + turbo-darwin-64@2.1.1: + resolution: {integrity: sha512-aYNuJpZlCoi0Htd79fl/2DywpewGKijdXeOfg9KzNuPVKzSMYlAXuAlNGh0MKjiOcyqxQGL7Mq9LFhwA0VpDpQ==} cpu: [x64] os: [darwin] - turbo-darwin-arm64@1.13.2: - resolution: {integrity: sha512-0HySm06/D2N91rJJ89FbiI/AodmY8B3WDSFTVEpu2+8spUw7hOJ8okWOT0e5iGlyayUP9gr31eOeL3VFZkpfCw==} + turbo-darwin-arm64@2.1.1: + resolution: {integrity: sha512-tifJKD8yHY48rHXPMcM8o1jI/Jk2KCaXiNjTKvvy9Zsim61BZksNVLelIbrRoCGwAN6PUBZO2lGU5iL/TQJ5Pw==} cpu: [arm64] os: [darwin] - turbo-linux-64@1.13.2: - resolution: {integrity: sha512-7HnibgbqZrjn4lcfIouzlPu8ZHSBtURG4c7Bedu7WJUDeZo+RE1crlrQm8wuwO54S0siYqUqo7GNHxu4IXbioQ==} + turbo-linux-64@2.1.1: + resolution: {integrity: sha512-Js6d/bSQe9DuV9c7ITXYpsU/ADzFHABdz1UIHa7Oqjj9VOEbFeA9WpAn0c+mdJrVD+IXJFbbDZUjN7VYssmtcg==} cpu: [x64] os: [linux] - turbo-linux-arm64@1.13.2: - resolution: {integrity: sha512-sUq4dbpk6SNKg/Hkwn256Vj2AEYSQdG96repio894h5/LEfauIK2QYiC/xxAeW3WBMc6BngmvNyURIg7ltrePg==} + turbo-linux-arm64@2.1.1: + resolution: {integrity: sha512-LidzTCq0yvQ+N8w8Qub9FmhQ/mmEIeoqFi7DSupekEV2EjvE9jw/zYc9Pk67X+g7dHVfgOnvVzmrjChdxpFePw==} cpu: [arm64] os: [linux] - turbo-windows-64@1.13.2: - resolution: {integrity: sha512-DqzhcrciWq3dpzllJR2VVIyOhSlXYCo4mNEWl98DJ3FZ08PEzcI3ceudlH6F0t/nIcfSItK1bDP39cs7YoZHEA==} + turbo-windows-64@2.1.1: + resolution: {integrity: sha512-GKc9ZywKwy4xLDhwXd6H07yzl0TB52HjXMrFLyHGhCVnf/w0oq4sLJv2sjbvuarPjsyx4xnCBJ3m3oyL2XmFtA==} cpu: [x64] os: [win32] - turbo-windows-arm64@1.13.2: - resolution: {integrity: sha512-WnPMrwfCXxK69CdDfS1/j2DlzcKxSmycgDAqV0XCYpK/812KB0KlvsVAt5PjEbZGXkY88pCJ1BLZHAjF5FcbqA==} + turbo-windows-arm64@2.1.1: + resolution: {integrity: sha512-oFKkMj11KKUv3xSK9/fhAEQTxLUp1Ol1EOktwc32+SFtEU0uls7kosAz0b+qe8k3pJGEMFdDPdqoEjyJidbxtQ==} cpu: [arm64] os: [win32] - turbo@1.13.2: - resolution: {integrity: sha512-rX/d9f4MgRT3yK6cERPAkfavIxbpBZowDQpgvkYwGMGDQ0Nvw1nc0NVjruE76GrzXQqoxR1UpnmEP54vBARFHQ==} + turbo@2.1.1: + resolution: {integrity: sha512-u9gUDkmR9dFS8b5kAYqIETK4OnzsS4l2ragJ0+soSMHh6VEeNHjTfSjk1tKxCqLyziCrPogadxP680J+v6yGHw==} hasBin: true type-check@0.4.0: @@ -3509,6 +3540,21 @@ packages: yup@1.4.0: resolution: {integrity: sha512-wPbgkJRCqIf+OHyiTBQoJiP5PFuAXaWiJK6AmYkzQAh5/c2K9hzSApBZG5wV9KoKSePF7sAxmNSvh/13YHkFDg==} + zustand@4.4.1: + resolution: {integrity: sha512-QCPfstAS4EBiTQzlaGP1gmorkh/UL1Leaj2tdj+zZCZ/9bm0WS7sI2wnfD5lpOszFqWJ1DcPnGoY8RDL61uokw==} + engines: {node: '>=12.7.0'} + peerDependencies: + '@types/react': '>=16.8' + immer: '>=9.0' + react: '>=16.8' + peerDependenciesMeta: + '@types/react': + optional: true + immer: + optional: true + react: + optional: true + zustand@4.5.2: resolution: {integrity: sha512-2cN1tPkDVkwCy5ickKrI7vijSjPksFRfqS6237NzT0vqSsztTNnQdHw9mmN7uBdk3gceVXU0a+21jFzFzAc9+g==} engines: {node: '>=12.7.0'} @@ -4905,7 +4951,20 @@ snapshots: '@ungap/structured-clone@1.2.0': {} - '@worldcoin/idkit-core@1.2.2(@types/react@18.2.79)(react@18.2.0)(typescript@5.4.5)': + '@wagmi/core@2.13.4(@types/react@18.2.79)(react@18.2.0)(typescript@5.4.5)(viem@2.17.3(typescript@5.4.5))': + dependencies: + eventemitter3: 5.0.1 + mipd: 0.0.7(typescript@5.4.5) + viem: 2.17.3(typescript@5.4.5) + zustand: 4.4.1(@types/react@18.2.79)(react@18.2.0) + optionalDependencies: + typescript: 5.4.5 + transitivePeerDependencies: + - '@types/react' + - immer + - react + + '@worldcoin/idkit-core@1.3.0(@types/react@18.2.79)(react@18.2.0)(typescript@5.4.5)': dependencies: browser-or-node: 3.0.0-pre.0 buffer: 6.0.3 @@ -5727,6 +5786,8 @@ snapshots: - bufferutil - utf-8-validate + eventemitter3@5.0.1: {} + execa@5.1.1: dependencies: cross-spawn: 7.0.3 @@ -6570,6 +6631,10 @@ snapshots: minipass@7.0.4: {} + mipd@0.0.7(typescript@5.4.5): + optionalDependencies: + typescript: 5.4.5 + ms@2.1.2: {} mz@2.7.0: @@ -7256,32 +7321,32 @@ snapshots: - supports-color - ts-node - turbo-darwin-64@1.13.2: + turbo-darwin-64@2.1.1: optional: true - turbo-darwin-arm64@1.13.2: + turbo-darwin-arm64@2.1.1: optional: true - turbo-linux-64@1.13.2: + turbo-linux-64@2.1.1: optional: true - turbo-linux-arm64@1.13.2: + turbo-linux-arm64@2.1.1: optional: true - turbo-windows-64@1.13.2: + turbo-windows-64@2.1.1: optional: true - turbo-windows-arm64@1.13.2: + turbo-windows-arm64@2.1.1: optional: true - turbo@1.13.2: + turbo@2.1.1: optionalDependencies: - turbo-darwin-64: 1.13.2 - turbo-darwin-arm64: 1.13.2 - turbo-linux-64: 1.13.2 - turbo-linux-arm64: 1.13.2 - turbo-windows-64: 1.13.2 - turbo-windows-arm64: 1.13.2 + turbo-darwin-64: 2.1.1 + turbo-darwin-arm64: 2.1.1 + turbo-linux-64: 2.1.1 + turbo-linux-arm64: 2.1.1 + turbo-windows-64: 2.1.1 + turbo-windows-arm64: 2.1.1 type-check@0.4.0: dependencies: @@ -7498,6 +7563,13 @@ snapshots: toposort: 2.0.2 type-fest: 2.19.0 + zustand@4.4.1(@types/react@18.2.79)(react@18.2.0): + dependencies: + use-sync-external-store: 1.2.0(react@18.2.0) + optionalDependencies: + '@types/react': 18.2.79 + react: 18.2.0 + zustand@4.5.2(@types/react@18.2.79)(react@18.2.0): dependencies: use-sync-external-store: 1.2.0(react@18.2.0) diff --git a/src/minikit.ts b/src/minikit.ts index 04b1efe5..ec5b1645 100644 --- a/src/minikit.ts +++ b/src/minikit.ts @@ -25,7 +25,7 @@ import { VerificationLevel } from "@worldcoin/idkit-core"; import { validateWalletAuthCommandInput } from "helpers/siwe/validate-wallet-auth-command-input"; import { generateSiweMessage } from "helpers/siwe/siwe"; import { - MiniKitInstallErrorCode, + MiniKitInstallErrorCodes, MiniKitInstallReturnType, MiniKitInstallErrorMessage, } from "types"; @@ -99,27 +99,29 @@ export class MiniKit { if (typeof window === "undefined" || Boolean(window.MiniKit)) { return { success: false, - errorCode: MiniKitInstallErrorCode.AlreadyInstalled, + errorCode: MiniKitInstallErrorCodes.AlreadyInstalled, errorMessage: - MiniKitInstallErrorMessage[MiniKitInstallErrorCode.AlreadyInstalled], + MiniKitInstallErrorMessage[MiniKitInstallErrorCodes.AlreadyInstalled], }; } if (!window.WorldApp) { return { success: false, - errorCode: MiniKitInstallErrorCode.OutsideOfWorldApp, + errorCode: MiniKitInstallErrorCodes.OutsideOfWorldApp, errorMessage: - MiniKitInstallErrorMessage[MiniKitInstallErrorCode.OutsideOfWorldApp], + MiniKitInstallErrorMessage[ + MiniKitInstallErrorCodes.OutsideOfWorldApp + ], }; } if (!this.commandsValid(window.WorldApp.supported_commands)) { return { success: false, - errorCode: MiniKitInstallErrorCode.AppOutOfDate, + errorCode: MiniKitInstallErrorCodes.AppOutOfDate, errorMessage: - MiniKitInstallErrorMessage[MiniKitInstallErrorCode.AppOutOfDate], + MiniKitInstallErrorMessage[MiniKitInstallErrorCodes.AppOutOfDate], }; } @@ -128,15 +130,15 @@ export class MiniKit { this.sendInit(); } catch (error) { console.error( - MiniKitInstallErrorMessage[MiniKitInstallErrorCode.Unknown], + MiniKitInstallErrorMessage[MiniKitInstallErrorCodes.Unknown], error ); return { success: false, - errorCode: MiniKitInstallErrorCode.Unknown, + errorCode: MiniKitInstallErrorCodes.Unknown, errorMessage: - MiniKitInstallErrorMessage[MiniKitInstallErrorCode.Unknown], + MiniKitInstallErrorMessage[MiniKitInstallErrorCodes.Unknown], }; } diff --git a/src/package.json b/src/package.json index f870de09..e898cebe 100644 --- a/src/package.json +++ b/src/package.json @@ -32,8 +32,9 @@ "typecheck": "tsc --noEmit" }, "dependencies": { - "@worldcoin/idkit-core": "^1.2.2", - "abitype": "^1.0.6" + "@worldcoin/idkit-core": "^1.3.0", + "abitype": "^1.0.6", + "turbo": "^2.1.1" }, "devDependencies": { "@typescript-eslint/eslint-plugin": "^7.7.0", @@ -41,7 +42,6 @@ "prettier": "^3.2.5", "prettier-plugin-sort-imports-desc": "^1.0.0", "tsup": "^8.0.2", - "turbo": "^1.13.2", "typescript": "^5.4.5" }, "peerDependencies": { diff --git a/src/types/commands.ts b/src/types/commands.ts index 24909b9a..28953dd8 100644 --- a/src/types/commands.ts +++ b/src/types/commands.ts @@ -1,8 +1,8 @@ -import { IDKitConfig, VerificationLevel } from "@worldcoin/idkit-core/*"; +import { IDKitConfig, VerificationLevel } from "@worldcoin/idkit-core"; import { Network, Tokens } from "./payment"; -import { MiniKitInstallErrorCode, MiniKitInstallErrorMessage } from "./"; import { Permit2, Transaction } from "./transactions"; import type { TypedData, TypedDataDomain } from "abitype"; +import { MiniKitInstallErrorCodes, MiniKitInstallErrorMessage } from "./errors"; export enum Command { Verify = "verify", @@ -62,8 +62,8 @@ export type MiniKitInstallReturnType = | { success: true } | { success: false; - errorCode: MiniKitInstallErrorCode; - errorMessage: (typeof MiniKitInstallErrorMessage)[MiniKitInstallErrorCode]; + errorCode: MiniKitInstallErrorCodes; + errorMessage: (typeof MiniKitInstallErrorMessage)[MiniKitInstallErrorCodes]; }; export type SendTransactionInput = { diff --git a/src/types/errors.ts b/src/types/errors.ts index b445b647..f4344467 100644 --- a/src/types/errors.ts +++ b/src/types/errors.ts @@ -93,23 +93,27 @@ export const SendTransactionErrorMessage = { "Something unexpected went wrong. Please try again.", }; -export enum SignMessageErrorCode { +export enum SignMessageErrorCodes { InvalidMessage = "invalid_message", UserRejected = "user_rejected", GenericError = "generic_error", } export const SignMessageErrorMessage = { - [SignMessageErrorCode.InvalidMessage]: "Invalid message requested", - [SignMessageErrorCode.UserRejected]: "User rejected the request.", - [SignMessageErrorCode.GenericError]: "Something unexpected went wrong.", + [SignMessageErrorCodes.InvalidMessage]: "Invalid message requested", + [SignMessageErrorCodes.UserRejected]: "User rejected the request.", + [SignMessageErrorCodes.GenericError]: "Something unexpected went wrong.", }; -export type SignTypedDataErrorCode = SignMessageErrorCode; +export enum SignTypedDataErrorCodes { + InvalidMessage = "invalid_message", + UserRejected = "user_rejected", + GenericError = "generic_error", +} export const SignTypedDataErrorMessage = SignMessageErrorMessage; -export enum MiniKitInstallErrorCode { +export enum MiniKitInstallErrorCodes { Unknown = "unknown", AlreadyInstalled = "already_installed", OutsideOfWorldApp = "outside_of_worldapp", @@ -118,11 +122,11 @@ export enum MiniKitInstallErrorCode { } export const MiniKitInstallErrorMessage = { - [MiniKitInstallErrorCode.Unknown]: "Failed to install MiniKit.", - [MiniKitInstallErrorCode.AlreadyInstalled]: "MiniKit is already installed.", - [MiniKitInstallErrorCode.OutsideOfWorldApp]: + [MiniKitInstallErrorCodes.Unknown]: "Failed to install MiniKit.", + [MiniKitInstallErrorCodes.AlreadyInstalled]: "MiniKit is already installed.", + [MiniKitInstallErrorCodes.OutsideOfWorldApp]: "MiniApp launched outside of WorldApp.", - [MiniKitInstallErrorCode.NotOnClient]: "Window object is not available.", - [MiniKitInstallErrorCode.AppOutOfDate]: + [MiniKitInstallErrorCodes.NotOnClient]: "Window object is not available.", + [MiniKitInstallErrorCodes.AppOutOfDate]: "WorldApp is out of date. Please update the app.", }; diff --git a/src/types/index.ts b/src/types/index.ts index f3db318a..5dc01687 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -16,4 +16,4 @@ export { export { Tokens } from "./payment"; export { SiweMessage } from "./wallet-auth"; -export { MiniKitInstallErrorCode, MiniKitInstallErrorMessage } from "./errors"; +export { MiniKitInstallErrorCodes, MiniKitInstallErrorMessage } from "./errors"; diff --git a/src/types/responses.ts b/src/types/responses.ts index f2dbac81..fcd1fc14 100644 --- a/src/types/responses.ts +++ b/src/types/responses.ts @@ -2,8 +2,8 @@ import { Network } from "./payment"; import { PaymentErrorCodes, SendTransactionErrorCodes, - SignMessageErrorCode, - SignTypedDataErrorCode, + SignMessageErrorCodes, + SignTypedDataErrorCodes, VerificationErrorCodes, WalletAuthErrorCodes, WalletAuthErrorMessage, @@ -102,12 +102,13 @@ export type MiniAppSendTransactionPayload = export type MiniAppSignMessageSuccessPayload = { status: "success"; signature: string; + address: string; version: number; }; export type MiniAppSignMessageErrorPayload = { status: "error"; - error_code: SignMessageErrorCode; + error_code: SignMessageErrorCodes; version: number; }; @@ -118,12 +119,13 @@ export type MiniAppSignMessagePayload = export type MiniAppSignTypedDataSuccessPayload = { status: "success"; signature: string; + address: string; version: number; }; export type MiniAppSignTypedDataErrorPayload = { status: "error"; - error_code: SignTypedDataErrorCode; + error_code: SignTypedDataErrorCodes; version: number; }; diff --git a/turbo.json b/turbo.json index f7764ee5..0b7765ea 100644 --- a/turbo.json +++ b/turbo.json @@ -1,6 +1,6 @@ { "$schema": "https://turbo.build/schema.json", - "pipeline": { + "tasks": { "build": { "dependsOn": ["^build"], "outputs": [".next/**", "!.next/cache/**"] @@ -12,6 +12,8 @@ "cache": false, "persistent": true }, - "type-check": {} + "type-check": { + "dependsOn": ["^check-types"] + } } }