Skip to content

Commit 5a67f16

Browse files
committed
Make wallet interface signature just a byte slice
1 parent e821617 commit 5a67f16

File tree

19 files changed

+102
-177
lines changed

19 files changed

+102
-177
lines changed

auth/certificates/certificate.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -270,12 +270,6 @@ func (c *Certificate) Verify(ctx context.Context) error {
270270
return fmt.Errorf("failed to serialize certificate: %w", err)
271271
}
272272

273-
// Parse the signature
274-
sig, err := ec.ParseSignature(c.Signature)
275-
if err != nil {
276-
return fmt.Errorf("failed to parse signature: %w", err)
277-
}
278-
279273
// Verify the signature using the certifier's public key
280274
verifyArgs := wallet.VerifySignatureArgs{
281275
EncryptionArgs: wallet.EncryptionArgs{
@@ -290,7 +284,7 @@ func (c *Certificate) Verify(ctx context.Context) error {
290284
},
291285
},
292286
Data: data,
293-
Signature: *sig,
287+
Signature: c.Signature,
294288
}
295289

296290
verifyResult, err := verifier.VerifySignature(ctx, verifyArgs, "")
@@ -349,7 +343,7 @@ func (c *Certificate) Sign(ctx context.Context, certifierWallet *wallet.ProtoWal
349343
}
350344

351345
// Store the signature
352-
c.Signature = signResult.Signature.Serialize()
346+
c.Signature = signResult.Signature
353347

354348
return nil
355349
}

auth/peer.go

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ func (p *Peer) ToPeer(ctx context.Context, message []byte, identityKey *ec.Publi
235235
return fmt.Errorf("failed to sign message: %w", err)
236236
}
237237

238-
generalMessage.Signature = sigResult.Signature.Serialize()
238+
generalMessage.Signature = sigResult.Signature
239239

240240
// Update session timestamp
241241
now := time.Now().UnixNano() / int64(time.Millisecond)
@@ -595,12 +595,6 @@ func (p *Peer) handleCertificateRequest(ctx context.Context, message *AuthMessag
595595
return fmt.Errorf("failed to serialize certificate request data: %w", err)
596596
}
597597

598-
// Try to parse the signature
599-
sig, err := ec.ParseSignature(message.Signature)
600-
if err != nil {
601-
return fmt.Errorf("failed to parse signature: %w", err)
602-
}
603-
604598
// Verify signature
605599
verifyResult, err := p.wallet.VerifySignature(ctx, wallet.VerifySignatureArgs{
606600
EncryptionArgs: wallet.EncryptionArgs{
@@ -616,7 +610,7 @@ func (p *Peer) handleCertificateRequest(ctx context.Context, message *AuthMessag
616610
},
617611
},
618612
Data: certRequestData,
619-
Signature: *sig,
613+
Signature: message.Signature,
620614
}, "")
621615

