[BUG] Type 'EthrDID' is not assignable to type 'Issuer'.
ouoabcde opened this issue ยท comments
Current Behavior
Type 'EthrDID' is no more compatible to type 'Issuer' from 2.1.5 to above versions. It works fine from 2.1.4 and below.
Expected Behavior
Document should work fine. Issuer should be created by new EthrDID
.
import * as EthrDID from 'ethr-did'
import { Issuer } from 'did-jwt-vc'
const issuer: Issuer = new EthrDID({
identifier: '0xf1232f840f3ad7d23fcdaa84d6c66dac24efb198',
privateKey: 'd8b595680851765f38ea5405129244ba3cbad84467d190859f4c8b20c1ff6c75'
})
This code have to create issuer fine.
Failure Information
Issuer can't be created by new EthrDID
because it's no more compatible.
It spits out the error like below.
vc-issuer.ts:4:7 - error TS2322: Type 'EthrDID' is not assignable to type 'Issuer'.
Types of property 'signer' are incompatible.
Type 'Signer | undefined' is not assignable to type 'Signer'.
Type 'undefined' is not assignable to type 'Signer'.
4 const issuer: Issuer = new EthrDID({
Steps to Reproduce
Just run the code at Expected Behavior section.
Alternatives you considered
Works fine from 2.1.4 and below versions. Spits error from 2.1.5 and above versions.
This is actually correct behavior, but the documentation is a bit outdated.
Thank you for spotting it!
It should be something like:
import { EthrDID } from 'ethr-did'
import { Issuer } from 'did-jwt-vc'
const issuer: Issuer = new EthrDID({
identifier: '0xf1232f840f3ad7d23fcdaa84d6c66dac24efb198',
privateKey: 'd8b595680851765f38ea5405129244ba3cbad84467d190859f4c8b20c1ff6c75'
}) as Issuer
Recent versions of EthrDID
support initialization without a privateKey
or signer
, for use-cases where only verification is required, but not issuance.
Since the Issuer
type in did-jwt-vc
is actually used for issuance, those fields are required.
Even if you initialize EthrDID for credential issuance at run-time, this property is not reflected in the typescript type which is evaluated at compile-time, so the compiler throws this warning.
As a developer you can make sure that your code performs the proper initialization and should be able to hint this to the typescript compiler by casting EthrDID
to Issuer
: const issuer = new EthrDID(...) as Issuer
๐ This issue has been resolved in version 2.1.9 ๐
The release is available on:
Your semantic-release bot ๐ฆ๐