@smartledger/bsv 3.4.0 → 3.4.2

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 (48) hide show
  1. package/CHANGELOG.md +64 -0
  2. package/README.md +60 -32
  3. package/bsv-anchor.min.js +12 -0
  4. package/bsv-covenant.min.js +8 -8
  5. package/bsv-didweb.min.js +12 -0
  6. package/bsv-gdaf.min.js +9 -9
  7. package/bsv-ltp.min.js +9 -9
  8. package/bsv-mnemonic.min.js +2 -2
  9. package/bsv-shamir.min.js +3 -3
  10. package/bsv-smartcontract.min.js +5 -5
  11. package/bsv-statuslist.min.js +18 -0
  12. package/bsv-vcjwt.min.js +12 -0
  13. package/bsv.bundle.js +9 -9
  14. package/bsv.min.js +5 -5
  15. package/build/webpack.anchor.config.js +9 -13
  16. package/build/webpack.didweb.config.js +10 -14
  17. package/build/webpack.statuslist.config.js +9 -14
  18. package/build/webpack.vcjwt.config.js +9 -13
  19. package/examples/legacy/README.md +11 -0
  20. package/index.js +24 -6
  21. package/lib/browser-utxo-manager-es5.js +11 -4
  22. package/lib/browser-utxo-manager.js +15 -8
  23. package/lib/ltp/claim.js +1 -0
  24. package/lib/ltp/obligation.js +1 -0
  25. package/lib/ltp/registry.js +2 -0
  26. package/lib/ltp/right.js +1 -0
  27. package/lib/transaction/transaction.js +1 -1
  28. package/lib/util/_.js +7 -1
  29. package/package.json +9 -11
  30. package/demos/gdaf_core_test.js +0 -131
  31. package/examples/scripts/custom_script_signature_test.js +0 -344
  32. package/tests/browser-compatibility/README.md +0 -35
  33. package/tests/browser-compatibility/test-cdn-vs-local.html +0 -186
  34. package/tests/browser-compatibility/test-pbkdf2.html +0 -51
  35. package/tests/bundle-completeness-test.html +0 -131
  36. package/tests/bundle-demo.html +0 -476
  37. package/tests/smartcontract-test.html +0 -239
  38. package/tests/standalone-modules-test.html +0 -260
  39. package/tests/test.html +0 -612
  40. package/tests/test_standalone_shamir.html +0 -83
  41. package/tests/unpkg-demo.html +0 -194
  42. package/utilities/blockchain-state.json +0 -118565
  43. /package/{lib/smart_contract/test_integration.js → examples/legacy/smart_contract_test_integration.js} +0 -0
  44. /package/{tests → examples/legacy}/test_builtin_verify.js +0 -0
  45. /package/{tests → examples/legacy}/test_debug_integration.js +0 -0
  46. /package/{tests → examples/legacy}/test_ecdsa_little.js +0 -0
  47. /package/{tests → examples/legacy}/test_shamir.js +0 -0
  48. /package/{tests → examples/legacy}/test_smartverify_der.js +0 -0
@@ -1,21 +1,17 @@
1
- var path = require('path')
1
+ const path = require('path')
2
2
 
3
3
  module.exports = {
4
- target: 'web',
5
- mode: 'production',
6
4
  entry: './anchor-entry.js',
5
+ mode: 'production',
6
+ optimization: {
7
+ minimize: true
8
+ },
7
9
  output: {
8
- path: path.resolve(__dirname, '..'),
10
+ path: path.resolve(__dirname, '../'),
9
11
  filename: 'bsv-anchor.min.js',
10
12
  library: 'bsvAnchor',
11
- libraryTarget: 'umd'
12
- },
13
- node: {
14
- crypto: true,
15
- stream: true,
16
- buffer: true
13
+ libraryTarget: 'umd',
14
+ globalObject: 'this'
17
15
  },
18
- node: {
19
- Buffer: true
20
- }
16
+ target: 'web'
21
17
  }
@@ -1,21 +1,17 @@
1
- var path = require('path')
1
+ const path = require('path')
2
2
 
