@secondlayer/shared 11.7.1 → 11.8.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.
Files changed (163) hide show
  1. package/dist/src/archive/copy-loader.d.ts +1 -1
  2. package/dist/src/archive/copy-loader.js +4 -20
  3. package/dist/src/archive/copy-loader.js.map +2 -2
  4. package/dist/src/archive/derived-stage-report.d.ts +1 -1
  5. package/dist/src/archive/derived-stage-report.js +3 -19
  6. package/dist/src/archive/derived-stage-report.js.map +2 -2
  7. package/dist/src/archive/disk-guard.d.ts +1 -1
  8. package/dist/src/archive/disk-guard.js +3 -19
  9. package/dist/src/archive/disk-guard.js.map +2 -2
  10. package/dist/src/archive/instance-diagnosis.d.ts +1 -1
  11. package/dist/src/archive/instance-diagnosis.js +6 -22
  12. package/dist/src/archive/instance-diagnosis.js.map +2 -2
  13. package/dist/src/archive/key-registry.d.ts +1 -1
  14. package/dist/src/archive/key-registry.js +12 -12
  15. package/dist/src/archive/key-registry.js.map +1 -1
  16. package/dist/src/archive/per-height-digest.d.ts +1 -1
  17. package/dist/src/archive/per-height-digest.js +3 -17
  18. package/dist/src/archive/per-height-digest.js.map +5 -5
  19. package/dist/src/archive/progress.d.ts +1 -1
  20. package/dist/src/archive/progress.js +4 -20
  21. package/dist/src/archive/progress.js.map +2 -2
  22. package/dist/src/archive/range-digest.d.ts +28 -3
  23. package/dist/src/archive/range-digest.js +4 -20
  24. package/dist/src/archive/range-digest.js.map +2 -2
  25. package/dist/src/archive/reference.d.ts +1 -1
  26. package/dist/src/archive/reference.js +14 -12
  27. package/dist/src/archive/reference.js.map +5 -5
  28. package/dist/src/archive/root-key.d.ts +1 -1
  29. package/dist/src/archive/root-key.js +3 -19
  30. package/dist/src/archive/root-key.js.map +2 -2
  31. package/dist/src/archive/semantic-digest-builder.d.ts +28 -3
  32. package/dist/src/archive/semantic-digest-builder.js +5 -19
  33. package/dist/src/archive/semantic-digest-builder.js.map +5 -5
  34. package/dist/src/archive/semantic-digest.d.ts +1 -1
  35. package/dist/src/archive/semantic-digest.js +4 -20
  36. package/dist/src/archive/semantic-digest.js.map +2 -2
  37. package/dist/src/archive/status.d.ts +1 -1
  38. package/dist/src/archive/status.js +4 -20
  39. package/dist/src/archive/status.js.map +2 -2
  40. package/dist/src/coverage/index.d.ts +27 -2
  41. package/dist/src/coverage/index.js +80 -96
  42. package/dist/src/coverage/index.js.map +2 -2
  43. package/dist/src/crypto/ed25519.d.ts +1 -1
  44. package/dist/src/crypto/ed25519.js +13 -13
  45. package/dist/src/crypto/ed25519.js.map +1 -1
  46. package/dist/src/crypto/hmac.d.ts +1 -1
  47. package/dist/src/crypto/hmac.js +9 -9
  48. package/dist/src/crypto/hmac.js.map +1 -1
  49. package/dist/src/crypto/secondlayer-webhook.d.ts +1 -1
  50. package/dist/src/crypto/secondlayer-webhook.js +14 -14
  51. package/dist/src/crypto/secondlayer-webhook.js.map +2 -2
  52. package/dist/src/crypto/secrets.d.ts +1 -1
  53. package/dist/src/crypto/secrets.js +15 -29
  54. package/dist/src/crypto/secrets.js.map +5 -5
  55. package/dist/src/crypto/standard-webhooks.d.ts +1 -1
  56. package/dist/src/crypto/standard-webhooks.js +3 -19
  57. package/dist/src/crypto/standard-webhooks.js.map +2 -2
  58. package/dist/src/db/index.d.ts +48 -19
  59. package/dist/src/db/index.js +41 -55
  60. package/dist/src/db/index.js.map +6 -6
  61. package/dist/src/db/jsonb.d.ts +1 -1
  62. package/dist/src/db/jsonb.js +3 -19
  63. package/dist/src/db/jsonb.js.map +2 -2
  64. package/dist/src/db/queries/chain-reorgs.d.ts +27 -2
  65. package/dist/src/db/queries/chain-reorgs.js +28 -42
  66. package/dist/src/db/queries/chain-reorgs.js.map +6 -6
  67. package/dist/src/db/queries/contracts.d.ts +27 -2
  68. package/dist/src/db/queries/contracts.js +9 -23
  69. package/dist/src/db/queries/contracts.js.map +5 -5
  70. package/dist/src/db/queries/instance.d.ts +27 -2
  71. package/dist/src/db/queries/instance.js +7 -23
  72. package/dist/src/db/queries/instance.js.map +2 -2
  73. package/dist/src/db/queries/integrity.d.ts +27 -2
  74. package/dist/src/db/queries/integrity.js +5 -21
  75. package/dist/src/db/queries/integrity.js.map +2 -2
  76. package/dist/src/db/queries/subgraph-gaps.d.ts +27 -2
  77. package/dist/src/db/queries/subgraph-gaps.js +5 -21
  78. package/dist/src/db/queries/subgraph-gaps.js.map +2 -2
  79. package/dist/src/db/queries/subgraph-operations.d.ts +27 -2
  80. package/dist/src/db/queries/subgraph-operations.js +17 -33
  81. package/dist/src/db/queries/subgraph-operations.js.map +2 -2
  82. package/dist/src/db/queries/subgraphs.d.ts +28 -14
  83. package/dist/src/db/queries/subgraphs.js +15 -37
  84. package/dist/src/db/queries/subgraphs.js.map +5 -5
  85. package/dist/src/db/queries/sync-scope.d.ts +27 -2
  86. package/dist/src/db/queries/sync-scope.js +6 -22
  87. package/dist/src/db/queries/sync-scope.js.map +2 -2
  88. package/dist/src/db/queries/webhooks.d.ts +27 -2
  89. package/dist/src/db/queries/webhooks.js +54 -50
  90. package/dist/src/db/queries/webhooks.js.map +5 -5
  91. package/dist/src/db/schema.d.ts +30 -2
  92. package/dist/src/env.d.ts +1 -1
  93. package/dist/src/env.js +7 -23
  94. package/dist/src/env.js.map +2 -2
  95. package/dist/src/errors.d.ts +4 -4
  96. package/dist/src/errors.js +15 -31
  97. package/dist/src/errors.js.map +3 -3
  98. package/dist/src/index-http.d.ts +1 -1
  99. package/dist/src/index-http.js +4 -20
  100. package/dist/src/index-http.js.map +3 -3
  101. package/dist/src/index-internal-auth.d.ts +4 -7
  102. package/dist/src/index-internal-auth.js +8 -24
  103. package/dist/src/index-internal-auth.js.map +3 -3
  104. package/dist/src/index.d.ts +176 -152
  105. package/dist/src/index.js +305 -317
  106. package/dist/src/index.js.map +15 -15
  107. package/dist/src/leader.d.ts +1 -1
  108. package/dist/src/leader.js +7 -21
  109. package/dist/src/leader.js.map +5 -5
  110. package/dist/src/logger.js +1 -17
  111. package/dist/src/logger.js.map +2 -2
  112. package/dist/src/mode.d.ts +1 -1
  113. package/dist/src/mode.js +5 -21
  114. package/dist/src/mode.js.map +2 -2
  115. package/dist/src/node/archive-client.d.ts +1 -1
  116. package/dist/src/node/archive-client.js +9 -23
  117. package/dist/src/node/archive-client.js.map +5 -5
  118. package/dist/src/node/client.d.ts +1 -1
  119. package/dist/src/node/client.js +4 -18
  120. package/dist/src/node/client.js.map +5 -5
  121. package/dist/src/node/consensus.d.ts +1 -1
  122. package/dist/src/node/consensus.js +5 -21
  123. package/dist/src/node/consensus.js.map +2 -2
  124. package/dist/src/node/hiro-client.d.ts +1 -1
  125. package/dist/src/node/hiro-client.js +1 -17
  126. package/dist/src/node/hiro-client.js.map +2 -2
  127. package/dist/src/node/hiro-pg-client.js +1 -17
  128. package/dist/src/node/hiro-pg-client.js.map +2 -2
  129. package/dist/src/node/local-client.d.ts +27 -2
  130. package/dist/src/node/local-client.js +3 -19
  131. package/dist/src/node/local-client.js.map +2 -2
  132. package/dist/src/node/nakamoto.d.ts +1 -1
  133. package/dist/src/node/nakamoto.js +12 -28
  134. package/dist/src/node/nakamoto.js.map +2 -2
  135. package/dist/src/queue/listener.d.ts +1 -1
  136. package/dist/src/queue/listener.js +4 -20
  137. package/dist/src/queue/listener.js.map +2 -2
  138. package/dist/src/runtime/index.d.ts +1 -1
  139. package/dist/src/runtime/index.js +51 -67
  140. package/dist/src/runtime/index.js.map +2 -2
  141. package/dist/src/schemas/index.d.ts +8 -4
  142. package/dist/src/schemas/index.js +64 -41
  143. package/dist/src/schemas/index.js.map +4 -4
  144. package/dist/src/schemas/subgraphs.d.ts +1 -4
  145. package/dist/src/schemas/subgraphs.js +1 -18
  146. package/dist/src/schemas/subgraphs.js.map +3 -3
  147. package/dist/src/schemas/webhooks.d.ts +19 -1
  148. package/dist/src/schemas/webhooks.js +70 -41
  149. package/dist/src/schemas/webhooks.js.map +3 -3
  150. package/dist/src/streams-bulk-manifest.d.ts +1 -1
  151. package/dist/src/streams-bulk-manifest.js +9 -9
  152. package/dist/src/streams-bulk-manifest.js.map +1 -1
  153. package/dist/src/streams-rows/index.d.ts +1 -1
  154. package/dist/src/streams-rows/index.js +32 -48
  155. package/dist/src/streams-rows/index.js.map +2 -2
  156. package/dist/src/subgraphs/spec.d.ts +1 -11
  157. package/dist/src/subgraphs/spec.js +27 -93
  158. package/dist/src/subgraphs/spec.js.map +3 -3
  159. package/dist/src/types.d.ts +1 -1
  160. package/migrations/0136_drop_subgraph_visibility.ts +34 -0
  161. package/migrations/0137_webhook_outbox_last_error.ts +27 -0
  162. package/migrations/0138_usage_ledger.ts +46 -0
  163. package/package.json +1 -1
