bug: fix hmac for insecure contexts
Some checks failed
Docker build on tag / build (push) Has been cancelled

This commit is contained in:
2023-03-15 11:09:20 +00:00
parent 9f4d9bf117
commit b846c5720c
2 changed files with 11 additions and 2 deletions

View File

@ -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));
}
}