@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,175 +2,173 @@
|
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* 🔧 BSV Working Script Validation Example
|
|
5
|
-
*
|
|
5
|
+
*
|
|
6
6
|
* Creates a transaction with properly signed inputs that will pass
|
|
7
7
|
* the BSV script interpreter validation.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
const bsv = require('../index.js')
|
|
11
|
-
const { acceptTransaction } = require('./miner-simulator')
|
|
12
|
-
const { loadConfig } = require('./utxo-manager')
|
|
10
|
+
const bsv = require('../index.js')
|
|
11
|
+
const { acceptTransaction } = require('./miner-simulator')
|
|
12
|
+
const { loadConfig } = require('./utxo-manager')
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* Create a properly signed transaction that should pass script validation
|
|
16
16
|
*/
|
|
17
|
-
function createValidTransaction() {
|
|
18
|
-
console.log('🔧 Creating Valid BSV Transaction')
|
|
19
|
-
console.log('═'.repeat(80))
|
|
20
|
-
|
|
17
|
+
function createValidTransaction () {
|
|
18
|
+
console.log('🔧 Creating Valid BSV Transaction')
|
|
19
|
+
console.log('═'.repeat(80))
|
|
20
|
+
|
|
21
21
|
try {
|
|
22
22
|
// Load wallet config
|
|
23
|
-
const config = loadConfig()
|
|
24
|
-
const wallet = config.wallet
|
|
25
|
-
const utxo = config.utxo
|
|
26
|
-
|
|
23
|
+
const config = loadConfig()
|
|
24
|
+
const wallet = config.wallet
|
|
25
|
+
const utxo = config.utxo
|
|
26
|
+
|
|
27
27
|
// Create recipient
|
|
28
|
-
const recipientKey = new bsv.PrivateKey()
|
|
29
|
-
const recipientAddress = recipientKey.toAddress()
|
|
30
|
-
|
|
31
|
-
console.log('📋 Transaction Details:')
|
|
32
|
-
console.log(`👛 From: ${wallet.address}`)
|
|
33
|
-
console.log(`🎯 To: ${recipientAddress}`)
|
|
34
|
-
console.log(`💰 Amount: 20,000 satoshis`)
|
|
35
|
-
console.log(`💳 UTXO: ${utxo.txid}:${utxo.vout} (${utxo.satoshis} sats)`)
|
|
36
|
-
|
|
28
|
+
const recipientKey = new bsv.PrivateKey()
|
|
29
|
+
const recipientAddress = recipientKey.toAddress()
|
|
30
|
+
|
|
31
|
+
console.log('📋 Transaction Details:')
|
|
32
|
+
console.log(`👛 From: ${wallet.address}`)
|
|
33
|
+
console.log(`🎯 To: ${recipientAddress}`)
|
|
34
|
+
console.log(`💰 Amount: 20,000 satoshis`)
|
|
35
|
+
console.log(`💳 UTXO: ${utxo.txid}:${utxo.vout} (${utxo.satoshis} sats)`)
|
|
36
|
+
|
|
37
37
|
// Create the transaction step by step
|
|
38
|
-
const tx = new bsv.Transaction()
|
|
39
|
-
|
|
38
|
+
const tx = new bsv.Transaction()
|
|
39
|
+
|
|
40
40
|
// Add input
|
|
41
41
|
tx.from({
|
|
42
42
|
txid: utxo.txid,
|
|
43
43
|
vout: utxo.vout,
|
|
44
44
|
scriptPubKey: utxo.script,
|
|
45
45
|
satoshis: utxo.satoshis
|
|
46
|
-
})
|
|
47
|
-
|
|
46
|
+
})
|
|
47
|
+
|
|
48
48
|
// Add outputs
|
|
49
|
-
tx.to(recipientAddress, 20000)
|
|
50
|
-
tx.change(wallet.address)
|
|
51
|
-
tx.fee(1000)
|
|
52
|
-
|
|
53
|
-
console.log('\n🔐 Signing transaction...')
|
|
54
|
-
console.log(`Private Key: ${wallet.privateKeyWIF}`)
|
|
55
|
-
console.log(`Input Script (before): ${tx.inputs[0].script ? tx.inputs[0].script.toHex() : 'empty'}`)
|
|
56
|
-
|
|
49
|
+
tx.to(recipientAddress, 20000)
|
|
50
|
+
tx.change(wallet.address)
|
|
51
|
+
tx.fee(1000)
|
|
52
|
+
|
|
53
|
+
console.log('\n🔐 Signing transaction...')
|
|
54
|
+
console.log(`Private Key: ${wallet.privateKeyWIF}`)
|
|
55
|
+
console.log(`Input Script (before): ${tx.inputs[0].script ? tx.inputs[0].script.toHex() : 'empty'}`)
|
|
56
|
+
|
|
57
57
|
// Sign with the correct private key and signature type
|
|
58
|
-
const privateKey = bsv.PrivateKey.fromWIF(wallet.privateKeyWIF)
|
|
59
|
-
|
|
58
|
+
const privateKey = bsv.PrivateKey.fromWIF(wallet.privateKeyWIF)
|
|
59
|
+
|
|
60
60
|
// Sign with SIGHASH_ALL | SIGHASH_FORKID
|
|
61
|
-
const sigType = bsv.crypto.Signature.SIGHASH_ALL | bsv.crypto.Signature.SIGHASH_FORKID
|
|
62
|
-
tx.sign(privateKey, sigType)
|
|
63
|
-
|
|
64
|
-
console.log(`Input Script (after): ${tx.inputs[0].script.toHex()}`)
|
|
65
|
-
console.log(`Script ASM: ${tx.inputs[0].script.toASM()}`)
|
|
66
|
-
|
|
67
|
-
console.log('\n✅ Transaction signed successfully')
|
|
68
|
-
console.log(`🆔 Transaction ID: ${tx.id}`)
|
|
69
|
-
console.log(`📦 Raw Hex: ${tx.toString()}`)
|
|
70
|
-
|
|
61
|
+
const sigType = bsv.crypto.Signature.SIGHASH_ALL | bsv.crypto.Signature.SIGHASH_FORKID
|
|
62
|
+
tx.sign(privateKey, sigType)
|
|
63
|
+
|
|
64
|
+
console.log(`Input Script (after): ${tx.inputs[0].script.toHex()}`)
|
|
65
|
+
console.log(`Script ASM: ${tx.inputs[0].script.toASM()}`)
|
|
66
|
+
|
|
67
|
+
console.log('\n✅ Transaction signed successfully')
|
|
68
|
+
console.log(`🆔 Transaction ID: ${tx.id}`)
|
|
69
|
+
console.log(`📦 Raw Hex: ${tx.toString()}`)
|
|
70
|
+
|
|
71
71
|
// Verify the signature locally first
|
|
72
|
-
console.log('\n🔍 Local signature verification:')
|
|
72
|
+
console.log('\n🔍 Local signature verification:')
|
|
73
73
|
try {
|
|
74
|
-
const verified = tx.verify()
|
|
75
|
-
console.log(`Local verification: ${verified ? '✅ VALID' : '❌ INVALID'}`)
|
|
74
|
+
const verified = tx.verify()
|
|
75
|
+
console.log(`Local verification: ${verified ? '✅ VALID' : '❌ INVALID'}`)
|
|
76
76
|
} catch (error) {
|
|
77
|
-
console.log(`Local verification error: ${error.message}`)
|
|
77
|
+
console.log(`Local verification error: ${error.message}`)
|
|
78
78
|
}
|
|
79
|
-
|
|
80
|
-
return tx
|
|
81
|
-
|
|
79
|
+
|
|
80
|
+
return tx
|
|
82
81
|
} catch (error) {
|
|
83
|
-
console.error('❌ Error creating transaction:', error.message)
|
|
84
|
-
return null
|
|
82
|
+
console.error('❌ Error creating transaction:', error.message)
|
|
83
|
+
return null
|
|
85
84
|
}
|
|
86
85
|
}
|
|
87
86
|
|
|
88
87
|
/**
|
|
89
88
|
* Test the transaction with our miner
|
|
90
89
|
*/
|
|
91
|
-
function testWithMiner() {
|
|
92
|
-
console.log('\n' + '═'.repeat(80))
|
|
93
|
-
console.log('🎯 Testing with BSV Script Interpreter Miner')
|
|
94
|
-
console.log('═'.repeat(80))
|
|
95
|
-
|
|
96
|
-
const tx = createValidTransaction()
|
|
97
|
-
|
|
90
|
+
function testWithMiner () {
|
|
91
|
+
console.log('\n' + '═'.repeat(80))
|
|
92
|
+
console.log('🎯 Testing with BSV Script Interpreter Miner')
|
|
93
|
+
console.log('═'.repeat(80))
|
|
94
|
+
|
|
95
|
+
const tx = createValidTransaction()
|
|
96
|
+
|
|
98
97
|
if (!tx) {
|
|
99
|
-
console.log('❌ Failed to create transaction')
|
|
100
|
-
return
|
|
98
|
+
console.log('❌ Failed to create transaction')
|
|
99
|
+
return
|
|
101
100
|
}
|
|
102
|
-
|
|
101
|
+
|
|
103
102
|
// Test with full script validation
|
|
104
|
-
console.log('\n📡 Sending to miner with full BSV script validation...')
|
|
105
|
-
const result = acceptTransaction(tx)
|
|
106
|
-
|
|
103
|
+
console.log('\n📡 Sending to miner with full BSV script validation...')
|
|
104
|
+
const result = acceptTransaction(tx)
|
|
105
|
+
|
|
107
106
|
if (result.accepted) {
|
|
108
|
-
console.log('\n🎉 SUCCESS! Transaction accepted by BSV script interpreter!')
|
|
109
|
-
console.log(`✅ TXID: ${result.txid}`)
|
|
107
|
+
console.log('\n🎉 SUCCESS! Transaction accepted by BSV script interpreter!')
|
|
108
|
+
console.log(`✅ TXID: ${result.txid}`)
|
|
110
109
|
} else {
|
|
111
|
-
console.log('\n❌ Transaction rejected')
|
|
112
|
-
console.log('Errors:', result.errors)
|
|
110
|
+
console.log('\n❌ Transaction rejected')
|
|
111
|
+
console.log('Errors:', result.errors)
|
|
113
112
|
}
|
|
114
|
-
|
|
115
|
-
return result
|
|
113
|
+
|
|
114
|
+
return result
|
|
116
115
|
}
|
|
117
116
|
|
|
118
117
|
/**
|
|
119
118
|
* Debug signature creation process
|
|
120
119
|
*/
|
|
121
|
-
function debugSignatureCreation() {
|
|
122
|
-
console.log('\n' + '═'.repeat(80))
|
|
123
|
-
console.log('🔍 Debugging Signature Creation')
|
|
124
|
-
console.log('═'.repeat(80))
|
|
125
|
-
|
|
120
|
+
function debugSignatureCreation () {
|
|
121
|
+
console.log('\n' + '═'.repeat(80))
|
|
122
|
+
console.log('🔍 Debugging Signature Creation')
|
|
123
|
+
console.log('═'.repeat(80))
|
|
124
|
+
|
|
126
125
|
try {
|
|
127
|
-
const config = loadConfig()
|
|
128
|
-
const wallet = config.wallet
|
|
129
|
-
const utxo = config.utxo
|
|
130
|
-
|
|
131
|
-
console.log('🔑 Wallet Info:')
|
|
132
|
-
console.log(`Address: ${wallet.address}`)
|
|
133
|
-
console.log(`Private Key: ${wallet.privateKeyWIF}`)
|
|
134
|
-
console.log(`Public Key: ${wallet.publicKey}`)
|
|
135
|
-
|
|
136
|
-
console.log('\n💰 UTXO Info:')
|
|
137
|
-
console.log(`TXID: ${utxo.txid}`)
|
|
138
|
-
console.log(`Vout: ${utxo.vout}`)
|
|
139
|
-
console.log(`Value: ${utxo.satoshis} satoshis`)
|
|
140
|
-
console.log(`Script: ${utxo.script}`)
|
|
141
|
-
|
|
126
|
+
const config = loadConfig()
|
|
127
|
+
const wallet = config.wallet
|
|
128
|
+
const utxo = config.utxo
|
|
129
|
+
|
|
130
|
+
console.log('🔑 Wallet Info:')
|
|
131
|
+
console.log(`Address: ${wallet.address}`)
|
|
132
|
+
console.log(`Private Key: ${wallet.privateKeyWIF}`)
|
|
133
|
+
console.log(`Public Key: ${wallet.publicKey}`)
|
|
134
|
+
|
|
135
|
+
console.log('\n💰 UTXO Info:')
|
|
136
|
+
console.log(`TXID: ${utxo.txid}`)
|
|
137
|
+
console.log(`Vout: ${utxo.vout}`)
|
|
138
|
+
console.log(`Value: ${utxo.satoshis} satoshis`)
|
|
139
|
+
console.log(`Script: ${utxo.script}`)
|
|
140
|
+
|
|
142
141
|
// Parse the script
|
|
143
|
-
const script = bsv.Script.fromHex(utxo.script)
|
|
144
|
-
console.log(`Script ASM: ${script.toASM()}`)
|
|
145
|
-
|
|
142
|
+
const script = bsv.Script.fromHex(utxo.script)
|
|
143
|
+
console.log(`Script ASM: ${script.toASM()}`)
|
|
144
|
+
|
|
146
145
|
// Verify the address matches
|
|
147
|
-
const scriptAddress = script.toAddress()
|
|
148
|
-
console.log(`Script Address: ${scriptAddress}`)
|
|
149
|
-
console.log(`Wallet Address: ${wallet.address}`)
|
|
150
|
-
console.log(`Addresses match: ${scriptAddress.toString() === wallet.address ? '✅' : '❌'}`)
|
|
151
|
-
|
|
146
|
+
const scriptAddress = script.toAddress()
|
|
147
|
+
console.log(`Script Address: ${scriptAddress}`)
|
|
148
|
+
console.log(`Wallet Address: ${wallet.address}`)
|
|
149
|
+
console.log(`Addresses match: ${scriptAddress.toString() === wallet.address ? '✅' : '❌'}`)
|
|
152
150
|
} catch (error) {
|
|
153
|
-
console.error('❌ Debug error:', error.message)
|
|
151
|
+
console.error('❌ Debug error:', error.message)
|
|
154
152
|
}
|
|
155
153
|
}
|
|
156
154
|
|
|
157
155
|
/**
|
|
158
156
|
* Run all tests
|
|
159
157
|
*/
|
|
160
|
-
function runTests() {
|
|
161
|
-
debugSignatureCreation()
|
|
162
|
-
const result = testWithMiner()
|
|
163
|
-
|
|
158
|
+
function runTests () {
|
|
159
|
+
debugSignatureCreation()
|
|
160
|
+
const result = testWithMiner()
|
|
161
|
+
|
|
164
162
|
if (result && result.accepted) {
|
|
165
|
-
console.log('\n🎯 Perfect! The BSV script interpreter accepted our transaction!')
|
|
163
|
+
console.log('\n🎯 Perfect! The BSV script interpreter accepted our transaction!')
|
|
166
164
|
} else {
|
|
167
|
-
console.log('\n🔧 Need to fix signature creation for script interpreter...')
|
|
165
|
+
console.log('\n🔧 Need to fix signature creation for script interpreter...')
|
|
168
166
|
}
|
|
169
167
|
}
|
|
170
168
|
|
|
171
169
|
// Run tests if called directly
|
|
172
170
|
if (require.main === module) {
|
|
173
|
-
runTests()
|
|
171
|
+
runTests()
|
|
174
172
|
}
|
|
175
173
|
|
|
176
174
|
module.exports = {
|
|
@@ -178,4 +176,4 @@ module.exports = {
|
|
|
178
176
|
testWithMiner,
|
|
179
177
|
debugSignatureCreation,
|
|
180
178
|
runTests
|
|
181
|
-
}
|
|
179
|
+
}
|
package/SECURITY.md
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
# Security Audit and Fixes
|
|
2
|
-
|
|
3
|
-
## Summary
|
|
4
|
-
|
|
5
|
-
This fork addresses critical elliptic curve cryptography vulnerabilities in BSV@1.5.6 while maintaining 100% API compatibility as a complete drop-in replacement.
|
|
6
|
-
|
|
7
|
-
## Vulnerabilities Fixed
|
|
8
|
-
|
|
9
|
-
### 1. Zero Parameter Signature Attack
|
|
10
|
-
**CVE Context**: Signatures with r=0 or s=0 could bypass validation checks
|
|
11
|
-
**Fix**: Enhanced `sigError()` method in `lib/crypto/ecdsa.js` to explicitly reject zero values
|
|
12
|
-
**Test**: Verified in security validation suite
|
|
13
|
-
|
|
14
|
-
### 2. Signature Malleability
|
|
15
|
-
**CVE Context**: High s values (s > n/2) allow multiple valid signatures for the same message
|
|
16
|
-
**Fix**: Canonical signature enforcement in signature validation
|
|
17
|
-
**Test**: High s values automatically converted to canonical form
|
|
18
|
-
|
|
19
|
-
### 3. Range Validation
|
|
20
|
-
**CVE Context**: Missing validation for parameters outside elliptic curve order
|
|
21
|
-
**Fix**: Added bounds checking for r and s values against curve order n
|
|
22
|
-
**Test**: Out-of-range parameters properly rejected
|
|
23
|
-
|
|
24
|
-
## Implementation Details
|
|
25
|
-
|
|
26
|
-
### Files Modified
|
|
27
|
-
- `lib/crypto/ecdsa.js`: Enhanced signature error checking
|
|
28
|
-
- `lib/crypto/signature.js`: Added security validation methods
|
|
29
|
-
- `index.js`: Added SmartLedger security exports
|
|
30
|
-
|
|
31
|
-
### Security Methods Added
|
|
32
|
-
- `Signature.prototype.isCanonical()`: Check if s ≤ n/2
|
|
33
|
-
- `Signature.prototype.validate()`: Comprehensive parameter validation
|
|
34
|
-
- `Signature.prototype.toCanonical()`: Convert to canonical form
|
|
35
|
-
- `SmartVerify.verifySignature()`: Enhanced strict verification
|
|
36
|
-
|
|
37
|
-
### Compatibility Approach
|
|
38
|
-
- Security validation only applied during cryptographic operations
|
|
39
|
-
- Format validation preserved for backward compatibility
|
|
40
|
-
- All original BSV tests continue to pass
|
|
41
|
-
- No breaking changes to existing API
|
|
42
|
-
|
|
43
|
-
## Test Results
|
|
44
|
-
|
|
45
|
-
### Original BSV Test Suite
|
|
46
|
-
- Signature tests: 41/41 passing
|
|
47
|
-
- ECDSA tests: All core functionality verified
|
|
48
|
-
- Full compatibility test: All BSV components accessible
|
|
49
|
-
|
|
50
|
-
### Security Validation Tests
|
|
51
|
-
- Zero r value rejection: ✅ PASS
|
|
52
|
-
- Zero s value rejection: ✅ PASS
|
|
53
|
-
- High s canonicalization: ✅ PASS
|
|
54
|
-
- Range validation: ✅ PASS
|
|
55
|
-
- Strict mode validation: ✅ PASS
|
|
56
|
-
|
|
57
|
-
## Security Validation Script
|
|
58
|
-
|
|
59
|
-
Run comprehensive security tests:
|
|
60
|
-
```bash
|
|
61
|
-
node test_security.js
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
## Verification Steps
|
|
65
|
-
|
|
66
|
-
1. **Install the package**: `npm install @smartledger/bsv`
|
|
67
|
-
2. **Run compatibility tests**: `npm test`
|
|
68
|
-
3. **Run security validation**: `node test_security.js`
|
|
69
|
-
4. **Verify drop-in replacement**: All existing BSV code works unchanged
|
|
70
|
-
|
|
71
|
-
## Responsible Disclosure
|
|
72
|
-
|
|
73
|
-
These security fixes address known vulnerabilities in elliptic curve signature validation. The fixes have been implemented with careful attention to maintaining backward compatibility while eliminating attack vectors.
|
|
74
|
-
|
|
75
|
-
For security concerns or questions, please contact the SmartLedger team.
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
var bsvCovenant=function(t){var e={};function r(n){if(e[n])return e[n].exports;var o=e[n]={i:n,l:!1,exports:{}};return t[n].call(o.exports,o,o.exports,r),o.l=!0,o.exports}return r.m=t,r.c=e,r.d=function(t,e,n){r.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:n})},r.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},r.t=function(t,e){if(1&e&&(t=r(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var o in t)r.d(n,o,function(e){return t[e]}.bind(null,o));return n},r.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return r.d(e,"a",e),e},r.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},r.p="",r(r.s=0)}([function(t,e,r){"use strict";if("undefined"==typeof bsv)throw new Error("CovenantInterface requires BSV library. Load bsv.min.js first.");const n=r(1);"undefined"!=typeof window&&(window.bsvCovenant={CovenantInterface:n,version:bsv.version||"unknown"},"undefined"!=typeof bsv&&(bsv.CovenantInterface=n),console.log("CovenantInterface standalone module loaded")),t.exports={CovenantInterface:n,version:bsv.version||"unknown"}},function(t,e,r){(function(e){const n=r(7);class o{constructor(t,e){this.tx=t,this.covenant=e,this.preimages=new Map}getPreimage(t,e,r){const n=`${t}-${e.toHex()}-${r}`;if(!this.preimages.has(n)){const o=this.covenant.getPreimage(this.tx,t,e,r);this.preimages.set(n,o)}return this.preimages.get(n)}signInput(t,e,r,o){const i=this.covenant.createSignature(this.tx,e,t,r,o),a=(new n.Script).add(i).add(e.publicKey.toBuffer());return this.tx.inputs[t].setScript(a),this}getTransaction(){return this.tx}verify(){try{return this.tx.verify()}catch(t){return console.error("Transaction validation error:",t.message),!1}}}class i{constructor(t){this.hex=t,this.buffer=e.from(t,"hex"),this.parseFields()}parseFields(){let t=0;this.nVersion=this.buffer.subarray(t,t+4),this.nVersionValue=this.buffer.readUInt32LE(t),t+=4,this.hashPrevouts=this.buffer.subarray(t,t+32),t+=32,this.hashSequence=this.buffer.subarray(t,t+32),t+=32,this.outpoint=this.buffer.subarray(t,t+36),this.prevTxId=this.buffer.subarray(t,t+32),t+=32,this.outputIndex=this.buffer.subarray(t,t+4),this.outputIndexValue=this.buffer.readUInt32LE(t),t+=4;const e=this.readVarInt(t);t+=this.getVarIntLength(e),this.scriptCode=this.buffer.subarray(t,t+e),t+=e,this.amount=this.buffer.subarray(t,t+8),this.amountValue=this.buffer.readBigUInt64LE(t),t+=8,this.nSequence=this.buffer.subarray(t,t+4),this.nSequenceValue=this.buffer.readUInt32LE(t),t+=4,this.hashOutputs=this.buffer.subarray(t,t+32),t+=32,this.nLockTime=this.buffer.subarray(t,t+4),this.nLockTimeValue=this.buffer.readUInt32LE(t),t+=4,this.sighashType=this.buffer.subarray(t,t+4),this.sighashTypeValue=this.buffer.readUInt32LE(t),t+=4,this.isValid=t===this.buffer.length&&this.buffer.length>=108}readVarInt(t){const e=this.buffer.readUInt8(t);return e<253?e:253===e?this.buffer.readUInt16LE(t+1):254===e?this.buffer.readUInt32LE(t+1):255===e?this.buffer.readBigUInt64LE(t+1):void 0}getVarIntLength(t){return t<253?1:t<=65535?3:t<=4294967295?5:9}}class a{constructor(t,e){this.isValid=t,this.message=e}toString(){return`${this.isValid?"VALID":"INVALID"}: ${this.message}`}}t.exports={CovenantInterface:class{constructor(){this.bsv=n}createCovenantTransaction(t){const e=new n.Transaction;return t.inputs&&t.inputs.forEach(t=>e.from(t)),t.outputs&&t.outputs.forEach(t=>{t.script?e.addOutput(new n.Transaction.Output({script:t.script,satoshis:t.satoshis})):e.to(t.address,t.satoshis)}),t.feePerKb&&e.feePerKb(t.feePerKb),new o(e,this)}createSignature(t,r,o,i,a,f=null){f=f||n.crypto.Signature.SIGHASH_ALL|n.crypto.Signature.SIGHASH_FORKID;const s=n.Transaction.sighash.sign(t,r,f,o,i,new n.crypto.BN(a));return e.concat([s.toDER(),e.from([f])])}getPreimage(t,e,r,o,a=null){a=a||n.crypto.Signature.SIGHASH_ALL|n.crypto.Signature.SIGHASH_FORKID;const f=n.Transaction.sighash.sighash(t,a,e,r,new n.crypto.BN(o));return new i(f)}createStateMachine(t,r,o){const i=new n.Script;i.add(e.from([r])),i.add(n.Opcode.OP_EQUAL),i.add(n.Opcode.OP_VERIFY);for(let o=0;o<t.length-1;o++)o===r&&t[o].nextStates.forEach(t=>{i.add(e.from([t])),i.add(n.Opcode.OP_EQUAL),i.add(n.Opcode.OP_IF),i.add(n.Opcode.OP_ENDIF)});return i.add(n.Opcode.OP_DUP),i.add(n.Opcode.OP_HASH160),i.add(o.toAddress().hashBuffer),i.add(n.Opcode.OP_EQUALVERIFY),i.add(n.Opcode.OP_CHECKSIG),i}createEscrow(t,r,o,i=null){const a=new n.Script;return i&&(a.add(n.Opcode.OP_IF),a.add(e.from(i.toString(16).padStart(8,"0"),"hex").reverse()),a.add(n.Opcode.OP_CHECKLOCKTIMEVERIFY),a.add(n.Opcode.OP_DROP),a.add(t.toBuffer()),a.add(n.Opcode.OP_CHECKSIG),a.add(n.Opcode.OP_ELSE)),a.add(n.Opcode.OP_2),a.add(t.toBuffer()),a.add(r.toBuffer()),a.add(o.toBuffer()),a.add(n.Opcode.OP_3),a.add(n.Opcode.OP_CHECKMULTISIG),i&&a.add(n.Opcode.OP_ENDIF),a}createTokenTransfer(t,r,o=null){const i=new n.Script;return r>0&&(i.add(n.Opcode.OP_DUP),i.add(e.from(r.toString(16),"hex")),i.add(n.Opcode.OP_GREATERTHANOREQUAL),i.add(n.Opcode.OP_VERIFY)),o&&i.add(o.toBuffer()),i.add(n.Opcode.OP_DUP),i.add(n.Opcode.OP_HASH160),i.add(t.toAddress().hashBuffer),i.add(n.Opcode.OP_EQUALVERIFY),i.add(n.Opcode.OP_CHECKSIG),i}validateCovenant(t,e,r,o){try{const i=new n.Script.Interpreter,f=n.Script.Interpreter.SCRIPT_VERIFY_P2SH|n.Script.Interpreter.SCRIPT_VERIFY_STRICTENC|n.Script.Interpreter.SCRIPT_ENABLE_SIGHASH_FORKID|n.Script.Interpreter.SCRIPT_ENABLE_MAGNETIC_OPCODES|n.Script.Interpreter.SCRIPT_ENABLE_MONOLITH_OPCODES,s=i.verify(r,o,t,e,f);return new a(s,i.errstr||"Success")}catch(t){return new a(!1,t.message)}}createAdvancedCovenant(t,e={}){const r={pushtx:this.createPushtxCovenant,perpetual:this.createPerpetualCovenant,pels:this.createPerpetualCovenant,introspection:this.createIntrospectionCovenant},n=r[t];if(!n)throw new Error(`Unknown advanced covenant type: ${t}. Available types: ${Object.keys(r).join(", ")}`);return n.call(this,e)}createPushtxCovenant(t={}){const{publicKey:r="0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",enforceOutputs:o=!0,sighashType:i=65}=t,a=new n.Script;a.add(n.Opcode.OP_2DUP).add(n.Opcode.OP_HASH256).add(n.Opcode.OP_SWAP),a.add(e.from("ffffffff","hex")).add(n.Opcode.OP_CAT).add(n.Opcode.OP_SWAP).add(n.Opcode.OP_CAT),a.add(e.from("00000000","hex")).add(e.from("41000000","hex")).add(n.Opcode.OP_CAT).add(n.Opcode.OP_CAT),a.add(n.Opcode.OP_HASH256);a.add(e.from("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798","hex")).add(n.Opcode.OP_ADD);return a.add(e.from("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141","hex")).add(n.Opcode.OP_MOD),this._addDERConversion(a),a.add(e.from([i])).add(n.Opcode.OP_CAT).add(e.from(r,"hex")),a.add(n.Opcode.OP_CHECKSIGVERIFY),o&&this._addOutputValidation(a,t),a}createPerpetualCovenant(t={}){const{publicKeyHash:r,feeDeduction:o=512,enforceScript:i=!0,enforceValue:a=!0}=t;if(!r)throw new Error("publicKeyHash required for perpetual covenant");const f=new n.Script;return f.add(n.Opcode.OP_2DUP).add(n.Opcode.OP_BIN2NUM),o>0&&f.add(e.from(o.toString(16).padStart(4,"0"),"hex")).add(n.Opcode.OP_SUB),f.add(e.from([8])).add(n.Opcode.OP_NUM2BIN).add(n.Opcode.OP_SWAP).add(n.Opcode.OP_CAT),f.add(n.Opcode.OP_HASH256),this._addPreimageConstruction(f,t),this._addPushtxSignature(f,t),f.add(n.Opcode.OP_SWAP).add(e.from([104])).add(n.Opcode.OP_SPLIT).add(n.Opcode.OP_NIP).add(n.Opcode.OP_SWAP).add(e.from([8])).add(n.Opcode.OP_SPLIT).add(n.Opcode.OP_SWAP).add(n.Opcode.OP_CAT),(a||i)&&f.add(n.Opcode.OP_EQUALVERIFY),f.add(n.Opcode.OP_DUP).add(n.Opcode.OP_HASH160).add(e.from(r,"hex")).add(n.Opcode.OP_EQUALVERIFY).add(n.Opcode.OP_CHECKSIG),f}createIntrospectionCovenant(t={}){const{validateInputs:r=!1,validateOutputs:o=!0,validateSequence:i=!1,validateLocktime:a=!1}=t,f=new n.Script;return this._addPushtxSignature(f,t),r&&f.add(n.Opcode.OP_DUP).add(e.from([4,36])).add(n.Opcode.OP_SPLIT).add(n.Opcode.OP_DROP),o&&f.add(n.Opcode.OP_DUP).add(e.from([100])).add(n.Opcode.OP_SPLIT).add(n.Opcode.OP_NIP).add(e.from([32])).add(n.Opcode.OP_SPLIT).add(n.Opcode.OP_DROP),f}_addDERConversion(t){t.add(n.Opcode.OP_DUP).add(e.from("7fffffffffffffffffffffffffffffff5d576e7357a4501ddfe92f46681b20a0","hex")).add(n.Opcode.OP_GREATERTHAN).add(n.Opcode.OP_IF);t.add(e.from("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141","hex")).add(n.Opcode.OP_SWAP).add(n.Opcode.OP_SUB),t.add(n.Opcode.OP_ENDIF),t.add(n.Opcode.OP_SIZE).add(n.Opcode.OP_DUP).add(e.from([36])).add(n.Opcode.OP_ADD).add(e.from([48])).add(n.Opcode.OP_SWAP).add(n.Opcode.OP_CAT),t.add(e.from("022079be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f8179802","hex")).add(n.Opcode.OP_CAT).add(n.Opcode.OP_SWAP).add(n.Opcode.OP_CAT).add(n.Opcode.OP_SWAP).add(n.Opcode.OP_CAT)}_addOutputValidation(t,r){const{enforceValue:o,enforceScript:i,enforceCount:a}=r;o&&t.add(n.Opcode.OP_DUP).add(e.from([8])).add(n.Opcode.OP_SPLIT),i&&t.add(n.Opcode.OP_DUP).add(n.Opcode.OP_SIZE).add(e.from([9])).add(n.Opcode.OP_SUB).add(n.Opcode.OP_SPLIT).add(n.Opcode.OP_NIP)}_addPreimageConstruction(t,r){const{version:o=1,locktime:i=0,sighashType:a=65,sequence:f=4294967295}=r;t.add(e.from(f.toString(16).padStart(8,"0"),"hex")).add(n.Opcode.OP_CAT).add(n.Opcode.OP_SWAP).add(n.Opcode.OP_CAT).add(e.from(i.toString(16).padStart(8,"0"),"hex")).add(n.Opcode.OP_CAT).add(e.from(a.toString(16).padStart(8,"0"),"hex")).add(n.Opcode.OP_CAT)}_addPushtxSignature(t,r){const{publicKey:o="0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798",sighashType:i=65}=r;t.add(n.Opcode.OP_HASH256);t.add(e.from("79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798","hex")).add(n.Opcode.OP_ADD);t.add(e.from("fffffffffffffffffffffffffffffffebaaedce6af48a03bbfd25e8cd0364141","hex")).add(n.Opcode.OP_MOD),this._addDERConversion(t),t.add(e.from([i])).add(n.Opcode.OP_CAT).add(e.from(o,"hex")).add(n.Opcode.OP_CHECKSIGVERIFY)}},CovenantTransaction:o,CovenantPreimage:i,CovenantValidation:a}}).call(this,r(2).Buffer)},function(t,e,r){"use strict";(function(t){
|
|
2
|
-
/*!
|
|
3
|
-
* The buffer module from node.js, for the browser.
|
|
4
|
-
*
|
|
5
|
-
* @author Feross Aboukhadijeh <http://feross.org>
|
|
6
|
-
* @license MIT
|
|
7
|
-
*/
|
|
8
|
-
var n=r(4),o=r(5),i=r(6);function a(){return s.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function f(t,e){if(a()<e)throw new RangeError("Invalid typed array length");return s.TYPED_ARRAY_SUPPORT?(t=new Uint8Array(e)).__proto__=s.prototype:(null===t&&(t=new s(e)),t.length=e),t}function s(t,e,r){if(!(s.TYPED_ARRAY_SUPPORT||this instanceof s))return new s(t,e,r);if("number"==typeof t){if("string"==typeof e)throw new Error("If encoding is specified then the first argument must be a string");return h(this,t)}return u(this,t,e,r)}function u(t,e,r,n){if("number"==typeof e)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&e instanceof ArrayBuffer?function(t,e,r,n){if(e.byteLength,r<0||e.byteLength<r)throw new RangeError("'offset' is out of bounds");if(e.byteLength<r+(n||0))throw new RangeError("'length' is out of bounds");e=void 0===r&&void 0===n?new Uint8Array(e):void 0===n?new Uint8Array(e,r):new Uint8Array(e,r,n);s.TYPED_ARRAY_SUPPORT?(t=e).__proto__=s.prototype:t=c(t,e);return t}(t,e,r,n):"string"==typeof e?function(t,e,r){"string"==typeof r&&""!==r||(r="utf8");if(!s.isEncoding(r))throw new TypeError('"encoding" must be a valid string encoding');var n=0|l(e,r),o=(t=f(t,n)).write(e,r);o!==n&&(t=t.slice(0,o));return t}(t,e,r):function(t,e){if(s.isBuffer(e)){var r=0|p(e.length);return 0===(t=f(t,r)).length||e.copy(t,0,0,r),t}if(e){if("undefined"!=typeof ArrayBuffer&&e.buffer instanceof ArrayBuffer||"length"in e)return"number"!=typeof e.length||(n=e.length)!=n?f(t,0):c(t,e);if("Buffer"===e.type&&i(e.data))return c(t,e.data)}var n;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(t,e)}function d(t){if("number"!=typeof t)throw new TypeError('"size" argument must be a number');if(t<0)throw new RangeError('"size" argument must not be negative')}function h(t,e){if(d(e),t=f(t,e<0?0:0|p(e)),!s.TYPED_ARRAY_SUPPORT)for(var r=0;r<e;++r)t[r]=0;return t}function c(t,e){var r=e.length<0?0:0|p(e.length);t=f(t,r);for(var n=0;n<r;n+=1)t[n]=255&e[n];return t}function p(t){if(t>=a())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+a().toString(16)+" bytes");return 0|t}function l(t,e){if(s.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var r=t.length;if(0===r)return 0;for(var n=!1;;)switch(e){case"ascii":case"latin1":case"binary":return r;case"utf8":case"utf-8":case void 0:return V(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*r;case"hex":return r>>>1;case"base64":return F(t).length;default:if(n)return V(t).length;e=(""+e).toLowerCase(),n=!0}}function g(t,e,r){var n=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===r||r>this.length)&&(r=this.length),r<=0)return"";if((r>>>=0)<=(e>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return R(this,e,r);case"utf8":case"utf-8":return m(this,e,r);case"ascii":return I(this,e,r);case"latin1":case"binary":return T(this,e,r);case"base64":return S(this,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return C(this,e,r);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function O(t,e,r){var n=t[e];t[e]=t[r],t[r]=n}function y(t,e,r,n,o){if(0===t.length)return-1;if("string"==typeof r?(n=r,r=0):r>2147483647?r=2147483647:r<-2147483648&&(r=-2147483648),r=+r,isNaN(r)&&(r=o?0:t.length-1),r<0&&(r=t.length+r),r>=t.length){if(o)return-1;r=t.length-1}else if(r<0){if(!o)return-1;r=0}if("string"==typeof e&&(e=s.from(e,n)),s.isBuffer(e))return 0===e.length?-1:P(t,e,r,n,o);if("number"==typeof e)return e&=255,s.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(t,e,r):Uint8Array.prototype.lastIndexOf.call(t,e,r):P(t,[e],r,n,o);throw new TypeError("val must be string, number or Buffer")}function P(t,e,r,n,o){var i,a=1,f=t.length,s=e.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||e.length<2)return-1;a=2,f/=2,s/=2,r/=2}function u(t,e){return 1===a?t[e]:t.readUInt16BE(e*a)}if(o){var d=-1;for(i=r;i<f;i++)if(u(t,i)===u(e,-1===d?0:i-d)){if(-1===d&&(d=i),i-d+1===s)return d*a}else-1!==d&&(i-=i-d),d=-1}else for(r+s>f&&(r=f-s),i=r;i>=0;i--){for(var h=!0,c=0;c<s;c++)if(u(t,i+c)!==u(e,c)){h=!1;break}if(h)return i}return-1}function _(t,e,r,n){r=Number(r)||0;var o=t.length-r;n?(n=Number(n))>o&&(n=o):n=o;var i=e.length;if(i%2!=0)throw new TypeError("Invalid hex string");n>i/2&&(n=i/2);for(var a=0;a<n;++a){var f=parseInt(e.substr(2*a,2),16);if(isNaN(f))return a;t[r+a]=f}return a}function b(t,e,r,n){return k(V(e,t.length-r),t,r,n)}function w(t,e,r,n){return k(function(t){for(var e=[],r=0;r<t.length;++r)e.push(255&t.charCodeAt(r));return e}(e),t,r,n)}function v(t,e,r,n){return w(t,e,r,n)}function E(t,e,r,n){return k(F(e),t,r,n)}function A(t,e,r,n){return k(function(t,e){for(var r,n,o,i=[],a=0;a<t.length&&!((e-=2)<0);++a)r=t.charCodeAt(a),n=r>>8,o=r%256,i.push(o),i.push(n);return i}(e,t.length-r),t,r,n)}function S(t,e,r){return 0===e&&r===t.length?n.fromByteArray(t):n.fromByteArray(t.slice(e,r))}function m(t,e,r){r=Math.min(t.length,r);for(var n=[],o=e;o<r;){var i,a,f,s,u=t[o],d=null,h=u>239?4:u>223?3:u>191?2:1;if(o+h<=r)switch(h){case 1:u<128&&(d=u);break;case 2:128==(192&(i=t[o+1]))&&(s=(31&u)<<6|63&i)>127&&(d=s);break;case 3:i=t[o+1],a=t[o+2],128==(192&i)&&128==(192&a)&&(s=(15&u)<<12|(63&i)<<6|63&a)>2047&&(s<55296||s>57343)&&(d=s);break;case 4:i=t[o+1],a=t[o+2],f=t[o+3],128==(192&i)&&128==(192&a)&&128==(192&f)&&(s=(15&u)<<18|(63&i)<<12|(63&a)<<6|63&f)>65535&&s<1114112&&(d=s)}null===d?(d=65533,h=1):d>65535&&(d-=65536,n.push(d>>>10&1023|55296),d=56320|1023&d),n.push(d),o+=h}return function(t){var e=t.length;if(e<=4096)return String.fromCharCode.apply(String,t);var r="",n=0;for(;n<e;)r+=String.fromCharCode.apply(String,t.slice(n,n+=4096));return r}(n)}e.Buffer=s,e.SlowBuffer=function(t){+t!=t&&(t=0);return s.alloc(+t)},e.INSPECT_MAX_BYTES=50,s.TYPED_ARRAY_SUPPORT=void 0!==t.TYPED_ARRAY_SUPPORT?t.TYPED_ARRAY_SUPPORT:function(){try{var t=new Uint8Array(1);return t.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===t.foo()&&"function"==typeof t.subarray&&0===t.subarray(1,1).byteLength}catch(t){return!1}}(),e.kMaxLength=a(),s.poolSize=8192,s._augment=function(t){return t.__proto__=s.prototype,t},s.from=function(t,e,r){return u(null,t,e,r)},s.TYPED_ARRAY_SUPPORT&&(s.prototype.__proto__=Uint8Array.prototype,s.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&s[Symbol.species]===s&&Object.defineProperty(s,Symbol.species,{value:null,configurable:!0})),s.alloc=function(t,e,r){return function(t,e,r,n){return d(e),e<=0?f(t,e):void 0!==r?"string"==typeof n?f(t,e).fill(r,n):f(t,e).fill(r):f(t,e)}(null,t,e,r)},s.allocUnsafe=function(t){return h(null,t)},s.allocUnsafeSlow=function(t){return h(null,t)},s.isBuffer=function(t){return!(null==t||!t._isBuffer)},s.compare=function(t,e){if(!s.isBuffer(t)||!s.isBuffer(e))throw new TypeError("Arguments must be Buffers");if(t===e)return 0;for(var r=t.length,n=e.length,o=0,i=Math.min(r,n);o<i;++o)if(t[o]!==e[o]){r=t[o],n=e[o];break}return r<n?-1:n<r?1:0},s.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},s.concat=function(t,e){if(!i(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return s.alloc(0);var r;if(void 0===e)for(e=0,r=0;r<t.length;++r)e+=t[r].length;var n=s.allocUnsafe(e),o=0;for(r=0;r<t.length;++r){var a=t[r];if(!s.isBuffer(a))throw new TypeError('"list" argument must be an Array of Buffers');a.copy(n,o),o+=a.length}return n},s.byteLength=l,s.prototype._isBuffer=!0,s.prototype.swap16=function(){var t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var e=0;e<t;e+=2)O(this,e,e+1);return this},s.prototype.swap32=function(){var t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var e=0;e<t;e+=4)O(this,e,e+3),O(this,e+1,e+2);return this},s.prototype.swap64=function(){var t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var e=0;e<t;e+=8)O(this,e,e+7),O(this,e+1,e+6),O(this,e+2,e+5),O(this,e+3,e+4);return this},s.prototype.toString=function(){var t=0|this.length;return 0===t?"":0===arguments.length?m(this,0,t):g.apply(this,arguments)},s.prototype.equals=function(t){if(!s.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===s.compare(this,t)},s.prototype.inspect=function(){var t="",r=e.INSPECT_MAX_BYTES;return this.length>0&&(t=this.toString("hex",0,r).match(/.{2}/g).join(" "),this.length>r&&(t+=" ... ")),"<Buffer "+t+">"},s.prototype.compare=function(t,e,r,n,o){if(!s.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===r&&(r=t?t.length:0),void 0===n&&(n=0),void 0===o&&(o=this.length),e<0||r>t.length||n<0||o>this.length)throw new RangeError("out of range index");if(n>=o&&e>=r)return 0;if(n>=o)return-1;if(e>=r)return 1;if(this===t)return 0;for(var i=(o>>>=0)-(n>>>=0),a=(r>>>=0)-(e>>>=0),f=Math.min(i,a),u=this.slice(n,o),d=t.slice(e,r),h=0;h<f;++h)if(u[h]!==d[h]){i=u[h],a=d[h];break}return i<a?-1:a<i?1:0},s.prototype.includes=function(t,e,r){return-1!==this.indexOf(t,e,r)},s.prototype.indexOf=function(t,e,r){return y(this,t,e,r,!0)},s.prototype.lastIndexOf=function(t,e,r){return y(this,t,e,r,!1)},s.prototype.write=function(t,e,r,n){if(void 0===e)n="utf8",r=this.length,e=0;else if(void 0===r&&"string"==typeof e)n=e,r=this.length,e=0;else{if(!isFinite(e))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");e|=0,isFinite(r)?(r|=0,void 0===n&&(n="utf8")):(n=r,r=void 0)}var o=this.length-e;if((void 0===r||r>o)&&(r=o),t.length>0&&(r<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var i=!1;;)switch(n){case"hex":return _(this,t,e,r);case"utf8":case"utf-8":return b(this,t,e,r);case"ascii":return w(this,t,e,r);case"latin1":case"binary":return v(this,t,e,r);case"base64":return E(this,t,e,r);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return A(this,t,e,r);default:if(i)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),i=!0}},s.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function I(t,e,r){var n="";r=Math.min(t.length,r);for(var o=e;o<r;++o)n+=String.fromCharCode(127&t[o]);return n}function T(t,e,r){var n="";r=Math.min(t.length,r);for(var o=e;o<r;++o)n+=String.fromCharCode(t[o]);return n}function R(t,e,r){var n=t.length;(!e||e<0)&&(e=0),(!r||r<0||r>n)&&(r=n);for(var o="",i=e;i<r;++i)o+=N(t[i]);return o}function C(t,e,r){for(var n=t.slice(e,r),o="",i=0;i<n.length;i+=2)o+=String.fromCharCode(n[i]+256*n[i+1]);return o}function U(t,e,r){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+e>r)throw new RangeError("Trying to access beyond buffer length")}function B(t,e,r,n,o,i){if(!s.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>o||e<i)throw new RangeError('"value" argument is out of bounds');if(r+n>t.length)throw new RangeError("Index out of range")}function L(t,e,r,n){e<0&&(e=65535+e+1);for(var o=0,i=Math.min(t.length-r,2);o<i;++o)t[r+o]=(e&255<<8*(n?o:1-o))>>>8*(n?o:1-o)}function x(t,e,r,n){e<0&&(e=4294967295+e+1);for(var o=0,i=Math.min(t.length-r,4);o<i;++o)t[r+o]=e>>>8*(n?o:3-o)&255}function D(t,e,r,n,o,i){if(r+n>t.length)throw new RangeError("Index out of range");if(r<0)throw new RangeError("Index out of range")}function Y(t,e,r,n,i){return i||D(t,0,r,4),o.write(t,e,r,n,23,4),r+4}function M(t,e,r,n,i){return i||D(t,0,r,8),o.write(t,e,r,n,52,8),r+8}s.prototype.slice=function(t,e){var r,n=this.length;if((t=~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),(e=void 0===e?n:~~e)<0?(e+=n)<0&&(e=0):e>n&&(e=n),e<t&&(e=t),s.TYPED_ARRAY_SUPPORT)(r=this.subarray(t,e)).__proto__=s.prototype;else{var o=e-t;r=new s(o,void 0);for(var i=0;i<o;++i)r[i]=this[i+t]}return r},s.prototype.readUIntLE=function(t,e,r){t|=0,e|=0,r||U(t,e,this.length);for(var n=this[t],o=1,i=0;++i<e&&(o*=256);)n+=this[t+i]*o;return n},s.prototype.readUIntBE=function(t,e,r){t|=0,e|=0,r||U(t,e,this.length);for(var n=this[t+--e],o=1;e>0&&(o*=256);)n+=this[t+--e]*o;return n},s.prototype.readUInt8=function(t,e){return e||U(t,1,this.length),this[t]},s.prototype.readUInt16LE=function(t,e){return e||U(t,2,this.length),this[t]|this[t+1]<<8},s.prototype.readUInt16BE=function(t,e){return e||U(t,2,this.length),this[t]<<8|this[t+1]},s.prototype.readUInt32LE=function(t,e){return e||U(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},s.prototype.readUInt32BE=function(t,e){return e||U(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},s.prototype.readIntLE=function(t,e,r){t|=0,e|=0,r||U(t,e,this.length);for(var n=this[t],o=1,i=0;++i<e&&(o*=256);)n+=this[t+i]*o;return n>=(o*=128)&&(n-=Math.pow(2,8*e)),n},s.prototype.readIntBE=function(t,e,r){t|=0,e|=0,r||U(t,e,this.length);for(var n=e,o=1,i=this[t+--n];n>0&&(o*=256);)i+=this[t+--n]*o;return i>=(o*=128)&&(i-=Math.pow(2,8*e)),i},s.prototype.readInt8=function(t,e){return e||U(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},s.prototype.readInt16LE=function(t,e){e||U(t,2,this.length);var r=this[t]|this[t+1]<<8;return 32768&r?4294901760|r:r},s.prototype.readInt16BE=function(t,e){e||U(t,2,this.length);var r=this[t+1]|this[t]<<8;return 32768&r?4294901760|r:r},s.prototype.readInt32LE=function(t,e){return e||U(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},s.prototype.readInt32BE=function(t,e){return e||U(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},s.prototype.readFloatLE=function(t,e){return e||U(t,4,this.length),o.read(this,t,!0,23,4)},s.prototype.readFloatBE=function(t,e){return e||U(t,4,this.length),o.read(this,t,!1,23,4)},s.prototype.readDoubleLE=function(t,e){return e||U(t,8,this.length),o.read(this,t,!0,52,8)},s.prototype.readDoubleBE=function(t,e){return e||U(t,8,this.length),o.read(this,t,!1,52,8)},s.prototype.writeUIntLE=function(t,e,r,n){(t=+t,e|=0,r|=0,n)||B(this,t,e,r,Math.pow(2,8*r)-1,0);var o=1,i=0;for(this[e]=255&t;++i<r&&(o*=256);)this[e+i]=t/o&255;return e+r},s.prototype.writeUIntBE=function(t,e,r,n){(t=+t,e|=0,r|=0,n)||B(this,t,e,r,Math.pow(2,8*r)-1,0);var o=r-1,i=1;for(this[e+o]=255&t;--o>=0&&(i*=256);)this[e+o]=t/i&255;return e+r},s.prototype.writeUInt8=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,1,255,0),s.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},s.prototype.writeUInt16LE=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,2,65535,0),s.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):L(this,t,e,!0),e+2},s.prototype.writeUInt16BE=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,2,65535,0),s.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):L(this,t,e,!1),e+2},s.prototype.writeUInt32LE=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,4,4294967295,0),s.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):x(this,t,e,!0),e+4},s.prototype.writeUInt32BE=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,4,4294967295,0),s.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):x(this,t,e,!1),e+4},s.prototype.writeIntLE=function(t,e,r,n){if(t=+t,e|=0,!n){var o=Math.pow(2,8*r-1);B(this,t,e,r,o-1,-o)}var i=0,a=1,f=0;for(this[e]=255&t;++i<r&&(a*=256);)t<0&&0===f&&0!==this[e+i-1]&&(f=1),this[e+i]=(t/a>>0)-f&255;return e+r},s.prototype.writeIntBE=function(t,e,r,n){if(t=+t,e|=0,!n){var o=Math.pow(2,8*r-1);B(this,t,e,r,o-1,-o)}var i=r-1,a=1,f=0;for(this[e+i]=255&t;--i>=0&&(a*=256);)t<0&&0===f&&0!==this[e+i+1]&&(f=1),this[e+i]=(t/a>>0)-f&255;return e+r},s.prototype.writeInt8=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,1,127,-128),s.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},s.prototype.writeInt16LE=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,2,32767,-32768),s.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):L(this,t,e,!0),e+2},s.prototype.writeInt16BE=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,2,32767,-32768),s.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):L(this,t,e,!1),e+2},s.prototype.writeInt32LE=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,4,2147483647,-2147483648),s.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):x(this,t,e,!0),e+4},s.prototype.writeInt32BE=function(t,e,r){return t=+t,e|=0,r||B(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),s.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):x(this,t,e,!1),e+4},s.prototype.writeFloatLE=function(t,e,r){return Y(this,t,e,!0,r)},s.prototype.writeFloatBE=function(t,e,r){return Y(this,t,e,!1,r)},s.prototype.writeDoubleLE=function(t,e,r){return M(this,t,e,!0,r)},s.prototype.writeDoubleBE=function(t,e,r){return M(this,t,e,!1,r)},s.prototype.copy=function(t,e,r,n){if(r||(r=0),n||0===n||(n=this.length),e>=t.length&&(e=t.length),e||(e=0),n>0&&n<r&&(n=r),n===r)return 0;if(0===t.length||0===this.length)return 0;if(e<0)throw new RangeError("targetStart out of bounds");if(r<0||r>=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-e<n-r&&(n=t.length-e+r);var o,i=n-r;if(this===t&&r<e&&e<n)for(o=i-1;o>=0;--o)t[o+e]=this[o+r];else if(i<1e3||!s.TYPED_ARRAY_SUPPORT)for(o=0;o<i;++o)t[o+e]=this[o+r];else Uint8Array.prototype.set.call(t,this.subarray(r,r+i),e);return i},s.prototype.fill=function(t,e,r,n){if("string"==typeof t){if("string"==typeof e?(n=e,e=0,r=this.length):"string"==typeof r&&(n=r,r=this.length),1===t.length){var o=t.charCodeAt(0);o<256&&(t=o)}if(void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!s.isEncoding(n))throw new TypeError("Unknown encoding: "+n)}else"number"==typeof t&&(t&=255);if(e<0||this.length<e||this.length<r)throw new RangeError("Out of range index");if(r<=e)return this;var i;if(e>>>=0,r=void 0===r?this.length:r>>>0,t||(t=0),"number"==typeof t)for(i=e;i<r;++i)this[i]=t;else{var a=s.isBuffer(t)?t:V(new s(t,n).toString()),f=a.length;for(i=0;i<r-e;++i)this[i+e]=a[i%f]}return this};var H=/[^+\/0-9A-Za-z-_]/g;function N(t){return t<16?"0"+t.toString(16):t.toString(16)}function V(t,e){var r;e=e||1/0;for(var n=t.length,o=null,i=[],a=0;a<n;++a){if((r=t.charCodeAt(a))>55295&&r<57344){if(!o){if(r>56319){(e-=3)>-1&&i.push(239,191,189);continue}if(a+1===n){(e-=3)>-1&&i.push(239,191,189);continue}o=r;continue}if(r<56320){(e-=3)>-1&&i.push(239,191,189),o=r;continue}r=65536+(o-55296<<10|r-56320)}else o&&(e-=3)>-1&&i.push(239,191,189);if(o=null,r<128){if((e-=1)<0)break;i.push(r)}else if(r<2048){if((e-=2)<0)break;i.push(r>>6|192,63&r|128)}else if(r<65536){if((e-=3)<0)break;i.push(r>>12|224,r>>6&63|128,63&r|128)}else{if(!(r<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;i.push(r>>18|240,r>>12&63|128,r>>6&63|128,63&r|128)}}return i}function F(t){return n.toByteArray(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(H,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function k(t,e,r,n){for(var o=0;o<n&&!(o+r>=e.length||o>=t.length);++o)e[o+r]=t[o];return o}}).call(this,r(3))},function(t,e){var r;r=function(){return this}();try{r=r||new Function("return this")()}catch(t){"object"==typeof window&&(r=window)}t.exports=r},function(t,e,r){"use strict";e.byteLength=function(t){var e=u(t),r=e[0],n=e[1];return 3*(r+n)/4-n},e.toByteArray=function(t){var e,r,n=u(t),a=n[0],f=n[1],s=new i(function(t,e,r){return 3*(e+r)/4-r}(0,a,f)),d=0,h=f>0?a-4:a;for(r=0;r<h;r+=4)e=o[t.charCodeAt(r)]<<18|o[t.charCodeAt(r+1)]<<12|o[t.charCodeAt(r+2)]<<6|o[t.charCodeAt(r+3)],s[d++]=e>>16&255,s[d++]=e>>8&255,s[d++]=255&e;2===f&&(e=o[t.charCodeAt(r)]<<2|o[t.charCodeAt(r+1)]>>4,s[d++]=255&e);1===f&&(e=o[t.charCodeAt(r)]<<10|o[t.charCodeAt(r+1)]<<4|o[t.charCodeAt(r+2)]>>2,s[d++]=e>>8&255,s[d++]=255&e);return s},e.fromByteArray=function(t){for(var e,r=t.length,o=r%3,i=[],a=0,f=r-o;a<f;a+=16383)i.push(d(t,a,a+16383>f?f:a+16383));1===o?(e=t[r-1],i.push(n[e>>2]+n[e<<4&63]+"==")):2===o&&(e=(t[r-2]<<8)+t[r-1],i.push(n[e>>10]+n[e>>4&63]+n[e<<2&63]+"="));return i.join("")};for(var n=[],o=[],i="undefined"!=typeof Uint8Array?Uint8Array:Array,a="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",f=0,s=a.length;f<s;++f)n[f]=a[f],o[a.charCodeAt(f)]=f;function u(t){var e=t.length;if(e%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var r=t.indexOf("=");return-1===r&&(r=e),[r,r===e?0:4-r%4]}function d(t,e,r){for(var o,i,a=[],f=e;f<r;f+=3)o=(t[f]<<16&16711680)+(t[f+1]<<8&65280)+(255&t[f+2]),a.push(n[(i=o)>>18&63]+n[i>>12&63]+n[i>>6&63]+n[63&i]);return a.join("")}o["-".charCodeAt(0)]=62,o["_".charCodeAt(0)]=63},function(t,e){
|
|
9
|
-
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
|
10
|
-
e.read=function(t,e,r,n,o){var i,a,f=8*o-n-1,s=(1<<f)-1,u=s>>1,d=-7,h=r?o-1:0,c=r?-1:1,p=t[e+h];for(h+=c,i=p&(1<<-d)-1,p>>=-d,d+=f;d>0;i=256*i+t[e+h],h+=c,d-=8);for(a=i&(1<<-d)-1,i>>=-d,d+=n;d>0;a=256*a+t[e+h],h+=c,d-=8);if(0===i)i=1-u;else{if(i===s)return a?NaN:1/0*(p?-1:1);a+=Math.pow(2,n),i-=u}return(p?-1:1)*a*Math.pow(2,i-n)},e.write=function(t,e,r,n,o,i){var a,f,s,u=8*i-o-1,d=(1<<u)-1,h=d>>1,c=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,p=n?0:i-1,l=n?1:-1,g=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(f=isNaN(e)?1:0,a=d):(a=Math.floor(Math.log(e)/Math.LN2),e*(s=Math.pow(2,-a))<1&&(a--,s*=2),(e+=a+h>=1?c/s:c*Math.pow(2,1-h))*s>=2&&(a++,s/=2),a+h>=d?(f=0,a=d):a+h>=1?(f=(e*s-1)*Math.pow(2,o),a+=h):(f=e*Math.pow(2,h-1)*Math.pow(2,o),a=0));o>=8;t[r+p]=255&f,p+=l,f/=256,o-=8);for(a=a<<o|f,u+=o;u>0;t[r+p]=255&a,p+=l,a/=256,u-=8);t[r+p-l]|=128*g}},function(t,e){var r={}.toString;t.exports=Array.isArray||function(t){return"[object Array]"==r.call(t)}},function(t,e){t.exports=bsv}]);
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
var bsvScriptHelper=function(t){var r={};function e(n){if(r[n])return r[n].exports;var i=r[n]={i:n,l:!1,exports:{}};return t[n].call(i.exports,i,i.exports,e),i.l=!0,i.exports}return e.m=t,e.c=r,e.d=function(t,r,n){e.o(t,r)||Object.defineProperty(t,r,{enumerable:!0,get:n})},e.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},e.t=function(t,r){if(1&r&&(t=e(t)),8&r)return t;if(4&r&&"object"==typeof t&&t&&t.__esModule)return t;var n=Object.create(null);if(e.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:t}),2&r&&"string"!=typeof t)for(var i in t)e.d(n,i,function(r){return t[r]}.bind(null,i));return n},e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,"a",r),r},e.o=function(t,r){return Object.prototype.hasOwnProperty.call(t,r)},e.p="",e(e.s=0)}([function(t,r,e){"use strict";if("undefined"==typeof bsv)throw new Error("CustomScriptHelper requires BSV library. Load bsv.min.js first.");const n=e(1);"undefined"!=typeof window&&(window.bsvScriptHelper={CustomScriptHelper:n,createSignature:n.createSignature,verifySignature:n.verifySignature,createMultisigSignature:n.createMultisigSignature,version:bsv.version||"unknown"},"undefined"!=typeof bsv&&(bsv.CustomScriptHelper=n),console.log("CustomScriptHelper standalone module loaded")),t.exports={CustomScriptHelper:n,createSignature:n.createSignature,verifySignature:n.verifySignature,createMultisigSignature:n.createMultisigSignature,version:bsv.version||"unknown"}},function(t,r,e){(function(r){const n=e(7);class i{static createSignature(t,e,i,o,u,f=null){f=f||n.crypto.Signature.SIGHASH_ALL|n.crypto.Signature.SIGHASH_FORKID;const a=n.Transaction.sighash.sign(t,e,f,i,o,new n.crypto.BN(u));return r.concat([a.toDER(),r.from([f])])}static createMultisigScript(t,r){let e=(new n.Script).add(n.Opcode["OP_"+t]);for(const t of r)e=e.add(t.toBuffer());return e.add(n.Opcode["OP_"+r.length]).add(n.Opcode.OP_CHECKMULTISIG)}static createMultisigUnlocking(t){let r=(new n.Script).add(n.Opcode.OP_0);for(const e of t)r=r.add(e);return r}static createTimelockScript(t,e){const i=r.from(t.toString(16).padStart(8,"0"),"hex").reverse();return(new n.Script).add(i).add(n.Opcode.OP_CHECKLOCKTIMEVERIFY).add(n.Opcode.OP_DROP).add(e.toBuffer())}static createConditionalScript(t,r=null){let e=(new n.Script).add(n.Opcode.OP_IF).add(t.toBuffer());return r&&(e=e.add(n.Opcode.OP_ELSE).add(r.toBuffer())),e.add(n.Opcode.OP_ENDIF)}static createP2PKHScript(t){return(new n.Script).add(n.Opcode.OP_DUP).add(n.Opcode.OP_HASH160).add(t.toAddress().hashBuffer).add(n.Opcode.OP_EQUALVERIFY).add(n.Opcode.OP_CHECKSIG)}static createP2PKHUnlocking(t,r){return(new n.Script).add(t).add(r.toBuffer())}static getPreimage(t,r,e,i,o=null){return o=o||n.crypto.Signature.SIGHASH_ALL|n.crypto.Signature.SIGHASH_FORKID,n.Transaction.sighash.sighash(t,o,r,e,new n.crypto.BN(i))}static createDataScript(t){return"string"==typeof t&&(t=r.from(t,"utf8")),(new n.Script).add(t)}static createOpReturnScript(t){return"string"==typeof t&&(t=r.from(t,"utf8")),(new n.Script).add(n.Opcode.OP_FALSE).add(n.Opcode.OP_RETURN).add(t)}static validateTransaction(t){try{return t.verify()}catch(t){return console.error("Transaction validation error:",t.message),!1}}static validateScript(t,r,e,i){try{return(new n.Script.Interpreter).verify(t,r,e,i,n.Script.Interpreter.SCRIPT_VERIFY_P2SH|n.Script.Interpreter.SCRIPT_VERIFY_STRICTENC|n.Script.Interpreter.SCRIPT_ENABLE_SIGHASH_FORKID|n.Script.Interpreter.SCRIPT_ENABLE_MAGNETIC_OPCODES|n.Script.Interpreter.SCRIPT_ENABLE_MONOLITH_OPCODES)}catch(t){return console.error("Script validation error:",t.message),!1}}static createLowFeeTransaction(t,r,e=10){let i=(new n.Transaction).feePerKb(e);for(const r of t)i=i.from(r);for(const t of r)i=i.to(t.address,t.satoshis);return i}}i.SIGHASH_ALL=n.crypto.Signature.SIGHASH_ALL|n.crypto.Signature.SIGHASH_FORKID,i.SIGHASH_NONE=n.crypto.Signature.SIGHASH_NONE|n.crypto.Signature.SIGHASH_FORKID,i.SIGHASH_SINGLE=n.crypto.Signature.SIGHASH_SINGLE|n.crypto.Signature.SIGHASH_FORKID,t.exports=i}).call(this,e(2).Buffer)},function(t,r,e){"use strict";(function(t){
|
|
2
|
-
/*!
|
|
3
|
-
* The buffer module from node.js, for the browser.
|
|
4
|
-
*
|
|
5
|
-
* @author Feross Aboukhadijeh <http://feross.org>
|
|
6
|
-
* @license MIT
|
|
7
|
-
*/
|
|
8
|
-
var n=e(4),i=e(5),o=e(6);function u(){return a.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function f(t,r){if(u()<r)throw new RangeError("Invalid typed array length");return a.TYPED_ARRAY_SUPPORT?(t=new Uint8Array(r)).__proto__=a.prototype:(null===t&&(t=new a(r)),t.length=r),t}function a(t,r,e){if(!(a.TYPED_ARRAY_SUPPORT||this instanceof a))return new a(t,r,e);if("number"==typeof t){if("string"==typeof r)throw new Error("If encoding is specified then the first argument must be a string");return c(this,t)}return s(this,t,r,e)}function s(t,r,e,n){if("number"==typeof r)throw new TypeError('"value" argument must not be a number');return"undefined"!=typeof ArrayBuffer&&r instanceof ArrayBuffer?function(t,r,e,n){if(r.byteLength,e<0||r.byteLength<e)throw new RangeError("'offset' is out of bounds");if(r.byteLength<e+(n||0))throw new RangeError("'length' is out of bounds");r=void 0===e&&void 0===n?new Uint8Array(r):void 0===n?new Uint8Array(r,e):new Uint8Array(r,e,n);a.TYPED_ARRAY_SUPPORT?(t=r).__proto__=a.prototype:t=p(t,r);return t}(t,r,e,n):"string"==typeof r?function(t,r,e){"string"==typeof e&&""!==e||(e="utf8");if(!a.isEncoding(e))throw new TypeError('"encoding" must be a valid string encoding');var n=0|g(r,e),i=(t=f(t,n)).write(r,e);i!==n&&(t=t.slice(0,i));return t}(t,r,e):function(t,r){if(a.isBuffer(r)){var e=0|l(r.length);return 0===(t=f(t,e)).length||r.copy(t,0,0,e),t}if(r){if("undefined"!=typeof ArrayBuffer&&r.buffer instanceof ArrayBuffer||"length"in r)return"number"!=typeof r.length||(n=r.length)!=n?f(t,0):p(t,r);if("Buffer"===r.type&&o(r.data))return p(t,r.data)}var n;throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}(t,r)}function h(t){if("number"!=typeof t)throw new TypeError('"size" argument must be a number');if(t<0)throw new RangeError('"size" argument must not be negative')}function c(t,r){if(h(r),t=f(t,r<0?0:0|l(r)),!a.TYPED_ARRAY_SUPPORT)for(var e=0;e<r;++e)t[e]=0;return t}function p(t,r){var e=r.length<0?0:0|l(r.length);t=f(t,e);for(var n=0;n<e;n+=1)t[n]=255&r[n];return t}function l(t){if(t>=u())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+u().toString(16)+" bytes");return 0|t}function g(t,r){if(a.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var e=t.length;if(0===e)return 0;for(var n=!1;;)switch(r){case"ascii":case"latin1":case"binary":return e;case"utf8":case"utf-8":case void 0:return F(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*e;case"hex":return e>>>1;case"base64":return k(t).length;default:if(n)return F(t).length;r=(""+r).toLowerCase(),n=!0}}function d(t,r,e){var n=!1;if((void 0===r||r<0)&&(r=0),r>this.length)return"";if((void 0===e||e>this.length)&&(e=this.length),e<=0)return"";if((e>>>=0)<=(r>>>=0))return"";for(t||(t="utf8");;)switch(t){case"hex":return T(this,r,e);case"utf8":case"utf-8":return m(this,r,e);case"ascii":return I(this,r,e);case"latin1":case"binary":return O(this,r,e);case"base64":return P(this,r,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return B(this,r,e);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0}}function y(t,r,e){var n=t[r];t[r]=t[e],t[e]=n}function w(t,r,e,n,i){if(0===t.length)return-1;if("string"==typeof e?(n=e,e=0):e>2147483647?e=2147483647:e<-2147483648&&(e=-2147483648),e=+e,isNaN(e)&&(e=i?0:t.length-1),e<0&&(e=t.length+e),e>=t.length){if(i)return-1;e=t.length-1}else if(e<0){if(!i)return-1;e=0}if("string"==typeof r&&(r=a.from(r,n)),a.isBuffer(r))return 0===r.length?-1:S(t,r,e,n,i);if("number"==typeof r)return r&=255,a.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,r,e):Uint8Array.prototype.lastIndexOf.call(t,r,e):S(t,[r],e,n,i);throw new TypeError("val must be string, number or Buffer")}function S(t,r,e,n,i){var o,u=1,f=t.length,a=r.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||r.length<2)return-1;u=2,f/=2,a/=2,e/=2}function s(t,r){return 1===u?t[r]:t.readUInt16BE(r*u)}if(i){var h=-1;for(o=e;o<f;o++)if(s(t,o)===s(r,-1===h?0:o-h)){if(-1===h&&(h=o),o-h+1===a)return h*u}else-1!==h&&(o-=o-h),h=-1}else for(e+a>f&&(e=f-a),o=e;o>=0;o--){for(var c=!0,p=0;p<a;p++)if(s(t,o+p)!==s(r,p)){c=!1;break}if(c)return o}return-1}function v(t,r,e,n){e=Number(e)||0;var i=t.length-e;n?(n=Number(n))>i&&(n=i):n=i;var o=r.length;if(o%2!=0)throw new TypeError("Invalid hex string");n>o/2&&(n=o/2);for(var u=0;u<n;++u){var f=parseInt(r.substr(2*u,2),16);if(isNaN(f))return u;t[e+u]=f}return u}function E(t,r,e,n){return G(F(r,t.length-e),t,e,n)}function _(t,r,e,n){return G(function(t){for(var r=[],e=0;e<t.length;++e)r.push(255&t.charCodeAt(e));return r}(r),t,e,n)}function A(t,r,e,n){return _(t,r,e,n)}function b(t,r,e,n){return G(k(r),t,e,n)}function R(t,r,e,n){return G(function(t,r){for(var e,n,i,o=[],u=0;u<t.length&&!((r-=2)<0);++u)e=t.charCodeAt(u),n=e>>8,i=e%256,o.push(i),o.push(n);return o}(r,t.length-e),t,e,n)}function P(t,r,e){return 0===r&&e===t.length?n.fromByteArray(t):n.fromByteArray(t.slice(r,e))}function m(t,r,e){e=Math.min(t.length,e);for(var n=[],i=r;i<e;){var o,u,f,a,s=t[i],h=null,c=s>239?4:s>223?3:s>191?2:1;if(i+c<=e)switch(c){case 1:s<128&&(h=s);break;case 2:128==(192&(o=t[i+1]))&&(a=(31&s)<<6|63&o)>127&&(h=a);break;case 3:o=t[i+1],u=t[i+2],128==(192&o)&&128==(192&u)&&(a=(15&s)<<12|(63&o)<<6|63&u)>2047&&(a<55296||a>57343)&&(h=a);break;case 4:o=t[i+1],u=t[i+2],f=t[i+3],128==(192&o)&&128==(192&u)&&128==(192&f)&&(a=(15&s)<<18|(63&o)<<12|(63&u)<<6|63&f)>65535&&a<1114112&&(h=a)}null===h?(h=65533,c=1):h>65535&&(h-=65536,n.push(h>>>10&1023|55296),h=56320|1023&h),n.push(h),i+=c}return function(t){var r=t.length;if(r<=4096)return String.fromCharCode.apply(String,t);var e="",n=0;for(;n<r;)e+=String.fromCharCode.apply(String,t.slice(n,n+=4096));return e}(n)}r.Buffer=a,r.SlowBuffer=function(t){+t!=t&&(t=0);return a.alloc(+t)},r.INSPECT_MAX_BYTES=50,a.TYPED_ARRAY_SUPPORT=void 0!==t.TYPED_ARRAY_SUPPORT?t.TYPED_ARRAY_SUPPORT:function(){try{var t=new Uint8Array(1);return t.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===t.foo()&&"function"==typeof t.subarray&&0===t.subarray(1,1).byteLength}catch(t){return!1}}(),r.kMaxLength=u(),a.poolSize=8192,a._augment=function(t){return t.__proto__=a.prototype,t},a.from=function(t,r,e){return s(null,t,r,e)},a.TYPED_ARRAY_SUPPORT&&(a.prototype.__proto__=Uint8Array.prototype,a.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&a[Symbol.species]===a&&Object.defineProperty(a,Symbol.species,{value:null,configurable:!0})),a.alloc=function(t,r,e){return function(t,r,e,n){return h(r),r<=0?f(t,r):void 0!==e?"string"==typeof n?f(t,r).fill(e,n):f(t,r).fill(e):f(t,r)}(null,t,r,e)},a.allocUnsafe=function(t){return c(null,t)},a.allocUnsafeSlow=function(t){return c(null,t)},a.isBuffer=function(t){return!(null==t||!t._isBuffer)},a.compare=function(t,r){if(!a.isBuffer(t)||!a.isBuffer(r))throw new TypeError("Arguments must be Buffers");if(t===r)return 0;for(var e=t.length,n=r.length,i=0,o=Math.min(e,n);i<o;++i)if(t[i]!==r[i]){e=t[i],n=r[i];break}return e<n?-1:n<e?1:0},a.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}},a.concat=function(t,r){if(!o(t))throw new TypeError('"list" argument must be an Array of Buffers');if(0===t.length)return a.alloc(0);var e;if(void 0===r)for(r=0,e=0;e<t.length;++e)r+=t[e].length;var n=a.allocUnsafe(r),i=0;for(e=0;e<t.length;++e){var u=t[e];if(!a.isBuffer(u))throw new TypeError('"list" argument must be an Array of Buffers');u.copy(n,i),i+=u.length}return n},a.byteLength=g,a.prototype._isBuffer=!0,a.prototype.swap16=function(){var t=this.length;if(t%2!=0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var r=0;r<t;r+=2)y(this,r,r+1);return this},a.prototype.swap32=function(){var t=this.length;if(t%4!=0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var r=0;r<t;r+=4)y(this,r,r+3),y(this,r+1,r+2);return this},a.prototype.swap64=function(){var t=this.length;if(t%8!=0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var r=0;r<t;r+=8)y(this,r,r+7),y(this,r+1,r+6),y(this,r+2,r+5),y(this,r+3,r+4);return this},a.prototype.toString=function(){var t=0|this.length;return 0===t?"":0===arguments.length?m(this,0,t):d.apply(this,arguments)},a.prototype.equals=function(t){if(!a.isBuffer(t))throw new TypeError("Argument must be a Buffer");return this===t||0===a.compare(this,t)},a.prototype.inspect=function(){var t="",e=r.INSPECT_MAX_BYTES;return this.length>0&&(t=this.toString("hex",0,e).match(/.{2}/g).join(" "),this.length>e&&(t+=" ... ")),"<Buffer "+t+">"},a.prototype.compare=function(t,r,e,n,i){if(!a.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===r&&(r=0),void 0===e&&(e=t?t.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),r<0||e>t.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&r>=e)return 0;if(n>=i)return-1;if(r>=e)return 1;if(this===t)return 0;for(var o=(i>>>=0)-(n>>>=0),u=(e>>>=0)-(r>>>=0),f=Math.min(o,u),s=this.slice(n,i),h=t.slice(r,e),c=0;c<f;++c)if(s[c]!==h[c]){o=s[c],u=h[c];break}return o<u?-1:u<o?1:0},a.prototype.includes=function(t,r,e){return-1!==this.indexOf(t,r,e)},a.prototype.indexOf=function(t,r,e){return w(this,t,r,e,!0)},a.prototype.lastIndexOf=function(t,r,e){return w(this,t,r,e,!1)},a.prototype.write=function(t,r,e,n){if(void 0===r)n="utf8",e=this.length,r=0;else if(void 0===e&&"string"==typeof r)n=r,e=this.length,r=0;else{if(!isFinite(r))throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");r|=0,isFinite(e)?(e|=0,void 0===n&&(n="utf8")):(n=e,e=void 0)}var i=this.length-r;if((void 0===e||e>i)&&(e=i),t.length>0&&(e<0||r<0)||r>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var o=!1;;)switch(n){case"hex":return v(this,t,r,e);case"utf8":case"utf-8":return E(this,t,r,e);case"ascii":return _(this,t,r,e);case"latin1":case"binary":return A(this,t,r,e);case"base64":return b(this,t,r,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return R(this,t,r,e);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0}},a.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function I(t,r,e){var n="";e=Math.min(t.length,e);for(var i=r;i<e;++i)n+=String.fromCharCode(127&t[i]);return n}function O(t,r,e){var n="";e=Math.min(t.length,e);for(var i=r;i<e;++i)n+=String.fromCharCode(t[i]);return n}function T(t,r,e){var n=t.length;(!r||r<0)&&(r=0),(!e||e<0||e>n)&&(e=n);for(var i="",o=r;o<e;++o)i+=N(t[o]);return i}function B(t,r,e){for(var n=t.slice(r,e),i="",o=0;o<n.length;o+=2)i+=String.fromCharCode(n[o]+256*n[o+1]);return i}function U(t,r,e){if(t%1!=0||t<0)throw new RangeError("offset is not uint");if(t+r>e)throw new RangeError("Trying to access beyond buffer length")}function C(t,r,e,n,i,o){if(!a.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(r>i||r<o)throw new RangeError('"value" argument is out of bounds');if(e+n>t.length)throw new RangeError("Index out of range")}function L(t,r,e,n){r<0&&(r=65535+r+1);for(var i=0,o=Math.min(t.length-e,2);i<o;++i)t[e+i]=(r&255<<8*(n?i:1-i))>>>8*(n?i:1-i)}function Y(t,r,e,n){r<0&&(r=4294967295+r+1);for(var i=0,o=Math.min(t.length-e,4);i<o;++i)t[e+i]=r>>>8*(n?i:3-i)&255}function M(t,r,e,n,i,o){if(e+n>t.length)throw new RangeError("Index out of range");if(e<0)throw new RangeError("Index out of range")}function H(t,r,e,n,o){return o||M(t,0,e,4),i.write(t,r,e,n,23,4),e+4}function D(t,r,e,n,o){return o||M(t,0,e,8),i.write(t,r,e,n,52,8),e+8}a.prototype.slice=function(t,r){var e,n=this.length;if((t=~~t)<0?(t+=n)<0&&(t=0):t>n&&(t=n),(r=void 0===r?n:~~r)<0?(r+=n)<0&&(r=0):r>n&&(r=n),r<t&&(r=t),a.TYPED_ARRAY_SUPPORT)(e=this.subarray(t,r)).__proto__=a.prototype;else{var i=r-t;e=new a(i,void 0);for(var o=0;o<i;++o)e[o]=this[o+t]}return e},a.prototype.readUIntLE=function(t,r,e){t|=0,r|=0,e||U(t,r,this.length);for(var n=this[t],i=1,o=0;++o<r&&(i*=256);)n+=this[t+o]*i;return n},a.prototype.readUIntBE=function(t,r,e){t|=0,r|=0,e||U(t,r,this.length);for(var n=this[t+--r],i=1;r>0&&(i*=256);)n+=this[t+--r]*i;return n},a.prototype.readUInt8=function(t,r){return r||U(t,1,this.length),this[t]},a.prototype.readUInt16LE=function(t,r){return r||U(t,2,this.length),this[t]|this[t+1]<<8},a.prototype.readUInt16BE=function(t,r){return r||U(t,2,this.length),this[t]<<8|this[t+1]},a.prototype.readUInt32LE=function(t,r){return r||U(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},a.prototype.readUInt32BE=function(t,r){return r||U(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},a.prototype.readIntLE=function(t,r,e){t|=0,r|=0,e||U(t,r,this.length);for(var n=this[t],i=1,o=0;++o<r&&(i*=256);)n+=this[t+o]*i;return n>=(i*=128)&&(n-=Math.pow(2,8*r)),n},a.prototype.readIntBE=function(t,r,e){t|=0,r|=0,e||U(t,r,this.length);for(var n=r,i=1,o=this[t+--n];n>0&&(i*=256);)o+=this[t+--n]*i;return o>=(i*=128)&&(o-=Math.pow(2,8*r)),o},a.prototype.readInt8=function(t,r){return r||U(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},a.prototype.readInt16LE=function(t,r){r||U(t,2,this.length);var e=this[t]|this[t+1]<<8;return 32768&e?4294901760|e:e},a.prototype.readInt16BE=function(t,r){r||U(t,2,this.length);var e=this[t+1]|this[t]<<8;return 32768&e?4294901760|e:e},a.prototype.readInt32LE=function(t,r){return r||U(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},a.prototype.readInt32BE=function(t,r){return r||U(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},a.prototype.readFloatLE=function(t,r){return r||U(t,4,this.length),i.read(this,t,!0,23,4)},a.prototype.readFloatBE=function(t,r){return r||U(t,4,this.length),i.read(this,t,!1,23,4)},a.prototype.readDoubleLE=function(t,r){return r||U(t,8,this.length),i.read(this,t,!0,52,8)},a.prototype.readDoubleBE=function(t,r){return r||U(t,8,this.length),i.read(this,t,!1,52,8)},a.prototype.writeUIntLE=function(t,r,e,n){(t=+t,r|=0,e|=0,n)||C(this,t,r,e,Math.pow(2,8*e)-1,0);var i=1,o=0;for(this[r]=255&t;++o<e&&(i*=256);)this[r+o]=t/i&255;return r+e},a.prototype.writeUIntBE=function(t,r,e,n){(t=+t,r|=0,e|=0,n)||C(this,t,r,e,Math.pow(2,8*e)-1,0);var i=e-1,o=1;for(this[r+i]=255&t;--i>=0&&(o*=256);)this[r+i]=t/o&255;return r+e},a.prototype.writeUInt8=function(t,r,e){return t=+t,r|=0,e||C(this,t,r,1,255,0),a.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[r]=255&t,r+1},a.prototype.writeUInt16LE=function(t,r,e){return t=+t,r|=0,e||C(this,t,r,2,65535,0),a.TYPED_ARRAY_SUPPORT?(this[r]=255&t,this[r+1]=t>>>8):L(this,t,r,!0),r+2},a.prototype.writeUInt16BE=function(t,r,e){return t=+t,r|=0,e||C(this,t,r,2,65535,0),a.TYPED_ARRAY_SUPPORT?(this[r]=t>>>8,this[r+1]=255&t):L(this,t,r,!1),r+2},a.prototype.writeUInt32LE=function(t,r,e){return t=+t,r|=0,e||C(this,t,r,4,4294967295,0),a.TYPED_ARRAY_SUPPORT?(this[r+3]=t>>>24,this[r+2]=t>>>16,this[r+1]=t>>>8,this[r]=255&t):Y(this,t,r,!0),r+4},a.prototype.writeUInt32BE=function(t,r,e){return t=+t,r|=0,e||C(this,t,r,4,4294967295,0),a.TYPED_ARRAY_SUPPORT?(this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=255&t):Y(this,t,r,!1),r+4},a.prototype.writeIntLE=function(t,r,e,n){if(t=+t,r|=0,!n){var i=Math.pow(2,8*e-1);C(this,t,r,e,i-1,-i)}var o=0,u=1,f=0;for(this[r]=255&t;++o<e&&(u*=256);)t<0&&0===f&&0!==this[r+o-1]&&(f=1),this[r+o]=(t/u>>0)-f&255;return r+e},a.prototype.writeIntBE=function(t,r,e,n){if(t=+t,r|=0,!n){var i=Math.pow(2,8*e-1);C(this,t,r,e,i-1,-i)}var o=e-1,u=1,f=0;for(this[r+o]=255&t;--o>=0&&(u*=256);)t<0&&0===f&&0!==this[r+o+1]&&(f=1),this[r+o]=(t/u>>0)-f&255;return r+e},a.prototype.writeInt8=function(t,r,e){return t=+t,r|=0,e||C(this,t,r,1,127,-128),a.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[r]=255&t,r+1},a.prototype.writeInt16LE=function(t,r,e){return t=+t,r|=0,e||C(this,t,r,2,32767,-32768),a.TYPED_ARRAY_SUPPORT?(this[r]=255&t,this[r+1]=t>>>8):L(this,t,r,!0),r+2},a.prototype.writeInt16BE=function(t,r,e){return t=+t,r|=0,e||C(this,t,r,2,32767,-32768),a.TYPED_ARRAY_SUPPORT?(this[r]=t>>>8,this[r+1]=255&t):L(this,t,r,!1),r+2},a.prototype.writeInt32LE=function(t,r,e){return t=+t,r|=0,e||C(this,t,r,4,2147483647,-2147483648),a.TYPED_ARRAY_SUPPORT?(this[r]=255&t,this[r+1]=t>>>8,this[r+2]=t>>>16,this[r+3]=t>>>24):Y(this,t,r,!0),r+4},a.prototype.writeInt32BE=function(t,r,e){return t=+t,r|=0,e||C(this,t,r,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),a.TYPED_ARRAY_SUPPORT?(this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=255&t):Y(this,t,r,!1),r+4},a.prototype.writeFloatLE=function(t,r,e){return H(this,t,r,!0,e)},a.prototype.writeFloatBE=function(t,r,e){return H(this,t,r,!1,e)},a.prototype.writeDoubleLE=function(t,r,e){return D(this,t,r,!0,e)},a.prototype.writeDoubleBE=function(t,r,e){return D(this,t,r,!1,e)},a.prototype.copy=function(t,r,e,n){if(e||(e=0),n||0===n||(n=this.length),r>=t.length&&(r=t.length),r||(r=0),n>0&&n<e&&(n=e),n===e)return 0;if(0===t.length||0===this.length)return 0;if(r<0)throw new RangeError("targetStart out of bounds");if(e<0||e>=this.length)throw new RangeError("sourceStart out of bounds");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-r<n-e&&(n=t.length-r+e);var i,o=n-e;if(this===t&&e<r&&r<n)for(i=o-1;i>=0;--i)t[i+r]=this[i+e];else if(o<1e3||!a.TYPED_ARRAY_SUPPORT)for(i=0;i<o;++i)t[i+r]=this[i+e];else Uint8Array.prototype.set.call(t,this.subarray(e,e+o),r);return o},a.prototype.fill=function(t,r,e,n){if("string"==typeof t){if("string"==typeof r?(n=r,r=0,e=this.length):"string"==typeof e&&(n=e,e=this.length),1===t.length){var i=t.charCodeAt(0);i<256&&(t=i)}if(void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!a.isEncoding(n))throw new TypeError("Unknown encoding: "+n)}else"number"==typeof t&&(t&=255);if(r<0||this.length<r||this.length<e)throw new RangeError("Out of range index");if(e<=r)return this;var o;if(r>>>=0,e=void 0===e?this.length:e>>>0,t||(t=0),"number"==typeof t)for(o=r;o<e;++o)this[o]=t;else{var u=a.isBuffer(t)?t:F(new a(t,n).toString()),f=u.length;for(o=0;o<e-r;++o)this[o+r]=u[o%f]}return this};var x=/[^+\/0-9A-Za-z-_]/g;function N(t){return t<16?"0"+t.toString(16):t.toString(16)}function F(t,r){var e;r=r||1/0;for(var n=t.length,i=null,o=[],u=0;u<n;++u){if((e=t.charCodeAt(u))>55295&&e<57344){if(!i){if(e>56319){(r-=3)>-1&&o.push(239,191,189);continue}if(u+1===n){(r-=3)>-1&&o.push(239,191,189);continue}i=e;continue}if(e<56320){(r-=3)>-1&&o.push(239,191,189),i=e;continue}e=65536+(i-55296<<10|e-56320)}else i&&(r-=3)>-1&&o.push(239,191,189);if(i=null,e<128){if((r-=1)<0)break;o.push(e)}else if(e<2048){if((r-=2)<0)break;o.push(e>>6|192,63&e|128)}else if(e<65536){if((r-=3)<0)break;o.push(e>>12|224,e>>6&63|128,63&e|128)}else{if(!(e<1114112))throw new Error("Invalid code point");if((r-=4)<0)break;o.push(e>>18|240,e>>12&63|128,e>>6&63|128,63&e|128)}}return o}function k(t){return n.toByteArray(function(t){if((t=function(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}(t).replace(x,"")).length<2)return"";for(;t.length%4!=0;)t+="=";return t}(t))}function G(t,r,e,n){for(var i=0;i<n&&!(i+e>=r.length||i>=t.length);++i)r[i+e]=t[i];return i}}).call(this,e(3))},function(t,r){var e;e=function(){return this}();try{e=e||new Function("return this")()}catch(t){"object"==typeof window&&(e=window)}t.exports=e},function(t,r,e){"use strict";r.byteLength=function(t){var r=s(t),e=r[0],n=r[1];return 3*(e+n)/4-n},r.toByteArray=function(t){var r,e,n=s(t),u=n[0],f=n[1],a=new o(function(t,r,e){return 3*(r+e)/4-e}(0,u,f)),h=0,c=f>0?u-4:u;for(e=0;e<c;e+=4)r=i[t.charCodeAt(e)]<<18|i[t.charCodeAt(e+1)]<<12|i[t.charCodeAt(e+2)]<<6|i[t.charCodeAt(e+3)],a[h++]=r>>16&255,a[h++]=r>>8&255,a[h++]=255&r;2===f&&(r=i[t.charCodeAt(e)]<<2|i[t.charCodeAt(e+1)]>>4,a[h++]=255&r);1===f&&(r=i[t.charCodeAt(e)]<<10|i[t.charCodeAt(e+1)]<<4|i[t.charCodeAt(e+2)]>>2,a[h++]=r>>8&255,a[h++]=255&r);return a},r.fromByteArray=function(t){for(var r,e=t.length,i=e%3,o=[],u=0,f=e-i;u<f;u+=16383)o.push(h(t,u,u+16383>f?f:u+16383));1===i?(r=t[e-1],o.push(n[r>>2]+n[r<<4&63]+"==")):2===i&&(r=(t[e-2]<<8)+t[e-1],o.push(n[r>>10]+n[r>>4&63]+n[r<<2&63]+"="));return o.join("")};for(var n=[],i=[],o="undefined"!=typeof Uint8Array?Uint8Array:Array,u="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",f=0,a=u.length;f<a;++f)n[f]=u[f],i[u.charCodeAt(f)]=f;function s(t){var r=t.length;if(r%4>0)throw new Error("Invalid string. Length must be a multiple of 4");var e=t.indexOf("=");return-1===e&&(e=r),[e,e===r?0:4-e%4]}function h(t,r,e){for(var i,o,u=[],f=r;f<e;f+=3)i=(t[f]<<16&16711680)+(t[f+1]<<8&65280)+(255&t[f+2]),u.push(n[(o=i)>>18&63]+n[o>>12&63]+n[o>>6&63]+n[63&o]);return u.join("")}i["-".charCodeAt(0)]=62,i["_".charCodeAt(0)]=63},function(t,r){
|
|
9
|
-
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
|
10
|
-
r.read=function(t,r,e,n,i){var o,u,f=8*i-n-1,a=(1<<f)-1,s=a>>1,h=-7,c=e?i-1:0,p=e?-1:1,l=t[r+c];for(c+=p,o=l&(1<<-h)-1,l>>=-h,h+=f;h>0;o=256*o+t[r+c],c+=p,h-=8);for(u=o&(1<<-h)-1,o>>=-h,h+=n;h>0;u=256*u+t[r+c],c+=p,h-=8);if(0===o)o=1-s;else{if(o===a)return u?NaN:1/0*(l?-1:1);u+=Math.pow(2,n),o-=s}return(l?-1:1)*u*Math.pow(2,o-n)},r.write=function(t,r,e,n,i,o){var u,f,a,s=8*o-i-1,h=(1<<s)-1,c=h>>1,p=23===i?Math.pow(2,-24)-Math.pow(2,-77):0,l=n?0:o-1,g=n?1:-1,d=r<0||0===r&&1/r<0?1:0;for(r=Math.abs(r),isNaN(r)||r===1/0?(f=isNaN(r)?1:0,u=h):(u=Math.floor(Math.log(r)/Math.LN2),r*(a=Math.pow(2,-u))<1&&(u--,a*=2),(r+=u+c>=1?p/a:p*Math.pow(2,1-c))*a>=2&&(u++,a/=2),u+c>=h?(f=0,u=h):u+c>=1?(f=(r*a-1)*Math.pow(2,i),u+=c):(f=r*Math.pow(2,c-1)*Math.pow(2,i),u=0));i>=8;t[e+l]=255&f,l+=g,f/=256,i-=8);for(u=u<<i|f,s+=i;s>0;t[e+l]=255&u,l+=g,u/=256,s-=8);t[e+l-g]|=128*d}},function(t,r){var e={}.toString;t.exports=Array.isArray||function(t){return"[object Array]"==e.call(t)}},function(t,r){t.exports=bsv}]);
|