Skip to content

Commit

Permalink
feat: REST binding for vc wallet commands
Browse files Browse the repository at this point in the history
- Part of hyperledger-archives#2770

Signed-off-by: sudesh.shetty <sudesh.shetty@securekey.com>
  • Loading branch information
sudeshrshetty committed Jan 22, 2022
1 parent 443a178 commit 6f2d212
Show file tree
Hide file tree
Showing 7 changed files with 1,898 additions and 19 deletions.
4 changes: 2 additions & 2 deletions pkg/controller/command/vcwallet/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func (o *Command) UpdateProfile(rw io.Writer, req io.Reader) command.Error {

// Open unlocks given user's wallet and returns a token for subsequent use of wallet features.
func (o *Command) Open(rw io.Writer, req io.Reader) command.Error {
request := &UnlockWalletRquest{}
request := &UnlockWalletRequest{}

err := json.NewDecoder(req).Decode(&request)
if err != nil {
Expand Down Expand Up @@ -586,7 +586,7 @@ func prepareProfileOptions(rqst *CreateOrUpdateProfileRequest) []wallet.ProfileO
}

// prepareUnlockOptions prepares options for unlocking wallet.
func prepareUnlockOptions(rqst *UnlockWalletRquest) []wallet.UnlockOptions {
func prepareUnlockOptions(rqst *UnlockWalletRequest) []wallet.UnlockOptions {
var options []wallet.UnlockOptions

if rqst.LocalKMSPassphrase != "" {
Expand Down
25 changes: 12 additions & 13 deletions pkg/controller/command/vcwallet/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,7 @@ func TestNew(t *testing.T) {
cmd := New(newMockProvider(t))
require.NotNil(t, cmd)

handlers := cmd.GetHandlers()
require.Equal(t, 13, len(handlers))
require.Len(t, cmd.GetHandlers(), 13)
})
}

Expand Down Expand Up @@ -524,7 +523,7 @@ func TestCommand_OpenAndClose(t *testing.T) {
t.Run("successfully unlock & lock wallet (local kms)", func(t *testing.T) {
cmd := New(mockctx)

request := &UnlockWalletRquest{
request := &UnlockWalletRequest{
UserID: sampleUser1,
LocalKMSPassphrase: samplePassPhrase,
}
Expand Down Expand Up @@ -562,7 +561,7 @@ func TestCommand_OpenAndClose(t *testing.T) {
t.Run("successfully unlock & lock wallet (remote kms)", func(t *testing.T) {
cmd := New(mockctx)

request := &UnlockWalletRquest{
request := &UnlockWalletRequest{
UserID: sampleUser2,
WebKMSAuth: sampleFakeTkn,
}
Expand Down Expand Up @@ -600,7 +599,7 @@ func TestCommand_OpenAndClose(t *testing.T) {
t.Run("successfully unlock & lock wallet (local kms, edv user)", func(t *testing.T) {
cmd := New(mockctx)

request := &UnlockWalletRquest{
request := &UnlockWalletRequest{
UserID: sampleUser3,
LocalKMSPassphrase: samplePassPhrase,
EDVUnlock: &EDVUnlockRequest{
Expand Down Expand Up @@ -643,7 +642,7 @@ func TestCommand_OpenAndClose(t *testing.T) {

var b bytes.Buffer

cmdErr := cmd.Open(&b, getReader(t, &UnlockWalletRquest{}))
cmdErr := cmd.Open(&b, getReader(t, &UnlockWalletRequest{}))
require.Error(t, cmdErr)
validateError(t, cmdErr, command.ExecuteError, OpenWalletErrorCode, "profile does not exist")
require.Empty(t, b.Len())
Expand All @@ -655,7 +654,7 @@ func TestCommand_OpenAndClose(t *testing.T) {
require.Empty(t, b.Len())
b.Reset()

cmdErr = cmd.Close(&b, getReader(t, &UnlockWalletRquest{}))
cmdErr = cmd.Close(&b, getReader(t, &UnlockWalletRequest{}))
require.Error(t, cmdErr)
validateError(t, cmdErr, command.ExecuteError, CloseWalletErrorCode, "profile does not exist")
require.Empty(t, b.Len())
Expand Down Expand Up @@ -683,7 +682,7 @@ func TestCommand_AddRemoveGetGetAll(t *testing.T) {
LocalKMSPassphrase: samplePassPhrase,
})

token1, lock1 := unlockWallet(t, mockctx, &UnlockWalletRquest{
token1, lock1 := unlockWallet(t, mockctx, &UnlockWalletRequest{
UserID: sampleUser1,
LocalKMSPassphrase: samplePassPhrase,
})
Expand All @@ -695,7 +694,7 @@ func TestCommand_AddRemoveGetGetAll(t *testing.T) {
KeyStoreURL: sampleKeyStoreURL,
})

token2, lock2 := unlockWallet(t, mockctx, &UnlockWalletRquest{
token2, lock2 := unlockWallet(t, mockctx, &UnlockWalletRequest{
UserID: sampleUser2,
WebKMSAuth: sampleFakeTkn,
})
Expand Down Expand Up @@ -948,7 +947,7 @@ func TestCommand_Query(t *testing.T) {
LocalKMSPassphrase: samplePassPhrase,
})

token, lock := unlockWallet(t, mockctx, &UnlockWalletRquest{
token, lock := unlockWallet(t, mockctx, &UnlockWalletRequest{
UserID: sampleUser1,
LocalKMSPassphrase: samplePassPhrase,
})
Expand Down Expand Up @@ -1070,7 +1069,7 @@ func TestCommand_IssueProveVerify(t *testing.T) {
LocalKMSPassphrase: samplePassPhrase,
})

token, lock := unlockWallet(t, mockctx, &UnlockWalletRquest{
token, lock := unlockWallet(t, mockctx, &UnlockWalletRequest{
UserID: sampleUser1,
LocalKMSPassphrase: samplePassPhrase,
})
Expand Down Expand Up @@ -1386,7 +1385,7 @@ func TestCommand_Derive(t *testing.T) {
LocalKMSPassphrase: samplePassPhrase,
})

token, lock := unlockWallet(t, mockctx, &UnlockWalletRquest{
token, lock := unlockWallet(t, mockctx, &UnlockWalletRequest{
UserID: sampleUser1,
LocalKMSPassphrase: samplePassPhrase,
})
Expand Down Expand Up @@ -1526,7 +1525,7 @@ func getUnlockToken(t *testing.T, b bytes.Buffer) string {
return response.Token
}

func unlockWallet(t *testing.T, ctx *mockprovider.Provider, request *UnlockWalletRquest) (string, func()) {
func unlockWallet(t *testing.T, ctx *mockprovider.Provider, request *UnlockWalletRequest) (string, func()) {
cmd := New(ctx)

var b bytes.Buffer
Expand Down
6 changes: 3 additions & 3 deletions pkg/controller/command/vcwallet/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ type EDVConfiguration struct {
MACKeyID string `json:"macKID,omitempty"`
}

// UnlockWalletRquest contains different options for unlocking wallet.
type UnlockWalletRquest struct {
// UnlockWalletRequest contains different options for unlocking wallet.
type UnlockWalletRequest struct {
// user ID of the wallet to be unlocked.
UserID string `json:"userID"`

Expand Down Expand Up @@ -96,7 +96,7 @@ type LockWalletResponse struct {
// Closed status of the wallet lock operation.
// if true, wallet is closed successfully
// if false, wallet is already closed or never unlocked.
Closed bool `json:"userID"`
Closed bool `json:"closed"`
}

// WalletAuth contains wallet auth parameters for performing wallet operations.
Expand Down
211 changes: 211 additions & 0 deletions pkg/controller/rest/vcwallet/models.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/

package vcwallet

import (
"github.com/hyperledger/aries-framework-go/pkg/controller/command/vcwallet"
)

// createOrUpdateProfileRequest is request model for
// creating a new wallet profile or updating an existing wallet profile.
//
// swagger:parameters createOrUpdateProfileReq
type createOrUpdateProfileRequest struct { // nolint: unused,deadcode
// Params for creating new wallet profile or for updating existing wallet profile.
//
// in: body
Params *vcwallet.CreateOrUpdateProfileRequest
}

// unlockWalletRequest contains different options for unlocking wallet.
//
// swagger:parameters unlockWalletReq
type unlockWalletRequest struct { // nolint: unused,deadcode
// Params for unlocking wallet.
//
// in: body
Params *vcwallet.UnlockWalletRequest
}

// unlockWalletResponse contains response for wallet unlock operation.
//
// swagger:response unlockWalletRes
type unlockWalletResponse struct { // nolint: unused,deadcode
// in: body
vcwallet.UnlockWalletResponse
}

// lockWalletRequest contains options for locking wallet.
//
// swagger:parameters lockWalletReq
type lockWalletRequest struct { // nolint: unused,deadcode
// Params for locking wallet.
//
// in: body
Params *vcwallet.LockWalletRequest
}

// lockWalletResponse contains response for wallet lock operation.
//
// swagger:response lockWalletRes
type lockWalletResponse struct { // nolint: unused,deadcode
// in: body
vcwallet.LockWalletResponse
}

// addContentRequest is request for adding a content to wallet.
//
// swagger:parameters addContentReq
type addContentRequest struct { // nolint: unused,deadcode
// Params for adding content to wallet.
//
// in: body
Params *vcwallet.AddContentRequest
}

// removeContentRequest is request for removing a content from wallet.
//
// swagger:parameters removeContentReq
type removeContentRequest struct { // nolint: unused,deadcode
// Params for removing content from wallet.
//
// in: body
Params *vcwallet.RemoveContentRequest
}

// getContentRequest is request for getting a content from wallet.
//
// swagger:parameters getContentReq
type getContentRequest struct { // nolint: unused,deadcode
// Params for getting content from wallet.
//
// in: body
Params *vcwallet.GetContentRequest
}

// getContentResponse response for get content from wallet operation.
//
// swagger:response getContentRes
type getContentResponse struct { // nolint: unused,deadcode
// in: body
vcwallet.GetContentResponse
}

// getAllContentRequest is request for getting all contents from wallet for given content type.
//
// swagger:parameters getAllContentReq
type getAllContentRequest struct { // nolint: unused,deadcode
// Params for getting all contents from wallet.
//
// in: body
Params *vcwallet.GetAllContentRequest
}

// getAllContentResponse response for get all content by content type wallet operation.
//
// swagger:response getAllContentRes
type getAllContentResponse struct {
// in: body
vcwallet.GetAllContentResponse
}

// contentQueryRequest is request model for querying wallet contents.
//
// swagger:parameters contentQueryReq
type contentQueryRequest struct { // nolint: unused,deadcode
// Params for querying credentials from wallet.
//
// in: body
Params *vcwallet.ContentQueryRequest
}

// contentQueryResponse response for wallet content query.
//
// swagger:response contentQueryRes
type contentQueryResponse struct { // nolint: unused,deadcode
// in: body
vcwallet.ContentQueryResponse
}

// issueRequest is request model for adding proof to credential from wallet.
//
// swagger:parameters issueReq
type issueRequest struct { // nolint: unused,deadcode
// Params for issuing credential from wallet.
//
// in: body
Params *vcwallet.IssueRequest
}

// issueResponse is response for issue credential interface from wallet.
//
// swagger:response issueRes
type issueResponse struct { // nolint: unused,deadcode
// in: body
vcwallet.IssueResponse
}

// proveRequest for producing verifiable presentation from wallet.
// Contains options for proofs and credential. Any combination of credential option can be mixed.
//
// swagger:parameters proveReq
type proveRequest struct { // nolint: unused,deadcode
// Params for producing verifiable presentation from wallet.
//
// in: body
Params *vcwallet.ProveRequest
}

// proveResponse contains response presentation from prove operation.
//
// swagger:response proveRes
type proveResponse struct { // nolint: unused,deadcode
// in: body
vcwallet.ProveResponse
}

// verifyRequest request for verifying a credential or presentation from wallet.
// Any one of the credential option should be used.
//
// swagger:parameters verifyReq
type verifyRequest struct { // nolint: unused,deadcode
// Params for producing verifying a credential or presentation from wallet.
//
// in: body
Params *vcwallet.VerifyRequest
}

// verifyResponse is response model for wallet verify operation.
//
// swagger:response verifyRes
type verifyResponse struct {
// in: body
vcwallet.VerifyResponse
}

// deriveRequest is request model for deriving a credential from wallet.
//
// swagger:parameters deriveReq
type deriveRequest struct { // nolint: unused,deadcode
// Params for deriving a credential from wallet.
//
// in: body
Params *vcwallet.DeriveRequest
}

// deriveResponse is response for derived credential operation.
//
// swagger:response deriveRes
type deriveResponse struct {
// in: body
vcwallet.DeriveResponse
}

// emptyRes model
//
// swagger:response emptyRes
type emptyRes struct{} // nolint: unused,deadcode
Loading

0 comments on commit 6f2d212

Please sign in to comment.