Skip to content

Commit

Permalink
Merge pull request #20 from celo-org/master
Browse files Browse the repository at this point in the history
master
  • Loading branch information
aaitor authored Dec 8, 2019
2 parents 181e782 + 1bee3f4 commit 6787bd5
Show file tree
Hide file tree
Showing 63 changed files with 643 additions and 817 deletions.
3 changes: 1 addition & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,8 @@ jobs:
# separate build to avoid ENOMEM in CI :(
yarn build --scope @celo/utils
yarn build --scope @celo/protocol
yarn build --scope docs
yarn build --scope @celo/walletkit
yarn build --ignore @celo/protocol --ignore docs --ignore @celo/walletkit
yarn build --ignore @celo/protocol --ignore docs --ignore @celo/walletkit --ignore @celo/web
- run:
name: Check licenses
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and other packages.
The source code for the Celo Blockchain which operates a node on the Celo Network is kept in a separate repo [here](https://github.com/celo-org/celo-blockchain).

### Celo's Mission - Prosperity for All

Celo, pronounced /ˈtselo/, means ‘purpose’ in Esperanto. In a similar spirit, we are aiming to create a new platform to connect people globally and bring financial stability to those who need it most. We believe blockchain technology is one of the most exciting innovations in recent history and as a community we look to push the boundaries of what is possible with it today. More importantly, we are driven by purpose -- to solve real-world problems such as lack of access to sound currency, or friction for cash-transfer programs aimed to alleviate poverty. Our mission is to build a monetary system that creates the conditions for prosperity for all.

<!-- image with YouTube link -->
Expand All @@ -21,7 +22,6 @@ Celo, pronounced /ˈtselo/, means ‘purpose’ in Esperanto. In a similar spiri
<i>What if money were beautiful?</i>
</p>


### The Celo Stack

Celo is oriented around providing the simplest possible experience for end users, who may have no familiarity with cryptocurrencies, and may be using low cost devices with limited connectivity. To achieve this, the project takes a full-stack approach, where each layer of the stack is designed with the end user in mind whilst considering other stakeholders \(e.g. operators of nodes in the network\) involved in enabling the end user experience.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AttestationState } from '@celo/contractkit/lib/wrappers/Attestations'
import { attestationMessageToSign } from '@celo/utils'
import { AttestationUtils } from '@celo/utils'
import { toChecksumAddress } from '@celo/utils/lib/address'
import { AddressType, E164PhoneNumberType } from '@celo/utils/lib/io'
import Logger from 'bunyan'
Expand Down Expand Up @@ -144,7 +144,7 @@ class AttestationRequestHandler {
}

