@actuallyfair/verifier 0.0.7 → 0.0.8
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.
- package/dist/compute-wager.d.ts +1 -10
- package/dist/compute-wager.js +5 -24
- package/package.json +1 -1
- package/src/compute-wager.ts +6 -39
package/dist/compute-wager.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Currency } from "./generated/currency";
|
|
2
2
|
import { FairCoinToss, FairCoinToss_Choice } from "./generated/context/fair-coin-toss";
|
|
3
|
-
import { CrashDice } from "./generated/context/crash-dice";
|
|
4
3
|
import { MultiRoulette } from "./generated/context/multi-roulette";
|
|
5
4
|
export type CompressedSeed = number;
|
|
6
5
|
export type RandomSource = Uint8Array;
|
|
@@ -22,15 +21,7 @@ export declare function computeFairCoinTossOutcome(randomSource: RandomSource, w
|
|
|
22
21
|
};
|
|
23
22
|
export declare function computeCrashResult(hash: Uint8Array, gameHash: Uint8Array, // This is the hash of the next from the hash chain
|
|
24
23
|
houseEdge?: number): number;
|
|
25
|
-
export
|
|
26
|
-
multiplier: number;
|
|
27
|
-
target: number;
|
|
28
|
-
win: boolean;
|
|
29
|
-
};
|
|
30
|
-
export declare function computeCrashDiceResultFromRandomSource(randomSource: RandomSource): number;
|
|
31
|
-
export declare function computeCrashDiceResult(hash: Uint8Array, clientSeed: string): number;
|
|
32
|
-
export declare function computeCrashDiceOutcomeFromRandomSource(randomSource: RandomSource, bet: CrashDice): CrashDiceOutcome;
|
|
33
|
-
export declare function computeCrashDiceOutcome(hash: Uint8Array, clientSeed: string, bet: CrashDice): CrashDiceOutcome;
|
|
24
|
+
export declare function computeCrashDiceResult(randomSource: RandomSource, houseEdge: number): number;
|
|
34
25
|
export declare function computeMultiRouletteResult(randomSource: RandomSource, bet: MultiRoulette): number | undefined;
|
|
35
26
|
export declare function computeMineLocations(randomSource: RandomSource, revealedCells: Set<number>, // tiles we know are safe
|
|
36
27
|
cells: number, // how many cells in total
|
package/dist/compute-wager.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.computePlinkoResult = exports.computePlinkoResultFromRandomSource = exports.computePlinkoHouseEdge = exports.computePlinkoPascalsProbabilities = exports.computePlinkoPath = exports.computePinkoPossibilityIndexFromPath = exports.computeMinesMultiplier = exports.computeMineLocations = exports.computeMultiRouletteResult = exports.
|
|
3
|
+
exports.computePlinkoResult = exports.computePlinkoResultFromRandomSource = exports.computePlinkoHouseEdge = exports.computePlinkoPascalsProbabilities = exports.computePlinkoPath = exports.computePinkoPossibilityIndexFromPath = exports.computeMinesMultiplier = exports.computeMineLocations = exports.computeMultiRouletteResult = exports.computeCrashDiceResult = exports.computeCrashResult = exports.computeFairCoinTossOutcome = exports.computeFairCoinTossResult = exports.computeRandomSource = exports.computeRandomSourceFromCompressedSeed = exports.computeCompressedSeedFromGameHash = exports.computeCompressedSeed = exports.splitHelixHash = void 0;
|
|
4
4
|
const sha256_1 = require("@noble/hashes/sha256");
|
|
5
5
|
const hmac_1 = require("@noble/hashes/hmac");
|
|
6
6
|
const utils_1 = require("@noble/curves/abstract/utils");
|
|
@@ -78,33 +78,14 @@ houseEdge = 0) {
|
|
|
78
78
|
return doComputeCrashResult((0, hmac_1.hmac)(sha256_1.sha256, hash, gameHash), houseEdge);
|
|
79
79
|
}
|
|
80
80
|
exports.computeCrashResult = computeCrashResult;
|
|
81
|
-
function
|
|
81
|
+
function computeCrashDiceResult(randomSource, houseEdge) {
|
|
82
82
|
const normalized = u32FromHash(randomSource);
|
|
83
83
|
const max = 2 ** 32;
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
exports.computeCrashDiceResultFromRandomSource = computeCrashDiceResultFromRandomSource;
|
|
88
|
-
function computeCrashDiceResult(hash, clientSeed) {
|
|
89
|
-
const randomSource = computeRandomSource(clientSeed, hash);
|
|
90
|
-
return computeCrashDiceResultFromRandomSource(randomSource);
|
|
84
|
+
let result = ((1 - houseEdge) * max) / (max - normalized);
|
|
85
|
+
result = Math.floor(result * 100) / 100;
|
|
86
|
+
return Math.max(1, result);
|
|
91
87
|
}
|
|
92
88
|
exports.computeCrashDiceResult = computeCrashDiceResult;
|
|
93
|
-
function computeCrashDiceOutcomeFromRandomSource(randomSource, bet) {
|
|
94
|
-
const multiplier = computeCrashDiceResultFromRandomSource(randomSource);
|
|
95
|
-
const target = bet.target;
|
|
96
|
-
return {
|
|
97
|
-
multiplier,
|
|
98
|
-
target,
|
|
99
|
-
win: multiplier >= target,
|
|
100
|
-
};
|
|
101
|
-
}
|
|
102
|
-
exports.computeCrashDiceOutcomeFromRandomSource = computeCrashDiceOutcomeFromRandomSource;
|
|
103
|
-
function computeCrashDiceOutcome(hash, clientSeed, bet) {
|
|
104
|
-
const randomSource = computeRandomSource(clientSeed, hash);
|
|
105
|
-
return computeCrashDiceOutcomeFromRandomSource(randomSource, bet);
|
|
106
|
-
}
|
|
107
|
-
exports.computeCrashDiceOutcome = computeCrashDiceOutcome;
|
|
108
89
|
// returns the index of which roulette outcome was picked
|
|
109
90
|
function computeMultiRouletteResult(randomSource, bet) {
|
|
110
91
|
const seedHash = (0, sha256_1.sha256)(randomSource);
|
package/package.json
CHANGED
package/src/compute-wager.ts
CHANGED
|
@@ -12,7 +12,6 @@ import {
|
|
|
12
12
|
FairCoinToss_Choice,
|
|
13
13
|
} from "./generated/context/fair-coin-toss";
|
|
14
14
|
import { bytesToHex } from "@noble/hashes/utils";
|
|
15
|
-
import { CrashDice } from "./generated/context/crash-dice";
|
|
16
15
|
import { MultiRoulette } from "./generated/context/multi-roulette";
|
|
17
16
|
|
|
18
17
|
export type CompressedSeed = number;
|
|
@@ -120,47 +119,15 @@ export function computeCrashResult(
|
|
|
120
119
|
return doComputeCrashResult(hmac(sha256, hash, gameHash), houseEdge);
|
|
121
120
|
}
|
|
122
121
|
|
|
123
|
-
export
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
win: boolean;
|
|
127
|
-
};
|
|
128
|
-
|
|
129
|
-
export function computeCrashDiceResultFromRandomSource(
|
|
130
|
-
randomSource: RandomSource
|
|
122
|
+
export function computeCrashDiceResult(
|
|
123
|
+
randomSource: RandomSource,
|
|
124
|
+
houseEdge: number
|
|
131
125
|
) {
|
|
132
126
|
const normalized = u32FromHash(randomSource);
|
|
133
127
|
const max = 2 ** 32;
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
export function computeCrashDiceResult(hash: Uint8Array, clientSeed: string) {
|
|
139
|
-
const randomSource = computeRandomSource(clientSeed, hash);
|
|
140
|
-
return computeCrashDiceResultFromRandomSource(randomSource);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
export function computeCrashDiceOutcomeFromRandomSource(
|
|
144
|
-
randomSource: RandomSource,
|
|
145
|
-
bet: CrashDice
|
|
146
|
-
): CrashDiceOutcome {
|
|
147
|
-
const multiplier = computeCrashDiceResultFromRandomSource(randomSource);
|
|
148
|
-
const target = bet.target;
|
|
149
|
-
|
|
150
|
-
return {
|
|
151
|
-
multiplier,
|
|
152
|
-
target,
|
|
153
|
-
win: multiplier >= target,
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
export function computeCrashDiceOutcome(
|
|
158
|
-
hash: Uint8Array,
|
|
159
|
-
clientSeed: string,
|
|
160
|
-
bet: CrashDice
|
|
161
|
-
): CrashDiceOutcome {
|
|
162
|
-
const randomSource = computeRandomSource(clientSeed, hash);
|
|
163
|
-
return computeCrashDiceOutcomeFromRandomSource(randomSource, bet);
|
|
128
|
+
let result = ((1 - houseEdge) * max) / (max - normalized);
|
|
129
|
+
result = Math.floor(result * 100) / 100;
|
|
130
|
+
return Math.max(1, result);
|
|
164
131
|
}
|
|
165
132
|
|
|
166
133
|
// returns the index of which roulette outcome was picked
|