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

### Hierarchy

- ByzCoinRPC

### Implements

- ICounterUpdater

## Index

### Constructors

- constructor

### Properties

- _latest
- cache
- config
- conn
- db
- genesis
- genesisDarc
- newBlock
- newBlockWS
- subscriberListenOnline
- subscriberNewBlocks
- updateInstances
- serviceName
- staticCounters

### Accessors

- genesisID
- latest

### Methods

- checkAuthorization
- clearCounters
- closeNewBlocks
- counters
- getAllInstanceVersions
- getConfig
- getDarc
- getGenesis
- getInstanceVersion
- getLastInstanceVersion
- getNewBlocks
- getNextCounter
- getProof
- getProofFrom
- getProofFromLatest
- getProtocolVersion
- getSignerCounters
- getUpdateInstances
- getUpdates
- instanceObservable
- listenNewBlocks
- sendTransactionAndWait
- setParallel
- updateCachedCounters
- updateConfig
- fromByzcoin
- makeGenesisDarc
- newByzCoinRPC

## Constructors

### Protected constructor

- new ByzCoinRPC(): ByzCoinRPC

- - Defined in src/byzcoin/byzcoin-rpc.ts:170

  #### Returns ByzCoinRPC

## Properties

### Private _latest

_latest: SkipBlock

- Defined in src/byzcoin/byzcoin-rpc.ts:170

### Private cache

cache: Map<string, BehaviorSubject<Proof>> = new Map<string, BehaviorSubject<Proof>>()

- Defined in src/byzcoin/byzcoin-rpc.ts:165

### Private config

config: ChainConfig

- Defined in src/byzcoin/byzcoin-rpc.ts:161

### Private conn

conn: IConnection

- Defined in src/byzcoin/byzcoin-rpc.ts:163

### Private db

db: IStorage

- Defined in src/byzcoin/byzcoin-rpc.ts:164

### Private genesis

genesis: SkipBlock

- Defined in src/byzcoin/byzcoin-rpc.ts:162

### Private genesisDarc

genesisDarc: Darc

- Defined in src/byzcoin/byzcoin-rpc.ts:159

### Private newBlock

newBlock: BehaviorSubject<SkipBlock>

- Defined in src/byzcoin/byzcoin-rpc.ts:160

### Private newBlockWS

newBlockWS: WebSocketAdapter

- Defined in src/byzcoin/byzcoin-rpc.ts:158

### Private subscriberListenOnline

subscriberListenOnline: Subscription

- Defined in src/byzcoin/byzcoin-rpc.ts:167

### Private subscriberNewBlocks

subscriberNewBlocks: Subscription

- Defined in src/byzcoin/byzcoin-rpc.ts:168

### Private updateInstances

updateInstances: BehaviorSubject<number>

- Defined in src/byzcoin/byzcoin-rpc.ts:166

### Static serviceName

serviceName: "ByzCoin" = "ByzCoin"

- Defined in src/byzcoin/byzcoin-rpc.ts:72

### Static Private staticCounters

staticCounters: Map<string, Map<string, Long>> = new Map<string, Map<string, Long>>()

- Defined in src/byzcoin/byzcoin-rpc.ts:157

## Accessors

### genesisID

- get genesisID(): InstanceID

- - Defined in src/byzcoin/byzcoin-rpc.ts:55

  #### Returns InstanceID

### latest

- get latest(): SkipBlock
- set latest(sb: SkipBlock): void

- - Defined in src/byzcoin/byzcoin-rpc.ts:59

  #### Returns SkipBlock

- - Defined in src/byzcoin/byzcoin-rpc.ts:63

  #### Parameters

  - ##### sb: SkipBlock

  #### Returns void

## Methods

### checkAuthorization

- checkAuthorization(byzCoinID: InstanceID, darcID: InstanceID, ...identities: IdentityWrapper[]): Promise<string[]>

- - Defined in src/byzcoin/byzcoin-rpc.ts:509

  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.

  #### Parameters

  - ##### byzCoinID: InstanceID

  - ##### darcID: InstanceID

    the base darc whose actions are verified

  - ##### Rest ...identities: IdentityWrapper[]

    the set of identities that are hypothetically signing

  #### Returns Promise<string[]>

### clearCounters

- clearCounters(): void

- - Defined in src/byzcoin/byzcoin-rpc.ts:484

  Clears the counters, in case of an error.

  #### Returns void

### closeNewBlocks

- closeNewBlocks(): void

- - Defined in src/byzcoin/byzcoin-rpc.ts:543

  Closes an eventual newBlock websocket. All connected BehaviorSubjects will get a 'completed' message.

  #### Returns void

### Private counters

- counters(): Map<string, Long>

- - Defined in src/byzcoin/byzcoin-rpc.ts:684

  #### Returns Map<string, Long>

### getAllInstanceVersions

- getAllInstanceVersions(instanceid: InstanceID): Promise<GetInstanceVersionResponse[]>

