Skip to content

Commit

Permalink
chore: cleanup wallet cli
Browse files Browse the repository at this point in the history
Signed-off-by: Andrii Holovko <andriy.holovko@gmail.com>
  • Loading branch information
aholovko committed Jan 15, 2024
1 parent 7fbe030 commit d9a3e44
Show file tree
Hide file tree
Showing 40 changed files with 465 additions and 4,047 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ stress-test:
VCS_API_URL= \
ISSUER_PROFILE_ID= \
VERIFIER_PROFILE_ID= \
VERIFIER_PROFILE_VERSION= \
VERIFIER_PRESENTATION_ID= \
CREDENTIAL_TEMPLATE_ID= \
TOKEN_CLIENT_ID= \
TOKEN_CLIENT_SECRET= \
Expand Down
42 changes: 0 additions & 42 deletions component/wallet-cli/internal/httputil/httputil.go

This file was deleted.

40 changes: 0 additions & 40 deletions component/wallet-cli/internal/oauth2util/oauth2util.go

This file was deleted.

File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"

"github.com/trustbloc/vcs/component/wallet-cli/pkg/walletrunner/consent"
"github.com/trustbloc/vcs/component/wallet-cli/pkg/consent"
)

func TestCognitoConsent(t *testing.T) {
Expand Down
13 changes: 12 additions & 1 deletion component/wallet-cli/pkg/oidc4vci/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ SPDX-License-Identifier: Apache-2.0

package oidc4vci

import "github.com/trustbloc/vcs/pkg/doc/verifiable"
import (
"time"

"github.com/trustbloc/vcs/pkg/doc/verifiable"
)

type JWTProofClaims struct {
Issuer string `json:"iss,omitempty"`
Expand Down Expand Up @@ -34,3 +38,10 @@ type CredentialResponse struct {
Format verifiable.OIDCFormat `json:"format"`
AckID *string `json:"ack_id"`
}

type PerfInfo struct {
GetIssuerCredentialsOIDCConfig time.Duration `json:"vci_get_issuer_credentials_oidc_config"`
GetAccessToken time.Duration `json:"vci_get_access_token"`
GetCredential time.Duration `json:"vci_get_credential"`
CredentialsAck time.Duration `json:"vci_credentials_ack"`
}
26 changes: 25 additions & 1 deletion component/wallet-cli/pkg/oidc4vci/oidc4vci_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ import (
"github.com/trustbloc/vc-go/verifiable"
"golang.org/x/oauth2"

"github.com/trustbloc/vcs/component/wallet-cli/pkg/consent"
"github.com/trustbloc/vcs/component/wallet-cli/pkg/credentialoffer"
jwssigner "github.com/trustbloc/vcs/component/wallet-cli/pkg/signer"
"github.com/trustbloc/vcs/component/wallet-cli/pkg/trustregistry"
"github.com/trustbloc/vcs/component/wallet-cli/pkg/wallet"
"github.com/trustbloc/vcs/component/wallet-cli/pkg/walletrunner/consent"
"github.com/trustbloc/vcs/component/wallet-cli/pkg/wellknown"
kmssigner "github.com/trustbloc/vcs/pkg/kms/signer"
"github.com/trustbloc/vcs/pkg/restapi/v1/common"
Expand Down Expand Up @@ -87,6 +87,7 @@ type Flow struct {
pin string
walletKeyID string
walletKeyType kms.KeyType
perfInfo *PerfInfo
}

type provider interface {
Expand Down Expand Up @@ -210,6 +211,7 @@ func NewFlow(p provider, opts ...Opt) (*Flow, error) {
issuerState: o.issuerState,
pin: o.pin,
trustRegistryURL: o.trustRegistryURL,
perfInfo: &PerfInfo{},
}, nil
}

Expand Down Expand Up @@ -250,11 +252,15 @@ func (f *Flow) Run(ctx context.Context) (*verifiable.Credential, error) {
issuerState = f.issuerState
}

start := time.Now()

openIDConfig, err := f.wellKnownService.GetWellKnownOpenIDConfiguration(credentialIssuer)
if err != nil {
return nil, err
}

f.perfInfo.GetIssuerCredentialsOIDCConfig = time.Since(start)

requireWalletAttestation := openIDConfig.TokenEndpointAuthMethodsSupported != nil &&
lo.Contains(openIDConfig.TokenEndpointAuthMethodsSupported, attestJWTClientAuthType)

Expand Down Expand Up @@ -292,6 +298,8 @@ func (f *Flow) Run(ctx context.Context) (*verifiable.Credential, error) {

var token *oauth2.Token

start = time.Now()

if f.flowType == FlowTypeAuthorizationCode || f.flowType == FlowTypeWalletInitiated {
oauthClient := &oauth2.Config{
ClientID: f.clientID,
Expand Down Expand Up @@ -392,6 +400,8 @@ func (f *Flow) Run(ctx context.Context) (*verifiable.Credential, error) {
)
}

f.perfInfo.GetAccessToken = time.Since(start)

vc, err := f.receiveVC(token, openIDConfig, credentialIssuer)
if err != nil {
return nil, err
Expand Down Expand Up @@ -678,6 +688,11 @@ func (f *Flow) receiveVC(
) (*verifiable.Credential, error) {
credentialEndpoint := wellKnown.CredentialEndpoint

start := time.Now()
defer func() {
f.perfInfo.GetCredential = time.Since(start)
}()

slog.Info("Getting credential",
"credential_endpoint", credentialEndpoint,
"credential_issuer", credentialIssuer,
Expand Down Expand Up @@ -814,6 +829,11 @@ func (f *Flow) handleIssuanceAck(
return nil
}

start := time.Now()
defer func() {
f.perfInfo.CredentialsAck = time.Since(start)
}()

slog.Info("Sending wallet ACK",
"ack_id", credResponse.AckID,
"endpoint", wellKnown.CredentialAckEndpoint,
Expand Down Expand Up @@ -857,6 +877,10 @@ func (f *Flow) handleIssuanceAck(
return nil
}

func (f *Flow) PerfInfo() *PerfInfo {
return f.perfInfo
}

func waitForEnter(
done chan<- struct{},
) {
Expand Down
10 changes: 10 additions & 0 deletions component/wallet-cli/pkg/oidc4vp/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ SPDX-License-Identifier: Apache-2.0
package oidc4vp

import (
"time"

"github.com/trustbloc/vc-go/presexch"
"github.com/trustbloc/vc-go/verifiable"
)
Expand Down Expand Up @@ -71,3 +73,11 @@ type VPTokenClaims struct {
Iat int64 `json:"iat"`
Jti string `json:"jti"`
}

type PerfInfo struct {
FetchRequestObject time.Duration `json:"vp_fetch_request_object"`
VerifyAuthorizationRequest time.Duration `json:"vp_verify_authorization_request"`
QueryCredentialFromWallet time.Duration `json:"vp_query_credential_from_wallet"`
CreateAuthorizedResponse time.Duration `json:"vp_create_authorized_response"`
SendAuthorizedResponse time.Duration `json:"vp_send_authorized_response"`
}
Loading

0 comments on commit d9a3e44

Please sign in to comment.