credo-ts
credo-ts copied to clipboard
Make PublicKey type property static
Shouldn't the type property of PublicKey child classes be static?
Some places require PublicKey type as a parameter. It would be convenient to use this property without having an instance of a class.
For example, the Ed25119Sig2018 class contains:
@Equals('Ed25519VerificationKey2018')
public type = 'Ed25519VerificationKey2018' as const
When I'm creating an instance of ReferencedAuthentication, it requires type as second parameter:
new ReferencedAuthentication(
new Ed25119Sig2018({
id: 'did:sov:SKJVx2kn373FNgvff1SbJo#5',
controller: 'did:sov:SKJVx2kn373FNgvff1SbJo',
publicKeyBase58: 'EoGusetSxDJktp493VCyh981nUnzMamTRjvBaHZAy68d',
}),
'Ed25519VerificationKey2018'
),
Another option could be creating an "enum" structure to avoid copy-pasting string literals.
Maybe, it's already there somewhere and I just haven't found it.
The problem with it being a static property is that we also need it as an instance property. So we would get the same as we have now with message classes where we have a static type and an instance type. The instance type value is the value of the static type so you don't have to declare the value twice. Maybe something like that would work?
However I have to say the implementation of the signature suite classes currently is overly complex and would be better of with some simplification. I made it a lot looser in the new did document implementation (not every verification method has it's own class anymore)
@TimoGlastra, just to verify. Is there overlap between the signature suite implementations mentioned here and the ones I'm working on for the jsonld work?