mirror of
https://github.com/bitcoin/bips.git
synced 2026-02-09 15:23:09 +00:00
* Add Chaincode Delegation BIP * Update license to BSD-3-Clause and expand blinded signing documentation * Address initial PR comments * Update with BIP number assignment * Fix delegator_sign test vector * Upgrade secp256k1lab and add license file - Upgrade vendored secp256k1lab to commit a265da1 (adds type annotations) - Add COPYING file to satisfy MIT license requirements - Document secp256k1lab commit reference in BIP text * Fix type checker and linter issues in reference implementation - Fix TweakContext to use Scalar types for gacc/tacc - Replace HashFunction enum with Callable type alias - Fix bytearray to bytes conversion in blind_sign - Move imports to top of file - Fix boolean comparison style (use 'not' instead of '== False') - Add proper type annotations and casts for dict handling - Remove unused imports and type ignore comments * Address PR review comments on terminology and clarity - Add intro explaining delegation naming (chain code is delegated, not signing authority) - Reorder terminology to list Delegator before Delegatee - Replace "quorum" with clearer "can co-sign for UTXOs" language - Clarify derivation constraints in terms of delegatee's extended key - Rename "Delegatee Signing" section to "Signing Modes" - Fix "delegatee can apply" to "delegator can produce" (line 112) - Replace undefined "caller" with "delegatee" (line 173) - Clarify "Change outputs" to "Tweaks for change outputs" (line 98) - Add note that message is separate from CCD bundle - Add note on application-specific verification (addresses, amounts) - Add transition sentence clarifying non-concurrent protocol scope * Add changelog entry for 0.1.3 * Fix header: use Authors (plural) for multiple authors * Fix BIP header format for CI compliance - Change Type from 'Standards Track' to 'Specification' (valid type) - Change 'Created' to 'Assigned' (correct field name per BIP format) - Change 'Post-History' to 'Discussion' (recognized field in buildtable.pl) * Apply suggestion from @murchandamus --------- Co-authored-by: Jesse Posner <jesse.posner@gmail.com>
43 lines
1.4 KiB
Python
43 lines
1.4 KiB
Python
"""Helpers for working with minimal SortedMulti descriptor templates."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass
|
|
from typing import Sequence
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class SortedMultiDescriptorTemplate:
|
|
"""Minimal representation of a ``wsh(sortedmulti(m, ...))`` descriptor."""
|
|
|
|
threshold: int
|
|
|
|
def witness_script(self, tweaked_keys: Sequence[bytes]) -> bytes:
|
|
"""Return the witness script for ``wsh(sortedmulti(threshold, tweaked_keys))``."""
|
|
|
|
if not tweaked_keys:
|
|
raise ValueError("sortedmulti requires at least one key")
|
|
if not 1 <= self.threshold <= len(tweaked_keys):
|
|
raise ValueError("threshold must satisfy 1 <= m <= n")
|
|
|
|
for key in tweaked_keys:
|
|
if len(key) != 33:
|
|
raise ValueError("sortedmulti keys must be 33-byte compressed pubkeys")
|
|
|
|
sorted_keys = sorted(tweaked_keys)
|
|
script = bytearray()
|
|
script.append(_op_n(self.threshold))
|
|
for key in sorted_keys:
|
|
script.append(len(key))
|
|
script.extend(key)
|
|
script.append(_op_n(len(sorted_keys)))
|
|
script.append(0xAE) # OP_CHECKMULTISIG
|
|
return bytes(script)
|
|
|
|
def _op_n(value: int) -> int:
|
|
if not 0 <= value <= 16:
|
|
raise ValueError("OP_N value out of range")
|
|
if value == 0:
|
|
return 0x00
|
|
return 0x50 + value
|