-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsignables.gen.go
More file actions
101 lines (93 loc) · 4.44 KB
/
Copy pathsignables.gen.go
File metadata and controls
101 lines (93 loc) · 4.44 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
// Code generated by signablegen; DO NOT EDIT.
package generated
import (
"context"
"fmt"
"github.com/jshufro/remote-signer-dirk-interop/pkg/errors"
apiv1 "github.com/attestantio/go-eth2-client/api/v1"
"github.com/attestantio/go-eth2-client/spec/altair"
"github.com/attestantio/go-eth2-client/spec/electra"
"github.com/attestantio/go-eth2-client/spec/phase0"
)
type AggregateAndProofElectra = electra.AggregateAndProof
type AggregateAndProofPhase0 = phase0.AggregateAndProof
type AttestationData = phase0.AttestationData
type BeaconBlock = phase0.BeaconBlock
type BeaconBlockAltair = altair.BeaconBlock
type BeaconBlockHeader = phase0.BeaconBlockHeader
type ContributionAndProof = altair.ContributionAndProof
type SyncAggregatorSelectionData = altair.SyncAggregatorSelectionData
type ValidatorRegistration = apiv1.ValidatorRegistration
type VoluntaryExit = phase0.VoluntaryExit
// Signer combines all signable request types from the remote signing API.
type Signer[AccountType any] interface {
AggregationSlotSigning(context.Context, AccountType, *AggregationSlotSigning) ([96]byte, error)
AggregateAndProofSigningV2(context.Context, AccountType, *AggregateAndProofSigningV2) ([96]byte, error)
AttestationSigning(context.Context, AccountType, *AttestationSigning) ([96]byte, error)
BeaconBlockSigning(context.Context, AccountType, *BeaconBlockSigning) ([96]byte, error)
DepositSigning(context.Context, AccountType, *DepositSigning) ([96]byte, error)
RandaoRevealSigning(context.Context, AccountType, *RandaoRevealSigning) ([96]byte, error)
VoluntaryExitSigning(context.Context, AccountType, *VoluntaryExitSigning) ([96]byte, error)
SyncCommitteeMessageSigning(context.Context, AccountType, *SyncCommitteeMessageSigning) ([96]byte, error)
SyncCommitteeSelectionProofSigning(context.Context, AccountType, *SyncCommitteeSelectionProofSigning) ([96]byte, error)
SyncCommitteeContributionAndProofSigning(context.Context, AccountType, *SyncCommitteeContributionAndProofSigning) ([96]byte, error)
ValidatorRegistrationSigning(context.Context, AccountType, *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 &AggregateAndProofSigningV2{}, nil
case "AGGREGATION_SLOT":
return &AggregationSlotSigning{}, nil
case "ATTESTATION":
return &AttestationSigning{}, nil
case "BLOCK_V2":
return &BeaconBlockSigning{}, nil
case "DEPOSIT":
return &DepositSigning{}, nil
case "RANDAO_REVEAL":
return &RandaoRevealSigning{}, nil
case "SYNC_COMMITTEE_CONTRIBUTION_AND_PROOF":
return &SyncCommitteeContributionAndProofSigning{}, nil
case "SYNC_COMMITTEE_MESSAGE":
return &SyncCommitteeMessageSigning{}, nil
case "SYNC_COMMITTEE_SELECTION_PROOF":
return &SyncCommitteeSelectionProofSigning{}, nil
case "VALIDATOR_REGISTRATION":
return &ValidatorRegistrationSigning{}, nil
case "VOLUNTARY_EXIT":
return &VoluntaryExitSigning{}, nil
default:
return nil, fmt.Errorf("unknown discriminator value: %s", discriminator)
}
}
// 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) ([96]byte, error) {
switch signable := signable.(type) {
case *AggregationSlotSigning:
return signer.AggregationSlotSigning(ctx, account, signable)
case *AggregateAndProofSigningV2:
return signer.AggregateAndProofSigningV2(ctx, account, signable)
case *AttestationSigning:
return signer.AttestationSigning(ctx, account, signable)
case *BeaconBlockSigning:
return signer.BeaconBlockSigning(ctx, account, signable)
case *DepositSigning:
return signer.DepositSigning(ctx, account, signable)
case *RandaoRevealSigning:
return signer.RandaoRevealSigning(ctx, account, signable)
case *VoluntaryExitSigning:
return signer.VoluntaryExitSigning(ctx, account, signable)
case *SyncCommitteeMessageSigning:
return signer.SyncCommitteeMessageSigning(ctx, account, signable)
case *SyncCommitteeSelectionProofSigning:
return signer.SyncCommitteeSelectionProofSigning(ctx, account, signable)
case *SyncCommitteeContributionAndProofSigning:
return signer.SyncCommitteeContributionAndProofSigning(ctx, account, signable)
case *ValidatorRegistrationSigning:
return signer.ValidatorRegistrationSigning(ctx, account, signable)
default:
return [96]byte{}, errors.InternalServerError()
}
}