@smartledger/bsv 3.3.2 → 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.
Files changed (118) hide show
  1. package/CHANGELOG.md +220 -79
  2. package/README.md +283 -71
  3. package/bsv-covenant.min.js +26 -3
  4. package/bsv-gdaf.min.js +11 -9
  5. package/bsv-ltp.min.js +10 -8
  6. package/bsv-mnemonic.min.js +4 -4
  7. package/bsv-script-helper.min.js +2 -2
  8. package/bsv-security.min.js +3 -24
  9. package/bsv-shamir.min.js +2 -2
  10. package/bsv-smartcontract.min.js +10 -8
  11. package/bsv.bundle.js +9 -9
  12. package/bsv.min.js +10 -8
  13. package/build/webpack.bundle.config.js +2 -2
  14. package/build/webpack.config.js +2 -2
  15. package/build/webpack.covenant.config.js +2 -2
  16. package/build/webpack.gdaf.config.js +6 -43
  17. package/build/webpack.script-helper.config.js +2 -2
  18. package/build/webpack.security.config.js +2 -2
  19. package/build/webpack.smartcontract.config.js +2 -2
  20. package/bundle-entry.js +1 -341
  21. package/covenant-entry.js +1 -44
  22. package/demos/README.md +188 -0
  23. package/{architecture_demo.js → demos/architecture_demo.js} +2 -2
  24. package/demos/bsv_wallet_demo.js +242 -0
  25. package/{complete_ltp_demo.js → demos/complete_ltp_demo.js} +1 -1
  26. package/demos/debug_tools_demo.js +87 -0
  27. package/demos/demo_features.js +123 -0
  28. package/demos/easy_interface_demo.js +109 -0
  29. package/demos/ecies_demo.js +182 -0
  30. package/demos/gdaf_core_test.js +131 -0
  31. package/demos/gdaf_demo.js +237 -0
  32. package/demos/ltp_demo.js +361 -0
  33. package/demos/ltp_primitives_demo.js +403 -0
  34. package/demos/message_demo.js +209 -0
  35. package/demos/preimage_separation_demo.js +383 -0
  36. package/demos/script_helper_demo.js +289 -0
  37. package/demos/security_demo.js +287 -0
  38. package/{shamir_demo.js → demos/shamir_demo.js} +1 -1
  39. package/{simple_demo.js → demos/simple_demo.js} +1 -1
  40. package/demos/simple_p2pkh_demo.js +169 -0
  41. package/demos/simple_utxo_preimage_demo.js +196 -0
  42. package/demos/smart_contract_demo.html +1347 -0
  43. package/demos/smart_contract_demo.js +910 -0
  44. package/demos/utxo_generator_demo.js +244 -0
  45. package/demos/validation_pipeline_demo.js +155 -0
  46. package/demos/web3keys.html +740 -0
  47. package/docs/BUNDLE_UPDATE_SUMMARY.md +40 -0
  48. package/docs/DOCUMENTATION_REVIEW_REPORT.md +295 -0
  49. package/docs/FIX_CREATEHMAC_ISSUE.md +91 -0
  50. package/docs/MODULE_REFERENCE_COMPLETE.md +330 -0
  51. package/docs/README.md +107 -79
  52. package/docs/SMARTLEDGER_BSV_USAGE_ANSWERS.md +477 -0
  53. package/docs/SMARTLEDGER_BSV_USAGE_EXAMPLES.js +372 -0
  54. package/docs/SMARTLEDGER_BSV_USAGE_GUIDE.md +555 -0
  55. package/docs/SMART_CONTRACT_DEVELOPMENT_GUIDE.md +1459 -0
  56. package/docs/advanced/LEGAL_TOKEN_PROTOCOL.md +411 -0
  57. package/docs/advanced/SMART_CONTRACT_GUIDE.md +1255 -0
  58. package/docs/advanced/UTXO_MANAGER_GUIDE.md +851 -0
  59. package/docs/api/LTP.md +334 -0
  60. package/docs/getting-started/INSTALLATION.md +410 -0
  61. package/docs/getting-started/QUICK_START.md +180 -0
  62. package/docs/migration/FROM_BSV_1_5_6.md +260 -0
  63. package/docs/technical/GDAF_DEVELOPER_INTERFACE.md +187 -0
  64. package/docs/technical/GDAF_IMPLEMENTATION_COMPLETE.md +190 -0
  65. package/docs/technical/SHAMIR_INTEGRATION_SUMMARY.md +165 -0
  66. package/docs/technical/roadmap.md +1250 -0
  67. package/docs/technical/trust_law.md +142 -0
  68. package/examples/complete_workflow_demo.js +783 -0
  69. package/examples/definitive_working_demo.js +261 -0
  70. package/examples/final_working_contracts.js +338 -0
  71. package/examples/smart_contract_templates.js +718 -0
  72. package/examples/working_smart_contracts.js +348 -0
  73. package/gdaf-entry.js +2 -54
  74. package/index.js +32 -0
  75. package/lib/mnemonic/pbkdf2.browser.js +69 -0
  76. package/lib/mnemonic/pbkdf2.js +2 -68
  77. package/lib/mnemonic/pbkdf2.node.js +68 -0
  78. package/ltp-entry.js +2 -92
  79. package/package.json +21 -8
  80. package/script-helper-entry.js +1 -49
  81. package/security-entry.js +1 -70
  82. package/shamir-entry.js +1 -173
  83. package/smartcontract-entry.js +1 -133
  84. package/tests/browser-compatibility/README.md +35 -0
  85. package/tests/browser-compatibility/test-cdn-vs-local.html +186 -0
  86. package/tests/browser-compatibility/test-pbkdf2.html +51 -0
  87. package/tests/test_builtin_verify.js +117 -0
  88. package/tests/test_debug_integration.js +71 -0
  89. package/tests/test_ecdsa_little.js +70 -0
  90. package/tests/test_smartverify_der.js +110 -0
  91. package/utilities/blockchain-state.js +155 -155
  92. package/utilities/blockchain-state.json +103293 -5244
  93. package/utilities/miner-simulator.js +354 -358
  94. package/utilities/mock-utxo-generator.js +54 -54
  95. package/utilities/raw-tx-examples.js +120 -122
  96. package/utilities/success-demo.js +104 -105
  97. package/utilities/transaction-examples.js +188 -188
  98. package/utilities/utxo-manager.js +91 -91
  99. package/utilities/wallet-setup.js +79 -80
  100. package/utilities/working-signature-demo.js +108 -110
  101. package/SECURITY.md +0 -75
  102. package/build/bsv-covenant.min.js +0 -10
  103. package/build/bsv-script-helper.min.js +0 -10
  104. package/build/bsv-security.min.js +0 -31
  105. package/build/bsv-smartcontract.min.js +0 -39
  106. package/build/bsv.bundle.js +0 -39
  107. package/build/bsv.min.js +0 -39
  108. package/validation_test.js +0 -97
  109. /package/docs/{ADVANCED_COVENANT_DEVELOPMENT.md → advanced/ADVANCED_COVENANT_DEVELOPMENT.md} +0 -0
  110. /package/docs/{CUSTOM_SCRIPT_DEVELOPMENT.md → advanced/CUSTOM_SCRIPT_DEVELOPMENT.md} +0 -0
  111. /package/docs/{block.md → api/BLOCKS.md} +0 -0
  112. /package/docs/{ecies.md → api/ECIES.md} +0 -0
  113. /package/docs/{networks.md → api/NETWORKS.md} +0 -0
  114. /package/docs/{script.md → api/SCRIPTS.md} +0 -0
  115. /package/docs/{transaction.md → api/TRANSACTIONS.md} +0 -0
  116. /package/docs/{unspentoutput.md → api/UTXO.md} +0 -0
  117. /package/{test_shamir.js → tests/test_shamir.js} +0 -0
  118. /package/{test_standalone_shamir.html → tests/test_standalone_shamir.html} +0 -0
