Skip to content

Commit 513dbab

Browse files
committed
chore: use ic_auth_types
1 parent 88d5818 commit 513dbab

File tree

11 files changed

+26
-54
lines changed

11 files changed

+26
-54
lines changed

Cargo.lock

Lines changed: 7 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ strip = true
1515
opt-level = 's'
1616

1717
[workspace.package]
18-
version = "0.6.11"
18+
version = "0.6.12"
1919
edition = "2021"
2020
repository = "https://github.com/ldclabs/ic-cose"
2121
keywords = ["config", "cbor", "canister", "icp", "encryption"]
@@ -46,6 +46,7 @@ icrc-ledger-types = "0.1"
4646
ic-certification = "3.0"
4747
ic-canister-sig-creation = "1.2"
4848
ic-agent = "0.39"
49+
ic_auth_types = "0.1"
4950
ic_auth_verifier = { version = "0.1" }
5051
getrandom = { version = "0.2", features = ["custom"] }
5152
rand = "0.8"

src/ic_cose/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ serde_bytes = { workspace = true }
1616
rand = { workspace = true }
1717
ic-agent = { workspace = true }
1818
x25519-dalek = { workspace = true }
19+
ic_auth_types = { workspace = true }
1920
ic_cose_types = { path = "../ic_cose_types", version = "0.6" }

