@@ -448,18 +448,18 @@ func Test_SignPersonalMessageFVM(t *testing.T) {
448
448
// For FVM personal messages, we need to construct the EIP-191 message format
449
449
// EIP191_FVM_PREFIX = "\x19Filecoin Signed Message:\n"
450
450
eip191FVMPrefix := []byte ("\x19 Filecoin Signed Message:\n " )
451
-
451
+
452
452
// Create message length buffer (4 bytes, big endian)
453
453
messageLen := uint32 (len (personalMessage ))
454
454
messageLengthBuffer := make ([]byte , 4 )
455
455
binary .BigEndian .PutUint32 (messageLengthBuffer , messageLen )
456
-
456
+
457
457
// Construct EIP-191 message: prefix + length + message
458
458
eip191Message := make ([]byte , 0 , len (eip191FVMPrefix )+ 4 + len (personalMessage ))
459
459
eip191Message = append (eip191Message , eip191FVMPrefix ... )
460
460
eip191Message = append (eip191Message , messageLengthBuffer ... )
461
461
eip191Message = append (eip191Message , personalMessage ... )
462
-
462
+
463
463
// Hash the EIP-191 message with Blake2b
464
464
messageHash := blake2b .Sum256 (eip191Message )
465
465
@@ -531,18 +531,18 @@ func Test_SignPersonalMessageFVM_LongMessage(t *testing.T) {
531
531
// For FVM personal messages, we need to construct the EIP-191 message format
532
532
// EIP191_FVM_PREFIX = "\x19Filecoin Signed Message:\n"
533
533
eip191FVMPrefix := []byte ("\x19 Filecoin Signed Message:\n " )
534
-
534
+
535
535
// Create message length buffer (4 bytes, big endian)
536
536
messageLen := uint32 (len (longMessage ))
537
537
messageLengthBuffer := make ([]byte , 4 )
538
538
binary .BigEndian .PutUint32 (messageLengthBuffer , messageLen )
539
-
539
+
540
540
// Construct EIP-191 message: prefix + length + message
541
541
eip191Message := make ([]byte , 0 , len (eip191FVMPrefix )+ 4 + len (longMessage ))
542
542
eip191Message = append (eip191Message , eip191FVMPrefix ... )
543
543
eip191Message = append (eip191Message , messageLengthBuffer ... )
544
544
eip191Message = append (eip191Message , longMessage ... )
545
-
545
+
546
546
// Hash the EIP-191 message with Blake2b
547
547
messageHash := blake2b .Sum256 (eip191Message )
548
548
@@ -561,64 +561,62 @@ func Test_SignPersonalMessageFVM_LongMessage(t *testing.T) {
561
561
}
562
562
563
563
func Test_SignRawBytes (t * testing.T ) {
564
- app , err := FindLedgerFilecoinApp ()
565
- if err != nil {
566
- t .Fatalf (err .Error ())
567
- }
568
- defer app .Close ()
569
-
570
- // Derivation path used across the existing tests.
571
- path := []uint32 {44 , 461 , 0 , 0 , 0 }
572
-
573
- // 1 KB payload taken from the reference JavaScript test.
574
- rawBytesHex := "ab11c412ff5f6fafc466e856f67eb20ad85ef754ad1b7c5d4120ffe95dcd94bd1079f1a89a575d284422825f1aaeb099439bc60e6537e3c939a3a5f0e108d372be73d388da351c11bfc5a20a316051fcd52b4a6d003cd1eef171ba197cfbf8d245f705d65ee0c82fa74e4d3ee1f918a496a0244fb342b7ea0a836e522ba3519001866edde3207af56ad45177433ceb0290e0b55e0584b4c799a7646805d50e885e95e89209d5b223d82001be1c85c881ec6c5bd21bcfceb286c12fdc1f28feaaaa13853655c24f6ef5c640c222ba8ed161718d535786867481fb96bc1720be4b63438d72ba559cb0c72485d1fb6543bc6c684d358aa7cfc1877031600c6efb0f90e5224951205e276cbbd3876953e92a522e26d22a75b0417b2971866a839c03825df7e06de380e00ba7599c59a01165a0ac95d636cc63d09f095df058a273aa4067e9dbeeb7d28ba62519c34c485c9389a485d90f6c47698260fc43b5d2fb88794c34f129fd2861a310c74238f12cd7c84b4f8df19faf05a0756e8b5261b48ee45929f9cfc33c8cedb69029af312a544b216ea8fc33a10cd7188d58591c8a22b2ee3ab6816fe45e080c4f1733ea2a71627cbc90133cecd8eae635e0d522731ee1992a09f411a424bc48ae54cfebcdb442d34ef8e42b1cd9212fdda322baed3569437e1106b67a25d064b0d96a1150a4ea866e4849eb646574a5e3c0d4d6efca09eef7feaf540a6eda9c886d92018b2afbf64d9c077c83f23f45529f826a51b575432c6fa0c7849799c3e9ba5a0f4d71b93a12b72a9d06238c686561cd952a2a50e2c516f3fc1b60e94365dbc883a8a47a0214a6df74390c9963836e6d1099bc16da0a6caf07f0962b945ef225930bd6131fe344ff7fcac9f0181a0a24940146b03b79a3de67b92fe592183258e939685d47089e6f9228b169952aabb45f3ad369b1d557099ce97b6092f2e0bd6122c2479fed1a2427c8fd763a93587795f38a391782b0dadf857a3a8d896940c94cef4183d3ff52f26af4957736955db70d668f524285d091313ffc9b807e0502edc6fbc3f1d6e76350a0c3d78fc6cdc6ae36bd2b9dccb3b4e7734c8d91a2c883390953429fd9dd185a81bfa3ac147d86342ac3b227eff6ac0c2904596076b845a3267b1b472e8bbb429575fb280ec82718734ceb2b07e8c998b42cad224c98cc56aa5ca3a9159e8bf3604f4f56b2350befc00cca8e1a1aecb3dbb64c9536ec557204dfd3ee68ee16b641c41e75c4f97266ed4c5f78b5f8fd7ff11eb8c5db201f85b3904f13931bbead263a00e85d1086340bb4a2fb6fd139b793d4a7540b3dbf2495f7d08f8821759bde65817aa08fa1424101639fbfb6c4f91961da1372bccb127afc627d352f9d9d2faa5a9176be55274b53dc04b94174b6b7aa52955939cf14970d31e03ea60cb2cdc99e422f232a4052"
575
- rawBytes , _ := hex .DecodeString (rawBytesHex )
576
-
577
- // The Ledger stacks expect the "Filecoin Sign Bytes:\n" prefix (EIP-191 style)
578
- prefix := []byte ("Filecoin Sign Bytes:\n " )
579
- txBlob := append (prefix , rawBytes ... )
580
-
581
- // Sign the blob
582
- signature , err := app .SignRawBytes (path , txBlob )
583
- if err != nil {
584
- t .Fatalf ("[SignRawBytes] Error: %s\n " , err .Error ())
585
- }
586
-
587
- // Basic sanity checks on the returned signature
588
- assert .NotNil (t , signature )
589
- assert .Equal (t , 32 , len (signature .r ), "R component should be 32 bytes" )
590
- assert .Equal (t , 32 , len (signature .s ), "S component should be 32 bytes" )
591
- assert .True (t , len (signature .derSignature ) > 0 , "DER-encoded signature should not be empty" )
592
-
593
- // Retrieve the associated public key to perform verification
594
- pubKey , err := app .GetPublicKey (path , SECP256K1 )
595
- if err != nil {
596
- t .Fatalf ("[GetPublicKey] Error: %s\n " , err .Error ())
597
- }
598
-
599
- parsedPK , err := btcec .ParsePubKey (pubKey )
600
- if err != nil {
601
- t .Fatalf ("[ParsePubKey] Error: %s\n " , err .Error ())
602
- }
603
-
604
- parsedSig , err := ecdsa .ParseDERSignature (signature .derSignature )
605
- if err != nil {
606
- t .Fatalf ("[ParseDERSignature] Error: %s\n " , err .Error ())
607
- }
608
-
609
- // Digest = Blake2b-256( CID_PREFIX || Blake2b-256(txBlob) )
610
- cidPrefix := []byte {0x01 , 0x71 , 0xa0 , 0xe4 , 0x02 , 0x20 }
611
- innerHash := blake2b .Sum256 (txBlob )
612
- cid := append (cidPrefix , innerHash [:]... )
613
- digest := blake2b .Sum256 (cid )
614
-
615
- verified := parsedSig .Verify (digest [:], parsedPK )
616
- assert .True (t , verified , "Signature verification failed" )
617
-
618
- fmt .Printf ("RawBytes Signature R: %x\n " , signature .r )
619
- fmt .Printf ("RawBytes Signature S: %x\n " , signature .s )
620
- fmt .Printf ("RawBytes Signature V: %d\n " , signature .v )
621
- fmt .Printf ("RawBytes DER Signature: %x\n " , signature .derSignature )
622
- }
564
+ app , err := FindLedgerFilecoinApp ()
565
+ if err != nil {
566
+ t .Fatalf (err .Error ())
567
+ }
568
+ defer app .Close ()
569
+
570
+ // Derivation path used across the existing tests.
571
+ path := []uint32 {44 , 461 , 0 , 0 , 0 }
623
572
573
+ // 1 KB payload taken from the reference JavaScript test.
574
+ rawBytesHex := "ab11c412ff5f6fafc466e856f67eb20ad85ef754ad1b7c5d4120ffe95dcd94bd1079f1a89a575d284422825f1aaeb099439bc60e6537e3c939a3a5f0e108d372be73d388da351c11bfc5a20a316051fcd52b4a6d003cd1eef171ba197cfbf8d245f705d65ee0c82fa74e4d3ee1f918a496a0244fb342b7ea0a836e522ba3519001866edde3207af56ad45177433ceb0290e0b55e0584b4c799a7646805d50e885e95e89209d5b223d82001be1c85c881ec6c5bd21bcfceb286c12fdc1f28feaaaa13853655c24f6ef5c640c222ba8ed161718d535786867481fb96bc1720be4b63438d72ba559cb0c72485d1fb6543bc6c684d358aa7cfc1877031600c6efb0f90e5224951205e276cbbd3876953e92a522e26d22a75b0417b2971866a839c03825df7e06de380e00ba7599c59a01165a0ac95d636cc63d09f095df058a273aa4067e9dbeeb7d28ba62519c34c485c9389a485d90f6c47698260fc43b5d2fb88794c34f129fd2861a310c74238f12cd7c84b4f8df19faf05a0756e8b5261b48ee45929f9cfc33c8cedb69029af312a544b216ea8fc33a10cd7188d58591c8a22b2ee3ab6816fe45e080c4f1733ea2a71627cbc90133cecd8eae635e0d522731ee1992a09f411a424bc48ae54cfebcdb442d34ef8e42b1cd9212fdda322baed3569437e1106b67a25d064b0d96a1150a4ea866e4849eb646574a5e3c0d4d6efca09eef7feaf540a6eda9c886d92018b2afbf64d9c077c83f23f45529f826a51b575432c6fa0c7849799c3e9ba5a0f4d71b93a12b72a9d06238c686561cd952a2a50e2c516f3fc1b60e94365dbc883a8a47a0214a6df74390c9963836e6d1099bc16da0a6caf07f0962b945ef225930bd6131fe344ff7fcac9f0181a0a24940146b03b79a3de67b92fe592183258e939685d47089e6f9228b169952aabb45f3ad369b1d557099ce97b6092f2e0bd6122c2479fed1a2427c8fd763a93587795f38a391782b0dadf857a3a8d896940c94cef4183d3ff52f26af4957736955db70d668f524285d091313ffc9b807e0502edc6fbc3f1d6e76350a0c3d78fc6cdc6ae36bd2b9dccb3b4e7734c8d91a2c883390953429fd9dd185a81bfa3ac147d86342ac3b227eff6ac0c2904596076b845a3267b1b472e8bbb429575fb280ec82718734ceb2b07e8c998b42cad224c98cc56aa5ca3a9159e8bf3604f4f56b2350befc00cca8e1a1aecb3dbb64c9536ec557204dfd3ee68ee16b641c41e75c4f97266ed4c5f78b5f8fd7ff11eb8c5db201f85b3904f13931bbead263a00e85d1086340bb4a2fb6fd139b793d4a7540b3dbf2495f7d08f8821759bde65817aa08fa1424101639fbfb6c4f91961da1372bccb127afc627d352f9d9d2faa5a9176be55274b53dc04b94174b6b7aa52955939cf14970d31e03ea60cb2cdc99e422f232a4052"
575
+ rawBytes , _ := hex .DecodeString (rawBytesHex )
576
+
577
+ // The Ledger stacks expect the "Filecoin Sign Bytes:\n" prefix (EIP-191 style)
578
+ prefix := []byte ("Filecoin Sign Bytes:\n " )
579
+ txBlob := append (prefix , rawBytes ... )
580
+
581
+ // Sign the blob
582
+ signature , err := app .SignRawBytes (path , txBlob )
583
+ if err != nil {
584
+ t .Fatalf ("[SignRawBytes] Error: %s\n " , err .Error ())
585
+ }
624
586
587
+ // Basic sanity checks on the returned signature
588
+ assert .NotNil (t , signature )
589
+ assert .Equal (t , 32 , len (signature .r ), "R component should be 32 bytes" )
590
+ assert .Equal (t , 32 , len (signature .s ), "S component should be 32 bytes" )
591
+ assert .True (t , len (signature .derSignature ) > 0 , "DER-encoded signature should not be empty" )
592
+
593
+ // Retrieve the associated public key to perform verification
594
+ pubKey , err := app .GetPublicKey (path , SECP256K1 )
595
+ if err != nil {
596
+ t .Fatalf ("[GetPublicKey] Error: %s\n " , err .Error ())
597
+ }
598
+
599
+ parsedPK , err := btcec .ParsePubKey (pubKey )
600
+ if err != nil {
601
+ t .Fatalf ("[ParsePubKey] Error: %s\n " , err .Error ())
602
+ }
603
+
604
+ parsedSig , err := ecdsa .ParseDERSignature (signature .derSignature )
605
+ if err != nil {
606
+ t .Fatalf ("[ParseDERSignature] Error: %s\n " , err .Error ())
607
+ }
608
+
609
+ // Digest = Blake2b-256( CID_PREFIX || Blake2b-256(txBlob) )
610
+ cidPrefix := []byte {0x01 , 0x71 , 0xa0 , 0xe4 , 0x02 , 0x20 }
611
+ innerHash := blake2b .Sum256 (txBlob )
612
+ cid := append (cidPrefix , innerHash [:]... )
613
+ digest := blake2b .Sum256 (cid )
614
+
615
+ verified := parsedSig .Verify (digest [:], parsedPK )
616
+ assert .True (t , verified , "Signature verification failed" )
617
+
618
+ fmt .Printf ("RawBytes Signature R: %x\n " , signature .r )
619
+ fmt .Printf ("RawBytes Signature S: %x\n " , signature .s )
620
+ fmt .Printf ("RawBytes Signature V: %d\n " , signature .v )
621
+ fmt .Printf ("RawBytes DER Signature: %x\n " , signature .derSignature )
622
+ }
0 commit comments