-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor DID related implementations
- Loading branch information
Showing
22 changed files
with
264 additions
and
172 deletions.
There are no files selected for viewing
4 changes: 1 addition & 3 deletions
4
src/main/java/tng/trustnetwork/keydistribution/clients/UniversalResolverClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,14 @@ | ||
package tng.trustnetwork.keydistribution.clients; | ||
|
||
import org.springframework.cloud.openfeign.FeignClient; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import tng.trustnetwork.keydistribution.model.DidDocument; | ||
|
||
@FeignClient(value = "universalresolver", url = "${universal.resolver}", | ||
configuration = UniversalResolverClientConfig.class) | ||
public interface UniversalResolverClient { | ||
|
||
@GetMapping(value = "/{didKey}", produces = "application/json") | ||
ResponseEntity<DidDocument> getDidDocument(@PathVariable("didKey") String didKey); | ||
String getDidDocument(@PathVariable("didKey") String didKey); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
src/main/java/tng/trustnetwork/keydistribution/entity/EcPublicKeyJwkEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package tng.trustnetwork.keydistribution.entity; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.DiscriminatorValue; | ||
import jakarta.persistence.Entity; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Entity | ||
@DiscriminatorValue("EC") | ||
public class EcPublicKeyJwkEntity extends PublicKeyJwkEntity { | ||
|
||
@Column(name = "crv", length = 100) | ||
private String crv; | ||
|
||
@Column(name = "x", length = 100) | ||
private String xvalue; | ||
|
||
@Column(name = "y", length = 100) | ||
private String yvalue; | ||
|
||
} |
31 changes: 11 additions & 20 deletions
31
src/main/java/tng/trustnetwork/keydistribution/entity/PublicKeyJwkEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,39 @@ | ||
package tng.trustnetwork.keydistribution.entity; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.DiscriminatorColumn; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Inheritance; | ||
import jakarta.persistence.InheritanceType; | ||
import jakarta.persistence.Table; | ||
import java.time.ZonedDateTime; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Data | ||
@Getter | ||
@Setter | ||
@Entity | ||
@Table(name = "public_key_jwk") | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class PublicKeyJwkEntity { | ||
@Entity | ||
@Table(name = "public_key_jwk") | ||
@Inheritance(strategy = InheritanceType.SINGLE_TABLE) | ||
@DiscriminatorColumn(name = "kty", columnDefinition = "varchar(10)") | ||
public abstract class PublicKeyJwkEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "id") | ||
private String id; | ||
|
||
@Column(name = "crv", length = 100) | ||
private String crv; | ||
|
||
@Column(name = "kty", length = 100) | ||
private String kty; | ||
private Long id; | ||
|
||
@Column(name = "x", length = 100) | ||
private String xvalue; | ||
|
||
@Column(name = "y", length = 100) | ||
private String yvalue; | ||
@Column(name = "created_at", nullable = false) | ||
private ZonedDateTime createdAt = ZonedDateTime.now(); | ||
|
||
@Column(name = "x5c", length = 7000) | ||
private String x5c; | ||
|
||
@Column(name = "created_at", nullable = false) | ||
private ZonedDateTime createdAt = ZonedDateTime.now(); | ||
|
||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/tng/trustnetwork/keydistribution/entity/RsaPublicKeyJwkEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package tng.trustnetwork.keydistribution.entity; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.DiscriminatorValue; | ||
import jakarta.persistence.Entity; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Entity | ||
@DiscriminatorValue("RSA") | ||
public class RsaPublicKeyJwkEntity extends PublicKeyJwkEntity { | ||
|
||
@Column(name = "n", length = 1000) | ||
private String nvalue; | ||
|
||
@Column(name = "e", length = 1000) | ||
private String evalue; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
src/main/java/tng/trustnetwork/keydistribution/mapper/DidMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package tng.trustnetwork.keydistribution.mapper; | ||
|
||
import java.util.List; | ||
import org.mapstruct.Mapper; | ||
import org.mapstruct.Mapping; | ||
import org.mapstruct.SubclassExhaustiveStrategy; | ||
import org.mapstruct.SubclassMapping; | ||
import tng.trustnetwork.keydistribution.entity.DecentralizedIdentifierEntity; | ||
import tng.trustnetwork.keydistribution.entity.EcPublicKeyJwkEntity; | ||
import tng.trustnetwork.keydistribution.entity.PublicKeyJwkEntity; | ||
import tng.trustnetwork.keydistribution.entity.RsaPublicKeyJwkEntity; | ||
import tng.trustnetwork.keydistribution.entity.VerificationMethodEntity; | ||
import tng.trustnetwork.keydistribution.model.DidDocument; | ||
import tng.trustnetwork.keydistribution.model.EcPublicKeyJwk; | ||
import tng.trustnetwork.keydistribution.model.JwkVerificationMethod; | ||
import tng.trustnetwork.keydistribution.model.PublicKeyJwk; | ||
import tng.trustnetwork.keydistribution.model.RsaPublicKeyJwk; | ||
import tng.trustnetwork.keydistribution.model.StringOrObject; | ||
import tng.trustnetwork.keydistribution.model.VerificationMethod; | ||
|
||
@Mapper(componentModel = "spring", subclassExhaustiveStrategy = SubclassExhaustiveStrategy.RUNTIME_EXCEPTION) | ||
public interface DidMapper { | ||
|
||
@Mapping(target = "didId", source = "didDocument.id") | ||
@Mapping(target = "id", ignore = true) | ||
@Mapping(target = "verificationMethods", source = "didDocument.verificationMethod") | ||
DecentralizedIdentifierEntity toEntity(DidDocument didDocument, String raw); | ||
|
||
@SubclassMapping(target = RsaPublicKeyJwkEntity.class, source = RsaPublicKeyJwk.class) | ||
@SubclassMapping(target = EcPublicKeyJwkEntity.class, source = EcPublicKeyJwk.class) | ||
PublicKeyJwkEntity toEntity(PublicKeyJwk publicKeyJwk); | ||
|
||
@Mapping(target = "xvalue", source = "x") | ||
@Mapping(target = "yvalue", source = "y") | ||
EcPublicKeyJwkEntity toEntity(EcPublicKeyJwk model); | ||
|
||
@Mapping(target = "evalue", source = "e") | ||
@Mapping(target = "nvalue", source = "n") | ||
RsaPublicKeyJwkEntity toEntity(RsaPublicKeyJwk model); | ||
|
||
@SubclassMapping(target = VerificationMethodEntity.class, source = JwkVerificationMethod.class) | ||
VerificationMethodEntity toEntity(VerificationMethod verificationMethod); | ||
|
||
@Mapping(target = "type", constant = "JsonWebKey2020") | ||
@Mapping(target = "vmId", source = "verificationMethod.id") | ||
@Mapping(target = "id", ignore = true) | ||
VerificationMethodEntity toEntity(JwkVerificationMethod verificationMethod); | ||
|
||
default <T> T unwrap(StringOrObject<T> wrapped) { | ||
return wrapped.getObjectValue(); | ||
} | ||
|
||
default String toSingleString(List<String> list) { | ||
|
||
return String.join(",", list); | ||
} | ||
} |
3 changes: 0 additions & 3 deletions
3
src/main/java/tng/trustnetwork/keydistribution/model/DidDocument.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 1 addition & 5 deletions
6
...n/java/tng/trustnetwork/keydistribution/repository/DecentralizedIdentifierRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,7 @@ | ||
package tng.trustnetwork.keydistribution.repository; | ||
|
||
import java.util.List; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import tng.trustnetwork.keydistribution.entity.DecentralizedIdentifierEntity; | ||
|
||
public interface DecentralizedIdentifierRepository extends JpaRepository<DecentralizedIdentifierEntity, String> { | ||
List<DecentralizedIdentifierEntity> findAllById(String id); | ||
|
||
List<DecentralizedIdentifierEntity> findByDidId(String id); | ||
public interface DecentralizedIdentifierRepository extends JpaRepository<DecentralizedIdentifierEntity, Long> { | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/tng/trustnetwork/keydistribution/repository/PublicKeyJwkRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package tng.trustnetwork.keydistribution.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import tng.trustnetwork.keydistribution.entity.PublicKeyJwkEntity; | ||
|
||
public interface PublicKeyJwkRepository extends JpaRepository<PublicKeyJwkEntity, Long> { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/main/java/tng/trustnetwork/keydistribution/repository/VerificationMethodRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package tng.trustnetwork.keydistribution.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import tng.trustnetwork.keydistribution.entity.VerificationMethodEntity; | ||
|
||
public interface VerificationMethodRepository extends JpaRepository<VerificationMethodEntity, Long> { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.