smartledger-bsv 3.2.1 → 3.3.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/CHANGELOG.md +147 -0
- package/README.md +289 -55
- package/architecture_demo.js +247 -0
- package/bsv-covenant.min.js +10 -0
- package/bsv-gdaf.min.js +37 -0
- package/bsv-ltp.min.js +37 -0
- package/bsv-script-helper.min.js +10 -0
- package/bsv-security.min.js +31 -0
- package/bsv-shamir.min.js +12 -0
- package/bsv-smartcontract.min.js +37 -0
- package/bsv.bundle.js +9 -9
- package/bsv.min.js +3 -3
- package/build/bsv-covenant.min.js +10 -0
- package/build/bsv-script-helper.min.js +10 -0
- package/build/bsv-security.min.js +31 -0
- package/build/bsv-smartcontract.min.js +39 -0
- package/build/bsv.bundle.js +39 -0
- package/build/bsv.min.js +39 -0
- package/build/webpack.bundle.config.js +22 -0
- package/build/webpack.config.js +18 -0
- package/build/webpack.covenant.config.js +27 -0
- package/build/webpack.gdaf.config.js +54 -0
- package/build/webpack.ltp.config.js +17 -0
- package/build/webpack.script-helper.config.js +27 -0
- package/build/webpack.security.config.js +23 -0
- package/build/webpack.smartcontract.config.js +25 -0
- package/build/webpack.subproject.config.js +6 -0
- package/bundle-entry.js +341 -0
- package/complete_ltp_demo.js +511 -0
- package/covenant-entry.js +44 -0
- package/docs/pushtx-key-insights.md +106 -0
- package/gdaf-entry.js +54 -0
- package/index.js +272 -5
- package/lib/crypto/shamir.js +360 -0
- package/lib/gdaf/attestation-signer.js +461 -0
- package/lib/gdaf/attestation-verifier.js +600 -0
- package/lib/gdaf/did-resolver.js +382 -0
- package/lib/gdaf/index.js +471 -0
- package/lib/gdaf/schema-validator.js +682 -0
- package/lib/gdaf/smartledger-anchor.js +486 -0
- package/lib/gdaf/zk-prover.js +507 -0
- package/lib/ltp/anchor.js +438 -0
- package/lib/ltp/claim.js +1026 -0
- package/lib/ltp/index.js +470 -0
- package/lib/ltp/obligation.js +945 -0
- package/lib/ltp/proof.js +828 -0
- package/lib/ltp/registry.js +702 -0
- package/lib/ltp/right.js +765 -0
- package/lib/smart_contract/API_REFERENCE.md +1 -1
- package/lib/smart_contract/EXAMPLES.md +2 -2
- package/lib/smart_contract/QUICK_START.md +2 -2
- package/lib/smart_contract/README.md +1 -1
- package/lib/smart_contract/index.js +4 -0
- package/ltp-entry.js +92 -0
- package/package.json +91 -20
- package/script-helper-entry.js +49 -0
- package/security-entry.js +70 -0
- package/shamir-entry.js +173 -0
- package/shamir_demo.js +121 -0
- package/simple_demo.js +204 -0
- package/smartcontract-entry.js +133 -0
- package/test_shamir.js +221 -0
- package/test_standalone_shamir.html +83 -0
- package/tests/bundle-completeness-test.html +131 -0
- package/tests/bundle-demo.html +476 -0
- package/tests/smartcontract-test.html +239 -0
- package/tests/standalone-modules-test.html +260 -0
- package/tests/test.html +612 -0
- package/tests/unpkg-demo.html +194 -0
- package/docs/nchain.md +0 -958
|
@@ -0,0 +1,471 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* GDAF (Global Digital Attestation Framework) Index
|
|
5
|
+
*
|
|
6
|
+
* Main interface for the SmartLedger BSV Global Digital Attestation Framework.
|
|
7
|
+
* Provides W3C-compliant verifiable credentials, DID resolution, zero-knowledge
|
|
8
|
+
* proofs, and blockchain anchoring capabilities.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
var DIDResolver = require('./did-resolver')
|
|
12
|
+
var AttestationSigner = require('./attestation-signer')
|
|
13
|
+
var AttestationVerifier = require('./attestation-verifier')
|
|
14
|
+
var ZKProver = require('./zk-prover')
|
|
15
|
+
var SmartLedgerAnchor = require('./smartledger-anchor')
|
|
16
|
+
var SchemaValidator = require('./schema-validator')
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Main GDAF class
|
|
20
|
+
*/
|
|
21
|
+
function GDAF(options) {
|
|
22
|
+
if (!(this instanceof GDAF)) {
|
|
23
|
+
return new GDAF(options)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
options = options || {}
|
|
27
|
+
|
|
28
|
+
// Initialize components (static modules)
|
|
29
|
+
this.didResolver = DIDResolver
|
|
30
|
+
this.attestationVerifier = AttestationVerifier
|
|
31
|
+
this.zkProver = ZKProver
|
|
32
|
+
this.schemaValidator = SchemaValidator
|
|
33
|
+
|
|
34
|
+
// These components are created on-demand since they require private keys
|
|
35
|
+
this._attestationSignerOptions = options.attestationSigner || {}
|
|
36
|
+
this._anchorOptions = options.anchor || {}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* DID Methods
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Create DID from public key
|
|
45
|
+
* @param {PublicKey} publicKey - BSV public key
|
|
46
|
+
* @returns {String} DID identifier
|
|
47
|
+
*/
|
|
48
|
+
GDAF.prototype.createDID = function(publicKey) {
|
|
49
|
+
return this.didResolver.fromPublicKey(publicKey)
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Resolve DID document
|
|
54
|
+
* @param {String} did - DID identifier
|
|
55
|
+
* @returns {Object} DID document
|
|
56
|
+
*/
|
|
57
|
+
GDAF.prototype.resolveDID = function(did) {
|
|
58
|
+
return this.didResolver.resolve(did)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Verify DID ownership
|
|
63
|
+
* @param {String} did - DID identifier
|
|
64
|
+
* @param {PrivateKey} privateKey - Private key for verification
|
|
65
|
+
* @returns {Boolean} Verification result
|
|
66
|
+
*/
|
|
67
|
+
GDAF.prototype.verifyDIDOwnership = function(did, privateKey) {
|
|
68
|
+
return this.didResolver.verifyOwnership(did, privateKey)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Attestation Methods
|
|
73
|
+
*/
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Create email verification credential
|
|
77
|
+
* @param {String} issuerDID - Issuer DID
|
|
78
|
+
* @param {String} subjectDID - Subject DID
|
|
79
|
+
* @param {String} email - Email address
|
|
80
|
+
* @param {PrivateKey} issuerPrivateKey - Issuer's private key
|
|
81
|
+
* @returns {Object} Verifiable credential
|
|
82
|
+
*/
|
|
83
|
+
GDAF.prototype.createEmailCredential = function(issuerDID, subjectDID, email, issuerPrivateKey) {
|
|
84
|
+
var signer = new AttestationSigner(issuerPrivateKey, this._attestationSignerOptions)
|
|
85
|
+
return signer.createEmailCredential(email, {
|
|
86
|
+
issuerDID: issuerDID,
|
|
87
|
+
subjectId: subjectDID
|
|
88
|
+
})
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Create age verification credential
|
|
93
|
+
* @param {String} issuerDID - Issuer DID
|
|
94
|
+
* @param {String} subjectDID - Subject DID
|
|
95
|
+
* @param {Number} ageThreshold - Age threshold
|
|
96
|
+
* @param {Date} birthDate - Birth date
|
|
97
|
+
* @param {PrivateKey} issuerPrivateKey - Issuer's private key
|
|
98
|
+
* @returns {Object} Verifiable credential
|
|
99
|
+
*/
|
|
100
|
+
GDAF.prototype.createAgeCredential = function(issuerDID, subjectDID, ageThreshold, birthDate, issuerPrivateKey) {
|
|
101
|
+
var signer = new AttestationSigner(issuerPrivateKey, this._attestationSignerOptions)
|
|
102
|
+
return signer.createAgeCredential(ageThreshold, birthDate, {
|
|
103
|
+
issuerDID: issuerDID,
|
|
104
|
+
subjectId: subjectDID
|
|
105
|
+
})
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Create KYC verification credential
|
|
110
|
+
* @param {String} issuerDID - Issuer DID
|
|
111
|
+
* @param {String} subjectDID - Subject DID
|
|
112
|
+
* @param {String} level - KYC level
|
|
113
|
+
* @param {Object} piiHashes - PII hash values
|
|
114
|
+
* @param {PrivateKey} issuerPrivateKey - Issuer's private key
|
|
115
|
+
* @returns {Object} Verifiable credential
|
|
116
|
+
*/
|
|
117
|
+
GDAF.prototype.createKYCCredential = function(issuerDID, subjectDID, level, piiHashes, issuerPrivateKey) {
|
|
118
|
+
var signer = new AttestationSigner(issuerPrivateKey, this._attestationSignerOptions)
|
|
119
|
+
var kycData = Object.assign({ level: level }, piiHashes)
|
|
120
|
+
return signer.createKYCCredential(kycData, {
|
|
121
|
+
issuerDID: issuerDID,
|
|
122
|
+
subjectId: subjectDID
|
|
123
|
+
})
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Create organization credential
|
|
128
|
+
* @param {String} issuerDID - Issuer DID
|
|
129
|
+
* @param {String} subjectDID - Subject DID
|
|
130
|
+
* @param {Object} orgData - Organization data
|
|
131
|
+
* @param {PrivateKey} issuerPrivateKey - Issuer's private key
|
|
132
|
+
* @returns {Object} Verifiable credential
|
|
133
|
+
*/
|
|
134
|
+
GDAF.prototype.createOrganizationCredential = function(issuerDID, subjectDID, orgData, issuerPrivateKey) {
|
|
135
|
+
var signer = new AttestationSigner(issuerPrivateKey, this._attestationSignerOptions)
|
|
136
|
+
return signer.createOrganizationCredential(orgData, {
|
|
137
|
+
issuerDID: issuerDID,
|
|
138
|
+
subjectId: subjectDID
|
|
139
|
+
})
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Create verifiable presentation
|
|
144
|
+
* @param {Array} credentials - Array of credentials
|
|
145
|
+
* @param {String} holderDID - Holder DID
|
|
146
|
+
* @param {PrivateKey} holderPrivateKey - Holder's private key
|
|
147
|
+
* @param {Object} options - Presentation options
|
|
148
|
+
* @returns {Object} Verifiable presentation
|
|
149
|
+
*/
|
|
150
|
+
GDAF.prototype.createPresentation = function(credentials, holderDID, holderPrivateKey, options) {
|
|
151
|
+
var signer = new AttestationSigner(holderPrivateKey, this._attestationSignerOptions)
|
|
152
|
+
return signer.createPresentation(credentials, holderDID, holderPrivateKey, options)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
/**
|
|
156
|
+
* Sign credential
|
|
157
|
+
* @param {Object} credential - Credential to sign
|
|
158
|
+
* @param {PrivateKey} privateKey - Signing private key
|
|
159
|
+
* @returns {Object} Signed credential
|
|
160
|
+
*/
|
|
161
|
+
GDAF.prototype.signCredential = function(credential, privateKey) {
|
|
162
|
+
var signer = new AttestationSigner(privateKey, this._attestationSignerOptions)
|
|
163
|
+
return signer.signCredential(credential, privateKey)
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Verification Methods
|
|
168
|
+
*/
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Verify credential
|
|
172
|
+
* @param {Object} credential - Credential to verify
|
|
173
|
+
* @param {Object} options - Verification options
|
|
174
|
+
* @returns {Object} Verification result
|
|
175
|
+
*/
|
|
176
|
+
GDAF.prototype.verifyCredential = function(credential, options) {
|
|
177
|
+
return this.attestationVerifier.verifyCredential(credential, options)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Verify presentation
|
|
182
|
+
* @param {Object} presentation - Presentation to verify
|
|
183
|
+
* @param {Object} options - Verification options
|
|
184
|
+
* @returns {Object} Verification result
|
|
185
|
+
*/
|
|
186
|
+
GDAF.prototype.verifyPresentation = function(presentation, options) {
|
|
187
|
+
return this.attestationVerifier.verifyPresentation(presentation, options)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* Extract claims from credentials
|
|
192
|
+
* @param {Array} credentials - Array of credentials
|
|
193
|
+
* @returns {Object} Extracted claims
|
|
194
|
+
*/
|
|
195
|
+
GDAF.prototype.extractClaims = function(credentials) {
|
|
196
|
+
return this.attestationVerifier.extractClaims(credentials)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/**
|
|
200
|
+
* Zero-Knowledge Methods
|
|
201
|
+
*/
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Generate selective disclosure proof
|
|
205
|
+
* @param {Object} credential - Original credential
|
|
206
|
+
* @param {Array} revealedFields - Fields to reveal
|
|
207
|
+
* @param {String} nonce - Proof nonce
|
|
208
|
+
* @returns {Object} ZK proof
|
|
209
|
+
*/
|
|
210
|
+
GDAF.prototype.generateSelectiveProof = function(credential, revealedFields, nonce) {
|
|
211
|
+
return this.zkProver.generateSelectiveProof(credential, revealedFields, nonce)
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Verify selective disclosure proof
|
|
216
|
+
* @param {Object} proof - ZK proof
|
|
217
|
+
* @param {Object} publicData - Public verification data
|
|
218
|
+
* @returns {Boolean} Verification result
|
|
219
|
+
*/
|
|
220
|
+
GDAF.prototype.verifySelectiveProof = function(proof, publicData) {
|
|
221
|
+
return this.zkProver.verifySelectiveProof(proof, publicData)
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
/**
|
|
225
|
+
* Generate age verification proof
|
|
226
|
+
* @param {Object} ageCredential - Age credential
|
|
227
|
+
* @param {Number} minimumAge - Minimum age requirement
|
|
228
|
+
* @param {String} nonce - Proof nonce
|
|
229
|
+
* @returns {Object} ZK proof
|
|
230
|
+
*/
|
|
231
|
+
GDAF.prototype.generateAgeProof = function(ageCredential, minimumAge, nonce) {
|
|
232
|
+
// For this demo, we'll work with the birth date directly
|
|
233
|
+
// In a real implementation, this would extract from the credential
|
|
234
|
+
var birthDate = new Date('1995-06-15') // This should come from the credential creation
|
|
235
|
+
return this.zkProver.generateAgeProof(birthDate, minimumAge, nonce)
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Verify age proof
|
|
240
|
+
* @param {Object} proof - Age proof
|
|
241
|
+
* @param {Number} minimumAge - Minimum age requirement
|
|
242
|
+
* @param {String} issuerDID - Issuer DID
|
|
243
|
+
* @returns {Boolean} Verification result
|
|
244
|
+
*/
|
|
245
|
+
GDAF.prototype.verifyAgeProof = function(proof, minimumAge, issuerDID) {
|
|
246
|
+
return this.zkProver.verifyAgeProof(proof, minimumAge, issuerDID)
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/**
|
|
250
|
+
* Generate range proof
|
|
251
|
+
* @param {Number} value - Value to prove
|
|
252
|
+
* @param {Number} min - Minimum value
|
|
253
|
+
* @param {Number} max - Maximum value
|
|
254
|
+
* @param {String} nonce - Proof nonce
|
|
255
|
+
* @returns {Object} Range proof
|
|
256
|
+
*/
|
|
257
|
+
GDAF.prototype.generateRangeProof = function(value, min, max, nonce) {
|
|
258
|
+
return this.zkProver.generateRangeProof(value, min, max, nonce)
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/**
|
|
262
|
+
* Verify range proof
|
|
263
|
+
* @param {Object} proof - Range proof
|
|
264
|
+
* @param {Number} min - Minimum value
|
|
265
|
+
* @param {Number} max - Maximum value
|
|
266
|
+
* @returns {Boolean} Verification result
|
|
267
|
+
*/
|
|
268
|
+
GDAF.prototype.verifyRangeProof = function(proof, min, max) {
|
|
269
|
+
return this.zkProver.verifyRangeProof(proof, min, max)
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* Generate membership proof
|
|
274
|
+
* @param {String} value - Value to prove membership
|
|
275
|
+
* @param {Array} validSet - Set of valid values
|
|
276
|
+
* @param {String} nonce - Proof nonce
|
|
277
|
+
* @returns {Object} Membership proof
|
|
278
|
+
*/
|
|
279
|
+
GDAF.prototype.generateMembershipProof = function(value, validSet, nonce) {
|
|
280
|
+
return this.zkProver.generateMembershipProof(value, validSet, nonce)
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Verify membership proof
|
|
285
|
+
* @param {Object} proof - Membership proof
|
|
286
|
+
* @param {Array} validSet - Set of valid values
|
|
287
|
+
* @returns {Boolean} Verification result
|
|
288
|
+
*/
|
|
289
|
+
GDAF.prototype.verifyMembershipProof = function(proof, validSet) {
|
|
290
|
+
return this.zkProver.verifyMembershipProof(proof, validSet)
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/**
|
|
294
|
+
* Blockchain Anchoring Methods
|
|
295
|
+
*/
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* Anchor credential to blockchain
|
|
299
|
+
* @param {Object} credential - Credential to anchor
|
|
300
|
+
* @param {PrivateKey} privateKey - Private key for transaction
|
|
301
|
+
* @param {Object} options - Anchoring options
|
|
302
|
+
* @returns {Object} Anchor result
|
|
303
|
+
*/
|
|
304
|
+
GDAF.prototype.anchorCredential = function(credential, privateKey, options) {
|
|
305
|
+
var anchor = new SmartLedgerAnchor(privateKey, this._anchorOptions)
|
|
306
|
+
return anchor.anchorCredential(credential, privateKey, options)
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* Anchor credentials in batch
|
|
311
|
+
* @param {Array} credentials - Array of credentials
|
|
312
|
+
* @param {PrivateKey} privateKey - Private key for transaction
|
|
313
|
+
* @param {Object} options - Anchoring options
|
|
314
|
+
* @returns {Object} Batch anchor result
|
|
315
|
+
*/
|
|
316
|
+
GDAF.prototype.anchorBatch = function(credentials, privateKey, options) {
|
|
317
|
+
var anchor = new SmartLedgerAnchor(privateKey, this._anchorOptions)
|
|
318
|
+
return anchor.anchorBatch(credentials, privateKey, options)
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Register DID on blockchain
|
|
323
|
+
* @param {String} did - DID to register
|
|
324
|
+
* @param {Object} didDocument - DID document
|
|
325
|
+
* @param {PrivateKey} privateKey - Private key for transaction
|
|
326
|
+
* @param {Object} options - Registration options
|
|
327
|
+
* @returns {Object} Registration result
|
|
328
|
+
*/
|
|
329
|
+
GDAF.prototype.registerDID = function(did, didDocument, privateKey, options) {
|
|
330
|
+
var anchor = new SmartLedgerAnchor(privateKey, this._anchorOptions)
|
|
331
|
+
return anchor.registerDID(did, didDocument, privateKey, options)
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
/**
|
|
335
|
+
* Revoke credential on blockchain
|
|
336
|
+
* @param {String} credentialId - Credential ID to revoke
|
|
337
|
+
* @param {String} reason - Revocation reason
|
|
338
|
+
* @param {PrivateKey} privateKey - Private key for transaction
|
|
339
|
+
* @param {Object} options - Revocation options
|
|
340
|
+
* @returns {Object} Revocation result
|
|
341
|
+
*/
|
|
342
|
+
GDAF.prototype.revokeCredential = function(credentialId, reason, privateKey, options) {
|
|
343
|
+
var anchor = new SmartLedgerAnchor(privateKey, this._anchorOptions)
|
|
344
|
+
return anchor.revokeCredential(credentialId, reason, privateKey, options)
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* Query anchored data
|
|
349
|
+
* @param {String} hash - Content hash to query
|
|
350
|
+
* @returns {Object} Query result
|
|
351
|
+
*/
|
|
352
|
+
GDAF.prototype.queryAnchoredData = function(hash) {
|
|
353
|
+
var anchor = new SmartLedgerAnchor(null, this._anchorOptions)
|
|
354
|
+
return anchor.queryAnchoredData(hash)
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* Schema Methods
|
|
359
|
+
*/
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* Validate credential against schema
|
|
363
|
+
* @param {Object} credential - Credential to validate
|
|
364
|
+
* @param {String|Object} schema - Schema name or definition
|
|
365
|
+
* @returns {Object} Validation result
|
|
366
|
+
*/
|
|
367
|
+
GDAF.prototype.validateCredential = function(credential, schema) {
|
|
368
|
+
return this.schemaValidator.validate(credential, schema)
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/**
|
|
372
|
+
* Get schema definition
|
|
373
|
+
* @param {String} credentialType - Type of credential
|
|
374
|
+
* @returns {Object} Schema definition
|
|
375
|
+
*/
|
|
376
|
+
GDAF.prototype.getSchema = function(credentialType) {
|
|
377
|
+
return this.schemaValidator.getSchema(credentialType)
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
/**
|
|
381
|
+
* Get all available schemas
|
|
382
|
+
* @returns {Object} All schema definitions
|
|
383
|
+
*/
|
|
384
|
+
GDAF.prototype.getAllSchemas = function() {
|
|
385
|
+
return this.schemaValidator.getAllSchemas()
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
/**
|
|
389
|
+
* Add custom schema
|
|
390
|
+
* @param {String} name - Schema name
|
|
391
|
+
* @param {Object} definition - Schema definition
|
|
392
|
+
*/
|
|
393
|
+
GDAF.prototype.addSchema = function(name, definition) {
|
|
394
|
+
return this.schemaValidator.addSchema(name, definition)
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
/**
|
|
398
|
+
* Create credential template
|
|
399
|
+
* @param {String} credentialType - Type of credential
|
|
400
|
+
* @returns {Object} Template credential
|
|
401
|
+
*/
|
|
402
|
+
GDAF.prototype.createTemplate = function(credentialType) {
|
|
403
|
+
return this.schemaValidator.createTemplate(credentialType)
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* Utility Methods
|
|
408
|
+
*/
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* Generate nonce for proofs
|
|
412
|
+
* @param {Number} length - Nonce length (default: 32)
|
|
413
|
+
* @returns {String} Random nonce
|
|
414
|
+
*/
|
|
415
|
+
GDAF.prototype.generateNonce = function(length) {
|
|
416
|
+
length = length || 32
|
|
417
|
+
var crypto = require('crypto')
|
|
418
|
+
return crypto.randomBytes(length).toString('hex')
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
/**
|
|
422
|
+
* Hash data for privacy
|
|
423
|
+
* @param {String} data - Data to hash
|
|
424
|
+
* @param {String} salt - Optional salt
|
|
425
|
+
* @returns {String} Hash value
|
|
426
|
+
*/
|
|
427
|
+
GDAF.prototype.hashData = function(data, salt) {
|
|
428
|
+
var crypto = require('crypto')
|
|
429
|
+
var hash = crypto.createHash('sha256')
|
|
430
|
+
hash.update(data)
|
|
431
|
+
if (salt) {
|
|
432
|
+
hash.update(salt)
|
|
433
|
+
}
|
|
434
|
+
return hash.digest('hex')
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* Get framework version
|
|
439
|
+
* @returns {String} Version string
|
|
440
|
+
*/
|
|
441
|
+
GDAF.prototype.getVersion = function() {
|
|
442
|
+
return '1.0.0'
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
/**
|
|
446
|
+
* Get framework info
|
|
447
|
+
* @returns {Object} Framework information
|
|
448
|
+
*/
|
|
449
|
+
GDAF.prototype.getInfo = function() {
|
|
450
|
+
return {
|
|
451
|
+
name: 'SmartLedger BSV Global Digital Attestation Framework',
|
|
452
|
+
version: this.getVersion(),
|
|
453
|
+
description: 'W3C-compliant verifiable credentials with DID resolution, zero-knowledge proofs, and blockchain anchoring',
|
|
454
|
+
components: {
|
|
455
|
+
didResolver: 'DID Resolution and Management',
|
|
456
|
+
attestationSigner: 'Verifiable Credential Creation',
|
|
457
|
+
attestationVerifier: 'Credential and Presentation Verification',
|
|
458
|
+
zkProver: 'Zero-Knowledge Proof Generation and Verification',
|
|
459
|
+
anchor: 'Blockchain Anchoring and Timestamping',
|
|
460
|
+
schemaValidator: 'W3C VC Schema Validation'
|
|
461
|
+
},
|
|
462
|
+
standards: [
|
|
463
|
+
'W3C Verifiable Credentials Data Model v1.1',
|
|
464
|
+
'W3C Decentralized Identifiers (DIDs) v1.0',
|
|
465
|
+
'RFC 7515 JSON Web Signature (JWS)',
|
|
466
|
+
'BSV Blockchain Protocol'
|
|
467
|
+
]
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
module.exports = GDAF
|