Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,034 changes: 1,955 additions & 79 deletions package-lock.json

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions packages/wasm/src/services/credential/pex-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ export const EPSILON_INT = 1;

export const MAX_DATE_PLACEHOLDER = 884541351600000;
export const MIN_DATE_PLACEHOLDER = -17592186044415;
export const MAX_INTEGER = 100 ** 9;
export const MIN_INTEGER = -4294967295;
export const MAX_NUMBER = 100 ** 5;
export const MIN_NUMBER = -4294967294;
export const MAX_INTEGER = Number.MAX_SAFE_INTEGER;
export const MIN_INTEGER = Number.MIN_SAFE_INTEGER;
export const MAX_NUMBER = Number.MAX_SAFE_INTEGER;
export const MIN_NUMBER = Number.MIN_SAFE_INTEGER;

/*
PEX Filter rules:
Expand Down
4 changes: 2 additions & 2 deletions packages/wasm/src/services/credential/pex-helpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ describe('pex helpers', () => {
{
attributeName: 'credentialSubject.age',
min: 0,
max: 10000000000,
max: Number.MAX_SAFE_INTEGER,
proofRequestMax: undefined,
proofRequestMin: 0,
format: undefined,
Expand Down Expand Up @@ -357,7 +357,7 @@ describe('pex helpers', () => {
{
attributeName: 'credentialSubject.age',
min: 0,
max: 10000000000,
max: Number.MAX_SAFE_INTEGER,
proofRequestMax: undefined,
proofRequestMin: 0,
format: undefined,
Expand Down
3 changes: 3 additions & 0 deletions packages/web/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist
test-results
playwright-report
39 changes: 39 additions & 0 deletions packages/web/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
The Dock Labs Non-Production License (the “DL-NPL”)
Copyright (c) 2024 Dock Labs AG.

This software and associated documentation files (the "Software") may only be
used in production, if you (and any entity that you represent) have agreed to,
and are in compliance with, the Dock Labs Subscription Master Services Agreement
(MSA), available at https://www.dock.io/master-services-agreement (the “Dock
Terms”), or other agreement governing the use of the Software, as agreed by you
and Dock Labs, and otherwise have a valid Dock Labs subscription that is being
utilized as intended and for its designated purposes.

Subject to the foregoing sentence, you are free to modify this Software and
publish patches to the Software. You agree that Dock Labs and/or its licensors
(as applicable) retain all right, title and interest in and to all such
modifications and/or patches, and all such modifications and/or patches may only
be used, copied, modified, displayed, distributed, or otherwise exploited with a
valid Dock Labs subscription that is being utilized as intended and for its
designated purposes. Notwithstanding the foregoing, you may copy and modify the
Software without obtaining a subscription only for non-production development
and testing purposes. For the avoidance of doubt, non-production use solely
consists of internal use of this software within a non-production development or
test environment which uses fictitious data in non-durable identity credentials.
You are not granted any other rights beyond what is expressly stated herein.
Subject to the foregoing, it is forbidden to copy, merge, publish, distribute,
sublicense, and/or sell the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

For all third party components incorporated into the Dock Labs Software, those
components are licensed under the original license provided by the owner of the
applicable component.

If you have any questions or need further assistance, please contact
support@dock.io.
150 changes: 150 additions & 0 deletions packages/web/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
# Truvera Web Wallet SDK

A simplified, browser-ready wrapper for the Wallet SDK, specialized for cloud wallet functionality.

## Installation

```bash
npm install @docknetwork/wallet-sdk-web
```

or via CDN:

```html
<script src="https://unpkg.com/@docknetwork/wallet-sdk-web/dist/wallet-sdk-web.iife.js"></script>
```

## Usage

The SDK can be used via a global variable (Script Tag) or imported as an ES Module (Bundlers).

> [!IMPORTANT]
> This SDK is designed for **browser-side use only**.

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.
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.
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.
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).

### 1. Script Tag (Global)

When loaded via `<script>`, the SDK exposes a global variable `TruveraWebWallet`.

```html
<script src="https://unpkg.com/@docknetwork/wallet-sdk-web/dist/wallet-sdk-web.iife.js"></script>
<script>
window.addEventListener('load', async () => {
const wallet = await TruveraWebWallet.initialize({ ... });
});
</script>
```

### 2. ES Module (Vite, Webpack, etc.)

You can import the SDK in your modern web application.

```javascript
// Default import
import TruveraWebWallet from '@docknetwork/wallet-sdk-web';

async function main() {
const wallet = await TruveraWebWallet.initialize({ ... });
}
```



### Key Generation (Optional)

If you don't have a mnemonic, you can generate a new master key/mnemonic pair using the SDK:

```javascript
const { masterKey, mnemonic } = await TruveraWebWallet.generateCloudWalletMasterKey();

console.log('Mnemonic:', mnemonic);
console.log('Master Key:', masterKey);
```

### Initialization

```javascript
const wallet = await TruveraWebWallet.initialize({
edvUrl: 'https://edv.dock.io',
edvAuthKey: '<your-auth-key>',
networkId: 'testnet',
// Use the mnemonic from generation or your existing one
mnemonic: mnemonic, // or use masterKey: masterKey
});

const credentials = await wallet.getCredentials();

console.log(credentials);
```


## API Reference

The `initialize` method returns a `wallet` object with the following simplified methods:

### `getCredentials`

Get the list of credentials stored in the wallet.

```javascript
const credentials = await wallet.getCredentials();
```

**Returns**: `Promise<Array<Object>>` - Array of credential objects.

---

### `addCredential`

Import a credential using an offer URI.

```javascript
const credential = await wallet.addCredential('openid-credential-offer://...');
```

**Parameters**:
- `uri` (string): The credential offer URI.

**Returns**: `Promise<Object>` - The imported credential.

---

### `getDID`

Get the default Decentralized Identifier (DID) associated with the wallet.

```javascript
const did = await wallet.getDID();
```

**Returns**: `Promise<object>` - The DID document.

---

### `submitPresentation`

Submit a presentation for specific credentials to a proof request URL.

```javascript
const response = await wallet.submitPresentation({
credentials: [
{
id: 'https://creds-testnet.truvera.io/c7f3e722287d1ea98c136ad5df8066209c5e9b44c6251af0860d62e9a3a21a76',
attributesToReveal: ['credentialSubject.fullName', 'credentialSubject.age']
},
],
proofRequestUrl: 'https://creds-staging.truvera.io/proof/77ae2c67-678e-4cb6-8c5d-a4dd4a1a19f1'
});
```

**Parameters**:
- `credentials` (Array<Object>): Array of credential objects to include in the presentation.
- `credentials[].id` (string): The credential ID.
- `credentials[].attributesToReveal` (Array<string>): Array of attribute names to reveal from this credential.
- `proofRequestUrl` (string): The URL of the proof request template from the verifier.

**Returns**: `Promise<Object>` - The submission response from the verifier.
31 changes: 31 additions & 0 deletions packages/web/example.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Truvera Web Wallet Example</title>
</head>

<body>
<!-- Load the Truvera Web Wallet bundle -->
<script src="https://unpkg.com/@docknetwork/wallet-sdk-web/dist/wallet-sdk-web.iife.js"></script>

<script>
// Log initial load
window.addEventListener('load', async () => {
const {mnemonic} = await TruveraWebWallet.generateCloudWalletMasterKey();
const wallet = await TruveraWebWallet.initialize({
edvUrl: 'https://edv.dock.io',
edvAuthKey: '<your-auth-key>',
networkId: 'testnet',
mnemonic: mnemonic,
});
const credentials = await wallet.getCredentials();

console.log(credentials);
});
</script>
</body>

</html>
61 changes: 61 additions & 0 deletions packages/web/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"name": "@docknetwork/wallet-sdk-web",
"version": "0.0.10",
"license": "https://github.com/docknetwork/wallet-sdk/LICENSE",
"repository": {
"type": "git",
"url": "https://github.com/docknetwork/wallet-sdk",
"directory": "packages/web-wallet"
},
"main": "dist/wallet-sdk-web.iife.js",
"module": "dist/wallet-sdk-web.esm.js",
"exports": {
".": {
"import": "./dist/wallet-sdk-web.esm.js",
"require": "./dist/wallet-sdk-web.iife.js",
"default": "./dist/wallet-sdk-web.iife.js"
}
},
"browser": "dist/wallet-sdk-web.iife.js",
"unpkg": "dist/wallet-sdk-web.iife.js",
"files": [
"dist",
"src",
"README.md"
],
"scripts": {
"build": "rollup -c",
"clean": "rm -rf dist",
"test": "playwright test",
"test:ui": "playwright test --ui",
"test:headed": "playwright test --headed"
},
"devDependencies": {
"@docknetwork/wallet-sdk-core": "^1.7.0",
"@docknetwork/wallet-sdk-data-store": "^1.7.0",
"@docknetwork/wallet-sdk-data-store-web": "^1.7.0",
"@playwright/test": "^1.58.0",
"@rollup/plugin-babel": "^6.1.0",
"@rollup/plugin-commonjs": "^29.0.0",
"@rollup/plugin-inject": "^5.0.5",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^16.0.3",
"@rollup/plugin-replace": "^6.0.3",
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^12.3.0",
"@rollup/plugin-wasm": "^6.2.2",
"babel-loader": "^8.4.1",
"buffer": "^6.0.3",
"crypto-browserify": "^3.12.1",
"http-server": "^14.1.1",
"node-polyfill-webpack-plugin": "^2.0.1",
"rollup": "^4.57.0",
"rollup-plugin-node-polyfills": "^0.2.1",
"rollup-plugin-polyfill-node": "^0.13.0",
"stream-browserify": "^3.0.0",
"terser-webpack-plugin": "^5.3.16",
"wasm-loader": "^1.3.0",
"webpack": "^5.67.0",
"webpack-cli": "^4.10.0"
}
}
31 changes: 31 additions & 0 deletions packages/web/playwright.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const {defineConfig, devices} = require('@playwright/test');

module.exports = defineConfig({
testDir: './test',
testMatch: '**/*.test.js',
fullyParallel: false,
forbidOnly: !!process.env.CI,
retries: process.env.CI ? 2 : 0,
workers: 1,
reporter: [['list'], ['html', {outputFolder: 'playwright-report'}]],
use: {
trace: 'on-first-retry',
screenshot: 'only-on-failure',
video: 'retain-on-failure',
},

projects: [
{
name: 'chromium',
use: {...devices['Desktop Chrome']},
},
],

// Web server configuration
webServer: {
command: 'npx http-server . -p 8686 -c-1',
port: 8686,
timeout: 120 * 1000,
reuseExistingServer: !process.env.CI,
},
});
Loading
Loading