mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-03 06:13:08 +00:00
* 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
41 lines
1.0 KiB
TypeScript
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;
|
|
}
|
|
}
|