622616
if err != nil || !verifyResult.Valid {
@@ -677,12 +671,6 @@ func (p *Peer) handleCertificateResponse(ctx context.Context, message *AuthMessa
677671
return fmt.Errorf("failed to serialize certificate data: %w", err)
678672
}
679673

680-
// Try to parse the signature
681-
sig, err := ec.ParseSignature(message.Signature)
682-
if err != nil {
683-
return fmt.Errorf("failed to parse signature: %w", err)
684-
}
685-
686674
// Verify signature
687675
verifyResult, err := p.wallet.VerifySignature(ctx, wallet.VerifySignatureArgs{
688676
EncryptionArgs: wallet.EncryptionArgs{
@@ -698,7 +686,7 @@ func (p *Peer) handleCertificateResponse(ctx context.Context, message *AuthMessa
698686
},
699687
},
700688
Data: certData,
701-
Signature: *sig,
689+
Signature: message.Signature,
702690
}, "")
703691

704692
if err != nil || !verifyResult.Valid {
@@ -774,12 +762,6 @@ func (p *Peer) handleGeneralMessage(ctx context.Context, message *AuthMessage, s
774762
session.LastUpdate = time.Now().UnixMilli()
775763
p.sessionManager.UpdateSession(session)
776764

777-
// Try to parse the signature
778-
sig, err := ec.ParseSignature(message.Signature)
779-
if err != nil {
780-
return fmt.Errorf("failed to parse signature: %w", err)
781-
}
782-
783765
// Verify signature
784766
verifyResult, err := p.wallet.VerifySignature(ctx, wallet.VerifySignatureArgs{
785767
EncryptionArgs: wallet.EncryptionArgs{
@@ -795,7 +777,7 @@ func (p *Peer) handleGeneralMessage(ctx context.Context, message *AuthMessage, s
795777
},
796778
},
797779
Data: message.Payload,
798-
Signature: *sig,
780+
Signature: message.Signature,
799781
}, "")
800782

801783
if err != nil || !verifyResult.Valid {
@@ -880,7 +862,7 @@ func (p *Peer) RequestCertificates(ctx context.Context, identityKey *ec.PublicKe
880862
return fmt.Errorf("failed to sign certificate request: %w", err)
881863
}
882864

883-
certRequest.Signature = sigResult.Signature.Serialize()
865+
certRequest.Signature = sigResult.Signature
884866

885867
// Send the request
886868
err = p.transport.Send(ctx, certRequest)
@@ -962,7 +944,7 @@ func (p *Peer) SendCertificateResponse(ctx context.Context, identityKey *ec.Publ
962944
return fmt.Errorf("failed to sign certificate response: %w", err)
963945
}
964946

965-
certResponse.Signature = sigResult.Signature.Serialize()
947+
certResponse.Signature = sigResult.Signature
966948

967949
// Send the response
968950
err = p.transport.Send(ctx, certResponse)

auth/peer_test.go

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -109,12 +109,13 @@ func CreatePeerPair(t *testing.T) (*Peer, *Peer, *wallet.MockWallet, *wallet.Moc
109109
// Setup basic crypto operations
110110
dummySig, err := alicePk.Sign([]byte("test"))
111111
require.NoError(t, err)
112+
dummySigBytes := dummySig.Serialize()
112113

113114
aliceWallet.MockCreateSignature = func(ctx context.Context, args wallet.CreateSignatureArgs, originator string) (*wallet.CreateSignatureResult, error) {
114-
return &wallet.CreateSignatureResult{Signature: *dummySig}, nil
115+
return &wallet.CreateSignatureResult{Signature: dummySigBytes}, nil
115116
}
116117
bobWallet.MockCreateSignature = func(ctx context.Context, args wallet.CreateSignatureArgs, originator string) (*wallet.CreateSignatureResult, error) {
117-
return &wallet.CreateSignatureResult{Signature: *dummySig}, nil
118+
return &wallet.CreateSignatureResult{Signature: dummySigBytes}, nil
118119
}
119120

120121
aliceWallet.MockVerifySignature = func(ctx context.Context, args wallet.VerifySignatureArgs, originator string) (*wallet.VerifySignatureResult, error) {
@@ -440,6 +441,7 @@ func TestPeerCertificateExchange(t *testing.T) {
440441
require.NoError(t, err)
441442
dummySig, err := dummyKey.Sign([]byte("test"))
442443
require.NoError(t, err)
444+
dummySigBytes := dummySig.Serialize()
443445

444446
// Mock the certificate verification to always succeed
445447
aliceWallet.MockVerifySignature = func(ctx context.Context, args wallet.VerifySignatureArgs, originator string) (*wallet.VerifySignatureResult, error) {
@@ -535,10 +537,10 @@ func TestPeerCertificateExchange(t *testing.T) {
535537

536538
// Setup crypto operations
537539
aliceWallet.MockCreateSignature = func(ctx context.Context, args wallet.CreateSignatureArgs, originator string) (*wallet.CreateSignatureResult, error) {
538-
return &wallet.CreateSignatureResult{Signature: *dummySig}, nil
540+
return &wallet.CreateSignatureResult{Signature: dummySigBytes}, nil
539541
}
540542
bobWallet.MockCreateSignature = func(ctx context.Context, args wallet.CreateSignatureArgs, originator string) (*wallet.CreateSignatureResult, error) {
541-
return &wallet.CreateSignatureResult{Signature: *dummySig}, nil
543+
return &wallet.CreateSignatureResult{Signature: dummySigBytes}, nil
542544
}
543545

544546
// Force all signature verifications to succeed
@@ -744,12 +746,13 @@ func TestPeerMultiDeviceAuthentication(t *testing.T) {
744746
// Setup crypto operations for both Alice wallets
745747
dummyAliceSig, err := alicePk.Sign([]byte("test"))
746748
require.NoError(t, err)
749+
dummyAliceSigBytes := dummyAliceSig.Serialize()
747750

748751
aliceWallet1.MockCreateSignature = func(ctx context.Context, args wallet.CreateSignatureArgs, originator string) (*wallet.CreateSignatureResult, error) {
749-
return &wallet.CreateSignatureResult{Signature: *dummyAliceSig}, nil
752+
return &wallet.CreateSignatureResult{Signature: dummyAliceSigBytes}, nil
750753
}
751754
aliceWallet2.MockCreateSignature = func(ctx context.Context, args wallet.CreateSignatureArgs, originator string) (*wallet.CreateSignatureResult, error) {
752-
return &wallet.CreateSignatureResult{Signature: *dummyAliceSig}, nil
755+
return &wallet.CreateSignatureResult{Signature: dummyAliceSigBytes}, nil
753756
}
754757

755758
aliceWallet1.MockVerifySignature = func(ctx context.Context, args wallet.VerifySignatureArgs, originator string) (*wallet.VerifySignatureResult, error) {
@@ -797,16 +800,17 @@ func TestPeerMultiDeviceAuthentication(t *testing.T) {
797800
// Setup Bob's crypto operations
798801
dummyBobSig, err := bobPk.Sign([]byte("test"))
799802
require.NoError(t, err)
803+
dummyBobSigBytes := dummyBobSig.Serialize()
800804

801805
bobWallet1.MockCreateSignature = func(ctx context.Context, args wallet.CreateSignatureArgs, originator string) (*wallet.CreateSignatureResult, error) {
802-
return &wallet.CreateSignatureResult{Signature: *dummyBobSig}, nil
806+
return &wallet.CreateSignatureResult{Signature: dummyBobSigBytes}, nil
803807
}
804808
bobWallet1.MockVerifySignature = func(ctx context.Context, args wallet.VerifySignatureArgs, originator string) (*wallet.VerifySignatureResult, error) {
805809
return &wallet.VerifySignatureResult{Valid: true}, nil
806810
}
807811

808812
bobWallet2.MockCreateSignature = func(ctx context.Context, args wallet.CreateSignatureArgs, originator string) (*wallet.CreateSignatureResult, error) {
809-
return &wallet.CreateSignatureResult{Signature: *dummyBobSig}, nil
813+
return &wallet.CreateSignatureResult{Signature: dummyBobSigBytes}, nil
810814
}
811815
bobWallet2.MockVerifySignature = func(ctx context.Context, args wallet.VerifySignatureArgs, originator string) (*wallet.VerifySignatureResult, error) {
812816
return &wallet.VerifySignatureResult{Valid: true}, nil
@@ -969,6 +973,7 @@ func TestPartialCertificateAcceptance(t *testing.T) {
969973
require.NoError(t, err)
970974
dummySig, err := dummyKey.Sign([]byte("test"))
971975
require.NoError(t, err)
976+
dummySigBytes := dummySig.Serialize()
972977

973978
// Mock the certificate verification to always succeed
974979
aliceWallet.MockVerifySignature = func(ctx context.Context, args wallet.VerifySignatureArgs, originator string) (*wallet.VerifySignatureResult, error) {
@@ -1060,10 +1065,10 @@ func TestPartialCertificateAcceptance(t *testing.T) {
10601065

10611066
// Setup crypto operations
10621067
aliceWallet.MockCreateSignature = func(ctx context.Context, args wallet.CreateSignatureArgs, originator string) (*wallet.CreateSignatureResult, error) {
1063-
return &wallet.CreateSignatureResult{Signature: *dummySig}, nil
1068+
return &wallet.CreateSignatureResult{Signature: dummySigBytes}, nil
10641069
}
10651070
bobWallet.MockCreateSignature = func(ctx context.Context, args wallet.CreateSignatureArgs, originator string) (*wallet.CreateSignatureResult, error) {
1066-
return &wallet.CreateSignatureResult{Signature: *dummySig}, nil
1071+
return &wallet.CreateSignatureResult{Signature: dummySigBytes}, nil
10671072
}
10681073

10691074
// Force all signature verifications to succeed
@@ -1281,6 +1286,7 @@ func TestLibraryCardVerification(t *testing.T) {
12811286
require.NoError(t, err)
12821287
dummySig, err := dummyKey.Sign([]byte("test"))
12831288
require.NoError(t, err)
1289+
dummySigBytes := dummySig.Serialize()
12841290

12851291
// Mock the certificate verification to always succeed
12861292
aliceWallet.MockVerifySignature = func(ctx context.Context, args wallet.VerifySignatureArgs, originator string) (*wallet.VerifySignatureResult, error) {
@@ -1336,10 +1342,10 @@ func TestLibraryCardVerification(t *testing.T) {
13361342

13371343
// Setup crypto operations
13381344
aliceWallet.MockCreateSignature = func(ctx context.Context, args wallet.CreateSignatureArgs, originator string) (*wallet.CreateSignatureResult, error) {
1339-
return &wallet.CreateSignatureResult{Signature: *dummySig}, nil
1345+
return &wallet.CreateSignatureResult{Signature: dummySigBytes}, nil
13401346
}
13411347
bobWallet.MockCreateSignature = func(ctx context.Context, args wallet.CreateSignatureArgs, originator string) (*wallet.CreateSignatureResult, error) {
1342-
return &wallet.CreateSignatureResult{Signature: *dummySig}, nil
1348+
return &wallet.CreateSignatureResult{Signature: dummySigBytes}, nil
13431349
}
13441350

13451351
// Force all signature verifications to succeed
@@ -1616,12 +1622,13 @@ func TestNonmatchingCertificateRejection(t *testing.T) {
16161622
// Set up crypto functions
16171623
dummySig, err := aliceKey.Sign([]byte("test"))
16181624
require.NoError(t, err)
1625+
dummySigBytes := dummySig.Serialize()
16191626

16201627
aliceWallet.MockCreateSignature = func(ctx context.Context, args wallet.CreateSignatureArgs, originator string) (*wallet.CreateSignatureResult, error) {
1621-
return &wallet.CreateSignatureResult{Signature: *dummySig}, nil
1628+
return &wallet.CreateSignatureResult{Signature: dummySigBytes}, nil
16221629
}
16231630
bobWallet.MockCreateSignature = func(ctx context.Context, args wallet.CreateSignatureArgs, originator string) (*wallet.CreateSignatureResult, error) {
1624-
return &wallet.CreateSignatureResult{Signature: *dummySig}, nil
1631+
return &wallet.CreateSignatureResult{Signature: dummySigBytes}, nil
16251632
}
16261633

16271634
aliceWallet.MockVerifySignature = func(ctx context.Context, args wallet.VerifySignatureArgs, originator string) (*wallet.VerifySignatureResult, error) {

docs/examples/create_signature/create_signature.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func main() {
4949
if err != nil {
5050
log.Fatalf("Failed to create signature for self: %v", err)
5151
}
52-
fmt.Printf("Signature created (R: %x, S: %x)\n", sigResult.Signature.R.Bytes(), sigResult.Signature.S.Bytes())
52+
fmt.Printf("Signature created (%x)\n", sigResult.Signature)
5353

5454
// --- 3. Verify Signature (by self) ---
5555
fmt.Println("\n--- 3. Verifying the signature (by self) ---")
@@ -124,7 +124,7 @@ func main() {
124124
if err != nil {
125125
log.Fatalf("Failed to create signature for hash (for self): %v", err)
126126
}
127-
fmt.Printf("Signature for hash created (R: %x, S: %x)\n", sigFromHashResult.Signature.R.Bytes(), sigFromHashResult.Signature.S.Bytes())
127+
fmt.Printf("Signature for hash created (%x)\n", sigFromHashResult.Signature)
128128

129129
// --- 6. Verify Signature of Pre-computed Hash (by self) ---
130130
fmt.Println("\n--- 6. Verifying signature of pre-computed hash (by self) ---")

identity/client_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -405,10 +405,10 @@ func TestPubliclyRevealAttributes(t *testing.T) {
405405
specificMockWallet.MockCreateSignature = func(ctx context.Context, args wallet.CreateSignatureArgs, originator string) (*wallet.CreateSignatureResult, error) {
406406
// Create a simple signature with R=1, S=1
407407
return &wallet.CreateSignatureResult{
408-
Signature: ec.Signature{
408+
Signature: (&ec.Signature{
409409
R: big.NewInt(1),
410410
S: big.NewInt(1),
411-
},
411+
}).Serialize(),
412412
}, nil
413413
}
414414

@@ -481,10 +481,10 @@ func TestPubliclyRevealAttributes(t *testing.T) {
481481
specificMockWallet.MockCreateSignature = func(ctx context.Context, args wallet.CreateSignatureArgs, originator string) (*wallet.CreateSignatureResult, error) {
482482
// Create a simple signature with R=1, S=1
483483
return &wallet.CreateSignatureResult{
484-
Signature: ec.Signature{
484+
Signature: (&ec.Signature{
485485
R: big.NewInt(1),
486486
S: big.NewInt(1),
487-
},
487+
}).Serialize(),
488488
}, nil
489489
}
490490

@@ -560,10 +560,10 @@ func TestPubliclyRevealAttributes(t *testing.T) {
560560
// Mock CreateSignature to succeed
561561
specificMockWallet.MockCreateSignature = func(ctx context.Context, args wallet.CreateSignatureArgs, originator string) (*wallet.CreateSignatureResult, error) {
562562
return &wallet.CreateSignatureResult{
563-
Signature: ec.Signature{
563+
Signature: (&ec.Signature{
564564
R: big.NewInt(1),
565565
S: big.NewInt(1),
566-
},
566+
}).Serialize(),
567567
}, nil
568568
}
569569

@@ -653,10 +653,10 @@ func TestPubliclyRevealAttributes(t *testing.T) {
653653

654654
specificMockWallet.MockCreateSignature = func(ctx context.Context, args wallet.CreateSignatureArgs, originator string) (*wallet.CreateSignatureResult, error) {
655655
return &wallet.CreateSignatureResult{
656-
Signature: ec.Signature{
656+
Signature: (&ec.Signature{
657657
R: big.NewInt(1),
658658
S: big.NewInt(1),
659-
},
659+
}).Serialize(),
660660
}, nil
661661
}
662662

registry/registry_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ func TestRegistryClient_RegisterDefinition(t *testing.T) {
110110

111111
// Setup mock CreateSignature response
112112
mockRegistry.CreateSignatureResult = &wallet.CreateSignatureResult{
113-
Signature: ec.Signature{
113+
Signature: (&ec.Signature{
114114
R: big.NewInt(1),
115115
S: big.NewInt(1),
116-
},
116+
}).Serialize(),
117117
}
118118

119119
// Create registry client with mock wallet
@@ -428,10 +428,10 @@ func TestRegistryClient_RevokeOwnRegistryEntry(t *testing.T) {
428428

429429
// Setup mock CreateSignature response
430430
mockRegistry.CreateSignatureResult = &wallet.CreateSignatureResult{
431-
Signature: ec.Signature{
431+
Signature: (&ec.Signature{
432432
R: big.NewInt(1),
433433
S: big.NewInt(1),
434-
},
434+
}).Serialize(),
435435
}
436436

437437
// Create registry client with mock wallet
@@ -655,10 +655,10 @@ func TestRegistryClient_RegisterDefinition_PushDrop(t *testing.T) {
655655

656656
// Setup mock CreateSignature response
657657
mockRegistry.CreateSignatureResult = &wallet.CreateSignatureResult{
658-
Signature: ec.Signature{
658+
Signature: (&ec.Signature{
659659
R: big.NewInt(1),
660660
S: big.NewInt(1),
661-
},
661+
}).Serialize(),
662662
}
663663

664664
// Create registry client with mock wallet

transaction/template/pushdrop/pushdrop.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ func (p *PushDropTemplate) Lock(
9696
if err != nil {
9797
return nil, fmt.Errorf("error creating wallet signature for lock: %w", err)
9898
}
99-
fields = append(fields, sig.Signature.Serialize())
99+
fields = append(fields, sig.Signature)
100100
}
101101
pushDropChunks := make([]*script.ScriptChunk, 0)
102102
for _, field := range fields {
@@ -184,7 +184,7 @@ func (p *PushDropUnlocker) Sign(
184184
}
185185
s := (&script.Script{})
186186
// Error throws if data is too big which wont happen here
187-
_ = s.AppendPushData(sig.Signature.Serialize())
187+
_ = s.AppendPushData(sig.Signature)
188188
return s, nil
189189
}
190190

0 commit comments

Comments
 (0)