@smartledger/bsv 3.2.2 → 3.3.3
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 +279 -4
- package/README.md +266 -71
- package/bsv-covenant.min.js +26 -3
- package/bsv-gdaf.min.js +39 -0
- package/bsv-ltp.min.js +39 -0
- package/bsv-script-helper.min.js +2 -2
- package/bsv-security.min.js +3 -24
- package/bsv-shamir.min.js +12 -0
- package/bsv-smartcontract.min.js +10 -8
- package/bsv.bundle.js +7 -7
- 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 +17 -0
- package/build/webpack.ltp.config.js +17 -0
- 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 -265
- package/covenant-entry.js +1 -44
- package/docs/DOCUMENTATION_REVIEW_REPORT.md +295 -0
- package/docs/MODULE_REFERENCE_COMPLETE.md +330 -0
- package/docs/README.md +107 -79
- 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/gdaf-entry.js +2 -0
- package/index.js +291 -0
- package/lib/crypto/shamir.js +360 -0
- package/lib/gdaf/attestation-signer.js +461 -0
- package/lib/gdaf/attestation-verifier.js +600 -0
- package/lib/gdaf/did-resolver.js +382 -0
- package/lib/gdaf/index.js +471 -0
- package/lib/gdaf/schema-validator.js +682 -0
- package/lib/gdaf/smartledger-anchor.js +486 -0
- package/lib/gdaf/zk-prover.js +507 -0
- package/lib/ltp/anchor.js +438 -0
- package/lib/ltp/claim.js +1026 -0
- package/lib/ltp/index.js +470 -0
- package/lib/ltp/obligation.js +945 -0
- package/lib/ltp/proof.js +828 -0
- package/lib/ltp/registry.js +702 -0
- package/lib/ltp/right.js +765 -0
- package/lib/smart_contract/API_REFERENCE.md +1 -1
- package/lib/smart_contract/EXAMPLES.md +2 -2
- package/lib/smart_contract/QUICK_START.md +2 -2
- package/lib/smart_contract/README.md +1 -1
- package/ltp-entry.js +2 -0
- package/package.json +48 -6
- package/script-helper-entry.js +1 -49
- package/security-entry.js +1 -70
- package/shamir-entry.js +1 -0
- package/smartcontract-entry.js +1 -133
- 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_shamir.js +221 -0
- package/tests/test_smartverify_der.js +110 -0
- package/tests/test_standalone_shamir.html +83 -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 -37
- package/build/bsv.bundle.js +0 -39
- package/build/bsv.min.js +0 -37
- 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
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
## Quick Start
|
|
20
20
|
|
|
21
21
|
```javascript
|
|
22
|
-
const SmartContract = require('bsv
|
|
22
|
+
const SmartContract = require('smartledger-bsv').SmartContract
|
|
23
23
|
|
|
24
24
|
// 🚀 Write covenant logic in JavaScript
|
|
25
25
|
const builder = SmartContract.createCovenantBuilder()
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
### Example 1: Simple Value Check
|
|
18
18
|
|
|
19
19
|
```javascript
|
|
20
|
-
const SmartContract = require('bsv
|
|
20
|
+
const SmartContract = require('smartledger-bsv').SmartContract
|
|
21
21
|
|
|
22
22
|
// Ensure transaction maintains minimum value
|
|
23
23
|
function createValueGuard(minimumSatoshis) {
|
|
@@ -419,7 +419,7 @@ function createSubscriptionCovenant(serviceProvider, subscriptionFee, renewalPer
|
|
|
419
419
|
### Example 12: Complete Covenant Deployment
|
|
420
420
|
|
|
421
421
|
```javascript
|
|
422
|
-
const bsv = require('bsv
|
|
422
|
+
const bsv = require('smartledger-bsv')
|
|
423
423
|
const SmartContract = bsv.SmartContract
|
|
424
424
|
|
|
425
425
|
async function deployValueLockCovenant(privateKey, minimumValue, utxo) {
|
|
@@ -9,7 +9,7 @@ The JavaScript-to-Bitcoin Script framework allows you to write complex covenant
|
|
|
9
9
|
## 🚀 30-Second Quick Start
|
|
10
10
|
|
|
11
11
|
```javascript
|
|
12
|
-
const SmartContract = require('bsv
|
|
12
|
+
const SmartContract = require('smartledger-bsv').SmartContract
|
|
13
13
|
|
|
14
14
|
// Write covenant logic in JavaScript
|
|
15
15
|
const builder = SmartContract.createCovenantBuilder()
|
|
@@ -415,7 +415,7 @@ Object.keys(opcodes)
|
|
|
415
415
|
### With BSV Library
|
|
416
416
|
|
|
417
417
|
```javascript
|
|
418
|
-
const bsv = require('bsv
|
|
418
|
+
const bsv = require('smartledger-bsv')
|
|
419
419
|
const SmartContract = bsv.SmartContract
|
|
420
420
|
|
|
421
421
|
// Create covenant from private key
|
|
@@ -7,7 +7,7 @@ The SmartContract module provides enterprise-grade covenant functionality for Bi
|
|
|
7
7
|
## Installation & Usage
|
|
8
8
|
|
|
9
9
|
```javascript
|
|
10
|
-
const bsv = require('bsv
|
|
10
|
+
const bsv = require('smartledger-bsv')
|
|
11
11
|
|
|
12
12
|
// Access SmartContract module
|
|
13
13
|
const SmartContract = bsv.SmartContract
|
package/ltp-entry.js
ADDED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smartledger/bsv",
|
|
3
|
-
"version": "3.
|
|
4
|
-
"description": "🚀 Complete Bitcoin SV development framework with
|
|
3
|
+
"version": "3.3.3",
|
|
4
|
+
"description": "🚀 Complete Bitcoin SV development framework with Legal Token Protocol (LTP), Global Digital Attestation Framework (GDAF), Shamir Secret Sharing, and 12 flexible loading options. Includes primitives-only architecture for maximum integration flexibility, SmartContract framework, covenant builder, and comprehensive Bitcoin SV API. Perfect for legal tokens, DeFi, smart contracts, and secure Bitcoin applications.",
|
|
5
5
|
"author": "SmartLedger Technology <hello@smartledger.technology> (https://smartledger.technology)",
|
|
6
6
|
"homepage": "https://github.com/codenlighten/smartledger-bsv#readme",
|
|
7
7
|
"bugs": {
|
|
@@ -10,8 +10,10 @@
|
|
|
10
10
|
"main": "index.js",
|
|
11
11
|
"scripts": {
|
|
12
12
|
"lint": "standard",
|
|
13
|
-
"test": "
|
|
14
|
-
"test:
|
|
13
|
+
"test": "mocha",
|
|
14
|
+
"test:ltp": "node complete_ltp_demo.js",
|
|
15
|
+
"test:ltp-primitives": "node simple_demo.js",
|
|
16
|
+
"test:architecture": "node architecture_demo.js",
|
|
15
17
|
"test:js2script": "node lib/smart_contract/opcode_map.js && node lib/smart_contract/covenant_builder.js",
|
|
16
18
|
"test:opcodes": "node lib/smart_contract/opcode_list.js",
|
|
17
19
|
"test:covenants": "node examples/covenants/advanced_covenant_demo.js",
|
|
@@ -23,14 +25,18 @@
|
|
|
23
25
|
"build-ecies": "NODE_OPTIONS=\"--openssl-legacy-provider\" webpack ecies/index.js --config build/webpack.subproject.config.js --output-library bsvEcies -o bsv-ecies.min.js",
|
|
24
26
|
"build-message": "NODE_OPTIONS=\"--openssl-legacy-provider\" webpack message/index.js --config build/webpack.subproject.config.js --output-library bsvMessage -o bsv-message.min.js",
|
|
25
27
|
"build-mnemonic": "NODE_OPTIONS=\"--openssl-legacy-provider\" webpack mnemonic/index.js --config build/webpack.subproject.config.js --output-library bsvMnemonic -o bsv-mnemonic.min.js",
|
|
28
|
+
"build-shamir": "NODE_OPTIONS=\"--openssl-legacy-provider\" webpack shamir-entry.js --config build/webpack.subproject.config.js --output-library bsvShamir -o bsv-shamir.min.js",
|
|
29
|
+
"build-ltp": "NODE_OPTIONS=\"--openssl-legacy-provider\" webpack ltp-entry.js --config build/webpack.ltp.config.js",
|
|
30
|
+
"build-gdaf": "NODE_OPTIONS=\"--openssl-legacy-provider\" webpack gdaf-entry.js --config build/webpack.gdaf.config.js",
|
|
26
31
|
"build-smartcontract": "NODE_OPTIONS=\"--openssl-legacy-provider\" webpack smartcontract-entry.js --config build/webpack.smartcontract.config.js",
|
|
27
32
|
"build-covenant": "NODE_OPTIONS=\"--openssl-legacy-provider\" webpack covenant-entry.js --config build/webpack.covenant.config.js",
|
|
28
33
|
"build-script-helper": "NODE_OPTIONS=\"--openssl-legacy-provider\" webpack script-helper-entry.js --config build/webpack.script-helper.config.js",
|
|
29
34
|
"build-security": "NODE_OPTIONS=\"--openssl-legacy-provider\" webpack security-entry.js --config build/webpack.security.config.js",
|
|
30
35
|
"build-bundle": "NODE_OPTIONS=\"--openssl-legacy-provider\" webpack bundle-entry.js --config build/webpack.bundle.config.js",
|
|
31
|
-
"build": "npm run build-bsv && npm run build-ecies && npm run build-message && npm run build-mnemonic && npm run build-smartcontract",
|
|
36
|
+
"build": "npm run build-bsv && npm run build-ecies && npm run build-message && npm run build-mnemonic && npm run build-shamir && npm run build-smartcontract",
|
|
32
37
|
"build-specialized": "npm run build-covenant && npm run build-script-helper && npm run build-security",
|
|
33
|
-
"build-
|
|
38
|
+
"build-advanced": "npm run build-ltp && npm run build-gdaf",
|
|
39
|
+
"build-all": "npm run build && npm run build-bundle && npm run build-specialized && npm run build-advanced",
|
|
34
40
|
"test:browser": "echo 'Open tests/standalone-modules-test.html in browser for comprehensive testing'",
|
|
35
41
|
"test:bundle": "echo 'Open tests/bundle-completeness-test.html in browser to verify bundle completeness'",
|
|
36
42
|
"demo": "npm run test:covenants",
|
|
@@ -58,12 +64,21 @@
|
|
|
58
64
|
"bsv-ecies.min.js",
|
|
59
65
|
"bsv-message.min.js",
|
|
60
66
|
"bsv-mnemonic.min.js",
|
|
67
|
+
"bsv-shamir.min.js",
|
|
68
|
+
"bsv-gdaf.min.js",
|
|
69
|
+
"bsv-ltp.min.js",
|
|
61
70
|
"bsv-smartcontract.min.js",
|
|
62
71
|
"bsv-covenant.min.js",
|
|
63
72
|
"bsv-script-helper.min.js",
|
|
64
73
|
"bsv-security.min.js",
|
|
65
74
|
"bsv.d.ts",
|
|
66
75
|
"validation_test.js",
|
|
76
|
+
"test_shamir.js",
|
|
77
|
+
"shamir_demo.js",
|
|
78
|
+
"complete_ltp_demo.js",
|
|
79
|
+
"simple_demo.js",
|
|
80
|
+
"architecture_demo.js",
|
|
81
|
+
"test_standalone_shamir.html",
|
|
67
82
|
"docs/",
|
|
68
83
|
"examples/",
|
|
69
84
|
"LICENSE",
|
|
@@ -75,6 +90,21 @@
|
|
|
75
90
|
"bitcoin",
|
|
76
91
|
"bitcoin-sv",
|
|
77
92
|
"bsv",
|
|
93
|
+
"legal-token-protocol",
|
|
94
|
+
"ltp",
|
|
95
|
+
"legal-tokens",
|
|
96
|
+
"primitives-only",
|
|
97
|
+
"legal-compliance",
|
|
98
|
+
"property-rights",
|
|
99
|
+
"obligations",
|
|
100
|
+
"attestations",
|
|
101
|
+
"gdaf",
|
|
102
|
+
"global-digital-attestation",
|
|
103
|
+
"w3c-credentials",
|
|
104
|
+
"verifiable-credentials",
|
|
105
|
+
"decentralized-identity",
|
|
106
|
+
"shamir-secret-sharing",
|
|
107
|
+
"threshold-cryptography",
|
|
78
108
|
"cryptocurrency",
|
|
79
109
|
"blockchain",
|
|
80
110
|
"smart-contracts",
|
|
@@ -101,6 +131,18 @@
|
|
|
101
131
|
"pels",
|
|
102
132
|
"bip143",
|
|
103
133
|
"preimage",
|
|
134
|
+
"shamir-secret-sharing",
|
|
135
|
+
"threshold-cryptography",
|
|
136
|
+
"secret-splitting",
|
|
137
|
+
"global-digital-attestation",
|
|
138
|
+
"gdaf",
|
|
139
|
+
"verifiable-credentials",
|
|
140
|
+
"w3c-credentials",
|
|
141
|
+
"decentralized-identity",
|
|
142
|
+
"did-resolution",
|
|
143
|
+
"zero-knowledge-proofs",
|
|
144
|
+
"blockchain-anchoring",
|
|
145
|
+
"attestation-framework",
|
|
104
146
|
"nchain",
|
|
105
147
|
"custom-scripts",
|
|
106
148
|
"multisig",
|
package/script-helper-entry.js
CHANGED
|
@@ -1,49 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* SmartLedger BSV Custom Script Helper - Standalone Module
|
|
3
|
-
*
|
|
4
|
-
* Simplified API for custom script development and signing
|
|
5
|
-
* Requires main BSV library to be loaded first.
|
|
6
|
-
*
|
|
7
|
-
* Usage:
|
|
8
|
-
* <script src="bsv.min.js"></script>
|
|
9
|
-
* <script src="bsv-script-helper.min.js"></script>
|
|
10
|
-
* <script>
|
|
11
|
-
* const sig = bsvScriptHelper.createSignature(tx, key, 0, script, sats);
|
|
12
|
-
* </script>
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
'use strict'
|
|
16
|
-
|
|
17
|
-
// Verify BSV library is available
|
|
18
|
-
if (typeof bsv === 'undefined') {
|
|
19
|
-
throw new Error('CustomScriptHelper requires BSV library. Load bsv.min.js first.');
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// Load CustomScriptHelper
|
|
23
|
-
const CustomScriptHelper = require('./lib/custom-script-helper.js');
|
|
24
|
-
|
|
25
|
-
// Browser compatibility
|
|
26
|
-
if (typeof window !== 'undefined') {
|
|
27
|
-
window.bsvScriptHelper = {
|
|
28
|
-
CustomScriptHelper: CustomScriptHelper,
|
|
29
|
-
createSignature: CustomScriptHelper.createSignature,
|
|
30
|
-
verifySignature: CustomScriptHelper.verifySignature,
|
|
31
|
-
createMultisigSignature: CustomScriptHelper.createMultisigSignature,
|
|
32
|
-
version: bsv.version || 'unknown'
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
// Also attach to main bsv object if available
|
|
36
|
-
if (typeof bsv !== 'undefined') {
|
|
37
|
-
bsv.CustomScriptHelper = CustomScriptHelper;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
console.log('CustomScriptHelper standalone module loaded');
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
module.exports = {
|
|
44
|
-
CustomScriptHelper: CustomScriptHelper,
|
|
45
|
-
createSignature: CustomScriptHelper.createSignature,
|
|
46
|
-
verifySignature: CustomScriptHelper.verifySignature,
|
|
47
|
-
createMultisigSignature: CustomScriptHelper.createMultisigSignature,
|
|
48
|
-
version: bsv.version || 'unknown'
|
|
49
|
-
};
|
|
1
|
+
module.exports = require('./lib/custom-script-helper');
|
package/security-entry.js
CHANGED
|
@@ -1,70 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* SmartLedger BSV Security Module - Standalone Module
|
|
3
|
-
*
|
|
4
|
-
* SmartLedger security enhancements and elliptic curve fixes
|
|
5
|
-
* Can be used standalone or with main BSV library.
|
|
6
|
-
*
|
|
7
|
-
* Usage:
|
|
8
|
-
* <script src="bsv-security.min.js"></script>
|
|
9
|
-
* <script>
|
|
10
|
-
* const verified = bsvSecurity.SmartVerify.verify(sig, hash, pubkey);
|
|
11
|
-
* </script>
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
'use strict'
|
|
15
|
-
|
|
16
|
-
// Load security modules
|
|
17
|
-
const SmartVerify = require('./lib/crypto/smartledger_verify');
|
|
18
|
-
const EllipticFixed = require('./lib/crypto/elliptic-fixed');
|
|
19
|
-
|
|
20
|
-
// Browser compatibility
|
|
21
|
-
if (typeof window !== 'undefined') {
|
|
22
|
-
window.bsvSecurity = {
|
|
23
|
-
SmartVerify: SmartVerify,
|
|
24
|
-
EllipticFixed: EllipticFixed,
|
|
25
|
-
SmartLedger: {
|
|
26
|
-
version: 'v3.2.1',
|
|
27
|
-
hardenedBy: 'SmartLedger',
|
|
28
|
-
baseVersion: 'v1.5.6',
|
|
29
|
-
securityFeatures: [
|
|
30
|
-
'canonical-signatures',
|
|
31
|
-
'malleability-protection',
|
|
32
|
-
'enhanced-validation',
|
|
33
|
-
'elliptic-patches'
|
|
34
|
-
],
|
|
35
|
-
SmartVerify: SmartVerify,
|
|
36
|
-
EllipticFixed: EllipticFixed
|
|
37
|
-
},
|
|
38
|
-
version: 'v3.2.1'
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
// Also attach to main bsv object if available
|
|
42
|
-
if (typeof bsv !== 'undefined') {
|
|
43
|
-
bsv.SmartVerify = SmartVerify;
|
|
44
|
-
bsv.EllipticFixed = EllipticFixed;
|
|
45
|
-
if (!bsv.SmartLedger) {
|
|
46
|
-
bsv.SmartLedger = window.bsvSecurity.SmartLedger;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
console.log('SmartLedger Security standalone module loaded');
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
module.exports = {
|
|
54
|
-
SmartVerify: SmartVerify,
|
|
55
|
-
EllipticFixed: EllipticFixed,
|
|
56
|
-
SmartLedger: {
|
|
57
|
-
version: 'v3.2.1',
|
|
58
|
-
hardenedBy: 'SmartLedger',
|
|
59
|
-
baseVersion: 'v1.5.6',
|
|
60
|
-
securityFeatures: [
|
|
61
|
-
'canonical-signatures',
|
|
62
|
-
'malleability-protection',
|
|
63
|
-
'enhanced-validation',
|
|
64
|
-
'elliptic-patches'
|
|
65
|
-
],
|
|
66
|
-
SmartVerify: SmartVerify,
|
|
67
|
-
EllipticFixed: EllipticFixed
|
|
68
|
-
},
|
|
69
|
-
version: 'v3.2.1'
|
|
70
|
-
};
|
|
1
|
+
module.exports = require('./lib/smartminer');
|
package/shamir-entry.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./lib/crypto/shamir');
|
package/smartcontract-entry.js
CHANGED
|
@@ -1,133 +1 @@
|
|
|
1
|
-
|
|
2
|
-
* SmartLedger BSV - SmartContract Interface
|
|
3
|
-
*
|
|
4
|
-
* Standalone SmartContract interface with debug tools for browser use.
|
|
5
|
-
* This module provides the complete SmartContract development framework
|
|
6
|
-
* including covenant builders, script debuggers, and testing tools.
|
|
7
|
-
*
|
|
8
|
-
* Usage:
|
|
9
|
-
* <script src="bsv.min.js"></script>
|
|
10
|
-
* <script src="bsv-smartcontract.min.js"></script>
|
|
11
|
-
* <script>
|
|
12
|
-
* // SmartContract interface available under bsv.SmartContract
|
|
13
|
-
* const script = bsv.Script.fromASM('OP_1 OP_2 OP_ADD');
|
|
14
|
-
* const result = bsv.SmartContract.examineStack(script);
|
|
15
|
-
* const metrics = bsv.SmartContract.getScriptMetrics(script);
|
|
16
|
-
* </script>
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
'use strict'
|
|
20
|
-
|
|
21
|
-
// Check if BSV library is available
|
|
22
|
-
if (typeof window !== 'undefined' && typeof window.bsv === 'undefined') {
|
|
23
|
-
throw new Error('SmartContract interface requires BSV library. Load bsv.min.js first.')
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// Get BSV reference (works in both Node.js and browser)
|
|
27
|
-
var bsv = (typeof window !== 'undefined') ? window.bsv : require('./index.js')
|
|
28
|
-
|
|
29
|
-
if (!bsv) {
|
|
30
|
-
throw new Error('BSV library not found. Ensure bsv.min.js is loaded before bsv-smartcontract.min.js')
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// Load SmartContract interface
|
|
34
|
-
var SmartContract
|
|
35
|
-
try {
|
|
36
|
-
SmartContract = require('./lib/smart_contract')
|
|
37
|
-
} catch (e) {
|
|
38
|
-
throw new Error('SmartContract module not found: ' + e.message)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// Attach to BSV library
|
|
42
|
-
bsv.SmartContract = SmartContract
|
|
43
|
-
|
|
44
|
-
// Make available globally for browser usage
|
|
45
|
-
if (typeof window !== 'undefined') {
|
|
46
|
-
window.bsvSmartContract = SmartContract
|
|
47
|
-
|
|
48
|
-
// Also ensure it's on the global bsv object
|
|
49
|
-
if (window.bsv) {
|
|
50
|
-
window.bsv.SmartContract = SmartContract
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// Add debug tools information
|
|
55
|
-
if (SmartContract) {
|
|
56
|
-
SmartContract.version = bsv.version || '3.2.1'
|
|
57
|
-
SmartContract.standalone = true
|
|
58
|
-
SmartContract.debugToolsAvailable = {
|
|
59
|
-
examineStack: !!SmartContract.examineStack,
|
|
60
|
-
interpretScript: !!SmartContract.interpretScript,
|
|
61
|
-
getScriptMetrics: !!SmartContract.getScriptMetrics,
|
|
62
|
-
optimizeScript: !!SmartContract.optimizeScript
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Convenience method to check if debug tools are working
|
|
66
|
-
SmartContract.testDebugTools = function() {
|
|
67
|
-
try {
|
|
68
|
-
if (!bsv.Script) {
|
|
69
|
-
return { success: false, error: 'BSV Script class not available' }
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const testScript = bsv.Script.fromASM('OP_1 OP_2 OP_ADD')
|
|
73
|
-
const results = {}
|
|
74
|
-
|
|
75
|
-
if (SmartContract.examineStack) {
|
|
76
|
-
try {
|
|
77
|
-
results.examineStack = SmartContract.examineStack(testScript)
|
|
78
|
-
results.examineStackWorking = true
|
|
79
|
-
} catch (e) {
|
|
80
|
-
results.examineStackWorking = false
|
|
81
|
-
results.examineStackError = e.message
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (SmartContract.interpretScript) {
|
|
86
|
-
try {
|
|
87
|
-
results.interpretScript = SmartContract.interpretScript(testScript)
|
|
88
|
-
results.interpretScriptWorking = true
|
|
89
|
-
} catch (e) {
|
|
90
|
-
results.interpretScriptWorking = false
|
|
91
|
-
results.interpretScriptError = e.message
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
if (SmartContract.getScriptMetrics) {
|
|
96
|
-
try {
|
|
97
|
-
results.scriptMetrics = SmartContract.getScriptMetrics(testScript)
|
|
98
|
-
results.scriptMetricsWorking = true
|
|
99
|
-
} catch (e) {
|
|
100
|
-
results.scriptMetricsWorking = false
|
|
101
|
-
results.scriptMetricsError = e.message
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
if (SmartContract.optimizeScript) {
|
|
106
|
-
try {
|
|
107
|
-
results.optimizeScript = SmartContract.optimizeScript(testScript)
|
|
108
|
-
results.optimizeScriptWorking = true
|
|
109
|
-
} catch (e) {
|
|
110
|
-
results.optimizeScriptWorking = false
|
|
111
|
-
results.optimizeScriptError = e.message
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
return {
|
|
116
|
-
success: true,
|
|
117
|
-
testScript: 'OP_1 OP_2 OP_ADD',
|
|
118
|
-
results: results,
|
|
119
|
-
methodCount: Object.keys(SmartContract).length
|
|
120
|
-
}
|
|
121
|
-
} catch (e) {
|
|
122
|
-
return { success: false, error: e.message }
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
console.log('SmartContract interface loaded:', !!SmartContract)
|
|
128
|
-
if (SmartContract) {
|
|
129
|
-
console.log('SmartContract methods available:', Object.keys(SmartContract).length)
|
|
130
|
-
console.log('Debug tools available:', SmartContract.debugToolsAvailable)
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
module.exports = SmartContract
|
|
1
|
+
module.exports = require('./lib/smart_contract');
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Test Transaction VerifySignature Method
|
|
5
|
+
*
|
|
6
|
+
* Tests the transaction's built-in verifySignature method
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const bsv = require('./index.js');
|
|
10
|
+
|
|
11
|
+
console.log('🔍 Test Transaction VerifySignature Method');
|
|
12
|
+
console.log('==========================================\n');
|
|
13
|
+
|
|
14
|
+
const privateKey = new bsv.PrivateKey('L1aW4aubDFB7yfras2S1mN3bqg9nwySY8nkoLmJebSLD5BWv3ENZ');
|
|
15
|
+
const address = privateKey.toAddress().toString();
|
|
16
|
+
|
|
17
|
+
// Create and sign transaction
|
|
18
|
+
const mockUTXO = {
|
|
19
|
+
txid: '1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef',
|
|
20
|
+
vout: 0,
|
|
21
|
+
address: address,
|
|
22
|
+
satoshis: 50000,
|
|
23
|
+
script: bsv.Script.buildPublicKeyHashOut(address).toHex()
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const transaction = new bsv.Transaction()
|
|
27
|
+
.from(mockUTXO)
|
|
28
|
+
.to(address, 100)
|
|
29
|
+
.change(address)
|
|
30
|
+
.feePerKb(10)
|
|
31
|
+
.sign(privateKey);
|
|
32
|
+
|
|
33
|
+
console.log('✅ Transaction created and signed');
|
|
34
|
+
console.log(`Transaction ID: ${transaction.id}`);
|
|
35
|
+
console.log(`Basic verify(): ${transaction.verify()}`);
|
|
36
|
+
|
|
37
|
+
// Extract signature details
|
|
38
|
+
const input = transaction.inputs[0];
|
|
39
|
+
const signature = input.script.chunks[0]?.buf;
|
|
40
|
+
const publicKey = input.script.chunks[1]?.buf;
|
|
41
|
+
|
|
42
|
+
if (signature && publicKey) {
|
|
43
|
+
console.log('\n🧪 Transaction VerifySignature Method Test:');
|
|
44
|
+
console.log('==========================================');
|
|
45
|
+
|
|
46
|
+
const sigWithoutHashtype = signature.slice(0, -1);
|
|
47
|
+
const pubkeyObj = new bsv.PublicKey(publicKey);
|
|
48
|
+
const subscript = input.output.script;
|
|
49
|
+
const satoshisBN = new bsv.crypto.BN(input.output.satoshis);
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
// Parse the signature first
|
|
53
|
+
const parsedSig = bsv.crypto.Signature.fromDER(sigWithoutHashtype);
|
|
54
|
+
parsedSig.nhashtype = signature[signature.length - 1]; // Set the hashtype
|
|
55
|
+
|
|
56
|
+
console.log(`Parsed signature r: ${parsedSig.r.toString('hex')}`);
|
|
57
|
+
console.log(`Parsed signature s: ${parsedSig.s.toString('hex')}`);
|
|
58
|
+
console.log(`Signature hashtype: 0x${parsedSig.nhashtype.toString(16)}`);
|
|
59
|
+
|
|
60
|
+
// Test transaction's built-in verifySignature method
|
|
61
|
+
const builtinVerify = transaction.verifySignature(parsedSig, pubkeyObj, 0, subscript, satoshisBN);
|
|
62
|
+
console.log(`transaction.verifySignature(): ${builtinVerify ? '✅ VALID' : '❌ INVALID'}`);
|
|
63
|
+
|
|
64
|
+
// Test with default flags
|
|
65
|
+
const builtinVerifyWithFlags = transaction.verifySignature(parsedSig, pubkeyObj, 0, subscript, satoshisBN,
|
|
66
|
+
bsv.Script.Interpreter.SCRIPT_ENABLE_SIGHASH_FORKID);
|
|
67
|
+
console.log(`transaction.verifySignature() with flags: ${builtinVerifyWithFlags ? '✅ VALID' : '❌ INVALID'}`);
|
|
68
|
+
|
|
69
|
+
console.log('\n🔍 Manual Sighash.verify Test:');
|
|
70
|
+
console.log('==============================');
|
|
71
|
+
|
|
72
|
+
// Test the Sighash.verify method directly
|
|
73
|
+
const sighashVerify = bsv.Transaction.Sighash.verify(transaction, parsedSig, pubkeyObj, 0, subscript, satoshisBN);
|
|
74
|
+
console.log(`Sighash.verify(): ${sighashVerify ? '✅ VALID' : '❌ INVALID'}`);
|
|
75
|
+
|
|
76
|
+
const sighashVerifyWithFlags = bsv.Transaction.Sighash.verify(transaction, parsedSig, pubkeyObj, 0, subscript, satoshisBN,
|
|
77
|
+
bsv.Script.Interpreter.SCRIPT_ENABLE_SIGHASH_FORKID);
|
|
78
|
+
console.log(`Sighash.verify() with flags: ${sighashVerifyWithFlags ? '✅ VALID' : '❌ INVALID'}`);
|
|
79
|
+
|
|
80
|
+
console.log('\n🔧 Compare Sighash Calculation:');
|
|
81
|
+
console.log('===============================');
|
|
82
|
+
|
|
83
|
+
// Get the sighash that Sighash.verify would calculate
|
|
84
|
+
const officialSighash = bsv.Transaction.Sighash.sighash(
|
|
85
|
+
transaction,
|
|
86
|
+
parsedSig.nhashtype,
|
|
87
|
+
0,
|
|
88
|
+
subscript,
|
|
89
|
+
satoshisBN,
|
|
90
|
+
bsv.Script.Interpreter.SCRIPT_ENABLE_SIGHASH_FORKID
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
console.log(`Official Sighash.sighash(): ${officialSighash.toString('hex')}`);
|
|
94
|
+
|
|
95
|
+
// Compare with our transaction.sighash method
|
|
96
|
+
const ourSighash = transaction.sighash(0, parsedSig.nhashtype, subscript, satoshisBN);
|
|
97
|
+
console.log(`Our transaction.sighash(): ${ourSighash.toString('hex')}`);
|
|
98
|
+
console.log(`Sighashes match: ${officialSighash.equals(ourSighash) ? '✅ YES' : '❌ NO'}`);
|
|
99
|
+
|
|
100
|
+
// Test verification with the official sighash
|
|
101
|
+
console.log('\n🎯 Verification with Official Sighash:');
|
|
102
|
+
console.log('=====================================');
|
|
103
|
+
|
|
104
|
+
const ecdsaWithOfficial = bsv.crypto.ECDSA.verify(officialSighash, parsedSig, pubkeyObj);
|
|
105
|
+
console.log(`ECDSA.verify(officialSighash): ${ecdsaWithOfficial ? '✅ VALID' : '❌ INVALID'}`);
|
|
106
|
+
|
|
107
|
+
const smartVerifyWithOfficial = bsv.SmartVerify.smartVerify(officialSighash, parsedSig, pubkeyObj);
|
|
108
|
+
console.log(`SmartVerify(officialSighash): ${smartVerifyWithOfficial ? '✅ VALID' : '❌ INVALID'}`);
|
|
109
|
+
|
|
110
|
+
} catch (error) {
|
|
111
|
+
console.log('❌ Test failed:', error.message);
|
|
112
|
+
console.log('Stack:', error.stack);
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
} else {
|
|
116
|
+
console.log('❌ Could not extract signature or public key');
|
|
117
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Test Script for Debug Tools Integration
|
|
4
|
+
* =======================================
|
|
5
|
+
* Tests the newly integrated StackExaminer and ScriptInterpreter tools
|
|
6
|
+
* in the SmartContract interface
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
const SmartContract = require('./lib/smart_contract/index.js');
|
|
10
|
+
|
|
11
|
+
console.log("🧪 Testing SmartContract Debug Tools Integration");
|
|
12
|
+
console.log("=================================================\n");
|
|
13
|
+
|
|
14
|
+
// Test 1: Check if modules are loaded
|
|
15
|
+
console.log("1. Module Loading Test:");
|
|
16
|
+
console.log(" StackExaminer loaded:", !!SmartContract.StackExaminer);
|
|
17
|
+
console.log(" ScriptInterpreter loaded:", !!SmartContract.ScriptInterpreter);
|
|
18
|
+
console.log(" examineStack method:", typeof SmartContract.examineStack);
|
|
19
|
+
console.log(" debugScriptExecution method:", typeof SmartContract.debugScriptExecution);
|
|
20
|
+
console.log(" parseScript method:", typeof SmartContract.parseScript);
|
|
21
|
+
|
|
22
|
+
// Test 2: Feature flags
|
|
23
|
+
console.log("\n2. Feature Flags Test:");
|
|
24
|
+
console.log(" STACK_EXAMINATION:", SmartContract.features.STACK_EXAMINATION);
|
|
25
|
+
console.log(" SCRIPT_DEBUGGING:", SmartContract.features.SCRIPT_DEBUGGING);
|
|
26
|
+
console.log(" STEP_BY_STEP_EXECUTION:", SmartContract.features.STEP_BY_STEP_EXECUTION);
|
|
27
|
+
console.log(" INTERACTIVE_DEBUGGING:", SmartContract.features.INTERACTIVE_DEBUGGING);
|
|
28
|
+
|
|
29
|
+
// Test 3: Simple script parsing
|
|
30
|
+
console.log("\n3. Script Parsing Test:");
|
|
31
|
+
try {
|
|
32
|
+
const parsedASM = SmartContract.parseScript("OP_DUP OP_HASH160");
|
|
33
|
+
console.log(" ✅ ASM parsing successful");
|
|
34
|
+
console.log(" Script length:", parsedASM.chunks.length);
|
|
35
|
+
} catch (err) {
|
|
36
|
+
console.log(" ❌ ASM parsing failed:", err.message);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
try {
|
|
40
|
+
const parsedHex = SmartContract.parseScript("76a914");
|
|
41
|
+
console.log(" ✅ HEX parsing successful");
|
|
42
|
+
console.log(" Script length:", parsedHex.chunks.length);
|
|
43
|
+
} catch (err) {
|
|
44
|
+
console.log(" ❌ HEX parsing failed:", err.message);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// Test 4: Stack examination (non-interactive)
|
|
48
|
+
console.log("\n4. Stack Examination Test:");
|
|
49
|
+
try {
|
|
50
|
+
// Use simple valid scripts for testing
|
|
51
|
+
const result = SmartContract.examineStack("51", "51"); // OP_1, OP_1
|
|
52
|
+
console.log(" ✅ Stack examination completed, result:", result);
|
|
53
|
+
} catch (err) {
|
|
54
|
+
console.log(" ⚠️ Stack examination had issues:", err.message);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
console.log("\n=================================================");
|
|
58
|
+
console.log("🎉 Debug Tools Integration Test Complete!");
|
|
59
|
+
console.log("=================================================");
|
|
60
|
+
|
|
61
|
+
// Count total methods in SmartContract
|
|
62
|
+
const methodCount = Object.keys(SmartContract).filter(key =>
|
|
63
|
+
typeof SmartContract[key] === 'function'
|
|
64
|
+
).length;
|
|
65
|
+
|
|
66
|
+
console.log(`\n📊 SmartContract Interface Summary:`);
|
|
67
|
+
console.log(` Total Methods: ${methodCount}`);
|
|
68
|
+
console.log(` Total Modules: ${Object.keys(SmartContract).filter(key =>
|
|
69
|
+
typeof SmartContract[key] === 'object' && SmartContract[key].constructor.name !== 'Object'
|
|
70
|
+
).length}`);
|
|
71
|
+
console.log(` Feature Flags: ${Object.keys(SmartContract.features).length}`);
|