From 21d6c176694c354b893765da12957afb1b44de68 Mon Sep 17 00:00:00 2001 From: tripathyr Date: Sun, 15 Oct 2023 08:38:36 +0530 Subject: [PATCH] Create messengerEthereum.js Added basic Ethereum Address generation functions which can be generated without Taproot functions. Just with existing libraries, and addition of keccak.js, Ethereum addresses of the contacts that messenger communicates with will be achieved. However as of now, messages cannot nbe sent to Ethereum addresses. --- scripts/messengerEthereum.js | 40 ++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 scripts/messengerEthereum.js diff --git a/scripts/messengerEthereum.js b/scripts/messengerEthereum.js new file mode 100644 index 0000000..47f91d5 --- /dev/null +++ b/scripts/messengerEthereum.js @@ -0,0 +1,40 @@ +(function (EXPORTS) { //floEthereum v1.0.1a + /* FLO Ethereum Operators */ + /* Make sure you added Taproot, Keccak, FLO and BTC Libraries before */ + 'use strict'; + const floEthereum = EXPORTS; + +//This needs y point to be even always. If y point is odd, it wil be converted to even +const ethAddressFromPrivateKey = floEthereum.ethAddressFromPrivateKey = function(privateKey){ + var t1,t1_x,t1_y,t1_x_BigInt,t1_y_BigInt,t2,t3,t4; + var groupOrder = BigInt("0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F"); + + t1 = bitjs.newPubkey(privateKey); + t1_x = t1.slice(2, 66); t1_y = t1.slice(-64); + t1_x_BigInt = BigInt("0x"+t1_x);t1_y_BigInt = BigInt("0x"+t1_y); + if (t1_y_BigInt % 2n !== 0n) { t1_y_BigInt = (groupOrder-t1_y_BigInt)%groupOrder; t1_y=t1_y_BigInt.toString(16)}; + t2 = t1_x.toString(16) + t1_y.toString(16); + t3 = keccak.keccak_256(Crypto.util.hexToBytes(t2)); + t4 = keccak.extractLast20Bytes(t3); + return "0x" + t4; +} + +const ethAddressFromCompressedPublicKey = floEthereum.ethAddressFromCompressedPublicKey = function(compressedPublicKey){ + var t1,t2,t3,t4; + t1 = coinjs.compressedToUncompressed(compressedPublicKey); + t2 = t1.slice(2); + t3 = keccak.keccak_256(Crypto.util.hexToBytes(t2)); + t4 = keccak.extractLast20Bytes(t3); + return "0x" + t4; +} + +const ethAddressFromUncompressedPublicKey = floEthereum.ethAddressFromUncompressedPublicKey = function(unCompressedPublicKey){ + var t1,t2,t3,t4; + t1 = unCompressedPublicKey; + t2 = t1.slice(2); + t3 = keccak.keccak_256(Crypto.util.hexToBytes(t2)); + t4 = keccak.extractLast20Bytes(t3); + return "0x" + t4; +} + +})('object' === typeof module ? module.exports : window.floEthereum = {});