-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-testnet-key.js
More file actions
58 lines (46 loc) · 1.8 KB
/
generate-testnet-key.js
File metadata and controls
58 lines (46 loc) · 1.8 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
// Generate a testnet private key and address for testing
const crypto = require('crypto');
const secp256k1 = require('secp256k1');
const bs58check = require('bs58check');
const { createHash } = require('crypto');
function ripemd160(buffer) {
return createHash('ripemd160').update(buffer).digest();
}
function sha256(buffer) {
return createHash('sha256').update(buffer).digest();
}
function generateTestnetAddress() {
// Generate random private key
let privateKey;
do {
privateKey = crypto.randomBytes(32);
} while (!secp256k1.privateKeyVerify(privateKey));
// Get public key (compressed)
const publicKey = Buffer.from(secp256k1.publicKeyCreate(privateKey, true));
// Hash public key: SHA256 then RIPEMD160
const sha = sha256(publicKey);
const hash160 = ripemd160(sha);
// Add testnet P2PKH prefix (0x1D 0x25 for testnet 'tm' addresses)
const payload = Buffer.concat([Buffer.from([0x1D, 0x25]), hash160]);
// Encode with base58check
const address = bs58check.default.encode(payload);
return {
privateKey: privateKey.toString('hex'),
publicKey: publicKey.toString('hex'),
address: address
};
}
console.log('🔑 Zcash Testnet Address Generator\n');
const wallet = generateTestnetAddress();
console.log('✅ Generated Testnet Wallet:');
console.log('─'.repeat(60));
console.log('Private Key:', wallet.privateKey);
console.log('Public Key: ', wallet.publicKey);
console.log('Address: ', wallet.address);
console.log('─'.repeat(60));
console.log('\n⚠️ IMPORTANT:');
console.log('1. Save the private key securely (for signing)');
console.log('2. Use the address to receive testnet ZEC from faucet');
console.log('3. Never use this for mainnet!');
console.log('\n📍 Testnet Faucet: https://faucet.zecpages.com/');
console.log(' Paste your address:', wallet.address);