@moneypot/hub 1.3.0-dev.13 → 1.3.0-dev.14
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.
|
@@ -6,6 +6,7 @@ import { DbHashKind, exactlyOneRow, maybeOneRow, superuserPool, withPgPoolTransa
|
|
|
6
6
|
import { assert } from "tsafe";
|
|
7
7
|
import { dbInsertHubHash, dbLockHubHashChain, } from "../hash-chain/db-hash-chain.js";
|
|
8
8
|
import { getIntermediateHash, getPreimageHash, } from "../hash-chain/get-hash.js";
|
|
9
|
+
import { createHmac } from "node:crypto";
|
|
9
10
|
const FLOAT_EPSILON = 1e-10;
|
|
10
11
|
function sum(ns) {
|
|
11
12
|
return ns.reduce((a, b) => a + b, 0);
|
|
@@ -239,7 +240,18 @@ export function MakeOutcomeBetPlugin({ betConfigs }) {
|
|
|
239
240
|
if (result.rowCount !== 1) {
|
|
240
241
|
throw new GraphQLError("Failed to update hash chain iteration");
|
|
241
242
|
}
|
|
242
|
-
const
|
|
243
|
+
const finalHash = (() => {
|
|
244
|
+
const serverHash = betHashResult.hash;
|
|
245
|
+
const clientSeed = dbHashChain.client_seed;
|
|
246
|
+
const finalHash = createHmac("sha256", serverHash)
|
|
247
|
+
.update(clientSeed)
|
|
248
|
+
.digest();
|
|
249
|
+
return finalHash;
|
|
250
|
+
})();
|
|
251
|
+
const { outcome, outcomeIdx } = pickRandomOutcome({
|
|
252
|
+
outcomes: input.outcomes,
|
|
253
|
+
hash: finalHash,
|
|
254
|
+
});
|
|
243
255
|
const netPlayerAmount = input.wager * outcome.profit;
|
|
244
256
|
await pgClient.query({
|
|
245
257
|
text: `
|
|
@@ -377,7 +389,7 @@ function normalizeHash(hash) {
|
|
|
377
389
|
const uint32Value = view.getUint32(0, false);
|
|
378
390
|
return uint32Value / Math.pow(2, 32);
|
|
379
391
|
}
|
|
380
|
-
function pickRandomOutcome(outcomes, hash) {
|
|
392
|
+
function pickRandomOutcome({ outcomes, hash, }) {
|
|
381
393
|
assert(outcomes.length >= 2, "Outcome count must be >= 2");
|
|
382
394
|
const totalWeight = sum(outcomes.map((o) => o.weight));
|
|
383
395
|
const outcomesWithProbability = outcomes.map((o) => ({
|