feat(wasm-dot): change encodeSs58/validateAddress to accept number prefix#204
Closed
bitgo-ai-agent-dev[bot] wants to merge 1 commit intomasterfrom
Closed
feat(wasm-dot): change encodeSs58/validateAddress to accept number prefix#204bitgo-ai-agent-dev[bot] wants to merge 1 commit intomasterfrom
bitgo-ai-agent-dev[bot] wants to merge 1 commit intomasterfrom
Conversation
…r prefix Replace AddressFormat enum parameter with plain number in encodeSs58 and validateAddress. The AddressFormat enum remains exported as a named-constants convenience; since its members are numeric (Polkadot=0, Kusama=2, Substrate=42), existing callers passing AddressFormat.Polkadot etc. continue to compile without change — numeric enum values are assignable to number. This eliminates the need for callers to import AddressFormat just to satisfy the type, and avoids as-unknown-as casts when bridging to sdk-core's DotAddressFormat. Mirrors the pattern used by wasm-utxo, which accepts plain primitives. Ticket: T1-57 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Author
|
Closing in favour of PR #203 (btc-3117/wasm-dot-address-format-union-type), which takes a better approach: replacing the enum with a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
encodeSs58(publicKey, format: AddressFormat)→encodeSs58(publicKey, prefix: number)in@bitgo/wasm-dotvalidateAddress(address, format?: AddressFormat)→validateAddress(address, prefix?: number)for consistencyAddressFormatimport fromaddress.ts(no longer used there)AddressFormatenum remains exported fromtypes.tsas named constants for callersWhy
The underlying Rust WASM binding (
AddressNamespace.encodeSs58) already accepts au16prefix. The TypeScript wrapper was unnecessarily constraining callers to use theAddressFormatenum, requiring anas unknown as AddressFormatcast when bridging fromsdk-core'sDotAddressFormatenum.Since
AddressFormatis a numeric enum (Polkadot=0,Kusama=2,Substrate=42), existing callers that passAddressFormat.Polkadotetc. continue to compile without any changes — numeric enum values are assignable tonumber.Backward Compatibility
No breaking change. Callers using
AddressFormat.Polkadot/AddressFormat.Substrateconstants continue to work as-is; TypeScript numeric enums assign tonumberwithout a cast.Follow-up
After this ships,
bgms/dot.tscan droptoWasmAddressFormatand theAddressFormatimport, passingaddressFormat(aDotAddressFormatnumber) directly toencodeSs58. See T1-57.Test plan
test/address.tsuseAddressFormat.Substrate/AddressFormat.Polkadotas named constants and still compile and pass without changesnoUnusedLocalserrors —AddressFormatwas removed fromaddress.tswhere it was used, and remains intypes.tsand tests)Ticket: T1-57
🤖 Generated with Claude Code