@smartledger/bsv 3.4.2 โ†’ 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 (88) hide show
  1. package/CHANGELOG.md +336 -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 +61 -58
  14. package/docs/advanced/LEGAL_TOKEN_PROTOCOL.md +3 -3
  15. package/docs/advanced/UTXO_MANAGER_GUIDE.md +1 -1
  16. package/docs/getting-started/INSTALLATION.md +30 -30
  17. package/docs/getting-started/QUICK_START.md +18 -18
  18. package/docs/migration/FROM_BSV_1_5_6.md +16 -10
  19. package/gdaf-entry.js +1 -2
  20. package/index.js +20 -7
  21. package/lib/smart_contract/covenant.js +10 -1
  22. package/lib/smartutxo.js +20 -12
  23. package/lib/transaction/transaction.js +7 -0
  24. package/ltp-entry.js +1 -2
  25. package/package.json +3 -3
  26. package/utilities/blockchain-state.js +32 -23
  27. package/demos/README.md +0 -188
  28. package/demos/architecture_demo.js +0 -247
  29. package/demos/browser-test.html +0 -1208
  30. package/demos/bsv_wallet_demo.js +0 -242
  31. package/demos/complete_ltp_demo.js +0 -511
  32. package/demos/debug_tools_demo.js +0 -87
  33. package/demos/demo_features.js +0 -123
  34. package/demos/easy_interface_demo.js +0 -109
  35. package/demos/ecies_demo.js +0 -182
  36. package/demos/gdaf_demo.js +0 -237
  37. package/demos/ltp_demo.js +0 -361
  38. package/demos/ltp_primitives_demo.js +0 -403
  39. package/demos/message_demo.js +0 -209
  40. package/demos/preimage_separation_demo.js +0 -383
  41. package/demos/script_helper_demo.js +0 -289
  42. package/demos/security_demo.js +0 -287
  43. package/demos/shamir_demo.js +0 -121
  44. package/demos/simple_demo.js +0 -204
  45. package/demos/simple_p2pkh_demo.js +0 -169
  46. package/demos/simple_utxo_preimage_demo.js +0 -196
  47. package/demos/smart_contract_demo.html +0 -1347
  48. package/demos/smart_contract_demo.js +0 -910
  49. package/demos/utxo_generator_demo.js +0 -244
  50. package/demos/validation_pipeline_demo.js +0 -155
  51. package/demos/web3keys.html +0 -740
  52. package/examples/README.md +0 -200
  53. package/examples/basic/transaction-creation.js +0 -534
  54. package/examples/basic/transaction_signature_api_gap.js +0 -178
  55. package/examples/complete_workflow_demo.js +0 -783
  56. package/examples/covenants/advanced_covenant_demo.js +0 -219
  57. package/examples/covenants/covenant_interface_demo.js +0 -270
  58. package/examples/covenants/covenant_manual_signature_resolved.js +0 -212
  59. package/examples/covenants/covenant_signature_template.js +0 -117
  60. package/examples/covenants2/covenant_bidirectional_example.js +0 -262
  61. package/examples/covenants2/covenant_utils_demo.js +0 -120
  62. package/examples/covenants2/preimage_covenant_utils.js +0 -287
  63. package/examples/covenants2/production_integration.js +0 -256
  64. package/examples/data/covenant_utxos.json +0 -28
  65. package/examples/data/utxos.json +0 -26
  66. package/examples/definitive_working_demo.js +0 -261
  67. package/examples/final_working_contracts.js +0 -338
  68. package/examples/legacy/README.md +0 -11
  69. package/examples/legacy/smart_contract_test_integration.js +0 -269
  70. package/examples/legacy/test_builtin_verify.js +0 -117
  71. package/examples/legacy/test_debug_integration.js +0 -71
  72. package/examples/legacy/test_ecdsa_little.js +0 -70
  73. package/examples/legacy/test_shamir.js +0 -221
  74. package/examples/legacy/test_smartverify_der.js +0 -110
  75. package/examples/preimage/README.md +0 -178
  76. package/examples/preimage/extract_preimage_bidirectional.js +0 -421
  77. package/examples/preimage/generate_sample_preimage.js +0 -208
  78. package/examples/preimage/generate_sighash_examples.js +0 -152
  79. package/examples/preimage/parse_preimage.js +0 -117
  80. package/examples/preimage/test_preimage_extractor.js +0 -53
  81. package/examples/preimage/test_varint_extraction.js +0 -95
  82. package/examples/scripts/custom_script_helper_example.js +0 -273
  83. package/examples/scripts/script_interpreter.js +0 -193
  84. package/examples/smart_contract/complete_workflow_demo.js +0 -343
  85. package/examples/smart_contract/covenant_builder_demo.js +0 -176
  86. package/examples/smart_contract/script_testing_integration.js +0 -198
  87. package/examples/smart_contract_templates.js +0 -718
  88. package/examples/working_smart_contracts.js +0 -348
