Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature flags setup, and implementation of SKIP_IDENTTITY_CREATION and SKIP_ENTROPY_COLLECTION #1410

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
module.exports = {
presets: ['module:metro-react-native-babel-preset'],
plugins: [
["transform-inline-environment-variables"],

["babel-plugin-inline-import", {
"extensions": [
".xml",
Expand Down
3 changes: 1 addition & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@ module.exports = {
"enzyme-to-json/serializer"
],
transformIgnorePatterns: [
"node_modules/(?!react-native|native-base|@?react-navigation|react-native-fabric)"
"node_modules/(?!react-native|native-base|@?react-navigation|react-native-fabric|typeorm)"
],
globals: {
window: true,
"ts-jest": {
babelConfig: true
}
Expand Down
5 changes: 4 additions & 1 deletion ormconfig.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { entityList } from './src/lib/storage/entities'
import { Initial1565886000404 } from './src/lib/storage/migration/1565886000404-initial'
import { ConnectionOptions } from 'typeorm/browser'

export default {
const typeOrmConfig: ConnectionOptions = {
type: 'react-native',
database: 'LocalSmartWalletData',
location: 'default',
Expand All @@ -14,3 +15,5 @@ export default {
migrationsDir: 'src/lib/storage/migration',
},
}

export default typeOrmConfig
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"@typescript-eslint/parser": "^1.5.0",
"babel-jest": "^24.8.0",
"babel-plugin-inline-import": "^3.0.0",
"babel-plugin-transform-inline-environment-variables": "^0.4.3",
"babel-plugin-transform-typescript-metadata": "^0.2.2",
"case-sensitive-paths-webpack-plugin": "^2.1.2",
"class-transformer": "^0.1.9",
Expand Down Expand Up @@ -56,8 +57,8 @@
},
"scripts": {
"start": "adb reverse tcp:8081 tcp:8081 & node node_modules/react-native/local-cli/cli.js start",
"test": "jest",
"test:debug": "node --inspect-brk node_modules/.bin/jest --runInBand",
"test": "NODE_ENV=test jest",
"test:debug": "NODE_ENV=test node --inspect-brk node_modules/.bin/jest --runInBand",
"run:ios": "react-native run-ios",
"run:android": "react-native run-android --appIdSuffix debug",
"run:android:staging": "react-native run-android --variant staging --appIdSuffix debugStaging",
Expand Down
4 changes: 2 additions & 2 deletions src/actions/registration/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export const createIdentity = (encodedEntropy: string): ThunkAction => async (

dispatch(setIsRegistering(true))

const { encryptionLib, keyChainLib, storageLib, registry } = backendMiddleware
const { encryptionLib, keyChainLib, storageLib, registry, fuelKeyWithEther } = backendMiddleware

const password = await keyChainLib.getPassword()
const encEntropy = encryptionLib.encryptWithPass({
Expand All @@ -81,7 +81,7 @@ export const createIdentity = (encodedEntropy: string): ThunkAction => async (

dispatch(setLoadingMsg(loading.loadingStages[1]))

await JolocomLib.util.fuelKeyWithEther(
await fuelKeyWithEther(
userVault.getPublicKey({
encryptionPass: password,
derivationPath: JolocomLib.KeyTypes.ethereumKey,
Expand Down
13 changes: 13 additions & 0 deletions src/backendMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import { IpfsCustomConnector } from './lib/ipfs'
import { jolocomContractsAdapter } from 'jolocom-lib/js/contracts/contractsAdapter'
import { jolocomEthereumResolver } from 'jolocom-lib/js/ethereum/ethereum'
import { jolocomContractsGateway } from 'jolocom-lib/js/contracts/contractsGateway'
import { SKIP_IDENTITY_REGISTRATION } from './env'

export class BackendMiddleware {
public identityWallet!: IdentityWallet
public storageLib: Storage
public encryptionLib: EncryptionLibInterface
public keyChainLib: KeyChainInterface
public registry: IRegistry
public fuelKeyWithEther: typeof JolocomLib.util.fuelKeyWithEther

public constructor(config: {
fuelingEndpoint: string
Expand All @@ -26,6 +28,7 @@ export class BackendMiddleware {
this.storageLib = new Storage(config.typeOrmConfig)
this.encryptionLib = new EncryptionLib()
this.keyChainLib = new KeyChain()
this.fuelKeyWithEther = JolocomLib.util.fuelKeyWithEther
this.registry = createJolocomRegistry({
ipfsConnector: new IpfsCustomConnector({
host: 'ipfs.jolocom.com',
Expand All @@ -38,6 +41,16 @@ export class BackendMiddleware {
gateway: jolocomContractsGateway,
},
})
if (SKIP_IDENTITY_REGISTRATION) {
this.registry.commit = this.fuelKeyWithEther = async (arg: any) =>
undefined
this.setIdentityWallet = async function(
mnzaki marked this conversation as resolved.
Show resolved Hide resolved
userVault: SoftwareKeyProvider,
pass: string,
): Promise<void> {
this.identityWallet = await this.registry.create(userVault, pass)
}
}
}

public async initStorage(): Promise<void> {
Expand Down
8 changes: 8 additions & 0 deletions src/env.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const env = process.env['NODE_ENV'] || 'development'
const isDev = env === 'development'
// @ts-ignore unused so far
const isTest = env === 'test'
const isTestE2E = env === 'test-e2e'

export const SKIP_ENTROPY_COLLECTION = isDev || isTestE2E
export const SKIP_IDENTITY_REGISTRATION = isDev || isTestE2E
1 change: 0 additions & 1 deletion src/lib/storage/entities/verifiableCredentialEntity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
OneToMany,
ManyToOne,
} from 'typeorm/browser'

import { Exclude, Expose, plainToClass, classToPlain } from 'class-transformer'
import { SignedCredential } from 'jolocom-lib/js/credentials/signedCredential/signedCredential'
import { ISignedCredentialAttrs } from 'jolocom-lib/js/credentials/signedCredential/types'
Expand Down
8 changes: 6 additions & 2 deletions src/ui/registration/containers/entropy.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { SKIP_ENTROPY_COLLECTION } from 'src/env'

import React from 'react'
import { connect } from 'react-redux'
import { registrationActions } from 'src/actions'
Expand All @@ -10,7 +12,7 @@ import {
import { generateSecureRandomBytes } from 'src/lib/util'
import { withErrorScreen } from 'src/actions/modifiers'
import { ThunkDispatch } from 'src/store'
import { AppError, ErrorCode } from '../../../lib/errors'
import { AppError, ErrorCode } from 'src/lib/errors'
import { routeList } from 'src/routeList'
import { StatusBar } from 'react-native'

Expand Down Expand Up @@ -58,7 +60,9 @@ export class EntropyContainer extends React.Component<Props, State> {
}

private updateEntropyProgress = async (): Promise<void> => {
const { entropyProgress } = this.state
const entropyProgress = SKIP_ENTROPY_COLLECTION

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its more efficient to move this to state init (line 39), if it has no other implications

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wanted it to start out as 0 so that you have to at least touch the screen once to get to "100%" 😄

? 1
: this.state.entropyProgress
if (entropyProgress >= 1) {
this.setState({ sufficientEntropy: true, entropyProgress: 1 })
while (this.entropyGenerator.getProgress() < 1) {
Expand Down
7 changes: 2 additions & 5 deletions tests/actions/registration/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { registrationActions } from 'src/actions'
import data from './data/mockRegistrationData'
import { JolocomLib } from 'jolocom-lib'
import * as util from 'src/lib/util'
import { withErrorScreen } from 'src/actions/modifiers'
import { AppError, ErrorCode } from 'src/lib/errors'
Expand Down Expand Up @@ -79,9 +78,6 @@ describe('Registration action creators', () => {
it('should attempt to create an identity', async () => {
MockDate.set(new Date(946681200000))
const { getPasswordResult, cipher, entropy, identityWallet } = data
const fuelSpy = jest
.spyOn(JolocomLib.util, 'fuelKeyWithEther')
.mockResolvedValueOnce(null)

const mockMiddleware = {
identityWallet,
Expand All @@ -107,6 +103,7 @@ describe('Registration action creators', () => {
create: () => identityWallet,
},
setIdentityWallet: jest.fn(() => Promise.resolve()),
fuelKeyWithEther: jest.fn().mockResolvedValueOnce(null)
}

const mockState: Partial<RootState> = {
Expand Down Expand Up @@ -134,7 +131,7 @@ describe('Registration action creators', () => {
expect(
mockMiddleware.storageLib.store.derivedKey.mock.calls,
).toMatchSnapshot()
expect(fuelSpy.mock.calls).toMatchSnapshot()
expect(mockMiddleware.fuelKeyWithEther.mock.calls).toMatchSnapshot()
MockDate.reset()
})

Expand Down
15 changes: 11 additions & 4 deletions tests/ui/containers/entropy.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,24 @@ import { stub, reveal } from 'tests/utils'
describe('Entropy container', () => {
const mockInstanceGenerator = (
instance: EntropyContainer,
progressValues = [0],
progressValues: number[] | null = null,
) => {
const getProgress = jest.fn().mockReturnValue(progressValues[0])
const getProgress = jest.fn()
// @ts-ignore private
const generatorMock = (instance.entropyGenerator = stub<EntropyGenerator>({
getProgress,
addFromDelta: jest.fn(),
generateRandomString: jest.fn().mockReturnValue('randomString'),
}))

progressValues.forEach(v => getProgress.mockReturnValueOnce(v))
if (progressValues) {
getProgress.mockReturnValue(progressValues[0])
progressValues.forEach(v => getProgress.mockReturnValueOnce(v))
} else {
getProgress.mockImplementation(() => {
throw new Error("shouldn't get here!")
})
}

return generatorMock
}
Expand All @@ -45,7 +52,7 @@ describe('Entropy container', () => {
it('correctly handles added points with the entropy generator', () => {
const rendered = shallow(<EntropyContainer {...props} />)
const instance = rendered.instance() as EntropyContainer
const generatorMock = mockInstanceGenerator(instance)
const generatorMock = mockInstanceGenerator(instance, [0])

expect(rendered.state()).toMatchSnapshot()

Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1851,6 +1851,11 @@ babel-plugin-syntax-trailing-function-commas@^7.0.0-beta.0:
resolved "https://registry.yarnpkg.com/babel-plugin-syntax-trailing-function-commas/-/babel-plugin-syntax-trailing-function-commas-7.0.0-beta.0.tgz#aa213c1435e2bffeb6fca842287ef534ad05d5cf"
integrity sha512-Xj9XuRuz3nTSbaTXWv3itLOcxyF4oPD8douBBmj7U9BBC6nEBYfyOJYQMf/8PJAFotC62UY5dFfIGEPr7WswzQ==

babel-plugin-transform-inline-environment-variables@^0.4.3:
version "0.4.3"
resolved "https://registry.yarnpkg.com/babel-plugin-transform-inline-environment-variables/-/babel-plugin-transform-inline-environment-variables-0.4.3.tgz#a3b09883353be8b5e2336e3ff1ef8a5d93f9c489"
integrity sha1-o7CYgzU76LXiM24/8e+KXZP5xIk=

babel-plugin-transform-typescript-metadata@^0.2.2:
version "0.2.2"
resolved "https://registry.yarnpkg.com/babel-plugin-transform-typescript-metadata/-/babel-plugin-transform-typescript-metadata-0.2.2.tgz#fc44611187409ed9d5cb372ca2f85939a359cada"
Expand Down