@waku/enr 0.0.27-f599932.0 → 0.0.28-b6339f7.0
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/CHANGELOG.md +8 -0
- package/bundle/index.js +727 -1393
- package/dist/.tsbuildinfo +1 -1
- package/dist/creator.d.ts +1 -1
- package/dist/creator.js +1 -2
- package/dist/creator.js.map +1 -1
- package/dist/decoder.js +1 -1
- package/dist/decoder.js.map +1 -1
- package/dist/enr.d.ts +1 -1
- package/dist/enr.js +2 -2
- package/dist/enr.js.map +1 -1
- package/dist/peer_id.d.ts +3 -4
- package/dist/peer_id.js +7 -24
- package/dist/peer_id.js.map +1 -1
- package/package.json +1 -1
- package/src/creator.ts +2 -3
- package/src/decoder.ts +1 -1
- package/src/enr.ts +3 -3
- package/src/peer_id.ts +9 -34
package/src/decoder.ts
CHANGED
@@ -37,7 +37,7 @@ async function fromValues(values: Uint8Array[]): Promise<ENR> {
|
|
37
37
|
}
|
38
38
|
const _seq = decodeSeq(seq);
|
39
39
|
|
40
|
-
const enr =
|
40
|
+
const enr = ENR.create(obj, _seq, signature);
|
41
41
|
checkSignature(seq, kvs, enr, signature);
|
42
42
|
return enr;
|
43
43
|
}
|
package/src/enr.ts
CHANGED
@@ -34,16 +34,16 @@ export class ENR extends RawEnr implements IEnr {
|
|
34
34
|
public static readonly RECORD_PREFIX = "enr:";
|
35
35
|
public peerId?: PeerId;
|
36
36
|
|
37
|
-
public static
|
37
|
+
public static create(
|
38
38
|
kvs: Record<ENRKey, ENRValue> = {},
|
39
39
|
seq: SequenceNumber = BigInt(1),
|
40
40
|
signature?: Uint8Array
|
41
|
-
):
|
41
|
+
): ENR {
|
42
42
|
const enr = new ENR(kvs, seq, signature);
|
43
43
|
try {
|
44
44
|
const publicKey = enr.publicKey;
|
45
45
|
if (publicKey) {
|
46
|
-
enr.peerId =
|
46
|
+
enr.peerId = createPeerIdFromPublicKey(publicKey);
|
47
47
|
}
|
48
48
|
} catch (e) {
|
49
49
|
log.error("Could not calculate peer id for ENR", e);
|
package/src/peer_id.ts
CHANGED
@@ -1,38 +1,13 @@
|
|
1
|
-
import {
|
2
|
-
import {
|
3
|
-
import
|
4
|
-
import { peerIdFromKeys } from "@libp2p/peer-id";
|
1
|
+
import { publicKeyFromRaw } from "@libp2p/crypto/keys";
|
2
|
+
import { type PeerId } from "@libp2p/interface";
|
3
|
+
import { peerIdFromPublicKey } from "@libp2p/peer-id";
|
5
4
|
|
6
|
-
export
|
7
|
-
publicKey: Uint8Array
|
8
|
-
): Promise<PeerId> {
|
9
|
-
const _publicKey = new supportedKeys.secp256k1.Secp256k1PublicKey(publicKey);
|
10
|
-
return peerIdFromKeys(_publicKey.bytes, undefined);
|
11
|
-
}
|
12
|
-
|
13
|
-
export function getPublicKeyFromPeerId(peerId: PeerId): Uint8Array {
|
14
|
-
if (peerId.type !== "secp256k1") {
|
15
|
-
throw new Error("Unsupported peer id type");
|
16
|
-
}
|
5
|
+
export const ERR_TYPE_NOT_IMPLEMENTED = "Keypair type not implemented";
|
17
6
|
|
18
|
-
|
19
|
-
|
7
|
+
export function createPeerIdFromPublicKey(publicKey: Uint8Array): PeerId {
|
8
|
+
const pubKey = publicKeyFromRaw(publicKey);
|
9
|
+
if (pubKey.type !== "secp256k1") {
|
10
|
+
throw new Error(ERR_TYPE_NOT_IMPLEMENTED);
|
20
11
|
}
|
21
|
-
|
22
|
-
return unmarshalPublicKey(peerId.publicKey).marshal();
|
23
|
-
}
|
24
|
-
|
25
|
-
// Only used in tests
|
26
|
-
export async function getPrivateKeyFromPeerId(
|
27
|
-
peerId: PeerId
|
28
|
-
): Promise<Uint8Array> {
|
29
|
-
if (peerId.type !== "secp256k1") {
|
30
|
-
throw new Error("Unsupported peer id type");
|
31
|
-
}
|
32
|
-
if (!peerId.privateKey) {
|
33
|
-
throw new Error("Private key not present on peer id");
|
34
|
-
}
|
35
|
-
|
36
|
-
const privateKey = await unmarshalPrivateKey(peerId.privateKey);
|
37
|
-
return privateKey.marshal();
|
12
|
+
return peerIdFromPublicKey(pubKey);
|
38
13
|
}
|