feat: nip44 v2

This commit is contained in:
2024-08-26 15:57:46 +03:00
parent 1ed36352a8
commit 644bd57094
12 changed files with 223 additions and 142 deletions

View File

@ -3,12 +3,10 @@ import * as utils from "@noble/curves/abstract/utils";
import { unwrap } from "@snort/shared";
import {
decodeEncryptionPayload,
EventKind,
EventSigner,
FullRelaySettings,
HexKey,
MessageEncryptorVersion,
NostrEvent,
NostrLink,
NotSignedNostrEvent,
@ -262,23 +260,6 @@ export class EventPublisher {
return await this.#sign(eb);
}
/**
* Generic decryption using NIP-23 payload scheme
*/
async decryptGeneric(content: string, from: string) {
const pl = decodeEncryptionPayload(content);
switch (pl.v) {
case MessageEncryptorVersion.Nip4: {
const nip4Payload = `${base64.encode(pl.ciphertext)}?iv=${base64.encode(pl.nonce)}`;
return await this.#signer.nip4Decrypt(nip4Payload, from);
}
case MessageEncryptorVersion.XChaCha20: {
return await this.#signer.nip44Decrypt(content, from);
}
}
throw new Error("Not supported version");
}
async decryptDm(note: NostrEvent) {
if (note.kind === EventKind.SealedRumor) {
const unseal = await this.unsealRumor(note);