3
3
  module.exports = {
4
- target: 'web',
5
- mode: 'production',
6
4
  entry: './didweb-entry.js',
5
+ mode: 'production',
6
+ optimization: {
7
+ minimize: true
8
+ },
7
9
  output: {
8
- path: path.resolve(__dirname, '..'),
10
+ path: path.resolve(__dirname, '../'),
9
11
  filename: 'bsv-didweb.min.js',
10
- library: 'bsvDidWeb',
11
- libraryTarget: 'umd'
12
- },
13
- node: {
14
- crypto: true,
15
- stream: true,
16
- buffer: true
12
+ library: 'bsvDIDWeb',
13
+ libraryTarget: 'umd',
14
+ globalObject: 'this'
17
15
  },
18
- node: {
19
- Buffer: true
20
- }
16
+ target: 'web'
21
17
  }
@@ -1,22 +1,17 @@
1
- var path = require('path')
1
+ const path = require('path')
2
2
 
3
3
  module.exports = {
4
- target: 'web',
5
- mode: 'production',
6
4
  entry: './statuslist-entry.js',
5
+ mode: 'production',
6
+ optimization: {
7
+ minimize: true
8
+ },
7
9
  output: {
8
- path: path.resolve(__dirname, '..'),
10
+ path: path.resolve(__dirname, '../'),
9
11
  filename: 'bsv-statuslist.min.js',
10
12
  library: 'bsvStatusList',
11
- libraryTarget: 'umd'
12
- },
13
- node: {
14
- crypto: true,
15
- stream: true,
16
- buffer: true,
17
- zlib: true
13
+ libraryTarget: 'umd',
14
+ globalObject: 'this'
18
15
  },
19
- node: {
20
- Buffer: true
21
- }
16
+ target: 'web'
22
17
  }
@@ -1,21 +1,17 @@
1
- var path = require('path')
1
+ const path = require('path')
2
2
 
3
3
  module.exports = {
4
- target: 'web',
5
- mode: 'production',
6
4
  entry: './vcjwt-entry.js',
5
+ mode: 'production',
6
+ optimization: {
7
+ minimize: true
8
+ },
7
9
  output: {
8
- path: path.resolve(__dirname, '..'),
10
+ path: path.resolve(__dirname, '../'),
9
11
  filename: 'bsv-vcjwt.min.js',
10
12
  library: 'bsvVcJwt',
11
- libraryTarget: 'umd'
12
- },
13
- node: {
14
- crypto: true,
15
- stream: true,
16
- buffer: true
13
+ libraryTarget: 'umd',
14
+ globalObject: 'this'
17
15
  },
18
- node: {
19
- Buffer: true
20
- }
16
+ target: 'web'
21
17
  }
