From 3f74a4a57a5c64ef3ff31d7eb0433d338f629110 Mon Sep 17 00:00:00 2001 From: volodymyr-basiuk <31999965+volodymyr-basiuk@users.noreply.github.com> Date: Tue, 20 Aug 2024 12:02:30 +0300 Subject: [PATCH] fix: getStateContractAndProviderForId - throw error if no config for chainId found (#256) * fix: getStateContractAndProviderForId - throw error if no config for chainId found * provide chainId in config --- package-lock.json | 4 ++-- package.json | 2 +- src/storage/blockchain/state.ts | 20 +++++--------------- tests/handlers/auth.test.ts | 1 + 4 files changed, 9 insertions(+), 18 deletions(-) diff --git a/package-lock.json b/package-lock.json index fdccd751..d0662365 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@0xpolygonid/js-sdk", - "version": "1.17.3", + "version": "1.17.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@0xpolygonid/js-sdk", - "version": "1.17.3", + "version": "1.17.4", "license": "MIT or Apache-2.0", "dependencies": { "@noble/curves": "^1.4.0", diff --git a/package.json b/package.json index ee278413..f4df2aee 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@0xpolygonid/js-sdk", - "version": "1.17.3", + "version": "1.17.4", "description": "SDK to work with Polygon ID", "main": "dist/node/cjs/index.js", "module": "dist/node/esm/index.js", diff --git a/src/storage/blockchain/state.ts b/src/storage/blockchain/state.ts index 60a52eda..bd4a2a57 100644 --- a/src/storage/blockchain/state.ts +++ b/src/storage/blockchain/state.ts @@ -240,13 +240,6 @@ export class EthStateStorage implements IStateStorage { provider: JsonRpcProvider; } { const idTyped = Id.fromBigInt(id as bigint); - if (!Array.isArray(this.ethConfig)) { - return { - stateContract: this.stateContract, - provider: this.provider - }; - } - const chainId = getChainId(DID.blockchainFromId(idTyped), DID.networkIdFromId(idTyped)); const config = this.networkByChainId(chainId); @@ -257,14 +250,11 @@ export class EthStateStorage implements IStateStorage { } private networkByChainId(chainId: number): EthConnectionConfig { - if (Array.isArray(this.ethConfig)) { - const network = this.ethConfig.find((c) => c.chainId === chainId); - if (!network) { - throw new Error(`chainId "${chainId}" not supported`); - } - return network; + const config = Array.isArray(this.ethConfig) ? this.ethConfig : [this.ethConfig]; + const network = config.find((c) => c.chainId === chainId); + if (!network) { + throw new Error(`chainId "${chainId}" not supported`); } - - return this.ethConfig as EthConnectionConfig; + return network; } } diff --git a/tests/handlers/auth.test.ts b/tests/handlers/auth.test.ts index ba50c918..47122508 100644 --- a/tests/handlers/auth.test.ts +++ b/tests/handlers/auth.test.ts @@ -1556,6 +1556,7 @@ describe('auth', () => { const stateEthConfig = defaultEthConnectionConfig; stateEthConfig.url = RPC_URL; stateEthConfig.contractAddress = STATE_CONTRACT; + stateEthConfig.chainId = 80002; const eth = new EthStateStorage(stateEthConfig); const kms = registerKeyProvidersInMemoryKMS();