mirror of
https://github.com/logos-messaging/js-waku.git
synced 2026-01-12 10:43:08 +00:00
* remove message-hash package, move it to core * add js-doc to message hash * up * address type changes * fix lint
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 { IEncryptedMessage } from "@waku/interfaces";
|
|
import { equals } from "uint8arrays/equals";
|
|
|
|
export class DecodedMessage
|
|
extends DecodedMessageV0
|
|
implements IEncryptedMessage
|
|
{
|
|
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;
|
|
}
|
|
}
|