mirror of
https://github.com/mempool/mempool.git
synced 2025-03-15 12:20:28 +01:00
P2A address format decoding
This commit is contained in:
parent
74fa3c7eb1
commit
5b331c144b
1 changed files with 10 additions and 1 deletions
|
@ -988,7 +988,7 @@ function scriptPubKeyToAddress(scriptPubKey: string, network: string): { address
|
||||||
}
|
}
|
||||||
// anchor
|
// anchor
|
||||||
if (scriptPubKey === '51024e73') {
|
if (scriptPubKey === '51024e73') {
|
||||||
return { address: 'bc1pfeessrawgf', type: 'anchor' };
|
return { address: p2a(network), type: 'anchor' };
|
||||||
}
|
}
|
||||||
// op_return
|
// op_return
|
||||||
if (/^6a/.test(scriptPubKey)) {
|
if (/^6a/.test(scriptPubKey)) {
|
||||||
|
@ -1048,6 +1048,15 @@ function p2tr(pubKeyHash: string, network: string): string {
|
||||||
return bech32Address;
|
return bech32Address;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function p2a(network: string): string {
|
||||||
|
const pubkeyHashArray = hexStringToUint8Array('4e73');
|
||||||
|
const hrp = ['testnet', 'testnet4', 'signet'].includes(network) ? 'tb' : 'bc';
|
||||||
|
const version = 1;
|
||||||
|
const words = [version].concat(toWords(pubkeyHashArray));
|
||||||
|
const bech32Address = bech32Encode(hrp, words, 0x2bc830a3);
|
||||||
|
return bech32Address;
|
||||||
|
}
|
||||||
|
|
||||||
// base58 encoding
|
// base58 encoding
|
||||||
function base58Encode(data: Uint8Array): string {
|
function base58Encode(data: Uint8Array): string {
|
||||||
const BASE58_ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
const BASE58_ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
||||||
|
|
Loading…
Add table
Reference in a new issue