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

Create @celo/encrypted-backup backup for ODIS hardened password encrypted backups #8896

Merged
merged 111 commits into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from 67 commits
Commits
Show all changes
111 commits
Select commit Hold shift + click to select a range
045f34b
create encrypted-backup package
Oct 23, 2021
596bd87
basic backup and open functions working without any key hardening
Oct 26, 2021
5fe1f33
basic backup and open functions working without any key hardening
Oct 26, 2021
3728e2d
Merge branch 'victor/encrypted-backup-library' of github.com:celo-org…
Oct 26, 2021
dc8b2f5
Merge branch 'master' of github.com:celo-org/celo-monorepo into victo…
Oct 26, 2021
c68de43
use io-ts to create serialization and deserialization functions
Oct 27, 2021
be6a077
Merge github.com:celo-org/celo-monorepo into victor/encrypted-backup-…
Oct 28, 2021
4b5814b
extract the encryption and decryption logic from the main functions
Oct 28, 2021
a8df18d
add io-ts schema definitions for Domain types
Oct 29, 2021
9d16856
add domain field to backup type and schema
Oct 29, 2021
292fd00
Merge github.com:celo-org/celo-monorepo into victor/encrypted-backup-…
Nov 2, 2021
db0245a
mix in the domain hash to the key as a simple proxy for ODIS
Nov 3, 2021
1cecf26
add a stub to hold the place of circuit breaker functions
Nov 3, 2021
b709305
Merge github.com:celo-org/celo-monorepo into victor/encrypted-backup-…
Nov 4, 2021
5ffeffb
update the dependency graph
Nov 4, 2021
9eb9bce
swap order of circuit breaker and odis stubs
Nov 4, 2021
ccd0b50
[broken] move domains source from @celo/identity to @celo/phone-numbe…
Nov 4, 2021
d2d09f4
[broken] remove @celo/identity dependency from @celo/phone-number-pri…
Nov 4, 2021
abea003
finish removing @celo/identity and a dependency of @celo/phone-number…
Nov 5, 2021
3c750ef
remove duplication and inconsistencies betweem @celo/identity and @ce…
Nov 5, 2021
92e5afa
fix linter errors
Nov 5, 2021
5e4568a
Merge github.com:celo-org/celo-monorepo into victor/encrypted-backup-…
Nov 8, 2021
071e329
clean up domain state and response types
Nov 9, 2021
8055225
[checkpoint] partially implemented key hardening through ODIS
Nov 9, 2021
1d830bd
refactor phone-number-privacy a little
Nov 10, 2021
39544fb
initial implementaion of odis key hardening logic
Nov 10, 2021
663d34b
wire in odis key hardening
Nov 11, 2021
b586bc7
fix issues occuring during package initialization
Nov 13, 2021
c0c537b
tests now working against a mock implementation of ODIS
Nov 13, 2021
4abfa0e
add (untested) circuit breaker client implementation
Nov 16, 2021
a445bd1
add comments and pipe in circuit breaker config values
Nov 16, 2021
3a7f9c7
Merge github.com:celo-org/celo-monorepo into victor/encrypted-backup-…
Nov 16, 2021
c995445
fix issues founds in manual testing
Nov 16, 2021
07ab834
add a mock and tests for circuit breaker client
Nov 16, 2021
d270a77
add a NO_GANACHE env variable to disable starting ganache for testing
Nov 16, 2021
57d3ac5
round out tests for the circuit breaker client
Nov 16, 2021
eda0dbf
refactor the mock circuit breaker to be ready to export
Nov 16, 2021
f69813d
use the circuit breaker for key hardening
Nov 17, 2021
d13309b
Merge github.com:celo-org/celo-monorepo into victor/encrypted-backup-…
Nov 22, 2021
fab3ae2
bump package versions
Nov 23, 2021
4da9989
add more information to error handling and debug messages
Nov 23, 2021
2f3b2c7
add doc strings to create and open backup functions
Nov 23, 2021
24601d3
add wrapper function createPinEncryptedBackup with documentation
Nov 23, 2021
445f341
refactor mock odis
Nov 23, 2021
f35ae96
handle 429 status from ODIS and add some error condition tests to bac…
Nov 23, 2021
09e7fd4
seperate handling of fetch errors and add more error case tests
Nov 23, 2021
23fea08
add tests for error cases in openBackup
Nov 23, 2021
9de9a4c
remove DO NOT MERGE note
Nov 23, 2021
b611ca9
update dependency graph
Nov 23, 2021
073c241
add more information to comments
Nov 23, 2021
9ab4761
add links to the new documentation
Nov 24, 2021
9fae41d
fix build error in signer
Nov 24, 2021
3975472
Merge branch 'master' into victor/encrypted-backup-library
Nov 24, 2021
bfaae46
Merge branch 'victor/encrypted-backup-library' of github.com:celo-org…
Nov 24, 2021
e27cadc
change request type definitions and checkSequentialDelay function
Nov 26, 2021
f468069
fix linter errors
Nov 26, 2021
7846660
Merge github.com:celo-org/celo-monorepo into victor/encrypted-backup-…
Nov 26, 2021
1d2604b
fix linter errors
Nov 26, 2021
7f87d68
but like really, fix linter errors
Nov 26, 2021
b6b1f23
ok I was only joking before about fixing the linter errors. this time…
Nov 26, 2021
37c29ec
add support for computational key hardening [lacks schema or tests]
Nov 27, 2021
350c26a
Merge branch 'master' into victor/encrypted-backup-library
Dec 6, 2021
e4c01b4
Merge branch 'victor/encrypted-backup-library' of github.com:celo-org…
Dec 6, 2021
56e0b15
extract odis mock to new file
Dec 6, 2021
97ed7a9
add computational hardening to test config
Dec 7, 2021
3a1ccb4
add failure case tests for mutated backups
Dec 7, 2021
8ea68fe
add computational hardening to schema
Dec 7, 2021
6dd6d17
Update packages/sdk/identity/src/odis/circuit-breaker.ts
Dec 14, 2021
ff3f8c5
Merge branch 'master' of github.com:celo-org/celo-monorepo into victo…
Jan 5, 2022
5763a18
consolidate imports
Jan 5, 2022
37a1137
address review comments
Jan 5, 2022
e102af0
add odis verification error type
Jan 6, 2022
26941d8
add safety gate to prevent use of OPRF function for key hardening in …
Jan 6, 2022
93dfd53
bump dep versions in phone-number-privacy-common
Jan 6, 2022
e6b4c62
remove new code for encrypted backup
Jan 6, 2022
4a8ab7e
Revert "remove new code for encrypted backup"
Jan 6, 2022
bc66ea7
populate index.ts file
Jan 6, 2022
77c48f1
fix import
Jan 6, 2022
96c9a8d
Merge branch 'victor/encrypted-backup-library-base' into victor/encry…
Jan 6, 2022
325f773
fix import again
Jan 6, 2022
8a521fc
Merge branch 'victor/encrypted-backup-library-base' into victor/encry…
Jan 6, 2022
cced2f4
update dep graphy
Jan 6, 2022
bc2f320
fix lint errors
Jan 6, 2022
a63264f
fix lint error
Jan 6, 2022
0a2afe5
Merge branch 'victor/encrypted-backup-library-base' into victor/encry…
Jan 6, 2022
7ba3dbf
update dependency graph
Jan 6, 2022
30bfc89
Merge branch 'master' into victor/encrypted-backup-library-base
alecps Jan 7, 2022
b0cc9f6
remove outdated DO NOT MERGE
Jan 7, 2022
8296695
add phone-number-privacy-common to package list and sort the list
Jan 7, 2022
8daa03b
Merge github.com:celo-org/celo-monorepo into victor/encrypted-backup-…
Jan 7, 2022
8df35ff
Merge branch 'victor/encrypted-backup-library-base' of github.com:cel…
Jan 7, 2022
7ba5c5d
add @types/express as dev dependency
Jan 7, 2022
91ea577
Merge branch 'victor/encrypted-backup-library-base' into victor/encry…
Jan 7, 2022
3e1b2ef
update circuit breaker keys to production values
Jan 8, 2022
1a1e699
Merge github.com:celo-org/celo-monorepo into victor/encrypted-backup-…
Jan 8, 2022
b702a63
Merge branch 'master' into victor/encrypted-backup-library
Jan 11, 2022
c70db7f
Merge branch 'master' into victor/encrypted-backup-library
Jan 21, 2022
6c45f81
Merge branch 'master' into victor/encrypted-backup-library
Jan 27, 2022
0527363
fix typos and add DO NOT MERGE comments for changes to be made
Feb 1, 2022
a99ebd1
bump development version of phone-number-privacy-common package
Feb 17, 2022
b7f90e6
address most of the DO NOT MERGE comments
Feb 17, 2022
87fa958
add createPasswordEncryptedBackup function
Feb 17, 2022
6cf433a
add safety measure to prevent accidental usage of the createBackup AP…
Feb 17, 2022
97396ad
Merge branch 'master' of github.com:celo-org/celo-monorepo into victo…
Feb 17, 2022
4746079
fix usages of renamed Endpoint enum
Feb 17, 2022
b7b5915
fix enum types
Feb 17, 2022
2c85c9f
remove accidentally added walletconnect package
Feb 17, 2022
8efc6fb
fix lint error
Feb 17, 2022
29e78a4
fix another lint error
Feb 17, 2022
4a4e9f9
fix dangling reference to CustomSigner
Feb 17, 2022
5a18a88
remove dangling refernce to signWithRawKey
Feb 17, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion dependency-graph.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@
"dependencies": [
"@celo/base",
"@celo/contractkit",
"@celo/identity",
"@celo/utils",
"@celo/wallet-local"
]
Expand Down Expand Up @@ -171,6 +170,17 @@
"@celo/utils"
]
},
"@celo/encrypted-backup": {
"location": "packages/sdk/encrypted-backup",
"dependencies": [
"@celo/base",
"@celo/dev-utils",
"@celo/flake-tracker",
"@celo/identity",
"@celo/phone-number-privacy-common",
"@celo/utils"
]
},
"@celo/explorer": {
"location": "packages/sdk/explorer",
"dependencies": [
Expand All @@ -197,6 +207,7 @@
"@celo/contractkit",
"@celo/dev-utils",
"@celo/flake-tracker",
"@celo/phone-number-privacy-common",
"@celo/utils",
"@celo/wallet-local"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export class BLSCryptographyClient {
blindedMessage: string,
logger?: Logger
): Promise<string> {
logger = logger ?? rootLogger
logger = logger ?? rootLogger()
const threshold = config.thresholdSignature.threshold
if (!this.hasSufficientSignatures()) {
logger.error(
Expand Down
2 changes: 1 addition & 1 deletion packages/phone-number-privacy/combiner/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ interface Config {
let config: Config

if (DEV_MODE) {
logger.debug('Running in dev mode')
logger().debug('Running in dev mode')
config = {
blockchain: {
provider: FORNO_ALFAJORES,
Expand Down
6 changes: 2 additions & 4 deletions packages/phone-number-privacy/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
"dependencies": {
"@celo/base": "1.3.3",
"@celo/contractkit": "1.3.3",
"@celo/identity": "1.3.3-dev",
"@celo/utils": "1.3.3-dev",
"bignumber.js": "^9.0.0",
"blind-threshold-bls": "https://github.com/celo-org/blind-threshold-bls-wasm#e1e2f8a",
Expand All @@ -30,8 +29,7 @@
"bunyan-gke-stackdriver": "0.1.2",
"dotenv": "^8.2.0",
"elliptic": "^6.5.4",
"is-base64": "^1.1.0",
"libphonenumber-js": "^1.9.11"
"is-base64": "^1.1.0"
},
"devDependencies": {
"@celo/wallet-local": "1.3.3-dev",
Expand All @@ -44,4 +42,4 @@
"engines": {
"node": ">=10"
}
}
}
9 changes: 9 additions & 0 deletions packages/phone-number-privacy/common/src/domains/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/**
* Enum of identifiers (i.e. names) for all standardized domains
*
* @privateRemarks DomainIdentifiers is defined in a separate file to avoid issues with circular
* dependencies causing undefined errors.
*/
export enum DomainIdentifiers {
SequentialDelay = 'ODIS Sequential Delay Domain',
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,9 @@ import {
noNumber,
noString,
} from '@celo/utils/lib/sign-typed-data-utils'
import {
Domain,
domainEIP712,
DomainOptions,
KnownDomain,
KnownDomainOptions,
SequentialDelayDomain,
SequentialDelayDomainOptions,
} from './domains'
import { DomainIdentifiers } from './constants'
import { Domain, domainEIP712, DomainOptions, KnownDomain, KnownDomainOptions } from './domains'
import { SequentialDelayDomain, SequentialDelayDomainOptions } from './sequential-delay'

// Compile-time check that Domain can be cast to type EIP712Object
export const TEST_DOMAIN_IS_EIP712: EIP712Object = ({} as unknown) as Domain
Expand All @@ -36,7 +30,7 @@ TEST_KNOWN_DOMAIN_DOMAIN_OPTIONS_ARE_DOMAIN_OPTIONS = ({} as unknown) as KnownDo
describe('domainEIP712()', () => {
it('should generate the correct type data for SequentialDelayDomain instance', () => {
const domain: SequentialDelayDomain = {
name: 'ODIS Sequential Delay Domain',
name: DomainIdentifiers.SequentialDelay,
version: '1',
stages: [
{ delay: 0, resetTimer: noBool, batchSize: defined(2), repetitions: noNumber },
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
import {
EIP712Object,
EIP712ObjectValue,
EIP712Optional,
eip712OptionalType,
EIP712TypedData,
EIP712TypesWithPrimary,
generateTypedDataHash,
} from '@celo/utils/lib/sign-typed-data-utils'
import * as t from 'io-ts'
import {
isSequentialDelayDomain,
SequentialDelayDomain,
sequentialDelayDomainEIP712Types,
SequentialDelayDomainOptions,
sequentialDelayDomainOptionsEIP712Types,
SequentialDelayDomainSchema,
SequentialDelayDomainState,
} from './sequential-delay'

// Concrete Domain subtypes are only assignable to Domain and EIP712Object when using type instead
// of interface. Otherwise the compiler complains about a missing index signature.
Expand All @@ -33,100 +41,6 @@ export interface Domain {
*/
export type DomainOptions = EIP712Object

export type SequentialDelayStage = {
/**
* How many seconds each batch of attempts in this stage is delayed with
* respect to the timer.
*/
delay: number
/**
* Whether the timer should be reset between attempts during this stage.
* Defaults to true.
*/
resetTimer: EIP712Optional<boolean>
/**
* The number of continuous attempts a user gets before the next delay
* in each repetition of this stage. Defaults to 1.
*/
batchSize: EIP712Optional<number>
/**
* The number of times this stage repeats before continuing to the next stage
* in the RateLimit array. Defaults to 1.
*/
repetitions: EIP712Optional<number>
}

export type SequentialDelayDomain = {
name: 'ODIS Sequential Delay Domain'
version: '1'
stages: SequentialDelayStage[]
/**
* Optional Celo address against which signed requests must be authenticated.
* In the case of Cloud Backup, this will be derived from a one-time key stored with the ciphertext.
* Encoded as a checksummed address with leading "0x".
*/
address: EIP712Optional<string>
/**
* Optional string to distinguish the output of this domain instance from
* other SequentialDelayDomain instances
*/
salt: EIP712Optional<string>
}

export type SequentialDelayDomainOptions = {
/**
* EIP-712 signature over the entire request by the address specified in the domain.
* Required if `address` is defined in the domain instance. If `address` is
* not defined in the domain instance, then a signature must not be provided.
* Encoded as a hex string with leading 0x.
*/
signature: EIP712Optional<string>
/**
* Used to prevent replay attacks. Required if a signature is provided.
* Code verifying the signature for rate limiting should check this nonce against a counter of
* applied requests. E.g. Ensure the nonce is 0 on the first request and 2 on the third.
*/
nonce: EIP712Optional<number>
}

export const isSequentialDelayDomain = (domain: Domain): domain is SequentialDelayDomain =>
domain.name === 'ODIS Sequential Delay Domain' && domain.version === '1'

export const sequentialDelayDomainEIP712Types: EIP712TypesWithPrimary = {
types: {
SequentialDelayDomain: [
{ name: 'address', type: 'Optional<address>' },
{ name: 'name', type: 'string' },
{ name: 'salt', type: 'Optional<string>' },
{ name: 'stages', type: 'SequentialDelayStage[]' },
{ name: 'version', type: 'string' },
],
SequentialDelayStage: [
{ name: 'batchSize', type: 'Optional<uint256>' },
{ name: 'delay', type: 'uint256' },
{ name: 'repetitions', type: 'Optional<uint256>' },
{ name: 'resetTimer', type: 'Optional<bool>' },
],
...eip712OptionalType('address'),
...eip712OptionalType('string'),
...eip712OptionalType('uint256'),
...eip712OptionalType('bool'),
},
primaryType: 'SequentialDelayDomain',
}

export const sequentialDelayDomainOptionsEIP712Types: EIP712TypesWithPrimary = {
types: {
SequentialDelayDomainOptions: [
{ name: 'nonce', type: 'Optional<uint256>' },
{ name: 'signature', type: 'Optional<string>' },
],
...eip712OptionalType('string'),
...eip712OptionalType('uint256'),
},
primaryType: 'SequentialDelayDomainOptions',
}

/**
* Union type of domains which are currently implmented and standardized for use with ODIS.
* Domains should be added to the union type as they are implemented.
Expand All @@ -135,6 +49,9 @@ export const sequentialDelayDomainOptionsEIP712Types: EIP712TypesWithPrimary = {
*/
export type KnownDomain = SequentialDelayDomain

/** io-ts schema for encoding and decoding domains of any standardized type */
export const KnownDomainSchema: t.Type<KnownDomain> = SequentialDelayDomainSchema

export function isKnownDomain(domain: Domain): domain is KnownDomain {
return isSequentialDelayDomain(domain)
}
Expand All @@ -148,6 +65,15 @@ export type KnownDomainOptions<
D extends KnownDomain = KnownDomain
> = D extends SequentialDelayDomain ? SequentialDelayDomainOptions : never

/**
* Parameterized union type of currently implemented and standarized domain state structs. If the
* type parameter is specified to be a concrete Domain subtype, then only its associated
* Domain state type is selected and assignable to the parameterized type.
*/
export type KnownDomainState<D extends KnownDomain = KnownDomain> = D extends SequentialDelayDomain
? SequentialDelayDomainState
: never

export function domainEIP712Types(domain: KnownDomain): EIP712TypesWithPrimary {
if (isSequentialDelayDomain(domain)) {
return sequentialDelayDomainEIP712Types
Expand Down
3 changes: 3 additions & 0 deletions packages/phone-number-privacy/common/src/domains/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './constants'
export * from './domains'
export * from './sequential-delay'
Loading