diff --git a/lerna.json b/lerna.json index 804d9d6a..aeee14fc 100644 --- a/lerna.json +++ b/lerna.json @@ -7,5 +7,5 @@ "publishConfig": { "directory": "build" }, - "version": "0.12.0-alpha.10" + "version": "0.12.0-alpha.13" } diff --git a/packages/node-api/package.json b/packages/node-api/package.json index c6dd6caa..c206e834 100644 --- a/packages/node-api/package.json +++ b/packages/node-api/package.json @@ -18,10 +18,10 @@ }, "sideEffects": false, "type": "module", - "version": "0.12.0-alpha.10", + "version": "0.12.0-alpha.13", "main": "index.js", "dependencies": { - "@encointer/types": "^0.12.0-alpha.10", + "@encointer/types": "^0.12.0-alpha.13", "@polkadot/api": "^10.9.1", "tslib": "^2.5.3" }, diff --git a/packages/types/package.json b/packages/types/package.json index 1f308ba5..5e43d21a 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -18,7 +18,7 @@ }, "sideEffects": false, "type": "module", - "version": "0.12.0-alpha.10", + "version": "0.12.0-alpha.13", "main": "index.js", "scripts": { "generate:defs": "node --experimental-specifier-resolution=node --loader ts-node/esm ../../node_modules/.bin/polkadot-types-from-defs --package @encointer/types/interfaces --input ./src/interfaces", diff --git a/packages/util/package.json b/packages/util/package.json index f0ea2d78..e3b28b81 100644 --- a/packages/util/package.json +++ b/packages/util/package.json @@ -20,7 +20,7 @@ "sideEffects": false, "type": "module", "types": "./index.d.ts", - "version": "0.12.0-alpha.10", + "version": "0.12.0-alpha.13", "main": "index.js", "dependencies": { "@babel/runtime": "^7.18.9", diff --git a/packages/worker-api/package.json b/packages/worker-api/package.json index fd6ef8b7..f1f38d3b 100644 --- a/packages/worker-api/package.json +++ b/packages/worker-api/package.json @@ -19,12 +19,12 @@ "sideEffects": false, "type": "module", "types": "./index.d.ts", - "version": "0.12.0-alpha.10", + "version": "0.12.0-alpha.13", "main": "index.js", "dependencies": { - "@encointer/node-api": "^0.12.0-alpha.10", - "@encointer/types": "^0.12.0-alpha.10", - "@encointer/util": "^0.12.0-alpha.10", + "@encointer/node-api": "^0.12.0-alpha.13", + "@encointer/types": "^0.12.0-alpha.13", + "@encointer/util": "^0.12.0-alpha.13", "@polkadot/api": "^10.9.1", "@polkadot/keyring": "^12.3.2", "@polkadot/types": "^10.9.1", diff --git a/packages/worker-api/src/integriteeWorker.spec.ts b/packages/worker-api/src/integriteeWorker.spec.ts index a8019fa9..bc62d19f 100644 --- a/packages/worker-api/src/integriteeWorker.spec.ts +++ b/packages/worker-api/src/integriteeWorker.spec.ts @@ -74,7 +74,7 @@ describe('worker', () => { describe('balance transfer should work', () => { it('should return value', async () => { - const shard = network.mrenclave; + const shard = network.chosenCid; const result = await worker.trustedBalanceTransfer( alice, shard, @@ -90,7 +90,7 @@ describe('worker', () => { describe('balance unshield should work', () => { it('should return value', async () => { - const shard = network.mrenclave; + const shard = network.chosenCid; const result = await worker.balanceUnshieldFunds( alice, shard, diff --git a/packages/worker-api/src/integriteeWorker.ts b/packages/worker-api/src/integriteeWorker.ts index d0b661f1..50d946ac 100644 --- a/packages/worker-api/src/integriteeWorker.ts +++ b/packages/worker-api/src/integriteeWorker.ts @@ -67,7 +67,7 @@ export class IntegriteeWorker extends Worker { async sendTrustedCall(call: IntegriteeTrustedCallSigned, shard: ShardIdentifier, options: CallOptions = {} as CallOptions): Promise { if (this.shieldingKey() == undefined) { - console.log(`Setting the shielding pubKey of the worker.`) + console.log(`[sentTrustedCall] Setting the shielding pubKey of the worker.`) await this.getShieldingKey(options); } diff --git a/packages/worker-api/src/parsers.ts b/packages/worker-api/src/parsers.ts index 3cd6a72c..cfeb177b 100644 --- a/packages/worker-api/src/parsers.ts +++ b/packages/worker-api/src/parsers.ts @@ -1,5 +1,5 @@ import { parseI64F64 } from '@encointer/util'; -import { u8aToBn, u8aToBuffer } from '@polkadot/util'; +import { u8aToBn } from '@polkadot/util'; // @ts-ignore import NodeRSA from 'node-rsa'; @@ -23,14 +23,27 @@ export function parseBalanceType(data: any): number { return parseI64F64(u8aToBn(data)); } +/** + * Parse a public key retrieved from the worker into `NodeRsa`. + * + * Note: This code is relatively sensitive: Changes here could lead + * to errors parsing and encryption errors in the browser, probably + * because of inconsistencies of node's `Buffer and the `buffer` + * polyfill in browser. + * @param data + */ export function parseNodeRSA(data: any): NodeRSA { const keyJson = JSON.parse(data); - keyJson.n = u8aToBuffer(keyJson.n).reverse(); + keyJson.n = new BN(keyJson.n, 'le'); keyJson.e = new BN(keyJson.e); const key = new NodeRSA(); setKeyOpts(key); key.importKey({ - n: keyJson.n, + // Important: use string here, not buffer, otherwise the browser will + // misinterpret the `n`. + n: keyJson.n.toString(10), + // Important: use number here, not buffer, otherwise the browser will + // misinterpret the `e`. e: keyJson.e.toNumber() }, 'components-public'); return key; diff --git a/packages/worker-api/src/sendRequest.ts b/packages/worker-api/src/sendRequest.ts index 919c9c97..533256c9 100644 --- a/packages/worker-api/src/sendRequest.ts +++ b/packages/worker-api/src/sendRequest.ts @@ -62,7 +62,7 @@ export const sendTrustedCall = async (self: IWorker, call: IntegriteeTrustedC let result: Promise; let parserType: string = options.debug ? 'raw': parser; - console.log(`TrustedCall: ${JSON.stringify(call)}`); + // console.log(`TrustedCall: ${JSON.stringify(call)}`); let top; if (direct) { @@ -83,7 +83,11 @@ export const sendTrustedCall = async (self: IWorker, call: IntegriteeTrustedC 'Request', { shard, cyphertext: cyphertext } ); - result = sendWorkerRequest(self, createJsonRpcRequest('author_submitExtrinsic', [r.toHex()], 1), parserType, options) + const rpc = createJsonRpcRequest('author_submitExtrinsic', [r.toHex()], 1); + result = sendWorkerRequest(self, rpc, parserType, options) + + console.log(`[sendTrustedCall] sent request: ${JSON.stringify(rpc)}`); + return result as Promise } diff --git a/packages/worker-api/src/testUtils/networks.ts b/packages/worker-api/src/testUtils/networks.ts index 40090eb0..67b3e4eb 100644 --- a/packages/worker-api/src/testUtils/networks.ts +++ b/packages/worker-api/src/testUtils/networks.ts @@ -40,7 +40,7 @@ export const localDockerNetwork = () => { worker: 'wss://127.0.0.1:2000', genesisHash: '0x388c446a804e24e77ae89f5bb099edb60cacc2ac7c898ce175bdaa08629c1439', mrenclave: 'HjkQuPjBn531Hkji2Dsj4CEYCGpqCc3aXqETMCM7x7z4', - chosenCid: '4Xgnkpg4RwXjFegLzYKgY6Y3jCSPmxyPmNvfs42Uvsuh', + chosenCid: 'HjkQuPjBn531Hkji2Dsj4CEYCGpqCc3aXqETMCM7x7z4', customTypes: {}, palletOverrides: {} }; @@ -54,7 +54,7 @@ export const paseoNetwork = () => { genesisHash: '', mrenclave: '7RuM6U4DLEtrTnVntDjDPBCAN4LbCGRpnmcTYUGhLqc7', // abused as shard vault - chosenCid: '5CBWPstfcW7dPYGdUG4kVDZSQq9Q9Ed65LT2Eu1inhJRoY8e', + chosenCid: '5wePd1LYa5M49ghwgZXs55cepKbJKhj5xfzQGfPeMS7c', customTypes: {}, palletOverrides: {} }; diff --git a/packages/worker-api/src/worker.ts b/packages/worker-api/src/worker.ts index ecc3891b..700886d0 100644 --- a/packages/worker-api/src/worker.ts +++ b/packages/worker-api/src/worker.ts @@ -33,7 +33,7 @@ const parseGetterResponse = (self: IWorker, responseType: string, data: string) throw new Error(`Worker error: ${data}`); } - console.log(`Getter response: ${data}`); + // console.log(`Getter response: ${data}`); const json = JSON.parse(data); const value = hexToU8a(json["result"]); @@ -70,6 +70,7 @@ const parseGetterResponse = (self: IWorker, responseType: string, data: string) parsedData = self.createType(responseType, returnValue.value); break case 'TrustedOperationResult': + console.log(`Got TrustedOperationResult`) parsedData = self.createType('Hash', returnValue.value); break default: diff --git a/yarn.lock b/yarn.lock index cfc03f94..5d49e538 100644 --- a/yarn.lock +++ b/yarn.lock @@ -755,18 +755,18 @@ __metadata: languageName: node linkType: hard -"@encointer/node-api@^0.12.0-alpha.10, @encointer/node-api@workspace:packages/node-api": +"@encointer/node-api@^0.12.0-alpha.13, @encointer/node-api@workspace:packages/node-api": version: 0.0.0-use.local resolution: "@encointer/node-api@workspace:packages/node-api" dependencies: - "@encointer/types": ^0.12.0-alpha.10 + "@encointer/types": ^0.12.0-alpha.13 "@polkadot/api": ^10.9.1 "@polkadot/util-crypto": ^12.3.2 tslib: ^2.5.3 languageName: unknown linkType: soft -"@encointer/types@^0.12.0-alpha.10, @encointer/types@workspace:packages/types": +"@encointer/types@^0.12.0-alpha.13, @encointer/types@workspace:packages/types": version: 0.0.0-use.local resolution: "@encointer/types@workspace:packages/types" dependencies: @@ -781,7 +781,7 @@ __metadata: languageName: unknown linkType: soft -"@encointer/util@^0.12.0-alpha.10, @encointer/util@workspace:packages/util": +"@encointer/util@^0.12.0-alpha.13, @encointer/util@workspace:packages/util": version: 0.0.0-use.local resolution: "@encointer/util@workspace:packages/util" dependencies: @@ -798,9 +798,9 @@ __metadata: version: 0.0.0-use.local resolution: "@encointer/worker-api@workspace:packages/worker-api" dependencies: - "@encointer/node-api": ^0.12.0-alpha.10 - "@encointer/types": ^0.12.0-alpha.10 - "@encointer/util": ^0.12.0-alpha.10 + "@encointer/node-api": ^0.12.0-alpha.13 + "@encointer/types": ^0.12.0-alpha.13 + "@encointer/util": ^0.12.0-alpha.13 "@polkadot/api": ^10.9.1 "@polkadot/keyring": ^12.3.2 "@polkadot/types": ^10.9.1