@smartledger/bsv 3.4.3 ā 3.4.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 +321 -0
- package/README.md +72 -72
- package/SECURITY.md +88 -0
- package/bin/cli.js +13 -8
- package/bsv-covenant.min.js +4 -4
- package/bsv-gdaf.min.js +5 -5
- package/bsv-ltp.min.js +7 -7
- package/bsv-smartcontract.min.js +5 -5
- package/bsv.bundle.js +5 -5
- package/bsv.d.ts +486 -9
- package/bsv.min.js +5 -5
- package/docs/COVENANT_DEVELOPMENT_RESOLVED.md +2 -2
- package/docs/MODULE_REFERENCE_COMPLETE.md +60 -57
- package/docs/advanced/UTXO_MANAGER_GUIDE.md +1 -1
- package/docs/getting-started/INSTALLATION.md +30 -30
- package/docs/getting-started/QUICK_START.md +14 -14
- package/docs/migration/FROM_BSV_1_5_6.md +5 -5
- package/gdaf-entry.js +1 -2
- package/index.js +20 -7
- package/lib/smart_contract/covenant.js +10 -1
- package/lib/smartutxo.js +20 -12
- package/lib/transaction/transaction.js +7 -0
- package/ltp-entry.js +1 -2
- package/package.json +3 -3
- 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_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/legacy/README.md +0 -11
- package/examples/legacy/smart_contract_test_integration.js +0 -269
- package/examples/legacy/test_builtin_verify.js +0 -117
- package/examples/legacy/test_debug_integration.js +0 -71
- package/examples/legacy/test_ecdsa_little.js +0 -70
- package/examples/legacy/test_shamir.js +0 -221
- package/examples/legacy/test_smartverify_der.js +0 -110
- 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/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/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_demo.js
DELETED
|
@@ -1,237 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* GDAF (Global Digital Attestation Framework) Demo
|
|
3
|
-
*
|
|
4
|
-
* Demonstrates the complete GDAF workflow including:
|
|
5
|
-
* - DID creation and resolution
|
|
6
|
-
* - Credential creation and signing
|
|
7
|
-
* - Zero-knowledge proofs
|
|
8
|
-
* - Blockchain anchoring
|
|
9
|
-
* - Schema validation
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
const bsv = require('../index.js')
|
|
13
|
-
|
|
14
|
-
console.log('š SmartLedger BSV Global Digital Attestation Framework Demo')
|
|
15
|
-
console.log('=========================================================\n')
|
|
16
|
-
|
|
17
|
-
// Initialize GDAF
|
|
18
|
-
const gdaf = new bsv.GDAF()
|
|
19
|
-
|
|
20
|
-
console.log('š Framework Information:')
|
|
21
|
-
console.log(JSON.stringify(gdaf.getInfo(), null, 2))
|
|
22
|
-
console.log('\n')
|
|
23
|
-
|
|
24
|
-
try {
|
|
25
|
-
// 1. Create test identities
|
|
26
|
-
console.log('š Step 1: Creating Test Identities')
|
|
27
|
-
console.log('----------------------------------')
|
|
28
|
-
|
|
29
|
-
const issuerPrivateKey = new bsv.PrivateKey()
|
|
30
|
-
const subjectPrivateKey = new bsv.PrivateKey()
|
|
31
|
-
const verifierPrivateKey = new bsv.PrivateKey()
|
|
32
|
-
|
|
33
|
-
const issuerDID = gdaf.createDID(issuerPrivateKey.toPublicKey())
|
|
34
|
-
const subjectDID = gdaf.createDID(subjectPrivateKey.toPublicKey())
|
|
35
|
-
const verifierDID = gdaf.createDID(verifierPrivateKey.toPublicKey())
|
|
36
|
-
|
|
37
|
-
console.log('Issuer DID:', issuerDID)
|
|
38
|
-
console.log('Subject DID:', subjectDID)
|
|
39
|
-
console.log('Verifier DID:', verifierDID)
|
|
40
|
-
console.log()
|
|
41
|
-
|
|
42
|
-
// 2. Resolve DID documents
|
|
43
|
-
console.log('š Step 2: DID Document Resolution')
|
|
44
|
-
console.log('----------------------------------')
|
|
45
|
-
|
|
46
|
-
const issuerDocument = gdaf.resolveDID(issuerDID)
|
|
47
|
-
const subjectDocument = gdaf.resolveDID(subjectDID)
|
|
48
|
-
|
|
49
|
-
console.log('Issuer DID Document:')
|
|
50
|
-
console.log(JSON.stringify(issuerDocument, null, 2))
|
|
51
|
-
console.log('\nSubject DID Document:')
|
|
52
|
-
console.log(JSON.stringify(subjectDocument, null, 2))
|
|
53
|
-
console.log()
|
|
54
|
-
|
|
55
|
-
// 3. Create credentials
|
|
56
|
-
console.log('š Step 3: Credential Creation')
|
|
57
|
-
console.log('------------------------------')
|
|
58
|
-
|
|
59
|
-
// Email credential
|
|
60
|
-
const emailCredential = gdaf.createEmailCredential(
|
|
61
|
-
issuerDID,
|
|
62
|
-
subjectDID,
|
|
63
|
-
'user@example.com',
|
|
64
|
-
issuerPrivateKey
|
|
65
|
-
)
|
|
66
|
-
|
|
67
|
-
// Age credential
|
|
68
|
-
const ageCredential = gdaf.createAgeCredential(
|
|
69
|
-
issuerDID,
|
|
70
|
-
subjectDID,
|
|
71
|
-
21,
|
|
72
|
-
new Date('1995-06-15'),
|
|
73
|
-
issuerPrivateKey
|
|
74
|
-
)
|
|
75
|
-
|
|
76
|
-
// KYC credential
|
|
77
|
-
const kycCredential = gdaf.createKYCCredential(
|
|
78
|
-
issuerDID,
|
|
79
|
-
subjectDID,
|
|
80
|
-
'enhanced',
|
|
81
|
-
{
|
|
82
|
-
firstNameHash: gdaf.hashData('John'),
|
|
83
|
-
lastNameHash: gdaf.hashData('Doe'),
|
|
84
|
-
ssnHash: gdaf.hashData('123-45-6789')
|
|
85
|
-
},
|
|
86
|
-
issuerPrivateKey
|
|
87
|
-
)
|
|
88
|
-
|
|
89
|
-
console.log('Email Credential:')
|
|
90
|
-
console.log(JSON.stringify(emailCredential, null, 2))
|
|
91
|
-
console.log('\nAge Credential:')
|
|
92
|
-
console.log(JSON.stringify(ageCredential, null, 2))
|
|
93
|
-
console.log('\nKYC Credential:')
|
|
94
|
-
console.log(JSON.stringify(kycCredential, null, 2))
|
|
95
|
-
console.log()
|
|
96
|
-
|
|
97
|
-
// 4. Schema validation
|
|
98
|
-
console.log('ā
Step 4: Schema Validation')
|
|
99
|
-
console.log('----------------------------')
|
|
100
|
-
|
|
101
|
-
const emailValidation = gdaf.validateCredential(emailCredential, 'EmailVerifiedCredential')
|
|
102
|
-
const ageValidation = gdaf.validateCredential(ageCredential, 'AgeVerifiedCredential')
|
|
103
|
-
const kycValidation = gdaf.validateCredential(kycCredential, 'KYCVerifiedCredential')
|
|
104
|
-
|
|
105
|
-
console.log('Email Validation:', emailValidation)
|
|
106
|
-
console.log('Age Validation:', ageValidation)
|
|
107
|
-
console.log('KYC Validation:', kycValidation)
|
|
108
|
-
console.log()
|
|
109
|
-
|
|
110
|
-
// 5. Credential verification
|
|
111
|
-
console.log('š Step 5: Credential Verification')
|
|
112
|
-
console.log('----------------------------------')
|
|
113
|
-
|
|
114
|
-
const emailVerification = gdaf.verifyCredential(emailCredential, {
|
|
115
|
-
checkSignature: true,
|
|
116
|
-
checkIssuer: true,
|
|
117
|
-
checkExpiration: true
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
const ageVerification = gdaf.verifyCredential(ageCredential, {
|
|
121
|
-
checkSignature: true,
|
|
122
|
-
checkIssuer: true,
|
|
123
|
-
checkExpiration: true
|
|
124
|
-
})
|
|
125
|
-
|
|
126
|
-
console.log('Email Verification:', emailVerification)
|
|
127
|
-
console.log('Age Verification:', ageVerification)
|
|
128
|
-
console.log()
|
|
129
|
-
|
|
130
|
-
// 6. Zero-knowledge proofs
|
|
131
|
-
console.log('š Step 6: Zero-Knowledge Proofs')
|
|
132
|
-
console.log('--------------------------------')
|
|
133
|
-
|
|
134
|
-
const nonce = gdaf.generateNonce()
|
|
135
|
-
|
|
136
|
-
// Selective disclosure proof
|
|
137
|
-
const selectiveProof = gdaf.generateSelectiveProof(
|
|
138
|
-
emailCredential,
|
|
139
|
-
['credentialSubject.verified'],
|
|
140
|
-
nonce
|
|
141
|
-
)
|
|
142
|
-
|
|
143
|
-
console.log('Selective Disclosure Proof:')
|
|
144
|
-
console.log(JSON.stringify(selectiveProof, null, 2))
|
|
145
|
-
|
|
146
|
-
// Age proof
|
|
147
|
-
const ageProof = gdaf.generateAgeProof(ageCredential, 18, nonce)
|
|
148
|
-
|
|
149
|
-
console.log('\nAge Proof (over 18):')
|
|
150
|
-
console.log(JSON.stringify(ageProof, null, 2))
|
|
151
|
-
|
|
152
|
-
// Verify proofs
|
|
153
|
-
const selectiveVerification = gdaf.verifySelectiveProof(selectiveProof, {
|
|
154
|
-
nonce: nonce,
|
|
155
|
-
issuerDID: issuerDID
|
|
156
|
-
})
|
|
157
|
-
|
|
158
|
-
const ageProofVerification = gdaf.verifyAgeProof(ageProof, 18, issuerDID)
|
|
159
|
-
|
|
160
|
-
console.log('\nSelective Proof Verification:', selectiveVerification)
|
|
161
|
-
console.log('Age Proof Verification:', ageProofVerification)
|
|
162
|
-
console.log()
|
|
163
|
-
|
|
164
|
-
// 7. Verifiable presentation
|
|
165
|
-
console.log('š Step 7: Verifiable Presentation')
|
|
166
|
-
console.log('----------------------------------')
|
|
167
|
-
|
|
168
|
-
const presentation = gdaf.createPresentation(
|
|
169
|
-
[emailCredential, ageCredential],
|
|
170
|
-
subjectDID,
|
|
171
|
-
subjectPrivateKey,
|
|
172
|
-
{
|
|
173
|
-
challenge: nonce,
|
|
174
|
-
domain: 'example.com'
|
|
175
|
-
}
|
|
176
|
-
)
|
|
177
|
-
|
|
178
|
-
console.log('Verifiable Presentation:')
|
|
179
|
-
console.log(JSON.stringify(presentation, null, 2))
|
|
180
|
-
|
|
181
|
-
const presentationVerification = gdaf.verifyPresentation(presentation, {
|
|
182
|
-
challenge: nonce,
|
|
183
|
-
domain: 'example.com'
|
|
184
|
-
})
|
|
185
|
-
|
|
186
|
-
console.log('\nPresentation Verification:', presentationVerification)
|
|
187
|
-
console.log()
|
|
188
|
-
|
|
189
|
-
// 8. Extract claims
|
|
190
|
-
console.log('š Step 8: Claims Extraction')
|
|
191
|
-
console.log('----------------------------')
|
|
192
|
-
|
|
193
|
-
const claims = gdaf.extractClaims([emailCredential, ageCredential, kycCredential])
|
|
194
|
-
|
|
195
|
-
console.log('Extracted Claims:')
|
|
196
|
-
console.log(JSON.stringify(claims, null, 2))
|
|
197
|
-
console.log()
|
|
198
|
-
|
|
199
|
-
// 9. Schema templates
|
|
200
|
-
console.log('š Step 9: Schema Templates')
|
|
201
|
-
console.log('---------------------------')
|
|
202
|
-
|
|
203
|
-
const emailTemplate = gdaf.createTemplate('EmailVerifiedCredential')
|
|
204
|
-
const orgTemplate = gdaf.createTemplate('OrganizationCredential')
|
|
205
|
-
|
|
206
|
-
console.log('Email Credential Template:')
|
|
207
|
-
console.log(JSON.stringify(emailTemplate, null, 2))
|
|
208
|
-
console.log('\nOrganization Credential Template:')
|
|
209
|
-
console.log(JSON.stringify(orgTemplate, null, 2))
|
|
210
|
-
console.log()
|
|
211
|
-
|
|
212
|
-
// 10. Available schemas
|
|
213
|
-
console.log('š Step 10: Available Schemas')
|
|
214
|
-
console.log('-----------------------------')
|
|
215
|
-
|
|
216
|
-
const allSchemas = gdaf.getAllSchemas()
|
|
217
|
-
const schemaNames = Object.keys(allSchemas)
|
|
218
|
-
|
|
219
|
-
console.log('Available Schema Types:', schemaNames)
|
|
220
|
-
console.log()
|
|
221
|
-
|
|
222
|
-
console.log('ā
GDAF Demo completed successfully!')
|
|
223
|
-
console.log('\nš All GDAF components are working correctly:')
|
|
224
|
-
console.log(' ā DID Resolution')
|
|
225
|
-
console.log(' ā Credential Creation & Signing')
|
|
226
|
-
console.log(' ā Schema Validation')
|
|
227
|
-
console.log(' ā Credential Verification')
|
|
228
|
-
console.log(' ā Zero-Knowledge Proofs')
|
|
229
|
-
console.log(' ā Verifiable Presentations')
|
|
230
|
-
console.log(' ā Claims Extraction')
|
|
231
|
-
console.log(' ā Template Generation')
|
|
232
|
-
|
|
233
|
-
} catch (error) {
|
|
234
|
-
console.error('ā GDAF Demo failed:', error.message)
|
|
235
|
-
console.error('Stack trace:', error.stack)
|
|
236
|
-
process.exit(1)
|
|
237
|
-
}
|