From 876634f93f1201edc8dc21daeb0f0ef00c3e0487 Mon Sep 17 00:00:00 2001 From: mixmix Date: Fri, 14 Jun 2024 10:13:07 +1200 Subject: [PATCH] rm databases,iagon --- packages/database/.gitignore | 10 - packages/database/CHANGELOG.md | 501 ------- packages/database/LICENSE | 201 --- packages/database/README.md | 115 -- .../database/coverage/coverage-summary.json | 3 - packages/database/package.json | 66 - packages/database/rollup/rollup.mjs | 5 - packages/database/src/index.ts | 119 -- packages/database/src/types.ts | 26 - packages/database/tests/fixtures.ts | 217 --- packages/database/tests/pluto.test.ts | 1263 ----------------- packages/database/tests/setup.ts | 18 - packages/database/tsconfig.json | 10 - packages/database/vitest.config.ts | 28 - packages/iagon/.gitignore | 4 - packages/iagon/CHANGELOG.md | 9 - packages/iagon/LICENSE | 201 --- packages/iagon/README.md | 5 - packages/iagon/coverage/.tmp/coverage-0.json | 1 - packages/iagon/package.json | 47 - packages/iagon/rollup/rollup.mjs | 5 - packages/iagon/src/IagonStorage/api.ts | 196 --- packages/iagon/src/IagonStorage/index.ts | 65 - packages/iagon/src/IagonStorage/instance.ts | 244 ---- packages/iagon/src/IagonStorage/internals.ts | 183 --- packages/iagon/src/IagonStorage/types.ts | 72 - packages/iagon/src/index.ts | 5 - packages/iagon/tests/init.test.ts | 42 - packages/iagon/tests/setup.ts | 17 - packages/iagon/tsconfig.json | 10 - packages/iagon/vitest.config.ts | 30 - 31 files changed, 3718 deletions(-) delete mode 100644 packages/database/.gitignore delete mode 100644 packages/database/CHANGELOG.md delete mode 100644 packages/database/LICENSE delete mode 100644 packages/database/README.md delete mode 100644 packages/database/coverage/coverage-summary.json delete mode 100644 packages/database/package.json delete mode 100644 packages/database/rollup/rollup.mjs delete mode 100644 packages/database/src/index.ts delete mode 100644 packages/database/src/types.ts delete mode 100644 packages/database/tests/fixtures.ts delete mode 100644 packages/database/tests/pluto.test.ts delete mode 100644 packages/database/tests/setup.ts delete mode 100644 packages/database/tsconfig.json delete mode 100644 packages/database/vitest.config.ts delete mode 100644 packages/iagon/.gitignore delete mode 100644 packages/iagon/CHANGELOG.md delete mode 100644 packages/iagon/LICENSE delete mode 100644 packages/iagon/README.md delete mode 100644 packages/iagon/coverage/.tmp/coverage-0.json delete mode 100644 packages/iagon/package.json delete mode 100644 packages/iagon/rollup/rollup.mjs delete mode 100644 packages/iagon/src/IagonStorage/api.ts delete mode 100644 packages/iagon/src/IagonStorage/index.ts delete mode 100644 packages/iagon/src/IagonStorage/instance.ts delete mode 100644 packages/iagon/src/IagonStorage/internals.ts delete mode 100644 packages/iagon/src/IagonStorage/types.ts delete mode 100644 packages/iagon/src/index.ts delete mode 100644 packages/iagon/tests/init.test.ts delete mode 100644 packages/iagon/tests/setup.ts delete mode 100644 packages/iagon/tsconfig.json delete mode 100644 packages/iagon/vitest.config.ts diff --git a/packages/database/.gitignore b/packages/database/.gitignore deleted file mode 100644 index 37d9a7e8..00000000 --- a/packages/database/.gitignore +++ /dev/null @@ -1,10 +0,0 @@ -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/database/CHANGELOG.md b/packages/database/CHANGELOG.md deleted file mode 100644 index 01a23fe1..00000000 --- a/packages/database/CHANGELOG.md +++ /dev/null @@ -1,501 +0,0 @@ -## @pluto-encrypted/database [1.15.6](https://github.com/atala-community-projects/pluto-encrypted/compare/@pluto-encrypted/database@1.15.5...@pluto-encrypted/database@1.15.6) (2024-02-23) - - - - - -### Dependencies - -* **@pluto-encrypted/inmemory:** upgraded to 1.12.3 - -## @pluto-encrypted/database [1.15.5](https://github.com/atala-community-projects/pluto-encrypted/compare/@pluto-encrypted/database@1.15.4...@pluto-encrypted/database@1.15.5) (2024-02-10) - - -### Bug Fixes - -* release db ([1e43c7c](https://github.com/atala-community-projects/pluto-encrypted/commit/1e43c7cf82dce2a5eea21af6b952da55b4ba0bf9)) - -## @pluto-encrypted/database [1.15.4](https://github.com/atala-community-projects/pluto-encrypted/compare/@pluto-encrypted/database@1.15.3...@pluto-encrypted/database@1.15.4) (2024-02-10) - - -### Bug Fixes - -* database and schemas fix for last key index for prism did keys. ([b88fa6e](https://github.com/atala-community-projects/pluto-encrypted/commit/b88fa6ed71a6f44da48129bf5bd7a5222b8d000f)) - -## @pluto-encrypted/database [1.15.3](https://github.com/atala-community-projects/pluto-encrypted/compare/@pluto-encrypted/database@1.15.2...@pluto-encrypted/database@1.15.3) (2024-02-08) - - -### Bug Fixes - -* improve coverage ([9de11a9](https://github.com/atala-community-projects/pluto-encrypted/commit/9de11a9095b6a4c232f78108bea5b3059b591e29)) -* Upgrade SDK to latest version which contains a fix to deserialize the JWT Credential from JTI String. ([e9aa761](https://github.com/atala-community-projects/pluto-encrypted/commit/e9aa7610f263fbe7aecf9786e42a1840c2b9a18d)) - - - - - -### Dependencies - -* **@pluto-encrypted/indexdb:** upgraded to 1.12.2 -* **@pluto-encrypted/inmemory:** upgraded to 1.12.2 -* **@pluto-encrypted/leveldb:** upgraded to 1.12.2 - -## @pluto-encrypted/database [1.13.3](https://github.com/atala-community-projects/pluto-encrypted/compare/@pluto-encrypted/database@1.13.2...@pluto-encrypted/database@1.13.3) (2024-01-10) - - -### Bug Fixes - -* databse fix ([a76aa4a](https://github.com/atala-community-projects/pluto-encrypted/commit/a76aa4ae63fcedce24a56b2803b9a15258ed8895)) - -## @pluto-encrypted/database [1.11.1](https://github.com/atala-community-projects/pluto-encrypted/compare/@pluto-encrypted/database@1.11.0...@pluto-encrypted/database@1.11.1) (2024-01-05) - - -### Bug Fixes - -* port changes ([#73](https://github.com/atala-community-projects/pluto-encrypted/issues/73)) ([d225f3b](https://github.com/atala-community-projects/pluto-encrypted/commit/d225f3b7de907fb6932faff1e7dda4b31d10f6cd)) - -# @pluto-encrypted/database [1.11.0](https://github.com/atala-community-projects/pluto-encrypted/compare/@pluto-encrypted/database@1.10.4...@pluto-encrypted/database@1.11.0) (2024-01-05) - - -### Features - -* database docs update. ([cdd1b8e](https://github.com/atala-community-projects/pluto-encrypted/commit/cdd1b8ed4cd6591919e921b4479b01020b5cdbbd)) - -## @pluto-encrypted/database [1.10.4](https://github.com/atala-community-projects/pluto-encrypted/compare/@pluto-encrypted/database@1.10.3...@pluto-encrypted/database@1.10.4) (2024-01-05) - - - - - -### Dependencies - -* **@pluto-encrypted/indexdb:** upgraded to 1.9.4 -* **@pluto-encrypted/inmemory:** upgraded to 1.9.4 -* **@pluto-encrypted/leveldb:** upgraded to 1.9.4 - -## @pluto-encrypted/database [1.10.3](https://github.com/atala-community-projects/pluto-encrypted/compare/@pluto-encrypted/database@1.10.2...@pluto-encrypted/database@1.10.3) (2024-01-05) - - -### Bug Fixes - -* packages docs ([6f5c375](https://github.com/atala-community-projects/pluto-encrypted/commit/6f5c375f198ac4fb09aa6f15af08881e779a7b0d)) - - - - - -### Dependencies - -* **@pluto-encrypted/encryption:** upgraded to 1.9.3 -* **@pluto-encrypted/indexdb:** upgraded to 1.9.3 -* **@pluto-encrypted/inmemory:** upgraded to 1.9.3 -* **@pluto-encrypted/leveldb:** upgraded to 1.9.3 - -## @pluto-encrypted/database [1.10.2](https://github.com/atala-community-projects/pluto-encrypted/compare/@pluto-encrypted/database@1.10.1...@pluto-encrypted/database@1.10.2) (2024-01-05) - - -### Bug Fixes - -* minor change ([#72](https://github.com/atala-community-projects/pluto-encrypted/issues/72)) ([6895b35](https://github.com/atala-community-projects/pluto-encrypted/commit/6895b35c5f144a4a5282e8afdba8f796837a9bfa)) - - - - - -### Dependencies - -* **@pluto-encrypted/encryption:** upgraded to 1.9.2 -* **@pluto-encrypted/indexdb:** upgraded to 1.9.2 -* **@pluto-encrypted/inmemory:** upgraded to 1.9.2 -* **@pluto-encrypted/leveldb:** upgraded to 1.9.2 - -## @pluto-encrypted/database [1.10.1](https://github.com/atala-community-projects/pluto-encrypted/compare/@pluto-encrypted/database@1.10.0...@pluto-encrypted/database@1.10.1) (2024-01-05) - - -### Bug Fixes - -* pkg author email change. ([1550d5f](https://github.com/atala-community-projects/pluto-encrypted/commit/1550d5f968caac92add817fb79716a6a54ab4bc3)) - - - - - -### Dependencies - -* **@pluto-encrypted/encryption:** upgraded to 1.9.1 -* **@pluto-encrypted/indexdb:** upgraded to 1.9.1 -* **@pluto-encrypted/inmemory:** upgraded to 1.9.1 -* **@pluto-encrypted/leveldb:** upgraded to 1.9.1 - -# @pluto-encrypted/database [1.10.0](https://github.com/atala-community-projects/pluto-encrypted/compare/@pluto-encrypted/database@1.9.0...@pluto-encrypted/database@1.10.0) (2024-01-05) - - -### Features - -* packages ([88e569b](https://github.com/atala-community-projects/pluto-encrypted/commit/88e569b05129d1b0f586f5aded5d8dd645cd285f)) - - - - - -### Dependencies - -* **@pluto-encrypted/encryption:** upgraded to 1.9.0 -* **@pluto-encrypted/indexdb:** upgraded to 1.9.0 -* **@pluto-encrypted/inmemory:** upgraded to 1.9.0 -* **@pluto-encrypted/leveldb:** upgraded to 1.9.0 - -## @pluto-encrypted/database [1.2.15](https://github.com/atala-community-projects/pluto-encrypted/compare/@pluto-encrypted/database@1.2.14...@pluto-encrypted/database@1.2.15) (2024-01-04) - - -### Bug Fixes - -* encrypted change in docs ([#69](https://github.com/atala-community-projects/pluto-encrypted/issues/69)) ([eebfacd](https://github.com/atala-community-projects/pluto-encrypted/commit/eebfacd3b0536600d77e0517a7eb8775826baa82)) - - - - - -### Dependencies - -* **@pluto-encrypted/encryption:** upgraded to 1.2.9 -* **@pluto-encrypted/indexdb:** upgraded to 1.3.12 -* **@pluto-encrypted/inmemory:** upgraded to 1.3.12 -* **@pluto-encrypted/leveldb:** upgraded to 1.3.12 - -## @pluto-encrypted/database [1.2.15-rc.1](https://github.com/atala-community-projects/pluto-encrypted/compare/@pluto-encrypted/database@1.2.14...@pluto-encrypted/database@1.2.15-rc.1) (2024-01-04) - - - - - -### Dependencies - -* **@pluto-encrypted/encryption:** upgraded to 1.2.9-rc.1 -* **@pluto-encrypted/indexdb:** upgraded to 1.3.12-rc.1 -* **@pluto-encrypted/inmemory:** upgraded to 1.3.12-rc.1 -* **@pluto-encrypted/leveldb:** upgraded to 1.3.12-rc.1 - -## @pluto-encrypted/database [1.2.14](https://github.com/atala-community-projects/pluto-encrypted/compare/@pluto-encrypted/database@1.2.13...@pluto-encrypted/database@1.2.14) (2024-01-03) - - - - - -### Dependencies - -* **@pluto-encrypted/indexdb:** upgraded to 1.3.11 -* **@pluto-encrypted/inmemory:** upgraded to 1.3.11 -* **@pluto-encrypted/leveldb:** upgraded to 1.3.11 - -## @pluto-encrypted/database [1.2.13](https://github.com/atala-community-projects/pluto-encrypted/compare/@pluto-encrypted/database@1.2.12...@pluto-encrypted/database@1.2.13) (2024-01-03) - - - - - -### Dependencies - -* **@pluto-encrypted/indexdb:** upgraded to 1.3.10 -* **@pluto-encrypted/inmemory:** upgraded to 1.3.10 -* **@pluto-encrypted/leveldb:** upgraded to 1.3.10 - -## @pluto-encrypted/database [1.2.12](https://github.com/atala-community-projects/pluto-encrypted/compare/@pluto-encrypted/database@1.2.11...@pluto-encrypted/database@1.2.12) (2024-01-03) - - - - - -### Dependencies - -* **@pluto-encrypted/indexdb:** upgraded to 1.3.9 -* **@pluto-encrypted/inmemory:** upgraded to 1.3.9 -* **@pluto-encrypted/leveldb:** upgraded to 1.3.9 - -## @pluto-encrypted/database [1.2.11](https://github.com/atala-community-projects/pluto-encrypted/compare/@pluto-encrypted/database@1.2.10...@pluto-encrypted/database@1.2.11) (2024-01-02) - - -### Bug Fixes - -* package updates and ci ([fb13bb7](https://github.com/atala-community-projects/pluto-encrypted/commit/fb13bb7942568b50b41f0c777fb1173bcd63dd3b)) -* release changes ([781915c](https://github.com/atala-community-projects/pluto-encrypted/commit/781915ccd4443bae3b8716de76929aaf1af3cd3e)) -* versions ([1bf0e2d](https://github.com/atala-community-projects/pluto-encrypted/commit/1bf0e2dbc9fb388f90c494858019af0ac29681da)) - - - - - -### Dependencies - -* **@pluto-encrypted/indexdb:** upgraded to 1.3.8 -* **@pluto-encrypted/inmemory:** upgraded to 1.3.8 -* **@pluto-encrypted/leveldb:** upgraded to 1.3.8 - -## @pluto-encrypted/database [1.2.9](https://github.com/atala-community-projects/pluto-encrypted/compare/@pluto-encrypted/database@1.2.8...@pluto-encrypted/database@1.2.9) (2024-01-01) - - -### Bug Fixes - -* add homepage to all npm packages. ([f0dcd0a](https://github.com/atala-community-projects/pluto-encrypted/commit/f0dcd0a90ff8cf5278de1158a6e90298d25d43c4)) - - - - - -### Dependencies - -* **@pluto-encrypted/indexdb:** upgraded to 1.3.6 -* **@pluto-encrypted/inmemory:** upgraded to 1.3.6 -* **@pluto-encrypted/leveldb:** upgraded to 1.3.6 - -## @pluto-encrypted/database [1.2.8](https://github.com/atala-community-projects/pluto-encrypted/compare/@pluto-encrypted/database@1.2.7...@pluto-encrypted/database@1.2.8) (2024-01-01) - - -### Bug Fixes - -* replace npm package repositories. ([c7c4bb9](https://github.com/atala-community-projects/pluto-encrypted/commit/c7c4bb9e5ab55762ac44bc9caa1b98094088647d)) - - - - - -### Dependencies - -* **@pluto-encrypted/indexdb:** upgraded to 1.3.5 -* **@pluto-encrypted/inmemory:** upgraded to 1.3.5 -* **@pluto-encrypted/leveldb:** upgraded to 1.3.5 - -## @pluto-encrypted/database [1.2.7](https://github.com/elribonazo/pluto-encrypted/compare/@pluto-encrypted/database@1.2.6...@pluto-encrypted/database@1.2.7) (2023-12-23) - - -### Bug Fixes - -* add higher test coverage for storages. ([#68](https://github.com/elribonazo/pluto-encrypted/issues/68)) ([f15979f](https://github.com/elribonazo/pluto-encrypted/commit/f15979fff3c58f04d0eb617eda3a5eb677b1dfa1)) - - - - - -### Dependencies - -* **@pluto-encrypted/indexdb:** upgraded to 1.3.4 -* **@pluto-encrypted/inmemory:** upgraded to 1.3.4 -* **@pluto-encrypted/leveldb:** upgraded to 1.3.4 - -## @pluto-encrypted/database [1.2.6](https://github.com/elribonazo/pluto-encrypted/compare/@pluto-encrypted/database@1.2.5...@pluto-encrypted/database@1.2.6) (2023-12-23) - - -### Bug Fixes - -* docs improvement. ([16f4d56](https://github.com/elribonazo/pluto-encrypted/commit/16f4d569e08e67f3130deee413bb9717b11c2889)) - -## @pluto-encrypted/database [1.2.4](https://github.com/elribonazo/pluto-encrypted/compare/@pluto-encrypted/database@1.2.3...@pluto-encrypted/database@1.2.4) (2023-12-23) - - -### Bug Fixes - -* Improve test coverage for test-suite with most of the needed fea… ([#66](https://github.com/elribonazo/pluto-encrypted/issues/66)) ([b90e406](https://github.com/elribonazo/pluto-encrypted/commit/b90e40670e82808f38b880456ccc0c5505b48757)) - - - - - -### Dependencies - -* **@pluto-encrypted/indexdb:** upgraded to 1.3.2 -* **@pluto-encrypted/inmemory:** upgraded to 1.3.2 -* **@pluto-encrypted/leveldb:** upgraded to 1.3.2 - -## @pluto-encrypted/database [1.2.2](https://github.com/elribonazo/pluto-encrypted/compare/@pluto-encrypted/database@1.2.1...@pluto-encrypted/database@1.2.2) (2023-12-23) - - -### Bug Fixes - -* Correct coverage on all 3 packages ([e18a707](https://github.com/elribonazo/pluto-encrypted/commit/e18a707b49784b6eace13aaa69e8d4fd4526626b)) - - - - - -### Dependencies - -* **@pluto-encrypted/indexdb:** upgraded to 1.3.1 -* **@pluto-encrypted/inmemory:** upgraded to 1.3.1 -* **@pluto-encrypted/leveldb:** upgraded to 1.3.1 - -## @pluto-encrypted/database [1.2.1](https://github.com/elribonazo/pluto-encrypted/compare/@pluto-encrypted/database@1.2.0...@pluto-encrypted/database@1.2.1) (2023-12-23) - - -### Bug Fixes - -* add missing code coverage. ([#65](https://github.com/elribonazo/pluto-encrypted/issues/65)) ([e3ded9a](https://github.com/elribonazo/pluto-encrypted/commit/e3ded9a5a30b01c37d0d42102bc9f03ce8b21f69)) - -## @pluto-encrypted/database [1.1.1](https://github.com/elribonazo/pluto-encrypted/compare/@pluto-encrypted/database@1.1.0...@pluto-encrypted/database@1.1.1) (2023-12-19) - - - - - -### Dependencies - -* **@pluto-encrypted/inmemory:** upgraded to 1.2.1 - -# @pluto-encrypted/database [1.1.0](https://github.com/elribonazo/pluto-encrypted/compare/@pluto-encrypted/database@1.0.23...@pluto-encrypted/database@1.1.0) (2023-12-19) - - -### Features - -* **migrations:** Support migrations across all encrypted storages supported by pluto encrypted ([#63](https://github.com/elribonazo/pluto-encrypted/issues/63)) ([6b609df](https://github.com/elribonazo/pluto-encrypted/commit/6b609df8cf893a269fc0c1f8026db0caa6098ac5)) - - - - - -### Dependencies - -* **@pluto-encrypted/indexdb:** upgraded to 1.2.0 -* **@pluto-encrypted/inmemory:** upgraded to 1.2.0 -* **@pluto-encrypted/leveldb:** upgraded to 1.2.0 - -## @pluto-encrypted/database [1.0.23](https://github.com/elribonazo/pluto-encrypted/compare/@pluto-encrypted/database@1.0.22...@pluto-encrypted/database@1.0.23) (2023-12-19) - - - - - -### Dependencies - -* **@pluto-encrypted/leveldb:** upgraded to 1.1.8 - -## @pluto-encrypted/database [1.0.19](https://github.com/elribonazo/pluto-encrypted/compare/@pluto-encrypted/database@1.0.18...@pluto-encrypted/database@1.0.19) (2023-12-18) - - -### Bug Fixes - -* Improve all package documentation ([2602af4](https://github.com/elribonazo/pluto-encrypted/commit/2602af4f37f97eb2f70d39d79eb3c3e715e7cead)) - - - - - -### Dependencies - -* **@pluto-encrypted/indexdb:** upgraded to 1.1.8 -* **@pluto-encrypted/inmemory:** upgraded to 1.1.7 -* **@pluto-encrypted/leveldb:** upgraded to 1.1.7 - -## @pluto-encrypted/database [1.0.18](https://github.com/elribonazo/pluto-encrypted/compare/@pluto-encrypted/database@1.0.17...@pluto-encrypted/database@1.0.18) (2023-12-17) - - -### Bug Fixes - -* Improve doc generation, export al types and possible external types from other dependencies. ([971241f](https://github.com/elribonazo/pluto-encrypted/commit/971241fd26aca33a0c1b8f01e36c56a9c8a8202c)) - - - - - -### Dependencies - -* **@pluto-encrypted/indexdb:** upgraded to 1.1.7 -* **@pluto-encrypted/inmemory:** upgraded to 1.1.6 -* **@pluto-encrypted/leveldb:** upgraded to 1.1.6 - -## @pluto-encrypted/database [1.0.17](https://github.com/elribonazo/pluto-encrypted/compare/@pluto-encrypted/database@1.0.16...@pluto-encrypted/database@1.0.17) (2023-12-17) - - -### Bug Fixes - -* generate documentation for all the packages in 1 shot. ([3a27f78](https://github.com/elribonazo/pluto-encrypted/commit/3a27f78d122855a353efe814fdb7e48e0222ade2)) - - - - - -### Dependencies - -* **@pluto-encrypted/indexdb:** upgraded to 1.1.6 -* **@pluto-encrypted/inmemory:** upgraded to 1.1.5 -* **@pluto-encrypted/leveldb:** upgraded to 1.1.5 - -## @pluto-encrypted/database [1.0.16](https://github.com/elribonazo/pluto-encrypted/compare/@pluto-encrypted/database@1.0.15...@pluto-encrypted/database@1.0.16) (2023-12-17) - - - - - -### Dependencies - -* **@pluto-encrypted/indexdb:** upgraded to 1.1.5 -* **@pluto-encrypted/inmemory:** upgraded to 1.1.4 -* **@pluto-encrypted/leveldb:** upgraded to 1.1.4 - -## @pluto-encrypted/database [1.0.15](https://github.com/elribonazo/pluto-encrypted/compare/@pluto-encrypted/database@1.0.14...@pluto-encrypted/database@1.0.15) (2023-12-17) - - -### Bug Fixes - -* Remove vulnerable dependencies with unused dev dependency, babel. ([94dcc39](https://github.com/elribonazo/pluto-encrypted/commit/94dcc3948d8c2e1774362fcfcfda0198b78da05c)) - -## @pluto-encrypted/database [1.0.14](https://github.com/elribonazo/pluto-encrypted/compare/@pluto-encrypted/database@1.0.13...@pluto-encrypted/database@1.0.14) (2023-12-17) - - -### Bug Fixes - -* Improve code coverage and set 100 threshold from now on ([#60](https://github.com/elribonazo/pluto-encrypted/issues/60)) ([3bc51e9](https://github.com/elribonazo/pluto-encrypted/commit/3bc51e93b95a14611ea0799f5d7c22bfd69bb21a)) - - - - - -### Dependencies - -* **@pluto-encrypted/indexdb:** upgraded to 1.1.4 -* **@pluto-encrypted/inmemory:** upgraded to 1.1.3 -* **@pluto-encrypted/leveldb:** upgraded to 1.1.3 - -## @pluto-encrypted/database [1.0.13](https://github.com/elribonazo/pluto-encrypted/compare/@pluto-encrypted/database@1.0.12...@pluto-encrypted/database@1.0.13) (2023-12-16) - - -### Bug Fixes - -* rollback pkg versions. ([738e4e9](https://github.com/elribonazo/pluto-encrypted/commit/738e4e9eb0cf6bf8712edf9f44011555b7513605)) -* trigger package update ([72c8d64](https://github.com/elribonazo/pluto-encrypted/commit/72c8d645db13000945b438cb223728c55f910433)) - - - - - -### Dependencies - -* **@pluto-encrypted/indexdb:** upgraded to 1.1.3 -* **@pluto-encrypted/inmemory:** upgraded to 1.1.2 -* **@pluto-encrypted/leveldb:** upgraded to 1.1.2 - -# [@pluto-encrypted/database-v1.0.11](https://github.com/elribonazo/pluto-encrypted/compare/@pluto-encrypted/database-v1.0.10...@pluto-encrypted/database-v1.0.11) (2023-12-16) - - -### Bug Fixes - -* Introducing shared dependencies for db wrappers ([#57](https://github.com/elribonazo/pluto-encrypted/issues/57)) ([393b3bc](https://github.com/elribonazo/pluto-encrypted/commit/393b3bc2cbd811bf45fca7f67bb6704c617ed504)) - -# [@pluto-encrypted/database-v1.0.7](https://github.com/elribonazo/pluto-encrypted/compare/@pluto-encrypted/database-v1.0.6...@pluto-encrypted/database-v1.0.7) (2023-12-16) - - -### Bug Fixes - -* re-enable test coverage report. ([37c94c3](https://github.com/elribonazo/pluto-encrypted/commit/37c94c3562ff180fe592c7c34ddcdb08a42b740b)) - -# [@pluto-encrypted/database-v1.0.6](https://github.com/elribonazo/pluto-encrypted/compare/@pluto-encrypted/database-v1.0.5...@pluto-encrypted/database-v1.0.6) (2023-12-16) - - -### Bug Fixes - -* remove coverage from ignored ([#53](https://github.com/elribonazo/pluto-encrypted/issues/53)) ([0b51989](https://github.com/elribonazo/pluto-encrypted/commit/0b519896bc12001abba3d8db6c9da290c72b0d94)) - -# [@pluto-encrypted/database-v1.0.5](https://github.com/elribonazo/pluto-encrypted/compare/@pluto-encrypted/database-v1.0.4...@pluto-encrypted/database-v1.0.5) (2023-12-16) - - -### Bug Fixes - -* release. ([b21a863](https://github.com/elribonazo/pluto-encrypted/commit/b21a863bedd3258bb0809c963f74a19c511fe8a8)) diff --git a/packages/database/LICENSE b/packages/database/LICENSE deleted file mode 100644 index 216af719..00000000 --- a/packages/database/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - 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/database/README.md b/packages/database/README.md deleted file mode 100644 index ce030e09..00000000 --- a/packages/database/README.md +++ /dev/null @@ -1,115 +0,0 @@ -# Pluto-encrypted -Pluto Encrypted is a secure storage wrapper for (IndexDB, InMemory or LevelDB) and [AtalaPrism ](https://input-output-hk.github.io/atala-prism-wallet-sdk-ts/)([Pluto](https://input-output-hk.github.io/atala-prism-wallet-sdk-ts/interfaces/Domain.Pluto.html)) - -## USAGE -To install simply run - -```bash -npm i pluto-encrypted --save -# or with yarnyarn add pluto-encrypted -``` - -## Usage -This package implements Pluto interface and is fully compatible with the Prism Agent (check-compatibility versions), in order to use it just create a database as follows. - -DatabaseName is any string. -Password is a 32 bytes buffer. - -```typescript -import { Database } from 'pluto-encrypted'; -//You can use IndexDB any other storage that is compatible. -import IndexDB from "@pluto-encrypted/indexdb"; -import { - getDefaultCollections, - DIDCollection, - DIDPairCollection, - MediatorCollection, - PrivateKeyColletion, - CredentialCollection, - CredentialRequestMetadataCollection, - LinkSecretColletion, - MessageColletion -} from "@pluto-encrypted/schemas"; -const defaultPassword = new Uint8Array(32).fill(1); -const db = await Database.createEncrypted<{ - dids: DIDCollection; - didpairs: DIDPairCollection; - mediators: MediatorCollection; - privatekeys: PrivateKeyColletion; - credentials: CredentialCollection; - credentialrequestmetadatas: CredentialRequestMetadataCollection; - linksecrets: LinkSecretColletion; - messages: MessageColletion; -}>( - { - name: `my-db`, - encryptionKey: defaultPassword, - storage: IndexDB, - collections: getDefaultCollections() - } -); -const messages = await db.getAllMessages(); -``` - -Backup database into an unencrypted JSON string and restore from backup. -```typescript -import { Database } from 'pluto-encrypted'; -//You can use IndexDB any other storage that is compatible. -import IndexDB from "@pluto-encrypted/indexdb"; -import { - getDefaultCollections, - DIDCollection, - DIDPairCollection, - MediatorCollection, - PrivateKeyColletion, - CredentialCollection, - CredentialRequestMetadataCollection, - LinkSecretColletion, - MessageColletion -} from "@pluto-encrypted/schemas"; -const defaultPassword = new Uint8Array(32).fill(1); -const db = await Database.createEncrypted<{ - dids: DIDCollection; - didpairs: DIDPairCollection; - mediators: MediatorCollection; - privatekeys: PrivateKeyColletion; - credentials: CredentialCollection; - credentialrequestmetadatas: CredentialRequestMetadataCollection; - linksecrets: LinkSecretColletion; - messages: MessageColletion; -}>( - { - name: "my-db", - encryptionKey: defaultPassword, - storage: IndexDB, - collections: getDefaultCollections() - } -); -const backup = await db.backup(); -const restoredDatabase = await Database.createEncrypted<{ - dids: DIDCollection; - didpairs: DIDPairCollection; - mediators: MediatorCollection; - privatekeys: PrivateKeyColletion; - credentials: CredentialCollection; - credentialrequestmetadatas: CredentialRequestMetadataCollection; - linksecrets: LinkSecretColletion; - messages: MessageColletion; -}>( - { - name: "my-db", - encryptionKey: defaultPassword, - storage: IndexDB, - importData: backup, - collections: getDefaultCollections() - } -); -const messages = await restoredDatabase.getAllMessages(); -``` - -If the database is later initialised with the wrong password the "createEncrypted" async function will throw an exception and will not let you decrypt any encrypted content. - -## QA & Documentation -| Statements | Branches | Functions | Lines | -| --------------------------- | ----------------------- | ------------------------- | ----------------- | -| ![Statements](https://img.shields.io/badge/statements-100%25-brightgreen.svg?style=flat) | ![Branches](https://img.shields.io/badge/branches-100%25-brightgreen.svg?style=flat) | ![Functions](https://img.shields.io/badge/functions-100%25-brightgreen.svg?style=flat) | ![Lines](https://img.shields.io/badge/lines-100%25-brightgreen.svg?style=flat) | diff --git a/packages/database/coverage/coverage-summary.json b/packages/database/coverage/coverage-summary.json deleted file mode 100644 index 2d4df372..00000000 --- a/packages/database/coverage/coverage-summary.json +++ /dev/null @@ -1,3 +0,0 @@ -{"total": {"lines":{"total":37,"covered":37,"skipped":0,"pct":100},"statements":{"total":37,"covered":37,"skipped":0,"pct":100},"functions":{"total":6,"covered":6,"skipped":0,"pct":100},"branches":{"total":15,"covered":15,"skipped":0,"pct":100},"branchesTrue":{"total":0,"covered":0,"skipped":0,"pct":"Unknown"}} -,"/home/runner/work/pluto-encrypted/pluto-encrypted/packages/database/src/index.ts": {"lines":{"total":37,"covered":37,"skipped":0,"pct":100},"functions":{"total":6,"covered":6,"skipped":0,"pct":100},"statements":{"total":37,"covered":37,"skipped":0,"pct":100},"branches":{"total":15,"covered":15,"skipped":0,"pct":100}} -} diff --git a/packages/database/package.json b/packages/database/package.json deleted file mode 100644 index f63c2edc..00000000 --- a/packages/database/package.json +++ /dev/null @@ -1,66 +0,0 @@ -{ - "name": "@pluto-encrypted/database", - "version": "1.15.6", - "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", - "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", - "test": "NODE_ENV=debug npx vitest run tests/*.test.ts --pool threads --poolOptions.threads.singleThread", - "test:watch": "NODE_ENV=debug vitest tests/*.test.ts --pool threads --poolOptions.threads.singleThread", - "test:debug": "NODE_ENV=debug vitest tests/*.test.ts --inspect-brk --pool threads --poolOptions.threads.singleThread", - "build": "rm -rf build && npx rollup -c rollup/rollup.mjs", - "coverage": "npx vitest run --coverage && npx istanbul-badges-readme", - "docs": "npx typedoc --options ./typedoc.markdown.cjs --hideGenerator", - "docs-html": "npx typedoc --options ./typedoc.html.cjs --hideGenerator" - }, - "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.2" - }, - "optionalDependencies": { - "@pluto-encrypted/indexdb": "1.12.2", - "@pluto-encrypted/inmemory": "1.12.3", - "@pluto-encrypted/leveldb": "1.12.2" - }, - "devDependencies": { - "@pluto-encrypted/encryption": "1.11.0", - "@pluto-encrypted/indexdb": "1.12.2", - "@pluto-encrypted/inmemory": "1.12.3", - "@pluto-encrypted/leveldb": "1.12.2", - "@pluto-encrypted/shared": "1.11.3", - "@pluto-encrypted/schemas": "^1.3.5", - "@vitest/coverage-v8": "^1.0.4", - "level": "^6.0.1" - }, - "dependencies": { - "@atala/prism-wallet-sdk": "^4.0.2", - "@pluto-encrypted/encryption": "1.11.0", - "@pluto-encrypted/shared": "1.11.3", - "@pluto-encrypted/schemas": "^1.3.5", - "rxdb": "^14.17.0", - "rxjs": "7.8.1", - "uuid": "^9.0.1" - }, - "files": [ - "build/*" - ], - "gitHead": "6aa4ce8bbb9938fc4c4e790efffa5b902631362c" -} diff --git a/packages/database/rollup/rollup.mjs b/packages/database/rollup/rollup.mjs deleted file mode 100644 index 1278dac6..00000000 --- a/packages/database/rollup/rollup.mjs +++ /dev/null @@ -1,5 +0,0 @@ -import nodePolyfills from "rollup-plugin-polyfill-node"; - -import CreateConfig from "../../../rollup/index.mjs"; - -export default CreateConfig(undefined, []); diff --git a/packages/database/src/index.ts b/packages/database/src/index.ts deleted file mode 100644 index 5aef3f31..00000000 --- a/packages/database/src/index.ts +++ /dev/null @@ -1,119 +0,0 @@ -/** - * @packageDocumentation - * @module database - */ -import { DatabaseBase, ExtractStaticMethods, UnionToIntersection } from '@pluto-encrypted/shared' -import { - CollectionsOfDatabase, - RxCollection, - RxCollectionCreator, - RxDumpDatabase, - RxError, - RxStorage -} from 'rxdb' - -export type * from './types'; - -/** - * 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 const Database = { - createEncrypted: async function createEncrypted< - Collections extends CollectionsOfDatabase, - >(options: { - name: string; - encryptionKey: Uint8Array; - importData?: RxDumpDatabase; - storage: RxStorage; - autoStart?: boolean; - collections: { - [key in keyof Collections]: RxCollectionCreator; - }; - }) { - try { - const { - collections, - name, - storage, - encryptionKey, - importData, - autoStart = true, - } = options; - - - if (!storage) { - throw new Error('Please provide a valid storage.') - } - - const collectionMap = new Map>(); - - Object.keys(collections).forEach((collectionName) => { - const currentCollection = collections[collectionName]!; - collectionMap.set(collectionName, currentCollection) - }) - - const instance = new DatabaseBase({ - ignoreDuplicate: true, - name, - storage, - password: Buffer.from(encryptionKey).toString('hex') - }) - - if (autoStart) { - await instance.start(collections) - } - - if (importData) { - await instance.db.importJSON(importData) - } - - 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 & UnionToIntersection>>(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()) - } - return destination; - } - }, - }) - - return proxy - } catch (err) { - /* istanbul ignore else */ - if ((err as RxError).code === 'DB1') { - throw new Error('Invalid Authentication') - } else { - /* istanbul ignore next */ - - throw err - } - } - } -} \ No newline at end of file diff --git a/packages/database/src/types.ts b/packages/database/src/types.ts deleted file mode 100644 index aa0d2fab..00000000 --- a/packages/database/src/types.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { PlutoCollections } from '@pluto-encrypted/schemas' -import { type MangoQuery, type MangoQueryNoLimit, type RxCollection, type RxDocument, type RxDumpDatabase, type RxStorage } from 'rxdb/dist/types/types' - -export type NoKeys = { - [P in Exclude]: T[P]; -} - - - -export interface GenericORMType extends RxCollection { - count: (this: RxCollection, query: MangoQuery | undefined) => Promise - findByIds: (this: RxCollection, ids: string[]) => Map - find: (queryObj?: MangoQueryNoLimit | string) => Array> - findOne: (queryObj?: MangoQueryNoLimit | string) => RxDocument | null - remove: (queryObj?: MangoQueryNoLimit | string) => Array> -} - - -export interface createEncryptedOptions { - name: string - encryptionKey: Uint8Array - importData?: RxDumpDatabase - storage: RxStorage -} - - diff --git a/packages/database/tests/fixtures.ts b/packages/database/tests/fixtures.ts deleted file mode 100644 index 42b52a67..00000000 --- a/packages/database/tests/fixtures.ts +++ /dev/null @@ -1,217 +0,0 @@ -import SDK from "@atala/prism-wallet-sdk"; -const { - Ed25519KeyPair, - Ed25519PrivateKey, - Secp256k1KeyPair, - Secp256k1PrivateKey, - X25519KeyPair, - X25519PrivateKey, -} = SDK; - -const secpPrivateKey = new Secp256k1PrivateKey( - new Uint8Array([ - 45, 182, 188, 189, 107, 229, 136, 180, 199, 177, 110, 84, 98, 140, 121, 84, - 107, 105, 179, 139, 14, 174, 177, 63, 173, 141, 7, 118, 161, 192, 192, 221, - ]) -); -export const secp256K1 = new Secp256k1KeyPair( - secpPrivateKey, - secpPrivateKey.publicKey() -); - -const ed25519PrivateKey = new Ed25519PrivateKey( - Buffer.from("JLIJQ5jlkyqtGmtOth6yggJLLC0zuRhUPiBhd1-rGPs", "base64url") -); -export const ed25519 = new Ed25519KeyPair( - ed25519PrivateKey, - ed25519PrivateKey.publicKey() -); - -const x25519PrivateKey = new X25519PrivateKey( - Buffer.from("eHbEtI71XIBIsuQK7XdjZ_ZPnLZb3y4paWoqSoS7BnI", "base64url") -); -export const x25519 = new X25519KeyPair( - x25519PrivateKey, - x25519PrivateKey.publicKey() -); - -export const linkSecret: SDK.Domain.Anoncreds.LinkSecret = - "11713282333014162675185775227133916651856831195832037281552411830422122210216"; - -export const schema: SDK.Domain.Anoncreds.Schema = { - name: "schema name", - version: "1.0", - attrNames: ["name", "age"], - issuerId: "did:web:xyz", -}; - -export const schemaId = "did:web:xyz/resource/schema"; -export const schemas = { [schemaId]: schema }; -export const credDefId = "did:web:xyz/resource/cred-def"; - -export const credOffer: SDK.Domain.Anoncreds.CredentialOffer = { - schema_id: schemaId, - cred_def_id: "did:web:xyz/resource/cred-def", - key_correctness_proof: { - c: "76557819503450570442357976029271303987759136289314846847024757974752606615433", - xz_cap: - "26047879363332547950920668394631678475313752008082689588028385075806198959009721480298642181417611387120760535340960652992598169976318796059443404652478753165940963938026715950444631637055579596396026982943529446772342056118213731997539494790069972362712412848545977350411933491687478962150552753933891241069977903236245408595467016248045708851235686828269686277218325172481148269365738838667311348922929239876501229218854901336077610669087389670091204141817761014674154146755628794442065539896048607369184947340323162627521384048677015174858428761829211514983844416604741456701465732354883642257230400665085164493995639836946749428712602480384130632356640901418646806091518373306556288954289", - xr_cap: [ - [ - "age", - "37523550844923066276917545265534491936001653058431807699727798378094010348017417786213033463012541464861614713651678817589894752131766899552202186956509278956052677681349590167219631006515597935364124683509557223008283580029502931430380055551345019089794453342866634865505293670597130041956152064268604570574775784367900164625667326244382433984825612756021533073304839324299187948682509607641828855308845653725291687712265043071582873816295392972053358963210517456371474273531564989381194134152519027319325114667103082545250397114009229013996244896611333191925354781709243382864211341173108829209135657104587482214147977220885303413739052442209985783183870139853950883453738389448581714672060", - ], - [ - "name", - "40114198290379256041372995441628703701697468212013103904320488156133624512624518776636636679936428767628511100834703945932272277119352677403376670387372871153129929576812118980029243346717913240254947965865744085397369091151556546260636586787167694200525462305016276069215035338546740434877965464035950368040654082423013022634233986285166071269362922845761571385784692708141028444335024777471220924204393976065258643143210131836379590020472238396839577304048276973858344620772092596583905864740719861059017160818497762374044149149314046526512381034705421360416522645565343294048956673555742143144006335123972014910685697417095527968642708567895812407107903351826576984395268441796123152869510", - ], - [ - "master_secret", - "17378775238119039681239435504832690562693139985297581004609697280961799415478395227365074603387798682709917541921746683788459574112268962573229585691444414002163279289000517128970409045422613794886895141511303902319051161040962745971806552893764259050521879639998894425230406084402232911982800786217758930274472277822969507777888869816351683032762867227108504826294469816717150773627310267951901092893045791169831629487768555281136526127037211876008761095116571863850777229858315210904916939671575373966848439177870458227542504890675195429629741131074431032162974747956977739339739205375284664571315097532432745565887768994606184944468164941808835757519277660700337481958408893690556466192208", - ], - ], - }, - nonce: "1155389807945475146571300", - method_name: "anoncreds", -}; - -export const credDef: SDK.Domain.Anoncreds.CredentialDefinition = { - schemaId: schemaId, - issuerId: "did:web:xyz", - type: "CL", - tag: "default-tag", - value: { - primary: { - n: "2138440416314633374591088195063696546043123277066922638020134791602273076278733265198390559999196639059617332341897171969471396384426442263407149455313654361683364983454358134154449737184762832549626365860664862681300853260092245460133629393197506797813510115597160823513332022868942084864264115026443220310847039670437343802177458713870037673612155704946372493840496386886773727466495489416209443026828278038061798339071661238983028310965032474627760641708951476779486574582009667149594572417153818776817059886544993889576267253226541766667935646506220326294624143640755229768275395867260209310406030868988219396673", - s: "375783515905172479678189694439438293124410653823481120500720236836905424414937248674149487774807325687499797860172928285508262280982970486768785344476352731223145346966890620843636512852741061102998942506714117113306492151964896503097722677379824165340858924427501815041684806109662866453098916197117471136063544146802291756839519730104512053670312142976363639936614666586671853469442125677481817693926232925010812196258066027716393514210467312905260647664980944899919627823305269563954240416713003055413714633135095057064137982879242895058862234484222386526805971607419993779687534728535549485529895709794024363544", - r: [ - [ - "name", - "1339792759576954480492376578847792893360328516229286900150133471363186583829749911481667461401130501227404036403509999655715920590906655449568921973193383734895050724786440176443319672836559729173248746986868722909818220919403659226270224677749054849267437090960630699131904219878221761847284501312771606158271185560102808030298570761806506842137173746368720591853713380684958166350096104972264094294658573736651672550243062941442151223970367393394495048879093769466881961496855436604768494279534819818767775118321755604018201554330386132841353338949038092004967328970916219672468954833865033319360866074670007780618", - ], - [ - "master_secret", - "812744365608357986515546951213735794905780531247400654485983675689007345252680783465620382756268298324619070095212727671013163587057960315104611505032391159923993186222992472271453158974000542388378728270352857044809506169036309424352546411124179707638441673291158450401569249553417829367721202384508794163270341742020366880294131562095198464204914661778362000567741892826931098757894984606489166588347686099839472171239690638334264704817162009248984017866176802917792042053625420351082400053844639007943327226933542386763152742005797026693758548721701645341688448869500455939673371665799883665035196100593742820765", - ], - [ - "age", - "1449485663749865112122084718309651799315876369399955386403349647157857267039738681846930133397399422116354888183111371765400737684123480339059046850189555156190164677867617134270296041268333092741226364695203773774260453734976395787415140818149909781659096210986518767963537521355538341046796673590463001432519694523140909453262132434115275751962728302009629278131044645113553957913861064628840202634780565720519420413110235161108122048945955929418529430552412537083201815025931848807079298247150295522314313662791060217650118275501496403633416974085086279896777251419212772606455298376048561561660554033200664561122", - ], - ], - rctxt: - "860911025032267966121537116747511648169210971555331852297327983657139587085942104673653614121933222003762276431341903715802016467096443789060052518852455149260273877263078757890535509188798812965587842763977780248898565717270220023917514653105171642271549164940634714174542454453494892988595340755873769347520154470471770549002457696766440819869518496811070236983222777464118573117519720995323647212086015212164299500917094183811610380285975565511188317704996015410378305078269879189003145417420690660051014495457659387330566369572172736139469523933999250778057312091553667159949004204624608553681313568626037528816", - z: "2121804520854046155333146480946067403536032620048509173296488461620991470957905025190073393533065162826019376175710496819562862443921284310624809586091960645852195207737003870600962592140196338174630044646719556493115513937191171697377398878248566738696903934756282960488248731988728585511385043106689590903854157937005001256453527432445636221995990491062748065236450143241984118701723276135733985922648057616666342802697522278188836392945197544183484607303781398698553490093880903336637463635680300818603734335511536928765778308620191754963249571453280495676312497378814397081522448865551665149984638461990456850881", - }, - }, -}; - -export const credDefs = { [credDefId]: credDef }; - -export const createJWTPayload = ( - id: string, - proof: string, - credentialType: SDK.Domain.CredentialType -) => { - const vc = { - id, - credentialType: credentialType, - type: [credentialType], - aud: ["aud"], - context: ["context"], - credentialSubject: { whatever: "credSubject" }, - evidence: { - id: "evidenceId", - type: "evidenceType", - }, - expirationDate: new Date().toISOString(), - issuanceDate: new Date().toISOString(), - issuer: new SDK.Domain.DID( - "did", - "peer", - "2.Ez6LSms555YhFthn1WV8ciDBpZm86hK9tp83WojJUmxPGk1hZ.Vz6MkmdBjMyB4TS5UbbQw54szm8yvMMf1ftGV2sQVYAxaeWhE.SeyJpZCI6Im5ldy1pZCIsInQiOiJkbSIsInMiOiJodHRwczovL21lZGlhdG9yLnJvb3RzaWQuY2xvdWQiLCJhIjpbImRpZGNvbW0vdjIiXX0" - ), - refreshService: { - id: "refreshServiceId", - type: "refreshServiceType", - }, - termsOfUse: { - id: "termsOfUseId", - type: "termsOfUseType", - }, - validFrom: { - id: "validFromId", - type: "validFromType", - }, - validUntil: { - id: "validUntilId", - type: "validUntilType", - }, - credentialSchema: { - id: "credentialSchemaId", - type: "credentialSchemaType", - }, - credentialStatus: { - id: "credentialStatusId", - type: "credentialStatusType", - }, - proof: proof, - }; - - const jwtPayload: any = { - id: "123", - iss: "did:peer:2.issuer", - nbf: 1680615608435, - sub: "did:peer:2.sub", - exp: 1680615608435, - aud: ["aud-json"], - vc: vc, - }; - - return jwtPayload; -}; -export const credRequestMeta: SDK.Domain.Anoncreds.CredentialRequestMeta = { - link_secret_blinding_data: { - v_prime: - "77955816791910907008648197625607251151043985904464685610589268755863823710042524325116894319321593903274621305101429675982328480929558765668395477286044036175023571135951855240427212072392115346223990606637530234412828281763675277786130736667970888577953183545724972075795470500481480587504146888168295548415330994692518385699942377815143595346327569474696881929936106990569016082555989993978175098221779656764883735585641835663445021379504408712254130562797706300716047105206280868009518894051808092685428634143160521444146484478798980767637798519834481411563284127214784285274598304432830695507876151369513892826498610123007743998318639", - }, - nonce: "384669312299348345170475", - link_secret_name: "link-secret-id", -}; - -export const credentialIssued: SDK.Domain.Anoncreds.CredentialIssued = { - schema_id: schemaId, - cred_def_id: "did:web:xyz/resource/cred-def", - values: [ - ["age", { raw: "28", encoded: "28" }], - [ - "name", - { - raw: "john", - encoded: - "68231017646261521938414776289104528029572365316885701689085572319872983785594", - }, - ], - ], - signature: { - p_credential: { - m_2: "90069112451055455821909400594406389902973279602878070870495376996444562816830", - a: "863206875070883508185084882433898034597056397288064150964909699848368101345942320681713420008320908172031366175764418516990530197118497873083108998836069955208560561365885178868957934721121818800195152765722925303482592098299043872531270628211279296662298703380533421005111978188231514326269144788469626292012467891951834985914306479999402596193828005218601831577836972155135721113555056320950898902900812022442212634154104525444865293627714269994627396682813488336112739630599692616934030468341046723507920859605204701140679082157987867742695138146865893004386171114420488126218257552981621418620795971402342420055", - e: "259344723055062059907025491480697571938277889515152306249728583105665800713306759149981690559193987143012367913206299323899696942213235956742930103453519678657228466134629917218519", - v: "8143446409913772255034152121328368039740626498888186354398879911744619763092523700068534155970316639325500748530790803346133400742208591972338832230481355996998878663423674449927007017103519158518841363025981102486265082027859231212785242394349018269859142047237847004466507505310624703221646956096334505927823727535128643408929895721360649486881661653430795374387398186589089307192641017475854047689060015396792244392488752028709889494148392343976206977761336843050968984216787674405343600492400040342034954879243301323597723425634111031850182237417361092482780483169862079554189749933027076569428078736298787846257330215373212181232245606400244542414366394276001432386415321137893700290570865313825552071290779533007084933667485178966714254743589959898887425372871525225305207025738953531478454150168638254081854031392", - }, - }, - signature_correctness_proof: { - se: "471472993450654125094815726148197965574424476578333157254325140782961168825105331051644868767781028679788350834880525043676296586472820693042050052742548830411776592846473749819901073592049502739648801719081538069485917308909817697575396656049685055624390272024518499392129521543088779385005671778669761735194904527436501886256576199999327721691983944094804259738379761906169617912917061639899452266237275643426312858778978574970646335896180734752298062049872360989081844266166354770197707949373253367460986810798494254673065207170398218825977487917435335438139842606666094711078074326163791098396957184806668244832", - c: "99614365014321274953096367476703930366339506406903542322778818757090357462808", - }, -}; - -export const createAnonCredsPayload = () => { - return credentialIssued; -}; - -export const encodeAnonCredsCredential = (cred: object) => { - const json = JSON.stringify(cred); - const encoded = Buffer.from(json); - return encoded; -}; diff --git a/packages/database/tests/pluto.test.ts b/packages/database/tests/pluto.test.ts deleted file mode 100644 index 1a2c4e52..00000000 --- a/packages/database/tests/pluto.test.ts +++ /dev/null @@ -1,1263 +0,0 @@ -import "./setup"; - -import { describe, it, beforeEach, afterEach } from 'vitest'; -import fs from 'fs'; -import path from 'path'; -import { randomUUID } from "crypto"; -import SDK, { JWTCredential } from "@atala/prism-wallet-sdk"; -import * as sinon from "sinon"; -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 } from "../src"; -import { PrivateKeyMethods, LinkSecretSchemaType, LinkSecretStaticMethodTypes, LinkSecretMethodTypes, LinkSecretMethods, LinkSecretSchema, LinkSecretStaticMethods, getDefaultCollections, PlutoCollections, CredentialCollection, CredentialRequestMetadataCollection, DIDCollection, DIDPairCollection, LinkSecretColletion, MediatorCollection, MessageColletion, PrivateKeyColletion, MessageSchemaType, MessageMethodTypes, MessageStaticMethodTypes } from "@pluto-encrypted/schemas"; -import { DatabaseBase, ExtractStaticMethods, UnionToIntersection } from "@pluto-encrypted/shared"; - -const { - AnonCredsCredential, - Apollo, - Castor, - Pollux, -} = SDK; - -const pollux = new Pollux(new Castor(new Apollo())); -const keyData = new Uint8Array(32); -const jwtParts = [ - "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9", - "eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwidHlwZSI6Imp3dCJ9", - "18bn-r7uRWAG4FCFBjxemKvFYPCAoJTOHaHthuXh5nM", -]; -const messageType = "https://didcomm.org/basicmessage/2.0/message"; -const createMessage = ( - from?: SDK.Domain.DID, - to?: SDK.Domain.DID, - direction: SDK.Domain.MessageDirection = SDK.Domain.MessageDirection.SENT -) => { - const message = new SDK.Domain.Message( - "{}", - randomUUID(), - messageType, - from, - to, - [], - undefined, - undefined, - undefined, - undefined, - undefined, - direction - ); - return message; -}; -const defaultPassword = Buffer.from(keyData); - -let sandbox: sinon.SinonSandbox; - -const databaseName = "prism-db"; -const databasePath = path.resolve(process.cwd(), databaseName); - -const storages: RxStorage[] = [ - createLevelDBStorage({ - dbPath: databasePath - }), - InMemory, - IndexDb, -] - -function getStorageDBName(storage: RxStorage) { - if (storage.name === "leveldb") { - return `${databaseName}${randomUUID()}` - } - if (storage.name === "in-memory") { - return databaseName - } - return `${databaseName}${randomUUID()}` -} - -type DefaultCollections = { - dids: DIDCollection; - didpairs: DIDPairCollection; - mediators: MediatorCollection; - privatekeys: PrivateKeyColletion; - credentials: CredentialCollection; - credentialrequestmetadatas: CredentialRequestMetadataCollection; - linksecrets: LinkSecretColletion; - messages: MessageColletion; -} - -describe("Pluto encrypted testing with different storages", () => { - let db: DatabaseBase & UnionToIntersection>; - - let currentDBName: string; - - afterEach(async () => { - // jest.useRealTimers(); - sandbox.restore(); - }); - - beforeEach(async () => { - // jest.useFakeTimers(); - sandbox = sinon.createSandbox(); - }); - - storages.forEach((storage, i) => { - - const storageName = `[${storage.name}]`; - - it(storageName + "Should throw an error if pluto has is startede with a wrong database password", async ({ expect }) => { - const forceDatabaseName = getStorageDBName(storage) - const createDatabase = async (password: Uint8Array) => { - const db = await Database.createEncrypted( - { - name: forceDatabaseName, - encryptionKey: password, - storage: storage, - collections: getDefaultCollections() - } - ); - - await db.getAllPrismDIDs() - const did = SDK.Domain.DID.fromString( - "did:prism:733e594871d7700d35e6116011a08fc11e88ff9d366d8b5571ffc1aa18d249ea:Ct8BCtwBEnQKH2F1dGhlbnRpY2F0aW9uYXV0aGVudGljYXRpb25LZXkQBEJPCglzZWNwMjU2azESIDS5zeYUkLCSAJLI6aLXRTPRxstCLPUEI6TgBrAVCHkwGiDk-ffklrHIFW7pKkT8i-YksXi-XXi5h31czUMaVClcpxJkCg9tYXN0ZXJtYXN0ZXJLZXkQAUJPCglzZWNwMjU2azESIDS5zeYUkLCSAJLI6aLXRTPRxstCLPUEI6TgBrAVCHkwGiDk-ffklrHIFW7pKkT8i-YksXi-XXi5h31czUMaVClcpw" - ); - const privateKey = Fixtures.secp256K1.privateKey; - await db.storePrismDID(did, 0, privateKey, null); - } - - await createDatabase(defaultPassword); - - const keyData2 = keyData; - keyData2[0] = 1; - keyData2[1] = 2; - - await expect(() => createDatabase(keyData2)).rejects.toThrowError(new Error("Invalid Authentication")); - - }); - - - describe(storageName, () => { - - beforeEach(async () => { - currentDBName = getStorageDBName(storage); - db = await Database.createEncrypted( - { - name: currentDBName, - encryptionKey: defaultPassword, - storage: storage, - collections: getDefaultCollections() - } - ); - }); - - afterEach(async () => { - if (db && (storage.name === "in-memory" || storage.name === "leveldb")) { - await db.clear() - } - }) - - it(storageName + "Should throw an error if pluto has not been started", async ({ expect }) => { - const createDatabase = async () => { - const restored = await Database.createEncrypted( - { - name: currentDBName, - encryptionKey: defaultPassword, - storage: storage, - autoStart: false, - collections: getDefaultCollections() - } - ); - - await restored.getAllMediators() - } - - await expect(() => createDatabase()).rejects.toThrowError(new Error("Start Pluto first.")); - }) - - it(storageName + "Should throw an error if pluto has been initialised with no storage.", async ({ expect }) => { - const createDatabase = async () => { - await Database.createEncrypted<{ - dids: DIDCollection; - didpairs: DIDPairCollection; - mediators: MediatorCollection; - privatekeys: PrivateKeyColletion; - credentials: CredentialCollection; - credentialrequestmetadatas: CredentialRequestMetadataCollection; - linksecrets: LinkSecretColletion; - messages: MessageColletion; - }>( - { - name: currentDBName, - encryptionKey: defaultPassword, - storage: undefined as any, - autoStart: false, - collections: getDefaultCollections() - } - ); - } - - await expect(() => createDatabase()).rejects.toThrowError(new Error("Please provide a valid storage.")); - }) - - it(storageName + "Should store a new Prism DID and its privateKeys", async ({ expect }) => { - expect(await db.getPrismLastKeyPathIndex()).toBe(0); - const did = SDK.Domain.DID.fromString( - "did:prism:733e594871d7700d35e6116011a08fc11e88ff9d366d8b5571ffc1aa18d249ea:Ct8BCtwBEnQKH2F1dGhlbnRpY2F0aW9uYXV0aGVudGljYXRpb25LZXkQBEJPCglzZWNwMjU2azESIDS5zeYUkLCSAJLI6aLXRTPRxstCLPUEI6TgBrAVCHkwGiDk-ffklrHIFW7pKkT8i-YksXi-XXi5h31czUMaVClcpxJkCg9tYXN0ZXJtYXN0ZXJLZXkQAUJPCglzZWNwMjU2azESIDS5zeYUkLCSAJLI6aLXRTPRxstCLPUEI6TgBrAVCHkwGiDk-ffklrHIFW7pKkT8i-YksXi-XXi5h31czUMaVClcpw" - ); - const did2 = SDK.Domain.DID.fromString( - "did:prism:733e594871d7700d35e6116011a08fc11e88ff9d366d8b5571ffc1aa18d249ea:Ct8BCtwBEnQKH2F1dGhlbnRpY2F0aW9uYXV0aGVudGljYXRpb25LZXkQBEJPCglzZWNwMjU2azESIDS5zeYUkLCSAJLI6aLXRTPRxstCLPUEI6TgBrAVCHkwGiDk-ffklrHIFW7pKkT8i-YksXi-XXi5h31czUMaVClcpxJkCg9tYXN0ZXJtYXN0ZXJLZXkQAUJPCglzZWNwMjU2azESIDS5zeYUkLCSAJLI6aLXRTPRxstCLPUEI6TgBrAVCHkwGiDk-ffklrHIFW7pKkT8i-YksXi-XXi5h31czUMaVClcpw1" - ); - const did3 = SDK.Domain.DID.fromString( - "did:prism:733e594871d7700d35e6116011a08fc11e88ff9d366d8b5571ffc1aa18d249ea:Ct8BCtwBEnQKH2F1dGhlbnRpY2F0aW9uYXV0aGVudGljYXRpb25LZXkQBEJPCglzZWNwMjU2azESIDS5zeYUkLCSAJLI6aLXRTPRxstCLPUEI6TgBrAVCHkwGiDk-ffklrHIFW7pKkT8i-YksXi-XXi5h31czUMaVClcpxJkCg9tYXN0ZXJtYXN0ZXJLZXkQAUJPCglzZWNwMjU2azESIDS5zeYUkLCSAJLI6aLXRTPRxstCLPUEI6TgBrAVCHkwGiDk-ffklrHIFW7pKkT8i-YksXi-XXi5h31czUMaVClcpw2" - ); - const privateKey = Fixtures.secp256K1.privateKey; - expect(await db.getPrismLastKeyPathIndex()).toBe(0); - - 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(1); - expect(await db.getPrismLastKeyPathIndex()).toBe(1); - await db.storePrismDID(did2, 1, privateKey, null); - expect(await db.getPrismDIDKeyPathIndex(did2)).toBe(2); - expect(await db.getPrismLastKeyPathIndex()).toBe(2); - expect(await db.getPrismDIDKeyPathIndex(did3)).toBe(0); - }); - - it(storageName + "Should throw an exception if a wrong key object from Database is loaded", async ({ expect }) => { - const wrongKey: any = { - keySpecification: [], - toDomainPrivateKey: PrivateKeyMethods.toDomainPrivateKey, - }; - expect(() => { - wrongKey.toDomainPrivateKey(); - }).toThrowError(new Error(`Invalid KeyType undefined`)); - - const wrongKey2: any = { - type: "sds", - keySpecification: [], - toDomainPrivateKey: PrivateKeyMethods.toDomainPrivateKey, - }; - expect(() => { - wrongKey2.toDomainPrivateKey(); - }).toThrowError(new Error(`Invalid KeyType sds`)); - - const wrongKey3: any = { - type: SDK.Domain.KeyTypes.Curve25519, - keySpecification: [], - toDomainPrivateKey: PrivateKeyMethods.toDomainPrivateKey, - }; - expect(() => { - wrongKey3.toDomainPrivateKey(); - }).toThrowError(new Error("Undefined key curve")); - - const wrongKey4: any = { - type: SDK.Domain.KeyTypes.Curve25519, - keySpecification: [ - { - name: SDK.Domain.KeyProperties.curve, - type: "string", - value: "asd", - }, - ], - toDomainPrivateKey: PrivateKeyMethods.toDomainPrivateKey, - }; - expect(() => { - wrongKey4.toDomainPrivateKey(); - }).toThrowError(new Error("Invalid key curve asd")); - - const wrongKey5: any = { - type: SDK.Domain.KeyTypes.Curve25519, - keySpecification: [ - { - name: SDK.Domain.KeyProperties.curve, - type: "string", - value: SDK.Domain.Curve.ED25519, - }, - ], - toDomainPrivateKey: PrivateKeyMethods.toDomainPrivateKey, - }; - expect(() => { - wrongKey5.toDomainPrivateKey(); - }).toThrowError(new Error("Undefined key raw")); - - const correctKey: any = { - type: SDK.Domain.KeyTypes.EC, - keySpecification: [ - { - name: SDK.Domain.KeyProperties.curve, - type: "string", - value: SDK.Domain.Curve.SECP256K1, - }, - { - name: SDK.Domain.KeyProperties.rawKey, - type: "string", - value: Buffer.from(Fixtures.secp256K1.privateKey.raw).toString( - "hex" - ), - }, - ], - toDomainPrivateKey: PrivateKeyMethods.toDomainPrivateKey, - }; - - correctKey.toDomainPrivateKey(); - - const correctKeyWithIndex: any = { - type: SDK.Domain.KeyTypes.EC, - keySpecification: [ - { - name: SDK.Domain.KeyProperties.curve, - type: "string", - value: SDK.Domain.Curve.SECP256K1, - }, - { - name: SDK.Domain.KeyProperties.rawKey, - type: "string", - value: Buffer.from(Fixtures.secp256K1.privateKey.raw).toString( - "hex" - ), - }, - { - name: SDK.Domain.KeyProperties.index, - type: "string", - value: Fixtures.secp256K1.privateKey.index, - }, - { - name: SDK.Domain.KeyProperties.seed, - type: "string", - value: "A12456", - }, - ], - toDomainPrivateKey: PrivateKeyMethods.toDomainPrivateKey, - }; - - correctKeyWithIndex.toDomainPrivateKey(); - - const correctEd25519Key: any = { - type: SDK.Domain.KeyTypes.EC, - keySpecification: [ - { - name: SDK.Domain.KeyProperties.curve, - type: "string", - value: SDK.Domain.Curve.ED25519, - }, - { - name: SDK.Domain.KeyProperties.rawKey, - type: "string", - value: Buffer.from(Fixtures.ed25519.privateKey.raw).toString("hex"), - }, - ], - toDomainPrivateKey: PrivateKeyMethods.toDomainPrivateKey, - }; - - correctEd25519Key.toDomainPrivateKey(); - - const correctX25519Key: any = { - type: SDK.Domain.KeyTypes.Curve25519, - keySpecification: [ - { - name: SDK.Domain.KeyProperties.curve, - type: "string", - value: SDK.Domain.Curve.X25519, - }, - { - name: SDK.Domain.KeyProperties.rawKey, - type: "string", - value: Buffer.from(Fixtures.x25519.privateKey.raw).toString("hex"), - }, - ], - toDomainPrivateKey: PrivateKeyMethods.toDomainPrivateKey, - }; - - correctX25519Key.toDomainPrivateKey(); - }); - - it(storageName + "Should return null when no privateKey is found by its id", async ({ expect }) => { - const did = SDK.Domain.DID.fromString( - "did:prism:733e594871d7700d35e6116011a08fc11e88ff9d366d8b5571ffc1aa18d249ea:Ct8BCtwBEnQKH2F1dGhlbnRpY2F0aW9uYXV0aGVudGljYXRpb25LZXkQBEJPCglzZWNwMjU2azESIDS5zeYUkLCSAJLI6aLXRTPRxstCLPUEI6TgBrAVCHkwGiDk-ffklrHIFW7pKkT8i-YksXi-XXi5h31czUMaVClcpxJkCg9tYXN0ZXJtYXN0ZXJLZXkQAUJPCglzZWNwMjU2azESIDS5zeYUkLCSAJLI6aLXRTPRxstCLPUEI6TgBrAVCHkwGiDk-ffklrHIFW7pKkT8i-YksXi-XXi5h31czUMaVClcpw" - ); - expect(await db.getDIDInfoByDID(did)).toBe(null); - }); - - it(storageName + "Should return null when no privateKey is found by its id", async ({ expect }) => { - expect(await db.getDIDPrivateKeyByID("not fund")).toBe(null); - }); - - it(storageName + "Should return null when no privateKey is found by its did", async ({ expect }) => { - const did = SDK.Domain.DID.fromString( - "did:prism::t8BCtwBEnQKH2F1dGhlbnRpY2F0aW9uYXV0aGVudGljYXRpb25LZXkQBEJPCglzZWNwMjU2azESIDS5zeYUkLCSAJLI6aLXRTPRxstCLPUEI6TgBrAVCHkwGiDk-ffklrHIFW7pKkT8i-YksXi-XXi5h31czUMaVClcpxJkCg9tYXN0ZXJtYXN0ZXJLZXkQAUJPCglzZWNwMjU2azESIDS5zeYUkLCSAJLI6aLXRTPRxstCLPUEI6TgBrAVCHkwGiDk-ffklrHIFW7pKkT8i-YksXi-XXi5h31czUMaVClcpw" - ); - expect((await db.getDIDPrivateKeysByDID(did)).length).toBe(0); - }); - - it(storageName + "Should store a new Prism DID and its privateKeys with privateKeyMetadataId", async ({ expect }) => { - const did = SDK.Domain.DID.fromString( - "did:prism:733e594871d7700d35e6116011a08fc11e88ff9d366d8b5571ffc1aa18d249ea:Ct8BCtwBEnQKH2F1dGhlbnRpY2F0aW9uYXV0aGVudGljYXRpb25LZXkQBEJPCglzZWNwMjU2azESIDS5zeYUkLCSAJLI6aLXRTPRxstCLPUEI6TgBrAVCHkwGiDk-ffklrHIFW7pKkT8i-YksXi-XXi5h31czUMaVClcpxJkCg9tYXN0ZXJtYXN0ZXJLZXkQAUJPCglzZWNwMjU2azESIDS5zeYUkLCSAJLI6aLXRTPRxstCLPUEI6TgBrAVCHkwGiDk-ffklrHIFW7pKkT8i-YksXi-XXi5h31czUMaVClcpw" - ); - const privateKey = Fixtures.secp256K1.privateKey; - await db.storePrismDID(did, 0, privateKey, did.toString()); - expect((await db.getAllPrismDIDs()).length).toBe(1); - }); - - it(storageName + "Should store a new Prism DID and its privateKeys with privateKeyMetadataId and alias", async ({ expect }) => { - const did = SDK.Domain.DID.fromString( - "did:prism:733e594871d7700d35e6116011a08fc11e88ff9d366d8b5571ffc1aa18d249ea:Ct8BCtwBEnQKH2F1dGhlbnRpY2F0aW9uYXV0aGVudGljYXRpb25LZXkQBEJPCglzZWNwMjU2azESIDS5zeYUkLCSAJLI6aLXRTPRxstCLPUEI6TgBrAVCHkwGiDk-ffklrHIFW7pKkT8i-YksXi-XXi5h31czUMaVClcpxJkCg9tYXN0ZXJtYXN0ZXJLZXkQAUJPCglzZWNwMjU2azESIDS5zeYUkLCSAJLI6aLXRTPRxstCLPUEI6TgBrAVCHkwGiDk-ffklrHIFW7pKkT8i-YksXi-XXi5h31czUMaVClcpw" - ); - const privateKey = Fixtures.secp256K1.privateKey; - await db.storePrismDID( - did, - 0, - privateKey, - did.toString(), - "defaultalias" - ); - expect((await db.getAllPrismDIDs()).length).toBe(1); - }); - - it(storageName + "Should store a new Prism DID and its privateKeys and fetch it by its alias", async ({ expect }) => { - const did = SDK.Domain.DID.fromString( - "did:prism:733e594871d7700d35e6116011a08fc11e88ff9d366d8b5571ffc1aa18d249ea:Ct8BCtwBEnQKH2F1dGhlbnRpY2F0aW9uYXV0aGVudGljYXRpb25LZXkQBEJPCglzZWNwMjU2azESIDS5zeYUkLCSAJLI6aLXRTPRxstCLPUEI6TgBrAVCHkwGiDk-ffklrHIFW7pKkT8i-YksXi-XXi5h31czUMaVClcpxJkCg9tYXN0ZXJtYXN0ZXJLZXkQAUJPCglzZWNwMjU2azESIDS5zeYUkLCSAJLI6aLXRTPRxstCLPUEI6TgBrAVCHkwGiDk-ffklrHIFW7pKkT8i-YksXi-XXi5h31czUMaVClcpw" - ); - const alias = "default"; - const privateKey = Fixtures.secp256K1.privateKey; - await db.storePrismDID(did, 0, privateKey, null, alias); - expect((await db.getDIDInfoByAlias(alias)).length).toBe(1); - }); - - it(storageName + "Should store a Message duplicate message", async ({ expect }) => { - const message = createMessage(); - await db.storeMessage(message); - await db.storeMessage(message); - }); - - it(storageName + "Should store a Message and fetch it", async ({ expect }) => { - const message = createMessage(); - await db.storeMessage(message); - const dbMesaage = await db.getMessage(message.id); - expect(dbMesaage).not.toBe(null); - expect(dbMesaage!.id).toBe(message.id); - }); - - it(storageName + "Should store a Message and update it", async ({ expect }) => { - const message = createMessage(); - await db.storeMessage(message); - await db.storeMessage(message); - const dbMesaage = await db.getMessage(message.id); - expect(dbMesaage).not.toBe(null); - expect(dbMesaage!.id).toBe(message.id); - }); - - it(storageName + "Should get all the messages", async ({ expect }) => { - const allMessages = await db.getAllMessages(); - expect(allMessages.length).toBe(0); - }); - - it(storageName + "Should fetch stored messages either by type or by did", async ({ expect }) => { - const from = SDK.Domain.DID.fromString("did:prism:123456"); - const to = SDK.Domain.DID.fromString("did:prism:654321"); - const from2 = SDK.Domain.DID.fromString("did:prism:12345644"); - const to2 = SDK.Domain.DID.fromString("did:prism:65432133"); - - await db.storeMessages([ - createMessage(from, to, SDK.Domain.MessageDirection.RECEIVED), - createMessage(from2, to2, SDK.Domain.MessageDirection.SENT), - ]); - - const byType = await db.getAllMessagesOfType(messageType); - expect(byType.length).toBe(2); - - const byType2 = await db.getAllMessagesOfType(messageType, from); - expect(byType2.length).toBe(1); - - const byType4 = await db.getAllMessagesSent(); - expect(byType4.length).toBe(1); - - const byType5 = await db.getAllMessagesReceived(); - expect(byType5.length).toBe(1); - - const byType6 = await db.getAllMessagesSentTo(to2); - expect(byType6.length).toBe(1); - - const byType7 = await db.getAllMessagesReceivedFrom(from); - expect(byType7.length).toBe(1); - - const byType8 = await db.getAllMessagesByFromToDID(from, to); - expect(byType8.length).toBe(1); - - const byType9 = await db.getAllMessagesByDID(from); - expect(byType9.length).toBe(1); - - const byType10 = await db.getAllMessages(); - expect(byType10.length).toBe(2); - }); - - it(storageName + "Should return null if message is not found by id ", async ({ expect }) => { - const dbMesaage = await db.getMessage("notfound"); - expect(dbMesaage).toBe(null); - }); - - it(storageName + "Should store multiple messages", async ({ expect }) => { - await db.storeMessages([createMessage(), createMessage()]); - }); - - it(storageName + "Should store a peerDID", async ({ expect }) => { - const did = new SDK.Domain.DID( - "did", - "peer", - "2.Ez6LSms555YhFthn1WV8ciDBpZm86hK9tp83WojJUmxPGk1hZ.Vz6MkmdBjMyB4TS5UbbQw54szm8yvMMf1ftGV2sQVYAxaeWhE.SeyJpZCI6Im5ldy1pZCIsInQiOiJkbSIsInMiOiJodHRwczovL21lZGlhdG9yLnJvb3RzaWQuY2xvdWQiLCJhIjpbImRpZGNvbW0vdjIiXX0" - ); - expect((await db.getAllPeerDIDs()).length).toBe(0); - await db.storePeerDID(did, [ - Fixtures.ed25519.privateKey, - Fixtures.x25519.privateKey, - ]); - expect((await db.getAllPeerDIDs()).length).toBe(1); - await db.getDIDInfoByDID(did); - }); - - it(storageName + "Should store a didPair", async ({ expect }) => { - const host = SDK.Domain.DID.fromString("did:prism:123456"); - const receiver = SDK.Domain.DID.fromString("did:prism:654321"); - const name = "example"; - await db.storeDIDPair(host, receiver, name); - }); - - it(storageName + "Should get all the didPairs", async ({ expect }) => { - const host = SDK.Domain.DID.fromString("did:prism:123456"); - const receiver = SDK.Domain.DID.fromString("did:prism:654321"); - const name = "example"; - expect((await db.getAllDidPairs()).length).toBe(0); - await db.storeDIDPair(host, receiver, name); - expect((await db.getAllDidPairs()).length).toBe(1); - }); - - it(storageName + "Should get a did pair by its did", async ({ expect }) => { - const host = SDK.Domain.DID.fromString("did:prism:123456"); - const receiver = SDK.Domain.DID.fromString("did:prism:654321"); - const name = "example"; - await db.storeDIDPair(host, receiver, name); - expect(await db.getPairByDID(host)).not.toBe(null); - }); - - it(storageName + "Should return null when a pair is fetched by a non existing did", async ({ expect }) => { - const notfound = SDK.Domain.DID.fromString("did:prism:65432155555"); - expect(await db.getPairByDID(notfound)).toBe(null); - }); - - it(storageName + "Should get a did pair by its name", async ({ expect }) => { - const host = SDK.Domain.DID.fromString("did:prism:123456"); - const receiver = SDK.Domain.DID.fromString("did:prism:654321"); - const name = "example"; - await db.storeDIDPair(host, receiver, name); - expect(await db.getPairByName(name)).not.toBe(null); - }); - - it(storageName + "Should return null when a pair by name is not found", async ({ expect }) => { - expect(await db.getPairByName("not found")).toBe(null); - }); - - it(storageName + "Should store a mediator", async ({ expect }) => { - const host = SDK.Domain.DID.fromString("did:prism:333333"); - const mediator = SDK.Domain.DID.fromString("did:prism:444444"); - const routing = SDK.Domain.DID.fromString("did:prism:555555"); - expect((await db.getAllMediators()).length).toBe(0); - await db.storeMediator(mediator, host, routing); - - expect((await db.getAllMediators()).length).toBe(1); - }); - - it(storageName + "Should go a backup of all the database and restore it", async ({ expect }) => { - const host = SDK.Domain.DID.fromString("did:prism:333333"); - const mediator = SDK.Domain.DID.fromString("did:prism:444444"); - const routing = SDK.Domain.DID.fromString("did:prism:555555"); - expect((await db.getAllMediators()).length).toBe(0); - await db.storeMediator(mediator, host, routing); - expect((await db.getAllMediators()).length).toBe(1); - const backup = await db.backup(); - - if (db && (storage.name === "in-memory" || storage.name === "leveldb")) { - await db.clear(); - } - - if (storage.name === "leveldb") { - if (fs.existsSync(databasePath)) { - fs.rmdirSync(databasePath, { recursive: true }) - } - } - - const restored = await Database.createEncrypted( - { - name: currentDBName, - encryptionKey: defaultPassword, - importData: backup, - storage: storage, - collections: getDefaultCollections() - } - ); - - expect((await restored.getAllMediators()).length).toBe(1); - }); - - it(storageName + "Should throw an error when an incomplete did is loaded from db", async ({ expect }) => { - const did = SDK.Domain.DID.fromString("did:prism:65432133"); - - await (db as any).db.dids.insert({ - did: did.toString(), - method: did.method, - methodId: did.methodId, - schema: did.schema, - }); - expect(db.getDIDInfoByDID(did)).rejects.toThrowError( - "Imposible to recover PrismDIDInfo without its privateKey data." - ); - }); - - it(storageName + "Should get a privateKey by its ID", async ({ expect }) => { - const did = SDK.Domain.DID.fromString("did:prism:65432133"); - - await (db as any).db.privatekeys.insert({ - id: "123", - did: did.toString(), - type: SDK.Domain.KeyTypes.EC, - keySpecification: [ - { - name: "curve", - value: SDK.Domain.Curve.ED25519, - type: "string", - }, - { - name: "curve", - value: SDK.Domain.Curve.ED25519, - type: "string", - }, - { - name: "raw", - value: new Array(32), - type: "string", - }, - ], - }); - expect(await db.getDIDPrivateKeyByID("123")).toHaveProperty("type"); - }); - - const encodeJWTCredential = (cred: object): string => { - const json = JSON.stringify(cred); - const encoded = Buffer.from(json).toString("base64"); - return `${jwtParts[0]}.${encoded}.${jwtParts[2]}`; - }; - - it(storageName + "Should store and fetch a JWT Credential", async ({ expect }) => { - expect((await db.getAllCredentials()).length).toBe(0); - const jwtPayload = Fixtures.createJWTPayload( - "jwtid", - "proof", - SDK.Domain.CredentialType.JWT - ); - const encoded = encodeJWTCredential(jwtPayload); - - const result = await pollux.parseCredential(Buffer.from(encoded), { - type: SDK.Domain.CredentialType.JWT, - }); - await db.storeCredential(result); - const results = await db.getAllCredentials() - expect(results.length).toBe(1); - }); - - it(storageName + "Should store and fetch a JWT Credential and then generate a proof", async ({ expect }) => { - class PresentationRequest { - /** - * @constructor - * @param type - CredentialType the json is related to - * @param json - the raw value - */ - constructor(type: SDK.Domain.CredentialType.AnonCreds, json: SDK.Domain.Anoncreds.PresentationRequest); - constructor(type: SDK.Domain.CredentialType.JWT, json: any); - constructor( - private readonly type: SDK.Domain.CredentialType, - private readonly json: T - ) { } - - /** - * Type guard that the instance is for the given CredentialType - * - * @param type - * @returns {boolean} - */ - isType(type: SDK.Domain.CredentialType.AnonCreds): this is PresentationRequest; - isType(type: SDK.Domain.CredentialType.JWT): this is PresentationRequest; - isType(target: SDK.Domain.CredentialType) { - return this.type === target; - } - - /** - * Get the raw PresentationRequest JSON - * - * @returns JSON - */ - toJSON(): T { - return this.json; - } - } - - expect((await db.getAllCredentials()).length).toBe(0); - const jwtPayload = Fixtures.createJWTPayload( - "jwtid", - "proof", - SDK.Domain.CredentialType.JWT - ); - const encoded = encodeJWTCredential(jwtPayload); - - const parsedCredential = await pollux.parseCredential(Buffer.from(encoded), { - type: SDK.Domain.CredentialType.JWT, - }); - await db.storeCredential(parsedCredential); - - - const credentials = await db.getAllCredentials() - expect(credentials.length).toBe(1); - - const credential = credentials[0]; - const apollo = new Apollo(); - - const pr = new PresentationRequest(SDK.Domain.CredentialType.JWT, { - "options": { - "challenge": "11c91493-01b3-4c4d-ac36-b336bab5bddf", - "domain": "http://localhost:8000/prism-agent" - }, - "presentation_definition": { - "format": null, - "id": "b2a49475-f8ba-4952-a719-a28e909858fa", - "input_descriptors": [], - "name": null, - "purpose": null - } - }); - const key = apollo.createPrivateKey({ - type: SDK.Domain.KeyTypes.EC, - curve: SDK.Domain.Curve.SECP256K1, - seed: Buffer.from(apollo.createRandomSeed().seed.value).toString('hex') - }); - const did = SDK.Domain.DID.fromString("did:prism:333333"); - const result = await pollux.createPresentationProof(pr as any, credential as any, { - did, - privateKey: key - }); - - expect(result).not.to.be.null; - }) - - - - - - it(storageName + "Should store and fetch a Anoncreds Credential", async ({ expect }) => { - expect((await db.getAllCredentials()).length).toBe(0); - const payload = Fixtures.createAnonCredsPayload(); - const result = new AnonCredsCredential({ - ...payload, - values: { - ...(payload.values.map(([varname, val]) => ({ - [varname]: val, - })) as any), - }, - }); - await db.storeCredential(result); - expect((await db.getAllCredentials()).length).toBe(1); - }); - - it(storageName + "Should store and fetch a link secret by its name", async ({ expect }) => { - const name = "test"; - const secret = "12345"; - await db.storeLinkSecret(secret, name); - expect(await db.getLinkSecret(name)).toBe(secret); - }); - - it(storageName + "Should store and fetch a link secret without params", async ({ expect }) => { - const name = "test"; - const secret = "12345"; - await db.storeLinkSecret(secret, name); - expect(await db.getLinkSecret()).toBe(secret); - }); - - it(storageName + "Should return null when no link secret is found", async ({ expect }) => { - expect(await db.getLinkSecret("notfound")).toBe(null); - }); - - it(storageName + "Should store and fetch credential metadata by link secret name", async ({ expect }) => { - const linkSecretName = "test"; - await db.storeCredentialMetadata( - Fixtures.credRequestMeta, - linkSecretName - ); - expect( - (await db.fetchCredentialMetadata(linkSecretName))?.link_secret_name - ).toBe(linkSecretName); - }); - - it(storageName + "should return null when no credentialMetadata is found by the linkSecretName", async ({ expect }) => { - expect(await db.fetchCredentialMetadata("notfound")).toBe(null); - }); - - it(storageName + "Should throw an error if a non storable credential is stored", async ({ expect }) => { - expect(db.storeCredential({ fail: true } as any)).rejects.toThrowError( - new Error("Credential is not storable") - ); - }); - - it(storageName + "Should throw an error if an unrecoverable key is loaded from DB", async ({ expect }) => { - const payload = Fixtures.createAnonCredsPayload(); - const result = new AnonCredsCredential({ - ...payload, - values: { - ...(payload.values.map(([varname, val]) => ({ - [varname]: val, - })) as any), - }, - }); - result.recoveryId = "demo"; - await db.storeCredential(result); - expect(db.getAllCredentials()).rejects.toThrowError( - new Error("Unsupported key type from db storage") - ); - }); - - it(storageName + "Should be able to request models from database", async ({ expect }) => { - const collectionNames = Object.keys(db.db.collections); - for (let collectionName of collectionNames) { - 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.db.collections); - for (let collectionName of collectionNames) { - 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.db.collections); - for (let collectionName of collectionNames) { - 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.db.collections); - for (let collectionName of collectionNames) { - const collection = db.db.collections[collectionName]; - const results = await collection.find().exec(); - expect(results.length).toBe(0) - } - }) - - it(storageName + "Should be able to request remove orm method on credential model", async ({ expect }) => { - const payload = Fixtures.createAnonCredsPayload(); - const result = new AnonCredsCredential({ - ...payload, - values: { - ...(payload.values.map(([varname, val]) => ({ - [varname]: val, - })) as any), - }, - }); - result.recoveryId = "demo"; - await db.storeCredential(result); - - const storedCredential = await db.db.collections.credentials.findOne({ - selector: { - recoveryId: { - $eq: result.recoveryId - } - } - }).exec(); - - const removed = await storedCredential?.remove() - expect(removed?.deleted).toBe(true) - }); - - it(storageName + "Should run migration once the schema version has changed and user had existing data", async ({ expect }) => { - - const forceDatabaseName = `${databaseName}${randomUUID()}` - const db = await Database.createEncrypted<{ - linksecrets: RxCollection< - LinkSecretSchemaType, - LinkSecretMethodTypes, - LinkSecretStaticMethodTypes - > - }>( - { - name: forceDatabaseName, - encryptionKey: defaultPassword, - storage, - collections: { - linksecrets: getDefaultCollections().linksecrets - } - } - ); - - await db.storeLinkSecret("demo123", "demo321"); - - const migrationDB = await Database.createEncrypted<{ - linksecrets: RxCollection< - LinkSecretSchemaType, - LinkSecretMethodTypes, - LinkSecretStaticMethodTypes - > - }>( - { - name: forceDatabaseName, - encryptionKey: defaultPassword, - storage, - collections: { - linksecrets: { - methods: { - toDomainLinkSecret: function toDomainLinkSecret(this: any) { - return this.secreto; - }, - }, - schema: { - version: 1, - primaryKey: "name", - type: "object", - properties: { - name: { - type: "string", - maxLength: 60, - }, - secreto: { - type: "string", - } - }, - encrypted: ["secreto"], - required: ["name", "secreto"], - }, - migrationStrategies: { - // 1 means, this transforms data from version 0 to version 1 - 1: async function (oldDoc) { - oldDoc.secreto = oldDoc.secret; - delete oldDoc.secret - return oldDoc; - } - }, - statics: LinkSecretStaticMethods - } - } - } - ); - - const linkSecret = await migrationDB.getLinkSecret() - expect(linkSecret).toBe("demo123") - - }); - - it(storageName + "Should run migration once the schema version has changed its primaryKey and user had existing data", async ({ expect }) => { - - const forceDatabaseName = `${databaseName}${randomUUID()}` - const db = await Database.createEncrypted<{ - linksecrets: RxCollection< - LinkSecretSchemaType, - LinkSecretMethodTypes, - LinkSecretStaticMethodTypes - > - }>( - { - name: forceDatabaseName, - encryptionKey: defaultPassword, - storage, - collections: getDefaultCollections() - } - ); - - await db.storeLinkSecret("demo123", "demo321"); - - const migrationDB = await Database.createEncrypted<{ - linksecrets: RxCollection< - LinkSecretSchemaType, - LinkSecretMethodTypes, - LinkSecretStaticMethodTypes - > - }>( - { - name: forceDatabaseName, - encryptionKey: defaultPassword, - storage, - collections: { - linksecrets: { - methods: { - toDomainLinkSecret: function toDomainLinkSecret(this: any) { - return this.secreto; - }, - }, - statics: LinkSecretStaticMethods, - schema: { - version: 1, - primaryKey: "name2", - type: "object", - properties: { - name2: { - type: "string", - maxLength: 60, - }, - secreto: { - type: "string", - } - }, - encrypted: ["secreto"], - required: ["name2", "secreto"], - }, - migrationStrategies: { - // 1 means, this transforms data from version 0 to version 1 - 1: async function (oldDoc) { - oldDoc.secreto = oldDoc.secret; - oldDoc.name2 = oldDoc.name; - delete oldDoc.secret - delete oldDoc.name - return oldDoc; - } - } - } - } - } - ); - - const linkSecret = await migrationDB.getLinkSecret() - expect(linkSecret).toBe("demo123") - - }); - - it(storageName + "Should run migration once the schema version has changed and user had existing data over time, with multiple versions", async ({ expect }) => { - - const forceDatabaseName = `${databaseName}${randomUUID()}` - const db = await Database.createEncrypted( - { - name: forceDatabaseName, - encryptionKey: defaultPassword, - storage, - collections: getDefaultCollections() - } - ); - - await db.storeLinkSecret("demo123", "demo321"); - - const migrationDB = await Database.createEncrypted( - { - name: forceDatabaseName, - encryptionKey: defaultPassword, - storage, - collections: { - ...(getDefaultCollections()), - linksecrets: { - methods: { - toDomainLinkSecret: function toDomainLinkSecret(this: any) { - return this.secreto; - }, - }, - statics: LinkSecretStaticMethods, - schema: { - version: 2, - primaryKey: "test", - type: "object", - properties: { - test: { - type: "string", - maxLength: 60, - }, - secreto: { - type: "string", - } - }, - encrypted: ["secreto"], - required: ["test", "secreto"], - }, - migrationStrategies: { - // 1 means, this transforms data from version 0 to version 1 - 1: async function (oldDoc) { - oldDoc.secreto = oldDoc.secret; - delete oldDoc.secret - return oldDoc; - }, - 2: async function (oldDoc) { - if (!oldDoc.test) { - oldDoc.test = oldDoc.name; - delete oldDoc.name - } - return oldDoc; - } - } - } - } - } - ); - - const linkSecret = await migrationDB.getLinkSecret() - expect(linkSecret).toBe("demo123") - - }); - - it(storageName + "Should allow anyone to add new models to the database", async ({ expect }) => { - const forceDatabaseName = `${databaseName}${randomUUID()}` - - const db = await Database.createEncrypted void } - > - }>( - { - name: forceDatabaseName, - encryptionKey: defaultPassword, - storage, - collections: { - ...getDefaultCollections(), - 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.createEncrypted void } - > - }>( - { - name: forceDatabaseName, - encryptionKey: defaultPassword, - storage, - collections: { - ...getDefaultCollections(), - 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 void } - >; - demo2: RxCollection< - LinkSecretSchemaType, - LinkSecretMethodTypes, - { hola: (demo: boolean, demo2: boolean) => void } - >; - }>( - { - name: forceDatabaseName, - encryptionKey: defaultPassword, - storage, - collections: { - ...getDefaultCollections(), - 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.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 as any).credentials).toBeUndefined() - expect(db.db.collections.demo).to.not.toBeUndefined(); - expect(db.db.collections.demo.hola).to.not.toBeUndefined(); - expect(db.hola).to.not.toBeUndefined(); - }) - - }); - }) -}) \ No newline at end of file diff --git a/packages/database/tests/setup.ts b/packages/database/tests/setup.ts deleted file mode 100644 index 8559be2e..00000000 --- a/packages/database/tests/setup.ts +++ /dev/null @@ -1,18 +0,0 @@ -import "fake-indexeddb/auto"; -import { TextEncoder, TextDecoder } from "util"; -import nodeCrypto from "crypto"; -import { RxDBDevModePlugin } from "rxdb/plugins/dev-mode"; -import { addRxPlugin } from "rxdb"; - - -if (process.env.NODE_ENV === "debug") { - addRxPlugin(RxDBDevModePlugin); -} - -Object.defineProperty(globalThis, "crypto", { - value: { - getRandomValues: (arr) => nodeCrypto.getRandomValues(arr), - }, -}); - -Object.assign(global, { TextDecoder, TextEncoder }); diff --git a/packages/database/tsconfig.json b/packages/database/tsconfig.json deleted file mode 100644 index 19742a26..00000000 --- a/packages/database/tsconfig.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "extends": "../../tsconfig.json", - "compilerOptions": { - "rootDir": "./src", - "declarationDir": "./build", - }, - "include": [ - "src" - ] -} \ No newline at end of file diff --git a/packages/database/vitest.config.ts b/packages/database/vitest.config.ts deleted file mode 100644 index 16c4c803..00000000 --- a/packages/database/vitest.config.ts +++ /dev/null @@ -1,28 +0,0 @@ -/// -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/iagon/.gitignore b/packages/iagon/.gitignore deleted file mode 100644 index cc67e869..00000000 --- a/packages/iagon/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -coverage/**/*.html -coverage/**/*.css -coverage/**/*.js -coverage/**/*.png \ No newline at end of file diff --git a/packages/iagon/CHANGELOG.md b/packages/iagon/CHANGELOG.md deleted file mode 100644 index 182baf5e..00000000 --- a/packages/iagon/CHANGELOG.md +++ /dev/null @@ -1,9 +0,0 @@ -## @pluto-encrypted/iagon [1.0.2](https://github.com/atala-community-projects/pluto-encrypted/compare/@pluto-encrypted/iagon@1.0.1...@pluto-encrypted/iagon@1.0.2) (2024-02-08) - - - - - -### Dependencies - -* **@pluto-encrypted/test-suite:** upgraded to 1.12.1 diff --git a/packages/iagon/LICENSE b/packages/iagon/LICENSE deleted file mode 100644 index 216af719..00000000 --- a/packages/iagon/LICENSE +++ /dev/null @@ -1,201 +0,0 @@ - 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/iagon/README.md b/packages/iagon/README.md deleted file mode 100644 index 29734505..00000000 --- a/packages/iagon/README.md +++ /dev/null @@ -1,5 +0,0 @@ -# @pluto-encrypted/iagon -This package contains a RXDB compatible wrapper over iagon and can be used as database engine inside @pluto-encrypted package with secure database encryption. - -The package is not yet ready for use, the API initialisation takes too long -breakes the integration with the agent completely. \ No newline at end of file diff --git a/packages/iagon/coverage/.tmp/coverage-0.json b/packages/iagon/coverage/.tmp/coverage-0.json deleted file mode 100644 index 57e75bd8..00000000 --- a/packages/iagon/coverage/.tmp/coverage-0.json +++ /dev/null @@ -1 +0,0 @@ -{"/home/runner/work/pluto-encrypted/pluto-encrypted/packages/iagon/src/IagonStorage/api.ts":{"path":"/home/runner/work/pluto-encrypted/pluto-encrypted/packages/iagon/src/IagonStorage/api.ts","statementMap":{"0":{"start":{"line":5,"column":4},"end":{"line":5,"column":33}},"1":{"start":{"line":6,"column":4},"end":{"line":6,"column":43}},"2":{"start":{"line":9,"column":4},"end":{"line":9,"column":60}},"3":{"start":{"line":12,"column":4},"end":{"line":22,"column":5}},"4":{"start":{"line":13,"column":24},"end":{"line":13,"column":34}},"5":{"start":{"line":14,"column":23},"end":{"line":14,"column":51}},"6":{"start":{"line":15,"column":22},"end":{"line":15,"column":32}},"7":{"start":{"line":16,"column":34},"end":{"line":16,"column":53}},"8":{"start":{"line":17,"column":6},"end":{"line":17,"column":98}},"9":{"start":{"line":18,"column":6},"end":{"line":18,"column":39}},"10":{"start":{"line":20,"column":6},"end":{"line":20,"column":83}},"11":{"start":{"line":21,"column":6},"end":{"line":21,"column":33}},"12":{"start":{"line":25,"column":20},"end":{"line":25,"column":66}},"13":{"start":{"line":26,"column":16},"end":{"line":26,"column":28}},"14":{"start":{"line":27,"column":20},"end":{"line":33,"column":5}},"15":{"start":{"line":34,"column":17},"end":{"line":34,"column":47}},"16":{"start":{"line":35,"column":4},"end":{"line":35,"column":16}},"17":{"start":{"line":38,"column":20},"end":{"line":38,"column":98}},"18":{"start":{"line":39,"column":16},"end":{"line":39,"column":104}},"19":{"start":{"line":40,"column":20},"end":{"line":46,"column":5}},"20":{"start":{"line":47,"column":21},"end":{"line":47,"column":51}},"21":{"start":{"line":48,"column":25},"end":{"line":48,"column":38}},"22":{"start":{"line":49,"column":4},"end":{"line":51,"column":5}},"23":{"start":{"line":50,"column":6},"end":{"line":50,"column":44}},"24":{"start":{"line":52,"column":24},"end":{"line":52,"column":111}},"25":{"start":{"line":53,"column":4},"end":{"line":53,"column":23}},"26":{"start":{"line":56,"column":20},"end":{"line":56,"column":74}},"27":{"start":{"line":57,"column":25},"end":{"line":67,"column":5}},"28":{"start":{"line":68,"column":21},"end":{"line":68,"column":58}},"29":{"start":{"line":69,"column":4},"end":{"line":69,"column":106}},"30":{"start":{"line":72,"column":20},"end":{"line":72,"column":98}},"31":{"start":{"line":73,"column":16},"end":{"line":73,"column":104}},"32":{"start":{"line":74,"column":20},"end":{"line":80,"column":5}},"33":{"start":{"line":81,"column":21},"end":{"line":81,"column":51}},"34":{"start":{"line":82,"column":25},"end":{"line":82,"column":38}},"35":{"start":{"line":83,"column":4},"end":{"line":85,"column":5}},"36":{"start":{"line":84,"column":6},"end":{"line":84,"column":44}},"37":{"start":{"line":86,"column":18},"end":{"line":86,"column":93}},"38":{"start":{"line":87,"column":4},"end":{"line":87,"column":17}},"39":{"start":{"line":90,"column":43},"end":{"line":90,"column":55}},"40":{"start":{"line":91,"column":17},"end":{"line":95,"column":5}},"41":{"start":{"line":96,"column":4},"end":{"line":98,"column":5}},"42":{"start":{"line":97,"column":6},"end":{"line":97,"column":51}},"43":{"start":{"line":99,"column":20},"end":{"line":99,"column":61}},"44":{"start":{"line":100,"column":20},"end":{"line":108,"column":5}},"45":{"start":{"line":109,"column":21},"end":{"line":109,"column":51}},"46":{"start":{"line":110,"column":25},"end":{"line":110,"column":38}},"47":{"start":{"line":111,"column":4},"end":{"line":113,"column":5}},"48":{"start":{"line":112,"column":6},"end":{"line":112,"column":44}},"49":{"start":{"line":114,"column":22},"end":{"line":114,"column":39}},"50":{"start":{"line":115,"column":4},"end":{"line":115,"column":21}},"51":{"start":{"line":118,"column":20},"end":{"line":118,"column":76}},"52":{"start":{"line":119,"column":18},"end":{"line":125,"column":5}},"53":{"start":{"line":126,"column":21},"end":{"line":126,"column":51}},"54":{"start":{"line":127,"column":4},"end":{"line":127,"column":25}},"55":{"start":{"line":130,"column":21},"end":{"line":130,"column":35}},"56":{"start":{"line":131,"column":4},"end":{"line":136,"column":5}},"57":{"start":{"line":132,"column":6},"end":{"line":135,"column":7}},"58":{"start":{"line":133,"column":22},"end":{"line":133,"column":30}},"59":{"start":{"line":134,"column":8},"end":{"line":134,"column":36}},"60":{"start":{"line":137,"column":4},"end":{"line":137,"column":20}},"61":{"start":{"line":140,"column":20},"end":{"line":140,"column":21}},"62":{"start":{"line":141,"column":4},"end":{"line":147,"column":5}},"63":{"start":{"line":142,"column":6},"end":{"line":146,"column":7}},"64":{"start":{"line":143,"column":8},"end":{"line":143,"column":32}},"65":{"start":{"line":145,"column":8},"end":{"line":145,"column":71}},"66":{"start":{"line":148,"column":4},"end":{"line":148,"column":28}},"67":{"start":{"line":151,"column":20},"end":{"line":151,"column":58}},"68":{"start":{"line":152,"column":17},"end":{"line":156,"column":6}},"69":{"start":{"line":157,"column":4},"end":{"line":157,"column":77}},"70":{"start":{"line":158,"column":18},"end":{"line":165,"column":5}},"71":{"start":{"line":166,"column":4},"end":{"line":166,"column":75}},"72":{"start":{"line":167,"column":21},"end":{"line":167,"column":51}},"73":{"start":{"line":168,"column":25},"end":{"line":168,"column":38}},"74":{"start":{"line":169,"column":4},"end":{"line":171,"column":5}},"75":{"start":{"line":170,"column":6},"end":{"line":170,"column":44}},"76":{"start":{"line":172,"column":4},"end":{"line":172,"column":29}}},"fnMap":{"0":{"name":"(anonymous_0)","decl":{"start":{"line":4,"column":2},"end":{"line":4,"column":3}},"loc":{"start":{"line":4,"column":26},"end":{"line":7,"column":3}},"line":4},"1":{"name":"(anonymous_1)","decl":{"start":{"line":8,"column":2},"end":{"line":8,"column":3}},"loc":{"start":{"line":8,"column":22},"end":{"line":10,"column":3}},"line":8},"2":{"name":"(anonymous_2)","decl":{"start":{"line":11,"column":2},"end":{"line":11,"column":3}},"loc":{"start":{"line":11,"column":28},"end":{"line":23,"column":3}},"line":11},"3":{"name":"(anonymous_3)","decl":{"start":{"line":24,"column":2},"end":{"line":24,"column":3}},"loc":{"start":{"line":24,"column":27},"end":{"line":36,"column":3}},"line":24},"4":{"name":"(anonymous_4)","decl":{"start":{"line":37,"column":2},"end":{"line":37,"column":3}},"loc":{"start":{"line":37,"column":42},"end":{"line":54,"column":3}},"line":37},"5":{"name":"(anonymous_5)","decl":{"start":{"line":55,"column":2},"end":{"line":55,"column":3}},"loc":{"start":{"line":55,"column":25},"end":{"line":70,"column":3}},"line":55},"6":{"name":"(anonymous_6)","decl":{"start":{"line":71,"column":2},"end":{"line":71,"column":3}},"loc":{"start":{"line":71,"column":36},"end":{"line":88,"column":3}},"line":71},"7":{"name":"(anonymous_7)","decl":{"start":{"line":89,"column":2},"end":{"line":89,"column":3}},"loc":{"start":{"line":89,"column":38},"end":{"line":116,"column":3}},"line":89},"8":{"name":"(anonymous_8)","decl":{"start":{"line":117,"column":2},"end":{"line":117,"column":3}},"loc":{"start":{"line":117,"column":44},"end":{"line":128,"column":3}},"line":117},"9":{"name":"(anonymous_9)","decl":{"start":{"line":129,"column":2},"end":{"line":129,"column":3}},"loc":{"start":{"line":129,"column":24},"end":{"line":138,"column":3}},"line":129},"10":{"name":"(anonymous_10)","decl":{"start":{"line":139,"column":2},"end":{"line":139,"column":3}},"loc":{"start":{"line":139,"column":28},"end":{"line":149,"column":3}},"line":139},"11":{"name":"(anonymous_11)","decl":{"start":{"line":150,"column":2},"end":{"line":150,"column":3}},"loc":{"start":{"line":150,"column":44},"end":{"line":173,"column":3}},"line":150}},"branchMap":{"0":{"loc":{"start":{"line":39,"column":16},"end":{"line":39,"column":104}},"type":"cond-expr","locations":[{"start":{"line":39,"column":36},"end":{"line":39,"column":89}},{"start":{"line":39,"column":92},"end":{"line":39,"column":104}}],"line":39},"1":{"loc":{"start":{"line":49,"column":4},"end":{"line":51,"column":5}},"type":"if","locations":[{"start":{"line":49,"column":4},"end":{"line":51,"column":5}},{"start":{},"end":{}}],"line":49},"2":{"loc":{"start":{"line":52,"column":24},"end":{"line":52,"column":111}},"type":"cond-expr","locations":[{"start":{"line":52,"column":77},"end":{"line":52,"column":106}},{"start":{"line":52,"column":109},"end":{"line":52,"column":111}}],"line":52},"3":{"loc":{"start":{"line":52,"column":24},"end":{"line":52,"column":74}},"type":"binary-expr","locations":[{"start":{"line":52,"column":24},"end":{"line":52,"column":41}},{"start":{"line":52,"column":45},"end":{"line":52,"column":74}}],"line":52},"4":{"loc":{"start":{"line":69,"column":23},"end":{"line":69,"column":104}},"type":"cond-expr","locations":[{"start":{"line":69,"column":59},"end":{"line":69,"column":72}},{"start":{"line":69,"column":75},"end":{"line":69,"column":104}}],"line":69},"5":{"loc":{"start":{"line":73,"column":16},"end":{"line":73,"column":104}},"type":"cond-expr","locations":[{"start":{"line":73,"column":36},"end":{"line":73,"column":89}},{"start":{"line":73,"column":92},"end":{"line":73,"column":104}}],"line":73},"6":{"loc":{"start":{"line":83,"column":4},"end":{"line":85,"column":5}},"type":"if","locations":[{"start":{"line":83,"column":4},"end":{"line":85,"column":5}},{"start":{},"end":{}}],"line":83},"7":{"loc":{"start":{"line":86,"column":18},"end":{"line":86,"column":93}},"type":"cond-expr","locations":[{"start":{"line":86,"column":65},"end":{"line":86,"column":88}},{"start":{"line":86,"column":91},"end":{"line":86,"column":93}}],"line":86},"8":{"loc":{"start":{"line":86,"column":18},"end":{"line":86,"column":62}},"type":"binary-expr","locations":[{"start":{"line":86,"column":18},"end":{"line":86,"column":35}},{"start":{"line":86,"column":39},"end":{"line":86,"column":62}}],"line":86},"9":{"loc":{"start":{"line":96,"column":4},"end":{"line":98,"column":5}},"type":"if","locations":[{"start":{"line":96,"column":4},"end":{"line":98,"column":5}},{"start":{},"end":{}}],"line":96},"10":{"loc":{"start":{"line":111,"column":4},"end":{"line":113,"column":5}},"type":"if","locations":[{"start":{"line":111,"column":4},"end":{"line":113,"column":5}},{"start":{},"end":{}}],"line":111},"11":{"loc":{"start":{"line":132,"column":6},"end":{"line":135,"column":7}},"type":"if","locations":[{"start":{"line":132,"column":6},"end":{"line":135,"column":7}},{"start":{},"end":{}}],"line":132},"12":{"loc":{"start":{"line":142,"column":6},"end":{"line":146,"column":7}},"type":"if","locations":[{"start":{"line":142,"column":6},"end":{"line":146,"column":7}},{"start":{"line":144,"column":13},"end":{"line":146,"column":7}}],"line":142},"13":{"loc":{"start":{"line":169,"column":4},"end":{"line":171,"column":5}},"type":"if","locations":[{"start":{"line":169,"column":4},"end":{"line":171,"column":5}},{"start":{},"end":{}}],"line":169}},"s":{"0":0,"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0,"15":0,"16":0,"17":0,"18":0,"19":0,"20":0,"21":0,"22":0,"23":0,"24":0,"25":0,"26":0,"27":0,"28":0,"29":0,"30":0,"31":0,"32":0,"33":0,"34":0,"35":0,"36":0,"37":0,"38":0,"39":0,"40":0,"41":0,"42":0,"43":0,"44":0,"45":0,"46":0,"47":0,"48":0,"49":0,"50":0,"51":0,"52":0,"53":0,"54":0,"55":0,"56":0,"57":0,"58":0,"59":0,"60":0,"61":0,"62":0,"63":0,"64":0,"65":0,"66":0,"67":0,"68":0,"69":0,"70":0,"71":0,"72":0,"73":0,"74":0,"75":0,"76":0},"f":{"0":0,"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0},"b":{"0":[0,0],"1":[0,0],"2":[0,0],"3":[0,0],"4":[0,0],"5":[0,0],"6":[0,0],"7":[0,0],"8":[0,0],"9":[0,0],"10":[0,0],"11":[0,0],"12":[0,0],"13":[0,0]},"inputSourceMap":{"version":3,"sources":["/home/runner/work/pluto-encrypted/pluto-encrypted/packages/iagon/src/IagonStorage/api.ts"],"sourcesContent":["import axios, { AxiosRequestConfig } from 'axios';\n\n\nimport { IagonFile, IagonFolder, IagonInternalParameters, IagonResponse } from \"./types\";\n\nexport class IagonAPI {\n private baseUrl = \"https://gw.iagon.com/\";\n constructor(private parameters: IagonInternalParameters) { }\n\n get iagonPassword() {\n return Buffer.from(this.parameters.password).toString()\n }\n\n private async runRequest | any>(options: AxiosRequestConfig) {\n try {\n const startTime = Date.now();\n const response = await axios.request(options);\n const endTime = Date.now();\n const elapsedMilliseconds = endTime - startTime;\n console.log(`Request \"${options.method}\":\"${options.url}\" took ${elapsedMilliseconds} ms.`);\n return Promise.resolve(response)\n } catch (err) {\n console.error(`Request \"${options.method}\":\"${options.url}\" failed: ${err}`);\n return Promise.reject(err)\n }\n }\n\n async removeFile(fileId: string) {\n const baseUrl = `${this.baseUrl}api/v2/storage/file/${fileId}`;\n const url = `${baseUrl}`\n const options = {\n 'method': 'DELETE',\n 'url': url,\n 'headers': {\n 'x-api-key': this.parameters.apiKey\n }\n };\n const file = await this.runRequest(options)\n return file\n }\n async getDirectories(parentDirectoryId?: string) {\n const baseUrl = `${this.baseUrl}api/v2/storage/directory?visibility=private&listingType=index`\n const url = parentDirectoryId ? `${baseUrl}&parent_directory_id=${parentDirectoryId}` : `${baseUrl}`\n const options = {\n 'method': 'GET',\n 'url': url,\n 'headers': {\n 'x-api-key': this.parameters.apiKey\n }\n };\n\n const response = await this.runRequest>(options)\n\n const jsonResponse = response.data;\n if (!jsonResponse.success) {\n throw new Error(jsonResponse.message)\n }\n\n const directories = jsonResponse.data && jsonResponse.data.directories ? jsonResponse.data.directories : [];\n return directories\n }\n async getFile(options: { parentDirectoryId?: string | undefined; file: IagonFile; }) {\n const baseUrl = `${this.baseUrl}api/v2/storage/parameterized/download`\n var requestOptions = {\n 'method': 'POST',\n 'url': baseUrl,\n 'headers': {\n 'x-api-key': this.parameters.apiKey\n },\n 'data': {\n \"id\": options.file._id,\n \"password\": this.iagonPassword\n }\n };\n const response = await this.runRequest(requestOptions)\n return Buffer.from(typeof response.data === \"string\" ? response.data : JSON.stringify(response.data));\n }\n async getFiles(parentDirectoryId?: string) {\n const baseUrl = `${this.baseUrl}api/v2/storage/directory?visibility=private&listingType=index`\n const url = parentDirectoryId ? `${baseUrl}&parent_directory_id=${parentDirectoryId}` : `${baseUrl}`\n const options = {\n 'method': 'GET',\n 'url': url,\n 'headers': {\n 'x-api-key': this.parameters.apiKey\n }\n };\n const response = await this.runRequest>(options);\n\n const jsonResponse: IagonResponse<{\n directories: IagonFolder[],\n files: IagonFile[]\n }> = response.data;\n\n if (!jsonResponse.success) {\n throw new Error(jsonResponse.message)\n }\n const files = jsonResponse.data && jsonResponse.data.files ? jsonResponse.data.files : [];\n return files\n }\n async createDirectory(queryOptions: { parentDirectoryId?: string, dirName: string }) {\n const { dirName, parentDirectoryId } = queryOptions\n const body: any = {\n \"directory_name\": dirName,\n \"visibility\": \"private\",\n \"index_listing\": true\n }\n\n if (parentDirectoryId) {\n body.parent_directory_id = parentDirectoryId;\n }\n\n const baseUrl = `${this.baseUrl}api/v2/storage/directory`\n const options = {\n 'method': 'POST',\n 'url': baseUrl,\n 'headers': {\n 'Content-Type': 'application/json',\n 'x-api-key': this.parameters.apiKey\n },\n data: JSON.stringify(body)\n };\n\n const response = await this.runRequest>(options)\n const jsonResponse: IagonResponse = response.data;\n if (!jsonResponse.success) {\n throw new Error(jsonResponse.message)\n }\n\n const directory = jsonResponse.data\n return directory\n }\n async removeDirectory(dirname: IagonFolder, recursive: true) {\n const baseUrl = `${this.baseUrl}api/v2/storage/directory/${dirname._id}`\n var options = {\n 'method': 'DELETE',\n 'url': baseUrl,\n 'headers': {\n 'x-api-key': this.parameters.apiKey\n }\n };\n const response = await this.runRequest(options);\n return response.data\n }\n private objectToFormData(obj) {\n const formData = new FormData();\n for (const key in obj) {\n if (obj.hasOwnProperty(key)) {\n const value = obj[key];\n formData.append(key, value);\n }\n }\n return formData;\n }\n private getFormDataSize(formData) {\n let totalSize = 0;\n for (const [key, value] of formData.entries()) {\n if (value instanceof Blob) {\n totalSize += value.size;\n } else {\n totalSize += new TextEncoder().encode(value.toString()).length;\n }\n }\n return totalSize / 1024;\n }\n async uploadFile(dirname: IagonFolder, file: string, contents: Uint8Array) {\n const baseUrl = `${this.baseUrl}api/v2/storage/upload`;\n const body = this.objectToFormData({\n \"visibility\": \"private\",\n \"password\": this.iagonPassword,\n 'directoryId': dirname._id\n });\n body.append(\"file\", new Blob([contents], { type: \"platin/text\" }), file)\n var options = {\n 'method': 'POST',\n 'url': baseUrl,\n 'headers': {\n 'x-api-key': this.parameters.apiKey\n },\n data: body\n };\n console.log(`Uploading aproximately ${this.getFormDataSize(body)} kb`)\n const response = await this.runRequest>(options);\n const jsonResponse: IagonResponse = response.data;\n if (!jsonResponse.success) {\n throw new Error(jsonResponse.message)\n }\n return jsonResponse.data\n }\n}"],"mappings":"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","names":[]},"_coverageSchema":"1a1c01bbd47fc00a2c39e90264f33305004495a9","hash":"08e641d43daae0a113a9957a7468719dea845441"},"/home/runner/work/pluto-encrypted/pluto-encrypted/packages/iagon/src/IagonStorage/instance.ts":{"path":"/home/runner/work/pluto-encrypted/pluto-encrypted/packages/iagon/src/IagonStorage/instance.ts","statementMap":{"0":{"start":{"line":9,"column":4},"end":{"line":9,"column":37}},"1":{"start":{"line":10,"column":4},"end":{"line":10,"column":31}},"2":{"start":{"line":11,"column":4},"end":{"line":11,"column":27}},"3":{"start":{"line":12,"column":4},"end":{"line":12,"column":25}},"4":{"start":{"line":13,"column":4},"end":{"line":13,"column":41}},"5":{"start":{"line":14,"column":4},"end":{"line":14,"column":29}},"6":{"start":{"line":15,"column":4},"end":{"line":15,"column":31}},"7":{"start":{"line":16,"column":4},"end":{"line":16,"column":49}},"8":{"start":{"line":17,"column":4},"end":{"line":17,"column":34}},"9":{"start":{"line":18,"column":4},"end":{"line":18,"column":75}},"10":{"start":{"line":21,"column":21},"end":{"line":21,"column":87}},"11":{"start":{"line":22,"column":26},"end":{"line":22,"column":76}},"12":{"start":{"line":22,"column":52},"end":{"line":22,"column":75}},"13":{"start":{"line":23,"column":22},"end":{"line":23,"column":24}},"14":{"start":{"line":24,"column":4},"end":{"line":29,"column":5}},"15":{"start":{"line":25,"column":26},"end":{"line":25,"column":68}},"16":{"start":{"line":26,"column":18},"end":{"line":26,"column":65}},"17":{"start":{"line":27,"column":17},"end":{"line":27,"column":38}},"18":{"start":{"line":28,"column":6},"end":{"line":28,"column":26}},"19":{"start":{"line":30,"column":4},"end":{"line":30,"column":21}},"20":{"start":{"line":33,"column":22},"end":{"line":33,"column":24}},"21":{"start":{"line":34,"column":4},"end":{"line":45,"column":5}},"22":{"start":{"line":35,"column":23},"end":{"line":35,"column":59}},"23":{"start":{"line":36,"column":6},"end":{"line":44,"column":7}},"24":{"start":{"line":37,"column":8},"end":{"line":39,"column":9}},"25":{"start":{"line":38,"column":10},"end":{"line":38,"column":35}},"26":{"start":{"line":40,"column":24},"end":{"line":40,"column":46}},"27":{"start":{"line":41,"column":8},"end":{"line":43,"column":9}},"28":{"start":{"line":42,"column":10},"end":{"line":42,"column":35}},"29":{"start":{"line":46,"column":4},"end":{"line":46,"column":21}},"30":{"start":{"line":49,"column":33},"end":{"line":49,"column":46}},"31":{"start":{"line":50,"column":21},"end":{"line":50,"column":35}},"32":{"start":{"line":51,"column":25},"end":{"line":51,"column":46}},"33":{"start":{"line":52,"column":17},"end":{"line":52,"column":44}},"34":{"start":{"line":53,"column":18},"end":{"line":53,"column":54}},"35":{"start":{"line":54,"column":26},"end":{"line":54,"column":38}},"36":{"start":{"line":55,"column":25},"end":{"line":58,"column":5}},"37":{"start":{"line":59,"column":28},"end":{"line":59,"column":43}},"38":{"start":{"line":60,"column":20},"end":{"line":60,"column":22}},"39":{"start":{"line":61,"column":4},"end":{"line":65,"column":5}},"40":{"start":{"line":62,"column":6},"end":{"line":62,"column":50}},"41":{"start":{"line":64,"column":6},"end":{"line":64,"column":72}},"42":{"start":{"line":64,"column":53},"end":{"line":64,"column":69}},"43":{"start":{"line":66,"column":37},"end":{"line":74,"column":6}},"44":{"start":{"line":67,"column":6},"end":{"line":73,"column":7}},"45":{"start":{"line":68,"column":8},"end":{"line":68,"column":58}},"46":{"start":{"line":68,"column":40},"end":{"line":68,"column":56}},"47":{"start":{"line":70,"column":8},"end":{"line":72,"column":11}},"48":{"start":{"line":71,"column":10},"end":{"line":71,"column":82}},"49":{"start":{"line":71,"column":57},"end":{"line":71,"column":80}},"50":{"start":{"line":75,"column":4},"end":{"line":85,"column":5}},"51":{"start":{"line":76,"column":6},"end":{"line":76,"column":40}},"52":{"start":{"line":77,"column":6},"end":{"line":77,"column":40}},"53":{"start":{"line":78,"column":6},"end":{"line":82,"column":7}},"54":{"start":{"line":79,"column":8},"end":{"line":79,"column":47}},"55":{"start":{"line":81,"column":8},"end":{"line":81,"column":50}},"56":{"start":{"line":84,"column":6},"end":{"line":84,"column":43}},"57":{"start":{"line":86,"column":22},"end":{"line":86,"column":46}},"58":{"start":{"line":87,"column":24},"end":{"line":87,"column":64}},"59":{"start":{"line":88,"column":4},"end":{"line":90,"column":5}},"60":{"start":{"line":89,"column":6},"end":{"line":89,"column":31}},"61":{"start":{"line":91,"column":20},"end":{"line":95,"column":5}},"62":{"start":{"line":96,"column":27},"end":{"line":96,"column":78}},"63":{"start":{"line":97,"column":4},"end":{"line":97,"column":47}},"64":{"start":{"line":98,"column":4},"end":{"line":98,"column":53}},"65":{"start":{"line":99,"column":4},"end":{"line":101,"column":6}},"66":{"start":{"line":104,"column":19},"end":{"line":104,"column":50}},"67":{"start":{"line":105,"column":4},"end":{"line":108,"column":6}},"68":{"start":{"line":111,"column":4},"end":{"line":111,"column":47}},"69":{"start":{"line":114,"column":4},"end":{"line":114,"column":47}},"70":{"start":{"line":117,"column":4},"end":{"line":117,"column":86}},"71":{"start":{"line":118,"column":4},"end":{"line":118,"column":16}},"72":{"start":{"line":121,"column":4},"end":{"line":121,"column":29}},"73":{"start":{"line":124,"column":4},"end":{"line":124,"column":40}},"74":{"start":{"line":127,"column":4},"end":{"line":127,"column":29}},"75":{"start":{"line":130,"column":4},"end":{"line":130,"column":55}},"76":{"start":{"line":133,"column":4},"end":{"line":133,"column":29}},"77":{"start":{"line":136,"column":41},"end":{"line":136,"column":50}},"78":{"start":{"line":137,"column":22},"end":{"line":137,"column":88}},"79":{"start":{"line":138,"column":4},"end":{"line":143,"column":5}},"80":{"start":{"line":139,"column":26},"end":{"line":139,"column":68}},"81":{"start":{"line":140,"column":20},"end":{"line":140,"column":67}},"82":{"start":{"line":141,"column":24},"end":{"line":141,"column":47}},"83":{"start":{"line":142,"column":6},"end":{"line":142,"column":41}},"84":{"start":{"line":144,"column":4},"end":{"line":144,"column":24}},"85":{"start":{"line":147,"column":24},"end":{"line":147,"column":40}},"86":{"start":{"line":148,"column":16},"end":{"line":151,"column":5}},"87":{"start":{"line":152,"column":22},"end":{"line":152,"column":50}},"88":{"start":{"line":153,"column":18},"end":{"line":153,"column":20}},"89":{"start":{"line":154,"column":4},"end":{"line":169,"column":5}},"90":{"start":{"line":155,"column":24},"end":{"line":155,"column":66}},"91":{"start":{"line":156,"column":31},"end":{"line":156,"column":83}},"92":{"start":{"line":157,"column":6},"end":{"line":168,"column":7}},"93":{"start":{"line":158,"column":8},"end":{"line":160,"column":9}},"94":{"start":{"line":159,"column":10},"end":{"line":159,"column":38}},"95":{"start":{"line":162,"column":8},"end":{"line":166,"column":9}},"96":{"start":{"line":163,"column":10},"end":{"line":163,"column":54}},"97":{"start":{"line":165,"column":10},"end":{"line":165,"column":44}},"98":{"start":{"line":167,"column":8},"end":{"line":167,"column":36}},"99":{"start":{"line":170,"column":24},"end":{"line":176,"column":5}},"100":{"start":{"line":177,"column":4},"end":{"line":177,"column":35}},"101":{"start":{"line":178,"column":27},"end":{"line":178,"column":53}},"102":{"start":{"line":179,"column":4},"end":{"line":184,"column":5}},"103":{"start":{"line":179,"column":17},"end":{"line":179,"column":18}},"104":{"start":{"line":180,"column":23},"end":{"line":180,"column":40}},"105":{"start":{"line":181,"column":20},"end":{"line":181,"column":50}},"106":{"start":{"line":182,"column":6},"end":{"line":182,"column":90}},"107":{"start":{"line":183,"column":6},"end":{"line":183,"column":45}},"108":{"start":{"line":185,"column":27},"end":{"line":185,"column":53}},"109":{"start":{"line":186,"column":4},"end":{"line":191,"column":5}},"110":{"start":{"line":186,"column":17},"end":{"line":186,"column":18}},"111":{"start":{"line":187,"column":23},"end":{"line":187,"column":40}},"112":{"start":{"line":188,"column":20},"end":{"line":188,"column":50}},"113":{"start":{"line":189,"column":6},"end":{"line":189,"column":90}},"114":{"start":{"line":190,"column":6},"end":{"line":190,"column":45}},"115":{"start":{"line":192,"column":4},"end":{"line":203,"column":5}},"116":{"start":{"line":193,"column":24},"end":{"line":193,"column":70}},"117":{"start":{"line":194,"column":6},"end":{"line":197,"column":8}},"118":{"start":{"line":198,"column":22},"end":{"line":198,"column":27}},"119":{"start":{"line":199,"column":6},"end":{"line":201,"column":9}},"120":{"start":{"line":200,"column":8},"end":{"line":200,"column":32}},"121":{"start":{"line":202,"column":6},"end":{"line":202,"column":48}},"122":{"start":{"line":204,"column":4},"end":{"line":204,"column":32}}},"fnMap":{"0":{"name":"(anonymous_0)","decl":{"start":{"line":8,"column":2},"end":{"line":8,"column":3}},"loc":{"start":{"line":8,"column":86},"end":{"line":19,"column":3}},"line":8},"1":{"name":"(anonymous_1)","decl":{"start":{"line":20,"column":2},"end":{"line":20,"column":3}},"loc":{"start":{"line":20,"column":44},"end":{"line":31,"column":3}},"line":20},"2":{"name":"(anonymous_2)","decl":{"start":{"line":22,"column":42},"end":{"line":22,"column":43}},"loc":{"start":{"line":22,"column":52},"end":{"line":22,"column":75}},"line":22},"3":{"name":"(anonymous_3)","decl":{"start":{"line":32,"column":2},"end":{"line":32,"column":3}},"loc":{"start":{"line":32,"column":60},"end":{"line":47,"column":3}},"line":32},"4":{"name":"(anonymous_4)","decl":{"start":{"line":48,"column":2},"end":{"line":48,"column":3}},"loc":{"start":{"line":48,"column":29},"end":{"line":102,"column":3}},"line":48},"5":{"name":"(anonymous_5)","decl":{"start":{"line":64,"column":42},"end":{"line":64,"column":43}},"loc":{"start":{"line":64,"column":53},"end":{"line":64,"column":69}},"line":64},"6":{"name":"(anonymous_6)","decl":{"start":{"line":66,"column":63},"end":{"line":66,"column":64}},"loc":{"start":{"line":66,"column":74},"end":{"line":74,"column":5}},"line":66},"7":{"name":"(anonymous_7)","decl":{"start":{"line":68,"column":28},"end":{"line":68,"column":29}},"loc":{"start":{"line":68,"column":40},"end":{"line":68,"column":56}},"line":68},"8":{"name":"(anonymous_8)","decl":{"start":{"line":70,"column":26},"end":{"line":70,"column":27}},"loc":{"start":{"line":70,"column":40},"end":{"line":72,"column":9}},"line":70},"9":{"name":"(anonymous_9)","decl":{"start":{"line":71,"column":41},"end":{"line":71,"column":42}},"loc":{"start":{"line":71,"column":57},"end":{"line":71,"column":80}},"line":71},"10":{"name":"(anonymous_10)","decl":{"start":{"line":103,"column":2},"end":{"line":103,"column":3}},"loc":{"start":{"line":103,"column":29},"end":{"line":109,"column":3}},"line":103},"11":{"name":"(anonymous_11)","decl":{"start":{"line":110,"column":2},"end":{"line":110,"column":3}},"loc":{"start":{"line":110,"column":54},"end":{"line":112,"column":3}},"line":110},"12":{"name":"(anonymous_12)","decl":{"start":{"line":113,"column":2},"end":{"line":113,"column":3}},"loc":{"start":{"line":113,"column":46},"end":{"line":115,"column":3}},"line":113},"13":{"name":"(anonymous_13)","decl":{"start":{"line":116,"column":2},"end":{"line":116,"column":3}},"loc":{"start":{"line":116,"column":36},"end":{"line":119,"column":3}},"line":116},"14":{"name":"(anonymous_14)","decl":{"start":{"line":120,"column":2},"end":{"line":120,"column":3}},"loc":{"start":{"line":120,"column":10},"end":{"line":122,"column":3}},"line":120},"15":{"name":"(anonymous_15)","decl":{"start":{"line":123,"column":2},"end":{"line":123,"column":3}},"loc":{"start":{"line":123,"column":17},"end":{"line":125,"column":3}},"line":123},"16":{"name":"(anonymous_16)","decl":{"start":{"line":126,"column":2},"end":{"line":126,"column":3}},"loc":{"start":{"line":126,"column":11},"end":{"line":128,"column":3}},"line":126},"17":{"name":"(anonymous_17)","decl":{"start":{"line":129,"column":2},"end":{"line":129,"column":3}},"loc":{"start":{"line":129,"column":27},"end":{"line":131,"column":3}},"line":129},"18":{"name":"(anonymous_18)","decl":{"start":{"line":132,"column":2},"end":{"line":132,"column":3}},"loc":{"start":{"line":132,"column":45},"end":{"line":134,"column":3}},"line":132},"19":{"name":"(anonymous_19)","decl":{"start":{"line":135,"column":2},"end":{"line":135,"column":3}},"loc":{"start":{"line":135,"column":26},"end":{"line":145,"column":3}},"line":135},"20":{"name":"(anonymous_20)","decl":{"start":{"line":146,"column":2},"end":{"line":146,"column":3}},"loc":{"start":{"line":146,"column":43},"end":{"line":205,"column":3}},"line":146},"21":{"name":"(anonymous_21)","decl":{"start":{"line":199,"column":43},"end":{"line":199,"column":44}},"loc":{"start":{"line":199,"column":54},"end":{"line":201,"column":7}},"line":199}},"branchMap":{"0":{"loc":{"start":{"line":8,"column":72},"end":{"line":8,"column":84}},"type":"default-arg","locations":[{"start":{"line":8,"column":83},"end":{"line":8,"column":84}}],"line":8},"1":{"loc":{"start":{"line":36,"column":6},"end":{"line":44,"column":7}},"type":"if","locations":[{"start":{"line":36,"column":6},"end":{"line":44,"column":7}},{"start":{},"end":{}}],"line":36},"2":{"loc":{"start":{"line":37,"column":8},"end":{"line":39,"column":9}},"type":"if","locations":[{"start":{"line":37,"column":8},"end":{"line":39,"column":9}},{"start":{},"end":{}}],"line":37},"3":{"loc":{"start":{"line":41,"column":8},"end":{"line":43,"column":9}},"type":"if","locations":[{"start":{"line":41,"column":8},"end":{"line":43,"column":9}},{"start":{},"end":{}}],"line":41},"4":{"loc":{"start":{"line":52,"column":17},"end":{"line":52,"column":44}},"type":"cond-expr","locations":[{"start":{"line":52,"column":30},"end":{"line":52,"column":40}},{"start":{"line":52,"column":43},"end":{"line":52,"column":44}}],"line":52},"5":{"loc":{"start":{"line":53,"column":18},"end":{"line":53,"column":54}},"type":"cond-expr","locations":[{"start":{"line":53,"column":32},"end":{"line":53,"column":43}},{"start":{"line":53,"column":46},"end":{"line":53,"column":54}}],"line":53},"6":{"loc":{"start":{"line":61,"column":4},"end":{"line":65,"column":5}},"type":"if","locations":[{"start":{"line":61,"column":4},"end":{"line":65,"column":5}},{"start":{"line":63,"column":11},"end":{"line":65,"column":5}}],"line":61},"7":{"loc":{"start":{"line":67,"column":6},"end":{"line":73,"column":7}},"type":"if","locations":[{"start":{"line":67,"column":6},"end":{"line":73,"column":7}},{"start":{"line":69,"column":13},"end":{"line":73,"column":7}}],"line":67},"8":{"loc":{"start":{"line":75,"column":4},"end":{"line":85,"column":5}},"type":"if","locations":[{"start":{"line":75,"column":4},"end":{"line":85,"column":5}},{"start":{"line":83,"column":11},"end":{"line":85,"column":5}}],"line":75},"9":{"loc":{"start":{"line":78,"column":6},"end":{"line":82,"column":7}},"type":"if","locations":[{"start":{"line":78,"column":6},"end":{"line":82,"column":7}},{"start":{"line":80,"column":13},"end":{"line":82,"column":7}}],"line":78},"10":{"loc":{"start":{"line":88,"column":4},"end":{"line":90,"column":5}},"type":"if","locations":[{"start":{"line":88,"column":4},"end":{"line":90,"column":5}},{"start":{},"end":{}}],"line":88},"11":{"loc":{"start":{"line":88,"column":8},"end":{"line":88,"column":47}},"type":"binary-expr","locations":[{"start":{"line":88,"column":8},"end":{"line":88,"column":20}},{"start":{"line":88,"column":24},"end":{"line":88,"column":47}}],"line":88},"12":{"loc":{"start":{"line":156,"column":31},"end":{"line":156,"column":83}},"type":"binary-expr","locations":[{"start":{"line":156,"column":31},"end":{"line":156,"column":55}},{"start":{"line":156,"column":59},"end":{"line":156,"column":83}}],"line":156},"13":{"loc":{"start":{"line":157,"column":6},"end":{"line":168,"column":7}},"type":"if","locations":[{"start":{"line":157,"column":6},"end":{"line":168,"column":7}},{"start":{"line":161,"column":13},"end":{"line":168,"column":7}}],"line":157},"14":{"loc":{"start":{"line":158,"column":8},"end":{"line":160,"column":9}},"type":"if","locations":[{"start":{"line":158,"column":8},"end":{"line":160,"column":9}},{"start":{},"end":{}}],"line":158},"15":{"loc":{"start":{"line":158,"column":12},"end":{"line":158,"column":87}},"type":"binary-expr","locations":[{"start":{"line":158,"column":12},"end":{"line":158,"column":28}},{"start":{"line":158,"column":32},"end":{"line":158,"column":87}}],"line":158},"16":{"loc":{"start":{"line":162,"column":8},"end":{"line":166,"column":9}},"type":"if","locations":[{"start":{"line":162,"column":8},"end":{"line":166,"column":9}},{"start":{"line":164,"column":15},"end":{"line":166,"column":9}}],"line":162},"17":{"loc":{"start":{"line":162,"column":12},"end":{"line":162,"column":87}},"type":"binary-expr","locations":[{"start":{"line":162,"column":12},"end":{"line":162,"column":28}},{"start":{"line":162,"column":32},"end":{"line":162,"column":87}}],"line":162},"18":{"loc":{"start":{"line":192,"column":4},"end":{"line":203,"column":5}},"type":"if","locations":[{"start":{"line":192,"column":4},"end":{"line":203,"column":5}},{"start":{},"end":{}}],"line":192}},"s":{"0":0,"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0,"15":0,"16":0,"17":0,"18":0,"19":0,"20":0,"21":0,"22":0,"23":0,"24":0,"25":0,"26":0,"27":0,"28":0,"29":0,"30":0,"31":0,"32":0,"33":0,"34":0,"35":0,"36":0,"37":0,"38":0,"39":0,"40":0,"41":0,"42":0,"43":0,"44":0,"45":0,"46":0,"47":0,"48":0,"49":0,"50":0,"51":0,"52":0,"53":0,"54":0,"55":0,"56":0,"57":0,"58":0,"59":0,"60":0,"61":0,"62":0,"63":0,"64":0,"65":0,"66":0,"67":0,"68":0,"69":0,"70":0,"71":0,"72":0,"73":0,"74":0,"75":0,"76":0,"77":0,"78":0,"79":0,"80":0,"81":0,"82":0,"83":0,"84":0,"85":0,"86":0,"87":0,"88":0,"89":0,"90":0,"91":0,"92":0,"93":0,"94":0,"95":0,"96":0,"97":0,"98":0,"99":0,"100":0,"101":0,"102":0,"103":0,"104":0,"105":0,"106":0,"107":0,"108":0,"109":0,"110":0,"111":0,"112":0,"113":0,"114":0,"115":0,"116":0,"117":0,"118":0,"119":0,"120":0,"121":0,"122":0},"f":{"0":0,"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0,"15":0,"16":0,"17":0,"18":0,"19":0,"20":0,"21":0},"b":{"0":[0],"1":[0,0],"2":[0,0],"3":[0,0],"4":[0,0],"5":[0,0],"6":[0,0],"7":[0,0],"8":[0,0],"9":[0,0],"10":[0,0],"11":[0,0],"12":[0,0],"13":[0,0],"14":[0,0],"15":[0,0],"16":[0,0],"17":[0,0],"18":[0,0]},"inputSourceMap":{"version":3,"sources":["/home/runner/work/pluto-encrypted/pluto-encrypted/packages/iagon/src/IagonStorage/instance.ts"],"sourcesContent":["import {\n Subject, type Observable\n} from 'rxjs'\n\nimport { RxStorageInstance, StringKeys, RxDocumentData, RxConflictResultionTask, EventBulk, RxStorageChangeEvent, RxStorageDefaultCheckpoint, RxJsonSchema, getPrimaryFieldOfPrimaryKey, BulkWriteRow, RxConflictResultionTaskSolution, RxDocumentDataById, RxStorageBulkWriteResponse, RxStorageCountResult, RxStorageQueryResult, categorizeBulkWriteRows, ensureNotFalsy, now, getQueryMatcher, getSortComparator } from \"rxdb\";\nimport { IagonInternalParameters, IagonStorageInternals } from './types';\nimport { IagonInternals } from './internals';\nimport { QueryMatcher } from 'rxdb/dist/types/types';\nimport { fixTxPipe } from '@pluto-encrypted/shared';\n\n\nexport class IagonStorageInstance<\n RxDocType,\n> implements RxStorageInstance<\n RxDocType,\n IagonStorageInternals,\n IagonInternalParameters,\n RxStorageDefaultCheckpoint\n> {\n public readonly primaryPath: StringKeys>\n\n public isInitialised = false;\n\n public conflictResultionTasks$ = new Subject>()\n public changes$ = new Subject>, RxStorageDefaultCheckpoint>>()\n\n constructor(\n public databaseName: string,\n public internals: IagonInternals,\n public options: Readonly,\n public schema: Readonly>>,\n public collectionName: string,\n public refCount: number = 0\n ) {\n this.primaryPath = getPrimaryFieldOfPrimaryKey(this.schema.primaryKey)\n }\n\n async findDocumentsById(ids: string[], withDeleted: boolean): Promise> {\n const allFiles = await this.internals.sdk.getFiles(this.internals.__dataFolder._id);\n const matchingFiles = allFiles.filter((file) => ids.includes(file.name));\n const documents: RxDocumentDataById = {}\n for (let file of matchingFiles) {\n const fileContent = await this.internals.sdk.getFile({ file: file })\n const doc = JSON.parse(Buffer.from(fileContent).toString());\n const id = doc[this.primaryPath];\n documents[id] = doc;\n }\n return documents\n }\n\n\n private async resolveDocumentIds(ids: string[], selectorKeys: string[], queryMatcher: QueryMatcher>): Promise>> {\n const documents: Array> = [];\n for (let documentId of ids) {\n const document = await this.internals.get(documentId)\n if (document) {\n if (selectorKeys.length <= 0) {\n documents.push(document)\n }\n const matches = queryMatcher(document)\n if (matches) {\n documents.push(document)\n }\n }\n }\n return documents\n }\n\n async query(preparedQuery: any): Promise> {\n const { queryPlan, query } = preparedQuery\n const selector = query.selector\n const selectorKeys = Object.keys(selector)\n const skip = query.skip ? query.skip : 0\n const limit = query.limit ? query.limit : Infinity\n const skipPlusLimit = skip + limit\n const queryMatcher: QueryMatcher> = getQueryMatcher(\n this.schema,\n query\n )\n\n const queryPlanFields: string[] = queryPlan.index\n const indexes: string[] = []\n if (queryPlanFields.length === 1) {\n indexes.push(fixTxPipe(queryPlanFields[0]!))\n } else {\n indexes.push(...queryPlanFields.map(field => fixTxPipe(field)))\n }\n\n const shouldAddCompoundIndexes = this.schema.indexes?.find((index) => {\n if (typeof index === 'string') {\n return indexes.find((index2) => index2 === index)\n } else {\n return index.find((subIndex) => {\n return subIndex === index.find((indexValue) => indexValue === subIndex)\n })\n }\n })\n\n if (shouldAddCompoundIndexes) {\n indexes.splice(0, indexes.length)\n indexes.push(this.collectionName)\n if (typeof shouldAddCompoundIndexes === 'string') {\n indexes.push(shouldAddCompoundIndexes)\n } else {\n indexes.push(...shouldAddCompoundIndexes)\n }\n } else {\n indexes.unshift(this.collectionName)\n }\n\n const indexName: string = `[${indexes.join('+')}]`\n\n const documentIds = await this.internals.getIndex(indexName)\n\n if (!documentIds || documentIds.length <= 0) {\n return { documents: [] }\n }\n\n let documents = await this.resolveDocumentIds(\n documentIds,\n selectorKeys,\n queryMatcher\n )\n\n const sortComparator = getSortComparator(this.schema, preparedQuery.query)\n documents = documents.sort(sortComparator)\n documents = documents.slice(skip, skipPlusLimit)\n return {\n documents\n }\n }\n async count(preparedQuery: any): Promise {\n const result = await this.query(preparedQuery)\n return {\n count: result.documents.length,\n mode: 'fast'\n }\n }\n getAttachmentData(documentId: string, attachmentId: string, digest: string): Promise {\n throw new Error('Method not implemented.');\n }\n getChangedDocumentsSince(limit: number, checkpoint?: any): Promise<{ documents: RxDocumentData[]; checkpoint: any; }> {\n throw new Error('Method not implemented.');\n }\n\n async cleanup(minimumDeletedTime: number): Promise {\n await this.internals.sdk.removeDirectory(this.internals.__collectionFolder, true)\n return true\n }\n close(): Promise {\n return Promise.resolve()\n }\n changeStream(): Observable, any>> {\n return this.changes$.asObservable()\n }\n remove(): Promise {\n return Promise.resolve()\n }\n conflictResultionTasks(): Observable> {\n return this.conflictResultionTasks$.asObservable()\n }\n resolveConflictResultionTask(taskSolution: RxConflictResultionTaskSolution): Promise {\n return Promise.resolve()\n }\n private async getAllDocuments() {\n const allDocuments: Map> = new Map();\n const dataFiles = await this.internals.sdk.getFiles(this.internals.__dataFolder._id);\n for (let file of dataFiles) {\n const fileContent = await this.internals.sdk.getFile({ file });\n const rxDoc: RxDocumentData = JSON.parse(Buffer.from(fileContent).toString())\n const currentId = rxDoc[this.primaryPath] as any;\n allDocuments.set(currentId, rxDoc)\n }\n return allDocuments\n }\n async bulkWrite(documentWrites: BulkWriteRow[], context: string): Promise> {\n const primaryPath = this.primaryPath\n const ret: RxStorageBulkWriteResponse = {\n success: {},\n error: {}\n }\n const documents = await this.getAllDocuments()\n const fixed: BulkWriteRow[] = []\n for (let currentWriteDoc of documentWrites) {\n const currentId = currentWriteDoc.document[this.primaryPath] as any;\n const previousDocument = currentWriteDoc.previous ?? documents.get(currentId)\n if (context === 'data-migrator-delete') {\n if (previousDocument && previousDocument._rev === currentWriteDoc.document._rev) {\n fixed.push(currentWriteDoc)\n }\n } else {\n if (previousDocument && previousDocument._rev !== currentWriteDoc.document._rev) {\n currentWriteDoc.previous = previousDocument\n } else {\n currentWriteDoc.previous = undefined\n }\n fixed.push(currentWriteDoc)\n }\n }\n\n const categorized = categorizeBulkWriteRows(\n this,\n primaryPath as any,\n documents,\n fixed,\n context\n )\n ret.error = categorized.errors\n\n /**\n * Do inserts/updates\n */\n const bulkInsertDocs = categorized.bulkInsertDocs\n for (let i = 0; i < bulkInsertDocs.length; ++i) {\n const writeRow = bulkInsertDocs[i]!\n const docId = writeRow.document[primaryPath]\n await this.internals.bulkPut([writeRow.document], this.collectionName, this.schema)\n ret.success[docId as any] = writeRow.document\n }\n\n const bulkUpdateDocs = categorized.bulkUpdateDocs\n for (let i = 0; i < bulkUpdateDocs.length; ++i) {\n const writeRow = bulkUpdateDocs[i]!\n const docId = writeRow.document[primaryPath]\n await this.internals.bulkPut([writeRow.document], this.collectionName, this.schema)\n ret.success[docId as any] = writeRow.document\n }\n\n if (categorized.eventBulk.events.length > 0) {\n const lastState = ensureNotFalsy(categorized.newestRow).document\n categorized.eventBulk.checkpoint = {\n id: lastState[primaryPath],\n lwt: lastState._meta.lwt\n }\n const endTime = now()\n categorized.eventBulk.events.forEach(event => {\n (event as any).endTime = endTime\n })\n this.changes$.next(categorized.eventBulk)\n }\n\n return Promise.resolve(ret)\n }\n}"],"mappings":"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","names":[]},"_coverageSchema":"1a1c01bbd47fc00a2c39e90264f33305004495a9","hash":"33de6f28eb18f7d6adba3216a2b63a1fe81d29b3"},"/home/runner/work/pluto-encrypted/pluto-encrypted/packages/iagon/src/IagonStorage/internals.ts":{"path":"/home/runner/work/pluto-encrypted/pluto-encrypted/packages/iagon/src/IagonStorage/internals.ts","statementMap":{"0":{"start":{"line":6,"column":4},"end":{"line":6,"column":29}},"1":{"start":{"line":7,"column":4},"end":{"line":7,"column":45}},"2":{"start":{"line":8,"column":4},"end":{"line":8,"column":40}},"3":{"start":{"line":11,"column":4},"end":{"line":19,"column":7}},"4":{"start":{"line":12,"column":6},"end":{"line":17,"column":7}},"5":{"start":{"line":13,"column":22},"end":{"line":13,"column":96}},"6":{"start":{"line":13,"column":54},"end":{"line":13,"column":95}},"7":{"start":{"line":14,"column":8},"end":{"line":16,"column":9}},"8":{"start":{"line":15,"column":10},"end":{"line":15,"column":23}},"9":{"start":{"line":18,"column":6},"end":{"line":18,"column":65}},"10":{"start":{"line":22,"column":28},"end":{"line":22,"column":59}},"11":{"start":{"line":23,"column":4},"end":{"line":25,"column":5}},"12":{"start":{"line":24,"column":6},"end":{"line":24,"column":54}},"13":{"start":{"line":28,"column":4},"end":{"line":68,"column":5}},"14":{"start":{"line":29,"column":6},"end":{"line":32,"column":7}},"15":{"start":{"line":30,"column":28},"end":{"line":30,"column":67}},"16":{"start":{"line":31,"column":8},"end":{"line":31,"column":44}},"17":{"start":{"line":33,"column":6},"end":{"line":42,"column":7}},"18":{"start":{"line":34,"column":28},"end":{"line":34,"column":84}},"19":{"start":{"line":35,"column":35},"end":{"line":35,"column":143}},"20":{"start":{"line":35,"column":92},"end":{"line":35,"column":135}},"21":{"start":{"line":36,"column":8},"end":{"line":41,"column":9}},"22":{"start":{"line":37,"column":10},"end":{"line":37,"column":55}},"23":{"start":{"line":39,"column":31},"end":{"line":39,"column":136}},"24":{"start":{"line":40,"column":10},"end":{"line":40,"column":49}},"25":{"start":{"line":43,"column":32},"end":{"line":43,"column":90}},"26":{"start":{"line":44,"column":27},"end":{"line":44,"column":142}},"27":{"start":{"line":44,"column":96},"end":{"line":44,"column":134}},"28":{"start":{"line":45,"column":24},"end":{"line":45,"column":136}},"29":{"start":{"line":45,"column":93},"end":{"line":45,"column":128}},"30":{"start":{"line":46,"column":6},"end":{"line":55,"column":7}},"31":{"start":{"line":47,"column":8},"end":{"line":54,"column":9}},"32":{"start":{"line":48,"column":10},"end":{"line":48,"column":44}},"33":{"start":{"line":50,"column":10},"end":{"line":53,"column":13}},"34":{"start":{"line":56,"column":6},"end":{"line":65,"column":7}},"35":{"start":{"line":57,"column":8},"end":{"line":64,"column":9}},"36":{"start":{"line":58,"column":10},"end":{"line":58,"column":40}},"37":{"start":{"line":60,"column":10},"end":{"line":63,"column":13}},"38":{"start":{"line":67,"column":6},"end":{"line":67,"column":33}},"39":{"start":{"line":71,"column":4},"end":{"line":71,"column":47}},"40":{"start":{"line":74,"column":20},"end":{"line":74,"column":44}},"41":{"start":{"line":75,"column":4},"end":{"line":75,"column":32}},"42":{"start":{"line":76,"column":4},"end":{"line":76,"column":78}},"43":{"start":{"line":79,"column":21},"end":{"line":79,"column":67}},"44":{"start":{"line":80,"column":26},"end":{"line":80,"column":72}},"45":{"start":{"line":80,"column":52},"end":{"line":80,"column":71}},"46":{"start":{"line":81,"column":4},"end":{"line":83,"column":5}},"47":{"start":{"line":82,"column":6},"end":{"line":82,"column":42}},"48":{"start":{"line":86,"column":25},"end":{"line":86,"column":55}},"49":{"start":{"line":87,"column":27},"end":{"line":87,"column":84}},"50":{"start":{"line":88,"column":26},"end":{"line":88,"column":66}},"51":{"start":{"line":89,"column":23},"end":{"line":91,"column":6}},"52":{"start":{"line":90,"column":40},"end":{"line":90,"column":55}},"53":{"start":{"line":92,"column":4},"end":{"line":92,"column":90}},"54":{"start":{"line":95,"column":18},"end":{"line":95,"column":64}},"55":{"start":{"line":96,"column":22},"end":{"line":98,"column":6}},"56":{"start":{"line":97,"column":6},"end":{"line":97,"column":31}},"57":{"start":{"line":99,"column":4},"end":{"line":101,"column":5}},"58":{"start":{"line":100,"column":6},"end":{"line":100,"column":18}},"59":{"start":{"line":102,"column":25},"end":{"line":102,"column":68}},"60":{"start":{"line":103,"column":25},"end":{"line":103,"column":73}},"61":{"start":{"line":104,"column":4},"end":{"line":104,"column":24}},"62":{"start":{"line":107,"column":26},"end":{"line":107,"column":107}},"63":{"start":{"line":108,"column":27},"end":{"line":108,"column":48}},"64":{"start":{"line":109,"column":4},"end":{"line":129,"column":5}},"65":{"start":{"line":110,"column":27},"end":{"line":110,"column":40}},"66":{"start":{"line":111,"column":17},"end":{"line":111,"column":49}},"67":{"start":{"line":112,"column":6},"end":{"line":128,"column":7}},"68":{"start":{"line":113,"column":8},"end":{"line":116,"column":9}},"69":{"start":{"line":114,"column":32},"end":{"line":114,"column":82}},"70":{"start":{"line":115,"column":10},"end":{"line":115,"column":56}},"71":{"start":{"line":117,"column":8},"end":{"line":117,"column":79}},"72":{"start":{"line":118,"column":8},"end":{"line":118,"column":48}},"73":{"start":{"line":119,"column":8},"end":{"line":119,"column":33}},"74":{"start":{"line":121,"column":8},"end":{"line":124,"column":9}},"75":{"start":{"line":122,"column":32},"end":{"line":122,"column":82}},"76":{"start":{"line":123,"column":10},"end":{"line":123,"column":52}},"77":{"start":{"line":125,"column":8},"end":{"line":125,"column":75}},"78":{"start":{"line":126,"column":8},"end":{"line":126,"column":44}},"79":{"start":{"line":127,"column":8},"end":{"line":127,"column":36}},"80":{"start":{"line":132,"column":23},"end":{"line":132,"column":70}},"81":{"start":{"line":133,"column":27},"end":{"line":133,"column":78}},"82":{"start":{"line":134,"column":23},"end":{"line":136,"column":6}},"83":{"start":{"line":135,"column":6},"end":{"line":135,"column":47}},"84":{"start":{"line":137,"column":4},"end":{"line":139,"column":5}},"85":{"start":{"line":138,"column":6},"end":{"line":138,"column":16}},"86":{"start":{"line":140,"column":26},"end":{"line":140,"column":70}},"87":{"start":{"line":141,"column":23},"end":{"line":141,"column":72}},"88":{"start":{"line":142,"column":4},"end":{"line":142,"column":22}},"89":{"start":{"line":145,"column":25},"end":{"line":145,"column":55}},"90":{"start":{"line":146,"column":27},"end":{"line":146,"column":84}},"91":{"start":{"line":147,"column":26},"end":{"line":147,"column":66}},"92":{"start":{"line":148,"column":23},"end":{"line":151,"column":8}},"93":{"start":{"line":152,"column":4},"end":{"line":152,"column":90}}},"fnMap":{"0":{"name":"(anonymous_0)","decl":{"start":{"line":5,"column":2},"end":{"line":5,"column":3}},"loc":{"start":{"line":5,"column":40},"end":{"line":9,"column":3}},"line":5},"1":{"name":"(anonymous_1)","decl":{"start":{"line":10,"column":2},"end":{"line":10,"column":3}},"loc":{"start":{"line":10,"column":37},"end":{"line":20,"column":3}},"line":10},"2":{"name":"(anonymous_2)","decl":{"start":{"line":11,"column":42},"end":{"line":11,"column":43}},"loc":{"start":{"line":11,"column":59},"end":{"line":19,"column":5}},"line":11},"3":{"name":"(anonymous_3)","decl":{"start":{"line":13,"column":39},"end":{"line":13,"column":40}},"loc":{"start":{"line":13,"column":54},"end":{"line":13,"column":95}},"line":13},"4":{"name":"(anonymous_4)","decl":{"start":{"line":21,"column":2},"end":{"line":21,"column":3}},"loc":{"start":{"line":21,"column":24},"end":{"line":26,"column":3}},"line":21},"5":{"name":"(anonymous_5)","decl":{"start":{"line":27,"column":2},"end":{"line":27,"column":3}},"loc":{"start":{"line":27,"column":51},"end":{"line":69,"column":3}},"line":27},"6":{"name":"(anonymous_6)","decl":{"start":{"line":35,"column":77},"end":{"line":35,"column":78}},"loc":{"start":{"line":35,"column":92},"end":{"line":35,"column":135}},"line":35},"7":{"name":"(anonymous_7)","decl":{"start":{"line":44,"column":81},"end":{"line":44,"column":82}},"loc":{"start":{"line":44,"column":96},"end":{"line":44,"column":134}},"line":44},"8":{"name":"(anonymous_8)","decl":{"start":{"line":45,"column":78},"end":{"line":45,"column":79}},"loc":{"start":{"line":45,"column":93},"end":{"line":45,"column":128}},"line":45},"9":{"name":"(anonymous_9)","decl":{"start":{"line":70,"column":2},"end":{"line":70,"column":3}},"loc":{"start":{"line":70,"column":16},"end":{"line":72,"column":3}},"line":70},"10":{"name":"(anonymous_10)","decl":{"start":{"line":73,"column":2},"end":{"line":73,"column":3}},"loc":{"start":{"line":73,"column":32},"end":{"line":77,"column":3}},"line":73},"11":{"name":"(anonymous_11)","decl":{"start":{"line":78,"column":2},"end":{"line":78,"column":3}},"loc":{"start":{"line":78,"column":25},"end":{"line":84,"column":3}},"line":78},"12":{"name":"(anonymous_12)","decl":{"start":{"line":80,"column":42},"end":{"line":80,"column":43}},"loc":{"start":{"line":80,"column":52},"end":{"line":80,"column":71}},"line":80},"13":{"name":"(anonymous_13)","decl":{"start":{"line":85,"column":2},"end":{"line":85,"column":3}},"loc":{"start":{"line":85,"column":42},"end":{"line":93,"column":3}},"line":85},"14":{"name":"(anonymous_14)","decl":{"start":{"line":90,"column":29},"end":{"line":90,"column":30}},"loc":{"start":{"line":90,"column":40},"end":{"line":90,"column":55}},"line":90},"15":{"name":"(anonymous_15)","decl":{"start":{"line":94,"column":2},"end":{"line":94,"column":3}},"loc":{"start":{"line":94,"column":17},"end":{"line":105,"column":3}},"line":94},"16":{"name":"(anonymous_16)","decl":{"start":{"line":96,"column":33},"end":{"line":96,"column":34}},"loc":{"start":{"line":96,"column":43},"end":{"line":98,"column":5}},"line":96},"17":{"name":"(anonymous_17)","decl":{"start":{"line":106,"column":2},"end":{"line":106,"column":3}},"loc":{"start":{"line":106,"column":47},"end":{"line":130,"column":3}},"line":106},"18":{"name":"(anonymous_18)","decl":{"start":{"line":131,"column":2},"end":{"line":131,"column":3}},"loc":{"start":{"line":131,"column":22},"end":{"line":143,"column":3}},"line":131},"19":{"name":"(anonymous_19)","decl":{"start":{"line":134,"column":49},"end":{"line":134,"column":50}},"loc":{"start":{"line":134,"column":64},"end":{"line":136,"column":5}},"line":134},"20":{"name":"(anonymous_20)","decl":{"start":{"line":144,"column":2},"end":{"line":144,"column":3}},"loc":{"start":{"line":144,"column":38},"end":{"line":153,"column":3}},"line":144}},"branchMap":{"0":{"loc":{"start":{"line":5,"column":26},"end":{"line":5,"column":38}},"type":"default-arg","locations":[{"start":{"line":5,"column":37},"end":{"line":5,"column":38}}],"line":5},"1":{"loc":{"start":{"line":12,"column":6},"end":{"line":17,"column":7}},"type":"if","locations":[{"start":{"line":12,"column":6},"end":{"line":17,"column":7}},{"start":{},"end":{}}],"line":12},"2":{"loc":{"start":{"line":14,"column":8},"end":{"line":16,"column":9}},"type":"if","locations":[{"start":{"line":14,"column":8},"end":{"line":16,"column":9}},{"start":{},"end":{}}],"line":14},"3":{"loc":{"start":{"line":29,"column":6},"end":{"line":32,"column":7}},"type":"if","locations":[{"start":{"line":29,"column":6},"end":{"line":32,"column":7}},{"start":{},"end":{}}],"line":29},"4":{"loc":{"start":{"line":33,"column":6},"end":{"line":42,"column":7}},"type":"if","locations":[{"start":{"line":33,"column":6},"end":{"line":42,"column":7}},{"start":{},"end":{}}],"line":33},"5":{"loc":{"start":{"line":35,"column":35},"end":{"line":35,"column":143}},"type":"cond-expr","locations":[{"start":{"line":35,"column":60},"end":{"line":35,"column":136}},{"start":{"line":35,"column":139},"end":{"line":35,"column":143}}],"line":35},"6":{"loc":{"start":{"line":36,"column":8},"end":{"line":41,"column":9}},"type":"if","locations":[{"start":{"line":36,"column":8},"end":{"line":41,"column":9}},{"start":{"line":38,"column":15},"end":{"line":41,"column":9}}],"line":36},"7":{"loc":{"start":{"line":44,"column":27},"end":{"line":44,"column":142}},"type":"cond-expr","locations":[{"start":{"line":44,"column":58},"end":{"line":44,"column":135}},{"start":{"line":44,"column":138},"end":{"line":44,"column":142}}],"line":44},"8":{"loc":{"start":{"line":45,"column":24},"end":{"line":45,"column":136}},"type":"cond-expr","locations":[{"start":{"line":45,"column":55},"end":{"line":45,"column":129}},{"start":{"line":45,"column":132},"end":{"line":45,"column":136}}],"line":45},"9":{"loc":{"start":{"line":46,"column":6},"end":{"line":55,"column":7}},"type":"if","locations":[{"start":{"line":46,"column":6},"end":{"line":55,"column":7}},{"start":{},"end":{}}],"line":46},"10":{"loc":{"start":{"line":47,"column":8},"end":{"line":54,"column":9}},"type":"if","locations":[{"start":{"line":47,"column":8},"end":{"line":54,"column":9}},{"start":{"line":49,"column":15},"end":{"line":54,"column":9}}],"line":47},"11":{"loc":{"start":{"line":56,"column":6},"end":{"line":65,"column":7}},"type":"if","locations":[{"start":{"line":56,"column":6},"end":{"line":65,"column":7}},{"start":{},"end":{}}],"line":56},"12":{"loc":{"start":{"line":57,"column":8},"end":{"line":64,"column":9}},"type":"if","locations":[{"start":{"line":57,"column":8},"end":{"line":64,"column":9}},{"start":{"line":59,"column":15},"end":{"line":64,"column":9}}],"line":57},"13":{"loc":{"start":{"line":99,"column":4},"end":{"line":101,"column":5}},"type":"if","locations":[{"start":{"line":99,"column":4},"end":{"line":101,"column":5}},{"start":{},"end":{}}],"line":99},"14":{"loc":{"start":{"line":107,"column":26},"end":{"line":107,"column":107}},"type":"cond-expr","locations":[{"start":{"line":107,"column":66},"end":{"line":107,"column":83}},{"start":{"line":107,"column":86},"end":{"line":107,"column":107}}],"line":107},"15":{"loc":{"start":{"line":112,"column":6},"end":{"line":128,"column":7}},"type":"if","locations":[{"start":{"line":112,"column":6},"end":{"line":128,"column":7}},{"start":{"line":120,"column":13},"end":{"line":128,"column":7}}],"line":112},"16":{"loc":{"start":{"line":137,"column":4},"end":{"line":139,"column":5}},"type":"if","locations":[{"start":{"line":137,"column":4},"end":{"line":139,"column":5}},{"start":{},"end":{}}],"line":137}},"s":{"0":0,"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0,"15":0,"16":0,"17":0,"18":0,"19":0,"20":0,"21":0,"22":0,"23":0,"24":0,"25":0,"26":0,"27":0,"28":0,"29":0,"30":0,"31":0,"32":0,"33":0,"34":0,"35":0,"36":0,"37":0,"38":0,"39":0,"40":0,"41":0,"42":0,"43":0,"44":0,"45":0,"46":0,"47":0,"48":0,"49":0,"50":0,"51":0,"52":0,"53":0,"54":0,"55":0,"56":0,"57":0,"58":0,"59":0,"60":0,"61":0,"62":0,"63":0,"64":0,"65":0,"66":0,"67":0,"68":0,"69":0,"70":0,"71":0,"72":0,"73":0,"74":0,"75":0,"76":0,"77":0,"78":0,"79":0,"80":0,"81":0,"82":0,"83":0,"84":0,"85":0,"86":0,"87":0,"88":0,"89":0,"90":0,"91":0,"92":0,"93":0},"f":{"0":0,"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0,"13":0,"14":0,"15":0,"16":0,"17":0,"18":0,"19":0,"20":0},"b":{"0":[0],"1":[0,0],"2":[0,0],"3":[0,0],"4":[0,0],"5":[0,0],"6":[0,0],"7":[0,0],"8":[0,0],"9":[0,0],"10":[0,0],"11":[0,0],"12":[0,0],"13":[0,0],"14":[0,0],"15":[0,0],"16":[0,0]},"inputSourceMap":{"version":3,"sources":["/home/runner/work/pluto-encrypted/pluto-encrypted/packages/iagon/src/IagonStorage/internals.ts"],"sourcesContent":["import {\n RxDocumentData,\n RxDocumentDataById,\n RxJsonSchema\n} from \"rxdb\";\nimport { IagonAPI } from \"./api\";\nimport { IagonFolder, IagonInternalParameters, IagonStorageInternals } from \"./types\";\nimport { getPrivateKeyValue, safeIndexList } from \"@pluto-encrypted/shared\";\n\n\nexport class IagonInternals implements IagonStorageInternals {\n public __databaseFolder!: IagonFolder;\n public __collectionFolder!: IagonFolder;\n public __indexFolder!: IagonFolder;\n public __dataFolder!: IagonFolder;\n public indexes: Map = new Map()\n\n public sdk: IagonAPI;\n\n\n constructor(parameters: IagonInternalParameters, public refCount: number = 0) {\n this.sdk = new IagonAPI(parameters)\n }\n\n async getDBDirectory(databaseName: string) {\n return this.sdk.getDirectories().then((directories) => {\n if (directories.length > 0) {\n const found = directories.find((directory) => directory.directory_name === databaseName)\n if (found) {\n return found;\n }\n }\n return this.sdk.createDirectory({ dirName: databaseName });\n })\n }\n\n private async resetDatabase() {\n const rootDirectories = await this.sdk.getDirectories();\n for (let directory of rootDirectories) {\n await this.sdk.removeDirectory(directory, true)\n }\n }\n\n async initialiseDB(databaseName: string, collectionName: string) {\n try {\n if (!this.__databaseFolder) {\n const databaseDir = await this.getDBDirectory(databaseName);\n this.__databaseFolder = databaseDir;\n }\n\n if (!this.__collectionFolder) {\n const collections = await this.sdk.getDirectories(this.__databaseFolder._id);\n const __collectionFolder = collections.length > 0 ? collections.find((directory) => directory.directory_name === collectionName) : null;\n\n if (__collectionFolder) {\n this.__collectionFolder = __collectionFolder;\n } else {\n const newDirectory = await this.sdk.createDirectory({ parentDirectoryId: this.__databaseFolder._id, dirName: collectionName })\n this.__collectionFolder = newDirectory\n }\n }\n\n const collectionFolders = await this.sdk.getDirectories(this.__collectionFolder._id);\n const indexesFound = collectionFolders.length > 0 ? collectionFolders.find((directory) => directory.directory_name === \"indexes\") : null;\n const dataFound = collectionFolders.length > 0 ? collectionFolders.find((directory) => directory.directory_name === \"data\") : null;\n\n if (!this.__indexFolder) {\n if (indexesFound) {\n this.__indexFolder = indexesFound;\n } else {\n this.__indexFolder = await this.sdk.createDirectory({\n parentDirectoryId: this.__collectionFolder._id,\n dirName: 'indexes'\n })\n }\n }\n\n if (!this.__dataFolder) {\n if (dataFound) {\n this.__dataFolder = dataFound;\n } else {\n this.__dataFolder = await this.sdk.createDirectory({\n parentDirectoryId: this.__collectionFolder._id,\n dirName: 'data'\n })\n }\n }\n\n\n } catch (err) {\n return Promise.reject(err)\n }\n }\n\n\n bulkGet(keys: string[]): Promise> {\n throw new Error(\"Method not implemented.\");\n }\n async addDoc(docId: string, document: RxDocumentData): Promise {\n const jsonDoc = JSON.stringify(document)\n await this.removeDoc(docId)\n await this.sdk.uploadFile(this.__dataFolder, docId, Buffer.from(jsonDoc))\n }\n async removeDoc(docId: string): Promise {\n const allFiles = await this.sdk.getFiles(this.__dataFolder._id);\n const matchingFiles = allFiles.filter((file) => file.name === docId)\n for (let file of matchingFiles) {\n await this.sdk.removeFile(file._id)\n }\n }\n async removeFromIndex(indexName: string, docId: string): Promise {\n const currentIndex = await this.getIndex(indexName)\n const cleanIndexPath = indexName.replace(/\\[(.*)\\]/g, \"$1\").split(\"+\").join(\"/\");\n const indexFilename = `${cleanIndexPath.split(\"/\").join(\"_\")}`;\n const jsonString = JSON.stringify([\n ...currentIndex.filter((index) => index !== docId),\n ])\n await this.sdk.uploadFile(this.__indexFolder, indexFilename, Buffer.from(jsonString))\n }\n async get(key: string): Promise | null> {\n const files = await this.sdk.getFiles(this.__dataFolder._id);\n const fileFound = files.find((file) => {\n return file.name === key;\n })\n if (!fileFound) {\n return null;\n }\n const fileContents = await this.sdk.getFile({ file: fileFound })\n const jsonDocument: RxDocumentData = JSON.parse(Buffer.from(fileContents).toString());\n return jsonDocument\n }\n async bulkPut(items: RxDocumentData[], collectionName: string, schema: RxJsonSchema>): Promise {\n const primaryKeyKey = typeof schema.primaryKey === 'string' ? schema.primaryKey : schema.primaryKey.key\n const saferIndexList = safeIndexList(schema)\n for (const item of items) {\n const shouldDelete = item._deleted\n const id = getPrivateKeyValue(item, schema)\n if (shouldDelete) {\n for (const requiredIndexes of saferIndexList) {\n const requiredIndex = `[${collectionName}+${requiredIndexes.join('+')}]`\n await this.removeFromIndex(requiredIndex, id)\n }\n await this.removeFromIndex(`[${collectionName}+${primaryKeyKey}]`, id)\n await this.removeFromIndex('[all]', id)\n await this.removeDoc(id)\n } else {\n for (const requiredIndexes of saferIndexList) {\n const requiredIndex = `[${collectionName}+${requiredIndexes.join('+')}]`\n await this.updateIndex(requiredIndex, id)\n }\n await this.updateIndex(`[${collectionName}+${primaryKeyKey}]`, id)\n await this.updateIndex('[all]', id)\n await this.addDoc(id, item)\n }\n }\n }\n\n async getIndex(key: string): Promise {\n const indexFiles = await this.sdk.getFiles(this.__indexFolder._id);\n const cleanIndexPath = key.replace(/\\[(.*)\\]/g, \"$1\").split(\"+\").join(\"_\");\n const indexFound = indexFiles.reverse().find((indexFile) => {\n return indexFile.name === cleanIndexPath\n });\n if (!indexFound) {\n return [];\n }\n const indexContents = await this.sdk.getFile({ file: indexFound })\n const jsonParsed: string[] = JSON.parse(Buffer.from(indexContents).toString())\n return jsonParsed\n }\n\n async updateIndex(indexName: string, docId: string) {\n const currentIndex = await this.getIndex(indexName)\n const cleanIndexPath = indexName.replace(/\\[(.*)\\]/g, \"$1\").split(\"+\").join(\"/\");\n const indexFilename = `${cleanIndexPath.split(\"/\").join(\"_\")}`;\n const jsonString = JSON.stringify(Array.from(new Set([\n ...currentIndex,\n docId\n ])))\n await this.sdk.uploadFile(this.__indexFolder, indexFilename, Buffer.from(jsonString))\n }\n\n}\n"],"mappings":"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","names":[]},"_coverageSchema":"1a1c01bbd47fc00a2c39e90264f33305004495a9","hash":"81c19842fad2999ea2ac4f6177c8fec11e25195e"},"/home/runner/work/pluto-encrypted/pluto-encrypted/packages/iagon/src/IagonStorage/index.ts":{"path":"/home/runner/work/pluto-encrypted/pluto-encrypted/packages/iagon/src/IagonStorage/index.ts","statementMap":{"0":{"start":{"line":8,"column":4},"end":{"line":8,"column":29}},"1":{"start":{"line":9,"column":4},"end":{"line":9,"column":24}},"2":{"start":{"line":10,"column":4},"end":{"line":10,"column":43}},"3":{"start":{"line":11,"column":4},"end":{"line":11,"column":54}},"4":{"start":{"line":12,"column":4},"end":{"line":12,"column":22}},"5":{"start":{"line":15,"column":4},"end":{"line":17,"column":5}},"6":{"start":{"line":16,"column":6},"end":{"line":16,"column":118}},"7":{"start":{"line":18,"column":4},"end":{"line":18,"column":20}},"8":{"start":{"line":19,"column":22},"end":{"line":19,"column":70}},"9":{"start":{"line":20,"column":4},"end":{"line":20,"column":77}},"10":{"start":{"line":21,"column":4},"end":{"line":27,"column":6}},"11":{"start":{"line":31,"column":18},"end":{"line":31,"column":46}},"12":{"start":{"line":32,"column":2},"end":{"line":34,"column":5}}},"fnMap":{"0":{"name":"(anonymous_0)","decl":{"start":{"line":7,"column":2},"end":{"line":7,"column":3}},"loc":{"start":{"line":7,"column":24},"end":{"line":13,"column":3}},"line":7},"1":{"name":"(anonymous_1)","decl":{"start":{"line":14,"column":2},"end":{"line":14,"column":3}},"loc":{"start":{"line":14,"column":38},"end":{"line":28,"column":3}},"line":14},"2":{"name":"createIagonStorage","decl":{"start":{"line":30,"column":16},"end":{"line":30,"column":34}},"loc":{"start":{"line":30,"column":47},"end":{"line":35,"column":1}},"line":30}},"branchMap":{"0":{"loc":{"start":{"line":15,"column":4},"end":{"line":17,"column":5}},"type":"if","locations":[{"start":{"line":15,"column":4},"end":{"line":17,"column":5}},{"start":{},"end":{}}],"line":15}},"s":{"0":0,"1":0,"2":0,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0},"f":{"0":0,"1":0,"2":0},"b":{"0":[0,0]},"inputSourceMap":{"version":3,"sources":["/home/runner/work/pluto-encrypted/pluto-encrypted/packages/iagon/src/IagonStorage/index.ts"],"sourcesContent":["/**\n * @packageDocumentation\n * @module indexdb\n * @description This is a RXDB IndexDB storage that supports encryption middleware.\n * In order to use this in your pluto-encrypted database you must write the following code:\n * Creating a IndexDB compatible storage is very simple.\n * \n * ```typescript\n * import IndexDB from \"@pluto-encrypted/indexdb\";\n * import { Database } from \"@pluto-encrypted/database\";\n * //default password must be 32 bytes long\n * const defaultPassword = new Uint8Array(32).fill(1);\n * const database = db = await Database.createEncrypted({\n * name: `my-db`,\n * encryptionKey: defaultPassword,\n * storage: IndexDB,\n * });\n * ```\n *\n */\n\nimport { wrappedKeyEncryptionStorage } from '@pluto-encrypted/encryption'\nimport { RxStorage, RxStorageDefaultStatics, RxStorageInstanceCreationParams, newRxError } from 'rxdb'\n\nimport { IagonStorageInstance } from './instance'\nimport { IagonInternalParameters, IagonStorageInternals } from './types'\nimport { IagonInternals } from './internals'\n\nclass IagonStorage<\n RxDocType,\n>{\n public name = \"iagon\"\n public statics = RxStorageDefaultStatics;\n public internalInstance: Map> = new Map()\n public refCount = 0;\n\n constructor(\n private settings: IagonInternalParameters,\n ) { }\n\n async createStorageInstance(params: RxStorageInstanceCreationParams) {\n if (params.schema.keyCompression) {\n throw newRxError('UT5', { args: { databaseName: params.databaseName, collectionName: params.collectionName } })\n }\n this.refCount++;\n\n const internals = new IagonInternals(this.settings, this.refCount)\n await internals.initialiseDB(params.databaseName, params.collectionName)\n\n return new IagonStorageInstance(\n params.databaseName,\n internals,\n params.options,\n params.schema,\n params.collectionName\n );\n }\n}\n\nexport function createIagonStorage(parameters: IagonInternalParameters) {\n const storage: RxStorage = new IagonStorage(parameters)\n return wrappedKeyEncryptionStorage({\n storage: storage\n });\n}\n"],"mappings":";AAqBA,SAAS,mCAAmC;AAC5C,SAAoB,yBAA0D,kBAAkB;AAEhG,SAAS,4BAA4B;AAErC,SAAS,sBAAsB;AAE/B,MAAM,aAEL;AAAA,EAMC,YACU,UACR;AADQ;AANV,SAAO,OAAO;AACd,SAAO,UAAU;AACjB,SAAO,mBAA2D,oBAAI,IAAI;AAC1E,SAAO,WAAW;AAAA,EAId;AAAA,EAEJ,MAAM,sBAAiC,QAAyD;AAC9F,QAAI,OAAO,OAAO,gBAAgB;AAChC,YAAM,WAAW,OAAO,EAAE,MAAM,EAAE,cAAc,OAAO,cAAc,gBAAgB,OAAO,eAAe,EAAE,CAAC;AAAA,IAChH;AACA,SAAK;AAEL,UAAM,YAAY,IAAI,eAAoB,KAAK,UAAU,KAAK,QAAQ;AACtE,UAAM,UAAU,aAAa,OAAO,cAAc,OAAO,cAAc;AAEvE,WAAO,IAAI;AAAA,MACT,OAAO;AAAA,MACP;AAAA,MACA,OAAO;AAAA,MACP,OAAO;AAAA,MACP,OAAO;AAAA,IACT;AAAA,EACF;AACF;AAEO,gBAAS,mBAAmB,YAAqC;AACtE,QAAM,UAA+B,IAAI,aAAkB,UAAU;AACrE,SAAO,4BAA4B;AAAA,IACjC;AAAA,EACF,CAAC;AACH;","names":[]},"_coverageSchema":"1a1c01bbd47fc00a2c39e90264f33305004495a9","hash":"4b4ee3ad8c66a5b5920913bc784a96fd056d948e"},"/home/runner/work/pluto-encrypted/pluto-encrypted/packages/iagon/src/IagonStorage/types.ts":{"path":"/home/runner/work/pluto-encrypted/pluto-encrypted/packages/iagon/src/IagonStorage/types.ts","statementMap":{"0":{"start":{"line":2,"column":40},"end":{"line":6,"column":20}},"1":{"start":{"line":3,"column":2},"end":{"line":3,"column":37}},"2":{"start":{"line":4,"column":2},"end":{"line":4,"column":35}},"3":{"start":{"line":5,"column":2},"end":{"line":5,"column":21}}},"fnMap":{"0":{"name":"(anonymous_0)","decl":{"start":{"line":2,"column":41},"end":{"line":2,"column":42}},"loc":{"start":{"line":2,"column":58},"end":{"line":6,"column":1}},"line":2}},"branchMap":{"0":{"loc":{"start":{"line":6,"column":3},"end":{"line":6,"column":19}},"type":"binary-expr","locations":[{"start":{"line":6,"column":3},"end":{"line":6,"column":13}},{"start":{"line":6,"column":17},"end":{"line":6,"column":19}}],"line":6}},"s":{"0":1,"1":1,"2":1,"3":1},"f":{"0":1},"b":{"0":[1,1]},"inputSourceMap":{"version":3,"sources":["/home/runner/work/pluto-encrypted/pluto-encrypted/packages/iagon/src/IagonStorage/types.ts"],"sourcesContent":["import { RxDocumentData, RxDocumentDataById, RxJsonSchema } from \"rxdb\"\n\n\n\nexport type IagonInternalParameters = {\n apiKey: string,\n password: Uint8Array\n}\n\nexport enum VISIBILITY {\n private = \"private\",\n public = \"public\"\n}\n\nexport type IagonFolder = {\n __v: number,\n _id: string,\n client_id: string,\n created_at: string,\n directory_name: string,\n index_listing: boolean,\n parent_directory_id: string | null,\n path: string,\n updated_at: string,\n visibility: VISIBILITY\n}\n\nexport type IagonFile = {\n __v: number,\n _id: string,\n availability: string,\n client_id: string,\n createdAt: string,\n file_size_byte_encrypted: 24,\n file_size_byte_native: 0,\n index_listing: boolean,\n name: string,\n parent_directory_id: string | null,\n path: string,\n region: string | null,\n unique_id: string,\n updated_at: string,\n visibility: VISIBILITY\n}\n\nexport type IagonResponse = {\n success: true,\n data: Data\n} | {\n success: false,\n message: string\n}\n\nexport type IagonStorageInternals = {\n __databaseFolder: IagonFolder;\n __collectionFolder: IagonFolder;\n __indexFolder: IagonFolder;\n __dataFolder: IagonFolder;\n refCount: number;\n\n getDBDirectory(databaseName: string): Promise\n initialiseDB(databaseName: string, collectionName: string): Promise\n bulkGet(keys: string[]): Promise>\n\n addDoc(docId: string, document: RxDocumentData): Promise\n removeDoc(docId: string): Promise\n removeFromIndex(indexName: string, docId: string): Promise\n get(key: string): Promise | null>\n getIndex(key: string): Promise\n updateIndex(indexName: string, docId: string): Promise\n bulkPut(items: Array>, collectionName: string, schema: Readonly>>): Promise\n}"],"mappings":";AASO,WAAK,aAAL,kBAAKA,gBAAL;AACH,EAAAA,YAAA,aAAU;AACV,EAAAA,YAAA,YAAS;AAFD,SAAAA;AAAA,GAAA;","names":["VISIBILITY"]},"_coverageSchema":"1a1c01bbd47fc00a2c39e90264f33305004495a9","hash":"25efa73b179eb51379945b8f25047f74d34de95b"},"/home/runner/work/pluto-encrypted/pluto-encrypted/packages/iagon/src/index.ts":{"path":"/home/runner/work/pluto-encrypted/pluto-encrypted/packages/iagon/src/index.ts","statementMap":{},"fnMap":{},"branchMap":{},"s":{},"f":{},"b":{},"inputSourceMap":{"version":3,"sources":["/home/runner/work/pluto-encrypted/pluto-encrypted/packages/iagon/src/index.ts"],"sourcesContent":["export * from './IagonStorage/api';\nexport * from './IagonStorage';\nexport * from './IagonStorage/instance';\nexport * from './IagonStorage/internals';\nexport * from './IagonStorage/types';\n"],"mappings":";AAAA,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;AACd,cAAc;","names":[]},"_coverageSchema":"1a1c01bbd47fc00a2c39e90264f33305004495a9","hash":"b16d02aaa4f83c11a0d0383f11d92362546f0208"}} \ No newline at end of file diff --git a/packages/iagon/package.json b/packages/iagon/package.json deleted file mode 100644 index 804991cd..00000000 --- a/packages/iagon/package.json +++ /dev/null @@ -1,47 +0,0 @@ -{ - "name": "@pluto-encrypted/iagon", - "version": "1.0.2", - "description": "Secure Encrypted iagon storage for @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" - } - }, - "private": "true", - "homepage": "https://atala-community-projects.github.io/pluto-encrypted", - "scripts": { - "prepublishOnly": "npm run build", - "clean-packages": "rm -rf node_modules && rm -rf build", - "build": "rm -rf build && npx rollup -c rollup/rollup.mjs", - "coverage": "npx vitest run --coverage && npx istanbul-badges-readme", - "test-local": "NODE_ENV=debug vitest --pool threads --poolOptions.threads.singleThread --run tests/*.test.ts" - }, - "repository": { - "type": "git", - "url": "https://github.com/atala-community-projects/pluto-encrypted.git" - }, - "author": "elribonazo@gmail.com", - "license": "Apache-2.0", - "dependencies": { - "@pluto-encrypted/encryption": "1.11.0", - "@pluto-encrypted/shared": "1.11.3", - "array-push-at-sort-position": "^4.0.1", - "axios": "^1.6.5", - "request": "^2.88.2", - "rxdb": "^14.17.0", - "uuid": "^9.0.1" - }, - "devDependencies": { - "@pluto-encrypted/encryption": "1.11.0", - "@pluto-encrypted/shared": "1.11.3", - "@pluto-encrypted/test-suite": "1.12.1" - }, - "files": [ - "build/*" - ], - "gitHead": "6aa4ce8bbb9938fc4c4e790efffa5b902631362c" -} diff --git a/packages/iagon/rollup/rollup.mjs b/packages/iagon/rollup/rollup.mjs deleted file mode 100644 index 1278dac6..00000000 --- a/packages/iagon/rollup/rollup.mjs +++ /dev/null @@ -1,5 +0,0 @@ -import nodePolyfills from "rollup-plugin-polyfill-node"; - -import CreateConfig from "../../../rollup/index.mjs"; - -export default CreateConfig(undefined, []); diff --git a/packages/iagon/src/IagonStorage/api.ts b/packages/iagon/src/IagonStorage/api.ts deleted file mode 100644 index d099cb98..00000000 --- a/packages/iagon/src/IagonStorage/api.ts +++ /dev/null @@ -1,196 +0,0 @@ -import axios, { AxiosRequestConfig } from 'axios'; - - -import { IagonFile, IagonFolder, IagonInternalParameters, IagonResponse } from "./types"; - -export class IagonAPI { - private baseUrl = "https://gw.iagon.com/"; - constructor(private parameters: IagonInternalParameters) { } - - get iagonPassword() { - return Buffer.from(this.parameters.password).toString() - } - - private async runRequest | any>(options: AxiosRequestConfig) { - try { - const startTime = Date.now(); - const response = await axios.request(options); - const endTime = Date.now(); - const elapsedMilliseconds = endTime - startTime; - console.log(`Request "${options.method}":"${options.url}" took ${elapsedMilliseconds} ms.`); - return Promise.resolve(response) - } catch (err) { - console.error(`Request "${options.method}":"${options.url}" failed: ${err}`); - return Promise.reject(err) - } - } - - async removeFile(fileId: string) { - const baseUrl = `${this.baseUrl}api/v2/storage/file/${fileId}`; - const url = `${baseUrl}` - const options = { - 'method': 'DELETE', - 'url': url, - 'headers': { - 'x-api-key': this.parameters.apiKey - } - }; - const file = await this.runRequest(options) - return file - } - async getDirectories(parentDirectoryId?: string) { - const baseUrl = `${this.baseUrl}api/v2/storage/directory?visibility=private&listingType=index` - const url = parentDirectoryId ? `${baseUrl}&parent_directory_id=${parentDirectoryId}` : `${baseUrl}` - const options = { - 'method': 'GET', - 'url': url, - 'headers': { - 'x-api-key': this.parameters.apiKey - } - }; - - const response = await this.runRequest>(options) - - const jsonResponse = response.data; - if (!jsonResponse.success) { - throw new Error(jsonResponse.message) - } - - const directories = jsonResponse.data && jsonResponse.data.directories ? jsonResponse.data.directories : []; - return directories - } - async getFile(options: { parentDirectoryId?: string | undefined; file: IagonFile; }) { - const baseUrl = `${this.baseUrl}api/v2/storage/parameterized/download` - var requestOptions = { - 'method': 'POST', - 'url': baseUrl, - 'headers': { - 'x-api-key': this.parameters.apiKey - }, - 'data': { - "id": options.file._id, - "password": this.iagonPassword - } - }; - const response = await this.runRequest(requestOptions) - return Buffer.from(typeof response.data === "string" ? response.data : JSON.stringify(response.data)); - } - async getFiles(parentDirectoryId?: string) { - const baseUrl = `${this.baseUrl}api/v2/storage/directory?visibility=private&listingType=index` - const url = parentDirectoryId ? `${baseUrl}&parent_directory_id=${parentDirectoryId}` : `${baseUrl}` - const options = { - 'method': 'GET', - 'url': url, - 'headers': { - 'x-api-key': this.parameters.apiKey - } - }; - const response = await this.runRequest>(options); - - const jsonResponse: IagonResponse<{ - directories: IagonFolder[], - files: IagonFile[] - }> = response.data; - - if (!jsonResponse.success) { - throw new Error(jsonResponse.message) - } - const files = jsonResponse.data && jsonResponse.data.files ? jsonResponse.data.files : []; - return files - } - async createDirectory(queryOptions: { parentDirectoryId?: string, dirName: string }) { - const { dirName, parentDirectoryId } = queryOptions - const body: any = { - "directory_name": dirName, - "visibility": "private", - "index_listing": true - } - - if (parentDirectoryId) { - body.parent_directory_id = parentDirectoryId; - } - - const baseUrl = `${this.baseUrl}api/v2/storage/directory` - const options = { - 'method': 'POST', - 'url': baseUrl, - 'headers': { - 'Content-Type': 'application/json', - 'x-api-key': this.parameters.apiKey - }, - data: JSON.stringify(body) - }; - - const response = await this.runRequest>(options) - const jsonResponse: IagonResponse = response.data; - if (!jsonResponse.success) { - throw new Error(jsonResponse.message) - } - - const directory = jsonResponse.data - return directory - } - async removeDirectory(dirname: IagonFolder, recursive: true) { - const baseUrl = `${this.baseUrl}api/v2/storage/directory/${dirname._id}` - var options = { - 'method': 'DELETE', - 'url': baseUrl, - 'headers': { - 'x-api-key': this.parameters.apiKey - } - }; - const response = await this.runRequest(options); - return response.data - } - private objectToFormData(obj) { - const formData = new FormData(); - for (const key in obj) { - if (obj.hasOwnProperty(key)) { - const value = obj[key]; - formData.append(key, value); - } - } - return formData; - } - private getFormDataSize(formData) { - let totalSize = 0; - for (const [key, value] of formData.entries()) { - if (value instanceof Blob) { - totalSize += value.size; - } else { - totalSize += new TextEncoder().encode(value.toString()).length; - } - } - return totalSize / 1024; - } - async uploadFile(dirname: IagonFolder, file: string, contents: Uint8Array) { - const baseUrl = `${this.baseUrl}api/v2/storage/upload`; - const body = this.objectToFormData({ - "visibility": "private", - "password": this.iagonPassword, - 'directoryId': dirname._id - }); - body.append("file", new Blob([contents], { type: "platin/text" }), file) - var options = { - 'method': 'POST', - 'url': baseUrl, - 'headers': { - 'x-api-key': this.parameters.apiKey - }, - data: body - }; - console.log(`Uploading aproximately ${this.getFormDataSize(body)} kb`) - const response = await this.runRequest>(options); - const jsonResponse: IagonResponse = response.data; - if (!jsonResponse.success) { - throw new Error(jsonResponse.message) - } - return jsonResponse.data - } -} \ No newline at end of file diff --git a/packages/iagon/src/IagonStorage/index.ts b/packages/iagon/src/IagonStorage/index.ts deleted file mode 100644 index 3cacae80..00000000 --- a/packages/iagon/src/IagonStorage/index.ts +++ /dev/null @@ -1,65 +0,0 @@ -/** - * @packageDocumentation - * @module indexdb - * @description This is a RXDB IndexDB storage that supports encryption middleware. - * In order to use this in your pluto-encrypted database you must write the following code: - * Creating a IndexDB compatible storage is very simple. - * - * ```typescript - * import IndexDB from "@pluto-encrypted/indexdb"; - * import { Database } from "@pluto-encrypted/database"; - * //default password must be 32 bytes long - * const defaultPassword = new Uint8Array(32).fill(1); - * const database = db = await Database.createEncrypted({ - * name: `my-db`, - * encryptionKey: defaultPassword, - * storage: IndexDB, - * }); - * ``` - * - */ - -import { wrappedKeyEncryptionStorage } from '@pluto-encrypted/encryption' -import { RxStorage, RxStorageDefaultStatics, RxStorageInstanceCreationParams, newRxError } from 'rxdb' - -import { IagonStorageInstance } from './instance' -import { IagonInternalParameters, IagonStorageInternals } from './types' -import { IagonInternals } from './internals' - -class IagonStorage< - RxDocType, ->{ - public name = "iagon" - public statics = RxStorageDefaultStatics; - public internalInstance: Map> = new Map() - public refCount = 0; - - constructor( - private settings: IagonInternalParameters, - ) { } - - async createStorageInstance(params: RxStorageInstanceCreationParams) { - if (params.schema.keyCompression) { - throw newRxError('UT5', { args: { databaseName: params.databaseName, collectionName: params.collectionName } }) - } - this.refCount++; - - const internals = new IagonInternals(this.settings, this.refCount) - await internals.initialiseDB(params.databaseName, params.collectionName) - - return new IagonStorageInstance( - params.databaseName, - internals, - params.options, - params.schema, - params.collectionName - ); - } -} - -export function createIagonStorage(parameters: IagonInternalParameters) { - const storage: RxStorage = new IagonStorage(parameters) - return wrappedKeyEncryptionStorage({ - storage: storage - }); -} diff --git a/packages/iagon/src/IagonStorage/instance.ts b/packages/iagon/src/IagonStorage/instance.ts deleted file mode 100644 index 20ad3fe6..00000000 --- a/packages/iagon/src/IagonStorage/instance.ts +++ /dev/null @@ -1,244 +0,0 @@ -import { - Subject, type Observable -} from 'rxjs' - -import { RxStorageInstance, StringKeys, RxDocumentData, RxConflictResultionTask, EventBulk, RxStorageChangeEvent, RxStorageDefaultCheckpoint, RxJsonSchema, getPrimaryFieldOfPrimaryKey, BulkWriteRow, RxConflictResultionTaskSolution, RxDocumentDataById, RxStorageBulkWriteResponse, RxStorageCountResult, RxStorageQueryResult, categorizeBulkWriteRows, ensureNotFalsy, now, getQueryMatcher, getSortComparator } from "rxdb"; -import { IagonInternalParameters, IagonStorageInternals } from './types'; -import { IagonInternals } from './internals'; -import { QueryMatcher } from 'rxdb/dist/types/types'; -import { fixTxPipe } from '@pluto-encrypted/shared'; - - -export class IagonStorageInstance< - RxDocType, -> implements RxStorageInstance< - RxDocType, - IagonStorageInternals, - IagonInternalParameters, - RxStorageDefaultCheckpoint -> { - public readonly primaryPath: StringKeys> - - public isInitialised = false; - - public conflictResultionTasks$ = new Subject>() - public changes$ = new Subject>, RxStorageDefaultCheckpoint>>() - - constructor( - public databaseName: string, - public internals: IagonInternals, - public options: Readonly, - public schema: Readonly>>, - public collectionName: string, - public refCount: number = 0 - ) { - this.primaryPath = getPrimaryFieldOfPrimaryKey(this.schema.primaryKey) - } - - async findDocumentsById(ids: string[], withDeleted: boolean): Promise> { - const allFiles = await this.internals.sdk.getFiles(this.internals.__dataFolder._id); - const matchingFiles = allFiles.filter((file) => ids.includes(file.name)); - const documents: RxDocumentDataById = {} - for (let file of matchingFiles) { - const fileContent = await this.internals.sdk.getFile({ file: file }) - const doc = JSON.parse(Buffer.from(fileContent).toString()); - const id = doc[this.primaryPath]; - documents[id] = doc; - } - return documents - } - - - private async resolveDocumentIds(ids: string[], selectorKeys: string[], queryMatcher: QueryMatcher>): Promise>> { - const documents: Array> = []; - for (let documentId of ids) { - const document = await this.internals.get(documentId) - if (document) { - if (selectorKeys.length <= 0) { - documents.push(document) - } - const matches = queryMatcher(document) - if (matches) { - documents.push(document) - } - } - } - return documents - } - - async query(preparedQuery: any): Promise> { - const { queryPlan, query } = preparedQuery - const selector = query.selector - const selectorKeys = Object.keys(selector) - const skip = query.skip ? query.skip : 0 - const limit = query.limit ? query.limit : Infinity - const skipPlusLimit = skip + limit - const queryMatcher: QueryMatcher> = getQueryMatcher( - this.schema, - query - ) - - const queryPlanFields: string[] = queryPlan.index - const indexes: string[] = [] - if (queryPlanFields.length === 1) { - indexes.push(fixTxPipe(queryPlanFields[0]!)) - } else { - indexes.push(...queryPlanFields.map(field => fixTxPipe(field))) - } - - const shouldAddCompoundIndexes = this.schema.indexes?.find((index) => { - if (typeof index === 'string') { - return indexes.find((index2) => index2 === index) - } else { - return index.find((subIndex) => { - return subIndex === index.find((indexValue) => indexValue === subIndex) - }) - } - }) - - if (shouldAddCompoundIndexes) { - indexes.splice(0, indexes.length) - indexes.push(this.collectionName) - if (typeof shouldAddCompoundIndexes === 'string') { - indexes.push(shouldAddCompoundIndexes) - } else { - indexes.push(...shouldAddCompoundIndexes) - } - } else { - indexes.unshift(this.collectionName) - } - - const indexName: string = `[${indexes.join('+')}]` - - const documentIds = await this.internals.getIndex(indexName) - - if (!documentIds || documentIds.length <= 0) { - return { documents: [] } - } - - let documents = await this.resolveDocumentIds( - documentIds, - selectorKeys, - queryMatcher - ) - - const sortComparator = getSortComparator(this.schema, preparedQuery.query) - documents = documents.sort(sortComparator) - documents = documents.slice(skip, skipPlusLimit) - return { - documents - } - } - async count(preparedQuery: any): Promise { - const result = await this.query(preparedQuery) - return { - count: result.documents.length, - mode: 'fast' - } - } - getAttachmentData(documentId: string, attachmentId: string, digest: string): Promise { - throw new Error('Method not implemented.'); - } - getChangedDocumentsSince(limit: number, checkpoint?: any): Promise<{ documents: RxDocumentData[]; checkpoint: any; }> { - throw new Error('Method not implemented.'); - } - - async cleanup(minimumDeletedTime: number): Promise { - await this.internals.sdk.removeDirectory(this.internals.__collectionFolder, true) - return true - } - close(): Promise { - return Promise.resolve() - } - changeStream(): Observable, any>> { - return this.changes$.asObservable() - } - remove(): Promise { - return Promise.resolve() - } - conflictResultionTasks(): Observable> { - return this.conflictResultionTasks$.asObservable() - } - resolveConflictResultionTask(taskSolution: RxConflictResultionTaskSolution): Promise { - return Promise.resolve() - } - private async getAllDocuments() { - const allDocuments: Map> = new Map(); - const dataFiles = await this.internals.sdk.getFiles(this.internals.__dataFolder._id); - for (let file of dataFiles) { - const fileContent = await this.internals.sdk.getFile({ file }); - const rxDoc: RxDocumentData = JSON.parse(Buffer.from(fileContent).toString()) - const currentId = rxDoc[this.primaryPath] as any; - allDocuments.set(currentId, rxDoc) - } - return allDocuments - } - async bulkWrite(documentWrites: BulkWriteRow[], context: string): Promise> { - const primaryPath = this.primaryPath - const ret: RxStorageBulkWriteResponse = { - success: {}, - error: {} - } - const documents = await this.getAllDocuments() - const fixed: BulkWriteRow[] = [] - for (let currentWriteDoc of documentWrites) { - const currentId = currentWriteDoc.document[this.primaryPath] as any; - const previousDocument = currentWriteDoc.previous ?? documents.get(currentId) - if (context === 'data-migrator-delete') { - if (previousDocument && previousDocument._rev === currentWriteDoc.document._rev) { - fixed.push(currentWriteDoc) - } - } else { - if (previousDocument && previousDocument._rev !== currentWriteDoc.document._rev) { - currentWriteDoc.previous = previousDocument - } else { - currentWriteDoc.previous = undefined - } - fixed.push(currentWriteDoc) - } - } - - const categorized = categorizeBulkWriteRows( - this, - primaryPath as any, - documents, - fixed, - context - ) - ret.error = categorized.errors - - /** - * Do inserts/updates - */ - const bulkInsertDocs = categorized.bulkInsertDocs - for (let i = 0; i < bulkInsertDocs.length; ++i) { - const writeRow = bulkInsertDocs[i]! - const docId = writeRow.document[primaryPath] - await this.internals.bulkPut([writeRow.document], this.collectionName, this.schema) - ret.success[docId as any] = writeRow.document - } - - const bulkUpdateDocs = categorized.bulkUpdateDocs - for (let i = 0; i < bulkUpdateDocs.length; ++i) { - const writeRow = bulkUpdateDocs[i]! - const docId = writeRow.document[primaryPath] - await this.internals.bulkPut([writeRow.document], this.collectionName, this.schema) - ret.success[docId as any] = writeRow.document - } - - if (categorized.eventBulk.events.length > 0) { - const lastState = ensureNotFalsy(categorized.newestRow).document - categorized.eventBulk.checkpoint = { - id: lastState[primaryPath], - lwt: lastState._meta.lwt - } - const endTime = now() - categorized.eventBulk.events.forEach(event => { - (event as any).endTime = endTime - }) - this.changes$.next(categorized.eventBulk) - } - - return Promise.resolve(ret) - } -} \ No newline at end of file diff --git a/packages/iagon/src/IagonStorage/internals.ts b/packages/iagon/src/IagonStorage/internals.ts deleted file mode 100644 index 0bbcee40..00000000 --- a/packages/iagon/src/IagonStorage/internals.ts +++ /dev/null @@ -1,183 +0,0 @@ -import { - RxDocumentData, - RxDocumentDataById, - RxJsonSchema -} from "rxdb"; -import { IagonAPI } from "./api"; -import { IagonFolder, IagonInternalParameters, IagonStorageInternals } from "./types"; -import { getPrivateKeyValue, safeIndexList } from "@pluto-encrypted/shared"; - - -export class IagonInternals implements IagonStorageInternals { - public __databaseFolder!: IagonFolder; - public __collectionFolder!: IagonFolder; - public __indexFolder!: IagonFolder; - public __dataFolder!: IagonFolder; - public indexes: Map = new Map() - - public sdk: IagonAPI; - - - constructor(parameters: IagonInternalParameters, public refCount: number = 0) { - this.sdk = new IagonAPI(parameters) - } - - async getDBDirectory(databaseName: string) { - return this.sdk.getDirectories().then((directories) => { - if (directories.length > 0) { - const found = directories.find((directory) => directory.directory_name === databaseName) - if (found) { - return found; - } - } - return this.sdk.createDirectory({ dirName: databaseName }); - }) - } - - private async resetDatabase() { - const rootDirectories = await this.sdk.getDirectories(); - for (let directory of rootDirectories) { - await this.sdk.removeDirectory(directory, true) - } - } - - async initialiseDB(databaseName: string, collectionName: string) { - try { - if (!this.__databaseFolder) { - const databaseDir = await this.getDBDirectory(databaseName); - this.__databaseFolder = databaseDir; - } - - if (!this.__collectionFolder) { - const collections = await this.sdk.getDirectories(this.__databaseFolder._id); - const __collectionFolder = collections.length > 0 ? collections.find((directory) => directory.directory_name === collectionName) : null; - - if (__collectionFolder) { - this.__collectionFolder = __collectionFolder; - } else { - const newDirectory = await this.sdk.createDirectory({ parentDirectoryId: this.__databaseFolder._id, dirName: collectionName }) - this.__collectionFolder = newDirectory - } - } - - const collectionFolders = await this.sdk.getDirectories(this.__collectionFolder._id); - const indexesFound = collectionFolders.length > 0 ? collectionFolders.find((directory) => directory.directory_name === "indexes") : null; - const dataFound = collectionFolders.length > 0 ? collectionFolders.find((directory) => directory.directory_name === "data") : null; - - if (!this.__indexFolder) { - if (indexesFound) { - this.__indexFolder = indexesFound; - } else { - this.__indexFolder = await this.sdk.createDirectory({ - parentDirectoryId: this.__collectionFolder._id, - dirName: 'indexes' - }) - } - } - - if (!this.__dataFolder) { - if (dataFound) { - this.__dataFolder = dataFound; - } else { - this.__dataFolder = await this.sdk.createDirectory({ - parentDirectoryId: this.__collectionFolder._id, - dirName: 'data' - }) - } - } - - - } catch (err) { - return Promise.reject(err) - } - } - - - bulkGet(keys: string[]): Promise> { - throw new Error("Method not implemented."); - } - async addDoc(docId: string, document: RxDocumentData): Promise { - const jsonDoc = JSON.stringify(document) - await this.removeDoc(docId) - await this.sdk.uploadFile(this.__dataFolder, docId, Buffer.from(jsonDoc)) - } - async removeDoc(docId: string): Promise { - const allFiles = await this.sdk.getFiles(this.__dataFolder._id); - const matchingFiles = allFiles.filter((file) => file.name === docId) - for (let file of matchingFiles) { - await this.sdk.removeFile(file._id) - } - } - async removeFromIndex(indexName: string, docId: string): Promise { - const currentIndex = await this.getIndex(indexName) - const cleanIndexPath = indexName.replace(/\[(.*)\]/g, "$1").split("+").join("/"); - const indexFilename = `${cleanIndexPath.split("/").join("_")}`; - const jsonString = JSON.stringify([ - ...currentIndex.filter((index) => index !== docId), - ]) - await this.sdk.uploadFile(this.__indexFolder, indexFilename, Buffer.from(jsonString)) - } - async get(key: string): Promise | null> { - const files = await this.sdk.getFiles(this.__dataFolder._id); - const fileFound = files.find((file) => { - return file.name === key; - }) - if (!fileFound) { - return null; - } - const fileContents = await this.sdk.getFile({ file: fileFound }) - const jsonDocument: RxDocumentData = JSON.parse(Buffer.from(fileContents).toString()); - return jsonDocument - } - async bulkPut(items: RxDocumentData[], collectionName: string, schema: RxJsonSchema>): Promise { - const primaryKeyKey = typeof schema.primaryKey === 'string' ? schema.primaryKey : schema.primaryKey.key - const saferIndexList = safeIndexList(schema) - for (const item of items) { - const shouldDelete = item._deleted - const id = getPrivateKeyValue(item, schema) - if (shouldDelete) { - for (const requiredIndexes of saferIndexList) { - const requiredIndex = `[${collectionName}+${requiredIndexes.join('+')}]` - await this.removeFromIndex(requiredIndex, id) - } - await this.removeFromIndex(`[${collectionName}+${primaryKeyKey}]`, id) - await this.removeFromIndex('[all]', id) - await this.removeDoc(id) - } else { - for (const requiredIndexes of saferIndexList) { - const requiredIndex = `[${collectionName}+${requiredIndexes.join('+')}]` - await this.updateIndex(requiredIndex, id) - } - await this.updateIndex(`[${collectionName}+${primaryKeyKey}]`, id) - await this.updateIndex('[all]', id) - await this.addDoc(id, item) - } - } - } - - async getIndex(key: string): Promise { - const indexFiles = await this.sdk.getFiles(this.__indexFolder._id); - const cleanIndexPath = key.replace(/\[(.*)\]/g, "$1").split("+").join("_"); - const indexFound = indexFiles.reverse().find((indexFile) => { - return indexFile.name === cleanIndexPath - }); - if (!indexFound) { - return []; - } - const indexContents = await this.sdk.getFile({ file: indexFound }) - const jsonParsed: string[] = JSON.parse(Buffer.from(indexContents).toString()) - return jsonParsed - } - - async updateIndex(indexName: string, docId: string) { - const currentIndex = await this.getIndex(indexName) - const cleanIndexPath = indexName.replace(/\[(.*)\]/g, "$1").split("+").join("/"); - const indexFilename = `${cleanIndexPath.split("/").join("_")}`; - const jsonString = JSON.stringify(Array.from(new Set([ - ...currentIndex, - docId - ]))) - await this.sdk.uploadFile(this.__indexFolder, indexFilename, Buffer.from(jsonString)) - } - -} diff --git a/packages/iagon/src/IagonStorage/types.ts b/packages/iagon/src/IagonStorage/types.ts deleted file mode 100644 index 59cfd10c..00000000 --- a/packages/iagon/src/IagonStorage/types.ts +++ /dev/null @@ -1,72 +0,0 @@ -import { RxDocumentData, RxDocumentDataById, RxJsonSchema } from "rxdb" - - - -export type IagonInternalParameters = { - apiKey: string, - password: Uint8Array -} - -export enum VISIBILITY { - private = "private", - public = "public" -} - -export type IagonFolder = { - __v: number, - _id: string, - client_id: string, - created_at: string, - directory_name: string, - index_listing: boolean, - parent_directory_id: string | null, - path: string, - updated_at: string, - visibility: VISIBILITY -} - -export type IagonFile = { - __v: number, - _id: string, - availability: string, - client_id: string, - createdAt: string, - file_size_byte_encrypted: 24, - file_size_byte_native: 0, - index_listing: boolean, - name: string, - parent_directory_id: string | null, - path: string, - region: string | null, - unique_id: string, - updated_at: string, - visibility: VISIBILITY -} - -export type IagonResponse = { - success: true, - data: Data -} | { - success: false, - message: string -} - -export type IagonStorageInternals = { - __databaseFolder: IagonFolder; - __collectionFolder: IagonFolder; - __indexFolder: IagonFolder; - __dataFolder: IagonFolder; - refCount: number; - - getDBDirectory(databaseName: string): Promise - initialiseDB(databaseName: string, collectionName: string): Promise - bulkGet(keys: string[]): Promise> - - addDoc(docId: string, document: RxDocumentData): Promise - removeDoc(docId: string): Promise - removeFromIndex(indexName: string, docId: string): Promise - get(key: string): Promise | null> - getIndex(key: string): Promise - updateIndex(indexName: string, docId: string): Promise - bulkPut(items: Array>, collectionName: string, schema: Readonly>>): Promise -} \ No newline at end of file diff --git a/packages/iagon/src/index.ts b/packages/iagon/src/index.ts deleted file mode 100644 index 64ebaad2..00000000 --- a/packages/iagon/src/index.ts +++ /dev/null @@ -1,5 +0,0 @@ -export * from './IagonStorage/api'; -export * from './IagonStorage'; -export * from './IagonStorage/instance'; -export * from './IagonStorage/internals'; -export * from './IagonStorage/types'; diff --git a/packages/iagon/tests/init.test.ts b/packages/iagon/tests/init.test.ts deleted file mode 100644 index df273f9a..00000000 --- a/packages/iagon/tests/init.test.ts +++ /dev/null @@ -1,42 +0,0 @@ -import "./setup"; - -import { describe, it, beforeEach, afterEach } from 'vitest'; -import { runTestSuite } from '@pluto-encrypted/test-suite'; -import { createIagonStorage } from '../src' - -if (!process.env.IAGON_API_KEY) { - throw new Error("Please add IAGON_API_KEY env var with your IagonAPI") -} - -if (!process.env.IAGON_PW) { - throw new Error("Please add IAGON_PW env var with your IagonAPI") -} - -const iagonStorage = createIagonStorage({ - apiKey: process.env.IAGON_API_KEY, - password: Buffer.from(process.env.IAGON_PW), -}) - -describe("Testing suite", () => { - runTestSuite({ - describe, it, beforeEach, afterEach - }, { - name: 'iagon', - getStorage() { - return iagonStorage - }, - getPerformanceStorage() { - return { - storage: iagonStorage, - description: 'any' - } - }, - hasPersistence: true, - hasMultiInstance: false, - hasAttachments: false, - hasBooleanIndexSupport: false, - async hasEncryption() { - return 'RandomPassword' - } - }) -}) diff --git a/packages/iagon/tests/setup.ts b/packages/iagon/tests/setup.ts deleted file mode 100644 index a6df6e1b..00000000 --- a/packages/iagon/tests/setup.ts +++ /dev/null @@ -1,17 +0,0 @@ -import "fake-indexeddb/auto"; -import { TextEncoder, TextDecoder } from "util"; -import { addRxPlugin } from "rxdb"; -import { RxDBDevModePlugin } from "rxdb/plugins/dev-mode"; -import nodeCrypto from "crypto"; - -if (process.env.NODE_ENV === "debug") { - addRxPlugin(RxDBDevModePlugin); -} - -Object.defineProperty(globalThis, "crypto", { - value: { - getRandomValues: (arr) => nodeCrypto.getRandomValues(arr), - }, -}); - -Object.assign(global, { TextDecoder, TextEncoder }); diff --git a/packages/iagon/tsconfig.json b/packages/iagon/tsconfig.json deleted file mode 100644 index 99c2653a..00000000 --- a/packages/iagon/tsconfig.json +++ /dev/null @@ -1,10 +0,0 @@ -{ - "extends": "../../tsconfig.json", - "compilerOptions": { - "rootDir": "./src", - "declarationDir": "./build", - }, - "include": [ - "src" - ] -} \ No newline at end of file diff --git a/packages/iagon/vitest.config.ts b/packages/iagon/vitest.config.ts deleted file mode 100644 index 21b8c892..00000000 --- a/packages/iagon/vitest.config.ts +++ /dev/null @@ -1,30 +0,0 @@ -/// -import { defineConfig } from 'vite' - -const isCI = process.env.CI === "true"; - -export default defineConfig({ - build: { - minify: 'terser', - terserOptions: { format: { comments: 'all' } }, - }, - test: { - testTimeout: 200000, - hookTimeout: 200000, - reporters: ['verbose'], // or 'verbose' - coverage: { - provider: 'istanbul', - reporter: isCI ? ['json-summary'] : ['json-summary', "html"], - thresholds: { - branches: 50, - functions: 50, - lines: 50, - statements: 50 - }, - include: [ - 'src/**/*', - ], - }, - - } -})