prizerail 1.2.1 → 1.3.1

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/README.md CHANGED
@@ -109,10 +109,10 @@ To answer a user who asks whether their entries counted, look them up in one dra
109
109
 
110
110
  ```ts
111
111
  const found = await campaign.drawings.entrant(drawingId, entrantId)
112
- // { entered, entries, position, receivedAt, drawn, winner }
112
+ // { entered, entries, position, receivedAt, drawn, winner, winners, totalCents }
113
113
  ```
114
114
 
115
- `entered` is false, not an error, for someone who isn't in the drawing. `winner` stays null for everyone until `drawn` is true. See [Look up an entrant](https://docs.prizerail.com/api/drawings#look-up-an-entrant).
115
+ `entered` is false, not an error, for someone who isn't in the drawing. `winner` stays null for everyone until `drawn` is true. In a campaign with repeat winners one entrant can win several slots, so credit users from `winners` or `totalCents`, not `winner` alone. See [Look up an entrant](https://docs.prizerail.com/api/drawings#look-up-an-entrant).
116
116
 
117
117
  ## Draw now, in the sandbox
118
118
 
package/dist/client.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { Http } from "./http.js";
2
2
  import type { Campaign, Drawing, DrawingRef, DrawingStatus, DrawingsPage, Entrant, EntrantEvent, EntrantLookup, EntriesPage, Guarantee, SendEntriesResponse, SentEntrant } from "./types.js";
3
3
  import { type DrawProof, type VerifyResult } from "./verify.js";
4
- export declare const VERSION = "1.2.1";
4
+ export declare const VERSION = "1.3.1";
5
5
  /** The API takes up to this many entries per request. */
6
6
  export declare const ENTRIES_PER_REQUEST = 1000;
