Skip to content

Commit

Permalink
Merge pull request #246 from Outblock/fixed-nufi-account-import
Browse files Browse the repository at this point in the history
fixed: finding address with weight
  • Loading branch information
zzggo authored Dec 3, 2024
2 parents 4aa79af + 888ece6 commit 6f85fa0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
7 changes: 6 additions & 1 deletion src/background/service/userWallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
24 changes: 13 additions & 11 deletions src/ui/utils/modules/findAddressWithPK.tsx
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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) => {
Expand Down

0 comments on commit 6f85fa0

Please sign in to comment.