@secondlayer/sdk 6.54.0 → 6.54.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.
- package/README.md +13 -24
- package/dist/index.d.ts +5 -4
- package/dist/index.js +2 -2
- package/dist/index.js.map +4 -4
- package/dist/streams/index.js.map +1 -1
- package/dist/subgraphs/index.d.ts +1 -1
- package/dist/subgraphs/index.js.map +1 -1
- package/dist/x402.d.ts +4 -3
- package/dist/x402.js +298 -2
- package/dist/x402.js.map +6 -4
- package/package.json +1 -1
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 sl 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 `sl 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
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ import { SubgraphAgentSchema, SubgraphSpecOptions } from "@secondlayer/shared/su
|
|
|
4
4
|
import { InferSubgraphClient } from "@secondlayer/subgraphs";
|
|
5
5
|
type FetchLike = (input: string | URL | Request, init?: RequestInit) => Promise<Response>;
|
|
6
6
|
interface SecondLayerOptions {
|
|
7
|
-
/** Base URL of the
|
|
7
|
+
/** Base URL of the instance API (trailing slashes are stripped). */
|
|
8
8
|
baseUrl: string;
|
|
9
9
|
/** Bearer token for authenticated requests. */
|
|
10
10
|
apiKey?: string;
|
|
@@ -3287,11 +3287,12 @@ type X402Fetch = (input: string | URL, init?: RequestInit) => Promise<Response>;
|
|
|
3287
3287
|
*
|
|
3288
3288
|
* @example
|
|
3289
3289
|
* const x402fetch = withX402(fetch, { account });
|
|
3290
|
-
* const res = await x402fetch("
|
|
3290
|
+
* const res = await x402fetch("http://127.0.0.1:3800/v1/index/events?event_type=ft_transfer");
|
|
3291
3291
|
*/
|
|
3292
3292
|
declare function withX402(baseFetch: typeof fetch, opts: WithX402Options): X402Fetch;
|
|
3293
3293
|
type X402ClientOptions = WithX402Options & {
|
|
3294
|
-
|
|
3294
|
+
/** Instance API. Defaults to {@link resolveBaseUrl}. */
|
|
3295
|
+
baseUrl?: string;
|
|
3295
3296
|
/** Override the underlying fetch (tests). */
|
|
3296
3297
|
fetch?: typeof fetch;
|
|
3297
3298
|
};
|
|
@@ -3314,7 +3315,7 @@ type X402Client = {
|
|
|
3314
3315
|
* parsed JSON plus the settlement receipt.
|
|
3315
3316
|
*
|
|
3316
3317
|
* @example
|
|
3317
|
-
* const sl = createX402Client({ account, baseUrl: "
|
|
3318
|
+
* const sl = createX402Client({ account, baseUrl: "http://127.0.0.1:3800" });
|
|
3318
3319
|
* const { data, payment } = await sl.get("/v1/index/events", { query: { event_type: "ft_transfer" } });
|
|
3319
3320
|
*/
|
|
3320
3321
|
declare function createX402Client(opts: X402ClientOptions): X402Client;
|
package/dist/index.js
CHANGED
|
@@ -2548,7 +2548,7 @@ function withX402(baseFetch, opts) {
|
|
|
2548
2548
|
}
|
|
2549
2549
|
function createX402Client(opts) {
|
|
2550
2550
|
const f = withX402(opts.fetch ?? fetch, opts);
|
|
2551
|
-
const base = opts.baseUrl
|
|
2551
|
+
const base = resolveBaseUrl(opts.baseUrl);
|
|
2552
2552
|
async function request(method, path, o = {}) {
|
|
2553
2553
|
const qs = o.query ? `?${new URLSearchParams(o.query).toString()}` : "";
|
|
2554
2554
|
const init = { method };
|
|
@@ -2846,5 +2846,5 @@ export {
|
|
|
2846
2846
|
ApiError
|
|
2847
2847
|
};
|
|
2848
2848
|
|
|
2849
|
-
//# debugId=
|
|
2849
|
+
//# debugId=00B669DC4969C3BE64756E2164756E21
|
|
2850
2850
|
//# sourceMappingURL=index.js.map
|