Skip to content

Commit 0e89e6c

Browse files
authored
fix: credential values encoding (#1157)
Signed-off-by: Łukasz Przytuła <lprzytula@gmail.com>
1 parent c752461 commit 0e89e6c

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

packages/core/src/modules/credentials/formats/indy/IndyCredentialUtils.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,13 @@ export class IndyCredentialUtils {
156156
}
157157

158158
// If value is an int32 number string return as number string
159-
if (isString(value) && !isEmpty(value) && !isNaN(Number(value)) && this.isInt32(Number(value))) {
159+
if (
160+
isString(value) &&
161+
!isEmpty(value) &&
162+
!isNaN(Number(value)) &&
163+
this.isNumeric(value) &&
164+
this.isInt32(Number(value))
165+
) {
160166
return Number(value).toString()
161167
}
162168

@@ -194,4 +200,8 @@ export class IndyCredentialUtils {
194200
// Check if number is integer and in range of int32
195201
return Number.isInteger(number) && number >= minI32 && number <= maxI32
196202
}
203+
204+
private static isNumeric(value: string) {
205+
return /^-?\d+$/.test(value)
206+
}
197207
}

packages/core/src/modules/credentials/formats/indy/__tests__/IndyCredentialUtils.test.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,14 @@ const testEncodings: { [key: string]: { raw: string | number | boolean | null; e
7474
raw: '0.1',
7575
encoded: '9382477430624249591204401974786823110077201914483282671737639310288175260432',
7676
},
77+
'str 1.0': {
78+
raw: '1.0',
79+
encoded: '94532235908853478633102631881008651863941875830027892478278578250784387892726',
80+
},
81+
'str 1': {
82+
raw: '1',
83+
encoded: '1',
84+
},
7785
'leading zero number string': {
7886
raw: '012345',
7987
encoded: '12345',

0 commit comments

Comments
 (0)