From 29e072c68c85b7bf0ea3aa2cc40c13136720acae Mon Sep 17 00:00:00 2001 From: Essbante Date: Wed, 13 Apr 2022 01:40:06 -0600 Subject: [PATCH 1/2] refactor: change git PAT environment variable names Change git PAT environment variable names so they match wal-cli ones. --- build.gradle.kts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index f6a7e32..9e68c4d 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -62,8 +62,8 @@ publishing { name = "GitHubPackages" url = uri("https://maven.pkg.github.com/roots-id/wal-library") credentials { - username = System.getenv("ROOTSID_USER") - password = System.getenv("ROOTSID_PASSWORD") + username = System.getenv("GITHUB_USER") + password = System.getenv("GITHUB_TOKEN") } } } From b1787e248736d2146936538d69243989efbf9c68 Mon Sep 17 00:00:00 2001 From: Essbante Date: Wed, 13 Apr 2022 01:46:55 -0600 Subject: [PATCH 2/2] feat: add a log to register blockchain transactions The log must show: action: one of ADD_KEY, REVOKE_KEY, PUBLISH_DID, ISSUE_CREDENTIAL, REVOKE_CREDENTIAL URL: to open the transaction on a blockchain explorer transaction-id: raw tx identifier --- .../kotlin/com/rootsid/wal/library/DLT.kt | 54 ++++++++++++++++--- .../kotlin/com/rootsid/wal/library/Model.kt | 36 ++++++++++++- 2 files changed, 83 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/com/rootsid/wal/library/DLT.kt b/src/main/kotlin/com/rootsid/wal/library/DLT.kt index fe3dac4..6c8e6d0 100644 --- a/src/main/kotlin/com/rootsid/wal/library/DLT.kt +++ b/src/main/kotlin/com/rootsid/wal/library/DLT.kt @@ -38,6 +38,31 @@ private fun transactionId(oid: AtalaOperationId): String { return response.transactionId } +/** + * Wait for submission + * + * @param nodePublicApi PRISM node + * @param operationId operation Identifier + * @param action action associated with the operation (for traceability) + * @return Log Entry + */ +private fun waitForSubmission(nodePublicApi: NodePublicApi, operationId: AtalaOperationId, action: BlockchainTxAction): BlockchainTxLogEntry { + var status = runBlocking { + nodePublicApi.getOperationInfo(operationId).status + } + + while (status == AtalaOperationStatus.PENDING_SUBMISSION) { + println("Current operation status: ${AtalaOperationStatus.asString(status)}\n") + Thread.sleep(10000) + status = runBlocking { + nodePublicApi.getOperationInfo(operationId).status + } + } + val tid = transactionId(operationId) + println("Track the transaction in:\n- ${Config.TESTNET_URL}$tid\n") + return BlockchainTxLogEntry(tid, action, "${Config.TESTNET_URL}$tid") +} + /** * Wait until confirmed * @@ -45,17 +70,14 @@ private fun transactionId(oid: AtalaOperationId): String { * @param operationId operation Identifier */ private fun waitUntilConfirmed(nodePublicApi: NodePublicApi, operationId: AtalaOperationId) { - var tid = "" + var status = runBlocking { nodePublicApi.getOperationInfo(operationId).status } + while (status != AtalaOperationStatus.CONFIRMED_AND_APPLIED && status != AtalaOperationStatus.CONFIRMED_AND_REJECTED ) { - if (status == AtalaOperationStatus.AWAIT_CONFIRMATION && tid.isEmpty()) { - tid = transactionId(operationId) - println("Track the transaction in:\n- ${Config.TESTNET_URL}$tid\n") - } println("Current operation status: ${AtalaOperationStatus.asString(status)}\n") Thread.sleep(10000) status = runBlocking { @@ -205,7 +227,7 @@ fun getDidDocument(wallet: Wallet, didAlias: String): PrismDidDataModel { /** * Publish did * - * @param wallet Wallet contining the DID + * @param wallet Wallet containing the DID * @param didAlias Alias of the DID * @return updated wallet */ @@ -238,6 +260,10 @@ fun publishDid(wallet: Wallet, didAlias: String): Wallet { PrismDid.DEFAULT_MASTER_KEY_ID ) } + + wallet.addBlockchainTxLog( + waitForSubmission(nodeAuthApi, createDidOperationId, BlockchainTxAction.PUBLISH_DID) + ) waitUntilConfirmed(nodeAuthApi, createDidOperationId) val response = runBlocking { nodeAuthApi.getOperationInfo(createDidOperationId) } @@ -310,6 +336,10 @@ fun addKey(wallet: Wallet, didAlias: String, keyId: String, keyTypeValue: Int): keysToRevoke = arrayOf() ) } + + wallet.addBlockchainTxLog( + waitForSubmission(nodeAuthApi, updateDidOperationId, BlockchainTxAction.ADD_KEY) + ) waitUntilConfirmed(nodeAuthApi, updateDidOperationId) val response = runBlocking { nodeAuthApi.getOperationInfo(updateDidOperationId) } @@ -365,6 +395,10 @@ fun revokeKey(wallet: Wallet, didAlias: String, keyId: String): Wallet { keysToRevoke = arrayOf(keyId) ) } + + wallet.addBlockchainTxLog( + waitForSubmission(nodeAuthApi, updateDidOperationId, BlockchainTxAction.REVOKE_KEY) + ) waitUntilConfirmed(nodeAuthApi, updateDidOperationId) val response = runBlocking { nodeAuthApi.getOperationInfo(updateDidOperationId) } @@ -430,6 +464,10 @@ fun issueCredential(wallet: Wallet, didAlias: String, issuedCredential: IssuedCr credentialsInfo.merkleRoot ) } + + wallet.addBlockchainTxLog( + waitForSubmission(nodeAuthApi, issueCredentialsOperationId, BlockchainTxAction.ISSUE_CREDENTIAL) + ) waitUntilConfirmed(nodeAuthApi, issueCredentialsOperationId) val response = runBlocking { nodeAuthApi.getOperationInfo(issueCredentialsOperationId) } @@ -484,6 +522,10 @@ fun revokeCredential(wallet: Wallet, credentialAlias: String): Wallet { arrayOf(Sha256Digest.fromHex(credential.credentialHash)) ) } + + wallet.addBlockchainTxLog( + waitForSubmission(nodeAuthApi, revokeOperationId, BlockchainTxAction.REVOKE_CREDENTIAL) + ) waitUntilConfirmed(nodeAuthApi, revokeOperationId) val status = runBlocking { nodeAuthApi.getOperationInfo(revokeOperationId).status } diff --git a/src/main/kotlin/com/rootsid/wal/library/Model.kt b/src/main/kotlin/com/rootsid/wal/library/Model.kt index f9629eb..ac29e11 100644 --- a/src/main/kotlin/com/rootsid/wal/library/Model.kt +++ b/src/main/kotlin/com/rootsid/wal/library/Model.kt @@ -27,9 +27,19 @@ data class Wallet( // List of imported (Issued elsewhere) var importedCredentials: MutableList = mutableListOf(), // List of credentials issued by a DID from this wallet - var issuedCredentials: MutableList = mutableListOf() + var issuedCredentials: MutableList = mutableListOf(), + var blockchainTxLogEntry: MutableList = mutableListOf() ) +/** + * Add blockchain tx log + * + * @param entry blockchain transaction log entry + */ +fun Wallet.addBlockchainTxLog(entry: BlockchainTxLogEntry) { + blockchainTxLogEntry.add(entry) +} + /** * D i d * @@ -75,6 +85,30 @@ data class KeyPair( var revoked: Boolean = false ) +/** + * Blockchain tx log + * + * @property txId transaction id + * @property action one of ADD_KEY, REVOKE_KEY, PUBLISH_DID, ISSUE_CREDENTIAL, REVOKE_CREDENTIAL + * @property url to open the transaction on a blockchain explorer + * @constructor Create empty Blockchain tx log + */ +@Serializable +data class BlockchainTxLogEntry( + val txId: String, + val action: BlockchainTxAction, + val url: String +) + +// Enum for blockchain tx actions +enum class BlockchainTxAction { + ADD_KEY, + REVOKE_KEY, + PUBLISH_DID, + ISSUE_CREDENTIAL, + REVOKE_CREDENTIAL +} + /** * Verified credential *