Changed around line 1
+ function generateWallet() {
+ const privateKey = generatePrivateKey();
+ const publicAddress = generatePublicAddress(privateKey);
+ document.getElementById('private-key').value = privateKey;
+ document.getElementById('public-address').value = publicAddress;
+ }
+
+ function generatePrivateKey() {
+ const array = new Uint8Array(32);
+ window.crypto.getRandomValues(array);
+ return Array.from(array, byte => byte.toString(16).padStart(2, '0')).join('');
+ }
+
+ function generatePublicAddress(privateKey) {
+ const sha256 = (data) => {
+ const buffer = new TextEncoder().encode(data);
+ return window.crypto.subtle.digest('SHA-256', buffer).then(hash => {
+ return Array.from(new Uint8Array(hash)).map(b => b.toString(16).padStart(2, '0')).join('');
+ });
+ };
+
+ const ripemd160 = (data) => {
+ const buffer = new TextEncoder().encode(data);
+ return window.crypto.subtle.digest('RIPEMD-160', buffer).then(hash => {
+ return Array.from(new Uint8Array(hash)).map(b => b.toString(16).padStart(2, '0')).join('');
+ });
+ };
+
+ return sha256(privateKey).then(hash => {
+ return ripemd160(hash);
+ }).then(hash => {
+ return '1' + hash;
+ });
+ }
+
+ document.getElementById('generate-wallet').addEventListener('click', generateWallet);