@secondlayer/sdk 6.34.0 → 6.36.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/dist/index.d.ts +41 -14
- package/dist/index.js +60 -6
- package/dist/index.js.map +9 -9
- package/dist/streams/index.js +19 -2
- package/dist/streams/index.js.map +4 -4
- package/dist/subgraphs/index.d.ts +40 -13
- package/dist/subgraphs/index.js +50 -3
- package/dist/subgraphs/index.js.map +7 -7
- package/dist/x402.js +9 -3
- package/dist/x402.js.map +3 -3
- package/package.json +5 -3
package/dist/index.d.ts
CHANGED
|
@@ -29,6 +29,7 @@ declare abstract class BaseClient {
|
|
|
29
29
|
protected baseUrl: string;
|
|
30
30
|
protected apiKey?: string;
|
|
31
31
|
protected origin: "cli" | "mcp" | "session";
|
|
32
|
+
protected fetchImpl: FetchLike;
|
|
32
33
|
constructor(options?: Partial<SecondLayerOptions>);
|
|
33
34
|
static authHeaders(apiKey?: string): Record<string, string>;
|
|
34
35
|
protected request<T>(method: string, path: string, body?: unknown): Promise<T>;
|
|
@@ -1107,19 +1108,27 @@ type IndexPrint = IndexEventBase & {
|
|
|
1107
1108
|
/** Decoded chain event, discriminated by `event_type`. */
|
|
1108
1109
|
type IndexEvent = IndexFtTransfer | IndexNftTransfer | IndexStxTransfer | IndexStxMint | IndexStxBurn | IndexStxLock | IndexFtMint | IndexFtBurn | IndexNftMint | IndexNftBurn | IndexPrint;
|
|
1109
1110
|
type IndexEventType = IndexEvent["event_type"];
|
|
1110
|
-
type EventsEnvelope = {
|
|
1111
|
-
events:
|
|
1111
|
+
type EventsEnvelope<T extends IndexEventType = IndexEventType> = {
|
|
1112
|
+
events: IndexEventOf<T>[]
|
|
1112
1113
|
next_cursor: string | null
|
|
1113
1114
|
tip: IndexTip
|
|
1114
1115
|
reorgs: IndexReorg[]
|
|
1115
1116
|
};
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1117
|
+
/** The single decoded-event member matching one `event_type` literal.
|
|
1118
|
+
* `IndexEventOf<"ft_transfer">` is `IndexFtTransfer`. */
|
|
1119
|
+
type IndexEventOf<T extends IndexEventType> = Extract<IndexEvent, {
|
|
1120
|
+
event_type: T
|
|
1121
|
+
}>;
|
|
1122
|
+
type EventsListParams<T extends IndexEventType = IndexEventType> = {
|
|
1123
|
+
/** Required. One of the decoded event types. Passing a literal narrows the
|
|
1124
|
+
* rows every surface hands back to that event's own shape. */
|
|
1125
|
+
eventType: T
|
|
1119
1126
|
cursor?: string | null
|
|
1120
1127
|
fromCursor?: string | null
|
|
1121
1128
|
limit?: number
|
|
1122
|
-
|
|
1129
|
+
/** One id, or several to scope the sweep to a set of contracts (max 20).
|
|
1130
|
+
* Mutually exclusive with `trait`. */
|
|
1131
|
+
contractId?: string | readonly string[]
|
|
1123
1132
|
assetIdentifier?: string
|
|
1124
1133
|
sender?: string
|
|
1125
1134
|
recipient?: string
|
|
@@ -1134,11 +1143,11 @@ type EventsListParams = {
|
|
|
1134
1143
|
* the only source of the submitting sender. */
|
|
1135
1144
|
txContext?: boolean
|
|
1136
1145
|
};
|
|
1137
|
-
type EventsWalkParams = Omit<EventsListParams
|
|
1146
|
+
type EventsWalkParams<T extends IndexEventType = IndexEventType> = Omit<EventsListParams<T>, "limit"> & {
|
|
1138
1147
|
batchSize?: number
|
|
1139
1148
|
signal?: AbortSignal
|
|
1140
1149
|
};
|
|
1141
|
-
type EventsConsumeParams = Omit<EventsListParams
|
|
1150
|
+
type EventsConsumeParams<T extends IndexEventType = IndexEventType> = Omit<EventsListParams<T>, "cursor" | "fromCursor" | "limit"> & IndexConsumeOptions<IndexEventOf<T>, EventsEnvelope<T>>;
|
|
1142
1151
|
type IndexContractCall = {
|
|
1143
1152
|
cursor: string
|
|
1144
1153
|
block_height: number
|
|
@@ -1163,7 +1172,9 @@ type ContractCallsListParams = {
|
|
|
1163
1172
|
cursor?: string | null
|
|
1164
1173
|
fromCursor?: string | null
|
|
1165
1174
|
limit?: number
|
|
1166
|
-
|
|
1175
|
+
/** One id, or several to scope the sweep to a set of contracts (max 20).
|
|
1176
|
+
* Mutually exclusive with `trait`. */
|
|
1177
|
+
contractId?: string | readonly string[]
|
|
1167
1178
|
functionName?: string
|
|
1168
1179
|
sender?: string
|
|
1169
1180
|
fromHeight?: number
|
|
@@ -1649,12 +1660,21 @@ type SbtcEventsWalkParams = Omit<SbtcEventsListParams, "limit"> & {
|
|
|
1649
1660
|
batchSize?: number
|
|
1650
1661
|
signal?: AbortSignal
|
|
1651
1662
|
};
|
|
1663
|
+
type SbtcEventsConsumeParams = Omit<SbtcEventsListParams, "cursor" | "fromCursor" | "limit"> & IndexConsumeOptions<IndexSbtcEvent, SbtcEventsEnvelope>;
|
|
1664
|
+
type SbtcDepositsConsumeParams = Omit<SbtcDepositsListParams, "cursor" | "fromCursor" | "limit"> & IndexConsumeOptions<IndexSbtcDeposit, SbtcDepositsEnvelope>;
|
|
1652
1665
|
/** `index.sbtc` — the decoded sBTC peg surface (deposits, withdrawals, raw
|
|
1653
1666
|
* events, scoreboard). The only productized decoded sBTC peg feed on Stacks. */
|
|
1654
1667
|
interface SbtcResource {
|
|
1655
1668
|
deposits: {
|
|
1656
1669
|
list(params?: SbtcDepositsListParams): Promise<SbtcDepositsEnvelope>
|
|
1657
1670
|
walk(params?: SbtcDepositsWalkParams): AsyncIterable<IndexSbtcDeposit>
|
|
1671
|
+
/** Checkpointed sweep of completed deposits — append-only, so safe to
|
|
1672
|
+
* mirror. See {@link IndexConsumeOptions}. */
|
|
1673
|
+
consume(params: SbtcDepositsConsumeParams): Promise<{
|
|
1674
|
+
cursor: string | null
|
|
1675
|
+
pages: number
|
|
1676
|
+
emptyPolls: number
|
|
1677
|
+
}>
|
|
1658
1678
|
/** Fetch a completed deposit by Bitcoin txid; 404 → null. */
|
|
1659
1679
|
get(bitcoinTxid: string): Promise<SbtcDepositEnvelope | null>
|
|
1660
1680
|
};
|
|
@@ -1667,6 +1687,13 @@ interface SbtcResource {
|
|
|
1667
1687
|
events: {
|
|
1668
1688
|
list(params?: SbtcEventsListParams): Promise<SbtcEventsEnvelope>
|
|
1669
1689
|
walk(params?: SbtcEventsWalkParams): AsyncIterable<IndexSbtcEvent>
|
|
1690
|
+
/** Checkpointed sweep of the raw peg event log — append-only across all
|
|
1691
|
+
* six topics. See {@link IndexConsumeOptions}. */
|
|
1692
|
+
consume(params: SbtcEventsConsumeParams): Promise<{
|
|
1693
|
+
cursor: string | null
|
|
1694
|
+
pages: number
|
|
1695
|
+
emptyPolls: number
|
|
1696
|
+
}>
|
|
1670
1697
|
};
|
|
1671
1698
|
/** The peg scoreboard — a single all-time aggregate (no pagination). */
|
|
1672
1699
|
summary(): Promise<SbtcSummaryEnvelope>;
|
|
@@ -1809,10 +1836,10 @@ interface NftTransfersResource {
|
|
|
1809
1836
|
}
|
|
1810
1837
|
/** `index.events` — callable shorthand for `.list()`; `eventType` is required. */
|
|
1811
1838
|
interface IndexEventsResource {
|
|
1812
|
-
(params: EventsListParams): Promise<EventsEnvelope
|
|
1813
|
-
list(params: EventsListParams): Promise<EventsEnvelope
|
|
1814
|
-
walk(params: EventsWalkParams): AsyncIterable<
|
|
1815
|
-
consume(params: EventsConsumeParams): Promise<{
|
|
1839
|
+
<T extends IndexEventType>(params: EventsListParams<T>): Promise<EventsEnvelope<T>>;
|
|
1840
|
+
list<T extends IndexEventType>(params: EventsListParams<T>): Promise<EventsEnvelope<T>>;
|
|
1841
|
+
walk<T extends IndexEventType>(params: EventsWalkParams<T>): AsyncIterable<IndexEventOf<T>>;
|
|
1842
|
+
consume<T extends IndexEventType>(params: EventsConsumeParams<T>): Promise<{
|
|
1816
1843
|
cursor: string | null
|
|
1817
1844
|
pages: number
|
|
1818
1845
|
emptyPolls: number
|
|
@@ -2869,4 +2896,4 @@ declare function toJsonSafe(value: unknown): unknown;
|
|
|
2869
2896
|
/** Decode a hex-encoded Clarity value to JSON-safe JS (uints as strings,
|
|
2870
2897
|
* buffers as `0x…` hex, tuples as objects). Returns the input hex on failure. */
|
|
2871
2898
|
declare function decodeClarityValue(hex: string): unknown;
|
|
2872
|
-
export { withX402, verifyWebhookSignature, verifyTransactionProof, verify as verifyStandardWebhooksHeaders, verifySecondlayerSignature, trigger, toJsonSafe, selectOffer, resolveApiKey, resolveAccountNonce, readX402Receipt, readX402Challenge, payAndRetry, isStxTransfer, isStxMint, isStxLock, isStxBurn, isPrint, isNftTransfer, isNftMint, isNftBurn, isFtTransfer, isFtMint, isFtBurn, getSubgraph, fetchRewardSet, decodeStxTransfer, decodeStxMint, decodeStxLock, decodeStxBurn, decodePrint, decodeNftTransfer, decodeNftMint, decodeNftBurn, decodeFtTransfer, decodeFtMint, decodeFtBurn, decodeClarityValue, decodeChainWebhook, createX402Client, createStreamsClient, consumeIndexFeed, buildSignedX402Payment, X402SpendGuardError, X402Result, X402Receipt, X402Fetch, X402ClientOptions, X402Client, X402Challenge, X402Accept, WithX402Options, WebhookHeaderInput, VersionConflictError, ValidationError, UpdateSubscriptionRequest2 as UpdateSubscriptionRequest, UpdateProjectParams, TransactionsWalkParams, TransactionsListParams, TransactionsEnvelope, TransactionProofVerifyResult, TransactionProof, TransactionEnvelope, Subscriptions, SubscriptionSummary2 as SubscriptionSummary, SubscriptionStatus, SubscriptionRuntime, SubscriptionKind, SubscriptionFormat, SubscriptionDetail2 as SubscriptionDetail, Subgraphs, SubgraphSpecOptions3 as SubgraphSpecOptions, SubgraphSpecFormat2 as SubgraphSpecFormat, SubgraphOperationStatus, SubgraphAgentSchema3 as SubgraphAgentSchema, StreamsUsage, StreamsTip, StreamsSignatureError, StreamsServerError, StreamsReorgsListParams, StreamsReorgsListEnvelope, StreamsReorgContext, StreamsReorg, StreamsEventsSubscribeParams, StreamsEventsStreamParams, StreamsEventsListParams, StreamsEventsListEnvelope, StreamsEventsEnvelope, StreamsEventsConsumeResult, StreamsEventsConsumeParams, StreamsEventType, StreamsEventPayload, StreamsEvent, StreamsDumpsManifest, StreamsDumps, StreamsDumpFile, StreamsConsumeParams, StreamsClient, StreamsCanonicalBlock, StreamsBatchContext, StreamsBatch, StandardWebhooksHeaders2 as StandardWebhooksHeaders, StackingWalkParams, StackingListParams, StackingEnvelope, SelectOfferOptions, SecondLayerOptions, SecondLayer, ScopedKeyProduct, SbtcWithdrawalsWalkParams, SbtcWithdrawalsListParams, SbtcWithdrawalsEnvelope, SbtcWithdrawalSweptConfirmedEvent, SbtcWithdrawalStatus, SbtcWithdrawalEvent, SbtcWithdrawalEnvelope, SbtcSummaryEnvelope, SbtcResource, SbtcEventsWalkParams, SbtcEventsListParams, SbtcEventsEnvelope, SbtcEventTopic, SbtcDepositsWalkParams, SbtcDepositsListParams, SbtcDepositsEnvelope, SbtcDepositEvent, SbtcDepositEnvelope, RotateSecretResponse2 as RotateSecretResponse, RewardSet2 as RewardSet, ReplayResult2 as ReplayResult, RateLimitError, Projects, ProjectTeamMember, ProjectTeam, ProjectInvitation, Project, PrintSchemaResponse, PoxResource, PoxCyclesWalkParams, PoxCyclesListParams, PoxCyclesEnvelope, PoxCycleEnvelope, Pox5Resource, Pox5EventsWalkParams, Pox5EventsListParams, Pox5EventsEnvelope, PayAndRetryOptions, NftTransfersWalkParams, NftTransfersResource, NftTransfersListParams, NftTransfersEnvelope, NftTransferPayload, NftTransferEvent, NftTransfer, MempoolWalkParams, MempoolTransactionEnvelope, MempoolListParams, MempoolEnvelope, IndexUsage, IndexTransaction, IndexTip, IndexStxTransfer, IndexStxMint, IndexStxLock, IndexStxBurn, IndexStackingAction, IndexSbtcWithdrawalPhase, IndexSbtcWithdrawalDetail, IndexSbtcWithdrawal, IndexSbtcSummary, IndexSbtcEvent, IndexSbtcDepositDetail, IndexSbtcDeposit, IndexReorg, IndexPrint, IndexPoxFunctionCount, IndexPoxCycle, IndexPox5EventTopic, IndexPox5Event, IndexPostCondition, IndexNftTransfer, IndexNftMint, IndexNftBurn, IndexMempoolTransaction, IndexFtTransfer, IndexFtMint, IndexFtBurn, IndexFeedItem, IndexFeedFetcher, IndexFeedEnvelope, IndexEventsResource, IndexEventTypeFilters, IndexEventType, IndexEvent, IndexDiscovery, IndexContractCall, IndexConsumeOptions, IndexCanonicalBlock, IndexBlock, Index, FtTransfersWalkParams, FtTransfersResource, FtTransfersListParams, FtTransfersEnvelope, FtTransferPayload, FtTransferEvent, FtTransfer, FetchLike2 as FetchLike, EventsWalkParams, EventsListParams, EventsEnvelope, EventsConsumeParams, DeliveryRow2 as DeliveryRow, DecodedStxTransferPayload, DecodedStxTransfer, DecodedStxMintPayload, DecodedStxMint, DecodedStxLockPayload, DecodedStxLock, DecodedStxBurnPayload, DecodedStxBurn, DecodedPrintValue, DecodedPrintPayload, DecodedPrint, DecodedNftTransferPayload, DecodedNftTransfer, DecodedNftMintPayload, DecodedNftMint, DecodedNftBurnPayload, DecodedNftBurn, DecodedFtTransferPayload, DecodedFtTransfer, DecodedFtMintPayload, DecodedFtMint, DecodedFtBurnPayload, DecodedFtBurn, DecodedEventRow, DecodedEventColumns, DeadRow2 as DeadRow, DEFAULT_PREFER_ASSETS, Cursor, CreateSubscriptionResponse2 as CreateSubscriptionResponse, CreateSubscriptionRequest2 as CreateSubscriptionRequest, CreateProjectParams, CreateApiKeyResponse, CreateApiKeyParams, ContractsListParams, ContractsEnvelope, Contracts, ContractSummary, ContractConformance, ContractCallsWalkParams, ContractCallsListParams, ContractCallsEnvelope, ContractCallsConsumeParams, ContextSnapshot, ContextProject, ContextApiKey, ContextAccount, ConsumerBatchContext, ChainWebhookEnvelope, ChainWebhookDelivery2 as ChainWebhookDelivery, ChainTxLevelEvent, ChainTriggerType, ChainTrigger, ChainTestDelivery, ChainStxTransferData, ChainStxMintData, ChainStxLockData, ChainStxBurnData, ChainReorgRollbackEnvelope, ChainReorgRollbackDelivery, ChainReorgOrphanedEntry, ChainPrintEventData, ChainNftTransferData, ChainNftMintData, ChainNftBurnData, ChainFtTransferData, ChainFtMintData, ChainFtBurnData, ChainEventEnvelope, ChainApplyEnvelopeOf, ChainApplyEnvelope, ChainApplyDeliveryOf, CanonicalWalkParams, CanonicalListParams, CanonicalEnvelope, ByoBreakingChangeError, ByoBreakingChangeDetails, BuildSignedX402PaymentOptions, BlocksWalkParams, BlocksListParams, BlocksEnvelope, BlockEnvelope, AuthError, ApiKeys, ApiKeySummary, ApiError, ActiveSubgraphOperation };
|
|
2899
|
+
export { withX402, verifyWebhookSignature, verifyTransactionProof, verify as verifyStandardWebhooksHeaders, verifySecondlayerSignature, trigger, toJsonSafe, selectOffer, resolveApiKey, resolveAccountNonce, readX402Receipt, readX402Challenge, payAndRetry, isStxTransfer, isStxMint, isStxLock, isStxBurn, isPrint, isNftTransfer, isNftMint, isNftBurn, isFtTransfer, isFtMint, isFtBurn, getSubgraph, fetchRewardSet, decodeStxTransfer, decodeStxMint, decodeStxLock, decodeStxBurn, decodePrint, decodeNftTransfer, decodeNftMint, decodeNftBurn, decodeFtTransfer, decodeFtMint, decodeFtBurn, decodeClarityValue, decodeChainWebhook, createX402Client, createStreamsClient, consumeIndexFeed, buildSignedX402Payment, X402SpendGuardError, X402Result, X402Receipt, X402Fetch, X402ClientOptions, X402Client, X402Challenge, X402Accept, WithX402Options, WebhookHeaderInput, VersionConflictError, ValidationError, UpdateSubscriptionRequest2 as UpdateSubscriptionRequest, UpdateProjectParams, TransactionsWalkParams, TransactionsListParams, TransactionsEnvelope, TransactionProofVerifyResult, TransactionProof, TransactionEnvelope, Subscriptions, SubscriptionSummary2 as SubscriptionSummary, SubscriptionStatus, SubscriptionRuntime, SubscriptionKind, SubscriptionFormat, SubscriptionDetail2 as SubscriptionDetail, Subgraphs, SubgraphSpecOptions3 as SubgraphSpecOptions, SubgraphSpecFormat2 as SubgraphSpecFormat, SubgraphOperationStatus, SubgraphAgentSchema3 as SubgraphAgentSchema, StreamsUsage, StreamsTip, StreamsSignatureError, StreamsServerError, StreamsReorgsListParams, StreamsReorgsListEnvelope, StreamsReorgContext, StreamsReorg, StreamsEventsSubscribeParams, StreamsEventsStreamParams, StreamsEventsListParams, StreamsEventsListEnvelope, StreamsEventsEnvelope, StreamsEventsConsumeResult, StreamsEventsConsumeParams, StreamsEventType, StreamsEventPayload, StreamsEvent, StreamsDumpsManifest, StreamsDumps, StreamsDumpFile, StreamsConsumeParams, StreamsClient, StreamsCanonicalBlock, StreamsBatchContext, StreamsBatch, StandardWebhooksHeaders2 as StandardWebhooksHeaders, StackingWalkParams, StackingListParams, StackingEnvelope, SelectOfferOptions, SecondLayerOptions, SecondLayer, ScopedKeyProduct, SbtcWithdrawalsWalkParams, SbtcWithdrawalsListParams, SbtcWithdrawalsEnvelope, SbtcWithdrawalSweptConfirmedEvent, SbtcWithdrawalStatus, SbtcWithdrawalEvent, SbtcWithdrawalEnvelope, SbtcSummaryEnvelope, SbtcResource, SbtcEventsWalkParams, SbtcEventsListParams, SbtcEventsEnvelope, SbtcEventsConsumeParams, SbtcEventTopic, SbtcDepositsWalkParams, SbtcDepositsListParams, SbtcDepositsEnvelope, SbtcDepositsConsumeParams, SbtcDepositEvent, SbtcDepositEnvelope, RotateSecretResponse2 as RotateSecretResponse, RewardSet2 as RewardSet, ReplayResult2 as ReplayResult, RateLimitError, Projects, ProjectTeamMember, ProjectTeam, ProjectInvitation, Project, PrintSchemaResponse, PoxResource, PoxCyclesWalkParams, PoxCyclesListParams, PoxCyclesEnvelope, PoxCycleEnvelope, Pox5Resource, Pox5EventsWalkParams, Pox5EventsListParams, Pox5EventsEnvelope, PayAndRetryOptions, NftTransfersWalkParams, NftTransfersResource, NftTransfersListParams, NftTransfersEnvelope, NftTransferPayload, NftTransferEvent, NftTransfer, MempoolWalkParams, MempoolTransactionEnvelope, MempoolListParams, MempoolEnvelope, IndexUsage, IndexTransaction, IndexTip, IndexStxTransfer, IndexStxMint, IndexStxLock, IndexStxBurn, IndexStackingAction, IndexSbtcWithdrawalPhase, IndexSbtcWithdrawalDetail, IndexSbtcWithdrawal, IndexSbtcSummary, IndexSbtcEvent, IndexSbtcDepositDetail, IndexSbtcDeposit, IndexReorg, IndexPrint, IndexPoxFunctionCount, IndexPoxCycle, IndexPox5EventTopic, IndexPox5Event, IndexPostCondition, IndexNftTransfer, IndexNftMint, IndexNftBurn, IndexMempoolTransaction, IndexFtTransfer, IndexFtMint, IndexFtBurn, IndexFeedItem, IndexFeedFetcher, IndexFeedEnvelope, IndexEventsResource, IndexEventTypeFilters, IndexEventType, IndexEventOf, IndexEvent, IndexDiscovery, IndexContractCall, IndexConsumeOptions, IndexCanonicalBlock, IndexBlock, Index, FtTransfersWalkParams, FtTransfersResource, FtTransfersListParams, FtTransfersEnvelope, FtTransferPayload, FtTransferEvent, FtTransfer, FetchLike2 as FetchLike, EventsWalkParams, EventsListParams, EventsEnvelope, EventsConsumeParams, DeliveryRow2 as DeliveryRow, DecodedStxTransferPayload, DecodedStxTransfer, DecodedStxMintPayload, DecodedStxMint, DecodedStxLockPayload, DecodedStxLock, DecodedStxBurnPayload, DecodedStxBurn, DecodedPrintValue, DecodedPrintPayload, DecodedPrint, DecodedNftTransferPayload, DecodedNftTransfer, DecodedNftMintPayload, DecodedNftMint, DecodedNftBurnPayload, DecodedNftBurn, DecodedFtTransferPayload, DecodedFtTransfer, DecodedFtMintPayload, DecodedFtMint, DecodedFtBurnPayload, DecodedFtBurn, DecodedEventRow, DecodedEventColumns, DeadRow2 as DeadRow, DEFAULT_PREFER_ASSETS, Cursor, CreateSubscriptionResponse2 as CreateSubscriptionResponse, CreateSubscriptionRequest2 as CreateSubscriptionRequest, CreateProjectParams, CreateApiKeyResponse, CreateApiKeyParams, ContractsListParams, ContractsEnvelope, Contracts, ContractSummary, ContractConformance, ContractCallsWalkParams, ContractCallsListParams, ContractCallsEnvelope, ContractCallsConsumeParams, ContextSnapshot, ContextProject, ContextApiKey, ContextAccount, ConsumerBatchContext, ChainWebhookEnvelope, ChainWebhookDelivery2 as ChainWebhookDelivery, ChainTxLevelEvent, ChainTriggerType, ChainTrigger, ChainTestDelivery, ChainStxTransferData, ChainStxMintData, ChainStxLockData, ChainStxBurnData, ChainReorgRollbackEnvelope, ChainReorgRollbackDelivery, ChainReorgOrphanedEntry, ChainPrintEventData, ChainNftTransferData, ChainNftMintData, ChainNftBurnData, ChainFtTransferData, ChainFtMintData, ChainFtBurnData, ChainEventEnvelope, ChainApplyEnvelopeOf, ChainApplyEnvelope, ChainApplyDeliveryOf, CanonicalWalkParams, CanonicalListParams, CanonicalEnvelope, ByoBreakingChangeError, ByoBreakingChangeDetails, BuildSignedX402PaymentOptions, BlocksWalkParams, BlocksListParams, BlocksEnvelope, BlockEnvelope, AuthError, ApiKeys, ApiKeySummary, ApiError, ActiveSubgraphOperation };
|
package/dist/index.js
CHANGED
|
@@ -66,10 +66,12 @@ class BaseClient {
|
|
|
66
66
|
baseUrl;
|
|
67
67
|
apiKey;
|
|
68
68
|
origin;
|
|
69
|
+
fetchImpl;
|
|
69
70
|
constructor(options = {}) {
|
|
70
71
|
this.baseUrl = (options.baseUrl ?? DEFAULT_BASE_URL).replace(/\/+$/, "");
|
|
71
72
|
this.apiKey = resolveApiKey(options.apiKey);
|
|
72
73
|
this.origin = options.origin ?? "cli";
|
|
74
|
+
this.fetchImpl = options.fetchImpl ?? ((...args) => fetch(...args));
|
|
73
75
|
}
|
|
74
76
|
static authHeaders(apiKey) {
|
|
75
77
|
const headers = {
|
|
@@ -115,7 +117,7 @@ class BaseClient {
|
|
|
115
117
|
}
|
|
116
118
|
let response;
|
|
117
119
|
try {
|
|
118
|
-
response = await
|
|
120
|
+
response = await this.fetchImpl(url, {
|
|
119
121
|
method,
|
|
120
122
|
headers,
|
|
121
123
|
body: serializedBody
|
|
@@ -494,6 +496,19 @@ var Cursor = {
|
|
|
494
496
|
function reorgKey(reorg) {
|
|
495
497
|
return `${reorg.detected_at}|${reorg.fork_point_height}|${reorg.new_canonical_tip}`;
|
|
496
498
|
}
|
|
499
|
+
function assertFinalizedCheckpoint(returned, checkpoint) {
|
|
500
|
+
if (returned === null || returned === undefined)
|
|
501
|
+
return;
|
|
502
|
+
if (returned === checkpoint)
|
|
503
|
+
return;
|
|
504
|
+
const r = Cursor.parse(returned);
|
|
505
|
+
const c = checkpoint === null ? null : Cursor.parse(checkpoint);
|
|
506
|
+
const above = c === null || r.blockHeight > c.blockHeight || r.blockHeight === c.blockHeight && r.eventIndex > c.eventIndex;
|
|
507
|
+
if (above) {
|
|
508
|
+
const boundary = c ? ` ("${checkpoint}")` : " (none delivered yet)";
|
|
509
|
+
throw new ValidationError(`onBatch returned cursor "${returned}", above the last delivered finalized event${boundary}. With finalizedOnly, events past that point were filtered out and will be re-read once finalized — committing beyond it skips them permanently. Return ctx.cursor (or nothing); never envelope.next_cursor.`, 400);
|
|
510
|
+
}
|
|
511
|
+
}
|
|
497
512
|
function batchContext(cursor, height, tipHeight) {
|
|
498
513
|
return {
|
|
499
514
|
cursor,
|
|
@@ -558,6 +573,8 @@ async function consumeStreamsEvents(opts) {
|
|
|
558
573
|
const checkpoint = finalizedOnly ? emitted.at(-1)?.cursor ?? cursor : envelope.next_cursor;
|
|
559
574
|
height = emitted.at(-1)?.block_height ?? height;
|
|
560
575
|
const returnedCursor = await opts.onBatch(emitted, envelope, batchContext(checkpoint, height, envelope.tip.block_height));
|
|
576
|
+
if (finalizedOnly)
|
|
577
|
+
assertFinalizedCheckpoint(returnedCursor, checkpoint);
|
|
561
578
|
const nextCursor = returnedCursor ?? checkpoint;
|
|
562
579
|
if (nextCursor && nextCursor !== cursor) {
|
|
563
580
|
cursor = nextCursor;
|
|
@@ -691,6 +708,8 @@ async function consumeIndexFeed(opts) {
|
|
|
691
708
|
const checkpoint = finalizedOnly ? emitted.at(-1)?.cursor ?? cursor : envelope.next_cursor;
|
|
692
709
|
height = emitted.at(-1)?.block_height ?? height;
|
|
693
710
|
const returnedCursor = await opts.onBatch(emitted, envelope, batchContext(checkpoint, height, envelope.tip.block_height));
|
|
711
|
+
if (finalizedOnly)
|
|
712
|
+
assertFinalizedCheckpoint(returnedCursor, checkpoint);
|
|
694
713
|
const nextCursor = returnedCursor ?? checkpoint;
|
|
695
714
|
if (nextCursor && nextCursor !== cursor) {
|
|
696
715
|
cursor = nextCursor;
|
|
@@ -807,6 +826,19 @@ class Index extends BaseClient {
|
|
|
807
826
|
deposits: {
|
|
808
827
|
list: (params = {}) => this.listSbtcDeposits(params),
|
|
809
828
|
walk: (params = {}) => this.walkSbtcDeposits(params),
|
|
829
|
+
consume: (params) => consumeIndexFeed({
|
|
830
|
+
...params,
|
|
831
|
+
fetchPage: ({ cursor, fromHeight, limit }) => this.listSbtcDeposits({
|
|
832
|
+
confirmed: params.confirmed,
|
|
833
|
+
sender: params.sender,
|
|
834
|
+
bitcoinTxid: params.bitcoinTxid,
|
|
835
|
+
toHeight: params.toHeight,
|
|
836
|
+
cursor,
|
|
837
|
+
fromHeight,
|
|
838
|
+
limit
|
|
839
|
+
}),
|
|
840
|
+
itemsOf: (envelope) => envelope.deposits
|
|
841
|
+
}),
|
|
810
842
|
get: (bitcoinTxid) => this.getSbtcDeposit(bitcoinTxid)
|
|
811
843
|
},
|
|
812
844
|
withdrawals: {
|
|
@@ -816,7 +848,22 @@ class Index extends BaseClient {
|
|
|
816
848
|
},
|
|
817
849
|
events: {
|
|
818
850
|
list: (params = {}) => this.listSbtcEvents(params),
|
|
819
|
-
walk: (params = {}) => this.walkSbtcEvents(params)
|
|
851
|
+
walk: (params = {}) => this.walkSbtcEvents(params),
|
|
852
|
+
consume: (params) => consumeIndexFeed({
|
|
853
|
+
...params,
|
|
854
|
+
fetchPage: ({ cursor, fromHeight, limit }) => this.listSbtcEvents({
|
|
855
|
+
confirmed: params.confirmed,
|
|
856
|
+
topic: params.topic,
|
|
857
|
+
sender: params.sender,
|
|
858
|
+
requestId: params.requestId,
|
|
859
|
+
bitcoinTxid: params.bitcoinTxid,
|
|
860
|
+
toHeight: params.toHeight,
|
|
861
|
+
cursor,
|
|
862
|
+
fromHeight,
|
|
863
|
+
limit
|
|
864
|
+
}),
|
|
865
|
+
itemsOf: (envelope) => envelope.events
|
|
866
|
+
})
|
|
820
867
|
},
|
|
821
868
|
summary: () => this.getSbtcSummary()
|
|
822
869
|
};
|
|
@@ -2066,11 +2113,17 @@ class X402SpendGuardError extends Error {
|
|
|
2066
2113
|
}
|
|
2067
2114
|
}
|
|
2068
2115
|
function b64encode(value) {
|
|
2069
|
-
|
|
2116
|
+
const utf8 = new TextEncoder().encode(JSON.stringify(value));
|
|
2117
|
+
let binary = "";
|
|
2118
|
+
for (const byte of utf8)
|
|
2119
|
+
binary += String.fromCharCode(byte);
|
|
2120
|
+
return btoa(binary);
|
|
2070
2121
|
}
|
|
2071
2122
|
function b64decodeJson(value) {
|
|
2072
2123
|
try {
|
|
2073
|
-
|
|
2124
|
+
const binary = atob(value);
|
|
2125
|
+
const utf8 = Uint8Array.from(binary, (ch) => ch.charCodeAt(0));
|
|
2126
|
+
return JSON.parse(new TextDecoder().decode(utf8));
|
|
2074
2127
|
} catch {
|
|
2075
2128
|
return null;
|
|
2076
2129
|
}
|
|
@@ -2340,8 +2393,9 @@ import {
|
|
|
2340
2393
|
stacksTxid,
|
|
2341
2394
|
verifyTxMerkleProof
|
|
2342
2395
|
} from "@secondlayer/shared/node/nakamoto";
|
|
2396
|
+
import { hexToBytes } from "@secondlayer/stacks/utils";
|
|
2343
2397
|
var strip = (h) => h.startsWith("0x") ? h.slice(2) : h;
|
|
2344
|
-
var bytes = (h) =>
|
|
2398
|
+
var bytes = (h) => hexToBytes(h);
|
|
2345
2399
|
async function fetchRewardSet(opts) {
|
|
2346
2400
|
const f = opts.fetchImpl ?? fetch;
|
|
2347
2401
|
const res = await f(`${opts.nodeUrl.replace(/\/+$/, "")}/v3/stacker_set/${opts.cycle}`);
|
|
@@ -2468,5 +2522,5 @@ export {
|
|
|
2468
2522
|
ApiError
|
|
2469
2523
|
};
|
|
2470
2524
|
|
|
2471
|
-
//# debugId=
|
|
2525
|
+
//# debugId=7D05343D5E23B9E764756E2164756E21
|
|
2472
2526
|
//# sourceMappingURL=index.js.map
|