diff --git a/src/connectors/webwallet/constants.ts b/src/connectors/webwallet/constants.ts index c0357e0..76e9a69 100644 --- a/src/connectors/webwallet/constants.ts +++ b/src/connectors/webwallet/constants.ts @@ -26,3 +26,5 @@ export const RPC_NODE_URL_TESTNET = export const RPC_NODE_URL_MAINNET = "https://cloud.argent-api.com/v1/starknet/mainnet/rpc/v0.6" + +export const OFFCHAIN_SESSION_ENTRYPOINT = "use_offchain_session" diff --git a/src/connectors/webwallet/starknetWindowObject/account.ts b/src/connectors/webwallet/starknetWindowObject/account.ts index 5a3a525..a93b217 100644 --- a/src/connectors/webwallet/starknetWindowObject/account.ts +++ b/src/connectors/webwallet/starknetWindowObject/account.ts @@ -16,6 +16,7 @@ import { SIGN_MESSAGE_POPUP_HEIGHT, SIGN_MESSAGE_POPUP_WIDTH, } from "../helpers/popupSizes" +import { OFFCHAIN_SESSION_ENTRYPOINT } from "../constants" class UnimplementedSigner implements SignerInterface { async getPubKey(): Promise { @@ -64,7 +65,7 @@ export class MessageAccount extends Account implements AccountInterface { if ( Array.isArray(calls) && calls[0] && - calls[0].entrypoint === "use_offchain_session" + calls[0].entrypoint === OFFCHAIN_SESSION_ENTRYPOINT ) { setPopupOptions({ width: 1, diff --git a/src/connectors/webwallet/starknetWindowObject/argentStarknetWindowObject.ts b/src/connectors/webwallet/starknetWindowObject/argentStarknetWindowObject.ts index 8a3ead7..db7c1d4 100644 --- a/src/connectors/webwallet/starknetWindowObject/argentStarknetWindowObject.ts +++ b/src/connectors/webwallet/starknetWindowObject/argentStarknetWindowObject.ts @@ -14,6 +14,7 @@ import { SIGN_MESSAGE_POPUP_HEIGHT, SIGN_MESSAGE_POPUP_WIDTH, } from "../helpers/popupSizes" +import { OFFCHAIN_SESSION_ENTRYPOINT } from "../constants" export const userEventHandlers: WalletEvents[] = [] @@ -77,7 +78,7 @@ export const getArgentStarknetWindowObject = ( if ( Array.isArray(calls) && calls[0] && - calls[0].entrypoint === "use_offchain_session" + calls[0].entrypoint === OFFCHAIN_SESSION_ENTRYPOINT ) { setPopupOptions({ width: 1, @@ -86,9 +87,7 @@ export const getArgentStarknetWindowObject = ( atLeftBottom: true, }) } - const hash = await proxyLink.addInvokeTransaction.mutate( - (call.params as any).calls, - ) + const hash = await proxyLink.addInvokeTransaction.mutate(calls) return { transaction_hash: hash } } diff --git a/src/types/window.ts b/src/types/window.ts index 4740315..a0dcaca 100644 --- a/src/types/window.ts +++ b/src/types/window.ts @@ -1,3 +1,4 @@ +import { OFFCHAIN_SESSION_ENTRYPOINT } from "../connectors/webwallet/constants" import type { InvokeFunctionResponse, Signature } from "starknet" import { z } from "zod" @@ -164,16 +165,33 @@ export type IframeMethods = { connect: () => void } +export const OffchainSessionDetailsSchema = z.object({ + nonce: bignumberishSchema, + maxFee: bignumberishSchema.optional(), + version: z.string(), +}) + export const RpcCallSchema = z .object({ contract_address: z.string(), entrypoint: z.string(), calldata: z.array(bignumberishSchema).optional(), + offchainSessionDetails: OffchainSessionDetailsSchema.optional(), }) - .transform(({ contract_address, entrypoint, calldata }) => ({ - contractAddress: contract_address, - entrypoint, - calldata: calldata || [], - })) + .transform( + ({ contract_address, entrypoint, calldata, offchainSessionDetails }) => + entrypoint === OFFCHAIN_SESSION_ENTRYPOINT + ? { + contractAddress: contract_address, + entrypoint, + calldata: calldata || [], + offchainSessionDetails: offchainSessionDetails || undefined, + } + : { + contractAddress: contract_address, + entrypoint, + calldata: calldata || [], + }, + ) export const RpcCallsArraySchema = z.array(RpcCallSchema).nonempty()