Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sdk): Update interaction naming in JS code #481

Merged
merged 1 commit into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions cmd/wallet-sdk-js/jsinterop/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"syscall/js"

"github.com/hyperledger/aries-framework-go/component/kmscrypto/kms"
"github.com/hyperledger/aries-framework-go/component/storage/indexeddb"
arieskms "github.com/hyperledger/aries-framework-go/spi/kms"

"github.com/trustbloc/wallet-sdk/cmd/wallet-sdk-js/jsinterop/errors"
Expand All @@ -28,8 +27,10 @@ const (
dbNamespace = "wallet-sdk"
)

var agentInstance *walletsdk.Agent
var agentMethodsRunner jssupport.AsyncRunner
var (
agentInstance *walletsdk.Agent
agentMethodsRunner jssupport.AsyncRunner
)

func InitAgent(_ js.Value, args []js.Value) (any, error) {
didResolverURI, err := jssupport.EnsureString(jssupport.GetOptionalNamedArgument(args, "didResolverURI"))
Expand Down Expand Up @@ -107,7 +108,7 @@ func CreateDID(_ js.Value, args []js.Value) (any, error) {
return types.SerializeDIDDoc(didDoc)
}

func CreateOpenID4CIInteraction(_ js.Value, args []js.Value) (any, error) {
func CreateOpenID4CIIssuerInitiatedInteraction(_ js.Value, args []js.Value) (any, error) {
if agentInstance == nil {
return nil, walleterror.NewExecutionError(
errors.Module,
Expand All @@ -121,19 +122,18 @@ func CreateOpenID4CIInteraction(_ js.Value, args []js.Value) (any, error) {
return nil, err
}

interaction, err := agentInstance.CreateOpenID4CIInteraction(initiateIssuanceURI)
interaction, err := agentInstance.CreateOpenID4CIIssuerInitiatedInteraction(initiateIssuanceURI)
if err != nil {
return nil, err
}

return types.SerializeOpenID4CIInteraction(&agentMethodsRunner, interaction), nil
return types.SerializeOpenID4CIIssuerInitiatedInteraction(&agentMethodsRunner, interaction), nil
}

func ExportAgentFunctions() map[string]js.Func {
return map[string]js.Func{
"initAgent": agentMethodsRunner.CreateAsyncFunc(InitAgent),
"createDID": agentMethodsRunner.CreateAsyncFunc(CreateDID),
"createOpenID4CIInteraction": agentMethodsRunner.CreateAsyncFunc(CreateOpenID4CIInteraction),
"initAgent": agentMethodsRunner.CreateAsyncFunc(InitAgent),
"createDID": agentMethodsRunner.CreateAsyncFunc(CreateDID),
"createOpenID4CIIssuerInitiatedInteraction": agentMethodsRunner.CreateAsyncFunc(CreateOpenID4CIIssuerInitiatedInteraction),
}

}
6 changes: 3 additions & 3 deletions cmd/wallet-sdk-js/jsinterop/types/openid4ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ const (
openid4ciRequestCredentialWithPreAuth = "requestCredentialWithPreAuth"
)

func SerializeOpenID4CIInteraction(agentMethodsRunner *jssupport.AsyncRunner,
interaction *walletsdk.OpenID4CIInteraction) map[string]interface{} {

func SerializeOpenID4CIIssuerInitiatedInteraction(agentMethodsRunner *jssupport.AsyncRunner,
interaction *walletsdk.OpenID4CIIssuerInitiatedInteraction,
) map[string]interface{} {
return map[string]interface{}{
openid4ciRequestCredentialWithPreAuth: agentMethodsRunner.CreateAsyncFunc(
func(this js.Value, args []js.Value) (any, error) {
Expand Down
4 changes: 2 additions & 2 deletions cmd/wallet-sdk-js/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ const Agent = async function (opts) {
verificationType: opts.verificationType
});
},
createOpenID4CIInteraction: async function (opts) {
return await goAgent.createOpenID4CIInteraction({
createOpenID4CIIssuerInitiatedInteraction: async function (opts) {
return await goAgent.createOpenID4CIIssuerInitiatedInteraction({
initiateIssuanceURI: opts.initiateIssuanceURI,
})
},
Expand Down
10 changes: 6 additions & 4 deletions cmd/wallet-sdk-js/walletsdk/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,18 @@ func (a *Agent) CreateDID(didMethodType string, didKeyType arieskms.KeyType, ver
return didDoc, nil
}

// CreateOpenID4CIInteraction creates and starts openid4ci interaction.
func (a *Agent) CreateOpenID4CIInteraction(initiateIssuanceURI string) (*OpenID4CIInteraction, error) {
interaction, err := openid4ci.NewInteraction(initiateIssuanceURI, &openid4ci.ClientConfig{
// CreateOpenID4CIIssuerInitiatedInteraction creates and starts openid4ci issuer-initiated interaction.
func (a *Agent) CreateOpenID4CIIssuerInitiatedInteraction(
initiateIssuanceURI string,
) (*OpenID4CIIssuerInitiatedInteraction, error) {
interaction, err := openid4ci.NewIssuerInitiatedInteraction(initiateIssuanceURI, &openid4ci.ClientConfig{
DIDResolver: a.didResolver,
})
if err != nil {
return nil, err
}

return &OpenID4CIInteraction{
return &OpenID4CIIssuerInitiatedInteraction{
interaction: interaction,
crypto: a.crypto,
}, nil
Expand Down
10 changes: 5 additions & 5 deletions cmd/wallet-sdk-js/walletsdk/openid4ci.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ import (
"github.com/trustbloc/wallet-sdk/pkg/openid4ci"
)

// OpenID4CIInteraction wraps openid4ci.Interaction and necessary dependencies.
type OpenID4CIInteraction struct {
interaction *openid4ci.Interaction
// OpenID4CIIssuerInitiatedInteraction wraps openid4ci.IssuerInitiatedInteraction and necessary dependencies.
type OpenID4CIIssuerInitiatedInteraction struct {
interaction *openid4ci.IssuerInitiatedInteraction
crypto api.Crypto
}

Expand All @@ -28,7 +28,7 @@ type OpenID4CIInteraction struct {
// For the equivalent method for the authorization code flow, see RequestCredentialWithAuth instead.
// If a PIN is required (which can be checked via the Capabilities method), then it must be passed
// into this method via the WithPIN option.
func (i *OpenID4CIInteraction) RequestCredentialWithPreAuth(vm *models.VerificationMethod, pin string,
func (i *OpenID4CIIssuerInitiatedInteraction) RequestCredentialWithPreAuth(vm *models.VerificationMethod, pin string,
) ([]*verifiable.Credential, error) {
signer, err := i.createSigner(vm)
if err != nil {
Expand All @@ -38,7 +38,7 @@ func (i *OpenID4CIInteraction) RequestCredentialWithPreAuth(vm *models.Verificat
return i.interaction.RequestCredentialWithPreAuth(signer, openid4ci.WithPIN(pin))
}

func (i *OpenID4CIInteraction) createSigner(vm *models.VerificationMethod) (*common.JWSSigner, error) {
func (i *OpenID4CIIssuerInitiatedInteraction) createSigner(vm *models.VerificationMethod) (*common.JWSSigner, error) {
if vm == nil {
return nil, errors.New("verification method must be provided")
}
Expand Down
Loading