diff --git a/README.md b/README.md
index 68fe166..3b54221 100644
--- a/README.md
+++ b/README.md
@@ -23,7 +23,7 @@ An implementation of the [Decentralized Identifiers (DIDs) v1.0](https://www.w3.
com.apicatalog
carbon-did
- 0.2.0
+ 0.3.0
```
@@ -32,7 +32,7 @@ An implementation of the [Decentralized Identifiers (DIDs) v1.0](https://www.w3.
Android API Level >=24
```gradle
-implementation("com.apicatalog:carbon-did:0.2.0")
+implementation("com.apicatalog:carbon-did:0.3.0")
```
diff --git a/pom.xml b/pom.xml
index 6f00230..7ee9dd2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -7,7 +7,7 @@
com.apicatalog
carbon-did
- 0.2.0
+ 0.3.0
jar
https://github.com/filip26/carbon-decentralized-identifiers
@@ -59,7 +59,7 @@
2.0.1
0.1.1
- 0.4.0
+ 0.5.0
5.10.2
diff --git a/src/main/java/com/apicatalog/did/key/DidKey.java b/src/main/java/com/apicatalog/did/key/DidKey.java
index 98dcb8c..add30ac 100644
--- a/src/main/java/com/apicatalog/did/key/DidKey.java
+++ b/src/main/java/com/apicatalog/did/key/DidKey.java
@@ -26,12 +26,14 @@ public class DidKey extends Did {
public static final String METHOD_KEY = "key";
- private final Multicodec codec;
+ protected final Multibase base;
+ protected final Multicodec codec;
- private final byte[] rawKey;
+ protected final byte[] rawKey;
- protected DidKey(Did did, Multicodec codec, byte[] rawValue) {
- super(did.getMethod(), did.getVersion(), did.getMethodSpecificId());
+ protected DidKey(String version, String encoded, Multibase base, Multicodec codec, byte[] rawValue) {
+ super(METHOD_KEY, version, encoded);
+ this.base = base;
this.codec = codec;
this.rawKey = rawValue;
}
@@ -65,14 +67,18 @@ public static final DidKey from(final Did did, final MultibaseDecoder bases, fin
}
final Multibase base = bases.getBase(did.getMethodSpecificId()).orElseThrow(() -> new IllegalArgumentException("Unsupported did:key base encoding. DID [" + did.toString() + "]."));
-
+
final byte[] decoded = base.decode(did.getMethodSpecificId());
final Multicodec codec = codecs.getCodec(decoded).orElseThrow(() -> new IllegalArgumentException("Unsupported did:key codec. DID [" + did.toString() + "]."));
final byte[] rawKey = codec.decode(decoded);
- return new DidKey(did, codec, rawKey);
+ return new DidKey(did.getVersion(), did.getMethodSpecificId(), base, codec, rawKey);
+ }
+
+ public static final DidKey create(Multibase base, Multicodec codec, byte[] rawKey) {
+ return new DidKey(null, base.encode(codec.encode(rawKey)), base, codec, rawKey);
}
public static boolean isDidKey(final Did did) {
@@ -93,6 +99,10 @@ public Multicodec getCodec() {
return codec;
}
+ public Multibase getBase() {
+ return base;
+ }
+
public byte[] getRawKey() {
return rawKey;
}