Skip to content

Commit 0884576

Browse files
committed
miniscript: add proto messages
We will support miniscript as part of output descriptors. Descriptors are an expression language to specify Bitcoin outputs. For example, `wsh(multi(2,<pubkey1>,<pubkey2>,<pubkey3>))` is a 2-of-3 multisig wrapped in a P2WSH (pay-to-witness-script-hash) output. Descriptors specification: https://github.com/bitcoin/bitcoin/blob/8f402710371a40c5777dc3f9c4ba6ca8505a2f90/doc/descriptors.md In fragments wrapping SCRIPT expressions, SCRIPT can also be a miniscript expression, for example: `wsh(or_b(pk(<pubkey1>),s:pk(<pubkey2>)))`. With hardware signers, we want to use xpubs with derivations instead of raw pubkeys, and also have a shorter representation than inlining the xpubs for readability. That is why we will follow the 'Wallet Policies for Descriptor Wallets' proposal specied here: https://github.com/bigspider/bips/blob/bip-wallet-policies/bip-wallet-policies.mediawiki (bitcoin/bips#1389). The above example then become `wsh(or_b(pk(@0/**),s:pk(@1/**)))`. The `@NUM` references a key provided in the keys list. For the policy with the keys, one can then derive pkScripts for receive and change addresses and use these to create addresses.
1 parent fbd1dd8 commit 0884576

File tree

7 files changed

+142
-61
lines changed

7 files changed

+142
-61
lines changed

messages/btc.proto

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,17 @@ message BTCScriptConfig {
5252
ScriptType script_type = 4;
5353
}
5454

55+
// A policy as specified by 'Wallet policies':
56+
// https://github.com/bitcoin/bips/pull/1389
57+
message Policy {
58+
string policy = 1;
59+
repeated KeyOriginInfo keys = 2;
60+
}
61+
5562
oneof config {
5663
SimpleType simple_type = 1;
5764
Multisig multisig = 2;
65+
Policy policy = 3;
5866
}
5967
}
6068

messages/common.proto

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,9 @@ message XPub {
4040
message Keypath {
4141
repeated uint32 keypath = 1;
4242
}
43+
44+
message KeyOriginInfo {
45+
bytes root_fingerprint = 1;
46+
repeated uint32 keypath = 2;
47+
XPub xpub = 3;
48+
}

py/bitbox02/bitbox02/communication/generated/btc_pb2.py

Lines changed: 58 additions & 56 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

py/bitbox02/bitbox02/communication/generated/btc_pb2.pyi

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,19 +123,40 @@ class BTCScriptConfig(google.protobuf.message.Message):
123123
) -> None: ...
124124
def ClearField(self, field_name: typing_extensions.Literal["our_xpub_index",b"our_xpub_index","script_type",b"script_type","threshold",b"threshold","xpubs",b"xpubs"]) -> None: ...
125125

126+
class Policy(google.protobuf.message.Message):
127+
"""A policy as specified by 'Wallet policies':
128+
https://github.com/bitcoin/bips/pull/1389
129+
"""
130+
DESCRIPTOR: google.protobuf.descriptor.Descriptor
131+
POLICY_FIELD_NUMBER: builtins.int
132+
KEYS_FIELD_NUMBER: builtins.int
133+
policy: typing.Text
134+
@property
135+
def keys(self) -> google.protobuf.internal.containers.RepeatedCompositeFieldContainer[common_pb2.KeyOriginInfo]: ...
136+
def __init__(self,
137+
*,
138+
policy: typing.Text = ...,
139+
keys: typing.Optional[typing.Iterable[common_pb2.KeyOriginInfo]] = ...,
140+
) -> None: ...
141+
def ClearField(self, field_name: typing_extensions.Literal["keys",b"keys","policy",b"policy"]) -> None: ...
142+
126143
SIMPLE_TYPE_FIELD_NUMBER: builtins.int
127144
MULTISIG_FIELD_NUMBER: builtins.int
145+
POLICY_FIELD_NUMBER: builtins.int
128146
simple_type: global___BTCScriptConfig.SimpleType.ValueType
129147
@property
130148
def multisig(self) -> global___BTCScriptConfig.Multisig: ...
149+
@property
150+
def policy(self) -> global___BTCScriptConfig.Policy: ...
131151
def __init__(self,
132152
*,
133153
simple_type: global___BTCScriptConfig.SimpleType.ValueType = ...,
134154
multisig: typing.Optional[global___BTCScriptConfig.Multisig] = ...,
155+
policy: typing.Optional[global___BTCScriptConfig.Policy] = ...,
135156
) -> None: ...
136-
def HasField(self, field_name: typing_extensions.Literal["config",b"config","multisig",b"multisig","simple_type",b"simple_type"]) -> builtins.bool: ...
137-
def ClearField(self, field_name: typing_extensions.Literal["config",b"config","multisig",b"multisig","simple_type",b"simple_type"]) -> None: ...
138-
def WhichOneof(self, oneof_group: typing_extensions.Literal["config",b"config"]) -> typing.Optional[typing_extensions.Literal["simple_type","multisig"]]: ...
157+
def HasField(self, field_name: typing_extensions.Literal["config",b"config","multisig",b"multisig","policy",b"policy","simple_type",b"simple_type"]) -> builtins.bool: ...
158+
def ClearField(self, field_name: typing_extensions.Literal["config",b"config","multisig",b"multisig","policy",b"policy","simple_type",b"simple_type"]) -> None: ...
159+
def WhichOneof(self, oneof_group: typing_extensions.Literal["config",b"config"]) -> typing.Optional[typing_extensions.Literal["simple_type","multisig","policy"]]: ...
139160
global___BTCScriptConfig = BTCScriptConfig
140161

