Skip to content

Commit a6025c5

Browse files
committed
support btc drivation path as well as rgb
1 parent a377f4c commit a6025c5

File tree

5 files changed

+16
-6
lines changed

5 files changed

+16
-6
lines changed

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,8 @@ ifeq ($(BITCOIN_NETWORK),testnet)
7373

7474
# Bitcoin testnet, no legacy support
7575
DEFINES += BIP32_PUBKEY_VERSION=0x043587CF
76-
DEFINES += BIP44_COIN_TYPE=1
76+
DEFINES += BIP44_COIN_TYPE=827167
77+
DEFINES += BIP44_BTC_COIN_TYPE=1
7778
DEFINES += COIN_P2PKH_VERSION=111
7879
DEFINES += COIN_P2SH_VERSION=196
7980
DEFINES += COIN_NATIVE_SEGWIT_PREFIX=\"tb\"
@@ -91,7 +92,8 @@ else ifeq ($(BITCOIN_NETWORK),mainnet)
9192

9293
# Bitcoin mainnet, no legacy support
9394
DEFINES += BIP32_PUBKEY_VERSION=0x0488B21E
94-
DEFINES += BIP44_COIN_TYPE=0
95+
DEFINES += BIP44_COIN_TYPE=827166
96+
DEFINES += BIP44_BTC_COIN_TYPE=0
9597
DEFINES += COIN_P2PKH_VERSION=0
9698
DEFINES += COIN_P2SH_VERSION=5
9799
DEFINES += COIN_NATIVE_SEGWIT_PREFIX=\"bc\"

bitcoin_client_rs/src/wallet.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ mod tests {
296296
use core::str::FromStr;
297297

298298
const MASTER_KEY_EXAMPLE: &str = "[5c9e228d]tpubDEGquuorgFNb8bjh5kNZQMPtABJzoWwNm78FUmeoPkfRtoPF7JLrtoZeT3J3ybq1HmC3Rn1Q8wFQ8J5usanzups5rj7PJoQLNyvq8QbJruW/**";
299-
const KEY_EXAMPLE: &str = "[5c9e228d/48'/1'/0'/0']tpubDEGquuorgFNb8bjh5kNZQMPtABJzoWwNm78FUmeoPkfRtoPF7JLrtoZeT3J3ybq1HmC3Rn1Q8wFQ8J5usanzups5rj7PJoQLNyvq8QbJruW/**";
299+
const KEY_EXAMPLE: &str = "[5c9e228d/48'/827167'/0'/0']tpubDEGquuorgFNb8bjh5kNZQMPtABJzoWwNm78FUmeoPkfRtoPF7JLrtoZeT3J3ybq1HmC3Rn1Q8wFQ8J5usanzups5rj7PJoQLNyvq8QbJruW/**";
300300

301301
#[test]
302302
fn test_master_walletpubkey_fromstr() {
@@ -319,7 +319,7 @@ mod tests {
319319
);
320320
assert_eq!(
321321
key.source.as_ref().unwrap().1,
322-
DerivationPath::from_str("m/48'/1'/0'/0'").unwrap()
322+
DerivationPath::from_str("m/48'/827167'/0'/0'").unwrap()
323323
);
324324
assert_eq!(key.inner, Xpub::from_str("tpubDEGquuorgFNb8bjh5kNZQMPtABJzoWwNm78FUmeoPkfRtoPF7JLrtoZeT3J3ybq1HmC3Rn1Q8wFQ8J5usanzups5rj7PJoQLNyvq8QbJruW").unwrap());
325325
assert_eq!(key.multipath, Some("/**".to_string()));

src/handler/get_extended_pubkey.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ static bool is_path_safe_for_pubkey_export(const uint32_t bip32_path[], size_t b
8383
}
8484

8585
uint32_t coin_type = bip32_path[1] & 0x7FFFFFFF;
86-
if (coin_type != BIP44_COIN_TYPE) {
86+
if (coin_type != BIP44_COIN_TYPE && coin_type != BIP44_BTC_COIN_TYPE) {
8787
return false;
8888
}
8989

src/handler/lib/policy.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1498,7 +1498,8 @@ bool is_wallet_policy_standard(dispatcher_context_t *dispatcher_context,
14981498
const uint32_t H = BIP32_FIRST_HARDENED_CHILD;
14991499
if (key_info.master_key_derivation_len != 3 ||
15001500
key_info.master_key_derivation[0] != H + bip44_purpose ||
1501-
key_info.master_key_derivation[1] != H + BIP44_COIN_TYPE ||
1501+
(key_info.master_key_derivation[1] != H + BIP44_COIN_TYPE &&
1502+
key_info.master_key_derivation[1] != H + BIP44_BTC_COIN_TYPE) ||
15021503
key_info.master_key_derivation[2] < H ||
15031504
key_info.master_key_derivation[2] > H + MAX_BIP44_ACCOUNT_RECOMMENDED) {
15041505
return false;

src/handler/sign_psbt.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,13 @@ preprocess_outputs(dispatcher_context_t *dc,
954954

955955
output.in_out.scriptPubKey_len = result_len;
956956

957+
// --- RGB/RGB OP_RETURN logic ---
958+
if (is_opreturn(output.in_out.scriptPubKey, output.in_out.scriptPubKey_len)) {
959+
// Allow OP_RETURN outputs (for RGB or other protocols)
960+
continue;
961+
}
962+
// --- End RGB logic ---
963+
957964
int is_internal = is_in_out_internal(dc, st, sign_psbt_cache, &output.in_out, false);
958965

959966
if (is_internal < 0) {

0 commit comments

Comments
 (0)