@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
package/dist/chain/services.js
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
1
|
-
import { encodeAbiParameters, keccak256 } from 'viem';
|
|
1
|
+
import { decodeFunctionResult, encodeAbiParameters, encodeFunctionData, keccak256 } from 'viem';
|
|
2
2
|
import { serviceRegistryAbi } from './abis/serviceRegistry.js';
|
|
3
3
|
import { requireAddress } from './deployments.js';
|
|
4
|
+
import { chainIdOf } from './chainId.js';
|
|
5
|
+
import { headFollowerOf } from './headFollower.js';
|
|
6
|
+
import { registerHeadPrefetch } from './headPrefetch.js';
|
|
7
|
+
import { pinnedRegistryCall } from './pinnedReads.js';
|
|
8
|
+
function serviceAt(client, registry, serviceId, at) {
|
|
9
|
+
return pinnedRegistryCall(client, at, registry, encodeFunctionData({ abi: serviceRegistryAbi, functionName: 'getService', args: [serviceId] }), false).then(data => {
|
|
10
|
+
if (data === undefined)
|
|
11
|
+
throw new Error('empty ServiceRegistry.getService response');
|
|
12
|
+
return decodeFunctionResult({ abi: serviceRegistryAbi, functionName: 'getService', data });
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* A service's registration at the chain head: at a live head follower's tip (a block-pinned read,
|
|
17
|
+
* pre-read at every new head once asked for), otherwise at `latest` by RPC as before.
|
|
18
|
+
* @param chain Reader of the deployment.
|
|
19
|
+
* @param serviceId Registered service.
|
|
20
|
+
*/
|
|
21
|
+
export function currentServiceRecord(chain, serviceId) {
|
|
22
|
+
const tip = headFollowerOf(chain.client)?.tip();
|
|
23
|
+
if (!tip)
|
|
24
|
+
return chain.readers.serviceRegistry.getService(serviceId);
|
|
25
|
+
const registry = requireAddress(chain.addresses, 'ServiceRegistry');
|
|
26
|
+
registerHeadPrefetch(chain.client, `service:${registry}:${serviceId}`.toLowerCase(), head => serviceAt(chain.client, registry, serviceId, head));
|
|
27
|
+
return serviceAt(chain.client, registry, serviceId, tip);
|
|
28
|
+
}
|
|
4
29
|
/** Permanent ServiceRegistry ABI ordinals. Registration grants no operator privileges. */
|
|
5
30
|
export const SERVICE_TYPES = { gasRelayer: 0, verifierAgent: 1, vaultService: 2 };
|
|
6
31
|
/**
|
|
@@ -57,12 +82,27 @@ export async function readApprovedServiceRecord(chain, approval) {
|
|
|
57
82
|
const registry = requireAddress(chain.addresses, 'ServiceRegistry');
|
|
58
83
|
if (registry.toLowerCase() !== approval.registry.toLowerCase())
|
|
59
84
|
throw new Error('Service registry approval mismatch');
|
|
60
|
-
const chainId = await chain.client
|
|
85
|
+
const chainId = await chainIdOf(chain.client);
|
|
61
86
|
if (chainId !== approval.chainId || (chain.client.chain && chain.client.chain.id !== chainId)) {
|
|
62
87
|
throw new Error('Service chain approval mismatch');
|
|
63
88
|
}
|
|
64
|
-
|
|
65
|
-
|
|
89
|
+
// At a live head follower's tip (confirmed within 2 s) that the follower also proves FINAL
|
|
90
|
+
// (instant finality, at or below a matching finalized header), the record is a read pinned to
|
|
91
|
+
// that block's hash and pre-read at every new head; otherwise the head number and the record at
|
|
92
|
+
// it are read by RPC, as before.
|
|
93
|
+
const follower = headFollowerOf(chain.client);
|
|
94
|
+
const live = follower?.tip();
|
|
95
|
+
const tip = live && follower?.isCanonical(live) === true ? live : undefined;
|
|
96
|
+
let blockNumber, record;
|
|
97
|
+
if (tip) {
|
|
98
|
+
registerHeadPrefetch(chain.client, `service:${registry}:${approval.serviceId}`.toLowerCase(), head => serviceAt(chain.client, registry, approval.serviceId, head));
|
|
99
|
+
blockNumber = tip.blockNumber;
|
|
100
|
+
record = await serviceAt(chain.client, registry, approval.serviceId, tip);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
blockNumber = await chain.client.getBlockNumber({ cacheTime: 0 });
|
|
104
|
+
record = await chain.readers.serviceRegistry.getService(approval.serviceId, blockNumber);
|
|
105
|
+
}
|
|
66
106
|
if (record.status !== SERVICE_STATUSES.active)
|
|
67
107
|
throw new Error('Service is not accepting new work');
|
|
68
108
|
if (record.serviceType !== approval.serviceType || !Object.values(SERVICE_TYPES).includes(record.serviceType)) {
|
package/dist/chain/slotClient.js
CHANGED
|
@@ -20,9 +20,18 @@ import { createTasraClient, } from '../client/index.js';
|
|
|
20
20
|
export function createTasraSlotClient(cfg) {
|
|
21
21
|
const rewrite = cfg.rewriteUrl ?? ((u) => u);
|
|
22
22
|
const open = new Set();
|
|
23
|
-
// The verifier set is network-wide (not per-slot), so discover it once and cache
|
|
23
|
+
// The verifier set is network-wide (not per-slot), so discover it once and cache - never a
|
|
24
|
+
// FAILED lookup: one RPC error used to poison the client for good (robustness audit P13).
|
|
24
25
|
let verifiersPromise;
|
|
25
|
-
const verifierDirectory = () =>
|
|
26
|
+
const verifierDirectory = () => {
|
|
27
|
+
if (verifiersPromise)
|
|
28
|
+
return verifiersPromise;
|
|
29
|
+
const lookup = resolveVerifierDirectory(cfg.chain);
|
|
30
|
+
verifiersPromise = lookup;
|
|
31
|
+
lookup.catch(() => { if (verifiersPromise === lookup)
|
|
32
|
+
verifiersPromise = undefined; });
|
|
33
|
+
return lookup;
|
|
34
|
+
};
|
|
26
35
|
async function resolveEndpoints(slotId) {
|
|
27
36
|
const [nodesRaw, dir] = await Promise.all([
|
|
28
37
|
resolveSlotKeeperUrls(cfg.chain, slotId),
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { type Address, type Hex, type PublicClient } from 'viem';
|
|
2
|
+
import { TasraError } from '../errors.js';
|
|
3
|
+
import type { TasraChainClient } from './client.js';
|
|
4
|
+
/**
|
|
5
|
+
* Stable refusal categories of the hand-off API; branch on `code`, never on the message.
|
|
6
|
+
* None is retryable: each needs a change of key, offer or slot first.
|
|
7
|
+
*/
|
|
8
|
+
export type SlotHandoffErrorCode = 'no-slot' | 'cancelled' | 'unsupported' | 'not-creator' | 'not-admin' | 'immutable' | 'same-holder' | 'already-offered' | 'guardian' | 'nothing-pending' | 'not-offered' | 'not-confirmed'
|
|
9
|
+
/** The slot would become its own creator: every later paid operation needs a creator signature only the slot itself could make. */
|
|
10
|
+
| 'self-custody'
|
|
11
|
+
/** The recipient is a contract: keepers accept creator signatures from an externally owned account only. */
|
|
12
|
+
| 'contract-holder';
|
|
13
|
+
/** A hand-off refused before signing, or one that did not reach the state the caller asked for. */
|
|
14
|
+
export declare class SlotHandoffError extends TasraError {
|
|
15
|
+
/** Refusal category; never infer it from the message. */
|
|
16
|
+
readonly code: SlotHandoffErrorCode;
|
|
17
|
+
/** Slot the refused call targeted. */
|
|
18
|
+
readonly slotId: Hex;
|
|
19
|
+
constructor(code: SlotHandoffErrorCode, slotId: Hex, message: string, opts?: {
|
|
20
|
+
cause?: unknown;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
/** A slot's roles and pending hand-offs as the chain records them; `null` means none. */
|
|
24
|
+
export interface SlotHandoffStatus {
|
|
25
|
+
/** Slot creator. */
|
|
26
|
+
creator: Address;
|
|
27
|
+
/** Wallet offered the creator role, not yet accepted. */
|
|
28
|
+
pendingCreator: Address | null;
|
|
29
|
+
/** Rule admin; `null` means the rule is immutable. */
|
|
30
|
+
ruleAdmin: Address | null;
|
|
31
|
+
/** Rule guardian. */
|
|
32
|
+
guardian: Address | null;
|
|
33
|
+
/** Wallet offered the rule admin role, not yet accepted. */
|
|
34
|
+
pendingRuleAdmin: Address | null;
|
|
35
|
+
/** The slot's own Ethereum account (a ready secp256k1 threshold slot), or `null`. */
|
|
36
|
+
slotAccount: Address | null;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Read a slot's roles and pending hand-offs. Refuses `no-slot`, `cancelled` and `unsupported`
|
|
40
|
+
* (a KeyRegistry without the hand-off).
|
|
41
|
+
* @param read A `readContract` function, from a viem public client.
|
|
42
|
+
* @param keyRegistry KeyRegistry address of the deployment.
|
|
43
|
+
* @param slotId Slot to read.
|
|
44
|
+
*/
|
|
45
|
+
export declare function readHandoffOnChain(read: PublicClient['readContract'], keyRegistry: Address, slotId: Hex): Promise<SlotHandoffStatus>;
|
|
46
|
+
/**
|
|
47
|
+
* Read a slot's creator, rule admin, guardian and any pending hand-off of either role.
|
|
48
|
+
* @param chain Reader for the deployment that owns the slot.
|
|
49
|
+
* @param slotId Slot to read; refuses `no-slot`, `cancelled` and `unsupported` as a `SlotHandoffError`.
|
|
50
|
+
*/
|
|
51
|
+
export declare function readSlotHandoff(chain: TasraChainClient, slotId: Hex): Promise<SlotHandoffStatus>;
|
|
52
|
+
/**
|
|
53
|
+
* The contract's refusals for a creator offer (`to` zero withdraws), then the no-op offers it would accept.
|
|
54
|
+
* @param s The slot's state.
|
|
55
|
+
* @param slotId Slot the offer targets.
|
|
56
|
+
* @param sender Account that would sign.
|
|
57
|
+
* @param to Offered wallet, or zero to withdraw.
|
|
58
|
+
*/
|
|
59
|
+
export declare function creatorOfferVerdict(s: SlotHandoffStatus, slotId: Hex, sender: Address, to: Address): void;
|
|
60
|
+
/**
|
|
61
|
+
* The contract's refusals for a creator acceptance.
|
|
62
|
+
* @param s The slot's state.
|
|
63
|
+
* @param slotId Slot the acceptance targets.
|
|
64
|
+
* @param sender Account that would sign.
|
|
65
|
+
*/
|
|
66
|
+
export declare function creatorAcceptVerdict(s: SlotHandoffStatus, slotId: Hex, sender: Address): void;
|
|
67
|
+
/**
|
|
68
|
+
* The contract's refusals for a rule admin offer (`to` zero withdraws), then the no-op offers it would accept.
|
|
69
|
+
* @param s The slot's state.
|
|
70
|
+
* @param slotId Slot the offer targets.
|
|
71
|
+
* @param sender Account that would sign.
|
|
72
|
+
* @param to Offered wallet, or zero to withdraw.
|
|
73
|
+
*/
|
|
74
|
+
export declare function adminOfferVerdict(s: SlotHandoffStatus, slotId: Hex, sender: Address, to: Address): void;
|
|
75
|
+
/**
|
|
76
|
+
* The contract's refusals for a rule admin acceptance.
|
|
77
|
+
* @param s The slot's state.
|
|
78
|
+
* @param slotId Slot the acceptance targets.
|
|
79
|
+
* @param sender Account that would sign.
|
|
80
|
+
*/
|
|
81
|
+
export declare function adminAcceptVerdict(s: SlotHandoffStatus, slotId: Hex, sender: Address): void;
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
// Two-step slot hand-offs: the creator offers the slot and the new creator accepts it; the rule
|
|
2
|
+
// admin offers its role and the new admin accepts it. The two roles move separately, so buying a
|
|
3
|
+
// slot never buys the power to rewrite its rule, and the guardian never moves.
|
|
4
|
+
//
|
|
5
|
+
// The typed refusal and the one on-chain read every hand-off write judges from. Every refusal is
|
|
6
|
+
// raised BEFORE anything is signed, in the contract's order. A KeyRegistry from before the
|
|
7
|
+
// hand-off is refused as `unsupported`, never as a bare revert.
|
|
8
|
+
import { hexToBytes } from 'viem';
|
|
9
|
+
import { addressFromEoaPubkey } from '../signing/ecdsa.js';
|
|
10
|
+
import { TasraError } from '../errors.js';
|
|
11
|
+
import { viemErrorChainHas } from '../internal/viemErrors.js';
|
|
12
|
+
import { keyRegistryAbi } from './abis/keyRegistry.js';
|
|
13
|
+
import { requireAddress } from './deployments.js';
|
|
14
|
+
/** A hand-off refused before signing, or one that did not reach the state the caller asked for. */
|
|
15
|
+
export class SlotHandoffError extends TasraError {
|
|
16
|
+
/** Refusal category; never infer it from the message. */
|
|
17
|
+
code;
|
|
18
|
+
/** Slot the refused call targeted. */
|
|
19
|
+
slotId;
|
|
20
|
+
constructor(code, slotId, message, opts = {}) {
|
|
21
|
+
super(message, { cause: opts.cause });
|
|
22
|
+
this.code = code;
|
|
23
|
+
this.slotId = slotId;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const ZERO = '0x0000000000000000000000000000000000000000';
|
|
27
|
+
/** Refusal for a slot that would become its own creator. */
|
|
28
|
+
function selfCustody(slotId) {
|
|
29
|
+
return new SlotHandoffError('self-custody', slotId, `slot cannot become its own creator: its paid operations need a creator signature, ` +
|
|
30
|
+
'which only a paid operation of the same slot could produce, so no operation, renewal or further hand-off could ever be signed again');
|
|
31
|
+
}
|
|
32
|
+
const same = (a, b) => a.toLowerCase() === b.toLowerCase();
|
|
33
|
+
const orNull = (a) => (same(a, ZERO) ? null : a);
|
|
34
|
+
/** True when a read reverted or returned no data, as a missing selector does. */
|
|
35
|
+
function missingFunction(e) {
|
|
36
|
+
// By name: the read comes from the caller's client, whose viem copy may not be this package's.
|
|
37
|
+
return viemErrorChainHas(e, ['ContractFunctionRevertedError', 'ContractFunctionZeroDataError']);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Read a slot's roles and pending hand-offs. Refuses `no-slot`, `cancelled` and `unsupported`
|
|
41
|
+
* (a KeyRegistry without the hand-off).
|
|
42
|
+
* @param read A `readContract` function, from a viem public client.
|
|
43
|
+
* @param keyRegistry KeyRegistry address of the deployment.
|
|
44
|
+
* @param slotId Slot to read.
|
|
45
|
+
*/
|
|
46
|
+
export async function readHandoffOnChain(read, keyRegistry, slotId) {
|
|
47
|
+
const [slot, policy] = await Promise.all([
|
|
48
|
+
read({ address: keyRegistry, abi: keyRegistryAbi, functionName: 'getKeySlot', args: [slotId] }),
|
|
49
|
+
read({ address: keyRegistry, abi: keyRegistryAbi, functionName: 'rulePolicy', args: [slotId] }),
|
|
50
|
+
]);
|
|
51
|
+
if (!slot.exists)
|
|
52
|
+
throw new SlotHandoffError('no-slot', slotId, `slot ${slotId} does not exist on this KeyRegistry; check the slot id and the network`);
|
|
53
|
+
if (slot.cancelled)
|
|
54
|
+
throw new SlotHandoffError('cancelled', slotId, `slot ${slotId} is cancelled; a cancelled slot hands nothing over`);
|
|
55
|
+
let pending;
|
|
56
|
+
try {
|
|
57
|
+
pending = await Promise.all([
|
|
58
|
+
read({ address: keyRegistry, abi: keyRegistryAbi, functionName: 'pendingCreator', args: [slotId] }),
|
|
59
|
+
read({ address: keyRegistry, abi: keyRegistryAbi, functionName: 'pendingRuleAdmin', args: [slotId] }),
|
|
60
|
+
]);
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
// The getters cannot revert on a registry that has them.
|
|
64
|
+
if (!missingFunction(e))
|
|
65
|
+
throw e;
|
|
66
|
+
throw new SlotHandoffError('unsupported', slotId, `the KeyRegistry ${keyRegistry} has no slot hand-off; it predates the upgrade that adds it`, { cause: e });
|
|
67
|
+
}
|
|
68
|
+
const [admin, guardian] = policy;
|
|
69
|
+
let slotAccount = null;
|
|
70
|
+
if (slot.mode === 2 && /^0x0[23][0-9a-fA-F]{64}$/.test(slot.publicKey))
|
|
71
|
+
slotAccount = addressFromEoaPubkey(hexToBytes(slot.publicKey));
|
|
72
|
+
return {
|
|
73
|
+
creator: slot.creator,
|
|
74
|
+
pendingCreator: orNull(pending[0]),
|
|
75
|
+
ruleAdmin: orNull(admin),
|
|
76
|
+
guardian: orNull(guardian),
|
|
77
|
+
pendingRuleAdmin: orNull(pending[1]),
|
|
78
|
+
slotAccount,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Read a slot's creator, rule admin, guardian and any pending hand-off of either role.
|
|
83
|
+
* @param chain Reader for the deployment that owns the slot.
|
|
84
|
+
* @param slotId Slot to read; refuses `no-slot`, `cancelled` and `unsupported` as a `SlotHandoffError`.
|
|
85
|
+
*/
|
|
86
|
+
export function readSlotHandoff(chain, slotId) {
|
|
87
|
+
return readHandoffOnChain(chain.client.readContract, requireAddress(chain.addresses, 'KeyRegistry'), slotId);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* The contract's refusals for a creator offer (`to` zero withdraws), then the no-op offers it would accept.
|
|
91
|
+
* @param s The slot's state.
|
|
92
|
+
* @param slotId Slot the offer targets.
|
|
93
|
+
* @param sender Account that would sign.
|
|
94
|
+
* @param to Offered wallet, or zero to withdraw.
|
|
95
|
+
*/
|
|
96
|
+
export function creatorOfferVerdict(s, slotId, sender, to) {
|
|
97
|
+
if (!same(sender, s.creator))
|
|
98
|
+
throw new SlotHandoffError('not-creator', slotId, `slot ${slotId} has creator ${s.creator}, but this client signs as ${sender}`);
|
|
99
|
+
if (same(to, s.creator))
|
|
100
|
+
throw new SlotHandoffError('same-holder', slotId, `${to} already is the creator of slot ${slotId}`);
|
|
101
|
+
if (s.slotAccount && same(to, s.slotAccount))
|
|
102
|
+
throw selfCustody(slotId);
|
|
103
|
+
if (same(to, ZERO)) {
|
|
104
|
+
if (!s.pendingCreator)
|
|
105
|
+
throw new SlotHandoffError('nothing-pending', slotId, `slot ${slotId} has no creator transfer pending`);
|
|
106
|
+
}
|
|
107
|
+
else if (s.pendingCreator && same(to, s.pendingCreator)) {
|
|
108
|
+
throw new SlotHandoffError('already-offered', slotId, `slot ${slotId} is already offered to ${to}`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* The contract's refusals for a creator acceptance.
|
|
113
|
+
* @param s The slot's state.
|
|
114
|
+
* @param slotId Slot the acceptance targets.
|
|
115
|
+
* @param sender Account that would sign.
|
|
116
|
+
*/
|
|
117
|
+
export function creatorAcceptVerdict(s, slotId, sender) {
|
|
118
|
+
if (!s.pendingCreator)
|
|
119
|
+
throw new SlotHandoffError('nothing-pending', slotId, `slot ${slotId} has no creator transfer pending`);
|
|
120
|
+
if (!same(sender, s.pendingCreator)) {
|
|
121
|
+
throw new SlotHandoffError('not-offered', slotId, `slot ${slotId} is offered to ${s.pendingCreator}, but this client signs as ${sender}`);
|
|
122
|
+
}
|
|
123
|
+
if (s.slotAccount && same(sender, s.slotAccount))
|
|
124
|
+
throw selfCustody(slotId);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* The contract's refusals for a rule admin offer (`to` zero withdraws), then the no-op offers it would accept.
|
|
128
|
+
* @param s The slot's state.
|
|
129
|
+
* @param slotId Slot the offer targets.
|
|
130
|
+
* @param sender Account that would sign.
|
|
131
|
+
* @param to Offered wallet, or zero to withdraw.
|
|
132
|
+
*/
|
|
133
|
+
export function adminOfferVerdict(s, slotId, sender, to) {
|
|
134
|
+
if (!s.ruleAdmin)
|
|
135
|
+
throw new SlotHandoffError('immutable', slotId, `slot ${slotId} has no rule admin; its rule is immutable`);
|
|
136
|
+
if (!same(sender, s.ruleAdmin))
|
|
137
|
+
throw new SlotHandoffError('not-admin', slotId, `slot ${slotId} has rule admin ${s.ruleAdmin}, but this client signs as ${sender}`);
|
|
138
|
+
if (same(to, s.ruleAdmin))
|
|
139
|
+
throw new SlotHandoffError('same-holder', slotId, `${to} already is the rule admin of slot ${slotId}`);
|
|
140
|
+
if (s.guardian && same(to, s.guardian)) {
|
|
141
|
+
throw new SlotHandoffError('guardian', slotId, `${to} is the guardian of slot ${slotId}; one wallet may not be both`);
|
|
142
|
+
}
|
|
143
|
+
if (same(to, ZERO)) {
|
|
144
|
+
if (!s.pendingRuleAdmin)
|
|
145
|
+
throw new SlotHandoffError('nothing-pending', slotId, `slot ${slotId} has no rule admin transfer pending`);
|
|
146
|
+
}
|
|
147
|
+
else if (s.pendingRuleAdmin && same(to, s.pendingRuleAdmin)) {
|
|
148
|
+
throw new SlotHandoffError('already-offered', slotId, `the rule admin of slot ${slotId} is already offered to ${to}`);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* The contract's refusals for a rule admin acceptance.
|
|
153
|
+
* @param s The slot's state.
|
|
154
|
+
* @param slotId Slot the acceptance targets.
|
|
155
|
+
* @param sender Account that would sign.
|
|
156
|
+
*/
|
|
157
|
+
export function adminAcceptVerdict(s, slotId, sender) {
|
|
158
|
+
if (!s.pendingRuleAdmin)
|
|
159
|
+
throw new SlotHandoffError('nothing-pending', slotId, `slot ${slotId} has no rule admin transfer pending`);
|
|
160
|
+
if (!same(sender, s.pendingRuleAdmin)) {
|
|
161
|
+
throw new SlotHandoffError('not-offered', slotId, `the rule admin of slot ${slotId} is offered to ${s.pendingRuleAdmin}, but this client signs as ${sender}`);
|
|
162
|
+
}
|
|
163
|
+
if (s.guardian && same(sender, s.guardian)) {
|
|
164
|
+
throw new SlotHandoffError('guardian', slotId, `${sender} is the guardian of slot ${slotId}; one wallet may not be both`);
|
|
165
|
+
}
|
|
166
|
+
}
|
package/dist/chain/slotSeed.d.ts
CHANGED
|
@@ -11,21 +11,63 @@ export interface SlotSeed {
|
|
|
11
11
|
/** The 64-byte BN254 G1 threshold signature; pass as `seedSig` to `revealKeySlotWithSeed`. */
|
|
12
12
|
signature: Hex;
|
|
13
13
|
}
|
|
14
|
+
/** One accountant's answer to one ask, when it was not a usable seed. */
|
|
15
|
+
export interface SlotSeedAnswer {
|
|
16
|
+
/** The accountant base URL that was asked. */
|
|
17
|
+
url: string;
|
|
18
|
+
/** HTTP status, when a response arrived. */
|
|
19
|
+
status?: number;
|
|
20
|
+
/** Why the answer was not usable: the response reason, a transport error, or a shape/digest fault. */
|
|
21
|
+
reason: string;
|
|
22
|
+
}
|
|
23
|
+
/** Why no seed was obtained: every answer of the LAST round of asks, and how many rounds ran. */
|
|
24
|
+
export interface SlotSeedFailure {
|
|
25
|
+
/** Rounds of asks made (one round asks every accountant once). */
|
|
26
|
+
rounds: number;
|
|
27
|
+
/** Each accountant's answer in the last round. Empty when no accountant is registered. */
|
|
28
|
+
answers: SlotSeedAnswer[];
|
|
29
|
+
/** One line naming the dominant cause, for logs and bench records. */
|
|
30
|
+
reason: string;
|
|
31
|
+
}
|
|
32
|
+
/** Default time the creation path keeps re-asking while the set answers "not yet". */
|
|
33
|
+
export declare const DEFAULT_SLOT_SEED_RETRY_MS = 90000;
|
|
34
|
+
/**
|
|
35
|
+
* Default stagger between launching the asks of one round. The asks run CONCURRENTLY and the first
|
|
36
|
+
* valid seed wins; the stagger only keeps a healthy set from leading n threshold rounds for one
|
|
37
|
+
* commitment (each accountant leads at most one round at a time and sheds the rest with a 503).
|
|
38
|
+
* An ask that fails launches the next one at once, without waiting for the stagger.
|
|
39
|
+
*/
|
|
40
|
+
export declare const DEFAULT_SLOT_SEED_HEDGE_MS = 750;
|
|
14
41
|
/**
|
|
15
|
-
* Accountant endpoint overrides
|
|
42
|
+
* Accountant endpoint overrides, per-request timeout and the bounded retry window for committee
|
|
43
|
+
* seed discovery.
|
|
16
44
|
*/
|
|
17
45
|
export interface SlotSeedOptions {
|
|
18
46
|
/** Accountant base URLs. Resolved from `NodeRegistry` when omitted. */
|
|
19
47
|
urls?: string[];
|
|
20
|
-
/** Per-accountant HTTP timeout.
|
|
48
|
+
/** Per-accountant HTTP timeout (default 20 s). Within a retry window it is also capped by what is left of the window. */
|
|
21
49
|
timeoutMs?: number;
|
|
50
|
+
/**
|
|
51
|
+
* Keep asking for up to this long while some refusal is a "not yet" (404 before the
|
|
52
|
+
* accountant's view reaches the commit, 503 while another creation's round holds it, 429, a
|
|
53
|
+
* timeout). Rounds back off with jitter and honour `Retry-After`; a `Retry-After` that lands past
|
|
54
|
+
* the window ends it at once. Default 0: one round. `createSlotCommitReveal` passes
|
|
55
|
+
* {@link DEFAULT_SLOT_SEED_RETRY_MS}.
|
|
56
|
+
*/
|
|
57
|
+
retryForMs?: number;
|
|
58
|
+
/** Stagger between the concurrent asks of one round (default {@link DEFAULT_SLOT_SEED_HEDGE_MS}; 0 asks all at once). */
|
|
59
|
+
hedgeMs?: number;
|
|
60
|
+
/** Cancels the asks and the waits between rounds. */
|
|
61
|
+
signal?: AbortSignal;
|
|
62
|
+
/** Called once with every answer of the last round when no seed was obtained. */
|
|
63
|
+
onFailure?: (failure: SlotSeedFailure) => void;
|
|
22
64
|
}
|
|
23
65
|
/**
|
|
24
|
-
* Request a committee draw seed and compare its digest with the registry. Checks signature encoding and rejects the point at infinity; signature cryptography is verified during the on-chain reveal.
|
|
66
|
+
* Request a committee draw seed and compare its digest with the registry. Checks signature encoding and rejects the point at infinity; signature cryptography is verified during the on-chain reveal. Accountants are asked concurrently and the first valid seed wins.
|
|
25
67
|
* @param chain Reader for the deployment owning the commitment.
|
|
26
68
|
* @param keyRegistry Registry that will receive the reveal transaction.
|
|
27
69
|
* @param commitment Previously submitted creation commitment.
|
|
28
|
-
* @param opts Accountant endpoints
|
|
29
|
-
* @returns A seed response, or null when no accountant returns an acceptable response.
|
|
70
|
+
* @param opts Accountant endpoints, request timeout, retry window and cancellation.
|
|
71
|
+
* @returns A seed response, or null when no accountant returns an acceptable response within the window.
|
|
30
72
|
*/
|
|
31
73
|
export declare function requestSlotSeed(chain: TasraChainClient, keyRegistry: `0x${string}`, commitment: Hex, opts?: SlotSeedOptions): Promise<SlotSeed | null>;
|