Skip to content

Commit

Permalink
Update: Disable cache for get pubkey from oasis
Browse files Browse the repository at this point in the history
  • Loading branch information
toandq2009 committed Sep 30, 2024
1 parent 57dc5fd commit 5c77c2d
Showing 1 changed file with 24 additions and 15 deletions.
39 changes: 24 additions & 15 deletions packages/background/src/keyring/keyring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -953,21 +953,25 @@ export class KeyRing {
})();

if (coinType === 474) {
const bip44HDPath = KeyRing.getKeyStoreBIP44Path(this.keyStore);
const path = `m/44'/474'/${bip44HDPath.account}'/${bip44HDPath.change}/${bip44HDPath.addressIndex}`;
const pubKeyIdentity = `pubKey-${KeyRing.getKeyStoreId(
this.keyStore
)}-${path}`;

const pubKeyGet = (await this.kvStore.get(pubKeyIdentity)) as string;
let signerPublicKey: Uint8Array;
if (pubKeyGet) {
signerPublicKey = Uint8Array.from(Buffer.from(pubKeyGet, "base64"));
} else {
signerPublicKey = await this.loadPublicKeyOasis();
var encodePublicKey = Buffer.from(signerPublicKey).toString("base64");
await this.kvStore.set(pubKeyIdentity, encodePublicKey);
}
// const bip44HDPath = KeyRing.getKeyStoreBIP44Path(this.keyStore);
// console.log(bip44HDPath,"bip44HDPath");
// console.log(KeyRing.getKeyStoreId(
// this.keyStore
// ),"key store ID")
// const path = `m/44'/474'/${bip44HDPath.account}'/${bip44HDPath.change}/${bip44HDPath.addressIndex}`;
// const pubKeyIdentity = `pubKey-${KeyRing.getKeyStoreId(
// this.keyStore
// )}-${path}`;
// console.log(pubKeyIdentity,this.keyStore.type,"pubKeyIdentity");
// const pubKeyGet = (await this.kvStore.get(pubKeyIdentity)) as string;
// let signerPublicKey: Uint8Array;
// if (pubKeyGet) {
// signerPublicKey = Uint8Array.from(Buffer.from(pubKeyGet, "base64"));
// } else {
const signerPublicKey = await this.loadPublicKeyOasis();
// var encodePublicKey = Buffer.from(signerPublicKey).toString("base64");
// await this.kvStore.set(pubKeyIdentity, encodePublicKey);
// }

const addressUint8Array = await oasis.staking.addressFromPublicKey(
signerPublicKey
Expand Down Expand Up @@ -1634,6 +1638,11 @@ export class KeyRing {
"Key store type is mnemonic and it is unlocked. But, mnemonic is not loaded unexpectedly"
);
}
if (this.type !== "mnemonic") {
throw new Error(
"Key store type is mnemonic and it is unlocked. But, mnemonic is not loaded unexpectedly"
);
}
const signer = await oasis.hdkey.HDKey.getAccountSigner(this.mnemonic, 0);
return signer.publicKey;
}
Expand Down

0 comments on commit 5c77c2d

Please sign in to comment.