Skip to content

Commit

Permalink
fix: credential values encoding (#1157)
Browse files Browse the repository at this point in the history
Signed-off-by: Łukasz Przytuła <[email protected]>
  • Loading branch information
Przytua authored Dec 14, 2022
1 parent c752461 commit 0e89e6c
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,13 @@ export class IndyCredentialUtils {
}

// If value is an int32 number string return as number string
if (isString(value) && !isEmpty(value) && !isNaN(Number(value)) && this.isInt32(Number(value))) {
if (
isString(value) &&
!isEmpty(value) &&
!isNaN(Number(value)) &&
this.isNumeric(value) &&
this.isInt32(Number(value))
) {
return Number(value).toString()
}

Expand Down Expand Up @@ -194,4 +200,8 @@ export class IndyCredentialUtils {
// Check if number is integer and in range of int32
return Number.isInteger(number) && number >= minI32 && number <= maxI32
}

private static isNumeric(value: string) {
return /^-?\d+$/.test(value)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ const testEncodings: { [key: string]: { raw: string | number | boolean | null; e
raw: '0.1',
encoded: '9382477430624249591204401974786823110077201914483282671737639310288175260432',
},
'str 1.0': {
raw: '1.0',
encoded: '94532235908853478633102631881008651863941875830027892478278578250784387892726',
},
'str 1': {
raw: '1',
encoded: '1',
},
'leading zero number string': {
raw: '012345',
encoded: '12345',
Expand Down

0 comments on commit 0e89e6c

Please sign in to comment.