Introducing The Sweep: OX’s New Live Security Research Series
Register Now
Breaking: The 2026 Vulnpocalypse Hits PHP: Four Critical RCEs, but How Dangerous Are They?
Read the Report
Are you exposed? Connect your apps in minutes.
Scan your apps free

@secondlayer/sdk

Latest version: v20.5.2

Overview

Last scanned
28 Nov 2026
Published
28 Nov 2026
npm package Publisher: ryanwaits
8 Stars
3 Forks
68 Versions
5.4K Downloads
TypeScript Repo language

Scan summary

@secondlayer/sdk was last scanned on 28 Nov 2026 at version 20.5.2. Risk score 0 of 100. No malicious behavior was detected.

  • Releases: 68 versions; the latest 5 were published within 5 days (24–28 Nov 2026).
  • Findings: No rules fired in version 20.5.2.
  • Downloads: 5,364 downloads.

Versions

68 versions published
Versions and the rules that fired in each
VersionPublishedStatus
20.5.2 LATEST 28 Nov 2026 No rules fired
20.5.1 27 Nov 2026 No rules fired
20.5.0 26 Nov 2026 No rules fired
20.4.0 25 Nov 2026 Not shown
20.3.0 24 Nov 2026 Not shown

No rules fired in 20.5.2

Findings

Findings for v20.5.2. The score is a capped sum of the weights of the rules that fired — not CVSS, not exploitability, and not a probability. It is not comparable across packages with different scan coverage.

The score describes 20.5.2; other versions have their own rules, not their own score.

README

The publisher’s own README, as collected from the registry.

@secondlayer/sdk

TypeScript SDK for the Secondlayer API.

Install

bun add @secondlayer/sdk

Quick Start

import { SecondLayer } from "@secondlayer/sdk";

const sl = new SecondLayer({
  apiKey: process.env.INSTANCE_TOKEN, // from secondlayer init; read from the env when omitted
  // default baseUrl: SECONDLAYER_API_URL, else http://127.0.0.1:3800
});

Hosted: set SECONDLAYER_API_KEY or pass apiKey (sk-sl_*) and the client uses https://api.secondlayer.tools. Self-host: use INSTANCE_TOKEN as below, which keeps the client on your instance even with an account key set. The key follows the host.

Auth, once (self-hosted instance): sl.index, sl.streams, sl.subgraphs.rows, and the typed subscribe read /v1, which is open on loopback and needs INSTANCE_TOKEN once the API is bound beyond it. Everything under sl.subgraphs.* and sl.webhooks.* calls /api, which needs INSTANCE_TOKEN as soon as one is configured, loopback included, and secondlayer init always configures one. Every client, including createStreamsClient, reads INSTANCE_TOKEN from the env when apiKey is omitted; pass apiKey: "" to force a keyless call. Public archive dumps (sl.streams.dumps) need no instance key.

Mental model

Everything is indexing — the question is how much of the indexer you run:

  • sl.index: every Stacks event, already decoded, from block 1, including contract state: read FT/NFT transfers, all event types (events), and contractCalls — or build your own app index on them with the checkpointed consume() loop (automatic reorg rewind), walk() sweeps, and resumable cursors on every page.
  • sl.subgraphs — deploy your own indexer (one defineSubgraph() file via the CLI), then read the tables on this instance.
  • sl.streams: exactly what the Stacks node emitted, in order, the feed Index is built on, with a checkpointed consume() and dumps replay() for building from zero.
  • sl.contracts — find deployed contracts by trait (SIP-009/010/013).

Streams

Typed HTTP client for Streams: exactly what the node emitted, in order. /v1 reads need no key on loopback.

const tip = await sl.streams.tip();
// tip.finalized_height — highest immutable (past Bitcoin-anchored finality) block
const page = await sl.streams.events.list({
  types: ["ft_transfer"],
  contractId: "SP...sbtc-token",
  sender: "SP...",       // exact payload sender (events that have one)
  recipient: "SP...",    // exact payload recipient
  assetIdentifier: "SP...token::asset", // exact FT/NFT asset id
  limit: 10,
});
// each event carries `finalized: boolean`
console.log({ tip, firstCursor: page.events[0]?.cursor });

createStreamsClient remains available for focused Streams-only consumers:

import { createStreamsClient } from "@secondlayer/sdk";

const streams = createStreamsClient({
  // apiKey: process.env.INSTANCE_TOKEN, // read from the env when omitted
  // verify: true,                 // verify ed25519 X-Signature on every read
  //                               // (auto-fetches the public key; { publicKey } pins a PEM)
  // dumpsBaseUrl: process.env.SL_STREAMS_DUMPS_URL, // required to use client.dumps
});

