Skip to content

Commit

Permalink
CP-8857 Remove keys and make app runnable without keys (#1412)
Browse files Browse the repository at this point in the history
  • Loading branch information
neven-s authored Jul 24, 2024
1 parent f77bfdf commit 26acd76
Show file tree
Hide file tree
Showing 27 changed files with 379 additions and 78 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { IdentityProof } from '@cubist-labs/cubesigner-sdk'
import Config from 'react-native-config'
import Logger from 'utils/Logger'
import { CoreSeedlessAPIServiceNoop } from 'seedless/services/CoreSeedlessAPIServiceNoop'
import { CoreSeedlessApiInterface } from 'seedless/services/types'

if (!Config.SEEDLESS_URL) {
throw Error('SEEDLESS_URL is missing. Please check your env file.')
Logger.warn('SEEDLESS_URL is missing in env file. Seedless is disabled.')
}

if (!Config.SEEDLESS_API_KEY) {
throw Error('SEEDLESS_API_KEY is missing. Please check your env file.')
Logger.warn('SEEDLESS_API_KEY is missing in env file. Seedless is disabled.')
}

export enum SeedlessUserRegistrationResult {
Expand All @@ -20,7 +22,9 @@ export enum SeedlessUserRegistrationResult {
* Service for core-seedless-api
* https://github.com/ava-labs/core-seedless-api
*/
class CoreSeedlessAPIService {
class CoreSeedlessAPIService implements CoreSeedlessApiInterface {
constructor(private seedlessApiKey: string) {}

async register(
identityProof: IdentityProof
): Promise<SeedlessUserRegistrationResult> {
Expand All @@ -31,7 +35,7 @@ class CoreSeedlessAPIService {
method: 'POST',
body: JSON.stringify(identityProof),
headers: {
Authorization: `${Config.SEEDLESS_API_KEY}`,
Authorization: this.seedlessApiKey,
'Content-Type': 'application/json'
}
}
Expand Down Expand Up @@ -64,7 +68,7 @@ class CoreSeedlessAPIService {
const response = await fetch(Config.SEEDLESS_URL + '/v1/addAccount', {
method: 'POST',
headers: {
Authorization: `${Config.SEEDLESS_API_KEY}`,
Authorization: this.seedlessApiKey,
'Content-Type': 'application/json'
},
body: JSON.stringify({
Expand All @@ -82,4 +86,6 @@ class CoreSeedlessAPIService {
}
}

export default new CoreSeedlessAPIService()
export default Config.SEEDLESS_API_KEY
? new CoreSeedlessAPIService(Config.SEEDLESS_API_KEY)
: new CoreSeedlessAPIServiceNoop()
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { SeedlessUserRegistrationResult } from 'seedless/services/CoreSeedlessAPIService'
import { CoreSeedlessApiInterface } from 'seedless/services/types'

export class CoreSeedlessAPIServiceNoop implements CoreSeedlessApiInterface {
async register(): Promise<SeedlessUserRegistrationResult> {
return SeedlessUserRegistrationResult.ERROR
}

async addAccount(): Promise<void> {
//noop
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ import Logger from 'utils/Logger'
import { RetryBackoffPolicy, retry } from 'utils/js/retry'

if (!Config.SEEDLESS_ORG_ID) {
throw Error('SEEDLESS_ORG_ID is missing. Please check your env file.')
Logger.warn('SEEDLESS_ORG_ID is missing. Seedless is disabled.')
}

if (!Config.SEEDLESS_ENVIRONMENT) {
throw Error('SEEDLESS_ENVIRONMENT is missing. Please check your env file.')
Logger.warn('SEEDLESS_ENVIRONMENT is missing. Please check your env file.')
}

const SEEDLESS_ORG_ID = Config.SEEDLESS_ORG_ID
const SEEDLESS_ORG_ID = Config.SEEDLESS_ORG_ID ?? ''

const SEEDLESS_ENVIRONMENT = Config.SEEDLESS_ENVIRONMENT

Expand Down
18 changes: 18 additions & 0 deletions packages/core-mobile/app/seedless/services/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { IdentityProof } from '@cubist-labs/cubesigner-sdk'
import { SeedlessUserRegistrationResult } from 'seedless/services/CoreSeedlessAPIService'

export interface CoreSeedlessApiInterface {
register(
identityProof: IdentityProof
): Promise<SeedlessUserRegistrationResult>

addAccount({
accountIndex,
identityProof,
mnemonicId
}: {
accountIndex: number
identityProof: IdentityProof
mnemonicId: string
}): Promise<void>
}
6 changes: 5 additions & 1 deletion packages/core-mobile/app/services/GlacierService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ import {
} from '@avalabs/glacier-sdk'
import Config from 'react-native-config'
import { ChainId } from '@avalabs/chains-sdk'
import Logger from 'utils/Logger'

if (!Config.GLACIER_URL) throw Error('GLACIER_URL ENV is missing')
if (!Config.GLACIER_URL)
Logger.warn(
'GLACIER_URL ENV is missing in env file. Glacier service disabled.'
)

export const GLACIER_URL = Config.GLACIER_URL

Expand Down
37 changes: 25 additions & 12 deletions packages/core-mobile/app/services/analytics/AnalyticsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,32 @@ import PostHogService from 'services/posthog/PostHogService'
import { AnalyticsEvents } from 'types/analytics'
import Config from 'react-native-config'
import { encrypt } from 'utils/hpke'
import { AnalyticsEventName, CaptureEventProperties } from './types'
import Logger from 'utils/Logger'
import { AnalyticsServiceNoop } from 'services/analytics/AnalyticsServiceNoop'
import {
AnalyticsEventName,
AnalyticsServiceInterface,
CaptureEventProperties
} from './types'

if (!Config.ANALYTICS_ENCRYPTION_KEY) {
throw Error(
'ANALYTICS_ENCRYPTION_KEY is missing. Please check your env file.'
Logger.warn(
'ANALYTICS_ENCRYPTION_KEY is missing in env file. Analytics are disabled.'
)
}

if (!Config.ANALYTICS_ENCRYPTION_KEY_ID) {
throw Error(
'ANALYTICS_ENCRYPTION_KEY_ID is missing. Please check your env file.'
Logger.warn(
'ANALYTICS_ENCRYPTION_KEY_ID is missing in env file. Analytics are disabled.'
)
}

const ANALYTICS_ENCRYPTION_KEY = Config.ANALYTICS_ENCRYPTION_KEY
class AnalyticsService implements AnalyticsServiceInterface {
constructor(
private analyticsEncryptionKey: string,
private analyticsEncryptionKeyId: string
) {}

const ANALYTICS_ENCRYPTION_KEY_ID = Config.ANALYTICS_ENCRYPTION_KEY_ID

class AnalyticsService {
private isEnabled: boolean | undefined

setEnabled(isEnabled: boolean): void {
Expand Down Expand Up @@ -49,8 +56,8 @@ class AnalyticsService {
const stringifiedProperties = JSON.stringify(properties)
const { encrypted, enc, keyID } = await encrypt(
stringifiedProperties,
ANALYTICS_ENCRYPTION_KEY,
ANALYTICS_ENCRYPTION_KEY_ID
this.analyticsEncryptionKey,
this.analyticsEncryptionKeyId
)

return PostHogService.capture(eventName, {
Expand All @@ -61,4 +68,10 @@ class AnalyticsService {
}
}

export default new AnalyticsService()
export default Config.ANALYTICS_ENCRYPTION_KEY &&
Config.ANALYTICS_ENCRYPTION_KEY_ID
? new AnalyticsService(
Config.ANALYTICS_ENCRYPTION_KEY,
Config.ANALYTICS_ENCRYPTION_KEY_ID
)
: new AnalyticsServiceNoop()
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { AnalyticsServiceInterface } from 'services/analytics/types'

export class AnalyticsServiceNoop implements AnalyticsServiceInterface {
setEnabled(): void {
//noop
}

async capture(): Promise<void> {
//noop
}

async captureWithEncryption(): Promise<void> {
//noop
}
}
12 changes: 12 additions & 0 deletions packages/core-mobile/app/services/analytics/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,15 @@ export type CaptureEventProperties<E extends AnalyticsEventName> =
undefined extends AnalyticsEvents[E]
? [AnalyticsEvents[E]?]
: [AnalyticsEvents[E]]

export interface AnalyticsServiceInterface {
setEnabled(isEnabled: boolean): void
capture<E extends AnalyticsEventName>(
eventName: E,
...properties: CaptureEventProperties<E>
): Promise<void>
captureWithEncryption<E extends AnalyticsEventName>(
eventName: E,
properties: AnalyticsEvents[E]
): Promise<void>
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import Blockaid from '@blockaid/client'
import Config from 'react-native-config'
import { TransactionParams } from '@avalabs/evm-module'
import Logger from 'utils/Logger'
import {
JsonRpcRequestData,
SiteScanResponse,
TransactionScanResponse
} from './types'

if (!Config.PROXY_URL) throw Error('PROXY_URL is missing')
if (!Config.PROXY_URL)
Logger.warn('PROXY_URL is missing in env file. Blockaid service disabled.')

const baseURL = Config.PROXY_URL + '/proxy/blockaid/'

Expand Down
3 changes: 2 additions & 1 deletion packages/core-mobile/app/services/browser/apiClient.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { Zodios } from '@zodios/core'
import Config from 'react-native-config'
import { z } from 'zod'
import Logger from 'utils/Logger'
import { DeFiProtocolInformationSchema } from './debankTypes'

if (!Config.PROXY_URL) throw Error('PROXY_URL is missing')
if (!Config.PROXY_URL) Logger.warn('PROXY_URL is missing')

const baseUrl = Config.PROXY_URL + '/proxy/debank/v1'

Expand Down
3 changes: 2 additions & 1 deletion packages/core-mobile/app/services/defi/apiClient.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { Zodios } from '@zodios/core'
import Config from 'react-native-config'
import { z } from 'zod'
import Logger from 'utils/Logger'
import {
DeFiChainSchema,
DeFiProtocolSchema,
DeFiSimpleProtocolSchema
} from './debankTypes'
import { ExchangeRateSchema } from './types'

if (!Config.PROXY_URL) throw Error('PROXY_URL is missing')
if (!Config.PROXY_URL) Logger.warn('PROXY_URL is missing. Defi disabled.')

const baseUrl = Config.PROXY_URL + '/proxy/debank/v1'

Expand Down
4 changes: 3 additions & 1 deletion packages/core-mobile/app/services/network/NetworkService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ import { avaxSerial } from '@avalabs/avalanchejs'
import { TransactionResponse } from 'ethers'
import { Networks } from 'store/network/types'
import Config from 'react-native-config'
import Logger from 'utils/Logger'
import { getBitcoinProvider, getEvmProvider } from './utils/providerUtils'

if (!Config.PROXY_URL) throw Error('PROXY_URL is missing')
if (!Config.PROXY_URL)
Logger.warn('PROXY_URL is missing in env file. Network service is disabled.')

class NetworkService {
async getNetworks(): Promise<Networks> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,19 @@
import Config from 'react-native-config'
import { InAppBrowser } from 'react-native-inappbrowser-reborn'
import {
PasskeyAuthenticationRequest,
PasskeyRegistrationRequest
} from 'react-native-passkey/lib/typescript/Passkey'
import {
FIDOAuthenticationResult,
FIDOAuthenticationRequest,
FIDORegistrationResult,
FIDOAuthenticationResult,
FIDORegistrationRequest,
FIDORegistrationResult,
FidoType,
PasskeyServiceInterface
} from 'services/passkey/types'
import { base64UrlToBuffer, bufferToBase64Url } from 'utils/data/base64'
import { FIDO_CALLBACK_URL, RP_ID } from './consts'

if (!Config.SEEDLESS_ENVIRONMENT) {
throw Error('SEEDLESS_ENVIRONMENT is missing. Please check your env file.')
}

const BROWSER_OPTIONS = {
showTitle: false,
toolbarColor: '#000000',
Expand Down
5 changes: 0 additions & 5 deletions packages/core-mobile/app/services/passkey/PasskeyService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Platform } from 'react-native'
import Config from 'react-native-config'
import { Passkey } from 'react-native-passkey'
import {
PasskeyAuthenticationRequest,
Expand All @@ -17,10 +16,6 @@ import {
import { base64ToBase64Url } from 'utils/data/base64'
import { FIDO_TIMEOUT, RP_ID, RP_NAME } from './consts'

if (!Config.SEEDLESS_ENVIRONMENT) {
throw Error('SEEDLESS_ENVIRONMENT is missing. Please check your env file.')
}

class PasskeyService implements PasskeyServiceInterface {
get isSupported(): boolean {
return Passkey.isSupported() && Platform.OS === 'ios'
Expand Down
Loading

0 comments on commit 26acd76

Please sign in to comment.