From 016dc28bd56ee8a232a507c35dc582d2a64aa43f Mon Sep 17 00:00:00 2001 From: David Rodriguez <70919589+daveroga@users.noreply.github.com> Date: Tue, 17 Dec 2024 17:43:30 +0100 Subject: [PATCH] Revert "Add support of Auth V2 validator (#281)" This reverts commit 812ce463d042157b1e802dcfc06ea06cb81f9928. --- .mocharc.json | 2 +- package-lock.json | 352 ++++++++++-------- package.json | 2 +- src/circuits/auth-v2.ts | 17 +- src/iden3comm/handlers/contract-request.ts | 13 +- src/iden3comm/utils/contract-request.utils.ts | 66 ---- src/iden3comm/utils/index.ts | 1 - src/proof/proof-service.ts | 17 - .../blockchain/onchain-zkp-verifier.ts | 169 ++++----- src/utils/did-helper.ts | 11 +- tests/handlers/contract-request.test.ts | 132 +++---- tests/handlers/payment.test.ts | 8 +- 12 files changed, 344 insertions(+), 446 deletions(-) delete mode 100644 src/iden3comm/utils/contract-request.utils.ts diff --git a/.mocharc.json b/.mocharc.json index 08de8748..954b0050 100644 --- a/.mocharc.json +++ b/.mocharc.json @@ -4,6 +4,6 @@ ], "spec": "tests/**/*.test.ts", "require": "ts-node/register", - "timeout": "400000", + "timeout": "300000", "maxDiffSize": "10000" } diff --git a/package-lock.json b/package-lock.json index 108bc1e3..2d0cd514 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@0xpolygonid/js-sdk", - "version": "1.25.1", + "version": "1.25.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@0xpolygonid/js-sdk", - "version": "1.25.1", + "version": "1.25.0", "license": "MIT or Apache-2.0", "dependencies": { "@iden3/onchain-non-merklized-issuer-base-abi": "^0.0.3", @@ -81,73 +81,76 @@ "license": "MIT" }, "node_modules/@cspell/cspell-bundled-dicts": { - "version": "8.14.2", - "resolved": "https://registry.npmjs.org/@cspell/cspell-bundled-dicts/-/cspell-bundled-dicts-8.14.2.tgz", - "integrity": "sha512-Kv2Utj/RTSxfufGXkkoTZ/3ErCsYWpCijtDFr/FwSsM7mC0PzLpdlcD9xjtgrJO5Kwp7T47iTG21U4Mwddyi8Q==", - "dev": true, - "license": "MIT", - "dependencies": { - "@cspell/dict-ada": "^4.0.2", - "@cspell/dict-aws": "^4.0.3", - "@cspell/dict-bash": "^4.1.3", - "@cspell/dict-companies": "^3.1.4", - "@cspell/dict-cpp": "^5.1.12", - "@cspell/dict-cryptocurrencies": "^5.0.0", - "@cspell/dict-csharp": "^4.0.2", - "@cspell/dict-css": "^4.0.13", - "@cspell/dict-dart": "^2.0.3", - "@cspell/dict-django": "^4.1.0", - "@cspell/dict-docker": "^1.1.7", - "@cspell/dict-dotnet": "^5.0.2", - "@cspell/dict-elixir": "^4.0.3", - "@cspell/dict-en_us": "^4.3.23", - "@cspell/dict-en-common-misspellings": "^2.0.4", + "version": "8.16.0", + "resolved": "https://registry.npmjs.org/@cspell/cspell-bundled-dicts/-/cspell-bundled-dicts-8.16.0.tgz", + "integrity": "sha512-R0Eqq5kTZnmZ0elih5uY3TWjMqqAeMl7ciU7maUs+m1FNjCEdJXtJ9wrQxNgjmXi0tX8cvahZRO3O558tEz/KA==", + "dev": true, + "license": "MIT", + "dependencies": { + "@cspell/dict-ada": "^4.0.5", + "@cspell/dict-al": "^1.0.3", + "@cspell/dict-aws": "^4.0.7", + "@cspell/dict-bash": "^4.1.8", + "@cspell/dict-companies": "^3.1.7", + "@cspell/dict-cpp": "^6.0.1", + "@cspell/dict-cryptocurrencies": "^5.0.3", + "@cspell/dict-csharp": "^4.0.5", + "@cspell/dict-css": "^4.0.16", + "@cspell/dict-dart": "^2.2.4", + "@cspell/dict-django": "^4.1.3", + "@cspell/dict-docker": "^1.1.11", + "@cspell/dict-dotnet": "^5.0.8", + "@cspell/dict-elixir": "^4.0.6", + "@cspell/dict-en_us": "^4.3.26", + "@cspell/dict-en-common-misspellings": "^2.0.7", "@cspell/dict-en-gb": "1.1.33", - "@cspell/dict-filetypes": "^3.0.4", - "@cspell/dict-fonts": "^4.0.0", - "@cspell/dict-fsharp": "^1.0.1", - "@cspell/dict-fullstack": "^3.2.0", - "@cspell/dict-gaming-terms": "^1.0.5", - "@cspell/dict-git": "^3.0.0", - "@cspell/dict-golang": "^6.0.9", - "@cspell/dict-google": "^1.0.1", - "@cspell/dict-haskell": "^4.0.1", - "@cspell/dict-html": "^4.0.5", - "@cspell/dict-html-symbol-entities": "^4.0.0", - "@cspell/dict-java": "^5.0.7", - "@cspell/dict-julia": "^1.0.1", - "@cspell/dict-k8s": "^1.0.6", - "@cspell/dict-latex": "^4.0.0", - "@cspell/dict-lorem-ipsum": "^4.0.0", - "@cspell/dict-lua": "^4.0.3", - "@cspell/dict-makefile": "^1.0.0", - "@cspell/dict-monkeyc": "^1.0.6", - "@cspell/dict-node": "^5.0.1", - "@cspell/dict-npm": "^5.0.18", - "@cspell/dict-php": "^4.0.8", - "@cspell/dict-powershell": "^5.0.5", - "@cspell/dict-public-licenses": "^2.0.7", - "@cspell/dict-python": "^4.2.4", - "@cspell/dict-r": "^2.0.1", - "@cspell/dict-ruby": "^5.0.2", - "@cspell/dict-rust": "^4.0.5", - "@cspell/dict-scala": "^5.0.3", - "@cspell/dict-software-terms": "^4.0.6", - "@cspell/dict-sql": "^2.1.5", - "@cspell/dict-svelte": "^1.0.2", - "@cspell/dict-swift": "^2.0.1", - "@cspell/dict-terraform": "^1.0.0", - "@cspell/dict-typescript": "^3.1.6", - "@cspell/dict-vue": "^3.0.0" + "@cspell/dict-filetypes": "^3.0.8", + "@cspell/dict-flutter": "^1.0.3", + "@cspell/dict-fonts": "^4.0.3", + "@cspell/dict-fsharp": "^1.0.4", + "@cspell/dict-fullstack": "^3.2.3", + "@cspell/dict-gaming-terms": "^1.0.8", + "@cspell/dict-git": "^3.0.3", + "@cspell/dict-golang": "^6.0.16", + "@cspell/dict-google": "^1.0.4", + "@cspell/dict-haskell": "^4.0.4", + "@cspell/dict-html": "^4.0.10", + "@cspell/dict-html-symbol-entities": "^4.0.3", + "@cspell/dict-java": "^5.0.10", + "@cspell/dict-julia": "^1.0.4", + "@cspell/dict-k8s": "^1.0.9", + "@cspell/dict-latex": "^4.0.3", + "@cspell/dict-lorem-ipsum": "^4.0.3", + "@cspell/dict-lua": "^4.0.6", + "@cspell/dict-makefile": "^1.0.3", + "@cspell/dict-markdown": "^2.0.7", + "@cspell/dict-monkeyc": "^1.0.9", + "@cspell/dict-node": "^5.0.5", + "@cspell/dict-npm": "^5.1.11", + "@cspell/dict-php": "^4.0.13", + "@cspell/dict-powershell": "^5.0.13", + "@cspell/dict-public-licenses": "^2.0.11", + "@cspell/dict-python": "^4.2.12", + "@cspell/dict-r": "^2.0.4", + "@cspell/dict-ruby": "^5.0.7", + "@cspell/dict-rust": "^4.0.9", + "@cspell/dict-scala": "^5.0.6", + "@cspell/dict-software-terms": "^4.1.13", + "@cspell/dict-sql": "^2.1.8", + "@cspell/dict-svelte": "^1.0.5", + "@cspell/dict-swift": "^2.0.4", + "@cspell/dict-terraform": "^1.0.6", + "@cspell/dict-typescript": "^3.1.11", + "@cspell/dict-vue": "^3.0.3" }, "engines": { "node": ">=18" } }, "node_modules/@cspell/cspell-pipe": { - "version": "8.14.2", - "resolved": "https://registry.npmjs.org/@cspell/cspell-pipe/-/cspell-pipe-8.14.2.tgz", - "integrity": "sha512-aWMoXZAXEre0/M9AYWOW33YyOJZ06i4vvsEpWBDWpHpWQEmsR/7cMMgld8Pp3wlEjIUclUAKTYmrZ61PFWU/og==", + "version": "8.16.0", + "resolved": "https://registry.npmjs.org/@cspell/cspell-pipe/-/cspell-pipe-8.16.0.tgz", + "integrity": "sha512-WoCgrv/mrtwCY4lhc6vEcqN3AQ7lT6K0NW5ShoSo116U2tRaW0unApIYH4Va8u7T9g3wyspFEceQRR1xD9qb9w==", "dev": true, "license": "MIT", "engines": { @@ -155,9 +158,9 @@ } }, "node_modules/@cspell/cspell-resolver": { - "version": "8.14.2", - "resolved": "https://registry.npmjs.org/@cspell/cspell-resolver/-/cspell-resolver-8.14.2.tgz", - "integrity": "sha512-pSyBsAvslaN0dx0pHdvECJEuFDDBJGAD6G8U4BVbIyj2OPk0Ox0HrZIj6csYxxoJERAgNO/q7yCPwa4j9NNFXg==", + "version": "8.16.0", + "resolved": "https://registry.npmjs.org/@cspell/cspell-resolver/-/cspell-resolver-8.16.0.tgz", + "integrity": "sha512-b+99bph43ptkXlQHgPXSkN/jK6LQHy2zL1Fm9up7+x6Yr64bxAzWzoeqJAPtnrPvFuOrFN0jZasZzKBw8CvrrQ==", "dev": true, "license": "MIT", "dependencies": { @@ -168,9 +171,9 @@ } }, "node_modules/@cspell/cspell-service-bus": { - "version": "8.14.2", - "resolved": "https://registry.npmjs.org/@cspell/cspell-service-bus/-/cspell-service-bus-8.14.2.tgz", - "integrity": "sha512-WUF7xf3YgXYIqjmBwLcVugYIrYL4WfXchgSo9rmbbnOcAArzsK+HKfzb4AniZAJ1unxcIQ0JnVlRmnCAKPjjLg==", + "version": "8.16.0", + "resolved": "https://registry.npmjs.org/@cspell/cspell-service-bus/-/cspell-service-bus-8.16.0.tgz", + "integrity": "sha512-+fn763JKA4EYCOv+1VShFq015UMEBAFRDr+rlCnesgLE0fv9TSFVLsjOfh9/g6GuGQLCRLUqKztwwuueeErstQ==", "dev": true, "license": "MIT", "engines": { @@ -178,9 +181,9 @@ } }, "node_modules/@cspell/cspell-types": { - "version": "8.14.2", - "resolved": "https://registry.npmjs.org/@cspell/cspell-types/-/cspell-types-8.14.2.tgz", - "integrity": "sha512-MRY8MjBNOKGMDSkxAKueYAgVL43miO+lDcLCBBP+7cNXqHiUFMIZteONcGp3kJT0dWS04dN6lKAXvaNF0aWcng==", + "version": "8.16.0", + "resolved": "https://registry.npmjs.org/@cspell/cspell-types/-/cspell-types-8.16.0.tgz", + "integrity": "sha512-bGrIK7p4NVsK+QX/CYWmjax+FkzfSIZaIaoiBESGV5gmwgXDVRMJ3IP6tQVAmTtckOYHCmtT5CZgI8zXWr8dHQ==", "dev": true, "license": "MIT", "engines": { @@ -188,9 +191,16 @@ } }, "node_modules/@cspell/dict-ada": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/@cspell/dict-ada/-/dict-ada-4.0.2.tgz", - "integrity": "sha512-0kENOWQeHjUlfyId/aCM/mKXtkEgV0Zu2RhUXCBr4hHo9F9vph+Uu8Ww2b0i5a4ZixoIkudGA+eJvyxrG1jUpA==", + "version": "4.0.5", + "resolved": "https://registry.npmjs.org/@cspell/dict-ada/-/dict-ada-4.0.5.tgz", + "integrity": "sha512-6/RtZ/a+lhFVmrx/B7bfP7rzC4yjEYe8o74EybXcvu4Oue6J4Ey2WSYj96iuodloj1LWrkNCQyX5h4Pmcj0Iag==", + "dev": true, + "license": "MIT" + }, + "node_modules/@cspell/dict-al": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@cspell/dict-al/-/dict-al-1.0.3.tgz", + "integrity": "sha512-V1HClwlfU/qwSq2Kt+MkqRAsonNu3mxjSCDyGRecdLGIHmh7yeEeaxqRiO/VZ4KP+eVSiSIlbwrb5YNFfxYZbw==", "dev": true, "license": "MIT" }, @@ -216,9 +226,9 @@ "license": "MIT" }, "node_modules/@cspell/dict-cpp": { - "version": "5.1.16", - "resolved": "https://registry.npmjs.org/@cspell/dict-cpp/-/dict-cpp-5.1.16.tgz", - "integrity": "sha512-32fU5RkuOM55IRcxjByiSoKbjr+C4danDfYjHaQNRWdvjzJzci3fLDGA2wTXiclkgDODxGiV8LCTUwCz+3TNWA==", + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/@cspell/dict-cpp/-/dict-cpp-6.0.2.tgz", + "integrity": "sha512-yw5eejWvY4bAnc6LUA44m4WsFwlmgPt2uMSnO7QViGMBDuoeopMma4z9XYvs4lSjTi8fIJs/A1YDfM9AVzb8eg==", "dev": true, "license": "MIT" }, @@ -286,9 +296,9 @@ "license": "MIT" }, "node_modules/@cspell/dict-en_us": { - "version": "4.3.23", - "resolved": "https://registry.npmjs.org/@cspell/dict-en_us/-/dict-en_us-4.3.23.tgz", - "integrity": "sha512-l0SoEQBsi3zDSl3OuL4/apBkxjuj4hLIg/oy6+gZ7LWh03rKdF6VNtSZNXWAmMY+pmb1cGA3ouleTiJIglbsIg==", + "version": "4.3.27", + "resolved": "https://registry.npmjs.org/@cspell/dict-en_us/-/dict-en_us-4.3.27.tgz", + "integrity": "sha512-7JYHahRWpi0VykWFTSM03KL/0fs6YtYfpOaTAg4N/d0wB2GfwVG/FJ/SBCjD4LBc6Rx9dzdo95Hs4BB8GPQbOA==", "dev": true, "license": "MIT" }, @@ -313,6 +323,13 @@ "dev": true, "license": "MIT" }, + "node_modules/@cspell/dict-flutter": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/@cspell/dict-flutter/-/dict-flutter-1.0.3.tgz", + "integrity": "sha512-52C9aUEU22ptpgYh6gQyIdA4MP6NPwzbEqndfgPh3Sra191/kgs7CVqXiO1qbtZa9gnYHUoVApkoxRE7mrXHfg==", + "dev": true, + "license": "MIT" + }, "node_modules/@cspell/dict-fonts": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/@cspell/dict-fonts/-/dict-fonts-4.0.3.tgz", @@ -432,6 +449,19 @@ "dev": true, "license": "MIT" }, + "node_modules/@cspell/dict-markdown": { + "version": "2.0.7", + "resolved": "https://registry.npmjs.org/@cspell/dict-markdown/-/dict-markdown-2.0.7.tgz", + "integrity": "sha512-F9SGsSOokFn976DV4u/1eL4FtKQDSgJHSZ3+haPRU5ki6OEqojxKa8hhj4AUrtNFpmBaJx/WJ4YaEzWqG7hgqg==", + "dev": true, + "license": "MIT", + "peerDependencies": { + "@cspell/dict-css": "^4.0.16", + "@cspell/dict-html": "^4.0.10", + "@cspell/dict-html-symbol-entities": "^4.0.3", + "@cspell/dict-typescript": "^3.1.11" + } + }, "node_modules/@cspell/dict-monkeyc": { "version": "1.0.9", "resolved": "https://registry.npmjs.org/@cspell/dict-monkeyc/-/dict-monkeyc-1.0.9.tgz", @@ -440,9 +470,9 @@ "license": "MIT" }, "node_modules/@cspell/dict-node": { - "version": "5.0.1", - "resolved": "https://registry.npmjs.org/@cspell/dict-node/-/dict-node-5.0.1.tgz", - "integrity": "sha512-lax/jGz9h3Dv83v8LHa5G0bf6wm8YVRMzbjJPG/9rp7cAGPtdrga+XANFq+B7bY5+jiSA3zvj10LUFCFjnnCCg==", + "version": "5.0.5", + "resolved": "https://registry.npmjs.org/@cspell/dict-node/-/dict-node-5.0.5.tgz", + "integrity": "sha512-7NbCS2E8ZZRZwlLrh2sA0vAk9n1kcTUiRp/Nia8YvKaItGXLfxYqD2rMQ3HpB1kEutal6hQLVic3N2Yi1X7AaA==", "dev": true, "license": "MIT" }, @@ -541,9 +571,9 @@ "license": "MIT" }, "node_modules/@cspell/dict-terraform": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/@cspell/dict-terraform/-/dict-terraform-1.0.1.tgz", - "integrity": "sha512-29lmUUnZgPh+ieZ5hunick8hzNIpNRtiJh9vAusNskPCrig3RTW6u7F+GG1a8uyslbzSw+Irjf40PTOan1OJJA==", + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/@cspell/dict-terraform/-/dict-terraform-1.0.6.tgz", + "integrity": "sha512-Sqm5vGbXuI9hCFcr4w6xWf4Y25J9SdleE/IqfM6RySPnk8lISEmVdax4k6+Kinv9qaxyvnIbUUN4WFLWcBPQAg==", "dev": true, "license": "MIT" }, @@ -562,9 +592,9 @@ "license": "MIT" }, "node_modules/@cspell/dynamic-import": { - "version": "8.14.2", - "resolved": "https://registry.npmjs.org/@cspell/dynamic-import/-/dynamic-import-8.14.2.tgz", - "integrity": "sha512-5MbqtIligU7yPwHWU/5yFCgMvur4i1bRAF1Cy8y2dDtHsa204S/w/SaXs+51EFLp2eNbCiBisCBrwJFT7R1RxA==", + "version": "8.16.0", + "resolved": "https://registry.npmjs.org/@cspell/dynamic-import/-/dynamic-import-8.16.0.tgz", + "integrity": "sha512-FH+B5y71qfunagXiLSJhXP9h/Vwb1Z8Cc/hLmliGekw/Y8BuYknL86tMg9grXBYNmM0kifIv6ZesQl8Km/p/rA==", "dev": true, "license": "MIT", "dependencies": { @@ -575,16 +605,16 @@ } }, "node_modules/@cspell/eslint-plugin": { - "version": "8.14.2", - "resolved": "https://registry.npmjs.org/@cspell/eslint-plugin/-/eslint-plugin-8.14.2.tgz", - "integrity": "sha512-SU8OPwkNFjRmYyMuwA1O6L1GsKw2pjLogBKsIR1iBQaVNvIf2JiwqjO0xB+UQnJHlqHzR2VuarR9mJUMNuy4tg==", + "version": "8.16.0", + "resolved": "https://registry.npmjs.org/@cspell/eslint-plugin/-/eslint-plugin-8.16.0.tgz", + "integrity": "sha512-j4vmbq30cq2kRR5xMAjfLraFW6ZrSxlAbEk06vC1T3Zxl9fOclOQVsxZ2afLd7TB0NKsrSjS2mFBHBlNkDmSFA==", "dev": true, "license": "MIT", "dependencies": { - "@cspell/cspell-types": "8.14.2", - "@cspell/url": "8.14.2", - "cspell-lib": "8.14.2", - "synckit": "^0.9.1" + "@cspell/cspell-types": "8.16.0", + "@cspell/url": "8.16.0", + "cspell-lib": "8.16.0", + "synckit": "^0.9.2" }, "engines": { "node": ">=18" @@ -594,9 +624,9 @@ } }, "node_modules/@cspell/filetypes": { - "version": "8.14.2", - "resolved": "https://registry.npmjs.org/@cspell/filetypes/-/filetypes-8.14.2.tgz", - "integrity": "sha512-ZevArA0mWeVTTqHicxCPZIAeCibpY3NwWK/x6d1Lgu7RPk/daoGAM546Q2SLChFu+r10tIH7pRG212A6Q9ihPA==", + "version": "8.16.0", + "resolved": "https://registry.npmjs.org/@cspell/filetypes/-/filetypes-8.16.0.tgz", + "integrity": "sha512-u2Ub0uSwXFPJFvXhAO/0FZBj3sMr4CeYCiQwTUsdFRkRMFpbTc7Vf+a+aC2vIj6WcaWrYXrJy3NZF/yjqF6SGw==", "dev": true, "license": "MIT", "engines": { @@ -604,9 +634,9 @@ } }, "node_modules/@cspell/strong-weak-map": { - "version": "8.14.2", - "resolved": "https://registry.npmjs.org/@cspell/strong-weak-map/-/strong-weak-map-8.14.2.tgz", - "integrity": "sha512-7sRzJc392CQYNNrtdPEfOHJdRqsqf6nASCtbS5A9hL2UrdWQ4uN7r/D+Y1HpuizwY9eOkZvarcFfsYt5wE0Pug==", + "version": "8.16.0", + "resolved": "https://registry.npmjs.org/@cspell/strong-weak-map/-/strong-weak-map-8.16.0.tgz", + "integrity": "sha512-R6N12wEIQpBk2uyni/FU1SFSIjP0uql7ynXVcF1ob8/JJeRoikssydi9Xq5J6ghMw+X50u35mFvg9BgWKz0d+g==", "dev": true, "license": "MIT", "engines": { @@ -614,9 +644,9 @@ } }, "node_modules/@cspell/url": { - "version": "8.14.2", - "resolved": "https://registry.npmjs.org/@cspell/url/-/url-8.14.2.tgz", - "integrity": "sha512-YmWW+B/2XQcCynLpiAQF77Bitm5Cynw3/BICZkbdveKjJkUzEmXB+U2qWuwXOyU8xUYuwkP63YM8McnI567rUA==", + "version": "8.16.0", + "resolved": "https://registry.npmjs.org/@cspell/url/-/url-8.16.0.tgz", + "integrity": "sha512-zW+6hAieD/FjysfjY4mVv7iHWWasBP3ldj6L+xy2p4Kuax1nug7uuJqMHlAVude/OywNwENG0rYaP/P9Pg4O+w==", "dev": true, "license": "MIT", "engines": { @@ -2080,9 +2110,9 @@ "license": "MIT" }, "node_modules/@types/node": { - "version": "20.16.5", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.16.5.tgz", - "integrity": "sha512-VwYCweNo3ERajwy0IUlqqcyZ8/A7Zwa9ZP3MnENWcB11AejO+tLy3pu850goUW2FC/IJMdZUfKpX/yxL1gymCA==", + "version": "20.17.6", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.17.6.tgz", + "integrity": "sha512-VEI7OdvK2wP7XHnsuXbAJnEpEkF6NjSN45QJlL4VGqZSXsnicpesdTWsg9RISeSdYd3yeRj/y3k5KGjUXYnFwQ==", "dev": true, "license": "MIT", "dependencies": { @@ -3426,13 +3456,13 @@ } }, "node_modules/cspell-config-lib": { - "version": "8.14.2", - "resolved": "https://registry.npmjs.org/cspell-config-lib/-/cspell-config-lib-8.14.2.tgz", - "integrity": "sha512-yHP1BdcH5dbjb8qiZr6+bxEnJ+rxTULQ00wBz3eBPWCghJywEAYYvMWoYuxVtPpndlkKYC1wJAHsyNkweQyepA==", + "version": "8.16.0", + "resolved": "https://registry.npmjs.org/cspell-config-lib/-/cspell-config-lib-8.16.0.tgz", + "integrity": "sha512-PGT6ohLtIYXYLIm+R5hTcTrF0dzj8e7WAUJSJe5WlV/7lrwVdwgWaliLcXtSSPmfxgczr6sndX9TMJ2IEmPrmg==", "dev": true, "license": "MIT", "dependencies": { - "@cspell/cspell-types": "8.14.2", + "@cspell/cspell-types": "8.16.0", "comment-json": "^4.2.5", "yaml": "^2.6.0" }, @@ -3441,15 +3471,15 @@ } }, "node_modules/cspell-dictionary": { - "version": "8.14.2", - "resolved": "https://registry.npmjs.org/cspell-dictionary/-/cspell-dictionary-8.14.2.tgz", - "integrity": "sha512-gWuAvf6queGGUvGbfAxxUq55cZ0OevWPbjnCrSB0PpJ4tqdFd8dLcvVrIKzoE2sBXKPw2NDkmoEngs6iGavC0w==", + "version": "8.16.0", + "resolved": "https://registry.npmjs.org/cspell-dictionary/-/cspell-dictionary-8.16.0.tgz", + "integrity": "sha512-Y3sN6ttLBKbu0dOLcduY641n5QP1srUvZkW4bOTnG455DbIZfilrP1El/2Hl0RS6hC8LN9PM4bsIm/2xgdbApA==", "dev": true, "license": "MIT", "dependencies": { - "@cspell/cspell-pipe": "8.14.2", - "@cspell/cspell-types": "8.14.2", - "cspell-trie-lib": "8.14.2", + "@cspell/cspell-pipe": "8.16.0", + "@cspell/cspell-types": "8.16.0", + "cspell-trie-lib": "8.16.0", "fast-equals": "^5.0.1" }, "engines": { @@ -3457,28 +3487,28 @@ } }, "node_modules/cspell-glob": { - "version": "8.14.2", - "resolved": "https://registry.npmjs.org/cspell-glob/-/cspell-glob-8.14.2.tgz", - "integrity": "sha512-9Q1Kgoo1ev3fKTpp9y5n8M4RLxd8B0f5o4y5FQe4dBU0j/bt+/YDrLZNWDm77JViV606XQ6fimG1FTTq6pT9/g==", + "version": "8.16.0", + "resolved": "https://registry.npmjs.org/cspell-glob/-/cspell-glob-8.16.0.tgz", + "integrity": "sha512-xJSXRHwfENCNFmjpVSEucXY8E3BrpSCA+TukmOYtLyaMKtn6EAwoCpEU7Oj2tZOjdivprPmQ74k4Dqb1RHjIVQ==", "dev": true, "license": "MIT", "dependencies": { - "@cspell/url": "8.14.2", - "micromatch": "^4.0.7" + "@cspell/url": "8.16.0", + "micromatch": "^4.0.8" }, "engines": { "node": ">=18" } }, "node_modules/cspell-grammar": { - "version": "8.14.2", - "resolved": "https://registry.npmjs.org/cspell-grammar/-/cspell-grammar-8.14.2.tgz", - "integrity": "sha512-eYwceVP80FGYVJenE42ALnvEKOXaXjq4yVbb1Ni1umO/9qamLWNCQ1RP6rRACy5e/cXviAbhrQ5Mtw6n+pyPEQ==", + "version": "8.16.0", + "resolved": "https://registry.npmjs.org/cspell-grammar/-/cspell-grammar-8.16.0.tgz", + "integrity": "sha512-vvbJEkBqXocGH/H975RtkfMzVpNxNGMd0JCDd+NjbpeRyZceuChFw5Tie7kHteFY29SwZovub+Am3F4H1kmf9A==", "dev": true, "license": "MIT", "dependencies": { - "@cspell/cspell-pipe": "8.14.2", - "@cspell/cspell-types": "8.14.2" + "@cspell/cspell-pipe": "8.16.0", + "@cspell/cspell-types": "8.16.0" }, "bin": { "cspell-grammar": "bin.mjs" @@ -3488,42 +3518,42 @@ } }, "node_modules/cspell-io": { - "version": "8.14.2", - "resolved": "https://registry.npmjs.org/cspell-io/-/cspell-io-8.14.2.tgz", - "integrity": "sha512-uaKpHiY3DAgfdzgKMQml6U8F8o9udMuYxGqYa5FVfN7D5Ap7B2edQzSLTUYwxrFEn4skSfp6XY73+nzJvxzH4Q==", + "version": "8.16.0", + "resolved": "https://registry.npmjs.org/cspell-io/-/cspell-io-8.16.0.tgz", + "integrity": "sha512-WIK5uhPMjGsTAzm2/fGRbIdr7zWsMVG1fn8wNJYUiYELuyvzvLelfI1VG6szaFCGYqd6Uvgb/fS0uNbwGqCLAQ==", "dev": true, "license": "MIT", "dependencies": { - "@cspell/cspell-service-bus": "8.14.2", - "@cspell/url": "8.14.2" + "@cspell/cspell-service-bus": "8.16.0", + "@cspell/url": "8.16.0" }, "engines": { "node": ">=18" } }, "node_modules/cspell-lib": { - "version": "8.14.2", - "resolved": "https://registry.npmjs.org/cspell-lib/-/cspell-lib-8.14.2.tgz", - "integrity": "sha512-d2oiIXHXnADmnhIuFLOdNE63L7OUfzgpLbYaqAWbkImCUDkevfGrOgnX8TJ03fUgZID4nvQ+3kgu/n2j4eLZjQ==", + "version": "8.16.0", + "resolved": "https://registry.npmjs.org/cspell-lib/-/cspell-lib-8.16.0.tgz", + "integrity": "sha512-fU8CfECyuhT12COIi4ViQu2bTkdqaa+05YSd2ZV8k8NA7lapPaMFnlooxdfcwwgZJfHeMhRVMzvQF1OhWmwGfA==", "dev": true, "license": "MIT", "dependencies": { - "@cspell/cspell-bundled-dicts": "8.14.2", - "@cspell/cspell-pipe": "8.14.2", - "@cspell/cspell-resolver": "8.14.2", - "@cspell/cspell-types": "8.14.2", - "@cspell/dynamic-import": "8.14.2", - "@cspell/filetypes": "8.14.2", - "@cspell/strong-weak-map": "8.14.2", - "@cspell/url": "8.14.2", + "@cspell/cspell-bundled-dicts": "8.16.0", + "@cspell/cspell-pipe": "8.16.0", + "@cspell/cspell-resolver": "8.16.0", + "@cspell/cspell-types": "8.16.0", + "@cspell/dynamic-import": "8.16.0", + "@cspell/filetypes": "8.16.0", + "@cspell/strong-weak-map": "8.16.0", + "@cspell/url": "8.16.0", "clear-module": "^4.1.2", "comment-json": "^4.2.5", - "cspell-config-lib": "8.14.2", - "cspell-dictionary": "8.14.2", - "cspell-glob": "8.14.2", - "cspell-grammar": "8.14.2", - "cspell-io": "8.14.2", - "cspell-trie-lib": "8.14.2", + "cspell-config-lib": "8.16.0", + "cspell-dictionary": "8.16.0", + "cspell-glob": "8.16.0", + "cspell-grammar": "8.16.0", + "cspell-io": "8.16.0", + "cspell-trie-lib": "8.16.0", "env-paths": "^3.0.0", "fast-equals": "^5.0.1", "gensequence": "^7.0.0", @@ -3538,14 +3568,14 @@ } }, "node_modules/cspell-trie-lib": { - "version": "8.14.2", - "resolved": "https://registry.npmjs.org/cspell-trie-lib/-/cspell-trie-lib-8.14.2.tgz", - "integrity": "sha512-rZMbaEBGoyy4/zxKECaMyVyGLbuUxYmZ5jlEgiA3xPtEdWwJ4iWRTo5G6dWbQsXoxPYdAXXZ0/q0GQ2y6Jt0kw==", + "version": "8.16.0", + "resolved": "https://registry.npmjs.org/cspell-trie-lib/-/cspell-trie-lib-8.16.0.tgz", + "integrity": "sha512-Io1qqI0r4U9ewAWBLClFBBlxLeAoIi15PUGJi4Za1xrlgQJwRE8PMNIJNHKmPEIp78Iute3o/JyC2OfWlxl4Sw==", "dev": true, "license": "MIT", "dependencies": { - "@cspell/cspell-pipe": "8.14.2", - "@cspell/cspell-types": "8.14.2", + "@cspell/cspell-pipe": "8.16.0", + "@cspell/cspell-types": "8.16.0", "gensequence": "^7.0.0" }, "engines": { @@ -7542,9 +7572,9 @@ } }, "node_modules/tslib": { - "version": "2.7.0", - "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.7.0.tgz", - "integrity": "sha512-gLXCKdN1/j47AiHiOkJN69hJmcbGTHI0ImLmbYLHykhgeN0jVGola9yVjFgzCUklsZQMW55o+dW7IXv3RCXDzA==", + "version": "2.8.1", + "resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz", + "integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==", "license": "0BSD" }, "node_modules/tsutils": { @@ -7858,9 +7888,9 @@ "peer": true }, "node_modules/webpack": { - "version": "5.94.0", - "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.94.0.tgz", - "integrity": "sha512-KcsGn50VT+06JH/iunZJedYGUJS5FGjow8wb9c0v5n1Om8O1g4L6LjtfxwlXIATopoQu+vOXXa7gYisWxCoPyg==", + "version": "5.96.1", + "resolved": "https://registry.npmjs.org/webpack/-/webpack-5.96.1.tgz", + "integrity": "sha512-l2LlBSvVZGhL4ZrPwyr8+37AunkcYj5qh8o6u2/2rzoPc8gxFJkLj1WxNgooi9pnoc06jh0BjuXnamM4qlujZA==", "dev": true, "license": "MIT", "peer": true, diff --git a/package.json b/package.json index b52cc8b0..85d7a277 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@0xpolygonid/js-sdk", - "version": "1.25.1", + "version": "1.25.0", "description": "SDK to work with Polygon ID", "main": "dist/node/cjs/index.js", "module": "dist/node/esm/index.js", diff --git a/src/circuits/auth-v2.ts b/src/circuits/auth-v2.ts index b2219d79..8396a05d 100644 --- a/src/circuits/auth-v2.ts +++ b/src/circuits/auth-v2.ts @@ -1,13 +1,7 @@ import { Hash, Proof } from '@iden3/js-merkletree'; import { Claim, Id } from '@iden3/js-iden3-core'; import { CircuitError, GISTProof, TreeState } from './models'; -import { - BaseConfig, - getNodeAuxValue, - IStateInfoPubSignals, - prepareSiblingsStr, - StatesInfo -} from './common'; +import { BaseConfig, getNodeAuxValue, prepareSiblingsStr } from './common'; import { Signature } from '@iden3/js-crypto'; import { byteDecoder, byteEncoder } from '../utils'; @@ -123,7 +117,7 @@ interface AuthV2CircuitInputs { * @public * @class AuthV2PubSignals */ -export class AuthV2PubSignals implements IStateInfoPubSignals { +export class AuthV2PubSignals { userID!: Id; challenge!: bigint; GISTRoot!: Hash; @@ -149,11 +143,4 @@ export class AuthV2PubSignals implements IStateInfoPubSignals { this.GISTRoot = Hash.fromString(sVals[2]); return this; } - - getStatesInfo(): StatesInfo { - return { - states: [], - gists: [{ id: this.userID, root: this.GISTRoot }] - }; - } } diff --git a/src/iden3comm/handlers/contract-request.ts b/src/iden3comm/handlers/contract-request.ts index 8779a6ac..bb055320 100644 --- a/src/iden3comm/handlers/contract-request.ts +++ b/src/iden3comm/handlers/contract-request.ts @@ -12,6 +12,7 @@ import { BasicHandlerOptions, IProtocolMessageHandler } from './message-handler'; + /** * Interface that allows the processing of the contract request * @@ -68,7 +69,6 @@ export class ContractRequestHandler implements IContractRequestHandler, IProtocolMessageHandler { private readonly _supportedCircuits = [ - CircuitId.AuthV2, CircuitId.AtomicQueryMTPV2OnChain, CircuitId.AtomicQuerySigV2OnChain, CircuitId.AtomicQueryV3OnChain @@ -125,19 +125,12 @@ export class ContractRequestHandler throw new Error(`Invalid chain id ${chain_id}`); } const verifierDid = message.from ? DID.parse(message.from) : undefined; - - const { scope = [] } = message.body; - const zkpResponses = await processZeroKnowledgeProofRequests( did, - scope, + message?.body?.scope, verifierDid, this._proofService, - { - ethSigner, - challenge, - supportedCircuits: this._supportedCircuits - } + { ethSigner, challenge, supportedCircuits: this._supportedCircuits } ); const methodId = message.body.transaction_data.method_id.replace('0x', ''); diff --git a/src/iden3comm/utils/contract-request.utils.ts b/src/iden3comm/utils/contract-request.utils.ts deleted file mode 100644 index 179926b0..00000000 --- a/src/iden3comm/utils/contract-request.utils.ts +++ /dev/null @@ -1,66 +0,0 @@ -import { keccak256 } from 'ethers'; -import { byteEncoder, hexToBytes, isEthereumIdentity } from '../../utils'; -import { CircuitId } from '../../circuits'; -import { Hex } from '@iden3/js-crypto'; -import { DID } from '@iden3/js-iden3-core'; -import { IProofService } from '../../proof'; -import { ZeroKnowledgeProofResponse } from '../types'; - -/** - * @beta - * Retrieves the request ID from circuit string. - * CircuitId.AuthV2 - 940499666 - * @returns The request ID. - */ -export function calculateRequestIdForCircuit(circuitId: CircuitId): number { - const circuitHash = keccak256(byteEncoder.encode(circuitId)); - const dataView = new DataView(Hex.decodeString(circuitHash.replace('0x', '')).buffer); - const id = dataView.getUint32(0); - return id; -} - -/** - * Prepares the zero-knowledge proof response for the AuthV2 circuit. - * @beta - * @param address - The address associated with the request. - * @param senderDid - The sender's decentralized identifier (DID). - * @param proofService - The proof service used to generate the proof. - * @returns A promise that resolves to an array of ZeroKnowledgeProofResponse objects. - */ -export async function prepareAuthV2ZeroKnowledgeResponse( - address: string, - senderDid: DID, - proofService: IProofService -): Promise { - const circuitId = CircuitId.AuthV2; - - // this is now hardcoded calculated value for 'authV2' that can be changed in the future. - const id = 940499666; - - if (isEthereumIdentity(senderDid)) { - return [ - { - circuitId, - id, - pub_signals: [], - proof: { - pi_a: [], - pi_b: [], - pi_c: [], - protocol: 'groth16' - } - } - ]; - } - const hash = Uint8Array.from([...hexToBytes(address), ...new Uint8Array(12)]).reverse(); - const { proof, pub_signals } = await proofService.generateAuthV2Proof(hash, senderDid); - - return [ - { - circuitId, - id, - pub_signals, - proof - } - ]; -} diff --git a/src/iden3comm/utils/index.ts b/src/iden3comm/utils/index.ts index a4006873..68f7ae88 100644 --- a/src/iden3comm/utils/index.ts +++ b/src/iden3comm/utils/index.ts @@ -1,5 +1,4 @@ export * from './envelope'; export * from './message'; export * from './did'; -export * from './contract-request.utils'; export * from './accept-profile'; diff --git a/src/proof/proof-service.ts b/src/proof/proof-service.ts index 8d81bbad..02719bd1 100644 --- a/src/proof/proof-service.ts +++ b/src/proof/proof-service.ts @@ -131,15 +131,6 @@ export interface IProofService { */ generateAuthV2Inputs(hash: Uint8Array, did: DID, circuitId: CircuitId): Promise; - /** - * generates auth inputs - * - * @param {Uint8Array} hash - challenge that will be signed - * @param {DID} did - identity that will generate a proof - * @returns `Promise` - */ - generateAuthV2Proof(hash: Uint8Array, did: DID): Promise; - /** * state verification function * @@ -497,14 +488,6 @@ export class ProofService implements IProofService { return authInputs.inputsMarshal(); } - /** {@inheritdoc IProofService.generateAuthV2Proof} */ - async generateAuthV2Proof(challenge: Uint8Array, did: DID): Promise { - const authInputs = await this.generateAuthV2Inputs(challenge, did, CircuitId.AuthV2); - - const zkProof = await this._prover.generate(authInputs, CircuitId.AuthV2); - return zkProof; - } - async verifyState( circuitId: string, pubSignals: string[], diff --git a/src/storage/blockchain/onchain-zkp-verifier.ts b/src/storage/blockchain/onchain-zkp-verifier.ts index 6c7df6cd..271901aa 100644 --- a/src/storage/blockchain/onchain-zkp-verifier.ts +++ b/src/storage/blockchain/onchain-zkp-verifier.ts @@ -8,12 +8,11 @@ import { } from '../../iden3comm'; import abi from './abi/ZkpVerifier.json'; import { TransactionService } from '../../blockchain'; -import { chainIDfromDID, DID, Id } from '@iden3/js-iden3-core'; +import { DID } from '@iden3/js-iden3-core'; import { AtomicQueryMTPV2OnChainPubSignals, AtomicQuerySigV2OnChainPubSignals, AtomicQueryV3OnChainPubSignals, - AuthV2PubSignals, CircuitId, StatesInfo } from '../../circuits'; @@ -44,12 +43,6 @@ export type OnChainZKPVerifierOptions = { didResolverUrl?: string; }; -type OnChainZKPVerifierCircuitId = - | CircuitId.AuthV2 - | CircuitId.AtomicQueryMTPV2OnChain - | CircuitId.AtomicQuerySigV2OnChain - | CircuitId.AtomicQueryV3OnChain; - /** * OnChainZKPVerifier is a class that allows to interact with the OnChainZKPVerifier contract * and submitZKPResponse. @@ -61,20 +54,12 @@ export class OnChainZKPVerifier implements IOnChainZKPVerifier { /** * supported circuits */ - private static readonly _supportedCircuits: OnChainZKPVerifierCircuitId[] = [ - CircuitId.AuthV2, + private static readonly _supportedCircuits = [ CircuitId.AtomicQueryMTPV2OnChain, CircuitId.AtomicQuerySigV2OnChain, CircuitId.AtomicQueryV3OnChain ]; - private static readonly _supportedCircuitsPubSignalsMap = { - [CircuitId.AtomicQueryMTPV2OnChain]: AtomicQueryMTPV2OnChainPubSignals, - [CircuitId.AtomicQuerySigV2OnChain]: AtomicQuerySigV2OnChainPubSignals, - [CircuitId.AtomicQueryV3OnChain]: AtomicQueryV3OnChainPubSignals, - [CircuitId.AuthV2]: AuthV2PubSignals - }; - /** * * Creates an instance of OnChainZKPVerifier. @@ -236,44 +221,6 @@ export class OnChainZKPVerifier implements IOnChainZKPVerifier { return new Map().set(txnHash, zkProofResponses); } - private static getCrossChainResolvers( - source: { - id: Id; - root?: Hash; - state?: Hash; - }[], - txDataChainId: number, - type: 'gist' | 'state', - didResolverUrl: string - ) { - return [ - ...new Set( - source.map((info) => - JSON.stringify({ - id: info.id.string(), - [type]: type === 'gist' ? info.root?.string() : info.state?.string() - }) - ) - ) - ].reduce((acc: Promise[], s: string) => { - const info = JSON.parse(s); - const id = Id.fromString(info.id); - const chainId = chainIDfromDID(DID.parseFromId(id)); - - if (txDataChainId === chainId) { - return acc; - } - const promise = this.resolveDidDocumentEip712MessageAndSignature( - DID.parseFromId(Id.fromString(info.id)), - didResolverUrl, - { - [type]: Hash.fromString(info[type]) - } - ); - return [...acc, promise]; - }, []); - } - public static async prepareTxArgsSubmitV2( resolverUrl: string, txData: ContractInvokeTransactionData, @@ -284,29 +231,21 @@ export class OnChainZKPVerifier implements IOnChainZKPVerifier { `submit cross chain doesn't implement requested method id. Only '0x${FunctionSignatures.SubmitZKPResponseV2}' is supported.` ); } - - const gistUpdates = []; - const stateUpdates = []; + const gistUpdateArr = []; + const stateUpdateArr = []; const payload = []; - const emptyBytes = '0x'; + // Resolved gists and states to avoid duplicate requests + const gistUpdateResolutionsPending: string[] = []; + const stateUpdateResolutionsPending: string[] = []; for (const zkProof of zkProofResponses) { - const { id: requestId, pub_signals: inputs } = zkProof; - const proofCircuitId = zkProof.circuitId as OnChainZKPVerifierCircuitId; + const requestID = zkProof.id; + const inputs = zkProof.pub_signals; - if (!this._supportedCircuits.includes(proofCircuitId)) { + if (!this._supportedCircuits.includes(zkProof.circuitId as CircuitId)) { throw new Error(`Circuit ${zkProof.circuitId} not supported by OnChainZKPVerifier`); } - if (inputs.length === 0) { - payload.push({ - requestId: requestId, - zkProof: emptyBytes, - data: emptyBytes - }); - continue; - } - const zkProofEncoded = this.packZkpProof( inputs, zkProof.proof.pi_a.slice(0, 2), @@ -317,28 +256,55 @@ export class OnChainZKPVerifier implements IOnChainZKPVerifier { zkProof.proof.pi_c.slice(0, 2) ); - const stateInfo = this.getOnChainGistRootStatePubSignals(proofCircuitId, inputs); - - const chainId = txData.chain_id; - const gistUpdateResolutions = this.getCrossChainResolvers( - stateInfo.gists, - chainId, - 'gist', - resolverUrl + const stateInfo = this.getOnChainGistRootStatePubSignals( + zkProof.circuitId as + | CircuitId.AtomicQueryMTPV2OnChain + | CircuitId.AtomicQuerySigV2OnChain + | CircuitId.AtomicQueryV3OnChain, + zkProof.pub_signals ); - const stateUpdateResolutions = this.getCrossChainResolvers( - stateInfo.states, - chainId, - 'state', - resolverUrl - ); + const gistUpdateResolutions = []; + for (const gist of stateInfo.gists) { + const gistResolutionPending = gistUpdateResolutionsPending.find( + (g) => g == JSON.stringify(gist) + ); + + if (gistResolutionPending) { + continue; + } + gistUpdateResolutionsPending.push(JSON.stringify(gist)); + + gistUpdateResolutions.push( + this.resolveDidDocumentEip712MessageAndSignature(DID.parseFromId(gist.id), resolverUrl, { + gist: gist.root + }) + ); + } + + const stateUpdateResolutions = []; + for (const state of stateInfo.states) { + const stateResolutionPending = stateUpdateResolutionsPending.find( + (s) => s == JSON.stringify(state) + ); + + if (stateResolutionPending) { + continue; + } + stateUpdateResolutionsPending.push(JSON.stringify(state)); + + stateUpdateResolutions.push( + this.resolveDidDocumentEip712MessageAndSignature(DID.parseFromId(state.id), resolverUrl, { + state: state.state + }) + ); + } if (gistUpdateResolutions.length > 0) { - gistUpdates.push(...((await Promise.all(gistUpdateResolutions)) as GlobalStateUpdate[])); + gistUpdateArr.push(...((await Promise.all(gistUpdateResolutions)) as GlobalStateUpdate[])); } if (stateUpdateResolutions.length > 0) { - stateUpdates.push( + stateUpdateArr.push( ...((await Promise.all(stateUpdateResolutions)) as IdentityStateUpdate[]) ); } @@ -362,18 +328,15 @@ export class OnChainZKPVerifier implements IOnChainZKPVerifier { } } - const metadata = metadataArr.length ? this.packMetadatas(metadataArr) : emptyBytes; + const metadata = metadataArr.length ? this.packMetadatas(metadataArr) : '0x'; payload.push({ - requestId: requestId, + requestId: requestID, zkProof: zkProofEncoded, data: metadata }); } - const crossChainProofs = - gistUpdates.length || stateUpdates.length - ? this.packCrossChainProofs(gistUpdates, stateUpdates) - : emptyBytes; + const crossChainProofs = this.packCrossChainProofs(gistUpdateArr, stateUpdateArr); return [payload, crossChainProofs]; } @@ -468,14 +431,24 @@ export class OnChainZKPVerifier implements IOnChainZKPVerifier { } private static getOnChainGistRootStatePubSignals( - onChainCircuitId: OnChainZKPVerifierCircuitId, + onChainCircuitId: + | CircuitId.AtomicQueryMTPV2OnChain + | CircuitId.AtomicQuerySigV2OnChain + | CircuitId.AtomicQueryV3OnChain, inputs: string[] ): StatesInfo { - const PubSignals = this._supportedCircuitsPubSignalsMap[onChainCircuitId]; - if (!PubSignals) { - throw new Error(`Circuit ${onChainCircuitId} not supported by OnChainZKPVerifier`); + let atomicQueryPubSignals; + switch (onChainCircuitId) { + case CircuitId.AtomicQueryMTPV2OnChain: + atomicQueryPubSignals = new AtomicQueryMTPV2OnChainPubSignals(); + break; + case CircuitId.AtomicQuerySigV2OnChain: + atomicQueryPubSignals = new AtomicQuerySigV2OnChainPubSignals(); + break; + case CircuitId.AtomicQueryV3OnChain: + atomicQueryPubSignals = new AtomicQueryV3OnChainPubSignals(); + break; } - const atomicQueryPubSignals = new PubSignals(); const encodedInputs = byteEncoder.encode(JSON.stringify(inputs)); atomicQueryPubSignals.pubSignalsUnmarshal(encodedInputs); return atomicQueryPubSignals.getStatesInfo(); diff --git a/src/utils/did-helper.ts b/src/utils/did-helper.ts index f4561e1d..132a5030 100644 --- a/src/utils/did-helper.ts +++ b/src/utils/did-helper.ts @@ -134,13 +134,10 @@ export const resolveDidDocument = async ( if (opts?.gist) { url += `${url.includes('?') ? '&' : '?'}gist=${opts.gist.hex()}`; } - try { - const resp = await fetch(url); - const data = await resp.json(); - return data; - } catch (e) { - throw new Error(`Failed to resolve DID document for ${did} ${e}`); - } + const resp = await fetch(url); + const data = await resp.json(); + + return data; }; export const buildDIDFromEthPubKey = (didType: Uint8Array, pubKeyEth: string): DID => { diff --git a/tests/handlers/contract-request.test.ts b/tests/handlers/contract-request.test.ts index 9e4aec79..b968a2c8 100644 --- a/tests/handlers/contract-request.test.ts +++ b/tests/handlers/contract-request.test.ts @@ -10,8 +10,7 @@ import { EthStateStorage, OnChainZKPVerifier, defaultEthConnectionConfig, - hexToBytes, - FunctionSignatures + hexToBytes } from '../../src'; import { IDataStorage, IStateStorage, IOnChainZKPVerifier } from '../../src/storage/interfaces'; import { InMemoryDataSource, InMemoryMerkleTreeStorage } from '../../src/storage/memory'; @@ -56,13 +55,7 @@ import { expect } from 'chai'; import { CredentialStatusResolverRegistry } from '../../src/credentials'; import { RHSResolver } from '../../src/credentials'; import { ethers, JsonRpcProvider, Signer } from 'ethers'; -import { - createIdentity, - getInMemoryDataStorage, - registerKeyProvidersInMemoryKMS, - RPC_URL, - SEED_USER -} from '../helpers'; +import { registerKeyProvidersInMemoryKMS, RPC_URL } from '../helpers'; import { AbstractMessageHandler } from '../../src/iden3comm/handlers/message-handler'; describe('contract-request', () => { @@ -753,58 +746,49 @@ describe('contract-request', () => { // cross chain integration test it.skip('cross chain contract request flow - integration test', async () => { - const CONTRACTS = { - AMOY_STATE_CONTRACT: '0x1a4cC30f2aA0377b0c3bc9848766D90cb4404124', - AMOY_UNIVERSAL_VERIFIER: '0x1Df0B05F15b5ea9648B8a081aca8ad0dE065bD1F', - PRIVADO_STATE_CONTRACT: '0x975556428F077dB5877Ea2474D783D6C69233742', - AUTH_V2_AMOY_VALIDATOR: '0x1a593E1aD3843b4363Dfa42585c4bBCA885553c0' + const privadoTestRpcUrl = '< >'; + const privadoMainRpcUrl = '< >'; + const amoyRpcUrl = '< >'; + const amoyStateContract = '< >'; + const privadoStateContract = '< >'; + const lineaSepoliaRpc = '< >'; + const erc20Verifier = '0xcfe3f46048cb9dAa40c90fd574F6E1deB534b9e7'; + + const issuerAmoyStateEthConfig = { + ...defaultEthConnectionConfig, + url: amoyRpcUrl, + contractAddress: amoyStateContract, + chainId: 80002 }; - const networkConfigs = { - amoy: (contractAddress) => ({ - ...defaultEthConnectionConfig, - url: '<>', - contractAddress, - chainId: 80002 - }), - privadoMain: (contractAddress) => ({ - ...defaultEthConnectionConfig, - url: '<>', - contractAddress, - chainId: 21000 - }), - privadoTest: (contractAddress) => ({ - ...defaultEthConnectionConfig, - url: 'https://rpc-testnet.privado.id', - contractAddress, - chainId: 21001 - }), - lineaSepolia: (contractAddress) => ({ - ...defaultEthConnectionConfig, - url: '<>', - contractAddress, - chainId: 80001 - }) + const issuerStateEthConfig = { + ...defaultEthConnectionConfig, + url: privadoTestRpcUrl, + contractAddress: privadoStateContract, + chainId: 21001 }; - const issuerAmoyStateEthConfig = networkConfigs.amoy(CONTRACTS.AMOY_STATE_CONTRACT); - - const issuerPrivadoTestStateEthConfig = networkConfigs.privadoTest( - CONTRACTS.PRIVADO_STATE_CONTRACT - ); - - // const userStateEthConfig = networkConfigs.amoy(CONTRACTS.AMOY_STATE_CONTRACT); - const userStateEthConfig = networkConfigs.privadoMain(CONTRACTS.PRIVADO_STATE_CONTRACT); + const userStateEthConfig = { + ...defaultEthConnectionConfig, + url: privadoMainRpcUrl, + contractAddress: privadoStateContract, + chainId: 21000 + }; const kms = registerKeyProvidersInMemoryKMS(); - dataStorage = getInMemoryDataStorage( - new EthStateStorage([ + dataStorage = { + credential: new CredentialStorage(new InMemoryDataSource()), + identity: new IdentityStorage( + new InMemoryDataSource(), + new InMemoryDataSource() + ), + mt: new InMemoryMerkleTreeStorage(40), + states: new EthStateStorage([ issuerAmoyStateEthConfig, userStateEthConfig, - issuerPrivadoTestStateEthConfig + issuerStateEthConfig ]) - ); - + }; const circuitStorage = new FSCircuitStorage({ dirname: path.join(__dirname, '../proofs/testdata') }); @@ -826,13 +810,29 @@ describe('contract-request', () => { proofService.verifyState.bind(proofService) ); - const { did: userDID } = await createIdentity(idWallet, { - seed: SEED_USER, + const { did: userDID, credential: cred } = await idWallet.createIdentity({ + method: DidMethod.Iden3, blockchain: Blockchain.Privado, - networkId: NetworkId.Main + networkId: NetworkId.Main, + seed: seedPhrase, + revocationOpts: { + type: CredentialStatusType.Iden3ReverseSparseMerkleTreeProof, + id: rhsUrl + } }); - const { did: issuerDID, credential: issuerAuthCredential } = await createIdentity(idWallet); + expect(cred).not.to.be.undefined; + + const { did: issuerDID, credential: issuerAuthCredential } = await idWallet.createIdentity({ + method: DidMethod.Iden3, + blockchain: Blockchain.Polygon, + networkId: NetworkId.Amoy, + seed: seedPhraseIssuer, + revocationOpts: { + type: CredentialStatusType.Iden3ReverseSparseMerkleTreeProof, + id: rhsUrl + } + }); expect(issuerAuthCredential).not.to.be.undefined; const claimReq: CredentialRequest = { @@ -854,8 +854,6 @@ describe('contract-request', () => { await credWallet.save(issuerCred); - // ADD proofReq to scope - // eslint-disable-next-line @typescript-eslint/no-unused-vars const proofReqs: ZeroKnowledgeProofRequest[] = [ { id: 138, @@ -876,24 +874,28 @@ describe('contract-request', () => { } ]; - const zkpVerifierNetworkConfig = networkConfigs.amoy(CONTRACTS.AMOY_UNIVERSAL_VERIFIER); + const conf = { + ...defaultEthConnectionConfig, + contractAddress: erc20Verifier, + url: lineaSepoliaRpc, + chainId: 59141 + }; - const zkpVerifier = new OnChainZKPVerifier([zkpVerifierNetworkConfig], { + const zkpVerifier = new OnChainZKPVerifier([conf], { didResolverUrl: 'https://resolver-dev.privado.id' }); - contractRequestHandler = new ContractRequestHandler(packageMgr, proofService, zkpVerifier); const transactionData: ContractInvokeTransactionData = { - contract_address: zkpVerifierNetworkConfig.contractAddress, - method_id: FunctionSignatures.SubmitZKPResponseV2, - chain_id: zkpVerifierNetworkConfig.chainId + contract_address: erc20Verifier, + method_id: 'ade09fcd', + chain_id: conf.chainId }; const ciRequestBody: ContractInvokeRequestBody = { reason: 'reason', transaction_data: transactionData, - scope: proofReqs + scope: [...proofReqs] }; const id = uuid.v4(); diff --git a/tests/handlers/payment.test.ts b/tests/handlers/payment.test.ts index c198a8a6..27ee17cb 100644 --- a/tests/handlers/payment.test.ts +++ b/tests/handlers/payment.test.ts @@ -458,7 +458,7 @@ describe('payment-request handler', () => { ], recipient: '0xE9D7fCDf32dF4772A7EF7C24c76aB40E4A42274a', amount: '2', - expirationDate: '2124-12-10T17:25:18.907Z', + expirationDate: '2024-12-04T18:42:51.337Z', nonce: '411393', metadata: '0x', proof: [ @@ -466,7 +466,7 @@ describe('payment-request handler', () => { type: SupportedPaymentProofType.EthereumEip712Signature2021, proofPurpose: 'assertionMethod', proofValue: - '0x31b57b1be0c22c21359252723a10b21c7c3e438705e1d46d2384feacdd8b429e3f1a3a230ac49fccdeef0aa1f7604020d4d4098c4078c4f24280c91c0dab45611b', + '0x6c6cbcc3943ab60f178f2721ccdcfa094b65196c0f0383e8bbf8747afce3fa0c64853872d705d5545f768fa54fa3cdafe4da37545d63ccda56f92ef9ff5ad4101b', verificationMethod: 'did:pkh:eip155:80002:0xE9D7fCDf32dF4772A7EF7C24c76aB40E4A42274a', created: new Date().toISOString(), eip712: { @@ -503,7 +503,7 @@ describe('payment-request handler', () => { tokenAddress: '0x71dcc8Dc5Eb138003d3571255458Bc5692a60eD4', recipient: '0xE9D7fCDf32dF4772A7EF7C24c76aB40E4A42274a', amount: '2', - expirationDate: '2124-12-10T17:25:18.907Z', + expirationDate: '2024-12-04T18:43:31.082Z', nonce: '411393', metadata: '0x', proof: [ @@ -511,7 +511,7 @@ describe('payment-request handler', () => { type: SupportedPaymentProofType.EthereumEip712Signature2021, proofPurpose: 'assertionMethod', proofValue: - '0x2b355fbeb6f303ebf3c5a88b335129799c67fa5db3debee8ee265b4d46fbeb7349a1b22e4c012d8a3c48581f8d77d8888337f5f0c9b7a38a0a7869749173937f1b', + '0xeb1e1d485ba8149c43b391bcadf4afb26f5b3e6cd66724c48ba10abb67c20c9158abf6efeb3a67b340f6bc9302d44bb47cfa0e1918c9cd382e18da154c4bfd011b', verificationMethod: 'did:pkh:eip155:80002:0xE9D7fCDf32dF4772A7EF7C24c76aB40E4A42274a', created: new Date().toISOString(), eip712: {