Skip to content

Commit 330a16b

Browse files
authored
Merge pull request #53 from filip26/feat/didkey-create
0.3.0 - DidKey.create
2 parents 679ce0e + e484289 commit 330a16b

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ An implementation of the [Decentralized Identifiers (DIDs) v1.0](https://www.w3.
2323
<dependency>
2424
<groupId>com.apicatalog</groupId>
2525
<artifactId>carbon-did</artifactId>
26-
<version>0.2.0</version>
26+
<version>0.3.0</version>
2727
</dependency>
2828

2929
```
@@ -32,7 +32,7 @@ An implementation of the [Decentralized Identifiers (DIDs) v1.0](https://www.w3.
3232
Android API Level >=24
3333

3434
```gradle
35-
implementation("com.apicatalog:carbon-did:0.2.0")
35+
implementation("com.apicatalog:carbon-did:0.3.0")
3636
```
3737

3838

pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<groupId>com.apicatalog</groupId>
88
<artifactId>carbon-did</artifactId>
99

10-
<version>0.2.0</version>
10+
<version>0.3.0</version>
1111
<packaging>jar</packaging>
1212

1313
<url>https://github.com/filip26/carbon-decentralized-identifiers</url>
@@ -59,7 +59,7 @@
5959
<jakarta.json.version>2.0.1</jakarta.json.version>
6060

6161
<copper.multicodec.version>0.1.1</copper.multicodec.version>
62-
<copper.multibase.version>0.4.0</copper.multibase.version>
62+
<copper.multibase.version>0.5.0</copper.multibase.version>
6363

6464
<!-- test resources -->
6565
<junit.version>5.10.2</junit.version>

src/main/java/com/apicatalog/did/key/DidKey.java

+16-6
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,14 @@ public class DidKey extends Did {
2626

2727
public static final String METHOD_KEY = "key";
2828

29-
private final Multicodec codec;
29+
protected final Multibase base;
30+
protected final Multicodec codec;
3031

31-
private final byte[] rawKey;
32+
protected final byte[] rawKey;
3233

33-
protected DidKey(Did did, Multicodec codec, byte[] rawValue) {
34-
super(did.getMethod(), did.getVersion(), did.getMethodSpecificId());
34+
protected DidKey(String version, String encoded, Multibase base, Multicodec codec, byte[] rawValue) {
35+
super(METHOD_KEY, version, encoded);
36+
this.base = base;
3537
this.codec = codec;
3638
this.rawKey = rawValue;
3739
}
@@ -65,14 +67,18 @@ public static final DidKey from(final Did did, final MultibaseDecoder bases, fin
6567
}
6668

6769
final Multibase base = bases.getBase(did.getMethodSpecificId()).orElseThrow(() -> new IllegalArgumentException("Unsupported did:key base encoding. DID [" + did.toString() + "]."));
68-
70+
6971
final byte[] decoded = base.decode(did.getMethodSpecificId());
7072

7173
final Multicodec codec = codecs.getCodec(decoded).orElseThrow(() -> new IllegalArgumentException("Unsupported did:key codec. DID [" + did.toString() + "]."));
7274

7375
final byte[] rawKey = codec.decode(decoded);
7476

75-
return new DidKey(did, codec, rawKey);
77+
return new DidKey(did.getVersion(), did.getMethodSpecificId(), base, codec, rawKey);
78+
}
79+
80+
public static final DidKey create(Multibase base, Multicodec codec, byte[] rawKey) {
81+
return new DidKey(null, base.encode(codec.encode(rawKey)), base, codec, rawKey);
7682
}
7783

7884
public static boolean isDidKey(final Did did) {
@@ -93,6 +99,10 @@ public Multicodec getCodec() {
9399
return codec;
94100
}
95101

102+
public Multibase getBase() {
103+
return base;
104+
}
105+
96106
public byte[] getRawKey() {
97107
return rawKey;
98108
}

0 commit comments

Comments
 (0)