Skip to content

Commit

Permalink
fix hash contract imports after renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
marcuspoehls committed Nov 3, 2023
1 parent 219ccdc commit 7d0a661
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
10 changes: 5 additions & 5 deletions packages/hashing/src/base-hasher.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

import { HashBuilder } from './hash-builder.js'
import Crypto, { BinaryLike, Encoding, Hash } from 'node:crypto'
import { BaseHasher as BaseHasherContract, HashBuilderCallback, HashBuilderOptions } from '@supercharge/contracts'
import { BaseHasher as BaseHasherContract, HashBuilderCallback, HashBuilderConfig } from '@supercharge/contracts'

export class BaseHasher implements BaseHasherContract {
/**
Expand Down Expand Up @@ -56,13 +56,13 @@ export class BaseHasher implements BaseHasherContract {
}

if (typeof inputEncodingOrHashBuilder === 'function') {
const hashBuilderOptions: HashBuilderOptions = { outputEncoding: 'base64' }
const builder = new HashBuilder(hashBuilderOptions)
const hashBuilderConfig: HashBuilderConfig = { outputEncoding: 'base64' }
const builder = new HashBuilder(hashBuilderConfig)
inputEncodingOrHashBuilder(builder)

return this
.createHash(algorithm, input, hashBuilderOptions.inputEncoding)
.digest(hashBuilderOptions.outputEncoding)
.createHash(algorithm, input, hashBuilderConfig.inputEncoding)
.digest(hashBuilderConfig.outputEncoding)
}

return this
Expand Down
28 changes: 20 additions & 8 deletions packages/hashing/src/hash-builder.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,38 @@

import { HashBuilder as HashBuilderContract, HashBuilderOptions } from '@supercharge/contracts'
import { BinaryToTextEncoding, Encoding } from 'crypto'
import { BinaryToTextEncoding, Encoding } from 'node:crypto'
import { HashBuilder as HashBuilderContract, HashBuilderConfig } from '@supercharge/contracts'

export class HashBuilder implements HashBuilderContract {
/**
* Stores the hash builder options.
* Stores the hash builder config.
*/
private readonly options: HashBuilderOptions
private readonly config: HashBuilderConfig

constructor (options: HashBuilderOptions) {
this.options = options
/**
* Create a new instance.
*/
constructor (options: HashBuilderConfig) {
this.config = options
}

/**
* Set the input encoding for the related value.
*/
inputEncoding (inputEncoding: Encoding): this {
this.options.inputEncoding = inputEncoding
this.config.inputEncoding = inputEncoding
return this
}

/**
* Calculate the final hash string value.
*/
digest (encoding: BinaryToTextEncoding): void {
this.options.outputEncoding = encoding
this.config.outputEncoding = encoding
}

/**
* This is an alias for the `digest` method that calculates the final hash string.
*/
toString (encoding: BinaryToTextEncoding): void {
this.digest(encoding)
}
Expand Down

0 comments on commit 7d0a661

Please sign in to comment.