diff --git a/config/rollup.config.js b/config/rollup.config.js index 846163e..5d7501a 100644 --- a/config/rollup.config.js +++ b/config/rollup.config.js @@ -1,28 +1,18 @@ import { createRequire } from 'node:module'; +import json from '@rollup/plugin-json'; +import url from '@rollup/plugin-url'; import { wasm } from '@rollup/plugin-wasm'; import typescript from '@rollup/plugin-typescript'; import replace from '@rollup/plugin-replace'; import resolve from '@rollup/plugin-node-resolve'; import commonjs from '@rollup/plugin-commonjs'; -import copy from 'rollup-plugin-copy'; import nodePolyfills from 'rollup-plugin-polyfill-node'; const require = createRequire(import.meta.url); const nodePlugins = [ - copy({ - targets: [ - { - src: './src/kms/node/*', - dest: 'lib/kms/node', - }, - { - src: './src/kms/node/kms_lib_bg.wasm', - dest: 'lib/', - }, - ], - }), + json(), wasm(), commonjs(), typescript({ @@ -31,19 +21,13 @@ const nodePlugins = [ ]; const webPlugins = [ - copy({ - targets: [ - { - src: './src/kms/web/*', - dest: 'lib/kms/web', - }, - ], - }), + json(), + url(), nodePolyfills(), replace({ preventAssignment: true, 'node-tfhe': 'tfhe', - 'kms/node': 'kms/web', + 'node-tkms': 'tkms', }), typescript({ tsconfig: './tsconfig.rollup.json', @@ -56,7 +40,7 @@ const webPlugins = [ commonjs(), resolve({ browser: true, - resolveOnly: ['tfhe'], + resolveOnly: ['tfhe', 'tkms'], extensions: ['.js', '.ts', '.wasm'], }), ]; @@ -71,6 +55,16 @@ export default [ }, plugins: [...webPlugins], }, + { + input: + './node_modules/tfhe/snippets/wasm-bindgen-rayon-3e04391371ad0a8e/src/workerHelpers.worker.js', + output: { + file: 'lib/workerHelpers.worker.js', + name: 'fhevm', + format: 'es', + }, + plugins: [...webPlugins], + }, { input: 'src/node.ts', output: { diff --git a/config/webpack.config.cjs b/config/webpack.config.cjs index a211614..2d63f10 100644 --- a/config/webpack.config.cjs +++ b/config/webpack.config.cjs @@ -59,9 +59,10 @@ const web = { 'node-tfhe': 'tfhe/tfhe', }, fallback: { - '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'), + 'tfhe_bg.wasm': require.resolve('tfhe/tfhe_bg.wasm'), + 'node-tkms': require.resolve('tkms/kms_lib'), + 'kms_lib_bg.wasm': require.resolve('tkms/kms_lib_bg.wasm'), buffer: require.resolve('buffer/'), crypto: require.resolve('crypto-browserify'), stream: require.resolve('stream-browserify'), @@ -72,9 +73,6 @@ const web = { new webpack.ProvidePlugin({ Buffer: ['buffer', 'Buffer'], }), - new webpack.optimize.LimitChunkCountPlugin({ - maxChunks: 1, - }), ], }; diff --git a/generateKeys.js b/generateKeys.js new file mode 100755 index 0000000..43b99c5 --- /dev/null +++ b/generateKeys.js @@ -0,0 +1,58 @@ +#!/usr/bin/env node + +import { + TfheCompactPublicKey, + TfheConfigBuilder, + TfheClientKey, + ShortintParameters, + ShortintParametersName, + CompactPkeCrs, + ShortintCompactPublicKeyEncryptionParameters, + ShortintCompactPublicKeyEncryptionParametersName, +} from 'node-tfhe'; + +import fs from 'fs'; + +const createTfheKeypair = () => { + const block_params = new ShortintParameters( + ShortintParametersName.PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_PBS_KS, + ); + const casting_params = new ShortintCompactPublicKeyEncryptionParameters( + ShortintCompactPublicKeyEncryptionParametersName.SHORTINT_PARAM_PKE_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64, + ); + const config = TfheConfigBuilder.default() + .use_custom_parameters(block_params) + .use_dedicated_compact_public_key_parameters(casting_params) + .build(); + let clientKey = TfheClientKey.generate(config); + let publicKey = TfheCompactPublicKey.new(clientKey); + fs.writeFileSync('src/test/keys/publicKey.bin', publicKey.serialize()); + fs.writeFileSync('src/test/keys/privateKey.bin', clientKey.serialize()); + const crs0 = CompactPkeCrs.from_config(config, 4 * 32); + fs.writeFileSync( + 'src/test/keys/crs128.bin', + crs0.public_params().serialize(), + ); + const crs1 = CompactPkeCrs.from_config(config, 4 * 64); + fs.writeFileSync( + 'src/test/keys/crs256.bin', + crs1.public_params().serialize(), + ); + const crs2 = CompactPkeCrs.from_config(config, 4 * 128); + fs.writeFileSync( + 'src/test/keys/crs512.bin', + crs2.public_params().serialize(), + ); + const crs3 = CompactPkeCrs.from_config(config, 4 * 256); + fs.writeFileSync( + 'src/test/keys/crs1024.bin', + crs3.public_params().serialize(), + ); + const crs4 = CompactPkeCrs.from_config(config, 4 * 512); + fs.writeFileSync( + 'src/test/keys/crs2048.bin', + crs4.public_params().serialize(), + ); +}; + +createTfheKeypair(); diff --git a/jest.config.cjs b/jest.config.cjs index 447a509..f548de9 100644 --- a/jest.config.cjs +++ b/jest.config.cjs @@ -26,6 +26,7 @@ module.exports = { '!src/node.ts', '!src/web.ts', ], + setupFiles: ['./setupJest.cjs'], testRegex: '\\.test\\.tsx?$', coverageReporters: ['lcov', 'text-summary', 'json'], transformIgnorePatterns: ['/node_modules/'], diff --git a/package-lock.json b/package-lock.json index 582184e..26b6b18 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,10 +12,12 @@ "@types/keccak": "^3.0.4", "bigint-buffer": "^1.1.5", "commander": "^11.0.0", - "node-fetch": "^2.7.0", - "node-tfhe": "^0.6.3", + "fetch-mock": "^11.1.3", + "node-tfhe": "^0.8.0", + "node-tkms": "^0.9.0-rc11", "sha3": "^2.1.4", - "tfhe": "^0.6.3", + "tfhe": "^0.8.0", + "tkms": "^0.9.0-rc11", "url": "^0.11.3", "web3-validator": "^2.0.6" }, @@ -23,18 +25,21 @@ "fhevm": "bin/fhevm.js" }, "devDependencies": { + "@fetch-mock/jest": "^0.1.0", + "@jest/globals": "^29.7.0", "@rollup/plugin-alias": "^5.1.0", "@rollup/plugin-commonjs": "^25.0.0", + "@rollup/plugin-json": "^6.1.0", "@rollup/plugin-node-resolve": "^15.1.0", "@rollup/plugin-replace": "^5.0.2", "@rollup/plugin-typescript": "^11.1.1", + "@rollup/plugin-url": "^8.0.2", "@rollup/plugin-wasm": "^6.1.3", "@types/jest": "^29.5.1", "@types/node-fetch": "^2.6.11", "buffer": "^6.0.3", "crypto-browserify": "^3.12.0", "ethers": "^6.13.1", - "fetch-mock-jest": "^1.5.1", "jest": "^29.5.0", "jest-raw-loader": "^1.0.1", "path-browserify": "^1.0.1", @@ -685,18 +690,6 @@ "@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", @@ -761,6 +754,40 @@ "node": ">=10.0.0" } }, + "node_modules/@fetch-mock/core": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/@fetch-mock/core/-/core-0.7.0.tgz", + "integrity": "sha512-8brSKB6bfAjsGpkmzjMqMZ6T4SbH00n9HaurNAhecB6/0dAKVPXnN4A2DolqBqj8PYK7ttKCUs3hVthtQ7J2Cw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@types/glob-to-regexp": "^0.4.4", + "dequal": "^2.0.3", + "glob-to-regexp": "^0.4.1", + "is-subset-of": "^3.1.10", + "regexparam": "^3.0.0" + }, + "engines": { + "node": ">=18.11.0" + } + }, + "node_modules/@fetch-mock/jest": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/@fetch-mock/jest/-/jest-0.1.0.tgz", + "integrity": "sha512-mX9m4MIxQjSXrz1c2+Q8Rj+5mUzSnq7dYlNRSPJLrgaF7Im5mIQJ19xCYxhnVR76RfOPBr08cwO40rWUELBlWg==", + "dev": true, + "license": "MIT", + "dependencies": { + "@fetch-mock/core": "^0.7.0" + }, + "engines": { + "node": ">=18.11.0" + }, + "peerDependencies": { + "@jest/globals": "*", + "jest": "*" + } + }, "node_modules/@istanbuljs/load-nyc-config": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz", @@ -851,72 +878,77 @@ } }, "node_modules/@jest/environment": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/@jest/environment/-/environment-29.5.0.tgz", - "integrity": "sha512-5FXw2+wD29YU1d4I2htpRX7jYnAyTRjP2CsXQdo9SAM8g3ifxWPSV0HnClSn71xwctr0U3oZIIH+dtbfmnbXVQ==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/@jest/environment/-/environment-29.7.0.tgz", + "integrity": "sha512-aQIfHDq33ExsN4jP1NWGXhxgQ/wixs60gDiKO+XVMd8Mn0NWPWgc34ZQDTb2jKaUWQ7MuwoitXAsN2XVXNMpAw==", "dev": true, + "license": "MIT", "dependencies": { - "@jest/fake-timers": "^29.5.0", - "@jest/types": "^29.5.0", + "@jest/fake-timers": "^29.7.0", + "@jest/types": "^29.6.3", "@types/node": "*", - "jest-mock": "^29.5.0" + "jest-mock": "^29.7.0" }, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, "node_modules/@jest/expect": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/@jest/expect/-/expect-29.5.0.tgz", - "integrity": "sha512-PueDR2HGihN3ciUNGr4uelropW7rqUfTiOn+8u0leg/42UhblPxHkfoh0Ruu3I9Y1962P3u2DY4+h7GVTSVU6g==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/@jest/expect/-/expect-29.7.0.tgz", + "integrity": "sha512-8uMeAMycttpva3P1lBHB8VciS9V0XAr3GymPpipdyQXbBcuhkLQOSe8E/p92RyAdToS6ZD1tFkX+CkhoECE0dQ==", "dev": true, + "license": "MIT", "dependencies": { - "expect": "^29.5.0", - "jest-snapshot": "^29.5.0" + "expect": "^29.7.0", + "jest-snapshot": "^29.7.0" }, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, "node_modules/@jest/expect-utils": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/@jest/expect-utils/-/expect-utils-29.5.0.tgz", - "integrity": "sha512-fmKzsidoXQT2KwnrwE0SQq3uj8Z763vzR8LnLBwC2qYWEFpjX8daRsk6rHUM1QvNlEW/UJXNXm59ztmJJWs2Mg==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/@jest/expect-utils/-/expect-utils-29.7.0.tgz", + "integrity": "sha512-GlsNBWiFQFCVi9QVSx7f5AgMeLxe9YCCs5PuP2O2LdjDAA8Jh9eX7lA1Jq/xdXw3Wb3hyvlFNfZIfcRetSzYcA==", "dev": true, + "license": "MIT", "dependencies": { - "jest-get-type": "^29.4.3" + "jest-get-type": "^29.6.3" }, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, "node_modules/@jest/fake-timers": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/@jest/fake-timers/-/fake-timers-29.5.0.tgz", - "integrity": "sha512-9ARvuAAQcBwDAqOnglWq2zwNIRUDtk/SCkp/ToGEhFv5r86K21l+VEs0qNTaXtyiY0lEePl3kylijSYJQqdbDg==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/@jest/fake-timers/-/fake-timers-29.7.0.tgz", + "integrity": "sha512-q4DH1Ha4TTFPdxLsqDXK1d3+ioSL7yL5oCMJZgDYm6i+6CygW5E5xVr/D1HdsGxjt1ZWSfUAs9OxSB/BNelWrQ==", "dev": true, + "license": "MIT", "dependencies": { - "@jest/types": "^29.5.0", + "@jest/types": "^29.6.3", "@sinonjs/fake-timers": "^10.0.2", "@types/node": "*", - "jest-message-util": "^29.5.0", - "jest-mock": "^29.5.0", - "jest-util": "^29.5.0" + "jest-message-util": "^29.7.0", + "jest-mock": "^29.7.0", + "jest-util": "^29.7.0" }, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, "node_modules/@jest/globals": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/@jest/globals/-/globals-29.5.0.tgz", - "integrity": "sha512-S02y0qMWGihdzNbUiqSAiKSpSozSuHX5UYc7QbnHP+D9Lyw8DgGGCinrN9uSuHPeKgSSzvPom2q1nAtBvUsvPQ==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/@jest/globals/-/globals-29.7.0.tgz", + "integrity": "sha512-mpiz3dutLbkW2MNFubUGUEVLkTGiqW6yLVTA+JbP6fI6J5iL9Y0Nlg8k95pcF8ctKwCS7WVxteBs29hhfAotzQ==", "dev": true, + "license": "MIT", "dependencies": { - "@jest/environment": "^29.5.0", - "@jest/expect": "^29.5.0", - "@jest/types": "^29.5.0", - "jest-mock": "^29.5.0" + "@jest/environment": "^29.7.0", + "@jest/expect": "^29.7.0", + "@jest/types": "^29.6.3", + "jest-mock": "^29.7.0" }, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" @@ -981,12 +1013,13 @@ } }, "node_modules/@jest/schemas": { - "version": "29.4.3", - "resolved": "https://registry.npmjs.org/@jest/schemas/-/schemas-29.4.3.tgz", - "integrity": "sha512-VLYKXQmtmuEz6IxJsrZwzG9NvtkQsWNnWMsKxqWNu3+CnfzJQhp0WDDKWLVV9hLKr0l3SLLFRqcYHjhtyuDVxg==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/@jest/schemas/-/schemas-29.6.3.tgz", + "integrity": "sha512-mo5j5X+jIZmJQveBKeS/clAueipV7KgiX1vMgCxam1RNYiqE1w62n0/tJJnHtjW8ZHcQco5gY85jA3mi0L+nSA==", "dev": true, + "license": "MIT", "dependencies": { - "@sinclair/typebox": "^0.25.16" + "@sinclair/typebox": "^0.27.8" }, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" @@ -1037,22 +1070,23 @@ } }, "node_modules/@jest/transform": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/@jest/transform/-/transform-29.5.0.tgz", - "integrity": "sha512-8vbeZWqLJOvHaDfeMuoHITGKSz5qWc9u04lnWrQE3VyuSw604PzQM824ZeX9XSjUCeDiE3GuxZe5UKa8J61NQw==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/@jest/transform/-/transform-29.7.0.tgz", + "integrity": "sha512-ok/BTPFzFKVMwO5eOHRrvnBVHdRy9IrsrW1GpMaQ9MCnilNLXQKmAX8s1YXDFaai9xJpac2ySzV0YeRRECr2Vw==", "dev": true, + "license": "MIT", "dependencies": { "@babel/core": "^7.11.6", - "@jest/types": "^29.5.0", - "@jridgewell/trace-mapping": "^0.3.15", + "@jest/types": "^29.6.3", + "@jridgewell/trace-mapping": "^0.3.18", "babel-plugin-istanbul": "^6.1.1", "chalk": "^4.0.0", "convert-source-map": "^2.0.0", "fast-json-stable-stringify": "^2.1.0", "graceful-fs": "^4.2.9", - "jest-haste-map": "^29.5.0", - "jest-regex-util": "^29.4.3", - "jest-util": "^29.5.0", + "jest-haste-map": "^29.7.0", + "jest-regex-util": "^29.6.3", + "jest-util": "^29.7.0", "micromatch": "^4.0.4", "pirates": "^4.0.4", "slash": "^3.0.0", @@ -1063,12 +1097,13 @@ } }, "node_modules/@jest/types": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/@jest/types/-/types-29.5.0.tgz", - "integrity": "sha512-qbu7kN6czmVRc3xWFQcAN03RAUamgppVUdXrvl1Wr3jlNF93o9mJbGcDWrwGB6ht44u7efB1qCFgVQmca24Uog==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/@jest/types/-/types-29.6.3.tgz", + "integrity": "sha512-u3UPsIilWKOM3F9CXtrG8LEJmNxwoCQC/XVj4IKYXvvpx7QIi/Kg1LI5uDmDpKlac62NUtX7eLjRh+jVZcLOzw==", "dev": true, + "license": "MIT", "dependencies": { - "@jest/schemas": "^29.4.3", + "@jest/schemas": "^29.6.3", "@types/istanbul-lib-coverage": "^2.0.0", "@types/istanbul-reports": "^3.0.0", "@types/node": "*", @@ -1325,6 +1360,27 @@ } } }, + "node_modules/@rollup/plugin-json": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/@rollup/plugin-json/-/plugin-json-6.1.0.tgz", + "integrity": "sha512-EGI2te5ENk1coGeADSIwZ7G2Q8CJS2sF120T7jLw4xFw9n7wIOXHo+kIYRAoVpJAN+kmqZSoO3Fp4JtoNF4ReA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@rollup/pluginutils": "^5.1.0" + }, + "engines": { + "node": ">=14.0.0" + }, + "peerDependencies": { + "rollup": "^1.20.0||^2.0.0||^3.0.0||^4.0.0" + }, + "peerDependenciesMeta": { + "rollup": { + "optional": true + } + } + }, "node_modules/@rollup/plugin-node-resolve": { "version": "15.1.0", "resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-15.1.0.tgz", @@ -1397,6 +1453,29 @@ } } }, + "node_modules/@rollup/plugin-url": { + "version": "8.0.2", + "resolved": "https://registry.npmjs.org/@rollup/plugin-url/-/plugin-url-8.0.2.tgz", + "integrity": "sha512-5yW2LP5NBEgkvIRSSEdJkmxe5cUNZKG3eenKtfJvSkxVm/xTTu7w+ayBtNwhozl1ZnTUCU0xFaRQR+cBl2H7TQ==", + "dev": true, + "license": "MIT", + "dependencies": { + "@rollup/pluginutils": "^5.0.1", + "make-dir": "^3.1.0", + "mime": "^3.0.0" + }, + "engines": { + "node": ">=14.0.0" + }, + "peerDependencies": { + "rollup": "^1.20.0||^2.0.0||^3.0.0||^4.0.0" + }, + "peerDependenciesMeta": { + "rollup": { + "optional": true + } + } + }, "node_modules/@rollup/plugin-wasm": { "version": "6.1.3", "resolved": "https://registry.npmjs.org/@rollup/plugin-wasm/-/plugin-wasm-6.1.3.tgz", @@ -1415,10 +1494,11 @@ } }, "node_modules/@rollup/pluginutils": { - "version": "5.0.2", - "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.0.2.tgz", - "integrity": "sha512-pTd9rIsP92h+B6wWwFbW8RkZv4hiR/xKsqre4SIuAOaOEQRxi0lqLke9k2/7WegC85GgUs9pjmOjCUi3In4vwA==", + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.1.2.tgz", + "integrity": "sha512-/FIdS3PyZ39bjZlwqFnWqCOVnW7o963LtKMwQOD0NhQqw22gSr2YY1afu3FxRip4ZCZNsD5jq6Aaz6QV3D/Njw==", "dev": true, + "license": "MIT", "dependencies": { "@types/estree": "^1.0.0", "estree-walker": "^2.0.2", @@ -1428,7 +1508,7 @@ "node": ">=14.0.0" }, "peerDependencies": { - "rollup": "^1.20.0||^2.0.0||^3.0.0" + "rollup": "^1.20.0||^2.0.0||^3.0.0||^4.0.0" }, "peerDependenciesMeta": { "rollup": { @@ -1492,10 +1572,11 @@ } }, "node_modules/@sinclair/typebox": { - "version": "0.25.24", - "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.25.24.tgz", - "integrity": "sha512-XJfwUVUKDHF5ugKwIcxEgc9k8b7HbznCp6eUfWgu710hMPNIO4aw4/zB5RogDQz8nd6gyCDpU9O/m6qYEWY6yQ==", - "dev": true + "version": "0.27.8", + "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.27.8.tgz", + "integrity": "sha512-+Fj43pSMwJs4KRrH/938Uf+uAELIgVBmQzg/q1YG10djyfA3TnrU8N8XzqCh/okZdszqBQTZf96idMfE5lnwTA==", + "dev": true, + "license": "MIT" }, "node_modules/@sinonjs/commons": { "version": "2.0.0", @@ -1601,6 +1682,12 @@ "@types/node": "*" } }, + "node_modules/@types/glob-to-regexp": { + "version": "0.4.4", + "resolved": "https://registry.npmjs.org/@types/glob-to-regexp/-/glob-to-regexp-0.4.4.tgz", + "integrity": "sha512-nDKoaKJYbnn1MZxUY0cA1bPmmgZbg0cTq7Rh13d0KWYNOiKbqoR+2d89SnRPszGh7ROzSwZ/GOjZ4jPbmmZ6Eg==", + "license": "MIT" + }, "node_modules/@types/graceful-fs": { "version": "4.1.6", "resolved": "https://registry.npmjs.org/@types/graceful-fs/-/graceful-fs-4.1.6.tgz", @@ -1679,12 +1766,6 @@ "form-data": "^4.0.0" } }, - "node_modules/@types/prettier": { - "version": "2.7.2", - "resolved": "https://registry.npmjs.org/@types/prettier/-/prettier-2.7.2.tgz", - "integrity": "sha512-KufADq8uQqo1pYKVIYzfKbJfBAc0sOeXqGbFaSpv8MRmC/zXgowNZmFcbngndGk922QDmOASEXUZCaY48gs4cg==", - "dev": true - }, "node_modules/@types/resolve": { "version": "1.20.2", "resolved": "https://registry.npmjs.org/@types/resolve/-/resolve-1.20.2.tgz", @@ -2703,17 +2784,6 @@ "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", @@ -2850,6 +2920,15 @@ "node": ">=0.4.0" } }, + "node_modules/dequal": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/dequal/-/dequal-2.0.3.tgz", + "integrity": "sha512-0je+qPKHEMohvfRTCEo3CrPG6cAzAYgmzKyxRiYSSDkS6eGJdyVJm7WaYA5ECaAD9wLB2T4EEeymA5aFVcYXCA==", + "license": "MIT", + "engines": { + "node": ">=6" + } + }, "node_modules/des.js": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/des.js/-/des.js-1.0.1.tgz", @@ -2870,10 +2949,11 @@ } }, "node_modules/diff-sequences": { - "version": "29.4.3", - "resolved": "https://registry.npmjs.org/diff-sequences/-/diff-sequences-29.4.3.tgz", - "integrity": "sha512-ofrBgwpPhCD85kMKtE9RYFFq6OC1A89oW2vvgWZNCwxrUpRUILopY7lsYyMDSjc8g6U6aiO0Qubg6r4Wgt5ZnA==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/diff-sequences/-/diff-sequences-29.6.3.tgz", + "integrity": "sha512-EjePK1srD3P08o2j4f0ExnylqRs5B9tJjcp9t1krH2qRi8CCdsYfwe9JgSLurFBWwq4uOlipzfk5fHNvwFKr8Q==", "dev": true, + "license": "MIT", "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } @@ -3235,16 +3315,17 @@ } }, "node_modules/expect": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/expect/-/expect-29.5.0.tgz", - "integrity": "sha512-yM7xqUrCO2JdpFo4XpM82t+PJBFybdqoQuJLDGeDX2ij8NZzqRHyu3Hp188/JX7SWqud+7t4MUdvcgGBICMHZg==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/expect/-/expect-29.7.0.tgz", + "integrity": "sha512-2Zks0hf1VLFYI1kbh0I5jP3KHHyCHpkfyHBzsSXRFgl/Bg9mWYfMW8oD+PdMPlEwy5HNsR9JutYy6pMeOh61nw==", "dev": true, + "license": "MIT", "dependencies": { - "@jest/expect-utils": "^29.5.0", - "jest-get-type": "^29.4.3", - "jest-matcher-utils": "^29.5.0", - "jest-message-util": "^29.5.0", - "jest-util": "^29.5.0" + "@jest/expect-utils": "^29.7.0", + "jest-get-type": "^29.6.3", + "jest-matcher-utils": "^29.7.0", + "jest-message-util": "^29.7.0", + "jest-util": "^29.7.0" }, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" @@ -3306,56 +3387,20 @@ } }, "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, + "version": "11.1.3", + "resolved": "https://registry.npmjs.org/fetch-mock/-/fetch-mock-11.1.3.tgz", + "integrity": "sha512-ATh0dWgnVrUHiiXuvQm1Ry+ThWfSv1QQgqJTCtybrNxyUrFiSOaDKsNG29eyysp1SHeNP6Q+dH50+8VifN51Ig==", + "license": "MIT", "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", + "@types/glob-to-regexp": "^0.4.4", + "dequal": "^2.0.3", + "glob-to-regexp": "^0.4.1", "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" + "regexparam": "^3.0.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 @@ -3557,8 +3602,7 @@ "node_modules/glob-to-regexp": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/glob-to-regexp/-/glob-to-regexp-0.4.1.tgz", - "integrity": "sha512-lkX1HJXwyMcprw/5YUZc2s7DrpAiHB21/V+E1rHUrVNokkvB6bqMzT0VfV6/86ZNabt1k14YOIaT7nDvOX3Iiw==", - "dev": true + "integrity": "sha512-lkX1HJXwyMcprw/5YUZc2s7DrpAiHB21/V+E1rHUrVNokkvB6bqMzT0VfV6/86ZNabt1k14YOIaT7nDvOX3Iiw==" }, "node_modules/globals": { "version": "11.12.0", @@ -4009,7 +4053,17 @@ "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 + "license": "MIT" + }, + "node_modules/is-subset-of": { + "version": "3.1.10", + "resolved": "https://registry.npmjs.org/is-subset-of/-/is-subset-of-3.1.10.tgz", + "integrity": "sha512-avvaYgVmYWyaZ1NDFiv4y9JGkrE2je3op1Po4VYKKJKR8H2qVPsg1GZuuXl5elCTxTlwAIsrAjWAs4BVrISFRw==", + "dev": true, + "license": "MIT", + "dependencies": { + "typedescriptor": "3.0.2" + } }, "node_modules/is-typed-array": { "version": "1.1.13", @@ -4307,15 +4361,16 @@ } }, "node_modules/jest-diff": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/jest-diff/-/jest-diff-29.5.0.tgz", - "integrity": "sha512-LtxijLLZBduXnHSniy0WMdaHjmQnt3g5sa16W4p0HqukYTTsyTW3GD1q41TyGl5YFXj/5B2U6dlh5FM1LIMgxw==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-diff/-/jest-diff-29.7.0.tgz", + "integrity": "sha512-LMIgiIrhigmPrs03JHpxUh2yISK3vLFPkAodPeo0+BuF7wA2FoQbkEg1u8gBYBThncu7e1oEDUfIXVuTqLRUjw==", "dev": true, + "license": "MIT", "dependencies": { "chalk": "^4.0.0", - "diff-sequences": "^29.4.3", - "jest-get-type": "^29.4.3", - "pretty-format": "^29.5.0" + "diff-sequences": "^29.6.3", + "jest-get-type": "^29.6.3", + "pretty-format": "^29.7.0" }, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" @@ -4367,29 +4422,31 @@ } }, "node_modules/jest-get-type": { - "version": "29.4.3", - "resolved": "https://registry.npmjs.org/jest-get-type/-/jest-get-type-29.4.3.tgz", - "integrity": "sha512-J5Xez4nRRMjk8emnTpWrlkyb9pfRQQanDrvWHhsR1+VUfbwxi30eVcZFlcdGInRibU4G5LwHXpI7IRHU0CY+gg==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/jest-get-type/-/jest-get-type-29.6.3.tgz", + "integrity": "sha512-zrteXnqYxfQh7l5FHyL38jL39di8H8rHoecLH3JNxH3BwOrBsNeabdap5e0I23lD4HHI8W5VFBZqG4Eaq5LNcw==", "dev": true, + "license": "MIT", "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, "node_modules/jest-haste-map": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/jest-haste-map/-/jest-haste-map-29.5.0.tgz", - "integrity": "sha512-IspOPnnBro8YfVYSw6yDRKh/TiCdRngjxeacCps1cQ9cgVN6+10JUcuJ1EabrgYLOATsIAigxA0rLR9x/YlrSA==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-haste-map/-/jest-haste-map-29.7.0.tgz", + "integrity": "sha512-fP8u2pyfqx0K1rGn1R9pyE0/KTn+G7PxktWidOBTqFPLYX0b9ksaMFkhK5vrS3DVun09pckLdlx90QthlW7AmA==", "dev": true, + "license": "MIT", "dependencies": { - "@jest/types": "^29.5.0", + "@jest/types": "^29.6.3", "@types/graceful-fs": "^4.1.3", "@types/node": "*", "anymatch": "^3.0.3", "fb-watchman": "^2.0.0", "graceful-fs": "^4.2.9", - "jest-regex-util": "^29.4.3", - "jest-util": "^29.5.0", - "jest-worker": "^29.5.0", + "jest-regex-util": "^29.6.3", + "jest-util": "^29.7.0", + "jest-worker": "^29.7.0", "micromatch": "^4.0.4", "walker": "^1.0.8" }, @@ -4401,13 +4458,14 @@ } }, "node_modules/jest-haste-map/node_modules/jest-worker": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/jest-worker/-/jest-worker-29.5.0.tgz", - "integrity": "sha512-NcrQnevGoSp4b5kg+akIpthoAFHxPBcb5P6mYPY0fUNT+sSvmtu6jlkEle3anczUKIKEbMxFimk9oTP/tpIPgA==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-worker/-/jest-worker-29.7.0.tgz", + "integrity": "sha512-eIz2msL/EzL9UFTFFx7jBTkeZfku0yUAyZZZmJ93H2TYEiroIx2PQjEXcwYtYl8zXCxb+PAmA2hLIt/6ZEkPHw==", "dev": true, + "license": "MIT", "dependencies": { "@types/node": "*", - "jest-util": "^29.5.0", + "jest-util": "^29.7.0", "merge-stream": "^2.0.0", "supports-color": "^8.0.0" }, @@ -4429,33 +4487,35 @@ } }, "node_modules/jest-matcher-utils": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/jest-matcher-utils/-/jest-matcher-utils-29.5.0.tgz", - "integrity": "sha512-lecRtgm/rjIK0CQ7LPQwzCs2VwW6WAahA55YBuI+xqmhm7LAaxokSB8C97yJeYyT+HvQkH741StzpU41wohhWw==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-matcher-utils/-/jest-matcher-utils-29.7.0.tgz", + "integrity": "sha512-sBkD+Xi9DtcChsI3L3u0+N0opgPYnCRPtGcQYrgXmR+hmt/fYfWAL0xRXYU8eWOdfuLgBe0YCW3AFtnRLagq/g==", "dev": true, + "license": "MIT", "dependencies": { "chalk": "^4.0.0", - "jest-diff": "^29.5.0", - "jest-get-type": "^29.4.3", - "pretty-format": "^29.5.0" + "jest-diff": "^29.7.0", + "jest-get-type": "^29.6.3", + "pretty-format": "^29.7.0" }, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, "node_modules/jest-message-util": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/jest-message-util/-/jest-message-util-29.5.0.tgz", - "integrity": "sha512-Kijeg9Dag6CKtIDA7O21zNTACqD5MD/8HfIV8pdD94vFyFuer52SigdC3IQMhab3vACxXMiFk+yMHNdbqtyTGA==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-message-util/-/jest-message-util-29.7.0.tgz", + "integrity": "sha512-GBEV4GRADeP+qtB2+6u61stea8mGcOT4mCtrYISZwfu9/ISHFJ/5zOMXYbpBE9RsS5+Gb63DW4FgmnKJ79Kf6w==", "dev": true, + "license": "MIT", "dependencies": { "@babel/code-frame": "^7.12.13", - "@jest/types": "^29.5.0", + "@jest/types": "^29.6.3", "@types/stack-utils": "^2.0.0", "chalk": "^4.0.0", "graceful-fs": "^4.2.9", "micromatch": "^4.0.4", - "pretty-format": "^29.5.0", + "pretty-format": "^29.7.0", "slash": "^3.0.0", "stack-utils": "^2.0.3" }, @@ -4464,14 +4524,15 @@ } }, "node_modules/jest-mock": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/jest-mock/-/jest-mock-29.5.0.tgz", - "integrity": "sha512-GqOzvdWDE4fAV2bWQLQCkujxYWL7RxjCnj71b5VhDAGOevB3qj3Ovg26A5NI84ZpODxyzaozXLOh2NCgkbvyaw==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-mock/-/jest-mock-29.7.0.tgz", + "integrity": "sha512-ITOMZn+UkYS4ZFh83xYAOzWStloNzJFO2s8DWrE4lhtGD+AorgnbkiKERe4wQVBydIGPx059g6riW5Btp6Llnw==", "dev": true, + "license": "MIT", "dependencies": { - "@jest/types": "^29.5.0", + "@jest/types": "^29.6.3", "@types/node": "*", - "jest-util": "^29.5.0" + "jest-util": "^29.7.0" }, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" @@ -4501,10 +4562,11 @@ "dev": true }, "node_modules/jest-regex-util": { - "version": "29.4.3", - "resolved": "https://registry.npmjs.org/jest-regex-util/-/jest-regex-util-29.4.3.tgz", - "integrity": "sha512-O4FglZaMmWXbGHSQInfXewIsd1LMn9p3ZXB/6r4FOkyhX2/iP/soMG98jGvk/A3HAN78+5VWcBGO0BJAPRh4kg==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/jest-regex-util/-/jest-regex-util-29.6.3.tgz", + "integrity": "sha512-KJJBsRCyyLNWCNBOvZyRDnAIfUiRJ8v+hOBQYGn8gDyF3UegwiP4gwRR3/SDa42g1YbVycTidUF3rKjyLFDWbg==", "dev": true, + "license": "MIT", "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } @@ -4648,46 +4710,45 @@ } }, "node_modules/jest-snapshot": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/jest-snapshot/-/jest-snapshot-29.5.0.tgz", - "integrity": "sha512-x7Wolra5V0tt3wRs3/ts3S6ciSQVypgGQlJpz2rsdQYoUKxMxPNaoHMGJN6qAuPJqS+2iQ1ZUn5kl7HCyls84g==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-snapshot/-/jest-snapshot-29.7.0.tgz", + "integrity": "sha512-Rm0BMWtxBcioHr1/OX5YCP8Uov4riHvKPknOGs804Zg9JGZgmIBkbtlxJC/7Z4msKYVbIJtfU+tKb8xlYNfdkw==", "dev": true, + "license": "MIT", "dependencies": { "@babel/core": "^7.11.6", "@babel/generator": "^7.7.2", "@babel/plugin-syntax-jsx": "^7.7.2", "@babel/plugin-syntax-typescript": "^7.7.2", - "@babel/traverse": "^7.7.2", "@babel/types": "^7.3.3", - "@jest/expect-utils": "^29.5.0", - "@jest/transform": "^29.5.0", - "@jest/types": "^29.5.0", - "@types/babel__traverse": "^7.0.6", - "@types/prettier": "^2.1.5", + "@jest/expect-utils": "^29.7.0", + "@jest/transform": "^29.7.0", + "@jest/types": "^29.6.3", "babel-preset-current-node-syntax": "^1.0.0", "chalk": "^4.0.0", - "expect": "^29.5.0", + "expect": "^29.7.0", "graceful-fs": "^4.2.9", - "jest-diff": "^29.5.0", - "jest-get-type": "^29.4.3", - "jest-matcher-utils": "^29.5.0", - "jest-message-util": "^29.5.0", - "jest-util": "^29.5.0", + "jest-diff": "^29.7.0", + "jest-get-type": "^29.6.3", + "jest-matcher-utils": "^29.7.0", + "jest-message-util": "^29.7.0", + "jest-util": "^29.7.0", "natural-compare": "^1.4.0", - "pretty-format": "^29.5.0", - "semver": "^7.3.5" + "pretty-format": "^29.7.0", + "semver": "^7.5.3" }, "engines": { "node": "^14.15.0 || ^16.10.0 || >=18.0.0" } }, "node_modules/jest-util": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/jest-util/-/jest-util-29.5.0.tgz", - "integrity": "sha512-RYMgG/MTadOr5t8KdhejfvUU82MxsCu5MF6KuDUHl+NuwzUt+Sm6jJWxTJVrDR1j5M/gJVCPKQEpWXY+yIQ6lQ==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-util/-/jest-util-29.7.0.tgz", + "integrity": "sha512-z6EbKajIpqGKU56y5KBUgy1dt1ihhQJgWzUlZHArA/+X2ad7Cb5iF+AK1EWVL/Bo7Rz9uurpqw6SiBCefUbCGA==", "dev": true, + "license": "MIT", "dependencies": { - "@jest/types": "^29.5.0", + "@jest/types": "^29.6.3", "@types/node": "*", "chalk": "^4.0.0", "ci-info": "^3.2.0", @@ -4892,24 +4953,12 @@ "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", @@ -5031,6 +5080,19 @@ "integrity": "sha512-c98Bf3tPniI+scsdk237ku1Dc3ujXQTSgyiPUDEOe7tRkhrqridvh8klBv0HCEso1OLOYcHuCv/cS6DNxKH+ZA==", "dev": true }, + "node_modules/mime": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-3.0.0.tgz", + "integrity": "sha512-jSCU7/VB1loIWBZe14aEYHU/+1UMEHoaO7qxCOVJOw9GgH72VAWppxNcjU+x9a2k3GSIBXNKxXQFqRvvZ7vr3A==", + "dev": true, + "license": "MIT", + "bin": { + "mime": "cli.js" + }, + "engines": { + "node": ">=10.0.0" + } + }, "node_modules/mime-db": { "version": "1.52.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", @@ -5116,44 +5178,6 @@ "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==", "dev": true }, - "node_modules/node-fetch": { - "version": "2.7.0", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", - "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", - "dependencies": { - "whatwg-url": "^5.0.0" - }, - "engines": { - "node": "4.x || >=6.0.0" - }, - "peerDependencies": { - "encoding": "^0.1.0" - }, - "peerDependenciesMeta": { - "encoding": { - "optional": true - } - } - }, - "node_modules/node-fetch/node_modules/tr46": { - "version": "0.0.3", - "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", - "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" - }, - "node_modules/node-fetch/node_modules/webidl-conversions": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", - "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" - }, - "node_modules/node-fetch/node_modules/whatwg-url": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", - "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", - "dependencies": { - "tr46": "~0.0.3", - "webidl-conversions": "^3.0.0" - } - }, "node_modules/node-int64": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz", @@ -5167,9 +5191,16 @@ "dev": true }, "node_modules/node-tfhe": { - "version": "0.6.3", - "resolved": "https://registry.npmjs.org/node-tfhe/-/node-tfhe-0.6.3.tgz", - "integrity": "sha512-pnPDgBZ8aAPhLOs+LDIZP70dinuRHQxc7BROuXFmtyQu6ysyLIvwfmXVsdoQAap2OBcwg15kcu38b5G8YBpcaA==" + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/node-tfhe/-/node-tfhe-0.8.0.tgz", + "integrity": "sha512-cuH06Wc5BiUQhaI2/RMAi2e9lMaE/hxrqlEKNDPVOtbjHGIUnwzS53CphjNQfsgpucV5ZEp0YxXMtAwbkMas5Q==", + "license": "BSD-3-Clause-Clear" + }, + "node_modules/node-tkms": { + "version": "0.9.0-rc11", + "resolved": "https://registry.npmjs.org/node-tkms/-/node-tkms-0.9.0-rc11.tgz", + "integrity": "sha512-imNY2BgNOZBgSc6N/zwM0biorh12gtP45RT5ejOM8fmz75d/OtokAq2jwLQYeIkXIl8dDKGe8EjtwSpbBr6Y4g==", + "license": "BSD-3-Clause-Clear" }, "node_modules/normalize-path": { "version": "3.0.0", @@ -5333,12 +5364,6 @@ "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", @@ -5436,12 +5461,13 @@ } }, "node_modules/pretty-format": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-29.5.0.tgz", - "integrity": "sha512-V2mGkI31qdttvTFX7Mt4efOqHXqJWMu4/r66Xh3Z3BwZaPfPJgp6/gbwoujRpPUtfEF6AUUWx3Jim3GCw5g/Qw==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-29.7.0.tgz", + "integrity": "sha512-Pdlw/oPxN+aXdmM9R00JVC9WVFoCLTKJvDVLgmJ+qAffBMxsV85l/Lu7sNx4zSzPyoL2euImuEwHhOXdEgNFZQ==", "dev": true, + "license": "MIT", "dependencies": { - "@jest/schemas": "^29.4.3", + "@jest/schemas": "^29.6.3", "ansi-styles": "^5.0.0", "react-is": "^18.0.0" }, @@ -5539,16 +5565,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "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", @@ -5638,11 +5654,14 @@ "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/regexparam": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/regexparam/-/regexparam-3.0.0.tgz", + "integrity": "sha512-RSYAtP31mvYLkAHrOlh25pCNQ5hWnT106VukGaaFfuJrZFkGRX5GhUAdPqpSDXxOhA2c4akmRuplv1mRqnBn6Q==", + "license": "MIT", + "engines": { + "node": ">=8" + } }, "node_modules/require-directory": { "version": "2.1.1", @@ -6253,9 +6272,16 @@ } }, "node_modules/tfhe": { - "version": "0.6.3", - "resolved": "https://registry.npmjs.org/tfhe/-/tfhe-0.6.3.tgz", - "integrity": "sha512-u+GPQ2SfzHsuNnCmJWeh9tImCUING4/6zOJZOqRhQ2+8teH2CHlNx7YGUQJz3z1ITJ6/nUHRy2dyBr/dpa3xWw==" + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/tfhe/-/tfhe-0.8.0.tgz", + "integrity": "sha512-sbgNXmvvjoNC+pOA89rrIGwJkA1ykPWU5zMVpj4RWM9R8Bc32zMLQwxVO8OblZX8QDWD8ZpoBL8bnkKwJLp9YA==", + "license": "BSD-3-Clause-Clear" + }, + "node_modules/tkms": { + "version": "0.9.0-rc11", + "resolved": "https://registry.npmjs.org/tkms/-/tkms-0.9.0-rc11.tgz", + "integrity": "sha512-bbSRgqOFeZpORQGWOGlZVHidGQWtofwuwUdf6LYFJBd9DpbroNPy2o38cNzPIhSUkBzJ5o1JD6nKYaFXxRwKjA==", + "license": "BSD-3-Clause-Clear" }, "node_modules/tmpl": { "version": "1.0.5", @@ -6295,15 +6321,6 @@ "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": { "version": "29.1.0", "resolved": "https://registry.npmjs.org/ts-jest/-/ts-jest-29.1.0.tgz", @@ -6419,6 +6436,13 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/typedescriptor": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/typedescriptor/-/typedescriptor-3.0.2.tgz", + "integrity": "sha512-hyVbaCUd18UiXk656g/imaBLMogpdijIEpnhWYrSda9rhvO4gOU16n2nh7xG5lv/rjumnZzGOdz0CEGTmFe0fQ==", + "dev": true, + "license": "MIT" + }, "node_modules/typescript": { "version": "5.0.4", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.0.4.tgz", @@ -6619,12 +6643,6 @@ "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", @@ -6748,17 +6766,6 @@ "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", @@ -7398,15 +7405,6 @@ "@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", @@ -7459,6 +7457,28 @@ "integrity": "sha512-dBVuXR082gk3jsFp7Rd/JI4kytwGHecnCoTtXFb7DB6CNHp4rg5k1bhg0nWdLGLnOV71lmDzGQaLMy8iPLY0pw==", "dev": true }, + "@fetch-mock/core": { + "version": "0.7.0", + "resolved": "https://registry.npmjs.org/@fetch-mock/core/-/core-0.7.0.tgz", + "integrity": "sha512-8brSKB6bfAjsGpkmzjMqMZ6T4SbH00n9HaurNAhecB6/0dAKVPXnN4A2DolqBqj8PYK7ttKCUs3hVthtQ7J2Cw==", + "dev": true, + "requires": { + "@types/glob-to-regexp": "^0.4.4", + "dequal": "^2.0.3", + "glob-to-regexp": "^0.4.1", + "is-subset-of": "^3.1.10", + "regexparam": "^3.0.0" + } + }, + "@fetch-mock/jest": { + "version": "0.1.0", + "resolved": "https://registry.npmjs.org/@fetch-mock/jest/-/jest-0.1.0.tgz", + "integrity": "sha512-mX9m4MIxQjSXrz1c2+Q8Rj+5mUzSnq7dYlNRSPJLrgaF7Im5mIQJ19xCYxhnVR76RfOPBr08cwO40rWUELBlWg==", + "dev": true, + "requires": { + "@fetch-mock/core": "^0.7.0" + } + }, "@istanbuljs/load-nyc-config": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/@istanbuljs/load-nyc-config/-/load-nyc-config-1.1.0.tgz", @@ -7529,60 +7549,60 @@ } }, "@jest/environment": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/@jest/environment/-/environment-29.5.0.tgz", - "integrity": "sha512-5FXw2+wD29YU1d4I2htpRX7jYnAyTRjP2CsXQdo9SAM8g3ifxWPSV0HnClSn71xwctr0U3oZIIH+dtbfmnbXVQ==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/@jest/environment/-/environment-29.7.0.tgz", + "integrity": "sha512-aQIfHDq33ExsN4jP1NWGXhxgQ/wixs60gDiKO+XVMd8Mn0NWPWgc34ZQDTb2jKaUWQ7MuwoitXAsN2XVXNMpAw==", "dev": true, "requires": { - "@jest/fake-timers": "^29.5.0", - "@jest/types": "^29.5.0", + "@jest/fake-timers": "^29.7.0", + "@jest/types": "^29.6.3", "@types/node": "*", - "jest-mock": "^29.5.0" + "jest-mock": "^29.7.0" } }, "@jest/expect": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/@jest/expect/-/expect-29.5.0.tgz", - "integrity": "sha512-PueDR2HGihN3ciUNGr4uelropW7rqUfTiOn+8u0leg/42UhblPxHkfoh0Ruu3I9Y1962P3u2DY4+h7GVTSVU6g==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/@jest/expect/-/expect-29.7.0.tgz", + "integrity": "sha512-8uMeAMycttpva3P1lBHB8VciS9V0XAr3GymPpipdyQXbBcuhkLQOSe8E/p92RyAdToS6ZD1tFkX+CkhoECE0dQ==", "dev": true, "requires": { - "expect": "^29.5.0", - "jest-snapshot": "^29.5.0" + "expect": "^29.7.0", + "jest-snapshot": "^29.7.0" } }, "@jest/expect-utils": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/@jest/expect-utils/-/expect-utils-29.5.0.tgz", - "integrity": "sha512-fmKzsidoXQT2KwnrwE0SQq3uj8Z763vzR8LnLBwC2qYWEFpjX8daRsk6rHUM1QvNlEW/UJXNXm59ztmJJWs2Mg==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/@jest/expect-utils/-/expect-utils-29.7.0.tgz", + "integrity": "sha512-GlsNBWiFQFCVi9QVSx7f5AgMeLxe9YCCs5PuP2O2LdjDAA8Jh9eX7lA1Jq/xdXw3Wb3hyvlFNfZIfcRetSzYcA==", "dev": true, "requires": { - "jest-get-type": "^29.4.3" + "jest-get-type": "^29.6.3" } }, "@jest/fake-timers": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/@jest/fake-timers/-/fake-timers-29.5.0.tgz", - "integrity": "sha512-9ARvuAAQcBwDAqOnglWq2zwNIRUDtk/SCkp/ToGEhFv5r86K21l+VEs0qNTaXtyiY0lEePl3kylijSYJQqdbDg==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/@jest/fake-timers/-/fake-timers-29.7.0.tgz", + "integrity": "sha512-q4DH1Ha4TTFPdxLsqDXK1d3+ioSL7yL5oCMJZgDYm6i+6CygW5E5xVr/D1HdsGxjt1ZWSfUAs9OxSB/BNelWrQ==", "dev": true, "requires": { - "@jest/types": "^29.5.0", + "@jest/types": "^29.6.3", "@sinonjs/fake-timers": "^10.0.2", "@types/node": "*", - "jest-message-util": "^29.5.0", - "jest-mock": "^29.5.0", - "jest-util": "^29.5.0" + "jest-message-util": "^29.7.0", + "jest-mock": "^29.7.0", + "jest-util": "^29.7.0" } }, "@jest/globals": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/@jest/globals/-/globals-29.5.0.tgz", - "integrity": "sha512-S02y0qMWGihdzNbUiqSAiKSpSozSuHX5UYc7QbnHP+D9Lyw8DgGGCinrN9uSuHPeKgSSzvPom2q1nAtBvUsvPQ==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/@jest/globals/-/globals-29.7.0.tgz", + "integrity": "sha512-mpiz3dutLbkW2MNFubUGUEVLkTGiqW6yLVTA+JbP6fI6J5iL9Y0Nlg8k95pcF8ctKwCS7WVxteBs29hhfAotzQ==", "dev": true, "requires": { - "@jest/environment": "^29.5.0", - "@jest/expect": "^29.5.0", - "@jest/types": "^29.5.0", - "jest-mock": "^29.5.0" + "@jest/environment": "^29.7.0", + "@jest/expect": "^29.7.0", + "@jest/types": "^29.6.3", + "jest-mock": "^29.7.0" } }, "@jest/reporters": { @@ -7632,12 +7652,12 @@ } }, "@jest/schemas": { - "version": "29.4.3", - "resolved": "https://registry.npmjs.org/@jest/schemas/-/schemas-29.4.3.tgz", - "integrity": "sha512-VLYKXQmtmuEz6IxJsrZwzG9NvtkQsWNnWMsKxqWNu3+CnfzJQhp0WDDKWLVV9hLKr0l3SLLFRqcYHjhtyuDVxg==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/@jest/schemas/-/schemas-29.6.3.tgz", + "integrity": "sha512-mo5j5X+jIZmJQveBKeS/clAueipV7KgiX1vMgCxam1RNYiqE1w62n0/tJJnHtjW8ZHcQco5gY85jA3mi0L+nSA==", "dev": true, "requires": { - "@sinclair/typebox": "^0.25.16" + "@sinclair/typebox": "^0.27.8" } }, "@jest/source-map": { @@ -7676,22 +7696,22 @@ } }, "@jest/transform": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/@jest/transform/-/transform-29.5.0.tgz", - "integrity": "sha512-8vbeZWqLJOvHaDfeMuoHITGKSz5qWc9u04lnWrQE3VyuSw604PzQM824ZeX9XSjUCeDiE3GuxZe5UKa8J61NQw==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/@jest/transform/-/transform-29.7.0.tgz", + "integrity": "sha512-ok/BTPFzFKVMwO5eOHRrvnBVHdRy9IrsrW1GpMaQ9MCnilNLXQKmAX8s1YXDFaai9xJpac2ySzV0YeRRECr2Vw==", "dev": true, "requires": { "@babel/core": "^7.11.6", - "@jest/types": "^29.5.0", - "@jridgewell/trace-mapping": "^0.3.15", + "@jest/types": "^29.6.3", + "@jridgewell/trace-mapping": "^0.3.18", "babel-plugin-istanbul": "^6.1.1", "chalk": "^4.0.0", "convert-source-map": "^2.0.0", "fast-json-stable-stringify": "^2.1.0", "graceful-fs": "^4.2.9", - "jest-haste-map": "^29.5.0", - "jest-regex-util": "^29.4.3", - "jest-util": "^29.5.0", + "jest-haste-map": "^29.7.0", + "jest-regex-util": "^29.6.3", + "jest-util": "^29.7.0", "micromatch": "^4.0.4", "pirates": "^4.0.4", "slash": "^3.0.0", @@ -7699,12 +7719,12 @@ } }, "@jest/types": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/@jest/types/-/types-29.5.0.tgz", - "integrity": "sha512-qbu7kN6czmVRc3xWFQcAN03RAUamgppVUdXrvl1Wr3jlNF93o9mJbGcDWrwGB6ht44u7efB1qCFgVQmca24Uog==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/@jest/types/-/types-29.6.3.tgz", + "integrity": "sha512-u3UPsIilWKOM3F9CXtrG8LEJmNxwoCQC/XVj4IKYXvvpx7QIi/Kg1LI5uDmDpKlac62NUtX7eLjRh+jVZcLOzw==", "dev": true, "requires": { - "@jest/schemas": "^29.4.3", + "@jest/schemas": "^29.6.3", "@types/istanbul-lib-coverage": "^2.0.0", "@types/istanbul-reports": "^3.0.0", "@types/node": "*", @@ -7883,6 +7903,15 @@ "magic-string": "^0.27.0" } }, + "@rollup/plugin-json": { + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/@rollup/plugin-json/-/plugin-json-6.1.0.tgz", + "integrity": "sha512-EGI2te5ENk1coGeADSIwZ7G2Q8CJS2sF120T7jLw4xFw9n7wIOXHo+kIYRAoVpJAN+kmqZSoO3Fp4JtoNF4ReA==", + "dev": true, + "requires": { + "@rollup/pluginutils": "^5.1.0" + } + }, "@rollup/plugin-node-resolve": { "version": "15.1.0", "resolved": "https://registry.npmjs.org/@rollup/plugin-node-resolve/-/plugin-node-resolve-15.1.0.tgz", @@ -7917,6 +7946,17 @@ "resolve": "^1.22.1" } }, + "@rollup/plugin-url": { + "version": "8.0.2", + "resolved": "https://registry.npmjs.org/@rollup/plugin-url/-/plugin-url-8.0.2.tgz", + "integrity": "sha512-5yW2LP5NBEgkvIRSSEdJkmxe5cUNZKG3eenKtfJvSkxVm/xTTu7w+ayBtNwhozl1ZnTUCU0xFaRQR+cBl2H7TQ==", + "dev": true, + "requires": { + "@rollup/pluginutils": "^5.0.1", + "make-dir": "^3.1.0", + "mime": "^3.0.0" + } + }, "@rollup/plugin-wasm": { "version": "6.1.3", "resolved": "https://registry.npmjs.org/@rollup/plugin-wasm/-/plugin-wasm-6.1.3.tgz", @@ -7925,9 +7965,9 @@ "requires": {} }, "@rollup/pluginutils": { - "version": "5.0.2", - "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.0.2.tgz", - "integrity": "sha512-pTd9rIsP92h+B6wWwFbW8RkZv4hiR/xKsqre4SIuAOaOEQRxi0lqLke9k2/7WegC85GgUs9pjmOjCUi3In4vwA==", + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.1.2.tgz", + "integrity": "sha512-/FIdS3PyZ39bjZlwqFnWqCOVnW7o963LtKMwQOD0NhQqw22gSr2YY1afu3FxRip4ZCZNsD5jq6Aaz6QV3D/Njw==", "dev": true, "requires": { "@types/estree": "^1.0.0", @@ -7974,9 +8014,9 @@ } }, "@sinclair/typebox": { - "version": "0.25.24", - "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.25.24.tgz", - "integrity": "sha512-XJfwUVUKDHF5ugKwIcxEgc9k8b7HbznCp6eUfWgu710hMPNIO4aw4/zB5RogDQz8nd6gyCDpU9O/m6qYEWY6yQ==", + "version": "0.27.8", + "resolved": "https://registry.npmjs.org/@sinclair/typebox/-/typebox-0.27.8.tgz", + "integrity": "sha512-+Fj43pSMwJs4KRrH/938Uf+uAELIgVBmQzg/q1YG10djyfA3TnrU8N8XzqCh/okZdszqBQTZf96idMfE5lnwTA==", "dev": true }, "@sinonjs/commons": { @@ -8083,6 +8123,11 @@ "@types/node": "*" } }, + "@types/glob-to-regexp": { + "version": "0.4.4", + "resolved": "https://registry.npmjs.org/@types/glob-to-regexp/-/glob-to-regexp-0.4.4.tgz", + "integrity": "sha512-nDKoaKJYbnn1MZxUY0cA1bPmmgZbg0cTq7Rh13d0KWYNOiKbqoR+2d89SnRPszGh7ROzSwZ/GOjZ4jPbmmZ6Eg==" + }, "@types/graceful-fs": { "version": "4.1.6", "resolved": "https://registry.npmjs.org/@types/graceful-fs/-/graceful-fs-4.1.6.tgz", @@ -8161,12 +8206,6 @@ "form-data": "^4.0.0" } }, - "@types/prettier": { - "version": "2.7.2", - "resolved": "https://registry.npmjs.org/@types/prettier/-/prettier-2.7.2.tgz", - "integrity": "sha512-KufADq8uQqo1pYKVIYzfKbJfBAc0sOeXqGbFaSpv8MRmC/zXgowNZmFcbngndGk922QDmOASEXUZCaY48gs4cg==", - "dev": true - }, "@types/resolve": { "version": "1.20.2", "resolved": "https://registry.npmjs.org/@types/resolve/-/resolve-1.20.2.tgz", @@ -8955,12 +8994,6 @@ "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", @@ -9073,6 +9106,11 @@ "integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==", "dev": true }, + "dequal": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/dequal/-/dequal-2.0.3.tgz", + "integrity": "sha512-0je+qPKHEMohvfRTCEo3CrPG6cAzAYgmzKyxRiYSSDkS6eGJdyVJm7WaYA5ECaAD9wLB2T4EEeymA5aFVcYXCA==" + }, "des.js": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/des.js/-/des.js-1.0.1.tgz", @@ -9090,9 +9128,9 @@ "dev": true }, "diff-sequences": { - "version": "29.4.3", - "resolved": "https://registry.npmjs.org/diff-sequences/-/diff-sequences-29.4.3.tgz", - "integrity": "sha512-ofrBgwpPhCD85kMKtE9RYFFq6OC1A89oW2vvgWZNCwxrUpRUILopY7lsYyMDSjc8g6U6aiO0Qubg6r4Wgt5ZnA==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/diff-sequences/-/diff-sequences-29.6.3.tgz", + "integrity": "sha512-EjePK1srD3P08o2j4f0ExnylqRs5B9tJjcp9t1krH2qRi8CCdsYfwe9JgSLurFBWwq4uOlipzfk5fHNvwFKr8Q==", "dev": true }, "diffie-hellman": { @@ -9373,16 +9411,16 @@ "dev": true }, "expect": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/expect/-/expect-29.5.0.tgz", - "integrity": "sha512-yM7xqUrCO2JdpFo4XpM82t+PJBFybdqoQuJLDGeDX2ij8NZzqRHyu3Hp188/JX7SWqud+7t4MUdvcgGBICMHZg==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/expect/-/expect-29.7.0.tgz", + "integrity": "sha512-2Zks0hf1VLFYI1kbh0I5jP3KHHyCHpkfyHBzsSXRFgl/Bg9mWYfMW8oD+PdMPlEwy5HNsR9JutYy6pMeOh61nw==", "dev": true, "requires": { - "@jest/expect-utils": "^29.5.0", - "jest-get-type": "^29.4.3", - "jest-matcher-utils": "^29.5.0", - "jest-message-util": "^29.5.0", - "jest-util": "^29.5.0" + "@jest/expect-utils": "^29.7.0", + "jest-get-type": "^29.6.3", + "jest-matcher-utils": "^29.7.0", + "jest-message-util": "^29.7.0", + "jest-util": "^29.7.0" } }, "fast-deep-equal": { @@ -9435,30 +9473,15 @@ } }, "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, + "version": "11.1.3", + "resolved": "https://registry.npmjs.org/fetch-mock/-/fetch-mock-11.1.3.tgz", + "integrity": "sha512-ATh0dWgnVrUHiiXuvQm1Ry+ThWfSv1QQgqJTCtybrNxyUrFiSOaDKsNG29eyysp1SHeNP6Q+dH50+8VifN51Ig==", "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", + "@types/glob-to-regexp": "^0.4.4", + "dequal": "^2.0.3", + "glob-to-regexp": "^0.4.1", "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" + "regexparam": "^3.0.0" } }, "file-uri-to-path": { @@ -9604,8 +9627,7 @@ "glob-to-regexp": { "version": "0.4.1", "resolved": "https://registry.npmjs.org/glob-to-regexp/-/glob-to-regexp-0.4.1.tgz", - "integrity": "sha512-lkX1HJXwyMcprw/5YUZc2s7DrpAiHB21/V+E1rHUrVNokkvB6bqMzT0VfV6/86ZNabt1k14YOIaT7nDvOX3Iiw==", - "dev": true + "integrity": "sha512-lkX1HJXwyMcprw/5YUZc2s7DrpAiHB21/V+E1rHUrVNokkvB6bqMzT0VfV6/86ZNabt1k14YOIaT7nDvOX3Iiw==" }, "globals": { "version": "11.12.0", @@ -9915,8 +9937,16 @@ "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 + "integrity": "sha512-6Ybun0IkarhmEqxXCNw/C0bna6Zb/TkfUX9UbwJtK6ObwAVCxmAP308WWTHviM/zAqXk05cdhYsUsZeGQh99iw==" + }, + "is-subset-of": { + "version": "3.1.10", + "resolved": "https://registry.npmjs.org/is-subset-of/-/is-subset-of-3.1.10.tgz", + "integrity": "sha512-avvaYgVmYWyaZ1NDFiv4y9JGkrE2je3op1Po4VYKKJKR8H2qVPsg1GZuuXl5elCTxTlwAIsrAjWAs4BVrISFRw==", + "dev": true, + "requires": { + "typedescriptor": "3.0.2" + } }, "is-typed-array": { "version": "1.1.13", @@ -10131,15 +10161,15 @@ } }, "jest-diff": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/jest-diff/-/jest-diff-29.5.0.tgz", - "integrity": "sha512-LtxijLLZBduXnHSniy0WMdaHjmQnt3g5sa16W4p0HqukYTTsyTW3GD1q41TyGl5YFXj/5B2U6dlh5FM1LIMgxw==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-diff/-/jest-diff-29.7.0.tgz", + "integrity": "sha512-LMIgiIrhigmPrs03JHpxUh2yISK3vLFPkAodPeo0+BuF7wA2FoQbkEg1u8gBYBThncu7e1oEDUfIXVuTqLRUjw==", "dev": true, "requires": { "chalk": "^4.0.0", - "diff-sequences": "^29.4.3", - "jest-get-type": "^29.4.3", - "pretty-format": "^29.5.0" + "diff-sequences": "^29.6.3", + "jest-get-type": "^29.6.3", + "pretty-format": "^29.7.0" } }, "jest-docblock": { @@ -10179,39 +10209,39 @@ } }, "jest-get-type": { - "version": "29.4.3", - "resolved": "https://registry.npmjs.org/jest-get-type/-/jest-get-type-29.4.3.tgz", - "integrity": "sha512-J5Xez4nRRMjk8emnTpWrlkyb9pfRQQanDrvWHhsR1+VUfbwxi30eVcZFlcdGInRibU4G5LwHXpI7IRHU0CY+gg==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/jest-get-type/-/jest-get-type-29.6.3.tgz", + "integrity": "sha512-zrteXnqYxfQh7l5FHyL38jL39di8H8rHoecLH3JNxH3BwOrBsNeabdap5e0I23lD4HHI8W5VFBZqG4Eaq5LNcw==", "dev": true }, "jest-haste-map": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/jest-haste-map/-/jest-haste-map-29.5.0.tgz", - "integrity": "sha512-IspOPnnBro8YfVYSw6yDRKh/TiCdRngjxeacCps1cQ9cgVN6+10JUcuJ1EabrgYLOATsIAigxA0rLR9x/YlrSA==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-haste-map/-/jest-haste-map-29.7.0.tgz", + "integrity": "sha512-fP8u2pyfqx0K1rGn1R9pyE0/KTn+G7PxktWidOBTqFPLYX0b9ksaMFkhK5vrS3DVun09pckLdlx90QthlW7AmA==", "dev": true, "requires": { - "@jest/types": "^29.5.0", + "@jest/types": "^29.6.3", "@types/graceful-fs": "^4.1.3", "@types/node": "*", "anymatch": "^3.0.3", "fb-watchman": "^2.0.0", "fsevents": "^2.3.2", "graceful-fs": "^4.2.9", - "jest-regex-util": "^29.4.3", - "jest-util": "^29.5.0", - "jest-worker": "^29.5.0", + "jest-regex-util": "^29.6.3", + "jest-util": "^29.7.0", + "jest-worker": "^29.7.0", "micromatch": "^4.0.4", "walker": "^1.0.8" }, "dependencies": { "jest-worker": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/jest-worker/-/jest-worker-29.5.0.tgz", - "integrity": "sha512-NcrQnevGoSp4b5kg+akIpthoAFHxPBcb5P6mYPY0fUNT+sSvmtu6jlkEle3anczUKIKEbMxFimk9oTP/tpIPgA==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-worker/-/jest-worker-29.7.0.tgz", + "integrity": "sha512-eIz2msL/EzL9UFTFFx7jBTkeZfku0yUAyZZZmJ93H2TYEiroIx2PQjEXcwYtYl8zXCxb+PAmA2hLIt/6ZEkPHw==", "dev": true, "requires": { "@types/node": "*", - "jest-util": "^29.5.0", + "jest-util": "^29.7.0", "merge-stream": "^2.0.0", "supports-color": "^8.0.0" } @@ -10229,43 +10259,43 @@ } }, "jest-matcher-utils": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/jest-matcher-utils/-/jest-matcher-utils-29.5.0.tgz", - "integrity": "sha512-lecRtgm/rjIK0CQ7LPQwzCs2VwW6WAahA55YBuI+xqmhm7LAaxokSB8C97yJeYyT+HvQkH741StzpU41wohhWw==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-matcher-utils/-/jest-matcher-utils-29.7.0.tgz", + "integrity": "sha512-sBkD+Xi9DtcChsI3L3u0+N0opgPYnCRPtGcQYrgXmR+hmt/fYfWAL0xRXYU8eWOdfuLgBe0YCW3AFtnRLagq/g==", "dev": true, "requires": { "chalk": "^4.0.0", - "jest-diff": "^29.5.0", - "jest-get-type": "^29.4.3", - "pretty-format": "^29.5.0" + "jest-diff": "^29.7.0", + "jest-get-type": "^29.6.3", + "pretty-format": "^29.7.0" } }, "jest-message-util": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/jest-message-util/-/jest-message-util-29.5.0.tgz", - "integrity": "sha512-Kijeg9Dag6CKtIDA7O21zNTACqD5MD/8HfIV8pdD94vFyFuer52SigdC3IQMhab3vACxXMiFk+yMHNdbqtyTGA==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-message-util/-/jest-message-util-29.7.0.tgz", + "integrity": "sha512-GBEV4GRADeP+qtB2+6u61stea8mGcOT4mCtrYISZwfu9/ISHFJ/5zOMXYbpBE9RsS5+Gb63DW4FgmnKJ79Kf6w==", "dev": true, "requires": { "@babel/code-frame": "^7.12.13", - "@jest/types": "^29.5.0", + "@jest/types": "^29.6.3", "@types/stack-utils": "^2.0.0", "chalk": "^4.0.0", "graceful-fs": "^4.2.9", "micromatch": "^4.0.4", - "pretty-format": "^29.5.0", + "pretty-format": "^29.7.0", "slash": "^3.0.0", "stack-utils": "^2.0.3" } }, "jest-mock": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/jest-mock/-/jest-mock-29.5.0.tgz", - "integrity": "sha512-GqOzvdWDE4fAV2bWQLQCkujxYWL7RxjCnj71b5VhDAGOevB3qj3Ovg26A5NI84ZpODxyzaozXLOh2NCgkbvyaw==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-mock/-/jest-mock-29.7.0.tgz", + "integrity": "sha512-ITOMZn+UkYS4ZFh83xYAOzWStloNzJFO2s8DWrE4lhtGD+AorgnbkiKERe4wQVBydIGPx059g6riW5Btp6Llnw==", "dev": true, "requires": { - "@jest/types": "^29.5.0", + "@jest/types": "^29.6.3", "@types/node": "*", - "jest-util": "^29.5.0" + "jest-util": "^29.7.0" } }, "jest-pnp-resolver": { @@ -10282,9 +10312,9 @@ "dev": true }, "jest-regex-util": { - "version": "29.4.3", - "resolved": "https://registry.npmjs.org/jest-regex-util/-/jest-regex-util-29.4.3.tgz", - "integrity": "sha512-O4FglZaMmWXbGHSQInfXewIsd1LMn9p3ZXB/6r4FOkyhX2/iP/soMG98jGvk/A3HAN78+5VWcBGO0BJAPRh4kg==", + "version": "29.6.3", + "resolved": "https://registry.npmjs.org/jest-regex-util/-/jest-regex-util-29.6.3.tgz", + "integrity": "sha512-KJJBsRCyyLNWCNBOvZyRDnAIfUiRJ8v+hOBQYGn8gDyF3UegwiP4gwRR3/SDa42g1YbVycTidUF3rKjyLFDWbg==", "dev": true }, "jest-resolve": { @@ -10407,43 +10437,40 @@ } }, "jest-snapshot": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/jest-snapshot/-/jest-snapshot-29.5.0.tgz", - "integrity": "sha512-x7Wolra5V0tt3wRs3/ts3S6ciSQVypgGQlJpz2rsdQYoUKxMxPNaoHMGJN6qAuPJqS+2iQ1ZUn5kl7HCyls84g==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-snapshot/-/jest-snapshot-29.7.0.tgz", + "integrity": "sha512-Rm0BMWtxBcioHr1/OX5YCP8Uov4riHvKPknOGs804Zg9JGZgmIBkbtlxJC/7Z4msKYVbIJtfU+tKb8xlYNfdkw==", "dev": true, "requires": { "@babel/core": "^7.11.6", "@babel/generator": "^7.7.2", "@babel/plugin-syntax-jsx": "^7.7.2", "@babel/plugin-syntax-typescript": "^7.7.2", - "@babel/traverse": "^7.7.2", "@babel/types": "^7.3.3", - "@jest/expect-utils": "^29.5.0", - "@jest/transform": "^29.5.0", - "@jest/types": "^29.5.0", - "@types/babel__traverse": "^7.0.6", - "@types/prettier": "^2.1.5", + "@jest/expect-utils": "^29.7.0", + "@jest/transform": "^29.7.0", + "@jest/types": "^29.6.3", "babel-preset-current-node-syntax": "^1.0.0", "chalk": "^4.0.0", - "expect": "^29.5.0", + "expect": "^29.7.0", "graceful-fs": "^4.2.9", - "jest-diff": "^29.5.0", - "jest-get-type": "^29.4.3", - "jest-matcher-utils": "^29.5.0", - "jest-message-util": "^29.5.0", - "jest-util": "^29.5.0", + "jest-diff": "^29.7.0", + "jest-get-type": "^29.6.3", + "jest-matcher-utils": "^29.7.0", + "jest-message-util": "^29.7.0", + "jest-util": "^29.7.0", "natural-compare": "^1.4.0", - "pretty-format": "^29.5.0", - "semver": "^7.3.5" + "pretty-format": "^29.7.0", + "semver": "^7.5.3" } }, "jest-util": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/jest-util/-/jest-util-29.5.0.tgz", - "integrity": "sha512-RYMgG/MTadOr5t8KdhejfvUU82MxsCu5MF6KuDUHl+NuwzUt+Sm6jJWxTJVrDR1j5M/gJVCPKQEpWXY+yIQ6lQ==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/jest-util/-/jest-util-29.7.0.tgz", + "integrity": "sha512-z6EbKajIpqGKU56y5KBUgy1dt1ihhQJgWzUlZHArA/+X2ad7Cb5iF+AK1EWVL/Bo7Rz9uurpqw6SiBCefUbCGA==", "dev": true, "requires": { - "@jest/types": "^29.5.0", + "@jest/types": "^29.6.3", "@types/node": "*", "chalk": "^4.0.0", "ci-info": "^3.2.0", @@ -10599,24 +10626,12 @@ "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", @@ -10718,6 +10733,12 @@ } } }, + "mime": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/mime/-/mime-3.0.0.tgz", + "integrity": "sha512-jSCU7/VB1loIWBZe14aEYHU/+1UMEHoaO7qxCOVJOw9GgH72VAWppxNcjU+x9a2k3GSIBXNKxXQFqRvvZ7vr3A==", + "dev": true + }, "mime-db": { "version": "1.52.0", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz", @@ -10784,35 +10805,6 @@ "integrity": "sha512-Yd3UES5mWCSqR+qNT93S3UoYUkqAZ9lLg8a7g9rimsWmYGK8cVToA4/sF3RrshdyV3sAGMXVUmpMYOw+dLpOuw==", "dev": true }, - "node-fetch": { - "version": "2.7.0", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", - "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", - "requires": { - "whatwg-url": "^5.0.0" - }, - "dependencies": { - "tr46": { - "version": "0.0.3", - "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", - "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" - }, - "webidl-conversions": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", - "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" - }, - "whatwg-url": { - "version": "5.0.0", - "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", - "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", - "requires": { - "tr46": "~0.0.3", - "webidl-conversions": "^3.0.0" - } - } - } - }, "node-int64": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz", @@ -10826,9 +10818,14 @@ "dev": true }, "node-tfhe": { - "version": "0.6.3", - "resolved": "https://registry.npmjs.org/node-tfhe/-/node-tfhe-0.6.3.tgz", - "integrity": "sha512-pnPDgBZ8aAPhLOs+LDIZP70dinuRHQxc7BROuXFmtyQu6ysyLIvwfmXVsdoQAap2OBcwg15kcu38b5G8YBpcaA==" + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/node-tfhe/-/node-tfhe-0.8.0.tgz", + "integrity": "sha512-cuH06Wc5BiUQhaI2/RMAi2e9lMaE/hxrqlEKNDPVOtbjHGIUnwzS53CphjNQfsgpucV5ZEp0YxXMtAwbkMas5Q==" + }, + "node-tkms": { + "version": "0.9.0-rc11", + "resolved": "https://registry.npmjs.org/node-tkms/-/node-tkms-0.9.0-rc11.tgz", + "integrity": "sha512-imNY2BgNOZBgSc6N/zwM0biorh12gtP45RT5ejOM8fmz75d/OtokAq2jwLQYeIkXIl8dDKGe8EjtwSpbBr6Y4g==" }, "normalize-path": { "version": "3.0.0", @@ -10947,12 +10944,6 @@ "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", @@ -11020,12 +11011,12 @@ "dev": true }, "pretty-format": { - "version": "29.5.0", - "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-29.5.0.tgz", - "integrity": "sha512-V2mGkI31qdttvTFX7Mt4efOqHXqJWMu4/r66Xh3Z3BwZaPfPJgp6/gbwoujRpPUtfEF6AUUWx3Jim3GCw5g/Qw==", + "version": "29.7.0", + "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-29.7.0.tgz", + "integrity": "sha512-Pdlw/oPxN+aXdmM9R00JVC9WVFoCLTKJvDVLgmJ+qAffBMxsV85l/Lu7sNx4zSzPyoL2euImuEwHhOXdEgNFZQ==", "dev": true, "requires": { - "@jest/schemas": "^29.4.3", + "@jest/schemas": "^29.6.3", "ansi-styles": "^5.0.0", "react-is": "^18.0.0" }, @@ -11096,12 +11087,6 @@ "side-channel": "^1.0.6" } }, - "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", @@ -11168,11 +11153,10 @@ "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 + "regexparam": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/regexparam/-/regexparam-3.0.0.tgz", + "integrity": "sha512-RSYAtP31mvYLkAHrOlh25pCNQ5hWnT106VukGaaFfuJrZFkGRX5GhUAdPqpSDXxOhA2c4akmRuplv1mRqnBn6Q==" }, "require-directory": { "version": "2.1.1", @@ -11609,9 +11593,14 @@ } }, "tfhe": { - "version": "0.6.3", - "resolved": "https://registry.npmjs.org/tfhe/-/tfhe-0.6.3.tgz", - "integrity": "sha512-u+GPQ2SfzHsuNnCmJWeh9tImCUING4/6zOJZOqRhQ2+8teH2CHlNx7YGUQJz3z1ITJ6/nUHRy2dyBr/dpa3xWw==" + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/tfhe/-/tfhe-0.8.0.tgz", + "integrity": "sha512-sbgNXmvvjoNC+pOA89rrIGwJkA1ykPWU5zMVpj4RWM9R8Bc32zMLQwxVO8OblZX8QDWD8ZpoBL8bnkKwJLp9YA==" + }, + "tkms": { + "version": "0.9.0-rc11", + "resolved": "https://registry.npmjs.org/tkms/-/tkms-0.9.0-rc11.tgz", + "integrity": "sha512-bbSRgqOFeZpORQGWOGlZVHidGQWtofwuwUdf6LYFJBd9DpbroNPy2o38cNzPIhSUkBzJ5o1JD6nKYaFXxRwKjA==" }, "tmpl": { "version": "1.0.5", @@ -11645,15 +11634,6 @@ "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", @@ -11722,6 +11702,12 @@ "integrity": "sha512-t0rzBq87m3fVcduHDUFhKmyyX+9eo6WQjZvf51Ea/M0Q7+T374Jp1aUiyUl0GKxp8M/OETVHSDvmkyPgvX+X2w==", "dev": true }, + "typedescriptor": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/typedescriptor/-/typedescriptor-3.0.2.tgz", + "integrity": "sha512-hyVbaCUd18UiXk656g/imaBLMogpdijIEpnhWYrSda9rhvO4gOU16n2nh7xG5lv/rjumnZzGOdz0CEGTmFe0fQ==", + "dev": true + }, "typescript": { "version": "5.0.4", "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.0.4.tgz", @@ -11862,12 +11848,6 @@ "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", @@ -11945,17 +11925,6 @@ "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", diff --git a/package.json b/package.json index c299912..9e632f1 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ }, "scripts": { "lint": "eslint src/", + "generateKeys": "./generateKeys.js", "build": "npm run build:lib && npm run build:bundle", "build:lib": "rollup -c config/rollup.config.js", "build:bundle": "webpack --mode=production --config config/webpack.config.cjs", @@ -48,26 +49,31 @@ "@types/keccak": "^3.0.4", "bigint-buffer": "^1.1.5", "commander": "^11.0.0", - "node-fetch": "^2.7.0", - "node-tfhe": "^0.6.3", + "fetch-mock": "^11.1.3", + "node-tfhe": "^0.8.0", + "node-tkms": "^0.9.0-rc11", "sha3": "^2.1.4", - "tfhe": "^0.6.3", + "tfhe": "^0.8.0", + "tkms": "^0.9.0-rc11", "url": "^0.11.3", "web3-validator": "^2.0.6" }, "devDependencies": { + "@fetch-mock/jest": "^0.1.0", + "@jest/globals": "^29.7.0", "@rollup/plugin-alias": "^5.1.0", "@rollup/plugin-commonjs": "^25.0.0", + "@rollup/plugin-json": "^6.1.0", "@rollup/plugin-node-resolve": "^15.1.0", "@rollup/plugin-replace": "^5.0.2", "@rollup/plugin-typescript": "^11.1.1", + "@rollup/plugin-url": "^8.0.2", "@rollup/plugin-wasm": "^6.1.3", "@types/jest": "^29.5.1", "@types/node-fetch": "^2.6.11", "buffer": "^6.0.3", "crypto-browserify": "^3.12.0", "ethers": "^6.13.1", - "fetch-mock-jest": "^1.5.1", "jest": "^29.5.0", "jest-raw-loader": "^1.0.1", "path-browserify": "^1.0.1", diff --git a/setupJest.cjs b/setupJest.cjs new file mode 100644 index 0000000..228e9f7 --- /dev/null +++ b/setupJest.cjs @@ -0,0 +1,3 @@ +const fetchMock = require('@fetch-mock/core'); + +global.fetch = fetchMock.default.fetchHandler; diff --git a/src/abi/kmsVerifier.json b/src/abi/kmsVerifier.json new file mode 100644 index 0000000..5f80594 --- /dev/null +++ b/src/abi/kmsVerifier.json @@ -0,0 +1,496 @@ +{ + "abi": [ + { + "inputs": [], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "target", + "type": "address" + } + ], + "name": "AddressEmptyCode", + "type": "error" + }, + { + "inputs": [], + "name": "ECDSAInvalidSignature", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "length", + "type": "uint256" + } + ], + "name": "ECDSAInvalidSignatureLength", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "s", + "type": "bytes32" + } + ], + "name": "ECDSAInvalidSignatureS", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "implementation", + "type": "address" + } + ], + "name": "ERC1967InvalidImplementation", + "type": "error" + }, + { + "inputs": [], + "name": "ERC1967NonPayable", + "type": "error" + }, + { + "inputs": [], + "name": "FailedInnerCall", + "type": "error" + }, + { + "inputs": [], + "name": "InvalidInitialization", + "type": "error" + }, + { + "inputs": [], + "name": "NotInitializing", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + } + ], + "name": "OwnableInvalidOwner", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "OwnableUnauthorizedAccount", + "type": "error" + }, + { + "inputs": [], + "name": "UUPSUnauthorizedCallContext", + "type": "error" + }, + { + "inputs": [ + { + "internalType": "bytes32", + "name": "slot", + "type": "bytes32" + } + ], + "name": "UUPSUnsupportedProxiableUUID", + "type": "error" + }, + { + "anonymous": false, + "inputs": [], + "name": "EIP712DomainChanged", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": false, + "internalType": "uint64", + "name": "version", + "type": "uint64" + } + ], + "name": "Initialized", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "previousOwner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "OwnershipTransferStarted", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "previousOwner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "OwnershipTransferred", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "signer", + "type": "address" + } + ], + "name": "SignerAdded", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "signer", + "type": "address" + } + ], + "name": "SignerRemoved", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "implementation", + "type": "address" + } + ], + "name": "Upgraded", + "type": "event" + }, + { + "inputs": [], + "name": "UPGRADE_INTERFACE_VERSION", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "acceptOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "signer", + "type": "address" + } + ], + "name": "addSigner", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "eip712Domain", + "outputs": [ + { + "internalType": "bytes1", + "name": "fields", + "type": "bytes1" + }, + { + "internalType": "string", + "name": "name", + "type": "string" + }, + { + "internalType": "string", + "name": "version", + "type": "string" + }, + { + "internalType": "uint256", + "name": "chainId", + "type": "uint256" + }, + { + "internalType": "address", + "name": "verifyingContract", + "type": "address" + }, + { + "internalType": "bytes32", + "name": "salt", + "type": "bytes32" + }, + { + "internalType": "uint256[]", + "name": "extensions", + "type": "uint256[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getSigners", + "outputs": [ + { + "internalType": "address[]", + "name": "", + "type": "address[]" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getThreshold", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "getVersion", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "pure", + "type": "function" + }, + { + "inputs": [], + "name": "get_DECRYPTIONRESULT_TYPE", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "initialOwner", + "type": "address" + } + ], + "name": "initialize", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "isSigner", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "owner", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "pendingOwner", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "proxiableUUID", + "outputs": [ + { + "internalType": "bytes32", + "name": "", + "type": "bytes32" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "signer", + "type": "address" + } + ], + "name": "removeSigner", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "renounceOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newOwner", + "type": "address" + } + ], + "name": "transferOwnership", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "newImplementation", + "type": "address" + }, + { + "internalType": "bytes", + "name": "data", + "type": "bytes" + } + ], + "name": "upgradeToAndCall", + "outputs": [], + "stateMutability": "payable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "aclAddress", + "type": "address" + }, + { + "internalType": "uint256[]", + "name": "handlesList", + "type": "uint256[]" + }, + { + "internalType": "bytes", + "name": "decryptedResult", + "type": "bytes" + }, + { + "internalType": "bytes[]", + "name": "signatures", + "type": "bytes[]" + } + ], + "name": "verifySignatures", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + } + ] +} diff --git a/src/ethCall.test.ts b/src/ethCall.test.ts deleted file mode 100644 index 7cbbf42..0000000 --- a/src/ethCall.test.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { decodeAbiBytes } from './ethCall'; - -describe('decrypt', () => { - let clientKeySer: Uint8Array; - - it('converts a hex to bytes', async () => { - const value = '0xff'; - const bytes = decodeAbiBytes(value); - expect(bytes).toEqual(new Uint8Array([255])); - - const value2 = '0x00'; - const bytes2 = decodeAbiBytes(value2); - expect(bytes2).toEqual(new Uint8Array([])); - - const value3 = '0xf0f0'; - const bytes3 = decodeAbiBytes(value3); - expect(bytes3).toEqual(new Uint8Array([240, 240])); - }); -}); diff --git a/src/ethCall.ts b/src/ethCall.ts deleted file mode 100644 index 874c1c6..0000000 --- a/src/ethCall.ts +++ /dev/null @@ -1,48 +0,0 @@ -/* istanbul ignore file */ -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; - if (typeof hexResult == 'object') { - return hexResult; - } - const decodedBytes = decodeAbiBytes(hexResult); - return `0x${toHexString(decodedBytes)}`; - } else { - throw new Error('No result from blockchain call'); - } - } catch (error) { - throw new Error('Error performing eth_call'); - } -}; diff --git a/src/global.d.ts b/src/global.d.ts new file mode 100644 index 0000000..3c05147 --- /dev/null +++ b/src/global.d.ts @@ -0,0 +1,4 @@ +declare module '*.bin' { + var data: Uint8Array; + export default data; +} diff --git a/src/init.ts b/src/init.ts index 63d63d3..6fd4693 100644 --- a/src/init.ts +++ b/src/init.ts @@ -1,8 +1,8 @@ import initTFHE, { InitInput as TFHEInput } from 'tfhe'; import wasmTFHE from 'tfhe/tfhe_bg.wasm'; -import initKMS, { InitInput as KMSInput } from './kms/web/kms_lib.js'; -import wasmKMS from './kms/web/kms_lib_bg.wasm'; +import initKMS, { InitInput as KMSInput } from 'tkms'; +import wasmKMS from 'tkms/kms_lib_bg.wasm'; let initialized = false; diff --git a/src/kms/node/index.js b/src/kms/node/index.js deleted file mode 100644 index 9a4cd55..0000000 --- a/src/kms/node/index.js +++ /dev/null @@ -1 +0,0 @@ -export * from './kms_lib'; diff --git a/src/kms/node/kms_lib.d.ts b/src/kms/node/kms_lib.d.ts deleted file mode 100644 index ef6e57d..0000000 --- a/src/kms/node/kms_lib.d.ts +++ /dev/null @@ -1,433 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -/** -* @param {PublicSigKey} pk -* @returns {Uint8Array} -*/ -export function public_sig_key_to_u8vec(pk: PublicSigKey): Uint8Array; -/** -* @param {Uint8Array} v -* @returns {PublicSigKey} -*/ -export function u8vec_to_public_sig_key(v: Uint8Array): PublicSigKey; -/** -* @param {PrivateSigKey} sk -* @returns {Uint8Array} -*/ -export function private_sig_key_to_u8vec(sk: PrivateSigKey): Uint8Array; -/** -* @param {Uint8Array} v -* @returns {PrivateSigKey} -*/ -export function u8vec_to_private_sig_key(v: Uint8Array): PrivateSigKey; -/** -* Instantiate a new client for use with the centralized KMS. -* @returns {Client} -*/ -export function default_client_for_centralized_kms(): Client; -/** -* Instantiate a new client. -* -* * `server_pks` - a list of KMS server signature public keys, -* which can parsed using [u8vec_to_public_sig_key]. -* -* * `server_pks_ids` - a list of the IDs that are associated to the -* server public keys. If None is given, then the IDs default to -* 1..n, where n is the length of `server_pks`. -* -* * `client_pk` - the client (wallet) public key, -* which can parsed using [u8vec_to_public_sig_key] also. -* -* * `shares_needed` - number of shares needed for reconstruction. -* In the centralized setting this is 1. -* -* * `param_choice` - the parameter choice, which can be either `"test"` or `"default"`. -* The "default" parameter choice is selected if no matching string is found. -* @param {(PublicSigKey)[]} server_pks -* @param {Uint8Array | undefined} server_pks_ids -* @param {PublicSigKey} client_pk -* @param {number} shares_needed -* @param {string} param_choice -* @returns {Client} -*/ -export function new_client(server_pks: (PublicSigKey)[], server_pks_ids: Uint8Array | undefined, client_pk: PublicSigKey, shares_needed: number, param_choice: string): Client; -/** -* @param {Client} client -* @returns {(PublicSigKey)[]} -*/ -export function get_server_public_keys(client: Client): (PublicSigKey)[]; -/** -* @param {Client} client -* @returns {PublicSigKey} -*/ -export function get_client_public_key(client: Client): PublicSigKey; -/** -* @param {Client} client -* @returns {PrivateSigKey | undefined} -*/ -export function get_client_secret_key(client: Client): PrivateSigKey | undefined; -/** -* @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; -/** -* @param {string} name -* @param {string} version -* @param {Uint8Array} chain_id -* @param {string} verifying_contract -* @param {Uint8Array} salt -* @returns {Eip712DomainMsg} -*/ -export function new_eip712_domain(name: string, version: string, chain_id: Uint8Array, verifying_contract: string, salt: Uint8Array): Eip712DomainMsg; -/** -* @param {string} request_id -* @returns {RequestId} -*/ -export function new_request_id(request_id: string): RequestId; -/** -* @param {string} type_str -* @returns {FheType} -*/ -export function new_fhe_type(type_str: string): FheType; -/** -* This function assembles a reencryption request -* 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. -* -* The result value needs to convert to the following JSON -* for the gateway. -* ``` -* { "signature": "010203", // HEX -* "verification_key": "010203", // HEX -* "enc_key": "010203", // HEX -* "ciphertext_digest": "010203", // HEX -* "eip712_verifying_contract": "0x1234", // String -* } -* ``` -* This can be done using [reencryption_request_to_flat_json_string]. -* @param {Client} client -* @param {Uint8Array} signature -* @param {PublicEncKey} enc_pk -* @param {FheType} fhe_type -* @param {RequestId} key_id -* @param {Uint8Array | undefined} ciphertext -* @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: Uint8Array | undefined, ciphertext_digest: Uint8Array, domain: Eip712DomainMsg): ReencryptionRequest; -/** -* @param {ReencryptionRequest} req -* @returns {string} -*/ -export function reencryption_request_to_flat_json_string(req: ReencryptionRequest): string; -/** -* Process the reencryption response from a JSON object. -* The result is a byte array representing a plaintext of any length. -* -* * `client` - client that wants to perform reencryption. -* -* * `request` - the initial reencryption request. -* -* * `agg_resp - the response JSON object from the gateway. -* -* * `agg_resp_ids - the KMS server identities that correspond to each request. -* If this is not given, the initial configuration is used -* from when the client is instantiated. -* -* * `enc_pk` - The ephemeral public key. -* -* * `enc_sk` - The ephemeral secret key. -* -* * `verify` - Whether to perform signature verification for the response. -* It is insecure if `verify = false`! -* @param {Client} client -* @param {ReencryptionRequest | undefined} request -* @param {any} agg_resp -* @param {Uint32Array | undefined} agg_resp_ids -* @param {PublicEncKey} enc_pk -* @param {PrivateEncKey} enc_sk -* @param {boolean} verify -* @returns {Uint8Array} -*/ -export function process_reencryption_resp_from_json(client: Client, request: ReencryptionRequest | undefined, agg_resp: any, agg_resp_ids: Uint32Array | undefined, enc_pk: PublicEncKey, enc_sk: PrivateEncKey, verify: boolean): Uint8Array; -/** -* Process the reencryption response from a JSON object. -* The result is a byte array representing a plaintext of any length. -* -* * `client` - client that wants to perform reencryption. -* -* * `request` - the initial reencryption request. -* -* * `agg_resp - the vector of reencryption responses. -* -* * `agg_resp_ids - the KMS server identities that correspond to each request. -* If this is not given, the initial configuration is used -* from when the client is instantiated. -* -* * `enc_pk` - The ephemeral public key. -* -* * `enc_sk` - The ephemeral secret key. -* -* * `verify` - Whether to perform signature verification for the response. -* It is insecure if `verify = false`! -* @param {Client} client -* @param {ReencryptionRequest | undefined} request -* @param {(ReencryptionResponse)[]} agg_resp -* @param {Uint32Array | undefined} agg_resp_ids -* @param {PublicEncKey} enc_pk -* @param {PrivateEncKey} enc_sk -* @param {boolean} verify -* @returns {Uint8Array} -*/ -export function process_reencryption_resp(client: Client, request: ReencryptionRequest | undefined, agg_resp: (ReencryptionResponse)[], agg_resp_ids: Uint32Array | undefined, enc_pk: PublicEncKey, enc_sk: PrivateEncKey, verify: boolean): Uint8Array; -/** -* The plaintext types that can be encrypted in a fhevm ciphertext. -*/ -export enum FheType { - Ebool = 0, - Euint4 = 1, - Euint8 = 2, - Euint16 = 3, - Euint32 = 4, - Euint64 = 5, - Euint128 = 6, - Euint160 = 7, - Euint256 = 8, - Euint512 = 9, - Euint1024 = 10, - Euint2048 = 11, -} -/** -* 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; -/** -*/ - bytes: Uint8Array; -} -/** -*/ -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 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 deleted file mode 100644 index 326bf9c..0000000 --- a/src/kms/node/kms_lib.js +++ /dev/null @@ -1,2179 +0,0 @@ -let imports = {}; -imports['__wbindgen_placeholder__'] = module.exports; -let wasm; -const { TextDecoder, TextEncoder } = require(`util`); - -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)); -} - -const heap = new Array(128).fill(undefined); - -heap.push(undefined, null, true, false); - -let heap_next = heap.length; - -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; -} - -function getObject(idx) { return heap[idx]; } - -function isLikeNone(x) { - return x === undefined || x === null; -} - -let cachedFloat64Memory0 = null; - -function getFloat64Memory0() { - if (cachedFloat64Memory0 === null || cachedFloat64Memory0.byteLength === 0) { - cachedFloat64Memory0 = new Float64Array(wasm.memory.buffer); - } - return cachedFloat64Memory0; -} - -let cachedInt32Memory0 = null; - -function getInt32Memory0() { - if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) { - cachedInt32Memory0 = new Int32Array(wasm.memory.buffer); - } - return cachedInt32Memory0; -} - -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 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 debugString(val) { - // primitive types - const type = typeof val; - if (type == 'number' || type == 'boolean' || val == null) { - return `${val}`; - } - if (type == 'string') { - return `"${val}"`; - } - if (type == 'symbol') { - const description = val.description; - if (description == null) { - return 'Symbol'; - } else { - return `Symbol(${description})`; - } - } - if (type == 'function') { - const name = val.name; - if (typeof name == 'string' && name.length > 0) { - return `Function(${name})`; - } else { - return 'Function'; - } - } - // objects - if (Array.isArray(val)) { - const length = val.length; - let debug = '['; - if (length > 0) { - debug += debugString(val[0]); - } - for(let i = 1; i < length; i++) { - debug += ', ' + debugString(val[i]); - } - debug += ']'; - return debug; - } - // Test for built-in - const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val)); - let className; - if (builtInMatches.length > 1) { - className = builtInMatches[1]; - } else { - // Failed to match the standard '[object ClassName]' - return toString.call(val); - } - if (className == 'Object') { - // we're a user defined class or Object - // JSON.stringify avoids problems with cycles, and is generally much - // easier than looping through ownProperties of `val`. - try { - return 'Object(' + JSON.stringify(val) + ')'; - } catch (_) { - return 'Object'; - } - } - // errors - if (val instanceof Error) { - return `${val.name}: ${val.message}\n${val.stack}`; - } - // TODO we could test for more things here, like `Set`s and `Map`s. - return className; -} - -function _assertClass(instance, klass) { - if (!(instance instanceof klass)) { - throw new Error(`expected instance of ${klass.name}`); - } - return instance.ptr; -} - -function getArrayU8FromWasm0(ptr, len) { - ptr = ptr >>> 0; - return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len); -} -/** -* @param {PublicSigKey} pk -* @returns {Uint8Array} -*/ -module.exports.public_sig_key_to_u8vec = function(pk) { - try { - const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); - _assertClass(pk, PublicSigKey); - wasm.public_sig_key_to_u8vec(retptr, 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); - } -}; - -function passArray8ToWasm0(arg, malloc) { - const ptr = malloc(arg.length * 1, 1) >>> 0; - getUint8Memory0().set(arg, ptr / 1); - WASM_VECTOR_LEN = arg.length; - return ptr; -} -/** -* @param {Uint8Array} v -* @returns {PublicSigKey} -*/ -module.exports.u8vec_to_public_sig_key = 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_public_sig_key(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 PublicSigKey.__wrap(r0); - } finally { - wasm.__wbindgen_add_to_stack_pointer(16); - } -}; - -/** -* @param {PrivateSigKey} sk -* @returns {Uint8Array} -*/ -module.exports.private_sig_key_to_u8vec = function(sk) { - try { - const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); - _assertClass(sk, PrivateSigKey); - wasm.private_sig_key_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 {PrivateSigKey} -*/ -module.exports.u8vec_to_private_sig_key = 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_private_sig_key(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 PrivateSigKey.__wrap(r0); - } finally { - wasm.__wbindgen_add_to_stack_pointer(16); - } -}; - -/** -* Instantiate a new client for use with the centralized KMS. -* @returns {Client} -*/ -module.exports.default_client_for_centralized_kms = function() { - try { - const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); - wasm.default_client_for_centralized_kms(retptr); - var r0 = getInt32Memory0()[retptr / 4 + 0]; - var r1 = getInt32Memory0()[retptr / 4 + 1]; - var r2 = getInt32Memory0()[retptr / 4 + 2]; - if (r2) { - throw takeObject(r1); - } - return Client.__wrap(r0); - } finally { - wasm.__wbindgen_add_to_stack_pointer(16); - } -}; - -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; -} -/** -* Instantiate a new client. -* -* * `server_pks` - a list of KMS server signature public keys, -* which can parsed using [u8vec_to_public_sig_key]. -* -* * `server_pks_ids` - a list of the IDs that are associated to the -* server public keys. If None is given, then the IDs default to -* 1..n, where n is the length of `server_pks`. -* -* * `client_pk` - the client (wallet) public key, -* which can parsed using [u8vec_to_public_sig_key] also. -* -* * `shares_needed` - number of shares needed for reconstruction. -* In the centralized setting this is 1. -* -* * `param_choice` - the parameter choice, which can be either `"test"` or `"default"`. -* The "default" parameter choice is selected if no matching string is found. -* @param {(PublicSigKey)[]} server_pks -* @param {Uint8Array | undefined} server_pks_ids -* @param {PublicSigKey} client_pk -* @param {number} shares_needed -* @param {string} param_choice -* @returns {Client} -*/ -module.exports.new_client = function(server_pks, server_pks_ids, client_pk, shares_needed, param_choice) { - try { - const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); - const ptr0 = passArrayJsValueToWasm0(server_pks, wasm.__wbindgen_malloc); - const len0 = WASM_VECTOR_LEN; - var ptr1 = isLikeNone(server_pks_ids) ? 0 : passArray8ToWasm0(server_pks_ids, wasm.__wbindgen_malloc); - var len1 = WASM_VECTOR_LEN; - _assertClass(client_pk, PublicSigKey); - var ptr2 = client_pk.__destroy_into_raw(); - const ptr3 = passStringToWasm0(param_choice, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len3 = WASM_VECTOR_LEN; - wasm.new_client(retptr, ptr0, len0, ptr1, len1, ptr2, shares_needed, ptr3, len3); - var r0 = getInt32Memory0()[retptr / 4 + 0]; - var r1 = getInt32Memory0()[retptr / 4 + 1]; - var r2 = getInt32Memory0()[retptr / 4 + 2]; - if (r2) { - throw takeObject(r1); - } - return Client.__wrap(r0); - } finally { - wasm.__wbindgen_add_to_stack_pointer(16); - } -}; - -function getArrayJsValueFromWasm0(ptr, len) { - ptr = ptr >>> 0; - const mem = getUint32Memory0(); - const slice = mem.subarray(ptr / 4, ptr / 4 + len); - const result = []; - for (let i = 0; i < slice.length; i++) { - result.push(takeObject(slice[i])); - } - return result; -} -/** -* @param {Client} client -* @returns {(PublicSigKey)[]} -*/ -module.exports.get_server_public_keys = function(client) { - try { - const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); - _assertClass(client, Client); - wasm.get_server_public_keys(retptr, client.__wbg_ptr); - var r0 = getInt32Memory0()[retptr / 4 + 0]; - var r1 = getInt32Memory0()[retptr / 4 + 1]; - var v1 = getArrayJsValueFromWasm0(r0, r1).slice(); - wasm.__wbindgen_free(r0, r1 * 4, 4); - return v1; - } finally { - wasm.__wbindgen_add_to_stack_pointer(16); - } -}; - -/** -* @param {Client} client -* @returns {PublicSigKey} -*/ -module.exports.get_client_public_key = function(client) { - _assertClass(client, Client); - const ret = wasm.get_client_public_key(client.__wbg_ptr); - return PublicSigKey.__wrap(ret); -}; - -/** -* @param {Client} client -* @returns {PrivateSigKey | undefined} -*/ -module.exports.get_client_secret_key = function(client) { - _assertClass(client, Client); - const ret = wasm.get_client_secret_key(client.__wbg_ptr); - return ret === 0 ? undefined : PrivateSigKey.__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_pk_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); - } -}; - -/** -* @param {string} name -* @param {string} version -* @param {Uint8Array} chain_id -* @param {string} verifying_contract -* @param {Uint8Array} salt -* @returns {Eip712DomainMsg} -*/ -module.exports.new_eip712_domain = function(name, version, chain_id, verifying_contract, salt) { - const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len0 = WASM_VECTOR_LEN; - const ptr1 = passStringToWasm0(version, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len1 = WASM_VECTOR_LEN; - const ptr2 = passArray8ToWasm0(chain_id, wasm.__wbindgen_malloc); - const len2 = WASM_VECTOR_LEN; - const ptr3 = passStringToWasm0(verifying_contract, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len3 = WASM_VECTOR_LEN; - const ptr4 = passArray8ToWasm0(salt, wasm.__wbindgen_malloc); - const len4 = WASM_VECTOR_LEN; - const ret = wasm.new_eip712_domain(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4); - return Eip712DomainMsg.__wrap(ret); -}; - -/** -* @param {string} request_id -* @returns {RequestId} -*/ -module.exports.new_request_id = function(request_id) { - const ptr0 = passStringToWasm0(request_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len0 = WASM_VECTOR_LEN; - const ret = wasm.new_request_id(ptr0, len0); - return RequestId.__wrap(ret); -}; - -/** -* @param {string} type_str -* @returns {FheType} -*/ -module.exports.new_fhe_type = function(type_str) { - try { - const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); - const ptr0 = passStringToWasm0(type_str, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len0 = WASM_VECTOR_LEN; - wasm.new_fhe_type(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 r0; - } finally { - wasm.__wbindgen_add_to_stack_pointer(16); - } -}; - -/** -* This function assembles a reencryption request -* 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. -* -* The result value needs to convert to the following JSON -* for the gateway. -* ``` -* { "signature": "010203", // HEX -* "verification_key": "010203", // HEX -* "enc_key": "010203", // HEX -* "ciphertext_digest": "010203", // HEX -* "eip712_verifying_contract": "0x1234", // String -* } -* ``` -* This can be done using [reencryption_request_to_flat_json_string]. -* @param {Client} client -* @param {Uint8Array} signature -* @param {PublicEncKey} enc_pk -* @param {FheType} fhe_type -* @param {RequestId} key_id -* @param {Uint8Array | undefined} ciphertext -* @param {Uint8Array} ciphertext_digest -* @param {Eip712DomainMsg} domain -* @returns {ReencryptionRequest} -*/ -module.exports.make_reencryption_req = function(client, signature, enc_pk, fhe_type, key_id, ciphertext, 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(); - var ptr3 = isLikeNone(ciphertext) ? 0 : passArray8ToWasm0(ciphertext, wasm.__wbindgen_malloc); - var len3 = WASM_VECTOR_LEN; - const ptr4 = passArray8ToWasm0(ciphertext_digest, wasm.__wbindgen_malloc); - const len4 = WASM_VECTOR_LEN; - _assertClass(domain, Eip712DomainMsg); - var ptr5 = domain.__destroy_into_raw(); - wasm.make_reencryption_req(retptr, client.__wbg_ptr, ptr0, len0, ptr1, fhe_type, ptr2, ptr3, len3, ptr4, len4, ptr5); - 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); - } -}; - -/** -* @param {ReencryptionRequest} req -* @returns {string} -*/ -module.exports.reencryption_request_to_flat_json_string = function(req) { - let deferred1_0; - let deferred1_1; - try { - const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); - _assertClass(req, ReencryptionRequest); - wasm.reencryption_request_to_flat_json_string(retptr, req.__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); - } -}; - -function passArray32ToWasm0(arg, malloc) { - const ptr = malloc(arg.length * 4, 4) >>> 0; - getUint32Memory0().set(arg, ptr / 4); - WASM_VECTOR_LEN = arg.length; - return ptr; -} -/** -* Process the reencryption response from a JSON object. -* The result is a byte array representing a plaintext of any length. -* -* * `client` - client that wants to perform reencryption. -* -* * `request` - the initial reencryption request. -* -* * `agg_resp - the response JSON object from the gateway. -* -* * `agg_resp_ids - the KMS server identities that correspond to each request. -* If this is not given, the initial configuration is used -* from when the client is instantiated. -* -* * `enc_pk` - The ephemeral public key. -* -* * `enc_sk` - The ephemeral secret key. -* -* * `verify` - Whether to perform signature verification for the response. -* It is insecure if `verify = false`! -* @param {Client} client -* @param {ReencryptionRequest | undefined} request -* @param {any} agg_resp -* @param {Uint32Array | undefined} agg_resp_ids -* @param {PublicEncKey} enc_pk -* @param {PrivateEncKey} enc_sk -* @param {boolean} verify -* @returns {Uint8Array} -*/ -module.exports.process_reencryption_resp_from_json = function(client, request, agg_resp, agg_resp_ids, enc_pk, enc_sk, verify) { - 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(); - } - var ptr1 = isLikeNone(agg_resp_ids) ? 0 : passArray32ToWasm0(agg_resp_ids, wasm.__wbindgen_malloc); - var len1 = WASM_VECTOR_LEN; - _assertClass(enc_pk, PublicEncKey); - _assertClass(enc_sk, PrivateEncKey); - wasm.process_reencryption_resp_from_json(retptr, client.__wbg_ptr, ptr0, addHeapObject(agg_resp), ptr1, len1, enc_pk.__wbg_ptr, enc_sk.__wbg_ptr, verify); - 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 v3 = getArrayU8FromWasm0(r0, r1).slice(); - wasm.__wbindgen_free(r0, r1 * 1, 1); - return v3; - } finally { - wasm.__wbindgen_add_to_stack_pointer(16); - } -}; - -/** -* Process the reencryption response from a JSON object. -* The result is a byte array representing a plaintext of any length. -* -* * `client` - client that wants to perform reencryption. -* -* * `request` - the initial reencryption request. -* -* * `agg_resp - the vector of reencryption responses. -* -* * `agg_resp_ids - the KMS server identities that correspond to each request. -* If this is not given, the initial configuration is used -* from when the client is instantiated. -* -* * `enc_pk` - The ephemeral public key. -* -* * `enc_sk` - The ephemeral secret key. -* -* * `verify` - Whether to perform signature verification for the response. -* It is insecure if `verify = false`! -* @param {Client} client -* @param {ReencryptionRequest | undefined} request -* @param {(ReencryptionResponse)[]} agg_resp -* @param {Uint32Array | undefined} agg_resp_ids -* @param {PublicEncKey} enc_pk -* @param {PrivateEncKey} enc_sk -* @param {boolean} verify -* @returns {Uint8Array} -*/ -module.exports.process_reencryption_resp = function(client, request, agg_resp, agg_resp_ids, enc_pk, enc_sk, verify) { - 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; - var ptr2 = isLikeNone(agg_resp_ids) ? 0 : passArray32ToWasm0(agg_resp_ids, wasm.__wbindgen_malloc); - var 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, verify); - 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 v4 = getArrayU8FromWasm0(r0, r1).slice(); - wasm.__wbindgen_free(r0, r1 * 1, 1); - return v4; - } 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({ Ebool:0,"0":"Ebool",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",Euint256:8,"8":"Euint256",Euint512:9,"9":"Euint512",Euint1024:10,"10":"Euint1024",Euint2048:11,"11":"Euint2048", }); - -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 {Uint8Array} - */ - get bytes() { - try { - const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); - wasm.__wbg_get_plaintext_bytes(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 bytes(arg0) { - const ptr0 = passArray8ToWasm0(arg0, wasm.__wbindgen_malloc); - const len0 = WASM_VECTOR_LEN; - wasm.__wbg_set_plaintext_bytes(this.__wbg_ptr, ptr0, len0); - } -} -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 { - - static __wrap(ptr) { - ptr = ptr >>> 0; - const obj = Object.create(PrivateSigKey.prototype); - obj.__wbg_ptr = ptr; - PrivateSigKeyFinalization.register(obj, obj.__wbg_ptr, obj); - return obj; - } - - __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 __wrap(ptr) { - ptr = ptr >>> 0; - const obj = Object.create(PublicSigKey.prototype); - obj.__wbg_ptr = ptr; - PublicSigKeyFinalization.register(obj, obj.__wbg_ptr, obj); - return obj; - } - - 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 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 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.__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_publicsigkey_new = function(arg0) { - const ret = PublicSigKey.__wrap(arg0); - return addHeapObject(ret); -}; - -module.exports.__wbindgen_number_get = function(arg0, arg1) { - const obj = getObject(arg1); - const ret = typeof(obj) === 'number' ? obj : undefined; - getFloat64Memory0()[arg0 / 8 + 1] = isLikeNone(ret) ? 0 : ret; - getInt32Memory0()[arg0 / 4 + 0] = !isLikeNone(ret); -}; - -module.exports.__wbindgen_object_drop_ref = function(arg0) { - takeObject(arg0); -}; - -module.exports.__wbg_reencryptionresponse_unwrap = function(arg0) { - const ret = ReencryptionResponse.__unwrap(takeObject(arg0)); - return ret; -}; - -module.exports.__wbindgen_string_get = function(arg0, arg1) { - const obj = getObject(arg1); - const ret = typeof(obj) === 'string' ? obj : undefined; - var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - var len1 = WASM_VECTOR_LEN; - getInt32Memory0()[arg0 / 4 + 1] = len1; - getInt32Memory0()[arg0 / 4 + 0] = ptr1; -}; - -module.exports.__wbindgen_is_object = function(arg0) { - const val = getObject(arg0); - const ret = typeof(val) === 'object' && val !== null; - return ret; -}; - -module.exports.__wbindgen_is_undefined = function(arg0) { - const ret = getObject(arg0) === undefined; - return ret; -}; - -module.exports.__wbindgen_in = function(arg0, arg1) { - const ret = getObject(arg0) in getObject(arg1); - return ret; -}; - -module.exports.__wbindgen_jsval_loose_eq = function(arg0, arg1) { - const ret = getObject(arg0) == getObject(arg1); - return ret; -}; - -module.exports.__wbindgen_boolean_get = function(arg0) { - const v = getObject(arg0); - const ret = typeof(v) === 'boolean' ? (v ? 1 : 0) : 2; - return ret; -}; - -module.exports.__wbindgen_as_number = function(arg0) { - const ret = +getObject(arg0); - return ret; -}; - -module.exports.__wbindgen_object_clone_ref = function(arg0) { - const ret = getObject(arg0); - return addHeapObject(ret); -}; - -module.exports.__wbindgen_string_new = function(arg0, arg1) { - const ret = getStringFromWasm0(arg0, arg1); - return addHeapObject(ret); -}; - -module.exports.__wbg_getwithrefkey_edc2c8960f0f1191 = function(arg0, arg1) { - const ret = getObject(arg0)[getObject(arg1)]; - return addHeapObject(ret); -}; - -module.exports.__wbg_String_b9412f8799faab3e = function(arg0, arg1) { - const ret = String(getObject(arg1)); - 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_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.__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_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.__wbg_msCrypto_eb05e62b530a1508 = function(arg0) { - const ret = getObject(arg0).msCrypto; - 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_get_bd8e338fbd5f5cc8 = function(arg0, arg1) { - const ret = getObject(arg0)[arg1 >>> 0]; - return addHeapObject(ret); -}; - -module.exports.__wbg_length_cd7af8117672b8b8 = function(arg0) { - const ret = getObject(arg0).length; - return ret; -}; - -module.exports.__wbg_newnoargs_e258087cd0daa0ea = function(arg0, arg1) { - const ret = new Function(getStringFromWasm0(arg0, arg1)); - return addHeapObject(ret); -}; - -module.exports.__wbg_next_40fc327bfc8770e6 = function(arg0) { - const ret = getObject(arg0).next; - return addHeapObject(ret); -}; - -module.exports.__wbg_next_196c84450b364254 = function() { return handleError(function (arg0) { - const ret = getObject(arg0).next(); - return addHeapObject(ret); -}, arguments) }; - -module.exports.__wbg_done_298b57d23c0fc80c = function(arg0) { - const ret = getObject(arg0).done; - return ret; -}; - -module.exports.__wbg_value_d93c65011f51a456 = function(arg0) { - const ret = getObject(arg0).value; - return addHeapObject(ret); -}; - -module.exports.__wbg_iterator_2cee6dadfd956dfa = function() { - const ret = Symbol.iterator; - return addHeapObject(ret); -}; - -module.exports.__wbg_get_e3c254076557e348 = function() { return handleError(function (arg0, arg1) { - const ret = Reflect.get(getObject(arg0), getObject(arg1)); - return addHeapObject(ret); -}, arguments) }; - -module.exports.__wbg_call_27c0f87801dedf93 = function() { return handleError(function (arg0, arg1) { - const ret = getObject(arg0).call(getObject(arg1)); - return addHeapObject(ret); -}, arguments) }; - -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.__wbg_isArray_2ab64d95e09ea0ae = function(arg0) { - const ret = Array.isArray(getObject(arg0)); - return ret; -}; - -module.exports.__wbg_instanceof_ArrayBuffer_836825be07d4c9d2 = function(arg0) { - let result; - try { - result = getObject(arg0) instanceof ArrayBuffer; - } catch (_) { - result = false; - } - const ret = result; - 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_isSafeInteger_f7b04ef02296c4d2 = function(arg0) { - const ret = Number.isSafeInteger(getObject(arg0)); - return ret; -}; - -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_length_c20a40f15020d68a = function(arg0) { - const ret = getObject(arg0).length; - return ret; -}; - -module.exports.__wbg_instanceof_Uint8Array_2b3bbecd033d19f6 = function(arg0) { - let result; - try { - result = getObject(arg0) instanceof Uint8Array; - } catch (_) { - result = false; - } - const ret = result; - return ret; -}; - -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_debug_string = function(arg0, arg1) { - const ret = debugString(getObject(arg1)); - 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.__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 deleted file mode 100644 index 8e9f47b..0000000 Binary files a/src/kms/node/kms_lib_bg.wasm and /dev/null differ diff --git a/src/kms/node/kms_lib_bg.wasm.d.ts b/src/kms/node/kms_lib_bg.wasm.d.ts deleted file mode 100644 index 91be0b4..0000000 --- a/src/kms/node/kms_lib_bg.wasm.d.ts +++ /dev/null @@ -1,96 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -export const memory: WebAssembly.Memory; -export function __wbg_client_free(a: 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 public_sig_key_to_u8vec(a: number, b: number): void; -export function u8vec_to_public_sig_key(a: number, b: number, c: number): void; -export function private_sig_key_to_u8vec(a: number, b: number): void; -export function u8vec_to_private_sig_key(a: number, b: number, c: number): void; -export function default_client_for_centralized_kms(a: number): void; -export function new_client(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number): void; -export function get_server_public_keys(a: number, b: number): void; -export function get_client_public_key(a: number): number; -export function get_client_secret_key(a: 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 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 new_eip712_domain(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number): number; -export function new_request_id(a: number, b: number): number; -export function new_fhe_type(a: number, b: number, c: 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, k: number, l: number): void; -export function reencryption_request_to_flat_json_string(a: number, b: number): void; -export function process_reencryption_resp_from_json(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: 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, j: number): void; -export function cryptobox_sk_to_u8vec(a: number, b: number): void; -export function __wbg_plaintext_free(a: number): void; -export function __wbg_get_plaintext_bytes(a: number, b: number): void; -export function __wbg_set_plaintext_bytes(a: number, b: number, c: 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_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_get_requestid_request_id(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 __wbindgen_malloc(a: number, b: number): number; -export function __wbindgen_realloc(a: number, b: number, c: number, d: number): number; -export function __wbindgen_add_to_stack_pointer(a: number): number; -export function __wbindgen_free(a: number, b: number, c: number): void; -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 deleted file mode 100644 index 38a75ec..0000000 --- a/src/kms/web/kms_lib.d.ts +++ /dev/null @@ -1,553 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -/** -* @param {PublicSigKey} pk -* @returns {Uint8Array} -*/ -export function public_sig_key_to_u8vec(pk: PublicSigKey): Uint8Array; -/** -* @param {Uint8Array} v -* @returns {PublicSigKey} -*/ -export function u8vec_to_public_sig_key(v: Uint8Array): PublicSigKey; -/** -* @param {PrivateSigKey} sk -* @returns {Uint8Array} -*/ -export function private_sig_key_to_u8vec(sk: PrivateSigKey): Uint8Array; -/** -* @param {Uint8Array} v -* @returns {PrivateSigKey} -*/ -export function u8vec_to_private_sig_key(v: Uint8Array): PrivateSigKey; -/** -* Instantiate a new client for use with the centralized KMS. -* @returns {Client} -*/ -export function default_client_for_centralized_kms(): Client; -/** -* Instantiate a new client. -* -* * `server_pks` - a list of KMS server signature public keys, -* which can parsed using [u8vec_to_public_sig_key]. -* -* * `server_pks_ids` - a list of the IDs that are associated to the -* server public keys. If None is given, then the IDs default to -* 1..n, where n is the length of `server_pks`. -* -* * `client_pk` - the client (wallet) public key, -* which can parsed using [u8vec_to_public_sig_key] also. -* -* * `shares_needed` - number of shares needed for reconstruction. -* In the centralized setting this is 1. -* -* * `param_choice` - the parameter choice, which can be either `"test"` or `"default"`. -* The "default" parameter choice is selected if no matching string is found. -* @param {(PublicSigKey)[]} server_pks -* @param {Uint8Array | undefined} server_pks_ids -* @param {PublicSigKey} client_pk -* @param {number} shares_needed -* @param {string} param_choice -* @returns {Client} -*/ -export function new_client(server_pks: (PublicSigKey)[], server_pks_ids: Uint8Array | undefined, client_pk: PublicSigKey, shares_needed: number, param_choice: string): Client; -/** -* @param {Client} client -* @returns {(PublicSigKey)[]} -*/ -export function get_server_public_keys(client: Client): (PublicSigKey)[]; -/** -* @param {Client} client -* @returns {PublicSigKey} -*/ -export function get_client_public_key(client: Client): PublicSigKey; -/** -* @param {Client} client -* @returns {PrivateSigKey | undefined} -*/ -export function get_client_secret_key(client: Client): PrivateSigKey | undefined; -/** -* @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; -/** -* @param {string} name -* @param {string} version -* @param {Uint8Array} chain_id -* @param {string} verifying_contract -* @param {Uint8Array} salt -* @returns {Eip712DomainMsg} -*/ -export function new_eip712_domain(name: string, version: string, chain_id: Uint8Array, verifying_contract: string, salt: Uint8Array): Eip712DomainMsg; -/** -* @param {string} request_id -* @returns {RequestId} -*/ -export function new_request_id(request_id: string): RequestId; -/** -* @param {string} type_str -* @returns {FheType} -*/ -export function new_fhe_type(type_str: string): FheType; -/** -* This function assembles a reencryption request -* 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. -* -* The result value needs to convert to the following JSON -* for the gateway. -* ``` -* { "signature": "010203", // HEX -* "verification_key": "010203", // HEX -* "enc_key": "010203", // HEX -* "ciphertext_digest": "010203", // HEX -* "eip712_verifying_contract": "0x1234", // String -* } -* ``` -* This can be done using [reencryption_request_to_flat_json_string]. -* @param {Client} client -* @param {Uint8Array} signature -* @param {PublicEncKey} enc_pk -* @param {FheType} fhe_type -* @param {RequestId} key_id -* @param {Uint8Array | undefined} ciphertext -* @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: Uint8Array | undefined, ciphertext_digest: Uint8Array, domain: Eip712DomainMsg): ReencryptionRequest; -/** -* @param {ReencryptionRequest} req -* @returns {string} -*/ -export function reencryption_request_to_flat_json_string(req: ReencryptionRequest): string; -/** -* Process the reencryption response from a JSON object. -* The result is a byte array representing a plaintext of any length. -* -* * `client` - client that wants to perform reencryption. -* -* * `request` - the initial reencryption request. -* -* * `agg_resp - the response JSON object from the gateway. -* -* * `agg_resp_ids - the KMS server identities that correspond to each request. -* If this is not given, the initial configuration is used -* from when the client is instantiated. -* -* * `enc_pk` - The ephemeral public key. -* -* * `enc_sk` - The ephemeral secret key. -* -* * `verify` - Whether to perform signature verification for the response. -* It is insecure if `verify = false`! -* @param {Client} client -* @param {ReencryptionRequest | undefined} request -* @param {any} agg_resp -* @param {Uint32Array | undefined} agg_resp_ids -* @param {PublicEncKey} enc_pk -* @param {PrivateEncKey} enc_sk -* @param {boolean} verify -* @returns {Uint8Array} -*/ -export function process_reencryption_resp_from_json(client: Client, request: ReencryptionRequest | undefined, agg_resp: any, agg_resp_ids: Uint32Array | undefined, enc_pk: PublicEncKey, enc_sk: PrivateEncKey, verify: boolean): Uint8Array; -/** -* Process the reencryption response from a JSON object. -* The result is a byte array representing a plaintext of any length. -* -* * `client` - client that wants to perform reencryption. -* -* * `request` - the initial reencryption request. -* -* * `agg_resp - the vector of reencryption responses. -* -* * `agg_resp_ids - the KMS server identities that correspond to each request. -* If this is not given, the initial configuration is used -* from when the client is instantiated. -* -* * `enc_pk` - The ephemeral public key. -* -* * `enc_sk` - The ephemeral secret key. -* -* * `verify` - Whether to perform signature verification for the response. -* It is insecure if `verify = false`! -* @param {Client} client -* @param {ReencryptionRequest | undefined} request -* @param {(ReencryptionResponse)[]} agg_resp -* @param {Uint32Array | undefined} agg_resp_ids -* @param {PublicEncKey} enc_pk -* @param {PrivateEncKey} enc_sk -* @param {boolean} verify -* @returns {Uint8Array} -*/ -export function process_reencryption_resp(client: Client, request: ReencryptionRequest | undefined, agg_resp: (ReencryptionResponse)[], agg_resp_ids: Uint32Array | undefined, enc_pk: PublicEncKey, enc_sk: PrivateEncKey, verify: boolean): Uint8Array; -/** -* The plaintext types that can be encrypted in a fhevm ciphertext. -*/ -export enum FheType { - Ebool = 0, - Euint4 = 1, - Euint8 = 2, - Euint16 = 3, - Euint32 = 4, - Euint64 = 5, - Euint128 = 6, - Euint160 = 7, - Euint256 = 8, - Euint512 = 9, - Euint1024 = 10, - Euint2048 = 11, -} -/** -* 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; -/** -*/ - bytes: Uint8Array; -} -/** -*/ -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 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_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 public_sig_key_to_u8vec: (a: number, b: number) => void; - readonly u8vec_to_public_sig_key: (a: number, b: number, c: number) => void; - readonly private_sig_key_to_u8vec: (a: number, b: number) => void; - readonly u8vec_to_private_sig_key: (a: number, b: number, c: number) => void; - readonly default_client_for_centralized_kms: (a: number) => void; - readonly new_client: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void; - readonly get_server_public_keys: (a: number, b: number) => void; - readonly get_client_public_key: (a: number) => number; - readonly get_client_secret_key: (a: 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 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 new_eip712_domain: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => number; - readonly new_request_id: (a: number, b: number) => number; - readonly new_fhe_type: (a: number, b: number, c: 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, k: number, l: number) => void; - readonly reencryption_request_to_flat_json_string: (a: number, b: number) => void; - readonly process_reencryption_resp_from_json: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number) => void; - readonly process_reencryption_resp: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number) => void; - readonly cryptobox_sk_to_u8vec: (a: number, b: number) => void; - readonly __wbg_plaintext_free: (a: number) => void; - readonly __wbg_get_plaintext_bytes: (a: number, b: number) => void; - readonly __wbg_set_plaintext_bytes: (a: number, b: number, c: 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_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_get_requestid_request_id: (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 __wbindgen_malloc: (a: number, b: number) => number; - readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number; - readonly __wbindgen_add_to_stack_pointer: (a: number) => number; - readonly __wbindgen_free: (a: number, b: number, c: number) => void; - 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 deleted file mode 100644 index 17e3596..0000000 --- a/src/kms/web/kms_lib.js +++ /dev/null @@ -1,2188 +0,0 @@ -let wasm; - -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)); -} - -const heap = new Array(128).fill(undefined); - -heap.push(undefined, null, true, false); - -let heap_next = heap.length; - -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; -} - -function getObject(idx) { return heap[idx]; } - -function isLikeNone(x) { - return x === undefined || x === null; -} - -let cachedFloat64Memory0 = null; - -function getFloat64Memory0() { - if (cachedFloat64Memory0 === null || cachedFloat64Memory0.byteLength === 0) { - cachedFloat64Memory0 = new Float64Array(wasm.memory.buffer); - } - return cachedFloat64Memory0; -} - -let cachedInt32Memory0 = null; - -function getInt32Memory0() { - if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) { - cachedInt32Memory0 = new Int32Array(wasm.memory.buffer); - } - return cachedInt32Memory0; -} - -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 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 debugString(val) { - // primitive types - const type = typeof val; - if (type == 'number' || type == 'boolean' || val == null) { - return `${val}`; - } - if (type == 'string') { - return `"${val}"`; - } - if (type == 'symbol') { - const description = val.description; - if (description == null) { - return 'Symbol'; - } else { - return `Symbol(${description})`; - } - } - if (type == 'function') { - const name = val.name; - if (typeof name == 'string' && name.length > 0) { - return `Function(${name})`; - } else { - return 'Function'; - } - } - // objects - if (Array.isArray(val)) { - const length = val.length; - let debug = '['; - if (length > 0) { - debug += debugString(val[0]); - } - for(let i = 1; i < length; i++) { - debug += ', ' + debugString(val[i]); - } - debug += ']'; - return debug; - } - // Test for built-in - const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val)); - let className; - if (builtInMatches.length > 1) { - className = builtInMatches[1]; - } else { - // Failed to match the standard '[object ClassName]' - return toString.call(val); - } - if (className == 'Object') { - // we're a user defined class or Object - // JSON.stringify avoids problems with cycles, and is generally much - // easier than looping through ownProperties of `val`. - try { - return 'Object(' + JSON.stringify(val) + ')'; - } catch (_) { - return 'Object'; - } - } - // errors - if (val instanceof Error) { - return `${val.name}: ${val.message}\n${val.stack}`; - } - // TODO we could test for more things here, like `Set`s and `Map`s. - return className; -} - -function _assertClass(instance, klass) { - if (!(instance instanceof klass)) { - throw new Error(`expected instance of ${klass.name}`); - } - return instance.ptr; -} - -function getArrayU8FromWasm0(ptr, len) { - ptr = ptr >>> 0; - return getUint8Memory0().subarray(ptr / 1, ptr / 1 + len); -} -/** -* @param {PublicSigKey} pk -* @returns {Uint8Array} -*/ -export function public_sig_key_to_u8vec(pk) { - try { - const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); - _assertClass(pk, PublicSigKey); - wasm.public_sig_key_to_u8vec(retptr, 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); - } -} - -function passArray8ToWasm0(arg, malloc) { - const ptr = malloc(arg.length * 1, 1) >>> 0; - getUint8Memory0().set(arg, ptr / 1); - WASM_VECTOR_LEN = arg.length; - return ptr; -} -/** -* @param {Uint8Array} v -* @returns {PublicSigKey} -*/ -export function u8vec_to_public_sig_key(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_public_sig_key(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 PublicSigKey.__wrap(r0); - } finally { - wasm.__wbindgen_add_to_stack_pointer(16); - } -} - -/** -* @param {PrivateSigKey} sk -* @returns {Uint8Array} -*/ -export function private_sig_key_to_u8vec(sk) { - try { - const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); - _assertClass(sk, PrivateSigKey); - wasm.private_sig_key_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 {PrivateSigKey} -*/ -export function u8vec_to_private_sig_key(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_private_sig_key(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 PrivateSigKey.__wrap(r0); - } finally { - wasm.__wbindgen_add_to_stack_pointer(16); - } -} - -/** -* Instantiate a new client for use with the centralized KMS. -* @returns {Client} -*/ -export function default_client_for_centralized_kms() { - try { - const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); - wasm.default_client_for_centralized_kms(retptr); - var r0 = getInt32Memory0()[retptr / 4 + 0]; - var r1 = getInt32Memory0()[retptr / 4 + 1]; - var r2 = getInt32Memory0()[retptr / 4 + 2]; - if (r2) { - throw takeObject(r1); - } - return Client.__wrap(r0); - } finally { - wasm.__wbindgen_add_to_stack_pointer(16); - } -} - -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; -} -/** -* Instantiate a new client. -* -* * `server_pks` - a list of KMS server signature public keys, -* which can parsed using [u8vec_to_public_sig_key]. -* -* * `server_pks_ids` - a list of the IDs that are associated to the -* server public keys. If None is given, then the IDs default to -* 1..n, where n is the length of `server_pks`. -* -* * `client_pk` - the client (wallet) public key, -* which can parsed using [u8vec_to_public_sig_key] also. -* -* * `shares_needed` - number of shares needed for reconstruction. -* In the centralized setting this is 1. -* -* * `param_choice` - the parameter choice, which can be either `"test"` or `"default"`. -* The "default" parameter choice is selected if no matching string is found. -* @param {(PublicSigKey)[]} server_pks -* @param {Uint8Array | undefined} server_pks_ids -* @param {PublicSigKey} client_pk -* @param {number} shares_needed -* @param {string} param_choice -* @returns {Client} -*/ -export function new_client(server_pks, server_pks_ids, client_pk, shares_needed, param_choice) { - try { - const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); - const ptr0 = passArrayJsValueToWasm0(server_pks, wasm.__wbindgen_malloc); - const len0 = WASM_VECTOR_LEN; - var ptr1 = isLikeNone(server_pks_ids) ? 0 : passArray8ToWasm0(server_pks_ids, wasm.__wbindgen_malloc); - var len1 = WASM_VECTOR_LEN; - _assertClass(client_pk, PublicSigKey); - var ptr2 = client_pk.__destroy_into_raw(); - const ptr3 = passStringToWasm0(param_choice, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len3 = WASM_VECTOR_LEN; - wasm.new_client(retptr, ptr0, len0, ptr1, len1, ptr2, shares_needed, ptr3, len3); - var r0 = getInt32Memory0()[retptr / 4 + 0]; - var r1 = getInt32Memory0()[retptr / 4 + 1]; - var r2 = getInt32Memory0()[retptr / 4 + 2]; - if (r2) { - throw takeObject(r1); - } - return Client.__wrap(r0); - } finally { - wasm.__wbindgen_add_to_stack_pointer(16); - } -} - -function getArrayJsValueFromWasm0(ptr, len) { - ptr = ptr >>> 0; - const mem = getUint32Memory0(); - const slice = mem.subarray(ptr / 4, ptr / 4 + len); - const result = []; - for (let i = 0; i < slice.length; i++) { - result.push(takeObject(slice[i])); - } - return result; -} -/** -* @param {Client} client -* @returns {(PublicSigKey)[]} -*/ -export function get_server_public_keys(client) { - try { - const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); - _assertClass(client, Client); - wasm.get_server_public_keys(retptr, client.__wbg_ptr); - var r0 = getInt32Memory0()[retptr / 4 + 0]; - var r1 = getInt32Memory0()[retptr / 4 + 1]; - var v1 = getArrayJsValueFromWasm0(r0, r1).slice(); - wasm.__wbindgen_free(r0, r1 * 4, 4); - return v1; - } finally { - wasm.__wbindgen_add_to_stack_pointer(16); - } -} - -/** -* @param {Client} client -* @returns {PublicSigKey} -*/ -export function get_client_public_key(client) { - _assertClass(client, Client); - const ret = wasm.get_client_public_key(client.__wbg_ptr); - return PublicSigKey.__wrap(ret); -} - -/** -* @param {Client} client -* @returns {PrivateSigKey | undefined} -*/ -export function get_client_secret_key(client) { - _assertClass(client, Client); - const ret = wasm.get_client_secret_key(client.__wbg_ptr); - return ret === 0 ? undefined : PrivateSigKey.__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_pk_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); - } -} - -/** -* @param {string} name -* @param {string} version -* @param {Uint8Array} chain_id -* @param {string} verifying_contract -* @param {Uint8Array} salt -* @returns {Eip712DomainMsg} -*/ -export function new_eip712_domain(name, version, chain_id, verifying_contract, salt) { - const ptr0 = passStringToWasm0(name, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len0 = WASM_VECTOR_LEN; - const ptr1 = passStringToWasm0(version, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len1 = WASM_VECTOR_LEN; - const ptr2 = passArray8ToWasm0(chain_id, wasm.__wbindgen_malloc); - const len2 = WASM_VECTOR_LEN; - const ptr3 = passStringToWasm0(verifying_contract, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len3 = WASM_VECTOR_LEN; - const ptr4 = passArray8ToWasm0(salt, wasm.__wbindgen_malloc); - const len4 = WASM_VECTOR_LEN; - const ret = wasm.new_eip712_domain(ptr0, len0, ptr1, len1, ptr2, len2, ptr3, len3, ptr4, len4); - return Eip712DomainMsg.__wrap(ret); -} - -/** -* @param {string} request_id -* @returns {RequestId} -*/ -export function new_request_id(request_id) { - const ptr0 = passStringToWasm0(request_id, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len0 = WASM_VECTOR_LEN; - const ret = wasm.new_request_id(ptr0, len0); - return RequestId.__wrap(ret); -} - -/** -* @param {string} type_str -* @returns {FheType} -*/ -export function new_fhe_type(type_str) { - try { - const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); - const ptr0 = passStringToWasm0(type_str, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - const len0 = WASM_VECTOR_LEN; - wasm.new_fhe_type(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 r0; - } finally { - wasm.__wbindgen_add_to_stack_pointer(16); - } -} - -/** -* This function assembles a reencryption request -* 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. -* -* The result value needs to convert to the following JSON -* for the gateway. -* ``` -* { "signature": "010203", // HEX -* "verification_key": "010203", // HEX -* "enc_key": "010203", // HEX -* "ciphertext_digest": "010203", // HEX -* "eip712_verifying_contract": "0x1234", // String -* } -* ``` -* This can be done using [reencryption_request_to_flat_json_string]. -* @param {Client} client -* @param {Uint8Array} signature -* @param {PublicEncKey} enc_pk -* @param {FheType} fhe_type -* @param {RequestId} key_id -* @param {Uint8Array | undefined} ciphertext -* @param {Uint8Array} ciphertext_digest -* @param {Eip712DomainMsg} domain -* @returns {ReencryptionRequest} -*/ -export function make_reencryption_req(client, signature, enc_pk, fhe_type, key_id, ciphertext, 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(); - var ptr3 = isLikeNone(ciphertext) ? 0 : passArray8ToWasm0(ciphertext, wasm.__wbindgen_malloc); - var len3 = WASM_VECTOR_LEN; - const ptr4 = passArray8ToWasm0(ciphertext_digest, wasm.__wbindgen_malloc); - const len4 = WASM_VECTOR_LEN; - _assertClass(domain, Eip712DomainMsg); - var ptr5 = domain.__destroy_into_raw(); - wasm.make_reencryption_req(retptr, client.__wbg_ptr, ptr0, len0, ptr1, fhe_type, ptr2, ptr3, len3, ptr4, len4, ptr5); - 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); - } -} - -/** -* @param {ReencryptionRequest} req -* @returns {string} -*/ -export function reencryption_request_to_flat_json_string(req) { - let deferred1_0; - let deferred1_1; - try { - const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); - _assertClass(req, ReencryptionRequest); - wasm.reencryption_request_to_flat_json_string(retptr, req.__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); - } -} - -function passArray32ToWasm0(arg, malloc) { - const ptr = malloc(arg.length * 4, 4) >>> 0; - getUint32Memory0().set(arg, ptr / 4); - WASM_VECTOR_LEN = arg.length; - return ptr; -} -/** -* Process the reencryption response from a JSON object. -* The result is a byte array representing a plaintext of any length. -* -* * `client` - client that wants to perform reencryption. -* -* * `request` - the initial reencryption request. -* -* * `agg_resp - the response JSON object from the gateway. -* -* * `agg_resp_ids - the KMS server identities that correspond to each request. -* If this is not given, the initial configuration is used -* from when the client is instantiated. -* -* * `enc_pk` - The ephemeral public key. -* -* * `enc_sk` - The ephemeral secret key. -* -* * `verify` - Whether to perform signature verification for the response. -* It is insecure if `verify = false`! -* @param {Client} client -* @param {ReencryptionRequest | undefined} request -* @param {any} agg_resp -* @param {Uint32Array | undefined} agg_resp_ids -* @param {PublicEncKey} enc_pk -* @param {PrivateEncKey} enc_sk -* @param {boolean} verify -* @returns {Uint8Array} -*/ -export function process_reencryption_resp_from_json(client, request, agg_resp, agg_resp_ids, enc_pk, enc_sk, verify) { - 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(); - } - var ptr1 = isLikeNone(agg_resp_ids) ? 0 : passArray32ToWasm0(agg_resp_ids, wasm.__wbindgen_malloc); - var len1 = WASM_VECTOR_LEN; - _assertClass(enc_pk, PublicEncKey); - _assertClass(enc_sk, PrivateEncKey); - wasm.process_reencryption_resp_from_json(retptr, client.__wbg_ptr, ptr0, addHeapObject(agg_resp), ptr1, len1, enc_pk.__wbg_ptr, enc_sk.__wbg_ptr, verify); - 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 v3 = getArrayU8FromWasm0(r0, r1).slice(); - wasm.__wbindgen_free(r0, r1 * 1, 1); - return v3; - } finally { - wasm.__wbindgen_add_to_stack_pointer(16); - } -} - -/** -* Process the reencryption response from a JSON object. -* The result is a byte array representing a plaintext of any length. -* -* * `client` - client that wants to perform reencryption. -* -* * `request` - the initial reencryption request. -* -* * `agg_resp - the vector of reencryption responses. -* -* * `agg_resp_ids - the KMS server identities that correspond to each request. -* If this is not given, the initial configuration is used -* from when the client is instantiated. -* -* * `enc_pk` - The ephemeral public key. -* -* * `enc_sk` - The ephemeral secret key. -* -* * `verify` - Whether to perform signature verification for the response. -* It is insecure if `verify = false`! -* @param {Client} client -* @param {ReencryptionRequest | undefined} request -* @param {(ReencryptionResponse)[]} agg_resp -* @param {Uint32Array | undefined} agg_resp_ids -* @param {PublicEncKey} enc_pk -* @param {PrivateEncKey} enc_sk -* @param {boolean} verify -* @returns {Uint8Array} -*/ -export function process_reencryption_resp(client, request, agg_resp, agg_resp_ids, enc_pk, enc_sk, verify) { - 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; - var ptr2 = isLikeNone(agg_resp_ids) ? 0 : passArray32ToWasm0(agg_resp_ids, wasm.__wbindgen_malloc); - var 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, verify); - 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 v4 = getArrayU8FromWasm0(r0, r1).slice(); - wasm.__wbindgen_free(r0, r1 * 1, 1); - return v4; - } 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({ Ebool:0,"0":"Ebool",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",Euint256:8,"8":"Euint256",Euint512:9,"9":"Euint512",Euint1024:10,"10":"Euint1024",Euint2048:11,"11":"Euint2048", }); - -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 {Uint8Array} - */ - get bytes() { - try { - const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); - wasm.__wbg_get_plaintext_bytes(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 bytes(arg0) { - const ptr0 = passArray8ToWasm0(arg0, wasm.__wbindgen_malloc); - const len0 = WASM_VECTOR_LEN; - wasm.__wbg_set_plaintext_bytes(this.__wbg_ptr, ptr0, len0); - } -} - -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 { - - static __wrap(ptr) { - ptr = ptr >>> 0; - const obj = Object.create(PrivateSigKey.prototype); - obj.__wbg_ptr = ptr; - PrivateSigKeyFinalization.register(obj, obj.__wbg_ptr, obj); - return obj; - } - - __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 __wrap(ptr) { - ptr = ptr >>> 0; - const obj = Object.create(PublicSigKey.prototype); - obj.__wbg_ptr = ptr; - PublicSigKeyFinalization.register(obj, obj.__wbg_ptr, obj); - return obj; - } - - 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 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 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.__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_publicsigkey_new = function(arg0) { - const ret = PublicSigKey.__wrap(arg0); - return addHeapObject(ret); - }; - imports.wbg.__wbindgen_number_get = function(arg0, arg1) { - const obj = getObject(arg1); - const ret = typeof(obj) === 'number' ? obj : undefined; - getFloat64Memory0()[arg0 / 8 + 1] = isLikeNone(ret) ? 0 : ret; - getInt32Memory0()[arg0 / 4 + 0] = !isLikeNone(ret); - }; - imports.wbg.__wbindgen_object_drop_ref = function(arg0) { - takeObject(arg0); - }; - imports.wbg.__wbg_reencryptionresponse_unwrap = function(arg0) { - const ret = ReencryptionResponse.__unwrap(takeObject(arg0)); - return ret; - }; - imports.wbg.__wbindgen_string_get = function(arg0, arg1) { - const obj = getObject(arg1); - const ret = typeof(obj) === 'string' ? obj : undefined; - var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc); - var len1 = WASM_VECTOR_LEN; - getInt32Memory0()[arg0 / 4 + 1] = len1; - getInt32Memory0()[arg0 / 4 + 0] = ptr1; - }; - imports.wbg.__wbindgen_is_object = function(arg0) { - const val = getObject(arg0); - const ret = typeof(val) === 'object' && val !== null; - return ret; - }; - imports.wbg.__wbindgen_is_undefined = function(arg0) { - const ret = getObject(arg0) === undefined; - return ret; - }; - imports.wbg.__wbindgen_in = function(arg0, arg1) { - const ret = getObject(arg0) in getObject(arg1); - return ret; - }; - imports.wbg.__wbindgen_jsval_loose_eq = function(arg0, arg1) { - const ret = getObject(arg0) == getObject(arg1); - return ret; - }; - imports.wbg.__wbindgen_boolean_get = function(arg0) { - const v = getObject(arg0); - const ret = typeof(v) === 'boolean' ? (v ? 1 : 0) : 2; - return ret; - }; - imports.wbg.__wbindgen_as_number = function(arg0) { - const ret = +getObject(arg0); - return ret; - }; - imports.wbg.__wbindgen_object_clone_ref = function(arg0) { - const ret = getObject(arg0); - return addHeapObject(ret); - }; - imports.wbg.__wbindgen_string_new = function(arg0, arg1) { - const ret = getStringFromWasm0(arg0, arg1); - return addHeapObject(ret); - }; - imports.wbg.__wbg_getwithrefkey_edc2c8960f0f1191 = function(arg0, arg1) { - const ret = getObject(arg0)[getObject(arg1)]; - return addHeapObject(ret); - }; - imports.wbg.__wbg_String_b9412f8799faab3e = function(arg0, arg1) { - const ret = String(getObject(arg1)); - 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_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.__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_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.__wbg_msCrypto_eb05e62b530a1508 = function(arg0) { - const ret = getObject(arg0).msCrypto; - 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_get_bd8e338fbd5f5cc8 = function(arg0, arg1) { - const ret = getObject(arg0)[arg1 >>> 0]; - return addHeapObject(ret); - }; - imports.wbg.__wbg_length_cd7af8117672b8b8 = function(arg0) { - const ret = getObject(arg0).length; - return ret; - }; - imports.wbg.__wbg_newnoargs_e258087cd0daa0ea = function(arg0, arg1) { - const ret = new Function(getStringFromWasm0(arg0, arg1)); - return addHeapObject(ret); - }; - imports.wbg.__wbg_next_40fc327bfc8770e6 = function(arg0) { - const ret = getObject(arg0).next; - return addHeapObject(ret); - }; - imports.wbg.__wbg_next_196c84450b364254 = function() { return handleError(function (arg0) { - const ret = getObject(arg0).next(); - return addHeapObject(ret); - }, arguments) }; - imports.wbg.__wbg_done_298b57d23c0fc80c = function(arg0) { - const ret = getObject(arg0).done; - return ret; - }; - imports.wbg.__wbg_value_d93c65011f51a456 = function(arg0) { - const ret = getObject(arg0).value; - return addHeapObject(ret); - }; - imports.wbg.__wbg_iterator_2cee6dadfd956dfa = function() { - const ret = Symbol.iterator; - return addHeapObject(ret); - }; - imports.wbg.__wbg_get_e3c254076557e348 = function() { return handleError(function (arg0, arg1) { - const ret = Reflect.get(getObject(arg0), getObject(arg1)); - return addHeapObject(ret); - }, arguments) }; - imports.wbg.__wbg_call_27c0f87801dedf93 = function() { return handleError(function (arg0, arg1) { - const ret = getObject(arg0).call(getObject(arg1)); - return addHeapObject(ret); - }, arguments) }; - 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.__wbg_isArray_2ab64d95e09ea0ae = function(arg0) { - const ret = Array.isArray(getObject(arg0)); - return ret; - }; - imports.wbg.__wbg_instanceof_ArrayBuffer_836825be07d4c9d2 = function(arg0) { - let result; - try { - result = getObject(arg0) instanceof ArrayBuffer; - } catch (_) { - result = false; - } - const ret = result; - 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_isSafeInteger_f7b04ef02296c4d2 = function(arg0) { - const ret = Number.isSafeInteger(getObject(arg0)); - return ret; - }; - 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_length_c20a40f15020d68a = function(arg0) { - const ret = getObject(arg0).length; - return ret; - }; - imports.wbg.__wbg_instanceof_Uint8Array_2b3bbecd033d19f6 = function(arg0) { - let result; - try { - result = getObject(arg0) instanceof Uint8Array; - } catch (_) { - result = false; - } - const ret = result; - return ret; - }; - 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_debug_string = function(arg0, arg1) { - const ret = debugString(getObject(arg1)); - 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.__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; - cachedFloat64Memory0 = null; - 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 deleted file mode 100644 index 553ff77..0000000 Binary files a/src/kms/web/kms_lib_bg.wasm and /dev/null differ diff --git a/src/kms/web/kms_lib_bg.wasm.d.ts b/src/kms/web/kms_lib_bg.wasm.d.ts deleted file mode 100644 index 91be0b4..0000000 --- a/src/kms/web/kms_lib_bg.wasm.d.ts +++ /dev/null @@ -1,96 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -export const memory: WebAssembly.Memory; -export function __wbg_client_free(a: 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 public_sig_key_to_u8vec(a: number, b: number): void; -export function u8vec_to_public_sig_key(a: number, b: number, c: number): void; -export function private_sig_key_to_u8vec(a: number, b: number): void; -export function u8vec_to_private_sig_key(a: number, b: number, c: number): void; -export function default_client_for_centralized_kms(a: number): void; -export function new_client(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number): void; -export function get_server_public_keys(a: number, b: number): void; -export function get_client_public_key(a: number): number; -export function get_client_secret_key(a: 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 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 new_eip712_domain(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number): number; -export function new_request_id(a: number, b: number): number; -export function new_fhe_type(a: number, b: number, c: 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, k: number, l: number): void; -export function reencryption_request_to_flat_json_string(a: number, b: number): void; -export function process_reencryption_resp_from_json(a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: 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, j: number): void; -export function cryptobox_sk_to_u8vec(a: number, b: number): void; -export function __wbg_plaintext_free(a: number): void; -export function __wbg_get_plaintext_bytes(a: number, b: number): void; -export function __wbg_set_plaintext_bytes(a: number, b: number, c: 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_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_get_requestid_request_id(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 __wbindgen_malloc(a: number, b: number): number; -export function __wbindgen_realloc(a: number, b: number, c: number, d: number): number; -export function __wbindgen_add_to_stack_pointer(a: number): number; -export function __wbindgen_free(a: number, b: number, c: number): void; -export function __wbindgen_exn_store(a: number): void; diff --git a/src/node.ts b/src/node.ts index efa8079..b570c0c 100644 --- a/src/node.ts +++ b/src/node.ts @@ -1,12 +1,4 @@ //@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'; diff --git a/src/sdk/config.ts b/src/sdk/config.ts new file mode 100644 index 0000000..7247305 --- /dev/null +++ b/src/sdk/config.ts @@ -0,0 +1,91 @@ +import { + BrowserProvider, + Contract, + Eip1193Provider, + JsonRpcProvider, + Provider, +} from 'ethers'; +import { PublicParams } from './encrypt'; +import { getKeysFromGateway } from './network'; +import { fromHexString, cleanURL } from '../utils'; +import { CompactPkePublicParams, TfheCompactPublicKey } from 'node-tfhe'; +import { abi } from '../abi/kmsVerifier.json'; + +export type FhevmInstanceConfig = { + kmsContractAddress: string; + aclContractAddress: string; + chainId?: number; + publicKey?: string; + gatewayUrl?: string; + network?: Eip1193Provider; + networkUrl?: string; + publicParams?: PublicParams; +}; + +export const getProvider = (config: FhevmInstanceConfig) => { + if (config.networkUrl) { + return new JsonRpcProvider(config.networkUrl); + } else if (config.network) { + return new BrowserProvider(config.network); + } + throw new Error( + 'You must provide a network URL or a EIP1193 object (eg: window.ethereum)', + ); +}; + +export const getChainId = async ( + provider: Provider, + config: FhevmInstanceConfig, +): Promise => { + if (config.chainId && typeof config.chainId === 'number') { + return config.chainId; + } else if (config.chainId && typeof config.chainId !== 'number') { + throw new Error('chainId must be a number.'); + } else { + const chainId = (await provider.getNetwork()).chainId; + return Number(chainId); + } +}; + +export const getTfheCompactPublicKey = async (config: FhevmInstanceConfig) => { + if (config.gatewayUrl && !config.publicKey) { + const inputs = await getKeysFromGateway(cleanURL(config.gatewayUrl)); + return inputs.publicKey; + } else if (config.publicKey) { + const buff = fromHexString(config.publicKey); + try { + return TfheCompactPublicKey.deserialize(buff); + } catch (e) { + throw new Error('Invalid public key (deserialization failed)'); + } + } else { + throw new Error('You must provide a public key.'); + } +}; + +export const getPublicParams = async (config: FhevmInstanceConfig) => { + if (config.gatewayUrl && !config.publicParams) { + const inputs = await getKeysFromGateway(cleanURL(config.gatewayUrl)); + return inputs.publicParams; + } else if (config.publicParams && config.publicParams['2048']) { + const buff = fromHexString(config.publicParams['2048']); + try { + return { + '2048': CompactPkePublicParams.deserialize(buff), + }; + } catch (e) { + throw new Error('Invalid public key (deserialization failed)'); + } + } else { + throw new Error('You must provide a valid CRS.'); + } +}; + +export const getKMSSignatures = async ( + provider: Provider, + config: FhevmInstanceConfig, +): Promise => { + const kmsContract = new Contract(config.kmsContractAddress, abi, provider); + const signatures: string[] = await kmsContract.getSigners(); + return signatures; +}; diff --git a/src/sdk/encrypt.test.ts b/src/sdk/encrypt.test.ts index 44e76f4..477ca9a 100644 --- a/src/sdk/encrypt.test.ts +++ b/src/sdk/encrypt.test.ts @@ -1,32 +1,26 @@ -import { - FheUint160, - CompactFheUint160List, - TfheCompactPublicKey, - TfheClientKey, - CompactFheUint2048List, - FheUint2048, -} from 'node-tfhe'; -import { createTfheKeypair } from '../tfhe'; +import { ProvenCompactCiphertextList } from 'node-tfhe'; import { createEncryptedInput } from './encrypt'; -import { fetchJSONRPC } from '../ethCall'; -import { fromHexString } from '../utils'; +import { publicKey, publicParams } from '../test'; +import fetchMock from '@fetch-mock/core'; -describe('encrypt', () => { - let clientKey: TfheClientKey; - let publicKey: TfheCompactPublicKey; - - beforeAll(async () => { - const keypair = createTfheKeypair(); - clientKey = keypair.clientKey; - publicKey = keypair.publicKey; - }); +fetchMock.post('https://test-gateway.net/zkp', { + response: {}, + status: 'success', +}); +describe('encrypt', () => { it('encrypt/decrypt', async () => { - const input = createEncryptedInput(publicKey)( + const input = createEncryptedInput( + '0x325ea1b59F28e9e1C51d3B5b47b7D3965CC5D8C8', + 1234, + 'https://test-gateway.net/', + publicKey, + publicParams, + )( '0x8ba1f109551bd432803012645ac136ddd64dba72', '0xa5e1defb98EFe38EBb2D958CEe052410247F4c80', ); - input.addBool(BigInt(0)); + input.addBool(false); input.add4(2); input.add8(BigInt(43)); input.add16(BigInt(87)); @@ -34,114 +28,113 @@ describe('encrypt', () => { input.add64(BigInt(23393893233)); input.add128(BigInt(233938932390)); input.addAddress('0xa5e1defb98EFe38EBb2D958CEe052410247F4c80'); - const buffer = input.encrypt(); - const compactList = CompactFheUint160List.deserialize(buffer.inputProof); - let encryptedList = compactList.expand(); - expect(encryptedList.length).toBe(8); - encryptedList.forEach((v: FheUint160, i: number) => { - const decrypted = v.decrypt(clientKey); - 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.add256(BigInt('2339389323922393930')); + const buffer = await input.encrypt(); + const compactList = ProvenCompactCiphertextList.safe_deserialize( + buffer.inputProof, + BigInt(1024 * 1024 * 512), + ); + + const types = input.getBits().map((_, i) => compactList.get_kind_of(i)); + const expectedTypes = [0, 2, 4, 8, 9, 10, 11, 12, 13]; + + types.forEach((val, i) => { + expect(val).toBe(expectedTypes[i]); }); - input.resetValues(); - expect(input.getBits().length).toBe(0); - expect(input.getValues().length).toBe(0); }); it('encrypt/decrypt one 0 value', async () => { - const input = createEncryptedInput(publicKey)( + const input = createEncryptedInput( + '0x325ea1b59F28e9e1C51d3B5b47b7D3965CC5D8C8', + 1234, + 'https://test-gateway.net/', + publicKey, + publicParams, + )( '0x8ba1f109551bd432803012645ac136ddd64dba72', '0xa5e1defb98EFe38EBb2D958CEe052410247F4c80', ); input.add128(BigInt(0)); - const buffer = input.encrypt(); - const compactList = CompactFheUint160List.deserialize(buffer.inputProof); - let encryptedList = compactList.expand(); - expect(encryptedList.length).toBe(1); - encryptedList.forEach((v: FheUint160, i: number) => { - const decrypted = v.decrypt(clientKey); - switch (i) { - case 0: - expect(decrypted.toString()).toBe('0'); - break; - } + const buffer = await input.encrypt(); + const compactList = ProvenCompactCiphertextList.safe_deserialize( + buffer.inputProof, + BigInt(1024 * 1024 * 512), + ); + const types = input.getBits().map((_, i) => compactList.get_kind_of(i)); + const expectedTypes = [11]; + + types.forEach((val, i) => { + expect(val).toBe(expectedTypes[i]); }); }); it('encrypt/decrypt one 2048 value', async () => { - const input = createEncryptedInput(publicKey)( + const input = createEncryptedInput( + '0x325ea1b59F28e9e1C51d3B5b47b7D3965CC5D8C8', + 1234, + 'https://test-gateway.net/', + publicKey, + publicParams, + )( '0x8ba1f109551bd432803012645ac136ddd64dba72', '0xa5e1defb98EFe38EBb2D958CEe052410247F4c80', ); - const data = new Uint8Array(64); + const data = new Uint8Array(256); data.set([255], 63); input.addBytes256(data); - const buffer = input.encrypt(); - const compactList = CompactFheUint2048List.deserialize(buffer.inputProof); - let encryptedList = compactList.expand(); - expect(encryptedList.length).toBe(1); - encryptedList.forEach((v: FheUint2048, i: number) => { - const decrypted = v.decrypt(clientKey); - switch (i) { - case 0: - expect(decrypted.toString()).toBe( - '13355433680216258829653813963056604541043899547855704341091828781832225889331072183923741976689688961175617671240445089717606406707212403657580392564654080', - ); - break; - } + const buffer = await input.encrypt(); + const compactList = ProvenCompactCiphertextList.safe_deserialize( + buffer.inputProof, + BigInt(1024 * 1024 * 512), + ); + const types = input.getBits().map((_, i) => compactList.get_kind_of(i)); + const expectedTypes = [16]; + + types.forEach((val, i) => { + expect(val).toBe(expectedTypes[i]); }); }); it('throws errors', async () => { expect(() => - createEncryptedInput()( - '0x8ba1f109551bd432803012645ac136ddd64dba72', - '0xa5e1defb98EFe38EBb2D958CEe052410247F4c80', - ), - ).toThrow( - 'Your instance has been created without the public blockchain key.', - ); + createEncryptedInput( + '0x325ea1b59F28e9e1C51d3B5b47b7D3965CC5D8C8', + 1234, + 'https://test-gateway.net/', + publicKey, + publicParams, + )('0xa5e1defb98EFe38EBb2D958CEe052410247F4c80', '0'), + ).toThrow('User address is not a valid address.'); expect(() => - createEncryptedInput(publicKey)( - '0x8ba1f109551bd432803012645ac136ddd64dba', - '0xa5e1defb98EFe38EBb2D958CEe052410247F4c80', - ), + createEncryptedInput( + '0x325ea1b59F28e9e1C51d3B5b47b7D3965CC5D8C8', + 1234, + 'https://test-gateway.net/', + publicKey, + publicParams, + )('0x0', '0xa5e1defb98EFe38EBb2D958CEe052410247F4c80'), ).toThrow('Contract address is not a valid address.'); expect(() => - createEncryptedInput(publicKey)( + createEncryptedInput( + '0x325ea1b59F28e9e1C51d3B5b47b7D3965CC5D8C8', + 1234, + 'https://test-gateway.net/', + publicKey, + publicParams, + )( '0x8ba1f109551bd432803012645ac136ddd64dba72', '0xa5e1defb98EFe38EBb2D958CEe052410247F4c', ), ).toThrow('User address is not a valid address.'); - const input = createEncryptedInput(publicKey)( + const input = createEncryptedInput( + '0x325ea1b59F28e9e1C51d3B5b47b7D3965CC5D8C8', + 1234, + 'https://test-gateway.net/', + publicKey, + publicParams, + )( '0x8ba1f109551bd432803012645ac136ddd64dba72', '0xa5e1defb98EFe38EBb2D958CEe052410247F4c80', ); @@ -151,7 +144,9 @@ describe('encrypt', () => { 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.addBool(29393 as any)).toThrow( + 'The value must be 1 or 0.', + ); expect(() => input.add4(29393)).toThrow( 'The value exceeds the limit for 4bits integer (15)', ); @@ -176,34 +171,22 @@ describe('encrypt', () => { expect(() => input.addAddress('0x00')).toThrow( 'The value must be a valid address.', ); - - expect(input.getBits().length).toBe(0); - expect(input.getValues().length).toBe(0); }); it('throws if total bits is above 2048', async () => { - const input2 = createEncryptedInput(publicKey)( + const input2 = createEncryptedInput( + '0x325ea1b59F28e9e1C51d3B5b47b7D3965CC5D8C8', + 1234, + 'https://test-gateway.net/', + publicKey, + publicParams, + )( '0x8ba1f109551bd432803012645ac136ddd64dba72', '0xa5e1defb98EFe38EBb2D958CEe052410247F4c80', ); - input2.addBytes256(new Uint8Array(64)); - input2.addBool(false); - expect(() => input2.encrypt()).toThrow( - 'Too many bits in provided values. Maximum is 2048.', - ); - }); - - it('throws if more than 12 values', async () => { - const input2 = createEncryptedInput(publicKey)( - '0x8ba1f109551bd432803012645ac136ddd64dba72', - '0xa5e1defb98EFe38EBb2D958CEe052410247F4c80', - ); - for (let i = 0; i < 13; i++) { - input2.addBool(false); - } - - expect(() => input2.encrypt()).toThrow( - "You can't pack more than 12 values.", + input2.addBytes256(new Uint8Array(256)); + expect(() => input2.addBool(false)).toThrow( + 'Packing more than 2048 bits in a single input ciphertext is unsupported', ); }); }); diff --git a/src/sdk/encrypt.ts b/src/sdk/encrypt.ts index e8984b3..1eb4b3f 100644 --- a/src/sdk/encrypt.ts +++ b/src/sdk/encrypt.ts @@ -1,16 +1,20 @@ -import { isAddress } from 'web3-validator'; +import { isAddress } from 'ethers'; import { Keccak } from 'sha3'; import { TfheCompactPublicKey, - CompactFheUint160List, - CompactFheUint2048List, + CompactCiphertextList, + CompactPkePublicParams, + ZkComputeLoad, } from 'node-tfhe'; -import { bytesToBigInt, fromHexString, toHexString } from '../utils'; +import { + bytesToBigInt, + fromHexString, + SERIALIZED_SIZE_LIMIT_CIPHERTEXT, +} from '../utils'; import { ENCRYPTION_TYPES } from './encryptionTypes'; -import { fetchJSONRPC } from '../ethCall'; -// const publicZkParams = CompactPkePublicParams.deserialize(crsBuffer); +type EncryptionTypes = keyof typeof ENCRYPTION_TYPES; export type ZKInput = { addBool: (value: boolean) => ZKInput; @@ -20,15 +24,16 @@ export type ZKInput = { add32: (value: number | bigint) => ZKInput; add64: (value: number | bigint) => ZKInput; add128: (value: number | bigint) => ZKInput; + add256: (value: number | bigint) => ZKInput; + addBytes64: (value: Uint8Array) => ZKInput; + addBytes128: (value: Uint8Array) => ZKInput; + addBytes256: (value: Uint8Array) => ZKInput; addAddress: (value: string) => ZKInput; - getValues: () => bigint[]; getBits: () => number[]; - resetValues: () => ZKInput; - encrypt: () => { + encrypt: () => Promise<{ handles: Uint8Array[]; inputProof: Uint8Array; - }; - send: () => Promise<{ handles: Uint8Array[]; inputProof: Uint8Array }>; + }>; }; const checkEncryptedValue = (value: number | bigint, bits: number) => { @@ -50,31 +55,19 @@ const checkEncryptedValue = (value: number | bigint, bits: number) => { } }; -const getListType = (bits: (keyof typeof ENCRYPTION_TYPES)[]) => { - // We limit to 12 items because for now we are using FheUint160List - if (bits.length > 12) { - throw new Error("You can't pack more than 12 values."); - } - - if (bits.reduce((total, v) => total + v, 0) > 2048) { - throw new Error('Too many bits in provided values. Maximum is 2048.'); - } - - if (bits.some((v) => v === 2048)) { - return 2048; - } else { - return 160; - } +export type PublicParams = { + [key in EncryptionTypes]?: T; }; 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.', - ); - + ( + aclContractAddress: string, + chainId: number, + gateway: string, + tfheCompactPublicKey: TfheCompactPublicKey, + publicParams: PublicParams, + ) => + (contractAddress: string, callerAddress: string): ZKInput => { if (!isAddress(contractAddress)) { throw new Error('Contract address is not a valid address.'); } @@ -82,10 +75,20 @@ export const createEncryptedInput = if (!isAddress(callerAddress)) { throw new Error('User address is not a valid address.'); } - const publicKey: TfheCompactPublicKey = tfheCompactPublicKey; - const values: bigint[] = []; - const bits: (keyof typeof ENCRYPTION_TYPES)[] = []; + const bits: EncryptionTypes[] = []; + const builder = CompactCiphertextList.builder(publicKey); + const checkLimit = (added: number) => { + if (bits.reduce((acc, val) => acc + Math.max(2, val), 0) + added > 2048) { + throw Error( + 'Packing more than 2048 bits in a single input ciphertext is unsupported', + ); + } + if (bits.length + 1 > 256) + throw Error( + 'Packing more than 256 variables in a single input ciphertext is unsupported', + ); + }; return { addBool(value: boolean | number | bigint) { if (value == null) throw new Error('Missing value'); @@ -100,43 +103,51 @@ export const createEncryptedInput = Number(value) > 1 ) throw new Error('The value must be 1 or 0.'); - values.push(BigInt(value)); - bits.push(1); + checkEncryptedValue(Number(value), 1); + checkLimit(2); + builder.push_boolean(!!value); + bits.push(1); // ebool takes 2 encrypted bits return this; }, add4(value: number | bigint) { checkEncryptedValue(value, 4); - values.push(BigInt(value)); + checkLimit(4); + builder.push_u4(Number(value)); bits.push(4); return this; }, add8(value: number | bigint) { checkEncryptedValue(value, 8); - values.push(BigInt(value)); + checkLimit(8); + builder.push_u8(Number(value)); bits.push(8); return this; }, add16(value: number | bigint) { checkEncryptedValue(value, 16); - values.push(BigInt(value)); + checkLimit(16); + builder.push_u16(Number(value)); bits.push(16); return this; }, add32(value: number | bigint) { checkEncryptedValue(value, 32); - values.push(BigInt(value)); + checkLimit(32); + builder.push_u32(Number(value)); bits.push(32); return this; }, add64(value: number | bigint) { checkEncryptedValue(value, 64); - values.push(BigInt(value)); + checkLimit(64); + builder.push_u64(BigInt(value)); bits.push(64); return this; }, add128(value: number | bigint) { checkEncryptedValue(value, 128); - values.push(BigInt(value)); + checkLimit(128); + builder.push_u128(BigInt(value)); bits.push(128); return this; }, @@ -144,98 +155,108 @@ export const createEncryptedInput = if (!isAddress(value)) { throw new Error('The value must be a valid address.'); } - values.push(BigInt(value)); + checkLimit(160); + builder.push_u160(BigInt(value)); bits.push(160); return this; }, + add256(value: number | bigint) { + checkEncryptedValue(value, 256); + checkLimit(256); + builder.push_u256(BigInt(value)); + bits.push(256); + return this; + }, + addBytes64(value: Uint8Array) { + if (value.length !== 64) + throw Error( + 'Uncorrect length of input Uint8Array, should be 64 for an ebytes64', + ); + const bigIntValue = bytesToBigInt(value); + checkEncryptedValue(bigIntValue, 512); + checkLimit(512); + builder.push_u512(bigIntValue); + bits.push(512); + return this; + }, + addBytes128(value: Uint8Array) { + if (value.length !== 128) + throw Error( + 'Uncorrect length of input Uint8Array, should be 128 for an ebytes128', + ); + const bigIntValue = bytesToBigInt(value); + checkEncryptedValue(bigIntValue, 1024); + checkLimit(1024); + builder.push_u1024(bigIntValue); + bits.push(1024); + return this; + }, addBytes256(value: Uint8Array) { + if (value.length !== 256) + throw Error( + 'Uncorrect length of input Uint8Array, should be 256 for an ebytes256', + ); const bigIntValue = bytesToBigInt(value); checkEncryptedValue(bigIntValue, 2048); - values.push(bigIntValue); + checkLimit(2048); + builder.push_u2048(bigIntValue); bits.push(2048); return this; }, - getValues() { - return values; - }, getBits() { return bits; }, - resetValues() { - values.length = 0; - bits.length = 0; - return this; - }, - encrypt() { - const listType = getListType(bits); + async encrypt() { + const getKeys = (obj: T) => + Object.keys(obj) as Array; - let encrypted; - - switch (listType) { - case 160: { - encrypted = CompactFheUint160List.encrypt_with_compact_public_key( - values, - publicKey, - ); - break; - } - case 2048: { - encrypted = CompactFheUint2048List.encrypt_with_compact_public_key( - values, - publicKey, - ); - break; - } + const totalBits = bits.reduce((total, v) => total + v, 0); + const now = Date.now(); + // const ppTypes = getKeys(publicParams); + const ppTypes = getKeys(publicParams); + const closestPP: EncryptionTypes | undefined = ppTypes.find( + (k) => Number(k) >= totalBits, + ); + if (!closestPP) { + throw new Error( + `Too many bits in provided values. Maximum is ${ + ppTypes[ppTypes.length - 1] + }.`, + ); } - - const inputProof = encrypted.serialize(); - const hash = new Keccak(256).update(Buffer.from(inputProof)).digest(); - // const encrypted = ProvenCompactFheUint160List.encrypt_with_compact_public_key( - // values, - // publicZkParams, - // publicKey, - // ZkComputeLoad.Proof, - // ); - const handles = bits.map((v, i) => { - const dataWithIndex = new Uint8Array(hash.length + 1); - dataWithIndex.set(hash, 0); - dataWithIndex.set([i], hash.length); - const finalHash = new Keccak(256) - .update(Buffer.from(dataWithIndex)) - .digest(); - const dataInput = new Uint8Array(32); - dataInput.set(finalHash, 0); - dataInput.set([i, ENCRYPTION_TYPES[v], 0], 29); - return dataInput; - }); - return { - handles, - inputProof, - }; - }, - async send() { - if (!coprocessorUrl) throw new Error('Coprocessor URL not provided'); - const encrypted = CompactFheUint160List.encrypt_with_compact_public_key( - values, - publicKey, + const pp = publicParams[closestPP]!; + const buffContract = fromHexString(contractAddress); + const buffUser = fromHexString(callerAddress); + const buffAcl = fromHexString(aclContractAddress); + const buffChainId = fromHexString(chainId.toString(16)); + const auxData = new Uint8Array( + buffContract.length + + buffUser.length + + buffAcl.length + + buffChainId.length, + ); + auxData.set(buffContract, 0); + auxData.set(buffUser, 20); + auxData.set(buffAcl, 40); + auxData.set(buffChainId, 60); + const encrypted = builder.build_with_proof_packed( + pp, + auxData, + ZkComputeLoad.Verify, ); - const ciphertext = encrypted.serialize(); - const data = new Uint8Array(1 + bits.length + ciphertext.length); - data.set([bits.length], 0); - bits.forEach((value, index) => { - data.set([ENCRYPTION_TYPES[value] & 0xff], 1 + index); - }); - data.set(ciphertext, bits.length + 1); + const inputProof = encrypted.safe_serialize( + SERIALIZED_SIZE_LIMIT_CIPHERTEXT, + ); const payload = { - jsonrpc: '2.0', - method: 'eth_addUserCiphertext', - params: ['0x' + toHexString(data), contractAddress, callerAddress], - id: 1, + client_address: contractAddress, + caller_address: callerAddress, + ct_proof: inputProof, + max_num_bits: 2048, }; - // Set up the fetch request options + // TODO Send payload const options = { method: 'POST', headers: { @@ -243,20 +264,39 @@ export const createEncryptedInput = }, body: JSON.stringify(payload), }; - let resJson; + + let json; try { - resJson = await fetchJSONRPC(coprocessorUrl, options); + const response = await fetch(`${gateway}zkp`, options); + json = await response.json(); } catch (e) { - throw new Error( - 'Impossible to send input to coprocessor (wrong url?)', - ); + console.log(`${gateway}zkp`); + throw new Error("Gateway didn't response correctly"); + } + let handles: Uint8Array[] = []; + if (json.response.handles && json.response.handles.length > 0) { + handles = json.response.handles.map(fromHexString); + } + + // if no handles has been returned by the gateway, create them + if (!handles.length) { + const hash = new Keccak(256).update(Buffer.from(inputProof)).digest(); + handles = bits.map((v, i) => { + const dataWithIndex = new Uint8Array(hash.length + 1); + dataWithIndex.set(hash, 0); + dataWithIndex.set([i], hash.length); + const finalHash = new Keccak(256) + .update(Buffer.from(dataWithIndex)) + .digest(); + const dataInput = new Uint8Array(32); + dataInput.set(finalHash, 0); + dataInput.set([i, ENCRYPTION_TYPES[v], 0], 29); + return dataInput; + }); } - const inputProof = convertToInputProof(resJson); return { - handles: resJson.handlesList.map((handle: string) => - fromHexString(handle), - ), - inputProof: fromHexString(inputProof), + handles, + inputProof, }; }, }; diff --git a/src/sdk/encryptionTypes.ts b/src/sdk/encryptionTypes.ts index f117dd1..2a0fc9d 100644 --- a/src/sdk/encryptionTypes.ts +++ b/src/sdk/encryptionTypes.ts @@ -1,5 +1,5 @@ export const ENCRYPTION_TYPES = { - 1: 0, + 1: 0, // ebool takes 2 encrypted bits 4: 1, 8: 2, 16: 3, diff --git a/src/sdk/index.test.ts b/src/sdk/index.test.ts index 62f7e74..68473c9 100644 --- a/src/sdk/index.test.ts +++ b/src/sdk/index.test.ts @@ -1,45 +1,61 @@ import { createInstance } from './index'; -import { createTfhePublicKey } from '../tfhe'; +import { publicKey, publicParams } from '../test'; +import { bytesToHex } from '../utils'; -describe('index', () => { - let tfhePublicKey: string; - - beforeAll(async () => { - tfhePublicKey = createTfhePublicKey(); - }); +jest.mock('ethers', () => ({ + JsonRpcProvider: () => ({ + // getSigners: () => ['0x4c102C7cA99d3079fEFF08114d3bad888b9794d9'], + }), + isAddress: () => true, + Contract: () => ({ + getSigners: () => ['0x4c102C7cA99d3079fEFF08114d3bad888b9794d9'], + }), +})); +describe('index', () => { it('creates an instance', async () => { + const serializedPublicKey = bytesToHex(publicKey.serialize()); + const serializedPublicParams = bytesToHex( + publicParams[2048].serialize(false), + ); const instance = await createInstance({ + aclContractAddress: '0x4c102C7cA99d3079fEFF08114d3bad888b9794d9', + kmsContractAddress: '0x325ea1b59F28e9e1C51d3B5b47b7D3965CC5D8C8', chainId: 1234, - publicKey: tfhePublicKey, - }); - expect(instance.reencrypt).toBeDefined(); - expect(instance.createEIP712).toBeDefined(); - expect(instance.generateKeypair).toBeDefined(); - expect(instance.createEncryptedInput).toBeDefined(); - expect(instance.getPublicKey()).toBe(tfhePublicKey); - }); - - it('creates an instance for mock', async () => { - const instance = await createInstance({ - chainId: 1234, + publicKey: serializedPublicKey, + publicParams: { 2048: serializedPublicParams }, + networkUrl: 'https://network.com/', }); expect(instance.reencrypt).toBeDefined(); expect(instance.createEIP712).toBeDefined(); expect(instance.generateKeypair).toBeDefined(); expect(instance.createEncryptedInput).toBeDefined(); + expect(instance.getPublicKey()).toBe(serializedPublicKey); }); it('fails to create an instance', async () => { + const serializedPublicKey = bytesToHex(publicKey.serialize()); + const serializedPublicParams = bytesToHex( + publicParams[2048].serialize(false), + ); await expect( createInstance({ + aclContractAddress: '0x4c102C7cA99d3079fEFF08114d3bad888b9794d9', + kmsContractAddress: '0x325ea1b59F28e9e1C51d3B5b47b7D3965CC5D8C8', chainId: BigInt(1234) as any, - publicKey: tfhePublicKey, + publicKey: serializedPublicKey, + publicParams: { 2048: serializedPublicParams }, + networkUrl: 'https://', }), ).rejects.toThrow('chainId must be a number'); await expect( - createInstance({ chainId: 9000, publicKey: 43 as any }), + createInstance({ + aclContractAddress: '0x4c102C7cA99d3079fEFF08114d3bad888b9794d9', + kmsContractAddress: '0x325ea1b59F28e9e1C51d3B5b47b7D3965CC5D8C8', + chainId: 9000, + publicKey: 43 as any, + }), ).rejects.toThrow('publicKey must be a string'); }); }); diff --git a/src/sdk/index.ts b/src/sdk/index.ts index a33b89a..7f29e3c 100644 --- a/src/sdk/index.ts +++ b/src/sdk/index.ts @@ -1,34 +1,17 @@ -import { TfheCompactPublicKey } from 'node-tfhe'; -import type { Eip1193Provider } from 'ethers'; -import { URL } from 'url'; -import { fromHexString } from '../utils'; -import { ZKInput } from './encrypt'; import { - getPublicKeyFromNetwork, - getPublicKeyFromCoprocessor, - getChainIdFromNetwork, - getChainIdFromEip1193, - getPublicKeyFromEip1193, -} from './network'; + FhevmInstanceConfig, + getChainId, + getKMSSignatures, + getProvider, + getPublicParams, + getTfheCompactPublicKey, +} from './config'; +import { cleanURL } from '../utils'; +import { PublicParams, ZKInput } from './encrypt'; import { createEncryptedInput } from './encrypt'; import { generateKeypair, createEIP712, EIP712 } from './keypair'; import { reencryptRequest } from './reencrypt'; - -export { - getPublicKeyCallParams, - getPublicKeyFromCoprocessor, - getPublicKeyFromNetwork, - getChainIdFromNetwork, -} from './network'; - -type FhevmInstanceConfig = { - chainId?: number; - publicKey?: string; - gatewayUrl?: string; - network?: Eip1193Provider; - networkUrl?: string; - coprocessorUrl?: string; -}; +import { isAddress } from 'ethers'; export type FhevmInstance = { createEncryptedInput: ( @@ -50,71 +33,56 @@ export type FhevmInstance = { userAddress: string, ) => Promise; getPublicKey: () => string | null; + getPublicParams: () => PublicParams; }; export const createInstance = async ( config: FhevmInstanceConfig, ): Promise => { - let { publicKey, networkUrl, network, gatewayUrl, coprocessorUrl } = config; + const { publicKey, kmsContractAddress, aclContractAddress } = config; - if (gatewayUrl) { - gatewayUrl = new URL(gatewayUrl).href; + if (!kmsContractAddress || !isAddress(kmsContractAddress)) { + throw new Error('KMS contract address is not valid or empty'); } - if (networkUrl) { - networkUrl = new URL(networkUrl).href; + if (!aclContractAddress || !isAddress(aclContractAddress)) { + throw new Error('ACL contract address is not valid or empty'); } - if (coprocessorUrl) { - coprocessorUrl = new URL(coprocessorUrl).href; - } + if (publicKey && typeof publicKey !== 'string') + throw new Error('publicKey must be a string'); - let chainId: number; - if (config.chainId && typeof config.chainId === 'number') { - chainId = config.chainId; - } else if (config.chainId && typeof config.chainId !== 'number') { - throw new Error('chainId must be a number.'); - } else if (networkUrl) { - chainId = await getChainIdFromNetwork(networkUrl); - } else if (network) { - chainId = await getChainIdFromEip1193(network); - } else { - throw new Error( - "You didn't provide the chainId nor the network url to get it.", - ); - } + const provider = getProvider(config); - if (coprocessorUrl && !publicKey) { - const data = await getPublicKeyFromCoprocessor(coprocessorUrl); - publicKey = data.publicKey; - } else if (networkUrl && !publicKey) { - publicKey = await getPublicKeyFromNetwork(networkUrl); - } else if (network && !publicKey) { - publicKey = await getPublicKeyFromEip1193(network); + if (!provider) { + throw new Error('No network has been provided!'); } - if (publicKey && typeof publicKey !== 'string') - throw new Error('publicKey must be a string'); + const chainId = await getChainId(provider, config); - let tfheCompactPublicKey: TfheCompactPublicKey | undefined; + const tfheCompactPublicKey = await getTfheCompactPublicKey(config); - if (publicKey) { - const buff = fromHexString(publicKey); - try { - tfheCompactPublicKey = TfheCompactPublicKey.deserialize(buff); - } catch (e) { - throw new Error('Invalid public key (deserialization failed)'); - } - } + const pkePublicParams: PublicParams = await getPublicParams(config); + + const kmsSignatures = await getKMSSignatures(provider, config); return { createEncryptedInput: createEncryptedInput( + aclContractAddress, + chainId, + cleanURL(config.gatewayUrl), tfheCompactPublicKey, - coprocessorUrl, + pkePublicParams, ), generateKeypair, createEIP712: createEIP712(chainId), - reencrypt: reencryptRequest(gatewayUrl), + reencrypt: reencryptRequest( + kmsSignatures, + chainId, + kmsContractAddress, + cleanURL(config.gatewayUrl), + ), getPublicKey: () => publicKey || null, + getPublicParams: () => pkePublicParams || null, }; }; diff --git a/src/sdk/keypair.test.ts b/src/sdk/keypair.test.ts index dc9bbc2..5f6d898 100644 --- a/src/sdk/keypair.test.ts +++ b/src/sdk/keypair.test.ts @@ -5,11 +5,9 @@ import { cryptobox_sk_to_u8vec, u8vec_to_cryptobox_pk, u8vec_to_cryptobox_sk, -} from '../kms/node/kms_lib'; +} from 'node-tkms'; describe('token', () => { - beforeAll(async () => {}); - it('generate a valid keypair', async () => { const keypair = generateKeypair(); diff --git a/src/sdk/keypair.ts b/src/sdk/keypair.ts index 5bd73a9..29cadf4 100644 --- a/src/sdk/keypair.ts +++ b/src/sdk/keypair.ts @@ -5,7 +5,7 @@ import { cryptobox_sk_to_u8vec, cryptobox_pk_to_u8vec, cryptobox_get_pk, -} from '../kms/node/kms_lib.js'; +} from 'node-tkms'; export type EIP712Type = { name: string; type: string }; diff --git a/src/sdk/network.test.ts b/src/sdk/network.test.ts index 9f566bb..f6a34f9 100644 --- a/src/sdk/network.test.ts +++ b/src/sdk/network.test.ts @@ -1,35 +1,23 @@ -import { TfheCompactPublicKey, TfheClientKey } from 'node-tfhe'; -import { createTfheKeypair } from '../tfhe'; -import { createEncryptedInput } from './encrypt'; -import { - getChainIdFromNetwork, - getPublicKeyCallParams, - getPublicKeyFromCoprocessor, - getPublicKeyFromNetwork, -} from './network'; -import { fromHexString } from '../utils'; +import { getKeysFromGateway } from './network'; +import { publicKey, publicParams } from '../test'; +import { bytesToHex } from '../utils'; +import fetchMock from '@fetch-mock/core'; -describe('network', () => { - let clientKey: TfheClientKey; - let publicKey: TfheCompactPublicKey; +fetchMock.get('https://test-gateway.net/keys', { + publicKey: { url: 'https://dummy-pk' }, + crs: { 2048: { url: 'https://dummy-2048' } }, +}); - beforeAll(async () => { - const keypair = createTfheKeypair(); - }); +fetchMock.get('https://dummy-pk', bytesToHex(publicKey.serialize())); +fetchMock.get( + 'https://dummy-2048', + bytesToHex(publicParams[2048].serialize(false)), +); - it('get chainId', async () => { - const chainId = await getChainIdFromNetwork('https://devnet.zama.ai'); - expect(chainId).toBe(8009); - }); - - it('get network key', async () => { - const pk = await getPublicKeyFromNetwork('https://devnet.zama.ai'); - expect(pk!.length).toBe(33106); - }); +describe('network', () => { + it('getInputsFromGateway', async () => { + const material = await getKeysFromGateway('https://test-gateway.net/'); - it('get public key params', async () => { - const params = getPublicKeyCallParams(); - expect(params.to).toBe('0x000000000000000000000000000000000000005d'); - expect(params.data).toBe('0xd9d47bb001'); + expect(material.publicKey.serialize()).toStrictEqual(publicKey.serialize()); }); }); diff --git a/src/sdk/network.ts b/src/sdk/network.ts index c8e007c..c965c5d 100644 --- a/src/sdk/network.ts +++ b/src/sdk/network.ts @@ -1,125 +1,42 @@ +import { CompactPkePublicParams, TfheCompactPublicKey } from 'node-tfhe'; import type { Eip1193Provider } from 'ethers'; -import { decodeAbiBytes, fetchJSONRPC } from '../ethCall'; -import { toHexString } from '../utils'; +import { fromHexString } from '../utils'; -export const getPublicKeyCallParams = () => ({ - to: '0x000000000000000000000000000000000000005d', - data: '0xd9d47bb001', -}); - -export const getChainIdFromEip1193 = async (ethereum: Eip1193Provider) => { - const payload = { - method: 'eth_chainId', - params: [], - }; - - let chainId; - try { - chainId = await ethereum.request(payload); - } catch (e) { - throw new Error('Impossible to fetch chain id (wrong network?)'); - } - return Number(chainId); +export type GatewayKeysItem = { + url: string; + signatures: string[]; }; - -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), +export type GatewayKeys = { + keyId: string; + crsId: string; + publicKey: GatewayKeysItem; + bootstrapKey: GatewayKeysItem; + crs: { + [key: string]: GatewayKeysItem; }; - let chainId; - try { - chainId = await fetchJSONRPC(url, options); - } catch (e) { - throw new Error('Impossible to fetch chain id (wrong url?)'); - } - return Number(chainId); }; -export const getPublicKeyFromEip1193 = async (ethereum: Eip1193Provider) => { - const payload = { - method: 'eth_call', - params: [getPublicKeyCallParams(), 'latest'], - }; - - let publicKey; +export const getKeysFromGateway = async (url: string) => { try { - const rawPubKey = await ethereum.request(payload); - const decodedBytes = decodeAbiBytes(rawPubKey); - publicKey = `0x${toHexString(decodedBytes)}`; - } catch (e) { - throw new Error( - 'Impossible to fetch public key from network (wrong network?)', - ); + const response = await fetch(`${url}keys`); + if (!response.ok) { + throw new Error(`HTTP error! status: ${response.status}`); + } + const data: GatewayKeys = await response.json(); + if (data) { + const publicKey = await (await fetch(data.publicKey.url)).text(); + const crs2048 = await (await fetch(data.crs['2048'].url)).text(); + return { + publicKey: TfheCompactPublicKey.deserialize(fromHexString(publicKey)), + publicParams: { + 2048: CompactPkePublicParams.deserialize(fromHexString(crs2048)), + }, + }; + } else { + throw new Error('No public key available'); + } + } catch (error) { + console.log('error', error); + throw new Error('Impossible to fetch public key: wrong gateway url.'); } - return publicKey; -}; - -// 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), - }; - let publicKey; - try { - publicKey = await fetchJSONRPC(url, options); - } catch (e) { - throw new Error('Impossible to fetch public key from network (wrong url?)'); - } - - return publicKey; -}; - -// 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), - }; - - let publicKey; - try { - publicKey = await fetchJSONRPC(url, options); - } catch (e) { - throw new Error( - 'Impossible to fetch public key from coprocessor (wrong url?)', - ); - } - - return publicKey; }; diff --git a/src/sdk/reencrypt.test.ts b/src/sdk/reencrypt.test.ts index 30dbd1c..2858795 100644 --- a/src/sdk/reencrypt.test.ts +++ b/src/sdk/reencrypt.test.ts @@ -1,41 +1,36 @@ import { reencryptRequest } from './reencrypt'; -import fetchMock from 'fetch-mock'; +import fetchMock from '@fetch-mock/core'; -global.fetch = require('fetch-mock-jest').sandbox(); +fetchMock.mockGlobal(); + +fetchMock.post('https://test-gateway.net/reencrypt', { + status: 'success', + response: {}, +}); + +const userKeypair = { + publicKey: + '0x2000000000000000f3efe739bc5c1f3ecc75ef238bb281358b6ad60a77a68b67888d8802c53e1c59', + privateKey: + '0x20000000000000001c0922c8007e42e2c5f1e6d3221c03703c868cf17636724fe43fb49383a4dfe4', +}; describe('reencrypt', () => { it('get reencryption for handle', async () => { - // const reencrypt = reencryptRequest('http://mock'); - // fetchMock.mock('http://mock/reencrypt', { - // status: 200, - // body: { - // response: { - // mock: 's', - // }, - // }, - // }); + const reencrypt = reencryptRequest( + [], + 9000, + '0x8ba1f109551bd432803012645ac136ddd64dba72', + 'https://test-gateway.net/', + ); // const result = await reencrypt( // BigInt(3333), - // '0xccc', - // '0xcccc', + // userKeypair.privateKey, + // userKeypair.publicKey, // '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 index 919a7e5..31c0f8a 100644 --- a/src/sdk/reencrypt.ts +++ b/src/sdk/reencrypt.ts @@ -1,18 +1,24 @@ +import { Provider } from 'ethers'; import { bytesToBigInt, - bigIntToBytes, + bigIntToBytes256, toHexString, fromHexString, } from '../utils'; import { u8vec_to_cryptobox_pk, - default_client_for_centralized_kms, - process_reencryption_resp_from_json, + new_client, + process_reencryption_resp_from_js, u8vec_to_cryptobox_sk, -} from '../kms/node/kms_lib.js'; +} from 'node-tkms'; export const reencryptRequest = - (gatewayUrl?: string) => + ( + kmsSignatures: string[], + chainId: number, + kmsContractAddress: string, + gatewayUrl: string, + ) => async ( handle: bigint, privateKey: string, @@ -21,8 +27,6 @@ export const reencryptRequest = contractAddress: string, userAddress: string, ) => { - if (!gatewayUrl) throw new Error('You must provide a reencryption URL.'); - const payload = { signature: signature.replace(/^(0x)/, ''), user_address: userAddress.replace(/^(0x)/, ''), @@ -54,18 +58,26 @@ export const reencryptRequest = throw new Error("Gateway didn't response correctly"); } - const client = default_client_for_centralized_kms(); + const client = new_client(kmsSignatures, userAddress, 'default'); try { - const decryption = process_reencryption_resp_from_json( + const eip712Domain = { + name: 'Authorization token', + version: '1', + chain_id: chainId, + verifying_contract: kmsContractAddress, + salt: [], + }; + const decryption = process_reencryption_resp_from_js( client, - undefined, + payload, + eip712Domain, json.response, - undefined, pubKey, privKey, - false, + true, ); + return bytesToBigInt(decryption); } catch (e) { throw new Error('An error occured during decryption'); diff --git a/src/test/index.ts b/src/test/index.ts new file mode 100644 index 0000000..d2bf766 --- /dev/null +++ b/src/test/index.ts @@ -0,0 +1,24 @@ +import { + CompactPkePublicParams, + TfheClientKey, + TfheCompactPublicKey, +} from 'node-tfhe'; +import fs from 'fs'; + +const privKey = fs.readFileSync(`${__dirname}/keys/privateKey.bin`); +const pubKey = fs.readFileSync(`${__dirname}/keys/publicKey.bin`); +const params128 = fs.readFileSync(`${__dirname}/keys/crs128.bin`); +const params256 = fs.readFileSync(`${__dirname}/keys/crs256.bin`); +const params512 = fs.readFileSync(`${__dirname}/keys/crs512.bin`); +const params1024 = fs.readFileSync(`${__dirname}/keys/crs1024.bin`); +const params2048 = fs.readFileSync(`${__dirname}/keys/crs2048.bin`); + +export const privateKey = TfheClientKey.deserialize(privKey); +export const publicKey = TfheCompactPublicKey.deserialize(pubKey); +export const publicParams = { + 128: CompactPkePublicParams.deserialize(params128), + 256: CompactPkePublicParams.deserialize(params256), + 512: CompactPkePublicParams.deserialize(params512), + 1024: CompactPkePublicParams.deserialize(params1024), + 2048: CompactPkePublicParams.deserialize(params2048), +}; diff --git a/src/test/keys/crs1024.bin b/src/test/keys/crs1024.bin new file mode 100644 index 0000000..d552e0c Binary files /dev/null and b/src/test/keys/crs1024.bin differ diff --git a/src/test/keys/crs128.bin b/src/test/keys/crs128.bin new file mode 100644 index 0000000..b12b1b1 Binary files /dev/null and b/src/test/keys/crs128.bin differ diff --git a/src/test/keys/crs2048.bin b/src/test/keys/crs2048.bin new file mode 100644 index 0000000..6a497b8 Binary files /dev/null and b/src/test/keys/crs2048.bin differ diff --git a/src/test/keys/crs256.bin b/src/test/keys/crs256.bin new file mode 100644 index 0000000..221c2a9 Binary files /dev/null and b/src/test/keys/crs256.bin differ diff --git a/src/test/keys/crs512.bin b/src/test/keys/crs512.bin new file mode 100644 index 0000000..ad35038 Binary files /dev/null and b/src/test/keys/crs512.bin differ diff --git a/src/test/keys/privateKey.bin b/src/test/keys/privateKey.bin new file mode 100644 index 0000000..536f1e0 Binary files /dev/null and b/src/test/keys/privateKey.bin differ diff --git a/src/test/keys/publicKey.bin b/src/test/keys/publicKey.bin new file mode 100644 index 0000000..c99fb41 Binary files /dev/null and b/src/test/keys/publicKey.bin differ diff --git a/src/tfhe.ts b/src/tfhe.ts index aa41e3d..7ea39b0 100644 --- a/src/tfhe.ts +++ b/src/tfhe.ts @@ -4,6 +4,9 @@ import { TfheClientKey, ShortintParameters, ShortintParametersName, + CompactPkeCrs, + ShortintCompactPublicKeyEncryptionParameters, + ShortintCompactPublicKeyEncryptionParametersName, } from 'node-tfhe'; import { toHexString } from './utils'; @@ -11,15 +14,17 @@ export const createTfheKeypair = () => { const block_params = new ShortintParameters( ShortintParametersName.PARAM_MESSAGE_2_CARRY_2_COMPACT_PK_PBS_KS, ); - // const configBuilder = new TfheConfigBuilder(); - // const config = configBuilder.use_custom_parameters(block_params).build(); + const casting_params = new ShortintCompactPublicKeyEncryptionParameters( + ShortintCompactPublicKeyEncryptionParametersName.SHORTINT_PARAM_PKE_MESSAGE_2_CARRY_2_KS_PBS_TUNIFORM_2M64, + ); const config = TfheConfigBuilder.default() .use_custom_parameters(block_params) + .use_dedicated_compact_public_key_parameters(casting_params) .build(); let clientKey = TfheClientKey.generate(config); let publicKey = TfheCompactPublicKey.new(clientKey); - publicKey = TfheCompactPublicKey.deserialize(publicKey.serialize()); - return { clientKey, publicKey }; + const crs = CompactPkeCrs.from_config(config, 4 * 512); + return { clientKey, publicKey, crs }; }; export const createTfhePublicKey = (): string => { diff --git a/src/utils.test.ts b/src/utils.test.ts index 4f19ce6..e15022b 100644 --- a/src/utils.test.ts +++ b/src/utils.test.ts @@ -1,34 +1,12 @@ import { - bigIntToBytes, + bigIntToBytes256, bytesToBigInt, bytesToHex, - clientKeyDecryptor, fromHexString, getCiphertextCallParams, - toHexString, } from './utils'; -import { createTfheKeypair } from './tfhe'; -import { - FheBool, - FheUint4, - FheUint8, - FheUint16, - FheUint32, - FheUint64, - FheUint160, - TfheCompactPublicKey, -} from 'node-tfhe'; describe('decrypt', () => { - let clientKeySer: Uint8Array; - let compactPublicKey: TfheCompactPublicKey; - - beforeAll(async () => { - const { clientKey, publicKey } = createTfheKeypair(); - clientKeySer = clientKey.serialize(); - compactPublicKey = publicKey; - }); - it('converts a hex to bytes', async () => { const value = '0xff'; const bytes = fromHexString(value); @@ -48,97 +26,102 @@ describe('decrypt', () => { it('converts a number to bytes', async () => { const value = BigInt(28482); - const bytes = bigIntToBytes(value); - expect(bytes).toEqual(new Uint8Array([66, 111])); + const bytes = bigIntToBytes256(value); + const arr = new Uint8Array(256); + arr[254] = 111; + arr[255] = 66; + expect(bytes).toEqual(arr); const value2 = BigInt(255); - const bytes2 = bigIntToBytes(value2); - expect(bytes2).toEqual(new Uint8Array([255])); + const bytes2 = bigIntToBytes256(value2); + const arr2 = new Uint8Array(256); + arr2[255] = 255; + expect(bytes2).toEqual(arr2); }); it('converts bytes to number', async () => { const value = new Uint8Array([23, 200, 15]); const bigint1 = bytesToBigInt(value); - expect(bigint1.toString()).toBe('1034263'); + expect(bigint1.toString()).toBe('1558543'); const value2 = new Uint8Array([37, 6, 210, 166, 239]); const bigint2 = bytesToBigInt(value2); - expect(bigint2.toString()).toBe('1029295965733'); + expect(bigint2.toString()).toBe('159028258543'); const value0 = new Uint8Array(); const bigint0 = bytesToBigInt(value0); expect(bigint0.toString()).toBe('0'); }); - it('decryptor bool', async () => { - const d = clientKeyDecryptor(clientKeySer); - const c = FheBool.encrypt_with_compact_public_key( - true, - compactPublicKey, - ).serialize(); - const v = await d.decryptBool(toHexString(c)); - expect(v).toBe(true); - }); - - it('decryptor 4', async () => { - const d = clientKeyDecryptor(clientKeySer); - const c = FheUint4.encrypt_with_compact_public_key( - 4, - compactPublicKey, - ).serialize(); - const v = await d.decrypt4(toHexString(c)); - expect(v).toBe(4); - }); - - it('decryptor 8', async () => { - const d = clientKeyDecryptor(clientKeySer); - const c = FheUint8.encrypt_with_compact_public_key( - 67, - compactPublicKey, - ).serialize(); - const v = await d.decrypt8(toHexString(c)); - expect(v).toBe(67); - }); - - it('decryptor 16', async () => { - const d = clientKeyDecryptor(clientKeySer); - const c = FheUint16.encrypt_with_compact_public_key( - 1700, - compactPublicKey, - ).serialize(); - const v = await d.decrypt16(toHexString(c)); - expect(v).toBe(1700); - }); - - it('decryptor 32', async () => { - const d = clientKeyDecryptor(clientKeySer); - const c = FheUint32.encrypt_with_compact_public_key( - 77662, - compactPublicKey, - ).serialize(); - const v = await d.decrypt32(toHexString(c)); - expect(v).toBe(77662); - }); - - it('decryptor 64', async () => { - const d = clientKeyDecryptor(clientKeySer); - const c = FheUint64.encrypt_with_compact_public_key( - BigInt(11200), - compactPublicKey, - ).serialize(); - const v = await d.decrypt64(toHexString(c)); - expect(v).toBe(BigInt(11200)); - }); - - it('decryptor address', async () => { - const d = clientKeyDecryptor(clientKeySer); - const c = FheUint160.encrypt_with_compact_public_key( - BigInt('0x8ba1f109551bd432803012645ac136ddd64dba72'), - compactPublicKey, - ).serialize(); - const v = await d.decryptAddress(toHexString(c)); - expect(v).toBe('0x8ba1f109551bd432803012645ac136ddd64dba72'); - }); + // it('decryptor bool', async () => { + // const d = clientKeyDecryptor(clientKeySer); + // const c = FheBool.encrypt_with_compact_public_key( + // true, + // compactPublicKey, + // ).serialize(); + // const v = await d.decryptBool(toHexString(c)); + // expect(v).toBe(true); + // }); + + // it('decryptor 4', async () => { + // const d = clientKeyDecryptor(clientKeySer); + // const c = FheUint4.encrypt_with_compact_public_key( + // 4, + // compactPublicKey, + // ).serialize(); + // const v = await d.decrypt4(toHexString(c)); + // expect(v).toBe(4); + // }); + + // it('decryptor 8', async () => { + // const d = clientKeyDecryptor(clientKeySer); + // const c = FheUint8.encrypt_with_compact_public_key( + // 67, + // compactPublicKey, + // ).serialize(); + // const v = await d.decrypt8(toHexString(c)); + // expect(v).toBe(67); + // }); + + // it('decryptor 16', async () => { + // const d = clientKeyDecryptor(clientKeySer); + // const c = FheUint16.encrypt_with_compact_public_key( + // 1700, + // compactPublicKey, + // ).serialize(); + // const v = await d.decrypt16(toHexString(c)); + // expect(v).toBe(1700); + // }); + + // it('decryptor 32', async () => { + // const d = clientKeyDecryptor(clientKeySer); + // const c = FheUint32.encrypt_with_compact_public_key( + // 77662, + // compactPublicKey, + // ).serialize(); + // const v = await d.decrypt32(toHexString(c)); + // expect(v).toBe(77662); + // }); + + // it('decryptor 64', async () => { + // const d = clientKeyDecryptor(clientKeySer); + // const c = FheUint64.encrypt_with_compact_public_key( + // BigInt(11200), + // compactPublicKey, + // ).serialize(); + // const v = await d.decrypt64(toHexString(c)); + // expect(v).toBe(BigInt(11200)); + // }); + + // it('decryptor address', async () => { + // const d = clientKeyDecryptor(clientKeySer); + // const c = FheUint160.encrypt_with_compact_public_key( + // BigInt('0x8ba1f109551bd432803012645ac136ddd64dba72'), + // compactPublicKey, + // ).serialize(); + // const v = await d.decryptAddress(toHexString(c)); + // expect(v).toBe('0x8ba1f109551bd432803012645ac136ddd64dba72'); + // }); it('returns ciphertext call params', async () => { const params = getCiphertextCallParams(BigInt(23)); diff --git a/src/utils.ts b/src/utils.ts index 649da3a..3ccd750 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,4 +1,4 @@ -import { toBigIntLE, toBufferLE } from 'bigint-buffer'; +import { toBigIntBE, toBufferBE } from 'bigint-buffer'; import { FheBool, FheUint4, @@ -10,6 +10,15 @@ import { TfheClientKey, } from 'node-tfhe'; +export const SERIALIZED_SIZE_LIMIT_CIPHERTEXT = BigInt(1024 * 1024 * 512); +export const SERIALIZED_SIZE_LIMIT_PK = BigInt(1024 * 1024 * 512); +export const SERIALIZED_SIZE_LIMIT_CRS = BigInt(1024 * 1024 * 512); + +export const cleanURL = (url: string | undefined) => { + if (!url) return ''; + return new URL(url).href; +}; + export const fromHexString = (hexString: string): Uint8Array => { const arr = hexString.replace(/^(0x)/, '').match(/.{1,2}/g); if (!arr) return new Uint8Array(); @@ -19,9 +28,16 @@ export const fromHexString = (hexString: string): Uint8Array => { export const toHexString = (bytes: Uint8Array) => bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, '0'), ''); -export const bigIntToBytes = (value: bigint) => { - const byteArrayLength = Math.ceil(value.toString(2).length / 8); - return new Uint8Array(toBufferLE(value, byteArrayLength)); +export const bigIntToBytes64 = (value: bigint) => { + return new Uint8Array(toBufferBE(value, 64)); +}; + +export const bigIntToBytes128 = (value: bigint) => { + return new Uint8Array(toBufferBE(value, 128)); +}; + +export const bigIntToBytes256 = (value: bigint) => { + return new Uint8Array(toBufferBE(value, 256)); }; export const bytesToHex = function (byteArray: Uint8Array): string { @@ -38,7 +54,7 @@ export const bytesToBigInt = function (byteArray: Uint8Array): bigint { } const buffer = Buffer.from(byteArray); - const result = toBigIntLE(buffer); + const result = toBigIntBE(buffer); return result; }; @@ -46,19 +62,40 @@ export const clientKeyDecryptor = (clientKeySer: Uint8Array) => { const clientKey = TfheClientKey.deserialize(clientKeySer); return { decryptBool: (ciphertext: string) => - FheBool.deserialize(fromHexString(ciphertext)).decrypt(clientKey), + FheBool.safe_deserialize( + fromHexString(ciphertext), + SERIALIZED_SIZE_LIMIT_CIPHERTEXT, + ).decrypt(clientKey), decrypt4: (ciphertext: string) => - FheUint4.deserialize(fromHexString(ciphertext)).decrypt(clientKey), + FheUint4.safe_deserialize( + fromHexString(ciphertext), + SERIALIZED_SIZE_LIMIT_CIPHERTEXT, + ).decrypt(clientKey), decrypt8: (ciphertext: string) => - FheUint8.deserialize(fromHexString(ciphertext)).decrypt(clientKey), + FheUint8.safe_deserialize( + fromHexString(ciphertext), + SERIALIZED_SIZE_LIMIT_CIPHERTEXT, + ).decrypt(clientKey), decrypt16: (ciphertext: string) => - FheUint16.deserialize(fromHexString(ciphertext)).decrypt(clientKey), + FheUint16.safe_deserialize( + fromHexString(ciphertext), + SERIALIZED_SIZE_LIMIT_CIPHERTEXT, + ).decrypt(clientKey), decrypt32: (ciphertext: string) => - FheUint32.deserialize(fromHexString(ciphertext)).decrypt(clientKey), + FheUint32.safe_deserialize( + fromHexString(ciphertext), + SERIALIZED_SIZE_LIMIT_CIPHERTEXT, + ).decrypt(clientKey), decrypt64: (ciphertext: string) => - FheUint64.deserialize(fromHexString(ciphertext)).decrypt(clientKey), + FheUint64.safe_deserialize( + fromHexString(ciphertext), + SERIALIZED_SIZE_LIMIT_CIPHERTEXT, + ).decrypt(clientKey), decryptAddress: (ciphertext: string) => { - let hex = FheUint160.deserialize(fromHexString(ciphertext)) + let hex = FheUint160.safe_deserialize( + fromHexString(ciphertext), + SERIALIZED_SIZE_LIMIT_CIPHERTEXT, + ) .decrypt(clientKey) .toString(16); while (hex.length < 40) { diff --git a/tsconfig.rollup.json b/tsconfig.rollup.json index 13fdbe3..75b04ee 100644 --- a/tsconfig.rollup.json +++ b/tsconfig.rollup.json @@ -11,7 +11,7 @@ "allowJs": true, "strict": true, "baseUrl": ".", - "resolveJsonModule": false, + "resolveJsonModule": true, "paths": { "*": ["*"] }