@actuallyfair/verifier 0.0.5 → 0.0.6

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.
@@ -2,7 +2,6 @@ import { Currency } from "./generated/currency";
2
2
  import { FairCoinToss, FairCoinToss_Choice } from "./generated/context/fair-coin-toss";
3
3
  import { CrashDice } from "./generated/context/crash-dice";
4
4
  import { MultiRoulette } from "./generated/context/multi-roulette";
5
- import { Plinko } from "./generated/context/plinko";
6
5
  export declare function computeFairCoinTossResult(sig: Uint8Array): FairCoinToss_Choice.HEADS | FairCoinToss_Choice.TAILS;
7
6
  export declare function computeFairCoinTossOutcome(sig: Uint8Array, w: FairCoinToss): {
8
7
  result: FairCoinToss_Choice;
@@ -11,7 +10,7 @@ export declare function computeFairCoinTossOutcome(sig: Uint8Array, w: FairCoinT
11
10
  amount: number;
12
11
  };
13
12
  };
14
- export declare function computeCrashResult(vxSignature: Uint8Array, gameHash: Uint8Array, // This is the hash of the next from the hash chain
13
+ export declare function computeCrashResult(hash: Uint8Array, gameHash: Uint8Array, // This is the hash of the next from the hash chain
15
14
  houseEdge?: number): number;
16
15
  export type CrashDiceOutcome = {
17
16
  multiplier: number;
@@ -20,8 +19,8 @@ export type CrashDiceOutcome = {
20
19
  };
21
20
  export declare function computeCrashDiceResult(hash: Uint8Array, clientSeed: string): number;
22
21
  export declare function computeCrashDiceOutcome(hash: Uint8Array, clientSeed: string, bet: CrashDice): CrashDiceOutcome;
23
- export declare function computeMultiRouletteResult(vxSignature: Uint8Array, bet: MultiRoulette): number | undefined;
24
- export declare function computeMineLocations(vxSignature: Uint8Array, revealedCells: Set<number>, // tiles we know are safe
22
+ export declare function computeMultiRouletteResult(hash: Uint8Array, bet: MultiRoulette): number | undefined;
23
+ export declare function computeMineLocations(hash: Uint8Array, revealedCells: Set<number>, // tiles we know are safe
25
24
  cells: number, // how many cells in total
26
25
  mines: number): Set<number>;
27
26
  export declare function computeMinesMultiplier(mines: number, // how many mines in the game
@@ -30,13 +29,12 @@ turn: number, // which turn they have finished
30
29
  houseEdge?: number): number;
31
30
  type PlinkoPath = ("L" | "R")[];
32
31
  export declare function computePinkoPossibilityIndexFromPath(path: PlinkoPath): number;
33
- export declare function computePlinkoPath(vxSignature: Uint8Array, possibilities: number): PlinkoPath;
32
+ export declare function computePlinkoPath(hash: Uint8Array, possibilities: number): PlinkoPath;
34
33
  export declare function computePlinkoPascalsProbabilities(rowNumber: number): number[];
35
- export declare function computePlinkoHouseEdge(possibilities: number[]): number;
34
+ export declare function computePlinkoHouseEdge(payouts: number[]): number;
36
35
  export type PlinkoResult = {
37
36
  slot: number;
38
37
  multiplier: number;
39
- win: boolean;
40
38
  };
41
- export declare function computePlinkoResult(hash: Uint8Array, clientSeed: string, bet: Plinko): PlinkoResult;
39
+ export declare function computePlinkoResult(hash: Uint8Array, clientSeed: string, payouts: number[]): PlinkoResult;
42
40
  export {};
@@ -7,7 +7,6 @@ const utils_1 = require("@noble/curves/abstract/utils");
7
7
  const currency_1 = require("./generated/currency");
8
8
  const fair_coin_toss_1 = require("./generated/context/fair-coin-toss");
9
9
  const utils_2 = require("@noble/hashes/utils");
10
- const duel_plinko_payouts_1 = require("./duel-plinko-payouts");
11
10
  function computeFairCoinTossResult(sig) {
12
11
  // We're going to hash the signature just to really be sure its fairly distributed
13
12
  const hash = (0, sha256_1.sha256)(sig);
@@ -42,9 +41,9 @@ function doComputeCrashResult(hash, houseEdge) {
42
41
  result = Math.max(1, result);
43
42
  return result;
44
43
  }
45
- function computeCrashResult(vxSignature, gameHash, // This is the hash of the next from the hash chain
44
+ function computeCrashResult(hash, gameHash, // This is the hash of the next from the hash chain
46
45
  houseEdge = 0) {
47
- return doComputeCrashResult((0, hmac_1.hmac)(sha256_1.sha256, vxSignature, gameHash), houseEdge);
46
+ return doComputeCrashResult((0, hmac_1.hmac)(sha256_1.sha256, hash, gameHash), houseEdge);
48
47
  }
49
48
  exports.computeCrashResult = computeCrashResult;
50
49
  function computeCrashDiceResult(hash, clientSeed) {
@@ -63,10 +62,10 @@ function computeCrashDiceOutcome(hash, clientSeed, bet) {
63
62
  }
64
63
  exports.computeCrashDiceOutcome = computeCrashDiceOutcome;
65
64
  // returns the index of which roulette outcome was picked
66
- function computeMultiRouletteResult(vxSignature, bet) {
67
- const hash = (0, sha256_1.sha256)(vxSignature);
65
+ function computeMultiRouletteResult(hash, bet) {
66
+ const seedHash = (0, sha256_1.sha256)(hash);
68
67
  const nBits = 52;
69
- const hashHex = (0, utils_2.bytesToHex)(hash);
68
+ const hashHex = (0, utils_2.bytesToHex)(seedHash);
70
69
  const seed = hashHex.slice(0, nBits / 4);
71
70
  const n = Number.parseInt(seed, 16);
72
71
  const v = n / 2 ** nBits; // uniform in [0; 1)
@@ -79,7 +78,7 @@ function computeMultiRouletteResult(vxSignature, bet) {
79
78
  }
80
79
  }
81
80
  exports.computeMultiRouletteResult = computeMultiRouletteResult;
82
- function computeMineLocations(vxSignature, revealedCells, // tiles we know are safe
81
+ function computeMineLocations(hash, revealedCells, // tiles we know are safe
83
82
  cells, // how many cells in total
84
83
  mines // how many mines there are going to be in total
85
84
  ) {
@@ -90,7 +89,7 @@ mines // how many mines there are going to be in total
90
89
  console.warn("Trying to place more mines than there are available locations.");
91
90
  break;
92
91
  }
93
- let mineIndex = Number((0, utils_1.bytesToNumberBE)(vxSignature) % BigInt(cellsLeft));
92
+ let mineIndex = Number((0, utils_1.bytesToNumberBE)(hash) % BigInt(cellsLeft));
94
93
  let adjustedIndex = 0;
95
94
  for (let i = 0; i < cells; i++) {
96
95
  if (revealedCells.has(i) || mineLocations.has(i))
@@ -152,14 +151,14 @@ function computePinkoPossibilityIndexFromPath(path) {
152
151
  exports.computePinkoPossibilityIndexFromPath = computePinkoPossibilityIndexFromPath;
153
152
  // return a path (saying 'L' or 'R', where 'L' means go left, and 'R' means going right)
154
153
  // of possibilities-1 length
155
- function computePlinkoPath(vxSignature, possibilities) {
154
+ function computePlinkoPath(hash, possibilities) {
156
155
  if (!Number.isSafeInteger(possibilities) ||
157
156
  possibilities < 2 ||
158
157
  possibilities > 256) {
159
158
  throw new Error("invalid possibilities ");
160
159
  }
161
- const hash = (0, sha256_1.sha256)(vxSignature);
162
- let n = (0, utils_1.bytesToNumberBE)(hash);
160
+ const pathHash = (0, sha256_1.sha256)(hash);
161
+ let n = (0, utils_1.bytesToNumberBE)(pathHash);
163
162
  let ret = [];
164
163
  for (let i = 0; i < possibilities - 1; i++) {
165
164
  ret.push(n % 2n == 0n ? "R" : "L");
@@ -193,45 +192,30 @@ function computePlinkoPascalsProbabilities(rowNumber) {
193
192
  return lastRow.map((v) => v / sum);
194
193
  }
195
194
  exports.computePlinkoPascalsProbabilities = computePlinkoPascalsProbabilities;
196
- function computePlinkoHouseEdge(possibilities) {
197
- const odds = computePlinkoPascalsProbabilities(possibilities.length);
195
+ function computePlinkoHouseEdge(payouts) {
196
+ const odds = computePlinkoPascalsProbabilities(payouts.length);
198
197
  let ev = 1; // you start off by betting everything
199
- for (let i = 0; i < possibilities.length; i++) {
200
- ev -= possibilities[i] * odds[i];
198
+ for (let i = 0; i < payouts.length; i++) {
199
+ ev -= payouts[i] * odds[i];
201
200
  }
202
201
  return ev;
203
202
  }
204
203
  exports.computePlinkoHouseEdge = computePlinkoHouseEdge;
205
- function computePlinkoResult(hash, clientSeed, bet) {
206
- const possibilities = resolvePlinkoPayouts(bet);
207
- if (possibilities.length < 2) {
204
+ function computePlinkoResult(hash, clientSeed, payouts) {
205
+ if (payouts.length < 2) {
208
206
  throw new Error("invalid possibilities ");
209
207
  }
210
- const probabilities = computePlinkoPascalsProbabilities(possibilities.length);
208
+ const probabilities = computePlinkoPascalsProbabilities(payouts.length);
211
209
  const rollHash = hmacSha256(hash, clientSeed);
212
210
  const roll = uniformFromHash(rollHash);
213
211
  const slot = pickSlot(probabilities, roll);
214
- const multiplier = possibilities[slot] ?? 0;
212
+ const multiplier = payouts[slot] ?? 0;
215
213
  return {
216
214
  slot,
217
215
  multiplier,
218
- win: multiplier >= 1,
219
216
  };
220
217
  }
221
218
  exports.computePlinkoResult = computePlinkoResult;
222
- function resolvePlinkoPayouts(bet) {
223
- const payouts = bet.payouts;
224
- if (!payouts) {
225
- return [];
226
- }
227
- if (payouts.duel) {
228
- return (0, duel_plinko_payouts_1.getDuelPlinkoPayoutsFromEnum)(payouts.duel.rows, payouts.duel.risk);
229
- }
230
- if (payouts.custom) {
231
- return payouts.custom.possibilities;
232
- }
233
- return [];
234
- }
235
219
  function hmacSha256(key, message) {
236
220
  const data = new TextEncoder().encode(message);
237
221
  return (0, hmac_1.hmac)(sha256_1.sha256, key, data);
@@ -1,14 +1,18 @@
1
- import { DuelPlinkoRisk } from "./generated/context/plinko";
2
- export declare const DUEL_PLINKO_RISK_KEYS: readonly ["low", "medium", "high"];
3
- export type DuelPlinkoRiskKey = (typeof DUEL_PLINKO_RISK_KEYS)[number];
4
- export declare const DUEL_PLINKO_PAYOUTS: Record<number, Record<DuelPlinkoRiskKey, number[]>>;
5
- export declare const DUEL_PLINKO_ROWS: {
1
+ import { PlinkoPayoutTable } from "./generated/context/plinko";
2
+ export declare const PLINKO_RISK_KEYS: readonly ["low", "medium", "high"];
3
+ export type PlinkoRiskKey = (typeof PLINKO_RISK_KEYS)[number];
4
+ export declare const PLINKO_PAYOUT_TABLE_KEYS: readonly ["duel_8_low", "duel_8_medium", "duel_8_high", "duel_9_low", "duel_9_medium", "duel_9_high", "duel_10_low", "duel_10_medium", "duel_10_high", "duel_11_low", "duel_11_medium", "duel_11_high", "duel_12_low", "duel_12_medium", "duel_12_high", "duel_13_low", "duel_13_medium", "duel_13_high", "duel_14_low", "duel_14_medium", "duel_14_high", "duel_15_low", "duel_15_medium", "duel_15_high", "duel_16_low", "duel_16_medium", "duel_16_high"];
5
+ export type PlinkoPayoutTableKey = (typeof PLINKO_PAYOUT_TABLE_KEYS)[number];
6
+ export declare const PLINKO_PAYOUT_TABLES: Record<PlinkoPayoutTableKey, number[]>;
7
+ export declare const PLINKO_ROWS: {
6
8
  readonly min: number;
7
9
  readonly max: number;
8
10
  };
9
- export declare function getDuelPlinkoPayouts(rows: number, risk: DuelPlinkoRiskKey): number[];
10
- export declare function isDuelPlinkoRiskKey(value: string): value is DuelPlinkoRiskKey;
11
- export declare function isDuelPlinkoRows(rows: number): boolean;
12
- export declare function duelPlinkoRiskToEnum(value: DuelPlinkoRiskKey): DuelPlinkoRisk;
13
- export declare function duelPlinkoRiskFromEnum(value: DuelPlinkoRisk): DuelPlinkoRiskKey | null;
14
- export declare function getDuelPlinkoPayoutsFromEnum(rows: number, risk: DuelPlinkoRisk): number[];
11
+ export declare function isPlinkoRiskKey(value: string): value is PlinkoRiskKey;
12
+ export declare function isPlinkoRows(rows: number): boolean;
13
+ export declare function getPlinkoPayoutTableKey(rows: number, risk: PlinkoRiskKey): PlinkoPayoutTableKey | null;
14
+ export declare function getPlinkoPayouts(key: PlinkoPayoutTableKey): number[];
15
+ export declare function isPlinkoPayoutTableKey(value: string): value is PlinkoPayoutTableKey;
16
+ export declare function plinkoPayoutTableToEnum(value: PlinkoPayoutTableKey): PlinkoPayoutTable;
17
+ export declare function plinkoPayoutTableFromEnum(value: PlinkoPayoutTable): PlinkoPayoutTableKey | null;
18
+ export declare function getPlinkoPayoutsFromEnum(value: PlinkoPayoutTable): number[];