Skip to content

Commit

Permalink
feat: stark tx session key auth entry points
Browse files Browse the repository at this point in the history
  • Loading branch information
Orlando committed Apr 18, 2024
1 parent 66e5646 commit c609d30
Show file tree
Hide file tree
Showing 2 changed files with 143 additions and 5 deletions.
145 changes: 140 additions & 5 deletions starknet/src/authenticators/stark_tx_session_key.cairo
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
use starknet::ContractAddress;
use sx::types::{Strategy, IndexedStrategy, Choice};

#[starknet::interface]
trait IStarkTxSessionKeyAuthenticator<TContractState> {
fn authenticate_propose(
Expand Down Expand Up @@ -36,13 +39,145 @@ trait IStarkTxSessionKeyAuthenticator<TContractState> {
session_public_key: felt252
);

fn authorize_with_stark_tx(
ref self: ContractState, session_public_key: felt252, session_duration: u32
) {}
fn register_with_owner_tx(
ref self: TContractState,
owner: ContractAddress,
session_public_key: felt252,
session_duration: u32
);

fn revoke_with_owner_stark_tx(ref self: ContractState, session_public_key: felt252) {}
fn revoke_with_owner_tx(
ref self: TContractState, owner: ContractAddress, session_public_key: felt252
);

fn revoke_with_session_key_sig(
ref self: TContractState, sig: Array<felt252>, salt: felt252, session_public_key: felt252
ref self: TContractState,
signature: Array<felt252>,
owner: ContractAddress,
session_public_key: felt252,
salt: felt252
);
}

#[starknet::contract]
mod StarkTxSessionKeyAuthenticator {
use super::IStarkTxSessionKeyAuthenticator;
use starknet::ContractAddress;
use sx::types::{Strategy, IndexedStrategy, Choice, UserAddress};
use sx::utils::SessionKey;

#[storage]
struct Storage {}

#[external(v0)]
impl StarkTxSessionKeyAuthenticator of IStarkTxSessionKeyAuthenticator<ContractState> {
fn authenticate_propose(
ref self: ContractState,
signature: Array<felt252>,
space: ContractAddress,
author: ContractAddress,
metadata_uri: Array<felt252>,
execution_strategy: Strategy,
user_proposal_validation_params: Array<felt252>,
salt: felt252,
session_public_key: felt252
) {
let mut state = SessionKey::unsafe_new_contract_state();
SessionKey::InternalImpl::authenticate_propose(
ref state,
signature,
space,
UserAddress::Starknet(author),
metadata_uri,
execution_strategy,
user_proposal_validation_params,
salt,
session_public_key
);
}

fn authenticate_vote(
ref self: ContractState,
signature: Array<felt252>,
space: ContractAddress,
voter: ContractAddress,
proposal_id: u256,
choice: Choice,
user_voting_strategies: Array<IndexedStrategy>,
metadata_uri: Array<felt252>,
session_public_key: felt252
) {
let mut state = SessionKey::unsafe_new_contract_state();
SessionKey::InternalImpl::authenticate_vote(
ref state,
signature,
space,
UserAddress::Starknet(voter),
proposal_id,
choice,
user_voting_strategies,
metadata_uri,
session_public_key
);
}

fn authenticate_update_proposal(
ref self: ContractState,
signature: Array<felt252>,
space: ContractAddress,
author: ContractAddress,
proposal_id: u256,
execution_strategy: Strategy,
metadata_uri: Array<felt252>,
salt: felt252,
session_public_key: felt252
) {
let mut state = SessionKey::unsafe_new_contract_state();
SessionKey::InternalImpl::authenticate_update_proposal(
ref state,
signature,
space,
UserAddress::Starknet(author),
proposal_id,
execution_strategy,
metadata_uri,
salt,
session_public_key
);
}

fn register_with_owner_tx(
ref self: ContractState,
owner: ContractAddress,
session_public_key: felt252,
session_duration: u32
) {
let mut state = SessionKey::unsafe_new_contract_state();
SessionKey::InternalImpl::register_with_owner_stark_tx(
ref state, owner, session_public_key, session_duration
);
}

fn revoke_with_owner_tx(
ref self: ContractState, owner: ContractAddress, session_public_key: felt252
) {
let mut state = SessionKey::unsafe_new_contract_state();
SessionKey::InternalImpl::revoke_with_owner_stark_tx(
ref state, owner, session_public_key
);
}

fn revoke_with_session_key_sig(
ref self: ContractState,
signature: Array<felt252>,
owner: ContractAddress,
session_public_key: felt252,
salt: felt252
) {
let mut state = SessionKey::unsafe_new_contract_state();
SessionKey::InternalImpl::revoke_with_session_key_sig(
ref state, signature, UserAddress::Starknet(owner), session_public_key, salt
);
}
}
}
3 changes: 3 additions & 0 deletions starknet/src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ mod authenticators {

mod stark_sig_session_key;
use stark_sig_session_key::StarkSigSessionKeyAuthenticator;

mod stark_tx_session_key;
use stark_tx_session_key::StarkTxSessionKeyAuthenticator;
}

mod execution_strategies {
Expand Down

0 comments on commit c609d30

Please sign in to comment.