{"bugs":{"url":"https://github.com/streamr-dev/streamr-client-protocol-js/issues"},"dist":{"shasum":"088ae25ee2a0fe820ffcf6bef556cc64e8c30c2a","tarball":"https://registry.npmjs.org/streamr-client-protocol/-/streamr-client-protocol-6.0.4-alpha.1.tgz","fileCount":167,"integrity":"sha512-DJorQetpp+zW3DAKaUfY6erx1HkPF+rz4TVLU4lgDNmOQeJZuLsIFkKuTlBev/kH8Rx7p0jxp+pQ5BzsBcRYeg==","signatures":[{"sig":"MEUCIHrIeFP4blxg1YpAkwvBpJU7jGfWRWcbC1ndKUUnj5PbAiEA3UZ6qPvrDPCgGEV0vMn+tBuXdlfKb4lDjVnGWiIC79g=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":4868393,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.13\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfuDU3CRA9TVsSAnZWagAA7rQP/im7sjNewFtbMxdAcTTh\nLZTjReDDXEi29VYEuVP4kp/repDjQ4YdF4qCIJ0fmAt/ribyjTF/ZBwibC83\ny3uXNjAAIJK3OmVvYyAgIB6uXNzpzdbkeYjJ+vZZCdRCAaGBsO73SU8Ynl6e\nWhF7F/Z9mfOdLk4vwQrFWnxSbPnt2IR/+jZWhN86J8kGYxvUp0empQT13EjZ\nGqGZXbnUg84pSBqm+Rh+3qjRtZ1U20znmEmo0okf3tTJpoXoqJKyynj2juA7\nwuNDk/Fh57vaPgfRILeVnGlWAOkZqUMfVM2kTcYYk+4pcN/OzmhpNWw4TBdq\n9wql+Ng3tRm2qaC3OV4BpFCQ7G1BgLF9stH/NgLYitj3HYNErqLILMv24GE1\nv/VH8mOxs62n5FSYlgVZIPvsukw224EYasg8j0P9AvYS408B4d3CP28OhDcX\n1amS1FzYC1KMSyOAug1d90PCBL0YRAbBeRtTfX4KVny58HdcJSnfRs/VZQ/G\nYO7bpB/vep/84fb4G9U3wwb8e7iV/ka2DfroC5RqBN5lknwGAYSPXdhctGOP\nS1Nom+CwwWoAYRKIbH4NGolnTmrJZB6Yz9+RNKkZlIJyaPplmWS+9IbW5q5R\nHtHtG3oeY/1ZxC85rXjqtdm1mMoOLrn++vaQAPUY8ew+cNLEPorxmecgAYOw\nYTY6\r\n=U5J1\r\n-----END PGP SIGNATURE-----\r\n"},"main":"dist/streamr-client-protocol.js","name":"streamr-client-protocol","author":{"name":"Streamr"},"module":"src/index.js","readme":"# streamr-client-protocol\n\nES6 JS implementations of [Streamr Protocol](https://github.com/streamr-dev/streamr-specs/blob/master/PROTOCOL.md) messages. This is shared code used by (at least):\n \n - [streamr-client-javascript](https://github.com/streamr-dev/streamr-client-javascript)\n - [streamr-broker](https://github.com/streamr-dev/streamr-broker)\n - [streamr-network](https://github.com/streamr-dev/streamr-network)\n \n The package is available on npm as `streamr-client-protocol`.\n \n ## Table of Contents\n- [Use](#use)\n- [Release](#release)\n\n## Use\n\n#### Creating messages from arguments\n\nEvery message type from both the Control Layer and the Message Layer is defined as a class and has a static `create` method that takes class-specific arguments to build an instance of the latest version of the message type. The arguments for each message type are defined in the [protocol documentation](https://github.com/streamr-dev/streamr-specs/blob/master/PROTOCOL.md) and in the definition of the `create` method.\n\nThis example shows how to create a `StreamMessage` and encapsulate it in a `PublishRequest`.\n\n```javascript\nconst streamMessage = new StreamMessage({\n    messageId: new MessageID(...),\n    content\n})\nconst publishRequest = new PublishRequest({\n    requestId: 'requestId', \n    streamMessage, \n})\n```\n\n#### Serializing messages to strings\n\nEvery message type from both the Control Layer and the Message Layer has a `serialize` method, which takes as argument the version to serialize to. By default, it serializes to the latest version of the message type. The `serialize` methods return a string.\n\n```javascript\nconst streamMessage = new StreamMessage({...})\nstreamMessage.serialize() // to latest version\n// > '[31,[\"streamId\",0,1529549961116,\"publisherId\",\"msgChainId\"],null,27,0,{\"foo\":\"bar\"},0,null]'\nstreamMessage.serialize(30) // to MessageLayer version 30\n// > '[30,[\"streamId\",0,1529549961116,\"publisherId\",\"msgChainId\"],null,27,{\"foo\":\"bar\"},0,null]'\n\nconst subscribeRequest = new SubscribeRequest({\n    streamId: 'streamId', \n    streamPartition: 0, \n    sessionToken: 'sessionToken',\n})\nsubscribeRequest.serialize() // to latest version\n// > '[2,9,\"requestId\",\"streamId\",0,\"sessionToken\"]'\nsubscribeRequest.serialize(1) // to ControlLayer version 1\n// > '[1,9,\"streamId\",0,\"sessionToken\"]'\n```\n\n#### Parsing messages from strings\n\nFor deserialization, use the static `deserialize` method that is present in `ControlMessage` for the ControlLayer and `StreamMessage` for the Message Layer. The `deserialize` method accepts both strings and arrays as input.\n\n```javascript\nconst serializedStreamMessage = '[30,[\"streamId\",0,1529549961116,\"publisherId\",\"msgChainId\"],null,27,{\"foo\":\"bar\"},0,null]'\nconst streamMessage = StreamMessage.deserialize(serializedStreamMessage)\n``` \n\nOn the other hand, the Control Layer has many different message types. So we can only know that the `deserialize` method will return a `ControlMessage`. We can use the `type` field to differentiate.\n\n```javascript\nconst serializedMessage = '[1,9,\"streamId\",0,\"sessionToken\"]'\nconst controlMessage = ControlMessage.deserialize(serializedMessage)\nif (controlMessage.type === ControlMessage.TYPES.UnicastMessage) {\n    //treat it as a UnicastMessage\n} else if (controlMessage.type === ControlMessage.TYPES.SubscribeRequest) {\n    //treat it as a SubscribeRequest\n} else if (...) {\n    \n} else {\n    throw new Error(`Unknown type: ${controlMessage.type}`)\n}\n```\n\n## Release\n\nPublishing to NPM is automated via Github Actions. Follow the steps below to publish stable (`latest`) or `beta`.\n\n### Publishing stable (latest)\n1. `git checkout master && git pull`\n2. Update version with either `npm version [patch|minor|major]`. Use semantic versioning\nhttps://semver.org/. Files package.json and package-lock.json will be automatically updated, and an appropriate git commit and tag created. \n3. `git push --follow-tags`\n4. Wait for Github Actions to run tests\n5. If tests passed, Github Actions will publish the new version to NPM\n\n### Publishing beta\n1. Update version with either `npm version [prepatch|preminor|premajor] --preid=beta`. Use semantic versioning\nhttps://semver.org/. Files package.json and package-lock.json will be automatically updated, and an appropriate git commit and tag created. \n2. `git push --follow-tags`\n3. Wait for Github Actions to run tests\n4. If tests passed, Github Actions will publish the new version to NPM\n","engines":{"node":">= 10"},"gitHead":"520d0e4823c8638c9ecd31fccffd4271d2040727","license":"Apache-2.0","scripts":{"dev":"webpack --progress --colors --watch","test":"jest","build":"rm dist/*; NODE_ENV=production webpack --mode=production --progress","eslint":"eslint .","prepare":"npm run build","pretest":"npm run eslint","coverage":"jest --coverage","benchmark":"jest test/benchmarks --detectOpenHandles","test-unit":"jest test/unit --detectOpenHandles","test-integration":"jest test/integration --detectOpenHandles"},"_npmUser":{"name":"timoxley","email":"secoif@gmail.com"},"homepage":"https://github.com/streamr-dev/streamr-client-protocol-js#readme","repository":{"url":"git://github.com/streamr-dev/streamr-client-protocol-js.git","type":"git"},"_npmVersion":"6.14.8","description":"JavaScript classes implementing the Streamr client-to-node protocol","directories":{"test":"test"},"maintainers":[{"name":"teogeb","email":"teo@streamr.com"},{"name":"streamr-dev","email":"devtools@streamr.com"},{"name":"jwolff","email":"jwolff@isentropy.com"},{"name":"jtakalai","email":"juuso.takalainen@streamr.com"},{"name":"juslesan","email":"santeri.juslenius@gmail.com"},{"name":"mmartinmo","email":"martin.moravek@streamr.com"},{"name":"pzsavola","email":"petri.savolainen@spaceify.net"},{"name":"kare","email":"kare.nuorteva@me.com"},{"name":"juhah","email":"juha.haavisto@streamr.com"},{"name":"fonty1","email":"mr.matto@gmail.com"},{"name":"hpihkala","email":"henri.pihkala@streamr.com"},{"name":"tumppi","email":"tuomas.koponen@streamr.com"},{"name":"timoxley","email":"secoif@gmail.com"},{"name":"harbu","email":"harbuzen@gmail.com"},{"name":"mariusz_io","email":"mariusz@mariusz.io"}],"_nodeVersion":"14.12.0","dependencies":{"heap":"^0.2.6","sha3":"^2.1.3","debug":"^4.2.0","ethers":"^5.0.14","core-js":"^3.6.5","secp256k1":"^4.0.2","eventemitter3":"^4.0.7","promise-memoize":"^1.2.1","@babel/runtime-corejs3":"^7.11.2"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jest":"^26.4.2","sinon":"^9.0.3","eslint":"^7.9.0","webpack":"^4.44.2","@babel/cli":"^7.11.6","babel-jest":"^26.3.0","@babel/core":"^7.11.6","await-sleep":"0.0.1","webpack-cli":"^3.3.12","babel-eslint":"^10.1.0","babel-loader":"^8.1.0","array-shuffle":"^1.0.1","eslint-loader":"^4.0.2","webpack-merge":"^5.1.4","@babel/preset-env":"^7.11.5","web3-eth-accounts":"^1.3.0","eslint-config-airbnb":"^18.2.0","eslint-plugin-import":"^2.22.0","eslint-plugin-promise":"^4.2.1","terser-webpack-plugin":"^4.2.2","webpack-node-externals":"^2.5.2","eslint-config-streamr-nodejs":"^1.3.0","@babel/plugin-transform-classes":"^7.10.4","@babel/plugin-transform-runtime":"^7.11.5","babel-plugin-add-module-exports":"^1.0.4","@babel/plugin-proposal-class-properties":"^7.10.4","babel-plugin-transform-class-properties":"^6.24.1","@babel/plugin-transform-modules-commonjs":"^7.10.4"},"_npmOperationalInternal":{"tmp":"tmp/streamr-client-protocol_6.0.4-alpha.1_1605907766876_0.688283091718696","host":"s3://npm-registry-packages"},"_id":"streamr-client-protocol@6.0.4-alpha.1","version":"6.0.4-alpha.1"}