package/lib/smartutxo.js CHANGED
@@ -5,6 +5,15 @@
5
5
  * Provides blockchain state management and UTXO tracking for testing and development
6
6
  */
7
7
 
8
+ // Set BSV_DEBUG=1 (Node) or window.BSV_DEBUG = true (browser) to surface
9
+ // info/warning output from this module. Matches the gating pattern used
10
+ // by lib/browser-utxo-manager-es5.js since v3.4.1.
11
+ const debug = function () {
12
+ const enabled = (typeof process !== 'undefined' && process.env && process.env.BSV_DEBUG) ||
13
+ (typeof window !== 'undefined' && window.BSV_DEBUG)
14
+ if (enabled) console.log.apply(console, arguments)
15
+ }
16
+
8
17
  // Browser-compatible imports
9
18
  let fs, path, crypto, blockchainState
10
19
 
@@ -16,8 +25,7 @@ if (typeof window === 'undefined' && typeof require === 'function') {
16
25
  crypto = require('crypto')
17
26
  blockchainState = require('../utilities/blockchain-state')
18
27
  } catch (e) {
19
- // Fallback for environments where these modules aren't available
20
- console.warn('SmartUTXO: Running in browser mode - some features may be limited')
28
+ debug('SmartUTXO: Running in browser mode - some features may be limited')
21
29
  }
22
30
  }
23
31
 
@@ -40,7 +48,7 @@ class SmartUTXOManager {
40
48
  const state = blockchainState.loadBlockchainState()
41
49
  return state
42
50
  } catch (error) {
43
- console.log('โš ๏ธ Could not load blockchain state:', error.message)
51
+ debug('โš ๏ธ Could not load blockchain state:', error.message)
44
52
  return null
45
53
  }
46
54
  }
@@ -53,9 +61,9 @@ class SmartUTXOManager {
53
61
  const state = blockchainState.loadBlockchainState()
54
62
  blockchainState.saveBlockchainState(state)
55
63
  const utxoCount = Object.keys(state.globalUTXOSet || {}).length
56
- console.log(`๐Ÿ’พ Saved blockchain state with ${utxoCount} UTXOs`)
64
+ debug(`๐Ÿ’พ Saved blockchain state with ${utxoCount} UTXOs`)
57
65
  } catch (error) {
58
- console.log('โš ๏ธ Could not save blockchain state:', error.message)
66
+ debug('โš ๏ธ Could not save blockchain state:', error.message)
59
67
  }
60
68
  }
61
69
 
@@ -76,7 +84,7 @@ class SmartUTXOManager {
76
84
  // Return the wallet's UTXOs
77
85
  return state.wallets[address].utxos || []
78
86
  } catch (error) {
79
- console.log('โš ๏ธ Error getting UTXOs:', error.message)
87
+ debug('โš ๏ธ Error getting UTXOs:', error.message)
80
88
  return []
81
89
  }
82
90
  }
@@ -90,7 +98,7 @@ class SmartUTXOManager {
90
98
  // Use the correct API: addUTXO(utxo, ownerAddress)
91
99
  blockchainState.addUTXO(utxo, utxo.address)
92
100
  } catch (error) {
93
- console.log('โš ๏ธ Error adding UTXO:', error.message)
101
+ debug('โš ๏ธ Error adding UTXO:', error.message)
94
102
  }
95
103
  }
96
104
 
@@ -106,7 +114,7 @@ class SmartUTXOManager {
106
114
  blockchainState.spendUTXO(input.txid, input.vout, spentInTx)
107
115
  }
108
116
  } catch (error) {
109
- console.log('โš ๏ธ Error spending UTXOs:', error.message)
117
+ debug('โš ๏ธ Error spending UTXOs:', error.message)
110
118
  }
111
119
  }
112
120
 
