Skip to content

Commit

Permalink
Merge branch 'main' into feature/ATL-7641
Browse files Browse the repository at this point in the history
  • Loading branch information
cristianIOHK authored Sep 16, 2024
2 parents 6872749 + 93d21c8 commit 78e72c6
Show file tree
Hide file tree
Showing 16 changed files with 111 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import org.hyperledger.identus.walletsdk.edgeagent.protocols.issueCredential.Off
import org.hyperledger.identus.walletsdk.edgeagent.protocols.proofOfPresentation.PresentationSubmission
import org.hyperledger.identus.walletsdk.edgeagent.protocols.proofOfPresentation.RequestPresentation
import org.hyperledger.identus.walletsdk.domain.models.KeyValue
import org.hyperledger.identus.walletsdk.logger.PrismLoggerMock
import org.hyperledger.identus.walletsdk.logger.LoggerMock
import org.hyperledger.identus.walletsdk.mercury.ApiMock
import org.hyperledger.identus.walletsdk.pollux.PolluxImpl
import org.hyperledger.identus.walletsdk.pollux.models.AnonCredential
Expand Down Expand Up @@ -114,7 +114,7 @@ class AnoncredsTests {
connectionManager = connectionManager,
seed = null,
api = ApiMock(statusCode = HttpStatusCode.OK, response = "{\"success\":\"true\"}"),
logger = PrismLoggerMock()
logger = LoggerMock()
)

val attachmentDescriptor =
Expand Down Expand Up @@ -192,7 +192,7 @@ class AnoncredsTests {
connectionManager = connectionManager,
seed = null,
api = ApiMock(HttpStatusCode.OK, "{\"success\":\"true\"}"),
logger = PrismLoggerMock()
logger = LoggerMock()
)

val attachmentDescriptor =
Expand Down Expand Up @@ -263,7 +263,7 @@ class AnoncredsTests {
connectionManager = connectionManagerMock,
seed = seed,
api = apiMock,
logger = PrismLoggerMock()
logger = LoggerMock()
)

