@libp2p/floodsub 11.0.25 → 11.0.26-02fcf704d

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.
@@ -1,6 +1,7 @@
1
1
  import { pbStream } from '@libp2p/utils'
2
2
  import { TypedEventEmitter } from 'main-event'
3
3
  import { RPC } from './message/rpc.ts'
4
+ import type { RPCDecodeLimits } from './decodeRpc.ts'
4
5
  import type { PubSubRPC } from './floodsub.ts'
5
6
  import type { PeerStreamsEvents } from './index.ts'
6
7
  import type { Stream, PeerId } from '@libp2p/interface'
@@ -38,7 +39,7 @@ export class PeerStreams extends TypedEventEmitter<PeerStreamsEvents> {
38
39
  this.shutDownController = new AbortController()
39
40
  }
40
41
 
41
- attachInboundStream (stream: Stream, streamOpts?: Partial<ProtobufStreamOpts>): void {
42
+ attachInboundStream (stream: Stream, streamOpts?: Partial<ProtobufStreamOpts>, decodeRpcLimits?: RPCDecodeLimits): void {
42
43
  this.inboundPb = pbStream(stream, streamOpts).pb(RPC)
43
44
 
44
45
  Promise.resolve().then(async () => {
@@ -48,7 +49,8 @@ export class PeerStreams extends TypedEventEmitter<PeerStreamsEvents> {
48
49
  }
49
50
 
50
51
  const message = await this.inboundPb.read({
51
- signal: this.shutDownController.signal
52
+ signal: this.shutDownController.signal,
53
+ limits: decodeRpcLimits
52
54
  })
53
55
 
54
56
  this.safeDispatchEvent('message', {
@@ -57,7 +59,11 @@ export class PeerStreams extends TypedEventEmitter<PeerStreamsEvents> {
57
59
  }
58
60
  })
59
61
  .catch(err => {
62
+ // the inbound stream errored (e.g. a frame exceeded the decode limits):
63
+ // reset it and close the peer so floodsub removes it instead of leaving
64
+ // a half-open peer with a dead inbound stream
60
65
  this.inboundPb?.unwrap().unwrap().abort(err)
66
+ this.close()
61
67
  })
62
68
  }
63
69
 
package/src/sign.ts CHANGED
@@ -80,14 +80,18 @@ export function messagePublicKey (message: SignedMessage): PublicKey {
80
80
  throw new Error('Could not get the public key from the originator id')
81
81
  }
82
82
 
83
- if (message.key != null) {
84
- return message.key
85
- }
86
-
83
+ // an Ed25519/secp256k1 peer id embeds its own public key, so a key recovered
84
+ // from `from` is provably the author's; trust it over the supplied message.key
87
85
  if (message.from.publicKey != null) {
88
86
  return message.from.publicKey
89
87
  }
90
88
 
89
+ // otherwise the supplied key must derive to the from peer id, else a message
90
+ // could be signed by one key while claiming a different author
91
+ if (message.key != null && message.from.equals(message.key.toMultihash().bytes)) {
92
+ return message.key
93
+ }
94
+
91
95
  // We couldn't validate pubkey is from the originator, error
92
96
  throw new Error('Could not get the public key from the originator id')
93
97
  }
@@ -1,41 +0,0 @@
1
- {
2
- "TopicValidatorResult": "https://libp2p.github.io/js-libp2p/enums/_libp2p_floodsub.TopicValidatorResult.html",
3
- ".:TopicValidatorResult": "https://libp2p.github.io/js-libp2p/enums/_libp2p_floodsub.TopicValidatorResult.html",
4
- "FloodSub": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_floodsub.FloodSub.html",
5
- ".:FloodSub": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_floodsub.FloodSub.html",
6
- "FloodSubComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_floodsub.FloodSubComponents.html",
7
- ".:FloodSubComponents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_floodsub.FloodSubComponents.html",
8
- "FloodSubEvents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_floodsub.FloodSubEvents.html",
9
- ".:FloodSubEvents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_floodsub.FloodSubEvents.html",
10
- "FloodSubInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_floodsub.FloodSubInit.html",
11
- ".:FloodSubInit": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_floodsub.FloodSubInit.html",
12
- "PeerStreamsEvents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_floodsub.PeerStreamsEvents.html",
13
- ".:PeerStreamsEvents": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_floodsub.PeerStreamsEvents.html",
14
- "PublishResult": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_floodsub.PublishResult.html",
15
- ".:PublishResult": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_floodsub.PublishResult.html",
16
- "SignedMessage": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_floodsub.SignedMessage.html",
17
- ".:SignedMessage": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_floodsub.SignedMessage.html",
18
- "Subscription": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_floodsub.Subscription.html",
19
- ".:Subscription": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_floodsub.Subscription.html",
20
- "SubscriptionChangeData": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_floodsub.SubscriptionChangeData.html",
21
- ".:SubscriptionChangeData": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_floodsub.SubscriptionChangeData.html",
22
- "TopicValidatorFn": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_floodsub.TopicValidatorFn.html",
23
- ".:TopicValidatorFn": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_floodsub.TopicValidatorFn.html",
24
- "UnsignedMessage": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_floodsub.UnsignedMessage.html",
25
- ".:UnsignedMessage": "https://libp2p.github.io/js-libp2p/interfaces/_libp2p_floodsub.UnsignedMessage.html",
26
- "Message": "https://libp2p.github.io/js-libp2p/types/_libp2p_floodsub.Message.html",
27
- ".:Message": "https://libp2p.github.io/js-libp2p/types/_libp2p_floodsub.Message.html",
28
- "SignaturePolicy": "https://libp2p.github.io/js-libp2p/types/_libp2p_floodsub.SignaturePolicy.html",
29
- ".:SignaturePolicy": "https://libp2p.github.io/js-libp2p/types/_libp2p_floodsub.SignaturePolicy.html",
30
- "protocol": "https://libp2p.github.io/js-libp2p/variables/_libp2p_floodsub.protocol.html",
31
- ".:protocol": "https://libp2p.github.io/js-libp2p/variables/_libp2p_floodsub.protocol.html",
32
- "pubSubSymbol": "https://libp2p.github.io/js-libp2p/variables/_libp2p_floodsub.pubSubSymbol.html",
33
- "StrictNoSign": "https://libp2p.github.io/js-libp2p/variables/_libp2p_floodsub.StrictNoSign.html",
34
- ".:StrictNoSign": "https://libp2p.github.io/js-libp2p/variables/_libp2p_floodsub.StrictNoSign.html",
35
- "StrictSign": "https://libp2p.github.io/js-libp2p/variables/_libp2p_floodsub.StrictSign.html",
36
- ".:StrictSign": "https://libp2p.github.io/js-libp2p/variables/_libp2p_floodsub.StrictSign.html",
37
- "floodsub": "https://libp2p.github.io/js-libp2p/functions/_libp2p_floodsub.floodsub.html",
38
- ".:floodsub": "https://libp2p.github.io/js-libp2p/functions/_libp2p_floodsub.floodsub.html",
39
- "isPubSub": "https://libp2p.github.io/js-libp2p/functions/_libp2p_floodsub.isPubSub.html",
40
- ".:isPubSub": "https://libp2p.github.io/js-libp2p/functions/_libp2p_floodsub.isPubSub.html"
41
- }