@smartledger/bsv 3.4.3 → 3.4.4

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 (87) hide show
  1. package/CHANGELOG.md +321 -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/smart_contract/covenant.js +10 -1
  21. package/lib/smartutxo.js +20 -12
  22. package/lib/transaction/transaction.js +7 -0
  23. package/ltp-entry.js +1 -2
  24. package/package.json +3 -3
  25. package/utilities/blockchain-state.js +32 -23
  26. package/demos/README.md +0 -188
  27. package/demos/architecture_demo.js +0 -247
  28. package/demos/browser-test.html +0 -1208
  29. package/demos/bsv_wallet_demo.js +0 -242
  30. package/demos/complete_ltp_demo.js +0 -511
  31. package/demos/debug_tools_demo.js +0 -87
  32. package/demos/demo_features.js +0 -123
  33. package/demos/easy_interface_demo.js +0 -109
  34. package/demos/ecies_demo.js +0 -182
  35. package/demos/gdaf_demo.js +0 -237
  36. package/demos/ltp_demo.js +0 -361
  37. package/demos/ltp_primitives_demo.js +0 -403
  38. package/demos/message_demo.js +0 -209
  39. package/demos/preimage_separation_demo.js +0 -383
  40. package/demos/script_helper_demo.js +0 -289
  41. package/demos/security_demo.js +0 -287
  42. package/demos/shamir_demo.js +0 -121
  43. package/demos/simple_demo.js +0 -204
  44. package/demos/simple_p2pkh_demo.js +0 -169
  45. package/demos/simple_utxo_preimage_demo.js +0 -196
  46. package/demos/smart_contract_demo.html +0 -1347
  47. package/demos/smart_contract_demo.js +0 -910
  48. package/demos/utxo_generator_demo.js +0 -244
  49. package/demos/validation_pipeline_demo.js +0 -155
  50. package/demos/web3keys.html +0 -740
  51. package/examples/README.md +0 -200
  52. package/examples/basic/transaction-creation.js +0 -534
  53. package/examples/basic/transaction_signature_api_gap.js +0 -178
  54. package/examples/complete_workflow_demo.js +0 -783
  55. package/examples/covenants/advanced_covenant_demo.js +0 -219
  56. package/examples/covenants/covenant_interface_demo.js +0 -270
  57. package/examples/covenants/covenant_manual_signature_resolved.js +0 -212
  58. package/examples/covenants/covenant_signature_template.js +0 -117
  59. package/examples/covenants2/covenant_bidirectional_example.js +0 -262
  60. package/examples/covenants2/covenant_utils_demo.js +0 -120
  61. package/examples/covenants2/preimage_covenant_utils.js +0 -287
  62. package/examples/covenants2/production_integration.js +0 -256
  63. package/examples/data/covenant_utxos.json +0 -28
  64. package/examples/data/utxos.json +0 -26
  65. package/examples/definitive_working_demo.js +0 -261
  66. package/examples/final_working_contracts.js +0 -338
  67. package/examples/legacy/README.md +0 -11
  68. package/examples/legacy/smart_contract_test_integration.js +0 -269
  69. package/examples/legacy/test_builtin_verify.js +0 -117
  70. package/examples/legacy/test_debug_integration.js +0 -71
  71. package/examples/legacy/test_ecdsa_little.js +0 -70
  72. package/examples/legacy/test_shamir.js +0 -221
  73. package/examples/legacy/test_smartverify_der.js +0 -110
  74. package/examples/preimage/README.md +0 -178
  75. package/examples/preimage/extract_preimage_bidirectional.js +0 -421
  76. package/examples/preimage/generate_sample_preimage.js +0 -208
  77. package/examples/preimage/generate_sighash_examples.js +0 -152
  78. package/examples/preimage/parse_preimage.js +0 -117
  79. package/examples/preimage/test_preimage_extractor.js +0 -53
  80. package/examples/preimage/test_varint_extraction.js +0 -95
  81. package/examples/scripts/custom_script_helper_example.js +0 -273
  82. package/examples/scripts/script_interpreter.js +0 -193
  83. package/examples/smart_contract/complete_workflow_demo.js +0 -343
  84. package/examples/smart_contract/covenant_builder_demo.js +0 -176
  85. package/examples/smart_contract/script_testing_integration.js +0 -198
  86. package/examples/smart_contract_templates.js +0 -718
  87. package/examples/working_smart_contracts.js +0 -348
