From 1189d1aed62bd493b3e89fa77cbe3da42ab6a6e0 Mon Sep 17 00:00:00 2001 From: "will.li" <120463031+higherordertech@users.noreply.github.com> Date: Thu, 10 Oct 2024 21:14:14 +1100 Subject: [PATCH] chore: P-1044 merge all identity tests into one (#3113) * chore: P-1044 combine all di identity tests, update ci config to run the combined di identity tests * removed unused function and clean up --------- Co-authored-by: higherordertech --- .github/workflows/ci.yml | 12 +- tee-worker/identity/build.Dockerfile | 2 +- ...t-di-bitcoin-identity-multiworker-test.yml | 22 - .../docker/lit-di-bitcoin-identity-test.yml | 22 - ...l => lit-di-identity-multiworker-test.yml} | 6 +- ...tity-test.yml => lit-di-identity-test.yml} | 6 +- ...it-di-solana-identity-multiworker-test.yml | 22 - .../docker/lit-di-solana-identity-test.yml | 22 - ...di-substrate-identity-multiworker-test.yml | 22 - .../docker/lit-di-substrate-identity-test.yml | 22 - .../docker/lit-discord-identity-test.yml | 22 - .../docker/lit-twitter-identity-test.yml | 22 - tee-worker/identity/ts-tests/README.md | 12 +- .../integration-tests/common/common-types.ts | 2 +- .../integration-tests/common/helpers.ts | 27 +- .../common/utils/identity-helper.ts | 4 +- .../di_bitcoin_identity.test.ts | 345 -------- .../integration-tests/di_evm_identity.test.ts | 370 -------- .../integration-tests/di_identity.test.ts | 362 ++++++++ .../di_solana_identity.test.ts | 365 -------- .../di_substrate_identity.test.ts | 829 ------------------ .../discord_identity.test.ts | 289 ------ .../ts-tests/integration-tests/dr_vc.test.ts | 2 +- .../twitter_identity.test.ts | 304 ------- 24 files changed, 399 insertions(+), 2714 deletions(-) delete mode 100644 tee-worker/identity/docker/lit-di-bitcoin-identity-multiworker-test.yml delete mode 100644 tee-worker/identity/docker/lit-di-bitcoin-identity-test.yml rename tee-worker/identity/docker/{lit-di-evm-identity-multiworker-test.yml => lit-di-identity-multiworker-test.yml} (80%) rename tee-worker/identity/docker/{lit-di-evm-identity-test.yml => lit-di-identity-test.yml} (82%) delete mode 100644 tee-worker/identity/docker/lit-di-solana-identity-multiworker-test.yml delete mode 100644 tee-worker/identity/docker/lit-di-solana-identity-test.yml delete mode 100644 tee-worker/identity/docker/lit-di-substrate-identity-multiworker-test.yml delete mode 100644 tee-worker/identity/docker/lit-di-substrate-identity-test.yml delete mode 100644 tee-worker/identity/docker/lit-discord-identity-test.yml delete mode 100644 tee-worker/identity/docker/lit-twitter-identity-test.yml delete mode 100644 tee-worker/identity/ts-tests/integration-tests/di_bitcoin_identity.test.ts delete mode 100644 tee-worker/identity/ts-tests/integration-tests/di_evm_identity.test.ts create mode 100644 tee-worker/identity/ts-tests/integration-tests/di_identity.test.ts delete mode 100644 tee-worker/identity/ts-tests/integration-tests/di_solana_identity.test.ts delete mode 100644 tee-worker/identity/ts-tests/integration-tests/di_substrate_identity.test.ts delete mode 100644 tee-worker/identity/ts-tests/integration-tests/discord_identity.test.ts delete mode 100644 tee-worker/identity/ts-tests/integration-tests/twitter_identity.test.ts diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index cb4a49f926..f7087e328f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -709,15 +709,10 @@ jobs: fail-fast: false matrix: include: - - test_name: lit-di-substrate-identity-test - - test_name: lit-di-evm-identity-test - - test_name: lit-di-bitcoin-identity-test - - test_name: lit-di-solana-identity-test + - test_name: lit-di-identity-test - test_name: lit-dr-vc-test - test_name: lit-parentchain-nonce - test_name: lit-test-failed-parentchain-extrinsic - - test_name: lit-twitter-identity-test - - test_name: lit-discord-identity-test name: ${{ matrix.test_name }} steps: - uses: actions/checkout@v4 @@ -785,10 +780,7 @@ jobs: fail-fast: false matrix: include: - - test_name: lit-di-bitcoin-identity-multiworker-test - - test_name: lit-di-evm-identity-multiworker-test - - test_name: lit-di-solana-identity-multiworker-test - - test_name: lit-di-substrate-identity-multiworker-test + - test_name: lit-di-identity-multiworker-test - test_name: lit-dr-vc-multiworker-test - test_name: lit-resume-worker name: ${{ matrix.test_name }} diff --git a/tee-worker/identity/build.Dockerfile b/tee-worker/identity/build.Dockerfile index be93051620..6ea754ca3c 100644 --- a/tee-worker/identity/build.Dockerfile +++ b/tee-worker/identity/build.Dockerfile @@ -85,7 +85,7 @@ RUN cargo test --release ################################################## FROM node:18-bookworm-slim AS runner -RUN apt update && apt install -y libssl-dev iproute2 jq curl protobuf-compiler +RUN apt update && apt install -y libssl-dev iproute2 jq curl protobuf-compiler python3 python-is-python3 build-essential RUN corepack enable && corepack prepare pnpm@8.7.6 --activate && corepack enable pnpm diff --git a/tee-worker/identity/docker/lit-di-bitcoin-identity-multiworker-test.yml b/tee-worker/identity/docker/lit-di-bitcoin-identity-multiworker-test.yml deleted file mode 100644 index 3e17273ea2..0000000000 --- a/tee-worker/identity/docker/lit-di-bitcoin-identity-multiworker-test.yml +++ /dev/null @@ -1,22 +0,0 @@ -services: - lit-di-bitcoin-identity-multiworker-test: - image: litentry/identity-cli:latest - container_name: litentry-di-bitcoin-identity-test - volumes: - - ../ts-tests:/ts-tests - - ../client-api:/client-api - - ../cli:/usr/local/worker-cli - build: - context: .. - dockerfile: build.Dockerfile - target: deployed-client - depends_on: - litentry-worker-3: - condition: service_healthy - networks: - - litentry-test-network - entrypoint: "bash -c '/usr/local/worker-cli/lit_ts_integration_test.sh di_bitcoin_identity.test.ts 2>&1' " - restart: "no" -networks: - litentry-test-network: - driver: bridge diff --git a/tee-worker/identity/docker/lit-di-bitcoin-identity-test.yml b/tee-worker/identity/docker/lit-di-bitcoin-identity-test.yml deleted file mode 100644 index 92245d8412..0000000000 --- a/tee-worker/identity/docker/lit-di-bitcoin-identity-test.yml +++ /dev/null @@ -1,22 +0,0 @@ -services: - lit-di-bitcoin-identity-test: - image: litentry/identity-cli:latest - container_name: litentry-di-bitcoin-identity-test - volumes: - - ../ts-tests:/ts-tests - - ../client-api:/client-api - - ../cli:/usr/local/worker-cli - build: - context: .. - dockerfile: build.Dockerfile - target: deployed-client - depends_on: - litentry-worker-1: - condition: service_healthy - networks: - - litentry-test-network - entrypoint: "bash -c '/usr/local/worker-cli/lit_ts_integration_test.sh di_bitcoin_identity.test.ts 2>&1' " - restart: "no" -networks: - litentry-test-network: - driver: bridge diff --git a/tee-worker/identity/docker/lit-di-evm-identity-multiworker-test.yml b/tee-worker/identity/docker/lit-di-identity-multiworker-test.yml similarity index 80% rename from tee-worker/identity/docker/lit-di-evm-identity-multiworker-test.yml rename to tee-worker/identity/docker/lit-di-identity-multiworker-test.yml index b287e454bd..5eb974a6c3 100644 --- a/tee-worker/identity/docker/lit-di-evm-identity-multiworker-test.yml +++ b/tee-worker/identity/docker/lit-di-identity-multiworker-test.yml @@ -1,7 +1,7 @@ services: - lit-di-evm-identity-multiworker-test: + lit-di-identity-multiworker-test: image: litentry/identity-cli:latest - container_name: litentry-di-evm-identity-test + container_name: litentry-di-identity-test volumes: - ../ts-tests:/ts-tests - ../client-api:/client-api @@ -15,7 +15,7 @@ services: condition: service_healthy networks: - litentry-test-network - entrypoint: "bash -c '/usr/local/worker-cli/lit_ts_integration_test.sh di_evm_identity.test.ts 2>&1' " + entrypoint: "bash -c '/usr/local/worker-cli/lit_ts_integration_test.sh di_identity.test.ts 2>&1' " restart: "no" networks: litentry-test-network: diff --git a/tee-worker/identity/docker/lit-di-evm-identity-test.yml b/tee-worker/identity/docker/lit-di-identity-test.yml similarity index 82% rename from tee-worker/identity/docker/lit-di-evm-identity-test.yml rename to tee-worker/identity/docker/lit-di-identity-test.yml index dd37b38dc0..87f8c9e09b 100644 --- a/tee-worker/identity/docker/lit-di-evm-identity-test.yml +++ b/tee-worker/identity/docker/lit-di-identity-test.yml @@ -1,7 +1,7 @@ services: - lit-di-evm-identity-test: + lit-di-identity-test: image: litentry/identity-cli:latest - container_name: litentry-di-evm-identity-test + container_name: litentry-di-identity-test volumes: - ../ts-tests:/ts-tests - ../client-api:/client-api @@ -15,7 +15,7 @@ services: condition: service_healthy networks: - litentry-test-network - entrypoint: "bash -c '/usr/local/worker-cli/lit_ts_integration_test.sh di_evm_identity.test.ts 2>&1' " + entrypoint: "bash -c '/usr/local/worker-cli/lit_ts_integration_test.sh di_identity.test.ts 2>&1' " restart: "no" networks: litentry-test-network: diff --git a/tee-worker/identity/docker/lit-di-solana-identity-multiworker-test.yml b/tee-worker/identity/docker/lit-di-solana-identity-multiworker-test.yml deleted file mode 100644 index 11f39fb2ad..0000000000 --- a/tee-worker/identity/docker/lit-di-solana-identity-multiworker-test.yml +++ /dev/null @@ -1,22 +0,0 @@ -services: - lit-di-solana-identity-multiworker-test: - image: litentry/identity-cli:latest - container_name: litentry-di-solana-identity-test - volumes: - - ../ts-tests:/ts-tests - - ../client-api:/client-api - - ../cli:/usr/local/worker-cli - build: - context: .. - dockerfile: build.Dockerfile - target: deployed-client - depends_on: - litentry-worker-3: - condition: service_healthy - networks: - - litentry-test-network - entrypoint: "bash -c '/usr/local/worker-cli/lit_ts_integration_test.sh di_solana_identity.test.ts 2>&1' " - restart: "no" -networks: - litentry-test-network: - driver: bridge diff --git a/tee-worker/identity/docker/lit-di-solana-identity-test.yml b/tee-worker/identity/docker/lit-di-solana-identity-test.yml deleted file mode 100644 index 9301d72f3b..0000000000 --- a/tee-worker/identity/docker/lit-di-solana-identity-test.yml +++ /dev/null @@ -1,22 +0,0 @@ -services: - lit-di-solana-identity-test: - image: litentry/identity-cli:latest - container_name: litentry-di-solana-identity-test - volumes: - - ../ts-tests:/ts-tests - - ../client-api:/client-api - - ../cli:/usr/local/worker-cli - build: - context: .. - dockerfile: build.Dockerfile - target: deployed-client - depends_on: - litentry-worker-1: - condition: service_healthy - networks: - - litentry-test-network - entrypoint: "bash -c '/usr/local/worker-cli/lit_ts_integration_test.sh di_solana_identity.test.ts 2>&1' " - restart: "no" -networks: - litentry-test-network: - driver: bridge diff --git a/tee-worker/identity/docker/lit-di-substrate-identity-multiworker-test.yml b/tee-worker/identity/docker/lit-di-substrate-identity-multiworker-test.yml deleted file mode 100644 index 50742a37ac..0000000000 --- a/tee-worker/identity/docker/lit-di-substrate-identity-multiworker-test.yml +++ /dev/null @@ -1,22 +0,0 @@ -services: - lit-di-substrate-identity-multiworker-test: - image: litentry/identity-cli:latest - container_name: litentry-di-substrate-identity-test - volumes: - - ../ts-tests:/ts-tests - - ../client-api:/client-api - - ../cli:/usr/local/worker-cli - build: - context: .. - dockerfile: build.Dockerfile - target: deployed-client - depends_on: - litentry-worker-3: - condition: service_healthy - networks: - - litentry-test-network - entrypoint: "bash -c '/usr/local/worker-cli/lit_ts_integration_test.sh di_substrate_identity.test.ts 2>&1' " - restart: "no" -networks: - litentry-test-network: - driver: bridge diff --git a/tee-worker/identity/docker/lit-di-substrate-identity-test.yml b/tee-worker/identity/docker/lit-di-substrate-identity-test.yml deleted file mode 100644 index 2bbb7d5c1a..0000000000 --- a/tee-worker/identity/docker/lit-di-substrate-identity-test.yml +++ /dev/null @@ -1,22 +0,0 @@ -services: - lit-di-substrate-identity-test: - image: litentry/identity-cli:latest - container_name: litentry-di-substrate-identity-test - volumes: - - ../ts-tests:/ts-tests - - ../client-api:/client-api - - ../cli:/usr/local/worker-cli - build: - context: .. - dockerfile: build.Dockerfile - target: deployed-client - depends_on: - litentry-worker-1: - condition: service_healthy - networks: - - litentry-test-network - entrypoint: "bash -c '/usr/local/worker-cli/lit_ts_integration_test.sh di_substrate_identity.test.ts 2>&1' " - restart: "no" -networks: - litentry-test-network: - driver: bridge diff --git a/tee-worker/identity/docker/lit-discord-identity-test.yml b/tee-worker/identity/docker/lit-discord-identity-test.yml deleted file mode 100644 index dfc5359e3b..0000000000 --- a/tee-worker/identity/docker/lit-discord-identity-test.yml +++ /dev/null @@ -1,22 +0,0 @@ -services: - lit-discord-identity-test: - image: litentry/identity-cli:latest - container_name: litentry-discord-identity-test - volumes: - - ../ts-tests:/ts-tests - - ../client-api:/client-api - - ../cli:/usr/local/worker-cli - build: - context: .. - dockerfile: build.Dockerfile - target: deployed-client - depends_on: - litentry-worker-1: - condition: service_healthy - networks: - - litentry-test-network - entrypoint: "bash -c '/usr/local/worker-cli/lit_ts_integration_test.sh discord_identity.test.ts 2>&1' " - restart: "no" -networks: - litentry-test-network: - driver: bridge diff --git a/tee-worker/identity/docker/lit-twitter-identity-test.yml b/tee-worker/identity/docker/lit-twitter-identity-test.yml deleted file mode 100644 index e3b8874668..0000000000 --- a/tee-worker/identity/docker/lit-twitter-identity-test.yml +++ /dev/null @@ -1,22 +0,0 @@ -services: - lit-twitter-identity-test: - image: litentry/identity-cli:latest - container_name: litentry-twitter-identity-test - volumes: - - ../ts-tests:/ts-tests - - ../client-api:/client-api - - ../cli:/usr/local/worker-cli - build: - context: .. - dockerfile: build.Dockerfile - target: deployed-client - depends_on: - litentry-worker-1: - condition: service_healthy - networks: - - litentry-test-network - entrypoint: "bash -c '/usr/local/worker-cli/lit_ts_integration_test.sh twitter_identity.test.ts 2>&1' " - restart: "no" -networks: - litentry-test-network: - driver: bridge diff --git a/tee-worker/identity/ts-tests/README.md b/tee-worker/identity/ts-tests/README.md index 764c128ef4..7e9684979f 100644 --- a/tee-worker/identity/ts-tests/README.md +++ b/tee-worker/identity/ts-tests/README.md @@ -33,17 +33,11 @@ pnpm install pnpm --filter integration-tests run test your-testfile.test.ts ``` -II identity test: `pnpm --filter integration-tests run test ii_identity.test.ts` +Direct invocation identity test: `pnpm --filter integration-tests run test di_identity.test.ts` -II vc test: `pnpm --filter integration-tests run test ii_vc.test.ts` +Direct invocation vc test: `pnpm --filter integration-tests run test vc_correctness.test.ts` -II batch identity test: `pnpm --filter integration-tests run test ii_batch.test.ts` - -Direct invocation substrate identity test: `pnpm --filter integration-tests run test di_substrate_identity.test.ts` - -Direct invocation evm identity test: `pnpm --filter integration-tests run test di_evm_identity.test.ts` - -Direct invocation vc test: `pnpm --filter integration-tests run test di_vc.test.ts` +Direct requect vc test: `pnpm --filter integration-tests run test dr_vc.test.ts` ## Data-provider test diff --git a/tee-worker/identity/ts-tests/integration-tests/common/common-types.ts b/tee-worker/identity/ts-tests/integration-tests/common/common-types.ts index 5dbc1823ee..36c6d00f74 100644 --- a/tee-worker/identity/ts-tests/integration-tests/common/common-types.ts +++ b/tee-worker/identity/ts-tests/integration-tests/common/common-types.ts @@ -11,7 +11,7 @@ import { Signer } from './utils/crypto'; // If there are types already defined in the client-api, please avoid redefining these types. // Instead, make every effort to use the types that have been generated within the client-api. -interface WalletType { +export interface WalletType { [walletName: string]: Signer; } export interface Wallets { diff --git a/tee-worker/identity/ts-tests/integration-tests/common/helpers.ts b/tee-worker/identity/ts-tests/integration-tests/common/helpers.ts index 883b784239..2af40c823e 100644 --- a/tee-worker/identity/ts-tests/integration-tests/common/helpers.ts +++ b/tee-worker/identity/ts-tests/integration-tests/common/helpers.ts @@ -5,14 +5,15 @@ import type { KeyringPair } from '@polkadot/keyring/types'; import type { HexString } from '@polkadot/util/types'; import './config'; import { IntegrationTestContext, JsonRpcRequest } from './common-types'; -import { createHash, randomBytes } from 'crypto'; +import { createHash, randomBytes, type KeyObject } from 'crypto'; import { ECPairFactory, ECPairInterface } from 'ecpair'; import * as ecc from 'tiny-secp256k1'; import { ethers, Wallet } from 'ethers'; import { Keypair } from '@solana/web3.js'; -import { EthersSigner, PolkadotSigner, BitcoinSigner, SolanaSigner } from './utils/crypto'; +import { EthersSigner, PolkadotSigner, BitcoinSigner, SolanaSigner, Signer } from './utils/crypto'; import { Wallets } from './common-types'; import type { ErrorDetail, StfError } from 'parachain-api'; +import { createSignedTrustedCallCleanIDGraphs, getSidechainNonce, sendRequestFromTrustedCall } from './di-utils'; export function blake2128Concat(data: HexString | Uint8Array): Uint8Array { return u8aConcat(blake2AsU8a(data, 128), u8aToU8a(data)); @@ -68,6 +69,21 @@ export function genesisSolanaWallet(name: string): Keypair { return keyPair; } +export const createWeb3Wallet = (walletType: string, walletName: string): Signer => { + switch (walletType) { + case 'evm': + return new EthersSigner(randomEvmWallet()); + case 'substrate': + return new PolkadotSigner(genesisSubstrateWallet(walletName)); + case 'bitcoin': + return new BitcoinSigner(randomBitcoinWallet()); + case 'solana': + return new SolanaSigner(genesisSolanaWallet(walletName)); + default: + throw new Error(`Unsupported wallet type: ${walletType}`); + } +}; + export const createWeb3Wallets = (): Wallets => { const wallets: Wallets = { evm: {}, @@ -77,10 +93,9 @@ export const createWeb3Wallets = (): Wallets => { }; const walletNames = ['Alice', 'Bob', 'Charlie', 'Dave', 'Eve']; for (const name of walletNames) { - wallets.evm[name] = new EthersSigner(randomEvmWallet()); - wallets.substrate[name] = new PolkadotSigner(genesisSubstrateWallet(name)); - wallets.bitcoin[name] = new BitcoinSigner(randomBitcoinWallet()); - wallets.solana[name] = new SolanaSigner(genesisSolanaWallet(name)); + for (const walletType in wallets) { + (wallets as any)[walletType][name] = createWeb3Wallet(walletType, name); + } } return wallets; diff --git a/tee-worker/identity/ts-tests/integration-tests/common/utils/identity-helper.ts b/tee-worker/identity/ts-tests/integration-tests/common/utils/identity-helper.ts index 35871fb8c2..3a7d74ed24 100644 --- a/tee-worker/identity/ts-tests/integration-tests/common/utils/identity-helper.ts +++ b/tee-worker/identity/ts-tests/integration-tests/common/utils/identity-helper.ts @@ -146,7 +146,7 @@ export async function buildValidations( signerIdentitity: CorePrimitivesIdentity, linkIdentity: CorePrimitivesIdentity, startingSidechainNonce: number, - network: 'ethereum' | 'substrate' | 'bitcoin' | 'solana', + network: 'evm' | 'substrate' | 'bitcoin' | 'solana', signer?: Signer, options?: { prettifiedMessage?: boolean } ): Promise { @@ -154,7 +154,7 @@ export async function buildValidations( const validationNonce = startingSidechainNonce++; const msg = generateVerificationMessage(context, signerIdentitity, linkIdentity, validationNonce); - if (network === 'ethereum') { + if (network === 'evm') { const evmValidationData = { Web3Validation: { Evm: { diff --git a/tee-worker/identity/ts-tests/integration-tests/di_bitcoin_identity.test.ts b/tee-worker/identity/ts-tests/integration-tests/di_bitcoin_identity.test.ts deleted file mode 100644 index c937f08bc8..0000000000 --- a/tee-worker/identity/ts-tests/integration-tests/di_bitcoin_identity.test.ts +++ /dev/null @@ -1,345 +0,0 @@ -import { randomBytes, KeyObject } from 'crypto'; -import { step } from 'mocha-steps'; -import { assert } from 'chai'; -import { - buildValidations, - initIntegrationTestContext, - assertIdGraphMutationResult, - assertIdGraphHash, - sleep, -} from './common/utils'; -import { assertIsInSidechainBlock } from './common/utils/assertion'; -import { - createSignedTrustedCallLinkIdentity, - createSignedTrustedGetterIdGraph, - createSignedTrustedCallDeactivateIdentity, - createSignedTrustedCallActivateIdentity, - decodeIdGraph, - getSidechainNonce, - getTeeShieldingKey, - sendRsaRequestFromGetter, - sendRequestFromTrustedCall, - sendAesRequestFromGetter, -} from './common/di-utils'; // @fixme move to a better place -import type { IntegrationTestContext } from './common/common-types'; -import { aesKey } from './common/call'; -import type { LitentryValidationData, Web3Network, CorePrimitivesIdentity } from 'parachain-api'; -import { type Bytes, type Vec } from '@polkadot/types'; -import type { HexString } from '@polkadot/util/types'; -import { hexToU8a } from '@polkadot/util'; - -describe('Test Identity (bitcoin direct invocation)', function () { - let context: IntegrationTestContext = undefined as any; - let teeShieldingKey: KeyObject = undefined as any; - let aliceBitcoinIdentity: CorePrimitivesIdentity = undefined as any; - let aliceEvmIdentity: CorePrimitivesIdentity; - let bobBitcoinIdentity: CorePrimitivesIdentity; - let currentNonce = 0; - - // Alice links: - // - alice's evm identity - // - bob's bitcoin identity - const linkIdentityRequestParams: { - nonce: number; - identity: CorePrimitivesIdentity; - validation: LitentryValidationData; - networks: Bytes | Vec; - }[] = []; - - const deactivateIdentityRequestParams: { - nonce: number; - identity: CorePrimitivesIdentity; - }[] = []; - - const activateIdentityRequestParams: { - nonce: number; - identity: CorePrimitivesIdentity; - }[] = []; - - this.timeout(6000000); - - before(async () => { - context = await initIntegrationTestContext( - process.env.PARACHAIN_ENDPOINT! // @fixme evil assertion; centralize env access - ); - teeShieldingKey = await getTeeShieldingKey(context); - aliceBitcoinIdentity = await context.web3Wallets.bitcoin.Alice.getIdentity(context); - aliceEvmIdentity = await context.web3Wallets.evm.Alice.getIdentity(context); - bobBitcoinIdentity = await context.web3Wallets.bitcoin.Bob.getIdentity(context); - currentNonce = (await getSidechainNonce(context, aliceBitcoinIdentity)).toNumber(); - }); - - step('check idGraph from sidechain storage before linking', async function () { - const idGraphGetter = await createSignedTrustedGetterIdGraph( - context.api, - context.web3Wallets.bitcoin.Alice, - aliceBitcoinIdentity - ); - const res = await sendAesRequestFromGetter(context, teeShieldingKey, hexToU8a(aesKey), idGraphGetter); - const idGraph = decodeIdGraph(context.sidechainRegistry, res.value); - assert.lengthOf(idGraph, 0); - }); - - step('linking identities (alice bitcoin account)', async function () { - const aliceEvmNonce = currentNonce++; - const aliceEvmValidation = await buildValidations( - context, - aliceBitcoinIdentity, - aliceEvmIdentity, - aliceEvmNonce, - 'ethereum', - context.web3Wallets.evm.Alice - ); - const aliceEvmNetworks = context.api.createType('Vec', ['Ethereum', 'Bsc']); - linkIdentityRequestParams.push({ - nonce: aliceEvmNonce, - identity: aliceEvmIdentity, - validation: aliceEvmValidation, - networks: aliceEvmNetworks, - }); - - // link another bitcoin account - const bobBitcoinNonce = currentNonce++; - const bobBitcoinValidation = await buildValidations( - context, - aliceBitcoinIdentity, - bobBitcoinIdentity, - bobBitcoinNonce, - 'bitcoin', - context.web3Wallets.bitcoin.Bob, - { prettifiedMessage: true } - ); - const bobBitcoinNetowrks = context.api.createType('Vec', ['BitcoinP2tr']); - linkIdentityRequestParams.push({ - nonce: bobBitcoinNonce, - identity: bobBitcoinIdentity, - validation: bobBitcoinValidation, - networks: bobBitcoinNetowrks, - }); - - const idGraphHashResults: HexString[] = []; - let expectedIdGraphs: [CorePrimitivesIdentity, boolean][][] = [ - [ - [aliceBitcoinIdentity, true], - [aliceEvmIdentity, true], - ], - [[bobBitcoinIdentity, true]], - ]; - - let counter = 0; - for (const { nonce, identity, validation, networks } of linkIdentityRequestParams) { - counter++; - const requestIdentifier = `0x${randomBytes(32).toString('hex')}`; - const linkIdentityCall = await createSignedTrustedCallLinkIdentity( - context.api, - context.mrEnclave, - context.api.createType('Index', nonce), - context.web3Wallets.bitcoin.Alice, - aliceBitcoinIdentity, - identity.toHex(), - validation.toHex(), - networks.toHex(), - context.api.createType('Option', aesKey).toHex(), - requestIdentifier, - { - withWrappedBytes: false, - withPrefix: counter % 2 === 0, // alternate per entry - } - ); - - const res = await sendRequestFromTrustedCall(context, teeShieldingKey, linkIdentityCall); - - idGraphHashResults.push( - await assertIdGraphMutationResult( - context, - teeShieldingKey, - aliceBitcoinIdentity, - res, - 'LinkIdentityResult', - expectedIdGraphs[0] - ) - ); - expectedIdGraphs = expectedIdGraphs.slice(1, expectedIdGraphs.length); - await assertIsInSidechainBlock('linkIdentityCall', res); - } - - assert.lengthOf(idGraphHashResults, 2); - }); - - step('check user sidechain storage after linking', async function () { - const idGraphGetter = await createSignedTrustedGetterIdGraph( - context.api, - context.web3Wallets.bitcoin.Alice, - aliceBitcoinIdentity - ); - const res = await sendRsaRequestFromGetter(context, teeShieldingKey, idGraphGetter); - const idGraph = decodeIdGraph(context.sidechainRegistry, res.value); - - // according to the order of linkIdentityRequestParams - const expectedWeb3Networks = [['Ethereum', 'Bsc'], ['BitcoinP2tr']]; - let currentIndex = 0; - - for (const { identity } of linkIdentityRequestParams) { - const identityDump = JSON.stringify(identity.toHuman(), null, 4); - console.debug(`checking identity: ${identityDump}`); - const idGraphNode = idGraph.find(([idGraphNodeIdentity]) => idGraphNodeIdentity.eq(identity)); - assert.isDefined(idGraphNode, `identity not found in idGraph: ${identityDump}`); - const [, idGraphNodeContext] = idGraphNode!; - - const web3networks = idGraphNode![1].web3networks.toHuman(); - assert.deepEqual(web3networks, expectedWeb3Networks[currentIndex]); - - assert.equal( - idGraphNodeContext.status.toString(), - 'Active', - `status should be active for identity: ${identityDump}` - ); - console.debug('active ✅'); - - currentIndex++; - } - - await assertIdGraphHash(context, teeShieldingKey, aliceBitcoinIdentity, idGraph); - }); - step('deactivating identity(alice bitcoin account)', async function () { - const aliceEvmNonce = currentNonce++; - - deactivateIdentityRequestParams.push({ - nonce: aliceEvmNonce, - identity: aliceEvmIdentity, - }); - - const idGraphHashResults: HexString[] = []; - let expectedIdGraphs: [CorePrimitivesIdentity, boolean][][] = [[[aliceEvmIdentity, false]]]; - - for (const { nonce, identity } of deactivateIdentityRequestParams) { - const requestIdentifier = `0x${randomBytes(32).toString('hex')}`; - const deactivateIdentityCall = await createSignedTrustedCallDeactivateIdentity( - context.api, - context.mrEnclave, - context.api.createType('Index', nonce), - context.web3Wallets.bitcoin.Alice, - aliceBitcoinIdentity, - identity.toHex(), - context.api.createType('Option', aesKey).toHex(), - requestIdentifier - ); - - const res = await sendRequestFromTrustedCall(context, teeShieldingKey, deactivateIdentityCall); - idGraphHashResults.push( - await assertIdGraphMutationResult( - context, - teeShieldingKey, - aliceBitcoinIdentity, - res, - 'DeactivateIdentityResult', - expectedIdGraphs[0] - ) - ); - expectedIdGraphs = expectedIdGraphs.slice(1, expectedIdGraphs.length); - await assertIsInSidechainBlock('deactivateIdentityCall', res); - assert.lengthOf(idGraphHashResults, 1); - } - }); - - step('check idGraph from sidechain storage after deactivating', async function () { - const idGraphGetter = await createSignedTrustedGetterIdGraph( - context.api, - context.web3Wallets.bitcoin.Alice, - aliceBitcoinIdentity - ); - const res = await sendRsaRequestFromGetter(context, teeShieldingKey, idGraphGetter); - const idGraph = decodeIdGraph(context.sidechainRegistry, res.value); - - for (const { identity } of deactivateIdentityRequestParams) { - const identityDump = JSON.stringify(identity.toHuman(), null, 4); - console.debug(`checking identity: ${identityDump}`); - const idGraphNode = idGraph.find(([idGraphNodeIdentity]) => idGraphNodeIdentity.eq(identity)); - assert.isDefined(idGraphNode, `identity not found in idGraph: ${identityDump}`); - const [, idGraphNodeContext] = idGraphNode!; - - assert.equal( - idGraphNodeContext.status.toString(), - 'Inactive', - `status should be Inactive for identity: ${identityDump}` - ); - console.debug('inactive ✅'); - } - - await assertIdGraphHash(context, teeShieldingKey, aliceBitcoinIdentity, idGraph); - }); - - step('activating identity(alice bitcoin account)', async function () { - const aliceEvmNonce = currentNonce++; - - activateIdentityRequestParams.push({ - nonce: aliceEvmNonce, - identity: aliceEvmIdentity, - }); - - const idGraphHashResults: HexString[] = []; - let expectedIdGraphs: [CorePrimitivesIdentity, boolean][][] = [[[aliceEvmIdentity, true]]]; - - for (const { nonce, identity } of activateIdentityRequestParams) { - const requestIdentifier = `0x${randomBytes(32).toString('hex')}`; - const activateIdentityCall = await createSignedTrustedCallActivateIdentity( - context.api, - context.mrEnclave, - context.api.createType('Index', nonce), - context.web3Wallets.bitcoin.Alice, - - aliceBitcoinIdentity, - identity.toHex(), - context.api.createType('Option', aesKey).toHex(), - requestIdentifier - ); - - const res = await sendRequestFromTrustedCall(context, teeShieldingKey, activateIdentityCall); - idGraphHashResults.push( - await assertIdGraphMutationResult( - context, - teeShieldingKey, - aliceBitcoinIdentity, - res, - 'ActivateIdentityResult', - expectedIdGraphs[0] - ) - ); - expectedIdGraphs = expectedIdGraphs.slice(1, expectedIdGraphs.length); - await assertIsInSidechainBlock('activateIdentityCall', res); - } - assert.lengthOf(idGraphHashResults, 1); - }); - - step('check idGraph from sidechain storage after activating', async function () { - const idGraphGetter = await createSignedTrustedGetterIdGraph( - context.api, - context.web3Wallets.bitcoin.Alice, - aliceBitcoinIdentity - ); - const res = await sendRsaRequestFromGetter(context, teeShieldingKey, idGraphGetter); - const idGraph = decodeIdGraph(context.sidechainRegistry, res.value); - - for (const { identity } of linkIdentityRequestParams) { - const identityDump = JSON.stringify(identity.toHuman(), null, 4); - console.debug(`checking identity: ${identityDump}`); - const idGraphNode = idGraph.find(([idGraphNodeIdentity]) => idGraphNodeIdentity.eq(identity)); - assert.isDefined(idGraphNode, `identity not found in idGraph: ${identityDump}`); - const [, idGraphNodeContext] = idGraphNode!; - - assert.equal( - idGraphNodeContext.status.toString(), - 'Active', - `status should be active for identity: ${identityDump}` - ); - console.debug('active ✅'); - } - - await assertIdGraphHash(context, teeShieldingKey, aliceBitcoinIdentity, idGraph); - }); - step('check sidechain nonce', async function () { - await sleep(20); - const nonce = await getSidechainNonce(context, aliceBitcoinIdentity); - assert.equal(nonce.toNumber(), currentNonce); - }); -}); diff --git a/tee-worker/identity/ts-tests/integration-tests/di_evm_identity.test.ts b/tee-worker/identity/ts-tests/integration-tests/di_evm_identity.test.ts deleted file mode 100644 index c2b0608c14..0000000000 --- a/tee-worker/identity/ts-tests/integration-tests/di_evm_identity.test.ts +++ /dev/null @@ -1,370 +0,0 @@ -import { randomBytes, KeyObject } from 'crypto'; -import { step } from 'mocha-steps'; -import { assert } from 'chai'; -import { - buildValidations, - initIntegrationTestContext, - assertIdGraphMutationResult, - assertIdGraphHash, - sleep, -} from './common/utils'; -import { assertIsInSidechainBlock } from './common/utils/assertion'; -import { - createSignedTrustedCallLinkIdentity, - createSignedTrustedGetterIdGraph, - createSignedTrustedCallDeactivateIdentity, - createSignedTrustedCallActivateIdentity, - decodeIdGraph, - getSidechainNonce, - getTeeShieldingKey, - sendRequestFromTrustedCall, - sendAesRequestFromGetter, -} from './common/di-utils'; // @fixme move to a better place -import type { IntegrationTestContext } from './common/common-types'; -import { aesKey } from './common/call'; -import type { LitentryValidationData, Web3Network, CorePrimitivesIdentity } from 'parachain-api'; -import { Vec, Bytes } from '@polkadot/types'; -import type { HexString } from '@polkadot/util/types'; -import { hexToU8a } from '@polkadot/util'; - -describe('Test Identity (evm direct invocation)', function () { - let context: IntegrationTestContext = undefined as any; - let teeShieldingKey: KeyObject = undefined as any; - let aliceEvmIdentity: CorePrimitivesIdentity = undefined as any; - let bobEvmIdentity: CorePrimitivesIdentity; - let currentNonce = 0; - - // Alice links: - // - a `mock_user` twitter - // - alice's evm identity - // - eve's substrate identity (as alice can't link her own substrate again) - const linkIdentityRequestParams: { - nonce: number; - identity: CorePrimitivesIdentity; - validation: LitentryValidationData; - networks: Bytes | Vec; - }[] = []; - this.timeout(6000000); - - before(async () => { - context = await initIntegrationTestContext( - process.env.PARACHAIN_ENDPOINT! // @fixme evil assertion; centralize env access - ); - teeShieldingKey = await getTeeShieldingKey(context); - - aliceEvmIdentity = await context.web3Wallets.evm.Alice.getIdentity(context); - bobEvmIdentity = await context.web3Wallets.evm.Bob.getIdentity(context); - currentNonce = (await getSidechainNonce(context, aliceEvmIdentity)).toNumber(); - }); - - step('check idGraph from sidechain storage before linking', async function () { - const idGraphGetter = await createSignedTrustedGetterIdGraph( - context.api, - context.web3Wallets.evm.Alice, - aliceEvmIdentity - ); - const res = await sendAesRequestFromGetter(context, teeShieldingKey, hexToU8a(aesKey), idGraphGetter); - - const idGraph = decodeIdGraph(context.sidechainRegistry, res.value); - - assert.lengthOf(idGraph, 0); - }); - - step('linking identities (alice evm account)', async function () { - const bobEvmNonce = currentNonce++; - const bobEvmValidation = await buildValidations( - context, - aliceEvmIdentity, - bobEvmIdentity, - bobEvmNonce, - 'ethereum', - context.web3Wallets.evm.Bob, - { prettifiedMessage: true } - ); - const bobEvmNetworks = context.api.createType('Vec', ['Ethereum', 'Bsc']); - linkIdentityRequestParams.push({ - nonce: bobEvmNonce, - identity: bobEvmIdentity, - validation: bobEvmValidation, - networks: bobEvmNetworks, - }); - - const eveSubstrateNonce = currentNonce++; - - const eveSubstrateIdentity = await context.web3Wallets.substrate.Eve.getIdentity(context); - const eveSubstrateValidation = await buildValidations( - context, - aliceEvmIdentity, - eveSubstrateIdentity, - eveSubstrateNonce, - 'substrate', - context.web3Wallets.substrate.Eve - ); - const eveSubstrateNetworks = context.api.createType('Vec', ['Litentry', 'Khala']); - linkIdentityRequestParams.push({ - nonce: eveSubstrateNonce, - identity: eveSubstrateIdentity, - validation: eveSubstrateValidation, - networks: eveSubstrateNetworks, - }); - - const idGraphHashResults: HexString[] = []; - let expectedIdGraphs: [CorePrimitivesIdentity, boolean][][] = [ - [ - [aliceEvmIdentity, true], - [bobEvmIdentity, true], - ], - [[eveSubstrateIdentity, true]], - ]; - - let counter = 0; - for (const { nonce, identity, validation, networks } of linkIdentityRequestParams) { - counter++; - const requestIdentifier = `0x${randomBytes(32).toString('hex')}`; - const linkIdentityCall = await createSignedTrustedCallLinkIdentity( - context.api, - context.mrEnclave, - context.api.createType('Index', nonce), - context.web3Wallets.evm.Alice, - aliceEvmIdentity, - identity.toHex(), - validation.toHex(), - networks.toHex(), - context.api.createType('Option', aesKey).toHex(), - requestIdentifier, - { - withWrappedBytes: false, - withPrefix: counter % 2 === 0, // alternate per entry - } - ); - - const res = await sendRequestFromTrustedCall(context, teeShieldingKey, linkIdentityCall); - idGraphHashResults.push( - await assertIdGraphMutationResult( - context, - teeShieldingKey, - aliceEvmIdentity, - res, - 'LinkIdentityResult', - expectedIdGraphs[0] - ) - ); - expectedIdGraphs = expectedIdGraphs.slice(1, expectedIdGraphs.length); - await assertIsInSidechainBlock('linkIdentityCall', res); - } - assert.lengthOf(idGraphHashResults, 2); - }); - - step('check user sidechain storage after linking', async function () { - const idGraphGetter = await createSignedTrustedGetterIdGraph( - context.api, - context.web3Wallets.evm.Alice, - aliceEvmIdentity - ); - const res = await sendAesRequestFromGetter(context, teeShieldingKey, hexToU8a(aesKey), idGraphGetter); - - const idGraph = decodeIdGraph(context.sidechainRegistry, res.value); - - // according to the order of linkIdentityRequestParams - const expectedWeb3Networks = [ - ['Ethereum', 'Bsc'], - ['Litentry', 'Khala'], - ]; - let currentIndex = 0; - - for (const { identity } of linkIdentityRequestParams) { - const identityDump = JSON.stringify(identity.toHuman(), null, 4); - console.debug(`checking identity: ${identityDump}`); - const idGraphNode = idGraph.find(([idGraphNodeIdentity]) => idGraphNodeIdentity.eq(identity)); - assert.isDefined(idGraphNode, `identity not found in idGraph: ${identityDump}`); - const [, idGraphNodeContext] = idGraphNode!; - - const web3networks = idGraphNode![1].web3networks.toHuman(); - assert.deepEqual(web3networks, expectedWeb3Networks[currentIndex]); - - assert.equal( - idGraphNodeContext.status.toString(), - 'Active', - `status should be active for identity: ${identityDump}` - ); - console.debug('active ✅'); - - currentIndex++; - } - - await assertIdGraphHash(context, teeShieldingKey, aliceEvmIdentity, idGraph); - }); - step('deactivating identity(alice evm account)', async function () { - const deactivateIdentityRequestParams: { - nonce: number; - identity: CorePrimitivesIdentity; - }[] = []; - - const bobEvmNonce = currentNonce++; - - deactivateIdentityRequestParams.push({ - nonce: bobEvmNonce, - identity: bobEvmIdentity, - }); - - const eveSubstrateNonce = currentNonce++; - - const eveSubstrateIdentity = await context.web3Wallets.substrate.Eve.getIdentity(context); - deactivateIdentityRequestParams.push({ - nonce: eveSubstrateNonce, - identity: eveSubstrateIdentity, - }); - - const idGraphHashResults: HexString[] = []; - let expectedIdGraphs: [CorePrimitivesIdentity, boolean][][] = [ - [[bobEvmIdentity, false]], - [[eveSubstrateIdentity, false]], - ]; - - for (const { nonce, identity } of deactivateIdentityRequestParams) { - const requestIdentifier = `0x${randomBytes(32).toString('hex')}`; - const deactivateIdentityCall = await createSignedTrustedCallDeactivateIdentity( - context.api, - context.mrEnclave, - context.api.createType('Index', nonce), - context.web3Wallets.evm.Alice, - aliceEvmIdentity, - identity.toHex(), - context.api.createType('Option', aesKey).toHex(), - requestIdentifier - ); - - const res = await sendRequestFromTrustedCall(context, teeShieldingKey, deactivateIdentityCall); - idGraphHashResults.push( - await assertIdGraphMutationResult( - context, - teeShieldingKey, - aliceEvmIdentity, - res, - 'DeactivateIdentityResult', - expectedIdGraphs[0] - ) - ); - expectedIdGraphs = expectedIdGraphs.slice(1, expectedIdGraphs.length); - await assertIsInSidechainBlock('deactivateIdentityCall', res); - } - assert.lengthOf(idGraphHashResults, 2); - }); - - step('check idGraph from sidechain storage after deactivating', async function () { - const idGraphGetter = await createSignedTrustedGetterIdGraph( - context.api, - context.web3Wallets.evm.Alice, - aliceEvmIdentity - ); - const res = await sendAesRequestFromGetter(context, teeShieldingKey, hexToU8a(aesKey), idGraphGetter); - const idGraph = decodeIdGraph(context.sidechainRegistry, res.value); - - for (const { identity } of linkIdentityRequestParams) { - const identityDump = JSON.stringify(identity.toHuman(), null, 4); - console.debug(`checking identity: ${identityDump}`); - const idGraphNode = idGraph.find(([idGraphNodeIdentity]) => idGraphNodeIdentity.eq(identity)); - assert.isDefined(idGraphNode, `identity not found in idGraph: ${identityDump}`); - const [, idGraphNodeContext] = idGraphNode!; - - assert.equal( - idGraphNodeContext.status.toString(), - 'Inactive', - `status should be Inactive for identity: ${identityDump}` - ); - console.debug('inactive ✅'); - } - - await assertIdGraphHash(context, teeShieldingKey, aliceEvmIdentity, idGraph); - }); - step('activating identity(alice evm account)', async function () { - const activateIdentityRequestParams: { - nonce: number; - identity: CorePrimitivesIdentity; - }[] = []; - - const bobEvmNonce = currentNonce++; - - activateIdentityRequestParams.push({ - nonce: bobEvmNonce, - identity: bobEvmIdentity, - }); - - const eveSubstrateNonce = currentNonce++; - - const eveSubstrateIdentity = await context.web3Wallets.substrate.Eve.getIdentity(context); - - activateIdentityRequestParams.push({ - nonce: eveSubstrateNonce, - identity: eveSubstrateIdentity, - }); - - const idGraphHashResults: HexString[] = []; - let expectedIdGraphs: [CorePrimitivesIdentity, boolean][][] = [ - [[bobEvmIdentity, true]], - [[eveSubstrateIdentity, true]], - ]; - - for (const { nonce, identity } of activateIdentityRequestParams) { - const requestIdentifier = `0x${randomBytes(32).toString('hex')}`; - const activateIdentityCall = await createSignedTrustedCallActivateIdentity( - context.api, - context.mrEnclave, - context.api.createType('Index', nonce), - context.web3Wallets.evm.Alice, - aliceEvmIdentity, - identity.toHex(), - context.api.createType('Option', aesKey).toHex(), - requestIdentifier - ); - - const res = await sendRequestFromTrustedCall(context, teeShieldingKey, activateIdentityCall); - idGraphHashResults.push( - await assertIdGraphMutationResult( - context, - teeShieldingKey, - aliceEvmIdentity, - res, - 'ActivateIdentityResult', - expectedIdGraphs[0] - ) - ); - expectedIdGraphs = expectedIdGraphs.slice(1, expectedIdGraphs.length); - await assertIsInSidechainBlock('activateIdentityCall', res); - } - assert.lengthOf(idGraphHashResults, 2); - }); - - step('check idGraph from sidechain storage after activating', async function () { - const idGraphGetter = await createSignedTrustedGetterIdGraph( - context.api, - context.web3Wallets.evm.Alice, - - aliceEvmIdentity - ); - const res = await sendAesRequestFromGetter(context, teeShieldingKey, hexToU8a(aesKey), idGraphGetter); - const idGraph = decodeIdGraph(context.sidechainRegistry, res.value); - - for (const { identity } of linkIdentityRequestParams) { - const identityDump = JSON.stringify(identity.toHuman(), null, 4); - console.debug(`checking identity: ${identityDump}`); - const idGraphNode = idGraph.find(([idGraphNodeIdentity]) => idGraphNodeIdentity.eq(identity)); - assert.isDefined(idGraphNode, `identity not found in idGraph: ${identityDump}`); - const [, idGraphNodeContext] = idGraphNode!; - - assert.equal( - idGraphNodeContext.status.toString(), - 'Active', - `status should be active for identity: ${identityDump}` - ); - console.debug('active ✅'); - } - - await assertIdGraphHash(context, teeShieldingKey, aliceEvmIdentity, idGraph); - }); - step('check sidechain nonce', async function () { - await sleep(20); - const nonce = await getSidechainNonce(context, aliceEvmIdentity); - assert.equal(nonce.toNumber(), currentNonce); - }); -}); diff --git a/tee-worker/identity/ts-tests/integration-tests/di_identity.test.ts b/tee-worker/identity/ts-tests/integration-tests/di_identity.test.ts new file mode 100644 index 0000000000..334ca52e4c --- /dev/null +++ b/tee-worker/identity/ts-tests/integration-tests/di_identity.test.ts @@ -0,0 +1,362 @@ +import { randomBytes, KeyObject } from 'crypto'; +import { step } from 'mocha-steps'; +import { assert } from 'chai'; +import { + buildValidations, + initIntegrationTestContext, + assertIdGraphMutationResult, + assertIdGraphHash, + sleep, + Signer, + buildWeb2Validation, + buildIdentityHelper, +} from './common/utils'; +import { assertIsInSidechainBlock } from './common/utils/assertion'; +import { + createSignedTrustedCallLinkIdentity, + createSignedTrustedGetterIdGraph, + createSignedTrustedCallDeactivateIdentity, + createSignedTrustedCallActivateIdentity, + decodeIdGraph, + getSidechainNonce, + getTeeShieldingKey, + sendRequestFromTrustedCall, + sendAesRequestFromGetter, +} from './common/di-utils'; // @fixme move to a better place +import type { IntegrationTestContext, WalletType } from './common/common-types'; +import { aesKey } from './common/call'; +import { createWeb3Wallet } from './common/helpers'; +import type { Web3Network, CorePrimitivesIdentity } from 'parachain-api'; +import { Vec, Bytes } from '@polkadot/types'; +import type { HexString } from '@polkadot/util/types'; +import { hexToU8a } from '@polkadot/util'; + +describe('Test Identity', function () { + const identityConfigs: { + [key: string]: { + wallet: string; + networks: string[]; + }; + } = { + evm: { + wallet: 'Bob', + networks: ['Ethereum'], + }, + substrate: { + wallet: 'Alice', + networks: ['Litentry'], + }, + bitcoin: { + wallet: 'Charlie', + networks: ['BitcoinP2tr'], + }, + solana: { + wallet: 'Dave', + networks: ['Solana'], + }, + }; + const identityNames = Object.keys(identityConfigs); + + let context: IntegrationTestContext = undefined as any; + let teeShieldingKey: KeyObject = undefined as any; + this.timeout(6000000); + + before(async function () { + const parachainEndpoint = process.env.PARACHAIN_ENDPOINT; + if (!parachainEndpoint) { + throw new Error('PARACHAIN_ENDPOINT environment variable is missing.'); + } + context = await initIntegrationTestContext(parachainEndpoint); + teeShieldingKey = await getTeeShieldingKey(context); + }); + + for (const identityName of identityNames) { + describe(`(${identityName} direct invocation)`, function () { + const linkedIdentityNetworks: { + identity: CorePrimitivesIdentity; + networks: Bytes | Vec; + }[] = []; + + let mainIdentity: CorePrimitivesIdentity = undefined as any; + let mainSigner: Signer = undefined as any; + let currentNonce = 0; + const isSubstrate = identityName === 'substrate'; + const walletName = identityConfigs[identityName].wallet; + + const getNextNonce = () => currentNonce++; + + before(async function () { + const wallet = (context.web3Wallets as any)[identityName] as WalletType; + mainSigner = wallet[walletName]; + + mainIdentity = await mainSigner.getIdentity(context); + currentNonce = (await getSidechainNonce(context, mainIdentity)).toNumber(); + }); + + step('check idGraph from sidechain storage before linking', async function () { + const idGraphGetter = await createSignedTrustedGetterIdGraph(context.api, mainSigner, mainIdentity); + const res = await sendAesRequestFromGetter(context, teeShieldingKey, hexToU8a(aesKey), idGraphGetter); + + const idGraph = decodeIdGraph(context.sidechainRegistry, res.value); + + assert.lengthOf(idGraph, 0); + }); + + step(`linking identities (${walletName} ${identityName} account)`, async function () { + const idGraphHashResults: HexString[] = []; + + const linkAndAssert = async ( + identityName: string, + identity: CorePrimitivesIdentity, + expectedIdGraph: [CorePrimitivesIdentity, boolean][], + signer?: Signer, + identityType?: string, + verificationType?: string + ) => { + const nonce = getNextNonce(); + const validationData = signer + ? await buildValidations(context, mainIdentity, identity, nonce, identityName as any, signer) + : await buildWeb2Validation({ + identityType, + context, + signerIdentitity: mainIdentity, + linkIdentity: identity, + verificationType, + validationNonce: nonce, + } as any); + + const networks = context.api.createType( + 'Vec', + identityConfigs[identityName]?.networks ?? [] + ); + const requestIdentifier = `0x${randomBytes(32).toString('hex')}`; + const linkIdentityCall = await createSignedTrustedCallLinkIdentity( + context.api, + context.mrEnclave, + context.api.createType('Index', nonce), + mainSigner, + mainIdentity, + identity.toHex(), + validationData.toHex(), + networks.toHex(), + context.api.createType('Option', aesKey).toHex(), + requestIdentifier, + { + withWrappedBytes: false, + withPrefix: (idGraphHashResults.length + 1) % 2 === 0, // alternate per entry + } + ); + const res = await sendRequestFromTrustedCall(context, teeShieldingKey, linkIdentityCall); + idGraphHashResults.push( + await assertIdGraphMutationResult( + context, + teeShieldingKey, + mainIdentity, + res, + 'LinkIdentityResult', + expectedIdGraph + ) + ); + await assertIsInSidechainBlock('linkIdentityCall', res); + + linkedIdentityNetworks.push({ + identity, + networks, + }); + }; + + // link identity + for (let i = 0; i < identityNames.length; i++) { + const identityName = identityNames[i]; + const signer = createWeb3Wallet(identityName, randomBytes(32).toString('base64')); + const identity = await signer.getIdentity(context); + + const expectedIdGraph: [CorePrimitivesIdentity, boolean][] = + i === 0 + ? [ + [mainIdentity, true], + [identity, true], + ] + : [[identity, true]]; + + await linkAndAssert(identityName, identity, expectedIdGraph, signer); + } + + // Web2 + if (isSubstrate) { + // discord + const discordIdentity = await buildIdentityHelper('bob', 'Discord', context); + await linkAndAssert( + 'discord', + discordIdentity, + [[discordIdentity, true]], + undefined, + 'Discord', + 'OAuth2' + ); + + // twitter + const twitterIdentity = await buildIdentityHelper('mock_user', 'Twitter', context); + await linkAndAssert( + 'twitter', + twitterIdentity, + [[twitterIdentity, true]], + undefined, + 'Twitter', + 'PublicTweet' + ); + } + + assert.lengthOf(idGraphHashResults, linkedIdentityNetworks.length); + }); + + step('check user sidechain storage after linking', async function () { + const idGraphGetter = await createSignedTrustedGetterIdGraph(context.api, mainSigner, mainIdentity); + const res = await sendAesRequestFromGetter(context, teeShieldingKey, hexToU8a(aesKey), idGraphGetter); + + const idGraph = decodeIdGraph(context.sidechainRegistry, res.value); + + for (const { identity, networks } of linkedIdentityNetworks) { + const identityDump = JSON.stringify(identity.toHuman(), null, 4); + console.debug(`checking identity: ${identityDump}`); + const idGraphNode = idGraph.find(([idGraphNodeIdentity]) => idGraphNodeIdentity.eq(identity)); + assert.isDefined(idGraphNode, `identity not found in idGraph: ${identityDump}`); + const [, idGraphNodeContext] = idGraphNode!; + + const web3networks = idGraphNode![1].web3networks.toHuman(); + assert.deepEqual(web3networks, networks.toHuman()); + + assert.equal( + idGraphNodeContext.status.toString(), + 'Active', + `status should be active for identity: ${identityDump}` + ); + console.debug('active ✅'); + } + + await assertIdGraphHash(context, teeShieldingKey, mainIdentity, idGraph); + }); + + step(`deactivating identity(${walletName} ${identityName} account)`, async function () { + const idGraphHashResults: HexString[] = []; + for (const { identity } of linkedIdentityNetworks) { + const nonce = getNextNonce(); + const requestIdentifier = `0x${randomBytes(32).toString('hex')}`; + const deactivateIdentityCall = await createSignedTrustedCallDeactivateIdentity( + context.api, + context.mrEnclave, + context.api.createType('Index', nonce), + mainSigner, + mainIdentity, + identity.toHex(), + context.api.createType('Option', aesKey).toHex(), + requestIdentifier + ); + + const expectedIdGraph: [CorePrimitivesIdentity, boolean][] = [[identity, false]]; + + const res = await sendRequestFromTrustedCall(context, teeShieldingKey, deactivateIdentityCall); + idGraphHashResults.push( + await assertIdGraphMutationResult( + context, + teeShieldingKey, + mainIdentity, + res, + 'DeactivateIdentityResult', + expectedIdGraph + ) + ); + await assertIsInSidechainBlock('deactivateIdentityCall', res); + } + + assert.lengthOf(idGraphHashResults, linkedIdentityNetworks.length); + }); + + step('check idGraph from sidechain storage after deactivating', async function () { + const idGraphGetter = await createSignedTrustedGetterIdGraph(context.api, mainSigner, mainIdentity); + const res = await sendAesRequestFromGetter(context, teeShieldingKey, hexToU8a(aesKey), idGraphGetter); + const idGraph = decodeIdGraph(context.sidechainRegistry, res.value); + + for (const { identity } of linkedIdentityNetworks) { + const identityDump = JSON.stringify(identity.toHuman(), null, 4); + console.debug(`checking identity: ${identityDump}`); + const idGraphNode = idGraph.find(([idGraphNodeIdentity]) => idGraphNodeIdentity.eq(identity)); + assert.isDefined(idGraphNode, `identity not found in idGraph: ${identityDump}`); + const [, idGraphNodeContext] = idGraphNode!; + + assert.equal( + idGraphNodeContext.status.toString(), + 'Inactive', + `status should be Inactive for identity: ${identityDump}` + ); + console.debug('inactive ✅'); + } + + await assertIdGraphHash(context, teeShieldingKey, mainIdentity, idGraph); + }); + + step(`activating identity(${walletName} ${identityName} account)`, async function () { + const idGraphHashResults: HexString[] = []; + for (const { identity } of linkedIdentityNetworks) { + const nonce = getNextNonce(); + const requestIdentifier = `0x${randomBytes(32).toString('hex')}`; + const activateIdentityCall = await createSignedTrustedCallActivateIdentity( + context.api, + context.mrEnclave, + context.api.createType('Index', nonce), + mainSigner, + mainIdentity, + identity.toHex(), + context.api.createType('Option', aesKey).toHex(), + requestIdentifier + ); + + const expectedIdGraph: [CorePrimitivesIdentity, boolean][] = [[identity, true]]; + + const res = await sendRequestFromTrustedCall(context, teeShieldingKey, activateIdentityCall); + idGraphHashResults.push( + await assertIdGraphMutationResult( + context, + teeShieldingKey, + mainIdentity, + res, + 'ActivateIdentityResult', + expectedIdGraph + ) + ); + await assertIsInSidechainBlock('activateIdentityCall', res); + } + assert.lengthOf(idGraphHashResults, linkedIdentityNetworks.length); + }); + + step('check idGraph from sidechain storage after activating', async function () { + const idGraphGetter = await createSignedTrustedGetterIdGraph(context.api, mainSigner, mainIdentity); + const res = await sendAesRequestFromGetter(context, teeShieldingKey, hexToU8a(aesKey), idGraphGetter); + const idGraph = decodeIdGraph(context.sidechainRegistry, res.value); + + for (const { identity } of linkedIdentityNetworks) { + const identityDump = JSON.stringify(identity.toHuman(), null, 4); + console.debug(`checking identity: ${identityDump}`); + const idGraphNode = idGraph.find(([idGraphNodeIdentity]) => idGraphNodeIdentity.eq(identity)); + assert.isDefined(idGraphNode, `identity not found in idGraph: ${identityDump}`); + const [, idGraphNodeContext] = idGraphNode!; + + assert.equal( + idGraphNodeContext.status.toString(), + 'Active', + `status should be active for identity: ${identityDump}` + ); + console.debug('active ✅'); + } + + await assertIdGraphHash(context, teeShieldingKey, mainIdentity, idGraph); + }); + + step('check sidechain nonce', async function () { + await sleep(20); + const nonce = await getSidechainNonce(context, mainIdentity); + assert.equal(nonce.toNumber(), currentNonce); + }); + }); + } +}); diff --git a/tee-worker/identity/ts-tests/integration-tests/di_solana_identity.test.ts b/tee-worker/identity/ts-tests/integration-tests/di_solana_identity.test.ts deleted file mode 100644 index dcc8b8a104..0000000000 --- a/tee-worker/identity/ts-tests/integration-tests/di_solana_identity.test.ts +++ /dev/null @@ -1,365 +0,0 @@ -import { randomBytes, KeyObject } from 'crypto'; -import { step } from 'mocha-steps'; -import { assert } from 'chai'; -import { - buildValidations, - initIntegrationTestContext, - assertIdGraphMutationResult, - assertIdGraphHash, - sleep, -} from './common/utils'; -import { assertIsInSidechainBlock } from './common/utils/assertion'; -import { - createSignedTrustedCallLinkIdentity, - createSignedTrustedGetterIdGraph, - createSignedTrustedCallDeactivateIdentity, - createSignedTrustedCallActivateIdentity, - decodeIdGraph, - getSidechainNonce, - getTeeShieldingKey, - sendRsaRequestFromGetter, - sendRequestFromTrustedCall, -} from './common/di-utils'; // @fixme move to a better place -import type { IntegrationTestContext } from './common/common-types'; -import { aesKey } from './common/call'; -import type { LitentryValidationData, Web3Network, CorePrimitivesIdentity } from 'parachain-api'; -import { Vec, Bytes } from '@polkadot/types'; -import type { HexString } from '@polkadot/util/types'; - -describe('Test Identity (solana direct invocation)', function () { - let context: IntegrationTestContext = undefined as any; - let teeShieldingKey: KeyObject = undefined as any; - let aliceSolanaIdentity: CorePrimitivesIdentity = undefined as any; - let bobSolanaIdentity: CorePrimitivesIdentity; - let currentNonce = 0; - - // Alice links: - // - alice's solana identity - // - eve's substrate identity (as alice can't link her own substrate again) - const linkIdentityRequestParams: { - nonce: number; - identity: CorePrimitivesIdentity; - validation: LitentryValidationData; - networks: Bytes | Vec; - }[] = []; - this.timeout(6000000); - - before(async () => { - context = await initIntegrationTestContext( - process.env.PARACHAIN_ENDPOINT! // @fixme evil assertion; centralize env access - ); - teeShieldingKey = await getTeeShieldingKey(context); - - aliceSolanaIdentity = await context.web3Wallets.solana.Alice.getIdentity(context); - bobSolanaIdentity = await context.web3Wallets.solana.Bob.getIdentity(context); - currentNonce = (await getSidechainNonce(context, aliceSolanaIdentity)).toNumber(); - }); - - step('check idGraph from sidechain storage before linking', async function () { - const idGraphGetter = await createSignedTrustedGetterIdGraph( - context.api, - context.web3Wallets.solana.Alice, - aliceSolanaIdentity - ); - const res = await sendRsaRequestFromGetter(context, teeShieldingKey, idGraphGetter); - - const idGraph = decodeIdGraph(context.sidechainRegistry, res.value); - - assert.lengthOf(idGraph, 0); - }); - - step('linking identities (alice solana account)', async function () { - const bobSolanaNonce = currentNonce++; - const bobSolanaValidation = await buildValidations( - context, - aliceSolanaIdentity, - bobSolanaIdentity, - bobSolanaNonce, - 'solana', - context.web3Wallets.solana.Bob, - { prettifiedMessage: true } - ); - const bobSolanaNetworks = context.api.createType('Vec', ['Solana']); - linkIdentityRequestParams.push({ - nonce: bobSolanaNonce, - identity: bobSolanaIdentity, - validation: bobSolanaValidation, - networks: bobSolanaNetworks, - }); - - const eveSubstrateNonce = currentNonce++; - - const eveSubstrateIdentity = await context.web3Wallets.substrate.Eve.getIdentity(context); - const eveSubstrateValidation = await buildValidations( - context, - aliceSolanaIdentity, - eveSubstrateIdentity, - eveSubstrateNonce, - 'substrate', - context.web3Wallets.substrate.Eve - ); - const eveSubstrateNetworks = context.api.createType('Vec', ['Litentry', 'Khala']); - linkIdentityRequestParams.push({ - nonce: eveSubstrateNonce, - identity: eveSubstrateIdentity, - validation: eveSubstrateValidation, - networks: eveSubstrateNetworks, - }); - - const idGraphHashResults: HexString[] = []; - let expectedIdGraphs: [CorePrimitivesIdentity, boolean][][] = [ - [ - [aliceSolanaIdentity, true], - [bobSolanaIdentity, true], - ], - [[eveSubstrateIdentity, true]], - ]; - - let counter = 0; - for (const { nonce, identity, validation, networks } of linkIdentityRequestParams) { - counter++; - const requestIdentifier = `0x${randomBytes(32).toString('hex')}`; - const linkIdentityCall = await createSignedTrustedCallLinkIdentity( - context.api, - context.mrEnclave, - context.api.createType('Index', nonce), - context.web3Wallets.solana.Alice, - aliceSolanaIdentity, - identity.toHex(), - validation.toHex(), - networks.toHex(), - context.api.createType('Option', aesKey).toHex(), - requestIdentifier, - { - withWrappedBytes: false, - withPrefix: counter % 2 === 0, // alternate per entry - } - ); - - const res = await sendRequestFromTrustedCall(context, teeShieldingKey, linkIdentityCall); - idGraphHashResults.push( - await assertIdGraphMutationResult( - context, - teeShieldingKey, - aliceSolanaIdentity, - res, - 'LinkIdentityResult', - expectedIdGraphs[0] - ) - ); - expectedIdGraphs = expectedIdGraphs.slice(1, expectedIdGraphs.length); - await assertIsInSidechainBlock('linkIdentityCall', res); - } - assert.lengthOf(idGraphHashResults, 2); - }); - - step('check user sidechain storage after linking', async function () { - const idGraphGetter = await createSignedTrustedGetterIdGraph( - context.api, - context.web3Wallets.solana.Alice, - aliceSolanaIdentity - ); - const res = await sendRsaRequestFromGetter(context, teeShieldingKey, idGraphGetter); - - const idGraph = decodeIdGraph(context.sidechainRegistry, res.value); - - // according to the order of linkIdentityRequestParams - const expectedWeb3Networks = [['Solana'], ['Litentry', 'Khala']]; - let currentIndex = 0; - - for (const { identity } of linkIdentityRequestParams) { - const identityDump = JSON.stringify(identity.toHuman(), null, 4); - console.debug(`checking identity: ${identityDump}`); - const idGraphNode = idGraph.find(([idGraphNodeIdentity]) => idGraphNodeIdentity.eq(identity)); - assert.isDefined(idGraphNode, `identity not found in idGraph: ${identityDump}`); - const [, idGraphNodeContext] = idGraphNode!; - - const web3networks = idGraphNode![1].web3networks.toHuman(); - assert.deepEqual(web3networks, expectedWeb3Networks[currentIndex]); - - assert.equal( - idGraphNodeContext.status.toString(), - 'Active', - `status should be active for identity: ${identityDump}` - ); - console.debug('active ✅'); - - currentIndex++; - } - - await assertIdGraphHash(context, teeShieldingKey, aliceSolanaIdentity, idGraph); - }); - step('deactivating identity(alice solana account)', async function () { - const deactivateIdentityRequestParams: { - nonce: number; - identity: CorePrimitivesIdentity; - }[] = []; - - const bobSolanaNonce = currentNonce++; - - deactivateIdentityRequestParams.push({ - nonce: bobSolanaNonce, - identity: bobSolanaIdentity, - }); - - const eveSubstrateNonce = currentNonce++; - - const eveSubstrateIdentity = await context.web3Wallets.substrate.Eve.getIdentity(context); - deactivateIdentityRequestParams.push({ - nonce: eveSubstrateNonce, - identity: eveSubstrateIdentity, - }); - - const idGraphHashResults: HexString[] = []; - let expectedIdGraphs: [CorePrimitivesIdentity, boolean][][] = [ - [[bobSolanaIdentity, false]], - [[eveSubstrateIdentity, false]], - ]; - - for (const { nonce, identity } of deactivateIdentityRequestParams) { - const requestIdentifier = `0x${randomBytes(32).toString('hex')}`; - const deactivateIdentityCall = await createSignedTrustedCallDeactivateIdentity( - context.api, - context.mrEnclave, - context.api.createType('Index', nonce), - context.web3Wallets.solana.Alice, - aliceSolanaIdentity, - identity.toHex(), - context.api.createType('Option', aesKey).toHex(), - requestIdentifier - ); - - const res = await sendRequestFromTrustedCall(context, teeShieldingKey, deactivateIdentityCall); - idGraphHashResults.push( - await assertIdGraphMutationResult( - context, - teeShieldingKey, - aliceSolanaIdentity, - res, - 'DeactivateIdentityResult', - expectedIdGraphs[0] - ) - ); - expectedIdGraphs = expectedIdGraphs.slice(1, expectedIdGraphs.length); - await assertIsInSidechainBlock('deactivateIdentityCall', res); - } - assert.lengthOf(idGraphHashResults, 2); - }); - - step('check idGraph from sidechain storage after deactivating', async function () { - const idGraphGetter = await createSignedTrustedGetterIdGraph( - context.api, - context.web3Wallets.solana.Alice, - aliceSolanaIdentity - ); - const res = await sendRsaRequestFromGetter(context, teeShieldingKey, idGraphGetter); - const idGraph = decodeIdGraph(context.sidechainRegistry, res.value); - - for (const { identity } of linkIdentityRequestParams) { - const identityDump = JSON.stringify(identity.toHuman(), null, 4); - console.debug(`checking identity: ${identityDump}`); - const idGraphNode = idGraph.find(([idGraphNodeIdentity]) => idGraphNodeIdentity.eq(identity)); - assert.isDefined(idGraphNode, `identity not found in idGraph: ${identityDump}`); - const [, idGraphNodeContext] = idGraphNode!; - - assert.equal( - idGraphNodeContext.status.toString(), - 'Inactive', - `status should be Inactive for identity: ${identityDump}` - ); - console.debug('inactive ✅'); - } - - await assertIdGraphHash(context, teeShieldingKey, aliceSolanaIdentity, idGraph); - }); - step('activating identity(alice solana account)', async function () { - const activateIdentityRequestParams: { - nonce: number; - identity: CorePrimitivesIdentity; - }[] = []; - - const bobSolanaNonce = currentNonce++; - - activateIdentityRequestParams.push({ - nonce: bobSolanaNonce, - identity: bobSolanaIdentity, - }); - - const eveSubstrateNonce = currentNonce++; - - const eveSubstrateIdentity = await context.web3Wallets.substrate.Eve.getIdentity(context); - - activateIdentityRequestParams.push({ - nonce: eveSubstrateNonce, - identity: eveSubstrateIdentity, - }); - - const idGraphHashResults: HexString[] = []; - let expectedIdGraphs: [CorePrimitivesIdentity, boolean][][] = [ - [[bobSolanaIdentity, true]], - [[eveSubstrateIdentity, true]], - ]; - - for (const { nonce, identity } of activateIdentityRequestParams) { - const requestIdentifier = `0x${randomBytes(32).toString('hex')}`; - const activateIdentityCall = await createSignedTrustedCallActivateIdentity( - context.api, - context.mrEnclave, - context.api.createType('Index', nonce), - context.web3Wallets.solana.Alice, - aliceSolanaIdentity, - identity.toHex(), - context.api.createType('Option', aesKey).toHex(), - requestIdentifier - ); - - const res = await sendRequestFromTrustedCall(context, teeShieldingKey, activateIdentityCall); - idGraphHashResults.push( - await assertIdGraphMutationResult( - context, - teeShieldingKey, - aliceSolanaIdentity, - res, - 'ActivateIdentityResult', - expectedIdGraphs[0] - ) - ); - expectedIdGraphs = expectedIdGraphs.slice(1, expectedIdGraphs.length); - await assertIsInSidechainBlock('activateIdentityCall', res); - } - assert.lengthOf(idGraphHashResults, 2); - }); - - step('check idGraph from sidechain storage after activating', async function () { - const idGraphGetter = await createSignedTrustedGetterIdGraph( - context.api, - context.web3Wallets.solana.Alice, - aliceSolanaIdentity - ); - const res = await sendRsaRequestFromGetter(context, teeShieldingKey, idGraphGetter); - const idGraph = decodeIdGraph(context.sidechainRegistry, res.value); - - for (const { identity } of linkIdentityRequestParams) { - const identityDump = JSON.stringify(identity.toHuman(), null, 4); - console.debug(`checking identity: ${identityDump}`); - const idGraphNode = idGraph.find(([idGraphNodeIdentity]) => idGraphNodeIdentity.eq(identity)); - assert.isDefined(idGraphNode, `identity not found in idGraph: ${identityDump}`); - const [, idGraphNodeContext] = idGraphNode!; - - assert.equal( - idGraphNodeContext.status.toString(), - 'Active', - `status should be active for identity: ${identityDump}` - ); - console.debug('active ✅'); - } - - await assertIdGraphHash(context, teeShieldingKey, aliceSolanaIdentity, idGraph); - }); - - step('check sidechain nonce', async function () { - await sleep(20); - const nonce = await getSidechainNonce(context, aliceSolanaIdentity); - assert.equal(nonce.toNumber(), currentNonce); - }); -}); diff --git a/tee-worker/identity/ts-tests/integration-tests/di_substrate_identity.test.ts b/tee-worker/identity/ts-tests/integration-tests/di_substrate_identity.test.ts deleted file mode 100644 index 1553d92f55..0000000000 --- a/tee-worker/identity/ts-tests/integration-tests/di_substrate_identity.test.ts +++ /dev/null @@ -1,829 +0,0 @@ -import { randomBytes, KeyObject } from 'crypto'; -import { step } from 'mocha-steps'; -import { assert } from 'chai'; -import { u8aToHex, u8aToString } from '@polkadot/util'; -import { - assertIdGraphMutationResult, - assertIdGraphHash, - assertWorkerError, - buildIdentityHelper, - buildValidations, - initIntegrationTestContext, - buildWeb2Validation, -} from './common/utils'; -import { assertIsInSidechainBlock } from './common/utils/assertion'; -import { - createSignedTrustedCallLinkIdentity, - createSignedTrustedGetterIdGraph, - createSignedTrustedCallDeactivateIdentity, - createSignedTrustedCallActivateIdentity, - decodeIdGraph, - getSidechainNonce, - getTeeShieldingKey, - sendRsaRequestFromGetter, - sendRequestFromTrustedCall, - createSignedTrustedCallSetIdentityNetworks, - createSignedTrustedCall, -} from './common/di-utils'; // @fixme move to a better place -import type { IntegrationTestContext } from './common/common-types'; -import { aesKey } from './common/call'; -import type { LitentryValidationData, Web3Network, CorePrimitivesIdentity } from 'parachain-api'; -import type { Vec, Bytes } from '@polkadot/types'; -import { ethers } from 'ethers'; -import type { HexString } from '@polkadot/util/types'; -import { sleep } from './common/utils'; - -describe('Test Identity (direct invocation)', function () { - let context: IntegrationTestContext = undefined as any; - let teeShieldingKey: KeyObject = undefined as any; - let aliceSubstrateIdentity: CorePrimitivesIdentity = undefined as any; - let bobSubstrateIdentity: CorePrimitivesIdentity = undefined as any; - let charlieSubstrateIdentity: CorePrimitivesIdentity = undefined as any; - let aliceCurrentNonce = 0; - let bobCurrentNonce = 0; - let charlieCurrentNonce = 0; - // Alice links: - // - a `mock_user` twitter - // - alice's evm identity - // - eve's substrate identity (as alice can't link her own substrate again) - // - alice's bitcoin identity - const linkIdentityRequestParams: { - nonce: number; - identity: CorePrimitivesIdentity; - validation: LitentryValidationData; - networks: Bytes | Vec; - }[] = []; - this.timeout(6000000); - - before(async () => { - context = await initIntegrationTestContext( - process.env.PARACHAIN_ENDPOINT! // @fixme evil assertion; centralize env access - ); - teeShieldingKey = await getTeeShieldingKey(context); - aliceSubstrateIdentity = await context.web3Wallets.substrate.Alice.getIdentity(context); - bobSubstrateIdentity = await context.web3Wallets.substrate.Bob.getIdentity(context); - charlieSubstrateIdentity = await context.web3Wallets.substrate.Charlie.getIdentity(context); - aliceCurrentNonce = (await getSidechainNonce(context, aliceSubstrateIdentity)).toNumber(); - bobCurrentNonce = (await getSidechainNonce(context, bobSubstrateIdentity)).toNumber(); - charlieCurrentNonce = (await getSidechainNonce(context, charlieSubstrateIdentity)).toNumber(); - }); - - step('check idgraph from sidechain storage before linking', async function () { - const idGraphGetter = await createSignedTrustedGetterIdGraph( - context.api, - context.web3Wallets.substrate.Alice, - aliceSubstrateIdentity - ); - const res = await sendRsaRequestFromGetter(context, teeShieldingKey, idGraphGetter); - - const idGraph = decodeIdGraph(context.sidechainRegistry, res.value); - - assert.lengthOf(idGraph, 0); - }); - - step('linking identities (alice)', async function () { - const twitterNonce = aliceCurrentNonce++; - - const twitterIdentity = await buildIdentityHelper('mock_user', 'Twitter', context); - - const twitterValidation = await buildWeb2Validation({ - identityType: 'Twitter', - context, - signerIdentitity: aliceSubstrateIdentity, - linkIdentity: twitterIdentity, - verificationType: 'PublicTweet', - validationNonce: twitterNonce, - }); - const twitterNetworks = context.api.createType('Vec', []); - linkIdentityRequestParams.push({ - nonce: twitterNonce, - identity: twitterIdentity, - validation: twitterValidation, - networks: twitterNetworks, - }); - - const evmNonce = aliceCurrentNonce++; - - const evmIdentity = await context.web3Wallets.evm.Alice.getIdentity(context); - const evmValidation = await buildValidations( - context, - aliceSubstrateIdentity, - evmIdentity, - evmNonce, - 'ethereum', - context.web3Wallets.evm.Alice - ); - const evmNetworks = context.api.createType('Vec', ['Ethereum', 'Bsc']); - linkIdentityRequestParams.push({ - nonce: evmNonce, - identity: evmIdentity, - validation: evmValidation, - networks: evmNetworks, - }); - - const eveSubstrateNonce = aliceCurrentNonce++; - const eveSubstrateIdentity = await buildIdentityHelper( - u8aToHex(context.web3Wallets.substrate.Eve.getAddressRaw()), - 'Substrate', - context - ); - const eveSubstrateValidation = await buildValidations( - context, - aliceSubstrateIdentity, - eveSubstrateIdentity, - eveSubstrateNonce, - 'substrate', - context.web3Wallets.substrate.Eve, - { prettifiedMessage: true } - ); - const eveSubstrateNetworks = context.api.createType('Vec', ['Polkadot', 'Litentry']); - linkIdentityRequestParams.push({ - nonce: eveSubstrateNonce, - identity: eveSubstrateIdentity, - validation: eveSubstrateValidation, - networks: eveSubstrateNetworks, - }); - - const bitcoinNonce = aliceCurrentNonce++; - const bitcoinIdentity = await buildIdentityHelper( - u8aToHex(context.web3Wallets.bitcoin.Alice.getAddressRaw()), - 'Bitcoin', - context - ); - console.log('bitcoin id: ', bitcoinIdentity.toHuman()); - const bitcoinValidation = await buildValidations( - context, - aliceSubstrateIdentity, - bitcoinIdentity, - bitcoinNonce, - 'bitcoin', - context.web3Wallets.bitcoin.Alice - ); - const bitcoinNetworks = context.api.createType('Vec', ['BitcoinP2tr']); - linkIdentityRequestParams.push({ - nonce: bitcoinNonce, - identity: bitcoinIdentity, - validation: bitcoinValidation, - networks: bitcoinNetworks, - }); - - const idGraphHashResults: HexString[] = []; - let expectedIdGraphs: [CorePrimitivesIdentity, boolean][][] = [ - [ - [aliceSubstrateIdentity, true], - [twitterIdentity, true], - ], - [[evmIdentity, true]], - [[eveSubstrateIdentity, true]], - [[bitcoinIdentity, true]], - ]; - - let counter = 0; - for (const { nonce, identity, validation, networks } of linkIdentityRequestParams) { - counter++; - const requestIdentifier = `0x${randomBytes(32).toString('hex')}`; - const linkIdentityCall = await createSignedTrustedCallLinkIdentity( - context.api, - context.mrEnclave, - context.api.createType('Index', nonce), - context.web3Wallets.substrate.Alice, - aliceSubstrateIdentity, - identity.toHex(), - validation.toHex(), - networks.toHex(), - context.api.createType('Option', aesKey).toHex(), - requestIdentifier, - { - withWrappedBytes: false, - withPrefix: counter % 2 === 0, // alternate per entry - } - ); - - const res = await sendRequestFromTrustedCall(context, teeShieldingKey, linkIdentityCall); - idGraphHashResults.push( - await assertIdGraphMutationResult( - context, - teeShieldingKey, - aliceSubstrateIdentity, - res, - 'LinkIdentityResult', - expectedIdGraphs[0] - ) - ); - expectedIdGraphs = expectedIdGraphs.slice(1, expectedIdGraphs.length); - await assertIsInSidechainBlock('linkIdentityCall', res); - } - assert.lengthOf(idGraphHashResults, 4); - }); - - step('check user sidechain storage after linking', async function () { - const idGraphGetter = await createSignedTrustedGetterIdGraph( - context.api, - context.web3Wallets.substrate.Alice, - - aliceSubstrateIdentity - ); - const res = await sendRsaRequestFromGetter(context, teeShieldingKey, idGraphGetter); - - const idGraph = decodeIdGraph(context.sidechainRegistry, res.value); - - // according to the order of linkIdentityRequestParams - const expectedWeb3Networks = [[], ['Ethereum', 'Bsc'], ['Polkadot', 'Litentry'], ['BitcoinP2tr']]; - let currentIndex = 0; - - for (const { identity } of linkIdentityRequestParams) { - const identityDump = JSON.stringify(identity.toHuman(), null, 4); - console.debug(`checking identity: ${identityDump}`); - const idGraphNode = idGraph.find(([idGraphNodeIdentity]) => idGraphNodeIdentity.eq(identity)); - assert.isDefined(idGraphNode, `identity not found in idGraph: ${identityDump}`); - const [, idGraphNodeContext] = idGraphNode!; - - const web3networks = idGraphNode![1].web3networks.toHuman(); - assert.deepEqual(web3networks, expectedWeb3Networks[currentIndex]); - - assert.equal( - idGraphNodeContext.status.toString(), - 'Active', - `status should be active for identity: ${identityDump}` - ); - console.debug('active ✅'); - - currentIndex++; - } - - await assertIdGraphHash(context, teeShieldingKey, aliceSubstrateIdentity, idGraph); - }); - - step('linking identity with wrong signature', async function () { - const evmIdentity = await context.web3Wallets.evm.Alice.getIdentity(context); - - const evmNetworks = context.api.createType('Vec', ['Ethereum', 'Bsc']); - - const evmNonce = aliceCurrentNonce++; - - // random wrong msg - const wrongMsg = '0x693d9131808e7a8574c7ea5eb7813bdf356223263e61fa8fe2ee8e434508bc75'; - const evmSignature = await context.web3Wallets.evm.Alice.sign(ethers.utils.arrayify(wrongMsg)); - - const evmValidationData = { - Web3Validation: { - Evm: { - message: wrongMsg as HexString, - signature: { - Ethereum: u8aToHex(evmSignature), - }, - }, - }, - }; - const encodedVerifyIdentityValidation = context.api.createType('LitentryValidationData', evmValidationData); - const requestIdentifier = `0x${randomBytes(32).toString('hex')}`; - - const linkIdentityCall = await createSignedTrustedCallLinkIdentity( - context.api, - context.mrEnclave, - context.api.createType('Index', evmNonce), - context.web3Wallets.substrate.Alice, - aliceSubstrateIdentity, - evmIdentity.toHex(), - encodedVerifyIdentityValidation.toHex(), - evmNetworks.toHex(), - context.api.createType('Option', aesKey).toHex(), - requestIdentifier - ); - const res = await sendRequestFromTrustedCall(context, teeShieldingKey, linkIdentityCall); - - assert.isTrue(res.do_watch.isFalse); - assert.isTrue(res.status.asTrustedOperationStatus[0].isInvalid); - assertWorkerError( - context, - (v) => { - assert.isTrue(v.isLinkIdentityFailed, `expected LinkIdentityFailed, received ${v.type} instead`); - assert.isTrue( - v.asLinkIdentityFailed.isUnexpectedMessage, - `expected UnexpectedMessage, received ${v.asLinkIdentityFailed.type} instead` - ); - }, - res - ); - }); - - step('linking already linked identity', async function () { - const twitterNonce = aliceCurrentNonce++; - - const twitterIdentity = await buildIdentityHelper('mock_user', 'Twitter', context); - const twitterValidation = await buildWeb2Validation({ - identityType: 'Twitter', - context, - signerIdentitity: aliceSubstrateIdentity, - linkIdentity: twitterIdentity, - verificationType: 'PublicTweet', - validationNonce: twitterNonce, - }); - const twitterNetworks = context.api.createType('Vec', []); - - const requestIdentifier = `0x${randomBytes(32).toString('hex')}`; - const linkIdentityCall = await createSignedTrustedCallLinkIdentity( - context.api, - context.mrEnclave, - context.api.createType('Index', twitterNonce), - context.web3Wallets.substrate.Alice, - aliceSubstrateIdentity, - twitterIdentity.toHex(), - twitterValidation.toHex(), - twitterNetworks.toHex(), - context.api.createType('Option', aesKey).toHex(), - requestIdentifier - ); - const res = await sendRequestFromTrustedCall(context, teeShieldingKey, linkIdentityCall); - - assert.isTrue(res.do_watch.isFalse); - assert.isTrue(res.status.asTrustedOperationStatus[0].isInvalid); - assertWorkerError( - context, - (v) => { - assert.isTrue(v.isLinkIdentityFailed, `expected LinkIdentityFailed, received ${v.type} instead`); - assert.isTrue( - v.asLinkIdentityFailed.isStfError, - `expected StfError, received ${v.asLinkIdentityFailed.type} instead` - ); - assert.equal(u8aToString(v.asLinkIdentityFailed.asStfError), 'IdentityAlreadyLinked'); - }, - res - ); - }); - - step('deactivating linked identities', async function () { - const deactivateIdentityRequestParams: { - nonce: number; - identity: CorePrimitivesIdentity; - }[] = []; - - const twitterNonce = aliceCurrentNonce++; - const twitterIdentity = await buildIdentityHelper('mock_user', 'Twitter', context); - - deactivateIdentityRequestParams.push({ - nonce: twitterNonce, - identity: twitterIdentity, - }); - - const evmNonce = aliceCurrentNonce++; - const evmIdentity = await context.web3Wallets.evm.Alice.getIdentity(context); - - deactivateIdentityRequestParams.push({ - nonce: evmNonce, - identity: evmIdentity, - }); - - const eveSubstrateNonce = aliceCurrentNonce++; - const eveSubstrateIdentity = await context.web3Wallets.substrate.Eve.getIdentity(context); - - deactivateIdentityRequestParams.push({ - nonce: eveSubstrateNonce, - identity: eveSubstrateIdentity, - }); - - const bitcoinNonce = aliceCurrentNonce++; - - const bitcoinIdentity = await context.web3Wallets.bitcoin.Alice.getIdentity(context); - - deactivateIdentityRequestParams.push({ - nonce: bitcoinNonce, - identity: bitcoinIdentity, - }); - - const idGraphHashResults: HexString[] = []; - let expectedIdGraphs: [CorePrimitivesIdentity, boolean][][] = [ - [[twitterIdentity, false]], - [[evmIdentity, false]], - [[eveSubstrateIdentity, false]], - [[bitcoinIdentity, false]], - ]; - - for (const { nonce, identity } of deactivateIdentityRequestParams) { - const requestIdentifier = `0x${randomBytes(32).toString('hex')}`; - const deactivateIdentityCall = await createSignedTrustedCallDeactivateIdentity( - context.api, - context.mrEnclave, - context.api.createType('Index', nonce), - context.web3Wallets.substrate.Alice, - aliceSubstrateIdentity, - identity.toHex(), - context.api.createType('Option', aesKey).toHex(), - requestIdentifier - ); - - const res = await sendRequestFromTrustedCall(context, teeShieldingKey, deactivateIdentityCall); - idGraphHashResults.push( - await assertIdGraphMutationResult( - context, - teeShieldingKey, - aliceSubstrateIdentity, - res, - 'DeactivateIdentityResult', - expectedIdGraphs[0] - ) - ); - expectedIdGraphs = expectedIdGraphs.slice(1, expectedIdGraphs.length); - await assertIsInSidechainBlock('deactivateIdentityCall', res); - } - assert.lengthOf(idGraphHashResults, 4); - }); - - step('check idgraph from sidechain storage after deactivating', async function () { - const idGraphGetter = await createSignedTrustedGetterIdGraph( - context.api, - context.web3Wallets.substrate.Alice, - aliceSubstrateIdentity - ); - const res = await sendRsaRequestFromGetter(context, teeShieldingKey, idGraphGetter); - const idGraph = decodeIdGraph(context.sidechainRegistry, res.value); - - for (const { identity } of linkIdentityRequestParams) { - const identityDump = JSON.stringify(identity.toHuman(), null, 4); - console.debug(`checking identity: ${identityDump}`); - const idGraphNode = idGraph.find(([idGraphNodeIdentity]) => idGraphNodeIdentity.eq(identity)); - assert.isDefined(idGraphNode, `identity not found in idGraph: ${identityDump}`); - const [, idGraphNodeContext] = idGraphNode!; - - assert.equal( - idGraphNodeContext.status.toString(), - 'Inactive', - `status should be Inactive for identity: ${identityDump}` - ); - console.debug('inactive ✅'); - } - - await assertIdGraphHash(context, teeShieldingKey, aliceSubstrateIdentity, idGraph); - }); - step('activating linked identities', async function () { - const activateIdentityRequestParams: { - nonce: number; - identity: CorePrimitivesIdentity; - }[] = []; - - const twitterNonce = aliceCurrentNonce++; - const twitterIdentity = await buildIdentityHelper('mock_user', 'Twitter', context); - - activateIdentityRequestParams.push({ - nonce: twitterNonce, - identity: twitterIdentity, - }); - - const evmNonce = aliceCurrentNonce++; - const evmIdentity = await context.web3Wallets.evm.Alice.getIdentity(context); - - activateIdentityRequestParams.push({ - nonce: evmNonce, - identity: evmIdentity, - }); - - const eveSubstrateNonce = aliceCurrentNonce++; - const eveSubstrateIdentity = await context.web3Wallets.substrate.Eve.getIdentity(context); - - activateIdentityRequestParams.push({ - nonce: eveSubstrateNonce, - identity: eveSubstrateIdentity, - }); - - const bitcoinNonce = aliceCurrentNonce++; - const bitcoinIdentity = await context.web3Wallets.bitcoin.Alice.getIdentity(context); - activateIdentityRequestParams.push({ - nonce: bitcoinNonce, - identity: bitcoinIdentity, - }); - - const idGraphHashResults: HexString[] = []; - let expectedIdGraphs: [CorePrimitivesIdentity, boolean][][] = [ - [[twitterIdentity, true]], - [[evmIdentity, true]], - [[eveSubstrateIdentity, true]], - [[bitcoinIdentity, true]], - ]; - - for (const { nonce, identity } of activateIdentityRequestParams) { - const requestIdentifier = `0x${randomBytes(32).toString('hex')}`; - const activateIdentityCall = await createSignedTrustedCallActivateIdentity( - context.api, - context.mrEnclave, - context.api.createType('Index', nonce), - context.web3Wallets.substrate.Alice, - aliceSubstrateIdentity, - identity.toHex(), - context.api.createType('Option', aesKey).toHex(), - requestIdentifier - ); - - const res = await sendRequestFromTrustedCall(context, teeShieldingKey, activateIdentityCall); - idGraphHashResults.push( - await assertIdGraphMutationResult( - context, - teeShieldingKey, - aliceSubstrateIdentity, - res, - 'ActivateIdentityResult', - expectedIdGraphs[0] - ) - ); - expectedIdGraphs = expectedIdGraphs.slice(1, expectedIdGraphs.length); - await assertIsInSidechainBlock('activateIdentityCall', res); - } - assert.lengthOf(idGraphHashResults, 4); - }); - - step('check idgraph from sidechain storage after activating', async function () { - const idGraphGetter = await createSignedTrustedGetterIdGraph( - context.api, - context.web3Wallets.substrate.Alice, - aliceSubstrateIdentity - ); - const res = await sendRsaRequestFromGetter(context, teeShieldingKey, idGraphGetter); - const idGraph = decodeIdGraph(context.sidechainRegistry, res.value); - - for (const { identity } of linkIdentityRequestParams) { - const identityDump = JSON.stringify(identity.toHuman(), null, 4); - console.debug(`checking identity: ${identityDump}`); - const idGraphNode = idGraph.find(([idGraphNodeIdentity]) => idGraphNodeIdentity.eq(identity)); - assert.isDefined(idGraphNode, `identity not found in idGraph: ${identityDump}`); - const [, idGraphNodeContext] = idGraphNode!; - - assert.equal( - idGraphNodeContext.status.toString(), - 'Active', - `status should be active for identity: ${identityDump}` - ); - console.debug('active ✅'); - } - - await assertIdGraphHash(context, teeShieldingKey, aliceSubstrateIdentity, idGraph); - }); - - step('check idgraph from sidechain storage before setting identity network', async function () { - const idGraphGetter = await createSignedTrustedGetterIdGraph( - context.api, - context.web3Wallets.substrate.Alice, - - aliceSubstrateIdentity - ); - const res = await sendRsaRequestFromGetter(context, teeShieldingKey, idGraphGetter); - const idGraph = decodeIdGraph(context.sidechainRegistry, res.value); - - // the third (last) identity in the IDGraph is eveSubstrateIdentity - const eveSubstrateIdentity = idGraph[3]; - const [, { web3networks }] = eveSubstrateIdentity; - const expectedWeb3Networks = ['Polkadot', 'Litentry']; - - assert.equal(web3networks.length, expectedWeb3Networks.length); - assert.equal(web3networks.indexOf('Polkadot') !== -1, true); - assert.equal(web3networks.indexOf('Litentry') !== -1, true); - }); - - step('setting identity network(alice)', async function () { - const eveSubstrateIdentity = await context.web3Wallets.substrate.Eve.getIdentity(context); - const requestIdentifier = `0x${randomBytes(32).toString('hex')}`; - const nonce = aliceCurrentNonce++; - - const idGraphHashResults: HexString[] = []; - let expectedIdGraphs: [CorePrimitivesIdentity, boolean][][] = [[[eveSubstrateIdentity, true]]]; - - // we set the network to ['Litentry', 'Kusama'] - const setIdentityNetworksCall = await createSignedTrustedCallSetIdentityNetworks( - context.api, - context.mrEnclave, - context.api.createType('Index', nonce), - context.web3Wallets.substrate.Alice, - aliceSubstrateIdentity, - eveSubstrateIdentity.toHex(), - context.api.createType('Vec', ['Litentry', 'Kusama']).toHex(), - context.api.createType('Option', aesKey).toHex(), - requestIdentifier - ); - - const res = await sendRequestFromTrustedCall(context, teeShieldingKey, setIdentityNetworksCall); - idGraphHashResults.push( - await assertIdGraphMutationResult( - context, - teeShieldingKey, - aliceSubstrateIdentity, - res, - 'ActivateIdentityResult', - expectedIdGraphs[0] - ) - ); - expectedIdGraphs = expectedIdGraphs.slice(1, expectedIdGraphs.length); - await assertIsInSidechainBlock('setIdentityNetworksCall', res); - - assert.lengthOf(idGraphHashResults, 1); - }); - - step('check idgraph from sidechain storage after setting identity network', async function () { - const expectedWeb3Networks = ['Kusama', 'Litentry']; - const idGraphGetter = await createSignedTrustedGetterIdGraph( - context.api, - context.web3Wallets.substrate.Alice, - aliceSubstrateIdentity - ); - const res = await sendRsaRequestFromGetter(context, teeShieldingKey, idGraphGetter); - const idGraph = decodeIdGraph(context.sidechainRegistry, res.value); - - assert.equal( - idGraph[3][1].web3networks.toHuman()?.toString(), - expectedWeb3Networks.toString(), - 'idGraph should be changed after setting network' - ); - - await assertIdGraphHash(context, teeShieldingKey, aliceSubstrateIdentity, idGraph); - }); - - step('setting incompatible identity network(alice)', async function () { - const eveSubstrateIdentity = await context.web3Wallets.substrate.Eve.getIdentity(context); - const requestIdentifier = `0x${randomBytes(32).toString('hex')}`; - const nonce = aliceCurrentNonce++; - - // alice address is not compatible with ethereum network - const setIdentityNetworksCall = await createSignedTrustedCallSetIdentityNetworks( - context.api, - context.mrEnclave, - context.api.createType('Index', nonce), - context.web3Wallets.substrate.Alice, - aliceSubstrateIdentity, - eveSubstrateIdentity.toHex(), - context.api.createType('Vec', ['BSC', 'Ethereum']).toHex(), - context.api.createType('Option', aesKey).toHex(), - requestIdentifier - ); - const res = await sendRequestFromTrustedCall(context, teeShieldingKey, setIdentityNetworksCall); - assertWorkerError( - context, - (v) => { - assert.isTrue(v.isDispatch, `expected Dispatch, received ${v.type} instead`); - assert.equal( - v.asDispatch.toString(), - ' error: Module(ModuleError { index: 8, error: [4, 0, 0, 0], message: Some("WrongWeb3NetworkTypes") })' - ); - }, - res - ); - console.log('setIdentityNetworks call returned', res.toHuman()); - assert.isTrue(res.status.isTrustedOperationStatus && res.status.asTrustedOperationStatus[0].isInvalid); - }); - - step('check idgraph from sidechain storage after setting incompatible identity network', async function () { - const expectedWeb3Networks = ['Kusama', 'Litentry']; - const idGraphGetter = await createSignedTrustedGetterIdGraph( - context.api, - - context.web3Wallets.substrate.Alice, - - aliceSubstrateIdentity - ); - const res = await sendRsaRequestFromGetter(context, teeShieldingKey, idGraphGetter); - const idGraph = decodeIdGraph(context.sidechainRegistry, res.value); - - assert.equal( - idGraph[3][1].web3networks.toHuman()?.toString(), - expectedWeb3Networks.toString(), - 'idGraph should not be changed after setting incompatible network' - ); - }); - - step('deactivate prime identity', async function () { - // deactivating prime identity should be possible and create the IDGraph if one doesn't exist already - const deactivateIdentityRequestParams: { - nonce: number; - identity: CorePrimitivesIdentity; - }[] = []; - - deactivateIdentityRequestParams.push({ - nonce: bobCurrentNonce++, - identity: bobSubstrateIdentity, - }); - - const idGraphHashResults: HexString[] = []; - let expectedIdGraphs: [CorePrimitivesIdentity, boolean][][] = [[[bobSubstrateIdentity, false]]]; - - for (const { nonce, identity } of deactivateIdentityRequestParams) { - const requestIdentifier = `0x${randomBytes(32).toString('hex')}`; - const deactivateIdentityCall = await createSignedTrustedCallDeactivateIdentity( - context.api, - context.mrEnclave, - context.api.createType('Index', nonce), - context.web3Wallets.substrate.Bob, - bobSubstrateIdentity, - identity.toHex(), - context.api.createType('Option', aesKey).toHex(), - requestIdentifier - ); - - const res = await sendRequestFromTrustedCall(context, teeShieldingKey, deactivateIdentityCall); - idGraphHashResults.push( - await assertIdGraphMutationResult( - context, - teeShieldingKey, - bobSubstrateIdentity, - res, - 'DeactivateIdentityResult', - expectedIdGraphs[0] - ) - ); - expectedIdGraphs = expectedIdGraphs.slice(1, expectedIdGraphs.length); - await assertIsInSidechainBlock('deactivateIdentityCall', res); - } - assert.lengthOf(idGraphHashResults, 1); - }); - - step('setting identity networks for prime identity)', async function () { - const requestIdentifier = `0x${randomBytes(32).toString('hex')}`; - - const idGraphHashResults: HexString[] = []; - let expectedIdGraphs: [CorePrimitivesIdentity, boolean][][] = [[[charlieSubstrateIdentity, true]]]; - - // we set the network to ['Litentry', 'Kusama'] - const setIdentityNetworksCall = await createSignedTrustedCallSetIdentityNetworks( - context.api, - context.mrEnclave, - context.api.createType('Index', charlieCurrentNonce++), - context.web3Wallets.substrate.Charlie, - charlieSubstrateIdentity, - charlieSubstrateIdentity.toHex(), - context.api.createType('Vec', ['Litentry', 'Kusama']).toHex(), - context.api.createType('Option', aesKey).toHex(), - requestIdentifier - ); - - const res = await sendRequestFromTrustedCall(context, teeShieldingKey, setIdentityNetworksCall); - idGraphHashResults.push( - await assertIdGraphMutationResult( - context, - teeShieldingKey, - charlieSubstrateIdentity, - res, - 'ActivateIdentityResult', - expectedIdGraphs[0] - ) - ); - expectedIdGraphs = expectedIdGraphs.slice(1, expectedIdGraphs.length); - await assertIsInSidechainBlock('setIdentityNetworksCall', res); - assert.lengthOf(idGraphHashResults, 1); - }); - - step('linking invalid identity with different identities', async function () { - let currentNonce = (await getSidechainNonce(context, bobSubstrateIdentity)).toNumber(); - const getNextNonce = () => currentNonce++; - const twitterIdentity = await buildIdentityHelper('mock_user', 'Twitter', context); - const twitterNonce = getNextNonce(); - const aliceEvmNonce = getNextNonce(); - const aliceEvmIdentity = await context.web3Wallets.evm.Alice.getIdentity(context); - const aliceEvmValidation = await buildValidations( - context, - bobSubstrateIdentity, - aliceEvmIdentity, - aliceEvmNonce, - 'ethereum', - context.web3Wallets.evm.Bob - ); - - const evmNetworks = context.api.createType('Vec', ['Ethereum', 'Bsc']); - const requestIdentifier = `0x${randomBytes(32).toString('hex')}`; - - const linkIdentityCall = await createSignedTrustedCall( - context.api, - [ - 'link_identity', - '(LitentryIdentity, LitentryIdentity, LitentryIdentity, LitentryValidationData, Vec, Option, H256)', - ], - context.web3Wallets.substrate.Bob, - context.mrEnclave, - - context.api.createType('Index', twitterNonce), - - [ - bobSubstrateIdentity.toHuman(), - aliceEvmIdentity.toHuman(), - twitterIdentity, - aliceEvmValidation, - evmNetworks, - aesKey, - requestIdentifier, - ] - ); - - const res = await sendRequestFromTrustedCall(context, teeShieldingKey, linkIdentityCall); - - assert.isTrue(res.do_watch.isFalse); - assert.isTrue(res.status.asTrustedOperationStatus[0].isInvalid); - console.log('linkInvalidIdentity call returned', res.toHuman()); - - assertWorkerError( - context, - (v) => { - assert.isTrue(v.isLinkIdentityFailed, `expected LinkIdentityFailed, received ${v.type} instead`); - }, - res - ); - }); - step('check sidechain nonce', async function () { - await sleep(20); - const aliceNonce = await getSidechainNonce(context, aliceSubstrateIdentity); - assert.equal(aliceNonce.toNumber(), aliceCurrentNonce); - }); -}); diff --git a/tee-worker/identity/ts-tests/integration-tests/discord_identity.test.ts b/tee-worker/identity/ts-tests/integration-tests/discord_identity.test.ts deleted file mode 100644 index 6ec729d4f2..0000000000 --- a/tee-worker/identity/ts-tests/integration-tests/discord_identity.test.ts +++ /dev/null @@ -1,289 +0,0 @@ -import { randomBytes, KeyObject } from 'crypto'; -import { step } from 'mocha-steps'; -import { assert } from 'chai'; -import { - assertIdGraphMutationResult, - assertIdGraphHash, - buildIdentityHelper, - initIntegrationTestContext, - buildWeb2Validation, -} from './common/utils'; -import { assertIsInSidechainBlock } from './common/utils/assertion'; -import { - createSignedTrustedCallLinkIdentity, - createSignedTrustedGetterIdGraph, - decodeIdGraph, - getSidechainNonce, - getTeeShieldingKey, - sendRsaRequestFromGetter, - sendRequestFromTrustedCall, -} from './common/di-utils'; // @fixme move to a better place -import { sleep } from './common/utils'; -import { aesKey } from './common/call'; -import type { IntegrationTestContext } from './common/common-types'; -import type { LitentryValidationData, Web3Network, CorePrimitivesIdentity } from 'parachain-api'; -import type { Vec, Bytes } from '@polkadot/types'; -import type { HexString } from '@polkadot/util/types'; - -describe('Test Discord Identity (direct invocation)', function () { - let context: IntegrationTestContext; - let teeShieldingKey: KeyObject; - let aliceSubstrateIdentity: CorePrimitivesIdentity; - let bobSubstrateIdentity: CorePrimitivesIdentity; - let aliceCurrentNonce = 0; - let bobCurrentNonce = 0; - - const aliceLinkIdentityRequestParams: { - nonce: number; - identity: CorePrimitivesIdentity; - validation: LitentryValidationData; - networks: Bytes | Vec; - }[] = []; - - const bobLinkIdentityRequestParams: { - nonce: number; - identity: CorePrimitivesIdentity; - validation: LitentryValidationData; - networks: Bytes | Vec; - }[] = []; - - this.timeout(6000000); - - before(async () => { - context = await initIntegrationTestContext( - process.env.PARACHAIN_ENDPOINT! // @fixme evil assertion; centralize env access - ); - teeShieldingKey = await getTeeShieldingKey(context); - - aliceSubstrateIdentity = await context.web3Wallets.substrate.Alice.getIdentity(context); - bobSubstrateIdentity = await context.web3Wallets.substrate.Bob.getIdentity(context); - - aliceCurrentNonce = (await getSidechainNonce(context, aliceSubstrateIdentity)).toNumber(); - bobCurrentNonce = (await getSidechainNonce(context, bobSubstrateIdentity)).toNumber(); - }); - - step('check alice idgraph from sidechain storage before linking', async function () { - const idGraphGetter = await createSignedTrustedGetterIdGraph( - context.api, - context.web3Wallets.substrate.Alice, - aliceSubstrateIdentity - ); - const res = await sendRsaRequestFromGetter(context, teeShieldingKey, idGraphGetter); - const idGraph = decodeIdGraph(context.sidechainRegistry, res.value); - - assert.lengthOf(idGraph, 0); - }); - - step('check bob idgraph from sidechain storage before linking', async function () { - const idGraphGetter = await createSignedTrustedGetterIdGraph( - context.api, - context.web3Wallets.substrate.Bob, - bobSubstrateIdentity - ); - const res = await sendRsaRequestFromGetter(context, teeShieldingKey, idGraphGetter); - const idGraph = decodeIdGraph(context.sidechainRegistry, res.value); - - assert.lengthOf(idGraph, 0); - }); - - step('linking discord identity with public message verification (alice)', async function () { - const nonce = aliceCurrentNonce++; - const discordIdentity = await buildIdentityHelper('alice', 'Discord', context); - const discordValidation = await buildWeb2Validation({ - identityType: 'Discord', - context, - signerIdentitity: aliceSubstrateIdentity, - linkIdentity: discordIdentity, - verificationType: 'PublicMessage', - validationNonce: nonce, - }); - const networks = context.api.createType('Vec', []); - - aliceLinkIdentityRequestParams.push({ - nonce, - identity: discordIdentity, - validation: discordValidation, - networks, - }); - - const idGraphHashResults: HexString[] = []; - let expectedIdGraphs: [CorePrimitivesIdentity, boolean][][] = [ - [ - [aliceSubstrateIdentity, true], - [discordIdentity, true], - ], - ]; - - for (const { nonce, identity, validation, networks } of aliceLinkIdentityRequestParams) { - const requestIdentifier = `0x${randomBytes(32).toString('hex')}`; - const linkIdentityCall = await createSignedTrustedCallLinkIdentity( - context.api, - context.mrEnclave, - context.api.createType('Index', nonce), - context.web3Wallets.substrate.Alice, - aliceSubstrateIdentity, - identity.toHex(), - validation.toHex(), - networks.toHex(), - context.api.createType('Option', aesKey).toHex(), - requestIdentifier, - { - withWrappedBytes: false, - withPrefix: false, - } - ); - const res = await sendRequestFromTrustedCall(context, teeShieldingKey, linkIdentityCall); - - idGraphHashResults.push( - await assertIdGraphMutationResult( - context, - teeShieldingKey, - aliceSubstrateIdentity, - res, - 'LinkIdentityResult', - expectedIdGraphs[0] - ) - ); - expectedIdGraphs = expectedIdGraphs.slice(1, expectedIdGraphs.length); - - await assertIsInSidechainBlock('linkIdentityCall', res); - } - assert.lengthOf(idGraphHashResults, 1); - }); - - step('linking discord identity with oauth2 verification (bob)', async function () { - const nonce = bobCurrentNonce++; - const discordIdentity = await buildIdentityHelper('bob', 'Discord', context); - const discordValidation = await buildWeb2Validation({ - identityType: 'Discord', - context, - signerIdentitity: bobSubstrateIdentity, - linkIdentity: discordIdentity, - validationNonce: nonce, - verificationType: 'OAuth2', - }); - const networks = context.api.createType('Vec', []); - - bobLinkIdentityRequestParams.push({ - nonce, - identity: discordIdentity, - validation: discordValidation, - networks, - }); - - const idGraphHashResults: HexString[] = []; - let expectedIdGraphs: [CorePrimitivesIdentity, boolean][][] = [ - [ - [bobSubstrateIdentity, true], - [discordIdentity, true], - ], - ]; - - for (const { nonce, identity, validation, networks } of bobLinkIdentityRequestParams) { - const requestIdentifier = `0x${randomBytes(32).toString('hex')}`; - const linkIdentityCall = await createSignedTrustedCallLinkIdentity( - context.api, - context.mrEnclave, - context.api.createType('Index', nonce), - context.web3Wallets.substrate.Bob, - bobSubstrateIdentity, - identity.toHex(), - validation.toHex(), - networks.toHex(), - context.api.createType('Option', aesKey).toHex(), - requestIdentifier, - { - withWrappedBytes: false, - withPrefix: true, - } - ); - - const res = await sendRequestFromTrustedCall(context, teeShieldingKey, linkIdentityCall); - - idGraphHashResults.push( - await assertIdGraphMutationResult( - context, - teeShieldingKey, - bobSubstrateIdentity, - res, - 'LinkIdentityResult', - expectedIdGraphs[0] - ) - ); - expectedIdGraphs = expectedIdGraphs.slice(1, expectedIdGraphs.length); - - await assertIsInSidechainBlock('linkIdentityCall', res); - } - assert.lengthOf(idGraphHashResults, 1); - }); - - step('check users sidechain storage after linking (alice)', async function () { - const idGraphGetter = await createSignedTrustedGetterIdGraph( - context.api, - context.web3Wallets.substrate.Alice, - aliceSubstrateIdentity - ); - const res = await sendRsaRequestFromGetter(context, teeShieldingKey, idGraphGetter); - const idGraph = decodeIdGraph(context.sidechainRegistry, res.value); - - for (const { identity } of aliceLinkIdentityRequestParams) { - const identityDump = JSON.stringify(identity.toHuman(), null, 4); - console.debug(`checking identity: ${identityDump}`); - const idGraphNode = idGraph.find(([idGraphNodeIdentity]) => idGraphNodeIdentity.eq(identity)); - assert.isDefined(idGraphNode, `identity not found in idGraph: ${identityDump}`); - const [, idGraphNodeContext] = idGraphNode!; - - const web3networks = idGraphNode![1].web3networks.toHuman(); - assert.deepEqual(web3networks, []); - - assert.equal( - idGraphNodeContext.status.toString(), - 'Active', - `status should be active for identity: ${identityDump}` - ); - console.debug('active ✅'); - } - - await assertIdGraphHash(context, teeShieldingKey, aliceSubstrateIdentity, idGraph); - }); - - step('check users sidechain storage after linking (bob)', async function () { - const idGraphGetter = await createSignedTrustedGetterIdGraph( - context.api, - context.web3Wallets.substrate.Bob, - bobSubstrateIdentity - ); - const res = await sendRsaRequestFromGetter(context, teeShieldingKey, idGraphGetter); - const idGraph = decodeIdGraph(context.sidechainRegistry, res.value); - - for (const { identity } of bobLinkIdentityRequestParams) { - const identityDump = JSON.stringify(identity.toHuman(), null, 4); - console.debug(`checking identity: ${identityDump}`); - const idGraphNode = idGraph.find(([idGraphNodeIdentity]) => idGraphNodeIdentity.eq(identity)); - assert.isDefined(idGraphNode, `identity not found in idGraph: ${identityDump}`); - const [, idGraphNodeContext] = idGraphNode!; - - const web3networks = idGraphNode![1].web3networks.toHuman(); - assert.deepEqual(web3networks, []); - - assert.equal( - idGraphNodeContext.status.toString(), - 'Active', - `status should be active for identity: ${identityDump}` - ); - console.debug('active ✅'); - } - - await assertIdGraphHash(context, teeShieldingKey, bobSubstrateIdentity, idGraph); - }); - - step('check sidechain nonce', async function () { - await sleep(20); - - const aliceNonce = await getSidechainNonce(context, aliceSubstrateIdentity); - assert.equal(aliceNonce.toNumber(), aliceCurrentNonce); - - const bobNonce = await getSidechainNonce(context, bobSubstrateIdentity); - assert.equal(bobNonce.toNumber(), bobCurrentNonce); - }); -}); diff --git a/tee-worker/identity/ts-tests/integration-tests/dr_vc.test.ts b/tee-worker/identity/ts-tests/integration-tests/dr_vc.test.ts index a8d469eb69..ce94486c24 100644 --- a/tee-worker/identity/ts-tests/integration-tests/dr_vc.test.ts +++ b/tee-worker/identity/ts-tests/integration-tests/dr_vc.test.ts @@ -77,7 +77,7 @@ describe('Test Vc (direct request)', function () { aliceSubstrateIdentity, evmIdentity, evmNonce, - 'ethereum', + 'evm', context.web3Wallets.evm.Alice ); const evmNetworks = context.api.createType('Vec', ['Ethereum', 'Bsc']); diff --git a/tee-worker/identity/ts-tests/integration-tests/twitter_identity.test.ts b/tee-worker/identity/ts-tests/integration-tests/twitter_identity.test.ts deleted file mode 100644 index 649c01300d..0000000000 --- a/tee-worker/identity/ts-tests/integration-tests/twitter_identity.test.ts +++ /dev/null @@ -1,304 +0,0 @@ -import { randomBytes, KeyObject } from 'crypto'; -import { step } from 'mocha-steps'; -import { assert } from 'chai'; -import { - assertIdGraphMutationResult, - assertIdGraphHash, - buildIdentityHelper, - initIntegrationTestContext, - buildWeb2Validation, -} from './common/utils'; -import { assertIsInSidechainBlock } from './common/utils/assertion'; -import { - createSignedTrustedCallLinkIdentity, - createSignedTrustedGetterIdGraph, - decodeIdGraph, - getSidechainNonce, - getTeeShieldingKey, - sendRsaRequestFromGetter, - sendRequestFromTrustedCall, - sendAesRequestFromGetter, -} from './common/di-utils'; // @fixme move to a better place -import { sleep } from './common/utils'; -import { aesKey, sendRequest, decodeRpcBytesAsString } from './common/call'; -import { createJsonRpcRequest, nextRequestId } from './common/helpers'; -import type { IntegrationTestContext } from './common/common-types'; -import type { LitentryValidationData, Web3Network, CorePrimitivesIdentity } from 'parachain-api'; -import type { Vec, Bytes } from '@polkadot/types'; -import type { HexString } from '@polkadot/util/types'; -import { hexToU8a } from '@polkadot/util'; - -describe('Test Twitter Identity (direct invocation)', function () { - let context: IntegrationTestContext; - let teeShieldingKey: KeyObject; - let aliceSubstrateIdentity: CorePrimitivesIdentity; - let bobSubstrateIdentity: CorePrimitivesIdentity; - let aliceCurrentNonce = 0; - let bobCurrentNonce = 0; - - const aliceLinkIdentityRequestParams: { - nonce: number; - identity: CorePrimitivesIdentity; - validation: LitentryValidationData; - networks: Bytes | Vec; - }[] = []; - - const bobLinkIdentityRequestParams: { - nonce: number; - identity: CorePrimitivesIdentity; - validation: LitentryValidationData; - networks: Bytes | Vec; - }[] = []; - - this.timeout(6000000); - - before(async () => { - context = await initIntegrationTestContext( - process.env.PARACHAIN_ENDPOINT! // @fixme evil assertion; centralize env access - ); - teeShieldingKey = await getTeeShieldingKey(context); - - aliceSubstrateIdentity = await context.web3Wallets.substrate.Alice.getIdentity(context); - bobSubstrateIdentity = await context.web3Wallets.substrate.Bob.getIdentity(context); - - aliceCurrentNonce = (await getSidechainNonce(context, aliceSubstrateIdentity)).toNumber(); - bobCurrentNonce = (await getSidechainNonce(context, bobSubstrateIdentity)).toNumber(); - }); - - step('check alice idgraph from sidechain storage before linking', async function () { - const idGraphGetter = await createSignedTrustedGetterIdGraph( - context.api, - context.web3Wallets.substrate.Alice, - aliceSubstrateIdentity - ); - const res = await sendAesRequestFromGetter(context, teeShieldingKey, hexToU8a(aesKey), idGraphGetter); - const idGraph = decodeIdGraph(context.sidechainRegistry, res.value); - - assert.lengthOf(idGraph, 0); - }); - - step('check bob idgraph from sidechain storage before linking', async function () { - const idGraphGetter = await createSignedTrustedGetterIdGraph( - context.api, - context.web3Wallets.substrate.Bob, - bobSubstrateIdentity - ); - const res = await sendRsaRequestFromGetter(context, teeShieldingKey, idGraphGetter); - const idGraph = decodeIdGraph(context.sidechainRegistry, res.value); - - assert.lengthOf(idGraph, 0); - }); - - step('linking twitter identity with public tweet verification (alice)', async function () { - const nonce = aliceCurrentNonce++; - const twitterIdentity = await buildIdentityHelper('mock_user', 'Twitter', context); - const twitterValidation = await buildWeb2Validation({ - identityType: 'Twitter', - context, - signerIdentitity: aliceSubstrateIdentity, - linkIdentity: twitterIdentity, - verificationType: 'PublicTweet', - validationNonce: nonce, - }); - const twitterNetworks = context.api.createType('Vec', []); - - aliceLinkIdentityRequestParams.push({ - nonce, - identity: twitterIdentity, - validation: twitterValidation, - networks: twitterNetworks, - }); - - const idGraphHashResults: HexString[] = []; - let expectedIdGraphs: [CorePrimitivesIdentity, boolean][][] = [ - [ - [aliceSubstrateIdentity, true], - [twitterIdentity, true], - ], - ]; - - for (const { nonce, identity, validation, networks } of aliceLinkIdentityRequestParams) { - const requestIdentifier = `0x${randomBytes(32).toString('hex')}`; - const linkIdentityCall = await createSignedTrustedCallLinkIdentity( - context.api, - context.mrEnclave, - context.api.createType('Index', nonce), - context.web3Wallets.substrate.Alice, - aliceSubstrateIdentity, - identity.toHex(), - validation.toHex(), - networks.toHex(), - context.api.createType('Option', aesKey).toHex(), - requestIdentifier, - { - withWrappedBytes: false, - withPrefix: false, - } - ); - const res = await sendRequestFromTrustedCall(context, teeShieldingKey, linkIdentityCall); - - idGraphHashResults.push( - await assertIdGraphMutationResult( - context, - teeShieldingKey, - aliceSubstrateIdentity, - res, - 'LinkIdentityResult', - expectedIdGraphs[0] - ) - ); - expectedIdGraphs = expectedIdGraphs.slice(1, expectedIdGraphs.length); - - await assertIsInSidechainBlock('linkIdentityCall', res); - } - assert.lengthOf(idGraphHashResults, 1); - }); - - step('linking twitter identity with oauth2 verification (bob)', async function () { - // Generate oauth code verifier on the enclave for the user - const did = 'did:litentry:substrate:0x8eaf04151687736326c9fea17e25fc5287613693c912909cb226aa4794f26a48'; - const request = createJsonRpcRequest( - 'identity_getTwitterAuthorizeUrl', - [did, 'http://127.0.0.1:3000/callback'], - nextRequestId(context) - ); - const response = await sendRequest(context.tee, request, context.api); - const authorizeUrl = decodeRpcBytesAsString(response.value); - const state = authorizeUrl.split('state=')[1].split('&')[0]; - - const nonce = bobCurrentNonce++; - const twitterIdentity = await buildIdentityHelper('mock_user_me', 'Twitter', context); - const twitterValidation = await buildWeb2Validation({ - identityType: 'Twitter', - context, - signerIdentitity: bobSubstrateIdentity, - linkIdentity: twitterIdentity, - validationNonce: nonce, - verificationType: 'OAuth2', - oauthState: state, - }); - const twitterNetworks = context.api.createType('Vec', []); - - bobLinkIdentityRequestParams.push({ - nonce, - identity: twitterIdentity, - validation: twitterValidation, - networks: twitterNetworks, - }); - - const idGraphHashResults: HexString[] = []; - let expectedIdGraphs: [CorePrimitivesIdentity, boolean][][] = [ - [ - [bobSubstrateIdentity, true], - [twitterIdentity, true], - ], - ]; - - for (const { nonce, identity, validation, networks } of bobLinkIdentityRequestParams) { - const requestIdentifier = `0x${randomBytes(32).toString('hex')}`; - const linkIdentityCall = await createSignedTrustedCallLinkIdentity( - context.api, - context.mrEnclave, - context.api.createType('Index', nonce), - context.web3Wallets.substrate.Bob, - bobSubstrateIdentity, - identity.toHex(), - validation.toHex(), - networks.toHex(), - context.api.createType('Option', aesKey).toHex(), - requestIdentifier, - { - withWrappedBytes: false, - withPrefix: true, - } - ); - - const res = await sendRequestFromTrustedCall(context, teeShieldingKey, linkIdentityCall); - - idGraphHashResults.push( - await assertIdGraphMutationResult( - context, - teeShieldingKey, - bobSubstrateIdentity, - res, - 'LinkIdentityResult', - expectedIdGraphs[0] - ) - ); - expectedIdGraphs = expectedIdGraphs.slice(1, expectedIdGraphs.length); - - await assertIsInSidechainBlock('linkIdentityCall', res); - } - assert.lengthOf(idGraphHashResults, 1); - }); - - step('check users sidechain storage after linking (alice)', async function () { - const idGraphGetter = await createSignedTrustedGetterIdGraph( - context.api, - context.web3Wallets.substrate.Alice, - aliceSubstrateIdentity - ); - const res = await sendRsaRequestFromGetter(context, teeShieldingKey, idGraphGetter); - const idGraph = decodeIdGraph(context.sidechainRegistry, res.value); - - for (const { identity } of aliceLinkIdentityRequestParams) { - const identityDump = JSON.stringify(identity.toHuman(), null, 4); - console.debug(`checking identity: ${identityDump}`); - const idGraphNode = idGraph.find(([idGraphNodeIdentity]) => idGraphNodeIdentity.eq(identity)); - assert.isDefined(idGraphNode, `identity not found in idGraph: ${identityDump}`); - const [, idGraphNodeContext] = idGraphNode!; - - const web3networks = idGraphNode![1].web3networks.toHuman(); - assert.deepEqual(web3networks, []); - - assert.equal( - idGraphNodeContext.status.toString(), - 'Active', - `status should be active for identity: ${identityDump}` - ); - console.debug('active ✅'); - } - - await assertIdGraphHash(context, teeShieldingKey, aliceSubstrateIdentity, idGraph); - }); - - step('check users sidechain storage after linking (bob)', async function () { - const idGraphGetter = await createSignedTrustedGetterIdGraph( - context.api, - context.web3Wallets.substrate.Bob, - bobSubstrateIdentity - ); - const res = await sendAesRequestFromGetter(context, teeShieldingKey, hexToU8a(aesKey), idGraphGetter); - const idGraph = decodeIdGraph(context.sidechainRegistry, res.value); - - for (const { identity } of bobLinkIdentityRequestParams) { - const identityDump = JSON.stringify(identity.toHuman(), null, 4); - console.debug(`checking identity: ${identityDump}`); - const idGraphNode = idGraph.find(([idGraphNodeIdentity]) => idGraphNodeIdentity.eq(identity)); - assert.isDefined(idGraphNode, `identity not found in idGraph: ${identityDump}`); - const [, idGraphNodeContext] = idGraphNode!; - - const web3networks = idGraphNode![1].web3networks.toHuman(); - assert.deepEqual(web3networks, []); - - assert.equal( - idGraphNodeContext.status.toString(), - 'Active', - `status should be active for identity: ${identityDump}` - ); - console.debug('active ✅'); - } - - await assertIdGraphHash(context, teeShieldingKey, bobSubstrateIdentity, idGraph); - }); - - step('check sidechain nonce', async function () { - await sleep(20); - - const aliceNonce = await getSidechainNonce(context, aliceSubstrateIdentity); - assert.equal(aliceNonce.toNumber(), aliceCurrentNonce); - - const bobNonce = await getSidechainNonce(context, bobSubstrateIdentity); - assert.equal(bobNonce.toNumber(), bobCurrentNonce); - }); -});