-
Notifications
You must be signed in to change notification settings - Fork 179
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(app): Configure analytics to send Python and JSON protocol info (#…
- Loading branch information
Showing
11 changed files
with
430 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// @flow | ||
// hash strings for an amount of anonymity | ||
// note: values will be _hashed_, not _enctrypted_; hashed values should not be | ||
// considered secure nor should they ever be released publicly | ||
const ALGORITHM = 'SHA-256' | ||
|
||
export default function hash (source: string): Promise<string> { | ||
const encoder = new TextEncoder() | ||
const data = encoder.encode(source) | ||
|
||
// https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest | ||
return global.crypto.subtle | ||
.digest(ALGORITHM, data) | ||
.then((digest: ArrayBuffer) => arrayBufferToHex(digest)) | ||
} | ||
|
||
// https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/digest#Converting_a_digest_to_a_hex_string | ||
function arrayBufferToHex (source: ArrayBuffer): string { | ||
const bytes = new Uint8Array(source) | ||
|
||
return [...bytes].map(b => b.toString(16).padStart(2, '0')).join('') | ||
} |
Oops, something went wrong.