@openzeppelin/guardian-client 0.18.3 → 0.19.0-rc.2
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 +127 -9
- package/dist/auth-request.d.ts +13 -0
- package/dist/auth-request.d.ts.map +1 -1
- package/dist/auth-request.js +26 -5
- package/dist/auth-request.js.map +1 -1
- package/dist/conversion.d.ts +8 -2
- package/dist/conversion.d.ts.map +1 -1
- package/dist/conversion.js +46 -3
- package/dist/conversion.js.map +1 -1
- package/dist/error-codes.d.ts +3 -5
- package/dist/error-codes.d.ts.map +1 -1
- package/dist/error-codes.js +23 -4
- package/dist/error-codes.js.map +1 -1
- package/dist/execution.d.ts +99 -0
- package/dist/execution.d.ts.map +1 -0
- package/dist/execution.js +124 -0
- package/dist/execution.js.map +1 -0
- package/dist/http.d.ts +81 -5
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +179 -27
- package/dist/http.js.map +1 -1
- package/dist/index.d.ts +8 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/request-envelope.d.ts +22 -0
- package/dist/request-envelope.d.ts.map +1 -0
- package/dist/request-envelope.js +51 -0
- package/dist/request-envelope.js.map +1 -0
- package/dist/server-types.d.ts +33 -0
- package/dist/server-types.d.ts.map +1 -1
- package/dist/session-request.d.ts +104 -0
- package/dist/session-request.d.ts.map +1 -0
- package/dist/session-request.js +164 -0
- package/dist/session-request.js.map +1 -0
- package/dist/types.d.ts +124 -5
- package/dist/types.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/auth-request.test.ts +12 -0
- package/src/auth-request.ts +37 -5
- package/src/conversion.test.ts +98 -0
- package/src/conversion.ts +59 -3
- package/src/dependencies.test.ts +25 -0
- package/src/error-codes.test.ts +14 -1
- package/src/error-codes.ts +23 -4
- package/src/execution.test.ts +145 -0
- package/src/execution.ts +206 -0
- package/src/http.test.ts +752 -19
- package/src/http.ts +244 -30
- package/src/index.ts +50 -1
- package/src/request-envelope.test.ts +30 -0
- package/src/request-envelope.ts +68 -0
- package/src/server-types.ts +35 -1
- package/src/session-request.test.ts +178 -0
- package/src/session-request.ts +191 -0
- package/src/types.ts +129 -4
package/dist/server-types.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { TransactionRequestEnvelope } from './request-envelope.js';
|
|
2
|
+
import type { ServerExecutionCapabilityWire } from './execution.js';
|
|
1
3
|
export interface ServerFalconSignature {
|
|
2
4
|
scheme: 'falcon';
|
|
3
5
|
signature: string;
|
|
@@ -40,6 +42,11 @@ export interface ServerProposalMetadata {
|
|
|
40
42
|
target_threshold?: number;
|
|
41
43
|
required_signatures?: number;
|
|
42
44
|
signer_commitments?: string[];
|
|
45
|
+
/**
|
|
46
|
+
* Target signer schemes (`"falcon"` / `"ecdsa"`), index-aligned with
|
|
47
|
+
* `signer_commitments` (issue #563). Proposer-supplied and stored as sent.
|
|
48
|
+
*/
|
|
49
|
+
signer_schemes?: string[];
|
|
43
50
|
target_procedure?: string;
|
|
44
51
|
salt?: string;
|
|
45
52
|
description?: string;
|
|
@@ -79,6 +86,7 @@ export interface ServerDeltaObject {
|
|
|
79
86
|
signature: ServerProposalSignature;
|
|
80
87
|
}>;
|
|
81
88
|
metadata?: ServerProposalMetadata;
|
|
89
|
+
transaction_request?: TransactionRequestEnvelope;
|
|
82
90
|
};
|
|
83
91
|
ack_sig?: string;
|
|
84
92
|
ack_pubkey?: string;
|
|
@@ -114,6 +122,16 @@ export interface ServerStateObject {
|
|
|
114
122
|
updated_at: string;
|
|
115
123
|
auth_scheme?: string;
|
|
116
124
|
}
|
|
125
|
+
export interface ServerQueuedCandidate {
|
|
126
|
+
nonce: number;
|
|
127
|
+
prev_commitment: string;
|
|
128
|
+
new_commitment: string;
|
|
129
|
+
}
|
|
130
|
+
export interface ServerStateTail {
|
|
131
|
+
state: ServerStateObject;
|
|
132
|
+
queue: ServerQueuedCandidate[];
|
|
133
|
+
accepts_submissions: boolean;
|
|
134
|
+
}
|
|
117
135
|
export interface ServerCanonicalNonceResponse {
|
|
118
136
|
account_id: string;
|
|
119
137
|
nonce: number;
|
|
@@ -127,6 +145,14 @@ export type ServerAuthConfig = {
|
|
|
127
145
|
MidenEcdsa: {
|
|
128
146
|
cosigner_commitments: string[];
|
|
129
147
|
};
|
|
148
|
+
} | {
|
|
149
|
+
Miden: {
|
|
150
|
+
cosigners: {
|
|
151
|
+
commitment: string;
|
|
152
|
+
scheme: 'falcon' | 'ecdsa';
|
|
153
|
+
}[];
|
|
154
|
+
guardian_scheme: 'falcon' | 'ecdsa';
|
|
155
|
+
};
|
|
130
156
|
};
|
|
131
157
|
export interface ServerConfigureRequest {
|
|
132
158
|
account_id: string;
|
|
@@ -154,6 +180,8 @@ export interface ServerDeltaProposalRequest {
|
|
|
154
180
|
signature: ServerProposalSignature;
|
|
155
181
|
}>;
|
|
156
182
|
metadata?: ServerProposalMetadata;
|
|
183
|
+
transaction_request?: TransactionRequestEnvelope;
|
|
184
|
+
base_commitment?: string;
|
|
157
185
|
};
|
|
158
186
|
}
|
|
159
187
|
export interface ServerDeltaProposalResponse {
|
|
@@ -166,12 +194,14 @@ export interface ServerProposalsResponse {
|
|
|
166
194
|
export interface ServerAbandonCandidateRequest {
|
|
167
195
|
account_id: string;
|
|
168
196
|
nonce: number;
|
|
197
|
+
proposal_id: string;
|
|
169
198
|
}
|
|
170
199
|
export interface ServerAbandonCandidateResponse {
|
|
171
200
|
account_id: string;
|
|
172
201
|
nonce: number;
|
|
173
202
|
state: 'pending' | 'abandoned' | 'retained';
|
|
174
203
|
abandon_requested_at?: string;
|
|
204
|
+
commitment: string;
|
|
175
205
|
}
|
|
176
206
|
export interface ServerSignProposalRequest {
|
|
177
207
|
account_id: string;
|
|
@@ -189,8 +219,10 @@ export interface ServerStatusResponse {
|
|
|
189
219
|
environment: string;
|
|
190
220
|
started_at: string;
|
|
191
221
|
uptime_seconds: number;
|
|
222
|
+
execution?: ServerExecutionCapabilityWire | null;
|
|
192
223
|
sessions?: {
|
|
193
224
|
max_ttl_seconds: number;
|
|
225
|
+
request_auth_version?: number;
|
|
194
226
|
};
|
|
195
227
|
}
|
|
196
228
|
export interface ServerCreateSessionRequest {
|
|
@@ -211,6 +243,7 @@ export interface ServerCreateSessionRequest {
|
|
|
211
243
|
export interface ServerCreateSessionResponse {
|
|
212
244
|
signer_commitment: string;
|
|
213
245
|
expires_at: string;
|
|
246
|
+
request_auth_version?: number;
|
|
214
247
|
}
|
|
215
248
|
export interface ServerRevokeSessionResponse {
|
|
216
249
|
revoked: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-types.d.ts","sourceRoot":"","sources":["../src/server-types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,qBAAqB;IACpC,MAAM,EAAE,QAAQ,CAAC;IACjB,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,oBAAoB;IACnC,MAAM,EAAE,OAAO,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,QAAQ,CAAC;CAC3B;AAED,MAAM,MAAM,uBAAuB,GAAG,qBAAqB,GAAG,oBAAoB,CAAC;AAEnF,MAAM,WAAW,uBAAuB;IACtC,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,uBAAuB,CAAC;IACnC,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,MAAM,iBAAiB,GACzB;IAAE,MAAM,EAAE,SAAS,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,WAAW,EAAE,MAAM,CAAC;IAAC,aAAa,EAAE,uBAAuB,EAAE,CAAA;CAAE,GACvG;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,GAC1C;IAAE,MAAM,EAAE,WAAW,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAA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AC;CAChD;AAED,MAAM,WAAW,iBAAiB;IAChC,KAAK,EAAE,kBAAkB,EAAE,CAAC;IAC5B,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B"}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Version 2 session request envelope (mirror of
|
|
3
|
+
* `crates/shared/src/session_request.rs`). A session key signs a fixed
|
|
4
|
+
* 62-byte envelope that binds the transport and the operation in addition to
|
|
5
|
+
* the account, timestamp and payload of the `AuthRequestMessage` word, so a
|
|
6
|
+
* request signed for one route is never accepted on another:
|
|
7
|
+
*
|
|
8
|
+
* `"GUARDIAN_SESSION_REQUEST" 0x00 || u16be(2) || u8(transport) ||
|
|
9
|
+
* u16be(operation) || request word (32 bytes)`
|
|
10
|
+
*
|
|
11
|
+
* P-256 signs these bytes with SHA-256: WebCrypto
|
|
12
|
+
* `sign({ name: 'ECDSA', hash: 'SHA-256' }, key, envelope)`.
|
|
13
|
+
*/
|
|
14
|
+
/** `x-auth-format` value of a version 2 session request. */
|
|
15
|
+
export declare const SESSION_REQUEST_AUTH_FORMAT = "session-v2";
|
|
16
|
+
/** The envelope version this client signs. */
|
|
17
|
+
export declare const SESSION_REQUEST_VERSION = 2;
|
|
18
|
+
/** Length of an encoded envelope. */
|
|
19
|
+
export declare const SESSION_REQUEST_ENVELOPE_LENGTH = 62;
|
|
20
|
+
/** How a request reaches Guardian. This client always uses HTTP. */
|
|
21
|
+
export declare const SessionTransport: {
|
|
22
|
+
readonly Http: 1;
|
|
23
|
+
readonly Grpc: 2;
|
|
24
|
+
};
|
|
25
|
+
export type SessionTransport = (typeof SessionTransport)[keyof typeof SessionTransport];
|
|
26
|
+
/** Every per-account operation a session may sign. Ids are permanent. */
|
|
27
|
+
export declare const SessionOperation: {
|
|
28
|
+
readonly GetState: 1;
|
|
29
|
+
readonly GetCanonicalNonce: 2;
|
|
30
|
+
readonly GetDelta: 3;
|
|
31
|
+
readonly GetDeltaSince: 4;
|
|
32
|
+
readonly GetDeltaHistory: 5;
|
|
33
|
+
readonly GetDeltaProposals: 6;
|
|
34
|
+
readonly GetDeltaProposal: 7;
|
|
35
|
+
readonly PushDelta: 8;
|
|
36
|
+
readonly PushDeltaProposal: 9;
|
|
37
|
+
readonly SignDeltaProposal: 10;
|
|
38
|
+
readonly ExecuteDeltaProposal: 11;
|
|
39
|
+
readonly GetDeltaProposalExecution: 12;
|
|
40
|
+
readonly GetCurrentExecution: 13;
|
|
41
|
+
readonly GetStateTail: 14;
|
|
42
|
+
};
|
|
43
|
+
export type SessionOperation = (typeof SessionOperation)[keyof typeof SessionOperation];
|
|
44
|
+
/** Whether Guardian checks `operation` under the strict write floor. */
|
|
45
|
+
export declare function isSessionWrite(operation: SessionOperation): boolean;
|
|
46
|
+
/** The bytes a session key signs for one per-account request. */
|
|
47
|
+
export declare function sessionRequestEnvelope(transport: SessionTransport, operation: SessionOperation, requestWord: Uint8Array): Uint8Array<ArrayBuffer>;
|
|
48
|
+
/**
|
|
49
|
+
* Guardian does not support the session request format this client signs.
|
|
50
|
+
* Terminal: the session is kept, nothing is retried and the wallet does not
|
|
51
|
+
* sign instead.
|
|
52
|
+
*/
|
|
53
|
+
export declare class UnsupportedAuthVersionError extends Error {
|
|
54
|
+
constructor(message: string);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Throws {@link UnsupportedAuthVersionError} unless a Guardian reports the
|
|
58
|
+
* session request version this client signs: such a server would refuse
|
|
59
|
+
* every session request.
|
|
60
|
+
*/
|
|
61
|
+
export declare function assertSupportedSessionPolicy(policy: {
|
|
62
|
+
requestAuthVersion?: number;
|
|
63
|
+
}): void;
|
|
64
|
+
/** How far a session request timestamp may run ahead of the local clock. */
|
|
65
|
+
export declare const SESSION_TIMESTAMP_MAX_AHEAD_MS = 1000;
|
|
66
|
+
/**
|
|
67
|
+
* A next timestamp this far ahead of the local clock means the clock stepped
|
|
68
|
+
* back, so minting restarts from the clock instead of waiting the step out.
|
|
69
|
+
*/
|
|
70
|
+
export declare const SESSION_CLOCK_STEP_BACK_MS = 5000;
|
|
71
|
+
/**
|
|
72
|
+
* After a replay rejection the next timestamp jumps to within this much below
|
|
73
|
+
* the ahead limit, at random, so it clears a floor an earlier page or tab of
|
|
74
|
+
* the same session left, and two of them stop colliding.
|
|
75
|
+
*/
|
|
76
|
+
export declare const SESSION_REPLAY_JUMP_SPREAD_MS = 200;
|
|
77
|
+
/**
|
|
78
|
+
* Strictly increasing request timestamps per account, shared by every client
|
|
79
|
+
* using one session, so two otherwise identical requests are never the same
|
|
80
|
+
* signed bytes. Accounts are independent: a burst on one does not push
|
|
81
|
+
* another's timestamps ahead of the clock.
|
|
82
|
+
*/
|
|
83
|
+
export declare class SessionTimestamps {
|
|
84
|
+
private readonly now;
|
|
85
|
+
private readonly last;
|
|
86
|
+
constructor(now?: () => number);
|
|
87
|
+
/**
|
|
88
|
+
* The next timestamp for `accountId`, waiting while it would run more than a
|
|
89
|
+
* second ahead. `afterReplay` jumps it near that limit first (see
|
|
90
|
+
* `SESSION_REPLAY_JUMP_SPREAD_MS`).
|
|
91
|
+
*/
|
|
92
|
+
next(accountId: string, afterReplay?: boolean): Promise<number>;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Runs a session's writes to one account one at a time, from minting the
|
|
96
|
+
* timestamp through the last replay retry, so they reach Guardian in
|
|
97
|
+
* timestamp order and never lose the strict write floor to each other. Writes
|
|
98
|
+
* to other accounts and all reads run freely.
|
|
99
|
+
*/
|
|
100
|
+
export declare class WriteSequencer {
|
|
101
|
+
private readonly tails;
|
|
102
|
+
run<T>(accountId: string, write: () => Promise<T>): Promise<T>;
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=session-request.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-request.d.ts","sourceRoot":"","sources":["../src/session-request.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,4DAA4D;AAC5D,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AAI,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,UAAQ,GAAG,OAAO,CAAC,MAAM,CAAC;CAuBpE;AAED;;;;;GAKG;AACH,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAuC;IAE7D,GAAG,CAAC,CAAC,EAAE,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;CAe/D"}
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Version 2 session request envelope (mirror of
|
|
3
|
+
* `crates/shared/src/session_request.rs`). A session key signs a fixed
|
|
4
|
+
* 62-byte envelope that binds the transport and the operation in addition to
|
|
5
|
+
* the account, timestamp and payload of the `AuthRequestMessage` word, so a
|
|
6
|
+
* request signed for one route is never accepted on another:
|
|
7
|
+
*
|
|
8
|
+
* `"GUARDIAN_SESSION_REQUEST" 0x00 || u16be(2) || u8(transport) ||
|
|
9
|
+
* u16be(operation) || request word (32 bytes)`
|
|
10
|
+
*
|
|
11
|
+
* P-256 signs these bytes with SHA-256: WebCrypto
|
|
12
|
+
* `sign({ name: 'ECDSA', hash: 'SHA-256' }, key, envelope)`.
|
|
13
|
+
*/
|
|
14
|
+
/** `x-auth-format` value of a version 2 session request. */
|
|
15
|
+
export const SESSION_REQUEST_AUTH_FORMAT = 'session-v2';
|
|
16
|
+
/** The envelope version this client signs. */
|
|
17
|
+
export const SESSION_REQUEST_VERSION = 2;
|
|
18
|
+
/** Length of an encoded envelope. */
|
|
19
|
+
export const SESSION_REQUEST_ENVELOPE_LENGTH = 62;
|
|
20
|
+
const DOMAIN = new TextEncoder().encode('GUARDIAN_SESSION_REQUEST\0');
|
|
21
|
+
/** How a request reaches Guardian. This client always uses HTTP. */
|
|
22
|
+
export const SessionTransport = {
|
|
23
|
+
Http: 1,
|
|
24
|
+
Grpc: 2,
|
|
25
|
+
};
|
|
26
|
+
/** Every per-account operation a session may sign. Ids are permanent. */
|
|
27
|
+
export const SessionOperation = {
|
|
28
|
+
GetState: 1,
|
|
29
|
+
GetCanonicalNonce: 2,
|
|
30
|
+
GetDelta: 3,
|
|
31
|
+
GetDeltaSince: 4,
|
|
32
|
+
GetDeltaHistory: 5,
|
|
33
|
+
GetDeltaProposals: 6,
|
|
34
|
+
GetDeltaProposal: 7,
|
|
35
|
+
PushDelta: 8,
|
|
36
|
+
PushDeltaProposal: 9,
|
|
37
|
+
SignDeltaProposal: 10,
|
|
38
|
+
ExecuteDeltaProposal: 11,
|
|
39
|
+
GetDeltaProposalExecution: 12,
|
|
40
|
+
GetCurrentExecution: 13,
|
|
41
|
+
GetStateTail: 14,
|
|
42
|
+
};
|
|
43
|
+
const WRITE_OPERATIONS = new Set([
|
|
44
|
+
SessionOperation.PushDelta,
|
|
45
|
+
SessionOperation.PushDeltaProposal,
|
|
46
|
+
SessionOperation.SignDeltaProposal,
|
|
47
|
+
SessionOperation.ExecuteDeltaProposal,
|
|
48
|
+
]);
|
|
49
|
+
/** Whether Guardian checks `operation` under the strict write floor. */
|
|
50
|
+
export function isSessionWrite(operation) {
|
|
51
|
+
return WRITE_OPERATIONS.has(operation);
|
|
52
|
+
}
|
|
53
|
+
/** The bytes a session key signs for one per-account request. */
|
|
54
|
+
export function sessionRequestEnvelope(transport, operation, requestWord) {
|
|
55
|
+
if (requestWord.length !== 32) {
|
|
56
|
+
throw new Error(`Request word must be 32 bytes, got ${requestWord.length}`);
|
|
57
|
+
}
|
|
58
|
+
const envelope = new Uint8Array(SESSION_REQUEST_ENVELOPE_LENGTH);
|
|
59
|
+
envelope.set(DOMAIN, 0);
|
|
60
|
+
envelope[25] = (SESSION_REQUEST_VERSION >> 8) & 0xff;
|
|
61
|
+
envelope[26] = SESSION_REQUEST_VERSION & 0xff;
|
|
62
|
+
envelope[27] = transport;
|
|
63
|
+
envelope[28] = (operation >> 8) & 0xff;
|
|
64
|
+
envelope[29] = operation & 0xff;
|
|
65
|
+
envelope.set(requestWord, 30);
|
|
66
|
+
return envelope;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Guardian does not support the session request format this client signs.
|
|
70
|
+
* Terminal: the session is kept, nothing is retried and the wallet does not
|
|
71
|
+
* sign instead.
|
|
72
|
+
*/
|
|
73
|
+
export class UnsupportedAuthVersionError extends Error {
|
|
74
|
+
constructor(message) {
|
|
75
|
+
super(message);
|
|
76
|
+
this.name = 'UnsupportedAuthVersionError';
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Throws {@link UnsupportedAuthVersionError} unless a Guardian reports the
|
|
81
|
+
* session request version this client signs: such a server would refuse
|
|
82
|
+
* every session request.
|
|
83
|
+
*/
|
|
84
|
+
export function assertSupportedSessionPolicy(policy) {
|
|
85
|
+
if (policy.requestAuthVersion !== SESSION_REQUEST_VERSION) {
|
|
86
|
+
throw new UnsupportedAuthVersionError(`Guardian reports session request version ${policy.requestAuthVersion ?? 'none'}, ` +
|
|
87
|
+
`this client signs version ${SESSION_REQUEST_VERSION}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/** How far a session request timestamp may run ahead of the local clock. */
|
|
91
|
+
export const SESSION_TIMESTAMP_MAX_AHEAD_MS = 1_000;
|
|
92
|
+
/**
|
|
93
|
+
* A next timestamp this far ahead of the local clock means the clock stepped
|
|
94
|
+
* back, so minting restarts from the clock instead of waiting the step out.
|
|
95
|
+
*/
|
|
96
|
+
export const SESSION_CLOCK_STEP_BACK_MS = 5_000;
|
|
97
|
+
/**
|
|
98
|
+
* After a replay rejection the next timestamp jumps to within this much below
|
|
99
|
+
* the ahead limit, at random, so it clears a floor an earlier page or tab of
|
|
100
|
+
* the same session left, and two of them stop colliding.
|
|
101
|
+
*/
|
|
102
|
+
export const SESSION_REPLAY_JUMP_SPREAD_MS = 200;
|
|
103
|
+
/**
|
|
104
|
+
* Strictly increasing request timestamps per account, shared by every client
|
|
105
|
+
* using one session, so two otherwise identical requests are never the same
|
|
106
|
+
* signed bytes. Accounts are independent: a burst on one does not push
|
|
107
|
+
* another's timestamps ahead of the clock.
|
|
108
|
+
*/
|
|
109
|
+
export class SessionTimestamps {
|
|
110
|
+
now;
|
|
111
|
+
last = new Map();
|
|
112
|
+
constructor(now = Date.now) {
|
|
113
|
+
this.now = now;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* The next timestamp for `accountId`, waiting while it would run more than a
|
|
117
|
+
* second ahead. `afterReplay` jumps it near that limit first (see
|
|
118
|
+
* `SESSION_REPLAY_JUMP_SPREAD_MS`).
|
|
119
|
+
*/
|
|
120
|
+
async next(accountId, afterReplay = false) {
|
|
121
|
+
if (afterReplay) {
|
|
122
|
+
const jump = this.now() +
|
|
123
|
+
SESSION_TIMESTAMP_MAX_AHEAD_MS -
|
|
124
|
+
Math.floor(Math.random() * SESSION_REPLAY_JUMP_SPREAD_MS);
|
|
125
|
+
this.last.set(accountId, Math.max(this.last.get(accountId) ?? -Infinity, jump - 1));
|
|
126
|
+
}
|
|
127
|
+
for (;;) {
|
|
128
|
+
const now = this.now();
|
|
129
|
+
let last = this.last.get(accountId) ?? -Infinity;
|
|
130
|
+
if (last - now > SESSION_CLOCK_STEP_BACK_MS) {
|
|
131
|
+
last = now - 1;
|
|
132
|
+
}
|
|
133
|
+
const next = Math.max(now, last + 1);
|
|
134
|
+
const ahead = next - now;
|
|
135
|
+
if (ahead <= SESSION_TIMESTAMP_MAX_AHEAD_MS) {
|
|
136
|
+
this.last.set(accountId, next);
|
|
137
|
+
return next;
|
|
138
|
+
}
|
|
139
|
+
await new Promise((resolve) => setTimeout(resolve, ahead - SESSION_TIMESTAMP_MAX_AHEAD_MS));
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Runs a session's writes to one account one at a time, from minting the
|
|
145
|
+
* timestamp through the last replay retry, so they reach Guardian in
|
|
146
|
+
* timestamp order and never lose the strict write floor to each other. Writes
|
|
147
|
+
* to other accounts and all reads run freely.
|
|
148
|
+
*/
|
|
149
|
+
export class WriteSequencer {
|
|
150
|
+
tails = new Map();
|
|
151
|
+
run(accountId, write) {
|
|
152
|
+
const previous = this.tails.get(accountId) ?? Promise.resolve();
|
|
153
|
+
const result = previous.then(write);
|
|
154
|
+
const tail = result.then(() => undefined, () => undefined);
|
|
155
|
+
this.tails.set(accountId, tail);
|
|
156
|
+
void tail.then(() => {
|
|
157
|
+
if (this.tails.get(accountId) === tail) {
|
|
158
|
+
this.tails.delete(accountId);
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
return result;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
//# sourceMappingURL=session-request.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"session-request.js","sourceRoot":"","sources":["../src/session-request.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,4DAA4D;AAC5D,MAAM,CAAC,MAAM,2BAA2B,GAAG,YAAY,CAAC;AAExD,8CAA8C;AAC9C,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,CAAC;AAEzC,qCAAqC;AACrC,MAAM,CAAC,MAAM,+BAA+B,GAAG,EAAE,CAAC;AAElD,MAAM,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,4BAA4B,CAAC,CAAC;AAEtE,oEAAoE;AACpE,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,IAAI,EAAE,CAAC;IACP,IAAI,EAAE,CAAC;CACC,CAAC;AAGX,yEAAyE;AACzE,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,QAAQ,EAAE,CAAC;IACX,iBAAiB,EAAE,CAAC;IACpB,QAAQ,EAAE,CAAC;IACX,aAAa,EAAE,CAAC;IAChB,eAAe,EAAE,CAAC;IAClB,iBAAiB,EAAE,CAAC;IACpB,gBAAgB,EAAE,CAAC;IACnB,SAAS,EAAE,CAAC;IACZ,iBAA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IAAI,CAAC,CAAC;QAChC,KAAK,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE;YAClB,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,SAAS,CAAC,KAAK,IAAI,EAAE,CAAC;gBACvC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;YAC/B,CAAC;QACH,CAAC,CAAC,CAAC;QACH,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import type { SessionOperation, WriteSequencer } from './session-request.js';
|
|
2
|
+
import type { TransactionRequestEnvelope } from './request-envelope.js';
|
|
1
3
|
import type { RequestAuthPayload } from './auth-request.js';
|
|
4
|
+
import type { ServerExecutionCapability } from './execution.js';
|
|
2
5
|
export interface Signer {
|
|
3
6
|
readonly commitment: string;
|
|
4
7
|
readonly publicKey: string;
|
|
@@ -75,7 +78,7 @@ export interface SessionGrantFields {
|
|
|
75
78
|
export type SessionEndReason = 'logout' | 'expired' | 'revoked' | 'rejected';
|
|
76
79
|
/**
|
|
77
80
|
* Signs session-eligible requests on behalf of a wallet after a session grant
|
|
78
|
-
* was registered. Requests carry `x-auth-format: session`.
|
|
81
|
+
* was registered. Requests carry `x-auth-format: session-v2`.
|
|
79
82
|
*/
|
|
80
83
|
export interface SessionRequestSigner {
|
|
81
84
|
/** Hex SEC1-compressed P-256 session public key, sent as `x-pubkey`. */
|
|
@@ -87,7 +90,20 @@ export interface SessionRequestSigner {
|
|
|
87
90
|
readonly signerCommitment: string;
|
|
88
91
|
/** Unix seconds. */
|
|
89
92
|
readonly expiresAt: number;
|
|
90
|
-
|
|
93
|
+
/**
|
|
94
|
+
* The next request timestamp (Unix ms) for `accountId`: strictly increasing
|
|
95
|
+
* per account for this session, never more than a second ahead of the
|
|
96
|
+
* clock, and jumped near that limit when `afterReplay` (see
|
|
97
|
+
* `SessionTimestamps`).
|
|
98
|
+
*/
|
|
99
|
+
nextTimestamp(accountId: string, afterReplay: boolean): Promise<number>;
|
|
100
|
+
/** Orders this session's writes per account; shared by every client using it. */
|
|
101
|
+
readonly writeSequencer: WriteSequencer;
|
|
102
|
+
/**
|
|
103
|
+
* Sign the version 2 envelope (see `sessionRequestEnvelope`) of this
|
|
104
|
+
* request over HTTP as `operation`.
|
|
105
|
+
*/
|
|
106
|
+
signRequest(operation: SessionOperation, accountId: string, timestamp: number, requestPayload: RequestAuthPayload): Promise<string> | string;
|
|
91
107
|
/** Sign the account-less `SessionLogoutMessage` for `POST /session/logout`. */
|
|
92
108
|
signLogout(timestampMs: number): Promise<string> | string;
|
|
93
109
|
/** Called once when the client stops using the session. */
|
|
@@ -102,13 +118,23 @@ export interface CreateSessionRequest {
|
|
|
102
118
|
signature: string;
|
|
103
119
|
grant: SessionGrantFields;
|
|
104
120
|
}
|
|
105
|
-
|
|
121
|
+
/** How a Guardian expects session requests to be signed. */
|
|
122
|
+
export interface SessionRequestPolicy {
|
|
123
|
+
/**
|
|
124
|
+
* The session request envelope version; this client signs 2, under which
|
|
125
|
+
* each signed session read is admitted once, within 60 s of server time,
|
|
126
|
+
* except the canonical nonce poll, accepted every time within 60 s behind
|
|
127
|
+
* and 30 s ahead.
|
|
128
|
+
*/
|
|
129
|
+
requestAuthVersion: number;
|
|
130
|
+
}
|
|
131
|
+
export interface CreateSessionResponse extends SessionRequestPolicy {
|
|
106
132
|
signerCommitment: string;
|
|
107
133
|
/** RFC 3339 UTC. */
|
|
108
134
|
expiresAt: string;
|
|
109
135
|
}
|
|
110
136
|
/** Session parameters a Guardian advertises on `GET /status`. */
|
|
111
|
-
export interface SessionsStatus {
|
|
137
|
+
export interface SessionsStatus extends Partial<SessionRequestPolicy> {
|
|
112
138
|
/** Grants may expire at most this many seconds after registration. */
|
|
113
139
|
maxTtlSeconds: number;
|
|
114
140
|
}
|
|
@@ -124,6 +150,11 @@ export interface EcdsaSignature {
|
|
|
124
150
|
}
|
|
125
151
|
export type ProposalSignature = FalconSignature | EcdsaSignature;
|
|
126
152
|
export type SignatureScheme = 'falcon' | 'ecdsa';
|
|
153
|
+
/** One cosigner of a {@link AuthConfig} `Miden` auth and the scheme Guardian verifies its signatures under. */
|
|
154
|
+
export interface MidenCosignerConfig {
|
|
155
|
+
commitment: string;
|
|
156
|
+
scheme: SignatureScheme;
|
|
157
|
+
}
|
|
127
158
|
export type AuthConfig = {
|
|
128
159
|
MidenFalconRpo: {
|
|
129
160
|
cosigner_commitments: string[];
|
|
@@ -132,6 +163,18 @@ export type AuthConfig = {
|
|
|
132
163
|
MidenEcdsa: {
|
|
133
164
|
cosigner_commitments: string[];
|
|
134
165
|
};
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Cosigners that each carry their own scheme, and the GUARDIAN's scheme
|
|
169
|
+
* (issue #563). Send it only for an account whose cosigners and GUARDIAN
|
|
170
|
+
* do not all share one scheme; servers before #563 reject it, and the
|
|
171
|
+
* single-scheme variants keep serving the accounts that do.
|
|
172
|
+
*/
|
|
173
|
+
| {
|
|
174
|
+
Miden: {
|
|
175
|
+
cosigners: MidenCosignerConfig[];
|
|
176
|
+
guardian_scheme: SignatureScheme;
|
|
177
|
+
};
|
|
135
178
|
};
|
|
136
179
|
export interface CosignerSignature {
|
|
137
180
|
signerId: string;
|
|
@@ -171,6 +214,15 @@ export interface ProposalMetadata {
|
|
|
171
214
|
targetThreshold?: number;
|
|
172
215
|
requiredSignatures?: number;
|
|
173
216
|
signerCommitments?: string[];
|
|
217
|
+
/**
|
|
218
|
+
* Target signer schemes (`"falcon"` / `"ecdsa"`), index-aligned with
|
|
219
|
+
* `signerCommitments`, for an update-signers proposal whose signers do not
|
|
220
|
+
* all share one scheme (issue #563). Absent => every target signer keeps the
|
|
221
|
+
* proposer's scheme. GUARDIAN stores the proposer's values as sent, so a
|
|
222
|
+
* consumer validates them, as it validates the rest of the metadata against
|
|
223
|
+
* the transaction summary, before relying on them.
|
|
224
|
+
*/
|
|
225
|
+
signerSchemes?: string[];
|
|
174
226
|
targetProcedure?: string;
|
|
175
227
|
salt?: string;
|
|
176
228
|
description?: string;
|
|
@@ -214,6 +266,8 @@ export interface DeltaObject {
|
|
|
214
266
|
signature: ProposalSignature;
|
|
215
267
|
}>;
|
|
216
268
|
metadata?: ProposalMetadata;
|
|
269
|
+
/** The request a Guardian-executable proposal stores. Absent on a self-executed one. */
|
|
270
|
+
transactionRequest?: TransactionRequestEnvelope;
|
|
217
271
|
};
|
|
218
272
|
ackSig?: string;
|
|
219
273
|
ackPubkey?: string;
|
|
@@ -239,8 +293,48 @@ export interface StateObject {
|
|
|
239
293
|
};
|
|
240
294
|
createdAt: string;
|
|
241
295
|
updatedAt: string;
|
|
296
|
+
/** `falcon` or `ecdsa` when the account's cosigners and GUARDIAN share that scheme, `mixed` when they do not. */
|
|
242
297
|
authScheme?: string;
|
|
243
298
|
}
|
|
299
|
+
/** A queued candidate the queue tail replays (`GET /state/tail`). */
|
|
300
|
+
export interface QueuedCandidate {
|
|
301
|
+
/** The account nonce the candidate's transaction leaves the account at. */
|
|
302
|
+
nonce: number;
|
|
303
|
+
/** The state it builds on: the canonical state for the oldest, the previous candidate's `newCommitment` after it. */
|
|
304
|
+
prevCommitment: string;
|
|
305
|
+
/** The state it leaves the account at. */
|
|
306
|
+
newCommitment: string;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* The queue tail (`GET /state/tail`, issue #517): the state a new delta or
|
|
310
|
+
* proposal must build on while the account's candidate queue holds
|
|
311
|
+
* candidates, and the candidates that lead to it.
|
|
312
|
+
*/
|
|
313
|
+
export interface StateTail {
|
|
314
|
+
/**
|
|
315
|
+
* The canonical state with every queued candidate applied, shaped as
|
|
316
|
+
* `getState` returns a state; the canonical state itself when nothing is
|
|
317
|
+
* queued. Not on chain until the queued candidates land.
|
|
318
|
+
*/
|
|
319
|
+
state: StateObject;
|
|
320
|
+
/**
|
|
321
|
+
* The queued candidates, oldest first: the first builds on the canonical
|
|
322
|
+
* state, each later one on the one before it, and the last one's
|
|
323
|
+
* `newCommitment` is the tail's commitment. Empty when nothing is queued.
|
|
324
|
+
*/
|
|
325
|
+
queue: QueuedCandidate[];
|
|
326
|
+
/**
|
|
327
|
+
* Whether the queue takes a delta or proposal built on this tail now.
|
|
328
|
+
* False while the queue is full (at the default depth of 1, whenever
|
|
329
|
+
* anything is queued), while the tail changes the account's signers or
|
|
330
|
+
* guardian key, or while its newest candidate was queued by a server before
|
|
331
|
+
* 0.19.0 under a label other than its nonce: a submission on the tail then
|
|
332
|
+
* gets `conflict_pending_delta`, so wait for the queue to drain and read
|
|
333
|
+
* again. True holds only at this read: the tail can move before the push,
|
|
334
|
+
* and the account's status and the proposal limits still apply.
|
|
335
|
+
*/
|
|
336
|
+
acceptsSubmissions: boolean;
|
|
337
|
+
}
|
|
244
338
|
/**
|
|
245
339
|
* Head of the latest canonical state (`GET /state/nonce`): the account
|
|
246
340
|
* nonce carried by the state GUARDIAN holds as canonical and that state's
|
|
@@ -279,6 +373,11 @@ export interface StatusResponse {
|
|
|
279
373
|
environment: string;
|
|
280
374
|
startedAt: string;
|
|
281
375
|
uptimeSeconds: number;
|
|
376
|
+
/**
|
|
377
|
+
* Whether the server accepts Guardian execution requests. Absent on a Guardian that predates
|
|
378
|
+
* Guardian execution: it does not offer it.
|
|
379
|
+
*/
|
|
380
|
+
execution?: ServerExecutionCapability;
|
|
282
381
|
/** Present on every Guardian that accepts session grants; absent on older servers. */
|
|
283
382
|
sessions?: SessionsStatus;
|
|
284
383
|
}
|
|
@@ -294,6 +393,17 @@ export interface DeltaProposalRequest {
|
|
|
294
393
|
signature: ProposalSignature;
|
|
295
394
|
}>;
|
|
296
395
|
metadata?: ProposalMetadata;
|
|
396
|
+
/** The request a Guardian-executable proposal stores. Omit for a self-executed one. */
|
|
397
|
+
transactionRequest?: TransactionRequestEnvelope;
|
|
398
|
+
/**
|
|
399
|
+
* Commitment of the state the summary was built on (issue #517). GUARDIAN
|
|
400
|
+
* 0.19.0 and later record the proposal only when it is the queue tail,
|
|
401
|
+
* refusing a base another queued candidate claimed with
|
|
402
|
+
* `conflict_pending_delta` and an unknown one with `commitment_mismatch`.
|
|
403
|
+
* Omit it to be judged by the nonce alone; earlier servers store it with
|
|
404
|
+
* the payload and ignore it.
|
|
405
|
+
*/
|
|
406
|
+
baseCommitment?: string;
|
|
297
407
|
};
|
|
298
408
|
}
|
|
299
409
|
export interface DeltaProposalResponse {
|
|
@@ -326,12 +436,21 @@ export interface AbandonCandidateResponse {
|
|
|
326
436
|
* return the original timestamp; absent once resolved.
|
|
327
437
|
*/
|
|
328
438
|
abandonRequestedAt?: string;
|
|
439
|
+
/**
|
|
440
|
+
* The abandoned delta's `new_commitment`. Another delta can later take
|
|
441
|
+
* the same nonce (a Guardian execution archives the abandoned one), so
|
|
442
|
+
* pass this to `abandonStatus` to poll for this delta.
|
|
443
|
+
*/
|
|
444
|
+
commitment: string;
|
|
329
445
|
}
|
|
330
446
|
/**
|
|
331
447
|
* Resolution of an abandon request, as observed via the delta feed.
|
|
332
448
|
* `'retained'` means the account slot is released but the on-chain
|
|
333
449
|
* outcome is still uncertain — "unlocked but unresolved", never to be
|
|
334
|
-
* read as "the transaction did not land".
|
|
450
|
+
* read as "the transaction did not land". When another delta has taken
|
|
451
|
+
* the nonce, `'abandoned'` means it is canonical (the abandoned
|
|
452
|
+
* transaction can no longer land) and `'waiting'` that it is still a
|
|
453
|
+
* candidate.
|
|
335
454
|
*/
|
|
336
455
|
export type AbandonStatus = 'waiting' | 'landed' | 'abandoned' | 'retained' | 'unexpected';
|
|
337
456
|
export interface PushDeltaResponse {
|