-
Notifications
You must be signed in to change notification settings - Fork 18
add coin purchase memo #162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| package firmware | ||
|
|
||
| import ( | ||
| "encoding/hex" | ||
| "testing" | ||
|
|
||
| "github.com/BitBoxSwiss/bitbox02-api-go/api/firmware/messages" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| // TODO: Add integration test for CoinPurchaseMemo once the firmware UI is implemented. | ||
| // potentially in psbt_test.go | ||
|
Comment on lines
+11
to
+12
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please no TODOs in code, they very often get missed or stay forever. Keep track of TODOs in issue trackers instead. In this case it might be most practical to wait with review&merge of this PR until this can be addressed. |
||
|
|
||
| func TestComputePaymentRequestSighash_CoinPurchaseMemo(t *testing.T) { | ||
| // This test verifies that our Go sighash computation matches the firmware's Rust implementation. | ||
| // The expected hash comes from a firmware test. | ||
| paymentRequest := &messages.BTCPaymentRequestRequest{ | ||
| RecipientName: "Merchant", | ||
| Memos: []*messages.BTCPaymentRequestRequest_Memo{ | ||
| { | ||
| Memo: &messages.BTCPaymentRequestRequest_Memo_CoinPurchaseMemo_{ | ||
| CoinPurchaseMemo: &messages.BTCPaymentRequestRequest_Memo_CoinPurchaseMemo{ | ||
| CoinType: 60, // Ethereum | ||
| Amount: "0.25 ETH", | ||
| Address: "0xabc1234567890", | ||
| // address_derivation is intentionally nil, since it's not part of the sighash | ||
| }, | ||
| }, | ||
| }, | ||
| }, | ||
| Nonce: []byte{}, | ||
| TotalAmount: 123456, | ||
| Signature: []byte{}, | ||
| } | ||
|
|
||
| sighash, err := ComputePaymentRequestSighash( | ||
| paymentRequest, | ||
| 1, // SLIP-44 coin type for Bitcoin Testnet | ||
| 123456, | ||
| "tb1q2q0j6gmfxynj40p0kxsr9jkagcvgpuqvqynnup", | ||
| ) | ||
| require.NoError(t, err) | ||
|
|
||
| expectedHash := "1806caf7c518aad69eb38f25fd418d507c6a3e01719a7d77be94cd50a2790872" | ||
| actualHash := hex.EncodeToString(sighash) | ||
|
|
||
| require.Equal(t, expectedHash, actualHash, "Sighash mismatch: Go implementation doesn't match firmware") | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
License header missing