prizerail 0.0.1 → 0.2.0
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/LICENSE +21 -0
- package/README.md +130 -3
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +60 -0
- package/dist/client.d.ts +135 -0
- package/dist/client.js +330 -0
- package/dist/entrant.d.ts +7 -0
- package/dist/entrant.js +14 -0
- package/dist/errors.d.ts +36 -0
- package/dist/errors.js +42 -0
- package/dist/http.d.ts +39 -0
- package/dist/http.js +140 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +4 -0
- package/dist/types.d.ts +191 -0
- package/dist/types.js +2 -0
- package/dist/verify-draw.d.mts +15 -0
- package/dist/verify-draw.mjs +786 -0
- package/dist/verify.d.ts +65 -0
- package/dist/verify.js +70 -0
- package/package.json +34 -5
- package/cli.mjs +0 -4
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An entrant id for a user: HMAC-SHA256 of their id with your secret key,
|
|
3
|
+
* as hex. The same user and key always give the same id, and without the
|
|
4
|
+
* key nobody can work back to the user. Keep the key fixed for the life of
|
|
5
|
+
* the campaign. Matches Node's createHmac("sha256", key).update(id).digest("hex").
|
|
6
|
+
*/
|
|
7
|
+
export declare function hashEntrant(userId: string | number, key: string): Promise<string>;
|
package/dist/entrant.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* An entrant id for a user: HMAC-SHA256 of their id with your secret key,
|
|
3
|
+
* as hex. The same user and key always give the same id, and without the
|
|
4
|
+
* key nobody can work back to the user. Keep the key fixed for the life of
|
|
5
|
+
* the campaign. Matches Node's createHmac("sha256", key).update(id).digest("hex").
|
|
6
|
+
*/
|
|
7
|
+
export async function hashEntrant(userId, key) {
|
|
8
|
+
if (!key)
|
|
9
|
+
throw new Error("hashEntrant needs your secret key.");
|
|
10
|
+
const enc = new TextEncoder();
|
|
11
|
+
const cryptoKey = await globalThis.crypto.subtle.importKey("raw", enc.encode(key), { name: "HMAC", hash: "SHA-256" }, false, ["sign"]);
|
|
12
|
+
const mac = await globalThis.crypto.subtle.sign("HMAC", cryptoKey, enc.encode(String(userId)));
|
|
13
|
+
return Array.from(new Uint8Array(mac), b => b.toString(16).padStart(2, "0")).join("");
|
|
14
|
+
}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { DrawingRef } from "./types.js";
|
|
2
|
+
/** An error response from the API, or a request that never got one. */
|
|
3
|
+
export declare class PrizerailError extends Error {
|
|
4
|
+
/** The HTTP status. 0 when the request failed before a response. */
|
|
5
|
+
readonly status: number;
|
|
6
|
+
/** The API's error code, like `not_found` or `no_open_drawing`. */
|
|
7
|
+
readonly code: string;
|
|
8
|
+
readonly detail?: string;
|
|
9
|
+
constructor(status: number, code: string, detail?: string);
|
|
10
|
+
}
|
|
11
|
+
/** What a send had stored before it stopped. */
|
|
12
|
+
export type SendProgress = {
|
|
13
|
+
drawing: DrawingRef;
|
|
14
|
+
/** Entries in the batches Prizerail confirmed. */
|
|
15
|
+
sent: number;
|
|
16
|
+
added: number;
|
|
17
|
+
updated: number;
|
|
18
|
+
unchanged: number;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* A send stopped so that no entry lands in the drawing after the one it
|
|
22
|
+
* targeted. Entries past `progress.sent` were not confirmed: check with
|
|
23
|
+
* `entries.list({ drawing })` before sending them to the next drawing.
|
|
24
|
+
*/
|
|
25
|
+
export declare class PrizerailCutoffError extends PrizerailError {
|
|
26
|
+
readonly progress: SendProgress;
|
|
27
|
+
readonly cause?: unknown;
|
|
28
|
+
constructor(detail: string, progress: SendProgress, cause?: unknown);
|
|
29
|
+
}
|
|
30
|
+
/** A batch went to a different drawing from the rest of the send. */
|
|
31
|
+
export declare class PrizerailDrawingChangedError extends PrizerailError {
|
|
32
|
+
readonly progress: SendProgress;
|
|
33
|
+
/** Where the last batch went. */
|
|
34
|
+
readonly landedIn: DrawingRef;
|
|
35
|
+
constructor(progress: SendProgress, landedIn: DrawingRef);
|
|
36
|
+
}
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/** An error response from the API, or a request that never got one. */
|
|
2
|
+
export class PrizerailError extends Error {
|
|
3
|
+
/** The HTTP status. 0 when the request failed before a response. */
|
|
4
|
+
status;
|
|
5
|
+
/** The API's error code, like `not_found` or `no_open_drawing`. */
|
|
6
|
+
code;
|
|
7
|
+
detail;
|
|
8
|
+
constructor(status, code, detail) {
|
|
9
|
+
super(detail ? `${code}: ${detail}` : code);
|
|
10
|
+
this.name = "PrizerailError";
|
|
11
|
+
this.status = status;
|
|
12
|
+
this.code = code;
|
|
13
|
+
this.detail = detail;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* A send stopped so that no entry lands in the drawing after the one it
|
|
18
|
+
* targeted. Entries past `progress.sent` were not confirmed: check with
|
|
19
|
+
* `entries.list({ drawing })` before sending them to the next drawing.
|
|
20
|
+
*/
|
|
21
|
+
export class PrizerailCutoffError extends PrizerailError {
|
|
22
|
+
progress;
|
|
23
|
+
cause;
|
|
24
|
+
constructor(detail, progress, cause) {
|
|
25
|
+
super(0, "cutoff_reached", detail);
|
|
26
|
+
this.name = "PrizerailCutoffError";
|
|
27
|
+
this.progress = progress;
|
|
28
|
+
this.cause = cause;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** A batch went to a different drawing from the rest of the send. */
|
|
32
|
+
export class PrizerailDrawingChangedError extends PrizerailError {
|
|
33
|
+
progress;
|
|
34
|
+
/** Where the last batch went. */
|
|
35
|
+
landedIn;
|
|
36
|
+
constructor(progress, landedIn) {
|
|
37
|
+
super(0, "drawing_changed", `A batch went to drawing ${landedIn.id}, not ${progress.drawing.id}. Its cutoff passed mid-send.`);
|
|
38
|
+
this.name = "PrizerailDrawingChangedError";
|
|
39
|
+
this.progress = progress;
|
|
40
|
+
this.landedIn = landedIn;
|
|
41
|
+
}
|
|
42
|
+
}
|
package/dist/http.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export type HttpOptions = {
|
|
2
|
+
apiKey?: string;
|
|
3
|
+
baseUrl: string;
|
|
4
|
+
fetch: typeof fetch;
|
|
5
|
+
/** Per attempt. */
|
|
6
|
+
timeoutMs: number;
|
|
7
|
+
/** Retries after the first attempt, for 429s, 5xx and network errors. */
|
|
8
|
+
maxRetries: number;
|
|
9
|
+
userAgent: string;
|
|
10
|
+
};
|
|
11
|
+
export type RequestOptions = {
|
|
12
|
+
query?: Record<string, string | number | undefined>;
|
|
13
|
+
body?: unknown;
|
|
14
|
+
/**
|
|
15
|
+
* No retry is started that would wait until this time, in ms since the
|
|
16
|
+
* epoch. `onDeadline` builds the error thrown instead.
|
|
17
|
+
*/
|
|
18
|
+
deadline?: number;
|
|
19
|
+
onDeadline?: (error: unknown) => Error;
|
|
20
|
+
/** For a request that isn't safe to repeat. Defaults to the client's maxRetries. */
|
|
21
|
+
maxRetries?: number;
|
|
22
|
+
/** For a request the server may take longer over. Defaults to the client's. */
|
|
23
|
+
timeoutMs?: number;
|
|
24
|
+
};
|
|
25
|
+
/** A server that asks for a longer wait than this gets the error instead. */
|
|
26
|
+
export declare const MAX_RETRY_AFTER_MS: number;
|
|
27
|
+
/** Retry-After as ms from now: delta seconds or an HTTP date. */
|
|
28
|
+
export declare function parseRetryAfter(value: string | null, now?: number): number | null;
|
|
29
|
+
/** Full jitter, with Retry-After as the floor when the server sent one. */
|
|
30
|
+
export declare function retryDelay(attempt: number, retryAfterMs: number | null): number;
|
|
31
|
+
export declare class Http {
|
|
32
|
+
readonly options: HttpOptions;
|
|
33
|
+
constructor(options: HttpOptions);
|
|
34
|
+
url(path: string, query?: RequestOptions["query"]): string;
|
|
35
|
+
/** JSON from the partner API, with retries. Throws PrizerailError. */
|
|
36
|
+
request<T>(method: "GET" | "POST", path: string, { query, body, deadline, onDeadline, ...rest }?: RequestOptions): Promise<T>;
|
|
37
|
+
/** Public JSON, like a draw's proof, with no key and no retries. */
|
|
38
|
+
getPublic<T>(url: string): Promise<T>;
|
|
39
|
+
}
|
package/dist/http.js
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import { PrizerailError } from "./errors.js";
|
|
2
|
+
const BASE_DELAY_MS = 1000;
|
|
3
|
+
const MAX_DELAY_MS = 30_000;
|
|
4
|
+
/** A server that asks for a longer wait than this gets the error instead. */
|
|
5
|
+
export const MAX_RETRY_AFTER_MS = 5 * 60_000;
|
|
6
|
+
/** Retry-After as ms from now: delta seconds or an HTTP date. */
|
|
7
|
+
export function parseRetryAfter(value, now = Date.now()) {
|
|
8
|
+
if (!value)
|
|
9
|
+
return null;
|
|
10
|
+
const trimmed = value.trim();
|
|
11
|
+
if (/^\d+$/.test(trimmed)) {
|
|
12
|
+
return Number(trimmed) * 1000;
|
|
13
|
+
}
|
|
14
|
+
const at = Date.parse(trimmed);
|
|
15
|
+
if (Number.isNaN(at))
|
|
16
|
+
return null;
|
|
17
|
+
return Math.max(at - now, 0);
|
|
18
|
+
}
|
|
19
|
+
/** Full jitter, with Retry-After as the floor when the server sent one. */
|
|
20
|
+
export function retryDelay(attempt, retryAfterMs) {
|
|
21
|
+
const ceiling = Math.min(MAX_DELAY_MS, BASE_DELAY_MS * 2 ** attempt);
|
|
22
|
+
const jitter = Math.random() * ceiling;
|
|
23
|
+
return retryAfterMs === null ? jitter : Math.max(retryAfterMs, jitter);
|
|
24
|
+
}
|
|
25
|
+
const retryable = (status) => status === 429 || (status >= 500 && status !== 501);
|
|
26
|
+
async function errorFrom(res) {
|
|
27
|
+
const text = await res.text().catch(() => "");
|
|
28
|
+
try {
|
|
29
|
+
const body = JSON.parse(text);
|
|
30
|
+
if (typeof body.error === "string") {
|
|
31
|
+
return new PrizerailError(res.status, body.error, typeof body.detail === "string" ? body.detail : undefined);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
// Not JSON, from a proxy or CDN. Keep the start of it.
|
|
36
|
+
}
|
|
37
|
+
return new PrizerailError(res.status, `http_${res.status}`, text.slice(0, 200) || res.statusText || undefined);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A 2xx body as JSON. A body that isn't JSON is a broken response, not a
|
|
41
|
+
* network error, so it isn't retried: a POST may already be stored.
|
|
42
|
+
*/
|
|
43
|
+
function parseBody(res, text) {
|
|
44
|
+
try {
|
|
45
|
+
return JSON.parse(text);
|
|
46
|
+
}
|
|
47
|
+
catch {
|
|
48
|
+
throw new PrizerailError(res.status, "invalid_response", `The API answered ${res.status} with a body that isn't JSON: ${text.slice(0, 200)}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
const sleep = (ms) => new Promise(r => setTimeout(r, ms));
|
|
52
|
+
export class Http {
|
|
53
|
+
options;
|
|
54
|
+
constructor(options) {
|
|
55
|
+
this.options = options;
|
|
56
|
+
}
|
|
57
|
+
url(path, query) {
|
|
58
|
+
const url = new URL(path.replace(/^\//, ""), `${this.options.baseUrl}/`);
|
|
59
|
+
for (const [k, v] of Object.entries(query ?? {})) {
|
|
60
|
+
if (v !== undefined)
|
|
61
|
+
url.searchParams.set(k, String(v));
|
|
62
|
+
}
|
|
63
|
+
return url.href;
|
|
64
|
+
}
|
|
65
|
+
/** JSON from the partner API, with retries. Throws PrizerailError. */
|
|
66
|
+
async request(method, path, { query, body, deadline, onDeadline, ...rest } = {}) {
|
|
67
|
+
const { apiKey, fetch, userAgent } = this.options;
|
|
68
|
+
const maxRetries = rest.maxRetries ?? this.options.maxRetries;
|
|
69
|
+
const timeoutMs = rest.timeoutMs ?? this.options.timeoutMs;
|
|
70
|
+
if (!apiKey) {
|
|
71
|
+
throw new PrizerailError(0, "no_api_key", "Pass apiKey to new Prizerail() to call the partner API.");
|
|
72
|
+
}
|
|
73
|
+
const url = this.url(path, query);
|
|
74
|
+
for (let attempt = 0;; attempt++) {
|
|
75
|
+
let failure;
|
|
76
|
+
let retryAfterMs = null;
|
|
77
|
+
let res = null;
|
|
78
|
+
let text = "";
|
|
79
|
+
try {
|
|
80
|
+
res = await fetch(url, {
|
|
81
|
+
method,
|
|
82
|
+
headers: {
|
|
83
|
+
authorization: `Bearer ${apiKey}`,
|
|
84
|
+
accept: "application/json",
|
|
85
|
+
"user-agent": userAgent,
|
|
86
|
+
...(body === undefined
|
|
87
|
+
? {}
|
|
88
|
+
: { "content-type": "application/json" }),
|
|
89
|
+
},
|
|
90
|
+
body: body === undefined ? undefined : JSON.stringify(body),
|
|
91
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
92
|
+
});
|
|
93
|
+
if (res.ok)
|
|
94
|
+
text = await res.text();
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
// No response, or the body was cut off: a timeout or network error.
|
|
98
|
+
res = null;
|
|
99
|
+
failure = new PrizerailError(0, "network_error", error instanceof Error ? error.message : String(error));
|
|
100
|
+
}
|
|
101
|
+
if (res?.ok)
|
|
102
|
+
return parseBody(res, text);
|
|
103
|
+
if (res) {
|
|
104
|
+
const error = await errorFrom(res);
|
|
105
|
+
if (!retryable(res.status))
|
|
106
|
+
throw error;
|
|
107
|
+
failure = error;
|
|
108
|
+
retryAfterMs = parseRetryAfter(res.headers.get("retry-after"));
|
|
109
|
+
}
|
|
110
|
+
// Set on every path that gets here.
|
|
111
|
+
const last = failure;
|
|
112
|
+
if (attempt >= maxRetries)
|
|
113
|
+
throw last;
|
|
114
|
+
if (retryAfterMs !== null && retryAfterMs > MAX_RETRY_AFTER_MS)
|
|
115
|
+
throw last;
|
|
116
|
+
const wait = retryDelay(attempt, retryAfterMs);
|
|
117
|
+
if (deadline !== undefined && Date.now() + wait >= deadline) {
|
|
118
|
+
throw onDeadline ? onDeadline(last) : last;
|
|
119
|
+
}
|
|
120
|
+
await sleep(wait);
|
|
121
|
+
// Timers can fire late, after a sleep or a busy event loop.
|
|
122
|
+
if (deadline !== undefined && Date.now() >= deadline) {
|
|
123
|
+
throw onDeadline ? onDeadline(last) : last;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/** Public JSON, like a draw's proof, with no key and no retries. */
|
|
128
|
+
async getPublic(url) {
|
|
129
|
+
const res = await this.options.fetch(url, {
|
|
130
|
+
headers: {
|
|
131
|
+
accept: "application/json",
|
|
132
|
+
"user-agent": this.options.userAgent,
|
|
133
|
+
},
|
|
134
|
+
signal: AbortSignal.timeout(this.options.timeoutMs),
|
|
135
|
+
});
|
|
136
|
+
if (!res.ok)
|
|
137
|
+
throw await errorFrom(res);
|
|
138
|
+
return parseBody(res, await res.text());
|
|
139
|
+
}
|
|
140
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { CampaignClient, DrawingsClient, ENTRIES_PER_REQUEST, EntriesClient, Prizerail, type PrizerailOptions, type SendOptions, type SendResult, VERSION, } from "./client.js";
|
|
2
|
+
export { hashEntrant } from "./entrant.js";
|
|
3
|
+
export { PrizerailCutoffError, PrizerailDrawingChangedError, PrizerailError, type SendProgress, } from "./errors.js";
|
|
4
|
+
export type * from "./types.js";
|
|
5
|
+
export { type Check, type DrawProof, type EntrantRow, type VerifyOptions, type VerifyResult, verifyDraw, wasEntered, } from "./verify.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { CampaignClient, DrawingsClient, ENTRIES_PER_REQUEST, EntriesClient, Prizerail, VERSION, } from "./client.js";
|
|
2
|
+
export { hashEntrant } from "./entrant.js";
|
|
3
|
+
export { PrizerailCutoffError, PrizerailDrawingChangedError, PrizerailError, } from "./errors.js";
|
|
4
|
+
export { verifyDraw, wasEntered, } from "./verify.js";
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
/** Shapes the Prizerail partner API returns, as documented at docs.prizerail.com. */
|
|
2
|
+
export type CampaignStatus = "draft" | "active" | "paused" | "ended";
|
|
3
|
+
export type Cadence = "hourly" | "daily" | "weekly" | "monthly";
|
|
4
|
+
export type DrawingStatus = "open" | "locked" | "entropy_requested" | "settled" | "paid";
|
|
5
|
+
export type DrawingKind = "regular" | "guarantee";
|
|
6
|
+
export type PayoutKind = "lump_sum" | "large_prize" | "guarantee";
|
|
7
|
+
export type PayoutStatus = "pending" | "submitted" | "confirmed" | "failed" | "held_manual";
|
|
8
|
+
export type GuaranteeStatus = "not_needed" | "drawn" | "skipped";
|
|
9
|
+
export type PrizeTier = {
|
|
10
|
+
amountCents: number;
|
|
11
|
+
/** A tier wins on `weight` of the table's `denominator` rolls. */
|
|
12
|
+
weight: number;
|
|
13
|
+
/** One winner's chance of this prize, from 0 to 1. */
|
|
14
|
+
odds: number;
|
|
15
|
+
};
|
|
16
|
+
export type PrizeTable = {
|
|
17
|
+
id: string;
|
|
18
|
+
version: number;
|
|
19
|
+
denominator: number;
|
|
20
|
+
/** Top prize first. */
|
|
21
|
+
tiers: PrizeTier[];
|
|
22
|
+
averagePrizeCents: number;
|
|
23
|
+
};
|
|
24
|
+
export type Campaign = {
|
|
25
|
+
slug: string;
|
|
26
|
+
name: string;
|
|
27
|
+
status: CampaignStatus;
|
|
28
|
+
/** The public campaign page. */
|
|
29
|
+
page: string;
|
|
30
|
+
schedule: {
|
|
31
|
+
cadence: Cadence;
|
|
32
|
+
drawHour: number | null;
|
|
33
|
+
drawMinute: number | null;
|
|
34
|
+
drawWeekday: number | null;
|
|
35
|
+
drawDayOfMonth: number | null;
|
|
36
|
+
timezone: string;
|
|
37
|
+
cutoffMinutes: number;
|
|
38
|
+
startsAt: string | null;
|
|
39
|
+
endsAt: string | null;
|
|
40
|
+
};
|
|
41
|
+
winnersPerDraw: number;
|
|
42
|
+
prizeTable: PrizeTable | null;
|
|
43
|
+
guarantee: {
|
|
44
|
+
amountCents: number;
|
|
45
|
+
thresholdCents: number;
|
|
46
|
+
periodDays: number;
|
|
47
|
+
} | null;
|
|
48
|
+
largePrizeThresholdCents: number | null;
|
|
49
|
+
termsUrl: string;
|
|
50
|
+
privacyUrl: string;
|
|
51
|
+
nextDrawing: {
|
|
52
|
+
id: string;
|
|
53
|
+
drawAt: string;
|
|
54
|
+
cutoffAt: string;
|
|
55
|
+
winnersPerDraw: number;
|
|
56
|
+
averagePrizeCents: number | null;
|
|
57
|
+
} | null;
|
|
58
|
+
};
|
|
59
|
+
export type DrawingRef = {
|
|
60
|
+
id: string;
|
|
61
|
+
drawAt: string;
|
|
62
|
+
cutoffAt: string;
|
|
63
|
+
};
|
|
64
|
+
export type Winner = {
|
|
65
|
+
position: number;
|
|
66
|
+
winner: string;
|
|
67
|
+
displayName: string | null;
|
|
68
|
+
avatarUrl: string | null;
|
|
69
|
+
/** The rest is set once the drawing settles. */
|
|
70
|
+
randomValue?: string;
|
|
71
|
+
roll?: number;
|
|
72
|
+
amountCents?: number;
|
|
73
|
+
heldForManualPayout?: boolean;
|
|
74
|
+
};
|
|
75
|
+
export type Payout = {
|
|
76
|
+
id: string;
|
|
77
|
+
kind: PayoutKind;
|
|
78
|
+
amountCents: number;
|
|
79
|
+
status: PayoutStatus;
|
|
80
|
+
chain: string;
|
|
81
|
+
token: string;
|
|
82
|
+
to: string;
|
|
83
|
+
txHash: string | null;
|
|
84
|
+
confirmedAt: string | null;
|
|
85
|
+
/** The winner a large-prize or guarantee payout is for. Null for the lump sum. */
|
|
86
|
+
winnerPosition: number | null;
|
|
87
|
+
};
|
|
88
|
+
export type Drawing = {
|
|
89
|
+
id: string;
|
|
90
|
+
kind: DrawingKind;
|
|
91
|
+
number: number | null;
|
|
92
|
+
drawAt: string;
|
|
93
|
+
cutoffAt: string;
|
|
94
|
+
status: DrawingStatus;
|
|
95
|
+
winnersExpected: number;
|
|
96
|
+
prizeTable: PrizeTable | null;
|
|
97
|
+
needsAttention: string | null;
|
|
98
|
+
winners: Winner[];
|
|
99
|
+
payouts: Payout[];
|
|
100
|
+
verification: {
|
|
101
|
+
winnersCommitment: string | null;
|
|
102
|
+
lockedAt: string | null;
|
|
103
|
+
entropyProvider: string | null;
|
|
104
|
+
entropyRequestId: string | null;
|
|
105
|
+
entropy: string | null;
|
|
106
|
+
entropyRevealedAt: string | null;
|
|
107
|
+
chain: Record<string, unknown> | null;
|
|
108
|
+
prizeTableId: string | null;
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
export type DrawingsPage = {
|
|
112
|
+
drawings: Drawing[];
|
|
113
|
+
nextBefore: string | null;
|
|
114
|
+
nextAfter: string | null;
|
|
115
|
+
};
|
|
116
|
+
/** An entrant id, with one entry, or an id with their entries and how they show if they win. */
|
|
117
|
+
export type Entrant = string | {
|
|
118
|
+
entrantId: string;
|
|
119
|
+
/** Their number of entries, a whole number from 1. Leave it out and it's 1. */
|
|
120
|
+
entries?: number;
|
|
121
|
+
/** @deprecated Use `entries`. Still sent as `entries`. */
|
|
122
|
+
weight?: number;
|
|
123
|
+
/** Up to 40 characters. */
|
|
124
|
+
displayName?: string;
|
|
125
|
+
/** https, up to 2,048 characters. */
|
|
126
|
+
avatarUrl?: string;
|
|
127
|
+
};
|
|
128
|
+
/** @deprecated Use `Entrant`. */
|
|
129
|
+
export type Entry = Entrant;
|
|
130
|
+
export type SendEntriesResponse = {
|
|
131
|
+
drawing: DrawingRef;
|
|
132
|
+
/** Entrants in this request that were new, changed or the same. */
|
|
133
|
+
added: number;
|
|
134
|
+
updated: number;
|
|
135
|
+
unchanged: number;
|
|
136
|
+
/** The drawing's entrants so far. */
|
|
137
|
+
entrantCount: number;
|
|
138
|
+
/** The drawing's total entries so far. */
|
|
139
|
+
totalEntries: number;
|
|
140
|
+
/** @deprecated Use `entrantCount`. */
|
|
141
|
+
count: number;
|
|
142
|
+
/** @deprecated Use `totalEntries`. */
|
|
143
|
+
totalWeight: number;
|
|
144
|
+
};
|
|
145
|
+
export type SentEntrant = {
|
|
146
|
+
entrantId: string;
|
|
147
|
+
/** Their number of entries. */
|
|
148
|
+
entries: number;
|
|
149
|
+
/** @deprecated Use `entries`. */
|
|
150
|
+
weight: number;
|
|
151
|
+
displayName: string | null;
|
|
152
|
+
avatarUrl: string | null;
|
|
153
|
+
/** Place in the locked list. Null until the cutoff. */
|
|
154
|
+
position: number | null;
|
|
155
|
+
receivedAt: string;
|
|
156
|
+
};
|
|
157
|
+
/** @deprecated Use `SentEntrant`. */
|
|
158
|
+
export type SentEntry = SentEntrant;
|
|
159
|
+
export type EntriesPage = {
|
|
160
|
+
drawing: DrawingRef & {
|
|
161
|
+
status: DrawingStatus;
|
|
162
|
+
};
|
|
163
|
+
entrantCount: number;
|
|
164
|
+
totalEntries: number;
|
|
165
|
+
/** In arrival order, the order the list locks in. */
|
|
166
|
+
entrants: SentEntrant[];
|
|
167
|
+
/** @deprecated Use `entrantCount`. */
|
|
168
|
+
count: number;
|
|
169
|
+
/** @deprecated Use `totalEntries`. */
|
|
170
|
+
totalWeight: number;
|
|
171
|
+
/** @deprecated Use `entrants`, the same list. */
|
|
172
|
+
entries: SentEntrant[];
|
|
173
|
+
/** Pass as `after` for the next page. Null on the last. */
|
|
174
|
+
next: string | null;
|
|
175
|
+
};
|
|
176
|
+
export type Guarantee = {
|
|
177
|
+
id: string;
|
|
178
|
+
period: number;
|
|
179
|
+
periodStart: string;
|
|
180
|
+
periodEnd: string;
|
|
181
|
+
status: GuaranteeStatus;
|
|
182
|
+
amountCents: number | null;
|
|
183
|
+
drawing: {
|
|
184
|
+
id: string;
|
|
185
|
+
number: number | null;
|
|
186
|
+
status: DrawingStatus;
|
|
187
|
+
entrants: number | null;
|
|
188
|
+
winner: string | null;
|
|
189
|
+
displayName: string | null;
|
|
190
|
+
} | null;
|
|
191
|
+
};
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Types for verify-draw.mjs, the public verify script, which this package
|
|
3
|
+
* ships unchanged (a test checks it matches public/verify/verify-draw.mjs).
|
|
4
|
+
*/
|
|
5
|
+
export type Check = { ok: boolean | null; label: string; detail?: string };
|
|
6
|
+
/** [index, keccak256(entrantId), weight] */
|
|
7
|
+
export type EntrantRow = [number, string, number];
|
|
8
|
+
export function keccak256(bytes: Uint8Array): string;
|
|
9
|
+
export function winnerHash(winner: string): string;
|
|
10
|
+
export function entrantsRoot(list: [string, number][]): string;
|
|
11
|
+
export function verifyProof(proof: unknown, entrants?: EntrantRow[]): Check[];
|
|
12
|
+
export function readEntrants(
|
|
13
|
+
source: string,
|
|
14
|
+
options?: { fetch?: typeof fetch; timeoutMs?: number }
|
|
15
|
+
): Promise<EntrantRow[]>;
|