diff --git a/src/console/console.did b/src/console/console.did index 152d748729..ee5fadca2e 100644 --- a/src/console/console.did +++ b/src/console/console.did @@ -52,7 +52,7 @@ type AuthenticationConfigInternetIdentity = record { }; type AuthenticationConfigOpenId = record { observatory_id : opt principal; - providers : vec record { OpenIdProvider; OpenIdProviderConfig }; + providers : vec record { OpenIdDelegationProvider; OpenIdProviderConfig }; }; type AuthenticationError = variant { PrepareDelegation : PrepareDelegationError; @@ -223,7 +223,7 @@ type ListSegmentsArgs = record { segment_kind : opt StorableSegmentKind; }; type Memory = variant { Heap; Stable }; -type OpenId = record { provider : OpenIdProvider; data : OpenIdData }; +type OpenId = record { provider : OpenIdDelegationProvider; data : OpenIdData }; type OpenIdData = record { name : opt text; locale : opt text; @@ -233,6 +233,7 @@ type OpenIdData = record { given_name : opt text; preferred_username : opt text; }; +type OpenIdDelegationProvider = variant { GitHub; Google }; type OpenIdGetDelegationArgs = record { jwt : text; session_key : blob; @@ -244,7 +245,6 @@ type OpenIdPrepareDelegationArgs = record { session_key : blob; salt : blob; }; -type OpenIdProvider = variant { GitHub; Google }; type OpenIdProviderConfig = record { delegation : opt OpenIdProviderDelegationConfig; client_id : text; diff --git a/src/console/src/auth/delegation.rs b/src/console/src/auth/delegation.rs index 78a9fc0a96..534180d036 100644 --- a/src/console/src/auth/delegation.rs +++ b/src/console/src/auth/delegation.rs @@ -4,13 +4,19 @@ use junobuild_auth::delegation::types::{ GetDelegationError, GetDelegationResult, OpenIdGetDelegationArgs, OpenIdPrepareDelegationArgs, PrepareDelegationError, PreparedDelegation, }; +use junobuild_auth::openid::delegation::types::provider::OpenIdDelegationProvider; use junobuild_auth::openid::types::interface::OpenIdCredential; -use junobuild_auth::openid::types::provider::OpenIdProvider; use junobuild_auth::state::types::config::OpenIdProviders; use junobuild_auth::{delegation, openid}; -pub type OpenIdPrepareDelegationResult = - Result<(PreparedDelegation, OpenIdProvider, OpenIdCredential), PrepareDelegationError>; +pub type OpenIdPrepareDelegationResult = Result< + ( + PreparedDelegation, + OpenIdDelegationProvider, + OpenIdCredential, + ), + PrepareDelegationError, +>; pub async fn openid_prepare_delegation( args: &OpenIdPrepareDelegationArgs, diff --git a/src/console/src/auth/register.rs b/src/console/src/auth/register.rs index 5dec898413..2b5007739a 100644 --- a/src/console/src/auth/register.rs +++ b/src/console/src/auth/register.rs @@ -3,12 +3,12 @@ use crate::types::state::OpenId; use crate::types::state::{Account, OpenIdData, Provider}; use candid::Principal; use junobuild_auth::delegation::types::UserKey; +use junobuild_auth::openid::delegation::types::provider::OpenIdDelegationProvider; use junobuild_auth::openid::types::interface::OpenIdCredential; -use junobuild_auth::openid::types::provider::OpenIdProvider; pub async fn register_account( public_key: &UserKey, - provider: &OpenIdProvider, + provider: &OpenIdDelegationProvider, credential: &OpenIdCredential, ) -> Result { let user_id = Principal::self_authenticating(public_key); diff --git a/src/console/src/lib.rs b/src/console/src/lib.rs index 02650cc546..d4432531bb 100644 --- a/src/console/src/lib.rs +++ b/src/console/src/lib.rs @@ -17,6 +17,7 @@ mod rates; mod segments; mod store; mod types; +mod upgrade; use crate::types::interface::AuthenticationArgs; use crate::types::interface::AuthenticationResult; diff --git a/src/console/src/memory/lifecycle.rs b/src/console/src/memory/lifecycle.rs index c4d911d416..8f1eebddbb 100644 --- a/src/console/src/memory/lifecycle.rs +++ b/src/console/src/memory/lifecycle.rs @@ -4,6 +4,7 @@ use crate::fees::init_factory_fees; use crate::memory::manager::{get_memory_upgrades, init_stable_state, STATE}; use crate::rates::init::init_factory_rates; use crate::types::state::{HeapState, ReleasesMetadata, State}; +use crate::upgrade::types::upgrade::UpgradeState; use ciborium::{from_reader, into_writer}; use ic_cdk_macros::{init, post_upgrade, pre_upgrade}; use junobuild_shared::ic::api::caller; @@ -50,9 +51,12 @@ fn post_upgrade() { let memory = get_memory_upgrades(); let state_bytes = read_post_upgrade(&memory); - let state: State = from_reader(&*state_bytes) + // TODO: remove once OpenIdProvider migrated on mainnet + let upgrade_state: UpgradeState = from_reader(&*state_bytes) .expect("Failed to decode the state of the console in post_upgrade hook."); + let state: State = upgrade_state.into(); + STATE.with(|s| *s.borrow_mut() = state); defer_init_certified_assets(); diff --git a/src/console/src/types.rs b/src/console/src/types.rs index 7af84477c8..70eb514de2 100644 --- a/src/console/src/types.rs +++ b/src/console/src/types.rs @@ -4,7 +4,7 @@ pub mod state { use candid::CandidType; use ic_ledger_types::{BlockIndex, Tokens}; use ic_stable_structures::StableBTreeMap; - use junobuild_auth::openid::types::provider::OpenIdProvider; + use junobuild_auth::openid::delegation::types::provider::OpenIdDelegationProvider; use junobuild_auth::state::types::state::AuthenticationHeapState; use junobuild_cdn::proposals::{ProposalsStable, SegmentDeploymentVersion}; use junobuild_cdn::storage::{ProposalAssetsStable, ProposalContentChunksStable}; @@ -83,7 +83,7 @@ pub mod state { #[derive(CandidType, Serialize, Deserialize, Clone)] pub struct OpenId { - pub provider: OpenIdProvider, + pub provider: OpenIdDelegationProvider, pub data: OpenIdData, } diff --git a/src/console/src/upgrade/impls.rs b/src/console/src/upgrade/impls.rs new file mode 100644 index 0000000000..ddff22dee9 --- /dev/null +++ b/src/console/src/upgrade/impls.rs @@ -0,0 +1,56 @@ +use crate::types::state::{HeapState, State}; +use crate::upgrade::types::upgrade::{ + UpgradeAuthenticationHeapState, UpgradeHeapState, UpgradeOpenIdProvider, UpgradeState, +}; +use junobuild_auth::openid::types::provider::OpenIdProvider; +use junobuild_auth::state::types::state::{AuthenticationHeapState, OpenIdState}; + +impl From for State { + fn from(upgrade: UpgradeState) -> Self { + State { + stable: upgrade.stable, + heap: upgrade.heap.into(), + } + } +} + +impl From for HeapState { + fn from(upgrade: UpgradeHeapState) -> Self { + HeapState { + authentication: upgrade.authentication.map(|auth| auth.into()), + controllers: upgrade.controllers, + mission_controls: upgrade.mission_controls, + payments: upgrade.payments, + invitation_codes: upgrade.invitation_codes, + factory_fees: upgrade.factory_fees, + factory_rates: upgrade.factory_rates, + storage: upgrade.storage, + releases_metadata: upgrade.releases_metadata, + } + } +} + +impl From for AuthenticationHeapState { + fn from(upgrade: UpgradeAuthenticationHeapState) -> Self { + AuthenticationHeapState { + config: upgrade.config, + salt: upgrade.salt, + openid: upgrade.openid.map(|openid_state| OpenIdState { + certificates: openid_state + .certificates + .into_iter() + .map(|(provider, cert)| (provider.into(), cert)) + .collect(), + }), + } + } +} + +impl From for OpenIdProvider { + fn from(old: UpgradeOpenIdProvider) -> Self { + match old { + UpgradeOpenIdProvider::Google => OpenIdProvider::Google, + UpgradeOpenIdProvider::GitHub => OpenIdProvider::GitHubAuth, + } + } +} diff --git a/src/console/src/upgrade/mod.rs b/src/console/src/upgrade/mod.rs new file mode 100644 index 0000000000..39fcb9cfe1 --- /dev/null +++ b/src/console/src/upgrade/mod.rs @@ -0,0 +1,2 @@ +mod impls; +pub mod types; diff --git a/src/console/src/upgrade/types.rs b/src/console/src/upgrade/types.rs new file mode 100644 index 0000000000..cde8370010 --- /dev/null +++ b/src/console/src/upgrade/types.rs @@ -0,0 +1,58 @@ +pub mod upgrade { + use crate::memory::manager::init_stable_state; + use crate::types::state::{ + Accounts, FactoryFees, FactoryRates, IcpPayments, InvitationCodes, ReleasesMetadata, + StableState, + }; + use candid::{CandidType, Deserialize}; + use junobuild_auth::state::types::config::AuthenticationConfig; + use junobuild_auth::state::types::state::{OpenIdCachedCertificate, Salt}; + use junobuild_shared::types::state::Controllers; + use junobuild_storage::types::state::StorageHeapState; + use serde::Serialize; + use std::collections::HashMap; + + #[derive(Serialize, Deserialize)] + pub struct UpgradeState { + // Direct stable state: State that is uses stable memory directly as its store. No need for pre/post upgrade hooks. + #[serde(skip, default = "init_stable_state")] + pub stable: StableState, + + pub heap: UpgradeHeapState, + } + + #[derive(Default, CandidType, Serialize, Deserialize, Clone)] + pub struct UpgradeHeapState { + #[deprecated(note = "Deprecated. Use stable memory instead.")] + pub mission_controls: Accounts, + #[deprecated(note = "Deprecated. Use stable memory instead.")] + pub payments: IcpPayments, + pub invitation_codes: InvitationCodes, + pub controllers: Controllers, + pub factory_fees: Option, + pub factory_rates: Option, + pub storage: StorageHeapState, + pub authentication: Option, + pub releases_metadata: ReleasesMetadata, + } + + #[derive(Default, CandidType, Serialize, Deserialize, Clone)] + pub struct UpgradeAuthenticationHeapState { + pub config: AuthenticationConfig, + pub salt: Option, + pub openid: Option, + } + + #[derive(Default, CandidType, Serialize, Deserialize, Clone)] + pub struct UpgradeOpenIdState { + pub certificates: HashMap, + } + + #[derive( + CandidType, Serialize, Deserialize, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Debug, + )] + pub enum UpgradeOpenIdProvider { + Google, + GitHub, + } +} diff --git a/src/declarations/_factory.ts b/src/declarations/_factory.ts index 094d19010b..c2f9e4aa8a 100644 --- a/src/declarations/_factory.ts +++ b/src/declarations/_factory.ts @@ -4,10 +4,12 @@ import { idlFactory as idlFactoryConsole0014 } from '$declarations/deprecated/co import { idlFactory as idlFactoryConsole008 } from '$declarations/deprecated/console-0-0-8-patch1.factory.did'; import { idlFactory as idlFactoryConsole015 } from '$declarations/deprecated/console-0-1-5.factory.did'; import { idlFactory as idlFactoryConsole020 } from '$declarations/deprecated/console-0-2-0.factory.did'; +import { idlFactory as idlFactoryConsole033 } from '$declarations/deprecated/console-0-3-3.factory.did'; import { idlFactory as idlFactoryMissionControl0013 } from '$declarations/deprecated/mission_control-0-0-13.factory.did'; import { idlFactory as idlFactoryMissionControl0014 } from '$declarations/deprecated/mission_control-0-0-14.factory.did'; import { idlFactory as idlFactoryMissionControl004 } from '$declarations/deprecated/mission_control-0-0-4.factory.did'; import { idlFactory as idlFactoryObservatory009 } from '$declarations/deprecated/observatory-0-0-9.factory.did'; +import { idlFactory as idlFactoryObservatory040 } from '$declarations/deprecated/observatory-0-4-0.factory.did'; import { idlFactory as idlFactoryOrbiter006 } from '$declarations/deprecated/orbiter-0-0-6.factory.did'; import { idlFactory as idlFactoryOrbiter007 } from '$declarations/deprecated/orbiter-0-0-7.factory.did'; import { idlFactory as idlFactoryOrbiter008 } from '$declarations/deprecated/orbiter-0-0-8.factory.did'; @@ -31,10 +33,12 @@ import type { _SERVICE as ConsoleActor0014 } from '$declarations/deprecated/cons import type { _SERVICE as ConsoleActor008 } from '$declarations/deprecated/console-0-0-8-patch1.did'; import type { _SERVICE as ConsoleActor015 } from '$declarations/deprecated/console-0-1-5.did'; import type { _SERVICE as ConsoleActor020 } from '$declarations/deprecated/console-0-2-0.did'; +import type { _SERVICE as ConsoleActor033 } from '$declarations/deprecated/console-0-3-3.did'; import type { _SERVICE as MissionControlActor0013 } from '$declarations/deprecated/mission_control-0-0-13.did'; import type { _SERVICE as MissionControlActor0014 } from '$declarations/deprecated/mission_control-0-0-14.did'; import type { _SERVICE as MissionControlActor004 } from '$declarations/deprecated/mission_control-0-0-4.did'; import type { _SERVICE as ObservatoryActor009 } from '$declarations/deprecated/observatory-0-0-9.did'; +import type { _SERVICE as ObservatoryActor040 } from '$declarations/deprecated/observatory-0-4-0.did'; import type { _SERVICE as OrbiterActor006 } from '$declarations/deprecated/orbiter-0-0-6.did'; import type { _SERVICE as OrbiterActor007 } from '$declarations/deprecated/orbiter-0-0-7.did'; import type { _SERVICE as OrbiterActor008 } from '$declarations/deprecated/orbiter-0-0-8.did'; @@ -60,6 +64,7 @@ export { idlFactoryConsole008, idlFactoryConsole015, idlFactoryConsole020, + idlFactoryConsole033, idlFactoryIC, idlFactoryMissionControl, idlFactoryMissionControl0013, @@ -67,6 +72,7 @@ export { idlFactoryMissionControl004, idlFactoryObservatory, idlFactoryObservatory009, + idlFactoryObservatory040, idlFactoryOrbiter, idlFactoryOrbiter006, idlFactoryOrbiter007, @@ -85,6 +91,7 @@ export { type ConsoleActor008, type ConsoleActor015, type ConsoleActor020, + type ConsoleActor033, type ICActor, type MissionControlActor, type MissionControlActor0013, @@ -92,6 +99,7 @@ export { type MissionControlActor004, type ObservatoryActor, type ObservatoryActor009, + type ObservatoryActor040, type OrbiterActor, type OrbiterActor006, type OrbiterActor007, diff --git a/src/declarations/_types.ts b/src/declarations/_types.ts index 41b996ff19..7a342c7a39 100644 --- a/src/declarations/_types.ts +++ b/src/declarations/_types.ts @@ -1,7 +1,9 @@ import type * as ConsoleDid from '$declarations/console/console.did'; import type * as ConsoleDid020 from '$declarations/deprecated/console-0-2-0.did'; +import type * as ConsoleDid033 from '$declarations/deprecated/console-0-3-3.did'; import type * as MissionControlDid0013 from '$declarations/deprecated/mission_control-0-0-13.did'; import type * as MissionControlDid004 from '$declarations/deprecated/mission_control-0-0-4.did'; +import type * as ObservatoryDid040 from '$declarations/deprecated/observatory-0-4-0.did'; import type * as OrbiterDid006 from '$declarations/deprecated/orbiter-0-0-6.did'; import type * as OrbiterDid007 from '$declarations/deprecated/orbiter-0-0-7.did'; import type * as OrbiterDid008 from '$declarations/deprecated/orbiter-0-0-8.did'; @@ -18,11 +20,13 @@ import type * as SputnikDid from '$declarations/sputnik/sputnik.did'; export type { ConsoleDid, ConsoleDid020, + ConsoleDid033, ICDid, MissionControlDid, MissionControlDid0013, MissionControlDid004, ObservatoryDid, + ObservatoryDid040, OrbiterDid, OrbiterDid006, OrbiterDid007, diff --git a/src/declarations/console/console.did.d.ts b/src/declarations/console/console.did.d.ts index c084e35f32..2fc936f0aa 100644 --- a/src/declarations/console/console.did.d.ts +++ b/src/declarations/console/console.did.d.ts @@ -69,7 +69,7 @@ export interface AuthenticationConfigInternetIdentity { } export interface AuthenticationConfigOpenId { observatory_id: [] | [Principal]; - providers: Array<[OpenIdProvider, OpenIdProviderConfig]>; + providers: Array<[OpenIdDelegationProvider, OpenIdProviderConfig]>; } export type AuthenticationError = | { @@ -277,7 +277,7 @@ export interface ListSegmentsArgs { } export type Memory = { Heap: null } | { Stable: null }; export interface OpenId { - provider: OpenIdProvider; + provider: OpenIdDelegationProvider; data: OpenIdData; } export interface OpenIdData { @@ -289,6 +289,7 @@ export interface OpenIdData { given_name: [] | [string]; preferred_username: [] | [string]; } +export type OpenIdDelegationProvider = { GitHub: null } | { Google: null }; export interface OpenIdGetDelegationArgs { jwt: string; session_key: Uint8Array; @@ -300,7 +301,6 @@ export interface OpenIdPrepareDelegationArgs { session_key: Uint8Array; salt: Uint8Array; } -export type OpenIdProvider = { GitHub: null } | { Google: null }; export interface OpenIdProviderConfig { delegation: [] | [OpenIdProviderDelegationConfig]; client_id: string; diff --git a/src/declarations/console/console.factory.certified.did.js b/src/declarations/console/console.factory.certified.did.js index ef34c851dc..97f5e8ffb4 100644 --- a/src/declarations/console/console.factory.certified.did.js +++ b/src/declarations/console/console.factory.certified.did.js @@ -24,7 +24,7 @@ export const idlFactory = ({ IDL }) => { user_key: IDL.Vec(IDL.Nat8), expiration: IDL.Nat64 }); - const OpenIdProvider = IDL.Variant({ + const OpenIdDelegationProvider = IDL.Variant({ GitHub: IDL.Null, Google: IDL.Null }); @@ -38,7 +38,7 @@ export const idlFactory = ({ IDL }) => { preferred_username: IDL.Opt(IDL.Text) }); const OpenId = IDL.Record({ - provider: OpenIdProvider, + provider: OpenIdDelegationProvider, data: OpenIdData }); const Provider = IDL.Variant({ @@ -143,7 +143,7 @@ export const idlFactory = ({ IDL }) => { }); const AuthenticationConfigOpenId = IDL.Record({ observatory_id: IDL.Opt(IDL.Principal), - providers: IDL.Vec(IDL.Tuple(OpenIdProvider, OpenIdProviderConfig)) + providers: IDL.Vec(IDL.Tuple(OpenIdDelegationProvider, OpenIdProviderConfig)) }); const AuthenticationConfigInternetIdentity = IDL.Record({ derivation_origin: IDL.Opt(IDL.Text), diff --git a/src/declarations/console/console.factory.did.js b/src/declarations/console/console.factory.did.js index 250efe59ac..03577a29a2 100644 --- a/src/declarations/console/console.factory.did.js +++ b/src/declarations/console/console.factory.did.js @@ -24,7 +24,7 @@ export const idlFactory = ({ IDL }) => { user_key: IDL.Vec(IDL.Nat8), expiration: IDL.Nat64 }); - const OpenIdProvider = IDL.Variant({ + const OpenIdDelegationProvider = IDL.Variant({ GitHub: IDL.Null, Google: IDL.Null }); @@ -38,7 +38,7 @@ export const idlFactory = ({ IDL }) => { preferred_username: IDL.Opt(IDL.Text) }); const OpenId = IDL.Record({ - provider: OpenIdProvider, + provider: OpenIdDelegationProvider, data: OpenIdData }); const Provider = IDL.Variant({ @@ -143,7 +143,7 @@ export const idlFactory = ({ IDL }) => { }); const AuthenticationConfigOpenId = IDL.Record({ observatory_id: IDL.Opt(IDL.Principal), - providers: IDL.Vec(IDL.Tuple(OpenIdProvider, OpenIdProviderConfig)) + providers: IDL.Vec(IDL.Tuple(OpenIdDelegationProvider, OpenIdProviderConfig)) }); const AuthenticationConfigInternetIdentity = IDL.Record({ derivation_origin: IDL.Opt(IDL.Text), diff --git a/src/declarations/console/console.factory.did.mjs b/src/declarations/console/console.factory.did.mjs index 250efe59ac..03577a29a2 100644 --- a/src/declarations/console/console.factory.did.mjs +++ b/src/declarations/console/console.factory.did.mjs @@ -24,7 +24,7 @@ export const idlFactory = ({ IDL }) => { user_key: IDL.Vec(IDL.Nat8), expiration: IDL.Nat64 }); - const OpenIdProvider = IDL.Variant({ + const OpenIdDelegationProvider = IDL.Variant({ GitHub: IDL.Null, Google: IDL.Null }); @@ -38,7 +38,7 @@ export const idlFactory = ({ IDL }) => { preferred_username: IDL.Opt(IDL.Text) }); const OpenId = IDL.Record({ - provider: OpenIdProvider, + provider: OpenIdDelegationProvider, data: OpenIdData }); const Provider = IDL.Variant({ @@ -143,7 +143,7 @@ export const idlFactory = ({ IDL }) => { }); const AuthenticationConfigOpenId = IDL.Record({ observatory_id: IDL.Opt(IDL.Principal), - providers: IDL.Vec(IDL.Tuple(OpenIdProvider, OpenIdProviderConfig)) + providers: IDL.Vec(IDL.Tuple(OpenIdDelegationProvider, OpenIdProviderConfig)) }); const AuthenticationConfigInternetIdentity = IDL.Record({ derivation_origin: IDL.Opt(IDL.Text), diff --git a/src/declarations/deprecated/console-0-3-3.did.d.ts b/src/declarations/deprecated/console-0-3-3.did.d.ts new file mode 100644 index 0000000000..c084e35f32 --- /dev/null +++ b/src/declarations/deprecated/console-0-3-3.did.d.ts @@ -0,0 +1,529 @@ +/* eslint-disable */ + +// @ts-nocheck + +// This file was automatically generated by @icp-sdk/bindgen@0.2.1. +// You should NOT make any changes in this file as it will be overwritten. +// Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified. + +import type { ActorMethod } from '@icp-sdk/core/agent'; +import type { IDL } from '@icp-sdk/core/candid'; +import type { Principal } from '@icp-sdk/core/principal'; + +export interface Account { + updated_at: bigint; + credits: Tokens; + mission_control_id: [] | [Principal]; + provider: [] | [Provider]; + owner: Principal; + created_at: bigint; +} +export interface Account_1 { + owner: Principal; + subaccount: [] | [Uint8Array]; +} +export interface AssertMissionControlCenterArgs { + mission_control_id: Principal; + user: Principal; +} +export interface AssetEncodingNoContent { + modified: bigint; + sha256: Uint8Array; + total_length: bigint; +} +export interface AssetKey { + token: [] | [string]; + collection: string; + owner: Principal; + name: string; + description: [] | [string]; + full_path: string; +} +export interface AssetNoContent { + key: AssetKey; + updated_at: bigint; + encodings: Array<[string, AssetEncodingNoContent]>; + headers: Array<[string, string]>; + created_at: bigint; + version: [] | [bigint]; +} +export interface AssetsUpgradeOptions { + clear_existing_assets: [] | [boolean]; +} +export interface Authentication { + delegation: PreparedDelegation; + account: Account; +} +export type AuthenticationArgs = { OpenId: OpenIdPrepareDelegationArgs }; +export interface AuthenticationConfig { + updated_at: [] | [bigint]; + openid: [] | [AuthenticationConfigOpenId]; + created_at: [] | [bigint]; + version: [] | [bigint]; + internet_identity: [] | [AuthenticationConfigInternetIdentity]; + rules: [] | [AuthenticationRules]; +} +export interface AuthenticationConfigInternetIdentity { + derivation_origin: [] | [string]; + external_alternative_origins: [] | [Array]; +} +export interface AuthenticationConfigOpenId { + observatory_id: [] | [Principal]; + providers: Array<[OpenIdProvider, OpenIdProviderConfig]>; +} +export type AuthenticationError = + | { + PrepareDelegation: PrepareDelegationError; + } + | { RegisterUser: string }; +export interface AuthenticationRules { + allowed_callers: Array; +} +export interface CommitBatch { + batch_id: bigint; + headers: Array<[string, string]>; + chunk_ids: Array; +} +export interface CommitProposal { + sha256: Uint8Array; + proposal_id: bigint; +} +export interface Config { + authentication: [] | [AuthenticationConfig]; + storage: StorageConfig; +} +export interface ConfigMaxMemorySize { + stable: [] | [bigint]; + heap: [] | [bigint]; +} +export interface Controller { + updated_at: bigint; + metadata: Array<[string, string]>; + created_at: bigint; + scope: ControllerScope; + expires_at: [] | [bigint]; +} +export type ControllerScope = { Write: null } | { Admin: null } | { Submit: null }; +export interface CreateMissionControlArgs { + subnet_id: [] | [Principal]; +} +export interface CreateOrbiterArgs { + block_index: [] | [bigint]; + subnet_id: [] | [Principal]; + name: [] | [string]; + user: Principal; +} +export interface CreateSatelliteArgs { + block_index: [] | [bigint]; + subnet_id: [] | [Principal]; + storage: [] | [InitStorageArgs]; + name: [] | [string]; + user: Principal; +} +export interface CustomDomain { + updated_at: bigint; + created_at: bigint; + version: [] | [bigint]; + bn_id: [] | [string]; +} +export interface CyclesTokens { + e12s: bigint; +} +export interface Delegation { + pubkey: Uint8Array; + targets: [] | [Array]; + expiration: bigint; +} +export interface DeleteControllersArgs { + controllers: Array; +} +export interface DeleteProposalAssets { + proposal_ids: Array; +} +export interface FactoryFee { + updated_at: bigint; + fee_cycles: CyclesTokens; + fee_icp: [] | [Tokens]; +} +export interface FeesArgs { + fee_cycles: CyclesTokens; + fee_icp: [] | [Tokens]; +} +export interface GetCreateCanisterFeeArgs { + user: Principal; +} +export type GetDelegationArgs = { OpenId: OpenIdGetDelegationArgs }; +export type GetDelegationError = + | { JwtFindProvider: JwtFindProviderError } + | { GetCachedJwks: null } + | { NoSuchDelegation: null } + | { JwtVerify: JwtVerifyError } + | { GetOrFetchJwks: GetOrRefreshJwksError } + | { DeriveSeedFailed: string }; +export type GetOrRefreshJwksError = + | { InvalidConfig: string } + | { MissingKid: null } + | { BadClaim: string } + | { KeyNotFoundCooldown: null } + | { CertificateNotFound: null } + | { BadSig: string } + | { MissingLastAttempt: string } + | { KeyNotFound: null } + | { FetchFailed: string }; +export interface HttpRequest { + url: string; + method: string; + body: Uint8Array; + headers: Array<[string, string]>; + certificate_version: [] | [number]; +} +export interface HttpResponse { + body: Uint8Array; + headers: Array<[string, string]>; + streaming_strategy: [] | [StreamingStrategy]; + status_code: number; +} +export interface IcpPayment { + status: PaymentStatus; + updated_at: bigint; + block_index_payment: bigint; + mission_control_id: [] | [Principal]; + created_at: bigint; + block_index_refunded: [] | [bigint]; +} +export interface IcrcPayment { + status: PaymentStatus; + updated_at: bigint; + created_at: bigint; + block_index_refunded: [] | [bigint]; + purchaser: Account_1; +} +export interface IcrcPaymentKey { + block_index: bigint; + ledger_id: Principal; +} +export interface InitAssetKey { + token: [] | [string]; + collection: string; + name: string; + description: [] | [string]; + encoding_type: [] | [string]; + full_path: string; +} +export interface InitStorageArgs { + system_memory: [] | [InitStorageMemory]; +} +export type InitStorageMemory = { Heap: null } | { Stable: null }; +export interface InitUploadResult { + batch_id: bigint; +} +export type JwtFindProviderError = + | { BadClaim: string } + | { BadSig: string } + | { NoMatchingProvider: null }; +export type JwtVerifyError = + | { WrongKeyType: null } + | { MissingKid: null } + | { BadClaim: string } + | { BadSig: string } + | { NoKeyForKid: null }; +export interface ListMatcher { + key: [] | [string]; + updated_at: [] | [TimestampMatcher]; + description: [] | [string]; + created_at: [] | [TimestampMatcher]; +} +export interface ListOrder { + field: ListOrderField; + desc: boolean; +} +export type ListOrderField = { UpdatedAt: null } | { Keys: null } | { CreatedAt: null }; +export interface ListPaginate { + start_after: [] | [string]; + limit: [] | [bigint]; +} +export interface ListParams { + order: [] | [ListOrder]; + owner: [] | [Principal]; + matcher: [] | [ListMatcher]; + paginate: [] | [ListPaginate]; +} +export interface ListProposalResults { + matches_length: bigint; + items: Array<[ProposalKey, Proposal]>; + items_length: bigint; +} +export interface ListProposalsOrder { + desc: boolean; +} +export interface ListProposalsPaginate { + start_after: [] | [bigint]; + limit: [] | [bigint]; +} +export interface ListProposalsParams { + order: [] | [ListProposalsOrder]; + paginate: [] | [ListProposalsPaginate]; +} +export interface ListResults { + matches_pages: [] | [bigint]; + matches_length: bigint; + items_page: [] | [bigint]; + items: Array<[string, AssetNoContent]>; + items_length: bigint; +} +export interface ListSegmentsArgs { + segment_id: [] | [Principal]; + segment_kind: [] | [StorableSegmentKind]; +} +export type Memory = { Heap: null } | { Stable: null }; +export interface OpenId { + provider: OpenIdProvider; + data: OpenIdData; +} +export interface OpenIdData { + name: [] | [string]; + locale: [] | [string]; + family_name: [] | [string]; + email: [] | [string]; + picture: [] | [string]; + given_name: [] | [string]; + preferred_username: [] | [string]; +} +export interface OpenIdGetDelegationArgs { + jwt: string; + session_key: Uint8Array; + salt: Uint8Array; + expiration: bigint; +} +export interface OpenIdPrepareDelegationArgs { + jwt: string; + session_key: Uint8Array; + salt: Uint8Array; +} +export type OpenIdProvider = { GitHub: null } | { Google: null }; +export interface OpenIdProviderConfig { + delegation: [] | [OpenIdProviderDelegationConfig]; + client_id: string; +} +export interface OpenIdProviderDelegationConfig { + targets: [] | [Array]; + max_time_to_live: [] | [bigint]; +} +export type PaymentStatus = { Refunded: null } | { Acknowledged: null } | { Completed: null }; +export type PrepareDelegationError = + | { + JwtFindProvider: JwtFindProviderError; + } + | { GetCachedJwks: null } + | { JwtVerify: JwtVerifyError } + | { GetOrFetchJwks: GetOrRefreshJwksError } + | { DeriveSeedFailed: string }; +export interface PreparedDelegation { + user_key: Uint8Array; + expiration: bigint; +} +export interface Proposal { + status: ProposalStatus; + updated_at: bigint; + sha256: [] | [Uint8Array]; + executed_at: [] | [bigint]; + owner: Principal; + created_at: bigint; + version: [] | [bigint]; + proposal_type: ProposalType; +} +export interface ProposalKey { + proposal_id: bigint; +} +export type ProposalStatus = + | { Initialized: null } + | { Failed: null } + | { Open: null } + | { Rejected: null } + | { Executed: null } + | { Accepted: null }; +export type ProposalType = + | { AssetsUpgrade: AssetsUpgradeOptions } + | { SegmentsDeployment: SegmentsDeploymentOptions }; +export type Provider = { InternetIdentity: null } | { OpenId: OpenId }; +export interface RateConfig { + max_tokens: bigint; + time_per_token_ns: bigint; +} +export type Result = { Ok: Authentication } | { Err: AuthenticationError }; +export type Result_1 = { Ok: SignedDelegation } | { Err: GetDelegationError }; +export interface Segment { + updated_at: bigint; + metadata: Array<[string, string]>; + segment_id: Principal; + created_at: bigint; +} +export interface SegmentKey { + user: Principal; + segment_id: Principal; + segment_kind: StorableSegmentKind; +} +export type SegmentKind = { Orbiter: null } | { MissionControl: null } | { Satellite: null }; +export interface SegmentsDeploymentOptions { + orbiter: [] | [string]; + mission_control_version: [] | [string]; + satellite_version: [] | [string]; +} +export interface SetAuthenticationConfig { + openid: [] | [AuthenticationConfigOpenId]; + version: [] | [bigint]; + internet_identity: [] | [AuthenticationConfigInternetIdentity]; + rules: [] | [AuthenticationRules]; +} +export interface SetController { + metadata: Array<[string, string]>; + scope: ControllerScope; + expires_at: [] | [bigint]; +} +export interface SetControllersArgs { + controller: SetController; + controllers: Array; +} +export interface SetSegmentMetadataArgs { + metadata: Array<[string, string]>; + segment_id: Principal; + segment_kind: StorableSegmentKind; +} +export interface SetSegmentsArgs { + metadata: [] | [Array<[string, string]>]; + segment_id: Principal; + segment_kind: StorableSegmentKind; +} +export interface SetStorageConfig { + iframe: [] | [StorageConfigIFrame]; + rewrites: Array<[string, string]>; + headers: Array<[string, Array<[string, string]>]>; + version: [] | [bigint]; + max_memory_size: [] | [ConfigMaxMemorySize]; + raw_access: [] | [StorageConfigRawAccess]; + redirects: [] | [Array<[string, StorageConfigRedirect]>]; +} +export interface SignedDelegation { + signature: Uint8Array; + delegation: Delegation; +} +export type StorableSegmentKind = { Orbiter: null } | { Satellite: null }; +export interface StorageConfig { + iframe: [] | [StorageConfigIFrame]; + updated_at: [] | [bigint]; + rewrites: Array<[string, string]>; + headers: Array<[string, Array<[string, string]>]>; + created_at: [] | [bigint]; + version: [] | [bigint]; + max_memory_size: [] | [ConfigMaxMemorySize]; + raw_access: [] | [StorageConfigRawAccess]; + redirects: [] | [Array<[string, StorageConfigRedirect]>]; +} +export type StorageConfigIFrame = { Deny: null } | { AllowAny: null } | { SameOrigin: null }; +export type StorageConfigRawAccess = { Deny: null } | { Allow: null }; +export interface StorageConfigRedirect { + status_code: number; + location: string; +} +export interface StreamingCallbackHttpResponse { + token: [] | [StreamingCallbackToken]; + body: Uint8Array; +} +export interface StreamingCallbackToken { + memory: Memory; + token: [] | [string]; + sha256: [] | [Uint8Array]; + headers: Array<[string, string]>; + index: bigint; + encoding_type: string; + full_path: string; +} +export type StreamingStrategy = { + Callback: { + token: StreamingCallbackToken; + callback: [Principal, string]; + }; +}; +export type TimestampMatcher = + | { Equal: bigint } + | { Between: [bigint, bigint] } + | { GreaterThan: bigint } + | { LessThan: bigint }; +export interface Tokens { + e8s: bigint; +} +export interface UnsetSegmentsArgs { + segment_id: Principal; + segment_kind: StorableSegmentKind; +} +export interface UploadChunk { + content: Uint8Array; + batch_id: bigint; + order_id: [] | [bigint]; +} +export interface UploadChunkResult { + chunk_id: bigint; +} +export interface _SERVICE { + add_credits: ActorMethod<[Principal, Tokens], undefined>; + add_invitation_code: ActorMethod<[string], undefined>; + assert_mission_control_center: ActorMethod<[AssertMissionControlCenterArgs], undefined>; + authenticate: ActorMethod<[AuthenticationArgs], Result>; + commit_proposal: ActorMethod<[CommitProposal], null>; + commit_proposal_asset_upload: ActorMethod<[CommitBatch], undefined>; + commit_proposal_many_assets_upload: ActorMethod<[Array], undefined>; + count_proposals: ActorMethod<[], bigint>; + create_mission_control: ActorMethod<[CreateMissionControlArgs], Principal>; + create_orbiter: ActorMethod<[CreateOrbiterArgs], Principal>; + create_satellite: ActorMethod<[CreateSatelliteArgs], Principal>; + del_controllers: ActorMethod<[DeleteControllersArgs], undefined>; + del_custom_domain: ActorMethod<[string], undefined>; + delete_proposal_assets: ActorMethod<[DeleteProposalAssets], undefined>; + get_account: ActorMethod<[], [] | [Account]>; + get_auth_config: ActorMethod<[], [] | [AuthenticationConfig]>; + get_config: ActorMethod<[], Config>; + get_create_orbiter_fee: ActorMethod<[GetCreateCanisterFeeArgs], [] | [Tokens]>; + get_create_satellite_fee: ActorMethod<[GetCreateCanisterFeeArgs], [] | [Tokens]>; + get_credits: ActorMethod<[], Tokens>; + get_delegation: ActorMethod<[GetDelegationArgs], Result_1>; + get_fee: ActorMethod<[SegmentKind], FactoryFee>; + get_or_init_account: ActorMethod<[], Account>; + get_proposal: ActorMethod<[bigint], [] | [Proposal]>; + get_rate_config: ActorMethod<[SegmentKind], RateConfig>; + get_storage_config: ActorMethod<[], StorageConfig>; + http_request: ActorMethod<[HttpRequest], HttpResponse>; + http_request_streaming_callback: ActorMethod< + [StreamingCallbackToken], + StreamingCallbackHttpResponse + >; + init_proposal: ActorMethod<[ProposalType], [bigint, Proposal]>; + init_proposal_asset_upload: ActorMethod<[InitAssetKey, bigint], InitUploadResult>; + init_proposal_many_assets_upload: ActorMethod< + [Array, bigint], + Array<[string, InitUploadResult]> + >; + list_accounts: ActorMethod<[], Array<[Principal, Account]>>; + list_assets: ActorMethod<[string, ListParams], ListResults>; + list_controllers: ActorMethod<[], Array<[Principal, Controller]>>; + list_custom_domains: ActorMethod<[], Array<[string, CustomDomain]>>; + list_icp_payments: ActorMethod<[], Array<[bigint, IcpPayment]>>; + list_icrc_payments: ActorMethod<[], Array<[IcrcPaymentKey, IcrcPayment]>>; + list_proposals: ActorMethod<[ListProposalsParams], ListProposalResults>; + list_segments: ActorMethod<[ListSegmentsArgs], Array<[SegmentKey, Segment]>>; + reject_proposal: ActorMethod<[CommitProposal], null>; + set_auth_config: ActorMethod<[SetAuthenticationConfig], AuthenticationConfig>; + set_controllers: ActorMethod<[SetControllersArgs], undefined>; + set_custom_domain: ActorMethod<[string, [] | [string]], undefined>; + set_fee: ActorMethod<[SegmentKind, FeesArgs], undefined>; + set_many_segments: ActorMethod<[Array], Array>; + set_rate_config: ActorMethod<[SegmentKind, RateConfig], undefined>; + set_segment: ActorMethod<[SetSegmentsArgs], Segment>; + set_segment_metadata: ActorMethod<[SetSegmentMetadataArgs], Segment>; + set_storage_config: ActorMethod<[SetStorageConfig], StorageConfig>; + submit_proposal: ActorMethod<[bigint], [bigint, Proposal]>; + unset_many_segments: ActorMethod<[Array], undefined>; + unset_segment: ActorMethod<[UnsetSegmentsArgs], undefined>; + upload_proposal_asset_chunk: ActorMethod<[UploadChunk], UploadChunkResult>; +} +export declare const idlFactory: IDL.InterfaceFactory; +export declare const init: (args: { IDL: typeof IDL }) => IDL.Type[]; diff --git a/src/declarations/deprecated/console-0-3-3.factory.did.js b/src/declarations/deprecated/console-0-3-3.factory.did.js new file mode 100644 index 0000000000..250efe59ac --- /dev/null +++ b/src/declarations/deprecated/console-0-3-3.factory.did.js @@ -0,0 +1,567 @@ +/* eslint-disable */ + +// @ts-nocheck + +// This file was automatically generated by @icp-sdk/bindgen@0.2.1. +// You should NOT make any changes in this file as it will be overwritten. +// Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified. + +export const idlFactory = ({ IDL }) => { + const Tokens = IDL.Record({ e8s: IDL.Nat64 }); + const AssertMissionControlCenterArgs = IDL.Record({ + mission_control_id: IDL.Principal, + user: IDL.Principal + }); + const OpenIdPrepareDelegationArgs = IDL.Record({ + jwt: IDL.Text, + session_key: IDL.Vec(IDL.Nat8), + salt: IDL.Vec(IDL.Nat8) + }); + const AuthenticationArgs = IDL.Variant({ + OpenId: OpenIdPrepareDelegationArgs + }); + const PreparedDelegation = IDL.Record({ + user_key: IDL.Vec(IDL.Nat8), + expiration: IDL.Nat64 + }); + const OpenIdProvider = IDL.Variant({ + GitHub: IDL.Null, + Google: IDL.Null + }); + const OpenIdData = IDL.Record({ + name: IDL.Opt(IDL.Text), + locale: IDL.Opt(IDL.Text), + family_name: IDL.Opt(IDL.Text), + email: IDL.Opt(IDL.Text), + picture: IDL.Opt(IDL.Text), + given_name: IDL.Opt(IDL.Text), + preferred_username: IDL.Opt(IDL.Text) + }); + const OpenId = IDL.Record({ + provider: OpenIdProvider, + data: OpenIdData + }); + const Provider = IDL.Variant({ + InternetIdentity: IDL.Null, + OpenId: OpenId + }); + const Account = IDL.Record({ + updated_at: IDL.Nat64, + credits: Tokens, + mission_control_id: IDL.Opt(IDL.Principal), + provider: IDL.Opt(Provider), + owner: IDL.Principal, + created_at: IDL.Nat64 + }); + const Authentication = IDL.Record({ + delegation: PreparedDelegation, + account: Account + }); + const JwtFindProviderError = IDL.Variant({ + BadClaim: IDL.Text, + BadSig: IDL.Text, + NoMatchingProvider: IDL.Null + }); + const JwtVerifyError = IDL.Variant({ + WrongKeyType: IDL.Null, + MissingKid: IDL.Null, + BadClaim: IDL.Text, + BadSig: IDL.Text, + NoKeyForKid: IDL.Null + }); + const GetOrRefreshJwksError = IDL.Variant({ + InvalidConfig: IDL.Text, + MissingKid: IDL.Null, + BadClaim: IDL.Text, + KeyNotFoundCooldown: IDL.Null, + CertificateNotFound: IDL.Null, + BadSig: IDL.Text, + MissingLastAttempt: IDL.Text, + KeyNotFound: IDL.Null, + FetchFailed: IDL.Text + }); + const PrepareDelegationError = IDL.Variant({ + JwtFindProvider: JwtFindProviderError, + GetCachedJwks: IDL.Null, + JwtVerify: JwtVerifyError, + GetOrFetchJwks: GetOrRefreshJwksError, + DeriveSeedFailed: IDL.Text + }); + const AuthenticationError = IDL.Variant({ + PrepareDelegation: PrepareDelegationError, + RegisterUser: IDL.Text + }); + const Result = IDL.Variant({ + Ok: Authentication, + Err: AuthenticationError + }); + const CommitProposal = IDL.Record({ + sha256: IDL.Vec(IDL.Nat8), + proposal_id: IDL.Nat + }); + const CommitBatch = IDL.Record({ + batch_id: IDL.Nat, + headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)), + chunk_ids: IDL.Vec(IDL.Nat) + }); + const CreateMissionControlArgs = IDL.Record({ + subnet_id: IDL.Opt(IDL.Principal) + }); + const CreateOrbiterArgs = IDL.Record({ + block_index: IDL.Opt(IDL.Nat64), + subnet_id: IDL.Opt(IDL.Principal), + name: IDL.Opt(IDL.Text), + user: IDL.Principal + }); + const InitStorageMemory = IDL.Variant({ + Heap: IDL.Null, + Stable: IDL.Null + }); + const InitStorageArgs = IDL.Record({ + system_memory: IDL.Opt(InitStorageMemory) + }); + const CreateSatelliteArgs = IDL.Record({ + block_index: IDL.Opt(IDL.Nat64), + subnet_id: IDL.Opt(IDL.Principal), + storage: IDL.Opt(InitStorageArgs), + name: IDL.Opt(IDL.Text), + user: IDL.Principal + }); + const DeleteControllersArgs = IDL.Record({ + controllers: IDL.Vec(IDL.Principal) + }); + const DeleteProposalAssets = IDL.Record({ + proposal_ids: IDL.Vec(IDL.Nat) + }); + const OpenIdProviderDelegationConfig = IDL.Record({ + targets: IDL.Opt(IDL.Vec(IDL.Principal)), + max_time_to_live: IDL.Opt(IDL.Nat64) + }); + const OpenIdProviderConfig = IDL.Record({ + delegation: IDL.Opt(OpenIdProviderDelegationConfig), + client_id: IDL.Text + }); + const AuthenticationConfigOpenId = IDL.Record({ + observatory_id: IDL.Opt(IDL.Principal), + providers: IDL.Vec(IDL.Tuple(OpenIdProvider, OpenIdProviderConfig)) + }); + const AuthenticationConfigInternetIdentity = IDL.Record({ + derivation_origin: IDL.Opt(IDL.Text), + external_alternative_origins: IDL.Opt(IDL.Vec(IDL.Text)) + }); + const AuthenticationRules = IDL.Record({ + allowed_callers: IDL.Vec(IDL.Principal) + }); + const AuthenticationConfig = IDL.Record({ + updated_at: IDL.Opt(IDL.Nat64), + openid: IDL.Opt(AuthenticationConfigOpenId), + created_at: IDL.Opt(IDL.Nat64), + version: IDL.Opt(IDL.Nat64), + internet_identity: IDL.Opt(AuthenticationConfigInternetIdentity), + rules: IDL.Opt(AuthenticationRules) + }); + const StorageConfigIFrame = IDL.Variant({ + Deny: IDL.Null, + AllowAny: IDL.Null, + SameOrigin: IDL.Null + }); + const ConfigMaxMemorySize = IDL.Record({ + stable: IDL.Opt(IDL.Nat64), + heap: IDL.Opt(IDL.Nat64) + }); + const StorageConfigRawAccess = IDL.Variant({ + Deny: IDL.Null, + Allow: IDL.Null + }); + const StorageConfigRedirect = IDL.Record({ + status_code: IDL.Nat16, + location: IDL.Text + }); + const StorageConfig = IDL.Record({ + iframe: IDL.Opt(StorageConfigIFrame), + updated_at: IDL.Opt(IDL.Nat64), + rewrites: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)), + headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)))), + created_at: IDL.Opt(IDL.Nat64), + version: IDL.Opt(IDL.Nat64), + max_memory_size: IDL.Opt(ConfigMaxMemorySize), + raw_access: IDL.Opt(StorageConfigRawAccess), + redirects: IDL.Opt(IDL.Vec(IDL.Tuple(IDL.Text, StorageConfigRedirect))) + }); + const Config = IDL.Record({ + authentication: IDL.Opt(AuthenticationConfig), + storage: StorageConfig + }); + const GetCreateCanisterFeeArgs = IDL.Record({ user: IDL.Principal }); + const OpenIdGetDelegationArgs = IDL.Record({ + jwt: IDL.Text, + session_key: IDL.Vec(IDL.Nat8), + salt: IDL.Vec(IDL.Nat8), + expiration: IDL.Nat64 + }); + const GetDelegationArgs = IDL.Variant({ OpenId: OpenIdGetDelegationArgs }); + const Delegation = IDL.Record({ + pubkey: IDL.Vec(IDL.Nat8), + targets: IDL.Opt(IDL.Vec(IDL.Principal)), + expiration: IDL.Nat64 + }); + const SignedDelegation = IDL.Record({ + signature: IDL.Vec(IDL.Nat8), + delegation: Delegation + }); + const GetDelegationError = IDL.Variant({ + JwtFindProvider: JwtFindProviderError, + GetCachedJwks: IDL.Null, + NoSuchDelegation: IDL.Null, + JwtVerify: JwtVerifyError, + GetOrFetchJwks: GetOrRefreshJwksError, + DeriveSeedFailed: IDL.Text + }); + const Result_1 = IDL.Variant({ + Ok: SignedDelegation, + Err: GetDelegationError + }); + const SegmentKind = IDL.Variant({ + Orbiter: IDL.Null, + MissionControl: IDL.Null, + Satellite: IDL.Null + }); + const CyclesTokens = IDL.Record({ e12s: IDL.Nat64 }); + const FactoryFee = IDL.Record({ + updated_at: IDL.Nat64, + fee_cycles: CyclesTokens, + fee_icp: IDL.Opt(Tokens) + }); + const ProposalStatus = IDL.Variant({ + Initialized: IDL.Null, + Failed: IDL.Null, + Open: IDL.Null, + Rejected: IDL.Null, + Executed: IDL.Null, + Accepted: IDL.Null + }); + const AssetsUpgradeOptions = IDL.Record({ + clear_existing_assets: IDL.Opt(IDL.Bool) + }); + const SegmentsDeploymentOptions = IDL.Record({ + orbiter: IDL.Opt(IDL.Text), + mission_control_version: IDL.Opt(IDL.Text), + satellite_version: IDL.Opt(IDL.Text) + }); + const ProposalType = IDL.Variant({ + AssetsUpgrade: AssetsUpgradeOptions, + SegmentsDeployment: SegmentsDeploymentOptions + }); + const Proposal = IDL.Record({ + status: ProposalStatus, + updated_at: IDL.Nat64, + sha256: IDL.Opt(IDL.Vec(IDL.Nat8)), + executed_at: IDL.Opt(IDL.Nat64), + owner: IDL.Principal, + created_at: IDL.Nat64, + version: IDL.Opt(IDL.Nat64), + proposal_type: ProposalType + }); + const RateConfig = IDL.Record({ + max_tokens: IDL.Nat64, + time_per_token_ns: IDL.Nat64 + }); + const HttpRequest = IDL.Record({ + url: IDL.Text, + method: IDL.Text, + body: IDL.Vec(IDL.Nat8), + headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)), + certificate_version: IDL.Opt(IDL.Nat16) + }); + const Memory = IDL.Variant({ Heap: IDL.Null, Stable: IDL.Null }); + const StreamingCallbackToken = IDL.Record({ + memory: Memory, + token: IDL.Opt(IDL.Text), + sha256: IDL.Opt(IDL.Vec(IDL.Nat8)), + headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)), + index: IDL.Nat64, + encoding_type: IDL.Text, + full_path: IDL.Text + }); + const StreamingStrategy = IDL.Variant({ + Callback: IDL.Record({ + token: StreamingCallbackToken, + callback: IDL.Func([], [], ['query']) + }) + }); + const HttpResponse = IDL.Record({ + body: IDL.Vec(IDL.Nat8), + headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)), + streaming_strategy: IDL.Opt(StreamingStrategy), + status_code: IDL.Nat16 + }); + const StreamingCallbackHttpResponse = IDL.Record({ + token: IDL.Opt(StreamingCallbackToken), + body: IDL.Vec(IDL.Nat8) + }); + const InitAssetKey = IDL.Record({ + token: IDL.Opt(IDL.Text), + collection: IDL.Text, + name: IDL.Text, + description: IDL.Opt(IDL.Text), + encoding_type: IDL.Opt(IDL.Text), + full_path: IDL.Text + }); + const InitUploadResult = IDL.Record({ batch_id: IDL.Nat }); + const ListOrderField = IDL.Variant({ + UpdatedAt: IDL.Null, + Keys: IDL.Null, + CreatedAt: IDL.Null + }); + const ListOrder = IDL.Record({ field: ListOrderField, desc: IDL.Bool }); + const TimestampMatcher = IDL.Variant({ + Equal: IDL.Nat64, + Between: IDL.Tuple(IDL.Nat64, IDL.Nat64), + GreaterThan: IDL.Nat64, + LessThan: IDL.Nat64 + }); + const ListMatcher = IDL.Record({ + key: IDL.Opt(IDL.Text), + updated_at: IDL.Opt(TimestampMatcher), + description: IDL.Opt(IDL.Text), + created_at: IDL.Opt(TimestampMatcher) + }); + const ListPaginate = IDL.Record({ + start_after: IDL.Opt(IDL.Text), + limit: IDL.Opt(IDL.Nat64) + }); + const ListParams = IDL.Record({ + order: IDL.Opt(ListOrder), + owner: IDL.Opt(IDL.Principal), + matcher: IDL.Opt(ListMatcher), + paginate: IDL.Opt(ListPaginate) + }); + const AssetKey = IDL.Record({ + token: IDL.Opt(IDL.Text), + collection: IDL.Text, + owner: IDL.Principal, + name: IDL.Text, + description: IDL.Opt(IDL.Text), + full_path: IDL.Text + }); + const AssetEncodingNoContent = IDL.Record({ + modified: IDL.Nat64, + sha256: IDL.Vec(IDL.Nat8), + total_length: IDL.Nat + }); + const AssetNoContent = IDL.Record({ + key: AssetKey, + updated_at: IDL.Nat64, + encodings: IDL.Vec(IDL.Tuple(IDL.Text, AssetEncodingNoContent)), + headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)), + created_at: IDL.Nat64, + version: IDL.Opt(IDL.Nat64) + }); + const ListResults = IDL.Record({ + matches_pages: IDL.Opt(IDL.Nat64), + matches_length: IDL.Nat64, + items_page: IDL.Opt(IDL.Nat64), + items: IDL.Vec(IDL.Tuple(IDL.Text, AssetNoContent)), + items_length: IDL.Nat64 + }); + const ControllerScope = IDL.Variant({ + Write: IDL.Null, + Admin: IDL.Null, + Submit: IDL.Null + }); + const Controller = IDL.Record({ + updated_at: IDL.Nat64, + metadata: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)), + created_at: IDL.Nat64, + scope: ControllerScope, + expires_at: IDL.Opt(IDL.Nat64) + }); + const CustomDomain = IDL.Record({ + updated_at: IDL.Nat64, + created_at: IDL.Nat64, + version: IDL.Opt(IDL.Nat64), + bn_id: IDL.Opt(IDL.Text) + }); + const PaymentStatus = IDL.Variant({ + Refunded: IDL.Null, + Acknowledged: IDL.Null, + Completed: IDL.Null + }); + const IcpPayment = IDL.Record({ + status: PaymentStatus, + updated_at: IDL.Nat64, + block_index_payment: IDL.Nat64, + mission_control_id: IDL.Opt(IDL.Principal), + created_at: IDL.Nat64, + block_index_refunded: IDL.Opt(IDL.Nat64) + }); + const IcrcPaymentKey = IDL.Record({ + block_index: IDL.Nat64, + ledger_id: IDL.Principal + }); + const Account_1 = IDL.Record({ + owner: IDL.Principal, + subaccount: IDL.Opt(IDL.Vec(IDL.Nat8)) + }); + const IcrcPayment = IDL.Record({ + status: PaymentStatus, + updated_at: IDL.Nat64, + created_at: IDL.Nat64, + block_index_refunded: IDL.Opt(IDL.Nat64), + purchaser: Account_1 + }); + const ListProposalsOrder = IDL.Record({ desc: IDL.Bool }); + const ListProposalsPaginate = IDL.Record({ + start_after: IDL.Opt(IDL.Nat), + limit: IDL.Opt(IDL.Nat) + }); + const ListProposalsParams = IDL.Record({ + order: IDL.Opt(ListProposalsOrder), + paginate: IDL.Opt(ListProposalsPaginate) + }); + const ProposalKey = IDL.Record({ proposal_id: IDL.Nat }); + const ListProposalResults = IDL.Record({ + matches_length: IDL.Nat64, + items: IDL.Vec(IDL.Tuple(ProposalKey, Proposal)), + items_length: IDL.Nat64 + }); + const StorableSegmentKind = IDL.Variant({ + Orbiter: IDL.Null, + Satellite: IDL.Null + }); + const ListSegmentsArgs = IDL.Record({ + segment_id: IDL.Opt(IDL.Principal), + segment_kind: IDL.Opt(StorableSegmentKind) + }); + const SegmentKey = IDL.Record({ + user: IDL.Principal, + segment_id: IDL.Principal, + segment_kind: StorableSegmentKind + }); + const Segment = IDL.Record({ + updated_at: IDL.Nat64, + metadata: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)), + segment_id: IDL.Principal, + created_at: IDL.Nat64 + }); + const SetAuthenticationConfig = IDL.Record({ + openid: IDL.Opt(AuthenticationConfigOpenId), + version: IDL.Opt(IDL.Nat64), + internet_identity: IDL.Opt(AuthenticationConfigInternetIdentity), + rules: IDL.Opt(AuthenticationRules) + }); + const SetController = IDL.Record({ + metadata: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)), + scope: ControllerScope, + expires_at: IDL.Opt(IDL.Nat64) + }); + const SetControllersArgs = IDL.Record({ + controller: SetController, + controllers: IDL.Vec(IDL.Principal) + }); + const FeesArgs = IDL.Record({ + fee_cycles: CyclesTokens, + fee_icp: IDL.Opt(Tokens) + }); + const SetSegmentsArgs = IDL.Record({ + metadata: IDL.Opt(IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text))), + segment_id: IDL.Principal, + segment_kind: StorableSegmentKind + }); + const SetSegmentMetadataArgs = IDL.Record({ + metadata: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)), + segment_id: IDL.Principal, + segment_kind: StorableSegmentKind + }); + const SetStorageConfig = IDL.Record({ + iframe: IDL.Opt(StorageConfigIFrame), + rewrites: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)), + headers: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)))), + version: IDL.Opt(IDL.Nat64), + max_memory_size: IDL.Opt(ConfigMaxMemorySize), + raw_access: IDL.Opt(StorageConfigRawAccess), + redirects: IDL.Opt(IDL.Vec(IDL.Tuple(IDL.Text, StorageConfigRedirect))) + }); + const UnsetSegmentsArgs = IDL.Record({ + segment_id: IDL.Principal, + segment_kind: StorableSegmentKind + }); + const UploadChunk = IDL.Record({ + content: IDL.Vec(IDL.Nat8), + batch_id: IDL.Nat, + order_id: IDL.Opt(IDL.Nat) + }); + const UploadChunkResult = IDL.Record({ chunk_id: IDL.Nat }); + + return IDL.Service({ + add_credits: IDL.Func([IDL.Principal, Tokens], [], []), + add_invitation_code: IDL.Func([IDL.Text], [], []), + assert_mission_control_center: IDL.Func([AssertMissionControlCenterArgs], [], ['query']), + authenticate: IDL.Func([AuthenticationArgs], [Result], []), + commit_proposal: IDL.Func([CommitProposal], [IDL.Null], []), + commit_proposal_asset_upload: IDL.Func([CommitBatch], [], []), + commit_proposal_many_assets_upload: IDL.Func([IDL.Vec(CommitBatch)], [], []), + count_proposals: IDL.Func([], [IDL.Nat64], ['query']), + create_mission_control: IDL.Func([CreateMissionControlArgs], [IDL.Principal], []), + create_orbiter: IDL.Func([CreateOrbiterArgs], [IDL.Principal], []), + create_satellite: IDL.Func([CreateSatelliteArgs], [IDL.Principal], []), + del_controllers: IDL.Func([DeleteControllersArgs], [], []), + del_custom_domain: IDL.Func([IDL.Text], [], []), + delete_proposal_assets: IDL.Func([DeleteProposalAssets], [], []), + get_account: IDL.Func([], [IDL.Opt(Account)], ['query']), + get_auth_config: IDL.Func([], [IDL.Opt(AuthenticationConfig)], ['query']), + get_config: IDL.Func([], [Config], ['query']), + get_create_orbiter_fee: IDL.Func([GetCreateCanisterFeeArgs], [IDL.Opt(Tokens)], ['query']), + get_create_satellite_fee: IDL.Func([GetCreateCanisterFeeArgs], [IDL.Opt(Tokens)], ['query']), + get_credits: IDL.Func([], [Tokens], ['query']), + get_delegation: IDL.Func([GetDelegationArgs], [Result_1], ['query']), + get_fee: IDL.Func([SegmentKind], [FactoryFee], ['query']), + get_or_init_account: IDL.Func([], [Account], []), + get_proposal: IDL.Func([IDL.Nat], [IDL.Opt(Proposal)], ['query']), + get_rate_config: IDL.Func([SegmentKind], [RateConfig], ['query']), + get_storage_config: IDL.Func([], [StorageConfig], ['query']), + http_request: IDL.Func([HttpRequest], [HttpResponse], ['query']), + http_request_streaming_callback: IDL.Func( + [StreamingCallbackToken], + [StreamingCallbackHttpResponse], + ['query'] + ), + init_proposal: IDL.Func([ProposalType], [IDL.Nat, Proposal], []), + init_proposal_asset_upload: IDL.Func([InitAssetKey, IDL.Nat], [InitUploadResult], []), + init_proposal_many_assets_upload: IDL.Func( + [IDL.Vec(InitAssetKey), IDL.Nat], + [IDL.Vec(IDL.Tuple(IDL.Text, InitUploadResult))], + [] + ), + list_accounts: IDL.Func([], [IDL.Vec(IDL.Tuple(IDL.Principal, Account))], ['query']), + list_assets: IDL.Func([IDL.Text, ListParams], [ListResults], ['query']), + list_controllers: IDL.Func([], [IDL.Vec(IDL.Tuple(IDL.Principal, Controller))], ['query']), + list_custom_domains: IDL.Func([], [IDL.Vec(IDL.Tuple(IDL.Text, CustomDomain))], ['query']), + list_icp_payments: IDL.Func([], [IDL.Vec(IDL.Tuple(IDL.Nat64, IcpPayment))], ['query']), + list_icrc_payments: IDL.Func([], [IDL.Vec(IDL.Tuple(IcrcPaymentKey, IcrcPayment))], ['query']), + list_proposals: IDL.Func([ListProposalsParams], [ListProposalResults], ['query']), + list_segments: IDL.Func( + [ListSegmentsArgs], + [IDL.Vec(IDL.Tuple(SegmentKey, Segment))], + ['query'] + ), + reject_proposal: IDL.Func([CommitProposal], [IDL.Null], []), + set_auth_config: IDL.Func([SetAuthenticationConfig], [AuthenticationConfig], []), + set_controllers: IDL.Func([SetControllersArgs], [], []), + set_custom_domain: IDL.Func([IDL.Text, IDL.Opt(IDL.Text)], [], []), + set_fee: IDL.Func([SegmentKind, FeesArgs], [], []), + set_many_segments: IDL.Func([IDL.Vec(SetSegmentsArgs)], [IDL.Vec(Segment)], []), + set_rate_config: IDL.Func([SegmentKind, RateConfig], [], []), + set_segment: IDL.Func([SetSegmentsArgs], [Segment], []), + set_segment_metadata: IDL.Func([SetSegmentMetadataArgs], [Segment], []), + set_storage_config: IDL.Func([SetStorageConfig], [StorageConfig], []), + submit_proposal: IDL.Func([IDL.Nat], [IDL.Nat, Proposal], []), + unset_many_segments: IDL.Func([IDL.Vec(UnsetSegmentsArgs)], [], []), + unset_segment: IDL.Func([UnsetSegmentsArgs], [], []), + upload_proposal_asset_chunk: IDL.Func([UploadChunk], [UploadChunkResult], []) + }); +}; + +export const init = ({ IDL }) => { + return []; +}; diff --git a/src/declarations/deprecated/observatory-0-4-0.did.d.ts b/src/declarations/deprecated/observatory-0-4-0.did.d.ts new file mode 100644 index 0000000000..4884af3d3d --- /dev/null +++ b/src/declarations/deprecated/observatory-0-4-0.did.d.ts @@ -0,0 +1,145 @@ +/* eslint-disable */ + +// @ts-nocheck + +// This file was automatically generated by @icp-sdk/bindgen@0.2.1. +// You should NOT make any changes in this file as it will be overwritten. +// Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified. + +import type { ActorMethod } from '@icp-sdk/core/agent'; +import type { IDL } from '@icp-sdk/core/candid'; +import type { Principal } from '@icp-sdk/core/principal'; + +export interface Controller { + updated_at: bigint; + metadata: Array<[string, string]>; + created_at: bigint; + scope: ControllerScope; + expires_at: [] | [bigint]; +} +export type ControllerScope = { Write: null } | { Admin: null } | { Submit: null }; +export interface CyclesBalance { + timestamp: bigint; + amount: bigint; +} +export interface DeleteControllersArgs { + controllers: Array; +} +export interface DepositedCyclesEmailNotification { + to: string; + deposited_cycles: CyclesBalance; +} +export interface Env { + email_api_key: [] | [string]; +} +export interface FailedCyclesDepositEmailNotification { + to: string; + funding_failure: FundingFailure; +} +export type FundingErrorCode = + | { BalanceCheckFailed: null } + | { ObtainCyclesFailed: null } + | { DepositFailed: null } + | { InsufficientCycles: null } + | { Other: string }; +export interface FundingFailure { + timestamp: bigint; + error_code: FundingErrorCode; +} +export interface GetNotifications { + to: [] | [bigint]; + from: [] | [bigint]; + segment_id: [] | [Principal]; +} +export interface GetOpenIdCertificateArgs { + provider: OpenIdProvider; +} +export interface Jwk { + alg: [] | [string]; + kid: [] | [string]; + kty: JwkType; + params: JwkParams; +} +export type JwkParams = + | { Ec: JwkParamsEc } + | { Oct: JwkParamsOct } + | { Okp: JwkParamsOkp } + | { Rsa: JwkParamsRsa }; +export interface JwkParamsEc { + x: string; + y: string; + crv: string; +} +export interface JwkParamsOct { + k: string; +} +export interface JwkParamsOkp { + x: string; + crv: string; +} +export interface JwkParamsRsa { + e: string; + n: string; +} +export type JwkType = { EC: null } | { OKP: null } | { RSA: null } | { oct: null }; +export interface Jwks { + keys: Array; +} +export type NotificationKind = + | { + DepositedCyclesEmail: DepositedCyclesEmailNotification; + } + | { FailedCyclesDepositEmail: FailedCyclesDepositEmailNotification }; +export interface NotifyArgs { + kind: NotificationKind; + user: Principal; + segment: Segment; +} +export interface NotifyStatus { + pending: bigint; + sent: bigint; + failed: bigint; +} +export interface OpenIdCertificate { + updated_at: bigint; + jwks: Jwks; + created_at: bigint; + version: [] | [bigint]; +} +export type OpenIdProvider = { GitHub: null } | { Google: null }; +export interface RateConfig { + max_tokens: bigint; + time_per_token_ns: bigint; +} +export type RateKind = { OpenIdCertificateRequests: null }; +export interface Segment { + id: Principal; + metadata: [] | [Array<[string, string]>]; + kind: SegmentKind; +} +export type SegmentKind = { Orbiter: null } | { MissionControl: null } | { Satellite: null }; +export interface SetController { + metadata: Array<[string, string]>; + scope: ControllerScope; + expires_at: [] | [bigint]; +} +export interface SetControllersArgs { + controller: SetController; + controllers: Array; +} +export interface _SERVICE { + del_controllers: ActorMethod<[DeleteControllersArgs], undefined>; + get_notify_status: ActorMethod<[GetNotifications], NotifyStatus>; + get_openid_certificate: ActorMethod<[GetOpenIdCertificateArgs], [] | [OpenIdCertificate]>; + is_openid_monitoring_enabled: ActorMethod<[OpenIdProvider], boolean>; + list_controllers: ActorMethod<[], Array<[Principal, Controller]>>; + notify: ActorMethod<[NotifyArgs], undefined>; + ping: ActorMethod<[NotifyArgs], undefined>; + set_controllers: ActorMethod<[SetControllersArgs], undefined>; + set_env: ActorMethod<[Env], undefined>; + set_rate_config: ActorMethod<[RateKind, RateConfig], undefined>; + start_openid_monitoring: ActorMethod<[OpenIdProvider], undefined>; + stop_openid_monitoring: ActorMethod<[OpenIdProvider], undefined>; +} +export declare const idlFactory: IDL.InterfaceFactory; +export declare const init: (args: { IDL: typeof IDL }) => IDL.Type[]; diff --git a/src/declarations/deprecated/observatory-0-4-0.factory.did.js b/src/declarations/deprecated/observatory-0-4-0.factory.did.js new file mode 100644 index 0000000000..2984066a23 --- /dev/null +++ b/src/declarations/deprecated/observatory-0-4-0.factory.did.js @@ -0,0 +1,149 @@ +/* eslint-disable */ + +// @ts-nocheck + +// This file was automatically generated by @icp-sdk/bindgen@0.2.1. +// You should NOT make any changes in this file as it will be overwritten. +// Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified. + +export const idlFactory = ({ IDL }) => { + const DeleteControllersArgs = IDL.Record({ + controllers: IDL.Vec(IDL.Principal) + }); + const GetNotifications = IDL.Record({ + to: IDL.Opt(IDL.Nat64), + from: IDL.Opt(IDL.Nat64), + segment_id: IDL.Opt(IDL.Principal) + }); + const NotifyStatus = IDL.Record({ + pending: IDL.Nat64, + sent: IDL.Nat64, + failed: IDL.Nat64 + }); + const OpenIdProvider = IDL.Variant({ + GitHub: IDL.Null, + Google: IDL.Null + }); + const GetOpenIdCertificateArgs = IDL.Record({ provider: OpenIdProvider }); + const JwkType = IDL.Variant({ + EC: IDL.Null, + OKP: IDL.Null, + RSA: IDL.Null, + oct: IDL.Null + }); + const JwkParamsEc = IDL.Record({ + x: IDL.Text, + y: IDL.Text, + crv: IDL.Text + }); + const JwkParamsOct = IDL.Record({ k: IDL.Text }); + const JwkParamsOkp = IDL.Record({ x: IDL.Text, crv: IDL.Text }); + const JwkParamsRsa = IDL.Record({ e: IDL.Text, n: IDL.Text }); + const JwkParams = IDL.Variant({ + Ec: JwkParamsEc, + Oct: JwkParamsOct, + Okp: JwkParamsOkp, + Rsa: JwkParamsRsa + }); + const Jwk = IDL.Record({ + alg: IDL.Opt(IDL.Text), + kid: IDL.Opt(IDL.Text), + kty: JwkType, + params: JwkParams + }); + const Jwks = IDL.Record({ keys: IDL.Vec(Jwk) }); + const OpenIdCertificate = IDL.Record({ + updated_at: IDL.Nat64, + jwks: Jwks, + created_at: IDL.Nat64, + version: IDL.Opt(IDL.Nat64) + }); + const ControllerScope = IDL.Variant({ + Write: IDL.Null, + Admin: IDL.Null, + Submit: IDL.Null + }); + const Controller = IDL.Record({ + updated_at: IDL.Nat64, + metadata: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)), + created_at: IDL.Nat64, + scope: ControllerScope, + expires_at: IDL.Opt(IDL.Nat64) + }); + const CyclesBalance = IDL.Record({ + timestamp: IDL.Nat64, + amount: IDL.Nat + }); + const DepositedCyclesEmailNotification = IDL.Record({ + to: IDL.Text, + deposited_cycles: CyclesBalance + }); + const FundingErrorCode = IDL.Variant({ + BalanceCheckFailed: IDL.Null, + ObtainCyclesFailed: IDL.Null, + DepositFailed: IDL.Null, + InsufficientCycles: IDL.Null, + Other: IDL.Text + }); + const FundingFailure = IDL.Record({ + timestamp: IDL.Nat64, + error_code: FundingErrorCode + }); + const FailedCyclesDepositEmailNotification = IDL.Record({ + to: IDL.Text, + funding_failure: FundingFailure + }); + const NotificationKind = IDL.Variant({ + DepositedCyclesEmail: DepositedCyclesEmailNotification, + FailedCyclesDepositEmail: FailedCyclesDepositEmailNotification + }); + const SegmentKind = IDL.Variant({ + Orbiter: IDL.Null, + MissionControl: IDL.Null, + Satellite: IDL.Null + }); + const Segment = IDL.Record({ + id: IDL.Principal, + metadata: IDL.Opt(IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text))), + kind: SegmentKind + }); + const NotifyArgs = IDL.Record({ + kind: NotificationKind, + user: IDL.Principal, + segment: Segment + }); + const SetController = IDL.Record({ + metadata: IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)), + scope: ControllerScope, + expires_at: IDL.Opt(IDL.Nat64) + }); + const SetControllersArgs = IDL.Record({ + controller: SetController, + controllers: IDL.Vec(IDL.Principal) + }); + const Env = IDL.Record({ email_api_key: IDL.Opt(IDL.Text) }); + const RateKind = IDL.Variant({ OpenIdCertificateRequests: IDL.Null }); + const RateConfig = IDL.Record({ + max_tokens: IDL.Nat64, + time_per_token_ns: IDL.Nat64 + }); + + return IDL.Service({ + del_controllers: IDL.Func([DeleteControllersArgs], [], []), + get_notify_status: IDL.Func([GetNotifications], [NotifyStatus], ['query']), + get_openid_certificate: IDL.Func([GetOpenIdCertificateArgs], [IDL.Opt(OpenIdCertificate)], []), + is_openid_monitoring_enabled: IDL.Func([OpenIdProvider], [IDL.Bool], []), + list_controllers: IDL.Func([], [IDL.Vec(IDL.Tuple(IDL.Principal, Controller))], ['query']), + notify: IDL.Func([NotifyArgs], [], []), + ping: IDL.Func([NotifyArgs], [], []), + set_controllers: IDL.Func([SetControllersArgs], [], []), + set_env: IDL.Func([Env], [], []), + set_rate_config: IDL.Func([RateKind, RateConfig], [], []), + start_openid_monitoring: IDL.Func([OpenIdProvider], [], []), + stop_openid_monitoring: IDL.Func([OpenIdProvider], [], []) + }); +}; + +export const init = ({ IDL }) => { + return []; +}; diff --git a/src/declarations/observatory/observatory.did.d.ts b/src/declarations/observatory/observatory.did.d.ts index 4884af3d3d..1c94f148bf 100644 --- a/src/declarations/observatory/observatory.did.d.ts +++ b/src/declarations/observatory/observatory.did.d.ts @@ -106,7 +106,7 @@ export interface OpenIdCertificate { created_at: bigint; version: [] | [bigint]; } -export type OpenIdProvider = { GitHub: null } | { Google: null }; +export type OpenIdProvider = { Google: null } | { GitHubAuth: null }; export interface RateConfig { max_tokens: bigint; time_per_token_ns: bigint; diff --git a/src/declarations/observatory/observatory.factory.certified.did.js b/src/declarations/observatory/observatory.factory.certified.did.js index c414d71f0e..426638d956 100644 --- a/src/declarations/observatory/observatory.factory.certified.did.js +++ b/src/declarations/observatory/observatory.factory.certified.did.js @@ -21,8 +21,8 @@ export const idlFactory = ({ IDL }) => { failed: IDL.Nat64 }); const OpenIdProvider = IDL.Variant({ - GitHub: IDL.Null, - Google: IDL.Null + Google: IDL.Null, + GitHubAuth: IDL.Null }); const GetOpenIdCertificateArgs = IDL.Record({ provider: OpenIdProvider }); const JwkType = IDL.Variant({ diff --git a/src/declarations/observatory/observatory.factory.did.js b/src/declarations/observatory/observatory.factory.did.js index 2984066a23..4b2ad5081f 100644 --- a/src/declarations/observatory/observatory.factory.did.js +++ b/src/declarations/observatory/observatory.factory.did.js @@ -21,8 +21,8 @@ export const idlFactory = ({ IDL }) => { failed: IDL.Nat64 }); const OpenIdProvider = IDL.Variant({ - GitHub: IDL.Null, - Google: IDL.Null + Google: IDL.Null, + GitHubAuth: IDL.Null }); const GetOpenIdCertificateArgs = IDL.Record({ provider: OpenIdProvider }); const JwkType = IDL.Variant({ diff --git a/src/declarations/observatory/observatory.factory.did.mjs b/src/declarations/observatory/observatory.factory.did.mjs index 2984066a23..4b2ad5081f 100644 --- a/src/declarations/observatory/observatory.factory.did.mjs +++ b/src/declarations/observatory/observatory.factory.did.mjs @@ -21,8 +21,8 @@ export const idlFactory = ({ IDL }) => { failed: IDL.Nat64 }); const OpenIdProvider = IDL.Variant({ - GitHub: IDL.Null, - Google: IDL.Null + Google: IDL.Null, + GitHubAuth: IDL.Null }); const GetOpenIdCertificateArgs = IDL.Record({ provider: OpenIdProvider }); const JwkType = IDL.Variant({ diff --git a/src/declarations/satellite/satellite.did.d.ts b/src/declarations/satellite/satellite.did.d.ts index dde06ba223..e81eff7e7b 100644 --- a/src/declarations/satellite/satellite.did.d.ts +++ b/src/declarations/satellite/satellite.did.d.ts @@ -54,7 +54,7 @@ export interface AuthenticationConfigInternetIdentity { } export interface AuthenticationConfigOpenId { observatory_id: [] | [Principal]; - providers: Array<[OpenIdProvider, OpenIdProviderConfig]>; + providers: Array<[OpenIdDelegationProvider, OpenIdProviderConfig]>; } export type AuthenticationError = | { @@ -259,6 +259,7 @@ export interface MemorySize { stable: bigint; heap: bigint; } +export type OpenIdDelegationProvider = { GitHub: null } | { Google: null }; export interface OpenIdGetDelegationArgs { jwt: string; session_key: Uint8Array; @@ -270,7 +271,6 @@ export interface OpenIdPrepareDelegationArgs { session_key: Uint8Array; salt: Uint8Array; } -export type OpenIdProvider = { GitHub: null } | { Google: null }; export interface OpenIdProviderConfig { delegation: [] | [OpenIdProviderDelegationConfig]; client_id: string; diff --git a/src/declarations/satellite/satellite.factory.certified.did.js b/src/declarations/satellite/satellite.factory.certified.did.js index b5c665b978..bb1b50049c 100644 --- a/src/declarations/satellite/satellite.factory.certified.did.js +++ b/src/declarations/satellite/satellite.factory.certified.did.js @@ -158,7 +158,7 @@ export const idlFactory = ({ IDL }) => { created_at: IDL.Nat64, version: IDL.Opt(IDL.Nat64) }); - const OpenIdProvider = IDL.Variant({ + const OpenIdDelegationProvider = IDL.Variant({ GitHub: IDL.Null, Google: IDL.Null }); @@ -172,7 +172,7 @@ export const idlFactory = ({ IDL }) => { }); const AuthenticationConfigOpenId = IDL.Record({ observatory_id: IDL.Opt(IDL.Principal), - providers: IDL.Vec(IDL.Tuple(OpenIdProvider, OpenIdProviderConfig)) + providers: IDL.Vec(IDL.Tuple(OpenIdDelegationProvider, OpenIdProviderConfig)) }); const AuthenticationConfigInternetIdentity = IDL.Record({ derivation_origin: IDL.Opt(IDL.Text), diff --git a/src/declarations/satellite/satellite.factory.did.js b/src/declarations/satellite/satellite.factory.did.js index ba851264b2..2a2b91a073 100644 --- a/src/declarations/satellite/satellite.factory.did.js +++ b/src/declarations/satellite/satellite.factory.did.js @@ -158,7 +158,7 @@ export const idlFactory = ({ IDL }) => { created_at: IDL.Nat64, version: IDL.Opt(IDL.Nat64) }); - const OpenIdProvider = IDL.Variant({ + const OpenIdDelegationProvider = IDL.Variant({ GitHub: IDL.Null, Google: IDL.Null }); @@ -172,7 +172,7 @@ export const idlFactory = ({ IDL }) => { }); const AuthenticationConfigOpenId = IDL.Record({ observatory_id: IDL.Opt(IDL.Principal), - providers: IDL.Vec(IDL.Tuple(OpenIdProvider, OpenIdProviderConfig)) + providers: IDL.Vec(IDL.Tuple(OpenIdDelegationProvider, OpenIdProviderConfig)) }); const AuthenticationConfigInternetIdentity = IDL.Record({ derivation_origin: IDL.Opt(IDL.Text), diff --git a/src/declarations/satellite/satellite.factory.did.mjs b/src/declarations/satellite/satellite.factory.did.mjs index ba851264b2..2a2b91a073 100644 --- a/src/declarations/satellite/satellite.factory.did.mjs +++ b/src/declarations/satellite/satellite.factory.did.mjs @@ -158,7 +158,7 @@ export const idlFactory = ({ IDL }) => { created_at: IDL.Nat64, version: IDL.Opt(IDL.Nat64) }); - const OpenIdProvider = IDL.Variant({ + const OpenIdDelegationProvider = IDL.Variant({ GitHub: IDL.Null, Google: IDL.Null }); @@ -172,7 +172,7 @@ export const idlFactory = ({ IDL }) => { }); const AuthenticationConfigOpenId = IDL.Record({ observatory_id: IDL.Opt(IDL.Principal), - providers: IDL.Vec(IDL.Tuple(OpenIdProvider, OpenIdProviderConfig)) + providers: IDL.Vec(IDL.Tuple(OpenIdDelegationProvider, OpenIdProviderConfig)) }); const AuthenticationConfigInternetIdentity = IDL.Record({ derivation_origin: IDL.Opt(IDL.Text), diff --git a/src/declarations/sputnik/sputnik.did.d.ts b/src/declarations/sputnik/sputnik.did.d.ts index dde06ba223..e81eff7e7b 100644 --- a/src/declarations/sputnik/sputnik.did.d.ts +++ b/src/declarations/sputnik/sputnik.did.d.ts @@ -54,7 +54,7 @@ export interface AuthenticationConfigInternetIdentity { } export interface AuthenticationConfigOpenId { observatory_id: [] | [Principal]; - providers: Array<[OpenIdProvider, OpenIdProviderConfig]>; + providers: Array<[OpenIdDelegationProvider, OpenIdProviderConfig]>; } export type AuthenticationError = | { @@ -259,6 +259,7 @@ export interface MemorySize { stable: bigint; heap: bigint; } +export type OpenIdDelegationProvider = { GitHub: null } | { Google: null }; export interface OpenIdGetDelegationArgs { jwt: string; session_key: Uint8Array; @@ -270,7 +271,6 @@ export interface OpenIdPrepareDelegationArgs { session_key: Uint8Array; salt: Uint8Array; } -export type OpenIdProvider = { GitHub: null } | { Google: null }; export interface OpenIdProviderConfig { delegation: [] | [OpenIdProviderDelegationConfig]; client_id: string; diff --git a/src/declarations/sputnik/sputnik.factory.certified.did.js b/src/declarations/sputnik/sputnik.factory.certified.did.js index b5c665b978..bb1b50049c 100644 --- a/src/declarations/sputnik/sputnik.factory.certified.did.js +++ b/src/declarations/sputnik/sputnik.factory.certified.did.js @@ -158,7 +158,7 @@ export const idlFactory = ({ IDL }) => { created_at: IDL.Nat64, version: IDL.Opt(IDL.Nat64) }); - const OpenIdProvider = IDL.Variant({ + const OpenIdDelegationProvider = IDL.Variant({ GitHub: IDL.Null, Google: IDL.Null }); @@ -172,7 +172,7 @@ export const idlFactory = ({ IDL }) => { }); const AuthenticationConfigOpenId = IDL.Record({ observatory_id: IDL.Opt(IDL.Principal), - providers: IDL.Vec(IDL.Tuple(OpenIdProvider, OpenIdProviderConfig)) + providers: IDL.Vec(IDL.Tuple(OpenIdDelegationProvider, OpenIdProviderConfig)) }); const AuthenticationConfigInternetIdentity = IDL.Record({ derivation_origin: IDL.Opt(IDL.Text), diff --git a/src/declarations/sputnik/sputnik.factory.did.js b/src/declarations/sputnik/sputnik.factory.did.js index ba851264b2..2a2b91a073 100644 --- a/src/declarations/sputnik/sputnik.factory.did.js +++ b/src/declarations/sputnik/sputnik.factory.did.js @@ -158,7 +158,7 @@ export const idlFactory = ({ IDL }) => { created_at: IDL.Nat64, version: IDL.Opt(IDL.Nat64) }); - const OpenIdProvider = IDL.Variant({ + const OpenIdDelegationProvider = IDL.Variant({ GitHub: IDL.Null, Google: IDL.Null }); @@ -172,7 +172,7 @@ export const idlFactory = ({ IDL }) => { }); const AuthenticationConfigOpenId = IDL.Record({ observatory_id: IDL.Opt(IDL.Principal), - providers: IDL.Vec(IDL.Tuple(OpenIdProvider, OpenIdProviderConfig)) + providers: IDL.Vec(IDL.Tuple(OpenIdDelegationProvider, OpenIdProviderConfig)) }); const AuthenticationConfigInternetIdentity = IDL.Record({ derivation_origin: IDL.Opt(IDL.Text), diff --git a/src/libs/auth/src/delegation/get.rs b/src/libs/auth/src/delegation/get.rs index 29801c37e7..723b885098 100644 --- a/src/libs/auth/src/delegation/get.rs +++ b/src/libs/auth/src/delegation/get.rs @@ -4,8 +4,8 @@ use crate::delegation::types::{ use crate::delegation::utils::seed::calculate_seed; use crate::delegation::utils::signature::{build_signature_inputs, build_signature_msg}; use crate::delegation::utils::targets::build_targets; +use crate::openid::delegation::types::provider::OpenIdDelegationProvider; use crate::openid::types::interface::{OpenIdCredential, OpenIdCredentialKey}; -use crate::openid::types::provider::OpenIdProvider; use crate::state::get_salt; use crate::state::services::read_state; use crate::strategies::{AuthCertificateStrategy, AuthHeapStrategy}; @@ -15,7 +15,7 @@ pub fn openid_get_delegation( session_key: &SessionKey, expiration: Timestamp, credential: &OpenIdCredential, - provider: &OpenIdProvider, + provider: &OpenIdDelegationProvider, auth_heap: &impl AuthHeapStrategy, certificate: &impl AuthCertificateStrategy, ) -> GetDelegationResult { @@ -33,7 +33,7 @@ pub fn get_delegation( session_key: &SessionKey, expiration: Timestamp, key: &OpenIdCredentialKey, - provider: &OpenIdProvider, + provider: &OpenIdDelegationProvider, auth_heap: &impl AuthHeapStrategy, certificate: &impl AuthCertificateStrategy, ) -> GetDelegationResult { diff --git a/src/libs/auth/src/delegation/prepare.rs b/src/libs/auth/src/delegation/prepare.rs index 9a61d458bf..c5da48853f 100644 --- a/src/libs/auth/src/delegation/prepare.rs +++ b/src/libs/auth/src/delegation/prepare.rs @@ -6,8 +6,8 @@ use crate::delegation::utils::duration::build_expiration; use crate::delegation::utils::seed::calculate_seed; use crate::delegation::utils::signature::{build_signature_inputs, build_signature_msg}; use crate::delegation::utils::targets::build_targets; +use crate::openid::delegation::types::provider::OpenIdDelegationProvider; use crate::openid::types::interface::{OpenIdCredential, OpenIdCredentialKey}; -use crate::openid::types::provider::OpenIdProvider; use crate::state::get_salt; use crate::state::services::mutate_state; use crate::strategies::{AuthCertificateStrategy, AuthHeapStrategy}; @@ -18,7 +18,7 @@ use serde_bytes::ByteBuf; pub fn openid_prepare_delegation( session_key: &SessionKey, credential: &OpenIdCredential, - provider: &OpenIdProvider, + provider: &OpenIdDelegationProvider, auth_heap: &impl AuthHeapStrategy, certificate: &impl AuthCertificateStrategy, ) -> PrepareDelegationResult { @@ -36,7 +36,7 @@ pub fn openid_prepare_delegation( fn prepare_delegation( session_key: &SessionKey, key: &OpenIdCredentialKey, - provider: &OpenIdProvider, + provider: &OpenIdDelegationProvider, auth_heap: &impl AuthHeapStrategy, certificate: &impl AuthCertificateStrategy, ) -> PrepareDelegationResult { @@ -60,7 +60,7 @@ fn prepare_delegation( fn add_delegation_signature( session_key: &PublicKey, expiration: Timestamp, - provider: &OpenIdProvider, + provider: &OpenIdDelegationProvider, seed: &[u8], auth_heap: &impl AuthHeapStrategy, ) { diff --git a/src/libs/auth/src/delegation/utils/duration.rs b/src/libs/auth/src/delegation/utils/duration.rs index 587f842741..7a7ca03d3a 100644 --- a/src/libs/auth/src/delegation/utils/duration.rs +++ b/src/libs/auth/src/delegation/utils/duration.rs @@ -1,11 +1,14 @@ use crate::delegation::constants::{DEFAULT_EXPIRATION_PERIOD_NS, MAX_EXPIRATION_PERIOD_NS}; -use crate::openid::types::provider::OpenIdProvider; +use crate::openid::delegation::types::provider::OpenIdDelegationProvider; use crate::state::get_config; use crate::strategies::AuthHeapStrategy; use ic_cdk::api::time; use std::cmp::min; -pub fn build_expiration(provider: &OpenIdProvider, auth_heap: &impl AuthHeapStrategy) -> u64 { +pub fn build_expiration( + provider: &OpenIdDelegationProvider, + auth_heap: &impl AuthHeapStrategy, +) -> u64 { let max_time_to_live = get_config(auth_heap) .as_ref() .and_then(|config| config.openid.as_ref()) diff --git a/src/libs/auth/src/delegation/utils/targets.rs b/src/libs/auth/src/delegation/utils/targets.rs index 2d837cc43d..7704204e0f 100644 --- a/src/libs/auth/src/delegation/utils/targets.rs +++ b/src/libs/auth/src/delegation/utils/targets.rs @@ -1,5 +1,5 @@ use crate::delegation::types::DelegationTargets; -use crate::openid::types::provider::OpenIdProvider; +use crate::openid::delegation::types::provider::OpenIdDelegationProvider; use crate::state::get_config; use crate::strategies::AuthHeapStrategy; use junobuild_shared::ic::api::id; @@ -19,7 +19,7 @@ use junobuild_shared::ic::api::id; // Moreover, there is unlikely to be a valid use case where a delegation generated by the Satellite // should target no canister at all. pub fn build_targets( - provider: &OpenIdProvider, + provider: &OpenIdDelegationProvider, auth_heap: &impl AuthHeapStrategy, ) -> Option { get_config(auth_heap) diff --git a/src/libs/auth/src/openid/delegation/impls.rs b/src/libs/auth/src/openid/delegation/impls.rs new file mode 100644 index 0000000000..79a9bfbd0e --- /dev/null +++ b/src/libs/auth/src/openid/delegation/impls.rs @@ -0,0 +1,38 @@ +use crate::openid::delegation::types::provider::OpenIdDelegationProvider; +use crate::openid::types::provider::OpenIdProvider; + +impl TryFrom<&OpenIdProvider> for OpenIdDelegationProvider { + type Error = String; + + fn try_from(provider: &OpenIdProvider) -> Result { + match provider { + OpenIdProvider::Google => Ok(OpenIdDelegationProvider::Google), + OpenIdProvider::GitHubAuth => Ok(OpenIdDelegationProvider::GitHub), + } + } +} + +impl From<&OpenIdDelegationProvider> for OpenIdProvider { + fn from(delegation_provider: &OpenIdDelegationProvider) -> Self { + match delegation_provider { + OpenIdDelegationProvider::Google => OpenIdProvider::Google, + OpenIdDelegationProvider::GitHub => OpenIdProvider::GitHubAuth, + } + } +} + +impl OpenIdDelegationProvider { + pub fn jwks_url(&self) -> &'static str { + match self { + Self::Google => OpenIdProvider::Google.jwks_url(), + Self::GitHub => OpenIdProvider::GitHubAuth.jwks_url(), + } + } + + pub fn issuers(&self) -> &[&'static str] { + match self { + Self::Google => OpenIdProvider::Google.issuers(), + Self::GitHub => OpenIdProvider::GitHubAuth.issuers(), + } + } +} diff --git a/src/libs/auth/src/openid/delegation/mod.rs b/src/libs/auth/src/openid/delegation/mod.rs new file mode 100644 index 0000000000..39fcb9cfe1 --- /dev/null +++ b/src/libs/auth/src/openid/delegation/mod.rs @@ -0,0 +1,2 @@ +mod impls; +pub mod types; diff --git a/src/libs/auth/src/openid/delegation/types.rs b/src/libs/auth/src/openid/delegation/types.rs new file mode 100644 index 0000000000..3dadd16463 --- /dev/null +++ b/src/libs/auth/src/openid/delegation/types.rs @@ -0,0 +1,12 @@ +pub mod provider { + use candid::{CandidType, Deserialize}; + use serde::Serialize; + + #[derive( + CandidType, Serialize, Deserialize, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Debug, + )] + pub enum OpenIdDelegationProvider { + Google, + GitHub, + } +} diff --git a/src/libs/auth/src/openid/impls.rs b/src/libs/auth/src/openid/impls.rs index 24002271f9..41d7776e7e 100644 --- a/src/libs/auth/src/openid/impls.rs +++ b/src/libs/auth/src/openid/impls.rs @@ -39,14 +39,14 @@ impl OpenIdProvider { Self::Google => "https://www.googleapis.com/oauth2/v3/certs", // Swap for local development with the Juno API: // http://host.docker.internal:3000/v1/auth/certs - Self::GitHub => "https://api.juno.build/v1/auth/certs", + Self::GitHubAuth => "https://api.juno.build/v1/auth/certs", } } pub fn issuers(&self) -> &[&'static str] { match self { OpenIdProvider::Google => &["https://accounts.google.com", "accounts.google.com"], - OpenIdProvider::GitHub => &["https://api.juno.build/auth/github"], + OpenIdProvider::GitHubAuth => &["https://api.juno.build/auth/github"], } } } @@ -93,7 +93,7 @@ impl Display for OpenIdProvider { fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult { match self { OpenIdProvider::Google => write!(f, "Google"), - OpenIdProvider::GitHub => write!(f, "GitHub"), + OpenIdProvider::GitHubAuth => write!(f, "GitHub"), } } } diff --git a/src/libs/auth/src/openid/jwt/provider.rs b/src/libs/auth/src/openid/jwt/provider.rs index 42f5cbebde..a1a3b6c9bf 100644 --- a/src/libs/auth/src/openid/jwt/provider.rs +++ b/src/libs/auth/src/openid/jwt/provider.rs @@ -1,7 +1,7 @@ +use crate::openid::delegation::types::provider::OpenIdDelegationProvider; use crate::openid::jwt::header::decode_jwt_header; use crate::openid::jwt::types::errors::JwtFindProviderError; use crate::openid::jwt::types::token::UnsafeClaims; -use crate::openid::types::provider::OpenIdProvider; use crate::state::types::config::{OpenIdProviderConfig, OpenIdProviders}; use jsonwebtoken::dangerous; @@ -10,7 +10,7 @@ use jsonwebtoken::dangerous; pub fn unsafe_find_jwt_provider<'a>( providers: &'a OpenIdProviders, jwt: &str, -) -> Result<(OpenIdProvider, &'a OpenIdProviderConfig), JwtFindProviderError> { +) -> Result<(OpenIdDelegationProvider, &'a OpenIdProviderConfig), JwtFindProviderError> { // 1) Header sanity check decode_jwt_header(jwt).map_err(JwtFindProviderError::from)?; @@ -34,8 +34,8 @@ pub fn unsafe_find_jwt_provider<'a>( #[cfg(test)] mod tests { use super::unsafe_find_jwt_provider; + use crate::openid::delegation::types::provider::OpenIdDelegationProvider; use crate::openid::jwt::types::errors::JwtFindProviderError; - use crate::openid::types::provider::OpenIdProvider; use crate::state::types::config::{OpenIdProviderConfig, OpenIdProviders}; use base64::engine::general_purpose::URL_SAFE_NO_PAD; use base64::Engine; @@ -54,7 +54,7 @@ mod tests { fn providers_with_google() -> OpenIdProviders { let mut map = BTreeMap::new(); map.insert( - OpenIdProvider::Google, + OpenIdDelegationProvider::Google, OpenIdProviderConfig { client_id: "client-123".into(), delegation: None, @@ -73,7 +73,7 @@ mod tests { let (provider, cfg) = unsafe_find_jwt_provider(&provs, &jwt).expect("should match provider"); - assert_eq!(provider, OpenIdProvider::Google); + assert_eq!(provider, OpenIdDelegationProvider::Google); assert_eq!(cfg.client_id, "client-123"); } @@ -85,7 +85,7 @@ mod tests { let provs = providers_with_google(); let (provider, _) = unsafe_find_jwt_provider(&provs, &jwt).expect("should match even without typ"); - assert_eq!(provider, OpenIdProvider::Google); + assert_eq!(provider, OpenIdDelegationProvider::Google); } #[test] diff --git a/src/libs/auth/src/openid/mod.rs b/src/libs/auth/src/openid/mod.rs index bce9aa14e3..c8fb4f5463 100644 --- a/src/libs/auth/src/openid/mod.rs +++ b/src/libs/auth/src/openid/mod.rs @@ -1,3 +1,4 @@ +pub mod delegation; mod impls; pub mod jwkset; pub mod jwt; diff --git a/src/libs/auth/src/openid/types.rs b/src/libs/auth/src/openid/types.rs index b5b51b003b..59a372983a 100644 --- a/src/libs/auth/src/openid/types.rs +++ b/src/libs/auth/src/openid/types.rs @@ -44,7 +44,7 @@ pub mod provider { )] pub enum OpenIdProvider { Google, - GitHub, + GitHubAuth, // GitHub user authentication (OAuth) via Juno API proxy } #[derive(CandidType, Serialize, Deserialize, Clone)] diff --git a/src/libs/auth/src/openid/verify.rs b/src/libs/auth/src/openid/verify.rs index ca3b90cc2b..509fe33184 100644 --- a/src/libs/auth/src/openid/verify.rs +++ b/src/libs/auth/src/openid/verify.rs @@ -1,3 +1,4 @@ +use crate::openid::delegation::types::provider::OpenIdDelegationProvider; use crate::openid::jwkset::{get_jwks, get_or_refresh_jwks}; use crate::openid::jwt::types::cert::Jwks; use crate::openid::jwt::{unsafe_find_jwt_provider, verify_openid_jwt}; @@ -10,7 +11,7 @@ use crate::state::types::state::Salt; use crate::strategies::AuthHeapStrategy; type VerifyOpenIdCredentialsResult = - Result<(OpenIdCredential, OpenIdProvider), VerifyOpenidCredentialsError>; + Result<(OpenIdCredential, OpenIdDelegationProvider), VerifyOpenidCredentialsError>; pub async fn verify_openid_credentials_with_jwks_renewal( jwt: &str, @@ -18,14 +19,16 @@ pub async fn verify_openid_credentials_with_jwks_renewal( providers: &OpenIdProviders, auth_heap: &impl AuthHeapStrategy, ) -> VerifyOpenIdCredentialsResult { - let (provider, config) = unsafe_find_jwt_provider(providers, jwt) + let (delegation_provider, config) = unsafe_find_jwt_provider(providers, jwt) .map_err(VerifyOpenidCredentialsError::JwtFindProvider)?; + let provider: OpenIdProvider = (&delegation_provider).into(); + let jwks = get_or_refresh_jwks(&provider, jwt, auth_heap) .await .map_err(VerifyOpenidCredentialsError::GetOrFetchJwks)?; - verify_openid_credentials(jwt, &jwks, &provider, &config.client_id, salt) + verify_openid_credentials(jwt, &jwks, &delegation_provider, &config.client_id, salt) } pub fn verify_openid_credentials_with_cached_jwks( @@ -34,18 +37,20 @@ pub fn verify_openid_credentials_with_cached_jwks( providers: &OpenIdProviders, auth_heap: &impl AuthHeapStrategy, ) -> VerifyOpenIdCredentialsResult { - let (provider, config) = unsafe_find_jwt_provider(providers, jwt) + let (delegation_provider, config) = unsafe_find_jwt_provider(providers, jwt) .map_err(VerifyOpenidCredentialsError::JwtFindProvider)?; + let provider: OpenIdProvider = (&delegation_provider).into(); + let jwks = get_jwks(&provider, auth_heap).ok_or(VerifyOpenidCredentialsError::GetCachedJwks)?; - verify_openid_credentials(jwt, &jwks, &provider, &config.client_id, salt) + verify_openid_credentials(jwt, &jwks, &delegation_provider, &config.client_id, salt) } fn verify_openid_credentials( jwt: &str, jwks: &Jwks, - provider: &OpenIdProvider, + provider: &OpenIdDelegationProvider, client_id: &OpenIdProviderClientId, salt: &Salt, ) -> VerifyOpenIdCredentialsResult { diff --git a/src/libs/auth/src/state/types.rs b/src/libs/auth/src/state/types.rs index abc4278382..3f1d6a5831 100644 --- a/src/libs/auth/src/state/types.rs +++ b/src/libs/auth/src/state/types.rs @@ -53,7 +53,7 @@ pub(crate) mod runtime_state { pub mod config { use crate::delegation::types::DelegationTargets; - use crate::openid::types::provider::OpenIdProvider; + use crate::openid::delegation::types::provider::OpenIdDelegationProvider; use candid::{CandidType, Deserialize, Principal}; use junobuild_shared::types::core::DomainName; use junobuild_shared::types::state::{Timestamp, Version}; @@ -87,7 +87,7 @@ pub mod config { pub allowed_callers: Vec, } - pub type OpenIdProviders = BTreeMap; + pub type OpenIdProviders = BTreeMap; pub type OpenIdProviderClientId = String; diff --git a/src/libs/satellite/satellite.did b/src/libs/satellite/satellite.did index 7814ee0c99..32aca29a2f 100644 --- a/src/libs/satellite/satellite.did +++ b/src/libs/satellite/satellite.did @@ -40,7 +40,7 @@ type AuthenticationConfigInternetIdentity = record { }; type AuthenticationConfigOpenId = record { observatory_id : opt principal; - providers : vec record { OpenIdProvider; OpenIdProviderConfig }; + providers : vec record { OpenIdDelegationProvider; OpenIdProviderConfig }; }; type AuthenticationError = variant { PrepareDelegation : PrepareDelegationError; @@ -210,6 +210,7 @@ type ListRulesResults = record { }; type Memory = variant { Heap; Stable }; type MemorySize = record { stable : nat64; heap : nat64 }; +type OpenIdDelegationProvider = variant { GitHub; Google }; type OpenIdGetDelegationArgs = record { jwt : text; session_key : blob; @@ -221,7 +222,6 @@ type OpenIdPrepareDelegationArgs = record { session_key : blob; salt : blob; }; -type OpenIdProvider = variant { GitHub; Google }; type OpenIdProviderConfig = record { delegation : opt OpenIdProviderDelegationConfig; client_id : text; diff --git a/src/libs/satellite/src/auth/delegation.rs b/src/libs/satellite/src/auth/delegation.rs index 78a9fc0a96..534180d036 100644 --- a/src/libs/satellite/src/auth/delegation.rs +++ b/src/libs/satellite/src/auth/delegation.rs @@ -4,13 +4,19 @@ use junobuild_auth::delegation::types::{ GetDelegationError, GetDelegationResult, OpenIdGetDelegationArgs, OpenIdPrepareDelegationArgs, PrepareDelegationError, PreparedDelegation, }; +use junobuild_auth::openid::delegation::types::provider::OpenIdDelegationProvider; use junobuild_auth::openid::types::interface::OpenIdCredential; -use junobuild_auth::openid::types::provider::OpenIdProvider; use junobuild_auth::state::types::config::OpenIdProviders; use junobuild_auth::{delegation, openid}; -pub type OpenIdPrepareDelegationResult = - Result<(PreparedDelegation, OpenIdProvider, OpenIdCredential), PrepareDelegationError>; +pub type OpenIdPrepareDelegationResult = Result< + ( + PreparedDelegation, + OpenIdDelegationProvider, + OpenIdCredential, + ), + PrepareDelegationError, +>; pub async fn openid_prepare_delegation( args: &OpenIdPrepareDelegationArgs, diff --git a/src/libs/satellite/src/auth/register.rs b/src/libs/satellite/src/auth/register.rs index 8e01852726..e14b6db360 100644 --- a/src/libs/satellite/src/auth/register.rs +++ b/src/libs/satellite/src/auth/register.rs @@ -7,8 +7,8 @@ use crate::user::core::types::state::{OpenIdData, ProviderData, UserData}; use crate::Doc; use candid::Principal; use junobuild_auth::delegation::types::UserKey; +use junobuild_auth::openid::delegation::types::provider::OpenIdDelegationProvider; use junobuild_auth::openid::types::interface::OpenIdCredential; -use junobuild_auth::openid::types::provider::OpenIdProvider; use junobuild_collections::constants::db::COLLECTION_USER_KEY; use junobuild_collections::msg::msg_db_collection_not_found; use junobuild_shared::ic::api::id; @@ -16,7 +16,7 @@ use junobuild_utils::decode_doc_data; pub fn register_user( public_key: &UserKey, - provider: &OpenIdProvider, + provider: &OpenIdDelegationProvider, credential: &OpenIdCredential, ) -> Result { let user_collection = COLLECTION_USER_KEY.to_string(); diff --git a/src/libs/satellite/src/user/core/impls.rs b/src/libs/satellite/src/user/core/impls.rs index c3bf7e3440..1647cba46c 100644 --- a/src/libs/satellite/src/user/core/impls.rs +++ b/src/libs/satellite/src/user/core/impls.rs @@ -9,8 +9,8 @@ use crate::user::core::types::state::{ AuthProvider, OpenIdData, ProviderData, UserData, WebAuthnData, }; use crate::{Doc, SetDoc}; +use junobuild_auth::openid::delegation::types::provider::OpenIdDelegationProvider; use junobuild_auth::openid::types::interface::OpenIdCredential; -use junobuild_auth::openid::types::provider::OpenIdProvider; use junobuild_auth::profile::types::{OpenIdProfile, Validated}; use junobuild_utils::encode_doc_data; @@ -160,11 +160,11 @@ impl From<&OpenIdCredential> for OpenIdData { } } -impl From<&OpenIdProvider> for AuthProvider { - fn from(provider: &OpenIdProvider) -> Self { +impl From<&OpenIdDelegationProvider> for AuthProvider { + fn from(provider: &OpenIdDelegationProvider) -> Self { match provider { - OpenIdProvider::Google => AuthProvider::Google, - OpenIdProvider::GitHub => AuthProvider::GitHub, + OpenIdDelegationProvider::Google => AuthProvider::Google, + OpenIdDelegationProvider::GitHub => AuthProvider::GitHub, } } } @@ -340,11 +340,11 @@ mod tests { #[test] fn test_openid_provider_to_auth_provider() { assert!(matches!( - AuthProvider::from(&OpenIdProvider::Google), + AuthProvider::from(&OpenIdDelegationProvider::Google), AuthProvider::Google )); assert!(matches!( - AuthProvider::from(&OpenIdProvider::GitHub), + AuthProvider::from(&OpenIdDelegationProvider::GitHub), AuthProvider::GitHub )); } diff --git a/src/observatory/observatory.did b/src/observatory/observatory.did index 8d9d593ffb..b0a25c013f 100644 --- a/src/observatory/observatory.did +++ b/src/observatory/observatory.did @@ -68,7 +68,7 @@ type OpenIdCertificate = record { created_at : nat64; version : opt nat64; }; -type OpenIdProvider = variant { GitHub; Google }; +type OpenIdProvider = variant { Google; GitHubAuth }; type RateConfig = record { max_tokens : nat64; time_per_token_ns : nat64 }; type RateKind = variant { OpenIdCertificateRequests }; type Segment = record { diff --git a/src/observatory/src/lib.rs b/src/observatory/src/lib.rs index e183fe0da0..34d7e821c4 100644 --- a/src/observatory/src/lib.rs +++ b/src/observatory/src/lib.rs @@ -11,6 +11,7 @@ mod random; mod store; mod templates; mod types; +mod upgrade; use crate::types::interface::GetNotifications; use crate::types::interface::NotifyStatus; diff --git a/src/observatory/src/memory/lifecycle.rs b/src/observatory/src/memory/lifecycle.rs index f841d7183f..6d70f08575 100644 --- a/src/observatory/src/memory/lifecycle.rs +++ b/src/observatory/src/memory/lifecycle.rs @@ -3,6 +3,7 @@ use crate::memory::state::STATE; use crate::openid::scheduler::defer_restart_monitoring; use crate::random::defer_init_random_seed; use crate::types::state::{HeapState, State}; +use crate::upgrade::types::upgrade::UpgradeState; use ciborium::{from_reader, into_writer}; use ic_cdk_macros::{init, post_upgrade, pre_upgrade}; use junobuild_shared::ic::api::caller; @@ -45,9 +46,12 @@ fn post_upgrade() { let memory = get_memory_upgrades(); let state_bytes = read_post_upgrade(&memory); - let state: State = from_reader(&*state_bytes) + // TODO: remove once OpenIdProvider migrated on mainnet + let upgrade_state: UpgradeState = from_reader(&*state_bytes) .expect("Failed to decode the state of the observatory in post_upgrade hook."); + let state: State = upgrade_state.into(); + STATE.with(|s| *s.borrow_mut() = state); init_runtime_state(); diff --git a/src/observatory/src/openid/scheduler.rs b/src/observatory/src/openid/scheduler.rs index be0a668c3a..eab85821fc 100644 --- a/src/observatory/src/openid/scheduler.rs +++ b/src/observatory/src/openid/scheduler.rs @@ -9,7 +9,7 @@ use std::time::Duration; pub fn defer_restart_monitoring() { // Early spare one timer if no scheduler is enabled. - let enabled_count = [OpenIdProvider::Google, OpenIdProvider::GitHub] + let enabled_count = [OpenIdProvider::Google, OpenIdProvider::GitHubAuth] .into_iter() .filter(|provider| is_scheduler_enabled(provider)) .count(); @@ -24,7 +24,7 @@ pub fn defer_restart_monitoring() { } async fn restart_monitoring() { - for provider in [OpenIdProvider::Google, OpenIdProvider::GitHub] { + for provider in [OpenIdProvider::Google, OpenIdProvider::GitHubAuth] { schedule_certificate_update(provider, None); } } diff --git a/src/observatory/src/upgrade/impls.rs b/src/observatory/src/upgrade/impls.rs new file mode 100644 index 0000000000..75355320c2 --- /dev/null +++ b/src/observatory/src/upgrade/impls.rs @@ -0,0 +1,51 @@ +use crate::types::state::{HeapState, OpenId, State}; +use crate::upgrade::types::upgrade::{ + UpgradeHeapState, UpgradeOpenId, UpgradeOpenIdProvider, UpgradeState, +}; +use junobuild_auth::openid::types::provider::OpenIdProvider; + +impl From for State { + fn from(upgrade: UpgradeState) -> Self { + State { + stable: upgrade.stable, + heap: upgrade.heap.into(), + } + } +} + +impl From for HeapState { + fn from(upgrade: UpgradeHeapState) -> Self { + HeapState { + controllers: upgrade.controllers, + env: upgrade.env, + openid: upgrade.openid.map(|openid| openid.into()), + rates: upgrade.rates, + } + } +} + +impl From for OpenId { + fn from(upgrade: UpgradeOpenId) -> Self { + OpenId { + certificates: upgrade + .certificates + .into_iter() + .map(|(provider, cert)| (provider.into(), cert)) + .collect(), + schedulers: upgrade + .schedulers + .into_iter() + .map(|(provider, scheduler)| (provider.into(), scheduler)) + .collect(), + } + } +} + +impl From for OpenIdProvider { + fn from(old: UpgradeOpenIdProvider) -> Self { + match old { + UpgradeOpenIdProvider::Google => OpenIdProvider::Google, + UpgradeOpenIdProvider::GitHub => OpenIdProvider::GitHubAuth, + } + } +} diff --git a/src/observatory/src/upgrade/mod.rs b/src/observatory/src/upgrade/mod.rs new file mode 100644 index 0000000000..39fcb9cfe1 --- /dev/null +++ b/src/observatory/src/upgrade/mod.rs @@ -0,0 +1,2 @@ +mod impls; +pub mod types; diff --git a/src/observatory/src/upgrade/types.rs b/src/observatory/src/upgrade/types.rs new file mode 100644 index 0000000000..d5cd9d858d --- /dev/null +++ b/src/observatory/src/upgrade/types.rs @@ -0,0 +1,40 @@ +pub mod upgrade { + use crate::memory::init_stable_state; + use crate::types::state::{Env, OpenIdScheduler, Rates, StableState}; + use candid::{CandidType, Deserialize}; + use junobuild_auth::openid::types::provider::OpenIdCertificate; + use junobuild_shared::types::state::Controllers; + use serde::Serialize; + use std::collections::HashMap; + + #[derive(Serialize, Deserialize)] + pub struct UpgradeState { + // Direct stable state: State that is uses stable memory directly as its store. No need for pre/post upgrade hooks. + #[serde(skip, default = "init_stable_state")] + pub stable: StableState, + + pub heap: UpgradeHeapState, + } + + #[derive(Default, CandidType, Serialize, Deserialize)] + pub struct UpgradeHeapState { + pub controllers: Controllers, + pub env: Option, + pub openid: Option, + pub rates: Option, + } + + #[derive(Default, CandidType, Serialize, Deserialize)] + pub struct UpgradeOpenId { + pub certificates: HashMap, + pub schedulers: HashMap, + } + + #[derive( + CandidType, Serialize, Deserialize, Clone, Hash, PartialEq, Eq, PartialOrd, Ord, Debug, + )] + pub enum UpgradeOpenIdProvider { + Google, + GitHub, + } +} diff --git a/src/satellite/satellite.did b/src/satellite/satellite.did index 8d8d97afff..4c6ce63070 100644 --- a/src/satellite/satellite.did +++ b/src/satellite/satellite.did @@ -42,7 +42,7 @@ type AuthenticationConfigInternetIdentity = record { }; type AuthenticationConfigOpenId = record { observatory_id : opt principal; - providers : vec record { OpenIdProvider; OpenIdProviderConfig }; + providers : vec record { OpenIdDelegationProvider; OpenIdProviderConfig }; }; type AuthenticationError = variant { PrepareDelegation : PrepareDelegationError; @@ -212,6 +212,7 @@ type ListRulesResults = record { }; type Memory = variant { Heap; Stable }; type MemorySize = record { stable : nat64; heap : nat64 }; +type OpenIdDelegationProvider = variant { GitHub; Google }; type OpenIdGetDelegationArgs = record { jwt : text; session_key : blob; @@ -223,7 +224,6 @@ type OpenIdPrepareDelegationArgs = record { session_key : blob; salt : blob; }; -type OpenIdProvider = variant { GitHub; Google }; type OpenIdProviderConfig = record { delegation : opt OpenIdProviderDelegationConfig; client_id : text; diff --git a/src/sputnik/sputnik.did b/src/sputnik/sputnik.did index 06751195a6..c63c0c969b 100644 --- a/src/sputnik/sputnik.did +++ b/src/sputnik/sputnik.did @@ -42,7 +42,7 @@ type AuthenticationConfigInternetIdentity = record { }; type AuthenticationConfigOpenId = record { observatory_id : opt principal; - providers : vec record { OpenIdProvider; OpenIdProviderConfig }; + providers : vec record { OpenIdDelegationProvider; OpenIdProviderConfig }; }; type AuthenticationError = variant { PrepareDelegation : PrepareDelegationError; @@ -212,6 +212,7 @@ type ListRulesResults = record { }; type Memory = variant { Heap; Stable }; type MemorySize = record { stable : nat64; heap : nat64 }; +type OpenIdDelegationProvider = variant { GitHub; Google }; type OpenIdGetDelegationArgs = record { jwt : text; session_key : blob; @@ -223,7 +224,6 @@ type OpenIdPrepareDelegationArgs = record { session_key : blob; salt : blob; }; -type OpenIdProvider = variant { GitHub; Google }; type OpenIdProviderConfig = record { delegation : opt OpenIdProviderDelegationConfig; client_id : text; diff --git a/src/tests/constants/auth-tests.constants.ts b/src/tests/constants/auth-tests.constants.ts index 8c85040c67..af3b4fbee8 100644 --- a/src/tests/constants/auth-tests.constants.ts +++ b/src/tests/constants/auth-tests.constants.ts @@ -7,4 +7,4 @@ export const LOG_SALT_INITIALIZED = 'Authentication salt initialized.'; export const LOG_SALT_ALREADY_INITIALIZED = 'Authentication salt exists. Skipping initialization.'; export const GOOGLE_OPEN_ID_PROVIDER = { Google: null }; -export const GITHUB_OPEN_ID_PROVIDER = { GitHub: null }; +export const GITHUB_OPEN_ID_PROVIDER = { GitHubAuth: null }; diff --git a/src/tests/declarations/test_satellite/test_satellite.did.d.ts b/src/tests/declarations/test_satellite/test_satellite.did.d.ts index 9ee13bd161..2c18c55c09 100644 --- a/src/tests/declarations/test_satellite/test_satellite.did.d.ts +++ b/src/tests/declarations/test_satellite/test_satellite.did.d.ts @@ -54,7 +54,7 @@ export interface AuthenticationConfigInternetIdentity { } export interface AuthenticationConfigOpenId { observatory_id: [] | [Principal]; - providers: Array<[OpenIdProvider, OpenIdProviderConfig]>; + providers: Array<[OpenIdDelegationProvider, OpenIdProviderConfig]>; } export type AuthenticationError = | { @@ -259,6 +259,7 @@ export interface MemorySize { stable: bigint; heap: bigint; } +export type OpenIdDelegationProvider = { GitHub: null } | { Google: null }; export interface OpenIdGetDelegationArgs { jwt: string; session_key: Uint8Array; @@ -270,7 +271,6 @@ export interface OpenIdPrepareDelegationArgs { session_key: Uint8Array; salt: Uint8Array; } -export type OpenIdProvider = { GitHub: null } | { Google: null }; export interface OpenIdProviderConfig { delegation: [] | [OpenIdProviderDelegationConfig]; client_id: string; diff --git a/src/tests/declarations/test_satellite/test_satellite.factory.certified.did.js b/src/tests/declarations/test_satellite/test_satellite.factory.certified.did.js index a6e62ab11a..5490f2ed38 100644 --- a/src/tests/declarations/test_satellite/test_satellite.factory.certified.did.js +++ b/src/tests/declarations/test_satellite/test_satellite.factory.certified.did.js @@ -158,7 +158,7 @@ export const idlFactory = ({ IDL }) => { created_at: IDL.Nat64, version: IDL.Opt(IDL.Nat64) }); - const OpenIdProvider = IDL.Variant({ + const OpenIdDelegationProvider = IDL.Variant({ GitHub: IDL.Null, Google: IDL.Null }); @@ -172,7 +172,7 @@ export const idlFactory = ({ IDL }) => { }); const AuthenticationConfigOpenId = IDL.Record({ observatory_id: IDL.Opt(IDL.Principal), - providers: IDL.Vec(IDL.Tuple(OpenIdProvider, OpenIdProviderConfig)) + providers: IDL.Vec(IDL.Tuple(OpenIdDelegationProvider, OpenIdProviderConfig)) }); const AuthenticationConfigInternetIdentity = IDL.Record({ derivation_origin: IDL.Opt(IDL.Text), diff --git a/src/tests/declarations/test_satellite/test_satellite.factory.did.js b/src/tests/declarations/test_satellite/test_satellite.factory.did.js index 13c363c35e..97ecb74c49 100644 --- a/src/tests/declarations/test_satellite/test_satellite.factory.did.js +++ b/src/tests/declarations/test_satellite/test_satellite.factory.did.js @@ -158,7 +158,7 @@ export const idlFactory = ({ IDL }) => { created_at: IDL.Nat64, version: IDL.Opt(IDL.Nat64) }); - const OpenIdProvider = IDL.Variant({ + const OpenIdDelegationProvider = IDL.Variant({ GitHub: IDL.Null, Google: IDL.Null }); @@ -172,7 +172,7 @@ export const idlFactory = ({ IDL }) => { }); const AuthenticationConfigOpenId = IDL.Record({ observatory_id: IDL.Opt(IDL.Principal), - providers: IDL.Vec(IDL.Tuple(OpenIdProvider, OpenIdProviderConfig)) + providers: IDL.Vec(IDL.Tuple(OpenIdDelegationProvider, OpenIdProviderConfig)) }); const AuthenticationConfigInternetIdentity = IDL.Record({ derivation_origin: IDL.Opt(IDL.Text), diff --git a/src/tests/fixtures/test_satellite/test_satellite.did b/src/tests/fixtures/test_satellite/test_satellite.did index 5990623871..2a9b557268 100644 --- a/src/tests/fixtures/test_satellite/test_satellite.did +++ b/src/tests/fixtures/test_satellite/test_satellite.did @@ -42,7 +42,7 @@ type AuthenticationConfigInternetIdentity = record { }; type AuthenticationConfigOpenId = record { observatory_id : opt principal; - providers : vec record { OpenIdProvider; OpenIdProviderConfig }; + providers : vec record { OpenIdDelegationProvider; OpenIdProviderConfig }; }; type AuthenticationError = variant { PrepareDelegation : PrepareDelegationError; @@ -212,6 +212,7 @@ type ListRulesResults = record { }; type Memory = variant { Heap; Stable }; type MemorySize = record { stable : nat64; heap : nat64 }; +type OpenIdDelegationProvider = variant { GitHub; Google }; type OpenIdGetDelegationArgs = record { jwt : text; session_key : blob; @@ -223,7 +224,6 @@ type OpenIdPrepareDelegationArgs = record { session_key : blob; salt : blob; }; -type OpenIdProvider = variant { GitHub; Google }; type OpenIdProviderConfig = record { delegation : opt OpenIdProviderDelegationConfig; client_id : text; diff --git a/src/tests/specs/console/upgrade/console.upgrade-v0-4-0.openid-provider.spec.ts b/src/tests/specs/console/upgrade/console.upgrade-v0-4-0.openid-provider.spec.ts new file mode 100644 index 0000000000..76fa610f76 --- /dev/null +++ b/src/tests/specs/console/upgrade/console.upgrade-v0-4-0.openid-provider.spec.ts @@ -0,0 +1,202 @@ +import { + idlFactoryConsole, + idlFactoryConsole033, + idlFactoryObservatory040, + type ConsoleActor, + type ConsoleActor033, + type ConsoleDid, + type ConsoleDid033, + type ObservatoryActor040, + type SatelliteDid +} from '$declarations'; +import { PocketIc, type Actor } from '@dfinity/pic'; +import { assertNonNullish, fromNullable } from '@dfinity/utils'; +import type { Identity } from '@icp-sdk/core/agent'; +import { ECDSAKeyIdentity, Ed25519KeyIdentity } from '@icp-sdk/core/identity'; +import type { Principal } from '@icp-sdk/core/principal'; +import { inject } from 'vitest'; +import { CONSOLE_ID } from '../../../constants/console-tests.constants'; +import { OBSERVATORY_ID } from '../../../constants/observatory-tests.constants'; +import { mockGitHubClientId } from '../../../mocks/jwt.mocks'; +import { authenticateAndMakeIdentity } from '../../../utils/auth-identity-tests.utils'; +import { generateNonce } from '../../../utils/auth-nonce-tests.utils'; +import type { TestSession } from '../../../utils/auth-tests.utils'; +import { deploySegments } from '../../../utils/console-tests.utils'; +import { tick } from '../../../utils/pic-tests.utils'; +import { updateRateConfigNoLimit } from '../../../utils/rate.tests.utils'; +import { + CONSOLE_WASM_PATH, + controllersInitArgs, + downloadConsole, + downloadObservatory +} from '../../../utils/setup-tests.utils'; + +describe('Console > Upgrade > OpenIdProvider > v0.3.3 -> v0.4.0', () => { + let pic: PocketIc; + let actor: Actor; + let canisterId: Principal; + let userIdentity: Identity; + + const controller = Ed25519KeyIdentity.generate(); + + const upgradeCurrent = async () => { + await tick(pic); + + await pic.upgradeCanister({ + canisterId, + wasm: CONSOLE_WASM_PATH, + sender: controller.getPrincipal() + }); + }; + + const registerUser = async ({ session }: { session: TestSession }) => { + actor.setIdentity(session.user); + + const { account, identity } = await authenticateAndMakeIdentity<{ + account: ConsoleDid.Account; + }>({ + pic, + session, + actor, + method: 'github' + }); + + const provider = fromNullable(account.provider); + + assertNonNullish(provider); + + expect('OpenId' in provider).toBeTruthy(); + + userIdentity = identity; + }; + + const setupAuth = async (): Promise<{ session: TestSession }> => { + // User and session + const user = Ed25519KeyIdentity.generate(); + const sessionKey = await ECDSAKeyIdentity.generate(); + const publicKey = new Uint8Array(sessionKey.getPublicKey().toDer()); + const { nonce, salt } = await generateNonce({ caller: user }); + + const destination = await downloadObservatory({ junoVersion: '0.0.66', version: '0.4.0' }); + + const { actor: obsA } = await pic.setupCanister({ + idlFactory: idlFactoryObservatory040, + wasm: destination, + sender: controller.getPrincipal(), + targetCanisterId: OBSERVATORY_ID + }); + + const observatoryActor = obsA; + observatoryActor.setIdentity(controller); + + const config: SatelliteDid.SetAuthenticationConfig = { + internet_identity: [], + rules: [], + openid: [ + { + providers: [ + [{ GitHub: null }, { client_id: mockGitHubClientId, delegation: [] }] as [ + ConsoleDid033.OpenIdProvider, + ConsoleDid033.OpenIdProviderConfig + ] + ], + observatory_id: [] + } + ], + version: [1n] + }; + + const { set_auth_config } = actor; + await set_auth_config(config); + + // Start fetching OpenID Jwts in Observatory + const { start_openid_monitoring } = observatoryActor; + await start_openid_monitoring({ GitHub: null }); + + await updateRateConfigNoLimit({ actor: observatoryActor }); + + return { + session: { + nonce, + publicKey, + salt, + sessionKey, + user + } + }; + }; + + beforeAll(async () => { + pic = await PocketIc.create(inject('PIC_URL')); + + const currentDate = new Date(2021, 6, 10, 0, 0, 0, 0); + await pic.setTime(currentDate.getTime()); + + const destination = await downloadConsole({ junoVersion: '0.0.66', version: '0.3.2' }); + + const { actor: c, canisterId: cId } = await pic.setupCanister({ + idlFactory: idlFactoryConsole033, + wasm: destination, + arg: controllersInitArgs(controller), + sender: controller.getPrincipal(), + targetCanisterId: CONSOLE_ID + }); + + actor = c; + canisterId = cId; + + actor.setIdentity(controller); + + await deploySegments({ + actor, + withSatellite: true, + withOrbiter: false + }); + + const { session } = await setupAuth(); + + await registerUser({ + session + }); + + // Register set the user as identity + actor.setIdentity(controller); + }); + + afterAll(async () => { + await pic?.tearDown(); + }); + + it('should migrate heap OpenIdState.certificates to OpenIdProvider.GitHubAuth', async () => { + await expect(upgradeCurrent()).resolves.not.toThrowError(); + }); + + it('should still be configured with GitHub respectively newly OpenIdDelegationProvider.GitHub', async () => { + const newActor = pic.createActor(idlFactoryConsole, canisterId); + newActor.setIdentity(controller); + + const { get_auth_config } = newActor; + + const config = fromNullable(await get_auth_config()); + + assertNonNullish(config); + + const openid = fromNullable(config.openid); + + assertNonNullish(openid); + + expect('GitHub' in openid.providers[0][0]).toBeTruthy(); + }); + + it('should still list the user', async () => { + const newActor = pic.createActor(idlFactoryConsole, canisterId); + newActor.setIdentity(controller); + + const { list_accounts } = newActor; + + const users = await list_accounts(); + + expect(users).toHaveLength(1); + expect(userIdentity.getPrincipal().toText()).toEqual(users[0][0].toText()); + }); +}); diff --git a/src/tests/specs/observatory/observatory.openid.upgrade.spec.ts b/src/tests/specs/observatory/observatory.openid.upgrade.spec.ts index 51f16dcc1f..5ba715aa0a 100644 --- a/src/tests/specs/observatory/observatory.openid.upgrade.spec.ts +++ b/src/tests/specs/observatory/observatory.openid.upgrade.spec.ts @@ -15,7 +15,8 @@ import { assertOpenIdHttpsOutcalls } from '../../utils/observatory-openid-tests. import { tick } from '../../utils/pic-tests.utils'; import { OBSERVATORY_WASM_PATH } from '../../utils/setup-tests.utils'; -describe('Observatory > OpenId > Upgrade', async () => { +// TODO: reactivate once OpenIdProvider migrated on mainnet +describe.todo('Observatory > OpenId > Upgrade', async () => { let pic: PocketIc; let actor: Actor; let observatoryId: Principal; diff --git a/src/tests/specs/observatory/observatory.upgrade-v0-5-0.openid-provider.spec.ts b/src/tests/specs/observatory/observatory.upgrade-v0-5-0.openid-provider.spec.ts new file mode 100644 index 0000000000..2b7e78af95 --- /dev/null +++ b/src/tests/specs/observatory/observatory.upgrade-v0-5-0.openid-provider.spec.ts @@ -0,0 +1,98 @@ +import { + idlFactoryObservatory, + idlFactoryObservatory040, + type ObservatoryActor, + type ObservatoryActor040 +} from '$declarations'; +import { PocketIc, type Actor } from '@dfinity/pic'; +import { fromNullable } from '@dfinity/utils'; +import { Ed25519KeyIdentity } from '@icp-sdk/core/identity'; +import type { Principal } from '@icp-sdk/core/principal'; +import { inject } from 'vitest'; +import { GITHUB_OPEN_ID_PROVIDER } from '../../constants/auth-tests.constants'; +import { OBSERVATORY_ID } from '../../constants/observatory-tests.constants'; +import { mockGitHubClientId } from '../../mocks/jwt.mocks'; +import { generateNonce } from '../../utils/auth-nonce-tests.utils'; +import { makeMockGitHubOpenIdJwt } from '../../utils/jwt-tests.utils'; +import { assertOpenIdHttpsOutcalls } from '../../utils/observatory-openid-tests.utils'; +import { tick } from '../../utils/pic-tests.utils'; +import { downloadObservatory, OBSERVATORY_WASM_PATH } from '../../utils/setup-tests.utils'; + +describe('Observatory > Upgrade', () => { + let pic: PocketIc; + let actor: Actor; + let observatoryId: Principal; + + const controller = Ed25519KeyIdentity.generate(); + + const upgradeCurrent = async () => { + await tick(pic); + + await pic.upgradeCanister({ + canisterId: observatoryId, + wasm: OBSERVATORY_WASM_PATH, + sender: controller.getPrincipal() + }); + }; + + beforeAll(async () => { + pic = await PocketIc.create(inject('PIC_URL')); + + const currentDate = new Date(2021, 6, 10, 0, 0, 0, 0); + await pic.setTime(currentDate.getTime()); + + const destination = await downloadObservatory({ junoVersion: '0.0.66', version: '0.4.0' }); + + const { actor: obsA, canisterId } = await pic.setupCanister({ + idlFactory: idlFactoryObservatory040, + wasm: destination, + sender: controller.getPrincipal(), + targetCanisterId: OBSERVATORY_ID + }); + + actor = obsA; + observatoryId = canisterId; + + actor.setIdentity(controller); + + // Start fetching OpenID Jwts in Observatory + const { start_openid_monitoring } = actor; + await start_openid_monitoring({ GitHub: null }); + + // Just a user for simplicity reason, this way we can use makeMockGitHubOpenIdJwt as it + const user = Ed25519KeyIdentity.generate(); + const { nonce } = await generateNonce({ caller: user }); + + // Load the related certificate + const mockJwt = await makeMockGitHubOpenIdJwt({ + clientId: mockGitHubClientId, + date: currentDate, + nonce + }); + + const { jwks } = mockJwt; + + await assertOpenIdHttpsOutcalls({ pic, jwks, method: 'github' }); + }); + + afterAll(async () => { + await pic?.tearDown(); + }); + + it('should migrate heap OpenId.certificates and OpenId.Schedulers to OpenIdProvider.GitHubAuth', async () => { + await expect(upgradeCurrent()).resolves.not.toThrowError(); + }); + + it('should still return certificate', async () => { + const newActor = pic.createActor(idlFactoryObservatory, observatoryId); + newActor.setIdentity(controller); + + const { get_openid_certificate } = newActor; + + const cert = await get_openid_certificate({ + provider: GITHUB_OPEN_ID_PROVIDER + }); + + expect(fromNullable(cert)).not.toBeUndefined(); + }); +}); diff --git a/src/tests/utils/auth-assertions-tests.utils.ts b/src/tests/utils/auth-assertions-tests.utils.ts index b71b112d67..3a05bd4646 100644 --- a/src/tests/utils/auth-assertions-tests.utils.ts +++ b/src/tests/utils/auth-assertions-tests.utils.ts @@ -1,5 +1,8 @@ import type { ConsoleActor, SatelliteActor, SatelliteDid } from '$declarations'; -import type { OpenIdProvider, OpenIdProviderConfig } from '$declarations/satellite/satellite.did'; +import type { + OpenIdDelegationProvider, + OpenIdProviderConfig +} from '$declarations/satellite/satellite.did'; import type { Actor, PocketIc } from '@dfinity/pic'; import { fromNullable, nonNullish, toNullable } from '@dfinity/utils'; import type { Identity } from '@icp-sdk/core/agent'; @@ -325,7 +328,7 @@ export const testAuthOpenIdConfig = ({ controller: () => Identity; version: bigint; }) => { - const googleConfig: [OpenIdProvider, OpenIdProviderConfig] = [ + const googleConfig: [OpenIdDelegationProvider, OpenIdProviderConfig] = [ { Google: null }, { client_id: mockGoogleClientId, @@ -333,7 +336,7 @@ export const testAuthOpenIdConfig = ({ } ]; - const githubConfig: [OpenIdProvider, OpenIdProviderConfig] = [ + const githubConfig: [OpenIdDelegationProvider, OpenIdProviderConfig] = [ { GitHub: null }, { client_id: mockGitHubClientId, diff --git a/src/tests/utils/auth-tests.utils.ts b/src/tests/utils/auth-tests.utils.ts index 9f4e64b6e0..80e4a19a22 100644 --- a/src/tests/utils/auth-tests.utils.ts +++ b/src/tests/utils/auth-tests.utils.ts @@ -5,7 +5,10 @@ import { type SatelliteActor, type SatelliteDid } from '$declarations'; -import type { OpenIdProvider, OpenIdProviderConfig } from '$declarations/satellite/satellite.did'; +import type { + OpenIdDelegationProvider, + OpenIdProviderConfig +} from '$declarations/satellite/satellite.did'; import type { _SERVICE as TestSatelliteActor } from '$test-declarations/test_satellite/test_satellite.did'; import type { Actor, PocketIc } from '@dfinity/pic'; import { ECDSAKeyIdentity, Ed25519KeyIdentity } from '@icp-sdk/core/identity'; @@ -167,7 +170,7 @@ const setupAuth = async ({ ...(withGitHub ? [ [{ GitHub: null }, { client_id: mockGitHubClientId, delegation: [] }] as [ - OpenIdProvider, + OpenIdDelegationProvider, OpenIdProviderConfig ] ] diff --git a/src/tests/utils/rate.tests.utils.ts b/src/tests/utils/rate.tests.utils.ts index 5ebc25d68e..e00971a8b5 100644 --- a/src/tests/utils/rate.tests.utils.ts +++ b/src/tests/utils/rate.tests.utils.ts @@ -1,6 +1,10 @@ -import type { ObservatoryActor } from '$declarations'; +import type { ObservatoryActor, ObservatoryActor040 } from '$declarations'; -export const updateRateConfigNoLimit = async ({ actor }: { actor: ObservatoryActor }) => { +export const updateRateConfigNoLimit = async ({ + actor +}: { + actor: ObservatoryActor | ObservatoryActor040; +}) => { // Allow lots of requests const { set_rate_config } = actor;