@dvmkit/sdk 0.2.0-rc.9 → 0.2.1-rc.9

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.
Files changed (58) hide show
  1. package/README.md +2 -0
  2. package/dist/{chunk-V7EVFLAK.js → chunk-2D75MNNG.js} +154 -523
  3. package/dist/{chunk-BIFLRKMO.js → chunk-2KGG5ORW.js} +1 -1
  4. package/dist/{chunk-5URG56JJ.js → chunk-A4CM2BD3.js} +18 -2
  5. package/dist/{chunk-FT6HTUM4.js → chunk-AJNFXR7J.js} +1 -1
  6. package/dist/{chunk-S3XAHZQY.js → chunk-COYKJRMM.js} +24 -3
  7. package/dist/{chunk-UP2F5RRT.js → chunk-D7YQYLLM.js} +1 -4
  8. package/dist/{chunk-OMIQMMME.js → chunk-FPOLJRBF.js} +3 -3
  9. package/dist/{chunk-QP53RWAD.js → chunk-JAHRF5X3.js} +1 -1
  10. package/dist/{chunk-PCUQZDZA.js → chunk-JNKQZVZX.js} +95 -321
  11. package/dist/{chunk-JDT5LCJC.js → chunk-MD3H3BF7.js} +1 -1
  12. package/dist/{chunk-KSQEFVFJ.js → chunk-MMCE7XSR.js} +1 -1
  13. package/dist/{chunk-MRAGS5VP.js → chunk-N5B66UOS.js} +4 -16
  14. package/dist/{chunk-2ATUAUAO.js → chunk-O6D72KYA.js} +2 -2
  15. package/dist/{chunk-KXCKFIJI.js → chunk-QX52F6IB.js} +1 -1
  16. package/dist/{chunk-PHHAYRQV.js → chunk-U5VNEALI.js} +23 -10
  17. package/dist/{chunk-JLXYOV4Y.js → chunk-V5ZRATJH.js} +1 -1
  18. package/dist/{chunk-6GRIKOFB.js → chunk-VA7GT6C6.js} +5 -16
  19. package/dist/{chunk-O2X2CCKH.js → chunk-VIVXB4CD.js} +1 -1
  20. package/dist/{chunk-L67WTZX2.js → chunk-XMDQOXHO.js} +10 -33
  21. package/dist/{chunk-QT4ONTST.js → chunk-XRLKGCAW.js} +1 -1
  22. package/dist/{chunk-KMZXTBLA.js → chunk-XZ7LW4S5.js} +0 -1
  23. package/dist/{chunk-XQXJKJ3P.js → chunk-YO56VCTQ.js} +0 -4
  24. package/dist/{credit-ledger-5ZEJRI46.js → credit-ledger-MHA652TV.js} +2 -2
  25. package/dist/{credit-menu-D4Gcdgc4.d.ts → credit-menu-kDA9RVzD.d.ts} +135 -532
  26. package/dist/{fx-B0SLBe5x.d.ts → fx-DhyT1Cjh.d.ts} +1 -1
  27. package/dist/index.d.ts +5 -17
  28. package/dist/internal/caller.d.ts +109 -698
  29. package/dist/internal/caller.js +10 -12
  30. package/dist/internal/server.d.ts +17 -42
  31. package/dist/internal/server.js +15 -15
  32. package/dist/{job-store-B2uZvga4.d.ts → job-store-D3CcZp_g.d.ts} +6 -10
  33. package/dist/{lightning-backend-CQBnQgsT.d.ts → lightning-backend-BhsyrBLa.d.ts} +1 -15
  34. package/dist/{memory-credit-ledger-ZOH6C3N4.js → memory-credit-ledger-BYBATRN3.js} +3 -3
  35. package/dist/{mpp-secret-state-WNAQQ6K4.js → mpp-secret-state-B5GCILVH.js} +1 -1
  36. package/dist/{mpp-setup-IOJBF7DB.js → mpp-setup-MPP3ST5X.js} +1 -1
  37. package/dist/{payout-reporter-5PIRYFVQ.js → payout-reporter-KEMUXEUO.js} +2 -2
  38. package/dist/{postgres-consumed-credential-store-ISRHBMOU.js → postgres-consumed-credential-store-6N2V5MJN.js} +1 -1
  39. package/dist/postgres-job-store-MZZZMS2B.js +7 -0
  40. package/dist/postgres-kv-store-DXGTKXLU.js +7 -0
  41. package/dist/{postgres-replay-store-IZFLTTAC.js → postgres-replay-store-ZF4JNZOW.js} +2 -2
  42. package/dist/{processed-payment-store-FIDI3RNH.js → processed-payment-store-GKMAWOM3.js} +2 -2
  43. package/dist/revenue-reporter-O75BGYFK.js +7 -0
  44. package/dist/server/index.d.ts +34 -140
  45. package/dist/server/index.js +52 -124
  46. package/dist/{step-cache-CXg7ziML.d.ts → step-cache-v2yhyhSZ.d.ts} +359 -1112
  47. package/dist/{tempo-charge-store-76TDAF34.js → tempo-charge-store-SDTUNTKA.js} +2 -2
  48. package/dist/{tempo-lifecycle-DXM7QXJQ.js → tempo-lifecycle-G5SB4HFC.js} +4 -4
  49. package/dist/{tempo-session-store-2JNOKJGX.js → tempo-session-store-WF3VZXNF.js} +2 -2
  50. package/dist/{tempo-wallet-O67H5M4N.js → tempo-wallet-ZFNUDFVO.js} +1 -1
  51. package/dist/testing/index.d.ts +2 -2
  52. package/dist/testing/index.js +2 -2
  53. package/dist/{usd-BNDg1715.d.ts → usd-Cu9G6xv2.d.ts} +1 -1
  54. package/dist/{x402-7S2EFINY.js → x402-CI6PSHNO.js} +4 -4
  55. package/package.json +2 -2
  56. package/dist/postgres-job-store-OGQ6IT4U.js +0 -7
  57. package/dist/postgres-kv-store-D5E2EZ24.js +0 -7
  58. package/dist/revenue-reporter-NNCNRY4C.js +0 -7
