Skip to content

Commit

Permalink
get or set nonce, instead of just getting
Browse files Browse the repository at this point in the history
  • Loading branch information
himanshu committed May 13, 2024
1 parent 87f5251 commit 628bffb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/helpers/metadataUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ export async function getNonce(
return getOrSetNonce(legacyMetadataHost, ecCurve, serverTimeOffset, X, Y, privKey, true);
}

export async function getSapphireMetadataNonce(X: string, Y: string): Promise<GetOrSetNonceResult> {
export async function getOrSetSapphireMetadataNonce(X: string, Y: string): Promise<GetOrSetNonceResult> {
const data = {
pub_key_X: X,
pub_key_Y: Y,
key_type: "secp256k1",
set_data: { operation: "get_nonce" },
set_data: { operation: "getOrSetNonce" },
};
return post<GetOrSetNonceResult>(`${SAPPHIRE_METADATA_URL}/get_or_set_nonce`, data, undefined, { useAPIKey: true });
}
6 changes: 3 additions & 3 deletions src/helpers/nodeUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { Some } from "../some";
import { calculateMedian, kCombinations, normalizeKeysResult, thresholdSame } from "./common";
import { generateAddressFromPrivKey, generateAddressFromPubKey, keccak256 } from "./keyUtils";
import { lagrangeInterpolation } from "./langrangeInterpolatePoly";
import { decryptNodeData, getMetadata, getOrSetNonce, getSapphireMetadataNonce } from "./metadataUtils";
import { decryptNodeData, getMetadata, getOrSetNonce, getOrSetSapphireMetadataNonce } from "./metadataUtils";

export const GetPubKeyOrKeyAssign = async (params: {
endpoints: string[];
Expand Down Expand Up @@ -91,7 +91,7 @@ export const GetPubKeyOrKeyAssign = async (params: {

// if nonce result is not returned by nodes, fetch directly from metadata
if (!nonceResult) {
const metadataNonceResult = await getSapphireMetadataNonce(keyResult.keys[0].pub_key_X, keyResult.keys[0].pub_key_Y);
const metadataNonceResult = await getOrSetSapphireMetadataNonce(keyResult.keys[0].pub_key_X, keyResult.keys[0].pub_key_Y);
// rechecking nonceResult to avoid promise race condition.
if (!nonceResult && metadataNonceResult) {
nonceResult = metadataNonceResult;
Expand Down Expand Up @@ -378,7 +378,7 @@ export async function retrieveOrImportShare(params: {
// if both thresholdNonceData and extended_verifier_id are not available
// then we need to throw other wise address would be incorrect.
if (!thresholdNonceData && !verifierParams.extended_verifier_id && !LEGACY_NETWORKS_ROUTE_MAP[network as TORUS_LEGACY_NETWORK_TYPE]) {
const metadataNonceResult = await getSapphireMetadataNonce(thresholdPublicKey.X, thresholdPublicKey.Y);
const metadataNonceResult = await getOrSetSapphireMetadataNonce(thresholdPublicKey.X, thresholdPublicKey.Y);
// rechecking nonceResult to avoid promise race condition.
if (metadataNonceResult && !thresholdNonceData) {
thresholdNonceData = metadataNonceResult;
Expand Down

0 comments on commit 628bffb

Please sign in to comment.