-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: removed redundant crypto functionality (#3075)
* chore: removed redundant crypto functionality * chore: changeset
- Loading branch information
1 parent
a059ea1
commit 482bbf0
Showing
8 changed files
with
11 additions
and
150 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@fuel-ts/crypto": patch | ||
"@fuel-ts/errors": patch | ||
--- | ||
|
||
chore: removed redundant crypto functionality |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,12 @@ | ||
import { FuelError, ErrorCode } from '@fuel-ts/errors'; | ||
import type { BytesLike } from '@fuel-ts/interfaces'; | ||
import { arrayify, hexlify } from '@fuel-ts/utils'; | ||
import { createHmac } from 'crypto'; | ||
|
||
let locked = false; | ||
|
||
const COMPUTEHMAC = ( | ||
algorithm: 'sha256' | 'sha512', | ||
key: Uint8Array, | ||
data: Uint8Array | ||
): BytesLike => createHmac(algorithm, key).update(data).digest(); | ||
|
||
let computeHMAC = COMPUTEHMAC; | ||
|
||
export function computeHmac( | ||
algorithm: 'sha256' | 'sha512', | ||
_key: Uint8Array, | ||
_data: Uint8Array | ||
): string { | ||
const key = arrayify(_key, 'key'); | ||
const data = arrayify(_data, 'data'); | ||
return hexlify(computeHMAC(algorithm, key, data)); | ||
return hexlify(createHmac(algorithm, key).update(data).digest()); | ||
} | ||
computeHmac._ = COMPUTEHMAC; | ||
computeHmac.lock = () => { | ||
locked = true; | ||
}; | ||
computeHmac.register = ( | ||
func: (algorithm: 'sha256' | 'sha512', key: Uint8Array, data: Uint8Array) => BytesLike | ||
) => { | ||
if (locked) { | ||
throw new FuelError(ErrorCode.HASHER_LOCKED, 'computeHmac is locked'); | ||
} | ||
computeHMAC = func; | ||
}; | ||
Object.freeze(computeHmac); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,8 @@ | ||
import { ErrorCode, FuelError } from '@fuel-ts/errors'; | ||
import type { BytesLike } from '@fuel-ts/interfaces'; | ||
import { arrayify } from '@fuel-ts/utils'; | ||
import { ripemd160 as noble_ripemd160 } from '@noble/hashes/ripemd160'; | ||
|
||
let locked = false; | ||
|
||
const helper = (data: Uint8Array): Uint8Array => noble_ripemd160(data); | ||
|
||
let ripemd: (data: Uint8Array) => Uint8Array = helper; | ||
|
||
export function ripemd160(_data: BytesLike): Uint8Array { | ||
const data = arrayify(_data, 'data'); | ||
return ripemd(data); | ||
return noble_ripemd160(data); | ||
} | ||
ripemd160._ = helper; | ||
ripemd160.lock = (): void => { | ||
locked = true; | ||
}; | ||
ripemd160.register = (func: (data: Uint8Array) => Uint8Array) => { | ||
if (locked) { | ||
throw new FuelError(ErrorCode.HASHER_LOCKED, 'ripemd160 is locked'); | ||
} | ||
ripemd = func; | ||
}; | ||
Object.freeze(ripemd160); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters