@smartledger/bsv 3.3.5 → 3.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/README.md +149 -20
  3. package/anchor-entry.js +1 -0
  4. package/bin/cli.js +349 -0
  5. package/bsv-anchor.min.js +12 -0
  6. package/bsv-covenant.min.js +8 -8
  7. package/bsv-didweb.min.js +12 -0
  8. package/bsv-gdaf.min.js +9 -9
  9. package/bsv-ltp.min.js +9 -9
  10. package/bsv-mnemonic.min.js +2 -2
  11. package/bsv-shamir.min.js +3 -3
  12. package/bsv-smartcontract.min.js +9 -9
  13. package/bsv-statuslist.min.js +18 -0
  14. package/bsv-vcjwt.min.js +12 -0
  15. package/bsv.bundle.js +9 -9
  16. package/bsv.min.js +8 -8
  17. package/build/webpack.anchor.config.js +17 -0
  18. package/build/webpack.didweb.config.js +17 -0
  19. package/build/webpack.statuslist.config.js +17 -0
  20. package/build/webpack.vcjwt.config.js +17 -0
  21. package/demos/browser-test.html +1 -1
  22. package/didweb-entry.js +1 -0
  23. package/docs/technical/roadmap.md +3 -3
  24. package/examples/legacy/README.md +11 -0
  25. package/index.js +39 -1
  26. package/lib/anchor/index.js +102 -0
  27. package/lib/browser-utxo-manager-es5.js +11 -4
  28. package/lib/browser-utxo-manager.js +15 -8
  29. package/lib/didweb/index.js +177 -0
  30. package/lib/ltp/claim.js +1 -0
  31. package/lib/ltp/obligation.js +1 -0
  32. package/lib/ltp/registry.js +2 -0
  33. package/lib/ltp/right.js +1 -0
  34. package/lib/statuslist/index.js +164 -0
  35. package/lib/transaction/transaction.js +1 -1
  36. package/lib/util/_.js +7 -1
  37. package/lib/vcjwt/index.js +189 -0
  38. package/package.json +19 -13
  39. package/statuslist-entry.js +1 -0
  40. package/vcjwt-entry.js +1 -0
  41. package/demos/gdaf_core_test.js +0 -131
  42. package/examples/scripts/custom_script_signature_test.js +0 -344
  43. package/tests/browser-compatibility/README.md +0 -35
  44. package/tests/browser-compatibility/test-cdn-vs-local.html +0 -186
  45. package/tests/browser-compatibility/test-pbkdf2.html +0 -51
  46. package/tests/bundle-completeness-test.html +0 -131
  47. package/tests/bundle-demo.html +0 -476
  48. package/tests/smartcontract-test.html +0 -239
  49. package/tests/standalone-modules-test.html +0 -260
  50. package/tests/test.html +0 -612
  51. package/tests/test_standalone_shamir.html +0 -83
  52. package/tests/unpkg-demo.html +0 -194
  53. package/utilities/blockchain-state.json +0 -118565
  54. /package/{lib/smart_contract/test_integration.js → examples/legacy/smart_contract_test_integration.js} +0 -0
  55. /package/{tests → examples/legacy}/test_builtin_verify.js +0 -0
  56. /package/{tests → examples/legacy}/test_debug_integration.js +0 -0
  57. /package/{tests → examples/legacy}/test_ecdsa_little.js +0 -0
  58. /package/{tests → examples/legacy}/test_shamir.js +0 -0
  59. /package/{tests → examples/legacy}/test_smartverify_der.js +0 -0
