TBD54566975 / web5-go

Apache License 2.0
6 stars 6 forks source link

`pexv2.SelectCredentials` sometimes fails to parse Input Descriptors #153

Closed tomdaffurn closed 3 days ago

tomdaffurn commented 4 days ago

When calling pexv2.SelectCredentials with 1 Input Descriptor that has multiple Fields, the function sometimes fails with a JSON schema error.

The cause is code that copies Input Descriptors to a JSONSchema object. As part of that, tokens are generated to uniquely identify each field. Sometimes the tokens are not unique because a system nano time is used for the token value.

Suggest we use a random number of hash instead of nano time.

Problem code:

token := strconv.FormatInt(time.Now().UnixNano(), 10)

Possible fix:

token := strconv.FormatInt(rand.Int63(), 10)

Error:

failed to satisfy input descriptor constraints 1: error compiling schema: jsonschema file:///<redacted>/credential/1 compilation failed: '/required' does not validate with http://json-schema.org/draft-07/schema#/properties/required/$ref/uniqueItems: items at index 0 and 1 are equal