Skip to content

Commit

Permalink
Add SessionPolicies type
Browse files Browse the repository at this point in the history
  • Loading branch information
JunichiSugiura committed Dec 2, 2024
1 parent bd25e03 commit f3cfca0
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions packages/controller/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,13 @@ import {
import {
AddInvokeTransactionResult,
Signature,
StarknetDomain,
StarknetType,
TypedData,
} from "@starknet-io/types-js";
import { KeychainIFrame, ProfileIFrame } from "./iframe";

export type Session = {
chainId: constants.StarknetChainId;
policies: Policy[];
policies: SessionPolicies;
maxFee: BigNumberish;
expiresAt: bigint;
credentials: {
Expand All @@ -25,19 +23,31 @@ export type Session = {
};
};

export type Policy = CallPolicy | TypedDataPolicy;
/** The key must be the origin */
export type VerifiedConfigs = Record<string, VerifiedConfig>;

export type VerifiedConfig = {
origin: string;
policies?: SessionPolicies;
preset?: ControllerTheme;
};

/** It must contain one field */
export type SessionPolicies = {
/** The key must be the contract address */
call?: CallPolicies;
sign?: SignTypedDataPolicy[];
};

export type CallPolicies = Record<string, CallPolicy>;

export type CallPolicy = {
target: string;
method: string;
contractAddress: string;
methods: string[];
description?: string;
};

export type TypedDataPolicy = {
types: Record<string, StarknetType[]>;
primaryType: string;
domain: StarknetDomain;
};
export type SignTypedDataPolicy = Omit<TypedData, "message">;

export enum ResponseCodes {
SUCCESS = "SUCCESS",
Expand All @@ -62,7 +72,7 @@ export type ControllerError = {
export type ConnectReply = {
code: ResponseCodes.SUCCESS;
address: string;
policies: Policy[];
policies: SessionPolicies;
};

export type ExecuteReply =
Expand Down Expand Up @@ -95,7 +105,7 @@ export type ControllerAccounts = Record<ContractAddress, CartridgeID>;
export interface Keychain {
probe(rpcUrl: string): Promise<ProbeReply | ConnectError>;
connect(
policies: Policy[],
policies: SessionPolicies,
rpcUrl: string,
): Promise<ConnectReply | ConnectError>;
disconnect(): void;
Expand Down

0 comments on commit f3cfca0

Please sign in to comment.