Skip to content

Commit a0d2a84

Browse files
committed
feat(wasm-dot): change encodeSs58/validateAddress to accept number
Parameter type changed from AddressFormat (0|2|42 union) to number, so callers can pass any numeric SS58 prefix without a cast. Existing callers using AddressFormat.Polkadot etc. continue to work unchanged. Ticket: T1-57 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent ab8940c commit a0d2a84

1 file changed

Lines changed: 7 additions & 8 deletions

File tree

packages/wasm-dot/js/address.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { AddressNamespace } from "./wasm/wasm_dot.js";
2-
import { AddressFormat } from "./types.js";
32

43
/**
54
* Result of decoding an SS58 address
@@ -13,11 +12,11 @@ export interface DecodedAddress {
1312
* Encode a public key to SS58 address format.
1413
*
1514
* @param publicKey - 32-byte Ed25519 public key
16-
* @param format - Address format (Polkadot, Kusama, or Substrate)
15+
* @param prefix - Network prefix (e.g. 0 = Polkadot, 2 = Kusama, 42 = Substrate)
1716
* @returns SS58-encoded address string
1817
*/
19-
export function encodeSs58(publicKey: Uint8Array, format: AddressFormat): string {
20-
return AddressNamespace.encodeSs58(publicKey, format);
18+
export function encodeSs58(publicKey: Uint8Array, prefix: number): string {
19+
return AddressNamespace.encodeSs58(publicKey, prefix);
2120
}
2221

2322
/**
@@ -34,9 +33,9 @@ export function decodeSs58(address: string): DecodedAddress {
3433
* Validate an SS58 address.
3534
*
3635
* @param address - SS58-encoded address string
37-
* @param format - Optional expected address format to check against
38-
* @returns true if the address is valid (and matches format if provided)
36+
* @param prefix - Optional expected network prefix to check against
37+
* @returns true if the address is valid (and matches prefix if provided)
3938
*/
40-
export function validateAddress(address: string, format?: AddressFormat): boolean {
41-
return AddressNamespace.validateAddress(address, format);
39+
export function validateAddress(address: string, prefix?: number): boolean {
40+
return AddressNamespace.validateAddress(address, prefix);
4241
}

0 commit comments

Comments
 (0)