@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.
- package/CHANGELOG.md +220 -79
- package/README.md +283 -71
- package/bsv-covenant.min.js +26 -3
- package/bsv-gdaf.min.js +11 -9
- package/bsv-ltp.min.js +10 -8
- package/bsv-mnemonic.min.js +4 -4
- package/bsv-script-helper.min.js +2 -2
- package/bsv-security.min.js +3 -24
- package/bsv-shamir.min.js +2 -2
- package/bsv-smartcontract.min.js +10 -8
- package/bsv.bundle.js +9 -9
- package/bsv.min.js +10 -8
- package/build/webpack.bundle.config.js +2 -2
- package/build/webpack.config.js +2 -2
- package/build/webpack.covenant.config.js +2 -2
- package/build/webpack.gdaf.config.js +6 -43
- package/build/webpack.script-helper.config.js +2 -2
- package/build/webpack.security.config.js +2 -2
- package/build/webpack.smartcontract.config.js +2 -2
- package/bundle-entry.js +1 -341
- package/covenant-entry.js +1 -44
- package/demos/README.md +188 -0
- package/{architecture_demo.js → demos/architecture_demo.js} +2 -2
- package/demos/bsv_wallet_demo.js +242 -0
- package/{complete_ltp_demo.js → demos/complete_ltp_demo.js} +1 -1
- 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/{shamir_demo.js → demos/shamir_demo.js} +1 -1
- package/{simple_demo.js → demos/simple_demo.js} +1 -1
- 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/DOCUMENTATION_REVIEW_REPORT.md +295 -0
- package/docs/FIX_CREATEHMAC_ISSUE.md +91 -0
- package/docs/MODULE_REFERENCE_COMPLETE.md +330 -0
- package/docs/README.md +107 -79
- 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/docs/advanced/LEGAL_TOKEN_PROTOCOL.md +411 -0
- package/docs/advanced/SMART_CONTRACT_GUIDE.md +1255 -0
- package/docs/advanced/UTXO_MANAGER_GUIDE.md +851 -0
- package/docs/api/LTP.md +334 -0
- package/docs/getting-started/INSTALLATION.md +410 -0
- package/docs/getting-started/QUICK_START.md +180 -0
- package/docs/migration/FROM_BSV_1_5_6.md +260 -0
- package/docs/technical/GDAF_DEVELOPER_INTERFACE.md +187 -0
- package/docs/technical/GDAF_IMPLEMENTATION_COMPLETE.md +190 -0
- package/docs/technical/SHAMIR_INTEGRATION_SUMMARY.md +165 -0
- package/docs/technical/roadmap.md +1250 -0
- package/docs/technical/trust_law.md +142 -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/gdaf-entry.js +2 -54
- package/index.js +32 -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/ltp-entry.js +2 -92
- package/package.json +21 -8
- package/script-helper-entry.js +1 -49
- package/security-entry.js +1 -70
- package/shamir-entry.js +1 -173
- package/smartcontract-entry.js +1 -133
- 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/tests/test_builtin_verify.js +117 -0
- package/tests/test_debug_integration.js +71 -0
- package/tests/test_ecdsa_little.js +70 -0
- package/tests/test_smartverify_der.js +110 -0
- package/utilities/blockchain-state.js +155 -155
- package/utilities/blockchain-state.json +103293 -5244
- package/utilities/miner-simulator.js +354 -358
- package/utilities/mock-utxo-generator.js +54 -54
- package/utilities/raw-tx-examples.js +120 -122
- package/utilities/success-demo.js +104 -105
- package/utilities/transaction-examples.js +188 -188
- package/utilities/utxo-manager.js +91 -91
- package/utilities/wallet-setup.js +79 -80
- package/utilities/working-signature-demo.js +108 -110
- package/SECURITY.md +0 -75
- package/build/bsv-covenant.min.js +0 -10
- package/build/bsv-script-helper.min.js +0 -10
- package/build/bsv-security.min.js +0 -31
- package/build/bsv-smartcontract.min.js +0 -39
- package/build/bsv.bundle.js +0 -39
- package/build/bsv.min.js +0 -39
- package/validation_test.js +0 -97
- /package/docs/{ADVANCED_COVENANT_DEVELOPMENT.md → advanced/ADVANCED_COVENANT_DEVELOPMENT.md} +0 -0
- /package/docs/{CUSTOM_SCRIPT_DEVELOPMENT.md → advanced/CUSTOM_SCRIPT_DEVELOPMENT.md} +0 -0
- /package/docs/{block.md → api/BLOCKS.md} +0 -0
- /package/docs/{ecies.md → api/ECIES.md} +0 -0
- /package/docs/{networks.md → api/NETWORKS.md} +0 -0
- /package/docs/{script.md → api/SCRIPTS.md} +0 -0
- /package/docs/{transaction.md → api/TRANSACTIONS.md} +0 -0
- /package/docs/{unspentoutput.md → api/UTXO.md} +0 -0
- /package/{test_shamir.js → tests/test_shamir.js} +0 -0
- /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
|
|
177
|
-
console.log(`Total balance: ${updatedConfig.availableUTXOs
|
|
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
|
+
}
|