{"bugs":{"url":"https://github.com/streamr-dev/streamr-client-protocol-js/issues"},"dist":{"shasum":"1d0a490a7690bd4877f24fb9addbb318ff984709","tarball":"https://registry.npmjs.org/streamr-client-protocol/-/streamr-client-protocol-5.0.0-beta.16.tgz","fileCount":147,"integrity":"sha512-LI4Yw5iK+UI4hhU+HQqiZl+4FxX9J7Ii8pcH1Q5PwBTurcwBXDUH4fX7l0WGK8XSUzt6EHgiBuHrhPefkwIz+Q==","signatures":[{"sig":"MEQCIFVIKei6uXT9rBkltyKhaREo9ZvDwNJmlUWBcoiRDAa1AiAu+EAQSt7SZUHxh3PMBcIN1EjS0ahJuchieKQBKy9Ryg==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":2061594,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJfKUgaCRA9TVsSAnZWagAAPCYP+gNzlEnNcPgEhA+CZDlr\n9rkriwjHCIa0hd1GA2/MPhypdaGVL1uxBlsVTqMYOhZP3Lkbg3FQdYlW/6fy\nQk0DuxtdDIdXKyctoPfFwYLnBEcWgMl21WtGgX+cncB5Rwio0dsmGHvZfZcE\noXySQhM3T2mhfybY8rE7yT6hdNngKzsj37c5lNCJ3YHaewDL/AXR3DGoVdaI\nOzaKjCQgwyhKeHfGRrYjaZRdh3CE78vicXrt52X+tuyb5bxFpTSnenMecpr3\njFsNZsL7FaJcKqj9V2eNK5zFACtc24yRJyP3t8SfYy90+6dHrrgajK5oLmuE\nPJPqQLOEgSQmfzjLFcUT3v46BIDZt+8QEkNVykD0jXKw63Ry5nJv3EUp56Y4\nCl1QlmzR2pwdapDcs3+TJKavH4gNjNLBVx0nHjjs7js1UDDM9uEth2pOcAgN\nX6XSZ+vNNnT9arTUokM4lbxqZCvS1tYx7+t2F3grxVDtopd6XWIbDJvMUWCn\nRS38/Mp1toYbx5dfrALP6NUdp1YnW9E7FFCgfZ1EHJ+Jjbn8Edke0By0bmAF\nZ0m4h5ynr4MjH7FOzYBwMYOolWdFB96qDgf+Mpwgk3REa/4J2H51KrnyI9TF\np3oCWdcotO1l0rfHAPNtfvSmSjYU7QnRVYH9ONS0ey6GXI3mqE8QUtPIESsw\nAWoU\r\n=AYhQ\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":"[![Build Status](https://travis-ci.com/streamr-dev/streamr-client-protocol-js.svg?branch=master)](https://travis-ci.com/streamr-dev/streamr-client-protocol-js)\n\nThis repository contains ES6 JS implementations of the Streamr [protocol](https://github.com/streamr-dev/streamr-specs/blob/master/PROTOCOL.md) messages. This is shared code used by:\n \n - [streamr-client-javascript](https://github.com/streamr-dev/streamr-client-javascript)\n - [broker](https://github.com/streamr-dev/broker)\n - [network](https://github.com/streamr-dev/network)\n \n This package is available on npm as `streamr-client-protocol`.\n\n### Usage\n\nThis section describes how to use the Javascript implementation of the [protocol](https://github.com/streamr-dev/streamr-specs/blob/master/PROTOCOL.md).\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## Publishing\n\nPublishing to NPM is automated via Github Actions. Follow the steps below to publish `latest` or `beta`.\n\n### Publishing `latest`:\n1. 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. \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\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":"a4606a792d6c6f4d9fa65b564fe02ad545511432","license":"Apache-2.0","scripts":{"dev":"webpack --progress --colors --watch","test":"jest","build":"NODE_ENV=production webpack","eslint":"eslint src/** test/**","prepare":"npm run build","pretest":"npm run eslint"},"_npmUser":{"name":"mirpo","email":"miroslavpokrovskiy@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.6","description":"JavaScript classes implementing the Streamr client-to-node protocol","directories":{"test":"test"},"maintainers":[{"name":"fonty1","email":"mr.matto@gmail.com"},{"name":"harbu","email":"harbuzen@gmail.com"},{"name":"hpihkala","email":"henri.pihkala@streamr.com"},{"name":"jtakalai","email":"juuso.takalainen@streamr.com"},{"name":"juhah","email":"juha.haavisto@streamr.com"},{"name":"juslesan","email":"santeri.juslenius@gmail.com"},{"name":"jwolff","email":"jwolff@isentropy.com"},{"name":"kare","email":"kare.nuorteva@me.com"},{"name":"mariusz_io","email":"mariusz@mariusz.io"},{"name":"mirpo","email":"miroslavpokrovskiy@gmail.com"},{"name":"mk_streamr","email":"mikhael.santos@streamr.com"},{"name":"mmartinmo","email":"martin.moravek@streamr.com"},{"name":"mthambipillai","email":"melkiorthambipillai@gmail.com"},{"name":"pzsavola","email":"petri.savolainen@spaceify.net"},{"name":"streamr-dev","email":"devtools@streamr.com"},{"name":"timoxley","email":"secoif@gmail.com"},{"name":"tumppi","email":"tuomas.koponen@streamr.com"}],"_nodeVersion":"12.18.3","dependencies":{"heap":"^0.2.6","sha3":"^2.1.2","debug":"^4.1.1","core-js":"^3.6.5","secp256k1":"^4.0.1","eventemitter3":"^4.0.0","promise-memoize":"^1.2.1","@babel/runtime-corejs3":"^7.9.6"},"_hasShrinkwrap":false,"readmeFilename":"README.md","devDependencies":{"jest":"^26.0.1","sinon":"^9.0.2","eslint":"^6.8.0","ethers":"^4.0.47","webpack":"^4.43.0","@babel/cli":"^7.8.4","babel-jest":"^26.0.1","@babel/core":"^7.9.0","await-sleep":"0.0.1","webpack-cli":"^3.3.11","babel-eslint":"^10.1.0","babel-loader":"^8.1.0","array-shuffle":"^1.0.1","eslint-loader":"^4.0.2","webpack-merge":"^4.2.2","@babel/preset-env":"^7.9.5","web3-eth-accounts":"^1.2.7","eslint-config-airbnb":"^18.1.0","eslint-plugin-import":"^2.20.2","eslint-plugin-promise":"^4.2.1","terser-webpack-plugin":"^3.0.0","webpack-node-externals":"^1.7.2","eslint-config-streamr-nodejs":"^1.3.0","@babel/plugin-transform-classes":"^7.9.5","@babel/plugin-transform-runtime":"^7.9.0","babel-plugin-add-module-exports":"^1.0.2","@babel/plugin-proposal-class-properties":"^7.8.3","babel-plugin-transform-class-properties":"^6.24.1","@babel/plugin-transform-modules-commonjs":"^7.9.0"},"_npmOperationalInternal":{"tmp":"tmp/streamr-client-protocol_5.0.0-beta.16_1596540954352_0.435892073389607","host":"s3://npm-registry-packages"},"_id":"streamr-client-protocol@5.0.0-beta.16","version":"5.0.0-beta.16"}