signAttestation() {
const message = attestationMessageToSign(
const message = AttestationUtils.getAttestationMessageToSignFromIdentifier(
this.attestationRequest.phoneNumber,
this.attestationRequest.account
)
Expand Down
2 changes: 1 addition & 1 deletion packages/blockchain-api/.env
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ EXCHANGE_RATES_API=https://apilayer.net/api
BLOCKSCOUT_API=https://integration-blockscout.celo-testnet.org/api
FAUCET_ADDRESS=0x47e172F6CfB6c7D01C1574fa3E2Be7CC73269D95
VERIFICATION_REWARDS_ADDRESS=0xb4fdaf5f3cd313654aa357299ada901b1d2dd3b5
WEB3_PROVIDER_URL=https://integration-forno.celo-testnet.org/
WEB3_PROVIDER_URL=https://integration-forno.celo-testnet.org
2 changes: 1 addition & 1 deletion packages/blockchain-api/app.alfajores.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ env_variables:
# TODO Pull addresses from the build artifacts of the network in protocol/build
FAUCET_ADDRESS: "0xCEa3eF8e187490A9d85A1849D98412E5D27D1Bb3"
VERIFICATION_REWARDS_ADDRESS: "0xb4fdaf5f3cd313654aa357299ada901b1d2dd3b5"
WEB3_PROVIDER_URL: "https://alfajores-forno.celo-testnet.org/"
WEB3_PROVIDER_URL: "https://alfajores-forno.celo-testnet.org"
2 changes: 1 addition & 1 deletion packages/blockchain-api/app.alfajoresstaging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ env_variables:
# TODO Pull addresses from the build artifacts of the network in protocol/build
FAUCET_ADDRESS: "0xF4314cb9046bECe6AA54bb9533155434d0c76909"
VERIFICATION_REWARDS_ADDRESS: "0xb4fdaf5f3cd313654aa357299ada901b1d2dd3b5"
WEB3_PROVIDER_URL: "https://alfajoresstaging-forno.celo-testnet.org/"
WEB3_PROVIDER_URL: "https://alfajoresstaging-forno.celo-testnet.org"
2 changes: 1 addition & 1 deletion packages/blockchain-api/app.integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ env_variables:
# TODO Pull addresses from the build artifacts of the network in protocol/build
FAUCET_ADDRESS: "0x47e172F6CfB6c7D01C1574fa3E2Be7CC73269D95"
VERIFICATION_REWARDS_ADDRESS: "0xb4fdaf5f3cd313654aa357299ada901b1d2dd3b5"
WEB3_PROVIDER_URL: "https://integration-forno.celo-testnet.org/"
WEB3_PROVIDER_URL: "https://integration-forno.celo-testnet.org"
2 changes: 1 addition & 1 deletion packages/blockchain-api/app.pilot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ env_variables:
# TODO Pull addresses from the build artifacts of the network in protocol/build
FAUCET_ADDRESS: "0x387bCb16Bfcd37AccEcF5c9eB2938E30d3aB8BF2"
VERIFICATION_REWARDS_ADDRESS: "0xb4fdaf5f3cd313654aa357299ada901b1d2dd3b5"
WEB3_PROVIDER_URL: "https://pilot-infura.celo-testnet.org/"
WEB3_PROVIDER_URL: "https://pilot-forno.celo-testnet.org"
2 changes: 1 addition & 1 deletion packages/blockchain-api/app.pilotstaging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ env_variables:
# TODO Pull addresses from the build artifacts of the network in protocol/build
FAUCET_ADDRESS: "0x545DEBe3030B570731EDab192640804AC8Cf65CA"
VERIFICATION_REWARDS_ADDRESS: "0xb4fdaf5f3cd313654aa357299ada901b1d2dd3b5"
WEB3_PROVIDER_URL: "https://pilotstaging-forno.celo-testnet.org/"
WEB3_PROVIDER_URL: "https://pilotstaging-forno.celo-testnet.org"
2 changes: 1 addition & 1 deletion packages/celotool/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"dependencies": {
"@celo/verification-pool-api": "^1.0.0",
"@celo/utils": "^0.1.0",
"@celo/walletkit": "^0.0.14",
"@celo/walletkit": "^0.0.15",
"@celo/contractkit": "0.2.5-dev",
"@google-cloud/monitoring": "0.7.1",
"@google-cloud/pubsub": "^0.28.1",
Expand Down
6 changes: 3 additions & 3 deletions packages/celotool/src/cmds/account/faucet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,13 @@ export const handler = async (argv: FaucetArgv) => {

if (!goldAmount.isZero()) {
if (await reserve.isSpender(account)) {
// await reserve.transferGold(address, goldAmount.toFixed()).sendAndWaitForReceipt()
await reserve.transferGold(address, goldAmount.toFixed()).sendAndWaitForReceipt()
} else {
// await goldToken.transfer(address, goldAmount.toFixed()).sendAndWaitForReceipt()
await goldToken.transfer(address, goldAmount.toFixed()).sendAndWaitForReceipt()
}
}
if (!stableTokenAmount.isZero()) {
// await stableToken.transfer(address, stableTokenAmount.toFixed()).sendAndWaitForReceipt()
await stableToken.transfer(address, stableTokenAmount.toFixed()).sendAndWaitForReceipt()
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/celotool/src/cmds/account/verify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ async function verifyCmd(argv: VerifyArgv) {
const currentWalletAddress = await accounts.getWalletAddress(account)

if (currentWalletAddress !== account) {
const setWalletAddressTx = await accounts.setWalletAddress(account)
const setWalletAddressTx = accounts.setWalletAddress(account)
const result = await setWalletAddressTx.send()
await result.waitReceipt()
}
Expand Down
10 changes: 5 additions & 5 deletions packages/celotool/src/lib/attestation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
ActionableAttestation,
AttestationsWrapper,
} from '@celo/contractkit/lib/wrappers/Attestations'
import { PhoneNumberUtils } from '@celo/utils'
import { AttestationUtils, PhoneNumberUtils } from '@celo/utils'
import { concurrentMap } from '@celo/utils/lib/async'
import { sample } from 'lodash'
import moment from 'moment'
Expand All @@ -27,7 +27,7 @@ export async function requestMoreAttestations(
}

await attestations.waitForSelectingIssuers(phoneNumber, account)
await attestations.selectIssuers(phoneNumber).then((txo) => txo.sendAndWaitForReceipt(txParams))
await attestations.selectIssuers(phoneNumber).sendAndWaitForReceipt(txParams)
}

type RequestAttestationError =
Expand Down Expand Up @@ -99,7 +99,7 @@ export async function findValidCode(
) {
for (const message of messages) {
try {
const code = attestations.extractAttestationCodeFromMessage(message)
const code = AttestationUtils.extractAttestationCodeFromMessage(message)
if (!code) {
continue
}
Expand Down Expand Up @@ -218,8 +218,8 @@ export async function createPhoneNumber(
await twilioClient.incomingPhoneNumbers.create({
phoneNumber: usableNumber,
addressSid,
// We don't really care
smsUrl: 'https://celo.org',
// Just an requestbin.com endpoint to avoid errors
smsUrl: 'https://enzyutth0wxme.x.pipedream.net/',
})

return usableNumber
Expand Down
3 changes: 2 additions & 1 deletion packages/cli/src/utils/identity.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { ContractKit } from '@celo/contractkit'
import { ClaimTypes, IdentityMetadataWrapper } from '@celo/contractkit/lib/identity'
import { Claim, validateClaim, verifyClaim } from '@celo/contractkit/lib/identity/claims/claim'
import { Claim, validateClaim } from '@celo/contractkit/lib/identity/claims/claim'
import {
VALIDATABLE_CLAIM_TYPES,
VERIFIABLE_CLAIM_TYPES,
} from '@celo/contractkit/lib/identity/claims/types'
import { verifyClaim } from '@celo/contractkit/lib/identity/claims/verify'
import { concurrentMap } from '@celo/utils/lib/async'
import { NativeSigner } from '@celo/utils/lib/signatureUtils'
import { cli } from 'cli-ux'
Expand Down
3 changes: 2 additions & 1 deletion packages/contractkit/src/identity/claims/account.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { NativeSigner } from '@celo/utils/lib/signatureUtils'
import { newKitFromWeb3 } from '../../kit'
import { IdentityMetadataWrapper } from '../metadata'
import { createAccountClaim, MetadataURLGetter } from './account'
import { Claim, verifyClaim } from './claim'
import { Claim } from './claim'
import { verifyClaim } from './verify'

testWithGanache('Account claims', (web3) => {
const kit = newKitFromWeb3(web3)
Expand Down
28 changes: 2 additions & 26 deletions packages/contractkit/src/identity/claims/claim.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { hashMessage } from '@celo/utils/lib/signatureUtils'
import * as t from 'io-ts'
import { ContractKit } from '../../kit'
import { AccountClaim, AccountClaimType, MetadataURLGetter, verifyAccountClaim } from './account'
import { AccountClaim, AccountClaimType } from './account'
import {
AttestationServiceURLClaim,
AttestationServiceURLClaimType,
validateAttestationServiceUrl,
} from './attestation-service-url'
import { KeybaseClaim, KeybaseClaimType, verifyKeybaseClaim } from './keybase'
import { KeybaseClaim, KeybaseClaimType } from './keybase'
import { ClaimTypes, now, SignatureType, TimestampType } from './types'

const DomainClaimType = t.type({
Expand Down Expand Up @@ -57,30 +57,6 @@ export type ClaimPayload<K extends ClaimTypes> = K extends typeof ClaimTypes.DOM
export const isOfType = <K extends ClaimTypes>(type: K) => (data: Claim): data is ClaimPayload<K> =>
data.type === type

/**
* Verifies a claim made by an account, i.e. whether a claim can be verified to be correct
* @param claim The claim to verify
* @param address The address that is making the claim
* @param metadataURLGetter A function that can retrieve the metadata URL for a given account address,
* should be Accounts.getMetadataURL()
* @returns If valid, returns undefined. If invalid or unable to verify, returns a string with the error
*/
export async function verifyClaim(
claim: Claim,
address: string,
metadataURLGetter: MetadataURLGetter
) {
switch (claim.type) {
case ClaimTypes.KEYBASE:
return verifyKeybaseClaim(claim, address)
case ClaimTypes.ACCOUNT:
return verifyAccountClaim(claim, address, metadataURLGetter)
default:
break
}
return
}

/**
* Validates a claim made by an account, i.e. whether the claim is usable
* @param claim The claim to validate
Expand Down
67 changes: 67 additions & 0 deletions packages/contractkit/src/identity/claims/verify.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import { isValidUrl } from '@celo/utils/lib/io'
import { Address } from '../../base'
import { IdentityMetadataWrapper } from '../metadata'
import { AccountClaim } from './account'
import { Claim } from './claim'
import { verifyKeybaseClaim } from './keybase'
import { ClaimTypes } from './types'

/**
* Verifies a claim made by an account, i.e. whether a claim can be verified to be correct
* @param claim The claim to verify
* @param address The address that is making the claim
* @param metadataURLGetter A function that can retrieve the metadata URL for a given account address,
* should be Accounts.getMetadataURL()
* @returns If valid, returns undefined. If invalid or unable to verify, returns a string with the error
*/
export async function verifyClaim(
claim: Claim,
address: string,
metadataURLGetter: MetadataURLGetter
) {
switch (claim.type) {
case ClaimTypes.KEYBASE:
return verifyKeybaseClaim(claim, address)
case ClaimTypes.ACCOUNT:
return verifyAccountClaim(claim, address, metadataURLGetter)
default:
break
}
return
}

/**
* A function that can asynchronously fetch the metadata URL for an account address
* Should virtually always be Accounts#getMetadataURL
*/
export type MetadataURLGetter = (address: Address) => Promise<string>

export const verifyAccountClaim = async (
claim: AccountClaim,
address: string,
metadataURLGetter: MetadataURLGetter
) => {
const metadataURL = await metadataURLGetter(claim.address)

console.info(JSON.stringify(metadataURL))
if (!isValidUrl(metadataURL)) {
return `Metadata URL of ${claim.address} could not be retrieved`
}

let metadata: IdentityMetadataWrapper
try {
metadata = await IdentityMetadataWrapper.fetchFromURL(metadataURL)
} catch (error) {
return `Metadata could not be fetched for ${
claim.address
} at ${metadataURL}: ${error.toString()}`
}

const accountClaims = metadata.filterClaims(ClaimTypes.ACCOUNT)

if (accountClaims.find((x) => x.address === address) === undefined) {
return `${claim.address} did not claim ${address}`
}

return
}
Loading

0 comments on commit 6787bd5

Please sign in to comment.