diff --git a/README.md b/README.md index 1c15cf0..38ad517 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ An implementation of the [Decentralized Identifiers (DIDs) v1.0](https://www.w3. com.apicatalog carbon-did - 0.0.7 + 0.1.0 ``` @@ -30,7 +30,7 @@ An implementation of the [Decentralized Identifiers (DIDs) v1.0](https://www.w3. Android API Level >=24 ```gradle -implementation("com.apicatalog:carbon-did:0.0.7") +implementation("com.apicatalog:carbon-did:0.1.0") ``` diff --git a/pom.xml b/pom.xml index ed218d1..a14969e 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ com.apicatalog carbon-did - 0.0.7 + 0.1.0 jar https://github.com/filip26/carbon-decentralized-identifiers @@ -58,8 +58,8 @@ 2.0.1 - 0.0.6 - 0.0.1 + 0.1.1 + 0.0.2 5.10.1 diff --git a/src/main/java/com/apicatalog/did/key/DidKey.java b/src/main/java/com/apicatalog/did/key/DidKey.java index 264f4a7..b3a0ca3 100644 --- a/src/main/java/com/apicatalog/did/key/DidKey.java +++ b/src/main/java/com/apicatalog/did/key/DidKey.java @@ -23,12 +23,12 @@ */ public class DidKey extends Did { - private static final long serialVersionUID = 582726516478574544L; + private static final long serialVersionUID = 3710900614215756688L; public static final String METHOD_KEY = "key"; protected static final MulticodecDecoder MULTICODEC = MulticodecDecoder.getInstance(Tag.Key); - protected static final MultibaseDecoder MULTIBASE = MultibaseDecoder.getInstance(Multibase.BASE_58_BTC); + protected static final MultibaseDecoder MULTIBASE = MultibaseDecoder.getInstance(); private final Multicodec codec; @@ -68,7 +68,9 @@ public static final DidKey from(final Did did) { throw new IllegalArgumentException("The given DID method [" + did.getMethod() + "] is not 'key'. DID [" + did.toString() + "]."); } - final byte[] decoded = MULTIBASE.decode(did.getMethodSpecificId()); + final Multibase base = MULTIBASE.getBase(did.getMethodSpecificId()).orElseThrow(() -> new IllegalArgumentException("Cannot detect did:key base encoding.")); + + final byte[] decoded = base.decode(did.getMethodSpecificId()); final Multicodec codec = MULTICODEC.getCodec(decoded).orElseThrow(() -> new IllegalArgumentException("Cannot detect did:key codec.")); diff --git a/src/main/java/com/apicatalog/did/key/DidKeyResolver.java b/src/main/java/com/apicatalog/did/key/DidKeyResolver.java index 7dc9b34..2509e0e 100644 --- a/src/main/java/com/apicatalog/did/key/DidKeyResolver.java +++ b/src/main/java/com/apicatalog/did/key/DidKeyResolver.java @@ -48,13 +48,6 @@ public DidDocument resolve(final Did did) { * @return The new verification key */ public static DidVerificationMethod createSignatureMethod(DidKey didKey) { - -// if (!Multicodec.Codec.Ed25519PublicKey.equals(didKey.getCodec())) { -// throw new IllegalArgumentException(); -// } - // 5. -// String encodingType = ED25519_VERIFICATION_KEY_2020_TYPE; - return new DidVerificationMethod( DidUrl.from(didKey, null, null, didKey.getMethodSpecificId()), DidUrl.from(didKey, null, null, didKey.getMethodSpecificId()), diff --git a/src/test/java/com/apicatalog/did/DidKeyTest.java b/src/test/java/com/apicatalog/did/DidKeyTest.java index a06d3df..fadff31 100644 --- a/src/test/java/com/apicatalog/did/DidKeyTest.java +++ b/src/test/java/com/apicatalog/did/DidKeyTest.java @@ -14,7 +14,7 @@ import org.junit.jupiter.params.provider.MethodSource; import com.apicatalog.did.key.DidKey; -import com.apicatalog.multicodec.MulticodecRegistry; +import com.apicatalog.multicodec.codec.KeyCodec; @DisplayName("DID Key") @TestMethodOrder(OrderAnnotation.class) @@ -54,77 +54,77 @@ static Stream testVectors() { static final DidKeyTestCase testCases[] = new DidKeyTestCase[] { DidKeyTestCase.create( "did:key:z6MkpTHR8VNsBxYAAWHut2Geadd9jSwuBV8xRoAnwWsdvktH", - MulticodecRegistry.ED25519_PUBLIC_KEY, + KeyCodec.ED25519_PUBLIC_KEY, 32 ), DidKeyTestCase.create( "did:key:z6MkiTBz1ymuepAQ4HEHYSF1H8quG5GLVVQR3djdX3mDooWp", - MulticodecRegistry.ED25519_PUBLIC_KEY, + KeyCodec.ED25519_PUBLIC_KEY, 32 ), DidKeyTestCase.create( "did:key:z6MkjchhfUsD6mmvni8mCdXHw216Xrm9bQe2mBH1P5RDjVJG", - MulticodecRegistry.ED25519_PUBLIC_KEY, + KeyCodec.ED25519_PUBLIC_KEY, 32 ), DidKeyTestCase.create( "did:key:z6MknGc3ocHs3zdPiJbnaaqDi58NGb4pk1Sp9WxWufuXSdxf", - MulticodecRegistry.ED25519_PUBLIC_KEY, + KeyCodec.ED25519_PUBLIC_KEY, 32 ), DidKeyTestCase.create( "did:key:z6MkicdicToW5HbxPP7zZV1H7RHvXgRMhoujWAF2n5WQkdd2", - MulticodecRegistry.ED25519_PUBLIC_KEY, + KeyCodec.ED25519_PUBLIC_KEY, 32 ), DidKeyTestCase.create( "did:key:z6MkiVQTYk3L2XKY6yg6MyeN2QLE5QkKcXByUeY1dkdiLx4j", - MulticodecRegistry.ED25519_PUBLIC_KEY, + KeyCodec.ED25519_PUBLIC_KEY, 32 ), DidKeyTestCase.create( "did:key:zQ3shokFTS3brHcDQrn82RUDfCZESWL1ZdCEJwekUDPQiYBme", - MulticodecRegistry.SECP256K1_PUBLIC_KEY, + KeyCodec.SECP256K1_PUBLIC_KEY, 33 ), DidKeyTestCase.create( "did:key:zQ3shtxV1FrJfhqE1dvxYRcCknWNjHc3c5X1y3ZSoPDi2aur2", - MulticodecRegistry.SECP256K1_PUBLIC_KEY, + KeyCodec.SECP256K1_PUBLIC_KEY, 33 ), DidKeyTestCase.create( "did:key:zQ3shZc2QzApp2oymGvQbzP8eKheVshBHbU4ZYjeXqwSKEn6N", - MulticodecRegistry.SECP256K1_PUBLIC_KEY, + KeyCodec.SECP256K1_PUBLIC_KEY, 33 ), DidKeyTestCase.create( "did:key:zDnaerDaTF5BXEavCrfRZEk316dpbLsfPDZ3WJ5hRTPFU2169", - MulticodecRegistry.P256_PUBLIC_KEY, + KeyCodec.P256_PUBLIC_KEY, 33 ), DidKeyTestCase.create( "did:key:zDnaerx9CtbPJ1q36T5Ln5wYt3MQYeGRG5ehnPAmxcf5mDZpv", - MulticodecRegistry.P256_PUBLIC_KEY, + KeyCodec.P256_PUBLIC_KEY, 33 ), DidKeyTestCase.create( "did:key:z82Lm1MpAkeJcix9K8TMiLd5NMAhnwkjjCBeWHXyu3U4oT2MVJJKXkcVBgjGhnLBn2Kaau9", - MulticodecRegistry.P384_PUBLIC_KEY, + KeyCodec.P384_PUBLIC_KEY, 49 ), DidKeyTestCase.create( "did:key:z82LkvCwHNreneWpsgPEbV3gu1C6NFJEBg4srfJ5gdxEsMGRJUz2sG9FE42shbn2xkZJh54", - MulticodecRegistry.P384_PUBLIC_KEY, + KeyCodec.P384_PUBLIC_KEY, 49 ), DidKeyTestCase.create( "did:key:z2J9gaYxrKVpdoG9A4gRnmpnRCcxU6agDtFVVBVdn1JedouoZN7SzcyREXXzWgt3gGiwpoHq7K68X4m32D8HgzG8wv3sY5j7", - MulticodecRegistry.P521_PUBLIC_KEY, + KeyCodec.P521_PUBLIC_KEY, 67 ), DidKeyTestCase.create( "did:key:z2J9gcGdb2nEyMDmzQYv2QZQcM1vXktvy1Pw4MduSWxGabLZ9XESSWLQgbuPhwnXN7zP7HpTzWqrMTzaY5zWe6hpzJ2jnw4f", - MulticodecRegistry.P521_PUBLIC_KEY, + KeyCodec.P521_PUBLIC_KEY, 67 ), @@ -136,13 +136,13 @@ static Stream testVectors() { // versioned keys DidKeyTestCase.create( "did:key:1.1:z6MkicdicToW5HbxPP7zZV1H7RHvXgRMhoujWAF2n5WQkdd2", - MulticodecRegistry.ED25519_PUBLIC_KEY, + KeyCodec.ED25519_PUBLIC_KEY, 32, "1.1" ), DidKeyTestCase.create( "did:key:0.7:z6MkicdicToW5HbxPP7zZV1H7RHvXgRMhoujWAF2n5WQkdd2", - MulticodecRegistry.ED25519_PUBLIC_KEY, + KeyCodec.ED25519_PUBLIC_KEY, 32, "0.7" ),