This PR introduces basic Miniscript support to the TestFramework.
I believe this would be useful for:
- Functional tests with more complex script satisfaction(s)
- Functional tests for future wallet RPC calls which handle Miniscript
- Entry point for developers looking to integrate Miniscript into external wallet projects (ecdsa, SomberNight, dgpv).
Usage:
Miniscript string constructor.
# key, delay in descriptor below must be represented as hex/int.
example_desc = βor_b(or_i(n:thresh_m(k,key,key),0),a:or_i(0,older(delay)))β
miniscript_node = Node.from_desc(example_desc)
Miniscript CScript constructor.
miniscript_node = Node.from_script(cscript)
Miniscript type and properties.
miniscript_node.p.to_string()
(Dis)satisfaction methods, returns list of tuple-lists.
# Canonical (dis)satisfying witnesses
miniscript_node.sat
miniscript_node.dsat
# Non-canonical (dis)satisfying witnesses
miniscript_node.sat_ncan
miniscript_node.dsat_ncan
Each tuple-list encodes a single, unique satisfying witness:
[
(SatType, Value),
(SatType, Value),
(SatType, Value),
β¦
]
The SatType, Value tuples encode the following witness information in correct order. Exception: Time/Delay tuples are not witness elements and will always be positioned at the beginning of the list.
| SatType | Value |
|---|---|
| OLDER | Delay int |
| AFTER | Time int |
| SIGNATURE | 33B Key/20B HASH160 Digest |
| KEY_AND_HASH160_PREIMAGE | 20B HASH160 Digest |
| SHA256_PREIMAGE | 32B SHA256 Digest |
| HASH256_PREIMAGE | 32B HASH256 Digest |
| RIPEMD160_PREIMAGE | 20B RIPEMD160 Digest |
| HASH160_PREIMAGE | 20B HASH160 Digest |
| DATA | Bytes |
Our example miniscript_node.sat above returns the following 2 satisfying witnesses:
[
[
(<SatType.DATA: 8>, b'\x01'),
(<SatType.DATA: 8>, b''),
(<SatType.SIGNATURE: 2>, key_bytes),
(<SatType.SIGNATURE: 2>, key_bytes),
(<SatType.DATA: 8>, b'\x01')
],
[
(<SatType.OLDER: 0>, 45),
(<SatType.DATA: 8>, b''),
(<SatType.DATA: 8>, b'')
]
]
Tests:
I have included tests in feature_miniscript.py to facilitate potential reviews, but would suggest to omit these if the maintainers decide to merge this PR.