Skip to Content
API Reference@parity/product-sdk-addressOverview

@parity/product-sdk-address

Address handling for accounts that live on both Substrate (SS58) and EVM (H160) chains.

Convert between formats, validate, normalize SS58 prefixes, and shorten addresses for display.

npm install @parity/product-sdk-address

Exports

Functions

NameSummary
accountIdBytes()Decode an SS58 address to its 32-byte AccountId using polkadot-api’s AccountId codec.
accountIdFromBytes()Encode an SS58 address from a 32-byte public key using polkadot-api’s AccountId codec.
addressesEqual()Compare two addresses for equality.
deriveH160()Derive the H160 EVM address from a 32-byte Substrate public key.
h160ToSs58()Convert an H160 EVM address to its corresponding SS58 address.
isValidH160()Validate whether a string is a valid H160 (20-byte hex) address.
isValidSs58()Validate whether a string is a valid SS58 address.
normalizeSs58()Re-encode an SS58 address with a different network prefix.
ss58Decode()Decode an SS58 address into its raw public key bytes and network prefix.
ss58Encode()Encode raw public key bytes into an SS58 address with the given prefix.
ss58ToH160()Convert an SS58 address to its H160 EVM address.
toGenericSs58()Convert any SS58 address to generic Substrate format (prefix 42).
toH160()Convert any address (SS58 or H160) to an H160 EVM address.
toPolkadotSs58()Convert any SS58 address to Polkadot format (prefix 0).
truncateAddress()Truncate an address for display.

Type Aliases

NameSummary
HexStringA 0x-prefixed hex string (e.g. 0xdeadbeef). The SDK uses it for raw byte
SS58StringAn SS58-encoded Substrate address (e.g. 5GrwvaEF...). The brand marks strings

Functions

accountIdBytes()

Decode an SS58 address to its 32-byte AccountId using polkadot-api’s AccountId codec. This is the inverse of accountIdFromBytes().

accountIdBytes(address: string): Uint8Array

accountIdFromBytes()

Encode an SS58 address from a 32-byte public key using polkadot-api’s AccountId codec. This is the inverse of accountIdBytes().

accountIdFromBytes(publicKey: Uint8Array, prefix: number = GENERIC_PREFIX): SS58String

addressesEqual()

Compare two addresses for equality.

H160 (0x-prefixed) addresses are compared case-insensitively. SS58 addresses are compared exactly (base58 is case-sensitive). Mixed types (SS58 vs H160) always return false - use ss58ToH160 to normalize first. SS58 addresses at different prefixes (same key, different network) return false - use normalizeSs58 to re-encode with the same prefix before comparing.

addressesEqual(a: string, b: string): boolean

deriveH160()

Derive the H160 EVM address from a 32-byte Substrate public key.

Asset Hub pallet-revive uses these derivation rules:

  • If the account was originally EVM-derived (last 12 bytes are all 0xEE): strip the padding to recover the original H160 address.
  • If native Substrate account (sr25519/ed25519): keccak256(publicKey), take last 20 bytes. One-way mapping.
deriveH160(publicKey: Uint8Array): `0x${string}`

h160ToSs58()

Convert an H160 EVM address to its corresponding SS58 address.

Constructs an “EVM-derived” AccountId32 by padding the H160 with 0xEE bytes. These accounts are implicitly mapped in pallet-revive.

h160ToSs58(evmAddress: string, prefix: number = 42): SS58String

isValidH160()

Validate whether a string is a valid H160 (20-byte hex) address.

isValidH160(address: string): boolean

isValidSs58()

Validate whether a string is a valid SS58 address.

isValidSs58(address: string): boolean

normalizeSs58()

Re-encode an SS58 address with a different network prefix. Returns null if the input is not a valid SS58 address.

normalizeSs58(address: string, prefix: number = GENERIC_PREFIX): SS58String | null

ss58Decode()

Decode an SS58 address into its raw public key bytes and network prefix.

ss58Decode(address: string): { prefix: number; publicKey: Uint8Array }

ss58Encode()

Encode raw public key bytes into an SS58 address with the given prefix. Defaults to prefix 42 (generic Substrate).

ss58Encode(publicKey: Uint8Array, prefix: number = GENERIC_PREFIX): SS58String

ss58ToH160()

Convert an SS58 address to its H160 EVM address.

Handles both native Substrate accounts (keccak256 path) and EVM-derived accounts (0xEE padding strip).

ss58ToH160(address: string): `0x${string}`

toGenericSs58()

Convert any SS58 address to generic Substrate format (prefix 42). Returns null if the input is invalid.

toGenericSs58(address: string): SS58String | null

toH160()

Convert any address (SS58 or H160) to an H160 EVM address. If already H160 format (0x-prefixed, 42 chars), returns as-is preserving original casing.

toH160(address: string): `0x${string}`

toPolkadotSs58()

Convert any SS58 address to Polkadot format (prefix 0). Returns null if the input is invalid.

toPolkadotSs58(address: string): SS58String | null

truncateAddress()

Truncate an address for display.

truncateAddress(address: string, startChars: number = 6, endChars: number = 4): string

Parameters

  • address: Full address (SS58 or H160)
  • startChars: Characters to show at the start (default 6)
  • endChars: Characters to show at the end (default 4)

Returns

Truncated string like “5Grwva…utQY”

Type Aliases

type HexString

A 0x-prefixed hex string (e.g. 0xdeadbeef). The SDK uses it for raw byte values like public keys and EVM addresses.

type HexString = string & { __hexString?: unknown }

type SS58String

An SS58-encoded Substrate address (e.g. 5GrwvaEF...). The brand marks strings the SDK has validated, so APIs accepting SS58String can skip re-checking. Construct one via normalizeSs58 or ss58Encode.

type SS58String = string & { __SS58String?: unknown }
Last updated on