{
    "$id": "config.schema.json",
    "$schema": "http://json-schema.org/draft-07/schema#",
    "description": "Client configuration format",
    "type": "object",
    "additionalProperties": false,
    "properties": {
        "id": {
            "type": "string"
        },
        "logLevel": {
            "type": "string",
            "enum": [
                "silent",
                "fatal",
                "error",
                "warn",
                "info",
                "debug",
                "trace"
            ],
            "default": "info"
        },
        "auth": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "privateKey": {
                    "type": "string",
                    "format": "ethereum-private-key"
                },
                "address": {
                    "type": "string",
                    "format": "ethereum-address"
                },
                "ethereum": {
                    "type": "object"
                }
            }
        },
        "orderMessages": {
            "type": "boolean",
            "default": true
        },
        "gapFill": {
            "type": "boolean",
            "default": true
        },
        "maxGapRequests": {
            "type": "number",
            "default": 5
        },
        "retryResendAfter": {
            "type": "number",
            "default": 5000
        },
        "gapFillTimeout": {
            "type": "number",
            "default": 5000
        },
        "network": {
            "type": "object",
            "additionalProperties": false,
            "required": [],
            "properties": {
                "id": {
                    "type": "string"
                },
                "acceptProxyConnections": {
                    "type": "boolean",
                    "default": false
                },
                "trackers": {
                    "anyOf": [
                        {
                            "type": "array",
                            "items": {
                                "type": "object",
                                "additionalProperties": false,
                                "required": [
                                    "id",
                                    "http",
                                    "ws"
                                ],
                                "properties": {
                                    "id": {
                                        "type": "string",
                                        "format": "ethereum-address"
                                    },
                                    "http": {
                                        "type": "string",
                                        "format": "uri"
                                    },
                                    "ws": {
                                        "type": "string",
                                        "format": "uri"
                                    }
                                }
                            }
                        },
                        {
                            "type": "object",
                            "required": [
                                "contractAddress"
                            ],
                            "additionalProperties": false,
                            "properties": {
                                "contractAddress": {
                                    "type": "string",
                                    "format": "ethereum-address"
                                }
                            }
                        }
                    ],
                    "default": {
                        "contractAddress": "0xab9BEb0e8B106078c953CcAB4D6bF9142BeF854d"
                    }
                },
                "trackerPingInterval": {
                    "type": "number",
                    "default": 60000
                },
                "trackerConnectionMaintenanceInterval": {
                    "type": "number",
                    "default": 5000
                },
                "webrtcDisallowPrivateAddresses": {
                    "type": "boolean",
                    "default": true
                },
                "newWebrtcConnectionTimeout": {
                    "type": "number",
                    "default": 15000
                },
                "webrtcDatachannelBufferThresholdLow": {
                    "type": "number",
                    "default": 32768
                },
                "webrtcDatachannelBufferThresholdHigh": {
                    "type": "number",
                    "default": 131072
                },
                "webrtcSendBufferMaxMessageCount": {
                    "type": "number",
                    "default": 500
                },
                "webrtcMaxMessageSize": {
                    "type": "number",
                    "default": 1048576
                },
                "webrtcPortRange": {
                    "type": "object",
                    "additionalProperties": false,
                    "required": [
                        "min",
                        "max"
                    ],
                    "properties": {
                        "min": {
                            "type": "number"
                        },
                        "max": {
                            "type": "number"
                        }
                    },
                    "default": {
                        "min": 6000,
                        "max": 65535
                    }
                },
                "disconnectionWaitTime": {
                    "type": "number",
                    "default": 200
                },
                "peerPingInterval": {
                    "type": "number",
                    "default": 30000
                },
                "rttUpdateTimeout": {
                    "type": "number",
                    "default": 15000
                },
                "externalIp": {
                    "type": "string",
                    "format": "ipv4"
                },
                "iceServers": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "required": [
                            "url",
                            "port"
                        ],
                        "additionalProperties": false,
                        "properties": {
                            "url": {
                                "type": "string"
                            },
                            "port": {
                                "type": "number"
                            },
                            "username": {
                                "type": "string"
                            },
                            "password": {
                                "type": "string"
                            },
                            "tcp": {
                                "type": "boolean"
                            }
                        }
                    },
                    "default": [
                        {
                            "url": "stun:stun.streamr.network",
                            "port": 5349
                        },
                        {
                            "url": "turn:turn.streamr.network",
                            "port": 5349,
                            "username": "BrubeckTurn1",
                            "password": "MIlbgtMw4nhpmbgqRrht1Q=="
                        },
                        {
                            "url": "turn:turn.streamr.network",
                            "port": 5349,
                            "username": "BrubeckTurn1",
                            "password": "MIlbgtMw4nhpmbgqRrht1Q==",
                            "tcp": true
                        }
                    ]
                },
                "location": {
                    "type": "object",
                    "additionalProperties": false,
                    "properties": {
                        "latitude": {
                            "type": "number"
                        },
                        "longitude": {
                            "type": "number"
                        },
                        "country": {
                            "type": "string"
                        },
                        "city": {
                            "type": "string"
                        }
                    }
                }
            },
            "default": {}
        },
        "contracts": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "streamRegistryChainAddress": {
                    "type": "string",
                    "format": "ethereum-address",
                    "default": "0x0D483E10612F327FC11965Fc82E90dC19b141641"
                },
                "streamStorageRegistryChainAddress": {
                    "type": "string",
                    "format": "ethereum-address",
                    "default": "0xe8e2660CeDf2a59C917a5ED05B72df4146b58399"
                },
                "storageNodeRegistryChainAddress": {
                    "type": "string",
                    "format": "ethereum-address",
                    "default": "0x080F34fec2bc33928999Ea9e39ADc798bEF3E0d6"
                },
                "mainChainRPCs": {
                    "anyOf": [
                        {
                            "$ref": "#/definitions/chainConnectionInfoList"
                        },
                        {
                            "type": "string",
                            "format": "uri"
                        }
                    ],
                    "default": {
                        "name": "ethereum",
                        "chainId": 1,
                        "rpcs": [
                            {
                                "url": "https://eth-rpc.gateway.pokt.network",
                                "timeout": 120000
                            },
                            {
                                "url": "https://ethereum.publicnode.com",
                                "timeout": 120000
                            },
                            {
                                "url": "https://rpc.ankr.com/eth",
                                "timeout": 120000
                            }
                        ]
                    }
                },
                "streamRegistryChainRPCs": {
                    "$ref": "#/definitions/chainConnectionInfoList",
                    "default": {
                        "name": "polygon",
                        "chainId": 137,
                        "rpcs": [{
                                "url": "https://polygon-rpc.com",
                                "timeout": 120000
                            }, {
                                "url": "https://poly-rpc.gateway.pokt.network/",
                                "timeout": 120000
                            }]
                    }
                },
                "ethereumNetworks": {
                    "type": "object",
                    "default": {
                        "polygon": {
                            "chainId": 137,
                            "highGasPriceStrategy": true
                        }
                    }
                },
                "theGraphUrl": {
                    "type": "string",
                    "format": "uri",
                    "default": "https://api.thegraph.com/subgraphs/name/streamr-dev/streams"
                },
                "maxConcurrentCalls": {
                    "type": "number",
                    "default": 10
                },
                "pollInterval": {
                    "type": "number"
                }
            },
            "default": {}
        },
        "encryption": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "litProtocolEnabled": {
                    "type": "boolean",
                    "default": false
                },
                "litProtocolLogging": {
                    "type": "boolean",
                    "default": false
                },
                "keyRequestTimeout": {
                    "type": "number",
                    "default": 30000
                },
                "maxKeyRequestsPerSecond": {
                    "type": "number",
                    "default": 20
                },
                "rsaKeyLength": {
                    "type": "number",
                    "default": 4096
                }
            },
            "default": {}
        },
        "metrics": {
            "anyOf": [
                {
                    "type": "boolean"
                },
                {
                    "type": "object",
                    "additionalProperties": false,
                    "properties": {
                        "periods": {
                            "type": "array",
                            "items": {
                                "type": "object",
                                "required": [
                                    "streamId",
                                    "duration"
                                ],
                                "properties": {
                                    "id": {
                                        "type": "string"
                                    },
                                    "duration": {
                                        "type": "number"
                                    }
                                }
                            }
                        },
                        "maxPublishDelay": {
                            "type": "number"
                        }
                    }
                }
            ]
        },
        "cache": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "maxSize": {
                    "type": "number",
                    "default": 10000
                },
                "maxAge": {
                    "type": "number",
                    "default": 86400000
                }
            },
            "default": {}
        },
        "_timeouts": {
            "type": "object",
            "additionalProperties": false,
            "properties": {
                "theGraph": {
                    "type": "object",
                    "additionalProperties": false,
                    "properties": {
                        "indexTimeout": {
                            "type": "number",
                            "default": 60000
                        },
                        "indexPollInterval": {
                            "type": "number",
                            "default": 1000
                        },
                        "fetchTimeout": {
                            "type": "number",
                            "default": 30000
                        }
                    },
                    "default": {}
                },
                "storageNode": {
                    "type": "object",
                    "additionalProperties": false,
                    "properties": {
                        "timeout": {
                            "type": "number",
                            "default": 30000
                        },
                        "retryInterval": {
                            "type": "number",
                            "default": 1000
                        }
                    },
                    "default": {}
                },
                "ensStreamCreation": {
                    "type": "object",
                    "additionalProperties": false,
                    "properties": {
                        "timeout": {
                            "type": "number",
                            "default": 180000
                        },
                        "retryInterval": {
                            "type": "number",
                            "default": 1000
                        }
                    },
                    "default": {}
                }
            },
            "default": {}
        }
    },
    "definitions": {
        "rpcProviderConfig": {
            "type": "object",
            "required": [
                "url"
            ],
            "properties": {
                "url": {
                    "type": "string",
                    "format": "uri"
                },
                "user": {
                    "type": "string"
                },
                "password": {
                    "type": "string"
                },
                "allowInsecureAuthentication": {
                    "type": "boolean"
                },
                "timeout": {
                    "type": "number",
                    "default": 120000
                },
                "headers": {
                    "type": "object"
                }
            }
        },
        "chainConnectionInfoList": {
            "type": "object",
            "additionalProperties": false,
            "required": [
                "rpcs",
                "chainId"
            ],
            "properties": {
                "chainId": {
                    "type": "number"
                },
                "name": {
                    "type": "string"
                },
                "rpcs": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "$ref": "#/definitions/rpcProviderConfig"
                    },
                    "minItems": 1
                }
            }
        }
    }
}
