diff --git a/zwaves_demo/.gitignore b/zwaves_demo/.gitignore new file mode 100644 index 0000000..d14071d --- /dev/null +++ b/zwaves_demo/.gitignore @@ -0,0 +1,61 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build + +# Dependency directories +node_modules/ +jspm_packages/ + +# TypeScript v1 declaration files +typings/ + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env + +# next.js build output +.next diff --git a/zwaves_demo/deploy.js b/zwaves_demo/deploy.js new file mode 100644 index 0000000..7b5c672 --- /dev/null +++ b/zwaves_demo/deploy.js @@ -0,0 +1,46 @@ +const fetch = require("node-fetch"); +const { broadcast, waitForTx, setScript, invokeScript } = require("@waves/waves-transactions"); +const { address, base58Encode, publicKey } = require("@waves/waves-crypto"); +const fs = require("fs"); +const {extract_vk} = require("../zwaves_node/lib/index.js"); + + + +const env = process.env; +if (env.NODE_ENV !== 'production') { + require('dotenv').load(); +} + + + + +const seed = env.MNEMONIC; +const rpc = env.WAVES_RPC; +const chainId = env.WAVES_CHAINID; +const dApp = address(env.MNEMONIC, chainId); + +const ridetpl = fs.readFileSync("ride/zwaves.ride", {encoding:"utf8"}); +const transfer_mpc = fs.readFileSync("../zwaves_setup/mpc_params_transfer"); +const accumulator_mpc = fs.readFileSync("../zwaves_setup/mpc_params_accumulator"); + + + + +(async () => { + const ridescript = ridetpl + .replace(`let transferVK=base58''`, `let transferVK=base58'${base58Encode(extract_vk(transfer_mpc))}'`) + .replace(`let utxoAccumulatorVK=base58''`, `let utxoAccumulatorVK=base58'${base58Encode(extract_vk(accumulator_mpc))}'`) + + + let request = await fetch(`${env.WAVES_RPC}utils/script/compile`, { method: "POST", body: ridescript }) + const {script} = await request.json(); + + + let tx = setScript({ script, fee: 1400000, chainId}, seed); + await broadcast(tx, rpc); + await waitForTx(tx.id, { apiBase: rpc }); + + console.log(`Dapp is deployed with public key ${publicKey(seed)}. Specify DAPP property at .env file.`) + + process.exit(); +})(); \ No newline at end of file diff --git a/zwaves_demo/package-lock.json b/zwaves_demo/package-lock.json new file mode 100644 index 0000000..a01d664 --- /dev/null +++ b/zwaves_demo/package-lock.json @@ -0,0 +1,758 @@ +{ + "name": "anonymous-transactions-prototype", + "version": "1.0.0", + "lockfileVersion": 1, + "requires": true, + "dependencies": { + "@types/base64-js": { + "version": "1.2.5", + "resolved": "https://registry.npmjs.org/@types/base64-js/-/base64-js-1.2.5.tgz", + "integrity": "sha1-WCskdhaabLpGCiFNR2x0REHYc9U=" + }, + "@types/bignumber.js": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/@types/bignumber.js/-/bignumber.js-5.0.0.tgz", + "integrity": "sha512-0DH7aPGCClywOFaxxjE6UwpN2kQYe9LwuDQMv+zYA97j5GkOMo8e66LYT+a8JYU7jfmUFRZLa9KycxHDsKXJCA==", + "requires": { + "bignumber.js": "*" + } + }, + "@waves/bignumber": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/@waves/bignumber/-/bignumber-0.0.1.tgz", + "integrity": "sha512-+bQCa8fPCYdkLtwKsKtgbvDD7MzZTv6bc2ZpGMqn9uq+RjO8Qf4XSrs0DVhtWWhCHplkVIqOeS4bzgW1i3P7rw==", + "requires": { + "@types/bignumber.js": "^5.0.0", + "bignumber.js": "^8.1.1" + } + }, + "@waves/marshall": { + "version": "0.9.1", + "resolved": "https://registry.npmjs.org/@waves/marshall/-/marshall-0.9.1.tgz", + "integrity": "sha512-DWBUKDno7ahI4ogMtaTbXujF1j2RoIHK68Xi9ZTd1Tk1FwnSfHXjEnkRLJ7qoRwZibVYmrxiOPN0t+LNkueTnw==", + "requires": { + "@types/base64-js": "^1.2.5", + "@waves/bignumber": "0.0.1", + "@waves/parse-json-bignumber": "^1.0.1", + "base64-js": "^1.3.0" + } + }, + "@waves/parse-json-bignumber": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@waves/parse-json-bignumber/-/parse-json-bignumber-1.0.3.tgz", + "integrity": "sha512-zBHIQUjjMYMQXNQcwJwzNShUZnoTM6JfVJDwa0eDGUVk+JAKVGiXxv/k29Ng9TsIDi97hwVravlPPwfZcy4XXQ==" + }, + "@waves/ts-lib-crypto": { + "version": "1.4.2", + "resolved": "https://registry.npmjs.org/@waves/ts-lib-crypto/-/ts-lib-crypto-1.4.2.tgz", + "integrity": "sha512-jRLN26IaqoEIMxvJtO5geOUc18A1JoSuH9wPuw8wfIBjMq8Mw7Y/k3zT+d99lKuaMED9IrDyGX5bdcxe8FFGsQ==", + "requires": { + "js-sha3": "^0.8.0", + "node-forge": "^0.8.5" + } + }, + "@waves/waves-crypto": { + "version": "3.0.17", + "resolved": "https://registry.npmjs.org/@waves/waves-crypto/-/waves-crypto-3.0.17.tgz", + "integrity": "sha512-2YZ7KxH3npZhdXMGnw59orvm8FRhok8kQ91ex1/VJG/ZmtR16/S94ujqb6sf4vrrNB3+BryDStrSWeBeoYxHoQ==", + "requires": { + "crypto-js": "^3.1.9-1" + } + }, + "@waves/waves-transactions": { + "version": "3.25.0", + "resolved": "https://registry.npmjs.org/@waves/waves-transactions/-/waves-transactions-3.25.0.tgz", + "integrity": "sha512-ddo/Go+hd5+0m2qglwhseSXrfhXVN24cx+60xLYD7ojz2Gw2Zk4cLU9ikXrCRPTk/qRvMFiWwlsaVPCGpB4QGg==", + "requires": { + "@waves/marshall": "^0.9.1", + "@waves/ts-lib-crypto": "^1.4.1", + "axios": "^0.19.0" + } + }, + "abstract-leveldown": { + "version": "6.0.3", + "resolved": "https://registry.npmjs.org/abstract-leveldown/-/abstract-leveldown-6.0.3.tgz", + "integrity": "sha512-jzewKKpZbaYUa6HTThnrl+GrJhzjEAeuc7hTVpZdzg7kupXZFoqQDFwyOwLNbmJKJlmzw8yiipMPkDiuKkT06Q==", + "requires": { + "level-concat-iterator": "~2.0.0", + "xtend": "~4.0.0" + } + }, + "ansi-regex": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-4.1.0.tgz", + "integrity": "sha512-1apePfXM1UOSqw0o9IiFAovVz9M5S1Dg+4TrDwfMewQ6p/rmMueb7tWZjQ1rx4Loy1ArBggoqGpfqqdI4rondg==" + }, + "ansi-styles": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-3.2.1.tgz", + "integrity": "sha512-VT0ZI6kZRdTh8YyJw3SMbYm/u+NqfsAxEpWO0Pf9sq8/e94WxxOpPKx9FR1FlyCtOVDNOQ+8ntlqFxiRc+r5qA==", + "requires": { + "color-convert": "^1.9.0" + } + }, + "assert": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/assert/-/assert-2.0.0.tgz", + "integrity": "sha512-se5Cd+js9dXJnu6Ag2JFc00t+HmHOen+8Q+L7O9zI0PqQXr20uk2J0XQqMxZEeo5U50o8Nvmmx7dZrl+Ufr35A==", + "requires": { + "es6-object-assign": "^1.1.0", + "is-nan": "^1.2.1", + "object-is": "^1.0.1", + "util": "^0.12.0" + } + }, + "axios": { + "version": "0.19.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-0.19.2.tgz", + "integrity": "sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==", + "requires": { + "follow-redirects": "1.5.10" + } + }, + "base64-js": { + "version": "1.3.1", + "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.3.1.tgz", + "integrity": "sha512-mLQ4i2QO1ytvGWFWmcngKO//JXAQueZvwEKtjgQFM4jIK0kU+ytMfplL8j+n5mspOfjHwoAg+9yhb7BwAHm36g==" + }, + "bignumber.js": { + "version": "8.1.1", + "resolved": "https://registry.npmjs.org/bignumber.js/-/bignumber.js-8.1.1.tgz", + "integrity": "sha512-QD46ppGintwPGuL1KqmwhR0O+N2cZUg8JG/VzwI2e28sM9TqHjQB10lI4QAaMHVbLzwVLLAwEglpKPViWX+5NQ==" + }, + "camelcase": { + "version": "5.3.1", + "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-5.3.1.tgz", + "integrity": "sha512-L28STB170nwWS63UjtlEOE3dldQApaJXZkOI1uMFfzf3rRuPegHaHesyee+YxQ+W6SvRDQV6UrdOdRiR153wJg==" + }, + "cliui": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/cliui/-/cliui-5.0.0.tgz", + "integrity": "sha512-PYeGSEmmHM6zvoef2w8TPzlrnNpXIjTipYK780YswmIP9vjxmd6Y2a3CB2Ks6/AU8NHjZugXvo8w3oWM2qnwXA==", + "requires": { + "string-width": "^3.1.0", + "strip-ansi": "^5.2.0", + "wrap-ansi": "^5.1.0" + } + }, + "color-convert": { + "version": "1.9.3", + "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-1.9.3.tgz", + "integrity": "sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==", + "requires": { + "color-name": "1.1.3" + } + }, + "color-name": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.3.tgz", + "integrity": "sha1-p9BVi9icQveV3UIyj3QIMcpTvCU=" + }, + "crypto-js": { + "version": "3.1.9-1", + "resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-3.1.9-1.tgz", + "integrity": "sha1-/aGedh/Ad+Af+/3G6f38WeiAbNg=" + }, + "debug": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", + "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", + "requires": { + "ms": "2.0.0" + } + }, + "decamelize": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz", + "integrity": "sha1-9lNNFRSCabIDUue+4m9QH5oZEpA=" + }, + "deferred-leveldown": { + "version": "5.3.0", + "resolved": "https://registry.npmjs.org/deferred-leveldown/-/deferred-leveldown-5.3.0.tgz", + "integrity": "sha512-a59VOT+oDy7vtAbLRCZwWgxu2BaCfd5Hk7wxJd48ei7I+nsg8Orlb9CLG0PMZienk9BSUKgeAqkO2+Lw+1+Ukw==", + "requires": { + "abstract-leveldown": "~6.2.1", + "inherits": "^2.0.3" + }, + "dependencies": { + "abstract-leveldown": { + "version": "6.2.2", + "resolved": "https://registry.npmjs.org/abstract-leveldown/-/abstract-leveldown-6.2.2.tgz", + "integrity": "sha512-/a+Iwj0rn//CX0EJOasNyZJd2o8xur8Ce9C57Sznti/Ilt/cb6Qd8/k98A4ZOklXgTG+iAYYUs1OTG0s1eH+zQ==", + "requires": { + "level-concat-iterator": "~2.0.0", + "level-supports": "~1.0.0", + "xtend": "~4.0.0" + } + } + } + }, + "define-properties": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/define-properties/-/define-properties-1.1.3.tgz", + "integrity": "sha512-3MqfYKj2lLzdMSf8ZIZE/V+Zuy+BgD6f164e8K2w7dgnpKArBDerGYpM46IYYcjnkdPNMjPk9A6VFB8+3SKlXQ==", + "requires": { + "object-keys": "^1.0.12" + } + }, + "dotenv": { + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-6.2.0.tgz", + "integrity": "sha512-HygQCKUBSFl8wKQZBSemMywRWcEDNidvNbjGVyZu3nbZ8qq9ubiPoGLMdRDpfSrpkkm9BXYFkpKxxFX38o/76w==" + }, + "emoji-regex": { + "version": "7.0.3", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-7.0.3.tgz", + "integrity": "sha512-CwBLREIQ7LvYFB0WyRvwhq5N5qPhc6PMjD6bYggFlI5YyDgl+0vxq5VHbMOFqLg7hfWzmu8T5Z1QofhmTIhItA==" + }, + "encoding-down": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/encoding-down/-/encoding-down-6.3.0.tgz", + "integrity": "sha512-QKrV0iKR6MZVJV08QY0wp1e7vF6QbhnbQhb07bwpEyuz4uZiZgPlEGdkCROuFkUwdxlFaiPIhjyarH1ee/3vhw==", + "requires": { + "abstract-leveldown": "^6.2.1", + "inherits": "^2.0.3", + "level-codec": "^9.0.0", + "level-errors": "^2.0.0" + }, + "dependencies": { + "abstract-leveldown": { + "version": "6.2.2", + "resolved": "https://registry.npmjs.org/abstract-leveldown/-/abstract-leveldown-6.2.2.tgz", + "integrity": "sha512-/a+Iwj0rn//CX0EJOasNyZJd2o8xur8Ce9C57Sznti/Ilt/cb6Qd8/k98A4ZOklXgTG+iAYYUs1OTG0s1eH+zQ==", + "requires": { + "level-concat-iterator": "~2.0.0", + "level-supports": "~1.0.0", + "xtend": "~4.0.0" + } + } + } + }, + "errno": { + "version": "0.1.7", + "resolved": "https://registry.npmjs.org/errno/-/errno-0.1.7.tgz", + "integrity": "sha512-MfrRBDWzIWifgq6tJj60gkAwtLNb6sQPlcFrSOflcP1aFmmruKQ2wRnze/8V6kgyz7H3FF8Npzv78mZ7XLLflg==", + "requires": { + "prr": "~1.0.1" + } + }, + "es-abstract": { + "version": "1.17.4", + "resolved": "https://registry.npmjs.org/es-abstract/-/es-abstract-1.17.4.tgz", + "integrity": "sha512-Ae3um/gb8F0mui/jPL+QiqmglkUsaQf7FwBEHYIFkztkneosu9imhqHpBzQ3h1vit8t5iQ74t6PEVvphBZiuiQ==", + "requires": { + "es-to-primitive": "^1.2.1", + "function-bind": "^1.1.1", + "has": "^1.0.3", + "has-symbols": "^1.0.1", + "is-callable": "^1.1.5", + "is-regex": "^1.0.5", + "object-inspect": "^1.7.0", + "object-keys": "^1.1.1", + "object.assign": "^4.1.0", + "string.prototype.trimleft": "^2.1.1", + "string.prototype.trimright": "^2.1.1" + } + }, + "es-to-primitive": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/es-to-primitive/-/es-to-primitive-1.2.1.tgz", + "integrity": "sha512-QCOllgZJtaUo9miYBcLChTUaHNjJF3PYs1VidD7AwiEj1kYxKeQTctLAezAOH5ZKRH0g2IgPn6KwB4IT8iRpvA==", + "requires": { + "is-callable": "^1.1.4", + "is-date-object": "^1.0.1", + "is-symbol": "^1.0.2" + } + }, + "es6-object-assign": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/es6-object-assign/-/es6-object-assign-1.1.0.tgz", + "integrity": "sha1-wsNYJlYkfDnqEHyx5mUrb58kUjw=" + }, + "find-up": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/find-up/-/find-up-3.0.0.tgz", + "integrity": "sha512-1yD6RmLI1XBfxugvORwlck6f75tYL+iR0jqwsOrOxMZyGYqUuDhJ0l4AXdO1iX/FTs9cBAMEk1gWSEx1kSbylg==", + "requires": { + "locate-path": "^3.0.0" + } + }, + "follow-redirects": { + "version": "1.5.10", + "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz", + "integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==", + "requires": { + "debug": "=3.1.0" + } + }, + "function-bind": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", + "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==" + }, + "get-caller-file": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/get-caller-file/-/get-caller-file-2.0.5.tgz", + "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==" + }, + "has": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has/-/has-1.0.3.tgz", + "integrity": "sha512-f2dvO0VU6Oej7RkWJGrehjbzMAjFp5/VKPp5tTpWIV4JHHZK1/BxbFRtf/siA2SWTe09caDmVtYYzWEIbBS4zw==", + "requires": { + "function-bind": "^1.1.1" + } + }, + "has-symbols": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.1.tgz", + "integrity": "sha512-PLcsoqu++dmEIZB+6totNFKq/7Do+Z0u4oT0zKOJNl3lYK6vGwwu2hjHs+68OEZbTjiUE9bgOABXbP/GvrS0Kg==" + }, + "immediate": { + "version": "3.2.3", + "resolved": "https://registry.npmjs.org/immediate/-/immediate-3.2.3.tgz", + "integrity": "sha1-0UD6j2FGWb1lQSMwl92qwlzdmRw=" + }, + "inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + }, + "is-arguments": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/is-arguments/-/is-arguments-1.0.4.tgz", + "integrity": "sha512-xPh0Rmt8NE65sNzvyUmWgI1tz3mKq74lGA0mL8LYZcoIzKOzDh6HmrYm3d18k60nHerC8A9Km8kYu87zfSFnLA==" + }, + "is-callable": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.1.5.tgz", + "integrity": "sha512-ESKv5sMCJB2jnHTWZ3O5itG+O128Hsus4K4Qh1h2/cgn2vbgnLSVqfV46AeJA9D5EeeLa9w81KUXMtn34zhX+Q==" + }, + "is-date-object": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/is-date-object/-/is-date-object-1.0.2.tgz", + "integrity": "sha512-USlDT524woQ08aoZFzh3/Z6ch9Y/EWXEHQ/AaRN0SkKq4t2Jw2R2339tSXmwuVoY7LLlBCbOIlx2myP/L5zk0g==" + }, + "is-fullwidth-code-point": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-2.0.0.tgz", + "integrity": "sha1-o7MKXE8ZkYMWeqq5O+764937ZU8=" + }, + "is-generator-function": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/is-generator-function/-/is-generator-function-1.0.7.tgz", + "integrity": "sha512-YZc5EwyO4f2kWCax7oegfuSr9mFz1ZvieNYBEjmukLxgXfBUbxAWGVF7GZf0zidYtoBl3WvC07YK0wT76a+Rtw==" + }, + "is-nan": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/is-nan/-/is-nan-1.3.0.tgz", + "integrity": "sha512-z7bbREymOqt2CCaZVly8aC4ML3Xhfi0ekuOnjO2L8vKdl+CttdVoGZQhd4adMFAsxQ5VeRVwORs4tU8RH+HFtQ==", + "requires": { + "define-properties": "^1.1.3" + } + }, + "is-number": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==" + }, + "is-regex": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/is-regex/-/is-regex-1.0.5.tgz", + "integrity": "sha512-vlKW17SNq44owv5AQR3Cq0bQPEb8+kF3UKZ2fiZNOWtztYE5i0CzCZxFDwO58qAOWtxdBRVO/V5Qin1wjCqFYQ==", + "requires": { + "has": "^1.0.3" + } + }, + "is-symbol": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/is-symbol/-/is-symbol-1.0.3.tgz", + "integrity": "sha512-OwijhaRSgqvhm/0ZdAcXNZt9lYdKFpcRDT5ULUuYXPoT794UNOdU+gpT6Rzo7b4V2HUl/op6GqY894AZwv9faQ==", + "requires": { + "has-symbols": "^1.0.1" + } + }, + "is-typedarray": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz", + "integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo=" + }, + "js-sha3": { + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.8.0.tgz", + "integrity": "sha512-gF1cRrHhIzNfToc802P800N8PpXS+evLLXfsVpowqmAFR9uwbi89WvXg2QspOmXL8QL86J4T1EpFu+yUkwJY3Q==" + }, + "level": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/level/-/level-5.0.1.tgz", + "integrity": "sha512-wcak5OQeA4rURGacqS62R/xNHjCYnJSQDBOlm4KNUGJVE9bWv2B04TclqReYejN+oD65PzD4FsqeWoI5wNC5Lg==", + "requires": { + "level-js": "^4.0.0", + "level-packager": "^5.0.0", + "leveldown": "^5.0.0", + "opencollective-postinstall": "^2.0.0" + } + }, + "level-codec": { + "version": "9.0.1", + "resolved": "https://registry.npmjs.org/level-codec/-/level-codec-9.0.1.tgz", + "integrity": "sha512-ajFP0kJ+nyq4i6kptSM+mAvJKLOg1X5FiFPtLG9M5gCEZyBmgDi3FkDrvlMkEzrUn1cWxtvVmrvoS4ASyO/q+Q==" + }, + "level-concat-iterator": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/level-concat-iterator/-/level-concat-iterator-2.0.1.tgz", + "integrity": "sha512-OTKKOqeav2QWcERMJR7IS9CUo1sHnke2C0gkSmcR7QuEtFNLLzHQAvnMw8ykvEcv0Qtkg0p7FOwP1v9e5Smdcw==" + }, + "level-errors": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/level-errors/-/level-errors-2.0.1.tgz", + "integrity": "sha512-UVprBJXite4gPS+3VznfgDSU8PTRuVX0NXwoWW50KLxd2yw4Y1t2JUR5In1itQnudZqRMT9DlAM3Q//9NCjCFw==", + "requires": { + "errno": "~0.1.1" + } + }, + "level-iterator-stream": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/level-iterator-stream/-/level-iterator-stream-4.0.2.tgz", + "integrity": "sha512-ZSthfEqzGSOMWoUGhTXdX9jv26d32XJuHz/5YnuHZzH6wldfWMOVwI9TBtKcya4BKTyTt3XVA0A3cF3q5CY30Q==", + "requires": { + "inherits": "^2.0.4", + "readable-stream": "^3.4.0", + "xtend": "^4.0.2" + } + }, + "level-js": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/level-js/-/level-js-4.0.2.tgz", + "integrity": "sha512-PeGjZsyMG4O89KHiez1zoMJxStnkM+oBIqgACjoo5PJqFiSUUm3GNod/KcbqN5ktyZa8jkG7I1T0P2u6HN9lIg==", + "requires": { + "abstract-leveldown": "~6.0.1", + "immediate": "~3.2.3", + "inherits": "^2.0.3", + "ltgt": "^2.1.2", + "typedarray-to-buffer": "~3.1.5" + } + }, + "level-packager": { + "version": "5.1.1", + "resolved": "https://registry.npmjs.org/level-packager/-/level-packager-5.1.1.tgz", + "integrity": "sha512-HMwMaQPlTC1IlcwT3+swhqf/NUO+ZhXVz6TY1zZIIZlIR0YSn8GtAAWmIvKjNY16ZkEg/JcpAuQskxsXqC0yOQ==", + "requires": { + "encoding-down": "^6.3.0", + "levelup": "^4.3.2" + } + }, + "level-supports": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/level-supports/-/level-supports-1.0.1.tgz", + "integrity": "sha512-rXM7GYnW8gsl1vedTJIbzOrRv85c/2uCMpiiCzO2fndd06U/kUXEEU9evYn4zFggBOg36IsBW8LzqIpETwwQzg==", + "requires": { + "xtend": "^4.0.2" + } + }, + "leveldown": { + "version": "5.4.1", + "resolved": "https://registry.npmjs.org/leveldown/-/leveldown-5.4.1.tgz", + "integrity": "sha512-3lMPc7eU3yj5g+qF1qlALInzIYnkySIosR1AsUKFjL9D8fYbTLuENBAeDRZXIG4qeWOAyqRItOoLu2v2avWiMA==", + "requires": { + "abstract-leveldown": "~6.2.1", + "napi-macros": "~2.0.0", + "node-gyp-build": "~4.1.0" + }, + "dependencies": { + "abstract-leveldown": { + "version": "6.2.2", + "resolved": "https://registry.npmjs.org/abstract-leveldown/-/abstract-leveldown-6.2.2.tgz", + "integrity": "sha512-/a+Iwj0rn//CX0EJOasNyZJd2o8xur8Ce9C57Sznti/Ilt/cb6Qd8/k98A4ZOklXgTG+iAYYUs1OTG0s1eH+zQ==", + "requires": { + "level-concat-iterator": "~2.0.0", + "level-supports": "~1.0.0", + "xtend": "~4.0.0" + } + } + } + }, + "levelup": { + "version": "4.3.2", + "resolved": "https://registry.npmjs.org/levelup/-/levelup-4.3.2.tgz", + "integrity": "sha512-cRTjU4ktWo59wf13PHEiOayHC3n0dOh4i5+FHr4tv4MX9+l7mqETicNq3Aj07HKlLdk0z5muVoDL2RD+ovgiyA==", + "requires": { + "deferred-leveldown": "~5.3.0", + "level-errors": "~2.0.0", + "level-iterator-stream": "~4.0.0", + "level-supports": "~1.0.0", + "xtend": "~4.0.0" + } + }, + "locate-path": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/locate-path/-/locate-path-3.0.0.tgz", + "integrity": "sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A==", + "requires": { + "p-locate": "^3.0.0", + "path-exists": "^3.0.0" + } + }, + "ltgt": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/ltgt/-/ltgt-2.2.1.tgz", + "integrity": "sha1-81ypHEk/e3PaDgdJUwTxezH4fuU=" + }, + "ms": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", + "integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g=" + }, + "napi-macros": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/napi-macros/-/napi-macros-2.0.0.tgz", + "integrity": "sha512-A0xLykHtARfueITVDernsAWdtIMbOJgKgcluwENp3AlsKN/PloyO10HtmoqnFAQAcxPkgZN7wdfPfEd0zNGxbg==" + }, + "node-fetch": { + "version": "2.6.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.0.tgz", + "integrity": "sha512-8dG4H5ujfvFiqDmVu9fQ5bOHUC15JMjMY/Zumv26oOvvVJjM67KF8koCWIabKQ1GJIa9r2mMZscBq/TbdOcmNA==" + }, + "node-forge": { + "version": "0.8.5", + "resolved": "https://registry.npmjs.org/node-forge/-/node-forge-0.8.5.tgz", + "integrity": "sha512-vFMQIWt+J/7FLNyKouZ9TazT74PRV3wgv9UT4cRjC8BffxFbKXkgIWR42URCPSnHm/QDz6BOlb2Q0U4+VQT67Q==" + }, + "node-gyp-build": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.1.1.tgz", + "integrity": "sha512-dSq1xmcPDKPZ2EED2S6zw/b9NKsqzXRE6dVr8TVQnI3FJOTteUMuqF3Qqs6LZg+mLGYJWqQzMbIjMtJqTv87nQ==" + }, + "object-inspect": { + "version": "1.7.0", + "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.7.0.tgz", + "integrity": "sha512-a7pEHdh1xKIAgTySUGgLMx/xwDZskN1Ud6egYYN3EdRW4ZMPNEDUTF+hwy2LUC+Bl+SyLXANnwz/jyh/qutKUw==" + }, + "object-is": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/object-is/-/object-is-1.0.2.tgz", + "integrity": "sha512-Epah+btZd5wrrfjkJZq1AOB9O6OxUQto45hzFd7lXGrpHPGE0W1k+426yrZV+k6NJOzLNNW/nVsmZdIWsAqoOQ==" + }, + "object-keys": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/object-keys/-/object-keys-1.1.1.tgz", + "integrity": "sha512-NuAESUOUMrlIXOfHKzD6bpPu3tYt3xvjNdRIQ+FeT0lNb4K8WR70CaDxhuNguS2XG+GjkyMwOzsN5ZktImfhLA==" + }, + "object.assign": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/object.assign/-/object.assign-4.1.0.tgz", + "integrity": "sha512-exHJeq6kBKj58mqGyTQ9DFvrZC/eR6OwxzoM9YRoGBqrXYonaFyGiFMuc9VZrXf7DarreEwMpurG3dd+CNyW5w==", + "requires": { + "define-properties": "^1.1.2", + "function-bind": "^1.1.1", + "has-symbols": "^1.0.0", + "object-keys": "^1.0.11" + } + }, + "object.entries": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/object.entries/-/object.entries-1.1.1.tgz", + "integrity": "sha512-ilqR7BgdyZetJutmDPfXCDffGa0/Yzl2ivVNpbx/g4UeWrCdRnFDUBrKJGLhGieRHDATnyZXWBeCb29k9CJysQ==", + "requires": { + "define-properties": "^1.1.3", + "es-abstract": "^1.17.0-next.1", + "function-bind": "^1.1.1", + "has": "^1.0.3" + } + }, + "opencollective-postinstall": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/opencollective-postinstall/-/opencollective-postinstall-2.0.2.tgz", + "integrity": "sha512-pVOEP16TrAO2/fjej1IdOyupJY8KDUM1CvsaScRbw6oddvpQoOfGk4ywha0HKKVAD6RkW4x6Q+tNBwhf3Bgpuw==" + }, + "p-limit": { + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.2.2.tgz", + "integrity": "sha512-WGR+xHecKTr7EbUEhyLSh5Dube9JtdiG78ufaeLxTgpudf/20KqyMioIUZJAezlTIi6evxuoUs9YXc11cU+yzQ==", + "requires": { + "p-try": "^2.0.0" + } + }, + "p-locate": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/p-locate/-/p-locate-3.0.0.tgz", + "integrity": "sha512-x+12w/To+4GFfgJhBEpiDcLozRJGegY+Ei7/z0tSLkMmxGZNybVMSfWj9aJn8Z5Fc7dBUNJOOVgPv2H7IwulSQ==", + "requires": { + "p-limit": "^2.0.0" + } + }, + "p-try": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz", + "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==" + }, + "path-exists": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/path-exists/-/path-exists-3.0.0.tgz", + "integrity": "sha1-zg6+ql94yxiSXqfYENe1mwEP1RU=" + }, + "prr": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/prr/-/prr-1.0.1.tgz", + "integrity": "sha1-0/wRS6BplaRexok/SEzrHXj19HY=" + }, + "readable-stream": { + "version": "3.5.0", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.5.0.tgz", + "integrity": "sha512-gSz026xs2LfxBPudDuI41V1lka8cxg64E66SGe78zJlsUofOg/yqwezdIcdfwik6B4h8LFmWPA9ef9X3FiNFLA==", + "requires": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + } + }, + "require-directory": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", + "integrity": "sha1-jGStX9MNqxyXbiNE/+f3kqam30I=" + }, + "require-main-filename": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/require-main-filename/-/require-main-filename-2.0.0.tgz", + "integrity": "sha512-NKN5kMDylKuldxYLSUfrbo5Tuzh4hd+2E8NPPX02mZtn1VuREQToYe/ZdlJy+J3uCpfaiGF05e7B8W0iXbQHmg==" + }, + "safe-buffer": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.0.tgz", + "integrity": "sha512-fZEwUGbVl7kouZs1jCdMLdt95hdIv0ZeHg6L7qPeciMZhZ+/gdesW4wgTARkrFWEpspjEATAzUGPG8N2jJiwbg==" + }, + "set-blocking": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", + "integrity": "sha1-BF+XgtARrppoA93TgrJDkrPYkPc=" + }, + "string-width": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-3.1.0.tgz", + "integrity": "sha512-vafcv6KjVZKSgz06oM/H6GDBrAtz8vdhQakGjFIvNrHA6y3HCF1CInLy+QLq8dTJPQ1b+KDUqDFctkdRW44e1w==", + "requires": { + "emoji-regex": "^7.0.1", + "is-fullwidth-code-point": "^2.0.0", + "strip-ansi": "^5.1.0" + } + }, + "string.prototype.trimleft": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/string.prototype.trimleft/-/string.prototype.trimleft-2.1.1.tgz", + "integrity": "sha512-iu2AGd3PuP5Rp7x2kEZCrB2Nf41ehzh+goo8TV7z8/XDBbsvc6HQIlUl9RjkZ4oyrW1XM5UwlGl1oVEaDjg6Ag==", + "requires": { + "define-properties": "^1.1.3", + "function-bind": "^1.1.1" + } + }, + "string.prototype.trimright": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/string.prototype.trimright/-/string.prototype.trimright-2.1.1.tgz", + "integrity": "sha512-qFvWL3/+QIgZXVmJBfpHmxLB7xsUXz6HsUmP8+5dRaC3Q7oKUv9Vo6aMCRZC1smrtyECFsIT30PqBJ1gTjAs+g==", + "requires": { + "define-properties": "^1.1.3", + "function-bind": "^1.1.1" + } + }, + "string_decoder": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", + "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", + "requires": { + "safe-buffer": "~5.2.0" + } + }, + "strip-ansi": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-5.2.0.tgz", + "integrity": "sha512-DuRs1gKbBqsMKIZlrffwlug8MHkcnpjs5VPmL1PAh+mA30U0DTotfDZ0d2UUsXpPmPmMMJ6W773MaA3J+lbiWA==", + "requires": { + "ansi-regex": "^4.1.0" + } + }, + "to-regex-range": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "requires": { + "is-number": "^7.0.0" + } + }, + "typedarray-to-buffer": { + "version": "3.1.5", + "resolved": "https://registry.npmjs.org/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz", + "integrity": "sha512-zdu8XMNEDepKKR+XYOXAVPtWui0ly0NtohUscw+UmaHiAWT8hrV1rr//H6V+0DvJ3OQ19S979M0laLfX8rm82Q==", + "requires": { + "is-typedarray": "^1.0.0" + } + }, + "util": { + "version": "0.12.1", + "resolved": "https://registry.npmjs.org/util/-/util-0.12.1.tgz", + "integrity": "sha512-MREAtYOp+GTt9/+kwf00IYoHZyjM8VU4aVrkzUlejyqaIjd2GztVl5V9hGXKlvBKE3gENn/FMfHE5v6hElXGcQ==", + "requires": { + "inherits": "^2.0.3", + "is-arguments": "^1.0.4", + "is-generator-function": "^1.0.7", + "object.entries": "^1.1.0", + "safe-buffer": "^5.1.2" + } + }, + "util-deprecate": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", + "integrity": "sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8=" + }, + "which-module": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/which-module/-/which-module-2.0.0.tgz", + "integrity": "sha1-2e8H3Od7mQK4o6j6SzHD4/fm6Ho=" + }, + "wrap-ansi": { + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/wrap-ansi/-/wrap-ansi-5.1.0.tgz", + "integrity": "sha512-QC1/iN/2/RPVJ5jYK8BGttj5z83LmSKmvbvrXPNCLZSEb32KKVDJDl/MOt2N01qU2H/FkzEa9PKto1BqDjtd7Q==", + "requires": { + "ansi-styles": "^3.2.0", + "string-width": "^3.0.0", + "strip-ansi": "^5.0.0" + } + }, + "xtend": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.2.tgz", + "integrity": "sha512-LKYU1iAXJXUgAXn9URjiu+MWhyUXHsvfp7mcuYm9dSUKK0/CjtrUwFAxD82/mCWbtLsGjFIad0wIsod4zrTAEQ==" + }, + "y18n": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/y18n/-/y18n-4.0.0.tgz", + "integrity": "sha512-r9S/ZyXu/Xu9q1tYlpsLIsa3EeLXXk0VwlxqTcFRfg9EhMW+17kbt9G0NrgCmhGb5vT2hyhJZLfDGx+7+5Uj/w==" + }, + "yargs": { + "version": "13.3.0", + "resolved": "https://registry.npmjs.org/yargs/-/yargs-13.3.0.tgz", + "integrity": "sha512-2eehun/8ALW8TLoIl7MVaRUrg+yCnenu8B4kBlRxj3GJGDKU1Og7sMXPNm1BYyM1DOJmTZ4YeN/Nwxv+8XJsUA==", + "requires": { + "cliui": "^5.0.0", + "find-up": "^3.0.0", + "get-caller-file": "^2.0.1", + "require-directory": "^2.1.1", + "require-main-filename": "^2.0.0", + "set-blocking": "^2.0.0", + "string-width": "^3.0.0", + "which-module": "^2.0.0", + "y18n": "^4.0.0", + "yargs-parser": "^13.1.1" + } + }, + "yargs-parser": { + "version": "13.1.1", + "resolved": "https://registry.npmjs.org/yargs-parser/-/yargs-parser-13.1.1.tgz", + "integrity": "sha512-oVAVsHz6uFrg3XQheFII8ESO2ssAf9luWuAd6Wexsu4F3OtIW0o8IribPXYrD4WC24LWtPrJlGy87y5udK+dxQ==", + "requires": { + "camelcase": "^5.0.0", + "decamelize": "^1.2.0" + } + } + } +} diff --git a/zwaves_demo/package.json b/zwaves_demo/package.json new file mode 100644 index 0000000..84aa25c --- /dev/null +++ b/zwaves_demo/package.json @@ -0,0 +1,30 @@ +{ + "name": "anonymous-transactions-prototype", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/wavesplatform/anonymous-transactions-prototype.git" + }, + "author": "Igor Gulamov", + "license": "MIT", + "bugs": { + "url": "https://github.com/wavesplatform/anonymous-transactions-prototype/issues" + }, + "homepage": "https://github.com/wavesplatform/anonymous-transactions-prototype#readme", + "dependencies": { + "@waves/waves-crypto": "^3.0.17", + "@waves/waves-transactions": "^3.12.1", + "assert": "^2.0.0", + "axios": "^0.19.0", + "dotenv": "^6.2.0", + "level": "^5.0.1", + "node-fetch": "^2.6.0", + "to-regex-range": "^5.0.1", + "yargs": "^13.3.0" + } +} diff --git a/zwaves_demo/ride/zwaves.ride b/zwaves_demo/ride/zwaves.ride new file mode 100644 index 0000000..afaa8ed --- /dev/null +++ b/zwaves_demo/ride/zwaves.ride @@ -0,0 +1,228 @@ +{-# STDLIB_VERSION 4 #-} +{-# CONTENT_TYPE DAPP #-} +{-# SCRIPT_TYPE ACCOUNT #-} + + +let transferVK=base58'' +let utxoAccumulatorVK=base58'' +let emptyRoot=base58'4ABQyM1tpHEDkbHes1t7G1F3yyMJXQSvaUR1rqkZqKak' + + +# TODO replace. Gas cost for transfer +let transferFee = 400000 + +# TODO replace. Gas cost for accumulation +let accumulatorFee = 400000 + + +func takeLR(v:ByteVector, from:Int, to:Int) = { + drop(take(v, to), from) +} + +func getUtxoKey(utxo:ByteVector) = "U:"+toBase58String(utxo) +func getRootKey(root:ByteVector) = "R:"+toBase58String(root) +func getNullifierKey(nullifier:ByteVector) = "N:"+toBase58String(nullifier) +func getMessageKey(n:Int) = "M:"+toString(n) +func getRootValueKey(n:Int) = "RV:"+toString(n) +func getUTXOMessageKey(n:Int) = "UM:"+toString(n) + + + +func flagExists(key:String) = { + match getBoolean(this, key) { + case a:Boolean => a + case _ => false + } +} + + +func rootExists(key:String) = { + if (key=="R:4ABQyM1tpHEDkbHes1t7G1F3yyMJXQSvaUR1rqkZqKak") then true + else match getBoolean(this, key) { + case a:Boolean => a + case _ => false + } +} + +func getMessageNum() = { + match getBinary(this, "MESSAGE_NUM") { + case a:ByteVector => toInt(a) + case _ => 0 + } +} + +func getRootNum() = { + match getBinary(this, "ROOT_NUM") { + case a:ByteVector => toInt(a) + case _ => 0 + } +} + +func getRootValue(n:Int) = { + match getBinary(this, getRootValueKey(n)) { + case a:ByteVector => a + case _ => emptyRoot + } +} + + + +# Transfer input structure +# receiver 256 +# root_hash 256 +# zeros 64 +# native_amount 64 signed int +# amount 64 signed int +# asset_id 64 +# out_hash0 256 +# out_hash1 256 +# nf0 256 +# nf1 256 + +@Callable(i) +func transferExternal(proof:ByteVector, v:ByteVector, m:ByteVector) = { + let receiver = Address(takeLR(v, 0+6, 32)) + let rootHash = getRootKey(takeLR(v, 32, 64)) + let nativeAmount = toInt(v, 72) + let amount = toInt(v, 80) + let assetId = toInt(v, 88) + + let rOutHash0 = takeLR(v, 96, 128) + let rOutHash1 = takeLR(v, 128, 160) + + let outHash0 = getUtxoKey(rOutHash0) + let outHash1 = getUtxoKey(rOutHash1) + + let rNf0 = takeLR(v, 160, 192) + let rNf1 = takeLR(v, 192, 224) + + let nf0 = getNullifierKey(rNf0) + let nf1 = getNullifierKey(rNf1) + + + let pmt = i.payments[0] + let mn = getMessageNum() + let fee = accumulatorFee + + let withdrawNativeAmount = + if (size(i.payments) == 0) + then - nativeAmount - fee + else if (size(i.payments) == 1 && !isDefined(i.payments[0].assetId)) + then i.payments[0].amount - nativeAmount - fee + else throw() + + if (assetId != 0 || amount != 0) + then throw("TODO: implement mapping from WAVES assetId into internal u64 asset_id to transfer tokens") + else if (withdrawNativeAmount < 0) + then throw("not enough WAVES to process transaction and positive number of money") + else if (flagExists(nf0) || flagExists(nf1)) + then throw("doublespend detected") + else if (flagExists(outHash0) || flagExists(outHash1)) + then throw("output utxo already exists") + else if (!rootExists(rootHash)) + then throw("root not exists") + else if (!groth16Verify(transferVK, proof, v)) then + throw("wrong proof") + else + [ + BooleanEntry(nf0, true), + BooleanEntry(nf1, true), + BooleanEntry(outHash0, true), + BooleanEntry(outHash1, true), + BinaryEntry("MESSAGE_NUM", toBytes(mn+1)), + BinaryEntry(getMessageKey(mn), rNf0+rNf1+m), + BinaryEntry(getUTXOMessageKey(mn), rOutHash0+rOutHash1), + ScriptTransfer(receiver, withdrawNativeAmount, unit) + ] +} + + +@Callable(i) +func transferInternal(proof:ByteVector, v:ByteVector, m:ByteVector) = { + let receiver = Address(takeLR(v, 0+6, 32)) + let rootHash = getRootKey(takeLR(v, 32, 64)) + let nativeAmount = toInt(v, 72) + let amount = toInt(v, 80) + let assetId = toInt(v, 88) + + let rOutHash0 = takeLR(v, 96, 128) + let rOutHash1 = takeLR(v, 128, 160) + + let outHash0 = getUtxoKey(rOutHash0) + let outHash1 = getUtxoKey(rOutHash1) + + let rNf0 = takeLR(v, 160, 192) + let rNf1 = takeLR(v, 192, 224) + + let nf0 = getNullifierKey(rNf0) + let nf1 = getNullifierKey(rNf1) + + + let mn = getMessageNum() + let fee = accumulatorFee + transferFee + + let withdrawNativeAmount = - nativeAmount - fee + + if (i.caller!=this) then + throw("wrong caller") + else if (assetId != 0 || amount != 0) + then throw("TODO: implement mapping from WAVES assetId into internal u64 asset_id to transfer tokens") + else if (withdrawNativeAmount < 0) + then throw("not enough WAVES to process transaction and positive number of money") + else if (flagExists(nf0) || flagExists(nf1)) + then throw("doublespend detected") + else if (flagExists(outHash0) || flagExists(outHash1)) + then throw("output utxo already exists") + else if (!rootExists(rootHash)) + then throw("root not exists") + else if (!groth16Verify(transferVK, proof, v)) then + throw("wrong proof") + else + [ + BooleanEntry(nf0, true), + BooleanEntry(nf1, true), + BooleanEntry(outHash0, true), + BooleanEntry(outHash1, true), + BinaryEntry("MESSAGE_NUM", toBytes(mn+1)), + BinaryEntry(getMessageKey(mn), rNf0+rNf1+m), + BinaryEntry(getUTXOMessageKey(mn), rOutHash0+rOutHash1), + ScriptTransfer(receiver, withdrawNativeAmount, unit) + ] +} + + + + +# UTXO Accumulator input structure +# utxo_pair 512 +# zeros 192 +# index 64 +# old_root 256 +# new_root 256 + +@Callable(i) +func utxoAccumulator(proof:ByteVector, newRoot:ByteVector) = { + + let rn = getRootNum() + let utxoPair = getBinaryValue(this, getUTXOMessageKey(rn)) + let oldRoot = getRootValue(rn) + + if (!groth16Verify(utxoAccumulatorVK, proof, utxoPair+base58'111111111111111111111111'+toBytes(rn*2)+oldRoot+newRoot)) + then throw("wrong proof or data racing case") + else + [ + BinaryEntry("ROOT_NUM", toBytes(rn+1)), + BinaryEntry(getRootValueKey(rn+1), newRoot), + BooleanEntry(getRootKey(newRoot), true) + ] +} + + + +@Verifier(tx) +func verify() = { + match tx { + case tx:InvokeScriptTransaction => (tx.function == "transferInternal") || (tx.function == "utxoAccumulator") || sigVerify(tx.bodyBytes, tx.proofs[0], tx.senderPublicKey) + case _ => true # TODO replace to false + } +} \ No newline at end of file diff --git a/zwaves_demo/test.js b/zwaves_demo/test.js new file mode 100644 index 0000000..0d432bb --- /dev/null +++ b/zwaves_demo/test.js @@ -0,0 +1,135 @@ +const { broadcast, waitForTx, setScript, invokeScript, nodeInteraction } = require("@waves/waves-transactions"); +const { address, base58Encode, base58Decode, publicKey, privateKey } = require("@waves/waves-crypto"); +const {extract_vk, MerkleTree, transfer, pubkey, fs_random, fr_random, verify, bufferizeBigints, debufferizeBigints, note_hash} = require("../zwaves_node/lib/index.js"); + +const fs = require("fs"); +const env = process.env; +if (env.NODE_ENV !== 'production') { + require('dotenv').load(); +} + + +function utxo(asset_id, amount, native_amount, txid, owner) { + return {asset_id, amount, native_amount, txid, owner}; +} + +const sleep = m => new Promise(r => setTimeout(r, m)); + +let seed = env.MNEMONIC; +const rpc = env.WAVES_RPC; +const chainId = env.WAVES_CHAINID; + + +const dAppPk = env.DAPP; +const dApp = address({publicKey:dAppPk}, chainId); +const userAddress = address(seed, chainId); + +const buff2bigintBe = (b) => { + let t = 0; + let ti = 0; + let res = 0n; + for (let i = 0; i < b.length ; i++) { + t = (t << 8) + b[i]; + ti += 1; + if (ti == 3) { + res = (res << 24n) + BigInt(t); + t = 0; + ti = 0; + } + } + if (ti > 0) { + res = (res << BigInt(ti * 8)) + BigInt(t); + } + return res; +} + +const address2bigint = a => buff2bigintBe(base58Decode(a)); + +const fee = 900000; +let transferFee = 400000n; +let accumulatorFee = 400000n; + +const transfer_mpc = fs.readFileSync("../zwaves_setup/mpc_params_transfer"); +const accumulator_mpc = fs.readFileSync("../zwaves_setup/mpc_params_accumulator"); + + + +let mt = new MerkleTree(48); +let sk = fs_random(); +let pk = pubkey(sk); + +let deposit_amount = 10000000n; + +let in_note = [utxo(0n, 0n, 0n, fr_random(), pk), utxo(0n, 0n, 0n, fr_random(), pk)]; +let in_proof_index = [0n, 0n]; +let in_proof_sibling = [Array(48).fill(0n), Array(48).fill(0n)]; +let out_note = [utxo(0n, 0n, deposit_amount - accumulatorFee, fr_random(), pk), utxo(0n, 0n, 0n, fr_random(), pk)]; +let packed_asset = (deposit_amount - accumulatorFee) << 128n; +let receiver = address2bigint(userAddress); + + +let data = { + in_note, + in_proof_index, + out_note, + in_proof_sibling, + root_hash: mt.root(), + sk, + packed_asset, + receiver + +}; + +console.log(data); +let res = transfer(transfer_mpc, data); + +console.log(res); +console.log(verify(extract_vk(transfer_mpc), res)); + + +(async()=>{ + + +console.log(`Waves balance before transfer:\t\t${await nodeInteraction.balance(address(seed, chainId), rpc)}`); + +let tx = invokeScript({ + dApp, + chainId, + payment: [{ amount: Number(deposit_amount), assetId: null }], + call: { + function: "transferExternal", + args: [{ type: "binary", value: res.proof.toString("base64") }, + { type: "binary", value: Buffer.concat(bufferizeBigints(res.publicInputs)).toString("base64") }, + { type: "binary", value: Buffer.from("test").toString("base64") }] + }, fee +}, seed); +await broadcast(tx, rpc); +console.log(`Waiting for ${tx.id}`); +await waitForTx(tx.id, { apiBase: rpc }); +console.log(`transaction complete`) + +await sleep(10000); +console.log(`Waves balance after transfer:\t\t${await nodeInteraction.balance(address(seed, chainId), rpc)}`); + +/* + +let note_hashes = out_note.map(n=>note_hashes(n)); +let proof_zero = mt.proof(0).slice(1); +mt.pushMany(note_hashes); +let proof_pair = mt.proof(0).slice(1); + +let data = { + note_hashes: pair, + proof_index: 0n, + proof_sibling: [proof_zero, proof_pair] +}; + +console.log(data); +let vk = extract_vk(mpc_params); +let res = utxoAccumulator(mpc_params, data); +console.log(res); +console.log(verify(vk, res)); +*/ + + +})(); \ No newline at end of file diff --git a/zwaves_node/package-lock.json b/zwaves_node/package-lock.json index 0791816..7cce1e2 100644 --- a/zwaves_node/package-lock.json +++ b/zwaves_node/package-lock.json @@ -50,6 +50,14 @@ "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" }, + "base-x": { + "version": "3.0.7", + "resolved": "https://registry.npmjs.org/base-x/-/base-x-3.0.7.tgz", + "integrity": "sha512-zAKJGuQPihXW22fkrfOclUUZXM2g92z5GzlSMHxhO6r6Qj+Nm0ccaGNBzDZojzwOMkpjAv4J0fOv1U4go+a4iw==", + "requires": { + "safe-buffer": "^5.0.1" + } + }, "bigint-buffer": { "version": "1.1.5", "resolved": "https://registry.npmjs.org/bigint-buffer/-/bigint-buffer-1.1.5.tgz", @@ -75,6 +83,14 @@ "concat-map": "0.0.1" } }, + "bs58": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/bs58/-/bs58-4.0.1.tgz", + "integrity": "sha1-vhYedsNU9veIrkBx9j806MTwpCo=", + "requires": { + "base-x": "^3.0.2" + } + }, "builtins": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/builtins/-/builtins-1.0.3.tgz", @@ -480,6 +496,11 @@ "rx-lite": "*" } }, + "safe-buffer": { + "version": "5.2.0", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.0.tgz", + "integrity": "sha512-fZEwUGbVl7kouZs1jCdMLdt95hdIv0ZeHg6L7qPeciMZhZ+/gdesW4wgTARkrFWEpspjEATAzUGPG8N2jJiwbg==" + }, "safer-buffer": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", diff --git a/zwaves_node/package.json b/zwaves_node/package.json index b44f91e..1a917d0 100644 --- a/zwaves_node/package.json +++ b/zwaves_node/package.json @@ -7,6 +7,7 @@ "license": "MIT", "dependencies": { "bigint-buffer": "^1.1.5", + "bs58": "^4.0.1", "lodash": "^4.17.15", "neon-cli": "^0.3.3" }, diff --git a/zwaves_node/test/test_merklehash.js b/zwaves_node/test/test_merklehash.js index ebf56e7..125c8f8 100644 --- a/zwaves_node/test/test_merklehash.js +++ b/zwaves_node/test/test_merklehash.js @@ -1,4 +1,5 @@ -const {MerkleTree} = require("../lib/index"); +const {MerkleTree, bufferizeBigints} = require("../lib/index"); +const bs58 = require('bs58') -let mt = new MerkleTree(32+1); -console.log(mt.root); \ No newline at end of file +let mt = new MerkleTree(48); +console.log(bs58.encode(bufferizeBigints(mt.root()))); \ No newline at end of file diff --git a/zwaves_node/test/test_transfer.js b/zwaves_node/test/test_transfer.js index afb54f3..617ba88 100644 --- a/zwaves_node/test/test_transfer.js +++ b/zwaves_node/test/test_transfer.js @@ -2,6 +2,7 @@ let {utxoAccumulator, MerkleTree, fr_random, fs_random, u64_random, verify, u32_random, pubkey, note_hash, randrange, transfer, extract_vk, bufferizeBigints} = require("../lib/index.js"); + function utxo_random(fixed) { return { asset_id:u32_random(), @@ -62,6 +63,7 @@ let data = { let vk = extract_vk(mpc_params); +console.log(data); let res = transfer(mpc_params, data); - +console.log(res); console.log(verify(vk, res)); diff --git a/zwaves_node/test/test_utxo_accumulator.js b/zwaves_node/test/test_utxo_accumulator.js index 0e6f57b..7a2a898 100644 --- a/zwaves_node/test/test_utxo_accumulator.js +++ b/zwaves_node/test/test_utxo_accumulator.js @@ -20,7 +20,8 @@ let data = { proof_sibling: [proof_zero, proof_pair] }; +console.log(data); let vk = extract_vk(mpc_params); let res = utxoAccumulator(mpc_params, data); - +console.log(res); console.log(verify(vk, res));