Skip to content

Commit

Permalink
chore: pass the private key to local registrars (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeplotean committed Oct 23, 2023
1 parent acde9fe commit c19ee12
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class LocalRegistrar : DidRegistrar {
override suspend fun create(options: DidCreateOptions): DidResult =
getRegistrarForMethod(options.method).register(options)
override suspend fun createByKey(key: Key, options: DidCreateOptions): DidResult =
getRegistrarForMethod(options.method).registerByKey(key.getPublicKey(), options)
getRegistrarForMethod(options.method).registerByKey(key, options)


override suspend fun update() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class DidJwkRegistrar : LocalRegistrarMethod("jwk") {
val did = "did:jwk:${key.exportJWK().toByteArray().encodeToBase64Url()}"

val didDocument = DidDocument(
DidJwkDocument(did, key.exportJWKObject())
DidJwkDocument(did, key.getPublicKey().exportJWKObject())
.toMap()
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ class DidKeyRegistrar : LocalRegistrarMethod("key") {
KeyType.secp256r1
)
) throw IllegalArgumentException("did:key can not be created with a ${key.keyType} key.")
val identifierComponents = getIdentifierComponents(key, it)
val pubKey = key.getPublicKey()
val identifierComponents = getIdentifierComponents(pubKey, it)
val identifier = convertRawKeyToMultiBase58Btc(identifierComponents.pubKeyBytes, identifierComponents.multiCodecKeyCode)
createDid(identifier, key.exportJWKObject())
createDid(identifier, pubKey.exportJWKObject())
}

private suspend fun getIdentifierComponents(key: Key, options: DidCreateOptions): IdentifierComponents =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ class DidWebRegistrar : LocalRegistrarMethod("web") {
DidResult(
"did:web:$domain$path", DidDocument(
DidWebDocument(
did = "did:web:$domain$path", keyId = key.getKeyId(), didKey = key.exportJWKObject()
did = "did:web:$domain$path",
keyId = key.getKeyId(),
didKey = key.getPublicKey().exportJWKObject()
).toMap()
)
)
Expand Down

0 comments on commit c19ee12

Please sign in to comment.