From 9d0688bebdcb55e3db4d8038bb3ebf28a0b48768 Mon Sep 17 00:00:00 2001 From: Oleg Cherr Date: Wed, 20 Sep 2023 15:59:06 +0200 Subject: [PATCH 1/6] Fix chat message order --- domains/data/ylide/chats.ts | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/domains/data/ylide/chats.ts b/domains/data/ylide/chats.ts index 9b23e22..c131111 100644 --- a/domains/data/ylide/chats.ts +++ b/domains/data/ylide/chats.ts @@ -121,7 +121,7 @@ export enum ChatState { LOADING, } -export function useChat({ recipientName }: { recipientName?: string }) { +export function useChat({ recipientName }: { recipientName: string }) { const { client } = useNFT3() const { account } = useUser() const { walletAccount, decodeMessage, forceAuth, isLoading, authState } = useYlide() @@ -144,19 +144,21 @@ export function useChat({ recipientName }: { recipientName?: string }) { limit: 1000, }) - const entries = enteriesRaw.map((entry) => ({ - ...entry, - msg: { - ...entry.msg, - key: new Uint8Array(entry.msg.key), - }, - })) + const entries = enteriesRaw + .map((entry) => ({ + ...entry, + msg: { + ...entry.msg, + key: new Uint8Array(entry.msg.key), + }, + })) + .reverse() return await Promise.all( entries .filter((e) => e.type === 'message') .map(async (entry) => { - const decoded = await decodeMessage(entry.id, entry.msg, walletAccount) + const decoded = await decodeMessage(entry.id, entry.msg, walletAccount!) return { id: entry.id, From e800672255c723bc3da1daf701fa0c1fac5bff91 Mon Sep 17 00:00:00 2001 From: Oleg Cherr Date: Wed, 20 Sep 2023 16:03:26 +0200 Subject: [PATCH 2/6] Update Ylide SDK --- UI/profile-board/Feed/index.tsx | 2 +- domains/data/ylide/Wallet.ts | 62 +-- domains/data/ylide/index.ts | 409 ++++++++------------ domains/data/ylide/utils/isBytesEqual.ts | 3 - domains/data/ylide/utils/publish-helpers.ts | 98 ++--- package.json | 6 +- yarn.lock | 92 ++--- 7 files changed, 276 insertions(+), 396 deletions(-) delete mode 100644 domains/data/ylide/utils/isBytesEqual.ts diff --git a/UI/profile-board/Feed/index.tsx b/UI/profile-board/Feed/index.tsx index 42236fd..21d702d 100644 --- a/UI/profile-board/Feed/index.tsx +++ b/UI/profile-board/Feed/index.tsx @@ -83,7 +83,7 @@ const defaultPosts: PostData[] = [ const uniqueFeedId = '0000000000000000000000000000000000000000000000000000000000000117' as Uint256 // ISME const export function useFeedLoader(userAddress: string) { - const feedId = constructFeedId(userAddress, true, uniqueFeedId) + const feedId = constructFeedId(userAddress, true, false, uniqueFeedId) const { walletAccount, decodeMessage } = useYlide() return useCallback( diff --git a/domains/data/ylide/Wallet.ts b/domains/data/ylide/Wallet.ts index 59895c4..af911fe 100644 --- a/domains/data/ylide/Wallet.ts +++ b/domains/data/ylide/Wallet.ts @@ -1,11 +1,11 @@ import type { AbstractWalletController, - IGenericAccount, + WalletAccount, WalletControllerFactory, Ylide, - YlideKeyStore, + YlideKeysRegistry, } from '@ylide/sdk' -import { WalletEvent } from '@ylide/sdk' +import { PrivateKeyAvailabilityState, WalletEvent, YlideKeyVersion } from '@ylide/sdk' import EventEmitter from 'eventemitter3' export class Wallet extends EventEmitter { @@ -15,12 +15,12 @@ export class Wallet extends EventEmitter { private _isAvailable = false - currentWalletAccount: IGenericAccount | null = null + currentWalletAccount: WalletAccount | null = null currentBlockchain = 'unknown' constructor( private readonly ylide: Ylide, - private readonly keystore: YlideKeyStore, + private readonly keysRegistry: YlideKeysRegistry, factory: WalletControllerFactory, controller: AbstractWalletController ) { @@ -56,12 +56,12 @@ export class Wallet extends EventEmitter { this.controller.off(WalletEvent.BLOCKCHAIN_CHANGED, this.handleBlockchainChanged) } - handleAccountChanged = (newAccount: IGenericAccount) => { + handleAccountChanged = (newAccount: WalletAccount) => { this.currentWalletAccount = newAccount this.emit('accountUpdate', this.currentWalletAccount) } - handleAccountLogin = (newAccount: IGenericAccount) => { + handleAccountLogin = (newAccount: WalletAccount) => { this.currentWalletAccount = newAccount this.emit('accountUpdate', this.currentWalletAccount) } @@ -83,36 +83,48 @@ export class Wallet extends EventEmitter { return this._isAvailable } - async constructLocalKeyV3(account: IGenericAccount) { - return await this.keystore.constructKeypairV3( - 'New account connection', + async constructLocalKeyV3(account: WalletAccount) { + return await this.keysRegistry.instantiateNewPrivateKey( this.factory.blockchainGroup, - this.factory.wallet, - account.address + account.address, + YlideKeyVersion.KEY_V3, + PrivateKeyAvailabilityState.AVAILABLE, + { + onPrivateKeyRequest: async (address, magicString) => + await this.controller.signMagicString(account, magicString), + } ) } - async constructLocalKeyV2(account: IGenericAccount, password: string) { - return await this.keystore.constructKeypairV2( - 'New account connection', + async constructLocalKeyV2(account: WalletAccount, password: string) { + return await this.keysRegistry.instantiateNewPrivateKey( this.factory.blockchainGroup, - this.factory.wallet, account.address, - password + YlideKeyVersion.KEY_V2, + PrivateKeyAvailabilityState.AVAILABLE, + { + onPrivateKeyRequest: async (address, magicString) => + await this.controller.signMagicString(account, magicString), + onYlidePasswordRequest: async (address) => password, + } ) } - async constructLocalKeyV1(account: IGenericAccount, password: string) { - return await this.keystore.constructKeypairV1( - 'New account connection', + async constructLocalKeyV1(account: WalletAccount, password: string) { + return await this.keysRegistry.instantiateNewPrivateKey( this.factory.blockchainGroup, - this.factory.wallet, account.address, - password + YlideKeyVersion.INSECURE_KEY_V1, + PrivateKeyAvailabilityState.AVAILABLE, + { + onPrivateKeyRequest: async (address, magicString) => + await this.controller.signMagicString(account, magicString), + onYlidePasswordRequest: async (address) => password, + } ) } - async readRemoteKeys(account: IGenericAccount) { + async readRemoteKeys(account: WalletAccount) { const result = await this.ylide.core.getAddressKeys(account.address) return { @@ -121,11 +133,11 @@ export class Wallet extends EventEmitter { } } - async getCurrentAccount(): Promise { + async getCurrentAccount(): Promise { return this.controller.getAuthenticatedAccount() } - async disconnectAccount(account: IGenericAccount) { + async disconnectAccount(account: WalletAccount) { await this.controller.disconnectAccount(account) } diff --git a/domains/data/ylide/index.ts b/domains/data/ylide/index.ts index 7a40f26..38067e7 100644 --- a/domains/data/ylide/index.ts +++ b/domains/data/ylide/index.ts @@ -1,34 +1,24 @@ -import type { EthereumBlockchainController, EthereumWalletController } from '@ylide/ethereum' +import type { EVMBlockchainController, EVMWalletController } from '@ylide/ethereum' import { EVM_CHAINS, EVM_NAMES, evmBlockchainFactories, EVMNetwork, evmWalletFactories } from '@ylide/ethereum' import type { BlockchainMap, - ExternalYlidePublicKey, - IGenericAccount, IMessage, IMessageContent, MessageContentV4, + RemotePublicKey, Uint256, - YlideKey, - YlideKeyPair, + WalletAccount, + YlidePrivateKey, YMF, } from '@ylide/sdk' -import { WalletEvent } from '@ylide/sdk' -import { - BrowserLocalStorage, - ServiceCode, - Ylide, - YlideKeyStore, - YlideKeyStoreEvent, - YlidePublicKeyVersion, -} from '@ylide/sdk' +import { BrowserLocalStorage, ServiceCode, WalletEvent, Ylide, YlideKeysRegistry, YlideKeyVersion } from '@ylide/sdk' import { toast } from 'lib/toastify' import { createContext } from 'app/utils/createContext' import { useCallback, useEffect, useMemo, useRef, useState } from 'react' import { useNFT3 } from '@nft3sdk/did-manager' import { blockchainMeta, evmNameToNetwork } from './constants' import { Wallet } from './Wallet' -import { isBytesEqual } from './utils/isBytesEqual' -import { chainIdByFaucetType, publishKeyThroughFaucet, requestFaucetSignature } from './utils/publish-helpers' +import { publishThroughFaucet } from './utils/publish-helpers' import { useDialog } from 'app/hooks/useDialog' export enum AuthState { @@ -40,42 +30,6 @@ export enum AuthState { AUTHORIZED = 'AUTHORIZED', // alles gut } -const INDEXER_BLOCKCHAINS = [ - 'ETHEREUM', - 'AVALANCHE', - 'ARBITRUM', - 'BNBCHAIN', - 'OPTIMISM', - 'POLYGON', - 'FANTOM', - 'KLAYTN', - 'GNOSIS', - 'AURORA', - 'CELO', - 'CRONOS', - 'MOONBEAM', - 'MOONRIVER', - 'METIS', -] - -Ylide.registerBlockchainFactory(evmBlockchainFactories[EVMNetwork.ETHEREUM]) -Ylide.registerBlockchainFactory(evmBlockchainFactories[EVMNetwork.AVALANCHE]) -Ylide.registerBlockchainFactory(evmBlockchainFactories[EVMNetwork.ARBITRUM]) -Ylide.registerBlockchainFactory(evmBlockchainFactories[EVMNetwork.BNBCHAIN]) -Ylide.registerBlockchainFactory(evmBlockchainFactories[EVMNetwork.OPTIMISM]) -Ylide.registerBlockchainFactory(evmBlockchainFactories[EVMNetwork.POLYGON]) -Ylide.registerBlockchainFactory(evmBlockchainFactories[EVMNetwork.FANTOM]) -Ylide.registerBlockchainFactory(evmBlockchainFactories[EVMNetwork.KLAYTN]) -Ylide.registerBlockchainFactory(evmBlockchainFactories[EVMNetwork.GNOSIS]) -Ylide.registerBlockchainFactory(evmBlockchainFactories[EVMNetwork.AURORA]) -Ylide.registerBlockchainFactory(evmBlockchainFactories[EVMNetwork.CELO]) -Ylide.registerBlockchainFactory(evmBlockchainFactories[EVMNetwork.CRONOS]) -Ylide.registerBlockchainFactory(evmBlockchainFactories[EVMNetwork.MOONBEAM]) -Ylide.registerBlockchainFactory(evmBlockchainFactories[EVMNetwork.MOONRIVER]) -Ylide.registerBlockchainFactory(evmBlockchainFactories[EVMNetwork.METIS]) - -Ylide.registerWalletFactory(evmWalletFactories.generic) - export interface YlideDecodedMessage { msgId: string decodedSubject: string @@ -86,28 +40,52 @@ export type BlockchainBalances = Record { const { account, identifier } = useNFT3() - const storage = useMemo(() => new BrowserLocalStorage(), []) - const keystore = useMemo( - () => - new YlideKeyStore(storage, { - onPasswordRequest: null, // handlePasswordRequest.bind(this), - onDeriveRequest: null, // handleDeriveRequest.bind(this), - }), - [storage] - ) - const ylide = useMemo(() => new Ylide(keystore, INDEXER_BLOCKCHAINS), [keystore]) - - useEffect(() => { - keystore.init() - }, [keystore]) + const keysRegistry = useMemo(() => new YlideKeysRegistry(new BrowserLocalStorage()), []) + const ylide = useMemo(() => { + const ylide = new Ylide(keysRegistry, [ + 'ETHEREUM', + 'AVALANCHE', + 'ARBITRUM', + 'BNBCHAIN', + 'OPTIMISM', + 'POLYGON', + 'FANTOM', + 'KLAYTN', + 'GNOSIS', + 'AURORA', + 'CELO', + 'CRONOS', + 'MOONBEAM', + 'MOONRIVER', + 'METIS', + ]) + + ylide.registerBlockchainFactory(evmBlockchainFactories[EVMNetwork.ETHEREUM]) + ylide.registerBlockchainFactory(evmBlockchainFactories[EVMNetwork.AVALANCHE]) + ylide.registerBlockchainFactory(evmBlockchainFactories[EVMNetwork.ARBITRUM]) + ylide.registerBlockchainFactory(evmBlockchainFactories[EVMNetwork.BNBCHAIN]) + ylide.registerBlockchainFactory(evmBlockchainFactories[EVMNetwork.OPTIMISM]) + ylide.registerBlockchainFactory(evmBlockchainFactories[EVMNetwork.POLYGON]) + ylide.registerBlockchainFactory(evmBlockchainFactories[EVMNetwork.FANTOM]) + ylide.registerBlockchainFactory(evmBlockchainFactories[EVMNetwork.KLAYTN]) + ylide.registerBlockchainFactory(evmBlockchainFactories[EVMNetwork.GNOSIS]) + ylide.registerBlockchainFactory(evmBlockchainFactories[EVMNetwork.AURORA]) + ylide.registerBlockchainFactory(evmBlockchainFactories[EVMNetwork.CELO]) + ylide.registerBlockchainFactory(evmBlockchainFactories[EVMNetwork.CRONOS]) + ylide.registerBlockchainFactory(evmBlockchainFactories[EVMNetwork.MOONBEAM]) + ylide.registerBlockchainFactory(evmBlockchainFactories[EVMNetwork.MOONRIVER]) + ylide.registerBlockchainFactory(evmBlockchainFactories[EVMNetwork.METIS]) + + ylide.registerWalletFactory(evmWalletFactories.generic) + + return ylide + }, [keysRegistry]) const [wallet, setWallet] = useState(null) - // blockchainControllers will be used in future - const [blockchainControllers, setBlockchainControllers] = useState>({}) - const [walletAccount, setWalletAccount] = useState(null) - const [keys, setKeys] = useState(keystore.keys) - const [remoteKeys, setRemoteKeys] = useState>({}) - const [remoteKey, setRemoteKey] = useState(null) + const [blockchainControllers, setBlockchainControllers] = useState>({}) + const [walletAccount, setWalletAccount] = useState(null) + const [localKeys, setLocalKeys] = useState([]) + const [remoteKey, setRemoteKey] = useState(null) const [initialized, setInitialized] = useState(false) const [isLoading, setIsLoading] = useState(true) @@ -115,7 +93,13 @@ const useYlideService = () => { console.log('Accounts changed, Ylide: ' + walletAccount?.address + ', NFT3: ' + account) }, [walletAccount, account]) - const switchEVMChain = useCallback(async (_walletController: EthereumWalletController, needNetwork: EVMNetwork) => { + const reloadRemoteKeys = useCallback(async () => { + if (!wallet || !walletAccount) return + const { remoteKey } = await wallet.readRemoteKeys(walletAccount) + setRemoteKey(remoteKey) + }, [wallet, walletAccount]) + + const switchEVMChain = useCallback(async (_walletController: EVMWalletController, needNetwork: EVMNetwork) => { try { const bData = blockchainMeta[EVM_NAMES[needNetwork]] @@ -124,7 +108,7 @@ const useYlideService = () => { params: [bData.ethNetwork!], }) } catch (error) { - console.log('error: ', error) + console.error('error: ', error) } try { @@ -142,23 +126,26 @@ const useYlideService = () => { useEffect(() => { ;(async () => { if (initialized) return - const availableWallets = await Ylide.getAvailableWallets() + + await keysRegistry.init() + + const availableWallets = await ylide.getAvailableWallets() const genericFactory = availableWallets.find((w) => w.wallet === 'generic') if (genericFactory && !wallet) { + // noinspection JSUnusedGlobalSymbols const newWalletController = await ylide.controllers.addWallet( - genericFactory.blockchainGroup, genericFactory.wallet, { dev: false, //document.location.hostname === 'localhost', onSwitchAccountRequest: () => {}, onNetworkSwitchRequest: async ( - reason: string, + _reason: string, currentNetwork: EVMNetwork | undefined, needNetwork: EVMNetwork ) => { try { - await switchEVMChain(newWalletController as EthereumWalletController, needNetwork) + await switchEVMChain(newWalletController as EVMWalletController, needNetwork) } catch (err) { alert( 'Wrong network (' + @@ -169,55 +156,28 @@ const useYlideService = () => { } }, walletConnectProvider: null, - } + }, + genericFactory.blockchainGroup ) - const newWallet = new Wallet(ylide, keystore, genericFactory, newWalletController) - const handleDeriveRequest = async ( - reason: string, - blockchainGroup: string, - walletName: string, - address: string, - magicString: string - ) => { - try { - if (newWallet.factory.wallet !== walletName) { - return null - } - return newWallet.controller.signMagicString( - { - address, - blockchain: blockchainGroup, - publicKey: null, - }, - magicString - ) - } catch (err) { - return null - } - } - keystore.options.onDeriveRequest = handleDeriveRequest + const newWallet = new Wallet(ylide, keysRegistry, genericFactory, newWalletController) setWallet(newWallet) } setInitialized(true) })() - }, [initialized, ylide, wallet, keystore, switchEVMChain]) - - const handleKeysUpdate = useCallback((newKeys: YlideKey[]) => { - setKeys([...newKeys]) - }, []) + }, [initialized, ylide, wallet, keysRegistry, switchEVMChain]) useEffect(() => { ;(async () => { - const registeredBlockchains = Ylide.blockchainsList.map((b) => b.factory) + const registeredBlockchains = ylide.blockchainsList.map((b) => b.factory) - const controllers: Record = Object.assign({}, blockchainControllers) + const controllers: Record = Object.assign({}, blockchainControllers) let changed = false for (const factory of registeredBlockchains) { if (!controllers[factory.blockchain]) { controllers[factory.blockchain] = (await ylide.controllers.addBlockchain(factory.blockchain, { dev: false, //document.location.hostname === 'localhost', - })) as EthereumBlockchainController + })) as EVMBlockchainController changed = true } } @@ -228,131 +188,108 @@ const useYlideService = () => { })() }, [blockchainControllers, ylide]) - useEffect(() => { - keystore.on(YlideKeyStoreEvent.KEYS_UPDATED, handleKeysUpdate) - return () => { - keystore.off(YlideKeyStoreEvent.KEYS_UPDATED, handleKeysUpdate) - } - }, [handleKeysUpdate, keystore]) - useEffect(() => { ;(async () => { if (!wallet) return - let lastWalletAccount: IGenericAccount | null = null + let lastWalletAccount: WalletAccount | null = null wallet.on('accountUpdate', async (newWalletAccount) => { console.log('Account update: ', newWalletAccount) if (newWalletAccount !== lastWalletAccount) { lastWalletAccount = newWalletAccount if (newWalletAccount) { - const { remoteKeys, remoteKey } = await wallet.readRemoteKeys(newWalletAccount) + const { remoteKey } = await wallet.readRemoteKeys(newWalletAccount) setWalletAccount(newWalletAccount) - setRemoteKeys(remoteKeys) setRemoteKey(remoteKey) } else { setWalletAccount(null) - setRemoteKeys({}) setRemoteKey(null) } } }) await wallet.init() lastWalletAccount = wallet.currentWalletAccount - if (wallet.currentWalletAccount) { - const { remoteKeys, remoteKey } = await wallet.readRemoteKeys(wallet.currentWalletAccount) - setWalletAccount(wallet.currentWalletAccount) - setRemoteKeys(remoteKeys) + if (lastWalletAccount) { + const { remoteKey } = await wallet.readRemoteKeys(lastWalletAccount) + setWalletAccount(lastWalletAccount) + setLocalKeys(keysRegistry.getLocalPrivateKeys(lastWalletAccount.address)) setRemoteKey(remoteKey) setIsLoading(false) } else { setWalletAccount(null) - setRemoteKeys({}) + setLocalKeys([]) setRemoteKey(null) setIsLoading(false) } })() - }, [wallet]) - - const reloadRemoteKeys = useCallback(async () => { - if (!wallet || !walletAccount) return - const { remoteKeys, remoteKey } = await wallet.readRemoteKeys(walletAccount) - setRemoteKeys(remoteKeys) - setRemoteKey(remoteKey) - }, [wallet, walletAccount]) + }, [keysRegistry, wallet]) // okay, so: // 1. walletAccount - current wallet account // 2. keys - all available local keys // 3. remoteKeys - remote keys for the current account - const authState = useMemo(() => { - if (isLoading) { - return AuthState.LOADING - } - if (!walletAccount || !account) { - return AuthState.NOT_AUTHORIZED - } - if (!remoteKey) { - return AuthState.NO_REMOTE_KEY - } - const localKey = keys.find((k) => k.address === walletAccount.address) - if (!localKey) { - return AuthState.HAS_REMOTE_BUT_NO_LOCAL_KEY - } - if (!isBytesEqual(localKey.keypair.publicKey, remoteKey.publicKey.bytes)) { - return AuthState.LOCAL_REMOTE_MISMATCH - } - return AuthState.AUTHORIZED - }, [account, isLoading, keys, remoteKey, walletAccount]) + const newState = (() => { + if (!initialized || isLoading) { + return AuthState.LOADING + } + + if (!walletAccount || !account) { + return AuthState.NOT_AUTHORIZED + } + + if (!remoteKey) { + return AuthState.NO_REMOTE_KEY + } + + const localKey = localKeys.find((k) => k.address === remoteKey.address) + if (!localKey) { + return AuthState.HAS_REMOTE_BUT_NO_LOCAL_KEY + } + + if (!localKey.publicKey.equals(remoteKey.publicKey)) { + return AuthState.LOCAL_REMOTE_MISMATCH + } + + return AuthState.AUTHORIZED + })() + + console.log(`authState`, newState) + return newState + }, [account, initialized, isLoading, localKeys, remoteKey, walletAccount]) const saveLocalKey = useCallback( - async (key: YlideKeyPair, keyVersion: YlidePublicKeyVersion) => { - await keystore.storeKey(key, keyVersion, 'evm', 'generic') - await keystore.save() + async (key: YlidePrivateKey) => { + await keysRegistry.addLocalPrivateKey(key) + setLocalKeys(keysRegistry.getLocalPrivateKeys(key.address)) }, - [keystore] + [keysRegistry] ) const isPasswordNeeded = useMemo(() => { - if (remoteKey?.keyVersion === 1) { - return true - } else if (remoteKey?.keyVersion === 2) { - return true - } else if (remoteKey?.keyVersion === 3) { - return false - } else { - return false - } + const keyVersion = remoteKey?.publicKey.keyVersion + return keyVersion === 1 || keyVersion === 2 }, [remoteKey]) const createLocalKey = useCallback( async (password: string, forceNew?: boolean) => { - console.log('createLocalKey') - let tempLocalKey: YlideKeyPair - let keyVersion: YlidePublicKeyVersion try { if (forceNew) { - tempLocalKey = await wallet.constructLocalKeyV2(walletAccount, password) - keyVersion = YlidePublicKeyVersion.KEY_V2 - } else if (remoteKey?.keyVersion === YlidePublicKeyVersion.INSECURE_KEY_V1) { + return await wallet.constructLocalKeyV2(walletAccount, password) + } else if (remoteKey?.publicKey.keyVersion === YlideKeyVersion.INSECURE_KEY_V1) { // strange... I'm not sure Qamon keys work here - tempLocalKey = await wallet.constructLocalKeyV1(walletAccount, password) //wallet.constructLocalKeyV1(walletAccount, password); - keyVersion = YlidePublicKeyVersion.INSECURE_KEY_V1 - } else if (remoteKey?.keyVersion === YlidePublicKeyVersion.KEY_V2) { + return await wallet.constructLocalKeyV1(walletAccount, password) //wallet.constructLocalKeyV1(walletAccount, password); + } else if (remoteKey?.publicKey.keyVersion === YlideKeyVersion.KEY_V2) { // if user already using password - we should use it too - tempLocalKey = await wallet.constructLocalKeyV2(walletAccount, password) - keyVersion = YlidePublicKeyVersion.KEY_V2 - } else if (remoteKey?.keyVersion === YlidePublicKeyVersion.KEY_V3) { + return await wallet.constructLocalKeyV2(walletAccount, password) + } else if (remoteKey?.publicKey.keyVersion === YlideKeyVersion.KEY_V3) { // if user is not using password - we should not use it too - tempLocalKey = await wallet.constructLocalKeyV3(walletAccount) - keyVersion = YlidePublicKeyVersion.KEY_V3 + return await wallet.constructLocalKeyV3(walletAccount) } else { // user have no key at all - use passwordless version - tempLocalKey = await wallet.constructLocalKeyV3(walletAccount) - keyVersion = YlidePublicKeyVersion.KEY_V3 + return await wallet.constructLocalKeyV3(walletAccount) } - return { key: tempLocalKey, keyVersion } } catch (err) { - console.log('createLocalKey error', err) + console.error('createLocalKey error', err) return null } }, @@ -361,40 +298,25 @@ const useYlideService = () => { const publishLocalKey = useCallback( async ( - faucetType: 'polygon' | 'gnosis' | 'fantom', - key: YlideKeyPair, - account: IGenericAccount, - keyVersion: number + faucetType: EVMNetwork.GNOSIS | EVMNetwork.FANTOM | EVMNetwork.POLYGON, + key: YlidePrivateKey, + account: WalletAccount ) => { - // TODO: request signature, publish through faucet - const chainId = chainIdByFaucetType(faucetType) - const timestampLock = Math.floor(Date.now() / 1000) - 90 - const registrar = 4 // NFT3 const - const signature = await requestFaucetSignature( + await publishThroughFaucet({ + ylide, + keysRegistry, wallet, - key.keypair.publicKey, account, - chainId, - registrar, - timestampLock - ) - - await publishKeyThroughFaucet( + publicKey: key.publicKey, faucetType, - key.keypair.publicKey, - account, - signature, - registrar, - timestampLock, - keyVersion - ) + }) }, - [wallet] + [keysRegistry, wallet, ylide] ) const getBalancesOf = useCallback( async (address: string): Promise => { - const chains = Ylide.blockchainsList.map((b) => b.factory) + const chains = ylide.blockchainsList.map((b) => b.factory) const balances = await Promise.all( chains.map((chain) => blockchainControllers[chain.blockchain]!.getBalance(address)) ) @@ -407,7 +329,7 @@ const useYlideService = () => { {} as BlockchainBalances ) }, - [blockchainControllers] + [blockchainControllers, ylide] ) useEffect(() => { @@ -421,46 +343,36 @@ const useYlideService = () => { }) ;(async () => { if (authState === AuthState.AUTHORIZED) { - console.log('User authorized in Ylide') // do nothing, user already authorized } else if (authState === AuthState.NO_REMOTE_KEY) { - const result = await createLocalKey('') - if (!result) { + const key = await createLocalKey('') + if (!key) { // so sad :( wait for user to try to read some message return } - const { key, keyVersion } = result - await saveLocalKey(key, keyVersion) - await publishLocalKey('gnosis', key, walletAccount, keyVersion) + await saveLocalKey(key) + await publishLocalKey(EVMNetwork.GNOSIS, key, walletAccount) await new Promise((r) => setTimeout(r, 3000)) - const { remoteKeys, remoteKey } = await wallet.readRemoteKeys(walletAccount) - console.log('setRemoteKeys') - setRemoteKeys(remoteKeys) - console.log('setRemoteKey') + const { remoteKey } = await wallet.readRemoteKeys(walletAccount) setRemoteKey(remoteKey) toast.success('Ylide is authorized') } else if (authState === AuthState.HAS_REMOTE_BUT_NO_LOCAL_KEY) { if (isPasswordNeeded) { // do nothing, wait for user to try to read some message } else { - const result = await createLocalKey('') - if (!result) { + const key = await createLocalKey('') + if (!key) { // so sad :( weird case, wait for user to try to read some message return } - const { key, keyVersion } = result - await saveLocalKey(key, keyVersion) - await publishLocalKey('gnosis', key, walletAccount, keyVersion) + await saveLocalKey(key) + await publishLocalKey(EVMNetwork.GNOSIS, key, walletAccount) await new Promise((r) => setTimeout(r, 3000)) - const { remoteKeys, remoteKey } = await wallet.readRemoteKeys(walletAccount) - console.log('setRemoteKeys') - setRemoteKeys(remoteKeys) - console.log('setRemoteKey') + const { remoteKey } = await wallet.readRemoteKeys(walletAccount) setRemoteKey(remoteKey) toast.success('Ylide is authorized') } } else { - console.log('no account', account, identifier) // no account, do nothing } })() @@ -484,19 +396,18 @@ const useYlideService = () => { onOpen: (callback?: () => boolean) => { enterPasswordCallbackRef.current = callback }, - onClose: async (e: any, password: string | null) => { + onClose: async (_e: any, password: string | null) => { if (!password) { return enterPasswordCallbackRef.current?.(false) } if (authState === AuthState.HAS_REMOTE_BUT_NO_LOCAL_KEY) { - const result = await createLocalKey(password) - if (!result) { + const key = await createLocalKey(password) + if (!key) { // so sad :( weird case, wait for user to try to read some message return enterPasswordCallbackRef.current?.(false) } - const { key, keyVersion } = result - if (isBytesEqual(key.publicKey, remoteKey.publicKey.bytes)) { - await saveLocalKey(key, keyVersion) + if (key.publicKey.equals(remoteKey.publicKey)) { + await saveLocalKey(key) toast.success('Ylide is authorized') enterPasswordCallbackRef.current?.(true) } else { @@ -514,24 +425,21 @@ const useYlideService = () => { }, [enterPasswordDialog]) const forceAuth = useCallback(async () => { - console.log('forceAuth', authState) if (authState === AuthState.AUTHORIZED) { return true } else if (authState === AuthState.NO_REMOTE_KEY || authState === AuthState.HAS_REMOTE_BUT_NO_LOCAL_KEY) { if (isPasswordNeeded) { return await new Promise(enterPasswordDialog.open) } else { - const result = await createLocalKey('') - if (!result) { + const key = await createLocalKey('') + if (!key) { // so sad :( wait for user to try to read some message return false } - const { key, keyVersion } = result - await saveLocalKey(key, keyVersion) - await publishLocalKey('gnosis', key, walletAccount, keyVersion) + await saveLocalKey(key) + await publishLocalKey(EVMNetwork.GNOSIS, key, walletAccount) await new Promise((r) => setTimeout(r, 3000)) - const { remoteKeys, remoteKey } = await wallet.readRemoteKeys(walletAccount) - setRemoteKeys(remoteKeys) + const { remoteKey } = await wallet.readRemoteKeys(walletAccount) setRemoteKey(remoteKey) toast.success('Ylide is authorized') return true @@ -550,12 +458,8 @@ const useYlideService = () => { wallet, ]) - useEffect(() => { - console.log('authState changed', authState) - }, [authState]) - const decodeMessage = useCallback( - async (msgId: string, msg: IMessage, recepient: IGenericAccount) => { + async (msgId: string, msg: IMessage, recepient: WalletAccount) => { const content = await ylide.core.getMessageContent(msg) if (!content || content.corrupted) { toast.error('Content is not available or corrupted') @@ -610,7 +514,7 @@ const useYlideService = () => { }, onClose: async (network?: EVMNetwork) => { if (network != null && activeNetwork != network) { - await switchEVMChain(wallet!.controller as EthereumWalletController, network) + await switchEVMChain(wallet!.controller as EVMWalletController, network) } evmNetworkCallbackRef.current?.(network) @@ -680,7 +584,6 @@ const useYlideService = () => { walletAccount, remoteKey, - remoteKeys, forceAuth, diff --git a/domains/data/ylide/utils/isBytesEqual.ts b/domains/data/ylide/utils/isBytesEqual.ts deleted file mode 100644 index ef278ef..0000000 --- a/domains/data/ylide/utils/isBytesEqual.ts +++ /dev/null @@ -1,3 +0,0 @@ -export const isBytesEqual = (a: Uint8Array, b: Uint8Array) => { - return a.length === b.length && a.every((v, i) => v === b[i]); -}; diff --git a/domains/data/ylide/utils/publish-helpers.ts b/domains/data/ylide/utils/publish-helpers.ts index 9ac9956..89735b8 100644 --- a/domains/data/ylide/utils/publish-helpers.ts +++ b/domains/data/ylide/utils/publish-helpers.ts @@ -1,75 +1,41 @@ -import { constructFaucetMsg, type EthereumWalletController } from '@ylide/ethereum' -import type { IGenericAccount } from '@ylide/sdk' -import SmartBuffer from '@ylide/smart-buffer' +import type { EVMNetwork } from '@ylide/ethereum' +import { EVM_NAMES } from '@ylide/ethereum' import type { Wallet } from '../Wallet' +import type { PublicKey, WalletAccount, Ylide, YlideKeysRegistry } from '@ylide/sdk' -export const requestFaucetSignature = async ( - wallet: Wallet, - publicKey: Uint8Array, - account: IGenericAccount, - chainId: number, - registrar: number, - timestampLock: number -) => { - const msg = constructFaucetMsg(publicKey, registrar, chainId, timestampLock) - +export async function publishThroughFaucet({ + ylide, + keysRegistry, + wallet, + account, + publicKey, + faucetType, +}: { + ylide: Ylide + keysRegistry: YlideKeysRegistry + wallet: Wallet + account: WalletAccount + publicKey: PublicKey + faucetType: EVMNetwork.GNOSIS | EVMNetwork.FANTOM | EVMNetwork.POLYGON +}) { try { - return await (wallet.controller as EthereumWalletController).signString(account, msg) - } catch (err) { - console.error('requestFaucetSignature error: ', err) - throw err - } -} + const faucet = await wallet.controller.getFaucet({ faucetType }) -export const chainIdByFaucetType = (faucetType: 'polygon' | 'gnosis' | 'fantom') => { - if (faucetType === 'polygon') { - return 137 - } else if (faucetType === 'gnosis') { - return 100 - } else if (faucetType === 'fantom') { - return 250 - } else { - throw new Error('Invalid faucet type') - } -} + const registrar = 4 // NFT3 const + const data = await faucet.authorizePublishing(account, publicKey, registrar) + + const result = await faucet.attachPublicKey(data) + + const key = await ylide.core.waitForPublicKey(EVM_NAMES[faucetType], account.address, publicKey.keyBytes) -export const publishKeyThroughFaucet = async ( - faucetType: 'polygon' | 'gnosis' | 'fantom', - publicKey: Uint8Array, - account: IGenericAccount, - signature: Awaited>, - registrar: number, - timestampLock: number, - keyVersion: number -): Promise< - | { result: true; hash: string } - | { result: false; errorCode: 'ALREADY_EXISTS' } - | { result: false; errorCode: 'GENERIC_ERROR'; rawError: any } -> => { - const faucetUrl = `https://faucet.ylide.io/${faucetType}` - const response = await fetch(faucetUrl, { - method: 'POST', - body: JSON.stringify({ - address: account.address.toLowerCase(), - referrer: '0x0000000000000000000000000000000000000000', - payBonus: '0', - registrar, - timestampLock, - publicKey: '0x' + new SmartBuffer(publicKey).toHexString(), - keyVersion, - _r: signature.r, - _s: signature.s, - _v: signature.v, - }), - }) - const result = await response.json() - if (result && result.data && result.data.txHash) { - return { result: true, hash: result.data.txHash } - } else { - if (result.error === 'Already exists') { - return { result: false, errorCode: 'ALREADY_EXISTS' } + if (key) { + await keysRegistry.addRemotePublicKey(key) + return { result: true, hash: result.txHash } } else { - return { result: false, errorCode: 'GENERIC_ERROR', rawError: result } + return { result: false } } + } catch (err: any) { + console.error(`Something went wrong with key publishing`, err) + return { result: false } } } diff --git a/package.json b/package.json index 7162580..18f372e 100644 --- a/package.json +++ b/package.json @@ -23,9 +23,9 @@ "@mui/material": "^5.8.0", "@nft3sdk/did-manager": "^0.3.1", "@reduxjs/toolkit": "^1.8.2", - "@ylide/ethereum": "0.8.0-beta.27", - "@ylide/sdk": "0.8.0-beta.9", - "@ylide/smart-buffer": "0.0.11", + "@ylide/ethereum": "0.9.0-beta.12", + "@ylide/sdk": "0.9.0-beta.8", + "@ylide/smart-buffer": "0.0.17", "axios": "^0.27.2", "bignumber.js": "^9.1.0", "date-fns": "^2.29.3", diff --git a/yarn.lock b/yarn.lock index 8b54653..876d55a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -56,10 +56,10 @@ "@babel/helper-validator-identifier" "^7.19.1" to-fast-properties "^2.0.0" -"@datastructures-js/binary-search-tree@5.2.0": - version "5.2.0" - resolved "https://registry.npmjs.org/@datastructures-js/binary-search-tree/-/binary-search-tree-5.2.0.tgz#0f377944aa3c645cd7e4333770b91bafbec24637" - integrity sha512-35OWgLeG+mGv5cZkpFdwSGmzgPDbsGQCEgWMH5STpdLs6B5d+oXSHXexQwU0/D1E8OaTt0QqJZ1TdISgQGmQCg== +"@datastructures-js/binary-search-tree@5.3.1": + version "5.3.1" + resolved "https://registry.yarnpkg.com/@datastructures-js/binary-search-tree/-/binary-search-tree-5.3.1.tgz#37001fa1e54c8de2edb47e475ac95bf3f191f732" + integrity sha512-FgNcahe8U9yaofirAzXUs+gLhR+z6sQgAKnIjdGyBLLemFhrsqyJIHyWxnGWtekELbH9XAUJ8/WezNYNDtPetA== "@datastructures-js/linked-list@5.2.5": version "5.2.5" @@ -228,10 +228,10 @@ dns-packet "^5.2.1" ethers "^5.0.30" -"@ensdomains/ensjs@3.0.0-alpha.53": - version "3.0.0-alpha.53" - resolved "https://registry.npmjs.org/@ensdomains/ensjs/-/ensjs-3.0.0-alpha.53.tgz#c41f7bd9463f88b6366f5fca7fed808f7ae4bc15" - integrity sha512-vlyvyRoUrdm8OEsCOKR2yPWOO53XHVEFsMfBUkCfLBE5h0JQHXPCoyrUR7fZzL3O6s6nnj5NgHUMQto8YYsBnw== +"@ensdomains/ensjs@3.0.0-alpha.66": + version "3.0.0-alpha.66" + resolved "https://registry.yarnpkg.com/@ensdomains/ensjs/-/ensjs-3.0.0-alpha.66.tgz#b6740f8160b2907256990079fdeaed189fb911aa" + integrity sha512-bXaKh++A3Ui/JP2xG7mIjrMaEAfONf4lFBz9bEdGImjU/DVd7kdP0jCXH5nMTOKGo3VuvSybWths24aGWIzFLA== dependencies: "@adraffy/ens-normalize" "1.9.0" "@ensdomains/address-encoder" "^0.2.18" @@ -827,10 +827,10 @@ resolved "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-12.3.4.tgz#d28ea15a72cdcf96201c60a43e9630cd7fda168f" integrity sha512-DQ20JEfTBZAgF8QCjYfJhv2/279M6onxFjdG/+5B0Cyj00/EdBxiWb2eGGFgQhrBbNv/lsvzFbbi0Ptf8Vw/bg== -"@nft3sdk/client@0.2.4": - version "0.2.4" - resolved "https://registry.npmjs.org/@nft3sdk/client/-/client-0.2.4.tgz#d66aee69c2598a48abea489bd66b57e14affb605" - integrity sha512-tix+H6KGEieZvqTzderP89pblh+BcuYN6P+8KUNkGbz2SZpmcEmsQriJ2Yuqw46sgSa1O2IFnN+nAtte++vuDQ== +"@nft3sdk/client@0.3.1": + version "0.3.1" + resolved "https://registry.yarnpkg.com/@nft3sdk/client/-/client-0.3.1.tgz#13a28b1e41b7afa26c223eb729d84ffda9059f1d" + integrity sha512-hJ7ofpp367vg7aXNAkR0e7ultpx6f92JkAoMcBrX/VjFzskCD5Dny7tiDDPvy0RoD87l+RUm7OhEC4kG+RcdtA== dependencies: "@ethersproject/abstract-signer" "^5.6.2" "@ethersproject/basex" "^5.7.0" @@ -845,13 +845,13 @@ axios "^0.27.2" tweetnacl "^1.0.3" -"@nft3sdk/did-manager@^0.2.4": - version "0.2.4" - resolved "https://registry.npmjs.org/@nft3sdk/did-manager/-/did-manager-0.2.4.tgz#2a64c7be0a05147f619da5409b16905b80092072" - integrity sha512-bxLCUW9kwBkwlBx8RZ5pQnhxJV0j4UHcRP9WxC+ghy/EL5nx7Box1JBkZtmOI2G2jrwiMocbZKaRm7iygJE0hg== +"@nft3sdk/did-manager@^0.3.1": + version "0.3.1" + resolved "https://registry.yarnpkg.com/@nft3sdk/did-manager/-/did-manager-0.3.1.tgz#8cfe6c770036f5db86deeefa604782209c9f13bf" + integrity sha512-elLOAl29kVIAoGwo4PGOS+gaawbApA8jOJUbDGWuZAw4mxkjJxSn4aMxlkqc5Tj6sj9HwTeVT7h1GjWg3ttyXw== dependencies: "@ethersproject/providers" "^5.6.8" - "@nft3sdk/client" "0.2.4" + "@nft3sdk/client" "0.3.1" "@nodelib/fs.scandir@2.1.5": version "2.1.5" @@ -1106,49 +1106,51 @@ "@typescript-eslint/types" "5.57.0" eslint-visitor-keys "^3.3.0" -"@ylide/ethereum-contracts@0.8.0-beta.12": - version "0.8.0-beta.12" - resolved "https://registry.npmjs.org/@ylide/ethereum-contracts/-/ethereum-contracts-0.8.0-beta.12.tgz#481a3ae4faf5e5903e5e6be5f28443e0e394035e" - integrity sha512-LI7RC5XOxIfLKxW+EOfMkPaBI+Xad/auHTT2cw4ECap6bI0tSMUIW2pS91cff0ZHeldJ+rASD3Ddrh3txYlhtw== +"@ylide/ethereum-contracts@0.8.0-beta.20": + version "0.8.0-beta.20" + resolved "https://registry.yarnpkg.com/@ylide/ethereum-contracts/-/ethereum-contracts-0.8.0-beta.20.tgz#9b283e05a7dc2ee47d70e5e6d52b1df7aee3da3e" + integrity sha512-om92y7tbicpoPkKYtNVxyZI1uC0o2/4HfpX+M0IbcxCVeVT3t2YgSHK6fCtidhOYuEUm5MYcW0E3UUcn9q7ITQ== dependencies: "@ethersproject/abi" "5.7.0" "@ethersproject/providers" "5.7.2" ethers "5.7.2" -"@ylide/ethereum@0.8.0-beta.27": - version "0.8.0-beta.27" - resolved "https://registry.npmjs.org/@ylide/ethereum/-/ethereum-0.8.0-beta.27.tgz#66c8145d50c92c004e4516dec0c69712dd0a5e96" - integrity sha512-tcbFy9Lnhd72cIQYfkxl2OJKJTXl5AlqaP7AZpIxRvhbtw4lR5YaMMI38VAo5064WMqIqNjhfb6hniZkIqj3JA== +"@ylide/ethereum@0.9.0-beta.12": + version "0.9.0-beta.12" + resolved "https://registry.yarnpkg.com/@ylide/ethereum/-/ethereum-0.9.0-beta.12.tgz#b69093f7efdd906bf0ab21b121c8797093546441" + integrity sha512-4ZZJvBZMEMspMVf9WVJuLnL1IUy36A11wuYZw4f3gdwFyEzk5wj1B7C3qZnIjSQUF9Uams0e9U+V7s8wHPSwwQ== dependencies: - "@ensdomains/ensjs" "3.0.0-alpha.53" + "@ensdomains/ensjs" "3.0.0-alpha.66" "@ethersproject/abi" "5.7.0" "@ethersproject/abstract-provider" "5.7.0" + "@ethersproject/logger" "5.7.0" + "@ethersproject/properties" "5.7.0" "@ethersproject/providers" "5.7.2" - "@ylide/ethereum-contracts" "0.8.0-beta.12" - "@ylide/sdk" "0.8.0-beta.9" - "@ylide/smart-buffer" "0.0.11" + "@ylide/ethereum-contracts" "0.8.0-beta.20" + "@ylide/sdk" "0.9.0-beta.8" + "@ylide/smart-buffer" "0.0.17" ethers "5.7.2" - eventemitter3 "5.0.0" + eventemitter3 "5.0.1" semaphore-promise "1.4.1" -"@ylide/sdk@0.8.0-beta.9": - version "0.8.0-beta.9" - resolved "https://registry.npmjs.org/@ylide/sdk/-/sdk-0.8.0-beta.9.tgz#41c90ad07a1d5dfc2cfeb217cc4ab5d1fc11e985" - integrity sha512-s4hge5yMued5UMrDSrYvlYadJxAax+wFmshSn1xVWz4bKIS+8zbChWZlFTcxmFGnKwE6NR+yp7NKMl7b+pyQCw== +"@ylide/sdk@0.9.0-beta.8": + version "0.9.0-beta.8" + resolved "https://registry.yarnpkg.com/@ylide/sdk/-/sdk-0.9.0-beta.8.tgz#2310004809059ddff386b1ccf618c42e872c5949" + integrity sha512-mRgfqAdvIKI/WRCRKGi9vHxbGQv9D7BuyuYGbJkAk1HpQtR7UBOpSRtyF7Z3b2u5dSor24sUbVjpdu9MECFqBw== dependencies: - "@datastructures-js/binary-search-tree" "5.2.0" + "@datastructures-js/binary-search-tree" "5.3.1" "@datastructures-js/linked-list" "5.2.5" - "@ylide/smart-buffer" "0.0.11" - eventemitter3 "5.0.0" + "@ylide/smart-buffer" "0.0.17" + eventemitter3 "5.0.1" idb "7.1.1" js-sha256 "0.9.0" pako "2.1.0" tweetnacl "1.0.3" -"@ylide/smart-buffer@0.0.11": - version "0.0.11" - resolved "https://registry.npmjs.org/@ylide/smart-buffer/-/smart-buffer-0.0.11.tgz#1ecd9f33903002f3e3ec8e7faf7d88880b5c44e8" - integrity sha512-5o7sCNGhkmxlZo/89Aw+RdspcskQtt6t8ADU3gSlylalCn7l9ZVAeeSyMEUwWObjiyWF2yjyAt51UyWHa0QjLQ== +"@ylide/smart-buffer@0.0.17": + version "0.0.17" + resolved "https://registry.yarnpkg.com/@ylide/smart-buffer/-/smart-buffer-0.0.17.tgz#cfb23b7be4f98c86f721598b74ca8cb976d4aea1" + integrity sha512-qhlw+SwxV5s94BbxLW51EKbTXGJ1ZD29VBvAkYXBEkni72ocG6BwOzZm6yryWl1WjysCSsBPBzPJ5YV7Rc6kYw== "@zxing/text-encoding@0.9.0": version "0.9.0" @@ -2149,10 +2151,10 @@ ethers@5.7.2, ethers@^5.0.30, ethers@^5.7.0: "@ethersproject/web" "5.7.1" "@ethersproject/wordlists" "5.7.0" -eventemitter3@5.0.0: - version "5.0.0" - resolved "https://registry.npmjs.org/eventemitter3/-/eventemitter3-5.0.0.tgz#084eb7f5b5388df1451e63f4c2aafd71b217ccb3" - integrity sha512-riuVbElZZNXLeLEoprfNYoDSwTBRR44X3mnhdI1YcnENpWTCsTTVZ2zFuqQcpoyqPQIUXdiPEU0ECAq0KQRaHg== +eventemitter3@5.0.1: + version "5.0.1" + resolved "https://registry.yarnpkg.com/eventemitter3/-/eventemitter3-5.0.1.tgz#53f5ffd0a492ac800721bb42c66b841de96423c4" + integrity sha512-GWkBvjiSZK87ELrYOSESUYeVIc9mvLLf/nXalMOS5dYrgZq9o5OVkbZAVM06CVxYsCwH9BDZFPlQTlPA1j4ahA== evp_bytestokey@^1.0.3: version "1.0.3" From fd3224b5da8fe068ab62522c696469b0a177eb12 Mon Sep 17 00:00:00 2001 From: Danila Simonov Date: Thu, 21 Sep 2023 17:00:48 +0200 Subject: [PATCH 3/6] add faucet key --- domains/data/ylide/index.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/domains/data/ylide/index.ts b/domains/data/ylide/index.ts index 38067e7..3fe4cdb 100644 --- a/domains/data/ylide/index.ts +++ b/domains/data/ylide/index.ts @@ -138,6 +138,10 @@ const useYlideService = () => { genericFactory.wallet, { dev: false, //document.location.hostname === 'localhost', + faucet: { + registrar: 4, + apiKey: { type: 'client', key: 'cl75d3ca9c025bee7e' }, + }, onSwitchAccountRequest: () => {}, onNetworkSwitchRequest: async ( _reason: string, From 182032b7836ddea0b56a32849f13aec8785df56e Mon Sep 17 00:00:00 2001 From: Oleg Cherr Date: Tue, 24 Oct 2023 14:57:19 +0200 Subject: [PATCH 4/6] Update @ylide/ethereum --- package.json | 2 +- yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package.json b/package.json index 18f372e..3abbc9f 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "@mui/material": "^5.8.0", "@nft3sdk/did-manager": "^0.3.1", "@reduxjs/toolkit": "^1.8.2", - "@ylide/ethereum": "0.9.0-beta.12", + "@ylide/ethereum": "0.9.0-beta.13", "@ylide/sdk": "0.9.0-beta.8", "@ylide/smart-buffer": "0.0.17", "axios": "^0.27.2", diff --git a/yarn.lock b/yarn.lock index 876d55a..c5c78af 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1115,10 +1115,10 @@ "@ethersproject/providers" "5.7.2" ethers "5.7.2" -"@ylide/ethereum@0.9.0-beta.12": - version "0.9.0-beta.12" - resolved "https://registry.yarnpkg.com/@ylide/ethereum/-/ethereum-0.9.0-beta.12.tgz#b69093f7efdd906bf0ab21b121c8797093546441" - integrity sha512-4ZZJvBZMEMspMVf9WVJuLnL1IUy36A11wuYZw4f3gdwFyEzk5wj1B7C3qZnIjSQUF9Uams0e9U+V7s8wHPSwwQ== +"@ylide/ethereum@0.9.0-beta.13": + version "0.9.0-beta.13" + resolved "https://registry.yarnpkg.com/@ylide/ethereum/-/ethereum-0.9.0-beta.13.tgz#2bba3a43298c43bff6920f5eec331f5eb82444f3" + integrity sha512-uHWRwRdVbz4ExcH9MAalKLbLCihnBnk91PCTwIicXEmb899YAIQTmkL3OnFM3l1WxjPpPitzHd8IV9fMqQm1uQ== dependencies: "@ensdomains/ensjs" "3.0.0-alpha.66" "@ethersproject/abi" "5.7.0" From 07c83ba9763431dc021f080674916e85c5b9e775 Mon Sep 17 00:00:00 2001 From: Oleg Cherr Date: Tue, 24 Oct 2023 16:26:52 +0200 Subject: [PATCH 5/6] Fix deps --- UI/profile-board/Feed/index.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/UI/profile-board/Feed/index.tsx b/UI/profile-board/Feed/index.tsx index 21d702d..8c6d8ac 100644 --- a/UI/profile-board/Feed/index.tsx +++ b/UI/profile-board/Feed/index.tsx @@ -245,7 +245,7 @@ const NewPostForm: FC<{ onPost: () => void }> = ({ onPost }) => { sendingAgentVersion: { major: 1, minor: 0, patch: 0 }, subject: cleanTitle, content: YMF.fromPlainText(cleanContent), - attachments: [], // TODO? + attachments: [], extraBytes: new Uint8Array(0), extraJson: {}, }) @@ -267,7 +267,7 @@ const NewPostForm: FC<{ onPost: () => void }> = ({ onPost }) => { .finally(() => { setSending(false) }) - }, [cleanTitle, cleanContent, broadcastMessage, onPost]) + }, [hasData, cleanTitle, cleanContent, broadcastMessage, onPost]) return (
From 2aa8fe486f3845eae33391f5581e5bbc07086256 Mon Sep 17 00:00:00 2001 From: Oleg Cherr Date: Tue, 24 Oct 2023 16:33:09 +0200 Subject: [PATCH 6/6] Load balances in background --- UI/layouts/Header/Actions/ChooseEvmNetwork/index.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/UI/layouts/Header/Actions/ChooseEvmNetwork/index.tsx b/UI/layouts/Header/Actions/ChooseEvmNetwork/index.tsx index 9004b3b..17dbf54 100644 --- a/UI/layouts/Header/Actions/ChooseEvmNetwork/index.tsx +++ b/UI/layouts/Header/Actions/ChooseEvmNetwork/index.tsx @@ -20,7 +20,7 @@ const ChooseEvmNetwork: FC = () => { const [balances, setBalances] = useState({}) useEffect(() => { ;(async () => { - if (chooseEvmNetworkDialog.visible && account) { + if (account) { setBalances(await getBalancesOf(account)) setLoading(false) } else { @@ -28,7 +28,7 @@ const ChooseEvmNetwork: FC = () => { setLoading(true) } })() - }, [account, chooseEvmNetworkDialog.visible, getBalancesOf]) + }, [account, getBalancesOf]) return (