From e124ef41aea88dbcc0285f72d21d531819eb7386 Mon Sep 17 00:00:00 2001 From: Bartosz Wrobel Date: Fri, 24 Sep 2021 16:07:22 +0200 Subject: [PATCH 01/23] bug(core) made use of Buffer class in new way --- src/utils/ENS_hash.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/ENS_hash.ts b/src/utils/ENS_hash.ts index 292e22ac..bb05c191 100644 --- a/src/utils/ENS_hash.ts +++ b/src/utils/ENS_hash.ts @@ -35,7 +35,7 @@ export function namehash(inputName: string) { const normalizedLabel = normalize(labels[i]); labelSha = sha3(normalizedLabel); } - node = sha3(new Buffer(node + labelSha, "hex")); + node = sha3(Buffer.from(node + labelSha, "hex")); } } From b4fd1234d59fb78b99a128cd7ec4f8fc57e83487 Mon Sep 17 00:00:00 2001 From: Bartosz Wrobel Date: Wed, 29 Sep 2021 09:42:25 +0200 Subject: [PATCH 02/23] fix(nats): change in the way nats is referenced changed the way nats.ws is referenced according to document https://github.com/nats-io/nats.ws/blob/master/developer_notes.md --- bili.config.ts | 36 +++++++++-------------- src/iam.ts | 2 +- src/iam/iam-base.ts | 2 +- test/claimsTests/enrollmentClaimsTests.ts | 2 +- test/testUtils/mocks.ts | 2 +- 5 files changed, 18 insertions(+), 26 deletions(-) diff --git a/bili.config.ts b/bili.config.ts index 23570cc2..d61a8769 100644 --- a/bili.config.ts +++ b/bili.config.ts @@ -1,28 +1,20 @@ import { Config } from "bili"; const config: Config = { - plugins: { - typescript2: { - tsconfigOverride: { - include: ["src", "ethers"] - } - } - }, - extendConfig: config => ({ - ...config, - // The default externals are the package.json dependencies and can only bundle node_modules that are not a dependency. - // So need to clear out all externals, to bundle nats.ws package. - externals: [] - }), - // nats.ws is bundled because using standard import/require does not work for cjs format. - // nat.ws only provides a .mjs file which cannot be required. - // include tslib for clients using older version of tslib - bundleNodeModules: ["nats.ws", "tslib"], - input: "src/iam-client-lib.ts", - output: { - format: ["cjs", "esm"], - minify: false - } + plugins: { + typescript2: { + tsconfigOverride: { + include: ["src", "ethers"], + }, + }, + }, + // include tslib for clients using older version of tslib + bundleNodeModules: ["tslib"], + input: "src/iam-client-lib.ts", + output: { + format: ["cjs", "esm"], + minify: false, + }, }; export default config; diff --git a/src/iam.ts b/src/iam.ts index 44ff2b54..e3de099c 100644 --- a/src/iam.ts +++ b/src/iam.ts @@ -63,7 +63,7 @@ import { proof_type_hash, typedMsgPrefix, } from "./utils/constants"; -import { Subscription } from "nats.ws"; +import { Subscription } from "../node_modules/nats.ws/lib/src/mod.js"; import { AxiosError } from "axios"; import { DIDDocumentFull } from "@ew-did-registry/did-document"; import { Methods } from "@ew-did-registry/did"; diff --git a/src/iam/iam-base.ts b/src/iam/iam-base.ts index ed4bd3f8..dd1f6d0b 100644 --- a/src/iam/iam-base.ts +++ b/src/iam/iam-base.ts @@ -25,7 +25,7 @@ import { ClaimManager } from "../../ethers/ClaimManager"; import { JWT } from "@ew-did-registry/jwt"; import { ICacheServerClient } from "../cacheServerClient/ICacheServerClient"; import { detectExecutionEnvironment, ExecutionEnvironment } from "../utils/detectEnvironment"; -import { connect, NatsConnection, JSONCodec, Codec } from "nats.ws"; +import { connect, NatsConnection, Codec, JSONCodec } from "../../node_modules/nats.ws/lib/src/mod.js"; import { ERROR_MESSAGES } from "../errors"; import { ClaimData } from "../cacheServerClient/cacheServerClient.types"; import difference from "lodash.difference"; diff --git a/test/claimsTests/enrollmentClaimsTests.ts b/test/claimsTests/enrollmentClaimsTests.ts index f1420548..5df99286 100644 --- a/test/claimsTests/enrollmentClaimsTests.ts +++ b/test/claimsTests/enrollmentClaimsTests.ts @@ -2,7 +2,7 @@ import { PreconditionType } from "@energyweb/iam-contracts"; import { Methods } from "@ew-did-registry/did"; import { addressOf } from "@ew-did-registry/did-ethr-resolver"; import { Wallet, utils } from "ethers"; -import { Codec } from "nats.ws"; +import { Codec } from "../../node_modules/nats.ws/lib/src/mod.js"; import { IAM, RegistrationTypes, IRoleDefinition, NATS_EXCHANGE_TOPIC } from "../../src/iam-client-lib"; import { createIam, root, rootOwner } from "../iam.test"; import { claimManager, replenish } from "../setup_contracts"; diff --git a/test/testUtils/mocks.ts b/test/testUtils/mocks.ts index 53a6eb54..ad02551c 100644 --- a/test/testUtils/mocks.ts +++ b/test/testUtils/mocks.ts @@ -1,5 +1,5 @@ import { IRoleDefinition } from "@energyweb/iam-contracts"; -import { JSONCodec } from "nats.ws"; +import { JSONCodec } from "../../node_modules/nats.ws/lib/src/mod.js"; import { Claim } from "../../src/cacheServerClient/cacheServerClient.types"; import { IAM } from "../../src/iam"; From 24fa04d4271bf879e02a3454602ad95ba9439eb6 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Wed, 29 Sep 2021 07:57:42 +0000 Subject: [PATCH 03/23] chore(release): 3.1.0-alpha.2 [skip ci] # [3.1.0-alpha.2](https://github.com/energywebfoundation/iam-client-lib/compare/v3.1.0-alpha.1...v3.1.0-alpha.2) (2021-09-29) ### Bug Fixes * **nats:** change in the way nats is referenced ([b4fd123](https://github.com/energywebfoundation/iam-client-lib/commit/b4fd1234d59fb78b99a128cd7ec4f8fc57e83487)) --- docs/CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index b7bbe2cf..f0b04a98 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,3 +1,10 @@ +# [3.1.0-alpha.2](https://github.com/energywebfoundation/iam-client-lib/compare/v3.1.0-alpha.1...v3.1.0-alpha.2) (2021-09-29) + + +### Bug Fixes + +* **nats:** change in the way nats is referenced ([b4fd123](https://github.com/energywebfoundation/iam-client-lib/commit/b4fd1234d59fb78b99a128cd7ec4f8fc57e83487)) + # [3.1.0-alpha.1](https://github.com/energywebfoundation/iam-client-lib/compare/v3.0.1-alpha.2...v3.1.0-alpha.1) (2021-09-23) From 867ecf276a242c971b63b36b00af5e5593bb65fa Mon Sep 17 00:00:00 2001 From: John Henderson Date: Wed, 29 Sep 2021 08:37:37 +0200 Subject: [PATCH 04/23] fix: update ew-did to fix invalid signature ICL-105 Fixed by standardizing format of publicKey --- package-lock.json | 128 ++++++++++++++++++++++---------------------- package.json | 16 +++--- src/iam/iam-base.ts | 2 +- 3 files changed, 72 insertions(+), 74 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2351c99f..967fd4a1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1734,62 +1734,55 @@ } }, "@ew-did-registry/claims": { - "version": "0.5.2-alpha.90.0", - "resolved": "https://registry.npmjs.org/@ew-did-registry/claims/-/claims-0.5.2-alpha.90.0.tgz", - "integrity": "sha512-KzPCDPb5qEbrGK3UF01UxsSw31FxbrRHbiG4lPOD8AAQOFL9UxlC6qTO+J3V6k9cXaRJmvUPDK9JiL7/7O+JYA==", - "requires": { - "@ew-did-registry/did": "0.5.2-alpha.90.0", - "@ew-did-registry/did-document": "0.5.2-alpha.90.0", - "@ew-did-registry/did-ethr-resolver": "0.5.2-alpha.90.0", - "@ew-did-registry/did-ipfs-store": "0.5.2-alpha.90.0", - "@ew-did-registry/did-resolver-interface": "0.5.2-alpha.90.0", + "version": "0.5.2-alpha.101.0", + "resolved": "https://registry.npmjs.org/@ew-did-registry/claims/-/claims-0.5.2-alpha.101.0.tgz", + "integrity": "sha512-LCOeSXcs+zs+LaptsmkObxO6xdWhq4JcCosqfazYmdofapcwMvPKzgprV2EAfGr/5PDwxCmSo7dGRRh6WTr6+Q==", + "requires": { + "@ew-did-registry/did": "0.5.2-alpha.101.0", + "@ew-did-registry/did-document": "0.5.2-alpha.101.0", + "@ew-did-registry/did-ethr-resolver": "0.5.2-alpha.101.0", + "@ew-did-registry/did-ipfs-store": "0.5.2-alpha.101.0", + "@ew-did-registry/did-resolver-interface": "0.5.2-alpha.101.0", "@ew-did-registry/did-store-interface": "0.5.0", - "@ew-did-registry/jwt": "0.5.2-alpha.90.0", - "@ew-did-registry/keys": "0.5.2-alpha.90.0", + "@ew-did-registry/jwt": "0.5.2-alpha.101.0", + "@ew-did-registry/keys": "0.5.2-alpha.101.0", "@types/sjcl": "1.0.28", "eciesjs": "^0.3.4", "sjcl": "npm:sjcl-complete@1.0.0" - }, - "dependencies": { - "sjcl": { - "version": "npm:sjcl-complete@1.0.0", - "resolved": "https://registry.npmjs.org/sjcl-complete/-/sjcl-complete-1.0.0.tgz", - "integrity": "sha512-nZx2bBY8jbx4cLjSToaUG0cI7J2mNBx2Op9T+eBBkiNe3xrFUkAHyZP0vEB6E8Q8iIDL6Qx8Yaf48pZJiq9JMQ==" - } } }, "@ew-did-registry/did": { - "version": "0.5.2-alpha.90.0", - "resolved": "https://registry.npmjs.org/@ew-did-registry/did/-/did-0.5.2-alpha.90.0.tgz", - "integrity": "sha512-rk3JHxKwOLkMtOYLdOVITGl23IZ/gjI16qpFkkTUhWLPx5RpFTGtQX2ijAnMI2kL1EyIPZqpUf+iv+90aNeclg==" + "version": "0.5.2-alpha.101.0", + "resolved": "https://registry.npmjs.org/@ew-did-registry/did/-/did-0.5.2-alpha.101.0.tgz", + "integrity": "sha512-X51o2KvzxN6k5TPOBGO9cvFF/0BJkzoZ0hgtKyBomk1M6mhb9BdW0U4vVImgemondGdiIeyx+hHdcaxPulju+A==" }, "@ew-did-registry/did-document": { - "version": "0.5.2-alpha.90.0", - "resolved": "https://registry.npmjs.org/@ew-did-registry/did-document/-/did-document-0.5.2-alpha.90.0.tgz", - "integrity": "sha512-5F8uVlyzjfoq7NaXbPat5uUnGNu8mUPyOROZLLedYKFCMlizYCecpiqIiDLZylaJz2hgEQCG8gj4JtfVTnml7g==", - "requires": { - "@ew-did-registry/did": "0.5.2-alpha.90.0", - "@ew-did-registry/did-ethr-resolver": "0.5.2-alpha.90.0", - "@ew-did-registry/did-resolver-interface": "0.5.2-alpha.90.0", - "@ew-did-registry/keys": "0.5.2-alpha.90.0", + "version": "0.5.2-alpha.101.0", + "resolved": "https://registry.npmjs.org/@ew-did-registry/did-document/-/did-document-0.5.2-alpha.101.0.tgz", + "integrity": "sha512-/4gx3smg1BIMZK3bhw3q/bEuzQ0rxzCnQ2/1qijCOfDzzGCGv+59kPD1mmETQIzxpVICfR/F9/g2MbdzdhtTIg==", + "requires": { + "@ew-did-registry/did": "0.5.2-alpha.101.0", + "@ew-did-registry/did-ethr-resolver": "0.5.2-alpha.101.0", + "@ew-did-registry/did-resolver-interface": "0.5.2-alpha.101.0", + "@ew-did-registry/keys": "0.5.2-alpha.101.0", "ethers": "^5.4.6" } }, "@ew-did-registry/did-ethr-resolver": { - "version": "0.5.2-alpha.90.0", - "resolved": "https://registry.npmjs.org/@ew-did-registry/did-ethr-resolver/-/did-ethr-resolver-0.5.2-alpha.90.0.tgz", - "integrity": "sha512-Emw5nJFz8LLTJiMUHMaQ2Hq7YtsUvIUcsTXJleOjPuASmZ28G+OMXZNe4y9B9zhudWRuzp7elQLSklMPmLU9aQ==", + "version": "0.5.2-alpha.101.0", + "resolved": "https://registry.npmjs.org/@ew-did-registry/did-ethr-resolver/-/did-ethr-resolver-0.5.2-alpha.101.0.tgz", + "integrity": "sha512-XouUMwUtLtX/Cm4NcIBd6jzOrlOjk8H2sb7RxRRbj8/yBGPoMJz0ZlX4+wpSpmlGx5QP/Fk+0CCb393CggEbHw==", "requires": { - "@ew-did-registry/did": "0.5.2-alpha.90.0", - "@ew-did-registry/did-resolver-interface": "0.5.2-alpha.90.0", - "@ew-did-registry/keys": "0.5.2-alpha.90.0", + "@ew-did-registry/did": "0.5.2-alpha.101.0", + "@ew-did-registry/did-resolver-interface": "0.5.2-alpha.101.0", + "@ew-did-registry/keys": "0.5.2-alpha.101.0", "ethers": "^5.4.6" } }, "@ew-did-registry/did-ipfs-store": { - "version": "0.5.2-alpha.90.0", - "resolved": "https://registry.npmjs.org/@ew-did-registry/did-ipfs-store/-/did-ipfs-store-0.5.2-alpha.90.0.tgz", - "integrity": "sha512-34Qeetfi3jAr2kDL6p5FmcXd3yuS9YGt3pCDLY4a7Je+FGR8Zu24N5pw2WRHOGn+IVpp7Zhnl7iI5CmgVuzbbw==", + "version": "0.5.2-alpha.101.0", + "resolved": "https://registry.npmjs.org/@ew-did-registry/did-ipfs-store/-/did-ipfs-store-0.5.2-alpha.101.0.tgz", + "integrity": "sha512-HKksjhzkxxGZ8Bkwx2fruJA3gTWYLvfTtO6UCW05+XoKqeQFDeaLX8vNzuuDXVS1zF33SQhRahZXGAJQYZteKg==", "requires": { "@ew-did-registry/did-store-interface": "0.5.0", "bl": "^4.0.2", @@ -1797,11 +1790,11 @@ } }, "@ew-did-registry/did-resolver-interface": { - "version": "0.5.2-alpha.90.0", - "resolved": "https://registry.npmjs.org/@ew-did-registry/did-resolver-interface/-/did-resolver-interface-0.5.2-alpha.90.0.tgz", - "integrity": "sha512-P2KGWPyZw5kn3rvjl/BwT6OWdWkar0iPZaNzUm4R4Ry797g425QG30Ad79TWJ7MJfmtCtb2dY+/Z/OKjlFkdLw==", + "version": "0.5.2-alpha.101.0", + "resolved": "https://registry.npmjs.org/@ew-did-registry/did-resolver-interface/-/did-resolver-interface-0.5.2-alpha.101.0.tgz", + "integrity": "sha512-Jbb/x6xhg7j1PWpk+qq4F08J8jun7LGLvoVAuk5ubJ5taeksd71nP7JMfG5DmMU3BRHfolTNG1uKhyabl7hZ2A==", "requires": { - "@ew-did-registry/did": "0.5.2-alpha.90.0", + "@ew-did-registry/did": "0.5.2-alpha.101.0", "ethers": "^5.4.6" } }, @@ -1811,11 +1804,11 @@ "integrity": "sha512-IRa5ze44YeJxpKADLWQkc1pGg+PZDEUeB8kOXuUKVvUDa24k7t5ck6D/iYJzFizrwsePu0aXZaMH7m57OBYPng==" }, "@ew-did-registry/jwt": { - "version": "0.5.2-alpha.90.0", - "resolved": "https://registry.npmjs.org/@ew-did-registry/jwt/-/jwt-0.5.2-alpha.90.0.tgz", - "integrity": "sha512-shh3dIZtGsmyDpujvhCTRqK7cQoIrtPWS6+45FSJOK1U6x7oNu3+2LFleLwQx+KfwTetKUC8OPD61qYePhd6zg==", + "version": "0.5.2-alpha.101.0", + "resolved": "https://registry.npmjs.org/@ew-did-registry/jwt/-/jwt-0.5.2-alpha.101.0.tgz", + "integrity": "sha512-ry8R2T8atb8AOCfVYLoC2E7Guwv69RLCb6L3BGZtQzTGRKw4R0i6141bG27jgO40YZzgptjSvLkYmf8s5nTMhw==", "requires": { - "@ew-did-registry/keys": "0.5.2-alpha.90.0", + "@ew-did-registry/keys": "0.5.2-alpha.101.0", "@types/jsonwebtoken": "8.5.0", "@types/promise.allsettled": "^1.0.3", "base64url": "^3.0.1", @@ -1827,9 +1820,9 @@ } }, "@ew-did-registry/keys": { - "version": "0.5.2-alpha.90.0", - "resolved": "https://registry.npmjs.org/@ew-did-registry/keys/-/keys-0.5.2-alpha.90.0.tgz", - "integrity": "sha512-LY+jA6ON0NK6JWBcEVY/kqw3aFZc3Dslska6kKXbQEJwiWDLnsOMmnf7NwGzF4NoZUauQQrDZtdl5uvQVyfIcg==", + "version": "0.5.2-alpha.101.0", + "resolved": "https://registry.npmjs.org/@ew-did-registry/keys/-/keys-0.5.2-alpha.101.0.tgz", + "integrity": "sha512-FdBNrZR+5C6BSF94jjoHtYGee7Vav8uj3pGFstIPDiJSiT4ThHwyVoNXQLJauWpuHQi4pI07aRbGSQhweN8sIA==", "requires": { "bn.js": "5.2.0", "eciesjs": "^0.3.4", @@ -1845,13 +1838,13 @@ } }, "@ew-did-registry/proxyidentity": { - "version": "0.5.2-alpha.90.0", - "resolved": "https://registry.npmjs.org/@ew-did-registry/proxyidentity/-/proxyidentity-0.5.2-alpha.90.0.tgz", - "integrity": "sha512-KDXPx2tmLqbYqYjgPvLjvS+jOWbIY3b/vMRP9sd+5b16+QbQvhQOyqDSpRvLHIKXdbXsNx9SwfC3r0QWl8TOgg==", + "version": "0.5.2-alpha.101.0", + "resolved": "https://registry.npmjs.org/@ew-did-registry/proxyidentity/-/proxyidentity-0.5.2-alpha.101.0.tgz", + "integrity": "sha512-GcGWKsxsyNM/8ewpNe85ot/QI6mGR0GHWQbQHIna7f2B6AI3x3lCUWHZ6Jvfza2t3RgNbN+pXT8TuIy/MnLuqg==", "requires": { - "@ew-did-registry/did-ethr-resolver": "0.5.2-alpha.90.0", - "@ew-did-registry/did-resolver-interface": "0.5.2-alpha.90.0", - "@ew-did-registry/keys": "0.5.2-alpha.90.0", + "@ew-did-registry/did-ethr-resolver": "0.5.2-alpha.101.0", + "@ew-did-registry/did-resolver-interface": "0.5.2-alpha.101.0", + "@ew-did-registry/keys": "0.5.2-alpha.101.0", "ethers": "^5.4.6" } }, @@ -7187,9 +7180,9 @@ } }, "eciesjs": { - "version": "0.3.11", - "resolved": "https://registry.npmjs.org/eciesjs/-/eciesjs-0.3.11.tgz", - "integrity": "sha512-WMyCAhS45hJdSzk2TZMYj9vo8+XjcsvnTG63MsIBmKgZbtTjViVSu201YmgfrjMuPZNm7gI7sJ8bkBR6ejN21A==", + "version": "0.3.12", + "resolved": "https://registry.npmjs.org/eciesjs/-/eciesjs-0.3.12.tgz", + "integrity": "sha512-noYSjSOM9F4CuODD5BNK1qt1uuDU7oSNvj2bssa4ymRL3/iVJt3Wp/w2TN/pXu5PloyYcfWSCEvVJ5jOiIY3Kg==", "requires": { "@types/secp256k1": "^4.0.2", "futoin-hkdf": "^1.3.3", @@ -8250,7 +8243,7 @@ } }, "ethereumjs-abi": { - "version": "git+https://github.com/ethereumjs/ethereumjs-abi.git#ee3994657fa7a427238e6ba92a84d0b529bbcde0", + "version": "git+https://github.com/ethereumjs/ethereumjs-abi.git#1a27c59c15ab1e95ee8e5c4ed6ad814c49cc439e", "from": "git+https://github.com/ethereumjs/ethereumjs-abi.git", "requires": { "bn.js": "^4.11.8", @@ -15728,9 +15721,9 @@ "integrity": "sha1-DMj20OK2IrR5xA1JnEbWS3Vcb18=" }, "nanoid": { - "version": "3.1.25", - "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.1.25.tgz", - "integrity": "sha512-rdwtIXaXCLFAQbnfqDRnI6jaRHp9fTcYBjtFKE8eezcZ7LuLjhUaQGNeMXf1HmRoCH32CLz6XwX0TtxEOS/A3Q==" + "version": "3.1.28", + "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.1.28.tgz", + "integrity": "sha512-gSu9VZ2HtmoKYe/lmyPFES5nknFrHa+/DT9muUFWFMi6Jh9E1I7bkvlQ8xxf1Kos9pi9o8lBnIOkatMhKX/YUw==" }, "nanomatch": { "version": "1.2.13", @@ -16312,7 +16305,7 @@ }, "abbrev": { "version": "1.1.1", - "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", + "resolved": false, "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==", "dev": true }, @@ -16375,7 +16368,7 @@ }, "ansicolors": { "version": "0.3.2", - "resolved": "https://registry.npmjs.org/ansicolors/-/ansicolors-0.3.2.tgz", + "resolved": false, "integrity": "sha1-ZlWX3oap/+Oqm/vmyuXG6kJrSXk=", "dev": true }, @@ -18213,7 +18206,7 @@ }, "text-table": { "version": "0.2.0", - "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", + "resolved": false, "integrity": "sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=", "dev": true }, @@ -21712,6 +21705,11 @@ "integrity": "sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==", "dev": true }, + "sjcl": { + "version": "npm:sjcl-complete@1.0.0", + "resolved": "https://registry.npmjs.org/sjcl-complete/-/sjcl-complete-1.0.0.tgz", + "integrity": "sha512-nZx2bBY8jbx4cLjSToaUG0cI7J2mNBx2Op9T+eBBkiNe3xrFUkAHyZP0vEB6E8Q8iIDL6Qx8Yaf48pZJiq9JMQ==" + }, "slash": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/slash/-/slash-3.0.0.tgz", diff --git a/package.json b/package.json index ac5b4ce5..5222f811 100644 --- a/package.json +++ b/package.json @@ -59,14 +59,14 @@ "@babel/runtime": "^7.12.5", "@energyweb/iam-contracts": "^3.0.0", "@ensdomains/ens": "^0.4.5", - "@ew-did-registry/claims": "0.5.2-alpha.90.0", - "@ew-did-registry/did": "0.5.2-alpha.90.0", - "@ew-did-registry/did-document": "0.5.2-alpha.90.0", - "@ew-did-registry/did-ethr-resolver": "0.5.2-alpha.90.0", - "@ew-did-registry/did-resolver-interface": "0.5.2-alpha.90.0", - "@ew-did-registry/jwt": "0.5.2-alpha.90.0", - "@ew-did-registry/keys": "0.5.2-alpha.90.0", - "@ew-did-registry/proxyidentity": "0.5.2-alpha.90.0", + "@ew-did-registry/claims": "0.5.2-alpha.101.0", + "@ew-did-registry/did": "0.5.2-alpha.101.0", + "@ew-did-registry/did-document": "0.5.2-alpha.101.0", + "@ew-did-registry/did-ethr-resolver": "0.5.2-alpha.101.0", + "@ew-did-registry/did-resolver-interface": "0.5.2-alpha.101.0", + "@ew-did-registry/jwt": "0.5.2-alpha.101.0", + "@ew-did-registry/keys": "0.5.2-alpha.101.0", + "@ew-did-registry/proxyidentity": "0.5.2-alpha.101.0", "@gnosis.pm/safe-apps-sdk": "1.0.3", "@metamask/detect-provider": "^1.2.0", "@walletconnect/web3-provider": "1.0.0-rc.4", diff --git a/src/iam/iam-base.ts b/src/iam/iam-base.ts index dd1f6d0b..c135402e 100644 --- a/src/iam/iam-base.ts +++ b/src/iam/iam-base.ts @@ -284,7 +284,7 @@ export class IAMBase { uriOrInfo: this._provider.connection.url, }); } else if (this._signer instanceof providers.JsonRpcSigner) { - this._didSigner = EwSigner.fromEthersProvider(this._signer.provider, this._publicKey); + this._didSigner = EwSigner.fromEthersSigner(this._signer, this._publicKey); } else { throw new Error(ERROR_MESSAGES.PROVIDER_NOT_INITIALIZED); } From 5ab1403c1a3743180fb57561b8034b4a7369b750 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Wed, 29 Sep 2021 08:09:22 +0000 Subject: [PATCH 05/23] chore(release): 3.1.0-alpha.3 [skip ci] # [3.1.0-alpha.3](https://github.com/energywebfoundation/iam-client-lib/compare/v3.1.0-alpha.2...v3.1.0-alpha.3) (2021-09-29) ### Bug Fixes * update ew-did to fix invalid signature ([867ecf2](https://github.com/energywebfoundation/iam-client-lib/commit/867ecf276a242c971b63b36b00af5e5593bb65fa)) --- docs/CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index f0b04a98..2977d24e 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,3 +1,10 @@ +# [3.1.0-alpha.3](https://github.com/energywebfoundation/iam-client-lib/compare/v3.1.0-alpha.2...v3.1.0-alpha.3) (2021-09-29) + + +### Bug Fixes + +* update ew-did to fix invalid signature ([867ecf2](https://github.com/energywebfoundation/iam-client-lib/commit/867ecf276a242c971b63b36b00af5e5593bb65fa)) + # [3.1.0-alpha.2](https://github.com/energywebfoundation/iam-client-lib/compare/v3.1.0-alpha.1...v3.1.0-alpha.2) (2021-09-29) From 4671db99f20ae92846bb1ac2fcbab14150dc1156 Mon Sep 17 00:00:00 2001 From: Bartosz Wrobel Date: Wed, 29 Sep 2021 10:33:05 +0200 Subject: [PATCH 06/23] fix(nats): changed path to nats.ws from absolute to relative fix to make nest.ws module able to found when using the iam-client-lib.esm.js --- src/iam.ts | 2 +- src/iam/iam-base.ts | 2 +- test/claimsTests/enrollmentClaimsTests.ts | 2 +- test/testUtils/mocks.ts | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/iam.ts b/src/iam.ts index e3de099c..96333b70 100644 --- a/src/iam.ts +++ b/src/iam.ts @@ -63,7 +63,7 @@ import { proof_type_hash, typedMsgPrefix, } from "./utils/constants"; -import { Subscription } from "../node_modules/nats.ws/lib/src/mod.js"; +import { Subscription } from "nats.ws/lib/src/mod.js"; import { AxiosError } from "axios"; import { DIDDocumentFull } from "@ew-did-registry/did-document"; import { Methods } from "@ew-did-registry/did"; diff --git a/src/iam/iam-base.ts b/src/iam/iam-base.ts index c135402e..a7b0b002 100644 --- a/src/iam/iam-base.ts +++ b/src/iam/iam-base.ts @@ -25,7 +25,7 @@ import { ClaimManager } from "../../ethers/ClaimManager"; import { JWT } from "@ew-did-registry/jwt"; import { ICacheServerClient } from "../cacheServerClient/ICacheServerClient"; import { detectExecutionEnvironment, ExecutionEnvironment } from "../utils/detectEnvironment"; -import { connect, NatsConnection, Codec, JSONCodec } from "../../node_modules/nats.ws/lib/src/mod.js"; +import { connect, NatsConnection, Codec, JSONCodec } from "nats.ws/lib/src/mod.js"; import { ERROR_MESSAGES } from "../errors"; import { ClaimData } from "../cacheServerClient/cacheServerClient.types"; import difference from "lodash.difference"; diff --git a/test/claimsTests/enrollmentClaimsTests.ts b/test/claimsTests/enrollmentClaimsTests.ts index 5df99286..30d429cb 100644 --- a/test/claimsTests/enrollmentClaimsTests.ts +++ b/test/claimsTests/enrollmentClaimsTests.ts @@ -2,7 +2,7 @@ import { PreconditionType } from "@energyweb/iam-contracts"; import { Methods } from "@ew-did-registry/did"; import { addressOf } from "@ew-did-registry/did-ethr-resolver"; import { Wallet, utils } from "ethers"; -import { Codec } from "../../node_modules/nats.ws/lib/src/mod.js"; +import { Codec } from "nats.ws/lib/src/mod.js"; import { IAM, RegistrationTypes, IRoleDefinition, NATS_EXCHANGE_TOPIC } from "../../src/iam-client-lib"; import { createIam, root, rootOwner } from "../iam.test"; import { claimManager, replenish } from "../setup_contracts"; diff --git a/test/testUtils/mocks.ts b/test/testUtils/mocks.ts index ad02551c..67b7346f 100644 --- a/test/testUtils/mocks.ts +++ b/test/testUtils/mocks.ts @@ -1,5 +1,5 @@ import { IRoleDefinition } from "@energyweb/iam-contracts"; -import { JSONCodec } from "../../node_modules/nats.ws/lib/src/mod.js"; +import { JSONCodec } from "nats.ws/lib/src/mod.js"; import { Claim } from "../../src/cacheServerClient/cacheServerClient.types"; import { IAM } from "../../src/iam"; From 191d84931f6029a4d3d100c074e6a81620d5af48 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Wed, 29 Sep 2021 08:52:48 +0000 Subject: [PATCH 07/23] chore(release): 3.1.0-alpha.4 [skip ci] # [3.1.0-alpha.4](https://github.com/energywebfoundation/iam-client-lib/compare/v3.1.0-alpha.3...v3.1.0-alpha.4) (2021-09-29) ### Bug Fixes * **nats:** changed path to nats.ws from absolute to relative ([4671db9](https://github.com/energywebfoundation/iam-client-lib/commit/4671db99f20ae92846bb1ac2fcbab14150dc1156)) --- docs/CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 2977d24e..4e11bd11 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,3 +1,10 @@ +# [3.1.0-alpha.4](https://github.com/energywebfoundation/iam-client-lib/compare/v3.1.0-alpha.3...v3.1.0-alpha.4) (2021-09-29) + + +### Bug Fixes + +* **nats:** changed path to nats.ws from absolute to relative ([4671db9](https://github.com/energywebfoundation/iam-client-lib/commit/4671db99f20ae92846bb1ac2fcbab14150dc1156)) + # [3.1.0-alpha.3](https://github.com/energywebfoundation/iam-client-lib/compare/v3.1.0-alpha.2...v3.1.0-alpha.3) (2021-09-29) From 7752b451f63a813ce1a574d1fb8e16f54eadcb5b Mon Sep 17 00:00:00 2001 From: Bartosz Wrobel Date: Wed, 29 Sep 2021 12:49:13 +0200 Subject: [PATCH 08/23] fix(core): update cache server interface to latest version and secure types fix to parentNamespace field and enforce type safety in interface implementation --- ...ent_cacheServerClient.CacheServerClient.md | 95 +++++------------- ...t_ICacheServerClient.ICacheServerClient.md | 97 ++++++------------- ...cheServerClient_cacheServerClient_types.md | 51 ++++++++++ src/cacheServerClient/ICacheServerClient.ts | 89 +++++++---------- src/cacheServerClient/cacheServerClient.ts | 90 ++++++++--------- .../cacheServerClient.types.ts | 22 +++++ 6 files changed, 200 insertions(+), 244 deletions(-) diff --git a/docs/api/classes/cacheServerClient_cacheServerClient.CacheServerClient.md b/docs/api/classes/cacheServerClient_cacheServerClient.CacheServerClient.md index ad71eb9e..f80acdff 100644 --- a/docs/api/classes/cacheServerClient_cacheServerClient.CacheServerClient.md +++ b/docs/api/classes/cacheServerClient_cacheServerClient.CacheServerClient.md @@ -86,8 +86,7 @@ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.did` | `string` | +| `__namedParameters` | `Pick`<[`ClaimsQueryParams`](../modules/cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"did"``\> | #### Returns @@ -123,8 +122,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.claimId` | `string` | +| `__namedParameters` | `Pick`<[`ClaimsQueryParams`](../modules/cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"claimId"``\> | #### Returns @@ -145,7 +143,6 @@ ___ | Name | Type | | :------ | :------ | | `__namedParameters` | `Object` | -| `__namedParameters.namespace` | `string` | #### Returns @@ -165,8 +162,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.namespace` | `string` | +| `__namedParameters` | `Pick`<[`ClaimsQueryParams`](../modules/cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"namespace"``\> | #### Returns @@ -186,8 +182,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.namespace` | `string` | +| `__namedParameters` | `Pick`<[`ClaimsQueryParams`](../modules/cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"namespace"``\> | #### Returns @@ -207,8 +202,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.owner` | `string` | +| `__namedParameters` | `Pick`<[`ClaimsQueryParams`](../modules/cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"owner"``\> | #### Returns @@ -228,8 +222,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.id` | `string` | +| `__namedParameters` | `Pick`<[`ClaimsQueryParams`](../modules/cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"id"``\> | #### Returns @@ -249,12 +242,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.id` | `string` | -| `__namedParameters.order?` | [`Order`](../enums/cacheServerClient_cacheServerClient_types.Order.md) | -| `__namedParameters.skip?` | `number` | -| `__namedParameters.take?` | `number` | -| `__namedParameters.type?` | [`AssetHistoryEventType`](../enums/cacheServerClient_cacheServerClient_types.AssetHistoryEventType.md) | +| `__namedParameters` | `Pick`<[`ClaimsQueryParams`](../modules/cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"type"`` \| ``"id"`` \| ``"order"`` \| ``"take"`` \| ``"skip"``\> | #### Returns @@ -274,10 +262,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.did` | `string` | -| `__namedParameters.isAccepted?` | `boolean` | -| `__namedParameters.namespace?` | `string` | +| `__namedParameters` | `Pick`<[`ClaimsQueryParams`](../modules/cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"did"`` \| ``"isAccepted"`` \| ``"parentNamespace"``\> | #### Returns @@ -297,10 +282,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.did` | `string` | -| `__namedParameters.isAccepted?` | `boolean` | -| `__namedParameters.namespace?` | `string` | +| `__namedParameters` | `Pick`<[`ClaimsQueryParams`](../modules/cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"did"`` \| ``"isAccepted"`` \| ``"parentNamespace"``\> | #### Returns @@ -320,10 +302,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.did` | `string` | -| `__namedParameters.isAccepted?` | `boolean` | -| `__namedParameters.namespace?` | `string` | +| `__namedParameters` | `Pick`<[`ClaimsQueryParams`](../modules/cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"did"`` \| ``"isAccepted"`` \| ``"parentNamespace"``\> | #### Returns @@ -363,8 +342,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.namespace` | `string` | +| `__namedParameters` | `Pick`<[`ClaimsQueryParams`](../modules/cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"namespace"``\> | #### Returns @@ -384,9 +362,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.did` | `string` | -| `__namedParameters.includeClaims?` | `boolean` | +| `__namedParameters` | `Pick`<[`ClaimsQueryParams`](../modules/cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"did"`` \| ``"includeClaims"``\> | #### Returns @@ -406,9 +382,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.search` | `string` | -| `__namedParameters.types?` | (``"App"`` \| ``"Org"`` \| ``"Role"``)[] | +| `__namedParameters` | `Pick`<[`ClaimsQueryParams`](../modules/cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"types"`` \| ``"search"``\> | #### Returns @@ -428,8 +402,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.did` | `string` | +| `__namedParameters` | `Pick`<[`ClaimsQueryParams`](../modules/cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"did"``\> | #### Returns @@ -449,8 +422,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.namespace` | `string` | +| `__namedParameters` | `Pick`<[`ClaimsQueryParams`](../modules/cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"namespace"``\> | #### Returns @@ -470,8 +442,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.namespace` | `string` | +| `__namedParameters` | `Pick`<[`ClaimsQueryParams`](../modules/cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"namespace"``\> | #### Returns @@ -491,8 +462,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.namespace` | `string` | +| `__namedParameters` | `Pick`<[`ClaimsQueryParams`](../modules/cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"namespace"``\> | #### Returns @@ -512,9 +482,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.excludeSubOrgs` | `boolean` | -| `__namedParameters.owner` | `string` | +| `__namedParameters` | `Pick`<[`ClaimsQueryParams`](../modules/cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"owner"`` \| ``"excludeSubOrgs"``\> | #### Returns @@ -534,8 +502,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.did` | `string` | +| `__namedParameters` | `Pick`<[`ClaimsQueryParams`](../modules/cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"did"``\> | #### Returns @@ -555,8 +522,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.owner` | `string` | +| `__namedParameters` | `Pick`<[`ClaimsQueryParams`](../modules/cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"owner"``\> | #### Returns @@ -576,8 +542,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.namespace` | `string` | +| `__namedParameters` | `Pick`<[`ClaimsQueryParams`](../modules/cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"namespace"``\> | #### Returns @@ -597,8 +562,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.owner` | `string` | +| `__namedParameters` | `Pick`<[`ClaimsQueryParams`](../modules/cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"owner"``\> | #### Returns @@ -618,8 +582,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.namespace` | `string` | +| `__namedParameters` | `Pick`<[`ClaimsQueryParams`](../modules/cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"namespace"``\> | #### Returns @@ -679,9 +642,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.did` | `string` | -| `__namedParameters.message` | [`IClaimIssuance`](../interfaces/iam.IClaimIssuance.md) | +| `__namedParameters` | [`IssueClaim`](../modules/cacheServerClient_cacheServerClient_types.md#issueclaim) | #### Returns @@ -715,9 +676,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.did` | `string` | -| `__namedParameters.message` | [`IClaimRejection`](../interfaces/iam.IClaimRejection.md) | +| `__namedParameters` | [`RejectClaim`](../modules/cacheServerClient_cacheServerClient_types.md#rejectclaim) | #### Returns @@ -737,9 +696,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.did` | `string` | -| `__namedParameters.message` | [`IClaimRequest`](../interfaces/iam.IClaimRequest.md) | +| `__namedParameters` | [`RequestClaim`](../modules/cacheServerClient_cacheServerClient_types.md#requestclaim) | #### Returns diff --git a/docs/api/interfaces/cacheServerClient_ICacheServerClient.ICacheServerClient.md b/docs/api/interfaces/cacheServerClient_ICacheServerClient.ICacheServerClient.md index 741aac4c..61eb6111 100644 --- a/docs/api/interfaces/cacheServerClient_ICacheServerClient.ICacheServerClient.md +++ b/docs/api/interfaces/cacheServerClient_ICacheServerClient.ICacheServerClient.md @@ -62,8 +62,7 @@ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.did` | `string` | +| `__namedParameters` | `Pick`<[`ClaimsQueryParams`](../modules/cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"did"``\> | #### Returns @@ -79,8 +78,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.claimId` | `string` | +| `__namedParameters` | `Pick`<[`ClaimsQueryParams`](../modules/cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"claimId"``\> | #### Returns @@ -96,8 +94,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.namespace` | `string` | +| `__namedParameters` | `Pick`<[`ClaimsQueryParams`](../modules/cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"namespace"``\> | #### Returns @@ -113,8 +110,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.namespace` | `string` | +| `__namedParameters` | `Pick`<[`ClaimsQueryParams`](../modules/cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"namespace"``\> | #### Returns @@ -130,8 +126,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.namespace` | `string` | +| `__namedParameters` | `Pick`<[`ClaimsQueryParams`](../modules/cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"namespace"``\> | #### Returns @@ -147,8 +142,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.owner` | `string` | +| `__namedParameters` | `Pick`<[`ClaimsQueryParams`](../modules/cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"owner"``\> | #### Returns @@ -164,8 +158,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.id` | `string` | +| `__namedParameters` | `Pick`<[`ClaimsQueryParams`](../modules/cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"id"``\> | #### Returns @@ -181,12 +174,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.id` | `string` | -| `__namedParameters.order?` | [`Order`](../enums/cacheServerClient_cacheServerClient_types.Order.md) | -| `__namedParameters.skip?` | `number` | -| `__namedParameters.take?` | `number` | -| `__namedParameters.type?` | [`AssetHistoryEventType`](../enums/cacheServerClient_cacheServerClient_types.AssetHistoryEventType.md) | +| `__namedParameters` | `Pick`<[`ClaimsQueryParams`](../modules/cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"type"`` \| ``"id"`` \| ``"order"`` \| ``"take"`` \| ``"skip"``\> | #### Returns @@ -202,10 +190,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.did` | `string` | -| `__namedParameters.isAccepted?` | `boolean` | -| `__namedParameters.parentNamespace?` | `string` | +| `__namedParameters` | `Pick`<[`ClaimsQueryParams`](../modules/cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"did"`` \| ``"isAccepted"`` \| ``"parentNamespace"``\> | #### Returns @@ -221,10 +206,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.did` | `string` | -| `__namedParameters.isAccepted?` | `boolean` | -| `__namedParameters.parentNamespace?` | `string` | +| `__namedParameters` | `Pick`<[`ClaimsQueryParams`](../modules/cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"did"`` \| ``"isAccepted"`` \| ``"parentNamespace"``\> | #### Returns @@ -240,10 +222,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.did` | `string` | -| `__namedParameters.isAccepted?` | `boolean` | -| `__namedParameters.parentNamespace?` | `string` | +| `__namedParameters` | `Pick`<[`ClaimsQueryParams`](../modules/cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"did"`` \| ``"isAccepted"`` \| ``"parentNamespace"``\> | #### Returns @@ -275,8 +254,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.namespace` | `string` | +| `__namedParameters` | `Pick`<[`ClaimsQueryParams`](../modules/cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"namespace"``\> | #### Returns @@ -292,9 +270,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.did` | `string` | -| `__namedParameters.includeClaims?` | `boolean` | +| `__namedParameters` | `Pick`<[`ClaimsQueryParams`](../modules/cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"did"`` \| ``"includeClaims"``\> | #### Returns @@ -310,9 +286,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.search` | `string` | -| `__namedParameters.types?` | (``"App"`` \| ``"Org"`` \| ``"Role"``)[] | +| `__namedParameters` | `Pick`<[`ClaimsQueryParams`](../modules/cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"types"`` \| ``"search"``\> | #### Returns @@ -328,8 +302,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.did` | `string` | +| `__namedParameters` | `Pick`<[`ClaimsQueryParams`](../modules/cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"did"``\> | #### Returns @@ -345,8 +318,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.namespace` | `string` | +| `__namedParameters` | `Pick`<[`ClaimsQueryParams`](../modules/cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"namespace"``\> | #### Returns @@ -362,8 +334,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.namespace` | `string` | +| `__namedParameters` | `Pick`<[`ClaimsQueryParams`](../modules/cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"namespace"``\> | #### Returns @@ -379,8 +350,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.namespace` | `string` | +| `__namedParameters` | `Pick`<[`ClaimsQueryParams`](../modules/cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"namespace"``\> | #### Returns @@ -396,9 +366,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.excludeSubOrgs` | `boolean` | -| `__namedParameters.owner` | `string` | +| `__namedParameters` | `Pick`<[`ClaimsQueryParams`](../modules/cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"owner"`` \| ``"excludeSubOrgs"``\> | #### Returns @@ -414,8 +382,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.did` | `string` | +| `__namedParameters` | `Pick`<[`ClaimsQueryParams`](../modules/cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"did"``\> | #### Returns @@ -431,8 +398,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.owner` | `string` | +| `__namedParameters` | `Pick`<[`ClaimsQueryParams`](../modules/cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"owner"``\> | #### Returns @@ -448,8 +414,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.namespace` | `string` | +| `__namedParameters` | `Pick`<[`ClaimsQueryParams`](../modules/cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"namespace"``\> | #### Returns @@ -465,8 +430,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.owner` | `string` | +| `__namedParameters` | `Pick`<[`ClaimsQueryParams`](../modules/cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"owner"``\> | #### Returns @@ -482,8 +446,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.namespace` | `string` | +| `__namedParameters` | `Pick`<[`ClaimsQueryParams`](../modules/cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"namespace"``\> | #### Returns @@ -509,9 +472,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.did` | `string` | -| `__namedParameters.message` | [`IClaimIssuance`](iam.IClaimIssuance.md) | +| `__namedParameters` | [`IssueClaim`](../modules/cacheServerClient_cacheServerClient_types.md#issueclaim) | #### Returns @@ -537,9 +498,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.did` | `string` | -| `__namedParameters.message` | [`IClaimRejection`](iam.IClaimRejection.md) | +| `__namedParameters` | [`RejectClaim`](../modules/cacheServerClient_cacheServerClient_types.md#rejectclaim) | #### Returns @@ -555,9 +514,7 @@ ___ | Name | Type | | :------ | :------ | -| `__namedParameters` | `Object` | -| `__namedParameters.did` | `string` | -| `__namedParameters.message` | [`IClaimRequest`](iam.IClaimRequest.md) | +| `__namedParameters` | [`RequestClaim`](../modules/cacheServerClient_cacheServerClient_types.md#requestclaim) | #### Returns diff --git a/docs/api/modules/cacheServerClient_cacheServerClient_types.md b/docs/api/modules/cacheServerClient_cacheServerClient_types.md index 2e704d3b..c4001eb7 100644 --- a/docs/api/modules/cacheServerClient_cacheServerClient_types.md +++ b/docs/api/modules/cacheServerClient_cacheServerClient_types.md @@ -20,3 +20,54 @@ - [IOrganization](../interfaces/cacheServerClient_cacheServerClient_types.IOrganization.md) - [IRole](../interfaces/cacheServerClient_cacheServerClient_types.IRole.md) - [Profile](../interfaces/cacheServerClient_cacheServerClient_types.Profile.md) + +### Type aliases + +- [ClaimsQueryParams](cacheServerClient_cacheServerClient_types.md#claimsqueryparams) +- [IssueClaim](cacheServerClient_cacheServerClient_types.md#issueclaim) +- [RejectClaim](cacheServerClient_cacheServerClient_types.md#rejectclaim) +- [RequestClaim](cacheServerClient_cacheServerClient_types.md#requestclaim) + +## Type aliases + +### ClaimsQueryParams + +Ƭ **ClaimsQueryParams**: `Object` + +#### Type declaration + +| Name | Type | +| :------ | :------ | +| `claimId` | `string` | +| `did` | `string` | +| `excludeSubOrgs` | `boolean` | +| `id` | `string` | +| `includeClaims?` | `boolean` | +| `isAccepted?` | `boolean` | +| `namespace` | `string` | +| `order?` | [`Order`](../enums/cacheServerClient_cacheServerClient_types.Order.md) | +| `owner` | `string` | +| `parentNamespace?` | `string` | +| `search` | `string` | +| `skip?` | `number` | +| `take?` | `number` | +| `type?` | [`AssetHistoryEventType`](../enums/cacheServerClient_cacheServerClient_types.AssetHistoryEventType.md) | +| `types?` | (``"App"`` \| ``"Org"`` \| ``"Role"``)[] | + +___ + +### IssueClaim + +Ƭ **IssueClaim**: `Pick`<[`ClaimsQueryParams`](cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"did"``\> & { `message`: [`IClaimIssuance`](../interfaces/iam.IClaimIssuance.md) } + +___ + +### RejectClaim + +Ƭ **RejectClaim**: `Pick`<[`ClaimsQueryParams`](cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"did"``\> & { `message`: [`IClaimRejection`](../interfaces/iam.IClaimRejection.md) } + +___ + +### RequestClaim + +Ƭ **RequestClaim**: `Pick`<[`ClaimsQueryParams`](cacheServerClient_cacheServerClient_types.md#claimsqueryparams), ``"did"``\> & { `message`: [`IClaimRequest`](../interfaces/iam.IClaimRequest.md) } diff --git a/src/cacheServerClient/ICacheServerClient.ts b/src/cacheServerClient/ICacheServerClient.ts index 9dce0ed4..6a07cb8f 100644 --- a/src/cacheServerClient/ICacheServerClient.ts +++ b/src/cacheServerClient/ICacheServerClient.ts @@ -1,97 +1,76 @@ import { IAppDefinition, IOrganizationDefinition, IRoleDefinition } from "@energyweb/iam-contracts"; import { IDIDDocument } from "@ew-did-registry/did-resolver-interface"; -import { IClaimIssuance, IClaimRejection, IClaimRequest } from "../iam"; import { IPubKeyAndIdentityToken } from "../utils/getPublicKeyAndIdentityToken"; import { Asset, AssetHistory, - AssetHistoryEventType, Claim, + ClaimsQueryParams, IApp, IOrganization, IRole, - Order, + IssueClaim, + RejectClaim, + RequestClaim, } from "./cacheServerClient.types"; - export interface ICacheServerClient { pubKeyAndIdentityToken: IPubKeyAndIdentityToken | undefined; testLogin: () => Promise; login: () => Promise<{ pubKeyAndIdentityToken: IPubKeyAndIdentityToken; token: string; refreshToken: string }>; isAuthEnabled: () => boolean; - getRoleDefinition: ({ namespace }: { namespace: string }) => Promise; - getOrgDefinition: ({ namespace }: { namespace: string }) => Promise; - getAppDefinition: ({ namespace }: { namespace: string }) => Promise; - getApplicationRoles: ({ namespace }: { namespace: string }) => Promise; - getOrganizationRoles: ({ namespace }: { namespace: string }) => Promise; + getRoleDefinition: ({ namespace }: Pick) => Promise; + getOrgDefinition: ({ namespace }: Pick) => Promise; + getAppDefinition: ({ namespace }: Pick) => Promise; + getApplicationRoles: ({ namespace }: Pick) => Promise; + getOrganizationRoles: ({ namespace }: Pick) => Promise; getOrganizationsByOwner: ({ owner, excludeSubOrgs, - }: { - owner: string; - excludeSubOrgs: boolean; - }) => Promise; - getApplicationsByOwner: ({ owner }: { owner: string }) => Promise; - getApplicationsByOrganization: ({ namespace }: { namespace: string }) => Promise; - getSubOrganizationsByOrganization: ({ namespace }: { namespace: string }) => Promise; - getOrgHierarchy: ({ namespace }: { namespace: string }) => Promise; + }: Pick) => Promise; + getApplicationsByOwner: ({ owner }: Pick) => Promise; + getApplicationsByOrganization: ({ namespace }: Pick) => Promise; + getSubOrganizationsByOrganization: ({ + namespace, + }: Pick) => Promise; + getOrgHierarchy: ({ namespace }: Pick) => Promise; getNamespaceBySearchPhrase: ({ types, search, - }: { - types?: ("App" | "Org" | "Role")[]; - search: string; - }) => Promise<(IOrganization | IApp | IRole)[]>; - getRolesByOwner: ({ owner }: { owner: string }) => Promise; + }: Pick) => Promise<(IOrganization | IApp | IRole)[]>; + getRolesByOwner: ({ owner }: Pick) => Promise; getClaimsBySubjects: (subjects: string[]) => Promise; getClaimsByIssuer: ({ did, isAccepted, parentNamespace, - }: { - did: string; - isAccepted?: boolean; - parentNamespace?: string; - }) => Promise; + }: Pick) => Promise; getClaimsByRequester: ({ did, isAccepted, parentNamespace, - }: { - did: string; - isAccepted?: boolean; - parentNamespace?: string; - }) => Promise; + }: Pick) => Promise; getClaimsBySubject: ({ did, isAccepted, parentNamespace, - }: { - did: string; - isAccepted?: boolean; - parentNamespace?: string; - }) => Promise; - requestClaim: ({ message, did }: { message: IClaimRequest; did: string }) => Promise; - issueClaim: ({ message, did }: { message: IClaimIssuance; did: string }) => Promise; - rejectClaim: ({ message, did }: { message: IClaimRejection; did: string }) => Promise; - deleteClaim: ({ claimId }: { claimId: string }) => Promise; - getDIDsForRole: ({ namespace }: { namespace: string }) => Promise; - getDidDocument: ({ did, includeClaims }: { did: string; includeClaims?: boolean }) => Promise; - addDIDToWatchList: ({ did }: { did: string }) => Promise; - getOwnedAssets: ({ did }: { did: string }) => Promise; - getOfferedAssets: ({ did }: { did: string }) => Promise; - getAssetById: ({ id }: { id: string }) => Promise; - getPreviouslyOwnedAssets: ({ owner }: { owner: string }) => Promise; + }: Pick) => Promise; + + requestClaim: ({ message, did }: RequestClaim) => Promise; + issueClaim: ({ message, did }: IssueClaim) => Promise; + rejectClaim: ({ message, did }: RejectClaim) => Promise; + deleteClaim: ({ claimId }: Pick) => Promise; + getDIDsForRole: ({ namespace }: Pick) => Promise; + getDidDocument: ({ did, includeClaims }: Pick) => Promise; + addDIDToWatchList: ({ did }: Pick) => Promise; + getOwnedAssets: ({ did }: Pick) => Promise; + getOfferedAssets: ({ did }: Pick) => Promise; + getAssetById: ({ id }: Pick) => Promise; + getPreviouslyOwnedAssets: ({ owner }: Pick) => Promise; getAssetHistory: ({ id, order, take, skip, type, - }: { - id: string; - order?: Order; - take?: number; - skip?: number; - type?: AssetHistoryEventType; - }) => Promise; + }: Pick) => Promise; } diff --git a/src/cacheServerClient/cacheServerClient.ts b/src/cacheServerClient/cacheServerClient.ts index 66eb5d8a..c78ac0a5 100644 --- a/src/cacheServerClient/cacheServerClient.ts +++ b/src/cacheServerClient/cacheServerClient.ts @@ -6,14 +6,14 @@ import { IRole, Claim, Asset, - Order, - AssetHistoryEventType, AssetHistory, + ClaimsQueryParams, + RejectClaim, + IssueClaim, + RequestClaim, } from "./cacheServerClient.types"; -import { IClaimIssuance, IClaimRejection, IClaimRequest } from "../iam"; import { IDIDDocument } from "@ew-did-registry/did-resolver-interface"; - import { ICacheServerClient } from "./ICacheServerClient"; import { detectExecutionEnvironment, ExecutionEnvironment } from "../utils/detectEnvironment"; import { getPublicKeyAndIdentityToken, IPubKeyAndIdentityToken } from "../utils/getPublicKeyAndIdentityToken"; @@ -138,49 +138,49 @@ export class CacheServerClient implements ICacheServerClient { } } - async getRoleDefinition({ namespace }: { namespace: string }) { + async getRoleDefinition({ namespace }: Pick) { const { data } = await this.httpClient.get(`/role/${namespace}`); return data?.definition; } - async getOrgDefinition({ namespace }: { namespace: string }) { + async getOrgDefinition({ namespace }: Pick) { const { data } = await this.httpClient.get(`/org/${namespace}`); return data?.definition; } - async getAppDefinition({ namespace }: { namespace: string }) { + async getAppDefinition({ namespace }) { const { data } = await this.httpClient.get(`/app/${namespace}`); return data?.definition; } - async getApplicationRoles({ namespace }: { namespace: string }) { + async getApplicationRoles({ namespace }: Pick) { const { data } = await this.httpClient.get(`/app/${namespace}/roles`); return data; } - async getOrganizationRoles({ namespace }: { namespace: string }) { + async getOrganizationRoles({ namespace }: Pick) { const { data } = await this.httpClient.get(`/org/${namespace}/roles`); return data; } - async getOrganizationsByOwner({ owner, excludeSubOrgs }: { owner: string; excludeSubOrgs: boolean }) { + async getOrganizationsByOwner({ owner, excludeSubOrgs }: Pick) { const { data } = await this.httpClient.get( `/org/owner/${owner}?excludeSubOrgs=${excludeSubOrgs}`, ); return data; } - async getSubOrganizationsByOrganization({ namespace }: { namespace: string }) { + async getSubOrganizationsByOrganization({ namespace }: Pick) { const { data } = await this.httpClient.get(`/org/${namespace}/suborgs`); return data; } - async getOrgHierarchy({ namespace }: { namespace: string }) { + async getOrgHierarchy({ namespace }: Pick) { const { data } = await this.httpClient.get(`/org/${namespace}`); return data; } - async getNamespaceBySearchPhrase({ types, search }: { types?: ("App" | "Org" | "Role")[]; search: string }) { + async getNamespaceBySearchPhrase({ types, search }: Pick) { if (types && types.length > 0) { const { data } = await this.httpClient.get<(IOrganization | IApp | IRole)[]>(`/search/${search}`, { params: { @@ -196,17 +196,17 @@ export class CacheServerClient implements ICacheServerClient { return data; } - async getApplicationsByOwner({ owner }: { owner: string }) { + async getApplicationsByOwner({ owner }: Pick) { const { data } = await this.httpClient.get(`/app/owner/${owner}`); return data; } - async getApplicationsByOrganization({ namespace }: { namespace: string }) { + async getApplicationsByOrganization({ namespace }: Pick) { const { data } = await this.httpClient.get(`/org/${namespace}/apps`); return data; } - async getRolesByOwner({ owner }: { owner: string }) { + async getRolesByOwner({ owner }: Pick) { const { data } = await this.httpClient.get(`/role/owner/${owner}`); return data; } @@ -218,11 +218,15 @@ export class CacheServerClient implements ICacheServerClient { return data; } - async getClaimsByIssuer({ did, isAccepted, namespace }: { did: string; isAccepted?: boolean; namespace?: string }) { + async getClaimsByIssuer({ + did, + isAccepted, + parentNamespace, + }: Pick) { const { data } = await this.httpClient.get(`/claim/issuer/${did}`, { params: { isAccepted, - namespace, + parentNamespace, }, }); return data; @@ -231,16 +235,12 @@ export class CacheServerClient implements ICacheServerClient { async getClaimsByRequester({ did, isAccepted, - namespace, - }: { - did: string; - isAccepted?: boolean; - namespace?: string; - }) { + parentNamespace, + }: Pick) { const { data } = await this.httpClient.get(`/claim/requester/${did}`, { params: { isAccepted, - namespace, + parentNamespace, }, }); return data; @@ -249,67 +249,63 @@ export class CacheServerClient implements ICacheServerClient { async getClaimsBySubject({ did, isAccepted, - namespace, - }: { - did: string; - isAccepted?: boolean; - namespace?: string; - }) { + parentNamespace, + }: Pick) { const { data } = await this.httpClient.get(`/claim/subject/${did}`, { params: { isAccepted, - namespace, + parentNamespace, }, }); return data; } - async requestClaim({ message, did }: { message: IClaimRequest; did: string }) { + async requestClaim({ message, did }: RequestClaim) { await this.httpClient.post(`/claim/request/${did}`, message); } - async issueClaim({ message, did }: { message: IClaimIssuance; did: string }) { + async issueClaim({ message, did }: IssueClaim) { await this.httpClient.post(`/claim/issue/${did}`, message); } - async rejectClaim({ message, did }: { message: IClaimRejection; did: string }) { + async rejectClaim({ message, did }: RejectClaim) { await this.httpClient.post(`/claim/reject/${did}`, message); } - async deleteClaim({ claimId }: { claimId: string }) { + async deleteClaim({ claimId }: Pick) { await this.httpClient.delete(`/claim/${claimId}`); } - async getDIDsForRole({ namespace }: { namespace: string }) { + async getDIDsForRole({ namespace }: Pick) { const { data } = await this.httpClient.get(`/claim/did/${namespace}?accepted=true`); return data; } - async getDidDocument({ did, includeClaims }: { did: string; includeClaims?: boolean }) { + async getDidDocument({ did, includeClaims }: Pick) { const { data } = await this.httpClient.get(`/DID/${did}?includeClaims=${includeClaims || false}`); return data; } - async addDIDToWatchList({ did }: { did: string }) { + async addDIDToWatchList({ did }: Pick) { await this.httpClient.post(`/DID/${did}`); } - async getOwnedAssets({ did }: { did: string }) { + async getOwnedAssets({ did }: Pick) { const { data } = await this.httpClient.get(`/assets/owner/${did}`); return data; } - async getOfferedAssets({ did }: { did: string }) { + async getOfferedAssets({ did }: Pick) { const { data } = await this.httpClient.get(`/assets/offered_to/${did}`); return data; } - async getAssetById({ id }: { id: string }) { + async getAssetById({ id }: Pick) { const { data } = await this.httpClient.get(`/assets/${id}`); return data; } - async getPreviouslyOwnedAssets({ owner }: { owner: string }) { + async getPreviouslyOwnedAssets({ owner }: Pick) { const { data } = await this.httpClient.get(`/assets/owner/history/${owner}`); return data; } @@ -320,13 +316,7 @@ export class CacheServerClient implements ICacheServerClient { take, skip, type, - }: { - id: string; - order?: Order; - take?: number; - skip?: number; - type?: AssetHistoryEventType; - }) { + }: Pick) { const query = stringify({ order, take, skip, type }, { skipNulls: true }); const { data } = await this.httpClient.get(`/assets/history/${id}?${query}`); return data; diff --git a/src/cacheServerClient/cacheServerClient.types.ts b/src/cacheServerClient/cacheServerClient.types.ts index be5aa71d..b3d40f56 100644 --- a/src/cacheServerClient/cacheServerClient.types.ts +++ b/src/cacheServerClient/cacheServerClient.types.ts @@ -1,5 +1,6 @@ import { IDIDDocument } from "@ew-did-registry/did-resolver-interface"; import { IRoleDefinition, IAppDefinition, IOrganizationDefinition } from "@energyweb/iam-contracts"; +import { IClaimIssuance, IClaimRejection, IClaimRequest } from "../iam"; export interface IRole { uid: string; @@ -105,3 +106,24 @@ export enum AssetHistoryEventType { ASSET_TRANSFERRED = "ASSET_TRANSFERRED", ASSET_OFFER_REJECTED = "ASSET_OFFER_REJECTED", } + +export type ClaimsQueryParams = { + namespace: string; + parentNamespace?: string; + id: string; + claimId: string; + did: string; + owner: string; + excludeSubOrgs: boolean; + includeClaims?: boolean; + isAccepted?: boolean; + types?: ("App" | "Org" | "Role")[]; + type?: AssetHistoryEventType; + search: string; + order?: Order; + take?: number; + skip?: number; +}; +export type RequestClaim = Pick & { message: IClaimRequest }; +export type IssueClaim = Pick & { message: IClaimIssuance }; +export type RejectClaim = Pick & { message: IClaimRejection }; From bda32968f5f7f3018a899568c2acefebb6073429 Mon Sep 17 00:00:00 2001 From: Dmitry Fesenko Date: Thu, 30 Sep 2021 10:40:59 +0300 Subject: [PATCH 09/23] fix: create DID before loging to cache server --- src/iam.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/iam.ts b/src/iam.ts index 96333b70..3c211270 100644 --- a/src/iam.ts +++ b/src/iam.ts @@ -202,13 +202,12 @@ export class IAM extends IAMBase { initializeMetamask: reinitializeMetamask, walletProvider, }); - - if (initCacheServer) { - await this.connectToCacheServer(); - } if (createDocument) { await this.connectToDIDRegistry(); } + if (initCacheServer) { + await this.connectToCacheServer(); + } } catch (err) { if ((err as Error).message === "User closed modal") { return { From d28a928f0bbbf954ae29495db71ef1b790b6e9f2 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Thu, 30 Sep 2021 08:06:44 +0000 Subject: [PATCH 10/23] chore(release): 3.1.0-alpha.5 [skip ci] # [3.1.0-alpha.5](https://github.com/energywebfoundation/iam-client-lib/compare/v3.1.0-alpha.4...v3.1.0-alpha.5) (2021-09-30) ### Bug Fixes * create DID before loging to cache server ([bda3296](https://github.com/energywebfoundation/iam-client-lib/commit/bda32968f5f7f3018a899568c2acefebb6073429)) --- docs/CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 4e11bd11..1f504816 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,3 +1,10 @@ +# [3.1.0-alpha.5](https://github.com/energywebfoundation/iam-client-lib/compare/v3.1.0-alpha.4...v3.1.0-alpha.5) (2021-09-30) + + +### Bug Fixes + +* create DID before loging to cache server ([bda3296](https://github.com/energywebfoundation/iam-client-lib/commit/bda32968f5f7f3018a899568c2acefebb6073429)) + # [3.1.0-alpha.4](https://github.com/energywebfoundation/iam-client-lib/compare/v3.1.0-alpha.3...v3.1.0-alpha.4) (2021-09-29) From 1a49f65184aff675a74be01a67356a30393c19a6 Mon Sep 17 00:00:00 2001 From: Dmitry Fesenko Date: Thu, 30 Sep 2021 12:00:53 +0300 Subject: [PATCH 11/23] fix: revert change initialization order --- src/iam.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/iam.ts b/src/iam.ts index 3c211270..18b1ce6a 100644 --- a/src/iam.ts +++ b/src/iam.ts @@ -202,12 +202,12 @@ export class IAM extends IAMBase { initializeMetamask: reinitializeMetamask, walletProvider, }); - if (createDocument) { - await this.connectToDIDRegistry(); - } if (initCacheServer) { await this.connectToCacheServer(); } + if (createDocument) { + await this.connectToDIDRegistry(); + } } catch (err) { if ((err as Error).message === "User closed modal") { return { From d1342fa571421966d5fca8f6b0f9dc3f4d7ec57b Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Thu, 30 Sep 2021 09:15:16 +0000 Subject: [PATCH 12/23] chore(release): 3.1.0-alpha.6 [skip ci] # [3.1.0-alpha.6](https://github.com/energywebfoundation/iam-client-lib/compare/v3.1.0-alpha.5...v3.1.0-alpha.6) (2021-09-30) ### Bug Fixes * revert change initialization order ([1a49f65](https://github.com/energywebfoundation/iam-client-lib/commit/1a49f65184aff675a74be01a67356a30393c19a6)) --- docs/CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 1f504816..fd8a125f 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,3 +1,10 @@ +# [3.1.0-alpha.6](https://github.com/energywebfoundation/iam-client-lib/compare/v3.1.0-alpha.5...v3.1.0-alpha.6) (2021-09-30) + + +### Bug Fixes + +* revert change initialization order ([1a49f65](https://github.com/energywebfoundation/iam-client-lib/commit/1a49f65184aff675a74be01a67356a30393c19a6)) + # [3.1.0-alpha.5](https://github.com/energywebfoundation/iam-client-lib/compare/v3.1.0-alpha.4...v3.1.0-alpha.5) (2021-09-30) From 68ab4b776c5f204a83c2107a21cfd9ecd2498f96 Mon Sep 17 00:00:00 2001 From: Bartosz Wrobel Date: Thu, 30 Sep 2021 14:20:47 +0200 Subject: [PATCH 13/23] fix(nats): revert nats to non cjs version due to imcompatibilities --- bili.config.ts | 10 +++++- package-lock.json | 39 ++++------------------- package.json | 2 +- src/iam.ts | 2 +- src/iam/iam-base.ts | 2 +- test/claimsTests/enrollmentClaimsTests.ts | 2 +- test/testUtils/mocks.ts | 6 ++-- 7 files changed, 22 insertions(+), 41 deletions(-) diff --git a/bili.config.ts b/bili.config.ts index d61a8769..76332818 100644 --- a/bili.config.ts +++ b/bili.config.ts @@ -8,8 +8,16 @@ const config: Config = { }, }, }, + extendConfig: (config) => ({ + ...config, + // The default externals are the package.json dependencies and can only bundle node_modules that are not a dependency. + // So need to clear out all externals, to bundle nats.ws package. + externals: [], + }), + // nats.ws is bundled because using standard import/require does not work for cjs format. + // nat.ws only provides a .mjs file which cannot be required. // include tslib for clients using older version of tslib - bundleNodeModules: ["tslib"], + bundleNodeModules: ["nats.ws", "tslib"], input: "src/iam-client-lib.ts", output: { format: ["cjs", "esm"], diff --git a/package-lock.json b/package-lock.json index 967fd4a1..3bd401db 100644 --- a/package-lock.json +++ b/package-lock.json @@ -15745,12 +15745,9 @@ } }, "nats.ws": { - "version": "1.3.0", - "resolved": "https://registry.npmjs.org/nats.ws/-/nats.ws-1.3.0.tgz", - "integrity": "sha512-BIeWvvRca/Qnh7PJzOBBOjcFbgmKBuTfTifxpkGAKQlSEX/AgM/CS957TrTEgb12UzcCIS4IhXwbTNK1K0PMGw==", - "requires": { - "nkeys.js": "^1.0.0-9" - } + "version": "1.0.0-111", + "resolved": "https://registry.npmjs.org/nats.ws/-/nats.ws-1.0.0-111.tgz", + "integrity": "sha512-kR5mc7I/bvSJy38F8gbSYmllOAoM83xEBNlSFhTn0fJb7+fUtrrEk9OYZF+zrlFnQf3nc34dHQRuThCrVLEU5w==" }, "natural-compare": { "version": "1.4.0", @@ -15808,30 +15805,6 @@ "integrity": "sha512-1nh45deeb5olNY7eX82BkPO7SSxR5SSYJiPTrTdFUVYwAl8CKMA5N9PjTYkHiRjisVcxcQ1HXdLhx2qxxJzLNQ==", "dev": true }, - "nkeys.js": { - "version": "1.0.0-9", - "resolved": "https://registry.npmjs.org/nkeys.js/-/nkeys.js-1.0.0-9.tgz", - "integrity": "sha512-m9O0NQT+3rUe1om6MWpxV77EuHql/LdorDH+FYQkoeARcM2V0sQ89kM36fArWaHWq/25EmNmQUW0MhLTcbqW1A==", - "optional": true, - "requires": { - "@types/node": "^14.0.26", - "tweetnacl": "^1.0.3" - }, - "dependencies": { - "@types/node": { - "version": "14.17.17", - "resolved": "https://registry.npmjs.org/@types/node/-/node-14.17.17.tgz", - "integrity": "sha512-niAjcewgEYvSPCZm3OaM9y6YQrL2SEPH9PymtE6fuZAvFiP6ereCcvApGl2jKTq7copTIguX3PBvfP08LN4LvQ==", - "optional": true - }, - "tweetnacl": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz", - "integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==", - "optional": true - } - } - }, "node-addon-api": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-2.0.2.tgz", @@ -16305,7 +16278,7 @@ }, "abbrev": { "version": "1.1.1", - "resolved": false, + "resolved": "", "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==", "dev": true }, @@ -16368,7 +16341,7 @@ }, "ansicolors": { "version": "0.3.2", - "resolved": false, + "resolved": "", "integrity": "sha1-ZlWX3oap/+Oqm/vmyuXG6kJrSXk=", "dev": true }, @@ -18206,7 +18179,7 @@ }, "text-table": { "version": "0.2.0", - "resolved": false, + "resolved": "", "integrity": "sha1-f17oI66AUgfACvLfSoTsP8+lcLQ=", "dev": true }, diff --git a/package.json b/package.json index 5222f811..f954c746 100644 --- a/package.json +++ b/package.json @@ -77,7 +77,7 @@ "ethers": "^5.4.4", "js-sha3": "^0.8.0", "lodash.difference": "^4.5.0", - "nats.ws": "^1.3.0", + "nats.ws": "^1.0.0-111", "qs": "^6.9.4", "tslib": "^2.0.3", "uuid": "^7.0.3" diff --git a/src/iam.ts b/src/iam.ts index 18b1ce6a..aa35b60b 100644 --- a/src/iam.ts +++ b/src/iam.ts @@ -63,7 +63,7 @@ import { proof_type_hash, typedMsgPrefix, } from "./utils/constants"; -import { Subscription } from "nats.ws/lib/src/mod.js"; +import { Subscription } from "nats.ws"; import { AxiosError } from "axios"; import { DIDDocumentFull } from "@ew-did-registry/did-document"; import { Methods } from "@ew-did-registry/did"; diff --git a/src/iam/iam-base.ts b/src/iam/iam-base.ts index a7b0b002..538c9fa8 100644 --- a/src/iam/iam-base.ts +++ b/src/iam/iam-base.ts @@ -25,7 +25,7 @@ import { ClaimManager } from "../../ethers/ClaimManager"; import { JWT } from "@ew-did-registry/jwt"; import { ICacheServerClient } from "../cacheServerClient/ICacheServerClient"; import { detectExecutionEnvironment, ExecutionEnvironment } from "../utils/detectEnvironment"; -import { connect, NatsConnection, Codec, JSONCodec } from "nats.ws/lib/src/mod.js"; +import { connect, NatsConnection, Codec, JSONCodec } from "nats.ws"; import { ERROR_MESSAGES } from "../errors"; import { ClaimData } from "../cacheServerClient/cacheServerClient.types"; import difference from "lodash.difference"; diff --git a/test/claimsTests/enrollmentClaimsTests.ts b/test/claimsTests/enrollmentClaimsTests.ts index 30d429cb..f1420548 100644 --- a/test/claimsTests/enrollmentClaimsTests.ts +++ b/test/claimsTests/enrollmentClaimsTests.ts @@ -2,7 +2,7 @@ import { PreconditionType } from "@energyweb/iam-contracts"; import { Methods } from "@ew-did-registry/did"; import { addressOf } from "@ew-did-registry/did-ethr-resolver"; import { Wallet, utils } from "ethers"; -import { Codec } from "nats.ws/lib/src/mod.js"; +import { Codec } from "nats.ws"; import { IAM, RegistrationTypes, IRoleDefinition, NATS_EXCHANGE_TOPIC } from "../../src/iam-client-lib"; import { createIam, root, rootOwner } from "../iam.test"; import { claimManager, replenish } from "../setup_contracts"; diff --git a/test/testUtils/mocks.ts b/test/testUtils/mocks.ts index 67b7346f..a8a580d1 100644 --- a/test/testUtils/mocks.ts +++ b/test/testUtils/mocks.ts @@ -1,5 +1,5 @@ import { IRoleDefinition } from "@energyweb/iam-contracts"; -import { JSONCodec } from "nats.ws/lib/src/mod.js"; +import { JSONCodec } from "nats.ws"; import { Claim } from "../../src/cacheServerClient/cacheServerClient.types"; import { IAM } from "../../src/iam"; @@ -48,9 +48,9 @@ export const restoreCacheClient = () => { }; let _jsonCodec; -export const mockJsonCodec = () => { +export const mockJsonCodec = () => { ({ _jsonCodec } = Reflect.get(IAM, "prototype")); - const jsonCodec = JSONCodec(); + const jsonCodec = JSONCodec(); Reflect.set(IAM.prototype, "_jsonCodec", jsonCodec); return jsonCodec; }; From 4543efb28c67155ac040aafa4c0491f8f1421f48 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Thu, 30 Sep 2021 13:03:11 +0000 Subject: [PATCH 14/23] chore(release): 3.1.0-alpha.7 [skip ci] # [3.1.0-alpha.7](https://github.com/energywebfoundation/iam-client-lib/compare/v3.1.0-alpha.6...v3.1.0-alpha.7) (2021-09-30) ### Bug Fixes * **nats:** revert nats to non cjs version due to imcompatibilities ([68ab4b7](https://github.com/energywebfoundation/iam-client-lib/commit/68ab4b776c5f204a83c2107a21cfd9ecd2498f96)) --- docs/CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index fd8a125f..cfb533f7 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,3 +1,10 @@ +# [3.1.0-alpha.7](https://github.com/energywebfoundation/iam-client-lib/compare/v3.1.0-alpha.6...v3.1.0-alpha.7) (2021-09-30) + + +### Bug Fixes + +* **nats:** revert nats to non cjs version due to imcompatibilities ([68ab4b7](https://github.com/energywebfoundation/iam-client-lib/commit/68ab4b776c5f204a83c2107a21cfd9ecd2498f96)) + # [3.1.0-alpha.6](https://github.com/energywebfoundation/iam-client-lib/compare/v3.1.0-alpha.5...v3.1.0-alpha.6) (2021-09-30) From 18b1b4ce4752fc39466ba9fa5c37c428dd277987 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Fri, 1 Oct 2021 06:36:39 +0000 Subject: [PATCH 15/23] chore(release): 3.1.0-alpha.8 [skip ci] # [3.1.0-alpha.8](https://github.com/energywebfoundation/iam-client-lib/compare/v3.1.0-alpha.7...v3.1.0-alpha.8) (2021-10-01) ### Bug Fixes * **core:** update cache server interface to latest version and secure types ([7752b45](https://github.com/energywebfoundation/iam-client-lib/commit/7752b451f63a813ce1a574d1fb8e16f54eadcb5b)) --- docs/CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index cfb533f7..f14ffbb3 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,3 +1,10 @@ +# [3.1.0-alpha.8](https://github.com/energywebfoundation/iam-client-lib/compare/v3.1.0-alpha.7...v3.1.0-alpha.8) (2021-10-01) + + +### Bug Fixes + +* **core:** update cache server interface to latest version and secure types ([7752b45](https://github.com/energywebfoundation/iam-client-lib/commit/7752b451f63a813ce1a574d1fb8e16f54eadcb5b)) + # [3.1.0-alpha.7](https://github.com/energywebfoundation/iam-client-lib/compare/v3.1.0-alpha.6...v3.1.0-alpha.7) (2021-09-30) From 716f8272c683ad214d640c3fceb6023905c8ee8c Mon Sep 17 00:00:00 2001 From: Dmitry Fesenko Date: Fri, 1 Oct 2021 12:19:06 +0300 Subject: [PATCH 16/23] docs: setup --- docs/setup.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 docs/setup.md diff --git a/docs/setup.md b/docs/setup.md new file mode 100644 index 00000000..94fe9d91 --- /dev/null +++ b/docs/setup.md @@ -0,0 +1,17 @@ + +# setting up and testing project locally + +to use/debug iam-client-lib locally you should + +1. clone the repo to your local machine +2. run `npm link` on root directory after `npm i` +3. then in repo you are going to use the package(i.e. switchboard-dapp), in root directory run `npm link iam-client-lib` + +after this steps when `npm run build` command will be executed the iam-client-lib will automatically be updated on switchboard-dapp. + +# supported environment + +for unix and windows environments lib is executing `npm i` and `npm run build` without problems + +but `npm run test:watch` throws error with message `cannot find ganache-cli` on `windows` environment. on linux ones its workng fine. +doing `npm i -g ganache-cli` does not help here. this needs further investigation. \ No newline at end of file From 30c74f472cbfb60ec5e9eef11fa519d9ff0b3fd5 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Fri, 1 Oct 2021 09:54:08 +0000 Subject: [PATCH 17/23] chore(release): 3.1.0-alpha.9 [skip ci] # [3.1.0-alpha.9](https://github.com/energywebfoundation/iam-client-lib/compare/v3.1.0-alpha.8...v3.1.0-alpha.9) (2021-10-01) --- docs/CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index f14ffbb3..66cd582a 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,3 +1,5 @@ +# [3.1.0-alpha.9](https://github.com/energywebfoundation/iam-client-lib/compare/v3.1.0-alpha.8...v3.1.0-alpha.9) (2021-10-01) + # [3.1.0-alpha.8](https://github.com/energywebfoundation/iam-client-lib/compare/v3.1.0-alpha.7...v3.1.0-alpha.8) (2021-10-01) From 4d11e58f2731fa8201e8b3d5e09985c2a4972b7e Mon Sep 17 00:00:00 2001 From: dawidgil Date: Fri, 1 Oct 2021 14:53:02 +0200 Subject: [PATCH 18/23] fix: detecting execution environment, when browser have declared global property. --- docs/api/modules/utils_detectEnvironment.md | 4 ++-- src/utils/detectEnvironment.ts | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/docs/api/modules/utils_detectEnvironment.md b/docs/api/modules/utils_detectEnvironment.md index 7a224dd3..3a77a7fb 100644 --- a/docs/api/modules/utils_detectEnvironment.md +++ b/docs/api/modules/utils_detectEnvironment.md @@ -14,8 +14,8 @@ ### detectExecutionEnvironment -▸ `Const` **detectExecutionEnvironment**(): `any` +▸ `Const` **detectExecutionEnvironment**(): `ExecutionEnvironment` #### Returns -`any` +`ExecutionEnvironment` diff --git a/src/utils/detectEnvironment.ts b/src/utils/detectEnvironment.ts index ce24b436..9053be28 100644 --- a/src/utils/detectEnvironment.ts +++ b/src/utils/detectEnvironment.ts @@ -4,8 +4,8 @@ export enum ExecutionEnvironment { } export const detectExecutionEnvironment = () => - (isNode() && ExecutionEnvironment.NODE) || (isBrowser() && ExecutionEnvironment.BROWSER); + isNode() && !isBrowser() ? ExecutionEnvironment.NODE : ExecutionEnvironment.BROWSER; -const isNode = new Function("try { return this === global } catch(e) { return false; }"); +const isNode = () => typeof process !== "undefined" && process.versions != null && process.versions.node != null; -const isBrowser = new Function("try { return this === window } catch(e) { return false; }"); +const isBrowser = () => typeof window !== "undefined" && typeof window.document !== "undefined"; From 65e579adfc16b40e263d08fd7ac820a65c09fc1e Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Mon, 4 Oct 2021 08:32:30 +0000 Subject: [PATCH 19/23] chore(release): 3.1.0-alpha.10 [skip ci] # [3.1.0-alpha.10](https://github.com/energywebfoundation/iam-client-lib/compare/v3.1.0-alpha.9...v3.1.0-alpha.10) (2021-10-04) ### Bug Fixes * detecting execution environment, when browser have declared global property. ([4d11e58](https://github.com/energywebfoundation/iam-client-lib/commit/4d11e58f2731fa8201e8b3d5e09985c2a4972b7e)) --- docs/CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 66cd582a..e3dc3efb 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,3 +1,10 @@ +# [3.1.0-alpha.10](https://github.com/energywebfoundation/iam-client-lib/compare/v3.1.0-alpha.9...v3.1.0-alpha.10) (2021-10-04) + + +### Bug Fixes + +* detecting execution environment, when browser have declared global property. ([4d11e58](https://github.com/energywebfoundation/iam-client-lib/commit/4d11e58f2731fa8201e8b3d5e09985c2a4972b7e)) + # [3.1.0-alpha.9](https://github.com/energywebfoundation/iam-client-lib/compare/v3.1.0-alpha.8...v3.1.0-alpha.9) (2021-10-01) # [3.1.0-alpha.8](https://github.com/energywebfoundation/iam-client-lib/compare/v3.1.0-alpha.7...v3.1.0-alpha.8) (2021-10-01) From cdb3d206aa062ba965d6dc37ad43f8c86ea3a6ab Mon Sep 17 00:00:00 2001 From: dawidgil Date: Fri, 1 Oct 2021 16:50:58 +0200 Subject: [PATCH 20/23] fix(auth): using private key in browser to login. --- docs/api/classes/GnosisIam.GnosisIam-1.md | 4 +- docs/api/classes/iam.IAM.md | 4 +- .../types_WalletProvider.WalletProvider.md | 7 ++++ src/iam/iam-base.ts | 39 +++++++++++++------ src/types/WalletProvider.ts | 1 + test/initializeConnection.testSuite.ts | 4 +- 6 files changed, 42 insertions(+), 17 deletions(-) diff --git a/docs/api/classes/GnosisIam.GnosisIam-1.md b/docs/api/classes/GnosisIam.GnosisIam-1.md index 42f0a595..ef306b5a 100644 --- a/docs/api/classes/GnosisIam.GnosisIam-1.md +++ b/docs/api/classes/GnosisIam.GnosisIam-1.md @@ -1041,13 +1041,13 @@ ___ ### getProviderType -▸ **getProviderType**(): `undefined` \| [`WalletProvider`](../enums/types_WalletProvider.WalletProvider.md) +▸ **getProviderType**(): [`WalletProvider`](../enums/types_WalletProvider.WalletProvider.md) Get the current initialized provider type #### Returns -`undefined` \| [`WalletProvider`](../enums/types_WalletProvider.WalletProvider.md) +[`WalletProvider`](../enums/types_WalletProvider.WalletProvider.md) provider type if the session is active if not undefined diff --git a/docs/api/classes/iam.IAM.md b/docs/api/classes/iam.IAM.md index 495d71f6..8160c819 100644 --- a/docs/api/classes/iam.IAM.md +++ b/docs/api/classes/iam.IAM.md @@ -893,13 +893,13 @@ ___ ### getProviderType -▸ **getProviderType**(): `undefined` \| [`WalletProvider`](../enums/types_WalletProvider.WalletProvider.md) +▸ **getProviderType**(): [`WalletProvider`](../enums/types_WalletProvider.WalletProvider.md) Get the current initialized provider type #### Returns -`undefined` \| [`WalletProvider`](../enums/types_WalletProvider.WalletProvider.md) +[`WalletProvider`](../enums/types_WalletProvider.WalletProvider.md) provider type if the session is active if not undefined diff --git a/docs/api/enums/types_WalletProvider.WalletProvider.md b/docs/api/enums/types_WalletProvider.WalletProvider.md index 1a62deaa..ed3f669c 100644 --- a/docs/api/enums/types_WalletProvider.WalletProvider.md +++ b/docs/api/enums/types_WalletProvider.WalletProvider.md @@ -8,6 +8,7 @@ - [EwKeyManager](types_WalletProvider.WalletProvider.md#ewkeymanager) - [MetaMask](types_WalletProvider.WalletProvider.md#metamask) +- [PrivateKey](types_WalletProvider.WalletProvider.md#privatekey) - [WalletConnect](types_WalletProvider.WalletProvider.md#walletconnect) ## Enumeration members @@ -24,6 +25,12 @@ ___ ___ +### PrivateKey + +• **PrivateKey** = `"PrivateKey"` + +___ + ### WalletConnect • **WalletConnect** = `"WalletConnect"` diff --git a/src/iam/iam-base.ts b/src/iam/iam-base.ts index 538c9fa8..c29b9e32 100644 --- a/src/iam/iam-base.ts +++ b/src/iam/iam-base.ts @@ -82,7 +82,7 @@ export class IAMBase { protected _didSigner: EwSigner | undefined; protected _identityToken: string | undefined; protected _transactionOverrides: utils.Deferrable = {}; - protected _providerType: WalletProvider | undefined; + protected _providerType: WalletProvider; protected _publicKey: string | undefined | null; protected _registrySetting: RegistrySettings; @@ -144,6 +144,10 @@ export class IAMBase { this._publicKey = localStorage.getItem(PUBLIC_KEY); } + if (this._executionEnvironment === ExecutionEnvironment.NODE) { + this._providerType = WalletProvider.PrivateKey; + } + this._walletConnectService = new WalletConnectService(bridgeUrl, infuraId, ewKeyManagerUrl); } @@ -180,15 +184,10 @@ export class IAMBase { walletProvider?: WalletProvider; }): Promise { const { privateKey, rpcUrl } = this._connectionOptions; - if (this._executionEnvironment === ExecutionEnvironment.NODE) { - if (!privateKey) { - throw new Error(ERROR_MESSAGES.PRIVATE_KEY_NOT_PROVIDED); - } - if (!rpcUrl) { - throw new Error(ERROR_MESSAGES.RPC_URL_NOT_PROVIDED); - } - this._provider = new JsonRpcProvider({ url: rpcUrl }); - this._signer = new Wallet(privateKey, this._provider); + + if (walletProvider === WalletProvider.PrivateKey) { + this.initWithPrivateKey(privateKey, rpcUrl); + this._providerType = walletProvider; return; } @@ -248,6 +247,17 @@ export class IAMBase { throw new Error(ERROR_MESSAGES.WALLET_TYPE_NOT_PROVIDED); } + private initWithPrivateKey(privateKey, rpcUrl) { + if (!privateKey) { + throw new Error(ERROR_MESSAGES.PRIVATE_KEY_NOT_PROVIDED); + } + if (!rpcUrl) { + throw new Error(ERROR_MESSAGES.RPC_URL_NOT_PROVIDED); + } + this._provider = new JsonRpcProvider({ url: rpcUrl }); + this._signer = new Wallet(privateKey, this._provider); + } + /** * @description Establishes connection to the cache serverand sets public key and identity token */ @@ -320,7 +330,14 @@ export class IAMBase { * @requires to be called after the connection to wallet was initialized */ on(event: "accountChanged" | "networkChanged" | "disconnected", eventHandler: () => void) { - if (!this._providerType) return; + const providersThatHandleEvents = [ + WalletProvider.WalletConnect, + WalletProvider.EwKeyManager, + WalletProvider.MetaMask, + ]; + if (!providersThatHandleEvents.includes(this._providerType)) { + return; + } const isMetamask = this._providerType === WalletProvider.MetaMask; switch (event) { case "accountChanged": { diff --git a/src/types/WalletProvider.ts b/src/types/WalletProvider.ts index e23dc491..09383a8a 100644 --- a/src/types/WalletProvider.ts +++ b/src/types/WalletProvider.ts @@ -2,4 +2,5 @@ export enum WalletProvider { WalletConnect = "WalletConnect", MetaMask = "MetaMask", EwKeyManager = "EwKeyManager", + PrivateKey = "PrivateKey", } diff --git a/test/initializeConnection.testSuite.ts b/test/initializeConnection.testSuite.ts index 7dc43cf0..8713d97f 100644 --- a/test/initializeConnection.testSuite.ts +++ b/test/initializeConnection.testSuite.ts @@ -6,8 +6,8 @@ import { WalletProvider } from "../src/types/WalletProvider"; const iam_withoutKey = new IAM({ rpcUrl }); export const initializeConnectionTests = () => { - test("initializeConnection requires privateKey or walletProvider enum", async () => { - await expect(iam_withoutKey.initializeConnection()).rejects.toThrow(ERROR_MESSAGES.WALLET_TYPE_NOT_PROVIDED); + test("initializeConnection requires privateKey", async () => { + await expect(iam_withoutKey.initializeConnection()).rejects.toThrow(ERROR_MESSAGES.PRIVATE_KEY_NOT_PROVIDED); }); test("initializeConnection requires walletProvider to be known value", async () => { From 4db2bb7b6548753280ed07962fb00ca6f21bc3a4 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Mon, 4 Oct 2021 13:47:18 +0000 Subject: [PATCH 21/23] chore(release): 3.1.0-alpha.11 [skip ci] # [3.1.0-alpha.11](https://github.com/energywebfoundation/iam-client-lib/compare/v3.1.0-alpha.10...v3.1.0-alpha.11) (2021-10-04) ### Bug Fixes * **auth:** using private key in browser to login. ([cdb3d20](https://github.com/energywebfoundation/iam-client-lib/commit/cdb3d206aa062ba965d6dc37ad43f8c86ea3a6ab)) --- docs/CHANGELOG.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index e3dc3efb..0dff5716 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,3 +1,10 @@ +# [3.1.0-alpha.11](https://github.com/energywebfoundation/iam-client-lib/compare/v3.1.0-alpha.10...v3.1.0-alpha.11) (2021-10-04) + + +### Bug Fixes + +* **auth:** using private key in browser to login. ([cdb3d20](https://github.com/energywebfoundation/iam-client-lib/commit/cdb3d206aa062ba965d6dc37ad43f8c86ea3a6ab)) + # [3.1.0-alpha.10](https://github.com/energywebfoundation/iam-client-lib/compare/v3.1.0-alpha.9...v3.1.0-alpha.10) (2021-10-04) From ac05bc9d13afd47df150332ba51ddf0a30fef456 Mon Sep 17 00:00:00 2001 From: Passerino Date: Tue, 5 Oct 2021 12:14:29 +0200 Subject: [PATCH 22/23] fix(doc): package.json with correct version - semantic release packages order change - npm before git - add package.json to git assets --- .releaserc.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.releaserc.json b/.releaserc.json index dfa12ec3..1e6c9db0 100644 --- a/.releaserc.json +++ b/.releaserc.json @@ -44,12 +44,12 @@ "changelogFile": "docs/CHANGELOG.md" } ], + "@semantic-release/npm", [ "@semantic-release/git", { - "assets": ["docs/CHANGELOG.md"] + "assets": ["package.json", "docs/CHANGELOG.md"] } - ], - "@semantic-release/npm" + ] ] } From 00da27798477a9813c380d17a1b4a1144bfed935 Mon Sep 17 00:00:00 2001 From: semantic-release-bot Date: Wed, 6 Oct 2021 07:45:36 +0000 Subject: [PATCH 23/23] chore(release): 3.1.0-alpha.12 [skip ci] # [3.1.0-alpha.12](https://github.com/energywebfoundation/iam-client-lib/compare/v3.1.0-alpha.11...v3.1.0-alpha.12) (2021-10-06) ### Bug Fixes * **doc:** package.json with correct version ([ac05bc9](https://github.com/energywebfoundation/iam-client-lib/commit/ac05bc9d13afd47df150332ba51ddf0a30fef456)) --- docs/CHANGELOG.md | 7 +++++++ package.json | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 0dff5716..414a559f 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -1,3 +1,10 @@ +# [3.1.0-alpha.12](https://github.com/energywebfoundation/iam-client-lib/compare/v3.1.0-alpha.11...v3.1.0-alpha.12) (2021-10-06) + + +### Bug Fixes + +* **doc:** package.json with correct version ([ac05bc9](https://github.com/energywebfoundation/iam-client-lib/commit/ac05bc9d13afd47df150332ba51ddf0a30fef456)) + # [3.1.0-alpha.11](https://github.com/energywebfoundation/iam-client-lib/compare/v3.1.0-alpha.10...v3.1.0-alpha.11) (2021-10-04) diff --git a/package.json b/package.json index f954c746..6c9ea96d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "iam-client-lib", - "version": "1.0.6", + "version": "3.1.0-alpha.12", "description": "Library for Decentralized Identity and Access Management", "main": "dist/iam-client-lib.js", "module": "dist/iam-client-lib.esm.js",