DetokenizeIdentityField detokenizes a specific field in an identity. Parameters: - identityID string: The ID of the identity. - fieldName string: The name of the field to detokenize. Returns: - string: The detokenized field value. - error: An error if the field could not be detokenized.
(identityID, fieldName string)
| 215 | // - string: The detokenized field value. |
| 216 | // - error: An error if the field could not be detokenized. |
| 217 | func (l *LedgerForge) DetokenizeIdentityField(identityID, fieldName string) (string, error) { |
| 218 | // Get the identity |
| 219 | identity, err := l.GetIdentity(identityID) |
| 220 | if err != nil { |
| 221 | return "", err |
| 222 | } |
| 223 | |
| 224 | // Try both original and capitalized field name |
| 225 | structFieldName := convertToStructFieldName(fieldName) |
| 226 | |
| 227 | // Check if field is tokenized |
| 228 | if !identity.IsFieldTokenized(fieldName) && !identity.IsFieldTokenized(structFieldName) { |
| 229 | // Debug info |
| 230 | if identity.MetaData != nil { |
| 231 | metaStr, _ := json.Marshal(identity.MetaData) |
| 232 | return "", fmt.Errorf("field %s is not tokenized. Metadata: %s", fieldName, metaStr) |
| 233 | } |
| 234 | return "", fmt.Errorf("field %s is not tokenized", fieldName) |
| 235 | } |
| 236 | |
| 237 | // Get the field value using reflection - try both field name versions |
| 238 | val := reflect.ValueOf(identity).Elem() |
| 239 | fieldVal := val.FieldByName(structFieldName) |
| 240 | |
| 241 | if !fieldVal.IsValid() { |
| 242 | fieldVal = val.FieldByName(fieldName) |
| 243 | if !fieldVal.IsValid() { |
| 244 | return "", fmt.Errorf("field %s not found", fieldName) |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | // Get the tokenized value |
| 249 | tokenVal := fieldVal.String() |
| 250 | |
| 251 | // Detokenize the value |
| 252 | originalValue, err := l.tokenizer.Detokenize(tokenVal) |
| 253 | if err != nil { |
| 254 | return "", err |
| 255 | } |
| 256 | |
| 257 | return originalValue, nil |
| 258 | } |
| 259 | |
| 260 | // TokenizeIdentity tokenizes all specified fields in an identity. |
| 261 | // |