qri-io / qri

you're invited to a data party!
https://qri.io
GNU General Public License v3.0
1.11k stars 66 forks source link

refactor(profile): profile.ID.Encode and Validate methods #1858

Closed dustmop closed 3 years ago

dustmop commented 3 years ago

Add methods to profile.ID called Encode and Validate. Encode replaces the old String function, and base58 encodes an ID. The old String function now outputs wrapped hex, to make it clear that profile.IDs have different shape from base58 encoded strings. The Validate method ensures that a profile.ID is not double-encoded. Use this function in collection.Set to prevent callers from breaking their collection by passing invalid IDs.

Fixes #1857

This refactoring was performed by renaming the old profile.ID.String method (to Stringz) then fixing all of the compilation errors this caused. This renaming uncovered that the function CompareDatasetRef was relying on the implicit base58 encoding that fmt.Errorf performs.