@@ -23,13 +23,8 @@ import (
23
23
"github.com/supabase/cli/pkg/config"
24
24
)
25
25
26
- type KeyPair struct {
27
- PublicKey config.JWK
28
- PrivateKey config.JWK
29
- }
30
-
31
- // GenerateKeyPair generates a new key pair for the specified algorithm
32
- func GenerateKeyPair (alg config.Algorithm ) (* KeyPair , error ) {
26
+ // GeneratePrivateKey generates a new private key for the specified algorithm
27
+ func GeneratePrivateKey (alg config.Algorithm ) (* config.JWK , error ) {
33
28
keyID := uuid .New ()
34
29
35
30
switch alg {
@@ -42,7 +37,7 @@ func GenerateKeyPair(alg config.Algorithm) (*KeyPair, error) {
42
37
}
43
38
}
44
39
45
- func generateRSAKeyPair (keyID uuid.UUID ) (* KeyPair , error ) {
40
+ func generateRSAKeyPair (keyID uuid.UUID ) (* config. JWK , error ) {
46
41
// Generate RSA key pair (2048 bits for RS256)
47
42
privateKey , err := rsa .GenerateKey (rand .Reader , 2048 )
48
43
if err != nil {
@@ -72,24 +67,10 @@ func generateRSAKeyPair(keyID uuid.UUID) (*KeyPair, error) {
72
67
FirstCRTCoefficient : base64 .RawURLEncoding .EncodeToString (privateKey .Precomputed .Qinv .Bytes ()),
73
68
}
74
69
75
- publicJWK := config.JWK {
76
- KeyType : "RSA" ,
77
- KeyID : keyID ,
78
- Use : "sig" ,
79
- KeyOps : []string {"verify" },
80
- Algorithm : "RS256" ,
81
- Extractable : cast .Ptr (true ),
82
- Modulus : privateJWK .Modulus ,
83
- Exponent : privateJWK .Exponent ,
84
- }
85
-
86
- return & KeyPair {
87
- PublicKey : publicJWK ,
88
- PrivateKey : privateJWK ,
89
- }, nil
70
+ return & privateJWK , nil
90
71
}
91
72
92
- func generateECDSAKeyPair (keyID uuid.UUID ) (* KeyPair , error ) {
73
+ func generateECDSAKeyPair (keyID uuid.UUID ) (* config. JWK , error ) {
93
74
// Generate ECDSA key pair (P-256 curve for ES256)
94
75
privateKey , err := ecdsa .GenerateKey (elliptic .P256 (), rand .Reader )
95
76
if err != nil {
@@ -112,22 +93,7 @@ func generateECDSAKeyPair(keyID uuid.UUID) (*KeyPair, error) {
112
93
PrivateExponent : base64 .RawURLEncoding .EncodeToString (privateKey .D .Bytes ()),
113
94
}
114
95
115
- publicJWK := config.JWK {
116
- KeyType : "EC" ,
117
- KeyID : keyID ,
118
- Use : "sig" ,
119
- KeyOps : []string {"verify" },
120
- Algorithm : "ES256" ,
121
- Extractable : cast .Ptr (true ),
122
- Curve : "P-256" ,
123
- X : privateJWK .X ,
124
- Y : privateJWK .Y ,
125
- }
126
-
127
- return & KeyPair {
128
- PublicKey : publicJWK ,
129
- PrivateKey : privateJWK ,
130
- }, nil
96
+ return & privateJWK , nil
131
97
}
132
98
133
99
// Run generates a key pair and writes it to the specified file path
@@ -139,7 +105,7 @@ func Run(ctx context.Context, algorithm string, appendMode bool, fsys afero.Fs)
139
105
outputPath := utils .Config .Auth .SigningKeysPath
140
106
141
107
// Generate key pair
142
- keyPair , err := GenerateKeyPair (config .Algorithm (algorithm ))
108
+ privateJWK , err := GeneratePrivateKey (config .Algorithm (algorithm ))
143
109
if err != nil {
144
110
return err
145
111
}
@@ -181,7 +147,7 @@ func Run(ctx context.Context, algorithm string, appendMode bool, fsys afero.Fs)
181
147
}
182
148
out = f
183
149
}
184
- jwkArray = append (jwkArray , keyPair . PrivateKey )
150
+ jwkArray = append (jwkArray , * privateJWK )
185
151
186
152
// Write to file
187
153
enc := json .NewEncoder (out )
0 commit comments