Verified responses: every Streams read is signed (ed25519 X-Signature + X-Signature-KeyId). Pass verify: true to check it on every read (or { publicKey } to pin a PEM); a missing/bad signature throws StreamsSignatureError. The public key is at GET /public/streams/signing-key. verify and verifyDumpsManifest are accepted by new SecondLayer({...}) too and reach sl.streams.

What verify: true proves depends on where the key came from. Over https, or on loopback, the key is fetched once from the instance and cached; a 5xx on that fetch surfaces as a retryable StreamsServerError and the next read fetches again. Over plain http to any other host the key travels the same unprotected path as the data, so the client refuses verify: true there and asks for verify: { publicKey } instead. The tradeoff: you copy the PEM once, and a server-side rotation then fails closed until you update it.

Convenience reads:

await sl.streams.canonical(182431);
await sl.streams.events.byTxId("0x...");
await sl.streams.blocks.events(182431);
await sl.streams.blocks.events("0xindex-block-hash");
await sl.streams.reorgs.list({ since: "2026-05-03T00:00:00.000Z" });

Checkpointed consumer.

Use client.events.consume for indexers and ETL jobs. Write your database rows inside onBatch, then return the cursor you committed. It exits when maxPages, maxEmptyPolls, or signal stops it.

await streams.events.consume({
  types: ["ft_transfer"],
  batchSize: 100,
  maxPages: 1,
  onBatch: async (events, ctx) => {
    for (const event of events) {
      console.log(event.cursor, event.tx_id);
    }
    return ctx.cursor;
  },
});

Live stream.

Use client.events.stream for live processors and watch-style apps. It follows the tip indefinitely. Stop it with an AbortSignal.

const abort = new AbortController();
process.once("SIGINT", () => abort.abort());

for await (const event of streams.events.stream({
  types: ["ft_transfer"],
  batchSize: 100,
  signal: abort.signal,
})) {
  console.log(event.cursor, event.tx_id);
}

Real-time push (events.subscribe).

Use client.events.subscribe for callback-style live delivery: it pushes each event to onEvent as it lands. It's fetch-based (so it carries the Bearer key) and works in browsers and Node 18+. It reconnects from the last handled cursor after a dropped socket, a clean server close, or staleAfterMs (60 s) with no frame, backing off from reconnectDelayMs (1 s) up to 30 s with jitter and honoring Retry-After. Errors a retry cannot fix (401, other 4xx, a bad signature) end the loop: onError sees them and the handle's done rejects.

const subscription = streams.events.subscribe({
  types: ["ft_transfer"],          // notTypes / contractId / sender / recipient / assetIdentifier also filter
  // fromCursor: lastCursor,       // resume strictly after this cursor; omit to tail from the tip
  onEvent: async (event) => {
    console.log(event.cursor, event.tx_id);
  },
  onError: (err) => console.error("subscribe", err),
});

await subscription.done;          // rejects when the loop stopped on an unfixable error
// later
subscription();                   // unsubscribe, or pass `signal` and abort it

The cursor advances only after onEvent resolves, so a handler that throws sees the same event again on reconnect (at-least-once). Key durable writes by cursor. subscribe is not reorg-aware: an event delivered then orphaned is never retracted, so anything writing durable state belongs in consume() with onReorg or a sink.

Each pushed frame is { event, sig, key_id }. When the client was created with verify (or { publicKey }), the per-frame ed25519 signature is checked before onEvent runs; a bad/missing signature ends the subscription with StreamsSignatureError.

Bulk parquet dumps.

Finalized history is published as public parquet files. Set dumpsBaseUrl (or SL_STREAMS_DUMPS_URL) — no API key needed for dumps. The SDK does not decode parquet; download hands you sha256-verified bytes to process with your own tooling.

The bulk manifest is ed25519-signed, and the SDK verifies that signature before it trusts any per-file sha256 listed in it. The verifyDumpsManifest option defaults to true — dumps.list() and events.replay() enforce it, so you don't trust the file hashes unless the manifest itself verifies. Opt out with verifyDumpsManifest: false.

const streams = createStreamsClient({
  dumpsBaseUrl: process.env.SL_STREAMS_DUMPS_URL!,
});

const manifest = await streams.dumps.list();       // parse the manifest
for (const file of manifest.files) {
  const bytes = await streams.dumps.download(file); // fetch + verify sha256
  await myParquetReader(bytes);
}