@@ -0,0 +1,11 @@
1
+ # Legacy sanity scripts
2
+
3
+ Pre-mocha standalone scripts kept here for historical reference. They are not
4
+ part of the test suite (no `describe`/`it`). Run with:
5
+
6
+ ```bash
7
+ node examples/legacy/<file>.js
8
+ ```
9
+
10
+ `smart_contract_test_integration.js` was previously in `lib/smart_contract/`
11
+ but is an integration script (calls `process.exit`), not library code.
package/index.js CHANGED
@@ -29,7 +29,15 @@ bsv.versionGuard = function (version) {
29
29
  bsv.versionGuard(global._bsv)
30
30
  global._bsv = bsv.version
31
31
 
32
- // SmartLedger security information
32
+ // SmartLedger security information.
33
+ // NOTE: these properties advertise that hardening *helpers* ship in this
34
+ // package (`bsv.SmartVerify`, `bsv.EllipticFixed`, `signature.toCanonical()`,
35
+ // etc.). They are NOT automatically wired into the default verify path:
36
+ // `transaction.verify()`, `signature.verify()`, and `Message().verify()` go
37
+ // through `lib/crypto/ecdsa.js`, which uses BSV's own pure-JS ECDSA and does
38
+ // not route through `SmartVerify` or `EllipticFixed`. To get the strict
39
+ // input validation, call `bsv.SmartVerify.smartVerify(...)` explicitly.
40
+ // See the Security section of README.md.
33
41
  bsv.isHardened = true
34
42
  bsv.hardenedBy = 'SmartLedger'
35
43
  bsv.baseVersion = 'v1.5.6'
@@ -119,7 +127,9 @@ try {
119
127
  try {
120
128
  bsv.BrowserUTXOManager = require('./lib/browser-utxo-manager-es5')
121
129
  } catch (e) {
122
- // BrowserUTXOManager not available
130
+ if (typeof window === 'undefined') {
131
+ console.warn('[bsv] BrowserUTXOManager failed to load:', e.message)
132
+ }
123
133
  }
124
134
 
125
135
  // Node.js specific tools (advanced development tools)
@@ -140,28 +150,36 @@ bsv.GDAF = require('./lib/gdaf')
140
150
  try {
141
151
  bsv.DIDWeb = require('./lib/didweb')
142
152
  } catch (e) {
143
- // DIDWeb module not available - use standalone bsv-didweb.min.js
153
+ if (typeof window === 'undefined') {
154
+ console.warn('[bsv] DIDWeb module failed to load:', e.message)
155
+ }
144
156
  }
145
157
 
146
158
  // VC-JWT Module (W3C Verifiable Credentials)
147
159
  try {
148
160
  bsv.VcJwt = require('./lib/vcjwt')
149
161
  } catch (e) {
150
- // VcJwt module not available - use standalone bsv-vcjwt.min.js
162
+ if (typeof window === 'undefined') {
163
+ console.warn('[bsv] VcJwt module failed to load:', e.message)
164
+ }
151
165
  }
152
166
 
153
167
  // StatusList2021 Module (Credential revocation)
154
168
  try {
155
169
  bsv.StatusList = require('./lib/statuslist')
156
170
  } catch (e) {
157
- // StatusList module not available - use standalone bsv-statuslist.min.js
171
+ if (typeof window === 'undefined') {
172
+ console.warn('[bsv] StatusList module failed to load:', e.message)
173
+ }
158
174
  }
159
175
 
160
176
  // Anchor Module (BSV hash anchoring)
161
177
  try {
162
178
  bsv.Anchor = require('./lib/anchor')
163
179
  } catch (e) {
164
- // Anchor module not available - use standalone bsv-anchor.min.js
180
+ if (typeof window === 'undefined') {
181
+ console.warn('[bsv] Anchor module failed to load:', e.message)
182
+ }
165
183
  }
166
184
 
167
185
  // GDAF Direct Access Methods (for easier developer experience)
@@ -5,6 +5,13 @@
5
5
  * Lightweight UTXO management for browser environments with configurable storage
6
6
  */
7
7
 
8
+ // Set window.BSV_DEBUG = true (browser) or BSV_DEBUG=1 (Node) to enable info logs.
9
+ var debug = function () {
10
+ var enabled = (typeof process !== 'undefined' && process.env && process.env.BSV_DEBUG) ||
11
+ (typeof window !== 'undefined' && window.BSV_DEBUG)
12
+ if (enabled) console.log.apply(console, arguments)
13
+ }
14
+
8
15
  var STORAGE_TYPES = {
9
16
  MEMORY: 'memory',
10
17
  SESSION: 'session',
@@ -75,7 +82,7 @@ BrowserUTXOManager.prototype.loadFromStorage = function() {
75
82
  this.metadata = parsed.metadata
76
83
  }
77
84
 
78
- console.log('✅ BrowserUTXOManager: Loaded ' + this.utxos.size + ' UTXOs from ' + this.options.storage + ' storage')
85
+ debug('✅ BrowserUTXOManager: Loaded ' + this.utxos.size + ' UTXOs from ' + this.options.storage + ' storage')
79
86
  } catch (e) {
80
87
  console.error('Failed to load UTXOs from storage:', e)
81
88
  }
@@ -96,7 +103,7 @@ BrowserUTXOManager.prototype.saveToStorage = function() {
96
103
  }
97
104
 
98
105
  storage.setItem(this.options.storageKey, JSON.stringify(data))
99
- console.log('💾 BrowserUTXOManager: Saved ' + this.utxos.size + ' UTXOs to ' + this.options.storage + ' storage')
106
+ debug('💾 BrowserUTXOManager: Saved ' + this.utxos.size + ' UTXOs to ' + this.options.storage + ' storage')
100
107
  } catch (e) {
101
108
  console.error('Failed to save UTXOs to storage:', e)
102
109
  }
@@ -110,7 +117,7 @@ BrowserUTXOManager.prototype.addUTXO = function(utxo) {
110
117
  var key = utxo.txid + ':' + utxo.vout
111
118
 
112
119
  if (this.utxos.has(key)) {
113
- console.log('⚠️ UTXO already exists: ' + key)
120
+ debug('⚠️ UTXO already exists: ' + key)
114
121
  return false
115
122
  }
116
123
 
@@ -298,7 +305,7 @@ BrowserUTXOManager.prototype.importData = function(jsonData, merge) {
298
305
  })
299
306
  }
