-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Restrict types supported by functions in the EdDSA Poseidon package #188
Comments
@artwyman After all, 1 reasonable compromise for the private key could be to allow devs to pass: Buffer, Uint8Array and text, i.e. all types that can be easily converted with That should eliminate ambiguity on input length. We could add more doc to explain to devs to convert their inputs if they are bigints or hexadecimals. |
Buffer is a subclass of Uint8Array so I think those two are mostly equivalent. Including string text seems fine, but does raise some ambiguity as to whether the string is being treated directly as byte (probably UTF-8) or some sort of encoded hex or decimal number. |
Yes true, but I think it could be a good trade-off. Let's say the private key will be optional (if users don't pass it it'll be generated randomly), which is a nice feature we should implement. In that case, I think most users will pass text (i.e. passwords) rather than bytes, so might be worth supporting that type as well. |
Tyes supported for the EdDSA private key has been reduced to 3: Buffer, Uint8Array and string, i.e. buffers or text. re #188
Types supported for the EdDSA private key have been reduced to 3: Buffer, Uint8Array and string. re #188
Describe the improvement you're thinking about
Currently, functions such as
deriveSecretScalar
,derivePublicKey
andsignMessage
accept different types of private keys. BigNumberish can be:bigint
,number
,string
, hexadecimal (string) or Buffer. Although supporting and converting many types reduces the dev's effort in certain contexts, it may also lead to ambiguity if a type is not correctly identified. For example, a hexadecimal string without '0x' is identified as plain text or as a bigint (if it contains only digits) depending on its value. And inconsistency remains between the length of an accepted arbitrary text (no limit at the moment) and the value of a bigint or a number, which have different size limits.In general, the right choice for determining how many and which types to support depends on the case. Prioritizing simplicity and accepting only one type (e.g. Buffer) may be the right choice if you want to make your code more efficient and eliminate ambiguity in the interpretation of types. Making the code more flexible and adaptable may be a better choice in the case of prioritizing the user experience.
This is an implementation of an algorithm where performance matters, but at the same time the aim is to give devs an optimal experience. An intermediate solution might be to reduce the number of types to 1 or 2, and provide utilities to convert any values before passing them to library functions.
Additional context
Originated from discussion in #178 (comment).
The text was updated successfully, but these errors were encountered: