smartledger-bsv 3.3.3 → 3.3.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/CHANGELOG.md +20 -7
  2. package/README.md +18 -1
  3. package/bsv-covenant.min.js +5 -5
  4. package/bsv-gdaf.min.js +4 -4
  5. package/bsv-ltp.min.js +4 -4
  6. package/bsv-mnemonic.min.js +4 -4
  7. package/bsv-smartcontract.min.js +4 -4
  8. package/bsv.bundle.js +4 -4
  9. package/bsv.min.js +4 -4
  10. package/demos/README.md +188 -0
  11. package/demos/architecture_demo.js +247 -0
  12. package/demos/bsv_wallet_demo.js +242 -0
  13. package/demos/complete_ltp_demo.js +511 -0
  14. package/demos/debug_tools_demo.js +87 -0
  15. package/demos/demo_features.js +123 -0
  16. package/demos/easy_interface_demo.js +109 -0
  17. package/demos/ecies_demo.js +182 -0
  18. package/demos/gdaf_core_test.js +131 -0
  19. package/demos/gdaf_demo.js +237 -0
  20. package/demos/ltp_demo.js +361 -0
  21. package/demos/ltp_primitives_demo.js +403 -0
  22. package/demos/message_demo.js +209 -0
  23. package/demos/preimage_separation_demo.js +383 -0
  24. package/demos/script_helper_demo.js +289 -0
  25. package/demos/security_demo.js +287 -0
  26. package/demos/shamir_demo.js +121 -0
  27. package/demos/simple_demo.js +204 -0
  28. package/demos/simple_p2pkh_demo.js +169 -0
  29. package/demos/simple_utxo_preimage_demo.js +196 -0
  30. package/demos/smart_contract_demo.html +1347 -0
  31. package/demos/smart_contract_demo.js +910 -0
  32. package/demos/utxo_generator_demo.js +244 -0
  33. package/demos/validation_pipeline_demo.js +155 -0
  34. package/demos/web3keys.html +740 -0
  35. package/docs/BUNDLE_UPDATE_SUMMARY.md +40 -0
  36. package/docs/FIX_CREATEHMAC_ISSUE.md +91 -0
  37. package/docs/SMARTLEDGER_BSV_USAGE_ANSWERS.md +477 -0
  38. package/docs/SMARTLEDGER_BSV_USAGE_EXAMPLES.js +372 -0
  39. package/docs/SMARTLEDGER_BSV_USAGE_GUIDE.md +555 -0
  40. package/docs/SMART_CONTRACT_DEVELOPMENT_GUIDE.md +1459 -0
  41. package/examples/complete_workflow_demo.js +783 -0
  42. package/examples/definitive_working_demo.js +261 -0
  43. package/examples/final_working_contracts.js +338 -0
  44. package/examples/smart_contract_templates.js +718 -0
  45. package/examples/working_smart_contracts.js +348 -0
  46. package/lib/mnemonic/pbkdf2.browser.js +69 -0
  47. package/lib/mnemonic/pbkdf2.js +2 -68
  48. package/lib/mnemonic/pbkdf2.node.js +68 -0
  49. package/package.json +17 -6
  50. package/tests/browser-compatibility/README.md +35 -0
  51. package/tests/browser-compatibility/test-cdn-vs-local.html +186 -0
  52. package/tests/browser-compatibility/test-pbkdf2.html +51 -0
@@ -0,0 +1,123 @@
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.');
@@ -0,0 +1,109 @@
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
+ }
@@ -0,0 +1,182 @@
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
+ });
@@ -0,0 +1,131 @@
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
+ }