mirror of
https://github.com/logos-messaging/js-rln.git
synced 2026-01-07 16:13:07 +00:00
fix: content topic can be utf-8
This commit is contained in:
parent
b9269660c8
commit
7c8b3f1f98
@ -1,5 +1,5 @@
|
|||||||
import debug from "debug";
|
import debug from "debug";
|
||||||
import { proto_message } from "js-waku";
|
import {proto_message, utils} from "js-waku";
|
||||||
import {
|
import {
|
||||||
Decoder,
|
Decoder,
|
||||||
Encoder,
|
Encoder,
|
||||||
@ -13,8 +13,7 @@ const log = debug("waku:message:rln-encoder");
|
|||||||
|
|
||||||
export class RLNEncoder implements Encoder {
|
export class RLNEncoder implements Encoder {
|
||||||
public contentTopic: string;
|
public contentTopic: string;
|
||||||
|
private readonly idKey: Uint8Array;
|
||||||
private idKey: Uint8Array;
|
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private encoder: Encoder,
|
private encoder: Encoder,
|
||||||
@ -33,19 +32,11 @@ export class RLNEncoder implements Encoder {
|
|||||||
return proto_message.WakuMessage.encode(protoMessage);
|
return proto_message.WakuMessage.encode(protoMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
toRLNSignal(msg: Message): Uint8Array {
|
|
||||||
const contentTopic = msg.contentTopic ?? "";
|
|
||||||
const contentTopicBytes = Uint8Array.from(
|
|
||||||
contentTopic.split("").map((x: string) => x.charCodeAt(0))
|
|
||||||
);
|
|
||||||
return new Uint8Array([...(msg.payload ?? []), ...contentTopicBytes]);
|
|
||||||
}
|
|
||||||
|
|
||||||
async encodeProto(message: Message): Promise<ProtoMessage | undefined> {
|
async encodeProto(message: Message): Promise<ProtoMessage | undefined> {
|
||||||
const protoMessage = await this.encoder.encodeProto(message);
|
const protoMessage = await this.encoder.encodeProto(message);
|
||||||
if (!protoMessage) return;
|
if (!protoMessage) return;
|
||||||
|
|
||||||
const signal = this.toRLNSignal(message);
|
const signal = toRLNSignal(message);
|
||||||
|
|
||||||
console.time("proof_gen_timer");
|
console.time("proof_gen_timer");
|
||||||
const proof = await this.rlnInstance.generateProof(
|
const proof = await this.rlnInstance.generateProof(
|
||||||
@ -83,3 +74,8 @@ export class RLNDecoder implements Decoder<Message> {
|
|||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function toRLNSignal(msg: Message): Uint8Array {
|
||||||
|
const contentTopicBytes = utils.utf8ToBytes(msg.contentTopic ?? "")
|
||||||
|
return new Uint8Array([...(msg.payload ?? []), ...contentTopicBytes]);
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user