val credential = AnonCredential.fromStorableData(
Expand Down Expand Up @@ -355,7 +355,7 @@ class AnoncredsTests {
connectionManager = connectionManagerMock,
seed = seed,
api = apiMock,
logger = PrismLoggerMock()
logger = LoggerMock()
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,25 @@ import org.hyperledger.identus.walletsdk.domain.models.keyManagement.SeedKey
import org.hyperledger.identus.walletsdk.domain.models.keyManagement.StorableKey
import org.hyperledger.identus.walletsdk.domain.models.keyManagement.StorablePrivateKey
import org.hyperledger.identus.walletsdk.domain.models.keyManagement.TypeKey
import org.hyperledger.identus.walletsdk.logger.LogComponent
import org.hyperledger.identus.walletsdk.logger.LogLevel
import org.hyperledger.identus.walletsdk.logger.Logger
import org.hyperledger.identus.walletsdk.logger.LoggerImpl

/**
* Apollo defines the set of cryptographic operations that are used in the Atala PRISM.
*/
class ApolloImpl : Apollo {
class ApolloImpl(
val logger: Logger = LoggerImpl(LogComponent.APOLLO)
) : Apollo {

/**
* Creates a random set of mnemonic phrases that can be used as a seed for generating a private key.
*
* @return An array of mnemonic phrases.
*/
override fun createRandomMnemonics(): Array<String> {
LogComponent.APOLLO.logLevel = LogLevel.INFO
return MnemonicHelper.createRandomMnemonics().toTypedArray()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ import org.hyperledger.identus.walletsdk.domain.models.keyManagement.PublicKey
import org.hyperledger.identus.walletsdk.logger.LogComponent
import org.hyperledger.identus.walletsdk.logger.LogLevel
import org.hyperledger.identus.walletsdk.logger.Metadata
import org.hyperledger.identus.walletsdk.logger.PrismLogger
import org.hyperledger.identus.walletsdk.logger.PrismLoggerImpl
import org.hyperledger.identus.walletsdk.logger.Logger
import org.hyperledger.identus.walletsdk.logger.LoggerImpl

/**
* Castor is a powerful and flexible library for working with DIDs. Whether you are building a decentralised application
Expand All @@ -36,7 +36,7 @@ class CastorImpl
@JvmOverloads
constructor(
val apollo: Apollo,
private val logger: PrismLogger = PrismLoggerImpl(LogComponent.CASTOR)
private val logger: Logger = LoggerImpl(LogComponent.CASTOR)
) : Castor {
var resolvers: Array<DIDResolver> = arrayOf(
LongFormPrismDIDResolver(this.apollo),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ import org.hyperledger.identus.walletsdk.domain.models.keyManagement.KeyPair
import org.hyperledger.identus.walletsdk.domain.models.keyManagement.PublicKey
import org.hyperledger.identus.walletsdk.logger.LogComponent
import org.hyperledger.identus.walletsdk.logger.LogLevel
import org.hyperledger.identus.walletsdk.logger.LoggerImpl
import org.hyperledger.identus.walletsdk.logger.Metadata
import org.hyperledger.identus.walletsdk.logger.PrismLoggerImpl
import org.kotlincrypto.hash.sha2.SHA256
import pbandk.decodeFromByteArray
import pbandk.encodeToByteArray
Expand All @@ -64,7 +64,7 @@ internal class CastorShared {
*
* @property logger The logger instance.
*/
private val logger = PrismLoggerImpl(LogComponent.CASTOR)
private val logger = LoggerImpl(LogComponent.CASTOR)

/**
* parseDID parses a string representation of a Decentralized Identifier (DID) into a DID object.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ import org.hyperledger.identus.walletsdk.edgeagent.protocols.proofOfPresentation
import org.hyperledger.identus.walletsdk.edgeagent.protocols.proofOfPresentation.RequestPresentation
import org.hyperledger.identus.walletsdk.logger.LogComponent
import org.hyperledger.identus.walletsdk.logger.Metadata
import org.hyperledger.identus.walletsdk.logger.PrismLogger
import org.hyperledger.identus.walletsdk.logger.PrismLoggerImpl
import org.hyperledger.identus.walletsdk.logger.Logger
import org.hyperledger.identus.walletsdk.logger.LoggerImpl
import org.hyperledger.identus.walletsdk.pluto.PlutoBackupTask
import org.hyperledger.identus.walletsdk.pluto.PlutoRestoreTask
import org.hyperledger.identus.walletsdk.pluto.models.backup.BackupV0_0_1
Expand Down Expand Up @@ -157,7 +157,7 @@ open class EdgeAgent {
private val edgeAgentScope: CoroutineScope = CoroutineScope(Dispatchers.Default)
private val api: Api
internal var connectionManager: ConnectionManager
private var logger: PrismLogger
private var logger: Logger
private val agentOptions: AgentOptions

/**
Expand Down Expand Up @@ -185,7 +185,7 @@ open class EdgeAgent {
connectionManager: ConnectionManager,
seed: Seed?,
api: Api?,
logger: PrismLogger = PrismLoggerImpl(LogComponent.PRISM_AGENT),
logger: Logger = LoggerImpl(LogComponent.EDGE_AGENT),
agentOptions: AgentOptions = AgentOptions()
) {
edgeAgentScope.launch {
Expand Down Expand Up @@ -239,7 +239,7 @@ open class EdgeAgent {
seed: Seed? = null,
api: Api? = null,
mediatorHandler: MediationHandler,
logger: PrismLogger = PrismLoggerImpl(LogComponent.PRISM_AGENT),
logger: Logger = LoggerImpl(LogComponent.EDGE_AGENT),
agentOptions: AgentOptions = AgentOptions()
) {
edgeAgentScope.launch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ private const val METADATA_PRIVACY_STR = "------"
private val hashingLog = UUID.randomUUID().toString()

/**
* PrismLogger is an interface that defines methods for logging messages
* Logger is an interface that defines methods for logging messages
* with different log levels and metadata.
*/
interface PrismLogger {
interface Logger {
/**
* Logs a debug message with optional metadata.
*
Expand Down Expand Up @@ -66,22 +66,24 @@ interface PrismLogger {
* @param error The error to be logged.
* @param metadata An array of metadata objects to be included in the log message. Defaults to an empty array if not provided.
*
* @see PrismLogger.error
* @see Logger.error
* @see Metadata
*/
fun error(error: Error, metadata: Array<Metadata> = arrayOf())
}

/**
* Implementation of the PrismLogger interface.
* Implementation of the Logger interface.
*
* @property category the LogComponent category for this logger
*/
class PrismLoggerImpl(category: LogComponent) : PrismLogger {
class LoggerImpl(private val category: LogComponent) :
Logger {

private val log = logging("[io.prism.kmm.sdk.$category]")
private val log = logging(
"[${category::class.qualifiedName}.$category]"

private var logLevel: LogLevel = LogLevel.INFO
)

/**
* Logs a debug message with optional metadata.
Expand All @@ -90,7 +92,7 @@ class PrismLoggerImpl(category: LogComponent) : PrismLogger {
* @param metadata An array of metadata objects associated with the message (optional).
*/
override fun debug(message: String, metadata: Array<Metadata>) {
if (logLevel != LogLevel.NONE) {
if (category.logLevel != LogLevel.NONE) {
log.debug { message }
if (metadata.isNotEmpty()) {
log.debug { "Metadata: ${arrayToString(metadata)}" }
Expand All @@ -105,7 +107,7 @@ class PrismLoggerImpl(category: LogComponent) : PrismLogger {
* @param metadata An array of metadata objects to be associated with the information message.
*/
override fun info(message: String, metadata: Array<Metadata>) {
if (logLevel != LogLevel.NONE) {
if (category.logLevel != LogLevel.NONE) {
log.info { message }
if (metadata.isNotEmpty()) {
log.info { "Metadata: ${arrayToString(metadata)}" }
Expand All @@ -120,7 +122,7 @@ class PrismLoggerImpl(category: LogComponent) : PrismLogger {
* @param metadata An array of metadata objects associated with the warning message.
*/
override fun warning(message: String, metadata: Array<Metadata>) {
if (logLevel != LogLevel.NONE) {
if (category.logLevel != LogLevel.NONE) {
log.warn { message }
if (metadata.isNotEmpty()) {
log.warn { "Metadata: ${arrayToString(metadata)}" }
Expand All @@ -135,7 +137,7 @@ class PrismLoggerImpl(category: LogComponent) : PrismLogger {
* @param metadata An array of metadata objects to be associated with the error message (optional).
*/
override fun error(message: String, metadata: Array<Metadata>) {
if (logLevel != LogLevel.NONE) {
if (category.logLevel != LogLevel.NONE) {
log.error { message }
if (metadata.isNotEmpty()) {
log.error { "Metadata: ${arrayToString(metadata)}" }
Expand All @@ -150,7 +152,7 @@ class PrismLoggerImpl(category: LogComponent) : PrismLogger {
* @param metadata An array of metadata objects associated with the error (optional).
*/
override fun error(error: Error, metadata: Array<Metadata>) {
if (logLevel != LogLevel.NONE) {
if (category.logLevel != LogLevel.NONE) {
log.error { error.message }
if (metadata.isNotEmpty()) {
log.error { "Metadata: ${arrayToString(metadata)}" }
Expand All @@ -165,7 +167,7 @@ class PrismLoggerImpl(category: LogComponent) : PrismLogger {
* @return The converted String representation of the Metadata objects, with each object's value separated by a new line.
*/
private fun arrayToString(array: Array<Metadata>): String {
return array.joinToString { "${it.getValue(logLevel)}\n" }
return array.joinToString { "${it.getValue(category.logLevel)}\n" }
}
}

Expand Down Expand Up @@ -333,13 +335,13 @@ enum class LogLevel(val value: Int) {
* - MERCURY
* - PLUTO
* - POLLUX
* - PRISM_AGENT
* - EDGE_AGENT
*/
enum class LogComponent {
APOLLO,
CASTOR,
MERCURY,
PLUTO,
POLLUX,
PRISM_AGENT
enum class LogComponent(var logLevel: LogLevel) {
APOLLO(LogLevel.DEBUG),
CASTOR(LogLevel.DEBUG),
MERCURY(LogLevel.DEBUG),
PLUTO(LogLevel.DEBUG),
POLLUX(LogLevel.DEBUG),
EDGE_AGENT(LogLevel.DEBUG)
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ import org.hyperledger.identus.walletsdk.domain.models.MercuryError
import org.hyperledger.identus.walletsdk.domain.models.Message
import org.hyperledger.identus.walletsdk.logger.LogComponent
import org.hyperledger.identus.walletsdk.logger.LogLevel
import org.hyperledger.identus.walletsdk.logger.Logger
import org.hyperledger.identus.walletsdk.logger.LoggerImpl
import org.hyperledger.identus.walletsdk.logger.Metadata
import org.hyperledger.identus.walletsdk.logger.PrismLogger
import org.hyperledger.identus.walletsdk.logger.PrismLoggerImpl
import org.hyperledger.identus.walletsdk.mercury.forward.ForwardMessage

/**
Expand Down Expand Up @@ -55,7 +55,7 @@ constructor(
private val castor: Castor,
private val protocol: DIDCommProtocol,
private val api: Api,
private val logger: PrismLogger = PrismLoggerImpl(LogComponent.MERCURY)
private val logger: Logger = LoggerImpl(LogComponent.MERCURY)
) : Mercury {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,15 @@ import org.hyperledger.identus.walletsdk.domain.models.MercuryError
import org.hyperledger.identus.walletsdk.domain.models.Message
import org.hyperledger.identus.walletsdk.logger.LogComponent
import org.hyperledger.identus.walletsdk.logger.LogLevel
import org.hyperledger.identus.walletsdk.logger.LoggerImpl
import org.hyperledger.identus.walletsdk.logger.Metadata
import org.hyperledger.identus.walletsdk.logger.PrismLoggerImpl
import org.hyperledger.identus.walletsdk.mercury.ATTACHMENT_SEPARATOR
import org.hyperledger.identus.walletsdk.mercury.BASE64
import org.hyperledger.identus.walletsdk.mercury.DIDCommProtocol
import org.hyperledger.identus.walletsdk.mercury.HASH
import org.hyperledger.identus.walletsdk.mercury.JSON
import org.hyperledger.identus.walletsdk.mercury.LINKS
import java.time.Instant.now
import kotlin.jvm.Throws

/**
* Wrapper class for the DIDComm functionality.
Expand All @@ -57,7 +56,7 @@ class DIDCommWrapper(castor: Castor, pluto: Pluto, apollo: Apollo) : DIDCommProt
private val didDocResolver = DIDCommDIDResolver(castor)
private val secretsResolver = DIDCommSecretsResolver(pluto, apollo)
private val didComm = DIDComm(didDocResolver, secretsResolver)
private val logger = PrismLoggerImpl(LogComponent.MERCURY)
private val logger = LoggerImpl(LogComponent.MERCURY)

/**
* Converts a JSON element to a map.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ import org.hyperledger.identus.walletsdk.domain.models.keyManagement.JWK
import org.hyperledger.identus.walletsdk.domain.models.keyManagement.PrivateKey
import org.hyperledger.identus.walletsdk.domain.models.keyManagement.StorableKey
import org.hyperledger.identus.walletsdk.domain.models.keyManagement.StorablePrivateKey
import org.hyperledger.identus.walletsdk.logger.Logger
import org.hyperledger.identus.walletsdk.logger.LoggerImpl
import org.hyperledger.identus.walletsdk.logger.LogComponent
import org.hyperledger.identus.walletsdk.pluto.models.backup.BackupV0_0_1
import org.hyperledger.identus.walletsdk.pluto.data.DbConnection
import org.hyperledger.identus.walletsdk.pluto.data.isConnected
Expand All @@ -55,7 +58,10 @@ import org.hyperledger.identus.walletsdk.pluto.data.StorableCredential as Storab
* @property db The instance of `SdkPlutoDb` representing the connection to the database.
* @property isConnected A flag to indicate whether the database connection is established or not.
*/
class PlutoImpl(private val connection: DbConnection) : Pluto {
class PlutoImpl(
private val connection: DbConnection,
private val logger: Logger = LoggerImpl(LogComponent.PLUTO)
) : Pluto {
private var db: SdkPlutoDb? = null

init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ import org.hyperledger.identus.walletsdk.edgeagent.protocols.proofOfPresentation
import org.hyperledger.identus.walletsdk.edgeagent.protocols.proofOfPresentation.PresentationSubmissionOptions
import org.hyperledger.identus.walletsdk.edgeagent.protocols.proofOfPresentation.PresentationSubmissionOptionsAnoncreds
import org.hyperledger.identus.walletsdk.edgeagent.protocols.proofOfPresentation.PresentationSubmissionOptionsJWT
import org.hyperledger.identus.walletsdk.logger.Logger
import org.hyperledger.identus.walletsdk.logger.LoggerImpl
import org.hyperledger.identus.walletsdk.logger.LogComponent
import org.hyperledger.identus.walletsdk.pluto.RestorationID
import org.hyperledger.identus.walletsdk.pollux.models.AnonCredential
import org.hyperledger.identus.walletsdk.pollux.models.AnoncredsPresentationDefinitionRequest
Expand All @@ -117,7 +120,8 @@ import org.hyperledger.identus.walletsdk.pollux.utils.BitString
open class PolluxImpl(
val apollo: Apollo,
val castor: Castor,
private val api: Api = ApiImpl(httpClient())
private val api: Api = ApiImpl(httpClient()),
private val logger: Logger = LoggerImpl(LogComponent.POLLUX)
) : Pollux {

/**
Expand Down
Loading

0 comments on commit 78e72c6

Please sign in to comment.