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)
This commit is contained in:
sairajzero 2023-03-08 03:13:36 +05:30
parent 2e24f024d1
commit b16473f982

View File

@ -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)