Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop fnv-plus, handwrite fnv-hash #16

Merged
merged 1 commit into from
Jan 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions build/main.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,8 @@

Object.defineProperty(exports, '__esModule', { value: true });

var fnv = require('fnv-plus');
var ffjavascript = require('ffjavascript');

function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }

var fnv__default = /*#__PURE__*/_interopDefaultLegacy(fnv);

/*

Copyright 2020 0KIMS association.
Expand Down Expand Up @@ -44,7 +39,17 @@ function flatArray(a) {
}

function fnvHash(str) {
return fnv__default['default'].hash(str, 64).hex();
const uint64_max = BigInt(2) ** BigInt(64);
let hash = BigInt("0xCBF29CE484222325");
for (var i = 0; i < str.length; i++) {
hash ^= BigInt(str[i].charCodeAt());
hash *= BigInt(0x100000001B3);
hash %= uint64_max;
}
let shash = hash.toString(16);
let n = 16 - shash.length;
shash = '0'.repeat(n).concat(shash);
return shash;
}

/* globals WebAssembly */
Expand Down
14 changes: 11 additions & 3 deletions js/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ limitations under the License.

*/

import fnv from "fnv-plus";

export function flatArray(a) {
var res = [];
fillArray(res, a);
Expand All @@ -35,5 +33,15 @@ export function flatArray(a) {
}

export function fnvHash(str) {
return fnv.hash(str, 64).hex();
const uint64_max = BigInt(2) ** BigInt(64);
let hash = BigInt("0xCBF29CE484222325");
for (var i = 0; i < str.length; i++) {
hash ^= BigInt(str[i].charCodeAt());
hash *= BigInt(0x100000001B3);
hash %= uint64_max;
}
let shash = hash.toString(16);
let n = 16 - shash.length;
shash = '0'.repeat(n).concat(shash);
return shash;
}
13 changes: 1 addition & 12 deletions package-lock.json

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

3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@
},
"homepage": "https://github.com/iden3/circom_runtime#readme",
"dependencies": {
"ffjavascript": "0.2.39",
"fnv-plus": "^1.3.1"
"ffjavascript": "0.2.39"
},
"devDependencies": {
"eslint": "^6.8.0",
Expand Down