@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,219 +0,0 @@
1
- /**
2
- * Advanced Covenant Interface Demonstration
3
- *
4
- * This demo showcases the enhanced covenant interface that combines:
5
- * 1. Detailed BIP143 preimage parsing and validation
6
- * 2. nChain PUSHTX techniques for in-script signature generation
7
- * 3. Perpetually Enforcing Locking Scripts (PELS)
8
- * 4. Advanced covenant patterns for BSV development
9
- *
10
- * Based on specifications from:
11
- * - BIP143 sighash preimage structure
12
- * - nChain white paper WP1605: PUSHTX and Its Building Blocks
13
- */
14
-
15
- const bsv = require('../index.js');
16
- const { CovenantInterface } = require('./lib/covenant-interface.js');
17
-
18
- console.log('='.repeat(80));
19
- console.log('ADVANCED COVENANT INTERFACE DEMONSTRATION');
20
- console.log('Combining BIP143 Preimage Parsing + nChain PUSHTX Techniques');
21
- console.log('='.repeat(80));
22
-
23
- // Initialize the enhanced covenant interface
24
- const covenantInterface = new CovenantInterface();
25
-
26
- // Test 1: Enhanced preimage parsing with BIP143 specifications
27
- console.log('\n1. ENHANCED PREIMAGE PARSING (BIP143 Compliant)');
28
- console.log('-'.repeat(60));
29
-
30
- try {
31
- // Create a test transaction for preimage generation
32
- const testTx = new bsv.Transaction()
33
- .from({
34
- txId: '88b9d41101a4c064b283f80ca73837d96f974bc3fbe931b35db7bca8370cca34',
35
- outputIndex: 0,
36
- script: '76a914751e76e8199196d454941c45d1b3a323f1433bd688ac',
37
- satoshis: 4999999388
38
- })
39
- .to('1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa', 4999998876);
40
-
41
- // Generate preimage using BSV library
42
- const lockingScript = bsv.Script.fromHex('76a914751e76e8199196d454941c45d1b3a323f1433bd688ac');
43
- const satoshis = 4999999388;
44
- const sighashType = bsv.crypto.Signature.SIGHASH_ALL | bsv.crypto.Signature.SIGHASH_FORKID;
45
-
46
- console.log('✓ Test transaction created');
47
- console.log(` - Input TXID: ${testTx.inputs[0].prevTxId}`);
48
- console.log(` - Output value: ${testTx.outputs[0].satoshis} satoshis`);
49
- console.log(` - Sighash type: 0x${sighashType.toString(16)}`);
50
-
51
- } catch (error) {
52
- console.log('⚠ Preimage demonstration (requires transaction context)');
53
- console.log(' Enhanced preimage parsing includes:');
54
- console.log(' - Field-by-field BIP143 structure validation');
55
- console.log(' - Proper endianness handling (little-endian fields)');
56
- console.log(' - Variable-length field parsing (scriptCode)');
57
- console.log(' - Comprehensive 108+ byte preimage validation');
58
- console.log(' - Direct field access (nVersion, hashPrevouts, etc.)');
59
- }
60
-
61
- // Test 2: PUSHTX Covenant Creation
62
- console.log('\n2. PUSHTX COVENANT CREATION (nChain WP1605)');
63
- console.log('-'.repeat(60));
64
-
65
- try {
66
- // Create PUSHTX covenant using nChain techniques
67
- const pushtxCovenant = covenantInterface.createAdvancedCovenant('pushtx', {
68
- publicKey: '0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798',
69
- enforceOutputs: true,
70
- sighashType: 0x41 // SIGHASH_ALL | SIGHASH_FORKID
71
- });
72
-
73
- console.log('✓ PUSHTX covenant created successfully');
74
- console.log(` - Script length: ${pushtxCovenant.toBuffer().length} bytes`);
75
- console.log(` - Script hex: ${pushtxCovenant.toHex().substring(0, 80)}...`);
76
- console.log(' - Features: In-script signature generation, message construction');
77
- console.log(' - Optimization: k=a=1 (generator point as public key)');
78
- console.log(' - Security: DER canonicalization prevents malleability');
79
-
80
- } catch (error) {
81
- console.error('✗ PUSHTX covenant creation failed:', error.message);
82
- }
83
-
84
- // Test 3: Perpetually Enforcing Locking Script (PELS)
85
- console.log('\n3. PERPETUALLY ENFORCING LOCKING SCRIPT (PELS)');
86
- console.log('-'.repeat(60));
87
-
88
- try {
89
- // Create PELS that enforces same script and value minus fees
90
- const pels = covenantInterface.createAdvancedCovenant('perpetual', {
91
- publicKeyHash: '751e76e8199196d454941c45d1b3a323f1433bd6',
92
- feeDeduction: 512, // Deduct 512 satoshis per transaction
93
- enforceScript: true,
94
- enforceValue: true
95
- });
96
-
97
- console.log('✓ PELS (Perpetual Covenant) created successfully');
98
- console.log(` - Script length: ${pels.toBuffer().length} bytes`);
99
- console.log(' - Enforcement: Same locking script + fee-adjusted value');
100
- console.log(' - Fee model: 512 satoshi deduction per spend');
101
- console.log(' - Perpetual: All future transactions must follow rules');
102
- console.log(' - Use case: Certificate authority attestation chains');
103
-
104
- } catch (error) {
105
- console.error('✗ PELS creation failed:', error.message);
106
- }
107
-
108
- // Test 4: Transaction Introspection Covenant
109
- console.log('\n4. TRANSACTION INTROSPECTION COVENANT');
110
- console.log('-'.repeat(60));
111
-
112
- try {
113
- // Create covenant that analyzes transaction structure via preimage
114
- const introspectionCovenant = covenantInterface.createAdvancedCovenant('introspection', {
115
- validateInputs: false,
116
- validateOutputs: true,
117
- validateSequence: false,
118
- validateLocktime: false
119
- });
120
-
121
- console.log('✓ Introspection covenant created successfully');
122
- console.log(` - Script length: ${introspectionCovenant.toBuffer().length} bytes`);
123
- console.log(' - Analysis: Output validation via preimage parsing');
124
- console.log(' - Fields: Selective validation of transaction components');
125
- console.log(' - Application: Complex multi-party validation rules');
126
-
127
- } catch (error) {
128
- console.error('✗ Introspection covenant creation failed:', error.message);
129
- }
130
-
131
- // Test 5: Enhanced Covenant Transaction Wrapper
132
- console.log('\n5. ENHANCED COVENANT TRANSACTION WRAPPER');
133
- console.log('-'.repeat(60));
134
-
135
- try {
136
- // Create covenant transaction with enhanced methods
137
- const covenantTx = covenantInterface.createCovenantTransaction({
138
- inputs: [],
139
- outputs: [{
140
- address: '1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa',
141
- satoshis: 1000000
142
- }]
143
- });
144
-
145
- console.log('✓ Enhanced covenant transaction created');
146
- console.log(' - Features: Preimage caching, enhanced error reporting');
147
- console.log(' - Methods: getPreimage(), signInput(), verify()');
148
- console.log(' - Integration: Works with existing BSV transaction API');
149
- console.log(' - Dual-level: High-level abstractions + granular control');
150
-
151
- } catch (error) {
152
- console.error('✗ Covenant transaction creation failed:', error.message);
153
- }
154
-
155
- // Test 6: Comprehensive Technical Specifications
156
- console.log('\n6. TECHNICAL SPECIFICATIONS SUMMARY');
157
- console.log('-'.repeat(60));
158
-
159
- console.log('BIP143 Preimage Structure (Enhanced Parsing):');
160
- console.log(' • nVersion (4 bytes, little-endian) + value accessor');
161
- console.log(' • hashPrevouts (32 bytes) - double SHA256 of input outpoints');
162
- console.log(' • hashSequence (32 bytes) - double SHA256 of input sequences');
163
- console.log(' • outpoint (36 bytes) - prevTxId + outputIndex with accessors');
164
- console.log(' • scriptCode (variable) - proper varint length parsing');
165
- console.log(' • amount (8 bytes, little-endian) + BigInt value accessor');
166
- console.log(' • nSequence (4 bytes, little-endian) + value accessor');
167
- console.log(' • hashOutputs (32 bytes) - double SHA256 of all outputs');
168
- console.log(' • nLockTime (4 bytes, little-endian) + value accessor');
169
- console.log(' • sighashType (4 bytes, little-endian) + value accessor');
170
- console.log(' • Validation: 108+ byte structure validation');
171
-
172
- console.log('\nnChain PUSHTX Techniques (WP1605 Implementation):');
173
- console.log(' • In-script signature generation: s = z + Gx mod n');
174
- console.log(' • Generator optimization: k=a=1 for efficiency');
175
- console.log(' • DER canonicalization: s <= n/2 prevents malleability');
176
- console.log(' • Message construction: BIP143 preimage building');
177
- console.log(' • Security proof: Computationally infeasible to forge');
178
- console.log(' • Fixed parameters: public key, ephemeral key, sighash flag');
179
-
180
- console.log('\nAdvanced Covenant Patterns:');
181
- console.log(' • PUSHTX: Basic transaction introspection capability');
182
- console.log(' • PELS: Perpetually enforcing locking scripts');
183
- console.log(' • Introspection: Selective transaction field validation');
184
- console.log(' • Optimization: Alt stack usage, endianness reversal');
185
- console.log(' • Fee management: Configurable deduction per spend');
186
- console.log(' • Transaction size: ~1KB for optimized PELS implementation');
187
-
188
- // Test 7: Developer Usage Examples
189
- console.log('\n7. DEVELOPER USAGE EXAMPLES');
190
- console.log('-'.repeat(60));
191
-
192
- console.log('Basic PUSHTX Usage:');
193
- console.log('```javascript');
194
- console.log('const covenant = new CovenantInterface();');
195
- console.log('const pushtx = covenant.createAdvancedCovenant("pushtx", {');
196
- console.log(' publicKey: "02...", enforceOutputs: true');
197
- console.log('});');
198
- console.log('```');
199
-
200
- console.log('\nPerpetual Covenant Usage:');
201
- console.log('```javascript');
202
- console.log('const pels = covenant.createAdvancedCovenant("perpetual", {');
203
- console.log(' publicKeyHash: "751e...", feeDeduction: 512');
204
- console.log('});');
205
- console.log('```');
206
-
207
- console.log('\nEnhanced Transaction Usage:');
208
- console.log('```javascript');
209
- console.log('const tx = covenant.createCovenantTransaction(config);');
210
- console.log('const preimage = tx.getPreimage(0, script, satoshis);');
211
- console.log('const parsedPreimage = new CovenantPreimage(preimage);');
212
- console.log('console.log(parsedPreimage.amountValue); // BigInt accessor');
213
- console.log('```');
214
-
215
- console.log('\n' + '='.repeat(80));
216
- console.log('ADVANCED COVENANT INTERFACE READY FOR PRODUCTION');
217
- console.log('Features: BIP143 parsing + nChain PUSHTX + PELS + Full BSV API');
218
- console.log('Status: SmartLedger-BSV v3.1.1+ with comprehensive covenant support');
219
- console.log('='.repeat(80));
@@ -1,270 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- /**
4
- * Covenant Interface Demo - High-Level + Granular Control
5
- *
6
- * Shows how to use the new CovenantInterface alongside the existing BSV API
7
- * for maximum flexibility in covenant development.
8
- */
9
-
10
- const bsv = require('../index.js');
11
- const { CovenantInterface } = require('./lib/covenant-interface.js');
12
-
13
- console.log('🔮 SmartLedger Covenant Interface Demo');
14
- console.log('====================================');
15
- console.log(`BSV Library Version: ${bsv.version}`);
16
- console.log(`Date: ${new Date().toISOString()}\n`);
17
-
18
- // Initialize covenant interface (keeps full BSV access)
19
- const covenant = new CovenantInterface();
20
-
21
- // Test keys
22
- const privateKey1 = new bsv.PrivateKey('5KYZdUEo39z3FPrtuX2QbbwGnNP5zTd7yyr2SC1j299sBCnWjss');
23
- const publicKey1 = privateKey1.publicKey;
24
- const privateKey2 = new bsv.PrivateKey('5Hx15HFGyep2CfPxsJKe2fXJsCVn5DEiyoeGGF6JZjGbTRnqfiD');
25
- const publicKey2 = privateKey2.publicKey;
26
- const privateKey3 = new bsv.PrivateKey(); // Generate random key
27
- const publicKey3 = privateKey3.publicKey;
28
-
29
- console.log('🔧 Test Setup:');
30
- console.log(`Key 1: ${publicKey1.toAddress()}`);
31
- console.log(`Key 2: ${publicKey2.toAddress()}`);
32
- console.log(`Key 3: ${publicKey3.toAddress()}\n`);
33
-
34
- /**
35
- * Example 1: High-Level Covenant Creation with Granular Access
36
- */
37
- async function demoHighLevelCovenant() {
38
- console.log('📝 EXAMPLE 1: High-Level Covenant with Granular Control');
39
- console.log('======================================================');
40
-
41
- // Create UTXO using standard BSV API
42
- const utxo = {
43
- txid: 'a'.repeat(64),
44
- vout: 0,
45
- script: bsv.Script.buildPublicKeyHashOut(publicKey1.toAddress()).toHex(),
46
- satoshis: 100000
47
- };
48
-
49
- // ✨ Use high-level covenant interface
50
- const covenantTx = covenant.createCovenantTransaction({
51
- inputs: [utxo],
52
- outputs: [
53
- { address: publicKey2.toAddress().toString(), satoshis: 99000 }
54
- ],
55
- feePerKb: 10 // Ultra-low fees
56
- });
57
-
58
- // 🔍 Access granular BSV functionality when needed
59
- console.log(`Transaction ID: ${covenantTx.tx.id}`);
60
- console.log(`Fee: ${covenantTx.tx.getFee()} satoshis`);
61
-
62
- // Get preimage using high-level interface
63
- const lockingScript = bsv.Script.fromHex(utxo.script);
64
- const preimage = covenantTx.getPreimage(0, lockingScript, utxo.satoshis);
65
-
66
- console.log(`Preimage: ${preimage.toString().substring(0, 40)}...`);
67
- console.log(`Preimage components available: ✅`);
68
- console.log(`Version: ${preimage.getVersion().toString('hex')}`);
69
- console.log(`Amount: ${preimage.getAmount().readBigUInt64LE(0)} satoshis`);
70
-
71
- // Sign using high-level interface
72
- covenantTx.signInput(0, privateKey1, lockingScript, utxo.satoshis);
73
-
74
- console.log(`Covenant transaction valid: ${covenantTx.verify() ? '✅ YES' : '❌ NO'}`);
75
- console.log(`High-level interface: ✅ WORKING\n`);
76
- }
77
-
78
- /**
79
- * Example 2: Template-Based Escrow Covenant
80
- */
81
- async function demoEscrowCovenant() {
82
- console.log('📝 EXAMPLE 2: Template-Based Escrow Covenant');
83
- console.log('===========================================');
84
-
85
- // ✨ Create escrow using template (high-level)
86
- const escrowScript = covenant.createEscrow(
87
- publicKey1, // buyer
88
- publicKey2, // seller
89
- publicKey3, // arbitrator
90
- 700000 // timelock for refund
91
- );
92
-
93
- console.log(`Escrow script: ${escrowScript.toString()}`);
94
-
95
- const utxo = {
96
- txid: 'b'.repeat(64),
97
- vout: 0,
98
- script: escrowScript.toHex(),
99
- satoshis: 200000
100
- };
101
-
102
- // Create transaction with high-level interface
103
- const escrowTx = covenant.createCovenantTransaction({
104
- inputs: [utxo],
105
- outputs: [
106
- { address: publicKey2.toAddress().toString(), satoshis: 199000 }
107
- ]
108
- });
109
-
110
- // 🔍 Granular control: Manual signature creation for 2-of-3 multisig
111
- const sig1 = covenant.createSignature(escrowTx.tx, privateKey1, 0, escrowScript, utxo.satoshis);
112
- const sig2 = covenant.createSignature(escrowTx.tx, privateKey2, 0, escrowScript, utxo.satoshis);
113
-
114
- // Create custom unlocking script (granular BSV control)
115
- const unlockingScript = new bsv.Script()
116
- .add(bsv.Opcode.OP_0) // CHECKMULTISIG bug
117
- .add(sig1)
118
- .add(sig2)
119
- .add(bsv.Opcode.OP_0); // Choose ELSE branch (multisig, not timelock)
120
-
121
- escrowTx.tx.inputs[0].setScript(unlockingScript);
122
-
123
- // Validate using high-level interface
124
- const validation = covenant.validateCovenant(
125
- escrowTx.tx, 0, unlockingScript, escrowScript
126
- );
127
-
128
- console.log(`Escrow validation: ${validation.toString()}`);
129
- console.log(`Template + granular control: ✅ WORKING\n`);
130
- }
131
-
132
- /**
133
- * Example 3: State Machine Covenant
134
- */
135
- async function demoStateMachine() {
136
- console.log('📝 EXAMPLE 3: State Machine Covenant');
137
- console.log('===================================');
138
-
139
- // Define states for a simple workflow
140
- const states = [
141
- { name: 'PENDING', nextStates: [1, 2] }, // Can go to APPROVED or REJECTED
142
- { name: 'APPROVED', nextStates: [3] }, // Can go to COMPLETED
143
- { name: 'REJECTED', nextStates: [0] }, // Can go back to PENDING
144
- { name: 'COMPLETED', nextStates: [] } // Terminal state
145
- ];
146
-
147
- // ✨ Create state machine using template
148
- const stateMachineScript = covenant.createStateMachine(states, 0, publicKey1);
149
-
150
- console.log(`State machine created: ${stateMachineScript.toString().length} bytes`);
151
- console.log(`Current state: PENDING (0)`);
152
- console.log(`Valid transitions: APPROVED (1), REJECTED (2)`);
153
- console.log(`Template-based covenant: ✅ WORKING\n`);
154
- }
155
-
156
- /**
157
- * Example 4: Full BSV API Access Preserved
158
- */
159
- async function demoGranularAccess() {
160
- console.log('📝 EXAMPLE 4: Full BSV API Access Preserved');
161
- console.log('==========================================');
162
-
163
- // 🔍 Full access to underlying BSV library
164
- console.log(`BSV Library accessible: ${covenant.bsv === bsv ? '✅ YES' : '❌ NO'}`);
165
-
166
- // Create transaction using pure BSV API
167
- const pureBsvTx = new bsv.Transaction()
168
- .from({
169
- txid: 'c'.repeat(64),
170
- vout: 0,
171
- script: bsv.Script.buildPublicKeyHashOut(publicKey1.toAddress()).toHex(),
172
- satoshis: 50000
173
- })
174
- .to(publicKey2.toAddress(), 49000)
175
- .sign(privateKey1);
176
-
177
- console.log(`Pure BSV transaction: ${pureBsvTx.verify() ? '✅ VALID' : '❌ INVALID'}`);
178
-
179
- // Mix covenant interface with BSV API
180
- const mixedSignature = covenant.createSignature(
181
- pureBsvTx,
182
- privateKey1,
183
- 0,
184
- bsv.Script.buildPublicKeyHashOut(publicKey1.toAddress()),
185
- 50000
186
- );
187
-
188
- console.log(`Mixed API signature: ${mixedSignature.length} bytes`);
189
- console.log(`BSV API compatibility: ✅ PRESERVED\n`);
190
- }
191
-
192
- /**
193
- * Example 5: Performance and Flexibility Comparison
194
- */
195
- async function demoComparison() {
196
- console.log('📝 EXAMPLE 5: Interface Comparison');
197
- console.log('=================================');
198
-
199
- // High-level approach
200
- console.time('High-level covenant creation');
201
- const highLevelTx = covenant.createCovenantTransaction({
202
- inputs: [{
203
- txid: 'd'.repeat(64),
204
- vout: 0,
205
- script: bsv.Script.buildPublicKeyHashOut(publicKey1.toAddress()).toHex(),
206
- satoshis: 75000
207
- }],
208
- outputs: [
209
- { address: publicKey2.toAddress().toString(), satoshis: 74000 }
210
- ]
211
- });
212
- console.timeEnd('High-level covenant creation');
213
-
214
- // Granular BSV approach
215
- console.time('Granular BSV creation');
216
- const granularTx = new bsv.Transaction()
217
- .from({
218
- txid: 'd'.repeat(64),
219
- vout: 0,
220
- script: bsv.Script.buildPublicKeyHashOut(publicKey1.toAddress()).toHex(),
221
- satoshis: 75000
222
- })
223
- .to(publicKey2.toAddress(), 74000);
224
- console.timeEnd('Granular BSV creation');
225
-
226
- console.log(`Both approaches available: ✅ YES`);
227
- console.log(`Developer choice preserved: ✅ YES`);
228
- console.log(`No breaking changes: ✅ CONFIRMED\n`);
229
- }
230
-
231
- /**
232
- * Run all demos
233
- */
234
- async function runAllDemos() {
235
- try {
236
- await demoHighLevelCovenant();
237
- await demoEscrowCovenant();
238
- await demoStateMachine();
239
- await demoGranularAccess();
240
- await demoComparison();
241
-
242
- console.log('🎉 COVENANT INTERFACE RESULTS');
243
- console.log('============================');
244
- console.log('✅ High-level covenant interface: WORKING');
245
- console.log('✅ Template-based covenant creation: WORKING');
246
- console.log('✅ Granular BSV API access: PRESERVED');
247
- console.log('✅ Preimage parsing and access: WORKING');
248
- console.log('✅ Mixed API usage: SUPPORTED');
249
- console.log('✅ No breaking changes: CONFIRMED');
250
- console.log('');
251
- console.log('🚀 Best of Both Worlds:');
252
- console.log(' - Simple covenant templates for rapid development');
253
- console.log(' - Full BSV API access for granular control');
254
- console.log(' - Backward compatibility with existing code');
255
- console.log(' - Enhanced preimage parsing and validation');
256
-
257
- } catch (error) {
258
- console.error('❌ Demo failed:', error.message);
259
- }
260
- }
261
-
262
- console.log('🎯 COVENANT INTERFACE PHILOSOPHY');
263
- console.log('===============================');
264
- console.log('✨ High-level abstractions for common patterns');
265
- console.log('🔍 Granular BSV API access when needed');
266
- console.log('🔄 Full backward compatibility');
267
- console.log('📈 Enhanced developer productivity\n');
268
-
269
- // Run the demos
270
- runAllDemos();