300
307
 
301
- console.log('✅ BrowserUTXOManager: Imported ' + (data.utxos && data.utxos.length || 0) + ' UTXOs')
308
+ debug('✅ BrowserUTXOManager: Imported ' + (data.utxos && data.utxos.length || 0) + ' UTXOs')
302
309
  return true
303
310
  } catch (e) {
304
311
  console.error('Failed to import UTXO data:', e)
@@ -5,6 +5,13 @@
5
5
  * Lightweight UTXO management for browser environments with configurable storage
6
6
  */
7
7
 
8
+ // Set window.BSV_DEBUG = true (browser) or BSV_DEBUG=1 (Node) to enable info logs.
9
+ var debug = function () {
10
+ var enabled = (typeof process !== 'undefined' && process.env && process.env.BSV_DEBUG) ||
11
+ (typeof window !== 'undefined' && window.BSV_DEBUG)
12
+ if (enabled) console.log.apply(console, arguments)
13
+ }
14
+
8
15
  /**
9
16
  * Storage types available for browser UTXO management
10
17
  */
@@ -127,7 +134,7 @@ function BrowserUTXOManager(options) {
127
134
  }
128
135
 
129
136
  this._updateMetadata()
130
- console.log(`✅ BrowserUTXOManager: Loaded ${this.utxos.size} UTXOs from ${this.options.storage} storage`)
137
+ debug(`✅ BrowserUTXOManager: Loaded ${this.utxos.size} UTXOs from ${this.options.storage} storage`)
131
138
 
132
139
  } catch (error) {
133
140
  console.error('BrowserUTXOManager: Error loading from storage:', error.message)
@@ -163,7 +170,7 @@ function BrowserUTXOManager(options) {
163
170
  })
164
171
 
165
172
  storage.setItem(this.options.storageKey, JSON.stringify(data))
166
- console.log(`💾 BrowserUTXOManager: Saved ${this.utxos.size} UTXOs to ${this.options.storage} storage`)
173
+ debug(`💾 BrowserUTXOManager: Saved ${this.utxos.size} UTXOs to ${this.options.storage} storage`)
167
174
 
168
175
  } catch (error) {
169
176
  console.error('BrowserUTXOManager: Error saving to storage:', error.message)
@@ -186,7 +193,7 @@ function BrowserUTXOManager(options) {
186
193
 
187
194
  // Check if already exists
188
195
  if (this.utxos.has(key)) {
189
- console.log(`⚠️ UTXO already exists: ${key}`)
196
+ debug(`⚠️ UTXO already exists: ${key}`)
190
197
  return false
191
198
  }
192
199
 
@@ -217,7 +224,7 @@ function BrowserUTXOManager(options) {
217
224
  this.saveToStorage()
218
225
  }
219
226
 
220
- console.log(`✅ UTXO added: ${key} (${utxo.satoshis} sats)`)
227
+ debug(`✅ UTXO added: ${key} (${utxo.satoshis} sats)`)
221
228
  return true
222
229
 
223
230
  } catch (error) {
@@ -305,7 +312,7 @@ function BrowserUTXOManager(options) {
305
312
  }
306
313
  }
307
314
 
308
- console.log(`❌ UTXO spent: ${key} in ${spentUTXO.spentInTx}`)
315
+ debug(`❌ UTXO spent: ${key} in ${spentUTXO.spentInTx}`)
309
316
  })
310
317
 
311
318
  this._updateMetadata()
@@ -446,11 +453,11 @@ function BrowserUTXOManager(options) {
446
453
  const storage = this._getStorage()
447
454
  if (storage) {
448
455
  storage.removeItem(this.options.storageKey)
449
- console.log(`🔄 Cleared ${this.options.storage} storage`)
456
+ debug(`🔄 Cleared ${this.options.storage} storage`)
450
457
  }
451
458
  }
