@genobank/biofs 2.0.6 → 2.1.0
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/CHANGELOG.md +387 -1
- package/CHANGELOG_V2.1.0.md +386 -0
- package/QUICK_START_V2.1.0.md +116 -0
- package/SEQUENTIA_MIGRATION_GUIDE.md +337 -0
- package/dist/commands/access-sequentia.d.ts +35 -0
- package/dist/commands/access-sequentia.d.ts.map +1 -0
- package/dist/commands/access-sequentia.js +256 -0
- package/dist/commands/access-sequentia.js.map +1 -0
- package/dist/commands/biofiles-sequentia.d.ts +21 -0
- package/dist/commands/biofiles-sequentia.d.ts.map +1 -0
- package/dist/commands/biofiles-sequentia.js +238 -0
- package/dist/commands/biofiles-sequentia.js.map +1 -0
- package/dist/commands/dissect-sequentia.d.ts +23 -0
- package/dist/commands/dissect-sequentia.d.ts.map +1 -0
- package/dist/commands/dissect-sequentia.js +227 -0
- package/dist/commands/dissect-sequentia.js.map +1 -0
- package/dist/commands/download-sequentia.d.ts +19 -0
- package/dist/commands/download-sequentia.d.ts.map +1 -0
- package/dist/commands/download-sequentia.js +159 -0
- package/dist/commands/download-sequentia.js.map +1 -0
- package/dist/commands/share-sequentia.d.ts +21 -0
- package/dist/commands/share-sequentia.d.ts.map +1 -0
- package/dist/commands/share-sequentia.js +161 -0
- package/dist/commands/share-sequentia.js.map +1 -0
- package/dist/commands/tokenize-sequentia.d.ts +21 -0
- package/dist/commands/tokenize-sequentia.d.ts.map +1 -0
- package/dist/commands/tokenize-sequentia.js +191 -0
- package/dist/commands/tokenize-sequentia.js.map +1 -0
- package/dist/commands/verify-sequentia.d.ts +18 -0
- package/dist/commands/verify-sequentia.d.ts.map +1 -0
- package/dist/commands/verify-sequentia.js +150 -0
- package/dist/commands/verify-sequentia.js.map +1 -0
- package/dist/index.js +15 -3
- package/dist/index.js.map +1 -1
- package/dist/lib/api/client.d.ts +25 -0
- package/dist/lib/api/client.d.ts.map +1 -1
- package/dist/lib/api/client.js +76 -0
- package/dist/lib/api/client.js.map +1 -1
- package/dist/lib/sequentia/BioCIDRegistry.d.ts +93 -0
- package/dist/lib/sequentia/BioCIDRegistry.d.ts.map +1 -0
- package/dist/lib/sequentia/BioCIDRegistry.js +229 -0
- package/dist/lib/sequentia/BioCIDRegistry.js.map +1 -0
- package/dist/lib/sequentia/BioPIL.d.ts +116 -0
- package/dist/lib/sequentia/BioPIL.d.ts.map +1 -0
- package/dist/lib/sequentia/BioPIL.js +349 -0
- package/dist/lib/sequentia/BioPIL.js.map +1 -0
- package/dist/lib/sequentia/BloomFilter.d.ts +70 -0
- package/dist/lib/sequentia/BloomFilter.d.ts.map +1 -0
- package/dist/lib/sequentia/BloomFilter.js +257 -0
- package/dist/lib/sequentia/BloomFilter.js.map +1 -0
- package/dist/lib/sequentia/ConsentManager.d.ts +109 -0
- package/dist/lib/sequentia/ConsentManager.d.ts.map +1 -0
- package/dist/lib/sequentia/ConsentManager.js +299 -0
- package/dist/lib/sequentia/ConsentManager.js.map +1 -0
- package/dist/lib/sequentia/OpenCravatJobs.d.ts +120 -0
- package/dist/lib/sequentia/OpenCravatJobs.d.ts.map +1 -0
- package/dist/lib/sequentia/OpenCravatJobs.js +328 -0
- package/dist/lib/sequentia/OpenCravatJobs.js.map +1 -0
- package/dist/lib/sequentia/PaymentRouter.d.ts +73 -0
- package/dist/lib/sequentia/PaymentRouter.d.ts.map +1 -0
- package/dist/lib/sequentia/PaymentRouter.js +207 -0
- package/dist/lib/sequentia/PaymentRouter.js.map +1 -0
- package/dist/lib/sequentia/index.d.ts +46 -0
- package/dist/lib/sequentia/index.d.ts.map +1 -0
- package/dist/lib/sequentia/index.js +69 -0
- package/dist/lib/sequentia/index.js.map +1 -0
- package/dist/lib/utils/logger.d.ts +1 -0
- package/dist/lib/utils/logger.d.ts.map +1 -1
- package/dist/lib/utils/logger.js +3 -0
- package/dist/lib/utils/logger.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Bloom Filter Fingerprinting for Genomic Files
|
|
4
|
+
*
|
|
5
|
+
* Creates DNA-specific fingerprints using Bloom Filters to:
|
|
6
|
+
* 1. Uniquely identify files based on SNP content
|
|
7
|
+
* 2. Detect duplicates across different uploads
|
|
8
|
+
* 3. Enable cross-format tracking (FASTQ → BAM → VCF → SQLite)
|
|
9
|
+
*
|
|
10
|
+
* Parameters (matching BioCIDRegistry.sol):
|
|
11
|
+
* - Capacity: 10,000 SNPs
|
|
12
|
+
* - Error rate: 0.001 (0.1%)
|
|
13
|
+
* - SNP format: {chrom}:{pos}:{GT}:{ref}:{alt}
|
|
14
|
+
*/
|
|
15
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
18
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
19
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
20
|
+
}
|
|
21
|
+
Object.defineProperty(o, k2, desc);
|
|
22
|
+
}) : (function(o, m, k, k2) {
|
|
23
|
+
if (k2 === undefined) k2 = k;
|
|
24
|
+
o[k2] = m[k];
|
|
25
|
+
}));
|
|
26
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
27
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
28
|
+
}) : function(o, v) {
|
|
29
|
+
o["default"] = v;
|
|
30
|
+
});
|
|
31
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
32
|
+
var ownKeys = function(o) {
|
|
33
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
34
|
+
var ar = [];
|
|
35
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
36
|
+
return ar;
|
|
37
|
+
};
|
|
38
|
+
return ownKeys(o);
|
|
39
|
+
};
|
|
40
|
+
return function (mod) {
|
|
41
|
+
if (mod && mod.__esModule) return mod;
|
|
42
|
+
var result = {};
|
|
43
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
44
|
+
__setModuleDefault(result, mod);
|
|
45
|
+
return result;
|
|
46
|
+
};
|
|
47
|
+
})();
|
|
48
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
49
|
+
exports.BloomFilterFingerprint = void 0;
|
|
50
|
+
exports.calculateFingerprint = calculateFingerprint;
|
|
51
|
+
exports.extractPhenotypeSubset = extractPhenotypeSubset;
|
|
52
|
+
const crypto_1 = require("crypto");
|
|
53
|
+
const fs = __importStar(require("fs/promises"));
|
|
54
|
+
const logger_1 = require("../utils/logger");
|
|
55
|
+
class BloomFilterFingerprint {
|
|
56
|
+
constructor() {
|
|
57
|
+
this.capacity = 10000;
|
|
58
|
+
this.errorRate = 0.001;
|
|
59
|
+
// Calculate optimal bit array size and number of hash functions
|
|
60
|
+
const bits = Math.ceil((this.capacity * Math.log(this.errorRate)) / Math.log(1 / Math.pow(2, Math.log(2))));
|
|
61
|
+
this.hashFunctions = Math.ceil((bits / this.capacity) * Math.log(2));
|
|
62
|
+
this.bitArray = new Uint8Array(Math.ceil(bits / 8));
|
|
63
|
+
logger_1.Logger.info(`Initialized Bloom Filter: ${bits} bits, ${this.hashFunctions} hash functions`);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Add SNP to Bloom Filter
|
|
67
|
+
*/
|
|
68
|
+
add(snp) {
|
|
69
|
+
const snpKey = `${snp.chromosome}:${snp.position}:${snp.genotype}:${snp.ref}:${snp.alt}`;
|
|
70
|
+
for (let i = 0; i < this.hashFunctions; i++) {
|
|
71
|
+
const hash = this.hash(snpKey, i);
|
|
72
|
+
const bitIndex = hash % (this.bitArray.length * 8);
|
|
73
|
+
const byteIndex = Math.floor(bitIndex / 8);
|
|
74
|
+
const bitOffset = bitIndex % 8;
|
|
75
|
+
this.bitArray[byteIndex] |= (1 << bitOffset);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Calculate fingerprint (SHA-256 of Bloom Filter bits)
|
|
80
|
+
*/
|
|
81
|
+
getFingerprint() {
|
|
82
|
+
const hash = (0, crypto_1.createHash)('sha256').update(this.bitArray).digest();
|
|
83
|
+
logger_1.Logger.info(`Fingerprint: 0x${Buffer.from(hash).toString('hex').substring(0, 16)}...`);
|
|
84
|
+
return new Uint8Array(hash);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Parse VCF file and calculate fingerprint
|
|
88
|
+
*/
|
|
89
|
+
static async fromVCF(vcfPath) {
|
|
90
|
+
logger_1.Logger.info(`Reading VCF: ${vcfPath}`);
|
|
91
|
+
const bloom = new BloomFilterFingerprint();
|
|
92
|
+
const content = await fs.readFile(vcfPath, 'utf-8');
|
|
93
|
+
const lines = content.split('\n');
|
|
94
|
+
let snpCount = 0;
|
|
95
|
+
for (const line of lines) {
|
|
96
|
+
// Skip headers and empty lines
|
|
97
|
+
if (line.startsWith('#') || line.trim() === '') {
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
const fields = line.split('\t');
|
|
101
|
+
if (fields.length < 5) {
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
const [chrom, pos, id, ref, alt, qual, filter, info, format, ...samples] = fields;
|
|
105
|
+
// Extract genotype from first sample
|
|
106
|
+
let genotype = 'GT';
|
|
107
|
+
if (samples.length > 0 && format) {
|
|
108
|
+
const formatFields = format.split(':');
|
|
109
|
+
const gtIndex = formatFields.indexOf('GT');
|
|
110
|
+
if (gtIndex !== -1) {
|
|
111
|
+
const sampleFields = samples[0].split(':');
|
|
112
|
+
genotype = sampleFields[gtIndex] || 'GT';
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
// Add to Bloom Filter
|
|
116
|
+
bloom.add({
|
|
117
|
+
rsid: id,
|
|
118
|
+
chromosome: chrom,
|
|
119
|
+
position: parseInt(pos),
|
|
120
|
+
genotype,
|
|
121
|
+
ref,
|
|
122
|
+
alt
|
|
123
|
+
});
|
|
124
|
+
snpCount++;
|
|
125
|
+
// Stop at capacity limit
|
|
126
|
+
if (snpCount >= 10000) {
|
|
127
|
+
logger_1.Logger.warn(`Reached capacity limit of 10,000 SNPs`);
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
logger_1.Logger.info(`Processed ${snpCount} SNPs`);
|
|
132
|
+
return bloom.getFingerprint();
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Parse 23andMe file and calculate fingerprint
|
|
136
|
+
*/
|
|
137
|
+
static async from23andMe(txtPath) {
|
|
138
|
+
logger_1.Logger.info(`Reading 23andMe: ${txtPath}`);
|
|
139
|
+
const bloom = new BloomFilterFingerprint();
|
|
140
|
+
const content = await fs.readFile(txtPath, 'utf-8');
|
|
141
|
+
const lines = content.split('\n');
|
|
142
|
+
let snpCount = 0;
|
|
143
|
+
for (const line of lines) {
|
|
144
|
+
// Skip comments and empty lines
|
|
145
|
+
if (line.startsWith('#') || line.trim() === '') {
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
const fields = line.split('\t');
|
|
149
|
+
if (fields.length < 4) {
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
const [rsid, chrom, pos, genotype] = fields;
|
|
153
|
+
// Skip if not a valid SNP
|
|
154
|
+
if (!rsid.startsWith('rs')) {
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
// Add to Bloom Filter
|
|
158
|
+
// Note: 23andMe doesn't provide ref/alt, so we use genotype directly
|
|
159
|
+
bloom.add({
|
|
160
|
+
rsid,
|
|
161
|
+
chromosome: chrom,
|
|
162
|
+
position: parseInt(pos),
|
|
163
|
+
genotype,
|
|
164
|
+
ref: genotype[0] || '',
|
|
165
|
+
alt: genotype[1] || ''
|
|
166
|
+
});
|
|
167
|
+
snpCount++;
|
|
168
|
+
if (snpCount >= 10000) {
|
|
169
|
+
logger_1.Logger.warn(`Reached capacity limit of 10,000 SNPs`);
|
|
170
|
+
break;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
logger_1.Logger.info(`Processed ${snpCount} SNPs`);
|
|
174
|
+
return bloom.getFingerprint();
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Parse Ancestry.com file and calculate fingerprint
|
|
178
|
+
*/
|
|
179
|
+
static async fromAncestry(txtPath) {
|
|
180
|
+
// Ancestry format is similar to 23andMe
|
|
181
|
+
return this.from23andMe(txtPath);
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Detect file format and calculate fingerprint
|
|
185
|
+
*/
|
|
186
|
+
static async fromFile(filePath) {
|
|
187
|
+
// Detect format from extension
|
|
188
|
+
const ext = filePath.toLowerCase().split('.').pop();
|
|
189
|
+
logger_1.Logger.info(`Detected format: ${ext}`);
|
|
190
|
+
switch (ext) {
|
|
191
|
+
case 'vcf':
|
|
192
|
+
case 'vcf.gz':
|
|
193
|
+
return this.fromVCF(filePath);
|
|
194
|
+
case 'txt':
|
|
195
|
+
// Try to detect 23andMe vs Ancestry format
|
|
196
|
+
const content = await fs.readFile(filePath, 'utf-8');
|
|
197
|
+
if (content.includes('# This data file generated by 23andMe')) {
|
|
198
|
+
return this.from23andMe(filePath);
|
|
199
|
+
}
|
|
200
|
+
else {
|
|
201
|
+
return this.fromAncestry(filePath);
|
|
202
|
+
}
|
|
203
|
+
default:
|
|
204
|
+
throw new Error(`Unsupported file format: ${ext}`);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Hash function for Bloom Filter
|
|
209
|
+
*/
|
|
210
|
+
hash(key, seed) {
|
|
211
|
+
const hash = (0, crypto_1.createHash)('sha256')
|
|
212
|
+
.update(key + seed.toString())
|
|
213
|
+
.digest();
|
|
214
|
+
// Convert first 4 bytes to number
|
|
215
|
+
return ((hash[0] << 24) |
|
|
216
|
+
(hash[1] << 16) |
|
|
217
|
+
(hash[2] << 8) |
|
|
218
|
+
hash[3]) >>> 0; // Unsigned 32-bit integer
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
exports.BloomFilterFingerprint = BloomFilterFingerprint;
|
|
222
|
+
/**
|
|
223
|
+
* Convenience function for quick fingerprint calculation
|
|
224
|
+
*/
|
|
225
|
+
async function calculateFingerprint(filePath) {
|
|
226
|
+
return BloomFilterFingerprint.fromFile(filePath);
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Extract phenotype-specific SNPs from VCF
|
|
230
|
+
*/
|
|
231
|
+
async function extractPhenotypeSubset(vcfPath, phenotype, relevantSNPs) {
|
|
232
|
+
logger_1.Logger.info(`Extracting SNPs for phenotype: ${phenotype}`);
|
|
233
|
+
const vcfContent = await fs.readFile(vcfPath, 'utf-8');
|
|
234
|
+
const lines = vcfContent.split('\n');
|
|
235
|
+
// Keep headers
|
|
236
|
+
const outputLines = lines.filter(line => line.startsWith('#'));
|
|
237
|
+
// Extract only relevant SNPs
|
|
238
|
+
let snpCount = 0;
|
|
239
|
+
const relevantPositions = new Set(relevantSNPs.map(snp => `${snp.chromosome}:${snp.position}`));
|
|
240
|
+
for (const line of lines) {
|
|
241
|
+
if (line.startsWith('#') || line.trim() === '') {
|
|
242
|
+
continue;
|
|
243
|
+
}
|
|
244
|
+
const [chrom, pos] = line.split('\t');
|
|
245
|
+
const key = `${chrom}:${pos}`;
|
|
246
|
+
if (relevantPositions.has(key)) {
|
|
247
|
+
outputLines.push(line);
|
|
248
|
+
snpCount++;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
logger_1.Logger.info(`Extracted ${snpCount} SNPs`);
|
|
252
|
+
return {
|
|
253
|
+
content: outputLines.join('\n'),
|
|
254
|
+
snpCount
|
|
255
|
+
};
|
|
256
|
+
}
|
|
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AC;IACjB,MAAM,iBAAiB,GAAG,IAAI,GAAG,CAC7B,YAAY,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,UAAU,IAAI,GAAG,CAAC,QAAQ,EAAE,CAAC,CAC/D,CAAC;IAEF,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QACvB,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;YAC7C,SAAS;QACb,CAAC;QAED,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QACtC,MAAM,GAAG,GAAG,GAAG,KAAK,IAAI,GAAG,EAAE,CAAC;QAE9B,IAAI,iBAAiB,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;YAC7B,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YACvB,QAAQ,EAAE,CAAC;QACf,CAAC;IACL,CAAC;IAED,eAAM,CAAC,IAAI,CAAC,aAAa,QAAQ,OAAO,CAAC,CAAC;IAE1C,OAAO;QACH,OAAO,EAAE,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC;QAC/B,QAAQ;KACX,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ConsentManager - GDPR Article 17 Right to Erasure
|
|
3
|
+
*
|
|
4
|
+
* Manages consent for genomic data sharing with full GDPR compliance:
|
|
5
|
+
* - Parental consent for newborn sequences (multi-party approval)
|
|
6
|
+
* - Age of majority transfer (automatic at 18)
|
|
7
|
+
* - Consent revocation (triggers S3 deletion)
|
|
8
|
+
* - Family inheritance rules
|
|
9
|
+
* - Time-limited consent
|
|
10
|
+
* - Access logging for GDPR Article 15 (right to access)
|
|
11
|
+
*
|
|
12
|
+
* This is WHY we use Sequentia Protocol instead of Story Protocol:
|
|
13
|
+
* Story Protocol IP Assets are IMMUTABLE - cannot be deleted
|
|
14
|
+
* Sequentia ConsentManager enables true GDPR compliance
|
|
15
|
+
*/
|
|
16
|
+
export declare enum ConsentStatus {
|
|
17
|
+
NotProvided = 0,
|
|
18
|
+
Active = 1,
|
|
19
|
+
Revoked = 2,// GDPR Article 17
|
|
20
|
+
Expired = 3,
|
|
21
|
+
Transferred = 4
|
|
22
|
+
}
|
|
23
|
+
export declare enum ConsentType {
|
|
24
|
+
Clinical = 0,
|
|
25
|
+
Research = 1,
|
|
26
|
+
Commercial = 2,
|
|
27
|
+
AITraining = 3,
|
|
28
|
+
FamilySharing = 4,
|
|
29
|
+
PublicDatabase = 5
|
|
30
|
+
}
|
|
31
|
+
export interface ConsentRecord {
|
|
32
|
+
biocid: string;
|
|
33
|
+
subject: string;
|
|
34
|
+
grantors: string[];
|
|
35
|
+
grantorApproved: Map<string, boolean>;
|
|
36
|
+
consentTypes: ConsentType[];
|
|
37
|
+
status: ConsentStatus;
|
|
38
|
+
grantedAt: number;
|
|
39
|
+
expiresAt: number;
|
|
40
|
+
ageOfMajority: number;
|
|
41
|
+
purpose: string;
|
|
42
|
+
requiresAllGrantors: boolean;
|
|
43
|
+
}
|
|
44
|
+
export interface AccessLog {
|
|
45
|
+
biocid: string;
|
|
46
|
+
accessor: string;
|
|
47
|
+
action: string;
|
|
48
|
+
timestamp: number;
|
|
49
|
+
ipAddress?: string;
|
|
50
|
+
}
|
|
51
|
+
export declare class ConsentManager {
|
|
52
|
+
private contract;
|
|
53
|
+
private signer;
|
|
54
|
+
constructor(privateKey: string);
|
|
55
|
+
/**
|
|
56
|
+
* Create consent (parental or self-consent)
|
|
57
|
+
*/
|
|
58
|
+
createConsent(biocid: string, subject: string, grantors: string[], consentTypes: ConsentType[], birthDate: number, // Unix timestamp of birth
|
|
59
|
+
expiresAt: number, // 0 = never expires
|
|
60
|
+
purpose: string, requiresAllGrantors?: boolean): Promise<string>;
|
|
61
|
+
/**
|
|
62
|
+
* Approve consent (for multi-party approval)
|
|
63
|
+
*/
|
|
64
|
+
approveConsent(biocid: string): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Revoke consent (GDPR Article 17 - Right to Erasure)
|
|
67
|
+
*
|
|
68
|
+
* This triggers off-chain S3 deletion via backend event listener
|
|
69
|
+
*/
|
|
70
|
+
revokeConsent(biocid: string, reason: string): Promise<void>;
|
|
71
|
+
/**
|
|
72
|
+
* Check consent status
|
|
73
|
+
*/
|
|
74
|
+
checkConsent(biocid: string): Promise<ConsentStatus>;
|
|
75
|
+
/**
|
|
76
|
+
* Verify consent is valid (Active and not expired)
|
|
77
|
+
*/
|
|
78
|
+
isConsentValid(biocid: string): Promise<boolean>;
|
|
79
|
+
/**
|
|
80
|
+
* Get full consent record
|
|
81
|
+
*/
|
|
82
|
+
getConsentRecord(biocid: string): Promise<ConsentRecord | null>;
|
|
83
|
+
/**
|
|
84
|
+
* Log access for GDPR Article 15 (Right to Access)
|
|
85
|
+
*/
|
|
86
|
+
logAccess(biocid: string, accessor: string, action: string, timestamp: Date): Promise<void>;
|
|
87
|
+
/**
|
|
88
|
+
* Get access logs for a BioCID
|
|
89
|
+
*/
|
|
90
|
+
getAccessLogs(biocid: string): Promise<AccessLog[]>;
|
|
91
|
+
/**
|
|
92
|
+
* Declare family inheritance (for deceased data subjects)
|
|
93
|
+
*/
|
|
94
|
+
declareFamilyInheritance(deceased: string, heirs: string[], heirShares: number[], // Basis points (10000 = 100%)
|
|
95
|
+
biocids: string[]): Promise<void>;
|
|
96
|
+
/**
|
|
97
|
+
* Transfer consent to subject at age of majority
|
|
98
|
+
*/
|
|
99
|
+
transferConsentToSubject(biocid: string): Promise<void>;
|
|
100
|
+
/**
|
|
101
|
+
* Helper: Calculate age of majority timestamp
|
|
102
|
+
*/
|
|
103
|
+
static calculateAgeOfMajority(birthDate: Date): number;
|
|
104
|
+
/**
|
|
105
|
+
* Helper: Format consent status for display
|
|
106
|
+
*/
|
|
107
|
+
static formatConsentStatus(status: ConsentStatus): string;
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=ConsentManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ConsentManager.d.ts","sourceRoot":"","sources":["../../../src/lib/sequentia/ConsentManager.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AASH,oBAAY,aAAa;IACrB,WAAW,IAAI;IACf,MAAM,IAAI;IACV,OAAO,IAAI,CAAS,kBAAkB;IACtC,OAAO,IAAI;IACX,WAAW,IAAI;CAClB;AAED,oBAAY,WAAW;IACnB,QAAQ,IAAI;IACZ,QAAQ,IAAI;IACZ,UAAU,IAAI;IACd,UAAU,IAAI;IACd,aAAa,IAAI;IACjB,cAAc,IAAI;CACrB;AAED,MAAM,WAAW,aAAa;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,eAAe,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACtC,YAAY,EAAE,WAAW,EAAE,CAAC;IAC5B,MAAM,EAAE,aAAa,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,MAAM,CAAC;IAChB,mBAAmB,EAAE,OAAO,CAAC;CAChC;AAED,MAAM,WAAW,SAAS;IACtB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,qBAAa,cAAc;IACvB,OAAO,CAAC,QAAQ,CAAkB;IAClC,OAAO,CAAC,MAAM,CAAgB;gBAGlB,UAAU,EAAE,MAAM;IA6B9B;;OAEG;IACG,aAAa,CACf,MAAM,EAAE,MAAM,EACd,OAA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AAE,IAAI,GAAG,MAAM;IAMtD;;OAEG;IACH,MAAM,CAAC,mBAAmB,CAAC,MAAM,EAAE,aAAa,GAAG,MAAM;CAgB5D"}
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* ConsentManager - GDPR Article 17 Right to Erasure
|
|
4
|
+
*
|
|
5
|
+
* Manages consent for genomic data sharing with full GDPR compliance:
|
|
6
|
+
* - Parental consent for newborn sequences (multi-party approval)
|
|
7
|
+
* - Age of majority transfer (automatic at 18)
|
|
8
|
+
* - Consent revocation (triggers S3 deletion)
|
|
9
|
+
* - Family inheritance rules
|
|
10
|
+
* - Time-limited consent
|
|
11
|
+
* - Access logging for GDPR Article 15 (right to access)
|
|
12
|
+
*
|
|
13
|
+
* This is WHY we use Sequentia Protocol instead of Story Protocol:
|
|
14
|
+
* Story Protocol IP Assets are IMMUTABLE - cannot be deleted
|
|
15
|
+
* Sequentia ConsentManager enables true GDPR compliance
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
exports.ConsentManager = exports.ConsentType = exports.ConsentStatus = void 0;
|
|
19
|
+
const ethers_1 = require("ethers");
|
|
20
|
+
const logger_1 = require("../utils/logger");
|
|
21
|
+
// Sequentia Network Configuration
|
|
22
|
+
const SEQUENTIA_RPC_URL = 'http://52.90.163.112:8545';
|
|
23
|
+
const CONSENT_MANAGER_ADDRESS = '0x0000000000000000000000000000000000000000'; // TODO: Deploy (optional for basic operations)
|
|
24
|
+
var ConsentStatus;
|
|
25
|
+
(function (ConsentStatus) {
|
|
26
|
+
ConsentStatus[ConsentStatus["NotProvided"] = 0] = "NotProvided";
|
|
27
|
+
ConsentStatus[ConsentStatus["Active"] = 1] = "Active";
|
|
28
|
+
ConsentStatus[ConsentStatus["Revoked"] = 2] = "Revoked";
|
|
29
|
+
ConsentStatus[ConsentStatus["Expired"] = 3] = "Expired";
|
|
30
|
+
ConsentStatus[ConsentStatus["Transferred"] = 4] = "Transferred"; // Age of majority
|
|
31
|
+
})(ConsentStatus || (exports.ConsentStatus = ConsentStatus = {}));
|
|
32
|
+
var ConsentType;
|
|
33
|
+
(function (ConsentType) {
|
|
34
|
+
ConsentType[ConsentType["Clinical"] = 0] = "Clinical";
|
|
35
|
+
ConsentType[ConsentType["Research"] = 1] = "Research";
|
|
36
|
+
ConsentType[ConsentType["Commercial"] = 2] = "Commercial";
|
|
37
|
+
ConsentType[ConsentType["AITraining"] = 3] = "AITraining";
|
|
38
|
+
ConsentType[ConsentType["FamilySharing"] = 4] = "FamilySharing";
|
|
39
|
+
ConsentType[ConsentType["PublicDatabase"] = 5] = "PublicDatabase";
|
|
40
|
+
})(ConsentType || (exports.ConsentType = ConsentType = {}));
|
|
41
|
+
class ConsentManager {
|
|
42
|
+
constructor(privateKey) {
|
|
43
|
+
try {
|
|
44
|
+
// ConsentManager is optional for basic operations
|
|
45
|
+
if (CONSENT_MANAGER_ADDRESS === '0x0000000000000000000000000000000000000000') {
|
|
46
|
+
logger_1.Logger.warn('ConsentManager not deployed - GDPR features disabled');
|
|
47
|
+
this.contract = null;
|
|
48
|
+
this.signer = null;
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const provider = new ethers_1.ethers.JsonRpcProvider(SEQUENTIA_RPC_URL);
|
|
52
|
+
this.signer = new ethers_1.ethers.Wallet(privateKey, provider);
|
|
53
|
+
const abi = require('../../abi/sequentia/ConsentManager.json');
|
|
54
|
+
this.contract = new ethers_1.ethers.Contract(CONSENT_MANAGER_ADDRESS, abi, this.signer);
|
|
55
|
+
logger_1.Logger.info('ConsentManager initialized');
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
logger_1.Logger.error(`Failed to initialize ConsentManager: ${error.message}`);
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Create consent (parental or self-consent)
|
|
64
|
+
*/
|
|
65
|
+
async createConsent(biocid, subject, grantors, consentTypes, birthDate, // Unix timestamp of birth
|
|
66
|
+
expiresAt, // 0 = never expires
|
|
67
|
+
purpose, requiresAllGrantors = true) {
|
|
68
|
+
logger_1.Logger.info(`Creating consent for BioCID: ${biocid}`);
|
|
69
|
+
logger_1.Logger.info(`Subject: ${subject}`);
|
|
70
|
+
logger_1.Logger.info(`Grantors: ${grantors.join(', ')}`);
|
|
71
|
+
logger_1.Logger.info(`Types: ${consentTypes.map(t => ConsentType[t]).join(', ')}`);
|
|
72
|
+
try {
|
|
73
|
+
const tx = await this.contract.createConsent(biocid, subject, grantors, consentTypes, birthDate, expiresAt, purpose, requiresAllGrantors);
|
|
74
|
+
logger_1.Logger.info(`Transaction submitted: ${tx.hash}`);
|
|
75
|
+
const receipt = await tx.wait();
|
|
76
|
+
logger_1.Logger.info(`Consent created in block ${receipt.blockNumber}`);
|
|
77
|
+
return biocid;
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
logger_1.Logger.error(`Consent creation failed: ${error.message}`);
|
|
81
|
+
throw error;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Approve consent (for multi-party approval)
|
|
86
|
+
*/
|
|
87
|
+
async approveConsent(biocid) {
|
|
88
|
+
logger_1.Logger.info(`Approving consent for BioCID: ${biocid}`);
|
|
89
|
+
try {
|
|
90
|
+
const tx = await this.contract.approveConsent(biocid);
|
|
91
|
+
await tx.wait();
|
|
92
|
+
logger_1.Logger.info('Consent approved');
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
logger_1.Logger.error(`Consent approval failed: ${error.message}`);
|
|
96
|
+
throw error;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Revoke consent (GDPR Article 17 - Right to Erasure)
|
|
101
|
+
*
|
|
102
|
+
* This triggers off-chain S3 deletion via backend event listener
|
|
103
|
+
*/
|
|
104
|
+
async revokeConsent(biocid, reason) {
|
|
105
|
+
logger_1.Logger.warn(`⚠️ REVOKING consent for BioCID: ${biocid}`);
|
|
106
|
+
logger_1.Logger.warn(` Reason: ${reason}`);
|
|
107
|
+
logger_1.Logger.warn(` This will trigger S3 deletion (GDPR Article 17)`);
|
|
108
|
+
try {
|
|
109
|
+
const tx = await this.contract.revokeConsent(biocid, reason);
|
|
110
|
+
const receipt = await tx.wait();
|
|
111
|
+
logger_1.Logger.info('✅ Consent revoked');
|
|
112
|
+
logger_1.Logger.info(' ConsentRevoked event emitted for backend S3 deletion');
|
|
113
|
+
logger_1.Logger.info(` GDPR Article 17: Right to erasure executed`);
|
|
114
|
+
// Parse event for confirmation
|
|
115
|
+
const event = receipt.logs.find((log) => {
|
|
116
|
+
try {
|
|
117
|
+
return log.topics[0] === this.contract.interface.getEvent('ConsentRevoked').topicHash;
|
|
118
|
+
}
|
|
119
|
+
catch {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
if (event) {
|
|
124
|
+
logger_1.Logger.info(' Backend will delete S3 file within 24 hours');
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
logger_1.Logger.error(`Consent revocation failed: ${error.message}`);
|
|
129
|
+
throw error;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Check consent status
|
|
134
|
+
*/
|
|
135
|
+
async checkConsent(biocid) {
|
|
136
|
+
// Return Active if ConsentManager not deployed
|
|
137
|
+
if (!this.contract) {
|
|
138
|
+
return ConsentStatus.Active;
|
|
139
|
+
}
|
|
140
|
+
logger_1.Logger.info(`Checking consent for BioCID: ${biocid}`);
|
|
141
|
+
try {
|
|
142
|
+
const consent = await this.contract.getConsent(biocid);
|
|
143
|
+
const status = consent.status;
|
|
144
|
+
logger_1.Logger.info(`Consent status: ${ConsentStatus[status]}`);
|
|
145
|
+
// Check if age of majority reached (automatic transfer)
|
|
146
|
+
if (consent.ageOfMajority > 0 && consent.ageOfMajority < Date.now() / 1000) {
|
|
147
|
+
logger_1.Logger.info(' Age of majority reached - automatic transfer');
|
|
148
|
+
return ConsentStatus.Transferred;
|
|
149
|
+
}
|
|
150
|
+
// Check expiration
|
|
151
|
+
if (consent.expiresAt > 0 && consent.expiresAt < Date.now() / 1000) {
|
|
152
|
+
logger_1.Logger.warn(' Consent expired');
|
|
153
|
+
return ConsentStatus.Expired;
|
|
154
|
+
}
|
|
155
|
+
return status;
|
|
156
|
+
}
|
|
157
|
+
catch (error) {
|
|
158
|
+
logger_1.Logger.error(`Consent check failed: ${error.message}`);
|
|
159
|
+
// Default to NotProvided if consent doesn't exist
|
|
160
|
+
return ConsentStatus.NotProvided;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Verify consent is valid (Active and not expired)
|
|
165
|
+
*/
|
|
166
|
+
async isConsentValid(biocid) {
|
|
167
|
+
const status = await this.checkConsent(biocid);
|
|
168
|
+
return status === ConsentStatus.Active;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Get full consent record
|
|
172
|
+
*/
|
|
173
|
+
async getConsentRecord(biocid) {
|
|
174
|
+
logger_1.Logger.info(`Fetching consent record for BioCID: ${biocid}`);
|
|
175
|
+
try {
|
|
176
|
+
const consent = await this.contract.getConsent(biocid);
|
|
177
|
+
// Convert to our interface
|
|
178
|
+
const grantorApproved = new Map();
|
|
179
|
+
for (let i = 0; i < consent.grantors.length; i++) {
|
|
180
|
+
grantorApproved.set(consent.grantors[i], consent.grantorApproved[i]);
|
|
181
|
+
}
|
|
182
|
+
return {
|
|
183
|
+
biocid,
|
|
184
|
+
subject: consent.subject,
|
|
185
|
+
grantors: consent.grantors,
|
|
186
|
+
grantorApproved,
|
|
187
|
+
consentTypes: consent.consentTypes,
|
|
188
|
+
status: consent.status,
|
|
189
|
+
grantedAt: consent.grantedAt,
|
|
190
|
+
expiresAt: consent.expiresAt,
|
|
191
|
+
ageOfMajority: consent.ageOfMajority,
|
|
192
|
+
purpose: consent.purpose,
|
|
193
|
+
requiresAllGrantors: consent.requiresAllGrantors
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
catch (error) {
|
|
197
|
+
logger_1.Logger.error(`Failed to fetch consent record: ${error.message}`);
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Log access for GDPR Article 15 (Right to Access)
|
|
203
|
+
*/
|
|
204
|
+
async logAccess(biocid, accessor, action, timestamp) {
|
|
205
|
+
logger_1.Logger.info(`Logging access: ${action} by ${accessor.substring(0, 10)}...`);
|
|
206
|
+
try {
|
|
207
|
+
const tx = await this.contract.logAccess(biocid, accessor, action, Math.floor(timestamp.getTime() / 1000));
|
|
208
|
+
await tx.wait();
|
|
209
|
+
logger_1.Logger.info('Access logged (GDPR Article 15 compliance)');
|
|
210
|
+
}
|
|
211
|
+
catch (error) {
|
|
212
|
+
// Log access errors shouldn't block the main operation
|
|
213
|
+
logger_1.Logger.warn(`Failed to log access: ${error.message}`);
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Get access logs for a BioCID
|
|
218
|
+
*/
|
|
219
|
+
async getAccessLogs(biocid) {
|
|
220
|
+
logger_1.Logger.info(`Fetching access logs for BioCID: ${biocid}`);
|
|
221
|
+
try {
|
|
222
|
+
const logs = await this.contract.getAccessLogs(biocid);
|
|
223
|
+
logger_1.Logger.info(`Found ${logs.length} access log(s)`);
|
|
224
|
+
return logs;
|
|
225
|
+
}
|
|
226
|
+
catch (error) {
|
|
227
|
+
logger_1.Logger.error(`Failed to fetch access logs: ${error.message}`);
|
|
228
|
+
return [];
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Declare family inheritance (for deceased data subjects)
|
|
233
|
+
*/
|
|
234
|
+
async declareFamilyInheritance(deceased, heirs, heirShares, // Basis points (10000 = 100%)
|
|
235
|
+
biocids) {
|
|
236
|
+
logger_1.Logger.info(`Declaring family inheritance for ${deceased}`);
|
|
237
|
+
logger_1.Logger.info(`Heirs: ${heirs.join(', ')}`);
|
|
238
|
+
if (heirs.length !== heirShares.length) {
|
|
239
|
+
throw new Error('Heirs and shares arrays must have same length');
|
|
240
|
+
}
|
|
241
|
+
const totalShares = heirShares.reduce((sum, share) => sum + share, 0);
|
|
242
|
+
if (totalShares !== 10000) {
|
|
243
|
+
throw new Error('Heir shares must sum to 10000 basis points (100%)');
|
|
244
|
+
}
|
|
245
|
+
try {
|
|
246
|
+
const tx = await this.contract.declareFamilyInheritance(deceased, heirs, heirShares, biocids);
|
|
247
|
+
await tx.wait();
|
|
248
|
+
logger_1.Logger.info('Family inheritance declared');
|
|
249
|
+
}
|
|
250
|
+
catch (error) {
|
|
251
|
+
logger_1.Logger.error(`Family inheritance declaration failed: ${error.message}`);
|
|
252
|
+
throw error;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Transfer consent to subject at age of majority
|
|
257
|
+
*/
|
|
258
|
+
async transferConsentToSubject(biocid) {
|
|
259
|
+
logger_1.Logger.info(`Transferring consent to subject for BioCID: ${biocid}`);
|
|
260
|
+
try {
|
|
261
|
+
const tx = await this.contract.transferConsentToSubject(biocid);
|
|
262
|
+
await tx.wait();
|
|
263
|
+
logger_1.Logger.info('Consent transferred to subject (age of majority reached)');
|
|
264
|
+
}
|
|
265
|
+
catch (error) {
|
|
266
|
+
logger_1.Logger.error(`Consent transfer failed: ${error.message}`);
|
|
267
|
+
throw error;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
/**
|
|
271
|
+
* Helper: Calculate age of majority timestamp
|
|
272
|
+
*/
|
|
273
|
+
static calculateAgeOfMajority(birthDate) {
|
|
274
|
+
const ageOfMajority = new Date(birthDate);
|
|
275
|
+
ageOfMajority.setFullYear(ageOfMajority.getFullYear() + 18);
|
|
276
|
+
return Math.floor(ageOfMajority.getTime() / 1000);
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Helper: Format consent status for display
|
|
280
|
+
*/
|
|
281
|
+
static formatConsentStatus(status) {
|
|
282
|
+
switch (status) {
|
|
283
|
+
case ConsentStatus.Active:
|
|
284
|
+
return '✅ Active';
|
|
285
|
+
case ConsentStatus.Revoked:
|
|
286
|
+
return '❌ Revoked (GDPR Article 17)';
|
|
287
|
+
case ConsentStatus.Expired:
|
|
288
|
+
return '⏰ Expired';
|
|
289
|
+
case ConsentStatus.Transferred:
|
|
290
|
+
return '🎂 Transferred (Age of Majority)';
|
|
291
|
+
case ConsentStatus.NotProvided:
|
|
292
|
+
return '⚠️ Not Provided';
|
|
293
|
+
default:
|
|
294
|
+
return '❓ Unknown';
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
exports.ConsentManager = ConsentManager;
|
|
299
|
+
//# sourceMappingURL=ConsentManager.js.map
|