@@ -0,0 +1,17 @@
1
+ const path = require('path')
2
+
3
+ module.exports = {
4
+ entry: './anchor-entry.js',
5
+ mode: 'production',
6
+ optimization: {
7
+ minimize: true
8
+ },
9
+ output: {
10
+ path: path.resolve(__dirname, '../'),
11
+ filename: 'bsv-anchor.min.js',
12
+ library: 'bsvAnchor',
13
+ libraryTarget: 'umd',
14
+ globalObject: 'this'
15
+ },
16
+ target: 'web'
17
+ }
@@ -0,0 +1,17 @@
1
+ const path = require('path')
2
+
3
+ module.exports = {
4
+ entry: './didweb-entry.js',
5
+ mode: 'production',
6
+ optimization: {
7
+ minimize: true
8
+ },
9
+ output: {
10
+ path: path.resolve(__dirname, '../'),
11
+ filename: 'bsv-didweb.min.js',
12
+ library: 'bsvDIDWeb',
13
+ libraryTarget: 'umd',
14
+ globalObject: 'this'
15
+ },
16
+ target: 'web'
17
+ }
@@ -0,0 +1,17 @@
1
+ const path = require('path')
2
+
3
+ module.exports = {
4
+ entry: './statuslist-entry.js',
5
+ mode: 'production',
6
+ optimization: {
7
+ minimize: true
8
+ },
9
+ output: {
10
+ path: path.resolve(__dirname, '../'),
11
+ filename: 'bsv-statuslist.min.js',
12
+ library: 'bsvStatusList',
13
+ libraryTarget: 'umd',
14
+ globalObject: 'this'
15
+ },
16
+ target: 'web'
17
+ }
@@ -0,0 +1,17 @@
1
+ const path = require('path')
2
+
3
+ module.exports = {
4
+ entry: './vcjwt-entry.js',
5
+ mode: 'production',
6
+ optimization: {
7
+ minimize: true
8
+ },
9
+ output: {
10
+ path: path.resolve(__dirname, '../'),
11
+ filename: 'bsv-vcjwt.min.js',
12
+ library: 'bsvVcJwt',
13
+ libraryTarget: 'umd',
14
+ globalObject: 'this'
15
+ },
16
+ target: 'web'
17
+ }
@@ -182,7 +182,7 @@
182
182
  </div>
183
183
 
184
184
  <!-- Load SmartLedger-BSV from CDN -->
185
- <script src="https://unpkg.com/smartledger-bsv@3.3.4/bsv.bundle.js"></script>
185
+ <script src="https://unpkg.com/smartledger-bsv@3.3.5/bsv.bundle.js"></script>
186
186
 
187
187
  <script>
188
188
  let bsv;
@@ -0,0 +1 @@
1
+ module.exports = require('./lib/didweb')
@@ -606,11 +606,11 @@ Provides hardened Bitcoin SV primitives + SmartLedger security modules.
606
606
 
607
607
  - **GitHub Repository** - https://github.com/codenlighten/smartledger-bsv🔒 *“Verified cryptographic fabric + transaction interpreter.”*
608
608
 
609
- - **Developer Documentation** - https://docs.smartledger.io
609
+ - **Developer Documentation** - https://docs.smartledger.technology
610
610
 
611
611
  - **Community Discord** - https://discord.gg/smartledger---
612
612
 
613
- - **Standards Working Group** - https://standards.smartledger.io
613
+ - **Standards Working Group** - https://standards.smartledger.technology
614
614
 
615
615
  ## 2️⃣ Identity Layer: GDAF (Global Digital Attestation Framework)
616
616
 
@@ -903,7 +903,7 @@ SmartLedger-BSV/
903
903
 
904
904
  ### 🔹 **Minified CDN Build**
905
905
 
906
- `https://cdn.smartledger.io/smartledger-bsv.min.js`
906
+ `https://cdn.smartledger.technology/smartledger-bsv.min.js`
907
907
  Provides browser-side access to the same hardened primitives used in Node:
908
908
 