452
459
 
453
- console.log('🔄 BrowserUTXOManager reset complete')
460
+ debug('🔄 BrowserUTXOManager reset complete')
454
461
  }
455
462
 
456
463
  /**
@@ -513,7 +520,7 @@ function BrowserUTXOManager(options) {
513
520
  this.saveToStorage()
514
521
  }
515
522
 
516
- console.log('✅ BrowserUTXOManager: Imported ' + (data.utxos && data.utxos.length || 0) + ' UTXOs')
523
+ debug('✅ BrowserUTXOManager: Imported ' + (data.utxos && data.utxos.length || 0) + ' UTXOs')
517
524
  return true
518
525
 
519
526
  } catch (error) {
package/lib/ltp/claim.js CHANGED
@@ -691,6 +691,7 @@ var ClaimValidator = {
691
691
  * @private
692
692
  */
693
693
  _generateBatchId: function() {
694
+ // Non-security: identifier collision avoidance only
694
695
  var data = 'batch_' + Date.now() + '_' + Math.random()
695
696
  return Hash.sha256(Buffer.from(data)).toString('hex').substring(0, 16)
696
697
  },
@@ -929,6 +929,7 @@ var ObligationToken = {
929
929
  * @private
930
930
  */
931
931
  _generateUUID: function() {
932
+ // Non-security: identifier collision avoidance only (not RFC 4122 v4 random)
932
933
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
933
934
  var r = Math.random() * 16 | 0
934
935
  var v = c === 'x' ? r : (r & 0x3 | 0x8)
@@ -552,6 +552,7 @@ var LTPRegistry = {
552
552
  * @private
553
553
  */
554
554
  _generateRegistryId: function() {
555
+ // Non-security: identifier collision avoidance only
555
556
  var data = 'reg_' + Date.now() + '_' + Math.random()
556
557
  return 'reg_' + Hash.sha256(Buffer.from(data)).toString('hex').substring(0, 16)
557
558
  },
@@ -685,6 +686,7 @@ var LTPRegistry = {
685
686
  * @private
686
687
  */
687
688
  _generateAuditId: function() {
689
+ // Non-security: identifier collision avoidance only
688
690
  var data = 'audit_' + Date.now() + '_' + Math.random()
689
691
  return 'audit_' + Hash.sha256(Buffer.from(data)).toString('hex').substring(0, 12)
690
692
  },
package/lib/ltp/right.js CHANGED
@@ -752,6 +752,7 @@ var RightToken = {
752
752
  * @private
753
753
  */
754
754
  _generateUUID: function() {
755
+ // Non-security: identifier collision avoidance only (not RFC 4122 v4 random)
755
756
  return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
756
757
  var r = Math.random() * 16 | 0
757
758
  var v = c === 'x' ? r : (r & 0x3 | 0x8)
@@ -577,7 +577,7 @@ Transaction.prototype._fromMultisigUtxo = function (utxo, pubkeys, threshold) {
577
577
  } else if (utxo.script.isScriptHashOut()) {
578
578
  Clazz = MultiSigScriptHashInput
579
579
  } else {
580
- throw new Error('@TODO')
580
+ throw new errors.Transaction.Input.UnsupportedScript(utxo.script.toString())
581
581
  }
582
582
  this.addInput(new Clazz({
583
583
  output: new Output({
package/lib/util/_.js CHANGED
@@ -1,5 +1,7 @@
1
1
  'use strict'
2
2
 
3
+ var Random = require('../crypto/random')
4
+
3
5
  var _ = {}
4
6
 
5
7
  _.isArray = t => Array.isArray(t)
@@ -28,10 +30,14 @@ _.values = o => Object.values(o)
28
30
  _.filter = (a, f) => a.filter(f)
29
31
  _.reduce = (a, f, s) => a.reduce(f, s)
30
32
  _.without = (a, n) => a.filter(t => t !== n)
33
+ // CSPRNG-backed Fisher-Yates. Output-order shuffling is a privacy primitive
34
+ // (Transaction.shuffleOutputs); a predictable PRNG defeats the purpose.
31
35
  _.shuffle = a => {
32
36
  const result = a.slice(0)
33
37
  for (let i = result.length - 1; i > 0; i--) {
34
- const j = Math.floor(Math.random() * (i + 1));
38
+ const buf = Random.getRandomBuffer(4)
39
+ const r = buf.readUInt32BE(0) / 0x100000000
40
+ const j = Math.floor(r * (i + 1));
35
41
  [result[i], result[j]] = [result[j], result[i]]
36
42
  }
37
43
  return result
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smartledger/bsv",
3
- "version": "3.4.0",
3
+ "version": "3.4.2",
4
4
  "description": "🚀 Complete Bitcoin SV development framework with legally-recognizable DID:web + W3C VC-JWT toolkit, Legal Token Protocol (LTP), Global Digital Attestation Framework (GDAF), StatusList2021 revocation, and 16 flexible loading options. Standards-based credentials with ES256/ES256K support, on-chain BSV anchoring, and comprehensive Bitcoin SV API. Perfect for legal tokens, verifiable credentials, DeFi, smart contracts, and secure Bitcoin applications.",
5
5
  "author": "SmartLedger Technology <hello@smartledger.technology> (https://smartledger.technology)",
6
6
  "homepage": "https://github.com/codenlighten/smartledger-bsv#readme",
@@ -62,7 +62,7 @@
62
62
  "test:browser": "echo 'Open tests/standalone-modules-test.html in browser for comprehensive testing'",
63
63
  "test:bundle": "echo 'Open tests/bundle-completeness-test.html in browser to verify bundle completeness'",
64
64
  "preimage:extract": "node examples/preimage/extract_preimage_bidirectional.js",
65
- "prepublishOnly": "NODE_OPTIONS=\"--openssl-legacy-provider\" npm run build"
65
+ "prepublishOnly": "NODE_OPTIONS=\"--openssl-legacy-provider\" npm run build-all"
66
66
  },
67
67
  "unpkg": "bsv.min.js",
68
68
  "jsdelivr": "bsv.min.js",
@@ -70,12 +70,13 @@
70
70
  "files": [
71
71
  "index.js",
72
72
  "lib/",
73
- "utilities/",
73
+ "utilities/*.js",
74
+ "utilities/README.md",
75
+ "utilities/wallet.json",
74
76
  "ecies/",
75
77
  "message/",
76
78
  "mnemonic/",
77
79
  "build/",
78
- "tests/",
79
80
  "*-entry.js",
80
81
  "bsv.min.js",
81
82
  "bsv.bundle.js",
@@ -89,14 +90,11 @@
89
90
  "bsv-covenant.min.js",
90
91
  "bsv-script-helper.min.js",
91
92
  "bsv-security.min.js",
93
+ "bsv-didweb.min.js",
94
+ "bsv-vcjwt.min.js",
95
+ "bsv-statuslist.min.js",
96
+ "bsv-anchor.min.js",
92
97
  "bsv.d.ts",
93
- "validation_test.js",
94
- "test_shamir.js",
95
- "shamir_demo.js",
96
- "complete_ltp_demo.js",
97
- "simple_demo.js",
98
- "architecture_demo.js",
99
- "test_standalone_shamir.html",
100
98
  "docs/",
101
99
  "demos/",
102
100
  "examples/",
@@ -1,131 +0,0 @@
1
- /**
2
- * Simple GDAF Demo
3
- *
4
- * Tests core GDAF functionality without async verification issues
5
- */
6
-
7
- const bsv = require('../index.js')
8
-
9
- console.log('🌐 SmartLedger BSV GDAF - Core Components Test')
10
- console.log('==============================================\n')
11
-
12
- // Initialize GDAF
13
- const gdaf = new bsv.GDAF()
14
-
15
- try {
16
- // 1. Create test identities
17
- console.log('🔑 Creating Test Identities')
18
- const issuerPrivateKey = new bsv.PrivateKey()
19
- const subjectPrivateKey = new bsv.PrivateKey()
20
-
21
- const issuerDID = gdaf.createDID(issuerPrivateKey.toPublicKey())
22
- const subjectDID = gdaf.createDID(subjectPrivateKey.toPublicKey())
23
-
24
- console.log('✅ Issuer DID:', issuerDID)
25
- console.log('✅ Subject DID:', subjectDID)
26
- console.log()
27
-
28
- // 2. Create credentials
29
- console.log('📝 Creating Credentials')
30
-
31
- const emailCredential = gdaf.createEmailCredential(
32
- issuerDID,
33
- subjectDID,
34
- 'user@example.com',
35
- issuerPrivateKey
36
- )
37
-
38
- const ageCredential = gdaf.createAgeCredential(
39
- issuerDID,
40
- subjectDID,
41
- 21,
42
- new Date('1995-06-15'),
43
- issuerPrivateKey
44
- )
45
-
46
- console.log('✅ Email credential created with proof')
47
- console.log('✅ Age credential created with proof')
48
- console.log()
49
-
50
- // 3. Schema validation
51
- console.log('🔍 Schema Validation')
52
-
53
- const emailValidation = gdaf.validateCredential(emailCredential, 'EmailVerifiedCredential')
54
- const ageValidation = gdaf.validateCredential(ageCredential, 'AgeVerifiedCredential')
55
-
56
- console.log('✅ Email validation:', emailValidation.valid ? 'PASSED' : 'FAILED')
57
- console.log('✅ Age validation:', ageValidation.valid ? 'PASSED' : 'FAILED')
58
- console.log()
59
-
60
- // 4. Zero-knowledge proofs
61
- console.log('🔒 Zero-Knowledge Proofs')
62
-
63
- const nonce = gdaf.generateNonce()
64
-
65
- // Selective disclosure proof
66
- const selectiveProof = gdaf.generateSelectiveProof(
67
- emailCredential,
68
- ['credentialSubject.verified'],
69
- nonce
70
- )
71
-
72
- console.log('✅ Selective disclosure proof generated')
73
- console.log(' - Proof type:', selectiveProof.type)
74
- console.log(' - Disclosed fields:', selectiveProof.disclosedFields.length)
75
- console.log(' - Merkle proofs:', selectiveProof.merkleProofs.length)
76
-
77
- // Age proof
78
- const ageProof = gdaf.generateAgeProof(ageCredential, 18, nonce)
79
-
80
- console.log('✅ Age proof generated')
81
- console.log(' - Minimum age:', ageProof.minimumAge)
82
- console.log(' - Meets requirement:', ageProof.meetsRequirement)
83
-
84
- // Verify age proof
85
- const ageProofVerification = gdaf.verifyAgeProof(ageProof, 18, issuerDID)
86
- console.log('✅ Age proof verification:', ageProofVerification ? 'PASSED' : 'FAILED')
87
- console.log()
88
-
89
- // 5. Available schemas
90
- console.log('📚 Available Schema Types')
91
- const allSchemas = gdaf.getAllSchemas()
92
- const schemaNames = Object.keys(allSchemas)
93
-
94
- console.log('✅ Schema count:', schemaNames.length)
95
- console.log('✅ Available types:', schemaNames.join(', '))
96
- console.log()
97
-
98
- // 6. Template generation
99
- console.log('📋 Template Generation')
100
-
101
- const emailTemplate = gdaf.createTemplate('EmailVerifiedCredential')
102
- const kycTemplate = gdaf.createTemplate('KYCVerifiedCredential')
103
-
104
- console.log('✅ Email template generated')
105
- console.log('✅ KYC template generated')
106
- console.log()
107
-
108
- // 7. Framework info
109
- console.log('ℹ️ Framework Information')
110
- const info = gdaf.getInfo()
111
- console.log('✅ Name:', info.name)
112
- console.log('✅ Version:', info.version)
113
- console.log('✅ Standards:', info.standards.length, 'standards supported')
114
- console.log('✅ Components:', Object.keys(info.components).length, 'components')
115
- console.log()
116
-
117
- console.log('🎉 GDAF Core Components Test: SUCCESS!')
118
- console.log('\n✅ All tested components are working correctly:')
119
- console.log(' ✓ DID Creation and Resolution')
120
- console.log(' ✓ Credential Creation and Signing')
121
- console.log(' ✓ Schema Validation')
122
- console.log(' ✓ Zero-Knowledge Proof Generation')
123
- console.log(' ✓ Age Proof Verification')
124
- console.log(' ✓ Template Generation')
125
- console.log(' ✓ Framework Information')
126
-
127
- } catch (error) {
128
- console.error('❌ GDAF Core Test failed:', error.message)
129
- console.error('Stack trace:', error.stack)
130
- process.exit(1)
131
- }