From d81aa509cd409007d3a1c8397bbcac8080eeb882 Mon Sep 17 00:00:00 2001 From: Nathan Seva Date: Mon, 18 Dec 2023 12:02:49 -0500 Subject: [PATCH] add chain id in API body --- api/server/models/sign_request.go | 17 +++++++++++++++++ api/server/restapi/embedded_spec.go | 14 ++++++++++++-- api/walletApi-V0.yml | 4 ++++ internal/handler/wallet/sign_test.go | 8 ++++---- 4 files changed, 37 insertions(+), 6 deletions(-) diff --git a/api/server/models/sign_request.go b/api/server/models/sign_request.go index 850eb3b7f..091038d00 100644 --- a/api/server/models/sign_request.go +++ b/api/server/models/sign_request.go @@ -22,6 +22,10 @@ type SignRequest struct { // A boolean property that indicates whether the sign operation is part of a batch of operations. Set to true if this operation is part of a batch, otherwise set to false. Batch bool `json:"batch,omitempty"` + // The chain id of the network to which the operation will be sent. + // Required: true + ChainID *int64 `json:"chainId"` + // correlation Id // Format: byte CorrelationID CorrelationID `json:"correlationId,omitempty"` @@ -40,6 +44,10 @@ type SignRequest struct { func (m *SignRequest) Validate(formats strfmt.Registry) error { var res []error + if err := m.validateChainID(formats); err != nil { + res = append(res, err) + } + if err := m.validateCorrelationID(formats); err != nil { res = append(res, err) } @@ -58,6 +66,15 @@ func (m *SignRequest) Validate(formats strfmt.Registry) error { return nil } +func (m *SignRequest) validateChainID(formats strfmt.Registry) error { + + if err := validate.Required("chainId", "body", m.ChainID); err != nil { + return err + } + + return nil +} + func (m *SignRequest) validateCorrelationID(formats strfmt.Registry) error { if swag.IsZero(m.CorrelationID) { // not required return nil diff --git a/api/server/restapi/embedded_spec.go b/api/server/restapi/embedded_spec.go index ee91e2c59..5215af6a7 100644 --- a/api/server/restapi/embedded_spec.go +++ b/api/server/restapi/embedded_spec.go @@ -1016,13 +1016,18 @@ func init() { "SignRequest": { "type": "object", "required": [ - "operation" + "operation", + "chainId" ], "properties": { "batch": { "description": "A boolean property that indicates whether the sign operation is part of a batch of operations. Set to true if this operation is part of a batch, otherwise set to false.", "type": "boolean" }, + "chainId": { + "description": "The chain id of the network to which the operation will be sent.", + "type": "integer" + }, "correlationId": { "$ref": "#/definitions/CorrelationId" }, @@ -2185,13 +2190,18 @@ func init() { "SignRequest": { "type": "object", "required": [ - "operation" + "operation", + "chainId" ], "properties": { "batch": { "description": "A boolean property that indicates whether the sign operation is part of a batch of operations. Set to true if this operation is part of a batch, otherwise set to false.", "type": "boolean" }, + "chainId": { + "description": "The chain id of the network to which the operation will be sent.", + "type": "integer" + }, "correlationId": { "$ref": "#/definitions/CorrelationId" }, diff --git a/api/walletApi-V0.yml b/api/walletApi-V0.yml index 90bc8c25c..eaccfd7c3 100644 --- a/api/walletApi-V0.yml +++ b/api/walletApi-V0.yml @@ -555,6 +555,7 @@ definitions: type: object required: - operation + - chainId properties: description: type: string @@ -569,6 +570,9 @@ definitions: type: boolean correlationId: $ref: "#/definitions/CorrelationId" + chainId: + type: integer + description: The chain id of the network to which the operation will be sent. SignMessageRequest: type: object diff --git a/internal/handler/wallet/sign_test.go b/internal/handler/wallet/sign_test.go index c65279d67..c84e9d085 100644 --- a/internal/handler/wallet/sign_test.go +++ b/internal/handler/wallet/sign_test.go @@ -55,7 +55,7 @@ func Test_walletSign_Handle(t *testing.T) { api, prompterApp, _, resChan, err := MockAPI() assert.NoError(t, err) - transactionData := fmt.Sprintf(`{"operation":"%s"}`, callSCString) + transactionData := fmt.Sprintf(`{"chainId": 1, "operation":"%s"}`, callSCString) nickname := "walletToDelete" password := "zePassword" createAccount(password, nickname, t, prompterApp) @@ -151,7 +151,7 @@ func Test_walletSign_Handle(t *testing.T) { }) t.Run("sign transaction batch", func(t *testing.T) { - transactionDataBatch := fmt.Sprintf(`{"operation":"%s","batch":true}`, callSCString) + transactionDataBatch := fmt.Sprintf(`{"chainId": 1, "operation":"%s","batch":true}`, callSCString) testResult := make(chan walletapp.EventData) // Send password to prompter app and wait for result @@ -174,14 +174,14 @@ func Test_walletSign_Handle(t *testing.T) { correlationId := base64.StdEncoding.EncodeToString(body.CorrelationID) - transactionDataBatch = fmt.Sprintf(`{"operation":"%s","correlationId":"%s"}`, callSCString, correlationId) + transactionDataBatch = fmt.Sprintf(`{"chainId": 1, "operation":"%s","correlationId":"%s"}`, callSCString, correlationId) // Send new transaction without password prompt resp = signTransaction(t, api, nickname, transactionDataBatch) verifyStatusCode(t, resp, http.StatusOK) // Send new transaction with incorrect correlation id correlationId = base64.StdEncoding.EncodeToString([]byte("wrong correlation id")) - transactionDataBatch = fmt.Sprintf(`{"operation":"%s","correlationId":"%s"}`, callSCString, correlationId) + transactionDataBatch = fmt.Sprintf(`{"chainId": 1, "operation":"%s","correlationId":"%s"}`, callSCString, correlationId) resp = signTransaction(t, api, nickname, transactionDataBatch) var bodyError operations.SignInternalServerError err = json.Unmarshal(resp.Body.Bytes(), &bodyError)