Skip to content

Commit

Permalink
[Wallet] Fix 8 digit codes for mainnet (#6663)
Browse files Browse the repository at this point in the history
### Description

* Fix attestaion service URL, when `/` in the end is missing
* Remove firebase proxies.

### Tested

Verification flow on Android device

### Backwards compatibility

Yes
  • Loading branch information
i1skn authored Jan 26, 2021
1 parent 07964da commit f2bbba6
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 112 deletions.
18 changes: 0 additions & 18 deletions packages/mobile/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ PODS:
- Firebase/DynamicLinks (6.13.0):
- Firebase/CoreOnly
- FirebaseDynamicLinks (~> 4.0.5)
- Firebase/Functions (6.13.0):
- Firebase/CoreOnly
- FirebaseFunctions (~> 2.5.1)
- Firebase/Messaging (6.13.0):
- Firebase/CoreOnly
- FirebaseMessaging (~> 4.1.9)
Expand Down Expand Up @@ -70,10 +67,6 @@ PODS:
- FirebaseDynamicLinks (4.0.8):
- FirebaseAnalyticsInterop (~> 1.3)
- FirebaseCore (~> 6.2)
- FirebaseFunctions (2.5.1):
- FirebaseAuthInterop (~> 1.0)
- FirebaseCore (~> 6.0)
- GTMSessionFetcher/Core (~> 1.1)
- FirebaseInstanceID (4.2.7):
- FirebaseCore (~> 6.0)
- GoogleUtilities/Environment (~> 6.0)
Expand Down Expand Up @@ -453,11 +446,6 @@ PODS:
- Firebase/DynamicLinks (~> 6.13.0)
- React
- RNFBApp
- RNFBFunctions (6.8.1):
- Firebase/Core (~> 6.13.0)
- Firebase/Functions (~> 6.13.0)
- React
- RNFBApp
- RNFBMessaging (6.7.1):
- Firebase/Core (~> 6.13.0)
- Firebase/Messaging (~> 6.13.0)
Expand Down Expand Up @@ -594,7 +582,6 @@ DEPENDENCIES:
- "RNFBAuth (from `../../../node_modules/@react-native-firebase/auth`)"
- "RNFBDatabase (from `../../../node_modules/@react-native-firebase/database`)"
- "RNFBDynamicLinks (from `../../../node_modules/@react-native-firebase/dynamic-links`)"
- "RNFBFunctions (from `../../../node_modules/@react-native-firebase/functions`)"
- "RNFBMessaging (from `../../../node_modules/@react-native-firebase/messaging`)"
- "RNFBStorage (from `../../../node_modules/@react-native-firebase/storage`)"
- RNFS (from `../../../node_modules/react-native-fs`)
Expand Down Expand Up @@ -625,7 +612,6 @@ SPEC REPOS:
- FirebaseCoreDiagnosticsInterop
- FirebaseDatabase
- FirebaseDynamicLinks
- FirebaseFunctions
- FirebaseInstanceID
- FirebaseMessaging
- FirebaseStorage
Expand Down Expand Up @@ -759,8 +745,6 @@ EXTERNAL SOURCES:
:path: "../../../node_modules/@react-native-firebase/database"
RNFBDynamicLinks:
:path: "../../../node_modules/@react-native-firebase/dynamic-links"
RNFBFunctions:
:path: "../../../node_modules/@react-native-firebase/functions"
RNFBMessaging:
:path: "../../../node_modules/@react-native-firebase/messaging"
RNFBStorage:
Expand Down Expand Up @@ -807,7 +791,6 @@ SPEC CHECKSUMS:
FirebaseCoreDiagnosticsInterop: 296e2c5f5314500a850ad0b83e9e7c10b011a850
FirebaseDatabase: 0144e0706a4761f1b0e8679572eba8095ddb59be
FirebaseDynamicLinks: 417dc6dbb6013233c77558290d73296f429656a6
FirebaseFunctions: 5af7c35d1c5e41608fecbb667eb6c4e672e318d0
FirebaseInstanceID: ebd2ea79ee38db0cb5f5167b17a0d387e1cc7b6e
FirebaseMessaging: 089b7a4991425783384acc8bcefcd78c0af913bd
FirebaseStorage: 93fe2f8190a01bfb2b2c4932df7d679744c4ef1d
Expand Down Expand Up @@ -874,7 +857,6 @@ SPEC CHECKSUMS:
RNFBAuth: 3d3491cf27037c65a7f68bd77a990c15fd97ccec
RNFBDatabase: 5cfc5a090c66c46dd325e0842378be69a1780d6f
RNFBDynamicLinks: 87346f14c8f12a16eb3ad56ae279c8ce0fdc9c03
RNFBFunctions: 88272875225ebb9736369410e0062b51a4fa50dc
RNFBMessaging: 67f7f6c799e1ea2a8f19b4717a5e5d9515902533
RNFBStorage: 08c6831d19190f68f0985ff7bd773262f11a1c4a
RNFS: 2bd9eb49dc82fa9676382f0585b992c424cd59df
Expand Down
1 change: 0 additions & 1 deletion packages/mobile/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
"@react-native-firebase/auth": "^6.7.1",
"@react-native-firebase/database": "^6.7.1",
"@react-native-firebase/dynamic-links": "^6.7.1",
"@react-native-firebase/functions": "^6.7.1",
"@react-native-firebase/messaging": "^6.7.1",
"@react-native-firebase/storage": "^6.7.1",
"@react-navigation/compat": "^5.3.10",
Expand Down
118 changes: 31 additions & 87 deletions packages/mobile/src/identity/verification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
extractAttestationCodeFromMessage,
extractSecurityCodeWithPrefix,
} from '@celo/utils/src/attestations'
import functions from '@react-native-firebase/functions'
import { Platform } from 'react-native'
import { Task } from 'redux-saga'
import {
Expand All @@ -39,7 +38,7 @@ import ValoraAnalytics from 'src/analytics/ValoraAnalytics'
import { setNumberVerified } from 'src/app/actions'
import { ErrorMessages } from 'src/app/ErrorMessages'
import { currentLanguageSelector } from 'src/app/reducers'
import { DEFAULT_TESTNET, SMS_RETRIEVER_APP_SIGNATURE } from 'src/config'
import { SMS_RETRIEVER_APP_SIGNATURE } from 'src/config'
import { features } from 'src/flags'
import { celoTokenBalanceSelector } from 'src/goldToken/selectors'
import { refreshAllBalances } from 'src/home/actions'
Expand Down Expand Up @@ -1049,40 +1048,16 @@ async function postToAttestationService(
attestationServiceUrl: string,
revealRequestBody: AttestationRequest
): Promise<{ ok: boolean; status: number; body: any }> {
if (shouldUseProxy()) {
Logger.debug(
`${TAG}@postToAttestationService`,
`Posting to proxy for service url ${attestationServiceUrl}`
)
const fullUrl = attestationServiceUrl + '/attestations'
const body = {
...revealRequestBody,
attestationServiceUrl: fullUrl,
}
try {
const proxyReveal = functions().httpsCallable('proxyReveal')
const response = await proxyReveal(body)
const { status, data } = response.data
const ok = status >= 200 && status < 300
return { ok, status, body: JSON.parse(data) }
} catch (error) {
Logger.error(`${TAG}@postToAttestationService`, 'Error calling proxyReveal', error)
// The httpsCallable throws on any HTTP error code instead of
// setting response.ok like fetch does, so catching errors here
return { ok: false, status: 500, body: error }
}
} else {
Logger.debug(
`${TAG}@postToAttestationService`,
`Revealing with contract kit for service url ${attestationServiceUrl}`
)
const response = await attestationsWrapper.revealPhoneNumberToIssuer(
attestationServiceUrl,
revealRequestBody
)
const body = await response.json()
return { ok: response.ok, status: response.status, body }
}
Logger.debug(
`${TAG}@postToAttestationService`,
`Revealing with contract kit for service url ${attestationServiceUrl}`
)
const response = await attestationsWrapper.revealPhoneNumberToIssuer(
attestationServiceUrl,
revealRequestBody
)
const body = await response.json()
return { ok: response.ok, status: response.status, body }
}

// Report to analytics reveal status from validator
Expand All @@ -1094,56 +1069,29 @@ export function* reportRevealStatusSaga({
pepper,
}: ReportRevealStatusAction) {
let aggregatedResponse: undefined | { ok: boolean; status: number; body: any }
if (shouldUseProxy()) {
Logger.debug(
`${TAG}@reportRevealStatusSaga`,
`Posting to proxy for service url ${attestationServiceUrl}`
)
const fullUrl = attestationServiceUrl + '/get_attestations'
const body = {
attestationServiceUrl: fullUrl,
const contractKit = yield call(getContractKit)
const attestationsWrapper: AttestationsWrapper = yield call([
contractKit.contracts,
contractKit.contracts.getAttestations,
])
Logger.debug(
`${TAG}@reportAttestationRevealStatus`,
`Start for service url ${attestationServiceUrl}`
)
try {
const response = yield call(
attestationsWrapper.getRevealStatus,
e164Number,
account,
phoneNumber: e164Number,
issuer,
pepper,
}
try {
const proxyReveal = functions().httpsCallable('proxyRevealStatus')
const response = yield call(proxyReveal, body)
const { status, data } = response.data
const ok = status >= 200 && status < 300
aggregatedResponse = { ok, status, body: JSON.parse(data) }
} catch (error) {
Logger.error(`${TAG}@reportAttestationRevealStatus`, 'Error calling proxyRevealStatus', error)
// The httpsCallable throws on any HTTP error code instead of
// setting response.ok like fetch does, so catching errors here
aggregatedResponse = { ok: false, status: 500, body: error }
}
} else {
const contractKit = yield call(getContractKit)
const attestationsWrapper: AttestationsWrapper = yield call([
contractKit.contracts,
contractKit.contracts.getAttestations,
])
Logger.debug(
`${TAG}@reportAttestationRevealStatus`,
`Start for service url ${attestationServiceUrl}`
attestationServiceUrl,
pepper
)
try {
const response = yield call(
attestationsWrapper.getRevealStatus,
e164Number,
account,
issuer,
attestationServiceUrl,
pepper
)
const body = yield call(response.json.bind(response))
aggregatedResponse = { ok: response.ok, body, status: response.status }
} catch (error) {
Logger.error(`${TAG}@reportAttestationRevealStatus`, 'Error calling proxyRevealStatus', error)
aggregatedResponse = { ok: false, status: 500, body: error }
}
const body = yield call(response.json.bind(response))
aggregatedResponse = { ok: response.ok, body, status: response.status }
} catch (error) {
Logger.error(`${TAG}@reportAttestationRevealStatus`, 'Error calling proxyRevealStatus', error)
aggregatedResponse = { ok: false, status: 500, body: error }
}
if (aggregatedResponse.ok) {
Logger.debug(
Expand Down Expand Up @@ -1210,7 +1158,3 @@ function* waitForAttestationCode(issuer: string) {
function* getPhoneHashDetails(e164Number: string) {
return yield call(fetchPhoneHashPrivate, e164Number)
}

function shouldUseProxy() {
return DEFAULT_TESTNET === 'mainnet'
}
6 changes: 5 additions & 1 deletion packages/sdk/contractkit/src/wrappers/Attestations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,11 @@ export class AttestationsWrapper extends BaseWrapper<Attestations> {

const nameClaim = metadata.findClaim(ClaimTypes.NAME)

const resp = await fetch(`${attestationServiceURLClaim.url}status`)
const resp = await fetch(
`${attestationServiceURLClaim.url}${
attestationServiceURLClaim.url.substr(-1) === '/' ? '' : '/'
}status`
)
if (!resp.ok) {
throw new Error(`Request failed with status ${resp.status}`)
}
Expand Down
5 changes: 0 additions & 5 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5743,11 +5743,6 @@
resolved "https://registry.yarnpkg.com/@react-native-firebase/dynamic-links/-/dynamic-links-6.7.1.tgz#1de460a2014818a9b1ed8706eb635d8fea59556d"
integrity sha512-y4xh1zznBLcBy7Gl1rlyPDhTyXcOss8jT1/2fa/e9cmlhCC13WJ3qz/oh61q5K6L61bFtR25DIZggW1MfMjThA==

"@react-native-firebase/functions@^6.7.1":
version "6.8.1"
resolved "https://registry.yarnpkg.com/@react-native-firebase/functions/-/functions-6.8.1.tgz#0098f1609418f76556e903fc7c96ae9ae9338558"
integrity sha512-F775T2Ef05UcophtCBpBm8o0U+76Zcv9x3jsqaQiG5gl3K7+0MhDp3CUUwWDI3+ldP9SKi3SMY6qogWpE7k40g==

"@react-native-firebase/messaging@^6.7.1":
version "6.7.1"
resolved "https://registry.yarnpkg.com/@react-native-firebase/messaging/-/messaging-6.7.1.tgz#d53b73791567366d95fb423f094e2057027cc9fa"
Expand Down

0 comments on commit f2bbba6

Please sign in to comment.