From b8f408f52fff01dd0552cfd4d1d0b762b104e4fb Mon Sep 17 00:00:00 2001 From: zzggo Date: Tue, 3 Dec 2024 16:07:34 +1100 Subject: [PATCH 1/2] fixed: finding address with weight --- src/ui/utils/modules/findAddressWithPK.tsx | 24 ++++++++++++---------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/ui/utils/modules/findAddressWithPK.tsx b/src/ui/utils/modules/findAddressWithPK.tsx index 120ba664..ca604235 100644 --- a/src/ui/utils/modules/findAddressWithPK.tsx +++ b/src/ui/utils/modules/findAddressWithPK.tsx @@ -1,5 +1,5 @@ -import { pk2PubKey, seed2PubKey, seed2PubKeyTemp } from './passkey'; import { findAddressWithKey } from './findAddressWithPubKey'; +import { pk2PubKey, seed2PubKey, seed2PubKeyTemp } from './passkey'; const findAddress = async (pubKTuple, address) => { const { P256, SECP256K1 } = pubKTuple; @@ -9,18 +9,20 @@ const findAddress = async (pubKTuple, address) => { const pS = sepc256k1Accounts.map((s) => ({ ...s, pk: SECP256K1.pk })); const accounts = pA.concat(pS); - // console.log('accounts 222 ==>', accounts); - if (accounts[0].weight < 1000) { - return null; - } if (!accounts || accounts.length === 0) { - SECP256K1['weight'] = 1000; - SECP256K1['hashAlgo'] = 'SHA2_256'; - SECP256K1['signAlgo'] = 'ECDSA_secp256k1'; - SECP256K1['keyIndex'] = 0; - return [SECP256K1]; + return [ + { + ...SECP256K1, + weight: 1000, + hashAlgo: 'SHA2_256', + signAlgo: 'ECDSA_secp256k1', + keyIndex: 0, + }, + ]; } - return accounts; + + const account = accounts.find((account) => account.weight >= 1000); + return account ? [account] : null; }; export const findAddressWithPK = async (pk, address) => { From 888ece6b4b90fd88456eeb0bad6b89db8b0cdfb5 Mon Sep 17 00:00:00 2001 From: zzggo Date: Tue, 3 Dec 2024 16:34:56 +1100 Subject: [PATCH 2/2] fixed: result error handling --- src/background/service/userWallet.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/background/service/userWallet.ts b/src/background/service/userWallet.ts index 2ac6545b..f71095cc 100644 --- a/src/background/service/userWallet.ts +++ b/src/background/service/userWallet.ts @@ -314,7 +314,12 @@ class UserWallet { if (!result[0].pubK) { console.log('No result found, creating a new result object'); // Create a new result object with extension default setting - result = await findAddressWithPK(keys.pk, ''); + const foundResult = await findAddressWithPK(keys.pk, ''); + if (!foundResult) { + throw new Error('Unable to find a address with the provided PK. Aborting login.'); + } + + result = foundResult; } const app = getApp(process.env.NODE_ENV!); const auth = getAuth(app);