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

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

24 Apr 2024 10:47AM UTC coverage: 31.599% (-0.3%) from 31.912%
8815523478

Pull #966

patlo-iog
chore: resolve conflict

Signed-off-by: Pat Losoponkul <pat.losoponkul@iohk.io>
Pull Request #966: feat: key management for Ed25519 and X25519

110 of 386 new or added lines in 22 files covered. (28.5%)

471 existing lines in 130 files now uncovered.

4652 of 14722 relevant lines covered (31.6%)

0.32 hits per line

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

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

3
import io.iohk.atala.agent.walletapi.model.ManagedDIDHdKeyPath
4
import io.iohk.atala.agent.walletapi.model.ManagedDIDKeyMeta
5
import io.iohk.atala.agent.walletapi.model.ManagedDIDRandKeyMeta
6
import io.iohk.atala.agent.walletapi.model.WalletSeed
7
import io.iohk.atala.agent.walletapi.storage.DIDNonSecretStorage
8
import io.iohk.atala.agent.walletapi.storage.DIDSecretStorage
9
import io.iohk.atala.agent.walletapi.storage.WalletSecretStorage
10
import io.iohk.atala.castor.core.model.did.EllipticCurve
11
import io.iohk.atala.castor.core.model.did.PrismDID
12
import io.iohk.atala.shared.crypto.Apollo
13
import io.iohk.atala.shared.crypto.Ed25519KeyPair
14
import io.iohk.atala.shared.crypto.Secp256k1KeyPair
15
import io.iohk.atala.shared.crypto.X25519KeyPair
16
import io.iohk.atala.shared.models.WalletAccessContext
17
import zio.*
18

19
class KeyResolver(
20
    apollo: Apollo,
21
    nonSecretStorage: DIDNonSecretStorage,
22
    secretStorage: DIDSecretStorage,
23
    walletSecretStorage: WalletSecretStorage
24
) {
1✔
25
  def getKey(
26
      did: PrismDID,
27
      keyId: String
NEW
28
  ): RIO[WalletAccessContext, Option[Secp256k1KeyPair | Ed25519KeyPair | X25519KeyPair]] =
×
NEW
29
    nonSecretStorage.getKeyMeta(did, keyId).flatMap {
×
30
      case None                                   => ZIO.none
1✔
NEW
31
      case Some(ManagedDIDKeyMeta.HD(path), oh)   => deriveHdKey(path)
×
32
      case Some(ManagedDIDKeyMeta.Rand(meta), oh) => getRandKey(did, keyId, meta, oh)
33
    }
34

1✔
35
  private def deriveHdKey(path: ManagedDIDHdKeyPath): RIO[WalletAccessContext, Option[Secp256k1KeyPair]] =
1✔
NEW
36
    walletSecretStorage.getWalletSeed.flatMap {
×
37
      case None       => ZIO.none
1✔
38
      case Some(seed) => apollo.secp256k1.deriveKeyPair(seed.toByteArray)(path.derivationPath: _*).asSome
39
    }
UNCOV
40

×
41
  private def getRandKey(
42
      did: PrismDID,
43
      keyId: String,
44
      meta: ManagedDIDRandKeyMeta,
45
      operationHash: Array[Byte]
46
  ): RIO[WalletAccessContext, Option[Ed25519KeyPair | X25519KeyPair]] = {
NEW
47
    meta.curve match {
×
NEW
48
      case EllipticCurve.SECP256K1 =>
×
NEW
49
        ZIO.die(Exception("Reading secp256k1 random key is not yet supported"))
×
NEW
50
      case EllipticCurve.ED25519 =>
×
NEW
51
        secretStorage.getPrismDIDKeyPair[Ed25519KeyPair](did, keyId, operationHash)
×
NEW
52
      case EllipticCurve.X25519 =>
×
53
        secretStorage.getPrismDIDKeyPair[X25519KeyPair](did, keyId, operationHash)
54
    }
55
  }
56
}
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