/// <reference types="node" />
import Long from "long";
import { BehaviorSubject } from "rxjs";
import Darc from "../darc/darc";
import IdentityWrapper, { IIdentity } from "../darc/identity-wrapper";
import { IConnection, Roster } from "../network";
import { SkipBlock } from "../skipchain";
import { ClientTransaction, ICounterUpdater } from "./client-transaction";
import ChainConfig from "./config";
import { InstanceID } from "./instance";
import Proof from "./proof";
import { AddTxResponse, GetInstanceVersionResponse, GetUpdatesReply, IDVersion } from "./proto/requests";
export declare const currentVersion = 5;
export declare const versionViewchange = 4;
export declare const versionPreID = 5;
export declare const CONFIG_INSTANCE_ID: Buffer;
/**
 * ByzCoinRPC represents one byzcoin-representation.
 *
 * TODO:
 * Split this into two classes:
 * - one with only static methods mapped to the API of byzcoin
 * - one representing a single byzcoin-instance
 */
export default class ByzCoinRPC implements ICounterUpdater {
    readonly genesisID: InstanceID;
    latest: SkipBlock;
    static readonly serviceName = "ByzCoin";
    /**
     * Helper to create a genesis darc
     * @param signers       Authorized signers
     * @param roster        Roster that will be used
     * @param description   An optional description for the chain
     */
    static makeGenesisDarc(signers: IIdentity[], roster: Roster, description?: string): Darc;
    /**
     * Recreate a byzcoin RPC from a given roster
     * @param nodes either a roster or an initialized connection
     * @param skipchainID   The genesis block identifier
     * @param waitMatch how many times to wait for a match - useful if its called just after an addTransactionAndWait.
     * @param interval how long to wait between two attempts in waitMatch.
     * @param latest if given, use this to prove the current state of the blockchain. Needs to be trusted!
     * @param storage to be used to store instance caches
     * @param verify will skip checking of links if false
     * @returns a promise that resolves with the initialized ByzCoin instance
     */
    static fromByzcoin(nodes: Roster | IConnection, skipchainID: Buffer, waitMatch?: number, interval?: number, latest?: SkipBlock, storage?: IStorage, verify?: boolean): Promise<ByzCoinRPC>;
    /**
     * Create a new byzcoin chain and returns an associated RPC
     * @param roster        The roster to use to create the genesis block
     * @param darc          The genesis darc
     * @param blockInterval The interval of block creation in nanoseconds
     * @param storage       To be used to store instance caches
     */
    static newByzCoinRPC(roster: Roster, darc: Darc, blockInterval: Long, storage?: IStorage): Promise<ByzCoinRPC>;
    private static staticCounters;
    private newBlockWS;
    private genesisDarc;
    private newBlock;
    private config;
    private genesis;
    private conn;
    private db;
    private cache;
    private updateInstances;
    private subscriberListenOnline;
    private subscriberNewBlocks;
    private _latest;
    protected constructor();
    /**
     * Getter for the genesis darc
     * @returns the genesis darc
     */
    getDarc(): Darc;
    /**
     * Getter for the chain configuration
     * @returns the configuration
     */
    getConfig(): ChainConfig;
    /**
     * Getter for the genesis block
     * @returns the genesis block
     */
    getGenesis(): SkipBlock;
    /**
     * Getter for the ByzCoin protocol version of the
     * latest block known by the RPC client.
     */
    getProtocolVersion(): number;
    /**
     * Returns an observable proof for an instance that will be
     * automatically updated whenever the instance is changed.
     * It returns a BehaviorSubject, which is a special observable that
     * keeps the current value.
     * It also caches all requests, so if there are two requests for the
     * same id, no new observable will be created.
     * It connects to `getNewBlocks` to be informed whenever a new block is
     * created.
     * @param id of the instance to return
     * @throws an error if the instance does not exist
     */
    instanceObservable(id: InstanceID): Promise<BehaviorSubject<Proof>>;
    /**
     * Defines how many nodes will be contacted in parallel when sending a message
     * @param p nodes to contact in parallel
     */
    setParallel(p: number): void;
    /**
     * Sends a transaction to byzcoin and waits for up to 'wait' blocks for the
     * transaction to be included in the global state. If more than 'wait' blocks
     * are created and the transaction is not included, an exception will be raised.
     *
     * @param transaction is the client transaction holding
     * one or more instructions to be sent to byzcoin.
     * @param wait indicates the number of blocks to wait for the
     * transaction to be included
     * @returns a promise that gets resolved if the block has been included
     */
    sendTransactionAndWait(transaction: ClientTransaction, wait?: number): Promise<AddTxResponse>;
    /**
     * Get the latest configuration for the chain and update the local
     * cache
     */
    updateConfig(): Promise<void>;
    /**
     * Gets a proof from byzcoin to show that a given instance is in the
     * global state. The proof always starts from the genesis block.
     *
     * @param id the instance key
     * @param waitMatch number of milliseconds to wait if the proof is false
     * @param interval how long to wait before checking for a match again
     * @param verify will skip checking of links if false
     * @return a promise that resolves with the proof, rejecting otherwise
     */
    getProof(id: Buffer, waitMatch?: number, interval?: number, verify?: boolean): Promise<Proof>;
    /**
     * Gets a proof from byzcoin to show that a given instance is in the
     * global state. The proof starts from the latest known block.
     * Caution: If you need to pass the Proof onwards to another server,
     * you must use getProof in order to create a complete standalone
     * proof starting from the genesis block.
     *
     * @param id the instance key
     * @param waitMatch number of milliseconds to wait if the proof is false
     * @param interval how long to wait before checking for a match again
     * @param verify will skip checking of links if false
     * @return a promise that resolves with the proof, rejecting otherwise
     */
    getProofFromLatest(id: Buffer, waitMatch?: number, interval?: number, verify?: boolean): Promise<Proof>;
    /**
     * Gets a proof from byzcoin to show that a given instance is in the
     * global state. The proof starts from the block given in parameter.
     * Caution: If you need to pass the Proof onwards to another server,
     * you must use getProof in order to create a complete standalone
     * proof starting from the genesis block.
     *
     * @param from skipblock to start
     * @param id the instance key
     * @param waitMatch number of milliseconds to wait if the proof is false
     * @param interval how long to wait before checking for a match again
     * @param verify will skip checking of links if false
     * @return a promise that resolves with the proof, rejecting otherwise
     */
    getProofFrom(from: SkipBlock, id: Buffer, waitMatch?: number, interval?: number, verify?: boolean): Promise<Proof>;
    /**
     * Gets one or more proofs for updated instances. The client can ask an array of instances and their latest
     * known version, and the service will return all instances that have been updated in the meantime.
     *
     * Instead of returning full proofs, it only returns the InclusionProofs.
     *
     * @param instances that will be queried for changes
     * @param flags are ORed to indicate the following behaviors:
     *    - GetUpdatesRequest.sendVersion0 (=1) will make GetUpdates to send all instances with
     *     version 0, even those that are note updated.
     *    - GetUpdatesRequest.sendMissingProofs (=2) will make GetUpdates send proofs for missing
     *     instances. If not present, missing instances are ignored.
     */
    getUpdates(instances: IDVersion[], flags?: Long): Promise<GetUpdatesReply>;
    /**
     * Get the latest counter for the given signers and increase it with a given value
     *
     * @param ids The identifiers of the signers
     * @param add The increment
     * @returns the ordered list of counters
     */
    getSignerCounters(ids: IIdentity[], add?: number): Promise<Long[]>;
    /**
     * This keeps track of the know counters, thus speeding up signing with known keys. It
     * also solves the problem of counters sometimes being out of synch with the chain.
     * After the call returns, all signers are in ClientTransaction.counters.
     *
     * @param rpc should allow updates for counters
     * @param signers the signers needed
     */
    updateCachedCounters(signers: IIdentity[]): Promise<Long[]>;
    /**
     * Clears the counters, in case of an error.
     */
    clearCounters(): void;
    /**
     * Returns the next value for the counter and updates the cache.
     */
    getNextCounter(signer: IIdentity): Long;
    /**
     * checks the authorization of a set of identities with respect to a given darc. This calls
     * an OmniLedger node and trusts it to return the name of the actions that a hypothetical set of
     * signatures from the given identities can execute using the given darc.
     *
     * This is useful if a darc delegates one or more actions to other darc, who delegate also, so
     * this call will test what actions are possible to be executed.
     *
     * @param darcID the base darc whose actions are verified
     * @param identities the set of identities that are hypothetically signing
     */
    checkAuthorization(byzCoinID: InstanceID, darcID: InstanceID, ...identities: IdentityWrapper[]): Promise<string[]>;
    /**
     * The returned BehaviorSubject replays all new blocks to all listeners.
     * The streaming is attached to the first node of the connectionlist.
     */
    getNewBlocks(): Promise<BehaviorSubject<SkipBlock>>;
    /**
     * Closes an eventual newBlock websocket. All connected BehaviorSubjects
     * will get a 'completed' message.
     */
    closeNewBlocks(): void;
    /**
     * Returns the latest version of an instance and the block-number it's been created or modified in. The node
     * might not have the version available.
     *
     * @param instanceid
     * @param version
     */
    getInstanceVersion(instanceid: InstanceID, version: Long): Promise<GetInstanceVersionResponse>;
    /**
     * Returns the latest version of an instance and the block-number it's been created or modified in.
     *
     * @param instanceid
     * @param version
     */
    getLastInstanceVersion(instanceid: InstanceID): Promise<GetInstanceVersionResponse>;
    /**
     * Returns a given version of an instance and the block-number it's in. The node might not have the version
     * available.
     *
     * @param instanceid
     * @param version
     */
    getAllInstanceVersions(instanceid: InstanceID): Promise<GetInstanceVersionResponse[]>;
    /**
     * For every new block received, this method calls getUpdates with all instance-IDs of the cache.
     * If an instance has been updated onchain, it calls 'next' with the new value.
     * This means that for every instance returned from instanceObservable, it will automatically be updated.
     */
    private getUpdateInstances;
    private listenNewBlocks;
    private counters;
}
/**
 * IStorage represents a storage backend - either a local cache, or a db
 * that stays around between sessions.
 */
export interface IStorage {
    get(key: string): Promise<Buffer | undefined>;
    set(key: string, value: Buffer): Promise<void>;
}
/**
 * LocalCache wraps a Map<string, Buffer> to be used by the Marshaller.
 */
export declare class LocalCache implements IStorage {
    private cache;
    get(key: string): Promise<Buffer | undefined>;
    set(key: string, value: Buffer): Promise<void>;
}
