expo-ii-integration
Version:
Expo library to enable smartphone native applications to invoke Internet Identity through a web application
157 lines (146 loc) • 6.23 kB
TypeScript
import { CryptoModule } from 'expo-crypto-universal';
import { DeepLinkType } from 'expo-icp-frontend-helpers';
import { default as default_2 } from 'react';
import { DelegationChain } from '@dfinity/identity';
import { Ed25519KeyIdentity } from '@dfinity/identity';
import { Identity } from '@dfinity/agent';
import { JSX } from 'react/jsx-runtime';
import { OpenBrowserOptions } from 'expo-icp-app-connect';
import { Storage as Storage_2 } from 'expo-storage-universal';
import { StorageWrapper } from 'expo-storage-universal';
/**
* A storage wrapper implementation for DelegationChain that handles serialization, deserialization, and validation.
* This wrapper provides a type-safe way to store and retrieve DelegationChain instances in a storage system,
* with automatic validation of delegation chains to ensure they are still valid.
*/
export declare class DelegationChainValueStorageWrapper implements StorageWrapper<DelegationChain> {
private storage;
private key;
/**
* Creates a new instance of DelegationChainValueStorageWrapper.
* @param storage - The storage implementation to use for persistence
* @param key - The key under which the DelegationChain will be stored
*/
constructor(storage: Storage_2, key: string);
/**
* Attempts to find and retrieve a DelegationChain from storage.
* If the stored delegation chain is invalid, it will be automatically removed from storage.
* @returns A Promise that resolves to the found DelegationChain or undefined if not found or invalid
*/
find(): Promise<DelegationChain | undefined>;
/**
* Retrieves a DelegationChain from storage, throwing an error if not found or invalid.
* @returns A Promise that resolves to the found and valid DelegationChain
* @throws {Error} If no valid DelegationChain is found for the configured key
*/
retrieve(): Promise<DelegationChain>;
/**
* Saves a DelegationChain to storage.
* @param value - The DelegationChain to save
* @returns A Promise that resolves when the save operation is complete
*/
save(value: DelegationChain): Promise<void>;
/**
* Removes the stored DelegationChain from storage.
* @returns A Promise that resolves when the removal operation is complete
*/
remove(): Promise<void>;
}
/**
* A storage wrapper implementation for Ed25519KeyIdentity that handles serialization and deserialization.
* This wrapper provides a type-safe way to store and retrieve Ed25519KeyIdentity instances in a storage system.
*/
export declare class Ed25519KeyIdentityValueStorageWrapper implements StorageWrapper<Ed25519KeyIdentity> {
private storage;
private key;
/**
* Creates a new instance of Ed25519KeyIdentityValueStorageWrapper.
* @param storage - The storage implementation to use for persistence
* @param key - The key under which the Ed25519KeyIdentity will be stored
*/
constructor(storage: Storage_2, key: string);
/**
* Attempts to find and retrieve an Ed25519KeyIdentity from storage.
* @returns A Promise that resolves to the found Ed25519KeyIdentity or undefined if not found
*/
find(): Promise<Ed25519KeyIdentity | undefined>;
/**
* Retrieves an Ed25519KeyIdentity from storage, throwing an error if not found.
* @returns A Promise that resolves to the found Ed25519KeyIdentity
* @throws {Error} If no Ed25519KeyIdentity is found for the configured key
*/
retrieve(): Promise<Ed25519KeyIdentity>;
/**
* Saves an Ed25519KeyIdentity to storage.
* @param value - The Ed25519KeyIdentity to save
* @returns A Promise that resolves when the save operation is complete
*/
save(value: Ed25519KeyIdentity): Promise<void>;
/**
* Removes the stored Ed25519KeyIdentity from storage.
* @returns A Promise that resolves when the removal operation is complete
*/
remove(): Promise<void>;
}
export declare const IIIntegrationProvider: ({ children, value, }: IIIntegrationProviderProps) => JSX.Element;
declare interface IIIntegrationProviderProps {
children: default_2.ReactNode;
value: IIIntegrationType;
}
/**
* Represents the return value of the useIIIntegration hook and IIIntegrationContext.
*/
declare type IIIntegrationType = {
isAuthReady: boolean;
isAuthenticated: boolean;
getIdentity: () => Promise<Identity>;
login: (loginOuterParams?: LoginOuterParams) => Promise<void>;
logout: () => Promise<void>;
authError: unknown | undefined;
clearAuthError: () => void;
};
/**
* Represents the outer parameters for the login function.
* @property {string} [redirectPath] - The path to redirect to after login, if any.
*/
declare type LoginOuterParams = {
redirectPath?: string;
openBrowserOptions?: OpenBrowserOptions;
};
/**
* Hook for managing II integration.
*
* This hook initializes the II integration process, handles URL changes for login callbacks,
* and provides functions for logging in and out. It also manages the redirect path after login.
*
* @param {UseIIIntegrationParams} params - The parameters required for the II integration.
* @returns {IIIntegrationType} An object containing the current identity, authentication status, login function, logout function, and any authentication error.
*/
export declare const useIIIntegration: ({ iiIntegrationUrl, deepLinkType, secureStorage, regularStorage, cryptoModule, }: UseIIIntegrationParams) => IIIntegrationType;
export declare const useIIIntegrationContext: () => IIIntegrationType;
/**
* Parameters for the useIIIntegration hook.
*/
declare type UseIIIntegrationParams = {
/**
* The II integration URL.
*/
iiIntegrationUrl: URL;
/**
* The deep link type.
*/
deepLinkType: DeepLinkType;
/**
* The secure storage.
*/
secureStorage: Storage_2;
/**
* The regular storage.
*/
regularStorage: Storage_2;
/**
* The crypto module.
*/
cryptoModule: CryptoModule;
};
export { }