From 11dee91e0698a739786d698735e4098d9da0d4e4 Mon Sep 17 00:00:00 2001 From: vignesha22 <82584664+vignesha22@users.noreply.github.com> Date: Tue, 9 Jan 2024 14:50:29 +0530 Subject: [PATCH] PRO-1958 - Fix_Guardian_Flow (#91) --- CHANGELOG.md | 4 + package-lock.json | 282 ++++------------------------- package.json | 12 +- src/sdk/base/EtherspotWalletAPI.ts | 16 ++ src/sdk/interfaces.ts | 1 + src/sdk/sdk.ts | 2 + 6 files changed, 66 insertions(+), 251 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b983c06..fea4f48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,8 @@ # Changelog +## [1.4.1] - 2023-12-27 +### Bug Fixes +- Added an optional parameter called accountAddress in SDKOptions to specify the contract address they wish to connect and added checks to verify that. This one is for users who changed the owner of the contract address + ## [1.4.0] ### Breaking Changes - Changed the data service to initialise as a seperate entity independent of the primeSdk object diff --git a/package-lock.json b/package-lock.json index 7b646fa..eb85440 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,16 +1,16 @@ { "name": "@etherspot/prime-sdk", - "version": "1.4.0", + "version": "1.4.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@etherspot/prime-sdk", - "version": "1.4.0", + "version": "1.4.1", "license": "MIT", "dependencies": { - "@apollo/client": "3.8.6", - "@lifi/sdk": "2.2.3", + "@apollo/client": "3.8.7", + "@lifi/sdk": "2.5.0", "@thehubbleproject/bls": "0.5.1", "@walletconnect/universal-provider": "2.10.0", "apollo-link-ws": "1.0.20", @@ -18,11 +18,11 @@ "class-transformer": "0.5.1", "class-validator": "0.14.0", "commander": "10.0.1", - "cross-fetch": "3.1.5", - "ethers": "5.7.0", + "cross-fetch": "3.1.8", + "ethers": "5.7.2", "graphql-ws": "5.14.2", "prettier": "2.8.8", - "reflect-metadata": "0.1.13", + "reflect-metadata": "0.1.14", "rxjs": "6.6.7" }, "devDependencies": { @@ -41,9 +41,9 @@ } }, "node_modules/@apollo/client": { - "version": "3.8.6", - "resolved": "https://registry.npmjs.org/@apollo/client/-/client-3.8.6.tgz", - "integrity": "sha512-FnHg3vhQP8tQzgBs6oTJCFFIbovelDGYujj6MK7CJneiHf62TJstCIO0Ot4A1h7XrgFEtgl8a/OgajQWqrTuYw==", + "version": "3.8.7", + "resolved": "https://registry.npmjs.org/@apollo/client/-/client-3.8.7.tgz", + "integrity": "sha512-DnQtFkQrCyxHTSa9gR84YRLmU/al6HeXcLZazVe+VxKBmx/Hj4rV8xWtzfWYX5ijartsqDR7SJgV037MATEecA==", "dependencies": { "@graphql-typed-document-node/core": "^3.1.1", "@wry/context": "^0.7.3", @@ -522,9 +522,9 @@ } }, "node_modules/@ethersproject/providers": { - "version": "5.7.0", - "resolved": "https://registry.npmjs.org/@ethersproject/providers/-/providers-5.7.0.tgz", - "integrity": "sha512-+TTrrINMzZ0aXtlwO/95uhAggKm4USLm1PbeCBR/3XZ7+Oey+3pMyddzZEyRhizHpy1HXV0FRWRMI1O3EGYibA==", + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/@ethersproject/providers/-/providers-5.7.2.tgz", + "integrity": "sha512-g34EWZ1WWAVgr4aptGlVBF8mhl3VWjv+8hoAnzStu8Ah22VHBsuGzP17eb6xDVRzw895G4W7vvx60lFFur/1Rg==", "funding": [ { "type": "individual", @@ -838,194 +838,26 @@ } }, "node_modules/@lifi/sdk": { - "version": "2.2.3", - "resolved": "https://registry.npmjs.org/@lifi/sdk/-/sdk-2.2.3.tgz", - "integrity": "sha512-k5KFK5SRRqA1hGrQkkWPPhM0AYciAFyu6GLCJdDFUK6HM+No4qDQWT359K9mGU6FrXVhPMds58Imex/lj/XReQ==", + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/@lifi/sdk/-/sdk-2.5.0.tgz", + "integrity": "sha512-wx/3Ff0DAfYyV8VSWSQ/Qiy3DlwdrIfG841hbwqJK3AGxK0ulunLl1rKpMQrRdEEwkqAFNKZuJ8by0lGf9YccQ==", "dependencies": { "@ethersproject/abi": "^5.7.0", "@ethersproject/contracts": "^5.7.0", - "@lifi/types": "^8.0.4", - "bignumber.js": "^9.1.1", + "@lifi/types": "^9.3.0", + "bignumber.js": "^9.1.2", "eth-rpc-errors": "^4.0.3", "ethers": "^5.7.2" } }, - "node_modules/@lifi/sdk/node_modules/@ethersproject/providers": { - "version": "5.7.2", - "resolved": "https://registry.npmjs.org/@ethersproject/providers/-/providers-5.7.2.tgz", - "integrity": "sha512-g34EWZ1WWAVgr4aptGlVBF8mhl3VWjv+8hoAnzStu8Ah22VHBsuGzP17eb6xDVRzw895G4W7vvx60lFFur/1Rg==", - "funding": [ - { - "type": "individual", - "url": "https://gitcoin.co/grants/13/ethersjs-complete-simple-and-tiny-2" - }, - { - "type": "individual", - "url": "https://www.buymeacoffee.com/ricmoo" - } - ], - "dependencies": { - "@ethersproject/abstract-provider": "^5.7.0", - "@ethersproject/abstract-signer": "^5.7.0", - "@ethersproject/address": "^5.7.0", - "@ethersproject/base64": "^5.7.0", - "@ethersproject/basex": "^5.7.0", - "@ethersproject/bignumber": "^5.7.0", - "@ethersproject/bytes": "^5.7.0", - "@ethersproject/constants": "^5.7.0", - "@ethersproject/hash": "^5.7.0", - "@ethersproject/logger": "^5.7.0", - "@ethersproject/networks": "^5.7.0", - "@ethersproject/properties": "^5.7.0", - "@ethersproject/random": "^5.7.0", - "@ethersproject/rlp": "^5.7.0", - "@ethersproject/sha2": "^5.7.0", - "@ethersproject/strings": "^5.7.0", - "@ethersproject/transactions": "^5.7.0", - "@ethersproject/web": "^5.7.0", - "bech32": "1.1.4", - "ws": "7.4.6" - } - }, - "node_modules/@lifi/sdk/node_modules/ethers": { - "version": "5.7.2", - "resolved": "https://registry.npmjs.org/ethers/-/ethers-5.7.2.tgz", - "integrity": "sha512-wswUsmWo1aOK8rR7DIKiWSw9DbLWe6x98Jrn8wcTflTVvaXhAMaB5zGAXy0GYQEQp9iO1iSHWVyARQm11zUtyg==", - "funding": [ - { - "type": "individual", - "url": "https://gitcoin.co/grants/13/ethersjs-complete-simple-and-tiny-2" - }, - { - "type": "individual", - "url": "https://www.buymeacoffee.com/ricmoo" - } - ], - "dependencies": { - "@ethersproject/abi": "5.7.0", - "@ethersproject/abstract-provider": "5.7.0", - "@ethersproject/abstract-signer": "5.7.0", - "@ethersproject/address": "5.7.0", - "@ethersproject/base64": "5.7.0", - "@ethersproject/basex": "5.7.0", - "@ethersproject/bignumber": "5.7.0", - "@ethersproject/bytes": "5.7.0", - "@ethersproject/constants": "5.7.0", - "@ethersproject/contracts": "5.7.0", - "@ethersproject/hash": "5.7.0", - "@ethersproject/hdnode": "5.7.0", - "@ethersproject/json-wallets": "5.7.0", - "@ethersproject/keccak256": "5.7.0", - "@ethersproject/logger": "5.7.0", - "@ethersproject/networks": "5.7.1", - "@ethersproject/pbkdf2": "5.7.0", - "@ethersproject/properties": "5.7.0", - "@ethersproject/providers": "5.7.2", - "@ethersproject/random": "5.7.0", - "@ethersproject/rlp": "5.7.0", - "@ethersproject/sha2": "5.7.0", - "@ethersproject/signing-key": "5.7.0", - "@ethersproject/solidity": "5.7.0", - "@ethersproject/strings": "5.7.0", - "@ethersproject/transactions": "5.7.0", - "@ethersproject/units": "5.7.0", - "@ethersproject/wallet": "5.7.0", - "@ethersproject/web": "5.7.1", - "@ethersproject/wordlists": "5.7.0" - } - }, "node_modules/@lifi/types": { - "version": "8.6.0", - "resolved": "https://registry.npmjs.org/@lifi/types/-/types-8.6.0.tgz", - "integrity": "sha512-dHSoszXs8VS3Z2PtQq1319Y4RkLXFA3F0sKdt2BDZW4dUpR8Lx3EHjWJiBjosIGza9qVjy2qyHDHNWMsviS0IQ==", + "version": "9.3.3", + "resolved": "https://registry.npmjs.org/@lifi/types/-/types-9.3.3.tgz", + "integrity": "sha512-XY8S6RZMPf5d8XR4Pux2Iko6scBmH60gHm5BtPX2BF7x5eqZJ1Umyv/ael9MvBtjIzs9mroJZ1NTUL4pdWVu9Q==", "dependencies": { "ethers": "^5.7.2" } }, - "node_modules/@lifi/types/node_modules/@ethersproject/providers": { - "version": "5.7.2", - "resolved": "https://registry.npmjs.org/@ethersproject/providers/-/providers-5.7.2.tgz", - "integrity": "sha512-g34EWZ1WWAVgr4aptGlVBF8mhl3VWjv+8hoAnzStu8Ah22VHBsuGzP17eb6xDVRzw895G4W7vvx60lFFur/1Rg==", - "funding": [ - { - "type": "individual", - "url": "https://gitcoin.co/grants/13/ethersjs-complete-simple-and-tiny-2" - }, - { - "type": "individual", - "url": "https://www.buymeacoffee.com/ricmoo" - } - ], - "dependencies": { - "@ethersproject/abstract-provider": "^5.7.0", - "@ethersproject/abstract-signer": "^5.7.0", - "@ethersproject/address": "^5.7.0", - "@ethersproject/base64": "^5.7.0", - "@ethersproject/basex": "^5.7.0", - "@ethersproject/bignumber": "^5.7.0", - "@ethersproject/bytes": "^5.7.0", - "@ethersproject/constants": "^5.7.0", - "@ethersproject/hash": "^5.7.0", - "@ethersproject/logger": "^5.7.0", - "@ethersproject/networks": "^5.7.0", - "@ethersproject/properties": "^5.7.0", - "@ethersproject/random": "^5.7.0", - "@ethersproject/rlp": "^5.7.0", - "@ethersproject/sha2": "^5.7.0", - "@ethersproject/strings": "^5.7.0", - "@ethersproject/transactions": "^5.7.0", - "@ethersproject/web": "^5.7.0", - "bech32": "1.1.4", - "ws": "7.4.6" - } - }, - "node_modules/@lifi/types/node_modules/ethers": { - "version": "5.7.2", - "resolved": "https://registry.npmjs.org/ethers/-/ethers-5.7.2.tgz", - "integrity": "sha512-wswUsmWo1aOK8rR7DIKiWSw9DbLWe6x98Jrn8wcTflTVvaXhAMaB5zGAXy0GYQEQp9iO1iSHWVyARQm11zUtyg==", - "funding": [ - { - "type": "individual", - "url": "https://gitcoin.co/grants/13/ethersjs-complete-simple-and-tiny-2" - }, - { - "type": "individual", - "url": "https://www.buymeacoffee.com/ricmoo" - } - ], - "dependencies": { - "@ethersproject/abi": "5.7.0", - "@ethersproject/abstract-provider": "5.7.0", - "@ethersproject/abstract-signer": "5.7.0", - "@ethersproject/address": "5.7.0", - "@ethersproject/base64": "5.7.0", - "@ethersproject/basex": "5.7.0", - "@ethersproject/bignumber": "5.7.0", - "@ethersproject/bytes": "5.7.0", - "@ethersproject/constants": "5.7.0", - "@ethersproject/contracts": "5.7.0", - "@ethersproject/hash": "5.7.0", - "@ethersproject/hdnode": "5.7.0", - "@ethersproject/json-wallets": "5.7.0", - "@ethersproject/keccak256": "5.7.0", - "@ethersproject/logger": "5.7.0", - "@ethersproject/networks": "5.7.1", - "@ethersproject/pbkdf2": "5.7.0", - "@ethersproject/properties": "5.7.0", - "@ethersproject/providers": "5.7.2", - "@ethersproject/random": "5.7.0", - "@ethersproject/rlp": "5.7.0", - "@ethersproject/sha2": "5.7.0", - "@ethersproject/signing-key": "5.7.0", - "@ethersproject/solidity": "5.7.0", - "@ethersproject/strings": "5.7.0", - "@ethersproject/transactions": "5.7.0", - "@ethersproject/units": "5.7.0", - "@ethersproject/wallet": "5.7.0", - "@ethersproject/web": "5.7.1", - "@ethersproject/wordlists": "5.7.0" - } - }, "node_modules/@stablelib/aead": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/@stablelib/aead/-/aead-1.0.1.tgz", @@ -2161,11 +1993,11 @@ "dev": true }, "node_modules/cross-fetch": { - "version": "3.1.5", - "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.5.tgz", - "integrity": "sha512-lvb1SBsI0Z7GDwmuid+mU3kWVBwTVUbe7S0H52yaaAdQOXq2YktTCZdlAcNKFzE6QtRz0snpw9bNiPeOIkkQvw==", + "version": "3.1.8", + "resolved": "https://registry.npmjs.org/cross-fetch/-/cross-fetch-3.1.8.tgz", + "integrity": "sha512-cvA+JwZoU0Xq+h6WkMvAUqPEYy92Obet6UdKLfW60qn99ftItKjB5T+BkyWOFWe2pUyfQ+IJHmpOTznqk1M6Kg==", "dependencies": { - "node-fetch": "2.6.7" + "node-fetch": "^2.6.12" } }, "node_modules/cross-spawn": { @@ -2768,9 +2600,9 @@ } }, "node_modules/ethers": { - "version": "5.7.0", - "resolved": "https://registry.npmjs.org/ethers/-/ethers-5.7.0.tgz", - "integrity": "sha512-5Xhzp2ZQRi0Em+0OkOcRHxPzCfoBfgtOQA+RUylSkuHbhTEaQklnYi2hsWbRgs3ztJsXVXd9VKBcO1ScWL8YfA==", + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/ethers/-/ethers-5.7.2.tgz", + "integrity": "sha512-wswUsmWo1aOK8rR7DIKiWSw9DbLWe6x98Jrn8wcTflTVvaXhAMaB5zGAXy0GYQEQp9iO1iSHWVyARQm11zUtyg==", "funding": [ { "type": "individual", @@ -2797,10 +2629,10 @@ "@ethersproject/json-wallets": "5.7.0", "@ethersproject/keccak256": "5.7.0", "@ethersproject/logger": "5.7.0", - "@ethersproject/networks": "5.7.0", + "@ethersproject/networks": "5.7.1", "@ethersproject/pbkdf2": "5.7.0", "@ethersproject/properties": "5.7.0", - "@ethersproject/providers": "5.7.0", + "@ethersproject/providers": "5.7.2", "@ethersproject/random": "5.7.0", "@ethersproject/rlp": "5.7.0", "@ethersproject/sha2": "5.7.0", @@ -2810,50 +2642,10 @@ "@ethersproject/transactions": "5.7.0", "@ethersproject/units": "5.7.0", "@ethersproject/wallet": "5.7.0", - "@ethersproject/web": "5.7.0", + "@ethersproject/web": "5.7.1", "@ethersproject/wordlists": "5.7.0" } }, - "node_modules/ethers/node_modules/@ethersproject/networks": { - "version": "5.7.0", - "resolved": "https://registry.npmjs.org/@ethersproject/networks/-/networks-5.7.0.tgz", - "integrity": "sha512-MG6oHSQHd4ebvJrleEQQ4HhVu8Ichr0RDYEfHzsVAVjHNM+w36x9wp9r+hf1JstMXtseXDtkiVoARAG6M959AA==", - "funding": [ - { - "type": "individual", - "url": "https://gitcoin.co/grants/13/ethersjs-complete-simple-and-tiny-2" - }, - { - "type": "individual", - "url": "https://www.buymeacoffee.com/ricmoo" - } - ], - "dependencies": { - "@ethersproject/logger": "^5.7.0" - } - }, - "node_modules/ethers/node_modules/@ethersproject/web": { - "version": "5.7.0", - "resolved": "https://registry.npmjs.org/@ethersproject/web/-/web-5.7.0.tgz", - "integrity": "sha512-ApHcbbj+muRASVDSCl/tgxaH2LBkRMEYfLOLVa0COipx0+nlu0QKet7U2lEg0vdkh8XRSLf2nd1f1Uk9SrVSGA==", - "funding": [ - { - "type": "individual", - "url": "https://gitcoin.co/grants/13/ethersjs-complete-simple-and-tiny-2" - }, - { - "type": "individual", - "url": "https://www.buymeacoffee.com/ricmoo" - } - ], - "dependencies": { - "@ethersproject/base64": "^5.7.0", - "@ethersproject/bytes": "^5.7.0", - "@ethersproject/logger": "^5.7.0", - "@ethersproject/properties": "^5.7.0", - "@ethersproject/strings": "^5.7.0" - } - }, "node_modules/eventemitter3": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-3.1.2.tgz", @@ -4064,9 +3856,9 @@ "dev": true }, "node_modules/node-fetch": { - "version": "2.6.7", - "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.7.tgz", - "integrity": "sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==", + "version": "2.7.0", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.7.0.tgz", + "integrity": "sha512-c4FRfUm/dbcWZ7U+1Wq0AwCyFL+3nt2bEw05wfxSz+DWpWsitgmSgYmy2dQdWyKC1694ELPqMs/YzUSNozLt8A==", "dependencies": { "whatwg-url": "^5.0.0" }, @@ -7499,9 +7291,9 @@ } }, "node_modules/reflect-metadata": { - "version": "0.1.13", - "resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.1.13.tgz", - "integrity": "sha512-Ts1Y/anZELhSsjMcU605fU9RE4Oi3p5ORujwbIKXfWa+0Zxs510Qrmrce5/Jowq3cHSZSJqBjypxmHarc+vEWg==" + "version": "0.1.14", + "resolved": "https://registry.npmjs.org/reflect-metadata/-/reflect-metadata-0.1.14.tgz", + "integrity": "sha512-ZhYeb6nRaXCfhnndflDK8qI6ZQ/YcWZCISRAWICW9XYqMUwjZM9Z0DveWX/ABN01oxSHwVxKQmxeYZSsm0jh5A==" }, "node_modules/regexp.prototype.flags": { "version": "1.5.0", diff --git a/package.json b/package.json index 1d51676..e32cf31 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@etherspot/prime-sdk", - "version": "1.4.0", + "version": "1.4.1", "description": "Etherspot Prime (Account Abstraction) SDK", "keywords": [ "ether", @@ -61,8 +61,8 @@ "url": "https://github.com/etherspot/etherspot-prime-sdk/issues" }, "dependencies": { - "@apollo/client": "3.8.6", - "@lifi/sdk": "2.2.3", + "@apollo/client": "3.8.7", + "@lifi/sdk": "2.5.0", "@thehubbleproject/bls": "0.5.1", "@walletconnect/universal-provider": "2.10.0", "apollo-link-ws": "1.0.20", @@ -70,11 +70,11 @@ "class-transformer": "0.5.1", "class-validator": "0.14.0", "commander": "10.0.1", - "cross-fetch": "3.1.5", - "ethers": "5.7.0", + "cross-fetch": "3.1.8", + "ethers": "5.7.2", "graphql-ws": "5.14.2", "prettier": "2.8.8", - "reflect-metadata": "0.1.13", + "reflect-metadata": "0.1.14", "rxjs": "6.6.7" }, "devDependencies": { diff --git a/src/sdk/base/EtherspotWalletAPI.ts b/src/sdk/base/EtherspotWalletAPI.ts index a71f798..5a57396 100644 --- a/src/sdk/base/EtherspotWalletAPI.ts +++ b/src/sdk/base/EtherspotWalletAPI.ts @@ -17,6 +17,7 @@ import { BaseApiParams, BaseAccountAPI } from './BaseAccountAPI'; export interface EtherspotWalletApiParams extends BaseApiParams { factoryAddress?: string; index?: number; + predefinedAccountAddress?: string; } /** @@ -30,6 +31,7 @@ export class EtherspotWalletAPI extends BaseAccountAPI { factoryAddress?: string; index: number; accountAddress?: string; + predefinedAccountAddress?: string; /** * our account contract. @@ -43,6 +45,17 @@ export class EtherspotWalletAPI extends BaseAccountAPI { super(params); this.factoryAddress = params.factoryAddress; this.index = params.index ?? 0; + this.predefinedAccountAddress = params.predefinedAccountAddress ?? null; + } + + async checkAccountAddress(address: string): Promise { + const accountContract = EtherspotWallet__factory.connect(address, this.provider); + if (!(await accountContract.isOwner(this.services.walletService.EOAAddress))) { + throw new Error('the specified accountAddress does not belong to the given EOA provider') + } + else { + this.accountAddress = address; + } } async _getAccountContract(): Promise { @@ -73,6 +86,9 @@ export class EtherspotWalletAPI extends BaseAccountAPI { } async getCounterFactualAddress(): Promise { + if (this.predefinedAccountAddress) { + await this.checkAccountAddress(this.predefinedAccountAddress); + } if (!this.accountAddress) { this.factory = EtherspotWalletFactory__factory.connect(this.factoryAddress, this.provider); this.accountAddress = await this.factory.getAddress( diff --git a/src/sdk/interfaces.ts b/src/sdk/interfaces.ts index 5e7d964..d21aed1 100644 --- a/src/sdk/interfaces.ts +++ b/src/sdk/interfaces.ts @@ -21,6 +21,7 @@ export interface SdkOptions { factoryWallet?: Factory; walletFactoryAddress?: string; entryPointAddress?: string; + accountAddress?: string; } export enum graphqlEndpoints { diff --git a/src/sdk/sdk.ts b/src/sdk/sdk.ts index 09b8574..9f3da8c 100644 --- a/src/sdk/sdk.ts +++ b/src/sdk/sdk.ts @@ -46,6 +46,7 @@ export class PrimeSdk { const { chainId, // rpcProviderUrl, + accountAddress, } = optionsLike; this.chainId = chainId; @@ -105,6 +106,7 @@ export class PrimeSdk { optionsLike, entryPointAddress, factoryAddress: walletFactoryAddress, + predefinedAccountAddress: accountAddress, }) } this.bundler = new HttpRpcClient(optionsLike.bundlerRpcUrl, entryPointAddress, chainId);