mirror of
https://github.com/waku-org/js-waku.git
synced 2025-02-17 06:47:29 +00:00
* chore: update noise * update: package.lock * update: @chainsafe/libp2p-gossipsub * rm unwanted libp2p interface deps & bump up libp2p * refactor code for new deps * update: new package.lock * setup prettier, refactor eslint and rm trailing commas * update package.lock * fix build * import type for interface * fix imports for merge * update typedoc exports * add: CustomEvent import * use new libp2p interface * add aegir as dev dep for tests
35 lines
720 B
TypeScript
35 lines
720 B
TypeScript
import type { Waku2 } from "@waku/interfaces";
|
|
|
|
export function encodeWaku2(protocols: Waku2): number {
|
|
let byte = 0;
|
|
|
|
if (protocols.lightPush) byte += 1;
|
|
byte = byte << 1;
|
|
if (protocols.filter) byte += 1;
|
|
byte = byte << 1;
|
|
if (protocols.store) byte += 1;
|
|
byte = byte << 1;
|
|
if (protocols.relay) byte += 1;
|
|
|
|
return byte;
|
|
}
|
|
|
|
export function decodeWaku2(byte: number): Waku2 {
|
|
const waku2 = {
|
|
relay: false,
|
|
store: false,
|
|
filter: false,
|
|
lightPush: false
|
|
};
|
|
|
|
if (byte % 2) waku2.relay = true;
|
|
byte = byte >> 1;
|
|
if (byte % 2) waku2.store = true;
|
|
byte = byte >> 1;
|
|
if (byte % 2) waku2.filter = true;
|
|
byte = byte >> 1;
|
|
if (byte % 2) waku2.lightPush = true;
|
|
|
|
return waku2;
|
|
}
|