@sig-net/midnight 0.15.0 → 0.17.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 +113 -49
- package/dist/constants.d.ts +55 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +85 -5
- package/dist/constants.js.map +1 -1
- package/dist/ecdsa-attestation.d.ts +6 -5
- package/dist/ecdsa-attestation.d.ts.map +1 -1
- package/dist/ecdsa-attestation.js +5 -4
- package/dist/ecdsa-attestation.js.map +1 -1
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -4
- package/dist/index.js.map +1 -1
- package/dist/managed/compiler/contract-manifest.json +2 -2
- package/dist/managed/contract/index.js +31 -31
- package/dist/managed/contract/index.js.map +1 -1
- package/dist/signature-requests-state-reader.d.ts +7 -7
- package/dist/signature-requests-state-reader.js +7 -7
- package/dist/signature-response-verification.d.ts +1 -1
- package/dist/signature-response-verification.d.ts.map +1 -1
- package/dist/signature-response-verification.js +3 -3
- package/dist/signature-response-verification.js.map +1 -1
- package/dist/signature-state-reading.js +2 -2
- package/dist/signature-state-reading.js.map +1 -1
- package/dist/signet-contract-events.d.ts +267 -0
- package/dist/signet-contract-events.d.ts.map +1 -0
- package/dist/signet-contract-events.js +272 -0
- package/dist/signet-contract-events.js.map +1 -0
- package/dist/signet-evtype2tx-requests.d.ts +4 -4
- package/dist/signet-evtype2tx-requests.d.ts.map +1 -1
- package/dist/signet-evtype2tx-requests.js +3 -3
- package/dist/signet-request-feed.d.ts +61 -33
- package/dist/signet-request-feed.d.ts.map +1 -1
- package/dist/signet-request-feed.js +116 -62
- package/dist/signet-request-feed.js.map +1 -1
- package/dist/signet-request-response-reader.d.ts +62 -55
- package/dist/signet-request-response-reader.d.ts.map +1 -1
- package/dist/signet-request-response-reader.js +85 -99
- package/dist/signet-request-response-reader.js.map +1 -1
- package/dist/signet-requests.js +2 -2
- package/dist/signet-requests.js.map +1 -1
- package/package.json +2 -2
- package/src/Signet.compact +45 -36
- package/dist/signet-contract-state-reader.d.ts +0 -247
- package/dist/signet-contract-state-reader.d.ts.map +0 -1
- package/dist/signet-contract-state-reader.js +0 -363
- package/dist/signet-contract-state-reader.js.map +0 -1
- package/dist/signet-request-resolver.d.ts +0 -60
- package/dist/signet-request-resolver.d.ts.map +0 -1
- package/dist/signet-request-resolver.js +0 -78
- package/dist/signet-request-resolver.js.map +0 -1
|
@@ -1,22 +1,42 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type SignetEventSource } from "./signet-contract-events.ts";
|
|
2
2
|
import type { SignetPublicStateSource } from "./signet-request-response-reader.ts";
|
|
3
|
-
import { type RequestIdHex } from "./signet-requests.ts";
|
|
3
|
+
import { type RequestIdHex, type SignBidirectionalEvent } from "./signet-requests.ts";
|
|
4
4
|
/** Default gap between poll cycles of {@link SignetRequestFeed.requests}. */
|
|
5
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
|
+
}
|
|
6
22
|
/** Everything a {@link SignetRequestFeed} needs. */
|
|
7
23
|
export interface SignetRequestFeedConfig {
|
|
8
|
-
/** Address of the central signet contract whose notification
|
|
24
|
+
/** Address of the central signet contract whose notification events to poll. */
|
|
9
25
|
readonly signetContractAddress: string;
|
|
10
26
|
/**
|
|
11
|
-
* Source of raw contract state for
|
|
12
|
-
*
|
|
13
|
-
* `indexerPublicDataProvider` is assignable.
|
|
27
|
+
* Source of raw contract state for the requester ledgers the feed
|
|
28
|
+
* enumerates. A full `indexerPublicDataProvider` is assignable.
|
|
14
29
|
*/
|
|
15
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;
|
|
16
36
|
/**
|
|
17
37
|
* Optional policy allow-list of requester contract addresses to serve
|
|
18
38
|
* (matched case- and `0x`-prefix-insensitively). Omit to serve every
|
|
19
|
-
* requester
|
|
39
|
+
* requester a notification points at. NOT a security control.
|
|
20
40
|
*/
|
|
21
41
|
readonly allowContracts?: Iterable<string>;
|
|
22
42
|
/** Poll cadence for {@link SignetRequestFeed.requests}; default {@link DEFAULT_FEED_POLL_INTERVAL_MS}. */
|
|
@@ -32,51 +52,59 @@ export interface SignetRequestFeedConfig {
|
|
|
32
52
|
*/
|
|
33
53
|
export declare function sleepUnlessAborted(ms: number, signal?: AbortSignal): Promise<void>;
|
|
34
54
|
/**
|
|
35
|
-
* The
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
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
|
|
40
62
|
* {@link forget} to re-arm a request whose downstream processing failed.
|
|
41
63
|
*/
|
|
42
64
|
export declare class SignetRequestFeed {
|
|
43
65
|
private readonly signetContractAddress;
|
|
44
66
|
private readonly source;
|
|
45
|
-
private readonly
|
|
67
|
+
private readonly eventSource;
|
|
46
68
|
private readonly allowContracts?;
|
|
47
69
|
private readonly pollIntervalMs;
|
|
48
70
|
private readonly yielded;
|
|
49
71
|
/**
|
|
50
|
-
* @param config - The signet contract, state
|
|
51
|
-
* allow-list.
|
|
72
|
+
* @param config - The signet contract, state and event sources, and
|
|
73
|
+
* optional policy allow-list.
|
|
52
74
|
*/
|
|
53
75
|
constructor(config: SignetRequestFeedConfig);
|
|
54
76
|
/** Whether the policy allow-list admits `callerAddress` (always true when unset). */
|
|
55
77
|
private allowed;
|
|
56
78
|
/**
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* records are likewise skipped (and logged) without being marked.
|
|
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.
|
|
66
87
|
*
|
|
67
|
-
*
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
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.
|
|
71
99
|
*
|
|
72
|
-
* @returns The newly-authenticated requests this cycle.
|
|
73
|
-
* @throws Error
|
|
74
|
-
*
|
|
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).
|
|
75
103
|
*/
|
|
76
104
|
poll(): Promise<ResolvedSignetRequest[]>;
|
|
77
105
|
/**
|
|
78
106
|
* Re-arm `requestId` for redelivery on the next {@link poll} / {@link requests}
|
|
79
|
-
* cycle
|
|
107
|
+
* cycle: call when downstream processing of a yielded request failed, so it
|
|
80
108
|
* is retried (mirrors the MPC's delete-on-failure of its processed set).
|
|
81
109
|
*
|
|
82
110
|
* @param requestId - The request id to allow through again.
|
|
@@ -85,7 +113,7 @@ export declare class SignetRequestFeed {
|
|
|
85
113
|
/**
|
|
86
114
|
* Live stream: poll + sleep, yielding each authenticated request exactly once
|
|
87
115
|
* (subject to {@link forget}), until `opts.signal` aborts. The natural
|
|
88
|
-
* sequential `for await` consumption serializes downstream processing
|
|
116
|
+
* sequential `for await` consumption serializes downstream processing: no
|
|
89
117
|
* two requests are handed over concurrently.
|
|
90
118
|
*
|
|
91
119
|
* @param opts.signal - Abort to stop the stream.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signet-request-feed.d.ts","sourceRoot":"","sources":["../src/signet-request-feed.ts"],"names":[],"mappings":"
|
|
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,EAC5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IAAI,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,19 +1,25 @@
|
|
|
1
1
|
// The MPC's single entry point for discovering signature requests: poll the
|
|
2
|
-
// central signet contract's
|
|
3
|
-
// each
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
//
|
|
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.
|
|
8
15
|
//
|
|
9
16
|
// The requester allow-list is an OPTIONAL policy filter here (drop requests
|
|
10
17
|
// from contracts you choose not to serve), never a security requirement and
|
|
11
|
-
// never the discovery mechanism
|
|
12
|
-
// authenticated
|
|
13
|
-
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import { stripHexPrefix } from "./signet-requests.js";
|
|
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";
|
|
17
23
|
/** Default gap between poll cycles of {@link SignetRequestFeed.requests}. */
|
|
18
24
|
export const DEFAULT_FEED_POLL_INTERVAL_MS = 3000;
|
|
19
25
|
/**
|
|
@@ -44,30 +50,32 @@ function normalizeAddress(address) {
|
|
|
44
50
|
return stripHexPrefix(address).toLowerCase();
|
|
45
51
|
}
|
|
46
52
|
/**
|
|
47
|
-
* The
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
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
|
|
52
60
|
* {@link forget} to re-arm a request whose downstream processing failed.
|
|
53
61
|
*/
|
|
54
62
|
export class SignetRequestFeed {
|
|
55
63
|
signetContractAddress;
|
|
56
64
|
source;
|
|
57
|
-
|
|
65
|
+
eventSource;
|
|
58
66
|
allowContracts;
|
|
59
67
|
pollIntervalMs;
|
|
60
|
-
// Request ids already yielded. NOT the security boundary (the
|
|
61
|
-
// just an at-most-once gate so one request is not processed twice.
|
|
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.
|
|
62
70
|
yielded = new Set();
|
|
63
71
|
/**
|
|
64
|
-
* @param config - The signet contract, state
|
|
65
|
-
* allow-list.
|
|
72
|
+
* @param config - The signet contract, state and event sources, and
|
|
73
|
+
* optional policy allow-list.
|
|
66
74
|
*/
|
|
67
75
|
constructor(config) {
|
|
68
76
|
this.signetContractAddress = config.signetContractAddress;
|
|
69
77
|
this.source = config.source;
|
|
70
|
-
this.
|
|
78
|
+
this.eventSource = config.eventSource;
|
|
71
79
|
this.allowContracts = config.allowContracts
|
|
72
80
|
? new Set(Array.from(config.allowContracts, normalizeAddress))
|
|
73
81
|
: undefined;
|
|
@@ -80,58 +88,104 @@ export class SignetRequestFeed {
|
|
|
80
88
|
this.allowContracts.has(normalizeAddress(callerAddress)));
|
|
81
89
|
}
|
|
82
90
|
/**
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
* records are likewise skipped (and logged) without being marked.
|
|
92
|
-
*
|
|
93
|
-
* Dedupe and resolution key off the request id of the registry entry's map
|
|
94
|
-
* key (the V1 payload no longer carries one). The key is caller-supplied,
|
|
95
|
-
* so it confers no authority — the resolver's membership check against the
|
|
96
|
-
* named caller's own ledger is what authenticates it.
|
|
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.
|
|
97
99
|
*
|
|
98
|
-
* @returns The
|
|
99
|
-
* @throws Error if the signet contract has no readable state at the
|
|
100
|
-
* configured address (wrong address or not yet deployed/indexed).
|
|
100
|
+
* @returns The deduplicated pointers to look up this cycle.
|
|
101
101
|
*/
|
|
102
|
-
async
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const out = [];
|
|
110
|
-
for (const [requestId, record] of [...registry.entries()].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))) {
|
|
111
|
-
let notification;
|
|
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;
|
|
112
109
|
try {
|
|
113
|
-
|
|
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
|
+
};
|
|
114
117
|
}
|
|
115
118
|
catch (error) {
|
|
116
|
-
console.warn(`SignetRequestFeed: skipping undecodable notification `
|
|
117
|
-
`registered under ${requestId}: ${String(error)}`);
|
|
119
|
+
console.warn(`SignetRequestFeed: skipping undecodable notification event: ${String(error)}`);
|
|
118
120
|
continue;
|
|
119
121
|
}
|
|
120
|
-
if (this.
|
|
121
|
-
continue;
|
|
122
|
-
if (!this.allowed(notification.callerAddress))
|
|
122
|
+
if (!this.allowed(pointer.callerAddress))
|
|
123
123
|
continue;
|
|
124
|
-
|
|
125
|
-
|
|
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))
|
|
126
157
|
continue;
|
|
127
|
-
|
|
128
|
-
|
|
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
|
+
});
|
|
129
183
|
}
|
|
130
184
|
return out;
|
|
131
185
|
}
|
|
132
186
|
/**
|
|
133
187
|
* Re-arm `requestId` for redelivery on the next {@link poll} / {@link requests}
|
|
134
|
-
* cycle
|
|
188
|
+
* cycle: call when downstream processing of a yielded request failed, so it
|
|
135
189
|
* is retried (mirrors the MPC's delete-on-failure of its processed set).
|
|
136
190
|
*
|
|
137
191
|
* @param requestId - The request id to allow through again.
|
|
@@ -142,7 +196,7 @@ export class SignetRequestFeed {
|
|
|
142
196
|
/**
|
|
143
197
|
* Live stream: poll + sleep, yielding each authenticated request exactly once
|
|
144
198
|
* (subject to {@link forget}), until `opts.signal` aborts. The natural
|
|
145
|
-
* sequential `for await` consumption serializes downstream processing
|
|
199
|
+
* sequential `for await` consumption serializes downstream processing: no
|
|
146
200
|
* two requests are handed over concurrently.
|
|
147
201
|
*
|
|
148
202
|
* @param opts.signal - Abort to stop the stream.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signet-request-feed.js","sourceRoot":"","sources":["../src/signet-request-feed.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,4EAA4E;AAC5E,
|
|
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,E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