{"bugs":{"url":"https://github.com/streamr-dev/streamr-client/issues"},"dist":{"shasum":"65c490f206111e8b7012a425bbb017ababb0033c","tarball":"https://registry.npmjs.org/streamr-client/-/streamr-client-6.1.0-beta.1.tgz","fileCount":264,"integrity":"sha512-WX6+aXsQzVeGbEZqEqbI356rd2NZyBdZeRCL3JFTTH7Rc6GX/QNsVoXTHd+oqGRveux8i0d3fseTpGIcBl4qjQ==","signatures":[{"sig":"MEUCIDmnM5SQJ2gwbydg7AtVLrq9h85jHXuxVW1beQA203tvAiEA0utRKOSLKhspovhHKU+ygyGc3tG2ZEQmWXwrMdnu5Ok=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":22693540,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v4.10.10\r\nComment: https://openpgpjs.org\r\n\r\nwsFzBAEBCAAGBQJizpjAACEJED1NWxICdlZqFiEECWMYAoorWMhJKdjhPU1b\r\nEgJ2Vmqi5g/8DuytkArflerIcjKnZBy1SbpaZgGzbXmYpyBEZhICpyQ3c4IV\r\naqOBGEnDUrDxZYl004I8+yhFgJw+/aSHMsxzj/pFivsrFG6wnK+3Zcmp+u+s\r\nd5GXwdKh/pqlYcHKVk+nGwCVmgNv+Y82hqX4tVcOUx4hOSJrxef1Sz+ombrz\r\nFz3nqYEeUooVF3br9wnw5LMAFy/oCr3DJc1MgbsdGVGZ+pzbaXkjgF3Yb1wg\r\nqDn7YnVvfjgRTP8tpKur8L533+1xonQ1+8muPurQn3GIiRxErSyIFTPMU1w5\r\nekYfZnVuMTqP2keDEuYTf990WSW/Srbe4+JToIEwZm26x1ZAcsvaHgZAk7rm\r\nhwD/S2NW5tlbfWLeTFD3SywJ1D8G1ypAqvzqaA16ZjdHgE/mMLcMSI1sepXB\r\nXPpm8t2N0R8iaN8/Sgg52BM2of50fHuO0QtMbH4I1CPz3sl+g8yzjcSP3R5d\r\nRMYX2A8sF3/yysY8WPub5oSt6TqjZezS7V8UA45NM0zUqASTNZi18f33LeOq\r\n8g1jthpZdGH6vnxGrn53NPtWilwhotN7gsJ2Nm7iu1cDXuNgJC1A207CUGe0\r\n5lpURkG9OFxXz/ujE9hCdkQ3nEOZwm4xdlpwYA8BuVYPKI/092lTB2seJh3m\r\nWwTYVqsNoQDarrVOpDg+MvBE8NsabG1JiKU=\r\n=Dikr\r\n-----END PGP SIGNATURE-----\r\n"},"main":"./src/index-commonjs.js","name":"streamr-client","types":"./types/src/index.d.ts","author":{"name":"Streamr"},"readme":"<p align=\"center\">\n  <a href=\"https://streamr.network\">\n    <img alt=\"Streamr\" src=\"https://raw.githubusercontent.com/streamr-dev/network-monorepo/main/packages/client/readme-header-img.png\" width=\"1320\" />\n  </a>\n</p>\n\n<h1 align=\"left\">\n  Streamr JavaScript Client\n</h1>\n\n[![Build status](https://github.com/streamr-dev/monorepo/actions/workflows/client-build.yml/badge.svg)](https://github.com/streamr-dev/monorepo/actions/workflows/client-build.yml)\n![latest npm package version](https://img.shields.io/npm/v/streamr-client?label=latest)\n![GitHub stars](https://img.shields.io/github/stars/streamr-dev/network-monorepo?style=social)\n[![Discord Chat](https://img.shields.io/discord/801574432350928907.svg?label=Discord&logo=Discord&colorB=7289da)](https://discord.gg/FVtAph9cvz)\n\nThis library allows you to easily interact with the [Streamr Network](https://streamr.network) from JavaScript-based environments, such as browsers and [node.js](https://nodejs.org). The library wraps a Streamr light node for publishing and subscribing to messages, as well as contains convenience functions for creating and managing streams.\n\n| If you are using the Streamr Client in Node, NodeJS version `16.13.x` and NPM version `8.x` is required |\n| --- |\n\nPlease see the [Streamr project docs](https://streamr.network/docs) for more detailed documentation.\n\n## Contents\n- [Getting started](#getting-started)\n    - [Subscribing](#subscribing)\n    - [Publishing](#publishing)\n- [Setup](#setup)\n- [Usage](#usage)\n    - [Client creation](#client-creation)\n    - [Creating a stream](#creating-a-stream)\n    - [Subscribing to a stream](#subscribing-to-a-stream)\n    - [Publishing to a stream](#publishing-to-a-stream)\n    - [Requesting historical messages](#requesting-historical-messages)\n    - [Searching for streams](#searching-for-streams)\n    - [Interacting with the `Stream` object](#interacting-with-the-stream-object)\n    - [Enabling storage](#enabling-storage)\n    - [Data Unions](#data-unions)\n    - [Utility functions](#utility-functions)\n- [Advanced usage](#advanced-usage)\n    - [Stream partitioning](#stream-partitioning)\n    - [Disable message ordering and gap filling](#disable-message-ordering-and-gap-filling)\n    - [Proxy publishing](#proxy-publishing)\n    - [Logging](#logging)\n\n## Getting started\n\n### Subscribing\n```js \nconst streamId = 'streamr.eth/demos/helsinki-trams'\n\nstreamr.subscribe(streamId, (message) => {\n    // handle for individual messages\n})\n\n```\n\n### Publishing\n```js \n// Requires MATIC tokens (Polygon blockchain gas token)\nconst stream = await streamr.createStream({\n    id: '/foo/bar'\n})\n\nawait stream.publish({ timestamp: Date.now() })\n```\n\n\nMore examples can be found in the [examples repo](https://github.com/streamr-dev/examples).\n___\n\n\n## Setup\n\n### Installation\nThe client is available on [npm](https://www.npmjs.com/package/streamr-client) and can be installed simply by:\n\n```\nnpm install streamr-client\n```\n\n### Importing `streamr-client`\nTo use with react please see [streamr-client-react](https://github.com/streamr-dev/streamr-client-react)\n\nIf using TypeScript you can import the library with:\n```js\nimport { StreamrClient } from 'streamr-client'\n```\nIf using Node.js you can import the library with:\n\n```js\nconst { StreamrClient } = require('streamr-client')\n```\n\nFor usage in the browser include the latest build, e.g. by including a `<script>` tag pointing at a CDN:\n\n```html\n<script src=\"https://unpkg.com/streamr-client@latest/streamr-client.web.js\"></script>\n```\n___\n## Usage\n### Client creation\nIn Streamr, Ethereum accounts are used for identity. You can generate an Ethereum private key using any Ethereum wallet, or you can use the utility function [`StreamrClient.generateEthereumAccount()`](#utility-functions), which returns the address and private key of a fresh Ethereum account. A private key is not required if you are only subscribing to public streams on the Network. \n\n```js\nconst streamr = new StreamrClient({\n    auth: {\n        privateKey: 'your-private-key'\n    }\n})\n```\n\nAuthenticating with an Ethereum private key contained in an Ethereum (web3) provider (e.g. MetaMask):\n```js\nconst streamr = new StreamrClient({\n    auth: {\n        ethereum: window.ethereum,\n    }\n})\n```\n\nYou can also create an anonymous client instance that can interact with public streams:\n```js\nconst streamr = new StreamrClient()\n```\n\n### Creating a stream\n```js\n// Requires MATIC tokens (Polygon blockchain gas token)\nconst stream = await streamr.createStream({\n    id: '/foo/bar'\n})\n\nconsole.log(stream.id) // e.g. `0x12345.../foo/bar`\n```\n\nYou can also create a stream by defining the address in the provided id. Please note that the creation will only succeed if you specify the same address as provided for authentication when creating the `streamr` instance:\n```js\n// Requires MATIC tokens (Polygon blockchain gas token)\nconst stream = await client.createStream({\n    id: `${address}/foo/bar`\n})\n\nconsole.log(stream.id) // e.g. `0x12345.../foo/bar`\n```\n\nMore information on Stream IDs can be found under the [stream creation project docs](https://streamr.network/docs/streams/creating-streams)\n\n### Subscribing to a stream\n```js\nconst subscription = await streamr.subscribe(\n    streamId, \n    (content, metadata) => { ... }\n)\n```\nThe callback's first parameter, `content`, will contain the value given to the `publish` method. \n\nThe second parameter `metadata` is of type `StreamMessage`. It contains metadata about the message, e.g. timestamp. \n\nUnsubscribing from an existent subscription:\n```js\nawait streamr.unsubscribe(streamId)\n// or, unsubscribe them all:\nconst streams = await streamr.unsubscribe()\n```\n\nGetting all streams the client is subscribed to:\n```js\nconst subscriptions = streamr.getSubscriptions()\n```\n### Publishing to a stream\n\n```js\n// Here's our example data point\nconst msg = {\n    temperature: 25.4,\n    humidity: 10,\n    happy: true\n}\n\n// Publish using the stream id only\nawait streamr.publish(streamId, msg)\n\n// Publish with a specific timestamp as a Date object (default is now)\nawait streamr.publish(streamId, msg, new Date(1546300800123))\n\n// Publish with a specific timestamp in ms\nawait streamr.publish(streamId, msg, 1546300800123)\n\n// Publish with a specific timestamp as a ISO8601 string\nawait streamr.publish(streamId, msg, '2019-01-01T00:00:00.123Z')\n\n// For convenience, stream.publish(...) equals streamr.publish(stream, ...)\nawait stream.publish(msg)\n```\n\n### Requesting historical messages\nBy default `subscribe` will not request historical messages.\n\nYou can fetch historical messages with the `resend` method:\n```js\n// Fetches the last 10 messages stored for the stream\nconst resend1 = await streamr.resend(\n    streamId,\n    {\n        last: 10,\n    }, \n    onMessage\n)\n```\n\nAlternatively you can fetch historical messages and subscribe to real-time messages:\n```js\n// Fetches the last 10 messages and subscribes to the stream\nconst sub1 = await streamr.subscribe({\n    id: streamId,\n    resend: {\n        last: 10,\n    }\n}, onMessage)\n```\nIn order to fetch historical messages the stream needs to have [storage enabled](#enabling-storage).\n\nResend from a specific timestamp up to the newest message:\n```js\nconst sub2 = await streamr.resend(\n    streamId,\n    {\n        from: {\n            timestamp: (Date.now() - 1000 * 60 * 5), // 5 minutes ago\n            sequenceNumber: 0, // optional\n        },\n        publisher: '0x12345...', // optional\n    }\n)\n```\nResend a range of messages:\n```js\nconst sub3 = await streamr.resend(\n    streamId,\n    {\n        from: {\n            timestamp: (Date.now() - 1000 * 60 * 10), // 10 minutes ago\n        },\n        to: {\n            timestamp: (Date.now() - 1000 * 60 * 5), // 5 minutes ago\n        },\n        // when using from and to the following parameters are optional\n        // but, if specified, both must be present\n        publisher: '0x12345...', \n        msgChainId: 'ihuzetvg0c88ydd82z5o', \n    }\n)\n```\nIf you choose one of the above resend options when subscribing, you can listen on the completion of this resend by doing the following:\n\n```js\nconst sub = await streamr.subscribe(options)\nsub.onResent(() => {\n    console.log('Received all requested historical messages! Now switching to real time!')\n})\n```\n\nNote that only one of the resend options can be used for a particular subscription. \n\n### Searching for streams\nYou can search for streams by specifying a search term:\n```js\nconst streams = await streamr.searchStreams('foo')\n```\nAlternatively or additionally to the search term, you can search for streams based on permissions.\n\nTo get all streams for which a user has any direct permission:\n```js \nconst streams = await streamr.searchStreams('foo', {\n    user: '0x12345...'\n})\n```\nTo get all streams for which a user has any permission (direct or public):\n```js\nconst streams = await streamr.searchStreams('foo', {\n    user: '0x12345...',\n    allowPublic: true\n})\n```\n\nIt is also possible to filter by specific permissions by using `allOf` and `anyOf` properties. The `allOf` property should be preferred over `anyOf` when possible due to better query performance.\n\nIf you want to find the streams you can subscribe to:\n```js \nconst streams = await streamr.searchStreams(undefined, {\n    user: '0x12345...',\n    allOf: [StreamPermission.SUBSCRIBE],\n    allowPublic: true\n})\n```\n___\n### Interacting with the `Stream` object\nThe `Stream` type provides a convenient way to interact with a stream without having to repeatedly pass Stream IDs.\n#### Getting existing streams\n```js\nconst stream = await streamr.getStream(streamId)\n```\n\nThe method getOrCreateStream gets the stream if it exists, and if not, creates it:\n```js\n// May require MATIC tokens (Polygon blockchain gas token)\nconst stream = await streamr.getOrCreateStream({\n    id: streamId\n})\n```\n\n#### Stream permissions\n\nThere are 5 different permissions:\n- StreamPermission.PUBLISH\n- StreamPermission.SUBSCRIBE\n- StreamPermission.EDIT\n- StreamPermission.DELETE\n- StreamPermission.GRANT\n\nYou can import the `StreamPermission` enum with:\n```js\nconst { StreamPermission } = require('streamr-client')\n```\n\nFor each stream + user there can be a permission assignment containing a subset of those permissions. It is also possible to grant public permissions for streams (only `StreamPermission.PUBLISH` and `StreamPermission.SUBSCRIBE`). If a stream has e.g. a public subscribe permissions, it means that anyone can subscribe to that stream.\n\n\nTo grant a permission for a user:\n```js\n// Requires MATIC tokens (Polygon blockchain gas token)\nawait stream.grantPermissions({\n    user: '0x12345...',\n    permissions: [StreamPermission.PUBLISH],\n})\n```\nOr to grant a public permission:\n```js\nawait stream.grantPermissions({\n    public: true,\n    permissions: [StreamPermission.SUBSCRIBE]\n})\n```\nTo revoke a permission from a user:\n```js\n// Requires MATIC tokens (Polygon blockchain gas token)\nawait stream.revokePermissions({\n    user: '0x12345...',\n    permissions: [StreamPermission.PUBLISH]\n})\n```\nOr revoke public permission:\n```js\nawait stream.revokePermissions({\n    public: true,\n    permissions: [StreamPermission.SUBSCRIBE]\n})\n```        \n\n\nThe method `streamr.setPermissions` can be used to set an exact set of permissions for one or more streams. Note that if there are existing permissions for the same users in a stream, the previous permissions are overwritten. Note that this method cannot be used from a stream, but via the `StreamrClient` instance:\n\n```js\n// Requires MATIC tokens (Polygon blockchain gas token)\nawait streamr.setPermissions({\n    streamId,\n    assignments: [\n        {\n            user: '0x11111...',\n            permissions: [StreamPermission.EDIT]\n        }, {\n            user: '0x22222...'\n            permissions: [StreamPermission.GRANT]\n        }, {\n            public: true,\n            permissions: [StreamPermission.PUBLISH, StreamPermission.SUBSCRIBE]\n        }\n    ]\n})\n```\n\nYou can query the existence of a permission with `hasPermission()`. Usually you want to use `allowPublic: true` flag so that also the existence of a public permission is checked:\n```js\nawait stream.hasPermission({\n    permission: StreamPermission.PUBLISH,\n    user: '0x12345...',\n    allowPublic: true\n}\n```\n\nThe full list of permissions for a stream can be queried by calling `stream.getPermissions()`:\n```js\nconst permissions = await stream.getPermissions()\n```\nThe returned value is an array of permissions containing an item for each user, and possibly one for public permissions:\n```js\npermissions = [\n    { user: '0x12345...', permissions: ['subscribe', 'publish'] },\n    { public: true, permissions: ['subscribe']}\n]\n```\n\n#### Updating a stream\nTo update the description of a stream:\n```js\n// Requires MATIC tokens (Polygon blockchain gas token)\nstream.description = 'New description!'\nawait stream.update()\n```\n\n\n#### Deleting a stream\nTo delete a stream:\n```js\n// Requires MATIC tokens (Polygon blockchain gas token)\nawait stream.delete()\n```\n\n\n\n### Enabling storage\n\nYou can enable storage on your streams to retain historical messages and access it later via `resend`. By default storage is not enabled on streams. You can enable it with:\n\n```js\nconst { StreamrClient, STREAMR_STORAGE_NODE_GERMANY } = require('streamr-client')\n...\n// assign a stream to a storage node\nawait stream.addToStorageNode(STREAMR_STORAGE_NODE_GERMANY)\n```\nOther operations with storage:\n```js\n// remove the stream from a storage node\nawait stream.removeFromStorageNode(STREAMR_STORAGE_NODE_GERMANY)\n// fetch the storage nodes for a stream\nconst storageNodes = stream.getStorageNodes()\n```\n\n\n### Data Unions\n> ⚠️ This code examples in this section are not up to date.\n\nThe Data Union framework is a data crowdsourcing and crowdselling solution. Working in tandem with the Streamr Network and Ethereum, the framework powers applications that enable people to earn by sharing valuable data. You can [read more about it here](https://streamr.network/docs/data-unions/intro-to-data-unions)\n\n\nTo deploy a new DataUnion with default [deployment options](#deployment-options):\n```js\nconst dataUnion = await streamr.deployDataUnion()\n```\n\nTo get an existing (previously deployed) `DataUnion` instance:\n```js\nconst dataUnion = await streamr.getDataUnion('0x12345...')\n```\n\n\n#### Admin Functions\n\nAdmin functions require xDai tokens on the xDai network. To get xDai you can either use a [faucet](https://www.xdaichain.com/for-users/get-xdai-tokens/xdai-faucet) or you can reach out on the [Streamr Discord #dev channel](https://discord.gg/gZAm8P7hK8).\n\nAdding members using admin functions is not at feature parity with the member function `join`. The newly added member will not be granted publish permissions to the streams inside the Data Union. This will need to be done manually using, `streamr.grantPermissions()`. Similarly, after removing a member using the admin function `removeMembers`, the publish permissions will need to be removed in a secondary step using `revokePermissions()`.\n\nAdding members:\n```js\nconst receipt = await dataUnion.addMembers([\n    '0x11111...',\n    '0x22222...',\n    '0x33333...',\n])\n```\nRemoving members:\n```js\nconst receipt = await dataUnion.removeMembers([\n    '0x11111...',\n    '0x22222...',\n    '0x33333...',\n])\n```\n\nChecking if an address belongs to the Data Union:\n```js\nconst isMember = await dataUnion.isMember('0x12345...')\n```\n\nSend all withdrawable earnings to the member's address:\n```js\nconst receipt = await dataUnion.withdrawAllToMember('0x12345...')\n```\nSend all withdrawable earnings to the address signed off by the member:\n```js\nconst recipientAddress = '0x22222...'\n\nconst signature = await dataUnion.signWithdrawAllTo(recipientAddress)\nconst receipt = await dataUnion.withdrawAllToSigned(\n    '0x11111...', // member address\n    recipientAddress,\n    signature\n)\n```\nSend some of the withdrawable earnings to the address signed off by the member\n```js\nconst signature = await dataUnion.signWithdrawAllTo(recipientAddress)\nconst receipt = await dataUnion.withdrawAllToSigned(\n    '0x12345...', // member address\n    recipientAddress,\n    signature\n)\n\n// Or to authorize a fixed amount:\nconst receipt = await dataUnion.withdrawAmountToSigned(\n    '0x12345...', // member address\n    recipientAddress, \n    100, // token amount, in wei \n    signature, \n)\n```\n\nSetting a new admin fee:\n```js\n// Any number between 0 and 1, inclusive\nconst receipt = await dataUnion.setAdminFee(0.4) \n```\n#### Query functions\nThese are available for everyone and anyone, to query publicly available info from a Data Union.\n\nGet Data Union's statistics:\n```js\nconst stats = await dataUnion.getStats()\n```\nGet a member's stats:\n```js\nconst memberStats = await dataUnion.getMemberStats('0x12345...')\n```\nGet the withdrawable DATA tokens in the DU for a member:\n```js\n// Returns a BigNumber\nconst balance = await dataUnion.getWithdrawableEarnings('0x12345...')\n```\nGetting the set admin fee:\n```js\nconst adminFee = await dataUnion.getAdminFee()\n```\nGetting admin's address:\n```js\nconst adminAddress = await dataUnion.getAdminAddress()\n```\n\nGetting the Data Union's version:\n```js\nconst version = await dataUnion.getVersion()\n// Can be 0, 1 or 2\n// 0 if the contract is not a data union\n```\n\n#### Withdraw options\n\nThe functions `withdrawAll`, `withdrawAllTo`, `withdrawAllToMember`, `withdrawAllToSigned`, `withdrawAmountToSigned` all can take an extra \"options\" argument. It's an object that can contain the following parameters. The provided values are the default ones, used when not specified or when the options parameter is not provided:\n```js\nconst receipt = await dataUnion.withdrawAll(\n    ...,\n    {\n        sendToMainnet: true, // Whether to send the withdrawn DATA tokens to mainnet address (or sidechain address)\n        payForTransport: true, //Whether to pay for the withdraw transaction signature transport to mainnet over the bridge\n        waitUntilTransportIsComplete: true, // Whether to wait until the withdrawn DATA tokens are visible in mainnet\n        pollingIntervalMs: 1000, // How often requests are sent to find out if the withdraw has completed, in ms\n        retryTimeoutMs: 60000, // When to give up when waiting for the withdraw to complete, in ms\n        gasPrice: /*Network Estimate*/ // Ethereum Mainnet transaction gas price to use when transporting tokens over the bridge\n    }\n)\n```\n\nThese withdraw transactions are sent to the sidechain, so gas price shouldn't be manually set (fees will hopefully stay very low),\nbut a little bit of [sidechain native token](https://www.xdaichain.com/for-users/get-xdai-tokens) is nonetheless required.\n\nThe return values from the withdraw functions also depend on the options.\n\nIf `sendToMainnet: false`, other options don't apply at all, and **sidechain transaction receipt** is returned as soon as the withdraw transaction is done. This should be fairly quick in the sidechain.\n\nThe use cases corresponding to the different combinations of the boolean flags:\n\n| `transport` | `wait`  | Returns | Effect |\n| :---------- | :------ | :------ | :----- |\n| `true`      | `true`  | Transaction receipt | *(default)* Self-service bridge to mainnet, client pays for mainnet gas |\n| `true`      | `false` | Transaction receipt | Self-service bridge to mainnet (but **skip** the wait that double-checks the withdraw succeeded and tokens arrived to destination) |\n| `false`     | `true`  | `null`              | Someone else pays for the mainnet gas automatically, e.g. the bridge operator (in this case the transaction receipt can't be returned) |\n| `false`     | `false` | AMB message hash    | Someone else pays for the mainnet gas, but we need to give them the message hash first |\n\n#### Deployment options\n\n`deployDataUnion` can take an options object as the argument. It's an object that can contain the following parameters. All shown values are the defaults for each property:\n```js\nconst ownerAddress = await streamr.getAddress()\n\nconst dataUnion = await streamr.deployDataUnion({\n    owner: ownerAddress, // Owner / admin of the newly created Data Union\n    joinPartsAgent: [ownerAddress], // Able to add and remove members to/from the Data Union\n    dataUnionName: /* Generated if not provided */, // NOT stored anywhere, only used for address derivation\n    adminFee: 0, // Must be between 0...1 \n    sidechainPollingIntervalMs: 1000, //How often requests are sent to find out if the deployment has completed\n    sidechainRetryTimeoutMs: 60000, // When to give up when waiting for the deployment to complete\n    confirmations: 1, // Blocks to wait after Data Union mainnet contract deployment to consider it final\n    gasPrice: /*Network Estimate*/ // Ethereum Mainnet gas price to use when deploying the Data Union mainnet contract\n})\n```\n\nStreamr Core is added as a `joinPartAgent` by default so that joining with secret works using the member function `join`. If you don't plan to use `join` for \"self-service joining\", you can leave out Streamr Core agent by calling `deployDataUnion` e.g. with your own address as the sole joinPartAgent:\n```js\nconst dataUnion = await streamr.deployDataUnion({\n    joinPartAgents: [ownerAddress],\n    adminFee,\n})\n```\n\n`dataUnionName` option exists purely for the purpose of predicting the addresses of Data Unions not yet deployed. Data Union deployment uses the [CREATE2 opcode](https://eips.ethereum.org/EIPS/eip-1014) which means a Data Union deployed by a particular address with particular \"name\" will have a predictable address.\n\n### Utility functions\nThe static function `StreamrClient.generateEthereumAccount()` generates a new Ethereum private key and returns an object with fields `address` and `privateKey`. \n```js \nconst { address, privateKey } = StreamrClient.generateEthereumAccount()\n```\nIn order to retrieve the client's address an async call must me made to `streamr.getAddress`\n```js\nconst address = await streamr.getAddress()\n```\n\n## Advanced usage\n### Stream partitioning\n\nPartitioning (sharding) enables streams to scale horizontally. This section describes how to use partitioned streams via this library. To learn the basics of partitioning, see [the docs](https://streamr.network/docs/streams#partitioning).\n\n#### A note on stream ids and partitions\nThe public methods of the client generally support the following three ways of defining a stream:\n```js\n// Stream id as a string:\nconst streamId = `${address}/foo/bar`\n\n// Stream id + partition as a string\nconst streamId = `${address}/foo/bar#4`\n\n// Stream id + partition as an object\nconst streamId = { \n    id: `${address}/foo/bar`, \n    partition: 4 \n}\n```\n\n#### Creating partitioned streams\n\nBy default, streams only have 1 partition when they are created. The partition count can be set to any number between 1 and 100. An example of creating a partitioned stream:\n\n```js\n// Requires MATIC tokens (Polygon blockchain gas token)\nconst stream = await streamr.createStream({\n    id: `/foo/bar`,\n    partitions: 10,\n})\nconsole.log(`Stream created: ${stream.id}. It has ${stream.partitions} partitions.`)\n```\n\n#### Publishing to partitioned streams\n\nIn most use cases, a user wants related messages (e.g. messages from a particular device) to be assigned to the same partition, so that the messages retain a deterministic order and reach the same subscriber(s) to allow them to compute stateful aggregates correctly.\n\nYou can specify the partition number as follows:\n```js\nawait streamr.publish({\n    id: `${address}/foo/bar`,\n    partition: 4\n}, msg)\n```\n\nThe library alternatively allows the user to choose a _partition key_, which simplifies publishing to partitioned streams by not requiring the user to assign a partition number explicitly. The same partition key always maps to the same partition. In an IoT use case, the device id can be used as partition key; in user interaction data it could be the user id, and so on.\n\nThe partition key can be given as an argument to the `publish` methods, and the library assigns a deterministic partition number automatically:\n\n```js\nawait stream.publish(\n    msg, \n    Date.now(), \n    msg.vehicleId // msg.vehicleId is the partition key here\n)\n```\n\n#### Subscribing to partitioned streams\n\nBy default, the client subscribes to the first partition (partition `0`) of a stream. Be aware: this behavior will change in the future so that it will subscribe to _all_ partitions by default.\n\nThe partition number can be explicitly given in `subscribe`:\n\n```js\nconst sub = await streamr.subscribe({\n    id: streamId,\n    partition: 4\n}, (content) => {\n    console.log('Got message %o', content)\n})\n```\n\nIf you want to subscribe to multiple partitions:\n```js\nconst onMessage = (content, streamMessage) => {\n    console.log('Got message %o from partition %d', content, streamMessage.getStreamPartition())\n}\n\nawait Promise.all([2, 3, 4].map(async (partition) => {\n    await streamr.subscribe({\n        id: streamId,\n        partition,\n    }, onMessage)\n}))\n```\n\n### Disable message ordering and gap filling\nIf your use case tolerates missing messages and message arriving out-of-order, you can turn off message ordering and gap filling when creating a instance of the client:\n```js\nconst streamr = new StreamrClient({\n    auth: { ... },\n    orderMessages: false,\n    gapFill: false\n})\n```\nBoth of these properties should be disabled in tandem for message ordering and gap filling to be properly turned off.\n\nBy disabling message ordering your application won't perform any filling nor sorting, dispatching messages as they come (faster) but without granting their collective integrity.\n\n\n### Proxy publishing\n\nIn some cases the client might be interested in publishing messages without participating in the stream's message propagation. With this option the nodes can sign all messages they publish by themselves. Alternatively, a client could open a WS connection to a broker node and allow the broker to handle signing with its private key.\n\nProxy publishing is done on the network overlay level. This means that there is no need to know the IP address of the node that will be used as a proxy. Instead, the node needs to know the ID of the network node it wants to connect to. It is not possible to set publish proxies for a stream that is already being \"traditionally\" subscribed or published to and vice versa.\n\n```js\n// Open publish proxy to a node on stream\nawait publishingClient.setPublishProxy(stream, '0x12345...')\n\n// Open publish proxy to multiple nodes on stream\nawait publishingClient.setPublishProxies(stream, ['0x11111...', '0x22222...'])\n\n// Remove publish proxy to a node on stream\nawait publishingClient.removePublishProxy(stream, '0x12345...')\n\n// Remove publish proxy to multiple nodes on stream\nawait publishingClient.removePublishProxies(stream, ['0x11111...', '0x22222...'])\n```\n\nIMPORTANT: The node that is used as a proxy must have set the option on the network layer to accept incoming proxy connections.\n\n### Logging\n\nThe library supports [debug](https://github.com/visionmedia/debug) for logging.\n\nIn node.js, start your app like this: `DEBUG=StreamrClient* node your-app.js`\n\nIn the browser, set `localStorage.debug = 'StreamrClient*'`\n","browser":"./streamr-client.web.js","engines":{"node":">= 12"},"exports":{"browser":"./streamr-client.web.js","default":{"import":"./src/index-esm.mjs","require":"./src/index-commonjs.js"}},"gitHead":"8c51d4dda6b186fee64b349bc37f173b1e804cc8","license":"Apache-2.0","_npmUser":{"name":"harbu","email":"harbuzen@gmail.com"},"homepage":"https://github.com/streamr-dev/streamr-client#readme","#IMPORTANT":"babel-runtime must be in dependencies, not devDependencies","repository":{"url":"git+https://github.com/streamr-dev/network-monorepo.git","type":"git","directory":"packages/client"},"_npmVersion":"8.7.0","description":"JavaScript client library for Streamr","directories":{},"maintainers":[{"name":"kare","email":"kare.nuorteva@me.com"},{"name":"fonty1","email":"mr.matto@gmail.com"},{"name":"hpihkala","email":"henri.pihkala@streamr.com"},{"name":"tumppi","email":"tuomas.koponen@streamr.com"},{"name":"harbu","email":"harbuzen@gmail.com"},{"name":"mariusz_io","email":"mariusz@mariusz.io"},{"name":"pzsavola","email":"petri.savolainen@spaceify.net"},{"name":"mmartinmo","email":"martin.moravek@streamr.com"},{"name":"juslesan","email":"santeri.juslenius@gmail.com"},{"name":"jtakalai","email":"juuso.takalainen@streamr.com"},{"name":"streamr-dev","email":"devtools@streamr.com"},{"name":"teogeb","email":"teo@streamr.com"},{"name":"samt1803","email":"samt1803@gmail.com"}],"_nodeVersion":"16.14.2","dependencies":{"ajv":"^8.8.2","mem":"^8.1.1","uuid":"^8.3.2","debug":"^4.3.2","lodash":"^4.17.21","split2":"^3.2.2","sqlite":"^4.0.23","core-js":"^3.19.1","p-limit":"^3.1.0","sqlite3":"^5.0.2","tsyringe":"^4.6.0","env-paths":"^2.2.1","p-memoize":"4.0.3","quick-lru":"^6.0.1","bufferutil":"^4.0.5","idb-keyval":"^5.1.5","node-fetch":"^2.6.6","ajv-formats":"^2.1.1","ts-toolbelt":"^9.6.0","@types/debug":"^4.1.7","eventemitter3":"^4.0.7","@babel/runtime":"^7.16.3","utf-8-validate":"^5.0.7","readable-stream":"^3.6.0","streamr-network":"^35.0.5","reflect-metadata":"^0.1.13","@ethersproject/abi":"^5.5.0","@ethersproject/web":"^5.5.0","@ethersproject/bytes":"^5.5.0","@ethersproject/units":"^5.5.0","@ethersproject/wallet":"^5.5.0","node-abort-controller":"^2.0.0","@babel/runtime-corejs3":"^7.16.3","@ethersproject/address":"^5.5.0","streamr-client-protocol":"^12.0.0","@ethersproject/bignumber":"^5.5.0","@ethersproject/constants":"^5.5.0","@ethersproject/contracts":"^5.5.0","@ethersproject/keccak256":"^5.5.0","@ethersproject/providers":"^5.5.0","@ethersproject/transactions":"^5.5.0","@ethersproject/abstract-signer":"^5.5.0"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"cors":"^2.8.5","jest":"^27.2.5","util":"^0.12.4","bytes":"^3.1.1","buffer":"^6.0.3","eslint":"^7.32.0","ethers":"^5.4.7","express":"^4.17.1","process":"^0.11.10","ts-jest":"^27.0.5","typedoc":"^0.22.5","webpack":"^5.64.1","benchmark":"^2.1.4","ts-loader":"^9.2.6","weak-napi":"^2.0.2","nightwatch":"^1.7.12","typescript":"^4.5.2","@babel/core":"^7.16.0","@types/jest":"^27.0.2","@types/node":"^16.10.6","@types/uuid":"^8.3.1","jest-circus":"^27.2.5","webpack-cli":"^4.9.1","babel-loader":"^8.2.3","chromedriver":"^98.0.0","concurrently":"^6.4.0","pretty-bytes":"^5.6.0","@types/lodash":"^4.14.175","@types/split2":"^3.2.1","eslint-loader":"^4.0.2","webpack-merge":"^5.8.0","@types/express":"^4.17.13","@babel/preset-env":"^7.16.4","@types/node-fetch":"^2.5.12","crypto-browserify":"^3.12.0","jest-leak-detector":"^27.3.1","streamr-test-utils":"^2.0.0","@streamr/dev-config":"^1.0.0","babel-plugin-lodash":"^3.3.4","eslint-config-airbnb":"^18.2.1","eslint-plugin-import":"^2.25.3","eslint-plugin-promise":"^5.1.0","lodash-webpack-plugin":"^0.11.6","terser-webpack-plugin":"^5.2.5","webpack-bundle-analyzer":"^4.5.0","@babel/preset-typescript":"^7.16.0","@ethersproject/wordlists":"^5.5.0","@typescript-eslint/parser":"^5.0.0","git-revision-webpack-plugin":"^5.0.0","eslint-config-streamr-nodejs":"^2.0.1","node-polyfill-webpack-plugin":"^1.1.4","@babel/plugin-transform-runtime":"^7.16.4","babel-plugin-add-module-exports":"^1.0.4","@typescript-eslint/eslint-plugin":"^5.0.0","@babel/plugin-proposal-decorators":"^7.16.4","@babel/plugin-transform-modules-commonjs":"^7.16.0","babel-plugin-transform-typescript-metadata":"^0.3.2"},"optionalDependencies":{"bufferutil":"^4.0.5","utf-8-validate":"^5.0.7"},"_npmOperationalInternal":{"tmp":"tmp/streamr-client_6.1.0-beta.1_1657706688444_0.9475764689394952","host":"s3://npm-registry-packages"},"_id":"streamr-client@6.1.0-beta.1","version":"6.1.0-beta.1"}