bug: fix hmac for insecure contexts
Some checks failed
Docker build on tag / build (push) Has been cancelled
Some checks failed
Docker build on tag / build (push) Has been cancelled
This commit is contained in:
parent
9f4d9bf117
commit
b846c5720c
@ -2,7 +2,7 @@ import * as secp from "@noble/secp256k1";
|
||||
import * as base64 from "@protobufjs/base64";
|
||||
import { useSelector } from "react-redux";
|
||||
import { RootState } from "State/Store";
|
||||
import { unwrap } from "Util";
|
||||
import { hmacSha256, unwrap } from "Util";
|
||||
|
||||
export interface ImgProxySettings {
|
||||
url: string;
|
||||
@ -19,7 +19,7 @@ export default function useImgProxy() {
|
||||
}
|
||||
|
||||
async function signUrl(u: string) {
|
||||
const result = await secp.utils.hmacSha256(
|
||||
const result = await hmacSha256(
|
||||
secp.utils.hexToBytes(unwrap(settings).key),
|
||||
secp.utils.hexToBytes(unwrap(settings).salt),
|
||||
te.encode(u)
|
||||
|
@ -1,5 +1,6 @@
|
||||
import * as secp from "@noble/secp256k1";
|
||||
import { sha256 as hash } from "@noble/hashes/sha256";
|
||||
import { hmac } from "@noble/hashes/hmac";
|
||||
import { bytesToHex } from "@noble/hashes/utils";
|
||||
import { decode as invoiceDecode } from "light-bolt11-decoder";
|
||||
import { bech32 } from "bech32";
|
||||
@ -453,3 +454,11 @@ export function findTag(e: TaggedRawEvent, tag: string) {
|
||||
});
|
||||
return maybeTag && maybeTag[1];
|
||||
}
|
||||
|
||||
export async function hmacSha256(key: Uint8Array, ...messages: Uint8Array[]) {
|
||||
if (window.crypto.subtle) {
|
||||
return await secp.utils.hmacSha256(key, ...messages);
|
||||
} else {
|
||||
return hmac(hash, key, secp.utils.concatBytes(...messages));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user