Skip to content

Commit 52f0676

Browse files
authored
Feat/wallet sdk web (#448)
* wallet-sdk-web * setting up wallet-sdk-web * setting up wallet-sdk-web * rename package * updating package.json * updating docs * updating docs * updating docs * updating docs * updating docs * updating docs * Playwright tests + adding jsdocs * Playwright tests * fixing tests * improve validation * minify bundle output * fixing lint * fixing tests * fixing tests * fixing issues with bbs credentials * fixing presentation issues * fixing lint * fixing range proofs issues * fixing lint * fixing lint
1 parent bc8dae2 commit 52f0676

14 files changed

Lines changed: 3051 additions & 85 deletions

package-lock.json

Lines changed: 1955 additions & 79 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/wasm/src/services/credential/pex-helpers.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ export const EPSILON_INT = 1;
55

66
export const MAX_DATE_PLACEHOLDER = 884541351600000;
77
export const MIN_DATE_PLACEHOLDER = -17592186044415;
8-
export const MAX_INTEGER = 100 ** 9;
9-
export const MIN_INTEGER = -4294967295;
10-
export const MAX_NUMBER = 100 ** 5;
11-
export const MIN_NUMBER = -4294967294;
8+
export const MAX_INTEGER = Number.MAX_SAFE_INTEGER;
9+
export const MIN_INTEGER = Number.MIN_SAFE_INTEGER;
10+
export const MAX_NUMBER = Number.MAX_SAFE_INTEGER;
11+
export const MIN_NUMBER = Number.MIN_SAFE_INTEGER;
1212

1313
/*
1414
PEX Filter rules:

packages/wasm/src/services/credential/pex-helpers.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ describe('pex helpers', () => {
302302
{
303303
attributeName: 'credentialSubject.age',
304304
min: 0,
305-
max: 10000000000,
305+
max: Number.MAX_SAFE_INTEGER,
306306
proofRequestMax: undefined,
307307
proofRequestMin: 0,
308308
format: undefined,
@@ -357,7 +357,7 @@ describe('pex helpers', () => {
357357
{
358358
attributeName: 'credentialSubject.age',
359359
min: 0,
360-
max: 10000000000,
360+
max: Number.MAX_SAFE_INTEGER,
361361
proofRequestMax: undefined,
362362
proofRequestMin: 0,
363363
format: undefined,

packages/web/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dist
2+
test-results
3+
playwright-report

packages/web/LICENSE

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
The Dock Labs Non-Production License (the “DL-NPL”)
2+
Copyright (c) 2024 Dock Labs AG.
3+
4+
This software and associated documentation files (the "Software") may only be
5+
used in production, if you (and any entity that you represent) have agreed to,
6+
and are in compliance with, the Dock Labs Subscription Master Services Agreement
7+
(MSA), available at https://www.dock.io/master-services-agreement (the “Dock
8+
Terms”), or other agreement governing the use of the Software, as agreed by you
9+
and Dock Labs, and otherwise have a valid Dock Labs subscription that is being
10+
utilized as intended and for its designated purposes.
11+
12+
Subject to the foregoing sentence, you are free to modify this Software and
13+
publish patches to the Software. You agree that Dock Labs and/or its licensors
14+
(as applicable) retain all right, title and interest in and to all such
15+
modifications and/or patches, and all such modifications and/or patches may only
16+
be used, copied, modified, displayed, distributed, or otherwise exploited with a
17+
valid Dock Labs subscription that is being utilized as intended and for its
18+
designated purposes. Notwithstanding the foregoing, you may copy and modify the
19+
Software without obtaining a subscription only for non-production development
20+
and testing purposes. For the avoidance of doubt, non-production use solely
21+
consists of internal use of this software within a non-production development or
22+
test environment which uses fictitious data in non-durable identity credentials.
23+
You are not granted any other rights beyond what is expressly stated herein.
24+
Subject to the foregoing, it is forbidden to copy, merge, publish, distribute,
25+
sublicense, and/or sell the Software.
26+
27+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
29+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
30+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
31+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
32+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33+
34+
For all third party components incorporated into the Dock Labs Software, those
35+
components are licensed under the original license provided by the owner of the
36+
applicable component.
37+
38+
If you have any questions or need further assistance, please contact
39+
support@dock.io.

packages/web/README.md

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
# Truvera Web Wallet SDK
2+
3+
A simplified, browser-ready wrapper for the Wallet SDK, specialized for cloud wallet functionality.
4+
5+
## Installation
6+
7+
```bash
8+
npm install @docknetwork/wallet-sdk-web
9+
```
10+
11+
or via CDN:
12+
13+
```html
14+
<script src="https://unpkg.com/@docknetwork/wallet-sdk-web/dist/wallet-sdk-web.iife.js"></script>
15+
```
16+
17+
## Usage
18+
19+
The SDK can be used via a global variable (Script Tag) or imported as an ES Module (Bundlers).
20+
21+
> [!IMPORTANT]
22+
> This SDK is designed for **browser-side use only**.
23+
24+
1. **Client-Side Only**: Your wallet keys (mnemonic/master key) decrypt your data locally in the browser. **Never** send these keys to a server or store them where they can be accessed by third parties.
25+
2. **No Server-Side Operations**: Do not use this SDK to initialize wallets or process keys on a backend server. Server-side handling of user keys creates significant security risks and breaks the non-custodial model.
26+
3. **End-to-End Encryption**: User data stored in the Cloud Wallet (EDV) is fully encrypted. The decryption key exists *only* in the user's browser session.
27+
4. **Authentication vs Encryption**: The `edvAuthKey` is strictly for authenticating the client with the storage server. It does **not** grant access to the encrypted data content; only the user's keys can do that. You can request an `edvAuthKey` by contacting Truvera support at [docs.truvera.io/support](https://docs.truvera.io/support).
28+
29+
### 1. Script Tag (Global)
30+
31+
When loaded via `<script>`, the SDK exposes a global variable `TruveraWebWallet`.
32+
33+
```html
34+
<script src="https://unpkg.com/@docknetwork/wallet-sdk-web/dist/wallet-sdk-web.iife.js"></script>
35+
<script>
36+
window.addEventListener('load', async () => {
37+
const wallet = await TruveraWebWallet.initialize({ ... });
38+
});
39+
</script>
40+
```
41+
42+
### 2. ES Module (Vite, Webpack, etc.)
43+
44+
You can import the SDK in your modern web application.
45+
46+
```javascript
47+
// Default import
48+
import TruveraWebWallet from '@docknetwork/wallet-sdk-web';
49+
50+
async function main() {
51+
const wallet = await TruveraWebWallet.initialize({ ... });
52+
}
53+
```
54+
55+
56+
57+
### Key Generation (Optional)
58+
59+
If you don't have a mnemonic, you can generate a new master key/mnemonic pair using the SDK:
60+
61+
```javascript
62+
const { masterKey, mnemonic } = await TruveraWebWallet.generateCloudWalletMasterKey();
63+
64+
console.log('Mnemonic:', mnemonic);
65+
console.log('Master Key:', masterKey);
66+
```
67+
68+
### Initialization
69+
70+
```javascript
71+
const wallet = await TruveraWebWallet.initialize({
72+
edvUrl: 'https://edv.dock.io',
73+
edvAuthKey: '<your-auth-key>',
74+
networkId: 'testnet',
75+
// Use the mnemonic from generation or your existing one
76+
mnemonic: mnemonic, // or use masterKey: masterKey
77+
});
78+
79+
const credentials = await wallet.getCredentials();
80+
81+
console.log(credentials);
82+
```
83+
84+
85+
## API Reference
86+
87+
The `initialize` method returns a `wallet` object with the following simplified methods:
88+
89+
### `getCredentials`
90+
91+
Get the list of credentials stored in the wallet.
92+
93+
```javascript
94+
const credentials = await wallet.getCredentials();
95+
```
96+
97+
**Returns**: `Promise<Array<Object>>` - Array of credential objects.
98+
99+
---
100+
101+
### `addCredential`
102+
103+
Import a credential using an offer URI.
104+
105+
```javascript
106+
const credential = await wallet.addCredential('openid-credential-offer://...');
107+
```
108+
109+
**Parameters**:
110+
- `uri` (string): The credential offer URI.
111+
112+
**Returns**: `Promise<Object>` - The imported credential.
113+
114+
---
115+
116+
### `getDID`
117+
118+
Get the default Decentralized Identifier (DID) associated with the wallet.
119+
120+
```javascript
121+
const did = await wallet.getDID();
122+
```
123+
124+
**Returns**: `Promise<object>` - The DID document.
125+
126+
---
127+
128+
### `submitPresentation`
129+
130+
Submit a presentation for specific credentials to a proof request URL.
131+
132+
```javascript
133+
const response = await wallet.submitPresentation({
134+
credentials: [
135+
{
136+
id: 'https://creds-testnet.truvera.io/c7f3e722287d1ea98c136ad5df8066209c5e9b44c6251af0860d62e9a3a21a76',
137+
attributesToReveal: ['credentialSubject.fullName', 'credentialSubject.age']
138+
},
139+
],
140+
proofRequestUrl: 'https://creds-staging.truvera.io/proof/77ae2c67-678e-4cb6-8c5d-a4dd4a1a19f1'
141+
});
142+
```
143+
144+
**Parameters**:
145+
- `credentials` (Array<Object>): Array of credential objects to include in the presentation.
146+
- `credentials[].id` (string): The credential ID.
147+
- `credentials[].attributesToReveal` (Array<string>): Array of attribute names to reveal from this credential.
148+
- `proofRequestUrl` (string): The URL of the proof request template from the verifier.
149+
150+
**Returns**: `Promise<Object>` - The submission response from the verifier.

packages/web/example.html

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
4+
<head>
5+
<meta charset="UTF-8" />
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
7+
<title>Truvera Web Wallet Example</title>
8+
</head>
9+
10+
<body>
11+
<!-- Load the Truvera Web Wallet bundle -->
12+
<script src="https://unpkg.com/@docknetwork/wallet-sdk-web/dist/wallet-sdk-web.iife.js"></script>
13+
14+
<script>
15+
// Log initial load
16+
window.addEventListener('load', async () => {
17+
const {mnemonic} = await TruveraWebWallet.generateCloudWalletMasterKey();
18+
const wallet = await TruveraWebWallet.initialize({
19+
edvUrl: 'https://edv.dock.io',
20+
edvAuthKey: '<your-auth-key>',
21+
networkId: 'testnet',
22+
mnemonic: mnemonic,
23+
});
24+
const credentials = await wallet.getCredentials();
25+
26+
console.log(credentials);
27+
});
28+
</script>
29+
</body>
30+
31+
</html>

packages/web/package.json

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"name": "@docknetwork/wallet-sdk-web",
3+
"version": "0.0.10",
4+
"license": "https://github.com/docknetwork/wallet-sdk/LICENSE",
5+
"repository": {
6+
"type": "git",
7+
"url": "https://github.com/docknetwork/wallet-sdk",
8+
"directory": "packages/web-wallet"
9+
},
10+
"main": "dist/wallet-sdk-web.iife.js",
11+
"module": "dist/wallet-sdk-web.esm.js",
12+
"exports": {
13+
".": {
14+
"import": "./dist/wallet-sdk-web.esm.js",
15+
"require": "./dist/wallet-sdk-web.iife.js",
16+
"default": "./dist/wallet-sdk-web.iife.js"
17+
}
18+
},
19+
"browser": "dist/wallet-sdk-web.iife.js",
20+
"unpkg": "dist/wallet-sdk-web.iife.js",
21+
"files": [
22+
"dist",
23+
"src",
24+
"README.md"
25+
],
26+
"scripts": {
27+
"build": "rollup -c",
28+
"clean": "rm -rf dist",
29+
"test": "playwright test",
30+
"test:ui": "playwright test --ui",
31+
"test:headed": "playwright test --headed"
32+
},
33+
"devDependencies": {
34+
"@docknetwork/wallet-sdk-core": "^1.7.0",
35+
"@docknetwork/wallet-sdk-data-store": "^1.7.0",
36+
"@docknetwork/wallet-sdk-data-store-web": "^1.7.0",
37+
"@playwright/test": "^1.58.0",
38+
"@rollup/plugin-babel": "^6.1.0",
39+
"@rollup/plugin-commonjs": "^29.0.0",
40+
"@rollup/plugin-inject": "^5.0.5",
41+
"@rollup/plugin-json": "^6.1.0",
42+
"@rollup/plugin-node-resolve": "^16.0.3",
43+
"@rollup/plugin-replace": "^6.0.3",
44+
"@rollup/plugin-terser": "^0.4.4",
45+
"@rollup/plugin-typescript": "^12.3.0",
46+
"@rollup/plugin-wasm": "^6.2.2",
47+
"babel-loader": "^8.4.1",
48+
"buffer": "^6.0.3",
49+
"crypto-browserify": "^3.12.1",
50+
"http-server": "^14.1.1",
51+
"node-polyfill-webpack-plugin": "^2.0.1",
52+
"rollup": "^4.57.0",
53+
"rollup-plugin-node-polyfills": "^0.2.1",
54+
"rollup-plugin-polyfill-node": "^0.13.0",
55+
"stream-browserify": "^3.0.0",
56+
"terser-webpack-plugin": "^5.3.16",
57+
"wasm-loader": "^1.3.0",
58+
"webpack": "^5.67.0",
59+
"webpack-cli": "^4.10.0"
60+
}
61+
}

packages/web/playwright.config.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const {defineConfig, devices} = require('@playwright/test');
2+
3+
module.exports = defineConfig({
4+
testDir: './test',
5+
testMatch: '**/*.test.js',
6+
fullyParallel: false,
7+
forbidOnly: !!process.env.CI,
8+
retries: process.env.CI ? 2 : 0,
9+
workers: 1,
10+
reporter: [['list'], ['html', {outputFolder: 'playwright-report'}]],
11+
use: {
12+
trace: 'on-first-retry',
13+
screenshot: 'only-on-failure',
14+
video: 'retain-on-failure',
15+
},
16+
17+
projects: [
18+
{
19+
name: 'chromium',
20+
use: {...devices['Desktop Chrome']},
21+
},
22+
],
23+
24+
// Web server configuration
25+
webServer: {
26+
command: 'npx http-server . -p 8686 -c-1',
27+
port: 8686,
28+
timeout: 120 * 1000,
29+
reuseExistingServer: !process.env.CI,
30+
},
31+
});

0 commit comments

Comments
 (0)