- - Defined in src/byzcoin/byzcoin-rpc.ts:589

  Returns a given version of an instance and the block-number it's in. The node might not have the version available.

  #### Parameters

  - ##### instanceid: InstanceID

  #### Returns Promise<GetInstanceVersionResponse[]>

### getConfig

- getConfig(): ChainConfig

- - Defined in src/byzcoin/byzcoin-rpc.ts:187

  Getter for the chain configuration

  #### Returns ChainConfig

  the configuration

### getDarc

- getDarc(): Darc

- - Defined in src/byzcoin/byzcoin-rpc.ts:179

  Getter for the genesis darc

  #### Returns Darc

  the genesis darc

### getGenesis

- getGenesis(): SkipBlock

- - Defined in src/byzcoin/byzcoin-rpc.ts:195

  Getter for the genesis block

  #### Returns SkipBlock

  the genesis block

### getInstanceVersion

- getInstanceVersion(instanceid: InstanceID, version: Long): Promise<GetInstanceVersionResponse>

- - Defined in src/byzcoin/byzcoin-rpc.ts:559

  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.

  #### Parameters

  - ##### instanceid: InstanceID

  - ##### version: Long

  #### Returns Promise<GetInstanceVersionResponse>

### getLastInstanceVersion

- getLastInstanceVersion(instanceid: InstanceID): Promise<GetInstanceVersionResponse>

- - Defined in src/byzcoin/byzcoin-rpc.ts:574

  Returns the latest version of an instance and the block-number it's been created or modified in.

  #### Parameters

  - ##### instanceid: InstanceID

  #### Returns Promise<GetInstanceVersionResponse>

### getNewBlocks

- getNewBlocks(): Promise<BehaviorSubject<SkipBlock>>

- - Defined in src/byzcoin/byzcoin-rpc.ts:526

  The returned BehaviorSubject replays all new blocks to all listeners. The streaming is attached to the first node of the connectionlist.

  #### Returns Promise<BehaviorSubject<SkipBlock>>

### getNextCounter

- getNextCounter(signer: IIdentity): Long

- Implementation of ICounterUpdater.getNextCounter

  - Defined in src/byzcoin/byzcoin-rpc.ts:491

  Returns the next value for the counter and updates the cache.

  #### Parameters

  - ##### signer: IIdentity

  #### Returns Long

### getProof

- getProof(id: Buffer, waitMatch?: number, interval?: number, verify?: boolean): Promise<Proof>

- - Defined in src/byzcoin/byzcoin-rpc.ts:345

  Gets a proof from byzcoin to show that a given instance is in the global state. The proof always starts from the genesis block.

  #### Parameters

  - ##### id: Buffer

    the instance key

  - ##### Default value waitMatch: number = 0

    number of milliseconds to wait if the proof is false

  - ##### Default value interval: number = 1000

    how long to wait before checking for a match again

  - ##### Default value verify: boolean = true

    will skip checking of links if false

  #### Returns Promise<Proof>

  a promise that resolves with the proof, rejecting otherwise

### getProofFrom

- getProofFrom(from: SkipBlock, id: Buffer, waitMatch?: number, interval?: number, verify?: boolean): Promise<Proof>

- - Defined in src/byzcoin/byzcoin-rpc.ts:389

  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.

  #### Parameters

  - ##### from: SkipBlock

    skipblock to start

  - ##### id: Buffer

    the instance key

  - ##### Default value waitMatch: number = 0

    number of milliseconds to wait if the proof is false

  - ##### Default value interval: number = 1000

    how long to wait before checking for a match again

  - ##### Default value verify: boolean = true

    will skip checking of links if false

  #### Returns Promise<Proof>

  a promise that resolves with the proof, rejecting otherwise

### getProofFromLatest

- getProofFromLatest(id: Buffer, waitMatch?: number, interval?: number, verify?: boolean): Promise<Proof>

- - Defined in src/byzcoin/byzcoin-rpc.ts:366

  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.

  #### Parameters

  - ##### id: Buffer

    the instance key

  - ##### Default value waitMatch: number = 0

    number of milliseconds to wait if the proof is false

  - ##### Default value interval: number = 1000

    how long to wait before checking for a match again

  - ##### Default value verify: boolean = true

    will skip checking of links if false

  #### Returns Promise<Proof>

  a promise that resolves with the proof, rejecting otherwise

### getProtocolVersion

- getProtocolVersion(): number

- - Defined in src/byzcoin/byzcoin-rpc.ts:203

  Getter for the ByzCoin protocol version of the latest block known by the RPC client.

  #### Returns number

### getSignerCounters

- getSignerCounters(ids: IIdentity[], add?: number): Promise<Long[]>

- Implementation of ICounterUpdater.getSignerCounters

  - Defined in src/byzcoin/byzcoin-rpc.ts:448

  Get the latest counter for the given signers and increase it with a given value

  #### Parameters

  - ##### ids: IIdentity[]

    The identifiers of the signers

  - ##### Default value add: number = 0

    The increment

  #### Returns Promise<Long[]>

  the ordered list of counters

