chore(script): implement `is_p2a` for `ScriptPubKeyExt`
What changed, and why it matters
This commit adds a new helper method called is_p2a that lets the library recognize a specific modern Bitcoin address/output type known as P2A (Pay-to-Anchor). It is a pure feature addition with no bug fix, no behavior change to existing code, and no security relevance visible in the commit.
No security action required. Treat as a routine library feature addition.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The patch adds an is_p2a() method to the ScriptPubKeyExt extension trait in bitcoin/src/blockdata/script/borrowed.rs. The method checks whether a scriptPubKey is exactly the P2A (Pay-to-Anchor) witness program: length 4, witness version 1, a 2-byte data push, and the P2A_PROGRAM bytes. No existing logic is modified; no unsafe code, no parsing changes, and no consensus or standardness rules are altered.
Changed components
bitcoin/src/blockdata/script/borrowed.rsScriptPubKeyExt traitInspect captured patch +10 / −0
diff --git a/bitcoin/src/blockdata/script/borrowed.rs b/bitcoin/src/blockdata/script/borrowed.rs
index f4cbd79b..c6eae74a 100644
--- a/bitcoin/src/blockdata/script/borrowed.rs
+++ b/bitcoin/src/blockdata/script/borrowed.rs
@@ -21,6 +21,7 @@ use crate::policy::{DUST_RELAY_TX_FEE, MAX_OP_RETURN_RELAY};
use crate::prelude::{sink, String, ToString};
use crate::script::{self, ScriptPubKeyBufExt as _};
use crate::taproot::{LeafVersion, TapLeafHash, TapNodeHash};
+use crate::witness_program::P2A_PROGRAM;
use crate::{internal_macros, Amount, FeeRate, ScriptPubKeyBuf, WitnessScriptBuf};
internal_macros::define_extension_trait! {
@@ -395,6 +396,15 @@ internal_macros::define_extension_trait! {
&& self.as_bytes()[1] == OP_PUSHBYTES_32.to_u8()
}
+ /// Checks whether a script pubkey is a P2A output.
+ #[inline]
+ fn is_p2a(&self) -> bool {
+ self.len() == 4
+ && self.witness_version() == Some(WitnessVersion::V1)
+ && self.as_bytes()[1] == OP_PUSHBYTES_2.to_u8()
+ && self.as_bytes()[2..] == P2A_PROGRAM
+ }
+
/// Check if this is a consensus-valid OP_RETURN output.
///
/// To validate if the OP_RETURN obeys Bitcoin Core's current standardness policy, use
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.