diff --git a/package.json b/package.json index 996acbe..86d09fb 100644 --- a/package.json +++ b/package.json @@ -117,7 +117,7 @@ "zod": "^3.20.6" }, "peerDependencies": { - "starknet": "^6.9.0" + "starknet": "^6.11.0" }, "gitHead": "b16688a8638cc138938e74e1a39d004760165d75" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7e0978a..e520fda 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -42,7 +42,7 @@ importers: specifier: ^4.17.21 version: 4.17.21 starknet: - specifier: ^6.9.0 + specifier: ^6.11.0 version: 6.11.0 svelte-forms: specifier: ^2.3.1 @@ -7459,7 +7459,7 @@ snapshots: transitivePeerDependencies: - supports-color - eslint-module-utils@2.12.0(@typescript-eslint/parser@6.21.0(eslint@8.57.1)(typescript@5.7.2))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.7.0)(eslint@8.57.1): + eslint-module-utils@2.12.0(@typescript-eslint/parser@6.21.0(eslint@8.57.1)(typescript@5.7.2))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.7.0(eslint-plugin-import@2.31.0)(eslint@8.57.1))(eslint@8.57.1): dependencies: debug: 3.2.7 optionalDependencies: @@ -7481,7 +7481,7 @@ snapshots: doctrine: 2.1.0 eslint: 8.57.1 eslint-import-resolver-node: 0.3.9 - eslint-module-utils: 2.12.0(@typescript-eslint/parser@6.21.0(eslint@8.57.1)(typescript@5.7.2))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.7.0)(eslint@8.57.1) + eslint-module-utils: 2.12.0(@typescript-eslint/parser@6.21.0(eslint@8.57.1)(typescript@5.7.2))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.7.0(eslint-plugin-import@2.31.0)(eslint@8.57.1))(eslint@8.57.1) hasown: 2.0.2 is-core-module: 2.16.1 is-glob: 4.0.3 diff --git a/src/connectors/webwallet/helpers/trpc.ts b/src/connectors/webwallet/helpers/trpc.ts index 9fe64c0..043ba99 100644 --- a/src/connectors/webwallet/helpers/trpc.ts +++ b/src/connectors/webwallet/helpers/trpc.ts @@ -9,6 +9,7 @@ import { RpcCallsArraySchema, StarknetMethodArgumentsSchemas, deployAccountContractSchema, + typedDataSchema, } from "../../../types/window" import { DEFAULT_WEBWALLET_URL } from "../constants" @@ -84,6 +85,31 @@ const appRouter = t.router({ }), ) .mutation(async () => ({})), + connectAndSignSession: t.procedure + //.input(z.any()) + .input( + z.object({ + callbackData: z.string().optional(), + approvalRequests: z.array( + z.object({ + tokenAddress: z.string(), + amount: z.string(), + spender: z.string(), + }), + ), + sessionTypedData: typedDataSchema, + }), + ) + .output( + z.object({ + account: z.string().array().optional(), + chainId: z.string().optional(), + signature: z.string().array().optional(), + approvalTransactionHash: z.string().optional(), + deploymentPayload: z.any().optional(), + }), + ) + .mutation(async () => ({})), enable: t.procedure.output(z.string()).mutation(async () => ""), execute: t.procedure .input(StarknetMethodArgumentsSchemas.execute) diff --git a/src/connectors/webwallet/index.ts b/src/connectors/webwallet/index.ts index 8445a6c..aa0d974 100644 --- a/src/connectors/webwallet/index.ts +++ b/src/connectors/webwallet/index.ts @@ -5,11 +5,12 @@ import { type RpcTypeToMessageMap, type AccountChangeEventHandler, type StarknetWindowObject, + type TypedData, } from "@starknet-io/types-js" import { Account, - AccountInterface, - ProviderInterface, + type AccountInterface, + type ProviderInterface, type ProviderOptions, } from "starknet" import { @@ -32,6 +33,7 @@ import { type Theme, type WebWalletStarknetWindowObject, } from "./starknetWindowObject/argentStarknetWindowObject" +import type { ApprovalRequest } from "./starknetWindowObject/types" let _wallet: StarknetWindowObject | null = null let _address: string | null = null @@ -111,6 +113,30 @@ export class WebWalletConnector extends Connector { return "Powered by Argent" } + async connectAndSignSession({ + callbackData, + approvalRequests, + sessionTypedData, + }: { + callbackData?: string + approvalRequests: ApprovalRequest[] + sessionTypedData: TypedData + }) { + await this.ensureWallet() + + if (!this._wallet) { + throw new ConnectorNotFoundError() + } + + return await ( + this._wallet as WebWalletStarknetWindowObject + ).connectAndSignSession({ + callbackData, + approvalRequests, + sessionTypedData, + }) + } + async connect(_args: ConnectArgs = {}): Promise { await this.ensureWallet() @@ -244,4 +270,4 @@ export class WebWalletConnector extends Connector { } } -export type { WebWalletStarknetWindowObject } +export type { WebWalletStarknetWindowObject, ApprovalRequest } diff --git a/src/connectors/webwallet/starknetWindowObject/argentStarknetWindowObject.ts b/src/connectors/webwallet/starknetWindowObject/argentStarknetWindowObject.ts index fc6f1fa..3e68724 100644 --- a/src/connectors/webwallet/starknetWindowObject/argentStarknetWindowObject.ts +++ b/src/connectors/webwallet/starknetWindowObject/argentStarknetWindowObject.ts @@ -3,6 +3,7 @@ import type { NetworkChangeEventHandler, RpcTypeToMessageMap, StarknetWindowObject, + TypedData, WalletEvents, } from "@starknet-io/types-js" import type { CreateTRPCProxyClient } from "@trpc/client" @@ -14,6 +15,7 @@ import { SIGN_MESSAGE_POPUP_WIDTH, } from "../helpers/popupSizes" import { setPopupOptions, type AppRouter } from "../helpers/trpc" +import type { ApprovalRequest } from "./types" export const userEventHandlers: WalletEvents[] = [] @@ -52,6 +54,21 @@ export type WebWalletStarknetWindowObject = StarknetWindowObject & { account?: string[] chainId?: string }> + connectAndSignSession({ + callbackData, + approvalRequests, + sessionTypedData, + }: { + callbackData?: string + approvalRequests: ApprovalRequest[] + sessionTypedData: TypedData + }): Promise<{ + account?: string[] + chainId?: string + signature?: string[] + approvalTransactionHash?: string + deploymentPayload?: any + }> } export const getArgentStarknetWindowObject = ( @@ -67,6 +84,10 @@ export const getArgentStarknetWindowObject = ( const { theme } = props return proxyLink.connectWebwallet.mutate({ theme }) }, + connectAndSignSession: (props) => { + console.log("connectAndSignSession", props) + return proxyLink.connectAndSignSession.mutate(props) + }, connectWebwalletSSO: (token, authorizedPartyId) => { return proxyLink.connectWebwalletSSO.mutate({ token, authorizedPartyId }) }, diff --git a/src/connectors/webwallet/starknetWindowObject/types.ts b/src/connectors/webwallet/starknetWindowObject/types.ts new file mode 100644 index 0000000..7cd2f3f --- /dev/null +++ b/src/connectors/webwallet/starknetWindowObject/types.ts @@ -0,0 +1,9 @@ +export type Hex = `0x${string}` + +export type Address = Hex + +export type ApprovalRequest = { + tokenAddress: Address + amount: string + spender: Address +} diff --git a/src/types/window.ts b/src/types/window.ts index e403884..9c8aae8 100644 --- a/src/types/window.ts +++ b/src/types/window.ts @@ -72,7 +72,7 @@ export const typedDataSchema = z.object({ ), primaryType: z.string(), domain: z.record(z.unknown()), - message: z.record(z.unknown()), + message: z.record(z.unknown()).or(z.object({})), }) export const AssetSchema = z.object({