Remove crypto dependency
Summary: Remove crypto dep, which was only used by NUX, to hash the elements that has been confirmed. Sadly trickier than hoped; there is no uniform api in both browser and Node available that can take a sha-256 hash, and the browser APIs are async. Reviewed By: aigoncharov Differential Revision: D32721204 fbshipit-source-id: 32625f83bf6c60cedc4fb7096240c2fa0d8434a7
This commit is contained in:
committed by
Facebook GitHub Bot
parent
058785a509
commit
f5f9608098
23
desktop/flipper-plugin/src/utils/sha256.tsx
Normal file
23
desktop/flipper-plugin/src/utils/sha256.tsx
Normal file
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||
*
|
||||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*
|
||||
* @format
|
||||
*/
|
||||
|
||||
export function sha256(message: string): Promise<string> {
|
||||
if (process.env.NODE_ENV === 'test') {
|
||||
return Promise.resolve(message.substr(0, 100));
|
||||
}
|
||||
// From https://stackoverflow.com/a/48161723/1983583
|
||||
const msgBuffer = new TextEncoder().encode(message);
|
||||
return crypto.subtle.digest('SHA-256', msgBuffer).then((hashBuffer) => {
|
||||
const hashArray = Array.from(new Uint8Array(hashBuffer));
|
||||
const hashHex = hashArray
|
||||
.map((b) => b.toString(16).padStart(2, '0'))
|
||||
.join('');
|
||||
return hashHex;
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user