From 7c96e27876bf54de59020b0bc70619706fbe97b8 Mon Sep 17 00:00:00 2001 From: "sudesh.shetty" Date: Tue, 16 Feb 2021 17:51:15 -0500 Subject: [PATCH] feat: vcwallet client - closes #2541 - part of #2433 Signed-off-by: sudesh.shetty --- pkg/client/messaging/client.go | 2 +- pkg/client/vcwallet/client.go | 141 +++++++++++++++++++++++++++++ pkg/client/vcwallet/client_test.go | 110 ++++++++++++++++++++++ pkg/client/vcwallet/models.go | 46 ++++++++++ 4 files changed, 298 insertions(+), 1 deletion(-) create mode 100644 pkg/client/vcwallet/client.go create mode 100644 pkg/client/vcwallet/client_test.go create mode 100644 pkg/client/vcwallet/models.go diff --git a/pkg/client/messaging/client.go b/pkg/client/messaging/client.go index b5212bf26..6c0220c6f 100644 --- a/pkg/client/messaging/client.go +++ b/pkg/client/messaging/client.go @@ -31,7 +31,7 @@ const ( errMsgDestinationMissing = "missing message destination" ) -var logger = log.New("aries-framework/controller/common") +var logger = log.New("aries-framework/client/messaging") // provider contains dependencies for the message client and is typically created by using aries.Context(). type provider interface { diff --git a/pkg/client/vcwallet/client.go b/pkg/client/vcwallet/client.go new file mode 100644 index 000000000..c74b2d590 --- /dev/null +++ b/pkg/client/vcwallet/client.go @@ -0,0 +1,141 @@ +/* +Copyright SecureKey Technologies Inc. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package vcwallet + +import ( + "encoding/json" + "fmt" +) + +// provider contains dependencies for the verifiable credential wallet client +// and is typically created by using aries.Context(). +type provider interface { + // TODO to be added #2433 +} + +// Client enable access to verifiable credential wallet features. +type Client struct { + // ID of wallet content owner + userID string +} + +// New returns new verifiable credential wallet client for given user. +func New(userID string, ctx provider) *Client { + // TODO initialize providers for stores, VDR, KMS #2433 + // TODO create user profile if not already created #2433 + return &Client{userID: userID} +} + +// Export produces a serialized exported wallet representation. +// Only ciphertext wallet contents can be exported. +// +// Args: +// - auth: token to be used to lock the wallet before exporting. +// +// Returns exported locked wallet. +// +// Supported data models: +// - https://w3c-ccg.github.io/universal-wallet-interop-spec/#Profile +// - https://w3c-ccg.github.io/universal-wallet-interop-spec/#Credential +// +func (c *Client) Export(auth string) (json.RawMessage, error) { + // TODO to be added #2433 + return nil, fmt.Errorf("to be implemented") +} + +// Import Takes a serialized exported wallet representation as input +// and imports all contents into wallet. +// +// Args: +// - contents: wallet content to be imported. +// - auth: token used while exporting the wallet. +// +// Supported data models: +// - https://w3c-ccg.github.io/universal-wallet-interop-spec/#Profile +// - https://w3c-ccg.github.io/universal-wallet-interop-spec/#Credential +// +func (c *Client) Import(auth string, contents json.RawMessage) error { + // TODO to be added #2433 + return fmt.Errorf("to be implemented") +} + +// Add adds given data model to wallet contents store. +// +// Supported data models: +// - https://w3c-ccg.github.io/universal-wallet-interop-spec/#Profile +// - https://w3c-ccg.github.io/universal-wallet-interop-spec/#Credential +// +func (c *Client) Add(model json.RawMessage) error { + // TODO to be added #2433 + return fmt.Errorf("to be implemented") +} + +// Remove removes wallet content by content ID. +// +// Supported data models: +// - https://w3c-ccg.github.io/universal-wallet-interop-spec/#Profile +// - https://w3c-ccg.github.io/universal-wallet-interop-spec/#Credential +// +func (c *Client) Remove(contentID string) error { + // TODO to be added #2433 + return fmt.Errorf("to be implemented") +} + +// Get fetches a wallet content by content ID. +// +// Supported data models: +// - https://w3c-ccg.github.io/universal-wallet-interop-spec/#Profile +// - https://w3c-ccg.github.io/universal-wallet-interop-spec/#Credential +// +func (c *Client) Get(contentID string) (json.RawMessage, error) { + // TODO to be added #2433 + return nil, fmt.Errorf("to be implemented") +} + +// Query returns a collection of results based on current wallet contents. +// +// Supported Query Types: +// - https://www.w3.org/TR/json-ld11-framing +// - https://identity.foundation/presentation-exchange +// +func (c *Client) Query(query *QueryParams) ([]json.RawMessage, error) { + // TODO to be added #2433 + return nil, fmt.Errorf("to be implemented") +} + +// Issue adds proof to a Verifiable Credential. +// +// Args: +// - A verifiable credential with or without proof +// - Proof options +// +func (c *Client) Issue(credential json.RawMessage, options *ProofOptions) (json.RawMessage, error) { + // TODO to be added #2433 + return nil, fmt.Errorf("to be implemented") +} + +// Prove produces a Verifiable Presentation. +// +// Args: +// - List of verifiable credentials IDs. +// - Proof options +// +func (c *Client) Prove(credentialIDs []string, options *ProofOptions) (json.RawMessage, error) { + // TODO to be added #2433 + return nil, fmt.Errorf("to be implemented") +} + +// Verify takes Takes a Verifiable Credential or Verifiable Presentation as input,. +// +// Args: +// - a Verifiable Credential or Verifiable Presentation +// +// Returns: a boolean verified, and an error if verified is false. +func (c *Client) Verify(raw json.RawMessage) (bool, error) { + // TODO to be added #2433 + return false, fmt.Errorf("to be implemented") +} diff --git a/pkg/client/vcwallet/client_test.go b/pkg/client/vcwallet/client_test.go new file mode 100644 index 000000000..f51ad7d16 --- /dev/null +++ b/pkg/client/vcwallet/client_test.go @@ -0,0 +1,110 @@ +/* +Copyright SecureKey Technologies Inc. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package vcwallet + +import ( + "testing" + + "github.com/stretchr/testify/require" +) + +const ( + sampleUserID = "sample-user01" + toBeImplementedErr = "to be implemented" +) + +func TestNew(t *testing.T) { + vcWalletClient := New(sampleUserID, nil) + require.NotEmpty(t, vcWalletClient) +} + +func TestClient_Export(t *testing.T) { + vcWalletClient := New(sampleUserID, nil) + require.NotEmpty(t, vcWalletClient) + + result, err := vcWalletClient.Export("") + require.Empty(t, result) + require.Error(t, err) + require.EqualError(t, err, toBeImplementedErr) +} + +func TestClient_Import(t *testing.T) { + vcWalletClient := New(sampleUserID, nil) + require.NotEmpty(t, vcWalletClient) + + err := vcWalletClient.Import("", nil) + require.Error(t, err) + require.EqualError(t, err, toBeImplementedErr) +} + +func TestClient_Add(t *testing.T) { + vcWalletClient := New(sampleUserID, nil) + require.NotEmpty(t, vcWalletClient) + + err := vcWalletClient.Add(nil) + require.Error(t, err) + require.EqualError(t, err, toBeImplementedErr) +} + +func TestClient_Remove(t *testing.T) { + vcWalletClient := New(sampleUserID, nil) + require.NotEmpty(t, vcWalletClient) + + err := vcWalletClient.Remove("") + require.Error(t, err) + require.EqualError(t, err, toBeImplementedErr) +} + +func TestClient_Get(t *testing.T) { + vcWalletClient := New(sampleUserID, nil) + require.NotEmpty(t, vcWalletClient) + + result, err := vcWalletClient.Get("") + require.Empty(t, result) + require.Error(t, err) + require.EqualError(t, err, toBeImplementedErr) +} + +func TestClient_Query(t *testing.T) { + vcWalletClient := New(sampleUserID, nil) + require.NotEmpty(t, vcWalletClient) + + results, err := vcWalletClient.Query(&QueryParams{}) + require.Empty(t, results) + require.Error(t, err) + require.EqualError(t, err, toBeImplementedErr) +} + +func TestClient_Issue(t *testing.T) { + vcWalletClient := New(sampleUserID, nil) + require.NotEmpty(t, vcWalletClient) + + result, err := vcWalletClient.Issue(nil, &ProofOptions{}) + require.Empty(t, result) + require.Error(t, err) + require.EqualError(t, err, toBeImplementedErr) +} + +func TestClient_Prove(t *testing.T) { + vcWalletClient := New(sampleUserID, nil) + require.NotEmpty(t, vcWalletClient) + + result, err := vcWalletClient.Prove(nil, &ProofOptions{}) + require.Empty(t, result) + require.Error(t, err) + require.EqualError(t, err, toBeImplementedErr) +} + +func TestClient_Verify(t *testing.T) { + vcWalletClient := New(sampleUserID, nil) + require.NotEmpty(t, vcWalletClient) + + result, err := vcWalletClient.Verify(nil) + require.Empty(t, result) + require.Error(t, err) + require.EqualError(t, err, toBeImplementedErr) +} diff --git a/pkg/client/vcwallet/models.go b/pkg/client/vcwallet/models.go new file mode 100644 index 000000000..6b8232719 --- /dev/null +++ b/pkg/client/vcwallet/models.go @@ -0,0 +1,46 @@ +/* +Copyright SecureKey Technologies Inc. All Rights Reserved. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package vcwallet + +import ( + "encoding/json" + "time" +) + +// QueryParams model +// +// Parameters for querying vc wallet contents. +// +type QueryParams struct { + // Type of the query. + // Allowed values 'QueryByFrame', 'PresentationExchange' + Type string + + // Wallet content query. + Query json.RawMessage +} + +// ProofOptions model +// +// Options for adding linked data proofs to a verifiable credential or a verifiable presentation. +// +type ProofOptions struct { + // VerificationMethod is the URI of the verificationMethod used for the proof. + VerificationMethod string `json:"verificationMethod,omitempty"` + // ProofPurpose is purpose of the proof. + ProofPurpose string `json:"proofPurpose,omitempty"` + // Controller is a DID to be for signing. + Controller string `json:"controller,omitempty"` + // Created date of the proof. If omitted current system time will be used. + Created *time.Time `json:"created,omitempty"` + // Domain is operational domain of a digital proof. + Domain string `json:"domain,omitempty"` + // Challenge is a random or pseudo-random value option authentication + Challenge string `json:"challenge,omitempty"` + // ProofType is signature type used for signing + ProofType string `json:"proofType,omitempty"` +}