Resolve "Protocol Parsing: BIP21/PayPro, bch-mnemonic, etc"

This commit is contained in:
2025-07-29 03:36:12 +00:00
committed by Jim Hamill
parent bb326d5b3b
commit 46baf8702d
6 changed files with 584 additions and 7 deletions
+21 -7
View File
@@ -8,18 +8,26 @@ import {
decodeCashAddress,
disassembleBytecodeBCH,
encodeBase58AddressFormat,
encodeCashAddress,
sha256,
ripemd160,
encodeCashAddressNonStandard,
cashAddressTypeToTypeBits,
} from '@bitauth/libauth';
import type { KnownAddressTypeContents } from '@bitauth/libauth';
export type AddressType = 'P2PK' | 'P2PKH' | 'P2SH20' | 'P2SH32';
export type AddressNetworkPrefix =
| 'bitcoincash'
| 'bchtest'
| 'bchreg'
| (string & {});
export const DEFAULT_ADDRESS_PREFIXES = [
'',
'bitcoincash',
'bch',
'bchtest',
'bchreg',
];
@@ -441,7 +449,7 @@ export class Address {
* @returns {string} The address in CashAddr format.
*/
public toCashAddr(
networkPrefix: 'bitcoincash' | 'bchtest' | 'bchreg' = 'bitcoincash',
networkPrefix: AddressNetworkPrefix = 'bitcoincash',
): string {
// Define the encode type in advance.
let encodeType: 'p2pkh' | 'p2sh';
@@ -461,10 +469,13 @@ export class Address {
);
}
// Get the type bits for the encode type.
const typeBits = cashAddressTypeToTypeBits[encodeType];
// NOTE: This function will throw if the payload is invalid.
return encodeCashAddress({
return encodeCashAddressNonStandard({
prefix: networkPrefix,
type: encodeType,
typeBits,
payload: this.addressContents.payload,
}).address;
}
@@ -479,7 +490,7 @@ export class Address {
* @returns {string} The address in Token Address format.
*/
public toTokenAddress(
networkPrefix: 'bitcoincash' | 'bchtest' | 'bchreg' = 'bitcoincash',
networkPrefix: AddressNetworkPrefix = 'bitcoincash',
): string {
// Define the encode type in advance.
let encodeType: 'p2pkhWithTokens' | 'p2shWithTokens';
@@ -499,10 +510,13 @@ export class Address {
);
}
// Get the type bits for the encode type.
const typeBits = cashAddressTypeToTypeBits[encodeType];
// NOTE: This function will throw if the payload is invalid.
return encodeCashAddress({
return encodeCashAddressNonStandard({
prefix: networkPrefix,
type: encodeType,
typeBits,
payload: this.addressContents.payload,
}).address;
}