@t3foundry/tasra-sdk 0.3.1-next.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,78 @@
|
|
|
1
|
+
import { type Hex, type PublicClient } from 'viem';
|
|
2
|
+
import { type ClientExecutionSigner } from '../committee/execution.js';
|
|
3
|
+
import { type PaymentIntentWire } from '../committee/payment.js';
|
|
4
|
+
import { type ExecutionRecoveryTarget, type RecoveredExecutionReply, type SignedPaidExecutionReport } from '../committee/recovery.js';
|
|
5
|
+
import { type ExpectedPaidOperation, type KeeperExecutionRecoveryObservation, type PaidKeeperEndpoint, type PaidKeeperTransportOptions, type PrepaidDeployment } from './prepaid.js';
|
|
6
|
+
/** Bounded keeper responses; no body text is included in transport errors. */
|
|
7
|
+
export interface KeeperRecoveryHttpResponse {
|
|
8
|
+
/** Observed status; a refusal is never permission to execute or reserve again. */
|
|
9
|
+
status: number;
|
|
10
|
+
/** Exact bounded response bytes. Completed results are private; never log them. */
|
|
11
|
+
body: Uint8Array;
|
|
12
|
+
/** Parsed `Retry-After` in ms, when the keeper sent one. */
|
|
13
|
+
retryAfterMs?: number;
|
|
14
|
+
}
|
|
15
|
+
/** Client-approved transport for public evidence and authenticated retained-result reads. */
|
|
16
|
+
export interface KeeperRecoveryTransport {
|
|
17
|
+
/** TLS and socket destination policy, no redirects, no automatic resends, bounded cancellation. */
|
|
18
|
+
keeperRecoveryRequest(url: string, options: {
|
|
19
|
+
/** Complete locally constructed JSON; recovery contains only public payment and a fresh client signature. */
|
|
20
|
+
body: Uint8Array;
|
|
21
|
+
/** Bound checked while receiving, including responses without Content-Length. */
|
|
22
|
+
maxBytes: number;
|
|
23
|
+
/** Caller-owned cancellation plus the SDK's total recovery deadline. */
|
|
24
|
+
signal: AbortSignal;
|
|
25
|
+
}): Promise<KeeperRecoveryHttpResponse>;
|
|
26
|
+
}
|
|
27
|
+
/** Result disclosed only after original canonical payment and exact-byte commitment checks. */
|
|
28
|
+
export interface RecoveredKeeperExecution {
|
|
29
|
+
/** Original history; its accepted-time policy grants no fresh execution permission. */
|
|
30
|
+
observation: KeeperExecutionRecoveryObservation;
|
|
31
|
+
/** Signed original completed work evidence. */
|
|
32
|
+
execution: SignedPaidExecutionReport;
|
|
33
|
+
/** Operation-specific retained result encoding. */
|
|
34
|
+
encoding: RecoveredExecutionReply['encoding'];
|
|
35
|
+
/** Exact JSON bytes as a string, authenticated before exposure; may differ from the original HTTP envelope. */
|
|
36
|
+
resultJson: string;
|
|
37
|
+
}
|
|
38
|
+
/** Safe status error without private result text; no failed read triggers paid work. */
|
|
39
|
+
export declare class KeeperRecoveryError extends Error {
|
|
40
|
+
/** Observed original keeper response status. */ readonly httpStatus: number;
|
|
41
|
+
/** Keeper-requested wait before reading again, in ms, when sent. */ readonly retryAfterMs?: number | undefined;
|
|
42
|
+
constructor(
|
|
43
|
+
/** Observed original keeper response status. */ httpStatus: number,
|
|
44
|
+
/** Keeper-requested wait before reading again, in ms, when sent. */ retryAfterMs?: number | undefined);
|
|
45
|
+
}
|
|
46
|
+
/** Immutable local recovery intent and explicitly approved network capabilities. */
|
|
47
|
+
export interface RecoverKeeperExecutionOptions {
|
|
48
|
+
/** Trusted bounded EIP-1898 RPC client for the independently selected chain. */
|
|
49
|
+
client: PublicClient;
|
|
50
|
+
/** Approved chain and contract addresses. */
|
|
51
|
+
deployment: PrepaidDeployment;
|
|
52
|
+
/** Original creator payment retained before submission. */
|
|
53
|
+
payment: PaymentIntentWire;
|
|
54
|
+
/** Independently intended slot, action and payload digest. */
|
|
55
|
+
expected: ExpectedPaidOperation;
|
|
56
|
+
/** Original assigned worker endpoint retained at submission, not downloaded from its response. */
|
|
57
|
+
keeper: PaidKeeperEndpoint;
|
|
58
|
+
/** Original paid stage and creator-certified client public key retained before submission. */
|
|
59
|
+
target: Omit<ExecutionRecoveryTarget, 'operatorKey'>;
|
|
60
|
+
/** Original client-only execution signer; its private seed is never sent. */
|
|
61
|
+
signer: ClientExecutionSigner;
|
|
62
|
+
/** Caller-approved guarded transport; Node applications can use createNodeKeeperRecoveryTransport. */
|
|
63
|
+
transport: KeeperRecoveryTransport;
|
|
64
|
+
/** Explicit local HTTP endpoint policy; never permits HTTP on official Fuji. */
|
|
65
|
+
transportPolicy?: PaidKeeperTransportOptions;
|
|
66
|
+
/** Optional cancellation. The complete read, RPC and signature flow also has a 60-second deadline. */
|
|
67
|
+
signal?: AbortSignal;
|
|
68
|
+
/** Optional nonzero local correlation nonce for a deterministic authenticated read. */
|
|
69
|
+
nonce?: Hex;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Read completed keeper results without resubmitting payment, key work, nonce preparation or closure.
|
|
73
|
+
* Authenticate the worker report and original canonical reserved history before requesting a fresh
|
|
74
|
+
* client signature. Then independently verify returned evidence and exact result bytes. Missing,
|
|
75
|
+
* failed, interrupted, orphaned or unavailable history is a refusal, never an automatic retry of work.
|
|
76
|
+
* @param options Locally retained original intent, client signer and approved read capabilities.
|
|
77
|
+
*/
|
|
78
|
+
export declare function recoverKeeperExecution(options: RecoverKeeperExecutionOptions): Promise<RecoveredKeeperExecution>;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { MAX_EXECUTION_BODY_BYTES } from '../committee/execution.js';
|
|
2
|
+
import { assertPaymentIntentWire } from '../committee/payment.js';
|
|
3
|
+
import { createExecutionRecoveryAuthorization, paidExecutionRequest, verifyRecoveredExecutionResult } from '../committee/recovery.js';
|
|
4
|
+
import { parseExecutionJson } from '../committee/recoveryJson.js';
|
|
5
|
+
import { protocolHex } from '../committee/receipts.js';
|
|
6
|
+
import { readKeeperExecutionRecoveryPolicy } from './prepaid.js';
|
|
7
|
+
/** Safe status error without private result text; no failed read triggers paid work. */
|
|
8
|
+
export class KeeperRecoveryError extends Error {
|
|
9
|
+
httpStatus;
|
|
10
|
+
retryAfterMs;
|
|
11
|
+
constructor(
|
|
12
|
+
/** Observed original keeper response status. */ httpStatus,
|
|
13
|
+
/** Keeper-requested wait before reading again, in ms, when sent. */ retryAfterMs) {
|
|
14
|
+
super(`Keeper result recovery returned HTTP ${httpStatus}`);
|
|
15
|
+
this.httpStatus = httpStatus;
|
|
16
|
+
this.retryAfterMs = retryAfterMs;
|
|
17
|
+
this.name = 'KeeperRecoveryError';
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function endpoint(keeper, deployment, policy) {
|
|
21
|
+
protocolHex(keeper.operator, 20, 'retained keeper operator');
|
|
22
|
+
protocolHex(keeper.publicKey, 32, 'retained keeper key');
|
|
23
|
+
if (keeper.url.length > 512)
|
|
24
|
+
throw new Error('Invalid retained keeper endpoint');
|
|
25
|
+
const url = new URL(keeper.url);
|
|
26
|
+
const local = ['localhost', '127.0.0.1', '[::1]'].includes(url.hostname);
|
|
27
|
+
if (url.username || url.password || url.search || url.hash
|
|
28
|
+
|| (url.protocol !== 'https:' && !(deployment.chainId === 43112 && policy.allowLocalHttp === true && local && url.protocol === 'http:')))
|
|
29
|
+
throw new Error('Invalid retained keeper transport policy');
|
|
30
|
+
return url.toString().replace(/\/$/, '');
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Read completed keeper results without resubmitting payment, key work, nonce preparation or closure.
|
|
34
|
+
* Authenticate the worker report and original canonical reserved history before requesting a fresh
|
|
35
|
+
* client signature. Then independently verify returned evidence and exact result bytes. Missing,
|
|
36
|
+
* failed, interrupted, orphaned or unavailable history is a refusal, never an automatic retry of work.
|
|
37
|
+
* @param options Locally retained original intent, client signer and approved read capabilities.
|
|
38
|
+
*/
|
|
39
|
+
export async function recoverKeeperExecution(options) {
|
|
40
|
+
assertPaymentIntentWire(options.payment);
|
|
41
|
+
const payment = structuredClone(options.payment), deployment = { ...options.deployment }, expected = { ...options.expected };
|
|
42
|
+
const keeper = { ...options.keeper }, target = { ...options.target, operatorKey: keeper.publicKey };
|
|
43
|
+
const client = options.client, signer = options.signer, transport = options.transport, policy = { ...options.transportPolicy }, nonce = options.nonce;
|
|
44
|
+
const base = endpoint(keeper, deployment, policy);
|
|
45
|
+
const controller = new AbortController(), active = options.signal ? AbortSignal.any([options.signal, controller.signal]) : controller.signal;
|
|
46
|
+
const timer = setTimeout(() => controller.abort(new Error('Keeper result recovery deadline exceeded')), 60_000);
|
|
47
|
+
let abort = () => { };
|
|
48
|
+
const work = async () => {
|
|
49
|
+
active.throwIfAborted();
|
|
50
|
+
const request = paidExecutionRequest(payment);
|
|
51
|
+
const query = new TextEncoder().encode(JSON.stringify({ request, stage: target.stage }));
|
|
52
|
+
const evidence = await transport.keeperRecoveryRequest(base + '/v1/prepaid/execution', { body: query, maxBytes: 65_536, signal: active });
|
|
53
|
+
active.throwIfAborted();
|
|
54
|
+
if (evidence.status !== 200)
|
|
55
|
+
throw new KeeperRecoveryError(evidence.status, evidence.retryAfterMs);
|
|
56
|
+
const execution = parseExecutionJson(evidence.body, 65_536);
|
|
57
|
+
const observation = await readKeeperExecutionRecoveryPolicy(client, deployment, payment, expected, target, execution, policy);
|
|
58
|
+
active.throwIfAborted();
|
|
59
|
+
// The retained endpoint is itself a client-approved network destination; the original operator identity must match.
|
|
60
|
+
if (observation.keeper.operator.toLowerCase() !== keeper.operator.toLowerCase())
|
|
61
|
+
throw new Error('Retained keeper differs from original canonical operator');
|
|
62
|
+
const authorization = await createExecutionRecoveryAuthorization({ payment, policy: observation.policy, target, execution, signer,
|
|
63
|
+
nowSecs: Math.floor(Date.now() / 1000), nonce });
|
|
64
|
+
active.throwIfAborted();
|
|
65
|
+
// result_json is a JSON string; escaping a maximum-size result may require six bytes per source byte.
|
|
66
|
+
const maxReplyBytes = 6 * MAX_EXECUTION_BODY_BYTES + 65_536;
|
|
67
|
+
const body = new TextEncoder().encode(JSON.stringify({ payment, authorization }));
|
|
68
|
+
const response = await transport.keeperRecoveryRequest(base + '/v1/prepaid/execution/recover', { body, maxBytes: maxReplyBytes, signal: active });
|
|
69
|
+
active.throwIfAborted();
|
|
70
|
+
if (response.status !== 200)
|
|
71
|
+
throw new KeeperRecoveryError(response.status, response.retryAfterMs);
|
|
72
|
+
const reply = parseExecutionJson(response.body, maxReplyBytes);
|
|
73
|
+
const resultJson = await verifyRecoveredExecutionResult({ payment, policy: observation.policy, target, expectedExecution: execution, reply });
|
|
74
|
+
active.throwIfAborted();
|
|
75
|
+
return { observation, execution: reply.execution, encoding: reply.encoding, resultJson };
|
|
76
|
+
};
|
|
77
|
+
try {
|
|
78
|
+
active.throwIfAborted();
|
|
79
|
+
return await Promise.race([work(), new Promise((_, reject) => {
|
|
80
|
+
abort = () => reject(active.reason);
|
|
81
|
+
active.addEventListener('abort', abort, { once: true });
|
|
82
|
+
if (active.aborted)
|
|
83
|
+
abort();
|
|
84
|
+
})]);
|
|
85
|
+
}
|
|
86
|
+
finally {
|
|
87
|
+
clearTimeout(timer);
|
|
88
|
+
active.removeEventListener('abort', abort);
|
|
89
|
+
controller.abort();
|
|
90
|
+
}
|
|
91
|
+
}
|
package/dist/chain/node.d.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { RegisteredAgentSession } from './registeredAgent.js';
|
|
2
2
|
import type { AgentTransport } from './registeredAgent.js';
|
|
3
|
+
import type { PaidAgentTransport } from './paidAgentTransport.js';
|
|
4
|
+
import type { KeeperRecoveryTransport } from './keeperRecovery.js';
|
|
3
5
|
import type { RelayTransport } from './registeredRelay.js';
|
|
4
|
-
import {
|
|
6
|
+
import type { ServiceDiscoveryTransport } from './serviceIdentity.js';
|
|
5
7
|
/**
|
|
6
8
|
* Conservative globally routable destinations; special-purpose exceptions require explicit policy.
|
|
7
9
|
* @param address IPv4 or IPv6 address resolved for the service destination.
|
|
@@ -36,6 +38,27 @@ export declare function createNodeRelayTransport(policy?: ServiceTransportPolicy
|
|
|
36
38
|
* @param policy Explicit private-host exceptions and additional trusted certificate roots.
|
|
37
39
|
*/
|
|
38
40
|
export declare function createNodeAgentTransport(policy?: ServiceTransportPolicy): AgentTransport;
|
|
41
|
+
/**
|
|
42
|
+
* Guarded paid-session creation and owner control, preserving HTTP consent/recovery statuses.
|
|
43
|
+
* @param policy Client-approved private hosts and additional CA roots; TLS verification stays enabled.
|
|
44
|
+
*/
|
|
45
|
+
export declare function createNodePaidAgentTransport(policy?: ServiceTransportPolicy): PaidAgentTransport;
|
|
46
|
+
/** Options for {@link createNodeKeeperRecoveryTransport}. */
|
|
47
|
+
export interface NodeKeeperRecoveryTransportPolicy extends ServiceTransportPolicy {
|
|
48
|
+
/**
|
|
49
|
+
* Local development fleet: also permit plain HTTP to loopback names, private IP literals and
|
|
50
|
+
* `allowedPrivateHosts` (and only those), resolving only to non-public addresses, with the same
|
|
51
|
+
* route checks as HTTPS. Default false: HTTPS only. The recovery reads separately permit HTTP
|
|
52
|
+
* only on the local development chain (43112) with the paid operation's `allowLocalHttp`.
|
|
53
|
+
*/
|
|
54
|
+
allowLocalHttp?: boolean;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Guarded completed-result reads using the same socket-bound destination and verified TLS policy.
|
|
58
|
+
* Only the two POST evidence/recovery paths are permitted; this transport cannot submit key work.
|
|
59
|
+
* @param policy Exact client-approved private hosts, additional CA roots and local development HTTP.
|
|
60
|
+
*/
|
|
61
|
+
export declare function createNodeKeeperRecoveryTransport(policy?: NodeKeeperRecoveryTransportPolicy): KeeperRecoveryTransport;
|
|
39
62
|
/**
|
|
40
63
|
* Wallet protocol requests restricted to the selected session and approved DID, with socket checks.
|
|
41
64
|
* @param session Authenticated session whose request, response and DID URLs are allowed.
|
package/dist/chain/node.js
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
/** Node-only service discovery transport; never imported by the browser-safe chain barrel. */
|
|
2
2
|
import { didWebUrl } from '../oid4vp/did-web.js';
|
|
3
|
+
import { parseRetryAfter } from '../internal/retryAfter.js';
|
|
3
4
|
import { lookup } from 'node:dns';
|
|
4
5
|
import { request } from 'node:https';
|
|
5
|
-
import {
|
|
6
|
+
import { request as plainRequest } from 'node:http';
|
|
7
|
+
import { createSecureContext, rootCertificates } from 'node:tls';
|
|
8
|
+
import { BoundedCache } from '../internal/bounded.js';
|
|
6
9
|
import { BlockList, isIP } from 'node:net';
|
|
7
|
-
import {
|
|
10
|
+
import { acceptsServiceResponse, serviceRequestShape } from './serviceRequestPolicy.js';
|
|
8
11
|
const denied = new BlockList();
|
|
9
12
|
for (const [address, prefix] of [
|
|
10
13
|
['0.0.0.0', 8], ['10.0.0.0', 8], ['100.64.0.0', 10], ['127.0.0.0', 8],
|
|
@@ -17,6 +20,19 @@ for (const [address, prefix] of [['2001::', 23], ['2001:db8::', 32], ['2002::',
|
|
|
17
20
|
denied.addSubnet(address, prefix, 'ipv6');
|
|
18
21
|
const globalV6 = new BlockList();
|
|
19
22
|
globalV6.addSubnet('2000::', 3, 'ipv6');
|
|
23
|
+
// Building a SecureContext parses every bundled root plus the deployment CAs: a few ms of CPU per
|
|
24
|
+
// request when each connection built its own. One context per exact CA set (keyed by the complete
|
|
25
|
+
// CA bytes, never a name) is shared; verification stays per connection (rejectUnauthorized, hostname).
|
|
26
|
+
const secureContexts = new BoundedCache(16);
|
|
27
|
+
function trustContext(ca) {
|
|
28
|
+
const extra = Array.isArray(ca) ? ca : [ca];
|
|
29
|
+
const key = JSON.stringify(extra.map(c => typeof c === 'string' ? ['s', c] : ['b', c.toString('base64')]));
|
|
30
|
+
return secureContexts.getOrCompute(key, () => createSecureContext({ ca: [...rootCertificates, ...extra] }));
|
|
31
|
+
}
|
|
32
|
+
/** A loopback name or a non-public IP literal (plain local-development HTTP only). */
|
|
33
|
+
function localName(host) {
|
|
34
|
+
return host === 'localhost' || host.endsWith('.localhost') || (isIP(host) !== 0 && !isPublicServiceAddress(host));
|
|
35
|
+
}
|
|
20
36
|
/**
|
|
21
37
|
* Conservative globally routable destinations; special-purpose exceptions require explicit policy.
|
|
22
38
|
* @param address IPv4 or IPv6 address resolved for the service destination.
|
|
@@ -47,7 +63,8 @@ export function createNodeServiceStatusTransport(policy = {}) {
|
|
|
47
63
|
export function createNodeRelayTransport(policy = {}) {
|
|
48
64
|
const discovery = guardedTransport(policy, 'discovery');
|
|
49
65
|
const relay = guardedTransport(policy, 'relay');
|
|
50
|
-
return { ...discovery, relayRequest: relay.request
|
|
66
|
+
return { ...discovery, relayRequest: relay.request,
|
|
67
|
+
relayExchange: (url, options) => relay.request(url, { ...options, full: true }) };
|
|
51
68
|
}
|
|
52
69
|
/**
|
|
53
70
|
* Session secrets use this same guarded connection and can only travel to a session GET.
|
|
@@ -56,7 +73,30 @@ export function createNodeRelayTransport(policy = {}) {
|
|
|
56
73
|
export function createNodeAgentTransport(policy = {}) {
|
|
57
74
|
const discovery = guardedTransport(policy, 'discovery');
|
|
58
75
|
const agent = guardedTransport(policy, 'agent');
|
|
59
|
-
return { ...discovery, agentRequest: agent.request
|
|
76
|
+
return { ...discovery, agentRequest: agent.request,
|
|
77
|
+
agentExchange: (url, options) => agent.request(url, { ...options, full: true }) };
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Guarded paid-session creation and owner control, preserving HTTP consent/recovery statuses.
|
|
81
|
+
* @param policy Client-approved private hosts and additional CA roots; TLS verification stays enabled.
|
|
82
|
+
*/
|
|
83
|
+
export function createNodePaidAgentTransport(policy = {}) {
|
|
84
|
+
const discovery = guardedTransport(policy, 'discovery');
|
|
85
|
+
const paid = guardedTransport(policy, 'paid-agent');
|
|
86
|
+
return { ...discovery, paidAgentRequest: (url, options) => {
|
|
87
|
+
if (options.body && options.body.length > 2 * 1024 * 1024)
|
|
88
|
+
throw new Error('Invalid service HTTP bounds');
|
|
89
|
+
return paid.request(url, { ...options, body: options.body?.slice() });
|
|
90
|
+
} };
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Guarded completed-result reads using the same socket-bound destination and verified TLS policy.
|
|
94
|
+
* Only the two POST evidence/recovery paths are permitted; this transport cannot submit key work.
|
|
95
|
+
* @param policy Exact client-approved private hosts, additional CA roots and local development HTTP.
|
|
96
|
+
*/
|
|
97
|
+
export function createNodeKeeperRecoveryTransport(policy = {}) {
|
|
98
|
+
const recovery = guardedTransport(policy, 'keeper-recovery', policy.allowLocalHttp === true);
|
|
99
|
+
return { keeperRecoveryRequest: (url, options) => recovery.request(url, { ...options, method: 'POST', body: options.body.slice() }) };
|
|
60
100
|
}
|
|
61
101
|
/**
|
|
62
102
|
* Wallet protocol requests restricted to the selected session and approved DID, with socket checks.
|
|
@@ -79,44 +119,30 @@ export function createNodeAgentWalletFetch(session, policy = {}) {
|
|
|
79
119
|
if (post && typeof init?.body !== 'string' || !post && init?.body != null)
|
|
80
120
|
throw new Error('Invalid wallet request body');
|
|
81
121
|
const signal = init?.signal ?? AbortSignal.timeout(30_000);
|
|
82
|
-
const
|
|
83
|
-
return new Response(new TextDecoder('utf-8', { fatal: true }).decode(
|
|
122
|
+
const response = await transport.request(url, { body: post ? new TextEncoder().encode(init.body) : undefined, maxBytes: post ? 16_384 : 65_536, signal });
|
|
123
|
+
return new Response(new TextDecoder('utf-8', { fatal: true }).decode(response.body), { status: response.status, headers: { 'content-type': url === requestUri ? 'application/oauth-authz-req+jwt' : 'application/json' } });
|
|
84
124
|
};
|
|
85
125
|
}
|
|
86
|
-
function guardedTransport(policy, mode) {
|
|
87
|
-
const relay = mode === 'relay', agent = mode === 'agent', wallet = mode === 'wallet'
|
|
126
|
+
function guardedTransport(policy, mode, localHttp = false) {
|
|
127
|
+
const relay = mode === 'relay', agent = mode === 'agent', wallet = mode === 'wallet';
|
|
128
|
+
const paid = mode === 'paid-agent';
|
|
129
|
+
const recovery = mode === 'keeper-recovery';
|
|
88
130
|
const allowed = new Set(policy.allowedPrivateHosts ?? []);
|
|
89
131
|
// Snapshot mutable caller configuration before the first asynchronous request.
|
|
90
132
|
const ca = Array.isArray(policy.ca) ? policy.ca.map(c => typeof c === 'string' ? c : Buffer.from(c))
|
|
91
133
|
: typeof policy.ca === 'string' || policy.ca === undefined ? policy.ca : Buffer.from(policy.ca);
|
|
92
134
|
return {
|
|
93
|
-
request(url, { body, maxBytes, signal, bearer }) {
|
|
135
|
+
request(url, { body, maxBytes, signal, bearer, method, oauth, full }) {
|
|
94
136
|
signal.throwIfAborted();
|
|
95
|
-
if (!Number.isSafeInteger(maxBytes) || maxBytes < 1 || maxBytes > (agent || wallet ? 1_048_576 : relay ? 4_096 : 16_384) || body && body.length > (wallet ? 1_048_576 : agent || relay ? 65_536 : 2_048))
|
|
96
|
-
throw new Error('Invalid service HTTP bounds');
|
|
97
|
-
// The registry's 512-byte limit applies to the base, excluding appended protocol paths.
|
|
98
|
-
const relaySuffix = url.match(/\/v1\/relay\/(forward|0x[0-9a-f]{64})$/)?.[0];
|
|
99
|
-
if (relay && (!relaySuffix || Boolean(body) !== relaySuffix.endsWith('/forward')))
|
|
100
|
-
throw new Error('Invalid relay path or method');
|
|
101
|
-
const agentSuffix = url.match(/\/v1\/sessions(?:\/[0-9a-f]{64})?$/)?.[0];
|
|
102
|
-
if (agent && (!agentSuffix || (body ? agentSuffix !== '/v1/sessions' || bearer !== undefined : agentSuffix === '/v1/sessions' || !/^[0-9a-f]{64}$/.test(bearer ?? ''))))
|
|
103
|
-
throw new Error('Invalid agent path, method or poll secret');
|
|
104
|
-
if (!agent && bearer !== undefined)
|
|
105
|
-
throw new Error('Bearer is only allowed for agent polling');
|
|
106
|
-
const walletSuffix = url.match(/(?:\/\.well-known\/did\.json|\/v1\/request\/[0-9a-f]{64}|\/v1\/response\?session=[0-9a-f]{64})$/)?.[0];
|
|
107
|
-
if (wallet && (!walletSuffix || Boolean(body) !== walletSuffix.startsWith('/v1/response?session=')))
|
|
108
|
-
throw new Error('Invalid wallet path or method');
|
|
109
|
-
const statusSuffix = url.match(/(?:\/readyz|\/v1\/relay\/policy)$/)?.[0];
|
|
110
|
-
if (status && (!statusSuffix || body !== undefined))
|
|
111
|
-
throw new Error('Invalid service status path or method');
|
|
112
|
-
const contentType = status && statusSuffix === '/readyz' ? 'text/plain' : wallet && !body && !url.endsWith('/did.json') ? 'application/oauth-authz-req+jwt' : 'application/json';
|
|
113
|
-
const responseTypes = wallet && walletSuffix === '/.well-known/did.json'
|
|
114
|
-
? ['application/json', 'application/did+json', 'application/did+ld+json'] : [contentType];
|
|
115
|
-
const suffix = status ? statusSuffix : wallet ? walletSuffix : agent ? agentSuffix : relay ? relaySuffix : [SERVICE_MANIFEST_PATH, SERVICE_IDENTITY_PATH].find(path => url.endsWith(path));
|
|
116
|
-
validateServiceEndpoint(suffix ? url.slice(0, -suffix.length) : url);
|
|
117
137
|
const parsed = new URL(url);
|
|
118
138
|
const host = parsed.hostname.replace(/^\[|\]$/g, '');
|
|
119
|
-
|
|
139
|
+
// Local development HTTP: only to a loopback name, a private IP literal or an approved private
|
|
140
|
+
// host, checked with the same route policy as its HTTPS form; every answer must be non-public.
|
|
141
|
+
const plain = localHttp && parsed.protocol === 'http:' && (localName(host) || allowed.has(host));
|
|
142
|
+
const shape = serviceRequestShape(mode, plain ? 'https:' + url.slice('http:'.length) : url, { body, maxBytes, bearer, method, oauth });
|
|
143
|
+
if (parsed.protocol !== 'https:' && !plain)
|
|
144
|
+
throw new Error('Service destination policy requires HTTPS');
|
|
145
|
+
const permits = (address) => plain ? !isPublicServiceAddress(address) : allowed.has(host) || isPublicServiceAddress(address);
|
|
120
146
|
if (isIP(host) && !permits(host))
|
|
121
147
|
throw new Error('Service destination policy refuses address');
|
|
122
148
|
const checkedLookup = (hostname, options, callback) => {
|
|
@@ -137,18 +163,24 @@ function guardedTransport(policy, mode) {
|
|
|
137
163
|
});
|
|
138
164
|
};
|
|
139
165
|
return new Promise((resolve, reject) => {
|
|
140
|
-
const
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
166
|
+
const common = { method: shape.method, agent: false, lookup: checkedLookup, signal, maxHeaderSize: 8_192,
|
|
167
|
+
headers: { ...shape.headers, 'accept-encoding': 'identity', ...(body ? { 'content-length': body.length } : {}) } };
|
|
168
|
+
// Inside the executor: a malformed CA still rejects this request, as when tls.connect parsed it.
|
|
169
|
+
const trust = plain || ca === undefined ? undefined : trustContext(ca);
|
|
170
|
+
const req = plain ? plainRequest(parsed, common, res => respond(res)) : request(parsed, { ...common,
|
|
171
|
+
...(trust === undefined ? {} : { secureContext: trust }), rejectUnauthorized: true,
|
|
172
|
+
}, res => respond(res));
|
|
173
|
+
function respond(res) {
|
|
145
174
|
const fail = (error) => { reject(error); req.destroy(error); };
|
|
146
|
-
|
|
147
|
-
|
|
175
|
+
const noContent = paid && res.statusCode === 204;
|
|
176
|
+
const receivedType = res.headers['content-type']?.split(';')[0]?.trim().toLowerCase() ?? '';
|
|
177
|
+
if (!acceptsServiceResponse(mode, shape, Boolean(body), res.statusCode ?? 0, receivedType, agent && Boolean(full)) || res.headers['content-encoding'] && res.headers['content-encoding'] !== 'identity') {
|
|
178
|
+
// The status and type name the refusal without any body bytes (certification run 39).
|
|
179
|
+
fail(new Error(`Service HTTP status, content type or encoding refused (HTTP ${res.statusCode ?? 0}, ${receivedType || 'no content type'})`));
|
|
148
180
|
return;
|
|
149
181
|
}
|
|
150
182
|
const advertised = res.headers['content-length'];
|
|
151
|
-
if (advertised && (!/^\d+$/.test(advertised) || Number(advertised) > maxBytes)) {
|
|
183
|
+
if (advertised && (!/^\d+$/.test(advertised) || Number(advertised) > maxBytes || noContent && Number(advertised) !== 0)) {
|
|
152
184
|
fail(new Error('Service response too large'));
|
|
153
185
|
return;
|
|
154
186
|
}
|
|
@@ -163,10 +195,23 @@ function guardedTransport(policy, mode) {
|
|
|
163
195
|
chunks.push(chunk);
|
|
164
196
|
});
|
|
165
197
|
res.on('error', reject);
|
|
166
|
-
res.on('end', () =>
|
|
167
|
-
|
|
198
|
+
res.on('end', () => {
|
|
199
|
+
if (noContent && size !== 0) {
|
|
200
|
+
fail(new Error('Unexpected paid agent response body'));
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
const bytes = Buffer.concat(chunks, size);
|
|
204
|
+
const header = res.headers['retry-after'], retryAfterMs = parseRetryAfter(Array.isArray(header) ? undefined : header);
|
|
205
|
+
// Paid replies also carry the raw wait headers, parsed strictly by the paid pacer. A
|
|
206
|
+
// repeated non-standard header arrives comma-joined (or as an array) and is ignored there.
|
|
207
|
+
const governor = res.headers['x-ratelimit-after'];
|
|
208
|
+
const raw = paid ? { ...(typeof header === 'string' ? { retryAfter: header } : {}),
|
|
209
|
+
...(governor !== undefined ? { rateLimitAfter: Array.isArray(governor) ? governor.join(', ') : governor } : {}) } : {};
|
|
210
|
+
resolve(paid || recovery || wallet || ((relay || agent) && full) ? { status: res.statusCode, body: bytes, ...(retryAfterMs !== undefined ? { retryAfterMs } : {}), ...raw } : bytes);
|
|
211
|
+
});
|
|
212
|
+
}
|
|
168
213
|
// Absolute request deadline also bounds DNS/TLS and slow trickle responses.
|
|
169
|
-
const timer = setTimeout(() => req.destroy(new Error('Service HTTP timed out')), agent || wallet ? 30_000 : 5_000);
|
|
214
|
+
const timer = setTimeout(() => req.destroy(new Error('Service HTTP timed out')), paid || recovery || agent || wallet ? 30_000 : 5_000);
|
|
170
215
|
req.on('close', () => clearTimeout(timer));
|
|
171
216
|
req.on('error', reject);
|
|
172
217
|
req.end(body);
|
package/dist/chain/offchain.d.ts
CHANGED
|
@@ -27,6 +27,8 @@ export interface NodeInfo {
|
|
|
27
27
|
rate_limit_enabled?: boolean;
|
|
28
28
|
/** Whether the keeper reports administrative scope checks as enabled. */
|
|
29
29
|
admin_scope_enabled?: boolean;
|
|
30
|
+
/** Separate admin-key verification, or administrative routes awaiting operator configuration. Missing on older keepers. */
|
|
31
|
+
admin_auth?: 'separate' | 'unconfigured';
|
|
30
32
|
[k: string]: unknown;
|
|
31
33
|
}
|
|
32
34
|
/**
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { ServiceDiscoveryTransport } from './serviceIdentity.js';
|
|
2
|
+
/** Bounded response from the original approved agent; non-success is never a retry instruction. */
|
|
3
|
+
export interface PaidAgentHttpResponse {
|
|
4
|
+
/** Observed HTTP status, including consent waits and unknown-delivery failures. */
|
|
5
|
+
status: number;
|
|
6
|
+
/** Exact bounded bytes; never log credentials or bearer-bearing creation bodies. */
|
|
7
|
+
body: Uint8Array;
|
|
8
|
+
/** Parsed `Retry-After` in ms, when the service sent one. A wait hint, never a resend instruction. */
|
|
9
|
+
retryAfterMs?: number;
|
|
10
|
+
/**
|
|
11
|
+
* Raw `Retry-After` header value, when sent. With {@link PaidAgentHttpResponse.rateLimitAfter} it
|
|
12
|
+
* is parsed strictly (integer seconds) to pace a definite 429/503 refusal of a repeatable request.
|
|
13
|
+
*/
|
|
14
|
+
retryAfter?: string;
|
|
15
|
+
/** Raw `x-ratelimit-after` header value (the agent's per-client limiter), when sent. */
|
|
16
|
+
rateLimitAfter?: string;
|
|
17
|
+
}
|
|
18
|
+
/** Transport for client-owned session initialization, consent and continuation. */
|
|
19
|
+
export interface PaidAgentTransport extends ServiceDiscoveryTransport {
|
|
20
|
+
/** Require verified TLS, connection-time destination checks, no redirects and cancellation. */
|
|
21
|
+
paidAgentRequest(url: string, options: {
|
|
22
|
+
/** Explicit method, including bodyless refusal/continuation POSTs. */
|
|
23
|
+
method: 'GET' | 'POST';
|
|
24
|
+
/** Complete client-built JSON bytes, when this route accepts a body. */
|
|
25
|
+
body?: Uint8Array;
|
|
26
|
+
/** Owner bearer only on authenticated session control paths. */
|
|
27
|
+
bearer?: string;
|
|
28
|
+
/** Exact OAuth artifacts; permitted only on the original session's OAuth-response POST. */
|
|
29
|
+
oauth?: {
|
|
30
|
+
accessToken: string;
|
|
31
|
+
proof: string;
|
|
32
|
+
};
|
|
33
|
+
/** Maximum response bytes; caller must also validate the protocol envelope. */
|
|
34
|
+
maxBytes: number;
|
|
35
|
+
/** Cancellation and deadline owned by the client. */
|
|
36
|
+
signal: AbortSignal;
|
|
37
|
+
}): Promise<PaidAgentHttpResponse>;
|
|
38
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { type Address, type Hex, type PublicClient } from 'viem';
|
|
2
|
+
import { TasraError } from '../errors.js';
|
|
3
|
+
/**
|
|
4
|
+
* D8 (2026-10-09): a paid verification epoch is admissible iff it was current or previous at
|
|
5
|
+
* the reservation's stored quote block (`Settlement.prepaidAssignmentBlock`), the window the
|
|
6
|
+
* accountant quorum enforced when it signed the reservation. Mirrors Rust
|
|
7
|
+
* `keykeeper_eth::paid_epoch` in its constants and decisions; keep the two in step.
|
|
8
|
+
* An unpaid draw is not judged here: it keeps the live `{latest, latest - 1}` window.
|
|
9
|
+
*/
|
|
10
|
+
/** Longest a creator's payment intent may live (`expires - now`). Rust `PAYMENT_INTENT_MAX_LIFETIME_SECS`. */
|
|
11
|
+
export declare const PAYMENT_INTENT_MAX_LIFETIME_SECS = 3600n;
|
|
12
|
+
/** Oldest quote block a reservation signer approves over. Rust `RESERVATION_QUOTE_MAX_AGE_SECS`. */
|
|
13
|
+
export declare const RESERVATION_QUOTE_MAX_AGE_SECS = 30n;
|
|
14
|
+
/**
|
|
15
|
+
* Signed submission window (`deadline = min(quote_ts + this, expires)`), enforced by the signers
|
|
16
|
+
* and `Settlement` only; not derivable from the assignment block and not re-proved here.
|
|
17
|
+
* Rust `RESERVATION_SUBMISSION_WINDOW_SECS`.
|
|
18
|
+
*/
|
|
19
|
+
export declare const RESERVATION_SUBMISSION_WINDOW_SECS = 120n;
|
|
20
|
+
/** How far a fresh observation's block time may lead the consumer clock. Rust `OBSERVATION_MAX_FUTURE_SKEW_SECS`. */
|
|
21
|
+
export declare const OBSERVATION_MAX_FUTURE_SKEW_SECS = 2n;
|
|
22
|
+
/**
|
|
23
|
+
* Upper bound on (observation time - quote block time) for using a purchased assignment (3632 s).
|
|
24
|
+
* Derived, not chosen; it bounds use, not quote signing or mining freshness. Rust `MAX_ASSIGNMENT_AGE_SECS`.
|
|
25
|
+
*/
|
|
26
|
+
export declare const MAX_ASSIGNMENT_AGE_SECS: bigint;
|
|
27
|
+
/** Stable paid-epoch failure codes. */
|
|
28
|
+
export type PaidEpochCode = 'paid_epoch_unavailable' | 'paid_epoch_refused';
|
|
29
|
+
/**
|
|
30
|
+
* A paid epoch could not be admitted. `paid_epoch_unavailable` (retryable): the quote block or
|
|
31
|
+
* its historical state could not be read (unknown block, pruned state, RPC failure); it is never
|
|
32
|
+
* an admission and never falls back to the live head. `paid_epoch_refused` (not retryable): a
|
|
33
|
+
* definite answer about the payment (a reorganised or substituted quote block, or an epoch
|
|
34
|
+
* outside the quote block's `{E_a, E_a - 1}`).
|
|
35
|
+
*/
|
|
36
|
+
export declare class PaidEpochError extends TasraError {
|
|
37
|
+
/** Stable failure code. */
|
|
38
|
+
readonly code: PaidEpochCode;
|
|
39
|
+
constructor(code: PaidEpochCode, message: string, cause?: unknown);
|
|
40
|
+
}
|
|
41
|
+
/** One canonical beacon read at a reservation's assignment (quote) block. */
|
|
42
|
+
export interface AssignmentEpoch {
|
|
43
|
+
blockHash: Hex;
|
|
44
|
+
blockNumber: bigint;
|
|
45
|
+
blockTimestamp: bigint;
|
|
46
|
+
beaconEpoch: bigint;
|
|
47
|
+
}
|
|
48
|
+
/** The consumer's own fresh observation of the mined reservation. */
|
|
49
|
+
export interface PaidEpochObservation {
|
|
50
|
+
assignmentBlock: Hex;
|
|
51
|
+
blockNumber: bigint;
|
|
52
|
+
blockTimestamp: bigint;
|
|
53
|
+
}
|
|
54
|
+
/** Throws a definite {@link PaidEpochError} unless `verificationEpoch` was current or previous at the receipt's quote block. */
|
|
55
|
+
export declare function requirePaidEpoch(verificationEpoch: bigint, receipt: PaidEpochObservation, anchor: AssignmentEpoch, headEpoch: bigint): void;
|
|
56
|
+
/**
|
|
57
|
+
* `beacon.epoch()` at `assignmentBlock` (EIP-1898 `requireCanonical`), plus a by-number canonical
|
|
58
|
+
* recheck. A missing block or unservable state is retryable `paid_epoch_unavailable`; a known
|
|
59
|
+
* block that is not canonical (or answers for another hash) is a definite `paid_epoch_refused`.
|
|
60
|
+
* There is no fallback to the head or to logs.
|
|
61
|
+
*
|
|
62
|
+
* The block's number and time and the epoch at that HASH are immutable, so once read they are
|
|
63
|
+
* kept per client (bounded) and the paid operation's later approvals read only the canonical
|
|
64
|
+
* recheck, which is never kept. A failed or refused read keeps nothing.
|
|
65
|
+
*/
|
|
66
|
+
export declare function readAssignmentEpoch(client: PublicClient, beacon: Address, assignmentBlock: Hex): Promise<AssignmentEpoch>;
|