@@ -11,7 +11,7 @@ import {
11
11
  } from "./chunk-Z4BNLUZF.js";
12
12
  import {
13
13
  usdcToMsats
14
- } from "./chunk-5URG56JJ.js";
14
+ } from "./chunk-A4CM2BD3.js";
15
15
  import {
16
16
  callerLoggers
17
17
  } from "./chunk-66HGCPBU.js";
@@ -66,8 +66,24 @@ function msatsToUsdCents(msats, btcPriceUsd) {
66
66
  return Math.round(usd * 100);
67
67
  }
68
68
  function msatsToUsdc(msats, btcUsdRate) {
69
- const usd = msatsToUsd(msats, btcUsdRate);
70
- return Math.ceil(usd * 1e6);
69
+ if (!Number.isSafeInteger(msats) || msats < 0) {
70
+ throw new RangeError("msats must be a non-negative safe integer");
71
+ }
72
+ if (!Number.isFinite(btcUsdRate) || btcUsdRate <= 0) {
73
+ throw new RangeError("BTC/USD rate must be finite and positive");
74
+ }
75
+ const [mantissa, exponent = "0"] = btcUsdRate.toString().split("e");
76
+ const decimalPlaces = mantissa.split(".")[1]?.length ?? 0;
77
+ const shift = Number(exponent) - decimalPlaces;
78
+ let numerator = BigInt(msats) * BigInt(mantissa.replace(".", ""));
79
+ let denominator = 100000n;
80
+ if (shift > 0) numerator *= 10n ** BigInt(shift);
81
+ else if (shift < 0) denominator *= 10n ** BigInt(-shift);
82
+ const micro = (numerator + denominator - 1n) / denominator;
83
+ if (micro > BigInt(Number.MAX_SAFE_INTEGER)) {
84
+ throw new RangeError("USDC micro-unit amount exceeds the safe integer range");
85
+ }
86
+ return Number(micro);
71
87
  }
72
88
  function usdcToMsats(usdc, btcUsdRate) {
73
89
  return usdToMsats(usdc, btcUsdRate);
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  withSdkInitLock
3
- } from "./chunk-S3XAHZQY.js";
3
+ } from "./chunk-COYKJRMM.js";
4
4
 
5
5
  // src/sdk/server/postgres-replay-store.ts
6
6
  var DEFAULT_TABLE_NAME = "signed_request_replays";
@@ -1,26 +1,47 @@
1
1
  // src/sdk/server/init-lock.ts
2
+ import { AsyncLocalStorage } from "async_hooks";
2
3
  var SDK_INIT_ADVISORY_LOCK = 17320927;