@@ -156,7 +164,7 @@ class SmartUTXOManager {
156
164
  // Return the wallet's total value
157
165
  return state.wallets[address].totalValue || 0
158
166
  } catch (error) {
159
- console.log('โš ๏ธ Error getting balance:', error.message)
167
+ debug('โš ๏ธ Error getting balance:', error.message)
160
168
  return 0
161
169
  }
162
170
  }
@@ -176,7 +184,7 @@ class SmartUTXOManager {
176
184
  lastUpdated: state.metadata.lastUpdated
177
185
  }
178
186
  } catch (error) {
179
- console.log('โš ๏ธ Error getting stats:', error.message)
187
+ debug('โš ๏ธ Error getting stats:', error.message)
180
188
  return { totalUTXOs: 0, totalValue: 0, totalWallets: 0, blockHeight: 0 }
181
189
  }
182
190
  }
@@ -189,10 +197,10 @@ class SmartUTXOManager {
189
197
  const statePath = path.join(__dirname, '../utilities/blockchain-state.json')
190
198
  if (fs.existsSync(statePath)) {
191
199
  fs.unlinkSync(statePath)
192
- console.log('๐Ÿ”„ Blockchain state reset')
200
+ debug('๐Ÿ”„ Blockchain state reset')
193
201
  }
194
202
  } catch (error) {
195
- console.log('โš ๏ธ Could not reset blockchain state:', error.message)
203
+ debug('โš ๏ธ Could not reset blockchain state:', error.message)
196
204
  }
197
205
  }
198
206
  }
@@ -911,6 +911,13 @@ Transaction.prototype._getUnspentValue = function () {
911
911
 
912
912
  Transaction.prototype._clearSignatures = function () {
913
913
  _.each(this.inputs, function (input) {
914
+ // Custom-script inputs (bare Input base class โ€” e.g. covenant or other
915
+ // non-standard locking scripts) have no library-managed signatures to
916
+ // clear; the caller owns input.script. Mirror the guard pattern used by
917
+ // Transaction.prototype.isFullySigned / isValidSignature below.
918
+ if (input.clearSignatures === Input.prototype.clearSignatures) {
919
+ return
920
+ }
914
921
  input.clearSignatures()
915
922
  })
916
923
  }
package/ltp-entry.js CHANGED
@@ -1,2 +1 @@
1
- // LTP module placeholder - will be implemented in future release
2
- module.exports = require('./lib/smart_contract');
1
+ module.exports = require('./lib/ltp')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smartledger/bsv",
3
- "version": "3.4.2",
3
+ "version": "3.4.4",
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",
@@ -8,12 +8,14 @@
8
8
  "url": "https://github.com/codenlighten/smartledger-bsv/issues"
9
9
  },
10
10
  "main": "index.js",
11
+ "types": "bsv.d.ts",
11
12
  "bin": {
12
13
  "smartledger-bsv": "./bin/cli.js"
13
14
  },
