|
| 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. |
0 commit comments