All files / src/factories legacyWalletFactories.ts

75% Statements 21/28
0% Branches 0/1
69.56% Functions 16/23
74.07% Lines 20/27

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293    1x 1x       1x       2x   2x                 1x                                                                                   5x                                     1x                       1x                     3x                       3x                       18x                                             2x                               24x                                                                       12x                                               7x                       9x                                   7x                                           1x             50x        
import { EventComponent } from '@affinidi/affinity-metrics-lib'
 
import { LegacyNetworkMemberWithFactories as Wallet } from '../CommonNetworkMember/LegacyNetworkMemberWithFactories'
import { Util } from '../CommonNetworkMember/Util'
import { KeyParams, MessageParameters, SdkOptions } from '../dto/shared.dto'
import { IPlatformCryptographyTools } from '../shared/interfaces'
 
export const createLegacyWalletFactories = (
  platformCryptographyTools: IPlatformCryptographyTools,
  eventComponent: EventComponent,
) => {
  const dependencies = { platformCryptographyTools, eventComponent }
 
  return {
    /**
     * @description Checks if registration for the user was completed
     * @param username - a valid email, phone number or arbitrary username
     * @param options - object with environment, dev is default { env: 'dev' }
     * @returns `true` if user is uncofirmed in Cognito, and `false` otherwise.
     * @deprecated
     */
    isUserUnconfirmed: (username: string, options: SdkOptions) => {
      return Wallet.isUserUnconfirmed(username, options)
    },
 
    /**
     * @description Initilizes instance of SDK from seed
     * @param seedHexWithMethod - seed for derive keys in string hex format
     * @param options - optional parameter { registryUrl: 'https://affinity-registry.apse1.dev.affinidi.io' }
     * @param password - optional password, will be generated, if not provided
     * @returns initialized instance of SDK
     * @deprecated
     */
    fromSeed: (seedHexWithMethod: string, options: SdkOptions, password: string = null) => {
      return Wallet.fromSeed(dependencies, seedHexWithMethod, options, password)
    },
 
    /**
     * @description Parses JWT and returns DID
     * @param jwt
     * @returns DID of entity who signed JWT
     * @deprecated use `Util` instead
     */
    getDidFromToken: (jwt: string) => {
      return Util.getDidFromToken(jwt)
    },
 
    /**
     * @description Creates DID and anchors it
     * 1. generate seed/keys
     * 2. build DID document
     * 3. sign DID document
     * 4. store DID document in IPFS
     * 5. anchor DID with DID document ID from IPFS
     * @param password - encryption key which will be used to encrypt randomly created seed/keys pair
     * @param options - optional parameter { registryUrl: 'https://affinity-registry.apse1.dev.affinidi.io' }
     * @returns
     *
     * did - hash from public key (your decentralized ID)
     *
     * encryptedSeed - seed is encrypted by provided password. Seed - it's a source to derive your keys
     * @deprecated Use `createWallet` instead
     */
    register: (password: string, options: SdkOptions) => {
      return Wallet.register(dependencies, options, password)
    },
 
    /**
     * @deprecated
     */
    anchorDid: (encryptedSeed: string, password: string, didDocument: any, nonce: number, options: SdkOptions) => {
      return Wallet.anchorDid(encryptedSeed, password, didDocument, nonce, options)
    },
 
    /**
     * @description Initiates passwordless login to Affinity
     * @param username - email/phoneNumber, registered in Cognito
     * @param options - optional parameters with specified environment
     * @param messageParameters - optional parameters with specified welcome message
     * @returns token
     * @deprecated use `initiateLogInPasswordless` instead
     */
    passwordlessLogin: (login: string, options: SdkOptions, messageParameters?: MessageParameters) => {
      return Wallet.passwordlessLogin(login, options, messageParameters)
    },
 
    /**
     * @description Completes login
     * @param token - received from #passwordlessLogin method
     * @param confirmationCode - OTP sent by AWS Cognito/SES
     * @param options - optional parameters for CommonNetworkMember initialization
     * @returns initialized instance of SDK
     * @deprecated use `completeLogInPasswordless` instead
     */
    completeLoginChallenge: (token: string, confirmationCode: string, inputOptions: SdkOptions) => {
      return Wallet.completeLoginChallenge(dependencies, token, confirmationCode, inputOptions)
    },
 
    /**
     * @description Initiates reset password flow
     * @param username - email/phoneNumber, registered in Cognito
     * @param options - optional parameters with specified environment
     * @param messageParameters - optional parameters with specified welcome message
     * @deprecated use `initiateForgotPassword` instead
     */
    forgotPassword: (login: string, options: SdkOptions, messageParameters?: MessageParameters) => {
      return Wallet.forgotPassword(login, options, messageParameters)
    },
 
    /**
     * @description Completes reset password flow
     * @param username - email/phoneNumber, registered in Cognito
     * @param confirmationCode - OTP sent by AWS Cognito/SES
     * @param newPassword - new password
     * @param options - optional parameters with specified environment
     * @deprecated use `completeForgotPassword` instead
     */
    forgotPasswordSubmit: (login: string, confirmationCode: string, newPassword: string, options: SdkOptions) => {
      return Wallet.forgotPasswordSubmit(login, confirmationCode, newPassword, options)
    },
 
    /**
     * @description Logins to Affinity with login and password
     * @param username - email/phoneNumber, registered in Cognito
     * @param password - password for Cognito user
     * @param options - optional parameters for CommonNetworkMember initialization
     * @returns initialized instance of SDK
     * @deprecated use `logInWithPassword` instead
     */
    fromLoginAndPassword: (username: string, password: string, inputOptions: SdkOptions) => {
      return Wallet.fromLoginAndPassword(dependencies, username, password, inputOptions)
    },
 
    /**
     * @description Initiates sign up flow to Affinity wallet with already created did
     * @param keyParams - { ecnryptedSeed, password } - previously created keys to be storead at wallet.
     * @param username - arbitrary username, email or phoneNumber
     * @param password - is required if arbitrary username was provided.
     * It is optional and random one will be generated, if not provided when
     * email or phoneNumber was given as a username.
     * @param options - optional parameters with specified environment
     * @param messageParameters - optional parameters with specified welcome message
     * @returns token or, in case when arbitrary username was used, it returns
     * initialized instance of SDK
     * @deprecated use `signUpWithUsername`, `initiateSignUpByEmail` or `initiateSignUpByPhone` instead
     */
    signUpWithExistsEntity: (
      keyParams: KeyParams,
      login: string,
      password: string,
      options: SdkOptions,
      messageParameters?: MessageParameters,
    ) => {
      return Wallet.signUpWithExistsEntity(dependencies, keyParams, login, password, options, messageParameters)
    },
 
    /**
     * @description Initiates sign up flow
     * @param username - arbitrary username, email or phoneNumber
     * @param password - is required if arbitrary username was provided.
     * It is optional and random one will be generated, if not provided when
     * email or phoneNumber was given as a username.
     * @param options - optional parameters with specified environment
     * @param messageParameters - optional parameters with specified welcome message
     * @returns token or, in case when arbitrary username was used, it returns
     * initialized instance of SDK
     * @deprecated use `signUpWithUsername`, `initiateSignUpByEmail` or `initiateSignUpByPhone` instead
     */
    signUp: (login: string, password: string, options: SdkOptions, messageParameters?: MessageParameters) => {
      return Wallet.signUp(dependencies, login, password, options, messageParameters)
    },
 
    /**
     * @description Completes sign up flow with already created did
     *       (as result created keys will be stored at the Affinity Wallet)
     * NOTE: no need calling this method in case of arbitrary username was given,
     *       as registration is already completed
     * NOTE: This method will throw an error if called for arbitrary username
     * @param keyParams - { ecnryptedSeed, password } - previously created keys to be storead at wallet.
     * @param token - Token returned by signUpWithExistsEntity method.
     * @param confirmationCode - OTP sent by AWS Cognito/SES.
     * @param options - optional parameters for CommonNetworkMember initialization
     * @returns initialized instance of SDK
     * @deprecated use `completeSignUp` instead
     */
    confirmSignUpWithExistsEntity: (
      keyParams: KeyParams,
      signUpToken: string,
      confirmationCode: string,
      options: SdkOptions,
    ) => {
      return Wallet.confirmSignUpWithExistsEntity(dependencies, keyParams, signUpToken, confirmationCode, options)
    },
 
    /**
     * @description Completes sign up flow
     * NOTE: no need calling this method in case of arbitrary username was given,
     *       as registration is already completed.
     * NOTE: this method will throw an error if called for arbitrary username
     * @param confirmationCode - OTP sent by AWS Cognito/SES.
     * @param options - optional parameters for CommonNetworkMember initialization
     * @returns initialized instance of SDK
     * @deprecated use `completeSignUp` instead
     */
    confirmSignUp: (signUpToken: string, confirmationCode: string, options: SdkOptions) => {
      return Wallet.confirmSignUp(dependencies, signUpToken, confirmationCode, options)
    },
 
    /**
     * @description Resends OTP for sign up flow
     * @param username - email/phoneNumber, registered and unconfirmed in Cognito
     * @param options - optional parameters with specified environment
     * @param messageParameters - optional parameters with specified welcome message
     * @deprecated use `resendSignUp` instead
     */
    resendSignUpConfirmationCode: (login: string, options: SdkOptions, messageParameters?: MessageParameters) => {
      return Wallet.resendSignUpConfirmationCode(login, options, messageParameters)
    },
 
    /**
     * @description Initiates passwordless sign in of an existing user,
     * or signs up a new one, if user was not registered
     * @param username - email/phoneNumber, registered in Cognito
     * @param options - optional parameters with specified environment
     * @param messageParameters - optional parameters with specified welcome message
     * @returns token
     * @deprecated use `initiateSignInPasswordless` instead
     */
    signIn: (login: string, options: SdkOptions, messageParameters?: MessageParameters) => {
      return Wallet.signIn(login, options, messageParameters)
    },
 
    /**
     * @description Completes sign in
     * @param token - received from #signIn method
     * @param confirmationCode - OTP sent by AWS Cognito/SES
     * @param options - optional parameters for CommonNetworkMember initialization
     * @returns an object with a flag, identifying whether new account was created, and initialized instance of SDK
     * @deprecated use `completeSignInPasswordless` instead
     */
    confirmSignIn: (token: string, confirmationCode: string, options: SdkOptions) => {
      return Wallet.confirmSignIn(dependencies, token, confirmationCode, options)
    },
 
    /**
     * @description Generates random seed from which keys could be derived
     * @deprecated use `Util` instead
     */
    generateSeed: (didMethod?: string) => {
      return Util.generateSeed(didMethod)
    },
 
    /**
     * @description Parses JWT token (request and response tokens of share and offer flows)
     * @param token - JWT
     * @returns parsed object from JWT
     * @deprecated use `Util` instead
     */
    fromJWT: (token: string) => {
      return Util.fromJWT(token)
    },
 
    /**
     * @description Creates a new instance of SDK by access token
     * @param accessToken
     * @param options - optional parameters for AffinityWallet initialization
     * @returns initialized instance of SDK
     * @deprecated use `deserialize` instead
     */
    fromAccessToken: (accessToken: string, options: SdkOptions) => {
      return Wallet.fromAccessToken(dependencies, accessToken, options)
    },
 
    /**
     * @description Logins with access token of Cognito user registered in Affinity
     * @param options - optional parameters for AffinityWallet initialization
     * @returns initialized instance of SDK or throws `COR-9` UnprocessableEntityError,
     * if user is not logged in.
     * @deprecated manage state storage and use `serialize`/`deserialize` instead
     */
    init: (options: SdkOptions) => {
      return Wallet.init(dependencies, options)
    },
 
    /**
     * @deprecated use `openWalletByEncryptedSeed` instead
     */
    legacyConstructor: (password: string, encryptedSeed: string, inputOptions: SdkOptions) => {
      return Wallet.legacyConstructor(dependencies, password, encryptedSeed, inputOptions)
    },
  }
}