14
15
  "scripts": {
15
16
  "lint": "standard",
16
17
  "test": "mocha",
18
+ "test:cli": "mocha test/cli/smoke.js --timeout 25000",
17
19
  "test:ltp": "node complete_ltp_demo.js",
18
20
  "test:ltp-primitives": "node simple_demo.js",
19
21
  "test:architecture": "node architecture_demo.js",
@@ -96,8 +98,6 @@
96
98
  "bsv-anchor.min.js",
97
99
  "bsv.d.ts",
98
100
  "docs/",
99
- "demos/",
100
- "examples/",
101
101
  "LICENSE",
102
102
  "README.md",
103
103
  "SECURITY.md",
@@ -5,6 +5,15 @@
5
5
  * Acts as the "blockchain database" for our miner simulator.
6
6
  */
7
7
 
8
+ // Set BSV_DEBUG=1 (Node) or window.BSV_DEBUG = true (browser) to surface
9
+ // info/warning narration from this module. Matches the gating pattern
10
+ // used by lib/browser-utxo-manager-es5.js since v3.4.1.
11
+ const debug = function () {
12
+ const enabled = (typeof process !== 'undefined' && process.env && process.env.BSV_DEBUG) ||
13
+ (typeof window !== 'undefined' && window.BSV_DEBUG)
14
+ if (enabled) console.log.apply(console, arguments)
15
+ }
16
+
8
17
  // Browser-compatible imports
9
18
  let bsv, fs, path, BLOCKCHAIN_STATE_PATH
10
19
 
@@ -16,7 +25,7 @@ if (typeof window === 'undefined' && typeof require === 'function') {
16
25
  path = require('path')
17
26
  BLOCKCHAIN_STATE_PATH = path.join(__dirname, 'blockchain-state.json')
18
27
  } catch (e) {
19
- console.warn('BlockchainState: Running in browser mode - persistence disabled')
28
+ debug('BlockchainState: Running in browser mode - persistence disabled')
20
29
  }
21
30
  } else {
22
31
  // In browser, try to get bsv from global scope or fallback
@@ -54,14 +63,14 @@ function loadBlockchainState () {
54
63
  }
55
64
 
56
65
  if (!fs.existsSync(BLOCKCHAIN_STATE_PATH)) {
57
- console.log('๐Ÿ†• Creating new blockchain state...')
66
+ debug('๐Ÿ†• Creating new blockchain state...')
58
67
  const initialState = initializeBlockchainState()
59
68
  saveBlockchainState(initialState)
60
69
  return initialState
61
70
  }
62
71
 
63
72
  const state = JSON.parse(fs.readFileSync(BLOCKCHAIN_STATE_PATH, 'utf8'))
64
- console.log('๐Ÿ“– Loaded existing blockchain state')
73
+ debug('๐Ÿ“– Loaded existing blockchain state')
65
74
  return state
66
75
  } catch (error) {
67
76
  console.error('โŒ Error loading blockchain state:', error.message)
@@ -79,7 +88,7 @@ function saveBlockchainState (state) {
79
88
  // Only save to file in Node.js environment
80
89
  if (fs && BLOCKCHAIN_STATE_PATH) {
81
90
  fs.writeFileSync(BLOCKCHAIN_STATE_PATH, JSON.stringify(state, null, 2))
82
- console.log('๐Ÿ’พ Blockchain state saved')
91
+ debug('๐Ÿ’พ Blockchain state saved')
83
92
  }
84
93
  } catch (error) {
85
94
  console.error('โŒ Error saving blockchain state:', error.message)
@@ -90,12 +99,12 @@ function saveBlockchainState (state) {
90
99
  * Register a new wallet in the blockchain state
91
100
  */
92
101
  function registerWallet (walletAddress, walletData) {
93
- console.log(`๐Ÿ“ Registering wallet: ${walletAddress}`)
102
+ debug(`๐Ÿ“ Registering wallet: ${walletAddress}`)
94
103
 
95
104
  const state = loadBlockchainState()
96
105
 
97
106
  if (state.wallets[walletAddress]) {
98
- console.log('โ„น๏ธ Wallet already exists, updating...')
107
+ debug('โ„น๏ธ Wallet already exists, updating...')
99
108
  }
100
109
 
101
110
  state.wallets[walletAddress] = {
@@ -122,7 +131,7 @@ function registerWallet (walletAddress, walletData) {
122
131
 
123
132
  saveBlockchainState(state)
124
133
 
125
- console.log(`โœ… Wallet registered: ${walletAddress}`)
134
+ debug(`โœ… Wallet registered: ${walletAddress}`)
126
135
  return state
127
136
  }
128
137
 
@@ -185,7 +194,7 @@ function spendUTXO (txid, vout, spentInTx) {
185
194
 
186
195
  updateBlockchainMetadata(state)
187
196
  saveBlockchainState(state)
188
- console.log(`โŒ UTXO spent: ${utxoKey} in tx ${spentInTx}`)
197
+ debug(`โŒ UTXO spent: ${utxoKey} in tx ${spentInTx}`)
189
198
  }
190
199
 
191
200
  /**
@@ -197,7 +206,7 @@ function addUTXO (utxo, ownerAddress) {
197
206
 
198
207
  // Check if UTXO already exists
199
208
  if (state.globalUTXOSet[utxoKey]) {
200
- console.log(`โš ๏ธ UTXO ${utxoKey} already exists, skipping`)
209
+ debug(`โš ๏ธ UTXO ${utxoKey} already exists, skipping`)
201
210
  return
202
211
  }
203
212
 
@@ -229,7 +238,7 @@ function addUTXO (utxo, ownerAddress) {
229
238
  updateBlockchainMetadata(state)
230
239
  saveBlockchainState(state)
231
240
 
232
- console.log(`โœ… UTXO added: ${utxoKey} for ${ownerAddress}`)
241
+ debug(`โœ… UTXO added: ${utxoKey} for ${ownerAddress}`)
233
242
  }
234
243
 
235
244
  /**
@@ -255,18 +264,18 @@ function updateBlockchainMetadata (state) {
255
264
  function getBlockchainStats () {
256
265
  const state = loadBlockchainState()
257
266
 
258
- console.log('๐ŸŒ Blockchain State Statistics:')
259
- console.log('โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•')
260
- console.log(`๐Ÿ“Š Total Wallets: ${state.metadata.totalWallets}`)
261
- console.log(`๐Ÿ’ฐ Total UTXOs: ${state.metadata.totalUTXOs}`)
262
- console.log(`๐Ÿ’Ž Total Value: ${state.metadata.totalValue} satoshis`)
263
- console.log(`๐Ÿ—๏ธ Block Height: ${state.metadata.blockHeight}`)
264
- console.log(`๐Ÿ• Last Updated: ${state.metadata.lastUpdated}\n`)
267
+ debug('๐ŸŒ Blockchain State Statistics:')
268
+ debug('โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•')
269
+ debug(`๐Ÿ“Š Total Wallets: ${state.metadata.totalWallets}`)
270
+ debug(`๐Ÿ’ฐ Total UTXOs: ${state.metadata.totalUTXOs}`)
271
+ debug(`๐Ÿ’Ž Total Value: ${state.metadata.totalValue} satoshis`)
272
+ debug(`๐Ÿ—๏ธ Block Height: ${state.metadata.blockHeight}`)
273
+ debug(`๐Ÿ• Last Updated: ${state.metadata.lastUpdated}\n`)
265
274
 
266
275
  if (Object.keys(state.wallets).length > 0) {
267
- console.log('๐Ÿ‘› Registered Wallets:')
276
+ debug('๐Ÿ‘› Registered Wallets:')
268
277
  Object.entries(state.wallets).forEach(([address, wallet]) => {
269
- console.log(` ${address}: ${wallet.utxos.length} UTXOs, ${wallet.totalValue} sats`)
278
+ debug(` ${address}: ${wallet.utxos.length} UTXOs, ${wallet.totalValue} sats`)
270
279
  })
271
280
  }
272
281
 
@@ -280,14 +289,14 @@ function importWalletFromFile () {
280
289
  const walletPath = path.join(__dirname, 'wallet.json')
281
290
 
282
291
  if (!fs.existsSync(walletPath)) {
283
- console.log('โŒ No wallet.json found to import')
292
+ debug('โŒ No wallet.json found to import')
284
293
  return false
285
294
  }
286
295
 
287
296
  try {
288
297
  const walletData = JSON.parse(fs.readFileSync(walletPath, 'utf8'))
289
298
 
290
- console.log('๐Ÿ“ฅ Importing wallet from wallet.json...')
299
+ debug('๐Ÿ“ฅ Importing wallet from wallet.json...')
291
300
 
292
301
  const walletInfo = {
293
302
  registeredAt: new Date().toISOString(),
@@ -296,7 +305,7 @@ function importWalletFromFile () {
296
305
 
297
306
  registerWallet(walletData.wallet.address, walletInfo)
298
307
 
299
- console.log('โœ… Wallet imported successfully')
308
+ debug('โœ… Wallet imported successfully')
300
309
  return true
301
310
  } catch (error) {
302
311
  console.error('โŒ Error importing wallet:', error.message)
@@ -313,7 +322,7 @@ if (require.main === module) {
313
322
  } else if (args[0] === 'init') {
314
323
  const state = initializeBlockchainState()
315
324
  saveBlockchainState(state)
316
- console.log('๐Ÿ†• Initialized new blockchain state')
325
+ debug('๐Ÿ†• Initialized new blockchain state')
317
326
  }
318
327
 
319
328
  getBlockchainStats()
package/demos/README.md DELETED
@@ -1,188 +0,0 @@
1
- # ๐Ÿš€ SmartLedger-BSV Demo Collection
2
-
3
- This directory contains interactive demonstrations of the SmartLedger-BSV smart contract framework capabilities.
4
-
5
- ## ๐Ÿ“‹ Available Demos
6
-
7
- ### 1. ๐ŸŒ **HTML Interactive Demo** (`smart_contract_demo.html`)
8
- **Web-based interactive demonstration with visual interface**
9
-
10
- - **Purpose:** Browser-based exploration of smart contract features
11
- - **Interface:** Modern web UI with tabs, buttons, and real-time output
12
- - **Best for:** Visual learners, presentations, and quick exploration
13
-
14
- **Features:**
15
- - ๐Ÿ“š **Basics Tab** - Library loading and feature overview
16
- - ๐Ÿ”’ **Covenant Builder** - Interactive covenant creation with multiple types
17
- - ๐Ÿงพ **Preimage Parser** - BIP-143 transaction field extraction
18
- - ๐Ÿ’Ž **UTXO Generator** - Mock UTXO creation and management
19
- - ๐Ÿ› ๏ธ **Script Tools** - Bitcoin Script building and analysis
20
-
21
- **Usage:**
22
- ```bash
23
- # Serve locally (requires http-server or similar)
24
- npx http-server demos/
25
- # Then open http://localhost:8080/smart_contract_demo.html
26
-
27
- # Or open directly in browser
28
- open demos/smart_contract_demo.html
29
- ```
30
-
31
- ---
32
-
33
- ### 2. ๐Ÿ’ป **Node.js CLI Demo** (`smart_contract_demo.js`)
34
- **Command-line interactive demonstration for developers**
35
-
36
- - **Purpose:** Terminal-based smart contract development workflow
37
- - **Interface:** Interactive CLI with colored output and structured commands
38
- - **Best for:** Developers, automation, CI/CD integration
39
-
40
- **Features:**
41
- - ๐ŸŽฏ **Interactive Mode** - Full CLI experience with command history
42
- - โšก **Direct Commands** - Run specific features without interaction
43
- - ๐ŸŽจ **Colored Output** - Enhanced readability with chalk (optional)
44
- - ๐Ÿ“Š **Structured Logging** - Timestamped output with status indicators
45
- - ๐Ÿ”ง **Developer-Friendly** - Perfect for scripting and automation
46
-
47
- **Usage:**
48
-
49
- ```bash
50
- # Interactive mode
51
- node demos/smart_contract_demo.js
52
-
53
- # Show help
54
- node demos/smart_contract_demo.js --help
55
-
56
- # Run specific features
57
- node demos/smart_contract_demo.js --feature basics
58
- node demos/smart_contract_demo.js --feature covenant
59
- node demos/smart_contract_demo.js --feature preimage
60
- node demos/smart_contract_demo.js --feature utxo
61
- node demos/smart_contract_demo.js --feature scripts
62
- ```
63
-
64
- **Interactive Commands:**
65
- ```
66
- smartledger-bsv> basics # Load library and run tests
67
- smartledger-bsv> covenant generate simple # Generate simple covenant
68
- smartledger-bsv> covenant test # Test current covenant
69
- smartledger-bsv> preimage sample # Generate sample transaction
70
- smartledger-bsv> utxo generate 50000 # Generate 50k sat UTXO
71
- smartledger-bsv> scripts build # Build sample script
72
- smartledger-bsv> examples # Show real-world use cases
73
- smartledger-bsv> help # Show all commands
74
- smartledger-bsv> exit # Exit demo
75
- ```
76
-
77
- ---
78
-
79
- ## ๐ŸŽฏ **Feature Comparison**
80
-
81
- | Feature | HTML Demo | Node.js Demo |
82
- |---------|-----------|--------------|
83
- | **Interface** | Visual web UI | Command-line interface |
84
- | **Interactivity** | Click-based | Type-based commands |
85
- | **Real-time Output** | Browser console + UI | Terminal with colors |
86
- | **Covenant Builder** | Form inputs + dropdowns | Command parameters |
87
- | **Script Analysis** | Visual results panel | Structured text output |
88
- | **UTXO Management** | Interactive forms | Command-driven |
89
- | **Automation** | Manual only | Scriptable commands |
90
- | **Dependencies** | Modern browser | Node.js (chalk optional) |
91
- | **Best Use Case** | Learning & exploration | Development & testing |
92
-
93
- ---
94
-
95
- ## ๐Ÿ”ง **Common Features Demonstrated**
96
-
97
- Both demos showcase the complete SmartLedger-BSV functionality:
98
-
99
- ### **Core Capabilities**
100
- - โœ… **Private Key & Address Generation** - Create BSV wallets
101
- - โœ… **Transaction Building** - Construct valid BSV transactions
102
- - โœ… **Script Creation** - Build custom Bitcoin Scripts
103
- - โœ… **UTXO Management** - Generate and spend test UTXOs
104
- - โœ… **Preimage Parsing** - Extract BIP-143 transaction fields
105
- - โœ… **Covenant Logic** - Create smart contract spending conditions
106
-
107
- ### **Smart Contract Types**
108
- 1. **Simple Covenants** - Basic spending restrictions
109
- 2. **Timelock Covenants** - Time-based spending conditions using preimage validation
110
- 3. **Multisig Covenants** - Multi-signature requirements
111
- 4. **Conditional Covenants** - IF/ELSE spending paths
112
-
113
- ### **Advanced Features**
114
- - ๐Ÿงพ **BIP-143 Preimage Extraction** - Parse transaction preimages
115
- - ๐Ÿ“Š **SIGHASH Analysis** - Understand signature hash types
116
- - ๐Ÿ” **Script Debugging** - Step-through script execution
117
- - โšก **Script Optimization** - Minimize script size and cost
118
- - ๐Ÿงช **Local Testing** - Verify scripts without blockchain access
119
-
120
- ---
121
-
122
- ## ๐Ÿš€ **Quick Start Guide**
123
-
124
- ### **For Visual Learners (HTML Demo)**
125
- 1. Open `smart_contract_demo.html` in your browser
126
- 2. Click "Load BSV Smart Contract Library"
127
- 3. Explore each tab (Basics โ†’ Covenant โ†’ Preimage โ†’ UTXO โ†’ Scripts)
128
- 4. Try the real-world use case examples
129
-
130
- ### **For Developers (Node.js Demo)**
131
- 1. Run `node demos/smart_contract_demo.js`
132
- 2. Type `basics` to load and test the library
133
- 3. Try `covenant generate simple` to create your first covenant
134
- 4. Use `help` to see all available commands
135
- 5. Explore with `utxo generate`, `preimage sample`, etc.
136
-
137
- ---
138
-
139
- ## ๐Ÿ“š **Learning Path**
140
-
141
- **Recommended progression through the demos:**
142
-
143
- 1. **๐ŸŽฏ Start Here:** `basics` - Understand core BSV functionality
144
- 2. **๐Ÿ—๏ธ Build:** `covenant generate` - Create your first smart contract
145
- 3. **๐Ÿ” Analyze:** `preimage sample` - Understand transaction structure
146
- 4. **๐Ÿ’Ž Manage:** `utxo generate` - Handle UTXOs and spending
147
- 5. **๐Ÿ› ๏ธ Script:** `scripts build` - Custom Bitcoin Script development
148
- 6. **๐ŸŽ“ Advanced:** `examples` - Real-world smart contract patterns
149
-
150
- ---
151
-
152
- ## ๐Ÿ”— **Related Documentation**
153
-
154
- - **[Usage Guide](../docs/SMARTLEDGER_BSV_USAGE_GUIDE.md)** - Complete API reference
155
- - **[Usage Answers](../docs/SMARTLEDGER_BSV_USAGE_ANSWERS.md)** - FAQ and troubleshooting
156
- - **[Smart Contract Guide](../docs/advanced/SMART_CONTRACT_GUIDE.md)** - Advanced development
157
- - **[Examples Directory](../examples/)** - Additional code samples
158
- - **[GitHub Repository](https://github.com/codenlighten/smartledger-bsv)** - Source code
159
-
160
- ---
161
-
162
- ## ๐Ÿ†˜ **Support & Troubleshooting**
163
-
164
- ### **Common Issues**
165
-
166
- **HTML Demo:**
167
- - **Bundle not found:** Ensure `../bsv.bundle.js` exists (run `npm run build`)
168
- - **CORS issues:** Serve via HTTP server, don't open file:// directly
169
- - **Console errors:** Check browser developer tools for detailed errors
170
-
171
- **Node.js Demo:**
172
- - **Module errors:** Run `npm install` to ensure dependencies
173
- - **Chalk missing:** Demo works without chalk (fallback to plain text)
174
- - **Permission denied:** Use `chmod +x demos/smart_contract_demo.js`
175
-
176
- ### **Getting Help**
177
-
178
- - **Issues:** [GitHub Issues](https://github.com/codenlighten/smartledger-bsv/issues)
179
- - **Documentation:** Check the `docs/` directory for detailed guides
180
- - **Examples:** Browse `examples/` for working code samples
181
-
182
- ---
183
-
184
- **Created by:** SmartLedger-BSV Development Team
185
- **Version:** v3.3.4
186
- **Last Updated:** October 30, 2025
187
-
188
- *Both demos provide identical functionality - choose the interface that works best for your workflow!* ๐ŸŽ‰