From b16473f9822ad47acda894b9bac632f90ec2ea11 Mon Sep 17 00:00:00 2001 From: sairajzero Date: Wed, 8 Mar 2023 03:13:36 +0530 Subject: [PATCH] floCrypto v2.3.6 - Added hashID(str): returns a floID based on the hash of given string - Added rawToFloID(raw_bytes): return floID from the given raw_bytes (20 bytes) --- floCrypto.js | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/floCrypto.js b/floCrypto.js index ec41da4..894c640 100644 --- a/floCrypto.js +++ b/floCrypto.js @@ -1,4 +1,4 @@ -(function (EXPORTS) { //floCrypto v2.3.5a +(function (EXPORTS) { //floCrypto v2.3.6 /* FLO Crypto Operators */ 'use strict'; const floCrypto = EXPORTS; @@ -152,6 +152,20 @@ newID: { get: () => generateNewID() }, + hashID: { + value: (str) => { + let bytes = ripemd160(Crypto.SHA256(str, { asBytes: true }), { asBytes: true }); + console.debug(bytes); + bytes.unshift(bitjs.pub); + var hash = Crypto.SHA256(Crypto.SHA256(bytes, { + asBytes: true + }), { + asBytes: true + }); + var checksum = hash.slice(0, 4); + return bitjs.Base58.encode(bytes.concat(checksum)); + } + }, tmpID: { get: () => { let bytes = Crypto.util.randomBytes(20); @@ -323,6 +337,21 @@ return bitjs.Base58.encode(raw.bytes.concat(hash.slice(0, 4))); } + //Convert raw address bytes to floID + floCrypto.rawToFloID = function (raw_bytes) { + if (typeof raw_bytes === 'string') + raw_bytes = Crypto.util.hexToBytes(raw_bytes); + if (raw_bytes.length != 20) + return null; + raw_bytes.unshift(bitjs.pub); + let hash = Crypto.SHA256(Crypto.SHA256(raw_bytes, { + asBytes: true + }), { + asBytes: true + }); + return bitjs.Base58.encode(raw_bytes.concat(hash.slice(0, 4))); + } + //Convert the given multisig address (any blockchain) to equivalent multisig floID floCrypto.toMultisigFloID = function (address, options = null) { if (!address)