Skip to content

Commit

Permalink
fix: display all types of btc pox addresses
Browse files Browse the repository at this point in the history
  • Loading branch information
friedger committed May 16, 2023
1 parent bf08216 commit d16a023
Showing 1 changed file with 2 additions and 21 deletions.
23 changes: 2 additions & 21 deletions app/utils/stacking.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,13 @@
import { NETWORK } from '@constants/index';
import { sha256 } from '@noble/hashes/sha256';
import { base58check } from '@scure/base';
import { AddressHashMode } from '@stacks/transactions';
import BN from 'bn.js';

const poxKeyToVersionBytesMap: Record<'mainnet' | 'testnet', any> = {
mainnet: {
[AddressHashMode.SerializeP2PKH]: 0x00,
[AddressHashMode.SerializeP2SH]: 0x05,
},
testnet: {
[AddressHashMode.SerializeP2PKH]: 0x6f,
[AddressHashMode.SerializeP2SH]: 0xc4,
},
};
import { poxAddressToBtcAddress } from '@stacks/stacking';

interface ConvertToPoxAddressBtc {
version: Uint8Array;
hashbytes: Uint8Array;
}
export function convertPoxAddressToBtc(network: 'mainnet' | 'testnet') {
return ({ version, hashbytes }: ConvertToPoxAddressBtc) => {
const ver = new BN(version).toNumber() as AddressHashMode;
if (ver === AddressHashMode.SerializeP2WPKH || ver === AddressHashMode.SerializeP2WSH)
return null;
return base58check(sha256).encode(
Buffer.concat([Buffer.from([poxKeyToVersionBytesMap[network][ver]]), hashbytes])
);
return poxAddressToBtcAddress(version[0], hashbytes, network);
};
}

Expand Down

0 comments on commit d16a023

Please sign in to comment.