1
0
Форкнуть 0

Merge pull request #218 from microsoft/niganesh/creating-did-when-absent-during-export

creating did when not present before exporting
This commit is contained in:
nithyaganeshng 2022-08-15 20:58:42 -04:00 коммит произвёл GitHub
Родитель 582ee9405c f4b2ddce9e
Коммит fa982a8e39
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 617 добавлений и 9 удалений

Просмотреть файл

@ -2,6 +2,7 @@
package com.microsoft.did.sdk.backup.content.microsoft2020
import com.microsoft.did.sdk.IdentifierService
import com.microsoft.did.sdk.backup.UnprotectedBackup
import com.microsoft.did.sdk.backup.content.BackupProcessor
import com.microsoft.did.sdk.backup.content.UnprotectedBackupData
@ -14,13 +15,13 @@ import com.microsoft.did.sdk.identifier.models.Identifier
import com.microsoft.did.sdk.util.Constants
import com.microsoft.did.sdk.util.controlflow.BackupException
import com.nimbusds.jose.jwk.JWK
import com.nimbusds.jose.jwk.OctetSequenceKey
import kotlinx.serialization.json.Json
import javax.inject.Inject
import javax.inject.Singleton
@Singleton
class Microsoft2020BackupProcessor @Inject constructor(
private val identifierService: IdentifierService,
private val identityRepository: IdentifierRepository,
private val keyStore: EncryptedKeyStore,
private val rawIdentifierConverter: RawIdentifierConverter,
@ -36,6 +37,9 @@ class Microsoft2020BackupProcessor @Inject constructor(
vcMetaMap[verifiableCredentialMetadataPair.first.jti] = verifiableCredentialMetadataPair.second
}
/* This line creates master DID and its key if there isn't one already which is required for export.
The created key is retrieved from keystore and used as seed in wallet metadata below.*/
identifierService.getMasterIdentifier()
backup.walletMetadata.seed = keyStore.getKey(Constants.MAIN_IDENTIFIER_REFERENCE).toJSONString()
return Microsoft2020UnprotectedBackupData(
vcs = vcMap,

Различия файлов скрыты, потому что одна или несколько строк слишком длинны

Просмотреть файл

@ -3,8 +3,13 @@
package com.microsoft.did.sdk.backup.content.microsoft2020
import android.util.BackupTestUtil
import com.microsoft.did.sdk.IdentifierService
import com.microsoft.did.sdk.identifier.models.Identifier
import com.microsoft.did.sdk.util.controlflow.Result
import com.microsoft.did.sdk.util.defaultTestSerializer
import io.mockk.coEvery
import io.mockk.coVerify
import io.mockk.mockk
import io.mockk.verify
import kotlinx.coroutines.runBlocking
import org.junit.Test
@ -14,8 +19,11 @@ class Microsoft2020UnprotectedBackupProcessorTest {
private val identifierRepository = BackupTestUtil.getMockIdentifierRepository()
private val keyStore = BackupTestUtil.getMockKeyStore()
private val rawIdentifierUtility = RawIdentifierConverter(identifierRepository, keyStore)
private val identifierService: IdentifierService = mockk()
private val masterIdentifier: Identifier = mockk()
private val backupProcessor = Microsoft2020BackupProcessor(
identifierService,
identifierRepository,
keyStore,
rawIdentifierUtility,
@ -33,17 +41,18 @@ class Microsoft2020UnprotectedBackupProcessorTest {
runBlocking {
val rawData = Microsoft2020UnprotectedBackupData(
mapOf(
"test" to BackupTestUtil.testVerifiedCredential.raw,
"test" to BackupTestUtil.testVerifiedCredential.raw
),
mapOf(
"test" to vcMetadata,
"test" to vcMetadata
),
WalletMetadata(),
listOf(
BackupTestUtil.rawIdentifier
)
)
rawData.metaInf.seed = "{\"kty\":\"EC\",\"d\":\"7-RR2JBX1tWCUw17ujvjhYFyB0zwkvM9ttKyBMfQUNM\",\"use\":\"sig\",\"crv\":\"P-256\",\"kid\":\"recover\",\"x\":\"XIpoCl3CxnSUfZXew2Gc1tSwCJBUos1EacEXnQyfjhg\",\"y\":\"YDHaAGK0rL7wZwp2vp4aCaKuzg_tSB-8i4q_u-kLxSw\"}"
rawData.metaInf.seed = "{\"kty\":\"EC\",\"d\":\"7-RR2JBX1tWCUw17ujvjhYFyB0zwkvM9ttKyBMfQUNM\",\"use\":\"sig\",\"crv\":\"P-256\"," +
"\"kid\":\"recover\",\"x\":\"XIpoCl3CxnSUfZXew2Gc1tSwCJBUos1EacEXnQyfjhg\",\"y\":\"YDHaAGK0rL7wZwp2vp4aCaKuzg_tSB-8i4q_u-kLxSw\"}"
val actual = backupProcessor.import(rawData) as Microsoft2020UnprotectedBackup
assertEquals(
backupData.verifiableCredentials,
@ -63,6 +72,7 @@ class Microsoft2020UnprotectedBackupProcessorTest {
@Test
fun `export transforms backup correctly`() {
coEvery { identifierService.getMasterIdentifier() } returns Result.Success(masterIdentifier)
runBlocking {
val actual = backupProcessor.export(backupData) as Microsoft2020UnprotectedBackupData
coVerify {

Просмотреть файл

@ -36,7 +36,6 @@ class JwtValidatorTest {
private val expectedDid: String = "did:test:4235"
private val expectedKid: String = "$expectedDid#kidTest2353"
init {
validator = JwtValidator(mockedResolver)
setUpResolver()

Просмотреть файл

@ -15,7 +15,7 @@ class JwsTokenTest {
private val key: ECKey = ECKeyGenerator(Curve.SECP256K1)
.keyID(keyRef)
.generate()
private val edKeyPair = OctetKeyPairGenerator(Curve.Ed25519).keyID("123").generate()
private val edKeyPair = OctetKeyPairGenerator(Curve.Ed25519).keyID("123").generate()
private val payload: String = "{\"iss\":\"joe\",\n" +
" \"exp\":1300819380,\n" +
" \"http://example.com/is_root\":true}"