Skip to content

Commit

Permalink
Rename issue credential functions
Browse files Browse the repository at this point in the history
Signed-off-by: Laurence de Jong <info@ldej.nl>
  • Loading branch information
ldej committed Sep 22, 2020
1 parent e3027ce commit da51b90
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 69 deletions.
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,23 +129,23 @@ Examples can be found in the [examples](./examples) folder.

`{id}` = credential exchange identifier

| Function Name | Method | Endpoint | Implemented |
| --------------------------------- | ------ | ------------------------------------------- | ------------------ |
| QueryCredentialExchange | GET | /issue-credential/records | :heavy_check_mark: |
| GetCredentialExchange | GET | /issue-credential/records/{id} | :heavy_check_mark: |
| CreateCredentialExchange | POST | /issue-credential/create | :heavy_check_mark: |
| SendCredentialExchange | POST | /issue-credential/send | :heavy_check_mark: |
| SendCredentialExchangeProposal | POST | /issue-credential/send-proposal | :heavy_check_mark: |
| SendCredentialExchangeOffer | POST | /issue-credential/send-offer | :heavy_check_mark: |
| SendCredentialExchangeOfferByID | POST | /issue-credential/{id}/send-offer | :heavy_check_mark: |
| SendCredentialExchangeRequestByID | POST | /issue-credential/{id}/send-request | :heavy_check_mark: |
| SendCredentialByID | POST | /issue-credential/{id}/issue | :heavy_check_mark: |
| StoreReceivedCredential | POST | /issue-credential/{id}/store | :heavy_check_mark: |
| RemoveCredentialExchange | POST | /issue-credential/{id}/remove | :heavy_check_mark: |
| ReportCredentialExchangeProblem | POST | /issue-credential/{id}/problem-report | :heavy_check_mark: |
| RevokeIssuedCredential | POST | /issue-credential/revoke | :heavy_check_mark: |
| - | POST | /issue-credential/publish-revocations | :exclamation: |
| - | POST | /issue-credential/clear-pending-revocations | :exclamation: |
| Function Name | Method | Endpoint | Implemented |
| ------------------------------- | ------ | ------------------------------------------- | ------------------ |
| QueryCredentialExchange | GET | /issue-credential/records | :heavy_check_mark: |
| GetCredentialExchange | GET | /issue-credential/records/{id} | :heavy_check_mark: |
| CreateCredentialExchange | POST | /issue-credential/create | :heavy_check_mark: |
| SendCredential | POST | /issue-credential/send | :heavy_check_mark: |
| SendCredentialProposal | POST | /issue-credential/send-proposal | :heavy_check_mark: |
| SendCredentialOffer | POST | /issue-credential/send-offer | :heavy_check_mark: |
| SendCredentialOfferByID | POST | /issue-credential/{id}/send-offer | :heavy_check_mark: |
| SendCredentialRequestByID | POST | /issue-credential/{id}/send-request | :heavy_check_mark: |
| IssueCredentialByID | POST | /issue-credential/{id}/issue | :heavy_check_mark: |
| StoreReceivedCredential | POST | /issue-credential/{id}/store | :heavy_check_mark: |
| RemoveCredentialExchange | POST | /issue-credential/{id}/remove | :heavy_check_mark: |
| ReportCredentialExchangeProblem | POST | /issue-credential/{id}/problem-report | :heavy_check_mark: |
| RevokeIssuedCredential | POST | /issue-credential/revoke | :heavy_check_mark: |
| - | POST | /issue-credential/publish-revocations | :exclamation: |
| - | POST | /issue-credential/clear-pending-revocations | :exclamation: |

### Credentials

Expand Down
7 changes: 4 additions & 3 deletions credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

