chore: avoid SubtleCrypto
This commit is contained in:
parent
84ad3556a7
commit
424c7c79d7
@ -35,7 +35,7 @@ export default function useEventPublisher() {
|
||||
|
||||
async function signEvent(ev: NEvent): Promise<NEvent> {
|
||||
if (hasNip07 && !privKey) {
|
||||
ev.Id = await ev.CreateId();
|
||||
ev.Id = ev.CreateId();
|
||||
const tmpEv = (await barrierNip07(() => window.nostr.signEvent(ev.ToObject()))) as RawEvent;
|
||||
return new NEvent(tmpEv as TaggedRawEvent);
|
||||
} else if (privKey) {
|
||||
|
@ -24,6 +24,7 @@
|
||||
"semi": false
|
||||
},
|
||||
"dependencies": {
|
||||
"@noble/hashes": "^1.2.0",
|
||||
"@noble/secp256k1": "^1.7.1",
|
||||
"bech32": "^2.0.0",
|
||||
"events": "^3.3.0",
|
||||
|
@ -1,4 +1,5 @@
|
||||
import * as secp from "@noble/secp256k1";
|
||||
import { sha256 } from "@noble/hashes/sha256";
|
||||
import * as base64 from "@protobufjs/base64";
|
||||
import { HexKey, RawEvent, TaggedRawEvent } from "./index";
|
||||
import EventKind from "./EventKind";
|
||||
@ -78,7 +79,7 @@ export default class Event {
|
||||
* Sign this message with a private key
|
||||
*/
|
||||
async Sign(key: HexKey) {
|
||||
this.Id = await this.CreateId();
|
||||
this.Id = this.CreateId();
|
||||
|
||||
const sig = await secp.schnorr.sign(this.Id, key);
|
||||
this.Signature = secp.utils.bytesToHex(sig);
|
||||
@ -92,12 +93,12 @@ export default class Event {
|
||||
* @returns True if valid signature
|
||||
*/
|
||||
async Verify() {
|
||||
const id = await this.CreateId();
|
||||
const id = this.CreateId();
|
||||
const result = await secp.schnorr.verify(this.Signature, id, this.PubKey);
|
||||
return result;
|
||||
}
|
||||
|
||||
async CreateId() {
|
||||
CreateId() {
|
||||
const payload = [
|
||||
0,
|
||||
this.PubKey,
|
||||
@ -107,9 +108,7 @@ export default class Event {
|
||||
this.Content,
|
||||
];
|
||||
|
||||
const payloadData = new TextEncoder().encode(JSON.stringify(payload));
|
||||
const data = await secp.utils.sha256(payloadData);
|
||||
const hash = secp.utils.bytesToHex(data);
|
||||
const hash = secp.utils.bytesToHex(sha256(JSON.stringify(payload)));
|
||||
if (this.Id !== "" && hash !== this.Id) {
|
||||
console.debug(payload);
|
||||
throw "ID doesnt match!";
|
||||
|
Loading…
x
Reference in New Issue
Block a user