@@ -10,6 +10,7 @@ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
1010import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
1111import type { TestSetup } from '../index.js'
1212import type { PeerIdFactory } from 'libp2p-interfaces/peer-id'
13+ import type { PublicKey , PrivateKey } from 'libp2p-interfaces/keys'
1314
1415const DAG_PB_CODE = 0x70
1516const LIBP2P_KEY_CODE = 0x72
@@ -58,14 +59,14 @@ export default (common: TestSetup<PeerIdFactory>) => {
5859
5960 it ( 'can be created for a Secp256k1 key' , async ( ) => {
6061 const id = await factory . create ( { keyType : 'secp256k1' , bits : 256 } )
61- const expB58 = base58btc . encode ( ( await identity . digest ( id . pubKey ! . bytes ) ) . bytes ) . slice ( 1 )
62+ const expB58 = base58btc . encode ( ( await identity . digest ( ( id . pubKey as PublicKey ) . bytes ) ) . bytes ) . slice ( 1 )
6263 expect ( id . toB58String ( ) ) . to . equal ( expB58 )
6364 } )
6465
6566 it ( 'can get the public key from a Secp256k1 key' , async ( ) => {
6667 const original = await factory . create ( { keyType : 'secp256k1' , bits : 256 } )
6768 const newId = factory . createFromB58String ( original . toB58String ( ) )
68- expect ( original . pubKey ! . bytes ) . to . eql ( newId . pubKey ! . bytes )
69+ expect ( ( original . pubKey as PublicKey ) . bytes ) . to . eql ( ( newId . pubKey as PublicKey ) . bytes )
6970 } )
7071
7172 it ( 'isPeerId' , async ( ) => {
@@ -194,15 +195,15 @@ export default (common: TestSetup<PeerIdFactory>) => {
194195 const key = '12D3KooWRm8J3iL796zPFi2EtGGtUJn58AG67gcqzMFHZnnsTzqD'
195196 const id = await factory . parse ( key )
196197 expect ( id . toB58String ( ) ) . to . equal ( key )
197- const expB58 = base58btc . encode ( ( await identity . digest ( id . pubKey ! . bytes ) ) . bytes ) . slice ( 1 )
198+ const expB58 = base58btc . encode ( ( await identity . digest ( ( id . pubKey as PublicKey ) . bytes ) ) . bytes ) . slice ( 1 )
198199 expect ( id . toB58String ( ) ) . to . equal ( expB58 )
199200 } )
200201
201202 it ( 'recreate from embedded secp256k1 key' , async ( ) => {
202203 const key = '16Uiu2HAm5qw8UyXP2RLxQUx5KvtSN8DsTKz8quRGqGNC3SYiaB8E'
203204 const id = await factory . parse ( key )
204205 expect ( id . toB58String ( ) ) . to . equal ( key )
205- const expB58 = base58btc . encode ( ( await identity . digest ( id . pubKey ! . bytes ) ) . bytes ) . slice ( 1 )
206+ const expB58 = base58btc . encode ( ( await identity . digest ( ( id . pubKey as PublicKey ) . bytes ) ) . bytes ) . slice ( 1 )
206207 expect ( id . toB58String ( ) ) . to . equal ( expB58 )
207208 } )
208209
@@ -215,20 +216,20 @@ export default (common: TestSetup<PeerIdFactory>) => {
215216 it ( 'can be created from a Secp256k1 public key' , async ( ) => {
216217 const privKey = await crypto . keys . generateKeyPair ( 'secp256k1' , 256 )
217218 const id = await factory . createFromPubKey ( privKey . public . bytes )
218- const expB58 = base58btc . encode ( ( await identity . digest ( id . pubKey ! . bytes ) ) . bytes ) . slice ( 1 )
219+ const expB58 = base58btc . encode ( ( await identity . digest ( ( id . pubKey as PublicKey ) . bytes ) ) . bytes ) . slice ( 1 )
219220 expect ( id . toB58String ( ) ) . to . equal ( expB58 )
220221 } )
221222
222223 it ( 'can be created from a Secp256k1 private key' , async ( ) => {
223224 const privKey = await crypto . keys . generateKeyPair ( 'secp256k1' , 256 )
224225 const id = await factory . createFromPrivKey ( privKey . bytes )
225- const expB58 = base58btc . encode ( ( await identity . digest ( id . pubKey ! . bytes ) ) . bytes ) . slice ( 1 )
226+ const expB58 = base58btc . encode ( ( await identity . digest ( ( id . pubKey as PublicKey ) . bytes ) ) . bytes ) . slice ( 1 )
226227 expect ( id . toB58String ( ) ) . to . equal ( expB58 )
227228 } )
228229
229230 it ( 'Compare generated ID with one created from PubKey' , async ( ) => {
230231 const id1 = await factory . create ( testOpts )
231- const id2 = await factory . createFromPubKey ( id1 . marshalPubKey ( ) ! )
232+ const id2 = await factory . createFromPubKey ( id1 . marshalPubKey ( ) as Uint8Array )
232233 expect ( id1 . id ) . to . be . eql ( id2 . id )
233234 } )
234235
@@ -242,7 +243,7 @@ export default (common: TestSetup<PeerIdFactory>) => {
242243 this . timeout ( 1000 * 60 )
243244 const shortId = await factory . create ( testOpts )
244245 const longId = await factory . create ( { bits : 1024 } )
245- expect ( shortId . privKey ! . bytes . length ) . is . below ( longId . privKey ! . bytes . length )
246+ expect ( ( shortId . privKey as PrivateKey ) . bytes . length ) . is . below ( ( longId . privKey as PrivateKey ) . bytes . length )
246247 } )
247248
248249 it ( 'Pretty printing' , async ( ) => {
@@ -292,8 +293,8 @@ export default (common: TestSetup<PeerIdFactory>) => {
292293 const id = await factory . create ( testOpts )
293294 const other = await factory . createFromJSON ( id . toJSON ( ) )
294295 expect ( id . toB58String ( ) ) . to . equal ( other . toB58String ( ) )
295- expect ( id . privKey ! . bytes ) . to . eql ( other . privKey ! . bytes )
296- expect ( id . pubKey ! . bytes ) . to . eql ( other . pubKey ! . bytes )
296+ expect ( ( id . privKey as PrivateKey ) . bytes ) . to . eql ( ( other . privKey as PrivateKey ) . bytes )
297+ expect ( ( id . pubKey as PublicKey ) . bytes ) . to . eql ( ( other . pubKey as PublicKey ) . bytes )
297298 } )
298299
299300 it ( 'only id' , async ( ) => {
@@ -308,7 +309,7 @@ export default (common: TestSetup<PeerIdFactory>) => {
308309
309310 it ( 'go interop' , async ( ) => {
310311 const id = await factory . createFromJSON ( goId )
311- const digest = await id . privKey ! . public . hash ( )
312+ const digest = await ( id . privKey as PrivateKey ) . public . hash ( )
312313 expect ( base58btc . encode ( digest ) . slice ( 1 ) ) . to . eql ( goId . id )
313314 } )
314315 } )
0 commit comments