uport-project / kotlin-did-jwt

Create and verify uPort and DID compliant JWTs in Kotlin
https://developer.uport.me
Apache License 2.0
8 stars 6 forks source link

[Bugfix] ethr-did delegate keys not being resolved #9

Closed mirceanis closed 5 years ago

mirceanis commented 5 years ago

This should be merged only after #7

What's here

The delegate keys of an ethr-did were not showing up in the resolved DID document.

This was caused by a broken conversion of a ByteArray into a String, resulting in a string with a bunch of null characters at the end. When the event log was parsed to accumulate the publicKey entries, the respective strings would fail basic string comparison with the expected values, resulting in all delegate keys getting skipped.

Testing

I added a test to validate the bug in a controlled environment. Running ./gradlew test will also run that test. This is already done by CI.

Also, the same data can be validated in the wild, on the rinkeby network:

prerequisites:
val resolver = EthrDIDResolver(
    rpc = JsonRPC(Networks.rinkeby.rpcUrl),
    registryAddress = Networks.rinkeby.ethrDidRegistry
)
val ddo = resolver.resolve("0xcf03dd0a894ef79cb5b601a43c4b25e3ae4c67ed")
println(ddo.toJson())
Expected output:

it should resolve to the following document:

{
  "id": "did:ethr:0xcf03dd0a894ef79cb5b601a43c4b25e3ae4c67ed",
  "publicKey": [{
      "id": "did:ethr:0xcf03dd0a894ef79cb5b601a43c4b25e3ae4c67ed#owner",
      "type": "Secp256k1VerificationKey2018",
      "owner": "did:ethr:0xcf03dd0a894ef79cb5b601a43c4b25e3ae4c67ed",
      "ethereumAddress": "0xcf03dd0a894ef79cb5b601a43c4b25e3ae4c67ed"
    },
    {
      "id": "did:ethr:0xcf03dd0a894ef79cb5b601a43c4b25e3ae4c67ed#delegate-1",
      "type": "Secp256k1VerificationKey2018",
      "owner": "did:ethr:0xcf03dd0a894ef79cb5b601a43c4b25e3ae4c67ed",
      "ethereumAddress": "0x62d283fe6939c01fc88f02c6d2c9a547cc3e2656"
    }],
  "authentication": [{
      "type": "Secp256k1SignatureAuthentication2018",
      "publicKey": "did:ethr:0xcf03dd0a894ef79cb5b601a43c4b25e3ae4c67ed#owner"
    }],
  "service": [],
  "@context": "https://w3id.org/did/v1"
}
Previous output (broken)
{
  "id": "did:ethr:0xcf03dd0a894ef79cb5b601a43c4b25e3ae4c67ed",
  "publicKey": [{
      "id": "did:ethr:0xcf03dd0a894ef79cb5b601a43c4b25e3ae4c67ed#owner",
      "type": "Secp256k1VerificationKey2018",
      "owner": "did:ethr:0xcf03dd0a894ef79cb5b601a43c4b25e3ae4c67ed",
      "ethereumAddress": "0xcf03dd0a894ef79cb5b601a43c4b25e3ae4c67ed"
    }],
  "authentication": [{
      "type": "Secp256k1SignatureAuthentication2018",
      "publicKey": "did:ethr:0xcf03dd0a894ef79cb5b601a43c4b25e3ae4c67ed#owner"
    }],
  "service": [],
  "@context": "https://w3id.org/did/v1"
}

Note

This PR also includes some additions to the EthrDID contract interface that allow the user to override some default transaction parameters (like nonce, value, gas, gasPrice) before signing. This interface is not documented and probably not used externally yet. This change does not impact functionality since the previous defaults still get used if the options are null.