Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes related to metadata backends #117

Merged
merged 3 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/helpers/metadataUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ export function generateMetadataParams(ecCurve: ec, serverTimeOffset: number, me
};
const sig = key.sign(keccak256(Buffer.from(stringify(setData), "utf8")).slice(2));
return {
pub_key_X: key.getPublic().getX().toString("hex", 64),
pub_key_Y: key.getPublic().getY().toString("hex", 64),
pub_key_X: key.getPublic().getX().toString("hex"), // DO NOT PAD THIS. BACKEND DOESN'T
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should update backend isn't it? Coz there might still be 0's in front which can get lost on the network.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't update backend due to legacy reasons.
0's don't get lost because we always transmit strings across network

pub_key_Y: key.getPublic().getY().toString("hex"), // DO NOT PAD THIS. BACKEND DOESN'T
set_data: setData,
signature: Buffer.from(sig.r.toString(16, 64) + sig.s.toString(16, 64) + new BN("").toString(16, 2), "hex").toString("base64"),
};
Expand Down
13 changes: 9 additions & 4 deletions src/torus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,10 +477,6 @@ class Torus {

const oAuthKeyAddress = generateAddressFromPrivKey(this.ec, oAuthKey);

// deriving address from pub key coz pubkey is always available
// but finalPrivKey won't be available for v2 user upgraded to 2/n
const finalEvmAddress = generateAddressFromPubKey(this.ec, finalPubKey.getX(), finalPubKey.getY());
log.debug("> torus.js/retrieveShares", { finalEvmAddress });
let finalPrivKey = ""; // it is empty for v2 user upgraded to 2/n
if (typeOfUser === "v1" || (typeOfUser === "v2" && metadataNonce.gt(new BN(0)))) {
const privateKeyWithNonce = oAuthKey.add(metadataNonce).umod(this.ec.curve.n);
Expand All @@ -493,6 +489,15 @@ class Torus {
} else if (typeOfUser === "v2") {
isUpgraded = metadataNonce.eq(new BN("0"));
}

// deriving address from pub key coz pubkey is always available
// but finalPrivKey won't be available for v2 user upgraded to 2/n
let finalEvmAddress = "";
if (finalPubKey) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in wht scenario finalPubKey won't be available ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the bug scenario where metadata doesn't come

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it should throw when metadata is missing right?

finalEvmAddress = generateAddressFromPubKey(this.ec, finalPubKey.getX(), finalPubKey.getY());
log.debug("> torus.js/retrieveShares", { finalEvmAddress });
}

return {
finalKeyData: {
evmAddress: finalEvmAddress,
Expand Down
Loading