From 66b9354bca8a537b477dd344e42631a2ccb2693c Mon Sep 17 00:00:00 2001 From: bluecco Date: Thu, 15 Aug 2024 11:37:19 +0200 Subject: [PATCH] fix: get-starknet-core dependency --- package.json | 2 - pnpm-lock.yaml | 80 +++---- src/connectors/webwallet/helpers/trpc.ts | 2 +- src/types/window.ts | 261 +++++++++++++++++++++++ 4 files changed, 288 insertions(+), 57 deletions(-) create mode 100644 src/types/window.ts diff --git a/package.json b/package.json index 2acb95b..fd2cfe0 100644 --- a/package.json +++ b/package.json @@ -60,7 +60,6 @@ "dev": "vite build --watch" }, "dependencies": { - "@argent/x-window": "^1.0.2", "@starknet-io/get-starknet": "^4.0.0", "@starknet-io/get-starknet-core": "^4.0.0", "@starknet-io/types-js": "^0.7.7", @@ -71,7 +70,6 @@ "detect-browser": "^5.3.0", "eventemitter3": "^5.0.1", "events": "^3.3.0", - "get-starknet-coreV3": "npm:get-starknet-core@3.2.0", "lodash-es": "^4.17.21", "svelte-forms": "^2.3.1", "trpc-browser": "^1.3.2" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9c39b78..8eda2ca 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,9 +8,6 @@ importers: .: dependencies: - '@argent/x-window': - specifier: ^1.0.2 - version: 1.0.2(starknet@6.11.0)(zod@3.23.8) '@starknet-io/get-starknet': specifier: ^4.0.0 version: 4.0.0 @@ -41,9 +38,6 @@ importers: events: specifier: ^3.3.0 version: 3.3.0 - get-starknet-coreV3: - specifier: npm:get-starknet-core@3.2.0 - version: get-starknet-core@3.2.0(starknet@6.11.0) lodash-es: specifier: ^4.17.21 version: 4.17.21 @@ -140,7 +134,7 @@ importers: version: 5.1.4(@babel/core@7.25.2)(postcss-load-config@4.0.2(postcss@8.4.41)(ts-node@10.9.2(@types/node@20.14.15)(typescript@5.5.4)))(postcss@8.4.41)(svelte@4.2.18)(typescript@5.5.4) tailwindcss: specifier: ^3.1.6 - version: 3.4.9(ts-node@10.9.2(@types/node@20.5.1)(typescript@5.5.4)) + version: 3.4.10(ts-node@10.9.2(@types/node@20.5.1)(typescript@5.5.4)) tslib: specifier: ^2.4.0 version: 2.6.3 @@ -173,11 +167,6 @@ packages: resolution: {integrity: sha512-30iZtAPgz+LTIYoeivqYo853f02jBYSd5uGnGpkFV0M3xOt9aN73erkgYAmZU43x4VfqcnLxW9Kpg3R5LC4YYw==} engines: {node: '>=6.0.0'} - '@argent/x-window@1.0.2': - resolution: {integrity: sha512-36dtSxpB34ShLRxMdK9zsdGc9o2oCURB6w6g7rlFI3E1hlewUbA1sJ9XCrkpzNyokdsDZOaAJb4vOL7/XsKBkQ==} - peerDependencies: - zod: ^3.23.8 - '@babel/code-frame@7.24.7': resolution: {integrity: sha512-BcYH1CVJBO9tvyIZ2jVeXgSIMvGZ2FDRvDdOIVQyuklNKSsx+eppDEBq/g47Ayw+RqNFE+URvOShmf+f/qwAlA==} engines: {node: '>=6.9.0'} @@ -1283,11 +1272,11 @@ packages: '@volar/typescript@1.11.1': resolution: {integrity: sha512-iU+t2mas/4lYierSnoFOeRFQUhAEMgsFuQxoxvwn5EdQopw43j+J27a4lt9LMInx1gLJBC6qL14WYGlgymaSMQ==} - '@vue/compiler-core@3.4.37': - resolution: {integrity: sha512-ZDDT/KiLKuCRXyzWecNzC5vTcubGz4LECAtfGPENpo0nrmqJHwuWtRLxk/Sb9RAKtR9iFflFycbkjkY+W/PZUQ==} + '@vue/compiler-core@3.4.38': + resolution: {integrity: sha512-8IQOTCWnLFqfHzOGm9+P8OPSEDukgg3Huc92qSG49if/xI2SAwLHQO2qaPQbjCWPBcQoO1WYfXfTACUrWV3c5A==} - '@vue/compiler-dom@3.4.37': - resolution: {integrity: sha512-rIiSmL3YrntvgYV84rekAtU/xfogMUJIclUMeIKEtVBFngOL3IeZHhsH3UaFEgB5iFGpj6IW+8YuM/2Up+vVag==} + '@vue/compiler-dom@3.4.38': + resolution: {integrity: sha512-Osc/c7ABsHXTsETLgykcOwIxFktHfGSUDkb05V61rocEfsFDcjDLH/IHJSNJP+/Sv9KeN2Lx1V6McZzlSb9EhQ==} '@vue/language-core@1.8.27': resolution: {integrity: sha512-L8Kc27VdQserNaCUNiSFdDl9LWT24ly8Hpwf1ECy3aFb9m6bDhBGQYOujDm21N7EW3moKIOKEanQwe1q5BK+mA==} @@ -1297,8 +1286,8 @@ packages: typescript: optional: true - '@vue/shared@3.4.37': - resolution: {integrity: sha512-nIh8P2fc3DflG8+5Uw8PT/1i17ccFn0xxN/5oE9RfV5SVnd7G0XEFRwakrnNFE/jlS95fpGXDVG5zDETS26nmg==} + '@vue/shared@3.4.38': + resolution: {integrity: sha512-q0xCiLkuWWQLzVrecPb0RMsNWyxICOjPrcrwxTUEHb1fsnvni4dcuyG7RT/Ie7VPTvnjzIaWzRMUBsrqNj/hhw==} '@walletconnect/core@2.14.0': resolution: {integrity: sha512-E/dgBM9q3judXnTfZQ5ILvDpeSdDpabBLsXtYXa3Nyc26cfNplfLJ2nXm9FgtTdhM1nZ7yx4+zDPiXawBRZl2g==} @@ -2004,8 +1993,8 @@ packages: eastasianwidth@0.2.0: resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==} - electron-to-chromium@1.5.6: - resolution: {integrity: sha512-jwXWsM5RPf6j9dPYzaorcBSUg6AiqocPEyMpkchkvntaH9HGfOOMZwxMJjDY/XEs3T5dM7uyH1VhRMkqUU9qVw==} + electron-to-chromium@1.5.7: + resolution: {integrity: sha512-6FTNWIWMxMy/ZY6799nBlPtF1DFDQ6VQJ7yyDP27SJNt5lwtQ5ufqVvHylb3fdQefvRcgA3fKcFMJi9OLwBRNw==} emoji-regex@8.0.0: resolution: {integrity: sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==} @@ -2023,8 +2012,8 @@ packages: resolution: {integrity: sha512-LMHl3dXhTcfv8gM4kEzIUeTQ+7fpdA0l2tUf34BddXPkz2A5xJ5L/Pchd5BL6rdccM9QGvu0sWZzK1Z1t4wwyg==} engines: {node: '>=10.13.0'} - entities@5.0.0: - resolution: {integrity: sha512-BeJFvFRJddxobhvEdm5GqHzRV/X+ACeuw0/BuuxsCh1EUZcAIz8+kYmBp/LrQuloy6K1f3a0M7+IhmZ7QnkISA==} + entities@4.5.0: + resolution: {integrity: sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==} engines: {node: '>=0.12'} env-ci@9.1.1: @@ -2368,11 +2357,6 @@ packages: get-port-please@3.1.2: resolution: {integrity: sha512-Gxc29eLs1fbn6LQ4jSU4vXjlwyZhF5HsGuMAa7gqBP4Rw4yxxltyDUuF5MBclFzDTXO+ACchGQoeela4DSfzdQ==} - get-starknet-core@3.2.0: - resolution: {integrity: sha512-SZhxtLlKoPKLZ2H3l9WIU7CiNmkL3qLWGksALmvZdAXa/9PykYfLtvIB5B8A2UZMpf2ojTZlWLfuo1KhgmVobA==} - peerDependencies: - starknet: ^5.18.0 - get-starknet-core@4.0.0: resolution: {integrity: sha512-6pLmidQZkC3wZsrHY99grQHoGpuuXqkbSP65F8ov1/JsEI8DDLkhsAuLCKFzNOK56cJp+f1bWWfTJ57e9r5eqQ==} @@ -4209,8 +4193,8 @@ packages: resolution: {integrity: sha512-ulAk51I9UVUyJgxlv9M6lFot2WP3e7t8Kz9+IS6D4rVba1tR9kON+Ey69f+1R4Q8cd45Lod6a4IcJIxnzGc/zA==} engines: {node: '>=18'} - tailwindcss@3.4.9: - resolution: {integrity: sha512-1SEOvRr6sSdV5IDf9iC+NU4dhwdqzF4zKKq3sAbasUWHEM6lsMhX+eNN5gkPx1BvLFEnZQEUFbXnGj8Qlp83Pg==} + tailwindcss@3.4.10: + resolution: {integrity: sha512-KWZkVPm7yJRhdu4SRSl9d4AK2wM3a50UsvgHZO7xY77NQr2V+fIrEuoDGQcbvswWvFGbS2f6e+jC/6WJm1Dl0w==} engines: {node: '>=14.0.0'} hasBin: true @@ -4825,14 +4809,6 @@ snapshots: '@jridgewell/gen-mapping': 0.3.5 '@jridgewell/trace-mapping': 0.3.25 - '@argent/x-window@1.0.2(starknet@6.11.0)(zod@3.23.8)': - dependencies: - '@starknet-io/get-starknet-core': 4.0.0 - get-starknet-coreV3: get-starknet-core@3.2.0(starknet@6.11.0) - zod: 3.23.8 - transitivePeerDependencies: - - starknet - '@babel/code-frame@7.24.7': dependencies: '@babel/highlight': 7.24.7 @@ -6019,25 +5995,25 @@ snapshots: '@volar/language-core': 1.11.1 path-browserify: 1.0.1 - '@vue/compiler-core@3.4.37': + '@vue/compiler-core@3.4.38': dependencies: '@babel/parser': 7.25.3 - '@vue/shared': 3.4.37 - entities: 5.0.0 + '@vue/shared': 3.4.38 + entities: 4.5.0 estree-walker: 2.0.2 source-map-js: 1.2.0 - '@vue/compiler-dom@3.4.37': + '@vue/compiler-dom@3.4.38': dependencies: - '@vue/compiler-core': 3.4.37 - '@vue/shared': 3.4.37 + '@vue/compiler-core': 3.4.38 + '@vue/shared': 3.4.38 '@vue/language-core@1.8.27(typescript@5.5.4)': dependencies: '@volar/language-core': 1.11.1 '@volar/source-map': 1.11.1 - '@vue/compiler-dom': 3.4.37 - '@vue/shared': 3.4.37 + '@vue/compiler-dom': 3.4.38 + '@vue/shared': 3.4.38 computeds: 0.0.1 minimatch: 9.0.5 muggle-string: 0.3.1 @@ -6046,7 +6022,7 @@ snapshots: optionalDependencies: typescript: 5.5.4 - '@vue/shared@3.4.37': {} + '@vue/shared@3.4.38': {} '@walletconnect/core@2.14.0': dependencies: @@ -6622,7 +6598,7 @@ snapshots: browserslist@4.23.3: dependencies: caniuse-lite: 1.0.30001651 - electron-to-chromium: 1.5.6 + electron-to-chromium: 1.5.7 node-releases: 2.0.18 update-browserslist-db: 1.1.0(browserslist@4.23.3) @@ -7038,7 +7014,7 @@ snapshots: eastasianwidth@0.2.0: {} - electron-to-chromium@1.5.6: {} + electron-to-chromium@1.5.7: {} emoji-regex@8.0.0: {} @@ -7055,7 +7031,7 @@ snapshots: graceful-fs: 4.2.11 tapable: 2.2.1 - entities@5.0.0: {} + entities@4.5.0: {} env-ci@9.1.1: dependencies: @@ -7621,10 +7597,6 @@ snapshots: get-port-please@3.1.2: {} - get-starknet-core@3.2.0(starknet@6.11.0): - dependencies: - starknet: 6.11.0 - get-starknet-core@4.0.0: dependencies: '@starknet-io/types-js': 0.7.7 @@ -9464,7 +9436,7 @@ snapshots: system-architecture@0.1.0: {} - tailwindcss@3.4.9(ts-node@10.9.2(@types/node@20.5.1)(typescript@5.5.4)): + tailwindcss@3.4.10(ts-node@10.9.2(@types/node@20.5.1)(typescript@5.5.4)): dependencies: '@alloc/quick-lru': 5.2.0 arg: 5.0.2 diff --git a/src/connectors/webwallet/helpers/trpc.ts b/src/connectors/webwallet/helpers/trpc.ts index 2ebf698..956eb7c 100644 --- a/src/connectors/webwallet/helpers/trpc.ts +++ b/src/connectors/webwallet/helpers/trpc.ts @@ -8,7 +8,7 @@ import { RpcCallsArraySchema, StarknetMethodArgumentsSchemas, deployAccountContractSchema, -} from "@argent/x-window" +} from "../../../types/window" import { DEFAULT_WEBWALLET_URL } from "../constants" import { Permission } from "@starknet-io/types-js" diff --git a/src/types/window.ts b/src/types/window.ts new file mode 100644 index 0000000..e403884 --- /dev/null +++ b/src/types/window.ts @@ -0,0 +1,261 @@ +// moved this file from @argent/x-window +// in order to remove get-starknet-core v3 dependency and stakrnetjs v5 +// TODO: update x-window to export this file only, probably as a separate package + +import type { InvokeFunctionResponse, Signature } from "starknet" +import { z } from "zod" + +const HEX_REGEX = /^0x[0-9a-f]+$/i +const DECIMAL_REGEX = /^\d+$/ + +const shortStringSchema = z + .string() + .min(1, "The short string cannot be empty") + .max(31, "The short string cannot exceed 31 characters") + .refine( + (value) => !HEX_REGEX.test(value), + "The shortString should not be a hex string", + ) + .refine( + (value) => !DECIMAL_REGEX.test(value), + "The shortString should not be an integer string", + ) + +export const BigNumberishSchema = z.union([ + z + .string() + .regex( + HEX_REGEX, + "Only hex, integers and bigint are supported in calldata", + ), + z + .string() + .regex( + DECIMAL_REGEX, + "Only hex, integers and bigint are supported in calldata", + ), + shortStringSchema, + z.number().int("Only hex, integers and bigint are supported in calldata"), + z.bigint(), +]) + +export const CallSchema = z.object({ + contractAddress: z.string(), + entrypoint: z.string(), + calldata: z + .array(BigNumberishSchema.or(z.array(BigNumberishSchema))) + .optional(), +}) + +export const CallsArraySchema = z.array(CallSchema).nonempty() + +export const typedDataSchema = z.object({ + types: z.record( + z.array( + z.union([ + z.object({ + name: z.string(), + type: z.literal("merkletree"), + contains: z.string(), + }), + z.object({ + name: z.string(), + type: z.literal("enum"), + contains: z.string(), + }), + z.object({ + name: z.string(), + type: z.string(), + }), + ]), + ), + ), + primaryType: z.string(), + domain: z.record(z.unknown()), + message: z.record(z.unknown()), +}) + +export const AssetSchema = z.object({ + type: z.literal("ERC20"), + options: z.object({ + address: z.string(), + symbol: z.string().optional(), + decimals: z.number().optional(), + image: z.string().optional(), + name: z.string().optional(), + }), +}) + +export const AddStarknetChainParametersSchema = z.union([ + z.object({ + id: z.string(), + chain_id: z.string(), + chain_name: z.string(), + rpc_urls: z.array(z.string()).optional(), + native_currency: AssetSchema.optional(), + block_explorer_url: z.array(z.string()).optional(), + }), + z + .object({ + id: z.string(), + chainId: z.string(), + chainName: z.string(), + rpcUrls: z.array(z.string()).optional(), + nativeCurrency: AssetSchema.optional(), + blockExplorerUrl: z.array(z.string()).optional(), + }) + // for backwards compatibility + .transform((value) => ({ + id: value.id, + chain_id: value.chainId, + chain_name: value.chainName, + rpc_urls: value.rpcUrls, + native_currency: value.nativeCurrency, + block_explorer_url: value.blockExplorerUrl, + })), +]) +export const StarknetMethodArgumentsSchemas = { + enable: z + .tuple([ + z + .object({ + starknetVersion: z + .union([z.literal("v3"), z.literal("v4"), z.literal("v5")]) + .optional(), + }) + .optional(), + ]) + .or(z.tuple([])), + addStarknetChain: z.tuple([AddStarknetChainParametersSchema]), + switchStarknetChain: z.tuple([ + z.object({ + chainId: z.string(), + }), + ]), + watchAsset: z.tuple([AssetSchema]), + requestAccounts: z.tuple([ + z.object({ + silent_mode: z.boolean().optional(), + }), + ]), + execute: z.tuple([ + CallsArraySchema.or(CallSchema), + z + .object({ + nonce: BigNumberishSchema.optional(), + maxFee: BigNumberishSchema.optional(), + version: BigNumberishSchema.optional(), + }) + .optional(), + ]), + signMessage: z.tuple([typedDataSchema]), +} as const + +export type StarknetMethods = { + enable: ( + ...args: z.infer + ) => Promise + addStarknetChain: ( + ...args: z.infer + ) => Promise + switchStarknetChain: ( + ...args: z.infer + ) => Promise + watchAsset: ( + ...args: z.infer + ) => Promise + requestAccounts: ( + ...args: z.infer + ) => Promise + execute: ( + ...args: z.infer + ) => Promise + signMessage: ( + ...args: z.infer + ) => Promise + + getLoginStatus: () => Promise< + | { isLoggedIn: false } + | { isLoggedIn: true; hasSession: boolean; isPreauthorized: boolean } + > +} + +export const StarknetExecuteBackwardCompatibleArgumentsSchemas = { + execute: z + .tuple([ + CallsArraySchema.or(CallSchema), + z + .object({ + nonce: BigNumberishSchema.optional(), + maxFee: BigNumberishSchema.optional(), + version: BigNumberishSchema.optional(), + }) + .optional(), + ]) + .or( + z.tuple([ + CallsArraySchema.or(CallSchema), + z.array(z.any()).optional(), + z + .object({ + nonce: BigNumberishSchema.optional(), + maxFee: BigNumberishSchema.optional(), + version: BigNumberishSchema.optional(), + }) + .optional(), + ]), + ), +} as const + +export type StarknetExecuteBackwardCompatibleMethods = { + execute: ( + ...args: z.infer< + typeof StarknetExecuteBackwardCompatibleArgumentsSchemas.execute + > + ) => Promise +} + +export type ConnectMethods = { + connect: () => void +} + +export type ModalMethods = { + shouldShow: () => void + shouldHide: () => void + heightChanged: (height: number) => void +} + +export type WebWalletMethods = ConnectMethods & ModalMethods + +export type IframeMethods = { + connect: () => void +} + +export const RpcCallSchema = z + .object({ + contract_address: z.string(), + entry_point: z.string(), + calldata: z.array(BigNumberishSchema).optional(), + }) + .transform(({ contract_address, entry_point, calldata }) => ({ + contractAddress: contract_address, + entrypoint: entry_point, + calldata: calldata || [], + })) + +export const RpcCallsArraySchema = z.array(RpcCallSchema).nonempty() + +const VERSIONS = { + ZERO: 0, + ONE: 1, +} as const + +export const deployAccountContractSchema = z.object({ + address: z.string(), + class_hash: z.string(), + salt: z.string(), + calldata: z.array(z.string()), + sigdata: z.array(z.string()).optional(), + //version: z.literal([0, 1]), + version: z.nativeEnum(VERSIONS), // allow only 0 | 1, workaround since zod doesn't support literals as numbers +})