diff --git a/config/rollup.config.js b/config/rollup.config.js index 0e66686..37494c7 100644 --- a/config/rollup.config.js +++ b/config/rollup.config.js @@ -10,6 +10,7 @@ const plugins = [ replace({ preventAssignment: true, 'node-tfhe': 'tfhe', + 'kms/node/': 'kms/web/', }), typescript({ tsconfig: './tsconfig.rollup.json', @@ -45,6 +46,7 @@ export default [ format: 'cjs', }, plugins: [ + commonjs(), typescript({ tsconfig: './tsconfig.rollup.json', }), diff --git a/config/webpack.config.cjs b/config/webpack.config.cjs index e64bc05..6b66559 100644 --- a/config/webpack.config.cjs +++ b/config/webpack.config.cjs @@ -1,25 +1,25 @@ -"use strict"; -const webpack = require("webpack"); -const path = require("path"); -const PATHS = require("./paths.cjs"); +'use strict'; +const webpack = require('webpack'); +const path = require('path'); +const PATHS = require('./paths.cjs'); const web = { entry: { - "fhevm.min": PATHS.web, + 'fhevm.min': PATHS.web, }, output: { path: PATHS.build, - filename: "[name].js", - chunkFilename: "[name].js", - globalObject: "this", + filename: '[name].js', + chunkFilename: '[name].js', + globalObject: 'this', library: { - name: "fhevm", - type: "umd2", + name: 'fhevm', + type: 'umd2', }, }, optimization: { splitChunks: { - chunks: "all", + chunks: 'all', minRemainingSize: 0, minChunks: 1, cacheGroups: { @@ -42,34 +42,36 @@ const web = { { test: /\.tsx?$/, exclude: [/node_modules/], - use: ["ts-loader"], + use: ['ts-loader'], generator: { - filename: "[name][ext]", + filename: '[name][ext]', }, }, ], }, resolve: { - extensions: [".tsx", ".ts", ".js"], + extensions: ['.tsx', '.ts', '.js'], extensionAlias: { - ".js": [".ts", ".tsx", ".js"], - ".mjs": [".mts", ".mjs"], + '.js': ['.ts', '.tsx', '.js'], + '.mjs': ['.mts', '.mjs'], }, alias: { - "node-tfhe": "tfhe/tfhe", + 'node-tfhe': 'tfhe/tfhe', }, fallback: { - "tfhe_bg.wasm": require.resolve("tfhe/tfhe_bg.wasm"), - "node-tfhe": require.resolve("tfhe/tfhe"), - buffer: require.resolve("buffer/"), - crypto: require.resolve("crypto-browserify"), - stream: require.resolve("stream-browserify"), - path: require.resolve("path-browserify"), + 'tfhe_bg.wasm': require.resolve('tfhe/tfhe_bg.wasm'), + 'node-tfhe': require.resolve('tfhe/tfhe'), + 'kms_lib_bg.wasm': require.resolve('../src/kms/web/kms_lib_bg.wasm'), + 'node-kms': require.resolve('../src/kms/web/kms_lib.js'), + buffer: require.resolve('buffer/'), + crypto: require.resolve('crypto-browserify'), + stream: require.resolve('stream-browserify'), + path: require.resolve('path-browserify'), }, }, plugins: [ new webpack.ProvidePlugin({ - Buffer: ["buffer", "Buffer"], + Buffer: ['buffer', 'Buffer'], }), new webpack.optimize.LimitChunkCountPlugin({ maxChunks: 1, diff --git a/jest.config.cjs b/jest.config.cjs index a556031..7ade4af 100644 --- a/jest.config.cjs +++ b/jest.config.cjs @@ -1,32 +1,37 @@ module.exports = { - preset: "ts-jest", + preset: 'ts-jest', transform: { - "^.+\\.tsx?$": [ - "ts-jest", + '^.+\\.tsx?$': [ + 'ts-jest', { - tsconfig: "tsconfig.json", + tsconfig: 'tsconfig.json', }, ], - "^.+\\.jsx?$": [ - "ts-jest", + '^.+\\.jsx?$': [ + 'ts-jest', { - tsconfig: "tsconfig.json", + tsconfig: 'tsconfig.json', }, ], - "^.+\\.bin$": ["config/rawLoader.cjs"], + '^.+\\.bin$': ['config/rawLoader.cjs'], + }, + testEnvironment: 'node', + moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], + moduleNameMapper: { + '^node-kms$': '/src/kms/node', }, - testEnvironment: "node", - moduleFileExtensions: ["ts", "tsx", "js", "jsx", "json", "node"], collectCoverageFrom: [ - "src/**/*.ts", - "!src/**/*.d.ts", - "src/**/*.tsx", - "!src/**/*.story.**", + 'src/**/*.ts', + 'src/**/*.tsx', + '!src/**/*.d.ts', + '!src/kms/*', + '!src/init.ts', + '!src/node.ts', + '!src/web.ts', ], - testRegex: "\\.test\\.tsx?$", - coverageReporters: ["lcov", "text-summary", "json"], - transformIgnorePatterns: ["/node_modules/"], - coveragePathIgnorePatterns: [], + testRegex: '\\.test\\.tsx?$', + coverageReporters: ['lcov', 'text-summary', 'json'], + transformIgnorePatterns: ['/node_modules/'], coverageThreshold: { global: { branches: 80, diff --git a/package-lock.json b/package-lock.json index 17ea3f6..1b69f79 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,22 +1,26 @@ { "name": "fhevmjs", - "version": "0.5.0-0", + "version": "0.5.0-1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "fhevmjs", - "version": "0.5.0-0", + "version": "0.5.0-1", "license": "BSD-3-Clause-Clear", "dependencies": { + "@types/keccak": "^3.0.4", "bigint-buffer": "^1.1.5", "commander": "^11.0.0", "crypto-js": "^4.1.1", "ethers": "^6.6.4", + "keccak": "^3.0.4", "libsodium": "^0.7.11", "libsodium-wrappers": "^0.7.11", + "node-fetch": "^3.3.2", "node-tfhe": "^0.6.1", - "tfhe": "^0.6.1" + "tfhe": "^0.6.1", + "web3-validator": "^2.0.6" }, "bin": { "fhevm": "bin/fhevm.js" @@ -30,8 +34,10 @@ "@rollup/plugin-wasm": "^6.1.3", "@types/jest": "^29.5.1", "@types/libsodium-wrappers": "^0.7.10", + "@types/node-fetch": "^2.6.11", "buffer": "^6.0.3", "crypto-browserify": "^3.12.0", + "fetch-mock-jest": "^1.5.1", "jest": "^29.5.0", "jest-raw-loader": "^1.0.1", "path-browserify": "^1.0.1", @@ -677,6 +683,18 @@ "@babel/core": "^7.0.0-0" } }, + "node_modules/@babel/runtime": { + "version": "7.24.6", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.24.6.tgz", + "integrity": "sha512-Ja18XcETdEl5mzzACGd+DKgaGJzPTCow7EglgwTmHdwokzDFYh/MHua6lU6DV/hjF2IaOJ4oX2nqnjG7RElKOw==", + "dev": true, + "dependencies": { + "regenerator-runtime": "^0.14.0" + }, + "engines": { + "node": ">=6.9.0" + } + }, "node_modules/@babel/template": { "version": "7.23.9", "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.23.9.tgz", @@ -1117,6 +1135,28 @@ "@jridgewell/sourcemap-codec": "1.4.14" } }, + "node_modules/@noble/curves": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/@noble/curves/-/curves-1.3.0.tgz", + "integrity": "sha512-t01iSXPuN+Eqzb4eBX0S5oubSqXbK/xXa1Ne18Hj8f9pStxztHCE2gfboSp/dZRLSqfuLpRK2nDXDK+W9puocA==", + "dependencies": { + "@noble/hashes": "1.3.3" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/@noble/curves/node_modules/@noble/hashes": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.3.tgz", + "integrity": "sha512-V7/fPHgl+jsVPXqqeOzT8egNj2iBIVt+ECeMMG8TdcnTikP3oaBtUVqpT/gYCR68aEBJSF+XbYUxStjbFMqIIA==", + "engines": { + "node": ">= 16" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, "node_modules/@noble/hashes": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.1.2.tgz", @@ -1404,6 +1444,61 @@ } } }, + "node_modules/@scure/base": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/@scure/base/-/base-1.1.6.tgz", + "integrity": "sha512-ok9AWwhcgYuGG3Zfhyqg+zwl+Wn5uE+dwC0NV/2qQkx4dABbb/bx96vWu8NSj+BNjjSjno+JRYRjle1jV08k3g==", + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/@scure/bip32": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/@scure/bip32/-/bip32-1.3.3.tgz", + "integrity": "sha512-LJaN3HwRbfQK0X1xFSi0Q9amqOgzQnnDngIt+ZlsBC3Bm7/nE7K0kwshZHyaru79yIVRv/e1mQAjZyuZG6jOFQ==", + "dependencies": { + "@noble/curves": "~1.3.0", + "@noble/hashes": "~1.3.2", + "@scure/base": "~1.1.4" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/@scure/bip32/node_modules/@noble/hashes": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.3.tgz", + "integrity": "sha512-V7/fPHgl+jsVPXqqeOzT8egNj2iBIVt+ECeMMG8TdcnTikP3oaBtUVqpT/gYCR68aEBJSF+XbYUxStjbFMqIIA==", + "engines": { + "node": ">= 16" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/@scure/bip39": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/@scure/bip39/-/bip39-1.2.2.tgz", + "integrity": "sha512-HYf9TUXG80beW+hGAt3TRM8wU6pQoYur9iNypTROm42dorCGmLnFe3eWjz3gOq6G62H2WRh0FCzAR1PI+29zIA==", + "dependencies": { + "@noble/hashes": "~1.3.2", + "@scure/base": "~1.1.4" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, + "node_modules/@scure/bip39/node_modules/@noble/hashes": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.3.tgz", + "integrity": "sha512-V7/fPHgl+jsVPXqqeOzT8egNj2iBIVt+ECeMMG8TdcnTikP3oaBtUVqpT/gYCR68aEBJSF+XbYUxStjbFMqIIA==", + "engines": { + "node": ">= 16" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, "node_modules/@sinclair/typebox": { "version": "0.25.24", "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.25.24.tgz", @@ -1544,6 +1639,14 @@ "integrity": "sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==", "dev": true }, + "node_modules/@types/keccak": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/@types/keccak/-/keccak-3.0.4.tgz", + "integrity": "sha512-hdnkmbie7tE0yXnQQvlIOqCyjEsoXDVEZ3ACqO+F305XgUOW4Z9ElWdogCXXRAW/khnZ7GxM0t/BGB5bORKt/g==", + "dependencies": { + "@types/node": "*" + } + }, "node_modules/@types/libsodium-wrappers": { "version": "0.7.10", "resolved": "https://registry.npmjs.org/@types/libsodium-wrappers/-/libsodium-wrappers-0.7.10.tgz", @@ -1553,8 +1656,17 @@ "node_modules/@types/node": { "version": "20.1.2", "resolved": "https://registry.npmjs.org/@types/node/-/node-20.1.2.tgz", - "integrity": "sha512-CTO/wa8x+rZU626cL2BlbCDzydgnFNgc19h4YvizpTO88MFQxab8wqisxaofQJ/9bLGugRdWIuX/TbIs6VVF6g==", - "dev": true + "integrity": "sha512-CTO/wa8x+rZU626cL2BlbCDzydgnFNgc19h4YvizpTO88MFQxab8wqisxaofQJ/9bLGugRdWIuX/TbIs6VVF6g==" + }, + "node_modules/@types/node-fetch": { + "version": "2.6.11", + "resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.11.tgz", + "integrity": "sha512-24xFj9R5+rfQJLRyM56qh+wnVSYhyXC2tkoBndtY0U+vubqNsYXGjufB2nn8Q6gt0LrARwL6UBtMCSVCwl4B1g==", + "dev": true, + "dependencies": { + "@types/node": "*", + "form-data": "^4.0.0" + } }, "node_modules/@types/prettier": { "version": "2.7.2", @@ -1930,12 +2042,32 @@ "integrity": "sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA==", "dev": true }, + "node_modules/asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", + "dev": true + }, "node_modules/atob-lite": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/atob-lite/-/atob-lite-2.0.0.tgz", "integrity": "sha512-LEeSAWeh2Gfa2FtlQE1shxQ8zi5F9GHarrGKz08TMdODD5T4eH6BMsvtnhbWZ+XQn+Gb6om/917ucvRu7l7ukw==", "dev": true }, + "node_modules/available-typed-arrays": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.7.tgz", + "integrity": "sha512-wvUjBtSGN7+7SjNpq/9M2Tg350UZD3q62IFZLbRAR1bSMlCo1ZaeW+BJ+D090e4hIIZLBcTDWe4Mh4jvUDajzQ==", + "dependencies": { + "possible-typed-array-names": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/babel-jest": { "version": "29.5.0", "resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-29.5.0.tgz", @@ -2108,12 +2240,12 @@ } }, "node_modules/braces": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", - "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", + "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", "dev": true, "dependencies": { - "fill-range": "^7.0.1" + "fill-range": "^7.1.1" }, "engines": { "node": ">=8" @@ -2295,6 +2427,24 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/call-bind": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.7.tgz", + "integrity": "sha512-GHTSNSYICQ7scH7sZ+M2rFopRoLh8t2bLSW6BbgrtLsahOIB5iyAVJf9GjWK3cYTDaMj4XdBpM1cA6pIS0Kv2w==", + "dependencies": { + "es-define-property": "^1.0.0", + "es-errors": "^1.3.0", + "function-bind": "^1.1.2", + "get-intrinsic": "^1.2.4", + "set-function-length": "^1.2.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/callsites": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", @@ -2505,6 +2655,18 @@ "integrity": "sha512-IfEDxwoWIjkeXL1eXcDiow4UbKjhLdq6/EuSVR9GMN7KVH3r9gQ83e73hsz1Nd1T3ijd5xv1wcWRYO+D6kCI2w==", "dev": true }, + "node_modules/combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dev": true, + "dependencies": { + "delayed-stream": "~1.0.0" + }, + "engines": { + "node": ">= 0.8" + } + }, "node_modules/commander": { "version": "11.0.0", "resolved": "https://registry.npmjs.org/commander/-/commander-11.0.0.tgz", @@ -2531,6 +2693,17 @@ "integrity": "sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==", "dev": true }, + "node_modules/core-js": { + "version": "3.37.1", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.37.1.tgz", + "integrity": "sha512-Xn6qmxrQZyB0FFY8E3bgRXei3lWDJHhvI+u0q9TKIYM49G8pAr0FgnnrFRAmsbptZL1yxRADVXn+x5AGsbBfyw==", + "dev": true, + "hasInstallScript": true, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/core-js" + } + }, "node_modules/create-ecdh": { "version": "4.0.4", "resolved": "https://registry.npmjs.org/create-ecdh/-/create-ecdh-4.0.4.tgz", @@ -2615,6 +2788,14 @@ "resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-4.2.0.tgz", "integrity": "sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q==" }, + "node_modules/data-uri-to-buffer": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz", + "integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==", + "engines": { + "node": ">= 12" + } + }, "node_modules/debug": { "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", @@ -2647,6 +2828,31 @@ "node": ">=0.10.0" } }, + "node_modules/define-data-property": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.4.tgz", + "integrity": "sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==", + "dependencies": { + "es-define-property": "^1.0.0", + "es-errors": "^1.3.0", + "gopd": "^1.0.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "dev": true, + "engines": { + "node": ">=0.4.0" + } + }, "node_modules/des.js": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/des.js/-/des.js-1.0.1.tgz", @@ -2801,6 +3007,25 @@ "is-arrayish": "^0.2.1" } }, + "node_modules/es-define-property": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.0.tgz", + "integrity": "sha512-jxayLKShrEqqzJ0eumQbVhTYQM27CfT1T35+gCgDFoL82JLsXqTJ76zv6A0YLOgEnLUMvLzsDsGIrl8NFpT2gQ==", + "dependencies": { + "get-intrinsic": "^1.2.4" + }, + "engines": { + "node": ">= 0.4" + } + }, + "node_modules/es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==", + "engines": { + "node": ">= 0.4" + } + }, "node_modules/es-module-lexer": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-1.2.1.tgz", @@ -2887,6 +3112,28 @@ "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==", "dev": true }, + "node_modules/ethereum-cryptography": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ethereum-cryptography/-/ethereum-cryptography-2.1.3.tgz", + "integrity": "sha512-BlwbIL7/P45W8FGW2r7LGuvoEZ+7PWsniMvQ4p5s2xCyw9tmaDlpfsN9HjAucbF+t/qpVHwZUisgfK24TCW8aA==", + "dependencies": { + "@noble/curves": "1.3.0", + "@noble/hashes": "1.3.3", + "@scure/bip32": "1.3.3", + "@scure/bip39": "1.2.2" + } + }, + "node_modules/ethereum-cryptography/node_modules/@noble/hashes": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.3.tgz", + "integrity": "sha512-V7/fPHgl+jsVPXqqeOzT8egNj2iBIVt+ECeMMG8TdcnTikP3oaBtUVqpT/gYCR68aEBJSF+XbYUxStjbFMqIIA==", + "engines": { + "node": ">= 16" + }, + "funding": { + "url": "https://paulmillr.com/funding/" + } + }, "node_modules/ethers": { "version": "6.6.4", "resolved": "https://registry.npmjs.org/ethers/-/ethers-6.6.4.tgz", @@ -3046,15 +3293,94 @@ "bser": "2.1.1" } }, + "node_modules/fetch-blob": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz", + "integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/jimmywarting" + }, + { + "type": "paypal", + "url": "https://paypal.me/jimmywarting" + } + ], + "dependencies": { + "node-domexception": "^1.0.0", + "web-streams-polyfill": "^3.0.3" + }, + "engines": { + "node": "^12.20 || >= 14.13" + } + }, + "node_modules/fetch-mock": { + "version": "9.11.0", + "resolved": "https://registry.npmjs.org/fetch-mock/-/fetch-mock-9.11.0.tgz", + "integrity": "sha512-PG1XUv+x7iag5p/iNHD4/jdpxL9FtVSqRMUQhPab4hVDt80T1MH5ehzVrL2IdXO9Q2iBggArFvPqjUbHFuI58Q==", + "dev": true, + "dependencies": { + "@babel/core": "^7.0.0", + "@babel/runtime": "^7.0.0", + "core-js": "^3.0.0", + "debug": "^4.1.1", + "glob-to-regexp": "^0.4.0", + "is-subset": "^0.1.1", + "lodash.isequal": "^4.5.0", + "path-to-regexp": "^2.2.1", + "querystring": "^0.2.0", + "whatwg-url": "^6.5.0" + }, + "engines": { + "node": ">=4.0.0" + }, + "funding": { + "type": "charity", + "url": "https://www.justgiving.com/refugee-support-europe" + }, + "peerDependencies": { + "node-fetch": "*" + }, + "peerDependenciesMeta": { + "node-fetch": { + "optional": true + } + } + }, + "node_modules/fetch-mock-jest": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/fetch-mock-jest/-/fetch-mock-jest-1.5.1.tgz", + "integrity": "sha512-+utwzP8C+Pax1GSka3nFXILWMY3Er2L+s090FOgqVNrNCPp0fDqgXnAHAJf12PLHi0z4PhcTaZNTz8e7K3fjqQ==", + "dev": true, + "dependencies": { + "fetch-mock": "^9.11.0" + }, + "engines": { + "node": ">=8.0.0" + }, + "funding": { + "type": "charity", + "url": "https://www.justgiving.com/refugee-support-europe" + }, + "peerDependencies": { + "node-fetch": "*" + }, + "peerDependenciesMeta": { + "node-fetch": { + "optional": true + } + } + }, "node_modules/file-uri-to-path": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==" }, "node_modules/fill-range": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", - "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", + "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", "dev": true, "dependencies": { "to-regex-range": "^5.0.1" @@ -3085,6 +3411,39 @@ "dtype": "^2.0.0" } }, + "node_modules/for-each": { + "version": "0.3.3", + "resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz", + "integrity": "sha512-jqYfLp7mo9vIyQf8ykW2v7A+2N4QjeCeI5+Dz9XraiO1ign81wjiH7Fb9vSOWvQfNtmSa4H2RoQTrrXivdUZmw==", + "dependencies": { + "is-callable": "^1.1.3" + } + }, + "node_modules/form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dev": true, + "dependencies": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/formdata-polyfill": { + "version": "4.0.10", + "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", + "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==", + "dependencies": { + "fetch-blob": "^3.1.2" + }, + "engines": { + "node": ">=12.20.0" + } + }, "node_modules/fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -3106,10 +3465,12 @@ } }, "node_modules/function-bind": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", - "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", - "dev": true + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==", + "funding": { + "url": "https://github.com/sponsors/ljharb" + } }, "node_modules/gensync": { "version": "1.0.0-beta.2", @@ -3129,6 +3490,24 @@ "node": "6.* || 8.* || >= 10.*" } }, + "node_modules/get-intrinsic": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.4.tgz", + "integrity": "sha512-5uYhsJH8VJBTv7oslg4BznJYhDoRI6waYCxMmCdnTrcCrHA/fCFKoTFz2JKKE0HdDFUF7/oQuhzumXJK7paBRQ==", + "dependencies": { + "es-errors": "^1.3.0", + "function-bind": "^1.1.2", + "has-proto": "^1.0.1", + "has-symbols": "^1.0.3", + "hasown": "^2.0.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/get-package-type": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/get-package-type/-/get-package-type-0.1.0.tgz", @@ -3217,6 +3596,17 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/gopd": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", + "integrity": "sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==", + "dependencies": { + "get-intrinsic": "^1.1.3" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/graceful-fs": { "version": "4.2.11", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", @@ -3244,6 +3634,53 @@ "node": ">=8" } }, + "node_modules/has-property-descriptors": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz", + "integrity": "sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg==", + "dependencies": { + "es-define-property": "^1.0.0" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-proto": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.0.3.tgz", + "integrity": "sha512-SJ1amZAJUiZS+PhsVLf5tGydlaVB8EdFpaSO4gmiUKUOxk8qzn5AIy4ZeJUmh22znIdk/uMAUT2pl3FxzVUH+Q==", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-symbols": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", + "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/has-tostringtag": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz", + "integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==", + "dependencies": { + "has-symbols": "^1.0.3" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/hash-base": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/hash-base/-/hash-base-3.1.0.tgz", @@ -3268,6 +3705,17 @@ "minimalistic-assert": "^1.0.1" } }, + "node_modules/hasown": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", + "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==", + "dependencies": { + "function-bind": "^1.1.2" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/hmac-drbg": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/hmac-drbg/-/hmac-drbg-1.0.1.tgz", @@ -3364,8 +3812,7 @@ "node_modules/inherits": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", - "dev": true + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" }, "node_modules/interpret": { "version": "3.1.1", @@ -3376,6 +3823,21 @@ "node": ">=10.13.0" } }, + "node_modules/is-arguments": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/is-arguments/-/is-arguments-1.1.1.tgz", + "integrity": "sha512-8Q7EARjzEnKpt/PCD7e1cgUS0a6X8u5tdSiMqXhojOdoV9TsMsiO+9VLC5vAmO8N7/GmXn7yjR8qnA6bVAEzfA==", + "dependencies": { + "call-bind": "^1.0.2", + "has-tostringtag": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/is-arrayish": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz", @@ -3427,6 +3889,17 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/is-callable": { + "version": "1.2.7", + "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.7.tgz", + "integrity": "sha512-1BC0BVFhS/p0qtw6enp8e+8OD0UrK0oFLztSjNzhcKA3WDuJxxAPXzPuPtKkjEY9UUoEWlX/8fgKeu2S8i9JTA==", + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/is-core-module": { "version": "2.12.0", "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.12.0.tgz", @@ -3466,6 +3939,20 @@ "node": ">=6" } }, + "node_modules/is-generator-function": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/is-generator-function/-/is-generator-function-1.0.10.tgz", + "integrity": "sha512-jsEjy9l3yiXEQ+PsXdmBwEPcOxaXWLspKdplFUVI9vq1iZgIekeC0L167qeu86czQaxed3q/Uzuw0swL0irL8A==", + "dependencies": { + "has-tostringtag": "^1.0.0" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/is-glob": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", @@ -3526,6 +4013,26 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/is-subset": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/is-subset/-/is-subset-0.1.1.tgz", + "integrity": "sha512-6Ybun0IkarhmEqxXCNw/C0bna6Zb/TkfUX9UbwJtK6ObwAVCxmAP308WWTHviM/zAqXk05cdhYsUsZeGQh99iw==", + "dev": true + }, + "node_modules/is-typed-array": { + "version": "1.1.13", + "resolved": "https://registry.npmjs.org/is-typed-array/-/is-typed-array-1.1.13.tgz", + "integrity": "sha512-uZ25/bUAlUY5fR4OKT4rZQEBrzQWYV9ZJYGGsUmEJ6thodVJ1HX64ePQ6Z0qPWP+m+Uq6e9UugrE38jeYsDSMw==", + "dependencies": { + "which-typed-array": "^1.1.14" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", @@ -4316,6 +4823,20 @@ "node": ">=6" } }, + "node_modules/keccak": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/keccak/-/keccak-3.0.4.tgz", + "integrity": "sha512-3vKuW0jV8J3XNTzvfyicFR5qvxrSAGl7KIhvgOu5cmWwM7tZRj3fMbj/pfIf4be7aznbc+prBWGjywox/g2Y6Q==", + "hasInstallScript": true, + "dependencies": { + "node-addon-api": "^2.0.0", + "node-gyp-build": "^4.2.0", + "readable-stream": "^3.6.0" + }, + "engines": { + "node": ">=10.0.0" + } + }, "node_modules/kind-of": { "version": "6.0.3", "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.3.tgz", @@ -4397,12 +4918,24 @@ "node": ">=8" } }, + "node_modules/lodash.isequal": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz", + "integrity": "sha512-pDo3lu8Jhfjqls6GkMgpahsF9kCyayhgykjyLMNFTKWrpVdAQtYyB4muAMWozBB4ig/dtWAmsMxLEI8wuz+DYQ==", + "dev": true + }, "node_modules/lodash.memoize": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-4.1.2.tgz", "integrity": "sha512-t7j+NzmgnQzTAYXcsHYLgimltOV1MXHtlOWf6GjL9Kj8GK5FInw5JotxvbOs+IvV1/Dzo04/fCGfLVs7aXb4Ag==", "dev": true }, + "node_modules/lodash.sortby": { + "version": "4.7.0", + "resolved": "https://registry.npmjs.org/lodash.sortby/-/lodash.sortby-4.7.0.tgz", + "integrity": "sha512-HDWXG8isMntAyRF5vZ7xKuEvOhT4AhlRt/3czTSjvGUxjYCBVRQY48ViDHyfYz9VIoBkW4TMGQNapx+l3RUwdA==", + "dev": true + }, "node_modules/lru-cache": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", @@ -4609,6 +5142,56 @@ "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==", "dev": true }, + "node_modules/node-addon-api": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-2.0.2.tgz", + "integrity": "sha512-Ntyt4AIXyaLIuMHF6IOoTakB3K+RWxwtsHNRxllEoA6vPwP9o4866g6YWDLUdnucilZhmkxiHwHr11gAENw+QA==" + }, + "node_modules/node-domexception": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", + "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/jimmywarting" + }, + { + "type": "github", + "url": "https://paypal.me/jimmywarting" + } + ], + "engines": { + "node": ">=10.5.0" + } + }, + "node_modules/node-fetch": { + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz", + "integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==", + "dependencies": { + "data-uri-to-buffer": "^4.0.0", + "fetch-blob": "^3.1.4", + "formdata-polyfill": "^4.0.10" + }, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/node-fetch" + } + }, + "node_modules/node-gyp-build": { + "version": "4.8.1", + "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.8.1.tgz", + "integrity": "sha512-OSs33Z9yWr148JZcbZd5WiAXhh/n9z8TxQcdMhIOlpN9AhWpLfvVFO73+m77bBABQMaY9XSvIa+qk0jlI7Gcaw==", + "bin": { + "node-gyp-build": "bin.js", + "node-gyp-build-optional": "optional.js", + "node-gyp-build-test": "build-test.js" + } + }, "node_modules/node-int64": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz", @@ -4777,6 +5360,12 @@ "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", "dev": true }, + "node_modules/path-to-regexp": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-2.4.0.tgz", + "integrity": "sha512-G6zHoVqC6GGTQkZwF4lkuEyMbVOjoBKAEybQUypI1WTkqinCOrq2x6U2+phkJ1XsEMTy4LjtwPI7HW+NVrRR2w==", + "dev": true + }, "node_modules/path-type": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz", @@ -4850,6 +5439,14 @@ "queue-lit": "^1.5.0" } }, + "node_modules/possible-typed-array-names": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/possible-typed-array-names/-/possible-typed-array-names-1.0.0.tgz", + "integrity": "sha512-d7Uw+eZoloe0EHDIYoe+bQ5WXnGMOpmiZFTuMWCwpjzzkL2nTjcKiAk4hh8TjnGye2TwWOk3UXucZ+3rbmBa8Q==", + "engines": { + "node": ">= 0.4" + } + }, "node_modules/prettier": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.0.0.tgz", @@ -4955,6 +5552,16 @@ } ] }, + "node_modules/querystring": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/querystring/-/querystring-0.2.1.tgz", + "integrity": "sha512-wkvS7mL/JMugcup3/rMitHmd9ecIGd2lhFhK9N3UUQ450h66d1r3Y9nvXzQAW1Lq+wyx61k/1pfKS5KuKiyEbg==", + "deprecated": "The querystring API is considered Legacy. new code should use the URLSearchParams API instead.", + "dev": true, + "engines": { + "node": ">=0.4.x" + } + }, "node_modules/queue-lit": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/queue-lit/-/queue-lit-1.5.0.tgz", @@ -5010,7 +5617,6 @@ "version": "3.6.2", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", - "dev": true, "dependencies": { "inherits": "^2.0.3", "string_decoder": "^1.1.1", @@ -5044,6 +5650,12 @@ "node": ">= 10.13.0" } }, + "node_modules/regenerator-runtime": { + "version": "0.14.1", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.14.1.tgz", + "integrity": "sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==", + "dev": true + }, "node_modules/require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", @@ -5187,7 +5799,6 @@ "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", - "dev": true, "funding": [ { "type": "github", @@ -5251,6 +5862,22 @@ "randombytes": "^2.1.0" } }, + "node_modules/set-function-length": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.2.2.tgz", + "integrity": "sha512-pgRc4hJ4/sNjWCSS9AmnS40x3bNMDTknHgL5UaMBTMyJnU90EgWh1Rz+MC9eFu4BuN/UwZjKQuY/1v3rM7HMfg==", + "dependencies": { + "define-data-property": "^1.1.4", + "es-errors": "^1.3.0", + "function-bind": "^1.1.2", + "get-intrinsic": "^1.2.4", + "gopd": "^1.0.1", + "has-property-descriptors": "^1.0.2" + }, + "engines": { + "node": ">= 0.4" + } + }, "node_modules/sha.js": { "version": "2.4.11", "resolved": "https://registry.npmjs.org/sha.js/-/sha.js-2.4.11.tgz", @@ -5369,7 +5996,6 @@ "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==", - "dev": true, "dependencies": { "safe-buffer": "~5.2.0" } @@ -5598,10 +6224,19 @@ "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", "dev": true, "dependencies": { - "is-number": "^7.0.0" - }, - "engines": { - "node": ">=8.0" + "is-number": "^7.0.0" + }, + "engines": { + "node": ">=8.0" + } + }, + "node_modules/tr46": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-1.0.1.tgz", + "integrity": "sha512-dTpowEjclQ7Kgx5SdBkqRzVhERQXov8/l9Ft9dVM9fmg0W0KQSVaXX9T4i6twCPNtYiZM53lpSSUAwJbFPOHxA==", + "dev": true, + "dependencies": { + "punycode": "^2.1.0" } }, "node_modules/ts-jest": { @@ -5799,11 +6434,22 @@ } } }, + "node_modules/util": { + "version": "0.12.5", + "resolved": "https://registry.npmjs.org/util/-/util-0.12.5.tgz", + "integrity": "sha512-kZf/K6hEIrWHI6XqOFUiiMa+79wE/D8Q+NCNAWclkyg3b4d2k7s0QGepNjiABc+aR3N1PAyHL7p6UcLY6LmrnA==", + "dependencies": { + "inherits": "^2.0.3", + "is-arguments": "^1.0.4", + "is-generator-function": "^1.0.7", + "is-typed-array": "^1.1.3", + "which-typed-array": "^1.1.2" + } + }, "node_modules/util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", - "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", - "dev": true + "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==" }, "node_modules/v8-to-istanbul": { "version": "9.1.0", @@ -5847,6 +6493,57 @@ "node": ">=10.13.0" } }, + "node_modules/web-streams-polyfill": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.3.3.tgz", + "integrity": "sha512-d2JWLCivmZYTSIoge9MsgFCZrt571BikcWGYkjC1khllbTeDlGqZ2D8vD8E/lJa8WGWbb7Plm8/XJYV7IJHZZw==", + "engines": { + "node": ">= 8" + } + }, + "node_modules/web3-errors": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/web3-errors/-/web3-errors-1.2.0.tgz", + "integrity": "sha512-58Kczou5zyjcm9LuSs5Hrm6VrG8t9p2J8X0yGArZrhKNPZL66gMGkOUpPx+EopE944Sk4yE+Q25hKv4H5BH+kA==", + "dependencies": { + "web3-types": "^1.6.0" + }, + "engines": { + "node": ">=14", + "npm": ">=6.12.0" + } + }, + "node_modules/web3-types": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/web3-types/-/web3-types-1.6.0.tgz", + "integrity": "sha512-qgOtADqlD5hw+KPKBUGaXAcdNLL0oh6qTeVgXwewCfbL/lG9R+/GrgMQB1gbTJ3cit8hMwtH8KX2Em6OwO0HRw==", + "engines": { + "node": ">=14", + "npm": ">=6.12.0" + } + }, + "node_modules/web3-validator": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/web3-validator/-/web3-validator-2.0.6.tgz", + "integrity": "sha512-qn9id0/l1bWmvH4XfnG/JtGKKwut2Vokl6YXP5Kfg424npysmtRLe9DgiNBM9Op7QL/aSiaA0TVXibuIuWcizg==", + "dependencies": { + "ethereum-cryptography": "^2.0.0", + "util": "^0.12.5", + "web3-errors": "^1.2.0", + "web3-types": "^1.6.0", + "zod": "^3.21.4" + }, + "engines": { + "node": ">=14", + "npm": ">=6.12.0" + } + }, + "node_modules/webidl-conversions": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-4.0.2.tgz", + "integrity": "sha512-YQ+BmxuTgd6UXZW3+ICGfyqRyHXVlD5GtQr5+qjiNW7bF0cqrzX500HVXPBOvgXb5YnzDd+h0zqyv61KUD7+Sg==", + "dev": true + }, "node_modules/webpack": { "version": "5.82.1", "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.82.1.tgz", @@ -5970,6 +6667,17 @@ "node": ">=10.13.0" } }, + "node_modules/whatwg-url": { + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-6.5.0.tgz", + "integrity": "sha512-rhRZRqx/TLJQWUpQ6bmrt2UV4f0HCQ463yQuONJqC6fO2VoEb1pTYddbe59SkYq87aoM5A3bdhMZiUiVws+fzQ==", + "dev": true, + "dependencies": { + "lodash.sortby": "^4.7.0", + "tr46": "^1.0.1", + "webidl-conversions": "^4.0.2" + } + }, "node_modules/which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", @@ -5985,6 +6693,24 @@ "node": ">= 8" } }, + "node_modules/which-typed-array": { + "version": "1.1.15", + "resolved": "https://registry.npmjs.org/which-typed-array/-/which-typed-array-1.1.15.tgz", + "integrity": "sha512-oV0jmFtUky6CXfkqehVvBP/LSWJ2sy4vWMioiENyJLePrBO/yKyV9OyJySfAKosh+RYkIl5zJCNZ8/4JncrpdA==", + "dependencies": { + "available-typed-arrays": "^1.0.7", + "call-bind": "^1.0.7", + "for-each": "^0.3.3", + "gopd": "^1.0.1", + "has-tostringtag": "^1.0.2" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/wildcard": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/wildcard/-/wildcard-2.0.1.tgz", @@ -6100,6 +6826,14 @@ "funding": { "url": "https://github.com/sponsors/sindresorhus" } + }, + "node_modules/zod": { + "version": "3.23.8", + "resolved": "https://registry.npmjs.org/zod/-/zod-3.23.8.tgz", + "integrity": "sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g==", + "funding": { + "url": "https://github.com/sponsors/colinhacks" + } } }, "dependencies": { @@ -6581,6 +7315,15 @@ "@babel/helper-plugin-utils": "^7.20.2" } }, + "@babel/runtime": { + "version": "7.24.6", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.24.6.tgz", + "integrity": "sha512-Ja18XcETdEl5mzzACGd+DKgaGJzPTCow7EglgwTmHdwokzDFYh/MHua6lU6DV/hjF2IaOJ4oX2nqnjG7RElKOw==", + "dev": true, + "requires": { + "regenerator-runtime": "^0.14.0" + } + }, "@babel/template": { "version": "7.23.9", "resolved": "https://registry.npmjs.org/@babel/template/-/template-7.23.9.tgz", @@ -6935,6 +7678,21 @@ "@jridgewell/sourcemap-codec": "1.4.14" } }, + "@noble/curves": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/@noble/curves/-/curves-1.3.0.tgz", + "integrity": "sha512-t01iSXPuN+Eqzb4eBX0S5oubSqXbK/xXa1Ne18Hj8f9pStxztHCE2gfboSp/dZRLSqfuLpRK2nDXDK+W9puocA==", + "requires": { + "@noble/hashes": "1.3.3" + }, + "dependencies": { + "@noble/hashes": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.3.tgz", + "integrity": "sha512-V7/fPHgl+jsVPXqqeOzT8egNj2iBIVt+ECeMMG8TdcnTikP3oaBtUVqpT/gYCR68aEBJSF+XbYUxStjbFMqIIA==" + } + } + }, "@noble/hashes": { "version": "1.1.2", "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.1.2.tgz", @@ -7098,6 +7856,44 @@ "picomatch": "^2.3.1" } }, + "@scure/base": { + "version": "1.1.6", + "resolved": "https://registry.npmjs.org/@scure/base/-/base-1.1.6.tgz", + "integrity": "sha512-ok9AWwhcgYuGG3Zfhyqg+zwl+Wn5uE+dwC0NV/2qQkx4dABbb/bx96vWu8NSj+BNjjSjno+JRYRjle1jV08k3g==" + }, + "@scure/bip32": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/@scure/bip32/-/bip32-1.3.3.tgz", + "integrity": "sha512-LJaN3HwRbfQK0X1xFSi0Q9amqOgzQnnDngIt+ZlsBC3Bm7/nE7K0kwshZHyaru79yIVRv/e1mQAjZyuZG6jOFQ==", + "requires": { + "@noble/curves": "~1.3.0", + "@noble/hashes": "~1.3.2", + "@scure/base": "~1.1.4" + }, + "dependencies": { + "@noble/hashes": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.3.tgz", + "integrity": "sha512-V7/fPHgl+jsVPXqqeOzT8egNj2iBIVt+ECeMMG8TdcnTikP3oaBtUVqpT/gYCR68aEBJSF+XbYUxStjbFMqIIA==" + } + } + }, + "@scure/bip39": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/@scure/bip39/-/bip39-1.2.2.tgz", + "integrity": "sha512-HYf9TUXG80beW+hGAt3TRM8wU6pQoYur9iNypTROm42dorCGmLnFe3eWjz3gOq6G62H2WRh0FCzAR1PI+29zIA==", + "requires": { + "@noble/hashes": "~1.3.2", + "@scure/base": "~1.1.4" + }, + "dependencies": { + "@noble/hashes": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.3.tgz", + "integrity": "sha512-V7/fPHgl+jsVPXqqeOzT8egNj2iBIVt+ECeMMG8TdcnTikP3oaBtUVqpT/gYCR68aEBJSF+XbYUxStjbFMqIIA==" + } + } + }, "@sinclair/typebox": { "version": "0.25.24", "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.25.24.tgz", @@ -7238,6 +8034,14 @@ "integrity": "sha512-wOuvG1SN4Us4rez+tylwwwCV1psiNVOkJeM3AUWUNWg/jDQY2+HE/444y5gc+jBmRqASOm2Oeh5c1axHobwRKQ==", "dev": true }, + "@types/keccak": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/@types/keccak/-/keccak-3.0.4.tgz", + "integrity": "sha512-hdnkmbie7tE0yXnQQvlIOqCyjEsoXDVEZ3ACqO+F305XgUOW4Z9ElWdogCXXRAW/khnZ7GxM0t/BGB5bORKt/g==", + "requires": { + "@types/node": "*" + } + }, "@types/libsodium-wrappers": { "version": "0.7.10", "resolved": "https://registry.npmjs.org/@types/libsodium-wrappers/-/libsodium-wrappers-0.7.10.tgz", @@ -7247,8 +8051,17 @@ "@types/node": { "version": "20.1.2", "resolved": "https://registry.npmjs.org/@types/node/-/node-20.1.2.tgz", - "integrity": "sha512-CTO/wa8x+rZU626cL2BlbCDzydgnFNgc19h4YvizpTO88MFQxab8wqisxaofQJ/9bLGugRdWIuX/TbIs6VVF6g==", - "dev": true + "integrity": "sha512-CTO/wa8x+rZU626cL2BlbCDzydgnFNgc19h4YvizpTO88MFQxab8wqisxaofQJ/9bLGugRdWIuX/TbIs6VVF6g==" + }, + "@types/node-fetch": { + "version": "2.6.11", + "resolved": "https://registry.npmjs.org/@types/node-fetch/-/node-fetch-2.6.11.tgz", + "integrity": "sha512-24xFj9R5+rfQJLRyM56qh+wnVSYhyXC2tkoBndtY0U+vubqNsYXGjufB2nn8Q6gt0LrARwL6UBtMCSVCwl4B1g==", + "dev": true, + "requires": { + "@types/node": "*", + "form-data": "^4.0.0" + } }, "@types/prettier": { "version": "2.7.2", @@ -7568,12 +8381,26 @@ } } }, + "asynckit": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", + "integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==", + "dev": true + }, "atob-lite": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/atob-lite/-/atob-lite-2.0.0.tgz", "integrity": "sha512-LEeSAWeh2Gfa2FtlQE1shxQ8zi5F9GHarrGKz08TMdODD5T4eH6BMsvtnhbWZ+XQn+Gb6om/917ucvRu7l7ukw==", "dev": true }, + "available-typed-arrays": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/available-typed-arrays/-/available-typed-arrays-1.0.7.tgz", + "integrity": "sha512-wvUjBtSGN7+7SjNpq/9M2Tg350UZD3q62IFZLbRAR1bSMlCo1ZaeW+BJ+D090e4hIIZLBcTDWe4Mh4jvUDajzQ==", + "requires": { + "possible-typed-array-names": "^1.0.0" + } + }, "babel-jest": { "version": "29.5.0", "resolved": "https://registry.npmjs.org/babel-jest/-/babel-jest-29.5.0.tgz", @@ -7701,12 +8528,12 @@ } }, "braces": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", - "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.3.tgz", + "integrity": "sha512-yQbXgO/OSZVD2IsiLlro+7Hf6Q18EJrKSEsdoMzKePKXct3gvD8oLcOQdIzGupr5Fj+EDe8gO/lxc1BzfMpxvA==", "dev": true, "requires": { - "fill-range": "^7.0.1" + "fill-range": "^7.1.1" } }, "brorand": { @@ -7843,6 +8670,18 @@ "integrity": "sha512-zhaCDicdLuWN5UbN5IMnFqNMhNfo919sH85y2/ea+5Yg9TsTkeZxpL+JLbp6cgYFS4sRLp3YV4S6yDuqVWHYOw==", "dev": true }, + "call-bind": { + "version": "1.0.7", + "resolved": "https://registry.npmjs.org/call-bind/-/call-bind-1.0.7.tgz", + "integrity": "sha512-GHTSNSYICQ7scH7sZ+M2rFopRoLh8t2bLSW6BbgrtLsahOIB5iyAVJf9GjWK3cYTDaMj4XdBpM1cA6pIS0Kv2w==", + "requires": { + "es-define-property": "^1.0.0", + "es-errors": "^1.3.0", + "function-bind": "^1.1.2", + "get-intrinsic": "^1.2.4", + "set-function-length": "^1.2.1" + } + }, "callsites": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", @@ -7987,6 +8826,15 @@ "integrity": "sha512-IfEDxwoWIjkeXL1eXcDiow4UbKjhLdq6/EuSVR9GMN7KVH3r9gQ83e73hsz1Nd1T3ijd5xv1wcWRYO+D6kCI2w==", "dev": true }, + "combined-stream": { + "version": "1.0.8", + "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", + "integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==", + "dev": true, + "requires": { + "delayed-stream": "~1.0.0" + } + }, "commander": { "version": "11.0.0", "resolved": "https://registry.npmjs.org/commander/-/commander-11.0.0.tgz", @@ -8010,6 +8858,12 @@ "integrity": "sha512-Kvp459HrV2FEJ1CAsi1Ku+MY3kasH19TFykTz2xWmMeq6bk2NU3XXvfJ+Q61m0xktWwt+1HSYf3JZsTms3aRJg==", "dev": true }, + "core-js": { + "version": "3.37.1", + "resolved": "https://registry.npmjs.org/core-js/-/core-js-3.37.1.tgz", + "integrity": "sha512-Xn6qmxrQZyB0FFY8E3bgRXei3lWDJHhvI+u0q9TKIYM49G8pAr0FgnnrFRAmsbptZL1yxRADVXn+x5AGsbBfyw==", + "dev": true + }, "create-ecdh": { "version": "4.0.4", "resolved": "https://registry.npmjs.org/create-ecdh/-/create-ecdh-4.0.4.tgz", @@ -8090,6 +8944,11 @@ "resolved": "https://registry.npmjs.org/crypto-js/-/crypto-js-4.2.0.tgz", "integrity": "sha512-KALDyEYgpY+Rlob/iriUtjV6d5Eq+Y191A5g4UqLAi8CyGP9N1+FdVbkc1SxKc2r4YAYqG8JzO2KGL+AizD70Q==" }, + "data-uri-to-buffer": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz", + "integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==" + }, "debug": { "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", @@ -8111,6 +8970,22 @@ "integrity": "sha512-3sUqbMEc77XqpdNO7FRyRog+eW3ph+GYCbj+rK+uYyRMuwsVy0rMiVtPn+QJlKFvWP/1PYpapqYn0Me2knFn+A==", "dev": true }, + "define-data-property": { + "version": "1.1.4", + "resolved": "https://registry.npmjs.org/define-data-property/-/define-data-property-1.1.4.tgz", + "integrity": "sha512-rBMvIzlpA8v6E+SJZoo++HAYqsLrkg7MSfIinMPFhmkorw7X+dOXVJQs+QT69zGkzMyfDnIMN2Wid1+NbL3T+A==", + "requires": { + "es-define-property": "^1.0.0", + "es-errors": "^1.3.0", + "gopd": "^1.0.1" + } + }, + "delayed-stream": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz", + "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", + "dev": true + }, "des.js": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/des.js/-/des.js-1.0.1.tgz", @@ -8239,6 +9114,19 @@ "is-arrayish": "^0.2.1" } }, + "es-define-property": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/es-define-property/-/es-define-property-1.0.0.tgz", + "integrity": "sha512-jxayLKShrEqqzJ0eumQbVhTYQM27CfT1T35+gCgDFoL82JLsXqTJ76zv6A0YLOgEnLUMvLzsDsGIrl8NFpT2gQ==", + "requires": { + "get-intrinsic": "^1.2.4" + } + }, + "es-errors": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/es-errors/-/es-errors-1.3.0.tgz", + "integrity": "sha512-Zf5H2Kxt2xjTvbJvP2ZWLEICxA6j+hAmMzIlypy4xcBg1vKVnx89Wy0GbS+kf5cwCVFFzdCFh2XSCFNULS6csw==" + }, "es-module-lexer": { "version": "1.2.1", "resolved": "https://registry.npmjs.org/es-module-lexer/-/es-module-lexer-1.2.1.tgz", @@ -8302,6 +9190,24 @@ "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==", "dev": true }, + "ethereum-cryptography": { + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/ethereum-cryptography/-/ethereum-cryptography-2.1.3.tgz", + "integrity": "sha512-BlwbIL7/P45W8FGW2r7LGuvoEZ+7PWsniMvQ4p5s2xCyw9tmaDlpfsN9HjAucbF+t/qpVHwZUisgfK24TCW8aA==", + "requires": { + "@noble/curves": "1.3.0", + "@noble/hashes": "1.3.3", + "@scure/bip32": "1.3.3", + "@scure/bip39": "1.2.2" + }, + "dependencies": { + "@noble/hashes": { + "version": "1.3.3", + "resolved": "https://registry.npmjs.org/@noble/hashes/-/hashes-1.3.3.tgz", + "integrity": "sha512-V7/fPHgl+jsVPXqqeOzT8egNj2iBIVt+ECeMMG8TdcnTikP3oaBtUVqpT/gYCR68aEBJSF+XbYUxStjbFMqIIA==" + } + } + }, "ethers": { "version": "6.6.4", "resolved": "https://registry.npmjs.org/ethers/-/ethers-6.6.4.tgz", @@ -8429,15 +9335,51 @@ "bser": "2.1.1" } }, + "fetch-blob": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz", + "integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==", + "requires": { + "node-domexception": "^1.0.0", + "web-streams-polyfill": "^3.0.3" + } + }, + "fetch-mock": { + "version": "9.11.0", + "resolved": "https://registry.npmjs.org/fetch-mock/-/fetch-mock-9.11.0.tgz", + "integrity": "sha512-PG1XUv+x7iag5p/iNHD4/jdpxL9FtVSqRMUQhPab4hVDt80T1MH5ehzVrL2IdXO9Q2iBggArFvPqjUbHFuI58Q==", + "dev": true, + "requires": { + "@babel/core": "^7.0.0", + "@babel/runtime": "^7.0.0", + "core-js": "^3.0.0", + "debug": "^4.1.1", + "glob-to-regexp": "^0.4.0", + "is-subset": "^0.1.1", + "lodash.isequal": "^4.5.0", + "path-to-regexp": "^2.2.1", + "querystring": "^0.2.0", + "whatwg-url": "^6.5.0" + } + }, + "fetch-mock-jest": { + "version": "1.5.1", + "resolved": "https://registry.npmjs.org/fetch-mock-jest/-/fetch-mock-jest-1.5.1.tgz", + "integrity": "sha512-+utwzP8C+Pax1GSka3nFXILWMY3Er2L+s090FOgqVNrNCPp0fDqgXnAHAJf12PLHi0z4PhcTaZNTz8e7K3fjqQ==", + "dev": true, + "requires": { + "fetch-mock": "^9.11.0" + } + }, "file-uri-to-path": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz", "integrity": "sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw==" }, "fill-range": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", - "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "version": "7.1.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.1.1.tgz", + "integrity": "sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==", "dev": true, "requires": { "to-regex-range": "^5.0.1" @@ -8462,6 +9404,33 @@ "dtype": "^2.0.0" } }, + "for-each": { + "version": "0.3.3", + "resolved": "https://registry.npmjs.org/for-each/-/for-each-0.3.3.tgz", + "integrity": "sha512-jqYfLp7mo9vIyQf8ykW2v7A+2N4QjeCeI5+Dz9XraiO1ign81wjiH7Fb9vSOWvQfNtmSa4H2RoQTrrXivdUZmw==", + "requires": { + "is-callable": "^1.1.3" + } + }, + "form-data": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz", + "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==", + "dev": true, + "requires": { + "asynckit": "^0.4.0", + "combined-stream": "^1.0.8", + "mime-types": "^2.1.12" + } + }, + "formdata-polyfill": { + "version": "4.0.10", + "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", + "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==", + "requires": { + "fetch-blob": "^3.1.2" + } + }, "fs.realpath": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", @@ -8476,10 +9445,9 @@ "optional": true }, "function-bind": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz", - "integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==", - "dev": true + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.2.tgz", + "integrity": "sha512-7XHNxH7qX9xG5mIwxkhumTox/MIRNcOgDrxWsMt2pAr23WHp6MrRlN7FBSFpCpr+oVO0F744iUgR82nJMfG2SA==" }, "gensync": { "version": "1.0.0-beta.2", @@ -8493,6 +9461,18 @@ "integrity": "sha512-DyFP3BM/3YHTQOCUL/w0OZHR0lpKeGrxotcHWcqNEdnltqFwXVfhEBQ94eIo34AfQpo0rGki4cyIiftY06h2Fg==", "dev": true }, + "get-intrinsic": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/get-intrinsic/-/get-intrinsic-1.2.4.tgz", + "integrity": "sha512-5uYhsJH8VJBTv7oslg4BznJYhDoRI6waYCxMmCdnTrcCrHA/fCFKoTFz2JKKE0HdDFUF7/oQuhzumXJK7paBRQ==", + "requires": { + "es-errors": "^1.3.0", + "function-bind": "^1.1.2", + "has-proto": "^1.0.1", + "has-symbols": "^1.0.3", + "hasown": "^2.0.0" + } + }, "get-package-type": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/get-package-type/-/get-package-type-0.1.0.tgz", @@ -8554,6 +9534,14 @@ "slash": "^3.0.0" } }, + "gopd": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/gopd/-/gopd-1.0.1.tgz", + "integrity": "sha512-d65bNlIadxvpb/A2abVdlqKqV563juRnZ1Wtk6s1sIR8uNsXR70xqIzVqxVf1eTqDunwT2MkczEeaezCKTZhwA==", + "requires": { + "get-intrinsic": "^1.1.3" + } + }, "graceful-fs": { "version": "4.2.11", "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz", @@ -8575,6 +9563,32 @@ "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==", "dev": true }, + "has-property-descriptors": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/has-property-descriptors/-/has-property-descriptors-1.0.2.tgz", + "integrity": "sha512-55JNKuIW+vq4Ke1BjOTjM2YctQIvCT7GFzHwmfZPGo5wnrgkid0YQtnAleFSqumZm4az3n2BS+erby5ipJdgrg==", + "requires": { + "es-define-property": "^1.0.0" + } + }, + "has-proto": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has-proto/-/has-proto-1.0.3.tgz", + "integrity": "sha512-SJ1amZAJUiZS+PhsVLf5tGydlaVB8EdFpaSO4gmiUKUOxk8qzn5AIy4ZeJUmh22znIdk/uMAUT2pl3FxzVUH+Q==" + }, + "has-symbols": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/has-symbols/-/has-symbols-1.0.3.tgz", + "integrity": "sha512-l3LCuF6MgDNwTDKkdYGEihYjt5pRPbEg46rtlmnSPlUbgmB8LOIrKJbYYFBSbnPaJexMKtiPO8hmeRjRz2Td+A==" + }, + "has-tostringtag": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/has-tostringtag/-/has-tostringtag-1.0.2.tgz", + "integrity": "sha512-NqADB8VjPFLM2V0VvHUewwwsw0ZWBaIdgo+ieHtK3hasLz4qeCRjYcqfB6AQrBggRKppKF8L52/VqdVsO47Dlw==", + "requires": { + "has-symbols": "^1.0.3" + } + }, "hash-base": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/hash-base/-/hash-base-3.1.0.tgz", @@ -8596,6 +9610,14 @@ "minimalistic-assert": "^1.0.1" } }, + "hasown": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/hasown/-/hasown-2.0.2.tgz", + "integrity": "sha512-0hJU9SCPvmMzIBdZFqNPXWa6dqh7WdH0cII9y+CyS8rG3nL48Bclra9HmKhVVUHyPWNH5Y7xDwAB7bfgSjkUMQ==", + "requires": { + "function-bind": "^1.1.2" + } + }, "hmac-drbg": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/hmac-drbg/-/hmac-drbg-1.0.1.tgz", @@ -8660,8 +9682,7 @@ "inherits": { "version": "2.0.4", "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", - "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", - "dev": true + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" }, "interpret": { "version": "3.1.1", @@ -8669,6 +9690,15 @@ "integrity": "sha512-6xwYfHbajpoF0xLW+iwLkhwgvLoZDfjYfoFNu8ftMoXINzwuymNLd9u/KmwtdT2GbR+/Cz66otEGEVVUHX9QLQ==", "dev": true }, + "is-arguments": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/is-arguments/-/is-arguments-1.1.1.tgz", + "integrity": "sha512-8Q7EARjzEnKpt/PCD7e1cgUS0a6X8u5tdSiMqXhojOdoV9TsMsiO+9VLC5vAmO8N7/GmXn7yjR8qnA6bVAEzfA==", + "requires": { + "call-bind": "^1.0.2", + "has-tostringtag": "^1.0.0" + } + }, "is-arrayish": { "version": "0.2.1", "resolved": "https://registry.npmjs.org/is-arrayish/-/is-arrayish-0.2.1.tgz", @@ -8705,6 +9735,11 @@ "builtin-modules": "^3.3.0" } }, + "is-callable": { + "version": "1.2.7", + "resolved": "https://registry.npmjs.org/is-callable/-/is-callable-1.2.7.tgz", + "integrity": "sha512-1BC0BVFhS/p0qtw6enp8e+8OD0UrK0oFLztSjNzhcKA3WDuJxxAPXzPuPtKkjEY9UUoEWlX/8fgKeu2S8i9JTA==" + }, "is-core-module": { "version": "2.12.0", "resolved": "https://registry.npmjs.org/is-core-module/-/is-core-module-2.12.0.tgz", @@ -8732,6 +9767,14 @@ "integrity": "sha512-cTIB4yPYL/Grw0EaSzASzg6bBy9gqCofvWN8okThAYIxKJZC+udlRAmGbM0XLeniEJSs8uEgHPGuHSe1XsOLSQ==", "dev": true }, + "is-generator-function": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/is-generator-function/-/is-generator-function-1.0.10.tgz", + "integrity": "sha512-jsEjy9l3yiXEQ+PsXdmBwEPcOxaXWLspKdplFUVI9vq1iZgIekeC0L167qeu86czQaxed3q/Uzuw0swL0irL8A==", + "requires": { + "has-tostringtag": "^1.0.0" + } + }, "is-glob": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", @@ -8777,6 +9820,20 @@ "integrity": "sha512-hFoiJiTl63nn+kstHGBtewWSKnQLpyb155KHheA1l39uvtO9nWIop1p3udqPcUd/xbF1VLMO4n7OI6p7RbngDg==", "dev": true }, + "is-subset": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/is-subset/-/is-subset-0.1.1.tgz", + "integrity": "sha512-6Ybun0IkarhmEqxXCNw/C0bna6Zb/TkfUX9UbwJtK6ObwAVCxmAP308WWTHviM/zAqXk05cdhYsUsZeGQh99iw==", + "dev": true + }, + "is-typed-array": { + "version": "1.1.13", + "resolved": "https://registry.npmjs.org/is-typed-array/-/is-typed-array-1.1.13.tgz", + "integrity": "sha512-uZ25/bUAlUY5fR4OKT4rZQEBrzQWYV9ZJYGGsUmEJ6thodVJ1HX64ePQ6Z0qPWP+m+Uq6e9UugrE38jeYsDSMw==", + "requires": { + "which-typed-array": "^1.1.14" + } + }, "isexe": { "version": "2.0.0", "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", @@ -9391,6 +10448,16 @@ "integrity": "sha512-XmOWe7eyHYH14cLdVPoyg+GOH3rYX++KpzrylJwSW98t3Nk+U8XOl8FWKOgwtzdb8lXGf6zYwDUzeHMWfxasyg==", "dev": true }, + "keccak": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/keccak/-/keccak-3.0.4.tgz", + "integrity": "sha512-3vKuW0jV8J3XNTzvfyicFR5qvxrSAGl7KIhvgOu5cmWwM7tZRj3fMbj/pfIf4be7aznbc+prBWGjywox/g2Y6Q==", + "requires": { + "node-addon-api": "^2.0.0", + "node-gyp-build": "^4.2.0", + "readable-stream": "^3.6.0" + } + }, "kind-of": { "version": "6.0.3", "resolved": "https://registry.npmjs.org/kind-of/-/kind-of-6.0.3.tgz", @@ -9454,12 +10521,24 @@ "p-locate": "^4.1.0" } }, + "lodash.isequal": { + "version": "4.5.0", + "resolved": "https://registry.npmjs.org/lodash.isequal/-/lodash.isequal-4.5.0.tgz", + "integrity": "sha512-pDo3lu8Jhfjqls6GkMgpahsF9kCyayhgykjyLMNFTKWrpVdAQtYyB4muAMWozBB4ig/dtWAmsMxLEI8wuz+DYQ==", + "dev": true + }, "lodash.memoize": { "version": "4.1.2", "resolved": "https://registry.npmjs.org/lodash.memoize/-/lodash.memoize-4.1.2.tgz", "integrity": "sha512-t7j+NzmgnQzTAYXcsHYLgimltOV1MXHtlOWf6GjL9Kj8GK5FInw5JotxvbOs+IvV1/Dzo04/fCGfLVs7aXb4Ag==", "dev": true }, + "lodash.sortby": { + "version": "4.7.0", + "resolved": "https://registry.npmjs.org/lodash.sortby/-/lodash.sortby-4.7.0.tgz", + "integrity": "sha512-HDWXG8isMntAyRF5vZ7xKuEvOhT4AhlRt/3czTSjvGUxjYCBVRQY48ViDHyfYz9VIoBkW4TMGQNapx+l3RUwdA==", + "dev": true + }, "lru-cache": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", @@ -9627,6 +10706,31 @@ "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==", "dev": true }, + "node-addon-api": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-2.0.2.tgz", + "integrity": "sha512-Ntyt4AIXyaLIuMHF6IOoTakB3K+RWxwtsHNRxllEoA6vPwP9o4866g6YWDLUdnucilZhmkxiHwHr11gAENw+QA==" + }, + "node-domexception": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", + "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==" + }, + "node-fetch": { + "version": "3.3.2", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.2.tgz", + "integrity": "sha512-dRB78srN/l6gqWulah9SrxeYnxeddIG30+GOqK/9OlLVyLg3HPnr6SqOWTWOXKRwC2eGYCkZ59NNuSgvSrpgOA==", + "requires": { + "data-uri-to-buffer": "^4.0.0", + "fetch-blob": "^3.1.4", + "formdata-polyfill": "^4.0.10" + } + }, + "node-gyp-build": { + "version": "4.8.1", + "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.8.1.tgz", + "integrity": "sha512-OSs33Z9yWr148JZcbZd5WiAXhh/n9z8TxQcdMhIOlpN9AhWpLfvVFO73+m77bBABQMaY9XSvIa+qk0jlI7Gcaw==" + }, "node-int64": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz", @@ -9756,6 +10860,12 @@ "integrity": "sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==", "dev": true }, + "path-to-regexp": { + "version": "2.4.0", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-2.4.0.tgz", + "integrity": "sha512-G6zHoVqC6GGTQkZwF4lkuEyMbVOjoBKAEybQUypI1WTkqinCOrq2x6U2+phkJ1XsEMTy4LjtwPI7HW+NVrRR2w==", + "dev": true + }, "path-type": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/path-type/-/path-type-4.0.0.tgz", @@ -9811,6 +10921,11 @@ "queue-lit": "^1.5.0" } }, + "possible-typed-array-names": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/possible-typed-array-names/-/possible-typed-array-names-1.0.0.tgz", + "integrity": "sha512-d7Uw+eZoloe0EHDIYoe+bQ5WXnGMOpmiZFTuMWCwpjzzkL2nTjcKiAk4hh8TjnGye2TwWOk3UXucZ+3rbmBa8Q==" + }, "prettier": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.0.0.tgz", @@ -9886,6 +11001,12 @@ "integrity": "sha512-6Yg0ekpKICSjPswYOuC5sku/TSWaRYlA0qsXqJgM/d/4pLPHPuTxK7Nbf7jFKzAeedUhR8C7K9Uv63FBsSo8xQ==", "dev": true }, + "querystring": { + "version": "0.2.1", + "resolved": "https://registry.npmjs.org/querystring/-/querystring-0.2.1.tgz", + "integrity": "sha512-wkvS7mL/JMugcup3/rMitHmd9ecIGd2lhFhK9N3UUQ450h66d1r3Y9nvXzQAW1Lq+wyx61k/1pfKS5KuKiyEbg==", + "dev": true + }, "queue-lit": { "version": "1.5.0", "resolved": "https://registry.npmjs.org/queue-lit/-/queue-lit-1.5.0.tgz", @@ -9927,7 +11048,6 @@ "version": "3.6.2", "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", - "dev": true, "requires": { "inherits": "^2.0.3", "string_decoder": "^1.1.1", @@ -9952,6 +11072,12 @@ "resolve": "^1.20.0" } }, + "regenerator-runtime": { + "version": "0.14.1", + "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.14.1.tgz", + "integrity": "sha512-dYnhHh0nJoMfnkZs6GmmhFknAGRrLznOu5nc9ML+EJxGvrx6H7teuevqVqCuPcPK//3eDrrjQhehXVx9cnkGdw==", + "dev": true + }, "require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", @@ -10048,8 +11174,7 @@ "safe-buffer": { "version": "5.2.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", - "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", - "dev": true + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==" }, "safer-buffer": { "version": "2.1.2", @@ -10086,6 +11211,19 @@ "randombytes": "^2.1.0" } }, + "set-function-length": { + "version": "1.2.2", + "resolved": "https://registry.npmjs.org/set-function-length/-/set-function-length-1.2.2.tgz", + "integrity": "sha512-pgRc4hJ4/sNjWCSS9AmnS40x3bNMDTknHgL5UaMBTMyJnU90EgWh1Rz+MC9eFu4BuN/UwZjKQuY/1v3rM7HMfg==", + "requires": { + "define-data-property": "^1.1.4", + "es-errors": "^1.3.0", + "function-bind": "^1.1.2", + "get-intrinsic": "^1.2.4", + "gopd": "^1.0.1", + "has-property-descriptors": "^1.0.2" + } + }, "sha.js": { "version": "2.4.11", "resolved": "https://registry.npmjs.org/sha.js/-/sha.js-2.4.11.tgz", @@ -10183,7 +11321,6 @@ "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==", - "dev": true, "requires": { "safe-buffer": "~5.2.0" } @@ -10348,6 +11485,15 @@ "is-number": "^7.0.0" } }, + "tr46": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-1.0.1.tgz", + "integrity": "sha512-dTpowEjclQ7Kgx5SdBkqRzVhERQXov8/l9Ft9dVM9fmg0W0KQSVaXX9T4i6twCPNtYiZM53lpSSUAwJbFPOHxA==", + "dev": true, + "requires": { + "punycode": "^2.1.0" + } + }, "ts-jest": { "version": "29.1.0", "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-29.1.0.tgz", @@ -10453,11 +11599,22 @@ "schema-utils": "^3.0.0" } }, + "util": { + "version": "0.12.5", + "resolved": "https://registry.npmjs.org/util/-/util-0.12.5.tgz", + "integrity": "sha512-kZf/K6hEIrWHI6XqOFUiiMa+79wE/D8Q+NCNAWclkyg3b4d2k7s0QGepNjiABc+aR3N1PAyHL7p6UcLY6LmrnA==", + "requires": { + "inherits": "^2.0.3", + "is-arguments": "^1.0.4", + "is-generator-function": "^1.0.7", + "is-typed-array": "^1.1.3", + "which-typed-array": "^1.1.2" + } + }, "util-deprecate": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", - "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==", - "dev": true + "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==" }, "v8-to-istanbul": { "version": "9.1.0", @@ -10497,6 +11654,42 @@ "graceful-fs": "^4.1.2" } }, + "web-streams-polyfill": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.3.3.tgz", + "integrity": "sha512-d2JWLCivmZYTSIoge9MsgFCZrt571BikcWGYkjC1khllbTeDlGqZ2D8vD8E/lJa8WGWbb7Plm8/XJYV7IJHZZw==" + }, + "web3-errors": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/web3-errors/-/web3-errors-1.2.0.tgz", + "integrity": "sha512-58Kczou5zyjcm9LuSs5Hrm6VrG8t9p2J8X0yGArZrhKNPZL66gMGkOUpPx+EopE944Sk4yE+Q25hKv4H5BH+kA==", + "requires": { + "web3-types": "^1.6.0" + } + }, + "web3-types": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/web3-types/-/web3-types-1.6.0.tgz", + "integrity": "sha512-qgOtADqlD5hw+KPKBUGaXAcdNLL0oh6qTeVgXwewCfbL/lG9R+/GrgMQB1gbTJ3cit8hMwtH8KX2Em6OwO0HRw==" + }, + "web3-validator": { + "version": "2.0.6", + "resolved": "https://registry.npmjs.org/web3-validator/-/web3-validator-2.0.6.tgz", + "integrity": "sha512-qn9id0/l1bWmvH4XfnG/JtGKKwut2Vokl6YXP5Kfg424npysmtRLe9DgiNBM9Op7QL/aSiaA0TVXibuIuWcizg==", + "requires": { + "ethereum-cryptography": "^2.0.0", + "util": "^0.12.5", + "web3-errors": "^1.2.0", + "web3-types": "^1.6.0", + "zod": "^3.21.4" + } + }, + "webidl-conversions": { + "version": "4.0.2", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-4.0.2.tgz", + "integrity": "sha512-YQ+BmxuTgd6UXZW3+ICGfyqRyHXVlD5GtQr5+qjiNW7bF0cqrzX500HVXPBOvgXb5YnzDd+h0zqyv61KUD7+Sg==", + "dev": true + }, "webpack": { "version": "5.82.1", "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.82.1.tgz", @@ -10574,6 +11767,17 @@ "integrity": "sha512-/DyMEOrDgLKKIG0fmvtz+4dUX/3Ghozwgm6iPp8KRhvn+eQf9+Q7GWxVNMk3+uCPWfdXYC4ExGBckIXdFEfH1w==", "dev": true }, + "whatwg-url": { + "version": "6.5.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-6.5.0.tgz", + "integrity": "sha512-rhRZRqx/TLJQWUpQ6bmrt2UV4f0HCQ463yQuONJqC6fO2VoEb1pTYddbe59SkYq87aoM5A3bdhMZiUiVws+fzQ==", + "dev": true, + "requires": { + "lodash.sortby": "^4.7.0", + "tr46": "^1.0.1", + "webidl-conversions": "^4.0.2" + } + }, "which": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", @@ -10583,6 +11787,18 @@ "isexe": "^2.0.0" } }, + "which-typed-array": { + "version": "1.1.15", + "resolved": "https://registry.npmjs.org/which-typed-array/-/which-typed-array-1.1.15.tgz", + "integrity": "sha512-oV0jmFtUky6CXfkqehVvBP/LSWJ2sy4vWMioiENyJLePrBO/yKyV9OyJySfAKosh+RYkIl5zJCNZ8/4JncrpdA==", + "requires": { + "available-typed-arrays": "^1.0.7", + "call-bind": "^1.0.7", + "for-each": "^0.3.3", + "gopd": "^1.0.1", + "has-tostringtag": "^1.0.2" + } + }, "wildcard": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/wildcard/-/wildcard-2.0.1.tgz", @@ -10660,6 +11876,11 @@ "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", "integrity": "sha512-rVksvsnNCdJ/ohGc6xgPwyN8eheCxsiLM8mxuE/t/mOVqJewPuO1miLpTHQiRgTKCLexL4MeAFVagts7HmNZ2Q==", "dev": true + }, + "zod": { + "version": "3.23.8", + "resolved": "https://registry.npmjs.org/zod/-/zod-3.23.8.tgz", + "integrity": "sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g==" } } } diff --git a/package.json b/package.json index 4fee09a..8317013 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "fhevmjs", - "version": "0.5.0-1", + "version": "0.5.0-2", "description": "fhEVM SDK for blockchain using TFHE", "main": "lib/node.cjs", "types": "lib/node.d.ts", @@ -43,14 +43,18 @@ }, "homepage": "https://github.com/zama-ai/fhevmjs#readme", "dependencies": { + "@types/keccak": "^3.0.4", "bigint-buffer": "^1.1.5", "commander": "^11.0.0", "crypto-js": "^4.1.1", "ethers": "^6.6.4", + "keccak": "^3.0.4", "libsodium": "^0.7.11", "libsodium-wrappers": "^0.7.11", + "node-fetch": "^3.3.2", "node-tfhe": "^0.6.1", - "tfhe": "^0.6.1" + "tfhe": "^0.6.1", + "web3-validator": "^2.0.6" }, "devDependencies": { "@rollup/plugin-alias": "^5.0.0", @@ -61,8 +65,10 @@ "@rollup/plugin-wasm": "^6.1.3", "@types/jest": "^29.5.1", "@types/libsodium-wrappers": "^0.7.10", + "@types/node-fetch": "^2.6.11", "buffer": "^6.0.3", "crypto-browserify": "^3.12.0", + "fetch-mock-jest": "^1.5.1", "jest": "^29.5.0", "jest-raw-loader": "^1.0.1", "path-browserify": "^1.0.1", diff --git a/src/ethCall.ts b/src/ethCall.ts new file mode 100644 index 0000000..53cf9e1 --- /dev/null +++ b/src/ethCall.ts @@ -0,0 +1,44 @@ +import { toHexString } from './utils'; + +export function decodeAbiBytes(hex: string): Uint8Array { + if (hex.startsWith('0x')) { + hex = hex.substring(2); + } + // The data offset is the first 32 bytes, which points to the start of the data (skip this part) + const dataOffset = parseInt(hex.substring(0, 64), 16) * 2; // Convert offset from bytes to characters + + // The length of the data is the next 32 bytes, starting from the offset + const dataLength = + parseInt(hex.substring(dataOffset, dataOffset + 64), 16) * 2; // Convert length from bytes to characters + + // Extract the data + const data = hex.substring(dataOffset + 64, dataOffset + 64 + dataLength); + + // Convert the extracted data from hex to Uint8Array + const bytes = new Uint8Array(data.length / 2); + for (let i = 0, j = 0; i < data.length; i += 2, j++) { + bytes[j] = parseInt(data.substring(i, i + 2), 16); + } + + return bytes; +} + +export const fetchJSONRPC = async (url: string, options: RequestInit) => { + try { + const response = await fetch(url, options); + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + const data = await response.json(); + if (data && data.result) { + // The result is usually prefixed with '0x' and is in hex format + const hexResult = data.result; + const decodedBytes = decodeAbiBytes(hexResult); + return `0x${toHexString(decodedBytes)}`; + } else { + console.error('No result from blockchain call'); + } + } catch (error) { + console.error('Error performing eth_call:', error); + } +}; diff --git a/src/kms/node/index.js b/src/kms/node/index.js new file mode 100644 index 0000000..9a4cd55 --- /dev/null +++ b/src/kms/node/index.js @@ -0,0 +1 @@ +export * from './kms_lib'; diff --git a/src/kms/node/kms_lib.d.ts b/src/kms/node/kms_lib.d.ts new file mode 100644 index 0000000..dca1618 --- /dev/null +++ b/src/kms/node/kms_lib.d.ts @@ -0,0 +1,293 @@ +/* tslint:disable */ +/* eslint-disable */ +/** +* @param {(PublicSigKey)[]} server_pks +* @param {PublicSigKey} client_pk +* @param {number} shares_needed +* @param {string} params_json +* @returns {Client} +*/ +export function new_client(server_pks: (PublicSigKey)[], client_pk: PublicSigKey, shares_needed: number, params_json: string): Client; +/** +* @returns {PrivateEncKey} +*/ +export function cryptobox_keygen(): PrivateEncKey; +/** +* @param {PrivateEncKey} sk +* @returns {PublicEncKey} +*/ +export function cryptobox_get_pk(sk: PrivateEncKey): PublicEncKey; +/** +* @param {PublicEncKey} pk +* @returns {Uint8Array} +*/ +export function cryptobox_pk_to_u8vec(pk: PublicEncKey): Uint8Array; +/** +* @param {PrivateEncKey} sk +* @returns {Uint8Array} +*/ +export function cryptobox_sk_to_u8vec(sk: PrivateEncKey): Uint8Array; +/** +* @param {Uint8Array} v +* @returns {PublicEncKey} +*/ +export function u8vec_to_cryptobox_pk(v: Uint8Array): PublicEncKey; +/** +* @param {Uint8Array} v +* @returns {PrivateEncKey} +*/ +export function u8vec_to_cryptobox_sk(v: Uint8Array): PrivateEncKey; +/** +* @param {Uint8Array} msg +* @param {PublicEncKey} their_pk +* @param {PrivateEncKey} my_sk +* @returns {CryptoBoxCt} +*/ +export function cryptobox_encrypt(msg: Uint8Array, their_pk: PublicEncKey, my_sk: PrivateEncKey): CryptoBoxCt; +/** +* @param {CryptoBoxCt} ct +* @param {PrivateEncKey} my_sk +* @param {PublicEncKey} their_pk +* @returns {Uint8Array} +*/ +export function cryptobox_decrypt(ct: CryptoBoxCt, my_sk: PrivateEncKey, their_pk: PublicEncKey): Uint8Array; +/** +* This function assembles [ReencryptionRequest] +* from a signature and other metadata. +* The signature is on the ephemeral public key +* signed by the client's private key +* following the EIP712 standard. +* @param {Client} client +* @param {Uint8Array} signature +* @param {PublicEncKey} enc_pk +* @param {FheType} fhe_type +* @param {RequestId} key_id +* @param {Uint8Array} ciphertext_digest +* @param {Eip712DomainMsg} domain +* @returns {ReencryptionRequest} +*/ +export function make_reencryption_req(client: Client, signature: Uint8Array, enc_pk: PublicEncKey, fhe_type: FheType, key_id: RequestId, ciphertext_digest: Uint8Array, domain: Eip712DomainMsg): ReencryptionRequest; +/** +* This function takes [AggregatedReencryptionResponse] normally +* but wasm does not support HashMap so we need to take two parameters: +* `agg_resp` and `agg_resp_id`. +* @param {Client} client +* @param {ReencryptionRequest | undefined} request +* @param {(ReencryptionResponse)[]} agg_resp +* @param {Uint32Array} agg_resp_ids +* @param {PublicEncKey} enc_pk +* @param {PrivateEncKey} enc_sk +* @returns {number} +*/ +export function process_reencryption_resp(client: Client, request: ReencryptionRequest | undefined, agg_resp: (ReencryptionResponse)[], agg_resp_ids: Uint32Array, enc_pk: PublicEncKey, enc_sk: PrivateEncKey): number; +/** +* The plaintext types that can be encrypted in a fhevm ciphertext. +*/ +export enum FheType { + Bool = 0, + Euint4 = 1, + Euint8 = 2, + Euint16 = 3, + Euint32 = 4, + Euint64 = 5, + Euint128 = 6, + Euint160 = 7, +} +/** +* Simple client to interact with the KMS servers. This can be seen as a proof-of-concept +* and reference code for validating the KMS. The logic supplied by the client will be +* distributed accross the aggregator/proxy and smart contracts. +* TODO should probably aggregate the KmsEndpointClient to void having two client code bases +* exposed in tests and MVP +* +* client_sk is optional because sometimes the private signing key is kept +* in a secure location, e.g., hardware wallet. Calling functions that requires +* client_sk when it is None will return an error. +*/ +export class Client { + free(): void; +} +/** +*/ +export class CryptoBoxCt { + free(): void; +} +/** +* +* eventually chain_id, verifying_contract and salt will be parsed in to solidity types +*/ +export class Eip712DomainMsg { + free(): void; +/** +*/ + chain_id: Uint8Array; +/** +*/ + name: string; +/** +*/ + salt: Uint8Array; +/** +*/ + verifying_contract: string; +/** +*/ + version: string; +} +/** +*/ +export class Plaintext { + free(): void; +/** +*/ + higest_bits: number; +/** +*/ + lowest_bits: bigint; +/** +*/ + middle_bits: bigint; +} +/** +*/ +export class PrivateEncKey { + free(): void; +} +/** +*/ +export class PrivateSigKey { + free(): void; +} +/** +*/ +export class PublicEncKey { + free(): void; +} +/** +*/ +export class PublicSigKey { + free(): void; +} +/** +*/ +export class ReencryptionRequest { + free(): void; +/** +*/ + domain?: Eip712DomainMsg; +/** +*/ + payload?: ReencryptionRequestPayload; +/** +* The ID that identifies this request. +* Future queries for the result must use this request ID. +*/ + request_id?: RequestId; +/** +* Signature of the ASN1 DER serialization of \[ReencryptionRequestPayload\]. +*/ + signature: Uint8Array; +} +/** +*/ +export class ReencryptionRequestPayload { + free(): void; +/** +* The actual ciphertext to decrypt, taken directly from the fhevm. +* When creating the payload, this field may be empty, +* it is the responsibility of the gateway to fetch the +* ciphertext for the given digest below. +*/ + ciphertext?: Uint8Array; +/** +* The SHA3 digest of the ciphertext above. +*/ + ciphertext_digest: Uint8Array; +/** +* Encoding of the user's public encryption key for this request. +* Encoding using the default encoding of libsodium, i.e. the 32 bytes of a +* Montgomery point. +*/ + enc_key: Uint8Array; +/** +* The type of plaintext encrypted. +*/ + fhe_type: number; +/** +* The key id to use for decryption. Will be the request_id used during key generation +*/ + key_id?: RequestId; +/** +* Randomness specified in the request to ensure EU-CMA of the signed response. +* TODO check that we don't need two types of randomness. One for the reuqest and one for the response +* TODO also check potential risk with repeated calls +*/ + randomness: Uint8Array; +/** +* The amount of shares needed to recombine the result. +* This implies the threshold used. +* Needed to avoid a single malicious server taking over a request that should +* have been distributed. +*/ + servers_needed: number; +/** +* The server's signature verification key. +* Encoded using SEC1. +* TODO not needed in the request! Should be removed +*/ + verification_key: Uint8Array; +/** +* Version of the request format. +*/ + version: number; +} +/** +*/ +export class ReencryptionResponse { + free(): void; +/** +* Digest of the request validated. +* Needed to ensure that the response is for the expected request. +*/ + digest: Uint8Array; +/** +* The type of plaintext encrypted. +*/ + fhe_type: number; +/** +* Servers_needed are not really needed since there is a link to the +* digest, however, it seems better to be able to handle a response without +* getting data from the request as well. but this is also a security issue +* since it is possible to get meaning from the response without directly +* linking it to a request +* +* The amount of shares needed to recombine the result. +* This implies the threshold used. +*/ + servers_needed: number; +/** +* The signcrypted payload, using a hybrid encryption approach in +* sign-then-encrypt. +*/ + signcrypted_ciphertext: Uint8Array; +/** +* The server's signature verification key. +* Encoded using SEC1. +* Needed to validate the response, but MUST also be linked to a list of +* trusted keys. +*/ + verification_key: Uint8Array; +/** +* Version of the response format. +*/ + version: number; +} +/** +* Simple response to return an ID, to be used to retrieve the computed result later on. +*/ +export class RequestId { + free(): void; +/** +*/ + request_id: string; +} diff --git a/src/kms/node/kms_lib.js b/src/kms/node/kms_lib.js new file mode 100644 index 0000000..e4b6af5 --- /dev/null +++ b/src/kms/node/kms_lib.js @@ -0,0 +1,1783 @@ +let imports = {}; +imports['__wbindgen_placeholder__'] = module.exports; +let wasm; +const { TextDecoder, TextEncoder } = require(`util`); + +const heap = new Array(128).fill(undefined); + +heap.push(undefined, null, true, false); + +function getObject(idx) { + return heap[idx]; +} + +let heap_next = heap.length; + +function dropObject(idx) { + if (idx < 132) return; + heap[idx] = heap_next; + heap_next = idx; +} + +function takeObject(idx) { + const ret = getObject(idx); + dropObject(idx); + return ret; +} + +let cachedTextDecoder = new TextDecoder('utf-8', { + ignoreBOM: true, + fatal: true, +}); + +cachedTextDecoder.decode(); + +let cachedUint8Memory0 = null; + +function getUint8Memory0() { + if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) { + cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer); + } + return cachedUint8Memory0; +} + +function getStringFromWasm0(ptr, len) { + ptr = ptr >>> 0; + return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len)); +} + +function addHeapObject(obj) { + if (heap_next === heap.length) heap.push(heap.length + 1); + const idx = heap_next; + heap_next = heap[idx]; + + heap[idx] = obj; + return idx; +} + +let cachedInt32Memory0 = null; + +function getInt32Memory0() { + if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) { + cachedInt32Memory0 = new Int32Array(wasm.memory.buffer); + } + return cachedInt32Memory0; +} + +let WASM_VECTOR_LEN = 0; + +let cachedTextEncoder = new TextEncoder('utf-8'); + +const encodeString = + typeof cachedTextEncoder.encodeInto === 'function' + ? function (arg, view) { + return cachedTextEncoder.encodeInto(arg, view); + } + : function (arg, view) { + const buf = cachedTextEncoder.encode(arg); + view.set(buf); + return { + read: arg.length, + written: buf.length, + }; + }; + +function passStringToWasm0(arg, malloc, realloc) { + if (realloc === undefined) { + const buf = cachedTextEncoder.encode(arg); + const ptr = malloc(buf.length, 1) >>> 0; + getUint8Memory0() + .subarray(ptr, ptr + buf.length) + .set(buf); + WASM_VECTOR_LEN = buf.length; + return ptr; + } + + let len = arg.length; + let ptr = malloc(len, 1) >>> 0; + + const mem = getUint8Memory0(); + + let offset = 0; + + for (; offset < len; offset++) { + const code = arg.charCodeAt(offset); + if (code > 0x7f) break; + mem[ptr + offset] = code; + } + + if (offset !== len) { + if (offset !== 0) { + arg = arg.slice(offset); + } + ptr = realloc(ptr, len, (len = offset + arg.length * 3), 1) >>> 0; + const view = getUint8Memory0().subarray(ptr + offset, ptr + len); + const ret = encodeString(arg, view); + + offset += ret.written; + ptr = realloc(ptr, len, offset, 1) >>> 0; + } + + WASM_VECTOR_LEN = offset; + return ptr; +} + +function getArrayU8FromWasm0(ptr, len) { + ptr = ptr >>> 0; + return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len); +} + +function passArray8ToWasm0(arg, malloc) { + const ptr = malloc(arg.length * 1, 1) >>> 0; + getUint8Memory0().set(arg, ptr / 1); + WASM_VECTOR_LEN = arg.length; + return ptr; +} + +function isLikeNone(x) { + return x === undefined || x === null; +} + +function _assertClass(instance, klass) { + if (!(instance instanceof klass)) { + throw new Error(`expected instance of ${klass.name}`); + } + return instance.ptr; +} + +let cachedUint32Memory0 = null; + +function getUint32Memory0() { + if (cachedUint32Memory0 === null || cachedUint32Memory0.byteLength === 0) { + cachedUint32Memory0 = new Uint32Array(wasm.memory.buffer); + } + return cachedUint32Memory0; +} + +function passArrayJsValueToWasm0(array, malloc) { + const ptr = malloc(array.length * 4, 4) >>> 0; + const mem = getUint32Memory0(); + for (let i = 0; i < array.length; i++) { + mem[ptr / 4 + i] = addHeapObject(array[i]); + } + WASM_VECTOR_LEN = array.length; + return ptr; +} +/** + * @param {(PublicSigKey)[]} server_pks + * @param {PublicSigKey} client_pk + * @param {number} shares_needed + * @param {string} params_json + * @returns {Client} + */ +module.exports.new_client = function ( + server_pks, + client_pk, + shares_needed, + params_json, +) { + const ptr0 = passArrayJsValueToWasm0(server_pks, wasm.__wbindgen_malloc); + const len0 = WASM_VECTOR_LEN; + _assertClass(client_pk, PublicSigKey); + var ptr1 = client_pk.__destroy_into_raw(); + const ptr2 = passStringToWasm0( + params_json, + wasm.__wbindgen_malloc, + wasm.__wbindgen_realloc, + ); + const len2 = WASM_VECTOR_LEN; + const ret = wasm.new_client(ptr0, len0, ptr1, shares_needed, ptr2, len2); + return Client.__wrap(ret); +}; + +/** + * @returns {PrivateEncKey} + */ +module.exports.cryptobox_keygen = function () { + const ret = wasm.cryptobox_keygen(); + return PrivateEncKey.__wrap(ret); +}; + +/** + * @param {PrivateEncKey} sk + * @returns {PublicEncKey} + */ +module.exports.cryptobox_get_pk = function (sk) { + _assertClass(sk, PrivateEncKey); + const ret = wasm.cryptobox_get_pk(sk.__wbg_ptr); + return PublicEncKey.__wrap(ret); +}; + +/** + * @param {PublicEncKey} pk + * @returns {Uint8Array} + */ +module.exports.cryptobox_pk_to_u8vec = function (pk) { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + _assertClass(pk, PublicEncKey); + wasm.cryptobox_pk_to_u8vec(retptr, pk.__wbg_ptr); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + var r2 = getInt32Memory0()[retptr / 4 + 2]; + var r3 = getInt32Memory0()[retptr / 4 + 3]; + if (r3) { + throw takeObject(r2); + } + var v1 = getArrayU8FromWasm0(r0, r1).slice(); + wasm.__wbindgen_free(r0, r1 * 1, 1); + return v1; + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } +}; + +/** + * @param {PrivateEncKey} sk + * @returns {Uint8Array} + */ +module.exports.cryptobox_sk_to_u8vec = function (sk) { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + _assertClass(sk, PrivateEncKey); + wasm.cryptobox_sk_to_u8vec(retptr, sk.__wbg_ptr); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + var r2 = getInt32Memory0()[retptr / 4 + 2]; + var r3 = getInt32Memory0()[retptr / 4 + 3]; + if (r3) { + throw takeObject(r2); + } + var v1 = getArrayU8FromWasm0(r0, r1).slice(); + wasm.__wbindgen_free(r0, r1 * 1, 1); + return v1; + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } +}; + +/** + * @param {Uint8Array} v + * @returns {PublicEncKey} + */ +module.exports.u8vec_to_cryptobox_pk = function (v) { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + const ptr0 = passArray8ToWasm0(v, wasm.__wbindgen_malloc); + const len0 = WASM_VECTOR_LEN; + wasm.u8vec_to_cryptobox_pk(retptr, ptr0, len0); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + var r2 = getInt32Memory0()[retptr / 4 + 2]; + if (r2) { + throw takeObject(r1); + } + return PublicEncKey.__wrap(r0); + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } +}; + +/** + * @param {Uint8Array} v + * @returns {PrivateEncKey} + */ +module.exports.u8vec_to_cryptobox_sk = function (v) { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + const ptr0 = passArray8ToWasm0(v, wasm.__wbindgen_malloc); + const len0 = WASM_VECTOR_LEN; + wasm.u8vec_to_cryptobox_sk(retptr, ptr0, len0); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + var r2 = getInt32Memory0()[retptr / 4 + 2]; + if (r2) { + throw takeObject(r1); + } + return PrivateEncKey.__wrap(r0); + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } +}; + +/** + * @param {Uint8Array} msg + * @param {PublicEncKey} their_pk + * @param {PrivateEncKey} my_sk + * @returns {CryptoBoxCt} + */ +module.exports.cryptobox_encrypt = function (msg, their_pk, my_sk) { + const ptr0 = passArray8ToWasm0(msg, wasm.__wbindgen_malloc); + const len0 = WASM_VECTOR_LEN; + _assertClass(their_pk, PublicEncKey); + _assertClass(my_sk, PrivateEncKey); + const ret = wasm.cryptobox_encrypt( + ptr0, + len0, + their_pk.__wbg_ptr, + my_sk.__wbg_ptr, + ); + return CryptoBoxCt.__wrap(ret); +}; + +/** + * @param {CryptoBoxCt} ct + * @param {PrivateEncKey} my_sk + * @param {PublicEncKey} their_pk + * @returns {Uint8Array} + */ +module.exports.cryptobox_decrypt = function (ct, my_sk, their_pk) { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + _assertClass(ct, CryptoBoxCt); + _assertClass(my_sk, PrivateEncKey); + _assertClass(their_pk, PublicEncKey); + wasm.cryptobox_decrypt( + retptr, + ct.__wbg_ptr, + my_sk.__wbg_ptr, + their_pk.__wbg_ptr, + ); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + var v1 = getArrayU8FromWasm0(r0, r1).slice(); + wasm.__wbindgen_free(r0, r1 * 1, 1); + return v1; + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } +}; + +/** + * This function assembles [ReencryptionRequest] + * from a signature and other metadata. + * The signature is on the ephemeral public key + * signed by the client's private key + * following the EIP712 standard. + * @param {Client} client + * @param {Uint8Array} signature + * @param {PublicEncKey} enc_pk + * @param {FheType} fhe_type + * @param {RequestId} key_id + * @param {Uint8Array} ciphertext_digest + * @param {Eip712DomainMsg} domain + * @returns {ReencryptionRequest} + */ +module.exports.make_reencryption_req = function ( + client, + signature, + enc_pk, + fhe_type, + key_id, + ciphertext_digest, + domain, +) { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + _assertClass(client, Client); + const ptr0 = passArray8ToWasm0(signature, wasm.__wbindgen_malloc); + const len0 = WASM_VECTOR_LEN; + _assertClass(enc_pk, PublicEncKey); + var ptr1 = enc_pk.__destroy_into_raw(); + _assertClass(key_id, RequestId); + var ptr2 = key_id.__destroy_into_raw(); + const ptr3 = passArray8ToWasm0(ciphertext_digest, wasm.__wbindgen_malloc); + const len3 = WASM_VECTOR_LEN; + _assertClass(domain, Eip712DomainMsg); + var ptr4 = domain.__destroy_into_raw(); + wasm.make_reencryption_req( + retptr, + client.__wbg_ptr, + ptr0, + len0, + ptr1, + fhe_type, + ptr2, + ptr3, + len3, + ptr4, + ); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + var r2 = getInt32Memory0()[retptr / 4 + 2]; + if (r2) { + throw takeObject(r1); + } + return ReencryptionRequest.__wrap(r0); + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } +}; + +function passArray32ToWasm0(arg, malloc) { + const ptr = malloc(arg.length * 4, 4) >>> 0; + getUint32Memory0().set(arg, ptr / 4); + WASM_VECTOR_LEN = arg.length; + return ptr; +} +/** + * This function takes [AggregatedReencryptionResponse] normally + * but wasm does not support HashMap so we need to take two parameters: + * `agg_resp` and `agg_resp_id`. + * @param {Client} client + * @param {ReencryptionRequest | undefined} request + * @param {(ReencryptionResponse)[]} agg_resp + * @param {Uint32Array} agg_resp_ids + * @param {PublicEncKey} enc_pk + * @param {PrivateEncKey} enc_sk + * @returns {number} + */ +module.exports.process_reencryption_resp = function ( + client, + request, + agg_resp, + agg_resp_ids, + enc_pk, + enc_sk, +) { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + _assertClass(client, Client); + let ptr0 = 0; + if (!isLikeNone(request)) { + _assertClass(request, ReencryptionRequest); + ptr0 = request.__destroy_into_raw(); + } + const ptr1 = passArrayJsValueToWasm0(agg_resp, wasm.__wbindgen_malloc); + const len1 = WASM_VECTOR_LEN; + const ptr2 = passArray32ToWasm0(agg_resp_ids, wasm.__wbindgen_malloc); + const len2 = WASM_VECTOR_LEN; + _assertClass(enc_pk, PublicEncKey); + _assertClass(enc_sk, PrivateEncKey); + wasm.process_reencryption_resp( + retptr, + client.__wbg_ptr, + ptr0, + ptr1, + len1, + ptr2, + len2, + enc_pk.__wbg_ptr, + enc_sk.__wbg_ptr, + ); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + var r2 = getInt32Memory0()[retptr / 4 + 2]; + if (r2) { + throw takeObject(r1); + } + return r0; + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } +}; + +function handleError(f, args) { + try { + return f.apply(this, args); + } catch (e) { + wasm.__wbindgen_exn_store(addHeapObject(e)); + } +} +/** + * The plaintext types that can be encrypted in a fhevm ciphertext. + */ +module.exports.FheType = Object.freeze({ + Bool: 0, + 0: 'Bool', + Euint4: 1, + 1: 'Euint4', + Euint8: 2, + 2: 'Euint8', + Euint16: 3, + 3: 'Euint16', + Euint32: 4, + 4: 'Euint32', + Euint64: 5, + 5: 'Euint64', + Euint128: 6, + 6: 'Euint128', + Euint160: 7, + 7: 'Euint160', +}); + +const ClientFinalization = + typeof FinalizationRegistry === 'undefined' + ? { register: () => {}, unregister: () => {} } + : new FinalizationRegistry((ptr) => wasm.__wbg_client_free(ptr >>> 0)); +/** + * Simple client to interact with the KMS servers. This can be seen as a proof-of-concept + * and reference code for validating the KMS. The logic supplied by the client will be + * distributed accross the aggregator/proxy and smart contracts. + * TODO should probably aggregate the KmsEndpointClient to void having two client code bases + * exposed in tests and MVP + * + * client_sk is optional because sometimes the private signing key is kept + * in a secure location, e.g., hardware wallet. Calling functions that requires + * client_sk when it is None will return an error. + */ +class Client { + static __wrap(ptr) { + ptr = ptr >>> 0; + const obj = Object.create(Client.prototype); + obj.__wbg_ptr = ptr; + ClientFinalization.register(obj, obj.__wbg_ptr, obj); + return obj; + } + + __destroy_into_raw() { + const ptr = this.__wbg_ptr; + this.__wbg_ptr = 0; + ClientFinalization.unregister(this); + return ptr; + } + + free() { + const ptr = this.__destroy_into_raw(); + wasm.__wbg_client_free(ptr); + } +} +module.exports.Client = Client; + +const CryptoBoxCtFinalization = + typeof FinalizationRegistry === 'undefined' + ? { register: () => {}, unregister: () => {} } + : new FinalizationRegistry((ptr) => wasm.__wbg_cryptoboxct_free(ptr >>> 0)); +/** + */ +class CryptoBoxCt { + static __wrap(ptr) { + ptr = ptr >>> 0; + const obj = Object.create(CryptoBoxCt.prototype); + obj.__wbg_ptr = ptr; + CryptoBoxCtFinalization.register(obj, obj.__wbg_ptr, obj); + return obj; + } + + __destroy_into_raw() { + const ptr = this.__wbg_ptr; + this.__wbg_ptr = 0; + CryptoBoxCtFinalization.unregister(this); + return ptr; + } + + free() { + const ptr = this.__destroy_into_raw(); + wasm.__wbg_cryptoboxct_free(ptr); + } +} +module.exports.CryptoBoxCt = CryptoBoxCt; + +const Eip712DomainMsgFinalization = + typeof FinalizationRegistry === 'undefined' + ? { register: () => {}, unregister: () => {} } + : new FinalizationRegistry((ptr) => + wasm.__wbg_eip712domainmsg_free(ptr >>> 0), + ); +/** + * + * eventually chain_id, verifying_contract and salt will be parsed in to solidity types + */ +class Eip712DomainMsg { + static __wrap(ptr) { + ptr = ptr >>> 0; + const obj = Object.create(Eip712DomainMsg.prototype); + obj.__wbg_ptr = ptr; + Eip712DomainMsgFinalization.register(obj, obj.__wbg_ptr, obj); + return obj; + } + + __destroy_into_raw() { + const ptr = this.__wbg_ptr; + this.__wbg_ptr = 0; + Eip712DomainMsgFinalization.unregister(this); + return ptr; + } + + free() { + const ptr = this.__destroy_into_raw(); + wasm.__wbg_eip712domainmsg_free(ptr); + } + /** + * @returns {string} + */ + get name() { + let deferred1_0; + let deferred1_1; + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + wasm.__wbg_get_eip712domainmsg_name(retptr, this.__wbg_ptr); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + deferred1_0 = r0; + deferred1_1 = r1; + return getStringFromWasm0(r0, r1); + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + wasm.__wbindgen_free(deferred1_0, deferred1_1, 1); + } + } + /** + * @param {string} arg0 + */ + set name(arg0) { + const ptr0 = passStringToWasm0( + arg0, + wasm.__wbindgen_malloc, + wasm.__wbindgen_realloc, + ); + const len0 = WASM_VECTOR_LEN; + wasm.__wbg_set_eip712domainmsg_name(this.__wbg_ptr, ptr0, len0); + } + /** + * @returns {string} + */ + get version() { + let deferred1_0; + let deferred1_1; + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + wasm.__wbg_get_eip712domainmsg_version(retptr, this.__wbg_ptr); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + deferred1_0 = r0; + deferred1_1 = r1; + return getStringFromWasm0(r0, r1); + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + wasm.__wbindgen_free(deferred1_0, deferred1_1, 1); + } + } + /** + * @param {string} arg0 + */ + set version(arg0) { + const ptr0 = passStringToWasm0( + arg0, + wasm.__wbindgen_malloc, + wasm.__wbindgen_realloc, + ); + const len0 = WASM_VECTOR_LEN; + wasm.__wbg_set_eip712domainmsg_version(this.__wbg_ptr, ptr0, len0); + } + /** + * @returns {Uint8Array} + */ + get chain_id() { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + wasm.__wbg_get_eip712domainmsg_chain_id(retptr, this.__wbg_ptr); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + var v1 = getArrayU8FromWasm0(r0, r1).slice(); + wasm.__wbindgen_free(r0, r1 * 1, 1); + return v1; + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } + } + /** + * @param {Uint8Array} arg0 + */ + set chain_id(arg0) { + const ptr0 = passArray8ToWasm0(arg0, wasm.__wbindgen_malloc); + const len0 = WASM_VECTOR_LEN; + wasm.__wbg_set_eip712domainmsg_chain_id(this.__wbg_ptr, ptr0, len0); + } + /** + * @returns {string} + */ + get verifying_contract() { + let deferred1_0; + let deferred1_1; + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + wasm.__wbg_get_eip712domainmsg_verifying_contract(retptr, this.__wbg_ptr); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + deferred1_0 = r0; + deferred1_1 = r1; + return getStringFromWasm0(r0, r1); + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + wasm.__wbindgen_free(deferred1_0, deferred1_1, 1); + } + } + /** + * @param {string} arg0 + */ + set verifying_contract(arg0) { + const ptr0 = passStringToWasm0( + arg0, + wasm.__wbindgen_malloc, + wasm.__wbindgen_realloc, + ); + const len0 = WASM_VECTOR_LEN; + wasm.__wbg_set_eip712domainmsg_verifying_contract( + this.__wbg_ptr, + ptr0, + len0, + ); + } + /** + * @returns {Uint8Array} + */ + get salt() { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + wasm.__wbg_get_eip712domainmsg_salt(retptr, this.__wbg_ptr); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + var v1 = getArrayU8FromWasm0(r0, r1).slice(); + wasm.__wbindgen_free(r0, r1 * 1, 1); + return v1; + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } + } + /** + * @param {Uint8Array} arg0 + */ + set salt(arg0) { + const ptr0 = passArray8ToWasm0(arg0, wasm.__wbindgen_malloc); + const len0 = WASM_VECTOR_LEN; + wasm.__wbg_set_eip712domainmsg_salt(this.__wbg_ptr, ptr0, len0); + } +} +module.exports.Eip712DomainMsg = Eip712DomainMsg; + +const PlaintextFinalization = + typeof FinalizationRegistry === 'undefined' + ? { register: () => {}, unregister: () => {} } + : new FinalizationRegistry((ptr) => wasm.__wbg_plaintext_free(ptr >>> 0)); +/** + */ +class Plaintext { + __destroy_into_raw() { + const ptr = this.__wbg_ptr; + this.__wbg_ptr = 0; + PlaintextFinalization.unregister(this); + return ptr; + } + + free() { + const ptr = this.__destroy_into_raw(); + wasm.__wbg_plaintext_free(ptr); + } + /** + * @returns {bigint} + */ + get lowest_bits() { + const ret = wasm.__wbg_get_plaintext_lowest_bits(this.__wbg_ptr); + return BigInt.asUintN(64, ret); + } + /** + * @param {bigint} arg0 + */ + set lowest_bits(arg0) { + wasm.__wbg_set_plaintext_lowest_bits(this.__wbg_ptr, arg0); + } + /** + * @returns {bigint} + */ + get middle_bits() { + const ret = wasm.__wbg_get_plaintext_middle_bits(this.__wbg_ptr); + return BigInt.asUintN(64, ret); + } + /** + * @param {bigint} arg0 + */ + set middle_bits(arg0) { + wasm.__wbg_set_plaintext_middle_bits(this.__wbg_ptr, arg0); + } + /** + * @returns {number} + */ + get higest_bits() { + const ret = wasm.__wbg_get_plaintext_higest_bits(this.__wbg_ptr); + return ret >>> 0; + } + /** + * @param {number} arg0 + */ + set higest_bits(arg0) { + wasm.__wbg_set_plaintext_higest_bits(this.__wbg_ptr, arg0); + } +} +module.exports.Plaintext = Plaintext; + +const PrivateEncKeyFinalization = + typeof FinalizationRegistry === 'undefined' + ? { register: () => {}, unregister: () => {} } + : new FinalizationRegistry((ptr) => + wasm.__wbg_privateenckey_free(ptr >>> 0), + ); +/** + */ +class PrivateEncKey { + static __wrap(ptr) { + ptr = ptr >>> 0; + const obj = Object.create(PrivateEncKey.prototype); + obj.__wbg_ptr = ptr; + PrivateEncKeyFinalization.register(obj, obj.__wbg_ptr, obj); + return obj; + } + + __destroy_into_raw() { + const ptr = this.__wbg_ptr; + this.__wbg_ptr = 0; + PrivateEncKeyFinalization.unregister(this); + return ptr; + } + + free() { + const ptr = this.__destroy_into_raw(); + wasm.__wbg_privateenckey_free(ptr); + } +} +module.exports.PrivateEncKey = PrivateEncKey; + +const PrivateSigKeyFinalization = + typeof FinalizationRegistry === 'undefined' + ? { register: () => {}, unregister: () => {} } + : new FinalizationRegistry((ptr) => + wasm.__wbg_privatesigkey_free(ptr >>> 0), + ); +/** + */ +class PrivateSigKey { + __destroy_into_raw() { + const ptr = this.__wbg_ptr; + this.__wbg_ptr = 0; + PrivateSigKeyFinalization.unregister(this); + return ptr; + } + + free() { + const ptr = this.__destroy_into_raw(); + wasm.__wbg_privatesigkey_free(ptr); + } +} +module.exports.PrivateSigKey = PrivateSigKey; + +const PublicEncKeyFinalization = + typeof FinalizationRegistry === 'undefined' + ? { register: () => {}, unregister: () => {} } + : new FinalizationRegistry((ptr) => + wasm.__wbg_publicenckey_free(ptr >>> 0), + ); +/** + */ +class PublicEncKey { + static __wrap(ptr) { + ptr = ptr >>> 0; + const obj = Object.create(PublicEncKey.prototype); + obj.__wbg_ptr = ptr; + PublicEncKeyFinalization.register(obj, obj.__wbg_ptr, obj); + return obj; + } + + __destroy_into_raw() { + const ptr = this.__wbg_ptr; + this.__wbg_ptr = 0; + PublicEncKeyFinalization.unregister(this); + return ptr; + } + + free() { + const ptr = this.__destroy_into_raw(); + wasm.__wbg_publicenckey_free(ptr); + } +} +module.exports.PublicEncKey = PublicEncKey; + +const PublicSigKeyFinalization = + typeof FinalizationRegistry === 'undefined' + ? { register: () => {}, unregister: () => {} } + : new FinalizationRegistry((ptr) => + wasm.__wbg_publicsigkey_free(ptr >>> 0), + ); +/** + */ +class PublicSigKey { + static __unwrap(jsValue) { + if (!(jsValue instanceof PublicSigKey)) { + return 0; + } + return jsValue.__destroy_into_raw(); + } + + __destroy_into_raw() { + const ptr = this.__wbg_ptr; + this.__wbg_ptr = 0; + PublicSigKeyFinalization.unregister(this); + return ptr; + } + + free() { + const ptr = this.__destroy_into_raw(); + wasm.__wbg_publicsigkey_free(ptr); + } +} +module.exports.PublicSigKey = PublicSigKey; + +const ReencryptionRequestFinalization = + typeof FinalizationRegistry === 'undefined' + ? { register: () => {}, unregister: () => {} } + : new FinalizationRegistry((ptr) => + wasm.__wbg_reencryptionrequest_free(ptr >>> 0), + ); +/** + */ +class ReencryptionRequest { + static __wrap(ptr) { + ptr = ptr >>> 0; + const obj = Object.create(ReencryptionRequest.prototype); + obj.__wbg_ptr = ptr; + ReencryptionRequestFinalization.register(obj, obj.__wbg_ptr, obj); + return obj; + } + + __destroy_into_raw() { + const ptr = this.__wbg_ptr; + this.__wbg_ptr = 0; + ReencryptionRequestFinalization.unregister(this); + return ptr; + } + + free() { + const ptr = this.__destroy_into_raw(); + wasm.__wbg_reencryptionrequest_free(ptr); + } + /** + * Signature of the ASN1 DER serialization of \[ReencryptionRequestPayload\]. + * @returns {Uint8Array} + */ + get signature() { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + wasm.__wbg_get_reencryptionrequest_signature(retptr, this.__wbg_ptr); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + var v1 = getArrayU8FromWasm0(r0, r1).slice(); + wasm.__wbindgen_free(r0, r1 * 1, 1); + return v1; + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } + } + /** + * Signature of the ASN1 DER serialization of \[ReencryptionRequestPayload\]. + * @param {Uint8Array} arg0 + */ + set signature(arg0) { + const ptr0 = passArray8ToWasm0(arg0, wasm.__wbindgen_malloc); + const len0 = WASM_VECTOR_LEN; + wasm.__wbg_set_eip712domainmsg_name(this.__wbg_ptr, ptr0, len0); + } + /** + * @returns {ReencryptionRequestPayload | undefined} + */ + get payload() { + const ret = wasm.__wbg_get_reencryptionrequest_payload(this.__wbg_ptr); + return ret === 0 ? undefined : ReencryptionRequestPayload.__wrap(ret); + } + /** + * @param {ReencryptionRequestPayload | undefined} [arg0] + */ + set payload(arg0) { + let ptr0 = 0; + if (!isLikeNone(arg0)) { + _assertClass(arg0, ReencryptionRequestPayload); + ptr0 = arg0.__destroy_into_raw(); + } + wasm.__wbg_set_reencryptionrequest_payload(this.__wbg_ptr, ptr0); + } + /** + * @returns {Eip712DomainMsg | undefined} + */ + get domain() { + const ret = wasm.__wbg_get_reencryptionrequest_domain(this.__wbg_ptr); + return ret === 0 ? undefined : Eip712DomainMsg.__wrap(ret); + } + /** + * @param {Eip712DomainMsg | undefined} [arg0] + */ + set domain(arg0) { + let ptr0 = 0; + if (!isLikeNone(arg0)) { + _assertClass(arg0, Eip712DomainMsg); + ptr0 = arg0.__destroy_into_raw(); + } + wasm.__wbg_set_reencryptionrequest_domain(this.__wbg_ptr, ptr0); + } + /** + * The ID that identifies this request. + * Future queries for the result must use this request ID. + * @returns {RequestId | undefined} + */ + get request_id() { + const ret = wasm.__wbg_get_reencryptionrequest_request_id(this.__wbg_ptr); + return ret === 0 ? undefined : RequestId.__wrap(ret); + } + /** + * The ID that identifies this request. + * Future queries for the result must use this request ID. + * @param {RequestId | undefined} [arg0] + */ + set request_id(arg0) { + let ptr0 = 0; + if (!isLikeNone(arg0)) { + _assertClass(arg0, RequestId); + ptr0 = arg0.__destroy_into_raw(); + } + wasm.__wbg_set_reencryptionrequest_request_id(this.__wbg_ptr, ptr0); + } +} +module.exports.ReencryptionRequest = ReencryptionRequest; + +const ReencryptionRequestPayloadFinalization = + typeof FinalizationRegistry === 'undefined' + ? { register: () => {}, unregister: () => {} } + : new FinalizationRegistry((ptr) => + wasm.__wbg_reencryptionrequestpayload_free(ptr >>> 0), + ); +/** + */ +class ReencryptionRequestPayload { + static __wrap(ptr) { + ptr = ptr >>> 0; + const obj = Object.create(ReencryptionRequestPayload.prototype); + obj.__wbg_ptr = ptr; + ReencryptionRequestPayloadFinalization.register(obj, obj.__wbg_ptr, obj); + return obj; + } + + __destroy_into_raw() { + const ptr = this.__wbg_ptr; + this.__wbg_ptr = 0; + ReencryptionRequestPayloadFinalization.unregister(this); + return ptr; + } + + free() { + const ptr = this.__destroy_into_raw(); + wasm.__wbg_reencryptionrequestpayload_free(ptr); + } + /** + * Version of the request format. + * @returns {number} + */ + get version() { + const ret = wasm.__wbg_get_reencryptionrequestpayload_version( + this.__wbg_ptr, + ); + return ret >>> 0; + } + /** + * Version of the request format. + * @param {number} arg0 + */ + set version(arg0) { + wasm.__wbg_set_reencryptionrequestpayload_version(this.__wbg_ptr, arg0); + } + /** + * The amount of shares needed to recombine the result. + * This implies the threshold used. + * Needed to avoid a single malicious server taking over a request that should + * have been distributed. + * @returns {number} + */ + get servers_needed() { + const ret = wasm.__wbg_get_reencryptionrequestpayload_servers_needed( + this.__wbg_ptr, + ); + return ret >>> 0; + } + /** + * The amount of shares needed to recombine the result. + * This implies the threshold used. + * Needed to avoid a single malicious server taking over a request that should + * have been distributed. + * @param {number} arg0 + */ + set servers_needed(arg0) { + wasm.__wbg_set_reencryptionrequestpayload_servers_needed( + this.__wbg_ptr, + arg0, + ); + } + /** + * The server's signature verification key. + * Encoded using SEC1. + * TODO not needed in the request! Should be removed + * @returns {Uint8Array} + */ + get verification_key() { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + wasm.__wbg_get_reencryptionrequest_signature(retptr, this.__wbg_ptr); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + var v1 = getArrayU8FromWasm0(r0, r1).slice(); + wasm.__wbindgen_free(r0, r1 * 1, 1); + return v1; + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } + } + /** + * The server's signature verification key. + * Encoded using SEC1. + * TODO not needed in the request! Should be removed + * @param {Uint8Array} arg0 + */ + set verification_key(arg0) { + const ptr0 = passArray8ToWasm0(arg0, wasm.__wbindgen_malloc); + const len0 = WASM_VECTOR_LEN; + wasm.__wbg_set_eip712domainmsg_name(this.__wbg_ptr, ptr0, len0); + } + /** + * Randomness specified in the request to ensure EU-CMA of the signed response. + * TODO check that we don't need two types of randomness. One for the reuqest and one for the response + * TODO also check potential risk with repeated calls + * @returns {Uint8Array} + */ + get randomness() { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + wasm.__wbg_get_reencryptionrequestpayload_randomness( + retptr, + this.__wbg_ptr, + ); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + var v1 = getArrayU8FromWasm0(r0, r1).slice(); + wasm.__wbindgen_free(r0, r1 * 1, 1); + return v1; + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } + } + /** + * Randomness specified in the request to ensure EU-CMA of the signed response. + * TODO check that we don't need two types of randomness. One for the reuqest and one for the response + * TODO also check potential risk with repeated calls + * @param {Uint8Array} arg0 + */ + set randomness(arg0) { + const ptr0 = passArray8ToWasm0(arg0, wasm.__wbindgen_malloc); + const len0 = WASM_VECTOR_LEN; + wasm.__wbg_set_eip712domainmsg_version(this.__wbg_ptr, ptr0, len0); + } + /** + * Encoding of the user's public encryption key for this request. + * Encoding using the default encoding of libsodium, i.e. the 32 bytes of a + * Montgomery point. + * @returns {Uint8Array} + */ + get enc_key() { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + wasm.__wbg_get_eip712domainmsg_chain_id(retptr, this.__wbg_ptr); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + var v1 = getArrayU8FromWasm0(r0, r1).slice(); + wasm.__wbindgen_free(r0, r1 * 1, 1); + return v1; + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } + } + /** + * Encoding of the user's public encryption key for this request. + * Encoding using the default encoding of libsodium, i.e. the 32 bytes of a + * Montgomery point. + * @param {Uint8Array} arg0 + */ + set enc_key(arg0) { + const ptr0 = passArray8ToWasm0(arg0, wasm.__wbindgen_malloc); + const len0 = WASM_VECTOR_LEN; + wasm.__wbg_set_eip712domainmsg_chain_id(this.__wbg_ptr, ptr0, len0); + } + /** + * The type of plaintext encrypted. + * @returns {number} + */ + get fhe_type() { + const ret = wasm.__wbg_get_reencryptionrequestpayload_fhe_type( + this.__wbg_ptr, + ); + return ret; + } + /** + * The type of plaintext encrypted. + * @param {number} arg0 + */ + set fhe_type(arg0) { + wasm.__wbg_set_reencryptionrequestpayload_fhe_type(this.__wbg_ptr, arg0); + } + /** + * The key id to use for decryption. Will be the request_id used during key generation + * @returns {RequestId | undefined} + */ + get key_id() { + const ret = wasm.__wbg_get_reencryptionrequestpayload_key_id( + this.__wbg_ptr, + ); + return ret === 0 ? undefined : RequestId.__wrap(ret); + } + /** + * The key id to use for decryption. Will be the request_id used during key generation + * @param {RequestId | undefined} [arg0] + */ + set key_id(arg0) { + let ptr0 = 0; + if (!isLikeNone(arg0)) { + _assertClass(arg0, RequestId); + ptr0 = arg0.__destroy_into_raw(); + } + wasm.__wbg_set_reencryptionrequestpayload_key_id(this.__wbg_ptr, ptr0); + } + /** + * The actual ciphertext to decrypt, taken directly from the fhevm. + * When creating the payload, this field may be empty, + * it is the responsibility of the gateway to fetch the + * ciphertext for the given digest below. + * @returns {Uint8Array | undefined} + */ + get ciphertext() { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + wasm.__wbg_get_reencryptionrequestpayload_ciphertext( + retptr, + this.__wbg_ptr, + ); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + let v1; + if (r0 !== 0) { + v1 = getArrayU8FromWasm0(r0, r1).slice(); + wasm.__wbindgen_free(r0, r1 * 1, 1); + } + return v1; + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } + } + /** + * The actual ciphertext to decrypt, taken directly from the fhevm. + * When creating the payload, this field may be empty, + * it is the responsibility of the gateway to fetch the + * ciphertext for the given digest below. + * @param {Uint8Array | undefined} [arg0] + */ + set ciphertext(arg0) { + var ptr0 = isLikeNone(arg0) + ? 0 + : passArray8ToWasm0(arg0, wasm.__wbindgen_malloc); + var len0 = WASM_VECTOR_LEN; + wasm.__wbg_set_reencryptionrequestpayload_ciphertext( + this.__wbg_ptr, + ptr0, + len0, + ); + } + /** + * The SHA3 digest of the ciphertext above. + * @returns {Uint8Array} + */ + get ciphertext_digest() { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + wasm.__wbg_get_reencryptionrequestpayload_ciphertext_digest( + retptr, + this.__wbg_ptr, + ); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + var v1 = getArrayU8FromWasm0(r0, r1).slice(); + wasm.__wbindgen_free(r0, r1 * 1, 1); + return v1; + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } + } + /** + * The SHA3 digest of the ciphertext above. + * @param {Uint8Array} arg0 + */ + set ciphertext_digest(arg0) { + const ptr0 = passArray8ToWasm0(arg0, wasm.__wbindgen_malloc); + const len0 = WASM_VECTOR_LEN; + wasm.__wbg_set_eip712domainmsg_verifying_contract( + this.__wbg_ptr, + ptr0, + len0, + ); + } +} +module.exports.ReencryptionRequestPayload = ReencryptionRequestPayload; + +const ReencryptionResponseFinalization = + typeof FinalizationRegistry === 'undefined' + ? { register: () => {}, unregister: () => {} } + : new FinalizationRegistry((ptr) => + wasm.__wbg_reencryptionresponse_free(ptr >>> 0), + ); +/** + */ +class ReencryptionResponse { + static __unwrap(jsValue) { + if (!(jsValue instanceof ReencryptionResponse)) { + return 0; + } + return jsValue.__destroy_into_raw(); + } + + __destroy_into_raw() { + const ptr = this.__wbg_ptr; + this.__wbg_ptr = 0; + ReencryptionResponseFinalization.unregister(this); + return ptr; + } + + free() { + const ptr = this.__destroy_into_raw(); + wasm.__wbg_reencryptionresponse_free(ptr); + } + /** + * Version of the response format. + * @returns {number} + */ + get version() { + const ret = wasm.__wbg_get_reencryptionresponse_version(this.__wbg_ptr); + return ret >>> 0; + } + /** + * Version of the response format. + * @param {number} arg0 + */ + set version(arg0) { + wasm.__wbg_set_reencryptionresponse_version(this.__wbg_ptr, arg0); + } + /** + * Servers_needed are not really needed since there is a link to the + * digest, however, it seems better to be able to handle a response without + * getting data from the request as well. but this is also a security issue + * since it is possible to get meaning from the response without directly + * linking it to a request + * + * The amount of shares needed to recombine the result. + * This implies the threshold used. + * @returns {number} + */ + get servers_needed() { + const ret = wasm.__wbg_get_reencryptionresponse_servers_needed( + this.__wbg_ptr, + ); + return ret >>> 0; + } + /** + * Servers_needed are not really needed since there is a link to the + * digest, however, it seems better to be able to handle a response without + * getting data from the request as well. but this is also a security issue + * since it is possible to get meaning from the response without directly + * linking it to a request + * + * The amount of shares needed to recombine the result. + * This implies the threshold used. + * @param {number} arg0 + */ + set servers_needed(arg0) { + wasm.__wbg_set_reencryptionresponse_servers_needed(this.__wbg_ptr, arg0); + } + /** + * The server's signature verification key. + * Encoded using SEC1. + * Needed to validate the response, but MUST also be linked to a list of + * trusted keys. + * @returns {Uint8Array} + */ + get verification_key() { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + wasm.__wbg_get_reencryptionrequest_signature(retptr, this.__wbg_ptr); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + var v1 = getArrayU8FromWasm0(r0, r1).slice(); + wasm.__wbindgen_free(r0, r1 * 1, 1); + return v1; + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } + } + /** + * The server's signature verification key. + * Encoded using SEC1. + * Needed to validate the response, but MUST also be linked to a list of + * trusted keys. + * @param {Uint8Array} arg0 + */ + set verification_key(arg0) { + const ptr0 = passArray8ToWasm0(arg0, wasm.__wbindgen_malloc); + const len0 = WASM_VECTOR_LEN; + wasm.__wbg_set_eip712domainmsg_name(this.__wbg_ptr, ptr0, len0); + } + /** + * Digest of the request validated. + * Needed to ensure that the response is for the expected request. + * @returns {Uint8Array} + */ + get digest() { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + wasm.__wbg_get_reencryptionrequestpayload_randomness( + retptr, + this.__wbg_ptr, + ); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + var v1 = getArrayU8FromWasm0(r0, r1).slice(); + wasm.__wbindgen_free(r0, r1 * 1, 1); + return v1; + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } + } + /** + * Digest of the request validated. + * Needed to ensure that the response is for the expected request. + * @param {Uint8Array} arg0 + */ + set digest(arg0) { + const ptr0 = passArray8ToWasm0(arg0, wasm.__wbindgen_malloc); + const len0 = WASM_VECTOR_LEN; + wasm.__wbg_set_eip712domainmsg_version(this.__wbg_ptr, ptr0, len0); + } + /** + * The type of plaintext encrypted. + * @returns {number} + */ + get fhe_type() { + const ret = wasm.__wbg_get_reencryptionresponse_fhe_type(this.__wbg_ptr); + return ret; + } + /** + * The type of plaintext encrypted. + * @param {number} arg0 + */ + set fhe_type(arg0) { + wasm.__wbg_set_reencryptionresponse_fhe_type(this.__wbg_ptr, arg0); + } + /** + * The signcrypted payload, using a hybrid encryption approach in + * sign-then-encrypt. + * @returns {Uint8Array} + */ + get signcrypted_ciphertext() { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + wasm.__wbg_get_eip712domainmsg_chain_id(retptr, this.__wbg_ptr); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + var v1 = getArrayU8FromWasm0(r0, r1).slice(); + wasm.__wbindgen_free(r0, r1 * 1, 1); + return v1; + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } + } + /** + * The signcrypted payload, using a hybrid encryption approach in + * sign-then-encrypt. + * @param {Uint8Array} arg0 + */ + set signcrypted_ciphertext(arg0) { + const ptr0 = passArray8ToWasm0(arg0, wasm.__wbindgen_malloc); + const len0 = WASM_VECTOR_LEN; + wasm.__wbg_set_eip712domainmsg_chain_id(this.__wbg_ptr, ptr0, len0); + } +} +module.exports.ReencryptionResponse = ReencryptionResponse; + +const RequestIdFinalization = + typeof FinalizationRegistry === 'undefined' + ? { register: () => {}, unregister: () => {} } + : new FinalizationRegistry((ptr) => wasm.__wbg_requestid_free(ptr >>> 0)); +/** + * Simple response to return an ID, to be used to retrieve the computed result later on. + */ +class RequestId { + static __wrap(ptr) { + ptr = ptr >>> 0; + const obj = Object.create(RequestId.prototype); + obj.__wbg_ptr = ptr; + RequestIdFinalization.register(obj, obj.__wbg_ptr, obj); + return obj; + } + + __destroy_into_raw() { + const ptr = this.__wbg_ptr; + this.__wbg_ptr = 0; + RequestIdFinalization.unregister(this); + return ptr; + } + + free() { + const ptr = this.__destroy_into_raw(); + wasm.__wbg_requestid_free(ptr); + } + /** + * @returns {string} + */ + get request_id() { + let deferred1_0; + let deferred1_1; + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + wasm.__wbg_get_eip712domainmsg_name(retptr, this.__wbg_ptr); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + deferred1_0 = r0; + deferred1_1 = r1; + return getStringFromWasm0(r0, r1); + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + wasm.__wbindgen_free(deferred1_0, deferred1_1, 1); + } + } + /** + * @param {string} arg0 + */ + set request_id(arg0) { + const ptr0 = passStringToWasm0( + arg0, + wasm.__wbindgen_malloc, + wasm.__wbindgen_realloc, + ); + const len0 = WASM_VECTOR_LEN; + wasm.__wbg_set_eip712domainmsg_name(this.__wbg_ptr, ptr0, len0); + } +} +module.exports.RequestId = RequestId; + +module.exports.__wbg_reencryptionresponse_unwrap = function (arg0) { + const ret = ReencryptionResponse.__unwrap(takeObject(arg0)); + return ret; +}; + +module.exports.__wbindgen_object_drop_ref = function (arg0) { + takeObject(arg0); +}; + +module.exports.__wbindgen_error_new = function (arg0, arg1) { + const ret = new Error(getStringFromWasm0(arg0, arg1)); + return addHeapObject(ret); +}; + +module.exports.__wbg_publicsigkey_unwrap = function (arg0) { + const ret = PublicSigKey.__unwrap(takeObject(arg0)); + return ret; +}; + +module.exports.__wbg_new_abda76e883ba8a5f = function () { + const ret = new Error(); + return addHeapObject(ret); +}; + +module.exports.__wbg_stack_658279fe44541cf6 = function (arg0, arg1) { + const ret = getObject(arg1).stack; + const ptr1 = passStringToWasm0( + ret, + wasm.__wbindgen_malloc, + wasm.__wbindgen_realloc, + ); + const len1 = WASM_VECTOR_LEN; + getInt32Memory0()[arg0 / 4 + 1] = len1; + getInt32Memory0()[arg0 / 4 + 0] = ptr1; +}; + +module.exports.__wbg_error_f851667af71bcfc6 = function (arg0, arg1) { + let deferred0_0; + let deferred0_1; + try { + deferred0_0 = arg0; + deferred0_1 = arg1; + console.error(getStringFromWasm0(arg0, arg1)); + } finally { + wasm.__wbindgen_free(deferred0_0, deferred0_1, 1); + } +}; + +module.exports.__wbg_crypto_1d1f22824a6a080c = function (arg0) { + const ret = getObject(arg0).crypto; + return addHeapObject(ret); +}; + +module.exports.__wbindgen_is_object = function (arg0) { + const val = getObject(arg0); + const ret = typeof val === 'object' && val !== null; + return ret; +}; + +module.exports.__wbg_process_4a72847cc503995b = function (arg0) { + const ret = getObject(arg0).process; + return addHeapObject(ret); +}; + +module.exports.__wbg_versions_f686565e586dd935 = function (arg0) { + const ret = getObject(arg0).versions; + return addHeapObject(ret); +}; + +module.exports.__wbg_node_104a2ff8d6ea03a2 = function (arg0) { + const ret = getObject(arg0).node; + return addHeapObject(ret); +}; + +module.exports.__wbindgen_is_string = function (arg0) { + const ret = typeof getObject(arg0) === 'string'; + return ret; +}; + +module.exports.__wbg_msCrypto_eb05e62b530a1508 = function (arg0) { + const ret = getObject(arg0).msCrypto; + return addHeapObject(ret); +}; + +module.exports.__wbg_require_cca90b1a94a0255b = function () { + return handleError(function () { + const ret = module.require; + return addHeapObject(ret); + }, arguments); +}; + +module.exports.__wbindgen_is_function = function (arg0) { + const ret = typeof getObject(arg0) === 'function'; + return ret; +}; + +module.exports.__wbindgen_string_new = function (arg0, arg1) { + const ret = getStringFromWasm0(arg0, arg1); + return addHeapObject(ret); +}; + +module.exports.__wbg_randomFillSync_5c9c955aa56b6049 = function () { + return handleError(function (arg0, arg1) { + getObject(arg0).randomFillSync(takeObject(arg1)); + }, arguments); +}; + +module.exports.__wbg_getRandomValues_3aa56aa6edec874c = function () { + return handleError(function (arg0, arg1) { + getObject(arg0).getRandomValues(getObject(arg1)); + }, arguments); +}; + +module.exports.__wbg_newnoargs_e258087cd0daa0ea = function (arg0, arg1) { + const ret = new Function(getStringFromWasm0(arg0, arg1)); + return addHeapObject(ret); +}; + +module.exports.__wbg_call_27c0f87801dedf93 = function () { + return handleError(function (arg0, arg1) { + const ret = getObject(arg0).call(getObject(arg1)); + return addHeapObject(ret); + }, arguments); +}; + +module.exports.__wbindgen_object_clone_ref = function (arg0) { + const ret = getObject(arg0); + return addHeapObject(ret); +}; + +module.exports.__wbg_self_ce0dbfc45cf2f5be = function () { + return handleError(function () { + const ret = self.self; + return addHeapObject(ret); + }, arguments); +}; + +module.exports.__wbg_window_c6fb939a7f436783 = function () { + return handleError(function () { + const ret = window.window; + return addHeapObject(ret); + }, arguments); +}; + +module.exports.__wbg_globalThis_d1e6af4856ba331b = function () { + return handleError(function () { + const ret = globalThis.globalThis; + return addHeapObject(ret); + }, arguments); +}; + +module.exports.__wbg_global_207b558942527489 = function () { + return handleError(function () { + const ret = global.global; + return addHeapObject(ret); + }, arguments); +}; + +module.exports.__wbindgen_is_undefined = function (arg0) { + const ret = getObject(arg0) === undefined; + return ret; +}; + +module.exports.__wbg_call_b3ca7c6051f9bec1 = function () { + return handleError(function (arg0, arg1, arg2) { + const ret = getObject(arg0).call(getObject(arg1), getObject(arg2)); + return addHeapObject(ret); + }, arguments); +}; + +module.exports.__wbg_buffer_12d079cc21e14bdb = function (arg0) { + const ret = getObject(arg0).buffer; + return addHeapObject(ret); +}; + +module.exports.__wbg_newwithbyteoffsetandlength_aa4a17c33a06e5cb = function ( + arg0, + arg1, + arg2, +) { + const ret = new Uint8Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0); + return addHeapObject(ret); +}; + +module.exports.__wbg_new_63b92bc8671ed464 = function (arg0) { + const ret = new Uint8Array(getObject(arg0)); + return addHeapObject(ret); +}; + +module.exports.__wbg_set_a47bac70306a19a7 = function (arg0, arg1, arg2) { + getObject(arg0).set(getObject(arg1), arg2 >>> 0); +}; + +module.exports.__wbg_newwithlength_e9b4878cebadb3d3 = function (arg0) { + const ret = new Uint8Array(arg0 >>> 0); + return addHeapObject(ret); +}; + +module.exports.__wbg_subarray_a1f73cd4b5b42fe1 = function (arg0, arg1, arg2) { + const ret = getObject(arg0).subarray(arg1 >>> 0, arg2 >>> 0); + return addHeapObject(ret); +}; + +module.exports.__wbindgen_throw = function (arg0, arg1) { + throw new Error(getStringFromWasm0(arg0, arg1)); +}; + +module.exports.__wbindgen_memory = function () { + const ret = wasm.memory; + return addHeapObject(ret); +}; + +const path = require('path').join(__dirname, 'kms_lib_bg.wasm'); +const bytes = require('fs').readFileSync(path); + +const wasmModule = new WebAssembly.Module(bytes); +const wasmInstance = new WebAssembly.Instance(wasmModule, imports); +wasm = wasmInstance.exports; +module.exports.__wasm = wasm; diff --git a/src/kms/node/kms_lib_bg.wasm b/src/kms/node/kms_lib_bg.wasm new file mode 100644 index 0000000..88cc376 Binary files /dev/null and b/src/kms/node/kms_lib_bg.wasm differ diff --git a/src/kms/node/kms_lib_bg.wasm.d.ts b/src/kms/node/kms_lib_bg.wasm.d.ts new file mode 100644 index 0000000..d2bdf1d --- /dev/null +++ b/src/kms/node/kms_lib_bg.wasm.d.ts @@ -0,0 +1,87 @@ +/* tslint:disable */ +/* eslint-disable */ +export const memory: WebAssembly.Memory; +export function __wbg_client_free(a: number): void; +export function __wbg_requestid_free(a: number): void; +export function __wbg_reencryptionrequestpayload_free(a: number): void; +export function __wbg_get_reencryptionrequestpayload_version(a: number): number; +export function __wbg_set_reencryptionrequestpayload_version(a: number, b: number): void; +export function __wbg_get_reencryptionrequestpayload_servers_needed(a: number): number; +export function __wbg_set_reencryptionrequestpayload_servers_needed(a: number, b: number): void; +export function __wbg_get_reencryptionrequestpayload_randomness(a: number, b: number): void; +export function __wbg_get_reencryptionrequestpayload_fhe_type(a: number): number; +export function __wbg_set_reencryptionrequestpayload_fhe_type(a: number, b: number): void; +export function __wbg_get_reencryptionrequestpayload_key_id(a: number): number; +export function __wbg_set_reencryptionrequestpayload_key_id(a: number, b: number): void; +export function __wbg_get_reencryptionrequestpayload_ciphertext(a: number, b: number): void; +export function __wbg_set_reencryptionrequestpayload_ciphertext(a: number, b: number, c: number): void; +export function __wbg_get_reencryptionrequestpayload_ciphertext_digest(a: number, b: number): void; +export function __wbg_eip712domainmsg_free(a: number): void; +export function __wbg_get_eip712domainmsg_name(a: number, b: number): void; +export function __wbg_set_eip712domainmsg_name(a: number, b: number, c: number): void; +export function __wbg_get_eip712domainmsg_version(a: number, b: number): void; +export function __wbg_set_eip712domainmsg_version(a: number, b: number, c: number): void; +export function __wbg_get_eip712domainmsg_chain_id(a: number, b: number): void; +export function __wbg_set_eip712domainmsg_chain_id(a: number, b: number, c: number): void; +export function __wbg_get_eip712domainmsg_verifying_contract(a: number, b: number): void; +export function __wbg_set_eip712domainmsg_verifying_contract(a: number, b: number, c: number): void; +export function __wbg_get_eip712domainmsg_salt(a: number, b: number): void; +export function __wbg_set_eip712domainmsg_salt(a: number, b: number, c: number): void; +export function __wbg_reencryptionrequest_free(a: number): void; +export function __wbg_get_reencryptionrequest_signature(a: number, b: number): void; +export function __wbg_get_reencryptionrequest_payload(a: number): number; +export function __wbg_set_reencryptionrequest_payload(a: number, b: number): void; +export function __wbg_get_reencryptionrequest_domain(a: number): number; +export function __wbg_set_reencryptionrequest_domain(a: number, b: number): void; +export function __wbg_get_reencryptionrequest_request_id(a: number): number; +export function __wbg_set_reencryptionrequest_request_id(a: number, b: number): void; +export function __wbg_reencryptionresponse_free(a: number): void; +export function __wbg_get_reencryptionresponse_version(a: number): number; +export function __wbg_set_reencryptionresponse_version(a: number, b: number): void; +export function __wbg_get_reencryptionresponse_servers_needed(a: number): number; +export function __wbg_set_reencryptionresponse_servers_needed(a: number, b: number): void; +export function __wbg_get_reencryptionresponse_fhe_type(a: number): number; +export function __wbg_set_reencryptionresponse_fhe_type(a: number, b: number): void; +export function __wbg_get_reencryptionrequestpayload_enc_key(a: number, b: number): void; +export function __wbg_get_reencryptionrequestpayload_verification_key(a: number, b: number): void; +export function __wbg_get_reencryptionresponse_verification_key(a: number, b: number): void; +export function __wbg_get_reencryptionresponse_digest(a: number, b: number): void; +export function __wbg_get_reencryptionresponse_signcrypted_ciphertext(a: number, b: number): void; +export function __wbg_get_requestid_request_id(a: number, b: number): void; +export function __wbg_set_requestid_request_id(a: number, b: number, c: number): void; +export function __wbg_set_reencryptionrequestpayload_verification_key(a: number, b: number, c: number): void; +export function __wbg_set_reencryptionrequestpayload_randomness(a: number, b: number, c: number): void; +export function __wbg_set_reencryptionrequestpayload_enc_key(a: number, b: number, c: number): void; +export function __wbg_set_reencryptionrequestpayload_ciphertext_digest(a: number, b: number, c: number): void; +export function __wbg_set_reencryptionrequest_signature(a: number, b: number, c: number): void; +export function __wbg_set_reencryptionresponse_verification_key(a: number, b: number, c: number): void; +export function __wbg_set_reencryptionresponse_digest(a: number, b: number, c: number): void; +export function __wbg_set_reencryptionresponse_signcrypted_ciphertext(a: number, b: number, c: number): void; +export function __wbg_plaintext_free(a: number): void; +export function __wbg_get_plaintext_lowest_bits(a: number): number; +export function __wbg_set_plaintext_lowest_bits(a: number, b: number): void; +export function __wbg_get_plaintext_middle_bits(a: number): number; +export function __wbg_set_plaintext_middle_bits(a: number, b: number): void; +export function __wbg_get_plaintext_higest_bits(a: number): number; +export function __wbg_set_plaintext_higest_bits(a: number, b: number): void; +export function new_client(a: number, b: number, c: number, d: number, e: number, f: number): number; +export function __wbg_cryptoboxct_free(a: number): void; +export function cryptobox_keygen(): number; +export function cryptobox_get_pk(a: number): number; +export function cryptobox_pk_to_u8vec(a: number, b: number): void; +export function cryptobox_sk_to_u8vec(a: number, b: number): void; +export function u8vec_to_cryptobox_pk(a: number, b: number, c: number): void; +export function u8vec_to_cryptobox_sk(a: number, b: number, c: number): void; +export function cryptobox_encrypt(a: number, b: number, c: number, d: number): number; +export function cryptobox_decrypt(a: number, b: number, c: number, d: number): void; +export function make_reencryption_req(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number): void; +export function process_reencryption_resp(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number): void; +export function __wbg_publicenckey_free(a: number): void; +export function __wbg_privateenckey_free(a: number): void; +export function __wbg_publicsigkey_free(a: number): void; +export function __wbg_privatesigkey_free(a: number): void; +export function __wbindgen_add_to_stack_pointer(a: number): number; +export function __wbindgen_free(a: number, b: number, c: number): void; +export function __wbindgen_malloc(a: number, b: number): number; +export function __wbindgen_realloc(a: number, b: number, c: number, d: number): number; +export function __wbindgen_exn_store(a: number): void; diff --git a/src/kms/web/kms_lib.d.ts b/src/kms/web/kms_lib.d.ts new file mode 100644 index 0000000..abb9b57 --- /dev/null +++ b/src/kms/web/kms_lib.d.ts @@ -0,0 +1,404 @@ +/* tslint:disable */ +/* eslint-disable */ +/** +* @param {(PublicSigKey)[]} server_pks +* @param {PublicSigKey} client_pk +* @param {number} shares_needed +* @param {string} params_json +* @returns {Client} +*/ +export function new_client(server_pks: (PublicSigKey)[], client_pk: PublicSigKey, shares_needed: number, params_json: string): Client; +/** +* @returns {PrivateEncKey} +*/ +export function cryptobox_keygen(): PrivateEncKey; +/** +* @param {PrivateEncKey} sk +* @returns {PublicEncKey} +*/ +export function cryptobox_get_pk(sk: PrivateEncKey): PublicEncKey; +/** +* @param {PublicEncKey} pk +* @returns {Uint8Array} +*/ +export function cryptobox_pk_to_u8vec(pk: PublicEncKey): Uint8Array; +/** +* @param {PrivateEncKey} sk +* @returns {Uint8Array} +*/ +export function cryptobox_sk_to_u8vec(sk: PrivateEncKey): Uint8Array; +/** +* @param {Uint8Array} v +* @returns {PublicEncKey} +*/ +export function u8vec_to_cryptobox_pk(v: Uint8Array): PublicEncKey; +/** +* @param {Uint8Array} v +* @returns {PrivateEncKey} +*/ +export function u8vec_to_cryptobox_sk(v: Uint8Array): PrivateEncKey; +/** +* @param {Uint8Array} msg +* @param {PublicEncKey} their_pk +* @param {PrivateEncKey} my_sk +* @returns {CryptoBoxCt} +*/ +export function cryptobox_encrypt(msg: Uint8Array, their_pk: PublicEncKey, my_sk: PrivateEncKey): CryptoBoxCt; +/** +* @param {CryptoBoxCt} ct +* @param {PrivateEncKey} my_sk +* @param {PublicEncKey} their_pk +* @returns {Uint8Array} +*/ +export function cryptobox_decrypt(ct: CryptoBoxCt, my_sk: PrivateEncKey, their_pk: PublicEncKey): Uint8Array; +/** +* This function assembles [ReencryptionRequest] +* from a signature and other metadata. +* The signature is on the ephemeral public key +* signed by the client's private key +* following the EIP712 standard. +* @param {Client} client +* @param {Uint8Array} signature +* @param {PublicEncKey} enc_pk +* @param {FheType} fhe_type +* @param {RequestId} key_id +* @param {Uint8Array} ciphertext_digest +* @param {Eip712DomainMsg} domain +* @returns {ReencryptionRequest} +*/ +export function make_reencryption_req(client: Client, signature: Uint8Array, enc_pk: PublicEncKey, fhe_type: FheType, key_id: RequestId, ciphertext_digest: Uint8Array, domain: Eip712DomainMsg): ReencryptionRequest; +/** +* This function takes [AggregatedReencryptionResponse] normally +* but wasm does not support HashMap so we need to take two parameters: +* `agg_resp` and `agg_resp_id`. +* @param {Client} client +* @param {ReencryptionRequest | undefined} request +* @param {(ReencryptionResponse)[]} agg_resp +* @param {Uint32Array} agg_resp_ids +* @param {PublicEncKey} enc_pk +* @param {PrivateEncKey} enc_sk +* @returns {number} +*/ +export function process_reencryption_resp(client: Client, request: ReencryptionRequest | undefined, agg_resp: (ReencryptionResponse)[], agg_resp_ids: Uint32Array, enc_pk: PublicEncKey, enc_sk: PrivateEncKey): number; +/** +* The plaintext types that can be encrypted in a fhevm ciphertext. +*/ +export enum FheType { + Bool = 0, + Euint4 = 1, + Euint8 = 2, + Euint16 = 3, + Euint32 = 4, + Euint64 = 5, + Euint128 = 6, + Euint160 = 7, +} +/** +* Simple client to interact with the KMS servers. This can be seen as a proof-of-concept +* and reference code for validating the KMS. The logic supplied by the client will be +* distributed accross the aggregator/proxy and smart contracts. +* TODO should probably aggregate the KmsEndpointClient to void having two client code bases +* exposed in tests and MVP +* +* client_sk is optional because sometimes the private signing key is kept +* in a secure location, e.g., hardware wallet. Calling functions that requires +* client_sk when it is None will return an error. +*/ +export class Client { + free(): void; +} +/** +*/ +export class CryptoBoxCt { + free(): void; +} +/** +* +* eventually chain_id, verifying_contract and salt will be parsed in to solidity types +*/ +export class Eip712DomainMsg { + free(): void; +/** +*/ + chain_id: Uint8Array; +/** +*/ + name: string; +/** +*/ + salt: Uint8Array; +/** +*/ + verifying_contract: string; +/** +*/ + version: string; +} +/** +*/ +export class Plaintext { + free(): void; +/** +*/ + higest_bits: number; +/** +*/ + lowest_bits: bigint; +/** +*/ + middle_bits: bigint; +} +/** +*/ +export class PrivateEncKey { + free(): void; +} +/** +*/ +export class PrivateSigKey { + free(): void; +} +/** +*/ +export class PublicEncKey { + free(): void; +} +/** +*/ +export class PublicSigKey { + free(): void; +} +/** +*/ +export class ReencryptionRequest { + free(): void; +/** +*/ + domain?: Eip712DomainMsg; +/** +*/ + payload?: ReencryptionRequestPayload; +/** +* The ID that identifies this request. +* Future queries for the result must use this request ID. +*/ + request_id?: RequestId; +/** +* Signature of the ASN1 DER serialization of \[ReencryptionRequestPayload\]. +*/ + signature: Uint8Array; +} +/** +*/ +export class ReencryptionRequestPayload { + free(): void; +/** +* The actual ciphertext to decrypt, taken directly from the fhevm. +* When creating the payload, this field may be empty, +* it is the responsibility of the gateway to fetch the +* ciphertext for the given digest below. +*/ + ciphertext?: Uint8Array; +/** +* The SHA3 digest of the ciphertext above. +*/ + ciphertext_digest: Uint8Array; +/** +* Encoding of the user's public encryption key for this request. +* Encoding using the default encoding of libsodium, i.e. the 32 bytes of a +* Montgomery point. +*/ + enc_key: Uint8Array; +/** +* The type of plaintext encrypted. +*/ + fhe_type: number; +/** +* The key id to use for decryption. Will be the request_id used during key generation +*/ + key_id?: RequestId; +/** +* Randomness specified in the request to ensure EU-CMA of the signed response. +* TODO check that we don't need two types of randomness. One for the reuqest and one for the response +* TODO also check potential risk with repeated calls +*/ + randomness: Uint8Array; +/** +* The amount of shares needed to recombine the result. +* This implies the threshold used. +* Needed to avoid a single malicious server taking over a request that should +* have been distributed. +*/ + servers_needed: number; +/** +* The server's signature verification key. +* Encoded using SEC1. +* TODO not needed in the request! Should be removed +*/ + verification_key: Uint8Array; +/** +* Version of the request format. +*/ + version: number; +} +/** +*/ +export class ReencryptionResponse { + free(): void; +/** +* Digest of the request validated. +* Needed to ensure that the response is for the expected request. +*/ + digest: Uint8Array; +/** +* The type of plaintext encrypted. +*/ + fhe_type: number; +/** +* Servers_needed are not really needed since there is a link to the +* digest, however, it seems better to be able to handle a response without +* getting data from the request as well. but this is also a security issue +* since it is possible to get meaning from the response without directly +* linking it to a request +* +* The amount of shares needed to recombine the result. +* This implies the threshold used. +*/ + servers_needed: number; +/** +* The signcrypted payload, using a hybrid encryption approach in +* sign-then-encrypt. +*/ + signcrypted_ciphertext: Uint8Array; +/** +* The server's signature verification key. +* Encoded using SEC1. +* Needed to validate the response, but MUST also be linked to a list of +* trusted keys. +*/ + verification_key: Uint8Array; +/** +* Version of the response format. +*/ + version: number; +} +/** +* Simple response to return an ID, to be used to retrieve the computed result later on. +*/ +export class RequestId { + free(): void; +/** +*/ + request_id: string; +} + +export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module; + +export interface InitOutput { + readonly memory: WebAssembly.Memory; + readonly __wbg_client_free: (a: number) => void; + readonly __wbg_requestid_free: (a: number) => void; + readonly __wbg_reencryptionrequestpayload_free: (a: number) => void; + readonly __wbg_get_reencryptionrequestpayload_version: (a: number) => number; + readonly __wbg_set_reencryptionrequestpayload_version: (a: number, b: number) => void; + readonly __wbg_get_reencryptionrequestpayload_servers_needed: (a: number) => number; + readonly __wbg_set_reencryptionrequestpayload_servers_needed: (a: number, b: number) => void; + readonly __wbg_get_reencryptionrequestpayload_randomness: (a: number, b: number) => void; + readonly __wbg_get_reencryptionrequestpayload_fhe_type: (a: number) => number; + readonly __wbg_set_reencryptionrequestpayload_fhe_type: (a: number, b: number) => void; + readonly __wbg_get_reencryptionrequestpayload_key_id: (a: number) => number; + readonly __wbg_set_reencryptionrequestpayload_key_id: (a: number, b: number) => void; + readonly __wbg_get_reencryptionrequestpayload_ciphertext: (a: number, b: number) => void; + readonly __wbg_set_reencryptionrequestpayload_ciphertext: (a: number, b: number, c: number) => void; + readonly __wbg_get_reencryptionrequestpayload_ciphertext_digest: (a: number, b: number) => void; + readonly __wbg_eip712domainmsg_free: (a: number) => void; + readonly __wbg_get_eip712domainmsg_name: (a: number, b: number) => void; + readonly __wbg_set_eip712domainmsg_name: (a: number, b: number, c: number) => void; + readonly __wbg_get_eip712domainmsg_version: (a: number, b: number) => void; + readonly __wbg_set_eip712domainmsg_version: (a: number, b: number, c: number) => void; + readonly __wbg_get_eip712domainmsg_chain_id: (a: number, b: number) => void; + readonly __wbg_set_eip712domainmsg_chain_id: (a: number, b: number, c: number) => void; + readonly __wbg_get_eip712domainmsg_verifying_contract: (a: number, b: number) => void; + readonly __wbg_set_eip712domainmsg_verifying_contract: (a: number, b: number, c: number) => void; + readonly __wbg_get_eip712domainmsg_salt: (a: number, b: number) => void; + readonly __wbg_set_eip712domainmsg_salt: (a: number, b: number, c: number) => void; + readonly __wbg_reencryptionrequest_free: (a: number) => void; + readonly __wbg_get_reencryptionrequest_signature: (a: number, b: number) => void; + readonly __wbg_get_reencryptionrequest_payload: (a: number) => number; + readonly __wbg_set_reencryptionrequest_payload: (a: number, b: number) => void; + readonly __wbg_get_reencryptionrequest_domain: (a: number) => number; + readonly __wbg_set_reencryptionrequest_domain: (a: number, b: number) => void; + readonly __wbg_get_reencryptionrequest_request_id: (a: number) => number; + readonly __wbg_set_reencryptionrequest_request_id: (a: number, b: number) => void; + readonly __wbg_reencryptionresponse_free: (a: number) => void; + readonly __wbg_get_reencryptionresponse_version: (a: number) => number; + readonly __wbg_set_reencryptionresponse_version: (a: number, b: number) => void; + readonly __wbg_get_reencryptionresponse_servers_needed: (a: number) => number; + readonly __wbg_set_reencryptionresponse_servers_needed: (a: number, b: number) => void; + readonly __wbg_get_reencryptionresponse_fhe_type: (a: number) => number; + readonly __wbg_set_reencryptionresponse_fhe_type: (a: number, b: number) => void; + readonly __wbg_get_reencryptionrequestpayload_enc_key: (a: number, b: number) => void; + readonly __wbg_get_reencryptionrequestpayload_verification_key: (a: number, b: number) => void; + readonly __wbg_get_reencryptionresponse_verification_key: (a: number, b: number) => void; + readonly __wbg_get_reencryptionresponse_digest: (a: number, b: number) => void; + readonly __wbg_get_reencryptionresponse_signcrypted_ciphertext: (a: number, b: number) => void; + readonly __wbg_get_requestid_request_id: (a: number, b: number) => void; + readonly __wbg_set_requestid_request_id: (a: number, b: number, c: number) => void; + readonly __wbg_set_reencryptionrequestpayload_verification_key: (a: number, b: number, c: number) => void; + readonly __wbg_set_reencryptionrequestpayload_randomness: (a: number, b: number, c: number) => void; + readonly __wbg_set_reencryptionrequestpayload_enc_key: (a: number, b: number, c: number) => void; + readonly __wbg_set_reencryptionrequestpayload_ciphertext_digest: (a: number, b: number, c: number) => void; + readonly __wbg_set_reencryptionrequest_signature: (a: number, b: number, c: number) => void; + readonly __wbg_set_reencryptionresponse_verification_key: (a: number, b: number, c: number) => void; + readonly __wbg_set_reencryptionresponse_digest: (a: number, b: number, c: number) => void; + readonly __wbg_set_reencryptionresponse_signcrypted_ciphertext: (a: number, b: number, c: number) => void; + readonly __wbg_plaintext_free: (a: number) => void; + readonly __wbg_get_plaintext_lowest_bits: (a: number) => number; + readonly __wbg_set_plaintext_lowest_bits: (a: number, b: number) => void; + readonly __wbg_get_plaintext_middle_bits: (a: number) => number; + readonly __wbg_set_plaintext_middle_bits: (a: number, b: number) => void; + readonly __wbg_get_plaintext_higest_bits: (a: number) => number; + readonly __wbg_set_plaintext_higest_bits: (a: number, b: number) => void; + readonly new_client: (a: number, b: number, c: number, d: number, e: number, f: number) => number; + readonly __wbg_cryptoboxct_free: (a: number) => void; + readonly cryptobox_keygen: () => number; + readonly cryptobox_get_pk: (a: number) => number; + readonly cryptobox_pk_to_u8vec: (a: number, b: number) => void; + readonly cryptobox_sk_to_u8vec: (a: number, b: number) => void; + readonly u8vec_to_cryptobox_pk: (a: number, b: number, c: number) => void; + readonly u8vec_to_cryptobox_sk: (a: number, b: number, c: number) => void; + readonly cryptobox_encrypt: (a: number, b: number, c: number, d: number) => number; + readonly cryptobox_decrypt: (a: number, b: number, c: number, d: number) => void; + readonly make_reencryption_req: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => void; + readonly process_reencryption_resp: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void; + readonly __wbg_publicenckey_free: (a: number) => void; + readonly __wbg_privateenckey_free: (a: number) => void; + readonly __wbg_publicsigkey_free: (a: number) => void; + readonly __wbg_privatesigkey_free: (a: number) => void; + readonly __wbindgen_add_to_stack_pointer: (a: number) => number; + readonly __wbindgen_free: (a: number, b: number, c: number) => void; + readonly __wbindgen_malloc: (a: number, b: number) => number; + readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number; + readonly __wbindgen_exn_store: (a: number) => void; +} + +export type SyncInitInput = BufferSource | WebAssembly.Module; +/** +* Instantiates the given `module`, which can either be bytes or +* a precompiled `WebAssembly.Module`. +* +* @param {SyncInitInput} module +* +* @returns {InitOutput} +*/ +export function initSync(module: SyncInitInput): InitOutput; + +/** +* If `module_or_path` is {RequestInfo} or {URL}, makes a request and +* for everything else, calls `WebAssembly.instantiate` directly. +* +* @param {InitInput | Promise} module_or_path +* +* @returns {Promise} +*/ +export default function __wbg_init (module_or_path?: InitInput | Promise): Promise; diff --git a/src/kms/web/kms_lib.js b/src/kms/web/kms_lib.js new file mode 100644 index 0000000..d5ef7fb --- /dev/null +++ b/src/kms/web/kms_lib.js @@ -0,0 +1,1639 @@ +let wasm; + +const heap = new Array(128).fill(undefined); + +heap.push(undefined, null, true, false); + +function getObject(idx) { return heap[idx]; } + +let heap_next = heap.length; + +function dropObject(idx) { + if (idx < 132) return; + heap[idx] = heap_next; + heap_next = idx; +} + +function takeObject(idx) { + const ret = getObject(idx); + dropObject(idx); + return ret; +} + +const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } ); + +if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); }; + +let cachedUint8Memory0 = null; + +function getUint8Memory0() { + if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) { + cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer); + } + return cachedUint8Memory0; +} + +function getStringFromWasm0(ptr, len) { + ptr = ptr >>> 0; + return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len)); +} + +function addHeapObject(obj) { + if (heap_next === heap.length) heap.push(heap.length + 1); + const idx = heap_next; + heap_next = heap[idx]; + + heap[idx] = obj; + return idx; +} + +let cachedInt32Memory0 = null; + +function getInt32Memory0() { + if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) { + cachedInt32Memory0 = new Int32Array(wasm.memory.buffer); + } + return cachedInt32Memory0; +} + +let WASM_VECTOR_LEN = 0; + +const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } ); + +const encodeString = (typeof cachedTextEncoder.encodeInto === 'function' + ? function (arg, view) { + return cachedTextEncoder.encodeInto(arg, view); +} + : function (arg, view) { + const buf = cachedTextEncoder.encode(arg); + view.set(buf); + return { + read: arg.length, + written: buf.length + }; +}); + +function passStringToWasm0(arg, malloc, realloc) { + + if (realloc === undefined) { + const buf = cachedTextEncoder.encode(arg); + const ptr = malloc(buf.length, 1) >>> 0; + getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf); + WASM_VECTOR_LEN = buf.length; + return ptr; + } + + let len = arg.length; + let ptr = malloc(len, 1) >>> 0; + + const mem = getUint8Memory0(); + + let offset = 0; + + for (; offset < len; offset++) { + const code = arg.charCodeAt(offset); + if (code > 0x7F) break; + mem[ptr + offset] = code; + } + + if (offset !== len) { + if (offset !== 0) { + arg = arg.slice(offset); + } + ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0; + const view = getUint8Memory0().subarray(ptr + offset, ptr + len); + const ret = encodeString(arg, view); + + offset += ret.written; + ptr = realloc(ptr, len, offset, 1) >>> 0; + } + + WASM_VECTOR_LEN = offset; + return ptr; +} + +function getArrayU8FromWasm0(ptr, len) { + ptr = ptr >>> 0; + return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len); +} + +function passArray8ToWasm0(arg, malloc) { + const ptr = malloc(arg.length * 1, 1) >>> 0; + getUint8Memory0().set(arg, ptr / 1); + WASM_VECTOR_LEN = arg.length; + return ptr; +} + +function isLikeNone(x) { + return x === undefined || x === null; +} + +function _assertClass(instance, klass) { + if (!(instance instanceof klass)) { + throw new Error(`expected instance of ${klass.name}`); + } + return instance.ptr; +} + +let cachedUint32Memory0 = null; + +function getUint32Memory0() { + if (cachedUint32Memory0 === null || cachedUint32Memory0.byteLength === 0) { + cachedUint32Memory0 = new Uint32Array(wasm.memory.buffer); + } + return cachedUint32Memory0; +} + +function passArrayJsValueToWasm0(array, malloc) { + const ptr = malloc(array.length * 4, 4) >>> 0; + const mem = getUint32Memory0(); + for (let i = 0; i < array.length; i++) { + mem[ptr / 4 + i] = addHeapObject(array[i]); + } + WASM_VECTOR_LEN = array.length; + return ptr; +} +/** +* @param {(PublicSigKey)[]} server_pks +* @param {PublicSigKey} client_pk +* @param {number} shares_needed +* @param {string} params_json +* @returns {Client} +*/ +export function new_client(server_pks, client_pk, shares_needed, params_json) { + const ptr0 = passArrayJsValueToWasm0(server_pks, wasm.__wbindgen_malloc); + const len0 = WASM_VECTOR_LEN; + _assertClass(client_pk, PublicSigKey); + var ptr1 = client_pk.__destroy_into_raw(); + const ptr2 = passStringToWasm0(params_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len2 = WASM_VECTOR_LEN; + const ret = wasm.new_client(ptr0, len0, ptr1, shares_needed, ptr2, len2); + return Client.__wrap(ret); +} + +/** +* @returns {PrivateEncKey} +*/ +export function cryptobox_keygen() { + const ret = wasm.cryptobox_keygen(); + return PrivateEncKey.__wrap(ret); +} + +/** +* @param {PrivateEncKey} sk +* @returns {PublicEncKey} +*/ +export function cryptobox_get_pk(sk) { + _assertClass(sk, PrivateEncKey); + const ret = wasm.cryptobox_get_pk(sk.__wbg_ptr); + return PublicEncKey.__wrap(ret); +} + +/** +* @param {PublicEncKey} pk +* @returns {Uint8Array} +*/ +export function cryptobox_pk_to_u8vec(pk) { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + _assertClass(pk, PublicEncKey); + wasm.cryptobox_pk_to_u8vec(retptr, pk.__wbg_ptr); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + var r2 = getInt32Memory0()[retptr / 4 + 2]; + var r3 = getInt32Memory0()[retptr / 4 + 3]; + if (r3) { + throw takeObject(r2); + } + var v1 = getArrayU8FromWasm0(r0, r1).slice(); + wasm.__wbindgen_free(r0, r1 * 1, 1); + return v1; + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } +} + +/** +* @param {PrivateEncKey} sk +* @returns {Uint8Array} +*/ +export function cryptobox_sk_to_u8vec(sk) { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + _assertClass(sk, PrivateEncKey); + wasm.cryptobox_sk_to_u8vec(retptr, sk.__wbg_ptr); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + var r2 = getInt32Memory0()[retptr / 4 + 2]; + var r3 = getInt32Memory0()[retptr / 4 + 3]; + if (r3) { + throw takeObject(r2); + } + var v1 = getArrayU8FromWasm0(r0, r1).slice(); + wasm.__wbindgen_free(r0, r1 * 1, 1); + return v1; + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } +} + +/** +* @param {Uint8Array} v +* @returns {PublicEncKey} +*/ +export function u8vec_to_cryptobox_pk(v) { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + const ptr0 = passArray8ToWasm0(v, wasm.__wbindgen_malloc); + const len0 = WASM_VECTOR_LEN; + wasm.u8vec_to_cryptobox_pk(retptr, ptr0, len0); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + var r2 = getInt32Memory0()[retptr / 4 + 2]; + if (r2) { + throw takeObject(r1); + } + return PublicEncKey.__wrap(r0); + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } +} + +/** +* @param {Uint8Array} v +* @returns {PrivateEncKey} +*/ +export function u8vec_to_cryptobox_sk(v) { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + const ptr0 = passArray8ToWasm0(v, wasm.__wbindgen_malloc); + const len0 = WASM_VECTOR_LEN; + wasm.u8vec_to_cryptobox_sk(retptr, ptr0, len0); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + var r2 = getInt32Memory0()[retptr / 4 + 2]; + if (r2) { + throw takeObject(r1); + } + return PrivateEncKey.__wrap(r0); + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } +} + +/** +* @param {Uint8Array} msg +* @param {PublicEncKey} their_pk +* @param {PrivateEncKey} my_sk +* @returns {CryptoBoxCt} +*/ +export function cryptobox_encrypt(msg, their_pk, my_sk) { + const ptr0 = passArray8ToWasm0(msg, wasm.__wbindgen_malloc); + const len0 = WASM_VECTOR_LEN; + _assertClass(their_pk, PublicEncKey); + _assertClass(my_sk, PrivateEncKey); + const ret = wasm.cryptobox_encrypt(ptr0, len0, their_pk.__wbg_ptr, my_sk.__wbg_ptr); + return CryptoBoxCt.__wrap(ret); +} + +/** +* @param {CryptoBoxCt} ct +* @param {PrivateEncKey} my_sk +* @param {PublicEncKey} their_pk +* @returns {Uint8Array} +*/ +export function cryptobox_decrypt(ct, my_sk, their_pk) { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + _assertClass(ct, CryptoBoxCt); + _assertClass(my_sk, PrivateEncKey); + _assertClass(their_pk, PublicEncKey); + wasm.cryptobox_decrypt(retptr, ct.__wbg_ptr, my_sk.__wbg_ptr, their_pk.__wbg_ptr); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + var v1 = getArrayU8FromWasm0(r0, r1).slice(); + wasm.__wbindgen_free(r0, r1 * 1, 1); + return v1; + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } +} + +/** +* This function assembles [ReencryptionRequest] +* from a signature and other metadata. +* The signature is on the ephemeral public key +* signed by the client's private key +* following the EIP712 standard. +* @param {Client} client +* @param {Uint8Array} signature +* @param {PublicEncKey} enc_pk +* @param {FheType} fhe_type +* @param {RequestId} key_id +* @param {Uint8Array} ciphertext_digest +* @param {Eip712DomainMsg} domain +* @returns {ReencryptionRequest} +*/ +export function make_reencryption_req(client, signature, enc_pk, fhe_type, key_id, ciphertext_digest, domain) { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + _assertClass(client, Client); + const ptr0 = passArray8ToWasm0(signature, wasm.__wbindgen_malloc); + const len0 = WASM_VECTOR_LEN; + _assertClass(enc_pk, PublicEncKey); + var ptr1 = enc_pk.__destroy_into_raw(); + _assertClass(key_id, RequestId); + var ptr2 = key_id.__destroy_into_raw(); + const ptr3 = passArray8ToWasm0(ciphertext_digest, wasm.__wbindgen_malloc); + const len3 = WASM_VECTOR_LEN; + _assertClass(domain, Eip712DomainMsg); + var ptr4 = domain.__destroy_into_raw(); + wasm.make_reencryption_req(retptr, client.__wbg_ptr, ptr0, len0, ptr1, fhe_type, ptr2, ptr3, len3, ptr4); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + var r2 = getInt32Memory0()[retptr / 4 + 2]; + if (r2) { + throw takeObject(r1); + } + return ReencryptionRequest.__wrap(r0); + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } +} + +function passArray32ToWasm0(arg, malloc) { + const ptr = malloc(arg.length * 4, 4) >>> 0; + getUint32Memory0().set(arg, ptr / 4); + WASM_VECTOR_LEN = arg.length; + return ptr; +} +/** +* This function takes [AggregatedReencryptionResponse] normally +* but wasm does not support HashMap so we need to take two parameters: +* `agg_resp` and `agg_resp_id`. +* @param {Client} client +* @param {ReencryptionRequest | undefined} request +* @param {(ReencryptionResponse)[]} agg_resp +* @param {Uint32Array} agg_resp_ids +* @param {PublicEncKey} enc_pk +* @param {PrivateEncKey} enc_sk +* @returns {number} +*/ +export function process_reencryption_resp(client, request, agg_resp, agg_resp_ids, enc_pk, enc_sk) { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + _assertClass(client, Client); + let ptr0 = 0; + if (!isLikeNone(request)) { + _assertClass(request, ReencryptionRequest); + ptr0 = request.__destroy_into_raw(); + } + const ptr1 = passArrayJsValueToWasm0(agg_resp, wasm.__wbindgen_malloc); + const len1 = WASM_VECTOR_LEN; + const ptr2 = passArray32ToWasm0(agg_resp_ids, wasm.__wbindgen_malloc); + const len2 = WASM_VECTOR_LEN; + _assertClass(enc_pk, PublicEncKey); + _assertClass(enc_sk, PrivateEncKey); + wasm.process_reencryption_resp(retptr, client.__wbg_ptr, ptr0, ptr1, len1, ptr2, len2, enc_pk.__wbg_ptr, enc_sk.__wbg_ptr); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + var r2 = getInt32Memory0()[retptr / 4 + 2]; + if (r2) { + throw takeObject(r1); + } + return r0; + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } +} + +function handleError(f, args) { + try { + return f.apply(this, args); + } catch (e) { + wasm.__wbindgen_exn_store(addHeapObject(e)); + } +} +/** +* The plaintext types that can be encrypted in a fhevm ciphertext. +*/ +export const FheType = Object.freeze({ Bool:0,"0":"Bool",Euint4:1,"1":"Euint4",Euint8:2,"2":"Euint8",Euint16:3,"3":"Euint16",Euint32:4,"4":"Euint32",Euint64:5,"5":"Euint64",Euint128:6,"6":"Euint128",Euint160:7,"7":"Euint160", }); + +const ClientFinalization = (typeof FinalizationRegistry === 'undefined') + ? { register: () => {}, unregister: () => {} } + : new FinalizationRegistry(ptr => wasm.__wbg_client_free(ptr >>> 0)); +/** +* Simple client to interact with the KMS servers. This can be seen as a proof-of-concept +* and reference code for validating the KMS. The logic supplied by the client will be +* distributed accross the aggregator/proxy and smart contracts. +* TODO should probably aggregate the KmsEndpointClient to void having two client code bases +* exposed in tests and MVP +* +* client_sk is optional because sometimes the private signing key is kept +* in a secure location, e.g., hardware wallet. Calling functions that requires +* client_sk when it is None will return an error. +*/ +export class Client { + + static __wrap(ptr) { + ptr = ptr >>> 0; + const obj = Object.create(Client.prototype); + obj.__wbg_ptr = ptr; + ClientFinalization.register(obj, obj.__wbg_ptr, obj); + return obj; + } + + __destroy_into_raw() { + const ptr = this.__wbg_ptr; + this.__wbg_ptr = 0; + ClientFinalization.unregister(this); + return ptr; + } + + free() { + const ptr = this.__destroy_into_raw(); + wasm.__wbg_client_free(ptr); + } +} + +const CryptoBoxCtFinalization = (typeof FinalizationRegistry === 'undefined') + ? { register: () => {}, unregister: () => {} } + : new FinalizationRegistry(ptr => wasm.__wbg_cryptoboxct_free(ptr >>> 0)); +/** +*/ +export class CryptoBoxCt { + + static __wrap(ptr) { + ptr = ptr >>> 0; + const obj = Object.create(CryptoBoxCt.prototype); + obj.__wbg_ptr = ptr; + CryptoBoxCtFinalization.register(obj, obj.__wbg_ptr, obj); + return obj; + } + + __destroy_into_raw() { + const ptr = this.__wbg_ptr; + this.__wbg_ptr = 0; + CryptoBoxCtFinalization.unregister(this); + return ptr; + } + + free() { + const ptr = this.__destroy_into_raw(); + wasm.__wbg_cryptoboxct_free(ptr); + } +} + +const Eip712DomainMsgFinalization = (typeof FinalizationRegistry === 'undefined') + ? { register: () => {}, unregister: () => {} } + : new FinalizationRegistry(ptr => wasm.__wbg_eip712domainmsg_free(ptr >>> 0)); +/** +* +* eventually chain_id, verifying_contract and salt will be parsed in to solidity types +*/ +export class Eip712DomainMsg { + + static __wrap(ptr) { + ptr = ptr >>> 0; + const obj = Object.create(Eip712DomainMsg.prototype); + obj.__wbg_ptr = ptr; + Eip712DomainMsgFinalization.register(obj, obj.__wbg_ptr, obj); + return obj; + } + + __destroy_into_raw() { + const ptr = this.__wbg_ptr; + this.__wbg_ptr = 0; + Eip712DomainMsgFinalization.unregister(this); + return ptr; + } + + free() { + const ptr = this.__destroy_into_raw(); + wasm.__wbg_eip712domainmsg_free(ptr); + } + /** + * @returns {string} + */ + get name() { + let deferred1_0; + let deferred1_1; + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + wasm.__wbg_get_eip712domainmsg_name(retptr, this.__wbg_ptr); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + deferred1_0 = r0; + deferred1_1 = r1; + return getStringFromWasm0(r0, r1); + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + wasm.__wbindgen_free(deferred1_0, deferred1_1, 1); + } + } + /** + * @param {string} arg0 + */ + set name(arg0) { + const ptr0 = passStringToWasm0(arg0, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len0 = WASM_VECTOR_LEN; + wasm.__wbg_set_eip712domainmsg_name(this.__wbg_ptr, ptr0, len0); + } + /** + * @returns {string} + */ + get version() { + let deferred1_0; + let deferred1_1; + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + wasm.__wbg_get_eip712domainmsg_version(retptr, this.__wbg_ptr); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + deferred1_0 = r0; + deferred1_1 = r1; + return getStringFromWasm0(r0, r1); + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + wasm.__wbindgen_free(deferred1_0, deferred1_1, 1); + } + } + /** + * @param {string} arg0 + */ + set version(arg0) { + const ptr0 = passStringToWasm0(arg0, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len0 = WASM_VECTOR_LEN; + wasm.__wbg_set_eip712domainmsg_version(this.__wbg_ptr, ptr0, len0); + } + /** + * @returns {Uint8Array} + */ + get chain_id() { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + wasm.__wbg_get_eip712domainmsg_chain_id(retptr, this.__wbg_ptr); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + var v1 = getArrayU8FromWasm0(r0, r1).slice(); + wasm.__wbindgen_free(r0, r1 * 1, 1); + return v1; + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } + } + /** + * @param {Uint8Array} arg0 + */ + set chain_id(arg0) { + const ptr0 = passArray8ToWasm0(arg0, wasm.__wbindgen_malloc); + const len0 = WASM_VECTOR_LEN; + wasm.__wbg_set_eip712domainmsg_chain_id(this.__wbg_ptr, ptr0, len0); + } + /** + * @returns {string} + */ + get verifying_contract() { + let deferred1_0; + let deferred1_1; + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + wasm.__wbg_get_eip712domainmsg_verifying_contract(retptr, this.__wbg_ptr); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + deferred1_0 = r0; + deferred1_1 = r1; + return getStringFromWasm0(r0, r1); + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + wasm.__wbindgen_free(deferred1_0, deferred1_1, 1); + } + } + /** + * @param {string} arg0 + */ + set verifying_contract(arg0) { + const ptr0 = passStringToWasm0(arg0, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len0 = WASM_VECTOR_LEN; + wasm.__wbg_set_eip712domainmsg_verifying_contract(this.__wbg_ptr, ptr0, len0); + } + /** + * @returns {Uint8Array} + */ + get salt() { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + wasm.__wbg_get_eip712domainmsg_salt(retptr, this.__wbg_ptr); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + var v1 = getArrayU8FromWasm0(r0, r1).slice(); + wasm.__wbindgen_free(r0, r1 * 1, 1); + return v1; + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } + } + /** + * @param {Uint8Array} arg0 + */ + set salt(arg0) { + const ptr0 = passArray8ToWasm0(arg0, wasm.__wbindgen_malloc); + const len0 = WASM_VECTOR_LEN; + wasm.__wbg_set_eip712domainmsg_salt(this.__wbg_ptr, ptr0, len0); + } +} + +const PlaintextFinalization = (typeof FinalizationRegistry === 'undefined') + ? { register: () => {}, unregister: () => {} } + : new FinalizationRegistry(ptr => wasm.__wbg_plaintext_free(ptr >>> 0)); +/** +*/ +export class Plaintext { + + __destroy_into_raw() { + const ptr = this.__wbg_ptr; + this.__wbg_ptr = 0; + PlaintextFinalization.unregister(this); + return ptr; + } + + free() { + const ptr = this.__destroy_into_raw(); + wasm.__wbg_plaintext_free(ptr); + } + /** + * @returns {bigint} + */ + get lowest_bits() { + const ret = wasm.__wbg_get_plaintext_lowest_bits(this.__wbg_ptr); + return BigInt.asUintN(64, ret); + } + /** + * @param {bigint} arg0 + */ + set lowest_bits(arg0) { + wasm.__wbg_set_plaintext_lowest_bits(this.__wbg_ptr, arg0); + } + /** + * @returns {bigint} + */ + get middle_bits() { + const ret = wasm.__wbg_get_plaintext_middle_bits(this.__wbg_ptr); + return BigInt.asUintN(64, ret); + } + /** + * @param {bigint} arg0 + */ + set middle_bits(arg0) { + wasm.__wbg_set_plaintext_middle_bits(this.__wbg_ptr, arg0); + } + /** + * @returns {number} + */ + get higest_bits() { + const ret = wasm.__wbg_get_plaintext_higest_bits(this.__wbg_ptr); + return ret >>> 0; + } + /** + * @param {number} arg0 + */ + set higest_bits(arg0) { + wasm.__wbg_set_plaintext_higest_bits(this.__wbg_ptr, arg0); + } +} + +const PrivateEncKeyFinalization = (typeof FinalizationRegistry === 'undefined') + ? { register: () => {}, unregister: () => {} } + : new FinalizationRegistry(ptr => wasm.__wbg_privateenckey_free(ptr >>> 0)); +/** +*/ +export class PrivateEncKey { + + static __wrap(ptr) { + ptr = ptr >>> 0; + const obj = Object.create(PrivateEncKey.prototype); + obj.__wbg_ptr = ptr; + PrivateEncKeyFinalization.register(obj, obj.__wbg_ptr, obj); + return obj; + } + + __destroy_into_raw() { + const ptr = this.__wbg_ptr; + this.__wbg_ptr = 0; + PrivateEncKeyFinalization.unregister(this); + return ptr; + } + + free() { + const ptr = this.__destroy_into_raw(); + wasm.__wbg_privateenckey_free(ptr); + } +} + +const PrivateSigKeyFinalization = (typeof FinalizationRegistry === 'undefined') + ? { register: () => {}, unregister: () => {} } + : new FinalizationRegistry(ptr => wasm.__wbg_privatesigkey_free(ptr >>> 0)); +/** +*/ +export class PrivateSigKey { + + __destroy_into_raw() { + const ptr = this.__wbg_ptr; + this.__wbg_ptr = 0; + PrivateSigKeyFinalization.unregister(this); + return ptr; + } + + free() { + const ptr = this.__destroy_into_raw(); + wasm.__wbg_privatesigkey_free(ptr); + } +} + +const PublicEncKeyFinalization = (typeof FinalizationRegistry === 'undefined') + ? { register: () => {}, unregister: () => {} } + : new FinalizationRegistry(ptr => wasm.__wbg_publicenckey_free(ptr >>> 0)); +/** +*/ +export class PublicEncKey { + + static __wrap(ptr) { + ptr = ptr >>> 0; + const obj = Object.create(PublicEncKey.prototype); + obj.__wbg_ptr = ptr; + PublicEncKeyFinalization.register(obj, obj.__wbg_ptr, obj); + return obj; + } + + __destroy_into_raw() { + const ptr = this.__wbg_ptr; + this.__wbg_ptr = 0; + PublicEncKeyFinalization.unregister(this); + return ptr; + } + + free() { + const ptr = this.__destroy_into_raw(); + wasm.__wbg_publicenckey_free(ptr); + } +} + +const PublicSigKeyFinalization = (typeof FinalizationRegistry === 'undefined') + ? { register: () => {}, unregister: () => {} } + : new FinalizationRegistry(ptr => wasm.__wbg_publicsigkey_free(ptr >>> 0)); +/** +*/ +export class PublicSigKey { + + static __unwrap(jsValue) { + if (!(jsValue instanceof PublicSigKey)) { + return 0; + } + return jsValue.__destroy_into_raw(); + } + + __destroy_into_raw() { + const ptr = this.__wbg_ptr; + this.__wbg_ptr = 0; + PublicSigKeyFinalization.unregister(this); + return ptr; + } + + free() { + const ptr = this.__destroy_into_raw(); + wasm.__wbg_publicsigkey_free(ptr); + } +} + +const ReencryptionRequestFinalization = (typeof FinalizationRegistry === 'undefined') + ? { register: () => {}, unregister: () => {} } + : new FinalizationRegistry(ptr => wasm.__wbg_reencryptionrequest_free(ptr >>> 0)); +/** +*/ +export class ReencryptionRequest { + + static __wrap(ptr) { + ptr = ptr >>> 0; + const obj = Object.create(ReencryptionRequest.prototype); + obj.__wbg_ptr = ptr; + ReencryptionRequestFinalization.register(obj, obj.__wbg_ptr, obj); + return obj; + } + + __destroy_into_raw() { + const ptr = this.__wbg_ptr; + this.__wbg_ptr = 0; + ReencryptionRequestFinalization.unregister(this); + return ptr; + } + + free() { + const ptr = this.__destroy_into_raw(); + wasm.__wbg_reencryptionrequest_free(ptr); + } + /** + * Signature of the ASN1 DER serialization of \[ReencryptionRequestPayload\]. + * @returns {Uint8Array} + */ + get signature() { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + wasm.__wbg_get_reencryptionrequest_signature(retptr, this.__wbg_ptr); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + var v1 = getArrayU8FromWasm0(r0, r1).slice(); + wasm.__wbindgen_free(r0, r1 * 1, 1); + return v1; + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } + } + /** + * Signature of the ASN1 DER serialization of \[ReencryptionRequestPayload\]. + * @param {Uint8Array} arg0 + */ + set signature(arg0) { + const ptr0 = passArray8ToWasm0(arg0, wasm.__wbindgen_malloc); + const len0 = WASM_VECTOR_LEN; + wasm.__wbg_set_eip712domainmsg_name(this.__wbg_ptr, ptr0, len0); + } + /** + * @returns {ReencryptionRequestPayload | undefined} + */ + get payload() { + const ret = wasm.__wbg_get_reencryptionrequest_payload(this.__wbg_ptr); + return ret === 0 ? undefined : ReencryptionRequestPayload.__wrap(ret); + } + /** + * @param {ReencryptionRequestPayload | undefined} [arg0] + */ + set payload(arg0) { + let ptr0 = 0; + if (!isLikeNone(arg0)) { + _assertClass(arg0, ReencryptionRequestPayload); + ptr0 = arg0.__destroy_into_raw(); + } + wasm.__wbg_set_reencryptionrequest_payload(this.__wbg_ptr, ptr0); + } + /** + * @returns {Eip712DomainMsg | undefined} + */ + get domain() { + const ret = wasm.__wbg_get_reencryptionrequest_domain(this.__wbg_ptr); + return ret === 0 ? undefined : Eip712DomainMsg.__wrap(ret); + } + /** + * @param {Eip712DomainMsg | undefined} [arg0] + */ + set domain(arg0) { + let ptr0 = 0; + if (!isLikeNone(arg0)) { + _assertClass(arg0, Eip712DomainMsg); + ptr0 = arg0.__destroy_into_raw(); + } + wasm.__wbg_set_reencryptionrequest_domain(this.__wbg_ptr, ptr0); + } + /** + * The ID that identifies this request. + * Future queries for the result must use this request ID. + * @returns {RequestId | undefined} + */ + get request_id() { + const ret = wasm.__wbg_get_reencryptionrequest_request_id(this.__wbg_ptr); + return ret === 0 ? undefined : RequestId.__wrap(ret); + } + /** + * The ID that identifies this request. + * Future queries for the result must use this request ID. + * @param {RequestId | undefined} [arg0] + */ + set request_id(arg0) { + let ptr0 = 0; + if (!isLikeNone(arg0)) { + _assertClass(arg0, RequestId); + ptr0 = arg0.__destroy_into_raw(); + } + wasm.__wbg_set_reencryptionrequest_request_id(this.__wbg_ptr, ptr0); + } +} + +const ReencryptionRequestPayloadFinalization = (typeof FinalizationRegistry === 'undefined') + ? { register: () => {}, unregister: () => {} } + : new FinalizationRegistry(ptr => wasm.__wbg_reencryptionrequestpayload_free(ptr >>> 0)); +/** +*/ +export class ReencryptionRequestPayload { + + static __wrap(ptr) { + ptr = ptr >>> 0; + const obj = Object.create(ReencryptionRequestPayload.prototype); + obj.__wbg_ptr = ptr; + ReencryptionRequestPayloadFinalization.register(obj, obj.__wbg_ptr, obj); + return obj; + } + + __destroy_into_raw() { + const ptr = this.__wbg_ptr; + this.__wbg_ptr = 0; + ReencryptionRequestPayloadFinalization.unregister(this); + return ptr; + } + + free() { + const ptr = this.__destroy_into_raw(); + wasm.__wbg_reencryptionrequestpayload_free(ptr); + } + /** + * Version of the request format. + * @returns {number} + */ + get version() { + const ret = wasm.__wbg_get_reencryptionrequestpayload_version(this.__wbg_ptr); + return ret >>> 0; + } + /** + * Version of the request format. + * @param {number} arg0 + */ + set version(arg0) { + wasm.__wbg_set_reencryptionrequestpayload_version(this.__wbg_ptr, arg0); + } + /** + * The amount of shares needed to recombine the result. + * This implies the threshold used. + * Needed to avoid a single malicious server taking over a request that should + * have been distributed. + * @returns {number} + */ + get servers_needed() { + const ret = wasm.__wbg_get_reencryptionrequestpayload_servers_needed(this.__wbg_ptr); + return ret >>> 0; + } + /** + * The amount of shares needed to recombine the result. + * This implies the threshold used. + * Needed to avoid a single malicious server taking over a request that should + * have been distributed. + * @param {number} arg0 + */ + set servers_needed(arg0) { + wasm.__wbg_set_reencryptionrequestpayload_servers_needed(this.__wbg_ptr, arg0); + } + /** + * The server's signature verification key. + * Encoded using SEC1. + * TODO not needed in the request! Should be removed + * @returns {Uint8Array} + */ + get verification_key() { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + wasm.__wbg_get_reencryptionrequest_signature(retptr, this.__wbg_ptr); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + var v1 = getArrayU8FromWasm0(r0, r1).slice(); + wasm.__wbindgen_free(r0, r1 * 1, 1); + return v1; + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } + } + /** + * The server's signature verification key. + * Encoded using SEC1. + * TODO not needed in the request! Should be removed + * @param {Uint8Array} arg0 + */ + set verification_key(arg0) { + const ptr0 = passArray8ToWasm0(arg0, wasm.__wbindgen_malloc); + const len0 = WASM_VECTOR_LEN; + wasm.__wbg_set_eip712domainmsg_name(this.__wbg_ptr, ptr0, len0); + } + /** + * Randomness specified in the request to ensure EU-CMA of the signed response. + * TODO check that we don't need two types of randomness. One for the reuqest and one for the response + * TODO also check potential risk with repeated calls + * @returns {Uint8Array} + */ + get randomness() { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + wasm.__wbg_get_reencryptionrequestpayload_randomness(retptr, this.__wbg_ptr); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + var v1 = getArrayU8FromWasm0(r0, r1).slice(); + wasm.__wbindgen_free(r0, r1 * 1, 1); + return v1; + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } + } + /** + * Randomness specified in the request to ensure EU-CMA of the signed response. + * TODO check that we don't need two types of randomness. One for the reuqest and one for the response + * TODO also check potential risk with repeated calls + * @param {Uint8Array} arg0 + */ + set randomness(arg0) { + const ptr0 = passArray8ToWasm0(arg0, wasm.__wbindgen_malloc); + const len0 = WASM_VECTOR_LEN; + wasm.__wbg_set_eip712domainmsg_version(this.__wbg_ptr, ptr0, len0); + } + /** + * Encoding of the user's public encryption key for this request. + * Encoding using the default encoding of libsodium, i.e. the 32 bytes of a + * Montgomery point. + * @returns {Uint8Array} + */ + get enc_key() { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + wasm.__wbg_get_eip712domainmsg_chain_id(retptr, this.__wbg_ptr); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + var v1 = getArrayU8FromWasm0(r0, r1).slice(); + wasm.__wbindgen_free(r0, r1 * 1, 1); + return v1; + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } + } + /** + * Encoding of the user's public encryption key for this request. + * Encoding using the default encoding of libsodium, i.e. the 32 bytes of a + * Montgomery point. + * @param {Uint8Array} arg0 + */ + set enc_key(arg0) { + const ptr0 = passArray8ToWasm0(arg0, wasm.__wbindgen_malloc); + const len0 = WASM_VECTOR_LEN; + wasm.__wbg_set_eip712domainmsg_chain_id(this.__wbg_ptr, ptr0, len0); + } + /** + * The type of plaintext encrypted. + * @returns {number} + */ + get fhe_type() { + const ret = wasm.__wbg_get_reencryptionrequestpayload_fhe_type(this.__wbg_ptr); + return ret; + } + /** + * The type of plaintext encrypted. + * @param {number} arg0 + */ + set fhe_type(arg0) { + wasm.__wbg_set_reencryptionrequestpayload_fhe_type(this.__wbg_ptr, arg0); + } + /** + * The key id to use for decryption. Will be the request_id used during key generation + * @returns {RequestId | undefined} + */ + get key_id() { + const ret = wasm.__wbg_get_reencryptionrequestpayload_key_id(this.__wbg_ptr); + return ret === 0 ? undefined : RequestId.__wrap(ret); + } + /** + * The key id to use for decryption. Will be the request_id used during key generation + * @param {RequestId | undefined} [arg0] + */ + set key_id(arg0) { + let ptr0 = 0; + if (!isLikeNone(arg0)) { + _assertClass(arg0, RequestId); + ptr0 = arg0.__destroy_into_raw(); + } + wasm.__wbg_set_reencryptionrequestpayload_key_id(this.__wbg_ptr, ptr0); + } + /** + * The actual ciphertext to decrypt, taken directly from the fhevm. + * When creating the payload, this field may be empty, + * it is the responsibility of the gateway to fetch the + * ciphertext for the given digest below. + * @returns {Uint8Array | undefined} + */ + get ciphertext() { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + wasm.__wbg_get_reencryptionrequestpayload_ciphertext(retptr, this.__wbg_ptr); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + let v1; + if (r0 !== 0) { + v1 = getArrayU8FromWasm0(r0, r1).slice(); + wasm.__wbindgen_free(r0, r1 * 1, 1); + } + return v1; + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } + } + /** + * The actual ciphertext to decrypt, taken directly from the fhevm. + * When creating the payload, this field may be empty, + * it is the responsibility of the gateway to fetch the + * ciphertext for the given digest below. + * @param {Uint8Array | undefined} [arg0] + */ + set ciphertext(arg0) { + var ptr0 = isLikeNone(arg0) ? 0 : passArray8ToWasm0(arg0, wasm.__wbindgen_malloc); + var len0 = WASM_VECTOR_LEN; + wasm.__wbg_set_reencryptionrequestpayload_ciphertext(this.__wbg_ptr, ptr0, len0); + } + /** + * The SHA3 digest of the ciphertext above. + * @returns {Uint8Array} + */ + get ciphertext_digest() { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + wasm.__wbg_get_reencryptionrequestpayload_ciphertext_digest(retptr, this.__wbg_ptr); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + var v1 = getArrayU8FromWasm0(r0, r1).slice(); + wasm.__wbindgen_free(r0, r1 * 1, 1); + return v1; + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } + } + /** + * The SHA3 digest of the ciphertext above. + * @param {Uint8Array} arg0 + */ + set ciphertext_digest(arg0) { + const ptr0 = passArray8ToWasm0(arg0, wasm.__wbindgen_malloc); + const len0 = WASM_VECTOR_LEN; + wasm.__wbg_set_eip712domainmsg_verifying_contract(this.__wbg_ptr, ptr0, len0); + } +} + +const ReencryptionResponseFinalization = (typeof FinalizationRegistry === 'undefined') + ? { register: () => {}, unregister: () => {} } + : new FinalizationRegistry(ptr => wasm.__wbg_reencryptionresponse_free(ptr >>> 0)); +/** +*/ +export class ReencryptionResponse { + + static __unwrap(jsValue) { + if (!(jsValue instanceof ReencryptionResponse)) { + return 0; + } + return jsValue.__destroy_into_raw(); + } + + __destroy_into_raw() { + const ptr = this.__wbg_ptr; + this.__wbg_ptr = 0; + ReencryptionResponseFinalization.unregister(this); + return ptr; + } + + free() { + const ptr = this.__destroy_into_raw(); + wasm.__wbg_reencryptionresponse_free(ptr); + } + /** + * Version of the response format. + * @returns {number} + */ + get version() { + const ret = wasm.__wbg_get_reencryptionresponse_version(this.__wbg_ptr); + return ret >>> 0; + } + /** + * Version of the response format. + * @param {number} arg0 + */ + set version(arg0) { + wasm.__wbg_set_reencryptionresponse_version(this.__wbg_ptr, arg0); + } + /** + * Servers_needed are not really needed since there is a link to the + * digest, however, it seems better to be able to handle a response without + * getting data from the request as well. but this is also a security issue + * since it is possible to get meaning from the response without directly + * linking it to a request + * + * The amount of shares needed to recombine the result. + * This implies the threshold used. + * @returns {number} + */ + get servers_needed() { + const ret = wasm.__wbg_get_reencryptionresponse_servers_needed(this.__wbg_ptr); + return ret >>> 0; + } + /** + * Servers_needed are not really needed since there is a link to the + * digest, however, it seems better to be able to handle a response without + * getting data from the request as well. but this is also a security issue + * since it is possible to get meaning from the response without directly + * linking it to a request + * + * The amount of shares needed to recombine the result. + * This implies the threshold used. + * @param {number} arg0 + */ + set servers_needed(arg0) { + wasm.__wbg_set_reencryptionresponse_servers_needed(this.__wbg_ptr, arg0); + } + /** + * The server's signature verification key. + * Encoded using SEC1. + * Needed to validate the response, but MUST also be linked to a list of + * trusted keys. + * @returns {Uint8Array} + */ + get verification_key() { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + wasm.__wbg_get_reencryptionrequest_signature(retptr, this.__wbg_ptr); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + var v1 = getArrayU8FromWasm0(r0, r1).slice(); + wasm.__wbindgen_free(r0, r1 * 1, 1); + return v1; + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } + } + /** + * The server's signature verification key. + * Encoded using SEC1. + * Needed to validate the response, but MUST also be linked to a list of + * trusted keys. + * @param {Uint8Array} arg0 + */ + set verification_key(arg0) { + const ptr0 = passArray8ToWasm0(arg0, wasm.__wbindgen_malloc); + const len0 = WASM_VECTOR_LEN; + wasm.__wbg_set_eip712domainmsg_name(this.__wbg_ptr, ptr0, len0); + } + /** + * Digest of the request validated. + * Needed to ensure that the response is for the expected request. + * @returns {Uint8Array} + */ + get digest() { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + wasm.__wbg_get_reencryptionrequestpayload_randomness(retptr, this.__wbg_ptr); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + var v1 = getArrayU8FromWasm0(r0, r1).slice(); + wasm.__wbindgen_free(r0, r1 * 1, 1); + return v1; + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } + } + /** + * Digest of the request validated. + * Needed to ensure that the response is for the expected request. + * @param {Uint8Array} arg0 + */ + set digest(arg0) { + const ptr0 = passArray8ToWasm0(arg0, wasm.__wbindgen_malloc); + const len0 = WASM_VECTOR_LEN; + wasm.__wbg_set_eip712domainmsg_version(this.__wbg_ptr, ptr0, len0); + } + /** + * The type of plaintext encrypted. + * @returns {number} + */ + get fhe_type() { + const ret = wasm.__wbg_get_reencryptionresponse_fhe_type(this.__wbg_ptr); + return ret; + } + /** + * The type of plaintext encrypted. + * @param {number} arg0 + */ + set fhe_type(arg0) { + wasm.__wbg_set_reencryptionresponse_fhe_type(this.__wbg_ptr, arg0); + } + /** + * The signcrypted payload, using a hybrid encryption approach in + * sign-then-encrypt. + * @returns {Uint8Array} + */ + get signcrypted_ciphertext() { + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + wasm.__wbg_get_eip712domainmsg_chain_id(retptr, this.__wbg_ptr); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + var v1 = getArrayU8FromWasm0(r0, r1).slice(); + wasm.__wbindgen_free(r0, r1 * 1, 1); + return v1; + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + } + } + /** + * The signcrypted payload, using a hybrid encryption approach in + * sign-then-encrypt. + * @param {Uint8Array} arg0 + */ + set signcrypted_ciphertext(arg0) { + const ptr0 = passArray8ToWasm0(arg0, wasm.__wbindgen_malloc); + const len0 = WASM_VECTOR_LEN; + wasm.__wbg_set_eip712domainmsg_chain_id(this.__wbg_ptr, ptr0, len0); + } +} + +const RequestIdFinalization = (typeof FinalizationRegistry === 'undefined') + ? { register: () => {}, unregister: () => {} } + : new FinalizationRegistry(ptr => wasm.__wbg_requestid_free(ptr >>> 0)); +/** +* Simple response to return an ID, to be used to retrieve the computed result later on. +*/ +export class RequestId { + + static __wrap(ptr) { + ptr = ptr >>> 0; + const obj = Object.create(RequestId.prototype); + obj.__wbg_ptr = ptr; + RequestIdFinalization.register(obj, obj.__wbg_ptr, obj); + return obj; + } + + __destroy_into_raw() { + const ptr = this.__wbg_ptr; + this.__wbg_ptr = 0; + RequestIdFinalization.unregister(this); + return ptr; + } + + free() { + const ptr = this.__destroy_into_raw(); + wasm.__wbg_requestid_free(ptr); + } + /** + * @returns {string} + */ + get request_id() { + let deferred1_0; + let deferred1_1; + try { + const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); + wasm.__wbg_get_eip712domainmsg_name(retptr, this.__wbg_ptr); + var r0 = getInt32Memory0()[retptr / 4 + 0]; + var r1 = getInt32Memory0()[retptr / 4 + 1]; + deferred1_0 = r0; + deferred1_1 = r1; + return getStringFromWasm0(r0, r1); + } finally { + wasm.__wbindgen_add_to_stack_pointer(16); + wasm.__wbindgen_free(deferred1_0, deferred1_1, 1); + } + } + /** + * @param {string} arg0 + */ + set request_id(arg0) { + const ptr0 = passStringToWasm0(arg0, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len0 = WASM_VECTOR_LEN; + wasm.__wbg_set_eip712domainmsg_name(this.__wbg_ptr, ptr0, len0); + } +} + +async function __wbg_load(module, imports) { + if (typeof Response === 'function' && module instanceof Response) { + if (typeof WebAssembly.instantiateStreaming === 'function') { + try { + return await WebAssembly.instantiateStreaming(module, imports); + + } catch (e) { + if (module.headers.get('Content-Type') != 'application/wasm') { + console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e); + + } else { + throw e; + } + } + } + + const bytes = await module.arrayBuffer(); + return await WebAssembly.instantiate(bytes, imports); + + } else { + const instance = await WebAssembly.instantiate(module, imports); + + if (instance instanceof WebAssembly.Instance) { + return { instance, module }; + + } else { + return instance; + } + } +} + +function __wbg_get_imports() { + const imports = {}; + imports.wbg = {}; + imports.wbg.__wbg_reencryptionresponse_unwrap = function(arg0) { + const ret = ReencryptionResponse.__unwrap(takeObject(arg0)); + return ret; + }; + imports.wbg.__wbindgen_object_drop_ref = function(arg0) { + takeObject(arg0); + }; + imports.wbg.__wbindgen_error_new = function(arg0, arg1) { + const ret = new Error(getStringFromWasm0(arg0, arg1)); + return addHeapObject(ret); + }; + imports.wbg.__wbg_publicsigkey_unwrap = function(arg0) { + const ret = PublicSigKey.__unwrap(takeObject(arg0)); + return ret; + }; + imports.wbg.__wbg_new_abda76e883ba8a5f = function() { + const ret = new Error(); + return addHeapObject(ret); + }; + imports.wbg.__wbg_stack_658279fe44541cf6 = function(arg0, arg1) { + const ret = getObject(arg1).stack; + const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); + const len1 = WASM_VECTOR_LEN; + getInt32Memory0()[arg0 / 4 + 1] = len1; + getInt32Memory0()[arg0 / 4 + 0] = ptr1; + }; + imports.wbg.__wbg_error_f851667af71bcfc6 = function(arg0, arg1) { + let deferred0_0; + let deferred0_1; + try { + deferred0_0 = arg0; + deferred0_1 = arg1; + console.error(getStringFromWasm0(arg0, arg1)); + } finally { + wasm.__wbindgen_free(deferred0_0, deferred0_1, 1); + } + }; + imports.wbg.__wbg_crypto_1d1f22824a6a080c = function(arg0) { + const ret = getObject(arg0).crypto; + return addHeapObject(ret); + }; + imports.wbg.__wbindgen_is_object = function(arg0) { + const val = getObject(arg0); + const ret = typeof(val) === 'object' && val !== null; + return ret; + }; + imports.wbg.__wbg_process_4a72847cc503995b = function(arg0) { + const ret = getObject(arg0).process; + return addHeapObject(ret); + }; + imports.wbg.__wbg_versions_f686565e586dd935 = function(arg0) { + const ret = getObject(arg0).versions; + return addHeapObject(ret); + }; + imports.wbg.__wbg_node_104a2ff8d6ea03a2 = function(arg0) { + const ret = getObject(arg0).node; + return addHeapObject(ret); + }; + imports.wbg.__wbindgen_is_string = function(arg0) { + const ret = typeof(getObject(arg0)) === 'string'; + return ret; + }; + imports.wbg.__wbg_msCrypto_eb05e62b530a1508 = function(arg0) { + const ret = getObject(arg0).msCrypto; + return addHeapObject(ret); + }; + imports.wbg.__wbg_require_cca90b1a94a0255b = function() { return handleError(function () { + const ret = module.require; + return addHeapObject(ret); + }, arguments) }; + imports.wbg.__wbindgen_is_function = function(arg0) { + const ret = typeof(getObject(arg0)) === 'function'; + return ret; + }; + imports.wbg.__wbindgen_string_new = function(arg0, arg1) { + const ret = getStringFromWasm0(arg0, arg1); + return addHeapObject(ret); + }; + imports.wbg.__wbg_randomFillSync_5c9c955aa56b6049 = function() { return handleError(function (arg0, arg1) { + getObject(arg0).randomFillSync(takeObject(arg1)); + }, arguments) }; + imports.wbg.__wbg_getRandomValues_3aa56aa6edec874c = function() { return handleError(function (arg0, arg1) { + getObject(arg0).getRandomValues(getObject(arg1)); + }, arguments) }; + imports.wbg.__wbg_newnoargs_e258087cd0daa0ea = function(arg0, arg1) { + const ret = new Function(getStringFromWasm0(arg0, arg1)); + return addHeapObject(ret); + }; + imports.wbg.__wbg_call_27c0f87801dedf93 = function() { return handleError(function (arg0, arg1) { + const ret = getObject(arg0).call(getObject(arg1)); + return addHeapObject(ret); + }, arguments) }; + imports.wbg.__wbindgen_object_clone_ref = function(arg0) { + const ret = getObject(arg0); + return addHeapObject(ret); + }; + imports.wbg.__wbg_self_ce0dbfc45cf2f5be = function() { return handleError(function () { + const ret = self.self; + return addHeapObject(ret); + }, arguments) }; + imports.wbg.__wbg_window_c6fb939a7f436783 = function() { return handleError(function () { + const ret = window.window; + return addHeapObject(ret); + }, arguments) }; + imports.wbg.__wbg_globalThis_d1e6af4856ba331b = function() { return handleError(function () { + const ret = globalThis.globalThis; + return addHeapObject(ret); + }, arguments) }; + imports.wbg.__wbg_global_207b558942527489 = function() { return handleError(function () { + const ret = global.global; + return addHeapObject(ret); + }, arguments) }; + imports.wbg.__wbindgen_is_undefined = function(arg0) { + const ret = getObject(arg0) === undefined; + return ret; + }; + imports.wbg.__wbg_call_b3ca7c6051f9bec1 = function() { return handleError(function (arg0, arg1, arg2) { + const ret = getObject(arg0).call(getObject(arg1), getObject(arg2)); + return addHeapObject(ret); + }, arguments) }; + imports.wbg.__wbg_buffer_12d079cc21e14bdb = function(arg0) { + const ret = getObject(arg0).buffer; + return addHeapObject(ret); + }; + imports.wbg.__wbg_newwithbyteoffsetandlength_aa4a17c33a06e5cb = function(arg0, arg1, arg2) { + const ret = new Uint8Array(getObject(arg0), arg1 >>> 0, arg2 >>> 0); + return addHeapObject(ret); + }; + imports.wbg.__wbg_new_63b92bc8671ed464 = function(arg0) { + const ret = new Uint8Array(getObject(arg0)); + return addHeapObject(ret); + }; + imports.wbg.__wbg_set_a47bac70306a19a7 = function(arg0, arg1, arg2) { + getObject(arg0).set(getObject(arg1), arg2 >>> 0); + }; + imports.wbg.__wbg_newwithlength_e9b4878cebadb3d3 = function(arg0) { + const ret = new Uint8Array(arg0 >>> 0); + return addHeapObject(ret); + }; + imports.wbg.__wbg_subarray_a1f73cd4b5b42fe1 = function(arg0, arg1, arg2) { + const ret = getObject(arg0).subarray(arg1 >>> 0, arg2 >>> 0); + return addHeapObject(ret); + }; + imports.wbg.__wbindgen_throw = function(arg0, arg1) { + throw new Error(getStringFromWasm0(arg0, arg1)); + }; + imports.wbg.__wbindgen_memory = function() { + const ret = wasm.memory; + return addHeapObject(ret); + }; + + return imports; +} + +function __wbg_init_memory(imports, maybe_memory) { + +} + +function __wbg_finalize_init(instance, module) { + wasm = instance.exports; + __wbg_init.__wbindgen_wasm_module = module; + cachedInt32Memory0 = null; + cachedUint32Memory0 = null; + cachedUint8Memory0 = null; + + + return wasm; +} + +function initSync(module) { + if (wasm !== undefined) return wasm; + + const imports = __wbg_get_imports(); + + __wbg_init_memory(imports); + + if (!(module instanceof WebAssembly.Module)) { + module = new WebAssembly.Module(module); + } + + const instance = new WebAssembly.Instance(module, imports); + + return __wbg_finalize_init(instance, module); +} + +async function __wbg_init(input) { + if (wasm !== undefined) return wasm; + + if (typeof input === 'undefined') { + input = new URL('kms_lib_bg.wasm', import.meta.url); + } + const imports = __wbg_get_imports(); + + if (typeof input === 'string' || (typeof Request === 'function' && input instanceof Request) || (typeof URL === 'function' && input instanceof URL)) { + input = fetch(input); + } + + __wbg_init_memory(imports); + + const { instance, module } = await __wbg_load(await input, imports); + + return __wbg_finalize_init(instance, module); +} + +export { initSync } +export default __wbg_init; diff --git a/src/kms/web/kms_lib_bg.wasm b/src/kms/web/kms_lib_bg.wasm new file mode 100644 index 0000000..d036e82 Binary files /dev/null and b/src/kms/web/kms_lib_bg.wasm differ diff --git a/src/kms/web/kms_lib_bg.wasm.d.ts b/src/kms/web/kms_lib_bg.wasm.d.ts new file mode 100644 index 0000000..d2bdf1d --- /dev/null +++ b/src/kms/web/kms_lib_bg.wasm.d.ts @@ -0,0 +1,87 @@ +/* tslint:disable */ +/* eslint-disable */ +export const memory: WebAssembly.Memory; +export function __wbg_client_free(a: number): void; +export function __wbg_requestid_free(a: number): void; +export function __wbg_reencryptionrequestpayload_free(a: number): void; +export function __wbg_get_reencryptionrequestpayload_version(a: number): number; +export function __wbg_set_reencryptionrequestpayload_version(a: number, b: number): void; +export function __wbg_get_reencryptionrequestpayload_servers_needed(a: number): number; +export function __wbg_set_reencryptionrequestpayload_servers_needed(a: number, b: number): void; +export function __wbg_get_reencryptionrequestpayload_randomness(a: number, b: number): void; +export function __wbg_get_reencryptionrequestpayload_fhe_type(a: number): number; +export function __wbg_set_reencryptionrequestpayload_fhe_type(a: number, b: number): void; +export function __wbg_get_reencryptionrequestpayload_key_id(a: number): number; +export function __wbg_set_reencryptionrequestpayload_key_id(a: number, b: number): void; +export function __wbg_get_reencryptionrequestpayload_ciphertext(a: number, b: number): void; +export function __wbg_set_reencryptionrequestpayload_ciphertext(a: number, b: number, c: number): void; +export function __wbg_get_reencryptionrequestpayload_ciphertext_digest(a: number, b: number): void; +export function __wbg_eip712domainmsg_free(a: number): void; +export function __wbg_get_eip712domainmsg_name(a: number, b: number): void; +export function __wbg_set_eip712domainmsg_name(a: number, b: number, c: number): void; +export function __wbg_get_eip712domainmsg_version(a: number, b: number): void; +export function __wbg_set_eip712domainmsg_version(a: number, b: number, c: number): void; +export function __wbg_get_eip712domainmsg_chain_id(a: number, b: number): void; +export function __wbg_set_eip712domainmsg_chain_id(a: number, b: number, c: number): void; +export function __wbg_get_eip712domainmsg_verifying_contract(a: number, b: number): void; +export function __wbg_set_eip712domainmsg_verifying_contract(a: number, b: number, c: number): void; +export function __wbg_get_eip712domainmsg_salt(a: number, b: number): void; +export function __wbg_set_eip712domainmsg_salt(a: number, b: number, c: number): void; +export function __wbg_reencryptionrequest_free(a: number): void; +export function __wbg_get_reencryptionrequest_signature(a: number, b: number): void; +export function __wbg_get_reencryptionrequest_payload(a: number): number; +export function __wbg_set_reencryptionrequest_payload(a: number, b: number): void; +export function __wbg_get_reencryptionrequest_domain(a: number): number; +export function __wbg_set_reencryptionrequest_domain(a: number, b: number): void; +export function __wbg_get_reencryptionrequest_request_id(a: number): number; +export function __wbg_set_reencryptionrequest_request_id(a: number, b: number): void; +export function __wbg_reencryptionresponse_free(a: number): void; +export function __wbg_get_reencryptionresponse_version(a: number): number; +export function __wbg_set_reencryptionresponse_version(a: number, b: number): void; +export function __wbg_get_reencryptionresponse_servers_needed(a: number): number; +export function __wbg_set_reencryptionresponse_servers_needed(a: number, b: number): void; +export function __wbg_get_reencryptionresponse_fhe_type(a: number): number; +export function __wbg_set_reencryptionresponse_fhe_type(a: number, b: number): void; +export function __wbg_get_reencryptionrequestpayload_enc_key(a: number, b: number): void; +export function __wbg_get_reencryptionrequestpayload_verification_key(a: number, b: number): void; +export function __wbg_get_reencryptionresponse_verification_key(a: number, b: number): void; +export function __wbg_get_reencryptionresponse_digest(a: number, b: number): void; +export function __wbg_get_reencryptionresponse_signcrypted_ciphertext(a: number, b: number): void; +export function __wbg_get_requestid_request_id(a: number, b: number): void; +export function __wbg_set_requestid_request_id(a: number, b: number, c: number): void; +export function __wbg_set_reencryptionrequestpayload_verification_key(a: number, b: number, c: number): void; +export function __wbg_set_reencryptionrequestpayload_randomness(a: number, b: number, c: number): void; +export function __wbg_set_reencryptionrequestpayload_enc_key(a: number, b: number, c: number): void; +export function __wbg_set_reencryptionrequestpayload_ciphertext_digest(a: number, b: number, c: number): void; +export function __wbg_set_reencryptionrequest_signature(a: number, b: number, c: number): void; +export function __wbg_set_reencryptionresponse_verification_key(a: number, b: number, c: number): void; +export function __wbg_set_reencryptionresponse_digest(a: number, b: number, c: number): void; +export function __wbg_set_reencryptionresponse_signcrypted_ciphertext(a: number, b: number, c: number): void; +export function __wbg_plaintext_free(a: number): void; +export function __wbg_get_plaintext_lowest_bits(a: number): number; +export function __wbg_set_plaintext_lowest_bits(a: number, b: number): void; +export function __wbg_get_plaintext_middle_bits(a: number): number; +export function __wbg_set_plaintext_middle_bits(a: number, b: number): void; +export function __wbg_get_plaintext_higest_bits(a: number): number; +export function __wbg_set_plaintext_higest_bits(a: number, b: number): void; +export function new_client(a: number, b: number, c: number, d: number, e: number, f: number): number; +export function __wbg_cryptoboxct_free(a: number): void; +export function cryptobox_keygen(): number; +export function cryptobox_get_pk(a: number): number; +export function cryptobox_pk_to_u8vec(a: number, b: number): void; +export function cryptobox_sk_to_u8vec(a: number, b: number): void; +export function u8vec_to_cryptobox_pk(a: number, b: number, c: number): void; +export function u8vec_to_cryptobox_sk(a: number, b: number, c: number): void; +export function cryptobox_encrypt(a: number, b: number, c: number, d: number): number; +export function cryptobox_decrypt(a: number, b: number, c: number, d: number): void; +export function make_reencryption_req(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number): void; +export function process_reencryption_resp(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number): void; +export function __wbg_publicenckey_free(a: number): void; +export function __wbg_privateenckey_free(a: number): void; +export function __wbg_publicsigkey_free(a: number): void; +export function __wbg_privatesigkey_free(a: number): void; +export function __wbindgen_add_to_stack_pointer(a: number): number; +export function __wbindgen_free(a: number, b: number, c: number): void; +export function __wbindgen_malloc(a: number, b: number): number; +export function __wbindgen_realloc(a: number, b: number, c: number, d: number): number; +export function __wbindgen_exn_store(a: number): void; diff --git a/src/kms/web/package.json b/src/kms/web/package.json new file mode 100644 index 0000000..c10d1d3 --- /dev/null +++ b/src/kms/web/package.json @@ -0,0 +1,14 @@ +{ + "name": "kms", + "version": "0.1.0", + "files": [ + "kms_lib_bg.wasm", + "kms_lib.js", + "kms_lib.d.ts" + ], + "module": "kms_lib.js", + "types": "kms_lib.d.ts", + "sideEffects": [ + "./snippets/*" + ] +} \ No newline at end of file diff --git a/src/node.d.ts b/src/node.d.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/node.ts b/src/node.ts index 9d5f06e..ceeed48 100644 --- a/src/node.ts +++ b/src/node.ts @@ -1,4 +1,13 @@ //@ts-check +import fetch, { Headers, Request, Response } from 'node-fetch'; + +if (!global.fetch) { + global.fetch = fetch as any; + globalThis.Headers = Headers as any; + globalThis.Request = Request as any; + globalThis.Response = Response as any; +} + export * from './sdk'; export * from './tfhe'; export { clientKeyDecryptor } from './utils'; diff --git a/src/sdk/decrypt.test.ts b/src/sdk/decrypt.test.ts deleted file mode 100644 index 4c4c58f..0000000 --- a/src/sdk/decrypt.test.ts +++ /dev/null @@ -1,75 +0,0 @@ -import sodium from 'libsodium-wrappers'; -import { decrypt, decryptAddress } from './decrypt'; -import { bigIntToBytes } from '../utils'; -import { getAddress } from 'ethers'; - -describe('decrypt', () => { - beforeAll(async () => { - await sodium.ready; - }); - - it('decrypts a hex value', async () => { - const keypair = sodium.crypto_box_keypair(); - - const value = BigInt(28482); - const ciphertext = sodium.crypto_box_seal( - bigIntToBytes(value), - keypair.publicKey, - 'hex', - ); - const cleartext = decrypt(keypair, ciphertext); - expect(cleartext.toString()).toBe(`${value}`); - }); - - it('decrypts a Uint8Array value', async () => { - const keypair = sodium.crypto_box_keypair(); - - const value = BigInt('10000939393388484938938389392929298383'); - const ciphertext = sodium.crypto_box_seal( - bigIntToBytes(value), - keypair.publicKey, - ); - const cleartext = decrypt(keypair, ciphertext); - expect(cleartext.toString()).toBe(value.toString()); - }); - - it('decrypts an address Uint8Array value', async () => { - const keypair = sodium.crypto_box_keypair(); - - const value = BigInt('0x8ba1f109551bd432803012645ac136ddd64dba72'); - const ciphertext = sodium.crypto_box_seal( - bigIntToBytes(value), - keypair.publicKey, - ); - const cleartext = decryptAddress(keypair, ciphertext); - expect(cleartext).toBe(getAddress(value.toString(16))); - }); - - it('decrypts an address Uint8Array value bigger than 160 bits', async () => { - const keypair = sodium.crypto_box_keypair(); - const address = '0x9b8a8ba1f109551bd432803012645ac136ddd64dba72'; - // Must truncate to 40-digit - const expected = '0x8ba1f109551bd432803012645ac136ddd64dba72'; - const value = BigInt(address); - const ciphertext = sodium.crypto_box_seal( - bigIntToBytes(value), - keypair.publicKey, - ); - const cleartext = decryptAddress(keypair, ciphertext); - expect(cleartext).toBe(getAddress(expected)); - }); - - it('decrypts an address Uint8Array value lower than 160 bits', async () => { - const keypair = sodium.crypto_box_keypair(); - const address = '0x8ba1f109551bd432803012645ac136ddd64d'; - // Must add padding until to 40-digit - const expected = '0x00008ba1f109551bd432803012645ac136ddd64d'; - const value = BigInt(address); - const ciphertext = sodium.crypto_box_seal( - bigIntToBytes(value), - keypair.publicKey, - ); - const cleartext = decryptAddress(keypair, ciphertext); - expect(cleartext).toBe(getAddress(expected)); - }); -}); diff --git a/src/sdk/decrypt.ts b/src/sdk/decrypt.ts deleted file mode 100644 index 46572c1..0000000 --- a/src/sdk/decrypt.ts +++ /dev/null @@ -1,41 +0,0 @@ -import sodium from 'libsodium-wrappers'; -import { bytesToBigInt, fromHexString, bytesToHex } from '../utils'; -import { ContractKeypair } from './types'; -import { getAddress } from 'ethers'; - -export const decrypt = ( - keypair: ContractKeypair, - ciphertext: string | Uint8Array, -): bigint => { - const toDecrypt = - typeof ciphertext === 'string' ? fromHexString(ciphertext) : ciphertext; - const decrypted = sodium.crypto_box_seal_open( - toDecrypt, - keypair.publicKey, - keypair.privateKey, - ); - return bytesToBigInt(decrypted); -}; - -export const decryptAddress = ( - keypair: ContractKeypair, - ciphertext: string | Uint8Array, -): string => { - const toDecrypt = - typeof ciphertext === 'string' ? fromHexString(ciphertext) : ciphertext; - const decrypted = sodium.crypto_box_seal_open( - toDecrypt, - keypair.publicKey, - keypair.privateKey, - ); - - let hexString = bytesToHex(decrypted); - // Ensure hexString forms a valid 40-digit Ethereum address. - // Truncate or pad with leading zeros as necessary to correct length issues. - if (hexString.length > 40) { - hexString = hexString.substring(hexString.length - 40); - } else { - hexString = hexString.slice(2).padStart(40, '0'); - } - return getAddress(hexString); -}; diff --git a/src/sdk/encrypt.test.ts b/src/sdk/encrypt.test.ts index 3abbeaa..eb71fee 100644 --- a/src/sdk/encrypt.test.ts +++ b/src/sdk/encrypt.test.ts @@ -1,29 +1,11 @@ import { - FheBool, - FheUint4, - FheUint8, - FheUint16, - FheUint32, - FheUint64, - CompactFheUint4List, - CompactFheUint8List, - CompactFheUint16List, - CompactFheUint32List, - CompactFheUint64List, + FheUint160, CompactFheUint160List, TfheCompactPublicKey, TfheClientKey, } from 'node-tfhe'; import { createTfheKeypair } from '../tfhe'; -import { - encryptBool, - encrypt4, - encrypt8, - encrypt16, - encrypt32, - encrypt64, - encryptAddress, -} from './encrypt'; +import { createEncryptedInput } from './encrypt'; describe('encrypt', () => { let clientKey: TfheClientKey; @@ -35,160 +17,139 @@ describe('encrypt', () => { publicKey = keypair.publicKey; }); - it('encrypt/decrypt 0 bool', async () => { - const buffer = encryptBool(false, publicKey); - const compactList = CompactFheUint4List.deserialize(buffer); - let encryptedList = compactList.expand(); - encryptedList.forEach((v: FheBool) => { - const decrypted = v.decrypt(clientKey); - expect(decrypted).toBe(0); - }); - }); - - it('encrypt/decrypt bool', async () => { - const buffer = encryptBool(true, publicKey); - const compactList = CompactFheUint4List.deserialize(buffer); - let encryptedList = compactList.expand(); - encryptedList.forEach((v: FheBool) => { - const decrypted = v.decrypt(clientKey); - expect(decrypted).toBe(1); - }); - }); - - it('encrypt/decrypt 0 4bits', async () => { - const buffer = encrypt4(0, publicKey); - const compactList = CompactFheUint4List.deserialize(buffer); - let encryptedList = compactList.expand(); - encryptedList.forEach((v: FheUint4) => { - const decrypted = v.decrypt(clientKey); - expect(decrypted).toBe(0); - }); - }); - - it('encrypt/decrypt 4bits', async () => { - const buffer = encrypt4(7, publicKey); - const compactList = CompactFheUint4List.deserialize(buffer); - let encryptedList = compactList.expand(); - encryptedList.forEach((v: FheUint4) => { - const decrypted = v.decrypt(clientKey); - expect(decrypted).toBe(7); - }); - }); - - it('encrypt/decrypt 0 8bits', async () => { - const buffer = encrypt8(0, publicKey); - const compactList = CompactFheUint8List.deserialize(buffer); - let encryptedList = compactList.expand(); - encryptedList.forEach((v: FheUint8) => { - const decrypted = v.decrypt(clientKey); - expect(decrypted).toBe(0); - }); - }); - - it('encrypt/decrypt 8bits', async () => { - const buffer = encrypt8(34, publicKey); - const compactList = CompactFheUint8List.deserialize(buffer); - let encryptedList = compactList.expand(); - encryptedList.forEach((v: FheUint8) => { - const decrypted = v.decrypt(clientKey); - expect(decrypted).toBe(34); - }); - }); - - it('encrypt/decrypt 0 16bits', async () => { - const buffer = encrypt16(0, publicKey); - const compactList = CompactFheUint8List.deserialize(buffer); - let encryptedList = compactList.expand(); - encryptedList.forEach((v: FheUint8) => { - const decrypted = v.decrypt(clientKey); - expect(decrypted).toBe(0); - }); - }); - - it('encrypt/decrypt 16bits', async () => { - const buffer = encrypt16(434, publicKey); - const compactList = CompactFheUint16List.deserialize(buffer); - let encryptedList = compactList.expand(); - encryptedList.forEach((v: FheUint16) => { - const decrypted = v.decrypt(clientKey); - expect(decrypted).toBe(434); - }); - }); - - it('encrypt/decrypt 0 32bits', async () => { - const buffer = encrypt32(0, publicKey); - const compactList = CompactFheUint8List.deserialize(buffer); - let encryptedList = compactList.expand(); - encryptedList.forEach((v: FheUint8) => { - const decrypted = v.decrypt(clientKey); - expect(decrypted).toBe(0); - }); - }); - - it('encrypt/decrypt 32bits', async () => { - const buffer = encrypt32(30210, publicKey); - const compactList = CompactFheUint32List.deserialize(buffer); - let encryptedList = compactList.expand(); - encryptedList.forEach((v: FheUint32) => { - const decrypted = v.decrypt(clientKey); - expect(decrypted).toBe(30210); - }); - }); - - it('encrypt/decrypt 0 64bits', async () => { - const buffer = encrypt64(0, publicKey); - const compactList = CompactFheUint64List.deserialize(buffer); - let encryptedList = compactList.expand(); - encryptedList.forEach((v: FheUint64) => { - const decrypted = v.decrypt(clientKey); - expect(decrypted.toString()).toBe('0'); - }); - }); - - it('encrypt/decrypt 64bits', async () => { - const buffer = encrypt64(3021094839202949, publicKey); - const compactList = CompactFheUint64List.deserialize(buffer); + it('encrypt/decrypt', async () => { + const input = createEncryptedInput(publicKey)( + '0x8ba1f109551bd432803012645ac136ddd64dba72', + '0xa5e1defb98EFe38EBb2D958CEe052410247F4c80', + ); + input.addBool(BigInt(0)); + input.add4(2); + input.add8(BigInt(43)); + input.add16(BigInt(87)); + input.add32(BigInt(2339389323)); + input.add64(BigInt(23393893233)); + input.add128(BigInt(233938932390)); + input.addAddress('0xa5e1defb98EFe38EBb2D958CEe052410247F4c80'); + const buffer = input.encrypt(); + const compactList = CompactFheUint160List.deserialize(buffer.data); let encryptedList = compactList.expand(); - encryptedList.forEach((v: FheUint64) => { + expect(encryptedList.length).toBe(8); + encryptedList.forEach((v: FheUint160, i: number) => { const decrypted = v.decrypt(clientKey); - expect(decrypted.toString()).toBe('3021094839202949'); + switch (i) { + case 0: + expect(decrypted.toString()).toBe('0'); + break; + case 1: + expect(decrypted.toString()).toBe('2'); + break; + case 2: + expect(decrypted.toString()).toBe('43'); + break; + case 3: + expect(decrypted.toString()).toBe('87'); + break; + case 3: + expect(decrypted.toString()).toBe('2339389323'); + break; + case 5: + expect(decrypted.toString()).toBe('23393893233'); + break; + case 6: + expect(decrypted.toString()).toBe('233938932390'); + break; + case 7: + expect(decrypted.toString()).toBe( + '947020569397242089359429103430823793539382463616', + ); + break; + } }); + input.resetValues(); + expect(input.getBits().length).toBe(0); + expect(input.getValues().length).toBe(0); }); - it('encrypt/decrypt bigint 64bits', async () => { - const buffer = encrypt64(BigInt('18446744073709551615'), publicKey); - const compactList = CompactFheUint64List.deserialize(buffer); - let encryptedList = compactList.expand(); - encryptedList.forEach((v: FheUint64) => { - const decrypted = v.decrypt(clientKey); - expect(decrypted.toString()).toBe('18446744073709551615'); - }); - }); - it('encrypt/decrypt 0x000... 160bits', async () => { - const buffer = encryptAddress( - '0x0000000000000000000000000000000000000000', - publicKey, + it('encrypt/decrypt one 0 value', async () => { + const input = createEncryptedInput(publicKey)( + '0x8ba1f109551bd432803012645ac136ddd64dba72', + '0xa5e1defb98EFe38EBb2D958CEe052410247F4c80', ); - const compactList = CompactFheUint160List.deserialize(buffer); + input.add128(BigInt(0)); + const buffer = input.encrypt(); + const compactList = CompactFheUint160List.deserialize(buffer.data); let encryptedList = compactList.expand(); - encryptedList.forEach((v: FheUint64) => { + expect(encryptedList.length).toBe(1); + encryptedList.forEach((v: FheUint160, i: number) => { const decrypted = v.decrypt(clientKey); - expect(decrypted.toString()).toBe('0'); + switch (i) { + case 0: + expect(decrypted.toString()).toBe('0'); + break; + } }); }); - it('encrypt/decrypt 160bits', async () => { - const buffer = encryptAddress( + it('throws errors', async () => { + expect(() => + createEncryptedInput()( + '0x8ba1f109551bd432803012645ac136ddd64dba72', + '0xa5e1defb98EFe38EBb2D958CEe052410247F4c80', + ), + ).toThrow( + 'Your instance has been created without the public blockchain key.', + ); + expect(() => + createEncryptedInput(publicKey)( + '0x8ba1f109551bd432803012645ac136ddd64dba', + '0xa5e1defb98EFe38EBb2D958CEe052410247F4c80', + ), + ).toThrow('Contract address is not a valid address.'); + + expect(() => + createEncryptedInput(publicKey)( + '0x8ba1f109551bd432803012645ac136ddd64dba72', + '0xa5e1defb98EFe38EBb2D958CEe052410247F4c', + ), + ).toThrow('User address is not a valid address.'); + + const input = createEncryptedInput(publicKey)( '0x8ba1f109551bd432803012645ac136ddd64dba72', - publicKey, + '0xa5e1defb98EFe38EBb2D958CEe052410247F4c80', ); - const compactList = CompactFheUint160List.deserialize(buffer); - let encryptedList = compactList.expand(); - encryptedList.forEach((v: FheUint64) => { - const decrypted = v.decrypt(clientKey); - expect(decrypted.toString()).toBe( - '797161134358056856230896843146392277790002887282', - ); - }); + expect(() => input.addBool('hello' as any)).toThrow( + 'The value must be a boolean, a number or a bigint.', + ); + expect(() => input.addBool({} as any)).toThrow( + 'The value must be a boolean, a number or a bigint.', + ); + expect(() => input.addBool(29393)).toThrow('The value must be 1 or 0.'); + expect(() => input.add4(29393)).toThrow( + 'The value exceeds the limit for 4bits integer (15)', + ); + expect(() => input.add8(2 ** 8)).toThrow( + 'The value exceeds the limit for 8bits integer (255)', + ); + expect(() => input.add16(2 ** 16)).toThrow( + `The value exceeds the limit for 16bits integer (65535).`, + ); + expect(() => input.add32(2 ** 32)).toThrow( + 'The value exceeds the limit for 32bits integer (4294967295).', + ); + expect(() => input.add64(BigInt('0xffffffffffffffff') + BigInt(1))).toThrow( + 'The value exceeds the limit for 64bits integer (18446744073709551615).', + ); + expect(() => + input.add128(BigInt('0xffffffffffffffffffffffffffffffff') + BigInt(1)), + ).toThrow( + 'The value exceeds the limit for 128bits integer (340282366920938463463374607431768211455).', + ); + + expect(() => input.addAddress('0x00')).toThrow( + 'The value must be a valid address.', + ); + + expect(input.getBits().length).toBe(0); + expect(input.getValues().length).toBe(0); }); }); diff --git a/src/sdk/encrypt.ts b/src/sdk/encrypt.ts index c78a214..3231e2c 100644 --- a/src/sdk/encrypt.ts +++ b/src/sdk/encrypt.ts @@ -1,94 +1,201 @@ -import { - TfheCompactPublicKey, - CompactFheBoolList, - CompactFheUint4List, - CompactFheUint8List, - CompactFheUint16List, - CompactFheUint32List, - CompactFheUint64List, - CompactFheUint160List, -} from 'node-tfhe'; -import { fromHexString } from '../utils'; +import { isAddress } from 'web3-validator'; +import createKeccakHash from 'keccak'; +import { TfheCompactPublicKey, CompactFheUint160List } from 'node-tfhe'; -export const encrypt4 = ( - value: number, - publicKey: TfheCompactPublicKey, -): Uint8Array => { - const uint8Array = new Uint8Array([value]); - const encrypted = CompactFheUint4List.encrypt_with_compact_public_key( - uint8Array, - publicKey, - ); - return encrypted.serialize(); -}; +import { toHexString } from '../utils'; +import { ENCRYPTION_TYPES } from './encryptionTypes'; +import { fetchJSONRPC } from '../ethCall'; -export const encryptBool = ( - value: boolean, - publicKey: TfheCompactPublicKey, -): Uint8Array => { - const encrypted = CompactFheBoolList.encrypt_with_compact_public_key( - [value], - publicKey, - ); - return encrypted.serialize(); -}; +// const publicZkParams = CompactPkePublicParams.deserialize(crsBuffer); -export const encrypt8 = ( - value: number, - publicKey: TfheCompactPublicKey, -): Uint8Array => { - const uint8Array = new Uint8Array([value]); - const encrypted = CompactFheUint8List.encrypt_with_compact_public_key( - uint8Array, - publicKey, - ); - return encrypted.serialize(); +export type ZKInput = { + addBool: (value: boolean) => ZKInput; + add4: (value: number | bigint) => ZKInput; + add8: (value: number | bigint) => ZKInput; + add16: (value: number | bigint) => ZKInput; + add32: (value: number | bigint) => ZKInput; + add64: (value: number | bigint) => ZKInput; + add128: (value: number | bigint) => ZKInput; + addAddress: (value: string) => ZKInput; + getValues: () => bigint[]; + getBits: () => number[]; + resetValues: () => ZKInput; + encrypt: () => { + inputs: Uint8Array[]; + data: Uint8Array; + }; + send: () => Promise<{ inputs: string[]; signature: string }>; }; -export const encrypt16 = ( - value: number, - publicKey: TfheCompactPublicKey, -): Uint8Array => { - const uint16Array = new Uint16Array([value]); - const encrypted = CompactFheUint16List.encrypt_with_compact_public_key( - uint16Array, - publicKey, - ); - return encrypted.serialize(); +const checkEncryptedValue = (value: number | bigint, bits: number) => { + if (value == null) throw new Error('Missing value'); + const limit = BigInt(Math.pow(2, bits)); + if (typeof value !== 'number' && typeof value !== 'bigint') + throw new Error('Value must be a number or a bigint.'); + if (value >= limit) { + throw new Error( + `The value exceeds the limit for ${bits}bits integer (${( + limit - BigInt(1) + ).toString()}).`, + ); + } }; -export const encrypt32 = ( - value: number, - publicKey: TfheCompactPublicKey, -): Uint8Array => { - const uint32Array = new Uint32Array([value]); - const encrypted = CompactFheUint32List.encrypt_with_compact_public_key( - uint32Array, - publicKey, - ); - return encrypted.serialize(); -}; +export const createEncryptedInput = + (tfheCompactPublicKey?: TfheCompactPublicKey, coprocessorUrl?: string) => + (contractAddress: string, callerAddress: string) => { + if (!tfheCompactPublicKey) + throw new Error( + 'Your instance has been created without the public blockchain key.', + ); -export const encrypt64 = ( - value: number | bigint, - publicKey: TfheCompactPublicKey, -): Uint8Array => { - const uint64Array = new BigUint64Array([BigInt(value)]); - const encrypted = CompactFheUint64List.encrypt_with_compact_public_key( - uint64Array, - publicKey, - ); - return encrypted.serialize(); -}; + if (!isAddress(contractAddress)) { + throw new Error('Contract address is not a valid address.'); + } -export const encryptAddress = ( - value: string, - publicKey: TfheCompactPublicKey, -): Uint8Array => { - // value is something like 0x8ba1f109551bd432803012645ac136ddd64dba72 - const encrypted = CompactFheUint160List.encrypt_with_compact_public_key( - [BigInt(value)], - publicKey, - ); - return encrypted.serialize(); -}; + if (!isAddress(callerAddress)) { + throw new Error('User address is not a valid address.'); + } + + const publicKey: TfheCompactPublicKey = tfheCompactPublicKey; + const values: bigint[] = []; + const bits: number[] = []; + return { + addBool(value: boolean | number | bigint) { + if (value == null) throw new Error('Missing value'); + if ( + typeof value !== 'boolean' && + typeof value !== 'number' && + typeof value !== 'bigint' + ) + throw new Error('The value must be a boolean, a number or a bigint.'); + if ( + (typeof value !== 'bigint' || typeof value !== 'number') && + Number(value) > 1 + ) + throw new Error('The value must be 1 or 0.'); + values.push(BigInt(value)); + bits.push(ENCRYPTION_TYPES[1]); + return this; + }, + add4(value: number | bigint) { + checkEncryptedValue(value, 4); + values.push(BigInt(value)); + bits.push(ENCRYPTION_TYPES[4]); + return this; + }, + add8(value: number | bigint) { + checkEncryptedValue(value, 8); + values.push(BigInt(value)); + bits.push(ENCRYPTION_TYPES[8]); + return this; + }, + add16(value: number | bigint) { + checkEncryptedValue(value, 16); + values.push(BigInt(value)); + bits.push(ENCRYPTION_TYPES[16]); + return this; + }, + add32(value: number | bigint) { + checkEncryptedValue(value, 32); + values.push(BigInt(value)); + bits.push(ENCRYPTION_TYPES[32]); + return this; + }, + add64(value: number | bigint) { + checkEncryptedValue(value, 64); + values.push(BigInt(value)); + bits.push(ENCRYPTION_TYPES[64]); + return this; + }, + add128(value: number | bigint) { + checkEncryptedValue(value, 128); + values.push(BigInt(value)); + bits.push(ENCRYPTION_TYPES[128]); + return this; + }, + addAddress(value: string) { + if (!isAddress(value)) { + throw new Error('The value must be a valid address.'); + } + values.push(BigInt(value)); + bits.push(ENCRYPTION_TYPES[160]); + return this; + }, + getValues() { + return values; + }, + getBits() { + return bits; + }, + resetValues() { + values.length = 0; + bits.length = 0; + return this; + }, + encrypt() { + const encrypted = CompactFheUint160List.encrypt_with_compact_public_key( + values, + publicKey, + ); + const data = encrypted.serialize(); + const hash = createKeccakHash('keccak256') + .update(Buffer.from(data)) + .digest(); + // const encrypted = ProvenCompactFheUint160List.encrypt_with_compact_public_key( + // values, + // publicZkParams, + // publicKey, + // ZkComputeLoad.Proof, + // ); + const inputs = bits.map((v, i) => { + const dataWithIndex = new Uint8Array(hash.length + 1); + dataWithIndex.set(hash, 0); + dataWithIndex.set([i], hash.length); + const finalHash = createKeccakHash('keccak256') + .update(Buffer.from(dataWithIndex)) + .digest(); + const dataInput = new Uint8Array(32); + dataInput.set(finalHash, 0); + dataInput.set([i, bits[v], 0], 29); + return dataInput; + }); + return { + inputs, + data, + }; + }, + async send() { + if (!coprocessorUrl) throw new Error('Coprocessor URL not provided'); + const encrypted = CompactFheUint160List.encrypt_with_compact_public_key( + values, + publicKey, + ); + const ciphertext = encrypted.serialize(); + + const data = new Uint8Array(1 + bits.length + ciphertext.length); + data.set([data.length], 0); + data.set(bits, 1); + data.set(ciphertext, data.length + 1); + + const payload = { + jsonrpc: '2.0', + method: 'eth_addUserCiphertext', + params: [toHexString(data), contractAddress, callerAddress], + id: 1, + }; + + // Set up the fetch request options + const options = { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(payload), + }; + const response = await fetchJSONRPC(coprocessorUrl, options); + if (!response) throw new Error('Invalid input'); + return JSON.parse(response); + }, + }; + }; diff --git a/src/sdk/encryptionTypes.ts b/src/sdk/encryptionTypes.ts new file mode 100644 index 0000000..f117dd1 --- /dev/null +++ b/src/sdk/encryptionTypes.ts @@ -0,0 +1,14 @@ +export const ENCRYPTION_TYPES = { + 1: 0, + 4: 1, + 8: 2, + 16: 3, + 32: 4, + 64: 5, + 128: 6, + 160: 7, + 256: 8, + 512: 9, + 1024: 10, + 2048: 11, +}; diff --git a/src/sdk/index.test.ts b/src/sdk/index.test.ts index 93ecb3e..ca811c8 100644 --- a/src/sdk/index.test.ts +++ b/src/sdk/index.test.ts @@ -1,7 +1,7 @@ import sodium from 'libsodium-wrappers'; import { createInstance } from './index'; import { createTfhePublicKey } from '../tfhe'; -import { fromHexString, toHexString, bigIntToBytes } from '../utils'; +import { fromHexString, bigIntToBytes } from '../utils'; describe('index', () => { let tfhePublicKey: string; @@ -16,46 +16,20 @@ describe('index', () => { chainId: 1234, publicKey: tfhePublicKey, }); - expect(instance.encryptBool).toBeDefined(); - expect(instance.encrypt4).toBeDefined(); - expect(instance.encrypt8).toBeDefined(); - expect(instance.encrypt16).toBeDefined(); - expect(instance.encrypt32).toBeDefined(); - expect(instance.generatePublicKey).toBeDefined(); - expect(instance.decrypt).toBeDefined(); - expect(instance.decryptAddress).toBeDefined(); - expect(instance.serializeKeypairs).toBeDefined(); - expect(instance.getPublicKey).toBeDefined(); - expect(instance.hasKeypair).toBeDefined(); + expect(instance.reencrypt).toBeDefined(); + expect(instance.createEIP712).toBeDefined(); + expect(instance.generateKeypair).toBeDefined(); + expect(instance.createEncryptedInput).toBeDefined(); }); it('creates an instance for mock', async () => { const instance = await createInstance({ chainId: 1234, }); - expect(instance.encrypt8).toBeDefined(); - expect(instance.encrypt16).toBeDefined(); - expect(instance.encrypt32).toBeDefined(); - expect(instance.encrypt64).toBeDefined(); - expect(instance.generatePublicKey).toBeDefined(); - expect(instance.decrypt).toBeDefined(); - expect(instance.decryptAddress).toBeDefined(); - expect(instance.serializeKeypairs).toBeDefined(); - expect(instance.getPublicKey).toBeDefined(); - expect(instance.hasKeypair).toBeDefined(); - - expect(() => instance.encrypt8(2)).toThrow( - 'Your instance has been created without the public blockchain key', - ); - expect(() => instance.encrypt16(2)).toThrow( - 'Your instance has been created without the public blockchain key', - ); - expect(() => instance.encrypt32(2)).toThrow( - 'Your instance has been created without the public blockchain key', - ); - expect(() => instance.encrypt64(2)).toThrow( - 'Your instance has been created without the public blockchain key', - ); + expect(instance.reencrypt).toBeDefined(); + expect(instance.createEIP712).toBeDefined(); + expect(instance.generateKeypair).toBeDefined(); + expect(instance.createEncryptedInput).toBeDefined(); }); it('fails to create an instance', async () => { @@ -70,312 +44,4 @@ describe('index', () => { createInstance({ chainId: 9000, publicKey: 43 as any }), ).rejects.toThrow('publicKey must be a string'); }); - - it('creates an instance with keypairs', async () => { - const keypair = sodium.crypto_box_keypair('hex'); - - const contractAddress = '0x1c786b8ca49D932AFaDCEc00827352B503edf16c'; - - const instance = await createInstance({ - chainId: 1234, - publicKey: tfhePublicKey, - keypairs: { - [contractAddress]: { - privateKey: keypair.privateKey, - publicKey: keypair.publicKey, - signature: null, - }, - }, - }); - - const value = BigInt(937387); - const ciphertext = sodium.crypto_box_seal( - bigIntToBytes(value), - fromHexString(keypair.publicKey), - 'hex', - ); - - const cleartext = instance.decrypt(contractAddress, ciphertext); - expect(cleartext.toString()).toBe(value.toString()); - - const address = BigInt('0xD115BFFAbbdd893A6f7ceA402e7338643Ced44a6'); - const ciphertextAddress = sodium.crypto_box_seal( - bigIntToBytes(address), - fromHexString(keypair.publicKey), - 'hex', - ); - - const cleartextAddress = instance.decryptAddress( - contractAddress, - ciphertextAddress, - ); - expect(cleartextAddress).toBe('0xD115BFFAbbdd893A6f7ceA402e7338643Ced44a6'); - }); - - it('controls decrypt', async () => { - const instance = await createInstance({ - chainId: 1234, - publicKey: tfhePublicKey, - }); - - const keypair = instance.generatePublicKey({ - verifyingContract: '0xD115BFFAbbdd893A6f7ceA402e7338643Ced44a6', - }); - - const value = BigInt(937387); - const ciphertext = sodium.crypto_box_seal( - bigIntToBytes(value), - keypair.publicKey, - 'hex', - ); - - const address = BigInt('0xD115BFFAbbdd893A6f7ceA402e7338643Ced44a6'); - const ciphertextAddress = sodium.crypto_box_seal( - bigIntToBytes(address), - keypair.publicKey, - 'hex', - ); - - expect(() => instance.decrypt(undefined as any, ciphertext)).toThrow( - 'Missing contract address.', - ); - - expect(() => - instance.decryptAddress(undefined as any, ciphertextAddress), - ).toThrow('Missing contract address.'); - - expect(() => - instance.decrypt( - '0xD115BFFAbbdd893A6f7ceA402e7338643Ced44a6', - undefined as any, - ), - ).toThrow('Missing ciphertext.'); - - expect(() => - instance.decryptAddress( - '0xD115BFFAbbdd893A6f7ceA402e7338643Ced44a6', - undefined as any, - ), - ).toThrow('Missing ciphertext.'); - - expect(() => - instance.decrypt( - '0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', - ciphertext, - ), - ).toThrow( - 'Missing keypair for 0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.', - ); - - expect(() => - instance.decryptAddress( - '0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb', - ciphertextAddress, - ), - ).toThrow( - 'Missing keypair for 0xbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb.', - ); - }); - - it('controls encrypt', async () => { - const instance = await createInstance({ - chainId: 1234, - publicKey: tfhePublicKey, - }); - expect(instance.encryptBool(true)).toBeTruthy(); - - expect(instance.encryptBool(1)).toBeTruthy(); - expect(instance.encrypt4(2)).toBeTruthy(); - expect(instance.encrypt8(34)).toBeTruthy(); - expect(instance.encrypt16(344)).toBeTruthy(); - expect(instance.encrypt32(3422)).toBeTruthy(); - expect(instance.encrypt64(34)).toBeTruthy(); - - expect(instance.encryptBool(BigInt(0))).toBeTruthy(); - expect(instance.encrypt4(BigInt(2))).toBeTruthy(); - expect(instance.encrypt8(BigInt(233))).toBeTruthy(); - expect(instance.encrypt16(BigInt(3342))).toBeTruthy(); - expect(instance.encrypt32(BigInt(838392))).toBeTruthy(); - expect(instance.encrypt64(BigInt(3433434343))).toBeTruthy(); - - expect( - instance.encryptAddress('0x8ba1f109551bd432803012645ac136ddd64dba72'), - ).toBeTruthy(); - - expect(() => instance.encryptBool(undefined as any)).toThrow( - 'Missing value', - ); - expect(() => instance.encrypt4(undefined as any)).toThrow('Missing value'); - expect(() => instance.encrypt8(undefined as any)).toThrow('Missing value'); - expect(() => instance.encrypt16(undefined as any)).toThrow('Missing value'); - expect(() => instance.encrypt32(undefined as any)).toThrow('Missing value'); - expect(() => instance.encrypt64(undefined as any)).toThrow('Missing value'); - - expect(() => instance.encryptBool('wrong value' as any)).toThrow( - 'Value must be a boolean', - ); - expect(() => instance.encrypt4('wrong value' as any)).toThrow( - 'Value must be a number or a bigint.', - ); - expect(() => instance.encrypt8('wrong value' as any)).toThrow( - 'Value must be a number or a bigint.', - ); - expect(() => instance.encrypt16('wrong value' as any)).toThrow( - 'Value must be a number or a bigint.', - ); - expect(() => instance.encrypt32('wrong value' as any)).toThrow( - 'Value must be a number or a bigint.', - ); - expect(() => instance.encrypt64('wrong value' as any)).toThrow( - 'Value must be a number or a bigint.', - ); - expect(() => instance.encryptAddress('wrong value' as any)).toThrow( - 'Value must be a valid address.', - ); - expect(() => instance.encryptAddress(BigInt(32) as any)).toThrow( - 'Value must be a string.', - ); - - // Check limit - expect(instance.encryptBool(1)).toBeTruthy(); - expect(() => instance.encryptBool(34)).toThrow('Value must be 1 or 0.'); - expect(() => instance.encryptBool(BigInt(34))).toThrow( - 'Value must be 1 or 0.', - ); - - expect(instance.encrypt4(Math.pow(2, 4) - 1)).toBeTruthy(); - expect(() => instance.encrypt4(BigInt(34))).toThrow( - 'The value exceeds the limit for 4bits integer (15).', - ); - - expect(instance.encrypt8(Math.pow(2, 8) - 1)).toBeTruthy(); - expect(() => instance.encrypt8(BigInt(256))).toThrow( - 'The value exceeds the limit for 8bits integer (255).', - ); - - expect(instance.encrypt16(Math.pow(2, 16) - 1)).toBeTruthy(); - expect(() => instance.encrypt16(BigInt(70000))).toThrow( - 'The value exceeds the limit for 16bits integer (65535).', - ); - - expect(instance.encrypt32(Math.pow(2, 32) - 1)).toBeTruthy(); - expect(() => instance.encrypt32(BigInt(Math.pow(2, 32)) as any)).toThrow( - 'The value exceeds the limit for 32bits integer (4294967295).', - ); - - expect( - instance.encrypt64(BigInt(Math.pow(2, 64)) - BigInt(1)), - ).toBeTruthy(); - expect(() => instance.encrypt64(BigInt(Math.pow(2, 64)) as any)).toThrow( - 'The value exceeds the limit for 64bits integer (18446744073709551615).', - ); - }); - - it('controls generatePublicKey', async () => { - const instance = await createInstance({ - chainId: 1234, - publicKey: tfhePublicKey, - }); - expect(() => instance.generatePublicKey(undefined as any)).toThrow( - 'Missing contract address', - ); - expect(() => instance.generatePublicKey({ verifyingContract: '' })).toThrow( - 'Missing contract address', - ); - expect(() => - instance.generatePublicKey({ verifyingContract: '0x847473829d' }), - ).toThrow('Invalid contract address'); - }); - - it('save generated public key', async () => { - const instance = await createInstance({ - chainId: 1234, - publicKey: tfhePublicKey, - }); - - const contractAddress = '0x1c786b8ca49D932AFaDCEc00827352B503edf16c'; - - const { eip712, publicKey } = instance.generatePublicKey({ - verifyingContract: contractAddress, - }); - - instance.setSignature(contractAddress, 'signnnn'); - - expect(instance.hasKeypair(contractAddress)).toBeTruthy(); - - const kp = instance.getPublicKey(contractAddress); - expect(kp!.publicKey).toBe(publicKey); - }); - - it("don't export keys without signature", async () => { - const instance = await createInstance({ - chainId: 1234, - publicKey: tfhePublicKey, - }); - - const contractAddress = '0x1c786b8ca49D932AFaDCEc00827352B503edf16c'; - - const { eip712, publicKey } = instance.generatePublicKey({ - verifyingContract: contractAddress, - }); - const keypairs = instance.serializeKeypairs(); - expect(keypairs[contractAddress]).toBeUndefined(); - const keypair = instance.getPublicKey(contractAddress); - expect(keypair).toBeNull(); - expect(instance.hasKeypair(contractAddress)).toBeFalsy(); - }); - - it('decrypts data', async () => { - const instance = await createInstance({ - chainId: 1234, - publicKey: tfhePublicKey, - }); - - const contractAddress = '0x1c786b8ca49D932AFaDCEc00827352B503edf16c'; - - const { eip712, publicKey } = instance.generatePublicKey({ - verifyingContract: contractAddress, - }); - - instance.setSignature(contractAddress, 'signnnn'); - - const kp = instance.getPublicKey(contractAddress); - expect(kp!.publicKey).toBe(publicKey); - - const value = BigInt(89290); - const ciphertext = sodium.crypto_box_seal( - bigIntToBytes(value), - publicKey, - 'hex', - ); - const cleartext = instance.decrypt(contractAddress, ciphertext); - expect(cleartext.toString()).toBe(value.toString()); - }); - - it('decrypts address', async () => { - const instance = await createInstance({ - chainId: 1234, - publicKey: tfhePublicKey, - }); - - const contractAddress = '0x1c786b8ca49D932AFaDCEc00827352B503edf16c'; - - const { eip712, publicKey } = instance.generatePublicKey({ - verifyingContract: contractAddress, - }); - - instance.setSignature(contractAddress, 'signnnn'); - - const kp = instance.getPublicKey(contractAddress); - expect(kp!.publicKey).toBe(publicKey); - - const value = BigInt('0x1c786b8ca49D932AFaDCEc00827352B503edf16c'); - const ciphertext = sodium.crypto_box_seal( - bigIntToBytes(value), - publicKey, - 'hex', - ); - const cleartext = instance.decryptAddress(contractAddress, ciphertext); - expect(cleartext).toBe('0x1c786b8ca49D932AFaDCEc00827352B503edf16c'); - }); }); diff --git a/src/sdk/index.ts b/src/sdk/index.ts index a992a84..b97bcfd 100644 --- a/src/sdk/index.ts +++ b/src/sdk/index.ts @@ -1,286 +1,90 @@ -import { TfheCompactPublicKey } from 'node-tfhe'; import sodium from 'libsodium-wrappers'; -import { - encrypt4, - encrypt8, - encrypt16, - encrypt32, - encrypt64, - encryptAddress, - encryptBool, -} from './encrypt'; -import { - EIP712, - GeneratePublicKeyParams, - generatePublicKey, -} from './publicKey'; -import { decrypt, decryptAddress } from './decrypt'; -import { fromHexString, isAddress, toHexString } from '../utils'; -import { ContractKeypairs } from './types'; +import { TfheCompactPublicKey } from 'node-tfhe'; -export type FhevmInstance = { - encryptBool: (value: boolean | number | bigint) => Uint8Array; - encrypt4: (value: number | bigint) => Uint8Array; - encrypt8: (value: number | bigint) => Uint8Array; - encrypt16: (value: number | bigint) => Uint8Array; - encrypt32: (value: number | bigint) => Uint8Array; - encrypt64: (value: number | bigint) => Uint8Array; - encryptAddress: (value: string) => Uint8Array; - generatePublicKey: ( - options: GeneratePublicKeyParams & { - force?: boolean; - }, - ) => { - publicKey: Uint8Array; - eip712: EIP712; - }; - setSignature: (contractAddress: string, signature: string) => void; - getPublicKey: ( - contractAddress: string, - ) => { publicKey: Uint8Array; signature: string } | null; - hasKeypair: (contractAddress: string) => boolean; - decrypt: (contractAddress: string, ciphertext: string) => bigint; - decryptAddress: (contractAddress: string, ciphertext: string) => string; - serializeKeypairs: () => ExportedContractKeypairs; -}; +import { fromHexString } from '../utils'; +import { ZKInput } from './encrypt'; +import { + getPublicKeyFromNetwork, + getPublicKeyFromCoprocessor, + getChainIdFromNetwork, +} from './network'; +import { createEncryptedInput } from './encrypt'; +import { generateKeypair, createEIP712, EIP712 } from './keypair'; +import { reencryptRequest } from './reencrypt'; -export type TokenSignature = { - publicKey: Uint8Array; - signature: string; -}; +export { getPublicKeyCallParams } from './network'; -export type ExportedContractKeypairs = { - [key: string]: { - publicKey: string; - privateKey: string; - signature?: string | null; - }; -}; - -export type FhevmInstanceParams = { +type FhevmInstanceConfig = { chainId: number; publicKey?: string; - keypairs?: ExportedContractKeypairs; + reencryptionUrl?: string; + networkUrl?: string; + coprocessorUrl?: string; }; -export const getPublicKeyCallParams = () => ({ - to: '0x000000000000000000000000000000000000005d', - data: '0xd9d47bb001', -}); - -export const getCiphertextCallParams = (handle: bigint) => { - let hex = handle.toString(16); - hex = hex.padStart(64, '0'); - return { - to: '0x000000000000000000000000000000000000005d', - data: '0xff627e77' + hex, - }; +export type FhevmInstance = { + createEncryptedInput: ( + contractAddress: string, + userAddress: string, + ) => ZKInput; + generateKeypair: () => { publicKey: string; privateKey: string }; + createEIP712: ( + publicKey: string, + contractAddress: string, + userAddress?: string, + ) => EIP712; + reencrypt: ( + handle: bigint, + privateKey: string, + publicKey: string, + signature: string, + contractAddress: string, + userAddress: string, + ) => Promise; }; export const createInstance = async ( - params: FhevmInstanceParams, + config: FhevmInstanceConfig, ): Promise => { await sodium.ready; - const { chainId, publicKey, keypairs } = params; - if (typeof chainId !== 'number') throw new Error('chainId must be a number'); - if (publicKey && typeof publicKey !== 'string') - throw new Error('publicKey must be a string'); - let tfheCompactPublicKey: TfheCompactPublicKey; - if (publicKey) { - const buff = fromHexString(publicKey); - tfheCompactPublicKey = TfheCompactPublicKey.deserialize(buff); - } - - let contractKeypairs: ContractKeypairs = {}; - - if (keypairs) { - Object.keys(keypairs).forEach((contractAddress) => { - if (isAddress(contractAddress)) { - const oKeys = Object.keys(keypairs[contractAddress]); - if ( - ['signature', 'privateKey', 'publicKey'].every((v) => - oKeys.includes(v), - ) - ) { - contractKeypairs[contractAddress] = { - signature: keypairs[contractAddress].signature, - publicKey: fromHexString(keypairs[contractAddress].publicKey), - privateKey: fromHexString(keypairs[contractAddress].privateKey), - }; - } - } - }); - } - - const hasKeypair = (contractAddress: string) => { - return ( - contractKeypairs[contractAddress] != null && - !!contractKeypairs[contractAddress].signature - ); - }; - - const checkEncryptedValue = (value: number | bigint, bits: number) => { - if (value == null) throw new Error('Missing value'); - const limit = BigInt(Math.pow(2, bits)); - if (typeof value !== 'number' && typeof value !== 'bigint') - throw new Error('Value must be a number or a bigint.'); - if (value >= limit) { - throw new Error( - `The value exceeds the limit for ${bits}bits integer (${( - limit - BigInt(1) - ).toString()}).`, - ); - } - }; - - return { - // Parameters - encryptBool(value) { - if (!tfheCompactPublicKey) - throw new Error( - 'Your instance has been created without the public blockchain key.', - ); - if (value == null) throw new Error('Missing value'); - if ( - typeof value !== 'boolean' && - typeof value !== 'number' && - typeof value !== 'bigint' - ) - throw new Error('Value must be a boolean, a number or a bigint.'); - if ( - (typeof value !== 'bigint' || typeof value !== 'number') && - Number(value) > 1 - ) - throw new Error('Value must be 1 or 0.'); - return encryptBool(Boolean(value), tfheCompactPublicKey); - }, - encrypt4(value) { - if (!tfheCompactPublicKey) - throw new Error( - 'Your instance has been created without the public blockchain key.', - ); - checkEncryptedValue(value, 4); - return encrypt4(Number(value), tfheCompactPublicKey); - }, - encrypt8(value) { - if (!tfheCompactPublicKey) - throw new Error( - 'Your instance has been created without the public blockchain key.', - ); - checkEncryptedValue(value, 8); - return encrypt8(Number(value), tfheCompactPublicKey); - }, - encrypt16(value) { - if (!tfheCompactPublicKey) - throw new Error( - 'Your instance has been created without the public blockchain key.', - ); - checkEncryptedValue(value, 16); - return encrypt16(Number(value), tfheCompactPublicKey); - }, - encrypt32(value) { - if (!tfheCompactPublicKey) - throw new Error( - 'Your instance has been created without the public blockchain key.', - ); - checkEncryptedValue(value, 32); - return encrypt32(Number(value), tfheCompactPublicKey); - }, + const { networkUrl, reencryptionUrl, coprocessorUrl } = config; - encrypt64(value) { - if (!tfheCompactPublicKey) - throw new Error( - 'Your instance has been created without the public blockchain key.', - ); - checkEncryptedValue(value, 64); - return encrypt64(value, tfheCompactPublicKey); - }, + let chainId: number | undefined = config.chainId; + let publicKey: string | undefined = config.publicKey; + let tfheCompactPublicKey: TfheCompactPublicKey | undefined; - encryptAddress(value) { - if (!tfheCompactPublicKey) - throw new Error( - 'Your instance has been created without the public blockchain key.', - ); - if (typeof value !== 'string') throw new Error('Value must be a string.'); - if (!isAddress(value)) throw new Error('Value must be a valid address.'); - return encryptAddress(value, tfheCompactPublicKey); - }, + if (typeof chainId !== 'number') throw new Error('chainId must be a number.'); - // Reencryption - generatePublicKey(options) { - if (!options || !options.verifyingContract) - throw new Error('Missing contract address'); - if (!isAddress(options.verifyingContract)) - throw new Error('Invalid contract address'); - let kp; - if (!options.force && contractKeypairs[options.verifyingContract]) { - kp = contractKeypairs[options.verifyingContract]; - } - const { eip712, keypair } = generatePublicKey({ - verifyingContract: options.verifyingContract, - name: options.name, - version: options.version, - chainId, - keypair: kp, - }); - contractKeypairs[options.verifyingContract] = { - privateKey: keypair.privateKey, - publicKey: keypair.publicKey, - signature: null, - }; - return { eip712, publicKey: keypair.publicKey }; - }, - - setSignature(contractAddress: string, signature: string) { - if ( - contractKeypairs[contractAddress] && - contractKeypairs[contractAddress].privateKey - ) { - contractKeypairs[contractAddress].signature = signature; - } - }, - - getPublicKey(contractAddress: string): TokenSignature | null { - if (hasKeypair(contractAddress)) { - return { - publicKey: contractKeypairs[contractAddress].publicKey, - signature: contractKeypairs[contractAddress].signature!, - }; - } - return null; - }, + if (coprocessorUrl && !publicKey) { + publicKey = await getPublicKeyFromCoprocessor(coprocessorUrl); + } else if (networkUrl && !publicKey) { + publicKey = await getPublicKeyFromNetwork(networkUrl); + } - hasKeypair, + if (networkUrl && !chainId) { + chainId = await getChainIdFromNetwork(networkUrl); + } - decrypt(contractAddress, ciphertext) { - if (!ciphertext) throw new Error('Missing ciphertext.'); - if (!contractAddress) throw new Error('Missing contract address.'); - const kp = contractKeypairs[contractAddress]; - if (!kp) throw new Error(`Missing keypair for ${contractAddress}.`); - return decrypt(kp, ciphertext); - }, + if (publicKey && typeof publicKey !== 'string') + throw new Error('publicKey must be a string'); - decryptAddress(contractAddress, ciphertext) { - if (!ciphertext) throw new Error('Missing ciphertext.'); - if (!contractAddress) throw new Error('Missing contract address.'); - const kp = contractKeypairs[contractAddress]; - if (!kp) throw new Error(`Missing keypair for ${contractAddress}.`); - return decryptAddress(kp, ciphertext); - }, + if (publicKey) { + const buff = fromHexString(publicKey); + try { + tfheCompactPublicKey = TfheCompactPublicKey.deserialize(buff); + } catch (e) { + throw new Error('Invalid public key (deserialization failed)'); + } + } - serializeKeypairs() { - const stringKeypairs: ExportedContractKeypairs = {}; - Object.keys(contractKeypairs).forEach((contractAddress) => { - const signature = contractKeypairs[contractAddress].signature; - if (!signature) return; - stringKeypairs[contractAddress] = { - signature, - publicKey: toHexString(contractKeypairs[contractAddress].publicKey), - privateKey: toHexString(contractKeypairs[contractAddress].privateKey), - }; - }); - return stringKeypairs; - }, + return { + createEncryptedInput: createEncryptedInput( + tfheCompactPublicKey, + coprocessorUrl, + ), + generateKeypair, + createEIP712: createEIP712(chainId), + reencrypt: reencryptRequest(reencryptionUrl), }; }; diff --git a/src/sdk/keypair.test.ts b/src/sdk/keypair.test.ts new file mode 100644 index 0000000..46d7a1b --- /dev/null +++ b/src/sdk/keypair.test.ts @@ -0,0 +1,92 @@ +import sodium from 'libsodium-wrappers'; +import { fromHexString } from '../utils'; +import { generateKeypair, createEIP712 } from './keypair'; +import { + cryptobox_pk_to_u8vec, + cryptobox_sk_to_u8vec, + u8vec_to_cryptobox_pk, + u8vec_to_cryptobox_sk, +} from '../kms/node/kms_lib'; + +describe('token', () => { + beforeAll(async () => { + await sodium.ready; + }); + + it('generate a valid keypair', async () => { + const keypair = generateKeypair(); + + expect(keypair.publicKey.length).toBe(68); + expect(keypair.privateKey.length).toBe(68); + + let pkBuf = cryptobox_pk_to_u8vec( + u8vec_to_cryptobox_pk(fromHexString(keypair.publicKey)), + ); + expect(34).toBe(pkBuf.length); + + let skBuf = cryptobox_sk_to_u8vec( + u8vec_to_cryptobox_sk(fromHexString(keypair.privateKey)), + ); + expect(34).toBe(skBuf.length); + }); + + it('create a valid EIP712', async () => { + const keypair = generateKeypair(); + + const eip712 = createEIP712(1234)( + keypair.publicKey, + '0x8ba1f109551bd432803012645ac136ddd64dba72', + ); + + expect(eip712.domain.chainId).toBe(1234); + expect(eip712.domain.name).toBe('Authorization token'); + expect(eip712.domain.version).toBe('1'); + expect(eip712.message.publicKey).toBe(`0x${keypair.publicKey}`); + expect(eip712.primaryType).toBe('Reencrypt'); + expect(eip712.types.Reencrypt.length).toBe(1); + expect(eip712.types.Reencrypt[0].name).toBe('publicKey'); + expect(eip712.types.Reencrypt[0].type).toBe('bytes32'); + }); + + it('create a valid EIP712 with delegated accunt', async () => { + const keypair = generateKeypair(); + + const eip712 = createEIP712(1234)( + keypair.publicKey, + '0x8ba1f109551bd432803012645ac136ddd64dba72', + '0xa5e1defb98EFe38EBb2D958CEe052410247F4c80', + ); + + expect(eip712.domain.chainId).toBe(1234); + expect(eip712.domain.name).toBe('Authorization token'); + expect(eip712.domain.version).toBe('1'); + expect(eip712.message.publicKey).toBe(`0x${keypair.publicKey}`); + expect(eip712.message.delegatedAccount).toBe( + '0xa5e1defb98EFe38EBb2D958CEe052410247F4c80', + ); + expect(eip712.primaryType).toBe('Reencrypt'); + expect(eip712.types.Reencrypt.length).toBe(2); + expect(eip712.types.Reencrypt[0].name).toBe('publicKey'); + expect(eip712.types.Reencrypt[0].type).toBe('bytes32'); + expect(eip712.types.Reencrypt[1].name).toBe('delegatedAccount'); + expect(eip712.types.Reencrypt[1].type).toBe('address'); + }); + + it('create invalid EIP712', async () => { + const keypair = generateKeypair(); + + expect(() => + createEIP712(1234)( + keypair.publicKey, + '0x8ba1f109551bd432803012645ac136ddd64dba', + ), + ).toThrow('Invalid contract address.'); + expect(() => + createEIP712(1234)( + keypair.publicKey, + '0x8ba1f109551bd432803012645ac136ddd64dba72', + '0xa5e1defb98EFe38EBb2D958CEe052410247F4c8022', + ), + ).toThrow('Invalid delegated account.'); + }); +}); diff --git a/src/sdk/keypair.ts b/src/sdk/keypair.ts new file mode 100644 index 0000000..87e7820 --- /dev/null +++ b/src/sdk/keypair.ts @@ -0,0 +1,84 @@ +import { isAddress } from 'web3-validator'; +import { toHexString } from '../utils'; +import { + cryptobox_keygen, + cryptobox_sk_to_u8vec, + cryptobox_pk_to_u8vec, + cryptobox_get_pk, +} from 'node-kms'; + +export type EIP712Type = { name: string; type: string }; + +export type EIP712 = { + domain: { + chainId: number; + name: string; + verifyingContract: string; + version: string; + }; + message: { + publicKey: string; + delegatedAccount?: string; + }; + primaryType: string; + types: { + [key: string]: EIP712Type[]; + }; +}; + +export const createEIP712 = + (chainId: number) => + (publicKey: string, verifyingContract: string, delegatedAccount?: string) => { + if (!isAddress(verifyingContract)) + throw new Error('Invalid contract address.'); + if (delegatedAccount && !isAddress(delegatedAccount)) + throw new Error('Invalid delegated account.'); + const msgParams: EIP712 = { + types: { + // This refers to the domain the contract is hosted on. + EIP712Domain: [ + { name: 'name', type: 'string' }, + { name: 'version', type: 'string' }, + { name: 'chainId', type: 'uint256' }, + { name: 'verifyingContract', type: 'address' }, + ], + // Refer to primaryType. + Reencrypt: [{ name: 'publicKey', type: 'bytes32' }], + }, + // This defines the message you're proposing the user to sign, is dapp-specific, and contains + // anything you want. There are no required fields. Be as explicit as possible when building out + // the message schema. + // This refers to the keys of the following types object. + primaryType: 'Reencrypt', + domain: { + // Give a user-friendly name to the specific contract you're signing for. + name: 'Authorization token', + // This identifies the latest version. + version: '1', + // This defines the network, in this case, Mainnet. + chainId, + // // Add a verifying contract to make sure you're establishing contracts with the proper entity. + verifyingContract, + }, + message: { + publicKey: `0x${publicKey}`, + }, + }; + + if (delegatedAccount) { + msgParams.message.delegatedAccount = delegatedAccount; + msgParams.types.Reencrypt.push({ + name: 'delegatedAccount', + type: 'address', + }); + } + return msgParams; + }; + +export const generateKeypair = () => { + const keypair = cryptobox_keygen(); + return { + publicKey: toHexString(cryptobox_pk_to_u8vec(cryptobox_get_pk(keypair))), + privateKey: toHexString(cryptobox_sk_to_u8vec(keypair)), + }; +}; diff --git a/src/sdk/network.test.ts b/src/sdk/network.test.ts new file mode 100644 index 0000000..fc1c78c --- /dev/null +++ b/src/sdk/network.test.ts @@ -0,0 +1,25 @@ +import { TfheCompactPublicKey, TfheClientKey } from 'node-tfhe'; +import { createTfheKeypair } from '../tfhe'; +import { createEncryptedInput } from './encrypt'; +import { getPublicKeyCallParams, getPublicKeyFromNetwork } from './network'; +import { fromHexString } from '../utils'; + +describe('network', () => { + let clientKey: TfheClientKey; + let publicKey: TfheCompactPublicKey; + + beforeAll(async () => { + const keypair = createTfheKeypair(); + }); + + it('get network key', async () => { + const pk = await getPublicKeyFromNetwork('https://devnet.zama.ai'); + expect(pk!.length).toBe(33106); + }); + + it('get public key params', async () => { + const params = await getPublicKeyCallParams(); + expect(params.to).toBe('0x000000000000000000000000000000000000005d'); + expect(params.data).toBe('0xd9d47bb001'); + }); +}); diff --git a/src/sdk/network.ts b/src/sdk/network.ts new file mode 100644 index 0000000..63fbc8e --- /dev/null +++ b/src/sdk/network.ts @@ -0,0 +1,68 @@ +import { fetchJSONRPC } from '../ethCall'; + +export const getPublicKeyCallParams = () => ({ + to: '0x000000000000000000000000000000000000005d', + data: '0xd9d47bb001', +}); + +export const getChainIdFromNetwork = async (url: string) => { + const payload = { + jsonrpc: '2.0', + method: 'eth_chainId', + params: [], + id: 1, + }; + + const options = { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(payload), + }; + return Number(fetchJSONRPC(url, options)); +}; + +// Define the function to perform the eth_call +export const getPublicKeyFromNetwork = async (url: string) => { + // Create the JSON-RPC request payload + const payload = { + jsonrpc: '2.0', + method: 'eth_call', + params: [getPublicKeyCallParams(), 'latest'], + id: 1, + }; + + // Set up the fetch request options + const options = { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(payload), + }; + + return fetchJSONRPC(url, options); +}; + +// Define the function to perform the eth_call +export const getPublicKeyFromCoprocessor = async (url: string) => { + // Create the JSON-RPC request payload + const payload = { + jsonrpc: '2.0', + method: 'eth_getPublicFhevmKey', + params: [], + id: 1, + }; + + // Set up the fetch request options + const options = { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify(payload), + }; + + return fetchJSONRPC(url, options); +}; diff --git a/src/sdk/publicKey.test.ts b/src/sdk/publicKey.test.ts deleted file mode 100644 index 179a029..0000000 --- a/src/sdk/publicKey.test.ts +++ /dev/null @@ -1,45 +0,0 @@ -import sodium from 'libsodium-wrappers'; -import { toHexString } from '../utils'; -import { generatePublicKey } from './publicKey'; - -describe('token', () => { - beforeAll(async () => { - await sodium.ready; - }); - it('creates a valid EIP712 object', async () => { - const { eip712, keypair } = generatePublicKey({ - verifyingContract: '0xccc', - chainId: 1234, - name: 'hello', - version: '3', - }); - expect(eip712.domain.chainId).toBe(1234); - expect(eip712.domain.name).toBe('hello'); - expect(eip712.domain.version).toBe('3'); - expect(eip712.message.publicKey).toBe( - `0x${toHexString(keypair.publicKey)}`, - ); - - expect(eip712.primaryType).toBe('Reencrypt'); - expect(eip712.types.Reencrypt.length).toBe(1); - expect(eip712.types.Reencrypt[0].name).toBe('publicKey'); - expect(eip712.types.Reencrypt[0].type).toBe('bytes32'); - }); - - it('creates a valid EIP712 object with default values', async () => { - const { eip712, keypair } = generatePublicKey({ - verifyingContract: '0xccc', - }); - expect(eip712.domain.chainId).toBe(9000); - expect(eip712.domain.name).toBe('Authorization token'); - expect(eip712.domain.version).toBe('1'); - expect(eip712.message.publicKey).toBe( - `0x${toHexString(keypair.publicKey)}`, - ); - - expect(eip712.primaryType).toBe('Reencrypt'); - expect(eip712.types.Reencrypt.length).toBe(1); - expect(eip712.types.Reencrypt[0].name).toBe('publicKey'); - expect(eip712.types.Reencrypt[0].type).toBe('bytes32'); - }); -}); diff --git a/src/sdk/publicKey.ts b/src/sdk/publicKey.ts deleted file mode 100644 index 8d19634..0000000 --- a/src/sdk/publicKey.ts +++ /dev/null @@ -1,78 +0,0 @@ -import sodium from 'libsodium-wrappers'; -import { toHexString } from '../utils'; -import { ContractKeypair } from './types'; - -export type EIP712Type = { name: string; type: string }; - -export type EIP712 = { - domain: { - chainId: number; - name: string; - verifyingContract: string; - version: string; - }; - message: { - [key: string]: any; - }; - primaryType: string; - types: { - [key: string]: EIP712Type[]; - }; -}; - -export type GeneratePublicKeyParams = { - name?: string; - version?: string; - chainId?: number; - verifyingContract: string; - keypair?: ContractKeypair; -}; - -export type FhevmToken = { - keypair: ContractKeypair; - eip712: EIP712; -}; - -export const generatePublicKey = ( - params: GeneratePublicKeyParams, -): FhevmToken => { - const keypair = params.keypair || sodium.crypto_box_keypair(); - const msgParams: EIP712 = { - types: { - // This refers to the domain the contract is hosted on. - EIP712Domain: [ - { name: 'name', type: 'string' }, - { name: 'version', type: 'string' }, - { name: 'chainId', type: 'uint256' }, - { name: 'verifyingContract', type: 'address' }, - ], - // Refer to primaryType. - Reencrypt: [{ name: 'publicKey', type: 'bytes32' }], - }, - // This defines the message you're proposing the user to sign, is dapp-specific, and contains - // anything you want. There are no required fields. Be as explicit as possible when building out - // the message schema. - // This refers to the keys of the following types object. - primaryType: 'Reencrypt', - domain: { - // Give a user-friendly name to the specific contract you're signing for. - name: params.name || 'Authorization token', - // This identifies the latest version. - version: params.version || '1', - // This defines the network, in this case, Mainnet. - chainId: params.chainId || 9000, - // // Add a verifying contract to make sure you're establishing contracts with the proper entity. - verifyingContract: params.verifyingContract, - }, - message: { - publicKey: `0x${toHexString(keypair.publicKey)}`, - }, - }; - return { - keypair: { - publicKey: keypair.publicKey, - privateKey: keypair.privateKey, - }, - eip712: msgParams, - }; -}; diff --git a/src/sdk/reencrypt.test.ts b/src/sdk/reencrypt.test.ts new file mode 100644 index 0000000..48b28d6 --- /dev/null +++ b/src/sdk/reencrypt.test.ts @@ -0,0 +1,41 @@ +import { + FheUint160, + CompactFheUint160List, + TfheCompactPublicKey, + TfheClientKey, +} from 'node-tfhe'; +import { reencryptRequest } from './reencrypt'; +import { createTfheKeypair } from '../tfhe'; +import { createEncryptedInput } from './encrypt'; +import { getPublicKeyCallParams, getPublicKeyFromNetwork } from './network'; +import { fromHexString } from '../utils'; + +describe('reencrypt', () => { + it('get reencryption for handle', async () => { + const reencrypt = reencryptRequest('mock'); + const result = await reencrypt( + BigInt(3333), + '0xccc', + '0xcccc', + '0xccc', + '0x8ba1f109551bd432803012645ac136ddd64dba72', + '0xa5e1defb98EFe38EBb2D958CEe052410247F4c80', + ); + + expect(result.toString()).toBe('10'); + }); + + it('throw if no reencryption URL is provided', async () => { + const reencrypt = reencryptRequest(); + const result = reencrypt( + BigInt(3333), + '0xccc', + '0xcccc', + '0xccc', + '0x8ba1f109551bd432803012645ac136ddd64dba72', + '0xa5e1defb98EFe38EBb2D958CEe052410247F4c80', + ); + + expect(result).rejects.toThrow('You must provide a reencryption URL.'); + }); +}); diff --git a/src/sdk/reencrypt.ts b/src/sdk/reencrypt.ts new file mode 100644 index 0000000..fdabc43 --- /dev/null +++ b/src/sdk/reencrypt.ts @@ -0,0 +1,31 @@ +import { toHexString } from '../utils'; +import { + u8vec_to_cryptobox_pk, + cryptobox_encrypt, + cryptobox_decrypt, + cryptobox_pk_to_u8vec, +} from '../kms/node'; + +export const reencryptRequest = + (reencryptionUrl?: string) => + async ( + handle: bigint, + privateKey: string, + publicKey: string, + signature: string, + contractAddress: string, + userAddress: string, + ) => { + if (!reencryptionUrl) + throw new Error('You must provide a reencryption URL.'); + const data = { + publicKey, + handle, + signature, + contractAddress, + userAddress, + }; + // const response = await fetch(`${reencryptUrl}`); + + return BigInt(10); + }; diff --git a/src/sdk/types.ts b/src/sdk/types.ts deleted file mode 100644 index 8a0922d..0000000 --- a/src/sdk/types.ts +++ /dev/null @@ -1,9 +0,0 @@ -export type ContractKeypairs = { - [key: string]: ContractKeypair; -}; - -export type ContractKeypair = { - publicKey: Uint8Array; - privateKey: Uint8Array; - signature?: string | null; -}; diff --git a/src/utils.test.ts b/src/utils.test.ts index 95ed0a0..79e2a1b 100644 --- a/src/utils.test.ts +++ b/src/utils.test.ts @@ -1,7 +1,9 @@ import { bigIntToBytes, bytesToBigInt, + bytesToHex, clientKeyDecryptor, + fromHexString, toHexString, } from './utils'; import { createTfheKeypair } from './tfhe'; @@ -26,6 +28,23 @@ describe('decrypt', () => { compactPublicKey = publicKey; }); + it('converts a hex to bytes', async () => { + const value = '0xff'; + const bytes = fromHexString(value); + expect(bytes).toEqual(new Uint8Array([255])); + + const bytes2 = fromHexString('0x'); + expect(bytes2).toEqual(new Uint8Array([])); + }); + + it('converts a bytes to hex', async () => { + const bytes = bytesToHex(new Uint8Array([255])); + expect(bytes).toEqual('0xff'); + + const bytes2 = bytesToHex(new Uint8Array()); + expect(bytes2).toEqual('0x0'); + }); + it('converts a number to bytes', async () => { const value = BigInt(28482); const bytes = bigIntToBytes(value); diff --git a/src/utils.ts b/src/utils.ts index face392..304d249 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -42,14 +42,6 @@ export const bytesToBigInt = function (byteArray: Uint8Array): bigint { return result; }; -export const isAddress = function (address: string) { - if (address.match(/^0x[0-9a-fA-F]{40}$/)) { - // check if it has the basic requirements of an address - return true; - } - return false; -}; - export const clientKeyDecryptor = (clientKeySer: Uint8Array) => { const clientKey = TfheClientKey.deserialize(clientKeySer); return { diff --git a/tsconfig.json b/tsconfig.json index 3ccb020..3818162 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -14,7 +14,8 @@ "baseUrl": ".", "resolveJsonModule": true, "paths": { - "*": ["*"] + "*": ["*"], + "node-kms": ["src/kms/node/index.js"] } }, "include": ["src", "types"], diff --git a/tsconfig.rollup.json b/tsconfig.rollup.json index c12c108..8287472 100644 --- a/tsconfig.rollup.json +++ b/tsconfig.rollup.json @@ -13,7 +13,8 @@ "baseUrl": ".", "resolveJsonModule": false, "paths": { - "*": ["*"] + "*": ["*"], + "node-kms": ["src/kms/node/index.js"] } }, "include": ["src"],