@openzeppelin/guardian-client 0.18.0 → 0.18.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 +46 -2
- package/dist/conversion.d.ts +4 -2
- package/dist/conversion.d.ts.map +1 -1
- package/dist/conversion.js +22 -0
- package/dist/conversion.js.map +1 -1
- package/dist/error-codes.d.ts +1 -1
- package/dist/error-codes.d.ts.map +1 -1
- package/dist/error-codes.js +3 -0
- package/dist/error-codes.js.map +1 -1
- package/dist/http.d.ts +41 -1
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +170 -26
- package/dist/http.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/server-types.d.ts +35 -2
- package/dist/server-types.d.ts.map +1 -1
- package/dist/types.d.ts +104 -9
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/conversion.test.ts +33 -1
- package/src/conversion.ts +30 -0
- package/src/error-codes.ts +3 -0
- package/src/http.test.ts +461 -1
- package/src/http.ts +211 -25
- package/src/index.ts +6 -0
- package/src/server-types.ts +40 -2
- package/src/types.ts +123 -9
package/README.md
CHANGED
|
@@ -47,6 +47,45 @@ const signer: Signer = {
|
|
|
47
47
|
client.setSigner(signer);
|
|
48
48
|
```
|
|
49
49
|
|
|
50
|
+
### Sessions
|
|
51
|
+
|
|
52
|
+
When the Guardian advertises `sessions` on `getStatus()`, a wallet can sign one
|
|
53
|
+
session grant and let a delegated signer (a P-256 key) sign the
|
|
54
|
+
session-eligible requests. `@openzeppelin/miden-multisig-client` builds and
|
|
55
|
+
signs the grant (`startGuardianSession`); this client only routes requests:
|
|
56
|
+
|
|
57
|
+
```typescript
|
|
58
|
+
client.setSession(session); // a SessionRequestSigner
|
|
59
|
+
await client.getState(accountId); // signed by the delegated signer
|
|
60
|
+
|
|
61
|
+
await client.revokeSession(); // session-key-signed logout; back to the wallet
|
|
62
|
+
await client.revokeAllSessions(); // wallet-signed: ends every session of the signer
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
The delegated signer signs reads (`getState`, `getCanonicalNonce`, `getDelta`,
|
|
66
|
+
`getDeltaSince`, `getDeltaHistory`), proposal reads and proposal create/sign
|
|
67
|
+
(`getDeltaProposals`, `getDeltaProposal`, `pushDeltaProposal`,
|
|
68
|
+
`signDeltaProposal`). Every other route uses the wallet signer, including
|
|
69
|
+
`configure`, `pushDelta`, `abandonCandidate`, account lookup and
|
|
70
|
+
`revokeAllSessions`; the server rejects session credentials there with
|
|
71
|
+
`wallet_signature_required`.
|
|
72
|
+
|
|
73
|
+
A session is used only while the wallet that granted it
|
|
74
|
+
(`session.signerCommitment`) is the client's signer. It is dropped 30 seconds
|
|
75
|
+
before it expires (`expired`), or as soon as Guardian answers
|
|
76
|
+
`session_expired`, `session_revoked` or `authentication_failed` to a request
|
|
77
|
+
it signed (`expired`, `revoked`, `rejected`); requests then fall back to the
|
|
78
|
+
wallet and `session.onEnded(reason)` is called once, so the app can start a
|
|
79
|
+
new session. `authorization_failed` (the wallet does not cosign that account)
|
|
80
|
+
keeps the session. Logout and revoke-all drop the session only after Guardian
|
|
81
|
+
confirms, with the reason `logout`: the app ended it itself.
|
|
82
|
+
|
|
83
|
+
Revoke-all ends sessions already registered with Guardian. A page that got a
|
|
84
|
+
grant signed can still register it for up to about 10 minutes afterwards, and
|
|
85
|
+
a revoking device whose clock runs behind can miss sessions started just
|
|
86
|
+
before it. When a session key may be compromised, run `revokeAllSessions`
|
|
87
|
+
again 10 minutes later.
|
|
88
|
+
|
|
50
89
|
### Configure an Account
|
|
51
90
|
|
|
52
91
|
```typescript
|
|
@@ -91,8 +130,13 @@ if (!inSync) {
|
|
|
91
130
|
### Abandon a Stuck Candidate
|
|
92
131
|
|
|
93
132
|
If an approved transaction died client-side after guardian approval, its
|
|
94
|
-
candidate keeps the account locked
|
|
95
|
-
|
|
133
|
+
candidate keeps the account locked: new proposals and deltas answer
|
|
134
|
+
`409 conflict_pending_delta` while the account's candidate queue (one
|
|
135
|
+
candidate by default) is full, when they build on the state that candidate
|
|
136
|
+
already claimed, or when their nonce does not extend the queue (a proposal's
|
|
137
|
+
must be the newest queued candidate's plus one), and any candidate queued
|
|
138
|
+
behind it can never land. Record an
|
|
139
|
+
abandon intent and poll for the resolution:
|
|
96
140
|
|
|
97
141
|
```typescript
|
|
98
142
|
const accepted = await client.abandonCandidate(accountId, nonce);
|
package/dist/conversion.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { CanonicalNonce, CosignerSignature, ConfigureRequest, ConfigureResponse, DeltaObject, DeltaProposalRequest, DeltaStatus, ExecutionDelta, HistoryEntry, HistoryPage, LookupResponse, ProposalSignature, ProposalMetadata, SignProposalRequest, StateObject } from './types.js';
|
|
2
|
-
import type { ServerCanonicalNonceResponse, ServerCosignerSignature, ServerConfigureRequest, ServerConfigureResponse, ServerDeltaObject, ServerDeltaProposalRequest, ServerDeltaStatus, ServerExecutionDelta, ServerHistoryEntry, ServerHistoryPage, ServerLookupResponse, ServerProposalSignature, ServerProposalMetadata, ServerSignProposalRequest, ServerStateObject } from './server-types.js';
|
|
1
|
+
import type { CanonicalNonce, CosignerSignature, ConfigureRequest, ConfigureResponse, CreateSessionRequest, CreateSessionResponse, DeltaObject, DeltaProposalRequest, DeltaStatus, ExecutionDelta, HistoryEntry, HistoryPage, LookupResponse, ProposalSignature, ProposalMetadata, SignProposalRequest, StateObject } from './types.js';
|
|
2
|
+
import type { ServerCanonicalNonceResponse, ServerCosignerSignature, ServerConfigureRequest, ServerConfigureResponse, ServerCreateSessionRequest, ServerCreateSessionResponse, ServerDeltaObject, ServerDeltaProposalRequest, ServerDeltaStatus, ServerExecutionDelta, ServerHistoryEntry, ServerHistoryPage, ServerLookupResponse, ServerProposalSignature, ServerProposalMetadata, ServerSignProposalRequest, ServerStateObject } from './server-types.js';
|
|
3
3
|
export declare function fromServerSignature(signature: ServerProposalSignature): ProposalSignature;
|
|
4
4
|
export declare function fromServerCosignerSignature(server: ServerCosignerSignature): CosignerSignature;
|
|
5
5
|
export declare function fromServerDeltaStatus(server: ServerDeltaStatus): DeltaStatus;
|
|
@@ -14,6 +14,8 @@ export declare function toServerCosignerSignature(sig: CosignerSignature): Serve
|
|
|
14
14
|
export declare function toServerDeltaStatus(status: DeltaStatus): ServerDeltaStatus;
|
|
15
15
|
export declare function toServerProposalMetadata(meta: ProposalMetadata): ServerProposalMetadata;
|
|
16
16
|
export declare function toServerConfigureRequest(req: ConfigureRequest): ServerConfigureRequest;
|
|
17
|
+
export declare function toServerCreateSessionRequest(req: CreateSessionRequest): ServerCreateSessionRequest;
|
|
18
|
+
export declare function fromServerCreateSessionResponse(server: ServerCreateSessionResponse): CreateSessionResponse;
|
|
17
19
|
export declare function toServerDeltaProposalRequest(req: DeltaProposalRequest): ServerDeltaProposalRequest;
|
|
18
20
|
export declare function toServerSignProposalRequest(req: SignProposalRequest): ServerSignProposalRequest;
|
|
19
21
|
export declare function toServerExecutionDelta(delta: ExecutionDelta): ServerExecutionDelta;
|
package/dist/conversion.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversion.d.ts","sourceRoot":"","sources":["../src/conversion.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,EACX,oBAAoB,EACpB,WAAW,EACX,cAAc,EACd,YAAY,EAEZ,WAAW,EACX,cAAc,EACd,iBAAiB,EACjB,gBAAgB,EAChB,mBAAmB,EACnB,WAAW,EACZ,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EACV,4BAA4B,EAC5B,uBAAuB,EACvB,sBAAsB,EACtB,uBAAuB,EACvB,iBAAiB,EACjB,0BAA0B,EAC1B,iBAAiB,EACjB,oBAAoB,EACpB,kBAAkB,EAElB,iBAAiB,EACjB,oBAAoB,EACpB,uBAAuB,EACvB,sBAAsB,EACtB,yBAAy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alMetadata(server) {
|
|
|
60
60
|
amount: server.amount,
|
|
61
61
|
noteType: server.note_type,
|
|
62
62
|
chainAnchor: server.chain_anchor,
|
|
63
|
+
boundBlockNum: server.bound_block_num,
|
|
63
64
|
reclaimHeight: server.reclaim_height,
|
|
64
65
|
timelockHeight: server.timelock_height,
|
|
65
66
|
};
|
|
@@ -177,6 +178,7 @@ export function toServerProposalMetadata(meta) {
|
|
|
177
178
|
amount: meta.amount,
|
|
178
179
|
note_type: meta.noteType,
|
|
179
180
|
chain_anchor: meta.chainAnchor,
|
|
181
|
+
bound_block_num: meta.boundBlockNum,
|
|
180
182
|
reclaim_height: meta.reclaimHeight,
|
|
181
183
|
timelock_height: meta.timelockHeight,
|
|
182
184
|
};
|
|
@@ -188,6 +190,26 @@ export function toServerConfigureRequest(req) {
|
|
|
188
190
|
initial_state: { data: req.initialState.data, account_id: req.initialState.accountId },
|
|
189
191
|
};
|
|
190
192
|
}
|
|
193
|
+
export function toServerCreateSessionRequest(req) {
|
|
194
|
+
return {
|
|
195
|
+
scheme: req.scheme,
|
|
196
|
+
...(req.authFormat ? { auth_format: req.authFormat } : {}),
|
|
197
|
+
...(req.publicKey ? { public_key: req.publicKey } : {}),
|
|
198
|
+
signature: req.signature,
|
|
199
|
+
grant: {
|
|
200
|
+
signer_commitment: req.grant.signerCommitment,
|
|
201
|
+
session_public_key: req.grant.sessionPublicKey,
|
|
202
|
+
origin: req.grant.origin,
|
|
203
|
+
issued_at: req.grant.issuedAt,
|
|
204
|
+
expires_at: req.grant.expiresAt,
|
|
205
|
+
guardian_commitment: req.grant.guardianCommitment,
|
|
206
|
+
network: req.grant.network,
|
|
207
|
+
},
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
export function fromServerCreateSessionResponse(server) {
|
|
211
|
+
return { signerCommitment: server.signer_commitment, expiresAt: server.expires_at };
|
|
212
|
+
}
|
|
191
213
|
export function toServerDeltaProposalRequest(req) {
|
|
192
214
|
return {
|
|
193
215
|
account_id: req.accountId,
|
package/dist/conversion.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversion.js","sourceRoot":"","sources":["../src/conversion.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"conversion.js","sourceRoot":"","sources":["../src/conversion.ts"],"names":[],"mappings":"AAuDA,SAAS,mBAAmB,CAAC,OAA2B;IAKtD,MAAM,SAAS,GAAG,YAAY,IAAI,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC;IACxF,MAAM,UAAU,GAAG,YAAY,IAAI,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,EAAE,CAAC;IAC1G,MAAM,QAAQ,GAAG,UAAU,IAAI,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;IACtE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,CAAC;AAC7C,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,SAAkC;IACpE,IAAI,SAAS,CAAC,MAAM,KAAK,OAAO,EAAE,CAAC;QACjC,OAAO;YACL,MAAM,EAAE,OAAO;YACf,SAAS,EAAE,SAAS,CAAC,SAAS;YAC9B,SAAS,EAAE,SAAS,CAAC,UAAU;YAC/B,GAAG,CAAC,SAAS,CAAC,cAAc,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,SAAS,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;SACjF,CAAC;IACJ,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,MAAM,UAAU,2BAA2B,CAAC,MAA+B;IACzE,OAAO;QACL,QAAQ,EAAE,MAAM,CAAC,SAAS;QAC1B,SAAS,EAAE,mBAAmB,CAA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K,EAAE,EAAE,CAAC,CAAC;YACpC,OAAO,EAAE,KAAK,CAAC,QAAQ;YACvB,IAAI,EAAE,KAAK,CAAC,IAAI;YAChB,MAAM,EAAE,KAAK,CAAC,MAAM;SACrB,CAAC,CAAC;QACH,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,SAAS,EAAE,MAAM,CAAC,SAAS;KAC5B,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,sBAAsB,CAAC,MAA0B;IAC/D,OAAO;QACL,KAAK,EAAE,MAAM,CAAC,KAAK;QACnB,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,aAAa,EAAE,MAAM,CAAC,cAAc,IAAI,SAAS;QACjD,UAAU,EAAE,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,qBAAqB,CAAC;QACzD,WAAW,EAAE,MAAM,CAAC,YAAY,CAAC,GAAG,CAAC,qBAAqB,CAAC;QAC3D,cAAc,EAAE,MAAM,CAAC,eAAe,IAAI,EAAE;KAC7C,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAC,MAAyB;IAC7D,OAAO;QACL,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,sBAAsB,CAAC;QACjD,UAAU,EAAE,MAAM,CAAC,WAAW,IAAI,SAAS;KAC5C,CAAC;AACJ,CAAC"}
|
package/dist/error-codes.d.ts
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* are normalized to snake_case here so the union has one consistent shape; use
|
|
9
9
|
* {@link normalizeGuardianErrorCode} at the wire boundary.
|
|
10
10
|
*/
|
|
11
|
-
export declare const GUARDIAN_ERROR_CODES: readonly ["account_already_exists", "account_data_unavailable", "account_not_found", "account_paused", "account_released", "authentication_failed", "authentication_replay", "authorization_failed", "candidate_landed", "commitment_mismatch", "configuration_error", "conflict_pending_delta", "conflict_pending_proposal", "data_unavailable", "delta_not_found", "insufficient_operator_permission", "insufficient_signatures", "invalid_account_id", "invalid_commitment", "invalid_cursor", "invalid_delta", "invalid_evm_proposal", "invalid_input", "invalid_limit", "invalid_network_config", "invalid_proposal_signature", "invalid_status_filter", "invalid_timestamp", "network_error", "pending_proposals_limit", "proposal_already_signed", "proposal_not_found", "rate_limit_exceeded", "rpc_unavailable", "rpc_validation_failed", "signature_scheme_not_allowed", "signer_not_authorized", "signing_error", "state_not_found", "storage_error", "unsupported_evm_chain", "unsupported_for_network"];
|
|
11
|
+
export declare const GUARDIAN_ERROR_CODES: readonly ["account_already_exists", "account_data_unavailable", "account_not_found", "account_paused", "account_released", "authentication_failed", "authentication_replay", "authorization_failed", "candidate_landed", "commitment_mismatch", "configuration_error", "conflict_pending_delta", "conflict_pending_proposal", "data_unavailable", "delta_not_found", "insufficient_operator_permission", "insufficient_signatures", "invalid_account_id", "invalid_commitment", "invalid_cursor", "invalid_delta", "invalid_evm_proposal", "invalid_input", "invalid_limit", "invalid_network_config", "invalid_proposal_signature", "invalid_status_filter", "invalid_timestamp", "network_error", "pending_proposals_limit", "proposal_already_signed", "proposal_not_found", "rate_limit_exceeded", "rpc_unavailable", "rpc_validation_failed", "session_expired", "session_revoked", "signature_scheme_not_allowed", "signer_not_authorized", "signing_error", "state_not_found", "storage_error", "unsupported_evm_chain", "unsupported_for_network", "wallet_signature_required"];
|
|
12
12
|
/**
|
|
13
13
|
* A stable Guardian error code, compiler-checked: comparing against a
|
|
14
14
|
* non-member literal is a type error, and `switch` statements can be
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-codes.d.ts","sourceRoot":"","sources":["../src/error-codes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,eAAO,MAAM,oBAAoB,
|
|
1
|
+
{"version":3,"file":"error-codes.d.ts","sourceRoot":"","sources":["../src/error-codes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,eAAO,MAAM,oBAAoB,yhCA8CvB,CAAC;AAEX;;;;;GAKG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,oBAAoB,CAAC,CAAC,MAAM,CAAC,CAAC;AAetE,6EAA6E;AAC7E,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,iBAAiB,CAE7E;AAED;;;;;;;GAOG;AACH,wBAAgB,0BAA0B,CAAC,GAAG,EAAE,MAAM,GAAG,iBAAiB,GAAG,IAAI,CAIhF"}
|
package/dist/error-codes.js
CHANGED
|
@@ -44,6 +44,8 @@ export const GUARDIAN_ERROR_CODES = [
|
|
|
44
44
|
'rate_limit_exceeded',
|
|
45
45
|
'rpc_unavailable',
|
|
46
46
|
'rpc_validation_failed',
|
|
47
|
+
'session_expired',
|
|
48
|
+
'session_revoked',
|
|
47
49
|
'signature_scheme_not_allowed',
|
|
48
50
|
'signer_not_authorized',
|
|
49
51
|
'signing_error',
|
|
@@ -51,6 +53,7 @@ export const GUARDIAN_ERROR_CODES = [
|
|
|
51
53
|
'storage_error',
|
|
52
54
|
'unsupported_evm_chain',
|
|
53
55
|
'unsupported_for_network',
|
|
56
|
+
'wallet_signature_required',
|
|
54
57
|
];
|
|
55
58
|
const CODE_SET = new Set(GUARDIAN_ERROR_CODES);
|
|
56
59
|
/**
|
package/dist/error-codes.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"error-codes.js","sourceRoot":"","sources":["../src/error-codes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,wBAAwB;IACxB,0BAA0B;IAC1B,mBAAmB;IACnB,gBAAgB;IAChB,kBAAkB;IAClB,uBAAuB;IACvB,uBAAuB;IACvB,sBAAsB;IACtB,kBAAkB;IAClB,qBAAqB;IACrB,qBAAqB;IACrB,wBAAwB;IACxB,2BAA2B;IAC3B,kBAAkB;IAClB,iBAAiB;IACjB,kCAAkC;IAClC,yBAAyB;IACzB,oBAAoB;IACpB,oBAAoB;IACpB,gBAAgB;IAChB,eAAe;IACf,sBAAsB;IACtB,eAAe;IACf,eAAe;IACf,wBAAwB;IACxB,4BAA4B;IAC5B,uBAAuB;IACvB,mBAAmB;IACnB,eAAe;IACf,yBAAyB;IACzB,yBAAyB;IACzB,oBAAoB;IACpB,qBAAqB;IACrB,iBAAiB;IACjB,uBAAuB;IACvB,8BAA8B;IAC9B,uBAAuB;IACvB,eAAe;IACf,iBAAiB;IACjB,eAAe;IACf,uBAAuB;IACvB,yBAAyB;
|
|
1
|
+
{"version":3,"file":"error-codes.js","sourceRoot":"","sources":["../src/error-codes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG;IAClC,wBAAwB;IACxB,0BAA0B;IAC1B,mBAAmB;IACnB,gBAAgB;IAChB,kBAAkB;IAClB,uBAAuB;IACvB,uBAAuB;IACvB,sBAAsB;IACtB,kBAAkB;IAClB,qBAAqB;IACrB,qBAAqB;IACrB,wBAAwB;IACxB,2BAA2B;IAC3B,kBAAkB;IAClB,iBAAiB;IACjB,kCAAkC;IAClC,yBAAyB;IACzB,oBAAoB;IACpB,oBAAoB;IACpB,gBAAgB;IAChB,eAAe;IACf,sBAAsB;IACtB,eAAe;IACf,eAAe;IACf,wBAAwB;IACxB,4BAA4B;IAC5B,uBAAuB;IACvB,mBAAmB;IACnB,eAAe;IACf,yBAAyB;IACzB,yBAAyB;IACzB,oBAAoB;IACpB,qBAAqB;IACrB,iBAAiB;IACjB,uBAAuB;IACvB,iBAAiB;IACjB,iBAAiB;IACjB,8BAA8B;IAC9B,uBAAuB;IACvB,eAAe;IACf,iBAAiB;IACjB,eAAe;IACf,uBAAuB;IACvB,yBAAyB;IACzB,2BAA2B;CACnB,CAAC;AAUX,MAAM,QAAQ,GAAwB,IAAI,GAAG,CAAC,oBAAoB,CAAC,CAAC;AAEpE;;;GAGG;AACH,MAAM,YAAY,GAAgD;IAChE,uBAAuB,EAAE,gBAAgB;IACzC,yBAAyB,EAAE,kBAAkB;IAC7C,yCAAyC,EAAE,kCAAkC;IAC7E,yBAAyB,EAAE,kBAAkB;CAC9C,CAAC;AAEF,6EAA6E;AAC7E,MAAM,UAAU,mBAAmB,CAAC,KAAa;IAC/C,OAAO,QAAQ,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;AAC7B,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,0BAA0B,CAAC,GAAW;IACpD,MAAM,OAAO,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;IAClC,IAAI,OAAO,KAAK,SAAS;QAAE,OAAO,OAAO,CAAC;IAC1C,OAAO,mBAAmB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC;AAC/C,CAAC"}
|
package/dist/http.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type GuardianErrorCode } from './error-codes.js';
|
|
2
|
-
import type { AbandonCandidateResponse, AbandonStatus, ConfigureRequest, ConfigureResponse, DeltaObject, DeltaProposalRequest, DeltaProposalResponse, ExecutionDelta, HistoryOptions, HistoryPage, LookupResponse, PubkeyResponse, PushDeltaResponse, SignProposalRequest, SignatureScheme, Signer, StateObject, StatusResponse, CanonicalNonce } from './types.js';
|
|
2
|
+
import type { AbandonCandidateResponse, AbandonStatus, ConfigureRequest, ConfigureResponse, CreateSessionRequest, CreateSessionResponse, DeltaObject, DeltaProposalRequest, DeltaProposalResponse, ExecutionDelta, HistoryOptions, HistoryPage, LookupResponse, PubkeyResponse, PushDeltaResponse, SessionRequestSigner, SignProposalRequest, SignatureScheme, Signer, StateObject, StatusResponse, CanonicalNonce } from './types.js';
|
|
3
3
|
/**
|
|
4
4
|
* Structured machine-readable side-data on a GUARDIAN error
|
|
5
5
|
* (feature `009-human-readable-errors`). `retryable` is always present.
|
|
@@ -82,6 +82,8 @@ export declare class GuardianHttpError extends Error {
|
|
|
82
82
|
*/
|
|
83
83
|
export declare class GuardianHttpClient {
|
|
84
84
|
private signer;
|
|
85
|
+
private session;
|
|
86
|
+
private readonly endedSessions;
|
|
85
87
|
private readonly baseUrl;
|
|
86
88
|
private lastTimestamp;
|
|
87
89
|
constructor(baseUrl: string);
|
|
@@ -92,6 +94,43 @@ export declare class GuardianHttpClient {
|
|
|
92
94
|
*/
|
|
93
95
|
private nextTimestamp;
|
|
94
96
|
setSigner(signer: Signer): void;
|
|
97
|
+
/**
|
|
98
|
+
* Sign session-eligible requests (reads, proposal list/get, proposal
|
|
99
|
+
* create/sign) with a registered delegated signer instead of the wallet.
|
|
100
|
+
* Every other route, including `configure`, `pushDelta`,
|
|
101
|
+
* `abandonCandidate`, account lookup and `revokeAllSessions`, uses the
|
|
102
|
+
* wallet signer. Pass `null` to stop using the session.
|
|
103
|
+
*/
|
|
104
|
+
setSession(session: SessionRequestSigner | null): void;
|
|
105
|
+
/**
|
|
106
|
+
* The session in use, or `null` when none is set, no wallet signer is set,
|
|
107
|
+
* the session was granted by another wallet than the current signer, or it
|
|
108
|
+
* is about to expire. A session reaching its expiry margin is dropped and
|
|
109
|
+
* told so.
|
|
110
|
+
*/
|
|
111
|
+
getSession(): SessionRequestSigner | null;
|
|
112
|
+
/**
|
|
113
|
+
* Stops using `session` if it is still the current one, and tells it why
|
|
114
|
+
* once. A newer session set meanwhile stays in use.
|
|
115
|
+
*/
|
|
116
|
+
private endSession;
|
|
117
|
+
/** Register a wallet-signed session grant (`POST /session`). */
|
|
118
|
+
createSession(request: CreateSessionRequest): Promise<CreateSessionResponse>;
|
|
119
|
+
/**
|
|
120
|
+
* Revoke a session on the server (`POST /session/logout`), the current one
|
|
121
|
+
* by default, and stop using it. Returns whether the server still had it
|
|
122
|
+
* active; `false` when there is none. On error the session stays in use.
|
|
123
|
+
*/
|
|
124
|
+
revokeSession(session?: SessionRequestSigner | null): Promise<boolean>;
|
|
125
|
+
/**
|
|
126
|
+
* Revoke every session of the wallet signer on the server
|
|
127
|
+
* (`POST /session/revoke-all`), including sessions started elsewhere, and
|
|
128
|
+
* stop using the session that was current when the call was made. A
|
|
129
|
+
* session started while the call is in flight was issued after it and
|
|
130
|
+
* stays in use. Signed by the wallet. Returns how many sessions the server
|
|
131
|
+
* revoked.
|
|
132
|
+
*/
|
|
133
|
+
revokeAllSessions(): Promise<number>;
|
|
95
134
|
getPubkey(scheme?: SignatureScheme): Promise<PubkeyResponse>;
|
|
96
135
|
getStatus(): Promise<StatusResponse>;
|
|
97
136
|
configure(request: ConfigureRequest): Promise<ConfigureResponse>;
|
|
@@ -164,5 +203,6 @@ export declare class GuardianHttpClient {
|
|
|
164
203
|
*/
|
|
165
204
|
private fetchLookupAuthenticated;
|
|
166
205
|
private fetchAuthenticated;
|
|
206
|
+
private walletAuthHeaders;
|
|
167
207
|
}
|
|
168
208
|
//# sourceMappingURL=http.d.ts.map
|
package/dist/http.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,iBAAiB,EAEvB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EACV,wBAAwB,EACxB,aAAa,EACb,gBAAgB,EAChB,iBAAiB,EACjB,WAAW,EACX,oBAAoB,EACpB,qBAAqB,EACrB,cAAc,EACd,cAAc,EACd,WAAW,EACX,cAAc,EACd,cAAc,EACd,iBAAiB,
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,iBAAiB,EAEvB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EACV,wBAAwB,EACxB,aAAa,EACb,gBAAgB,EAChB,iBAAiB,EACjB,oBAAoB,EACpB,qBAAqB,EACrB,WAAW,EACX,oBAAoB,EACpB,qBAAqB,EACrB,cAAc,EACd,cAAc,EACd,WAAW,EACX,cAAc,EACd,cAAc,EACd,iBAAiB,EAEjB,oBAAoB,EACpB,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AE,CAAC;IAU5D,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAU7E,iBAAiB,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,qBAAqB,CAAC;IAatF;;;;;;;;;;;;OAYG;IACG,gBAAgB,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,wBAAwB,CAAC;IAgB3F;;;;;;;;;;;OAWG;IACG,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,aAAa,CAAC;IA6BvE,iBAAiB,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,WAAW,CAAC;IAUrE,SAAS,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,CAAC,iBAAiB,CAAC;IAkB5D,QAAQ,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAiBhE,aAAa,CAAC,SAAS,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC;IAiB/E;;;;;;;OAOG;IACG,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,WAAW,CAAC;YAmB9E,KAAK;IAuBnB;;;;;OAKG;YACW,wBAAwB;YA4BxB,kBAAkB;YAyDlB,iBAAiB;CAahC"}
|
package/dist/http.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { normalizeGuardianErrorCode, } from './error-codes.js';
|
|
2
2
|
import { RequestAuthPayload } from './auth-request.js';
|
|
3
|
-
import { fromServerCanonicalNonce, fromServerConfigureResponse, fromServerDeltaObject, fromServerHistoryPage, fromServerLookupResponse, fromServerStateObject, toServerConfigureRequest, toServerDeltaProposalRequest, toServerExecutionDelta, toServerSignProposalRequest, } from './conversion.js';
|
|
3
|
+
import { fromServerCanonicalNonce, fromServerConfigureResponse, fromServerCreateSessionResponse, fromServerDeltaObject, fromServerHistoryPage, fromServerLookupResponse, fromServerStateObject, toServerConfigureRequest, toServerCreateSessionRequest, toServerDeltaProposalRequest, toServerExecutionDelta, toServerSignProposalRequest, } from './conversion.js';
|
|
4
4
|
/**
|
|
5
5
|
* Parse a GUARDIAN error body `{ code, message, meta }` (feature 009),
|
|
6
6
|
* mapping the server's snake_case `meta` fields to camelCase. Returns
|
|
@@ -138,11 +138,32 @@ function parseRetryAfterSeconds(header) {
|
|
|
138
138
|
const secs = Number(trimmed);
|
|
139
139
|
return Number.isSafeInteger(secs) ? secs : undefined;
|
|
140
140
|
}
|
|
141
|
+
/**
|
|
142
|
+
* A session is set aside this long before it expires, so a request never
|
|
143
|
+
* reaches the server already expired; requests then fall back to the wallet.
|
|
144
|
+
*/
|
|
145
|
+
const SESSION_EXPIRY_MARGIN_MS = 30_000;
|
|
146
|
+
/** Codes that end a session-signed request's session for good. */
|
|
147
|
+
const SESSION_END_REASONS = {
|
|
148
|
+
session_expired: 'expired',
|
|
149
|
+
session_revoked: 'revoked',
|
|
150
|
+
authentication_failed: 'rejected',
|
|
151
|
+
};
|
|
152
|
+
function authHeaders(publicKey, signature, timestamp, format) {
|
|
153
|
+
return {
|
|
154
|
+
'x-pubkey': publicKey,
|
|
155
|
+
'x-signature': signature,
|
|
156
|
+
'x-timestamp': timestamp.toString(),
|
|
157
|
+
...(format ? { 'x-auth-format': format } : {}),
|
|
158
|
+
};
|
|
159
|
+
}
|
|
141
160
|
/**
|
|
142
161
|
* Minimal HTTP client for GUARDIAN server.
|
|
143
162
|
*/
|
|
144
163
|
export class GuardianHttpClient {
|
|
145
164
|
signer = null;
|
|
165
|
+
session = null;
|
|
166
|
+
endedSessions = new WeakSet();
|
|
146
167
|
baseUrl;
|
|
147
168
|
lastTimestamp = 0;
|
|
148
169
|
constructor(baseUrl) {
|
|
@@ -162,6 +183,108 @@ export class GuardianHttpClient {
|
|
|
162
183
|
setSigner(signer) {
|
|
163
184
|
this.signer = signer;
|
|
164
185
|
}
|
|
186
|
+
/**
|
|
187
|
+
* Sign session-eligible requests (reads, proposal list/get, proposal
|
|
188
|
+
* create/sign) with a registered delegated signer instead of the wallet.
|
|
189
|
+
* Every other route, including `configure`, `pushDelta`,
|
|
190
|
+
* `abandonCandidate`, account lookup and `revokeAllSessions`, uses the
|
|
191
|
+
* wallet signer. Pass `null` to stop using the session.
|
|
192
|
+
*/
|
|
193
|
+
setSession(session) {
|
|
194
|
+
this.session = session;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* The session in use, or `null` when none is set, no wallet signer is set,
|
|
198
|
+
* the session was granted by another wallet than the current signer, or it
|
|
199
|
+
* is about to expire. A session reaching its expiry margin is dropped and
|
|
200
|
+
* told so.
|
|
201
|
+
*/
|
|
202
|
+
getSession() {
|
|
203
|
+
const session = this.session;
|
|
204
|
+
if (!session) {
|
|
205
|
+
return null;
|
|
206
|
+
}
|
|
207
|
+
if (session.expiresAt * 1000 - SESSION_EXPIRY_MARGIN_MS <= Date.now()) {
|
|
208
|
+
this.endSession(session, 'expired');
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
if (!this.signer ||
|
|
212
|
+
this.signer.commitment.toLowerCase() !== session.signerCommitment.toLowerCase()) {
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
return session;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Stops using `session` if it is still the current one, and tells it why
|
|
219
|
+
* once. A newer session set meanwhile stays in use.
|
|
220
|
+
*/
|
|
221
|
+
endSession(session, reason) {
|
|
222
|
+
if (this.session === session) {
|
|
223
|
+
this.session = null;
|
|
224
|
+
}
|
|
225
|
+
if (!this.endedSessions.has(session)) {
|
|
226
|
+
this.endedSessions.add(session);
|
|
227
|
+
session.onEnded?.(reason);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
/** Register a wallet-signed session grant (`POST /session`). */
|
|
231
|
+
async createSession(request) {
|
|
232
|
+
const response = await this.fetch('/session', {
|
|
233
|
+
method: 'POST',
|
|
234
|
+
body: JSON.stringify(toServerCreateSessionRequest(request)),
|
|
235
|
+
});
|
|
236
|
+
return fromServerCreateSessionResponse((await response.json()));
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Revoke a session on the server (`POST /session/logout`), the current one
|
|
240
|
+
* by default, and stop using it. Returns whether the server still had it
|
|
241
|
+
* active; `false` when there is none. On error the session stays in use.
|
|
242
|
+
*/
|
|
243
|
+
async revokeSession(session = this.session) {
|
|
244
|
+
if (!session) {
|
|
245
|
+
return false;
|
|
246
|
+
}
|
|
247
|
+
const timestamp = this.nextTimestamp();
|
|
248
|
+
const signature = await session.signLogout(timestamp);
|
|
249
|
+
const response = await this.fetch('/session/logout', {
|
|
250
|
+
method: 'POST',
|
|
251
|
+
headers: authHeaders(session.publicKey, signature, timestamp),
|
|
252
|
+
});
|
|
253
|
+
const data = (await response.json());
|
|
254
|
+
this.endSession(session, 'logout');
|
|
255
|
+
return data.revoked;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Revoke every session of the wallet signer on the server
|
|
259
|
+
* (`POST /session/revoke-all`), including sessions started elsewhere, and
|
|
260
|
+
* stop using the session that was current when the call was made. A
|
|
261
|
+
* session started while the call is in flight was issued after it and
|
|
262
|
+
* stays in use. Signed by the wallet. Returns how many sessions the server
|
|
263
|
+
* revoked.
|
|
264
|
+
*/
|
|
265
|
+
async revokeAllSessions() {
|
|
266
|
+
const signer = this.signer;
|
|
267
|
+
if (!signer) {
|
|
268
|
+
throw new Error('No signer configured. Call setSigner() first.');
|
|
269
|
+
}
|
|
270
|
+
if (!signer.signSessionRevokeAll) {
|
|
271
|
+
throw new Error('This signer cannot sign Guardian session revocations');
|
|
272
|
+
}
|
|
273
|
+
const revoking = this.session;
|
|
274
|
+
const timestamp = this.nextTimestamp();
|
|
275
|
+
const signature = await signer.signSessionRevokeAll(signer.commitment, timestamp);
|
|
276
|
+
const body = { signer_commitment: signer.commitment };
|
|
277
|
+
const response = await this.fetch('/session/revoke-all', {
|
|
278
|
+
method: 'POST',
|
|
279
|
+
headers: authHeaders(signer.publicKey, signature, timestamp, signer.requestAuthFormat),
|
|
280
|
+
body: JSON.stringify(body),
|
|
281
|
+
});
|
|
282
|
+
const data = (await response.json());
|
|
283
|
+
if (revoking?.signerCommitment.toLowerCase() === signer.commitment.toLowerCase()) {
|
|
284
|
+
this.endSession(revoking, 'logout');
|
|
285
|
+
}
|
|
286
|
+
return data.revoked;
|
|
287
|
+
}
|
|
165
288
|
async getPubkey(scheme) {
|
|
166
289
|
const query = scheme ? `?scheme=${scheme}` : '';
|
|
167
290
|
const response = await this.fetch(`/pubkey${query}`, { method: 'GET' });
|
|
@@ -181,10 +304,18 @@ export class GuardianHttpClient {
|
|
|
181
304
|
environment: data.environment,
|
|
182
305
|
startedAt: data.started_at,
|
|
183
306
|
uptimeSeconds: data.uptime_seconds,
|
|
307
|
+
...(data.sessions
|
|
308
|
+
? {
|
|
309
|
+
sessions: {
|
|
310
|
+
maxTtlSeconds: data.sessions.max_ttl_seconds,
|
|
311
|
+
},
|
|
312
|
+
}
|
|
313
|
+
: {}),
|
|
184
314
|
};
|
|
185
315
|
}
|
|
186
316
|
async configure(request) {
|
|
187
317
|
const serverRequest = toServerConfigureRequest(request);
|
|
318
|
+
// Configuration changes who the account trusts: always the wallet.
|
|
188
319
|
const response = await this.fetchAuthenticated('/configure', {
|
|
189
320
|
method: 'POST',
|
|
190
321
|
body: JSON.stringify(serverRequest),
|
|
@@ -197,7 +328,7 @@ export class GuardianHttpClient {
|
|
|
197
328
|
const params = new URLSearchParams(requestQuery);
|
|
198
329
|
const response = await this.fetchAuthenticated(`/state?${params}`, {
|
|
199
330
|
method: 'GET',
|
|
200
|
-
}, accountId, requestQuery);
|
|
331
|
+
}, accountId, requestQuery, 'session');
|
|
201
332
|
const server = (await response.json());
|
|
202
333
|
return fromServerStateObject(server);
|
|
203
334
|
}
|
|
@@ -213,7 +344,7 @@ export class GuardianHttpClient {
|
|
|
213
344
|
const params = new URLSearchParams(requestQuery);
|
|
214
345
|
const response = await this.fetchAuthenticated(`/state/nonce?${params}`, {
|
|
215
346
|
method: 'GET',
|
|
216
|
-
}, accountId, requestQuery);
|
|
347
|
+
}, accountId, requestQuery, 'session');
|
|
217
348
|
const server = (await response.json());
|
|
218
349
|
return fromServerCanonicalNonce(server);
|
|
219
350
|
}
|
|
@@ -234,7 +365,7 @@ export class GuardianHttpClient {
|
|
|
234
365
|
const params = new URLSearchParams(requestQuery);
|
|
235
366
|
const response = await this.fetchAuthenticated(`/delta/proposal?${params}`, {
|
|
236
367
|
method: 'GET',
|
|
237
|
-
}, accountId, requestQuery);
|
|
368
|
+
}, accountId, requestQuery, 'session');
|
|
238
369
|
const data = (await response.json());
|
|
239
370
|
return data.proposals.map(fromServerDeltaObject);
|
|
240
371
|
}
|
|
@@ -243,7 +374,7 @@ export class GuardianHttpClient {
|
|
|
243
374
|
const params = new URLSearchParams(requestQuery);
|
|
244
375
|
const response = await this.fetchAuthenticated(`/delta/proposal/single?${params}`, {
|
|
245
376
|
method: 'GET',
|
|
246
|
-
}, accountId, requestQuery);
|
|
377
|
+
}, accountId, requestQuery, 'session');
|
|
247
378
|
const data = (await response.json());
|
|
248
379
|
return fromServerDeltaObject(data);
|
|
249
380
|
}
|
|
@@ -252,7 +383,7 @@ export class GuardianHttpClient {
|
|
|
252
383
|
const response = await this.fetchAuthenticated('/delta/proposal', {
|
|
253
384
|
method: 'POST',
|
|
254
385
|
body: JSON.stringify(serverRequest),
|
|
255
|
-
}, request.accountId, serverRequest);
|
|
386
|
+
}, request.accountId, serverRequest, 'session');
|
|
256
387
|
const server = (await response.json());
|
|
257
388
|
return {
|
|
258
389
|
delta: fromServerDeltaObject(server.delta),
|
|
@@ -274,6 +405,7 @@ export class GuardianHttpClient {
|
|
|
274
405
|
*/
|
|
275
406
|
async abandonCandidate(accountId, nonce) {
|
|
276
407
|
const serverRequest = { account_id: accountId, nonce };
|
|
408
|
+
// Abandoning changes the account's canonical chain: always the wallet.
|
|
277
409
|
const response = await this.fetchAuthenticated('/delta/candidate/abandon', {
|
|
278
410
|
method: 'POST',
|
|
279
411
|
body: JSON.stringify(serverRequest),
|
|
@@ -331,12 +463,13 @@ export class GuardianHttpClient {
|
|
|
331
463
|
const response = await this.fetchAuthenticated('/delta/proposal', {
|
|
332
464
|
method: 'PUT',
|
|
333
465
|
body: JSON.stringify(serverRequest),
|
|
334
|
-
}, request.accountId, serverRequest);
|
|
466
|
+
}, request.accountId, serverRequest, 'session');
|
|
335
467
|
const server = (await response.json());
|
|
336
468
|
return fromServerDeltaObject(server);
|
|
337
469
|
}
|
|
338
470
|
async pushDelta(delta) {
|
|
339
471
|
const serverDelta = toServerExecutionDelta(delta);
|
|
472
|
+
// Guardian's ACK commits the account to this transition: always the wallet.
|
|
340
473
|
const response = await this.fetchAuthenticated('/delta', {
|
|
341
474
|
method: 'POST',
|
|
342
475
|
body: JSON.stringify(serverDelta),
|
|
@@ -363,7 +496,7 @@ export class GuardianHttpClient {
|
|
|
363
496
|
const params = new URLSearchParams(requestQuery);
|
|
364
497
|
const response = await this.fetchAuthenticated(`/delta?${params}`, {
|
|
365
498
|
method: 'GET',
|
|
366
|
-
}, accountId, requestPayload);
|
|
499
|
+
}, accountId, requestPayload, 'session');
|
|
367
500
|
const server = (await response.json());
|
|
368
501
|
return fromServerDeltaObject(server);
|
|
369
502
|
}
|
|
@@ -379,7 +512,7 @@ export class GuardianHttpClient {
|
|
|
379
512
|
const params = new URLSearchParams(requestQuery);
|
|
380
513
|
const response = await this.fetchAuthenticated(`/delta/since?${params}`, {
|
|
381
514
|
method: 'GET',
|
|
382
|
-
}, accountId, requestPayload);
|
|
515
|
+
}, accountId, requestPayload, 'session');
|
|
383
516
|
const server = (await response.json());
|
|
384
517
|
return fromServerDeltaObject(server);
|
|
385
518
|
}
|
|
@@ -405,7 +538,7 @@ export class GuardianHttpClient {
|
|
|
405
538
|
const params = new URLSearchParams(requestPayload);
|
|
406
539
|
const response = await this.fetchAuthenticated(`/delta/history?${params}`, {
|
|
407
540
|
method: 'GET',
|
|
408
|
-
}, accountId, requestPayload);
|
|
541
|
+
}, accountId, requestPayload, 'session');
|
|
409
542
|
const server = (await response.json());
|
|
410
543
|
return fromServerHistoryPage(server);
|
|
411
544
|
}
|
|
@@ -445,35 +578,37 @@ export class GuardianHttpClient {
|
|
|
445
578
|
...init,
|
|
446
579
|
headers: {
|
|
447
580
|
...init.headers,
|
|
448
|
-
|
|
449
|
-
'x-signature': signature,
|
|
450
|
-
'x-timestamp': timestamp.toString(),
|
|
451
|
-
...(this.signer.requestAuthFormat ? { 'x-auth-format': this.signer.requestAuthFormat } : {}),
|
|
581
|
+
...authHeaders(this.signer.publicKey, signature, timestamp, this.signer.requestAuthFormat),
|
|
452
582
|
},
|
|
453
583
|
});
|
|
454
584
|
}
|
|
455
|
-
async fetchAuthenticated(path, init, accountId, requestPayload, retries = 2) {
|
|
456
|
-
if (!this.signer) {
|
|
457
|
-
throw new Error('No signer configured. Call setSigner() first.');
|
|
458
|
-
}
|
|
585
|
+
async fetchAuthenticated(path, init, accountId, requestPayload, mode = 'wallet', retries = 2) {
|
|
459
586
|
const timestamp = this.nextTimestamp();
|
|
460
587
|
const authPayload = RequestAuthPayload.fromRequest(requestPayload);
|
|
461
|
-
const
|
|
462
|
-
|
|
463
|
-
|
|
588
|
+
const session = mode === 'session' ? this.getSession() : null;
|
|
589
|
+
const headers = session
|
|
590
|
+
? authHeaders(session.publicKey, await session.signRequest(accountId, timestamp, authPayload), timestamp, 'session')
|
|
591
|
+
: await this.walletAuthHeaders(accountId, timestamp, authPayload);
|
|
464
592
|
try {
|
|
465
593
|
return await this.fetch(path, {
|
|
466
594
|
...init,
|
|
467
595
|
headers: {
|
|
468
596
|
...init.headers,
|
|
469
|
-
|
|
470
|
-
'x-signature': signature,
|
|
471
|
-
'x-timestamp': timestamp.toString(),
|
|
472
|
-
...(this.signer.requestAuthFormat ? { 'x-auth-format': this.signer.requestAuthFormat } : {}),
|
|
597
|
+
...headers,
|
|
473
598
|
},
|
|
474
599
|
});
|
|
475
600
|
}
|
|
476
601
|
catch (err) {
|
|
602
|
+
// A session Guardian ended or no longer accepts (unknown key after a
|
|
603
|
+
// restart, rotated Guardian key or network) is dead for good: stop
|
|
604
|
+
// using it so the caller can start a new one; meanwhile the wallet
|
|
605
|
+
// signs again.
|
|
606
|
+
if (session && err instanceof GuardianHttpError) {
|
|
607
|
+
const reason = SESSION_END_REASONS[err.code ?? ''];
|
|
608
|
+
if (reason) {
|
|
609
|
+
this.endSession(session, reason);
|
|
610
|
+
}
|
|
611
|
+
}
|
|
477
612
|
// Replay rejections are transient: the request was correctly signed
|
|
478
613
|
// but lost the server's per-signer timestamp CAS. Retry with a fresh
|
|
479
614
|
// timestamp and signature, branching only on the dedicated
|
|
@@ -484,10 +619,19 @@ export class GuardianHttpClient {
|
|
|
484
619
|
err instanceof GuardianHttpError &&
|
|
485
620
|
err.code === 'authentication_replay') {
|
|
486
621
|
await new Promise((resolve) => setTimeout(resolve, 50));
|
|
487
|
-
return this.fetchAuthenticated(path, init, accountId, requestPayload, retries - 1);
|
|
622
|
+
return this.fetchAuthenticated(path, init, accountId, requestPayload, mode, retries - 1);
|
|
488
623
|
}
|
|
489
624
|
throw err;
|
|
490
625
|
}
|
|
491
626
|
}
|
|
627
|
+
async walletAuthHeaders(accountId, timestamp, authPayload) {
|
|
628
|
+
if (!this.signer) {
|
|
629
|
+
throw new Error('No signer configured. Call setSigner() first.');
|
|
630
|
+
}
|
|
631
|
+
const signature = this.signer.signRequest
|
|
632
|
+
? await this.signer.signRequest(accountId, timestamp, authPayload)
|
|
633
|
+
: await this.signer.signAccountIdWithTimestamp(accountId, timestamp);
|
|
634
|
+
return authHeaders(this.signer.publicKey, signature, timestamp, this.signer.requestAuthFormat);
|
|
635
|
+
}
|
|
492
636
|
}
|
|
493
637
|
//# sourceMappingURL=http.js.map
|