-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsign.gen.go
More file actions
117 lines (109 loc) · 4.97 KB
/
Copy pathsign.gen.go
File metadata and controls
117 lines (109 loc) · 4.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
// Code generated by signablegen; DO NOT EDIT.
package generated
import (
"context"
"fmt"
"github.com/jshufro/remote-signer-dirk-interop/pkg/errors"
"github.com/jshufro/remote-signer-dirk-interop/pkg/fork"
"github.com/jshufro/remote-signer-dirk-interop/generated/api"
)
// Signer combines all signable request types from the remote signing API.
type Signer[AccountType any] interface {
AggregationSlotSigning(context.Context, AccountType, *api.AggregationSlotSigning, *fork.ForkInfo) ([96]byte, error)
AggregateAndProofSigningV2(context.Context, AccountType, *api.AggregateAndProofSigningV2, *fork.ForkInfo) ([96]byte, error)
AttestationSigning(context.Context, AccountType, *api.AttestationSigning, *fork.ForkInfo) ([96]byte, error)
BeaconBlockSigning(context.Context, AccountType, *api.BeaconBlockSigning, *fork.ForkInfo) ([96]byte, error)
DepositSigning(context.Context, AccountType, *api.DepositSigning) ([96]byte, error)
RandaoRevealSigning(context.Context, AccountType, *api.RandaoRevealSigning, *fork.ForkInfo) ([96]byte, error)
VoluntaryExitSigning(context.Context, AccountType, *api.VoluntaryExitSigning, *fork.ForkInfo) ([96]byte, error)
SyncCommitteeMessageSigning(context.Context, AccountType, *api.SyncCommitteeMessageSigning, *fork.ForkInfo) ([96]byte, error)
SyncCommitteeSelectionProofSigning(context.Context, AccountType, *api.SyncCommitteeSelectionProofSigning, *fork.ForkInfo) ([96]byte, error)
SyncCommitteeContributionAndProofSigning(context.Context, AccountType, *api.SyncCommitteeContributionAndProofSigning, *fork.ForkInfo) ([96]byte, error)
ValidatorRegistrationSigning(context.Context, AccountType, *api.ValidatorRegistrationSigning) ([96]byte, error)
}
// StringToSignableType converts a discriminator string to a signable type.
func StringToSignableType(discriminator string) (any, error) {
switch discriminator {
case "AGGREGATE_AND_PROOF_V2":
return &api.AggregateAndProofSigningV2{}, nil
case "AGGREGATION_SLOT":
return &api.AggregationSlotSigning{}, nil
case "ATTESTATION":
return &api.AttestationSigning{}, nil
case "BLOCK_V2":
return &api.BeaconBlockSigning{}, nil
case "DEPOSIT":
return &api.DepositSigning{}, nil
case "RANDAO_REVEAL":
return &api.RandaoRevealSigning{}, nil
case "SYNC_COMMITTEE_CONTRIBUTION_AND_PROOF":
return &api.SyncCommitteeContributionAndProofSigning{}, nil
case "SYNC_COMMITTEE_MESSAGE":
return &api.SyncCommitteeMessageSigning{}, nil
case "SYNC_COMMITTEE_SELECTION_PROOF":
return &api.SyncCommitteeSelectionProofSigning{}, nil
case "VALIDATOR_REGISTRATION":
return &api.ValidatorRegistrationSigning{}, nil
case "VOLUNTARY_EXIT":
return &api.VoluntaryExitSigning{}, nil
default:
return nil, fmt.Errorf("unknown discriminator value: %s", discriminator)
}
}
// ForkInfoRequired returns true if the signable requires a fork info.
func ForkInfoRequired(signable any) bool {
switch signable.(type) {
case *api.AggregationSlotSigning:
return true
case *api.AggregateAndProofSigningV2:
return true
case *api.AttestationSigning:
return true
case *api.BeaconBlockSigning:
return true
case *api.RandaoRevealSigning:
return true
case *api.VoluntaryExitSigning:
return true
case *api.SyncCommitteeMessageSigning:
return true
case *api.SyncCommitteeSelectionProofSigning:
return true
case *api.SyncCommitteeContributionAndProofSigning:
return true
default:
return false
}
}
// Sign calls the appropriate sign method based on the type of the signable.
func Sign[AccountType any](ctx context.Context, signer Signer[AccountType], account AccountType, signable any, forkInfo *fork.ForkInfo) ([96]byte, error) {
if ForkInfoRequired(signable) && forkInfo == nil {
return [96]byte{}, errors.BadRequest("fork_info is required")
}
switch signable := signable.(type) {
case *api.AggregationSlotSigning:
return signer.AggregationSlotSigning(ctx, account, signable, forkInfo)
case *api.AggregateAndProofSigningV2:
return signer.AggregateAndProofSigningV2(ctx, account, signable, forkInfo)
case *api.AttestationSigning:
return signer.AttestationSigning(ctx, account, signable, forkInfo)
case *api.BeaconBlockSigning:
return signer.BeaconBlockSigning(ctx, account, signable, forkInfo)
case *api.DepositSigning:
return signer.DepositSigning(ctx, account, signable)
case *api.RandaoRevealSigning:
return signer.RandaoRevealSigning(ctx, account, signable, forkInfo)
case *api.VoluntaryExitSigning:
return signer.VoluntaryExitSigning(ctx, account, signable, forkInfo)
case *api.SyncCommitteeMessageSigning:
return signer.SyncCommitteeMessageSigning(ctx, account, signable, forkInfo)
case *api.SyncCommitteeSelectionProofSigning:
return signer.SyncCommitteeSelectionProofSigning(ctx, account, signable, forkInfo)
case *api.SyncCommitteeContributionAndProofSigning:
return signer.SyncCommitteeContributionAndProofSigning(ctx, account, signable, forkInfo)
case *api.ValidatorRegistrationSigning:
return signer.ValidatorRegistrationSigning(ctx, account, signable)
default:
return [96]byte{}, errors.InternalServerError()
}
}