From b6ee1c4d62f5f990b457a0dd5ffe0e348f7e3f0f Mon Sep 17 00:00:00 2001 From: Christian Langenbacher Date: Wed, 1 May 2024 16:20:00 +0200 Subject: [PATCH] Revert "[worker] test all endianness in unit tests" This reverts commit c8f69f1e5efdcd5e795bb3046be922b84108501f. --- .../worker-api/src/integriteeWorker.spec.ts | 68 ++----------------- packages/worker-api/src/interface.ts | 9 +-- packages/worker-api/src/worker.ts | 14 ++-- 3 files changed, 13 insertions(+), 78 deletions(-) diff --git a/packages/worker-api/src/integriteeWorker.spec.ts b/packages/worker-api/src/integriteeWorker.spec.ts index 2de04753..2b9ca611 100644 --- a/packages/worker-api/src/integriteeWorker.spec.ts +++ b/packages/worker-api/src/integriteeWorker.spec.ts @@ -72,88 +72,32 @@ describe('worker', () => { }); }); - // describe('balance transfer should work', () => { - // it('should return value', async () => { - // const shard = network.chosenCid; - // const result = await worker.trustedBalanceTransfer( - // alice, - // shard, - // network.mrenclave, - // alice.address, - // charlie.address, - // 1100000000000 - // ); - // console.log('balance transfer result', result.toHuman()); - // expect(result).toBeDefined(); - // }); - // }); - - describe('balance unshield should work be/be', () => { + describe('balance transfer should work', () => { it('should return value', async () => { const shard = network.chosenCid; - - const result = await worker.balanceUnshieldFunds( + const result = await worker.trustedBalanceTransfer( alice, shard, network.mrenclave, alice.address, charlie.address, - 1100000000000, - {inputEndian: "be", outputEndian: "be"} + 1100000000000 ); - console.log('balance unshield result', result.toHuman()); + console.log('balance transfer result', result.toHuman()); expect(result).toBeDefined(); }); }); - describe('balance unshield should work be/le', () => { + describe('balance unshield should work', () => { it('should return value', async () => { const shard = network.chosenCid; - - const result = await worker.balanceUnshieldFunds( - alice, - shard, - network.mrenclave, - alice.address, - charlie.address, - 1100000000000, - {inputEndian: "be", outputEndian: "le"} - ); - console.log('balance unshield result', result.toHuman()); - expect(result).toBeDefined(); - }); - }); - - describe('balance unshield should work le/be', () => { - it('should return value', async () => { - const shard = network.chosenCid; - - const result = await worker.balanceUnshieldFunds( - alice, - shard, - network.mrenclave, - alice.address, - charlie.address, - 1100000000000, - {inputEndian: "le", outputEndian: "be"} - ); - console.log('balance unshield result', result.toHuman()); - expect(result).toBeDefined(); - }); - }); - - describe('balance unshield should work le/le', () => { - it('should return value', async () => { - const shard = network.chosenCid; - const result = await worker.balanceUnshieldFunds( alice, shard, network.mrenclave, alice.address, charlie.address, - 1100000000000, - {inputEndian: "le", outputEndian: "le"} + 1100000000000 ); console.log('balance unshield result', result.toHuman()); expect(result).toBeDefined(); diff --git a/packages/worker-api/src/interface.ts b/packages/worker-api/src/interface.ts index f2564d1e..c7a3f424 100644 --- a/packages/worker-api/src/interface.ts +++ b/packages/worker-api/src/interface.ts @@ -4,7 +4,6 @@ import {Keyring} from "@polkadot/keyring"; import type {u8} from "@polkadot/types-codec"; import type {TypeRegistry, Vec} from "@polkadot/types"; import type {RegistryTypes} from "@polkadot/types/types"; -import BN from "bn.js"; export interface IWorker extends WebSocketAsPromised { rsCount: number; @@ -12,7 +11,7 @@ export interface IWorker extends WebSocketAsPromised { keyring: () => Keyring | undefined; createType: (apiType: string, obj?: any) => any; open: () => Promise; - encrypt: (data: Uint8Array, inputEndian?: BN.Endianness, outputEndian?: BN.Endianness) => Promise> + encrypt: (data: Uint8Array) => Promise> registry: () => TypeRegistry } @@ -50,10 +49,8 @@ export interface PublicGetterArgs { export type RequestArgs = PublicGetterArgs | TrustedGetterArgs | { } export interface CallOptions { - timeout?: number; - debug?: boolean; - inputEndian?: BN.Endianness; - outputEndian?: BN.Endianness; + timeout: number; + debug: boolean; } export enum Request { diff --git a/packages/worker-api/src/worker.ts b/packages/worker-api/src/worker.ts index 32e1be35..126c63ae 100644 --- a/packages/worker-api/src/worker.ts +++ b/packages/worker-api/src/worker.ts @@ -18,7 +18,6 @@ import {parseBalance} from './parsers.js'; import {callGetter} from './sendRequest.js'; import {parseWebCryptoRSA, encryptWithPublicKey} from "./webCryptoRSA.js"; import type {u8} from "@polkadot/types-codec"; -import BN from "bn.js"; const unwrapWorkerResponse = (self: IWorker, data: string) => { /// Defaults to return `[]`, which is fine as `createType(api.registry, , [])` @@ -116,16 +115,11 @@ export class Worker extends WebSocketAsPromised implements IWorker { } } - public async encrypt(data: Uint8Array, inputEndian: BN.Endianness = 'le', outputEndian: BN.Endianness = 'le'): Promise> { - const dataBE = new BN(data, inputEndian); - const dataArrayBE = new Uint8Array(dataBE.toArray()); - - const cypherTextBuffer = await encryptWithPublicKey(dataArrayBE, this.shieldingKey() as CryptoKey); + public async encrypt(data: Uint8Array): Promise> { + // @ts-ignore + const cypherTextBuffer = await encryptWithPublicKey(data, this.shieldingKey() as CryptoKey); const cypherArray = new Uint8Array(cypherTextBuffer); - - const be = new BN(cypherArray, outputEndian) - const beArray = new Uint8Array(be.toArray()); - return this.createType('Vec', compactAddLength(beArray)) + return this.createType('Vec', compactAddLength(cypherArray)) } public registry(): TypeRegistry {