From dfaa20a74ae8dc4e1596fb1dac131e5a25dfc371 Mon Sep 17 00:00:00 2001 From: Luca Nicola Debiasi <63785793+lucanicoladebiasi@users.noreply.github.com> Date: Tue, 28 Jan 2025 15:07:14 +0000 Subject: [PATCH] fix: fr9 recommendations (#1743) * fix: fr9 recommendations * fix: en_1 recommendations --------- Co-authored-by: Fabio Rigamonti <73019897+fabiorigam@users.noreply.github.com> --- docs/accounts.md | 2 +- docs/certificates.md | 2 +- docs/cryptography.md | 2 +- docs/examples/accounts/keystore.ts | 2 +- docs/examples/certificates/sign_verify.ts | 2 +- docs/examples/cryptography/secp256k1.ts | 2 +- .../transactions/blockref-expiration.ts | 2 +- .../examples/transactions/multiple-clauses.ts | 2 +- docs/examples/transactions/sign-decode.ts | 2 +- docs/examples/transactions/tx-dependency.ts | 2 +- docs/transactions.md | 8 +- packages/core/src/secp256k1/Secp256k1.ts | 47 ++-- .../core/tests/keystore/keystore.unit.test.ts | 10 +- .../tests/secp256k1/Secp256k1.unit.test.ts | 216 ++++++++++-------- packages/core/tests/secp256k1/fixture.ts | 49 ---- ...provider-internal-base-wallet.unit.test.ts | 5 +- 16 files changed, 151 insertions(+), 204 deletions(-) delete mode 100644 packages/core/tests/secp256k1/fixture.ts diff --git a/docs/accounts.md b/docs/accounts.md index 030eb7c66..7b8b55b49 100644 --- a/docs/accounts.md +++ b/docs/accounts.md @@ -130,7 +130,7 @@ Through the use of mnemonics and keystore, VeChainSDK ensures secure and user-fr ```typescript { name=keystore, category=example } // 1 - Create private key using Secp256k1 -const privateKey = await Secp256k1.generatePrivateKey(); +const privateKey = Secp256k1.generatePrivateKey(); // @NOTE you can use BIP 39 too! // const words = Mnemonic.of() diff --git a/docs/certificates.md b/docs/certificates.md index 5ccdf6912..770f64bc1 100644 --- a/docs/certificates.md +++ b/docs/certificates.md @@ -47,7 +47,7 @@ It's important to note that certificates in the VeChainThor blockchain are self- ```typescript { name=sign_verify, category=example } // 1 - Generate a private key and address for the signer -const privateKey = await Secp256k1.generatePrivateKey(); +const privateKey = Secp256k1.generatePrivateKey(); const publicKey = Secp256k1.derivePublicKey(privateKey); const signerAddress = Address.ofPublicKey(publicKey).toString(); diff --git a/docs/cryptography.md b/docs/cryptography.md index 14d1d8dab..caa0e412e 100644 --- a/docs/cryptography.md +++ b/docs/cryptography.md @@ -51,7 +51,7 @@ Secp256k1 is mainly used for generating public and private key pairs in cryptogr ```typescript { name=secp256k1, category=example } // 1 - Generate a private key. -const privateKey = await Secp256k1.generatePrivateKey(); +const privateKey = Secp256k1.generatePrivateKey(); console.log('Private key:', Hex.of(privateKey).toString()); // Private key: ...SOME_PRIVATE_KEY... diff --git a/docs/examples/accounts/keystore.ts b/docs/examples/accounts/keystore.ts index de3d5e41d..b120514c9 100644 --- a/docs/examples/accounts/keystore.ts +++ b/docs/examples/accounts/keystore.ts @@ -5,7 +5,7 @@ import { expect } from 'expect'; // 1 - Create private key using Secp256k1 -const privateKey = await Secp256k1.generatePrivateKey(); +const privateKey = Secp256k1.generatePrivateKey(); // @NOTE you can use BIP 39 too! // const words = Mnemonic.of() diff --git a/docs/examples/certificates/sign_verify.ts b/docs/examples/certificates/sign_verify.ts index 30843549d..aea3f4843 100644 --- a/docs/examples/certificates/sign_verify.ts +++ b/docs/examples/certificates/sign_verify.ts @@ -4,7 +4,7 @@ import { Address, Certificate, Secp256k1 } from '@vechain/sdk-core'; // 1 - Generate a private key and address for the signer -const privateKey = await Secp256k1.generatePrivateKey(); +const privateKey = Secp256k1.generatePrivateKey(); const publicKey = Secp256k1.derivePublicKey(privateKey); const signerAddress = Address.ofPublicKey(publicKey).toString(); diff --git a/docs/examples/cryptography/secp256k1.ts b/docs/examples/cryptography/secp256k1.ts index bfca9d93b..32fce2b51 100644 --- a/docs/examples/cryptography/secp256k1.ts +++ b/docs/examples/cryptography/secp256k1.ts @@ -5,7 +5,7 @@ import { expect } from 'expect'; // 1 - Generate a private key. -const privateKey = await Secp256k1.generatePrivateKey(); +const privateKey = Secp256k1.generatePrivateKey(); console.log('Private key:', Hex.of(privateKey).toString()); // Private key: ...SOME_PRIVATE_KEY... diff --git a/docs/examples/transactions/blockref-expiration.ts b/docs/examples/transactions/blockref-expiration.ts index 482b096c7..642592796 100644 --- a/docs/examples/transactions/blockref-expiration.ts +++ b/docs/examples/transactions/blockref-expiration.ts @@ -37,7 +37,7 @@ const body: TransactionBody = { // 3 - Create private key -const privateKey = await Secp256k1.generatePrivateKey(); +const privateKey = Secp256k1.generatePrivateKey(); // 4 - Sign transaction diff --git a/docs/examples/transactions/multiple-clauses.ts b/docs/examples/transactions/multiple-clauses.ts index 38db1fd8f..3cfd258e6 100644 --- a/docs/examples/transactions/multiple-clauses.ts +++ b/docs/examples/transactions/multiple-clauses.ts @@ -46,7 +46,7 @@ const body: TransactionBody = { }; // Create private key -const privateKey = await Secp256k1.generatePrivateKey(); +const privateKey = Secp256k1.generatePrivateKey(); // 4 - Sign transaction diff --git a/docs/examples/transactions/sign-decode.ts b/docs/examples/transactions/sign-decode.ts index 2ca476a2c..9fdc00c1c 100644 --- a/docs/examples/transactions/sign-decode.ts +++ b/docs/examples/transactions/sign-decode.ts @@ -40,7 +40,7 @@ const body: TransactionBody = { }; // Create private key -const privateKey = await Secp256k1.generatePrivateKey(); +const privateKey = Secp256k1.generatePrivateKey(); // 4 - Sign transaction diff --git a/docs/examples/transactions/tx-dependency.ts b/docs/examples/transactions/tx-dependency.ts index 727c0a2eb..cd76ad71c 100644 --- a/docs/examples/transactions/tx-dependency.ts +++ b/docs/examples/transactions/tx-dependency.ts @@ -57,7 +57,7 @@ const txBBody: TransactionBody = { }; // Define the senders private key -const senderPrivateKey = await Secp256k1.generatePrivateKey(); +const senderPrivateKey = Secp256k1.generatePrivateKey(); // To define transaction B as dependent on transaction // it's necessary to sign transaction A, and then get its Id diff --git a/docs/transactions.md b/docs/transactions.md index a4360ecc9..26bbcfa32 100644 --- a/docs/transactions.md +++ b/docs/transactions.md @@ -47,7 +47,7 @@ const body: TransactionBody = { }; // Create private key -const privateKey = await Secp256k1.generatePrivateKey(); +const privateKey = Secp256k1.generatePrivateKey(); // 4 - Sign transaction @@ -99,7 +99,7 @@ const body: TransactionBody = { }; // Create private key -const privateKey = await Secp256k1.generatePrivateKey(); +const privateKey = Secp256k1.generatePrivateKey(); // 4 - Sign transaction @@ -214,7 +214,7 @@ const body: TransactionBody = { // 3 - Create private key -const privateKey = await Secp256k1.generatePrivateKey(); +const privateKey = Secp256k1.generatePrivateKey(); // 4 - Sign transaction @@ -277,7 +277,7 @@ const txBBody: TransactionBody = { }; // Define the senders private key -const senderPrivateKey = await Secp256k1.generatePrivateKey(); +const senderPrivateKey = Secp256k1.generatePrivateKey(); // To define transaction B as dependent on transaction // it's necessary to sign transaction A, and then get its Id diff --git a/packages/core/src/secp256k1/Secp256k1.ts b/packages/core/src/secp256k1/Secp256k1.ts index 2d8416404..c5b421fac 100644 --- a/packages/core/src/secp256k1/Secp256k1.ts +++ b/packages/core/src/secp256k1/Secp256k1.ts @@ -94,41 +94,26 @@ class Secp256k1 { } /** - * Generates a new random private key. - * If an error occurs during generation using - * [nc_secp256k1](https://github.com/paulmillr/noble-secp256k1), - * an AES-GCM key is generated as a fallback in runtimes not supported - * by `nc_secp256k1`, if those support {@link {@link global.crypto}. + * Generates a new Secp256k1 private key using a secure random number generator. * - * @return {Promise} The generated private key as a Uint8Array. + * @return {Uint8Array} A Uint8Array representing the generated private key. + * This encoded private key is suitable for cryptographic operations. + * @throws {InvalidSecp256k1PrivateKey} Throws an error if private key generation fails if a secure random number + * generator is not provided by the hosting operating system. * * @remarks Security auditable method, depends on - * * {@link global.crypto.subtle.exportKey}; - * * {@link global.crypto.subtle.generateKey}; * * [nc_secp256k1.utils.randomPrivateKey](https://github.com/paulmillr/noble-secp256k1). */ - public static async generatePrivateKey(): Promise { + public static generatePrivateKey(): Uint8Array { try { return nc_secp256k1.utils.randomPrivateKey(); } catch (e) { - // Generate an ECDSA key pair - const cryptoKey = await global.crypto.subtle.generateKey( - { - name: 'AES-GCM', - length: 256 - }, - true, - ['encrypt', 'decrypt'] - ); - - // Export the private key to raw format - const rawKey = await global.crypto.subtle.exportKey( - 'raw', - cryptoKey + throw new InvalidSecp256k1PrivateKey( + 'Secp256k1.generatePrivateKey', + 'Private key generation failed: ensure you have a secure random number generator available at runtime.', + undefined, + e ); - - // Convert the ArrayBuffer to Uint8Array - return new Uint8Array(rawKey); } } @@ -192,20 +177,18 @@ class Secp256k1 { * {@link {@link global.crypto} is used as fall back togenerate * the random sequence. * - * @param {number} [bytesLength=32] - Optional. The number of random bytes to generate. + * @param {number} [bytesLength=32] - Optional. The number of random bytes to generate, 32 by default. * @return {Uint8Array} - A Uint8Array containing the random bytes. * * @remarks Security auditable method, depends on - * * {@link global.crypto.getRandomValues}; + * * {@link global.crypto.getRandomValues}; * * [nh_randomBytes](https://github.com/paulmillr/noble-hashes). */ - public static randomBytes(bytesLength?: number): Uint8Array { + public static randomBytes(bytesLength: number = 32): Uint8Array { try { return nh_randomBytes(bytesLength); } catch (e) { - return global.crypto.getRandomValues( - new Uint8Array(bytesLength ?? 32) - ); + return global.crypto.getRandomValues(new Uint8Array(bytesLength)); } } diff --git a/packages/core/tests/keystore/keystore.unit.test.ts b/packages/core/tests/keystore/keystore.unit.test.ts index 10afec487..5bd8674d6 100644 --- a/packages/core/tests/keystore/keystore.unit.test.ts +++ b/packages/core/tests/keystore/keystore.unit.test.ts @@ -31,7 +31,7 @@ import { encryptionPassword } from './fixture'; */ test('encrypt', async () => { // Generate a random private key - const privateKey = await Secp256k1.generatePrivateKey(); + const privateKey = Secp256k1.generatePrivateKey(); const addressFromPrivateKey = Address.ofPrivateKey(privateKey).toString(); @@ -68,7 +68,7 @@ import { encryptionPassword } from './fixture'; */ test('decrypt', async () => { // Generate a random private key - const privateKey = await Secp256k1.generatePrivateKey(); + const privateKey = Secp256k1.generatePrivateKey(); const expected = HexUInt.of(privateKey).toString(); @@ -93,7 +93,7 @@ import { encryptionPassword } from './fixture'; */ test('decrypt with invalid password', async () => { // Generate a random private key - const privateKey = await Secp256k1.generatePrivateKey(); + const privateKey = Secp256k1.generatePrivateKey(); // Create keystore const myKeystore = await keystore.encrypt( @@ -116,7 +116,7 @@ import { encryptionPassword } from './fixture'; */ test('decrypt invalid keystore', async () => { // Generate a random private key - const privateKey = await Secp256k1.generatePrivateKey(); + const privateKey = Secp256k1.generatePrivateKey(); // Create keystore const myKeystore = await keystore.encrypt( @@ -149,7 +149,7 @@ import { encryptionPassword } from './fixture'; */ test('validation', async () => { // Generate a random private key - const privateKey = await Secp256k1.generatePrivateKey(); + const privateKey = Secp256k1.generatePrivateKey(); // Create keystore const myKeystore = await keystore.encrypt( diff --git a/packages/core/tests/secp256k1/Secp256k1.unit.test.ts b/packages/core/tests/secp256k1/Secp256k1.unit.test.ts index 9bd0b29f5..372a5a3a3 100644 --- a/packages/core/tests/secp256k1/Secp256k1.unit.test.ts +++ b/packages/core/tests/secp256k1/Secp256k1.unit.test.ts @@ -4,177 +4,191 @@ import { InvalidSecp256k1PrivateKey, InvalidSecp256k1Signature } from '@vechain/sdk-errors'; -import { HexUInt, Secp256k1, ZERO_BYTES } from '../../src'; -import { - invalidMessageHashes, - messageHashBuffer, - privateKey, - publicKeyCompressed, - publicKeyUncompressed, - signature, - validMessageHashes, - validPrivateKeys -} from './fixture'; +import { Keccak256, Secp256k1, Txt, ZERO_BYTES } from '../../src'; +import * as n_utils from '@noble/curves/abstract/utils'; + +const HASHES = { + invalid: Txt.of('some_invalid_stuff').bytes, + valid: Keccak256.of(Txt.of('hello world').bytes).bytes +}; + +const KEYS = { + private: { + invalid: n_utils.hexToBytes( + 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff' + ), + valid: n_utils.hexToBytes( + '7582be841ca040aa940fff6c05773129e135623e41acce3e0b8ba520dc1ae26a' + ) + }, + public: { + compressed: n_utils.hexToBytes( + '03b90e9bb2617387eba4502c730de65a33878ef384a46f1096d86f2da19043304a' + ), + uncompressed: n_utils.hexToBytes( + '04b90e9bb2617387eba4502c730de65a33878ef384a46f1096d86f2da19043304afa67d0ad09cf2bea0c6f2d1767a9e62a7a7ecc41facf18f2fa505d92243a658f' + ) + } +}; + +const SIGNATURES = { + valid: n_utils.hexToBytes( + 'f8fe82c74f9e1f5bf443f8a7f8eb968140f554968fdcab0a6ffe904e451c8b9244be44bccb1feb34dd20d9d8943f8c131227e55861736907b02d32c06b934d7200' + ) +}; /** * Test Secp256k1 class. * @group unit/Secp256k1 */ describe('Secp256k1 class tests', () => { - const invalid = new TextEncoder().encode('some_invalid_stuff'); - describe('Secp256k1 - compressPublicKey', () => { - test('Secp256k1 - compressPublicKey - from compressed', () => { + describe('compressPublicKey', () => { + test('ok <- compressed', () => { expect( - Secp256k1.compressPublicKey(publicKeyCompressed) - ).toStrictEqual(publicKeyCompressed); + Secp256k1.compressPublicKey(KEYS.public.compressed) + ).toStrictEqual(KEYS.public.compressed); }); - test('Secp256k1 - compressPublicKey - from uncompressed', () => { + test('ok <- uncompressed', () => { expect( - Secp256k1.compressPublicKey(publicKeyUncompressed) - ).toStrictEqual(publicKeyCompressed); + Secp256k1.compressPublicKey(KEYS.public.uncompressed) + ).toStrictEqual(KEYS.public.compressed); }); }); - describe('Secp256k1 - derivePublicKey', () => { - test('Secp256k1 - derivePublicKey - compressed', () => { - expect(Secp256k1.derivePublicKey(privateKey)).toStrictEqual( - Secp256k1.compressPublicKey(publicKeyUncompressed) + describe('derivePublicKey', () => { + test('ok <- compressed', () => { + expect(Secp256k1.derivePublicKey(KEYS.private.valid)).toStrictEqual( + Secp256k1.compressPublicKey(KEYS.public.compressed) ); }); - test('Secp256k1 - derivePublicKey - uncompressed', () => { - expect(Secp256k1.derivePublicKey(privateKey, false)).toStrictEqual( - publicKeyUncompressed - ); + test('ok <- uncompressed', () => { + expect( + Secp256k1.derivePublicKey(KEYS.private.valid, false) + ).toStrictEqual(KEYS.public.uncompressed); }); - test('Secp256k1 - derivePublicKey - error', () => { + test('error <- invalid key', () => { expect(() => Secp256k1.derivePublicKey(ZERO_BYTES(32)) ).toThrowError(InvalidSecp256k1PrivateKey); }); }); - describe('Secp256k1 - generatePublicKey', () => { - test('Secp256k1 - generatePrivateKey', async () => { - const randomPrivateKey = await Secp256k1.generatePrivateKey(); + describe('generatePrivateKey', () => { + test('ok <- noble library', () => { + const privateKey = Secp256k1.generatePrivateKey(); // Length of private key should be 32 bytes - expect(randomPrivateKey.length).toBe(32); + expect(privateKey.length).toBe(32); // Private key should be valid - expect(Secp256k1.isValidPrivateKey(randomPrivateKey)).toBe(true); + expect(Secp256k1.isValidPrivateKey(privateKey)).toBe(true); + }); + + test('error <- mock no hw support for cryptography', () => { + jest.spyOn(Secp256k1, 'generatePrivateKey').mockImplementation( + () => { + throw new InvalidSecp256k1PrivateKey( + 'Secp256k1.generatePrivateKey', + 'Private key generation failed: ensure you have a secure random number generator available at runtime.', + undefined + ); + } + ); + expect(() => Secp256k1.generatePrivateKey()).toThrowError( + InvalidSecp256k1PrivateKey + ); }); }); - describe('Secp256k1 - inflatePublicKey', () => { - test('Secp256k1 - inflatePublicKey - compressed', () => { + describe('inflatePublicKey', () => { + test('ok <- compressed', () => { expect( - Secp256k1.inflatePublicKey(publicKeyCompressed) - ).toStrictEqual(publicKeyUncompressed); + Secp256k1.inflatePublicKey(KEYS.public.compressed) + ).toStrictEqual(KEYS.public.uncompressed); }); - test('Secp256k1 - inflatePublicKey - uncompressed', () => { + test('ok <- uncompressed', () => { expect( - Secp256k1.inflatePublicKey(publicKeyUncompressed) - ).toStrictEqual(publicKeyUncompressed); + Secp256k1.inflatePublicKey(KEYS.public.uncompressed) + ).toStrictEqual(KEYS.public.uncompressed); }); }); - describe('Secp256k1 - isValidMessageHash', () => { - test('Secp256k1 - isValidMessageHash - true', () => { - validMessageHashes.forEach((messageHash: Uint8Array) => { - expect(Secp256k1.isValidMessageHash(messageHash)).toBe(true); - }); + describe('isValidMessageHash', () => { + test('true <- valid', () => { + expect(Secp256k1.isValidMessageHash(HASHES.valid)).toBe(true); }); - test('Secp256k1 - isValidMessageHash - false', () => { - invalidMessageHashes.forEach((messageHash: Uint8Array) => { - expect(Secp256k1.isValidMessageHash(messageHash)).toBe(false); - }); + test('false <- invalid', () => { + expect(Secp256k1.isValidMessageHash(HASHES.invalid)).toBe(false); }); }); - describe('Secp256k1 - isValidPrivateKey', () => { - test('Secp256k1 - isValidPrivateKey - true', () => { - validPrivateKeys.forEach((privateKey: Uint8Array) => { - expect(Secp256k1.isValidPrivateKey(privateKey)).toBe(true); - }); + describe('isValidPrivateKey', () => { + test('true <- valid', () => { + expect(Secp256k1.isValidPrivateKey(KEYS.private.valid)).toBe(true); }); - test('Secp256k1 - isValidPrivateKey - false', () => { - validPrivateKeys.forEach((privateKey: Uint8Array) => { - expect(Secp256k1.isValidPrivateKey(privateKey)).toBe(true); - }); + test('false <- invalid', () => { + expect(Secp256k1.isValidPrivateKey(KEYS.private.invalid)).toBe( + false + ); }); }); - describe('Secp256k1 - sign', () => { - test('Secp256k1 - sign - success', () => { - expect(Secp256k1.sign(messageHashBuffer, privateKey)).toStrictEqual( - signature - ); + describe('sign', () => { + test('ok - valid hash', () => { + expect( + Secp256k1.sign(HASHES.valid, KEYS.private.valid) + ).toStrictEqual(SIGNATURES.valid); }); - test('Secp256k1 - sign - failure - invalid message hash', () => { - expect(() => Secp256k1.sign(invalid, privateKey)).toThrowError( - InvalidSecp256k1MessageHash - ); + test('error <- invalid hash', () => { + expect(() => + Secp256k1.sign(HASHES.invalid, KEYS.private.valid) + ).toThrowError(InvalidSecp256k1MessageHash); }); - test('Secp256k1 - sign - failure - invalid private key', () => { + test('error <- invalid private key', () => { expect(() => - Secp256k1.sign( - messageHashBuffer, - HexUInt.of( - 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff' - ).bytes - ) + Secp256k1.sign(HASHES.valid, KEYS.private.invalid) ).toThrowError(InvalidSecp256k1PrivateKey); }); }); - describe('Secp256k1 - randomBytes', () => { - test('Secp256k1 - randomBytes - without parameters', () => { + describe('randomBytes', () => { + test('ok <- default', () => { const result = Secp256k1.randomBytes(); - expect(result.length).toBeGreaterThan(0); + expect(result.length).toBe(32); }); - test('Secp256k1 - randomBytes - with param', () => { + test('ok <- set length', () => { const result = Secp256k1.randomBytes(16); expect(result.length).toBe(16); }); - - test('Secp256k1 - randomBytes - with param', () => { - expect(() => Secp256k1.randomBytes(28)).toBeDefined(); - }); }); - describe('Secp256k1 - recover', () => { - test('Secp256k1 - recover - success', () => { + describe('recover', () => { + test('ok < - valid', () => { expect( - Secp256k1.recover(messageHashBuffer, signature) - ).toStrictEqual(publicKeyUncompressed); + Secp256k1.recover(HASHES.valid, SIGNATURES.valid) + ).toStrictEqual(KEYS.public.uncompressed); }); - test('Secp256k1 - recover - invalid message hash', () => { - expect(() => Secp256k1.recover(invalid, signature)).toThrowError( - InvalidSecp256k1MessageHash - ); - }); - - test('Secp256k1 - recover - invalid signature', () => { - // Invalid signature + test('error <- invalid hash', () => { expect(() => - Secp256k1.recover(messageHashBuffer, invalid) - ).toThrowError(InvalidSecp256k1Signature); + Secp256k1.recover(HASHES.invalid, SIGNATURES.valid) + ).toThrowError(InvalidSecp256k1MessageHash); }); - test('Secp256k1 - recover - failure', () => { - // Invalid signature recovery - const invalidSignatureRecovery = new Uint8Array(signature); - invalidSignatureRecovery[64] = 8; + test('error <- invalid signature', () => { + // Forge an invalid signature... + const invalidSignature = new Uint8Array(SIGNATURES.valid); + // ... altering the last byte. + invalidSignature[64] = 8; expect(() => - Secp256k1.recover(messageHashBuffer, invalidSignatureRecovery) + Secp256k1.recover(HASHES.valid, invalidSignature) ).toThrowError(InvalidSecp256k1Signature); }); }); diff --git a/packages/core/tests/secp256k1/fixture.ts b/packages/core/tests/secp256k1/fixture.ts deleted file mode 100644 index e14fb1845..000000000 --- a/packages/core/tests/secp256k1/fixture.ts +++ /dev/null @@ -1,49 +0,0 @@ -import * as n_utils from '@noble/curves/abstract/utils'; -import { Keccak256, Txt } from '../../src'; - -/** - * Simple public key and private key pair with corresponding signature - */ -const privateKey = n_utils.hexToBytes( - '7582be841ca040aa940fff6c05773129e135623e41acce3e0b8ba520dc1ae26a' -); - -const publicKeyCompressed = n_utils.hexToBytes( - '03b90e9bb2617387eba4502c730de65a33878ef384a46f1096d86f2da19043304a' -); - -const publicKeyUncompressed = n_utils.hexToBytes( - '04b90e9bb2617387eba4502c730de65a33878ef384a46f1096d86f2da19043304afa67d0ad09cf2bea0c6f2d1767a9e62a7a7ecc41facf18f2fa505d92243a658f' -); - -const signature = n_utils.hexToBytes( - 'f8fe82c74f9e1f5bf443f8a7f8eb968140f554968fdcab0a6ffe904e451c8b9244be44bccb1feb34dd20d9d8943f8c131227e55861736907b02d32c06b934d7200' -); - -/** - * Simple message hashes - */ -const messageHashBuffer = Keccak256.of(Txt.of('hello world').bytes).bytes; -const validMessageHashes = [messageHashBuffer]; -const invalidMessageHashes = [Txt.of('some_invalid_stuff').bytes]; - -/** - * Valid and invalid private keys - */ -const validPrivateKeys = [ - // PLEASE: Don't use this private key for your wallet :D - n_utils.hexToBytes( - '7582be841ca040aa940fff6c05773129e135623e41acce3e0b8ba520dc1ae26a' - ) -]; - -export { - invalidMessageHashes, - messageHashBuffer, - privateKey, - publicKeyCompressed, - publicKeyUncompressed, - signature, - validMessageHashes, - validPrivateKeys -}; diff --git a/packages/network/tests/provider/helpers/provider-internal-wallets/base-wallet/provider-internal-base-wallet.unit.test.ts b/packages/network/tests/provider/helpers/provider-internal-wallets/base-wallet/provider-internal-base-wallet.unit.test.ts index 8d54c56fc..d97d786aa 100644 --- a/packages/network/tests/provider/helpers/provider-internal-wallets/base-wallet/provider-internal-base-wallet.unit.test.ts +++ b/packages/network/tests/provider/helpers/provider-internal-wallets/base-wallet/provider-internal-base-wallet.unit.test.ts @@ -169,9 +169,8 @@ describe('Base wallet tests', () => { // Initialize delegator const delegators: SignTransactionOptions[] = [ { - delegatorPrivateKey: Hex.of( - await Secp256k1.generatePrivateKey() - ).digits + delegatorPrivateKey: Hex.of(Secp256k1.generatePrivateKey()) + .digits }, { delegatorUrl: