• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

input-output-hk / atala-prism-building-blocks / 5276703626

15 Jun 2023 08:44AM UTC coverage: 27.25% (+0.05%) from 27.196%
5276703626

Pull #542

patlo-iog
docs: update default DEV_MODE doc
Pull Request #542: Atl 4173 secret management documentation

2419 of 8877 relevant lines covered (27.25%)

0.27 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

44.0
/prism-agent/service/wallet-api/src/main/scala/io/iohk/atala/agent/walletapi/util/SeedResolver.scala
1
package io.iohk.atala.agent.walletapi.util
2

3
import zio.*
4
import io.iohk.atala.shared.models.HexString
5
import io.iohk.atala.agent.walletapi.crypto.Apollo
6

7
trait SeedResolver {
8
  def resolve: Task[Array[Byte]]
9
}
10

11
object SeedResolver {
1✔
12
  def layer(seedOverrideHex: Option[String] = None): URLayer[Apollo, SeedResolver] =
1✔
13
    ZLayer.fromFunction(SeedResolverImpl(_, seedOverrideHex))
14
}
15

16
private class SeedResolverImpl(apollo: Apollo, seedOverrideHex: Option[String]) extends SeedResolver {
1✔
17
  override def resolve: Task[Array[Byte]] = {
18
    val seedOverride =
1✔
19
      for {
1✔
20
        _ <- ZIO.logInfo("Resolving a wallet seed using seed-override")
1✔
21
        maybeSeed <- seedOverrideHex
×
22
          .fold(ZIO.none) { hex =>
×
23
            ZIO.fromTry(HexString.fromString(hex)).map(_.toByteArray).asSome
24
          }
×
25
          .tapError(e => ZIO.logError("Failed to parse seed-override"))
×
26
        _ <- ZIO.logInfo("seed-override is not found. Fallback to the next resolver").when(maybeSeed.isEmpty)
27
      } yield maybeSeed
28

29
    val seedEnv =
1✔
30
      for {
×
31
        _ <- ZIO.logInfo("Resolving a wallet seed using WALLET_SEED environemnt variable")
×
32
        maybeSeed <- System
33
          .env("WALLET_SEED")
34
          .flatMap {
×
35
            case Some(hex) => ZIO.fromTry(HexString.fromString(hex)).map(_.toByteArray).asSome
×
36
            case None      => ZIO.none
37
          }
×
38
          .tapError(e => ZIO.logError("Failed to parse WALLET_SEED"))
×
39
        _ <- ZIO.logInfo("WALLET_SEED environment is not found. Fallback to the next resolver").when(maybeSeed.isEmpty)
40
      } yield maybeSeed
41

42
    val seedRand =
1✔
43
      for {
×
44
        _ <- ZIO.logInfo("Generating a new wallet seed")
1✔
45
        seed <- apollo.ecKeyFactory.randomBip32Seed()
46
      } yield seed
47

×
48
    seedOverride
49
      .flatMap {
×
50
        case Some(seed) => ZIO.some(seed)
×
51
        case None       => seedEnv
52
      }
53
      .flatMap {
1✔
54
        case Some(seed) => ZIO.succeed(seed)
1✔
55
        case None       => seedRand
56
      }
57
  }
58
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc