@moneypot/hub 1.4.9 → 1.4.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { dbLockHubHashChain, dbInsertHubHash } from "./db-hash-chain.js";
|
|
2
2
|
export type { HashResult } from "./get-hash.js";
|
|
3
3
|
export { getTerminalHash, getIntermediateHash, getPreimageHash, } from "./get-hash.js";
|
|
4
|
-
export { makeFinalHash,
|
|
4
|
+
export { makeFinalHash, normalizeHash } from "./util.js";
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export { dbLockHubHashChain, dbInsertHubHash } from "./db-hash-chain.js";
|
|
2
2
|
export { getTerminalHash, getIntermediateHash, getPreimageHash, } from "./get-hash.js";
|
|
3
|
-
export { makeFinalHash,
|
|
3
|
+
export { makeFinalHash, normalizeHash } from "./util.js";
|
|
@@ -3,8 +3,7 @@ export declare function makeFinalHash({ serverHash, clientSeed, }: {
|
|
|
3
3
|
serverHash: Uint8Array;
|
|
4
4
|
clientSeed: string;
|
|
5
5
|
}): Buffer<ArrayBufferLike>;
|
|
6
|
-
declare function normalizeHash(hash: Uint8Array): number;
|
|
7
|
-
export declare const getRollFromFinalHash: typeof normalizeHash;
|
|
6
|
+
export declare function normalizeHash(hash: Uint8Array): number;
|
|
8
7
|
export declare function pickRandomOutcome({ outcomes, finalHash, }: {
|
|
9
8
|
outcomes: readonly DbOutcome[];
|
|
10
9
|
finalHash: Uint8Array;
|
|
@@ -12,4 +11,3 @@ export declare function pickRandomOutcome({ outcomes, finalHash, }: {
|
|
|
12
11
|
outcomeIdx: number;
|
|
13
12
|
roll: number;
|
|
14
13
|
};
|
|
15
|
-
export {};
|
|
@@ -6,13 +6,12 @@ export function makeFinalHash({ serverHash, clientSeed, }) {
|
|
|
6
6
|
.digest();
|
|
7
7
|
return finalHash;
|
|
8
8
|
}
|
|
9
|
-
function normalizeHash(hash) {
|
|
9
|
+
export function normalizeHash(hash) {
|
|
10
10
|
assert(hash.length >= 4, "Hash must be at least 4 bytes");
|
|
11
11
|
const view = new DataView(hash.buffer, hash.byteOffset, Math.min(hash.byteLength, 4));
|
|
12
12
|
const uint32Value = view.getUint32(0, false);
|
|
13
13
|
return uint32Value / Math.pow(2, 32);
|
|
14
14
|
}
|
|
15
|
-
export const getRollFromFinalHash = normalizeHash;
|
|
16
15
|
export function pickRandomOutcome({ outcomes, finalHash, }, floatEpsilon = 1e-10) {
|
|
17
16
|
assert(outcomes.length >= 2, "Outcome count must be >= 2");
|
|
18
17
|
const totalWeight = outcomes.reduce((sum, o) => sum + o.weight, 0);
|
|
@@ -22,7 +21,7 @@ export function pickRandomOutcome({ outcomes, finalHash, }, floatEpsilon = 1e-10
|
|
|
22
21
|
}));
|
|
23
22
|
const totalProb = outcomesWithProbability.reduce((sum, outcome) => sum + outcome.probability, 0);
|
|
24
23
|
assert(Math.abs(totalProb - 1.0) < floatEpsilon, "Probabilities must sum to ~1");
|
|
25
|
-
const roll =
|
|
24
|
+
const roll = normalizeHash(finalHash);
|
|
26
25
|
let cumulativeProb = 0;
|
|
27
26
|
for (let i = 0; i < outcomesWithProbability.length; i++) {
|
|
28
27
|
const outcome = outcomesWithProbability[i];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@moneypot/hub",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.10",
|
|
4
4
|
"author": "moneypot.com",
|
|
5
5
|
"homepage": "https://moneypot.com/hub",
|
|
6
6
|
"keywords": [
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"@types/node": "^22.1.0",
|
|
67
67
|
"@types/pg": "^8.11.5",
|
|
68
68
|
"eslint": "^9.8.0",
|
|
69
|
-
"globals": "^
|
|
69
|
+
"globals": "^16.0.0",
|
|
70
70
|
"typescript": "^5.4.5",
|
|
71
71
|
"typescript-eslint": "^8.0.1"
|
|
72
72
|
},
|