@@ -2,81 +2,81 @@
2
2
 
3
3
  /**
4
4
  * 🎯 Simple Transaction Success Demo
5
- *
5
+ *
6
6
  * Demonstrates a successful transaction flow with simplified validation
7
7
  * to show the complete mining process working.
8
8
  */
9
9
 
10
- const bsv = require('../index.js');
11
- const {
12
- loadBlockchainState,
10
+ const bsv = require('../index.js')
11
+ const {
12
+ loadBlockchainState,
13
13
  saveBlockchainState,
14
14
  getUTXO,
15
15
  spendUTXO,
16
16
  addUTXO,
17
- getBlockchainStats
18
- } = require('./blockchain-state');
19
- const {
17
+ getBlockchainStats
18
+ } = require('./blockchain-state')
19
+ const {
20
20
  loadConfig,
21
21
  updateUTXOFromTransaction
22
- } = require('./utxo-manager');
22
+ } = require('./utxo-manager')
23
23
 
24
24
  /**
25
25
  * Simplified miner that accepts valid transaction structure
26
26
  */
27
- function acceptTransactionSimplified(transaction) {
28
- console.log('\n📡 SIMPLIFIED MINER: Transaction received');
29
- console.log(`Transaction ID: ${transaction.id}`);
30
- console.log(`Inputs: ${transaction.inputs.length}`);
31
- console.log(`Outputs: ${transaction.outputs.length}`);
32
-
27
+ function acceptTransactionSimplified (transaction) {
28
+ console.log('\n📡 SIMPLIFIED MINER: Transaction received')
29
+ console.log(`Transaction ID: ${transaction.id}`)
30
+ console.log(`Inputs: ${transaction.inputs.length}`)
31
+ console.log(`Outputs: ${transaction.outputs.length}`)
32
+
33
33
  // Basic validation only
34
- let isValid = true;
35
- const errors = [];
36
-
34
+ let isValid = true
35
+ const errors = []
36
+
37
37
  // Check UTXO existence
38
38
  for (const input of transaction.inputs) {
39
- const prevTxId = input.prevTxId.toString('hex');
40
- const outputIndex = input.outputIndex;
41
- const utxoResult = getUTXO(prevTxId, outputIndex);
42
-
39
+ const prevTxId = input.prevTxId.toString('hex')
40
+ const outputIndex = input.outputIndex
41
+ const utxoResult = getUTXO(prevTxId, outputIndex)
42
+
43
43
  if (!utxoResult.exists) {
44
- isValid = false;
45
- errors.push(`UTXO ${prevTxId}:${outputIndex} does not exist`);
44
+ isValid = false
45
+ errors.push(`UTXO ${prevTxId}:${outputIndex} does not exist`)
46
46
  } else {
47
- console.log(`✅ UTXO ${prevTxId}:${outputIndex} exists (${utxoResult.utxo.satoshis} sats)`);
47
+ console.log(`✅ UTXO ${prevTxId}:${outputIndex} exists (${utxoResult.utxo.satoshis} sats)`)
48
48
  }
49
49
  }
50
-
50
+
51
51
  // Check basic transaction structure
52
52
  if (transaction.inputs.length === 0) {
53
- isValid = false;
54
- errors.push('No inputs provided');
53
+ isValid = false
54
+ errors.push('No inputs provided')
55
55
  }
56
-
56
+
57
57
  if (transaction.outputs.length === 0) {
58
- isValid = false;
59
- errors.push('No outputs provided');
58
+ isValid = false
59
+ errors.push('No outputs provided')
60
60
  }
61
-
61
+
62
62
  if (isValid) {
63
- console.log('✅ Basic validation passed - Processing transaction...');
64
-
63
+ console.log('✅ Basic validation passed - Processing transaction...')
64
+
65
65
  // Process the transaction
66
- const state = loadBlockchainState();
67
-
66
+ const state = loadBlockchainState()
67
+
68
68
  // Spend input UTXOs
69
69
  for (const input of transaction.inputs) {
70
- const prevTxId = input.prevTxId.toString('hex');
71
- const outputIndex = input.outputIndex;
72
- spendUTXO(prevTxId, outputIndex, transaction.id);
70
+ const prevTxId = input.prevTxId.toString('hex')
71
+ const outputIndex = input.outputIndex
72
+ spendUTXO(prevTxId, outputIndex, transaction.id)
73
73
  }
74
-
74
+
75
75
  // Create new UTXOs
76
76
  for (let i = 0; i < transaction.outputs.length; i++) {
77
- const output = transaction.outputs[i];
77
+ const output = transaction.outputs[i]
78
78
  try {
79
- const outputAddress = output.script.toAddress();
79
+ const outputAddress = output.script.toAddress()
80
80
  const newUTXO = {
81
81
  txid: transaction.id,
82
82
  vout: i,
@@ -85,109 +85,108 @@ function acceptTransactionSimplified(transaction) {
85
85
  scriptPubKey: output.script.toHex(),
86
86
  satoshis: output.satoshis,
87
87
  address: outputAddress.toString()
88
- };
89
-
90
- addUTXO(newUTXO, outputAddress.toString());
91
- console.log(`✅ Created UTXO ${transaction.id}:${i} -> ${outputAddress} (${output.satoshis} sats)`);
88
+ }
89
+
90
+ addUTXO(newUTXO, outputAddress.toString())
91
+ console.log(`✅ Created UTXO ${transaction.id}:${i} -> ${outputAddress} (${output.satoshis} sats)`)
92
92
  } catch (error) {
93
- console.error(`❌ Error creating output ${i}: ${error.message}`);
93
+ console.error(`❌ Error creating output ${i}: ${error.message}`)
94
94
  }
95
95
  }
96
-
96
+
97
97
  // Update block height
98
- state.metadata.blockHeight += 1;
98
+ state.metadata.blockHeight += 1
99
99
  state.transactionHistory.push({
100
100
  txid: transaction.id,
101
101
  processedAt: new Date().toISOString(),
102
102
  inputCount: transaction.inputs.length,
103
103
  outputCount: transaction.outputs.length
104
- });
105
-
106
- saveBlockchainState(state);
107
-
108
- console.log('🎉 Transaction processed successfully!');
109
- console.log(`🏗️ New block height: ${state.metadata.blockHeight}`);
110
-
111
- return { accepted: true, txid: transaction.id, errors: [] };
104
+ })
105
+
106
+ saveBlockchainState(state)
107
+
108
+ console.log('🎉 Transaction processed successfully!')
109
+ console.log(`🏗️ New block height: ${state.metadata.blockHeight}`)
110
+
111
+ return { accepted: true, txid: transaction.id, errors: [] }
112
112
  } else {
113
- console.log('❌ Transaction rejected');
114
- errors.forEach(error => console.log(` - ${error}`));
115
- return { accepted: false, txid: transaction.id, errors };
113
+ console.log('❌ Transaction rejected')
114
+ errors.forEach(error => console.log(` - ${error}`))
115
+ return { accepted: false, txid: transaction.id, errors }
116
116
  }