### Private getUpdateInstances

- getUpdateInstances(): Promise<BehaviorSubject<number>>

- - Defined in src/byzcoin/byzcoin-rpc.ts:603

  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.

  #### Returns Promise<BehaviorSubject<number>>

### getUpdates

- getUpdates(instances: IDVersion[], flags?: Long): Promise<GetUpdatesReply>

- - Defined in src/byzcoin/byzcoin-rpc.ts:431

  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.

  #### Parameters

  - ##### instances: IDVersion[]

    that will be queried for changes

  - ##### Default value flags: Long = Long.fromNumber(0)

    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.

  #### Returns Promise<GetUpdatesReply>

### instanceObservable

- instanceObservable(id: InstanceID): Promise<BehaviorSubject<Proof>>

- - Defined in src/byzcoin/byzcoin-rpc.ts:221

  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.

  throws

    an error if the instance does not exist

  #### Parameters

  - ##### id: InstanceID

    of the instance to return

  #### Returns Promise<BehaviorSubject<Proof>>

### Private listenNewBlocks

- listenNewBlocks(): void

- - Defined in src/byzcoin/byzcoin-rpc.ts:637

  #### Returns void

### sendTransactionAndWait

- sendTransactionAndWait(transaction: ClientTransaction, wait?: number): Promise<AddTxResponse>

- - Defined in src/byzcoin/byzcoin-rpc.ts:293

  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.

  #### Parameters

  - ##### transaction: ClientTransaction

    is the client transaction holding one or more instructions to be sent to byzcoin.

  - ##### Default value wait: number = 10

    indicates the number of blocks to wait for the transaction to be included

  #### Returns Promise<AddTxResponse>

  a promise that gets resolved if the block has been included

### setParallel

- setParallel(p: number): void

- - Defined in src/byzcoin/byzcoin-rpc.ts:278

  Defines how many nodes will be contacted in parallel when sending a message

  #### Parameters

  - ##### p: number

    nodes to contact in parallel

  #### Returns void

### updateCachedCounters

- updateCachedCounters(signers: IIdentity[]): Promise<Long[]>

- Implementation of ICounterUpdater.updateCachedCounters

  - Defined in src/byzcoin/byzcoin-rpc.ts:468

  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.

  #### Parameters

  - ##### signers: IIdentity[]

    the signers needed

  #### Returns Promise<Long[]>

### updateConfig

- updateConfig(): Promise<void>

- - Defined in src/byzcoin/byzcoin-rpc.ts:325

  Get the latest configuration for the chain and update the local cache

  #### Returns Promise<void>

### Static fromByzcoin

- fromByzcoin(nodes: Roster | IConnection, skipchainID: Buffer, waitMatch?: number, interval?: number, latest?: SkipBlock, storage?: IStorage, verify?: boolean): Promise<ByzCoinRPC>

- - Defined in src/byzcoin/byzcoin-rpc.ts:109

  Recreate a byzcoin RPC from a given roster

  #### Parameters

  - ##### nodes: Roster | IConnection

    either a roster or an initialized connection

  - ##### skipchainID: Buffer

    The genesis block identifier

  - ##### Default value waitMatch: number = 0

    how many times to wait for a match - useful if its called just after an addTransactionAndWait.

  - ##### Default value interval: number = 1000

    how long to wait between two attempts in waitMatch.

  - ##### Optional latest: SkipBlock

    if given, use this to prove the current state of the blockchain. Needs to be trusted!

  - ##### Optional storage: IStorage

    to be used to store instance caches

  - ##### Default value verify: boolean = true

    will skip checking of links if false

  #### Returns Promise<ByzCoinRPC>

  a promise that resolves with the initialized ByzCoin instance

### Static makeGenesisDarc

- makeGenesisDarc(signers: IIdentity[], roster: Roster, description?: string): Darc

- - Defined in src/byzcoin/byzcoin-rpc.ts:80

  Helper to create a genesis darc

  #### Parameters

  - ##### signers: IIdentity[]

    Authorized signers

  - ##### roster: Roster

    Roster that will be used

  - ##### Optional description: string

    An optional description for the chain

  #### Returns Darc

### Static newByzCoinRPC

- newByzCoinRPC(roster: Roster, darc: Darc, blockInterval: Long, storage?: IStorage): Promise<ByzCoinRPC>

- - Defined in src/byzcoin/byzcoin-rpc.ts:141

  Create a new byzcoin chain and returns an associated RPC

  #### Parameters

  - ##### roster: Roster

    The roster to use to create the genesis block

  - ##### darc: Darc

    The genesis darc

  - ##### blockInterval: Long

    The interval of block creation in nanoseconds

  - ##### Optional storage: IStorage

    To be used to store instance caches

  #### Returns Promise<ByzCoinRPC>

Generated using TypeDoc