@t3foundry/tasra-sdk 0.3.1 → 0.4.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/CHANGELOG.md +1067 -28
- package/README.md +15 -0
- package/dist/app/approvals.d.ts +66 -4
- package/dist/app/approvals.js +153 -16
- package/dist/app/authorization.d.ts +1 -1
- package/dist/app/authorization.js +1 -1
- package/dist/app/browser.d.ts +63 -0
- package/dist/app/browser.js +242 -0
- package/dist/app/client.d.ts +114 -13
- package/dist/app/client.js +302 -76
- package/dist/app/identity.js +21 -9
- package/dist/app/index.d.ts +28 -3
- package/dist/app/index.js +16 -1
- package/dist/app/memory-store.d.ts +7 -0
- package/dist/app/memory-store.js +55 -0
- package/dist/app/node.d.ts +34 -6
- package/dist/app/node.js +387 -64
- package/dist/app/paid-allowance.d.ts +325 -0
- package/dist/app/paid-allowance.js +1290 -0
- package/dist/app/paid-approval.d.ts +122 -0
- package/dist/app/paid-approval.js +379 -0
- package/dist/app/paid-journal.d.ts +51 -0
- package/dist/app/paid-journal.js +117 -0
- package/dist/app/paid-keys.d.ts +12 -0
- package/dist/app/paid-keys.js +20 -0
- package/dist/app/paid-operation.d.ts +821 -0
- package/dist/app/paid-operation.js +1720 -0
- package/dist/app/paid-reservation.d.ts +157 -0
- package/dist/app/paid-reservation.js +323 -0
- package/dist/app/paid-session.d.ts +147 -0
- package/dist/app/paid-session.js +578 -0
- package/dist/app/payer-queue.d.ts +11 -0
- package/dist/app/payer-queue.js +27 -0
- package/dist/app/policy-bootstrap.d.ts +342 -0
- package/dist/app/policy-bootstrap.js +365 -0
- package/dist/app/policy-operation.d.ts +47 -0
- package/dist/app/policy-operation.js +101 -0
- package/dist/app/ready-slot.d.ts +12 -0
- package/dist/app/ready-slot.js +5 -2
- package/dist/app/rotation-lock.d.ts +38 -0
- package/dist/app/rotation-lock.js +42 -0
- package/dist/app/session-decrypt.d.ts +135 -0
- package/dist/app/session-decrypt.js +335 -0
- package/dist/app/session-grants.d.ts +349 -0
- package/dist/app/session-grants.js +811 -0
- package/dist/app/signing-intents.d.ts +78 -0
- package/dist/app/signing-intents.js +95 -0
- package/dist/app/store-commit.d.ts +63 -0
- package/dist/app/store-commit.js +126 -0
- package/dist/app/store-errors.d.ts +8 -0
- package/dist/app/store-errors.js +11 -0
- package/dist/app/tasra-client.d.ts +2 -0
- package/dist/app/tasra-client.js +1 -1
- package/dist/app/wallet.js +4 -1
- package/dist/auth/holderProof.d.ts +3 -0
- package/dist/auth/holderProof.js +8 -7
- package/dist/auth/verifier.d.ts +4 -2
- package/dist/auth/verifier.js +5 -2
- package/dist/chain/abis/index.d.ts +6178 -4101
- package/dist/chain/abis/index.js +3 -0
- package/dist/chain/abis/keyRegistry.d.ts +256 -0
- package/dist/chain/abis/keyRegistry.js +333 -0
- package/dist/chain/abis/prepaidFaultOracle.d.ts +321 -0
- package/dist/chain/abis/prepaidFaultOracle.js +413 -0
- package/dist/chain/abis/settlement.d.ts +2203 -703
- package/dist/chain/abis/settlement.js +2685 -764
- package/dist/chain/allowance.d.ts +358 -0
- package/dist/chain/allowance.js +800 -0
- package/dist/chain/billing.d.ts +85 -0
- package/dist/chain/billing.js +197 -0
- package/dist/chain/chainId.d.ts +13 -0
- package/dist/chain/chainId.js +26 -0
- package/dist/chain/client.d.ts +15 -1
- package/dist/chain/client.js +57 -1
- package/dist/chain/commitmentRecovery.d.ts +51 -0
- package/dist/chain/commitmentRecovery.js +38 -0
- package/dist/chain/committeeClient.d.ts +17 -10
- package/dist/chain/committeeClient.js +64 -16
- package/dist/chain/committeeDraw.d.ts +12 -0
- package/dist/chain/committeeDraw.js +56 -0
- package/dist/chain/custodyHealth.d.ts +212 -0
- package/dist/chain/custodyHealth.js +365 -0
- package/dist/chain/deployments.js +2 -0
- package/dist/chain/events.js +2 -0
- package/dist/chain/headFollower.d.ts +77 -0
- package/dist/chain/headFollower.js +219 -0
- package/dist/chain/headPrefetch.d.ts +23 -0
- package/dist/chain/headPrefetch.js +67 -0
- package/dist/chain/index.d.ts +50 -8
- package/dist/chain/index.js +28 -3
- package/dist/chain/keeperExecution.d.ts +44 -0
- package/dist/chain/keeperExecution.js +127 -0
- package/dist/chain/keeperRecovery.d.ts +78 -0
- package/dist/chain/keeperRecovery.js +91 -0
- package/dist/chain/node.d.ts +24 -1
- package/dist/chain/node.js +88 -43
- package/dist/chain/offchain.d.ts +2 -0
- package/dist/chain/paidAgentTransport.d.ts +38 -0
- package/dist/chain/paidAgentTransport.js +1 -0
- package/dist/chain/paidEpoch.d.ts +66 -0
- package/dist/chain/paidEpoch.js +139 -0
- package/dist/chain/paidPacing.d.ts +81 -0
- package/dist/chain/paidPacing.js +136 -0
- package/dist/chain/pinnedReads.d.ts +49 -0
- package/dist/chain/pinnedReads.js +218 -0
- package/dist/chain/prepaid.d.ts +383 -0
- package/dist/chain/prepaid.js +1046 -0
- package/dist/chain/prepaidEscape.d.ts +274 -0
- package/dist/chain/prepaidEscape.js +432 -0
- package/dist/chain/prepaidFault.d.ts +94 -0
- package/dist/chain/prepaidFault.js +148 -0
- package/dist/chain/receipt.d.ts +24 -0
- package/dist/chain/receipt.js +82 -0
- package/dist/chain/registeredAgent.d.ts +68 -3
- package/dist/chain/registeredAgent.js +143 -42
- package/dist/chain/registeredOperation.d.ts +10 -1
- package/dist/chain/registeredOperation.js +18 -3
- package/dist/chain/registeredPaidAgent.d.ts +254 -0
- package/dist/chain/registeredPaidAgent.js +889 -0
- package/dist/chain/registeredRelay.d.ts +31 -1
- package/dist/chain/registeredRelay.js +164 -43
- package/dist/chain/relayVoucher.d.ts +64 -0
- package/dist/chain/relayVoucher.js +69 -0
- package/dist/chain/reservation.d.ts +239 -0
- package/dist/chain/reservation.js +746 -0
- package/dist/chain/reshareRoster.d.ts +64 -0
- package/dist/chain/reshareRoster.js +85 -0
- package/dist/chain/revertReason.d.ts +8 -0
- package/dist/chain/revertReason.js +2 -1
- package/dist/chain/rotationLock.d.ts +130 -0
- package/dist/chain/rotationLock.js +168 -0
- package/dist/chain/serviceRequestPolicy.d.ts +47 -0
- package/dist/chain/serviceRequestPolicy.js +86 -0
- package/dist/chain/services.d.ts +7 -0
- package/dist/chain/services.js +44 -4
- package/dist/chain/slotClient.js +11 -2
- package/dist/chain/slotHandoff.d.ts +81 -0
- package/dist/chain/slotHandoff.js +166 -0
- package/dist/chain/slotSeed.d.ts +47 -5
- package/dist/chain/slotSeed.js +173 -42
- package/dist/chain/verifierSnapshot.d.ts +36 -0
- package/dist/chain/verifierSnapshot.js +197 -0
- package/dist/chain/write.d.ts +111 -21
- package/dist/chain/write.js +378 -146
- package/dist/committee/blsSharing.d.ts +53 -0
- package/dist/committee/blsSharing.js +90 -0
- package/dist/committee/client.d.ts +62 -23
- package/dist/committee/client.js +288 -72
- package/dist/committee/dual-operation.d.ts +165 -0
- package/dist/committee/dual-operation.js +229 -0
- package/dist/committee/dual-sign.d.ts +26 -1
- package/dist/committee/dual-sign.js +85 -7
- package/dist/committee/ecdsa.d.ts +38 -0
- package/dist/committee/ecdsa.js +87 -15
- package/dist/committee/evidence.d.ts +30 -0
- package/dist/committee/evidence.js +65 -0
- package/dist/committee/execution.d.ts +414 -0
- package/dist/committee/execution.js +446 -0
- package/dist/committee/extraction.js +33 -26
- package/dist/committee/index.d.ts +30 -7
- package/dist/committee/index.js +18 -6
- package/dist/committee/keeperExecution.d.ts +37 -0
- package/dist/committee/keeperExecution.js +141 -0
- package/dist/committee/oauth.d.ts +14 -4
- package/dist/committee/oauth.js +17 -5
- package/dist/committee/payment.d.ts +369 -0
- package/dist/committee/payment.js +339 -0
- package/dist/committee/recovery.d.ts +136 -0
- package/dist/committee/recovery.js +204 -0
- package/dist/committee/recoveryJson.d.ts +2 -0
- package/dist/committee/recoveryJson.js +87 -0
- package/dist/committee/request.d.ts +63 -27
- package/dist/committee/request.js +77 -66
- package/dist/committee/session-grant.d.ts +320 -0
- package/dist/committee/session-grant.js +397 -0
- package/dist/committee/status-refresh.d.ts +257 -0
- package/dist/committee/status-refresh.js +619 -0
- package/dist/committee/token.d.ts +163 -15
- package/dist/committee/token.js +247 -10
- package/dist/crypto/bn254.d.ts +70 -0
- package/dist/crypto/bn254.js +222 -0
- package/dist/crypto/ibe.d.ts +32 -0
- package/dist/crypto/ibe.js +56 -8
- package/dist/crypto/index.d.ts +1 -1
- package/dist/crypto/index.js +1 -1
- package/dist/crypto/kem.d.ts +31 -0
- package/dist/crypto/kem.js +113 -7
- package/dist/crypto/recipient.d.ts +75 -0
- package/dist/crypto/recipient.js +107 -0
- package/dist/decryption/client.d.ts +10 -16
- package/dist/decryption/client.js +8 -76
- package/dist/decryption/index.d.ts +2 -0
- package/dist/decryption/index.js +2 -0
- package/dist/decryption/sealed.d.ts +72 -0
- package/dist/decryption/sealed.js +147 -0
- package/dist/decryption/session.d.ts +115 -0
- package/dist/decryption/session.js +358 -0
- package/dist/errors.d.ts +406 -1
- package/dist/errors.js +400 -5
- package/dist/index.d.ts +9 -2
- package/dist/index.js +6 -1
- package/dist/internal/bounded.d.ts +66 -0
- package/dist/internal/bounded.js +126 -0
- package/dist/internal/network.d.ts +4 -0
- package/dist/internal/network.js +40 -0
- package/dist/internal/retryAfter.d.ts +8 -0
- package/dist/internal/retryAfter.js +28 -0
- package/dist/internal/sleep.d.ts +6 -0
- package/dist/internal/sleep.js +15 -0
- package/dist/internal/typedData.d.ts +13 -0
- package/dist/internal/typedData.js +77 -0
- package/dist/internal/viemErrors.d.ts +26 -0
- package/dist/internal/viemErrors.js +49 -0
- package/dist/oid4vp/binding.d.ts +27 -1
- package/dist/oid4vp/binding.js +36 -1
- package/dist/oid4vp/jose.d.ts +4 -2
- package/dist/oid4vp/jose.js +39 -7
- package/dist/oid4vp/request-object.d.ts +61 -4
- package/dist/oid4vp/request-object.js +140 -5
- package/dist/oid4vp/verifier-agent.d.ts +18 -8
- package/dist/oid4vp/verifier-agent.js +48 -6
- package/dist/oid4vp/wallet.d.ts +2 -4
- package/dist/oid4vp/wallet.js +1 -0
- package/dist/retry.d.ts +78 -0
- package/dist/retry.js +137 -0
- package/dist/signing/frost.d.ts +1 -1
- package/dist/verifier-agent/index.d.ts +41 -5
- package/dist/verifier-agent/index.js +124 -9
- package/dist/verifier-agent/payment.d.ts +7 -0
- package/dist/verifier-agent/payment.js +17 -0
- package/docs/api.md +8 -2
- package/docs/application-api.md +25 -2
- package/docs/chain.md +155 -9
- package/docs/consumer-migrations.md +61 -0
- package/docs/encrypted-notes.md +3 -2
- package/docs/encryption.md +4 -2
- package/docs/errors.md +14 -1
- package/docs/flows.md +2 -2
- package/docs/funding.md +902 -0
- package/docs/native-approvals.md +63 -0
- package/docs/reference/README.md +9 -8
- package/docs/reference/app-browser.md +232 -0
- package/docs/reference/app-node.md +38 -8
- package/docs/reference/app.md +4621 -805
- package/docs/reference/chain-node.md +74 -16
- package/docs/reference/chain.md +6740 -1592
- package/docs/reference/committee.md +5630 -987
- package/docs/reference/main.md +1439 -140
- package/docs/reference/oid4vp.md +297 -144
- package/docs/reference/verifier-agent.md +77 -35
- package/docs/signing.md +6 -0
- package/examples/encrypted-notes.ts +21 -6
- package/examples/getting-started.ts +2 -7
- package/examples/live-config.ts +24 -17
- package/package.json +17 -5
|
@@ -0,0 +1,349 @@
|
|
|
1
|
+
import { TasraError } from '../errors.js';
|
|
2
|
+
import type { VerifierSet } from '../committee/token.js';
|
|
3
|
+
import { type SessionGrantRequestWire, type SessionGrantWire, type SessionKeyJwk, type VerifiedSessionGrant } from '../committee/session-grant.js';
|
|
4
|
+
import type { ApplicationStore } from './ready-slot.js';
|
|
5
|
+
import type { ApprovedAgentProfile } from '../chain/registeredAgent.js';
|
|
6
|
+
import type { PaidAgentTransport } from '../chain/paidAgentTransport.js';
|
|
7
|
+
import type { BeaconDrawState } from '../chain/prepaid.js';
|
|
8
|
+
/** A session key the client holds; only its public JWK ever leaves it. */
|
|
9
|
+
export interface SessionKeyHandle {
|
|
10
|
+
/** Public JWK sent at session create (RFC 7638 members only). */
|
|
11
|
+
readonly jwk: SessionKeyJwk;
|
|
12
|
+
/** 64-byte signature over a 32-byte proof or control hash (Ed25519, or ES256 `r ‖ s`). */
|
|
13
|
+
sign(hash: Uint8Array): Promise<Uint8Array>;
|
|
14
|
+
/** Forget the private key (in-memory Ed25519 keys are zeroed; WebCrypto keys are dropped). */
|
|
15
|
+
dispose(): void;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Create a fresh session key. Prefers a NON-EXTRACTABLE WebCrypto P-256 key (ES256), so the private
|
|
19
|
+
* key never exists as bytes in the page; without WebCrypto ECDSA it uses an in-memory Ed25519 key.
|
|
20
|
+
* A session key is per session: never reuse it across sessions.
|
|
21
|
+
* @param opts - Force `Ed25519` (tests, runtimes without WebCrypto) or `ES256`.
|
|
22
|
+
*/
|
|
23
|
+
export declare function createSessionKey(opts?: {
|
|
24
|
+
alg?: 'ES256' | 'Ed25519';
|
|
25
|
+
}): Promise<SessionKeyHandle>;
|
|
26
|
+
/** Requested session parameters; the platform clamps them and the grant carries the granted values. */
|
|
27
|
+
export interface SessionGrantParams {
|
|
28
|
+
/** KEM slots (1..16, distinct). */
|
|
29
|
+
slots: `0x${string}`[];
|
|
30
|
+
/** Grant lifetime before a refresh is needed (platform cap 45 s, default 30). */
|
|
31
|
+
accessTtlSecs?: number;
|
|
32
|
+
/** Longest idle gap between refreshes (cap 1800 s). */
|
|
33
|
+
idleTimeoutSecs?: number;
|
|
34
|
+
/** Longest session life from its presentation (cap 12 h). */
|
|
35
|
+
absoluteTtlSecs?: number;
|
|
36
|
+
}
|
|
37
|
+
/** The `session_grant` object added to `POST /v1/sessions` (session mode). */
|
|
38
|
+
export interface SessionGrantCreateFragment {
|
|
39
|
+
/** Session key, slots and requested lifetimes. */
|
|
40
|
+
session_grant: SessionGrantRequestWire;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Build the session-mode object for `POST /v1/sessions` (merge it into the create body). Slots are
|
|
44
|
+
* sorted ascending, as the agent canonicalizes them; requested lifetimes travel as requested and
|
|
45
|
+
* the agent clamps them to the platform caps.
|
|
46
|
+
* @param key - The session key whose public JWK the grant will bind.
|
|
47
|
+
* @param params - Slots and requested lifetimes.
|
|
48
|
+
*/
|
|
49
|
+
export declare function sessionGrantCreateFragment(key: SessionKeyHandle, params: SessionGrantParams): SessionGrantCreateFragment;
|
|
50
|
+
/** Independently established verification material for one granted slot. */
|
|
51
|
+
export interface SlotTrust {
|
|
52
|
+
/** Active verifier set (registry size + index to Ed25519 key) at the grant's epoch. */
|
|
53
|
+
set: VerifierSet;
|
|
54
|
+
/** The slot's committee size and quorum. */
|
|
55
|
+
committee: number;
|
|
56
|
+
/** Signatures from the slot's drawn committee required. */
|
|
57
|
+
quorum: number;
|
|
58
|
+
/** keccak256 of the slot's raw rule. */
|
|
59
|
+
ruleHash: Uint8Array;
|
|
60
|
+
/** The beacon seed of the grant's epoch, `beacon.seedAt(epoch)`, read from the chain: a grant on any other seed is refused. */
|
|
61
|
+
seed: Uint8Array;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Where a session's refresh and revoke go, and how its slots are trusted. Refresh and revoke travel
|
|
65
|
+
* through the SAME guarded registered-agent transport and request policy as every other paid agent
|
|
66
|
+
* call (verified TLS, connection-time destination checks, no redirects, bounded replies); the routes
|
|
67
|
+
* carry no bearer, because the session-key signature is their authorization.
|
|
68
|
+
*/
|
|
69
|
+
export interface SessionTransport {
|
|
70
|
+
/** The configured deployment chain: a grant naming any other chain is refused on accept, refresh and resume. */
|
|
71
|
+
chainId: number;
|
|
72
|
+
/** The approved verifier-agent and its guarded transport (`createNodePaidAgentTransport` / `createBrowserPaidAgentTransport`). */
|
|
73
|
+
agent: {
|
|
74
|
+
profile: ApprovedAgentProfile;
|
|
75
|
+
transport: PaidAgentTransport;
|
|
76
|
+
};
|
|
77
|
+
/** Verification material per granted slot, read from the chain by the caller. */
|
|
78
|
+
trust(slot: `0x${string}`, epoch: bigint): Promise<SlotTrust>;
|
|
79
|
+
}
|
|
80
|
+
/** A session that can no longer be refreshed: the application must present again. */
|
|
81
|
+
export declare class SessionEndedError extends TasraError {
|
|
82
|
+
/**
|
|
83
|
+
* A definite refusal ({@link SESSION_REFUSAL_CODES}), `unsupported` (a verifier-agent without
|
|
84
|
+
* session refresh) or `local-*` (`local-idle`, `local-absolute`, `local-expired`,
|
|
85
|
+
* `local-revoking`, `local-stale`: the beacon left the grant's window).
|
|
86
|
+
*/
|
|
87
|
+
readonly code: string;
|
|
88
|
+
constructor(code: string, message: string);
|
|
89
|
+
}
|
|
90
|
+
interface SessionRecord {
|
|
91
|
+
schema: 1;
|
|
92
|
+
sessionId: string;
|
|
93
|
+
grant: SessionGrantWire;
|
|
94
|
+
/** Highest seq reserved (written BEFORE it is signed or sent; never reused). */
|
|
95
|
+
lastSeq: number;
|
|
96
|
+
/** Unix seconds of the presentation or the last accepted refresh. */
|
|
97
|
+
lastRefresh: number;
|
|
98
|
+
/** Requested values, the upper bound every granted value must respect. */
|
|
99
|
+
requested: {
|
|
100
|
+
accessTtlSecs: number;
|
|
101
|
+
idleTimeoutSecs: number;
|
|
102
|
+
absoluteTtlSecs: number;
|
|
103
|
+
slots: string[];
|
|
104
|
+
};
|
|
105
|
+
ended?: {
|
|
106
|
+
code: string;
|
|
107
|
+
at: number;
|
|
108
|
+
};
|
|
109
|
+
/** A revoke started (journaled first): the session serves nothing more, even before the revoke completes. */
|
|
110
|
+
revoking?: true;
|
|
111
|
+
}
|
|
112
|
+
/** Lifecycle options. */
|
|
113
|
+
export interface GrantedSessionOptions {
|
|
114
|
+
/** Store that journals the session record (grant, reserved seq, end). */
|
|
115
|
+
store: ApplicationStore;
|
|
116
|
+
/** Transport for the agent's session refresh and revoke routes. */
|
|
117
|
+
transport: SessionTransport;
|
|
118
|
+
/** The session key the grant binds; it signs every refresh and revoke. */
|
|
119
|
+
key: SessionKeyHandle;
|
|
120
|
+
/** Refresh this many seconds before `exp` (default: a third of the grant's lifetime, at least 5 s). */
|
|
121
|
+
refreshLeadSecs?: number;
|
|
122
|
+
/** Called once when the session ends and a new presentation is needed. */
|
|
123
|
+
onEnded?(error: SessionEndedError): void;
|
|
124
|
+
/** Called after every accepted refresh with the new grant (re-derive per-epoch trust or proofs here). */
|
|
125
|
+
onRefreshed?(grant: SessionGrantWire): void;
|
|
126
|
+
/**
|
|
127
|
+
* The beacon's latest epoch (e.g. `readCurrentBeaconEpoch`). With it, {@link GrantedSession.start}
|
|
128
|
+
* also polls the beacon every `pollMs` (default 2000) and refreshes the grant in the background
|
|
129
|
+
* the moment the beacon moves past the grant's epoch ({@link GrantedSession.observeBeacon}).
|
|
130
|
+
*/
|
|
131
|
+
beacon?: {
|
|
132
|
+
latestEpoch(): Promise<bigint>;
|
|
133
|
+
/**
|
|
134
|
+
* The beacon's latest epoch AND its draw epoch (`readBeaconDrawState`). When set, the poll
|
|
135
|
+
* reads this instead of `latestEpoch` and a follow refreshes only once the agent can draw the
|
|
136
|
+
* next epoch (its verifier snapshot is anchored): ONE refresh per epoch, at the anchor, instead
|
|
137
|
+
* of re-signing the grant on its old epoch every `followRetryMs` until the anchor lands (each
|
|
138
|
+
* such refresh spends the holder's per-verifier session quota).
|
|
139
|
+
*/
|
|
140
|
+
drawState?(): Promise<BeaconDrawState>;
|
|
141
|
+
pollMs?: number;
|
|
142
|
+
};
|
|
143
|
+
/**
|
|
144
|
+
* How long a run of `session_context_changed` refresh refusals the chain does not confirm is
|
|
145
|
+
* retried before the session ends, ms (default 15000; needs `beacon`). See {@link SESSION_REFUSAL_CODES}.
|
|
146
|
+
*/
|
|
147
|
+
contextRetryMs?: number;
|
|
148
|
+
/** Pause between follow attempts while a new epoch's anchors land, ms (default 1000; tests use 0). */
|
|
149
|
+
followRetryMs?: number;
|
|
150
|
+
/** Clock override, Unix seconds (tests). */
|
|
151
|
+
clock?: () => number;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Accept the grant the agent returned for a session-mode presentation, after checking it against
|
|
155
|
+
* what was requested and against each slot's anchored committee, then persist it. The granted
|
|
156
|
+
* values may be lower than requested, never higher; the key thumbprint must be this key's.
|
|
157
|
+
* @param opts - Store, transport, session key and clock.
|
|
158
|
+
* @param fragment - The fragment sent at create.
|
|
159
|
+
* @param response - The agent's create/complete response carrying `session_grant` and `refresh_seq`.
|
|
160
|
+
*/
|
|
161
|
+
export declare function acceptSessionGrant(opts: GrantedSessionOptions, fragment: SessionGrantCreateFragment, response: unknown): Promise<GrantedSession>;
|
|
162
|
+
/**
|
|
163
|
+
* Refresh refusals no retry of the same session can pass (keykeeper-verifier `session_grant.rs`,
|
|
164
|
+
* relayed by the verifier-agent): the session ends and the application presents again.
|
|
165
|
+
* `session_context_changed`: the verifiers' live draw no longer admits the grant's epoch or seed
|
|
166
|
+
* (the beacon left the grant's window, or the draw changed); `session_continuation`: the session
|
|
167
|
+
* cannot cross an epoch; `session_unknown`: no agent session holds this grant; `session_wrong_key`,
|
|
168
|
+
* `session_key_not_bound`, `session_mismatch`, `session_invalid_request`, `session_lifetime`: this
|
|
169
|
+
* session's own refresh is malformed or bound elsewhere, every retry the same. Everything else
|
|
170
|
+
* (`session_rate_limited`, `session_quorum_unmet`, `session_unavailable`, `session_status_window`,
|
|
171
|
+
* untyped answers) is transient: the held grant still serves and the refresh is retried, backing off.
|
|
172
|
+
*
|
|
173
|
+
* One exception: `session_context_changed` is also what a verifier answers when ITS beacon read lags
|
|
174
|
+
* the chain (the grant's epoch ahead of its live epoch) or the continuation epoch's seed is not
|
|
175
|
+
* anchored at it yet (keykeeper-verifier `validate_beacon_draw`), and the agent relays one such
|
|
176
|
+
* signer's code as final. With a `beacon` reader, the session ends on it only when the client's
|
|
177
|
+
* own chain read confirms the grant two epochs behind, or the refusal persists past
|
|
178
|
+
* `contextRetryMs`; until then it is retried as transient (the held grant still serves).
|
|
179
|
+
*/
|
|
180
|
+
export declare const SESSION_REFUSAL_CODES: ReadonlySet<string>;
|
|
181
|
+
/**
|
|
182
|
+
* Session-route refusals the SAME request may pass later (verifier `session_grant.rs`, C24): the
|
|
183
|
+
* held grant still serves and the refresh is retried, never below the answer's `Retry-After`.
|
|
184
|
+
* `session_verifier_behind` (503, NEW): a verifier's chain view trails the grant (its live beacon
|
|
185
|
+
* is older than the grant's epoch, or that epoch's seed is not anchored at its head yet); it
|
|
186
|
+
* passes once the verifier catches up, with no new presentation. Before C24 a verifier answered
|
|
187
|
+
* that as `session_context_changed`, which an up-to-date server now sends only for a definite
|
|
188
|
+
* change (it stays in {@link SESSION_REFUSAL_CODES}, with the chain-confirmed exception for older
|
|
189
|
+
* servers). `session_rate_limited` (429), `session_unavailable`, `session_quorum_unmet` (503,
|
|
190
|
+
* the agent's mixed or older answers) and `session_status_window` are transient as before; any
|
|
191
|
+
* other non-refusal answer stays transient too.
|
|
192
|
+
*/
|
|
193
|
+
export declare const SESSION_RETRYABLE_CODES: ReadonlySet<string>;
|
|
194
|
+
/**
|
|
195
|
+
* The pause before retrying a `session_verifier_behind` refusal that carries no `Retry-After`
|
|
196
|
+
* (the verifier sends 2 s and a current verifier-agent sets or relays it; an older agent relays the
|
|
197
|
+
* code without the header), ms. A Retry-After that is present always wins.
|
|
198
|
+
*/
|
|
199
|
+
export declare const SESSION_VERIFIER_BEHIND_RETRY_MS = 2000;
|
|
200
|
+
/**
|
|
201
|
+
* A transient refresh failure: the held grant is unchanged and still serves until its `exp`.
|
|
202
|
+
* `retryAfterMs` is the agent's `Retry-After`, when it sends one: no verifier-agent or verifier
|
|
203
|
+
* sets it today (2026-11), so the backoff alone paces the retries; the support is kept for when
|
|
204
|
+
* one does.
|
|
205
|
+
*/
|
|
206
|
+
export declare class SessionRefreshError extends TasraError {
|
|
207
|
+
/** HTTP status of the agent's reply. */
|
|
208
|
+
readonly status: number;
|
|
209
|
+
/** The agent's error code, when it sent one. */
|
|
210
|
+
readonly code: string | undefined;
|
|
211
|
+
/** Milliseconds to wait before retrying, when known. */
|
|
212
|
+
readonly retryAfterMs: number | undefined;
|
|
213
|
+
/** Always true: a later refresh may pass. */
|
|
214
|
+
readonly retryable = true;
|
|
215
|
+
constructor(
|
|
216
|
+
/** HTTP status of the agent's reply. */
|
|
217
|
+
status: number,
|
|
218
|
+
/** The agent's error code, when it sent one. */
|
|
219
|
+
code: string | undefined,
|
|
220
|
+
/** Milliseconds to wait before retrying, when known. */
|
|
221
|
+
retryAfterMs: number | undefined);
|
|
222
|
+
}
|
|
223
|
+
/** An accepted, refreshable session grant. */
|
|
224
|
+
export declare class GrantedSession {
|
|
225
|
+
#private;
|
|
226
|
+
/** Lowercase 0x-prefixed 32-byte session id. */
|
|
227
|
+
readonly sessionId: string;
|
|
228
|
+
/** @internal Use {@link acceptSessionGrant} or {@link loadGrantedSession}. */
|
|
229
|
+
constructor(opts: GrantedSessionOptions, sessionId: string, record: SessionRecord);
|
|
230
|
+
/**
|
|
231
|
+
* The current grant on the wire, for keeper requests. Throws once the session ended or the grant
|
|
232
|
+
* is past its deadline. A read is a USE: it keeps the session from going idle.
|
|
233
|
+
*/
|
|
234
|
+
current(): SessionGrantWire;
|
|
235
|
+
/** Verified grant for one slot (re-verified against the slot's anchored committee). */
|
|
236
|
+
verifiedFor(slot: `0x${string}`): Promise<VerifiedSessionGrant>;
|
|
237
|
+
/** The session key bound by this grant. */
|
|
238
|
+
get key(): SessionKeyHandle;
|
|
239
|
+
/**
|
|
240
|
+
* Refresh now: a session-key signature over `(grant_hash, seq, issued_at)` with a fresh seq;
|
|
241
|
+
* the verifiers re-check status, rules, idle and absolute limits and sign a new grant. A typed
|
|
242
|
+
* refusal, a 404 (verifiers without session support) or a local limit ends the session.
|
|
243
|
+
*/
|
|
244
|
+
refresh(): Promise<SessionGrantWire>;
|
|
245
|
+
/** The newest beacon epoch this session has observed, if any. */
|
|
246
|
+
get beaconEpoch(): bigint | undefined;
|
|
247
|
+
/**
|
|
248
|
+
* Report the beacon's latest epoch AS READ FROM THE CHAIN (a payment discovery's `beaconEpoch`,
|
|
249
|
+
* the beacon poll, a fresh `readCurrentBeaconEpoch`). Never pass an epoch a keeper or any other
|
|
250
|
+
* service claims: observations never move backwards, so one inflated value would stall the
|
|
251
|
+
* session until it is presented again. Once it is past the grant's epoch the grant is refreshed in the BACKGROUND
|
|
252
|
+
* ({@link followBeacon}): keepers still admit the current grant for the whole next epoch, so the
|
|
253
|
+
* refresh lands well before the boundary that would end it, and no message waits for it. An
|
|
254
|
+
* observation never moves backwards.
|
|
255
|
+
*/
|
|
256
|
+
observeBeacon(epoch: bigint): void;
|
|
257
|
+
/**
|
|
258
|
+
* Report the beacon's latest epoch and its DRAW epoch AS READ FROM THE CHAIN at one head
|
|
259
|
+
* (`readBeaconDrawState`; the `beacon.drawState` poll does this). As {@link observeBeacon}, and a
|
|
260
|
+
* follow refreshes only once the draw epoch is past the grant's (the agent can continue the
|
|
261
|
+
* session onto it); until then nothing is sent. Observations never move backwards.
|
|
262
|
+
*/
|
|
263
|
+
observeDraw(state: BeaconDrawState): void;
|
|
264
|
+
/** The newest draw epoch observed, if a `beacon.drawState` is configured and has answered. */
|
|
265
|
+
get drawEpoch(): bigint | undefined;
|
|
266
|
+
/**
|
|
267
|
+
* Bring the grant up to the newest observed beacon epoch, one continuation per epoch (the agent
|
|
268
|
+
* continues a session exactly ONE epoch). A refresh that stays on the old epoch (the new epoch's
|
|
269
|
+
* anchors have not landed at the agent) is retried, bounded, while the held grant is still
|
|
270
|
+
* admissible (its epoch the beacon's latest or previous); never past that. Single-flight; resolves
|
|
271
|
+
* `true` when the grant moved, `false` when it was already current. Throws
|
|
272
|
+
* {@link SessionEndedError} when the session cannot continue (present again), and a
|
|
273
|
+
* {@link TasraError} when {@link stop} interrupts it.
|
|
274
|
+
*
|
|
275
|
+
* A caller of this method WAITS for the follow, so while it waits the follow's pauses keep the
|
|
276
|
+
* process alive (a background follow, started by {@link observeBeacon}, never does): a waiter
|
|
277
|
+
* whose only pending work is an unreferenced timer would be dropped when the event loop drains.
|
|
278
|
+
*/
|
|
279
|
+
followBeacon(): Promise<boolean>;
|
|
280
|
+
/**
|
|
281
|
+
* Refresh now if the beacon has moved past the grant's epoch (`beaconEpoch`, e.g.
|
|
282
|
+
* `PaidSessionDecrypt.beaconEpoch`). Keepers admit a grant only while its epoch is the beacon's
|
|
283
|
+
* latest or previous, and the agent continues a session ONE epoch at a time, so a grant must
|
|
284
|
+
* follow the beacon every epoch, not only before its `exp`: wait for a second move and the
|
|
285
|
+
* session needs a new presentation. Resolves `true` when it refreshed, `false` when the grant is
|
|
286
|
+
* already on (or ahead of) that epoch.
|
|
287
|
+
*/
|
|
288
|
+
refreshForEpoch(beaconEpoch: bigint): Promise<boolean>;
|
|
289
|
+
/**
|
|
290
|
+
* Refresh in the background before each grant's `exp`, until stopped or the session ends. With
|
|
291
|
+
* `beacon` configured, also poll the beacon and follow it ({@link observeBeacon}). Background
|
|
292
|
+
* refreshes keep a session alive only while it is USED ({@link current}) within its idle timeout:
|
|
293
|
+
* an unused session reaches the idle timeout and ends (`local-idle`, `onEnded`), so the next use
|
|
294
|
+
* presents again.
|
|
295
|
+
*/
|
|
296
|
+
start(): void;
|
|
297
|
+
/**
|
|
298
|
+
* Stop background refresh and the beacon poll, and interrupt a running beacon follow: its
|
|
299
|
+
* {@link followBeacon} waiters reject at once (`SessionEndedError` when the session ended,
|
|
300
|
+
* otherwise a `TasraError`), never left waiting on a cleared timer.
|
|
301
|
+
*/
|
|
302
|
+
stop(): void;
|
|
303
|
+
/**
|
|
304
|
+
* Revoke at the verifiers (effective at the next refresh; an issued grant runs to its `exp`, at
|
|
305
|
+
* most 45 s), then end locally. The agent answers 204 only once `n - k + 1` members of every draw
|
|
306
|
+
* that could hold the session acknowledged (so the rest can never form a quorum); `503
|
|
307
|
+
* session_revoke_partial` (and a 429/503 busy answer) is retried, each attempt under a fresh
|
|
308
|
+
* durably reserved seq, until `deadlineMs`. The session stops serving the moment revoke starts
|
|
309
|
+
* (journaled), even when the revoke has not completed; call `revoke()` again after a
|
|
310
|
+
* {@link SessionRevokeIncompleteError}. A 404 (the agent holds no session for this grant, so no
|
|
311
|
+
* verifier was asked) ends and disposes the session locally and throws
|
|
312
|
+
* {@link SessionRevokeUnconfirmedError}.
|
|
313
|
+
* @param options - `deadlineMs`: total retry budget (default 30 s, at most 120 s); `sleep` for tests.
|
|
314
|
+
*/
|
|
315
|
+
revoke(options?: {
|
|
316
|
+
deadlineMs?: number;
|
|
317
|
+
sleep?: (ms: number) => Promise<void>;
|
|
318
|
+
}): Promise<void>;
|
|
319
|
+
}
|
|
320
|
+
/**
|
|
321
|
+
* A revoke that has not reached a quorum of every draw yet (`session_revoke_partial`, or the agent
|
|
322
|
+
* stayed busy) within its deadline. The session no longer serves locally; retry `revoke()`.
|
|
323
|
+
*/
|
|
324
|
+
export declare class SessionRevokeIncompleteError extends TasraError {
|
|
325
|
+
/** Always true: the same call may be repeated (each attempt signs a fresh seq). */
|
|
326
|
+
readonly retryable = true;
|
|
327
|
+
/** The agent's last answer (`session_revoke_partial`, `session_rate_limited`, `status 503`, ...). */
|
|
328
|
+
readonly code: string;
|
|
329
|
+
constructor(code: string);
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
* The agent answered 404 to a revoke: it holds no session for this grant, so no verifier was asked
|
|
333
|
+
* and nothing confirmed the revocation. The session was still ended and its key disposed locally,
|
|
334
|
+
* so it can never be refreshed (only this key could); the last issued grant runs to its `exp`.
|
|
335
|
+
*/
|
|
336
|
+
export declare class SessionRevokeUnconfirmedError extends TasraError {
|
|
337
|
+
/** Retrying cannot help: the agent has no session to relay it for. */
|
|
338
|
+
readonly retryable = false;
|
|
339
|
+
/** Always `session_unknown`. */
|
|
340
|
+
readonly code = "session_unknown";
|
|
341
|
+
constructor();
|
|
342
|
+
}
|
|
343
|
+
/**
|
|
344
|
+
* Load a journaled session (same process, same key) after a restart of its owner, e.g. a tab reload with the key kept.
|
|
345
|
+
* @param opts - Lifecycle options; `key` must be the key the grant binds.
|
|
346
|
+
* @param sessionId - 0x-prefixed 32-byte session id.
|
|
347
|
+
*/
|
|
348
|
+
export declare function loadGrantedSession(opts: GrantedSessionOptions, sessionId: string): Promise<GrantedSession>;
|
|
349
|
+
export {};
|