|
15 | 15 | package firmware
|
16 | 16 |
|
17 | 17 | import (
|
| 18 | + "math/big" |
18 | 19 | "testing"
|
19 | 20 |
|
20 | 21 | "github.com/BitBoxSwiss/bitbox02-api-go/api/firmware/messages"
|
@@ -378,3 +379,75 @@ func TestSimulatorETHSignTypedMessage(t *testing.T) {
|
378 | 379 | require.Len(t, sig, 65)
|
379 | 380 | })
|
380 | 381 | }
|
| 382 | + |
| 383 | +func TestSimulatorETHSign(t *testing.T) { |
| 384 | + testInitializedSimulators(t, func(t *testing.T, device *Device) { |
| 385 | + t.Helper() |
| 386 | + chainID := uint64(1) |
| 387 | + keypath := []uint32{ |
| 388 | + 44 + hardenedKeyStart, |
| 389 | + 60 + hardenedKeyStart, |
| 390 | + 0 + hardenedKeyStart, |
| 391 | + 0, |
| 392 | + 10, |
| 393 | + } |
| 394 | + nonce := uint64(8156) |
| 395 | + gasPrice := new(big.Int).SetUint64(6000000000) |
| 396 | + gasLimit := uint64(21000) |
| 397 | + recipient := [20]byte{0x04, 0xf2, 0x64, 0xcf, 0x34, 0x44, 0x03, 0x13, 0xb4, 0xa0, |
| 398 | + 0x19, 0x2a, 0x35, 0x28, 0x14, 0xfb, 0xe9, 0x27, 0xb8, 0x85} |
| 399 | + value := new(big.Int).SetUint64(530564000000000000) |
| 400 | + data := []byte("") |
| 401 | + |
| 402 | + sig, err := device.ETHSign( |
| 403 | + chainID, |
| 404 | + keypath, |
| 405 | + nonce, |
| 406 | + gasPrice, |
| 407 | + gasLimit, |
| 408 | + recipient, |
| 409 | + value, |
| 410 | + data, |
| 411 | + ) |
| 412 | + require.NoError(t, err) |
| 413 | + |
| 414 | + require.Len(t, sig, 65, "The signature should have exactly 65 bytes") |
| 415 | + }) |
| 416 | +} |
| 417 | + |
| 418 | +func TestSimulatorETHSignEIP1559(t *testing.T) { |
| 419 | + testInitializedSimulators(t, func(t *testing.T, device *Device) { |
| 420 | + t.Helper() |
| 421 | + chainID := uint64(1) |
| 422 | + keypath := []uint32{ |
| 423 | + 44 + hardenedKeyStart, |
| 424 | + 60 + hardenedKeyStart, |
| 425 | + 0 + hardenedKeyStart, |
| 426 | + 0, |
| 427 | + 10, |
| 428 | + } |
| 429 | + nonce := uint64(8156) |
| 430 | + maxPriorityFeePerGas := new(big.Int) |
| 431 | + maxFeePerGas := new(big.Int).SetUint64(6000000000) |
| 432 | + gasLimit := uint64(21000) |
| 433 | + recipient := [20]byte{0x04, 0xf2, 0x64, 0xcf, 0x34, 0x44, 0x03, 0x13, 0xb4, 0xa0, |
| 434 | + 0x19, 0x2a, 0x35, 0x28, 0x14, 0xfb, 0xe9, 0x27, 0xb8, 0x85} |
| 435 | + value := new(big.Int).SetUint64(530564000000000000) |
| 436 | + data := []byte("") |
| 437 | + |
| 438 | + sig, err := device.ETHSignEIP1559( |
| 439 | + chainID, |
| 440 | + keypath, |
| 441 | + nonce, |
| 442 | + maxPriorityFeePerGas, |
| 443 | + maxFeePerGas, |
| 444 | + gasLimit, |
| 445 | + recipient, |
| 446 | + value, |
| 447 | + data, |
| 448 | + ) |
| 449 | + require.NoError(t, err) |
| 450 | + |
| 451 | + require.Len(t, sig, 65, "The signature should have exactly 65 bytes") |
| 452 | + }) |
| 453 | +} |
0 commit comments