reduce browser bundle size
reduces browser bundle size by ~612k or ~92%.
This commit is contained in:
18
src/util/browser-support.ts
Normal file
18
src/util/browser-support.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
|
||||
export async function signMessage(message: string, secret: string): Promise<string> {
|
||||
const encoder = new TextEncoder();
|
||||
const key = await window.crypto.subtle.importKey(
|
||||
'raw',
|
||||
encoder.encode(secret),
|
||||
{name: 'HMAC', hash: {name: 'SHA-256'}},
|
||||
false,
|
||||
['sign']
|
||||
);
|
||||
|
||||
const signature = await window.crypto.subtle.sign('HMAC', key, encoder.encode(message));
|
||||
|
||||
return Array.prototype.map.call(
|
||||
new Uint8Array(signature),
|
||||
(x: any) => ('00'+x.toString(16)).slice(-2)
|
||||
).join('');
|
||||
};
|
||||
Reference in New Issue
Block a user