From 315e345911668a64ff3c493857c34aa06c728828 Mon Sep 17 00:00:00 2001 From: Peter Somogyvari Date: Wed, 3 Jul 2024 22:08:21 +0000 Subject: [PATCH] test(common): jest migration of the key-converter utility test cases 1. Also upgraded the tsx dependency to the latest version. 2. We are planning on retiring ts-node in favor of tsx and this helps with further triage of it. Signed-off-by: Peter Somogyvari --- .cspell.json | 1 + .github/workflows/ci.yaml | 2 +- .taprc | 1 - jest.config.js | 1 - package.json | 1 + packages/cactus-cmd-api-server/package.json | 2 +- .../typescript/unit/key-converter.test.ts | 670 ++++++++---------- .../package.json | 2 +- yarn.lock | 268 ++++++- 9 files changed, 549 insertions(+), 399 deletions(-) diff --git a/.cspell.json b/.cspell.json index 27eece777a..fb701615fa 100644 --- a/.cspell.json +++ b/.cspell.json @@ -166,6 +166,7 @@ "shrn", "Smonitor", "socketio", + "Somogyvari", "soroban", "Soroban", "SPDX", diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 44c1b92c2d..09280bc4ec 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -547,7 +547,7 @@ jobs: FULL_BUILD_DISABLED: true JEST_TEST_PATTERN: packages/cactus-common/src/test/typescript/(unit|integration|benchmark)/.*/*.test.ts JEST_TEST_RUNNER_DISABLED: false - TAPE_TEST_PATTERN: '--files={./packages/cactus-common/src/test/typescript/unit/key-converter.test.ts,./packages/cactus-common/src/test/typescript/unit/logging/logger.test.ts}' + TAPE_TEST_PATTERN: './packages/cactus-common/src/test/typescript/unit/logging/logger.test.ts' TAPE_TEST_RUNNER_DISABLED: false needs: build-dev runs-on: ubuntu-22.04 diff --git a/.taprc b/.taprc index 5ac6ee708c..1647e4651e 100644 --- a/.taprc +++ b/.taprc @@ -42,7 +42,6 @@ files: - ./packages/cactus-plugin-ledger-connector-xdai/src/test/typescript/integration/invoke-contract-xdai-json-object.test.ts - ./packages/cactus-plugin-ledger-connector-xdai/src/test/typescript/integration/openapi/openapi-validation.test.ts - ./packages/cactus-plugin-ledger-connector-xdai/src/test/typescript/integration/openapi/openapi-validation-no-keychain.test.ts - - ./packages/cactus-common/src/test/typescript/unit/key-converter.test.ts - ./packages/cactus-common/src/test/typescript/unit/logging/logger.test.ts - ./packages/cactus-plugin-keychain-aws-sm/src/test/typescript/integration/plugin-keychain-aws-sm.test.ts - ./packages/cactus-api-client/src/test/typescript/integration/default-consortium-provider.test.ts diff --git a/jest.config.js b/jest.config.js index e23a276a1b..e7421b591d 100644 --- a/jest.config.js +++ b/jest.config.js @@ -55,7 +55,6 @@ module.exports = { `./packages/cactus-plugin-ledger-connector-xdai/src/test/typescript/integration/invoke-contract-xdai-json-object.test.ts`, `./packages/cactus-plugin-ledger-connector-xdai/src/test/typescript/integration/openapi/openapi-validation.test.ts`, `./packages/cactus-plugin-ledger-connector-xdai/src/test/typescript/integration/openapi/openapi-validation-no-keychain.test.ts`, - `./packages/cactus-common/src/test/typescript/unit/key-converter.test.ts`, `./packages/cactus-common/src/test/typescript/unit/logging/logger.test.ts`, `./packages/cactus-plugin-keychain-aws-sm/src/test/typescript/integration/plugin-keychain-aws-sm.test.ts`, `./packages/cactus-api-client/src/test/typescript/integration/default-consortium-provider.test.ts`, diff --git a/package.json b/package.json index 3a472d7546..77a02b04f0 100644 --- a/package.json +++ b/package.json @@ -194,6 +194,7 @@ "ts-jest": "29.1.1", "ts-loader": "9.4.4", "ts-node": "10.9.1", + "tsx": "4.16.2", "typescript": "5.5.2", "web3": "4.1.1", "web3-core": "4.1.1", diff --git a/packages/cactus-cmd-api-server/package.json b/packages/cactus-cmd-api-server/package.json index 01b6d9d9b0..df0c0053e6 100644 --- a/packages/cactus-cmd-api-server/package.json +++ b/packages/cactus-cmd-api-server/package.json @@ -135,7 +135,7 @@ "grpc_tools_node_protoc_ts": "5.3.3", "http-status-codes": "2.1.4", "protobufjs": "7.2.5", - "tsx": "4.7.0" + "tsx": "4.16.2" }, "engines": { "node": ">=18", diff --git a/packages/cactus-common/src/test/typescript/unit/key-converter.test.ts b/packages/cactus-common/src/test/typescript/unit/key-converter.test.ts index 252ef81d3f..65d7595001 100644 --- a/packages/cactus-common/src/test/typescript/unit/key-converter.test.ts +++ b/packages/cactus-common/src/test/typescript/unit/key-converter.test.ts @@ -1,4 +1,4 @@ -import test, { Test } from "tape"; +import "jest-extended"; import KeyEncoder from "key-encoder"; @@ -12,420 +12,328 @@ import { KeyFormat, } from "../../../main/typescript/key-converter"; -test.skip("Test Public Raw key conversion", async (assert: Test) => { - const keyConverter = new KeyConverter(); - const keyPair = Secp256k1Keys.generateKeyPairsBuffer(); - const keyEncoder: KeyEncoder = new KeyEncoder("secp256k1"); - const hexPublic = Buffer.from(keyPair.publicKey).toString("hex"); - const pemPublic = keyEncoder.encodePublic( - Buffer.from(keyPair.publicKey).toString("hex"), - "raw", - "pem", - ); - - const convertRawPrivate = keyConverter.publicKeyAs( - keyPair.publicKey, - KeyFormat.Raw, - KeyFormat.Raw, - ); - assert.deepEquals( - keyPair.publicKey, - convertRawPrivate, - "Public Raw => Raw conversion successful", - ); - - const convertHexPublic = keyConverter.publicKeyAs( - keyPair.publicKey, - KeyFormat.Raw, - KeyFormat.Hex, - ); - assert.equals( - hexPublic, - convertHexPublic, - "Public Raw => Hex conversion successful", - ); - - const convertPemPublic = keyConverter.publicKeyAs( - keyPair.publicKey, - KeyFormat.Raw, - KeyFormat.PEM, - ); - assert.equals( - pemPublic, - convertPemPublic, - "Public Raw => PEM conversion successful", - ); - - assert.end(); -}); +describe("KeyConverter", () => { + test("Test Public Raw key conversion", async () => { + const keyConverter = new KeyConverter(); + const keyPair = Secp256k1Keys.generateKeyPairsBuffer(); + const keyEncoder: KeyEncoder = new KeyEncoder("secp256k1"); + const hexPublic = Buffer.from(keyPair.publicKey).toString("hex"); + const pemPublic = keyEncoder.encodePublic( + Buffer.from(keyPair.publicKey).toString("hex"), + "raw", + "pem", + ); -test.skip("Test Public Hex key conversion", async (assert: Test) => { - const keyConverter = new KeyConverter(); - const keyPair = Secp256k1Keys.generateKeyPairsBuffer(); - const keyEncoder: KeyEncoder = new KeyEncoder("secp256k1"); - const hexPublic = Buffer.from(keyPair.publicKey).toString("hex"); - const pemPublic = keyEncoder.encodePublic( - Buffer.from(keyPair.publicKey).toString("hex"), - "raw", - "pem", - ); - - const convertRawPublic = keyConverter.publicKeyAs( - hexPublic, - KeyFormat.Hex, - KeyFormat.Raw, - ); - assert.deepEquals( - keyPair.publicKey, - convertRawPublic, - "Public Hex => Raw conversion successful", - ); - - const convertHexPublic = keyConverter.publicKeyAs( - hexPublic, - KeyFormat.Hex, - KeyFormat.Hex, - ); - assert.deepEquals( - hexPublic, - convertHexPublic, - "Public Hex => Hex conversion successful", - ); - - const convertPemPublic = keyConverter.publicKeyAs( - hexPublic, - KeyFormat.Hex, - KeyFormat.PEM, - ); - assert.deepEquals( - pemPublic, - convertPemPublic, - "Public Hex => PEM conversion successful", - ); - - assert.end(); -}); + const convertRawPrivate = keyConverter.publicKeyAs( + keyPair.publicKey, + KeyFormat.Raw, + KeyFormat.Raw, + ); -test.skip("Test Public PEM key conversion", async (assert: Test) => { - const keyConverter = new KeyConverter(); - const keyPair = Secp256k1Keys.generateKeyPairsBuffer(); - const keyEncoder: KeyEncoder = new KeyEncoder("secp256k1"); - const hexPublic = Buffer.from(keyPair.publicKey).toString("hex"); - const pemPublic = keyEncoder.encodePublic( - Buffer.from(keyPair.publicKey).toString("hex"), - "raw", - "pem", - ); - - const convertRawPublic = keyConverter.publicKeyAs( - pemPublic, - KeyFormat.PEM, - KeyFormat.Raw, - ); - assert.deepEquals( - keyPair.publicKey, - convertRawPublic, - "Public PEM => Raw conversion successful", - ); - - const convertHexPublic = keyConverter.publicKeyAs( - pemPublic, - KeyFormat.PEM, - KeyFormat.Hex, - ); - assert.deepEquals( - hexPublic, - convertHexPublic, - "Public PEM => Hex conversion successful", - ); - - const convertPemPublic = keyConverter.publicKeyAs( - pemPublic, - KeyFormat.PEM, - KeyFormat.PEM, - ); - assert.deepEquals( - pemPublic, - convertPemPublic, - "Public PEM => PEM conversion successful", - ); - - assert.end(); -}); + // If the output came back with the wrong type, fail the test. + if (typeof convertRawPrivate === "string") { + throw new Error( + "Expected Uint8Array not a string because we passed in toFormat as KeyFormat.Raw", + ); + } -test.skip("Test Private Raw key conversion", async (assert: Test) => { - const keyConverter = new KeyConverter(); - const keyPair = Secp256k1Keys.generateKeyPairsBuffer(); - const keyEncoder: KeyEncoder = new KeyEncoder("secp256k1"); - const hexPrivate = keyPair.privateKey.toString("hex"); - const pemPrivate = keyEncoder.encodePrivate( - keyPair.privateKey.toString("hex"), - "raw", - "pem", - ); - - const convertRawPrivate = keyConverter.privateKeyAs( - keyPair.privateKey, - KeyFormat.Raw, - KeyFormat.Raw, - ); - assert.deepEquals( - keyPair.privateKey, - convertRawPrivate, - "Private Raw => Raw conversion successful", - ); - - const convertHexPrivate = keyConverter.privateKeyAs( - keyPair.privateKey, - KeyFormat.Raw, - KeyFormat.Hex, - ); - assert.equals( - hexPrivate, - convertHexPrivate, - "Private Raw => Hex conversion successful", - ); - - const convertPemPrivate = keyConverter.privateKeyAs( - keyPair.privateKey, - KeyFormat.Raw, - KeyFormat.PEM, - ); - assert.equals( - pemPrivate, - convertPemPrivate, - "Private Raw => PEM conversion successful", - ); - - assert.end(); -}); + expect(keyPair.publicKey).toEqual(convertRawPrivate); -test.skip("Test Private Hex key conversion", async (assert: Test) => { - const keyConverter = new KeyConverter(); - const keyPair = Secp256k1Keys.generateKeyPairsBuffer(); - const keyEncoder: KeyEncoder = new KeyEncoder("secp256k1"); - const hexPrivate = keyPair.privateKey.toString("hex"); - const pemPrivate = keyEncoder.encodePrivate( - keyPair.privateKey.toString("hex"), - "raw", - "pem", - ); - - const convertRawPrivate = keyConverter.privateKeyAs( - hexPrivate, - KeyFormat.Hex, - KeyFormat.Raw, - ); - assert.deepEquals( - keyPair.privateKey, - convertRawPrivate, - "Private Hex => Raw conversion successful", - ); - - const convertHexPrivate = keyConverter.privateKeyAs( - hexPrivate, - KeyFormat.Hex, - KeyFormat.Hex, - ); - assert.deepEquals( - hexPrivate, - convertHexPrivate, - "Private Hex => Hex conversion successful", - ); - - const convertPemPrivate = keyConverter.privateKeyAs( - hexPrivate, - KeyFormat.Hex, - KeyFormat.PEM, - ); - assert.deepEquals( - pemPrivate, - convertPemPrivate, - "Private Hex => PEM conversion successful", - ); - - assert.end(); -}); + const convertHexPublic = keyConverter.publicKeyAs( + keyPair.publicKey, + KeyFormat.Raw, + KeyFormat.Hex, + ); + expect(hexPublic).toEqual(convertHexPublic); -test.skip("Test Private PEM key conversion", async (assert: Test) => { - const keyConverter = new KeyConverter(); - const keyPair = Secp256k1Keys.generateKeyPairsBuffer(); - const keyEncoder: KeyEncoder = new KeyEncoder("secp256k1"); - const hexPrivate = keyPair.privateKey.toString("hex"); - const pemPrivate = keyEncoder.encodePrivate( - keyPair.privateKey.toString("hex"), - "raw", - "pem", - ); - - const convertRawPrivate = keyConverter.privateKeyAs( - pemPrivate, - KeyFormat.PEM, - KeyFormat.Raw, - ); - assert.deepEquals( - keyPair.privateKey, - convertRawPrivate, - "Private PEM => Raw conversion successful", - ); - - const convertHexPrivate = keyConverter.privateKeyAs( - pemPrivate, - KeyFormat.PEM, - KeyFormat.Hex, - ); - assert.deepEquals( - hexPrivate, - convertHexPrivate, - "Private PEM => Hex conversion successful", - ); - - const convertPemPrivate = keyConverter.privateKeyAs( - pemPrivate, - KeyFormat.PEM, - KeyFormat.PEM, - ); - assert.deepEquals( - pemPrivate, - convertPemPrivate, - "Private PEM => PEM conversion successful", - ); - - assert.end(); -}); + const convertPemPublic = keyConverter.publicKeyAs( + keyPair.publicKey, + KeyFormat.Raw, + KeyFormat.PEM, + ); -test.skip("Test invalid from key format", async (t: Test) => { - const keyConverter = new KeyConverter(); - const keyPair = Secp256k1Keys.generateKeyPairsBuffer(); + expect(pemPublic).toEqual(convertPemPublic); + }); - t.throws(() => { - keyConverter.publicKeyAs( - keyPair.publicKey, - "abc" as KeyFormat, + test("Test Public Hex key conversion", async () => { + const keyConverter = new KeyConverter(); + const keyPair = Secp256k1Keys.generateKeyPairsBuffer(); + const keyEncoder: KeyEncoder = new KeyEncoder("secp256k1"); + const hexPublic = Buffer.from(keyPair.publicKey).toString("hex"); + const pemPublic = keyEncoder.encodePublic( + Buffer.from(keyPair.publicKey).toString("hex"), + "raw", + "pem", + ); + + const convertRawPublic = keyConverter.publicKeyAs( + hexPublic, + KeyFormat.Hex, + KeyFormat.Raw, + ); + expect(keyPair.publicKey).toEqual(convertRawPublic); + + const convertHexPublic = keyConverter.publicKeyAs( + hexPublic, + KeyFormat.Hex, + KeyFormat.Hex, + ); + + expect(hexPublic).toEqual(convertHexPublic); + + const convertPemPublic = keyConverter.publicKeyAs( + hexPublic, + KeyFormat.Hex, KeyFormat.PEM, ); - }, "KeyConverter#publicKeyAs Invalid KeyFormat"); + expect(pemPublic).toEqual(convertPemPublic); + }); - t.throws(() => { - keyConverter.publicKeyAs( - keyPair.publicKey, + test("Test Public PEM key conversion", async () => { + const keyConverter = new KeyConverter(); + const keyPair = Secp256k1Keys.generateKeyPairsBuffer(); + const keyEncoder: KeyEncoder = new KeyEncoder("secp256k1"); + const hexPublic = Buffer.from(keyPair.publicKey).toString("hex"); + const pemPublic = keyEncoder.encodePublic( + Buffer.from(keyPair.publicKey).toString("hex"), + "raw", + "pem", + ); + + const convertRawPublic = keyConverter.publicKeyAs( + pemPublic, + KeyFormat.PEM, KeyFormat.Raw, - "abc" as KeyFormat, ); - }, "KeyConverter#publicKeyAs Invalid KeyFormat"); + expect(keyPair.publicKey).toEqual(convertRawPublic); - t.throws(() => { - keyConverter.privateKeyAs( - keyPair.privateKey, - "abc" as KeyFormat, + const convertHexPublic = keyConverter.publicKeyAs( + pemPublic, + KeyFormat.PEM, + KeyFormat.Hex, + ); + expect(hexPublic).toEqual(convertHexPublic); + + const convertPemPublic = keyConverter.publicKeyAs( + pemPublic, + KeyFormat.PEM, KeyFormat.PEM, ); - }, "KeyConverter#privateKeyAs Invalid KeyFormat"); + expect(pemPublic).toEqual(convertPemPublic); + }); + + test("Test Private Raw key conversion", async () => { + const keyConverter = new KeyConverter(); + const keyPair = Secp256k1Keys.generateKeyPairsBuffer(); + const keyEncoder: KeyEncoder = new KeyEncoder("secp256k1"); + const hexPrivate = keyPair.privateKey.toString("hex"); + const pemPrivate = keyEncoder.encodePrivate( + keyPair.privateKey.toString("hex"), + "raw", + "pem", + ); - t.throws(() => { - keyConverter.privateKeyAs( + const convertRawPrivate = keyConverter.privateKeyAs( keyPair.privateKey, KeyFormat.Raw, - "abc" as KeyFormat, + KeyFormat.Raw, ); - }, "KeyConverter#privateKeyAs Invalid KeyFormat"); - t.end(); -}); + expect(keyPair.privateKey).toEqual(convertRawPrivate); -test.skip("correct signatures after conversion whirlwind", async (t: Test) => { - const keyConverter = new KeyConverter(); - const keyPair = Secp256k1Keys.generateKeyPairsBuffer(); - - t.comment(`keyPair.privateKey: ${keyPair.privateKey}`); - - t.comment(`privateKey hex: ${keyPair.privateKey.toString("hex")}`); - - const privKeyPem = keyConverter.privateKeyAs( - keyPair.privateKey, - KeyFormat.Raw, - KeyFormat.PEM, - ); - t.comment(`privKeyPem: ${privKeyPem}`); - - const privKeyHex = keyConverter.privateKeyAs( - privKeyPem, - KeyFormat.PEM, - KeyFormat.Hex, - ); - t.comment(`privKeyHex: ${privKeyHex}`); - - const privKeyRaw = keyConverter.privateKeyAs( - privKeyPem, - KeyFormat.PEM, - KeyFormat.Raw, - ); - t.comment(`privKeyBuffer: ${privKeyRaw}`); - t.deepEquals(keyPair.privateKey, privKeyRaw, "privKey equals privKeyRaw"); - - const privKeyPem2 = keyConverter.privateKeyAs( - privKeyHex, - KeyFormat.Hex, - KeyFormat.PEM, - ); - t.comment(`privKeyPem2: ${privKeyPem2}`); - - const privKeyPem3 = keyConverter.privateKeyAs( - privKeyRaw, - KeyFormat.Raw, - KeyFormat.PEM, - ); - t.comment(`privKeyPem3: ${privKeyPem3}`); - - t.equal(privKeyPem, privKeyPem2, "privKeyPem equals privKeyPem2"); - t.equal(privKeyPem, privKeyPem3, "privKeyPem equals privKeyPem3"); - t.equal(privKeyPem2, privKeyPem3, "privKeyPem2 equals privKeyPem3"); - - const payload = "hello"; - - const signer1 = new JsObjectSigner({ - privateKey: keyPair.privateKey, - }); + const convertHexPrivate = keyConverter.privateKeyAs( + keyPair.privateKey, + KeyFormat.Raw, + KeyFormat.Hex, + ); + expect(hexPrivate).toEqual(convertHexPrivate); - const signer2 = new JsObjectSigner({ - privateKey: keyConverter.privateKeyAs( - privKeyPem2, - KeyFormat.PEM, + const convertPemPrivate = keyConverter.privateKeyAs( + keyPair.privateKey, KeyFormat.Raw, - ), - }); - const signer3 = new JsObjectSigner({ - privateKey: keyConverter.privateKeyAs( - privKeyPem3, KeyFormat.PEM, - KeyFormat.Raw, - ), + ); + + expect(pemPrivate).toEqual(convertPemPrivate); }); - const signer4 = new JsObjectSigner({ - privateKey: keyConverter.privateKeyAs( - privKeyHex, + + test("Test Private Hex key conversion", async () => { + const keyConverter = new KeyConverter(); + const keyPair = Secp256k1Keys.generateKeyPairsBuffer(); + const keyEncoder: KeyEncoder = new KeyEncoder("secp256k1"); + const hexPrivate = keyPair.privateKey.toString("hex"); + const pemPrivate = keyEncoder.encodePrivate( + keyPair.privateKey.toString("hex"), + "raw", + "pem", + ); + + const convertRawPrivate = keyConverter.privateKeyAs( + hexPrivate, KeyFormat.Hex, KeyFormat.Raw, - ), + ); + expect(keyPair.privateKey).toEqual(convertRawPrivate); + + const convertHexPrivate = keyConverter.privateKeyAs( + hexPrivate, + KeyFormat.Hex, + KeyFormat.Hex, + ); + expect(hexPrivate).toEqual(convertHexPrivate); + + const convertPemPrivate = keyConverter.privateKeyAs( + hexPrivate, + KeyFormat.Hex, + KeyFormat.PEM, + ); + expect(pemPrivate).toEqual(convertPemPrivate); }); - const signature1 = signer1.sign(payload); - t.comment(`Signature 1: ${signature1}`); + test("Test Private PEM key conversion", async () => { + const keyConverter = new KeyConverter(); + const keyPair = Secp256k1Keys.generateKeyPairsBuffer(); + const keyEncoder: KeyEncoder = new KeyEncoder("secp256k1"); + const hexPrivate = keyPair.privateKey.toString("hex"); + const pemPrivate = keyEncoder.encodePrivate( + keyPair.privateKey.toString("hex"), + "raw", + "pem", + ); - const signature2 = signer2.sign(payload); - t.comment(`Signature 2: ${signature2}`); + const convertRawPrivate = keyConverter.privateKeyAs( + pemPrivate, + KeyFormat.PEM, + KeyFormat.Raw, + ); + expect(keyPair.privateKey).toEqual(convertRawPrivate); - const signature3 = signer3.sign(payload); - t.comment(`Signature 3: ${signature3}`); + const convertHexPrivate = keyConverter.privateKeyAs( + pemPrivate, + KeyFormat.PEM, + KeyFormat.Hex, + ); + expect(hexPrivate).toEqual(convertHexPrivate); - const signature4 = signer4.sign(payload); - t.comment(`Signature 4: ${signature4}`); + const convertPemPrivate = keyConverter.privateKeyAs( + pemPrivate, + KeyFormat.PEM, + KeyFormat.PEM, + ); + expect(pemPrivate).toEqual(convertPemPrivate); + }); + + test("Test invalid from key format", async () => { + const keyConverter = new KeyConverter(); + const keyPair = Secp256k1Keys.generateKeyPairsBuffer(); + + expect(() => { + keyConverter.publicKeyAs( + keyPair.publicKey, + "abc" as KeyFormat, + KeyFormat.PEM, + ); + }).toThrow(); + + expect(() => { + keyConverter.publicKeyAs( + keyPair.publicKey, + KeyFormat.Raw, + "abc" as KeyFormat, + ); + }).toThrow(); + + expect(() => { + keyConverter.privateKeyAs( + keyPair.privateKey, + "abc" as KeyFormat, + KeyFormat.PEM, + ); + }).toThrow(); + + expect(() => { + keyConverter.privateKeyAs( + keyPair.privateKey, + KeyFormat.Raw, + "abc" as KeyFormat, + ); + }).toThrow(); + }); + + test("correct signatures after conversion whirlwind", async () => { + const keyConverter = new KeyConverter(); + const keyPair = Secp256k1Keys.generateKeyPairsBuffer(); - t.deepEquals(signature1, signature2, "signature1 deep equals signature2"); + const privKeyPem = keyConverter.privateKeyAs( + keyPair.privateKey, + KeyFormat.Raw, + KeyFormat.PEM, + ); + + const privKeyHex = keyConverter.privateKeyAs( + privKeyPem, + KeyFormat.PEM, + KeyFormat.Hex, + ); - t.deepEquals(signature2, signature3, "signature2 deep equals signature3"); + const privKeyRaw = keyConverter.privateKeyAs( + privKeyPem, + KeyFormat.PEM, + KeyFormat.Raw, + ); + expect(keyPair.privateKey).toEqual(privKeyRaw); - t.deepEquals(signature1, signature4, "signature1 deep equals signature4"); + const privKeyPem2 = keyConverter.privateKeyAs( + privKeyHex, + KeyFormat.Hex, + KeyFormat.PEM, + ); - t.end(); + const privKeyPem3 = keyConverter.privateKeyAs( + privKeyRaw, + KeyFormat.Raw, + KeyFormat.PEM, + ); + expect(privKeyPem).toEqual(privKeyPem2); + expect(privKeyPem).toEqual(privKeyPem3); + expect(privKeyPem2).toEqual(privKeyPem3); + + const payload = "hello"; + + const signer1 = new JsObjectSigner({ + privateKey: keyPair.privateKey, + }); + + const signer2 = new JsObjectSigner({ + privateKey: keyConverter.privateKeyAs( + privKeyPem2, + KeyFormat.PEM, + KeyFormat.Raw, + ), + }); + const signer3 = new JsObjectSigner({ + privateKey: keyConverter.privateKeyAs( + privKeyPem3, + KeyFormat.PEM, + KeyFormat.Raw, + ), + }); + const signer4 = new JsObjectSigner({ + privateKey: keyConverter.privateKeyAs( + privKeyHex, + KeyFormat.Hex, + KeyFormat.Raw, + ), + }); + + const signature1 = signer1.sign(payload); + + const signature2 = signer2.sign(payload); + const signature3 = signer3.sign(payload); + const signature4 = signer4.sign(payload); + + expect(signature1).toEqual(signature2); + expect(signature2).toEqual(signature3); + expect(signature1).toEqual(signature4); + }); }); diff --git a/packages/cactus-plugin-ledger-connector-besu/package.json b/packages/cactus-plugin-ledger-connector-besu/package.json index 09132f6386..cab60f52d4 100644 --- a/packages/cactus-plugin-ledger-connector-besu/package.json +++ b/packages/cactus-plugin-ledger-connector-besu/package.json @@ -101,7 +101,7 @@ "npm-run-all2": "6.1.2", "protobufjs": "7.2.5", "socket.io": "4.6.2", - "tsx": "4.7.0", + "tsx": "4.16.2", "uuid": "9.0.1", "web3-core": "1.6.1", "web3-eth": "1.6.1" diff --git a/yarn.lock b/yarn.lock index 1ce1009ec9..8a016b3e4d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -5597,6 +5597,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/aix-ppc64@npm:0.21.5": + version: 0.21.5 + resolution: "@esbuild/aix-ppc64@npm:0.21.5" + conditions: os=aix & cpu=ppc64 + languageName: node + linkType: hard + "@esbuild/android-arm64@npm:0.18.17": version: 0.18.17 resolution: "@esbuild/android-arm64@npm:0.18.17" @@ -5618,6 +5625,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/android-arm64@npm:0.21.5": + version: 0.21.5 + resolution: "@esbuild/android-arm64@npm:0.21.5" + conditions: os=android & cpu=arm64 + languageName: node + linkType: hard + "@esbuild/android-arm@npm:0.18.17": version: 0.18.17 resolution: "@esbuild/android-arm@npm:0.18.17" @@ -5639,6 +5653,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/android-arm@npm:0.21.5": + version: 0.21.5 + resolution: "@esbuild/android-arm@npm:0.21.5" + conditions: os=android & cpu=arm + languageName: node + linkType: hard + "@esbuild/android-x64@npm:0.18.17": version: 0.18.17 resolution: "@esbuild/android-x64@npm:0.18.17" @@ -5660,6 +5681,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/android-x64@npm:0.21.5": + version: 0.21.5 + resolution: "@esbuild/android-x64@npm:0.21.5" + conditions: os=android & cpu=x64 + languageName: node + linkType: hard + "@esbuild/darwin-arm64@npm:0.18.17": version: 0.18.17 resolution: "@esbuild/darwin-arm64@npm:0.18.17" @@ -5681,6 +5709,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/darwin-arm64@npm:0.21.5": + version: 0.21.5 + resolution: "@esbuild/darwin-arm64@npm:0.21.5" + conditions: os=darwin & cpu=arm64 + languageName: node + linkType: hard + "@esbuild/darwin-x64@npm:0.18.17": version: 0.18.17 resolution: "@esbuild/darwin-x64@npm:0.18.17" @@ -5702,6 +5737,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/darwin-x64@npm:0.21.5": + version: 0.21.5 + resolution: "@esbuild/darwin-x64@npm:0.21.5" + conditions: os=darwin & cpu=x64 + languageName: node + linkType: hard + "@esbuild/freebsd-arm64@npm:0.18.17": version: 0.18.17 resolution: "@esbuild/freebsd-arm64@npm:0.18.17" @@ -5723,6 +5765,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/freebsd-arm64@npm:0.21.5": + version: 0.21.5 + resolution: "@esbuild/freebsd-arm64@npm:0.21.5" + conditions: os=freebsd & cpu=arm64 + languageName: node + linkType: hard + "@esbuild/freebsd-x64@npm:0.18.17": version: 0.18.17 resolution: "@esbuild/freebsd-x64@npm:0.18.17" @@ -5744,6 +5793,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/freebsd-x64@npm:0.21.5": + version: 0.21.5 + resolution: "@esbuild/freebsd-x64@npm:0.21.5" + conditions: os=freebsd & cpu=x64 + languageName: node + linkType: hard + "@esbuild/linux-arm64@npm:0.18.17": version: 0.18.17 resolution: "@esbuild/linux-arm64@npm:0.18.17" @@ -5765,6 +5821,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-arm64@npm:0.21.5": + version: 0.21.5 + resolution: "@esbuild/linux-arm64@npm:0.21.5" + conditions: os=linux & cpu=arm64 + languageName: node + linkType: hard + "@esbuild/linux-arm@npm:0.18.17": version: 0.18.17 resolution: "@esbuild/linux-arm@npm:0.18.17" @@ -5786,6 +5849,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-arm@npm:0.21.5": + version: 0.21.5 + resolution: "@esbuild/linux-arm@npm:0.21.5" + conditions: os=linux & cpu=arm + languageName: node + linkType: hard + "@esbuild/linux-ia32@npm:0.18.17": version: 0.18.17 resolution: "@esbuild/linux-ia32@npm:0.18.17" @@ -5807,6 +5877,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-ia32@npm:0.21.5": + version: 0.21.5 + resolution: "@esbuild/linux-ia32@npm:0.21.5" + conditions: os=linux & cpu=ia32 + languageName: node + linkType: hard + "@esbuild/linux-loong64@npm:0.18.17": version: 0.18.17 resolution: "@esbuild/linux-loong64@npm:0.18.17" @@ -5828,6 +5905,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-loong64@npm:0.21.5": + version: 0.21.5 + resolution: "@esbuild/linux-loong64@npm:0.21.5" + conditions: os=linux & cpu=loong64 + languageName: node + linkType: hard + "@esbuild/linux-mips64el@npm:0.18.17": version: 0.18.17 resolution: "@esbuild/linux-mips64el@npm:0.18.17" @@ -5849,6 +5933,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-mips64el@npm:0.21.5": + version: 0.21.5 + resolution: "@esbuild/linux-mips64el@npm:0.21.5" + conditions: os=linux & cpu=mips64el + languageName: node + linkType: hard + "@esbuild/linux-ppc64@npm:0.18.17": version: 0.18.17 resolution: "@esbuild/linux-ppc64@npm:0.18.17" @@ -5870,6 +5961,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-ppc64@npm:0.21.5": + version: 0.21.5 + resolution: "@esbuild/linux-ppc64@npm:0.21.5" + conditions: os=linux & cpu=ppc64 + languageName: node + linkType: hard + "@esbuild/linux-riscv64@npm:0.18.17": version: 0.18.17 resolution: "@esbuild/linux-riscv64@npm:0.18.17" @@ -5891,6 +5989,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-riscv64@npm:0.21.5": + version: 0.21.5 + resolution: "@esbuild/linux-riscv64@npm:0.21.5" + conditions: os=linux & cpu=riscv64 + languageName: node + linkType: hard + "@esbuild/linux-s390x@npm:0.18.17": version: 0.18.17 resolution: "@esbuild/linux-s390x@npm:0.18.17" @@ -5912,6 +6017,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-s390x@npm:0.21.5": + version: 0.21.5 + resolution: "@esbuild/linux-s390x@npm:0.21.5" + conditions: os=linux & cpu=s390x + languageName: node + linkType: hard + "@esbuild/linux-x64@npm:0.18.17": version: 0.18.17 resolution: "@esbuild/linux-x64@npm:0.18.17" @@ -5933,6 +6045,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/linux-x64@npm:0.21.5": + version: 0.21.5 + resolution: "@esbuild/linux-x64@npm:0.21.5" + conditions: os=linux & cpu=x64 + languageName: node + linkType: hard + "@esbuild/netbsd-x64@npm:0.18.17": version: 0.18.17 resolution: "@esbuild/netbsd-x64@npm:0.18.17" @@ -5954,6 +6073,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/netbsd-x64@npm:0.21.5": + version: 0.21.5 + resolution: "@esbuild/netbsd-x64@npm:0.21.5" + conditions: os=netbsd & cpu=x64 + languageName: node + linkType: hard + "@esbuild/openbsd-x64@npm:0.18.17": version: 0.18.17 resolution: "@esbuild/openbsd-x64@npm:0.18.17" @@ -5975,6 +6101,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/openbsd-x64@npm:0.21.5": + version: 0.21.5 + resolution: "@esbuild/openbsd-x64@npm:0.21.5" + conditions: os=openbsd & cpu=x64 + languageName: node + linkType: hard + "@esbuild/sunos-x64@npm:0.18.17": version: 0.18.17 resolution: "@esbuild/sunos-x64@npm:0.18.17" @@ -5996,6 +6129,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/sunos-x64@npm:0.21.5": + version: 0.21.5 + resolution: "@esbuild/sunos-x64@npm:0.21.5" + conditions: os=sunos & cpu=x64 + languageName: node + linkType: hard + "@esbuild/win32-arm64@npm:0.18.17": version: 0.18.17 resolution: "@esbuild/win32-arm64@npm:0.18.17" @@ -6017,6 +6157,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/win32-arm64@npm:0.21.5": + version: 0.21.5 + resolution: "@esbuild/win32-arm64@npm:0.21.5" + conditions: os=win32 & cpu=arm64 + languageName: node + linkType: hard + "@esbuild/win32-ia32@npm:0.18.17": version: 0.18.17 resolution: "@esbuild/win32-ia32@npm:0.18.17" @@ -6038,6 +6185,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/win32-ia32@npm:0.21.5": + version: 0.21.5 + resolution: "@esbuild/win32-ia32@npm:0.21.5" + conditions: os=win32 & cpu=ia32 + languageName: node + linkType: hard + "@esbuild/win32-x64@npm:0.18.17": version: 0.18.17 resolution: "@esbuild/win32-x64@npm:0.18.17" @@ -6059,6 +6213,13 @@ __metadata: languageName: node linkType: hard +"@esbuild/win32-x64@npm:0.21.5": + version: 0.21.5 + resolution: "@esbuild/win32-x64@npm:0.21.5" + conditions: os=win32 & cpu=x64 + languageName: node + linkType: hard + "@eslint-community/eslint-utils@npm:^4.2.0, @eslint-community/eslint-utils@npm:^4.4.0": version: 4.4.0 resolution: "@eslint-community/eslint-utils@npm:4.4.0" @@ -7755,7 +7916,7 @@ __metadata: semver: "npm:7.5.2" socket.io: "npm:4.6.2" socket.io-client-fixed-types: "npm:4.5.4" - tsx: "npm:4.7.0" + tsx: "npm:4.16.2" typescript-optional: "npm:2.0.1" uuid: "npm:9.0.1" languageName: unknown @@ -8594,7 +8755,7 @@ __metadata: rxjs: "npm:7.8.1" socket.io: "npm:4.6.2" socket.io-client-fixed-types: "npm:4.5.4" - tsx: "npm:4.7.0" + tsx: "npm:4.16.2" typescript-optional: "npm:2.0.1" uuid: "npm:9.0.1" web3: "npm:1.6.1" @@ -9539,6 +9700,7 @@ __metadata: ts-jest: "npm:29.1.1" ts-loader: "npm:9.4.4" ts-node: "npm:10.9.1" + tsx: "npm:4.16.2" typescript: "npm:5.5.2" web3: "npm:4.1.1" web3-core: "npm:4.1.1" @@ -25217,7 +25379,7 @@ __metadata: languageName: node linkType: hard -"esbuild@npm:^0.19.3, esbuild@npm:~0.19.10": +"esbuild@npm:^0.19.3": version: 0.19.12 resolution: "esbuild@npm:0.19.12" dependencies: @@ -25297,6 +25459,86 @@ __metadata: languageName: node linkType: hard +"esbuild@npm:~0.21.5": + version: 0.21.5 + resolution: "esbuild@npm:0.21.5" + dependencies: + "@esbuild/aix-ppc64": "npm:0.21.5" + "@esbuild/android-arm": "npm:0.21.5" + "@esbuild/android-arm64": "npm:0.21.5" + "@esbuild/android-x64": "npm:0.21.5" + "@esbuild/darwin-arm64": "npm:0.21.5" + "@esbuild/darwin-x64": "npm:0.21.5" + "@esbuild/freebsd-arm64": "npm:0.21.5" + "@esbuild/freebsd-x64": "npm:0.21.5" + "@esbuild/linux-arm": "npm:0.21.5" + "@esbuild/linux-arm64": "npm:0.21.5" + "@esbuild/linux-ia32": "npm:0.21.5" + "@esbuild/linux-loong64": "npm:0.21.5" + "@esbuild/linux-mips64el": "npm:0.21.5" + "@esbuild/linux-ppc64": "npm:0.21.5" + "@esbuild/linux-riscv64": "npm:0.21.5" + "@esbuild/linux-s390x": "npm:0.21.5" + "@esbuild/linux-x64": "npm:0.21.5" + "@esbuild/netbsd-x64": "npm:0.21.5" + "@esbuild/openbsd-x64": "npm:0.21.5" + "@esbuild/sunos-x64": "npm:0.21.5" + "@esbuild/win32-arm64": "npm:0.21.5" + "@esbuild/win32-ia32": "npm:0.21.5" + "@esbuild/win32-x64": "npm:0.21.5" + dependenciesMeta: + "@esbuild/aix-ppc64": + optional: true + "@esbuild/android-arm": + optional: true + "@esbuild/android-arm64": + optional: true + "@esbuild/android-x64": + optional: true + "@esbuild/darwin-arm64": + optional: true + "@esbuild/darwin-x64": + optional: true + "@esbuild/freebsd-arm64": + optional: true + "@esbuild/freebsd-x64": + optional: true + "@esbuild/linux-arm": + optional: true + "@esbuild/linux-arm64": + optional: true + "@esbuild/linux-ia32": + optional: true + "@esbuild/linux-loong64": + optional: true + "@esbuild/linux-mips64el": + optional: true + "@esbuild/linux-ppc64": + optional: true + "@esbuild/linux-riscv64": + optional: true + "@esbuild/linux-s390x": + optional: true + "@esbuild/linux-x64": + optional: true + "@esbuild/netbsd-x64": + optional: true + "@esbuild/openbsd-x64": + optional: true + "@esbuild/sunos-x64": + optional: true + "@esbuild/win32-arm64": + optional: true + "@esbuild/win32-ia32": + optional: true + "@esbuild/win32-x64": + optional: true + bin: + esbuild: bin/esbuild + checksum: 10/d2ff2ca84d30cce8e871517374d6c2290835380dc7cd413b2d49189ed170d45e407be14de2cb4794cf76f75cf89955c4714726ebd3de7444b3046f5cab23ab6b + languageName: node + linkType: hard + "escalade@npm:^3.1.1": version: 3.1.1 resolution: "escalade@npm:3.1.1" @@ -28801,12 +29043,12 @@ __metadata: languageName: node linkType: hard -"get-tsconfig@npm:^4.7.2": - version: 4.7.2 - resolution: "get-tsconfig@npm:4.7.2" +"get-tsconfig@npm:^4.7.5": + version: 4.7.5 + resolution: "get-tsconfig@npm:4.7.5" dependencies: resolve-pkg-maps: "npm:^1.0.0" - checksum: 10/f21135848fb5d16012269b7b34b186af7a41824830f8616aba17a15eb4d9e54fdc876833f1e21768395215a826c8145582f5acd594ae2b4de3284d10b38d20f8 + checksum: 10/de7de5e4978354e8e6d9985baf40ea32f908a13560f793bc989930c229cc8d5c3f7b6b2896d8e43eb1a9b4e9e30018ef4b506752fd2a4b4d0dfee4af6841b119 languageName: node linkType: hard @@ -48567,19 +48809,19 @@ __metadata: languageName: node linkType: hard -"tsx@npm:4.7.0": - version: 4.7.0 - resolution: "tsx@npm:4.7.0" +"tsx@npm:4.16.2": + version: 4.16.2 + resolution: "tsx@npm:4.16.2" dependencies: - esbuild: "npm:~0.19.10" + esbuild: "npm:~0.21.5" fsevents: "npm:~2.3.3" - get-tsconfig: "npm:^4.7.2" + get-tsconfig: "npm:^4.7.5" dependenciesMeta: fsevents: optional: true bin: tsx: dist/cli.mjs - checksum: 10/3e6ee0a0a8adb7b1cb58875f50b143b41df0132ade3a7cdda16a166ac473eee446197762ba6afb235ace4c6adae7e55f61a420ee55b17438717eea1e55e611c0 + checksum: 10/841ccbace3dc0c42704bb5c4cea47e1f4cd313aa4719fd4531e5ed40bb862b02349c76f7c56c53b64207eebbb1c2ac2e117482aabfbf197a30fbc0b2584b60be languageName: node linkType: hard