// TODO Credential differs between Swagger documentation and retrieved credential
type Credential struct {
CredentialID string `json:"referent"` // ??
CredentialDefinitionID string `json:"cred_def_id"`
CredentialRevokeID string `json:"cred_rev_id"`
SchemaID string `json:"schema_id"`
Expand All @@ -20,8 +19,10 @@ type Credential struct {
Witness struct {
Omega string `json:"omega"`
} `json:"witness"`
Values map[string]CredentialAttribute `json:"values"`
Attributes map[string]interface{}
Values map[string]CredentialAttribute `json:"values"`

CredentialID string `json:"referent"` // ??
Attributes map[string]interface{} `json:"attrs"`
}

type CredentialAttribute struct {
Expand Down
75 changes: 30 additions & 45 deletions credential_exchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ type CredentialProposal struct {
SchemaIssuerDID string `json:"schema_issuer_did"`
SchemaVersion string `json:"schema_version"`
Comment string `json:"comment"`
Credential CredentialPreview `json:"credential_proposal"`
CredentialPreview CredentialPreview `json:"credential_proposal"`
}

type CredentialRequest struct {
Expand Down Expand Up @@ -123,21 +123,12 @@ type Attribute struct {
Value string `json:"value"`
}

func (c *Client) SendCredentialExchangeOffer(offer CredentialOfferRequest) (CredentialExchange, error) {
var credentialExchangeRecord CredentialExchange
err := c.post(fmt.Sprintf("%s/issue-credential/send-offer", c.ACApyURL), nil, offer, &credentialExchangeRecord)
if err != nil {
return CredentialExchange{}, err
}
return credentialExchangeRecord, nil
}

type CredentialProposalRequest struct {
CredentialDefinitionID string `json:"cred_def_id"`
ConnectionID string `json:"connection_id"`
IssuerDID string `json:"issuer_did"`
Comment string `json:"comment"`
CredentialProposal CredentialPreview `json:"credential_proposal"`
CredentialPreview CredentialPreview `json:"credential_proposal"`
SchemaName string `json:"schema_name"`
SchemaVersion string `json:"schema_version"`
SchemaID string `json:"schema_id"`
Expand All @@ -146,28 +137,22 @@ type CredentialProposalRequest struct {
AutoRemove bool `json:"auto_remove"`
}

type CredentialProposalResponse struct {
CredentialExchangeID string `json:"credential_exchange_id"`
ConnectionID string `json:"connection_id"`
ThreadID string `json:"thread_id"`
State string `json:"state"`
Initiator string `json:"initiator"`
Role string `json:"role"`
CredentialProposalMap CredentialProposal `json:"credential_proposal_dict"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
Trace bool `json:"trace"`
AutoIssue bool `json:"auto_issue"`
AutoRemove bool `json:"auto_remove"`
func (c *Client) SendCredentialProposal(proposal CredentialProposalRequest) (CredentialExchange, error) {
var credentialExchange CredentialExchange
err := c.post(fmt.Sprintf("%s/issue-credential/send-proposal", c.ACApyURL), nil, proposal, &credentialExchange)
if err != nil {
return CredentialExchange{}, err
}
return credentialExchange, nil
}

func (c *Client) SendCredentialExchangeProposal(proposal CredentialProposalRequest) (CredentialProposalResponse, error) {
var credentialProposalResponse CredentialProposalResponse
err := c.post(fmt.Sprintf("%s/issue-credential/send-proposal", c.ACApyURL), nil, proposal, &credentialProposalResponse)
func (c *Client) SendCredentialOffer(offer CredentialOfferRequest) (CredentialExchange, error) {
var credentialExchangeRecord CredentialExchange
err := c.post(fmt.Sprintf("%s/issue-credential/send-offer", c.ACApyURL), nil, offer, &credentialExchangeRecord)
if err != nil {
return CredentialProposalResponse{}, err
return CredentialExchange{}, err
}
return credentialProposalResponse, nil
return credentialExchangeRecord, nil
}

type QueryCredentialExchangeParams struct {
Expand Down Expand Up @@ -204,17 +189,16 @@ func (c *Client) GetCredentialExchange(credentialExchangeID string) (CredentialE
}

type CredentialCreateRequest struct {
CredentialDefinitionID string `json:"cred_def_id"`
// ConnectionID string `json:"connection_id"`
IssuerDID string `json:"issuer_did"`
Comment string `json:"comment"`
CredentialProposal CredentialPreview `json:"credential_proposal"`
SchemaName string `json:"schema_name"`
SchemaVersion string `json:"schema_version"`
SchemaID string `json:"schema_id"`
SchemaIssuerDID string `json:"schema_issuer_did"`
Trace bool `json:"trace"`
AutoRemove bool `json:"auto_remove"`
CredentialDefinitionID string `json:"cred_def_id"`
IssuerDID string `json:"issuer_did"`
Comment string `json:"comment"`
CredentialPreview CredentialPreview `json:"credential_proposal"`
SchemaName string `json:"schema_name"`
SchemaVersion string `json:"schema_version"`
SchemaID string `json:"schema_id"`
SchemaIssuerDID string `json:"schema_issuer_did"`
Trace bool `json:"trace"`
AutoRemove bool `json:"auto_remove"`
}

func (c *Client) CreateCredentialExchange(request CredentialCreateRequest) (CredentialExchange, error) {
Expand All @@ -228,7 +212,7 @@ func (c *Client) CreateCredentialExchange(request CredentialCreateRequest) (Cred

type CredentialSendRequest CredentialProposalRequest

func (c *Client) SendCredentialExchange(request CredentialSendRequest) (CredentialExchange, error) {
func (c *Client) SendCredential(request CredentialSendRequest) (CredentialExchange, error) {
var credentialExchange CredentialExchange
err := c.post(fmt.Sprintf("%s/issue-credential/send", c.ACApyURL), nil, request, &credentialExchange)
if err != nil {
Expand All @@ -237,7 +221,7 @@ func (c *Client) SendCredentialExchange(request CredentialSendRequest) (Credenti
return credentialExchange, nil
}

func (c *Client) SendCredentialExchangeOfferByID(credentialExchangeID string) (CredentialExchange, error) {
func (c *Client) SendCredentialOfferByID(credentialExchangeID string) (CredentialExchange, error) {
var credentialExchange CredentialExchange
err := c.post(fmt.Sprintf("%s/issue-credential/records/%s/send-offer", c.ACApyURL, credentialExchangeID), nil, nil, &credentialExchange)
if err != nil {
Expand All @@ -246,7 +230,7 @@ func (c *Client) SendCredentialExchangeOfferByID(credentialExchangeID string) (C
return credentialExchange, nil
}

func (c *Client) SendCredentialExchangeRequestByID(credentialExchangeID string) (CredentialExchange, error) {
func (c *Client) SendCredentialRequestByID(credentialExchangeID string) (CredentialExchange, error) {
var credentialExchange CredentialExchange
err := c.post(fmt.Sprintf("%s/issue-credential/records/%s/send-request", c.ACApyURL, credentialExchangeID), nil, nil, &credentialExchange)
if err != nil {
Expand All @@ -255,7 +239,7 @@ func (c *Client) SendCredentialExchangeRequestByID(credentialExchangeID string)
return credentialExchange, nil
}

func (c *Client) SendCredentialToHolder(credentialExchangeID string, comment string) (CredentialExchange, error) {
func (c *Client) IssueCredentialByID(credentialExchangeID string, comment string) (CredentialExchange, error) {
var credentialExchange CredentialExchange
var body = struct {
Comment string `json:"comment"`
Expand All @@ -269,7 +253,8 @@ func (c *Client) SendCredentialToHolder(credentialExchangeID string, comment str
return credentialExchange, nil
}

func (c *Client) StoreReceivedCredential(credentialExchangeID string, credentialID string) (CredentialExchange, error) {
// credentialID is optional: https://github.com/hyperledger/aries-cloudagent-python/issues/594#issuecomment-656113125
func (c *Client) StoreCredentialByID(credentialExchangeID string, credentialID string) (CredentialExchange, error) {
var credentialExchange CredentialExchange
var body = struct {
CredentialID string `json:"credential_id"`
Expand Down
8 changes: 4 additions & 4 deletions examples/issue_credential/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,13 @@ func (app *App) ReadCommands() {
AutoRemove: false,
AutoIssue: false,
}
exchangeOffer, _ := app.client.SendCredentialExchangeOffer(offer)
exchangeOffer, _ := app.client.SendCredentialOffer(offer)
fmt.Printf("Credential Exchange ID: %s\n", exchangeOffer.CredentialExchangeID)
case "6":
fmt.Printf("Credential Exchange ID: ")
scanner.Scan()
credentialExchangeID := scanner.Text()
_, _ = app.client.SendCredentialExchangeRequestByID(credentialExchangeID)
_, _ = app.client.SendCredentialRequestByID(credentialExchangeID)
case "7":
fmt.Printf("Credential Exchange ID: ")
scanner.Scan()
Expand All @@ -156,7 +156,7 @@ func (app *App) ReadCommands() {
scanner.Scan()
comment := scanner.Text()

_, _ = app.client.SendCredentialToHolder(credentialExchangeID, comment)
_, _ = app.client.IssueCredentialByID(credentialExchangeID, comment)
case "8":
fmt.Printf("Credential Exchange ID: ")
scanner.Scan()
Expand All @@ -166,7 +166,7 @@ func (app *App) ReadCommands() {
scanner.Scan()
credentialID := scanner.Text()

_, _ = app.client.StoreReceivedCredential(credentialExchangeID, credentialID)
_, _ = app.client.StoreCredentialByID(credentialExchangeID, credentialID)
case "9":
credentials, _ := app.client.GetCredentials(10, 0, "")
for _, cred := range credentials {
Expand Down

0 comments on commit da51b90

Please sign in to comment.