@smartledger/bsv 3.4.3 → 3.4.5

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 (89) hide show
  1. package/CHANGELOG.md +367 -0
  2. package/README.md +72 -72
  3. package/SECURITY.md +88 -0
  4. package/bin/cli.js +13 -8
  5. package/bsv-covenant.min.js +4 -4
  6. package/bsv-gdaf.min.js +5 -5
  7. package/bsv-ltp.min.js +7 -7
  8. package/bsv-smartcontract.min.js +5 -5
  9. package/bsv.bundle.js +5 -5
  10. package/bsv.d.ts +486 -9
  11. package/bsv.min.js +5 -5
  12. package/docs/COVENANT_DEVELOPMENT_RESOLVED.md +2 -2
  13. package/docs/MODULE_REFERENCE_COMPLETE.md +60 -57
  14. package/docs/advanced/UTXO_MANAGER_GUIDE.md +1 -1
  15. package/docs/getting-started/INSTALLATION.md +30 -30
  16. package/docs/getting-started/QUICK_START.md +14 -14
  17. package/docs/migration/FROM_BSV_1_5_6.md +5 -5
  18. package/gdaf-entry.js +1 -2
  19. package/index.js +20 -7
  20. package/lib/script/script.js +19 -0
  21. package/lib/smart_contract/covenant.js +10 -1
  22. package/lib/smartutxo.js +20 -12
  23. package/lib/transaction/input/publickeyhash.js +6 -1
  24. package/lib/transaction/transaction.js +12 -1
  25. package/ltp-entry.js +1 -2
  26. package/package.json +3 -3
  27. package/utilities/blockchain-state.js +32 -23
  28. package/demos/README.md +0 -188
  29. package/demos/architecture_demo.js +0 -247
  30. package/demos/browser-test.html +0 -1208
  31. package/demos/bsv_wallet_demo.js +0 -242
  32. package/demos/complete_ltp_demo.js +0 -511
  33. package/demos/debug_tools_demo.js +0 -87
  34. package/demos/demo_features.js +0 -123
  35. package/demos/easy_interface_demo.js +0 -109
  36. package/demos/ecies_demo.js +0 -182
  37. package/demos/gdaf_demo.js +0 -237
  38. package/demos/ltp_demo.js +0 -361
  39. package/demos/ltp_primitives_demo.js +0 -403
  40. package/demos/message_demo.js +0 -209
  41. package/demos/preimage_separation_demo.js +0 -383
  42. package/demos/script_helper_demo.js +0 -289
  43. package/demos/security_demo.js +0 -287
  44. package/demos/shamir_demo.js +0 -121
  45. package/demos/simple_demo.js +0 -204
  46. package/demos/simple_p2pkh_demo.js +0 -169
  47. package/demos/simple_utxo_preimage_demo.js +0 -196
  48. package/demos/smart_contract_demo.html +0 -1347
  49. package/demos/smart_contract_demo.js +0 -910
  50. package/demos/utxo_generator_demo.js +0 -244
  51. package/demos/validation_pipeline_demo.js +0 -155
  52. package/demos/web3keys.html +0 -740
  53. package/examples/README.md +0 -200
  54. package/examples/basic/transaction-creation.js +0 -534
  55. package/examples/basic/transaction_signature_api_gap.js +0 -178
  56. package/examples/complete_workflow_demo.js +0 -783
  57. package/examples/covenants/advanced_covenant_demo.js +0 -219
  58. package/examples/covenants/covenant_interface_demo.js +0 -270
  59. package/examples/covenants/covenant_manual_signature_resolved.js +0 -212
  60. package/examples/covenants/covenant_signature_template.js +0 -117
  61. package/examples/covenants2/covenant_bidirectional_example.js +0 -262
  62. package/examples/covenants2/covenant_utils_demo.js +0 -120
  63. package/examples/covenants2/preimage_covenant_utils.js +0 -287
  64. package/examples/covenants2/production_integration.js +0 -256
  65. package/examples/data/covenant_utxos.json +0 -28
  66. package/examples/data/utxos.json +0 -26
  67. package/examples/definitive_working_demo.js +0 -261
  68. package/examples/final_working_contracts.js +0 -338
  69. package/examples/legacy/README.md +0 -11
  70. package/examples/legacy/smart_contract_test_integration.js +0 -269
  71. package/examples/legacy/test_builtin_verify.js +0 -117
  72. package/examples/legacy/test_debug_integration.js +0 -71
  73. package/examples/legacy/test_ecdsa_little.js +0 -70
  74. package/examples/legacy/test_shamir.js +0 -221
  75. package/examples/legacy/test_smartverify_der.js +0 -110
  76. package/examples/preimage/README.md +0 -178
  77. package/examples/preimage/extract_preimage_bidirectional.js +0 -421
  78. package/examples/preimage/generate_sample_preimage.js +0 -208
  79. package/examples/preimage/generate_sighash_examples.js +0 -152
  80. package/examples/preimage/parse_preimage.js +0 -117
  81. package/examples/preimage/test_preimage_extractor.js +0 -53
  82. package/examples/preimage/test_varint_extraction.js +0 -95
  83. package/examples/scripts/custom_script_helper_example.js +0 -273
  84. package/examples/scripts/script_interpreter.js +0 -193
  85. package/examples/smart_contract/complete_workflow_demo.js +0 -343
  86. package/examples/smart_contract/covenant_builder_demo.js +0 -176
  87. package/examples/smart_contract/script_testing_integration.js +0 -198
  88. package/examples/smart_contract_templates.js +0 -718
  89. package/examples/working_smart_contracts.js +0 -348
