Skip to content

Commit

Permalink
Code inject samples for typescript and .net where possible (#551)
Browse files Browse the repository at this point in the history
  • Loading branch information
fundthmcalculus committed Apr 7, 2022
1 parent a79d268 commit 322916b
Show file tree
Hide file tree
Showing 9 changed files with 113 additions and 196 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
fetch-depth: 0 # Get everything so that the `mkdocs-git-authors` plugin answers correctly
with:
fetch-depth: 0 # Get everything so that the `mkdocs-git-authors` plugin answers correctly
- uses: actions/setup-python@v2
with:
python-version: '3.10'
Expand Down
2 changes: 1 addition & 1 deletion docs/node/index.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# The Trinsic Javascript / Node SDK

The Trinsic Node SDK makes it easy to interact with the Trinsic API from any backend javascript application. The most recent version of the library can be found on npm. You can find the SDKs source on [Github](https://github.com/trinsic-id/sdk/java).
The Trinsic Node SDK makes it easy to interact with the Trinsic API from any backend javascript application. The most recent version of the library can be found on npm. You can find the SDKs source on [Github](https://github.com/trinsic-id/sdk/node).
## Installation
Install the package for Node from [npmjs.com <small>:material-open-in-new:<small>](https://www.npmjs.com/package/@trinsic/trinsic){target=_blank}

Expand Down
6 changes: 3 additions & 3 deletions docs/reference/services/account-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ provide are evidenced in the code snippets below:
```
=== "Java"
```java
var protectedProfile = accountService.protect(accountProfile, "1234");
var protectedProfile = AccountService.protect(accountProfile, "1234");
```
=== "Ruby"
```ruby
Expand All @@ -191,15 +191,15 @@ email or SMS as the `securityCode` argument.
```
=== "Python"
```python
account_profile = account_service.protect(protected_profile, "1234".encode('utf-8'))
account_profile = account_service.unprotect(protected_profile, "1234".encode('utf-8'))
```
=== "Go"
```golang
accountProfile, err := accountService.Unprotect(protectedProfile, "1234")
```
=== "Java"
```java
var accountProfile = accountService.unprotect(protectedProfile, "1234");
var accountProfile = AccountService.unprotect(protectedProfile, "1234");
```
=== "Ruby"
```ruby
Expand Down
92 changes: 40 additions & 52 deletions docs/reference/services/credential-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,37 +13,35 @@ The Credential service supports signing data using [BBS+ Signatures <small>:mate
trinsic issuer issue --document <INPUT_JSONLD_FILE> --out <OUTPUT_FILE>
```
=== "TypeScript"

<!--codeinclude-->
```typescript
let unsignedDocument = {
"@context": "https://w3id.org/security/v2",
"id": "https://issuer.oidp.uscis.gov/credentials/83627465"
}

let signedDocument = await credentialService.issue(unsignedDocument);
[Issue Credential](../../../node/test/VaccineDemo.ts) inside_block:issueCredential
```
<!--/codeinclude-->

=== "C#"

<!--codeinclude-->
```csharp
var unsignedDocument = new JObject
{
{ "@context", "https://w3id.org/security/v2" },
{ "id", "https://issuer.oidp.uscis.gov/credentials/83627465" }
};

var signedDocument = await credentialService.IssueCredential(unsignedDocument);
[Issue Credential](../../../dotnet/Tests/Tests.cs) inside_block:issueCredentialSample
```
<!--/codeinclude-->

=== "Python"

```python
import json
credential_json = json.dumps({
{ "@context", "https://w3id.org/security/v2" },
{ "id", "https://issuer.oidp.uscis.gov/credentials/83627465" }
})
credential = await credential_service.issue_credential(credential_json)

```

=== "Go"
```golang

```
=== "Java"
```java

```
=== "Ruby"
```ruby

```

The output of this method will be a signed JSON document using BBS+ Signature Suite 2020. This document is not automatically stored in the wallet when issued. You need to call the [insert record](#insert-record) separately if you'd like to store a copy of this document.
Expand All @@ -55,13 +53,18 @@ The output of this method will be a signed JSON document using BBS+ Signature Su

```
=== "TypeScript"
<!--codeinclude-->
```typescript

[Issue From Template](../../../node/test/CredentialTemplates.ts) inside_block:issueFromTemplate
```
<!--/codeinclude-->

=== "C#"
<!--codeinclude-->
```csharp

[Issue From Template](../../../dotnet/Tests/Tests.cs) inside_block:issueFromTemplate
```
<!--/codeinclude-->

=== "Python"
```python
Expand Down Expand Up @@ -160,33 +163,20 @@ The endpoint to create a proof requires two inputs:
```bash
trinsic vc create-proof --document-id <STRING> --out <OUTPUT_FILE> --reveal-document <JSONLD_FRAME_FILE>
```
=== "TypeScript"

=== "TypeScript"
<!--codeinclude-->
```typescript
let frame = {
"@context": "https://www.w3.org/2018/credentials/v1",
"type": [ "VerifiableCredential" ],
"@explicit": true,
"issuer": {}
}
let itemId = "<item document id>";

let signedDocument = await credentialService.createProof(itemId, frame);
[CreateProof](../../../node/test/WalletService.ts) inside_block:createProof
```
<!--/codeinclude-->

=== "C#"

<!--codeinclude-->
```csharp
var frame = new JObject
{
{ "@context", "https://www.w3.org/2018/credentials/v1" },
{ "@explicit", true }
{ "issuer", new JObject() }
};
var itemId = "<item document id>";

var signedDocument = await credentialService.CreateProof(itemId, frame);
[CreateProof](../../../dotnet/Tests/Tests.cs) inside_block:createProof
```
<!--/codeinclude-->

=== "Python"

Expand All @@ -211,20 +201,18 @@ This endpoint verifies if the submitted data contains a valid proof. The data to
trinsic vc issuer verify-proof --proof-document <JSONLD_FILE>
```
=== "TypeScript"

<!--codeinclude-->
```typescript
let isValid = await credentialService.verifyProof(proofDocument);

console.log("Verify result: " + isValid);
[VerifyProof](../../../node/test/WalletService.ts) inside_block:verifyProof
```
<!--/codeinclude-->

=== "C#"

<!--codeinclude-->
```csharp
var isValid = await credentialService.VerifyProof(proofDocument);

Console.WriteLine($"Verify result: {isValid}");
[CreateProof](../../../dotnet/Tests/Tests.cs) inside_block:verifyProof
```
<!--/codeinclude-->

=== "Python"
```python
Expand Down
11 changes: 8 additions & 3 deletions docs/reference/services/template-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,25 @@ These credential templates can be shared between issuers in an ecosystem.

A template is a saved JSON-LD schema that is used to define/create credentials and verification.

### Create
### Create Credential Template

=== "Trinsic CLI"
```bash

```
=== "TypeScript"
<!--codeinclude-->
```typescript

[Define Template](../../../node/test/CredentialTemplates.ts) inside_block:defineTemplate
```
<!--/codeinclude-->

=== "C#"
<!--codeinclude-->
```csharp

[CreateProof](../../../dotnet/Tests/Tests.cs) inside_block:createTemplate
```
<!--/codeinclude-->

=== "Python"
```python
Expand Down
80 changes: 19 additions & 61 deletions docs/reference/services/wallet-service.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,49 +5,8 @@ The wallet service is the main interface for interacting with a cloud wallet. Th

## Create Wallet

Wallets can be created directly by the user or through an invitation by the ecosystem provider. Depending on the ecosystem settings, direct wallet creation may not be enabled for your provider.
Wallets can be created directly by the user or through an invitation by the ecosystem provider. Depending on the ecosystem settings, direct wallet creation may not be enabled for your provider. The wallet is created automatically upon user signin.

### Create wallet directly

To create a wallet directly without an invitation, use the following methods. These methods return secure profile data that should be stored in a safe place. The profile is used to authenticate the wallet service with the cloud provider. Read more details and recommendations in the [Security Profiles](/reference/#authorization) page.

=== "Trinsic CLI"
```bash
trinsic wallet create --name <profile_name>
```
=== "TypeScript"
```typescript
const profile = await walletService.createWallet();
```
=== "C#"
```csharp
var profile = await walletService.Create();
```
=== "Python"
```python
profile = await wallet_service.create_wallet()
```

### Create wallet with provider invitation

If invited by a provider, you can supply the security code found in your invitation (via email, SMS, etc). Read more about [inviting participants](/reference/services/provider-service/#invite-participants) to your ecosystem as provider.

=== "Trinsic CLI"
```bash
trinsic wallet create --name <profile> --security-code <code>
```
=== "TypeScript"
```typescript
const profile = await walletService.createWallet("<security code>");
```
=== "C#"
```csharp
var profile = await walletService.Create("<security code>");
```
=== "Python"
```python
profile = await wallet_service.create_wallet("<security code>")
```

## Insert Item

Expand All @@ -58,20 +17,17 @@ This method allows inserting any JSON data in the wallet.
trinsic wallet insert-item --item <INPUT_JSON_FILE>
```
=== "TypeScript"
<!--codeinclude-->
```typescript
let itemId = await walletService.insertItem({
"foo": "bar"
});
[VerifyProof](../../../node/test/WalletService.ts) inside_block:insertItemWallet
```
<!--/codeinclude-->
=== "C#"
<!--codeinclude-->
```csharp
var item = new JObject
{
{ "foo", "bar" }
};

var itemId = await walletService.InsertItem(item);
[CreateProof](../../../dotnet/Tests/Tests.cs) inside_block:insertItemWallet
```
<!--/codeinclude-->
=== "Python"
```python
item_id = await wallet_service.insert_item(credential)
Expand All @@ -94,16 +50,18 @@ The default query used in the commands below returns a full wallet result set. T
trinsic wallet search
```
=== "TypeScript"

<!--codeinclude-->
```typescript
const items = await walletService.Search();
[SearchWallet](../../../node/test/WalletService.ts) inside_block:searchWallet
```
<!--/codeinclude-->

=== "C#"

<!--codeinclude-->
```csharp
var items = await walletService.Search();
[CreateProof](../../../dotnet/Tests/Tests.cs) inside_block:searchWallet
```
<!--/codeinclude-->

=== "Python"
```python
Expand All @@ -120,18 +78,18 @@ To pass custom query to the search function, use the query parameter or the avai
--query "SELECT * FROM c WHERE c.type = 'VerifiableCredential'"
```
=== "TypeScript"

<!--codeinclude-->
```typescript
const query = "SELECT * FROM c WHERE c.type = 'VerifiableCredential'";

const items = await walletService.search(query);
[VerifyProof](../../../node/test/WalletService.ts) inside_block:searchWalletSQL
```
<!--/codeinclude-->

=== "C#"

<!--codeinclude-->
```csharp
var items = await walletService.Search("SELECT * FROM c WHERE c.type = 'VerifiableCredential'");
[CreateProof](../../../dotnet/Tests/Tests.cs) inside_block:searchWalletSQL
```
<!--/codeinclude-->

=== "Python"
```python
Expand Down
Loading

0 comments on commit 322916b

Please sign in to comment.