Skip to content

Commit 3ce4b75

Browse files
committed
refactor(multisig): improve fallback logic for deriving reward addresses
- Updated the fallback mechanism in the multisig import validation to derive reward addresses directly from script key hashes when no matching stake key is found. - Enhanced error handling to ensure robustness during address resolution attempts, maintaining consistency in return values.
1 parent ecbdae9 commit 3ce4b75

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/utils/validateMultisigImport.ts

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ export async function validateMultisigImportPayload(payload: unknown): Promise<V
459459
// Fallback: use the keyHash itself where no stake key was provided
460460
return sig.toLowerCase();
461461
});
462-
// Build stakeAddressesUsed positionally: reward addresses for matched keys, else raw key hash placeholders
462+
// Build stakeAddressesUsed positionally: reward addresses for matched keys, else derive from script key hash
463463
stakeAddressesUsedFinal = stakeSigKeyHashes.map((sig) => {
464464
const m = lowerMatches.get(sig.toLowerCase());
465465
const providedStakeHex = m?.signerStakeKey;
@@ -481,8 +481,22 @@ export async function validateMultisigImportPayload(payload: unknown): Promise<V
481481
// If we couldn't build a valid reward address, fall back to the hex itself
482482
return hex;
483483
}
484-
// No match: use the script key hash in this position
485-
return sig.toLowerCase();
484+
// No match: attempt to build a reward address directly from the script key hash
485+
const hex = sig.toLowerCase();
486+
const tryNetworks: Array<0 | 1> = network === undefined ? [0, 1] : [network as 0 | 1];
487+
for (const netId of tryNetworks) {
488+
try {
489+
const addr = serializeRewardAddress(hex, false, netId);
490+
const resolved = stakeKeyHash(addr)?.toLowerCase();
491+
if (resolved === hex) {
492+
return addr;
493+
}
494+
} catch {
495+
// continue to next
496+
}
497+
}
498+
// If unable to derive, fall back to the raw key hash
499+
return hex;
486500
});
487501
}
488502

0 commit comments

Comments
 (0)