import { Base58String } from '../index.js'; import { AccountAddress } from '../types/index.js'; declare const CCD_NETWORK_ID = 919; /** JSON representation of a {@link Type}. */ export type JSON = { /** The address of the account holding the token. */ address: Base58String; /** Optional coininfo describing the network for the account. */ coinInfo?: typeof CCD_NETWORK_ID; }; declare class CborAccountAddress { #private; /** The address of the account holding the token. */ readonly address: AccountAddress.Type; /** * Optional coin info describing the network for the account. If this is `undefined` * it is interpreted as a Concordium account. */ readonly coinInfo: typeof CCD_NETWORK_ID | undefined; constructor( /** The address of the account holding the token. */ address: AccountAddress.Type, /** * Optional coin info describing the network for the account. If this is `undefined` * it is interpreted as a Concordium account. */ coinInfo: typeof CCD_NETWORK_ID | undefined); toString(): string; /** * Get a JSON-serializable representation of the account address. This is called implicitly when serialized with JSON.stringify. * @returns {JSON} The JSON representation. */ toJSON(): JSON; } /** * Public type alias for the CBOR aware AccountAddress wrapper. * Instances are created via the helper factory functions rather than the class constructor. */ export type Type = CborAccountAddress; /** * Construct a {@link Type} from an existing {@link AccountAddress.Type}. * Coin information will default to the Concordium network id (919). */ export declare function fromAccountAddress(address: AccountAddress.Type): CborAccountAddress; /** * Recreate a {@link Type} from its JSON form. * @throws {Error} If the supplied coinInfo is present and not the Concordium network id. */ export declare function fromJSON(json: JSON): Type; /** * Construct a CborAccountAddress from a base58check string. * * @param {string} address String of base58check encoded account address, must use a byte version of 1. * @returns {CborAccountAddress} The CborAccountAddress. * @throws If the provided string is not: exactly 50 characters, a valid base58check encoding using version byte 1. */ export declare function fromBase58(address: string): CborAccountAddress; /** * Get a base58check string of the account address. * @param {CborAccountAddress} accountAddress The account address. */ export declare function toBase58(accountAddress: CborAccountAddress): string; /** * Type predicate which checks if a value is an instance of {@linkcode Type} */ export declare function instanceOf(value: unknown): value is Type; /** * Converts an CborAccountAddress to its CBOR (Concise Binary Object Representation) encoding. * This encodes the account address as a CBOR tagged value with tag 40307, containing both * the coin information (tagged as 40305) and the account's decoded address. * * This corresponds to a concordium-specific subtype of the `tagged-address` type from * [BCR-2020-009]{@link https://github.com/BlockchainCommons/Research/blob/master/papers/bcr-2020-009-address.md}, * identified by `tagged-coininfo` corresponding to the Concordium network from * [BCR-2020-007]{@link https://github.com/BlockchainCommons/Research/blob/master/papers/bcr-2020-007-hdkey.md} * * Example of CBOR diagnostic notation for an encoded account address: * ``` * 40307({ * 1: 40305({1: 919}), * 3: h'abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789' * }) * ``` * Where 919 is the Concordium network identifier and the hex string is the raw account address. * * @param {Type} value - The token holder to convert to CBOR format. * @throws {Error} - If an unsupported CBOR encoding is specified. * @returns {Uint8Array} The CBOR encoded representation of the token holder. */ export declare function toCBOR(value: Type): Uint8Array; /** * Registers a CBOR encoder for the CborAccountAddress type with the `cbor2` library. * This allows CborAccountAddress instances to be automatically encoded when used with * the `cbor2` library's encode function. * * @returns {void} * @example * // Register the encoder * registerCBOREncoder(); * // Now CborAccountAddress instances can be encoded directly * const encoded = encode(myCborAccountAddress); */ export declare function registerCBOREncoder(): void; /** * Decodes a CBOR value into a CborAccountAddress instance. * This function checks if the value is a tagged address (40307) and decodes it accordingly. * * @param {unknown} value - The CBOR decoded value, expected to be a tagged address. * @throws {Error} - If the value is not a valid CBOR encoded token holder account. * @returns {Type} The decoded CborAccountAddress instance. */ export declare function fromCBORValue(value: unknown): Type; /** * Decodes a CBOR-encoded account address into an CborAccountAddress instance. * This function can handle both the full tagged format (with coin information) * and a simplified format with just the address bytes. * * 1. With `tagged-coininfo` (40305): * ``` * 40307({ * 1: 40305({1: 919}), // Optional coin information * 3: h'abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789' * }) * ``` * * 2. Without `tagged-coininfo`: * ``` * 40307({ * 3: h'abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789' * }) // The address is assumed to be a Concordium address * ``` * * @param {Uint8Array} bytes - The CBOR encoded representation of an account address. * @throws {Error} - If the input is not a valid CBOR encoding of an account address. * @returns {Type} The decoded CborAccountAddress instance. */ export declare function fromCBOR(bytes: Uint8Array): Type; /** * Registers a CBOR decoder for the tagged-address (40307) format with the `cbor2` library. * This enables automatic decoding of CBOR data containing Concordium account addresses * when using the `cbor2` library's decode function. * * @returns {() => void} A cleanup function that, when called, will restore the previous * decoder (if any) that was registered for the tagged-address format. This is useful * when used in an existing `cbor2` use-case. * * @example * // Register the decoder * const cleanup = registerCBORDecoder(); * // Use the decoder * const tokenHolder = decode(cborBytes); // Returns CborAccountAddress if format matches * // Later, unregister the decoder * cleanup(); */ export declare function registerCBORDecoder(): () => void; export {};