Skip to content
This repository was archived by the owner on Jun 26, 2023. It is now read-only.

Commit 269a6f5

Browse files
authored
fix: typescript types (#69)
1 parent 14d0997 commit 269a6f5

File tree

5 files changed

+25
-11
lines changed

5 files changed

+25
-11
lines changed

src/pubsub/errors.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
export namespace codes {
2+
export const ERR_INVALID_SIGNATURE_POLICY: string;
3+
export const ERR_UNHANDLED_SIGNATURE_POLICY: string;
24
export const ERR_MISSING_SIGNATURE: string;
5+
export const ERR_MISSING_SEQNO: string;
36
export const ERR_INVALID_SIGNATURE: string;
7+
export const ERR_UNEXPECTED_FROM: string;
8+
export const ERR_UNEXPECTED_SIGNATURE: string;
9+
export const ERR_UNEXPECTED_KEY: string;
10+
export const ERR_UNEXPECTED_SEQNO: string;
411
}

src/pubsub/index.d.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,16 @@ declare class PubsubBaseProtocol {
2222
* @param {String} props.debugName log namespace
2323
* @param {Array<string>|string} props.multicodecs protocol identificers to connect
2424
* @param {Libp2p} props.libp2p
25-
* @param {boolean} [props.signMessages = true] if messages should be signed
26-
* @param {boolean} [props.strictSigning = true] if message signing should be required
25+
* @param {SignaturePolicy} [props.globalSignaturePolicy = SignaturePolicy.StrictSign] defines how signatures should be handled
2726
* @param {boolean} [props.canRelayMessage = false] if can relay messages not subscribed
2827
* @param {boolean} [props.emitSelf = false] if publish should emit to self, if subscribed
2928
* @abstract
3029
*/
31-
constructor({ debugName, multicodecs, libp2p, signMessages, strictSigning, canRelayMessage, emitSelf }: {
30+
constructor({ debugName, multicodecs, libp2p, globalSignaturePolicy, canRelayMessage, emitSelf }: {
3231
debugName: string;
3332
multicodecs: string | string[];
3433
libp2p: any;
35-
signMessages?: boolean;
36-
strictSigning?: boolean;
34+
globalSignaturePolicy?: any;
3735
canRelayMessage?: boolean;
3836
emitSelf?: boolean;
3937
});
@@ -66,12 +64,12 @@ declare class PubsubBaseProtocol {
6664
* @type {Map<string, import('./peer-streams')>}
6765
*/
6866
peers: Map<string, import('./peer-streams')>;
69-
signMessages: boolean;
7067
/**
71-
* If message signing should be required for incoming messages
72-
* @type {boolean}
68+
* The signature policy to follow by default
69+
*
70+
* @type {string}
7371
*/
74-
strictSigning: boolean;
72+
globalSignaturePolicy: string;
7573
/**
7674
* If router can relay received messages, even if not subscribed
7775
* @type {boolean}
@@ -284,7 +282,7 @@ declare class PubsubBaseProtocol {
284282
getTopics(): string[];
285283
}
286284
declare namespace PubsubBaseProtocol {
287-
export { message, utils, InMessage, PeerId };
285+
export { message, utils, SignaturePolicy, InMessage, PeerId };
288286
}
289287
type PeerId = import("peer-id");
290288
/**
@@ -305,3 +303,7 @@ type InMessage = {
305303
*/
306304
declare const message: typeof import('./message');
307305
declare const utils: typeof import("./utils");
306+
declare const SignaturePolicy: {
307+
StrictSign: string;
308+
StrictNoSign: string;
309+
};

src/pubsub/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ class PubsubBaseProtocol extends EventEmitter {
116116
/**
117117
* The signature policy to follow by default
118118
*
119-
* @type {SignaturePolicy}
119+
* @type {string}
120120
*/
121121
this.globalSignaturePolicy = globalSignaturePolicy
122122

src/pubsub/signature-policy.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export namespace SignaturePolicy {
2+
export const StrictSign: string;
3+
export const StrictNoSign: string;
4+
}

src/pubsub/utils.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export function randomSeqno(): Uint8Array;
22
export function msgId(from: string, seqno: Uint8Array): Uint8Array;
3+
export function noSignMsgId(data: Uint8Array): Uint8Array;
34
export function anyMatch(a: any[] | Set<any>, b: any[] | Set<any>): boolean;
45
export function ensureArray(maybeArray: any): any[];
56
export function normalizeInRpcMessage(message: any, peerId: string): any;

0 commit comments

Comments
 (0)