Skip to content

Commit c4c79dc

Browse files
committed
WIP: library
1 parent f919573 commit c4c79dc

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

dashgov.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ var DashGov = ("object" === typeof module && exports) || {};
7373
// Adapted from
7474
// github.com/dashpay/dash/tree/develop/src/governance/common.cpp
7575

76-
// USAGE
77-
// node ./gobject-hash-debugger.js
76+
let Crypto = globalThis.crypto;
7877

7978
const LITTLE_ENDIAN = true;
8079
const VARINT_8_MAX = 252;
@@ -459,6 +458,17 @@ var DashGov = ("object" === typeof module && exports) || {};
459458
return ms;
460459
};
461460

461+
/**
462+
* @param {Uint8Array} gobjBytes - serialized gobj bytes
463+
*/
464+
GObj.proposal.doubleSha256 = async function (gobjBytes) {
465+
let hash1 = await Crypto.subtle.digest("SHA-256", gobjBytes);
466+
let hash2 = await Crypto.subtle.digest("SHA-256", hash1);
467+
let gobjHash = new Uint8Array(hash2);
468+
469+
return gobjHash;
470+
};
471+
462472
/**
463473
* Note: since we're dealing with estimates that are typically reliable
464474
* within an hour (and often even within 15 minutes), this may
@@ -526,8 +536,8 @@ var DashGov = ("object" === typeof module && exports) || {};
526536

527537
/**
528538
* @param {Snapshot} snapshot
529-
* @param {Float64} [secondsPerBlock]
530-
* @param {Uint53} offset - how many superblocks in the future
539+
* @param {Float64} secondsPerBlock
540+
* @param {Uint53} [offset] - how many superblocks in the future
531541
* @returns {Estimate} - details about the current governance cycle
532542
*/
533543
GObj.estimateNthNextGovCycle = function (

0 commit comments

Comments
 (0)