@libp2p/gossipsub 14.1.1-6059227cb
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +85 -0
- package/dist/index.min.js +19 -0
- package/dist/index.min.js.map +7 -0
- package/dist/src/config.d.ts +32 -0
- package/dist/src/config.d.ts.map +1 -0
- package/dist/src/config.js +2 -0
- package/dist/src/config.js.map +1 -0
- package/dist/src/constants.d.ts +213 -0
- package/dist/src/constants.d.ts.map +1 -0
- package/dist/src/constants.js +217 -0
- package/dist/src/constants.js.map +1 -0
- package/dist/src/errors.d.ts +9 -0
- package/dist/src/errors.d.ts.map +1 -0
- package/dist/src/errors.js +15 -0
- package/dist/src/errors.js.map +1 -0
- package/dist/src/gossipsub.d.ts +419 -0
- package/dist/src/gossipsub.d.ts.map +1 -0
- package/dist/src/gossipsub.js +2520 -0
- package/dist/src/gossipsub.js.map +1 -0
- package/dist/src/index.d.ts +344 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +43 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/message/decodeRpc.d.ts +11 -0
- package/dist/src/message/decodeRpc.d.ts.map +1 -0
- package/dist/src/message/decodeRpc.js +10 -0
- package/dist/src/message/decodeRpc.js.map +1 -0
- package/dist/src/message/index.d.ts +2 -0
- package/dist/src/message/index.d.ts.map +1 -0
- package/dist/src/message/index.js +2 -0
- package/dist/src/message/index.js.map +1 -0
- package/dist/src/message/rpc.d.ts +99 -0
- package/dist/src/message/rpc.d.ts.map +1 -0
- package/dist/src/message/rpc.js +663 -0
- package/dist/src/message/rpc.js.map +1 -0
- package/dist/src/message-cache.d.ts +80 -0
- package/dist/src/message-cache.d.ts.map +1 -0
- package/dist/src/message-cache.js +144 -0
- package/dist/src/message-cache.js.map +1 -0
- package/dist/src/metrics.d.ts +467 -0
- package/dist/src/metrics.d.ts.map +1 -0
- package/dist/src/metrics.js +896 -0
- package/dist/src/metrics.js.map +1 -0
- package/dist/src/score/compute-score.d.ts +4 -0
- package/dist/src/score/compute-score.d.ts.map +1 -0
- package/dist/src/score/compute-score.js +75 -0
- package/dist/src/score/compute-score.js.map +1 -0
- package/dist/src/score/index.d.ts +4 -0
- package/dist/src/score/index.d.ts.map +1 -0
- package/dist/src/score/index.js +4 -0
- package/dist/src/score/index.js.map +1 -0
- package/dist/src/score/message-deliveries.d.ts +45 -0
- package/dist/src/score/message-deliveries.d.ts.map +1 -0
- package/dist/src/score/message-deliveries.js +75 -0
- package/dist/src/score/message-deliveries.js.map +1 -0
- package/dist/src/score/peer-score-params.d.ts +125 -0
- package/dist/src/score/peer-score-params.d.ts.map +1 -0
- package/dist/src/score/peer-score-params.js +159 -0
- package/dist/src/score/peer-score-params.js.map +1 -0
- package/dist/src/score/peer-score-thresholds.d.ts +31 -0
- package/dist/src/score/peer-score-thresholds.d.ts.map +1 -0
- package/dist/src/score/peer-score-thresholds.js +32 -0
- package/dist/src/score/peer-score-thresholds.js.map +1 -0
- package/dist/src/score/peer-score.d.ts +119 -0
- package/dist/src/score/peer-score.d.ts.map +1 -0
- package/dist/src/score/peer-score.js +459 -0
- package/dist/src/score/peer-score.js.map +1 -0
- package/dist/src/score/peer-stats.d.ts +32 -0
- package/dist/src/score/peer-stats.d.ts.map +1 -0
- package/dist/src/score/peer-stats.js +2 -0
- package/dist/src/score/peer-stats.js.map +1 -0
- package/dist/src/score/scoreMetrics.d.ts +23 -0
- package/dist/src/score/scoreMetrics.d.ts.map +1 -0
- package/dist/src/score/scoreMetrics.js +155 -0
- package/dist/src/score/scoreMetrics.js.map +1 -0
- package/dist/src/stream.d.ts +30 -0
- package/dist/src/stream.d.ts.map +1 -0
- package/dist/src/stream.js +55 -0
- package/dist/src/stream.js.map +1 -0
- package/dist/src/tracer.d.ts +53 -0
- package/dist/src/tracer.d.ts.map +1 -0
- package/dist/src/tracer.js +155 -0
- package/dist/src/tracer.js.map +1 -0
- package/dist/src/types.d.ts +148 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +90 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/utils/buildRawMessage.d.ts +20 -0
- package/dist/src/utils/buildRawMessage.d.ts.map +1 -0
- package/dist/src/utils/buildRawMessage.js +151 -0
- package/dist/src/utils/buildRawMessage.js.map +1 -0
- package/dist/src/utils/create-gossip-rpc.d.ts +7 -0
- package/dist/src/utils/create-gossip-rpc.d.ts.map +1 -0
- package/dist/src/utils/create-gossip-rpc.js +31 -0
- package/dist/src/utils/create-gossip-rpc.js.map +1 -0
- package/dist/src/utils/index.d.ts +4 -0
- package/dist/src/utils/index.d.ts.map +1 -0
- package/dist/src/utils/index.js +4 -0
- package/dist/src/utils/index.js.map +1 -0
- package/dist/src/utils/messageIdToString.d.ts +5 -0
- package/dist/src/utils/messageIdToString.d.ts.map +1 -0
- package/dist/src/utils/messageIdToString.js +8 -0
- package/dist/src/utils/messageIdToString.js.map +1 -0
- package/dist/src/utils/msgIdFn.d.ts +10 -0
- package/dist/src/utils/msgIdFn.d.ts.map +1 -0
- package/dist/src/utils/msgIdFn.js +23 -0
- package/dist/src/utils/msgIdFn.js.map +1 -0
- package/dist/src/utils/multiaddr.d.ts +3 -0
- package/dist/src/utils/multiaddr.d.ts.map +1 -0
- package/dist/src/utils/multiaddr.js +15 -0
- package/dist/src/utils/multiaddr.js.map +1 -0
- package/dist/src/utils/publishConfig.d.ts +8 -0
- package/dist/src/utils/publishConfig.d.ts.map +1 -0
- package/dist/src/utils/publishConfig.js +25 -0
- package/dist/src/utils/publishConfig.js.map +1 -0
- package/dist/src/utils/set.d.ts +14 -0
- package/dist/src/utils/set.d.ts.map +1 -0
- package/dist/src/utils/set.js +41 -0
- package/dist/src/utils/set.js.map +1 -0
- package/dist/src/utils/shuffle.d.ts +7 -0
- package/dist/src/utils/shuffle.d.ts.map +1 -0
- package/dist/src/utils/shuffle.js +21 -0
- package/dist/src/utils/shuffle.js.map +1 -0
- package/dist/src/utils/time-cache.d.ts +22 -0
- package/dist/src/utils/time-cache.d.ts.map +1 -0
- package/dist/src/utils/time-cache.js +54 -0
- package/dist/src/utils/time-cache.js.map +1 -0
- package/package.json +142 -0
- package/src/config.ts +31 -0
- package/src/constants.ts +261 -0
- package/src/errors.ts +17 -0
- package/src/gossipsub.ts +3061 -0
- package/src/index.ts +404 -0
- package/src/message/decodeRpc.ts +19 -0
- package/src/message/index.ts +1 -0
- package/src/message/rpc.proto +58 -0
- package/src/message/rpc.ts +848 -0
- package/src/message-cache.ts +196 -0
- package/src/metrics.ts +1014 -0
- package/src/score/compute-score.ts +98 -0
- package/src/score/index.ts +3 -0
- package/src/score/message-deliveries.ts +95 -0
- package/src/score/peer-score-params.ts +316 -0
- package/src/score/peer-score-thresholds.ts +70 -0
- package/src/score/peer-score.ts +565 -0
- package/src/score/peer-stats.ts +33 -0
- package/src/score/scoreMetrics.ts +215 -0
- package/src/stream.ts +79 -0
- package/src/tracer.ts +177 -0
- package/src/types.ts +178 -0
- package/src/utils/buildRawMessage.ts +174 -0
- package/src/utils/create-gossip-rpc.ts +34 -0
- package/src/utils/index.ts +3 -0
- package/src/utils/messageIdToString.ts +8 -0
- package/src/utils/msgIdFn.ts +24 -0
- package/src/utils/multiaddr.ts +19 -0
- package/src/utils/publishConfig.ts +33 -0
- package/src/utils/set.ts +43 -0
- package/src/utils/shuffle.ts +21 -0
- package/src/utils/time-cache.ts +71 -0
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { TopicValidatorResult } from './index.ts';
|
|
2
|
+
import type { Message } from './index.ts';
|
|
3
|
+
import type { RPC } from './message/rpc.js';
|
|
4
|
+
import type { PrivateKey, PeerId } from '@libp2p/interface';
|
|
5
|
+
import type { Multiaddr } from '@multiformats/multiaddr';
|
|
6
|
+
export type MsgIdStr = string;
|
|
7
|
+
export type PeerIdStr = string;
|
|
8
|
+
export type TopicStr = string;
|
|
9
|
+
export type IPStr = string;
|
|
10
|
+
export interface AddrInfo {
|
|
11
|
+
id: PeerId;
|
|
12
|
+
addrs: Multiaddr[];
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Compute a local non-spec'ed msg-id for faster de-duplication of seen messages.
|
|
16
|
+
* Used exclusively for a local seen_cache
|
|
17
|
+
*/
|
|
18
|
+
export interface FastMsgIdFn {
|
|
19
|
+
(msg: RPC.Message): string | number;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* By default, gossipsub only provide a browser friendly function to convert Uint8Array message id to string.
|
|
23
|
+
* Application could use this option to provide a more efficient function.
|
|
24
|
+
*/
|
|
25
|
+
export interface MsgIdToStrFn {
|
|
26
|
+
(msgId: Uint8Array): string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Compute spec'ed msg-id. Used for IHAVE / IWANT messages
|
|
30
|
+
*/
|
|
31
|
+
export interface MsgIdFn {
|
|
32
|
+
(msg: Message): Promise<Uint8Array> | Uint8Array;
|
|
33
|
+
}
|
|
34
|
+
export interface DataTransform {
|
|
35
|
+
/**
|
|
36
|
+
* Takes the data published by peers on a topic and transforms the data.
|
|
37
|
+
* Should be the reverse of outboundTransform(). Example:
|
|
38
|
+
* - `inboundTransform()`: decompress snappy payload
|
|
39
|
+
* - `outboundTransform()`: compress snappy payload
|
|
40
|
+
*/
|
|
41
|
+
inboundTransform(topic: TopicStr, data: Uint8Array): Uint8Array;
|
|
42
|
+
/**
|
|
43
|
+
* Takes the data to be published (a topic and associated data) transforms the data. The
|
|
44
|
+
* transformed data will then be used to create a `RawGossipsubMessage` to be sent to peers.
|
|
45
|
+
*/
|
|
46
|
+
outboundTransform(topic: TopicStr, data: Uint8Array): Uint8Array;
|
|
47
|
+
}
|
|
48
|
+
export declare enum SignaturePolicy {
|
|
49
|
+
/**
|
|
50
|
+
* On the producing side:
|
|
51
|
+
* - Build messages with the signature, key (from may be enough for certain inlineable public key types), from and seqno fields.
|
|
52
|
+
*
|
|
53
|
+
* On the consuming side:
|
|
54
|
+
* - Enforce the fields to be present, reject otherwise.
|
|
55
|
+
* - Propagate only if the fields are valid and signature can be verified, reject otherwise.
|
|
56
|
+
*/
|
|
57
|
+
StrictSign = "StrictSign",
|
|
58
|
+
/**
|
|
59
|
+
* On the producing side:
|
|
60
|
+
* - Build messages without the signature, key, from and seqno fields.
|
|
61
|
+
* - The corresponding protobuf key-value pairs are absent from the marshalled message, not just empty.
|
|
62
|
+
*
|
|
63
|
+
* On the consuming side:
|
|
64
|
+
* - Enforce the fields to be absent, reject otherwise.
|
|
65
|
+
* - Propagate only if the fields are absent, reject otherwise.
|
|
66
|
+
* - A message_id function will not be able to use the above fields, and should instead rely on the data field. A commonplace strategy is to calculate a hash.
|
|
67
|
+
*/
|
|
68
|
+
StrictNoSign = "StrictNoSign"
|
|
69
|
+
}
|
|
70
|
+
export interface PublishOpts {
|
|
71
|
+
/**
|
|
72
|
+
* Do not throw `PublishError.NoPeersSubscribedToTopic` error if there are no
|
|
73
|
+
* peers listening on the topic.
|
|
74
|
+
*
|
|
75
|
+
* N.B. if you sent this option to true, and you publish a message on a topic
|
|
76
|
+
* with no peers listening on that topic, no other network node will ever
|
|
77
|
+
* receive the message.
|
|
78
|
+
*/
|
|
79
|
+
allowPublishToZeroTopicPeers?: boolean;
|
|
80
|
+
ignoreDuplicatePublishError?: boolean;
|
|
81
|
+
/** serialize message once and send to all peers without control messages */
|
|
82
|
+
batchPublish?: boolean;
|
|
83
|
+
}
|
|
84
|
+
export declare enum PublishConfigType {
|
|
85
|
+
Signing = 0,
|
|
86
|
+
Anonymous = 1
|
|
87
|
+
}
|
|
88
|
+
export type PublishConfig = {
|
|
89
|
+
type: PublishConfigType.Signing;
|
|
90
|
+
author: PeerId;
|
|
91
|
+
key: Uint8Array;
|
|
92
|
+
privateKey: PrivateKey;
|
|
93
|
+
} | {
|
|
94
|
+
type: PublishConfigType.Anonymous;
|
|
95
|
+
};
|
|
96
|
+
export type RejectReasonObj = {
|
|
97
|
+
reason: RejectReason.Error;
|
|
98
|
+
error: ValidateError;
|
|
99
|
+
} | {
|
|
100
|
+
reason: Exclude<RejectReason, RejectReason.Error>;
|
|
101
|
+
};
|
|
102
|
+
export declare enum RejectReason {
|
|
103
|
+
/**
|
|
104
|
+
* The message failed the configured validation during decoding.
|
|
105
|
+
* SelfOrigin is considered a ValidationError
|
|
106
|
+
*/
|
|
107
|
+
Error = "error",
|
|
108
|
+
/**
|
|
109
|
+
* Custom validator fn reported status IGNORE.
|
|
110
|
+
*/
|
|
111
|
+
Ignore = "ignore",
|
|
112
|
+
/**
|
|
113
|
+
* Custom validator fn reported status REJECT.
|
|
114
|
+
*/
|
|
115
|
+
Reject = "reject",
|
|
116
|
+
/**
|
|
117
|
+
* The peer that sent the message OR the source from field is blacklisted.
|
|
118
|
+
* Causes messages to be ignored, not penalized, neither do score record creation.
|
|
119
|
+
*/
|
|
120
|
+
Blacklisted = "blacklisted"
|
|
121
|
+
}
|
|
122
|
+
export declare enum ValidateError {
|
|
123
|
+
InvalidSignature = "invalid_signature",
|
|
124
|
+
InvalidSeqno = "invalid_seqno",
|
|
125
|
+
InvalidPeerId = "invalid_peerid",
|
|
126
|
+
SignaturePresent = "signature_present",
|
|
127
|
+
SeqnoPresent = "seqno_present",
|
|
128
|
+
FromPresent = "from_present",
|
|
129
|
+
TransformFailed = "transform_failed"
|
|
130
|
+
}
|
|
131
|
+
export declare enum MessageStatus {
|
|
132
|
+
duplicate = "duplicate",
|
|
133
|
+
invalid = "invalid",
|
|
134
|
+
valid = "valid"
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* Store both Uint8Array and string message id so that we don't have to convert data between the two.
|
|
138
|
+
* See https://github.com/ChainSafe/js-libp2p-gossipsub/pull/274
|
|
139
|
+
*/
|
|
140
|
+
export interface MessageId {
|
|
141
|
+
msgId: Uint8Array;
|
|
142
|
+
msgIdStr: MsgIdStr;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* Typesafe conversion of MessageAcceptance -> RejectReason. TS ensures all values covered
|
|
146
|
+
*/
|
|
147
|
+
export declare function rejectReasonFromAcceptance(acceptance: Exclude<TopicValidatorResult, TopicValidatorResult.Accept>): RejectReason.Ignore | RejectReason.Reject;
|
|
148
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AACjD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,YAAY,CAAA;AACzC,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAA;AAC3D,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAExD,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAA;AAC7B,MAAM,MAAM,SAAS,GAAG,MAAM,CAAA;AAC9B,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAA;AAC7B,MAAM,MAAM,KAAK,GAAG,MAAM,CAAA;AAE1B,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,SAAS,EAAE,CAAA;CACnB;AAED;;;GAGG;AACH,MAAM,WAAW,WAAW;IAAG,CAAC,GAAG,EAAE,GAAG,CAAC,OAAO,GAAG,MAAM,GAAG,MAAM,CAAA;CAAE;AAEpE;;;GAGG;AACH,MAAM,WAAW,YAAY;IAAG,CAAC,KAAK,EAAE,UAAU,GAAG,MAAM,CAAA;CAAE;AAE7D;;GAEG;AACH,MAAM,WAAW,OAAO;IACtB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,GAAG,UAAU,CAAA;CACjD;AAED,MAAM,WAAW,aAAa;IAC5B;;;;;OAKG;IACH,gBAAgB,CAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,UAAU,GAAG,UAAU,CA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AS,cAAc;IACvB,OAAO,YAAY;IACnB,KAAK,UAAU;CAChB;AAED;;;GAGG;AACH,MAAM,WAAW,SAAS;IACxB,KAAK,EAAE,UAAU,CAAA;IACjB,QAAQ,EAAE,QAAQ,CAAA;CACnB;AAED;;GAEG;AACH,wBAAgB,0BAA0B,CACxC,UAAU,EAAE,OAAO,CAAC,oBAAoB,EAAE,oBAAoB,CAAC,MAAM,CAAC,GACrE,YAAY,CAAC,MAAM,GAAG,YAAY,CAAC,MAAM,CAS3C"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { TopicValidatorResult } from "./index.js";
|
|
2
|
+
export var SignaturePolicy;
|
|
3
|
+
(function (SignaturePolicy) {
|
|
4
|
+
/**
|
|
5
|
+
* On the producing side:
|
|
6
|
+
* - Build messages with the signature, key (from may be enough for certain inlineable public key types), from and seqno fields.
|
|
7
|
+
*
|
|
8
|
+
* On the consuming side:
|
|
9
|
+
* - Enforce the fields to be present, reject otherwise.
|
|
10
|
+
* - Propagate only if the fields are valid and signature can be verified, reject otherwise.
|
|
11
|
+
*/
|
|
12
|
+
SignaturePolicy["StrictSign"] = "StrictSign";
|
|
13
|
+
/**
|
|
14
|
+
* On the producing side:
|
|
15
|
+
* - Build messages without the signature, key, from and seqno fields.
|
|
16
|
+
* - The corresponding protobuf key-value pairs are absent from the marshalled message, not just empty.
|
|
17
|
+
*
|
|
18
|
+
* On the consuming side:
|
|
19
|
+
* - Enforce the fields to be absent, reject otherwise.
|
|
20
|
+
* - Propagate only if the fields are absent, reject otherwise.
|
|
21
|
+
* - A message_id function will not be able to use the above fields, and should instead rely on the data field. A commonplace strategy is to calculate a hash.
|
|
22
|
+
*/
|
|
23
|
+
SignaturePolicy["StrictNoSign"] = "StrictNoSign";
|
|
24
|
+
})(SignaturePolicy || (SignaturePolicy = {}));
|
|
25
|
+
export var PublishConfigType;
|
|
26
|
+
(function (PublishConfigType) {
|
|
27
|
+
PublishConfigType[PublishConfigType["Signing"] = 0] = "Signing";
|
|
28
|
+
PublishConfigType[PublishConfigType["Anonymous"] = 1] = "Anonymous";
|
|
29
|
+
})(PublishConfigType || (PublishConfigType = {}));
|
|
30
|
+
export var RejectReason;
|
|
31
|
+
(function (RejectReason) {
|
|
32
|
+
/**
|
|
33
|
+
* The message failed the configured validation during decoding.
|
|
34
|
+
* SelfOrigin is considered a ValidationError
|
|
35
|
+
*/
|
|
36
|
+
RejectReason["Error"] = "error";
|
|
37
|
+
/**
|
|
38
|
+
* Custom validator fn reported status IGNORE.
|
|
39
|
+
*/
|
|
40
|
+
RejectReason["Ignore"] = "ignore";
|
|
41
|
+
/**
|
|
42
|
+
* Custom validator fn reported status REJECT.
|
|
43
|
+
*/
|
|
44
|
+
RejectReason["Reject"] = "reject";
|
|
45
|
+
/**
|
|
46
|
+
* The peer that sent the message OR the source from field is blacklisted.
|
|
47
|
+
* Causes messages to be ignored, not penalized, neither do score record creation.
|
|
48
|
+
*/
|
|
49
|
+
RejectReason["Blacklisted"] = "blacklisted";
|
|
50
|
+
})(RejectReason || (RejectReason = {}));
|
|
51
|
+
export var ValidateError;
|
|
52
|
+
(function (ValidateError) {
|
|
53
|
+
/// The message has an invalid signature,
|
|
54
|
+
ValidateError["InvalidSignature"] = "invalid_signature";
|
|
55
|
+
/// The sequence number was the incorrect size
|
|
56
|
+
ValidateError["InvalidSeqno"] = "invalid_seqno";
|
|
57
|
+
/// The PeerId was invalid
|
|
58
|
+
ValidateError["InvalidPeerId"] = "invalid_peerid";
|
|
59
|
+
/// Signature existed when validation has been sent to
|
|
60
|
+
/// [`crate::behaviour::MessageAuthenticity::Anonymous`].
|
|
61
|
+
ValidateError["SignaturePresent"] = "signature_present";
|
|
62
|
+
/// Sequence number existed when validation has been sent to
|
|
63
|
+
/// [`crate::behaviour::MessageAuthenticity::Anonymous`].
|
|
64
|
+
ValidateError["SeqnoPresent"] = "seqno_present";
|
|
65
|
+
/// Message source existed when validation has been sent to
|
|
66
|
+
/// [`crate::behaviour::MessageAuthenticity::Anonymous`].
|
|
67
|
+
ValidateError["FromPresent"] = "from_present";
|
|
68
|
+
/// The data transformation failed.
|
|
69
|
+
ValidateError["TransformFailed"] = "transform_failed";
|
|
70
|
+
})(ValidateError || (ValidateError = {}));
|
|
71
|
+
export var MessageStatus;
|
|
72
|
+
(function (MessageStatus) {
|
|
73
|
+
MessageStatus["duplicate"] = "duplicate";
|
|
74
|
+
MessageStatus["invalid"] = "invalid";
|
|
75
|
+
MessageStatus["valid"] = "valid";
|
|
76
|
+
})(MessageStatus || (MessageStatus = {}));
|
|
77
|
+
/**
|
|
78
|
+
* Typesafe conversion of MessageAcceptance -> RejectReason. TS ensures all values covered
|
|
79
|
+
*/
|
|
80
|
+
export function rejectReasonFromAcceptance(acceptance) {
|
|
81
|
+
switch (acceptance) {
|
|
82
|
+
case TopicValidatorResult.Ignore:
|
|
83
|
+
return RejectReason.Ignore;
|
|
84
|
+
case TopicValidatorResult.Reject:
|
|
85
|
+
return RejectReason.Reject;
|
|
86
|
+
default:
|
|
87
|
+
throw new Error('Unreachable');
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAmDjD,MAAM,CAAN,IAAY,eAqBX;AArBD,WAAY,eAAe;IACzB;;;;;;;OAOG;IACH,4CAAyB,CAAA;IACzB;;;;;;;;;OASG;IACH,gDAA6B,CAAA;AAC/B,CAAC,EArBW,eAAe,KAAf,eAAe,QAqB1B;AAiBD,MAAM,CAAN,IAAY,iBAGX;AAHD,WAAY,iBAAiB;IAC3B,+DAAO,CAAA;IACP,mEAAS,CAAA;AACX,CAAC,EAHW,iBAAiB,KAAjB,iBAAiB,QAG5B;AAeD,MAAM,CAAN,IAAY,YAmBX;AAnBD,WAAY,YAAY;IACtB;;;OAGG;IACH,+BAAe,CAAA;IACf;;OAEG;IACH,iCAAiB,CAAA;IACjB;;OAEG;IACH,iCAAiB,CAAA;IACjB;;;OAGG;IACH,2CAA2B,CAAA;AAC7B,CAAC,EAnBW,YAAY,KAAZ,YAAY,QAmBvB;AAED,MAAM,CAAN,IAAY,aAkBX;AAlBD,WAAY,aAAa;IACvB,yCAAyC;IACzC,uDAAsC,CAAA;IACtC,8CAA8C;IAC9C,+CAA8B,CAAA;IAC9B,0BAA0B;IAC1B,iDAAgC,CAAA;IAChC,sDAAsD;IACtD,yDAAyD;IACzD,uDAAsC,CAAA;IACtC,4DAA4D;IAC5D,yDAAyD;IACzD,+CAA8B,CAAA;IAC9B,2DAA2D;IAC3D,yDAAyD;IACzD,6CAA4B,CAAA;IAC5B,mCAAmC;IACnC,qDAAoC,CAAA;AACtC,CAAC,EAlBW,aAAa,KAAb,aAAa,QAkBxB;AAED,MAAM,CAAN,IAAY,aAIX;AAJD,WAAY,aAAa;IACvB,wCAAuB,CAAA;IACvB,oCAAmB,CAAA;IACnB,gCAAe,CAAA;AACjB,CAAC,EAJW,aAAa,KAAb,aAAa,QAIxB;AAWD;;GAEG;AACH,MAAM,UAAU,0BAA0B,CACxC,UAAsE;IAEtE,QAAQ,UAAU,EAAE,CAAC;QACnB,KAAK,oBAAoB,CAAC,MAAM;YAC9B,OAAO,YAAY,CAAC,MAAM,CAAA;QAC5B,KAAK,oBAAoB,CAAC,MAAM;YAC9B,OAAO,YAAY,CAAC,MAAM,CAAA;QAC5B;YACE,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,CAAA;IAClC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { StrictSign, StrictNoSign } from '../index.ts';
|
|
2
|
+
import { RPC } from '../message/rpc.js';
|
|
3
|
+
import { ValidateError } from '../types.js';
|
|
4
|
+
import type { Message } from '../index.ts';
|
|
5
|
+
import type { PublishConfig, TopicStr } from '../types.js';
|
|
6
|
+
export declare const SignPrefix: Uint8Array<ArrayBufferLike>;
|
|
7
|
+
export interface RawMessageAndMessage {
|
|
8
|
+
raw: RPC.Message;
|
|
9
|
+
msg: Message;
|
|
10
|
+
}
|
|
11
|
+
export declare function buildRawMessage(publishConfig: PublishConfig, topic: TopicStr, originalData: Uint8Array, transformedData: Uint8Array): Promise<RawMessageAndMessage>;
|
|
12
|
+
export type ValidationResult = {
|
|
13
|
+
valid: true;
|
|
14
|
+
message: Message;
|
|
15
|
+
} | {
|
|
16
|
+
valid: false;
|
|
17
|
+
error: ValidateError;
|
|
18
|
+
};
|
|
19
|
+
export declare function validateToRawMessage(signaturePolicy: typeof StrictNoSign | typeof StrictSign, msg: RPC.Message): Promise<ValidationResult>;
|
|
20
|
+
//# sourceMappingURL=buildRawMessage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildRawMessage.d.ts","sourceRoot":"","sources":["../../../src/utils/buildRawMessage.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AACtD,OAAO,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAA;AACvC,OAAO,EAAqB,aAAa,EAAE,MAAM,aAAa,CAAA;AAC9D,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAC1C,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAA;AAG1D,eAAO,MAAM,UAAU,6BAAyC,CAAA;AAEhE,MAAM,WAAW,oBAAoB;IACnC,GAAG,EAAE,GAAG,CAAC,OAAO,CAAA;IAChB,GAAG,EAAE,OAAO,CAAA;CACb;AAED,wBAAsB,eAAe,CACnC,aAAa,EAAE,aAAa,EAC5B,KAAK,EAAE,QAAQ,EACf,YAAY,EAAE,UAAU,EACxB,eAAe,EAAE,UAAU,GAC1B,OAAO,CAAC,oBAAoB,CAAC,CAuD/B;AAED,MAAM,MAAM,gBAAgB,GAAG;IAAE,KAAK,EAAE,IAAI,CAAC;IAAC,OAAO,EAAE,OAAO,CAAA;CAAE,GAAG;IAAE,KAAK,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,aAAa,CAAA;CAAE,CAAA;AAEzG,wBAAsB,oBAAoB,CACxC,eAAe,EAAE,OAAO,YAAY,GAAG,OAAO,UAAU,EACxD,GAAG,EAAE,GAAG,CAAC,OAAO,GACf,OAAO,CAAC,gBAAgB,CAAC,CAqF3B"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { randomBytes } from '@libp2p/crypto';
|
|
2
|
+
import { publicKeyFromProtobuf } from '@libp2p/crypto/keys';
|
|
3
|
+
import { peerIdFromMultihash } from '@libp2p/peer-id';
|
|
4
|
+
import * as Digest from 'multiformats/hashes/digest';
|
|
5
|
+
import { concat as uint8ArrayConcat } from 'uint8arrays/concat';
|
|
6
|
+
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
|
|
7
|
+
import { toString as uint8ArrayToString } from 'uint8arrays/to-string';
|
|
8
|
+
import { StrictSign, StrictNoSign } from "../index.js";
|
|
9
|
+
import { RPC } from '../message/rpc.js';
|
|
10
|
+
import { PublishConfigType, ValidateError } from '../types.js';
|
|
11
|
+
export const SignPrefix = uint8ArrayFromString('libp2p-pubsub:');
|
|
12
|
+
export async function buildRawMessage(publishConfig, topic, originalData, transformedData) {
|
|
13
|
+
switch (publishConfig.type) {
|
|
14
|
+
case PublishConfigType.Signing: {
|
|
15
|
+
const rpcMsg = {
|
|
16
|
+
from: publishConfig.author.toMultihash().bytes,
|
|
17
|
+
data: transformedData,
|
|
18
|
+
seqno: randomBytes(8),
|
|
19
|
+
topic,
|
|
20
|
+
signature: undefined, // Exclude signature field for signing
|
|
21
|
+
key: undefined // Exclude key field for signing
|
|
22
|
+
};
|
|
23
|
+
// Get the message in bytes, and prepend with the pubsub prefix
|
|
24
|
+
// the signature is over the bytes "libp2p-pubsub:<protobuf-message>"
|
|
25
|
+
const bytes = uint8ArrayConcat([SignPrefix, RPC.Message.encode(rpcMsg)]);
|
|
26
|
+
rpcMsg.signature = await publishConfig.privateKey.sign(bytes);
|
|
27
|
+
rpcMsg.key = publishConfig.key;
|
|
28
|
+
const msg = {
|
|
29
|
+
type: 'signed',
|
|
30
|
+
from: publishConfig.author,
|
|
31
|
+
data: originalData,
|
|
32
|
+
sequenceNumber: BigInt(`0x${uint8ArrayToString(rpcMsg.seqno ?? new Uint8Array(0), 'base16')}`),
|
|
33
|
+
topic,
|
|
34
|
+
signature: rpcMsg.signature,
|
|
35
|
+
key: publicKeyFromProtobuf(rpcMsg.key)
|
|
36
|
+
};
|
|
37
|
+
return {
|
|
38
|
+
raw: rpcMsg,
|
|
39
|
+
msg
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
case PublishConfigType.Anonymous: {
|
|
43
|
+
return {
|
|
44
|
+
raw: {
|
|
45
|
+
from: undefined,
|
|
46
|
+
data: transformedData,
|
|
47
|
+
seqno: undefined,
|
|
48
|
+
topic,
|
|
49
|
+
signature: undefined,
|
|
50
|
+
key: undefined
|
|
51
|
+
},
|
|
52
|
+
msg: {
|
|
53
|
+
type: 'unsigned',
|
|
54
|
+
data: originalData,
|
|
55
|
+
topic
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
default:
|
|
60
|
+
throw new Error('Unreachable');
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
export async function validateToRawMessage(signaturePolicy, msg) {
|
|
64
|
+
// If strict-sign, verify all
|
|
65
|
+
// If anonymous (no-sign), ensure no preven
|
|
66
|
+
switch (signaturePolicy) {
|
|
67
|
+
case StrictNoSign:
|
|
68
|
+
if (msg.signature != null) {
|
|
69
|
+
return { valid: false, error: ValidateError.SignaturePresent };
|
|
70
|
+
}
|
|
71
|
+
if (msg.seqno != null) {
|
|
72
|
+
return { valid: false, error: ValidateError.SeqnoPresent };
|
|
73
|
+
}
|
|
74
|
+
if (msg.key != null) {
|
|
75
|
+
return { valid: false, error: ValidateError.FromPresent };
|
|
76
|
+
}
|
|
77
|
+
return { valid: true, message: { type: 'unsigned', topic: msg.topic, data: msg.data ?? new Uint8Array(0) } };
|
|
78
|
+
case StrictSign: {
|
|
79
|
+
// Verify seqno
|
|
80
|
+
if (msg.seqno == null) {
|
|
81
|
+
return { valid: false, error: ValidateError.InvalidSeqno };
|
|
82
|
+
}
|
|
83
|
+
if (msg.seqno.length !== 8) {
|
|
84
|
+
return { valid: false, error: ValidateError.InvalidSeqno };
|
|
85
|
+
}
|
|
86
|
+
if (msg.signature == null) {
|
|
87
|
+
return { valid: false, error: ValidateError.InvalidSignature };
|
|
88
|
+
}
|
|
89
|
+
if (msg.from == null) {
|
|
90
|
+
return { valid: false, error: ValidateError.InvalidPeerId };
|
|
91
|
+
}
|
|
92
|
+
let fromPeerId;
|
|
93
|
+
try {
|
|
94
|
+
// TODO: Fix PeerId types
|
|
95
|
+
fromPeerId = peerIdFromMultihash(Digest.decode(msg.from));
|
|
96
|
+
}
|
|
97
|
+
catch (e) {
|
|
98
|
+
return { valid: false, error: ValidateError.InvalidPeerId };
|
|
99
|
+
}
|
|
100
|
+
// - check from defined
|
|
101
|
+
// - transform source to PeerId
|
|
102
|
+
// - parse signature
|
|
103
|
+
// - get .key, else from source
|
|
104
|
+
// - check key == source if present
|
|
105
|
+
// - verify sig
|
|
106
|
+
let publicKey;
|
|
107
|
+
if (msg.key != null) {
|
|
108
|
+
publicKey = publicKeyFromProtobuf(msg.key);
|
|
109
|
+
// TODO: Should `fromPeerId.pubKey` be optional?
|
|
110
|
+
if (fromPeerId.publicKey !== undefined && !publicKey.equals(fromPeerId.publicKey)) {
|
|
111
|
+
return { valid: false, error: ValidateError.InvalidPeerId };
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
if (fromPeerId.publicKey == null) {
|
|
116
|
+
return { valid: false, error: ValidateError.InvalidPeerId };
|
|
117
|
+
}
|
|
118
|
+
publicKey = fromPeerId.publicKey;
|
|
119
|
+
}
|
|
120
|
+
const rpcMsgPreSign = {
|
|
121
|
+
from: msg.from,
|
|
122
|
+
data: msg.data,
|
|
123
|
+
seqno: msg.seqno,
|
|
124
|
+
topic: msg.topic,
|
|
125
|
+
signature: undefined, // Exclude signature field for signing
|
|
126
|
+
key: undefined // Exclude key field for signing
|
|
127
|
+
};
|
|
128
|
+
// Get the message in bytes, and prepend with the pubsub prefix
|
|
129
|
+
// the signature is over the bytes "libp2p-pubsub:<protobuf-message>"
|
|
130
|
+
const bytes = uint8ArrayConcat([SignPrefix, RPC.Message.encode(rpcMsgPreSign)]);
|
|
131
|
+
if (!(await publicKey.verify(bytes, msg.signature))) {
|
|
132
|
+
return { valid: false, error: ValidateError.InvalidSignature };
|
|
133
|
+
}
|
|
134
|
+
return {
|
|
135
|
+
valid: true,
|
|
136
|
+
message: {
|
|
137
|
+
type: 'signed',
|
|
138
|
+
from: fromPeerId,
|
|
139
|
+
data: msg.data ?? new Uint8Array(0),
|
|
140
|
+
sequenceNumber: BigInt(`0x${uint8ArrayToString(msg.seqno, 'base16')}`),
|
|
141
|
+
topic: msg.topic,
|
|
142
|
+
signature: msg.signature,
|
|
143
|
+
key: msg.key != null ? publicKeyFromProtobuf(msg.key) : publicKey
|
|
144
|
+
}
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
default:
|
|
148
|
+
throw new Error('Unreachable');
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=buildRawMessage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buildRawMessage.js","sourceRoot":"","sources":["../../../src/utils/buildRawMessage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAC5C,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAA;AAC3D,OAAO,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,KAAK,MAAM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AC,CAAC,CAAA;YAE/E,IAAI,CAAC,CAAC,MAAM,SAAS,CAAC,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC;gBACpD,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,aAAa,CAAC,gBAAgB,EAAE,CAAA;YAChE,CAAC;YAED,OAAO;gBACL,KAAK,EAAE,IAAI;gBACX,OAAO,EAAE;oBACP,IAAI,EAAE,QAAQ;oBACd,IAAI,EAAE,UAAU;oBAChB,IAAI,EAAE,GAAG,CAAC,IAAI,IAAI,IAAI,UAAU,CAAC,CAAC,CAAC;oBACnC,cAAc,EAAE,MAAM,CAAC,KAAK,kBAAkB,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,EAAE,CAAC;oBACtE,KAAK,EAAE,GAAG,CAAC,KAAK;oBAChB,SAAS,EAAE,GAAG,CAAC,SAAS;oBACxB,GAAG,EAAE,GAAG,CAAC,GAAG,IAAI,IAAI,CAAC,CAAC,CAAC,qBAAqB,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS;iBAClE;aACF,CAAA;QACH,CAAC;QAED;YACE,MAAM,IAAI,KAAK,CAAC,aAAa,CAAC,CAAA;IAClC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { RPC } from '../message/rpc.js';
|
|
2
|
+
/**
|
|
3
|
+
* Create a gossipsub RPC object
|
|
4
|
+
*/
|
|
5
|
+
export declare function createGossipRpc(messages?: RPC.Message[], control?: Partial<RPC.ControlMessage>): RPC;
|
|
6
|
+
export declare function ensureControl(rpc: RPC): Required<RPC>;
|
|
7
|
+
//# sourceMappingURL=create-gossip-rpc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-gossip-rpc.d.ts","sourceRoot":"","sources":["../../../src/utils/create-gossip-rpc.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,mBAAmB,CAAA;AAE5C;;GAEG;AACH,wBAAgB,eAAe,CAAE,QAAQ,GAAE,GAAG,CAAC,OAAO,EAAO,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC,GAAG,GAAG,CAczG;AAED,wBAAgB,aAAa,CAAE,GAAG,EAAE,GAAG,GAAG,QAAQ,CAAC,GAAG,CAAC,CAYtD"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a gossipsub RPC object
|
|
3
|
+
*/
|
|
4
|
+
export function createGossipRpc(messages = [], control) {
|
|
5
|
+
return {
|
|
6
|
+
subscriptions: [],
|
|
7
|
+
messages,
|
|
8
|
+
control: control !== undefined
|
|
9
|
+
? {
|
|
10
|
+
graft: control.graft ?? [],
|
|
11
|
+
prune: control.prune ?? [],
|
|
12
|
+
ihave: control.ihave ?? [],
|
|
13
|
+
iwant: control.iwant ?? [],
|
|
14
|
+
idontwant: control.idontwant ?? []
|
|
15
|
+
}
|
|
16
|
+
: undefined
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
export function ensureControl(rpc) {
|
|
20
|
+
if (rpc.control === undefined) {
|
|
21
|
+
rpc.control = {
|
|
22
|
+
graft: [],
|
|
23
|
+
prune: [],
|
|
24
|
+
ihave: [],
|
|
25
|
+
iwant: [],
|
|
26
|
+
idontwant: []
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
return rpc;
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=create-gossip-rpc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"create-gossip-rpc.js","sourceRoot":"","sources":["../../../src/utils/create-gossip-rpc.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,UAAU,eAAe,CAAE,WAA0B,EAAE,EAAE,OAAqC;IAClG,OAAO;QACL,aAAa,EAAE,EAAE;QACjB,QAAQ;QACR,OAAO,EAAE,OAAO,KAAK,SAAS;YAC5B,CAAC,CAAC;gBACE,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,EAAE;gBAC1B,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,EAAE;gBAC1B,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,EAAE;gBAC1B,KAAK,EAAE,OAAO,CAAC,KAAK,IAAI,EAAE;gBAC1B,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,EAAE;aACnC;YACH,CAAC,CAAC,SAAS;KACd,CAAA;AACH,CAAC;AAED,MAAM,UAAU,aAAa,CAAE,GAAQ;IACrC,IAAI,GAAG,CAAC,OAAO,KAAK,SAAS,EAAE,CAAC;QAC9B,GAAG,CAAC,OAAO,GAAG;YACZ,KAAK,EAAE,EAAE;YACT,KAAK,EAAE,EAAE;YACT,KAAK,EAAE,EAAE;YACT,KAAK,EAAE,EAAE;YACT,SAAS,EAAE,EAAE;SACd,CAAA;IACH,CAAC;IAED,OAAO,GAAoB,CAAA;AAC7B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,wBAAwB,CAAA;AACtC,OAAO,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,wBAAwB,CAAA;AACtC,OAAO,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messageIdToString.d.ts","sourceRoot":"","sources":["../../../src/utils/messageIdToString.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,wBAAgB,iBAAiB,CAAE,KAAK,EAAE,UAAU,GAAG,MAAM,CAE5D"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { toString } from 'uint8arrays/to-string';
|
|
2
|
+
/**
|
|
3
|
+
* Browser friendly function to convert Uint8Array message id to base64 string.
|
|
4
|
+
*/
|
|
5
|
+
export function messageIdToString(msgId) {
|
|
6
|
+
return toString(msgId, 'base64');
|
|
7
|
+
}
|
|
8
|
+
//# sourceMappingURL=messageIdToString.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"messageIdToString.js","sourceRoot":"","sources":["../../../src/utils/messageIdToString.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAA;AAEhD;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAE,KAAiB;IAClD,OAAO,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;AAClC,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Message } from '../index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Generate a message id, based on the `key` and `seqno`
|
|
4
|
+
*/
|
|
5
|
+
export declare function msgIdFnStrictSign(msg: Message): Uint8Array;
|
|
6
|
+
/**
|
|
7
|
+
* Generate a message id, based on message `data`
|
|
8
|
+
*/
|
|
9
|
+
export declare function msgIdFnStrictNoSign(msg: Message): Promise<Uint8Array>;
|
|
10
|
+
//# sourceMappingURL=msgIdFn.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"msgIdFn.d.ts","sourceRoot":"","sources":["../../../src/utils/msgIdFn.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAA;AAE1C;;GAEG;AACH,wBAAgB,iBAAiB,CAAE,GAAG,EAAE,OAAO,GAAG,UAAU,CAS3D;AAED;;GAEG;AACH,wBAAsB,mBAAmB,CAAE,GAAG,EAAE,OAAO,GAAG,OAAO,CAAC,UAAU,CAAC,CAE5E"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { msgId } from '@libp2p/pubsub/utils';
|
|
2
|
+
import { sha256 } from 'multiformats/hashes/sha2';
|
|
3
|
+
/**
|
|
4
|
+
* Generate a message id, based on the `key` and `seqno`
|
|
5
|
+
*/
|
|
6
|
+
export function msgIdFnStrictSign(msg) {
|
|
7
|
+
if (msg.type !== 'signed') {
|
|
8
|
+
throw new Error('expected signed message type');
|
|
9
|
+
}
|
|
10
|
+
// Should never happen
|
|
11
|
+
if (msg.sequenceNumber == null) {
|
|
12
|
+
throw Error('missing seqno field');
|
|
13
|
+
}
|
|
14
|
+
// TODO: Should use .from here or key?
|
|
15
|
+
return msgId(msg.from.publicKey ?? msg.key, msg.sequenceNumber);
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Generate a message id, based on message `data`
|
|
19
|
+
*/
|
|
20
|
+
export async function msgIdFnStrictNoSign(msg) {
|
|
21
|
+
return sha256.encode(msg.data);
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=msgIdFn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"msgIdFn.js","sourceRoot":"","sources":["../../../src/utils/msgIdFn.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,0BAA0B,CAAA;AAGjD;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAE,GAAY;IAC7C,IAAI,GAAG,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC1B,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAA;IACjD,CAAC;IACD,sBAAsB;IACtB,IAAI,GAAG,CAAC,cAAc,IAAI,IAAI,EAAE,CAAC;QAAC,MAAM,KAAK,CAAC,qBAAqB,CAAC,CAAA;IAAC,CAAC;IAEtE,sCAAsC;IACtC,OAAO,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,IAAI,GAAG,CAAC,GAAG,EAAE,GAAG,CAAC,cAAc,CAAC,CAAA;AACjE,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CAAE,GAAY;IACrD,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;AAChC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multiaddr.d.ts","sourceRoot":"","sources":["../../../src/utils/multiaddr.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAExD,wBAAgB,gBAAgB,CAAE,SAAS,EAAE,SAAS,GAAG,MAAM,GAAG,IAAI,CAerE"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { getNetConfig, isNetworkAddress } from '@libp2p/utils';
|
|
2
|
+
export function multiaddrToIPStr(multiaddr) {
|
|
3
|
+
if (isNetworkAddress(multiaddr)) {
|
|
4
|
+
const config = getNetConfig(multiaddr);
|
|
5
|
+
switch (config.type) {
|
|
6
|
+
case 'ip4':
|
|
7
|
+
case 'ip6':
|
|
8
|
+
return config.host;
|
|
9
|
+
default:
|
|
10
|
+
break;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=multiaddr.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"multiaddr.js","sourceRoot":"","sources":["../../../src/utils/multiaddr.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAG9D,MAAM,UAAU,gBAAgB,CAAE,SAAoB;IACpD,IAAI,gBAAgB,CAAC,SAAS,CAAC,EAAE,CAAC;QAChC,MAAM,MAAM,GAAG,YAAY,CAAC,SAAS,CAAC,CAAA;QAEtC,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;YACpB,KAAK,KAAK,CAAC;YACX,KAAK,KAAK;gBAER,OAAO,MAAM,CAAC,IAAI,CAAA;YACpB;gBACE,MAAK;QACT,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAA;AACb,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { StrictSign, StrictNoSign } from '../index.ts';
|
|
2
|
+
import type { PublishConfig } from '../types.js';
|
|
3
|
+
import type { PeerId, PrivateKey } from '@libp2p/interface';
|
|
4
|
+
/**
|
|
5
|
+
* Prepare a PublishConfig object from a PeerId.
|
|
6
|
+
*/
|
|
7
|
+
export declare function getPublishConfigFromPeerId(signaturePolicy: typeof StrictSign | typeof StrictNoSign, peerId: PeerId, privateKey: PrivateKey): PublishConfig;
|
|
8
|
+
//# sourceMappingURL=publishConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publishConfig.d.ts","sourceRoot":"","sources":["../../../src/utils/publishConfig.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAEtD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAA;AAE3D;;GAEG;AACH,wBAAgB,0BAA0B,CACxC,eAAe,EAAE,OAAO,UAAU,GAAG,OAAO,YAAY,EACxD,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,UAAU,GACrB,aAAa,CAmBf"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { publicKeyToProtobuf } from '@libp2p/crypto/keys';
|
|
2
|
+
import { StrictSign, StrictNoSign } from "../index.js";
|
|
3
|
+
import { PublishConfigType } from '../types.js';
|
|
4
|
+
/**
|
|
5
|
+
* Prepare a PublishConfig object from a PeerId.
|
|
6
|
+
*/
|
|
7
|
+
export function getPublishConfigFromPeerId(signaturePolicy, peerId, privateKey) {
|
|
8
|
+
switch (signaturePolicy) {
|
|
9
|
+
case StrictSign: {
|
|
10
|
+
return {
|
|
11
|
+
type: PublishConfigType.Signing,
|
|
12
|
+
author: peerId,
|
|
13
|
+
key: publicKeyToProtobuf(privateKey.publicKey),
|
|
14
|
+
privateKey
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
case StrictNoSign:
|
|
18
|
+
return {
|
|
19
|
+
type: PublishConfigType.Anonymous
|
|
20
|
+
};
|
|
21
|
+
default:
|
|
22
|
+
throw new Error(`Unknown signature policy "${signaturePolicy}"`);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=publishConfig.js.map
|