package/demos/ltp_demo.js DELETED
@@ -1,361 +0,0 @@
1
- // Legal Token Protocol (LTP) Demo
2
- // Demonstrates the creation, validation, and management of legal tokens
3
-
4
- var bsv = require('../index.js')
5
-
6
- console.log('=== Legal Token Protocol (LTP) Demo ===\n')
7
-
8
- // Test 1: Create Property Right Token
9
- console.log('1. Creating Property Right Token...')
10
-
11
- var ownerKey = new bsv.PrivateKey()
12
- var propertyData = {
13
- type: 'PropertyTitle',
14
- owner: 'did:smartledger:' + ownerKey.toPublicKey().toString(),
15
- jurisdiction: 'US-CA',
16
- property: {
17
- address: '123 Main St, San Francisco, CA 94105',
18
- parcelId: 'APN-12345678',
19
- coordinates: {
20
- lat: 37.7749,
21
- lng: -122.4194
22
- },
23
- area: {
24
- value: 1000,
25
- unit: 'sqft'
26
- }
27
- },
28
- value: {
29
- amount: 850000,
30
- currency: 'USD'
31
- },
32
- legalDescription: 'Lot 1, Block 2, Map 3456, City of San Francisco',
33
- restrictions: ['zoning:residential', 'height:35ft'],
34
- issuanceDate: new Date().toISOString(),
35
- expirationDate: new Date(Date.now() + 365 * 24 * 60 * 60 * 1000).toISOString() // 1 year
36
- }
37
-
38
- try {
39
- // Use LTP primitives for claim validation instead
40
- const claimHash = bsv.hashClaim(propertyData)
41
- const canonicalClaim = bsv.canonicalizeClaim(propertyData)
42
-
43
- console.log('✓ Property claim processed successfully')
44
- console.log(' Claim Hash:', claimHash)
45
- console.log(' Property Type:', propertyData.type)
46
- console.log(' Property ID:', propertyData.propertyId)
47
- console.log(' Owner Key:', ownerKey.toAddress().toString())
48
-
49
- var propertyToken = { success: true, token: { hash: claimHash, data: canonicalClaim } }
50
- } catch (e) {
51
- console.log('✗ Failed to create property token:', e.message)
52
- var propertyToken = { success: false, error: e.message }
53
- }
54
-
55
- console.log()
56
-
57
- // Test 2: Verify Token
58
- console.log('2. Verifying Property Token...')
59
-
60
- if (propertyToken.success) {
61
- console.log('✓ Token verification completed')
62
- console.log(' Public Key:', ownerKey.toPublicKey().toString())
63
- console.log(' Token Hash:', propertyToken.token.hash)
64
- console.log(' Owner Address:', ownerKey.toAddress().toString())
65
- } else {
66
- console.log('✗ Token verification failed:', propertyToken.error)
67
- }
68
-
69
- console.log()
70
-
71
- // Test 3: Create Vehicle Title Token
72
- console.log('3. Creating Vehicle Title Token...')
73
-
74
- var vehicleOwnerKey = new bsv.PrivateKey()
75
- var vehicleData = {
76
- type: 'VehicleTitle',
77
- owner: 'did:smartledger:' + vehicleOwnerKey.toPublicKey().toString(),
78
- jurisdiction: 'US-TX',
79
- vehicle: {
80
- vin: '1HGBH41JXMN109186',
81
- make: 'Tesla',
82
- model: 'Model S',
83
- year: 2023,
84
- color: 'Pearl White',
85
- mileage: 5000
86
- },
87
- value: {
88
- amount: 95000,
89
- currency: 'USD'
90
- },
91
- registrationNumber: 'TX-ABC-1234',
92
- issuanceDate: new Date().toISOString()
93
- }
94
-
95
- try {
96
- // Use LTP primitives for vehicle claim
97
- const vehicleClaimHash = bsv.hashClaim(vehicleData)
98
- const vehicleCanonicalClaim = bsv.canonicalizeClaim(vehicleData)
99
-
100
- console.log('✓ Vehicle claim processed successfully')
101
- console.log(' Claim Hash:', vehicleClaimHash)
102
- console.log(' VIN:', vehicleData.vehicle.vin)
103
- console.log(' Registration:', vehicleData.registrationNumber)
104
-
105
- var vehicleToken = { success: true, token: { hash: vehicleClaimHash, data: vehicleCanonicalClaim } }
106
- } catch (e) {
107
- console.log('✗ Failed to create vehicle token:', e.message)
108
- var vehicleToken = { success: false, error: e.message }
109
- }
110
-
111
- console.log()
112
-
113
- // Test 4: Transfer Property Right
114
- console.log('4. Transferring Property Right...')
115
-
116
- var newOwnerKey = new bsv.PrivateKey()
117
- var newOwnerDID = 'did:smartledger:' + newOwnerKey.toPublicKey().toString()
118
-
119
- // Simulate transfer using LTP primitives
120
- if (propertyToken.success) {
121
- console.log('✓ Property transfer prepared successfully')
122
- console.log(' Original Owner:', ownerKey.toAddress().toString())
123
- console.log(' New Owner DID:', newOwnerDID)
124
- console.log(' Transfer Reason: Sale')
125
- console.log(' Consideration: $875,000 USD')
126
-
127
- var transfer = { success: true, transferId: 'transfer_' + Date.now() }
128
- } else {
129
- console.log('✗ Transfer failed: Token not available')
130
- var transfer = { success: false, error: 'Token not available' }
131
- }
132
-
133
- console.log()
134
-
135
- // Test 5: Create Obligation from Right
136
- console.log('5. Creating Obligation from Property Right...')
137
-
138
- var obligationData = {
139
- obligationType: 'PropertyTax',
140
- obligor: newOwnerDID, // New owner is obligated
141
- obligee: 'City of San Francisco',
142
- jurisdiction: 'US-CA',
143
- description: 'Annual property tax payment obligation',
144
- amount: {
145
- value: 10200, // $10,200 annual property tax
146
- currency: 'USD'
147
- },
148
- dueDate: new Date(Date.now() + 365 * 24 * 60 * 60 * 1000).toISOString(), // Due in 1 year
149
- recurrence: 'ANNUAL',
150
- penalties: {
151
- lateFeePct: 0.015, // 1.5% monthly late fee
152
- maxLateFee: 5000
153
- }
154
- }
155
-
156
- // Simulate obligation creation using LTP primitives
157
- try {
158
- const obligationHash = bsv.hashClaim(obligationData)
159
-
160
- console.log('✓ Tax obligation created successfully')
161
- console.log(' Obligation Hash:', obligationHash)
162
- console.log(' Obligor:', obligationData.obligor)
163
- console.log(' Obligee:', obligationData.obligee)
164
- console.log(' Amount:', obligationData.amount.value, obligationData.amount.currency)
165
- console.log(' Due Date:', obligationData.dueDate)
166
-
167
- var obligation = { success: true, hash: obligationHash }
168
- } catch (e) {
169
- console.log('✗ Obligation creation failed:', e.message)
170
- var obligation = { success: false, error: e.message }
171
- }
172
-
173
- console.log()
174
-
175
- // Test 6: Validate Legal Claims
176
- console.log('6. Validating Legal Claims...')
177
-
178
- var propertyClaimData = {
179
- propertyId: 'APN-87654321',
180
- address: {
181
- street: '456 Oak Street',
182
- city: 'Los Angeles',
183
- state: 'CA',
184
- zipCode: '90210',
185
- country: 'US'
186
- },
187
- ownershipType: 'fee_simple',
188
- owner: {
189
- name: 'John Doe',
190
- ssn: '***-**-1234' // Masked for privacy
191
- },
192
- legalDescription: 'Lot 5, Block 10, Tract 5000',
193
- recordedDate: '2023-01-15T10:30:00Z',
194
- grantorGrantee: {
195
- grantor: 'Jane Smith',
196
- grantee: 'John Doe'
197
- }
198
- }
199
-
200
- // Use working LTP validation methods
201
- try {
202
- const availableSchemas = bsv.getClaimSchemaNames()
203
- const template = bsv.createClaimTemplate('PropertyTitle')
204
-
205
- console.log('✓ Property claim is valid')
206
- console.log(' Schema type: PropertyTitle')
207
- console.log(' Available schemas:', availableSchemas.length)
208
- console.log(' Template fields:', Object.keys(template).join(', '))
209
-
210
- var claimValidation = { valid: true }
211
- } catch (e) {
212
- console.log('✗ Property claim validation failed:', e.message)
213
- var claimValidation = { valid: false, errors: [e.message] }
214
- }
215
-
216
- console.log()
217
-
218
- // Test 7: Create Selective Disclosure Proof
219
- console.log('7. Creating Selective Disclosure Proof...')
220
-
221
- var revealedFields = [
222
- 'type',
223
- 'jurisdiction',
224
- 'property.address',
225
- 'property.area',
226
- 'issuanceDate'
227
- ]
228
-
229
- var nonce = 'demo-nonce-' + Date.now()
230
-
231
- // Simulate selective disclosure
232
- console.log('✓ Selective disclosure proof created')
233
- console.log(' Proof type: ZKP-selective-disclosure')
234
- console.log(' Revealed fields:', revealedFields.join(', '))
235
- console.log(' Nonce:', nonce)
236
-
237
- var disclosureProof = { success: true }
238
- console.log(' Disclosed fields:', revealedFields.length)
239
- console.log(' Total fields: 12')
240
- console.log(' Merkle root: 0x' + Math.random().toString(16).substr(2, 64))
241
-
242
- // Show disclosed values
243
- console.log(' Disclosed values:')
244
- console.log(' property.address: 123 Elm Street')
245
- console.log(' property.area: 2500 sq ft')
246
- console.log(' issuanceDate: 2023-10-28')
247
-
248
- console.log()
249
-
250
- // Test 8: Legal Registry Operations
251
- console.log('8. Testing Legal Registry Operations...')
252
-
253
- var registryConfig = {
254
- id: 'demo-registry-' + Date.now(),
255
- name: 'California Property Registry',
256
- jurisdiction: 'US-CA',
257
- authority: 'California Department of Real Estate',
258
- allowPublicRegistration: false,
259
- requireApproval: true,
260
- enableRevocation: true,
261
- enableAuditTrail: true
262
- }
263
-
264
- // Simulate registry creation
265
- var registry = {
266
- id: 'registry_' + Date.now(),
267
- jurisdiction: registryConfig.jurisdiction,
268
- authority: registryConfig.authority
269
- }
270
-
271
- console.log('✓ Legal registry created')
272
- console.log(' Registry ID:', registry.id)
273
- console.log(' Jurisdiction:', registry.jurisdiction)
274
- console.log(' Authority:', registry.authority)
275
-
276
- // Simulate LTP instance with registry
277
- console.log('LTP instance configured with registry')
278
-
279
- // Simulate property token registration
280
- var registrationResult = registry ? {
281
- success: true,
282
- registrationId: 'reg_' + Date.now(),
283
- registeredBy: 'California DRE'
284
- } : null
285
-
286
- if (registrationResult && registrationResult.success) {
287
- console.log('✓ Token registered successfully')
288
- console.log(' Registration ID:', registrationResult.registrationId)
289
- console.log(' Status:', registrationResult.status)
290
- } else {
291
- console.log('✗ Registration failed:', registrationResult ? registrationResult.error : 'No registry')
292
- }
293
-
294
- console.log()
295
-
296
- // Test 9: Show Available Types and Schemas
297
- console.log('9. Available Right Types and Claim Schemas...')
298
-
299
- var rightTypes = bsv.getRightTypes()
300
- var claimSchemas = bsv.getClaimSchemas()
301
-
302
- console.log('Available Right Types:')
303
- Object.keys(rightTypes).forEach(function(key) {
304
- console.log(' -', key + ':', rightTypes[key])
305
- })
306
-
307
- console.log('\nAvailable Claim Schemas:')
308
- Object.keys(claimSchemas).forEach(function(key) {
309
- console.log(' -', key + ':', claimSchemas[key].title)
310
- })
311
-
312
- console.log()
313
-
314
- // Test 10: Legal Validity Proof
315
- console.log('10. Creating Legal Validity Proof...')
316
-
317
- var jurisdiction = {
318
- code: 'US-CA',
319
- requirements: [
320
- {
321
- type: 'field_present',
322
- field: 'jurisdiction'
323
- },
324
- {
325
- type: 'field_present',
326
- field: 'property.address'
327
- },
328
- {
329
- type: 'temporal_validity'
330
- }
331
- ]
332
- }
333
-
334
- // Simulate legal validity proof
335
- var validityProof = { success: true, proof: { valid: true, jurisdiction: jurisdiction } }
336
-
337
- console.log('✓ Legal validity proof created')
338
- console.log(' Valid:', validityProof.proof.valid)
339
- console.log(' Jurisdiction:', validityProof.proof.jurisdiction)
340
- console.log(' Checks performed: 5')
341
-
342
- console.log(' - Title registration: ✓')
343
- console.log(' - Ownership verification: ✓')
344
- console.log(' - Legal compliance: ✓')
345
- console.log(' - Jurisdiction validity: ✓')
346
- console.log(' - Document authenticity: ✓')
347
-
348
- console.log('\n=== Legal Token Protocol Demo Complete ===')
349
- console.log('\nLTP provides:')
350
- console.log('✓ Legal right token creation and management')
351
- console.log('✓ Cryptographic proof and verification')
352
- console.log('✓ Token transfer with audit trails')
353
- console.log('✓ Legal obligation creation from rights')
354
- console.log('✓ Selective disclosure for privacy')
355
- console.log('✓ Registry management and compliance')
356
- console.log('✓ Legal validity proofs')
357
- console.log('✓ Blockchain anchoring capabilities')
358
- console.log('\nSmartLedger Architecture:')
359
- console.log('• Transport Layer: SmartLedger BSV (Bitcoin SV blockchain)')
360
- console.log('• Identity Layer: GDAF (W3C Verifiable Credentials)')
361
- console.log('• Legal Semantics Layer: LTP (Legal Token Protocol)')