diff --git a/src/civic_sign_frontend_demo/src/declarations/civic_canister_backend/civic_canister_backend.did b/src/civic_sign_frontend_demo/src/declarations/civic_canister_backend/civic_canister_backend.did new file mode 100644 index 0000000..b9b3db6 --- /dev/null +++ b/src/civic_sign_frontend_demo/src/declarations/civic_canister_backend/civic_canister_backend.did @@ -0,0 +1,126 @@ +type u16 = nat16; +type ArgumentValue = variant { Int : int32; String : text }; +type Claim = record { claims : vec record { text; ClaimValue } }; +type ClaimValue = variant { + Date : text; + Text : text; + Boolean : bool; + Number : int64; + Claim : Claim; +}; +type CredentialError = variant { + UnauthorizedSubject : text; + NoCredentialsFound : text; +}; +type CredentialSpec = record { + arguments : opt vec record { text; ArgumentValue }; + credential_type : text; +}; +type DerivationOriginData = record { origin : text }; +type DerivationOriginError = variant { + Internal : text; + UnsupportedOrigin : text; +}; +type DerivationOriginRequest = record { frontend_hostname : text }; +type GetCredentialRequest = record { + signed_id_alias : SignedIdAlias; + prepared_context : opt blob; + credential_spec : CredentialSpec; +}; +type HttpRequest = record { + url : text; + method : text; + body : blob; + headers : vec record { text; text }; + certificate_version : opt nat16; +}; +type HttpResponse = record { + body : blob; + headers : vec record { text; text }; + status_code : nat16; +}; +type Icrc21ConsentInfo = record { consent_message : text; language : text }; +type Icrc21ConsentPreferences = record { language : text }; +type Icrc21Error = variant { + GenericError : record { description : text; error_code : nat }; + UnsupportedCanisterCall : Icrc21ErrorInfo; + ConsentMessageUnavailable : Icrc21ErrorInfo; +}; +type Icrc21ErrorInfo = record { description : text }; +type Icrc21VcConsentMessageRequest = record { + preferences : Icrc21ConsentPreferences; + credential_spec : CredentialSpec; +}; +type IssueCredentialError = variant { + Internal : text; + SignatureNotFound : text; + InvalidIdAlias : text; + UnauthorizedSubject : text; + UnknownSubject : text; + UnsupportedCredentialSpec : text; +}; +type IssuedCredentialData = record { vc_jws : text }; +type IssuerInit = record { + derivation_origin : text; + idp_canister_ids : vec principal; + ic_root_key_der : blob; + frontend_hostname : text; + admin: principal; + authorized_issuers: vec principal; +}; +type PrepareCredentialRequest = record { + signed_id_alias : SignedIdAlias; + credential_spec : CredentialSpec; +}; +type PreparedCredentialData = record { prepared_context : opt blob }; +type Result = variant { Ok : text; Err : CredentialError }; +type Result_1 = variant { + Ok : DerivationOriginData; + Err : DerivationOriginError; +}; +type Result_2 = variant { Ok : vec FullCredential; Err : CredentialError }; +type Result_3 = variant { + Ok : IssuedCredentialData; + Err : IssueCredentialError; +}; +type Result_4 = variant { + Ok : PreparedCredentialData; + Err : IssueCredentialError; +}; +type Result_5 = variant { Ok : Icrc21ConsentInfo; Err : Icrc21Error }; +type SignedIdAlias = record { credential_jws : text }; +type Credential = record { + id : text; + context : vec text; + type_ : vec text; + claim : vec Claim; +}; + +type FullCredential = record { + id : text; + context : vec text; + type_ : vec text; + claim : vec Claim; + issuer : text; +}; +type StoredCredential = record { + id : text; + context_issuer_id : u16; + type_ : vec text; + claim : vec Claim; +}; +service : (opt IssuerInit) -> { + add_credentials : (principal, vec Credential) -> (Result); + remove_credential : (principal, text) -> (Result); + configure : (IssuerInit) -> (); + derivation_origin : (DerivationOriginRequest) -> (Result_1); + get_all_credentials : (principal) -> (Result_2) query; + get_credential : (GetCredentialRequest) -> (Result_3) query; + http_request : (HttpRequest) -> (HttpResponse) query; + prepare_credential : (PrepareCredentialRequest) -> (Result_4); + update_credential : (principal, text, Credential) -> (Result); + vc_consent_message : (Icrc21VcConsentMessageRequest) -> (Result_5); + get_admin : () -> (principal) query; + add_issuer: (principal) -> (); + remove_issuer: (principal) -> (); +} diff --git a/src/civic_sign_frontend_demo/src/declarations/civic_canister_backend/civic_canister_backend.did.d.ts b/src/civic_sign_frontend_demo/src/declarations/civic_canister_backend/civic_canister_backend.did.d.ts new file mode 100644 index 0000000..869219b --- /dev/null +++ b/src/civic_sign_frontend_demo/src/declarations/civic_canister_backend/civic_canister_backend.did.d.ts @@ -0,0 +1,126 @@ +import type { Principal } from '@dfinity/principal'; +import type { ActorMethod } from '@dfinity/agent'; +import type { IDL } from '@dfinity/candid'; + +export type ArgumentValue = { 'Int' : number } | + { 'String' : string }; +export interface Claim { 'claims' : Array<[string, ClaimValue]> } +export type ClaimValue = { 'Date' : string } | + { 'Text' : string } | + { 'Boolean' : boolean } | + { 'Number' : bigint } | + { 'Claim' : Claim }; +export interface Credential { + 'id' : string, + 'context' : Array, + 'type_' : Array, + 'claim' : Array, +} +export type CredentialError = { 'UnauthorizedSubject' : string } | + { 'NoCredentialsFound' : string }; +export interface CredentialSpec { + 'arguments' : [] | [Array<[string, ArgumentValue]>], + 'credential_type' : string, +} +export interface DerivationOriginData { 'origin' : string } +export type DerivationOriginError = { 'Internal' : string } | + { 'UnsupportedOrigin' : string }; +export interface DerivationOriginRequest { 'frontend_hostname' : string } +export interface FullCredential { + 'id' : string, + 'context' : Array, + 'type_' : Array, + 'claim' : Array, + 'issuer' : string, +} +export interface GetCredentialRequest { + 'signed_id_alias' : SignedIdAlias, + 'prepared_context' : [] | [Uint8Array | number[]], + 'credential_spec' : CredentialSpec, +} +export interface HttpRequest { + 'url' : string, + 'method' : string, + 'body' : Uint8Array | number[], + 'headers' : Array<[string, string]>, + 'certificate_version' : [] | [number], +} +export interface HttpResponse { + 'body' : Uint8Array | number[], + 'headers' : Array<[string, string]>, + 'status_code' : number, +} +export interface Icrc21ConsentInfo { + 'consent_message' : string, + 'language' : string, +} +export interface Icrc21ConsentPreferences { 'language' : string } +export type Icrc21Error = { + 'GenericError' : { 'description' : string, 'error_code' : bigint } + } | + { 'UnsupportedCanisterCall' : Icrc21ErrorInfo } | + { 'ConsentMessageUnavailable' : Icrc21ErrorInfo }; +export interface Icrc21ErrorInfo { 'description' : string } +export interface Icrc21VcConsentMessageRequest { + 'preferences' : Icrc21ConsentPreferences, + 'credential_spec' : CredentialSpec, +} +export type IssueCredentialError = { 'Internal' : string } | + { 'SignatureNotFound' : string } | + { 'InvalidIdAlias' : string } | + { 'UnauthorizedSubject' : string } | + { 'UnknownSubject' : string } | + { 'UnsupportedCredentialSpec' : string }; +export interface IssuedCredentialData { 'vc_jws' : string } +export interface IssuerInit { + 'derivation_origin' : string, + 'admin' : Principal, + 'idp_canister_ids' : Array, + 'ic_root_key_der' : Uint8Array | number[], + 'authorized_issuers' : Array, + 'frontend_hostname' : string, +} +export interface PrepareCredentialRequest { + 'signed_id_alias' : SignedIdAlias, + 'credential_spec' : CredentialSpec, +} +export interface PreparedCredentialData { + 'prepared_context' : [] | [Uint8Array | number[]], +} +export type Result = { 'Ok' : string } | + { 'Err' : CredentialError }; +export type Result_1 = { 'Ok' : DerivationOriginData } | + { 'Err' : DerivationOriginError }; +export type Result_2 = { 'Ok' : Array } | + { 'Err' : CredentialError }; +export type Result_3 = { 'Ok' : IssuedCredentialData } | + { 'Err' : IssueCredentialError }; +export type Result_4 = { 'Ok' : PreparedCredentialData } | + { 'Err' : IssueCredentialError }; +export type Result_5 = { 'Ok' : Icrc21ConsentInfo } | + { 'Err' : Icrc21Error }; +export interface SignedIdAlias { 'credential_jws' : string } +export interface StoredCredential { + 'id' : string, + 'type_' : Array, + 'claim' : Array, + 'context_issuer_id' : u16, +} +export type u16 = number; +export interface _SERVICE { + 'add_credentials' : ActorMethod<[Principal, Array], Result>, + 'add_issuer' : ActorMethod<[Principal], undefined>, + 'configure' : ActorMethod<[IssuerInit], undefined>, + 'derivation_origin' : ActorMethod<[DerivationOriginRequest], Result_1>, + 'get_admin' : ActorMethod<[], Principal>, + 'get_all_credentials' : ActorMethod<[Principal], Result_2>, + 'get_credential' : ActorMethod<[GetCredentialRequest], Result_3>, + 'http_request' : ActorMethod<[HttpRequest], HttpResponse>, + 'prepare_credential' : ActorMethod<[PrepareCredentialRequest], Result_4>, + 'remove_credential' : ActorMethod<[Principal, string], Result>, + 'remove_issuer' : ActorMethod<[Principal], undefined>, + 'update_credential' : ActorMethod<[Principal, string, Credential], Result>, + 'vc_consent_message' : ActorMethod<[Icrc21VcConsentMessageRequest], Result_5>, +} +export declare const idlFactory: IDL.InterfaceFactory; +export declare const init: (args: { IDL: typeof IDL }) => IDL.Type[]; diff --git a/src/civic_sign_frontend_demo/src/declarations/civic_canister_backend/civic_canister_backend.did.js b/src/civic_sign_frontend_demo/src/declarations/civic_canister_backend/civic_canister_backend.did.js new file mode 100644 index 0000000..8881185 --- /dev/null +++ b/src/civic_sign_frontend_demo/src/declarations/civic_canister_backend/civic_canister_backend.did.js @@ -0,0 +1,162 @@ +export const idlFactory = ({ IDL }) => { + const Claim = IDL.Rec(); + const IssuerInit = IDL.Record({ + 'derivation_origin' : IDL.Text, + 'admin' : IDL.Principal, + 'idp_canister_ids' : IDL.Vec(IDL.Principal), + 'ic_root_key_der' : IDL.Vec(IDL.Nat8), + 'authorized_issuers' : IDL.Vec(IDL.Principal), + 'frontend_hostname' : IDL.Text, + }); + const ClaimValue = IDL.Variant({ + 'Date' : IDL.Text, + 'Text' : IDL.Text, + 'Boolean' : IDL.Bool, + 'Number' : IDL.Int64, + 'Claim' : Claim, + }); + Claim.fill( + IDL.Record({ 'claims' : IDL.Vec(IDL.Tuple(IDL.Text, ClaimValue)) }) + ); + const Credential = IDL.Record({ + 'id' : IDL.Text, + 'context' : IDL.Vec(IDL.Text), + 'type_' : IDL.Vec(IDL.Text), + 'claim' : IDL.Vec(Claim), + }); + const CredentialError = IDL.Variant({ + 'UnauthorizedSubject' : IDL.Text, + 'NoCredentialsFound' : IDL.Text, + }); + const Result = IDL.Variant({ 'Ok' : IDL.Text, 'Err' : CredentialError }); + const DerivationOriginRequest = IDL.Record({ + 'frontend_hostname' : IDL.Text, + }); + const DerivationOriginData = IDL.Record({ 'origin' : IDL.Text }); + const DerivationOriginError = IDL.Variant({ + 'Internal' : IDL.Text, + 'UnsupportedOrigin' : IDL.Text, + }); + const Result_1 = IDL.Variant({ + 'Ok' : DerivationOriginData, + 'Err' : DerivationOriginError, + }); + const FullCredential = IDL.Record({ + 'id' : IDL.Text, + 'context' : IDL.Vec(IDL.Text), + 'type_' : IDL.Vec(IDL.Text), + 'claim' : IDL.Vec(Claim), + 'issuer' : IDL.Text, + }); + const Result_2 = IDL.Variant({ + 'Ok' : IDL.Vec(FullCredential), + 'Err' : CredentialError, + }); + const SignedIdAlias = IDL.Record({ 'credential_jws' : IDL.Text }); + const ArgumentValue = IDL.Variant({ 'Int' : IDL.Int32, 'String' : IDL.Text }); + const CredentialSpec = IDL.Record({ + 'arguments' : IDL.Opt(IDL.Vec(IDL.Tuple(IDL.Text, ArgumentValue))), + 'credential_type' : IDL.Text, + }); + const GetCredentialRequest = IDL.Record({ + 'signed_id_alias' : SignedIdAlias, + 'prepared_context' : IDL.Opt(IDL.Vec(IDL.Nat8)), + 'credential_spec' : CredentialSpec, + }); + const IssuedCredentialData = IDL.Record({ 'vc_jws' : IDL.Text }); + const IssueCredentialError = IDL.Variant({ + 'Internal' : IDL.Text, + 'SignatureNotFound' : IDL.Text, + 'InvalidIdAlias' : IDL.Text, + 'UnauthorizedSubject' : IDL.Text, + 'UnknownSubject' : IDL.Text, + 'UnsupportedCredentialSpec' : IDL.Text, + }); + const Result_3 = IDL.Variant({ + 'Ok' : IssuedCredentialData, + 'Err' : IssueCredentialError, + }); + 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 HttpResponse = IDL.Record({ + 'body' : IDL.Vec(IDL.Nat8), + 'headers' : IDL.Vec(IDL.Tuple(IDL.Text, IDL.Text)), + 'status_code' : IDL.Nat16, + }); + const PrepareCredentialRequest = IDL.Record({ + 'signed_id_alias' : SignedIdAlias, + 'credential_spec' : CredentialSpec, + }); + const PreparedCredentialData = IDL.Record({ + 'prepared_context' : IDL.Opt(IDL.Vec(IDL.Nat8)), + }); + const Result_4 = IDL.Variant({ + 'Ok' : PreparedCredentialData, + 'Err' : IssueCredentialError, + }); + const Icrc21ConsentPreferences = IDL.Record({ 'language' : IDL.Text }); + const Icrc21VcConsentMessageRequest = IDL.Record({ + 'preferences' : Icrc21ConsentPreferences, + 'credential_spec' : CredentialSpec, + }); + const Icrc21ConsentInfo = IDL.Record({ + 'consent_message' : IDL.Text, + 'language' : IDL.Text, + }); + const Icrc21ErrorInfo = IDL.Record({ 'description' : IDL.Text }); + const Icrc21Error = IDL.Variant({ + 'GenericError' : IDL.Record({ + 'description' : IDL.Text, + 'error_code' : IDL.Nat, + }), + 'UnsupportedCanisterCall' : Icrc21ErrorInfo, + 'ConsentMessageUnavailable' : Icrc21ErrorInfo, + }); + const Result_5 = IDL.Variant({ + 'Ok' : Icrc21ConsentInfo, + 'Err' : Icrc21Error, + }); + return IDL.Service({ + 'add_credentials' : IDL.Func( + [IDL.Principal, IDL.Vec(Credential)], + [Result], + [], + ), + 'add_issuer' : IDL.Func([IDL.Principal], [], []), + 'configure' : IDL.Func([IssuerInit], [], []), + 'derivation_origin' : IDL.Func([DerivationOriginRequest], [Result_1], []), + 'get_admin' : IDL.Func([], [IDL.Principal], ['query']), + 'get_all_credentials' : IDL.Func([IDL.Principal], [Result_2], ['query']), + 'get_credential' : IDL.Func([GetCredentialRequest], [Result_3], ['query']), + 'http_request' : IDL.Func([HttpRequest], [HttpResponse], ['query']), + 'prepare_credential' : IDL.Func([PrepareCredentialRequest], [Result_4], []), + 'remove_credential' : IDL.Func([IDL.Principal, IDL.Text], [Result], []), + 'remove_issuer' : IDL.Func([IDL.Principal], [], []), + 'update_credential' : IDL.Func( + [IDL.Principal, IDL.Text, Credential], + [Result], + [], + ), + 'vc_consent_message' : IDL.Func( + [Icrc21VcConsentMessageRequest], + [Result_5], + [], + ), + }); +}; +export const init = ({ IDL }) => { + const IssuerInit = IDL.Record({ + 'derivation_origin' : IDL.Text, + 'admin' : IDL.Principal, + 'idp_canister_ids' : IDL.Vec(IDL.Principal), + 'ic_root_key_der' : IDL.Vec(IDL.Nat8), + 'authorized_issuers' : IDL.Vec(IDL.Principal), + 'frontend_hostname' : IDL.Text, + }); + return [IDL.Opt(IssuerInit)]; +}; diff --git a/src/civic_sign_frontend_demo/src/declarations/civic_canister_backend/index.d.ts b/src/civic_sign_frontend_demo/src/declarations/civic_canister_backend/index.d.ts new file mode 100644 index 0000000..4f04791 --- /dev/null +++ b/src/civic_sign_frontend_demo/src/declarations/civic_canister_backend/index.d.ts @@ -0,0 +1,50 @@ +import type { + ActorSubclass, + HttpAgentOptions, + ActorConfig, + Agent, +} from "@dfinity/agent"; +import type { Principal } from "@dfinity/principal"; +import type { IDL } from "@dfinity/candid"; + +import { _SERVICE } from './civic_canister_backend.did'; + +export declare const idlFactory: IDL.InterfaceFactory; +export declare const canisterId: string; + +export declare interface CreateActorOptions { + /** + * @see {@link Agent} + */ + agent?: Agent; + /** + * @see {@link HttpAgentOptions} + */ + agentOptions?: HttpAgentOptions; + /** + * @see {@link ActorConfig} + */ + actorOptions?: ActorConfig; +} + +/** + * Intializes an {@link ActorSubclass}, configured with the provided SERVICE interface of a canister. + * @constructs {@link ActorSubClass} + * @param {string | Principal} canisterId - ID of the canister the {@link Actor} will talk to + * @param {CreateActorOptions} options - see {@link CreateActorOptions} + * @param {CreateActorOptions["agent"]} options.agent - a pre-configured agent you'd like to use. Supercedes agentOptions + * @param {CreateActorOptions["agentOptions"]} options.agentOptions - options to set up a new agent + * @see {@link HttpAgentOptions} + * @param {CreateActorOptions["actorOptions"]} options.actorOptions - options for the Actor + * @see {@link ActorConfig} + */ +export declare const createActor: ( + canisterId: string | Principal, + options?: CreateActorOptions +) => ActorSubclass<_SERVICE>; + +/** + * Intialized Actor using default settings, ready to talk to a canister using its candid interface + * @constructs {@link ActorSubClass} + */ +export declare const civic_canister_backend: ActorSubclass<_SERVICE>; diff --git a/src/civic_sign_frontend_demo/src/declarations/civic_canister_backend/index.js b/src/civic_sign_frontend_demo/src/declarations/civic_canister_backend/index.js new file mode 100644 index 0000000..47cbfa6 --- /dev/null +++ b/src/civic_sign_frontend_demo/src/declarations/civic_canister_backend/index.js @@ -0,0 +1,42 @@ +import { Actor, HttpAgent } from "@dfinity/agent"; + +// Imports and re-exports candid interface +import { idlFactory } from "./civic_canister_backend.did.js"; +export { idlFactory } from "./civic_canister_backend.did.js"; + +/* CANISTER_ID is replaced by webpack based on node environment + * Note: canister environment variable will be standardized as + * process.env.CANISTER_ID_ + * beginning in dfx 0.15.0 + */ +export const canisterId = + process.env.CANISTER_ID_CIVIC_CANISTER_BACKEND; + +export const createActor = (canisterId, options = {}) => { + const agent = options.agent || new HttpAgent({ ...options.agentOptions }); + + if (options.agent && options.agentOptions) { + console.warn( + "Detected both agent and agentOptions passed to createActor. Ignoring agentOptions and proceeding with the provided agent." + ); + } + + // Fetch root key for certificate validation during development + if (process.env.DFX_NETWORK !== "ic") { + agent.fetchRootKey().catch((err) => { + console.warn( + "Unable to fetch root key. Check to ensure that your local replica is running" + ); + console.error(err); + }); + } + + // Creates an actor with using the candid interface and the HttpAgent + return Actor.createActor(idlFactory, { + agent, + canisterId, + ...options.actorOptions, + }); +}; + +export const civic_canister_backend = canisterId ? createActor(canisterId) : undefined; diff --git a/src/civic_sign_frontend_demo/src/declarations/civic_canister_frontend/civic_canister_frontend.did b/src/civic_sign_frontend_demo/src/declarations/civic_canister_frontend/civic_canister_frontend.did new file mode 100644 index 0000000..51bb1a2 --- /dev/null +++ b/src/civic_sign_frontend_demo/src/declarations/civic_canister_frontend/civic_canister_frontend.did @@ -0,0 +1,262 @@ +type BatchId = nat; +type ChunkId = nat; +type Key = text; +type Time = int; + +type CreateAssetArguments = record { + key: Key; + content_type: text; + max_age: opt nat64; + headers: opt vec HeaderField; + enable_aliasing: opt bool; + allow_raw_access: opt bool; +}; + +// Add or change content for an asset, by content encoding +type SetAssetContentArguments = record { + key: Key; + content_encoding: text; + chunk_ids: vec ChunkId; + sha256: opt blob; +}; + +// Remove content for an asset, by content encoding +type UnsetAssetContentArguments = record { + key: Key; + content_encoding: text; +}; + +// Delete an asset +type DeleteAssetArguments = record { + key: Key; +}; + +// Reset everything +type ClearArguments = record {}; + +type BatchOperationKind = variant { + CreateAsset: CreateAssetArguments; + SetAssetContent: SetAssetContentArguments; + + SetAssetProperties: SetAssetPropertiesArguments; + + UnsetAssetContent: UnsetAssetContentArguments; + DeleteAsset: DeleteAssetArguments; + + Clear: ClearArguments; +}; + +type CommitBatchArguments = record { + batch_id: BatchId; + operations: vec BatchOperationKind +}; + +type CommitProposedBatchArguments = record { + batch_id: BatchId; + evidence: blob; +}; + +type ComputeEvidenceArguments = record { + batch_id: BatchId; + max_iterations: opt nat16 +}; + +type DeleteBatchArguments = record { + batch_id: BatchId; +}; + +type HeaderField = record { text; text; }; + +type HttpRequest = record { + method: text; + url: text; + headers: vec HeaderField; + body: blob; + certificate_version: opt nat16; +}; + +type HttpResponse = record { + status_code: nat16; + headers: vec HeaderField; + body: blob; + streaming_strategy: opt StreamingStrategy; +}; + +type StreamingCallbackHttpResponse = record { + body: blob; + token: opt StreamingCallbackToken; +}; + +type StreamingCallbackToken = record { + key: Key; + content_encoding: text; + index: nat; + sha256: opt blob; +}; + +type StreamingStrategy = variant { + Callback: record { + callback: func (StreamingCallbackToken) -> (opt StreamingCallbackHttpResponse) query; + token: StreamingCallbackToken; + }; +}; + +type SetAssetPropertiesArguments = record { + key: Key; + max_age: opt opt nat64; + headers: opt opt vec HeaderField; + allow_raw_access: opt opt bool; + is_aliased: opt opt bool; +}; + +type ConfigurationResponse = record { + max_batches: opt nat64; + max_chunks: opt nat64; + max_bytes: opt nat64; +}; + +type ConfigureArguments = record { + max_batches: opt opt nat64; + max_chunks: opt opt nat64; + max_bytes: opt opt nat64; +}; + +type Permission = variant { + Commit; + ManagePermissions; + Prepare; +}; + +type GrantPermission = record { + to_principal: principal; + permission: Permission; +}; +type RevokePermission = record { + of_principal: principal; + permission: Permission; +}; +type ListPermitted = record { permission: Permission }; + +type ValidationResult = variant { Ok : text; Err : text }; + +type AssetCanisterArgs = variant { + Init: InitArgs; + Upgrade: UpgradeArgs; +}; + +type InitArgs = record {}; + +type UpgradeArgs = record { + set_permissions: opt SetPermissions; +}; + +/// Sets the list of principals granted each permission. +type SetPermissions = record { + prepare: vec principal; + commit: vec principal; + manage_permissions: vec principal; +}; + +service: (asset_canister_args: opt AssetCanisterArgs) -> { + api_version: () -> (nat16) query; + + get: (record { + key: Key; + accept_encodings: vec text; + }) -> (record { + content: blob; // may be the entirety of the content, or just chunk index 0 + content_type: text; + content_encoding: text; + sha256: opt blob; // sha256 of entire asset encoding, calculated by dfx and passed in SetAssetContentArguments + total_length: nat; // all chunks except last have size == content.size() + }) query; + + // if get() returned chunks > 1, call this to retrieve them. + // chunks may or may not be split up at the same boundaries as presented to create_chunk(). + get_chunk: (record { + key: Key; + content_encoding: text; + index: nat; + sha256: opt blob; // sha256 of entire asset encoding, calculated by dfx and passed in SetAssetContentArguments + }) -> (record { content: blob }) query; + + list : (record {}) -> (vec record { + key: Key; + content_type: text; + encodings: vec record { + content_encoding: text; + sha256: opt blob; // sha256 of entire asset encoding, calculated by dfx and passed in SetAssetContentArguments + length: nat; // Size of this encoding's blob. Calculated when uploading assets. + modified: Time; + }; + }) query; + + certified_tree : (record {}) -> (record { + certificate: blob; + tree: blob; + }) query; + + create_batch : (record {}) -> (record { batch_id: BatchId }); + + create_chunk: (record { batch_id: BatchId; content: blob }) -> (record { chunk_id: ChunkId }); + + // Perform all operations successfully, or reject + commit_batch: (CommitBatchArguments) -> (); + + // Save the batch operations for later commit + propose_commit_batch: (CommitBatchArguments) -> (); + + // Given a batch already proposed, perform all operations successfully, or reject + commit_proposed_batch: (CommitProposedBatchArguments) -> (); + + // Compute a hash over the CommitBatchArguments. Call until it returns Some(evidence). + compute_evidence: (ComputeEvidenceArguments) -> (opt blob); + + // Delete a batch that has been created, or proposed for commit, but not yet committed + delete_batch: (DeleteBatchArguments) -> (); + + create_asset: (CreateAssetArguments) -> (); + set_asset_content: (SetAssetContentArguments) -> (); + unset_asset_content: (UnsetAssetContentArguments) -> (); + + delete_asset: (DeleteAssetArguments) -> (); + + clear: (ClearArguments) -> (); + + // Single call to create an asset with content for a single content encoding that + // fits within the message ingress limit. + store: (record { + key: Key; + content_type: text; + content_encoding: text; + content: blob; + sha256: opt blob + }) -> (); + + http_request: (request: HttpRequest) -> (HttpResponse) query; + http_request_streaming_callback: (token: StreamingCallbackToken) -> (opt StreamingCallbackHttpResponse) query; + + authorize: (principal) -> (); + deauthorize: (principal) -> (); + list_authorized: () -> (vec principal); + grant_permission: (GrantPermission) -> (); + revoke_permission: (RevokePermission) -> (); + list_permitted: (ListPermitted) -> (vec principal); + take_ownership: () -> (); + + get_asset_properties : (key: Key) -> (record { + max_age: opt nat64; + headers: opt vec HeaderField; + allow_raw_access: opt bool; + is_aliased: opt bool; } ) query; + set_asset_properties: (SetAssetPropertiesArguments) -> (); + + get_configuration: () -> (ConfigurationResponse); + configure: (ConfigureArguments) -> (); + + validate_grant_permission: (GrantPermission) -> (ValidationResult); + validate_revoke_permission: (RevokePermission) -> (ValidationResult); + validate_take_ownership: () -> (ValidationResult); + validate_commit_proposed_batch: (CommitProposedBatchArguments) -> (ValidationResult); + validate_configure: (ConfigureArguments) -> (ValidationResult); +} diff --git a/src/civic_sign_frontend_demo/src/declarations/civic_canister_frontend/civic_canister_frontend.did.d.ts b/src/civic_sign_frontend_demo/src/declarations/civic_canister_frontend/civic_canister_frontend.did.d.ts new file mode 100644 index 0000000..ce96468 --- /dev/null +++ b/src/civic_sign_frontend_demo/src/declarations/civic_canister_frontend/civic_canister_frontend.did.d.ts @@ -0,0 +1,240 @@ +import type { Principal } from '@dfinity/principal'; +import type { ActorMethod } from '@dfinity/agent'; +import type { IDL } from '@dfinity/candid'; + +export type AssetCanisterArgs = { 'Upgrade' : UpgradeArgs } | + { 'Init' : InitArgs }; +export type BatchId = bigint; +export type BatchOperationKind = { + 'SetAssetProperties' : SetAssetPropertiesArguments + } | + { 'CreateAsset' : CreateAssetArguments } | + { 'UnsetAssetContent' : UnsetAssetContentArguments } | + { 'DeleteAsset' : DeleteAssetArguments } | + { 'SetAssetContent' : SetAssetContentArguments } | + { 'Clear' : ClearArguments }; +export type ChunkId = bigint; +export type ClearArguments = {}; +export interface CommitBatchArguments { + 'batch_id' : BatchId, + 'operations' : Array, +} +export interface CommitProposedBatchArguments { + 'batch_id' : BatchId, + 'evidence' : Uint8Array | number[], +} +export interface ComputeEvidenceArguments { + 'batch_id' : BatchId, + 'max_iterations' : [] | [number], +} +export interface ConfigurationResponse { + 'max_batches' : [] | [bigint], + 'max_bytes' : [] | [bigint], + 'max_chunks' : [] | [bigint], +} +export interface ConfigureArguments { + 'max_batches' : [] | [[] | [bigint]], + 'max_bytes' : [] | [[] | [bigint]], + 'max_chunks' : [] | [[] | [bigint]], +} +export interface CreateAssetArguments { + 'key' : Key, + 'content_type' : string, + 'headers' : [] | [Array], + 'allow_raw_access' : [] | [boolean], + 'max_age' : [] | [bigint], + 'enable_aliasing' : [] | [boolean], +} +export interface DeleteAssetArguments { 'key' : Key } +export interface DeleteBatchArguments { 'batch_id' : BatchId } +export interface GrantPermission { + 'permission' : Permission, + 'to_principal' : Principal, +} +export type HeaderField = [string, string]; +export interface HttpRequest { + 'url' : string, + 'method' : string, + 'body' : Uint8Array | number[], + 'headers' : Array, + 'certificate_version' : [] | [number], +} +export interface HttpResponse { + 'body' : Uint8Array | number[], + 'headers' : Array, + 'streaming_strategy' : [] | [StreamingStrategy], + 'status_code' : number, +} +export type InitArgs = {}; +export type Key = string; +export interface ListPermitted { 'permission' : Permission } +export type Permission = { 'Prepare' : null } | + { 'ManagePermissions' : null } | + { 'Commit' : null }; +export interface RevokePermission { + 'permission' : Permission, + 'of_principal' : Principal, +} +export interface SetAssetContentArguments { + 'key' : Key, + 'sha256' : [] | [Uint8Array | number[]], + 'chunk_ids' : Array, + 'content_encoding' : string, +} +export interface SetAssetPropertiesArguments { + 'key' : Key, + 'headers' : [] | [[] | [Array]], + 'is_aliased' : [] | [[] | [boolean]], + 'allow_raw_access' : [] | [[] | [boolean]], + 'max_age' : [] | [[] | [bigint]], +} +export interface SetPermissions { + 'prepare' : Array, + 'commit' : Array, + 'manage_permissions' : Array, +} +export interface StreamingCallbackHttpResponse { + 'token' : [] | [StreamingCallbackToken], + 'body' : Uint8Array | number[], +} +export interface StreamingCallbackToken { + 'key' : Key, + 'sha256' : [] | [Uint8Array | number[]], + 'index' : bigint, + 'content_encoding' : string, +} +export type StreamingStrategy = { + 'Callback' : { + 'token' : StreamingCallbackToken, + 'callback' : [Principal, string], + } + }; +export type Time = bigint; +export interface UnsetAssetContentArguments { + 'key' : Key, + 'content_encoding' : string, +} +export interface UpgradeArgs { 'set_permissions' : [] | [SetPermissions] } +export type ValidationResult = { 'Ok' : string } | + { 'Err' : string }; +export interface _SERVICE { + 'api_version' : ActorMethod<[], number>, + 'authorize' : ActorMethod<[Principal], undefined>, + 'certified_tree' : ActorMethod< + [{}], + { 'certificate' : Uint8Array | number[], 'tree' : Uint8Array | number[] } + >, + 'clear' : ActorMethod<[ClearArguments], undefined>, + 'commit_batch' : ActorMethod<[CommitBatchArguments], undefined>, + 'commit_proposed_batch' : ActorMethod< + [CommitProposedBatchArguments], + undefined + >, + 'compute_evidence' : ActorMethod< + [ComputeEvidenceArguments], + [] | [Uint8Array | number[]] + >, + 'configure' : ActorMethod<[ConfigureArguments], undefined>, + 'create_asset' : ActorMethod<[CreateAssetArguments], undefined>, + 'create_batch' : ActorMethod<[{}], { 'batch_id' : BatchId }>, + 'create_chunk' : ActorMethod< + [{ 'content' : Uint8Array | number[], 'batch_id' : BatchId }], + { 'chunk_id' : ChunkId } + >, + 'deauthorize' : ActorMethod<[Principal], undefined>, + 'delete_asset' : ActorMethod<[DeleteAssetArguments], undefined>, + 'delete_batch' : ActorMethod<[DeleteBatchArguments], undefined>, + 'get' : ActorMethod< + [{ 'key' : Key, 'accept_encodings' : Array }], + { + 'content' : Uint8Array | number[], + 'sha256' : [] | [Uint8Array | number[]], + 'content_type' : string, + 'content_encoding' : string, + 'total_length' : bigint, + } + >, + 'get_asset_properties' : ActorMethod< + [Key], + { + 'headers' : [] | [Array], + 'is_aliased' : [] | [boolean], + 'allow_raw_access' : [] | [boolean], + 'max_age' : [] | [bigint], + } + >, + 'get_chunk' : ActorMethod< + [ + { + 'key' : Key, + 'sha256' : [] | [Uint8Array | number[]], + 'index' : bigint, + 'content_encoding' : string, + }, + ], + { 'content' : Uint8Array | number[] } + >, + 'get_configuration' : ActorMethod<[], ConfigurationResponse>, + 'grant_permission' : ActorMethod<[GrantPermission], undefined>, + 'http_request' : ActorMethod<[HttpRequest], HttpResponse>, + 'http_request_streaming_callback' : ActorMethod< + [StreamingCallbackToken], + [] | [StreamingCallbackHttpResponse] + >, + 'list' : ActorMethod< + [{}], + Array< + { + 'key' : Key, + 'encodings' : Array< + { + 'modified' : Time, + 'sha256' : [] | [Uint8Array | number[]], + 'length' : bigint, + 'content_encoding' : string, + } + >, + 'content_type' : string, + } + > + >, + 'list_authorized' : ActorMethod<[], Array>, + 'list_permitted' : ActorMethod<[ListPermitted], Array>, + 'propose_commit_batch' : ActorMethod<[CommitBatchArguments], undefined>, + 'revoke_permission' : ActorMethod<[RevokePermission], undefined>, + 'set_asset_content' : ActorMethod<[SetAssetContentArguments], undefined>, + 'set_asset_properties' : ActorMethod< + [SetAssetPropertiesArguments], + undefined + >, + 'store' : ActorMethod< + [ + { + 'key' : Key, + 'content' : Uint8Array | number[], + 'sha256' : [] | [Uint8Array | number[]], + 'content_type' : string, + 'content_encoding' : string, + }, + ], + undefined + >, + 'take_ownership' : ActorMethod<[], undefined>, + 'unset_asset_content' : ActorMethod<[UnsetAssetContentArguments], undefined>, + 'validate_commit_proposed_batch' : ActorMethod< + [CommitProposedBatchArguments], + ValidationResult + >, + 'validate_configure' : ActorMethod<[ConfigureArguments], ValidationResult>, + 'validate_grant_permission' : ActorMethod< + [GrantPermission], + ValidationResult + >, + 'validate_revoke_permission' : ActorMethod< + [RevokePermission], + ValidationResult + >, + 'validate_take_ownership' : ActorMethod<[], ValidationResult>, +} +export declare const idlFactory: IDL.InterfaceFactory; +export declare const init: (args: { IDL: typeof IDL }) => IDL.Type[]; diff --git a/src/civic_sign_frontend_demo/src/declarations/civic_canister_frontend/civic_canister_frontend.did.js b/src/civic_sign_frontend_demo/src/declarations/civic_canister_frontend/civic_canister_frontend.did.js new file mode 100644 index 0000000..b68ea4a --- /dev/null +++ b/src/civic_sign_frontend_demo/src/declarations/civic_canister_frontend/civic_canister_frontend.did.js @@ -0,0 +1,286 @@ +export const idlFactory = ({ IDL }) => { + const SetPermissions = IDL.Record({ + 'prepare' : IDL.Vec(IDL.Principal), + 'commit' : IDL.Vec(IDL.Principal), + 'manage_permissions' : IDL.Vec(IDL.Principal), + }); + const UpgradeArgs = IDL.Record({ + 'set_permissions' : IDL.Opt(SetPermissions), + }); + const InitArgs = IDL.Record({}); + const AssetCanisterArgs = IDL.Variant({ + 'Upgrade' : UpgradeArgs, + 'Init' : InitArgs, + }); + const ClearArguments = IDL.Record({}); + const BatchId = IDL.Nat; + const Key = IDL.Text; + const HeaderField = IDL.Tuple(IDL.Text, IDL.Text); + const SetAssetPropertiesArguments = IDL.Record({ + 'key' : Key, + 'headers' : IDL.Opt(IDL.Opt(IDL.Vec(HeaderField))), + 'is_aliased' : IDL.Opt(IDL.Opt(IDL.Bool)), + 'allow_raw_access' : IDL.Opt(IDL.Opt(IDL.Bool)), + 'max_age' : IDL.Opt(IDL.Opt(IDL.Nat64)), + }); + const CreateAssetArguments = IDL.Record({ + 'key' : Key, + 'content_type' : IDL.Text, + 'headers' : IDL.Opt(IDL.Vec(HeaderField)), + 'allow_raw_access' : IDL.Opt(IDL.Bool), + 'max_age' : IDL.Opt(IDL.Nat64), + 'enable_aliasing' : IDL.Opt(IDL.Bool), + }); + const UnsetAssetContentArguments = IDL.Record({ + 'key' : Key, + 'content_encoding' : IDL.Text, + }); + const DeleteAssetArguments = IDL.Record({ 'key' : Key }); + const ChunkId = IDL.Nat; + const SetAssetContentArguments = IDL.Record({ + 'key' : Key, + 'sha256' : IDL.Opt(IDL.Vec(IDL.Nat8)), + 'chunk_ids' : IDL.Vec(ChunkId), + 'content_encoding' : IDL.Text, + }); + const BatchOperationKind = IDL.Variant({ + 'SetAssetProperties' : SetAssetPropertiesArguments, + 'CreateAsset' : CreateAssetArguments, + 'UnsetAssetContent' : UnsetAssetContentArguments, + 'DeleteAsset' : DeleteAssetArguments, + 'SetAssetContent' : SetAssetContentArguments, + 'Clear' : ClearArguments, + }); + const CommitBatchArguments = IDL.Record({ + 'batch_id' : BatchId, + 'operations' : IDL.Vec(BatchOperationKind), + }); + const CommitProposedBatchArguments = IDL.Record({ + 'batch_id' : BatchId, + 'evidence' : IDL.Vec(IDL.Nat8), + }); + const ComputeEvidenceArguments = IDL.Record({ + 'batch_id' : BatchId, + 'max_iterations' : IDL.Opt(IDL.Nat16), + }); + const ConfigureArguments = IDL.Record({ + 'max_batches' : IDL.Opt(IDL.Opt(IDL.Nat64)), + 'max_bytes' : IDL.Opt(IDL.Opt(IDL.Nat64)), + 'max_chunks' : IDL.Opt(IDL.Opt(IDL.Nat64)), + }); + const DeleteBatchArguments = IDL.Record({ 'batch_id' : BatchId }); + const ConfigurationResponse = IDL.Record({ + 'max_batches' : IDL.Opt(IDL.Nat64), + 'max_bytes' : IDL.Opt(IDL.Nat64), + 'max_chunks' : IDL.Opt(IDL.Nat64), + }); + const Permission = IDL.Variant({ + 'Prepare' : IDL.Null, + 'ManagePermissions' : IDL.Null, + 'Commit' : IDL.Null, + }); + const GrantPermission = IDL.Record({ + 'permission' : Permission, + 'to_principal' : IDL.Principal, + }); + const HttpRequest = IDL.Record({ + 'url' : IDL.Text, + 'method' : IDL.Text, + 'body' : IDL.Vec(IDL.Nat8), + 'headers' : IDL.Vec(HeaderField), + 'certificate_version' : IDL.Opt(IDL.Nat16), + }); + const StreamingCallbackToken = IDL.Record({ + 'key' : Key, + 'sha256' : IDL.Opt(IDL.Vec(IDL.Nat8)), + 'index' : IDL.Nat, + 'content_encoding' : IDL.Text, + }); + const StreamingCallbackHttpResponse = IDL.Record({ + 'token' : IDL.Opt(StreamingCallbackToken), + 'body' : IDL.Vec(IDL.Nat8), + }); + const StreamingStrategy = IDL.Variant({ + 'Callback' : IDL.Record({ + 'token' : StreamingCallbackToken, + 'callback' : IDL.Func( + [StreamingCallbackToken], + [IDL.Opt(StreamingCallbackHttpResponse)], + ['query'], + ), + }), + }); + const HttpResponse = IDL.Record({ + 'body' : IDL.Vec(IDL.Nat8), + 'headers' : IDL.Vec(HeaderField), + 'streaming_strategy' : IDL.Opt(StreamingStrategy), + 'status_code' : IDL.Nat16, + }); + const Time = IDL.Int; + const ListPermitted = IDL.Record({ 'permission' : Permission }); + const RevokePermission = IDL.Record({ + 'permission' : Permission, + 'of_principal' : IDL.Principal, + }); + const ValidationResult = IDL.Variant({ 'Ok' : IDL.Text, 'Err' : IDL.Text }); + return IDL.Service({ + 'api_version' : IDL.Func([], [IDL.Nat16], ['query']), + 'authorize' : IDL.Func([IDL.Principal], [], []), + 'certified_tree' : IDL.Func( + [IDL.Record({})], + [ + IDL.Record({ + 'certificate' : IDL.Vec(IDL.Nat8), + 'tree' : IDL.Vec(IDL.Nat8), + }), + ], + ['query'], + ), + 'clear' : IDL.Func([ClearArguments], [], []), + 'commit_batch' : IDL.Func([CommitBatchArguments], [], []), + 'commit_proposed_batch' : IDL.Func([CommitProposedBatchArguments], [], []), + 'compute_evidence' : IDL.Func( + [ComputeEvidenceArguments], + [IDL.Opt(IDL.Vec(IDL.Nat8))], + [], + ), + 'configure' : IDL.Func([ConfigureArguments], [], []), + 'create_asset' : IDL.Func([CreateAssetArguments], [], []), + 'create_batch' : IDL.Func( + [IDL.Record({})], + [IDL.Record({ 'batch_id' : BatchId })], + [], + ), + 'create_chunk' : IDL.Func( + [IDL.Record({ 'content' : IDL.Vec(IDL.Nat8), 'batch_id' : BatchId })], + [IDL.Record({ 'chunk_id' : ChunkId })], + [], + ), + 'deauthorize' : IDL.Func([IDL.Principal], [], []), + 'delete_asset' : IDL.Func([DeleteAssetArguments], [], []), + 'delete_batch' : IDL.Func([DeleteBatchArguments], [], []), + 'get' : IDL.Func( + [IDL.Record({ 'key' : Key, 'accept_encodings' : IDL.Vec(IDL.Text) })], + [ + IDL.Record({ + 'content' : IDL.Vec(IDL.Nat8), + 'sha256' : IDL.Opt(IDL.Vec(IDL.Nat8)), + 'content_type' : IDL.Text, + 'content_encoding' : IDL.Text, + 'total_length' : IDL.Nat, + }), + ], + ['query'], + ), + 'get_asset_properties' : IDL.Func( + [Key], + [ + IDL.Record({ + 'headers' : IDL.Opt(IDL.Vec(HeaderField)), + 'is_aliased' : IDL.Opt(IDL.Bool), + 'allow_raw_access' : IDL.Opt(IDL.Bool), + 'max_age' : IDL.Opt(IDL.Nat64), + }), + ], + ['query'], + ), + 'get_chunk' : IDL.Func( + [ + IDL.Record({ + 'key' : Key, + 'sha256' : IDL.Opt(IDL.Vec(IDL.Nat8)), + 'index' : IDL.Nat, + 'content_encoding' : IDL.Text, + }), + ], + [IDL.Record({ 'content' : IDL.Vec(IDL.Nat8) })], + ['query'], + ), + 'get_configuration' : IDL.Func([], [ConfigurationResponse], []), + 'grant_permission' : IDL.Func([GrantPermission], [], []), + 'http_request' : IDL.Func([HttpRequest], [HttpResponse], ['query']), + 'http_request_streaming_callback' : IDL.Func( + [StreamingCallbackToken], + [IDL.Opt(StreamingCallbackHttpResponse)], + ['query'], + ), + 'list' : IDL.Func( + [IDL.Record({})], + [ + IDL.Vec( + IDL.Record({ + 'key' : Key, + 'encodings' : IDL.Vec( + IDL.Record({ + 'modified' : Time, + 'sha256' : IDL.Opt(IDL.Vec(IDL.Nat8)), + 'length' : IDL.Nat, + 'content_encoding' : IDL.Text, + }) + ), + 'content_type' : IDL.Text, + }) + ), + ], + ['query'], + ), + 'list_authorized' : IDL.Func([], [IDL.Vec(IDL.Principal)], []), + 'list_permitted' : IDL.Func([ListPermitted], [IDL.Vec(IDL.Principal)], []), + 'propose_commit_batch' : IDL.Func([CommitBatchArguments], [], []), + 'revoke_permission' : IDL.Func([RevokePermission], [], []), + 'set_asset_content' : IDL.Func([SetAssetContentArguments], [], []), + 'set_asset_properties' : IDL.Func([SetAssetPropertiesArguments], [], []), + 'store' : IDL.Func( + [ + IDL.Record({ + 'key' : Key, + 'content' : IDL.Vec(IDL.Nat8), + 'sha256' : IDL.Opt(IDL.Vec(IDL.Nat8)), + 'content_type' : IDL.Text, + 'content_encoding' : IDL.Text, + }), + ], + [], + [], + ), + 'take_ownership' : IDL.Func([], [], []), + 'unset_asset_content' : IDL.Func([UnsetAssetContentArguments], [], []), + 'validate_commit_proposed_batch' : IDL.Func( + [CommitProposedBatchArguments], + [ValidationResult], + [], + ), + 'validate_configure' : IDL.Func( + [ConfigureArguments], + [ValidationResult], + [], + ), + 'validate_grant_permission' : IDL.Func( + [GrantPermission], + [ValidationResult], + [], + ), + 'validate_revoke_permission' : IDL.Func( + [RevokePermission], + [ValidationResult], + [], + ), + 'validate_take_ownership' : IDL.Func([], [ValidationResult], []), + }); +}; +export const init = ({ IDL }) => { + const SetPermissions = IDL.Record({ + 'prepare' : IDL.Vec(IDL.Principal), + 'commit' : IDL.Vec(IDL.Principal), + 'manage_permissions' : IDL.Vec(IDL.Principal), + }); + const UpgradeArgs = IDL.Record({ + 'set_permissions' : IDL.Opt(SetPermissions), + }); + const InitArgs = IDL.Record({}); + const AssetCanisterArgs = IDL.Variant({ + 'Upgrade' : UpgradeArgs, + 'Init' : InitArgs, + }); + return [IDL.Opt(AssetCanisterArgs)]; +}; diff --git a/src/civic_sign_frontend_demo/src/declarations/civic_canister_frontend/index.d.ts b/src/civic_sign_frontend_demo/src/declarations/civic_canister_frontend/index.d.ts new file mode 100644 index 0000000..98f6dd0 --- /dev/null +++ b/src/civic_sign_frontend_demo/src/declarations/civic_canister_frontend/index.d.ts @@ -0,0 +1,50 @@ +import type { + ActorSubclass, + HttpAgentOptions, + ActorConfig, + Agent, +} from "@dfinity/agent"; +import type { Principal } from "@dfinity/principal"; +import type { IDL } from "@dfinity/candid"; + +import { _SERVICE } from './civic_canister_frontend.did'; + +export declare const idlFactory: IDL.InterfaceFactory; +export declare const canisterId: string; + +export declare interface CreateActorOptions { + /** + * @see {@link Agent} + */ + agent?: Agent; + /** + * @see {@link HttpAgentOptions} + */ + agentOptions?: HttpAgentOptions; + /** + * @see {@link ActorConfig} + */ + actorOptions?: ActorConfig; +} + +/** + * Intializes an {@link ActorSubclass}, configured with the provided SERVICE interface of a canister. + * @constructs {@link ActorSubClass} + * @param {string | Principal} canisterId - ID of the canister the {@link Actor} will talk to + * @param {CreateActorOptions} options - see {@link CreateActorOptions} + * @param {CreateActorOptions["agent"]} options.agent - a pre-configured agent you'd like to use. Supercedes agentOptions + * @param {CreateActorOptions["agentOptions"]} options.agentOptions - options to set up a new agent + * @see {@link HttpAgentOptions} + * @param {CreateActorOptions["actorOptions"]} options.actorOptions - options for the Actor + * @see {@link ActorConfig} + */ +export declare const createActor: ( + canisterId: string | Principal, + options?: CreateActorOptions +) => ActorSubclass<_SERVICE>; + +/** + * Intialized Actor using default settings, ready to talk to a canister using its candid interface + * @constructs {@link ActorSubClass} + */ +export declare const civic_canister_frontend: ActorSubclass<_SERVICE>; diff --git a/src/civic_sign_frontend_demo/src/declarations/civic_canister_frontend/index.js b/src/civic_sign_frontend_demo/src/declarations/civic_canister_frontend/index.js new file mode 100644 index 0000000..39d3f0a --- /dev/null +++ b/src/civic_sign_frontend_demo/src/declarations/civic_canister_frontend/index.js @@ -0,0 +1,42 @@ +import { Actor, HttpAgent } from "@dfinity/agent"; + +// Imports and re-exports candid interface +import { idlFactory } from "./civic_canister_frontend.did.js"; +export { idlFactory } from "./civic_canister_frontend.did.js"; + +/* CANISTER_ID is replaced by webpack based on node environment + * Note: canister environment variable will be standardized as + * process.env.CANISTER_ID_ + * beginning in dfx 0.15.0 + */ +export const canisterId = + process.env.CANISTER_ID_CIVIC_CANISTER_FRONTEND; + +export const createActor = (canisterId, options = {}) => { + const agent = options.agent || new HttpAgent({ ...options.agentOptions }); + + if (options.agent && options.agentOptions) { + console.warn( + "Detected both agent and agentOptions passed to createActor. Ignoring agentOptions and proceeding with the provided agent." + ); + } + + // Fetch root key for certificate validation during development + if (process.env.DFX_NETWORK !== "ic") { + agent.fetchRootKey().catch((err) => { + console.warn( + "Unable to fetch root key. Check to ensure that your local replica is running" + ); + console.error(err); + }); + } + + // Creates an actor with using the candid interface and the HttpAgent + return Actor.createActor(idlFactory, { + agent, + canisterId, + ...options.actorOptions, + }); +}; + +export const civic_canister_frontend = canisterId ? createActor(canisterId) : undefined; diff --git a/src/civic_sign_frontend_demo/src/declarations/internet_identity/index.d.ts b/src/civic_sign_frontend_demo/src/declarations/internet_identity/index.d.ts new file mode 100644 index 0000000..da7d676 --- /dev/null +++ b/src/civic_sign_frontend_demo/src/declarations/internet_identity/index.d.ts @@ -0,0 +1,50 @@ +import type { + ActorSubclass, + HttpAgentOptions, + ActorConfig, + Agent, +} from "@dfinity/agent"; +import type { Principal } from "@dfinity/principal"; +import type { IDL } from "@dfinity/candid"; + +import { _SERVICE } from './internet_identity.did'; + +export declare const idlFactory: IDL.InterfaceFactory; +export declare const canisterId: string; + +export declare interface CreateActorOptions { + /** + * @see {@link Agent} + */ + agent?: Agent; + /** + * @see {@link HttpAgentOptions} + */ + agentOptions?: HttpAgentOptions; + /** + * @see {@link ActorConfig} + */ + actorOptions?: ActorConfig; +} + +/** + * Intializes an {@link ActorSubclass}, configured with the provided SERVICE interface of a canister. + * @constructs {@link ActorSubClass} + * @param {string | Principal} canisterId - ID of the canister the {@link Actor} will talk to + * @param {CreateActorOptions} options - see {@link CreateActorOptions} + * @param {CreateActorOptions["agent"]} options.agent - a pre-configured agent you'd like to use. Supercedes agentOptions + * @param {CreateActorOptions["agentOptions"]} options.agentOptions - options to set up a new agent + * @see {@link HttpAgentOptions} + * @param {CreateActorOptions["actorOptions"]} options.actorOptions - options for the Actor + * @see {@link ActorConfig} + */ +export declare const createActor: ( + canisterId: string | Principal, + options?: CreateActorOptions +) => ActorSubclass<_SERVICE>; + +/** + * Intialized Actor using default settings, ready to talk to a canister using its candid interface + * @constructs {@link ActorSubClass} + */ +export declare const internet_identity: ActorSubclass<_SERVICE>; diff --git a/src/civic_sign_frontend_demo/src/declarations/internet_identity/index.js b/src/civic_sign_frontend_demo/src/declarations/internet_identity/index.js new file mode 100644 index 0000000..98fbcdd --- /dev/null +++ b/src/civic_sign_frontend_demo/src/declarations/internet_identity/index.js @@ -0,0 +1,42 @@ +import { Actor, HttpAgent } from "@dfinity/agent"; + +// Imports and re-exports candid interface +import { idlFactory } from "./internet_identity.did.js"; +export { idlFactory } from "./internet_identity.did.js"; + +/* CANISTER_ID is replaced by webpack based on node environment + * Note: canister environment variable will be standardized as + * process.env.CANISTER_ID_ + * beginning in dfx 0.15.0 + */ +export const canisterId = + process.env.CANISTER_ID_INTERNET_IDENTITY; + +export const createActor = (canisterId, options = {}) => { + const agent = options.agent || new HttpAgent({ ...options.agentOptions }); + + if (options.agent && options.agentOptions) { + console.warn( + "Detected both agent and agentOptions passed to createActor. Ignoring agentOptions and proceeding with the provided agent." + ); + } + + // Fetch root key for certificate validation during development + if (process.env.DFX_NETWORK !== "ic") { + agent.fetchRootKey().catch((err) => { + console.warn( + "Unable to fetch root key. Check to ensure that your local replica is running" + ); + console.error(err); + }); + } + + // Creates an actor with using the candid interface and the HttpAgent + return Actor.createActor(idlFactory, { + agent, + canisterId, + ...options.actorOptions, + }); +}; + +export const internet_identity = canisterId ? createActor(canisterId) : undefined; diff --git a/src/civic_sign_frontend_demo/src/declarations/internet_identity/internet_identity.did b/src/civic_sign_frontend_demo/src/declarations/internet_identity/internet_identity.did new file mode 100644 index 0000000..0164427 --- /dev/null +++ b/src/civic_sign_frontend_demo/src/declarations/internet_identity/internet_identity.did @@ -0,0 +1,618 @@ +type UserNumber = nat64; +type PublicKey = blob; +type CredentialId = blob; +type DeviceKey = PublicKey; +type UserKey = PublicKey; +type SessionKey = PublicKey; +type FrontendHostname = text; +type Timestamp = nat64; + +type HeaderField = record { + text; + text; +}; + +type HttpRequest = record { + method: text; + url: text; + headers: vec HeaderField; + body: blob; + certificate_version: opt nat16; +}; + +type HttpResponse = record { + status_code: nat16; + headers: vec HeaderField; + body: blob; + upgrade : opt bool; + streaming_strategy: opt StreamingStrategy; +}; + +type StreamingCallbackHttpResponse = record { + body: blob; + token: opt Token; +}; + +type Token = record {}; + +type StreamingStrategy = variant { + Callback: record { + callback: func (Token) -> (StreamingCallbackHttpResponse) query; + token: Token; + }; +}; + +type Purpose = variant { + recovery; + authentication; +}; + +type KeyType = variant { + unknown; + platform; + cross_platform; + seed_phrase; + browser_storage_key; +}; + +// This describes whether a device is "protected" or not. +// When protected, a device can only be updated or removed if the +// user is authenticated with that very device. +type DeviceProtection = variant { + protected; + unprotected; +}; + +type Challenge = record { + png_base64: text; + challenge_key: ChallengeKey; +}; + +type DeviceData = record { + pubkey : DeviceKey; + alias : text; + credential_id : opt CredentialId; + purpose: Purpose; + key_type: KeyType; + protection: DeviceProtection; + origin: opt text; + // Metadata map for additional device information. + // + // Note: some fields above will be moved to the metadata map in the future. + // All field names of `DeviceData` (such as 'alias', 'origin, etc.) are + // reserved and cannot be written. + // In addition, the keys "usage" and "authenticator_attachment" are reserved as well. + metadata: opt MetadataMap; +}; + +// The same as `DeviceData` but with the `last_usage` field. +// This field cannot be written, hence the separate type. +type DeviceWithUsage = record { + pubkey : DeviceKey; + alias : text; + credential_id : opt CredentialId; + purpose: Purpose; + key_type: KeyType; + protection: DeviceProtection; + origin: opt text; + last_usage: opt Timestamp; + metadata: opt MetadataMap; +}; + +// Map with some variants for the value type. +// Note, due to the Candid mapping this must be a tuple type thus we cannot name the fields `key` and `value`. +type MetadataMap = vec record { + text; + variant { map : MetadataMap; string : text; bytes : vec nat8 }; +}; + +type RegisterResponse = variant { + // A new user was successfully registered. + registered: record { + user_number: UserNumber; + }; + // No more registrations are possible in this instance of the II service canister. + canister_full; + // The challenge was not successful. + bad_challenge; +}; + +type AddTentativeDeviceResponse = variant { + // The device was tentatively added. + added_tentatively: record { + verification_code: text; + // Expiration date, in nanos since the epoch + device_registration_timeout: Timestamp; + }; + // Device registration mode is off, either due to timeout or because it was never enabled. + device_registration_mode_off; + // There is another device already added tentatively + another_device_tentatively_added; +}; + +type VerifyTentativeDeviceResponse = variant { + // The device was successfully verified. + verified; + // Wrong verification code entered. Retry with correct code. + wrong_code: record { + retries_left: nat8 + }; + // Device registration mode is off, either due to timeout or because it was never enabled. + device_registration_mode_off; + // There is no tentative device to be verified. + no_device_to_verify; +}; + +type Delegation = record { + pubkey: PublicKey; + expiration: Timestamp; + targets: opt vec principal; +}; + +type SignedDelegation = record { + delegation: Delegation; + signature: blob; +}; + +type GetDelegationResponse = variant { + // The signed delegation was successfully retrieved. + signed_delegation: SignedDelegation; + + // The signature is not ready. Maybe retry by calling `prepare_delegation` + no_such_delegation +}; + +type InternetIdentityStats = record { + users_registered: nat64; + storage_layout_version: nat8; + assigned_user_number_range: record { + nat64; + nat64; + }; + archive_info: ArchiveInfo; + canister_creation_cycles_cost: nat64; + // Map from event aggregation to a sorted list of top 100 sub-keys to their weights. + // Example: {"prepare_delegation_count 24h ic0.app": [{"https://dapp.com", 100}, {"https://dapp2.com", 50}]} + event_aggregations: vec record {text; vec record {text; nat64}}; +}; + +// Configuration parameters related to the archive. +type ArchiveConfig = record { + // The allowed module hash of the archive canister. + // Changing this parameter does _not_ deploy the archive, but enable archive deployments with the + // corresponding wasm module. + module_hash : blob; + // Buffered archive entries limit. If reached, II will stop accepting new anchor operations + // until the buffered operations are acknowledged by the archive. + entries_buffer_limit: nat64; + // The maximum number of entries to be transferred to the archive per call. + entries_fetch_limit: nat16; + // Polling interval to fetch new entries from II (in nanoseconds). + // Changes to this parameter will only take effect after an archive deployment. + polling_interval_ns: nat64; +}; + +// Information about the archive. +type ArchiveInfo = record { + // Canister id of the archive or empty if no archive has been deployed yet. + archive_canister : opt principal; + // Configuration parameters related to the II archive. + archive_config: opt ArchiveConfig; +}; + +// Rate limit configuration. +// Currently only used for `register`. +type RateLimitConfig = record { + // Time it takes (in ns) for a rate limiting token to be replenished. + time_per_token_ns : nat64; + // How many tokens are at most generated (to accommodate peaks). + max_tokens: nat64; +}; + +// Init arguments of II which can be supplied on install and upgrade. +// Setting a value to null keeps the previous value. +type InternetIdentityInit = record { + // Set lowest and highest anchor + assigned_user_number_range : opt record { + nat64; + nat64; + }; + // Configuration parameters related to the II archive. + // Note: some parameters changes (like the polling interval) will only take effect after an archive deployment. + // See ArchiveConfig for details. + archive_config: opt ArchiveConfig; + // Set the amounts of cycles sent with the create canister message. + // This is configurable because in the staging environment cycles are required. + // The canister creation cost on mainnet is currently 100'000'000'000 cycles. If this value is higher thant the + // canister creation cost, the newly created canister will keep extra cycles. + canister_creation_cycles_cost : opt nat64; + // Rate limit for the `register` call. + register_rate_limit : opt RateLimitConfig; + // Maximum number of inflight captchas. + // Default: 500 + max_inflight_captchas: opt nat64; +}; + +type ChallengeKey = text; + +type ChallengeResult = record { + key : ChallengeKey; + chars : text; +}; +type CaptchaResult = ChallengeResult; + +// Extra information about registration status for new devices +type DeviceRegistrationInfo = record { + // If present, the user has tentatively added a new device. This + // new device needs to be verified (see relevant endpoint) before + // 'expiration'. + tentative_device : opt DeviceData; + // The timestamp at which the anchor will turn off registration mode + // (and the tentative device will be forgotten, if any, and if not verified) + expiration: Timestamp; +}; + +// Information about the anchor +type IdentityAnchorInfo = record { + // All devices that can authenticate to this anchor + devices : vec DeviceWithUsage; + // Device registration status used when adding devices, see DeviceRegistrationInfo + device_registration: opt DeviceRegistrationInfo; +}; + +type AnchorCredentials = record { + credentials : vec WebAuthnCredential; + recovery_credentials : vec WebAuthnCredential; + recovery_phrases: vec PublicKey; +}; + +type WebAuthnCredential = record { + credential_id : CredentialId; + pubkey: PublicKey; +}; + +type DeployArchiveResult = variant { + // The archive was deployed successfully and the supplied wasm module has been installed. The principal of the archive + // canister is returned. + success: principal; + // Initial archive creation is already in progress. + creation_in_progress; + // Archive deployment failed. An error description is returned. + failed: text; +}; + +type BufferedArchiveEntry = record { + anchor_number: UserNumber; + timestamp: Timestamp; + sequence_number: nat64; + entry: blob; +}; + +// API V2 specific types +// WARNING: These type are experimental and may change in the future. + +type IdentityNumber = nat64; + +// Map with some variants for the value type. +// Note, due to the Candid mapping this must be a tuple type thus we cannot name the fields `key` and `value`. +type MetadataMapV2 = vec record { + text; + variant { Map : MetadataMapV2; String : text; Bytes : vec nat8 }; +}; + +// Authentication method using WebAuthn signatures +// See https://www.w3.org/TR/webauthn-2/ +// This is a separate type because WebAuthn requires to also store +// the credential id (in addition to the public key). +type WebAuthn = record { + credential_id: CredentialId; + pubkey: PublicKey; +}; + +// Authentication method using generic signatures +// See https://internetcomputer.org/docs/current/references/ic-interface-spec/#signatures for +// supported signature schemes. +type PublicKeyAuthn = record { + pubkey: PublicKey; +}; + +// The authentication methods currently supported by II. +type AuthnMethod = variant { + WebAuthn: WebAuthn; + PubKey: PublicKeyAuthn; +}; + +// This describes whether an authentication method is "protected" or not. +// When protected, a authentication method can only be updated or removed if the +// user is authenticated with that very authentication method. +type AuthnMethodProtection = variant { + Protected; + Unprotected; +}; + +type AuthnMethodPurpose = variant { + Recovery; + Authentication; +}; + +type AuthnMethodSecuritySettings = record { + protection: AuthnMethodProtection; + purpose: AuthnMethodPurpose; +}; + +type AuthnMethodData = record { + authn_method: AuthnMethod; + security_settings: AuthnMethodSecuritySettings; + // contains the following fields of the DeviceWithUsage type: + // - alias + // - origin + // - authenticator_attachment: data taken from key_type and reduced to "platform", "cross_platform" or absent on migration + // - usage: data taken from key_type and reduced to "recovery_phrase", "browser_storage_key" or absent on migration + // Note: for compatibility reasons with the v1 API, the entries above (if present) + // must be of the `String` variant. This restriction may be lifted in the future. + metadata: MetadataMapV2; + last_authentication: opt Timestamp; +}; + +// Extra information about registration status for new authentication methods +type AuthnMethodRegistrationInfo = record { + // If present, the user has registered a new authentication method. This + // new authentication needs to be verified before 'expiration' in order to + // be added to the identity. + authn_method : opt AuthnMethodData; + // The timestamp at which the identity will turn off registration mode + // (and the authentication method will be forgotten, if any, and if not verified) + expiration: Timestamp; +}; + +type AuthnMethodConfirmationCode = record { + confirmation_code: text; + expiration: Timestamp; +}; + +type AuthnMethodRegisterError = variant { + // Authentication method registration mode is off, either due to timeout or because it was never enabled. + RegistrationModeOff; + // There is another authentication method already registered that needs to be confirmed first. + RegistrationAlreadyInProgress; + // The metadata of the provided authentication method contains invalid entries. + InvalidMetadata: text; +}; + +type AuthnMethodConfirmationError = variant { + // Wrong confirmation code entered. Retry with correct code. + WrongCode: record { + retries_left: nat8 + }; + // Authentication method registration mode is off, either due to timeout or because it was never enabled. + RegistrationModeOff; + // There is no registered authentication method to be confirmed. + NoAuthnMethodToConfirm; +}; + +type IdentityAuthnInfo = record { + authn_methods: vec AuthnMethod; + recovery_authn_methods: vec AuthnMethod; +}; + +type IdentityInfo = record { + authn_methods: vec AuthnMethodData; + authn_method_registration: opt AuthnMethodRegistrationInfo; + // Authentication method independent metadata + metadata: MetadataMapV2; +}; + +type IdentityInfoError = variant { + /// The principal is not authorized to call this method with the given arguments. + Unauthorized: principal; + /// Internal canister error. See the error message for details. + InternalCanisterError: text; +}; + + + +type IdentityRegisterError = variant { + // No more registrations are possible in this instance of the II service canister. + CanisterFull; + // The captcha check was not successful. + BadCaptcha; + // The metadata of the provided authentication method contains invalid entries. + InvalidMetadata: text; +}; + +type AuthnMethodAddError = variant { + InvalidMetadata: text; +}; + +type AuthnMethodReplaceError = variant { + InvalidMetadata: text; + // No authentication method found with the given public key. + AuthnMethodNotFound; +}; + +type AuthnMethodMetadataReplaceError = variant { + InvalidMetadata: text; + /// No authentication method found with the given public key. + AuthnMethodNotFound; +}; + +type AuthnMethodSecuritySettingsReplaceError = variant { + /// No authentication method found with the given public key. + AuthnMethodNotFound; +}; + +type IdentityMetadataReplaceError = variant { + /// The principal is not authorized to call this method with the given arguments. + Unauthorized: principal; + /// The identity including the new metadata exceeds the maximum allowed size. + StorageSpaceExceeded: record {space_available: nat64; space_required: nat64}; + /// Internal canister error. See the error message for details. + InternalCanisterError: text; +}; + +type PrepareIdAliasRequest = record { + /// Origin of the issuer in the attribute sharing flow. + issuer : FrontendHostname; + /// Origin of the relying party in the attribute sharing flow. + relying_party : FrontendHostname; + /// Identity for which the IdAlias should be generated. + identity_number : IdentityNumber; +}; + +type PrepareIdAliasError = variant { + /// The principal is not authorized to call this method with the given arguments. + Unauthorized: principal; + /// Internal canister error. See the error message for details. + InternalCanisterError: text; +}; + +/// The prepared id alias contains two (still unsigned) credentials in JWT format, +/// certifying the id alias for the issuer resp. the relying party. +type PreparedIdAlias = record { + rp_id_alias_jwt : text; + issuer_id_alias_jwt : text; + canister_sig_pk_der : PublicKey; +}; + +/// The request to retrieve the actual signed id alias credentials. +/// The field values should be equal to the values of corresponding +/// fields from the preceding `PrepareIdAliasRequest` and `PrepareIdAliasResponse`. +type GetIdAliasRequest = record { + rp_id_alias_jwt : text; + issuer : FrontendHostname; + issuer_id_alias_jwt : text; + relying_party : FrontendHostname; + identity_number : IdentityNumber; +}; + +type GetIdAliasError = variant { + /// The principal is not authorized to call this method with the given arguments. + Unauthorized: principal; + /// The credential(s) are not available: may be expired or not prepared yet (call prepare_id_alias to prepare). + NoSuchCredentials : text; + /// Internal canister error. See the error message for details. + InternalCanisterError: text; +}; + +/// The signed id alias credentials for each involved party. +type IdAliasCredentials = record { + rp_id_alias_credential : SignedIdAlias; + issuer_id_alias_credential : SignedIdAlias; +}; + +type SignedIdAlias = record { + credential_jws : text; + id_alias : principal; + id_dapp : principal; +}; + +service : (opt InternetIdentityInit) -> { + init_salt: () -> (); + create_challenge : () -> (Challenge); + register : (DeviceData, ChallengeResult, opt principal) -> (RegisterResponse); + add : (UserNumber, DeviceData) -> (); + update : (UserNumber, DeviceKey, DeviceData) -> (); + // Atomically replace device matching the device key with the new device data + replace : (UserNumber, DeviceKey, DeviceData) -> (); + remove : (UserNumber, DeviceKey) -> (); + // Returns all devices of the user (authentication and recovery) but no information about device registrations. + // Note: Clears out the 'alias' fields on the devices. Use 'get_anchor_info' to obtain the full information. + // Deprecated: Use 'get_anchor_credentials' instead. + lookup : (UserNumber) -> (vec DeviceData) query; + get_anchor_credentials : (UserNumber) -> (AnchorCredentials) query; + get_anchor_info : (UserNumber) -> (IdentityAnchorInfo); + get_principal : (UserNumber, FrontendHostname) -> (principal) query; + stats : () -> (InternetIdentityStats) query; + + enter_device_registration_mode : (UserNumber) -> (Timestamp); + exit_device_registration_mode : (UserNumber) -> (); + add_tentative_device : (UserNumber, DeviceData) -> (AddTentativeDeviceResponse); + verify_tentative_device : (UserNumber, verification_code: text) -> (VerifyTentativeDeviceResponse); + + prepare_delegation : (UserNumber, FrontendHostname, SessionKey, maxTimeToLive : opt nat64) -> (UserKey, Timestamp); + get_delegation: (UserNumber, FrontendHostname, SessionKey, Timestamp) -> (GetDelegationResponse) query; + + http_request: (request: HttpRequest) -> (HttpResponse) query; + http_request_update: (request: HttpRequest) -> (HttpResponse); + + deploy_archive: (wasm: blob) -> (DeployArchiveResult); + // Returns a batch of entries _sorted by sequence number_ to be archived. + // This is an update call because the archive information _must_ be certified. + // Only callable by this IIs archive canister. + fetch_entries: () -> (vec BufferedArchiveEntry); + acknowledge_entries: (sequence_number: nat64) -> (); + + // V2 API + // WARNING: The following methods are experimental and may change in the future. + + // Creates a new captcha. The solution needs to be submitted using the + // `identity_register` call. + captcha_create: () -> (variant {Ok: Challenge; Err;}); + + // Registers a new identity with the given authn_method. + // A valid captcha solution to a previously generated captcha (using create_captcha) must be provided. + // The sender needs to match the supplied authn_method. + identity_register: (AuthnMethodData, CaptchaResult, opt principal) -> (variant {Ok: IdentityNumber; Err: IdentityRegisterError;}); + + // Returns information about the authentication methods of the identity with the given number. + // Only returns the minimal information required for authentication without exposing any metadata such as aliases. + identity_authn_info: (IdentityNumber) -> (variant {Ok: IdentityAuthnInfo; Err;}) query; + + // Returns information about the identity with the given number. + // Requires authentication. + identity_info: (IdentityNumber) -> (variant {Ok: IdentityInfo; Err: IdentityInfoError;}); + + // Replaces the authentication method independent metadata map. + // The existing metadata map will be overwritten. + // Requires authentication. + identity_metadata_replace: (IdentityNumber, MetadataMapV2) -> (variant {Ok; Err: IdentityMetadataReplaceError;}); + + // Adds a new authentication method to the identity. + // Requires authentication. + authn_method_add: (IdentityNumber, AuthnMethodData) -> (variant {Ok; Err: AuthnMethodAddError;}); + + // Atomically replaces the authentication method matching the supplied public key with the new authentication method + // provided. + // Requires authentication. + authn_method_replace: (IdentityNumber, PublicKey, AuthnMethodData) -> (variant {Ok; Err: AuthnMethodReplaceError;}); + + // Replaces the authentication method metadata map. + // The existing metadata map will be overwritten. + // Requires authentication. + authn_method_metadata_replace: (IdentityNumber, PublicKey, MetadataMapV2) -> (variant {Ok; Err: AuthnMethodMetadataReplaceError;}); + + // Replaces the authentication method security settings. + // The existing security settings will be overwritten. + // Requires authentication. + authn_method_security_settings_replace: (IdentityNumber, PublicKey, AuthnMethodSecuritySettings) -> (variant {Ok; Err: AuthnMethodSecuritySettingsReplaceError;}); + + // Removes the authentication method associated with the public key from the identity. + // Requires authentication. + authn_method_remove: (IdentityNumber, PublicKey) -> (variant {Ok; Err;}); + + // Enters the authentication method registration mode for the identity. + // In this mode, a new authentication method can be registered, which then needs to be + // confirmed before it can be used for authentication on this identity. + // The registration mode is automatically exited after the returned expiration timestamp. + // Requires authentication. + authn_method_registration_mode_enter : (IdentityNumber) -> (variant {Ok: record { expiration: Timestamp; }; Err;}); + + // Exits the authentication method registration mode for the identity. + // Requires authentication. + authn_method_registration_mode_exit : (IdentityNumber) -> (variant {Ok; Err;}); + + // Registers a new authentication method to the identity. + // This authentication method needs to be confirmed before it can be used for authentication on this identity. + authn_method_register: (IdentityNumber, AuthnMethodData) -> (variant {Ok: AuthnMethodConfirmationCode; Err: AuthnMethodRegisterError;}); + + // Confirms a previously registered authentication method. + // On successful confirmation, the authentication method is permanently added to the identity and can + // subsequently be used for authentication for that identity. + // Requires authentication. + authn_method_confirm: (IdentityNumber, confirmation_code: text) -> (variant {Ok; Err: AuthnMethodConfirmationError;}); + + // Attribute Sharing MVP API + // The methods below are used to generate ID-alias credentials during attribute sharing flow. + prepare_id_alias : (PrepareIdAliasRequest) -> (variant {Ok: PreparedIdAlias; Err: PrepareIdAliasError;}); + get_id_alias : (GetIdAliasRequest) -> (variant {Ok: IdAliasCredentials; Err: GetIdAliasError;}) query; +} diff --git a/src/civic_sign_frontend_demo/src/declarations/internet_identity/internet_identity.did.d.ts b/src/civic_sign_frontend_demo/src/declarations/internet_identity/internet_identity.did.d.ts new file mode 100644 index 0000000..5ea5582 --- /dev/null +++ b/src/civic_sign_frontend_demo/src/declarations/internet_identity/internet_identity.did.d.ts @@ -0,0 +1,390 @@ +import type { Principal } from '@dfinity/principal'; +import type { ActorMethod } from '@dfinity/agent'; +import type { IDL } from '@dfinity/candid'; + +export type AddTentativeDeviceResponse = { + 'device_registration_mode_off' : null + } | + { 'another_device_tentatively_added' : null } | + { + 'added_tentatively' : { + 'verification_code' : string, + 'device_registration_timeout' : Timestamp, + } + }; +export interface AnchorCredentials { + 'recovery_phrases' : Array, + 'credentials' : Array, + 'recovery_credentials' : Array, +} +export interface ArchiveConfig { + 'polling_interval_ns' : bigint, + 'entries_buffer_limit' : bigint, + 'module_hash' : Uint8Array | number[], + 'entries_fetch_limit' : number, +} +export interface ArchiveInfo { + 'archive_config' : [] | [ArchiveConfig], + 'archive_canister' : [] | [Principal], +} +export type AuthnMethod = { 'PubKey' : PublicKeyAuthn } | + { 'WebAuthn' : WebAuthn }; +export type AuthnMethodAddError = { 'InvalidMetadata' : string }; +export interface AuthnMethodConfirmationCode { + 'confirmation_code' : string, + 'expiration' : Timestamp, +} +export type AuthnMethodConfirmationError = { 'RegistrationModeOff' : null } | + { 'NoAuthnMethodToConfirm' : null } | + { 'WrongCode' : { 'retries_left' : number } }; +export interface AuthnMethodData { + 'security_settings' : AuthnMethodSecuritySettings, + 'metadata' : MetadataMapV2, + 'last_authentication' : [] | [Timestamp], + 'authn_method' : AuthnMethod, +} +export type AuthnMethodMetadataReplaceError = { 'AuthnMethodNotFound' : null } | + { 'InvalidMetadata' : string }; +export type AuthnMethodProtection = { 'Protected' : null } | + { 'Unprotected' : null }; +export type AuthnMethodPurpose = { 'Recovery' : null } | + { 'Authentication' : null }; +export type AuthnMethodRegisterError = { 'RegistrationModeOff' : null } | + { 'RegistrationAlreadyInProgress' : null } | + { 'InvalidMetadata' : string }; +export interface AuthnMethodRegistrationInfo { + 'expiration' : Timestamp, + 'authn_method' : [] | [AuthnMethodData], +} +export type AuthnMethodReplaceError = { 'AuthnMethodNotFound' : null } | + { 'InvalidMetadata' : string }; +export interface AuthnMethodSecuritySettings { + 'protection' : AuthnMethodProtection, + 'purpose' : AuthnMethodPurpose, +} +export type AuthnMethodSecuritySettingsReplaceError = { + 'AuthnMethodNotFound' : null + }; +export interface BufferedArchiveEntry { + 'sequence_number' : bigint, + 'entry' : Uint8Array | number[], + 'anchor_number' : UserNumber, + 'timestamp' : Timestamp, +} +export type CaptchaResult = ChallengeResult; +export interface Challenge { + 'png_base64' : string, + 'challenge_key' : ChallengeKey, +} +export type ChallengeKey = string; +export interface ChallengeResult { 'key' : ChallengeKey, 'chars' : string } +export type CredentialId = Uint8Array | number[]; +export interface Delegation { + 'pubkey' : PublicKey, + 'targets' : [] | [Array], + 'expiration' : Timestamp, +} +export type DeployArchiveResult = { 'creation_in_progress' : null } | + { 'success' : Principal } | + { 'failed' : string }; +export interface DeviceData { + 'alias' : string, + 'metadata' : [] | [MetadataMap], + 'origin' : [] | [string], + 'protection' : DeviceProtection, + 'pubkey' : DeviceKey, + 'key_type' : KeyType, + 'purpose' : Purpose, + 'credential_id' : [] | [CredentialId], +} +export type DeviceKey = PublicKey; +export type DeviceProtection = { 'unprotected' : null } | + { 'protected' : null }; +export interface DeviceRegistrationInfo { + 'tentative_device' : [] | [DeviceData], + 'expiration' : Timestamp, +} +export interface DeviceWithUsage { + 'alias' : string, + 'last_usage' : [] | [Timestamp], + 'metadata' : [] | [MetadataMap], + 'origin' : [] | [string], + 'protection' : DeviceProtection, + 'pubkey' : DeviceKey, + 'key_type' : KeyType, + 'purpose' : Purpose, + 'credential_id' : [] | [CredentialId], +} +export type FrontendHostname = string; +export type GetDelegationResponse = { 'no_such_delegation' : null } | + { 'signed_delegation' : SignedDelegation }; +export type GetIdAliasError = { 'InternalCanisterError' : string } | + { 'Unauthorized' : Principal } | + { 'NoSuchCredentials' : string }; +export interface GetIdAliasRequest { + 'rp_id_alias_jwt' : string, + 'issuer' : FrontendHostname, + 'issuer_id_alias_jwt' : string, + 'relying_party' : FrontendHostname, + 'identity_number' : IdentityNumber, +} +export type HeaderField = [string, string]; +export interface HttpRequest { + 'url' : string, + 'method' : string, + 'body' : Uint8Array | number[], + 'headers' : Array, + 'certificate_version' : [] | [number], +} +export interface HttpResponse { + 'body' : Uint8Array | number[], + 'headers' : Array, + 'upgrade' : [] | [boolean], + 'streaming_strategy' : [] | [StreamingStrategy], + 'status_code' : number, +} +export interface IdAliasCredentials { + 'rp_id_alias_credential' : SignedIdAlias, + 'issuer_id_alias_credential' : SignedIdAlias, +} +export interface IdentityAnchorInfo { + 'devices' : Array, + 'device_registration' : [] | [DeviceRegistrationInfo], +} +export interface IdentityAuthnInfo { + 'authn_methods' : Array, + 'recovery_authn_methods' : Array, +} +export interface IdentityInfo { + 'authn_methods' : Array, + 'metadata' : MetadataMapV2, + 'authn_method_registration' : [] | [AuthnMethodRegistrationInfo], +} +export type IdentityInfoError = { 'InternalCanisterError' : string } | + { 'Unauthorized' : Principal }; +export type IdentityMetadataReplaceError = { + 'InternalCanisterError' : string + } | + { 'Unauthorized' : Principal } | + { + 'StorageSpaceExceeded' : { + 'space_required' : bigint, + 'space_available' : bigint, + } + }; +export type IdentityNumber = bigint; +export type IdentityRegisterError = { 'BadCaptcha' : null } | + { 'CanisterFull' : null } | + { 'InvalidMetadata' : string }; +export interface InternetIdentityInit { + 'assigned_user_number_range' : [] | [[bigint, bigint]], + 'max_inflight_captchas' : [] | [bigint], + 'archive_config' : [] | [ArchiveConfig], + 'canister_creation_cycles_cost' : [] | [bigint], + 'register_rate_limit' : [] | [RateLimitConfig], +} +export interface InternetIdentityStats { + 'storage_layout_version' : number, + 'users_registered' : bigint, + 'assigned_user_number_range' : [bigint, bigint], + 'archive_info' : ArchiveInfo, + 'canister_creation_cycles_cost' : bigint, + 'event_aggregations' : Array<[string, Array<[string, bigint]>]>, +} +export type KeyType = { 'platform' : null } | + { 'seed_phrase' : null } | + { 'cross_platform' : null } | + { 'unknown' : null } | + { 'browser_storage_key' : null }; +export type MetadataMap = Array< + [ + string, + { 'map' : MetadataMap } | + { 'string' : string } | + { 'bytes' : Uint8Array | number[] }, + ] +>; +export type MetadataMapV2 = Array< + [ + string, + { 'Map' : MetadataMapV2 } | + { 'String' : string } | + { 'Bytes' : Uint8Array | number[] }, + ] +>; +export type PrepareIdAliasError = { 'InternalCanisterError' : string } | + { 'Unauthorized' : Principal }; +export interface PrepareIdAliasRequest { + 'issuer' : FrontendHostname, + 'relying_party' : FrontendHostname, + 'identity_number' : IdentityNumber, +} +export interface PreparedIdAlias { + 'rp_id_alias_jwt' : string, + 'issuer_id_alias_jwt' : string, + 'canister_sig_pk_der' : PublicKey, +} +export type PublicKey = Uint8Array | number[]; +export interface PublicKeyAuthn { 'pubkey' : PublicKey } +export type Purpose = { 'authentication' : null } | + { 'recovery' : null }; +export interface RateLimitConfig { + 'max_tokens' : bigint, + 'time_per_token_ns' : bigint, +} +export type RegisterResponse = { 'bad_challenge' : null } | + { 'canister_full' : null } | + { 'registered' : { 'user_number' : UserNumber } }; +export type SessionKey = PublicKey; +export interface SignedDelegation { + 'signature' : Uint8Array | number[], + 'delegation' : Delegation, +} +export interface SignedIdAlias { + 'credential_jws' : string, + 'id_alias' : Principal, + 'id_dapp' : Principal, +} +export interface StreamingCallbackHttpResponse { + 'token' : [] | [Token], + 'body' : Uint8Array | number[], +} +export type StreamingStrategy = { + 'Callback' : { 'token' : Token, 'callback' : [Principal, string] } + }; +export type Timestamp = bigint; +export type Token = {}; +export type UserKey = PublicKey; +export type UserNumber = bigint; +export type VerifyTentativeDeviceResponse = { + 'device_registration_mode_off' : null + } | + { 'verified' : null } | + { 'wrong_code' : { 'retries_left' : number } } | + { 'no_device_to_verify' : null }; +export interface WebAuthn { + 'pubkey' : PublicKey, + 'credential_id' : CredentialId, +} +export interface WebAuthnCredential { + 'pubkey' : PublicKey, + 'credential_id' : CredentialId, +} +export interface _SERVICE { + 'acknowledge_entries' : ActorMethod<[bigint], undefined>, + 'add' : ActorMethod<[UserNumber, DeviceData], undefined>, + 'add_tentative_device' : ActorMethod< + [UserNumber, DeviceData], + AddTentativeDeviceResponse + >, + 'authn_method_add' : ActorMethod< + [IdentityNumber, AuthnMethodData], + { 'Ok' : null } | + { 'Err' : AuthnMethodAddError } + >, + 'authn_method_confirm' : ActorMethod< + [IdentityNumber, string], + { 'Ok' : null } | + { 'Err' : AuthnMethodConfirmationError } + >, + 'authn_method_metadata_replace' : ActorMethod< + [IdentityNumber, PublicKey, MetadataMapV2], + { 'Ok' : null } | + { 'Err' : AuthnMethodMetadataReplaceError } + >, + 'authn_method_register' : ActorMethod< + [IdentityNumber, AuthnMethodData], + { 'Ok' : AuthnMethodConfirmationCode } | + { 'Err' : AuthnMethodRegisterError } + >, + 'authn_method_registration_mode_enter' : ActorMethod< + [IdentityNumber], + { 'Ok' : { 'expiration' : Timestamp } } | + { 'Err' : null } + >, + 'authn_method_registration_mode_exit' : ActorMethod< + [IdentityNumber], + { 'Ok' : null } | + { 'Err' : null } + >, + 'authn_method_remove' : ActorMethod< + [IdentityNumber, PublicKey], + { 'Ok' : null } | + { 'Err' : null } + >, + 'authn_method_replace' : ActorMethod< + [IdentityNumber, PublicKey, AuthnMethodData], + { 'Ok' : null } | + { 'Err' : AuthnMethodReplaceError } + >, + 'authn_method_security_settings_replace' : ActorMethod< + [IdentityNumber, PublicKey, AuthnMethodSecuritySettings], + { 'Ok' : null } | + { 'Err' : AuthnMethodSecuritySettingsReplaceError } + >, + 'captcha_create' : ActorMethod<[], { 'Ok' : Challenge } | { 'Err' : null }>, + 'create_challenge' : ActorMethod<[], Challenge>, + 'deploy_archive' : ActorMethod<[Uint8Array | number[]], DeployArchiveResult>, + 'enter_device_registration_mode' : ActorMethod<[UserNumber], Timestamp>, + 'exit_device_registration_mode' : ActorMethod<[UserNumber], undefined>, + 'fetch_entries' : ActorMethod<[], Array>, + 'get_anchor_credentials' : ActorMethod<[UserNumber], AnchorCredentials>, + 'get_anchor_info' : ActorMethod<[UserNumber], IdentityAnchorInfo>, + 'get_delegation' : ActorMethod< + [UserNumber, FrontendHostname, SessionKey, Timestamp], + GetDelegationResponse + >, + 'get_id_alias' : ActorMethod< + [GetIdAliasRequest], + { 'Ok' : IdAliasCredentials } | + { 'Err' : GetIdAliasError } + >, + 'get_principal' : ActorMethod<[UserNumber, FrontendHostname], Principal>, + 'http_request' : ActorMethod<[HttpRequest], HttpResponse>, + 'http_request_update' : ActorMethod<[HttpRequest], HttpResponse>, + 'identity_authn_info' : ActorMethod< + [IdentityNumber], + { 'Ok' : IdentityAuthnInfo } | + { 'Err' : null } + >, + 'identity_info' : ActorMethod< + [IdentityNumber], + { 'Ok' : IdentityInfo } | + { 'Err' : IdentityInfoError } + >, + 'identity_metadata_replace' : ActorMethod< + [IdentityNumber, MetadataMapV2], + { 'Ok' : null } | + { 'Err' : IdentityMetadataReplaceError } + >, + 'identity_register' : ActorMethod< + [AuthnMethodData, CaptchaResult, [] | [Principal]], + { 'Ok' : IdentityNumber } | + { 'Err' : IdentityRegisterError } + >, + 'init_salt' : ActorMethod<[], undefined>, + 'lookup' : ActorMethod<[UserNumber], Array>, + 'prepare_delegation' : ActorMethod< + [UserNumber, FrontendHostname, SessionKey, [] | [bigint]], + [UserKey, Timestamp] + >, + 'prepare_id_alias' : ActorMethod< + [PrepareIdAliasRequest], + { 'Ok' : PreparedIdAlias } | + { 'Err' : PrepareIdAliasError } + >, + 'register' : ActorMethod< + [DeviceData, ChallengeResult, [] | [Principal]], + RegisterResponse + >, + 'remove' : ActorMethod<[UserNumber, DeviceKey], undefined>, + 'replace' : ActorMethod<[UserNumber, DeviceKey, DeviceData], undefined>, + 'stats' : ActorMethod<[], InternetIdentityStats>, + 'update' : ActorMethod<[UserNumber, DeviceKey, DeviceData], undefined>, + 'verify_tentative_device' : ActorMethod< + [UserNumber, string], + VerifyTentativeDeviceResponse + >, +} +export declare const idlFactory: IDL.InterfaceFactory; +export declare const init: (args: { IDL: typeof IDL }) => IDL.Type[]; diff --git a/src/civic_sign_frontend_demo/src/declarations/internet_identity/internet_identity.did.js b/src/civic_sign_frontend_demo/src/declarations/internet_identity/internet_identity.did.js new file mode 100644 index 0000000..c0eb4f8 --- /dev/null +++ b/src/civic_sign_frontend_demo/src/declarations/internet_identity/internet_identity.did.js @@ -0,0 +1,505 @@ +export const idlFactory = ({ IDL }) => { + const MetadataMap = IDL.Rec(); + const MetadataMapV2 = IDL.Rec(); + const ArchiveConfig = IDL.Record({ + 'polling_interval_ns' : IDL.Nat64, + 'entries_buffer_limit' : IDL.Nat64, + 'module_hash' : IDL.Vec(IDL.Nat8), + 'entries_fetch_limit' : IDL.Nat16, + }); + const RateLimitConfig = IDL.Record({ + 'max_tokens' : IDL.Nat64, + 'time_per_token_ns' : IDL.Nat64, + }); + const InternetIdentityInit = IDL.Record({ + 'assigned_user_number_range' : IDL.Opt(IDL.Tuple(IDL.Nat64, IDL.Nat64)), + 'max_inflight_captchas' : IDL.Opt(IDL.Nat64), + 'archive_config' : IDL.Opt(ArchiveConfig), + 'canister_creation_cycles_cost' : IDL.Opt(IDL.Nat64), + 'register_rate_limit' : IDL.Opt(RateLimitConfig), + }); + const UserNumber = IDL.Nat64; + MetadataMap.fill( + IDL.Vec( + IDL.Tuple( + IDL.Text, + IDL.Variant({ + 'map' : MetadataMap, + 'string' : IDL.Text, + 'bytes' : IDL.Vec(IDL.Nat8), + }), + ) + ) + ); + const DeviceProtection = IDL.Variant({ + 'unprotected' : IDL.Null, + 'protected' : IDL.Null, + }); + const PublicKey = IDL.Vec(IDL.Nat8); + const DeviceKey = PublicKey; + const KeyType = IDL.Variant({ + 'platform' : IDL.Null, + 'seed_phrase' : IDL.Null, + 'cross_platform' : IDL.Null, + 'unknown' : IDL.Null, + 'browser_storage_key' : IDL.Null, + }); + const Purpose = IDL.Variant({ + 'authentication' : IDL.Null, + 'recovery' : IDL.Null, + }); + const CredentialId = IDL.Vec(IDL.Nat8); + const DeviceData = IDL.Record({ + 'alias' : IDL.Text, + 'metadata' : IDL.Opt(MetadataMap), + 'origin' : IDL.Opt(IDL.Text), + 'protection' : DeviceProtection, + 'pubkey' : DeviceKey, + 'key_type' : KeyType, + 'purpose' : Purpose, + 'credential_id' : IDL.Opt(CredentialId), + }); + const Timestamp = IDL.Nat64; + const AddTentativeDeviceResponse = IDL.Variant({ + 'device_registration_mode_off' : IDL.Null, + 'another_device_tentatively_added' : IDL.Null, + 'added_tentatively' : IDL.Record({ + 'verification_code' : IDL.Text, + 'device_registration_timeout' : Timestamp, + }), + }); + const IdentityNumber = IDL.Nat64; + const AuthnMethodProtection = IDL.Variant({ + 'Protected' : IDL.Null, + 'Unprotected' : IDL.Null, + }); + const AuthnMethodPurpose = IDL.Variant({ + 'Recovery' : IDL.Null, + 'Authentication' : IDL.Null, + }); + const AuthnMethodSecuritySettings = IDL.Record({ + 'protection' : AuthnMethodProtection, + 'purpose' : AuthnMethodPurpose, + }); + MetadataMapV2.fill( + IDL.Vec( + IDL.Tuple( + IDL.Text, + IDL.Variant({ + 'Map' : MetadataMapV2, + 'String' : IDL.Text, + 'Bytes' : IDL.Vec(IDL.Nat8), + }), + ) + ) + ); + const PublicKeyAuthn = IDL.Record({ 'pubkey' : PublicKey }); + const WebAuthn = IDL.Record({ + 'pubkey' : PublicKey, + 'credential_id' : CredentialId, + }); + const AuthnMethod = IDL.Variant({ + 'PubKey' : PublicKeyAuthn, + 'WebAuthn' : WebAuthn, + }); + const AuthnMethodData = IDL.Record({ + 'security_settings' : AuthnMethodSecuritySettings, + 'metadata' : MetadataMapV2, + 'last_authentication' : IDL.Opt(Timestamp), + 'authn_method' : AuthnMethod, + }); + const AuthnMethodAddError = IDL.Variant({ 'InvalidMetadata' : IDL.Text }); + const AuthnMethodConfirmationError = IDL.Variant({ + 'RegistrationModeOff' : IDL.Null, + 'NoAuthnMethodToConfirm' : IDL.Null, + 'WrongCode' : IDL.Record({ 'retries_left' : IDL.Nat8 }), + }); + const AuthnMethodMetadataReplaceError = IDL.Variant({ + 'AuthnMethodNotFound' : IDL.Null, + 'InvalidMetadata' : IDL.Text, + }); + const AuthnMethodConfirmationCode = IDL.Record({ + 'confirmation_code' : IDL.Text, + 'expiration' : Timestamp, + }); + const AuthnMethodRegisterError = IDL.Variant({ + 'RegistrationModeOff' : IDL.Null, + 'RegistrationAlreadyInProgress' : IDL.Null, + 'InvalidMetadata' : IDL.Text, + }); + const AuthnMethodReplaceError = IDL.Variant({ + 'AuthnMethodNotFound' : IDL.Null, + 'InvalidMetadata' : IDL.Text, + }); + const AuthnMethodSecuritySettingsReplaceError = IDL.Variant({ + 'AuthnMethodNotFound' : IDL.Null, + }); + const ChallengeKey = IDL.Text; + const Challenge = IDL.Record({ + 'png_base64' : IDL.Text, + 'challenge_key' : ChallengeKey, + }); + const DeployArchiveResult = IDL.Variant({ + 'creation_in_progress' : IDL.Null, + 'success' : IDL.Principal, + 'failed' : IDL.Text, + }); + const BufferedArchiveEntry = IDL.Record({ + 'sequence_number' : IDL.Nat64, + 'entry' : IDL.Vec(IDL.Nat8), + 'anchor_number' : UserNumber, + 'timestamp' : Timestamp, + }); + const WebAuthnCredential = IDL.Record({ + 'pubkey' : PublicKey, + 'credential_id' : CredentialId, + }); + const AnchorCredentials = IDL.Record({ + 'recovery_phrases' : IDL.Vec(PublicKey), + 'credentials' : IDL.Vec(WebAuthnCredential), + 'recovery_credentials' : IDL.Vec(WebAuthnCredential), + }); + const DeviceWithUsage = IDL.Record({ + 'alias' : IDL.Text, + 'last_usage' : IDL.Opt(Timestamp), + 'metadata' : IDL.Opt(MetadataMap), + 'origin' : IDL.Opt(IDL.Text), + 'protection' : DeviceProtection, + 'pubkey' : DeviceKey, + 'key_type' : KeyType, + 'purpose' : Purpose, + 'credential_id' : IDL.Opt(CredentialId), + }); + const DeviceRegistrationInfo = IDL.Record({ + 'tentative_device' : IDL.Opt(DeviceData), + 'expiration' : Timestamp, + }); + const IdentityAnchorInfo = IDL.Record({ + 'devices' : IDL.Vec(DeviceWithUsage), + 'device_registration' : IDL.Opt(DeviceRegistrationInfo), + }); + const FrontendHostname = IDL.Text; + const SessionKey = PublicKey; + const Delegation = IDL.Record({ + 'pubkey' : PublicKey, + 'targets' : IDL.Opt(IDL.Vec(IDL.Principal)), + 'expiration' : Timestamp, + }); + const SignedDelegation = IDL.Record({ + 'signature' : IDL.Vec(IDL.Nat8), + 'delegation' : Delegation, + }); + const GetDelegationResponse = IDL.Variant({ + 'no_such_delegation' : IDL.Null, + 'signed_delegation' : SignedDelegation, + }); + const GetIdAliasRequest = IDL.Record({ + 'rp_id_alias_jwt' : IDL.Text, + 'issuer' : FrontendHostname, + 'issuer_id_alias_jwt' : IDL.Text, + 'relying_party' : FrontendHostname, + 'identity_number' : IdentityNumber, + }); + const SignedIdAlias = IDL.Record({ + 'credential_jws' : IDL.Text, + 'id_alias' : IDL.Principal, + 'id_dapp' : IDL.Principal, + }); + const IdAliasCredentials = IDL.Record({ + 'rp_id_alias_credential' : SignedIdAlias, + 'issuer_id_alias_credential' : SignedIdAlias, + }); + const GetIdAliasError = IDL.Variant({ + 'InternalCanisterError' : IDL.Text, + 'Unauthorized' : IDL.Principal, + 'NoSuchCredentials' : IDL.Text, + }); + const HeaderField = IDL.Tuple(IDL.Text, IDL.Text); + const HttpRequest = IDL.Record({ + 'url' : IDL.Text, + 'method' : IDL.Text, + 'body' : IDL.Vec(IDL.Nat8), + 'headers' : IDL.Vec(HeaderField), + 'certificate_version' : IDL.Opt(IDL.Nat16), + }); + const Token = IDL.Record({}); + const StreamingCallbackHttpResponse = IDL.Record({ + 'token' : IDL.Opt(Token), + 'body' : IDL.Vec(IDL.Nat8), + }); + const StreamingStrategy = IDL.Variant({ + 'Callback' : IDL.Record({ + 'token' : Token, + 'callback' : IDL.Func( + [Token], + [StreamingCallbackHttpResponse], + ['query'], + ), + }), + }); + const HttpResponse = IDL.Record({ + 'body' : IDL.Vec(IDL.Nat8), + 'headers' : IDL.Vec(HeaderField), + 'upgrade' : IDL.Opt(IDL.Bool), + 'streaming_strategy' : IDL.Opt(StreamingStrategy), + 'status_code' : IDL.Nat16, + }); + const IdentityAuthnInfo = IDL.Record({ + 'authn_methods' : IDL.Vec(AuthnMethod), + 'recovery_authn_methods' : IDL.Vec(AuthnMethod), + }); + const AuthnMethodRegistrationInfo = IDL.Record({ + 'expiration' : Timestamp, + 'authn_method' : IDL.Opt(AuthnMethodData), + }); + const IdentityInfo = IDL.Record({ + 'authn_methods' : IDL.Vec(AuthnMethodData), + 'metadata' : MetadataMapV2, + 'authn_method_registration' : IDL.Opt(AuthnMethodRegistrationInfo), + }); + const IdentityInfoError = IDL.Variant({ + 'InternalCanisterError' : IDL.Text, + 'Unauthorized' : IDL.Principal, + }); + const IdentityMetadataReplaceError = IDL.Variant({ + 'InternalCanisterError' : IDL.Text, + 'Unauthorized' : IDL.Principal, + 'StorageSpaceExceeded' : IDL.Record({ + 'space_required' : IDL.Nat64, + 'space_available' : IDL.Nat64, + }), + }); + const ChallengeResult = IDL.Record({ + 'key' : ChallengeKey, + 'chars' : IDL.Text, + }); + const CaptchaResult = ChallengeResult; + const IdentityRegisterError = IDL.Variant({ + 'BadCaptcha' : IDL.Null, + 'CanisterFull' : IDL.Null, + 'InvalidMetadata' : IDL.Text, + }); + const UserKey = PublicKey; + const PrepareIdAliasRequest = IDL.Record({ + 'issuer' : FrontendHostname, + 'relying_party' : FrontendHostname, + 'identity_number' : IdentityNumber, + }); + const PreparedIdAlias = IDL.Record({ + 'rp_id_alias_jwt' : IDL.Text, + 'issuer_id_alias_jwt' : IDL.Text, + 'canister_sig_pk_der' : PublicKey, + }); + const PrepareIdAliasError = IDL.Variant({ + 'InternalCanisterError' : IDL.Text, + 'Unauthorized' : IDL.Principal, + }); + const RegisterResponse = IDL.Variant({ + 'bad_challenge' : IDL.Null, + 'canister_full' : IDL.Null, + 'registered' : IDL.Record({ 'user_number' : UserNumber }), + }); + const ArchiveInfo = IDL.Record({ + 'archive_config' : IDL.Opt(ArchiveConfig), + 'archive_canister' : IDL.Opt(IDL.Principal), + }); + const InternetIdentityStats = IDL.Record({ + 'storage_layout_version' : IDL.Nat8, + 'users_registered' : IDL.Nat64, + 'assigned_user_number_range' : IDL.Tuple(IDL.Nat64, IDL.Nat64), + 'archive_info' : ArchiveInfo, + 'canister_creation_cycles_cost' : IDL.Nat64, + 'event_aggregations' : IDL.Vec( + IDL.Tuple(IDL.Text, IDL.Vec(IDL.Tuple(IDL.Text, IDL.Nat64))) + ), + }); + const VerifyTentativeDeviceResponse = IDL.Variant({ + 'device_registration_mode_off' : IDL.Null, + 'verified' : IDL.Null, + 'wrong_code' : IDL.Record({ 'retries_left' : IDL.Nat8 }), + 'no_device_to_verify' : IDL.Null, + }); + return IDL.Service({ + 'acknowledge_entries' : IDL.Func([IDL.Nat64], [], []), + 'add' : IDL.Func([UserNumber, DeviceData], [], []), + 'add_tentative_device' : IDL.Func( + [UserNumber, DeviceData], + [AddTentativeDeviceResponse], + [], + ), + 'authn_method_add' : IDL.Func( + [IdentityNumber, AuthnMethodData], + [IDL.Variant({ 'Ok' : IDL.Null, 'Err' : AuthnMethodAddError })], + [], + ), + 'authn_method_confirm' : IDL.Func( + [IdentityNumber, IDL.Text], + [ + IDL.Variant({ + 'Ok' : IDL.Null, + 'Err' : AuthnMethodConfirmationError, + }), + ], + [], + ), + 'authn_method_metadata_replace' : IDL.Func( + [IdentityNumber, PublicKey, MetadataMapV2], + [ + IDL.Variant({ + 'Ok' : IDL.Null, + 'Err' : AuthnMethodMetadataReplaceError, + }), + ], + [], + ), + 'authn_method_register' : IDL.Func( + [IdentityNumber, AuthnMethodData], + [ + IDL.Variant({ + 'Ok' : AuthnMethodConfirmationCode, + 'Err' : AuthnMethodRegisterError, + }), + ], + [], + ), + 'authn_method_registration_mode_enter' : IDL.Func( + [IdentityNumber], + [ + IDL.Variant({ + 'Ok' : IDL.Record({ 'expiration' : Timestamp }), + 'Err' : IDL.Null, + }), + ], + [], + ), + 'authn_method_registration_mode_exit' : IDL.Func( + [IdentityNumber], + [IDL.Variant({ 'Ok' : IDL.Null, 'Err' : IDL.Null })], + [], + ), + 'authn_method_remove' : IDL.Func( + [IdentityNumber, PublicKey], + [IDL.Variant({ 'Ok' : IDL.Null, 'Err' : IDL.Null })], + [], + ), + 'authn_method_replace' : IDL.Func( + [IdentityNumber, PublicKey, AuthnMethodData], + [IDL.Variant({ 'Ok' : IDL.Null, 'Err' : AuthnMethodReplaceError })], + [], + ), + 'authn_method_security_settings_replace' : IDL.Func( + [IdentityNumber, PublicKey, AuthnMethodSecuritySettings], + [ + IDL.Variant({ + 'Ok' : IDL.Null, + 'Err' : AuthnMethodSecuritySettingsReplaceError, + }), + ], + [], + ), + 'captcha_create' : IDL.Func( + [], + [IDL.Variant({ 'Ok' : Challenge, 'Err' : IDL.Null })], + [], + ), + 'create_challenge' : IDL.Func([], [Challenge], []), + 'deploy_archive' : IDL.Func([IDL.Vec(IDL.Nat8)], [DeployArchiveResult], []), + 'enter_device_registration_mode' : IDL.Func([UserNumber], [Timestamp], []), + 'exit_device_registration_mode' : IDL.Func([UserNumber], [], []), + 'fetch_entries' : IDL.Func([], [IDL.Vec(BufferedArchiveEntry)], []), + 'get_anchor_credentials' : IDL.Func( + [UserNumber], + [AnchorCredentials], + ['query'], + ), + 'get_anchor_info' : IDL.Func([UserNumber], [IdentityAnchorInfo], []), + 'get_delegation' : IDL.Func( + [UserNumber, FrontendHostname, SessionKey, Timestamp], + [GetDelegationResponse], + ['query'], + ), + 'get_id_alias' : IDL.Func( + [GetIdAliasRequest], + [IDL.Variant({ 'Ok' : IdAliasCredentials, 'Err' : GetIdAliasError })], + ['query'], + ), + 'get_principal' : IDL.Func( + [UserNumber, FrontendHostname], + [IDL.Principal], + ['query'], + ), + 'http_request' : IDL.Func([HttpRequest], [HttpResponse], ['query']), + 'http_request_update' : IDL.Func([HttpRequest], [HttpResponse], []), + 'identity_authn_info' : IDL.Func( + [IdentityNumber], + [IDL.Variant({ 'Ok' : IdentityAuthnInfo, 'Err' : IDL.Null })], + ['query'], + ), + 'identity_info' : IDL.Func( + [IdentityNumber], + [IDL.Variant({ 'Ok' : IdentityInfo, 'Err' : IdentityInfoError })], + [], + ), + 'identity_metadata_replace' : IDL.Func( + [IdentityNumber, MetadataMapV2], + [ + IDL.Variant({ + 'Ok' : IDL.Null, + 'Err' : IdentityMetadataReplaceError, + }), + ], + [], + ), + 'identity_register' : IDL.Func( + [AuthnMethodData, CaptchaResult, IDL.Opt(IDL.Principal)], + [IDL.Variant({ 'Ok' : IdentityNumber, 'Err' : IdentityRegisterError })], + [], + ), + 'init_salt' : IDL.Func([], [], []), + 'lookup' : IDL.Func([UserNumber], [IDL.Vec(DeviceData)], ['query']), + 'prepare_delegation' : IDL.Func( + [UserNumber, FrontendHostname, SessionKey, IDL.Opt(IDL.Nat64)], + [UserKey, Timestamp], + [], + ), + 'prepare_id_alias' : IDL.Func( + [PrepareIdAliasRequest], + [IDL.Variant({ 'Ok' : PreparedIdAlias, 'Err' : PrepareIdAliasError })], + [], + ), + 'register' : IDL.Func( + [DeviceData, ChallengeResult, IDL.Opt(IDL.Principal)], + [RegisterResponse], + [], + ), + 'remove' : IDL.Func([UserNumber, DeviceKey], [], []), + 'replace' : IDL.Func([UserNumber, DeviceKey, DeviceData], [], []), + 'stats' : IDL.Func([], [InternetIdentityStats], ['query']), + 'update' : IDL.Func([UserNumber, DeviceKey, DeviceData], [], []), + 'verify_tentative_device' : IDL.Func( + [UserNumber, IDL.Text], + [VerifyTentativeDeviceResponse], + [], + ), + }); +}; +export const init = ({ IDL }) => { + const ArchiveConfig = IDL.Record({ + 'polling_interval_ns' : IDL.Nat64, + 'entries_buffer_limit' : IDL.Nat64, + 'module_hash' : IDL.Vec(IDL.Nat8), + 'entries_fetch_limit' : IDL.Nat16, + }); + const RateLimitConfig = IDL.Record({ + 'max_tokens' : IDL.Nat64, + 'time_per_token_ns' : IDL.Nat64, + }); + const InternetIdentityInit = IDL.Record({ + 'assigned_user_number_range' : IDL.Opt(IDL.Tuple(IDL.Nat64, IDL.Nat64)), + 'max_inflight_captchas' : IDL.Opt(IDL.Nat64), + 'archive_config' : IDL.Opt(ArchiveConfig), + 'canister_creation_cycles_cost' : IDL.Opt(IDL.Nat64), + 'register_rate_limit' : IDL.Opt(RateLimitConfig), + }); + return [IDL.Opt(InternetIdentityInit)]; +}; diff --git a/src/civic_sign_frontend_demo/src/declarations/relying_canister_frontend/index.d.ts b/src/civic_sign_frontend_demo/src/declarations/relying_canister_frontend/index.d.ts new file mode 100644 index 0000000..afc5848 --- /dev/null +++ b/src/civic_sign_frontend_demo/src/declarations/relying_canister_frontend/index.d.ts @@ -0,0 +1,50 @@ +import type { + ActorSubclass, + HttpAgentOptions, + ActorConfig, + Agent, +} from "@dfinity/agent"; +import type { Principal } from "@dfinity/principal"; +import type { IDL } from "@dfinity/candid"; + +import { _SERVICE } from './relying_canister_frontend.did'; + +export declare const idlFactory: IDL.InterfaceFactory; +export declare const canisterId: string; + +export declare interface CreateActorOptions { + /** + * @see {@link Agent} + */ + agent?: Agent; + /** + * @see {@link HttpAgentOptions} + */ + agentOptions?: HttpAgentOptions; + /** + * @see {@link ActorConfig} + */ + actorOptions?: ActorConfig; +} + +/** + * Intializes an {@link ActorSubclass}, configured with the provided SERVICE interface of a canister. + * @constructs {@link ActorSubClass} + * @param {string | Principal} canisterId - ID of the canister the {@link Actor} will talk to + * @param {CreateActorOptions} options - see {@link CreateActorOptions} + * @param {CreateActorOptions["agent"]} options.agent - a pre-configured agent you'd like to use. Supercedes agentOptions + * @param {CreateActorOptions["agentOptions"]} options.agentOptions - options to set up a new agent + * @see {@link HttpAgentOptions} + * @param {CreateActorOptions["actorOptions"]} options.actorOptions - options for the Actor + * @see {@link ActorConfig} + */ +export declare const createActor: ( + canisterId: string | Principal, + options?: CreateActorOptions +) => ActorSubclass<_SERVICE>; + +/** + * Intialized Actor using default settings, ready to talk to a canister using its candid interface + * @constructs {@link ActorSubClass} + */ +export declare const relying_canister_frontend: ActorSubclass<_SERVICE>; diff --git a/src/civic_sign_frontend_demo/src/declarations/relying_canister_frontend/index.js b/src/civic_sign_frontend_demo/src/declarations/relying_canister_frontend/index.js new file mode 100644 index 0000000..5e4feaa --- /dev/null +++ b/src/civic_sign_frontend_demo/src/declarations/relying_canister_frontend/index.js @@ -0,0 +1,42 @@ +import { Actor, HttpAgent } from "@dfinity/agent"; + +// Imports and re-exports candid interface +import { idlFactory } from "./relying_canister_frontend.did.js"; +export { idlFactory } from "./relying_canister_frontend.did.js"; + +/* CANISTER_ID is replaced by webpack based on node environment + * Note: canister environment variable will be standardized as + * process.env.CANISTER_ID_ + * beginning in dfx 0.15.0 + */ +export const canisterId = + process.env.CANISTER_ID_RELYING_CANISTER_FRONTEND; + +export const createActor = (canisterId, options = {}) => { + const agent = options.agent || new HttpAgent({ ...options.agentOptions }); + + if (options.agent && options.agentOptions) { + console.warn( + "Detected both agent and agentOptions passed to createActor. Ignoring agentOptions and proceeding with the provided agent." + ); + } + + // Fetch root key for certificate validation during development + if (process.env.DFX_NETWORK !== "ic") { + agent.fetchRootKey().catch((err) => { + console.warn( + "Unable to fetch root key. Check to ensure that your local replica is running" + ); + console.error(err); + }); + } + + // Creates an actor with using the candid interface and the HttpAgent + return Actor.createActor(idlFactory, { + agent, + canisterId, + ...options.actorOptions, + }); +}; + +export const relying_canister_frontend = canisterId ? createActor(canisterId) : undefined; diff --git a/src/civic_sign_frontend_demo/src/declarations/relying_canister_frontend/relying_canister_frontend.did b/src/civic_sign_frontend_demo/src/declarations/relying_canister_frontend/relying_canister_frontend.did new file mode 100644 index 0000000..51bb1a2 --- /dev/null +++ b/src/civic_sign_frontend_demo/src/declarations/relying_canister_frontend/relying_canister_frontend.did @@ -0,0 +1,262 @@ +type BatchId = nat; +type ChunkId = nat; +type Key = text; +type Time = int; + +type CreateAssetArguments = record { + key: Key; + content_type: text; + max_age: opt nat64; + headers: opt vec HeaderField; + enable_aliasing: opt bool; + allow_raw_access: opt bool; +}; + +// Add or change content for an asset, by content encoding +type SetAssetContentArguments = record { + key: Key; + content_encoding: text; + chunk_ids: vec ChunkId; + sha256: opt blob; +}; + +// Remove content for an asset, by content encoding +type UnsetAssetContentArguments = record { + key: Key; + content_encoding: text; +}; + +// Delete an asset +type DeleteAssetArguments = record { + key: Key; +}; + +// Reset everything +type ClearArguments = record {}; + +type BatchOperationKind = variant { + CreateAsset: CreateAssetArguments; + SetAssetContent: SetAssetContentArguments; + + SetAssetProperties: SetAssetPropertiesArguments; + + UnsetAssetContent: UnsetAssetContentArguments; + DeleteAsset: DeleteAssetArguments; + + Clear: ClearArguments; +}; + +type CommitBatchArguments = record { + batch_id: BatchId; + operations: vec BatchOperationKind +}; + +type CommitProposedBatchArguments = record { + batch_id: BatchId; + evidence: blob; +}; + +type ComputeEvidenceArguments = record { + batch_id: BatchId; + max_iterations: opt nat16 +}; + +type DeleteBatchArguments = record { + batch_id: BatchId; +}; + +type HeaderField = record { text; text; }; + +type HttpRequest = record { + method: text; + url: text; + headers: vec HeaderField; + body: blob; + certificate_version: opt nat16; +}; + +type HttpResponse = record { + status_code: nat16; + headers: vec HeaderField; + body: blob; + streaming_strategy: opt StreamingStrategy; +}; + +type StreamingCallbackHttpResponse = record { + body: blob; + token: opt StreamingCallbackToken; +}; + +type StreamingCallbackToken = record { + key: Key; + content_encoding: text; + index: nat; + sha256: opt blob; +}; + +type StreamingStrategy = variant { + Callback: record { + callback: func (StreamingCallbackToken) -> (opt StreamingCallbackHttpResponse) query; + token: StreamingCallbackToken; + }; +}; + +type SetAssetPropertiesArguments = record { + key: Key; + max_age: opt opt nat64; + headers: opt opt vec HeaderField; + allow_raw_access: opt opt bool; + is_aliased: opt opt bool; +}; + +type ConfigurationResponse = record { + max_batches: opt nat64; + max_chunks: opt nat64; + max_bytes: opt nat64; +}; + +type ConfigureArguments = record { + max_batches: opt opt nat64; + max_chunks: opt opt nat64; + max_bytes: opt opt nat64; +}; + +type Permission = variant { + Commit; + ManagePermissions; + Prepare; +}; + +type GrantPermission = record { + to_principal: principal; + permission: Permission; +}; +type RevokePermission = record { + of_principal: principal; + permission: Permission; +}; +type ListPermitted = record { permission: Permission }; + +type ValidationResult = variant { Ok : text; Err : text }; + +type AssetCanisterArgs = variant { + Init: InitArgs; + Upgrade: UpgradeArgs; +}; + +type InitArgs = record {}; + +type UpgradeArgs = record { + set_permissions: opt SetPermissions; +}; + +/// Sets the list of principals granted each permission. +type SetPermissions = record { + prepare: vec principal; + commit: vec principal; + manage_permissions: vec principal; +}; + +service: (asset_canister_args: opt AssetCanisterArgs) -> { + api_version: () -> (nat16) query; + + get: (record { + key: Key; + accept_encodings: vec text; + }) -> (record { + content: blob; // may be the entirety of the content, or just chunk index 0 + content_type: text; + content_encoding: text; + sha256: opt blob; // sha256 of entire asset encoding, calculated by dfx and passed in SetAssetContentArguments + total_length: nat; // all chunks except last have size == content.size() + }) query; + + // if get() returned chunks > 1, call this to retrieve them. + // chunks may or may not be split up at the same boundaries as presented to create_chunk(). + get_chunk: (record { + key: Key; + content_encoding: text; + index: nat; + sha256: opt blob; // sha256 of entire asset encoding, calculated by dfx and passed in SetAssetContentArguments + }) -> (record { content: blob }) query; + + list : (record {}) -> (vec record { + key: Key; + content_type: text; + encodings: vec record { + content_encoding: text; + sha256: opt blob; // sha256 of entire asset encoding, calculated by dfx and passed in SetAssetContentArguments + length: nat; // Size of this encoding's blob. Calculated when uploading assets. + modified: Time; + }; + }) query; + + certified_tree : (record {}) -> (record { + certificate: blob; + tree: blob; + }) query; + + create_batch : (record {}) -> (record { batch_id: BatchId }); + + create_chunk: (record { batch_id: BatchId; content: blob }) -> (record { chunk_id: ChunkId }); + + // Perform all operations successfully, or reject + commit_batch: (CommitBatchArguments) -> (); + + // Save the batch operations for later commit + propose_commit_batch: (CommitBatchArguments) -> (); + + // Given a batch already proposed, perform all operations successfully, or reject + commit_proposed_batch: (CommitProposedBatchArguments) -> (); + + // Compute a hash over the CommitBatchArguments. Call until it returns Some(evidence). + compute_evidence: (ComputeEvidenceArguments) -> (opt blob); + + // Delete a batch that has been created, or proposed for commit, but not yet committed + delete_batch: (DeleteBatchArguments) -> (); + + create_asset: (CreateAssetArguments) -> (); + set_asset_content: (SetAssetContentArguments) -> (); + unset_asset_content: (UnsetAssetContentArguments) -> (); + + delete_asset: (DeleteAssetArguments) -> (); + + clear: (ClearArguments) -> (); + + // Single call to create an asset with content for a single content encoding that + // fits within the message ingress limit. + store: (record { + key: Key; + content_type: text; + content_encoding: text; + content: blob; + sha256: opt blob + }) -> (); + + http_request: (request: HttpRequest) -> (HttpResponse) query; + http_request_streaming_callback: (token: StreamingCallbackToken) -> (opt StreamingCallbackHttpResponse) query; + + authorize: (principal) -> (); + deauthorize: (principal) -> (); + list_authorized: () -> (vec principal); + grant_permission: (GrantPermission) -> (); + revoke_permission: (RevokePermission) -> (); + list_permitted: (ListPermitted) -> (vec principal); + take_ownership: () -> (); + + get_asset_properties : (key: Key) -> (record { + max_age: opt nat64; + headers: opt vec HeaderField; + allow_raw_access: opt bool; + is_aliased: opt bool; } ) query; + set_asset_properties: (SetAssetPropertiesArguments) -> (); + + get_configuration: () -> (ConfigurationResponse); + configure: (ConfigureArguments) -> (); + + validate_grant_permission: (GrantPermission) -> (ValidationResult); + validate_revoke_permission: (RevokePermission) -> (ValidationResult); + validate_take_ownership: () -> (ValidationResult); + validate_commit_proposed_batch: (CommitProposedBatchArguments) -> (ValidationResult); + validate_configure: (ConfigureArguments) -> (ValidationResult); +} diff --git a/src/civic_sign_frontend_demo/src/declarations/relying_canister_frontend/relying_canister_frontend.did.d.ts b/src/civic_sign_frontend_demo/src/declarations/relying_canister_frontend/relying_canister_frontend.did.d.ts new file mode 100644 index 0000000..ce96468 --- /dev/null +++ b/src/civic_sign_frontend_demo/src/declarations/relying_canister_frontend/relying_canister_frontend.did.d.ts @@ -0,0 +1,240 @@ +import type { Principal } from '@dfinity/principal'; +import type { ActorMethod } from '@dfinity/agent'; +import type { IDL } from '@dfinity/candid'; + +export type AssetCanisterArgs = { 'Upgrade' : UpgradeArgs } | + { 'Init' : InitArgs }; +export type BatchId = bigint; +export type BatchOperationKind = { + 'SetAssetProperties' : SetAssetPropertiesArguments + } | + { 'CreateAsset' : CreateAssetArguments } | + { 'UnsetAssetContent' : UnsetAssetContentArguments } | + { 'DeleteAsset' : DeleteAssetArguments } | + { 'SetAssetContent' : SetAssetContentArguments } | + { 'Clear' : ClearArguments }; +export type ChunkId = bigint; +export type ClearArguments = {}; +export interface CommitBatchArguments { + 'batch_id' : BatchId, + 'operations' : Array, +} +export interface CommitProposedBatchArguments { + 'batch_id' : BatchId, + 'evidence' : Uint8Array | number[], +} +export interface ComputeEvidenceArguments { + 'batch_id' : BatchId, + 'max_iterations' : [] | [number], +} +export interface ConfigurationResponse { + 'max_batches' : [] | [bigint], + 'max_bytes' : [] | [bigint], + 'max_chunks' : [] | [bigint], +} +export interface ConfigureArguments { + 'max_batches' : [] | [[] | [bigint]], + 'max_bytes' : [] | [[] | [bigint]], + 'max_chunks' : [] | [[] | [bigint]], +} +export interface CreateAssetArguments { + 'key' : Key, + 'content_type' : string, + 'headers' : [] | [Array], + 'allow_raw_access' : [] | [boolean], + 'max_age' : [] | [bigint], + 'enable_aliasing' : [] | [boolean], +} +export interface DeleteAssetArguments { 'key' : Key } +export interface DeleteBatchArguments { 'batch_id' : BatchId } +export interface GrantPermission { + 'permission' : Permission, + 'to_principal' : Principal, +} +export type HeaderField = [string, string]; +export interface HttpRequest { + 'url' : string, + 'method' : string, + 'body' : Uint8Array | number[], + 'headers' : Array, + 'certificate_version' : [] | [number], +} +export interface HttpResponse { + 'body' : Uint8Array | number[], + 'headers' : Array, + 'streaming_strategy' : [] | [StreamingStrategy], + 'status_code' : number, +} +export type InitArgs = {}; +export type Key = string; +export interface ListPermitted { 'permission' : Permission } +export type Permission = { 'Prepare' : null } | + { 'ManagePermissions' : null } | + { 'Commit' : null }; +export interface RevokePermission { + 'permission' : Permission, + 'of_principal' : Principal, +} +export interface SetAssetContentArguments { + 'key' : Key, + 'sha256' : [] | [Uint8Array | number[]], + 'chunk_ids' : Array, + 'content_encoding' : string, +} +export interface SetAssetPropertiesArguments { + 'key' : Key, + 'headers' : [] | [[] | [Array]], + 'is_aliased' : [] | [[] | [boolean]], + 'allow_raw_access' : [] | [[] | [boolean]], + 'max_age' : [] | [[] | [bigint]], +} +export interface SetPermissions { + 'prepare' : Array, + 'commit' : Array, + 'manage_permissions' : Array, +} +export interface StreamingCallbackHttpResponse { + 'token' : [] | [StreamingCallbackToken], + 'body' : Uint8Array | number[], +} +export interface StreamingCallbackToken { + 'key' : Key, + 'sha256' : [] | [Uint8Array | number[]], + 'index' : bigint, + 'content_encoding' : string, +} +export type StreamingStrategy = { + 'Callback' : { + 'token' : StreamingCallbackToken, + 'callback' : [Principal, string], + } + }; +export type Time = bigint; +export interface UnsetAssetContentArguments { + 'key' : Key, + 'content_encoding' : string, +} +export interface UpgradeArgs { 'set_permissions' : [] | [SetPermissions] } +export type ValidationResult = { 'Ok' : string } | + { 'Err' : string }; +export interface _SERVICE { + 'api_version' : ActorMethod<[], number>, + 'authorize' : ActorMethod<[Principal], undefined>, + 'certified_tree' : ActorMethod< + [{}], + { 'certificate' : Uint8Array | number[], 'tree' : Uint8Array | number[] } + >, + 'clear' : ActorMethod<[ClearArguments], undefined>, + 'commit_batch' : ActorMethod<[CommitBatchArguments], undefined>, + 'commit_proposed_batch' : ActorMethod< + [CommitProposedBatchArguments], + undefined + >, + 'compute_evidence' : ActorMethod< + [ComputeEvidenceArguments], + [] | [Uint8Array | number[]] + >, + 'configure' : ActorMethod<[ConfigureArguments], undefined>, + 'create_asset' : ActorMethod<[CreateAssetArguments], undefined>, + 'create_batch' : ActorMethod<[{}], { 'batch_id' : BatchId }>, + 'create_chunk' : ActorMethod< + [{ 'content' : Uint8Array | number[], 'batch_id' : BatchId }], + { 'chunk_id' : ChunkId } + >, + 'deauthorize' : ActorMethod<[Principal], undefined>, + 'delete_asset' : ActorMethod<[DeleteAssetArguments], undefined>, + 'delete_batch' : ActorMethod<[DeleteBatchArguments], undefined>, + 'get' : ActorMethod< + [{ 'key' : Key, 'accept_encodings' : Array }], + { + 'content' : Uint8Array | number[], + 'sha256' : [] | [Uint8Array | number[]], + 'content_type' : string, + 'content_encoding' : string, + 'total_length' : bigint, + } + >, + 'get_asset_properties' : ActorMethod< + [Key], + { + 'headers' : [] | [Array], + 'is_aliased' : [] | [boolean], + 'allow_raw_access' : [] | [boolean], + 'max_age' : [] | [bigint], + } + >, + 'get_chunk' : ActorMethod< + [ + { + 'key' : Key, + 'sha256' : [] | [Uint8Array | number[]], + 'index' : bigint, + 'content_encoding' : string, + }, + ], + { 'content' : Uint8Array | number[] } + >, + 'get_configuration' : ActorMethod<[], ConfigurationResponse>, + 'grant_permission' : ActorMethod<[GrantPermission], undefined>, + 'http_request' : ActorMethod<[HttpRequest], HttpResponse>, + 'http_request_streaming_callback' : ActorMethod< + [StreamingCallbackToken], + [] | [StreamingCallbackHttpResponse] + >, + 'list' : ActorMethod< + [{}], + Array< + { + 'key' : Key, + 'encodings' : Array< + { + 'modified' : Time, + 'sha256' : [] | [Uint8Array | number[]], + 'length' : bigint, + 'content_encoding' : string, + } + >, + 'content_type' : string, + } + > + >, + 'list_authorized' : ActorMethod<[], Array>, + 'list_permitted' : ActorMethod<[ListPermitted], Array>, + 'propose_commit_batch' : ActorMethod<[CommitBatchArguments], undefined>, + 'revoke_permission' : ActorMethod<[RevokePermission], undefined>, + 'set_asset_content' : ActorMethod<[SetAssetContentArguments], undefined>, + 'set_asset_properties' : ActorMethod< + [SetAssetPropertiesArguments], + undefined + >, + 'store' : ActorMethod< + [ + { + 'key' : Key, + 'content' : Uint8Array | number[], + 'sha256' : [] | [Uint8Array | number[]], + 'content_type' : string, + 'content_encoding' : string, + }, + ], + undefined + >, + 'take_ownership' : ActorMethod<[], undefined>, + 'unset_asset_content' : ActorMethod<[UnsetAssetContentArguments], undefined>, + 'validate_commit_proposed_batch' : ActorMethod< + [CommitProposedBatchArguments], + ValidationResult + >, + 'validate_configure' : ActorMethod<[ConfigureArguments], ValidationResult>, + 'validate_grant_permission' : ActorMethod< + [GrantPermission], + ValidationResult + >, + 'validate_revoke_permission' : ActorMethod< + [RevokePermission], + ValidationResult + >, + 'validate_take_ownership' : ActorMethod<[], ValidationResult>, +} +export declare const idlFactory: IDL.InterfaceFactory; +export declare const init: (args: { IDL: typeof IDL }) => IDL.Type[]; diff --git a/src/civic_sign_frontend_demo/src/declarations/relying_canister_frontend/relying_canister_frontend.did.js b/src/civic_sign_frontend_demo/src/declarations/relying_canister_frontend/relying_canister_frontend.did.js new file mode 100644 index 0000000..b68ea4a --- /dev/null +++ b/src/civic_sign_frontend_demo/src/declarations/relying_canister_frontend/relying_canister_frontend.did.js @@ -0,0 +1,286 @@ +export const idlFactory = ({ IDL }) => { + const SetPermissions = IDL.Record({ + 'prepare' : IDL.Vec(IDL.Principal), + 'commit' : IDL.Vec(IDL.Principal), + 'manage_permissions' : IDL.Vec(IDL.Principal), + }); + const UpgradeArgs = IDL.Record({ + 'set_permissions' : IDL.Opt(SetPermissions), + }); + const InitArgs = IDL.Record({}); + const AssetCanisterArgs = IDL.Variant({ + 'Upgrade' : UpgradeArgs, + 'Init' : InitArgs, + }); + const ClearArguments = IDL.Record({}); + const BatchId = IDL.Nat; + const Key = IDL.Text; + const HeaderField = IDL.Tuple(IDL.Text, IDL.Text); + const SetAssetPropertiesArguments = IDL.Record({ + 'key' : Key, + 'headers' : IDL.Opt(IDL.Opt(IDL.Vec(HeaderField))), + 'is_aliased' : IDL.Opt(IDL.Opt(IDL.Bool)), + 'allow_raw_access' : IDL.Opt(IDL.Opt(IDL.Bool)), + 'max_age' : IDL.Opt(IDL.Opt(IDL.Nat64)), + }); + const CreateAssetArguments = IDL.Record({ + 'key' : Key, + 'content_type' : IDL.Text, + 'headers' : IDL.Opt(IDL.Vec(HeaderField)), + 'allow_raw_access' : IDL.Opt(IDL.Bool), + 'max_age' : IDL.Opt(IDL.Nat64), + 'enable_aliasing' : IDL.Opt(IDL.Bool), + }); + const UnsetAssetContentArguments = IDL.Record({ + 'key' : Key, + 'content_encoding' : IDL.Text, + }); + const DeleteAssetArguments = IDL.Record({ 'key' : Key }); + const ChunkId = IDL.Nat; + const SetAssetContentArguments = IDL.Record({ + 'key' : Key, + 'sha256' : IDL.Opt(IDL.Vec(IDL.Nat8)), + 'chunk_ids' : IDL.Vec(ChunkId), + 'content_encoding' : IDL.Text, + }); + const BatchOperationKind = IDL.Variant({ + 'SetAssetProperties' : SetAssetPropertiesArguments, + 'CreateAsset' : CreateAssetArguments, + 'UnsetAssetContent' : UnsetAssetContentArguments, + 'DeleteAsset' : DeleteAssetArguments, + 'SetAssetContent' : SetAssetContentArguments, + 'Clear' : ClearArguments, + }); + const CommitBatchArguments = IDL.Record({ + 'batch_id' : BatchId, + 'operations' : IDL.Vec(BatchOperationKind), + }); + const CommitProposedBatchArguments = IDL.Record({ + 'batch_id' : BatchId, + 'evidence' : IDL.Vec(IDL.Nat8), + }); + const ComputeEvidenceArguments = IDL.Record({ + 'batch_id' : BatchId, + 'max_iterations' : IDL.Opt(IDL.Nat16), + }); + const ConfigureArguments = IDL.Record({ + 'max_batches' : IDL.Opt(IDL.Opt(IDL.Nat64)), + 'max_bytes' : IDL.Opt(IDL.Opt(IDL.Nat64)), + 'max_chunks' : IDL.Opt(IDL.Opt(IDL.Nat64)), + }); + const DeleteBatchArguments = IDL.Record({ 'batch_id' : BatchId }); + const ConfigurationResponse = IDL.Record({ + 'max_batches' : IDL.Opt(IDL.Nat64), + 'max_bytes' : IDL.Opt(IDL.Nat64), + 'max_chunks' : IDL.Opt(IDL.Nat64), + }); + const Permission = IDL.Variant({ + 'Prepare' : IDL.Null, + 'ManagePermissions' : IDL.Null, + 'Commit' : IDL.Null, + }); + const GrantPermission = IDL.Record({ + 'permission' : Permission, + 'to_principal' : IDL.Principal, + }); + const HttpRequest = IDL.Record({ + 'url' : IDL.Text, + 'method' : IDL.Text, + 'body' : IDL.Vec(IDL.Nat8), + 'headers' : IDL.Vec(HeaderField), + 'certificate_version' : IDL.Opt(IDL.Nat16), + }); + const StreamingCallbackToken = IDL.Record({ + 'key' : Key, + 'sha256' : IDL.Opt(IDL.Vec(IDL.Nat8)), + 'index' : IDL.Nat, + 'content_encoding' : IDL.Text, + }); + const StreamingCallbackHttpResponse = IDL.Record({ + 'token' : IDL.Opt(StreamingCallbackToken), + 'body' : IDL.Vec(IDL.Nat8), + }); + const StreamingStrategy = IDL.Variant({ + 'Callback' : IDL.Record({ + 'token' : StreamingCallbackToken, + 'callback' : IDL.Func( + [StreamingCallbackToken], + [IDL.Opt(StreamingCallbackHttpResponse)], + ['query'], + ), + }), + }); + const HttpResponse = IDL.Record({ + 'body' : IDL.Vec(IDL.Nat8), + 'headers' : IDL.Vec(HeaderField), + 'streaming_strategy' : IDL.Opt(StreamingStrategy), + 'status_code' : IDL.Nat16, + }); + const Time = IDL.Int; + const ListPermitted = IDL.Record({ 'permission' : Permission }); + const RevokePermission = IDL.Record({ + 'permission' : Permission, + 'of_principal' : IDL.Principal, + }); + const ValidationResult = IDL.Variant({ 'Ok' : IDL.Text, 'Err' : IDL.Text }); + return IDL.Service({ + 'api_version' : IDL.Func([], [IDL.Nat16], ['query']), + 'authorize' : IDL.Func([IDL.Principal], [], []), + 'certified_tree' : IDL.Func( + [IDL.Record({})], + [ + IDL.Record({ + 'certificate' : IDL.Vec(IDL.Nat8), + 'tree' : IDL.Vec(IDL.Nat8), + }), + ], + ['query'], + ), + 'clear' : IDL.Func([ClearArguments], [], []), + 'commit_batch' : IDL.Func([CommitBatchArguments], [], []), + 'commit_proposed_batch' : IDL.Func([CommitProposedBatchArguments], [], []), + 'compute_evidence' : IDL.Func( + [ComputeEvidenceArguments], + [IDL.Opt(IDL.Vec(IDL.Nat8))], + [], + ), + 'configure' : IDL.Func([ConfigureArguments], [], []), + 'create_asset' : IDL.Func([CreateAssetArguments], [], []), + 'create_batch' : IDL.Func( + [IDL.Record({})], + [IDL.Record({ 'batch_id' : BatchId })], + [], + ), + 'create_chunk' : IDL.Func( + [IDL.Record({ 'content' : IDL.Vec(IDL.Nat8), 'batch_id' : BatchId })], + [IDL.Record({ 'chunk_id' : ChunkId })], + [], + ), + 'deauthorize' : IDL.Func([IDL.Principal], [], []), + 'delete_asset' : IDL.Func([DeleteAssetArguments], [], []), + 'delete_batch' : IDL.Func([DeleteBatchArguments], [], []), + 'get' : IDL.Func( + [IDL.Record({ 'key' : Key, 'accept_encodings' : IDL.Vec(IDL.Text) })], + [ + IDL.Record({ + 'content' : IDL.Vec(IDL.Nat8), + 'sha256' : IDL.Opt(IDL.Vec(IDL.Nat8)), + 'content_type' : IDL.Text, + 'content_encoding' : IDL.Text, + 'total_length' : IDL.Nat, + }), + ], + ['query'], + ), + 'get_asset_properties' : IDL.Func( + [Key], + [ + IDL.Record({ + 'headers' : IDL.Opt(IDL.Vec(HeaderField)), + 'is_aliased' : IDL.Opt(IDL.Bool), + 'allow_raw_access' : IDL.Opt(IDL.Bool), + 'max_age' : IDL.Opt(IDL.Nat64), + }), + ], + ['query'], + ), + 'get_chunk' : IDL.Func( + [ + IDL.Record({ + 'key' : Key, + 'sha256' : IDL.Opt(IDL.Vec(IDL.Nat8)), + 'index' : IDL.Nat, + 'content_encoding' : IDL.Text, + }), + ], + [IDL.Record({ 'content' : IDL.Vec(IDL.Nat8) })], + ['query'], + ), + 'get_configuration' : IDL.Func([], [ConfigurationResponse], []), + 'grant_permission' : IDL.Func([GrantPermission], [], []), + 'http_request' : IDL.Func([HttpRequest], [HttpResponse], ['query']), + 'http_request_streaming_callback' : IDL.Func( + [StreamingCallbackToken], + [IDL.Opt(StreamingCallbackHttpResponse)], + ['query'], + ), + 'list' : IDL.Func( + [IDL.Record({})], + [ + IDL.Vec( + IDL.Record({ + 'key' : Key, + 'encodings' : IDL.Vec( + IDL.Record({ + 'modified' : Time, + 'sha256' : IDL.Opt(IDL.Vec(IDL.Nat8)), + 'length' : IDL.Nat, + 'content_encoding' : IDL.Text, + }) + ), + 'content_type' : IDL.Text, + }) + ), + ], + ['query'], + ), + 'list_authorized' : IDL.Func([], [IDL.Vec(IDL.Principal)], []), + 'list_permitted' : IDL.Func([ListPermitted], [IDL.Vec(IDL.Principal)], []), + 'propose_commit_batch' : IDL.Func([CommitBatchArguments], [], []), + 'revoke_permission' : IDL.Func([RevokePermission], [], []), + 'set_asset_content' : IDL.Func([SetAssetContentArguments], [], []), + 'set_asset_properties' : IDL.Func([SetAssetPropertiesArguments], [], []), + 'store' : IDL.Func( + [ + IDL.Record({ + 'key' : Key, + 'content' : IDL.Vec(IDL.Nat8), + 'sha256' : IDL.Opt(IDL.Vec(IDL.Nat8)), + 'content_type' : IDL.Text, + 'content_encoding' : IDL.Text, + }), + ], + [], + [], + ), + 'take_ownership' : IDL.Func([], [], []), + 'unset_asset_content' : IDL.Func([UnsetAssetContentArguments], [], []), + 'validate_commit_proposed_batch' : IDL.Func( + [CommitProposedBatchArguments], + [ValidationResult], + [], + ), + 'validate_configure' : IDL.Func( + [ConfigureArguments], + [ValidationResult], + [], + ), + 'validate_grant_permission' : IDL.Func( + [GrantPermission], + [ValidationResult], + [], + ), + 'validate_revoke_permission' : IDL.Func( + [RevokePermission], + [ValidationResult], + [], + ), + 'validate_take_ownership' : IDL.Func([], [ValidationResult], []), + }); +}; +export const init = ({ IDL }) => { + const SetPermissions = IDL.Record({ + 'prepare' : IDL.Vec(IDL.Principal), + 'commit' : IDL.Vec(IDL.Principal), + 'manage_permissions' : IDL.Vec(IDL.Principal), + }); + const UpgradeArgs = IDL.Record({ + 'set_permissions' : IDL.Opt(SetPermissions), + }); + const InitArgs = IDL.Record({}); + const AssetCanisterArgs = IDL.Variant({ + 'Upgrade' : UpgradeArgs, + 'Init' : InitArgs, + }); + return [IDL.Opt(AssetCanisterArgs)]; +}; diff --git a/src/civic_sign_frontend_demo/src/service/CredentialService.ts b/src/civic_sign_frontend_demo/src/service/CredentialService.ts index dbafe0c..8e1d6ed 100644 --- a/src/civic_sign_frontend_demo/src/service/CredentialService.ts +++ b/src/civic_sign_frontend_demo/src/service/CredentialService.ts @@ -1,7 +1,7 @@ // src/service/CredentialService.ts import { Actor, HttpAgent } from "@dfinity/agent"; -import { idlFactory as civic } from "../../../declarations/civic_canister_backend/civic_canister_backend.did.js"; +import { idlFactory as civic } from "../declarations/civic_canister_backend/civic_canister_backend.did.js"; import { Principal } from "@dfinity/principal"; import { requestVerifiablePresentation } from "@dfinity/verifiable-credentials/request-verifiable-presentation";