Skip to content

Commit

Permalink
fix: condition for leading zero
Browse files Browse the repository at this point in the history
Signed-off-by: Sai Ranjit Tummalapalli <[email protected]>
  • Loading branch information
sairanjit committed Apr 21, 2024
1 parent e280794 commit 29061e7
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 8 deletions.
4 changes: 2 additions & 2 deletions packages/anoncreds/src/utils/__tests__/credential.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const testEncodings: { [key: string]: { raw: string | number | boolean | null; e
},
'leading zero number string': {
raw: '012345',
encoded: '012345',
encoded: '15442803653501515687133735982599955909858317553820932727345025407787217899333',
},
'chr 0': {
raw: String.fromCharCode(0),
Expand Down Expand Up @@ -132,7 +132,7 @@ describe('Utils | Credentials', () => {
encoded: '68086943237164982734333428280784300550565381723532936263016368251445461241953',
},
age: { raw: '1234', encoded: '1234' },
id: { raw: '0678', encoded: '0678' },
id: { raw: '0678', encoded: '77028439388269848458807170800403172154093562860161099407497319717275846030012' },
})
})
})
Expand Down
6 changes: 0 additions & 6 deletions packages/anoncreds/src/utils/credential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ const isString = (value: unknown): value is string => typeof value === 'string'
const isNumber = (value: unknown): value is number => typeof value === 'number'
const isBoolean = (value: unknown): value is boolean => typeof value === 'boolean'
const isNumeric = (value: string) => /^-?\d+$/.test(value)
const isDecimal = (value: string): boolean => /\d+\.\d+/.test(value)
const hasLeadingZero = (value: string) => value.length > 1 && value.startsWith('0')

const isInt32 = (number: number) => {
Expand Down Expand Up @@ -51,11 +50,6 @@ export function encodeCredentialValue(value: unknown) {
return value.toString()
}

// If value is a number string with leading zero and not a decimal return as number string
if (isString(value) && !isNaN(Number(value)) && !isDecimal(value) && hasLeadingZero(value)) {
return value.toString()
}

// If value is an int32 number string return as number string
if (
isString(value) &&
Expand Down

0 comments on commit 29061e7

Please sign in to comment.