diff --git a/.releaserc.yml b/.releaserc.yml index 88e903b5..b64a9899 100644 --- a/.releaserc.yml +++ b/.releaserc.yml @@ -5,7 +5,7 @@ branches: - name: '@pluto-encrypted/*/v+([0-9]).X.X' type: maintenance - name: '@pluto-encrypted/*/v+([0-9])' - type: maintenances + type: maintenance - name: 'develop' prerelease: 'rc' @@ -19,8 +19,7 @@ plugins: prepareCmd: "npm version ${nextRelease.version} --git-tag-version false" } ] - - ["@semantic-release/exec", { prepareCmd: "npm run build" }] - - ["@semantic-release/exec", { prepareCmd: "npm publish --access public" }] + - ["@semantic-release/exec", { prepareCmd: "npm run build && npm publish --access public" }] - [ "@semantic-release/git", { diff --git a/package-lock.json b/package-lock.json index 8f56a9ad..7cf8344c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -522,9 +522,9 @@ } }, "node_modules/@babel/helpers": { - "version": "7.23.7", - "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.23.7.tgz", - "integrity": "sha512-6AMnjCoC8wjqBzDHkuqpa7jAKwvMo4dC+lr/TFBz+ucfulO1XMpDnwWPGBNwClOKZ8h6xn5N81W/R5OrcKtCbQ==", + "version": "7.23.8", + "resolved": "https://registry.npmjs.org/@babel/helpers/-/helpers-7.23.8.tgz", + "integrity": "sha512-KDqYz4PiOWvDFrdHLPhKtCThtIcKVy6avWD2oG4GEvyQ+XDZwHD4YQd+H2vNMnq2rkdxsDkU82T+Vk8U/WXHRQ==", "dev": true, "dependencies": { "@babel/template": "^7.22.15", @@ -633,9 +633,9 @@ } }, "node_modules/@babel/runtime": { - "version": "7.23.7", - "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.23.7.tgz", - "integrity": "sha512-w06OXVOFso7LcbzMiDGt+3X7Rh7Ho8MmgPoWU3rarH+8upf+wSU/grlGbWzQyr3DkdN6ZeuMFjpdwW0Q+HxobA==", + "version": "7.23.8", + "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.23.8.tgz", + "integrity": "sha512-Y7KbAP984rn1VGMbGqKmBLio9V7y5Je9GvU4rQPCPinCyNfUcToxIXl06d59URp/F3LwinvODxab5N/G6qggkw==", "dev": true, "dependencies": { "regenerator-runtime": "^0.14.0" @@ -2734,9 +2734,9 @@ "dev": true }, "node_modules/@mongodb-js/saslprep": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/@mongodb-js/saslprep/-/saslprep-1.1.1.tgz", - "integrity": "sha512-t7c5K033joZZMspnHg/gWPE4kandgc2OxE74aYOtGKfgB9VPuVJPix0H6fhmm2erj5PBJ21mqcx34lpIGtUCsQ==", + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/@mongodb-js/saslprep/-/saslprep-1.1.3.tgz", + "integrity": "sha512-SyCxhJfmK6MoLNV5SbDpNdUy9SDv5H7y9/9rl3KpnwgTHWuNNMc87zWqbcIZXNWY+aUjxLGLEcvHoLagG4tWCg==", "dependencies": { "sparse-bitfield": "^3.0.3" } @@ -3507,6 +3507,10 @@ "resolved": "packages/leveldb", "link": true }, + "node_modules/@pluto-encrypted/schemas": { + "resolved": "packages/schemas", + "link": true + }, "node_modules/@pluto-encrypted/shared": { "resolved": "packages/shared", "link": true @@ -3746,12 +3750,12 @@ } }, "node_modules/@rollup/plugin-typescript": { - "version": "11.1.5", - "resolved": "https://registry.npmjs.org/@rollup/plugin-typescript/-/plugin-typescript-11.1.5.tgz", - "integrity": "sha512-rnMHrGBB0IUEv69Q8/JGRD/n4/n6b3nfpufUu26axhUcboUzv/twfZU8fIBbTOphRAe0v8EyxzeDpKXqGHfyDA==", + "version": "11.1.6", + "resolved": "https://registry.npmjs.org/@rollup/plugin-typescript/-/plugin-typescript-11.1.6.tgz", + "integrity": "sha512-R92yOmIACgYdJ7dJ97p4K69I8gg6IEHt8M7dUBxN3W6nrO8uUxX5ixl0yU/N3aZTi8WhPuICvOHXQvF6FaykAA==", "dev": true, "dependencies": { - "@rollup/pluginutils": "^5.0.1", + "@rollup/pluginutils": "^5.1.0", "resolve": "^1.22.1" }, "engines": { @@ -3814,9 +3818,9 @@ } }, "node_modules/@rollup/rollup-android-arm-eabi": { - "version": "4.9.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.9.3.tgz", - "integrity": "sha512-nvh9bB41vXEoKKvlWCGptpGt8EhrEwPQFDCY0VAto+R+qpSbaErPS3OjMZuXR8i/2UVw952Dtlnl2JFxH31Qvg==", + "version": "4.9.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm-eabi/-/rollup-android-arm-eabi-4.9.4.tgz", + "integrity": "sha512-ub/SN3yWqIv5CWiAZPHVS1DloyZsJbtXmX4HxUTIpS0BHm9pW5iYBo2mIZi+hE3AeiTzHz33blwSnhdUo+9NpA==", "cpu": [ "arm" ], @@ -3826,9 +3830,9 @@ ] }, "node_modules/@rollup/rollup-android-arm64": { - "version": "4.9.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.9.3.tgz", - "integrity": "sha512-kffYCJ2RhDL1DlshLzYPyJtVeusHlA8Q1j6k6s4AEVKLq/3HfGa2ADDycLsmPo3OW83r4XtOPqRMbcFzFsEIzQ==", + "version": "4.9.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-android-arm64/-/rollup-android-arm64-4.9.4.tgz", + "integrity": "sha512-ehcBrOR5XTl0W0t2WxfTyHCR/3Cq2jfb+I4W+Ch8Y9b5G+vbAecVv0Fx/J1QKktOrgUYsIKxWAKgIpvw56IFNA==", "cpu": [ "arm64" ], @@ -3838,9 +3842,9 @@ ] }, "node_modules/@rollup/rollup-darwin-arm64": { - "version": "4.9.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.9.3.tgz", - "integrity": "sha512-Fo7DR6Q9/+ztTyMBZ79+WJtb8RWZonyCgkBCjV51rW5K/dizBzImTW6HLC0pzmHaAevwM0jW1GtB5LCFE81mSw==", + "version": "4.9.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-arm64/-/rollup-darwin-arm64-4.9.4.tgz", + "integrity": "sha512-1fzh1lWExwSTWy8vJPnNbNM02WZDS8AW3McEOb7wW+nPChLKf3WG2aG7fhaUmfX5FKw9zhsF5+MBwArGyNM7NA==", "cpu": [ "arm64" ], @@ -3850,9 +3854,9 @@ ] }, "node_modules/@rollup/rollup-darwin-x64": { - "version": "4.9.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.9.3.tgz", - "integrity": "sha512-5HcxDF9fqHucIlTiw/gmMb3Qv23L8bLCg904I74Q2lpl4j/20z9ogaD3tWkeguRuz+/17cuS321PT3PAuyjQdg==", + "version": "4.9.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-darwin-x64/-/rollup-darwin-x64-4.9.4.tgz", + "integrity": "sha512-Gc6cukkF38RcYQ6uPdiXi70JB0f29CwcQ7+r4QpfNpQFVHXRd0DfWFidoGxjSx1DwOETM97JPz1RXL5ISSB0pA==", "cpu": [ "x64" ], @@ -3862,9 +3866,9 @@ ] }, "node_modules/@rollup/rollup-linux-arm-gnueabihf": { - "version": "4.9.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.9.3.tgz", - "integrity": "sha512-cO6hKV+99D1V7uNJQn1chWaF9EGp7qV2N8sGH99q9Y62bsbN6Il55EwJppEWT+JiqDRg396vWCgwdHwje8itBQ==", + "version": "4.9.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm-gnueabihf/-/rollup-linux-arm-gnueabihf-4.9.4.tgz", + "integrity": "sha512-g21RTeFzoTl8GxosHbnQZ0/JkuFIB13C3T7Y0HtKzOXmoHhewLbVTFBQZu+z5m9STH6FZ7L/oPgU4Nm5ErN2fw==", "cpu": [ "arm" ], @@ -3874,9 +3878,9 @@ ] }, "node_modules/@rollup/rollup-linux-arm64-gnu": { - "version": "4.9.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.9.3.tgz", - "integrity": "sha512-xANyq6lVg6KMO8UUs0LjA4q7di3tPpDbzLPgVEU2/F1ngIZ54eli8Zdt3uUUTMXVbgTCafIO+JPeGMhu097i3w==", + "version": "4.9.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-gnu/-/rollup-linux-arm64-gnu-4.9.4.tgz", + "integrity": "sha512-TVYVWD/SYwWzGGnbfTkrNpdE4HON46orgMNHCivlXmlsSGQOx/OHHYiQcMIOx38/GWgwr/po2LBn7wypkWw/Mg==", "cpu": [ "arm64" ], @@ -3886,9 +3890,9 @@ ] }, "node_modules/@rollup/rollup-linux-arm64-musl": { - "version": "4.9.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.9.3.tgz", - "integrity": "sha512-TZJUfRTugVFATQToCMD8DNV6jv/KpSwhE1lLq5kXiQbBX3Pqw6dRKtzNkh5wcp0n09reBBq/7CGDERRw9KmE+g==", + "version": "4.9.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-arm64-musl/-/rollup-linux-arm64-musl-4.9.4.tgz", + "integrity": "sha512-XcKvuendwizYYhFxpvQ3xVpzje2HHImzg33wL9zvxtj77HvPStbSGI9czrdbfrf8DGMcNNReH9pVZv8qejAQ5A==", "cpu": [ "arm64" ], @@ -3898,9 +3902,9 @@ ] }, "node_modules/@rollup/rollup-linux-riscv64-gnu": { - "version": "4.9.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.9.3.tgz", - "integrity": "sha512-4/QVaRyaB5tkEAGfjVvWrmWdPF6F2NoaoO5uEP7N0AyeBw7l8SeCWWKAGrbx/00PUdHrJVURJiYikazslSKttQ==", + "version": "4.9.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-riscv64-gnu/-/rollup-linux-riscv64-gnu-4.9.4.tgz", + "integrity": "sha512-LFHS/8Q+I9YA0yVETyjonMJ3UA+DczeBd/MqNEzsGSTdNvSJa1OJZcSH8GiXLvcizgp9AlHs2walqRcqzjOi3A==", "cpu": [ "riscv64" ], @@ -3910,9 +3914,9 @@ ] }, "node_modules/@rollup/rollup-linux-x64-gnu": { - "version": "4.9.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.9.3.tgz", - "integrity": "sha512-koLC6D3pj1YLZSkTy/jsk3HOadp7q2h6VQl/lPX854twOmmLNekHB6yuS+MkWcKdGGdW1JPuPBv/ZYhr5Yhtdg==", + "version": "4.9.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-gnu/-/rollup-linux-x64-gnu-4.9.4.tgz", + "integrity": "sha512-dIYgo+j1+yfy81i0YVU5KnQrIJZE8ERomx17ReU4GREjGtDW4X+nvkBak2xAUpyqLs4eleDSj3RrV72fQos7zw==", "cpu": [ "x64" ], @@ -3922,9 +3926,9 @@ ] }, "node_modules/@rollup/rollup-linux-x64-musl": { - "version": "4.9.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.9.3.tgz", - "integrity": "sha512-0OAkQ4HBp+JO2ip2Lgt/ShlrveOMzyhwt2D0KvqH28jFPqfZco28KSq76zymZwmU+F6GRojdxtQMJiNSXKNzeA==", + "version": "4.9.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-linux-x64-musl/-/rollup-linux-x64-musl-4.9.4.tgz", + "integrity": "sha512-RoaYxjdHQ5TPjaPrLsfKqR3pakMr3JGqZ+jZM0zP2IkDtsGa4CqYaWSfQmZVgFUCgLrTnzX+cnHS3nfl+kB6ZQ==", "cpu": [ "x64" ], @@ -3934,9 +3938,9 @@ ] }, "node_modules/@rollup/rollup-win32-arm64-msvc": { - "version": "4.9.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.9.3.tgz", - "integrity": "sha512-z5uvoMvdRWggigOnsb9OOCLERHV0ykRZoRB5O+URPZC9zM3pkoMg5fN4NKu2oHqgkzZtfx9u4njqqlYEzM1v9A==", + "version": "4.9.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-arm64-msvc/-/rollup-win32-arm64-msvc-4.9.4.tgz", + "integrity": "sha512-T8Q3XHV+Jjf5e49B4EAaLKV74BbX7/qYBRQ8Wop/+TyyU0k+vSjiLVSHNWdVd1goMjZcbhDmYZUYW5RFqkBNHQ==", "cpu": [ "arm64" ], @@ -3946,9 +3950,9 @@ ] }, "node_modules/@rollup/rollup-win32-ia32-msvc": { - "version": "4.9.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.9.3.tgz", - "integrity": "sha512-wxomCHjBVKws+O4N1WLnniKCXu7vkLtdq9Fl9CN/EbwEldojvUrkoHE/fBLZzC7IT/x12Ut6d6cRs4dFvqJkMg==", + "version": "4.9.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-ia32-msvc/-/rollup-win32-ia32-msvc-4.9.4.tgz", + "integrity": "sha512-z+JQ7JirDUHAsMecVydnBPWLwJjbppU+7LZjffGf+Jvrxq+dVjIE7By163Sc9DKc3ADSU50qPVw0KonBS+a+HQ==", "cpu": [ "ia32" ], @@ -3958,9 +3962,9 @@ ] }, "node_modules/@rollup/rollup-win32-x64-msvc": { - "version": "4.9.3", - "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.9.3.tgz", - "integrity": "sha512-1Qf/qk/iEtx0aOi+AQQt5PBoW0mFngsm7bPuxHClC/hWh2hHBktR6ktSfUg5b5rC9v8hTwNmHE7lBWXkgqluUQ==", + "version": "4.9.4", + "resolved": "https://registry.npmjs.org/@rollup/rollup-win32-x64-msvc/-/rollup-win32-x64-msvc-4.9.4.tgz", + "integrity": "sha512-LfdGXCV9rdEify1oxlN9eamvDSjv9md9ZVMAbNHA87xqIfFCxImxan9qZ8+Un54iK2nnqPlbnSi4R54ONtbWBw==", "cpu": [ "x64" ], @@ -4677,9 +4681,9 @@ } }, "node_modules/@types/clone": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/@types/clone/-/clone-2.1.2.tgz", - "integrity": "sha512-fKXTsQvII/8K7xSxQF2OEuN6Pt4/PDasws60s/qeqoIOaBX7Aoevy5CmaQ4fANbvOo04MN3kx3xUIc6ZNXsmaQ==" + "version": "2.1.3", + "resolved": "https://registry.npmjs.org/@types/clone/-/clone-2.1.3.tgz", + "integrity": "sha512-DxFaNYaIUXW1OSRCVCC1UHoLcvk6bVJ0v9VvUaZ6kR5zK8/QazXlOThgdvnK0Xpa4sBq+b/Yoq/mnNn383hVRw==" }, "node_modules/@types/common-tags": { "version": "1.8.1", @@ -4829,9 +4833,9 @@ "dev": true }, "node_modules/@types/node": { - "version": "20.10.6", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.10.6.tgz", - "integrity": "sha512-Vac8H+NlRNNlAmDfGUP7b5h/KA+AtWIzuXy0E6OyP8f1tCLYAtPvKRRDJjAPqhpCb0t6U2j7/xqAuLEebW2kiw==", + "version": "20.10.8", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.10.8.tgz", + "integrity": "sha512-f8nQs3cLxbAFc00vEU59yf9UyGUftkPaLGfvbVOIDdx2i1b8epBqj2aNGyP19fiyXWvlmZ7qC1XLjAzw/OKIeA==", "dependencies": { "undici-types": "~5.26.4" } @@ -4898,9 +4902,9 @@ } }, "node_modules/@types/sinon": { - "version": "17.0.2", - "resolved": "https://registry.npmjs.org/@types/sinon/-/sinon-17.0.2.tgz", - "integrity": "sha512-Zt6heIGsdqERkxctIpvN5Pv3edgBrhoeb3yHyxffd4InN0AX2SVNKSrhdDZKGQICVOxWP/q4DyhpfPNMSrpIiA==", + "version": "17.0.3", + "resolved": "https://registry.npmjs.org/@types/sinon/-/sinon-17.0.3.tgz", + "integrity": "sha512-j3uovdn8ewky9kRBG19bOwaZbexJu/XjtkHyjvUgt4xfPFz18dcORIMqnYh66Fx3Powhcr85NT5+er3+oViapw==", "dev": true, "dependencies": { "@types/sinonjs__fake-timers": "*" @@ -4941,16 +4945,16 @@ } }, "node_modules/@typescript-eslint/eslint-plugin": { - "version": "6.17.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.17.0.tgz", - "integrity": "sha512-Vih/4xLXmY7V490dGwBQJTpIZxH4ZFH6eCVmQ4RFkB+wmaCTDAx4dtgoWwMNGKLkqRY1L6rPqzEbjorRnDo4rQ==", + "version": "6.18.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/eslint-plugin/-/eslint-plugin-6.18.1.tgz", + "integrity": "sha512-nISDRYnnIpk7VCFrGcu1rnZfM1Dh9LRHnfgdkjcbi/l7g16VYRri3TjXi9Ir4lOZSw5N/gnV/3H7jIPQ8Q4daA==", "dev": true, "dependencies": { "@eslint-community/regexpp": "^4.5.1", - "@typescript-eslint/scope-manager": "6.17.0", - "@typescript-eslint/type-utils": "6.17.0", - "@typescript-eslint/utils": "6.17.0", - "@typescript-eslint/visitor-keys": "6.17.0", + "@typescript-eslint/scope-manager": "6.18.1", + "@typescript-eslint/type-utils": "6.18.1", + "@typescript-eslint/utils": "6.18.1", + "@typescript-eslint/visitor-keys": "6.18.1", "debug": "^4.3.4", "graphemer": "^1.4.0", "ignore": "^5.2.4", @@ -4976,15 +4980,15 @@ } }, "node_modules/@typescript-eslint/parser": { - "version": "6.17.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-6.17.0.tgz", - "integrity": "sha512-C4bBaX2orvhK+LlwrY8oWGmSl4WolCfYm513gEccdWZj0CwGadbIADb0FtVEcI+WzUyjyoBj2JRP8g25E6IB8A==", + "version": "6.18.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-6.18.1.tgz", + "integrity": "sha512-zct/MdJnVaRRNy9e84XnVtRv9Vf91/qqe+hZJtKanjojud4wAVy/7lXxJmMyX6X6J+xc6c//YEWvpeif8cAhWA==", "dev": true, "dependencies": { - "@typescript-eslint/scope-manager": "6.17.0", - "@typescript-eslint/types": "6.17.0", - "@typescript-eslint/typescript-estree": "6.17.0", - "@typescript-eslint/visitor-keys": "6.17.0", + "@typescript-eslint/scope-manager": "6.18.1", + "@typescript-eslint/types": "6.18.1", + "@typescript-eslint/typescript-estree": "6.18.1", + "@typescript-eslint/visitor-keys": "6.18.1", "debug": "^4.3.4" }, "engines": { @@ -5004,13 +5008,13 @@ } }, "node_modules/@typescript-eslint/scope-manager": { - "version": "6.17.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-6.17.0.tgz", - "integrity": "sha512-RX7a8lwgOi7am0k17NUO0+ZmMOX4PpjLtLRgLmT1d3lBYdWH4ssBUbwdmc5pdRX8rXon8v9x8vaoOSpkHfcXGA==", + "version": "6.18.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/scope-manager/-/scope-manager-6.18.1.tgz", + "integrity": "sha512-BgdBwXPFmZzaZUuw6wKiHKIovms97a7eTImjkXCZE04TGHysG+0hDQPmygyvgtkoB/aOQwSM/nWv3LzrOIQOBw==", "dev": true, "dependencies": { - "@typescript-eslint/types": "6.17.0", - "@typescript-eslint/visitor-keys": "6.17.0" + "@typescript-eslint/types": "6.18.1", + "@typescript-eslint/visitor-keys": "6.18.1" }, "engines": { "node": "^16.0.0 || >=18.0.0" @@ -5021,13 +5025,13 @@ } }, "node_modules/@typescript-eslint/type-utils": { - "version": "6.17.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-6.17.0.tgz", - "integrity": "sha512-hDXcWmnbtn4P2B37ka3nil3yi3VCQO2QEB9gBiHJmQp5wmyQWqnjA85+ZcE8c4FqnaB6lBwMrPkgd4aBYz3iNg==", + "version": "6.18.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/type-utils/-/type-utils-6.18.1.tgz", + "integrity": "sha512-wyOSKhuzHeU/5pcRDP2G2Ndci+4g653V43gXTpt4nbyoIOAASkGDA9JIAgbQCdCkcr1MvpSYWzxTz0olCn8+/Q==", "dev": true, "dependencies": { - "@typescript-eslint/typescript-estree": "6.17.0", - "@typescript-eslint/utils": "6.17.0", + "@typescript-eslint/typescript-estree": "6.18.1", + "@typescript-eslint/utils": "6.18.1", "debug": "^4.3.4", "ts-api-utils": "^1.0.1" }, @@ -5048,9 +5052,9 @@ } }, "node_modules/@typescript-eslint/types": { - "version": "6.17.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-6.17.0.tgz", - "integrity": "sha512-qRKs9tvc3a4RBcL/9PXtKSehI/q8wuU9xYJxe97WFxnzH8NWWtcW3ffNS+EWg8uPvIerhjsEZ+rHtDqOCiH57A==", + "version": "6.18.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/types/-/types-6.18.1.tgz", + "integrity": "sha512-4TuMAe+tc5oA7wwfqMtB0Y5OrREPF1GeJBAjqwgZh1lEMH5PJQgWgHGfYufVB51LtjD+peZylmeyxUXPfENLCw==", "dev": true, "engines": { "node": "^16.0.0 || >=18.0.0" @@ -5061,13 +5065,13 @@ } }, "node_modules/@typescript-eslint/typescript-estree": { - "version": "6.17.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-6.17.0.tgz", - "integrity": "sha512-gVQe+SLdNPfjlJn5VNGhlOhrXz4cajwFd5kAgWtZ9dCZf4XJf8xmgCTLIqec7aha3JwgLI2CK6GY1043FRxZwg==", + "version": "6.18.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/typescript-estree/-/typescript-estree-6.18.1.tgz", + "integrity": "sha512-fv9B94UAhywPRhUeeV/v+3SBDvcPiLxRZJw/xZeeGgRLQZ6rLMG+8krrJUyIf6s1ecWTzlsbp0rlw7n9sjufHA==", "dev": true, "dependencies": { - "@typescript-eslint/types": "6.17.0", - "@typescript-eslint/visitor-keys": "6.17.0", + "@typescript-eslint/types": "6.18.1", + "@typescript-eslint/visitor-keys": "6.18.1", "debug": "^4.3.4", "globby": "^11.1.0", "is-glob": "^4.0.3", @@ -5089,17 +5093,17 @@ } }, "node_modules/@typescript-eslint/utils": { - "version": "6.17.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-6.17.0.tgz", - "integrity": "sha512-LofsSPjN/ITNkzV47hxas2JCsNCEnGhVvocfyOcLzT9c/tSZE7SfhS/iWtzP1lKNOEfLhRTZz6xqI8N2RzweSQ==", + "version": "6.18.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/utils/-/utils-6.18.1.tgz", + "integrity": "sha512-zZmTuVZvD1wpoceHvoQpOiewmWu3uP9FuTWo8vqpy2ffsmfCE8mklRPi+vmnIYAIk9t/4kOThri2QCDgor+OpQ==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.4.0", "@types/json-schema": "^7.0.12", "@types/semver": "^7.5.0", - "@typescript-eslint/scope-manager": "6.17.0", - "@typescript-eslint/types": "6.17.0", - "@typescript-eslint/typescript-estree": "6.17.0", + "@typescript-eslint/scope-manager": "6.18.1", + "@typescript-eslint/types": "6.18.1", + "@typescript-eslint/typescript-estree": "6.18.1", "semver": "^7.5.4" }, "engines": { @@ -5114,12 +5118,12 @@ } }, "node_modules/@typescript-eslint/visitor-keys": { - "version": "6.17.0", - "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-6.17.0.tgz", - "integrity": "sha512-H6VwB/k3IuIeQOyYczyyKN8wH6ed8EwliaYHLxOIhyF0dYEIsN8+Bk3GE19qafeMKyZJJHP8+O1HiFhFLUNKSg==", + "version": "6.18.1", + "resolved": "https://registry.npmjs.org/@typescript-eslint/visitor-keys/-/visitor-keys-6.18.1.tgz", + "integrity": "sha512-/kvt0C5lRqGoCfsbmm7/CwMqoSkY3zzHLIjdhHZQW3VFrnz7ATecOHR7nb7V+xn4286MBxfnQfQhAmCI0u+bJA==", "dev": true, "dependencies": { - "@typescript-eslint/types": "6.17.0", + "@typescript-eslint/types": "6.18.1", "eslint-visitor-keys": "^3.4.1" }, "engines": { @@ -5948,44 +5952,14 @@ "is-node": "1.0.2" } }, - "node_modules/async-test-util/node_modules/@types/clone": { - "version": "2.1.3", - "resolved": "https://registry.npmjs.org/@types/clone/-/clone-2.1.3.tgz", - "integrity": "sha512-DxFaNYaIUXW1OSRCVCC1UHoLcvk6bVJ0v9VvUaZ6kR5zK8/QazXlOThgdvnK0Xpa4sBq+b/Yoq/mnNn383hVRw==" - }, - "node_modules/async-test-util/node_modules/deep-equal": { - "version": "2.2.2", - "resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-2.2.2.tgz", - "integrity": "sha512-xjVyBf0w5vH0I42jdAZzOKVldmPgSulmiyPRywoyq7HXC9qdgo17kxJE+rdnif5Tz6+pIrpJI8dCpMNLIGkUiA==", - "dependencies": { - "array-buffer-byte-length": "^1.0.0", - "call-bind": "^1.0.2", - "es-get-iterator": "^1.1.3", - "get-intrinsic": "^1.2.1", - "is-arguments": "^1.1.1", - "is-array-buffer": "^3.0.2", - "is-date-object": "^1.0.5", - "is-regex": "^1.1.4", - "is-shared-array-buffer": "^1.0.2", - "isarray": "^2.0.5", - "object-is": "^1.1.5", - "object-keys": "^1.1.1", - "object.assign": "^4.1.4", - "regexp.prototype.flags": "^1.5.0", - "side-channel": "^1.0.4", - "which-boxed-primitive": "^1.0.2", - "which-collection": "^1.0.1", - "which-typed-array": "^1.1.9" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" + "node_modules/async-test-util/node_modules/clone": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/clone/-/clone-2.1.2.tgz", + "integrity": "sha512-3Pe/CF1Nn94hyhIYpjtiLhdCoEoz0DqQ+988E9gmeEdQZlojxnOb74wctFyuwWQHzqyf9X7C7MG8juUpqBJT8w==", + "engines": { + "node": ">=0.8" } }, - "node_modules/async-test-util/node_modules/isarray": { - "version": "2.0.5", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-2.0.5.tgz", - "integrity": "sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw==" - }, "node_modules/asynckit": { "version": "0.4.0", "resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz", @@ -6003,9 +5977,9 @@ } }, "node_modules/axios": { - "version": "1.6.4", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.4.tgz", - "integrity": "sha512-heJnIs6N4aa1eSthhN9M5ioILu8Wi8vmQW9iHQ9NUvfkJb0lEEDUiIdQNAuBtfUt3FxReaKdpQA5DbmMOqzF/A==", + "version": "1.6.5", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.5.tgz", + "integrity": "sha512-Ii012v05KEVuUoFWmMW/UQv9aRIc3ZwkWDcM+h5Il8izZCtRVpDUfwpoFf7eOtajT3QiGR4yDUx7lPqHJULgbg==", "dependencies": { "follow-redirects": "^1.15.4", "form-data": "^4.0.0", @@ -6403,9 +6377,9 @@ } }, "node_modules/caniuse-lite": { - "version": "1.0.30001574", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001574.tgz", - "integrity": "sha512-BtYEK4r/iHt/txm81KBudCUcTy7t+s9emrIaHqjYurQ10x71zJ5VQ9x1dYPcz/b+pKSp4y/v1xSI67A+LzpNyg==", + "version": "1.0.30001576", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001576.tgz", + "integrity": "sha512-ff5BdakGe2P3SQsMsiqmt1Lc8221NR1VzHj5jXN5vBny9A6fpze94HiVV/n7XRosOlsShJcvMv5mdnpjOGCEgg==", "dev": true, "funding": [ { @@ -6620,9 +6594,10 @@ } }, "node_modules/clone": { - "version": "2.1.2", - "resolved": "https://registry.npmjs.org/clone/-/clone-2.1.2.tgz", - "integrity": "sha512-3Pe/CF1Nn94hyhIYpjtiLhdCoEoz0DqQ+988E9gmeEdQZlojxnOb74wctFyuwWQHzqyf9X7C7MG8juUpqBJT8w==", + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/clone/-/clone-1.0.4.tgz", + "integrity": "sha512-JQHZ2QMW6l3aH/j6xCqQThY/9OH4D/9ls34cgkUBiEeocRTU04tHfKPBsUK1PqZCUQM7GiA0IIXJSuXHI64Kbg==", + "dev": true, "engines": { "node": ">=0.8" } @@ -7403,24 +7378,38 @@ } }, "node_modules/deep-equal": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-1.1.2.tgz", - "integrity": "sha512-5tdhKF6DbU7iIzrIOa1AOUt39ZRm13cmL1cGEh//aqR8x9+tNfbywRf0n5FD/18OKMdo7DNEtrX2t22ZAkI+eg==", + "version": "2.2.2", + "resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-2.2.2.tgz", + "integrity": "sha512-xjVyBf0w5vH0I42jdAZzOKVldmPgSulmiyPRywoyq7HXC9qdgo17kxJE+rdnif5Tz6+pIrpJI8dCpMNLIGkUiA==", "dependencies": { + "array-buffer-byte-length": "^1.0.0", + "call-bind": "^1.0.2", + "es-get-iterator": "^1.1.3", + "get-intrinsic": "^1.2.1", "is-arguments": "^1.1.1", + "is-array-buffer": "^3.0.2", "is-date-object": "^1.0.5", "is-regex": "^1.1.4", + "is-shared-array-buffer": "^1.0.2", + "isarray": "^2.0.5", "object-is": "^1.1.5", "object-keys": "^1.1.1", - "regexp.prototype.flags": "^1.5.1" - }, - "engines": { - "node": ">= 0.4" + "object.assign": "^4.1.4", + "regexp.prototype.flags": "^1.5.0", + "side-channel": "^1.0.4", + "which-boxed-primitive": "^1.0.2", + "which-collection": "^1.0.1", + "which-typed-array": "^1.1.9" }, "funding": { "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/deep-equal/node_modules/isarray": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/isarray/-/isarray-2.0.5.tgz", + "integrity": "sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw==" + }, "node_modules/deep-extend": { "version": "0.6.0", "resolved": "https://registry.npmjs.org/deep-extend/-/deep-extend-0.6.0.tgz", @@ -7457,15 +7446,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/defaults/node_modules/clone": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/clone/-/clone-1.0.4.tgz", - "integrity": "sha512-JQHZ2QMW6l3aH/j6xCqQThY/9OH4D/9ls34cgkUBiEeocRTU04tHfKPBsUK1PqZCUQM7GiA0IIXJSuXHI64Kbg==", - "dev": true, - "engines": { - "node": ">=0.8" - } - }, "node_modules/defekt": { "version": "9.3.0", "resolved": "https://registry.npmjs.org/defekt/-/defekt-9.3.0.tgz", @@ -7790,9 +7770,9 @@ } }, "node_modules/electron-to-chromium": { - "version": "1.4.623", - "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.623.tgz", - "integrity": "sha512-lKoz10iCYlP1WtRYdh5MvocQPWVRoI7ysp6qf18bmeBgR8abE6+I2CsfyNKztRDZvhdWc+krKT6wS7Neg8sw3A==", + "version": "1.4.626", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.4.626.tgz", + "integrity": "sha512-f7/be56VjRRQk+Ric6PmIrEtPcIqsn3tElyAu9Sh6egha2VLJ82qwkcOdcnT06W+Pb6RUulV1ckzrGbKzVcTHg==", "dev": true }, "node_modules/elliptic": { @@ -8444,9 +8424,9 @@ } }, "node_modules/eslint-plugin-n": { - "version": "16.6.1", - "resolved": "https://registry.npmjs.org/eslint-plugin-n/-/eslint-plugin-n-16.6.1.tgz", - "integrity": "sha512-M1kE5bVQRLBMDYRZwDhWzlzbp370SRRRC1MHqq4I3L2Tatey+9/2csc5mwLDPlmhJaDvkojbrNUME5/llpRyDg==", + "version": "16.6.2", + "resolved": "https://registry.npmjs.org/eslint-plugin-n/-/eslint-plugin-n-16.6.2.tgz", + "integrity": "sha512-6TyDmZ1HXoFQXnhCTUjVFULReoBPOAjpuiKELMkeP40yffI/1ZRO+d9ug/VC6fqISo2WkuIBk3cvuRPALaWlOQ==", "dev": true, "dependencies": { "@eslint-community/eslint-utils": "^4.4.0", @@ -11278,9 +11258,9 @@ } }, "node_modules/just-extend": { - "version": "4.2.1", - "resolved": "https://registry.npmjs.org/just-extend/-/just-extend-4.2.1.tgz", - "integrity": "sha512-g3UB796vUFIY90VIv/WX3L2c8CS2MdWUww3CNrYmqza1Fg0DURc2K/O4YrnklBdQarSJ/y8JnJYDGc+1iumQjg==", + "version": "6.2.0", + "resolved": "https://registry.npmjs.org/just-extend/-/just-extend-6.2.0.tgz", + "integrity": "sha512-cYofQu2Xpom82S6qD778jBDpwvvy39s1l/hrYij2u9AMdQcGRpaBu6kY4mVhuno5kJVi1DAz4aiphA2WI1/OAw==", "dev": true }, "node_modules/jwa": { @@ -13107,6 +13087,33 @@ "deep-equal": "^1.0.1" } }, + "node_modules/modifyjs/node_modules/clone": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/clone/-/clone-2.1.2.tgz", + "integrity": "sha512-3Pe/CF1Nn94hyhIYpjtiLhdCoEoz0DqQ+988E9gmeEdQZlojxnOb74wctFyuwWQHzqyf9X7C7MG8juUpqBJT8w==", + "engines": { + "node": ">=0.8" + } + }, + "node_modules/modifyjs/node_modules/deep-equal": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/deep-equal/-/deep-equal-1.1.2.tgz", + "integrity": "sha512-5tdhKF6DbU7iIzrIOa1AOUt39ZRm13cmL1cGEh//aqR8x9+tNfbywRf0n5FD/18OKMdo7DNEtrX2t22ZAkI+eg==", + "dependencies": { + "is-arguments": "^1.1.1", + "is-date-object": "^1.0.5", + "is-regex": "^1.1.4", + "object-is": "^1.1.5", + "object-keys": "^1.1.1", + "regexp.prototype.flags": "^1.5.1" + }, + "engines": { + "node": ">= 0.4" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, "node_modules/module-error": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/module-error/-/module-error-1.0.2.tgz", @@ -13327,25 +13334,25 @@ "dev": true }, "node_modules/nise": { - "version": "5.1.5", - "resolved": "https://registry.npmjs.org/nise/-/nise-5.1.5.tgz", - "integrity": "sha512-VJuPIfUFaXNRzETTQEEItTOP8Y171ijr+JLq42wHes3DiryR8vT+1TXQW/Rx8JNUhyYYWyIvjXTU6dOhJcs9Nw==", + "version": "5.1.7", + "resolved": "https://registry.npmjs.org/nise/-/nise-5.1.7.tgz", + "integrity": "sha512-wWtNUhkT7k58uvWTB/Gy26eA/EJKtPZFVAhEilN5UYVmmGRYOURbejRUyKm0Uu9XVEW7K5nBOZfR8VMB4QR2RQ==", "dev": true, "dependencies": { - "@sinonjs/commons": "^2.0.0", - "@sinonjs/fake-timers": "^10.0.2", - "@sinonjs/text-encoding": "^0.7.1", - "just-extend": "^4.0.2", - "path-to-regexp": "^1.7.0" + "@sinonjs/commons": "^3.0.0", + "@sinonjs/fake-timers": "^11.2.2", + "@sinonjs/text-encoding": "^0.7.2", + "just-extend": "^6.2.0", + "path-to-regexp": "^6.2.1" } }, - "node_modules/nise/node_modules/@sinonjs/commons": { - "version": "2.0.0", - "resolved": "https://registry.npmjs.org/@sinonjs/commons/-/commons-2.0.0.tgz", - "integrity": "sha512-uLa0j859mMrg2slwQYdO/AkrOfmH+X6LTVmNTS9CqexuE2IvVORIkSpJLqePAbEnKJ77aMmCwr1NUZ57120Xcg==", + "node_modules/nise/node_modules/@sinonjs/fake-timers": { + "version": "11.2.2", + "resolved": "https://registry.npmjs.org/@sinonjs/fake-timers/-/fake-timers-11.2.2.tgz", + "integrity": "sha512-G2piCSxQ7oWOxwGSAyFHfPIsyeJGXYtc6mFbnFA+kRXkiEnTl8c/8jul2S329iFBnDI9HGoeWWAZvuvOkZccgw==", "dev": true, "dependencies": { - "type-detect": "4.0.8" + "@sinonjs/commons": "^3.0.0" } }, "node_modules/nkeys.js": { @@ -13419,9 +13426,9 @@ } }, "node_modules/node-gyp-build": { - "version": "4.7.1", - "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.7.1.tgz", - "integrity": "sha512-wTSrZ+8lsRRa3I3H8Xr65dLWSgCvY2l4AOnaeKdPA9TB/WYMPaTcrzf3rXvFoVvjKNVnu0CcWSx54qq9GKRUYg==", + "version": "4.8.0", + "resolved": "https://registry.npmjs.org/node-gyp-build/-/node-gyp-build-4.8.0.tgz", + "integrity": "sha512-u6fs2AEUljNho3EYTJNBfImO5QTo/J/1Etd+NVdCj7qWKUSN/bSLkZwhDv7I+w/MSC6qJ4cknepkAYykDdK8og==", "dev": true, "bin": { "node-gyp-build": "bin.js", @@ -17348,9 +17355,9 @@ } }, "node_modules/pacote/node_modules/npm-packlist": { - "version": "8.0.1", - "resolved": "https://registry.npmjs.org/npm-packlist/-/npm-packlist-8.0.1.tgz", - "integrity": "sha512-MQpL27ZrsJQ2kiAuQPpZb5LtJwydNRnI15QWXsf3WHERu4rzjRj6Zju/My2fov7tLuu3Gle/uoIX/DDZ3u4O4Q==", + "version": "8.0.2", + "resolved": "https://registry.npmjs.org/npm-packlist/-/npm-packlist-8.0.2.tgz", + "integrity": "sha512-shYrPFIS/JLP4oQmAwDyk5HcyysKW8/JLTEA32S0Z5TzvpaeeX2yMFfoK1fjEBnCBvVyIB/Jj/GBFdm0wsgzbA==", "dev": true, "dependencies": { "ignore-walk": "^6.0.4" @@ -17550,18 +17557,9 @@ } }, "node_modules/path-to-regexp": { - "version": "1.8.0", - "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-1.8.0.tgz", - "integrity": "sha512-n43JRhlUKUAlibEJhPeir1ncUID16QnEjNpwzNdO3Lm4ywrBpBZ5oLD0I6br9evr1Y9JTqwRtAh7JLoOzAQdVA==", - "dev": true, - "dependencies": { - "isarray": "0.0.1" - } - }, - "node_modules/path-to-regexp/node_modules/isarray": { - "version": "0.0.1", - "resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz", - "integrity": "sha512-D2S+3GLxWH+uhrNEcoh/fnmYeP8E8/zHl644d/jdA0g2uyXvy3sb0qxotE+ne0LtccHknQzWwZEzhak7oJ0COQ==", + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/path-to-regexp/-/path-to-regexp-6.2.1.tgz", + "integrity": "sha512-JLyh7xT1kizaEvcaXOQwOc2/Yhw6KZOvPf1S8401UyLk86CU79LN3vl7ztXGm/pZ+YjoyAJ4rxmHwbkBXJX+yw==", "dev": true }, "node_modules/path-type": { @@ -19221,6 +19219,11 @@ "node": ">=6.9.0" } }, + "node_modules/rxdb/node_modules/@types/clone": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/@types/clone/-/clone-2.1.2.tgz", + "integrity": "sha512-fKXTsQvII/8K7xSxQF2OEuN6Pt4/PDasws60s/qeqoIOaBX7Aoevy5CmaQ4fANbvOo04MN3kx3xUIc6ZNXsmaQ==" + }, "node_modules/rxdb/node_modules/ajv": { "version": "8.12.0", "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.12.0.tgz", @@ -19279,15 +19282,18 @@ "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" }, "node_modules/safe-regex-test": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/safe-regex-test/-/safe-regex-test-1.0.0.tgz", - "integrity": "sha512-JBUUzyOgEwXQY1NuPtvcj/qcBDbDmEvWufhlnXZIm75DEHp+afM1r1ujJpJsV/gSM4t59tpDyPi1sd6ZaPFfsA==", + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/safe-regex-test/-/safe-regex-test-1.0.1.tgz", + "integrity": "sha512-Y5NejJTTliTyY4H7sipGqY+RX5P87i3F7c4Rcepy72nq+mNLhIsD0W4c7kEmduMDQCSqtPsXPlSTsFhh2LQv+g==", "dev": true, "dependencies": { - "call-bind": "^1.0.2", - "get-intrinsic": "^1.1.3", + "call-bind": "^1.0.5", + "get-intrinsic": "^1.2.2", "is-regex": "^1.1.4" }, + "engines": { + "node": ">= 0.4" + }, "funding": { "url": "https://github.com/sponsors/ljharb" } @@ -19639,9 +19645,9 @@ "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" }, "node_modules/serialize-javascript": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.1.tgz", - "integrity": "sha512-owoXEFjWRllis8/M1Q+Cw5k8ZH40e3zhp/ovX+Xr/vi1qj6QesbyXXViFbpNvWvPNAD62SutwEXavefrLJWj7w==", + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/serialize-javascript/-/serialize-javascript-6.0.2.tgz", + "integrity": "sha512-Saa1xPByTTq2gdeFZYLLo+RFE35NHZkAbqZeWNd3BpzppeVisAqpDjcp8dyf6uIvEqJRd46jemmyA4iFIeVk8g==", "dev": true, "dependencies": { "randombytes": "^2.1.0" @@ -21994,9 +22000,9 @@ } }, "node_modules/vite/node_modules/rollup": { - "version": "4.9.3", - "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.9.3.tgz", - "integrity": "sha512-JnchF0ZGFiqGpAPjg3e89j656Ne4tTtCY1VZc1AxtoQcRIxjTu9jyYHBAtkDXE+X681n4un/nX9SU52AroSRzg==", + "version": "4.9.4", + "resolved": "https://registry.npmjs.org/rollup/-/rollup-4.9.4.tgz", + "integrity": "sha512-2ztU7pY/lrQyXSCnnoU4ICjT/tCG9cdH3/G25ERqE3Lst6vl2BCM5hL2Nw+sslAvAf+ccKsAq1SkKQALyqhR7g==", "dependencies": { "@types/estree": "1.0.5" }, @@ -22008,19 +22014,19 @@ "npm": ">=8.0.0" }, "optionalDependencies": { - "@rollup/rollup-android-arm-eabi": "4.9.3", - "@rollup/rollup-android-arm64": "4.9.3", - "@rollup/rollup-darwin-arm64": "4.9.3", - "@rollup/rollup-darwin-x64": "4.9.3", - "@rollup/rollup-linux-arm-gnueabihf": "4.9.3", - "@rollup/rollup-linux-arm64-gnu": "4.9.3", - "@rollup/rollup-linux-arm64-musl": "4.9.3", - "@rollup/rollup-linux-riscv64-gnu": "4.9.3", - "@rollup/rollup-linux-x64-gnu": "4.9.3", - "@rollup/rollup-linux-x64-musl": "4.9.3", - "@rollup/rollup-win32-arm64-msvc": "4.9.3", - "@rollup/rollup-win32-ia32-msvc": "4.9.3", - "@rollup/rollup-win32-x64-msvc": "4.9.3", + "@rollup/rollup-android-arm-eabi": "4.9.4", + "@rollup/rollup-android-arm64": "4.9.4", + "@rollup/rollup-darwin-arm64": "4.9.4", + "@rollup/rollup-darwin-x64": "4.9.4", + "@rollup/rollup-linux-arm-gnueabihf": "4.9.4", + "@rollup/rollup-linux-arm64-gnu": "4.9.4", + "@rollup/rollup-linux-arm64-musl": "4.9.4", + "@rollup/rollup-linux-riscv64-gnu": "4.9.4", + "@rollup/rollup-linux-x64-gnu": "4.9.4", + "@rollup/rollup-linux-x64-musl": "4.9.4", + "@rollup/rollup-win32-arm64-msvc": "4.9.4", + "@rollup/rollup-win32-ia32-msvc": "4.9.4", + "@rollup/rollup-win32-x64-msvc": "4.9.4", "fsevents": "~2.3.2" } }, @@ -22760,27 +22766,31 @@ }, "packages/database": { "name": "@pluto-encrypted/database", - "version": "1.12.0-rc.1", + "version": "2.0.0-rc.2", "license": "Apache-2.0", "dependencies": { "@atala/prism-wallet-sdk": "^4.0.0-rc.1", - "@pluto-encrypted/encryption": "1.9.3", + "@pluto-encrypted/encryption": "1.10.0-rc.1", + "@pluto-encrypted/schemas": "^1.0.0-rc.1", + "@pluto-encrypted/shared": "2.0.0-rc.2", "rxdb": "^14.17.0", "rxjs": "7.8.1", "uuid": "^9.0.1" }, "devDependencies": { - "@pluto-encrypted/encryption": "1.9.3", - "@pluto-encrypted/indexdb": "1.9.4", - "@pluto-encrypted/inmemory": "1.9.4", - "@pluto-encrypted/leveldb": "1.9.4", + "@pluto-encrypted/encryption": "1.10.0-rc.1", + "@pluto-encrypted/indexdb": "2.0.0-rc.2", + "@pluto-encrypted/inmemory": "2.0.0-rc.2", + "@pluto-encrypted/leveldb": "2.0.0-rc.2", + "@pluto-encrypted/schemas": "^1.0.0-rc.1", + "@pluto-encrypted/shared": "2.0.0-rc.2", "@vitest/coverage-v8": "^1.0.4", "level": "^6.0.1" }, "optionalDependencies": { - "@pluto-encrypted/indexdb": "1.9.4", - "@pluto-encrypted/inmemory": "1.9.4", - "@pluto-encrypted/leveldb": "1.9.4" + "@pluto-encrypted/indexdb": "2.0.0-rc.2", + "@pluto-encrypted/inmemory": "2.0.0-rc.2", + "@pluto-encrypted/leveldb": "2.0.0-rc.2" }, "peerDependencies": { "@atala/prism-wallet-sdk": "^4.0.0-rc.1" @@ -22788,7 +22798,7 @@ }, "packages/encryption": { "name": "@pluto-encrypted/encryption", - "version": "1.9.3", + "version": "1.10.0-rc.1", "license": "Apache-2.0", "dependencies": { "@noble/ciphers": "^0.4.1", @@ -22802,8 +22812,6 @@ }, "packages/encryption/node_modules/buffer": { "version": "6.0.3", - "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", - "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", "funding": [ { "type": "github", @@ -22818,6 +22826,7 @@ "url": "https://feross.org/support" } ], + "license": "MIT", "dependencies": { "base64-js": "^1.3.1", "ieee754": "^1.2.1" @@ -22825,55 +22834,53 @@ }, "packages/indexdb": { "name": "@pluto-encrypted/indexdb", - "version": "1.9.4", + "version": "2.0.0-rc.2", "license": "Apache-2.0", "dependencies": { - "@pluto-encrypted/encryption": "1.9.3", - "@pluto-encrypted/shared": "1.9.3", + "@pluto-encrypted/encryption": "1.10.0-rc.1", + "@pluto-encrypted/shared": "2.0.0-rc.2", "array-push-at-sort-position": "^4.0.1", "rxdb": "^14.17.0", "uuid": "^9.0.1" }, "devDependencies": { - "@pluto-encrypted/encryption": "1.9.3", - "@pluto-encrypted/shared": "1.9.3", - "@pluto-encrypted/test-suite": "1.9.4" + "@pluto-encrypted/encryption": "1.10.0-rc.1", + "@pluto-encrypted/shared": "2.0.0-rc.2", + "@pluto-encrypted/test-suite": "1.10.0-rc.1" } }, "packages/indexdb/node_modules/array-push-at-sort-position": { "version": "4.0.1", - "resolved": "https://registry.npmjs.org/array-push-at-sort-position/-/array-push-at-sort-position-4.0.1.tgz", - "integrity": "sha512-KdtdxZmp+j6n+jiekMbBRO/TOVP7oEadrJ+M4jB0Oe1VHZHS1Uwzx5lsvFN4juNZtHNA1l1fvcEs/SDmdoXL3w==" + "license": "Apache-2.0" }, "packages/inmemory": { "name": "@pluto-encrypted/inmemory", - "version": "1.9.4", + "version": "2.0.0-rc.2", "license": "Apache-2.0", "dependencies": { - "@pluto-encrypted/encryption": "1.9.3", - "@pluto-encrypted/shared": "1.9.3", + "@pluto-encrypted/encryption": "1.10.0-rc.1", + "@pluto-encrypted/shared": "2.0.0-rc.2", "array-push-at-sort-position": "^4.0.1", "rxdb": "^14.17.0", "uuid": "^9.0.1" }, "devDependencies": { - "@pluto-encrypted/encryption": "1.9.3", - "@pluto-encrypted/shared": "1.9.3", - "@pluto-encrypted/test-suite": "1.9.4" + "@pluto-encrypted/encryption": "1.10.0-rc.1", + "@pluto-encrypted/shared": "2.0.0-rc.2", + "@pluto-encrypted/test-suite": "1.10.0-rc.1" } }, "packages/inmemory/node_modules/array-push-at-sort-position": { "version": "4.0.1", - "resolved": "https://registry.npmjs.org/array-push-at-sort-position/-/array-push-at-sort-position-4.0.1.tgz", - "integrity": "sha512-KdtdxZmp+j6n+jiekMbBRO/TOVP7oEadrJ+M4jB0Oe1VHZHS1Uwzx5lsvFN4juNZtHNA1l1fvcEs/SDmdoXL3w==" + "license": "Apache-2.0" }, "packages/leveldb": { "name": "@pluto-encrypted/leveldb", - "version": "1.9.4", + "version": "2.0.0-rc.2", "license": "Apache-2.0", "dependencies": { - "@pluto-encrypted/encryption": "1.9.3", - "@pluto-encrypted/shared": "1.9.3", + "@pluto-encrypted/encryption": "1.10.0-rc.1", + "@pluto-encrypted/shared": "2.0.0-rc.2", "array-push-at-sort-position": "^4.0.1", "level": "^6.0.1", "module-error": "^1.0.2", @@ -22883,28 +22890,49 @@ "uuid": "^9.0.1" }, "devDependencies": { - "@pluto-encrypted/encryption": "1.9.3", - "@pluto-encrypted/shared": "1.9.3", - "@pluto-encrypted/test-suite": "1.9.4" + "@pluto-encrypted/encryption": "1.10.0-rc.1", + "@pluto-encrypted/shared": "2.0.0-rc.2", + "@pluto-encrypted/test-suite": "1.10.0-rc.1" } }, "packages/leveldb/node_modules/array-push-at-sort-position": { "version": "4.0.1", - "resolved": "https://registry.npmjs.org/array-push-at-sort-position/-/array-push-at-sort-position-4.0.1.tgz", - "integrity": "sha512-KdtdxZmp+j6n+jiekMbBRO/TOVP7oEadrJ+M4jB0Oe1VHZHS1Uwzx5lsvFN4juNZtHNA1l1fvcEs/SDmdoXL3w==" + "license": "Apache-2.0" + }, + "packages/schemas": { + "name": "@pluto-encrypted/schemas", + "version": "1.0.0-rc.2", + "license": "Apache-2.0", + "dependencies": { + "@atala/prism-wallet-sdk": "^4.0.0-rc.1", + "@pluto-encrypted/encryption": "1.10.0-rc.1", + "@pluto-encrypted/shared": "2.0.0-rc.2", + "rxdb": "^14.17.0", + "rxjs": "7.8.1", + "uuid": "^9.0.1" + }, + "devDependencies": { + "@pluto-encrypted/encryption": "1.10.0-rc.1", + "@pluto-encrypted/shared": "2.0.0-rc.2", + "@vitest/coverage-v8": "^1.0.4" + }, + "peerDependencies": { + "@atala/prism-wallet-sdk": "^4.0.0-rc.1" + } }, "packages/shared": { "name": "@pluto-encrypted/shared", - "version": "1.9.3", + "version": "2.0.0-rc.2", "license": "Apache-2.0", "dependencies": { + "@pluto-encrypted/encryption": "1.10.0-rc.1", "rxdb": "^14.17.0", "uuid": "^9.0.1" } }, "packages/test-suite": { "name": "@pluto-encrypted/test-suite", - "version": "1.9.4", + "version": "1.10.0-rc.1", "license": "Apache-2.0", "dependencies": { "@faker-js/faker": "^8.3.1", diff --git a/package.json b/package.json index 14b906c8..fcb0eab1 100644 --- a/package.json +++ b/package.json @@ -88,4 +88,4 @@ "dependencies": { "typedoc-plugin-external-module-map": "^2.0.1" } -} +} \ No newline at end of file diff --git a/packages/database/coverage/coverage-summary.json b/packages/database/coverage/coverage-summary.json index 4f618502..0a227bd7 100644 --- a/packages/database/coverage/coverage-summary.json +++ b/packages/database/coverage/coverage-summary.json @@ -1,11 +1,3 @@ -{"total": {"lines":{"total":207,"covered":207,"skipped":0,"pct":100},"statements":{"total":218,"covered":218,"skipped":0,"pct":100},"functions":{"total":77,"covered":77,"skipped":0,"pct":100},"branches":{"total":72,"covered":72,"skipped":0,"pct":100},"branchesTrue":{"total":0,"covered":0,"skipped":0,"pct":100}} -,"/home/runner/work/pluto-encrypted/pluto-encrypted/packages/database/src/index.ts": {"lines":{"total":153,"covered":153,"skipped":0,"pct":100},"functions":{"total":67,"covered":67,"skipped":0,"pct":100},"statements":{"total":164,"covered":164,"skipped":0,"pct":100},"branches":{"total":50,"covered":50,"skipped":0,"pct":100}} -,"/home/runner/work/pluto-encrypted/pluto-encrypted/packages/database/src/schemas/Credential.ts": {"lines":{"total":11,"covered":11,"skipped":0,"pct":100},"functions":{"total":1,"covered":1,"skipped":0,"pct":100},"statements":{"total":11,"covered":11,"skipped":0,"pct":100},"branches":{"total":4,"covered":4,"skipped":0,"pct":100}} -,"/home/runner/work/pluto-encrypted/pluto-encrypted/packages/database/src/schemas/CredentialRequestMetadata.ts": {"lines":{"total":3,"covered":3,"skipped":0,"pct":100},"functions":{"total":1,"covered":1,"skipped":0,"pct":100},"statements":{"total":3,"covered":3,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}} -,"/home/runner/work/pluto-encrypted/pluto-encrypted/packages/database/src/schemas/DID.ts": {"lines":{"total":1,"covered":1,"skipped":0,"pct":100},"functions":{"total":0,"covered":0,"skipped":0,"pct":100},"statements":{"total":1,"covered":1,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}} -,"/home/runner/work/pluto-encrypted/pluto-encrypted/packages/database/src/schemas/DIDPair.ts": {"lines":{"total":1,"covered":1,"skipped":0,"pct":100},"functions":{"total":0,"covered":0,"skipped":0,"pct":100},"statements":{"total":1,"covered":1,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}} -,"/home/runner/work/pluto-encrypted/pluto-encrypted/packages/database/src/schemas/LinkSecret.ts": {"lines":{"total":3,"covered":3,"skipped":0,"pct":100},"functions":{"total":1,"covered":1,"skipped":0,"pct":100},"statements":{"total":3,"covered":3,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}} -,"/home/runner/work/pluto-encrypted/pluto-encrypted/packages/database/src/schemas/Mediator.ts": {"lines":{"total":4,"covered":4,"skipped":0,"pct":100},"functions":{"total":1,"covered":1,"skipped":0,"pct":100},"statements":{"total":4,"covered":4,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}} -,"/home/runner/work/pluto-encrypted/pluto-encrypted/packages/database/src/schemas/Message.ts": {"lines":{"total":3,"covered":3,"skipped":0,"pct":100},"functions":{"total":1,"covered":1,"skipped":0,"pct":100},"statements":{"total":3,"covered":3,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}} -,"/home/runner/work/pluto-encrypted/pluto-encrypted/packages/database/src/schemas/PrivateKey.ts": {"lines":{"total":28,"covered":28,"skipped":0,"pct":100},"functions":{"total":5,"covered":5,"skipped":0,"pct":100},"statements":{"total":28,"covered":28,"skipped":0,"pct":100},"branches":{"total":18,"covered":18,"skipped":0,"pct":100}} +{"total": {"lines":{"total":31,"covered":31,"skipped":0,"pct":100},"statements":{"total":31,"covered":31,"skipped":0,"pct":100},"functions":{"total":5,"covered":5,"skipped":0,"pct":100},"branches":{"total":18,"covered":18,"skipped":0,"pct":100},"branchesTrue":{"total":0,"covered":0,"skipped":0,"pct":"Unknown"}} +,"/Users/ribo/Projects/personal/pluto-encrypted/packages/database/src/index.ts": {"lines":{"total":31,"covered":31,"skipped":0,"pct":100},"functions":{"total":5,"covered":5,"skipped":0,"pct":100},"statements":{"total":31,"covered":31,"skipped":0,"pct":100},"branches":{"total":18,"covered":18,"skipped":0,"pct":100}} } diff --git a/packages/database/package.json b/packages/database/package.json index c61d1c45..10ffdaaa 100644 --- a/packages/database/package.json +++ b/packages/database/package.json @@ -1,6 +1,6 @@ { "name": "@pluto-encrypted/database", - "version": "1.11.1", + "version": "2.0.0-rc.3", "description": "Encrypted database for Edge Wallet SDK that supports multiple db, IndexDB, LevelDB and InMemory", "main": "./build/cjs/index.cjs", "module": "./build/esm/index.mjs", @@ -36,21 +36,25 @@ "@atala/prism-wallet-sdk": "^4.0.0-rc.1" }, "optionalDependencies": { - "@pluto-encrypted/indexdb": "1.9.4", - "@pluto-encrypted/inmemory": "1.9.4", - "@pluto-encrypted/leveldb": "1.9.4" + "@pluto-encrypted/indexdb": "2.0.0-rc.3", + "@pluto-encrypted/inmemory": "2.0.0-rc.3", + "@pluto-encrypted/leveldb": "2.0.0-rc.3" }, "devDependencies": { - "@pluto-encrypted/encryption": "1.9.3", - "@pluto-encrypted/indexdb": "1.9.4", - "@pluto-encrypted/inmemory": "1.9.4", - "@pluto-encrypted/leveldb": "1.9.4", + "@pluto-encrypted/encryption": "1.10.0-rc.1", + "@pluto-encrypted/indexdb": "2.0.0-rc.3", + "@pluto-encrypted/inmemory": "2.0.0-rc.3", + "@pluto-encrypted/leveldb": "2.0.0-rc.3", + "@pluto-encrypted/shared": "2.0.0-rc.3", + "@pluto-encrypted/schemas": "^1.0.0-rc.1", "@vitest/coverage-v8": "^1.0.4", "level": "^6.0.1" }, "dependencies": { "@atala/prism-wallet-sdk": "^4.0.0-rc.1", - "@pluto-encrypted/encryption": "1.9.3", + "@pluto-encrypted/encryption": "1.10.0-rc.1", + "@pluto-encrypted/shared": "2.0.0-rc.3", + "@pluto-encrypted/schemas": "^1.0.0-rc.1", "rxdb": "^14.17.0", "rxjs": "7.8.1", "uuid": "^9.0.1" diff --git a/packages/database/src/index.ts b/packages/database/src/index.ts index 62c82c75..f9b52903 100644 --- a/packages/database/src/index.ts +++ b/packages/database/src/index.ts @@ -1,1135 +1,159 @@ /** + * * @packageDocumentation * @module database */ import SDK from '@atala/prism-wallet-sdk' +import { getDefaultCollections } from '@pluto-encrypted/schemas' +import { DatabaseBase, ValuesOf } from '@pluto-encrypted/shared' import { - type MangoQuerySelector, type RxCollectionCreator, - type RxDatabase, - type RxDatabaseCreator, - type RxDumpDatabase, - type RxError, - type RxStorage, - addRxPlugin, - createRxDatabase, - removeRxDatabase + CollectionsOfDatabase, + RxCollection, + RxCollectionCreator, + RxDumpDatabase, + RxError, + RxStorage } from 'rxdb' -import { RxDBEncryptedMigrationPlugin } from '@pluto-encrypted/encryption' -import { RxDBJsonDumpPlugin } from 'rxdb/plugins/json-dump' -import { RxDBQueryBuilderPlugin } from 'rxdb/plugins/query-builder' -import { v4 as uuidv4 } from 'uuid' -import CredentialSchema, { - type CredentialCollection, - CredentialMethods -} from './schemas/Credential' -import CredentialRequestMetadataSchema, { - type CredentialRequestMetadataCollection, - CredentialRequestMetadataMethods -} from './schemas/CredentialRequestMetadata' -import DIDSchema, { type DIDCollection } from './schemas/DID' -import DIDPairSchema, { type DIDPairCollection } from './schemas/DIDPair' -import LinkSecretSchema, { - type LinkSecretColletion, - LinkSecretMethods -} from './schemas/LinkSecret' -import MediatorSchema, { - type MediatorCollection, - MediatorMethods -} from './schemas/Mediator' -import MessageSchema, { - type MessageColletion, - MessageMethods, - type MessageSchemaType -} from './schemas/Message' -import PrivateKeySchema, { - type KeySpec, type PrivateKeyColletion, type PrivateKeyDocument, - PrivateKeyMethods -} from './schemas/PrivateKey' -import { type PlutoCollections } from './types' -export * from './schemas/Credential' -export * from './schemas/CredentialRequestMetadata' -export * from './schemas/DID' -export * from './schemas/DIDPair' -export * from './schemas/LinkSecret' -export * from './schemas/Mediator' -export * from './schemas/Message' -export * from './schemas/PrivateKey' export type * from './types' -export type { Domain as WALLET_SDK_DOMAIN } from '@atala/prism-wallet-sdk' -export type ValuesOf = T[keyof T] -export type PlutoDatabase = RxDatabase +type ExtractDTcol2

