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

CIP1: Attestation service #1078

Merged
merged 13 commits into from
Sep 27, 2019
Merged

CIP1: Attestation service #1078

merged 13 commits into from
Sep 27, 2019

Conversation

nambrot
Copy link
Contributor

@nambrot nambrot commented Sep 23, 2019

Description

This PR adds the minimum possible version for CIP1 celo-org/celo-proposals#1

It currently does the following:

  • Receives a request from anyone
  • Signs the request with a configured key
  • Sends the attestation message to the specified phone number

Outstanding work that we'll want prior to betanet

Outstanding work that we should do eventually but does not need to happen right now:

Tested

  • Tested locally for the integration network and it produced a well-formed attestation message

Related issues

@nambrot nambrot assigned jmrossy and unassigned jmrossy Sep 23, 2019
@nambrot nambrot assigned nambrot and jmrossy and unassigned jmrossy Sep 23, 2019
@ashishb ashishb closed this Sep 24, 2019
@ashishb ashishb deleted the nambrot/attestation-service branch September 24, 2019 01:26
@ashishb ashishb restored the nambrot/attestation-service branch September 24, 2019 01:35
@ashishb ashishb reopened this Sep 24, 2019
@codecov
Copy link

codecov bot commented Sep 24, 2019

Codecov Report

Merging #1078 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master    #1078   +/-   ##
=======================================
  Coverage   66.45%   66.45%           
=======================================
  Files         256      256           
  Lines        7367     7367           
  Branches      427      491   +64     
=======================================
  Hits         4896     4896           
+ Misses       2381     2379    -2     
- Partials       90       92    +2
Flag Coverage Δ
#mobile 66.45% <ø> (ø) ⬆️
Impacted Files Coverage Δ
packages/mobile/src/utils/formatting.ts 87.5% <0%> (ø) ⬆️
packages/mobile/src/identity/reducer.ts 41.66% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update e2fe7a4...459682a. Read the comment docs.

@nambrot nambrot assigned jmrossy and unassigned nambrot Sep 24, 2019
packages/attestation-service/package.json Outdated Show resolved Hide resolved
"build": "tsc -b .",
"clean": "tsc -b . --clean",
"clean:all": "yarn clean && rm -rf src/generated",
"build:gen": "yarn --cwd ../protocol build",
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this command relevant here?

Copy link
Contributor

Choose a reason for hiding this comment

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

You missed this one

packages/attestation-service/package.json Outdated Show resolved Hide resolved
packages/attestation-service/package.json Outdated Show resolved Hide resolved
packages/attestation-service/src/server.ts Outdated Show resolved Hide resolved
packages/attestation-service/src/server.ts Outdated Show resolved Hide resolved

const phoneUtil = PhoneNumberUtil.getInstance()

let nexmoClient: any
Copy link
Contributor

Choose a reason for hiding this comment

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

can we type this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The library unfortunately does not have any types

Copy link
Contributor

Choose a reason for hiding this comment

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

You can define you own but not important for now

}

export async function handleAttestationRequest(req: express.Request, res: express.Response) {
// TODO: Should parse request appropriately
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggest adding error handling at this level

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, and have a separate ticket for it #1075

Copy link
Contributor

Choose a reason for hiding this comment

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

It's not just about malformed requests, if you code throws an exception somewhere (like when sending with Nexmo), that will propagate all the way up and the 500 we return will leak details about the internal error

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My goal would it be to handle this more globally with that ticket. You are right that the ticket did not specify that, I edited the ticket

packages/utils/src/attestations.ts Outdated Show resolved Hide resolved
@jmrossy jmrossy assigned nambrot and unassigned jmrossy Sep 24, 2019

init().catch((err) => {
console.error(`Error occurred while running server, exiting ....`)
console.error(err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit, err can beg the 2nd param of the previous console.error call

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 personally like the error on a separate line, do you mind keeping it this way?

export async function sendSms(phoneNumber: string, message: string) {
const countryCode = phoneUtil.getRegionCodeForNumber(phoneUtil.parse(phoneNumber))

if (countryCode === undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Consider if (!countryCode)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed it, though I'm generally a fan of comparing to undefined as ! will also match the '' 0, etc.

Copy link
Contributor

Choose a reason for hiding this comment

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

right, that's really the benefit though. If getRegionCodeForNumber returns null instead of undefined, that's now covered

@nambrot nambrot assigned jmrossy and unassigned nambrot Sep 25, 2019
@jmrossy jmrossy assigned nambrot and unassigned jmrossy Sep 25, 2019
@nambrot nambrot merged commit c34eef3 into master Sep 27, 2019
@mcortesi mcortesi deleted the nambrot/attestation-service branch December 4, 2019 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Validators SBAT run an attestation service
3 participants