{"_id":"wasm-metering","_rev":"8-f1fc7d40841f113640468fc21e9e3e84","name":"wasm-metering","description":"injects metering into webassembly binaries","dist-tags":{"latest":"0.2.1"},"versions":{"0.0.0":{"name":"wasm-metering","version":"0.0.0","description":"This is a prototype that injects metering into wasm code","main":"index.js","scripts":{"coverage":"istanbul cover ./tests/index.js","coveralls":"npm run coverage && coveralls <coverage/lcov.info","lint":"standard","test":"tape ./tests/index.js"},"bin":{"injectMetering":"./bin/injectMetering.js"},"author":{"name":"mjbecze","email":"mjbecze@riseup.net"},"license":"MPL-2.0","dependencies":{"wast-codegen":"^0.4.1","wast-graph":"^1.1.0","wast-parser":"^0.17.0","yargs":"^4.3.1"},"devDependencies":{"coveralls":"^2.11.9","istanbul":"^0.4.2","standard":"^6.0.8","tape":"^4.5.1"},"gitHead":"f59127389d75fb8c3c468fe5e611c34f8ff1868f","_id":"wasm-metering@0.0.0","_shasum":"657f8576df90623cc7db99c0b39bf90022a721fa","_from":".","_npmVersion":"3.8.5","_nodeVersion":"5.10.1","_npmUser":{"name":"null_radix","email":"null_radix@riseup.net"},"dist":{"shasum":"657f8576df90623cc7db99c0b39bf90022a721fa","tarball":"https://registry.npmjs.org/wasm-metering/-/wasm-metering-0.0.0.tgz","integrity":"sha512-ATkTUmsAnrOq/mCj5rnwHKHbl/K4fKw6DrhqIAS2WO5971YfyXm2y0orlgyRZ70b6E80NpVllcimETzshIrhyg==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCE1DjdC6JnF4WpdcC74FYg8OAANGp9o7iSa5D/qDbmcgIgJV2zrgw3NaPhw69kFivGb/O8MzLZvo3nXvacJFCYLEs="}]},"maintainers":[{"name":"null_radix","email":"null_radix@riseup.net"}],"_npmOperationalInternal":{"host":"packages-16-east.internal.npmjs.com","tmp":"tmp/wasm-metering-0.0.0.tgz_1460564924335_0.16610279423184693"},"directories":{}},"0.1.0":{"name":"wasm-metering","version":"0.1.0","description":"injects metering into webassembly binaries","main":"index.js","scripts":{"coverage":"node --harmony ./node_modules/istanbul/lib/cli.js cover ./test/index.js","coveralls":"npm run coverage && coveralls <coverage/lcov.info","lint":"standard","test":"node --harmony ./test/index.js"},"author":{"name":"mjbecze","email":"mjbecze@gmail.com"},"license":"MPL-2.0","dependencies":{"leb128":"0.0.0","wasm-json-toolkit":"0.1.0"},"devDependencies":{"coveralls":"^2.11.4","istanbul":"^0.4.1","standard":"^8.6.0","tape":"^4.6.3"},"keywords":["wasm","metering","webassembly"],"repository":{"type":"git","url":"git+https://github.com/ewasm/wasm-metering.git"},"bugs":{"url":"https://github.com/ewasm/wasm-metering/issues"},"homepage":"https://github.com/ewasm/wasm-metering","standard":{"ignore":["test/wabt"]},"gitHead":"86b7126f82eddc1535a165f6296ce828389f24a4","_id":"wasm-metering@0.1.0","_shasum":"4377ef1b8934bfdb809b0bccce5fb503b1d64b37","_from":".","_npmVersion":"3.10.9","_nodeVersion":"8.0.0-pre","_npmUser":{"name":"null_radix","email":"null_radix@riseup.net"},"dist":{"shasum":"4377ef1b8934bfdb809b0bccce5fb503b1d64b37","tarball":"https://registry.npmjs.org/wasm-metering/-/wasm-metering-0.1.0.tgz","integrity":"sha512-d4LGh0K3shWZPV1eGFzDUTuhBEyPQuRrvuEgtruKpC3WEVsd/Qa0KY+/txKIblhnGSjCCqbUiJQQkarD+POG2w==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIFT7GS3GNmWr0PgQBKZoDt/ety3Z+qYV+mr+kdazddulAiEA4nUL6xvbFCHGQCACNH8LHfRMxxHUsowVSJfNbIIL9AA="}]},"maintainers":[{"name":"null_radix","email":"null_radix@riseup.net"}],"_npmOperationalInternal":{"host":"packages-12-west.internal.npmjs.com","tmp":"tmp/wasm-metering-0.1.0.tgz_1482381974619_0.2506207684054971"},"directories":{}},"0.1.1":{"name":"wasm-metering","version":"0.1.1","description":"injects metering into webassembly binaries","main":"index.js","scripts":{"coverage":"node --harmony ./node_modules/istanbul/lib/cli.js cover ./test/index.js","coveralls":"npm run coverage && coveralls <coverage/lcov.info","lint":"standard","test":"node --harmony ./test/index.js"},"author":{"name":"mjbecze","email":"mjbecze@gmail.com"},"license":"MPL-2.0","dependencies":{"leb128":"0.0.0","wasm-json-toolkit":"0.1.0"},"devDependencies":{"coveralls":"^2.11.4","istanbul":"^0.4.1","standard":"^8.6.0","tape":"^4.6.3"},"keywords":["wasm","metering","webassembly"],"repository":{"type":"git","url":"git+https://github.com/ewasm/wasm-metering.git"},"bugs":{"url":"https://github.com/ewasm/wasm-metering/issues"},"homepage":"https://github.com/ewasm/wasm-metering","standard":{"ignore":["test/wabt"],"globals":["WebAssembly"]},"gitHead":"246f3fc7e479630f8e034ee20b41b7adb92ba4f9","_id":"wasm-metering@0.1.1","_shasum":"6c064fecaf74d79e3d75c4421dac8afcb90dcba4","_from":".","_npmVersion":"3.10.9","_nodeVersion":"8.0.0-pre","_npmUser":{"name":"null_radix","email":"null_radix@riseup.net"},"dist":{"shasum":"6c064fecaf74d79e3d75c4421dac8afcb90dcba4","tarball":"https://registry.npmjs.org/wasm-metering/-/wasm-metering-0.1.1.tgz","integrity":"sha512-Rmiz1OAN7wU5wJewNq/VaEoD4Uk3NKqG95fP0w+qII/PFZ9NOU7v2n1H0D1EIJss48dCBVjdEm8Gi9N80yTldA==","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQDP9RVhueUphzV8lSOxfLc7CgMZWIQfvPPCkDY0V6KQ0QIhAKHHE5hPrFInJzQsJoALGqmyGyspb7jbJx3fhhNcCm5U"}]},"maintainers":[{"name":"null_radix","email":"null_radix@riseup.net"}],"_npmOperationalInternal":{"host":"packages-18-east.internal.npmjs.com","tmp":"tmp/wasm-metering-0.1.1.tgz_1482451484256_0.2662783812265843"},"directories":{}},"0.2.0":{"name":"wasm-metering","version":"0.2.0","description":"injects metering into webassembly binaries","main":"index.js","scripts":{"coveralls":"npm run coverage && nyc report --reporter=text-lcov | coveralls","coverage":"nyc npm test","lint":"standard","test":"node --harmony ./test/index.js"},"bin":{"wasm-meter":"./bin/wasm-meter"},"author":{"name":"mjbecze","email":"mjbecze@gmail.com"},"contributors":[{"name":"Alex Beregszaszi","email":"alex@rtfs.hu"}],"license":"MPL-2.0","dependencies":{"leb128":"^0.0.4","wasm-json-toolkit":"0.2.3"},"devDependencies":{"coveralls":"^3.0.0","nyc":"^11.6.0","standard":"^11.0.0","tape":"^4.9.0"},"keywords":["wasm","metering","webassembly"],"repository":{"type":"git","url":"git+https://github.com/ewasm/wasm-metering.git"},"bugs":{"url":"https://github.com/ewasm/wasm-metering/issues"},"homepage":"https://github.com/ewasm/wasm-metering","standard":{"ignore":["test/wabt"],"globals":["WebAssembly"]},"gitHead":"98a5da77e110f5b1d0d2b1b749147bc9e36f6b55","_id":"wasm-metering@0.2.0","_npmVersion":"5.8.0","_nodeVersion":"9.10.1","_npmUser":{"name":"null_radix","email":"null_radix@riseup.net"},"dist":{"integrity":"sha512-a0F2aDc+4EarK8DS7vEFWqjkw0yDofw8SHFzLjyT9ENBLzPjLTTydz9bK0T+GaH9mfs2vN7KaY6nASClbUIvqQ==","shasum":"e4135193a08d893d4b6f1868082dae7136f0139d","tarball":"https://registry.npmjs.org/wasm-metering/-/wasm-metering-0.2.0.tgz","fileCount":1537,"unpackedSize":13838548,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIDrNsrFP/Vk6etyBEnElm3T9qQBJtncAaRLbsaFAPojgAiAOAW8643InLX52Zsls5jro9KIIKwWYSWfoZ9UHnTTP2g=="}]},"maintainers":[{"name":"null_radix","email":"null_radix@riseup.net"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/wasm-metering_0.2.0_1522967477480_0.7145009114435474"},"_hasShrinkwrap":false},"0.2.1":{"name":"wasm-metering","version":"0.2.1","description":"injects metering into webassembly binaries","main":"index.js","scripts":{"coveralls":"npm run coverage && nyc report --reporter=text-lcov | coveralls","coverage":"nyc npm test","lint":"standard","test":"node --harmony ./test/index.js"},"bin":{"wasm-meter":"./bin/wasm-meter"},"author":{"name":"mjbecze","email":"mjbecze@gmail.com"},"contributors":[{"name":"Alex Beregszaszi","email":"alex@rtfs.hu"}],"license":"MPL-2.0","dependencies":{"leb128":"^0.0.4","wasm-json-toolkit":"0.2.3"},"devDependencies":{"coveralls":"^3.0.0","nyc":"^11.6.0","standard":"^11.0.0","tape":"^4.9.0"},"keywords":["wasm","metering","webassembly"],"repository":{"type":"git","url":"git+https://github.com/ewasm/wasm-metering.git"},"bugs":{"url":"https://github.com/ewasm/wasm-metering/issues"},"homepage":"https://github.com/ewasm/wasm-metering","standard":{"ignore":["test/wabt"],"globals":["WebAssembly"]},"gitHead":"7b75f6dde9773189c8d7ff5b6fa3cf80ffca764a","_id":"wasm-metering@0.2.1","_npmVersion":"5.8.0","_nodeVersion":"9.10.1","_npmUser":{"name":"null_radix","email":"null_radix@riseup.net"},"dist":{"integrity":"sha512-YDlTPY4jspknNyDaVBQhLTuTYBh+39qI0P9F0grmR88NR4oh7qfgpTwZ2ly4oX2hHCj9KlIwhy2Yyez+3/wY2Q==","shasum":"08220896e5e74b4ee3286636fd31d84e40544083","tarball":"https://registry.npmjs.org/wasm-metering/-/wasm-metering-0.2.1.tgz","fileCount":3720,"unpackedSize":20825906,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIE0+JMX+Eux2N0XAhpnjIZjoefzNYRcezhCd8oQJgZmHAiBcN5SWcoRCBi6gHbUoo4+R+S60/B/uq68uncz+fVHZjQ=="}]},"maintainers":[{"name":"null_radix","email":"null_radix@riseup.net"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/wasm-metering_0.2.1_1523056674248_0.5657921489865896"},"_hasShrinkwrap":false}},"readme":"# SYNOPSIS \n\n[![NPM Package](https://img.shields.io/npm/v/wasm-metering.svg?style=flat-square)](https://www.npmjs.org/package/wasm-metering)\n[![Build Status](https://img.shields.io/travis/ewasm/wasm-metering.svg?branch=master&style=flat-square)](https://travis-ci.org/ewasm/wasm-metering)\n[![Coverage Status](https://img.shields.io/coveralls/ewasm/wasm-metering.svg?style=flat-square)](https://coveralls.io/r/ewasm/wasm-metering)\n\n[![js-standard-style](https://cdn.rawgit.com/feross/standard/master/badge.svg)](https://github.com/feross/standard)  \n\nInjects metering into webassembly binaries. The metering counts computation\ntime for a given program in units of `gas`. The metered wasm binary expects an \nimport that functions as the gas counter. This works for binary version 0x1.\nFor a more detailed description of how this works see [metering.md](https://github.com/ewasm/design/blob/master/metering.md)\n\n# INSTALL\n`npm install wasm-metering`\n\n# USAGE\n```javascript\nconst fs = require('fs')\nconst metering = require('wasm-metering')\n\nconst wasm = fs.readFileSync('fac.wasm')\nconst meteredWasm = metering.meterWASM(wasm, {\n  meterType: 'i32'\n})\n\nconst limit = 90000000\nlet gasUsed = 0\n\nconst mod = WebAssembly.Module(meteredWasm.module)\nconst instance = WebAssembly.Instance(mod, {\n  'metering': {\n    'usegas': (gas) => {\n      gasUsed += gas\n      if (gasUsed > limit) {\n        throw new Error('out of gas!')\n      }\n    }\n  }\n})\n\nconst result = instance.exports.fac(6)\nconsole.log(`result:${result}, gas used ${gasUsed * 1e-4}`) // result:720, gas used 0.4177\n```\n[Source](./example/index.js)\n\n# API\n## meterJSON\n\n[./index.js:104-224](https://github.com/ewasm/wasm-metering/blob/5ab76de89bc07d0abfaa6d0c776c204a752a0d9d/./index.js#L104-L224 \"Source code on GitHub\")\n\nInjects metering into a JSON output of [wasm2json](https://github.com/ewasm/wasm-json-toolkit#wasm2json)\n\n**Parameters**\n\n-   `json` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** the json tobe metered\n-   `opts` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** \n    -   `opts.costTable` **\\[[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)]** the cost table to meter with. See these notes about the default. (optional, default `defaultTable`)\n    -   `opts.moduleStr` **\\[[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]** the import string for the metering function (optional, default `'metering'`)\n    -   `opts.fieldStr` **\\[[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]** the field string for the metering function (optional, default `'usegas'`)\n    -   `opts.meterType` **\\[[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]** the register type that is used to meter. Can be `i64`, `i32`, `f64`, `f32` (optional, default `'i64'`)\n\nReturns **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** the metered json\n\n## meterWASM\n\n[./index.js:236-240](https://github.com/ewasm/wasm-metering/blob/5ab76de89bc07d0abfaa6d0c776c204a752a0d9d/./index.js#L236-L240 \"Source code on GitHub\")\n\nInjects metering into a webassembly binary\n\n**Parameters**\n\n-   `json` **[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)** the json tobe metered\n-   `opts` **\\[[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)](default {})** \n    -   `opts.costTable` **\\[[Object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object)]** the cost table to meter with. See these notes about the default. (optional, default `defaultTable`)\n    -   `opts.moduleStr` **\\[[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]** the import string for the metering function (optional, default `'metering'`)\n    -   `opts.fieldStr` **\\[[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]** the field string for the metering function (optional, default `'usegas'`)\n    -   `opts.meterType` **\\[[String](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)]** the register type that is used to meter. Can be `i64`, `i32`, `f64`, `f32` (optional, default `'i64'`)\n-   `wasm`  \n\nReturns **[Buffer](https://nodejs.org/api/buffer.html)** \n\n## costTable\n\nThe costTable option defines the cost of each of the operations.\nCost Tables consist of an object whose keys are sections in a wasm binary. \nFor example\n```\nmodule.exports = {\n  'start': 1,\n  'type': {\n    'params': {\n      'DEFAULT': 1\n    },\n    'return_type': {\n      'DEFAULT': 1\n    }\n  },\n  'import': 1,\n  'code': {\n    'locals': {\n      'DEFAULT': 1\n    },\n    'code': {\n      'DEFAULT': 1\n    }\n  },\n  'memory': (entry) => {\n    return entry.maximum * 10\n  },\n  'data': 5\n}\n\n```\n\nKeys can either map to a function which will be given that section's entries or\nan integer which will be used as the cost for each entry or an object whose\nkeys are matched against the [JSON representation](https://github.com/ewasm/wasm-json-toolkit) of the code.\nThe default cost table used is from [here](https://github.com/ewasm/design/blob/master/determining_wasm_gas_costs.md)\n\nThe cost table can use a special key 'DEFAULT' that will be used as the cost value for any fields in a section that are not defined.\n\n## Initial Cost\nThe Initial cost for instantation for the module is calculated from all the \nsections other than the code section (which is metered at runtime). This information is\nstored as a [custom section](https://github.com/WebAssembly/design/blob/master/BinaryEncoding.md#name-section)\nthat is inserted directly after the preamble. It uses the the name `initCost` and\nits payload contains the initial cost encoded as an unsigned leb128 interger.\n\n# LICENSE\n[MPL-2.0](https://tldrlegal.com/license/mozilla-public-license-2.0-(mpl-2))\n","maintainers":[{"name":"null_radix","email":"null_radix@riseup.net"}],"time":{"modified":"2022-06-28T21:54:11.175Z","created":"2016-04-13T16:28:45.953Z","0.0.0":"2016-04-13T16:28:45.953Z","0.1.0":"2016-12-22T04:46:17.317Z","0.1.1":"2016-12-23T00:04:44.957Z","0.2.0":"2018-04-05T22:31:17.781Z","0.2.1":"2018-04-06T23:17:54.589Z"},"author":{"name":"mjbecze","email":"mjbecze@gmail.com"},"license":"MPL-2.0","readmeFilename":"README.md","homepage":"https://github.com/ewasm/wasm-metering","keywords":["wasm","metering","webassembly"],"repository":{"type":"git","url":"git+https://github.com/ewasm/wasm-metering.git"},"bugs":{"url":"https://github.com/ewasm/wasm-metering/issues"},"contributors":[{"name":"Alex Beregszaszi","email":"alex@rtfs.hu"}]}