Skip to content

Commit 9d68834

Browse files
authored
Merge pull request #297 from docknetwork/DCKW-617-update-examples-for-using-the-mobile-sdk
dckw-617: update wallet sdk docs
2 parents f91eb47 + 77aa682 commit 9d68834

File tree

1 file changed

+121
-0
lines changed

1 file changed

+121
-0
lines changed

docs/getting-started.md

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# Dock Wallet SDK
2+
3+
This guide walks you through the process of setting up the Dock Wallet SDK, creating a wallet, managing decentralized identifiers (DIDs), adding credentials, and verifying them.
4+
5+
## Installation
6+
7+
To start, you need to install the necessary packages for the wallet SDK and the data store. Open your terminal and run the following command:
8+
9+
```bash
10+
yarn add @docknetwork/wallet-sdk-core @docknetwork/wallet-sdk-data-store-typeorm
11+
```
12+
13+
The `@docknetwork/wallet-sdk-core` provides the core wallet functionality, while `@docknetwork/wallet-sdk-data-store-typeorm` handles data persistence using a local SQLite database.
14+
15+
## Usage Example
16+
17+
### 1. Initialize the Data Store
18+
19+
Before creating a wallet, you need to set up a data store to manage the persistence of wallet data such as DIDs and credentials. Here’s how to create a data store:
20+
21+
```ts
22+
import {createDataStore} from '@docknetwork/wallet-sdk-data-store-typeorm/lib';
23+
24+
const dataStore = await createDataStore({
25+
databasePath: 'dock-wallet',
26+
dbType: 'sqlite',
27+
defaultNetwork: 'testnet',
28+
});
29+
```
30+
31+
This code initializes a SQLite database to store wallet data. You can adjust the `databasePath` and `defaultNetwork` based on your needs.
32+
33+
If you want to use the cloud wallet solution, please refer to the [Cloud Wallet Documentation](cloud-wallet.md) for detailed instructions and configuration options.
34+
35+
### 2. Create a New Wallet
36+
37+
Once the data store is set up, you can create a wallet. The wallet will act as a container for managing your documents, DIDs, and credentials.
38+
39+
```ts
40+
import {createWallet} from '@docknetwork/wallet-sdk-core/lib/wallet';
41+
42+
const wallet = await createWallet({
43+
dataStore,
44+
});
45+
```
46+
47+
This creates a new wallet instance that links to the previously created data store.
48+
49+
### 3. Fetch your DIDs
50+
51+
DIDs (Decentralized Identifiers) are a key part of self-sovereign identity. When a wallet is created, a default DID is automatically generated. You can retrieve and view the default DID associated with your wallet using the following code:
52+
53+
```ts
54+
// The didProvider is used to manage DIDs
55+
import {createDIDProvider} from '@docknetwork/wallet-sdk-core/src/did-provider';
56+
57+
const didProvider = createDIDProvider({wallet});
58+
const defaultDID = await didProvider.getDefaultDID();
59+
60+
console.log(defaultDID);
61+
62+
// Example output: did:key:z6MkrcDhePAr5J44Htf6CLSQpZFUGGec4kPVVmERaY9Seijw
63+
```
64+
65+
### 4. Add a Credential to the Wallet
66+
67+
Once you have a wallet and a DID, you can start managing credentials. In this example, you will import a credential from a URL into the wallet.
68+
69+
```ts
70+
import {createCredentialProvider} from '@docknetwork/wallet-sdk-core/src/credential-provider';
71+
72+
const credentialProvider = createCredentialProvider({
73+
wallet, // Pass the wallet instance
74+
});
75+
76+
await credentialProvider.importCredentialFromURI({
77+
uri: 'https://creds-testnet.dock.io/8489dc69b69a70c97646ad9b4f256acaddb57762b5a6f661f0c9dae3b7f72ea6', // Credential URL
78+
getAuthCode: async () => {
79+
// You can implement your own UI to get the password
80+
// For this example it will be hardcoded
81+
return 'test';
82+
},
83+
});
84+
85+
const credentials = await credentialProvider.getCredentials(); // Retrieve all imported credentials
86+
87+
console.log(credentials);
88+
```
89+
90+
In this example, the credential is fetched from a specified URI and imported into the wallet. The `getAuthCode` function is used to handle any authentication, such as providing a password if required.
91+
92+
### 5. Verify a Credential
93+
94+
The Dock Wallet SDK provides built-in functionality for verifying credentials. This is especially useful when interacting with third parties who need to verify your credentials. The verification controller manages this process. Below is an example of how to start a verification, select which credentials to reveal, create a presentation, and submit it for verification.
95+
96+
```ts
97+
const {
98+
createVerificationController,
99+
} = require('@docknetwork/wallet-sdk-core/src/verification-controller');
100+
101+
const controller = createVerificationController({
102+
wallet, // Your wallet instance
103+
});
104+
105+
await controller.start({
106+
template: 'https://creds-testnet.dock.io/proof/1fd8c457-f805-4117-9469-67b3e8c70fff', // Proof request template from the verifier
107+
});
108+
109+
controller.selectedCredentials.set(credential.id, {
110+
credential: credential, // Specify the credential you want to present
111+
attributesToReveal: ['credentialSubject.name'] // Choose which attributes to reveal
112+
});
113+
114+
const presentation = await controller.createPresentation(); // Create a presentation based on the selected credentials
115+
116+
const verificationResponse = await controller.submitPresentation(presentation); // Submit the presentation for verification
117+
118+
console.log(verificationResponse);
119+
```
120+
121+
In this example, the verification process starts by fetching a proof request template. After selecting the credentials and specifying which attributes to reveal, the wallet creates a verifiable presentation. The presentation is then submitted, and the verifier responds with a verification result.

0 commit comments

Comments
 (0)