mirror of https://github.com/waku-org/js-waku.git
feat: export `Decoder`, `Encoder` and `DecodedMessage` types from root
Fixes #1010
This commit is contained in:
parent
abe1e204b1
commit
da1b18d995
|
@ -1,9 +1,10 @@
|
|||
export { DefaultPubSubTopic } from "./lib/constants.js";
|
||||
export { DefaultUserAgent } from "./lib/waku.js";
|
||||
|
||||
export {
|
||||
createEncoder,
|
||||
createDecoder,
|
||||
export { createEncoder, createDecoder } from "./lib/message/version_0.js";
|
||||
export type {
|
||||
Encoder,
|
||||
Decoder,
|
||||
DecodedMessage,
|
||||
} from "./lib/message/version_0.js";
|
||||
export * as message from "./lib/message/index.js";
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
import {
|
||||
DecodedMessage as DecodedMessageV0,
|
||||
proto,
|
||||
} from "@waku/core/lib/message/version_0";
|
||||
import type { IDecodedMessage } from "@waku/interfaces";
|
||||
|
||||
export class DecodedMessage
|
||||
extends DecodedMessageV0
|
||||
implements IDecodedMessage
|
||||
{
|
||||
private readonly _decodedPayload: Uint8Array;
|
||||
|
||||
constructor(
|
||||
proto: proto.WakuMessage,
|
||||
decodedPayload: Uint8Array,
|
||||
public signature?: Uint8Array,
|
||||
public signaturePublicKey?: Uint8Array
|
||||
) {
|
||||
super(proto);
|
||||
this._decodedPayload = decodedPayload;
|
||||
}
|
||||
|
||||
get payload(): Uint8Array {
|
||||
return this._decodedPayload;
|
||||
}
|
||||
}
|
|
@ -9,6 +9,7 @@ import type {
|
|||
import { WakuMessage } from "@waku/proto";
|
||||
import debug from "debug";
|
||||
|
||||
import { DecodedMessage } from "./decoded_message.js";
|
||||
import {
|
||||
decryptAsymmetric,
|
||||
encryptAsymmetric,
|
||||
|
@ -17,18 +18,18 @@ import {
|
|||
} from "./waku_payload.js";
|
||||
|
||||
import {
|
||||
DecodedMessage,
|
||||
generatePrivateKey,
|
||||
getPublicKey,
|
||||
OneMillion,
|
||||
Version,
|
||||
} from "./index.js";
|
||||
|
||||
export { DecodedMessage, generatePrivateKey, getPublicKey };
|
||||
export { generatePrivateKey, getPublicKey };
|
||||
export type { Encoder, Decoder, DecodedMessage };
|
||||
|
||||
const log = debug("waku:message-encryption:ecies");
|
||||
|
||||
export class Encoder implements IEncoder {
|
||||
class Encoder implements IEncoder {
|
||||
constructor(
|
||||
public contentTopic: string,
|
||||
private publicKey: Uint8Array,
|
||||
|
@ -88,7 +89,7 @@ export function createEncoder({
|
|||
return new Encoder(contentTopic, publicKey, sigPrivKey, ephemeral);
|
||||
}
|
||||
|
||||
export class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
|
||||
class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
|
||||
constructor(contentTopic: string, private privateKey: Uint8Array) {
|
||||
super(contentTopic);
|
||||
}
|
||||
|
|
|
@ -1,18 +1,14 @@
|
|||
import {
|
||||
DecodedMessage as DecodedMessageV0,
|
||||
proto,
|
||||
} from "@waku/core/lib/message/version_0";
|
||||
import type { IDecodedMessage } from "@waku/interfaces";
|
||||
|
||||
import {
|
||||
generatePrivateKey,
|
||||
generateSymmetricKey,
|
||||
getPublicKey,
|
||||
} from "./crypto/index.js";
|
||||
import { DecodedMessage } from "./decoded_message.js";
|
||||
|
||||
export const OneMillion = BigInt(1_000_000);
|
||||
|
||||
export { generatePrivateKey, generateSymmetricKey, getPublicKey };
|
||||
export type { DecodedMessage };
|
||||
|
||||
export * as ecies from "./ecies.js";
|
||||
export * as symmetric from "./symmetric.js";
|
||||
|
@ -23,24 +19,3 @@ export type Signature = {
|
|||
signature: Uint8Array;
|
||||
publicKey: Uint8Array | undefined;
|
||||
};
|
||||
|
||||
export class DecodedMessage
|
||||
extends DecodedMessageV0
|
||||
implements IDecodedMessage
|
||||
{
|
||||
private readonly _decodedPayload: Uint8Array;
|
||||
|
||||
constructor(
|
||||
proto: proto.WakuMessage,
|
||||
decodedPayload: Uint8Array,
|
||||
public signature?: Uint8Array,
|
||||
public signaturePublicKey?: Uint8Array
|
||||
) {
|
||||
super(proto);
|
||||
this._decodedPayload = decodedPayload;
|
||||
}
|
||||
|
||||
get payload(): Uint8Array {
|
||||
return this._decodedPayload;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import type {
|
|||
import { WakuMessage } from "@waku/proto";
|
||||
import debug from "debug";
|
||||
|
||||
import { DecodedMessage } from "./decoded_message.js";
|
||||
import {
|
||||
decryptSymmetric,
|
||||
encryptSymmetric,
|
||||
|
@ -16,18 +17,14 @@ import {
|
|||
preCipher,
|
||||
} from "./waku_payload.js";
|
||||
|
||||
import {
|
||||
DecodedMessage,
|
||||
generateSymmetricKey,
|
||||
OneMillion,
|
||||
Version,
|
||||
} from "./index.js";
|
||||
import { generateSymmetricKey, OneMillion, Version } from "./index.js";
|
||||
|
||||
export { DecodedMessage, generateSymmetricKey };
|
||||
export { generateSymmetricKey };
|
||||
export type { DecodedMessage, Encoder, Decoder };
|
||||
|
||||
const log = debug("waku:message-encryption:symmetric");
|
||||
|
||||
export class Encoder implements IEncoder {
|
||||
class Encoder implements IEncoder {
|
||||
constructor(
|
||||
public contentTopic: string,
|
||||
private symKey: Uint8Array,
|
||||
|
@ -87,7 +84,7 @@ export function createEncoder({
|
|||
return new Encoder(contentTopic, symKey, sigPrivKey, ephemeral);
|
||||
}
|
||||
|
||||
export class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
|
||||
class Decoder extends DecoderV0 implements IDecoder<DecodedMessage> {
|
||||
constructor(contentTopic: string, private symKey: Uint8Array) {
|
||||
super(contentTopic);
|
||||
}
|
||||
|
|
|
@ -2,11 +2,12 @@ import {
|
|||
createCursor,
|
||||
createDecoder,
|
||||
createEncoder,
|
||||
DecodedMessage,
|
||||
PageDirection,
|
||||
waitForRemotePeer,
|
||||
} from "@waku/core";
|
||||
import { createLightNode } from "@waku/create";
|
||||
import type { IDecodedMessage, IMessage, LightNode } from "@waku/interfaces";
|
||||
import type { IMessage, LightNode } from "@waku/interfaces";
|
||||
import { Protocols } from "@waku/interfaces";
|
||||
import {
|
||||
createDecoder as createEciesDecoder,
|
||||
|
@ -147,10 +148,10 @@ describe("Waku Store", () => {
|
|||
const query = waku.store.queryGenerator([TestDecoder]);
|
||||
|
||||
// messages in reversed order (first message at last index)
|
||||
const messages: IDecodedMessage[] = [];
|
||||
const messages: DecodedMessage[] = [];
|
||||
for await (const page of query) {
|
||||
for await (const msg of page.reverse()) {
|
||||
messages.push(msg as IDecodedMessage);
|
||||
messages.push(msg as DecodedMessage);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -160,12 +161,12 @@ describe("Waku Store", () => {
|
|||
// create cursor to extract messages after the 3rd index
|
||||
const cursor = await createCursor(messages[cursorIndex]);
|
||||
|
||||
const messagesAfterCursor: IDecodedMessage[] = [];
|
||||
const messagesAfterCursor: DecodedMessage[] = [];
|
||||
for await (const page of waku.store.queryGenerator([TestDecoder], {
|
||||
cursor,
|
||||
})) {
|
||||
for await (const msg of page.reverse()) {
|
||||
messagesAfterCursor.push(msg as IDecodedMessage);
|
||||
messagesAfterCursor.push(msg as DecodedMessage);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -419,7 +420,7 @@ describe("Waku Store", () => {
|
|||
|
||||
await waitForRemotePeer(waku2, [Protocols.Store]);
|
||||
|
||||
const messages: IDecodedMessage[] = [];
|
||||
const messages: DecodedMessage[] = [];
|
||||
log("Retrieve messages from store");
|
||||
|
||||
for await (const msgPromises of waku2.store.queryGenerator([
|
||||
|
|
Loading…
Reference in New Issue