From 8c95c6416b79050eb45807bc4925d331f7351970 Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Fri, 1 Dec 2023 10:51:48 +0200 Subject: [PATCH 1/5] new web proxy for nodeAccountId 3 Signed-off-by: svetoslav-nikol0v --- src/constants/ClientConstants.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/constants/ClientConstants.js b/src/constants/ClientConstants.js index ae6f7d870..7aa50106c 100644 --- a/src/constants/ClientConstants.js +++ b/src/constants/ClientConstants.js @@ -3,6 +3,7 @@ import AccountId from "../account/AccountId.js"; // MAINNET node proxies are the same for both 'WebClient' and 'NativeClient' export const MAINNET = { "https://grpc-web.myhbarwallet.com:443": new AccountId(3), + "https://node00.swirldslabs.com:443": new AccountId(3), "https://node01-00-grpc.swirlds.com:443": new AccountId(4), "https://node02.swirldslabs.com:443": new AccountId(5), "https://node03.swirldslabs.com:443": new AccountId(6), From 70411277c1bc1f198d7fc5ea50d4bc1d6529709a Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Fri, 1 Dec 2023 14:56:21 +0200 Subject: [PATCH 2/5] tests Signed-off-by: svetoslav-nikol0v --- test/unit/EcdsaPrivateKey.js | 21 +++++++++++++++++---- test/unit/Ed25519PrivateKey.js | 21 +++++++++++++++++---- 2 files changed, 34 insertions(+), 8 deletions(-) diff --git a/test/unit/EcdsaPrivateKey.js b/test/unit/EcdsaPrivateKey.js index 2bde9a6ab..1913cfb6a 100644 --- a/test/unit/EcdsaPrivateKey.js +++ b/test/unit/EcdsaPrivateKey.js @@ -6,6 +6,17 @@ import * as bip32 from "../../packages/cryptography/src/primitive/bip32.js"; const RAW_KEY = "8776c6b831a1b61ac10dac0304a2843de4716f54b1919bb91a2685d0fe3f3048"; +const DER_PRIVATE_KEY = + "3030020100300706052b8104000a04220420e06ecd79f00124bfc030b0321006683a6a579be7602f2eb52ca73e2901880682"; +const DER_PRIVATE_KEY_BYTES = new Uint8Array([ + 48, 48, 2, 1, 0, 48, 7, 6, 5, 43, 129, + 4, 0, 10, 4, 34, 4, 32, 224, 110, 205, 121, + 240, 1, 36, 191, 192, 48, 176, 50, 16, 6, 104, + 58, 106, 87, 155, 231, 96, 47, 46, 181, 44, 167, + 62, 41, 1, 136, 6, 130 +]) +const DER_PUBLIC_KEY = + "302d300706052b8104000a032200033697a2b3f9f0b9f4831b39986f7f3885636a3e8622a0bc3814a4a56f7ecdc4f1"; describe("EcdsaPrivateKey", function () { it("generate should return object", function () { @@ -23,10 +34,6 @@ describe("EcdsaPrivateKey", function () { }); it("should return a public key from a der private key", function () { - const DER_PRIVATE_KEY = - "3030020100300706052b8104000a04220420e06ecd79f00124bfc030b0321006683a6a579be7602f2eb52ca73e2901880682"; - const DER_PUBLIC_KEY = - "302d300706052b8104000a032200033697a2b3f9f0b9f4831b39986f7f3885636a3e8622a0bc3814a4a56f7ecdc4f1"; const publicKey = PrivateKey.fromStringDer(DER_PRIVATE_KEY).publicKey.toStringDer(); expect(publicKey).to.be.equal(DER_PUBLIC_KEY); @@ -352,4 +359,10 @@ describe("EcdsaPrivateKey", function () { PUBLIC_KEY4 ); }); + + it('should return private key from bytes', async function() { + const privateKeyFromBytes = PrivateKey.fromBytesECDSA(DER_PRIVATE_KEY_BYTES) + const publicKeyDer = privateKeyFromBytes.toStringDer() + expect(publicKeyDer).to.be.equal(DER_PRIVATE_KEY); + }) }); diff --git a/test/unit/Ed25519PrivateKey.js b/test/unit/Ed25519PrivateKey.js index bf0a02f78..7947fbc36 100644 --- a/test/unit/Ed25519PrivateKey.js +++ b/test/unit/Ed25519PrivateKey.js @@ -5,6 +5,17 @@ import * as hex from "../../src/encoding/hex.js"; const RAW_KEY = "302e020100300506032b657004220420a7bd8982bb05415bbc1e2dc2ae6aced66cba5eb871a4afd1579f8620b8c00d37"; +// ED25519 key +const DER_PRIVATE_KEY = + "302e020100300506032b6570042204203a056f85d71921be62466f5e93a4af0aa2e09a9eb4b2d839e06d805366659a74"; +const DER_PRIVATE_KEY_BYTES = new Uint8Array([ + 58, 5, 111, 133, 215, 25, 33, 190, + 98, 70, 111, 94, 147, 164, 175, 10, + 162, 224, 154, 158, 180, 178, 216, 57, + 224, 109, 128, 83, 102, 101, 154, 116 +]) +const DER_PUBLIC_KEY = + "302a300506032b65700321004a6892f034d2d1c9b1a76acca8e34884055172f4210a0c02e3c7d55084f224d1"; describe("Ed25519PrivateKey", function () { it("generate should return object", function () { @@ -22,10 +33,6 @@ describe("Ed25519PrivateKey", function () { }); it("should return a public key from a der private key", function () { - const DER_PRIVATE_KEY = - "302e020100300506032b6570042204203a056f85d71921be62466f5e93a4af0aa2e09a9eb4b2d839e06d805366659a74"; - const DER_PUBLIC_KEY = - "302a300506032b65700321004a6892f034d2d1c9b1a76acca8e34884055172f4210a0c02e3c7d55084f224d1"; const publicKey = PrivateKey.fromStringDer(DER_PRIVATE_KEY).publicKey.toStringDer(); expect(publicKey).to.be.equal(DER_PUBLIC_KEY); @@ -269,4 +276,10 @@ describe("Ed25519PrivateKey", function () { PUBLIC_KEY1 ); }); + + it('should return private key from bytes', async function() { + const privateKeyFromBytes = PrivateKey.fromBytesED25519(DER_PRIVATE_KEY_BYTES) + const publicKeyDer = privateKeyFromBytes.toStringDer() + expect(publicKeyDer).to.be.equal(DER_PRIVATE_KEY); + }) }); From ea6c98e7f73e03cc7323312f89ff0853b0ac8525 Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Mon, 4 Dec 2023 10:36:11 +0200 Subject: [PATCH 3/5] unit tests Signed-off-by: svetoslav-nikol0v --- test/integration/ClientIntegrationTest.js | 4 +++ test/integration/WalletIntegrationTest.js | 13 ++++++++ test/unit/EcdsaPrivateKey.js | 39 +++++++++++++++++------ test/unit/Ed25519PrivateKey.js | 35 ++++++++++++++------ 4 files changed, 72 insertions(+), 19 deletions(-) diff --git a/test/integration/ClientIntegrationTest.js b/test/integration/ClientIntegrationTest.js index 94a9b1380..5db07c04d 100644 --- a/test/integration/ClientIntegrationTest.js +++ b/test/integration/ClientIntegrationTest.js @@ -168,6 +168,10 @@ describe("ClientIntegration", function () { await clientForNetwork.pingAll(); }); + it('should return a boolean for client transport security', () => { + expect(clientTestnet.isTransportSecurity()).to.be.an('boolean') + }) + after(async function () { await env.close(); clientTestnet.close(); diff --git a/test/integration/WalletIntegrationTest.js b/test/integration/WalletIntegrationTest.js index cc72b22ce..c4e089040 100644 --- a/test/integration/WalletIntegrationTest.js +++ b/test/integration/WalletIntegrationTest.js @@ -1,3 +1,4 @@ +import { expect } from "chai"; import { AccountCreateTransaction, Hbar, @@ -8,6 +9,18 @@ import { Wallet, LocalProvider } from "../../src/index.js"; import IntegrationTestEnv from "./client/NodeIntegrationTestEnv.js"; describe("WalletIntegration", function () { + it("should create a wallet (ECDSA)", async () => { + const wallet = await Wallet.createRandomECDSA() + expect(wallet.getAccountKey()).to.not.equal(null) + expect(wallet.getAccountId()).to.not.equal(null) + }) + + it("should create a wallet (ED25519)", async () => { + const wallet = await Wallet.createRandomED25519() + expect(wallet.getAccountKey()).to.not.equal(null) + expect(wallet.getAccountId()).to.not.equal(null) + }) + it("issue-1530", async function () { this.timeout(30000); const env = await IntegrationTestEnv.new(); diff --git a/test/unit/EcdsaPrivateKey.js b/test/unit/EcdsaPrivateKey.js index 1913cfb6a..6c7a8121a 100644 --- a/test/unit/EcdsaPrivateKey.js +++ b/test/unit/EcdsaPrivateKey.js @@ -9,12 +9,10 @@ const RAW_KEY = const DER_PRIVATE_KEY = "3030020100300706052b8104000a04220420e06ecd79f00124bfc030b0321006683a6a579be7602f2eb52ca73e2901880682"; const DER_PRIVATE_KEY_BYTES = new Uint8Array([ - 48, 48, 2, 1, 0, 48, 7, 6, 5, 43, 129, - 4, 0, 10, 4, 34, 4, 32, 224, 110, 205, 121, - 240, 1, 36, 191, 192, 48, 176, 50, 16, 6, 104, - 58, 106, 87, 155, 231, 96, 47, 46, 181, 44, 167, - 62, 41, 1, 136, 6, 130 -]) + 48, 48, 2, 1, 0, 48, 7, 6, 5, 43, 129, 4, 0, 10, 4, 34, 4, 32, 224, 110, + 205, 121, 240, 1, 36, 191, 192, 48, 176, 50, 16, 6, 104, 58, 106, 87, 155, + 231, 96, 47, 46, 181, 44, 167, 62, 41, 1, 136, 6, 130, +]); const DER_PUBLIC_KEY = "302d300706052b8104000a032200033697a2b3f9f0b9f4831b39986f7f3885636a3e8622a0bc3814a4a56f7ecdc4f1"; @@ -360,9 +358,30 @@ describe("EcdsaPrivateKey", function () { ); }); - it('should return private key from bytes', async function() { - const privateKeyFromBytes = PrivateKey.fromBytesECDSA(DER_PRIVATE_KEY_BYTES) - const publicKeyDer = privateKeyFromBytes.toStringDer() + it("should return private key from bytes", async function () { + const privateKeyFromBytes = PrivateKey.fromBytesECDSA( + DER_PRIVATE_KEY_BYTES + ); + const publicKeyDer = privateKeyFromBytes.toStringDer(); expect(publicKeyDer).to.be.equal(DER_PRIVATE_KEY); - }) + }); + + it("should return a constructed aliasKey accountId", async function () { + const privateKey = PrivateKey.generateECDSA(); + const publicKey = privateKey.publicKey; + + console.log(privateKey.type); + + const aliasAccountId = publicKey.toAccountId(0, 0); + + expect(aliasAccountId.toString()).to.be.equal( + `0.0.${publicKey.toString()}` + ); + }); + + it("should return type of the private key", async function () { + const privateKey = PrivateKey.generateECDSA(); + + expect(privateKey.type).to.be.string("secp256k1"); + }); }); diff --git a/test/unit/Ed25519PrivateKey.js b/test/unit/Ed25519PrivateKey.js index 7947fbc36..866c3beb7 100644 --- a/test/unit/Ed25519PrivateKey.js +++ b/test/unit/Ed25519PrivateKey.js @@ -9,11 +9,9 @@ const RAW_KEY = const DER_PRIVATE_KEY = "302e020100300506032b6570042204203a056f85d71921be62466f5e93a4af0aa2e09a9eb4b2d839e06d805366659a74"; const DER_PRIVATE_KEY_BYTES = new Uint8Array([ - 58, 5, 111, 133, 215, 25, 33, 190, - 98, 70, 111, 94, 147, 164, 175, 10, - 162, 224, 154, 158, 180, 178, 216, 57, - 224, 109, 128, 83, 102, 101, 154, 116 -]) + 58, 5, 111, 133, 215, 25, 33, 190, 98, 70, 111, 94, 147, 164, 175, 10, 162, + 224, 154, 158, 180, 178, 216, 57, 224, 109, 128, 83, 102, 101, 154, 116, +]); const DER_PUBLIC_KEY = "302a300506032b65700321004a6892f034d2d1c9b1a76acca8e34884055172f4210a0c02e3c7d55084f224d1"; @@ -277,9 +275,28 @@ describe("Ed25519PrivateKey", function () { ); }); - it('should return private key from bytes', async function() { - const privateKeyFromBytes = PrivateKey.fromBytesED25519(DER_PRIVATE_KEY_BYTES) - const publicKeyDer = privateKeyFromBytes.toStringDer() + it("should return private key from bytes", async function () { + const privateKeyFromBytes = PrivateKey.fromBytesED25519( + DER_PRIVATE_KEY_BYTES + ); + const publicKeyDer = privateKeyFromBytes.toStringDer(); expect(publicKeyDer).to.be.equal(DER_PRIVATE_KEY); - }) + }); + + it("should return a constructed aliasKey accountId", async function () { + const privateKey = PrivateKey.generateED25519(); + const publicKey = privateKey.publicKey; + + const aliasAccountId = publicKey.toAccountId(0, 0); + + expect(aliasAccountId.toString()).to.be.equal( + `0.0.${publicKey.toString()}` + ); + }); + + it("should return type of the private key", async function () { + const privateKey = PrivateKey.generateED25519(); + + expect(privateKey.type).to.be.string("ED25519"); + }); }); From 1812669ed73a09f47db55d38d6462141660e0b72 Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Mon, 4 Dec 2023 17:49:11 +0200 Subject: [PATCH 4/5] integration tests for all node proxies Signed-off-by: svetoslav-nikol0v --- .../ClientConstantsIntegrationTest.js | 97 +++++++++++++++++++ test/integration/ClientIntegrationTest.js | 6 +- test/integration/WalletIntegrationTest.js | 22 ++--- 3 files changed, 111 insertions(+), 14 deletions(-) create mode 100644 test/integration/ClientConstantsIntegrationTest.js diff --git a/test/integration/ClientConstantsIntegrationTest.js b/test/integration/ClientConstantsIntegrationTest.js new file mode 100644 index 000000000..a8800853a --- /dev/null +++ b/test/integration/ClientConstantsIntegrationTest.js @@ -0,0 +1,97 @@ +/* eslint-disable mocha/no-setup-in-describe */ +import { + MAINNET, + WEB_TESTNET, + WEB_PREVIEWNET, + NATIVE_PREVIEWNET, + NATIVE_TESTNET, +} from "../../src/constants/ClientConstants.js"; +import { + AccountBalance, + AccountBalanceQuery, + Hbar, +} from "../../src/exports.js"; +import IntegrationTestEnv from "./client/NodeIntegrationTestEnv.js"; + +describe("ClientConstantsIntegrationTest", function () { + let env; + + before(async function () { + env = await IntegrationTestEnv.new(); + }); + + describe("MAINNET node proxies", function () { + const proxies = Object.keys(MAINNET); + proxies.forEach((proxy) => { + it(`should fetch ${MAINNET[proxy]} account balnace`, async function () { + const accountBalance = await new AccountBalanceQuery() + .setNodeAccountIds([MAINNET[proxy]]) + .setAccountId(env.operatorId) + .execute(env.client); + + expect(accountBalance instanceof AccountBalance).to.be.true; + expect(accountBalance.hbars instanceof Hbar).to.be.true; + }); + }); + }); + + describe("WEB TESTNET node proxies", function () { + const proxies = Object.keys(WEB_TESTNET); + proxies.forEach((proxy) => { + it(`should fetch ${WEB_TESTNET[proxy]} account balnace`, async function () { + const accountBalance = await new AccountBalanceQuery() + .setNodeAccountIds([WEB_TESTNET[proxy]]) + .setAccountId(env.operatorId) + .execute(env.client); + + expect(accountBalance instanceof AccountBalance).to.be.true; + expect(accountBalance.hbars instanceof Hbar).to.be.true; + }); + }); + }); + + describe("WEB PREVIEWNET node proxies", function () { + const proxies = Object.keys(WEB_PREVIEWNET); + proxies.forEach((proxy) => { + it(`should fetch ${WEB_PREVIEWNET[proxy]} account balnace`, async function () { + const accountBalance = await new AccountBalanceQuery() + .setNodeAccountIds([WEB_PREVIEWNET[proxy]]) + .setAccountId(env.operatorId) + .execute(env.client); + + expect(accountBalance instanceof AccountBalance).to.be.true; + expect(accountBalance.hbars instanceof Hbar).to.be.true; + }); + }); + }); + + describe("NATIVE PREVIEWNET node proxies", function () { + const proxies = Object.keys(NATIVE_PREVIEWNET); + proxies.forEach((proxy) => { + it(`should fetch ${NATIVE_PREVIEWNET[proxy]} account balnace`, async function () { + const accountBalance = await new AccountBalanceQuery() + .setNodeAccountIds([NATIVE_PREVIEWNET[proxy]]) + .setAccountId(env.operatorId) + .execute(env.client); + + expect(accountBalance instanceof AccountBalance).to.be.true; + expect(accountBalance.hbars instanceof Hbar).to.be.true; + }); + }); + }); + + describe("NATIVE TESTNET node proxies", function () { + const proxies = Object.keys(NATIVE_TESTNET); + proxies.forEach((proxy) => { + it(`should fetch ${NATIVE_TESTNET[proxy]} account balnace`, async function () { + const accountBalance = await new AccountBalanceQuery() + .setNodeAccountIds([NATIVE_TESTNET[proxy]]) + .setAccountId(env.operatorId) + .execute(env.client); + + expect(accountBalance instanceof AccountBalance).to.be.true; + expect(accountBalance.hbars instanceof Hbar).to.be.true; + }); + }); + }); +}); diff --git a/test/integration/ClientIntegrationTest.js b/test/integration/ClientIntegrationTest.js index 5db07c04d..72b698afb 100644 --- a/test/integration/ClientIntegrationTest.js +++ b/test/integration/ClientIntegrationTest.js @@ -168,9 +168,9 @@ describe("ClientIntegration", function () { await clientForNetwork.pingAll(); }); - it('should return a boolean for client transport security', () => { - expect(clientTestnet.isTransportSecurity()).to.be.an('boolean') - }) + it("should return a boolean for client transport security", function () { + expect(clientTestnet.isTransportSecurity()).to.be.an("boolean"); + }); after(async function () { await env.close(); diff --git a/test/integration/WalletIntegrationTest.js b/test/integration/WalletIntegrationTest.js index c4e089040..ab3659074 100644 --- a/test/integration/WalletIntegrationTest.js +++ b/test/integration/WalletIntegrationTest.js @@ -9,17 +9,17 @@ import { Wallet, LocalProvider } from "../../src/index.js"; import IntegrationTestEnv from "./client/NodeIntegrationTestEnv.js"; describe("WalletIntegration", function () { - it("should create a wallet (ECDSA)", async () => { - const wallet = await Wallet.createRandomECDSA() - expect(wallet.getAccountKey()).to.not.equal(null) - expect(wallet.getAccountId()).to.not.equal(null) - }) - - it("should create a wallet (ED25519)", async () => { - const wallet = await Wallet.createRandomED25519() - expect(wallet.getAccountKey()).to.not.equal(null) - expect(wallet.getAccountId()).to.not.equal(null) - }) + it("should create a wallet (ECDSA)", async function () { + const wallet = await Wallet.createRandomECDSA(); + expect(wallet.getAccountKey()).to.not.equal(null); + expect(wallet.getAccountId()).to.not.equal(null); + }); + + it("should create a wallet (ED25519)", async function () { + const wallet = await Wallet.createRandomED25519(); + expect(wallet.getAccountKey()).to.not.equal(null); + expect(wallet.getAccountId()).to.not.equal(null); + }); it("issue-1530", async function () { this.timeout(30000); From bd58a171b9bb3dd5a1d42ea2cb0a7f135d629061 Mon Sep 17 00:00:00 2001 From: svetoslav-nikol0v Date: Tue, 5 Dec 2023 11:02:49 +0200 Subject: [PATCH 5/5] change the account id to avoid possible problem while running tests Signed-off-by: svetoslav-nikol0v --- test/integration/ClientConstantsIntegrationTest.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/integration/ClientConstantsIntegrationTest.js b/test/integration/ClientConstantsIntegrationTest.js index a8800853a..86466c19a 100644 --- a/test/integration/ClientConstantsIntegrationTest.js +++ b/test/integration/ClientConstantsIntegrationTest.js @@ -26,7 +26,7 @@ describe("ClientConstantsIntegrationTest", function () { it(`should fetch ${MAINNET[proxy]} account balnace`, async function () { const accountBalance = await new AccountBalanceQuery() .setNodeAccountIds([MAINNET[proxy]]) - .setAccountId(env.operatorId) + .setAccountId(MAINNET[proxy]) .execute(env.client); expect(accountBalance instanceof AccountBalance).to.be.true; @@ -41,7 +41,7 @@ describe("ClientConstantsIntegrationTest", function () { it(`should fetch ${WEB_TESTNET[proxy]} account balnace`, async function () { const accountBalance = await new AccountBalanceQuery() .setNodeAccountIds([WEB_TESTNET[proxy]]) - .setAccountId(env.operatorId) + .setAccountId(WEB_TESTNET[proxy]) .execute(env.client); expect(accountBalance instanceof AccountBalance).to.be.true; @@ -56,7 +56,7 @@ describe("ClientConstantsIntegrationTest", function () { it(`should fetch ${WEB_PREVIEWNET[proxy]} account balnace`, async function () { const accountBalance = await new AccountBalanceQuery() .setNodeAccountIds([WEB_PREVIEWNET[proxy]]) - .setAccountId(env.operatorId) + .setAccountId(WEB_PREVIEWNET[proxy]) .execute(env.client); expect(accountBalance instanceof AccountBalance).to.be.true; @@ -71,7 +71,7 @@ describe("ClientConstantsIntegrationTest", function () { it(`should fetch ${NATIVE_PREVIEWNET[proxy]} account balnace`, async function () { const accountBalance = await new AccountBalanceQuery() .setNodeAccountIds([NATIVE_PREVIEWNET[proxy]]) - .setAccountId(env.operatorId) + .setAccountId(NATIVE_PREVIEWNET[proxy]) .execute(env.client); expect(accountBalance instanceof AccountBalance).to.be.true; @@ -86,7 +86,7 @@ describe("ClientConstantsIntegrationTest", function () { it(`should fetch ${NATIVE_TESTNET[proxy]} account balnace`, async function () { const accountBalance = await new AccountBalanceQuery() .setNodeAccountIds([NATIVE_TESTNET[proxy]]) - .setAccountId(env.operatorId) + .setAccountId(NATIVE_TESTNET[proxy]) .execute(env.client); expect(accountBalance instanceof AccountBalance).to.be.true;