From cddf0026c5ef3b87128220b46b1333e7a1dca5b2 Mon Sep 17 00:00:00 2001 From: Aaron DeRuvo Date: Thu, 12 Sep 2024 15:04:51 +0200 Subject: [PATCH] remove identity commands from cli --- .changeset/moody-falcons-remain.md | 8 ++ .../identity/get-attestations.test.ts | 62 ---------- .../src/commands/identity/get-attestations.ts | 106 ------------------ .../cli/src/commands/identity/identifier.ts | 63 ----------- 4 files changed, 8 insertions(+), 231 deletions(-) create mode 100644 .changeset/moody-falcons-remain.md delete mode 100644 packages/cli/src/commands/identity/get-attestations.test.ts delete mode 100644 packages/cli/src/commands/identity/get-attestations.ts delete mode 100644 packages/cli/src/commands/identity/identifier.ts diff --git a/.changeset/moody-falcons-remain.md b/.changeset/moody-falcons-remain.md new file mode 100644 index 000000000..02ec211be --- /dev/null +++ b/.changeset/moody-falcons-remain.md @@ -0,0 +1,8 @@ +--- +'@celo/celocli': major +--- +Remove commands identity:identifier, identity:get-attestations + +See https://forum.celo.org/t/rfc-deprecation-of-celocli-identity-commands/8676 + + diff --git a/packages/cli/src/commands/identity/get-attestations.test.ts b/packages/cli/src/commands/identity/get-attestations.test.ts deleted file mode 100644 index 27c71b938..000000000 --- a/packages/cli/src/commands/identity/get-attestations.test.ts +++ /dev/null @@ -1,62 +0,0 @@ -import { newAttestations } from '@celo/abis/web3/Attestations' -import { StrongAddress } from '@celo/base' -import { newKitFromWeb3 } from '@celo/contractkit' -import { WrapperCache } from '@celo/contractkit/lib/contract-cache' -import { AttestationsWrapper } from '@celo/contractkit/lib/wrappers/Attestations' -import { testWithAnvilL1 } from '@celo/dev-utils/lib/anvil-test' -import { deployAttestationsContract } from '@celo/dev-utils/lib/contracts' -import Web3 from 'web3' -import { testLocallyWithWeb3Node } from '../../test-utils/cliUtils' -import GetAttestations from './get-attestations' - -process.env.NO_SYNCCHECK = 'true' - -testWithAnvilL1('identity:get-attetstations', (web3: Web3) => { - beforeEach(async () => { - const kit = newKitFromWeb3(web3) - const accounts = (await web3.eth.getAccounts()) as StrongAddress[] - const attestationsContractAddress = await deployAttestationsContract(web3, accounts[0]) - - jest.spyOn(WrapperCache.prototype, 'getAttestations').mockImplementation(async () => { - return new AttestationsWrapper( - kit.connection, - newAttestations(web3, attestationsContractAddress), - newKitFromWeb3(web3).contracts - ) - }) - }) - - describe('input validation correctly outputs errors', () => { - const consoleOutput: string[] = [] - const mockedError = (output: string) => consoleOutput.push(output) - beforeEach(() => (console.error = mockedError)) - - it('Fails when neither from, pepper, nor identifier are specified', async () => { - await expect( - testLocallyWithWeb3Node(GetAttestations, ['--phoneNumber', '+15555555555'], web3) - ).rejects.toThrow('Must specify either --from or --pepper or --identifier') - }) - - it('Fails when neither phone number nor identifier are specified', async () => { - await expect( - testLocallyWithWeb3Node( - GetAttestations, - ['--from', '0x47e172F6CfB6c7D01C1574fa3E2Be7CC73269D95'], - web3 - ) - ).rejects.toThrow('Must specify phoneNumber if identifier not provided') - }) - - it('Successfully prints identifier when given pepper and number', async () => { - console.log = jest.fn() - await testLocallyWithWeb3Node( - GetAttestations, - ['--phoneNumber', '+15555555555', '--pepper', 'XQke2bjvN7mPt'], - web3 - ) - expect(console.log).toHaveBeenCalledWith( - 'Identifier: 0xd9460ae529b2889716c8f1ccebb5efec945adc46fe1e9cd16f6242463e81f37c' - ) - }) - }) -}) diff --git a/packages/cli/src/commands/identity/get-attestations.ts b/packages/cli/src/commands/identity/get-attestations.ts deleted file mode 100644 index 223b752c0..000000000 --- a/packages/cli/src/commands/identity/get-attestations.ts +++ /dev/null @@ -1,106 +0,0 @@ -import { ContractKit } from '@celo/contractkit' -import { OdisUtils } from '@celo/identity' -import { AuthSigner, OdisContextName } from '@celo/identity/lib/odis/query' -import { Flags } from '@oclif/core' -import { BaseCommand } from '../../base' -import { CustomFlags } from '../../utils/command' - -export default class GetAttestations extends BaseCommand { - static description = - "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." - - static flags = { - ...BaseCommand.flags, - phoneNumber: Flags.string({ - required: false, - description: 'Phone number to check attestations for', - }), - from: CustomFlags.address({ - required: false, - description: 'Account whose balance to use for querying ODIS for the pepper lookup', - }), - pepper: Flags.string({ - required: false, - description: 'ODIS phone number pepper', - }), - identifier: Flags.string({ - required: false, - description: 'On-chain identifier', - }), - network: Flags.string({ - required: false, - description: 'The ODIS service to hit: mainnet, alfajores, alfajoresstaging', - }), - } - - static examples = [ - 'get-attestations --phoneNumber +15555555555 --from 0x47e172F6CfB6c7D01C1574fa3E2Be7CC73269D95', - 'get-attestations --phoneNumber +15555555555 --pepper XgnKVpplZc0p1', - 'get-attestations --identifier 0x4952c9db9c283a62721b13f56c4b5e84a438e2569af3de21cb3440efa8840872', - ] - - async run() { - const kit = await this.getKit() - const res = await this.parse(GetAttestations) - const phoneNumber = res.flags.phoneNumber - const account = res.flags.from - let identifier = res.flags.identifier - let pepper = res.flags.pepper - if (!account && !pepper && !identifier) { - throw Error('Must specify either --from or --pepper or --identifier') - } - const network = res.flags.network - const attestationsContract = await kit.contracts.getAttestations() - const accountsContract = await kit.contracts.getAccounts() - - if (!identifier) { - if (!phoneNumber) { - throw Error('Must specify phoneNumber if identifier not provided') - } - // Get Phone number pepper - // Needs a balance to perform query - if (!pepper) { - pepper = await this.getPhoneNumberPepper(kit, phoneNumber!, account!, network) - console.log('Pepper: ' + pepper) - } - - const computedIdentifier = kit.connection.web3.utils.soliditySha3({ - type: 'string', - value: 'tel://' + phoneNumber + '__' + pepper, - }) - identifier = computedIdentifier! - console.log('Identifier: ' + identifier) - } - const accounts = await attestationsContract.lookupAccountsForIdentifier(identifier) - accounts.forEach(async (accountAddress) => { - console.log('Account address: ' + accountAddress) - console.log('\tWallet address: ' + (await accountsContract.getWalletAddress(accountAddress))) - console.log( - '\tData-Encryption Key: ' + (await accountsContract.getDataEncryptionKey(accountAddress)) - ) - }) - } - - async getPhoneNumberPepper( - kit: ContractKit, - phoneNumber: string, - account: string, - network: string = 'mainnet' - ): Promise { - console.log('Using network: ' + network) - const authSigner: AuthSigner = { - authenticationMethod: OdisUtils.Query.AuthenticationMethod.WALLET_KEY, - // @ts-ignore -- TODO: if identity depends on diff version of ck which has a slightly different type this complains - contractKit: kit, - } - - const ret = await OdisUtils.PhoneNumberIdentifier.getPhoneNumberIdentifier( - phoneNumber, - account, - authSigner, - OdisUtils.Query.getServiceContext(network as OdisContextName) - ) - - return ret.pepper - } -} diff --git a/packages/cli/src/commands/identity/identifier.ts b/packages/cli/src/commands/identity/identifier.ts deleted file mode 100644 index 879f516f2..000000000 --- a/packages/cli/src/commands/identity/identifier.ts +++ /dev/null @@ -1,63 +0,0 @@ -import { OdisUtils } from '@celo/identity' -import { AuthSigner, OdisContextName } from '@celo/identity/lib/odis/query' -import { Flags, ux } from '@oclif/core' -import { BaseCommand } from '../../base' -import { newCheckBuilder } from '../../utils/checks' -import { printValueMap } from '../../utils/cli' -import { CustomFlags } from '../../utils/command' - -export default class IdentifierQuery extends BaseCommand { - static description = - 'Queries ODIS for the on-chain identifier and pepper corresponding to a given phone number.' - - static flags = { - ...BaseCommand.flags, - from: CustomFlags.address({ - required: true, - description: 'The address from which to perform the query', - }), - phoneNumber: CustomFlags.phoneNumber({ - required: true, - description: - 'The phone number for which to query the identifier. Should be in e164 format with country code.', - }), - context: Flags.string({ - required: false, - description: 'mainnet (default), alfajores, or alfajoresstaging', - }), - } - - static examples = [ - 'identifier --phoneNumber +14151231234 --from 0x5409ed021d9299bf6814279a6a1411a7e866a631 --context alfajores', - ] - - async run() { - const kit = await this.getKit() - const { flags } = await this.parse(IdentifierQuery) - const { phoneNumber, from, context } = flags - - await newCheckBuilder(this).isValidAddress(flags.from).runChecks() - - ux.action.start('Querying ODIS for identifier') - - const authSigner: AuthSigner = { - authenticationMethod: OdisUtils.Query.AuthenticationMethod.WALLET_KEY, - // @ts-ignore -- TODO: if identity depends on diff version of ck which has a slightly differnt type this complains - contractKit: kit, - } - - const res = await OdisUtils.PhoneNumberIdentifier.getPhoneNumberIdentifier( - phoneNumber, - from, - authSigner, - OdisUtils.Query.getServiceContext(context as OdisContextName) - ) - - ux.action.stop() - - printValueMap({ - identifier: res.phoneHash, - pepper: res.pepper, - }) - } -}