Skip to content

Commit

Permalink
fixes related to metadata backends
Browse files Browse the repository at this point in the history
  • Loading branch information
chaitanyapotti committed Aug 21, 2023
1 parent 15a5ee6 commit 48ff75d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
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
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) {
finalEvmAddress = generateAddressFromPubKey(this.ec, finalPubKey.getX(), finalPubKey.getY());
log.debug("> torus.js/retrieveShares", { finalEvmAddress });
}

return {
finalKeyData: {
evmAddress: finalEvmAddress,
Expand Down

0 comments on commit 48ff75d

Please sign in to comment.