From ca1a4e0cc7452724e703a6530c2e56112c307b66 Mon Sep 17 00:00:00 2001 From: alvrs Date: Tue, 17 May 2022 14:23:04 +0100 Subject: [PATCH] feat(@mud/utils): add keccak256 hash function that accepts string inputs --- packages/utils/package.json | 4 +++- packages/utils/src/hash.ts | 5 +++++ packages/utils/src/index.ts | 1 + yarn.lock | 33 ++++++++------------------------- 4 files changed, 17 insertions(+), 26 deletions(-) create mode 100644 packages/utils/src/hash.ts diff --git a/packages/utils/package.json b/packages/utils/package.json index f8fd82ed44..b6a5a91434 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -12,6 +12,7 @@ "@rollup/plugin-node-resolve": "^13.1.3", "@rollup/plugin-typescript": "^8.3.1", "@types/jest": "^27.4.1", + "ethers": "^5.6.6", "jest": "^27.5.1", "mobx": "^6.5.0", "proxy-deep": "^3.1.1", @@ -27,6 +28,7 @@ "peerDependencies": { "mobx": "^6.5.0", "proxy-deep": "^3.1.1", - "rxjs": "^7.5.5" + "rxjs": "^7.5.5", + "ethers": "^5.6.6" } } diff --git a/packages/utils/src/hash.ts b/packages/utils/src/hash.ts new file mode 100644 index 0000000000..ad53e3828a --- /dev/null +++ b/packages/utils/src/hash.ts @@ -0,0 +1,5 @@ +import { keccak256 as keccak256Bytes, toUtf8Bytes } from "ethers/lib/utils"; + +export function keccak256(data: string) { + return keccak256Bytes(toUtf8Bytes(data)); +} diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index 363deac8e4..c79bb4b35f 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -12,5 +12,6 @@ export * from "./promise"; export * from "./sleep"; export * from "./iterable"; export * from "./area"; +export * from "./hash"; export type { Cached, PromiseValue, ValueOf, Area, Coord } from "./types"; diff --git a/yarn.lock b/yarn.lock index 7400bcb779..c790add7a7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2530,12 +2530,12 @@ resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.5.tgz#5f19d2b85a98e9558036f6a3cacc8819420f05cf" integrity sha512-JCB8C6SnDoQf0cNycqd/35A7MjcnK+ZTqE7judS6o7utxUCg6imJg3QK2qzHKszlTjcj2cn+NwMB2i96ubpj7w== -"@types/react-dom@^17.0.14": - version "17.0.17" - resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-17.0.17.tgz#2e3743277a793a96a99f1bf87614598289da68a1" - integrity sha512-VjnqEmqGnasQKV0CWLevqMTXBYG9GbwuE6x3VetERLh0cq2LTptFE73MrQi2S7GkKXCf2GgwItB/melLnxfnsg== +"@types/react-dom@^18.0.4": + version "18.0.4" + resolved "https://registry.yarnpkg.com/@types/react-dom/-/react-dom-18.0.4.tgz#dcbcadb277bcf6c411ceff70069424c57797d375" + integrity sha512-FgTtbqPOCI3dzZPZoC2T/sx3L34qxy99ITWn4eoSA95qPyXDMH0ALoAqUp49ITniiJFsXUVBtalh/KffMpg21Q== dependencies: - "@types/react" "^17" + "@types/react" "*" "@types/react@*": version "18.0.9" @@ -2546,7 +2546,7 @@ "@types/scheduler" "*" csstype "^3.0.2" -"@types/react@^17", "@types/react@^17.0.43": +"@types/react@^17.0.43": version "17.0.45" resolved "https://registry.yarnpkg.com/@types/react/-/react-17.0.45.tgz#9b3d5b661fd26365fefef0e766a1c6c30ccf7b3f" integrity sha512-YfhQ22Lah2e3CHPsb93tRwIGNiSwkuz1/blk4e6QrWS0jQzCSNbGLtOEYhPg02W0yGTTmpajp7dCTbBAMN3qsg== @@ -3360,14 +3360,6 @@ buffer@^5.5.0, buffer@^5.6.0: base64-js "^1.3.1" ieee754 "^1.1.13" -buffer@^6.0.3: - version "6.0.3" - resolved "https://registry.yarnpkg.com/buffer/-/buffer-6.0.3.tgz#2ace578459cc8fbe2a70aaa8f52ee63b6a74c6c6" - integrity sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA== - dependencies: - base64-js "^1.3.1" - ieee754 "^1.2.1" - builtin-modules@^3.0.0: version "3.3.0" resolved "https://registry.yarnpkg.com/builtin-modules/-/builtin-modules-3.3.0.tgz#cae62812b89801e9656336e46223e030386be7b6" @@ -6039,7 +6031,7 @@ iconv-lite@^0.6.2: dependencies: safer-buffer ">= 2.1.2 < 3.0.0" -ieee754@^1.1.13, ieee754@^1.2.1: +ieee754@^1.1.13: version "1.2.1" resolved "https://registry.yarnpkg.com/ieee754/-/ieee754-1.2.1.tgz#8eb7a10a63fff25d15a57b001586d177d1b0d352" integrity sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA== @@ -7122,16 +7114,7 @@ jsprim@^2.0.2: json-schema "0.4.0" verror "1.10.0" -keccak256@^1.0.6: - version "1.0.6" - resolved "https://registry.yarnpkg.com/keccak256/-/keccak256-1.0.6.tgz#dd32fb771558fed51ce4e45a035ae7515573da58" - integrity sha512-8GLiM01PkdJVGUhR1e6M/AvWnSqYS0HaERI+K/QtStGDGlSTx2B1zTqZk4Zlqu5TxHJNTxWAdP9Y+WI50OApUw== - dependencies: - bn.js "^5.2.0" - buffer "^6.0.3" - keccak "^3.0.2" - -keccak@^3.0.0, keccak@^3.0.2: +keccak@^3.0.0: version "3.0.2" resolved "https://registry.yarnpkg.com/keccak/-/keccak-3.0.2.tgz#4c2c6e8c54e04f2670ee49fa734eb9da152206e0" integrity sha512-PyKKjkH53wDMLGrvmRGSNWgmSxZOUqbnXwKL9tmgbFYA1iAYqW21kfR7mZXV0MlESiefxQQE9X9fTa3X+2MPDQ==