From 5b331c144ba2498df23969a97fc257f227f1f9d8 Mon Sep 17 00:00:00 2001 From: natsoni Date: Wed, 8 Jan 2025 15:25:19 +0100 Subject: [PATCH] P2A address format decoding --- frontend/src/app/shared/transaction.utils.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/frontend/src/app/shared/transaction.utils.ts b/frontend/src/app/shared/transaction.utils.ts index af1412838..b33d88c2f 100644 --- a/frontend/src/app/shared/transaction.utils.ts +++ b/frontend/src/app/shared/transaction.utils.ts @@ -988,7 +988,7 @@ function scriptPubKeyToAddress(scriptPubKey: string, network: string): { address } // anchor if (scriptPubKey === '51024e73') { - return { address: 'bc1pfeessrawgf', type: 'anchor' }; + return { address: p2a(network), type: 'anchor' }; } // op_return if (/^6a/.test(scriptPubKey)) { @@ -1048,6 +1048,15 @@ function p2tr(pubKeyHash: string, network: string): string { 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 function base58Encode(data: Uint8Array): string { const BASE58_ALPHABET = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";