-
Notifications
You must be signed in to change notification settings - Fork 400
migrate to @scure/base for base64 & bech32 encoding #1666
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
base: main
Are you sure you want to change the base?
Conversation
CircleCI output
|
Thanks. LFS budget was fixed now. I am happy for the new implementation. But can we do that without changing the types of CosmJS interfaces? Is it possible to use bech32 decoding without knowing the prefix? |
For a backwards compatible 0.33.2 release, existing TypeScript code can't break if it was expecting a The new return type of the decode function and some address-getters doesn't force users to change anything, but it does give them the choice to take advantage of the new type to enforce more compile-time constraints (statically ensuring this string is a valid address) in their codebase. And if you mean, is it possible to use this library's decode function without casting |
I am trying to use @scure/base without changing public interfaces. But hitting some issues. See paulmillr/scure-base#43 |
If no breaking type interface changes ever happen in CosmJS, why are there so many semver-incompatible versions (0.33, 0.34, 0.35), which indicate breaking changes? |
Return types are narrowed in a way that's still backwards-compatible.
ad4a5e0
to
6350748
Compare
There are breaking changes in public APIs every now and then and if they improve the user experience I am happy to do them. But I don't want to make unnecessary changes that require users to rewrite half of their app just to get an overly strict type into functionality that every user is perfectly happy with. |
limit = Infinity, | ||
): { readonly prefix: string; readonly data: Uint8Array } { | ||
const decodedAddress = bech32.decode(address, limit); | ||
const decodedAddress = bech32.decode(address as `${string}1${string}`, limit); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is an unsafe cast, isn't it? address
might be any string but we tell bech32.decode
it is guaranteed to have a certain structure. I guess if we add an
function isBech32Structure(input: string): input is ${string}1${string} {
// return false if malformatted
}
we get a safe type narrowing
*/ | ||
export function normalizeBech32(address: string): string { | ||
const { prefix, data } = fromBech32(address); | ||
const { prefix, data } = fromBech32(address as `${string}1${string}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is not needed anymore as fromBech32
accepts any string
TypeScript return types are narrowed in a way that's still backwards-compatible.