Skip to content

Commit

Permalink
feat(hash): add BLAKE3 hash support (#994)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyBanks authored Jul 1, 2021
1 parent 01af5fa commit f4496b7
Show file tree
Hide file tree
Showing 7 changed files with 270 additions and 171 deletions.
1 change: 1 addition & 0 deletions hash/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,4 @@ Following algorithms are supported.
- keccak256
- keccak384
- keccak512
- blake3
58 changes: 58 additions & 0 deletions hash/_wasm/Cargo.lock

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

1 change: 1 addition & 0 deletions hash/_wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ sha-1 = "0.9.1"
sha2 = "0.9.1"
sha3 = "0.9.1"
wasm-bindgen = "0.2.68"
blake3 = "0.3.8"

[profile.release]
lto = true
Expand Down
1 change: 1 addition & 0 deletions hash/_wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ pub fn create_hash(algorithm: &str) -> Result<DenoHash, JsValue> {
"keccak256" => Some(Box::new(sha3::Keccak256::new())),
"keccak384" => Some(Box::new(sha3::Keccak384::new())),
"keccak512" => Some(Box::new(sha3::Keccak512::new())),
"blake3" => Some(Box::new(blake3::Hasher::new())),
_ => None,
};

Expand Down
323 changes: 153 additions & 170 deletions hash/_wasm/wasm.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions hash/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export const supportedAlgorithms = [
"keccak256",
"keccak384",
"keccak512",
"blake3",
] as const;
export type SupportedAlgorithm = typeof supportedAlgorithms[number];
/**
Expand Down
56 changes: 55 additions & 1 deletion hash/test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,30 @@ const testSetHex: Record<string, string[][]> = {
"3c3a876da14034ab60627c077bb98f7e120a2a5370212dffb3385a18d4f38859ed311d0a9d5141ce9cc5c66ee689b266a8aa18ace8282a0e0db596c90b0a7b87",
],
],
blake3: [
["", "af1349b9f5f9a1a6a0404dea36dcc9499bcb25c9adc112b7cc9a93cae41f3262"],
["abc", "6437b3ac38465133ffb63b75273a8db548c558465d79db03fd359c6cd5bd9d85"],
[
"deno",
"e5dd810dd67713fab4438e17516c7ea13a35666900ece70a561184ff68de8d79",
],
[
"The quick brown fox jumps over the lazy dog",
"2f1514181aadccd913abd94cfa592701a5686ab23f8df1dff1b74710febc6d4a",
],
[
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"86dd7cd514f2b1f6aaa34688ead22746f453e9d9ddeeca1ef124477507aefc9f",
],
[
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"472c51290d607f100d2036fdcedd7590bba245e9adeb21364a063b7bb4ca81c7",
],
[
millionAs,
"616f575a1b58d4c9797d4217b9730ae5e6eb319d76edef6549b46f4efe31ff8b",
],
],
};

const testSetBase64: Record<string, string[][]> = {
Expand Down Expand Up @@ -281,6 +305,36 @@ const testSetBase64: Record<string, string[][]> = {
"PDqHbaFANKtgYnwHe7mPfhIKKlNwIS3/szhaGNTziFntMR0KnVFBzpzFxm7mibJmqKoYrOgoKg4NtZbJCwp7hw==",
],
],
blake3: [
[
"",
"rxNJufX5oaagQE3qNtzJSZvLJcmtwRK3zJqTyuQfMmI=",
],
[
"abc",
"ZDezrDhGUTP/tjt1JzqNtUjFWEZdedsD/TWcbNW9nYU=",
],
[
"deno",
"5d2BDdZ3E/q0Q44XUWx+oTo1ZmkA7OcKVhGE/2jejXk=",
],
[
"The quick brown fox jumps over the lazy dog",
"LxUUGBqtzNkTq9lM+lknAaVoarI/jfHf8bdHEP68bUo=",
],
[
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"ht181RTysfaqo0aI6tInRvRT6dnd7soe8SRHdQeu/J8=",
],
[
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
"RyxRKQ1gfxANIDb9zt11kLuiRemt6yE2SgY7e7TKgcc=",
],
[
millionAs,
"YW9XWhtY1Ml5fUIXuXMK5ebrMZ127e9lSbRvTv4x/4s=",
],
],
};

Deno.test("[hash/all/hex] testAllHex", () => {
Expand All @@ -292,7 +346,7 @@ Deno.test("[hash/all/hex] testAllHex", () => {
}
});

Deno.test("[hash/all/base64] testAllHex", () => {
Deno.test("[hash/all/base64] testAllBase64", () => {
for (const algorithm in testSetBase64) {
for (const [input, output] of testSetBase64[algorithm]) {
const hash = createHash(algorithm as SupportedAlgorithm);
Expand Down

0 comments on commit f4496b7

Please sign in to comment.