7
7
  export type PrizerailOptions = {
package/dist/client.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { PrizerailCutoffError, PrizerailDrawingChangedError, PrizerailError, } from "./errors.js";
2
2
  import { Http } from "./http.js";
3
3
  import { verifyDraw } from "./verify.js";
4
- export const VERSION = "1.2.1";
4
+ export const VERSION = "1.3.1";
5
5
  const badPage = (detail) => new PrizerailError(0, "invalid_response", `Paging stopped: ${detail}.`);
6
6
  /** The API takes up to this many entries per request. */
7
7
  export const ENTRIES_PER_REQUEST = 1000;
package/dist/types.d.ts CHANGED
@@ -41,6 +41,12 @@ export type Campaign = {
41
41
  endsAt: string | null;
42
42
  };
43
43
  winnersPerDraw: number;
44
+ /**
45
+ * True when one entrant can win several slots in a draw. New drawings take
46
+ * a change, so `nextDrawing.repeatWinners` can differ for up to one draw
47
+ * period. Absent from servers before repeat winners shipped.
48
+ */
49
+ repeatWinners?: boolean;
44
50
  prizeTable: PrizeTable | null;
45
51
  guarantee: {
46
52
  amountCents: number;
@@ -55,6 +61,7 @@ export type Campaign = {
55
61
  drawAt: string;
56
62
  cutoffAt: string;
57
63
  winnersPerDraw: number;
64
+ repeatWinners?: boolean;
58
65
  averagePrizeCents: number | null;
59
66
  } | null;
60
67
  };
@@ -95,6 +102,8 @@ export type Drawing = {
95
102
  cutoffAt: string;
96
103
  status: DrawingStatus;
97
104
  winnersExpected: number;
105
+ /** Whether one entrant can win several slots in this drawing. */
106
+ repeatWinners?: boolean;
98
107
  prizeTable: PrizeTable | null;
99
108
  needsAttention: string | null;
100
109
  winners: Winner[];
@@ -143,12 +152,22 @@ export type EntrantLookup = {
143
152
  * `winner` is null for everyone, so null alone doesn't mean they lost.
144
153
  */
145
154
  drawn: boolean;
146
- /** Their win, or null. `position` is their slot in the drawing's winners. */
147
- winner: {
148
- position: number;
149
- amountCents: number;
150
- heldForManualPayout: boolean;
151
- } | null;
155
+ /**
156
+ * Their win, or null. `position` is their slot in the drawing's winners.
157
+ * With repeat winners it's their first slot, so credit users from
158
+ * `winners` or `totalCents`.
159
+ */
160
+ winner: EntrantSlot | null;
161
+ /** Every slot they won, in slot order. Empty until drawn. */
162
+ winners?: EntrantSlot[];
163
+ /** What they won in all, or null if they didn't win. */
164
+ totalCents?: number | null;
165
+ };
166
+ /** One winning slot in `drawings.entrant()`. */
167
+ export type EntrantSlot = {
168
+ position: number;
169
+ amountCents: number;
170
+ heldForManualPayout: boolean;
152
171
  };
153
172
  export type DrawingsPage = {
154
173
  drawings: Drawing[];
@@ -29,7 +29,8 @@
29
29
  * at or above 2^256 mod the weight of the entrants not picked yet. The
30
30
  * pick is that value mod the same weight, and the winner is the entrant
31
31
  * whose range holds it, counting the ones still in, in index order. They
32
- * sit out later slots.
32
+ * sit out later slots, unless the proof's entrantList.repeatWinners is
33
+ * true: then nobody sits out, and one entrant can fill several slots.
33
34
  * 4. Each winner's ID hashes to the entry the pick landed on.
34
35
  * 5. Each winner's random value is the first
35
36
  * keccak256(abi.encode(bytes32 entropy, bytes32 campaignId,
@@ -310,7 +311,8 @@ export function selectWinners(
310
311
  campaignId,
311
312
  drawingNumber,
312
313
  list,
313
- winnerCount
314
+ winnerCount,
315
+ repeat = false
314
316
  ) {
315
317
  const weights = list.map(([, weight]) => weight);
316
318
  const sums = new Array(weights.length + 1).fill(0);
@@ -335,7 +337,8 @@ export function selectWinners(
335
337
  const entropyBytes = hexBytes(entropy);
336
338
  const id = campaignIdBytes32(campaignId);
337
339
  const picks = [];
338
- for (let slot = 0; slot < Math.min(winnerCount, list.length); slot++) {
340
+ const slots = repeat ? winnerCount : Math.min(winnerCount, list.length);
341
+ for (let slot = 0; slot < slots; slot++) {
339
342
  const threshold = (1n << 256n) % BigInt(remaining);
340
343
  let r;
341
344
  for (let k = 0n; ; k++) {
@@ -354,6 +357,7 @@ export function selectWinners(
354
357
  const pick = Number(BigInt(r) % BigInt(remaining));
355
358
  const entrantIndex = find(pick);
356
359
  picks.push({ entrantIndex, selectionValue: r, pick });
360
+ if (repeat) continue;
357
361
  add(entrantIndex, -weights[entrantIndex]);
358
362
  remaining -= weights[entrantIndex];
359
363
  }
@@ -393,6 +397,21 @@ const usd = cents =>
393
397
  minimumFractionDigits: cents % 100 ? 2 : 0,
394
398
  })}`;
395
399
 
400
+ /**
401
+ * Why a proof value can't be checked, naming its field, or "" if it can.
402
+ * `want` is "string" or "whole number".
403
+ */
404
+ function fieldProblem(value, field, want) {
405
+ if (want === "string" ? typeof value === "string" : Number.isInteger(value)) {
406
+ return "";
407
+ }
408
+ if (value === undefined || value === null) return `${field} is missing`;
409
+ const got = Array.isArray(value) ? "a list" : `a ${typeof value}`;
410
+ return `${field} is ${got}, not a ${want}`;
411
+ }
412
+
413
+ const isObject = value => typeof value === "object" && value !== null;
414
+
396
415
  /**
397
416
  * Every check on a proof, as { ok, label, detail? }. `ok` is true, false, or
398
417
  * null for something worth knowing that the math can't settle.
@@ -412,21 +431,43 @@ export function verifyProof(proof, entrants) {
412
431
  }
413
432
  }
414
433
 
415
- if (
416
- typeof proof.campaign?.id !== "string" ||
417
- !Number.isInteger(proof.drawing?.number)
418
- ) {
434
+ if (!isObject(proof)) {
435
+ check(false, "The proof is a JSON object");
436
+ return checks;
437
+ }
438
+ const idProblem =
439
+ fieldProblem(proof.campaign?.id, "campaign.id", "string") ||
440
+ (/^[\x20-\x7e]{1,32}$/.test(proof.campaign.id)
441
+ ? ""
442
+ : "campaign.id isn't 1 to 32 ASCII characters");
443
+ const keyProblems = [
444
+ idProblem,
445
+ fieldProblem(proof.drawing?.number, "drawing.number", "whole number"),
446
+ ].filter(Boolean);
447
+ if (keyProblems.length > 0) {
419
448
  check(
420
449
  false,
421
450
  "The proof names its campaign ID and drawing number",
422
- `this script reads ${proof.format ?? "an unknown format"} proofs only if they have both`
451
+ `${keyProblems.join(", ")}. This script reads ${proof.format ?? "an unknown format"} proofs only if they have both`
423
452
  );
424
453
  return checks;
425
454
  }
426
455
 
427
456
  const { denominator, tiers } = proof.prizeTable ?? {};
428
- if (!Array.isArray(tiers) || !Array.isArray(proof.results)) {
429
- check(false, "The proof has a prize table and results");
457
+ if (!Array.isArray(tiers) || !tiers.every(isObject)) {
458
+ check(
459
+ false,
460
+ "The proof has a prize table",
461
+ "prizeTable.tiers is missing or isn't a list of tiers"
462
+ );
463
+ return checks;
464
+ }
465
+ if (!Array.isArray(proof.results) || !proof.results.every(isObject)) {
466
+ check(
467
+ false,
468
+ "The proof has results",
469
+ "results is missing or isn't a list of results"
470
+ );
430
471
  return checks;
431
472
  }
432
473
  const total = tiers.reduce((n, t) => n + t.weight, 0);
@@ -437,6 +478,7 @@ export function verifyProof(proof, entrants) {
437
478
  tiers.length >= 2 &&
438
479
  tiers.length <= MAX_TIERS &&
439
480
  tiers.every(t => Number.isInteger(t.weight) && t.weight > 0) &&
481
+ tiers.every(t => Number.isInteger(t.amountCents) && t.amountCents >= 0) &&
440
482
  total === denominator &&
441
483
  tiers.every(
442
484
  (t, i) => i === 0 || tiers[i - 1].amountCents >= t.amountCents
@@ -460,9 +502,8 @@ export function verifyProof(proof, entrants) {
460
502
  if (!withinLimit) return checks;
461
503
  const resultAt = new Map(proof.results.map(r => [r.position, r]));
462
504
 
463
- const entropy = proof.entropy.value;
464
505
  const entrantList = proof.entrantList;
465
- if (!entrantList) {
506
+ if (!isObject(entrantList)) {
466
507
  check(
467
508
  false,
468
509
  "The proof has an entrant list",
@@ -470,15 +511,67 @@ export function verifyProof(proof, entrants) {
470
511
  );
471
512
  return checks;
472
513
  }
514
+ // Every pick and roll comes from the random value, but the list's root
515
+ // doesn't, so a missing one still leaves the root to check.
516
+ const entropy = proof.entropy?.value;
517
+ const entropyProblem =
518
+ fieldProblem(entropy, "entropy.value", "string") ||
519
+ (HASH.test(entropy) ? "" : "entropy.value isn't 32 bytes of hex");
520
+ if (entropyProblem) {
521
+ check(
522
+ false,
523
+ "The proof has its random value",
524
+ `${entropyProblem}, so no pick or roll was checked`
525
+ );
526
+ }
527
+ const badPositions = proof.results
528
+ .map((r, i) =>
529
+ fieldProblem(r.position, `results[${i}].position`, "whole number")
530
+ )
531
+ .filter(Boolean);
532
+ if (badPositions.length > 0) {
533
+ check(false, "Every result has a position", badPositions.join(", "));
534
+ }
473
535
  // The winners are the results in slot order, picked from the list.
474
536
  const winners = [...proof.results]
475
537
  .sort((a, b) => a.position - b.position)
476
538
  .map(r => r.winner);
477
- checkEntrants(proof, entrants, check, resultAt);
539
+ checkEntrants(proof, entrants, check, resultAt, !entropyProblem);
478
540
  check(
479
541
  proof.results.length === winners.length,
480
542
  `One result per winner (${proof.results.length})`
481
543
  );
544
+ if (!entropyProblem) checkRolls(proof, check, resultAt, winners);
545
+
546
+ const { lockedAt } = entrantList;
547
+ const { revealedAt, provider, requestId } = proof.entropy ?? {};
548
+ if (lockedAt && revealedAt) {
549
+ check(
550
+ new Date(lockedAt) < new Date(revealedAt),
551
+ "The list was locked before the random value was revealed",
552
+ "by Prizerail's own timestamps"
553
+ );
554
+ }
555
+ if (provider === "mock") {
556
+ check(
557
+ null,
558
+ "Random value source: test randomness",
559
+ "made by Prizerail in a test environment, so it can't be checked independently"
560
+ );
561
+ } else {
562
+ check(
563
+ null,
564
+ `Random value source: ${provider}${requestId ? ` request ${requestId}` : ""}`,
565
+ "this script doesn't look up the request onchain yet; check it on the chain's explorer"
566
+ );
567
+ }
568
+ return checks;
569
+ }
570
+
571
+ /** Each winner's random value, roll and prize. */
572
+ function checkRolls(proof, check, resultAt, winners) {
573
+ const entropy = proof.entropy.value;
574
+ const { denominator, tiers } = proof.prizeTable;
482
575
  // Every winner's roll first, since the top-tier rule looks across them.
483
576
  const rolled = winners.map((_, position) => {
484
577
  const randomValue = winnerRandomValue(
@@ -504,68 +597,72 @@ export function verifyProof(proof, entrants) {
504
597
  const amountCents = tier === -1 ? null : tiers[tier].amountCents;
505
598
  const demoted = rolled[position].tier === 0 && tier === 1;
506
599
  const problems = [
507
- randomValue !== result.randomValue.toLowerCase() &&
508
- `random value should be ${randomValue}`,
509
- roll !== result.roll && `roll should be ${roll}`,
510
- amountCents !== result.amountCents &&
511
- `prize should be ${amountCents === null ? "none" : usd(amountCents)}`,
600
+ fieldProblem(winner, "winner", "string"),
601
+ fieldProblem(result.randomValue, "randomValue", "string") ||
602
+ (randomValue !== result.randomValue.toLowerCase() &&
603
+ `random value should be ${randomValue}`),
604
+ fieldProblem(result.roll, "roll", "whole number") ||
605
+ (roll !== result.roll && `roll should be ${roll}`),
606
+ fieldProblem(result.amountCents, "amountCents", "whole number") ||
607
+ (amountCents !== result.amountCents &&
608
+ `prize should be ${amountCents === null ? "none" : usd(amountCents)}`),
512
609
  ].filter(Boolean);
610
+ const wins = Number.isInteger(result.amountCents)
611
+ ? usd(result.amountCents)
612
+ : "an unstated prize";
513
613
  check(
514
614
  problems.length === 0,
515
- `${label}: roll ${roll.toLocaleString("en-US")} wins ${usd(result.amountCents)}${demoted ? ", the second prize, since another winner with a lower random value kept the top one" : ""}`,
615
+ `${label}: roll ${roll.toLocaleString("en-US")} wins ${wins}${demoted ? ", the second prize, since another winner with a lower random value kept the top one" : ""}`,
516
616
  problems.join(", ") || undefined
517
617
  );
518
618
  }
519
-
520
- const { lockedAt } = entrantList;
521
- const { revealedAt, provider, requestId } = proof.entropy;
522
- if (lockedAt && revealedAt) {
523
- check(
524
- new Date(lockedAt) < new Date(revealedAt),
525
- "The list was locked before the random value was revealed",
526
- "by Prizerail's own timestamps"
527
- );
528
- }
529
- if (provider === "mock") {
530
- check(
531
- null,
532
- "Random value source: test randomness",
533
- "made by Prizerail in a test environment, so it can't be checked independently"
534
- );
535
- } else {
536
- check(
537
- null,
538
- `Random value source: ${provider}${requestId ? ` request ${requestId}` : ""}`,
539
- "this script doesn't look up the request onchain yet; check it on the chain's explorer"
540
- );
541
- }
542
- return checks;
543
619
  }
544
620
 
545
- /** The entrant list's checks: its root, then every pick. */
546
- function checkEntrants(proof, entrants, check, results) {
621
+ /**
622
+ * The entrant list's checks: its root, then every pick, if the proof has a
623
+ * usable random value (`picksCheckable`).
624
+ */
625
+ function checkEntrants(proof, entrants, check, results, picksCheckable) {
547
626
  const { root, count, totalWeight, winnersRequested } = proof.entrantList;
548
- if (
549
- typeof root !== "string" ||
550
- !HASH.test(root) ||
551
- !Number.isInteger(count) ||
552
- count < 1 ||
553
- !Number.isSafeInteger(totalWeight) ||
554
- !Number.isInteger(winnersRequested) ||
555
- winnersRequested < 1 ||
556
- winnersRequested > MAX_WINNERS
557
- ) {
627
+ // Proofs from before the setting have no field, and those draws took
628
+ // each winner out.
629
+ const repeat = proof.entrantList.repeatWinners === true;
630
+ const fieldProblems = [
631
+ fieldProblem(root, "entrantList.root", "string") ||
632
+ (HASH.test(root) ? "" : "entrantList.root isn't 32 bytes of hex"),
633
+ fieldProblem(count, "entrantList.count", "whole number") ||
634
+ (count < 1 ? "entrantList.count is below 1" : ""),
635
+ fieldProblem(totalWeight, "entrantList.totalWeight", "whole number") ||
636
+ (Number.isSafeInteger(totalWeight)
637
+ ? ""
638
+ : "entrantList.totalWeight is too big"),
639
+ fieldProblem(
640
+ winnersRequested,
641
+ "entrantList.winnersRequested",
642
+ "whole number"
643
+ ) ||
644
+ (winnersRequested < 1 || winnersRequested > MAX_WINNERS
645
+ ? `entrantList.winnersRequested isn't from 1 to ${MAX_WINNERS}`
646
+ : ""),
647
+ ].filter(Boolean);
648
+ if (fieldProblems.length > 0) {
558
649
  check(
559
650
  false,
560
651
  "The proof's entrant list fields are well formed",
561
- "root must be 32 bytes of hex, count and totalWeight whole numbers, and winnersRequested from 1 to 500"
652
+ fieldProblems.join(", ")
562
653
  );
563
654
  return;
564
655
  }
565
- const expected = Math.min(winnersRequested, count);
656
+ // Without repeat winners each entrant fills at most one slot, so the draw
657
+ // has as many winners as asked for, or as entrants if fewer. With them,
658
+ // every slot asked for is filled. Draws the first contracts ran never
659
+ // repeat, so their proofs say false or leave the field out.
660
+ const expected = repeat
661
+ ? winnersRequested
662
+ : Math.min(winnersRequested, count);
566
663
  check(
567
664
  proof.results.length === expected,
568
- `${expected} winner${expected === 1 ? "" : "s"}: ${winnersRequested} asked for, from ${count.toLocaleString("en-US")} entrants`
665
+ `${expected} winner${expected === 1 ? "" : "s"}: ${winnersRequested} asked for, from ${count.toLocaleString("en-US")} entrants${repeat ? ", repeat winners allowed" : ""}`
569
666
  );
570
667
  if (!entrants) {
571
668
  // The root and the picks are what make an entrants draw checkable, so
@@ -628,12 +725,14 @@ function checkEntrants(proof, entrants, check, results) {
628
725
  "Entrant list root matches the list",
629
726
  computed === root.toLowerCase() ? undefined : `computed ${computed}`
630
727
  );
728
+ if (!picksCheckable) return;
631
729
  const picks = selectWinners(
632
730
  proof.entropy.value,
633
731
  proof.campaign.id,
634
732
  proof.drawing.number,
635
733
  list,
636
- winnersRequested
734
+ expected,
735
+ repeat
637
736
  );
638
737
  for (const [slot, pick] of picks.entries()) {
639
738
  const result = results.get(slot);
@@ -644,13 +743,17 @@ function checkEntrants(proof, entrants, check, results) {
644
743
  }
645
744
  const entry = list.at(pick.entrantIndex);
646
745
  const problems = [
647
- pick.selectionValue !== result.selectionValue?.toLowerCase() &&
648
- `selection value should be ${pick.selectionValue}`,
649
- pick.pick !== result.pick && `pick should be ${pick.pick}`,
650
- pick.entrantIndex !== result.entrantPosition &&
651
- `winner should be entrant ${pick.entrantIndex}`,
652
- winnerHash(result.winner) !== entry[0].toLowerCase() &&
653
- `${result.winner} doesn't hash to entrant ${pick.entrantIndex}`,
746
+ fieldProblem(result.selectionValue, "selectionValue", "string") ||
747
+ (pick.selectionValue !== result.selectionValue.toLowerCase() &&
748
+ `selection value should be ${pick.selectionValue}`),
749
+ fieldProblem(result.pick, "pick", "whole number") ||
750
+ (pick.pick !== result.pick && `pick should be ${pick.pick}`),
751
+ fieldProblem(result.entrantPosition, "entrantPosition", "whole number") ||
752
+ (pick.entrantIndex !== result.entrantPosition &&
753
+ `winner should be entrant ${pick.entrantIndex}`),
754
+ fieldProblem(result.winner, "winner", "string") ||
755
+ (winnerHash(result.winner) !== entry[0].toLowerCase() &&
756
+ `${result.winner} doesn't hash to entrant ${pick.entrantIndex}`),
654
757
  ].filter(Boolean);
655
758
  check(
656
759
  problems.length === 0,
@@ -749,16 +852,17 @@ async function main() {
749
852
  }
750
853
  const proof = await readJson(source);
751
854
  let entrants;
752
- if (proof.entrantList) {
855
+ if (proof?.entrantList) {
856
+ const listUrl = proof.entrantList.url;
753
857
  const listSource =
754
858
  process.argv[3] ??
755
- (/^https?:\/\//.test(source)
756
- ? new URL(proof.entrantList.url, source).href
859
+ (/^https?:\/\//.test(source) && typeof listUrl === "string"
860
+ ? new URL(listUrl, source).href
757
861
  : undefined);
758
862
  if (listSource) entrants = await readEntrants(listSource);
759
863
  }
760
864
  console.log(
761
- `\n${proof.campaign.name}, draw of ${proof.drawing.drawAt} (${proof.drawing.id})\n`
865
+ `\n${proof?.campaign?.name ?? "Unnamed campaign"}, draw of ${proof?.drawing?.drawAt ?? "an unknown time"} (${proof?.drawing?.id ?? "no draw ID"})\n`
762
866
  );
763
867
  const checks = verifyProof(proof, entrants);
764
868
  for (const { ok, label, detail } of checks) {
package/dist/verify.d.ts CHANGED
@@ -23,6 +23,8 @@ export type DrawProof = {
23
23
  count: number;
24
24
  totalWeight: number;
25
25
  winnersRequested: number;
26
+ /** One entrant can fill several slots. Absent, or false, they can't. */
27
+ repeatWinners?: boolean;
26
28
  lockedAt: string | null;
27
29
  };
28
30
  [field: string]: unknown;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prizerail",
3
- "version": "1.2.1",
3
+ "version": "1.3.1",
4
4
  "description": "The Prizerail SDK: send entries, read draws and verify them.",
5
5
  "license": "MIT",
6
6
  "homepage": "https://docs.prizerail.com",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "prizerail",
3
- "version": "1.2.1",
3
+ "version": "1.3.1",
4
4
  "description": "Integrate Prizerail prize draws into an app, check an integration end to end, and look up or verify draws.",
5
5
  "author": {
6
6
  "name": "Prizerail",
@@ -12,10 +12,10 @@ Prizerail runs prize draws for partner apps. Through each period the partner sen
12
12
  ## Concepts
13
13
 
14
14
  - **Campaign:** a partner's draw, found by its slug in `https://www.prizerail.com/campaigns/{slug}`. Draws run on a schedule (hourly, daily, weekly or monthly) in the campaign's time zone.
15
- - **Entrants:** the partner sends them, each an id with a number of `entries` (1 unless it sends more), which the proof calls its `weight`. Nobody picks who wins: the random value draws the winners from the locked list, each entrant in proportion to their weight, and nobody wins twice in one draw. A draw proves the winners and prizes are fair for the list it was given.
15
+ - **Entrants:** the partner sends them, each an id with a number of `entries` (1 unless it sends more), which the proof calls its `weight`. Nobody picks who wins: the random value draws the winners from the locked list, each entrant in proportion to their weight, and nobody wins twice in one draw unless the proof's `entrantList.repeatWinners` is true. A draw has `winnersRequested` winners. Without `repeatWinners` that's capped at `count`, so every entrant wins when there are fewer. With it, every slot is filled even from a short list. A draw proves the winners and prizes are fair for the list it was given.
16
16
  - **Cutoff:** the partner can send entries until `cutoffAt`. Each campaign sets how long before `drawAt` that is, from minutes to days.
17
17
  - **Entrant list fingerprint:** the root of an OpenZeppelin `StandardMerkleTree` over `(uint256 index, bytes32 keccak256(bytes(entrantId)), uint64 weight)`. The tree sorts its leaves, so the root commits to the set of entries and the index is the only order: indices must run exactly 0 to `count - 1`. It is recorded and published, with the hashed list, when the list locks, before the random value exists.
18
- - **Winners:** for slot `j`, `r` is the first `keccak256(abi.encode(bytes32 entropy, bytes32 campaignId, uint64 drawingId, bytes32 "prizerail.entrant", uint256 j, uint256 k))` for `k = 0, 1, …` that is at least `2^256 mod remaining`, where `remaining` is the weight of the entrants not drawn yet. `pick = r mod remaining`, and the winner is the entrant whose run of weight holds `pick`, counting the ones still in, in index order
18
+ - **Winners:** for slot `j`, `r` is the first `keccak256(abi.encode(bytes32 entropy, bytes32 campaignId, uint64 drawingId, bytes32 "prizerail.entrant", uint256 j, uint256 k))` for `k = 0, 1, …` that is at least `2^256 mod remaining`, where `remaining` is the weight of the entrants not drawn yet (with `repeatWinners`, nobody is taken out, so it's the whole list's weight every slot). `pick = r mod remaining`, and the winner is the entrant whose run of weight holds `pick`, counting the ones still in, in index order
19
19
  - **Prize:** the same math the Prizerail contract runs onchain. For the winner in slot `i`:
20
20
  - `campaignId` is the proof's `campaign.id` as ASCII, right-padded to 32 bytes, and `drawingId` is `drawing.number`
21
21
  - `randomValue` is the first `keccak256(abi.encode(bytes32 entropy, bytes32 campaignId, uint64 drawingId, uint256 i, uint256 k))` for `k = 0, 1, …` that is at least `2^256 mod denominator`. In practice `k` is always 0
@@ -48,7 +48,7 @@ Base `https://www.prizerail.com`. Public, with CORS `*`.
48
48
  | Endpoint | Returns |
49
49
  |---|---|
50
50
  | `GET /campaigns/{slug}/draws.json` | `campaign` (name, status, cadence, timezone, winnersPerDraw, payout chain and token), `draws[]` newest first (`id`, `number`, `drawAt`, `cutoffAt`, `stage`, `winners`, `winnersCommitment`, `entrants`, `lockedAt`, `settledAt`, `paidAt`, `proof`), and `nextBefore`. Page back with `?before={nextBefore}`. `?limit=` up to 100, default 30 |
51
- | `GET /campaigns/{slug}/draws/{id}/proof.json` | A drawn draw's proof: `entrantList` (`root`, `count`, `totalWeight`, `winnersRequested`, `lockedAt`, `url` of the list), `entropy` (`provider`, `requestId`, `value`, `revealedAt`), `prizeTable` (`denominator`, `tiers[]` of `amountCents` and `weight`), `results[]` (`position`, `winner`, `displayName`, `entrantPosition`, `selectionValue`, `pick`, `randomValue`, `roll`, `amountCents`). `displayName` is the partner's public name for the winner, shown only and never hashed. |
51
+ | `GET /campaigns/{slug}/draws/{id}/proof.json` | A drawn draw's proof: `entrantList` (`root`, `count`, `totalWeight`, `winnersRequested`, `repeatWinners`, `lockedAt`, `url` of the list), `entropy` (`provider`, `requestId`, `value`, `revealedAt`), `prizeTable` (`denominator`, `tiers[]` of `amountCents` and `weight`), `results[]` (`position`, `winner`, `displayName`, `entrantPosition`, `selectionValue`, `pick`, `randomValue`, `roll`, `amountCents`). `displayName` is the partner's public name for the winner, shown only and never hashed. |
52
52
  | `GET /campaigns/{slug}/draws/{id}/entrants.json?page=1` | A locked draw's entrant list, hashed: `entrants[]` of `[index, keccak256(bytes(entrantId)), weight]` sorted by index, 20,000 a page, with `root`, `count`, `totalWeight`, `page`, `pages` and `next` |
53
53
  | `GET /verify/verify-draw.mjs` | The verify script (Node.js 18+, no dependencies) |
54
54