js-waku/packages/message-encryption/src/decoded_message.ts
Danish Arora 169a09d552
chore: enforce access modifiers (#2068)
* feat: introduce eslint flag

* chore: update logger

* chore: update enr

* chore: update core

* chore: update sdk

* chore: update relay

* chore: update discovery

* chore: update message-encryption

* chore: update tests

* chore: fix modifiers

* chore(tests): fix access modifiers

* chore: fix rebase
2024-07-19 15:58:17 +05:30

41 lines
1.0 KiB
TypeScript

import {
DecodedMessage as DecodedMessageV0,
proto
} from "@waku/core/lib/message/version_0";
import type { IDecodedMessage } from "@waku/interfaces";
import { equals } from "uint8arrays/equals";
export class DecodedMessage
extends DecodedMessageV0
implements IDecodedMessage
{
private readonly _decodedPayload: Uint8Array;
public constructor(
pubsubTopic: string,
proto: proto.WakuMessage,
decodedPayload: Uint8Array,
public signature?: Uint8Array,
public signaturePublicKey?: Uint8Array
) {
super(pubsubTopic, proto);
this._decodedPayload = decodedPayload;
}
public get payload(): Uint8Array {
return this._decodedPayload;
}
/**
* Verify the message's signature against the public key.
*
* @returns true if the signature matches the public key, false if not or if no signature is present.
*/
public verifySignature(publicKey: Uint8Array): boolean {
if (this.signaturePublicKey) {
return equals(this.signaturePublicKey, publicKey);
}
return false;
}
}