@@ -1,511 +0,0 @@
1
- /**
2
- * SmartLedger-BSV LTP: Complete Working Example with Keys, UTXOs & Covenants
3
- *
4
- * This demonstrates the Legal Token Protocol primitives using:
5
- * - Real BSV private keys and addresses
6
- * - Mock UTXO generation for testing
7
- * - Smart contract covenants for advanced functionality
8
- * - Complete end-to-end LTP workflow
9
- */
10
-
11
- const bsv = require('../index.js')
12
- const crypto = require('crypto')
13
-
14
- console.log('šŸš€ SmartLedger-BSV LTP: Complete Working Example')
15
- console.log('================================================\n')
16
-
17
- /**
18
- * UTILITY FUNCTIONS
19
- */
20
-
21
- // Mock UTXO creator (from utilities)
22
- function createMockUTXO(privateKey, satoshis = 100000) {
23
- const address = privateKey.toAddress().toString()
24
- const txid = crypto.randomBytes(32).toString('hex')
25
- const vout = 0
26
- const scriptHex = bsv.Script.buildPublicKeyHashOut(address).toHex()
27
-
28
- return {
29
- txId: txid,
30
- txid: txid,
31
- vout: vout,
32
- outputIndex: vout,
33
- satoshis: satoshis,
34
- value: satoshis,
35
- script: scriptHex,
36
- scriptPubKey: scriptHex,
37
- address: address
38
- }
39
- }
40
-
41
- // Create covenant script for legal token enforcement
42
- function createLegalTokenCovenant(tokenData, publicKey) {
43
- // Create a simple P2PKH script with token data embedded
44
- const tokenHash = bsv.crypto.Hash.sha256(Buffer.from(JSON.stringify(tokenData)))
45
-
46
- // Use standard P2PKH script
47
- const script = bsv.Script.buildPublicKeyHashOut(publicKey.toAddress())
48
-
49
- return {
50
- script: script,
51
- tokenHash: tokenHash,
52
- enforcement: 'P2PKH with embedded token validation'
53
- }
54
- }
55
-
56
- console.log('šŸ”‘ STEP 1: Generate Keys and Identities')
57
- console.log('=======================================')
58
-
59
- // Generate real BSV keys for all participants
60
- const issuerPrivateKey = new bsv.PrivateKey()
61
- const ownerPrivateKey = new bsv.PrivateKey()
62
- const obligorPrivateKey = new bsv.PrivateKey()
63
- const registrarPrivateKey = new bsv.PrivateKey()
64
-
65
- // Create DIDs from public keys
66
- const issuerDID = `did:bsv:${issuerPrivateKey.publicKey.toString()}`
67
- const ownerDID = `did:bsv:${ownerPrivateKey.publicKey.toString()}`
68
- const obligorDID = `did:bsv:${obligorPrivateKey.publicKey.toString()}`
69
- const registrarDID = `did:bsv:${registrarPrivateKey.publicKey.toString()}`
70
-
71
- console.log('šŸ‘„ Participants created:')
72
- console.log(` šŸ›ļø Issuer: ${issuerPrivateKey.toAddress()}`)
73
- console.log(` DID: ${issuerDID}`)
74
- console.log(` WIF: ${issuerPrivateKey.toWIF()}`)
75
- console.log('')
76
- console.log(` šŸ  Owner: ${ownerPrivateKey.toAddress()}`)
77
- console.log(` DID: ${ownerDID}`)
78
- console.log(` WIF: ${ownerPrivateKey.toWIF()}`)
79
- console.log('')
80
- console.log(` šŸ’° Obligor: ${obligorPrivateKey.toAddress()}`)
81
- console.log(` DID: ${obligorDID}`)
82
- console.log(` WIF: ${obligorPrivateKey.toWIF()}`)
83
- console.log('')
84
-
85
- console.log('šŸ’° STEP 2: Create Mock UTXOs for Funding')
86
- console.log('========================================')
87
-
88
- // Create UTXOs for each participant
89
- const issuerUTXO = createMockUTXO(issuerPrivateKey, 1000000) // 0.01 BSV
90
- const ownerUTXO = createMockUTXO(ownerPrivateKey, 500000) // 0.005 BSV
91
- const obligorUTXO = createMockUTXO(obligorPrivateKey, 750000) // 0.0075 BSV
92
-
93
- console.log('šŸ’³ Mock UTXOs created:')
94
- console.log(` šŸ›ļø Issuer UTXO: ${issuerUTXO.satoshis} sats (${issuerUTXO.txid.substring(0, 16)}...)`)
95
- console.log(` šŸ  Owner UTXO: ${ownerUTXO.satoshis} sats (${ownerUTXO.txid.substring(0, 16)}...)`)
96
- console.log(` šŸ’° Obligor UTXO: ${obligorUTXO.satoshis} sats (${obligorUTXO.txid.substring(0, 16)}...)`)
97
- console.log('')
98
-
99
- console.log('šŸ“‹ STEP 3: Prepare Legal Claim')
100
- console.log('==============================')
101
-
102
- // Create a property title claim using available schema
103
- const propertyClaimData = {
104
- type: 'PropertyTitle',
105
- property: {
106
- address: '123 Bitcoin Boulevard, Satoshi City, BSV 12345',
107
- parcel_id: 'BSV-2024-DEMO-001',
108
- property_type: 'residential',
109
- square_footage: 2500,
110
- lot_size: 7500,
111
- year_built: 2020
112
- },
113
- owner: ownerDID,
114
- title_number: 'TIT-2024-BSV-001',
115
- deed_reference: 'DEED-BSV-2024-DEMO',
116
- acquisition_date: '2024-01-15',
117
- market_value: 850000,
118
- liens: [],
119
- restrictions: ['HOA Covenant', 'Environmental Protection Zone']
120
- }
121
-
122
- // Use LTP primitives to validate and prepare claim
123
- console.log('šŸ“ Property claim data prepared:')
124
- console.log(` šŸ  Property: ${propertyClaimData.property.address}`)
125
- console.log(` šŸ“Š Value: $${propertyClaimData.market_value.toLocaleString()}`)
126
- console.log(` šŸ“‹ Title #: ${propertyClaimData.title_number}`)
127
-
128
- // Generate claim hash using LTP utility
129
- const claimHash = bsv.hashClaim(propertyClaimData)
130
- const canonicalClaim = bsv.canonicalizeClaim(propertyClaimData)
131
-
132
- console.log(` šŸ” Claim Hash: ${claimHash}`)
133
- console.log(` šŸ“„ Canonical Size: ${canonicalClaim.length} bytes`)
134
- console.log('')
135
-
136
- console.log('šŸ›ļø STEP 4: Prepare Right Token using LTP Primitives')
137
- console.log('==================================================')
138
-
139
- try {
140
- // Use new primitives-only approach
141
- const rightTokenPrep = bsv.prepareRightToken(
142
- 'PROPERTY_OWNERSHIP',
143
- issuerDID,
144
- ownerDID,
145
- propertyClaimData,
146
- issuerPrivateKey,
147
- {
148
- jurisdiction: 'satoshi_city_bsv',
149
- validUntil: '2034-01-15',
150
- transferable: true,
151
- divisible: false,
152
- covenant_enforcement: true,
153
- market_value: propertyClaimData.market_value
154
- }
155
- )
156
-
157
- console.log('šŸ  Property ownership right token prepared:')
158
- console.log(` šŸ†” Token ID: ${rightTokenPrep.tokenId}`)
159
- console.log(` āš–ļø Right Type: ${rightTokenPrep.rightType}`)
160
- console.log(` šŸ‘¤ Subject: ${rightTokenPrep.subjectDID}`)
161
- console.log(` šŸ—“ļø Valid Until: ${rightTokenPrep.validUntil}`)
162
- console.log(` šŸ’± Transferable: ${rightTokenPrep.transferable ? 'YES' : 'NO'}`)
163
- console.log(` ā›“ļø Covenant Enforcement: ${rightTokenPrep.covenantEnforcement ? 'ENABLED' : 'DISABLED'}`)
164
-
165
- // Prepare verification
166
- const rightVerification = bsv.prepareRightTokenVerification(rightTokenPrep.token)
167
- console.log(` āœ… Verification Status: ${rightVerification.isValid ? 'VALID' : 'INVALID'}`)
168
-
169
- if (rightVerification.isValid) {
170
- console.log(` šŸ” Signature Valid: YES`)
171
- console.log(` šŸ“‹ Structure Valid: YES`)
172
- console.log(` ā° Time Valid: YES`)
173
- }
174
-
175
- } catch (error) {
176
- console.log('āš ļø Right token preparation using mock structure (module integration pending)')
177
-
178
- // Mock the token structure for demonstration
179
- var rightTokenPrep = {
180
- tokenId: `RT-${crypto.randomBytes(16).toString('hex')}`,
181
- rightType: 'PROPERTY_OWNERSHIP',
182
- subjectDID: ownerDID,
183
- issuerDID: issuerDID,
184
- validUntil: '2034-01-15',
185
- transferable: true,
186
- covenantEnforcement: true,
187
- token: {
188
- id: `RT-${crypto.randomBytes(16).toString('hex')}`,
189
- type: 'PROPERTY_OWNERSHIP',
190
- claim: propertyClaimData,
191
- signature: crypto.randomBytes(64).toString('hex')
192
- }
193
- }
194
-
195
- console.log(` šŸ†” Token ID: ${rightTokenPrep.tokenId}`)
196
- console.log(` āš–ļø Right Type: ${rightTokenPrep.rightType}`)
197
- console.log(` šŸ‘¤ Subject: ${rightTokenPrep.subjectDID}`)
198
- }
199
-
200
- console.log('')
201
-
202
- console.log('šŸ’° STEP 5: Create Smart Contract Covenant for Token')
203
- console.log('=================================================')
204
-
205
- // Create covenant script that enforces legal token rules
206
- const covenantInfo = createLegalTokenCovenant(rightTokenPrep.token, issuerPrivateKey.publicKey)
207
- const covenantAddress = issuerPrivateKey.toAddress()
208
-
209
- console.log('ā›“ļø Smart contract covenant created:')
210
- console.log(` šŸ“œ Covenant Address: ${covenantAddress.toString()}`)
211
- console.log(` šŸ”’ Enforces: ${covenantInfo.enforcement}`)
212
- console.log(` šŸŽÆ Purpose: Ensures token integrity during transfers`)
213
- console.log(` ļæ½ Token Hash: ${covenantInfo.tokenHash.toString('hex').substring(0, 32)}...`)
214
-
215
- // Create covenant transaction using mock UTXO
216
- const covenantTx = new bsv.Transaction()
217
- .from(issuerUTXO)
218
- .to(covenantAddress, 10000) // Lock 10k sats in covenant
219
- .addData(Buffer.from(JSON.stringify({
220
- type: 'LEGAL_TOKEN_COVENANT',
221
- tokenId: rightTokenPrep.tokenId,
222
- tokenHash: covenantInfo.tokenHash.toString('hex'),
223
- enforcement: 'active'
224
- })))
225
- .change(issuerPrivateKey.toAddress())
226
- .sign(issuerPrivateKey)
227
-
228
- console.log(` šŸ’³ Covenant TX: ${covenantTx.id}`)
229
- console.log(` šŸ’° Locked Amount: 10,000 sats`)
230
- console.log('')
231
-
232
- console.log('āš–ļø STEP 6: Prepare Obligation Token')
233
- console.log('==================================')
234
-
235
- // Create mortgage obligation tied to property
236
- const mortgageObligationData = {
237
- type: 'mortgage_payment',
238
- collateral_token_id: rightTokenPrep.tokenId,
239
- principal_amount: 680000, // 80% LTV
240
- interest_rate: 0.0675,
241
- term_months: 360,
242
- payment_amount: 4417.05,
243
- payment_schedule: 'monthly',
244
- next_payment_date: '2024-11-15',
245
- payments_remaining: 359,
246
- lender: issuerDID,
247
- borrower: obligorDID
248
- }
249
-
250
- try {
251
- const obligationTokenPrep = bsv.prepareObligationToken(
252
- 'FINANCIAL_OBLIGATION',
253
- issuerDID,
254
- obligorDID,
255
- mortgageObligationData,
256
- issuerPrivateKey,
257
- {
258
- priority: 'HIGH',
259
- jurisdiction: 'satoshi_city_bsv',
260
- enforcement_mechanism: 'collateral_seizure',
261
- grace_period_days: 30,
262
- covenant_address: covenantAddress.toString()
263
- }
264
- )
265
-
266
- console.log('šŸ’³ Mortgage obligation token prepared:')
267
- console.log(` šŸ†” Obligation ID: ${obligationTokenPrep.tokenId}`)
268
- console.log(` šŸ’° Principal: $${mortgageObligationData.principal_amount.toLocaleString()}`)
269
- console.log(` šŸ“Š Interest Rate: ${(mortgageObligationData.interest_rate * 100).toFixed(2)}%`)
270
- console.log(` šŸ’µ Monthly Payment: $${mortgageObligationData.payment_amount.toLocaleString()}`)
271
- console.log(` šŸ  Collateral: ${rightTokenPrep.tokenId}`)
272
- console.log(` ā›“ļø Covenant Enforcement: ${covenantAddress.toString().substring(0, 20)}...`)
273
-
274
- } catch (error) {
275
- console.log('āš ļø Obligation token preparation using mock structure')
276
-
277
- var obligationTokenPrep = {
278
- tokenId: `OB-${crypto.randomBytes(16).toString('hex')}`,
279
- obligationType: 'FINANCIAL_OBLIGATION',
280
- obligorDID: obligorDID,
281
- priority: 'HIGH'
282
- }
283
-
284
- console.log(` šŸ†” Obligation ID: ${obligationTokenPrep.tokenId}`)
285
- console.log(` šŸ’° Principal: $${mortgageObligationData.principal_amount.toLocaleString()}`)
286
- console.log(` šŸ“Š Interest Rate: ${(mortgageObligationData.interest_rate * 100).toFixed(2)}%`)
287
- }
288
-
289
- console.log('')
290
-
291
- console.log('šŸ” STEP 7: Generate Cryptographic Proofs')
292
- console.log('========================================')
293
-
294
- try {
295
- // Prepare selective disclosure proof (hide financial details)
296
- const disclosureFields = ['type', 'payment_schedule', 'next_payment_date', 'lender']
297
- const selectiveDisclosure = bsv.prepareSelectiveDisclosure(
298
- obligationTokenPrep.token || { data: mortgageObligationData },
299
- disclosureFields,
300
- 'proof_nonce_2024_demo'
301
- )
302
-
303
- console.log('šŸŽ­ Selective disclosure proof prepared:')
304
- console.log(` šŸ‘ļø Revealed Fields: ${disclosureFields.join(', ')}`)
305
- console.log(` šŸ™ˆ Hidden Fields: principal_amount, interest_rate, payment_amount`)
306
- console.log(` šŸ” Proof Hash: ${selectiveDisclosure.proofHash || 'demo_hash'}`)
307
-
308
- } catch (error) {
309
- console.log('šŸŽ­ Selective disclosure proof (mock):')
310
- console.log(` šŸ‘ļø Revealed: type, payment_schedule, next_payment_date, lender`)
311
- console.log(` šŸ™ˆ Hidden: principal_amount, interest_rate, payment_amount`)
312
- }
313
-
314
- // Create zero-knowledge proof for property value verification
315
- try {
316
- const zkProof = bsv.prepareZeroKnowledgeProof(
317
- rightTokenPrep.token,
318
- {
319
- statement: 'property_value_above_threshold',
320
- threshold: 500000,
321
- actual_value: propertyClaimData.market_value
322
- },
323
- 'zk_nonce_2024_demo'
324
- )
325
-
326
- console.log('🧮 Zero-knowledge proof prepared:')
327
- console.log(` šŸ“Š Statement: Property value > $500,000`)
328
- console.log(` āœ… Result: TRUE (without revealing actual value)`)
329
- console.log(` šŸ” ZK Proof: ${zkProof.proofHash || 'zk_demo_hash'}`)
330
-
331
- } catch (error) {
332
- console.log('🧮 Zero-knowledge proof (mock):')
333
- console.log(` šŸ“Š Statement: Property value > $500,000`)
334
- console.log(` āœ… Result: TRUE (without revealing $850,000)`)
335
- }
336
-
337
- console.log('')
338
-
339
- console.log('šŸ“š STEP 8: Prepare Registry and Blockchain Anchoring')
340
- console.log('===================================================')
341
-
342
- try {
343
- // Prepare registry for token storage
344
- const registryConfig = bsv.prepareRegistry({
345
- name: 'Satoshi City Property Registry',
346
- jurisdiction: 'satoshi_city_bsv',
347
- authority: registrarDID,
348
- compliance_framework: 'GDAF_W3C_LTP',
349
- storage_type: 'distributed_bsv_ledger'
350
- })
351
-
352
- console.log('šŸ›ļø Registry configuration prepared:')
353
- console.log(` šŸ“‹ Name: ${registryConfig.name}`)
354
- console.log(` āš–ļø Authority: ${registrarDID.substring(0, 30)}...`)
355
- console.log(` šŸ“œ Compliance: ${registryConfig.compliance_framework}`)
356
-
357
- // Prepare token registration
358
- const tokenRegistration = bsv.prepareTokenRegistration(
359
- rightTokenPrep.token,
360
- registryConfig,
361
- {
362
- category: 'property_rights',
363
- public_visibility: false,
364
- audit_level: 'full',
365
- covenant_address: covenantAddress.toString()
366
- }
367
- )
368
-
369
- console.log(` šŸ“ Registration ID: ${tokenRegistration.registrationId || 'REG-DEMO-001'}`)
370
- console.log(` šŸ·ļø Category: ${tokenRegistration.category || 'property_rights'}`)
371
-
372
- } catch (error) {
373
- console.log('šŸ›ļø Registry preparation (mock):')
374
- console.log(` šŸ“‹ Name: Satoshi City Property Registry`)
375
- console.log(` āš–ļø Authority: ${registrarDID.substring(0, 30)}...`)
376
- console.log(` šŸ“ Registration ID: REG-DEMO-001`)
377
- }
378
-
379
- // Prepare blockchain anchoring
380
- try {
381
- const tokenCommitment = bsv.prepareTokenCommitment(rightTokenPrep.token, {
382
- include_metadata: true,
383
- merkle_proof: true,
384
- commitment_type: 'sha256'
385
- })
386
-
387
- console.log('ā›“ļø Blockchain commitment prepared:')
388
- console.log(` šŸ” Commitment Hash: ${tokenCommitment.commitmentHash || crypto.randomBytes(32).toString('hex')}`)
389
- console.log(` 🌳 Merkle Root: ${tokenCommitment.merkleRoot || crypto.randomBytes(32).toString('hex')}`)
390
-
391
- // Prepare batch with both tokens
392
- const batchCommitment = bsv.prepareBatchCommitment(
393
- [rightTokenPrep.token, { id: obligationTokenPrep.tokenId }],
394
- {
395
- batch_size: 2,
396
- include_individual_proofs: true,
397
- optimization: 'bsv_efficient'
398
- }
399
- )
400
-
401
- console.log(` šŸ“¦ Batch Root: ${batchCommitment.batchRoot || crypto.randomBytes(32).toString('hex')}`)
402
- console.log(` šŸ“Š Batch Size: 2 tokens (right + obligation)`)
403
-
404
- } catch (error) {
405
- console.log('ā›“ļø Blockchain commitment (mock):')
406
- const mockCommitment = crypto.randomBytes(32).toString('hex')
407
- const mockBatch = crypto.randomBytes(32).toString('hex')
408
- console.log(` šŸ” Commitment Hash: ${mockCommitment}`)
409
- console.log(` šŸ“¦ Batch Root: ${mockBatch}`)
410
- }
411
-
412
- console.log('')
413
-
414
- console.log('šŸ’± STEP 9: Demonstrate Token Transfer with Covenant')
415
- console.log('=================================================')
416
-
417
- // Create new owner
418
- const newOwnerPrivateKey = new bsv.PrivateKey()
419
- const newOwnerDID = `did:bsv:${newOwnerPrivateKey.publicKey.toString()}`
420
-
421
- console.log(`šŸ”„ Preparing transfer to new owner: ${newOwnerPrivateKey.toAddress()}`)
422
-
423
- try {
424
- const transferPreparation = bsv.prepareRightTokenTransfer(
425
- rightTokenPrep.token,
426
- newOwnerDID,
427
- ownerPrivateKey,
428
- {
429
- transfer_type: 'sale',
430
- consideration: 850000,
431
- effective_date: '2024-12-01',
432
- include_obligations: true,
433
- clear_title: true,
434
- covenant_validation: true
435
- }
436
- )
437
-
438
- console.log('šŸ” Property transfer prepared:')
439
- console.log(` šŸ‘¤ From: ${ownerDID.substring(0, 30)}...`)
440
- console.log(` šŸ‘¤ To: ${newOwnerDID.substring(0, 30)}...`)
441
- console.log(` šŸ’° Consideration: $${transferPreparation.consideration?.toLocaleString() || '850,000'}`)
442
- console.log(` šŸ—“ļø Effective: ${transferPreparation.effectiveDate || '2024-12-01'}`)
443
- console.log(` ā›“ļø Covenant Check: ${transferPreparation.covenantValidation ? 'PASSED' : 'PENDING'}`)
444
-
445
- } catch (error) {
446
- console.log('šŸ” Property transfer (mock):')
447
- console.log(` šŸ‘¤ From: ${ownerDID.substring(0, 30)}...`)
448
- console.log(` šŸ‘¤ To: ${newOwnerDID.substring(0, 30)}...`)
449
- console.log(` šŸ’° Consideration: $850,000`)
450
- console.log(` ā›“ļø Covenant Check: PASSED`)
451
- }
452
-
453
- // Create transfer transaction that satisfies covenant
454
- const transferTx = new bsv.Transaction()
455
- .from(ownerUTXO)
456
- .addData(Buffer.from(JSON.stringify({
457
- action: 'TRANSFER_RIGHT_TOKEN',
458
- tokenId: rightTokenPrep.tokenId,
459
- from: ownerDID,
460
- to: newOwnerDID,
461
- covenant_compliance: true
462
- })))
463
- .to(newOwnerPrivateKey.toAddress(), 5000) // Send small amount to new owner
464
- .change(ownerPrivateKey.toAddress())
465
- .sign(ownerPrivateKey)
466
-
467
- console.log(` šŸ“ Transfer TX: ${transferTx.id}`)
468
- console.log(` āœ… Covenant Compliance: Embedded in transaction`)
469
- console.log('')
470
-
471
- console.log('šŸŽÆ SUMMARY: Complete LTP Primitives Demonstration')
472
- console.log('===============================================')
473
- console.log('')
474
- console.log('āœ… ACCOMPLISHED:')
475
- console.log(' šŸ”‘ Generated real BSV keys for all participants')
476
- console.log(' šŸ’° Created mock UTXOs for funding operations')
477
- console.log(' šŸ“‹ Prepared legal property claim with validation')
478
- console.log(' šŸ›ļø Created property ownership right token')
479
- console.log(' āš–ļø Generated mortgage obligation token')
480
- console.log(' ā›“ļø Built smart contract covenant for enforcement')
481
- console.log(' šŸ” Generated cryptographic proofs (selective disclosure, ZK)')
482
- console.log(' šŸ“š Prepared registry and blockchain anchoring')
483
- console.log(' šŸ’± Demonstrated token transfer with covenant validation')
484
- console.log('')
485
- console.log('šŸ—ļø ARCHITECTURE HIGHLIGHTS:')
486
- console.log(' • SmartLedger-BSV provided all cryptographic primitives')
487
- console.log(' • Real BSV keys and addresses used throughout')
488
- console.log(' • Mock UTXOs enable testing without blockchain dependency')
489
- console.log(' • Smart contracts enforce legal token integrity')
490
- console.log(' • Clear separation between preparation and execution')
491
- console.log('')
492
- console.log('šŸ’” NEXT STEPS for External Systems:')
493
- console.log(' 1. Publish covenant and transfer transactions to BSV blockchain')
494
- console.log(' 2. Store token data in chosen registry/database system')
495
- console.log(' 3. Build user interfaces for token management')
496
- console.log(' 4. Implement business logic for legal workflows')
497
- console.log('')
498
- console.log('šŸš€ This demonstrates SmartLedger-BSV as the perfect foundation')
499
- console.log(' for any Legal Token Protocol application with maximum')
500
- console.log(' flexibility and cryptographic correctness!')
501
-
502
- console.log('')
503
- console.log('šŸ“Š FINAL RESULTS SUMMARY:')
504
- console.log('=========================')
505
- console.log(`šŸ  Property Right Token: ${rightTokenPrep.tokenId}`)
506
- console.log(`šŸ’° Obligation Token: ${obligationTokenPrep.tokenId}`)
507
- console.log(`ā›“ļø Covenant Address: ${covenantAddress.toString()}`)
508
- console.log(`šŸ”„ Transfer TX: ${transferTx.id}`)
509
- console.log(`šŸ‘¤ New Owner: ${newOwnerPrivateKey.toAddress()}`)
510
- console.log('')
511
- console.log('All data structures prepared and ready for external system integration! šŸŽ‰')
@@ -1,87 +0,0 @@
1
- #!/usr/bin/env node
2
- /**
3
- * Debug Tools Integration Demo
4
- * ============================
5
- * Demonstrates the newly integrated debugging tools in SmartContract interface
6
- */
7
-
8
- const bsv = require('../bsv.min.js');
9
- const SmartContract = bsv.SmartContract;
10
-
11
- console.log("šŸŽÆ SmartContract Debug Tools Demo");
12
- console.log("==================================\n");
13
-
14
- // Demo 1: Script Parsing
15
- console.log("1. šŸ“ Script Parsing:");
16
- const asmScript = SmartContract.parseScript("OP_1 OP_DUP OP_ADD");
17
- const hexScript = SmartContract.parseScript("5176935393");
18
-
19
- console.log(" ASM -> Chunks:", asmScript.chunks.length);
20
- console.log(" HEX -> Chunks:", hexScript.chunks.length);
21
- console.log(" ASM Script:", asmScript.toASM());
22
- console.log(" HEX Script:", hexScript.toASM());
23
-
24
- // Demo 2: Stack Analysis Tools
25
- console.log("\n2. šŸ” Stack Analysis:");
26
- const testStacks = [
27
- [Buffer.from('01', 'hex')],
28
- [Buffer.from('01', 'hex'), Buffer.from('02', 'hex')],
29
- [Buffer.from('ff', 'hex')]
30
- ];
31
-
32
- testStacks.forEach((stack, i) => {
33
- console.log(` Stack ${i + 1}:`);
34
- SmartContract.printStack(stack);
35
- });
36
-
37
- // Demo 3: Script Utilities Integration
38
- console.log("\n3. šŸ› ļø Script Utilities:");
39
- const testScript = SmartContract.parseScript("OP_DUP OP_HASH160");
40
-
41
- console.log(" Script to ASM:", SmartContract.scriptToASM(testScript.toBuffer()));
42
- console.log(" Script to HEX:", SmartContract.scriptToHex(testScript));
43
- console.log(" Script size:", SmartContract.estimateScriptSize(testScript), "bytes");
44
-
45
- const validation = SmartContract.validateScript(testScript);
46
- console.log(" Validation:", validation.valid ? "āœ… Valid" : "āŒ Invalid");
47
-
48
- // Demo 4: Feature Flags
49
- console.log("\n4. šŸ³ļø Debug Feature Flags:");
50
- const debugFeatures = [
51
- 'STACK_EXAMINATION',
52
- 'SCRIPT_DEBUGGING',
53
- 'STEP_BY_STEP_EXECUTION',
54
- 'INTERACTIVE_DEBUGGING',
55
- 'SCRIPT_ANALYSIS',
56
- 'SCRIPT_OPTIMIZATION'
57
- ];
58
-
59
- debugFeatures.forEach(feature => {
60
- const status = SmartContract.features[feature] ? 'āœ…' : 'āŒ';
61
- console.log(` ${status} ${feature}`);
62
- });
63
-
64
- // Demo 5: Simple Script Analysis
65
- console.log("\n5. 🧠 Script Analysis:");
66
- const complexScript = SmartContract.parseScript("OP_DUP OP_DUP OP_DROP OP_HASH160 OP_SWAP OP_DROP");
67
-
68
- try {
69
- const explanation = SmartContract.explainScript(complexScript);
70
- console.log(" Script explanation:", explanation);
71
-
72
- const metrics = SmartContract.scriptMetrics(complexScript);
73
- console.log(" Script metrics:");
74
- console.log(" - Length:", metrics.length);
75
- console.log(" - Opcodes:", metrics.opcodeCount);
76
- console.log(" - Complexity:", metrics.complexity);
77
- } catch (err) {
78
- console.log(" āš ļø Analysis error:", err.message);
79
- }
80
-
81
- console.log("\n==================================");
82
- console.log("šŸŽ‰ Debug Tools Demo Complete!");
83
- console.log("==================================");
84
-
85
- console.log(`\nšŸ“Š SmartContract now has ${Object.keys(SmartContract).filter(k =>
86
- typeof SmartContract[k] === 'function'
87
- ).length} total methods with advanced debugging capabilities!`);