@secondlayer/sdk 6.54.0 → 7.0.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/README.md +13 -24
- package/dist/index.d.ts +15 -587
- package/dist/index.js +42 -395
- package/dist/index.js.map +15 -22
- package/dist/sinks/bun-sqlite.js +2 -24
- package/dist/sinks/bun-sqlite.js.map +3 -3
- package/dist/sinks/core.js +2 -24
- package/dist/sinks/core.js.map +3 -3
- package/dist/sinks/drizzle.js +2 -24
- package/dist/sinks/drizzle.js.map +3 -3
- package/dist/sinks/kysely.js +2 -24
- package/dist/sinks/kysely.js.map +3 -3
- package/dist/streams/index.d.ts +9 -378
- package/dist/streams/index.js +35 -309
- package/dist/streams/index.js.map +9 -15
- package/dist/streams/rows.d.ts +2 -355
- package/dist/streams/rows.js +26 -280
- package/dist/streams/rows.js.map +4 -10
- package/dist/subgraphs/index.d.ts +2 -295
- package/dist/subgraphs/index.js +10 -174
- package/dist/subgraphs/index.js.map +10 -13
- package/dist/x402.d.ts +4 -3
- package/dist/x402.js +273 -2
- package/dist/x402.js.map +6 -4
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -14,25 +14,14 @@ bun add @secondlayer/sdk
|
|
|
14
14
|
import { SecondLayer } from "@secondlayer/sdk";
|
|
15
15
|
|
|
16
16
|
const sl = new SecondLayer({
|
|
17
|
-
apiKey:
|
|
18
|
-
baseUrl:
|
|
17
|
+
apiKey: process.env.INSTANCE_TOKEN, // from secondlayer init; omit on loopback
|
|
18
|
+
// default baseUrl: http://127.0.0.1:3800 (or SL_API_URL)
|
|
19
19
|
});
|
|
20
20
|
```
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
publicly-known free-tier token exists but a bearer is always required. Writes
|
|
26
|
-
require an `sk-sl_` API key, created in the platform console at
|
|
27
|
-
https://secondlayer.tools/platform/api-keys. (Public Streams bulk dumps —
|
|
28
|
-
`client.dumps`, `events.replay` — need no key.)
|
|
29
|
-
|
|
30
|
-
**API keys.** Each `sk-sl_` key has a `product`. An **`account`** key (dashboard
|
|
31
|
-
default) grants both `streams:read` and `index:read` and is the only key that can
|
|
32
|
-
mint new keys; **`streams`** / **`index`** keys are scoped, read-only, and cannot
|
|
33
|
-
mint. Mint scoped keys programmatically with `sl.apiKeys.create({ product })`
|
|
34
|
-
(needs an account/owner key) — the returned `key` is shown once and inherits your
|
|
35
|
-
plan's tier.
|
|
22
|
+
Reads hit your instance. Writes use `INSTANCE_TOKEN` from `secondlayer init` when the
|
|
23
|
+
API is bound beyond loopback. Public archive dumps (`client.dumps`) need no
|
|
24
|
+
instance key.
|
|
36
25
|
|
|
37
26
|
## Mental model
|
|
38
27
|
|
|
@@ -43,14 +32,14 @@ Everything is indexing — the question is how much of the indexer you run:
|
|
|
43
32
|
with the checkpointed `consume()` loop (automatic reorg rewind), `walk()`
|
|
44
33
|
sweeps, and resumable cursors on every page.
|
|
45
34
|
- `sl.subgraphs` — deploy your own indexer (one `defineSubgraph()` file via the
|
|
46
|
-
CLI), then read
|
|
35
|
+
CLI), then read the tables on this instance.
|
|
47
36
|
- `sl.streams` — the raw ordered event firehose Index itself is built on, with
|
|
48
37
|
a checkpointed `consume()` and dumps `replay()` for building from zero.
|
|
49
38
|
- `sl.contracts` — find deployed contracts by trait (SIP-009/010/013).
|
|
50
39
|
|
|
51
40
|
## Streams
|
|
52
41
|
|
|
53
|
-
Typed HTTP client for the raw event firehose.
|
|
42
|
+
Typed HTTP client for the raw event firehose. Loopback reads need no key.
|
|
54
43
|
|
|
55
44
|
```typescript
|
|
56
45
|
const tip = await sl.streams.tip();
|
|
@@ -73,7 +62,7 @@ console.log({ tip, firstCursor: page.events[0]?.cursor });
|
|
|
73
62
|
import { createStreamsClient } from "@secondlayer/sdk";
|
|
74
63
|
|
|
75
64
|
const streams = createStreamsClient({
|
|
76
|
-
apiKey: process.env.
|
|
65
|
+
// apiKey: process.env.INSTANCE_TOKEN, // when the API is bound beyond loopback
|
|
77
66
|
// verify: true, // verify ed25519 X-Signature on every read
|
|
78
67
|
// // (auto-fetches the public key; { publicKey } pins a PEM)
|
|
79
68
|
// dumpsBaseUrl: process.env.SL_STREAMS_DUMPS_URL, // required to use client.dumps
|
|
@@ -289,7 +278,7 @@ client-side and trusts nothing the API returned.
|
|
|
289
278
|
import { verifyTransactionProof, fetchRewardSet } from "@secondlayer/sdk";
|
|
290
279
|
|
|
291
280
|
const proof = await fetch(
|
|
292
|
-
`
|
|
281
|
+
`http://127.0.0.1:3800/v1/index/transactions/${txid}/proof`,
|
|
293
282
|
).then((r) => r.json());
|
|
294
283
|
|
|
295
284
|
const result = verifyTransactionProof(proof); // anchored + consensus (embedded set)
|
|
@@ -531,8 +520,8 @@ few hundredths of a cent per request from a Stacks wallet. Payment is **gasless*
|
|
|
531
520
|
(you sign; we sponsor the STX fee) and uses standard **x402 v2** on `stacks:1`.
|
|
532
521
|
Supported assets: **sBTC** (default), **USDCx**, **STX**.
|
|
533
522
|
|
|
534
|
-
> Keyed (`
|
|
535
|
-
>
|
|
523
|
+
> Keyed (`INSTANCE_TOKEN`) requests skip x402. The rail is for accountless
|
|
524
|
+
> callers on an instance that has it enabled.
|
|
536
525
|
|
|
537
526
|
Drop-in `fetch` that pays on `402` automatically:
|
|
538
527
|
|
|
@@ -547,7 +536,7 @@ const x402fetch = withX402(fetch, {
|
|
|
547
536
|
});
|
|
548
537
|
|
|
549
538
|
const res = await x402fetch(
|
|
550
|
-
"
|
|
539
|
+
"http://127.0.0.1:3800/v1/index/events?event_type=ft_transfer",
|
|
551
540
|
);
|
|
552
541
|
const data = await res.json();
|
|
553
542
|
readX402Receipt(res); // { success, txid, payer, network } | null
|
|
@@ -558,7 +547,7 @@ Or a small client returning `{ data, payment }`:
|
|
|
558
547
|
```typescript
|
|
559
548
|
import { createX402Client } from "@secondlayer/sdk";
|
|
560
549
|
|
|
561
|
-
const sl = createX402Client({ account
|
|
550
|
+
const sl = createX402Client({ account }); // baseUrl defaults to http://127.0.0.1:3800
|
|
562
551
|
const { data, payment } = await sl.get("/v1/index/events", {
|
|
563
552
|
query: { event_type: "ft_transfer" },
|
|
564
553
|
});
|