Skip to content

Commit

Permalink
Merge pull request #109 from argentlabs/fix/remove-offchain-sessions
Browse files Browse the repository at this point in the history
Fix/remove offchain sessions
  • Loading branch information
bluecco authored Jun 19, 2024
2 parents ebb50d2 + 586f3fe commit b7427d5
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 47 deletions.
2 changes: 0 additions & 2 deletions src/connectors/webwallet/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,3 @@ 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"
3 changes: 0 additions & 3 deletions src/connectors/webwallet/helpers/popupSizes.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
export const OFFCHAIN_SESSION_KEYS_EXECUTE_POPUP_WIDTH = 1
export const OFFCHAIN_SESSION_KEYS_EXECUTE_POPUP_HEIGHT = 1

/* all these sizes are optimistic */
export const EXECUTE_POPUP_WIDTH = 385
export const EXECUTE_POPUP_HEIGHT = 775
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import type { constants } from "starknet"
import type {
AccountChangeEventHandler,
NetworkChangeEventHandler,
RpcTypeToMessageMap,
StarknetWindowObject,
WalletEvents,
} from "starknet-types"
import { OFFCHAIN_SESSION_ENTRYPOINT } from "../constants"
import {
EXECUTE_POPUP_HEIGHT,
EXECUTE_POPUP_WIDTH,
Expand Down Expand Up @@ -52,10 +52,17 @@ export const getArgentStarknetWindowObject = (
}

case "wallet_signTypedData": {
const params =
call.params as RpcTypeToMessageMap["wallet_signTypedData"]["params"]

const isSession =
params?.primaryType === "Session" &&
params?.domain.name === "SessionAccount.session"

setPopupOptions({
width: SIGN_MESSAGE_POPUP_WIDTH,
height: SIGN_MESSAGE_POPUP_HEIGHT,
location: "/signMessage",
location: isSession ? "/signSessionKeys" : "/signMessage",
})
const data = Array.isArray(call.params) ? call.params : [call.params]
return proxyLink.signTypedData.mutate(data as any)
Expand All @@ -73,18 +80,7 @@ export const getArgentStarknetWindowObject = (
height: EXECUTE_POPUP_HEIGHT,
location: "/review",
})
if (
Array.isArray(calls) &&
calls[0] &&
calls[0].entrypoint === OFFCHAIN_SESSION_ENTRYPOINT
) {
setPopupOptions({
width: 1,
height: 1,
location: "/executeSessionTx",
atLeftBottom: true,
})
}

const hash = await proxyLink.addInvokeTransaction.mutate(calls)

return { transaction_hash: hash }
Expand Down
33 changes: 5 additions & 28 deletions src/window/window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,40 +227,17 @@ export type IframeMethods = {
connect: () => void
}

export const OffchainSessionDetailsSchema = z.object({
nonce: BigNumberishSchema,
maxFee: BigNumberishSchema.optional(),
version: z.string(),
})

export type OffchainSessionDetails = z.infer<
typeof OffchainSessionDetailsSchema
>

const OFFCHAIN_SESSION_ENTRYPOINT = "use_offchain_session"

export const RpcCallSchema = z
.object({
contract_address: z.string(),
entry_point: z.string(),
calldata: z.array(BigNumberishSchema).optional(),
offchainSessionDetails: OffchainSessionDetailsSchema.optional(),
})
.transform(
({ contract_address, entry_point, calldata, offchainSessionDetails }) =>
entry_point === OFFCHAIN_SESSION_ENTRYPOINT
? {
contractAddress: contract_address,
entrypoint: entry_point,
calldata: calldata || [],
offchainSessionDetails: offchainSessionDetails || undefined,
}
: {
contractAddress: contract_address,
entrypoint: entry_point,
calldata: calldata || [],
},
)
.transform(({ contract_address, entry_point, calldata }) => ({
contractAddress: contract_address,
entrypoint: entry_point,
calldata: calldata || [],
}))

export const RpcCallsArraySchema = z.array(RpcCallSchema).nonempty()

Expand Down

0 comments on commit b7427d5

Please sign in to comment.