@@ -1,25 +1,9 @@
1
- import { createRequire } from "node:module";
2
- var __defProp = Object.defineProperty;
3
- var __returnValue = (v) => v;
4
- function __exportSetter(name, newValue) {
5
- this[name] = __returnValue.bind(null, newValue);
6
- }
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, {
10
- get: all[name],
11
- enumerable: true,
12
- configurable: true,
13
- set: __exportSetter.bind(all, name)
14
- });
15
- };
16
-
17
1
  // src/index-internal-auth.ts
18
2
  var INDEX_INTERNAL_TENANT_ID = "tenant_index_internal";
19
3
  var INTERNAL_STREAMS_TENANT_ID = "tenant_streams_decode_internal";
20
4
  var DEFAULT_INTERNAL_INDEX_BASE_URL = "http://api:3800";
21
5
  var MISSING_INTERNAL_STREAMS_API_KEY = "Set STREAMS_INTERNAL_API_KEY (archive; prefix sl-int_) or INSTANCE_TOKEN (OSS). Empty env no longer falls back to a committed secret.";
22
- var MISSING_INTERNAL_INDEX_API_KEY = "Set INDEX_INTERNAL_API_KEY (archive; prefix sl-int_) or INSTANCE_TOKEN (OSS). Without one, Index reads go out anonymously and are capped at the last 24h, so any seek into older history 402s.";
6
+ var MISSING_INTERNAL_INDEX_API_KEY = "Set INDEX_INTERNAL_API_KEY (archive; prefix sl-int_) or INSTANCE_TOKEN (OSS). Without one, Index reads carry no credential and platform mode 401s every one of them.";
23
7
  function defaultInternalIndexApiKey(env = process.env) {
24
8
  const internal = env.INDEX_INTERNAL_API_KEY?.trim();
25
9
  if (internal)
@@ -54,14 +38,14 @@ function defaultInternalIndexBaseUrl() {
54
38
  return process.env.SUBGRAPH_INDEX_API_URL || process.env.STREAMS_API_URL || DEFAULT_INTERNAL_INDEX_BASE_URL;
55
39
  }
56
40
  export {
57
- requireInternalStreamsApiKey,
58
- requireInternalIndexApiKey,
59
- defaultInternalStreamsApiKey,
60
- defaultInternalIndexBaseUrl,
61
- defaultInternalIndexApiKey,
41
+ INDEX_INTERNAL_TENANT_ID,
62
42
  INTERNAL_STREAMS_TENANT_ID,
63
- INDEX_INTERNAL_TENANT_ID
43
+ defaultInternalIndexApiKey,
44
+ defaultInternalIndexBaseUrl,
45
+ defaultInternalStreamsApiKey,
46
+ requireInternalIndexApiKey,
47
+ requireInternalStreamsApiKey
64
48
  };
65
49
 
66
- //# debugId=D4294FDC89E3160364756E2164756E21
50
+ //# debugId=E78A002D4B7D692A64756E2164756E21
67
51
  //# sourceMappingURL=index-internal-auth.js.map
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../src/index-internal-auth.ts"],
4
4
  "sourcesContent": [
5
- "// Internal service credentials for first-party consumers of /v1/index and\n// /v1/streams over HTTP (decoder, subgraph processor PublicApiBlockSource).\n// Seeded as internal tenants with NO account_id, so these reads are\n// unmetered (metering gates on account_id). Lives in shared so the API (seed)\n// and the consumers import it without a cycle.\n//\n// Resolution: STREAMS_INTERNAL_API_KEY / INDEX_INTERNAL_API_KEY, then\n// INSTANCE_TOKEN (OSS). No committed fallback. Empty-string env values fall\n// through (`trim()`, then empty): compose interpolates\n// `${STREAMS_INTERNAL_API_KEY:-}` which is \"\" when unset.\n//\n// Archive keys must not use the `sk-sl_` prefix; generate with `sl-int_`.\n// OSS compose should omit the internal env and send INSTANCE_TOKEN.\nexport const INDEX_INTERNAL_TENANT_ID = \"tenant_index_internal\";\nexport const INTERNAL_STREAMS_TENANT_ID = \"tenant_streams_decode_internal\";\n\nconst DEFAULT_INTERNAL_INDEX_BASE_URL = \"http://api:3800\";\n\nconst MISSING_INTERNAL_STREAMS_API_KEY =\n\t\"Set STREAMS_INTERNAL_API_KEY (archive; prefix sl-int_) or INSTANCE_TOKEN (OSS). Empty env no longer falls back to a committed secret.\";\n\nconst MISSING_INTERNAL_INDEX_API_KEY =\n\t\"Set INDEX_INTERNAL_API_KEY (archive; prefix sl-int_) or INSTANCE_TOKEN (OSS). Without one, Index reads go out anonymously and are capped at the last 24h, so any seek into older history 402s.\";\n\nexport function defaultInternalIndexApiKey(\n\tenv: NodeJS.ProcessEnv = process.env,\n): string | undefined {\n\tconst internal = env.INDEX_INTERNAL_API_KEY?.trim();\n\tif (internal) return internal;\n\tconst instance = env.INSTANCE_TOKEN?.trim();\n\tif (instance) return instance;\n\treturn undefined;\n}\n\nexport function defaultInternalStreamsApiKey(\n\tenv: NodeJS.ProcessEnv = process.env,\n): string | undefined {\n\tconst internal = env.STREAMS_INTERNAL_API_KEY?.trim();\n\tif (internal) return internal;\n\tconst instance = env.INSTANCE_TOKEN?.trim();\n\tif (instance) return instance;\n\treturn undefined;\n}\n\n/**\n * Platform-mode Index consumer: refuse to run with neither credential.\n *\n * A keyless Index read is not an error — it is an anonymous read, and the API\n * serves it for the last 24h (`api/src/index/free-window.ts`). That makes a\n * missing key invisible right up until a consumer's cursor falls out of the\n * window, at which point every read 402s and the container goes unhealthy,\n * possibly weeks after the misconfiguration. Callers that seek older history\n * on a platform-mode instance should fail here at startup instead.\n *\n * Self-hosted (oss/dedicated) instances are not gated, so they must NOT call\n * this — `defaultInternalIndexApiKey()` returning undefined is correct there.\n */\nexport function requireInternalIndexApiKey(\n\tenv: NodeJS.ProcessEnv = process.env,\n): string {\n\tconst key = defaultInternalIndexApiKey(env);\n\tif (!key) throw new Error(MISSING_INTERNAL_INDEX_API_KEY);\n\treturn key;\n}\n\n/** Decoder startup: refuse to run with neither credential. */\nexport function requireInternalStreamsApiKey(\n\tenv: NodeJS.ProcessEnv = process.env,\n): string {\n\tconst key = defaultInternalStreamsApiKey(env);\n\tif (!key) throw new Error(MISSING_INTERNAL_STREAMS_API_KEY);\n\treturn key;\n}\n\n/** Shared env contract for decoder + subgraph HTTP dogfood. */\nexport function defaultInternalIndexBaseUrl(): string {\n\treturn (\n\t\tprocess.env.SUBGRAPH_INDEX_API_URL ||\n\t\tprocess.env.STREAMS_API_URL ||\n\t\tDEFAULT_INTERNAL_INDEX_BASE_URL\n\t);\n}\n"
5
+ "// Internal service credentials for first-party consumers of /v1/index and\n// /v1/streams over HTTP (decoder, subgraph processor PublicApiBlockSource).\n// Seeded as internal tenants with NO account_id, so these reads are\n// unmetered (metering gates on account_id). Lives in shared so the API (seed)\n// and the consumers import it without a cycle.\n//\n// Resolution: STREAMS_INTERNAL_API_KEY / INDEX_INTERNAL_API_KEY, then\n// INSTANCE_TOKEN (OSS). No committed fallback. Empty-string env values fall\n// through (`trim()`, then empty): compose interpolates\n// `${STREAMS_INTERNAL_API_KEY:-}` which is \"\" when unset.\n//\n// Archive keys must not use the `sk-sl_` prefix; generate with `sl-int_`.\n// OSS compose should omit the internal env and send INSTANCE_TOKEN.\nexport const INDEX_INTERNAL_TENANT_ID = \"tenant_index_internal\";\nexport const INTERNAL_STREAMS_TENANT_ID = \"tenant_streams_decode_internal\";\n\nconst DEFAULT_INTERNAL_INDEX_BASE_URL = \"http://api:3800\";\n\nconst MISSING_INTERNAL_STREAMS_API_KEY =\n\t\"Set STREAMS_INTERNAL_API_KEY (archive; prefix sl-int_) or INSTANCE_TOKEN (OSS). Empty env no longer falls back to a committed secret.\";\n\nconst MISSING_INTERNAL_INDEX_API_KEY =\n\t\"Set INDEX_INTERNAL_API_KEY (archive; prefix sl-int_) or INSTANCE_TOKEN (OSS). Without one, Index reads carry no credential and platform mode 401s every one of them.\";\n\nexport function defaultInternalIndexApiKey(\n\tenv: NodeJS.ProcessEnv = process.env,\n): string | undefined {\n\tconst internal = env.INDEX_INTERNAL_API_KEY?.trim();\n\tif (internal) return internal;\n\tconst instance = env.INSTANCE_TOKEN?.trim();\n\tif (instance) return instance;\n\treturn undefined;\n}\n\nexport function defaultInternalStreamsApiKey(\n\tenv: NodeJS.ProcessEnv = process.env,\n): string | undefined {\n\tconst internal = env.STREAMS_INTERNAL_API_KEY?.trim();\n\tif (internal) return internal;\n\tconst instance = env.INSTANCE_TOKEN?.trim();\n\tif (instance) return instance;\n\treturn undefined;\n}\n\n/**\n * Platform-mode Index consumer: refuse to run with neither credential.\n *\n * Platform mode requires a credential on every Index read (a keyless read\n * 401s, `api/src/index/auth.ts`) — a first-party consumer with no internal\n * key would fail every request at call time. Fail here at startup instead.\n *\n * Self-hosted (oss/dedicated) instances are not gated, so they must NOT call\n * this — `defaultInternalIndexApiKey()` returning undefined is correct there.\n */\nexport function requireInternalIndexApiKey(\n\tenv: NodeJS.ProcessEnv = process.env,\n): string {\n\tconst key = defaultInternalIndexApiKey(env);\n\tif (!key) throw new Error(MISSING_INTERNAL_INDEX_API_KEY);\n\treturn key;\n}\n\n/** Decoder startup: refuse to run with neither credential. */\nexport function requireInternalStreamsApiKey(\n\tenv: NodeJS.ProcessEnv = process.env,\n): string {\n\tconst key = defaultInternalStreamsApiKey(env);\n\tif (!key) throw new Error(MISSING_INTERNAL_STREAMS_API_KEY);\n\treturn key;\n}\n\n/** Shared env contract for decoder + subgraph HTTP dogfood. */\nexport function defaultInternalIndexBaseUrl(): string {\n\treturn (\n\t\tprocess.env.SUBGRAPH_INDEX_API_URL ||\n\t\tprocess.env.STREAMS_API_URL ||\n\t\tDEFAULT_INTERNAL_INDEX_BASE_URL\n\t);\n}\n"
6
6
  ],
7
- "mappings": ";;;;;;;;;;;;;;;;;AAaO,IAAM,2BAA2B;AACjC,IAAM,6BAA6B;AAE1C,IAAM,kCAAkC;AAExC,IAAM,mCACL;AAED,IAAM,iCACL;AAEM,SAAS,0BAA0B,CACzC,MAAyB,QAAQ,KACZ;AAAA,EACrB,MAAM,WAAW,IAAI,wBAAwB,KAAK;AAAA,EAClD,IAAI;AAAA,IAAU,OAAO;AAAA,EACrB,MAAM,WAAW,IAAI,gBAAgB,KAAK;AAAA,EAC1C,IAAI;AAAA,IAAU,OAAO;AAAA,EACrB;AAAA;AAGM,SAAS,4BAA4B,CAC3C,MAAyB,QAAQ,KACZ;AAAA,EACrB,MAAM,WAAW,IAAI,0BAA0B,KAAK;AAAA,EACpD,IAAI;AAAA,IAAU,OAAO;AAAA,EACrB,MAAM,WAAW,IAAI,gBAAgB,KAAK;AAAA,EAC1C,IAAI;AAAA,IAAU,OAAO;AAAA,EACrB;AAAA;AAgBM,SAAS,0BAA0B,CACzC,MAAyB,QAAQ,KACxB;AAAA,EACT,MAAM,MAAM,2BAA2B,GAAG;AAAA,EAC1C,IAAI,CAAC;AAAA,IAAK,MAAM,IAAI,MAAM,8BAA8B;AAAA,EACxD,OAAO;AAAA;AAID,SAAS,4BAA4B,CAC3C,MAAyB,QAAQ,KACxB;AAAA,EACT,MAAM,MAAM,6BAA6B,GAAG;AAAA,EAC5C,IAAI,CAAC;AAAA,IAAK,MAAM,IAAI,MAAM,gCAAgC;AAAA,EAC1D,OAAO;AAAA;AAID,SAAS,2BAA2B,GAAW;AAAA,EACrD,OACC,QAAQ,IAAI,0BACZ,QAAQ,IAAI,mBACZ;AAAA;",
8
- "debugId": "D4294FDC89E3160364756E2164756E21",
7
+ "mappings": ";AAaO,IAAM,2BAA2B;AACjC,IAAM,6BAA6B;AAE1C,IAAM,kCAAkC;AAExC,IAAM,mCACL;AAED,IAAM,iCACL;AAEM,SAAS,0BAA0B,CACzC,MAAyB,QAAQ,KACZ;AAAA,EACrB,MAAM,WAAW,IAAI,wBAAwB,KAAK;AAAA,EAClD,IAAI;AAAA,IAAU,OAAO;AAAA,EACrB,MAAM,WAAW,IAAI,gBAAgB,KAAK;AAAA,EAC1C,IAAI;AAAA,IAAU,OAAO;AAAA,EACrB;AAAA;AAGM,SAAS,4BAA4B,CAC3C,MAAyB,QAAQ,KACZ;AAAA,EACrB,MAAM,WAAW,IAAI,0BAA0B,KAAK;AAAA,EACpD,IAAI;AAAA,IAAU,OAAO;AAAA,EACrB,MAAM,WAAW,IAAI,gBAAgB,KAAK;AAAA,EAC1C,IAAI;AAAA,IAAU,OAAO;AAAA,EACrB;AAAA;AAaM,SAAS,0BAA0B,CACzC,MAAyB,QAAQ,KACxB;AAAA,EACT,MAAM,MAAM,2BAA2B,GAAG;AAAA,EAC1C,IAAI,CAAC;AAAA,IAAK,MAAM,IAAI,MAAM,8BAA8B;AAAA,EACxD,OAAO;AAAA;AAID,SAAS,4BAA4B,CAC3C,MAAyB,QAAQ,KACxB;AAAA,EACT,MAAM,MAAM,6BAA6B,GAAG;AAAA,EAC5C,IAAI,CAAC;AAAA,IAAK,MAAM,IAAI,MAAM,gCAAgC;AAAA,EAC1D,OAAO;AAAA;AAID,SAAS,2BAA2B,GAAW;AAAA,EACrD,OACC,QAAQ,IAAI,0BACZ,QAAQ,IAAI,mBACZ;AAAA;",
8
+ "debugId": "E78A002D4B7D692A64756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -152,7 +152,6 @@ interface SubgraphsTable {
152
152
  handler_code: string | null;
153
153
  source_code: string | null;
154
154
  project_id: string | null;
155
- visibility: Generated<string>;
156
155
  /** Paid (wallet-ghost) deploys expire unless renewed or claimed; NULL = no expiry. */
157
156
  expires_at: Date | null;
158
157
  /** (event type, contract) probe pairs persisted at deploy for weight classification. */
@@ -782,6 +781,7 @@ interface Database {
782
781
  coverage_segments: CoverageSegmentsTable;
783
782
  stage_failures: StageFailuresTable;
784
783
  archive_fetches: ArchiveFetchesTable;
784
+ usage_ledger: UsageLedgerTable;
785
785
  waitlists: WaitlistsTable;
786
786
  waitlist_signups: WaitlistSignupsTable;
787
787
  }
@@ -835,6 +835,30 @@ interface ArchiveFetchesTable {
835
835
  type ArchiveFetch = Selectable<ArchiveFetchesTable>;
836
836
  type InsertArchiveFetch = Insertable<ArchiveFetchesTable>;
837
837
  type UpdateArchiveFetch = Updateable<ArchiveFetchesTable>;
838
+ /**
839
+ * One metered ledger for every billable unit (archive partitions, hosted
840
+ * Index/Streams rows, and future hosted-stack meters). Append-only, written
841
+ * only by `meter()`. `idempotency_key` is UNIQUE so a retried submission
842
+ * no-ops instead of double-charging. `debited` is false when the balance
843
+ * (or a spend cap) refused the charge — the row still exists so the gap is
844
+ * visible, never silently dropped. `usd_micros` is negative for a Stripe
845
+ * top-up (`unit: "topup"`).
846
+ */
847
+ interface UsageLedgerTable {
848
+ id: Generated<string>;
849
+ account_id: string;
850
+ unit: string;
851
+ quantity: string | number | bigint;
852
+ usd_micros: string | number | bigint;
853
+ debited: Generated<boolean>;
854
+ source: string;
855
+ idempotency_key: string;
856
+ occurred_at: Generated<Date>;
857
+ recorded_at: Generated<Date>;
858
+ }
859
+ type UsageLedgerRow = Selectable<UsageLedgerTable>;
860
+ type InsertUsageLedgerRow = Insertable<UsageLedgerTable>;
861
+ type UpdateUsageLedgerRow = Updateable<UsageLedgerTable>;
838
862
  type Block = Selectable<BlocksTable>;
839
863
  type InsertBlock = Insertable<BlocksTable>;
840
864
  type UpdateBlock = Updateable<BlocksTable>;
@@ -939,6 +963,10 @@ interface WebhookOutboxTable {
939
963
  failed_at: Date | null;
940
964
  locked_by: string | null;
941
965
  locked_until: Date | null;
966
+ /** Set when a reorg marks an in-flight row `dead` instead of retrying it
967
+ * into an orphaned fork. Null otherwise — delivery failures track their
968
+ * history on `webhooks.last_error`, not per-row. */
969
+ last_error: string | null;
942
970
  created_at: Generated<Date>;
943
971
  }
944
972
  type WebhookOutbox = Selectable<WebhookOutboxTable>;
@@ -1034,23 +1062,22 @@ declare function isPox5DecoderEnabled(env?: EnvMap): boolean;
1034
1062
  declare function isSbtcDecoderEnabled(env?: EnvMap): boolean;
1035
1063
  /** Default OFF. Opt in with `BNS_DECODER_ENABLED=true`. */
1036
1064
  declare function isBnsDecoderEnabled(env?: EnvMap): boolean;
1037
- import { RawBuilder } from "kysely";
1038
- /**
1039
- * Safely encode a JS value as a JSONB literal for Kysely inserts/updates.
1040
- * Kysely + postgres.js double-encodes JSON when using parameterized queries
1041
- * with ::jsonb casts. This uses sql.raw to inline a properly escaped literal.
1042
- *
1043
- * Generic parameter lets callers set the RawBuilder's output type so they
1044
- * don't need to cast at the insert site. Default is `unknown` — widen at
1045
- * the call site when the column type is narrower, e.g. `jsonb<MyShape>(...)`.
1046
- */
1047
- declare function jsonb<T = unknown>(value: T): RawBuilder<T>;
1048
- /**
1049
- * Safely parse a JSONB value from the database.
1050
- * Handles double-encoded strings where postgres.js returns a JSON string
1051
- * instead of a parsed object.
1052
- */
1053
- declare function parseJsonb<T = unknown>(value: unknown): T;
1065
+ import { DECODED_EVENT_TYPES, VM_NODE_TO_STORED_TYPE } from "@secondlayer/stacks/filters";
1066
+ import { DecodedEventType } from "@secondlayer/stacks/filters";
1067
+ import { DECODED_EVENT_TYPES as DECODED_EVENT_TYPES2, VM_EVENT_TYPES, VM_NODE_TO_STORED_TYPE as VM_NODE_TO_STORED_TYPE2, DecodedEventType as DecodedEventType2, VmEventType, VmNodeEventType } from "@secondlayer/stacks/filters";
1068
+ type VmStoredToNode = { [K in keyof typeof VM_NODE_TO_STORED_TYPE as (typeof VM_NODE_TO_STORED_TYPE)[K]] : K };
1069
+ /** Inverse of {@link VM_NODE_TO_STORED_TYPE}. Replay reconstruction emits the
1070
+ * node-shaped `/new_block.vm_events` body, so ingest can re-parse it. */
1071
+ declare const VM_STORED_TO_NODE_TYPE: VmStoredToNode;
1072
+ /** Alias kept for the Streams surface (identical to {@link DECODED_EVENT_TYPES}).
1073
+ * Explicit type annotation required — isolatedDeclarations emits `unknown` for
1074
+ * a bare const-to-const alias. */
1075
+ declare const STREAMS_EVENT_TYPES: typeof DECODED_EVENT_TYPES;
1076
+ type StreamsEventType = DecodedEventType;
1077
+ declare const STREAMS_DB_EVENT_TYPES: readonly ["stx_transfer_event", "stx_mint_event", "stx_burn_event", "stx_lock_event", "ft_transfer_event", "ft_mint_event", "ft_burn_event", "nft_transfer_event", "nft_mint_event", "nft_burn_event", "smart_contract_event", "contract_event"];
1078
+ type StreamsDbEventType = (typeof STREAMS_DB_EVENT_TYPES)[number];
1079
+ declare const DB_TO_STREAMS_EVENT_TYPE: Record<StreamsDbEventType, StreamsEventType>;
1080
+ declare const STREAMS_TO_DB_EVENT_TYPES: Record<StreamsEventType, readonly StreamsDbEventType[]>;
1054
1081
  import { Kysely } from "kysely";
1055
1082
  import postgres from "postgres";
1056
1083
  import { sql } from "kysely";
@@ -1886,6 +1913,23 @@ declare const SOURCE_READ_PKS: {
1886
1913
  readonly events: readonly ["tx_id", "event_index"]
1887
1914
  readonly chain_reorgs: null
1888
1915
  };
1916
+ import { RawBuilder } from "kysely";
1917
+ /**
1918
+ * Safely encode a JS value as a JSONB literal for Kysely inserts/updates.
1919
+ * Kysely + postgres.js double-encodes JSON when using parameterized queries
1920
+ * with ::jsonb casts. This uses sql.raw to inline a properly escaped literal.
1921
+ *
1922
+ * Generic parameter lets callers set the RawBuilder's output type so they
1923
+ * don't need to cast at the insert site. Default is `unknown` — widen at
1924
+ * the call site when the column type is narrower, e.g. `jsonb<MyShape>(...)`.
1925
+ */
1926
+ declare function jsonb<T = unknown>(value: T): RawBuilder<T>;
1927
+ /**
1928
+ * Safely parse a JSONB value from the database.
1929
+ * Handles double-encoded strings where postgres.js returns a JSON string
1930
+ * instead of a parsed object.
1931
+ */
1932
+ declare function parseJsonb<T = unknown>(value: unknown): T;
1889
1933
  /**
1890
1934
  * Per-migration DB-plane gating for the source/target split.
1891
1935
  *
@@ -1990,6 +2034,7 @@ declare const TABLE_TO_DB: {
1990
2034
  subgraph_processing_stats: string
1991
2035
  account_credits: string
1992
2036
  archive_fetches: string
2037
+ usage_ledger: string
1993
2038
  waitlists: string
1994
2039
  waitlist_signups: string
1995
2040
  service_heartbeats: string
@@ -2117,9 +2162,9 @@ declare class RateLimitError extends SecondLayerError {
2117
2162
  constructor(message: string);
2118
2163
  }
2119
2164
  /**
2120
- * HTTP 402. Carries the x402 challenge (or a retry-later reason) in `details` so
2121
- * the global error handler emits it in the body. The wire `PAYMENT-REQUIRED`
2122
- * header is set separately by the x402 middleware on the challenge path.
2165
+ * HTTP 402: insufficient credits. Carries a machine-readable reason (e.g.
2166
+ * `insufficient_credits`, `UPGRADE_REQUIRED`) in `details` so the global
2167
+ * error handler emits it in the body, alongside a top-up hint/link.
2123
2168
  */
2124
2169
  declare class PaymentRequiredError extends SecondLayerError {
2125
2170
  constructor(message: string, details?: Record<string, unknown>);
@@ -2142,6 +2187,56 @@ declare class TenantSuspendedError extends SecondLayerError {
2142
2187
  * (avoids cross-bundle instanceof failures from bunup class duplication). */
2143
2188
  declare const CODE_TO_STATUS: Record<string, 400 | 401 | 402 | 403 | 404 | 409 | 415 | 422 | 423 | 429 | 503>;
2144
2189
  declare function getErrorMessage(err: unknown): string;
2190
+ /**
2191
+ * Block finality, anchored to the burn (Bitcoin) chain.
2192
+ *
2193
+ * Post-Nakamoto, Stacks blocks arrive every few seconds, so a fixed count of
2194
+ * Stacks blocks is a poor finality proxy (e.g. 144 fast blocks ≈ 12 minutes).
2195
+ * A Stacks block is final once its anchoring burn block has enough Bitcoin
2196
+ * confirmations — so finality is expressed in burn-block confirmations and
2197
+ * mapped to a Stacks height via the burn_block_height carried on each block.
2198
+ */
2199
+ /** Bitcoin confirmations required before a block is treated as final. ~1 hour. */
2200
+ declare const DEFAULT_BTC_CONFIRMATIONS = 6;
2201
+ /**
2202
+ * Highest burn (Bitcoin) block height considered finalized given the current
2203
+ * burn tip. Stacks blocks whose `burn_block_height` is at or below the result
2204
+ * are final. Returns 0 when the chain is shorter than the confirmation window.
2205
+ */
2206
+ declare function finalizedBurnHeight(burnTipHeight: number, confirmations?: number): number;
2207
+ /**
2208
+ * Canonical Streams cursor codec, shared by every product (Streams, Index,
2209
+ * Datasets, bulk). A cursor is `"<block_height>:<event_index>"` — an opaque,
2210
+ * monotonic resume token. One implementation so encode/decode and the
2211
+ * empty-range sentinel can never drift between products.
2212
+ *
2213
+ * NOTE: this codec IS the shared piece worth centralizing. A broader "shared
2214
+ * canonical reader" across the ~10 raw-event query sites (streams-events,
2215
+ * streams-bulk/query, l2/storage) was deliberately NOT built: those sites split
2216
+ * into distinct query patterns and share only the row_number ordering *pattern*,
2217
+ * not an identical reader. The reorg-archive design (migration 0084) keeps the
2218
+ * main tables canonical-only, so each reader's `WHERE canonical` filter already
2219
+ * needs no dedup logic. Forcing one mega-reader was the wrong abstraction; this
2220
+ * codec captures the only part that actually drifts.
2221
+ */
2222
+ type StreamsCursor = {
2223
+ block_height: number
2224
+ event_index: number
2225
+ };
2226
+ /**
2227
+ * Event index used to advance a cursor past a fully-filtered range instead of
2228
+ * returning null. A filter that eliminates every event in a scanned range would
2229
+ * otherwise pin the consumer at the previous cursor and spin forever. Must fit
2230
+ * in Postgres int4 (the `stream_event_index` column type) — int4 max is plenty,
2231
+ * real blocks have far fewer than ~2.1B events.
2232
+ */
2233
+ declare const EMPTY_RANGE_EVENT_INDEX_SENTINEL = 2147483647;
2234
+ declare function encodeStreamsCursor(cursor: StreamsCursor): string;
2235
+ declare function decodeStreamsCursor(cursor: string): StreamsCursor;
2236
+ declare function compareStreamsCursor(a: StreamsCursor, b: StreamsCursor): number;
2237
+ declare function isEmptyRangeCursor(cursor: StreamsCursor): boolean;
2238
+ /** Exclusive end of every event that can live in `height`. */
2239
+ declare function blockEndCursor(height: number): StreamsCursor;
2145
2240
  declare class Logger {
2146
2241
  private _level?;
2147
2242
  private _isProduction?;
@@ -2160,7 +2255,6 @@ declare const logger: Logger;
2160
2255
  import { z as z2 } from "zod";
2161
2256
  interface DeploySubgraphRequest {
2162
2257
  name: string;
2163
- version?: string;
2164
2258
  description?: string;
2165
2259
  sources: Record<string, Record<string, unknown>>;
2166
2260
  schema: Record<string, unknown>;
@@ -2213,7 +2307,6 @@ interface SubgraphSummary {
2213
2307
  gapCount: number;
2214
2308
  /** history_filling = expected gaps while a tip-first backfill op runs. */
2215
2309
  integrity: "complete" | "gaps_detected" | "history_filling";
2216
- visibility?: "public" | "private";
2217
2310
  /** Most recent indexing error reason + when it occurred, if any. */
2218
2311
  lastError?: string | null;
2219
2312
  lastErrorAt?: string | null;
@@ -2270,7 +2363,6 @@ interface SubgraphDetail {
2270
2363
  version: string;
2271
2364
  schemaHash?: string;
2272
2365
  status: string;
2273
- visibility?: "public" | "private";
2274
2366
  lastProcessedBlock: number;
2275
2367
  description?: string;
2276
2368
  sources?: Record<string, unknown>;
@@ -2583,6 +2675,13 @@ interface WebhookDetail extends WebhookSummary {
2583
2675
  circuitFailures: number;
2584
2676
  circuitOpenedAt: string | null;
2585
2677
  lastError: string | null;
2678
+ /** Set on a `kind="chain"` webhook when this instance's chain-trigger
2679
+ * evaluator isn't running (`SUBGRAPH_SOURCE` != `streams-index`) — the
2680
+ * webhook will never fire until that's fixed. Null otherwise. Surfaced
2681
+ * on create (so it's seen immediately) and on every read (so `secondlayer
2682
+ * webhooks doctor` reports it for a webhook created before the mismatch,
2683
+ * or on an instance whose config changed since). */
2684
+ warning: string | null;
2586
2685
  }
2587
2686
  interface CreateWebhookResponse {
2588
2687
  webhook: WebhookDetail;
@@ -2635,15 +2734,6 @@ type SubgraphSpecFormat = "openapi" | "agent" | "markdown";
2635
2734
  interface SubgraphSpecOptions {
2636
2735
  serverUrl?: string;
2637
2736
  generatedAt?: string;
2638
- /**
2639
- * Self-hosted instances ignore the `visibility` column when deciding
2640
- * whether a read needs a key (`/v1/subgraphs` auth is the loopback rule,
2641
- * not the flag) — but this generator still branched on it, so a spec built
2642
- * for a self-hosted deploy pointed readers at the authenticated `/api`
2643
- * path for a read that was actually open. Callers on that mode should set
2644
- * this so the generated URLs match the auth the API actually enforces.
2645
- */
2646
- forcePublicRead?: boolean;
2647
2737
  }
2648
2738
  interface SubgraphAgentSchema {
2649
2739
  name: string;
@@ -2682,124 +2772,6 @@ declare function generateSubgraphAgentSchema(detail: SubgraphDetail, options?: S
2682
2772
  declare function generateSubgraphOpenApi(detail: SubgraphDetail, options?: SubgraphSpecOptions): Record<string, unknown>;
2683
2773
  declare function generateSubgraphMarkdown(detail: SubgraphDetail, options?: SubgraphSpecOptions): string;
2684
2774
  declare function generateSubgraphSpec(detail: SubgraphDetail, format: SubgraphSpecFormat, options?: SubgraphSpecOptions): Record<string, unknown> | SubgraphAgentSchema | string;
2685
- declare namespace exports_hmac {
2686
- export { verifySignatureHeader, verifySignature, signPayload, generateSecret, createSignatureHeader };
2687
- }
2688
- /**
2689
- * Generate a random secret for delivery signing
2690
- * Returns 32 bytes as a 64-character hex string
2691
- */
2692
- declare function generateSecret(): string;
2693
- /**
2694
- * Sign a payload with HMAC-SHA256
2695
- * Returns the signature as a hex string
2696
- */
2697
- declare function signPayload(payload: string, secret: string): string;
2698
- /**
2699
- * Verify an HMAC signature
2700
- * Uses constant-time comparison to prevent timing attacks
2701
- */
2702
- declare function verifySignature(payload: string, signature: string, secret: string): boolean;
2703
- /**
2704
- * Create a Stripe-style signature header
2705
- * Format: t=timestamp,v1=signature
2706
- */
2707
- declare function createSignatureHeader(payload: string, secret: string, timestamp?: number): string;
2708
- /**
2709
- * Parse and verify a Stripe-style signature header
2710
- * Returns true if valid, false otherwise
2711
- */
2712
- declare function verifySignatureHeader(payload: string, header: string, secret: string, toleranceSeconds?: number): boolean;
2713
- declare namespace exports_ed25519 {
2714
- export { verifyEd25519, signEd25519, publicKeyPemFromPrivate, loadEd25519PublicKey, loadEd25519PrivateKey, generateEd25519KeyPair, ed25519KeyId };
2715
- }
2716
- import { KeyObject } from "node:crypto";
2717
- /**
2718
- * Asymmetric ed25519 signing for Streams response proofs.
2719
- *
2720
- * Asymmetric (not HMAC) so the proof is real: only the server holds the private
2721
- * key, and any consumer verifies with the published public key — no shared
2722
- * secret to leak. ed25519 uses node's `sign`/`verify` with a `null` algorithm.
2723
- * Keys are PEM (PKCS8 private / SPKI public) for env transport; load once and
2724
- * reuse the KeyObject on hot paths.
2725
- */
2726
- declare function generateEd25519KeyPair(): {
2727
- privateKeyPem: string
2728
- publicKeyPem: string
2729
- };
2730
- declare function loadEd25519PrivateKey(pem: string): KeyObject;
2731
- declare function loadEd25519PublicKey(pem: string): KeyObject;
2732
- declare function publicKeyPemFromPrivate(privateKeyPem: string): string;
2733
- /** Stable short id for a public key (rotation hint via X-Signature-KeyId). */
2734
- declare function ed25519KeyId(publicKeyPem: string): string;
2735
- declare function signEd25519(payload: string, privateKey: KeyObject): string;
2736
- declare function verifyEd25519(payload: string, signatureBase64: string, publicKey: KeyObject): boolean;
2737
- import { DECODED_EVENT_TYPES, VM_NODE_TO_STORED_TYPE } from "@secondlayer/stacks/filters";
2738
- import { DecodedEventType } from "@secondlayer/stacks/filters";
2739
- import { DECODED_EVENT_TYPES as DECODED_EVENT_TYPES2, VM_EVENT_TYPES, VM_NODE_TO_STORED_TYPE as VM_NODE_TO_STORED_TYPE2, DecodedEventType as DecodedEventType2, VmEventType, VmNodeEventType } from "@secondlayer/stacks/filters";
2740
- type VmStoredToNode = { [K in keyof typeof VM_NODE_TO_STORED_TYPE as (typeof VM_NODE_TO_STORED_TYPE)[K]] : K };
2741
- /** Inverse of {@link VM_NODE_TO_STORED_TYPE}. Replay reconstruction emits the
2742
- * node-shaped `/new_block.vm_events` body, so ingest can re-parse it. */
2743
- declare const VM_STORED_TO_NODE_TYPE: VmStoredToNode;
2744
- /** Alias kept for the Streams surface (identical to {@link DECODED_EVENT_TYPES}).
2745
- * Explicit type annotation required — isolatedDeclarations emits `unknown` for
2746
- * a bare const-to-const alias. */
2747
- declare const STREAMS_EVENT_TYPES: typeof DECODED_EVENT_TYPES;
2748
- type StreamsEventType = DecodedEventType;
2749
- declare const STREAMS_DB_EVENT_TYPES: readonly ["stx_transfer_event", "stx_mint_event", "stx_burn_event", "stx_lock_event", "ft_transfer_event", "ft_mint_event", "ft_burn_event", "nft_transfer_event", "nft_mint_event", "nft_burn_event", "smart_contract_event", "contract_event"];
2750
- type StreamsDbEventType = (typeof STREAMS_DB_EVENT_TYPES)[number];
2751
- declare const DB_TO_STREAMS_EVENT_TYPE: Record<StreamsDbEventType, StreamsEventType>;
2752
- declare const STREAMS_TO_DB_EVENT_TYPES: Record<StreamsEventType, readonly StreamsDbEventType[]>;
2753
- /**
2754
- * Block finality, anchored to the burn (Bitcoin) chain.
2755
- *
2756
- * Post-Nakamoto, Stacks blocks arrive every few seconds, so a fixed count of
2757
- * Stacks blocks is a poor finality proxy (e.g. 144 fast blocks ≈ 12 minutes).
2758
- * A Stacks block is final once its anchoring burn block has enough Bitcoin
2759
- * confirmations — so finality is expressed in burn-block confirmations and
2760
- * mapped to a Stacks height via the burn_block_height carried on each block.
2761
- */
2762
- /** Bitcoin confirmations required before a block is treated as final. ~1 hour. */
2763
- declare const DEFAULT_BTC_CONFIRMATIONS = 6;
2764
- /**
2765
- * Highest burn (Bitcoin) block height considered finalized given the current
2766
- * burn tip. Stacks blocks whose `burn_block_height` is at or below the result
2767
- * are final. Returns 0 when the chain is shorter than the confirmation window.
2768
- */
2769
- declare function finalizedBurnHeight(burnTipHeight: number, confirmations?: number): number;
2770
- /**
2771
- * Canonical Streams cursor codec, shared by every product (Streams, Index,
2772
- * Datasets, bulk). A cursor is `"<block_height>:<event_index>"` — an opaque,
2773
- * monotonic resume token. One implementation so encode/decode and the
2774
- * empty-range sentinel can never drift between products.
2775
- *
2776
- * NOTE: this codec IS the shared piece worth centralizing. A broader "shared
2777
- * canonical reader" across the ~10 raw-event query sites (streams-events,
2778
- * streams-bulk/query, l2/storage) was deliberately NOT built: those sites split
2779
- * into distinct query patterns and share only the row_number ordering *pattern*,
2780
- * not an identical reader. The reorg-archive design (migration 0084) keeps the
2781
- * main tables canonical-only, so each reader's `WHERE canonical` filter already
2782
- * needs no dedup logic. Forcing one mega-reader was the wrong abstraction; this
2783
- * codec captures the only part that actually drifts.
2784
- */
2785
- type StreamsCursor = {
2786
- block_height: number
2787
- event_index: number
2788
- };
2789
- /**
2790
- * Event index used to advance a cursor past a fully-filtered range instead of
2791
- * returning null. A filter that eliminates every event in a scanned range would
2792
- * otherwise pin the consumer at the previous cursor and spin forever. Must fit
2793
- * in Postgres int4 (the `stream_event_index` column type) — int4 max is plenty,
2794
- * real blocks have far fewer than ~2.1B events.
2795
- */
2796
- declare const EMPTY_RANGE_EVENT_INDEX_SENTINEL = 2147483647;
2797
- declare function encodeStreamsCursor(cursor: StreamsCursor): string;
2798
- declare function decodeStreamsCursor(cursor: string): StreamsCursor;
2799
- declare function compareStreamsCursor(a: StreamsCursor, b: StreamsCursor): number;
2800
- declare function isEmptyRangeCursor(cursor: StreamsCursor): boolean;
2801
- /** Exclusive end of every event that can live in `height`. */
2802
- declare function blockEndCursor(height: number): StreamsCursor;
2803
2775
  /**
2804
2776
  * Payload for `sbtc_deposit` (topic: completed-deposit).
2805
2777
  * `sender` is the Stacks address that initiated the deposit and receives the sBTC.
@@ -3059,4 +3031,56 @@ interface ChainTestDelivery {
3059
3031
  * "Chain webhook webhook payloads" doc.
3060
3032
  */
3061
3033
  type ChainWebhookDelivery = ChainApplyDeliveryOf<"stx_transfer", ChainEventEnvelope<"stx_transfer_event", ChainStxTransferData>> | ChainApplyDeliveryOf<"stx_mint", ChainEventEnvelope<"stx_mint_event", ChainStxMintData>> | ChainApplyDeliveryOf<"stx_burn", ChainEventEnvelope<"stx_burn_event", ChainStxBurnData>> | ChainApplyDeliveryOf<"stx_lock", ChainEventEnvelope<"stx_lock_event", ChainStxLockData>> | ChainApplyDeliveryOf<"ft_transfer", ChainEventEnvelope<"ft_transfer_event", ChainFtTransferData>> | ChainApplyDeliveryOf<"ft_mint", ChainEventEnvelope<"ft_mint_event", ChainFtMintData>> | ChainApplyDeliveryOf<"ft_burn", ChainEventEnvelope<"ft_burn_event", ChainFtBurnData>> | ChainApplyDeliveryOf<"nft_transfer", ChainEventEnvelope<"nft_transfer_event", ChainNftTransferData>> | ChainApplyDeliveryOf<"nft_mint", ChainEventEnvelope<"nft_mint_event", ChainNftMintData>> | ChainApplyDeliveryOf<"nft_burn", ChainEventEnvelope<"nft_burn_event", ChainNftBurnData>> | ChainApplyDeliveryOf<"print_event", ChainEventEnvelope<"contract_event", ChainPrintEventData>> | ChainApplyDeliveryOf<"contract_call", ChainTxLevelEvent> | ChainApplyDeliveryOf<"contract_deploy", ChainTxLevelEvent> | ChainApplyDeliveryOf<"sbtc_deposit", SbtcDepositEvent> | ChainApplyDeliveryOf<"sbtc_withdrawal_create", SbtcWithdrawalEvent> | ChainApplyDeliveryOf<"sbtc_withdrawal_accept", SbtcWithdrawalEvent> | ChainApplyDeliveryOf<"sbtc_withdrawal_reject", SbtcWithdrawalEvent> | ChainApplyDeliveryOf<"sbtc_withdrawal_swept_confirmed", SbtcWithdrawalSweptConfirmedEvent> | ChainReorgRollbackDelivery | ChainTestDelivery;
3062
- export { validateWebhookFilterForTable, sql, setMigrationRole, parseJsonb, onControlPlane, onChainPlane, logger, jsonb, isSbtcDecoderEnabled, isPox5DecoderEnabled, isPox4DecoderEnabled, isEmptyRangeCursor, isBnsDecoderEnabled, getTargetDb, getSourceDb, getRawClientFor, getRawClient, getMigrationRole, getErrorMessage, getEnv, getDbSplitStatus, getDb, generateSubgraphSpec, generateSubgraphOpenApi, generateSubgraphMarkdown, generateSubgraphAgentSchema, formatWebhookSchemaErrors, finalizedBurnHeight, encodeStreamsCursor, exports_ed25519 as ed25519, decodeStreamsCursor, exports_hmac as crypto, compareStreamsCursor, closeDb, blockEndCursor, assertDbSplit, applicationDatabaseUrl, WebhooksTable, WebhookSummary, WebhookStatusSchema, WebhookStatus, WebhookSchemaTables, WebhookSchemaTable, WebhookSchemaColumn, WebhookRuntimeSchema, WebhookRuntime, WebhookOutboxTable, WebhookOutbox, WebhookKind, WebhookFormatSchema, WebhookFormat, WebhookFilterSchema, WebhookFilterPrimitiveSchema, WebhookFilterPrimitive, WebhookFilterOperatorSchema, WebhookFilterOperator, WebhookFilterClauseSchema, WebhookFilterClause, WebhookFilter, WebhookDetail, WebhookDelivery, WebhookDeliveriesTable, Webhook, WaitlistsTable, WaitlistSignupsTable, WaitlistSignup, Waitlist, WEBHOOK_STATUSES, WEBHOOK_RUNTIMES, WEBHOOK_FORMATS, WEBHOOK_FILTER_OPERATORS, VmNodeEventType, VmEventsTable, VmEventsArchiveTable, VmEventType, VmEvent, VersionConflictError, ValidationError, VM_STORED_TO_NODE_TYPE, VM_NODE_TO_STORED_TYPE2 as VM_NODE_TO_STORED_TYPE, VM_EVENT_TYPES, UpdateWebhookRequestSchema, UpdateWebhookRequest, UpdateWebhookOutbox, UpdateWebhook, UpdateVmEvent, UpdateTransaction, UpdateSubgraphOperation, UpdateSubgraph, UpdateIndexProgress, UpdateEvent, UpdateContract, UpdateBlock, UpdateArchiveFetch, UpdateApiKey, UpdateAccountSpendCap, UpdateAccountCredits, TriggerEvaluatorStateTable, TriggerEvaluatorState, TransactionsTable, TransactionsArchiveTable, Transaction, TenantSuspendedError, TABLE_TO_DB, SyncScopesTable, SubgraphsTable, SubgraphViolationsTable, SubgraphSyncInfo, SubgraphSummary, SubgraphSpecOptions, SubgraphSpecFormat, SubgraphQueryParams, SubgraphProcessingStatsTable, SubgraphOperationsTable, SubgraphOperationStatus, SubgraphOperationKind, SubgraphOperation, SubgraphHealthSnapshotsTable, SubgraphHealthSnapshot, SubgraphGapsTable, SubgraphGapsResponse, SubgraphGapRange, SubgraphGapEntry, SubgraphGap, SubgraphDetail, SubgraphAggregateResponse, SubgraphAggregateParams, SubgraphAgentSchema, Subgraph, StreamsEventType, StreamsDbEventType, StreamsCursor, StageRunsTable, StageRegistryTable, StageKind, StageFailuresTable, StageBlockReceiptsTable, SessionsTable, Session, ServiceHeartbeatsTable, SecondLayerError, SbtcWithdrawalSweptConfirmedEvent, SbtcWithdrawalEvent, SbtcTokenEventsTable, SbtcTokenEventType, SbtcSettlementsTable, SbtcEventsTable, SbtcEventTopic, SbtcDepositEvent, STREAMS_TO_DB_EVENT_TYPES, STREAMS_EVENT_TYPES, STREAMS_DB_EVENT_TYPES, SOURCE_READ_TYPES, SOURCE_READ_PKS, SOURCE_READ_COLUMNS, RunStatus, RotateSecretResponse, RetryState, ReplayWebhookRequestSchema, ReplayWebhookRequest, ReplayResult, RepairMode, ReindexResponse, RateLimitError, ProcessedStripeEventsTable, Pox5EventsTable, Pox5EventTopic, Pox4FunctionName, Pox4CallsTable, PendingForkBlocksTable, PaymentRequiredError, ParsedUpdateWebhookRequest, ParsedReplayWebhookRequest, ParsedCreateWebhookRequest, OutboxStatus, ObserverJournalTable, ObserverJournalStatus, NumericAsText, NotFoundError, NativeClock, MigrationRole, MempoolTransactionsTable, MempoolTransaction, MagicLinksTable, MagicLink, KeyRotatedError, InstancesTable, InsertWebhookOutbox, InsertWebhookDelivery, InsertWebhook, InsertWaitlistSignup, InsertVmEvent, InsertTransaction, InsertSubgraphOperation, InsertSubgraphHealthSnapshot, InsertSubgraphGap, InsertSubgraph, InsertSession, InsertMempoolTransaction, InsertMagicLink, InsertIndexProgress, InsertEvent, InsertContract, InsertBlock, InsertArchiveFetch, InsertApiKey, InsertAccountSpendCap, InsertAccountCredits, InsertAccount, IndexProgressTable, IndexProgress, IndexPrimaryKey, IndexColumnType, IndexColumn, ForbiddenError, FailureUnit, FailureClass, EventsTable, EventsArchiveTable, Event, ErrorCodes, ErrorCode, Env, EMPTY_RANGE_EVENT_INDEX_SENTINEL, DeploySubgraphResponse, DeploySubgraphRequestSchema, DeploySubgraphRequest, DeliveryRow, DecoderCheckpointsTable, DecodedEventsTable, DecodedEventType2 as DecodedEventType, DeadRow, DeadLetterEventsTable, DbSplitStatus, DbReadRow, DbPlane, DatabaseError, Database, DEFAULT_BTC_CONFIRMATIONS, DECODED_EVENT_TYPES2 as DECODED_EVENT_TYPES, DB_TO_STREAMS_EVENT_TYPE, CreateWebhookResponse, CreateWebhookRequestSchema, CreateWebhookRequest, CoverageSegmentsTable, ContractsTable, Contract, ChainWebhookEnvelope, ChainWebhookDelivery, ChainTxLevelEvent, ChainTestDelivery, ChainStxTransferData, ChainStxMintData, ChainStxLockData, ChainStxBurnData, ChainReorgsTable, ChainReorgRollbackEnvelope, ChainReorgRollbackDelivery, ChainReorgOrphanedEntry, ChainReadCacheTable, ChainPrintEventData, ChainNftTransferData, ChainNftMintData, ChainNftBurnData, ChainFtTransferData, ChainFtMintData, ChainFtBurnData, ChainEventEnvelope, ChainApplyEnvelopeOf, ChainApplyEnvelope, ChainApplyDeliveryOf, CODE_TO_STATUS, CHAIN_TRIGGER_TYPES, CHAIN_TRIGGER_FIELDS, BurnBlockRewardsTable, BurnBlockRewardSlotsTable, BnsNamespacesTable, BnsNamespaceEventsTable, BnsNamespaceEventStatus, BnsNamesTable, BnsNameEventsTable, BnsNameEventTopic, BnsMarketplaceEventsTable, BnsMarketplaceAction, BlocksTable, Block, AuthorizationError, AuthenticationError, ArchiveFetchesTable, ArchiveFetch, ApiKeysTable, ApiKey, AccountsTable, AccountSpendCapsTable, AccountSpendCap, AccountCreditsTable, AccountCredits, Account };
3034
+ declare namespace exports_hmac {
3035
+ export { createSignatureHeader, generateSecret, signPayload, verifySignature, verifySignatureHeader };
3036
+ }
3037
+ /**
3038
+ * Generate a random secret for delivery signing
3039
+ * Returns 32 bytes as a 64-character hex string
3040
+ */
3041
+ declare function generateSecret(): string;
3042
+ /**
3043
+ * Sign a payload with HMAC-SHA256
3044
+ * Returns the signature as a hex string
3045
+ */
3046
+ declare function signPayload(payload: string, secret: string): string;
3047
+ /**
3048
+ * Verify an HMAC signature
3049
+ * Uses constant-time comparison to prevent timing attacks
3050
+ */
3051
+ declare function verifySignature(payload: string, signature: string, secret: string): boolean;
3052
+ /**
3053
+ * Create a Stripe-style signature header
3054
+ * Format: t=timestamp,v1=signature
3055
+ */
3056
+ declare function createSignatureHeader(payload: string, secret: string, timestamp?: number): string;
3057
+ /**
3058
+ * Parse and verify a Stripe-style signature header
3059
+ * Returns true if valid, false otherwise
3060
+ */
3061
+ declare function verifySignatureHeader(payload: string, header: string, secret: string, toleranceSeconds?: number): boolean;
3062
+ declare namespace exports_ed25519 {
3063
+ export { ed25519KeyId, generateEd25519KeyPair, loadEd25519PrivateKey, loadEd25519PublicKey, publicKeyPemFromPrivate, signEd25519, verifyEd25519 };
3064
+ }
3065
+ import { KeyObject } from "node:crypto";
3066
+ /**
3067
+ * Asymmetric ed25519 signing for Streams response proofs.
3068
+ *
3069
+ * Asymmetric (not HMAC) so the proof is real: only the server holds the private
3070
+ * key, and any consumer verifies with the published public key — no shared
3071
+ * secret to leak. ed25519 uses node's `sign`/`verify` with a `null` algorithm.
3072
+ * Keys are PEM (PKCS8 private / SPKI public) for env transport; load once and
3073
+ * reuse the KeyObject on hot paths.
3074
+ */
3075
+ declare function generateEd25519KeyPair(): {
3076
+ privateKeyPem: string
3077
+ publicKeyPem: string
3078
+ };
3079
+ declare function loadEd25519PrivateKey(pem: string): KeyObject;
3080
+ declare function loadEd25519PublicKey(pem: string): KeyObject;
3081
+ declare function publicKeyPemFromPrivate(privateKeyPem: string): string;
3082
+ /** Stable short id for a public key (rotation hint via X-Signature-KeyId). */
3083
+ declare function ed25519KeyId(publicKeyPem: string): string;
3084
+ declare function signEd25519(payload: string, privateKey: KeyObject): string;
3085
+ declare function verifyEd25519(payload: string, signatureBase64: string, publicKey: KeyObject): boolean;
3086
+ export { Account, AccountCredits, AccountCreditsTable, AccountSpendCap, AccountSpendCapsTable, AccountsTable, ApiKey, ApiKeysTable, ArchiveFetch, ArchiveFetchesTable, AuthenticationError, AuthorizationError, Block, BlocksTable, BnsMarketplaceAction, BnsMarketplaceEventsTable, BnsNameEventTopic, BnsNameEventsTable, BnsNamesTable, BnsNamespaceEventStatus, BnsNamespaceEventsTable, BnsNamespacesTable, BurnBlockRewardSlotsTable, BurnBlockRewardsTable, CHAIN_TRIGGER_FIELDS, CHAIN_TRIGGER_TYPES, CODE_TO_STATUS, ChainApplyDeliveryOf, ChainApplyEnvelope, ChainApplyEnvelopeOf, ChainEventEnvelope, ChainFtBurnData, ChainFtMintData, ChainFtTransferData, ChainNftBurnData, ChainNftMintData, ChainNftTransferData, ChainPrintEventData, ChainReadCacheTable, ChainReorgOrphanedEntry, ChainReorgRollbackDelivery, ChainReorgRollbackEnvelope, ChainReorgsTable, ChainStxBurnData, ChainStxLockData, ChainStxMintData, ChainStxTransferData, ChainTestDelivery, ChainTxLevelEvent, ChainWebhookDelivery, ChainWebhookEnvelope, Contract, ContractsTable, CoverageSegmentsTable, CreateWebhookRequest, CreateWebhookRequestSchema, CreateWebhookResponse, DB_TO_STREAMS_EVENT_TYPE, DECODED_EVENT_TYPES2 as DECODED_EVENT_TYPES, DEFAULT_BTC_CONFIRMATIONS, Database, DatabaseError, DbPlane, DbReadRow, DbSplitStatus, DeadLetterEventsTable, DeadRow, DecodedEventType2 as DecodedEventType, DecodedEventsTable, DecoderCheckpointsTable, DeliveryRow, DeploySubgraphRequest, DeploySubgraphRequestSchema, DeploySubgraphResponse, EMPTY_RANGE_EVENT_INDEX_SENTINEL, Env, ErrorCode, ErrorCodes, Event, EventsArchiveTable, EventsTable, FailureClass, FailureUnit, ForbiddenError, IndexColumn, IndexColumnType, IndexPrimaryKey, IndexProgress, IndexProgressTable, InsertAccount, InsertAccountCredits, InsertAccountSpendCap, InsertApiKey, InsertArchiveFetch, InsertBlock, InsertContract, InsertEvent, InsertIndexProgress, InsertMagicLink, InsertMempoolTransaction, InsertSession, InsertSubgraph, InsertSubgraphGap, InsertSubgraphHealthSnapshot, InsertSubgraphOperation, InsertTransaction, InsertUsageLedgerRow, InsertVmEvent, InsertWaitlistSignup, InsertWebhook, InsertWebhookDelivery, InsertWebhookOutbox, InstancesTable, KeyRotatedError, MagicLink, MagicLinksTable, MempoolTransaction, MempoolTransactionsTable, MigrationRole, NativeClock, NotFoundError, NumericAsText, ObserverJournalStatus, ObserverJournalTable, OutboxStatus, ParsedCreateWebhookRequest, ParsedReplayWebhookRequest, ParsedUpdateWebhookRequest, PaymentRequiredError, PendingForkBlocksTable, Pox4CallsTable, Pox4FunctionName, Pox5EventTopic, Pox5EventsTable, ProcessedStripeEventsTable, RateLimitError, ReindexResponse, RepairMode, ReplayResult, ReplayWebhookRequest, ReplayWebhookRequestSchema, RetryState, RotateSecretResponse, RunStatus, SOURCE_READ_COLUMNS, SOURCE_READ_PKS, SOURCE_READ_TYPES, STREAMS_DB_EVENT_TYPES, STREAMS_EVENT_TYPES, STREAMS_TO_DB_EVENT_TYPES, SbtcDepositEvent, SbtcEventTopic, SbtcEventsTable, SbtcSettlementsTable, SbtcTokenEventType, SbtcTokenEventsTable, SbtcWithdrawalEvent, SbtcWithdrawalSweptConfirmedEvent, SecondLayerError, ServiceHeartbeatsTable, Session, SessionsTable, StageBlockReceiptsTable, StageFailuresTable, StageKind, StageRegistryTable, StageRunsTable, StreamsCursor, StreamsDbEventType, StreamsEventType, Subgraph, SubgraphAgentSchema, SubgraphAggregateParams, SubgraphAggregateResponse, SubgraphDetail, SubgraphGap, SubgraphGapEntry, SubgraphGapRange, SubgraphGapsResponse, SubgraphGapsTable, SubgraphHealthSnapshot, SubgraphHealthSnapshotsTable, SubgraphOperation, SubgraphOperationKind, SubgraphOperationStatus, SubgraphOperationsTable, SubgraphProcessingStatsTable, SubgraphQueryParams, SubgraphSpecFormat, SubgraphSpecOptions, SubgraphSummary, SubgraphSyncInfo, SubgraphViolationsTable, SubgraphsTable, SyncScopesTable, TABLE_TO_DB, TenantSuspendedError, Transaction, TransactionsArchiveTable, TransactionsTable, TriggerEvaluatorState, TriggerEvaluatorStateTable, UpdateAccountCredits, UpdateAccountSpendCap, UpdateApiKey, UpdateArchiveFetch, UpdateBlock, UpdateContract, UpdateEvent, UpdateIndexProgress, UpdateSubgraph, UpdateSubgraphOperation, UpdateTransaction, UpdateUsageLedgerRow, UpdateVmEvent, UpdateWebhook, UpdateWebhookOutbox, UpdateWebhookRequest, UpdateWebhookRequestSchema, UsageLedgerRow, UsageLedgerTable, VM_EVENT_TYPES, VM_NODE_TO_STORED_TYPE2 as VM_NODE_TO_STORED_TYPE, VM_STORED_TO_NODE_TYPE, ValidationError, VersionConflictError, VmEvent, VmEventType, VmEventsArchiveTable, VmEventsTable, VmNodeEventType, WEBHOOK_FILTER_OPERATORS, WEBHOOK_FORMATS, WEBHOOK_RUNTIMES, WEBHOOK_STATUSES, Waitlist, WaitlistSignup, WaitlistSignupsTable, WaitlistsTable, Webhook, WebhookDeliveriesTable, WebhookDelivery, WebhookDetail, WebhookFilter, WebhookFilterClause, WebhookFilterClauseSchema, WebhookFilterOperator, WebhookFilterOperatorSchema, WebhookFilterPrimitive, WebhookFilterPrimitiveSchema, WebhookFilterSchema, WebhookFormat, WebhookFormatSchema, WebhookKind, WebhookOutbox, WebhookOutboxTable, WebhookRuntime, WebhookRuntimeSchema, WebhookSchemaColumn, WebhookSchemaTable, WebhookSchemaTables, WebhookStatus, WebhookStatusSchema, WebhookSummary, WebhooksTable, applicationDatabaseUrl, assertDbSplit, blockEndCursor, closeDb, compareStreamsCursor, exports_hmac as crypto, decodeStreamsCursor, exports_ed25519 as ed25519, encodeStreamsCursor, finalizedBurnHeight, formatWebhookSchemaErrors, generateSubgraphAgentSchema, generateSubgraphMarkdown, generateSubgraphOpenApi, generateSubgraphSpec, getDb, getDbSplitStatus, getEnv, getErrorMessage, getMigrationRole, getRawClient, getRawClientFor, getSourceDb, getTargetDb, isBnsDecoderEnabled, isEmptyRangeCursor, isPox4DecoderEnabled, isPox5DecoderEnabled, isSbtcDecoderEnabled, jsonb, logger, onChainPlane, onControlPlane, parseJsonb, setMigrationRole, sql, validateWebhookFilterForTable };