@genobank/biofs 2.4.1 → 2.5.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.
Files changed (153) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/LICENSE +37 -0
  3. package/README.md +2 -1
  4. package/bin/biofs.js +2 -1
  5. package/contracts/ClaraJobNFT.sol +101 -0
  6. package/dist/commands/agent/health.js +1 -1
  7. package/dist/commands/agent/health.js.map +1 -1
  8. package/dist/commands/agent/list.d.ts +14 -0
  9. package/dist/commands/agent/list.d.ts.map +1 -0
  10. package/dist/commands/agent/list.js +101 -0
  11. package/dist/commands/agent/list.js.map +1 -0
  12. package/dist/commands/agent/register.d.ts +18 -0
  13. package/dist/commands/agent/register.d.ts.map +1 -0
  14. package/dist/commands/agent/register.js +120 -0
  15. package/dist/commands/agent/register.js.map +1 -0
  16. package/dist/commands/agent/status.d.ts +14 -0
  17. package/dist/commands/agent/status.d.ts.map +1 -0
  18. package/dist/commands/agent/status.js +151 -0
  19. package/dist/commands/agent/status.js.map +1 -0
  20. package/dist/commands/annotate/status.d.ts +11 -0
  21. package/dist/commands/annotate/status.d.ts.map +1 -0
  22. package/dist/commands/annotate/status.js +123 -0
  23. package/dist/commands/annotate/status.js.map +1 -0
  24. package/dist/commands/annotate/submit.d.ts +23 -0
  25. package/dist/commands/annotate/submit.d.ts.map +1 -0
  26. package/dist/commands/annotate/submit.js +296 -0
  27. package/dist/commands/annotate/submit.js.map +1 -0
  28. package/dist/commands/family-status.d.ts +12 -0
  29. package/dist/commands/family-status.d.ts.map +1 -0
  30. package/dist/commands/family-status.js +220 -0
  31. package/dist/commands/family-status.js.map +1 -0
  32. package/dist/commands/job/status.d.ts +1 -0
  33. package/dist/commands/job/status.d.ts.map +1 -1
  34. package/dist/commands/job/status.js.map +1 -1
  35. package/dist/commands/link-clara.d.ts +20 -0
  36. package/dist/commands/link-clara.d.ts.map +1 -0
  37. package/dist/commands/link-clara.js +234 -0
  38. package/dist/commands/link-clara.js.map +1 -0
  39. package/dist/commands/mount-remote.d.ts +1 -1
  40. package/dist/commands/mount-remote.js +1 -1
  41. package/dist/commands/payment/balance.d.ts +12 -0
  42. package/dist/commands/payment/balance.d.ts.map +1 -0
  43. package/dist/commands/payment/balance.js +101 -0
  44. package/dist/commands/payment/balance.js.map +1 -0
  45. package/dist/commands/payment/faucet.d.ts +11 -0
  46. package/dist/commands/payment/faucet.d.ts.map +1 -0
  47. package/dist/commands/payment/faucet.js +92 -0
  48. package/dist/commands/payment/faucet.js.map +1 -0
  49. package/dist/commands/payment/history.d.ts +27 -0
  50. package/dist/commands/payment/history.d.ts.map +1 -0
  51. package/dist/commands/payment/history.js +162 -0
  52. package/dist/commands/payment/history.js.map +1 -0
  53. package/dist/commands/payment/pricing.d.ts +12 -0
  54. package/dist/commands/payment/pricing.d.ts.map +1 -0
  55. package/dist/commands/payment/pricing.js +65 -0
  56. package/dist/commands/payment/pricing.js.map +1 -0
  57. package/dist/commands/payment/setup.d.ts +25 -0
  58. package/dist/commands/payment/setup.d.ts.map +1 -0
  59. package/dist/commands/payment/setup.js +155 -0
  60. package/dist/commands/payment/setup.js.map +1 -0
  61. package/dist/commands/tokenize-biosample.d.ts +19 -0
  62. package/dist/commands/tokenize-biosample.d.ts.map +1 -0
  63. package/dist/commands/tokenize-biosample.js +253 -0
  64. package/dist/commands/tokenize-biosample.js.map +1 -0
  65. package/dist/index.js +281 -13
  66. package/dist/index.js.map +1 -1
  67. package/dist/lib/api/bionft-client.d.ts +35 -7
  68. package/dist/lib/api/bionft-client.d.ts.map +1 -1
  69. package/dist/lib/api/bionft-client.js +106 -16
  70. package/dist/lib/api/bionft-client.js.map +1 -1
  71. package/dist/lib/kite/agent.d.ts +85 -0
  72. package/dist/lib/kite/agent.d.ts.map +1 -0
  73. package/dist/lib/kite/agent.js +332 -0
  74. package/dist/lib/kite/agent.js.map +1 -0
  75. package/dist/lib/kite/index.d.ts +9 -0
  76. package/dist/lib/kite/index.d.ts.map +1 -0
  77. package/dist/lib/kite/index.js +25 -0
  78. package/dist/lib/kite/index.js.map +1 -0
  79. package/dist/lib/kite/passport.d.ts +69 -0
  80. package/dist/lib/kite/passport.d.ts.map +1 -0
  81. package/dist/lib/kite/passport.js +312 -0
  82. package/dist/lib/kite/passport.js.map +1 -0
  83. package/dist/lib/x402/client.d.ts +78 -0
  84. package/dist/lib/x402/client.d.ts.map +1 -0
  85. package/dist/lib/x402/client.js +298 -0
  86. package/dist/lib/x402/client.js.map +1 -0
  87. package/dist/lib/x402/index.d.ts +9 -0
  88. package/dist/lib/x402/index.d.ts.map +1 -0
  89. package/dist/lib/x402/index.js +37 -0
  90. package/dist/lib/x402/index.js.map +1 -0
  91. package/dist/lib/x402/middleware.d.ts +37 -0
  92. package/dist/lib/x402/middleware.d.ts.map +1 -0
  93. package/dist/lib/x402/middleware.js +220 -0
  94. package/dist/lib/x402/middleware.js.map +1 -0
  95. package/dist/types/kite.d.ts +157 -0
  96. package/dist/types/kite.d.ts.map +1 -0
  97. package/dist/types/kite.js +107 -0
  98. package/dist/types/kite.js.map +1 -0
  99. package/dist/types/x402.d.ts +78 -0
  100. package/dist/types/x402.d.ts.map +1 -0
  101. package/dist/types/x402.js +79 -0
  102. package/dist/types/x402.js.map +1 -0
  103. package/docs/AI_AGENT_MCP_MANUAL.md +1029 -0
  104. package/docs/USER_MANUAL.md +603 -0
  105. package/docs/technical-details.html +555 -0
  106. package/lib/bionfs-client.js +2 -0
  107. package/lib/consent-manager.js +2 -0
  108. package/lib/consent-prompt.js +2 -0
  109. package/package.json +9 -3
  110. package/presentation/biofs-x402-kite-presentation.html +813 -0
  111. package/scripts/build_annotator_dictionary.py +1 -0
  112. package/scripts/deploy-clara-nft.js +37 -0
  113. package/test-complete-flow.sh +1 -1
  114. package/test.vcf +1 -0
  115. package/test_23andme.txt +1 -0
  116. package/ADMIN_REGISTER_LAB.md +0 -252
  117. package/ANNOTATOR_RECOMMENDATIONS_API.md +0 -490
  118. package/BIOFS_QUICK_START.md +0 -200
  119. package/BIOFS_TOKENIZE_COMPLETE.md +0 -541
  120. package/BIOFS_V1.2.7_PUBLISHED.md +0 -317
  121. package/BIOFS_V1.2.9_FIXES.md +0 -306
  122. package/BIOFS_V1.3.0_DIRECT_GRANT.md +0 -381
  123. package/BIOFS_V1.3.1_GRANTED_FILES.md +0 -328
  124. package/BIONFS_DEPLOYMENT_GUIDE.md +0 -408
  125. package/BIONFS_MOUNT_INTEGRATION_PLAN.md +0 -415
  126. package/BIONFS_PROTOCOL_SPECIFICATION.md +0 -688
  127. package/BIONFS_SEQUENTIAS_INTEGRATION.md +0 -457
  128. package/BIONFT_GATED_REMOTE_MOUNTING.md +0 -1260
  129. package/BIONFT_NFS_PROTOCOL_ARCHITECTURE.md +0 -583
  130. package/BIOOS_CLI_IMPLEMENTATION_COMPLETE.md +0 -422
  131. package/BIOOS_JOB_MANAGEMENT.md +0 -681
  132. package/BUGFIX_V2.1.3.md +0 -72
  133. package/CHANGELOG_V2.1.0.md +0 -386
  134. package/CHANGELOG_V2.2.0.md +0 -284
  135. package/ENHANCEMENT_DOCUMENTATION.md +0 -218
  136. package/GDPR_BIONFS_CONSENT_ARCHITECTURE.md +0 -798
  137. package/GDPR_BIONFS_IMPLEMENTATION_STATUS.md +0 -462
  138. package/INSTALL_V1.2.7_ON_MAC.md +0 -306
  139. package/LABNFT_BIOFS_INTEGRATION.md +0 -396
  140. package/OPENCRAVAT_ANNOTATORS_REFERENCE.md +0 -340
  141. package/OPENCRAVAT_ANNOTATOR_INTELLIGENCE_COMPLETE.md +0 -479
  142. package/QUICK_START_V2.1.0.md +0 -116
  143. package/RELEASE_SUMMARY_V1.2.7.md +0 -479
  144. package/RELEASE_SUMMARY_V1.3.0.md +0 -324
  145. package/SEQUENTIAS_PROTOCOL_ARCHITECTURE.md +0 -880
  146. package/SEQUENTIA_MIGRATION_GUIDE.md +0 -337
  147. package/SESSION_SUMMARY_DIRECT_GRANT.md +0 -321
  148. package/ULTRATHINK_BIONFS_COMPLETE.md +0 -458
  149. package/WEB3FUSE_LICENSE_TOKEN_ANALYSIS.md +0 -494
  150. package/WHERE_PERMISSIONS_LIVE.md +0 -165
  151. package/config.json +0 -21
  152. package/opencravat_annotators_dictionary.json +0 -2356
  153. package/package.json.working.v1.9.2.20251105_023952 +0 -48
@@ -1,798 +0,0 @@
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! 🔒