@libp2p/floodsub 11.0.31-e48eabf67 → 11.0.32-2d4c93ed6
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/dist/index.min.js +1 -1
- package/dist/index.min.js.map +4 -4
- package/dist/src/sign.d.ts +4 -8
- package/dist/src/sign.d.ts.map +1 -1
- package/dist/src/sign.js +15 -29
- package/dist/src/sign.js.map +1 -1
- package/package.json +9 -9
- package/src/sign.ts +15 -33
package/dist/src/sign.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { PubSubRPCMessage } from './floodsub.ts';
|
|
2
2
|
import type { SignedMessage } from './index.ts';
|
|
3
|
-
import type { PeerId, PrivateKey
|
|
3
|
+
import type { PeerId, PrivateKey } from '@libp2p/interface';
|
|
4
4
|
export declare const SignPrefix: Uint8Array<ArrayBuffer>;
|
|
5
5
|
/**
|
|
6
|
-
* Signs the provided message with the given
|
|
6
|
+
* Signs the provided message with the given private key
|
|
7
7
|
*/
|
|
8
8
|
export declare function signMessage(privateKey: PrivateKey, message: {
|
|
9
9
|
from: PeerId;
|
|
@@ -12,12 +12,8 @@ export declare function signMessage(privateKey: PrivateKey, message: {
|
|
|
12
12
|
sequenceNumber: bigint;
|
|
13
13
|
}, encode: (rpc: PubSubRPCMessage) => Uint8Array): Promise<SignedMessage>;
|
|
14
14
|
/**
|
|
15
|
-
* Verifies the signature of the given message
|
|
15
|
+
* Verifies the signature of the given message, returning false if its key does
|
|
16
|
+
* not belong to the author
|
|
16
17
|
*/
|
|
17
18
|
export declare function verifySignature(message: SignedMessage, encode: (rpc: PubSubRPCMessage) => Uint8Array): Promise<boolean>;
|
|
18
|
-
/**
|
|
19
|
-
* Returns the PublicKey associated with the given message.
|
|
20
|
-
* If no valid PublicKey can be retrieved an error will be returned.
|
|
21
|
-
*/
|
|
22
|
-
export declare function messagePublicKey(message: SignedMessage): PublicKey;
|
|
23
19
|
//# sourceMappingURL=sign.d.ts.map
|
package/dist/src/sign.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sign.d.ts","sourceRoot":"","sources":["../../src/sign.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sign.d.ts","sourceRoot":"","sources":["../../src/sign.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AACrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAC/C,OAAO,KAAK,EAAE,MAAM,EAAE,UAAU,EAAa,MAAM,mBAAmB,CAAA;AAEtE,eAAO,MAAM,UAAU,yBAAyC,CAAA;AAEhE;;GAEG;AACH,wBAAsB,WAAW,CAAE,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,UAAU,CAAC;IAAC,cAAc,EAAE,MAAM,CAAA;CAAE,EAAE,MAAM,EAAE,CAAC,GAAG,EAAE,gBAAgB,KAAK,UAAU,GAAG,OAAO,CAAC,aAAa,CAAC,CAoBpN;AAED;;;GAGG;AACH,wBAAsB,eAAe,CAAE,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,CAAC,GAAG,EAAE,gBAAgB,KAAK,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,CAsC9H"}
|
package/dist/src/sign.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { publicKeyForPeer } from '@libp2p/crypto/keys';
|
|
1
2
|
import { peerIdFromPrivateKey } from '@libp2p/peer-id';
|
|
2
3
|
import { concat as uint8ArrayConcat } from 'uint8arrays/concat';
|
|
3
4
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string';
|
|
4
5
|
import { toRpcMessage } from "./utils.js";
|
|
5
6
|
export const SignPrefix = uint8ArrayFromString('libp2p-pubsub:');
|
|
6
7
|
/**
|
|
7
|
-
* Signs the provided message with the given
|
|
8
|
+
* Signs the provided message with the given private key
|
|
8
9
|
*/
|
|
9
10
|
export async function signMessage(privateKey, message, encode) {
|
|
10
11
|
// @ts-expect-error signature field is missing, added below
|
|
@@ -25,7 +26,8 @@ export async function signMessage(privateKey, message, encode) {
|
|
|
25
26
|
return outputMessage;
|
|
26
27
|
}
|
|
27
28
|
/**
|
|
28
|
-
* Verifies the signature of the given message
|
|
29
|
+
* Verifies the signature of the given message, returning false if its key does
|
|
30
|
+
* not belong to the author
|
|
29
31
|
*/
|
|
30
32
|
export async function verifySignature(message, encode) {
|
|
31
33
|
if (message.type !== 'signed') {
|
|
@@ -46,34 +48,18 @@ export async function verifySignature(message, encode) {
|
|
|
46
48
|
key: undefined
|
|
47
49
|
}).subarray()
|
|
48
50
|
]);
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Returns the PublicKey associated with the given message.
|
|
56
|
-
* If no valid PublicKey can be retrieved an error will be returned.
|
|
57
|
-
*/
|
|
58
|
-
export function messagePublicKey(message) {
|
|
59
|
-
if (message.type !== 'signed') {
|
|
60
|
-
throw new Error('Message type must be "signed" to have a public key');
|
|
51
|
+
let pubKey;
|
|
52
|
+
try {
|
|
53
|
+
// only trust a supplied key if it derives to the author
|
|
54
|
+
pubKey = await publicKeyForPeer(message.from, message.key);
|
|
61
55
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
// from `from` is provably the author's; trust it over the supplied message.key
|
|
68
|
-
if (message.from.publicKey != null) {
|
|
69
|
-
return message.from.publicKey;
|
|
70
|
-
}
|
|
71
|
-
// otherwise the supplied key must derive to the from peer id, else a message
|
|
72
|
-
// could be signed by one key while claiming a different author
|
|
73
|
-
if (message.key != null && message.from.equals(message.key.toMultihash().bytes)) {
|
|
74
|
-
return message.key;
|
|
56
|
+
catch (err) {
|
|
57
|
+
if (err.name === 'InvalidPublicKeyError') {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
throw err;
|
|
75
61
|
}
|
|
76
|
-
//
|
|
77
|
-
|
|
62
|
+
// verify the base message
|
|
63
|
+
return pubKey.verify(bytes, message.signature);
|
|
78
64
|
}
|
|
79
65
|
//# sourceMappingURL=sign.js.map
|
package/dist/src/sign.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sign.js","sourceRoot":"","sources":["../../src/sign.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAA;AACtD,OAAO,EAAE,MAAM,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAC/D,OAAO,EAAE,UAAU,IAAI,oBAAoB,EAAE,MAAM,yBAAyB,CAAA;AAC5E,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAKzC,MAAM,CAAC,MAAM,UAAU,GAAG,oBAAoB,CAAC,gBAAgB,CAAC,CAAA;AAEhE;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,WAAW,CAAE,UAAsB,EAAE,OAAkF,EAAE,MAA6C;IAC1L,2DAA2D;IAC3D,MAAM,aAAa,GAAkB;QACnC,IAAI,EAAE,QAAQ;QACd,KAAK,EAAE,OAAO,CAAC,KAAK;QACpB,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,cAAc,EAAE,OAAO,CAAC,cAAc;QACtC,IAAI,EAAE,oBAAoB,CAAC,UAAU,CAAC;KACvC,CAAA;IAED,+DAA+D;IAC/D,MAAM,KAAK,GAAG,gBAAgB,CAAC;QAC7B,UAAU;QACV,MAAM,CAAC,YAAY,CAAC,aAAa,CAAC,CAAC,CAAC,QAAQ,EAAE;KAC/C,CAAC,CAAA;IAEF,aAAa,CAAC,SAAS,GAAG,MAAM,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;IACtD,aAAa,CAAC,GAAG,GAAG,UAAU,CAA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KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAA;IACjE,CAAC;IAED,IAAI,OAAO,CAAC,SAAS,IAAI,IAAI,EAAE,CAAC;QAC9B,MAAM,IAAI,KAAK,CAAC,iDAAiD,CAAC,CAAA;IACpE,CAAC;IAED,IAAI,OAAO,CAAC,IAAI,IAAI,IAAI,EAAE,CAAC;QACzB,MAAM,IAAI,KAAK,CAAC,qDAAqD,CAAC,CAAA;IACxE,CAAC;IAED,iCAAiC;IACjC,MAAM,KAAK,GAAG,gBAAgB,CAAC;QAC7B,UAAU;QACV,MAAM,CAAC;YACL,GAAG,YAAY,CAAC,OAAO,CAAC;YACxB,SAAS,EAAE,SAAS;YACpB,GAAG,EAAE,SAAS;SACf,CAAC,CAAC,QAAQ,EAAE;KACd,CAAC,CAAA;IAEF,IAAI,MAAiB,CAAA;IAErB,IAAI,CAAC;QACH,wDAAwD;QACxD,MAAM,GAAG,MAAM,gBAAgB,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,CAAC,CAAA;IAC5D,CAAC;IAAC,OAAO,GAAQ,EAAE,CAAC;QAClB,IAAI,GAAG,CAAC,IAAI,KAAK,uBAAuB,EAAE,CAAC;YACzC,OAAO,KAAK,CAAA;QACd,CAAC;QAED,MAAM,GAAG,CAAA;IACX,CAAC;IAED,0BAA0B;IAC1B,OAAO,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,SAAS,CAAC,CAAA;AAChD,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@libp2p/floodsub",
|
|
3
|
-
"version": "11.0.
|
|
3
|
+
"version": "11.0.32-2d4c93ed6",
|
|
4
4
|
"description": "libp2p-floodsub, also known as pubsub-flood or just dumbsub, this implementation of pubsub focused on delivering an API for Publish/Subscribe, but with no CastTree Forming (it just floods the network).",
|
|
5
5
|
"license": "Apache-2.0 OR MIT",
|
|
6
6
|
"homepage": "https://github.com/libp2p/js-libp2p/tree/main/packages/floodsub#readme",
|
|
@@ -54,22 +54,22 @@
|
|
|
54
54
|
"test:electron-main": "aegir test -t electron-main"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@libp2p/crypto": "5.1.
|
|
58
|
-
"@libp2p/interface": "3.
|
|
59
|
-
"@libp2p/interface-internal": "3.
|
|
60
|
-
"@libp2p/peer-collections": "7.0.
|
|
61
|
-
"@libp2p/peer-id": "6.0.
|
|
62
|
-
"@libp2p/utils": "7.4.
|
|
57
|
+
"@libp2p/crypto": "5.1.25-2d4c93ed6",
|
|
58
|
+
"@libp2p/interface": "3.4.0-2d4c93ed6",
|
|
59
|
+
"@libp2p/interface-internal": "3.2.0-2d4c93ed6",
|
|
60
|
+
"@libp2p/peer-collections": "7.0.30-2d4c93ed6",
|
|
61
|
+
"@libp2p/peer-id": "6.0.17-2d4c93ed6",
|
|
62
|
+
"@libp2p/utils": "7.4.3-2d4c93ed6",
|
|
63
63
|
"it-length-prefixed": "^11.0.1",
|
|
64
64
|
"main-event": "^1.0.5",
|
|
65
65
|
"multiformats": "^14.0.0",
|
|
66
|
-
"p-queue": "^
|
|
66
|
+
"p-queue": "^10.0.0",
|
|
67
67
|
"protons-runtime": "^7.0.0",
|
|
68
68
|
"uint8arraylist": "^3.0.2",
|
|
69
69
|
"uint8arrays": "^6.1.1"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
|
-
"@libp2p/logger": "6.2.
|
|
72
|
+
"@libp2p/logger": "6.2.15-2d4c93ed6",
|
|
73
73
|
"@multiformats/multiaddr": "^13.0.3",
|
|
74
74
|
"@types/sinon": "^22.0.0",
|
|
75
75
|
"aegir": "^48.1.1",
|
package/src/sign.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { publicKeyForPeer } from '@libp2p/crypto/keys'
|
|
1
2
|
import { peerIdFromPrivateKey } from '@libp2p/peer-id'
|
|
2
3
|
import { concat as uint8ArrayConcat } from 'uint8arrays/concat'
|
|
3
4
|
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
|
|
@@ -9,7 +10,7 @@ import type { PeerId, PrivateKey, PublicKey } from '@libp2p/interface'
|
|
|
9
10
|
export const SignPrefix = uint8ArrayFromString('libp2p-pubsub:')
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
|
-
* Signs the provided message with the given
|
|
13
|
+
* Signs the provided message with the given private key
|
|
13
14
|
*/
|
|
14
15
|
export async function signMessage (privateKey: PrivateKey, message: { from: PeerId, topic: string, data: Uint8Array, sequenceNumber: bigint }, encode: (rpc: PubSubRPCMessage) => Uint8Array): Promise<SignedMessage> {
|
|
15
16
|
// @ts-expect-error signature field is missing, added below
|
|
@@ -34,7 +35,8 @@ export async function signMessage (privateKey: PrivateKey, message: { from: Peer
|
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
/**
|
|
37
|
-
* Verifies the signature of the given message
|
|
38
|
+
* Verifies the signature of the given message, returning false if its key does
|
|
39
|
+
* not belong to the author
|
|
38
40
|
*/
|
|
39
41
|
export async function verifySignature (message: SignedMessage, encode: (rpc: PubSubRPCMessage) => Uint8Array): Promise<boolean> {
|
|
40
42
|
if (message.type !== 'signed') {
|
|
@@ -59,39 +61,19 @@ export async function verifySignature (message: SignedMessage, encode: (rpc: Pub
|
|
|
59
61
|
}).subarray()
|
|
60
62
|
])
|
|
61
63
|
|
|
62
|
-
|
|
63
|
-
const pubKey = messagePublicKey(message)
|
|
64
|
+
let pubKey: PublicKey
|
|
64
65
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
try {
|
|
67
|
+
// only trust a supplied key if it derives to the author
|
|
68
|
+
pubKey = await publicKeyForPeer(message.from, message.key)
|
|
69
|
+
} catch (err: any) {
|
|
70
|
+
if (err.name === 'InvalidPublicKeyError') {
|
|
71
|
+
return false
|
|
72
|
+
}
|
|
68
73
|
|
|
69
|
-
|
|
70
|
-
* Returns the PublicKey associated with the given message.
|
|
71
|
-
* If no valid PublicKey can be retrieved an error will be returned.
|
|
72
|
-
*/
|
|
73
|
-
export function messagePublicKey (message: SignedMessage): PublicKey {
|
|
74
|
-
if (message.type !== 'signed') {
|
|
75
|
-
throw new Error('Message type must be "signed" to have a public key')
|
|
74
|
+
throw err
|
|
76
75
|
}
|
|
77
76
|
|
|
78
|
-
//
|
|
79
|
-
|
|
80
|
-
throw new Error('Could not get the public key from the originator id')
|
|
81
|
-
}
|
|
82
|
-
|
|
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
|
|
85
|
-
if (message.from.publicKey != null) {
|
|
86
|
-
return message.from.publicKey
|
|
87
|
-
}
|
|
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
|
-
|
|
95
|
-
// We couldn't validate pubkey is from the originator, error
|
|
96
|
-
throw new Error('Could not get the public key from the originator id')
|
|
77
|
+
// verify the base message
|
|
78
|
+
return pubKey.verify(bytes, message.signature)
|
|
97
79
|
}
|