All files / src/factories walletFactories.ts

100% Statements 21/21
100% Branches 0/0
100% Functions 4/4
100% Lines 19/19

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      1x 1x 1x 1x             1x                   2x   2x 50x       1x       2x 2x 2x 2x 2x               1x       2x 2x 2x 2x            
import { EventComponent } from '@affinidi/affinity-metrics-lib'
 
import { IPlatformCryptographyTools } from '../shared/interfaces'
import { createCognitoWalletFactories } from './cognitoWalletFactories'
import { createCognitolessWalletFactories } from './cognitolessWalletFactories'
import { createLegacyWalletFactories } from './legacyWalletFactories'
import { createPublicToolsFactories } from './publicToolsFactories'
 
/**
 * Turns any arrow function into a constructor of its return value accepting the same arguments
 * @param inputFunction Original function (e.g. `(arg: string) => ({ arg })`)
 * @returns Constructor (e.g. `C` such that `new C('abc') === { arg: 'abc' }`)
 */
const createConstructor = <T extends (...args: any) => any>(inputFunction: T) => {
  type TF = (...args: Parameters<T>) => ReturnType<T>
 
  type TConstructor = {
    /**
     * @deprecated use `createFromEncryptedSeedAndPassword` instead
     */
    new (...args: Parameters<T>): ReturnType<T>
  }
 
  const f: TF = inputFunction
 
  return (function (...args: Parameters<T>) {
    return f(...args)
  } as any) as TConstructor
}
 
export const createV5CompatibleWalletFactories = (
  platformCryptographyTools: IPlatformCryptographyTools,
  component: EventComponent,
) => {
  const { legacyConstructor, ...legacyFactories } = createLegacyWalletFactories(platformCryptographyTools, component)
  const cognitoFactories = createCognitoWalletFactories(platformCryptographyTools, component)
  const cognitolessFactories = createCognitolessWalletFactories(platformCryptographyTools, component)
  const publicToolsFactories = createPublicToolsFactories(platformCryptographyTools, component)
  return Object.assign(createConstructor(legacyConstructor), {
    ...cognitoFactories,
    ...cognitolessFactories,
    ...publicToolsFactories,
    ...legacyFactories,
  })
}
 
export const createV6WalletFactories = (
  platformCryptographyTools: IPlatformCryptographyTools,
  component: EventComponent,
) => {
  const cognitoFactories = createCognitoWalletFactories(platformCryptographyTools, component)
  const cognitolessFactories = createCognitolessWalletFactories(platformCryptographyTools, component)
  const publicToolsFactories = createPublicToolsFactories(platformCryptographyTools, component)
  return {
    ...cognitoFactories,
    ...cognitolessFactories,
    ...publicToolsFactories,
  }
}