@sig-net/midnight 0.14.0 → 0.16.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 +133 -48
- 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-info.json +12 -1
- package/dist/managed/compiler/contract-manifest.json +8 -8
- package/dist/managed/contract/index.d.ts +8 -6
- package/dist/managed/contract/index.js +76 -60
- package/dist/managed/contract/index.js.map +1 -1
- package/dist/signature-requests-state-reader.d.ts +29 -10
- package/dist/signature-requests-state-reader.d.ts.map +1 -1
- package/dist/signature-requests-state-reader.js +67 -21
- package/dist/signature-requests-state-reader.js.map +1 -1
- 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.d.ts +17 -25
- package/dist/signature-state-reading.d.ts.map +1 -1
- package/dist/signature-state-reading.js +39 -59
- package/dist/signature-state-reading.js.map +1 -1
- package/dist/signet-contract-events.d.ts +262 -0
- package/dist/signet-contract-events.d.ts.map +1 -0
- package/dist/signet-contract-events.js +266 -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 +59 -34
- package/dist/signet-request-feed.d.ts.map +1 -1
- package/dist/signet-request-feed.js +95 -62
- package/dist/signet-request-feed.js.map +1 -1
- package/dist/signet-request-response-reader.d.ts +70 -62
- package/dist/signet-request-response-reader.d.ts.map +1 -1
- package/dist/signet-request-response-reader.js +88 -102
- 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 +90 -43
- package/dist/signet-contract-state-reader.d.ts +0 -241
- package/dist/signet-contract-state-reader.d.ts.map +0 -1
- package/dist/signet-contract-state-reader.js +0 -345
- 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,56 @@ 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
|
-
* lifetime, so a re-
|
|
40
|
-
* {@link forget} to re-arm a request whose downstream
|
|
55
|
+
* The event-polling request feed. Reads the signet contract's emitted
|
|
56
|
+
* notifications (discovery) and enumerates each pointed-at caller's own
|
|
57
|
+
* request map (authentication by construction: the records come from the
|
|
58
|
+
* caller's ledger), yielding each member request once. Dedupes by request id
|
|
59
|
+
* across its lifetime, so a re-notified or still-pending request is not
|
|
60
|
+
* re-yielded. Call {@link forget} to re-arm a request whose downstream
|
|
61
|
+
* processing failed.
|
|
41
62
|
*/
|
|
42
63
|
export declare class SignetRequestFeed {
|
|
43
64
|
private readonly signetContractAddress;
|
|
44
65
|
private readonly source;
|
|
45
|
-
private readonly
|
|
66
|
+
private readonly eventSource;
|
|
46
67
|
private readonly allowContracts?;
|
|
47
68
|
private readonly pollIntervalMs;
|
|
48
69
|
private readonly yielded;
|
|
49
70
|
/**
|
|
50
|
-
* @param config - The signet contract, state
|
|
51
|
-
* allow-list.
|
|
71
|
+
* @param config - The signet contract, state and event sources, and
|
|
72
|
+
* optional policy allow-list.
|
|
52
73
|
*/
|
|
53
74
|
constructor(config: SignetRequestFeedConfig);
|
|
54
75
|
/** Whether the policy allow-list admits `callerAddress` (always true when unset). */
|
|
55
76
|
private allowed;
|
|
56
77
|
/**
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
* being marked yielded, so a genuine request whose ledger write has not
|
|
64
|
-
* indexed yet is retried next cycle; undecodable or unsupported-version
|
|
65
|
-
* records are likewise skipped (and logged) without being marked.
|
|
78
|
+
* The unique `(callerAddress, requestsPath)` pointers of the currently
|
|
79
|
+
* emitted notification events, allow-list applied, in ascending
|
|
80
|
+
* caller-address order (event enumeration order is per-source, so a
|
|
81
|
+
* stable sort keeps the poll deterministic). Undecodable or
|
|
82
|
+
* unsupported-version events are skipped (and logged): they carry no
|
|
83
|
+
* request, so nothing is lost.
|
|
66
84
|
*
|
|
67
|
-
*
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
85
|
+
* @returns The deduplicated pointers to enumerate this cycle.
|
|
86
|
+
*/
|
|
87
|
+
private notificationPointers;
|
|
88
|
+
/**
|
|
89
|
+
* One-shot: every request in a notified caller's request map that is
|
|
90
|
+
* admitted by the allow-list and not already yielded. Within one caller's
|
|
91
|
+
* map, requests are processed in ascending request-id-hex order: a
|
|
92
|
+
* stable, deterministic sequence. A pointer at a caller with no readable
|
|
93
|
+
* state, or at a field that is not a request map, yields nothing WITHOUT
|
|
94
|
+
* marking anything, so a genuine request whose ledger write has not
|
|
95
|
+
* indexed yet is retried next cycle.
|
|
71
96
|
*
|
|
72
|
-
* @returns The newly-authenticated requests this cycle.
|
|
73
|
-
* @throws Error
|
|
74
|
-
*
|
|
97
|
+
* @returns The newly-discovered authenticated requests this cycle.
|
|
98
|
+
* @throws Error when the event source itself fails (e.g. the indexer is
|
|
99
|
+
* unreachable).
|
|
75
100
|
*/
|
|
76
101
|
poll(): Promise<ResolvedSignetRequest[]>;
|
|
77
102
|
/**
|
|
78
103
|
* Re-arm `requestId` for redelivery on the next {@link poll} / {@link requests}
|
|
79
|
-
* cycle
|
|
104
|
+
* cycle: call when downstream processing of a yielded request failed, so it
|
|
80
105
|
* is retried (mirrors the MPC's delete-on-failure of its processed set).
|
|
81
106
|
*
|
|
82
107
|
* @param requestId - The request id to allow through again.
|
|
@@ -85,7 +110,7 @@ export declare class SignetRequestFeed {
|
|
|
85
110
|
/**
|
|
86
111
|
* Live stream: poll + sleep, yielding each authenticated request exactly once
|
|
87
112
|
* (subject to {@link forget}), until `opts.signal` aborts. The natural
|
|
88
|
-
* sequential `for await` consumption serializes downstream processing
|
|
113
|
+
* sequential `for await` consumption serializes downstream processing: no
|
|
89
114
|
* two requests are handed over concurrently.
|
|
90
115
|
*
|
|
91
116
|
* @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":"AAmBA,OAAO,EAIL,KAAK,iBAAiB,EACvB,MAAM,6BAA6B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AE,uBAAuB;IAW3C,qFAAqF;IACrF,OAAO,CAAC,OAAO;IAOf;;;;;;;;;OASG;YACW,oBAAoB;IAyClC;;;;;;;;;;;;OAYG;IACG,IAAI,IAAI,OAAO,CAAC,qBAAqB,EAAE,CAAC;IA+B9C;;;;;;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,24 @@
|
|
|
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 enumerate the AUTHENTICATED
|
|
4
|
+
// requests in that caller's own request map. A notification is a doorbell,
|
|
5
|
+
// never an authority: it says only WHERE to look (caller address + the
|
|
6
|
+
// resolved ledger-tree path of its request map), and every request served
|
|
7
|
+
// comes from the named caller's own ledger. An attacker cannot write into a
|
|
8
|
+
// contract it does not control, so a forged notification can at most
|
|
9
|
+
// re-point at a legitimate caller's map, never inject a request.
|
|
10
|
+
//
|
|
11
|
+
// The event log has no on-ledger cursor the feed consumes, so the feed's
|
|
12
|
+
// in-memory `yielded` set is the diff cursor: every poll enumerates the
|
|
13
|
+
// pointed-at maps and serves what it has not served before.
|
|
8
14
|
//
|
|
9
15
|
// The requester allow-list is an OPTIONAL policy filter here (drop requests
|
|
10
16
|
// 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";
|
|
17
|
+
// never the discovery mechanism: attribution comes from reading the
|
|
18
|
+
// caller's authenticated state.
|
|
19
|
+
import { decodeSignBidirectionalEventNotificationPayload, decodeSignBidirectionalNotification, SignetEventName, } from "./signet-contract-events.js";
|
|
20
|
+
import { readSignetRequestIndexAt } from "./signature-requests-state-reader.js";
|
|
21
|
+
import { stripHexPrefix, } from "./signet-requests.js";
|
|
17
22
|
/** Default gap between poll cycles of {@link SignetRequestFeed.requests}. */
|
|
18
23
|
export const DEFAULT_FEED_POLL_INTERVAL_MS = 3000;
|
|
19
24
|
/**
|
|
@@ -44,30 +49,31 @@ function normalizeAddress(address) {
|
|
|
44
49
|
return stripHexPrefix(address).toLowerCase();
|
|
45
50
|
}
|
|
46
51
|
/**
|
|
47
|
-
* The
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* lifetime, so a re-
|
|
52
|
-
* {@link forget} to re-arm a request whose downstream
|
|
52
|
+
* The event-polling request feed. Reads the signet contract's emitted
|
|
53
|
+
* notifications (discovery) and enumerates each pointed-at caller's own
|
|
54
|
+
* request map (authentication by construction: the records come from the
|
|
55
|
+
* caller's ledger), yielding each member request once. Dedupes by request id
|
|
56
|
+
* across its lifetime, so a re-notified or still-pending request is not
|
|
57
|
+
* re-yielded. Call {@link forget} to re-arm a request whose downstream
|
|
58
|
+
* processing failed.
|
|
53
59
|
*/
|
|
54
60
|
export class SignetRequestFeed {
|
|
55
61
|
signetContractAddress;
|
|
56
62
|
source;
|
|
57
|
-
|
|
63
|
+
eventSource;
|
|
58
64
|
allowContracts;
|
|
59
65
|
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.
|
|
66
|
+
// Request ids already yielded. NOT the security boundary (the caller-ledger
|
|
67
|
+
// read is), just an at-most-once gate so one request is not processed twice.
|
|
62
68
|
yielded = new Set();
|
|
63
69
|
/**
|
|
64
|
-
* @param config - The signet contract, state
|
|
65
|
-
* allow-list.
|
|
70
|
+
* @param config - The signet contract, state and event sources, and
|
|
71
|
+
* optional policy allow-list.
|
|
66
72
|
*/
|
|
67
73
|
constructor(config) {
|
|
68
74
|
this.signetContractAddress = config.signetContractAddress;
|
|
69
75
|
this.source = config.source;
|
|
70
|
-
this.
|
|
76
|
+
this.eventSource = config.eventSource;
|
|
71
77
|
this.allowContracts = config.allowContracts
|
|
72
78
|
? new Set(Array.from(config.allowContracts, normalizeAddress))
|
|
73
79
|
: undefined;
|
|
@@ -80,58 +86,85 @@ export class SignetRequestFeed {
|
|
|
80
86
|
this.allowContracts.has(normalizeAddress(callerAddress)));
|
|
81
87
|
}
|
|
82
88
|
/**
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
*
|
|
89
|
-
* being marked yielded, so a genuine request whose ledger write has not
|
|
90
|
-
* indexed yet is retried next cycle; undecodable or unsupported-version
|
|
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.
|
|
89
|
+
* The unique `(callerAddress, requestsPath)` pointers of the currently
|
|
90
|
+
* emitted notification events, allow-list applied, in ascending
|
|
91
|
+
* caller-address order (event enumeration order is per-source, so a
|
|
92
|
+
* stable sort keeps the poll deterministic). Undecodable or
|
|
93
|
+
* unsupported-version events are skipped (and logged): they carry no
|
|
94
|
+
* request, so nothing is lost.
|
|
97
95
|
*
|
|
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).
|
|
96
|
+
* @returns The deduplicated pointers to enumerate this cycle.
|
|
101
97
|
*/
|
|
102
|
-
async
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
const registry = readSignBidirectionalNotificationIndexFromState(state.data);
|
|
109
|
-
const out = [];
|
|
110
|
-
for (const [requestId, record] of [...registry.entries()].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))) {
|
|
98
|
+
async notificationPointers() {
|
|
99
|
+
const events = await this.eventSource.querySignetEvents(this.signetContractAddress);
|
|
100
|
+
const pointers = new Map();
|
|
101
|
+
for (const event of events) {
|
|
102
|
+
if (event.name !== SignetEventName.SignBidirectionalEvent)
|
|
103
|
+
continue;
|
|
111
104
|
let notification;
|
|
112
105
|
try {
|
|
113
|
-
notification = decodeSignBidirectionalNotification(
|
|
106
|
+
notification = decodeSignBidirectionalNotification(decodeSignBidirectionalEventNotificationPayload(event.payload));
|
|
114
107
|
}
|
|
115
108
|
catch (error) {
|
|
116
|
-
console.warn(`SignetRequestFeed: skipping undecodable notification `
|
|
117
|
-
`registered under ${requestId}: ${String(error)}`);
|
|
109
|
+
console.warn(`SignetRequestFeed: skipping undecodable notification event: ${String(error)}`);
|
|
118
110
|
continue;
|
|
119
111
|
}
|
|
120
|
-
if (this.yielded.has(requestId))
|
|
121
|
-
continue;
|
|
122
112
|
if (!this.allowed(notification.callerAddress))
|
|
123
113
|
continue;
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
114
|
+
pointers.set(`${notification.callerAddress}:${notification.requestsPath.join(",")}`, {
|
|
115
|
+
callerAddress: notification.callerAddress,
|
|
116
|
+
requestsPath: notification.requestsPath,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
return [...pointers.values()].sort((a, b) => a.callerAddress < b.callerAddress
|
|
120
|
+
? -1
|
|
121
|
+
: a.callerAddress > b.callerAddress
|
|
122
|
+
? 1
|
|
123
|
+
: 0);
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* One-shot: every request in a notified caller's request map that is
|
|
127
|
+
* admitted by the allow-list and not already yielded. Within one caller's
|
|
128
|
+
* map, requests are processed in ascending request-id-hex order: a
|
|
129
|
+
* stable, deterministic sequence. A pointer at a caller with no readable
|
|
130
|
+
* state, or at a field that is not a request map, yields nothing WITHOUT
|
|
131
|
+
* marking anything, so a genuine request whose ledger write has not
|
|
132
|
+
* indexed yet is retried next cycle.
|
|
133
|
+
*
|
|
134
|
+
* @returns The newly-discovered authenticated requests this cycle.
|
|
135
|
+
* @throws Error when the event source itself fails (e.g. the indexer is
|
|
136
|
+
* unreachable).
|
|
137
|
+
*/
|
|
138
|
+
async poll() {
|
|
139
|
+
const out = [];
|
|
140
|
+
for (const pointer of await this.notificationPointers()) {
|
|
141
|
+
let state;
|
|
142
|
+
try {
|
|
143
|
+
state = await this.source.queryContractState(pointer.callerAddress);
|
|
144
|
+
}
|
|
145
|
+
catch {
|
|
146
|
+
continue; // caller address not a contract / transient read error
|
|
147
|
+
}
|
|
148
|
+
if (!state?.data) {
|
|
149
|
+
continue; // no state at the named caller: nothing to serve yet
|
|
150
|
+
}
|
|
151
|
+
const index = readSignetRequestIndexAt(state.data, pointer.requestsPath);
|
|
152
|
+
for (const [requestId, request] of [...index.entries()].sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0))) {
|
|
153
|
+
if (this.yielded.has(requestId))
|
|
154
|
+
continue;
|
|
155
|
+
this.yielded.add(requestId);
|
|
156
|
+
out.push({
|
|
157
|
+
callerAddress: pointer.callerAddress,
|
|
158
|
+
requestId,
|
|
159
|
+
request,
|
|
160
|
+
});
|
|
161
|
+
}
|
|
129
162
|
}
|
|
130
163
|
return out;
|
|
131
164
|
}
|
|
132
165
|
/**
|
|
133
166
|
* Re-arm `requestId` for redelivery on the next {@link poll} / {@link requests}
|
|
134
|
-
* cycle
|
|
167
|
+
* cycle: call when downstream processing of a yielded request failed, so it
|
|
135
168
|
* is retried (mirrors the MPC's delete-on-failure of its processed set).
|
|
136
169
|
*
|
|
137
170
|
* @param requestId - The request id to allow through again.
|
|
@@ -142,7 +175,7 @@ export class SignetRequestFeed {
|
|
|
142
175
|
/**
|
|
143
176
|
* Live stream: poll + sleep, yielding each authenticated request exactly once
|
|
144
177
|
* (subject to {@link forget}), until `opts.signal` aborts. The natural
|
|
145
|
-
* sequential `for await` consumption serializes downstream processing
|
|
178
|
+
* sequential `for await` consumption serializes downstream processing: no
|
|
146
179
|
* two requests are handed over concurrently.
|
|
147
180
|
*
|
|
148
181
|
* @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,4EAA4E;AAC5E,2EAA2E;AAC3E,uEAAuE;AACvE,0EAA0E;AAC1E,4EAA4E;AAC5E,qEAAqE;AACrE,iEAAiE;AACjE,EAAE;AACF,yEAAyE;AACzE,wEAAwE;AACxE,4DAA4D;AAC5D,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,wBAAwB,EAAE,MAAM,sCAAsC,CAAC;AAEhF,OAAO,EACL,cAAc,GAGf,MAAM,sBAAsB,CAAC;AAE9B,6EAA6E;AAC7E,MAAM,CAAC,MAAM,6BAA6B,GAAG,IAAI,CAAC;AA2ClD;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAChC,EAAU,EACV,MAAoB;IAEpB,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;QAC7B,IAAI,MAAM,EAAE,OAAO;YAAE,OAAO,OAAO,EAAE,CAAC;QACtC,MAAM,KAAK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