Skip to content

Commit

Permalink
refactor(extension,cardano,staking): remove redundant code and fix er…
Browse files Browse the repository at this point in the history
…rors
  • Loading branch information
przemyslaw-wlodek committed Jan 24, 2025
1 parent 1047ddf commit 1f76bc1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export class ExtensionDocumentStore<T extends {}> extends ExtensionStore impleme

/**
* @param docId unique document id within the store, used as extension storage key
* @param logger
*/
constructor(protected docId: string, logger: Logger) {
super(contextLogger(logger, `ExtensionStore(${docId})`));
Expand Down
16 changes: 10 additions & 6 deletions packages/cardano/src/wallet/lib/cardano-wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import { WsProvider } from '@cardano-sdk/cardano-services-client';
let bip32Ed25519: Promise<Crypto.SodiumBip32Ed25519> | undefined;

export const getBip32Ed25519 = async (): Promise<Crypto.SodiumBip32Ed25519> =>
bip32Ed25519 || (bip32Ed25519 = await Crypto.SodiumBip32Ed25519.create());
bip32Ed25519 || (bip32Ed25519 = Crypto.SodiumBip32Ed25519.create());

export type KeyAgentsByChain = Record<ChainName, { keyAgentData: KeyManagement.SerializableKeyAgentData }>;

Expand Down Expand Up @@ -96,7 +96,11 @@ export const restoreWallet = async (
keyAgentData: KeyManagement.SerializableKeyAgentData,
getPassword: () => Promise<Uint8Array>
): Promise<{ keyAgent: KeyManagement.KeyAgent }> => {
const keyAgent = await restoreKeyAgent(keyAgentData, { logger: console, bip32Ed25519 }, getPassword);
const keyAgent = await restoreKeyAgent(
keyAgentData,
{ logger: console, bip32Ed25519: await getBip32Ed25519() },
getPassword
);
return { keyAgent };
};

Expand Down Expand Up @@ -128,7 +132,7 @@ export const validateWalletPassword = async (
// Not needed for this
{
logger: console,
bip32Ed25519
bip32Ed25519: await getBip32Ed25519()
},
getPassword
);
Expand Down Expand Up @@ -160,7 +164,7 @@ export const validateWalletMnemonic = async (
},
{
logger: console,
bip32Ed25519
bip32Ed25519: await getBip32Ed25519()
}
);

Expand All @@ -170,15 +174,15 @@ export const validateWalletMnemonic = async (
return originalPublicKey === validatingPublicKey;
};

export const createKeyAgent = (
export const createKeyAgent = async (
keyAgentData: KeyManagement.SerializableKeyAgentData,
getPassword: () => Promise<Uint8Array>
): Promise<KeyManagement.KeyAgent> =>
restoreKeyAgent(
keyAgentData,
{
logger: console,
bip32Ed25519
bip32Ed25519: await getBip32Ed25519()
},
getPassword
);

0 comments on commit 1f76bc1

Please sign in to comment.