Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/remove offchain sessions #109

Merged
merged 2 commits into from
Jun 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading