This refactors the Statement class hierarchy a bit to make a clean split between signed and unsigned statements.
There's now a base Statement class that has everything except the signature field, plus common helper methods like .toProtobuf, .expandObjects, etc.
The UnsignedStatement subclass adds the .calculateSignature and .sign methods, which return Buffer and SignedStatement, respectively.
The SignedStatement class has the signature field and the .verifySignature method. Both SignedStatement and UnsignedStatement inherit from Statement directly, so SignedStatement does not have the .sign and .calculateSignature methods. However, there's a helper on the the base class .asUnsignedStatement() that will return an unsigned copy of either a signed or unsigned statement. So, if you need to strip an existing signature and re-sign a message, you can do:
mySignedStmt.asUnsignedStatement().sign(newPublisherId)
.then(signed => {
// `signed` has a new signature
})
Converting from protobuf still happens with Statement.fromProtobuf(), which will return a SignedStatement if the protobuf message has a signature, and an UnsignedStatement otherwise.
This refactors the Statement class hierarchy a bit to make a clean split between signed and unsigned statements.
There's now a base
Statement
class that has everything except thesignature
field, plus common helper methods like.toProtobuf
,.expandObjects
, etc.The
UnsignedStatement
subclass adds the.calculateSignature
and.sign
methods, which returnBuffer
andSignedStatement
, respectively.The
SignedStatement
class has thesignature
field and the.verifySignature
method. BothSignedStatement
andUnsignedStatement
inherit fromStatement
directly, soSignedStatement
does not have the.sign
and.calculateSignature
methods. However, there's a helper on the the base class.asUnsignedStatement()
that will return an unsigned copy of either a signed or unsigned statement. So, if you need to strip an existing signature and re-sign a message, you can do:Converting from protobuf still happens with
Statement.fromProtobuf()
, which will return aSignedStatement
if the protobuf message has asignature
, and anUnsignedStatement
otherwise.