Try it Live
Run Signature examples in the interactive playground
BrandedSignature
Branded Uint8Array type for cryptographic signatures with algorithm metadata.Type Definition
Properties
brand
algorithm
"secp256k1"- Bitcoin/Ethereum ECDSA"p256"- NIST P-256 ECDSA"ed25519"- EdDSA on Curve25519
v
27- First recovery attempt (standard Ethereum)28- Second recovery attemptundefined- Not secp256k1 or no recovery ID
Byte Structure
ECDSA (secp256k1, p256)
Ed25519
Metadata Storage
Properties are defined usingObject.defineProperties():
Type Guards
is
- Is Uint8Array
- Has
[brand] === "Signature" - Has
algorithmproperty
Algorithm-Specific Checks
Examples
Creating Branded Signatures
Accessing Metadata
Preserving Metadata
Type Safety
Comparison with Plain Uint8Array
BrandedSignature
Plain Uint8Array
Serialization
JSON
Binary
Performance
Memory Overhead
BrandedSignature has minimal overhead:- Base: 64 bytes (signature data)
- Metadata: 3 property descriptors (~48 bytes)
- Total: ~112 bytes
Runtime Cost
- Property access: O(1) (native object properties)
- Type checking: O(1) (simple property checks)
- Creation: Minimal overhead vs plain Uint8Array
Optimization
Immutability
All properties are readonly:Compatibility
Uint8Array Methods
BrandedSignature supports all Uint8Array methods:Type Narrowing
Design Rationale
Why Branded Types?
- Type Safety: Compile-time guarantees about signature format
- Self-Describing: Algorithm embedded in data
- API Simplicity: No need to pass algorithm separately
- Runtime Validation: Type guards enable safe operations
Why Not Classes?
See Also
- Constructors - Creating BrandedSignature instances
- Utilities - Type guards and helpers
- Signature Overview - Main documentation

