We implemented SS58 serialization as extensions to Data and to String.

It uses our Base58 implementation under the hood.

let publicKey: Data
let accountId: AccountId /* Data alias */ = try publicKey.ss58.accountId()

let polkadotAddress: String = try publicKey.ss58.address(type: 0)
let kusamaAddress: String = try publicKey.ss58.address(type: 2)

let networkTypeFromPolkadotAddress: UInt = try polkadotAddress.ss58.networkType() // 0
let networkTypeFromKusamaAddress: UInt = try kusamaAddress.ss58.networkType() // 2

let accountIdFromPolkadotAddress: Data = try polkadotAddress.ss58.accountId()
let accountIdFromKusamaAddress: Data = try polkadotAddress.ss58.accountId()

Last updated