-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-proof-simple.js
More file actions
88 lines (77 loc) · 2.86 KB
/
test-proof-simple.js
File metadata and controls
88 lines (77 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Quick test of the proof generation
const { proposeTransaction, proveTransaction } = require('./dist/index.js');
const { randomBytes } = require('crypto');
const secp = require('secp256k1');
const { ripemd160 } = require('@noble/hashes/ripemd160');
const { sha256 } = require('@noble/hashes/sha256');
async function testProofGeneration() {
console.log('Starting proof generation test...');
// Generate a random key pair
const privKey = randomBytes(32);
const pubKey = secp.publicKeyCreate(privKey);
// Calculate P2PKH script
const pubKeyHash = ripemd160(sha256(pubKey));
const scriptPubKey = new Uint8Array([
0x76, 0xa9, 0x14,
...pubKeyHash,
0x88, 0xac,
]);
const inputs = [
[
{
txid: 'a'.repeat(64),
vout: 0,
sequence: 0xFFFFFFFF,
},
{
value: 100_000_000n,
scriptPubKey: scriptPubKey,
pubkey: pubKey,
txid: 'a'.repeat(64),
vout: 0,
},
],
];
const realUnifiedAddress = 'u1pg2aaph7jp8rpf6yhsza25722sg5fcn3vaca6ze27hqjw7jvvhhuxkpcg0ge9xh6drsgdkda8qjq5chpehkcpxf87rnjryjqwymdheptpvnljqqrjqzjwkc2ma6hcq666kgwfytxwac8eyex6ndgr6ezte66706e3vaqrd25dzvzkc69kw0jgywtd0cmq52q5lkw6uh7hyvzjse8ksx';
const request = {
payments: [{
address: realUnifiedAddress,
amount: 90_000_000n,
memo: Buffer.from('Test Orchard payment'),
}],
blockHeight: 2_500_000,
};
console.log('1. Proposing transaction...');
const pczt = await proposeTransaction(inputs, request);
console.log('✓ Transaction proposed');
console.log(' - Has Orchard bundle:', pczt.orchard !== null);
console.log(' - Transparent inputs:', pczt.transparent?.inputs?.length || 0);
console.log('\n2. Generating proofs (this may take 5-10 seconds)...');
console.time('Proof generation');
try {
const provedPczt = await proveTransaction(pczt);
console.timeEnd('Proof generation');
console.log('✓ Proofs generated successfully!');
console.log(' - Has Orchard proof:', provedPczt.orchard?.proof !== undefined && provedPczt.orchard?.proof !== null);
return true;
} catch (error) {
console.timeEnd('Proof generation');
console.error('✗ Proof generation failed:');
console.error(error.message);
return false;
}
}
testProofGeneration()
.then(success => {
if (success) {
console.log('\n🎉 SUCCESS! Proof generation is working!');
process.exit(0);
} else {
console.log('\n❌ FAILED! Proof generation is not working.');
process.exit(1);
}
})
.catch(error => {
console.error('\n❌ Unexpected error:', error);
process.exit(1);
});