@genobank/biofs 1.3.4 β 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/BIONFS_DEPLOYMENT_GUIDE.md +408 -0
- package/BIONFS_MOUNT_INTEGRATION_PLAN.md +415 -0
- package/BIONFS_PROTOCOL_SPECIFICATION.md +688 -0
- package/BIONFS_SEQUENTIAS_INTEGRATION.md +457 -0
- package/BIONFT_NFS_PROTOCOL_ARCHITECTURE.md +583 -0
- package/GDPR_BIONFS_CONSENT_ARCHITECTURE.md +798 -0
- package/GDPR_BIONFS_IMPLEMENTATION_STATUS.md +462 -0
- package/SEQUENTIAS_PROTOCOL_ARCHITECTURE.md +880 -0
- package/ULTRATHINK_BIONFS_COMPLETE.md +458 -0
- package/WEB3FUSE_LICENSE_TOKEN_ANALYSIS.md +494 -0
- package/WHERE_PERMISSIONS_LIVE.md +165 -0
- package/dist/commands/access/revoke-consent.d.ts +13 -0
- package/dist/commands/access/revoke-consent.d.ts.map +1 -0
- package/dist/commands/access/revoke-consent.js +171 -0
- package/dist/commands/access/revoke-consent.js.map +1 -0
- package/dist/commands/download-with-consent.d.ts +12 -0
- package/dist/commands/download-with-consent.d.ts.map +1 -0
- package/dist/commands/download-with-consent.js +126 -0
- package/dist/commands/download-with-consent.js.map +1 -0
- package/dist/commands/mount.d.ts +11 -0
- package/dist/commands/mount.d.ts.map +1 -0
- package/dist/commands/mount.js +179 -0
- package/dist/commands/mount.js.map +1 -0
- package/dist/index.js +46 -10
- package/dist/index.js.map +1 -1
- package/dist/lib/biofiles/resolver.d.ts.map +1 -1
- package/dist/lib/biofiles/resolver.js +6 -1
- package/dist/lib/biofiles/resolver.js.map +1 -1
- package/dist/lib/consent/consent-manager.d.ts +34 -0
- package/dist/lib/consent/consent-manager.d.ts.map +1 -0
- package/dist/lib/consent/consent-manager.js +96 -0
- package/dist/lib/consent/consent-manager.js.map +1 -0
- package/dist/lib/consent/consent-prompt.d.ts +27 -0
- package/dist/lib/consent/consent-prompt.d.ts.map +1 -0
- package/dist/lib/consent/consent-prompt.js +118 -0
- package/dist/lib/consent/consent-prompt.js.map +1 -0
- package/dist/types/biofiles.d.ts +3 -0
- package/dist/types/biofiles.d.ts.map +1 -1
- package/lib/bionfs-client.js +125 -0
- package/lib/consent-manager.js +88 -0
- package/lib/consent-prompt.js +118 -0
- package/package.json +2 -2
|
@@ -0,0 +1,798 @@
|
|
|
1
|
+
# π GDPR-Compliant BioNFS Access Architecture
|
|
2
|
+
|
|
3
|
+
## π§ ULTRATHINK ANALYSIS: Genomic Data Access Consent
|
|
4
|
+
|
|
5
|
+
### Legal Requirements (GDPR Articles 6, 7, 9)
|
|
6
|
+
|
|
7
|
+
**Article 9 - Special Categories of Personal Data:**
|
|
8
|
+
> "Processing of personal data revealing...genetic data...shall be prohibited EXCEPT where...the data subject has given explicit consent."
|
|
9
|
+
|
|
10
|
+
**Article 7 - Conditions for Consent:**
|
|
11
|
+
> "The data subject shall have the right to withdraw consent at any time."
|
|
12
|
+
|
|
13
|
+
**Article 13 - Information to be Provided:**
|
|
14
|
+
> "The controller shall provide the data subject with: (a) identity of controller, (b) purposes of processing, (c) legitimate interests, (d) recipients of data, (e) right to withdraw consent."
|
|
15
|
+
|
|
16
|
+
### π― Design Principles
|
|
17
|
+
|
|
18
|
+
1. **Informed Consent** - User understands EXACTLY what they're accessing
|
|
19
|
+
2. **Explicit Agreement** - Requires active "yes" (not just "OK")
|
|
20
|
+
3. **Granular Control** - Per-file consent, not blanket approval
|
|
21
|
+
4. **Revocable** - Can withdraw consent anytime via `biofs access revoke`
|
|
22
|
+
5. **Auditable** - All consent actions logged on-chain + MongoDB
|
|
23
|
+
6. **Minimal Data** - Only show consent for files being accessed NOW
|
|
24
|
+
|
|
25
|
+
---
|
|
26
|
+
|
|
27
|
+
## Architecture Overview
|
|
28
|
+
|
|
29
|
+
```
|
|
30
|
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
31
|
+
β Dr. Claudia's Workflow β
|
|
32
|
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
|
|
33
|
+
β β
|
|
34
|
+
β biofs download "55052008714000.deepvariant.vcf" β
|
|
35
|
+
β β β
|
|
36
|
+
β β β
|
|
37
|
+
β βββββββββββββββββββββββββββββββββββββββββββ β
|
|
38
|
+
β β 1. Check if consent already given β β
|
|
39
|
+
β β - Query MongoDB: consents collectionβ β
|
|
40
|
+
β β - Key: {wallet, ip_id, action} β β
|
|
41
|
+
β βββββββββββββββββββββββββββββββββββββββββββ β
|
|
42
|
+
β β β
|
|
43
|
+
β β NO CONSENT FOUND β
|
|
44
|
+
β βββββββββββββββββββββββββββββββββββββββββββ β
|
|
45
|
+
β β 2. Display GDPR Consent Notice β β
|
|
46
|
+
β β β β
|
|
47
|
+
β β ββββββββββββββββββββββββββββββββββββββ β β
|
|
48
|
+
β β β GENOMIC DATA ACCESS CONSENT β β β
|
|
49
|
+
β β β βββββββββββββββββββββββββββββββββββββ£ β β
|
|
50
|
+
β β β File: 55052008714000.deepvariant.vcfβ β β
|
|
51
|
+
β β β Owner: 0x5f5a...d19a (Daniel Uribe)β β β
|
|
52
|
+
β β β License: Non-Commercial Use β β β
|
|
53
|
+
β β β β β β
|
|
54
|
+
β β β YOU ARE ABOUT TO ACCESS: β β β
|
|
55
|
+
β β β β’ Genomic variants (VCF format) β β β
|
|
56
|
+
β β β β’ Potentially identifying genetic β β β
|
|
57
|
+
β β β information protected under GDPR β β β
|
|
58
|
+
β β β Article 9 (Special Categories) β β β
|
|
59
|
+
β β β β β β
|
|
60
|
+
β β β PURPOSE OF ACCESS: β β β
|
|
61
|
+
β β β Research and clinical analysis β β β
|
|
62
|
+
β β β β β β
|
|
63
|
+
β β β YOUR RIGHTS: β β β
|
|
64
|
+
β β β β Revoke access anytime β β β
|
|
65
|
+
β β β β All access is logged (audit trail)β β β
|
|
66
|
+
β β β β Data owner can revoke your licenseβ β β
|
|
67
|
+
β β β β β β
|
|
68
|
+
β β β LICENSE TERMS: β β β
|
|
69
|
+
β β β β’ Non-commercial use only β β β
|
|
70
|
+
β β β β’ Attribution required β β β
|
|
71
|
+
β β β β’ No redistribution β β β
|
|
72
|
+
β β β β β β
|
|
73
|
+
β β β By typing "I AGREE" you confirm: β β β
|
|
74
|
+
β β β 1. You understand this is genomic β β β
|
|
75
|
+
β β β data protected under GDPR β β β
|
|
76
|
+
β β β 2. You will use it only for stated β β β
|
|
77
|
+
β β β purposes β β β
|
|
78
|
+
β β β 3. You will comply with license termsβ β β
|
|
79
|
+
β β ββββββββββββββββββββββββββββββββββββββ β β
|
|
80
|
+
β β β β
|
|
81
|
+
β β > Type "I AGREE" to proceed: _____ β β
|
|
82
|
+
β βββββββββββββββββββββββββββββββββββββββββββ β
|
|
83
|
+
β β β
|
|
84
|
+
β β USER TYPES "I AGREE" β
|
|
85
|
+
β βββββββββββββββββββββββββββββββββββββββββββ β
|
|
86
|
+
β β 3. Record Consent β β
|
|
87
|
+
β β - Save to MongoDB consents collectionβ β
|
|
88
|
+
β β - Log to blockchain (optional) β β
|
|
89
|
+
β β - Timestamp + wallet signature β β
|
|
90
|
+
β βββββββββββββββββββββββββββββββββββββββββββ β
|
|
91
|
+
β β β
|
|
92
|
+
β β β
|
|
93
|
+
β βββββββββββββββββββββββββββββββββββββββββββ β
|
|
94
|
+
β β 4. Proceed with Download/Mount β β
|
|
95
|
+
β β - Authenticate with BioNFS server β β
|
|
96
|
+
β β - Verify license token β β
|
|
97
|
+
β β - Stream file from S3 β β
|
|
98
|
+
β βββββββββββββββββββββββββββββββββββββββββββ β
|
|
99
|
+
β β β
|
|
100
|
+
β β β
|
|
101
|
+
β β
File downloaded to: ./55052008714000.deepvariant.vcf β
|
|
102
|
+
β β
|
|
103
|
+
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
---
|
|
107
|
+
|
|
108
|
+
## Data Model: Consent Records
|
|
109
|
+
|
|
110
|
+
### MongoDB Collection: `bioip_access_consents`
|
|
111
|
+
|
|
112
|
+
```javascript
|
|
113
|
+
{
|
|
114
|
+
"_id": ObjectId("..."),
|
|
115
|
+
"wallet_address": "0xb3c3a584491b8ca4df45116a1e250098a0d6192d", // Dr. Claudia
|
|
116
|
+
"ip_id": "0xCCe14315eE3D6a41596EeB4a2839eE50A8ec59f7",
|
|
117
|
+
"filename": "55052008714000.deepvariant.vcf",
|
|
118
|
+
"data_owner": "0x5f5a60EaEf242c0D51A21c703f520347b96Ed19a", // Daniel
|
|
119
|
+
"license_token_id": 40249,
|
|
120
|
+
"license_type": "non-commercial",
|
|
121
|
+
|
|
122
|
+
"action": "download", // or "mount"
|
|
123
|
+
"purpose": "research_and_clinical_analysis",
|
|
124
|
+
|
|
125
|
+
"consent_text_version": "v1.0", // Track which consent text was shown
|
|
126
|
+
"consent_given_at": ISODate("2025-10-07T06:00:00Z"),
|
|
127
|
+
"consent_ip_address": "192.168.1.100",
|
|
128
|
+
"consent_user_agent": "BioFS CLI v1.0.0",
|
|
129
|
+
|
|
130
|
+
"gdpr_rights_acknowledged": true,
|
|
131
|
+
"license_terms_acknowledged": true,
|
|
132
|
+
|
|
133
|
+
"access_count": 1, // Increment on each access
|
|
134
|
+
"last_accessed_at": ISODate("2025-10-07T06:00:00Z"),
|
|
135
|
+
|
|
136
|
+
"revoked": false,
|
|
137
|
+
"revoked_at": null,
|
|
138
|
+
"revoked_reason": null
|
|
139
|
+
}
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
**Indexes:**
|
|
143
|
+
```javascript
|
|
144
|
+
db.bioip_access_consents.createIndex({ wallet_address: 1, ip_id: 1, action: 1 });
|
|
145
|
+
db.bioip_access_consents.createIndex({ ip_id: 1 });
|
|
146
|
+
db.bioip_access_consents.createIndex({ data_owner: 1 });
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## Implementation: Consent Flow
|
|
152
|
+
|
|
153
|
+
### 1. Check if Consent Already Given
|
|
154
|
+
|
|
155
|
+
```javascript
|
|
156
|
+
// lib/consent-manager.js
|
|
157
|
+
|
|
158
|
+
class ConsentManager {
|
|
159
|
+
async hasConsent(wallet, ipId, action) {
|
|
160
|
+
const consent = await db.collection('bioip_access_consents').findOne({
|
|
161
|
+
wallet_address: wallet.toLowerCase(),
|
|
162
|
+
ip_id: ipId.toLowerCase(),
|
|
163
|
+
action: action, // 'download' or 'mount'
|
|
164
|
+
revoked: false
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
return consent !== null;
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
### 2. Display Consent Notice
|
|
173
|
+
|
|
174
|
+
```javascript
|
|
175
|
+
// lib/consent-prompt.js
|
|
176
|
+
|
|
177
|
+
const chalk = require('chalk');
|
|
178
|
+
const inquirer = require('inquirer');
|
|
179
|
+
|
|
180
|
+
class ConsentPrompt {
|
|
181
|
+
async showConsentNotice(fileInfo) {
|
|
182
|
+
console.log('\n');
|
|
183
|
+
console.log(chalk.yellow('β'.repeat(70)));
|
|
184
|
+
console.log(chalk.bold.yellow(' π GENOMIC DATA ACCESS CONSENT'));
|
|
185
|
+
console.log(chalk.yellow('β'.repeat(70)));
|
|
186
|
+
console.log('');
|
|
187
|
+
|
|
188
|
+
console.log(chalk.bold('FILE INFORMATION:'));
|
|
189
|
+
console.log(` Filename: ${chalk.cyan(fileInfo.filename)}`);
|
|
190
|
+
console.log(` Owner: ${chalk.cyan(fileInfo.owner)}`);
|
|
191
|
+
console.log(` IP Asset: ${chalk.gray(fileInfo.ip_id)}`);
|
|
192
|
+
console.log(` License Type: ${chalk.green(fileInfo.license_type)}`);
|
|
193
|
+
console.log('');
|
|
194
|
+
|
|
195
|
+
console.log(chalk.bold('YOU ARE ABOUT TO ACCESS:'));
|
|
196
|
+
console.log(' β’ Genomic variants (VCF format)');
|
|
197
|
+
console.log(' β’ Potentially identifying genetic information');
|
|
198
|
+
console.log(' β’ Protected under GDPR Article 9 (Special Categories)');
|
|
199
|
+
console.log('');
|
|
200
|
+
|
|
201
|
+
console.log(chalk.bold('PURPOSE OF ACCESS:'));
|
|
202
|
+
console.log(' Research and clinical analysis');
|
|
203
|
+
console.log('');
|
|
204
|
+
|
|
205
|
+
console.log(chalk.bold.green('YOUR RIGHTS:'));
|
|
206
|
+
console.log(' β Revoke access anytime via: ' + chalk.cyan('biofs access revoke <ip_id>'));
|
|
207
|
+
console.log(' β All access is logged (audit trail)');
|
|
208
|
+
console.log(' β Data owner can revoke your license token');
|
|
209
|
+
console.log('');
|
|
210
|
+
|
|
211
|
+
console.log(chalk.bold('LICENSE TERMS:'));
|
|
212
|
+
if (fileInfo.license_type === 'non-commercial') {
|
|
213
|
+
console.log(' β’ Non-commercial use only');
|
|
214
|
+
console.log(' β’ Attribution required');
|
|
215
|
+
console.log(' β’ No redistribution without permission');
|
|
216
|
+
}
|
|
217
|
+
console.log('');
|
|
218
|
+
|
|
219
|
+
console.log(chalk.bold('GDPR COMPLIANCE:'));
|
|
220
|
+
console.log(' This access will be recorded with:');
|
|
221
|
+
console.log(` β’ Your wallet: ${fileInfo.wallet}`);
|
|
222
|
+
console.log(` β’ Timestamp: ${new Date().toISOString()}`);
|
|
223
|
+
console.log(` β’ IP address: ${await this.getPublicIP()}`);
|
|
224
|
+
console.log('');
|
|
225
|
+
|
|
226
|
+
console.log(chalk.yellow('β'.repeat(70)));
|
|
227
|
+
console.log('');
|
|
228
|
+
|
|
229
|
+
// Require explicit "I AGREE"
|
|
230
|
+
const answer = await inquirer.prompt([
|
|
231
|
+
{
|
|
232
|
+
type: 'input',
|
|
233
|
+
name: 'consent',
|
|
234
|
+
message: 'Type "I AGREE" to confirm consent and proceed:',
|
|
235
|
+
validate: (input) => {
|
|
236
|
+
if (input.trim().toUpperCase() === 'I AGREE') {
|
|
237
|
+
return true;
|
|
238
|
+
}
|
|
239
|
+
return 'You must type "I AGREE" exactly to proceed';
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
]);
|
|
243
|
+
|
|
244
|
+
return answer.consent.trim().toUpperCase() === 'I AGREE';
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
async getPublicIP() {
|
|
248
|
+
try {
|
|
249
|
+
const response = await axios.get('https://api.ipify.org?format=json');
|
|
250
|
+
return response.data.ip;
|
|
251
|
+
} catch {
|
|
252
|
+
return 'unknown';
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
### 3. Record Consent
|
|
259
|
+
|
|
260
|
+
```javascript
|
|
261
|
+
// lib/consent-manager.js (continued)
|
|
262
|
+
|
|
263
|
+
class ConsentManager {
|
|
264
|
+
async recordConsent(wallet, fileInfo, action, ipAddress) {
|
|
265
|
+
const consentRecord = {
|
|
266
|
+
wallet_address: wallet.toLowerCase(),
|
|
267
|
+
ip_id: fileInfo.ip_id.toLowerCase(),
|
|
268
|
+
filename: fileInfo.filename,
|
|
269
|
+
data_owner: fileInfo.owner.toLowerCase(),
|
|
270
|
+
license_token_id: fileInfo.license_token_id,
|
|
271
|
+
license_type: fileInfo.license_type,
|
|
272
|
+
|
|
273
|
+
action: action, // 'download' or 'mount'
|
|
274
|
+
purpose: 'research_and_clinical_analysis',
|
|
275
|
+
|
|
276
|
+
consent_text_version: 'v1.0',
|
|
277
|
+
consent_given_at: new Date(),
|
|
278
|
+
consent_ip_address: ipAddress,
|
|
279
|
+
consent_user_agent: 'BioFS CLI v1.0.0',
|
|
280
|
+
|
|
281
|
+
gdpr_rights_acknowledged: true,
|
|
282
|
+
license_terms_acknowledged: true,
|
|
283
|
+
|
|
284
|
+
access_count: 1,
|
|
285
|
+
last_accessed_at: new Date(),
|
|
286
|
+
|
|
287
|
+
revoked: false,
|
|
288
|
+
revoked_at: null,
|
|
289
|
+
revoked_reason: null
|
|
290
|
+
};
|
|
291
|
+
|
|
292
|
+
await db.collection('bioip_access_consents').insertOne(consentRecord);
|
|
293
|
+
|
|
294
|
+
// Also log to audit trail
|
|
295
|
+
await db.collection('audit_log').insertOne({
|
|
296
|
+
event_type: 'consent_granted',
|
|
297
|
+
wallet: wallet,
|
|
298
|
+
ip_id: fileInfo.ip_id,
|
|
299
|
+
action: action,
|
|
300
|
+
timestamp: new Date()
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
console.log(chalk.green('β
Consent recorded'));
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
async incrementAccessCount(wallet, ipId, action) {
|
|
307
|
+
await db.collection('bioip_access_consents').updateOne(
|
|
308
|
+
{
|
|
309
|
+
wallet_address: wallet.toLowerCase(),
|
|
310
|
+
ip_id: ipId.toLowerCase(),
|
|
311
|
+
action: action
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
$inc: { access_count: 1 },
|
|
315
|
+
$set: { last_accessed_at: new Date() }
|
|
316
|
+
}
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
---
|
|
323
|
+
|
|
324
|
+
## Implementation: Download with Consent
|
|
325
|
+
|
|
326
|
+
### Updated Download Command
|
|
327
|
+
|
|
328
|
+
```javascript
|
|
329
|
+
// commands/download.js
|
|
330
|
+
|
|
331
|
+
const ConsentManager = require('../lib/consent-manager');
|
|
332
|
+
const ConsentPrompt = require('../lib/consent-prompt');
|
|
333
|
+
const BioNFSClient = require('../lib/bionfs-client');
|
|
334
|
+
|
|
335
|
+
async function downloadCommand(biocid, destination, options) {
|
|
336
|
+
const spinner = ora('Preparing download...').start();
|
|
337
|
+
|
|
338
|
+
try {
|
|
339
|
+
// 1. Load authentication
|
|
340
|
+
const { wallet, signature } = loadAuth();
|
|
341
|
+
|
|
342
|
+
// 2. Resolve BioCID to get file metadata
|
|
343
|
+
spinner.text = 'Resolving BioCID...';
|
|
344
|
+
const fileInfo = await api.resolveFile(biocid, signature);
|
|
345
|
+
|
|
346
|
+
if (!fileInfo) {
|
|
347
|
+
throw new Error('File not found or you do not have access');
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
spinner.stop();
|
|
351
|
+
|
|
352
|
+
// 3. Check if consent already given
|
|
353
|
+
const consentManager = new ConsentManager();
|
|
354
|
+
const hasConsent = await consentManager.hasConsent(
|
|
355
|
+
wallet,
|
|
356
|
+
fileInfo.ip_id,
|
|
357
|
+
'download'
|
|
358
|
+
);
|
|
359
|
+
|
|
360
|
+
if (!hasConsent) {
|
|
361
|
+
// 4. Show GDPR consent notice
|
|
362
|
+
const consentPrompt = new ConsentPrompt();
|
|
363
|
+
fileInfo.wallet = wallet; // Add user's wallet to display
|
|
364
|
+
|
|
365
|
+
const agreed = await consentPrompt.showConsentNotice(fileInfo);
|
|
366
|
+
|
|
367
|
+
if (!agreed) {
|
|
368
|
+
console.log(chalk.red('β Consent declined. Download cancelled.'));
|
|
369
|
+
process.exit(1);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
// 5. Record consent
|
|
373
|
+
const ipAddress = await consentPrompt.getPublicIP();
|
|
374
|
+
await consentManager.recordConsent(wallet, fileInfo, 'download', ipAddress);
|
|
375
|
+
} else {
|
|
376
|
+
console.log(chalk.green('β Using existing consent'));
|
|
377
|
+
|
|
378
|
+
// Increment access count
|
|
379
|
+
await consentManager.incrementAccessCount(wallet, fileInfo.ip_id, 'download');
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
// 6. Proceed with BioNFS download
|
|
383
|
+
spinner.start('Authenticating with BioNFS...');
|
|
384
|
+
|
|
385
|
+
const bionfs = new BioNFSClient();
|
|
386
|
+
await bionfs.authenticate(wallet, signature);
|
|
387
|
+
|
|
388
|
+
spinner.text = `Downloading ${fileInfo.filename}...`;
|
|
389
|
+
await bionfs.streamFile(fileInfo.ip_id, destination);
|
|
390
|
+
|
|
391
|
+
spinner.succeed(`β
Downloaded: ${destination}`);
|
|
392
|
+
|
|
393
|
+
// 7. Show post-download info
|
|
394
|
+
console.log('');
|
|
395
|
+
console.log(chalk.bold('File Information:'));
|
|
396
|
+
console.log(` Size: ${filesize(fileInfo.size)}`);
|
|
397
|
+
console.log(` License: ${fileInfo.license_type}`);
|
|
398
|
+
console.log('');
|
|
399
|
+
console.log(chalk.yellow('π‘ To revoke access: ') + chalk.cyan(`biofs access revoke ${fileInfo.ip_id}`));
|
|
400
|
+
|
|
401
|
+
} catch (error) {
|
|
402
|
+
spinner.fail('Download failed');
|
|
403
|
+
console.error(error.message);
|
|
404
|
+
process.exit(1);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
---
|
|
410
|
+
|
|
411
|
+
## Implementation: Mount with Consent
|
|
412
|
+
|
|
413
|
+
### New Mount Command
|
|
414
|
+
|
|
415
|
+
```javascript
|
|
416
|
+
// commands/mount.js
|
|
417
|
+
|
|
418
|
+
const ConsentManager = require('../lib/consent-manager');
|
|
419
|
+
const ConsentPrompt = require('../lib/consent-prompt');
|
|
420
|
+
const BioNFSClient = require('../lib/bionfs-client');
|
|
421
|
+
|
|
422
|
+
async function mountCommand(mountPoint, options) {
|
|
423
|
+
const spinner = ora('Preparing mount...').start();
|
|
424
|
+
|
|
425
|
+
try {
|
|
426
|
+
// 1. Load authentication
|
|
427
|
+
const { wallet, signature } = loadAuth();
|
|
428
|
+
|
|
429
|
+
// 2. Get all granted files
|
|
430
|
+
spinner.text = 'Discovering granted files...';
|
|
431
|
+
const files = await api.getGrantedBioIPs(signature);
|
|
432
|
+
|
|
433
|
+
if (files.length === 0) {
|
|
434
|
+
spinner.warn('No granted files found');
|
|
435
|
+
console.log('π‘ Request access to files with: ' + chalk.cyan('biofs access request'));
|
|
436
|
+
process.exit(0);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
spinner.stop();
|
|
440
|
+
|
|
441
|
+
// 3. Check consent for each file
|
|
442
|
+
const consentManager = new ConsentManager();
|
|
443
|
+
const consentPrompt = new ConsentPrompt();
|
|
444
|
+
const filesNeedingConsent = [];
|
|
445
|
+
|
|
446
|
+
for (const file of files) {
|
|
447
|
+
const hasConsent = await consentManager.hasConsent(
|
|
448
|
+
wallet,
|
|
449
|
+
file.ip_id,
|
|
450
|
+
'mount'
|
|
451
|
+
);
|
|
452
|
+
|
|
453
|
+
if (!hasConsent) {
|
|
454
|
+
filesNeedingConsent.push(file);
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
|
|
458
|
+
// 4. Show consent for files that need it
|
|
459
|
+
if (filesNeedingConsent.length > 0) {
|
|
460
|
+
console.log('');
|
|
461
|
+
console.log(chalk.yellow(`β οΈ ${filesNeedingConsent.length} file(s) require consent before mounting`));
|
|
462
|
+
console.log('');
|
|
463
|
+
|
|
464
|
+
for (let i = 0; i < filesNeedingConsent.length; i++) {
|
|
465
|
+
const file = filesNeedingConsent[i];
|
|
466
|
+
|
|
467
|
+
console.log(chalk.bold(`\nπ File ${i+1} of ${filesNeedingConsent.length}:`));
|
|
468
|
+
file.wallet = wallet;
|
|
469
|
+
|
|
470
|
+
const agreed = await consentPrompt.showConsentNotice(file);
|
|
471
|
+
|
|
472
|
+
if (!agreed) {
|
|
473
|
+
console.log(chalk.red(`β Consent declined for ${file.filename}. Skipping.`));
|
|
474
|
+
continue;
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
// Record consent
|
|
478
|
+
const ipAddress = await consentPrompt.getPublicIP();
|
|
479
|
+
await consentManager.recordConsent(wallet, file, 'mount', ipAddress);
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
// 5. Mount all consented files
|
|
484
|
+
spinner.start('Mounting files...');
|
|
485
|
+
|
|
486
|
+
const bionfs = new BioNFSClient();
|
|
487
|
+
await bionfs.authenticate(wallet, signature);
|
|
488
|
+
|
|
489
|
+
fs.mkdirSync(mountPoint, { recursive: true });
|
|
490
|
+
|
|
491
|
+
let mountedCount = 0;
|
|
492
|
+
for (const file of files) {
|
|
493
|
+
const hasConsent = await consentManager.hasConsent(
|
|
494
|
+
wallet,
|
|
495
|
+
file.ip_id,
|
|
496
|
+
'mount'
|
|
497
|
+
);
|
|
498
|
+
|
|
499
|
+
if (!hasConsent) continue; // Skip files without consent
|
|
500
|
+
|
|
501
|
+
const localPath = path.join(mountPoint, file.filename);
|
|
502
|
+
spinner.text = `Mounting ${file.filename}...`;
|
|
503
|
+
|
|
504
|
+
await bionfs.streamFile(file.ip_id, localPath);
|
|
505
|
+
mountedCount++;
|
|
506
|
+
|
|
507
|
+
// Increment access count
|
|
508
|
+
await consentManager.incrementAccessCount(wallet, file.ip_id, 'mount');
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
spinner.succeed(`β
Mounted ${mountedCount} file(s) to ${mountPoint}`);
|
|
512
|
+
|
|
513
|
+
// 6. Show usage info
|
|
514
|
+
console.log('');
|
|
515
|
+
console.log(chalk.bold('Your Files:'));
|
|
516
|
+
files.forEach(file => {
|
|
517
|
+
const localPath = path.join(mountPoint, file.filename);
|
|
518
|
+
if (fs.existsSync(localPath)) {
|
|
519
|
+
console.log(` ${chalk.green('β')} ${file.filename}`);
|
|
520
|
+
}
|
|
521
|
+
});
|
|
522
|
+
|
|
523
|
+
console.log('');
|
|
524
|
+
console.log(chalk.bold('Usage Examples:'));
|
|
525
|
+
console.log(` bcftools view ${mountPoint}/55052008714000.deepvariant.vcf | head -20`);
|
|
526
|
+
console.log(` IGV ${mountPoint}/55052008714000.deepvariant.vcf`);
|
|
527
|
+
console.log('');
|
|
528
|
+
console.log(chalk.yellow('π‘ To revoke access to all files: ') + chalk.cyan('biofs access revoke --all'));
|
|
529
|
+
|
|
530
|
+
} catch (error) {
|
|
531
|
+
spinner.fail('Mount failed');
|
|
532
|
+
console.error(error.message);
|
|
533
|
+
process.exit(1);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
```
|
|
537
|
+
|
|
538
|
+
---
|
|
539
|
+
|
|
540
|
+
## Implementation: Revoke Access
|
|
541
|
+
|
|
542
|
+
### New Access Revoke Command
|
|
543
|
+
|
|
544
|
+
```javascript
|
|
545
|
+
// commands/access/revoke.js
|
|
546
|
+
|
|
547
|
+
async function revokeCommand(ipId, options) {
|
|
548
|
+
const spinner = ora('Revoking access...').start();
|
|
549
|
+
|
|
550
|
+
try {
|
|
551
|
+
const { wallet, signature } = loadAuth();
|
|
552
|
+
|
|
553
|
+
if (options.all) {
|
|
554
|
+
// Revoke all consents
|
|
555
|
+
const consents = await db.collection('bioip_access_consents').find({
|
|
556
|
+
wallet_address: wallet.toLowerCase(),
|
|
557
|
+
revoked: false
|
|
558
|
+
}).toArray();
|
|
559
|
+
|
|
560
|
+
spinner.text = `Revoking ${consents.length} consent(s)...`;
|
|
561
|
+
|
|
562
|
+
await db.collection('bioip_access_consents').updateMany(
|
|
563
|
+
{
|
|
564
|
+
wallet_address: wallet.toLowerCase(),
|
|
565
|
+
revoked: false
|
|
566
|
+
},
|
|
567
|
+
{
|
|
568
|
+
$set: {
|
|
569
|
+
revoked: true,
|
|
570
|
+
revoked_at: new Date(),
|
|
571
|
+
revoked_reason: 'user_requested'
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
);
|
|
575
|
+
|
|
576
|
+
spinner.succeed(`β
Revoked access to ${consents.length} file(s)`);
|
|
577
|
+
|
|
578
|
+
} else {
|
|
579
|
+
// Revoke specific IP asset
|
|
580
|
+
const result = await db.collection('bioip_access_consents').updateMany(
|
|
581
|
+
{
|
|
582
|
+
wallet_address: wallet.toLowerCase(),
|
|
583
|
+
ip_id: ipId.toLowerCase(),
|
|
584
|
+
revoked: false
|
|
585
|
+
},
|
|
586
|
+
{
|
|
587
|
+
$set: {
|
|
588
|
+
revoked: true,
|
|
589
|
+
revoked_at: new Date(),
|
|
590
|
+
revoked_reason: 'user_requested'
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
);
|
|
594
|
+
|
|
595
|
+
spinner.succeed(`β
Revoked access to IP asset ${ipId}`);
|
|
596
|
+
console.log(` ${result.modifiedCount} consent record(s) updated`);
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
// Log to audit trail
|
|
600
|
+
await db.collection('audit_log').insertOne({
|
|
601
|
+
event_type: 'consent_revoked',
|
|
602
|
+
wallet: wallet,
|
|
603
|
+
ip_id: ipId || 'all',
|
|
604
|
+
timestamp: new Date()
|
|
605
|
+
});
|
|
606
|
+
|
|
607
|
+
} catch (error) {
|
|
608
|
+
spinner.fail('Revoke failed');
|
|
609
|
+
console.error(error.message);
|
|
610
|
+
process.exit(1);
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
```
|
|
614
|
+
|
|
615
|
+
---
|
|
616
|
+
|
|
617
|
+
## API Endpoints: BioNFS with Consent
|
|
618
|
+
|
|
619
|
+
### 1. Add Consent Verification to BioNFS
|
|
620
|
+
|
|
621
|
+
```python
|
|
622
|
+
# /production_api/plugins/bioip/api_bioip.py
|
|
623
|
+
|
|
624
|
+
@app.route('/bionfs/v1/verify_consent', methods=['POST'])
|
|
625
|
+
def verify_consent():
|
|
626
|
+
"""
|
|
627
|
+
Verify user has given GDPR consent for this file
|
|
628
|
+
Called by biofs CLI before download/mount
|
|
629
|
+
"""
|
|
630
|
+
user_signature = request.json.get('user_signature')
|
|
631
|
+
ip_id = request.json.get('ip_id')
|
|
632
|
+
action = request.json.get('action') # 'download' or 'mount'
|
|
633
|
+
|
|
634
|
+
wallet = recover_wallet(user_signature)
|
|
635
|
+
|
|
636
|
+
# Check MongoDB for consent record
|
|
637
|
+
consent = db.bioip_access_consents.find_one({
|
|
638
|
+
'wallet_address': wallet.lower(),
|
|
639
|
+
'ip_id': ip_id.lower(),
|
|
640
|
+
'action': action,
|
|
641
|
+
'revoked': False
|
|
642
|
+
})
|
|
643
|
+
|
|
644
|
+
if consent:
|
|
645
|
+
return jsonify({
|
|
646
|
+
'has_consent': True,
|
|
647
|
+
'consent_given_at': consent['consent_given_at'].isoformat(),
|
|
648
|
+
'access_count': consent['access_count']
|
|
649
|
+
})
|
|
650
|
+
else:
|
|
651
|
+
return jsonify({
|
|
652
|
+
'has_consent': False
|
|
653
|
+
})
|
|
654
|
+
|
|
655
|
+
|
|
656
|
+
@app.route('/bionfs/v1/record_consent', methods=['POST'])
|
|
657
|
+
def record_consent():
|
|
658
|
+
"""
|
|
659
|
+
Record GDPR consent after user agrees
|
|
660
|
+
Called by biofs CLI after showing consent notice
|
|
661
|
+
"""
|
|
662
|
+
user_signature = request.json.get('user_signature')
|
|
663
|
+
ip_id = request.json.get('ip_id')
|
|
664
|
+
action = request.json.get('action')
|
|
665
|
+
ip_address = request.json.get('ip_address')
|
|
666
|
+
|
|
667
|
+
wallet = recover_wallet(user_signature)
|
|
668
|
+
|
|
669
|
+
# Get file info
|
|
670
|
+
bioip = bioip_dao.get_bioip_by_ip_id(ip_id)
|
|
671
|
+
|
|
672
|
+
# Create consent record
|
|
673
|
+
consent_record = {
|
|
674
|
+
'wallet_address': wallet.lower(),
|
|
675
|
+
'ip_id': ip_id.lower(),
|
|
676
|
+
'filename': bioip['filename'],
|
|
677
|
+
'data_owner': bioip['owner'].lower(),
|
|
678
|
+
'license_token_id': bioip['license_token_id'],
|
|
679
|
+
'license_type': bioip['license_type'],
|
|
680
|
+
|
|
681
|
+
'action': action,
|
|
682
|
+
'purpose': 'research_and_clinical_analysis',
|
|
683
|
+
|
|
684
|
+
'consent_text_version': 'v1.0',
|
|
685
|
+
'consent_given_at': datetime.utcnow(),
|
|
686
|
+
'consent_ip_address': ip_address,
|
|
687
|
+
'consent_user_agent': request.headers.get('User-Agent'),
|
|
688
|
+
|
|
689
|
+
'gdpr_rights_acknowledged': True,
|
|
690
|
+
'license_terms_acknowledged': True,
|
|
691
|
+
|
|
692
|
+
'access_count': 1,
|
|
693
|
+
'last_accessed_at': datetime.utcnow(),
|
|
694
|
+
|
|
695
|
+
'revoked': False
|
|
696
|
+
}
|
|
697
|
+
|
|
698
|
+
db.bioip_access_consents.insert_one(consent_record)
|
|
699
|
+
|
|
700
|
+
# Log to audit trail
|
|
701
|
+
db.audit_log.insert_one({
|
|
702
|
+
'event_type': 'consent_granted',
|
|
703
|
+
'wallet': wallet,
|
|
704
|
+
'ip_id': ip_id,
|
|
705
|
+
'action': action,
|
|
706
|
+
'timestamp': datetime.utcnow()
|
|
707
|
+
})
|
|
708
|
+
|
|
709
|
+
return jsonify({'status': 'Success', 'message': 'Consent recorded'})
|
|
710
|
+
```
|
|
711
|
+
|
|
712
|
+
---
|
|
713
|
+
|
|
714
|
+
## Deployment Steps
|
|
715
|
+
|
|
716
|
+
1. **Add consent-manager.js to biofs CLI**
|
|
717
|
+
2. **Add consent-prompt.js to biofs CLI**
|
|
718
|
+
3. **Add BioNFS client library**
|
|
719
|
+
4. **Update download command with consent flow**
|
|
720
|
+
5. **Add mount command with consent flow**
|
|
721
|
+
6. **Add revoke command**
|
|
722
|
+
7. **Deploy BioNFS endpoints to main API**
|
|
723
|
+
8. **Create MongoDB bioip_access_consents collection**
|
|
724
|
+
|
|
725
|
+
---
|
|
726
|
+
|
|
727
|
+
## Testing with Dr. Claudia
|
|
728
|
+
|
|
729
|
+
### Test 1: First Download (Shows Consent)
|
|
730
|
+
|
|
731
|
+
```bash
|
|
732
|
+
biofs download "55052008714000.deepvariant.vcf"
|
|
733
|
+
|
|
734
|
+
# Should show:
|
|
735
|
+
# βββββββββββββββββββββββββββββββββββββββββββ
|
|
736
|
+
# π GENOMIC DATA ACCESS CONSENT
|
|
737
|
+
# βββββββββββββββββββββββββββββββββββββββββββ
|
|
738
|
+
#
|
|
739
|
+
# FILE INFORMATION:
|
|
740
|
+
# Filename: 55052008714000.deepvariant.vcf
|
|
741
|
+
# Owner: 0x5f5a60EaEf242c0D51A21c703f520347b96Ed19a
|
|
742
|
+
# ...
|
|
743
|
+
#
|
|
744
|
+
# > Type "I AGREE" to proceed: I AGREE
|
|
745
|
+
#
|
|
746
|
+
# β
Consent recorded
|
|
747
|
+
# β³ Downloading...
|
|
748
|
+
# β
Downloaded: ./55052008714000.deepvariant.vcf
|
|
749
|
+
```
|
|
750
|
+
|
|
751
|
+
### Test 2: Second Download (Uses Existing Consent)
|
|
752
|
+
|
|
753
|
+
```bash
|
|
754
|
+
biofs download "55052008714000.deepvariant.vcf" ~/second-copy.vcf
|
|
755
|
+
|
|
756
|
+
# Should show:
|
|
757
|
+
# β Using existing consent
|
|
758
|
+
# β³ Downloading...
|
|
759
|
+
# β
Downloaded: ~/second-copy.vcf
|
|
760
|
+
```
|
|
761
|
+
|
|
762
|
+
### Test 3: Mount (Shows Consent for Each File)
|
|
763
|
+
|
|
764
|
+
```bash
|
|
765
|
+
biofs mount ~/genomic-data
|
|
766
|
+
|
|
767
|
+
# Should show consent for each file, then:
|
|
768
|
+
# β
Mounted 1 file(s) to ~/genomic-data
|
|
769
|
+
#
|
|
770
|
+
# Your Files:
|
|
771
|
+
# β 55052008714000.deepvariant.vcf
|
|
772
|
+
```
|
|
773
|
+
|
|
774
|
+
### Test 4: Revoke Access
|
|
775
|
+
|
|
776
|
+
```bash
|
|
777
|
+
biofs access revoke 0xCCe14315eE3D6a41596EeB4a2839eE50A8ec59f7
|
|
778
|
+
|
|
779
|
+
# Should show:
|
|
780
|
+
# β
Revoked access to IP asset 0xCCe1...59f7
|
|
781
|
+
# 1 consent record(s) updated
|
|
782
|
+
```
|
|
783
|
+
|
|
784
|
+
---
|
|
785
|
+
|
|
786
|
+
## Summary: GDPR Compliance Features
|
|
787
|
+
|
|
788
|
+
β
**Informed Consent** - Clear explanation of what's being accessed
|
|
789
|
+
β
**Explicit Agreement** - Requires typing "I AGREE"
|
|
790
|
+
β
**Granular** - Per-file, per-action consent
|
|
791
|
+
β
**Revocable** - `biofs access revoke` command
|
|
792
|
+
β
**Auditable** - All actions logged with timestamp + IP
|
|
793
|
+
β
**Purpose Limitation** - Stated purpose of access
|
|
794
|
+
β
**Data Minimization** - Only access files user explicitly needs
|
|
795
|
+
β
**Right to Information** - Shows owner, license, rights
|
|
796
|
+
β
**Transparent** - Access count tracked and visible
|
|
797
|
+
|
|
798
|
+
This implementation satisfies GDPR Articles 6, 7, 9, and 13! π
|