From dc8e0053728e89ad11a0e43b52aa59f923fee39e Mon Sep 17 00:00:00 2001 From: Eela Nagaraj <7308464+eelanagaraj@users.noreply.github.com> Date: Tue, 21 Feb 2023 15:07:57 +0100 Subject: [PATCH] Remove ASv1-specific commands from the CLI --- .../account/claim-attestation-service-url.ts | 34 ---- .../cli/src/commands/account/deauthorize.ts | 3 +- .../identity/current-attestation-services.ts | 74 --------- .../identity/test-attestation-service.ts | 147 ------------------ packages/cli/src/utils/identity.ts | 27 +--- .../docs/command-line-interface/account.md | 37 +---- .../docs/command-line-interface/identity.md | 54 ------- 7 files changed, 7 insertions(+), 369 deletions(-) delete mode 100644 packages/cli/src/commands/account/claim-attestation-service-url.ts delete mode 100644 packages/cli/src/commands/identity/current-attestation-services.ts delete mode 100644 packages/cli/src/commands/identity/test-attestation-service.ts diff --git a/packages/cli/src/commands/account/claim-attestation-service-url.ts b/packages/cli/src/commands/account/claim-attestation-service-url.ts deleted file mode 100644 index 2437f3fc5eb..00000000000 --- a/packages/cli/src/commands/account/claim-attestation-service-url.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { createAttestationServiceURLClaim } from '@celo/contractkit/lib/identity/claims/attestation-service-url' -import { flags } from '@oclif/command' -import { Flags } from '../../utils/command' -import { ClaimCommand } from '../../utils/identity' -export default class ClaimAttestationServiceUrl extends ClaimCommand { - static description = - 'Claim the URL of the attestation service and add the claim to a local metadata file' - static flags = { - ...ClaimCommand.flags, - url: Flags.url({ - required: true, - description: 'The URL you want to claim. Should begin http://', - }), - force: flags.boolean({ description: 'Ignore URL validity checks' }), - } - static args = ClaimCommand.args - static examples = [ - 'claim-attestation-service-url ~/metadata.json --url https://test.com/myurl --from 0x47e172F6CfB6c7D01C1574fa3E2Be7CC73269D95', - ] - self = ClaimAttestationServiceUrl - - async run() { - const res = this.parse(ClaimAttestationServiceUrl) - if (!res.flags.force && !res.flags.url.startsWith('https://')) { - this.error( - 'Attestation Service URLs should begin https:// to be accessible to all clients. Use --force to proceed anyway.' - ) - return - } - const metadata = await this.readMetadata() - await this.addClaim(metadata, createAttestationServiceURLClaim(res.flags.url)) - this.writeMetadata(metadata) - } -} diff --git a/packages/cli/src/commands/account/deauthorize.ts b/packages/cli/src/commands/account/deauthorize.ts index 32eeab92473..d8afb7da2ee 100644 --- a/packages/cli/src/commands/account/deauthorize.ts +++ b/packages/cli/src/commands/account/deauthorize.ts @@ -4,8 +4,7 @@ import { displaySendTx } from '../../utils/cli' import { Flags } from '../../utils/command' export default class Deauthorize extends BaseCommand { - static description = - 'Validators who can no longer serve Attestation Service requests should deauthorize their attestation signer. Please note that Attestation Services are important to the health of the Celo network, and validators should only use this command when troubleshooting their service is not an option.' + static description = "Remove an account's authorized attestation signer role." static flags = { ...BaseCommand.flags, diff --git a/packages/cli/src/commands/identity/current-attestation-services.ts b/packages/cli/src/commands/identity/current-attestation-services.ts deleted file mode 100644 index 175f470cf60..00000000000 --- a/packages/cli/src/commands/identity/current-attestation-services.ts +++ /dev/null @@ -1,74 +0,0 @@ -import { AttestationServiceStatusState } from '@celo/contractkit/lib/wrappers/Attestations' -import { concurrentMap } from '@celo/utils/lib/async' -import chalk from 'chalk' -import { cli } from 'cli-ux' -import { BaseCommand } from '../../base' - -export default class AttestationServicesCurrent extends BaseCommand { - static description = - "Outputs the set of validators currently participating in BFT and which ones are participating in Celo's lightweight identity protocol" - - static flags = { - ...BaseCommand.flags, - ...(cli.table.flags() as object), - } - - async run() { - const res = this.parse(AttestationServicesCurrent) - cli.action.start('Fetching currently elected Validators') - const election = await this.kit.contracts.getElection() - const validators = await this.kit.contracts.getValidators() - const attestations = await this.kit.contracts.getAttestations() - const signers = await election.getCurrentValidatorSigners() - const validatorList = await Promise.all( - signers.map((addr) => validators.getValidatorFromSigner(addr)) - ) - const validatorInfo = await concurrentMap( - 5, - validatorList, - attestations.getAttestationServiceStatus.bind(attestations) - ) - - cli.action.stop() - cli.table( - validatorInfo.sort((a, b) => { - if (a.affiliation === b.affiliation) { - return 0 - } else if (a.affiliation === null) { - return 1 - } else if (b.affiliation === null) { - return -1 - } - return a.affiliation.toLowerCase().localeCompare(b.affiliation.toLowerCase()) - }), - { - address: {}, - affiliation: {}, - name: {}, - state: { - get: (r) => { - switch (r.state) { - case AttestationServiceStatusState.NoMetadataURL: - case AttestationServiceStatusState.InvalidMetadata: - case AttestationServiceStatusState.UnreachableAttestationService: - case AttestationServiceStatusState.WrongAccount: - case AttestationServiceStatusState.Unhealthy: - case AttestationServiceStatusState.InvalidAttestationServiceURL: - return chalk.red(r.state) - case AttestationServiceStatusState.Valid: - return chalk.green(r.state) - case AttestationServiceStatusState.NoAttestationSigner: - return r.state - default: - return chalk.yellow(r.state) - } - }, - }, - version: {}, - attestationServiceURL: {}, - smsProviders: {}, - }, - res.flags - ) - } -} diff --git a/packages/cli/src/commands/identity/test-attestation-service.ts b/packages/cli/src/commands/identity/test-attestation-service.ts deleted file mode 100644 index da34232d38d..00000000000 --- a/packages/cli/src/commands/identity/test-attestation-service.ts +++ /dev/null @@ -1,147 +0,0 @@ -import { ClaimTypes, IdentityMetadataWrapper } from '@celo/contractkit/lib/identity' -import { sleep } from '@celo/utils/lib/async' -import { appendPath } from '@celo/utils/lib/string' -import { flags as oFlags } from '@oclif/command' -import { cli } from 'cli-ux' -import fetch from 'cross-fetch' -import { BaseCommand } from '../../base' -import { newCheckBuilder } from '../../utils/checks' -import { Flags } from '../../utils/command' -export default class TestAttestationService extends BaseCommand { - static description = - 'Tests whether the account has setup the attestation service properly by calling the test endpoint on it' - - static flags = { - ...BaseCommand.flags, - from: Flags.address({ - required: true, - description: "Your validator's signer or account address", - }), - phoneNumber: Flags.phoneNumber({ - required: true, - description: 'The phone number to send the test message to', - }), - message: oFlags.string({ required: true, description: 'The message of the SMS' }), - provider: oFlags.string({ - required: false, - description: 'Test a specific provider (try "twilio" or "nexmo")', - }), - } - - static examples = ['test-attestation-service --from 0x97f7333c51897469E8D98E7af8653aAb468050a3'] - - requireSynced = false - async run() { - const { flags } = this.parse(TestAttestationService) - const address = flags.from - const { phoneNumber, message, provider } = flags - - await newCheckBuilder(this, flags.from).isSignerOrAccount().canSign(address).runChecks() - - const accounts = await this.kit.contracts.getAccounts() - const account = await accounts.signerToAccount(address) - - const hasAuthorizedAttestationSigner = await accounts.hasAuthorizedAttestationSigner(account) - if (!hasAuthorizedAttestationSigner) { - console.info('Account has not authorized an attestation signer') - return - } - - const metadataURL = await accounts.getMetadataURL(account) - - if (!metadataURL) { - console.info('No metadata set for address') - return - } - - let metadata: IdentityMetadataWrapper - try { - metadata = await IdentityMetadataWrapper.fetchFromURL(accounts, metadataURL) - } catch (error: any) { - console.error(`Metadata could not be retrieved from ${metadataURL}: ${error.toString()}`) - return - } - - const attestationServiceUrlClaim = metadata.findClaim(ClaimTypes.ATTESTATION_SERVICE_URL) - if (!attestationServiceUrlClaim) { - console.error('No attestation service claim could be found') - return - } - - const signature = await this.kit.connection.sign(phoneNumber + message, address) - - try { - const testUrl = appendPath(attestationServiceUrlClaim.url, 'test_attestations') - cli.action.start(`Sending request to ${testUrl}`) - - console.info() - - const response = await fetch(testUrl, { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ phoneNumber, signature, message, provider }), - }) - - if (!response.ok) { - console.error('Request was not successful') - console.error(`Status: ${response.status}`) - console.error(`Response: ${await response.text()}`) - } - - cli.action.stop() - - const testRes = JSON.parse(await response.text()) - if (!testRes.success) { - console.error('Request was not successful') - cli.styledJSON(testRes) - return - } - - console.info('Request successful') - - if (testRes.salt) { - // Service supports tracking attestation delivery status. - const getUrl = appendPath(attestationServiceUrlClaim.url, 'get_attestations') - cli.action.start(`Checking for delivery status at ${getUrl}`) - let latestGet = null - for (let i = 0; i < 6; i++) { - await sleep(5 * 1000) - const getResponse = await fetch( - getUrl + - '?' + - new URLSearchParams({ - phoneNumber, - salt: testRes.salt, - issuer: testRes.issuer, - account: testRes.account, - }), - { - method: 'GET', - headers: { 'Content-Type': 'application/json' }, - } - ) - - if (!getResponse.ok) { - console.error('Request was not successful') - console.error(`Status: ${getResponse.status}`) - console.error(`Response: ${await getResponse.text()}`) - } - - latestGet = JSON.parse(await getResponse.text()) - - if (latestGet!.status === 'Delivered') { - break - } - } - - cli.action.stop() - if (latestGet) { - cli.styledJSON(latestGet) - } - } - } catch (error) { - console.error(`Something went wrong`) - console.error(error) - } - } -} diff --git a/packages/cli/src/utils/identity.ts b/packages/cli/src/utils/identity.ts index 70e1be406b1..0148d83e549 100644 --- a/packages/cli/src/utils/identity.ts +++ b/packages/cli/src/utils/identity.ts @@ -1,10 +1,7 @@ import { ContractKit } from '@celo/contractkit' import { ClaimTypes, IdentityMetadataWrapper } from '@celo/contractkit/lib/identity' -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 { Claim } from '@celo/contractkit/lib/identity/claims/claim' +import { VERIFIABLE_CLAIM_TYPES } from '@celo/contractkit/lib/identity/claims/types' import { verifyClaim } from '@celo/contractkit/lib/identity/claims/verify' import { eqAddress } from '@celo/utils/lib/address' import { concurrentMap } from '@celo/utils/lib/async' @@ -103,17 +100,9 @@ export const displayMetadata = async ( ) => { const data = await concurrentMap(5, metadata.claims, async (claim) => { const verifiable = VERIFIABLE_CLAIM_TYPES.includes(claim.type) - const validatable = VALIDATABLE_CLAIM_TYPES.includes(claim.type) - const status = verifiable - ? await verifyClaim(kit, claim, metadata.data.meta.address) - : validatable - ? await validateClaim(kit, claim, metadata.data.meta.address) - : 'N/A' + const status = verifiable ? await verifyClaim(kit, claim, metadata.data.meta.address) : 'N/A' let extra = '' switch (claim.type) { - case ClaimTypes.ATTESTATION_SERVICE_URL: - extra = `URL: ${claim.url}` - break case ClaimTypes.DOMAIN: extra = `Domain: ${claim.domain}` break @@ -133,15 +122,7 @@ export const displayMetadata = async ( return { type: claim.type, extra, - status: verifiable - ? status - ? `Could not verify: ${status}` - : 'Verified!' - : validatable - ? status - ? `Invalid: ${status}` - : `Valid!` - : 'N/A', + status: verifiable ? (status ? `Could not verify: ${status}` : 'Verified!') : 'N/A', createdAt: moment.unix(claim.timestamp).fromNow(), } }) diff --git a/packages/docs/command-line-interface/account.md b/packages/docs/command-line-interface/account.md index 0c50195760e..528f6b7b41d 100644 --- a/packages/docs/command-line-interface/account.md +++ b/packages/docs/command-line-interface/account.md @@ -117,39 +117,6 @@ EXAMPLE _See code: [src/commands/account/claim-account.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/commands/account/claim-account.ts)_ -## `celocli account:claim-attestation-service-url FILE` - -Claim the URL of the attestation service and add the claim to a local metadata file - -``` -Claim the URL of the attestation service and add the claim to a local metadata file - -USAGE - $ celocli account:claim-attestation-service-url FILE - -ARGUMENTS - FILE Path of the metadata file - -OPTIONS - --force Ignore URL validity checks - - --from=0xc1912fEE45d61C87Cc5EA59DaE31190FFFFf232d (required) Address of the account - to set metadata for or an - authorized signer for the address - in the metadata - - --globalHelp View all available global flags - - --url=https://www.celo.org (required) The URL you want to - claim. Should begin http:// - -EXAMPLE - claim-attestation-service-url ~/metadata.json --url https://test.com/myurl --from - 0x47e172F6CfB6c7D01C1574fa3E2Be7CC73269D95 -``` - -_See code: [src/commands/account/claim-attestation-service-url.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/commands/account/claim-attestation-service-url.ts)_ - ## `celocli account:claim-domain FILE` Claim a domain and add the claim to a local metadata file @@ -303,10 +270,10 @@ _See code: [src/commands/account/create-metadata.ts](https://github.com/celo-org ## `celocli account:deauthorize` -Validators who can no longer serve Attestation Service requests should deauthorize their attestation signer. Please note that Attestation Services are important to the health of the Celo network, and validators should only use this command when troubleshooting their service is not an option. +Remove an account's authorized attestation signer role. ``` -Validators who can no longer serve Attestation Service requests should deauthorize their attestation signer. Please note that Attestation Services are important to the health of the Celo network, and validators should only use this command when troubleshooting their service is not an option. +Remove an account's authorized attestation signer role. USAGE $ celocli account:deauthorize diff --git a/packages/docs/command-line-interface/identity.md b/packages/docs/command-line-interface/identity.md index aac2ab18fe9..9beea527c97 100644 --- a/packages/docs/command-line-interface/identity.md +++ b/packages/docs/command-line-interface/identity.md @@ -3,30 +3,6 @@ Interact with ODIS and the attestations service -## `celocli identity:current-attestation-services` - -Outputs the set of validators currently participating in BFT and which ones are participating in Celo's lightweight identity protocol - -``` -Outputs the set of validators currently participating in BFT and which ones are participating in Celo's lightweight identity protocol - -USAGE - $ celocli identity:current-attestation-services - -OPTIONS - -x, --extended show extra columns - --columns=columns only show provided columns (comma-separated) - --csv output is csv format [alias: --output=csv] - --filter=filter filter property by partial string matching, ex: name=foo - --globalHelp View all available global flags - --no-header hide table header from output - --no-truncate do not truncate output to fit screen - --output=csv|json|yaml output in a more machine friendly format - --sort=sort property to sort by (prepend '-' for descending) -``` - -_See code: [src/commands/identity/current-attestation-services.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/commands/identity/current-attestation-services.ts)_ - ## `celocli identity:get-attestations` Looks up attestations associated with the provided phone number. If a pepper is not provided, it uses the --from account's balance to query the pepper. @@ -95,36 +71,6 @@ EXAMPLE _See code: [src/commands/identity/identifier.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/commands/identity/identifier.ts)_ -## `celocli identity:test-attestation-service` - -Tests whether the account has setup the attestation service properly by calling the test endpoint on it - -``` -Tests whether the account has setup the attestation service properly by calling the test endpoint on it - -USAGE - $ celocli identity:test-attestation-service - -OPTIONS - --from=0xc1912fEE45d61C87Cc5EA59DaE31190FFFFf232d (required) Your validator's signer - or account address - - --globalHelp View all available global flags - - --message=message (required) The message of the SMS - - --phoneNumber=+14152223333 (required) The phone number to send - the test message to - - --provider=provider Test a specific provider (try - "twilio" or "nexmo") - -EXAMPLE - test-attestation-service --from 0x97f7333c51897469E8D98E7af8653aAb468050a3 -``` - -_See code: [src/commands/identity/test-attestation-service.ts](https://github.com/celo-org/celo-monorepo/tree/master/packages/cli/src/commands/identity/test-attestation-service.ts)_ - ## `celocli identity:withdraw-attestation-rewards` Withdraw accumulated attestation rewards for a given currency