141162
class BTCPubRequest(google.protobuf.message.Message):

py/bitbox02/bitbox02/communication/generated/common_pb2.py

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

py/bitbox02/bitbox02/communication/generated/common_pb2.pyi

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,23 @@ class Keypath(google.protobuf.message.Message):
7777
) -> None: ...
7878
def ClearField(self, field_name: typing_extensions.Literal["keypath",b"keypath"]) -> None: ...
7979
global___Keypath = Keypath
80+
81+
class KeyOriginInfo(google.protobuf.message.Message):
82+
DESCRIPTOR: google.protobuf.descriptor.Descriptor
83+
ROOT_FINGERPRINT_FIELD_NUMBER: builtins.int
84+
KEYPATH_FIELD_NUMBER: builtins.int
85+
XPUB_FIELD_NUMBER: builtins.int
86+
root_fingerprint: builtins.bytes
87+
@property
88+
def keypath(self) -> google.protobuf.internal.containers.RepeatedScalarFieldContainer[builtins.int]: ...
89+
@property
90+
def xpub(self) -> global___XPub: ...
91+
def __init__(self,
92+
*,
93+
root_fingerprint: builtins.bytes = ...,
94+
keypath: typing.Optional[typing.Iterable[builtins.int]] = ...,
95+
xpub: typing.Optional[global___XPub] = ...,
96+
) -> None: ...
97+
def HasField(self, field_name: typing_extensions.Literal["xpub",b"xpub"]) -> builtins.bool: ...
98+
def ClearField(self, field_name: typing_extensions.Literal["keypath",b"keypath","root_fingerprint",b"root_fingerprint","xpub",b"xpub"]) -> None: ...
99+
global___KeyOriginInfo = KeyOriginInfo

src/rust/bitbox02-rust/src/shiftcrypto.bitbox02.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ pub struct Keypath {
3838
}
3939
#[allow(clippy::derive_partial_eq_without_eq)]
4040
#[derive(Clone, PartialEq, ::prost::Message)]
41+
pub struct KeyOriginInfo {
42+
#[prost(bytes = "vec", tag = "1")]
43+
pub root_fingerprint: ::prost::alloc::vec::Vec<u8>,
44+
#[prost(uint32, repeated, tag = "2")]
45+
pub keypath: ::prost::alloc::vec::Vec<u32>,
46+
#[prost(message, optional, tag = "3")]
47+
pub xpub: ::core::option::Option<XPub>,
48+
}
49+
#[allow(clippy::derive_partial_eq_without_eq)]
50+
#[derive(Clone, PartialEq, ::prost::Message)]
4151
pub struct CheckBackupRequest {
4252
#[prost(bool, tag = "1")]
4353
pub silent: bool,
@@ -203,7 +213,7 @@ pub struct AntiKleptoSignatureRequest {
203213
#[allow(clippy::derive_partial_eq_without_eq)]
204214
#[derive(Clone, PartialEq, ::prost::Message)]
205215
pub struct BtcScriptConfig {
206-
#[prost(oneof = "btc_script_config::Config", tags = "1, 2")]
216+
#[prost(oneof = "btc_script_config::Config", tags = "1, 2, 3")]
207217
pub config: ::core::option::Option<btc_script_config::Config>,
208218
}
209219
/// Nested message and enum types in `BTCScriptConfig`.
@@ -265,6 +275,16 @@ pub mod btc_script_config {
265275
}
266276
}
267277
}
278+
/// A policy as specified by 'Wallet policies':
279+
/// <https://github.com/bitcoin/bips/pull/1389>
280+
#[allow(clippy::derive_partial_eq_without_eq)]
281+
#[derive(Clone, PartialEq, ::prost::Message)]
282+
pub struct Policy {
283+
#[prost(string, tag = "1")]
284+
pub policy: ::prost::alloc::string::String,
285+
#[prost(message, repeated, tag = "2")]
286+
pub keys: ::prost::alloc::vec::Vec<super::KeyOriginInfo>,
287+
}
268288
/// SimpleType is a "simple" script: one public key, no additional inputs.
269289
#[derive(
270290
Clone,
@@ -312,6 +332,8 @@ pub mod btc_script_config {
312332
SimpleType(i32),
313333
#[prost(message, tag = "2")]
314334
Multisig(Multisig),
335+
#[prost(message, tag = "3")]
336+
Policy(Policy),
315337
}
316338
}
317339
#[allow(clippy::derive_partial_eq_without_eq)]

0 commit comments

Comments
 (0)