|
1 | 1 | --- |
2 | 2 | title: Create and Share Access to Protected Data |
3 | | -description: Créer et partager l'accès aux données protégées |
| 3 | +description: |
| 4 | + Learn how to protect data and grant secure access for specific apps and users |
4 | 5 | --- |
5 | 6 |
|
6 | | -# Create and Share Access to Protected Data |
| 7 | +# 🛡️ Create and Share Access to Protected Data |
7 | 8 |
|
8 | | -Cette page est en cours de développement. |
| 9 | +**Want to keep your data private while still using it in applications?** Here's |
| 10 | +how DataProtector works: first you encrypt your data, then you control exactly |
| 11 | +who can access it and when. |
9 | 12 |
|
10 | | -<!-- TODO: Ajouter le guide de création et partage d'accès --> |
| 13 | +Once data is protected, it's only accessible inside secure enclaves (TEEs) by |
| 14 | +the specific people and iApps you authorize. No exceptions. |
| 15 | + |
| 16 | +## Quick Start |
| 17 | + |
| 18 | +First, install DataProtector in your project: |
| 19 | + |
| 20 | +::: code-group |
| 21 | + |
| 22 | +```bash [npm] |
| 23 | +npm install @iexec/dataprotector |
| 24 | +``` |
| 25 | + |
| 26 | +```bash [yarn] |
| 27 | +yarn add @iexec/dataprotector |
| 28 | +``` |
| 29 | + |
| 30 | +```bash [pnpm] |
| 31 | +pnpm add @iexec/dataprotector |
| 32 | +``` |
| 33 | + |
| 34 | +::: |
| 35 | + |
| 36 | +## Protect Your Data |
| 37 | + |
| 38 | +**Here's what happens:** Your data gets encrypted client-side and stored as an |
| 39 | +NFT. Only you control who can decrypt and use it. |
| 40 | + |
| 41 | +```ts |
| 42 | +import { IExecDataProtectorCore, getWeb3Provider } from '@iexec/dataprotector'; |
| 43 | + |
| 44 | +const web3Provider = getWeb3Provider('PRIVATE_KEY'); |
| 45 | +const dataProtectorCore = new IExecDataProtectorCore(web3Provider); |
| 46 | + |
| 47 | +const protectedData = await dataProtectorCore.protectData({ |
| 48 | + name: 'My Email Contact', |
| 49 | + data: { |
| 50 | + |
| 51 | + firstName: 'Alice', |
| 52 | + lastName: 'Smith', |
| 53 | + }, |
| 54 | +}); |
| 55 | + |
| 56 | +console.log('Protected data address:', protectedData.address); |
| 57 | +``` |
| 58 | + |
| 59 | +### What You Can Protect |
| 60 | + |
| 61 | +**Data**: Any JSON object with custom keys. Think user profiles, API |
| 62 | +credentials, datasets, model parameters - anything you want to keep private but |
| 63 | +still use in computations. |
| 64 | + |
| 65 | +**Supported types**: Strings, numbers, booleans, nested objects, files (convert |
| 66 | +to ArrayBuffer first), and arrays (convert to Record format). |
| 67 | + |
| 68 | +**Limits**: File size depends on your storage choice (IPFS or Arweave). For |
| 69 | +large datasets, consider using another IPFS node. |
| 70 | + |
| 71 | +::: tip Need Help? Check our |
| 72 | +[Schema and Dataset Types guide](/manage_data/guides/handle-schemas-dataset-types) |
| 73 | +for detailed formatting instructions. ::: |
| 74 | + |
| 75 | +### Debug Mode Option |
| 76 | + |
| 77 | +```ts |
| 78 | +const protectedData = await dataProtectorCore.protectData({ |
| 79 | + data: { email: '[email protected]' }, |
| 80 | + allowDebug: true, // Only for development/testing |
| 81 | +}); |
| 82 | +``` |
| 83 | + |
| 84 | +::: warning Debug mode lets you test with debug iApps during development. As |
| 85 | +"debug" iApps don't have the same security standards, we recommend using this |
| 86 | +mode only during iApp development. ::: |
| 87 | + |
| 88 | +## Grant Access |
| 89 | + |
| 90 | +**Here's the key:** The protocol blocks all access to your protected data by |
| 91 | +default. You must explicitly grant permission for each app and user combination. |
| 92 | + |
| 93 | +Once you own protected data, here's how to share access: |
| 94 | + |
| 95 | +```ts |
| 96 | +const grantedAccess = await dataProtectorCore.grantAccess({ |
| 97 | + protectedData: '0x123abc...', // Your protected data address |
| 98 | + authorizedApp: '0x456def...', // iApp that can process the data |
| 99 | + authorizedUser: '0x789cba...', // User who can trigger the processing |
| 100 | + pricePerAccess: 0, // Cost per use (in nRLC) |
| 101 | + numberOfAccess: 10, // Maximum number of uses |
| 102 | +}); |
| 103 | +``` |
| 104 | + |
| 105 | +### Parameters Explained |
| 106 | + |
| 107 | +#### `protectedData` <Badge type="danger" text="required" /> |
| 108 | + |
| 109 | +The address of your protected data (returned when you created it). **You must |
| 110 | +own this data** to grant access. |
| 111 | + |
| 112 | +#### `authorizedApp` <Badge type="danger" text="required" /> |
| 113 | + |
| 114 | +**What it is**: The iApp address that's allowed to process your data inside the |
| 115 | +secure enclave. |
| 116 | + |
| 117 | +**Why needed**: This ensures only specific, audited applications can access your |
| 118 | +data. No random code can touch it. |
| 119 | + |
| 120 | +**Pro tip**: Use app whitelists for production. Instead of a single app address, |
| 121 | +you can specify a whitelist contract that contains multiple approved app |
| 122 | +versions. Very useful for when you need to upgrade your iApps, without losing |
| 123 | +all the granted access. |
| 124 | + |
| 125 | +```ts |
| 126 | +// Single app |
| 127 | +authorizedApp: 'web3mail.apps.iexec.eth'; |
| 128 | + |
| 129 | +// Or use a whitelist (recommended for production) |
| 130 | +authorizedApp: '0x781482C39CcE25546583EaC4957Fb7Bf04C277D2'; // Web3Mail whitelist |
| 131 | +``` |
| 132 | + |
| 133 | +#### `authorizedUser` <Badge type="danger" text="required" /> |
| 134 | + |
| 135 | +**What it is**: The wallet address that can initiate processing of your data. |
| 136 | + |
| 137 | +**Why needed**: Even with an authorized app, only specific users can trigger the |
| 138 | +computation. This gives you granular control over who uses your data. |
| 139 | + |
| 140 | +**Don't forget**: Even if you are the owner of the data, you need to authorize |
| 141 | +yourself! |
| 142 | + |
| 143 | +**Special case**: Set to `0x0000000000000000000000000000000000000000` to allow |
| 144 | +**any user** to trigger processing (useful for public datasets). |
| 145 | + |
| 146 | +#### `pricePerAccess` <Badge type="tip" text="optional" /> |
| 147 | + |
| 148 | +**Quick explanation**: How much you charge per data usage (in nano RLC - nRLC). |
| 149 | + |
| 150 | +Set to `0` for free access, or specify a price to monetize your data |
| 151 | +automatically. |
| 152 | + |
| 153 | +**Example**: `pricePerAccess: 1000000000` = 1 RLC per access |
| 154 | + |
| 155 | +→ **Want to learn more monetization capabilities?** See our detailed |
| 156 | +[Manage Data Monetization guide](/manage_data/guides/manage-data-monetization) |
| 157 | + |
| 158 | +#### `numberOfAccess` <Badge type="tip" text="optional" /> |
| 159 | + |
| 160 | +**Quick explanation**: Maximum number of times this authorization can be used. |
| 161 | + |
| 162 | +::: warning Important If someone tries to process your data more times than |
| 163 | +allowed, they'll get a "no dataset orders" error. Set this high enough for your |
| 164 | +use case. ::: |
| 165 | + |
| 166 | +**Example values**: |
| 167 | + |
| 168 | +- `1` - Single use (great for one-time data analysis) |
| 169 | +- `100` - Limited campaign (email marketing with usage cap) |
| 170 | +- `10000` - Effectively unlimited for most use cases |
| 171 | + |
| 172 | +## What's Next? |
| 173 | + |
| 174 | +**You now have protected data with controlled access.** Here are your next |
| 175 | +steps: |
| 176 | + |
| 177 | +- **Process the data**: Use |
| 178 | + [processProtectedData](/manage_data/dataProtector/dataProtectorCore/processProtectedData) |
| 179 | + to run computations |
| 180 | +- **Manage access**: |
| 181 | + [Revoke](/manage_data/dataProtector/dataProtectorCore/revokeOneAccess) or |
| 182 | + [modify permissions](/manage_data/dataProtector/dataProtectorCore/grantAccess) |
| 183 | + anytime |
| 184 | +- **Learn data types**: Deep dive into |
| 185 | + [schemas and dataset types](/manage_data/guides/handle-schemas-dataset-types) |
| 186 | +- **Monetize data**: Explore |
| 187 | + [data monetization strategies](/manage_data/guides/manage-data-monetization) |
| 188 | + |
| 189 | +--- |
| 190 | + |
| 191 | +**TL;DR**: Protect data → Grant access to specific app + user → Data stays |
| 192 | +encrypted except inside authorized secure enclaves. You keep full control. 🔒 |
0 commit comments