Skip to content

Commit d2a7b2e

Browse files
asimm241zone117x
authored andcommitted
refactor: improve publicKeyToBitcoinAddress
1 parent 342cce9 commit d2a7b2e

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/api/routes/rosetta/construction.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ export function createRosettaConstructionRouter(db: DataStore): RouterWithAsync
3030

3131
try {
3232
const btcAddress = publicKeyToBitcoinAddress(publicKey.hex_bytes, network.network);
33+
if (btcAddress === undefined) {
34+
res.status(400).json(RosettaErrors.invalidPublicKey);
35+
return;
36+
}
3337
const stxAddress = bitcoinAddressToSTXAddress(btcAddress);
3438

3539
const response: RosettaConstructionDeriveResponse = {

src/rosetta-helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ function makePoisonMicroblockOperation(tx: DbMempoolTx | DbTx, index: number): R
174174
return sender;
175175
}
176176

177-
export function publicKeyToBitcoinAddress(publicKey: string, network: string): string {
177+
export function publicKeyToBitcoinAddress(publicKey: string, network: string): string | undefined {
178178
const publicKeyBuffer = Buffer.from(publicKey, 'hex');
179179

180180
let btcNetwork: btc.Network;
@@ -188,7 +188,7 @@ export function publicKeyToBitcoinAddress(publicKey: string, network: string): s
188188
pubkey: publicKeyBuffer,
189189
network: btcNetwork,
190190
});
191-
return address.address ? address.address : '';
191+
return address.address;
192192
}
193193

194194
export function bitcoinAddressToSTXAddress(btcAddress: string): string {

0 commit comments

Comments
 (0)