Skip to content

Commit

Permalink
refactor: 1115 Hash implementations moved in vcdm (#1245)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucanicoladebiasi authored Sep 6, 2024
1 parent ce7e896 commit de75861
Show file tree
Hide file tree
Showing 18 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/certificate/certificate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CertificateSignature } from '@vechain/sdk-errors';
import fastJsonStableStringify from 'fast-json-stable-stringify';
import { Blake2b256 } from '../hash';
import { Blake2b256 } from '../vcdm/hash/Blake2b256';
import { secp256k1 } from '../secp256k1';
import { Address, Hex, Txt } from '../vcdm';
import { type Certificate } from './types';
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export * from './certificate';
export * from './clause';
export * from './contract';
export * from './encoding';
export * from './hash';
export * from './vcdm/hash/Hash';
export * from './hdkey';
export * from './keystore';
export * from './secp256k1';
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/hdkey/HDKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
InvalidSecp256k1PrivateKey
} from '@vechain/sdk-errors';
import { HexUInt } from '../vcdm/HexUInt';
import { Sha256 } from '../hash';
import { Sha256 } from '../vcdm/hash/Sha256';
import { FPN } from '../vcdm';

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ctr } from '@noble/ciphers/aes';
import * as n_utils from '@noble/curves/abstract/utils';
import { scrypt } from '@noble/hashes/scrypt';
import { InvalidKeystoreParams, stringifyData } from '@vechain/sdk-errors';
import { Keccak256 } from '../../../hash';
import { Keccak256 } from '../../../vcdm/hash/Keccak256';
import { secp256k1 } from '../../../secp256k1';
import { Address, Hex } from '../../../vcdm';
import { type Keystore, type KeystoreAccount } from '../../types';
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/secp256k1/secp256k1.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as n_utils from '@noble/curves/abstract/utils';
import { Hex } from '../vcdm/Hex';
import { Hex } from '../vcdm';
import { SIGNATURE_LENGTH } from '../utils';
import { randomBytes as _randomBytes } from '@noble/hashes/utils';
import { secp256k1 as n_secp256k1 } from '@noble/curves/secp256k1';
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/transaction/transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
UnavailableTransactionField
} from '@vechain/sdk-errors';
import { type RLPValidObject } from '../encoding';
import { Blake2b256 } from '../hash';
import { Blake2b256 } from '../vcdm/hash/Blake2b256';
import { secp256k1 } from '../secp256k1';
import {
BLOCK_REF_LENGTH,
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/vcdm/Address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
InvalidHDKey,
InvalidSecp256k1PrivateKey
} from '@vechain/sdk-errors';
import { Keccak256 } from '../hash';
import { Keccak256 } from './hash/Keccak256';
import { HDKey } from '../hdkey';
import { secp256k1 } from '../secp256k1';
import { Hex } from './Hex';
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/vcdm/BloomFilter.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as nc_utils from '@noble/curves/abstract/utils';
import { Blake2b256 } from '../hash';
import { Blake2b256 } from './hash/Blake2b256';
import { Hex } from './Hex';
import { InvalidDataType, InvalidOperation } from '@vechain/sdk-errors';
import { type VeChainDataModel } from './VeChainDataModel';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { blake2b as nh_blake2b } from '@noble/hashes/blake2b';
import { InvalidOperation } from '@vechain/sdk-errors';
import { Hex, Txt, type Hash } from '../vcdm';
import { HexUInt } from '../vcdm/HexUInt';
import { Hex, Txt, type Hash } from '../index';
import { HexUInt } from '../HexUInt';

/**
* Represents the result of an [BLAKE](https://en.wikipedia.org/wiki/BLAKE_(hash_function)) [BlAKE2B 256](https://www.blake2.net/) hash operation.
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { keccak_256 as nh_keccak_256 } from '@noble/hashes/sha3';
import { InvalidOperation } from '@vechain/sdk-errors';
import { Hex, Txt, type Hash } from '../vcdm';
import { HexUInt } from '../vcdm/HexUInt';
import { Hex, Txt, type Hash } from '../index';
import { HexUInt } from '../HexUInt';

/**
* Represents the result of an [SHA-3](https://en.wikipedia.org/wiki/SHA-3) [KECCAK 256](https://keccak.team/keccak.html) hash operation.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as nh_sha256 from '@noble/hashes/sha256';
import { InvalidOperation } from '@vechain/sdk-errors';
import { Hex, Txt, type Hash } from '../vcdm';
import { HexUInt } from '../vcdm/HexUInt';
import { Hex, Txt, type Hash } from '../index';
import { HexUInt } from '../HexUInt';

/**
* Represents the result of an [SHA256](https://en.wikipedia.org/wiki/SHA-2) hash operation.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './Blake2b256';
export * from './Hash';
export * from './Keccak256';
export * from './Sha256';
2 changes: 1 addition & 1 deletion packages/core/src/vcdm/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export * from './Address';
export * from './BloomFilter';
export * from './Currency';
export * from './FPN';
export * from './Hash';
export * from './hash';
export * from './Hex';
export * from './HexInt';
export * from './HexUInt';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, test } from '@jest/globals';
import { bytesToHex } from '@noble/hashes/utils';
import { InvalidOperation } from '@vechain/sdk-errors';
import { blake2b256, Blake2b256, Hex } from '../../src';
import { blake2b256, Blake2b256, Hex } from '../../../src';
import { CONTENT, NO_CONTENT } from './fixture';

// Hex on purpose because it must be equal to the returned HexUInt hash.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, test } from '@jest/globals';
import { bytesToHex } from '@noble/hashes/utils';
import { InvalidOperation } from '@vechain/sdk-errors';
import { Hex, Keccak256, keccak256 } from '../../src';
import { Hex, Keccak256, keccak256 } from '../../../src';
import { CONTENT, NO_CONTENT } from './fixture';

// Hex on purpose because it must be equal to the returned HexUInt hash.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { describe, expect, test } from '@jest/globals';
import { bytesToHex } from '@noble/hashes/utils';
import { InvalidOperation } from '@vechain/sdk-errors';
import { Hex, sha256, Sha256 } from '../../src';
import { Hex, sha256, Sha256 } from '../../../src';
import { CONTENT, NO_CONTENT } from './fixture';

// Hex on purpose because it must be equal to the returned HexUInt hash.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Hex, Txt } from '../../src';
import { Hex, Txt } from '../../../src';

const CONTENT = Hex.of(
Txt.of('Hello world - Здравствуйте - こんにちは!').bytes
Expand Down

1 comment on commit de75861

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test Coverage

Summary

Lines Statements Branches Functions
Coverage: 99%
99.5% (4039/4059) 98.2% (1259/1282) 99.87% (807/808)
Title Tests Skipped Failures Errors Time
core 804 0 💤 0 ❌ 0 🔥 1m 32s ⏱️
network 643 0 💤 0 ❌ 0 🔥 4m 4s ⏱️
errors 42 0 💤 0 ❌ 0 🔥 14.613s ⏱️

Please sign in to comment.