import type { CustomAuthArgs } from "@toruslabs/customauth" ; import BN from "bn.js" ; import { Point , Polynomial , PublicPolynomial , PublicPolynomialMap , PublicShare , PublicSharePolyIDShareIndexMap , Share , ShareMap , ShareStore , ShareStoreMap , ShareStorePolyIDShareIndexMap , } from "../base" ; import { BNString , EncryptedMessage , ISerializable , IServiceProvider , IStorageLayer , PolyIDAndShares , PolynomialID , ShareDescriptionMap , } from "./commonTypes" ; export interface IModule { moduleName : string ; setModuleReferences ( api ) : void ; initialize ( ) : Promise < void > ; } export type ModuleMap = { [ moduleName ] : IModule ; } ; export type RefreshMiddlewareMap = { [ moduleName ] : ( generalStore : unknown , oldShareStores : ShareStoreMap , newShareStores : ShareStoreMap ) => unknown ; } ; export type ReconstructKeyMiddlewareMap = { [ moduleName ] : ( ) => Promise < BN [ ] > ; } ; export type ShareSerializationMiddleware = { serialize : ( share : BN , type : string ) => Promise < unknown > ; deserialize : ( serializedShare : unknown , type : string ) => Promise < BN > ; } ; export interface IMetadata extends ISerializable { pubKey : Point ; publicPolynomials : PublicPolynomialMap ; publicShares : PublicSharePolyIDShareIndexMap ; polyIDList : PolyIDAndShares [ ] ; generalStore : { [ moduleName ] : unknown ; } ; tkeyStore : { [ moduleName ] : unknown ; } ; scopedStore : { [ moduleName ] : unknown ; } ; nonce : number ; getShareIndexesForPolynomial ( polyID ) : string [ ] ; getLatestPublicPolynomial ( ) : PublicPolynomial ; addPublicShare ( polynomialID , publicShare ) : void ; setGeneralStoreDomain ( key , obj ) : void ; getGeneralStoreDomain ( key ) : unknown ; deleteGeneralStoreDomain ( key ) : unknown ; setTkeyStoreDomain ( key , arr ) : void ; getTkeyStoreDomain ( key ) : unknown ; addFromPolynomialAndShares ( polynomial , shares ) : void ; setScopedStore ( domain , data ) : void ; getEncryptedShare ( shareStore ) : Promise < ShareStore > ; getShareDescription ( ) : ShareDescriptionMap ; shareToShareStore ( share ) : ShareStore ; addShareDescription ( shareIndex , description ) : void ; deleteShareDescription ( shareIndex , description ) : void ; updateShareDescription ( shareIndex , oldDescription , newDescription ) : void ; clone ( ) : IMetadata ; } export type InitializeNewKeyResult = { privKey : BN ; deviceShare ? : ShareStore ; userShare ? : ShareStore ; } ; export type ReconstructedKeyResult = { privKey : BN ; seedPhrase ? : BN [ ] ; allKeys ? : BN [ ] ; } ; export type CatchupToLatestShareResult = { latestShare : ShareStore ; shareMetadata : IMetadata ; } ; export type GenerateNewShareResult = { newShareStores : ShareStoreMap ; newShareIndex : BN ; } ; export type DeleteShareResult = { newShareStores : ShareStoreMap ; } ; export type RefreshSharesResult = { shareStores : ShareStoreMap ; } ; export type KeyDetails = { pubKey : Point ; requiredShares : number ; threshold : number ; totalShares : number ; shareDescriptions : ShareDescriptionMap ; } ; export type TKeyArgs = { enableLogging ? : boolean ; modules ? : ModuleMap ; serviceProvider ? : IServiceProvider ; storageLayer ? : IStorageLayer ; directParams ? : CustomAuthArgs ; manualSync ? : boolean ; serverTimeOffset ? : number ; } ; export interface SecurityQuestionStoreArgs { nonce : BNString ; shareIndex : BNString ; sqPublicShare : PublicShare ; polynomialID : PolynomialID ; questions : string ; } export interface TkeyStoreDataArgs { [ key ] : unknown ; } export interface TkeyStoreArgs { data : TkeyStoreDataArgs ; } export interface ShareTransferStorePointerArgs { pointer : BNString ; } export type BufferObj = { type : string ; data : number [ ] ; } ; export interface ShareRequestArgs { encPubKey : unknown ; encShareInTransit : EncryptedMessage ; availableShareIndexes : string [ ] ; userAgent : string ; userIp : string ; timestamp : number ; } export type TkeyStoreItemType = { id : string ; } ; export type ISeedPhraseStore = TkeyStoreItemType & { seedPhrase : string ; type : string ; } ; export type ISQAnswerStore = TkeyStoreItemType & { answer : string ; } ; export type ISeedPhraseStoreWithKeys = ISeedPhraseStore & { keys : BN [ ] ; } ; export type MetamaskSeedPhraseStore = ISeedPhraseStore & { numberOfWallets : number ; } ; export type IPrivateKeyStore = TkeyStoreItemType & { privateKey : BN ; type : string ; } ; export type SECP256k1NStore = IPrivateKeyStore ; export interface ISeedPhraseFormat { type : string ; validateSeedPhrase ( seedPhrase ) : boolean ; deriveKeysFromSeedPhrase ( seedPhraseStore ) : Promise < BN [ ] > ; createSeedPhraseStore ( seedPhrase ? ) : Promise < ISeedPhraseStore > ; } export interface IPrivateKeyFormat { privateKey : BN ; type : string ; validatePrivateKey ( privateKey ) : boolean ; createPrivateKeyStore ( privateKey ) : SECP256k1NStore ; } export interface IAuthMetadata { metadata : IMetadata ; privKey : BN ; } export interface IMessageMetadata { message : string ; dateAdded ? : number ; } export type IAuthMetadatas = IAuthMetadata [ ] ; export type ShareStores = ShareStore [ ] ; export type IMessageMetadatas = IMessageMetadata [ ] ; export type LocalTransitionShares = BN [ ] ; export type LocalTransitionData = [ ... IAuthMetadatas , ... ShareStores , ... IMessageMetadatas ] ; export type LocalMetadataTransitions = [ LocalTransitionShares , LocalTransitionData ] ; export interface ITKeyApi { getMetadata ( ) : IMetadata ; getStorageLayer ( ) : IStorageLayer ; initialize ( params ) : Promise < KeyDetails > ; catchupToLatestShare ( params ) : Promise < CatchupToLatestShareResult > ; _syncShareMetadata ( adjustScopedStore ? ) : Promise < void > ; inputShareStoreSafe ( shareStore , autoUpdateMetadata ? ) : Promise < void > ; _setDeviceStorage ( storeDeviceStorage ) : void ; addShareDescription ( shareIndex , description , updateMetadata ? ) : Promise < void > ; _addRefreshMiddleware ( moduleName , middleware ) : void ; _addReconstructKeyMiddleware ( moduleName , middleware ) : void ; _addShareSerializationMiddleware ( serialize , deserialize ) : void ; generateNewShare ( ) : Promise < GenerateNewShareResult > ; outputShareStore ( shareIndex , polyID ? ) : ShareStore ; inputShare ( share , type ? ) : Promise < void > ; outputShare ( shareIndex , type ? ) : Promise < unknown > ; inputShareStore ( shareStore ) : void ; deleteShare ( shareIndex ) : Promise < DeleteShareResult > ; encrypt ( data ) : Promise < EncryptedMessage > ; decrypt ( encryptedMesage ) : Promise < Buffer > ; getTKeyStoreItem ( moduleName , id ) : Promise < TkeyStoreItemType > ; getTKeyStore ( moduleName ) : Promise < TkeyStoreItemType [ ] > ; _deleteTKeyStoreItem ( moduleName , id ) : Promise < void > ; _setTKeyStoreItem ( moduleName , data , updateMetadata ? ) : Promise < void > ; } export interface ITKey extends ITKeyApi , ISerializable { modules : ModuleMap ; enableLogging : boolean ; serviceProvider : IServiceProvider ; shares : ShareStorePolyIDShareIndexMap ; privKey : BN ; _localMetadataTransitions : LocalMetadataTransitions ; manualSync : boolean ; _refreshMiddleware : RefreshMiddlewareMap ; _reconstructKeyMiddleware : ReconstructKeyMiddlewareMap ; _shareSerializationMiddleware : ShareSerializationMiddleware ; initialize ( params ) : Promise < KeyDetails > ; reconstructKey ( ) : Promise < ReconstructedKeyResult > ; reconstructLatestPoly ( ) : Polynomial ; _refreshShares ( threshold , newShareIndexes , previousPolyID ) : Promise < RefreshSharesResult > ; _initializeNewKey ( params ) : Promise < InitializeNewKeyResult > ; _setKey ( privKey ) : void ; getKeyDetails ( ) : KeyDetails ; }