= P extends RxCollectionCreator ? T : any /** * Pluto is a storage interface describing storage requirements of the edge agents * which will be implemented using this SDK. Implement this interface using your * preferred underlying storage technology, most appropriate for your use case. */ -export class Database implements SDK.Domain.Pluto { - private _db!: RxDatabase - - protected get db() { - if (!this._db) { - throw new Error('Start Pluto first.') - } - return this._db - } - - constructor(private readonly dbOptions: RxDatabaseCreator) { - addRxPlugin(RxDBQueryBuilderPlugin) - addRxPlugin(RxDBJsonDumpPlugin) - addRxPlugin(RxDBEncryptedMigrationPlugin) - } - - async backup() { - return await this.db.exportJSON() - } - - get collections(): PlutoCollections { - return this.db.collections - } - - /** - * CredentialRequestMetadatas - * Stores anoncreds credential metadata + exposes orm functions - * - * Count all Credential Metadatas with optional query - * ```ts - * await db.credentialmetadatas.count({selector: {id: {$eq: 1}}}) //Query is optional - * ``` - * - * Find all credential metadatas matching the query - * ```ts - * await db.credentialmetadatas.find({selector: {id: {$eq: 1}}}) //Query is optional - * ``` - * - * Find all credential metadatas by id - * ```ts - * await db.credentialmetadatas.findByIds([id]) - * ``` - * Find one credential metadatas matching the query - * ```ts - * await db.credentialmetadatas.findOne({selector: {id: {$eq: 1}}}) //Query is optional - * ``` - * - * Remove any credential metadatas matching the query - * ```ts - * await db.credentialmetadatas.remove({selector: {id: {$eq: 1}}}) - * ``` - */ - get credentialrequestmetadatas(): CredentialRequestMetadataCollection { - return this.db.collections.credentialrequestmetadatas - } - - /** - * LinkSecrets - * Stores anoncreds link secrets + exposes orm functions - * - * Count all LinkSecrets with optional query - * ```ts - * await db.linksecrets.count({selector: {id: {$eq: 1}}}) //Query is optional - * ``` - * - * Find all LinkSecrets matching the query - * ```ts - * await db.linksecrets.find({selector: {id: {$eq: 1}}}) //Query is optional - * ``` - * - * Find all LinkSecrets by id - * ```ts - * await db.linksecrets.findByIds([id]) - * ``` - * Find one LinkSecrets matching the query - * ```ts - * await db.linksecrets.findOne({selector: {id: {$eq: 1}}}) //Query is optional - * ``` - * - * Remove any LinkSecrets matching the query - * ```ts - * await db.linksecrets.remove({selector: {id: {$eq: 1}}}) - * ``` - */ - get linksecrets(): LinkSecretColletion { - return this.db.collections.linksecrets - } - - /** - * DIDPairs - * Stores groups of dids, also known as connections + exposes orm functions - * - * Count all DIDPairs with optional query - * ```ts - * await db.didpairs.count({selector: {id: {$eq: 1}}}) //Query is optional - * ``` - * - * Find all DIDPairs matching the query - * ```ts - * await db.didpairs.find({selector: {id: {$eq: 1}}}) //Query is optional - * ``` - * - * Find all DIDPairs by id - * ```ts - * await db.didpairs.findByIds([id]) - * ``` - * Find one DIDPairs matching the query - * ```ts - * await db.didpairs.findOne({selector: {id: {$eq: 1}}}) //Query is optional - * ``` - * - * Remove any DIDPairs matching the query - * ```ts - * await db.didpairs.remove({selector: {id: {$eq: 1}}}) - * ``` - */ - get didpairs(): DIDPairCollection { - return this.db.collections.didpairs - } - - /** - * Credentials - * Stores credentials, both anoncreda and prism/jwt + exposes orm functions - * - * Count all Credentials with optional query - * ```ts - * await db.credentials.count({selector: {id: {$eq: 1}}}) //Query is optional - * ``` - * - * Find all Credentials matching the query - * ```ts - * await db.credentials.find({selector: {id: {$eq: 1}}}) //Query is optional - * ``` - * - * Find all Credentials by id - * ```ts - * await db.credentials.findByIds([id]) - * ``` - * Find one Credentials matching the query - * ```ts - * await db.credentials.findOne({selector: {id: {$eq: 1}}}) //Query is optional - * ``` - * - * Remove any Credentials matching the query - * ```ts - * await db.credentials.remove({selector: {id: {$eq: 1}}}) - * ``` - */ - get credentials(): CredentialCollection { - return this.db.collections.credentials - } - - /** - * Mediators - * Stores mediators + exposes orm functions - * - * Count all Mediators with optional query - * ```ts - * await db.mediators.count({selector: {id: {$eq: 1}}}) //Query is optional - * ``` - * - * Find all Mediators matching the query - * ```ts - * await db.mediators.find({selector: {id: {$eq: 1}}}) //Query is optional - * ``` - * - * Find all Mediators by id - * ```ts - * await db.mediators.findByIds([id]) - * ``` - * Find one Mediators matching the query - * ```ts - * await db.mediators.findOne({selector: {id: {$eq: 1}}}) //Query is optional - * ``` - * - * Remove any Mediators matching the query - * ```ts - * await db.mediators.remove({selector: {id: {$eq: 1}}}) - * ``` - */ - get mediators(): MediatorCollection { - return this.db.collections.mediators - } - - /** - * DIDs - * Stores dids + exposes orm functions - * - * Count all DIDS with optional query - * ```ts - * await db.dids.count({selector: {id: {$eq: 1}}}) //Query is optional - * ``` - * - * Find all DIDS matching the query - * ```ts - * await db.dids.find({selector: {id: {$eq: 1}}}) //Query is optional - * ``` - * - * Find all DIDS by id - * ```ts - * await db.dids.findByIds([id]) - * ``` - * Find one DIDS matching the query - * ```ts - * await db.dids.findOne({selector: {id: {$eq: 1}}}) //Query is optional - * ``` - * - * Remove any DIDS matching the query - * ```ts - * await db.dids.remove({selector: {id: {$eq: 1}}}) - * ``` - */ - get dids(): DIDCollection { - return this.db.collections.dids - } - - /** - * PrivateKeys - * Stores privateKeys + exposes orm functions - * - * Count all PrivateKeys with optional query - * ```ts - * await db.privatekeys.count({selector: {id: {$eq: 1}}}) //Query is optional - * ``` - * - * Find all PrivateKeys matching the query - * ```ts - * await db.privatekeys.find({selector: {id: {$eq: 1}}}) //Query is optional - * ``` - * - * Find all PrivateKeys by id - * ```ts - * await db.privatekeys.findByIds([id]) - * ``` - * Find one PrivateKeys matching the query - * ```ts - * await db.privatekeys.findOne({selector: {id: {$eq: 1}}}) //Query is optional - * ``` - * - * Remove any PrivateKeys matching the query - * ```ts - * await db.privatekeys.remove({selector: {id: {$eq: 1}}}) - * ``` - */ - get privatekeys(): PrivateKeyColletion { - return this.db.collections.privatekeys - } - - /** - * Messages - * Stores Messages + exposes orm functions - * - * Count all Messages with optional query - * ```ts - * await db.messages.count({selector: {id: {$eq: 1}}}) //Query is optional - * ``` - * - * Find all Messages matching the query - * ```ts - * await db.messages.find({selector: {id: {$eq: 1}}}) //Query is optional - * ``` - * - * Find all Messages by id - * ```ts - * await db.messages.findByIds([id]) - * ``` - * Find one Messages matching the query - * ```ts - * await db.messages.findOne({selector: {id: {$eq: 1}}}) //Query is optional - * ``` - * - * Remove any Messages matching the query - * ```ts - * await db.messages.remove({selector: {id: {$eq: 1}}}) - * ``` - */ - get messages(): MessageColletion { - return this.db.collections.messages - } - - /** - * Use with caution, this will remove all entries from database - * and then destroy the database itself. - */ - async clear() { - const storages = Array.from(this.db.storageInstances.values()) - for (const storage of storages) { - await storage.cleanup(Infinity) - } - await removeRxDatabase(this.dbOptions.name, this.db.storage) - } +export const Database = { + createBaseEncrypted: async function createBaseEncrypted< + Collections extends CollectionsOfDatabase, + >(options: { + name: string; + encryptionKey: Uint8Array; + importData?: RxDumpDatabase; + storage: RxStorage; + autoStart?: boolean; + collections?: { + [key in keyof Collections]: RxCollectionCreator; + }; + }) { + + const { + name, + storage, + encryptionKey, + importData, + autoStart = true, + collections + } = options + + if (!storage) { + throw new Error('Please provide a valid storage.') + } + + const instance = new DatabaseBase({ + ignoreDuplicate: true, + name, + storage, + password: Buffer.from(encryptionKey).toString('hex') + }) - /** - * Creates a database instance. - * @param options - * @returns Database - */ - static async createEncrypted( - options: { - name: string - encryptionKey: Uint8Array - importData?: RxDumpDatabase - storage: RxStorage - autoStart?: boolean - collections?: Partial<{ - messages: RxCollectionCreator - dids: RxCollectionCreator - didpairs: RxCollectionCreator - mediators: RxCollectionCreator - privatekeys: RxCollectionCreator - credentials: RxCollectionCreator - credentialrequestmetadatas: RxCollectionCreator - linksecrets: RxCollectionCreator - }> - } - ) { + if (autoStart) { + await instance.start(collections) + } + + if (importData) { + await instance.db.importJSON(importData) + } + + return instance + }, + createEncrypted: async function createEncrypted< + Collections extends CollectionsOfDatabase, + ExtendedCollections extends CollectionsOfDatabase = Collections & { [key in keyof ReturnType]: RxCollection[key]>> }, + STATIC_RETURN = ExtendedCollections[keyof ExtendedCollections]['statics'] + >(options: { + name: string; + encryptionKey: Uint8Array; + importData?: RxDumpDatabase; + storage: RxStorage; + autoStart?: boolean; + withDefaultCollections?: boolean; + collections?: { + [key in keyof Collections]: RxCollectionCreator; + }; + }): Promise & SDK.Domain.Pluto & STATIC_RETURN> { try { - const { name, storage, encryptionKey, importData, autoStart = true, collections } = options - if (!storage) { - throw new Error('Please provide a valid storage.') - } - const database = new Database({ - ignoreDuplicate: true, - name, - storage, - password: Buffer.from(encryptionKey).toString('hex') - }) - - if (autoStart) { - await database.start(collections) - } - - if (importData) { - await database.db.importJSON(importData) - } - - return database - } catch (err) { - /* istanbul ignore else */ - if ((err as RxError).code === 'DB1') { - throw new Error('Invalid Authentication') - } else { - /* istanbul ignore next */ - - throw err - } - } - } - - /** - * Get a Message by its id - * @param id - * @returns [Message](https://input-output-hk.github.io/atala-prism-wallet-sdk-ts/classes/Domain.Message.html) - */ - async getMessage(id: string): Promise { - const message = await this.db.messages.findOne({ - selector: { - id: { - $eq: id - } - } - }).exec() - if (message) { - return message.toDomainMessage() - } - return null - } - - /** - * Stores a message - * @param [Message](https://input-output-hk.github.io/atala-prism-wallet-sdk-ts/classes/Domain.Message.html) - * @returns void - */ - async storeMessage(message: SDK.Domain.Message): Promise { - const existing = await this.db.messages - .findOne({ - selector: { - id: { - $eq: message.id + const { withDefaultCollections = true, collections } = options; + const collectionMap = new Map>(); + + if (withDefaultCollections) { + const defaultCollections = getDefaultCollections() + Object.keys(getDefaultCollections()).forEach((collectionName) => { + const currentCollection = defaultCollections[collectionName]; + if (currentCollection) { + collectionMap.set(collectionName, currentCollection) } - } - }).exec() - if (existing) { - await existing.patch({ - ...message, - to: message.to?.toString(), - from: message.from?.toString() - }) - } else { - await this.db.messages.insert({ - ...message, - to: message.to?.toString(), - from: message.from?.toString() - }) - } - } - - /** - * Stores multiple messages in 1 call - * @param [Message[]](https://input-output-hk.github.io/atala-prism-wallet-sdk-ts/classes/Domain.Message.html) - * @returns void - */ - async storeMessages(messages: SDK.Domain.Message[]): Promise { - for (const message of messages) { - await this.storeMessage(message) - } - } - - /** - * Get all the stored messages - * @returns [Message[]](https://input-output-hk.github.io/atala-prism-wallet-sdk-ts/classes/Domain.Message.html) - */ - async getAllMessages(): Promise { - const messages = await this.db.messages.find().exec() - return messages.map((message) => message.toDomainMessage()) - } - - private getDefaultCollections() { - return { - messages: { - schema: MessageSchema, - methods: MessageMethods - }, - dids: { - schema: DIDSchema - }, - didpairs: { - schema: DIDPairSchema - }, - mediators: { - schema: MediatorSchema, - methods: MediatorMethods - }, - privatekeys: { - schema: PrivateKeySchema, - methods: PrivateKeyMethods - }, - credentials: { - schema: CredentialSchema, - methods: CredentialMethods - }, - credentialrequestmetadatas: { - schema: CredentialRequestMetadataSchema, - methods: CredentialRequestMetadataMethods - }, - linksecrets: { - schema: LinkSecretSchema, - methods: LinkSecretMethods + }); } - } - } - - /** - * Start the database and build collections - */ - async start(collections?: Partial<{ - messages: RxCollectionCreator - dids: RxCollectionCreator - didpairs: RxCollectionCreator - mediators: RxCollectionCreator - privatekeys: RxCollectionCreator - credentials: RxCollectionCreator - credentialrequestmetadatas: RxCollectionCreator - linksecrets: RxCollectionCreator - }>): Promise { - const { dbOptions } = this - - const database = await createRxDatabase({ - ...dbOptions, - multiInstance: false - }) - - await database.addCollections({ - ...this.getDefaultCollections(), - ...(collections ?? {}) as any - }) - - this._db = database - } - - /** - * Stores a prismDID and its privateKey - * @param did - * @param keyPathIndex - * @param privateKey - * @param privateKeyMetaId - * @param alias - */ - async storePrismDID( - did: SDK.Domain.DID, - keyPathIndex: number, - privateKey: SDK.Domain.PrivateKey, - _privateKeyMetaId?: string | null, - alias?: string | undefined - ): Promise { - await this.db.dids.insert({ - did: did.toString(), - method: did.method, - methodId: did.methodId, - schema: did.schema, - alias - }) - await this.storePrivateKeys( - privateKey, - did, - keyPathIndex - ) - } - - /** - * Stores a peerdid with its privateKeys - * @param did - * @param privateKeys - */ - async storePeerDID( - did: SDK.Domain.DID, - privateKeys: SDK.Domain.PrivateKey[] - ): Promise { - await this.db.dids.insert({ - did: did.toString(), - method: did.method, - methodId: did.methodId, - schema: did.schema - }) - for (const prv of privateKeys) { - await this.db.privatekeys.insert({ - id: uuidv4(), - did: did.toString(), - type: prv.type, - keySpecification: Array.from(prv.keySpecification).reduce( - (all, [key, value]) => [ - ...all, - { - type: 'string', - name: key, - value: `${value}` - } - ], - [ - { - type: 'string', - name: 'raw', - value: Buffer.from(prv.raw).toString('hex') - } - ] - ) - }) - } - } - - /** - * Stores a didpair - * @param host - * @param receiver - * @param name - */ - async storeDIDPair( - host: SDK.Domain.DID, - receiver: SDK.Domain.DID, - name: string - ): Promise { - await this.db.didpairs.insert({ - hostDID: host.toString(), - receiverDID: receiver.toString(), - name - }) - } - - /** - * Stores privateKeys references to an existing DID - * @param privateKey - * @param did - * @param keyPathIndex - * @param _metaId - */ - async storePrivateKeys( - privateKey: SDK.Domain.PrivateKey, - did: SDK.Domain.DID, - keyPathIndex: number - ): Promise { - await this.db.privatekeys.insert({ - id: uuidv4(), - did: did.toString(), - type: privateKey.type, - keySpecification: Array.from(privateKey.keySpecification).reduce( - (all, [key, value]) => [ - ...all, - { - type: 'string', - name: key, - value: `${value}` - } - ], - [ - { - type: 'string', - name: 'raw', - value: Buffer.from(privateKey.raw).toString('hex') - }, - { - type: 'number', - name: 'index', - value: `${keyPathIndex}` - } - ] - ) - }) - } - - /** - * Gets all the stores didPairs - * @returns [Domain.DIDPair[]](https://input-output-hk.github.io/atala-prism-wallet-sdk-ts/classes/Domain.DIDPair.html) - */ - async getAllDidPairs(): Promise { - const results = await this.db.didpairs.find().exec() - return results.map( - ({ hostDID, receiverDID, name }) => - new SDK.Domain.DIDPair(SDK.Domain.DID.fromString(hostDID), SDK.Domain.DID.fromString(receiverDID), name) - ) - } - - /** - * Get a did pair (connection) by one of its dids - * @param did - * @returns [Domain.DIDPair](https://input-output-hk.github.io/atala-prism-wallet-sdk-ts/classes/Domain.DIDPair.html) - */ - async getPairByDID(did: SDK.Domain.DID): Promise { - const didPair = await this.db.didpairs - .findOne({ - selector: { - $or: [ - { - hostDID: did.toString() - }, - { - receiverDID: did.toString() - } - ] - } - }).exec() - return didPair - ? new SDK.Domain.DIDPair( - SDK.Domain.DID.fromString(didPair.hostDID), - SDK.Domain.DID.fromString(didPair.receiverDID), - didPair.name - ) - : null - } - - async getPairByName(name: string): Promise { - const didPair = await this.db.didpairs - .findOne({ - selector: { - $and: [ - { - name - } - ] - } - }).exec() - - return didPair - ? new SDK.Domain.DIDPair( - SDK.Domain.DID.fromString(didPair.hostDID), - SDK.Domain.DID.fromString(didPair.receiverDID), - didPair.name - ) - : null - } - private getPrivateKeyFromDB( - privateKey: PrivateKeyDocument - ): SDK.Domain.PrivateKey { - return privateKey.toDomainPrivateKey() - } - - async getDIDPrivateKeysByDID(did: SDK.Domain.DID): Promise { - const privateKeys = await this.db.privatekeys - .find({ - selector: { - did: { - $eq: did.toString() + if (collections) { + Object.keys(collections).forEach((collectionName) => { + const currentCollection = collections[collectionName]; + if (currentCollection) { + collectionMap.set(collectionName, currentCollection) } - } - }).exec() - return privateKeys.map((privateKey) => { - return this.getPrivateKeyFromDB(privateKey) - }) - } - - async getDIDPrivateKeyByID(id: string): Promise { - const privateKey = await this.db.privatekeys.findOne({ - selector: { - id: { - $eq: id - } - } - }).exec() - return privateKey ? this.getPrivateKeyFromDB(privateKey) : null - } - - async storeMediator( - mediator: SDK.Domain.DID, - host: SDK.Domain.DID, - routing: SDK.Domain.DID - ): Promise { - await this.db.mediators.insert({ - id: uuidv4(), - mediatorDID: mediator.toString(), - hostDID: host.toString(), - routingDID: routing.toString() - }) - } - - async getAllPrismDIDs(): Promise { - const dids = await this.db.dids.find({ - selector: { - method: { - $eq: 'prism' - } - } - }).exec() - - const prismDIDInfo: SDK.Domain.PrismDIDInfo[] = [] - - for (const did of dids) { - const didPrivateKeys = await this.getDIDPrivateKeysByDID( - SDK.Domain.DID.fromString(did.did) - ) - - for (const privateKey of didPrivateKeys) { - const indexProp = privateKey.getProperty(SDK.Domain.KeyProperties.index)! - - prismDIDInfo.push( - new SDK.Domain.PrismDIDInfo( - SDK.Domain.DID.fromString(did.did), - parseInt(indexProp), - did.alias - ) - ) - } - } - - return prismDIDInfo - } - - async getDIDInfoByDID(did: SDK.Domain.DID): Promise { - const didDB = await this.db.dids - .findOne({ - selector: { - did: did.toString() - } - }).exec() - - if (didDB) { - const privateKeys = await this.getDIDPrivateKeysByDID( - SDK.Domain.DID.fromString(didDB.did) - ) - /* istanbul ignore if */ - if (privateKeys.length === 0) { - throw new Error( - 'Imposible to recover PrismDIDInfo without its privateKey data.' - ) - } - const indexProp = privateKeys - .at(0)! - .getProperty(SDK.Domain.KeyProperties.index) - const index = indexProp ? parseInt(indexProp) : undefined - return new SDK.Domain.PrismDIDInfo( - SDK.Domain.DID.fromString(didDB.did), - index, - didDB.alias - ) - } - - return null - } - - async getDIDInfoByAlias(alias: string): Promise { - const dids = await this.db.dids.find({ - selector: { - alias: { - $eq: alias - } + }) } - }).exec() - const prismDIDInfo: SDK.Domain.PrismDIDInfo[] = [] - for (const did of dids) { - const didPrivateKeys = await this.getDIDPrivateKeysByDID( - SDK.Domain.DID.fromString(did.did) - ) - for (const privateKey of didPrivateKeys) { - const indexProp = privateKey.getProperty(SDK.Domain.KeyProperties.index)! - prismDIDInfo.push( - new SDK.Domain.PrismDIDInfo( - SDK.Domain.DID.fromString(did.did), - parseInt(indexProp), - did.alias - ) - ) - } - } - return prismDIDInfo - } - - async getAllMessagesByDID(did: SDK.Domain.DID): Promise { - const messages = await this.db.messages - .find({ - selector: { - $or: [ - { - to: did.toString() - }, - { - from: did.toString() - } - ] - } - }).exec() - - return messages.map((message) => message.toDomainMessage()) - } - - async getAllMessagesSent(): Promise { - const messages = await this.db.messages - .find({ - selector: { - $or: [ - { - direction: SDK.Domain.MessageDirection.SENT - } - ] - } - }).exec() - - return messages.map((message) => message.toDomainMessage()) - } - - async getAllMessagesReceived(): Promise { - const messages = await this.db.messages - .find({ - selector: { - $or: [ - { - direction: SDK.Domain.MessageDirection.RECEIVED - } - ] - } - }).exec() - return messages.map((message) => message.toDomainMessage()) - } - async getAllMessagesSentTo(did: SDK.Domain.DID): Promise { - const messages = await this.db.messages - .find({ - selector: { - $and: [ - { - to: did.toString() - }, - { - direction: SDK.Domain.MessageDirection.SENT - } - ] - } - }).exec() - return messages.map((message) => message.toDomainMessage()) - } + const instance = await this.createBaseEncrypted({ + ...options, + collections: Object.fromEntries(collectionMap) + }); - async getAllMessagesReceivedFrom(did: SDK.Domain.DID): Promise { - const messages = await this.db.messages - .find({ - selector: { - $and: [ - { - from: did.toString() - }, - { - direction: SDK.Domain.MessageDirection.RECEIVED + const currentCollections = instance.db.collections; + const collectionKeys = Object.keys(currentCollections) + const staticMethodModels = collectionKeys.reduce>((statics, collectionName) => { + const currentCollection: RxCollection = instance.getCollection(collectionName); + Object.keys(currentCollection.statics).forEach((staticName) => { + const func = currentCollection.statics[staticName]!; + if (statics.has(staticName)) { + throw new Error(`Static function in model ${collectionName}.${staticName} is duplicated, statics must be unique across al collections.`) + } + statics.set(staticName, func) + }) + return statics + }, new Map()); + + const proxy = new Proxy & SDK.Domain.Pluto & STATIC_RETURN>(instance as any, { + get(target, propAny) { + const prop = String(propAny) + const destination = target[prop] + if (typeof destination === 'function') { + // If the property is a function, return a function that calls it + return function (...args) { + return destination.apply(target, args); + }; + } else { + if (staticMethodModels.has(prop.toString())) { + return staticMethodModels.get(prop.toString()) } - ] - } - }).exec() - return messages.map((message) => message.toDomainMessage()) - } - - async getAllMessagesOfType( - type: string, - relatedWithDID?: SDK.Domain.DID | undefined - ): Promise { - const query: Array> = [ - { - piuri: type - } - ] - if (relatedWithDID) { - query.push({ - $or: [ - { - from: relatedWithDID.toString() - }, - { - to: relatedWithDID.toString() + return destination; } - ] + }, }) - } - const messages = await this.db.messages - .find({ - selector: { - $and: query - } - }).exec() - - return messages.map((message) => message.toDomainMessage()) - } - - async getAllMessagesByFromToDID( - from: SDK.Domain.DID, - to: SDK.Domain.DID - ): Promise { - const messages = await this.db.messages - .find({ - selector: { - $or: [ - { - from: from.toString() - }, - { - to: to.toString() - } - ] - } - }).exec() - - return messages.map((message) => message.toDomainMessage()) - } - - async getPrismDIDKeyPathIndex(did: SDK.Domain.DID): Promise { - const [key] = await this.getDIDPrivateKeysByDID(did) - if (!key) { - return null - } - return key.index || 0 - } - - async getPrismLastKeyPathIndex(): Promise { - const results = await this.getAllPrismDIDs() - if (!results || results.length === 0) { - return 0 - } - return Math.max(...results.map((result) => result.keyPathIndex)) - } - - async getAllPeerDIDs(): Promise { - const peerDIDs: SDK.PeerDID[] = [] - const dids = await this.db.dids.find({ - selector: { - method: { - $eq: 'peer' - } - } - }).exec() - for (const did of dids) { - const peerDID = SDK.Domain.DID.fromString(did.did) - const keys = await this.getDIDPrivateKeysByDID(peerDID) - peerDIDs.push( - new SDK.PeerDID( - peerDID, - keys.map((key) => ({ - keyCurve: { - curve: key.curve as any - }, - value: key.raw - })) - ) - ) - } - return peerDIDs - } - - async storeCredential(credential: SDK.Domain.Credential): Promise { - if (!credential.isStorable || !credential.isStorable()) { - throw new Error('Credential is not storable') - } - const storable = credential.toStorable() - /* istanbul ignore else -- @preserve */ - if (!storable.id) storable.id = uuidv4() - - await this.db.credentials.insert(storable) - } - - async getAllMediators(): Promise { - const mediators = await this.db.mediators.find().exec() - return mediators.map((mediator) => mediator.toDomainMediator()) - } - async getAllCredentials(): Promise { - const credentials = await this.db.credentials.find().exec() - return credentials.map( - (verifiableCredential) => verifiableCredential.toDomainCredential() - ) - } + return proxy; + } catch (err) { + /* istanbul ignore else */ + if ((err as RxError).code === 'DB1') { + throw new Error('Invalid Authentication') + } else { + /* istanbul ignore next */ - async getLinkSecret( - linkSecretName?: string | undefined - ): Promise { - const query = linkSecretName - ? { - selector: { - name: { - $eq: linkSecretName - } - } + throw err } - : {} - - const linkSecret = await this.db.linksecrets - .findOne(query).exec() - - if (linkSecret) { - return linkSecret.toDomainLinkSecret() - } - - return null - } - - async storeLinkSecret( - linkSecret: string, - linkSecretName: string - ): Promise { - await this.db.linksecrets.insert({ - name: linkSecretName, - secret: linkSecret - }) - } - - async storeCredentialMetadata( - metadata: SDK.Domain.Anoncreds.CredentialRequestMeta, - linkSecret: string - ): Promise { - await this.db.credentialrequestmetadatas.insert({ - ...metadata, - id: uuidv4(), - link_secret_name: linkSecret - }) - } - - async fetchCredentialMetadata( - linkSecretName: string - ): Promise { - const credentialRequestMetadata = await this.db.credentialrequestmetadatas - .findOne({ - selector: { - link_secret_name: { - $eq: linkSecretName - } - } - }).exec() - - if (credentialRequestMetadata) { - return credentialRequestMetadata.toDomainCredentialRequestMetadata() } - return null } -} +} \ No newline at end of file diff --git a/packages/database/src/schemas/Credential.ts b/packages/database/src/schemas/Credential.ts deleted file mode 100644 index 0e35b3fd..00000000 --- a/packages/database/src/schemas/Credential.ts +++ /dev/null @@ -1,109 +0,0 @@ -import SDK from '@atala/prism-wallet-sdk' -import type { Schema } from '../types' -import { type RxCollection, type RxDocument } from 'rxdb' - -export interface CredentialSubjectType { - type: string - name: string - value: string -} - -export interface CredentialSchemaType { - id: string - recoveryId: string - credentialData: string - issuer?: string - subject?: string - credentialCreated?: string - credentialUpdated?: string - credentialSchema?: string - validUntil?: string - revoked?: boolean - availableClaims?: string[] -} - -const CredentialSchema: Schema = { - version: 0, - primaryKey: 'id', - type: 'object', - properties: { - id: { - type: 'string', - maxLength: 60 - }, - recoveryId: { - type: 'string' - }, - credentialData: { - type: 'string' - }, - issuer: { - type: 'string' - }, - subject: { - type: 'string' - }, - credentialCreated: { - type: 'string' - }, - credentialUpdated: { - type: 'string' - }, - credentialSchema: { - type: 'string' - }, - validUntil: { - type: 'string' - }, - revoked: { - type: 'boolean' - }, - availableClaims: { - type: 'array', - items: { - type: 'string' - } - } - }, - encrypted: ['credentialData'], - required: ['id', 'recoveryId', 'credentialData'] -} - -export type CredentialDocument = RxDocument -export interface CredentialMethodTypes { - toDomainCredential: (this: CredentialSchemaType) => SDK.Domain.Credential -} - -export const CredentialMethods: CredentialMethodTypes = { - toDomainCredential: function toDomainCredential(this: CredentialSchemaType) { - if (this.recoveryId === SDK.JWTVerifiableCredentialRecoveryId) { - const jwtString = Buffer.from(this.credentialData).toString() - const jwtObj = JSON.parse(jwtString) - return SDK.JWTCredential.fromJWT(jwtObj, jwtString) - } else if (this.recoveryId === SDK.AnonCredsRecoveryId) { - const credentialData = Buffer.from(this.credentialData).toString() - const credentialJson = JSON.parse(credentialData) - return new SDK.AnonCredsCredential({ - schema_id: credentialJson[SDK.AnonCredsCredentialProperties.schemaId], - cred_def_id: - credentialJson[SDK.AnonCredsCredentialProperties.credentialDefinitionId], - values: credentialJson[SDK.AnonCredsCredentialProperties.values], - signature: credentialJson[SDK.AnonCredsCredentialProperties.signature], - signature_correctness_proof: - credentialJson[ - SDK.AnonCredsCredentialProperties.signatureCorrectnessProof - ] - }) - } else { - throw new Error('Unsupported key type from db storage') - } - } -} - -export type CredentialCollection = RxCollection< - CredentialSchemaType, - CredentialMethodTypes, - CredentialDocument -> - -export default CredentialSchema diff --git a/packages/database/src/schemas/CredentialRequestMetadata.ts b/packages/database/src/schemas/CredentialRequestMetadata.ts deleted file mode 100644 index 085a40cd..00000000 --- a/packages/database/src/schemas/CredentialRequestMetadata.ts +++ /dev/null @@ -1,68 +0,0 @@ -import SDK from '@atala/prism-wallet-sdk' -import type { Schema } from '../types' -import { type RxCollection, type RxDocument } from 'rxdb' - -export interface CredentialRequestMetadataSchemaType { - id: string - link_secret_blinding_data: { - v_prime: string - } - link_secret_name: string - nonce: string -} - -const CredentialRequestMetadataSchema: Schema = -{ - version: 0, - primaryKey: 'id', - type: 'object', - properties: { - id: { - type: 'string', - maxLength: 60 - }, - link_secret_blinding_data: { - type: 'object', - properties: { - v_prime: { - type: 'string' - } - } - }, - link_secret_name: { - type: 'string' - }, - nonce: { - type: 'string' - } - }, - encrypted: ['link_secret_blinding_data', 'nonce'], - required: ['id', 'link_secret_blinding_data', 'link_secret_name', 'nonce'] -} - -export type CredentialRequestMetadataDocument = - RxDocument - -export interface CredentialRequestMetadataMethodTypes { - toDomainCredentialRequestMetadata: ( - this: CredentialRequestMetadataSchemaType - ) => SDK.Domain.Anoncreds.CredentialRequestMeta -} - -export const CredentialRequestMetadataMethods: CredentialRequestMetadataMethodTypes = -{ - toDomainCredentialRequestMetadata: - function toDomainCredentialRequestMetadata( - this: CredentialRequestMetadataSchemaType - ) { - return this - } -} - -export type CredentialRequestMetadataCollection = RxCollection< - CredentialRequestMetadataSchemaType, - CredentialRequestMetadataMethodTypes, - CredentialRequestMetadataDocument -> - -export default CredentialRequestMetadataSchema diff --git a/packages/database/src/schemas/DID.ts b/packages/database/src/schemas/DID.ts deleted file mode 100644 index e5cc00ec..00000000 --- a/packages/database/src/schemas/DID.ts +++ /dev/null @@ -1,45 +0,0 @@ -import { type RxCollection, type RxDocument } from 'rxdb' -import type { Schema } from '../types' - -export interface DIDSchemaType { - schema: string - method: string - methodId: string - alias?: string - did: string -} - -const DIDSchema: Schema = { - version: 0, - primaryKey: 'did', - type: 'object', - properties: { - method: { - type: 'string', - maxLength: 60 - }, - methodId: { - type: 'string', - maxLength: 60 - }, - schema: { - type: 'string', - maxLength: 60 - }, - alias: { - type: 'string', - maxLength: 60 - }, - did: { - type: 'string', - maxLength: 60 - } - }, - encrypted: [], - required: ['method', 'methodId', 'did', 'schema'] -} -export type DIDDocument = RxDocument - -export type DIDCollection = RxCollection - -export default DIDSchema diff --git a/packages/database/src/schemas/DIDPair.ts b/packages/database/src/schemas/DIDPair.ts deleted file mode 100644 index 97f7d102..00000000 --- a/packages/database/src/schemas/DIDPair.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { type RxCollection, type RxDocument } from 'rxdb' -import type { Schema } from '../types' - -export interface DIDPairSchemaType { - hostDID: string - receiverDID: string - name: string -} - -const DIDPairSchema: Schema = { - version: 0, - primaryKey: 'name', - type: 'object', - properties: { - hostDID: { - type: 'string' - }, - name: { - type: 'string', - maxLength: 60 - }, - receiverDID: { - type: 'string' - } - }, - encrypted: [], - required: ['name', 'hostDID', 'receiverDID'] -} - -export type DIDPairDocument = RxDocument -export type DIDPairCollection = RxCollection - -export default DIDPairSchema diff --git a/packages/database/src/schemas/LinkSecret.ts b/packages/database/src/schemas/LinkSecret.ts deleted file mode 100644 index bf179c27..00000000 --- a/packages/database/src/schemas/LinkSecret.ts +++ /dev/null @@ -1,47 +0,0 @@ -import SDK from '@atala/prism-wallet-sdk' -import type { Schema } from '../types' -import { type RxCollection, type RxDocument } from 'rxdb' - -export interface LinkSecretSchemaType { - readonly name: string - readonly secret: string -} - -const LinkSecretSchema: Schema = { - version: 0, - primaryKey: 'name', - type: 'object', - properties: { - name: { - type: 'string', - maxLength: 60 - }, - secret: { - type: 'string' - } - }, - encrypted: ['secret'], - required: ['name', 'secret'] -} - -export type LinkSecretDocument = RxDocument< - LinkSecretSchemaType, - LinkSecretMethodTypes -> - -export interface LinkSecretMethodTypes { - toDomainLinkSecret: (this: LinkSecretDocument) => SDK.Domain.Anoncreds.LinkSecret -} - -export type LinkSecretColletion = RxCollection< - LinkSecretSchemaType, - LinkSecretMethodTypes, - LinkSecretDocument -> - -export const LinkSecretMethods: LinkSecretMethodTypes = { - toDomainLinkSecret: function toDomainLinkSecret(this: LinkSecretDocument) { - return this.secret - } -} -export default LinkSecretSchema diff --git a/packages/database/src/schemas/Mediator.ts b/packages/database/src/schemas/Mediator.ts deleted file mode 100644 index f51a5ffa..00000000 --- a/packages/database/src/schemas/Mediator.ts +++ /dev/null @@ -1,56 +0,0 @@ -import { type RxCollection, type RxDocument } from 'rxdb' -import type { Schema } from '../types' -import SDK from '@atala/prism-wallet-sdk' - -export interface MediatorSchemaType { - id: string - mediatorDID: string - hostDID: string - routingDID: string -} - -const MediatorSchema: Schema = { - version: 0, - primaryKey: 'id', - type: 'object', - properties: { - id: { - type: 'string', - maxLength: 60 - }, - mediatorDID: { - type: 'string' - }, - hostDID: { - type: 'string' - }, - routingDID: { - type: 'string' - } - }, - encrypted: [], - required: ['id', 'mediatorDID'] -} - -export type MediatorDocument = RxDocument -export interface MediatorMethodTypes { - toDomainMediator: (this: RxDocument) => SDK.Domain.Mediator -} -export type MediatorCollection = RxCollection< - MediatorSchemaType, - MediatorMethodTypes, - MediatorDocument -> - -export const MediatorMethods: MediatorMethodTypes = { - toDomainMediator: function toDomainMediator(this: RxDocument) { - const mediator = this.toJSON() - return { - hostDID: SDK.Domain.DID.fromString(mediator.hostDID), - routingDID: SDK.Domain.DID.fromString(mediator.routingDID), - mediatorDID: SDK.Domain.DID.fromString(mediator.mediatorDID) - } - } -} - -export default MediatorSchema diff --git a/packages/database/src/schemas/Message.ts b/packages/database/src/schemas/Message.ts deleted file mode 100644 index 4713d43c..00000000 --- a/packages/database/src/schemas/Message.ts +++ /dev/null @@ -1,125 +0,0 @@ -import SDK from '@atala/prism-wallet-sdk' -import type { Schema } from '../types' -import { type RxCollection, type RxDocument } from 'rxdb' - -export interface MessageSchemaType { - readonly body: string - readonly id: string - readonly piuri: string - readonly from?: string | undefined - readonly to?: string | undefined - readonly attachments: SDK.Domain.AttachmentDescriptor[] - readonly thid?: string - readonly extraHeaders: string[] - readonly createdTime: string - readonly expiresTimePlus: string - readonly ack: string[] - readonly direction: SDK.Domain.MessageDirection - readonly fromPrior?: string | undefined - readonly pthid?: string | undefined -} - -const MessageSchema: Schema = { - version: 0, - primaryKey: 'id', - type: 'object', - properties: { - id: { - type: 'string', - maxLength: 60 - }, - body: { - type: 'string' - }, - piuri: { - type: 'string' - }, - attachments: { - type: 'array', - items: { - type: 'object', - properties: { - id: { - type: 'id', - maxLength: 60 - }, - description: { - type: 'string' - }, - byteCount: { - type: 'number' - }, - lastModTime: { - type: 'string' - }, - format: { - type: 'string' - }, - filename: { - type: 'array', - items: { - type: 'string' - } - }, - mediaType: { - type: 'string' - }, - data: { - type: 'object' - } - } - } - }, - extraHeaders: { - type: 'array' - }, - createdTime: { - type: 'string' - }, - expiresTimePlus: { - type: 'string' - }, - ack: { - type: 'array' - }, - direction: { - type: 'number' - }, - from: { - type: 'string' - }, - to: { - type: 'string' - }, - thid: { - type: 'string' - }, - fromPrior: { - type: 'string' - }, - pthid: { - type: 'string' - } - }, - encrypted: ['thid', 'attachments', 'body'], - required: ['id'] -} -export type MessageDocument = RxDocument - -export interface MessageMethodTypes { - toDomainMessage: (this: MessageDocument) => SDK.Domain.Message -} - -export type MessageColletion = RxCollection< - MessageSchemaType, - MessageMethodTypes, - MessageDocument -> - -export const MessageMethods: MessageMethodTypes = { - toDomainMessage: function toDomainMessage(this: MessageDocument) { - return SDK.Domain.Message.fromJson(JSON.stringify(this)) - } -} - -export default MessageSchema diff --git a/packages/database/src/schemas/PrivateKey.ts b/packages/database/src/schemas/PrivateKey.ts deleted file mode 100644 index d55fde25..00000000 --- a/packages/database/src/schemas/PrivateKey.ts +++ /dev/null @@ -1,161 +0,0 @@ -import SDK from '@atala/prism-wallet-sdk' -import type { Schema } from '../types' -import { type RxCollection, type RxDocument } from 'rxdb' - - -export interface KeySpec { - name: string - type: string - value: string -} - -export interface KeySchemaType { - id: string - type: string - did: string - keySpecification: KeySpec[] -} - -const PrivateKeySchema: Schema = { - version: 0, - primaryKey: 'id', - type: 'object', - properties: { - id: { - type: 'string', - maxLength: 60 - }, - did: { - type: 'string' - }, - type: { - type: 'string' - }, - keySpecification: { - type: 'array', - items: { - type: 'object', - properties: { - name: { - type: 'string' - }, - type: { - type: 'string' - }, - value: { - type: 'string' - } - } - } - } - }, - encrypted: ['keySpecification', 'type'], - required: ['keySpecification', 'did', 'type', 'id'] -} - -export interface PrivateKeyMethodTypes { - toDomainPrivateKey: (this: PrivateKeyDocument) => SDK.Domain.PrivateKey -} -export type PrivateKeyColletion = RxCollection< - KeySchemaType, - PrivateKeyMethodTypes, - PrivateKeyDocument -> -export type PrivateKeyDocument = RxDocument< - KeySchemaType, - PrivateKeyMethodTypes -> - -export const PrivateKeyMethods: PrivateKeyMethodTypes = { - toDomainPrivateKey: function toDomainPrivateKey(this: PrivateKeyDocument) { - const { type, keySpecification } = this - const curve = keySpecification.find( - (item) => item.name === SDK.KeyProperties.curve - ) - const raw = keySpecification.find( - (item) => item.name === SDK.KeyProperties.rawKey - ) - if (!(type in SDK.Domain.KeyTypes)) { - throw new Error(`Invalid KeyType ${type || 'undefined'}`) - } - if (!curve) { - throw new Error('Undefined key curve') - } - - if ( - curve.value !== SDK.Domain.Curve.SECP256K1 && - curve.value !== SDK.Domain.Curve.ED25519 && - curve.value !== SDK.Domain.Curve.X25519 - ) { - throw new Error(`Invalid key curve ${curve.value}`) - } - - if (!raw) { - throw new Error('Undefined key raw') - } - - /* istanbul ignore else -- @preserve */ - if (curve.value === SDK.Domain.Curve.SECP256K1) { - const index = keySpecification.find( - (item) => item.name === SDK.KeyProperties.index - ) - const seed = keySpecification.find( - (item) => item.name === SDK.KeyProperties.seed - ) - - const privateKey = new SDK.Secp256k1PrivateKey( - Buffer.from(raw.value, 'hex') - ) - - privateKey.keySpecification.set(SDK.Domain.KeyProperties.rawKey, raw.value) - - privateKey.keySpecification.set( - SDK.Domain.KeyProperties.curve, - SDK.Domain.Curve.SECP256K1 - ) - - if (index) { - privateKey.keySpecification.set( - SDK.Domain.KeyProperties.index, - index.value - ) - } - - if (seed) { - privateKey.keySpecification.set( - SDK.Domain.KeyProperties.seed, - seed.value - ) - } - - return privateKey - } else if (curve.value === SDK.Domain.Curve.ED25519) { - const privateKey = new SDK.Ed25519PrivateKey(Buffer.from(raw.value, 'hex')) - - privateKey.keySpecification.set(SDK.Domain.KeyProperties.rawKey, raw.value) - - privateKey.keySpecification.set( - SDK.Domain.KeyProperties.curve, - SDK.Domain.Curve.ED25519 - ) - - return privateKey - } else if (curve.value === SDK.Domain.Curve.X25519) { - const privateKey = new SDK.X25519PrivateKey(Buffer.from(raw.value, 'hex')) - - privateKey.keySpecification.set(SDK.Domain.KeyProperties.rawKey, raw.value) - - privateKey.keySpecification.set( - SDK.Domain.KeyProperties.curve, - SDK.Domain.Curve.X25519 - ) - - return privateKey - } else { - /* istanbul ignore next -- @preserve */ - throw new Error(`Invalid key ${curve.value} ${type}`) - } - } -} - -export default PrivateKeySchema diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts index 7a15101d..aa0d2fab 100644 --- a/packages/database/src/types.ts +++ b/packages/database/src/types.ts @@ -1,21 +1,11 @@ -import { type RxJsonSchema } from 'rxdb' +import { PlutoCollections } from '@pluto-encrypted/schemas' import { type MangoQuery, type MangoQueryNoLimit, type RxCollection, type RxDocument, type RxDumpDatabase, type RxStorage } from 'rxdb/dist/types/types' -import { type CredentialCollection } from './schemas/Credential' -import { type CredentialRequestMetadataCollection } from './schemas/CredentialRequestMetadata' -import { type DIDCollection } from './schemas/DID' -import { type DIDPairCollection } from './schemas/DIDPair' -import { type LinkSecretColletion } from './schemas/LinkSecret' -import { type MediatorCollection } from './schemas/Mediator' -import { type MessageColletion } from './schemas/Message' -import { type PrivateKeyColletion } from './schemas/PrivateKey' export type NoKeys = { [P in Exclude]: T[P]; } -export type Schema = RxJsonSchema & { - encrypted: Array -} + export interface GenericORMType extends RxCollection { count: (this: RxCollection, query: MangoQuery | undefined) => Promise @@ -25,16 +15,6 @@ export interface GenericORMType extends RxCollection { remove: (queryObj?: MangoQueryNoLimit | string) => Array> } -export interface PlutoCollections { - messages: MessageColletion - dids: DIDCollection - didpairs: DIDPairCollection - mediators: MediatorCollection - privatekeys: PrivateKeyColletion - credentials: CredentialCollection - credentialrequestmetadatas: CredentialRequestMetadataCollection - linksecrets: LinkSecretColletion -} export interface createEncryptedOptions { name: string @@ -42,3 +22,5 @@ export interface createEncryptedOptions { importData?: RxDumpDatabase storage: RxStorage } + + diff --git a/packages/database/tests/pluto.test.ts b/packages/database/tests/pluto.test.ts index b07e1940..f83b8aec 100644 --- a/packages/database/tests/pluto.test.ts +++ b/packages/database/tests/pluto.test.ts @@ -6,13 +6,14 @@ import path from 'path'; import { randomUUID } from "crypto"; import SDK from "@atala/prism-wallet-sdk"; import * as sinon from "sinon"; -import { RxStorage } from "rxdb"; +import { RxCollection, RxStorage } from "rxdb"; import InMemory from "../../inmemory/src"; import IndexDb from "../../indexdb/src"; import { createLevelDBStorage } from '../../leveldb/src' import * as Fixtures from "./fixtures"; -import { Database, PrivateKeyMethods } from "../src"; +import { Database } from "../src"; +import { PrivateKeyMethods, LinkSecretSchemaType, LinkSecretStaticMethodTypes, LinkSecretMethodTypes, LinkSecretMethods, LinkSecretSchema, LinkSecretStaticMethods, getDefaultCollections } from "@pluto-encrypted/schemas"; const { AnonCredsCredential, @@ -76,7 +77,7 @@ function getStorageDBName(storage: RxStorage) { } describe("Pluto encrypted testing with different storages", () => { - let db: Database; + let db: Awaited>; let currentDBName: string; afterEach(async () => { @@ -100,7 +101,7 @@ describe("Pluto encrypted testing with different storages", () => { { name: forceDatabaseName, encryptionKey: password, - storage: storage, + storage: storage } ); await db.getAllPrismDIDs() @@ -108,7 +109,7 @@ describe("Pluto encrypted testing with different storages", () => { "did:prism:733e594871d7700d35e6116011a08fc11e88ff9d366d8b5571ffc1aa18d249ea:Ct8BCtwBEnQKH2F1dGhlbnRpY2F0aW9uYXV0aGVudGljYXRpb25LZXkQBEJPCglzZWNwMjU2azESIDS5zeYUkLCSAJLI6aLXRTPRxstCLPUEI6TgBrAVCHkwGiDk-ffklrHIFW7pKkT8i-YksXi-XXi5h31czUMaVClcpxJkCg9tYXN0ZXJtYXN0ZXJLZXkQAUJPCglzZWNwMjU2azESIDS5zeYUkLCSAJLI6aLXRTPRxstCLPUEI6TgBrAVCHkwGiDk-ffklrHIFW7pKkT8i-YksXi-XXi5h31czUMaVClcpw" ); const privateKey = Fixtures.secp256K1.privateKey; - await db.storePrismDID(did, 0, privateKey); + await db.storePrismDID(did, 0, privateKey, null); } await createDatabase(defaultPassword); @@ -130,7 +131,7 @@ describe("Pluto encrypted testing with different storages", () => { { name: currentDBName, encryptionKey: defaultPassword, - storage: storage, + storage: storage } ); }); @@ -184,12 +185,12 @@ describe("Pluto encrypted testing with different storages", () => { "did:prism:733e594871d7700d35e6116011a08fc11e88ff9d366d8b5571ffc1aa18d249ea:Ct8BCtwBEnQKH2F1dGhlbnRpY2F0aW9uYXV0aGVudGljYXRpb25LZXkQBEJPCglzZWNwMjU2azESIDS5zeYUkLCSAJLI6aLXRTPRxstCLPUEI6TgBrAVCHkwGiDk-ffklrHIFW7pKkT8i-YksXi-XXi5h31czUMaVClcpxJkCg9tYXN0ZXJtYXN0ZXJLZXkQAUJPCglzZWNwMjU2azESIDS5zeYUkLCSAJLI6aLXRTPRxstCLPUEI6TgBrAVCHkwGiDk-ffklrHIFW7pKkT8i-YksXi-XXi5h31czUMaVClcpw2" ); const privateKey = Fixtures.secp256K1.privateKey; - await db.storePrismDID(did, 0, privateKey); + await db.storePrismDID(did, 0, privateKey, null); expect((await db.getAllPrismDIDs()).length).toBe(1); expect(await db.getDIDInfoByDID(did)).not.toBe(null); expect(await db.getPrismDIDKeyPathIndex(did)).toBe(0); expect(await db.getPrismLastKeyPathIndex()).toBe(0); - await db.storePrismDID(did2, 1, privateKey); + await db.storePrismDID(did2, 1, privateKey, null); expect(await db.getPrismDIDKeyPathIndex(did2)).toBe(1); expect(await db.getPrismLastKeyPathIndex()).toBe(1); expect(await db.getPrismDIDKeyPathIndex(did3)).toBe(null); @@ -561,7 +562,7 @@ describe("Pluto encrypted testing with different storages", () => { name: currentDBName, encryptionKey: defaultPassword, importData: backup, - storage: storage, + storage: storage } ); @@ -705,36 +706,36 @@ describe("Pluto encrypted testing with different storages", () => { }); it(storageName + "Should be able to request models from database", async ({ expect }) => { - const collectionNames = Object.keys(db.collections); + const collectionNames = Object.keys(db.db.collections); for (let collectionName of collectionNames) { - const collection = db[collectionName]; + const collection = db.db.collections[collectionName]; expect(collection).not.undefined } }) it(storageName + "Should be able to request count orm method on all models", async ({ expect }) => { - const collectionNames = Object.keys(db.collections); + const collectionNames = Object.keys(db.db.collections); for (let collectionName of collectionNames) { - const collection = db[collectionName]; + const collection = db.db.collections[collectionName]; const count = await collection.count().exec(); expect(count).toBe(0) } }) it(storageName + "Should be able to request findByIds orm method on all models", async ({ expect }) => { - const collectionNames = Object.keys(db.collections); + const collectionNames = Object.keys(db.db.collections); for (let collectionName of collectionNames) { - const collection = db[collectionName]; + const collection = db.db.collections[collectionName]; const count = await collection.findByIds([]).exec(); expect(count.size).toBe(0) } }) it(storageName + "Should be able to request find orm method on all models", async ({ expect }) => { - const collectionNames = Object.keys(db.collections); + const collectionNames = Object.keys(db.db.collections); for (let collectionName of collectionNames) { - const collection = db[collectionName]; + const collection = db.db.collections[collectionName]; const results = await collection.find().exec(); expect(results.length).toBe(0) } @@ -753,7 +754,7 @@ describe("Pluto encrypted testing with different storages", () => { result.recoveryId = "demo"; await db.storeCredential(result); - const storedCredential = await db.credentials.findOne({ + const storedCredential = await db.db.collections.credentials.findOne({ selector: { recoveryId: { $eq: result.recoveryId @@ -778,7 +779,13 @@ describe("Pluto encrypted testing with different storages", () => { await db.storeLinkSecret("demo123", "demo321"); - const migrationDB = await Database.createEncrypted( + const migrationDB = await Database.createEncrypted<{ + linksecrets: RxCollection< + LinkSecretSchemaType, + LinkSecretMethodTypes, + LinkSecretStaticMethodTypes + > + }>( { name: forceDatabaseName, encryptionKey: defaultPassword, @@ -813,7 +820,8 @@ describe("Pluto encrypted testing with different storages", () => { delete oldDoc.secret return oldDoc; } - } + }, + statics: LinkSecretStaticMethods } } } @@ -837,7 +845,13 @@ describe("Pluto encrypted testing with different storages", () => { await db.storeLinkSecret("demo123", "demo321"); - const migrationDB = await Database.createEncrypted( + const migrationDB = await Database.createEncrypted<{ + linksecrets: RxCollection< + LinkSecretSchemaType, + LinkSecretMethodTypes, + LinkSecretStaticMethodTypes + > + }>( { name: forceDatabaseName, encryptionKey: defaultPassword, @@ -849,6 +863,7 @@ describe("Pluto encrypted testing with different storages", () => { return this.secreto; }, }, + statics: LinkSecretStaticMethods, schema: { version: 1, primaryKey: "name2", @@ -893,23 +908,32 @@ describe("Pluto encrypted testing with different storages", () => { name: forceDatabaseName, encryptionKey: defaultPassword, storage, + collections: getDefaultCollections() } ); await db.storeLinkSecret("demo123", "demo321"); - const migrationDB = await Database.createEncrypted( + const migrationDB = await Database.createEncrypted<{ + linksecrets: RxCollection< + LinkSecretSchemaType, + LinkSecretMethodTypes, + LinkSecretStaticMethodTypes + > + }>( { name: forceDatabaseName, encryptionKey: defaultPassword, storage, collections: { + ...(getDefaultCollections()), linksecrets: { methods: { toDomainLinkSecret: function toDomainLinkSecret(this: any) { return this.secreto; }, }, + statics: LinkSecretStaticMethods, schema: { version: 2, primaryKey: "test", @@ -951,6 +975,155 @@ describe("Pluto encrypted testing with different storages", () => { }); + it(storageName + "Should allow anyone to add new models to the database", async ({ expect }) => { + const forceDatabaseName = `${databaseName}${randomUUID()}` + + const db = await Database.createEncrypted<{ + demo: RxCollection< + LinkSecretSchemaType, + LinkSecretMethodTypes, + { hola: (demo: boolean, demo2: boolean) => void } + > + }>( + { + name: forceDatabaseName, + encryptionKey: defaultPassword, + storage, + collections: { + demo: { + methods: LinkSecretMethods, + schema: LinkSecretSchema, + statics: { + hola: function (demo: boolean, demo2: boolean): void { + throw new Error('Function not implemented.') + } + } + } + } + } + ); + + expect(db.db.collections.credentials).to.not.toBeUndefined(); + expect(db.db.collections.demo).to.not.toBeUndefined(); + expect(db.db.collections.demo.hola).to.not.toBeUndefined(); + + }) + + it(storageName + "Should allow anyone to add new models to the database without using the same models", async ({ expect }) => { + const forceDatabaseName = `${databaseName}${randomUUID()}` + + const db = await Database.createBaseEncrypted<{ + demo: RxCollection< + LinkSecretSchemaType, + LinkSecretMethodTypes, + { hola: (demo: boolean, demo2: boolean) => void } + > + }>( + { + name: forceDatabaseName, + encryptionKey: defaultPassword, + storage, + collections: { + demo: { + methods: LinkSecretMethods, + schema: LinkSecretSchema, + statics: { + hola: function (demo: boolean, demo2: boolean): void { + throw new Error('Function not implemented.') + } + } + } + } + } + ); + + expect((db.db.collections as any).privateKeys).toBeUndefined(); + expect(db.db.collections.demo).to.not.toBeUndefined(); + expect(db.db.collections.demo.hola).to.not.toBeUndefined(); + + + }) + + it(storageName + "Should allow anyone to add new models to the database without using the same models", async ({ expect }) => { + const forceDatabaseName = `${databaseName}${randomUUID()}` + + + await expect(() => Database.createEncrypted<{ + demo: RxCollection< + LinkSecretSchemaType, + LinkSecretMethodTypes, + { hola: (demo: boolean, demo2: boolean) => void } + >, + demo2: RxCollection< + LinkSecretSchemaType, + LinkSecretMethodTypes, + { hola: (demo: boolean, demo2: boolean) => void } + > + }>( + { + name: forceDatabaseName, + encryptionKey: defaultPassword, + storage, + withDefaultCollections: false, + collections: { + demo: { + methods: LinkSecretMethods, + schema: LinkSecretSchema, + statics: { + hola: function (demo: boolean, demo2: boolean): void { + throw new Error('Function not implemented.') + } + } + }, + demo2: { + methods: LinkSecretMethods, + schema: LinkSecretSchema, + statics: { + hola: function (demo: boolean, demo2: boolean): void { + throw new Error('Function not implemented.') + } + } + } + } + } + )).rejects.toThrowError(new Error("Static function in model demo2.hola is duplicated, statics must be unique across al collections.")); + + + }) + + it(storageName + "Should allow anyone to add new models to the database without using the same models and the defaultModels won't be available", async ({ expect }) => { + const forceDatabaseName = `${databaseName}${randomUUID()}` + + const db = await Database.createBaseEncrypted<{ + demo: RxCollection< + LinkSecretSchemaType, + LinkSecretMethodTypes, + { hola: (demo: boolean, demo2: boolean) => void } + > + }>( + { + name: forceDatabaseName, + encryptionKey: defaultPassword, + storage, + collections: { + demo: { + methods: LinkSecretMethods, + schema: LinkSecretSchema, + statics: { + hola: function (demo: boolean, demo2: boolean): void { + throw new Error('Function not implemented.') + } + } + } + } + } + ); + + expect((db.db.collections as any).credentials).toBeUndefined() + expect(db.db.collections.demo).to.not.toBeUndefined(); + expect(db.db.collections.demo.hola).to.not.toBeUndefined(); + }) + }); }) }) \ No newline at end of file diff --git a/packages/encryption/package.json b/packages/encryption/package.json index 502d60f9..764d5703 100644 --- a/packages/encryption/package.json +++ b/packages/encryption/package.json @@ -1,6 +1,6 @@ { "name": "@pluto-encrypted/encryption", - "version": "1.9.3", + "version": "1.10.0-rc.1", "description": "Encryption layer for @pluto-encrypted/database storages.", "main": "./build/cjs/index.cjs", "module": "./build/esm/index.mjs", diff --git a/packages/encryption/src/index.ts b/packages/encryption/src/index.ts index f9ce8e23..8afec838 100644 --- a/packages/encryption/src/index.ts +++ b/packages/encryption/src/index.ts @@ -1,4 +1,5 @@ /** + * * @packageDocumentation * @module encryption * @description This package is an rxdb encryption layer, a replacement for the vulnerable crypto-js dependency provided by the free version of rxDB. diff --git a/packages/indexdb/coverage/coverage-summary.json b/packages/indexdb/coverage/coverage-summary.json index f7d07dd7..1c16db4b 100644 --- a/packages/indexdb/coverage/coverage-summary.json +++ b/packages/indexdb/coverage/coverage-summary.json @@ -1,7 +1,7 @@ {"total": {"lines":{"total":236,"covered":221,"skipped":0,"pct":93.64},"statements":{"total":246,"covered":228,"skipped":0,"pct":92.68},"functions":{"total":56,"covered":53,"skipped":0,"pct":94.64},"branches":{"total":105,"covered":84,"skipped":0,"pct":80},"branchesTrue":{"total":0,"covered":0,"skipped":0,"pct":100}} -,"/home/runner/work/pluto-encrypted/pluto-encrypted/packages/indexdb/src/index.ts": {"lines":{"total":1,"covered":1,"skipped":0,"pct":100},"functions":{"total":0,"covered":0,"skipped":0,"pct":100},"statements":{"total":1,"covered":1,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}} -,"/home/runner/work/pluto-encrypted/pluto-encrypted/packages/indexdb/src/storage-dexie/dexie-helper.ts": {"lines":{"total":95,"covered":86,"skipped":0,"pct":90.52},"functions":{"total":22,"covered":21,"skipped":0,"pct":95.45},"statements":{"total":100,"covered":90,"skipped":0,"pct":90},"branches":{"total":48,"covered":39,"skipped":0,"pct":81.25}} -,"/home/runner/work/pluto-encrypted/pluto-encrypted/packages/indexdb/src/storage-dexie/dexie-query.ts": {"lines":{"total":32,"covered":30,"skipped":0,"pct":93.75},"functions":{"total":6,"covered":5,"skipped":0,"pct":83.33},"statements":{"total":35,"covered":32,"skipped":0,"pct":91.42},"branches":{"total":14,"covered":10,"skipped":0,"pct":71.42}} -,"/home/runner/work/pluto-encrypted/pluto-encrypted/packages/indexdb/src/storage-dexie/rx-storage-dexie.ts": {"lines":{"total":10,"covered":10,"skipped":0,"pct":100},"functions":{"total":3,"covered":3,"skipped":0,"pct":100},"statements":{"total":10,"covered":10,"skipped":0,"pct":100},"branches":{"total":3,"covered":3,"skipped":0,"pct":100}} -,"/home/runner/work/pluto-encrypted/pluto-encrypted/packages/indexdb/src/storage-dexie/rx-storage-instance-dexie.ts": {"lines":{"total":98,"covered":94,"skipped":0,"pct":95.91},"functions":{"total":25,"covered":24,"skipped":0,"pct":96},"statements":{"total":100,"covered":95,"skipped":0,"pct":95},"branches":{"total":40,"covered":32,"skipped":0,"pct":80}} +,"/Users/ribo/Projects/personal/pluto-encrypted/packages/indexdb/src/index.ts": {"lines":{"total":1,"covered":1,"skipped":0,"pct":100},"functions":{"total":0,"covered":0,"skipped":0,"pct":100},"statements":{"total":1,"covered":1,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}} +,"/Users/ribo/Projects/personal/pluto-encrypted/packages/indexdb/src/storage-dexie/dexie-helper.ts": {"lines":{"total":95,"covered":86,"skipped":0,"pct":90.52},"functions":{"total":22,"covered":21,"skipped":0,"pct":95.45},"statements":{"total":100,"covered":90,"skipped":0,"pct":90},"branches":{"total":48,"covered":39,"skipped":0,"pct":81.25}} +,"/Users/ribo/Projects/personal/pluto-encrypted/packages/indexdb/src/storage-dexie/dexie-query.ts": {"lines":{"total":32,"covered":30,"skipped":0,"pct":93.75},"functions":{"total":6,"covered":5,"skipped":0,"pct":83.33},"statements":{"total":35,"covered":32,"skipped":0,"pct":91.42},"branches":{"total":14,"covered":10,"skipped":0,"pct":71.42}} +,"/Users/ribo/Projects/personal/pluto-encrypted/packages/indexdb/src/storage-dexie/rx-storage-dexie.ts": {"lines":{"total":10,"covered":10,"skipped":0,"pct":100},"functions":{"total":3,"covered":3,"skipped":0,"pct":100},"statements":{"total":10,"covered":10,"skipped":0,"pct":100},"branches":{"total":3,"covered":3,"skipped":0,"pct":100}} +,"/Users/ribo/Projects/personal/pluto-encrypted/packages/indexdb/src/storage-dexie/rx-storage-instance-dexie.ts": {"lines":{"total":98,"covered":94,"skipped":0,"pct":95.91},"functions":{"total":25,"covered":24,"skipped":0,"pct":96},"statements":{"total":100,"covered":95,"skipped":0,"pct":95},"branches":{"total":40,"covered":32,"skipped":0,"pct":80}} } diff --git a/packages/indexdb/package.json b/packages/indexdb/package.json index 0aba4332..19799e57 100644 --- a/packages/indexdb/package.json +++ b/packages/indexdb/package.json @@ -1,6 +1,6 @@ { "name": "@pluto-encrypted/indexdb", - "version": "1.9.4", + "version": "2.0.0-rc.3", "description": "Secure Encrypted IndexDB storage for @pluto-encrypted/database", "main": "./build/cjs/index.cjs", "module": "./build/esm/index.mjs", @@ -33,14 +33,14 @@ "dependencies": { "rxdb": "^14.17.0", "uuid": "^9.0.1", - "@pluto-encrypted/encryption": "1.9.3", - "@pluto-encrypted/shared": "1.9.3", + "@pluto-encrypted/encryption": "1.10.0-rc.1", + "@pluto-encrypted/shared": "2.0.0-rc.3", "array-push-at-sort-position": "^4.0.1" }, "devDependencies": { - "@pluto-encrypted/encryption": "1.9.3", - "@pluto-encrypted/shared": "1.9.3", - "@pluto-encrypted/test-suite": "1.9.4" + "@pluto-encrypted/encryption": "1.10.0-rc.1", + "@pluto-encrypted/shared": "2.0.0-rc.3", + "@pluto-encrypted/test-suite": "1.10.0-rc.1" }, "files": [ "build/*" diff --git a/packages/indexdb/src/index.ts b/packages/indexdb/src/index.ts index 97ff1244..af9a8571 100644 --- a/packages/indexdb/src/index.ts +++ b/packages/indexdb/src/index.ts @@ -1,4 +1,5 @@ /** + * * @packageDocumentation * @module indexdb * @description This is a RXDB IndexDB storage that supports encryption middleware. diff --git a/packages/inmemory/coverage/coverage-summary.json b/packages/inmemory/coverage/coverage-summary.json index 609fcad1..34c5cdc7 100644 --- a/packages/inmemory/coverage/coverage-summary.json +++ b/packages/inmemory/coverage/coverage-summary.json @@ -1,5 +1,5 @@ {"total": {"lines":{"total":147,"covered":143,"skipped":0,"pct":97.27},"statements":{"total":153,"covered":148,"skipped":0,"pct":96.73},"functions":{"total":28,"covered":27,"skipped":0,"pct":96.42},"branches":{"total":53,"covered":43,"skipped":0,"pct":81.13},"branchesTrue":{"total":0,"covered":0,"skipped":0,"pct":100}} -,"/home/runner/work/pluto-encrypted/pluto-encrypted/packages/inmemory/src/index.ts": {"lines":{"total":12,"covered":12,"skipped":0,"pct":100},"functions":{"total":2,"covered":2,"skipped":0,"pct":100},"statements":{"total":12,"covered":12,"skipped":0,"pct":100},"branches":{"total":5,"covered":5,"skipped":0,"pct":100}} -,"/home/runner/work/pluto-encrypted/pluto-encrypted/packages/inmemory/src/inMemoryStorage/instance.ts": {"lines":{"total":93,"covered":89,"skipped":0,"pct":95.69},"functions":{"total":15,"covered":14,"skipped":0,"pct":93.33},"statements":{"total":98,"covered":93,"skipped":0,"pct":94.89},"branches":{"total":34,"covered":24,"skipped":0,"pct":70.58}} -,"/home/runner/work/pluto-encrypted/pluto-encrypted/packages/inmemory/src/inMemoryStorage/internal.ts": {"lines":{"total":42,"covered":42,"skipped":0,"pct":100},"functions":{"total":11,"covered":11,"skipped":0,"pct":100},"statements":{"total":43,"covered":43,"skipped":0,"pct":100},"branches":{"total":14,"covered":14,"skipped":0,"pct":100}} +,"/Users/ribo/Projects/personal/pluto-encrypted/packages/inmemory/src/index.ts": {"lines":{"total":12,"covered":12,"skipped":0,"pct":100},"functions":{"total":2,"covered":2,"skipped":0,"pct":100},"statements":{"total":12,"covered":12,"skipped":0,"pct":100},"branches":{"total":5,"covered":5,"skipped":0,"pct":100}} +,"/Users/ribo/Projects/personal/pluto-encrypted/packages/inmemory/src/inMemoryStorage/instance.ts": {"lines":{"total":93,"covered":89,"skipped":0,"pct":95.69},"functions":{"total":15,"covered":14,"skipped":0,"pct":93.33},"statements":{"total":98,"covered":93,"skipped":0,"pct":94.89},"branches":{"total":34,"covered":24,"skipped":0,"pct":70.58}} +,"/Users/ribo/Projects/personal/pluto-encrypted/packages/inmemory/src/inMemoryStorage/internal.ts": {"lines":{"total":42,"covered":42,"skipped":0,"pct":100},"functions":{"total":11,"covered":11,"skipped":0,"pct":100},"statements":{"total":43,"covered":43,"skipped":0,"pct":100},"branches":{"total":14,"covered":14,"skipped":0,"pct":100}} } diff --git a/packages/inmemory/package.json b/packages/inmemory/package.json index b6027e67..7f8ba596 100644 --- a/packages/inmemory/package.json +++ b/packages/inmemory/package.json @@ -1,6 +1,6 @@ { "name": "@pluto-encrypted/inmemory", - "version": "1.9.4", + "version": "2.0.0-rc.3", "description": "Secure Encrypted InMemory storage for @pluto-encrypted/database", "main": "./build/cjs/index.cjs", "module": "./build/esm/index.mjs", @@ -31,16 +31,16 @@ "author": "elribonazo@gmail.com", "license": "Apache-2.0", "dependencies": { - "@pluto-encrypted/encryption": "1.9.3", - "@pluto-encrypted/shared": "1.9.3", + "@pluto-encrypted/encryption": "1.10.0-rc.1", + "@pluto-encrypted/shared": "2.0.0-rc.3", "array-push-at-sort-position": "^4.0.1", "rxdb": "^14.17.0", "uuid": "^9.0.1" }, "devDependencies": { - "@pluto-encrypted/encryption": "1.9.3", - "@pluto-encrypted/shared": "1.9.3", - "@pluto-encrypted/test-suite": "1.9.4" + "@pluto-encrypted/encryption": "1.10.0-rc.1", + "@pluto-encrypted/shared": "2.0.0-rc.3", + "@pluto-encrypted/test-suite": "1.10.0-rc.1" }, "files": [ "build/*" diff --git a/packages/inmemory/src/index.ts b/packages/inmemory/src/index.ts index fe251486..70849c03 100644 --- a/packages/inmemory/src/index.ts +++ b/packages/inmemory/src/index.ts @@ -1,4 +1,5 @@ /** + * * @packageDocumentation * @module inmemory * @description This is a RXDB InMemory storage that supports encryption middleware. diff --git a/packages/leveldb/coverage/coverage-summary.json b/packages/leveldb/coverage/coverage-summary.json index 2b723e7c..008c2972 100644 --- a/packages/leveldb/coverage/coverage-summary.json +++ b/packages/leveldb/coverage/coverage-summary.json @@ -1,5 +1,5 @@ {"total": {"lines":{"total":200,"covered":189,"skipped":0,"pct":94.5},"statements":{"total":207,"covered":195,"skipped":0,"pct":94.2},"functions":{"total":51,"covered":48,"skipped":0,"pct":94.11},"branches":{"total":68,"covered":51,"skipped":0,"pct":75},"branchesTrue":{"total":0,"covered":0,"skipped":0,"pct":100}} -,"/home/runner/work/pluto-encrypted/pluto-encrypted/packages/leveldb/src/index.ts": {"lines":{"total":19,"covered":19,"skipped":0,"pct":100},"functions":{"total":4,"covered":4,"skipped":0,"pct":100},"statements":{"total":19,"covered":19,"skipped":0,"pct":100},"branches":{"total":8,"covered":6,"skipped":0,"pct":75}} -,"/home/runner/work/pluto-encrypted/pluto-encrypted/packages/leveldb/src/leveldb/instance.ts": {"lines":{"total":93,"covered":89,"skipped":0,"pct":95.69},"functions":{"total":16,"covered":15,"skipped":0,"pct":93.75},"statements":{"total":99,"covered":94,"skipped":0,"pct":94.94},"branches":{"total":30,"covered":22,"skipped":0,"pct":73.33}} -,"/home/runner/work/pluto-encrypted/pluto-encrypted/packages/leveldb/src/leveldb/internal.ts": {"lines":{"total":88,"covered":81,"skipped":0,"pct":92.04},"functions":{"total":31,"covered":29,"skipped":0,"pct":93.54},"statements":{"total":89,"covered":82,"skipped":0,"pct":92.13},"branches":{"total":30,"covered":23,"skipped":0,"pct":76.66}} +,"/Users/ribo/Projects/personal/pluto-encrypted/packages/leveldb/src/index.ts": {"lines":{"total":19,"covered":19,"skipped":0,"pct":100},"functions":{"total":4,"covered":4,"skipped":0,"pct":100},"statements":{"total":19,"covered":19,"skipped":0,"pct":100},"branches":{"total":8,"covered":6,"skipped":0,"pct":75}} +,"/Users/ribo/Projects/personal/pluto-encrypted/packages/leveldb/src/leveldb/instance.ts": {"lines":{"total":93,"covered":89,"skipped":0,"pct":95.69},"functions":{"total":16,"covered":15,"skipped":0,"pct":93.75},"statements":{"total":99,"covered":94,"skipped":0,"pct":94.94},"branches":{"total":30,"covered":22,"skipped":0,"pct":73.33}} +,"/Users/ribo/Projects/personal/pluto-encrypted/packages/leveldb/src/leveldb/internal.ts": {"lines":{"total":88,"covered":81,"skipped":0,"pct":92.04},"functions":{"total":31,"covered":29,"skipped":0,"pct":93.54},"statements":{"total":89,"covered":82,"skipped":0,"pct":92.13},"branches":{"total":30,"covered":23,"skipped":0,"pct":76.66}} } diff --git a/packages/leveldb/package.json b/packages/leveldb/package.json index 960f58a0..5534f914 100644 --- a/packages/leveldb/package.json +++ b/packages/leveldb/package.json @@ -1,6 +1,6 @@ { "name": "@pluto-encrypted/leveldb", - "version": "1.9.4", + "version": "2.0.0-rc.3", "description": "Secure Encrypted LevelDB storage for @pluto-encrypted/database", "main": "./build/cjs/index.cjs", "module": "./build/esm/index.mjs", @@ -31,8 +31,8 @@ "author": "elribonazo@gmail.com", "license": "Apache-2.0", "dependencies": { - "@pluto-encrypted/encryption": "1.9.3", - "@pluto-encrypted/shared": "1.9.3", + "@pluto-encrypted/encryption": "1.10.0-rc.1", + "@pluto-encrypted/shared": "2.0.0-rc.3", "array-push-at-sort-position": "^4.0.1", "level": "^6.0.1", "module-error": "^1.0.2", @@ -42,9 +42,9 @@ "uuid": "^9.0.1" }, "devDependencies": { - "@pluto-encrypted/encryption": "1.9.3", - "@pluto-encrypted/shared": "1.9.3", - "@pluto-encrypted/test-suite": "1.9.4" + "@pluto-encrypted/encryption": "1.10.0-rc.1", + "@pluto-encrypted/shared": "2.0.0-rc.3", + "@pluto-encrypted/test-suite": "1.10.0-rc.1" }, "files": [ "build/*" diff --git a/packages/leveldb/src/index.ts b/packages/leveldb/src/index.ts index 019f90f3..769607bd 100644 --- a/packages/leveldb/src/index.ts +++ b/packages/leveldb/src/index.ts @@ -1,4 +1,5 @@ /** + * * @packageDocumentation * @module leveldb * @description This is a RXDB LevelDB storage that supports encryption middleware. diff --git a/packages/leveldb/tests/init.test.ts b/packages/leveldb/tests/init.test.ts index 3575e91c..09304079 100644 --- a/packages/leveldb/tests/init.test.ts +++ b/packages/leveldb/tests/init.test.ts @@ -8,6 +8,7 @@ import { runTestSuite } from '@pluto-encrypted/test-suite'; import { createLevelDBStorage } from '../src' import { Database } from "../../database/src"; +import { getDefaultCollections } from "@pluto-encrypted/schemas"; const keyData = new Uint8Array(32); @@ -30,6 +31,7 @@ describe("Testing suite", () => { storage: createLevelDBStorage({ dbPath: "./db1" }), + collections: getDefaultCollections() } ); @@ -42,6 +44,7 @@ describe("Testing suite", () => { storage: createLevelDBStorage({ dbPath: "./db2" }), + collections: getDefaultCollections() } ); diff --git a/packages/schemas/.gitignore b/packages/schemas/.gitignore new file mode 100644 index 00000000..37d9a7e8 --- /dev/null +++ b/packages/schemas/.gitignore @@ -0,0 +1,10 @@ +node_modules +junit.xml +lcov.info +build +.npmrc + +coverage/**/*.html +coverage/**/*.css +coverage/**/*.js +coverage/**/*.png \ No newline at end of file diff --git a/packages/schemas/CHANGELOG.md b/packages/schemas/CHANGELOG.md new file mode 100644 index 00000000..e69de29b diff --git a/packages/schemas/LICENSE b/packages/schemas/LICENSE new file mode 100644 index 00000000..216af719 --- /dev/null +++ b/packages/schemas/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright © 2021-2023 Input Output Global + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. diff --git a/packages/schemas/README.md b/packages/schemas/README.md new file mode 100644 index 00000000..c8439483 --- /dev/null +++ b/packages/schemas/README.md @@ -0,0 +1,2 @@ +# Pluto-encrypted +Pluto Encrypted default models and schemas. \ No newline at end of file diff --git a/packages/schemas/coverage/coverage-summary.json b/packages/schemas/coverage/coverage-summary.json new file mode 100644 index 00000000..425132b6 --- /dev/null +++ b/packages/schemas/coverage/coverage-summary.json @@ -0,0 +1,25 @@ +{"total": {"lines":{"total":176,"covered":0,"skipped":0,"pct":0},"statements":{"total":187,"covered":0,"skipped":0,"pct":0},"functions":{"total":61,"covered":0,"skipped":0,"pct":0},"branches":{"total":60,"covered":0,"skipped":0,"pct":0},"branchesTrue":{"total":0,"covered":0,"skipped":0,"pct":100}} +,"/Users/ribo/Projects/personal/pluto-encrypted/packages/schemas/src/index.ts": {"lines":{"total":1,"covered":0,"skipped":0,"pct":0},"functions":{"total":1,"covered":0,"skipped":0,"pct":0},"statements":{"total":1,"covered":0,"skipped":0,"pct":0},"branches":{"total":1,"covered":0,"skipped":0,"pct":0}} +,"/Users/ribo/Projects/personal/pluto-encrypted/packages/schemas/src/schemas/credential/orm.ts": {"lines":{"total":10,"covered":0,"skipped":0,"pct":0},"functions":{"total":1,"covered":0,"skipped":0,"pct":0},"statements":{"total":10,"covered":0,"skipped":0,"pct":0},"branches":{"total":4,"covered":0,"skipped":0,"pct":0}} +,"/Users/ribo/Projects/personal/pluto-encrypted/packages/schemas/src/schemas/credential/schema.ts": {"lines":{"total":1,"covered":0,"skipped":0,"pct":0},"functions":{"total":0,"covered":0,"skipped":0,"pct":100},"statements":{"total":1,"covered":0,"skipped":0,"pct":0},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}} +,"/Users/ribo/Projects/personal/pluto-encrypted/packages/schemas/src/schemas/credential/static.ts": {"lines":{"total":9,"covered":0,"skipped":0,"pct":0},"functions":{"total":3,"covered":0,"skipped":0,"pct":0},"statements":{"total":10,"covered":0,"skipped":0,"pct":0},"branches":{"total":5,"covered":0,"skipped":0,"pct":0}} +,"/Users/ribo/Projects/personal/pluto-encrypted/packages/schemas/src/schemas/credentialRequestMetadata/orm.ts": {"lines":{"total":2,"covered":0,"skipped":0,"pct":0},"functions":{"total":1,"covered":0,"skipped":0,"pct":0},"statements":{"total":2,"covered":0,"skipped":0,"pct":0},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}} +,"/Users/ribo/Projects/personal/pluto-encrypted/packages/schemas/src/schemas/credentialRequestMetadata/schema.ts": {"lines":{"total":1,"covered":0,"skipped":0,"pct":0},"functions":{"total":0,"covered":0,"skipped":0,"pct":100},"statements":{"total":1,"covered":0,"skipped":0,"pct":0},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}} +,"/Users/ribo/Projects/personal/pluto-encrypted/packages/schemas/src/schemas/credentialRequestMetadata/static.ts": {"lines":{"total":6,"covered":0,"skipped":0,"pct":0},"functions":{"total":2,"covered":0,"skipped":0,"pct":0},"statements":{"total":6,"covered":0,"skipped":0,"pct":0},"branches":{"total":2,"covered":0,"skipped":0,"pct":0}} +,"/Users/ribo/Projects/personal/pluto-encrypted/packages/schemas/src/schemas/did/schema.ts": {"lines":{"total":1,"covered":0,"skipped":0,"pct":0},"functions":{"total":0,"covered":0,"skipped":0,"pct":100},"statements":{"total":1,"covered":0,"skipped":0,"pct":0},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}} +,"/Users/ribo/Projects/personal/pluto-encrypted/packages/schemas/src/schemas/did/static.ts": {"lines":{"total":48,"covered":0,"skipped":0,"pct":0},"functions":{"total":11,"covered":0,"skipped":0,"pct":0},"statements":{"total":49,"covered":0,"skipped":0,"pct":0},"branches":{"total":14,"covered":0,"skipped":0,"pct":0}} +,"/Users/ribo/Projects/personal/pluto-encrypted/packages/schemas/src/schemas/didpair/schema.ts": {"lines":{"total":1,"covered":0,"skipped":0,"pct":0},"functions":{"total":0,"covered":0,"skipped":0,"pct":100},"statements":{"total":1,"covered":0,"skipped":0,"pct":0},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}} +,"/Users/ribo/Projects/personal/pluto-encrypted/packages/schemas/src/schemas/didpair/static.ts": {"lines":{"total":9,"covered":0,"skipped":0,"pct":0},"functions":{"total":5,"covered":0,"skipped":0,"pct":0},"statements":{"total":9,"covered":0,"skipped":0,"pct":0},"branches":{"total":4,"covered":0,"skipped":0,"pct":0}} +,"/Users/ribo/Projects/personal/pluto-encrypted/packages/schemas/src/schemas/linksecret/orm.ts": {"lines":{"total":2,"covered":0,"skipped":0,"pct":0},"functions":{"total":1,"covered":0,"skipped":0,"pct":0},"statements":{"total":2,"covered":0,"skipped":0,"pct":0},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}} +,"/Users/ribo/Projects/personal/pluto-encrypted/packages/schemas/src/schemas/linksecret/schema.ts": {"lines":{"total":1,"covered":0,"skipped":0,"pct":0},"functions":{"total":0,"covered":0,"skipped":0,"pct":100},"statements":{"total":1,"covered":0,"skipped":0,"pct":0},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}} +,"/Users/ribo/Projects/personal/pluto-encrypted/packages/schemas/src/schemas/linksecret/static.ts": {"lines":{"total":7,"covered":0,"skipped":0,"pct":0},"functions":{"total":2,"covered":0,"skipped":0,"pct":0},"statements":{"total":7,"covered":0,"skipped":0,"pct":0},"branches":{"total":4,"covered":0,"skipped":0,"pct":0}} +,"/Users/ribo/Projects/personal/pluto-encrypted/packages/schemas/src/schemas/mediator/orm.ts": {"lines":{"total":3,"covered":0,"skipped":0,"pct":0},"functions":{"total":1,"covered":0,"skipped":0,"pct":0},"statements":{"total":3,"covered":0,"skipped":0,"pct":0},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}} +,"/Users/ribo/Projects/personal/pluto-encrypted/packages/schemas/src/schemas/mediator/schema.ts": {"lines":{"total":1,"covered":0,"skipped":0,"pct":0},"functions":{"total":0,"covered":0,"skipped":0,"pct":100},"statements":{"total":1,"covered":0,"skipped":0,"pct":0},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}} +,"/Users/ribo/Projects/personal/pluto-encrypted/packages/schemas/src/schemas/mediator/static.ts": {"lines":{"total":4,"covered":0,"skipped":0,"pct":0},"functions":{"total":3,"covered":0,"skipped":0,"pct":0},"statements":{"total":5,"covered":0,"skipped":0,"pct":0},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}} +,"/Users/ribo/Projects/personal/pluto-encrypted/packages/schemas/src/schemas/message/orm.ts": {"lines":{"total":2,"covered":0,"skipped":0,"pct":0},"functions":{"total":1,"covered":0,"skipped":0,"pct":0},"statements":{"total":2,"covered":0,"skipped":0,"pct":0},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}} +,"/Users/ribo/Projects/personal/pluto-encrypted/packages/schemas/src/schemas/message/schema.ts": {"lines":{"total":1,"covered":0,"skipped":0,"pct":0},"functions":{"total":0,"covered":0,"skipped":0,"pct":100},"statements":{"total":1,"covered":0,"skipped":0,"pct":0},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}} +,"/Users/ribo/Projects/personal/pluto-encrypted/packages/schemas/src/schemas/message/static.ts": {"lines":{"total":30,"covered":0,"skipped":0,"pct":0},"functions":{"total":19,"covered":0,"skipped":0,"pct":0},"statements":{"total":38,"covered":0,"skipped":0,"pct":0},"branches":{"total":6,"covered":0,"skipped":0,"pct":0}} +,"/Users/ribo/Projects/personal/pluto-encrypted/packages/schemas/src/schemas/privatekey/orm.ts": {"lines":{"total":27,"covered":0,"skipped":0,"pct":0},"functions":{"total":5,"covered":0,"skipped":0,"pct":0},"statements":{"total":27,"covered":0,"skipped":0,"pct":0},"branches":{"total":18,"covered":0,"skipped":0,"pct":0}} +,"/Users/ribo/Projects/personal/pluto-encrypted/packages/schemas/src/schemas/privatekey/schema.ts": {"lines":{"total":1,"covered":0,"skipped":0,"pct":0},"functions":{"total":0,"covered":0,"skipped":0,"pct":100},"statements":{"total":1,"covered":0,"skipped":0,"pct":0},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}} +,"/Users/ribo/Projects/personal/pluto-encrypted/packages/schemas/src/schemas/privatekey/static.ts": {"lines":{"total":8,"covered":0,"skipped":0,"pct":0},"functions":{"total":5,"covered":0,"skipped":0,"pct":0},"statements":{"total":8,"covered":0,"skipped":0,"pct":0},"branches":{"total":2,"covered":0,"skipped":0,"pct":0}} +} diff --git a/packages/schemas/package.json b/packages/schemas/package.json new file mode 100644 index 00000000..adc7edd2 --- /dev/null +++ b/packages/schemas/package.json @@ -0,0 +1,49 @@ +{ + "name": "@pluto-encrypted/schemas", + "version": "1.0.0-rc.3", + "description": "Provides the default schemas used in @pluto-encrypted/database", + "main": "./build/cjs/index.cjs", + "module": "./build/esm/index.mjs", + "types": "./build/index.d.ts", + "exports": { + ".": { + "import": "./build/esm/index.mjs", + "require": "./build/cjs/index.cjs" + } + }, + "homepage": "https://atala-community-projects.github.io/pluto-encrypted", + "publishConfig": { + "access": "public" + }, + "scripts": { + "prepublishOnly": "npm run build", + "clean-packages": "rm -rf node_modules && rm -rf build", + "build": "rm -rf build && npx rollup -c rollup/rollup.mjs" + }, + "repository": { + "type": "git", + "url": "https://github.com/atala-community-projects/pluto-encrypted.git" + }, + "author": "elribonazo@gmail.com", + "license": "Apache-2.0", + "peerDependencies": { + "@atala/prism-wallet-sdk": "^4.0.0-rc.1" + }, + "devDependencies": { + "@pluto-encrypted/encryption": "1.10.0-rc.1", + "@pluto-encrypted/shared": "2.0.0-rc.3", + "@vitest/coverage-v8": "^1.0.4" + }, + "dependencies": { + "@atala/prism-wallet-sdk": "^4.0.0-rc.1", + "@pluto-encrypted/encryption": "1.10.0-rc.1", + "@pluto-encrypted/shared": "2.0.0-rc.3", + "rxdb": "^14.17.0", + "rxjs": "7.8.1", + "uuid": "^9.0.1" + }, + "files": [ + "build/*" + ], + "gitHead": "6aa4ce8bbb9938fc4c4e790efffa5b902631362c" +} diff --git a/packages/schemas/rollup/rollup.mjs b/packages/schemas/rollup/rollup.mjs new file mode 100644 index 00000000..1278dac6 --- /dev/null +++ b/packages/schemas/rollup/rollup.mjs @@ -0,0 +1,5 @@ +import nodePolyfills from "rollup-plugin-polyfill-node"; + +import CreateConfig from "../../../rollup/index.mjs"; + +export default CreateConfig(undefined, []); diff --git a/packages/schemas/src/index.ts b/packages/schemas/src/index.ts new file mode 100644 index 00000000..6396d797 --- /dev/null +++ b/packages/schemas/src/index.ts @@ -0,0 +1,71 @@ +/** + * + * @packageDocumentation + * @module database + */ +import { RxCollectionCreator } from 'rxdb' +import { CredentialSchema, CredentialMethods, CredentialStaticMethods } from './schemas/credential' +import { CredentialRequestMetadataSchema, CredentialRequestMetadataMethods, CredentialRequestMetadataStaticMethods } from './schemas/credentialRequestMetadata' +import { DIDSchema, DIDStaticMethods } from './schemas/did' +import { DIDPairSchema, DIDPairStaticMethods } from './schemas/didpair' +import { LinkSecretSchema, LinkSecretMethods, LinkSecretStaticMethods } from './schemas/linksecret' +import { MediatorSchema, MediatorMethods, MediatorStaticMethods } from './schemas/mediator' +import { MessageSchema, MessageMethods, MessageStaticMethods } from './schemas/message' +import { PrivateKeySchema, PrivateKeyMethods, PrivateKeyStaticMethods } from './schemas/privatekey' +import { PlutoCollectionsCreator } from './types' + +export function getDefaultCollections(extendedCollections: { [name: string]: RxCollectionCreator } = {}): { [name: string]: RxCollectionCreator } & PlutoCollectionsCreator { + return { + messages: { + schema: MessageSchema, + methods: MessageMethods, + statics: MessageStaticMethods + }, + dids: { + schema: DIDSchema, + statics: DIDStaticMethods + }, + didpairs: { + schema: DIDPairSchema, + statics: DIDPairStaticMethods + }, + mediators: { + schema: MediatorSchema, + methods: MediatorMethods, + statics: MediatorStaticMethods + }, + privatekeys: { + schema: PrivateKeySchema, + methods: PrivateKeyMethods, + statics: PrivateKeyStaticMethods + }, + credentials: { + schema: CredentialSchema, + methods: CredentialMethods, + statics: CredentialStaticMethods + }, + credentialrequestmetadatas: { + schema: CredentialRequestMetadataSchema, + methods: CredentialRequestMetadataMethods, + statics: CredentialRequestMetadataStaticMethods + }, + linksecrets: { + schema: LinkSecretSchema, + methods: LinkSecretMethods, + statics: LinkSecretStaticMethods + }, + ...extendedCollections, + } +} + +export * from './schemas/credential' +export * from './schemas/credentialRequestMetadata' +export * from './schemas/did' +export * from './schemas/didpair' +export * from './schemas/linksecret' +export * from './schemas/mediator' +export * from './schemas/message' +export * from './schemas/privatekey' +export * from './types' + +export type { Domain as WALLET_SDK_DOMAIN } from '@atala/prism-wallet-sdk' \ No newline at end of file diff --git a/packages/schemas/src/schemas/credential/index.ts b/packages/schemas/src/schemas/credential/index.ts new file mode 100644 index 00000000..c6864c03 --- /dev/null +++ b/packages/schemas/src/schemas/credential/index.ts @@ -0,0 +1,4 @@ +export * from './orm'; +export * from './schema'; +export * from './static'; +export * from './types'; \ No newline at end of file diff --git a/packages/schemas/src/schemas/credential/orm.ts b/packages/schemas/src/schemas/credential/orm.ts new file mode 100644 index 00000000..925df347 --- /dev/null +++ b/packages/schemas/src/schemas/credential/orm.ts @@ -0,0 +1,28 @@ + +import SDK from '@atala/prism-wallet-sdk' +import { CredentialMethodTypes, CredentialSchemaType } from './types'; + +export const CredentialMethods: CredentialMethodTypes = { + toDomainCredential: function toDomainCredential(this: CredentialSchemaType) { + if (this.recoveryId === SDK.JWTVerifiableCredentialRecoveryId) { + const jwtString = Buffer.from(this.credentialData).toString() + const jwtObj = JSON.parse(jwtString) + return SDK.JWTCredential.fromJWT(jwtObj, jwtString) + } else if (this.recoveryId === SDK.AnonCredsRecoveryId) { + const credentialData = Buffer.from(this.credentialData).toString() + const credentialJson = JSON.parse(credentialData) + return new SDK.AnonCredsCredential({ + schema_id: credentialJson[SDK.AnonCredsCredentialProperties.schemaId], + cred_def_id: credentialJson[SDK.AnonCredsCredentialProperties.credentialDefinitionId], + values: credentialJson[SDK.AnonCredsCredentialProperties.values], + signature: credentialJson[SDK.AnonCredsCredentialProperties.signature], + signature_correctness_proof: + credentialJson[ + SDK.AnonCredsCredentialProperties.signatureCorrectnessProof + ] + }) + } else { + throw new Error('Unsupported key type from db storage') + } + } +} \ No newline at end of file diff --git a/packages/schemas/src/schemas/credential/schema.ts b/packages/schemas/src/schemas/credential/schema.ts new file mode 100644 index 00000000..6e38cc41 --- /dev/null +++ b/packages/schemas/src/schemas/credential/schema.ts @@ -0,0 +1,51 @@ +import { Schema } from "../../types"; +import { CredentialSchemaType } from "./types"; + + + +export const CredentialSchema: Schema = { + version: 0, + primaryKey: 'id', + type: 'object', + properties: { + id: { + type: 'string', + maxLength: 60 + }, + recoveryId: { + type: 'string' + }, + credentialData: { + type: 'string' + }, + issuer: { + type: 'string' + }, + subject: { + type: 'string' + }, + credentialCreated: { + type: 'string' + }, + credentialUpdated: { + type: 'string' + }, + credentialSchema: { + type: 'string' + }, + validUntil: { + type: 'string' + }, + revoked: { + type: 'boolean' + }, + availableClaims: { + type: 'array', + items: { + type: 'string' + } + } + }, + encrypted: ['credentialData'], + required: ['id', 'recoveryId', 'credentialData'] +} \ No newline at end of file diff --git a/packages/schemas/src/schemas/credential/static.ts b/packages/schemas/src/schemas/credential/static.ts new file mode 100644 index 00000000..379cf76d --- /dev/null +++ b/packages/schemas/src/schemas/credential/static.ts @@ -0,0 +1,24 @@ +import SDK from '@atala/prism-wallet-sdk' +import { v4 as uuidv4 } from 'uuid' + +import { CredentialStaticMethodTypes } from './types' + +export const CredentialStaticMethods: CredentialStaticMethodTypes = { + async getAllCredentials(): Promise { + const credentials = await this.db.collections.credentials.find().exec() + return credentials.map( + (verifiableCredential) => verifiableCredential.toDomainCredential() + ) + }, + async storeCredential(credential: SDK.Domain.Credential): Promise { + if (!credential.isStorable || !credential.isStorable()) { + throw new Error('Credential is not storable') + } + const storable = credential.toStorable() + /* istanbul ignore else -- @preserve */ + if (!storable.id) storable.id = uuidv4() + + await this.db.collections.credentials.insert(storable) + } + +} \ No newline at end of file diff --git a/packages/schemas/src/schemas/credential/types.ts b/packages/schemas/src/schemas/credential/types.ts new file mode 100644 index 00000000..8a4f69c4 --- /dev/null +++ b/packages/schemas/src/schemas/credential/types.ts @@ -0,0 +1,39 @@ +import { KeyFunctionMap, RxCollection, RxDocument } from "rxdb" +import SDK from '@atala/prism-wallet-sdk' +import { StaticRxCollectionContext } from "../../types" + +export interface CredentialSubjectType { + type: string + name: string + value: string +} + +export interface CredentialSchemaType { + id: string + recoveryId: string + credentialData: string + issuer?: string + subject?: string + credentialCreated?: string + credentialUpdated?: string + credentialSchema?: string + validUntil?: string + revoked?: boolean + availableClaims?: string[] +} + +export type CredentialDocument = RxDocument +export interface CredentialMethodTypes extends KeyFunctionMap { + toDomainCredential: (this: CredentialSchemaType) => SDK.Domain.Credential +} + +export interface CredentialStaticMethodTypes extends KeyFunctionMap { + getAllCredentials(this: StaticRxCollectionContext<{ credentials: CredentialCollection }>): Promise + storeCredential(this: StaticRxCollectionContext<{ credentials: CredentialCollection }>, credential: SDK.Domain.Credential): Promise +} + +export type CredentialCollection = RxCollection< + CredentialSchemaType, + CredentialMethodTypes, + CredentialDocument +> diff --git a/packages/schemas/src/schemas/credentialRequestMetadata/index.ts b/packages/schemas/src/schemas/credentialRequestMetadata/index.ts new file mode 100644 index 00000000..c6864c03 --- /dev/null +++ b/packages/schemas/src/schemas/credentialRequestMetadata/index.ts @@ -0,0 +1,4 @@ +export * from './orm'; +export * from './schema'; +export * from './static'; +export * from './types'; \ No newline at end of file diff --git a/packages/schemas/src/schemas/credentialRequestMetadata/orm.ts b/packages/schemas/src/schemas/credentialRequestMetadata/orm.ts new file mode 100644 index 00000000..f5a8c21d --- /dev/null +++ b/packages/schemas/src/schemas/credentialRequestMetadata/orm.ts @@ -0,0 +1,9 @@ +import { CredentialRequestMetadataMethodTypes, CredentialRequestMetadataSchemaType } from "./types" + +export const CredentialRequestMetadataMethods: CredentialRequestMetadataMethodTypes = { + toDomainCredentialRequestMetadata: function toDomainCredentialRequestMetadata( + this: CredentialRequestMetadataSchemaType + ) { + return this + } +} \ No newline at end of file diff --git a/packages/schemas/src/schemas/credentialRequestMetadata/schema.ts b/packages/schemas/src/schemas/credentialRequestMetadata/schema.ts new file mode 100644 index 00000000..a42cea58 --- /dev/null +++ b/packages/schemas/src/schemas/credentialRequestMetadata/schema.ts @@ -0,0 +1,31 @@ +import { Schema } from "../../types"; +import { CredentialRequestMetadataSchemaType } from "./types"; + +export const CredentialRequestMetadataSchema: Schema = +{ + version: 0, + primaryKey: 'id', + type: 'object', + properties: { + id: { + type: 'string', + maxLength: 60 + }, + link_secret_blinding_data: { + type: 'object', + properties: { + v_prime: { + type: 'string' + } + } + }, + link_secret_name: { + type: 'string' + }, + nonce: { + type: 'string' + } + }, + encrypted: ['link_secret_blinding_data', 'nonce'], + required: ['id', 'link_secret_blinding_data', 'link_secret_name', 'nonce'] +} \ No newline at end of file diff --git a/packages/schemas/src/schemas/credentialRequestMetadata/static.ts b/packages/schemas/src/schemas/credentialRequestMetadata/static.ts new file mode 100644 index 00000000..905cebec --- /dev/null +++ b/packages/schemas/src/schemas/credentialRequestMetadata/static.ts @@ -0,0 +1,33 @@ +import SDK from '@atala/prism-wallet-sdk' +import { v4 as uuidv4 } from 'uuid' +import { CredentialRequestMetadataStaticMethodTypes } from './types' + +export const CredentialRequestMetadataStaticMethods: CredentialRequestMetadataStaticMethodTypes = +{ + async storeCredentialMetadata( + metadata: SDK.Domain.Anoncreds.CredentialRequestMeta, + linkSecret: string + ): Promise { + await this.db.collections.credentialrequestmetadatas.insert({ + ...metadata, + id: uuidv4(), + link_secret_name: linkSecret + }) + }, + async fetchCredentialMetadata( + linkSecretName: string + ): Promise { + const credentialRequestMetadata = await this.db.collections.credentialrequestmetadatas.findOne({ + selector: { + link_secret_name: { + $eq: linkSecretName + } + } + }).exec() + + if (credentialRequestMetadata) { + return credentialRequestMetadata.toDomainCredentialRequestMetadata() + } + return null + } +} diff --git a/packages/schemas/src/schemas/credentialRequestMetadata/types.ts b/packages/schemas/src/schemas/credentialRequestMetadata/types.ts new file mode 100644 index 00000000..102af592 --- /dev/null +++ b/packages/schemas/src/schemas/credentialRequestMetadata/types.ts @@ -0,0 +1,44 @@ +import { KeyFunctionMap, RxCollection, RxDocument } from "rxdb" +import SDK from '@atala/prism-wallet-sdk' +import { StaticRxCollectionContext } from "../../types" + + + + +export type CredentialRequestMetadataCollection = RxCollection< + CredentialRequestMetadataSchemaType, + CredentialRequestMetadataMethodTypes, + CredentialRequestMetadataStaticMethodTypes +> + + + +export interface CredentialRequestMetadataSchemaType { + id: string + link_secret_blinding_data: { + v_prime: string + } + link_secret_name: string + nonce: string +} + +export type CredentialRequestMetadataDocument = + RxDocument + +export interface CredentialRequestMetadataMethodTypes extends KeyFunctionMap { + toDomainCredentialRequestMetadata: ( + this: CredentialRequestMetadataSchemaType + ) => SDK.Domain.Anoncreds.CredentialRequestMeta +} + +export interface CredentialRequestMetadataStaticMethodTypes extends KeyFunctionMap { + fetchCredentialMetadata( + this: StaticRxCollectionContext<{ credentialrequestmetadatas: CredentialRequestMetadataCollection }>, + linkSecretName: string + ): Promise + storeCredentialMetadata( + this: StaticRxCollectionContext<{ credentialrequestmetadatas: CredentialRequestMetadataCollection }>, + metadata: SDK.Domain.Anoncreds.CredentialRequestMeta, + linkSecret: string + ): Promise +} \ No newline at end of file diff --git a/packages/schemas/src/schemas/did/index.ts b/packages/schemas/src/schemas/did/index.ts new file mode 100644 index 00000000..70bef2c2 --- /dev/null +++ b/packages/schemas/src/schemas/did/index.ts @@ -0,0 +1,3 @@ +export * from './schema'; +export * from './static'; +export * from './types'; \ No newline at end of file diff --git a/packages/schemas/src/schemas/did/schema.ts b/packages/schemas/src/schemas/did/schema.ts new file mode 100644 index 00000000..3d47dbf8 --- /dev/null +++ b/packages/schemas/src/schemas/did/schema.ts @@ -0,0 +1,35 @@ +import { Schema } from "../../types"; +import { DIDSchemaType } from "./types"; + + + + +export const DIDSchema: Schema = { + version: 0, + primaryKey: 'did', + type: 'object', + properties: { + method: { + type: 'string', + maxLength: 60 + }, + methodId: { + type: 'string', + maxLength: 60 + }, + schema: { + type: 'string', + maxLength: 60 + }, + alias: { + type: 'string', + maxLength: 60 + }, + did: { + type: 'string', + maxLength: 60 + } + }, + encrypted: [], + required: ['method', 'methodId', 'did', 'schema'] +} \ No newline at end of file diff --git a/packages/schemas/src/schemas/did/static.ts b/packages/schemas/src/schemas/did/static.ts new file mode 100644 index 00000000..42b8d8ea --- /dev/null +++ b/packages/schemas/src/schemas/did/static.ts @@ -0,0 +1,195 @@ +import SDK from '@atala/prism-wallet-sdk' +import { v4 as uuidv4 } from 'uuid' + +import { KeySpec } from '../privatekey' +import { DIDStaticMethodTypes } from './types' + + + +export const DIDStaticMethods: DIDStaticMethodTypes = { + async storePrismDID(did: SDK.Domain.DID, keyPathIndex: number, privateKey: SDK.Domain.PrivateKey, _privateKeyMetaId?: string | null | undefined, alias?: string | undefined): Promise { + await this.db.collections.dids.insert({ + did: did.toString(), + method: did.method, + methodId: did.methodId, + schema: did.schema, + alias + }) + await this.storePrivateKeys( + privateKey, + did, + keyPathIndex, + null + ) + }, + async getAllPrismDIDs(): Promise { + const dids = await this.db.collections.dids.find({ + selector: { + method: { + $eq: 'prism' + } + } + }).exec() + + const prismDIDInfo: SDK.Domain.PrismDIDInfo[] = [] + + for (const did of dids) { + const didPrivateKeys = await this.getDIDPrivateKeysByDID!( + SDK.Domain.DID.fromString(did.did) + ) + + for (const privateKey of didPrivateKeys) { + const indexProp = privateKey.getProperty(SDK.Domain.KeyProperties.index)! + + prismDIDInfo.push( + new SDK.Domain.PrismDIDInfo( + SDK.Domain.DID.fromString(did.did), + parseInt(indexProp), + did.alias + ) + ) + } + } + + return prismDIDInfo + }, + async getDIDInfoByDID(did: SDK.Domain.DID): Promise { + const didDB = await this.db.collections.dids.findOne({ + selector: { + did: did.toString() + } + }).exec() + + if (didDB) { + const privateKeys = await this.getDIDPrivateKeysByDID!( + SDK.Domain.DID.fromString(didDB.did) + ) + /* istanbul ignore if */ + if (privateKeys.length === 0) { + throw new Error( + 'Imposible to recover PrismDIDInfo without its privateKey data.' + ) + } + const indexProp = privateKeys + .at(0)! + .getProperty(SDK.Domain.KeyProperties.index) + const index = indexProp ? parseInt(indexProp) : undefined + return new SDK.Domain.PrismDIDInfo( + SDK.Domain.DID.fromString(didDB.did), + index, + didDB.alias + ) + } + + return null + }, + async getDIDInfoByAlias(alias: string): Promise { + const dids = await this.db.collections.dids.find({ + selector: { + alias: { + $eq: alias + } + } + }).exec() + const prismDIDInfo: SDK.Domain.PrismDIDInfo[] = [] + for (const did of dids) { + const didPrivateKeys = await this.getDIDPrivateKeysByDID!( + SDK.Domain.DID.fromString(did.did) + ) + for (const privateKey of didPrivateKeys) { + const indexProp = privateKey.getProperty(SDK.Domain.KeyProperties.index)! + prismDIDInfo.push( + new SDK.Domain.PrismDIDInfo( + SDK.Domain.DID.fromString(did.did), + parseInt(indexProp), + did.alias + ) + ) + } + } + return prismDIDInfo + }, + async getPrismDIDKeyPathIndex(did: SDK.Domain.DID): Promise { + const [key] = await this.getDIDPrivateKeysByDID!(did) + if (!key) { + return null + } + return key.index || 0 + }, + + async getPrismLastKeyPathIndex(): Promise { + const results = await this.getAllPrismDIDs!() + if (!results || results.length === 0) { + return 0 + } + return Math.max(...results.map((result) => result.keyPathIndex)) + }, + async getAllPeerDIDs(): Promise { + const peerDIDs: SDK.PeerDID[] = [] + const dids = await this.db.collections.dids.find({ + selector: { + method: { + $eq: 'peer' + } + } + }).exec() + for (const did of dids) { + const peerDID = SDK.Domain.DID.fromString(did.did) + const keys = await this.getDIDPrivateKeysByDID!(peerDID) + peerDIDs.push( + new SDK.PeerDID( + peerDID, + keys.map((key) => ({ + keyCurve: { + curve: key.curve as any + }, + value: key.raw + })) + ) + ) + } + return peerDIDs + }, + /** + * Stores a peerdid with its privateKeys + * @param did + * @param privateKeys + */ + async storePeerDID( + did: SDK.Domain.DID, + privateKeys: SDK.Domain.PrivateKey[] + ): Promise { + await this.db.collections.dids.insert({ + did: did.toString(), + method: did.method, + methodId: did.methodId, + schema: did.schema + }) + for (const prv of privateKeys) { + await this.db.collections.privatekeys.insert({ + id: uuidv4(), + did: did.toString(), + type: prv.type, + keySpecification: Array.from(prv.keySpecification).reduce( + (all, [key, value]) => [ + ...all, + { + type: 'string', + name: key, + value: `${value}` + } + ], + [ + { + type: 'string', + name: 'raw', + value: Buffer.from(prv.raw).toString('hex') + } + ] + ) + }) + } + }, + + +} \ No newline at end of file diff --git a/packages/schemas/src/schemas/did/types.ts b/packages/schemas/src/schemas/did/types.ts new file mode 100644 index 00000000..3eec271d --- /dev/null +++ b/packages/schemas/src/schemas/did/types.ts @@ -0,0 +1,45 @@ +import SDK from '@atala/prism-wallet-sdk' +import { RxDocument, KeyFunctionMap, RxCollection } from "rxdb" + +import { StaticRxCollectionContext } from "../../types" + + +export interface DIDSchemaType { + schema: string + method: string + methodId: string + alias?: string + did: string +} + +export type DIDDocument = RxDocument + +export interface DIDStaticMethodTypes extends KeyFunctionMap { + getPrismLastKeyPathIndex(this: StaticRxCollectionContext<{ dids: DIDCollection }>): Promise + getPrismDIDKeyPathIndex(this: StaticRxCollectionContext<{ dids: DIDCollection }>, did: SDK.Domain.DID): Promise + storePeerDID( + this: StaticRxCollectionContext<{ dids: DIDCollection }>, + did: SDK.Domain.DID, + privateKeys: SDK.Domain.PrivateKey[] + ): Promise + getAllPeerDIDs(this: StaticRxCollectionContext<{ dids: DIDCollection }>): Promise + getAllPrismDIDs(this: StaticRxCollectionContext<{ dids: DIDCollection }>): Promise + getDIDInfoByDID(this: StaticRxCollectionContext<{ dids: DIDCollection }>, did: SDK.Domain.DID): Promise + getDIDInfoByAlias(this: StaticRxCollectionContext<{ dids: DIDCollection }>, alias: string): Promise + storePrismDID( + this: StaticRxCollectionContext<{ dids: DIDCollection }>, + did: SDK.Domain.DID, + keyPathIndex: number, + privateKey: SDK.Domain.PrivateKey, + _privateKeyMetaId?: string | null, + alias?: string | undefined + ): Promise +} + + + +export type DIDCollection = RxCollection< + DIDSchemaType, + any, + DIDStaticMethodTypes +> \ No newline at end of file diff --git a/packages/schemas/src/schemas/didpair/index.ts b/packages/schemas/src/schemas/didpair/index.ts new file mode 100644 index 00000000..70bef2c2 --- /dev/null +++ b/packages/schemas/src/schemas/didpair/index.ts @@ -0,0 +1,3 @@ +export * from './schema'; +export * from './static'; +export * from './types'; \ No newline at end of file diff --git a/packages/schemas/src/schemas/didpair/schema.ts b/packages/schemas/src/schemas/didpair/schema.ts new file mode 100644 index 00000000..1db82356 --- /dev/null +++ b/packages/schemas/src/schemas/didpair/schema.ts @@ -0,0 +1,24 @@ +import { Schema } from "../../types"; +import { DIDPairSchemaType } from "./types"; + + + +export const DIDPairSchema: Schema = { + version: 0, + primaryKey: 'name', + type: 'object', + properties: { + hostDID: { + type: 'string' + }, + name: { + type: 'string', + maxLength: 60 + }, + receiverDID: { + type: 'string' + } + }, + encrypted: [], + required: ['name', 'hostDID', 'receiverDID'] +} \ No newline at end of file diff --git a/packages/schemas/src/schemas/didpair/static.ts b/packages/schemas/src/schemas/didpair/static.ts new file mode 100644 index 00000000..6e5fa88d --- /dev/null +++ b/packages/schemas/src/schemas/didpair/static.ts @@ -0,0 +1,81 @@ +import SDK from '@atala/prism-wallet-sdk' + + +import { DIDPairStaticMethodTypes } from './types' + +export const DIDPairStaticMethods: DIDPairStaticMethodTypes = { + + /** + * Stores a didpair + * @param host + * @param receiver + * @param name + */ + async storeDIDPair( + host: SDK.Domain.DID, + receiver: SDK.Domain.DID, + name: string + ): Promise { + await this.db.collections.didpairs.insert({ + hostDID: host.toString(), + receiverDID: receiver.toString(), + name + }) + }, + /** + * Gets all the stores didPairs + * @returns [Domain.DIDPair[]](https://input-output-hk.github.io/atala-prism-wallet-sdk-ts/classes/Domain.DIDPair.html) + */ + async getAllDidPairs(): Promise { + const results = await this.db.collections.didpairs.find().exec() + return results.map( + ({ hostDID, receiverDID, name }) => + new SDK.Domain.DIDPair(SDK.Domain.DID.fromString(hostDID), SDK.Domain.DID.fromString(receiverDID), name) + ) + }, + async getPairByName(name: string): Promise { + const didPair = await this.db.collections.didpairs.findOne({ + selector: { + $and: [ + { + name + } + ] + } + }).exec() + + return didPair + ? new SDK.Domain.DIDPair( + SDK.Domain.DID.fromString(didPair.hostDID), + SDK.Domain.DID.fromString(didPair.receiverDID), + didPair.name + ) + : null + }, + /** + * Get a did pair (connection) by one of its dids + * @param did + * @returns [Domain.DIDPair](https://input-output-hk.github.io/atala-prism-wallet-sdk-ts/classes/Domain.DIDPair.html) + */ + async getPairByDID(did: SDK.Domain.DID): Promise { + const didPair = await this.db.collections.didpairs.findOne({ + selector: { + $or: [ + { + hostDID: did.toString() + }, + { + receiverDID: did.toString() + } + ] + } + }).exec() + return didPair + ? new SDK.Domain.DIDPair( + SDK.Domain.DID.fromString(didPair.hostDID), + SDK.Domain.DID.fromString(didPair.receiverDID), + didPair.name + ) + : null + } +} \ No newline at end of file diff --git a/packages/schemas/src/schemas/didpair/types.ts b/packages/schemas/src/schemas/didpair/types.ts new file mode 100644 index 00000000..69858ce8 --- /dev/null +++ b/packages/schemas/src/schemas/didpair/types.ts @@ -0,0 +1,25 @@ +import { RxDocument, KeyFunctionMap, RxCollection } from "rxdb" +import SDK from '@atala/prism-wallet-sdk' +import { StaticRxCollectionContext } from "../../types" + +export interface DIDPairSchemaType { + hostDID: string + receiverDID: string + name: string +} + + +export type DIDPairDocument = RxDocument + +export interface DIDPairStaticMethodTypes extends KeyFunctionMap { + storeDIDPair( + this: StaticRxCollectionContext<{ didpairs: DIDPairCollection }>, + host: SDK.Domain.DID, + receiver: SDK.Domain.DID, + name: string + ): Promise + getAllDidPairs(this: StaticRxCollectionContext<{ didpairs: DIDPairCollection }>,): Promise + getPairByName(this: StaticRxCollectionContext<{ didpairs: DIDPairCollection }>, name: string): Promise + getPairByDID(this: StaticRxCollectionContext<{ didpairs: DIDPairCollection }>, did: SDK.Domain.DID): Promise +} +export type DIDPairCollection = RxCollection diff --git a/packages/schemas/src/schemas/linksecret/index.ts b/packages/schemas/src/schemas/linksecret/index.ts new file mode 100644 index 00000000..c6864c03 --- /dev/null +++ b/packages/schemas/src/schemas/linksecret/index.ts @@ -0,0 +1,4 @@ +export * from './orm'; +export * from './schema'; +export * from './static'; +export * from './types'; \ No newline at end of file diff --git a/packages/schemas/src/schemas/linksecret/orm.ts b/packages/schemas/src/schemas/linksecret/orm.ts new file mode 100644 index 00000000..5a483192 --- /dev/null +++ b/packages/schemas/src/schemas/linksecret/orm.ts @@ -0,0 +1,10 @@ +import { LinkSecretDocument, LinkSecretMethodTypes } from "./types" + + + + +export const LinkSecretMethods: LinkSecretMethodTypes = { + toDomainLinkSecret: function toDomainLinkSecret(this: LinkSecretDocument) { + return this.secret + } +} \ No newline at end of file diff --git a/packages/schemas/src/schemas/linksecret/schema.ts b/packages/schemas/src/schemas/linksecret/schema.ts new file mode 100644 index 00000000..5b640616 --- /dev/null +++ b/packages/schemas/src/schemas/linksecret/schema.ts @@ -0,0 +1,19 @@ +import { Schema } from "../../types"; +import { LinkSecretSchemaType } from "./types"; + +export const LinkSecretSchema: Schema = { + version: 0, + primaryKey: 'name', + type: 'object', + properties: { + name: { + type: 'string', + maxLength: 60 + }, + secret: { + type: 'string' + } + }, + encrypted: ['secret'], + required: ['name', 'secret'] +} diff --git a/packages/schemas/src/schemas/linksecret/static.ts b/packages/schemas/src/schemas/linksecret/static.ts new file mode 100644 index 00000000..e921960a --- /dev/null +++ b/packages/schemas/src/schemas/linksecret/static.ts @@ -0,0 +1,31 @@ + +import { LinkSecretStaticMethodTypes } from "./types" + +export const LinkSecretStaticMethods: LinkSecretStaticMethodTypes = { + async storeLinkSecret( + linkSecret: string, + linkSecretName: string + ): Promise { + await this.db.collections.linksecrets.insert({ + name: linkSecretName, + secret: linkSecret + }) + }, + async getLinkSecret( + linkSecretName?: string | undefined + ): Promise { + const query = linkSecretName + ? { + selector: { + name: { + $eq: linkSecretName + } + } + } : {} + const linkSecret = await this.db.collections.linksecrets.findOne(query).exec() + if (linkSecret) { + return linkSecret.toDomainLinkSecret() + } + return null + } +} diff --git a/packages/schemas/src/schemas/linksecret/types.ts b/packages/schemas/src/schemas/linksecret/types.ts new file mode 100644 index 00000000..c30dc854 --- /dev/null +++ b/packages/schemas/src/schemas/linksecret/types.ts @@ -0,0 +1,41 @@ +import SDK from '@atala/prism-wallet-sdk' +import { RxDocument, KeyFunctionMap, RxCollection } from 'rxdb' +import { StaticRxCollectionContext } from '../../types' + + + + + +export interface LinkSecretSchemaType { + readonly name: string + readonly secret: string +} + + + +export type LinkSecretDocument = RxDocument< + LinkSecretSchemaType, + LinkSecretMethodTypes +> + +export interface LinkSecretMethodTypes extends KeyFunctionMap { + toDomainLinkSecret: (this: LinkSecretDocument) => SDK.Domain.Anoncreds.LinkSecret +} + +export interface LinkSecretStaticMethodTypes extends KeyFunctionMap { + storeLinkSecret( + this: StaticRxCollectionContext<{ linksecrets: LinkSecretColletion }>, + linkSecret: string, + linkSecretName: string + ): Promise + getLinkSecret( + this: StaticRxCollectionContext<{ linksecrets: LinkSecretColletion }>, + linkSecretName?: string | undefined + ): Promise +} + +export type LinkSecretColletion = RxCollection< + LinkSecretSchemaType, + LinkSecretMethodTypes, + LinkSecretStaticMethodTypes +> \ No newline at end of file diff --git a/packages/schemas/src/schemas/mediator/index.ts b/packages/schemas/src/schemas/mediator/index.ts new file mode 100644 index 00000000..c6864c03 --- /dev/null +++ b/packages/schemas/src/schemas/mediator/index.ts @@ -0,0 +1,4 @@ +export * from './orm'; +export * from './schema'; +export * from './static'; +export * from './types'; \ No newline at end of file diff --git a/packages/schemas/src/schemas/mediator/orm.ts b/packages/schemas/src/schemas/mediator/orm.ts new file mode 100644 index 00000000..e7f4249b --- /dev/null +++ b/packages/schemas/src/schemas/mediator/orm.ts @@ -0,0 +1,15 @@ + +import SDK from '@atala/prism-wallet-sdk' +import { MediatorMethodTypes, MediatorSchemaType } from './types' +import { RxDocument } from 'rxdb' + +export const MediatorMethods: MediatorMethodTypes = { + toDomainMediator: function toDomainMediator(this: RxDocument) { + const mediator = this.toJSON() + return { + hostDID: SDK.Domain.DID.fromString(mediator.hostDID), + routingDID: SDK.Domain.DID.fromString(mediator.routingDID), + mediatorDID: SDK.Domain.DID.fromString(mediator.mediatorDID) + } + } +} \ No newline at end of file diff --git a/packages/schemas/src/schemas/mediator/schema.ts b/packages/schemas/src/schemas/mediator/schema.ts new file mode 100644 index 00000000..5b097552 --- /dev/null +++ b/packages/schemas/src/schemas/mediator/schema.ts @@ -0,0 +1,30 @@ +import { Schema } from "../../types"; +import { MediatorSchemaType } from "./types"; + + + + +export const MediatorSchema: Schema = { + version: 0, + primaryKey: 'id', + type: 'object', + properties: { + id: { + type: 'string', + maxLength: 60 + }, + mediatorDID: { + type: 'string' + }, + hostDID: { + type: 'string' + }, + routingDID: { + type: 'string' + } + }, + encrypted: [], + required: ['id', 'mediatorDID'] +} + + diff --git a/packages/schemas/src/schemas/mediator/static.ts b/packages/schemas/src/schemas/mediator/static.ts new file mode 100644 index 00000000..664f0b4d --- /dev/null +++ b/packages/schemas/src/schemas/mediator/static.ts @@ -0,0 +1,24 @@ +import SDK from '@atala/prism-wallet-sdk' +import { v4 as uuidv4 } from 'uuid' + +import { MediatorStaticMethodTypes } from "./types" + +export const MediatorStaticMethods: MediatorStaticMethodTypes = { + async storeMediator( + mediator: SDK.Domain.DID, + host: SDK.Domain.DID, + routing: SDK.Domain.DID + ): Promise { + await this.db.collections.mediators.insert({ + id: uuidv4(), + mediatorDID: mediator.toString(), + hostDID: host.toString(), + routingDID: routing.toString() + }) + } + , + async getAllMediators(): Promise { + const mediators = await this.db.collections.mediators.find().exec() + return mediators.map((mediator) => mediator.toDomainMediator()) + } +} \ No newline at end of file diff --git a/packages/schemas/src/schemas/mediator/types.ts b/packages/schemas/src/schemas/mediator/types.ts new file mode 100644 index 00000000..b00047a1 --- /dev/null +++ b/packages/schemas/src/schemas/mediator/types.ts @@ -0,0 +1,32 @@ +import { KeyFunctionMap, RxCollection, RxDocument } from "rxdb" +import SDK from '@atala/prism-wallet-sdk' +import { StaticRxCollectionContext } from "../../types" + +export interface MediatorSchemaType { + id: string + mediatorDID: string + hostDID: string + routingDID: string +} + + + +export type MediatorDocument = RxDocument +export interface MediatorMethodTypes extends KeyFunctionMap { + toDomainMediator: (this: RxDocument) => SDK.Domain.Mediator +} + +export interface MediatorStaticMethodTypes extends KeyFunctionMap { + getAllMediators(this: StaticRxCollectionContext<{ mediators: MediatorCollection }>): Promise + storeMediator( + this: StaticRxCollectionContext<{ mediators: MediatorCollection }>, + mediator: SDK.Domain.DID, + host: SDK.Domain.DID, + routing: SDK.Domain.DID + ): Promise +} +export type MediatorCollection = RxCollection< + MediatorSchemaType, + MediatorMethodTypes, + MediatorStaticMethodTypes +> \ No newline at end of file diff --git a/packages/schemas/src/schemas/message/index.ts b/packages/schemas/src/schemas/message/index.ts new file mode 100644 index 00000000..c6864c03 --- /dev/null +++ b/packages/schemas/src/schemas/message/index.ts @@ -0,0 +1,4 @@ +export * from './orm'; +export * from './schema'; +export * from './static'; +export * from './types'; \ No newline at end of file diff --git a/packages/schemas/src/schemas/message/orm.ts b/packages/schemas/src/schemas/message/orm.ts new file mode 100644 index 00000000..ef992454 --- /dev/null +++ b/packages/schemas/src/schemas/message/orm.ts @@ -0,0 +1,10 @@ + +import SDK from '@atala/prism-wallet-sdk' +import { MessageDocument, MessageMethodTypes } from './types' + + +export const MessageMethods: MessageMethodTypes = { + toDomainMessage: function toDomainMessage(this: MessageDocument) { + return SDK.Domain.Message.fromJson(JSON.stringify(this)) + } +} \ No newline at end of file diff --git a/packages/schemas/src/schemas/message/schema.ts b/packages/schemas/src/schemas/message/schema.ts new file mode 100644 index 00000000..5826525f --- /dev/null +++ b/packages/schemas/src/schemas/message/schema.ts @@ -0,0 +1,88 @@ +import { Schema } from "../../types"; +import { MessageSchemaType } from "./types"; + +export const MessageSchema: Schema = { + version: 0, + primaryKey: 'id', + type: 'object', + properties: { + id: { + type: 'string', + maxLength: 60 + }, + body: { + type: 'string' + }, + piuri: { + type: 'string' + }, + attachments: { + type: 'array', + items: { + type: 'object', + properties: { + id: { + type: 'id', + maxLength: 60 + }, + description: { + type: 'string' + }, + byteCount: { + type: 'number' + }, + lastModTime: { + type: 'string' + }, + format: { + type: 'string' + }, + filename: { + type: 'array', + items: { + type: 'string' + } + }, + mediaType: { + type: 'string' + }, + data: { + type: 'object' + } + } + } + }, + extraHeaders: { + type: 'array' + }, + createdTime: { + type: 'string' + }, + expiresTimePlus: { + type: 'string' + }, + ack: { + type: 'array' + }, + direction: { + type: 'number' + }, + from: { + type: 'string' + }, + to: { + type: 'string' + }, + thid: { + type: 'string' + }, + fromPrior: { + type: 'string' + }, + pthid: { + type: 'string' + } + }, + encrypted: ['thid', 'attachments', 'body'], + required: ['id'] +} \ No newline at end of file diff --git a/packages/schemas/src/schemas/message/static.ts b/packages/schemas/src/schemas/message/static.ts new file mode 100644 index 00000000..38dbfcd4 --- /dev/null +++ b/packages/schemas/src/schemas/message/static.ts @@ -0,0 +1,192 @@ + +import SDK from '@atala/prism-wallet-sdk' +import { MessageSchemaType, MessageStaticMethodTypes } from './types' +import { MangoQuerySelector } from 'rxdb' + + +export const MessageStaticMethods: MessageStaticMethodTypes = { + async getAllMessagesByDID(did: SDK.Domain.DID): Promise { + const messages = await this.db.collections.messages.find({ + selector: { + $or: [ + { + to: did.toString() + }, + { + from: did.toString() + } + ] + } + }).exec() + + return messages.map((message) => message.toDomainMessage()) + }, + async getAllMessagesSent(): Promise { + const messages = await this.db.collections.messages.find({ + selector: { + $or: [ + { + direction: SDK.Domain.MessageDirection.SENT + } + ] + } + }).exec() + + return messages.map((message) => message.toDomainMessage()) + }, + async getAllMessagesReceived(): Promise { + const messages = await this.db.collections.messages.find({ + selector: { + $or: [ + { + direction: SDK.Domain.MessageDirection.RECEIVED + } + ] + } + }).exec() + + return messages.map((message) => message.toDomainMessage()) + }, + async getAllMessagesSentTo(did: SDK.Domain.DID): Promise { + const messages = await this.db.collections.messages.find({ + selector: { + $and: [ + { + to: did.toString() + }, + { + direction: SDK.Domain.MessageDirection.SENT + } + ] + } + }).exec() + return messages.map((message) => message.toDomainMessage()) + }, + async getAllMessagesReceivedFrom(did: SDK.Domain.DID): Promise { + const messages = await this.db.collections.messages.find({ + selector: { + $and: [ + { + from: did.toString() + }, + { + direction: SDK.Domain.MessageDirection.RECEIVED + } + ] + } + }).exec() + return messages.map((message) => message.toDomainMessage()) + }, + async getAllMessagesOfType( + type: string, + relatedWithDID?: SDK.Domain.DID | undefined + ): Promise { + const query: Array> = [ + { + piuri: type + } + ] + if (relatedWithDID) { + query.push({ + $or: [ + { + from: relatedWithDID.toString() + }, + { + to: relatedWithDID.toString() + } + ] + }) + } + const messages = await this.db.collections.messages.find({ + selector: { + $and: query + } + }).exec() + + return messages.map((message) => message.toDomainMessage()) + }, + async getAllMessagesByFromToDID( + from: SDK.Domain.DID, + to: SDK.Domain.DID + ): Promise { + const messages = await this.db.collections.messages.find({ + selector: { + $or: [ + { + from: from.toString() + }, + { + to: to.toString() + } + ] + } + }).exec() + + return messages.map((message) => message.toDomainMessage()) + } + , + /** + * Get all the stored messages + * @returns [Message[]](https://input-output-hk.github.io/atala-prism-wallet-sdk-ts/classes/Domain.Message.html) + */ + async getAllMessages(): Promise { + const messages = await this.db.collections.messages.find().exec() + return messages.map((message) => message.toDomainMessage()) + }, + /** + * Stores multiple messages in 1 call + * @param [Message[]](https://input-output-hk.github.io/atala-prism-wallet-sdk-ts/classes/Domain.Message.html) + * @returns void + */ + async storeMessages(messages: SDK.Domain.Message[]): Promise { + for (const message of messages) { + await this.storeMessage(message) + } + }, + /** + * Stores a message + * @param [Message](https://input-output-hk.github.io/atala-prism-wallet-sdk-ts/classes/Domain.Message.html) + * @returns void + */ + async storeMessage(message: SDK.Domain.Message): Promise { + const existing = await this.db.collections.messages.findOne({ + selector: { + id: { + $eq: message.id + } + } + }).exec() + if (existing) { + await existing.patch({ + ...message, + to: message.to?.toString(), + from: message.from?.toString() + }) + } else { + await this.db.collections.messages.insert({ + ...message, + to: message.to?.toString(), + from: message.from?.toString() + }) + } + }, + /** + * Get a Message by its id + * @param id + * @returns [Message](https://input-output-hk.github.io/atala-prism-wallet-sdk-ts/classes/Domain.Message.html) + */ + async getMessage(id: string): Promise { + const message = await this.db.collections.messages.findOne({ + selector: { + id: { + $eq: id + } + } + }).exec() + if (message) { + return message.toDomainMessage() + } + return null + } +} \ No newline at end of file diff --git a/packages/schemas/src/schemas/message/types.ts b/packages/schemas/src/schemas/message/types.ts new file mode 100644 index 00000000..dda360da --- /dev/null +++ b/packages/schemas/src/schemas/message/types.ts @@ -0,0 +1,103 @@ +import SDK from '@atala/prism-wallet-sdk' +import { RxDocument, KeyFunctionMap, RxCollection } from 'rxdb' +import { StaticRxCollectionContext } from '../../types' + + +export interface MessageSchemaType { + readonly body: string + readonly id: string + readonly piuri: string + readonly from?: string | undefined + readonly to?: string | undefined + readonly attachments: SDK.Domain.AttachmentDescriptor[] + readonly thid?: string + readonly extraHeaders: string[] + readonly createdTime: string + readonly expiresTimePlus: string + readonly ack: string[] + readonly direction: SDK.Domain.MessageDirection + readonly fromPrior?: string | undefined + readonly pthid?: string | undefined +} + +export type MessageDocument = RxDocument + +export interface MessageMethodTypes extends KeyFunctionMap { + toDomainMessage: ( + this: MessageDocument + ) => SDK.Domain.Message +} + +export interface MessageStaticMethodTypes extends KeyFunctionMap { + getMessage( + this: StaticRxCollectionContext<{ + messages: MessageColletion + }>, + id: string + ): Promise + storeMessage( + this: StaticRxCollectionContext<{ + messages: MessageColletion + }>, + message: SDK.Domain.Message + ): Promise + storeMessages( + this: StaticRxCollectionContext<{ + messages: MessageColletion + }>, + messages: SDK.Domain.Message[] + ): Promise + getAllMessages( + this: StaticRxCollectionContext<{ + messages: MessageColletion + }> + ): Promise + getAllMessagesByFromToDID( + this: StaticRxCollectionContext<{ + messages: MessageColletion + }>, + from: SDK.Domain.DID, + to: SDK.Domain.DID + ): Promise + getAllMessagesOfType( + this: StaticRxCollectionContext<{ + messages: MessageColletion + }>, + type: string, + relatedWithDID?: SDK.Domain.DID | undefined + ): Promise + getAllMessagesReceivedFrom( + this: StaticRxCollectionContext<{ + messages: MessageColletion + }>, + did: SDK.Domain.DID + ): Promise + getAllMessagesSentTo( + this: StaticRxCollectionContext<{ + messages: MessageColletion + }>, + did: SDK.Domain.DID + ): Promise + getAllMessagesReceived( + this: StaticRxCollectionContext<{ + messages: MessageColletion + }> + ): Promise + getAllMessagesSent( + this: StaticRxCollectionContext<{ + messages: MessageColletion + }> + ): Promise + getAllMessagesByDID( + this: StaticRxCollectionContext<{ + messages: MessageColletion + }>, + did: SDK.Domain.DID + ): Promise +} + +export type MessageColletion = RxCollection< + MessageSchemaType, + MessageMethodTypes, + MessageStaticMethodTypes +> \ No newline at end of file diff --git a/packages/schemas/src/schemas/privatekey/index.ts b/packages/schemas/src/schemas/privatekey/index.ts new file mode 100644 index 00000000..c6864c03 --- /dev/null +++ b/packages/schemas/src/schemas/privatekey/index.ts @@ -0,0 +1,4 @@ +export * from './orm'; +export * from './schema'; +export * from './static'; +export * from './types'; \ No newline at end of file diff --git a/packages/schemas/src/schemas/privatekey/orm.ts b/packages/schemas/src/schemas/privatekey/orm.ts new file mode 100644 index 00000000..776ee86d --- /dev/null +++ b/packages/schemas/src/schemas/privatekey/orm.ts @@ -0,0 +1,94 @@ +import SDK from '@atala/prism-wallet-sdk' +import { PrivateKeyDocument, PrivateKeyMethodTypes } from './types'; + +export const PrivateKeyMethods: PrivateKeyMethodTypes = { + toDomainPrivateKey: function toDomainPrivateKey(this: PrivateKeyDocument) { + const { type, keySpecification } = this + const curve = keySpecification.find( + (item) => item.name === SDK.KeyProperties.curve + ) + const raw = keySpecification.find( + (item) => item.name === SDK.KeyProperties.rawKey + ) + if (!(type in SDK.Domain.KeyTypes)) { + throw new Error(`Invalid KeyType ${type || 'undefined'}`) + } + if (!curve) { + throw new Error('Undefined key curve') + } + + if ( + curve.value !== SDK.Domain.Curve.SECP256K1 && + curve.value !== SDK.Domain.Curve.ED25519 && + curve.value !== SDK.Domain.Curve.X25519 + ) { + throw new Error(`Invalid key curve ${curve.value}`) + } + + if (!raw) { + throw new Error('Undefined key raw') + } + + /* istanbul ignore else -- @preserve */ + if (curve.value === SDK.Domain.Curve.SECP256K1) { + const index = keySpecification.find( + (item) => item.name === SDK.KeyProperties.index + ) + const seed = keySpecification.find( + (item) => item.name === SDK.KeyProperties.seed + ) + + const privateKey = new SDK.Secp256k1PrivateKey( + Buffer.from(raw.value, 'hex') + ) + + privateKey.keySpecification.set(SDK.Domain.KeyProperties.rawKey, raw.value) + + privateKey.keySpecification.set( + SDK.Domain.KeyProperties.curve, + SDK.Domain.Curve.SECP256K1 + ) + + if (index) { + privateKey.keySpecification.set( + SDK.Domain.KeyProperties.index, + index.value + ) + } + + if (seed) { + privateKey.keySpecification.set( + SDK.Domain.KeyProperties.seed, + seed.value + ) + } + + return privateKey + } else if (curve.value === SDK.Domain.Curve.ED25519) { + const privateKey = new SDK.Ed25519PrivateKey(Buffer.from(raw.value, 'hex')) + + privateKey.keySpecification.set(SDK.Domain.KeyProperties.rawKey, raw.value) + + privateKey.keySpecification.set( + SDK.Domain.KeyProperties.curve, + SDK.Domain.Curve.ED25519 + ) + + return privateKey + } else if (curve.value === SDK.Domain.Curve.X25519) { + const privateKey = new SDK.X25519PrivateKey(Buffer.from(raw.value, 'hex')) + + privateKey.keySpecification.set(SDK.Domain.KeyProperties.rawKey, raw.value) + + privateKey.keySpecification.set( + SDK.Domain.KeyProperties.curve, + SDK.Domain.Curve.X25519 + ) + + return privateKey + } else { + /* istanbul ignore next -- @preserve */ + throw new Error(`Invalid key ${curve.value} ${type}`) + } + } +} \ No newline at end of file diff --git a/packages/schemas/src/schemas/privatekey/schema.ts b/packages/schemas/src/schemas/privatekey/schema.ts new file mode 100644 index 00000000..a0352c2e --- /dev/null +++ b/packages/schemas/src/schemas/privatekey/schema.ts @@ -0,0 +1,41 @@ +import { Schema } from "../../types"; +import { KeySchemaType } from "./types"; + + + +export const PrivateKeySchema: Schema = { + version: 0, + primaryKey: 'id', + type: 'object', + properties: { + id: { + type: 'string', + maxLength: 60 + }, + did: { + type: 'string' + }, + type: { + type: 'string' + }, + keySpecification: { + type: 'array', + items: { + type: 'object', + properties: { + name: { + type: 'string' + }, + type: { + type: 'string' + }, + value: { + type: 'string' + } + } + } + } + }, + encrypted: ['keySpecification', 'type'], + required: ['keySpecification', 'did', 'type', 'id'] +} \ No newline at end of file diff --git a/packages/schemas/src/schemas/privatekey/static.ts b/packages/schemas/src/schemas/privatekey/static.ts new file mode 100644 index 00000000..9f8287fe --- /dev/null +++ b/packages/schemas/src/schemas/privatekey/static.ts @@ -0,0 +1,68 @@ +import SDK from '@atala/prism-wallet-sdk' +import { v4 as uuidv4 } from 'uuid' +import { KeySpec, PrivateKeyStaticMethodTypes } from './types' + +export const PrivateKeyStaticMethods: PrivateKeyStaticMethodTypes = { + /** + * Stores privateKeys references to an existing DID + * @param privateKey + * @param did + * @param keyPathIndex + * @param _metaId + */ + async storePrivateKeys( + privateKey: SDK.Domain.PrivateKey, + did: SDK.Domain.DID, + keyPathIndex: number + ): Promise { + await this.db.collections.privatekeys.insert({ + id: uuidv4(), + did: did.toString(), + type: privateKey.type, + keySpecification: Array.from(privateKey.keySpecification).reduce( + (all, [key, value]) => [ + ...all, + { + type: 'string', + name: key, + value: `${value}` + } + ], + [ + { + type: 'string', + name: 'raw', + value: Buffer.from(privateKey.raw).toString('hex') + }, + { + type: 'number', + name: 'index', + value: `${keyPathIndex}` + } + ] + ) + }) + }, + async getDIDPrivateKeysByDID(did: SDK.Domain.DID): Promise { + const privateKeys = await this.db.collections.privatekeys.find({ + selector: { + did: { + $eq: did.toString() + } + } + }).exec() + return privateKeys.map((privateKey) => { + return privateKey.toDomainPrivateKey() + }) + }, + async getDIDPrivateKeyByID(id: string): Promise { + const privateKey = await this.db.collections.privatekeys.findOne({ + selector: { + id: { + $eq: id + } + } + }).exec() + return privateKey ? privateKey.toDomainPrivateKey() : null + } +} \ No newline at end of file diff --git a/packages/schemas/src/schemas/privatekey/types.ts b/packages/schemas/src/schemas/privatekey/types.ts new file mode 100644 index 00000000..5aa515dc --- /dev/null +++ b/packages/schemas/src/schemas/privatekey/types.ts @@ -0,0 +1,51 @@ +import SDK from '@atala/prism-wallet-sdk' +import { KeyFunctionMap, RxCollection, RxDocument } from 'rxdb' +import { StaticRxCollectionContext } from '../../types' + +export interface KeySpec { + name: string + type: string + value: string +} + +export interface KeySchemaType { + id: string + type: string + did: string + keySpecification: KeySpec[] +} + +export interface PrivateKeyMethodTypes extends KeyFunctionMap { + toDomainPrivateKey: (this: PrivateKeyDocument) => SDK.Domain.PrivateKey +} + +export interface PrivateKeyStaticMethodTypes extends KeyFunctionMap { + storePrivateKeys( + this: StaticRxCollectionContext<{ privatekeys: PrivateKeyColletion }>, + privateKey: SDK.Domain.PrivateKey, + did: SDK.Domain.DID, + keyPathIndex: number + ): Promise + getDIDPrivateKeysByDID( + this: StaticRxCollectionContext<{ + privatekeys: PrivateKeyColletion + }>, + did: SDK.Domain.DID + ): Promise + getDIDPrivateKeyByID( + this: StaticRxCollectionContext<{ + privatekeys: PrivateKeyColletion + }>, + id: string + ): Promise +} + +export type PrivateKeyColletion = RxCollection< + KeySchemaType, + PrivateKeyMethodTypes, + PrivateKeyStaticMethodTypes +> +export type PrivateKeyDocument = RxDocument< + KeySchemaType, + PrivateKeyMethodTypes +> \ No newline at end of file diff --git a/packages/schemas/src/types.ts b/packages/schemas/src/types.ts new file mode 100644 index 00000000..74d67dcb --- /dev/null +++ b/packages/schemas/src/types.ts @@ -0,0 +1,57 @@ +import SDK from '@atala/prism-wallet-sdk' + +import { + CollectionsOfDatabase, + RxCollection, + RxCollectionCreator, + RxDatabase, + RxDatabaseCreator, + RxDumpDatabase, + RxJsonSchema, + RxStorage +} from "rxdb" + +import { CredentialCollection } from "./schemas/credential" +import { DIDPairCollection } from "./schemas/didpair" + +import { MediatorCollection } from "./schemas/mediator" +import { LinkSecretColletion } from "./schemas/linksecret" +import { DIDCollection } from "./schemas/did" +import { CredentialRequestMetadataCollection } from "./schemas/credentialRequestMetadata" + + +import { MessageColletion } from "./schemas/message" +import { PrivateKeyColletion } from "./schemas/privatekey" +import { DatabaseBase } from '@pluto-encrypted/shared' + +export type ValuesOf = T[keyof T] +export type Schema = RxJsonSchema & { + encrypted: Array +} + +export interface PlutoCollections { + messages: MessageColletion + dids: DIDCollection + didpairs: DIDPairCollection + mediators: MediatorCollection + privatekeys: PrivateKeyColletion + credentials: CredentialCollection + credentialrequestmetadatas: CredentialRequestMetadataCollection + linksecrets: LinkSecretColletion +} +export interface PlutoCollectionsCreator { + messages: RxCollectionCreator + dids: RxCollectionCreator + didpairs: RxCollectionCreator + mediators: RxCollectionCreator + privatekeys: RxCollectionCreator + credentials: RxCollectionCreator + credentialrequestmetadatas: RxCollectionCreator + linksecrets: RxCollectionCreator +} + +export type PlutoInstance< + Collections = CollectionsOfDatabase, +> = DatabaseBase & SDK.Domain.Pluto +export type DBOptions = RxDatabaseCreator; +export type StaticRxCollectionContext = PlutoInstance diff --git a/packages/schemas/tsconfig.json b/packages/schemas/tsconfig.json new file mode 100644 index 00000000..41c8ed49 --- /dev/null +++ b/packages/schemas/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../../tsconfig.json", + "compilerOptions": { + "rootDir": "./src", + "declarationDir": "./build", + }, + "include": [ + "src" + ] +} diff --git a/packages/schemas/vitest.config.ts b/packages/schemas/vitest.config.ts new file mode 100644 index 00000000..16c4c803 --- /dev/null +++ b/packages/schemas/vitest.config.ts @@ -0,0 +1,28 @@ +/// +import { defineConfig } from 'vite' + +const isCI = process.env.CI === "true"; + +export default defineConfig({ + build: { + minify: 'terser', + terserOptions: { format: { comments: 'all' } }, + }, + test: { + reporters: ['verbose'], // or 'verbose' + coverage: { + provider: 'istanbul', + reporter: isCI ? ['json-summary'] : ['json-summary', "html"], + thresholds: { + branches: 95, + functions: 95, + lines: 95, + statements: 95 + }, + include: [ + 'src/**/*', + ], + }, + + } +}) diff --git a/packages/shared/package.json b/packages/shared/package.json index e5a5143e..4141a1d0 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -1,6 +1,6 @@ { "name": "@pluto-encrypted/shared", - "version": "1.9.3", + "version": "2.0.0-rc.3", "description": "Shared depencencies for @pluto-encrypted and its db providers", "main": "./build/cjs/index.cjs", "module": "./build/esm/index.mjs", @@ -28,7 +28,8 @@ "license": "Apache-2.0", "dependencies": { "rxdb": "^14.17.0", - "uuid": "^9.0.1" + "uuid": "^9.0.1", + "@pluto-encrypted/encryption": "1.10.0-rc.1" }, "files": [ "build/*" diff --git a/packages/shared/src/index.ts b/packages/shared/src/index.ts index e68507aa..3d9cb022 100644 --- a/packages/shared/src/index.ts +++ b/packages/shared/src/index.ts @@ -5,7 +5,10 @@ * @description Shared is used by other dependencies of pluto-encrypted to reduce code duplication. * */ -import { type MangoQuerySelector, type RxDocumentData, type RxJsonSchema } from 'rxdb' +import { RxDBEncryptedMigrationPlugin } from '@pluto-encrypted/encryption' +import { RxDBJsonDumpPlugin } from 'rxdb/plugins/json-dump' +import { RxDBQueryBuilderPlugin } from 'rxdb/plugins/query-builder' +import { CollectionsOfDatabase, RxCollectionCreator, addRxPlugin, createRxDatabase, removeRxDatabase, type MangoQuerySelector, type RxDocumentData, type RxJsonSchema, RxDatabase, RxDatabaseCreator, RxDumpDatabase, RxStorage } from 'rxdb' export type { RxDocumentMeta, PlainJsonValue, PropertyType, PlainSimpleJsonObject } from 'rxdb/dist/types/types' export type { MangoQuerySelector, RxAttachmentDataBase, MangoQueryOperators, RxDocumentData, RxAttachmentData } from 'rxdb' @@ -234,3 +237,66 @@ export function getPrivateKeyValue(document: RxDocumentData = T[keyof T] +export type DBOptions = RxDatabaseCreator; + + +export class DatabaseBase { + private _db!: RxDatabase + + get db() { + if (!this._db) { + throw new Error('Start Pluto first.') + } + return this._db + } + + getCollection(name: string) { + if (!this.db.collections[name]) { + throw new Error("Collection does not exist") + } + return this.db.collections[name] + } + + constructor( + private readonly dbOptions: DBOptions + ) { + addRxPlugin(RxDBQueryBuilderPlugin) + addRxPlugin(RxDBJsonDumpPlugin) + addRxPlugin(RxDBEncryptedMigrationPlugin) + } + + async backup() { + return await this.db.exportJSON() + } + + /** + * Use with caution, this will remove all entries from database + * and then destroy the database itself. + */ + async clear() { + const storages = Array.from(this.db.storageInstances.values()) + for (const storage of storages) { + await storage.cleanup(Infinity) + } + await removeRxDatabase(this.dbOptions.name, this.db.storage) + } + + /** + * Start the database and build collections + */ + async start(collections?: { + [name: string]: RxCollectionCreator + }): Promise { + const { dbOptions } = this + const database = await createRxDatabase({ + ...dbOptions, + multiInstance: false + }) + const extendedCollections = collections ? collections : {}; + await database.addCollections(extendedCollections); + + this._db = database + } +} \ No newline at end of file diff --git a/packages/test-suite/package.json b/packages/test-suite/package.json index 5c01ee35..cb51222f 100644 --- a/packages/test-suite/package.json +++ b/packages/test-suite/package.json @@ -1,6 +1,6 @@ { "name": "@pluto-encrypted/test-suite", - "version": "1.9.4", + "version": "1.10.0-rc.1", "description": "This is a test-suite that works out of the box without cloning rxdb repo or submodule, it does not support replication!!", "main": "./build/cjs/index.cjs", "module": "./build/esm/index.mjs", diff --git a/packages/test-suite/src/index.ts b/packages/test-suite/src/index.ts index 3ee81879..acaacc51 100644 --- a/packages/test-suite/src/index.ts +++ b/packages/test-suite/src/index.ts @@ -1,4 +1,5 @@ /** + * * @packageDocumentation * @module test-suite * @description This package can be used as a compliance test to validate a new storage created by you or the community.