import { Sha256 } from '../crypto/crypto'; import { Base58AddressNetwork } from './base58-address'; import { CashAddressNetworkPrefix } from './cash-address'; /** * The most common address types used on bitcoin and bitcoin-like networks. Each * address type represents a commonly used locking bytecode pattern. * * @remarks * Addresses are strings which encode information about the network and * `lockingBytecode` to which a transaction output can pay. * * Several address formats exist – `Base58Address` was the format used by the * original satoshi client, and is still in use on several active chains (see * `encodeBase58Address`). On Bitcoin Cash, the `CashAddress` standard is most * common (See `encodeCashAddress`). */ export declare enum AddressType { /** * Pay to Public Key (P2PK). This address type is uncommon, and primarily * occurs in early blocks because the original satoshi implementation mined * rewards to P2PK addresses. * * There are no standardized address formats for representing a P2PK address. * Instead, most applications use the `AddressType.p2pkh` format. */ p2pk = "P2PK", /** * Pay to Public Key Hash (P2PKH). The most common address type. P2PKH * addresses lock funds using a single private key. */ p2pkh = "P2PKH", /** * Pay to Script Hash (P2SH). An address type which locks funds to the hash of * a script provided in the spending transaction. See BIP13 for details. */ p2sh = "P2SH", /** * This `AddressType` represents an address using an unknown or uncommon * locking bytecode pattern for which no standardized address formats exist. */ unknown = "unknown" } /** * An object representing the contents of an address. This can be used to encode * an address or its locking bytecode. * * See `lockingBytecodeToAddressContents` for details. */ export interface AddressContents { type: AddressType; payload: Uint8Array; } /** * Attempt to match a lockingBytecode to a standard address type for use in * address encoding. (See `AddressType` for details.) * * For a locking bytecode matching the Pay to Public Key Hash (P2PKH) pattern, * the returned `type` is `AddressType.p2pkh` and `payload` is the `HASH160` of * the public key. * * For a locking bytecode matching the Pay to Script Hash (P2SH) pattern, the * returned `type` is `AddressType.p2sh` and `payload` is the `HASH160` of the * redeeming bytecode, A.K.A. "redeem script hash". * * For a locking bytecode matching the Pay to Public Key (P2PK) pattern, the * returned `type` is `AddressType.p2pk` and `payload` is the full public key. * * Any other locking bytecode will return a `type` of `AddressType.unknown` and * a payload of the unmodified `bytecode`. * * @param bytecode - the locking bytecode to match */ export declare const lockingBytecodeToAddressContents: (bytecode: Uint8Array) => AddressContents; /** * Get the locking bytecode for a valid `AddressContents` object. See * `lockingBytecodeToAddressContents` for details. * * For `AddressContents` of `type` `AddressType.unknown`, this method returns * the `payload` without modification. * * @param addressContents - the `AddressContents` to encode */ export declare const addressContentsToLockingBytecode: (addressContents: AddressContents) => Uint8Array; /** * Encode a locking bytecode as a CashAddress given a network prefix. * * If `bytecode` matches either the P2PKH or P2SH pattern, it is encoded using * the proper address type and returned as a valid CashAddress (string). * * If `bytecode` cannot be encoded as an address (i.e. because the pattern is * not standard), the resulting `AddressContents` is returned. * * @param bytecode - the locking bytecode to encode * @param prefix - the network prefix to use, e.g. `bitcoincash`, `bchtest`, or * `bchreg` */ export declare const lockingBytecodeToCashAddress: (bytecode: Uint8Array, prefix: Prefix) => string | AddressContents; export declare enum LockingBytecodeEncodingError { unknownCashAddressType = "This CashAddress uses an unknown address type." } /** * Convert a CashAddress to its respective locking bytecode. * * This method returns the locking bytecode and network prefix. If an error * occurs, an error message is returned as a string. * * @param address - the CashAddress to convert */ export declare const cashAddressToLockingBytecode: (address: string) => import("./cash-address").CashAddressDecodingError | LockingBytecodeEncodingError.unknownCashAddressType | { bytecode: Uint8Array; prefix: string; }; /** * Encode a locking bytecode as a Base58Address for a given network. * * If `bytecode` matches either the P2PKH or P2SH pattern, it is encoded using * the proper address type and returned as a valid Base58Address (string). * * If `bytecode` cannot be encoded as an address (i.e. because the pattern is * not standard), the resulting `AddressContents` is returned. * * @param sha256 - an implementation of sha256 (a universal implementation is * available via `instantiateSha256`) * @param bytecode - the locking bytecode to encode * @param network - the network for which to encode the address (`mainnet` or * `testnet`) */ export declare const lockingBytecodeToBase58Address: (sha256: { hash: Sha256['hash']; }, bytecode: Uint8Array, network: Base58AddressNetwork) => string | AddressContents; /** * Convert a Base58Address to its respective locking bytecode. * * This method returns the locking bytecode and network version. If an error * occurs, an error message is returned as a string. * * @param address - the CashAddress to convert */ export declare const base58AddressToLockingBytecode: (sha256: { hash: Sha256['hash']; }, address: string) => import("./base58-address").Base58AddressError | { bytecode: Uint8Array; version: number; }; //# sourceMappingURL=locking-bytecode.d.ts.map