Skip to content

Commit 9033163

Browse files
add metadata back
1 parent 6dedd02 commit 9033163

14 files changed

Lines changed: 91 additions & 11 deletions

File tree

waltid-applications/waltid-wallet-demo-compose/sharedLogic/src/commonMain/kotlin/id/walt/walletdemo/compose/logic/WalletDemoCredential.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ data class CredentialSummary(
88
val label: String,
99
val addedAt: String? = null,
1010
val credentialDataJson: String? = null,
11+
val metadataJson: String? = null,
1112
)
1213

1314
typealias WalletDemoCredential = CredentialSummary

waltid-applications/waltid-wallet-demo-compose/sharedLogic/src/mobileMain/kotlin/id/walt/walletdemo/compose/logic/MobileDemoWallet.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ internal class MobileDemoWallet(
4040
label = credential.label ?: credential.format,
4141
addedAt = credential.addedAt,
4242
credentialDataJson = credential.credentialDataJson,
43+
metadataJson = credential.metadataJson,
4344
)
4445
}
4546

waltid-applications/waltid-wallet-demo-ios/iosApp/iosApp/Display/CredentialDisplayModels.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,27 @@ struct CredentialDetails: Equatable, Identifiable {
99
let format: String
1010
let addedAt: Date?
1111
let groups: [ClaimGroup]
12+
let metadataJSON: String?
13+
14+
init(
15+
id: String,
16+
title: String,
17+
issuer: String?,
18+
subject: String?,
19+
format: String,
20+
addedAt: Date?,
21+
groups: [ClaimGroup],
22+
metadataJSON: String? = nil
23+
) {
24+
self.id = id
25+
self.title = title
26+
self.issuer = issuer
27+
self.subject = subject
28+
self.format = format
29+
self.addedAt = addedAt
30+
self.groups = groups
31+
self.metadataJSON = metadataJSON
32+
}
1233
}
1334

