diff --git a/package-lock.json b/package-lock.json index 52aa93e..78260c3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,7 +10,8 @@ "license": "MIT", "dependencies": { "@aleph-sdk/client": "^1.0.6", - "@aleph-sdk/ethereum": "^1.0.3", + "@aleph-sdk/ethereum": "file:../aleph-sdk-ts/packages/ethereum/aleph-sdk-ethereum-1.0.3.tgz", + "@aleph-sdk/evm": "file:../aleph-sdk-ts/packages/evm/aleph-sdk-evm-1.0.4.tgz", "@aleph-sdk/message": "^1.0.7", "@libertai/libertai-js": "0.0.10-beta", "@quasar/extras": "^1.16.12", @@ -101,6 +102,8 @@ }, "node_modules/@aleph-sdk/ethereum": { "version": "1.0.3", + "resolved": "file:../aleph-sdk-ts/packages/ethereum/aleph-sdk-ethereum-1.0.3.tgz", + "integrity": "sha512-u+OU1J6uGFxpTlmnS+MmYotXYRvvdHOUMLEBYYQjEVtHlI3YlEwn5ro9xNCzjH1Vh9z48FEuMZzqVHWuSuzi2w==", "license": "MIT", "dependencies": { "bip39": "^3.1.0", @@ -114,11 +117,10 @@ } }, "node_modules/@aleph-sdk/evm": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/@aleph-sdk/evm/-/evm-1.0.3.tgz", - "integrity": "sha512-JaCsuRszxrZy+PGTE9svXst1+RkCbiAIYHtA5HNwD+Ow35NixjqxaxcqlK4UnRSYvIs/2y16YuN8+69jnSg+qw==", + "version": "1.0.4", + "resolved": "file:../aleph-sdk-ts/packages/evm/aleph-sdk-evm-1.0.4.tgz", + "integrity": "sha512-msCd/ssASraYoO8VDpQWsN/LJBWac9lKm3nqo5ttdQMfJDvr+7kkYeVmaAy6j3R1b4zvppLRIo9Mh2ZsibOS/g==", "license": "MIT", - "peer": true, "dependencies": { "@metamask/eth-sig-util": "^7.0.1", "ethereumjs-util": "^7.1.5" @@ -3750,7 +3752,6 @@ "resolved": "https://registry.npmjs.org/@metamask/abi-utils/-/abi-utils-2.0.4.tgz", "integrity": "sha512-StnIgUB75x7a7AgUhiaUZDpCsqGp7VkNnZh2XivXkJ6mPkE83U8ARGQj5MbRis7VJY8BC5V1AbB1fjdh0hupPQ==", "license": "(Apache-2.0 AND MIT)", - "peer": true, "dependencies": { "@metamask/superstruct": "^3.1.0", "@metamask/utils": "^9.0.0" @@ -3764,7 +3765,6 @@ "resolved": "https://registry.npmjs.org/@metamask/utils/-/utils-9.1.0.tgz", "integrity": "sha512-g2REf+xSt0OZfMoNNdC4+/Yy8eP3KUqvIArel54XRFKPoXbHI6+YjFfrLtfykWBjffOp7DTfIc3Kvk5TLfuiyg==", "license": "ISC", - "peer": true, "dependencies": { "@ethereumjs/tx": "^4.2.0", "@metamask/superstruct": "^3.1.0", @@ -3789,7 +3789,6 @@ "https://github.com/sponsors/ctavan" ], "license": "MIT", - "peer": true, "bin": { "uuid": "dist/bin/uuid" } @@ -3875,7 +3874,6 @@ "resolved": "https://registry.npmjs.org/@metamask/eth-sig-util/-/eth-sig-util-7.0.3.tgz", "integrity": "sha512-PAtGnOkYvh90k2lEZldq/FK7GTLF6WxE+2bV85PoA3pqlJnmJCAY62tuvxHSwnVngSKlc4mcNvjnUg2eYO6JGg==", "license": "ISC", - "peer": true, "dependencies": { "@ethereumjs/util": "^8.1.0", "@metamask/abi-utils": "^2.0.4", @@ -3893,7 +3891,6 @@ "resolved": "https://registry.npmjs.org/@metamask/utils/-/utils-9.1.0.tgz", "integrity": "sha512-g2REf+xSt0OZfMoNNdC4+/Yy8eP3KUqvIArel54XRFKPoXbHI6+YjFfrLtfykWBjffOp7DTfIc3Kvk5TLfuiyg==", "license": "ISC", - "peer": true, "dependencies": { "@ethereumjs/tx": "^4.2.0", "@metamask/superstruct": "^3.1.0", @@ -3918,7 +3915,6 @@ "https://github.com/sponsors/ctavan" ], "license": "MIT", - "peer": true, "bin": { "uuid": "dist/bin/uuid" } @@ -5877,7 +5873,6 @@ "resolved": "https://registry.npmjs.org/@types/bn.js/-/bn.js-5.1.5.tgz", "integrity": "sha512-V46N0zwKRF5Q00AZ6hWtN0T8gGmDUaUzLWQvHFo5yThtVwK/VCenFY3wXVbOvNfajEpsTfQM4IN9k/d6gUVX3A==", "license": "MIT", - "peer": true, "dependencies": { "@types/node": "*" } @@ -6062,7 +6057,6 @@ "resolved": "https://registry.npmjs.org/@types/pbkdf2/-/pbkdf2-3.1.2.tgz", "integrity": "sha512-uRwJqmiXmh9++aSu1VNEn3iIxWOhd8AHXNSdlaLfdAAdSTY9jYVeGWnzejM3dvrkbqE3/hyQkQQ29IFATEGlew==", "license": "MIT", - "peer": true, "dependencies": { "@types/node": "*" } @@ -7862,7 +7856,6 @@ "resolved": "https://registry.npmjs.org/base-x/-/base-x-3.0.10.tgz", "integrity": "sha512-7d0s06rR9rYaIWHkpfLIFICM/tkSVdoPC9qYAQRpxn9DdKNWNsKC0uk++akckyLq16Tx2WIinnZ6WRriAt6njQ==", "license": "MIT", - "peer": true, "dependencies": { "safe-buffer": "^5.0.1" } @@ -7950,8 +7943,7 @@ "version": "1.2.1", "resolved": "https://registry.npmjs.org/blakejs/-/blakejs-1.2.1.tgz", "integrity": "sha512-QXUSXI3QVc/gJME0dBpXrag1kbzOqCjCX8/b54ntNyW6sjtoqxqRk3LTmXzaJoh71zMsDCjM+47jS7XiwN/+fQ==", - "license": "MIT", - "peer": true + "license": "MIT" }, "node_modules/bn.js": { "version": "4.12.0", @@ -8183,7 +8175,6 @@ "resolved": "https://registry.npmjs.org/bs58/-/bs58-4.0.1.tgz", "integrity": "sha512-Ok3Wdf5vOIlBrgCvTq96gBkJw+JUEzdBgyaza5HLtPm7yTHkjRy8+JzNyHF7BHa0bNWOQIp3m5YF0nnFcOIKLw==", "license": "MIT", - "peer": true, "dependencies": { "base-x": "^3.0.2" } @@ -8193,7 +8184,6 @@ "resolved": "https://registry.npmjs.org/bs58check/-/bs58check-2.1.2.tgz", "integrity": "sha512-0TS1jicxdU09dwJMNZtVAfzPi6Q6QeN0pM1Fkzrjn+XYHvzMKPU3pHVpva+769iNVSfIYWf7LJ6WR+BuuMf8cA==", "license": "MIT", - "peer": true, "dependencies": { "bs58": "^4.0.0", "create-hash": "^1.1.0", @@ -10130,7 +10120,6 @@ "resolved": "https://registry.npmjs.org/ethereumjs-util/-/ethereumjs-util-7.1.5.tgz", "integrity": "sha512-SDl5kKrQAudFBUe5OJM9Ac6WmMyYmXX/6sTmLZ3ffG2eY6ZIGBes3pEDxNN6V72WyOw4CPD5RomKdsa8DAAwLg==", "license": "MPL-2.0", - "peer": true, "dependencies": { "@types/bn.js": "^5.1.0", "bn.js": "^5.1.2", @@ -10146,15 +10135,13 @@ "version": "5.2.1", "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-5.2.1.tgz", "integrity": "sha512-eXRvHzWyYPBuB4NBy0cmYQjGitUrtqwbvlzP3G6VFnNRbsZQIxQ10PbKKHt8gZ/HW/D/747aDl+QkDqg3KQLMQ==", - "license": "MIT", - "peer": true + "license": "MIT" }, "node_modules/ethereumjs-util/node_modules/ethereum-cryptography": { "version": "0.1.3", "resolved": "https://registry.npmjs.org/ethereum-cryptography/-/ethereum-cryptography-0.1.3.tgz", "integrity": "sha512-w8/4x1SGGzc+tO97TASLja6SLd3fRIK2tLVcV2Gx4IB21hE19atll5Cq9o3d0ZmAYC/8aw0ipieTSiekAea4SQ==", "license": "MIT", - "peer": true, "dependencies": { "@types/pbkdf2": "^3.0.0", "@types/secp256k1": "^4.0.1", @@ -10177,8 +10164,7 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-2.0.2.tgz", "integrity": "sha512-Ntyt4AIXyaLIuMHF6IOoTakB3K+RWxwtsHNRxllEoA6vPwP9o4866g6YWDLUdnucilZhmkxiHwHr11gAENw+QA==", - "license": "MIT", - "peer": true + "license": "MIT" }, "node_modules/ethereumjs-util/node_modules/secp256k1": { "version": "4.0.3", @@ -10186,7 +10172,6 @@ "integrity": "sha512-NLZVf+ROMxwtEj3Xa562qgv2BK5e2WNmXPiOdVIPLgs6lyTzMvBq0aWTYMI5XCP9jZMVKOcqZLw/Wc4vDkuxhA==", "hasInstallScript": true, "license": "MIT", - "peer": true, "dependencies": { "elliptic": "^6.5.4", "node-addon-api": "^2.0.0", @@ -15812,7 +15797,6 @@ "resolved": "https://registry.npmjs.org/rlp/-/rlp-2.2.7.tgz", "integrity": "sha512-d5gdPmgQ0Z+AklL2NVXr/IoSjNZFfTVvQWzL/AM2AOcSzYP2xjlb0AC8YyCLc41MSNf6P6QVtjgPdmVtzb+4lQ==", "license": "MPL-2.0", - "peer": true, "dependencies": { "bn.js": "^5.2.0" }, @@ -15824,8 +15808,7 @@ "version": "5.2.1", "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-5.2.1.tgz", "integrity": "sha512-eXRvHzWyYPBuB4NBy0cmYQjGitUrtqwbvlzP3G6VFnNRbsZQIxQ10PbKKHt8gZ/HW/D/747aDl+QkDqg3KQLMQ==", - "license": "MIT", - "peer": true + "license": "MIT" }, "node_modules/rollup": { "version": "3.29.4", @@ -15979,8 +15962,7 @@ "version": "3.0.1", "resolved": "https://registry.npmjs.org/scrypt-js/-/scrypt-js-3.0.1.tgz", "integrity": "sha512-cdwTTnqPu0Hyvf5in5asVdZocVDTNRmR7XEcJuIzMjJeSHybHl7vpB66AzwTaIg6CLSbtjcxc8fqcySfnTkccA==", - "license": "MIT", - "peer": true + "license": "MIT" }, "node_modules/secp256k1": { "version": "5.0.0", @@ -16970,8 +16952,7 @@ "version": "1.0.3", "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.3.tgz", "integrity": "sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw==", - "license": "Unlicense", - "peer": true + "license": "Unlicense" }, "node_modules/type-check": { "version": "0.4.0", diff --git a/package.json b/package.json index 7f5eee9..a2e7e56 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,8 @@ }, "dependencies": { "@aleph-sdk/client": "^1.0.6", - "@aleph-sdk/ethereum": "^1.0.3", + "@aleph-sdk/ethereum": "file:../aleph-sdk-ts/packages/ethereum/aleph-sdk-ethereum-1.0.3.tgz", + "@aleph-sdk/evm": "file:../aleph-sdk-ts/packages/evm/aleph-sdk-evm-1.0.4.tgz", "@aleph-sdk/message": "^1.0.7", "@libertai/libertai-js": "0.0.10-beta", "@quasar/extras": "^1.16.12", diff --git a/src/utils/aleph-persistent-storage.ts b/src/utils/aleph-persistent-storage.ts index dfd8a54..2170772 100644 --- a/src/utils/aleph-persistent-storage.ts +++ b/src/utils/aleph-persistent-storage.ts @@ -2,8 +2,9 @@ import { AuthenticatedAlephHttpClient } from '@aleph-sdk/client'; import { ETHAccount, getAccountFromProvider, importAccountFromPrivateKey } from '@aleph-sdk/ethereum'; import web3 from 'web3'; import { ItemType } from '@aleph-sdk/message'; -import { signMessage } from '@wagmi/core'; +import { type Config, getClient, signMessage } from '@wagmi/core'; import { config } from 'src/config/wagmi'; +import type { Chain, Client, Transport } from 'viem'; import { SignMessageReturnType } from 'viem'; import { KnowledgeBase, @@ -14,6 +15,7 @@ import { import { decrypt, encrypt, generateIv, generateKey } from 'src/utils/encryption'; import { PrivateKey } from 'eciesjs'; import { decryptKnowledgeBaseIdentifiers, encryptKnowledgeBaseIdentifiers } from 'src/utils/knowledge/encryption'; +import { providers } from 'ethers'; // Aleph keys and channels settings const SECURITY_AGGREGATE_KEY = 'security'; @@ -23,6 +25,29 @@ 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 clientToProvider(client: Client) { + const { chain, transport } = client; + const network = { + chainId: chain.id, + name: chain.name, + ensAddress: chain.contracts?.ensRegistry?.address, + }; + if (transport.type === 'fallback') + return new providers.FallbackProvider( + (transport.transports as ReturnType[]).map( + ({ value }) => new providers.JsonRpcProvider(value?.url, network), + ), + ); + return new providers.JsonRpcProvider(transport.url, network); +} + +/** Action to convert a viem Public Client to an ethers.js Provider. */ +export function getEthersProvider(config: Config, { chainId }: { chainId?: number } = {}) { + const client = getClient(config, { chainId }); + if (!client) return; + return clientToProvider(client); +} + export class AlephPersistentStorage { constructor( /* eslint-disable-next-line no-unused-vars */ @@ -47,7 +72,9 @@ export class AlephPersistentStorage { const encryptionPrivateKey = PrivateKey.fromHex(privateKey); const subAccount = importAccountFromPrivateKey(privateKey); - const account = await getAccountFromProvider(window.ethereum); + const provider = getEthersProvider(config); + + const account = await getAccountFromProvider(provider as unknown as any); const accountClient = new AuthenticatedAlephHttpClient(account, process.env.ALEPH_API_URL); const subAccountClient = new AuthenticatedAlephHttpClient(subAccount, process.env.ALEPH_API_URL);