Skip to content

Commit 2960c90

Browse files
committed
staticaddr: address review comments
1 parent dcc6d58 commit 2960c90

2 files changed

Lines changed: 22 additions & 5 deletions

File tree

staticaddr/address/manager.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,17 +246,22 @@ func validateServerAddressParams(
246246
return fmt.Errorf("missing server address parameters")
247247
}
248248

249-
if len(params.GetServerKey()) == 0 {
249+
serverKey := params.GetServerKey()
250+
if len(serverKey) == 0 {
250251
return fmt.Errorf("missing server public key")
251252
}
253+
if !btcec.IsCompressedPubKey(serverKey) {
254+
return fmt.Errorf("server public key is not a compressed " +
255+
"secp256k1 public key")
256+
}
252257

253258
expiry := params.GetExpiry()
254259
switch {
255260
case expiry == 0:
256261
return fmt.Errorf("static address CSV expiry must be non-zero")
257262

258263
case expiry&^wire.SequenceLockTimeMask != 0:
259-
return fmt.Errorf("invalid static address CSV flags: %x",
264+
return fmt.Errorf("static address expiry does not fit into CSV: %x",
260265
expiry)
261266

262267
case expiry > maxStaticAddressCSVExpiry:

staticaddr/address/manager_test.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,16 @@ func TestNewAddressValidatesServerResponse(t *testing.T) {
156156
},
157157
expected: "missing server public key",
158158
},
159+
{
160+
name: "uncompressed server key",
161+
resp: &swapserverrpc.ServerNewAddressResponse{
162+
Params: &swapserverrpc.ServerAddressParameters{
163+
ServerKey: []byte{0x04},
164+
Expiry: defaultExpiry,
165+
},
166+
},
167+
expected: "server public key is not a compressed",
168+
},
159169
{
160170
name: "zero expiry",
161171
resp: newServerNewAddressResponse(0),
@@ -166,21 +176,21 @@ func TestNewAddressValidatesServerResponse(t *testing.T) {
166176
resp: newServerNewAddressResponse(
167177
wire.SequenceLockTimeIsSeconds | 1,
168178
),
169-
expected: "invalid static address CSV flags",
179+
expected: "static address expiry does not fit into CSV",
170180
},
171181
{
172182
name: "disabled flag",
173183
resp: newServerNewAddressResponse(
174184
wire.SequenceLockTimeDisabled | 1,
175185
),
176-
expected: "invalid static address CSV flags",
186+
expected: "static address expiry does not fit into CSV",
177187
},
178188
{
179189
name: "reserved flag",
180190
resp: newServerNewAddressResponse(
181191
wire.SequenceLockTimeMask + 1,
182192
),
183-
expected: "invalid static address CSV flags",
193+
expected: "static address expiry does not fit into CSV",
184194
},
185195
{
186196
name: "too large",
@@ -305,6 +315,8 @@ func NewAddressManagerTestContextWithResponse(t *testing.T,
305315
}
306316
}
307317

318+
// newServerNewAddressResponse returns a valid server response with the given
319+
// CSV expiry.
308320
func newServerNewAddressResponse(expiry uint32) *swapserverrpc.ServerNewAddressResponse {
309321
return &swapserverrpc.ServerNewAddressResponse{
310322
Params: &swapserverrpc.ServerAddressParameters{

0 commit comments

Comments
 (0)