UNPKG

incubed

Version:

Typescript-version of the incubed client

1,614 lines (1,613 loc) 195 kB
import * as Ajv from 'ajv'; /** * the Proof-for a single Account */ export interface AccountProof { /** * the serialized merle-noodes beginning with the root-node */ accountProof: string[]; /** * the address of this account */ address: string; /** * the balance of this account as hex */ balance: string; /** * the codeHash of this account as hex */ codeHash: string; /** * the code of this account as hex ( if required) */ code?: string; /** * the nonce of this account as hex */ nonce: string; /** * the storageHash of this account as hex */ storageHash: string; /** * proof for requested storage-data */ storageProof: { /** * the storage key */ key: string; /** * the serialized merkle-noodes beginning with the root-node ( storageHash ) */ proof: string[]; /** * the stored value */ value: string; }[]; } /** * a Object holding proofs for validator logs. The key is the blockNumber as hex */ export interface AuraValidatoryProof { /** * the transaction log index */ logIndex: number; /** * the serialized blockheader * example: 0x72804cfa0179d648ccbe6a65b01a6463a8f1ebb14f3aff6b19cb91acf2b8ec1ffee98c0437b4ac839d8a2ece1b18166da704b86d8f42c92bbda6463a8f1ebb14f3aff6b19cb91acf2b8ec1ffee98c0437b4ac839d8a2ece1b18166da704b */ block: string; /** * the transactionIndex within the block */ txIndex: number; /** * the merkleProof */ proof: string[]; /** * the serialized blockheader as hex, required in case of finality asked * example: 0x72804cfa0179d648ccbe6a65b01a6463a8f1ebb14f3aff6b19cb91acf2b8ec1ffee98c0437b4ac839d8a2ece1b18166da704b86d8f42c92bbda6463a8f1ebb14f3aff6b19cb91acf2b8ec1ffee98c0437b4ac839d8a2ece1b18166da704b */ finalityBlocks?: any[]; } /** * describes the chainspecific consensus params */ export interface ChainSpec { /** * the engine type (like Ethhash, authorityRound, ... ) */ engine?: string; /** * the aura contract to get the validators */ validatorContract?: string; /** * the list of validators */ validatorList?: any[]; } /** * the iguration of the IN3-Client. This can be paritally overriden for every request. */ export interface IN3Config { /** * number of seconds requests can be cached. */ cacheTimeout?: number; /** * the limit of nodes to store in the client. * example: 150 */ nodeLimit?: number; /** * if true, the in3-section of thr response will be kept. Otherwise it will be removed after validating the data. This is useful for debugging or if the proof should be used afterwards. */ keepIn3?: boolean; /** * the format for sending the data to the client. Default is json, but using cbor means using only 30-40% of the payload since it is using binary encoding * example: json */ format?: 'json' | 'jsonRef' | 'cbor'; /** * the client key to sign requests * example: 0x387a8233c96e1fc0ad5e284353276177af2186e7afa85296f106336e376669f7 */ key?: any; /** * if true the config will be adjusted depending on the request */ autoConfig?: boolean; /** * if true the the request may be handled without proof in case of an error. (use with care!) */ retryWithoutProof?: boolean; /** * max number of attempts in case a response is rejected * example: 10 */ maxAttempts?: number; /** * if true, the request should include the codes of all accounts. otherwise only the the codeHash is returned. In this case the client may ask by calling eth_getCode() afterwards * example: true */ includeCode?: boolean; /** * number of max bytes used to cache the code in memory * example: 100000 */ maxCodeCache?: number; /** * number of number of blocks cached in memory * example: 100 */ maxBlockCache?: number; /** * if the client sends a array of blockhashes the server will not deliver any signatures or blockheaders for these blocks, but only return a string with a number. This is automaticly updated by the cache, but can be overriden per request. */ verifiedHashes?: string[]; /** * if true the nodes should send a proof of the response * example: true */ proof?: 'none' | 'standard' | 'full'; /** * number of signatures requested * example: 2 */ signatureCount?: number; /** * min stake of the server. Only nodes owning at least this amount will be chosen. */ minDeposit: number; /** * if specified, the blocknumber *latest* will be replaced by blockNumber- specified value * example: 6 */ replaceLatestBlock?: number; /** * the number of request send when getting a first answer * example: 3 */ requestCount: number; /** * the number in percent needed in order reach finality (% of signature of the validators) * example: 50 */ finality?: number; /** * specifies the number of milliseconds before the request times out. increasing may be helpful if the device uses a slow connection. * example: 3000 */ timeout?: number; /** * servers to filter for the given chain. The chain-id based on EIP-155. * example: 0x1 */ chainId: string; /** * main chain-registry contract * example: 0xe36179e2286ef405e929C90ad3E70E649B22a945 */ chainRegistry?: string; /** * main chain-id, where the chain registry is running. * example: 0x1 */ mainChain?: string; /** * if true the nodelist will be automaticly updated if the lastBlock is newer * example: true */ autoUpdateList?: boolean; /** * a cache handler offering 2 functions ( setItem(string,string), getItem(string) ) */ cacheStorage?: any; /** * a url of RES-Endpoint, the client will log all errors to. The client will post to this endpoint JSON like { id?, level, message, meta? } */ loggerUrl?: string; /** * url of one or more rpc-endpoints to use. (list can be comma seperated) */ rpc?: string; /** * the nodelist per chain */ servers?: { [name: string]: { /** * name of the module responsible for handling the verification */ verifier?: string; /** * a alias for the chain */ name?: string; /** * chain definition */ chainSpec?: ChainSpec; /** * a list of addresses which should always be part of the nodelist when getting an update * example: 0xe36179e2286ef405e929C90ad3E70E649B22a945,0x6d17b34aeaf95fee98c0437b4ac839d8a2ece1b1 */ initAddresses?: string[]; /** * the blockNumber of the last event in the registry * example: 23498798 */ lastBlock?: number; /** * the address of the registry contract * example: 0xe36179e2286ef405e929C90ad3E70E649B22a945 */ contract?: string; /** * if true the nodelist should be updated. */ needsUpdate?: boolean; /** * the chainid for the contract * example: 0x8 */ contractChain?: string; /** * the list of nodes */ nodeList?: IN3NodeConfig[]; /** * the list of authority nodes for handling conflicts * example: 0xe36179e2286ef405e929C90ad3E70E649B22a945,0x6d17b34aeaf95fee98c0437b4ac839d8a2ece1b1 */ nodeAuthorities?: string[]; /** * the weights of nodes depending on former performance which is used internally */ weights?: { [name: string]: IN3NodeWeight; }; }; }; } /** * a configuration of a in3-server. */ export interface IN3NodeConfig { /** * the index within the contract * example: 13 */ index?: number; /** * the address of the node, which is the public address it iis signing with. * example: 0x6C1a01C2aB554930A937B0a2E8105fB47946c679 */ address: string; /** * the time (in seconds) until an owner is able to receive his deposit back after he unregisters himself * example: 3600 */ timeout?: number; /** * the endpoint to post to * example: https://in3.slock.it */ url: string; /** * the list of supported chains * example: 0x1 */ chainIds: string[]; /** * the deposit of the node in wei * example: 12350000 */ deposit: number; /** * the capacity of the node. * example: 100 */ capacity?: number; /** * the properties of the node. * example: 3 */ props?: number; } /** * a local weight of a n3-node. (This is used internally to weight the requests) */ export interface IN3NodeWeight { /** * factor the weight this noe (default 1.0) * example: 0.5 */ weight?: number; /** * number of uses. * example: 147 */ responseCount?: number; /** * average time of a response in ms * example: 240 */ avgResponseTime?: number; /** * last price */ pricePerRequest?: number; /** * timestamp of the last request in ms * example: 1529074632623 */ lastRequest?: number; /** * blacklisted because of failed requests until the timestamp * example: 1529074639623 */ blacklistedUntil?: number; } /** * the configuration for the rpc-handler */ export interface IN3RPCConfig { /** * a identifier used in logfiles as also for reading the config from the database */ id?: string; /** * the default chainId in case the request does not contain one. */ defaultChain?: string; /** * the listeneing port for the server */ port?: number; db?: { /** * username for the db */ user?: string; /** * password for db-access */ password?: string; /** * db-host (default = localhost) */ host?: string; /** * the database port */ port?: number; /** * name of the database */ database?: string; }; profile?: { /** * url to a icon or logo of company offering this node */ icon?: string; /** * url of the website of the company */ url?: string; /** * name of the node or company */ name?: string; /** * comments for the node */ comment?: string; /** * if active the stats will not be shown (default:false) */ noStats?: boolean; }; /** * logger config */ logging?: { /** * the path to the logile */ file?: string; /** * Loglevel */ level?: string; /** * if true colors will be used */ colors?: boolean; /** * the name of the provider */ name?: string; /** * the module of the provider */ type?: string; /** * the port for custom logging */ port?: number; /** * the host for custom logging */ host?: string; }; /** * a definition of the Handler per chain */ chains?: { [name: string]: IN3RPCHandlerConfig; }; } /** * the configuration for the rpc-handler */ export interface IN3RPCHandlerConfig { /** * the impl used to handle the calls */ handler?: 'eth' | 'ipfs' | 'btc'; /** * the url of the ipfs-client */ ipfsUrl?: string; /** * number of milliseconds to wait before a request gets a timeout */ timeout?: number; /** * the url of the client */ rpcUrl: string; /** * a comma sepearted list of client keys to use for simulating clients for the watchdog */ clientKeys?: string; /** * average time between sending requests to the same node. 0 turns it off (default) */ watchdogInterval?: number; /** * the score for requests without a valid signature */ freeScore?: number; /** * the minimal blockheight in order to sign */ minBlockHeight?: number; /** * the filename of the file keeping track of the last handled blocknumber */ persistentFile?: string; /** * blocknumber to start watching the registry */ startBlock?: number; /** * the number of seconds of the interval for checking for new events */ watchInterval?: number; /** * the private key used to sign blockhashes. this can be either a 0x-prefixed string with the raw private key or the path to a key-file. */ privateKey: string; /** * the password used to decrpyt the private key */ privateKeyPassphrase?: string; /** * the address of the server registry used in order to update the nodeList */ registry: string; /** * the url of the client in case the registry is not on the same chain. */ registryRPC?: string; autoRegistry?: { /** * the public url to reach this node */ url: string; /** * the deposit you want ot store */ deposit: number; /** * max number of parallel requests */ capacity?: number; /** * unit of the deposit value */ depositUnit?: 'ether' | 'finney' | 'szabo' | 'wei'; capabilities?: { /** * if true, this node is able to deliver proofs */ proof?: boolean; /** * if true, this node is able to deliver multiple chains */ multiChain?: boolean; }; }; } /** * additional config for a IN3 RPC-Request */ export interface IN3RPCRequestConfig { /** * the requested chainId * example: 0x1 */ chainId: string; /** * if true, the request should include the codes of all accounts. otherwise only the the codeHash is returned. In this case the client may ask by calling eth_getCode() afterwards * example: true */ includeCode?: boolean; /** * if the client sends a array of blockhashes the server will not deliver any signatures or blockheaders for these blocks, but only return a string with a number. */ verifiedHashes?: string[]; /** * if specified, the blocknumber *latest* will be replaced by blockNumber- specified value * example: 6 */ latestBlock?: number; /** * if true binary-data (starting with a 0x) will be refered if occuring again. */ useRef?: boolean; /** * if true binary-data will be used. */ useBinary?: boolean; /** * if true all data in the response will be proven, which leads to a higher payload. */ useFullProof?: boolean; /** * if given the server will deliver the blockheaders of the following blocks until at least the number in percent of the validators is reached. */ finality?: number; /** * defines the kind of proof the client is asking for * example: proof */ verification?: 'never' | 'proof' | 'proofWithSignature'; /** * the signature of the client */ clientSignature?: any; /** * a list of addresses requested to sign the blockhash * example: 0x6C1a01C2aB554930A937B0a2E8105fB47946c679 */ signatures?: string[]; } /** * additional data returned from a IN3 Server */ export interface IN3ResponseConfig { /** * the Proof-data */ proof?: Proof; /** * the blocknumber for the last block updating the nodelist. If the client has a smaller blocknumber he should update the nodeList. * example: 326478 */ lastNodeList?: number; /** * the blocknumber of gthe last change of the validatorList */ lastValidatorChange?: number; /** * the current blocknumber. * example: 320126478 */ currentBlock?: number; } /** * a Object holding proofs for event logs. The key is the blockNumber as hex */ export interface LogProof { [name: string]: { /** * the blockNumber */ number?: number; /** * the serialized blockheader * example: 0x72804cfa0179d648ccbe6a65b01a6463a8f1ebb14f3aff6b19cb91acf2b8ec1ffee98c0437b4ac839d8a2ece1b18166da704b86d8f42c92bbda6463a8f1ebb14f3aff6b19cb91acf2b8ec1ffee98c0437b4ac839d8a2ece1b18166da704b */ block: string; /** * temp. list of all receipts, which is not included in the final proof */ allReceipts?: any[]; /** * the map of existing receipts with the txHash as key */ receipts: { [name: string]: { /** * the transactionHash */ txHash?: string; /** * the transactionIndex within the block */ txIndex: number; /** * the merkleProof */ txProof?: string[]; /** * the merkleProof */ proof: string[]; }; }; }; } /** * the Proof-data as part of the in3-section */ export interface Proof { /** * the type of the proof * example: accountProof */ type: 'transactionProof' | 'receiptProof' | 'blockProof' | 'accountProof' | 'callProof' | 'logProof'; /** * the serialized blockheader as hex, required in most proofs * example: 0x72804cfa0179d648ccbe6a65b01a6463a8f1ebb14f3aff6b19cb91acf2b8ec1ffee98c0437b4ac839d8a2ece1b18166da704b86d8f42c92bbda6463a8f1ebb14f3aff6b19cb91acf2b8ec1ffee98c0437b4ac839d8a2ece1b18166da704b */ block?: string; /** * the serialized blockheader as hex, required in case of finality asked * example: 0x72804cfa0179d648ccbe6a65b01a6463a8f1ebb14f3aff6b19cb91acf2b8ec1ffee98c0437b4ac839d8a2ece1b18166da704b86d8f42c92bbda6463a8f1ebb14f3aff6b19cb91acf2b8ec1ffee98c0437b4ac839d8a2ece1b18166da704b */ finalityBlocks?: any[]; /** * the list of transactions of the block * example: */ transactions?: any[]; /** * the list of uncle-headers of the block * example: */ uncles?: any[]; /** * the serialized merle-noodes beginning with the root-node */ merkleProof?: string[]; /** * the serialized merkle-noodes beginning with the root-node of the previous entry (only for full proof of receipts) */ merkleProofPrev?: string[]; /** * the serialized merkle-nodes beginning with the root-node in order to prrof the transactionIndex */ txProof?: string[]; /** * the Log Proof in case of a Log-Request */ logProof?: LogProof; /** * a map of addresses and their AccountProof */ accounts?: { [name: string]: AccountProof; }; /** * the transactionIndex within the block * example: 4 */ txIndex?: number; /** * requested signatures */ signatures?: Signature[]; } /** * a JSONRPC-Request with N3-Extension */ export interface RPCRequest { /** * the version */ jsonrpc: '2.0'; /** * the method to call * example: eth_getBalance */ method: string; /** * the identifier of the request * example: 2 */ id?: number | string; /** * the params * example: 0xe36179e2286ef405e929C90ad3E70E649B22a945,latest */ params?: any[]; /** * the IN3-Config */ in3?: IN3RPCRequestConfig; } /** * a JSONRPC-Responset with N3-Extension */ export interface RPCResponse { /** * the version */ jsonrpc: '2.0'; /** * the id matching the request * example: 2 */ id: string | number; /** * in case of an error this needs to be set */ error?: string; /** * the params * example: 0xa35bc */ result?: any; /** * the IN3-Result */ in3?: IN3ResponseConfig; /** * the node handling this response (internal only) */ in3Node?: IN3NodeConfig; } /** * a List of nodes */ export interface ServerList { /** * last Block number */ lastBlockNumber?: number; /** * the list of nodes */ nodes: IN3NodeConfig[]; /** * IN3 Registry */ contract?: string; /** * number of servers */ totalServers?: number; proof?: Proof; } /** * Verified ECDSA Signature. Signatures are a pair (r, s). Where r is computed as the X coordinate of a point R, modulo the curve order n. */ export interface Signature { /** * the address of the signing node * example: 0x6C1a01C2aB554930A937B0a2E8105fB47946c679 */ address?: string; /** * the blocknumber * example: 3123874 */ block: number; /** * the hash of the block * example: 0x6C1a01C2aB554930A937B0a212346037E8105fB47946c679 */ blockHash: string; /** * hash of the message * example: 0x9C1a01C2aB554930A937B0a212346037E8105fB47946AB5D */ msgHash: string; /** * Positive non-zero Integer signature.r * example: 0x72804cfa0179d648ccbe6a65b01a6463a8f1ebb14f3aff6b19cb91acf2b8ec1f */ r: string; /** * Positive non-zero Integer signature.s * example: 0x6d17b34aeaf95fee98c0437b4ac839d8a2ece1b18166da704b86d8f42c92bbda */ s: string; /** * Calculated curve point, or identity element O. * example: 28 */ v: number; } export declare const validationDef: { IN3NodeWeight: { description: string; type: string; properties: { weight: { description: string; type: string; example: number; }; responseCount: { description: string; type: string; example: number; }; avgResponseTime: { description: string; type: string; example: number; }; pricePerRequest: { description: string; type: string; }; lastRequest: { description: string; type: string; example: number; }; blacklistedUntil: { description: string; type: string; example: number; }; }; }; IN3NodeConfig: { description: string; type: string; required: string[]; properties: { index: { description: string; type: string; example: number; }; address: { description: string; type: string; format: string; example: string; }; timeout: { description: string; type: string; example: number; }; url: { description: string; type: string; example: string; }; chainIds: { description: string; example: string[]; type: string; items: { type: string; format: string; }; }; deposit: { description: string; type: string; example: number; }; capacity: { description: string; type: string; example: number; }; props: { description: string; type: string; example: number; }; }; }; IN3RPCRequestConfig: { description: string; required: string[]; properties: { chainId: { description: string; type: string; example: string; format: string; }; includeCode: { description: string; type: string; example: boolean; }; verifiedHashes: { description: string; type: string; items: { type: string; format: string; }; }; latestBlock: { description: string; type: string; example: number; }; useRef: { description: string; type: string; }; useBinary: { description: string; type: string; }; useFullProof: { description: string; type: string; }; finality: { description: string; type: string; }; verification: { description: string; type: string; enum: string[]; example: string; }; clientSignature: { description: string; }; signatures: { description: string; type: string; example: string[]; items: { type: string; format: string; }; }; }; }; Signature: { description: string; type: string; required: string[]; properties: { address: { type: string; description: string; format: string; example: string; }; block: { type: string; description: string; example: number; }; blockHash: { type: string; description: string; example: string; format: string; }; msgHash: { type: string; description: string; format: string; example: string; }; r: { type: string; description: string; format: string; example: string; }; s: { type: string; description: string; format: string; example: string; }; v: { type: string; description: string; format: string; example: number; }; }; }; IN3ResponseConfig: { type: string; description: string; properties: { proof: { description: string; type: string; required: string[]; properties: { type: { description: string; type: string; enum: string[]; example: string; }; block: { type: string; description: string; example: string; }; finalityBlocks: { type: string; description: string; example: string[]; }; transactions: { type: string; description: string; example: any[]; }; uncles: { type: string; description: string; example: any[]; }; merkleProof: { type: string; description: string; exmaple: string[]; items: { type: string; pattern: string; }; }; merkleProofPrev: { type: string; description: string; exmaple: string[]; items: { type: string; pattern: string; }; }; txProof: { type: string; description: string; items: { type: string; pattern: string; }; }; logProof: { description: string; type: string; additionalProperties: { type: string; required: string[]; properties: { number: { description: string; type: string; }; block: { description: string; type: string; example: string; }; allReceipts: { description: string; type: string; }; receipts: { description: string; type: string; additionalProperties: { type: string; required: string[]; properties: { txHash: { type: string; description: string; }; txIndex: { type: string; description: string; }; txProof: { type: string; description: string; items: { type: string; pattern: string; }; }; proof: { type: string; description: string; items: { type: string; pattern: string; }; }; }; }; }; }; }; }; accounts: { type: string; description: string; additionalProperties: { type: string; description: string; required: string[]; properties: { accountProof: { type: string; description: string; items: { type: string; pattern: string; }; }; address: { type: string; description: string; pattern: string; }; balance: { type: string; description: string; pattern: string; }; codeHash: { type: string; description: string; pattern: string; }; code: { type: string; description: string; pattern: string; }; nonce: { type: string; description: string; pattern: string; }; storageHash: { type: string; description: string; pattern: string; }; storageProof: { type: string; description: string; items: { type: string; required: string[]; properties: { key: { type: string; description: string; pattern: string; }; proof: { type: string; description: string; items: { type: string; pattern: string; }; }; value: { type: string; description: string; pattern: string; }; }; }; }; }; }; }; txIndex: { type: string; description: string; example: number; }; signatures: { type: string; description: string; items: { description: string; type: string; required: string[]; properties: { address: { type: string; description: string; format: string; example: string; }; block: { type: string; description: string; example: number; }; blockHash: { type: string; description: string; example: string; format: string; }; msgHash: { type: string; description: string; format: string; example: string; }; r: { type: string; description: string; format: string; example: string; }; s: { type: string; description: string; format: string; example: string; }; v: { type: string; description: string; format: string; example: number; }; }; }; }; }; }; lastNodeList: { description: string; type: string; example: number; }; lastValidatorChange: { description: string; type: string; }; currentBlock: { description: string; type: string; example: number; }; }; }; ChainSpec: { type: string; description: string; properties: { engine: { description: string; type: string; }; validatorContract: { description: string; type: string; }; validatorList: { description: string; type: string; }; }; }; IN3Config: { description: string; type: string; required: string[]; properties: { cacheTimeout: { type: string; description: string; }; nodeLimit: { description: string; type: string; example: number; }; keepIn3: { description: string; type: string; example: boolean; }; format: { description: string; type: string; enum: string[]; example: string; }; key: { description: string; example: string; }; autoConfig: { description: string; type: string; example: boolean; }; retryWithoutProof: { description: string; type: string; example: boolean; }; maxAttempts: { description: string; type: string; example: number; }; includeCode: { description: string; type: string; example: boolean; }; maxCodeCache: { description: string; type: string; example: number; }; maxBlockCache: { description: string; type: string; example: number; }; verifiedHashes: { description: string; type: string; items: { type: string; format: string; }; }; proof: { description: string; type: string; enum: string[]; example: boolean; }; signatureCount: { description: string; type: string; example: number; }; minDeposit: { type: string; description: string; example: number; }; replaceLatestBlock: { description: string; type: string; example: number; }; requestCount: { type: string; min: number; default: number; description: string; example: number; }; finality: { type: string; min: number; max: number; default: number; description: string; example: number; }; timeout: { type: string; min: number; default: number; description: string; example: number; }; chainId: { type: string; pattern: string; description: string; example: string; }; chainRegistry: { type: string; pattern: string; description: string; example: string; }; mainChain: { type: string; pattern: string; description: string; example: string; }; autoUpdateList: { type: string; description: string; example: boolean; }; cacheStorage: { description: string; }; loggerUrl: { type: string; description: string; }; rpc: { type: string; description: string; }; servers: { type: string; description: string; additionalProperties: { type: string; properties: { verifier: { type: string; description: string; }; name: { type: string; description: string; }; chainSpec: { description: string; type: string; properties: { engine: { description: string; type: string; }; validatorContract: { description: string; type: string; }; validatorList: { description: string; type: string; }; }; }; initAddresses: { description: string; type: string; example: string[]; items: { type: string; }; }; lastBlock: { type: string; description: string; example: number; }; contract: { type: string; description: string; example: string; }; needsUpdate: { type: string; description: string; }; contractChain: { type: string; description: string; example: string; }; nodeList: { description: string; type: string; items: { description: string; type: string; required: string[]; properties: { index: { description: string; type: string; example: number; }; address: { description: string; type: string; format: string; example: string; }; timeout: { description: string; type: string; example: number; }; url: { description: string; type: string; example: string; }; chainIds: { description: string; example: string[]; type: string; items: { type: string; format: string; }; }; deposit: { description: string; type: string; example: number; }; capacity: { description: string; type: string; example: number; }; props: { description: string; type: string; example: number; }; }; }; }; nodeAuthorities: { description: string; type: string; example: string[]; items: { type: string; }; }; weights: { description: string; type: string; additionalProperties: { description: string;