1435
struct ClaimGroup: Equatable, Identifiable {

waltid-applications/waltid-wallet-demo-ios/iosApp/iosApp/Display/CredentialDisplayNormalizer.swift

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import WalletSDK
44
enum CredentialDisplayNormalizer {
55

66
static func details(for credential: Credential) -> CredentialDetails {
7-
details(
7+
var result = details(
88
id: credential.id,
99
title: credential.label ?? credential.format,
1010
issuer: credential.issuer,
@@ -13,6 +13,16 @@ enum CredentialDisplayNormalizer {
1313
addedAt: credential.addedAt,
1414
credentialDataJSON: credential.credentialDataJSON
1515
)
16+
return CredentialDetails(
17+
id: result.id,
18+
title: result.title,
19+
issuer: result.issuer,
20+
subject: result.subject,
21+
format: result.format,
22+
addedAt: result.addedAt,
23+
groups: result.groups,
24+
metadataJSON: nil
25+
)
1626
}
1727

1828
static func details(for option: PresentationCredentialOption) -> CredentialDetails {

waltid-libraries/protocols/waltid-openid4vc-wallet-mobile/src/commonMain/kotlin/id/walt/wallet2/mobile/MobileWallet.kt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public data class MobileWalletBootstrapResult(
6666
* @property label Optional display label stored with the credential.
6767
* @property addedAt ISO-8601 timestamp string for when the credential was added, when known.
6868
* @property credentialDataJson Parsed credential data encoded as JSON for app-side display.
69+
* @property metadataJson Optional arbitrary metadata stored alongside the credential as JSON.
6970
*/
7071
public data class MobileWalletCredential(
7172
public val id: String,
@@ -75,6 +76,7 @@ public data class MobileWalletCredential(
7576
public val label: String?,
7677
public val addedAt: String?,
7778
public val credentialDataJson: String,
79+
public val metadataJson: String? = null,
7880
)
7981

8082
/**
@@ -292,6 +294,7 @@ public class MobileWallet internal constructor(
292294
label = meta.label,
293295
addedAt = meta.addedAt?.toString(),
294296
credentialDataJson = credential.credential.credentialData.encodeJsonObject(),
297+
metadataJson = credential.metadata?.let { Json.encodeToString(JsonObject.serializer(), it) },
295298
)
296299
}
297300

waltid-libraries/protocols/waltid-openid4vc-wallet-mobile/src/iosMain/kotlin/id/walt/wallet2/mobile/swiftinterop/WalletSdkBridgeModels.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,15 @@ public interface WalletBridgeDatabaseEncryptionKeyProvider {
133133
* @property format Credential format, for example `vc+sd-jwt` or `jwt_vc_json`.
134134
* @property label Optional user-facing credential label.
135135
* @property addedAt Optional ISO-8601 timestamp for when the credential was added.
136+
* @property metadataJson Optional arbitrary metadata as a JSON string.
136137
*/
137138
public data class WalletBridgeStoredCredential(
138139
public val id: String,
139140
public val serializedCredential: String,
140141
public val format: String,
141142
public val label: String? = null,
142143
public val addedAt: String? = null,
144+
public val metadataJson: String? = null,
143145
)
144146

145147
/**
@@ -398,6 +400,7 @@ private suspend fun WalletBridgeStoredCredential.toStoredCredential(): StoredCre
398400
credential = credential,
399401
label = label,
400402
addedAt = addedAt?.let(Instant::parse),
403+
metadata = metadataJson?.let { Json.decodeFromString(JsonObject.serializer(), it) },
401404
)
402405
}
403406

@@ -407,6 +410,7 @@ private fun StoredCredential.toBridgeStoredCredential() = WalletBridgeStoredCred
407410
format = credential.format,
408411
label = label,
409412
addedAt = addedAt?.toString(),
413+
metadataJson = metadata?.let { Json.encodeToString(JsonObject.serializer(), it) },
410414
)
411415

412416
private fun DigitalCredential.serializedForBridgeStorage(): String =

waltid-libraries/protocols/waltid-openid4vc-wallet-persistence-mobile/src/commonMain/kotlin/id/walt/wallet2/persistence/stores/SqlDelightCredentialStore.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,13 @@ import id.walt.wallet2.data.StoredCredential
99
import id.walt.wallet2.data.WalletCredentialStore
1010
import kotlinx.coroutines.flow.Flow
1111
import kotlinx.coroutines.flow.flow
12+
import kotlinx.serialization.json.Json
13+
import kotlinx.serialization.json.JsonObject
1214
import kotlin.time.Clock
1315
import kotlin.time.Instant
1416

17+
private val json = Json { ignoreUnknownKeys = true }
18+
1519
/**
1620
* SQLDelight-backed implementation of [WalletCredentialStore] for mobile wallets.
1721
*
@@ -49,6 +53,7 @@ public class SqlDelightCredentialStore(
4953
format = entry.credential.format,
5054
label = entry.label,
5155
added_at = entry.addedAt?.toEpochMilliseconds() ?: Clock.System.now().toEpochMilliseconds(),
56+
metadata = entry.metadata?.let { json.encodeToString(JsonObject.serializer(), it) },
5257
)
5358
}
5459

@@ -68,6 +73,7 @@ public class SqlDelightCredentialStore(
6873
credential = credential,
6974
label = label,
7075
addedAt = Instant.fromEpochMilliseconds(added_at),
76+
metadata = metadata?.let { json.decodeFromString(JsonObject.serializer(), it) },
7177
)
7278
}
7379
}

waltid-libraries/protocols/waltid-openid4vc-wallet-persistence-mobile/src/commonMain/sqldelight/id/walt/wallet2/persistence/db/WalletPersistence.sq

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ CREATE TABLE credentials (
2626
serialized_credential TEXT NOT NULL,
2727
format TEXT NOT NULL DEFAULT '',
2828
label TEXT,
29-
added_at INTEGER NOT NULL
29+
added_at INTEGER NOT NULL,
30+
metadata TEXT
3031
);
3132

3233
selectAllCredentials:
@@ -36,8 +37,8 @@ selectCredentialById:
3637
SELECT * FROM credentials WHERE id = ?;
3738

3839
insertCredential:
39-
INSERT OR REPLACE INTO credentials (id, serialized_credential, format, label, added_at)
40-
VALUES (?, ?, ?, ?, ?);
40+
INSERT OR REPLACE INTO credentials (id, serialized_credential, format, label, added_at, metadata)
41+
VALUES (?, ?, ?, ?, ?, ?);
4142

4243
deleteCredentialById:
4344
DELETE FROM credentials WHERE id = ?;

waltid-libraries/protocols/waltid-openid4vc-wallet-persistence-server/src/main/kotlin/id/walt/wallet2/persistence/ExposedCredentialStore.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import id.walt.wallet2.data.WalletCredentialStore
66
import kotlinx.coroutines.flow.Flow
77
import kotlinx.coroutines.flow.asFlow
88
import kotlinx.serialization.json.Json
9+
import kotlinx.serialization.json.JsonObject
910
import org.jetbrains.exposed.v1.core.ResultRow
1011
import org.jetbrains.exposed.v1.core.and
1112
import org.jetbrains.exposed.v1.core.eq
@@ -56,6 +57,8 @@ class ExposedCredentialStore(
5657
it[Wallet2Tables.Credentials.label] = entry.label
5758
it[Wallet2Tables.Credentials.addedAt] =
5859
(entry.addedAt ?: Clock.System.now()).toJavaInstant()
60+
it[Wallet2Tables.Credentials.metadata] =
61+
entry.metadata?.let { meta -> json.encodeToString(JsonObject.serializer(), meta) }
5962
}
6063
}
6164
}
@@ -76,7 +79,10 @@ class ExposedCredentialStore(
7679
row[Wallet2Tables.Credentials.serializedCredential]
7780
),
7881
label = row[Wallet2Tables.Credentials.label],
79-
addedAt = row[Wallet2Tables.Credentials.addedAt].toKotlinInstant()
82+
addedAt = row[Wallet2Tables.Credentials.addedAt].toKotlinInstant(),
83+
metadata = row[Wallet2Tables.Credentials.metadata]?.let {
84+
json.decodeFromString(JsonObject.serializer(), it)
85+
},
8086
)
8187
}.getOrNull()
8288
}

waltid-libraries/protocols/waltid-openid4vc-wallet-persistence-server/src/main/kotlin/id/walt/wallet2/persistence/Wallet2Tables.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ object Wallet2Tables {
9696
val serializedCredential = text("serialized_credential")
9797
val label = varchar("label", 512).nullable()
9898
val addedAt = timestamp("added_at")
99+
val metadata = text("metadata").nullable()
99100
override val primaryKey = PrimaryKey(storeId, id)
100101
}
101102

0 commit comments

Comments
 (0)