smartledger-bsv 3.4.0 ā 3.4.5
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 +446 -0
- package/README.md +112 -84
- package/SECURITY.md +88 -0
- package/bin/cli.js +13 -8
- package/bsv-anchor.min.js +12 -0
- package/bsv-covenant.min.js +8 -8
- package/bsv-didweb.min.js +12 -0
- package/bsv-gdaf.min.js +9 -9
- package/bsv-ltp.min.js +9 -9
- package/bsv-mnemonic.min.js +2 -2
- package/bsv-shamir.min.js +3 -3
- package/bsv-smartcontract.min.js +5 -5
- package/bsv-statuslist.min.js +18 -0
- package/bsv-vcjwt.min.js +12 -0
- package/bsv.bundle.js +9 -9
- package/bsv.d.ts +486 -9
- package/bsv.min.js +5 -5
- package/build/webpack.anchor.config.js +9 -13
- package/build/webpack.didweb.config.js +10 -14
- package/build/webpack.statuslist.config.js +9 -14
- package/build/webpack.vcjwt.config.js +9 -13
- package/docs/COVENANT_DEVELOPMENT_RESOLVED.md +2 -2
- package/docs/MODULE_REFERENCE_COMPLETE.md +61 -58
- package/docs/advanced/LEGAL_TOKEN_PROTOCOL.md +3 -3
- package/docs/advanced/UTXO_MANAGER_GUIDE.md +1 -1
- package/docs/getting-started/INSTALLATION.md +30 -30
- package/docs/getting-started/QUICK_START.md +18 -18
- package/docs/migration/FROM_BSV_1_5_6.md +16 -10
- package/gdaf-entry.js +1 -2
- package/index.js +44 -13
- package/lib/browser-utxo-manager-es5.js +11 -4
- package/lib/browser-utxo-manager.js +15 -8
- package/lib/ltp/claim.js +1 -0
- package/lib/ltp/obligation.js +1 -0
- package/lib/ltp/registry.js +2 -0
- package/lib/ltp/right.js +1 -0
- package/lib/script/script.js +19 -0
- package/lib/smart_contract/covenant.js +10 -1
- package/lib/smartutxo.js +20 -12
- package/lib/transaction/input/publickeyhash.js +6 -1
- package/lib/transaction/transaction.js +13 -2
- package/lib/util/_.js +7 -1
- package/ltp-entry.js +1 -2
- package/package.json +11 -13
- package/utilities/blockchain-state.js +32 -23
- package/demos/README.md +0 -188
- package/demos/architecture_demo.js +0 -247
- package/demos/browser-test.html +0 -1208
- package/demos/bsv_wallet_demo.js +0 -242
- package/demos/complete_ltp_demo.js +0 -511
- package/demos/debug_tools_demo.js +0 -87
- package/demos/demo_features.js +0 -123
- package/demos/easy_interface_demo.js +0 -109
- package/demos/ecies_demo.js +0 -182
- package/demos/gdaf_core_test.js +0 -131
- package/demos/gdaf_demo.js +0 -237
- package/demos/ltp_demo.js +0 -361
- package/demos/ltp_primitives_demo.js +0 -403
- package/demos/message_demo.js +0 -209
- package/demos/preimage_separation_demo.js +0 -383
- package/demos/script_helper_demo.js +0 -289
- package/demos/security_demo.js +0 -287
- package/demos/shamir_demo.js +0 -121
- package/demos/simple_demo.js +0 -204
- package/demos/simple_p2pkh_demo.js +0 -169
- package/demos/simple_utxo_preimage_demo.js +0 -196
- package/demos/smart_contract_demo.html +0 -1347
- package/demos/smart_contract_demo.js +0 -910
- package/demos/utxo_generator_demo.js +0 -244
- package/demos/validation_pipeline_demo.js +0 -155
- package/demos/web3keys.html +0 -740
- package/examples/README.md +0 -200
- package/examples/basic/transaction-creation.js +0 -534
- package/examples/basic/transaction_signature_api_gap.js +0 -178
- package/examples/complete_workflow_demo.js +0 -783
- package/examples/covenants/advanced_covenant_demo.js +0 -219
- package/examples/covenants/covenant_interface_demo.js +0 -270
- package/examples/covenants/covenant_manual_signature_resolved.js +0 -212
- package/examples/covenants/covenant_signature_template.js +0 -117
- package/examples/covenants2/covenant_bidirectional_example.js +0 -262
- package/examples/covenants2/covenant_utils_demo.js +0 -120
- package/examples/covenants2/preimage_covenant_utils.js +0 -287
- package/examples/covenants2/production_integration.js +0 -256
- package/examples/data/covenant_utxos.json +0 -28
- package/examples/data/utxos.json +0 -26
- package/examples/definitive_working_demo.js +0 -261
- package/examples/final_working_contracts.js +0 -338
- package/examples/preimage/README.md +0 -178
- package/examples/preimage/extract_preimage_bidirectional.js +0 -421
- package/examples/preimage/generate_sample_preimage.js +0 -208
- package/examples/preimage/generate_sighash_examples.js +0 -152
- package/examples/preimage/parse_preimage.js +0 -117
- package/examples/preimage/test_preimage_extractor.js +0 -53
- package/examples/preimage/test_varint_extraction.js +0 -95
- package/examples/scripts/custom_script_helper_example.js +0 -273
- package/examples/scripts/custom_script_signature_test.js +0 -344
- package/examples/scripts/script_interpreter.js +0 -193
- package/examples/smart_contract/complete_workflow_demo.js +0 -343
- package/examples/smart_contract/covenant_builder_demo.js +0 -176
- package/examples/smart_contract/script_testing_integration.js +0 -198
- package/examples/smart_contract_templates.js +0 -718
- package/examples/working_smart_contracts.js +0 -348
- package/lib/smart_contract/test_integration.js +0 -269
- package/tests/browser-compatibility/README.md +0 -35
- package/tests/browser-compatibility/test-cdn-vs-local.html +0 -186
- package/tests/browser-compatibility/test-pbkdf2.html +0 -51
- package/tests/bundle-completeness-test.html +0 -131
- package/tests/bundle-demo.html +0 -476
- package/tests/smartcontract-test.html +0 -239
- package/tests/standalone-modules-test.html +0 -260
- package/tests/test.html +0 -612
- package/tests/test_builtin_verify.js +0 -117
- package/tests/test_debug_integration.js +0 -71
- package/tests/test_ecdsa_little.js +0 -70
- package/tests/test_shamir.js +0 -221
- package/tests/test_smartverify_der.js +0 -110
- package/tests/test_standalone_shamir.html +0 -83
- package/tests/unpkg-demo.html +0 -194
- package/utilities/blockchain-state.json +0 -118565
package/demos/demo_features.js
DELETED
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* SmartLedger-BSV v3.0.2 New Features Demo
|
|
5
|
-
*
|
|
6
|
-
* This script demonstrates the new UTXO management and miner simulation features
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
const bsv = require('../index.js');
|
|
10
|
-
|
|
11
|
-
console.log('š SmartLedger-BSV v3.0.2 New Features Demo');
|
|
12
|
-
console.log('============================================\n');
|
|
13
|
-
|
|
14
|
-
// Create test wallet
|
|
15
|
-
const privateKey = new bsv.PrivateKey();
|
|
16
|
-
const address = privateKey.toAddress().toString();
|
|
17
|
-
|
|
18
|
-
console.log('š± Demo Wallet:');
|
|
19
|
-
console.log(`Address: ${address}`);
|
|
20
|
-
console.log(`Private Key: ${privateKey.toString()}\n`);
|
|
21
|
-
|
|
22
|
-
// 1. UTXO Management Demo
|
|
23
|
-
console.log('š° SmartUTXO Management System:');
|
|
24
|
-
console.log('===============================');
|
|
25
|
-
|
|
26
|
-
const utxoManager = new bsv.SmartUTXO();
|
|
27
|
-
|
|
28
|
-
// Create mock UTXOs for testing
|
|
29
|
-
const mockUTXOs = utxoManager.createMockUTXOs(address, 3, 50000);
|
|
30
|
-
console.log(`Created ${mockUTXOs.length} mock UTXOs for testing`);
|
|
31
|
-
|
|
32
|
-
// Add UTXOs to the system
|
|
33
|
-
mockUTXOs.forEach(utxo => utxoManager.addUTXO(utxo));
|
|
34
|
-
console.log('UTXOs added to blockchain state');
|
|
35
|
-
|
|
36
|
-
// Check balance
|
|
37
|
-
const balance = utxoManager.getBalance(address);
|
|
38
|
-
console.log(`Total balance: ${balance} satoshis (${balance / 100000000} BSV)`);
|
|
39
|
-
|
|
40
|
-
// Get UTXOs for the address
|
|
41
|
-
const utxos = utxoManager.getUTXOsForAddress(address);
|
|
42
|
-
console.log(`Available UTXOs: ${utxos.length}`);
|
|
43
|
-
|
|
44
|
-
// Get blockchain stats
|
|
45
|
-
const stats = utxoManager.getStats();
|
|
46
|
-
console.log(`Blockchain stats: ${stats.totalUTXOs} UTXOs, ${stats.totalValue} satoshis\n`);
|
|
47
|
-
|
|
48
|
-
// 2. Miner Simulation Demo
|
|
49
|
-
console.log('āļø SmartMiner Blockchain Simulation:');
|
|
50
|
-
console.log('====================================');
|
|
51
|
-
|
|
52
|
-
const miner = new bsv.SmartMiner(bsv, {
|
|
53
|
-
logLevel: 'info',
|
|
54
|
-
validateScripts: true
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
// Create a simple transaction
|
|
58
|
-
try {
|
|
59
|
-
const transaction = new bsv.Transaction()
|
|
60
|
-
.from({
|
|
61
|
-
txid: mockUTXOs[0].txid,
|
|
62
|
-
vout: mockUTXOs[0].vout,
|
|
63
|
-
address: address,
|
|
64
|
-
script: mockUTXOs[0].script,
|
|
65
|
-
satoshis: mockUTXOs[0].satoshis
|
|
66
|
-
})
|
|
67
|
-
.to(address, 25000) // Send to self
|
|
68
|
-
.change(address) // Change back to self
|
|
69
|
-
.sign(privateKey);
|
|
70
|
-
|
|
71
|
-
console.log(`Transaction created: ${transaction.id}`);
|
|
72
|
-
|
|
73
|
-
// Submit to miner
|
|
74
|
-
const accepted = miner.acceptTransaction(transaction);
|
|
75
|
-
console.log(`Transaction accepted: ${accepted}`);
|
|
76
|
-
|
|
77
|
-
// Check mempool
|
|
78
|
-
const mempoolStats = miner.getMempoolStats();
|
|
79
|
-
console.log(`Mempool: ${mempoolStats.transactionCount} transactions`);
|
|
80
|
-
|
|
81
|
-
// Mine a block
|
|
82
|
-
const block = miner.mineBlock();
|
|
83
|
-
console.log(`Mined block ${block.height} with ${block.transactionCount} transactions`);
|
|
84
|
-
console.log(`Block hash: ${block.hash}`);
|
|
85
|
-
|
|
86
|
-
// Get blockchain status
|
|
87
|
-
const blockchainStats = miner.getBlockchainStats();
|
|
88
|
-
console.log(`Blockchain height: ${blockchainStats.currentHeight}`);
|
|
89
|
-
|
|
90
|
-
} catch (error) {
|
|
91
|
-
console.log(`Transaction error (expected for demo): ${error.message}`);
|
|
92
|
-
console.log('Note: This is normal for mock UTXOs without proper scripts');
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
console.log('\n3. Signature Verification Demo:');
|
|
96
|
-
console.log('===============================');
|
|
97
|
-
|
|
98
|
-
// Test the fixed signature verification
|
|
99
|
-
const message = Buffer.from('SmartLedger-BSV v3.0.2 Demo', 'utf8');
|
|
100
|
-
const hash = bsv.crypto.Hash.sha256(message);
|
|
101
|
-
const signature = bsv.crypto.ECDSA.sign(hash, privateKey);
|
|
102
|
-
const derSig = signature.toDER();
|
|
103
|
-
|
|
104
|
-
// Test all verification methods
|
|
105
|
-
console.log('Message:', message.toString());
|
|
106
|
-
console.log('Signature verification tests:');
|
|
107
|
-
|
|
108
|
-
const ecdsaResult = bsv.crypto.ECDSA.verify(hash, derSig, privateKey.publicKey);
|
|
109
|
-
console.log(`ā
ECDSA.verify(): ${ecdsaResult}`);
|
|
110
|
-
|
|
111
|
-
const smartResult = bsv.SmartVerify.smartVerify(hash, derSig, privateKey.publicKey);
|
|
112
|
-
console.log(`ā
SmartVerify.smartVerify(): ${smartResult}`);
|
|
113
|
-
|
|
114
|
-
const canonicalResult = bsv.SmartVerify.isCanonical(derSig);
|
|
115
|
-
console.log(`ā
SmartVerify.isCanonical(): ${canonicalResult}`);
|
|
116
|
-
|
|
117
|
-
console.log('\nš Demo completed successfully!');
|
|
118
|
-
console.log('š All signature verification methods are now working correctly.');
|
|
119
|
-
console.log('š§ New UTXO management and miner tools are ready for development!');
|
|
120
|
-
|
|
121
|
-
// Save state for future use
|
|
122
|
-
utxoManager.saveState();
|
|
123
|
-
console.log('\nš¾ Blockchain state saved for future sessions.');
|
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Easy Developer Interface Demo
|
|
3
|
-
*
|
|
4
|
-
* Shows how developers can use GDAF features directly from the main bsv object
|
|
5
|
-
* without needing to create separate GDAF instances.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
const bsv = require('../index.js')
|
|
9
|
-
|
|
10
|
-
console.log('šÆ SmartLedger BSV - Easy GDAF Developer Interface')
|
|
11
|
-
console.log('=================================================\n')
|
|
12
|
-
|
|
13
|
-
try {
|
|
14
|
-
// 1. BEFORE: Complex approach (still available)
|
|
15
|
-
console.log('ā BEFORE - Complex approach:')
|
|
16
|
-
console.log(' const gdaf = new bsv.GDAF()')
|
|
17
|
-
console.log(' const did = gdaf.createDID(publicKey)')
|
|
18
|
-
console.log(' const credential = gdaf.createEmailCredential(...)')
|
|
19
|
-
console.log()
|
|
20
|
-
|
|
21
|
-
// 2. NOW: Simple direct access
|
|
22
|
-
console.log('ā
NOW - Simple direct access:')
|
|
23
|
-
console.log(' const did = bsv.createDID(publicKey)')
|
|
24
|
-
console.log(' const credential = bsv.createEmailCredential(...)')
|
|
25
|
-
console.log()
|
|
26
|
-
|
|
27
|
-
// 3. Demonstrate the new easy interface
|
|
28
|
-
console.log('š Live Demo with Easy Interface:')
|
|
29
|
-
console.log('--------------------------------')
|
|
30
|
-
|
|
31
|
-
const issuerPrivateKey = new bsv.PrivateKey()
|
|
32
|
-
const subjectPrivateKey = new bsv.PrivateKey()
|
|
33
|
-
|
|
34
|
-
// Direct DID creation - no GDAF instance needed!
|
|
35
|
-
const issuerDID = bsv.createDID(issuerPrivateKey.toPublicKey())
|
|
36
|
-
const subjectDID = bsv.createDID(subjectPrivateKey.toPublicKey())
|
|
37
|
-
|
|
38
|
-
console.log('ā
DIDs created directly from bsv object')
|
|
39
|
-
console.log(' Issuer:', issuerDID.substring(0, 50) + '...')
|
|
40
|
-
console.log(' Subject:', subjectDID.substring(0, 50) + '...')
|
|
41
|
-
|
|
42
|
-
// Direct credential creation - no GDAF instance needed!
|
|
43
|
-
const emailCredential = bsv.createEmailCredential(
|
|
44
|
-
issuerDID,
|
|
45
|
-
subjectDID,
|
|
46
|
-
'developer@example.com',
|
|
47
|
-
issuerPrivateKey
|
|
48
|
-
)
|
|
49
|
-
|
|
50
|
-
console.log('ā
Email credential created directly')
|
|
51
|
-
console.log(' Type:', emailCredential.type.join(', '))
|
|
52
|
-
console.log(' Issuer:', emailCredential.issuer.substring(0, 50) + '...')
|
|
53
|
-
|
|
54
|
-
// Direct validation - no GDAF instance needed!
|
|
55
|
-
const validation = bsv.validateCredential(emailCredential, 'EmailVerifiedCredential')
|
|
56
|
-
|
|
57
|
-
console.log('ā
Credential validated directly')
|
|
58
|
-
console.log(' Valid:', validation.valid)
|
|
59
|
-
console.log(' Errors:', validation.errors.length)
|
|
60
|
-
|
|
61
|
-
// Direct ZK proof generation - no GDAF instance needed!
|
|
62
|
-
const proof = bsv.generateSelectiveProof(
|
|
63
|
-
emailCredential,
|
|
64
|
-
['credentialSubject.verified'],
|
|
65
|
-
'demo-nonce-123'
|
|
66
|
-
)
|
|
67
|
-
|
|
68
|
-
console.log('ā
ZK proof generated directly')
|
|
69
|
-
console.log(' Type:', proof.type)
|
|
70
|
-
console.log(' Disclosed fields:', proof.disclosedFields.length)
|
|
71
|
-
|
|
72
|
-
// Direct schema access - no GDAF instance needed!
|
|
73
|
-
const schemas = bsv.getCredentialSchemas()
|
|
74
|
-
const schemaNames = Object.keys(schemas)
|
|
75
|
-
|
|
76
|
-
console.log('ā
Schemas accessed directly')
|
|
77
|
-
console.log(' Available types:', schemaNames.length)
|
|
78
|
-
console.log(' Types:', schemaNames.slice(0, 3).join(', ') + '...')
|
|
79
|
-
|
|
80
|
-
// Direct template creation - no GDAF instance needed!
|
|
81
|
-
const template = bsv.createCredentialTemplate('KYCVerifiedCredential')
|
|
82
|
-
|
|
83
|
-
console.log('ā
Template created directly')
|
|
84
|
-
console.log(' Template type:', template.type.join(', '))
|
|
85
|
-
console.log()
|
|
86
|
-
|
|
87
|
-
console.log('š Developer Experience Comparison:')
|
|
88
|
-
console.log('===================================')
|
|
89
|
-
console.log()
|
|
90
|
-
console.log('š¦ COMPLEX (Old way):')
|
|
91
|
-
console.log(' const bsv = require("smartledger-bsv")')
|
|
92
|
-
console.log(' const gdaf = new bsv.GDAF() // Extra step!')
|
|
93
|
-
console.log(' const did = gdaf.createDID(publicKey)')
|
|
94
|
-
console.log(' const cred = gdaf.createEmailCredential(...)')
|
|
95
|
-
console.log(' const proof = gdaf.generateSelectiveProof(...)')
|
|
96
|
-
console.log()
|
|
97
|
-
console.log('ā” SIMPLE (New way):')
|
|
98
|
-
console.log(' const bsv = require("smartledger-bsv")')
|
|
99
|
-
console.log(' const did = bsv.createDID(publicKey) // Direct!')
|
|
100
|
-
console.log(' const cred = bsv.createEmailCredential(...)')
|
|
101
|
-
console.log(' const proof = bsv.generateSelectiveProof(...)')
|
|
102
|
-
console.log()
|
|
103
|
-
console.log('ā
Result: 50% fewer lines, no intermediate objects!')
|
|
104
|
-
console.log('ā
Perfect for developers who want quick GDAF features!')
|
|
105
|
-
|
|
106
|
-
} catch (error) {
|
|
107
|
-
console.error('ā Easy Interface Demo failed:', error.message)
|
|
108
|
-
process.exit(1)
|
|
109
|
-
}
|
package/demos/ecies_demo.js
DELETED
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* ECIES Encryption/Decryption Demo
|
|
5
|
-
* ================================
|
|
6
|
-
*
|
|
7
|
-
* Demonstrates ECIES (Elliptic Curve Integrated Encryption Scheme) capabilities
|
|
8
|
-
* using SmartLedger-BSV's bsv-ecies module.
|
|
9
|
-
*
|
|
10
|
-
* Features demonstrated:
|
|
11
|
-
* - ECIES encryption with public keys
|
|
12
|
-
* - ECIES decryption with private keys
|
|
13
|
-
* - Message encryption/decryption
|
|
14
|
-
* - File-like data encryption
|
|
15
|
-
* - Error handling and validation
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
const bsv = require('../index.js');
|
|
19
|
-
|
|
20
|
-
console.log('š SmartLedger-BSV ECIES Demo');
|
|
21
|
-
console.log('==============================\n');
|
|
22
|
-
|
|
23
|
-
// Test ECIES functionality
|
|
24
|
-
async function demonstrateECIES() {
|
|
25
|
-
try {
|
|
26
|
-
// Generate sender and receiver keypairs
|
|
27
|
-
console.log('š Generating keypairs...');
|
|
28
|
-
const senderPrivateKey = bsv.PrivateKey.fromRandom();
|
|
29
|
-
const receiverPrivateKey = bsv.PrivateKey.fromRandom();
|
|
30
|
-
|
|
31
|
-
console.log('š¤ Sender Address:', senderPrivateKey.toAddress().toString());
|
|
32
|
-
console.log('š¤ Receiver Address:', receiverPrivateKey.toAddress().toString());
|
|
33
|
-
console.log('');
|
|
34
|
-
|
|
35
|
-
// Test 1: Basic message encryption
|
|
36
|
-
console.log('š Test 1: Basic Message Encryption');
|
|
37
|
-
console.log('-----------------------------------');
|
|
38
|
-
|
|
39
|
-
const message = 'Hello, this is a secret message from SmartLedger-BSV ECIES demo!';
|
|
40
|
-
console.log('Original message:', message);
|
|
41
|
-
|
|
42
|
-
// Encrypt with receiver's public key
|
|
43
|
-
const encrypted = bsv.ECIES()
|
|
44
|
-
.privateKey(senderPrivateKey)
|
|
45
|
-
.publicKey(receiverPrivateKey.publicKey)
|
|
46
|
-
.encrypt(message);
|
|
47
|
-
|
|
48
|
-
console.log('ā
Message encrypted successfully');
|
|
49
|
-
console.log('š¦ Encrypted data length:', encrypted.length, 'bytes');
|
|
50
|
-
console.log('š Encrypted (hex):', encrypted.toString('hex').substring(0, 64) + '...');
|
|
51
|
-
|
|
52
|
-
// Decrypt with receiver's private key
|
|
53
|
-
const decrypted = bsv.ECIES()
|
|
54
|
-
.privateKey(receiverPrivateKey)
|
|
55
|
-
.publicKey(senderPrivateKey.publicKey)
|
|
56
|
-
.decrypt(encrypted);
|
|
57
|
-
|
|
58
|
-
console.log('ā
Message decrypted successfully');
|
|
59
|
-
console.log('š Decrypted message:', decrypted.toString());
|
|
60
|
-
console.log('šÆ Match:', message === decrypted.toString() ? 'ā
SUCCESS' : 'ā FAILED');
|
|
61
|
-
console.log('');
|
|
62
|
-
|
|
63
|
-
// Test 2: JSON data encryption
|
|
64
|
-
console.log('š Test 2: JSON Data Encryption');
|
|
65
|
-
console.log('-------------------------------');
|
|
66
|
-
|
|
67
|
-
const jsonData = {
|
|
68
|
-
wallet: {
|
|
69
|
-
balance: 0.12345678,
|
|
70
|
-
transactions: ['tx1', 'tx2', 'tx3'],
|
|
71
|
-
lastUpdated: new Date().toISOString()
|
|
72
|
-
},
|
|
73
|
-
user: {
|
|
74
|
-
name: 'SmartLedger User',
|
|
75
|
-
preferences: { currency: 'BSV', notifications: true }
|
|
76
|
-
}
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
const jsonString = JSON.stringify(jsonData);
|
|
80
|
-
console.log('š Original JSON:', jsonString.substring(0, 100) + '...');
|
|
81
|
-
|
|
82
|
-
const encryptedJson = bsv.ECIES()
|
|
83
|
-
.privateKey(senderPrivateKey)
|
|
84
|
-
.publicKey(receiverPrivateKey.publicKey)
|
|
85
|
-
.encrypt(jsonString);
|
|
86
|
-
|
|
87
|
-
const decryptedJson = bsv.ECIES()
|
|
88
|
-
.privateKey(receiverPrivateKey)
|
|
89
|
-
.publicKey(senderPrivateKey.publicKey)
|
|
90
|
-
.decrypt(encryptedJson);
|
|
91
|
-
|
|
92
|
-
const parsedData = JSON.parse(decryptedJson.toString());
|
|
93
|
-
console.log('š° Decrypted wallet balance:', parsedData.wallet.balance);
|
|
94
|
-
console.log('š¤ Decrypted user name:', parsedData.user.name);
|
|
95
|
-
console.log('šÆ JSON integrity:', JSON.stringify(jsonData) === decryptedJson.toString() ? 'ā
SUCCESS' : 'ā FAILED');
|
|
96
|
-
console.log('');
|
|
97
|
-
|
|
98
|
-
// Test 3: Binary data encryption
|
|
99
|
-
console.log('š¢ Test 3: Binary Data Encryption');
|
|
100
|
-
console.log('---------------------------------');
|
|
101
|
-
|
|
102
|
-
const binaryData = Buffer.from([0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x42, 0x69, 0x6e, 0x61, 0x72, 0x79]);
|
|
103
|
-
console.log('š Original binary data:', binaryData.toString('hex'));
|
|
104
|
-
|
|
105
|
-
const encryptedBinary = bsv.ECIES()
|
|
106
|
-
.privateKey(senderPrivateKey)
|
|
107
|
-
.publicKey(receiverPrivateKey.publicKey)
|
|
108
|
-
.encrypt(binaryData);
|
|
109
|
-
|
|
110
|
-
const decryptedBinary = bsv.ECIES()
|
|
111
|
-
.privateKey(receiverPrivateKey)
|
|
112
|
-
.publicKey(senderPrivateKey.publicKey)
|
|
113
|
-
.decrypt(encryptedBinary);
|
|
114
|
-
|
|
115
|
-
console.log('š Decrypted binary data:', decryptedBinary.toString('hex'));
|
|
116
|
-
console.log('šÆ Binary integrity:', binaryData.equals(decryptedBinary) ? 'ā
SUCCESS' : 'ā FAILED');
|
|
117
|
-
console.log('');
|
|
118
|
-
|
|
119
|
-
// Test 4: Error handling
|
|
120
|
-
console.log('ā ļø Test 4: Error Handling');
|
|
121
|
-
console.log('-------------------------');
|
|
122
|
-
|
|
123
|
-
try {
|
|
124
|
-
// Try to decrypt with wrong key
|
|
125
|
-
const wrongKey = bsv.PrivateKey.fromRandom();
|
|
126
|
-
bsv.ECIES()
|
|
127
|
-
.privateKey(wrongKey)
|
|
128
|
-
.publicKey(senderPrivateKey.publicKey)
|
|
129
|
-
.decrypt(encrypted);
|
|
130
|
-
console.log('ā Should have thrown error for wrong key');
|
|
131
|
-
} catch (error) {
|
|
132
|
-
console.log('ā
Correctly caught decryption error:', error.message.substring(0, 50) + '...');
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
console.log('');
|
|
136
|
-
|
|
137
|
-
// Performance metrics
|
|
138
|
-
console.log('š Performance Metrics');
|
|
139
|
-
console.log('---------------------');
|
|
140
|
-
|
|
141
|
-
const iterations = 100;
|
|
142
|
-
const testMessage = 'Performance test message for ECIES encryption/decryption benchmarking.';
|
|
143
|
-
|
|
144
|
-
const startTime = Date.now();
|
|
145
|
-
|
|
146
|
-
for (let i = 0; i < iterations; i++) {
|
|
147
|
-
const enc = bsv.ECIES()
|
|
148
|
-
.privateKey(senderPrivateKey)
|
|
149
|
-
.publicKey(receiverPrivateKey.publicKey)
|
|
150
|
-
.encrypt(testMessage);
|
|
151
|
-
|
|
152
|
-
const dec = bsv.ECIES()
|
|
153
|
-
.privateKey(receiverPrivateKey)
|
|
154
|
-
.publicKey(senderPrivateKey.publicKey)
|
|
155
|
-
.decrypt(enc);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
const endTime = Date.now();
|
|
159
|
-
const totalTime = endTime - startTime;
|
|
160
|
-
const avgTime = totalTime / iterations;
|
|
161
|
-
|
|
162
|
-
console.log(`ā±ļø ${iterations} encrypt/decrypt cycles: ${totalTime}ms`);
|
|
163
|
-
console.log(`š Average per cycle: ${avgTime.toFixed(2)}ms`);
|
|
164
|
-
console.log(`š Operations per second: ${(1000 / avgTime).toFixed(0)}`);
|
|
165
|
-
|
|
166
|
-
} catch (error) {
|
|
167
|
-
console.error('ā Demo error:', error.message);
|
|
168
|
-
console.error('š Stack:', error.stack);
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
// Run the demo
|
|
173
|
-
demonstrateECIES().then(() => {
|
|
174
|
-
console.log('\nš ECIES Demo completed!');
|
|
175
|
-
console.log('');
|
|
176
|
-
console.log('š” Use Cases:');
|
|
177
|
-
console.log(' ⢠Secure messaging between BSV addresses');
|
|
178
|
-
console.log(' ⢠Encrypted data storage with public key access');
|
|
179
|
-
console.log(' ⢠Secure API communication');
|
|
180
|
-
console.log(' ⢠Privacy-preserving smart contracts');
|
|
181
|
-
console.log(' ⢠Encrypted blockchain data anchoring');
|
|
182
|
-
});
|
package/demos/gdaf_core_test.js
DELETED
|
@@ -1,131 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Simple GDAF Demo
|
|
3
|
-
*
|
|
4
|
-
* Tests core GDAF functionality without async verification issues
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
const bsv = require('../index.js')
|
|
8
|
-
|
|
9
|
-
console.log('š SmartLedger BSV GDAF - Core Components Test')
|
|
10
|
-
console.log('==============================================\n')
|
|
11
|
-
|
|
12
|
-
// Initialize GDAF
|
|
13
|
-
const gdaf = new bsv.GDAF()
|
|
14
|
-
|
|
15
|
-
try {
|
|
16
|
-
// 1. Create test identities
|
|
17
|
-
console.log('š Creating Test Identities')
|
|
18
|
-
const issuerPrivateKey = new bsv.PrivateKey()
|
|
19
|
-
const subjectPrivateKey = new bsv.PrivateKey()
|
|
20
|
-
|
|
21
|
-
const issuerDID = gdaf.createDID(issuerPrivateKey.toPublicKey())
|
|
22
|
-
const subjectDID = gdaf.createDID(subjectPrivateKey.toPublicKey())
|
|
23
|
-
|
|
24
|
-
console.log('ā
Issuer DID:', issuerDID)
|
|
25
|
-
console.log('ā
Subject DID:', subjectDID)
|
|
26
|
-
console.log()
|
|
27
|
-
|
|
28
|
-
// 2. Create credentials
|
|
29
|
-
console.log('š Creating Credentials')
|
|
30
|
-
|
|
31
|
-
const emailCredential = gdaf.createEmailCredential(
|
|
32
|
-
issuerDID,
|
|
33
|
-
subjectDID,
|
|
34
|
-
'user@example.com',
|
|
35
|
-
issuerPrivateKey
|
|
36
|
-
)
|
|
37
|
-
|
|
38
|
-
const ageCredential = gdaf.createAgeCredential(
|
|
39
|
-
issuerDID,
|
|
40
|
-
subjectDID,
|
|
41
|
-
21,
|
|
42
|
-
new Date('1995-06-15'),
|
|
43
|
-
issuerPrivateKey
|
|
44
|
-
)
|
|
45
|
-
|
|
46
|
-
console.log('ā
Email credential created with proof')
|
|
47
|
-
console.log('ā
Age credential created with proof')
|
|
48
|
-
console.log()
|
|
49
|
-
|
|
50
|
-
// 3. Schema validation
|
|
51
|
-
console.log('š Schema Validation')
|
|
52
|
-
|
|
53
|
-
const emailValidation = gdaf.validateCredential(emailCredential, 'EmailVerifiedCredential')
|
|
54
|
-
const ageValidation = gdaf.validateCredential(ageCredential, 'AgeVerifiedCredential')
|
|
55
|
-
|
|
56
|
-
console.log('ā
Email validation:', emailValidation.valid ? 'PASSED' : 'FAILED')
|
|
57
|
-
console.log('ā
Age validation:', ageValidation.valid ? 'PASSED' : 'FAILED')
|
|
58
|
-
console.log()
|
|
59
|
-
|
|
60
|
-
// 4. Zero-knowledge proofs
|
|
61
|
-
console.log('š Zero-Knowledge Proofs')
|
|
62
|
-
|
|
63
|
-
const nonce = gdaf.generateNonce()
|
|
64
|
-
|
|
65
|
-
// Selective disclosure proof
|
|
66
|
-
const selectiveProof = gdaf.generateSelectiveProof(
|
|
67
|
-
emailCredential,
|
|
68
|
-
['credentialSubject.verified'],
|
|
69
|
-
nonce
|
|
70
|
-
)
|
|
71
|
-
|
|
72
|
-
console.log('ā
Selective disclosure proof generated')
|
|
73
|
-
console.log(' - Proof type:', selectiveProof.type)
|
|
74
|
-
console.log(' - Disclosed fields:', selectiveProof.disclosedFields.length)
|
|
75
|
-
console.log(' - Merkle proofs:', selectiveProof.merkleProofs.length)
|
|
76
|
-
|
|
77
|
-
// Age proof
|
|
78
|
-
const ageProof = gdaf.generateAgeProof(ageCredential, 18, nonce)
|
|
79
|
-
|
|
80
|
-
console.log('ā
Age proof generated')
|
|
81
|
-
console.log(' - Minimum age:', ageProof.minimumAge)
|
|
82
|
-
console.log(' - Meets requirement:', ageProof.meetsRequirement)
|
|
83
|
-
|
|
84
|
-
// Verify age proof
|
|
85
|
-
const ageProofVerification = gdaf.verifyAgeProof(ageProof, 18, issuerDID)
|
|
86
|
-
console.log('ā
Age proof verification:', ageProofVerification ? 'PASSED' : 'FAILED')
|
|
87
|
-
console.log()
|
|
88
|
-
|
|
89
|
-
// 5. Available schemas
|
|
90
|
-
console.log('š Available Schema Types')
|
|
91
|
-
const allSchemas = gdaf.getAllSchemas()
|
|
92
|
-
const schemaNames = Object.keys(allSchemas)
|
|
93
|
-
|
|
94
|
-
console.log('ā
Schema count:', schemaNames.length)
|
|
95
|
-
console.log('ā
Available types:', schemaNames.join(', '))
|
|
96
|
-
console.log()
|
|
97
|
-
|
|
98
|
-
// 6. Template generation
|
|
99
|
-
console.log('š Template Generation')
|
|
100
|
-
|
|
101
|
-
const emailTemplate = gdaf.createTemplate('EmailVerifiedCredential')
|
|
102
|
-
const kycTemplate = gdaf.createTemplate('KYCVerifiedCredential')
|
|
103
|
-
|
|
104
|
-
console.log('ā
Email template generated')
|
|
105
|
-
console.log('ā
KYC template generated')
|
|
106
|
-
console.log()
|
|
107
|
-
|
|
108
|
-
// 7. Framework info
|
|
109
|
-
console.log('ā¹ļø Framework Information')
|
|
110
|
-
const info = gdaf.getInfo()
|
|
111
|
-
console.log('ā
Name:', info.name)
|
|
112
|
-
console.log('ā
Version:', info.version)
|
|
113
|
-
console.log('ā
Standards:', info.standards.length, 'standards supported')
|
|
114
|
-
console.log('ā
Components:', Object.keys(info.components).length, 'components')
|
|
115
|
-
console.log()
|
|
116
|
-
|
|
117
|
-
console.log('š GDAF Core Components Test: SUCCESS!')
|
|
118
|
-
console.log('\nā
All tested components are working correctly:')
|
|
119
|
-
console.log(' ā DID Creation and Resolution')
|
|
120
|
-
console.log(' ā Credential Creation and Signing')
|
|
121
|
-
console.log(' ā Schema Validation')
|
|
122
|
-
console.log(' ā Zero-Knowledge Proof Generation')
|
|
123
|
-
console.log(' ā Age Proof Verification')
|
|
124
|
-
console.log(' ā Template Generation')
|
|
125
|
-
console.log(' ā Framework Information')
|
|
126
|
-
|
|
127
|
-
} catch (error) {
|
|
128
|
-
console.error('ā GDAF Core Test failed:', error.message)
|
|
129
|
-
console.error('Stack trace:', error.stack)
|
|
130
|
-
process.exit(1)
|
|
131
|
-
}
|