Skip to content

Commit

Permalink
fix: remove hash helpers error constant
Browse files Browse the repository at this point in the history
  • Loading branch information
rodolfopietro97 committed Oct 30, 2023
1 parent a92290c commit e543738
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 34 deletions.
8 changes: 6 additions & 2 deletions packages/core/src/hash/blake2b256.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import blake from 'blakejs';
import { type HashInput, type ReturnType } from './types';
import { createInvalidReturnTypeError, isValidReturnType } from './helpers';
import { isValidReturnType } from './helpers';
import { buildError, DATA } from '@vechain-sdk/errors';

/**
* Internal function to compute the blake2b256 256-bit hash of the given data.
Expand Down Expand Up @@ -73,7 +74,10 @@ function blake2b256(
returnType: ReturnType = 'buffer'
): Buffer | string {
if (!isValidReturnType(returnType)) {
throw createInvalidReturnTypeError();
throw buildError(
DATA.INVALID_DATA_RETURN_TYPE,
"Invalid return type. Return type should be either 'buffer' or 'hex'"
);
}

// Converts the data to an array of Buffer or string
Expand Down
27 changes: 0 additions & 27 deletions packages/core/src/hash/helpers/hashhelpers.ts

This file was deleted.

1 change: 0 additions & 1 deletion packages/core/src/hash/helpers/index.ts

This file was deleted.

8 changes: 6 additions & 2 deletions packages/core/src/hash/keccak256.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ethers } from 'ethers';
import { type ReturnType, type HashInput } from './types';
import { createInvalidReturnTypeError, isValidReturnType } from './helpers';
import { isValidReturnType } from './helpers';
import { buildError, DATA } from '@vechain-sdk/errors';

/* --- Overloaded functions start --- */

Expand Down Expand Up @@ -52,7 +53,10 @@ function keccak256(
returnType: ReturnType = 'buffer'
): Buffer | string {
if (!isValidReturnType(returnType)) {
throw createInvalidReturnTypeError();
throw buildError(
DATA.INVALID_DATA_RETURN_TYPE,
"Invalid return type. Return type should be either 'buffer' or 'hex'"
);
}

const hash = ethers.isBytesLike(data)
Expand Down
8 changes: 6 additions & 2 deletions packages/core/src/hash/sha256.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ethers } from 'ethers';
import { type ReturnType, type HashInput } from './types';
import { createInvalidReturnTypeError, isValidReturnType } from './helpers';
import { isValidReturnType } from './helpers';
import { buildError, DATA } from '@vechain-sdk/errors';

/* --- Overloaded functions start --- */

Expand Down Expand Up @@ -51,7 +52,10 @@ function sha256(
returnType: ReturnType = 'buffer'
): Buffer | string {
if (!isValidReturnType(returnType)) {
throw createInvalidReturnTypeError();
throw buildError(
DATA.INVALID_DATA_RETURN_TYPE,
"Invalid return type. Return type should be either 'buffer' or 'hex'"
);
}

const hash = ethers.isBytesLike(data)
Expand Down

0 comments on commit e543738

Please sign in to comment.