Skip to content

Commit

Permalink
Fix Go/Java samples; re-add WalletService.Search() Go interface (#833)
Browse files Browse the repository at this point in the history
  • Loading branch information
geel9 committed Jul 1, 2022
1 parent 16f14db commit fc641ab
Show file tree
Hide file tree
Showing 11 changed files with 325 additions and 219 deletions.
14 changes: 7 additions & 7 deletions docs/reference/services/credential-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Issues a credential from a valid JSON-LD document. Issued credentials are not au
=== "Go"
<!--codeinclude-->
```golang
[VerifyProof](../../../go/examples/vaccine_test.go) inside_block:issueCredential
[VerifyProof](../../../go/services/credential_service_test.go) inside_block:issueCredential
```
<!--/codeinclude-->

Expand Down Expand Up @@ -105,7 +105,7 @@ Issues a credential from a [previously-defined template](/reference/services/tem
=== "Go"
<!--codeinclude-->
```golang
[Issue From Template](../../../go/services/template_service_test.go) inside_block:issueFromTemplate
[Issue From Template](../../../go/services/credential_service_test.go) inside_block:issueFromTemplate
```
<!--/codeinclude-->

Expand Down Expand Up @@ -228,7 +228,7 @@ If `reveal_document_json` is passed, a proof will be generated for only the fiel
=== "TypeScript"
<!--codeinclude-->
```typescript
[CreateProof](../../../web/test/WalletService.test.ts) inside_block:createProof
[CreateProof](../../../web/test/WalletService.test.ts) inside_block:createProof
```
<!--/codeinclude-->

Expand All @@ -249,7 +249,7 @@ If `reveal_document_json` is passed, a proof will be generated for only the fiel
=== "Go"
<!--codeinclude-->
```golang
[CreateProof](../../../go/services/services_test.go) inside_block:createProof
[CreateProof](../../../go/services/credential_service_test.go) inside_block:createProof
```
<!--/codeinclude-->

Expand Down Expand Up @@ -299,14 +299,14 @@ Verifies a proof for validity and authenticity. Only supports BBS+ Signatures at
=== "Python"
<!--codeinclude-->
```python
[VerifyProof](../../../python/samples/vaccine_demo.py) inside_block:verifyProof
[VerifyProof](../../../python/samples/credential_demo.py) inside_block:verifyProof
```
<!--/codeinclude-->

=== "Go"
<!--codeinclude-->
```golang
[VerifyProof](../../../go/services/services_test.go) inside_block:verifyProof
[VerifyProof](../../../go/services/credential_service_test.go) inside_block:verifyProof
```
<!--/codeinclude-->

Expand Down Expand Up @@ -372,7 +372,7 @@ The specified email address must be tied to an existing account in the same ecos
=== "Go"
<!--codeinclude-->
```golang
[SendRequest](../../../go/services/services_test.go) inside_block:sendCredential
[SendRequest](../../../go/services/credential_service_test.go) inside_block:sendCredential
```
<!--/codeinclude-->

Expand Down
8 changes: 4 additions & 4 deletions docs/reference/services/trust-registry-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Creates a Governance Framework and attaches it to the current ecosystem.
=== "Java"
<!--codeinclude-->
```java
[RegisterGovernanceFramework](../../../java/src/test/java/trinsic/TrustRegistryDemo.java) inside_block:registerGovernanceFramework
[RegisterGovernanceFramework](../../../java/src/test/java/trinsic/TrustRegistryDemo.java) inside_block:addFramework
```
<!--/codeinclude-->

Expand Down Expand Up @@ -81,7 +81,7 @@ Registers an authorized issuer for a specific credential type (identified by its
=== "Go"
<!--codeinclude-->
```golang
[RegisterIssuer](../../../go/services/services_test.go) inside_block:registerIssuerSample
[RegisterIssuer](../../../go/services/services_test.go) inside_block:registerMemberSample
```
<!--/codeinclude-->

Expand Down Expand Up @@ -127,7 +127,7 @@ Unregisters an issuer for a specific credential type (identified by its `schema_
=== "Go"
<!--codeinclude-->
```golang
[RegisterIssuer](../../../go/services/services_test.go) inside_block:unregisterIssuer
[RegisterIssuer](../../../go/services/services_test.go) inside_block:unregisterMember
```
<!--/codeinclude-->

Expand Down Expand Up @@ -171,7 +171,7 @@ Check the status of an issuer for a specific credential type.
=== "Go"
<!--codeinclude-->
```golang
[RegisterIssuer](../../../go/services/services_test.go) inside_block:checkIssuerStatus
[RegisterIssuer](../../../go/services/services_test.go) inside_block:getMembershipStatus
```
<!--/codeinclude-->

Expand Down
4 changes: 2 additions & 2 deletions docs/reference/services/wallet-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Stores a credential (or any other JSON object) in a wallet.
=== "Go"
<!--codeinclude-->
```golang
[RegisterIssuer](../../../go/services/services_test.go) inside_block:insertItemWallet
[RegisterIssuer](../../../go/services/wallet_service_test.go) inside_block:insertItemWallet
```
<!--/codeinclude-->

Expand Down Expand Up @@ -114,7 +114,7 @@ If no `query` is specified, this call by default returns the first 100 items in
=== "Go"
<!--codeinclude-->
```golang
[RegisterIssuer](../../../go/services/services_test.go) inside_block:searchWalletBasic
[RegisterIssuer](../../../go/services/wallet_service_test.go) inside_block:searchWalletBasic
```
<!--/codeinclude-->

Expand Down
4 changes: 2 additions & 2 deletions go/examples/vaccine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import (
"testing"
)

func defineTemplate(trinsic services.TrinsicService, t *testing.T) *template.TemplateData {
func defineTemplate(trinsic *services.Trinsic, t *testing.T) *template.TemplateData {
// createTemplate() {
templateRequest := &template.CreateCredentialTemplateRequest{Name: "VaccinationCertificate", AllowAdditionalFields: false, Fields: make(map[string]*template.TemplateField)}
templateRequest.Fields["firstName"] = &template.TemplateField{Description: "First name of vaccine recipient"}
templateRequest.Fields["lastName"] = &template.TemplateField{Description: "Last name of vaccine recipient"}
templateRequest.Fields["batchNumber"] = &template.TemplateField{Description: "Batch number of vaccine", Type: template.FieldType_STRING}
templateRequest.Fields["countryOfVaccination"] = &template.TemplateField{Description: "Country in which the subject was vaccinated"}

createdTemplate, _ := templateService.Create(context.Background(), templateRequest)
createdTemplate, _ := trinsic.Template().Create(context.Background(), templateRequest)

templateId := createdTemplate.Data.Id
// }
Expand Down
12 changes: 6 additions & 6 deletions go/services/account_service_test.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package services

import (
"context"
"testing"
"context"
"testing"

"github.com/stretchr/testify/assert"
"github.com/trinsic-id/sdk/go/proto/services/account/v1/account"
"github.com/stretchr/testify/assert"
"github.com/trinsic-id/sdk/go/proto/services/account/v1/account"
)

func TestLogin(t *testing.T) {
assert2 := assert.New(t)

trinsic, err := NewTrinsic(WithTestEnv())
trinsic, err := CreateTestTrinsicWithNewEcosystem()
if !assert2.Nil(err) {
return
}
Expand Down Expand Up @@ -42,7 +42,7 @@ func TestLogin(t *testing.T) {
func TestAuthWebhook(t *testing.T) {
assert2 := assert.New(t)

trinsic, err := NewTrinsic(WithTestEnv())
trinsic, err := CreateTestTrinsicWithNewEcosystem()
if !assert2.Nil(err) {
return
}
Expand Down
94 changes: 94 additions & 0 deletions go/services/credential_service_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package services

import (
"context"
"encoding/json"
"github.com/trinsic-id/sdk/go/proto/services/verifiablecredentials/templates/v1/template"
"github.com/trinsic-id/sdk/go/proto/services/verifiablecredentials/v1/credential"
"testing"

"github.com/stretchr/testify/assert"
)

func TestIssueAndVerify(t *testing.T) {
assert2 := assert.New(t)

trinsic, err := CreateTestTrinsicWithNewEcosystem()
assert2.Nil(err)

// Create a simple template to issue against
templateRequest := &template.CreateCredentialTemplateRequest{Name: "Test", AllowAdditionalFields: false, Fields: make(map[string]*template.TemplateField)}
templateRequest.Fields["name"] = &template.TemplateField{Description: "Name of credential recipient"}

createdTemplate, _ := trinsic.Template().Create(context.Background(), templateRequest)
templateId := createdTemplate.Data.Id

// Issue from template
valuesBytes, _ := json.Marshal(struct{ name string }{name: "A Realperson"})
valuesJson := string(valuesBytes)

// issueFromTemplate() {
issueTemplateResponse, err := trinsic.Credential().IssueFromTemplate(context.Background(),
&credential.IssueFromTemplateRequest{
ValuesJson: valuesJson,
TemplateId: templateId,
})
// }

credentialJson := issueTemplateResponse.DocumentJson

assert2.Nil(err)
assert2.NotNil(issueTemplateResponse)

// Issue (not from template) -- can just be any JSON blob
unsignedCredential := valuesJson

// issueCredential() {
issueResponse, err := trinsic.Credential().Issue(context.Background(),
&credential.IssueRequest{
DocumentJson: unsignedCredential,
})
// }

assert2.NotNil(issueResponse)

// Create a proof
// createProof() {
request := &credential.CreateProofRequest{
Proof: &credential.CreateProofRequest_DocumentJson{
DocumentJson: credentialJson,
},
}

proofResponse, err := trinsic.Credential().CreateProof(context.Background(), request)
// }

assert2.NotNil(proofResponse)
assert2.Nil(err)

proofJson := proofResponse.ProofDocumentJson

// Verify proof
// verifyProof() {
verifyResponse, err := trinsic.Credential().VerifyProof(context.Background(), &credential.VerifyProofRequest{
ProofDocumentJson: proofJson,
})
// }

assert2.NotNil(verifyResponse)
assert2.Nil(err)

// Send credential
// sendCredential() {
sendResponse, err := trinsic.Credential().Send(context.Background(), &credential.SendRequest{
DeliveryMethod: &credential.SendRequest_Email{
Email: "example@trinsic.id",
},
DocumentJson: credentialJson,
})
// }

// Send() isn't implemented yet, should error
assert2.Nil(sendResponse)
assert2.NotNil(err)
}

0 comments on commit fc641ab

Please sign in to comment.