Skip to content

Commit

Permalink
feat: vcwallet client
Browse files Browse the repository at this point in the history
- closes hyperledger-archives#2541
- part of hyperledger-archives#2433

Signed-off-by: sudesh.shetty <sudesh.shetty@securekey.com>
  • Loading branch information
sudeshrshetty committed Feb 16, 2021
1 parent f40dc2c commit 7c96e27
Show file tree
Hide file tree
Showing 4 changed files with 298 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/client/messaging/client.go
Expand Up @@ -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 {
Expand Down
141 changes: 141 additions & 0 deletions 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")
}
110 changes: 110 additions & 0 deletions 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)
}
46 changes: 46 additions & 0 deletions 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"`
}

0 comments on commit 7c96e27

Please sign in to comment.