@@ -8,6 +8,7 @@ import { equals } from "uint8arrays/equals";
8
8
9
9
import { ERR_INVALID_ID } from "./constants.js" ;
10
10
import { EnrCreator } from "./creator.js" ;
11
+ import { EnrDecoder } from "./decoder.js" ;
11
12
import { ENR } from "./enr.js" ;
12
13
import { getPrivateKeyFromPeerId } from "./peer_id.js" ;
13
14
@@ -34,7 +35,7 @@ describe("ENR", function () {
34
35
} ;
35
36
36
37
const txt = await enr . encodeTxt ( privateKey ) ;
37
- const enr2 = await ENR . decodeTxt ( txt ) ;
38
+ const enr2 = await EnrDecoder . fromString ( txt ) ;
38
39
39
40
if ( ! enr . signature ) throw "enr.signature is undefined" ;
40
41
if ( ! enr2 . signature ) throw "enr.signature is undefined" ;
@@ -65,7 +66,7 @@ describe("ENR", function () {
65
66
it ( "should decode valid enr successfully" , async ( ) => {
66
67
const txt =
67
68
"enr:-Ku4QMh15cIjmnq-co5S3tYaNXxDzKTgj0ufusA-QfZ66EWHNsULt2kb0eTHoo1Dkjvvf6CAHDS1Di-htjiPFZzaIPcLh2F0dG5ldHOIAAAAAAAAAACEZXRoMpD2d10HAAABE________x8AgmlkgnY0gmlwhHZFkMSJc2VjcDI1NmsxoQIWSDEWdHwdEA3Lw2B_byeFQOINTZ0GdtF9DBjes6JqtIN1ZHCCIyg" ;
68
- const enr = await ENR . decodeTxt ( txt ) ;
69
+ const enr = await EnrDecoder . fromString ( txt ) ;
69
70
const eth2 = enr . get ( "eth2" ) ;
70
71
if ( ! eth2 ) throw "eth2 is undefined" ;
71
72
expect ( bytesToHex ( eth2 ) ) . to . be . equal ( "f6775d0700000113ffffffffffff1f00" ) ;
@@ -74,7 +75,7 @@ describe("ENR", function () {
74
75
it ( "should decode valid ENR with multiaddrs successfully [shared test vector]" , async ( ) => {
75
76
const txt =
76
77
"enr:-QEnuEBEAyErHEfhiQxAVQoWowGTCuEF9fKZtXSd7H_PymHFhGJA3rGAYDVSHKCyJDGRLBGsloNbS8AZF33IVuefjOO6BIJpZIJ2NIJpcIQS39tkim11bHRpYWRkcnO4lgAvNihub2RlLTAxLmRvLWFtczMud2FrdXYyLnRlc3Quc3RhdHVzaW0ubmV0BgG73gMAODcxbm9kZS0wMS5hYy1jbi1ob25na29uZy1jLndha3V2Mi50ZXN0LnN0YXR1c2ltLm5ldAYBu94DACm9A62t7AQL4Ef5ZYZosRpQTzFVAB8jGjf1TER2wH-0zBOe1-MDBNLeA4lzZWNwMjU2azGhAzfsxbxyCkgCqq8WwYsVWH7YkpMLnU2Bw5xJSimxKav-g3VkcIIjKA" ;
77
- const enr = await ENR . decodeTxt ( txt ) ;
78
+ const enr = await EnrDecoder . fromString ( txt ) ;
78
79
79
80
expect ( enr . multiaddrs ) . to . not . be . undefined ;
80
81
expect ( enr . multiaddrs ! . length ) . to . be . equal ( 3 ) ;
@@ -93,7 +94,7 @@ describe("ENR", function () {
93
94
it ( "should decode valid enr with tcp successfully" , async ( ) => {
94
95
const txt =
95
96
"enr:-IS4QAmC_o1PMi5DbR4Bh4oHVyQunZblg4bTaottPtBodAhJZvxVlWW-4rXITPNg4mwJ8cW__D9FBDc9N4mdhyMqB-EBgmlkgnY0gmlwhIbRi9KJc2VjcDI1NmsxoQOevTdO6jvv3fRruxguKR-3Ge4bcFsLeAIWEDjrfaigNoN0Y3CCdl8" ;
96
- const enr = await ENR . decodeTxt ( txt ) ;
97
+ const enr = await EnrDecoder . fromString ( txt ) ;
97
98
expect ( enr . tcp ) . to . not . be . undefined ;
98
99
expect ( enr . tcp ) . to . be . equal ( 30303 ) ;
99
100
expect ( enr . ip ) . to . not . be . undefined ;
@@ -114,7 +115,7 @@ describe("ENR", function () {
114
115
enr . set ( "id" , new Uint8Array ( [ 0 ] ) ) ;
115
116
const txt = await enr . encodeTxt ( privateKey ) ;
116
117
117
- await ENR . decodeTxt ( txt ) ;
118
+ await EnrDecoder . fromString ( txt ) ;
118
119
assert . fail ( "Expect error here" ) ;
119
120
} catch ( err : unknown ) {
120
121
const e = err as Error ;
@@ -126,7 +127,7 @@ describe("ENR", function () {
126
127
try {
127
128
const txt =
128
129
"enr:-IS4QJ2d11eu6dC7E7LoXeLMgMP3kom1u3SE8esFSWvaHoo0dP1jg8O3-nx9ht-EO3CmG7L6OkHcMmoIh00IYWB92QABgmlkgnY0gmlwhH8AAAGJc2d11eu6dCsxoQIB_c-jQMOXsbjWkbN-kj99H57gfId5pfb4wa1qxwV4CIN1ZHCCIyk" ;
129
- ENR . decodeTxt ( txt ) ;
130
+ EnrDecoder . fromString ( txt ) ;
130
131
assert . fail ( "Expect error here" ) ;
131
132
} catch ( err : unknown ) {
132
133
const e = err as Error ;
@@ -180,7 +181,7 @@ describe("ENR", function () {
180
181
it ( "should return false" , async ( ) => {
181
182
const txt =
182
183
"enr:-Ku4QMh15cIjmnq-co5S3tYaNXxDzKTgj0ufusA-QfZ66EWHNsULt2kb0eTHoo1Dkjvvf6CAHDS1Di-htjiPFZzaIPcLh2F0dG5ldHOIAAAAAAAAAACEZXRoMpD2d10HAAABE________x8AgmlkgnY0gmlwhHZFkMSJc2VjcDI1NmsxoQIWSDEWdHwdEA3Lw2B_byeFQOINTZ0GdtF9DBjes6JqtIN1ZHCCIyg" ;
183
- const enr = await ENR . decodeTxt ( txt ) ;
184
+ const enr = await EnrDecoder . fromString ( txt ) ;
184
185
// should have id and public key inside ENR
185
186
expect ( enr . verify ( new Uint8Array ( 32 ) , new Uint8Array ( 64 ) ) ) . to . be . false ;
186
187
} ) ;
@@ -209,7 +210,7 @@ describe("ENR", function () {
209
210
210
211
it ( "should encode/decode to RLP encoding" , async function ( ) {
211
212
const encoded = await record . encode ( privateKey ) ;
212
- const decoded = await ENR . decode ( encoded ) ;
213
+ const decoded = await EnrDecoder . fromRLP ( encoded ) ;
213
214
214
215
record . forEach ( ( value , key ) => {
215
216
expect ( equals ( decoded . get ( key ) ! , value ) ) . to . be . true ;
@@ -220,7 +221,7 @@ describe("ENR", function () {
220
221
// spec enr https://eips.ethereum.org/EIPS/eip-778
221
222
const testTxt =
222
223
"enr:-IS4QHCYrYZbAKWCBRlAy5zzaDZXJBGkcnh4MHcBFZntXNFrdvJjX04jRzjzCBOonrkTfj499SZuOh8R33Ls8RRcy5wBgmlkgnY0gmlwhH8AAAGJc2VjcDI1NmsxoQPKY0yuDUmstAHYpMa2_oxVtw0RW_QAdpzBQA8yWM0xOIN1ZHCCdl8" ;
223
- const decoded = await ENR . decodeTxt ( testTxt ) ;
224
+ const decoded = await EnrDecoder . fromString ( testTxt ) ;
224
225
// Note: Signatures are different due to the extra entropy added
225
226
// by @noble /secp256k1:
226
227
// https://github.com/paulmillr/noble-secp256k1#signmsghash-privatekey
@@ -403,7 +404,7 @@ describe("ENR", function () {
403
404
enr . waku2 = waku2Protocols ;
404
405
405
406
const txt = await enr . encodeTxt ( privateKey ) ;
406
- const decoded = ( await ENR . decodeTxt ( txt ) ) . waku2 ! ;
407
+ const decoded = ( await EnrDecoder . fromString ( txt ) ) . waku2 ! ;
407
408
408
409
expect ( decoded . relay ) . to . equal ( false ) ;
409
410
expect ( decoded . store ) . to . equal ( false ) ;
@@ -419,7 +420,7 @@ describe("ENR", function () {
419
420
420
421
enr . waku2 = waku2Protocols ;
421
422
const txt = await enr . encodeTxt ( privateKey ) ;
422
- const decoded = ( await ENR . decodeTxt ( txt ) ) . waku2 ! ;
423
+ const decoded = ( await EnrDecoder . fromString ( txt ) ) . waku2 ! ;
423
424
424
425
expect ( decoded . relay ) . to . equal ( true ) ;
425
426
expect ( decoded . store ) . to . equal ( true ) ;
@@ -432,7 +433,7 @@ describe("ENR", function () {
432
433
433
434
enr . waku2 = waku2Protocols ;
434
435
const txt = await enr . encodeTxt ( privateKey ) ;
435
- const decoded = ( await ENR . decodeTxt ( txt ) ) . waku2 ! ;
436
+ const decoded = ( await EnrDecoder . fromString ( txt ) ) . waku2 ! ;
436
437
437
438
expect ( decoded . relay ) . to . equal ( true ) ;
438
439
expect ( decoded . store ) . to . equal ( false ) ;
@@ -445,7 +446,7 @@ describe("ENR", function () {
445
446
446
447
enr . waku2 = waku2Protocols ;
447
448
const txt = await enr . encodeTxt ( privateKey ) ;
448
- const decoded = ( await ENR . decodeTxt ( txt ) ) . waku2 ! ;
449
+ const decoded = ( await EnrDecoder . fromString ( txt ) ) . waku2 ! ;
449
450
450
451
expect ( decoded . relay ) . to . equal ( false ) ;
451
452
expect ( decoded . store ) . to . equal ( true ) ;
@@ -458,7 +459,7 @@ describe("ENR", function () {
458
459
459
460
enr . waku2 = waku2Protocols ;
460
461
const txt = await enr . encodeTxt ( privateKey ) ;
461
- const decoded = ( await ENR . decodeTxt ( txt ) ) . waku2 ! ;
462
+ const decoded = ( await EnrDecoder . fromString ( txt ) ) . waku2 ! ;
462
463
463
464
expect ( decoded . relay ) . to . equal ( false ) ;
464
465
expect ( decoded . store ) . to . equal ( false ) ;
@@ -471,7 +472,7 @@ describe("ENR", function () {
471
472
472
473
enr . waku2 = waku2Protocols ;
473
474
const txt = await enr . encodeTxt ( privateKey ) ;
474
- const decoded = ( await ENR . decodeTxt ( txt ) ) . waku2 ! ;
475
+ const decoded = ( await EnrDecoder . fromString ( txt ) ) . waku2 ! ;
475
476
476
477
expect ( decoded . relay ) . to . equal ( false ) ;
477
478
expect ( decoded . store ) . to . equal ( false ) ;
@@ -485,7 +486,7 @@ describe("ENR", function () {
485
486
const txt =
486
487
"enr:-Iu4QADPfXNCM6iYyte0pIdbMirIw_AsKR7J1DeJBysXDWz4DZvyjgIwpMt-sXTVUzLJdE9FaStVy2ZKtHUVQAH61-KAgmlkgnY0gmlwhMCosvuJc2VjcDI1NmsxoQI0OCNtPJtBayNgvFvKp-0YyCozcvE1rqm_V1W51nHVv4N0Y3CC6mCFd2FrdTIH" ;
487
488
488
- const decoded = ( await ENR . decodeTxt ( txt ) ) . waku2 ! ;
489
+ const decoded = ( await EnrDecoder . fromString ( txt ) ) . waku2 ! ;
489
490
490
491
expect ( decoded . relay ) . to . equal ( true ) ;
491
492
expect ( decoded . store ) . to . equal ( true ) ;
0 commit comments