Address

Overview

Represents a quantum-resistant address in OP_NET's hybrid cryptographic architecture. An Address internally stores the SHA256 hash of an ML-DSA (quantum) public key as its primary 32-byte content and maintains a classical Bitcoin tweaked public key separately. This dual-key design enables quantum-resistant addressing while preserving full compatibility with traditional Bitcoin address formats (P2TR, P2WPKH, P2PKH, P2SH-P2WPKH, P2WDA, and P2OP).

The Address class extends Uint8Array (always 32 bytes) and implements Disposable for secure memory cleanup.

The full source code is available on GitHub at Address.ts.

Critical Warning

Address.fromString() does NOT accept bech32 addresses. You cannot pass bc1q... or bc1p... strings to this method. It requires two hexadecimal public key parameters: the first is the 32-byte SHA256 hash of the ML-DSA public key, and the second is the 33-byte (or 65-byte) Bitcoin compressed (or uncompressed) public key. Both must be 0x-prefixed hex strings.

If you have a bech32 address and need to create an Address object, you must first resolve it to its public keys using a provider (e.g., await provider.getPublicKeyInfo("bc1q...")).

Lazy Loading Architecture

The Address class uses lazy evaluation for expensive EC operations. When a classical public key is provided, it is stored but not processed until a method that requires it is called (e.g., p2tr(), p2wpkh(), tweakedPublicKeyToBuffer()). This means:

  • Creating an Address with both keys is cheap (no EC math at construction time).
  • Methods that only use the ML-DSA hash (e.g., toHex(), p2op(), toBigInt()) never trigger legacy key processing.
  • The first call to a method requiring the classical key triggers the deferred processing. Subsequent calls use cached results.

This design is critical for performance in hot paths like block parsing, where thousands of addresses may be created but only a fraction require classical key operations.

Import

import { Address } from '@btc-vision/transaction';

Constructor

constructor()

Static Methods

fromString()
dead()
wrap()
fromBigInt()
fromUint64Array()
uncompressedToCompressed()

Instance Methods

toHex()
tweakedToHex()
toBuffer()
originalPublicKeyBuffer()
tweakedPublicKeyToBuffer()
toUncompressedHex()
toUncompressedBuffer()
toHybridPublicKeyHex()
toHybridPublicKeyBuffer()
toTweakedHybridPublicKeyHex()
toTweakedHybridPublicKeyBuffer()
p2tr()
p2wpkh()
p2pkh()
p2shp2wpkh()
p2wda()
p2op()
p2pk()
set()
equals()
lessThan()
greaterThan()
toBigInt()
tweakedToBigInt()
toUint64Array()
isDead()
isValidLegacyPublicKey()
toString()
toJSON()
toCSV()
toCSVTweaked()
toCSVP2MR()
[Symbol.dispose]()

Properties

originalPublicKey
mldsaPublicKey
originalMDLSAPublicKey
mldsaLevel