Skip to content

Commit

Permalink
fix: change blake impl
Browse files Browse the repository at this point in the history
  • Loading branch information
dawidsowardx committed Nov 14, 2024
1 parent 6a2b390 commit 6873211
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 47 deletions.
46 changes: 6 additions & 40 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,13 @@
"@mui/material": "^5.14.0",
"@noble/curves": "^1.4.0",
"@radixdlt/babylon-gateway-api-sdk": "^1.2.7",
"@radixdlt/radix-connect-webrtc": "1.2.2-csp.1",
"@radixdlt/radix-dapp-toolkit": "2.2.0-dev.10",
"@radixdlt/radix-connect-webrtc": "^1.2.1",
"@stitches/react": "^1.2.8",
"@types/blake2b": "^2.1.0",
"bech32": "^2.0.0",
"bip32": "^2.0.0",
"bip39": "^3.1.0",
"blake2b": "^2.1.4",
"blakejs": "^1.2.1",
"buffer": "^6.0.3",
"ed25519-hd-key": "^1.3.0",
"elliptic": "^6.5.4",
Expand Down
10 changes: 6 additions & 4 deletions src/crypto/blake2b.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Buffer } from 'buffer'
import blake2bHash from 'blake2b'
import blake from 'blakejs'
import { errAsync, okAsync, ResultAsync } from 'neverthrow'

export const blake2b = (input: Buffer): ResultAsync<Buffer, Error> => {
const output = new Uint8Array(32)
try {
return okAsync(
blake2bHash(output.length).update(new Uint8Array(input)).digest('hex'),
).map((hex) => Buffer.from(hex, 'hex'))
blake.blake2b(new Uint8Array(input), undefined, output.length),
).map((hex) => Buffer.from(hex))
} catch (error) {
return errAsync(error as Error)
}
Expand All @@ -17,4 +17,6 @@ export const blakeHashHexSync = (data: string) =>
blakeHashBufferToHex(Buffer.from(data, 'hex'))

export const blakeHashBufferToHex = (buffer: Buffer) =>
blake2bHash(32).update(new Uint8Array(buffer)).digest('hex')
Buffer.from(blake.blake2b(new Uint8Array(buffer), undefined, 32)).toString(
'hex',
)

0 comments on commit 6873211

Please sign in to comment.