909
909
  ```js
@@ -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
@@ -119,7 +119,9 @@ try {
119
119
  try {
120
120
  bsv.BrowserUTXOManager = require('./lib/browser-utxo-manager-es5')
121
121
  } catch (e) {
122
- // BrowserUTXOManager not available
122
+ if (typeof window === 'undefined') {
123
+ console.warn('[bsv] BrowserUTXOManager failed to load:', e.message)
124
+ }
123
125
  }
124
126
 
125
127
  // Node.js specific tools (advanced development tools)
@@ -136,6 +138,42 @@ if (typeof window === 'undefined' && typeof require === 'function') {
136
138
  // Global Digital Attestation Framework (GDAF)
137
139
  bsv.GDAF = require('./lib/gdaf')
138
140
 
141
+ // DID:web Module (W3C standards-based DIDs)
142
+ try {
143
+ bsv.DIDWeb = require('./lib/didweb')
144
+ } catch (e) {
145
+ if (typeof window === 'undefined') {
146
+ console.warn('[bsv] DIDWeb module failed to load:', e.message)
147
+ }
148
+ }
149
+
150
+ // VC-JWT Module (W3C Verifiable Credentials)
151
+ try {
152
+ bsv.VcJwt = require('./lib/vcjwt')
153
+ } catch (e) {
154
+ if (typeof window === 'undefined') {
155
+ console.warn('[bsv] VcJwt module failed to load:', e.message)
156
+ }
157
+ }
158
+
159
+ // StatusList2021 Module (Credential revocation)
160
+ try {
161
+ bsv.StatusList = require('./lib/statuslist')
162
+ } catch (e) {
163
+ if (typeof window === 'undefined') {
164
+ console.warn('[bsv] StatusList module failed to load:', e.message)
165
+ }
166
+ }
167
+
168
+ // Anchor Module (BSV hash anchoring)
169
+ try {
170
+ bsv.Anchor = require('./lib/anchor')
171
+ } catch (e) {
172
+ if (typeof window === 'undefined') {
173
+ console.warn('[bsv] Anchor module failed to load:', e.message)
174
+ }
175
+ }
176
+
139
177
  // GDAF Direct Access Methods (for easier developer experience)
140
178
  bsv.createDID = function(publicKey) {
141
179
  var gdaf = new bsv.GDAF()
@@ -0,0 +1,102 @@
1
+ 'use strict'
2
+
3
+ /**
4
+ * BSV Anchor Module
5
+ * Hash anchoring helpers for on-chain evidence (no PII)
6
+ */
7
+
8
+ var crypto = require('crypto')
9
+
10
+ // SHA-256 hex hash
11
+ function sha256Hex(data) {
12
+ var buffer
13
+ if (typeof data === 'string') {
14
+ buffer = Buffer.from(data, 'utf8')
15
+ } else if (Buffer.isBuffer(data)) {
16
+ buffer = data
17
+ } else if (data instanceof Uint8Array) {
18
+ buffer = Buffer.from(data)
19
+ } else {
20
+ throw new Error('Data must be string, Buffer, or Uint8Array')
21
+ }
22
+
23
+ return crypto.createHash('sha256').update(buffer).digest('hex')
24
+ }
25
+
26
+ // Build anchor payload for OP_RETURN
27
+ function buildAnchorPayload(params) {
28
+ if (!params.kind || !params.hash || !params.issuerDid) {
29
+ throw new Error('kind, hash, and issuerDid are required')
30
+ }
31
+
32
+ var validKinds = ['VC_ANCHOR_SHA256', 'STATUSLIST_SHA256', 'PRESENTATION_SHA256']
33
+ if (validKinds.indexOf(params.kind) === -1) {
34
+ throw new Error('Invalid kind. Must be one of: ' + validKinds.join(', '))
35
+ }
36
+
37
+ // Validate hash format (64 hex characters)
38
+ if (!/^[a-fA-F0-9]{64}$/.test(params.hash)) {
39
+ throw new Error('Invalid hash format. Must be 64 hex characters')
40
+ }
41
+
42
+ var payload = {
43
+ protocol: 'SmartLedger',
44
+ version: '1.0',
45
+ type: params.kind,
46
+ hash: params.hash,
47
+ issuer: params.issuerDid,
48
+ timestamp: params.issuedAt || new Date().toISOString()
49
+ }
50
+
51
+ return {
52
+ json: JSON.stringify(payload)
53
+ }
54
+ }
55
+
56
+ // Verify anchor hash against original data
57
+ function verifyAnchorHash(originalData, anchorHash) {
58
+ var computed = sha256Hex(originalData)
59
+ return computed === anchorHash
60
+ }
61
+
62
+ // Extract anchor info from OP_RETURN data
63
+ function parseAnchorPayload(opReturnData) {
64
+ try {
65
+ var parsed = JSON.parse(opReturnData)
66
+
67
+ if (parsed.protocol !== 'SmartLedger') {
68
+ return { valid: false, error: 'Invalid protocol' }
69
+ }
70
+
71
+ var validTypes = ['VC_ANCHOR_SHA256', 'STATUSLIST_SHA256', 'PRESENTATION_SHA256']
72
+ if (validTypes.indexOf(parsed.type) === -1) {
73
+ return { valid: false, error: 'Invalid anchor type' }
74
+ }
75
+
76
+ if (!/^[a-fA-F0-9]{64}$/.test(parsed.hash)) {
77
+ return { valid: false, error: 'Invalid hash format' }
78
+ }
79
+
80
+ return {
81
+ valid: true,
82
+ protocol: parsed.protocol,
83
+ version: parsed.version,
84
+ type: parsed.type,
85
+ hash: parsed.hash,
86
+ issuer: parsed.issuer,
87
+ timestamp: parsed.timestamp
88
+ }
89
+ } catch (error) {
90
+ return {
91
+ valid: false,
92
+ error: 'Failed to parse anchor payload: ' + error.message
93
+ }
94
+ }
95
+ }
96
+
97
+ module.exports = {
98
+ sha256Hex: sha256Hex,
99
+ buildAnchorPayload: buildAnchorPayload,
100
+ verifyAnchorHash: verifyAnchorHash,
101
+ parseAnchorPayload: parseAnchorPayload
102
+ }
@@ -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) {
@@ -0,0 +1,177 @@
1
+ 'use strict'
2
+
3
+ /**
4
+ * DID:web Module
5
+ * Legally-recognizable DID (did:web) generation and management
6
+ * Supports ES256 (P-256) and ES256K (secp256k1) keys
7
+ */
8
+
9
+ var crypto = require('crypto')
10
+
11
+ // Generate issuer keys (ES256 or ES256K)
12
+ async function generateIssuerKeys(opts) {
13
+ opts = opts || {}
14
+ var alg = opts.alg || 'ES256'
15
+ var kid = opts.kid || 'key-' + Date.now()
16
+
17
+ if (alg !== 'ES256' && alg !== 'ES256K') {
18
+ throw new Error('Invalid algorithm. Must be ES256 or ES256K')
19
+ }
20
+
21
+ var keyPair
22
+ if (alg === 'ES256') {
23
+ // P-256 (NIST curve)
24
+ keyPair = crypto.generateKeyPairSync('ec', {
25
+ namedCurve: 'P-256',
26
+ publicKeyEncoding: { type: 'spki', format: 'pem' },
27
+ privateKeyEncoding: { type: 'pkcs8', format: 'pem' }
28
+ })
29
+ } else {
30
+ // secp256k1
31
+ keyPair = crypto.generateKeyPairSync('ec', {
32
+ namedCurve: 'secp256k1',
33
+ publicKeyEncoding: { type: 'spki', format: 'pem' },
34
+ privateKeyEncoding: { type: 'pkcs8', format: 'pem' }
35
+ })
36
+ }
37
+
38
+ // Convert to JWK format
39
+ var publicJwk = crypto.createPublicKey(keyPair.publicKey).export({ format: 'jwk' })
40
+ var privateJwk = crypto.createPrivateKey(keyPair.privateKey).export({ format: 'jwk' })
41
+
42
+ // Add required JWK fields
43
+ publicJwk.kid = kid
44
+ publicJwk.alg = alg
45
+ publicJwk.use = 'sig'
46
+ publicJwk.kty = 'EC'
47
+
48
+ privateJwk.kid = kid
49
+ privateJwk.alg = alg
50
+ privateJwk.use = 'sig'
51
+ privateJwk.kty = 'EC'
52
+
53
+ return {
54
+ privateJwk: privateJwk,
55
+ publicJwk: publicJwk,
56
+ kid: kid,
57
+ alg: alg
58
+ }
59
+ }
60
+
61
+ // Build did:web documents (did.json and jwks.json)
62
+ function buildDidWebDocuments(params) {
63
+ if (!params.domain) {
64
+ throw new Error('domain is required')
65
+ }
66
+
67
+ var domain = params.domain
68
+ var did = 'did:web:' + domain.replace(/:/g, '%3A')
69
+
70
+ var verificationMethods = []
71
+ var publicKeys = []
72
+
73
+ // Add P-256 key if provided
74
+ if (params.p256) {
75
+ var p256Method = {
76
+ id: did + '#' + params.p256.kid,
77
+ type: 'JsonWebKey2020',
78
+ controller: did,
79
+ publicKeyJwk: params.p256.jwk
80
+ }
81
+ verificationMethods.push(p256Method)
82
+ publicKeys.push(params.p256.jwk)
83
+ }
84
+
85
+ // Add secp256k1 key if provided
86
+ if (params.k1) {
87
+ var k1Method = {
88
+ id: did + '#' + params.k1.kid,
89
+ type: 'JsonWebKey2020',
90
+ controller: did,
91
+ publicKeyJwk: params.k1.jwk
92
+ }
93
+ verificationMethods.push(k1Method)
94
+ publicKeys.push(params.k1.jwk)
95
+ }
96
+
97
+ if (verificationMethods.length === 0) {
98
+ throw new Error('At least one key (p256 or k1) must be provided')
99
+ }
100
+
101
+ // Build DID Document
102
+ var didDocument = {
103
+ '@context': [
104
+ 'https://www.w3.org/ns/did/v1',
105
+ 'https://w3id.org/security/suites/jws-2020/v1'
106
+ ],
107
+ id: did,
108
+ verificationMethod: verificationMethods,
109
+ authentication: verificationMethods.map(function(vm) { return vm.id }),
110
+ assertionMethod: verificationMethods.map(function(vm) { return vm.id })
111
+ }
112
+
113
+ if (params.controllerName) {
114
+ didDocument.controller = params.controllerName
115
+ }
116
+
117
+ // Build JWKS
118
+ var jwks = {
119
+ keys: publicKeys
120
+ }
121
+
122
+ return {
123
+ did: did,
124
+ didDocument: didDocument,
125
+ jwks: jwks
126
+ }
127
+ }
128
+
129
+ // Rotate issuer key
130
+ function rotateIssuerKey(params) {
131
+ if (!params.domain || !params.newKey) {
132
+ throw new Error('domain and newKey are required')
133
+ }
134
+
135
+ var domain = params.domain
136
+ var did = 'did:web:' + domain.replace(/:/g, '%3A')
137
+ var keepOldForDays = params.keepOldForDays || 30
138
+
139
+ // Create verification method for new key
140
+ var newMethod = {
141
+ id: did + '#' + params.newKey.kid,
142
+ type: 'JsonWebKey2020',
143
+ controller: did,
144
+ publicKeyJwk: params.newKey.jwk
145
+ }
146
+
147
+ // Build updated DID Document with new key as primary
148
+ var didDocument = {
149
+ '@context': [
150
+ 'https://www.w3.org/ns/did/v1',
151
+ 'https://w3id.org/security/suites/jws-2020/v1'
152
+ ],
153
+ id: did,
154
+ verificationMethod: [newMethod],
155
+ authentication: [newMethod.id],
156
+ assertionMethod: [newMethod.id],
157
+ rotationInfo: {
158
+ rotatedAt: new Date().toISOString(),
159
+ gracePeriodDays: keepOldForDays
160
+ }
161
+ }
162
+
163
+ var jwks = {
164
+ keys: [params.newKey.jwk]
165
+ }
166
+
167
+ return {
168
+ didDocument: didDocument,
169
+ jwks: jwks
170
+ }
171
+ }
172
+
173
+ module.exports = {
174
+ generateIssuerKeys: generateIssuerKeys,
175
+ buildDidWebDocuments: buildDidWebDocuments,
176
+ rotateIssuerKey: rotateIssuerKey
177
+ }
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)