From 820bd0ef7d2f1b4d4793a8bfb4d8293a247aba5e Mon Sep 17 00:00:00 2001 From: Derek Trider Date: Wed, 30 Aug 2023 18:40:10 -0400 Subject: [PATCH] feat(sdk): Change masking character to a bullet Also made some improvements to the Resolve Display docs. Signed-off-by: Derek Trider --- .../display/displaydata_test.go | 4 ++-- .../display/resolve_test.go | 4 ++-- cmd/wallet-sdk-gomobile/docs/usage.md | 23 +++++++------------ pkg/credentialschema/credentialdisplay.go | 2 +- pkg/credentialschema/credentialschema_test.go | 8 +++---- .../expecteddisplaydata/bank_issuer.json | 4 ++-- 6 files changed, 19 insertions(+), 26 deletions(-) diff --git a/cmd/wallet-sdk-gomobile/display/displaydata_test.go b/cmd/wallet-sdk-gomobile/display/displaydata_test.go index ab41c0d5..dfc0ad83 100644 --- a/cmd/wallet-sdk-gomobile/display/displaydata_test.go +++ b/cmd/wallet-sdk-gomobile/display/displaydata_test.go @@ -25,9 +25,9 @@ const ( `{"raw_id":"given_name","label":"Given Name","value_type":"string","order":1,"raw_value":"Alice","locale":"en-US"},` + `{"raw_id":"surname","label":"Surname","value_type":"string","order":2,"raw_value":"Bowman","locale":"en-US"},` + `{"raw_id":"gpa","label":"GPA","value_type":"number","raw_value":"4.0","locale":"en-US"},` + - `{"raw_id":"sensitive_id","label":"Sensitive ID","value_type":"string","value":"*****6789",` + + `{"raw_id":"sensitive_id","label":"Sensitive ID","value_type":"string","value":"•••••6789",` + `"raw_value":"123456789","mask":"regex(^(.*).{4}$)","locale":"en-US"},` + - `{"raw_id":"really_sensitive_id","label":"Really Sensitive ID","value_type":"string","value":"*******",` + + `{"raw_id":"really_sensitive_id","label":"Really Sensitive ID","value_type":"string","value":"•••••••",` + `"raw_value":"abcdefg","mask":"regex((.*))","locale":"en-US"}` + `]}` diff --git a/cmd/wallet-sdk-gomobile/display/resolve_test.go b/cmd/wallet-sdk-gomobile/display/resolve_test.go index 8aca9daa..6a4490df 100644 --- a/cmd/wallet-sdk-gomobile/display/resolve_test.go +++ b/cmd/wallet-sdk-gomobile/display/resolve_test.go @@ -225,7 +225,7 @@ func checkClaims(t *testing.T, credentialDisplay *display.CredentialDisplay) { / RawID: "sensitive_id", Label: "Sensitive ID", ValueType: "string", - Value: "*****6789", + Value: "•••••6789", RawValue: "123456789", Locale: "en-US", IsMasked: true, @@ -234,7 +234,7 @@ func checkClaims(t *testing.T, credentialDisplay *display.CredentialDisplay) { / RawID: "really_sensitive_id", Label: "Really Sensitive ID", ValueType: "string", - Value: "*******", + Value: "•••••••", RawValue: "abcdefg", Locale: "en-US", IsMasked: true, diff --git a/cmd/wallet-sdk-gomobile/docs/usage.md b/cmd/wallet-sdk-gomobile/docs/usage.md index 347646a9..d734813a 100644 --- a/cmd/wallet-sdk-gomobile/docs/usage.md +++ b/cmd/wallet-sdk-gomobile/docs/usage.md @@ -1108,9 +1108,11 @@ from the issuer. See [Resolve Display](#resolve-display) for more information. Display data objects can be serialized using the `serialize()` method (useful for storage) and parsed from serialized form back into display data objects using the `parseDisplayData()` function. +### The Display Object Structure + The structure of the display data object is as follows: -### `Data` +#### `Data` * The root object. * Contains display information for the issuer and each of the credentials passed in to the `resolveDisplay` @@ -1120,31 +1122,31 @@ function. * Use the `credentialDisplaysLength()` and `credentialDisplayAtIndex()` methods to iterate over the `CredentialDisplay` objects. There's one for each credential passed in to the `resolveDisplay` function, and they're in the same order. -### `IssuerDisplay` +#### `IssuerDisplay` * Describes display information about the issuer. * Can be serialized using the `serialize()` method and parsed using the `parseIssuerDisplay()` function. * Has `name()` and `locale()` methods. -### `CredentialDisplay` +#### `CredentialDisplay` * Describes display information about a credential. * Can be serialized using the `serialize()` method and parsed using the `parseCredentialDisplay()` function. * The `overview()` method returns the `CredentialOverview` object. * Use the `claimsLength()` and `claimAtIndex()` methods to iterate over the `Claim` objects. -### `CredentialOverview` +#### `CredentialOverview` * Describes display information for a credential as a whole. * Has `name()`, `logo()`, `backgroundColor()`, `textColor()`, and `locale()` methods. The `logo()` method returns a `Logo` object. -### `Logo` +#### `Logo` * Describes display information for a logo. * Has `url()` and `altText()` methods. -### `Claim` +#### `Claim` * Describes display information for a specific claim within a credential. * Has `label()`, `rawID()`, `valueType()`, `value()`, `rawValue()`, `isMasked()`, `hasOrder()`, `order()`, @@ -1165,20 +1167,11 @@ It's not localized or formatted for display. * `valueType()` returns the value type for this claim - when it's "image", then you should expect the value data to be formatted using the [data URL scheme](https://www.rfc-editor.org/rfc/rfc2397). -### A Note about `locale()` - -The locale returned by the various `locale()` methods may not be the same as the preferred locale you passed into the -`ResolveDisplay` function under certain circumstances. For instance, if the locale you passed in wasn't available, -then a default locale may get used instead. - ### Resolve Display Examples The following examples show how the `ResolveDisplay` function can be used. The function requires you to pass in one or more VCs and the issuer URI. -A preferred locale and/or additional headers to be sent to the issuer can be specified by creating an `Opts` -object, setting your desired parameters using the supplied methods, and passing the object in. - #### Kotlin (Android) ##### Using Default Options diff --git a/pkg/credentialschema/credentialdisplay.go b/pkg/credentialschema/credentialdisplay.go index 2d2f469f..ad7f27c5 100644 --- a/pkg/credentialschema/credentialdisplay.go +++ b/pkg/credentialschema/credentialdisplay.go @@ -217,7 +217,7 @@ func getMaskedValue(rawValue, maskingPattern string) (string, error) { // Always use the first submatch. valueToBeMasked := r.ReplaceAllString(rawValue, "$1") - maskedValue := strings.ReplaceAll(rawValue, valueToBeMasked, strings.Repeat("*", len(valueToBeMasked))) + maskedValue := strings.ReplaceAll(rawValue, valueToBeMasked, strings.Repeat("•", len(valueToBeMasked))) return maskedValue, nil } diff --git a/pkg/credentialschema/credentialschema_test.go b/pkg/credentialschema/credentialschema_test.go index 36356d37..94b9f2e6 100644 --- a/pkg/credentialschema/credentialschema_test.go +++ b/pkg/credentialschema/credentialschema_test.go @@ -214,11 +214,11 @@ func TestResolve(t *testing.T) { {RawID: "gpa", Label: "GPA", RawValue: "4.0", ValueType: "number", Locale: "en-US"}, { RawID: "sensitive_id", Label: "Sensitive ID", RawValue: "123456789", - Value: "*****6789", ValueType: "string", Mask: "regex(^(.*).{4}$)", Locale: "en-US", + Value: "•••••6789", ValueType: "string", Mask: "regex(^(.*).{4}$)", Locale: "en-US", }, { RawID: "really_sensitive_id", Label: "Really Sensitive ID", RawValue: "abcdefg", - Value: "*******", ValueType: "string", Mask: "regex((.*))", Locale: "en-US", + Value: "•••••••", ValueType: "string", Mask: "regex((.*))", Locale: "en-US", }, { RawID: "chemistry", Label: "Chemistry Final Grade", RawValue: "78", @@ -432,11 +432,11 @@ func checkSuccessCaseMatchedDisplayData(t *testing.T, resolvedDisplayData *crede }, {RawID: "gpa", Label: "GPA", RawValue: "4.0", ValueType: "number", Locale: "en-US"}, { - RawID: "sensitive_id", Label: "Sensitive ID", RawValue: "123456789", Value: "*****6789", + RawID: "sensitive_id", Label: "Sensitive ID", RawValue: "123456789", Value: "•••••6789", ValueType: "string", Mask: "regex(^(.*).{4}$)", Locale: "en-US", }, { - RawID: "really_sensitive_id", Label: "Really Sensitive ID", RawValue: "abcdefg", Value: "*******", + RawID: "really_sensitive_id", Label: "Really Sensitive ID", RawValue: "abcdefg", Value: "•••••••", ValueType: "string", Mask: "regex((.*))", Locale: "en-US", }, { diff --git a/test/integration/expecteddisplaydata/bank_issuer.json b/test/integration/expecteddisplaydata/bank_issuer.json index 988003e7..85715eca 100644 --- a/test/integration/expecteddisplaydata/bank_issuer.json +++ b/test/integration/expecteddisplaydata/bank_issuer.json @@ -71,7 +71,7 @@ "raw_id": "sensitiveID", "label":"Sensitive ID", "value_type": "string", - "value":"*****6789", + "value":"•••••6789", "raw_value":"123456789", "mask":"regex(^(.*).{4}$)", "locale":"en-US" @@ -80,7 +80,7 @@ "raw_id": "reallySensitiveID", "label":"Really Sensitive ID", "value_type": "string", - "value":"*******", + "value":"•••••••", "raw_value":"abcdefg", "mask":"regex((.*))", "locale":"en-US"