diff --git a/README.md b/README.md index 7229724..1a563d0 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/credential.go b/credential.go index f3cee89..2fb3db1 100644 --- a/credential.go +++ b/credential.go @@ -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"` @@ -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 { diff --git a/credential_exchange.go b/credential_exchange.go index 86bead4..aaeaf0a 100644 --- a/credential_exchange.go +++ b/credential_exchange.go @@ -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 { @@ -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"` @@ -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 { @@ -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) { @@ -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 { @@ -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 { @@ -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 { @@ -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"` @@ -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"` diff --git a/examples/issue_credential/main.go b/examples/issue_credential/main.go index eaade83..3904aa6 100644 --- a/examples/issue_credential/main.go +++ b/examples/issue_credential/main.go @@ -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() @@ -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() @@ -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 {