mirror of
https://github.com/privacy-scaling-explorations/zk-kit.git
synced 2026-04-22 03:00:15 -04:00
Merge pull request #25 from vivianjeng/main
chore: use `crypto-js/sha256` instead of `js-sha256` Former-commit-id: 10e54e109a46ec22de5b827033fa819b9a24bb90 [formerly b487f2c308d2763ad9b345a6fa32d3227a1e83cd] [formerly c00d46d4343054da40d7ec2cc62e75537c423612 [formerly 7ef81456ac034f111ffa1dbe71e55fde41aa6112]] [formerly 604ce6e5620eaafd01a539aa7b308af8cc07d136 [formerly b015f92a4c524e6e82ce67ea64fafbd587bd1750] [formerly 2e949690bf797bd69e19c92c2016652b9f396986 [formerly d062966077e4ffdbf78b28c151e9ecd61fc515f2]]] Former-commit-id: dbf7e4660322a2b959c1eb8aa503211f80678bed [formerly aef91c9371ff8f17ba36bda05ce57b85b23bf958] [formerly 362bdeaf51799141f6eccca5bf0180fd718b63e4 [formerly 96bea1bdf2072eb8366400fad59ae17b3718879b]] Former-commit-id: 877aad73f86be626c4a809a37f9466e41c9271a8 [formerly bb1fa13f7913a0cc85f7d7e75c653db09e7b970e] Former-commit-id: 6019a77c3db8b4136880070956ebebfbda8469ad
This commit is contained in:
@@ -31,6 +31,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@rollup/plugin-typescript": "^8.3.0",
|
||||
"@types/crypto-js": "^4.1.1",
|
||||
"rollup-plugin-cleanup": "^3.2.1",
|
||||
"typedoc": "^0.22.11"
|
||||
},
|
||||
@@ -38,6 +39,6 @@
|
||||
"@ethersproject/bignumber": "^5.5.0",
|
||||
"@ethersproject/random": "^5.5.1",
|
||||
"circomlibjs": "0.0.8",
|
||||
"js-sha256": "^0.9.0"
|
||||
"crypto-js": "^4.1.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { BigNumber } from "@ethersproject/bignumber"
|
||||
import { randomBytes } from "@ethersproject/random"
|
||||
import { sha256 as _sha256 } from "js-sha256"
|
||||
import _sha256 from "crypto-js/sha256"
|
||||
|
||||
/**
|
||||
* Returns an hexadecimal sha256 hash of the message passed as parameter.
|
||||
@@ -8,11 +8,9 @@ import { sha256 as _sha256 } from "js-sha256"
|
||||
* @returns The hexadecimal hash of the message.
|
||||
*/
|
||||
export function sha256(message: string): string {
|
||||
const hash = _sha256.create()
|
||||
const hash = _sha256(message)
|
||||
|
||||
hash.update(message)
|
||||
|
||||
return hash.hex()
|
||||
return hash.toString()
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -245,6 +245,11 @@
|
||||
dependencies:
|
||||
"@types/node" "*"
|
||||
|
||||
"@types/crypto-js@^4.1.1":
|
||||
version "4.1.1"
|
||||
resolved "https://registry.yarnpkg.com/@types/crypto-js/-/crypto-js-4.1.1.tgz#602859584cecc91894eb23a4892f38cfa927890d"
|
||||
integrity sha512-BG7fQKZ689HIoc5h+6D2Dgq1fABRa0RbBWKBd9SP/MVRVXROflpm5fhwyATX5duFmbStzyzyycPB8qUYKDH3NA==
|
||||
|
||||
"@types/estree@0.0.39":
|
||||
version "0.0.39"
|
||||
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.39.tgz#e177e699ee1b8c22d23174caaa7422644389509f"
|
||||
@@ -752,6 +757,11 @@ crypto-browserify@3.12.0:
|
||||
randombytes "^2.0.0"
|
||||
randomfill "^1.0.3"
|
||||
|
||||
crypto-js@^4.1.1:
|
||||
version "4.1.1"
|
||||
resolved "https://registry.yarnpkg.com/crypto-js/-/crypto-js-4.1.1.tgz#9e485bcf03521041bd85844786b83fb7619736cf"
|
||||
integrity sha512-o2JlM7ydqd3Qk9CA0L4NL6mTzU2sdx96a+oOfPu8Mkl/PK51vSyoi8/rQ8NknZtk44vq15lmhAj9CIAGwgeWKw==
|
||||
|
||||
d@1, d@^1.0.1:
|
||||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/d/-/d-1.0.1.tgz#8698095372d58dbee346ffd0c7093f99f8f9eb5a"
|
||||
@@ -1618,11 +1628,6 @@ js-cleanup@^1.2.0:
|
||||
perf-regexes "^1.0.1"
|
||||
skip-regex "^1.0.2"
|
||||
|
||||
js-sha256@^0.9.0:
|
||||
version "0.9.0"
|
||||
resolved "https://registry.yarnpkg.com/js-sha256/-/js-sha256-0.9.0.tgz#0b89ac166583e91ef9123644bd3c5334ce9d0966"
|
||||
integrity sha512-sga3MHh9sgQN2+pJ9VYZ+1LPwXOxuBJBA5nrR5/ofPfuiJBE2hnjsaN8se8JznOmGLN2p49Pe5U/ttafcs/apA==
|
||||
|
||||
js-sha3@0.8.0, js-sha3@^0.8.0:
|
||||
version "0.8.0"
|
||||
resolved "https://registry.yarnpkg.com/js-sha3/-/js-sha3-0.8.0.tgz#b9b7a5da73afad7dedd0f8c463954cbde6818840"
|
||||
|
||||
@@ -90,11 +90,11 @@ or [JSDelivr](https://www.jsdelivr.com/):
|
||||
|
||||
```typescript
|
||||
import { SparseMerkleTree } from "@zk-kit/sparse-merkle-tree"
|
||||
import { sha256 } from "js-sha256"
|
||||
import sha256 from "crypto-js/sha256"
|
||||
import { poseidon } from "circomlibjs"
|
||||
|
||||
// Hexadecimal hashes.
|
||||
const hash = (childNodes: ChildNodes) => sha256(childNodes.join(""))
|
||||
const hash = (childNodes: ChildNodes) => sha256(childNodes.join("")).toString()
|
||||
const tree = new SparseMerkleTree(hash)
|
||||
|
||||
// Big number hashes.
|
||||
|
||||
@@ -41,7 +41,8 @@
|
||||
"devDependencies": {
|
||||
"@rollup/plugin-typescript": "^8.3.0",
|
||||
"circomlibjs": "^0.0.8",
|
||||
"js-sha256": "^0.9.0",
|
||||
"crypto-js": "^4.1.1",
|
||||
"@types/crypto-js": "^4.1.1",
|
||||
"rollup-plugin-cleanup": "^3.2.1",
|
||||
"rollup-plugin-terser": "^7.0.2",
|
||||
"typedoc": "^0.22.11"
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { poseidon, smt } from "circomlibjs"
|
||||
import { sha256 } from "js-sha256"
|
||||
import sha256 from "crypto-js/sha256"
|
||||
import { ChildNodes, SparseMerkleTree } from "../src"
|
||||
|
||||
describe("Sparse Merkle tree", () => {
|
||||
const hash = (childNodes: ChildNodes) => sha256(childNodes.join(""))
|
||||
const hash = (childNodes: ChildNodes) => sha256(childNodes.join("")).toString()
|
||||
const testKeys = ["a", "3", "2b", "20", "9", "17"]
|
||||
|
||||
describe("Create hexadecimal trees", () => {
|
||||
@@ -177,7 +177,7 @@ describe("Sparse Merkle tree", () => {
|
||||
})
|
||||
|
||||
it("Should not create a big number tree if the hash function does not return a big number", () => {
|
||||
const hash = (childNodes: ChildNodes) => sha256(childNodes.join(""))
|
||||
const hash = (childNodes: ChildNodes) => sha256(childNodes.join("")).toString()
|
||||
|
||||
const fun = () => new SparseMerkleTree(hash, true)
|
||||
|
||||
|
||||
@@ -258,6 +258,11 @@
|
||||
dependencies:
|
||||
"@types/node" "*"
|
||||
|
||||
"@types/crypto-js@^4.1.1":
|
||||
version "4.1.1"
|
||||
resolved "https://registry.yarnpkg.com/@types/crypto-js/-/crypto-js-4.1.1.tgz#602859584cecc91894eb23a4892f38cfa927890d"
|
||||
integrity sha512-BG7fQKZ689HIoc5h+6D2Dgq1fABRa0RbBWKBd9SP/MVRVXROflpm5fhwyATX5duFmbStzyzyycPB8qUYKDH3NA==
|
||||
|
||||
"@types/estree@0.0.39":
|
||||
version "0.0.39"
|
||||
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.39.tgz#e177e699ee1b8c22d23174caaa7422644389509f"
|
||||
@@ -803,6 +808,11 @@ crypto-browserify@3.12.0:
|
||||
randombytes "^2.0.0"
|
||||
randomfill "^1.0.3"
|
||||
|
||||
crypto-js@^4.1.1:
|
||||
version "4.1.1"
|
||||
resolved "https://registry.yarnpkg.com/crypto-js/-/crypto-js-4.1.1.tgz#9e485bcf03521041bd85844786b83fb7619736cf"
|
||||
integrity sha512-o2JlM7ydqd3Qk9CA0L4NL6mTzU2sdx96a+oOfPu8Mkl/PK51vSyoi8/rQ8NknZtk44vq15lmhAj9CIAGwgeWKw==
|
||||
|
||||
d@1, d@^1.0.1:
|
||||
version "1.0.1"
|
||||
resolved "https://registry.yarnpkg.com/d/-/d-1.0.1.tgz#8698095372d58dbee346ffd0c7093f99f8f9eb5a"
|
||||
@@ -1693,11 +1703,6 @@ js-cleanup@^1.2.0:
|
||||
perf-regexes "^1.0.1"
|
||||
skip-regex "^1.0.2"
|
||||
|
||||
js-sha256@^0.9.0:
|
||||
version "0.9.0"
|
||||
resolved "https://registry.yarnpkg.com/js-sha256/-/js-sha256-0.9.0.tgz#0b89ac166583e91ef9123644bd3c5334ce9d0966"
|
||||
integrity sha512-sga3MHh9sgQN2+pJ9VYZ+1LPwXOxuBJBA5nrR5/ofPfuiJBE2hnjsaN8se8JznOmGLN2p49Pe5U/ttafcs/apA==
|
||||
|
||||
js-sha3@0.8.0, js-sha3@^0.8.0:
|
||||
version "0.8.0"
|
||||
resolved "https://registry.yarnpkg.com/js-sha3/-/js-sha3-0.8.0.tgz#b9b7a5da73afad7dedd0f8c463954cbde6818840"
|
||||
|
||||
Reference in New Issue
Block a user