Type Method
taggedHash(tag:data:)
Computes a BIP-340 tagged hash SHA256(SHA256(tag) || SHA256(tag) || data) via upstream secp256k1_tagged_sha256, producing a 32-byte SHA256Digest.
- iOS 13.0+
- macCatalyst 13.0+
- macOS 10.15+
- tvOS 13.0+
- visionOS 1.0+
- watchOS 6.0+
static func taggedHash<D>(tag: D, data: D) -> SHA256Digest where D : DataProtocol
Parameters
-
tag
-
The domain-separation tag bytes; repeated twice before data as specified by BIP-340.
-
data
-
The message bytes to hash after the two tag hashes.
Return Value
A 32-byte SHA256Digest.
Mentioned In
Discussion
Tagged hashes prevent cross-protocol attacks by domain-separating hashes with an application-specific tag. The construction is defined in BIP-340 § Design and reused throughout the Bitcoin Taproot stack:
"BIP0340/challenge" for the Schnorr signing challenge
"BIP0340/nonce" for BIP-340 nonce derivation
"BIP0340/aux" for auxiliary-randomness mixing
"TapLeaf", "TapBranch", "TapTweak", "TapSighash" for BIP-341 Taproot
Because the upstream SHA-256 implementation is shared between this Swift surface and libsecp256k1’s internal signing / verification code, the tag-hash output here is byte-for-byte identical to what a libsecp256k1 signer would compute internally for the same (tag, data) pair.