@secondlayer/sdk 6.18.0 → 6.19.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.
@@ -232,6 +232,13 @@ declare class Contracts extends BaseClient {
232
232
  constructor(options?: Partial<SecondLayerOptions>);
233
233
  /** Find contracts conforming to `trait`. `trait` is required (server 400s without it). */
234
234
  list(params: ContractsListParams): Promise<ContractsEnvelope>;
235
+ /**
236
+ * Fetch a single contract from the registry by id (the prod-safe ABI source).
237
+ * Pass `{ includeAbi: true }` for the full ABI blob. Resolves null on 404.
238
+ */
239
+ get(contractId: string, opts?: {
240
+ includeAbi?: boolean
241
+ }): Promise<ContractSummary | null>;
235
242
  }
236
243
  /**
237
244
  * Typed client for the Foundation Datasets REST API (`/v1/datasets/*`).
@@ -377,6 +384,42 @@ declare class Datasets extends BaseClient {
377
384
  private paramsToQuery;
378
385
  private cursorDataset;
379
386
  }
387
+ import { RewardSet } from "@secondlayer/shared/node/consensus";
388
+ import { MerkleProofStep } from "@secondlayer/shared/node/nakamoto";
389
+ /**
390
+ * Trustless transaction-inclusion proof verification.
391
+ *
392
+ * Given a proof from `GET /v1/index/transactions/:txid/proof`, the consumer
393
+ * re-derives everything itself — it does NOT trust any value Secondlayer
394
+ * computed. Anchored level: (1) recompute the txid from the raw tx bytes, (2)
395
+ * fold it up the merkle path to the header's `tx_merkle_root`, (3) recompute the
396
+ * header's `block_hash` and `index_block_hash` from the raw header — "this tx is
397
+ * included in a header any node can corroborate". Consensus level (when the proof
398
+ * carries a `consensus` field, or a `rewardSet` is passed): additionally recover
399
+ * the header's signer signatures and confirm ≥70% of reward-set signer weight
400
+ * signed the block.
401
+ *
402
+ * Note: uses Node's crypto via `@secondlayer/shared` (same as the Streams
403
+ * signature verify); intended for Node/server verification.
404
+ */
405
+ interface TransactionProof {
406
+ txid: string;
407
+ index_block_hash: string;
408
+ block_height: number;
409
+ tx_index: number;
410
+ /** Raw consensus-serialized transaction bytes (hex). */
411
+ raw_tx: string;
412
+ /** Raw Nakamoto block-header bytes (hex) — parsed + re-hashed by the verifier. */
413
+ raw_header: string;
414
+ /** Authentication path from the tx leaf to `tx_merkle_root`. */
415
+ tx_merkle_path: MerkleProofStep[];
416
+ /** Present when consensus-level verification is available: the reward cycle and
417
+ * its signer set, against which the header's signer signatures are checked. */
418
+ consensus?: {
419
+ reward_cycle: number
420
+ reward_set: RewardSet
421
+ };
422
+ }
380
423
  type IndexTip = {
381
424
  block_height: number
382
425
  lag_seconds: number
@@ -936,6 +979,7 @@ declare class Index extends BaseClient {
936
979
  list: (params?: TransactionsListParams) => Promise<TransactionsEnvelope>
937
980
  walk: (params?: TransactionsWalkParams) => AsyncIterable<IndexTransaction>
938
981
  get: (txId: string) => Promise<TransactionEnvelope | null>
982
+ getProof: (txId: string) => Promise<TransactionProof | null>
939
983
  };
940
984
  /** Decoded PoX-4 stacking actions. Empty (with a `notes` hint) when the
941
985
  * platform's PoX-4 decoder is disabled. */
@@ -965,6 +1009,11 @@ declare class Index extends BaseClient {
965
1009
  private walkBlocks;
966
1010
  private listTransactions;
967
1011
  private getTransaction;
1012
+ /** Fetch the inclusion proof for a tx (raw tx + Nakamoto header + merkle path)
1013
+ * to verify client-side with `verifyTransactionProof`. 404 → null. A 503
1014
+ * (`PROOF_TX_SET_INCOMPLETE` / `PROOF_NODE_UNAVAILABLE`) surfaces as an
1015
+ * ApiError — the proof can't be assembled on this deployment right now. */
1016
+ private getTransactionProof;
968
1017
  private walkTransactions;
969
1018
  private listStacking;
970
1019
  private walkStacking;
@@ -417,6 +417,16 @@ class Contracts extends BaseClient {
417
417
  cursor: params.cursor
418
418
  })}`);
419
419
  }
420
+ async get(contractId, opts = {}) {
421
+ try {
422
+ const { contract } = await this.request("GET", `/v1/contracts/${encodeURIComponent(contractId)}${opts.includeAbi ? "?include=abi" : ""}`);
423
+ return contract;
424
+ } catch (err) {
425
+ if (err instanceof ApiError && err.status === 404)
426
+ return null;
427
+ throw err;
428
+ }
429
+ }
420
430
  }
421
431
 
422
432
  // src/datasets/client.ts
@@ -624,7 +634,8 @@ class Index extends BaseClient {
624
634
  transactions = {
625
635
  list: (params = {}) => this.listTransactions(params),
626
636
  walk: (params = {}) => this.walkTransactions(params),
627
- get: (txId) => this.getTransaction(txId)
637
+ get: (txId) => this.getTransaction(txId),
638
+ getProof: (txId) => this.getTransactionProof(txId)
628
639
  };
629
640
  stacking = {
630
641
  list: (params = {}) => this.listStacking(params),
@@ -886,6 +897,15 @@ class Index extends BaseClient {
886
897
  throw err;
887
898
  }
888
899
  }
900
+ async getTransactionProof(txId) {
901
+ try {
902
+ return await this.request("GET", `/v1/index/transactions/${encodeURIComponent(txId)}/proof`);
903
+ } catch (err) {
904
+ if (err instanceof ApiError && err.status === 404)
905
+ return null;
906
+ throw err;
907
+ }
908
+ }
889
909
  async* walkTransactions(params = {}) {
890
910
  const batchSize = params.batchSize ?? 200;
891
911
  let cursor = params.cursor ?? params.fromCursor ?? null;
@@ -1795,5 +1815,5 @@ export {
1795
1815
  Subgraphs
1796
1816
  };
1797
1817
 
1798
- //# debugId=A5185B837644857464756E2164756E21
1818
+ //# debugId=7ABB6E8514AEA9F664756E2164756E21
1799
1819
  //# sourceMappingURL=index.js.map