download hashes the body as it streams in and retries a dropped socket or 5xx with the same policy consume() uses for pages, so a multi-hundred-MB file costs its own size in memory, not double, and one flaky fetch does not end a replay. The bytes are still returned whole; write them out per file.

for (const file of (await streams.dumps.list()).files) {
  await Bun.write(file.path.split("/").pop()!, await streams.dumps.download(file));
}

Backfill then tail (events.replay).

Backfills from bulk dumps, then tails live from the manifest's latest_finalized_cursor, with no gap or dupe at the seam. onDumpFile hands you each finalized file; onBatch receives live events after the seam.

Dump delivery is file-granular and at-least-once: the file straddling from arrives whole, with ctx.from so you can skip rows at or below the checkpoint (or key rows by cursor and let the upsert dedupe). Files ending at or below from are not delivered.

await streams.events.replay({
  from: lastCheckpoint,
  async onDumpFile(file, { from }) {
    const bytes = await streams.dumps.download(file);
    await ingestParquet(bytes, { skipAtOrBelow: from }); // your tooling
  },
  async onBatch(events, ctx) {
    for (const event of events) await handle(event);
    return ctx.cursor;
  },
});

Archive.

Signed canonical partitions (blocks / transactions / events), distinct from Streams dumps. latest follows latest.json and verifies the ed25519 manifest (default on). quote and fetch need an account key (sk-sl_*) against api.secondlayer.tools, not the instance baseUrl. download returns sha256-verified bytes; it does not decode parquet. Verify, repair, and bootstrap remain CLI.

const sl = new SecondLayer({
  accountKey: process.env.SECONDLAYER_API_KEY,
});
// SECONDLAYER_API_KEY is the hosted account key (sk-sl_*). It is not the instance token.

const ref = await sl.archive.latest();
const partitions = sl.archive.partitions(ref, { dataset: "blocks" });
const quote = await sl.archive.quote({
  paths: partitions.map((p) => p.path),
  flow: "bootstrap",
});
const fetched = await sl.archive.fetch({
  paths: partitions.map((p) => p.path),
  flow: "bootstrap",
});
for (const item of fetched.urls) {
  const partition = partitions.find((p) => p.path === item.path)!;
  const bytes = await sl.archive.download(partition, { url: item.url });
}

Decoder helper.

import { decodeFtTransfer, isFtTransfer } from "@secondlayer/sdk/streams/rows";

for await (const event of streams.events.stream({ types: ["ft_transfer"] })) {
  if (!isFtTransfer(event)) continue;
  const transfer = decodeFtTransfer(event);
  console.log(transfer.decoded_payload);
  break;
}

Helper convention: each event helper is a pure function with no shared state. Use is<EventName>(event) as the type guard and decode<EventName>(event) as the decoder. Decoders throw when the event type or payload is malformed. Add new helpers beside src/streams/ft-transfer.ts and export them through src/streams/index.ts.

Index

Decoded transfer events.

const ftPage = await sl.index.ftTransfers.list({
  contractId: "SP...sbtc-token",
  sender: "SP...",
  limit: 100,
});

const nftPage = await sl.index.nftTransfers.list({
  assetIdentifier: "SP...collection::token",
  recipient: "SP...",
});

Backfill with SDK walkers:

for await (const transfer of sl.index.ftTransfers.walk({
  fromHeight: 0,
  batchSize: 500,
})) {
  console.log(transfer.cursor, transfer.amount);
}

Checkpointed consumer — build your app index.

index.events.consume / index.contractCalls.consume is the same contract as the Streams consumer: write your rows inside onBatch, return the cursor you committed, and reorgs rewind automatically to the fork point. Only forks at or below your checkpoint roll back (a fork above it has nothing to undo), and a rewind deeper than maxRollbackDepth (default 1000 blocks) is refused before anything is deleted. finalizedOnly holds delivery to rows at or below tip.finalized_height (Index rows carry no per-event flag). Walkthrough: docs/index.

await sl.index.contractCalls.consume({
  contractId: "SP...marketplace-v4",
  functionName: "purchase-asset",
  fromCursor: await loadCheckpoint(), // null on first run
  fromHeight: 0,                      // first run: backfill from genesis
  onBatch: async (calls, ctx) => {
    await commitRowsAndCheckpoint(calls, ctx.cursor);
    return ctx.cursor;
  },
  onReorg: async (reorg) => {
    await rollbackAboveHeight(reorg.fork_point_height);
  },
});
Runes

Bitcoin Runes on the same Index plane: an etch catalog, per-rune activity, and balances, on a Bitcoin tip instead of a Stacks one.

