@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.
- package/CHANGELOG.md +336 -0
- package/README.md +72 -72
- package/SECURITY.md +88 -0
- package/bin/cli.js +13 -8
- package/bsv-covenant.min.js +4 -4
- package/bsv-gdaf.min.js +5 -5
- package/bsv-ltp.min.js +7 -7
- package/bsv-smartcontract.min.js +5 -5
- package/bsv.bundle.js +5 -5
- package/bsv.d.ts +486 -9
- package/bsv.min.js +5 -5
- package/docs/COVENANT_DEVELOPMENT_RESOLVED.md +2 -2
- package/docs/MODULE_REFERENCE_COMPLETE.md +61 -58
- package/docs/advanced/LEGAL_TOKEN_PROTOCOL.md +3 -3
- package/docs/advanced/UTXO_MANAGER_GUIDE.md +1 -1
- package/docs/getting-started/INSTALLATION.md +30 -30
- package/docs/getting-started/QUICK_START.md +18 -18
- package/docs/migration/FROM_BSV_1_5_6.md +16 -10
- package/gdaf-entry.js +1 -2
- package/index.js +20 -7
- package/lib/smart_contract/covenant.js +10 -1
- package/lib/smartutxo.js +20 -12
- package/lib/transaction/transaction.js +7 -0
- package/ltp-entry.js +1 -2
- package/package.json +3 -3
- package/utilities/blockchain-state.js +32 -23
- package/demos/README.md +0 -188
- package/demos/architecture_demo.js +0 -247
- package/demos/browser-test.html +0 -1208
- package/demos/bsv_wallet_demo.js +0 -242
- package/demos/complete_ltp_demo.js +0 -511
- package/demos/debug_tools_demo.js +0 -87
- package/demos/demo_features.js +0 -123
- package/demos/easy_interface_demo.js +0 -109
- package/demos/ecies_demo.js +0 -182
- package/demos/gdaf_demo.js +0 -237
- package/demos/ltp_demo.js +0 -361
- package/demos/ltp_primitives_demo.js +0 -403
- package/demos/message_demo.js +0 -209
- package/demos/preimage_separation_demo.js +0 -383
- package/demos/script_helper_demo.js +0 -289
- package/demos/security_demo.js +0 -287
- package/demos/shamir_demo.js +0 -121
- package/demos/simple_demo.js +0 -204
- package/demos/simple_p2pkh_demo.js +0 -169
- package/demos/simple_utxo_preimage_demo.js +0 -196
- package/demos/smart_contract_demo.html +0 -1347
- package/demos/smart_contract_demo.js +0 -910
- package/demos/utxo_generator_demo.js +0 -244
- package/demos/validation_pipeline_demo.js +0 -155
- package/demos/web3keys.html +0 -740
- package/examples/README.md +0 -200
- package/examples/basic/transaction-creation.js +0 -534
- package/examples/basic/transaction_signature_api_gap.js +0 -178
- package/examples/complete_workflow_demo.js +0 -783
- package/examples/covenants/advanced_covenant_demo.js +0 -219
- package/examples/covenants/covenant_interface_demo.js +0 -270
- package/examples/covenants/covenant_manual_signature_resolved.js +0 -212
- package/examples/covenants/covenant_signature_template.js +0 -117
- package/examples/covenants2/covenant_bidirectional_example.js +0 -262
- package/examples/covenants2/covenant_utils_demo.js +0 -120
- package/examples/covenants2/preimage_covenant_utils.js +0 -287
- package/examples/covenants2/production_integration.js +0 -256
- package/examples/data/covenant_utxos.json +0 -28
- package/examples/data/utxos.json +0 -26
- package/examples/definitive_working_demo.js +0 -261
- package/examples/final_working_contracts.js +0 -338
- package/examples/legacy/README.md +0 -11
- package/examples/legacy/smart_contract_test_integration.js +0 -269
- package/examples/legacy/test_builtin_verify.js +0 -117
- package/examples/legacy/test_debug_integration.js +0 -71
- package/examples/legacy/test_ecdsa_little.js +0 -70
- package/examples/legacy/test_shamir.js +0 -221
- package/examples/legacy/test_smartverify_der.js +0 -110
- package/examples/preimage/README.md +0 -178
- package/examples/preimage/extract_preimage_bidirectional.js +0 -421
- package/examples/preimage/generate_sample_preimage.js +0 -208
- package/examples/preimage/generate_sighash_examples.js +0 -152
- package/examples/preimage/parse_preimage.js +0 -117
- package/examples/preimage/test_preimage_extractor.js +0 -53
- package/examples/preimage/test_varint_extraction.js +0 -95
- package/examples/scripts/custom_script_helper_example.js +0 -273
- package/examples/scripts/script_interpreter.js +0 -193
- package/examples/smart_contract/complete_workflow_demo.js +0 -343
- package/examples/smart_contract/covenant_builder_demo.js +0 -176
- package/examples/smart_contract/script_testing_integration.js +0 -198
- package/examples/smart_contract_templates.js +0 -718
- 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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
64
|
+
debug(`๐พ Saved blockchain state with ${utxoCount} UTXOs`)
|
|
57
65
|
} catch (error) {
|
|
58
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
200
|
+
debug('๐ Blockchain state reset')
|
|
193
201
|
}
|
|
194
202
|
} catch (error) {
|
|
195
|
-
|
|
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
|
-
|
|
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.
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
102
|
+
debug(`๐ Registering wallet: ${walletAddress}`)
|
|
94
103
|
|
|
95
104
|
const state = loadBlockchainState()
|
|
96
105
|
|
|
97
106
|
if (state.wallets[walletAddress]) {
|
|
98
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
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
|
-
|
|
276
|
+
debug('๐ Registered Wallets:')
|
|
268
277
|
Object.entries(state.wallets).forEach(([address, wallet]) => {
|
|
269
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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!* ๐
|