Skip to content

Commit

Permalink
[C-1644] Remove Recaptcha (#4496)
Browse files Browse the repository at this point in the history
  • Loading branch information
dylanjeffers authored Dec 17, 2022
1 parent 4eab3a3 commit e349316
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 165 deletions.
17 changes: 2 additions & 15 deletions libs/src/AudiusLibs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { Wormhole, WormholeConfig } from './services/wormhole'
import { AudiusABIDecoder } from './services/ABIDecoder'
import { Schemas, SchemaValidator } from './services/schemaValidator'
import { UserStateManager } from './userStateManager'
import { Utils, Captcha, Nullable, Logger, CaptchaConfig } from './utils'
import { Utils, Nullable, Logger } from './utils'
import { ServiceProvider } from './api/ServiceProvider'

import { Account } from './api/Account'
Expand Down Expand Up @@ -84,7 +84,6 @@ type AudiusLibsConfig = {
creatorNodeConfig: CreatorNodeConfig
comstockConfig: LibsComstockConfig
wormholeConfig: WormholeConfig
captchaConfig: CaptchaConfig
hedgehogConfig: LibsHedgehogConfig
isServer: boolean
logger: Logger
Expand Down Expand Up @@ -334,7 +333,6 @@ export class AudiusLibs {
discoveryProviderConfig: LibsDiscoveryProviderConfig
comstockConfig: LibsComstockConfig
wormholeConfig: WormholeConfig
captchaConfig: CaptchaConfig
hedgehogConfig: LibsHedgehogConfig
isServer: boolean
isDebug: boolean
Expand All @@ -356,7 +354,6 @@ export class AudiusLibs {
contracts: Nullable<AudiusContracts>
wormholeClient: Nullable<Wormhole>
creatorNode: Nullable<CreatorNode>
captcha: Nullable<Captcha>
schemas?: Schemas
comstock: Nullable<Comstock>

Expand Down Expand Up @@ -396,7 +393,6 @@ export class AudiusLibs {
creatorNodeConfig,
comstockConfig,
wormholeConfig,
captchaConfig,
hedgehogConfig,
isServer,
logger = console,
Expand All @@ -418,7 +414,6 @@ export class AudiusLibs {
this.discoveryProviderConfig = discoveryProviderConfig
this.comstockConfig = comstockConfig
this.wormholeConfig = wormholeConfig
this.captchaConfig = captchaConfig
this.hedgehogConfig = hedgehogConfig
this.isServer = isServer
this.isDebug = isDebug
Expand All @@ -440,7 +435,6 @@ export class AudiusLibs {
this.wormholeClient = null
this.contracts = null
this.creatorNode = null
this.captcha = null
this.comstock = null

// API
Expand Down Expand Up @@ -473,16 +467,10 @@ export class AudiusLibs {
// Config external web3 is an async function, so await it here in case it needs to be
this.web3Config = await this.web3Config

/** Captcha */
if (this.captchaConfig) {
this.captcha = new Captcha(this.captchaConfig)
}

/** Identity Service */
if (this.identityServiceConfig) {
this.identityService = new IdentityService({
identityServiceEndpoint: this.identityServiceConfig.url,
captcha: this.captcha
identityServiceEndpoint: this.identityServiceConfig.url
})
const hedgehogService = new Hedgehog({
identityService: this.identityService,
Expand Down Expand Up @@ -644,7 +632,6 @@ export class AudiusLibs {
this.wormholeClient,
this.creatorNode,
this.comstock,
this.captcha,
this.isServer,
this.logger
] as BaseConstructorArgs
Expand Down
19 changes: 3 additions & 16 deletions libs/src/NativeAudiusLibs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {
} from './services/discoveryProvider'
import { Schemas, SchemaValidator } from './services/schemaValidator'
import { UserStateManager } from './userStateManager'
import type { Logger, CaptchaConfig, Nullable } from './utils'
import { Captcha, Utils } from './utils'
import type { Logger, Nullable } from './utils'
import { Utils } from './utils'

import { Keypair, PublicKey } from '@solana/web3.js'

Expand Down Expand Up @@ -77,7 +77,6 @@ type AudiusLibsConfig = {
creatorNodeConfig: CreatorNodeConfig
comstockConfig: LibsComstockConfig
wormholeConfig: ProxyWormholeConfig
captchaConfig: CaptchaConfig
hedgehogConfig: LibsHedgehogConfig
isServer: boolean
logger: Logger
Expand Down Expand Up @@ -303,7 +302,6 @@ export class AudiusLibs {
discoveryProviderConfig: LibsDiscoveryProviderConfig
comstockConfig: LibsComstockConfig
wormholeConfig: ProxyWormholeConfig
captchaConfig: CaptchaConfig
hedgehogConfig: LibsHedgehogConfig
isServer: boolean
isDebug: boolean
Expand All @@ -321,7 +319,6 @@ export class AudiusLibs {
contracts: Nullable<AudiusContracts>
wormholeClient: Nullable<ProxyWormhole>
creatorNode: Nullable<CreatorNode>
captcha: Nullable<Captcha>
schemas?: Schemas
comstock: Nullable<Comstock>

Expand Down Expand Up @@ -360,7 +357,6 @@ export class AudiusLibs {
creatorNodeConfig,
comstockConfig,
wormholeConfig,
captchaConfig,
hedgehogConfig,
isServer,
logger = console,
Expand All @@ -381,7 +377,6 @@ export class AudiusLibs {
this.discoveryProviderConfig = discoveryProviderConfig
this.comstockConfig = comstockConfig
this.wormholeConfig = wormholeConfig
this.captchaConfig = captchaConfig
this.hedgehogConfig = hedgehogConfig
this.isServer = isServer
this.isDebug = isDebug
Expand All @@ -399,7 +394,6 @@ export class AudiusLibs {
this.wormholeClient = null
this.contracts = null
this.creatorNode = null
this.captcha = null
this.comstock = null

// API
Expand Down Expand Up @@ -432,16 +426,10 @@ export class AudiusLibs {
// Config external web3 is an async function, so await it here in case it needs to be
this.web3Config = await this.web3Config

/** Captcha */
if (this.captchaConfig) {
this.captcha = new Captcha(this.captchaConfig)
}

/** Identity Service */
if (this.identityServiceConfig) {
this.identityService = new IdentityService({
identityServiceEndpoint: this.identityServiceConfig.url,
captcha: this.captcha
identityServiceEndpoint: this.identityServiceConfig.url
})
const hedgehogService = new Hedgehog({
identityService: this.identityService,
Expand Down Expand Up @@ -588,7 +576,6 @@ export class AudiusLibs {
this.wormholeClient,
this.creatorNode,
this.comstock,
this.captcha,
this.isServer,
this.logger
] as BaseConstructorArgs
Expand Down
5 changes: 0 additions & 5 deletions libs/src/api/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import type { SolanaAudiusData } from '../services/solanaAudiusData/SolanaAudius
import type { SolanaWeb3Manager } from '../services/solana'
import type { Web3Manager } from '../services/web3Manager'
import type { UserStateManager } from '../userStateManager'
import type { Captcha } from '../utils'
import type { Wormhole } from '../services/wormhole'

export const Services = Object.freeze({
Expand All @@ -36,7 +35,6 @@ export type BaseConstructorArgs = [
Wormhole,
CreatorNode,
Comstock,
Captcha,
boolean,
any
]
Expand All @@ -55,7 +53,6 @@ export class Base {
wormholeClient: Wormhole
creatorNode: CreatorNode
comstock: Comstock
captcha: Captcha
isServer: boolean
logger: any = console

Expand All @@ -75,7 +72,6 @@ export class Base {
wormholeClient: Wormhole,
creatorNode: CreatorNode,
comstock: Comstock,
captcha: Captcha,
isServer: boolean,
logger: any = console
) {
Expand All @@ -92,7 +88,6 @@ export class Base {
this.wormholeClient = wormholeClient
this.creatorNode = creatorNode
this.comstock = comstock
this.captcha = captcha
this.isServer = isServer
this.logger = logger

Expand Down
33 changes: 2 additions & 31 deletions libs/src/services/identity/IdentityService.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios, { AxiosError, AxiosRequestConfig, AxiosResponse } from 'axios'
import { AuthHeaders } from '../../constants'
import { uuid } from '../../utils/uuid'
import type { Captcha, Nullable } from '../../utils'
import type { Nullable } from '../../utils'

import { getTrackListens, TimeFrame } from './requests'
import type { Web3Manager } from '../web3Manager'
Expand Down Expand Up @@ -87,22 +87,16 @@ type CreateStripeSessionResponse = {
status: string
}

// Only probabilistically capture 50% of relay captchas
const RELAY_CAPTCHA_SAMPLE_RATE = 0.5

export type IdentityServiceConfig = {
identityServiceEndpoint: string
captcha?: Nullable<Captcha>
}

export class IdentityService {
identityServiceEndpoint: string
captcha?: Nullable<Captcha>
web3Manager: Web3Manager | null

constructor({ identityServiceEndpoint, captcha }: IdentityServiceConfig) {
constructor({ identityServiceEndpoint }: IdentityServiceConfig) {
this.identityServiceEndpoint = identityServiceEndpoint
this.captcha = captcha
this.web3Manager = null
}

Expand Down Expand Up @@ -132,18 +126,6 @@ export class IdentityService {
}

async setUserFn(obj: Data & { token?: string }) {
if (this.captcha) {
try {
const token = await this.captcha.generate('identity/user')
obj.token = token
} catch (e) {
console.warn(
'CAPTCHA (user) - Recaptcha failed to generate token in :',
e
)
}
}

return await this._makeRequest({
url: '/user',
method: 'post',
Expand Down Expand Up @@ -415,16 +397,6 @@ export class IdentityService {
gasLimit: number,
handle: string | null = null
): Promise<{ receipt: TransactionReceipt }> {
const shouldCaptcha = Math.random() < RELAY_CAPTCHA_SAMPLE_RATE
let token
if (this.captcha && shouldCaptcha) {
try {
token = await this.captcha.generate('identity/relay')
} catch (e) {
console.warn('CAPTCHA (relay) - Recaptcha failed to generate token:', e)
}
}

return await this._makeRequest({
url: '/relay',
method: 'post',
Expand All @@ -434,7 +406,6 @@ export class IdentityService {
senderAddress,
encodedABI,
gasLimit,
token,
handle
}
})
Expand Down
97 changes: 0 additions & 97 deletions libs/src/utils/captcha.ts

This file was deleted.

1 change: 0 additions & 1 deletion libs/src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
export * from './utils'
export * from './apiSigning'
export * from './captcha'
export * from './estimateGas'
export * from './multiProvider'
export * from './promiseFight'
Expand Down

0 comments on commit e349316

Please sign in to comment.