From 81311ca00b103ec96478783bb3dc99eb144ab653 Mon Sep 17 00:00:00 2001 From: Reza Rahemtola Date: Wed, 4 Sep 2024 15:06:03 +0900 Subject: [PATCH] fix(account): Working provider with ethers and injected wallet --- package-lock.json | 34 +++++++++++++-------------- package.json | 2 +- src/utils/aleph-persistent-storage.ts | 19 +++++++-------- 3 files changed, 25 insertions(+), 30 deletions(-) diff --git a/package-lock.json b/package-lock.json index 7f23915..420496d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,7 @@ "license": "MIT", "dependencies": { "@aleph-sdk/base": "file:../aleph-sdk-ts/packages/base", - "@aleph-sdk/client": "^1.0.6", + "@aleph-sdk/client": "file:../aleph-sdk-ts/packages/client", "@aleph-sdk/core": "file:../aleph-sdk-ts/packages/core", "@aleph-sdk/ethereum": "file:../aleph-sdk-ts/packages/ethereum", "@aleph-sdk/evm": "file:../aleph-sdk-ts/packages/evm", @@ -91,6 +91,19 @@ "ethers": "^5.x.x" } }, + "../aleph-sdk-ts/packages/client": { + "name": "@aleph-sdk/client", + "version": "1.0.6", + "license": "MIT", + "devDependencies": { + "@types/sha.js": "^2.4.4" + }, + "peerDependencies": { + "@aleph-sdk/account": "^1.x.x", + "@aleph-sdk/core": "^1.x.x", + "@aleph-sdk/message": "^1.x.x" + } + }, "../aleph-sdk-ts/packages/core": { "name": "@aleph-sdk/core", "version": "1.0.4", @@ -152,28 +165,13 @@ "integrity": "sha512-nA9XHtlAkYfJxY7bce8DcN7eKxWWCWkU+1GR9d+U6MbNpfwQp8TI7vqOsBsMcHoT4mBu2kypKoSKnghEzOOq5Q==", "license": "MIT" }, - "node_modules/@aleph-sdk/account": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/@aleph-sdk/account/-/account-1.0.3.tgz", - "integrity": "sha512-LVeY3bJ5pg1JxQpnIB7f1Dz4TVN1SuJeI4dFKJy/71r6foF1zUxzWt+dbedc1zhOspjlgf5oU6gsXZrkzUGLhQ==", - "license": "MIT", - "peer": true, - "peerDependencies": { - "@aleph-sdk/core": "^1.x.x" - } - }, "node_modules/@aleph-sdk/base": { "resolved": "../aleph-sdk-ts/packages/base", "link": true }, "node_modules/@aleph-sdk/client": { - "version": "1.0.6", - "license": "MIT", - "peerDependencies": { - "@aleph-sdk/account": "^1.x.x", - "@aleph-sdk/core": "^1.x.x", - "@aleph-sdk/message": "^1.x.x" - } + "resolved": "../aleph-sdk-ts/packages/client", + "link": true }, "node_modules/@aleph-sdk/core": { "resolved": "../aleph-sdk-ts/packages/core", diff --git a/package.json b/package.json index b390862..bed6cd4 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ }, "dependencies": { "@aleph-sdk/base": "file:../aleph-sdk-ts/packages/base", - "@aleph-sdk/client": "^1.0.6", + "@aleph-sdk/client": "file:../aleph-sdk-ts/packages/client", "@aleph-sdk/core": "file:../aleph-sdk-ts/packages/core", "@aleph-sdk/ethereum": "file:../aleph-sdk-ts/packages/ethereum", "@aleph-sdk/evm": "file:../aleph-sdk-ts/packages/evm", diff --git a/src/utils/aleph-persistent-storage.ts b/src/utils/aleph-persistent-storage.ts index b34fdc8..8919ea7 100644 --- a/src/utils/aleph-persistent-storage.ts +++ b/src/utils/aleph-persistent-storage.ts @@ -25,22 +25,20 @@ const LIBERTAI_SETTINGS_KEY = `${LIBERTAI_CHANNEL}-settings`; const LIBERTAI_KNOWLEDGE_BASE_IDENTIFIERS_KEY = `${LIBERTAI_CHANNEL}-knowledge-base-identifiers-test-12`; const LIBERTAI_KNOWLEDGE_BASE_POST_TYPE = `${LIBERTAI_CHANNEL}-knowledge-base-test-12`; -export function clientToSigner(client: Client) { - const { account, chain, transport } = client; +export function clientToProvider(client: Client) { + const { chain, transport } = client; const network = { chainId: chain.id, name: chain.name, ensAddress: chain.contracts?.ensRegistry?.address, }; - const provider = new providers.Web3Provider(transport, network); - const signer = provider.getSigner(account.address); - return signer; + return new providers.Web3Provider(transport, network); } -/** Action to convert a Viem Client to an ethers.js Signer. */ -export async function getEthersSigner(config: Config, { chainId }: { chainId?: number } = {}) { +/** Action to convert a Viem Client to an ethers.js Web3Provider. */ +export async function getEthersProvider(config: Config, { chainId }: { chainId?: number } = {}) { const client = await getConnectorClient(config, { chainId }); - return clientToSigner(client); + return clientToProvider(client); } export class AlephPersistentStorage { @@ -67,10 +65,9 @@ export class AlephPersistentStorage { const encryptionPrivateKey = PrivateKey.fromHex(privateKey); const subAccount = importAccountFromPrivateKey(privateKey); - const signer = await getEthersSigner(config); - const web3Provider = signer.provider; + const provider = await getEthersProvider(config); - const account = await getAccountFromProvider(web3Provider as unknown as any); + const account = await getAccountFromProvider(provider); const accountClient = new AuthenticatedAlephHttpClient(account, process.env.ALEPH_API_URL); const subAccountClient = new AuthenticatedAlephHttpClient(subAccount, process.env.ALEPH_API_URL);