3
4
  async function withSdkInitLock(db, fn) {
5
+ const context = activeInits.getStore();
6
+ if (context?.get(db)?.active) return fn();
4
7
  assertPoolFitsLock(db);
5
8
  let holder = holders.get(db);
6
9
  if (holder) {
7
10
  holder.refs += 1;
8
11
  } else {
9
- holder = { refs: 1, acquired: acquire(db) };
12
+ holder = { refs: 1, acquired: acquire(db), tail: Promise.resolve() };
10
13
  holders.set(db, holder);
11
14
  }
15
+ const predecessor = holder.tail;
16
+ let finishTurn;
17
+ holder.tail = new Promise((resolve) => {
18
+ finishTurn = resolve;
19
+ });
12
20
  let guardedFailed = false;
13
21
  try {
14
22
  await holder.acquired;
15
- return await fn();
23
+ await predecessor;
24
+ const token = { active: true };
25
+ const nextContext = new Map(context);
26
+ nextContext.set(db, token);
27
+ try {
28
+ return await activeInits.run(nextContext, fn);
29
+ } finally {
30
+ token.active = false;
31
+ }
16
32
  } catch (err) {
17
33
  guardedFailed = true;
18
34
  throw err;
19
35
  } finally {
20
- await releaseHolder(db, holder, guardedFailed);
36
+ try {
37
+ await releaseHolder(db, holder, guardedFailed);
38
+ } finally {
39
+ finishTurn();
40
+ }
21
41
  }
22
42
  }
23
43
  var holders = /* @__PURE__ */ new WeakMap();
44
+ var activeInits = new AsyncLocalStorage();
24
45
  function assertPoolFitsLock(db) {
25
46
  const max = db.options?.max;
26
47
  if (max === void 0 || max >= 2) return;
@@ -4,7 +4,7 @@ import {
4
4
  } from "./chunk-YG7G4DPZ.js";
5
5
  import {
6
6
  withSdkInitLock
7
- } from "./chunk-S3XAHZQY.js";
7
+ } from "./chunk-COYKJRMM.js";
8
8
  import {
9
9
  withPostgresTransactionRecovery
10
10
  } from "./chunk-C3MTFLC6.js";
@@ -18,7 +18,6 @@ var PostgresTempoSessionStore = class {
18
18
  }
19
19
  pool;
20
20
  acceptance = new AsyncLocalStorage();
21
- /** Create the channel table under the SDK-wide migration lock. */
22
21
  async init() {
23
22
  await withSdkInitLock(this.pool, async () => {
24
23
  await this.pool.query(`
@@ -47,7 +46,6 @@ var PostgresTempoSessionStore = class {
47
46
  );
48
47
  });
49
48
  }
50
- /** Read one channel snapshot. */
51
49
  async get(key) {
52
50
  const client = this.acceptance.getStore()?.client;
53
51
  const { rows } = await (client ?? this.pool).query(
@@ -60,7 +58,6 @@ var PostgresTempoSessionStore = class {
60
58
  async put(key, value) {
61
59
  await this.update(key, () => ({ op: "set", value, result: void 0 }));
62
60
  }
63
- /** Delete one channel snapshot. */
64
61
  async delete(key) {
65
62
  await this.update(key, () => ({ op: "delete", result: void 0 }));
66
63
  }
@@ -2,19 +2,19 @@ import {
2
2
  connectedTempoAccount,
3
3
  tempoBalanceCheckHint,
4
4
  tempoTokenReference
5
- } from "./chunk-O2X2CCKH.js";
5
+ } from "./chunk-VIVXB4CD.js";
6
6
  import {
7
7
  fundingReachableAt,
8
8
  listCredits,
9
9
  maxAdvertisedMicro,
10
10
  normalizeCreditEndpoint,
11
11
  withinAdvertisedTolerance
12
- } from "./chunk-KSQEFVFJ.js";
12
+ } from "./chunk-MMCE7XSR.js";
13
13
  import {
14
14
  costAnchor,
15
15
  formatUsd,
16
16
  formatUsdcMicrounits
17
- } from "./chunk-5URG56JJ.js";
17
+ } from "./chunk-A4CM2BD3.js";
18
18
  import {
19
19
  DvmError,
20
20
  IDENTITIES_FILE,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  withSdkInitLock
3
- } from "./chunk-S3XAHZQY.js";
3
+ } from "./chunk-COYKJRMM.js";
4
4
 
5
5
  // src/sdk/server/postgres-job-store.ts
6
6
  import { createHash } from "crypto";