@@ -56,6 +56,42 @@ describe('message signing', () => {
56
56
} )
57
57
} )
58
58
59
+ it ( 'should be able to extract the public key from an inlined key' , ( done ) => {
60
+ const testSecp256k1 = ( peerId ) => {
61
+ const message = {
62
+ from : peerId . id ,
63
+ data : 'hello' ,
64
+ seqno : randomSeqno ( ) ,
65
+ topicIDs : [ 'test-topic' ]
66
+ }
67
+
68
+ const bytesToSign = Buffer . concat ( [ SignPrefix , Message . encode ( message ) ] )
69
+ peerId . privKey . sign ( bytesToSign , ( err , expectedSignature ) => {
70
+ if ( err ) return done ( err )
71
+
72
+ signMessage ( peerId , message , ( err , signedMessage ) => {
73
+ if ( err ) return done ( err )
74
+
75
+ // Check the signature and public key
76
+ expect ( signedMessage . signature ) . to . eql ( expectedSignature )
77
+ signedMessage . key = undefined
78
+
79
+ // Verify the signature
80
+ verifySignature ( signedMessage , ( err , verified ) => {
81
+ expect ( err ) . to . not . exist ( )
82
+ expect ( verified ) . to . eql ( true )
83
+ done ( err )
84
+ } )
85
+ } )
86
+ } )
87
+ }
88
+
89
+ PeerId . create ( { keyType : 'secp256k1' , bits : 256 } , ( err , peerId ) => {
90
+ expect ( err ) . to . not . exist ( )
91
+ testSecp256k1 ( peerId )
92
+ } )
93
+ } )
94
+
59
95
it ( 'should be able to extract the public key from the message' , ( done ) => {
60
96
const message = {
61
97
from : peerId . id ,
0 commit comments