Skip to content

Commit

Permalink
did 체크 함수 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
YoungBaeJeon committed Jan 28, 2021
1 parent a20c161 commit d756a87
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
23 changes: 23 additions & 0 deletions src/main/java/com/metadium/did/MetadiumWallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,29 @@ public static MetadiumWallet createDid(MetaDelegator metaDelegator, MetadiumKey
}
}

/**
* DID 가 블럭체인상에 존재하는지 확인
* @param metaDelegator {@link MetaDelegator}
* @return 존재하는 경우 true
* @throws DidException
* @throws Exception
*/
public boolean existsDid(MetaDelegator metaDelegator) throws DidException, Exception {
IdentityRegistry identityRegistry = IdentityRegistry.load(
metaDelegator.getAllServiceAddress().identityRegistry,
metaDelegator.getWeb3j(),
new NotSignTransactionManager(metaDelegator.getWeb3j()),
new ZeroContractGasProvider()
);

try {
return identityRegistry.hasIdentity(key.getAddress()).send();
}
catch (Exception e) {
throw new IOException(e);
}
}

/**
* 서비스 키 추가
*
Expand Down
6 changes: 5 additions & 1 deletion src/test/java/com/metadium/did/DidTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
public class DidTest {

@Test
public void testCRUD() throws DidException, InvalidAlgorithmParameterException, ParseException {
public void testCRUD() throws DidException, InvalidAlgorithmParameterException, ParseException, Exception {
MetaDelegator delegator = new MetaDelegator("https://testdelegator.metadium.com", "https://testdelegator.metadium.com", "did:meta:testnet");

// Create did
Expand All @@ -50,9 +50,13 @@ public void testCRUD() throws DidException, InvalidAlgorithmParameterException,
assertNotNull(didDocument);
assertNotNull(didDocument.getPublicKey(wallet.getKid()));

assertTrue(wallet.existsDid(delegator));

// Delete did
wallet.deleteDid(delegator);

assertTrue(!wallet.existsDid(delegator));

// Check did document
didDocument = DIDResolverAPI.getInstance().getDocument(wallet.getDid());
assertNull(didDocument);
Expand Down

0 comments on commit d756a87

Please sign in to comment.