Skip to content

Commit

Permalink
chore: ic_backend_types crate
Browse files Browse the repository at this point in the history
needed to be separate to properly compile the tests
  • Loading branch information
ilbertt committed Apr 11, 2024
1 parent 5749fe4 commit 009a0d2
Show file tree
Hide file tree
Showing 14 changed files with 61 additions and 30 deletions.
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 12 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
[workspace]
members = ["src/ic_backend"]
members = ["src/ic_backend", "src/ic_backend_types"]
resolver = "2"

[workspace.package]
edition = "2021"

[workspace.dependencies]
candid = "0.10"

serde = "1.0"
serde_bytes = "0.11"

ic_backend_types = { path = "src/ic_backend_types" }
12 changes: 7 additions & 5 deletions src/ic_backend/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,31 +1,33 @@
[package]
name = "ic_backend"
version = "0.1.0"
edition = "2021"
edition.workspace = true

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[lib]
crate-type = ["cdylib", "rlib"]
crate-type = ["cdylib"]

[dependencies]
candid = "0.10"
candid.workspace = true
ic-cdk = "0.13"
ic-cdk-timers = "0.7"
ic-stable-structures = "0.6"
ic-certified-map = "0.4"
canister_sig_util = { git = "https://github.com/dfinity/internet-identity", tag = "release-2024-04-05" }

serde = "1.0"
serde.workspace = true
serde_json = "1.0"
serde_bytes = "0.11"
serde_bytes.workspace = true

jsonwebtoken-rustcrypto = "1.2"
hex = "0.4"
getrandom = { version = "0.2", features = ["custom"] }
base64 = "0.21.0"
sha2 = "0.10.8"

ic_backend_types.workspace = true

[dev-dependencies]
hex-literal = "0.2.1"
pocket-ic = "2.2"
Expand Down
12 changes: 5 additions & 7 deletions src/ic_backend/src/delegation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@ use canister_sig_util::{
signature_map::{SignatureMap, LABEL_SIG},
CanisterSigPublicKey,
};
use ic_backend_types::{
Delegation, GetDelegationResponse, PublicKey, SessionKey, SignedDelegation, Timestamp, UserKey,
UserSub,
};
use ic_cdk::{api::set_certified_data, id};
use ic_certified_map::{labeled_hash, Hash};
use serde_bytes::ByteBuf;

use crate::{
hash, state,
types::{
Delegation, GetDelegationResponse, PublicKey, SessionKey, SignedDelegation, Timestamp,
UserKey, UserSub,
},
};
use crate::{hash, state};

pub async fn prepare_delegation(
user_sub: &UserSub,
Expand Down
16 changes: 6 additions & 10 deletions src/ic_backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@ mod delegation;
mod hash;
mod id_token;
mod state;
pub mod types;
mod users;
mod utils;

use candid::Principal;
use ic_backend_types::{
Auth0JWKSet, AuthenticatedResponse, GetDelegationResponse, PrepareDelegationResponse,
SessionKey, Timestamp, UserSub,
};
use ic_cdk::{api::is_controller, *};
use ic_cdk_timers::set_timer;
use ic_stable_structures::{
Expand All @@ -18,15 +21,8 @@ use id_token::IdToken;
use jsonwebtoken_rustcrypto::Algorithm;
use serde_bytes::ByteBuf;
use std::{cell::RefCell, time::Duration};
use types::Auth0JWKSet;

use crate::{
state::{Salt, State, EMPTY_SALT},
types::{
AuthenticatedResponse, GetDelegationResponse, PrepareDelegationResponse, SessionKey,
Timestamp, UserSub,
},
};

use crate::state::{Salt, State, EMPTY_SALT};

type Memory = VirtualMemory<DefaultMemoryImpl>;

Expand Down
4 changes: 2 additions & 2 deletions src/ic_backend/src/state.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
use std::time::Duration;

use canister_sig_util::signature_map::SignatureMap;
use ic_backend_types::Auth0JWKSet;
use ic_cdk::api::management_canister::http_request::{
http_request, CanisterHttpRequestArgument, HttpMethod,
};
use ic_cdk::{api::management_canister::main::raw_rand, trap};
use ic_cdk::{print, spawn};
use ic_cdk_timers::set_timer_interval;

use crate::id_token::AUTH0_ISSUER;
use crate::{types::Auth0JWKSet, SALT, STATE};
use crate::{id_token::AUTH0_ISSUER, SALT, STATE};

pub type Salt = [u8; 32];

Expand Down
3 changes: 2 additions & 1 deletion src/ic_backend/src/users.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use candid::Principal;
use ic_backend_types::UserSub;

use crate::{types::UserSub, utils::principal_to_blob, PRINCIPAL_USER_SUB};
use crate::{utils::principal_to_blob, PRINCIPAL_USER_SUB};

pub fn register_user(principal: Principal, user_sub: UserSub) {
PRINCIPAL_USER_SUB.with_borrow_mut(|s| s.insert(principal_to_blob(principal), user_sub));
Expand Down
2 changes: 1 addition & 1 deletion src/ic_backend/tests/common/auth_provider.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use base64::{engine::general_purpose, Engine as _};
use ic_backend::types::{Auth0JWK, Auth0JWKSet};
use ic_backend_types::{Auth0JWK, Auth0JWKSet};
use jwt_simple::prelude::*;

// ignore rust-analyzer errors on these environment variables
Expand Down
2 changes: 1 addition & 1 deletion src/ic_backend/tests/common/canister.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use candid::Principal;
use ic_backend::types::{Auth0JWKSet, GetDelegationResponse, PrepareDelegationResponse};
use ic_backend_types::{Auth0JWKSet, GetDelegationResponse, PrepareDelegationResponse};
use pocket_ic::{query_candid_as, update_candid_as, CallError, ErrorCode, UserError};

use super::test_env::TestEnv;
Expand Down
2 changes: 1 addition & 1 deletion src/ic_backend/tests/controller_only.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use common::{
test_env,
};
use ic_agent::Identity;
use ic_backend::types::Auth0JWKSet;
use ic_backend_types::Auth0JWKSet;

#[test]
fn test_sync_jwks_controller_only() {
Expand Down
2 changes: 1 addition & 1 deletion src/ic_backend/tests/delegation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::time::SystemTime;

use candid::Principal;
use ic_agent::Identity;
use ic_backend::types::{
use ic_backend_types::{
Delegation, GetDelegationResponse, PrepareDelegationResponse, SignedDelegation,
};
use jwt_simple::prelude::*;
Expand Down
10 changes: 10 additions & 0 deletions src/ic_backend_types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[package]
name = "ic_backend_types"
version = "0.1.0"
edition.workspace = true

[dependencies]
candid.workspace = true

serde.workspace = true
serde_bytes.workspace = true
3 changes: 3 additions & 0 deletions src/ic_backend_types/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
mod types;

pub use types::*;
File renamed without changes.

0 comments on commit 009a0d2

Please sign in to comment.