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

Update ODIS Monitor to Cloud Function Gen2 #168

Merged
merged 9 commits into from
Nov 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions .changeset/ten-beers-build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@celo/phone-number-privacy-monitor': minor
---

Updated to run on cloud function gen2 using node18. Updated test script to point to latest Clabs Signer deployments.
12 changes: 0 additions & 12 deletions apps/monitor/.env

This file was deleted.

3 changes: 3 additions & 0 deletions apps/monitor/.env.celo-pgpnp-mainnet
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PHONE_NUMBER=+14155550123
MONITOR_CONTEXT_NAME=mainnet
BLOCKCHAIN_PROVIDER=https://forno.celo.org
3 changes: 3 additions & 0 deletions apps/monitor/.env.celo-phone-number-privacy
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PHONE_NUMBER=+14155550123
MONITOR_CONTEXT_NAME=alfajores
BLOCKCHAIN_PROVIDER=https://alfajores-forno.celo-testnet.org
3 changes: 3 additions & 0 deletions apps/monitor/.env.celo-phone-number-privacy-stg
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PHONE_NUMBER=+14155550123
MONITOR_CONTEXT_NAME=alfajoresstaging
BLOCKCHAIN_PROVIDER=https://alfajores-forno.celo-testnet.org
10 changes: 5 additions & 5 deletions apps/monitor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"license": "Apache-2.0",
"main": "dist/index.js",
"scripts": {
"deploy": "yarn build && firebase deploy --only functions:odisMonitorScheduleFunctionLegacyPNP,functions:odisMonitorScheduleFunctionPNP,functions:odisMonitorScheduleFunctionDomains",
"deploy": "yarn build && firebase deploy --only functions:odisMonitorScheduleFunctionPNPGen2,functions:odisMonitorScheduleFunctionDomainsGen2",
"deploy:staging": "yarn deploy --project celo-phone-number-privacy-stg",
"deploy:alfajores": "yarn deploy --project celo-phone-number-privacy",
"deploy:mainnet": "yarn deploy --project celo-pgpnp-mainnet",
Expand All @@ -31,17 +31,17 @@
"@celo/phone-number-privacy-common": "^3.1.1",
"@celo/utils": "^5.0.5",
"@celo/wallet-local": "^5.1.0",
"firebase-admin": "^9.12.0",
"firebase-functions": "^3.15.7",
"firebase-admin": "^11.11.0",
"firebase-functions": "^4.5.0",
"yargs": "^14.0.0"
},
"devDependencies": {
"firebase-functions-test": "^3.1.0",
"firebase-tools": "9.20.0",
"firebase-tools": "12.9.1",
"jest": "^29.7.0",
"ts-node": "^10.9.1"
},
"engines": {
"node": ">=14"
"node": "18"
}
}
26 changes: 12 additions & 14 deletions apps/monitor/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import * as functions from 'firebase-functions'
import { defineString } from 'firebase-functions/params'
import * as functions from 'firebase-functions/v2/scheduler'
import { testDomainSignQuery, testPNPSignQuery } from './test'

const contextName = functions.config().monitor.context_name
const blockchainProvider = functions.config().blockchain.provider
if (!contextName || !blockchainProvider) {
throw new Error('blockchain provider and context name must be set in function config')
}
const contextName = defineString('MONITOR_CONTEXT_NAME')
const blockchainProvider = defineString('BLOCKCHAIN_PROVIDER')

export const odisMonitorScheduleFunctionPNP = functions
.region('us-central1')
.pubsub.schedule('every 5 minutes')
.onRun(async () => testPNPSignQuery(blockchainProvider, contextName))
export const odisMonitorScheduleFunctionPNPGen2 = functions.onSchedule(
'every 5 minutes',
async () => testPNPSignQuery(blockchainProvider.value(), contextName.value() as any),
)

export const odisMonitorScheduleFunctionDomains = functions
.region('us-central1')
.pubsub.schedule('every 5 minutes')
.onRun(async () => testDomainSignQuery(contextName))
export const odisMonitorScheduleFunctionDomainsGen2 = functions.onSchedule(
'every 5 minutes',
async () => testDomainSignQuery(contextName.value() as any),
)
6 changes: 4 additions & 2 deletions apps/monitor/src/query.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,16 @@ import {
OdisAPI,
OdisContextName,
} from '@celo/identity/lib/odis/query'
import { fetchEnv } from '@celo/phone-number-privacy-common'
import { genSessionID } from '@celo/phone-number-privacy-common/lib/utils/logger'
import { normalizeAddressWith0x, privateKeyToAddress } from '@celo/utils/lib/address'
import { defined } from '@celo/utils/lib/sign-typed-data-utils'
import { LocalWallet } from '@celo/wallet-local'
import { defineString } from 'firebase-functions/params'
import { dekAuthSigner, generateRandomPhoneNumber, PRIVATE_KEY } from './resources'

let phoneNumber = fetchEnv('PHONE_NUMBER')
let phoneNumber: string

const defaultPhoneNumber = defineString('PHONE_NUMBER')
const newPrivateKey = async () => {
const mnemonic = await generateMnemonic(MnemonicStrength.s256_24words)
return (await generateKeys(mnemonic)).privateKey
Expand Down Expand Up @@ -63,6 +64,7 @@ export const queryOdisForSalt = async (
authenticationMethod: OdisUtils.Query.AuthenticationMethod.WALLET_KEY,
contractKit,
}
phoneNumber = defaultPhoneNumber.value()
}

const abortController = new AbortController()
Expand Down
Loading
Loading