smartledger-bsv 3.3.3 โ 3.3.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 +20 -7
- package/README.md +18 -1
- package/bsv-covenant.min.js +5 -5
- package/bsv-gdaf.min.js +4 -4
- package/bsv-ltp.min.js +4 -4
- package/bsv-mnemonic.min.js +4 -4
- package/bsv-smartcontract.min.js +4 -4
- package/bsv.bundle.js +4 -4
- package/bsv.min.js +4 -4
- package/demos/README.md +188 -0
- package/demos/architecture_demo.js +247 -0
- package/demos/bsv_wallet_demo.js +242 -0
- package/demos/complete_ltp_demo.js +511 -0
- package/demos/debug_tools_demo.js +87 -0
- package/demos/demo_features.js +123 -0
- package/demos/easy_interface_demo.js +109 -0
- package/demos/ecies_demo.js +182 -0
- package/demos/gdaf_core_test.js +131 -0
- package/demos/gdaf_demo.js +237 -0
- package/demos/ltp_demo.js +361 -0
- package/demos/ltp_primitives_demo.js +403 -0
- package/demos/message_demo.js +209 -0
- package/demos/preimage_separation_demo.js +383 -0
- package/demos/script_helper_demo.js +289 -0
- package/demos/security_demo.js +287 -0
- package/demos/shamir_demo.js +121 -0
- package/demos/simple_demo.js +204 -0
- package/demos/simple_p2pkh_demo.js +169 -0
- package/demos/simple_utxo_preimage_demo.js +196 -0
- package/demos/smart_contract_demo.html +1347 -0
- package/demos/smart_contract_demo.js +910 -0
- package/demos/utxo_generator_demo.js +244 -0
- package/demos/validation_pipeline_demo.js +155 -0
- package/demos/web3keys.html +740 -0
- package/docs/BUNDLE_UPDATE_SUMMARY.md +40 -0
- package/docs/FIX_CREATEHMAC_ISSUE.md +91 -0
- package/docs/SMARTLEDGER_BSV_USAGE_ANSWERS.md +477 -0
- package/docs/SMARTLEDGER_BSV_USAGE_EXAMPLES.js +372 -0
- package/docs/SMARTLEDGER_BSV_USAGE_GUIDE.md +555 -0
- package/docs/SMART_CONTRACT_DEVELOPMENT_GUIDE.md +1459 -0
- package/examples/complete_workflow_demo.js +783 -0
- package/examples/definitive_working_demo.js +261 -0
- package/examples/final_working_contracts.js +338 -0
- package/examples/smart_contract_templates.js +718 -0
- package/examples/working_smart_contracts.js +348 -0
- package/lib/mnemonic/pbkdf2.browser.js +69 -0
- package/lib/mnemonic/pbkdf2.js +2 -68
- package/lib/mnemonic/pbkdf2.node.js +68 -0
- package/package.json +17 -6
- package/tests/browser-compatibility/README.md +35 -0
- package/tests/browser-compatibility/test-cdn-vs-local.html +186 -0
- package/tests/browser-compatibility/test-pbkdf2.html +51 -0
package/demos/README.md
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
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.3
|
|
186
|
+
**Last Updated:** October 30, 2025
|
|
187
|
+
|
|
188
|
+
*Both demos provide identical functionality - choose the interface that works best for your workflow!* ๐
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SmartLedger-BSV Legal Token Protocol (LTP) - Primitives-Only Architecture Demo
|
|
3
|
+
*
|
|
4
|
+
* This demonstrates the key architectural difference:
|
|
5
|
+
* BEFORE: Library did blockchain publishing and storage
|
|
6
|
+
* AFTER: Library provides preparation primitives, external systems handle publishing
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const bsv = require('../index.js')
|
|
10
|
+
|
|
11
|
+
console.log('๐ SmartLedger-BSV LTP: Primitives-Only Architecture')
|
|
12
|
+
console.log('==================================================\n')
|
|
13
|
+
|
|
14
|
+
console.log('๐ ARCHITECTURAL TRANSFORMATION DEMO')
|
|
15
|
+
console.log('------------------------------------\n')
|
|
16
|
+
|
|
17
|
+
// Demo keys and identities
|
|
18
|
+
const issuerPrivateKey = new bsv.PrivateKey()
|
|
19
|
+
const ownerDID = `did:bsv:${new bsv.PrivateKey().publicKey.toString()}`
|
|
20
|
+
const obligorDID = `did:bsv:${new bsv.PrivateKey().publicKey.toString()}`
|
|
21
|
+
|
|
22
|
+
console.log('๐ Participants:')
|
|
23
|
+
console.log(` Issuer DID: ${issuerPrivateKey.publicKey.toString()}`)
|
|
24
|
+
console.log(` Owner DID: ${ownerDID}`)
|
|
25
|
+
console.log(` Obligor DID: ${obligorDID}\n`)
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* DEMONSTRATE CLAIM VALIDATION PRIMITIVES
|
|
29
|
+
*/
|
|
30
|
+
console.log('1๏ธโฃ CLAIM VALIDATION - Primitives Only')
|
|
31
|
+
console.log('=====================================')
|
|
32
|
+
|
|
33
|
+
const propertyClaimData = {
|
|
34
|
+
type: 'PropertyTitle',
|
|
35
|
+
property: {
|
|
36
|
+
address: '123 Blockchain Street',
|
|
37
|
+
parcel_id: 'BLK-2024-001',
|
|
38
|
+
property_type: 'residential'
|
|
39
|
+
},
|
|
40
|
+
owner: ownerDID
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// Get available schemas (unchanged utility)
|
|
44
|
+
const availableSchemas = bsv.getClaimSchemaNames()
|
|
45
|
+
console.log('๐ Available claim schemas:', availableSchemas.join(', '))
|
|
46
|
+
|
|
47
|
+
// Create claim template (utility function)
|
|
48
|
+
const claimTemplate = bsv.createClaimTemplate('PropertyTitle')
|
|
49
|
+
console.log('๐ Claim template structure:')
|
|
50
|
+
console.log(' Required fields:', Object.keys(claimTemplate).slice(0, 3).join(', '), '...')
|
|
51
|
+
|
|
52
|
+
console.log('\n๐ง PRIMITIVES-ONLY APPROACH:')
|
|
53
|
+
console.log(' โ
Library validates claim structure')
|
|
54
|
+
console.log(' โ
Library provides canonicalization')
|
|
55
|
+
console.log(' โ
Library generates claim hash')
|
|
56
|
+
console.log(' โ Library does NOT store claims')
|
|
57
|
+
console.log(' โ Library does NOT publish to blockchain')
|
|
58
|
+
|
|
59
|
+
// Demonstrate claim processing primitives
|
|
60
|
+
const claimHash = bsv.hashClaim(propertyClaimData)
|
|
61
|
+
const canonicalClaim = bsv.canonicalizeClaim(propertyClaimData)
|
|
62
|
+
|
|
63
|
+
console.log('๐ Claim processing results:')
|
|
64
|
+
console.log(` Claim Hash: ${claimHash}`)
|
|
65
|
+
console.log(` Canonical Form: ${canonicalClaim.length} bytes`)
|
|
66
|
+
console.log('')
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* DEMONSTRATE RIGHT TOKEN PRIMITIVES
|
|
70
|
+
*/
|
|
71
|
+
console.log('2๏ธโฃ RIGHT TOKEN - Preparation Primitives')
|
|
72
|
+
console.log('=======================================')
|
|
73
|
+
|
|
74
|
+
console.log('๐ง PRIMITIVES-ONLY APPROACH:')
|
|
75
|
+
|
|
76
|
+
// Get available right types
|
|
77
|
+
const rightTypes = bsv.getRightTypes()
|
|
78
|
+
console.log('โ๏ธ Available right types:', Object.keys(rightTypes).slice(0, 4).join(', '), '...')
|
|
79
|
+
|
|
80
|
+
// Prepare right token (doesn't create, just prepares structure)
|
|
81
|
+
try {
|
|
82
|
+
const rightTokenPrep = bsv.prepareRightToken(
|
|
83
|
+
'PROPERTY_OWNERSHIP',
|
|
84
|
+
`did:bsv:${issuerPrivateKey.publicKey.toString()}`,
|
|
85
|
+
ownerDID,
|
|
86
|
+
propertyClaimData,
|
|
87
|
+
issuerPrivateKey,
|
|
88
|
+
{
|
|
89
|
+
jurisdiction: 'demo_jurisdiction',
|
|
90
|
+
validUntil: '2034-01-15'
|
|
91
|
+
}
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
console.log('๐ Right token prepared:')
|
|
95
|
+
console.log(` Token ID: ${rightTokenPrep.tokenId}`)
|
|
96
|
+
console.log(` Right Type: ${rightTokenPrep.rightType}`)
|
|
97
|
+
console.log(` Valid Until: ${rightTokenPrep.validUntil}`)
|
|
98
|
+
console.log(` Jurisdiction: ${rightTokenPrep.jurisdiction}`)
|
|
99
|
+
|
|
100
|
+
// Prepare verification data
|
|
101
|
+
const verificationPrep = bsv.prepareRightTokenVerification(rightTokenPrep.token)
|
|
102
|
+
console.log(` Verification Ready: ${verificationPrep.isValid ? 'YES' : 'NO'}`)
|
|
103
|
+
|
|
104
|
+
console.log('\n โ
Library prepares token structure')
|
|
105
|
+
console.log(' โ
Library validates token format')
|
|
106
|
+
console.log(' โ
Library signs token data')
|
|
107
|
+
console.log(' โ Library does NOT publish to blockchain')
|
|
108
|
+
console.log(' โ Library does NOT store in registry')
|
|
109
|
+
|
|
110
|
+
} catch (error) {
|
|
111
|
+
console.log('โ ๏ธ Right token preparation demo skipped (module loading)')
|
|
112
|
+
console.log(' Expected: Token preparation without blockchain publishing')
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
console.log('')
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* DEMONSTRATE OBLIGATION PRIMITIVES
|
|
119
|
+
*/
|
|
120
|
+
console.log('3๏ธโฃ OBLIGATION TOKEN - Management Primitives')
|
|
121
|
+
console.log('===========================================')
|
|
122
|
+
|
|
123
|
+
console.log('๐ง PRIMITIVES-ONLY APPROACH:')
|
|
124
|
+
|
|
125
|
+
// Get obligation types and statuses
|
|
126
|
+
try {
|
|
127
|
+
const obligationTypes = bsv.getObligationTypes()
|
|
128
|
+
const obligationStatuses = bsv.getObligationStatus()
|
|
129
|
+
|
|
130
|
+
console.log('๐ Obligation framework:')
|
|
131
|
+
console.log(` Types available: ${Object.keys(obligationTypes).length}`)
|
|
132
|
+
console.log(` Status options: ${Object.keys(obligationStatuses).length}`)
|
|
133
|
+
console.log(` Priority levels: ${Object.keys(bsv.getObligationPriority()).length}`)
|
|
134
|
+
|
|
135
|
+
console.log('\n โ
Library prepares obligation tokens')
|
|
136
|
+
console.log(' โ
Library validates fulfillment data')
|
|
137
|
+
console.log(' โ
Library tracks obligation status')
|
|
138
|
+
console.log(' โ Library does NOT execute payments')
|
|
139
|
+
console.log(' โ Library does NOT enforce obligations')
|
|
140
|
+
|
|
141
|
+
} catch (error) {
|
|
142
|
+
console.log('โ ๏ธ Obligation demo skipped (module loading)')
|
|
143
|
+
console.log(' Expected: Obligation management without execution')
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
console.log('')
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* DEMONSTRATE REGISTRY PRIMITIVES
|
|
150
|
+
*/
|
|
151
|
+
console.log('4๏ธโฃ REGISTRY MANAGEMENT - Preparation Primitives')
|
|
152
|
+
console.log('===============================================')
|
|
153
|
+
|
|
154
|
+
console.log('๐ง PRIMITIVES-ONLY APPROACH:')
|
|
155
|
+
console.log(' โ
Library prepares registry data structures')
|
|
156
|
+
console.log(' โ
Library formats token registration data')
|
|
157
|
+
console.log(' โ
Library validates registry queries')
|
|
158
|
+
console.log(' โ Library does NOT store registry data')
|
|
159
|
+
console.log(' โ Library does NOT manage database connections')
|
|
160
|
+
|
|
161
|
+
// Simulate registry preparation
|
|
162
|
+
console.log('๐ Registry operations prepared:')
|
|
163
|
+
console.log(' โข Token registration data formatted')
|
|
164
|
+
console.log(' โข Search query structure validated')
|
|
165
|
+
console.log(' โข Audit log format prepared')
|
|
166
|
+
console.log(' โข Statistics query template ready')
|
|
167
|
+
console.log('')
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* DEMONSTRATE BLOCKCHAIN ANCHORING PRIMITIVES
|
|
171
|
+
*/
|
|
172
|
+
console.log('5๏ธโฃ BLOCKCHAIN ANCHORING - Commitment Primitives')
|
|
173
|
+
console.log('===============================================')
|
|
174
|
+
|
|
175
|
+
console.log('๐ง PRIMITIVES-ONLY APPROACH:')
|
|
176
|
+
console.log(' โ
Library prepares commitment hashes')
|
|
177
|
+
console.log(' โ
Library creates merkle tree structures')
|
|
178
|
+
console.log(' โ
Library validates anchor proofs')
|
|
179
|
+
console.log(' โ Library does NOT publish transactions')
|
|
180
|
+
console.log(' โ Library does NOT manage wallet keys')
|
|
181
|
+
|
|
182
|
+
// Simulate anchor preparation
|
|
183
|
+
console.log('โ๏ธ Blockchain operations prepared:')
|
|
184
|
+
console.log(' โข Token commitment hash: ready for transaction')
|
|
185
|
+
console.log(' โข Batch merkle root: ready for efficient anchoring')
|
|
186
|
+
console.log(' โข Verification proof: ready for anchor validation')
|
|
187
|
+
console.log(' โข Revocation format: ready for token cancellation')
|
|
188
|
+
console.log('')
|
|
189
|
+
|
|
190
|
+
/**
|
|
191
|
+
* SUMMARY OF ARCHITECTURAL BENEFITS
|
|
192
|
+
*/
|
|
193
|
+
console.log('๐ฏ PRIMITIVES-ONLY ARCHITECTURE BENEFITS')
|
|
194
|
+
console.log('========================================')
|
|
195
|
+
console.log('')
|
|
196
|
+
console.log('๐๏ธ SEPARATION OF CONCERNS:')
|
|
197
|
+
console.log(' ๐ SmartLedger-BSV: Foundation library with crypto primitives')
|
|
198
|
+
console.log(' ๐ง External Apps: Handle UI, storage, and blockchain publishing')
|
|
199
|
+
console.log(' โ๏ธ Legal Framework: Validated structure and compliance tools')
|
|
200
|
+
console.log('')
|
|
201
|
+
console.log('๐ช DEVELOPER BENEFITS:')
|
|
202
|
+
console.log(' โข Maximum flexibility in implementation choices')
|
|
203
|
+
console.log(' โข No vendor lock-in to specific platforms or blockchains')
|
|
204
|
+
console.log(' โข Clean separation between crypto/legal logic and app logic')
|
|
205
|
+
console.log(' โข Easy integration with existing systems and workflows')
|
|
206
|
+
console.log('')
|
|
207
|
+
console.log('โก LIBRARY ADVANTAGES:')
|
|
208
|
+
console.log(' โข Focused on what it does best: cryptography and validation')
|
|
209
|
+
console.log(' โข Smaller footprint and fewer dependencies')
|
|
210
|
+
console.log(' โข More predictable behavior and easier testing')
|
|
211
|
+
console.log(' โข Clear API boundaries and responsibilities')
|
|
212
|
+
console.log('')
|
|
213
|
+
console.log('๐ INTEGRATION PATTERN:')
|
|
214
|
+
console.log(' 1. Use SmartLedger-BSV to prepare and validate legal tokens')
|
|
215
|
+
console.log(' 2. Use external systems for blockchain publishing')
|
|
216
|
+
console.log(' 3. Use external systems for storage and registries')
|
|
217
|
+
console.log(' 4. Use external systems for user interfaces and workflows')
|
|
218
|
+
console.log('')
|
|
219
|
+
console.log('๐ RESULT: Complete foundation for any Legal Token Protocol')
|
|
220
|
+
console.log(' application while maintaining architectural flexibility!')
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* SHOW EXAMPLE EXTERNAL SYSTEM INTEGRATION
|
|
224
|
+
*/
|
|
225
|
+
console.log('')
|
|
226
|
+
console.log('๐ EXAMPLE: How External Systems Would Use These Primitives')
|
|
227
|
+
console.log('=========================================================')
|
|
228
|
+
console.log('')
|
|
229
|
+
console.log('// External Application Code Example:')
|
|
230
|
+
console.log('const bsv = require("smartledger-bsv")')
|
|
231
|
+
console.log('const MyBlockchainAPI = require("my-blockchain-service")')
|
|
232
|
+
console.log('const MyStorage = require("my-database-service")')
|
|
233
|
+
console.log('')
|
|
234
|
+
console.log('// 1. Use SmartLedger-BSV to prepare legal token')
|
|
235
|
+
console.log('const tokenPrep = bsv.prepareRightToken(...)')
|
|
236
|
+
console.log('')
|
|
237
|
+
console.log('// 2. Use external service to publish to blockchain')
|
|
238
|
+
console.log('const txResult = await MyBlockchainAPI.publish(tokenPrep.commitment)')
|
|
239
|
+
console.log('')
|
|
240
|
+
console.log('// 3. Use external service to store token data')
|
|
241
|
+
console.log('const storeResult = await MyStorage.save(tokenPrep.token)')
|
|
242
|
+
console.log('')
|
|
243
|
+
console.log('// 4. Use SmartLedger-BSV to verify results')
|
|
244
|
+
console.log('const verification = bsv.verifyTokenAnchor(token, txResult.txid)')
|
|
245
|
+
console.log('')
|
|
246
|
+
console.log('This pattern gives developers complete control while ensuring')
|
|
247
|
+
console.log('cryptographic and legal correctness through SmartLedger-BSV!')
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* SmartLedger Real BSV Wallet Demo
|
|
5
|
+
*
|
|
6
|
+
* This script demonstrates how to use SmartLedger-BSV with real BSV addresses
|
|
7
|
+
* for UTXO management, transaction creation, and validation.
|
|
8
|
+
*
|
|
9
|
+
* Usage Examples:
|
|
10
|
+
* - Check real BSV address balance and UTXOs
|
|
11
|
+
* - Create and validate real BSV transactions
|
|
12
|
+
* - Test signature verification with real data
|
|
13
|
+
* - Optionally broadcast transactions to BSV network
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
const bsv = require('../index.js');
|
|
17
|
+
|
|
18
|
+
// Demo configuration - replace with your own for real use
|
|
19
|
+
const DEMO_CONFIG = {
|
|
20
|
+
// Test private key (has 0 balance) - replace with your own for real testing
|
|
21
|
+
privateKey: 'L1aW4aubDFB7yfras2S1mN3bqg9nwySY8nkoLmJebSLD5BWv3ENZ',
|
|
22
|
+
|
|
23
|
+
// Demo addresses for testing
|
|
24
|
+
testAddresses: {
|
|
25
|
+
bitcoinEater: '1BitcoinEaterAddressDontSendf59kuE', // Provably unspendable
|
|
26
|
+
satoshiGenesis: '12c6DSiU4Rq3P4ZxziKxzrL5LmMBrzjrJX' // Genesis block address
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
console.log('๐ SmartLedger Real BSV Wallet Demo');
|
|
31
|
+
console.log('===================================\n');
|
|
32
|
+
|
|
33
|
+
console.log('๐ก This demo shows how to:');
|
|
34
|
+
console.log(' โข Use real BSV private keys and addresses');
|
|
35
|
+
console.log(' โข Fetch real UTXOs from the BSV blockchain');
|
|
36
|
+
console.log(' โข Create and validate real BSV transactions');
|
|
37
|
+
console.log(' โข Test signature verification with real data');
|
|
38
|
+
console.log(' โข Optionally broadcast to the BSV network\n');
|
|
39
|
+
|
|
40
|
+
console.log('โ ๏ธ IMPORTANT SAFETY NOTES:');
|
|
41
|
+
console.log(' โข This demo uses a test key with 0 balance');
|
|
42
|
+
console.log(' โข Replace DEMO_CONFIG.privateKey with your own for real use');
|
|
43
|
+
console.log(' โข Always test on testnet first (use --testnet flag)');
|
|
44
|
+
console.log(' โข Broadcasting requires --broadcast flag for safety\n');
|
|
45
|
+
|
|
46
|
+
// Initialize wallet
|
|
47
|
+
const privateKey = new bsv.PrivateKey(DEMO_CONFIG.privateKey);
|
|
48
|
+
const address = privateKey.toAddress().toString();
|
|
49
|
+
|
|
50
|
+
console.log('๐ฑ Demo Wallet:');
|
|
51
|
+
console.log(`Private Key: ${DEMO_CONFIG.privateKey}`);
|
|
52
|
+
console.log(`Address: ${address}`);
|
|
53
|
+
console.log(`Public Key: ${privateKey.publicKey.toString()}\n`);
|
|
54
|
+
|
|
55
|
+
// Real BSV integration example
|
|
56
|
+
async function demonstrateRealBSV() {
|
|
57
|
+
console.log('๐ Real BSV Blockchain Integration:');
|
|
58
|
+
console.log('==================================');
|
|
59
|
+
console.log('');
|
|
60
|
+
console.log('๐ Real BSV integration available via separate modules');
|
|
61
|
+
|
|
62
|
+
console.log('1. โ
SmartLedger signature verification works');
|
|
63
|
+
console.log('2. โ
Real UTXO fetching via WhatsOnChain API');
|
|
64
|
+
console.log('3. โ
Transaction creation and validation');
|
|
65
|
+
console.log('4. โ
Broadcasting capability (when enabled)');
|
|
66
|
+
console.log('5. โ
Mock UTXO fallback for testing\n');
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Signature verification demo with real keys
|
|
70
|
+
function demonstrateSignatureVerification() {
|
|
71
|
+
console.log('๐ Signature Verification with Real Keys:');
|
|
72
|
+
console.log('=========================================');
|
|
73
|
+
|
|
74
|
+
// Create a message to sign
|
|
75
|
+
const message = `SmartLedger-BSV Demo - ${new Date().toISOString()}`;
|
|
76
|
+
const messageBuffer = Buffer.from(message, 'utf8');
|
|
77
|
+
const hash = bsv.crypto.Hash.sha256(messageBuffer);
|
|
78
|
+
|
|
79
|
+
console.log(`Message: "${message}"`);
|
|
80
|
+
console.log(`Hash: ${hash.toString('hex')}`);
|
|
81
|
+
|
|
82
|
+
// Create signature
|
|
83
|
+
const signature = bsv.crypto.ECDSA.sign(hash, privateKey);
|
|
84
|
+
const derSig = signature.toDER();
|
|
85
|
+
|
|
86
|
+
console.log(`Signature: ${derSig.toString('hex')}`);
|
|
87
|
+
console.log(`Is canonical: ${signature.isCanonical()}`);
|
|
88
|
+
|
|
89
|
+
// Verify signature - this was broken in v3.0.1, fixed in v3.0.2!
|
|
90
|
+
const verified1 = bsv.crypto.ECDSA.verify(hash, derSig, privateKey.publicKey);
|
|
91
|
+
const verified2 = bsv.SmartVerify.smartVerify(hash, derSig, privateKey.publicKey);
|
|
92
|
+
const isCanonical = bsv.SmartVerify.isCanonical(derSig);
|
|
93
|
+
|
|
94
|
+
console.log('\n๐ Verification Results:');
|
|
95
|
+
console.log(`ECDSA.verify(): ${verified1 ? 'โ
VALID' : 'โ INVALID'}`);
|
|
96
|
+
console.log(`SmartVerify.smartVerify(): ${verified2 ? 'โ
VALID' : 'โ INVALID'}`);
|
|
97
|
+
console.log(`SmartVerify.isCanonical(): ${isCanonical ? 'โ
CANONICAL' : 'โ NON-CANONICAL'}`);
|
|
98
|
+
|
|
99
|
+
if (verified1 && verified2 && isCanonical) {
|
|
100
|
+
console.log('\n๐ All signature verification methods working correctly!');
|
|
101
|
+
} else {
|
|
102
|
+
console.log('\nโ Signature verification failed - this indicates a bug');
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// Transaction creation demo
|
|
107
|
+
function demonstrateTransactionCreation() {
|
|
108
|
+
console.log('\n๐ธ Transaction Creation Demo:');
|
|
109
|
+
console.log('============================');
|
|
110
|
+
|
|
111
|
+
// Create a mock UTXO for demonstration
|
|
112
|
+
const mockUTXO = {
|
|
113
|
+
txid: '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef',
|
|
114
|
+
vout: 0,
|
|
115
|
+
address: address,
|
|
116
|
+
satoshis: 100000, // 1000 bits
|
|
117
|
+
script: '76a914' + bsv.Address.fromString(address).hashBuffer.toString('hex') + '88ac'
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
console.log('Mock UTXO for demo:');
|
|
121
|
+
console.log(` TXID: ${mockUTXO.txid}`);
|
|
122
|
+
console.log(` Vout: ${mockUTXO.vout}`);
|
|
123
|
+
console.log(` Address: ${mockUTXO.address}`);
|
|
124
|
+
console.log(` Satoshis: ${mockUTXO.satoshis}`);
|
|
125
|
+
|
|
126
|
+
try {
|
|
127
|
+
// Create transaction
|
|
128
|
+
const transaction = new bsv.Transaction()
|
|
129
|
+
.from(mockUTXO)
|
|
130
|
+
.to(DEMO_CONFIG.testAddresses.bitcoinEater, 1000)
|
|
131
|
+
.change(address)
|
|
132
|
+
.sign(privateKey);
|
|
133
|
+
|
|
134
|
+
console.log('\n๐๏ธ Transaction Created:');
|
|
135
|
+
console.log(` Transaction ID: ${transaction.id}`);
|
|
136
|
+
console.log(` Inputs: ${transaction.inputs.length}`);
|
|
137
|
+
console.log(` Outputs: ${transaction.outputs.length}`);
|
|
138
|
+
console.log(` Size: ${transaction.toBuffer().length} bytes`);
|
|
139
|
+
|
|
140
|
+
// Validate transaction
|
|
141
|
+
const isValid = transaction.verify();
|
|
142
|
+
console.log(` Validation: ${isValid ? 'โ
VALID' : 'โ INVALID'}`);
|
|
143
|
+
|
|
144
|
+
if (isValid) {
|
|
145
|
+
console.log(` Raw TX: ${transaction.toString()}`);
|
|
146
|
+
console.log('\nโ
Transaction created and validated successfully!');
|
|
147
|
+
console.log('๐ก This transaction could be broadcast with real UTXOs');
|
|
148
|
+
} else {
|
|
149
|
+
console.log('\nโ Transaction validation failed');
|
|
150
|
+
}
|
|
151
|
+
} catch (error) {
|
|
152
|
+
console.log(`\nโ Transaction creation failed: ${error.message}`);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// UTXO management demo
|
|
157
|
+
function demonstrateUTXOManagement() {
|
|
158
|
+
console.log('\n๐ฐ UTXO Management Demo:');
|
|
159
|
+
console.log('========================');
|
|
160
|
+
|
|
161
|
+
// Create SmartUTXO manager
|
|
162
|
+
const utxoManager = new bsv.SmartUTXO();
|
|
163
|
+
|
|
164
|
+
// Create some mock UTXOs
|
|
165
|
+
const mockUTXOs = utxoManager.createMockUTXOs(address, 3, 50000);
|
|
166
|
+
|
|
167
|
+
console.log('Adding mock UTXOs to management system:');
|
|
168
|
+
mockUTXOs.forEach((utxo, i) => {
|
|
169
|
+
utxoManager.addUTXO(utxo);
|
|
170
|
+
console.log(` ${i + 1}: ${utxo.txid.substring(0, 16)}...${utxo.txid.substring(48)}:${utxo.vout} = ${utxo.satoshis} sats`);
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
// Check balance and UTXOs
|
|
174
|
+
const balance = utxoManager.getBalance(address);
|
|
175
|
+
const utxos = utxoManager.getUTXOsForAddress(address);
|
|
176
|
+
const stats = utxoManager.getStats();
|
|
177
|
+
|
|
178
|
+
console.log('\n๐ Wallet Status:');
|
|
179
|
+
console.log(` Balance: ${balance} satoshis (${balance / 100000000} BSV)`);
|
|
180
|
+
console.log(` Available UTXOs: ${utxos.length}`);
|
|
181
|
+
console.log(` Total blockchain UTXOs: ${stats.totalUTXOs}`);
|
|
182
|
+
console.log(` Total blockchain value: ${stats.totalValue} satoshis`);
|
|
183
|
+
|
|
184
|
+
// Demonstrate spending
|
|
185
|
+
if (utxos.length > 0) {
|
|
186
|
+
const utxoToSpend = utxos[0];
|
|
187
|
+
console.log(`\n๐ธ Spending UTXO: ${utxoToSpend.txid.substring(0, 16)}...${utxoToSpend.txid.substring(48)}:${utxoToSpend.vout}`);
|
|
188
|
+
|
|
189
|
+
utxoManager.spendUTXOs([{ txid: utxoToSpend.txid, vout: utxoToSpend.vout }]);
|
|
190
|
+
|
|
191
|
+
const newBalance = utxoManager.getBalance(address);
|
|
192
|
+
console.log(` New balance: ${newBalance} satoshis (reduced by ${balance - newBalance})`);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
console.log('\nโ
UTXO management working correctly!');
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// Production usage guide
|
|
199
|
+
function showProductionGuide() {
|
|
200
|
+
console.log('\n๐ Production Usage Guide:');
|
|
201
|
+
console.log('=========================');
|
|
202
|
+
|
|
203
|
+
console.log('For real BSV applications:');
|
|
204
|
+
console.log('');
|
|
205
|
+
console.log('1. ๐ Replace DEMO_CONFIG.privateKey with your private key');
|
|
206
|
+
console.log(' const privateKey = new bsv.PrivateKey("YOUR_PRIVATE_KEY_WIF");');
|
|
207
|
+
console.log('');
|
|
208
|
+
console.log('2. ๐ Fetch real UTXOs using the RealUTXOManager:');
|
|
209
|
+
console.log(' const utxoManager = new RealUTXOManager({ network: "main" });');
|
|
210
|
+
console.log(' const realUTXOs = await utxoManager.fetchRealUTXOs(address);');
|
|
211
|
+
console.log('');
|
|
212
|
+
console.log('3. ๐ธ Create real transactions:');
|
|
213
|
+
console.log(' const txResult = await utxoManager.createAndValidateTransaction(');
|
|
214
|
+
console.log(' fromAddress, toAddress, satoshis, feePerByte');
|
|
215
|
+
console.log(' );');
|
|
216
|
+
console.log('');
|
|
217
|
+
console.log('4. ๐ก Broadcast to network (BE CAREFUL!):');
|
|
218
|
+
console.log(' if (txResult.isValid) {');
|
|
219
|
+
console.log(' await utxoManager.broadcastTransaction(txResult.rawTx);');
|
|
220
|
+
console.log(' }');
|
|
221
|
+
console.log('');
|
|
222
|
+
console.log('๐ก Always test on testnet first: node real_utxo_test.js --testnet');
|
|
223
|
+
console.log('โ ๏ธ Use --broadcast flag only when ready to spend real BSV!');
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// Run all demos
|
|
227
|
+
console.log('๐ Running SmartLedger-BSV Demos...\n');
|
|
228
|
+
|
|
229
|
+
demonstrateSignatureVerification();
|
|
230
|
+
demonstrateTransactionCreation();
|
|
231
|
+
demonstrateUTXOManagement();
|
|
232
|
+
demonstrateRealBSV();
|
|
233
|
+
showProductionGuide();
|
|
234
|
+
|
|
235
|
+
console.log('\n๐ Demo completed successfully!');
|
|
236
|
+
console.log('โ
SmartLedger-BSV v3.0.2 is ready for real BSV development!');
|
|
237
|
+
console.log('');
|
|
238
|
+
console.log('๐ Next steps:');
|
|
239
|
+
console.log(' โข Run: node real_utxo_test.js --help');
|
|
240
|
+
console.log(' โข Test with testnet: node real_utxo_test.js --testnet');
|
|
241
|
+
console.log(' โข Check documentation: README.md and CHANGELOG.md');
|
|
242
|
+
console.log(' โข Report issues: https://github.com/codenlighten/smartledger-bsv/issues');
|