aboutsummaryrefslogtreecommitdiff
path: root/src/helpers.ts
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2018-01-04 11:08:39 +0100
committerFlorian Dold <florian.dold@gmail.com>2018-01-04 11:08:39 +0100
commit02b4a2ad6208c3b70a4a194b4c763a4e4334cdc1 (patch)
treed139d88ce51c328cb55a9e8ad8f9371c3351568e /src/helpers.ts
parentfd2cd9c383b07cd681c18137396deae025d98047 (diff)
downloadwallet-core-02b4a2ad6208c3b70a4a194b4c763a4e4334cdc1.tar.xz
store sender wire info in separate store
Diffstat (limited to 'src/helpers.ts')
-rw-r--r--src/helpers.ts14
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;
+}