Skip to content

Commit

Permalink
feat: WACI holder APIs for vcwallet
Browse files Browse the repository at this point in the history
- Implemented Universal wallet interfaces discussed in
w3c-ccg/universal-wallet-interop-spec#99
- Added bindings for SDK, REST, JS
- Closes hyperledger-archives#2928
- Part of hyperledger-archives#2433

Signed-off-by: sudesh.shetty <sudesh.shetty@securekey.com>
  • Loading branch information
sudeshrshetty committed Aug 11, 2021
1 parent 75e11e2 commit 81f0775
Show file tree
Hide file tree
Showing 14 changed files with 2,347 additions and 52 deletions.
12 changes: 12 additions & 0 deletions cmd/aries-js-worker/src/agent-rest-client.js
Expand Up @@ -456,6 +456,18 @@ const pkgs = {
path: "/vcwallet/create-key-pair",
method: "POST",
},
Connect: {
path: "/vcwallet/connect",
method: "POST",
},
ProposePresentation: {
path: "/vcwallet/propose-presentation",
method: "POST",
},
PresentProof: {
path: "/vcwallet/present-proof",
method: "POST",
},
},
ld: {
AddContexts: {
Expand Down
32 changes: 32 additions & 0 deletions cmd/aries-js-worker/src/aries.js
Expand Up @@ -1271,6 +1271,38 @@ const Aries = function (opts) {
createKeyPair: async function (req) {
return invoke(aw, pending, this.pkgname, "CreateKeyPair", req, "timeout while creating key pair from wallet")
},

/**
*
* accepts out-of-band invitation and performs DID exchange from wallet.
*
* @returns {Promise<Object>}
*/
connect: async function (req) {
return invoke(aw, pending, this.pkgname, "Connect", req, "timeout while performing DID connect from wallet")
},

/**
*
* accepts out-of-band invitation and sends propose presentation message to sender.
*
* Returns request presentation message response.
*
* @returns {Promise<Object>}
*/
proposePresentation: async function (req) {
return invoke(aw, pending, this.pkgname, "ProposePresentation", req, "timeout while proposing presentation from wallet")
},

/**
*
* sends presentation as present proof message.
*
* @returns {Promise<Object>}
*/
presentProof: async function (req) {
return invoke(aw, pending, this.pkgname, "PresentProof", req, "timeout while performing present proof from wallet")
},
},
/**
* JSON-LD management API.
Expand Down
77 changes: 77 additions & 0 deletions pkg/client/vcwallet/client.go
Expand Up @@ -13,8 +13,10 @@ import (

"github.com/piprate/json-gold/ld"

"github.com/hyperledger/aries-framework-go/pkg/client/outofband"
"github.com/hyperledger/aries-framework-go/pkg/common/log"
"github.com/hyperledger/aries-framework-go/pkg/crypto"
"github.com/hyperledger/aries-framework-go/pkg/didcomm/common/service"
"github.com/hyperledger/aries-framework-go/pkg/doc/verifiable"
"github.com/hyperledger/aries-framework-go/pkg/framework/aries/api/vdr"
"github.com/hyperledger/aries-framework-go/pkg/kms"
Expand All @@ -34,6 +36,17 @@ type provider interface {
VDRegistry() vdr.Registry
Crypto() crypto.Crypto
JSONLDDocumentLoader() ld.DocumentLoader
didCommProvider // to be used only if wallet needs to be participated in DIDComm.
}

// didCommProvider to be used only if wallet needs to be participated in DIDComm operation.
// TODO: using wallet KMS instead of provider KMS.
// TODO: reconcile Protocol storage with wallet store.
type didCommProvider interface {
KMS() kms.KeyManager
ServiceEndpoint() string
ProtocolStateStorageProvider() storage.Provider
Service(id string) (interface{}, error)
}

// walletAuth is auth function which returns wallet unlock token.
Expand Down Expand Up @@ -336,3 +349,67 @@ func (c *Client) CreateKeyPair(keyType kms.KeyType) (*wallet.KeyPair, error) {

return c.wallet.CreateKeyPair(auth, keyType)
}

// Connect accepts out-of-band invitations and performs DID exchange.
//
// Args:
// - invitation: out-of-band invitation.
// - options: connection options.
//
// Returns:
// - connection ID if DID exchange is successful.
// - error if operation false.
//
func (c *Client) Connect(invitation *outofband.Invitation, options ...wallet.ConnectOptions) (string, error) {
auth, err := c.auth()
if err != nil {
return "", err
}

return c.wallet.Connect(auth, invitation, options...)
}

// ProposePresentation accepts out-of-band invitation and sends message proposing presentation
// from wallet to relying party.
//
// Currently Supporting
// [0454-present-proof-v2](https://github.com/hyperledger/aries-rfcs/tree/master/features/0454-present-proof-v2)
//
// Args:
// - invitation: out-of-band invitation from relying party.
// - options: options for accepting invitation and send propose presentation message.
//
// Returns:
// - DIDCommMsgMap containing request presentation message if operation is successful.
// - error if operation fails.
//
func (c *Client) ProposePresentation(invitation *outofband.Invitation, options ...wallet.ProposePresentationOption) (*service.DIDCommMsgMap, error) { //nolint: lll
auth, err := c.auth()
if err != nil {
return nil, err
}

return c.wallet.ProposePresentation(auth, invitation, options...)
}

// PresentProof sends message present proof message from wallet to relying party.
//
// Currently Supporting
// [0454-present-proof-v2](https://github.com/hyperledger/aries-rfcs/tree/master/features/0454-present-proof-v2)
//
// Args:
// - thID: thread ID (action ID) of request presentation.
// - presentation: presentation to be sent.
//
// Returns:
// - error if operation fails.
//
// TODO: wait for acknowledgement option to be added.
func (c *Client) PresentProof(thID string, presentation *verifiable.Presentation) error {
auth, err := c.auth()
if err != nil {
return err
}

return c.wallet.PresentProof(auth, thID, presentation)
}

0 comments on commit 81f0775

Please sign in to comment.