diff options
author | Florian Dold <florian.dold@gmail.com> | 2018-01-04 11:08:39 +0100 |
---|---|---|
committer | Florian Dold <florian.dold@gmail.com> | 2018-01-04 11:08:39 +0100 |
commit | 02b4a2ad6208c3b70a4a194b4c763a4e4334cdc1 (patch) | |
tree | d139d88ce51c328cb55a9e8ad8f9371c3351568e /src/helpers.ts | |
parent | fd2cd9c383b07cd681c18137396deae025d98047 (diff) | |
download | wallet-core-02b4a2ad6208c3b70a4a194b4c763a4e4334cdc1.tar.xz |
store sender wire info in separate store
Diffstat (limited to 'src/helpers.ts')
-rw-r--r-- | src/helpers.ts | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/helpers.ts b/src/helpers.ts index d85808acb..42863c65b 100644 --- a/src/helpers.ts +++ b/src/helpers.ts @@ -138,3 +138,17 @@ export function getTalerStampDate(stamp: string): Date | null { return new Date(sec * 1000); } +export function hash(val: any): number { + const str = canonicalJson(val); + // https://github.com/darkskyapp/string-hash + let h = 5381; + let i = str.length; + while (i) { + h = (h * 33) ^ str.charCodeAt(--i); + } + + /* JavaScript does bitwise operations (like XOR, above) on 32-bit signed + * integers. Since we want the results to be always positive, convert the + * signed int to an unsigned by doing an unsigned bitshift. */ + return h >>> 0; +} |