await sl.index.runes.list({ search: "dog", sort: "mints" });
await sl.index.runes.get("DOG•GO•TO•THE•MOON"); // id, spaced name, or bare name — null on 404
await sl.index.runes.balances({ address: "bc1phnp234rd5hel0h8ulqvnq3zrww2td0a8q48hjcg7mv67j97jnxfq9ayczm" }); // exactly one of address/outpoint

for await (const e of sl.index.runes.activity.walk({ fromHeight: 900_000 })) {
  console.log(e.kind, e.rune.spaced_name, e.amount); // amounts are u128 decimal strings
}

RuneRef (the type every rune field/param takes) is an id (`${number}:${number}`) or any name form, spacers and case ignored — typing all 178k+ rune names would be huge and stale, so list({ search }) covers discovery instead. Live on api.secondlayer.tools and on self-hosted instances with the bitcoin compose profile. Full guide: docs/index#runes.

Transaction-inclusion proofs

Verify — without trusting Secondlayer — that a transaction is included in a Stacks (Nakamoto) block, and that ≥70% of the reward cycle's signer weight attested to that block. verifyTransactionProof recomputes everything client-side and trusts nothing the API returned.

Verification uses Node's crypto via @secondlayer/shared — Node/server-side use.

import { verifyTransactionProof, fetchRewardSet } from "@secondlayer/sdk";

const proof = await fetch(
  `http://127.0.0.1:3800/v1/index/transactions/${txid}/proof`,
).then((r) => r.json());

const result = verifyTransactionProof(proof); // anchored + consensus (embedded set)
// result.ok, result.level === "consensus", result.signerWeightBps

// Fully trustless — resolve the reward set from your own node:
const rewardSet = await fetchRewardSet({
  nodeUrl: "https://your-stacks-node:20443",
  cycle: proof.consensus.reward_cycle,
});
const trustless = verifyTransactionProof(proof, { rewardSet }); // rewardSetSource: "provided"

Two trust levels:

  • Anchored — recompute the txid from raw_tx, fold tx_merkle_path up to the header's tx_merkle_root, and recompute block_hash + index_block_hash from raw_header. The tx is in a header any node can corroborate.
  • Consensus — additionally recover the header's signer signatures and confirm ≥70% of the reward cycle's signer weight signed the block. Fully trustless when you pass a rewardSet resolved yourself via fetchRewardSet (rewardSetSource: "provided"); otherwise it uses the proof's embedded set (rewardSetSource: "embedded").
verifyTransactionProof(
  proof: TransactionProof,
  opts?: { rewardSet?: RewardSet },
): TransactionProofVerifyResult;

fetchRewardSet(opts: {
  nodeUrl: string;            // your own stacks-node
  cycle: number;             // reward cycle — proof.consensus.reward_cycle
  fetchImpl?: typeof fetch;
}): Promise<RewardSet | null>; // reads /v3/stacker_set/{cycle}

verifyTransactionProof returns a TransactionProofVerifyResult:

{
  level: "anchored" | "consensus";
  txidMatches: boolean;
  includedInHeader: boolean;
  headerSelfConsistent: boolean;
  signerWeightBps?: number;   // consensus only
  thresholdMet?: boolean;     // consensus only — ≥70% (7000 bps)
  rewardSetSource?: "provided" | "embedded";
  ok: boolean;
  errors: string[];
}

OX Radar and Response Center

Find threats in your stack.

OX Radar can check high-priority threats, like critical package CVEs, against your context.

Each incident is marked Detected or Not Detected with a remediation plan and proof all tracked in the Response Center.

Where it’s listed

The probe returned only these fields for this server — auth requirement, protocol and tool list weren’t observed, so they’re not shown (never guessed).

  • npm @secondlayer/sdk

References

The publisher’s own links, as the registry reports them. These are not sources for the assessment on this page.

Powered by Read the latest findings

Scan your whole stack

Group 1261154050 1
Group 1261154050
 

From OX Research Newsroom

Cry2Wolf: How to Tell a Real Bug from a Nothingburger
AI & VibeSec

Cry2Wolf: Not Every Branded Bug Deserves a Fire Drill

Copy of Template Design OX Blog (3)
Research

Ruby2Shell: Ruby Memory Corruption Flaws Expose Applications to Remote Code Execution, But is it an Actual Risk?

Copy of Template Design OX Blog (2)
Research

NGINX2Root: Five Critical NGINX Flaws Expose Web Servers to Remote Code Execution

Frame 2085668439 (1)
Group 1261154229