verify.go raw
1 // Package verify is the signature verification worker domain. It owns no
2 // state: it receives a public key, message hash and signature, and answers
3 // with a boolean. Several of these domains form the relay's verification pool.
4 package verify
5
6 import (
7 "git.smesh.lol/torly/pkg/crypto/secp256k1"
8 tinyspawn "git.smesh.lol/torly/pkg/tinyspawn"
9 "git.smesh.lol/torly/pkg/wire"
10 )
11
12 // Chans are the channels bound at spawn.
13 type Chans struct {
14 Req tinyspawn.Duplex[wire.VerifyRequest]
15 Resp tinyspawn.Duplex[wire.VerifyResponse]
16 Ready chan<- wire.Ready
17 Stop tinyspawn.Breaker
18 }
19
20 // Run is the domain entry point.
21 func Run(_ struct{}, ch Chans) {
22 ch.Ready <- wire.Ready{OK: true}
23 for {
24 select {
25 case req := <-ch.Req.Recv():
26 ok := secp256k1.Verify(req.Pub, req.Msg, req.Sig)
27 select {
28 case ch.Resp.Tx <- wire.VerifyResponse{ID: req.ID, OK: ok}:
29 case <-ch.Stop.Done():
30 return
31 }
32 case <-ch.Stop.Done():
33 return
34 }
35 }
36 }
37