src/ic_cose/src/client.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use candid::{
44
CandidType, Decode, Principal,
55
};
66
use ic_agent::Agent;
7+
use ic_auth_types::{SignInResponse, SignedDelegation};
78
use ic_cose_types::{
89
cose::{
910
ecdh::ecdh_x25519, encrypt0::cose_decrypt0, get_cose_key_secret, CborSerializable, CoseKey,
@@ -13,8 +14,7 @@ use ic_cose_types::{
1314
types::setting::*,
1415
types::{
1516
state::StateInfo, ECDHInput, ECDHOutput, PublicKeyInput, PublicKeyOutput, SchnorrAlgorithm,
16-
SettingPath, SignDelegationInput, SignDelegationOutput, SignIdentityInput, SignInput,
17-
SignedDelegation,
17+
SettingPath, SignDelegationInput, SignIdentityInput, SignInput,
1818
},
1919
BoxError, CanisterCaller,
2020
};
@@ -306,7 +306,7 @@ pub trait CoseSDK: CanisterCaller + Sized {
306306
async fn namespace_sign_delegation(
307307
&self,
308308
input: &SignDelegationInput,
309-
) -> Result<SignDelegationOutput, String> {
309+
) -> Result<SignInResponse, String> {
310310
self.canister_update(self.canister(), "namespace_sign_delegation", (input,))
311311
.await
312312
.map_err(format_error)?

src/ic_cose_canister/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,6 @@ ic-secp256k1 = { workspace = true }
2828
ic-ed25519 = { workspace = true }
2929
ic-canister-sig-creation = { workspace = true }
3030
ic-certification = { workspace = true }
31+
ic_auth_types = { workspace = true }
3132
ic_auth_verifier = { workspace = true }
3233
getrandom = { version = "0.2", features = ["custom"] }

src/ic_cose_canister/ic_cose_canister.did

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ type PublicKeyOutput = record { public_key : blob; chain_code : blob };
6464
type Result = variant { Ok; Err : text };
6565
type Result_1 = variant { Ok : NamespaceInfo; Err : text };
6666
type Result_10 = variant { Ok : vec record { principal; blob }; Err : text };
67-
type Result_11 = variant { Ok : SignDelegationOutput; Err : text };
67+
type Result_11 = variant { Ok : SignInResponse; Err : text };
6868
type Result_12 = variant { Ok : nat; Err : text };
6969
type Result_13 = variant { Ok : CreateSettingOutput; Err : text };
7070
type Result_14 = variant { Ok : SettingInfo; Err : text };
@@ -113,12 +113,12 @@ type SignDelegationInput = record {
113113
name : text;
114114
pubkey : blob;
115115
};
116-
type SignDelegationOutput = record {
116+
type SignIdentityInput = record { ns : text; audience : text };
117+
type SignInResponse = record {
117118
user_key : blob;
118119
seed : blob;
119120
expiration : nat64;
120121
};
121-
type SignIdentityInput = record { ns : text; audience : text };
122122
type SignInput = record {
123123
ns : text;
124124
derivation_path : vec blob;

src/ic_cose_canister/src/api_identity.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
use candid::Principal;
22
use ciborium::into_writer;
3+
use ic_auth_types::{Delegation, SignInResponse, SignedDelegation};
34
use ic_auth_verifier::{user_public_key_from_der, verify_basic_sig};
45
use ic_canister_sig_creation::{delegation_signature_msg, CanisterSigPublicKey};
56
use ic_cose_types::{
6-
types::{
7-
namespace::NamespaceDelegatorsInput, Delegation, SignDelegationInput, SignDelegationOutput,
8-
SignedDelegation,
9-
},
7+
types::{namespace::NamespaceDelegatorsInput, SignDelegationInput},
108
MILLISECONDS,
119
};
1210
use serde_bytes::ByteBuf;
@@ -81,7 +79,7 @@ fn namespace_remove_delegator(input: NamespaceDelegatorsInput) -> Result<(), Str
8179
}
8280

8381
#[ic_cdk::update]
84-
fn namespace_sign_delegation(input: SignDelegationInput) -> Result<SignDelegationOutput, String> {
82+
fn namespace_sign_delegation(input: SignDelegationInput) -> Result<SignInResponse, String> {
8583
store::state::allowed_api("namespace_sign_delegation")?;
8684
let caller = ic_cdk::caller();
8785
let now_ms = ic_cdk::api::time() / MILLISECONDS;
@@ -112,7 +110,7 @@ fn namespace_sign_delegation(input: SignDelegationInput) -> Result<SignDelegatio
112110
let delegation_hash = delegation_signature_msg(input.pubkey.as_slice(), expiration, None);
113111
store::state::add_signature(user_key.seed.as_slice(), delegation_hash.as_slice());
114112

115-
Ok(SignDelegationOutput {
113+
Ok(SignInResponse {
116114
expiration,
117115
user_key: user_key.to_der().into(),
118116
seed: user_key.seed.into(),

src/ic_cose_canister/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use candid::Principal;
2+
use ic_auth_types::*;
23
use ic_cose_types::{
34
format_error, types::namespace::*, types::setting::*, types::state::StateInfo, types::*,
45
ANONYMOUS,

src/ic_cose_canister/src/store.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -469,11 +469,7 @@ pub mod state {
469469
}
470470

471471
pub fn is_controller(caller: &Principal) -> bool {
472-
STATE.with_borrow(|s| {
473-
s.governance_canister
474-
.as_ref()
475-
.map_or(false, |p| p == caller)
476-
})
472+
STATE.with_borrow(|s| s.governance_canister.as_ref() == Some(caller))
477473
}
478474

479475
pub fn is_manager(caller: &Principal) -> bool {
@@ -720,7 +716,7 @@ pub mod ns {
720716
}
721717

722718
let setting = SETTINGS_STORE.with_borrow(|m| m.get(&spk.v0()));
723-
Ok(setting.map_or(false, |s| s.readers.contains(caller)))
719+
Ok(setting.is_some_and(|s| s.readers.contains(caller)))
724720
})
725721
.unwrap_or(false)
726722
}

src/ic_cose_types/src/types/mod.rs

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use candid::{CandidType, Principal};
1+
use candid::CandidType;
22
use serde::{Deserialize, Serialize};
33
use serde_bytes::{ByteArray, ByteBuf};
44
use std::collections::BTreeMap;
@@ -51,34 +51,10 @@ pub struct ECDHOutput<T> {
5151
pub public_key: ByteArray<32>, // server side ECDH public key
5252
}
5353

54-
#[derive(CandidType, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
55-
pub struct Delegation {
56-
pub pubkey: ByteBuf,
57-
pub expiration: u64,
58-
pub targets: Option<Vec<Principal>>,
59-
}
60-
61-
#[derive(CandidType, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
62-
pub struct SignedDelegation {
63-
pub delegation: Delegation,
64-
pub signature: ByteBuf,
65-
}
66-
6754
#[derive(CandidType, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
6855
pub struct SignDelegationInput {
6956
pub ns: String,
7057
pub name: String,
7158
pub pubkey: ByteBuf,
7259
pub sig: ByteBuf,
7360
}
74-
75-
#[derive(CandidType, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
76-
pub struct SignDelegationOutput {
77-
/// The session expiration time in nanoseconds since the UNIX epoch. This is the time at which
78-
/// the delegation will no longer be valid.
79-
pub expiration: u64,
80-
/// The user canister public key. This key is used to derive the user principal.
81-
pub user_key: ByteBuf,
82-
/// seed is a part of the user_key
83-
pub seed: ByteBuf,
84-
}

0 commit comments

Comments
 (0)