@sig-net/midnight 0.19.0 → 0.20.0-rc.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 +42 -2
- package/dist/abi-serde.d.ts +32 -30
- package/dist/abi-serde.d.ts.map +1 -1
- package/dist/abi-serde.js +139 -75
- package/dist/abi-serde.js.map +1 -1
- package/dist/byte-codecs.d.ts +62 -0
- package/dist/byte-codecs.d.ts.map +1 -0
- package/dist/byte-codecs.js +116 -0
- package/dist/byte-codecs.js.map +1 -0
- package/dist/compact-descriptors.d.ts +89 -0
- package/dist/compact-descriptors.d.ts.map +1 -0
- package/dist/compact-descriptors.js +139 -0
- package/dist/compact-descriptors.js.map +1 -0
- package/dist/constants.d.ts +18 -43
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +19 -45
- package/dist/constants.js.map +1 -1
- package/dist/ecdsa-attestation.d.ts +49 -97
- package/dist/ecdsa-attestation.d.ts.map +1 -1
- package/dist/ecdsa-attestation.js +78 -142
- package/dist/ecdsa-attestation.js.map +1 -1
- package/dist/epsilon-derivation.d.ts +24 -31
- package/dist/epsilon-derivation.d.ts.map +1 -1
- package/dist/epsilon-derivation.js +52 -62
- package/dist/epsilon-derivation.js.map +1 -1
- package/dist/index.d.ts +10 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -8
- package/dist/index.js.map +1 -1
- package/dist/managed/compiler/contract-info.json +0 -22
- package/dist/managed/compiler/contract-manifest.json +8 -8
- package/dist/managed/contract/index.d.ts +0 -3
- package/dist/managed/contract/index.js +65 -80
- package/dist/managed/contract/index.js.map +1 -1
- package/dist/raw-contract-state.d.ts +25 -0
- package/dist/raw-contract-state.d.ts.map +1 -0
- package/dist/raw-contract-state.js +52 -0
- package/dist/raw-contract-state.js.map +1 -0
- package/dist/signature-requests-state-reader.d.ts +18 -44
- package/dist/signature-requests-state-reader.d.ts.map +1 -1
- package/dist/signature-requests-state-reader.js +82 -146
- package/dist/signature-requests-state-reader.js.map +1 -1
- package/dist/signature-response-verification.d.ts +9 -8
- package/dist/signature-response-verification.d.ts.map +1 -1
- package/dist/signature-response-verification.js +20 -17
- package/dist/signature-response-verification.js.map +1 -1
- package/dist/signet-contract-events.d.ts +56 -64
- package/dist/signet-contract-events.d.ts.map +1 -1
- package/dist/signet-contract-events.js +46 -48
- package/dist/signet-contract-events.js.map +1 -1
- package/dist/signet-evtype2tx-record-decoding.d.ts +18 -0
- package/dist/signet-evtype2tx-record-decoding.d.ts.map +1 -0
- package/dist/signet-evtype2tx-record-decoding.js +97 -0
- package/dist/signet-evtype2tx-record-decoding.js.map +1 -0
- package/dist/signet-evtype2tx-requests.d.ts +43 -87
- package/dist/signet-evtype2tx-requests.d.ts.map +1 -1
- package/dist/signet-evtype2tx-requests.js +59 -130
- package/dist/signet-evtype2tx-requests.js.map +1 -1
- package/dist/signet-request-id.d.ts +14 -0
- package/dist/signet-request-id.d.ts.map +1 -0
- package/dist/signet-request-id.js +27 -0
- package/dist/signet-request-id.js.map +1 -0
- package/dist/signet-request-response-reader.d.ts +34 -56
- package/dist/signet-request-response-reader.d.ts.map +1 -1
- package/dist/signet-request-response-reader.js +56 -68
- package/dist/signet-request-response-reader.js.map +1 -1
- package/dist/signet-requests.d.ts +28 -92
- package/dist/signet-requests.d.ts.map +1 -1
- package/dist/signet-requests.js +39 -141
- package/dist/signet-requests.js.map +1 -1
- package/dist/testing.d.ts +3 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +20 -0
- package/dist/testing.js.map +1 -0
- package/package.json +12 -3
- package/src/Signet.compact +110 -171
- package/src/circuits.compact +9 -16
- package/dist/signature-state-reading.d.ts +0 -43
- package/dist/signature-state-reading.d.ts.map +0 -1
- package/dist/signature-state-reading.js +0 -74
- package/dist/signature-state-reading.js.map +0 -1
- package/dist/signet-request-feed.d.ts +0 -126
- package/dist/signet-request-feed.d.ts.map +0 -1
- package/dist/signet-request-feed.js +0 -216
- package/dist/signet-request-feed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AsE;YACtE,mEAAmE;YACnE,kCAAkC;YAClC,IAAI,KAAK,KAAK,CAAC,IAAI,KAAK,KAAK,IAAI,CAAC,MAAM,GAAG,CAAC;gBAAE,OAAO,IAAI,CAAC;YAC1D,MAAM,IAAI,KAAK,CACb,qBAAqB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,oCAAoC,KAAK,EAAE,CACrF,CAAC;QACJ,CAAC;QACD,MAAM,IAAI,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC;QAC3C,IAAI,IAAI,KAAK,SAAS,EAAE,CAAC;YACvB,MAAM,IAAI,KAAK,CACb,qBAAqB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,KAAK,0BAA0B,KAAK,EAAE,CAC1F,CAAC;QACJ,CAAC;QACD,IAAI,GAAG,IAAI,CAAC;IACd,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
import { type SignetEventSource } from "./signet-contract-events.ts";
|
|
2
|
-
import type { SignetPublicStateSource } from "./signet-request-response-reader.ts";
|
|
3
|
-
import { type RequestIdHex, type SignBidirectionalEvent } from "./signet-requests.ts";
|
|
4
|
-
/** Default gap between poll cycles of {@link SignetRequestFeed.requests}. */
|
|
5
|
-
export declare const DEFAULT_FEED_POLL_INTERVAL_MS = 3000;
|
|
6
|
-
/**
|
|
7
|
-
* A request discovered through a notification event and read from the named
|
|
8
|
-
* caller's own authenticated ledger.
|
|
9
|
-
*/
|
|
10
|
-
export interface ResolvedSignetRequest {
|
|
11
|
-
/**
|
|
12
|
-
* The contract whose authenticated state the request was read from: the
|
|
13
|
-
* epsilon-derivation predecessor. Key derivation keys off THIS, never off a
|
|
14
|
-
* field taken from the notification on faith.
|
|
15
|
-
*/
|
|
16
|
-
callerAddress: string;
|
|
17
|
-
/** The request id the record is stored under in `callerAddress`'s index. */
|
|
18
|
-
requestId: RequestIdHex;
|
|
19
|
-
/** The authenticated request record to sign. */
|
|
20
|
-
request: SignBidirectionalEvent;
|
|
21
|
-
}
|
|
22
|
-
/** Everything a {@link SignetRequestFeed} needs. */
|
|
23
|
-
export interface SignetRequestFeedConfig {
|
|
24
|
-
/** Address of the central signet contract whose notification events to poll. */
|
|
25
|
-
readonly signetContractAddress: string;
|
|
26
|
-
/**
|
|
27
|
-
* Source of raw contract state for the requester ledgers the feed
|
|
28
|
-
* enumerates. A full `indexerPublicDataProvider` is assignable.
|
|
29
|
-
*/
|
|
30
|
-
readonly source: SignetPublicStateSource;
|
|
31
|
-
/**
|
|
32
|
-
* Source of the signet contract's emitted events (discovery). Adapt a full
|
|
33
|
-
* provider with `signetEventSourceFromPublicDataProvider`.
|
|
34
|
-
*/
|
|
35
|
-
readonly eventSource: SignetEventSource;
|
|
36
|
-
/**
|
|
37
|
-
* Optional policy allow-list of requester contract addresses to serve
|
|
38
|
-
* (matched case- and `0x`-prefix-insensitively). Omit to serve every
|
|
39
|
-
* requester a notification points at. NOT a security control.
|
|
40
|
-
*/
|
|
41
|
-
readonly allowContracts?: Iterable<string>;
|
|
42
|
-
/** Poll cadence for {@link SignetRequestFeed.requests}; default {@link DEFAULT_FEED_POLL_INTERVAL_MS}. */
|
|
43
|
-
readonly pollIntervalMs?: number;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Resolve after `ms`, or immediately once `signal` aborts. Used to space out
|
|
47
|
-
* polls without wedging a shutdown.
|
|
48
|
-
*
|
|
49
|
-
* @param ms - Milliseconds to wait.
|
|
50
|
-
* @param signal - Abort to resolve early.
|
|
51
|
-
* @returns A promise that settles after the delay or the abort.
|
|
52
|
-
*/
|
|
53
|
-
export declare function sleepUnlessAborted(ms: number, signal?: AbortSignal): Promise<void>;
|
|
54
|
-
/**
|
|
55
|
-
* The event-polling request feed. Reads the signet contract's emitted
|
|
56
|
-
* notifications (discovery) and looks each declared request id up in the
|
|
57
|
-
* pointed-at caller's own request map (authentication by construction: the
|
|
58
|
-
* records come from the caller's ledger), yielding each found request once.
|
|
59
|
-
* A request stored WITHOUT a notification is never discovered: the
|
|
60
|
-
* notification is the doorbell. Dedupes by request id across its lifetime,
|
|
61
|
-
* so a re-notified or still-pending request is not re-yielded. Call
|
|
62
|
-
* {@link forget} to re-arm a request whose downstream processing failed.
|
|
63
|
-
*/
|
|
64
|
-
export declare class SignetRequestFeed {
|
|
65
|
-
private readonly signetContractAddress;
|
|
66
|
-
private readonly source;
|
|
67
|
-
private readonly eventSource;
|
|
68
|
-
private readonly allowContracts?;
|
|
69
|
-
private readonly pollIntervalMs;
|
|
70
|
-
private readonly yielded;
|
|
71
|
-
/**
|
|
72
|
-
* @param config - The signet contract, state and event sources, and
|
|
73
|
-
* optional policy allow-list.
|
|
74
|
-
*/
|
|
75
|
-
constructor(config: SignetRequestFeedConfig);
|
|
76
|
-
/** Whether the policy allow-list admits `callerAddress` (always true when unset). */
|
|
77
|
-
private allowed;
|
|
78
|
-
/**
|
|
79
|
-
* The unique `(callerAddress, requestsPath, requestId)` pointers of the
|
|
80
|
-
* currently emitted notification events, allow-list applied, in ascending
|
|
81
|
-
* (caller-address, request-id) order (event enumeration order is
|
|
82
|
-
* per-source, so a stable sort keeps the poll deterministic). Deduped by
|
|
83
|
-
* the FULL triple, not the id alone, so a forged notification declaring a
|
|
84
|
-
* genuine id under a wrong pointer cannot shadow the genuine one.
|
|
85
|
-
* Undecodable or unsupported-version events are skipped (and logged):
|
|
86
|
-
* they carry no readable pointer, so nothing is lost.
|
|
87
|
-
*
|
|
88
|
-
* @returns The deduplicated pointers to look up this cycle.
|
|
89
|
-
*/
|
|
90
|
-
private notificationPointers;
|
|
91
|
-
/**
|
|
92
|
-
* One-shot: every notified request that is admitted by the allow-list,
|
|
93
|
-
* not already yielded, and found by id in the pointed-at caller's own
|
|
94
|
-
* request map. A pointer whose caller has no readable state, whose path
|
|
95
|
-
* holds no request map, or whose declared id is not (yet) a member yields
|
|
96
|
-
* nothing WITHOUT marking anything, so a genuine request whose ledger
|
|
97
|
-
* write has not indexed yet is retried next cycle. One caller's state is
|
|
98
|
-
* queried at most once per cycle.
|
|
99
|
-
*
|
|
100
|
-
* @returns The newly-discovered authenticated requests this cycle.
|
|
101
|
-
* @throws Error when the event source itself fails (e.g. the indexer is
|
|
102
|
-
* unreachable).
|
|
103
|
-
*/
|
|
104
|
-
poll(): Promise<ResolvedSignetRequest[]>;
|
|
105
|
-
/**
|
|
106
|
-
* Re-arm `requestId` for redelivery on the next {@link poll} / {@link requests}
|
|
107
|
-
* cycle: call when downstream processing of a yielded request failed, so it
|
|
108
|
-
* is retried (mirrors the MPC's delete-on-failure of its processed set).
|
|
109
|
-
*
|
|
110
|
-
* @param requestId - The request id to allow through again.
|
|
111
|
-
*/
|
|
112
|
-
forget(requestId: RequestIdHex): void;
|
|
113
|
-
/**
|
|
114
|
-
* Live stream: poll + sleep, yielding each authenticated request exactly once
|
|
115
|
-
* (subject to {@link forget}), until `opts.signal` aborts. The natural
|
|
116
|
-
* sequential `for await` consumption serializes downstream processing: no
|
|
117
|
-
* two requests are handed over concurrently.
|
|
118
|
-
*
|
|
119
|
-
* @param opts.signal - Abort to stop the stream.
|
|
120
|
-
* @yields Each authenticated request, in discovery order.
|
|
121
|
-
*/
|
|
122
|
-
requests(opts?: {
|
|
123
|
-
signal?: AbortSignal;
|
|
124
|
-
}): AsyncIterableIterator<ResolvedSignetRequest>;
|
|
125
|
-
}
|
|
126
|
-
//# sourceMappingURL=signet-request-feed.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"signet-request-feed.d.ts","sourceRoot":"","sources":["../src/signet-request-feed.ts"],"names":[],"mappings":"AAoBA,OAAO,EAIL,KAAK,iBAAiB,EACvB,MAAM,6BAA6B,CAAC;AAErC,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,qCAAqC,CAAC;AAEnF,OAAO,EAGL,KAAK,YAAY,EACjB,KAAK,sBAAsB,EAC5B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AAI,IAAI,OAAO,CAAC,qBAAqB,EAAE,CAAC;IAuC9C;;;;;;OAMG;IACH,MAAM,CAAC,SAAS,EAAE,YAAY,GAAG,IAAI;IAIrC;;;;;;;;OAQG;IACI,QAAQ,CAAC,IAAI,CAAC,EAAE;QACrB,MAAM,CAAC,EAAE,WAAW,CAAC;KACtB,GAAG,qBAAqB,CAAC,qBAAqB,CAAC;CAQjD"}
|
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
// The MPC's single entry point for discovering signature requests: poll the
|
|
2
|
-
// central signet contract's emitted SignBidirectionalEvent notifications,
|
|
3
|
-
// follow each to the named caller contract, and read the AUTHENTICATED
|
|
4
|
-
// request it declares from that caller's own request map. A notification is
|
|
5
|
-
// a doorbell, never an authority: it says only WHERE to look (caller
|
|
6
|
-
// address + the resolved ledger-tree path of its request map) and WHICH
|
|
7
|
-
// request (the declared id), and every request served comes from the named
|
|
8
|
-
// caller's own ledger. An attacker cannot write into a contract it does not
|
|
9
|
-
// control, so a forged notification can at most re-point at a legitimate
|
|
10
|
-
// caller's stored request, never inject one.
|
|
11
|
-
//
|
|
12
|
-
// The event log has no on-ledger cursor the feed consumes, so the feed's
|
|
13
|
-
// in-memory `yielded` set is the diff cursor: every poll looks up the
|
|
14
|
-
// notified requests and serves what it has not served before.
|
|
15
|
-
//
|
|
16
|
-
// The requester allow-list is an OPTIONAL policy filter here (drop requests
|
|
17
|
-
// from contracts you choose not to serve), never a security requirement and
|
|
18
|
-
// never the discovery mechanism: attribution comes from reading the
|
|
19
|
-
// caller's authenticated state.
|
|
20
|
-
import { decodeSignBidirectionalEventNotificationPayload, decodeSignBidirectionalNotification, SignetEventName, } from "./signet-contract-events.js";
|
|
21
|
-
import { lookupSignetRequestAt } from "./signature-requests-state-reader.js";
|
|
22
|
-
import { requestIdHex, stripHexPrefix, } from "./signet-requests.js";
|
|
23
|
-
/** Default gap between poll cycles of {@link SignetRequestFeed.requests}. */
|
|
24
|
-
export const DEFAULT_FEED_POLL_INTERVAL_MS = 3000;
|
|
25
|
-
/**
|
|
26
|
-
* Resolve after `ms`, or immediately once `signal` aborts. Used to space out
|
|
27
|
-
* polls without wedging a shutdown.
|
|
28
|
-
*
|
|
29
|
-
* @param ms - Milliseconds to wait.
|
|
30
|
-
* @param signal - Abort to resolve early.
|
|
31
|
-
* @returns A promise that settles after the delay or the abort.
|
|
32
|
-
*/
|
|
33
|
-
export function sleepUnlessAborted(ms, signal) {
|
|
34
|
-
return new Promise((resolve) => {
|
|
35
|
-
if (signal?.aborted)
|
|
36
|
-
return resolve();
|
|
37
|
-
const timer = setTimeout(() => {
|
|
38
|
-
signal?.removeEventListener("abort", onAbort);
|
|
39
|
-
resolve();
|
|
40
|
-
}, ms);
|
|
41
|
-
const onAbort = () => {
|
|
42
|
-
clearTimeout(timer);
|
|
43
|
-
resolve();
|
|
44
|
-
};
|
|
45
|
-
signal?.addEventListener("abort", onAbort, { once: true });
|
|
46
|
-
});
|
|
47
|
-
}
|
|
48
|
-
/** Canonical form for comparing contract addresses: no `0x`, lowercase. */
|
|
49
|
-
function normalizeAddress(address) {
|
|
50
|
-
return stripHexPrefix(address).toLowerCase();
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* The event-polling request feed. Reads the signet contract's emitted
|
|
54
|
-
* notifications (discovery) and looks each declared request id up in the
|
|
55
|
-
* pointed-at caller's own request map (authentication by construction: the
|
|
56
|
-
* records come from the caller's ledger), yielding each found request once.
|
|
57
|
-
* A request stored WITHOUT a notification is never discovered: the
|
|
58
|
-
* notification is the doorbell. Dedupes by request id across its lifetime,
|
|
59
|
-
* so a re-notified or still-pending request is not re-yielded. Call
|
|
60
|
-
* {@link forget} to re-arm a request whose downstream processing failed.
|
|
61
|
-
*/
|
|
62
|
-
export class SignetRequestFeed {
|
|
63
|
-
signetContractAddress;
|
|
64
|
-
source;
|
|
65
|
-
eventSource;
|
|
66
|
-
allowContracts;
|
|
67
|
-
pollIntervalMs;
|
|
68
|
-
// Request ids already yielded. NOT the security boundary (the caller-ledger
|
|
69
|
-
// read is), just an at-most-once gate so one request is not processed twice.
|
|
70
|
-
yielded = new Set();
|
|
71
|
-
/**
|
|
72
|
-
* @param config - The signet contract, state and event sources, and
|
|
73
|
-
* optional policy allow-list.
|
|
74
|
-
*/
|
|
75
|
-
constructor(config) {
|
|
76
|
-
this.signetContractAddress = config.signetContractAddress;
|
|
77
|
-
this.source = config.source;
|
|
78
|
-
this.eventSource = config.eventSource;
|
|
79
|
-
this.allowContracts = config.allowContracts
|
|
80
|
-
? new Set(Array.from(config.allowContracts, normalizeAddress))
|
|
81
|
-
: undefined;
|
|
82
|
-
this.pollIntervalMs =
|
|
83
|
-
config.pollIntervalMs ?? DEFAULT_FEED_POLL_INTERVAL_MS;
|
|
84
|
-
}
|
|
85
|
-
/** Whether the policy allow-list admits `callerAddress` (always true when unset). */
|
|
86
|
-
allowed(callerAddress) {
|
|
87
|
-
return (this.allowContracts === undefined ||
|
|
88
|
-
this.allowContracts.has(normalizeAddress(callerAddress)));
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* The unique `(callerAddress, requestsPath, requestId)` pointers of the
|
|
92
|
-
* currently emitted notification events, allow-list applied, in ascending
|
|
93
|
-
* (caller-address, request-id) order (event enumeration order is
|
|
94
|
-
* per-source, so a stable sort keeps the poll deterministic). Deduped by
|
|
95
|
-
* the FULL triple, not the id alone, so a forged notification declaring a
|
|
96
|
-
* genuine id under a wrong pointer cannot shadow the genuine one.
|
|
97
|
-
* Undecodable or unsupported-version events are skipped (and logged):
|
|
98
|
-
* they carry no readable pointer, so nothing is lost.
|
|
99
|
-
*
|
|
100
|
-
* @returns The deduplicated pointers to look up this cycle.
|
|
101
|
-
*/
|
|
102
|
-
async notificationPointers() {
|
|
103
|
-
const events = await this.eventSource.querySignetEvents(this.signetContractAddress);
|
|
104
|
-
const pointers = new Map();
|
|
105
|
-
for (const event of events) {
|
|
106
|
-
if (event.name !== SignetEventName.SignBidirectionalEvent)
|
|
107
|
-
continue;
|
|
108
|
-
let pointer;
|
|
109
|
-
try {
|
|
110
|
-
const post = decodeSignBidirectionalEventNotificationPayload(event.payload);
|
|
111
|
-
const notification = decodeSignBidirectionalNotification(post.event);
|
|
112
|
-
pointer = {
|
|
113
|
-
callerAddress: notification.callerAddress,
|
|
114
|
-
requestsPath: notification.requestsPath,
|
|
115
|
-
requestId: requestIdHex(post.requestId),
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
catch (error) {
|
|
119
|
-
console.warn(`SignetRequestFeed: skipping undecodable notification event: ${String(error)}`);
|
|
120
|
-
continue;
|
|
121
|
-
}
|
|
122
|
-
if (!this.allowed(pointer.callerAddress))
|
|
123
|
-
continue;
|
|
124
|
-
pointers.set(`${pointer.callerAddress}:${pointer.requestsPath.join(",")}:${pointer.requestId}`, pointer);
|
|
125
|
-
}
|
|
126
|
-
return [...pointers.values()].sort((a, b) => {
|
|
127
|
-
const byCaller = a.callerAddress < b.callerAddress
|
|
128
|
-
? -1
|
|
129
|
-
: a.callerAddress > b.callerAddress
|
|
130
|
-
? 1
|
|
131
|
-
: 0;
|
|
132
|
-
if (byCaller !== 0)
|
|
133
|
-
return byCaller;
|
|
134
|
-
return a.requestId < b.requestId ? -1 : a.requestId > b.requestId ? 1 : 0;
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
/**
|
|
138
|
-
* One-shot: every notified request that is admitted by the allow-list,
|
|
139
|
-
* not already yielded, and found by id in the pointed-at caller's own
|
|
140
|
-
* request map. A pointer whose caller has no readable state, whose path
|
|
141
|
-
* holds no request map, or whose declared id is not (yet) a member yields
|
|
142
|
-
* nothing WITHOUT marking anything, so a genuine request whose ledger
|
|
143
|
-
* write has not indexed yet is retried next cycle. One caller's state is
|
|
144
|
-
* queried at most once per cycle.
|
|
145
|
-
*
|
|
146
|
-
* @returns The newly-discovered authenticated requests this cycle.
|
|
147
|
-
* @throws Error when the event source itself fails (e.g. the indexer is
|
|
148
|
-
* unreachable).
|
|
149
|
-
*/
|
|
150
|
-
async poll() {
|
|
151
|
-
const out = [];
|
|
152
|
-
// Per-cycle caller-state cache: null marks a caller whose state could
|
|
153
|
-
// not be read this cycle (not a contract / transient read error).
|
|
154
|
-
const states = new Map();
|
|
155
|
-
for (const pointer of await this.notificationPointers()) {
|
|
156
|
-
if (this.yielded.has(pointer.requestId))
|
|
157
|
-
continue;
|
|
158
|
-
let raw = states.get(pointer.callerAddress);
|
|
159
|
-
if (raw === undefined) {
|
|
160
|
-
try {
|
|
161
|
-
raw =
|
|
162
|
-
(await this.source.queryContractState(pointer.callerAddress))
|
|
163
|
-
?.data ?? null;
|
|
164
|
-
}
|
|
165
|
-
catch {
|
|
166
|
-
raw = null;
|
|
167
|
-
}
|
|
168
|
-
states.set(pointer.callerAddress, raw);
|
|
169
|
-
}
|
|
170
|
-
if (raw === null) {
|
|
171
|
-
continue; // no state at the named caller: nothing to serve yet
|
|
172
|
-
}
|
|
173
|
-
const request = lookupSignetRequestAt(raw, pointer.requestsPath, pointer.requestId);
|
|
174
|
-
if (request === undefined) {
|
|
175
|
-
continue; // forged pointer, or the ledger write has not indexed yet
|
|
176
|
-
}
|
|
177
|
-
this.yielded.add(pointer.requestId);
|
|
178
|
-
out.push({
|
|
179
|
-
callerAddress: pointer.callerAddress,
|
|
180
|
-
requestId: pointer.requestId,
|
|
181
|
-
request,
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
return out;
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Re-arm `requestId` for redelivery on the next {@link poll} / {@link requests}
|
|
188
|
-
* cycle: call when downstream processing of a yielded request failed, so it
|
|
189
|
-
* is retried (mirrors the MPC's delete-on-failure of its processed set).
|
|
190
|
-
*
|
|
191
|
-
* @param requestId - The request id to allow through again.
|
|
192
|
-
*/
|
|
193
|
-
forget(requestId) {
|
|
194
|
-
this.yielded.delete(requestId);
|
|
195
|
-
}
|
|
196
|
-
/**
|
|
197
|
-
* Live stream: poll + sleep, yielding each authenticated request exactly once
|
|
198
|
-
* (subject to {@link forget}), until `opts.signal` aborts. The natural
|
|
199
|
-
* sequential `for await` consumption serializes downstream processing: no
|
|
200
|
-
* two requests are handed over concurrently.
|
|
201
|
-
*
|
|
202
|
-
* @param opts.signal - Abort to stop the stream.
|
|
203
|
-
* @yields Each authenticated request, in discovery order.
|
|
204
|
-
*/
|
|
205
|
-
async *requests(opts) {
|
|
206
|
-
while (!opts?.signal?.aborted) {
|
|
207
|
-
const batch = await this.poll();
|
|
208
|
-
for (const resolved of batch)
|
|
209
|
-
yield resolved;
|
|
210
|
-
if (opts?.signal?.aborted)
|
|
211
|
-
break;
|
|
212
|
-
await sleepUnlessAborted(this.pollIntervalMs, opts?.signal);
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
//# sourceMappingURL=signet-request-feed.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"signet-request-feed.js","sourceRoot":"","sources":["../src/signet-request-feed.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,0EAA0E;AAC1E,uEAAuE;AACvE,4EAA4E;AAC5E,qEAAqE;AACrE,wEAAwE;AACxE,2EAA2E;AAC3E,4EAA4E;AAC5E,yEAAyE;AACzE,6CAA6C;AAC7C,EAAE;AACF,yEAAyE;AACzE,sEAAsE;AACtE,8DAA8D;AAC9D,EAAE;AACF,4EAA4E;AAC5E,4EAA4E;AAC5E,oEAAoE;AACpE,gCAAgC;AAEhC,OAAO,EACL,+CAA+C,EAC/C,mCAAmC,EACnC,eAAe,GAEhB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,qBAAqB,EAAE,MAAM,sCAAsC,CAAC;AAG7E,OAAO,EACL,YAAY,EACZ,cAAc,GAGf,MAAM,sBAAsB,CAAC;AAE9B,6EAA6E;AAC7E,MAAM,CAAC,MAAM,6BAA6B,GAAG,IAAI,CAAC;AA2ClD;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAChC,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