117
117
  }
118
118
 
119
119
  /**
120
120
  * Demo successful transaction
121
121
  */
122
- function demoSuccessfulTransaction() {
123
- console.log('🎯 BSV Successful Transaction Demo');
124
- console.log('═'.repeat(80));
125
-
122
+ function demoSuccessfulTransaction () {
123
+ console.log('🎯 BSV Successful Transaction Demo')
124
+ console.log('═'.repeat(80))
125
+
126
126
  try {
127
127
  // Load wallet config
128
- const config = loadConfig();
129
- const wallet = config.wallet;
130
-
128
+ const config = loadConfig()
129
+ const wallet = config.wallet
130
+
131
131
  // Create recipient
132
- const recipientKey = new bsv.PrivateKey();
133
- const recipientAddress = recipientKey.toAddress().toString();
134
-
132
+ const recipientKey = new bsv.PrivateKey()
133
+ const recipientAddress = recipientKey.toAddress().toString()
134
+
135
135
  // Get UTXO
136
- const utxo = config.utxo;
137
-
138
- console.log('📋 Transaction Setup:');
139
- console.log(`👛 From: ${wallet.address}`);
140
- console.log(`🎯 To: ${recipientAddress}`);
141
- console.log(`💰 Amount: 15,000 satoshis`);
142
- console.log(`💳 UTXO: ${utxo.txid}:${utxo.vout} (${utxo.satoshis} sats)`);
143
- console.log(`💵 Fee: 1,000 satoshis`);
144
- console.log(`🔄 Change: ${utxo.satoshis - 15000 - 1000} satoshis\n`);
145
-
136
+ const utxo = config.utxo
137
+
138
+ console.log('📋 Transaction Setup:')
139
+ console.log(`👛 From: ${wallet.address}`)
140
+ console.log(`🎯 To: ${recipientAddress}`)
141
+ console.log(`💰 Amount: 15,000 satoshis`)
142
+ console.log(`💳 UTXO: ${utxo.txid}:${utxo.vout} (${utxo.satoshis} sats)`)
143
+ console.log(`💵 Fee: 1,000 satoshis`)
144
+ console.log(`🔄 Change: ${utxo.satoshis - 15000 - 1000} satoshis\n`)
145
+
146
146
  // Create transaction
147
147
  const tx = new bsv.Transaction()
148
148
  .from(utxo)
149
149
  .to(recipientAddress, 15000)
150
150
  .change(wallet.address)
151
151
  .fee(1000)
152
- .sign(bsv.PrivateKey.fromWIF(wallet.privateKeyWIF));
153
-
154
- console.log('✅ Transaction created:');
155
- console.log(`🆔 TXID: ${tx.id}`);
156
- console.log(`📦 Raw hex: ${tx.toString()}`);
157
- console.log(`📏 Size: ${tx.toString().length / 2} bytes\n`);
158
-
152
+ .sign(bsv.PrivateKey.fromWIF(wallet.privateKeyWIF))
153
+
154
+ console.log('✅ Transaction created:')
155
+ console.log(`🆔 TXID: ${tx.id}`)
156
+ console.log(`📦 Raw hex: ${tx.toString()}`)
157
+ console.log(`📏 Size: ${tx.toString().length / 2} bytes\n`)
158
+
159
159
  // Show blockchain state before
160
- console.log('📊 Blockchain state BEFORE transaction:');
161
- getBlockchainStats();
162
-
160
+ console.log('📊 Blockchain state BEFORE transaction:')
161
+ getBlockchainStats()
162
+
163
163
  // Process with simplified miner
164
- const result = acceptTransactionSimplified(tx);
165
-
164
+ const result = acceptTransactionSimplified(tx)
165
+
166
166
  if (result.accepted) {
167
167
  // Update local wallet too
168
- updateUTXOFromTransaction(tx, utxo);
169
-
170
- console.log('\n📊 Blockchain state AFTER transaction:');
171
- getBlockchainStats();
172
-
173
- console.log('\n💰 Local wallet state:');
174
- const { loadConfig } = require('./utxo-manager');
175
- const updatedConfig = loadConfig();
176
- console.log(`Available UTXOs: ${updatedConfig.availableUTXOs?.length || 0}`);
177
- console.log(`Total balance: ${updatedConfig.availableUTXOs?.reduce((sum, u) => sum + u.satoshis, 0) || 0} sats`);
168
+ updateUTXOFromTransaction(tx, utxo)
169
+
170
+ console.log('\n📊 Blockchain state AFTER transaction:')
171
+ getBlockchainStats()
172
+
173
+ console.log('\n💰 Local wallet state:')
174
+ const { loadConfig } = require('./utxo-manager')
175
+ const updatedConfig = loadConfig()
176
+ console.log(`Available UTXOs: ${updatedConfig.availableUTXOs ? updatedConfig.availableUTXOs.length : 0}`)
177
+ console.log(`Total balance: ${updatedConfig.availableUTXOs ? updatedConfig.availableUTXOs.reduce((sum, u) => sum + u.satoshis, 0) : 0} sats`)
178
178
  }
179
-
180
179
  } catch (error) {
181
- console.error('❌ Error:', error.message);
180
+ console.error('❌ Error:', error.message)
182
181
  }
183
182
  }
184
183
 
185
184
  // Run if called directly
186
185
  if (require.main === module) {
187
- demoSuccessfulTransaction();
186
+ demoSuccessfulTransaction()
188
187
  }
189
188
 
190
189
  module.exports = {
191
190
  acceptTransactionSimplified,
192
191
  demoSuccessfulTransaction
193
- };
192
+ }