@wopr-network/platform-core 1.58.0 → 1.58.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.
@@ -68,6 +68,7 @@ async function main() {
68
68
  oracle,
69
69
  bitcoindUser: BITCOIND_USER,
70
70
  bitcoindPassword: BITCOIND_PASSWORD,
71
+ serviceKey: SERVICE_KEY,
71
72
  log: (msg, meta) => console.log(`[watcher] ${msg}`, meta ?? ""),
72
73
  });
73
74
  const server = serve({ fetch: app.fetch, port: PORT });
@@ -29,6 +29,8 @@ export interface WatcherServiceOpts {
29
29
  log?: (msg: string, meta?: Record<string, unknown>) => void;
30
30
  /** Allowed callback URL prefixes. Default: ["https://"] — enforces HTTPS. */
31
31
  allowedCallbackPrefixes?: string[];
32
+ /** Service key sent as Bearer token in webhook deliveries. */
33
+ serviceKey?: string;
32
34
  }
33
35
  export interface PaymentPayload {
34
36
  txHash: string;
@@ -43,7 +43,7 @@ async function enqueueWebhook(db, chargeId, callbackUrl, payload) {
43
43
  payload: JSON.stringify(payload),
44
44
  });
45
45
  }
46
- async function processDeliveries(db, allowedPrefixes, log) {
46
+ async function processDeliveries(db, allowedPrefixes, log, serviceKey) {
47
47
  const now = new Date().toISOString();
48
48
  const pending = await db
49
49
  .select()
@@ -60,9 +60,12 @@ async function processDeliveries(db, allowedPrefixes, log) {
60
60
  continue;
61
61
  }
62
62
  try {
63
+ const headers = { "Content-Type": "application/json" };
64
+ if (serviceKey)
65
+ headers.Authorization = `Bearer ${serviceKey}`;
63
66
  const res = await fetch(row.callbackUrl, {
64
67
  method: "POST",
65
- headers: { "Content-Type": "application/json" },
68
+ headers,
66
69
  body: row.payload,
67
70
  });
68
71
  if (!res.ok)
@@ -175,6 +178,7 @@ export async function startWatchers(opts) {
175
178
  const deliveryMs = opts.deliveryIntervalMs ?? 10_000;
176
179
  const log = opts.log ?? (() => { });
177
180
  const allowedPrefixes = opts.allowedCallbackPrefixes ?? ["https://"];
181
+ const serviceKey = opts.serviceKey;
178
182
  const timers = [];
179
183
  const methods = await methodStore.listEnabled();
180
184
  const utxoMethods = methods.filter((m) => m.type === "native" && (m.chain === "bitcoin" || m.chain === "litecoin" || m.chain === "dogecoin"));
@@ -388,7 +392,7 @@ export async function startWatchers(opts) {
388
392
  // --- Webhook delivery outbox processor ---
389
393
  timers.push(setInterval(async () => {
390
394
  try {
391
- const count = await processDeliveries(db, allowedPrefixes, log);
395
+ const count = await processDeliveries(db, allowedPrefixes, log, serviceKey);
392
396
  if (count > 0)
393
397
  log("Webhooks delivered", { count });
394
398
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wopr-network/platform-core",
3
- "version": "1.58.0",
3
+ "version": "1.58.1",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -77,6 +77,7 @@ async function main(): Promise<void> {
77
77
  oracle,
78
78
  bitcoindUser: BITCOIND_USER,
79
79
  bitcoindPassword: BITCOIND_PASSWORD,
80
+ serviceKey: SERVICE_KEY,
80
81
  log: (msg, meta) => console.log(`[watcher] ${msg}`, meta ?? ""),
81
82
  });
82
83
 
@@ -43,6 +43,8 @@ export interface WatcherServiceOpts {
43
43
  log?: (msg: string, meta?: Record<string, unknown>) => void;
44
44
  /** Allowed callback URL prefixes. Default: ["https://"] — enforces HTTPS. */
45
45
  allowedCallbackPrefixes?: string[];
46
+ /** Service key sent as Bearer token in webhook deliveries. */
47
+ serviceKey?: string;
46
48
  }
47
49
 
48
50
  // --- SSRF validation ---
@@ -79,6 +81,7 @@ async function processDeliveries(
79
81
  db: DrizzleDb,
80
82
  allowedPrefixes: string[],
81
83
  log: (msg: string, meta?: Record<string, unknown>) => void,
84
+ serviceKey?: string,
82
85
  ): Promise<number> {
83
86
  const now = new Date().toISOString();
84
87
  const pending = await db
@@ -103,9 +106,11 @@ async function processDeliveries(
103
106
  }
104
107
 
105
108
  try {
109
+ const headers: Record<string, string> = { "Content-Type": "application/json" };
110
+ if (serviceKey) headers.Authorization = `Bearer ${serviceKey}`;
106
111
  const res = await fetch(row.callbackUrl, {
107
112
  method: "POST",
108
- headers: { "Content-Type": "application/json" },
113
+ headers,
109
114
  body: row.payload,
110
115
  });
111
116
  if (!res.ok) throw new Error(`HTTP ${res.status}`);
@@ -242,6 +247,7 @@ export async function startWatchers(opts: WatcherServiceOpts): Promise<() => voi
242
247
  const deliveryMs = opts.deliveryIntervalMs ?? 10_000;
243
248
  const log = opts.log ?? (() => {});
244
249
  const allowedPrefixes = opts.allowedCallbackPrefixes ?? ["https://"];
250
+ const serviceKey = opts.serviceKey;
245
251
  const timers: ReturnType<typeof setInterval>[] = [];
246
252
 
247
253
  const methods = await methodStore.listEnabled();
@@ -500,7 +506,7 @@ export async function startWatchers(opts: WatcherServiceOpts): Promise<() => voi
500
506
  timers.push(
501
507
  setInterval(async () => {
502
508
  try {
503
- const count = await processDeliveries(db, allowedPrefixes, log);
509
+ const count = await processDeliveries(db, allowedPrefixes, log, serviceKey);
504
510
  if (count > 0) log("Webhooks delivered", { count });
505
511
  } catch (err) {
506
512
  log("Delivery loop error", { error: String(err) });