Skip to content

Commit 8348d4b

Browse files
OttoAllmendingerllm-git
andcommitted
fix(wasm-utxo): correct paygo address validation in tests
This commit fixes an issue with PayGo attestation validation by updating the test address from "1CdWUVacSQQJ617HuNWByGiisEGXGNx2c" to "1CdWUVacSQQJ617HfuNWByGiisEGXGNx2c" and its corresponding script pubkey. Enables proper signature verification in tests that were previously failing or ignored. Issue: BTC-2650 Co-authored-by: llm-git <llm-git@ttll.de>
1 parent 5489ce8 commit 8348d4b

6 files changed

Lines changed: 55 additions & 44 deletions

File tree

packages/wasm-utxo/src/fixed_script_wallet/bitgo_psbt/mod.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3979,7 +3979,7 @@ mod tests {
39793979
psbt.unsigned_tx.output.push(miniscript::bitcoin::TxOut {
39803980
value: miniscript::bitcoin::Amount::from_sat(10000),
39813981
script_pubkey: miniscript::bitcoin::ScriptBuf::from_hex(
3982-
"76a91479b000887626b294a914501a4cd226b58b23598388ac",
3982+
"76a9147f90f63fed017815f1da8bea299da27945a17bda88ac",
39833983
)
39843984
.unwrap(),
39853985
});
@@ -3998,7 +3998,7 @@ mod tests {
39983998
assert!(result.is_ok(), "Should add attestation successfully");
39993999

40004000
// Extract and verify
4001-
let address = "1CdWUVacSQQJ617HuNWByGiisEGXGNx2c";
4001+
let address = "1CdWUVacSQQJ617HfuNWByGiisEGXGNx2c";
40024002
let psbt = bitgo_psbt.psbt();
40034003

40044004
// Verify it was added (with address, no verification)
@@ -4091,9 +4091,9 @@ mod tests {
40914091
psbt.unsigned_tx.output.push(miniscript::bitcoin::TxOut {
40924092
value: miniscript::bitcoin::Amount::from_sat(10000),
40934093
script_pubkey: miniscript::bitcoin::ScriptBuf::from_hex(
4094-
"76a91479b000887626b294a914501a4cd226b58b23598388ac",
4094+
"76a9147f90f63fed017815f1da8bea299da27945a17bda88ac",
40954095
)
4096-
.unwrap(), // Address: 1CdWUVacSQQJ617HuNWByGiisEGXGNx2c
4096+
.unwrap(), // Address: 1CdWUVacSQQJ617HfuNWByGiisEGXGNx2c
40974097
});
40984098

40994099
// Add PayGo attestation
@@ -4122,15 +4122,12 @@ mod tests {
41224122
.unwrap();
41234123
let pubkey = secp256k1::PublicKey::from_slice(&pubkey_bytes).unwrap();
41244124

4125-
// Note: Signature verification with bitcoinjs-message format is not fully working yet
4126-
// So parsing with pubkey will fail validation
4127-
let parsed_result = bitgo_psbt.parse_outputs_with_wallet_keys(&wallet_keys, &[pubkey]);
4125+
let parsed_result = bitgo_psbt
4126+
.parse_outputs_with_wallet_keys(&wallet_keys, &[pubkey])
4127+
.unwrap();
41284128

4129-
// We expect this to fail validation for now
4130-
assert!(
4131-
parsed_result.is_err(),
4132-
"Expected verification to fail with current signature format"
4133-
);
4129+
// The PayGo output should have paygo: true (verified)
4130+
assert!(parsed_result[output_index].paygo);
41344131
}
41354132

41364133
crate::test_psbt_fixtures!(test_parse_transaction_with_wallet_keys, network, format, {

packages/wasm-utxo/src/paygo/attestation.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ mod tests {
6565
fn test_new_valid_entropy() {
6666
let entropy = vec![0u8; 64];
6767
let signature = vec![1u8; 65];
68-
let address = "1CdWUVacSQQJ617HuNWByGiisEGXGNx2c".to_string();
68+
let address = "1CdWUVacSQQJ617HfuNWByGiisEGXGNx2c".to_string();
6969

7070
let attestation =
7171
PayGoAttestation::new(entropy.clone(), signature.clone(), address.clone());
@@ -81,7 +81,7 @@ mod tests {
8181
fn test_new_invalid_entropy_length() {
8282
let entropy = vec![0u8; 32]; // Wrong length
8383
let signature = vec![1u8; 65];
84-
let address = "1CdWUVacSQQJ617HuNWByGiisEGXGNx2c".to_string();
84+
let address = "1CdWUVacSQQJ617HfuNWByGiisEGXGNx2c".to_string();
8585

8686
let result = PayGoAttestation::new(entropy, signature, address);
8787
assert!(result.is_err());
@@ -99,23 +99,23 @@ mod tests {
9999
b722b6d0d9adbab782d2d0d66402794b6bd6449dc26f634035ee388a2b5e7b53f6",
100100
)
101101
.unwrap();
102-
let address = "1CdWUVacSQQJ617HuNWByGiisEGXGNx2c".to_string();
102+
let address = "1CdWUVacSQQJ617HfuNWByGiisEGXGNx2c".to_string();
103103

104104
let attestation = PayGoAttestation::new(entropy, signature, address.clone()).unwrap();
105105
let message = attestation.to_message();
106106

107-
// Message should be: 64 bytes entropy + 33 bytes address + 36 bytes UUID = 133 bytes
108-
assert_eq!(message.len(), 133);
107+
// Message should be: 64 bytes entropy + 34 bytes address + 36 bytes UUID = 134 bytes
108+
assert_eq!(message.len(), 134);
109109

110110
// Verify components
111111
let entropy_part = &message[0..64];
112-
let address_part = &message[64..97];
113-
let uuid_part = &message[97..133];
112+
let address_part = &message[64..98];
113+
let uuid_part = &message[98..134];
114114

115115
assert_eq!(entropy_part, &vec![0u8; 64][..]);
116116
assert_eq!(
117117
std::str::from_utf8(address_part).unwrap(),
118-
"1CdWUVacSQQJ617HuNWByGiisEGXGNx2c"
118+
"1CdWUVacSQQJ617HfuNWByGiisEGXGNx2c"
119119
);
120120
assert_eq!(
121121
std::str::from_utf8(uuid_part).unwrap(),

packages/wasm-utxo/src/paygo/psbt.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ mod tests {
196196
#[test]
197197
fn test_extract_paygo_attestation_success() {
198198
let output = create_test_output_with_attestation();
199-
let address = "1CdWUVacSQQJ617HuNWByGiisEGXGNx2c";
199+
let address = "1CdWUVacSQQJ617HfuNWByGiisEGXGNx2c";
200200

201201
let result = extract_paygo_attestation(&output, address);
202202
assert!(result.is_ok());
@@ -210,7 +210,7 @@ mod tests {
210210
#[test]
211211
fn test_extract_paygo_attestation_not_found() {
212212
let output = Output::default();
213-
let address = "1CdWUVacSQQJ617HuNWByGiisEGXGNx2c";
213+
let address = "1CdWUVacSQQJ617HfuNWByGiisEGXGNx2c";
214214

215215
let result = extract_paygo_attestation(&output, address);
216216
assert!(result.is_err());
@@ -236,7 +236,7 @@ mod tests {
236236
output.proprietary.insert(key, signature);
237237
}
238238

239-
let address = "1CdWUVacSQQJ617HuNWByGiisEGXGNx2c";
239+
let address = "1CdWUVacSQQJ617HfuNWByGiisEGXGNx2c";
240240
let result = extract_paygo_attestation(&output, address);
241241
assert!(result.is_err());
242242
assert!(result
@@ -320,7 +320,7 @@ mod tests {
320320
b722b6d0d9adbab782d2d0d66402794b6bd6449dc26f634035ee388a2b5e7b53f6",
321321
)
322322
.unwrap();
323-
let address = "1CdWUVacSQQJ617HuNWByGiisEGXGNx2c";
323+
let address = "1CdWUVacSQQJ617HfuNWByGiisEGXGNx2c";
324324
let pubkey_bytes =
325325
hex::decode("02456f4f788b6af55eb9c54d88692cadef4babdbc34cde75218cc1d6b6de3dea2d")
326326
.unwrap();
@@ -337,10 +337,8 @@ mod tests {
337337
assert_eq!(attestation.address, address);
338338

339339
// Verify with pubkeys
340-
// Note: Signature verification is not fully working yet with bitcoinjs-message format
341-
// For now, we just verify the function runs without panic
342340
let result = has_paygo_attestation_verify(&output, Some(address), &[pubkey]);
343-
// The verification may fail, but should not panic
344-
let _ = result;
341+
assert!(result.is_ok());
342+
assert!(result.unwrap(), "Signature should be valid");
345343
}
346344
}

packages/wasm-utxo/src/paygo/verify.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,7 @@ mod tests {
106106
use super::*;
107107
use crate::paygo::PayGoAttestation;
108108

109-
// TODO: Fix signature verification test - the recovery algorithm needs adjustment
110-
// to match bitcoinjs-message format
111109
#[test]
112-
#[ignore]
113110
fn test_verify_valid_signature() {
114111
use secp256k1::PublicKey;
115112

@@ -120,7 +117,7 @@ mod tests {
120117
b722b6d0d9adbab782d2d0d66402794b6bd6449dc26f634035ee388a2b5e7b53f6",
121118
)
122119
.unwrap();
123-
let address = "1CdWUVacSQQJ617HuNWByGiisEGXGNx2c".to_string();
120+
let address = "1CdWUVacSQQJ617HfuNWByGiisEGXGNx2c".to_string();
124121
let pubkey_bytes =
125122
hex::decode("02456f4f788b6af55eb9c54d88692cadef4babdbc34cde75218cc1d6b6de3dea2d")
126123
.unwrap();
@@ -144,7 +141,7 @@ mod tests {
144141
b722b6d0d9adbab782d2d0d66402794b6bd6449dc26f634035ee388a2b5e7b53f6",
145142
)
146143
.unwrap();
147-
let address = "1CdWUVacSQQJ617HuNWByGiisEGXGNx2c".to_string();
144+
let address = "1CdWUVacSQQJ617HfuNWByGiisEGXGNx2c".to_string();
148145

149146
// Different public key
150147
let wrong_pubkey_bytes =
@@ -165,7 +162,7 @@ mod tests {
165162

166163
let entropy = vec![0u8; 64];
167164
let signature = vec![1u8; 32]; // Too short
168-
let address = "1CdWUVacSQQJ617HuNWByGiisEGXGNx2c".to_string();
165+
let address = "1CdWUVacSQQJ617HfuNWByGiisEGXGNx2c".to_string();
169166
let pubkey_bytes =
170167
hex::decode("02456f4f788b6af55eb9c54d88692cadef4babdbc34cde75218cc1d6b6de3dea2d")
171168
.unwrap();

packages/wasm-utxo/src/wasm/try_into_js_value.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ impl<T: TryIntoJsValue> TryIntoJsValue for Option<T> {
8080
}
8181
}
8282

83+
impl TryIntoJsValue for bool {
84+
fn try_to_js_value(&self) -> Result<JsValue, WasmUtxoError> {
85+
Ok(JsValue::from_bool(*self))
86+
}
87+
}
88+
8389
impl TryIntoJsValue for XOnlyPublicKey {
8490
fn try_to_js_value(&self) -> Result<JsValue, WasmUtxoError> {
8591
Ok(JsValue::from_str(&self.to_string()))
@@ -367,7 +373,8 @@ impl TryIntoJsValue for crate::fixed_script_wallet::bitgo_psbt::ParsedOutput {
367373
"address" => self.address.clone(),
368374
"script" => self.script.clone(),
369375
"value" => self.value,
370-
"scriptId" => self.script_id
376+
"scriptId" => self.script_id,
377+
"paygo" => self.paygo
371378
)
372379
}
373380
}

packages/wasm-utxo/test/fixedScript/paygoAttestation.ts

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ describe("PayGo Attestation", function () {
1111
hash: Buffer.alloc(32, 0),
1212
index: 0,
1313
});
14-
// Add output with script_pubkey for address 1CdWUVacSQQJ617HuNWByGiisEGXGNx2c
14+
// Add output with script_pubkey for address 1CdWUVacSQQJ617HfuNWByGiisEGXGNx2c
1515
psbt.addOutput({
16-
script: Buffer.from("76a91479b000887626b294a914501a4cd226b58b23598388ac", "hex"),
16+
script: Buffer.from("76a9147f90f63fed017815f1da8bea299da27945a17bda88ac", "hex"),
1717
value: BigInt(10000000),
1818
});
1919

@@ -104,23 +104,35 @@ describe("PayGo Attestation", function () {
104104
});
105105

106106
it("should verify PayGo attestation with correct pubkey", function () {
107-
// This test documents the expected behavior once signature verification is working
108107
const psbt = createSimplePsbt();
109108

110-
// Test fixtures
111109
const entropy = Buffer.alloc(64, 0);
112110
const signature = Buffer.from(
113111
"1fd62abac20bb963f5150aa4b3f4753c5f2f53ced5183ab7761d0c95c2820f6b" +
114112
"b722b6d0d9adbab782d2d0d66402794b6bd6449dc26f634035ee388a2b5e7b53f6",
115113
"hex",
116114
);
117115

118-
// Add attestation
119116
psbt.addPayGoAttestation(0, entropy, signature);
120117

121-
// Note: Verification with ECPair would be tested here once signature format is aligned
122-
// For now, we just verify the attestation was added
123-
const bytesWithAttestation = psbt.serialize();
124-
assert.ok(bytesWithAttestation.length > 0);
118+
// Verification pubkey from utxo-core test fixtures
119+
const pubkey = Buffer.from(
120+
"02456f4f788b6af55eb9c54d88692cadef4babdbc34cde75218cc1d6b6de3dea2d",
121+
"hex",
122+
);
123+
124+
// Parse outputs with PayGo pubkey - should set paygo: true on the attested output
125+
const outputs = psbt.parseOutputsWithWalletKeys(
126+
// Use dummy wallet keys - they won't match any output but PayGo verification is independent
127+
[
128+
"xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8",
129+
"xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8",
130+
"xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8",
131+
],
132+
[pubkey],
133+
);
134+
135+
assert.strictEqual(outputs.length, 1);
136+
assert.strictEqual(outputs[0].paygo, true);
125137
});
126138
});

0 commit comments

Comments
 (0)