Skip to content

Commit

Permalink
feat: update lib method to resolved vc/vp validate
Browse files Browse the repository at this point in the history
  • Loading branch information
thackerronak committed Jun 5, 2023
1 parent 1698996 commit 6f70b09
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public VerifiableCredential issueFrameworkCredential(IssueFrameworkCredentialReq
Validate.isFalse(callerBPN.equals(baseWallet.getBpn())).launch(new ForbiddenException(BASE_WALLET_BPN_IS_NOT_MATCHING_WITH_REQUEST_BPN_FROM_TOKEN));

// get Key
byte[] privateKeyBytes = walletKeyService.getPrivateKeyByWalletIdentifier(baseWallet.getId());
byte[] privateKeyBytes = walletKeyService.getPrivateKeyByWalletIdentifierAsBytes(baseWallet.getId());

Map<String, Object> subject = Map.of("type", request.getType(),
"id", holderWallet.getDid(),
Expand Down Expand Up @@ -225,7 +225,7 @@ public VerifiableCredential issueDismantlerCredential(IssueDismantlerCredentialR
//check duplicate
isCredentialExit(holderWallet.getDid(), MIWVerifiableCredentialType.DISMANTLER_CREDENTIAL_CX);

byte[] privateKeyBytes = walletKeyService.getPrivateKeyByWalletIdentifier(baseWallet.getId());
byte[] privateKeyBytes = walletKeyService.getPrivateKeyByWalletIdentifierAsBytes(baseWallet.getId());

Map<String, Object> subject = Map.of("type", MIWVerifiableCredentialType.DISMANTLER_CREDENTIAL,
"id", holderWallet.getDid(),
Expand Down Expand Up @@ -264,7 +264,7 @@ public VerifiableCredential issueMembershipCredential(IssueMembershipCredentialR
//validate BPN access
Validate.isFalse(callerBPN.equals(baseWallet.getBpn())).launch(new ForbiddenException(BASE_WALLET_BPN_IS_NOT_MATCHING_WITH_REQUEST_BPN_FROM_TOKEN));

byte[] privateKeyBytes = walletKeyService.getPrivateKeyByWalletIdentifier(baseWallet.getId());
byte[] privateKeyBytes = walletKeyService.getPrivateKeyByWalletIdentifierAsBytes(baseWallet.getId());
List<String> types = List.of(VerifiableCredentialType.VERIFIABLE_CREDENTIAL, MIWVerifiableCredentialType.MEMBERSHIP_CREDENTIAL_CX);
//VC Subject
Credential credential = CommonUtils.getCredential(Map.of("type", VerifiableCredentialType.MEMBERSHIP_CREDENTIAL,
Expand Down Expand Up @@ -297,7 +297,7 @@ public Map<String, Object> credentialsValidation(Map<String, Object> data) {
// DID Resolver Constracture params
DidWebParser didParser = new DidWebParser();
var httpClient = HttpClient.newHttpClient();
var enforceHttps = true;
var enforceHttps = false;

var didDocumentResolverRegistry = new DidDocumentResolverRegistryImpl();
didDocumentResolverRegistry.register(
Expand All @@ -319,7 +319,7 @@ public VerifiableCredential issueCredential(Map<String, Object> data, String cal
Validate.isFalse(callerBpn.equals(issuerWallet.getBpn())).launch(new ForbiddenException(BASE_WALLET_BPN_IS_NOT_MATCHING_WITH_REQUEST_BPN_FROM_TOKEN));

// get Key
byte[] privateKeyBytes = walletKeyService.getPrivateKeyByWalletIdentifier(issuerWallet.getId());
byte[] privateKeyBytes = walletKeyService.getPrivateKeyByWalletIdentifierAsBytes(issuerWallet.getId());

// Create Credential
Credential credential = CommonUtils.getCredential(verifiableCredential.getCredentialSubject().get(0),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public Map<String, Object> createPresentation(Map<String, Object> data, boolean

//Build JWT
SignedJWT presentation = presentationFactory.createPresentation(
issuerDid, verifiableCredentials, audience, walletKeyService.getEd25519Key(holderWallet.getId()));
issuerDid, verifiableCredentials, audience, walletKeyService.getPrivateKeyByWalletIdentifier(holderWallet.getId()));

response.put("vp", presentation.serialize());
} else {
Expand Down Expand Up @@ -169,7 +169,7 @@ public Map<String, Object> validatePresentation(Map<String, Object> vp, boolean
//validate jwt signature
DidWebParser didParser = new DidWebParser();
var httpClient = HttpClient.newHttpClient();
var enforceHttps = true;
var enforceHttps = false;

var didDocumentResolverRegistry = new DidDocumentResolverRegistryImpl();
didDocumentResolverRegistry.register(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,16 @@ protected SpecificationUtil<WalletKey> getSpecificationUtil() {


@SneakyThrows
public byte[] getPrivateKeyByWalletIdentifier(long walletId) {
WalletKey wallet = walletKeyRepository.getByWalletId(walletId);
String privateKey = encryptionUtils.decrypt(wallet.getPrivateKey());
return new PemReader(new StringReader(privateKey)).readPemObject().getContent();
public byte[] getPrivateKeyByWalletIdentifierAsBytes(long walletId) {
return getPrivateKeyByWalletIdentifier(walletId).getEncoded();
}

@SneakyThrows
public Ed25519Key getEd25519Key(long walletId) {
return new Ed25519Key(getPrivateKeyByWalletIdentifier(walletId));

public Ed25519Key getPrivateKeyByWalletIdentifier(long walletId) {
WalletKey wallet = walletKeyRepository.getByWalletId(walletId);
String privateKey = encryptionUtils.decrypt(wallet.getPrivateKey());
byte[] content = new PemReader(new StringReader(privateKey)).readPemObject().getContent();
return Ed25519Key.asPrivateKey(content);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ public Wallet createWallet(CreateWalletRequest request) {

//issue BPN credentials``
Wallet baseWallet = getWalletByIdentifier(miwSettings.authorityWalletBpn());
byte[] privateKeyBytes = walletKeyService.getPrivateKeyByWalletIdentifier(baseWallet.getId());
byte[] privateKeyBytes = walletKeyService.getPrivateKeyByWalletIdentifierAsBytes(baseWallet.getId());
List<String> types = List.of(VerifiableCredentialType.VERIFIABLE_CREDENTIAL, MIWVerifiableCredentialType.BPN_CREDENTIAL_CX);
Credential credential = CommonUtils.getCredential(Map.of("type", MIWVerifiableCredentialType.BPN_CREDENTIAL,
"id", wallet.getDid(),
Expand Down

0 comments on commit 6f70b09

Please sign in to comment.