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:
parent
2e24f024d1
commit
b16473f982
31
floCrypto.js
31
floCrypto.js
@ -1,4 +1,4 @@
|
|||||||
(function (EXPORTS) { //floCrypto v2.3.5a
|
(function (EXPORTS) { //floCrypto v2.3.6
|
||||||
/* FLO Crypto Operators */
|
/* FLO Crypto Operators */
|
||||||
'use strict';
|
'use strict';
|
||||||
const floCrypto = EXPORTS;
|
const floCrypto = EXPORTS;
|
||||||
@ -152,6 +152,20 @@
|
|||||||
newID: {
|
newID: {
|
||||||
get: () => generateNewID()
|
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: {
|
tmpID: {
|
||||||
get: () => {
|
get: () => {
|
||||||
let bytes = Crypto.util.randomBytes(20);
|
let bytes = Crypto.util.randomBytes(20);
|
||||||
@ -323,6 +337,21 @@
|
|||||||
return bitjs.Base58.encode(raw.bytes.concat(hash.slice(0, 4)));
|
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
|
//Convert the given multisig address (any blockchain) to equivalent multisig floID
|
||||||
floCrypto.toMultisigFloID = function (address, options = null) {
|
floCrypto.toMultisigFloID = function (address, options = null) {
|
||||||
if (!address)
|
if (!address)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user