@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
package/dist/committee/client.js
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import { checkedDecryptionRequestHash, recipientPayloadDigest } from '../crypto/recipient.js';
|
|
2
|
+
import { sha256 } from '@noble/hashes/sha256';
|
|
3
|
+
import { ed25519 } from '@noble/curves/ed25519';
|
|
4
|
+
import { evidenceBindingMessage, evidenceBody } from './evidence.js';
|
|
1
5
|
// Committee-mode HTTP orchestration - the glue around the pure token
|
|
2
6
|
// crypto in ./committee.ts. Three pieces:
|
|
3
7
|
// - committeeAuthorize() - POST a VP to ONE verifier's /v1/committee-authorize,
|
|
@@ -9,19 +13,20 @@
|
|
|
9
13
|
// - committeeSign() / committeeDecrypt() - POST the assembled token (in the
|
|
10
14
|
// BODY, no auth header) to the keeper's /v1/committee/{sign,decrypt}.
|
|
11
15
|
import { hexToBytes, bytesToHex } from '../crypto/hex.js';
|
|
12
|
-
import {
|
|
16
|
+
import { assertPaymentIntentWire, paymentIntentHash } from './payment.js';
|
|
17
|
+
import { httpError, RevocationStatusError, TasraHttpError, ThresholdNotMetError } from '../errors.js';
|
|
13
18
|
import { bytesToHex as bareHex } from '@noble/hashes/utils';
|
|
14
|
-
import { assembleCompoundToken, compoundTokenHash, bindingFromWire } from './token.js';
|
|
15
|
-
import {
|
|
19
|
+
import { assembleCompoundToken, compoundTokenHash, bindingFromWire, verifyStatusAttestation } from './token.js';
|
|
20
|
+
import { base64Decode } from '../crypto/envelope.js';
|
|
16
21
|
import { decodeOperationReceipt } from './receipts.js';
|
|
22
|
+
import { withKeeperExecutionApprovals } from './keeperExecution.js';
|
|
23
|
+
import { ibeVerifyShare } from '../crypto/ibe.js';
|
|
24
|
+
import { withNetworkDeadline } from '../internal/network.js';
|
|
17
25
|
const strip0x = (s) => (s.startsWith('0x') ? s.slice(2) : s);
|
|
18
26
|
const base = (u) => u.replace(/\/$/, '');
|
|
19
27
|
function bytesEqual(a, b) {
|
|
20
28
|
return a.length === b.length && a.every((x, i) => x === b[i]);
|
|
21
29
|
}
|
|
22
|
-
function ctToWire(ct) {
|
|
23
|
-
return { u: base64Encode(ct.u), nonce: base64Encode(ct.nonce), aead_ct: base64Encode(ct.aeadCt) };
|
|
24
|
-
}
|
|
25
30
|
function proofsToWire(proofs) {
|
|
26
31
|
return proofs.map(p => ({
|
|
27
32
|
verifier_index: p.verifierIndex,
|
|
@@ -46,7 +51,23 @@ export class CommitteeAuthorizeError extends TasraHttpError {
|
|
|
46
51
|
}
|
|
47
52
|
}
|
|
48
53
|
function authorizeWire(b) {
|
|
54
|
+
if (b.payment !== undefined) {
|
|
55
|
+
assertPaymentIntentWire(b.payment);
|
|
56
|
+
const p = b.payment;
|
|
57
|
+
if (!b.binding
|
|
58
|
+
|| p.chain_id !== Number(b.binding.chainId)
|
|
59
|
+
|| p.slot.toLowerCase() !== bytesToHex(b.slotId).toLowerCase()
|
|
60
|
+
|| p.payload_digest.toLowerCase() !== bytesToHex(b.binding.payloadDigest).toLowerCase()
|
|
61
|
+
|| (p.action === 'eoa-sign' ? 'sign' : p.action) !== b.binding.action
|
|
62
|
+
|| p.verification_epoch !== Number(b.epoch)
|
|
63
|
+
|| p.verification_seed.toLowerCase() !== bytesToHex(b.seed).toLowerCase()
|
|
64
|
+
|| p.verification_registry_size !== b.registrySize
|
|
65
|
+
|| p.verification_committee !== b.committee) {
|
|
66
|
+
throw new Error('payment differs from verifier request');
|
|
67
|
+
}
|
|
68
|
+
}
|
|
49
69
|
return {
|
|
70
|
+
...(b.payment !== undefined ? { payment: b.payment } : {}),
|
|
50
71
|
holder: b.holder,
|
|
51
72
|
credentials: b.credentials,
|
|
52
73
|
// Omit rather than send "": the server field is an Option, and an empty
|
|
@@ -104,7 +125,19 @@ export async function committeeAuthorize(verifierUrl, body) {
|
|
|
104
125
|
throw new CommitteeAuthorizeError(res.status, `committee-authorize → HTTP ${res.status}${detail ? `: ${detail}` : ''}`, { url, body: detail });
|
|
105
126
|
}
|
|
106
127
|
const d = (await res.json());
|
|
128
|
+
let sealedEvidence;
|
|
129
|
+
if ([d.evidence_hash, d.evidence_key_id, d.evidence_sig, d.evidence_ct].some(v => v != null)) {
|
|
130
|
+
const token = { verifier_indexes: d.committee_indexes, evidence_hash: d.evidence_hash ?? undefined, evidence_key_id: d.evidence_key_id ?? undefined,
|
|
131
|
+
evidence_signatures: [{ verifier_index: d.verifier_index, signature: d.evidence_sig }] };
|
|
132
|
+
evidenceBody(token, d.evidence_ct ?? undefined);
|
|
133
|
+
sealedEvidence = { hash: d.evidence_hash, keyId: d.evidence_key_id, signature: d.evidence_sig, ciphertext: d.evidence_ct };
|
|
134
|
+
}
|
|
135
|
+
const expectedPayment = body.payment ? paymentIntentHash(body.payment) : undefined;
|
|
136
|
+
if ((d.payment_hash ?? undefined)?.toLowerCase() !== expectedPayment?.toLowerCase())
|
|
137
|
+
throw new Error('verifier changed or omitted the payment commitment');
|
|
107
138
|
return {
|
|
139
|
+
...(sealedEvidence ? { sealedEvidence } : {}),
|
|
140
|
+
...(expectedPayment ? { paymentHash: hexToBytes(expectedPayment) } : {}),
|
|
108
141
|
verifierIndex: Number(d.verifier_index),
|
|
109
142
|
tokenHash: hexToBytes(d.token_hash),
|
|
110
143
|
vpHash: hexToBytes(d.vp_hash),
|
|
@@ -116,8 +149,20 @@ export async function committeeAuthorize(verifierUrl, body) {
|
|
|
116
149
|
signature: hexToBytes(d.signature),
|
|
117
150
|
committeeIndexes: d.committee_indexes,
|
|
118
151
|
ruleVersion: typeof d.rule_version === 'number' ? d.rule_version : undefined,
|
|
152
|
+
...statusAttestationField(d.status_until, d.status_signature),
|
|
119
153
|
};
|
|
120
154
|
}
|
|
155
|
+
// A reply carries both halves of a status attestation or neither. Half of one, or a malformed
|
|
156
|
+
// one, makes the whole reply invalid (the verifier-agent refuses such a reply the same way).
|
|
157
|
+
function statusAttestationField(until, signature) {
|
|
158
|
+
if (until == null && signature == null)
|
|
159
|
+
return {};
|
|
160
|
+
if (typeof until !== 'number' || !Number.isSafeInteger(until) || typeof signature !== 'string' || !/^(?:0x)?[0-9a-fA-F]{128}$/.test(signature)) {
|
|
161
|
+
throw new Error('verifier reply carries a malformed or partial status attestation');
|
|
162
|
+
}
|
|
163
|
+
return { statusAttestation: { statusUntil: until, signature: hexToBytes(signature) } };
|
|
164
|
+
}
|
|
165
|
+
// coordinator: gather a quorum + assemble the token
|
|
121
166
|
/**
|
|
122
167
|
* Fan out to the candidate verifiers, collect signatures from the drawn committee
|
|
123
168
|
* until quorum, and assemble the compound token. Verifies that our locally
|
|
@@ -127,11 +172,36 @@ export async function committeeAuthorize(verifierUrl, body) {
|
|
|
127
172
|
* @param opts - Verifier requests, committee draw and required signature quorum.
|
|
128
173
|
*/
|
|
129
174
|
export async function gatherCommitteeToken(opts) {
|
|
175
|
+
if (opts.authorize.payment && opts.quorum !== opts.authorize.payment.verification_quorum)
|
|
176
|
+
throw new Error('quorum differs from payment');
|
|
130
177
|
const settled = await Promise.allSettled(opts.verifiers.map(async (v) => {
|
|
131
178
|
const body = opts.holderProofFor
|
|
132
179
|
? { ...opts.authorize, holderProof: await opts.holderProofFor(v) }
|
|
133
180
|
: opts.authorize;
|
|
134
|
-
|
|
181
|
+
const reply = await committeeAuthorize(v.url, body);
|
|
182
|
+
// Revocation-status freshness: authenticate the reply's attestation under this verifier's
|
|
183
|
+
// committee key (the key its token signature is checked against) before it may be relayed.
|
|
184
|
+
// A forged one refuses the reply, as the verifier-agent does. Without a known key it is
|
|
185
|
+
// dropped, never relayed unauthenticated.
|
|
186
|
+
if (reply.statusAttestation) {
|
|
187
|
+
const pubkey = typeof v.pubkey === 'string' ? hexToBytes(v.pubkey) : v.pubkey;
|
|
188
|
+
if (!pubkey) {
|
|
189
|
+
const { statusAttestation: _dropped, ...rest } = reply;
|
|
190
|
+
if (reply.sealedEvidence)
|
|
191
|
+
throw new Error('Sealed evidence requires the verifier public key');
|
|
192
|
+
return rest;
|
|
193
|
+
}
|
|
194
|
+
if (reply.verifierIndex !== v.index || !verifyStatusAttestation(pubkey, reply.tokenHash, { verifierIndex: reply.verifierIndex, ...reply.statusAttestation })) {
|
|
195
|
+
throw new Error(`verifier #${v.index} status attestation does not verify`);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (reply.sealedEvidence) {
|
|
199
|
+
const key = typeof v.pubkey === 'string' ? hexToBytes(v.pubkey) : v.pubkey;
|
|
200
|
+
const e = reply.sealedEvidence;
|
|
201
|
+
if (!key || reply.verifierIndex !== v.index || !ed25519.verify(hexToBytes(e.signature), evidenceBindingMessage(reply.tokenHash, hexToBytes(e.hash), hexToBytes(e.keyId)), key, { zip215: false }))
|
|
202
|
+
throw new Error('Verifier sealed evidence signature does not verify');
|
|
203
|
+
}
|
|
204
|
+
return reply;
|
|
135
205
|
}));
|
|
136
206
|
const replies = settled
|
|
137
207
|
.filter((r) => r.status === 'fulfilled')
|
|
@@ -155,6 +225,11 @@ export async function gatherCommitteeToken(opts) {
|
|
|
155
225
|
throw new Error(`gatherCommitteeToken: no verifier authorized the request — ${why}`);
|
|
156
226
|
}
|
|
157
227
|
const ref = replies[0];
|
|
228
|
+
const sealed = ref.sealedEvidence;
|
|
229
|
+
if (replies.some(r => Boolean(r.sealedEvidence) !== Boolean(sealed) || sealed && (r.sealedEvidence.ciphertext !== sealed.ciphertext || r.sealedEvidence.hash.toLowerCase() !== sealed.hash.toLowerCase() || r.sealedEvidence.keyId.toLowerCase() !== sealed.keyId.toLowerCase())))
|
|
230
|
+
throw new Error('Verifier sealed evidence replies disagree');
|
|
231
|
+
if (sealed && !opts.onEvidence)
|
|
232
|
+
throw new Error('Sealed authorization requires onEvidence to retain its ciphertext');
|
|
158
233
|
opts.onReplies?.(replies, ref);
|
|
159
234
|
const committeeIndexes = ref.committeeIndexes;
|
|
160
235
|
const inCommittee = new Set(committeeIndexes);
|
|
@@ -192,25 +267,51 @@ export async function gatherCommitteeToken(opts) {
|
|
|
192
267
|
// The binding the reference verifier declared; the hash cross-check below proves
|
|
193
268
|
// every signer signed the SAME request_hash + binding byte.
|
|
194
269
|
...(ref.requestHash !== undefined ? { requestHash: ref.requestHash } : {}),
|
|
270
|
+
...(ref.paymentHash !== undefined ? { paymentHash: ref.paymentHash, payment: opts.authorize.payment } : {}),
|
|
195
271
|
binding: ref.binding,
|
|
196
272
|
verifierIndexes: committeeIndexes,
|
|
197
273
|
iat: opts.authorize.iat,
|
|
198
274
|
exp: opts.authorize.exp,
|
|
199
275
|
};
|
|
200
|
-
|
|
276
|
+
const canonicalHash = compoundTokenHash(payload);
|
|
277
|
+
if (replies.some(r => !bytesEqual(canonicalHash, r.tokenHash))) {
|
|
201
278
|
throw new Error('gatherCommitteeToken: canonical token hash disagrees with the verifier (encoding mismatch)');
|
|
202
279
|
}
|
|
203
|
-
|
|
280
|
+
// Revocation-status attestations (already authenticated above) from the signers whose signature
|
|
281
|
+
// the token carries. Relayed only when at least a quorum carry one: a keeper that sees the field
|
|
282
|
+
// requires a quorum of them, so a partial list would turn a grant a keeper could accept (field
|
|
283
|
+
// absent, freshness not yet enforced) into one every keeper refuses.
|
|
284
|
+
const attestations = [];
|
|
285
|
+
for (const r of replies) {
|
|
286
|
+
if (sigByIndex.has(r.verifierIndex) && r.statusAttestation && !attestations.some(a => a.verifierIndex === r.verifierIndex)) {
|
|
287
|
+
attestations.push({ verifierIndex: r.verifierIndex, ...r.statusAttestation });
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
const token = assembleCompoundToken(payload, [...sigByIndex.values()], attestations.length >= opts.quorum ? attestations : undefined);
|
|
291
|
+
if (sealed) {
|
|
292
|
+
token.evidence_hash = sealed.hash;
|
|
293
|
+
token.evidence_key_id = sealed.keyId;
|
|
294
|
+
token.evidence_signatures = [...new Map(replies.filter(r => inCommittee.has(r.verifierIndex)).map(r => [r.verifierIndex, { verifier_index: r.verifierIndex, signature: r.sealedEvidence.signature }])).values()];
|
|
295
|
+
evidenceBody(token, sealed.ciphertext);
|
|
296
|
+
opts.onEvidence(sealed.ciphertext);
|
|
297
|
+
}
|
|
298
|
+
return token;
|
|
204
299
|
}
|
|
205
300
|
/**
|
|
206
301
|
* Sign via committee authorization. The slot id is taken from the token.
|
|
302
|
+
* Approvals, HTTP and response decoding share a 15-second deadline. A timeout
|
|
303
|
+
* is an uncertain outcome; reconcile the original paid operation before resubmitting.
|
|
207
304
|
*
|
|
208
305
|
* @param opts - Keeper endpoint, compound authorization and message to sign.
|
|
209
306
|
*/
|
|
210
307
|
export async function committeeSign(opts) {
|
|
211
|
-
|
|
308
|
+
return withNetworkDeadline(signal => signWithinDeadline({ ...opts, signal }), opts.signal);
|
|
309
|
+
}
|
|
310
|
+
async function signWithinDeadline(opts) {
|
|
311
|
+
opts = { ...opts, committeeToken: structuredClone(opts.committeeToken) };
|
|
312
|
+
let body = {
|
|
212
313
|
committee_token: opts.committeeToken,
|
|
213
|
-
...(opts.
|
|
314
|
+
...evidenceBody(opts.committeeToken, opts.evidenceCt),
|
|
214
315
|
message_hex: bareHex(opts.message),
|
|
215
316
|
};
|
|
216
317
|
if (opts.signingSet)
|
|
@@ -221,16 +322,15 @@ export async function committeeSign(opts) {
|
|
|
221
322
|
body.target_keykeeper = strip0x(opts.targetKeykeeper);
|
|
222
323
|
if (opts.verifierProofs)
|
|
223
324
|
body.verifier_proofs = proofsToWire(opts.verifierProofs);
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
body.client_signature = bareHex(opts.clientSignature);
|
|
227
|
-
}
|
|
325
|
+
body = await withKeeperExecutionApprovals({ body, kind: 'committee-sign', nodeUrl: opts.nodeUrl, payment: opts.committeeToken.payment,
|
|
326
|
+
approveExecution: opts.approveExecution, signal: opts.signal });
|
|
228
327
|
const url = `${base(opts.nodeUrl)}/v1/committee/sign`;
|
|
229
328
|
const res = await (opts.fetchImpl ?? fetch)(url, {
|
|
230
329
|
method: 'POST',
|
|
231
330
|
headers: { 'Content-Type': 'application/json' },
|
|
232
331
|
body: JSON.stringify(body),
|
|
233
332
|
signal: opts.signal,
|
|
333
|
+
...(opts.committeeToken.payment ? { redirect: 'error', credentials: 'omit' } : {}),
|
|
234
334
|
});
|
|
235
335
|
if (!res.ok)
|
|
236
336
|
throw await httpError(res, url, 'committee/sign');
|
|
@@ -246,46 +346,21 @@ export async function committeeSign(opts) {
|
|
|
246
346
|
}
|
|
247
347
|
/**
|
|
248
348
|
* Decrypt via committee authorization. The slot id is taken from the token.
|
|
349
|
+
* Approvals, HTTP and response decoding share a 15-second deadline. A timeout
|
|
350
|
+
* does not prove that the keeper performed no work and never triggers a retry.
|
|
249
351
|
*
|
|
250
352
|
* @param opts - Keeper endpoint, compound authorization, ciphertext and associated data.
|
|
251
353
|
*/
|
|
252
354
|
export async function committeeDecrypt(opts) {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
...(opts.evidenceCt !== undefined ? { evidence_ct: opts.evidenceCt } : {}),
|
|
256
|
-
ciphertext: ctToWire(opts.ciphertext),
|
|
257
|
-
identity: new TextDecoder().decode(opts.identity),
|
|
258
|
-
decrypting_set: opts.decryptingSet,
|
|
259
|
-
bls_peers: opts.blsPeers.map(p => ({ id: p.id, peer_id: p.peerId })),
|
|
260
|
-
};
|
|
261
|
-
if (opts.userSignature)
|
|
262
|
-
body.user_signature = bareHex(opts.userSignature);
|
|
263
|
-
if (opts.ciphertextEpoch !== undefined)
|
|
264
|
-
body.ciphertext_epoch = opts.ciphertextEpoch;
|
|
265
|
-
if (opts.targetKeykeeper)
|
|
266
|
-
body.target_keykeeper = strip0x(opts.targetKeykeeper);
|
|
267
|
-
if (opts.verifierProofs)
|
|
268
|
-
body.verifier_proofs = proofsToWire(opts.verifierProofs);
|
|
269
|
-
if (opts.clientPubkey && opts.clientSignature) {
|
|
270
|
-
body.client_pubkey = bareHex(opts.clientPubkey);
|
|
271
|
-
body.client_signature = bareHex(opts.clientSignature);
|
|
272
|
-
}
|
|
273
|
-
const url = `${base(opts.nodeUrl)}/v1/committee/decrypt`;
|
|
274
|
-
const res = await (opts.fetchImpl ?? fetch)(url, {
|
|
275
|
-
method: 'POST',
|
|
276
|
-
headers: { 'Content-Type': 'application/json' },
|
|
277
|
-
body: JSON.stringify(body),
|
|
278
|
-
});
|
|
279
|
-
if (!res.ok)
|
|
280
|
-
throw await httpError(res, url, 'committee/decrypt');
|
|
281
|
-
const d = (await res.json());
|
|
282
|
-
return base64Decode(d.plaintext);
|
|
355
|
+
void opts;
|
|
356
|
+
throw new Error('custody decryption is retired; use decryptWithCommitteePartials with a client recipient and authenticated verifying shares');
|
|
283
357
|
}
|
|
284
358
|
async function ibeExtractOne(nodeUrl, opts) {
|
|
285
|
-
|
|
359
|
+
let body = {
|
|
286
360
|
committee_token: opts.committeeToken,
|
|
287
|
-
...(opts.
|
|
361
|
+
...evidenceBody(opts.committeeToken, opts.evidenceCt),
|
|
288
362
|
identity: opts.identity,
|
|
363
|
+
recipient: opts.recipient.recipient,
|
|
289
364
|
};
|
|
290
365
|
if (opts.userSignature)
|
|
291
366
|
body.user_signature = bareHex(opts.userSignature);
|
|
@@ -293,26 +368,35 @@ async function ibeExtractOne(nodeUrl, opts) {
|
|
|
293
368
|
body.ciphertext_epoch = opts.ciphertextEpoch;
|
|
294
369
|
if (opts.verifierProofs)
|
|
295
370
|
body.verifier_proofs = proofsToWire(opts.verifierProofs);
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
371
|
+
body = await withKeeperExecutionApprovals({ body, kind: 'ibe-extract', nodeUrl, payment: opts.committeeToken.payment,
|
|
372
|
+
approveExecution: opts.approveExecution, signal: opts.signal });
|
|
373
|
+
// An approver may ignore cancellation. Never dispatch its late authorization.
|
|
374
|
+
opts.signal?.throwIfAborted();
|
|
300
375
|
const url = `${base(nodeUrl)}/v1/shards/ibe/extract`;
|
|
301
376
|
const res = await (opts.fetchImpl ?? fetch)(url, {
|
|
302
377
|
method: 'POST',
|
|
303
378
|
headers: { 'Content-Type': 'application/json' },
|
|
304
379
|
body: JSON.stringify(body),
|
|
305
380
|
signal: opts.signal,
|
|
381
|
+
...(opts.committeeToken.payment ? { redirect: 'error', credentials: 'omit' } : {}),
|
|
306
382
|
});
|
|
383
|
+
const text = await readIbeReply(res, opts.signal);
|
|
384
|
+
opts.signal?.throwIfAborted();
|
|
307
385
|
if (!res.ok)
|
|
308
|
-
throw await httpError(res, url, 'shards/ibe/extract');
|
|
309
|
-
const d =
|
|
310
|
-
const vs = base64Decode(d.verifying_share);
|
|
386
|
+
throw await httpError(new Response(text, { status: res.status }), url, 'shards/ibe/extract');
|
|
387
|
+
const d = JSON.parse(text);
|
|
388
|
+
const vs = base64Decode(d.verifying_share), receipt = decodeOperationReceipt(d);
|
|
389
|
+
const trusted = opts.verifyingShares.get(d.identifier);
|
|
390
|
+
if (!trusted || trusted.length !== 144 || !bytesEqual(vs, trusted) || d.epoch !== opts.ciphertextEpoch || d.key_slot_id?.replace(/^0x/, '').toLowerCase() !== opts.committeeToken.slot_id.replace(/^0x/, '').toLowerCase())
|
|
391
|
+
throw new Error('Sealed extraction differs from authenticated slot/sharing');
|
|
392
|
+
const digest = recipientPayloadDigest(sha256(new TextEncoder().encode(opts.identity)), opts.ciphertextEpoch, opts.recipient.recipient);
|
|
393
|
+
const hash = checkedDecryptionRequestHash(opts.chainId, opts.committeeToken.slot_id, 'ibe-extract', digest, opts.committeeToken.request_hash);
|
|
394
|
+
const partial = await opts.recipient.open(d.sealed_share, hash, d.identifier, d.epoch, trusted);
|
|
311
395
|
return {
|
|
312
396
|
...(d.key_slot_id !== undefined ? { keySlotId: d.key_slot_id } : {}),
|
|
313
|
-
...(
|
|
397
|
+
...(receipt ? { receipt } : {}),
|
|
314
398
|
identifier: Number(d.identifier),
|
|
315
|
-
value:
|
|
399
|
+
value: partial,
|
|
316
400
|
// The reply is the 144-byte dual-group encoding (96B G2 || 48B G1); the IBE pairing
|
|
317
401
|
// check needs the G2 half.
|
|
318
402
|
verifyingShareG2: vs.slice(0, 96),
|
|
@@ -320,6 +404,42 @@ async function ibeExtractOne(nodeUrl, opts) {
|
|
|
320
404
|
nodeUrl,
|
|
321
405
|
};
|
|
322
406
|
}
|
|
407
|
+
export async function readIbeReply(response, signal) {
|
|
408
|
+
const cap = 16 * 1024;
|
|
409
|
+
if (Number(response.headers.get('content-length')) > cap) {
|
|
410
|
+
void response.body?.cancel().catch(() => { });
|
|
411
|
+
throw new Error('Extraction reply exceeds 16 KiB');
|
|
412
|
+
}
|
|
413
|
+
const reader = response.body?.getReader();
|
|
414
|
+
if (!reader)
|
|
415
|
+
return '';
|
|
416
|
+
let bytes = 0, text = '';
|
|
417
|
+
const decoder = new TextDecoder();
|
|
418
|
+
const cancelled = () => { void reader.cancel().catch(() => { }); };
|
|
419
|
+
signal?.addEventListener('abort', cancelled, { once: true });
|
|
420
|
+
try {
|
|
421
|
+
if (signal?.aborted)
|
|
422
|
+
cancelled();
|
|
423
|
+
signal?.throwIfAborted();
|
|
424
|
+
for (;;) {
|
|
425
|
+
const { done, value } = await reader.read();
|
|
426
|
+
signal?.throwIfAborted();
|
|
427
|
+
if (done)
|
|
428
|
+
break;
|
|
429
|
+
bytes += value.length;
|
|
430
|
+
if (bytes > cap)
|
|
431
|
+
throw new Error('Extraction reply exceeds 16 KiB');
|
|
432
|
+
text += decoder.decode(value, { stream: true });
|
|
433
|
+
}
|
|
434
|
+
return text + decoder.decode();
|
|
435
|
+
}
|
|
436
|
+
finally {
|
|
437
|
+
// Includes a streaming cap refusal. Do not wait for a hostile body's cancel hook.
|
|
438
|
+
void reader.cancel().catch(() => { });
|
|
439
|
+
reader.releaseLock();
|
|
440
|
+
signal?.removeEventListener('abort', cancelled);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
323
443
|
/**
|
|
324
444
|
* Fan out to the keeper nodes and collect extraction partials. Nodes that refuse or are
|
|
325
445
|
* down are skipped; throws - naming every node and its reason - only when NONE served.
|
|
@@ -329,23 +449,119 @@ async function ibeExtractOne(nodeUrl, opts) {
|
|
|
329
449
|
* @param opts - Compound token, identity, keepers and optional expected epoch.
|
|
330
450
|
*/
|
|
331
451
|
export async function requestIbeExtractionPartials(opts) {
|
|
452
|
+
opts = { ...opts };
|
|
453
|
+
const identity = new TextEncoder().encode(opts.identity);
|
|
454
|
+
return collectIbeExtractionPartials(opts, opts.threshold === undefined ? undefined : p => {
|
|
455
|
+
if (!Number.isSafeInteger(p.identifier) || p.identifier < 1 || p.identifier > 65535 ||
|
|
456
|
+
p.value.length !== 48 || p.verifyingShareG2.length !== 96 ||
|
|
457
|
+
!Number.isSafeInteger(p.epoch) || p.epoch < 0 ||
|
|
458
|
+
p.keySlotId !== undefined && strip0x(p.keySlotId).toLowerCase() !== strip0x(opts.committeeToken.slot_id).toLowerCase() ||
|
|
459
|
+
opts.ciphertextEpoch !== undefined && p.epoch !== opts.ciphertextEpoch) {
|
|
460
|
+
throw new Error('Invalid extraction identifier, encoding or epoch');
|
|
461
|
+
}
|
|
462
|
+
ibeVerifyShare(new Map([[p.identifier, p.verifyingShareG2]]), identity, p);
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
/** @internal The strict helper supplies its independent keeper/receipt admission check. */
|
|
466
|
+
export async function collectIbeExtractionPartials(opts, validate) {
|
|
467
|
+
opts = { ...opts, nodeUrls: [...opts.nodeUrls], committeeToken: structuredClone(opts.committeeToken),
|
|
468
|
+
verifierProofs: opts.verifierProofs && structuredClone(opts.verifierProofs), userSignature: opts.userSignature?.slice() };
|
|
469
|
+
if (!opts.recipient || opts.chainId === undefined || !opts.verifyingShares || opts.ciphertextEpoch === undefined)
|
|
470
|
+
throw new Error('Recipient, chain, epoch and authenticated verifying shares required for IBE extraction');
|
|
471
|
+
opts.verifyingShares = new Map([...opts.verifyingShares].map(([id, share]) => [id, share.slice()]));
|
|
472
|
+
const recipientDigest = recipientPayloadDigest(sha256(new TextEncoder().encode(opts.identity)), opts.ciphertextEpoch, opts.recipient.recipient);
|
|
473
|
+
checkedDecryptionRequestHash(opts.chainId, opts.committeeToken.slot_id, 'ibe-extract', recipientDigest, opts.committeeToken.request_hash);
|
|
332
474
|
if (opts.nodeUrls.length === 0)
|
|
333
475
|
throw new Error('requestIbeExtractionPartials: no node URLs');
|
|
334
|
-
const
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
if (
|
|
339
|
-
|
|
340
|
-
.map((r, i) => {
|
|
341
|
-
if (r.status === 'fulfilled')
|
|
342
|
-
return null;
|
|
343
|
-
const e = r.reason;
|
|
344
|
-
return `${opts.nodeUrls[i]}: ${e?.message ?? String(r.reason)}`;
|
|
345
|
-
})
|
|
346
|
-
.filter(Boolean)
|
|
347
|
-
.join('; ');
|
|
348
|
-
throw new Error(`requestIbeExtractionPartials: no node served an extraction — ${why}`);
|
|
476
|
+
const threshold = opts.threshold, timeoutMs = opts.timeoutMs ?? 10_000;
|
|
477
|
+
if (threshold !== undefined && (!Number.isSafeInteger(threshold) || threshold < 1 || threshold > opts.nodeUrls.length)) {
|
|
478
|
+
throw new Error('Invalid extraction threshold');
|
|
479
|
+
}
|
|
480
|
+
if (threshold !== undefined && new Set(opts.nodeUrls.map(base)).size !== opts.nodeUrls.length) {
|
|
481
|
+
throw new Error('Duplicate extraction endpoint');
|
|
349
482
|
}
|
|
350
|
-
|
|
483
|
+
if (!Number.isSafeInteger(timeoutMs) || timeoutMs < 1 || timeoutMs > 2_147_483_647) {
|
|
484
|
+
throw new Error('Invalid extraction timeout');
|
|
485
|
+
}
|
|
486
|
+
opts.signal?.throwIfAborted();
|
|
487
|
+
const controller = new AbortController();
|
|
488
|
+
const requests = { ...opts, signal: controller.signal };
|
|
489
|
+
return new Promise((resolve, reject) => {
|
|
490
|
+
const partials = [], ids = new Set();
|
|
491
|
+
const accepted = new Map();
|
|
492
|
+
const failures = new Map();
|
|
493
|
+
// Keepers that refused only for stale/missing revocation-status attestations: when every
|
|
494
|
+
// failure is one, surface the typed "present again" error instead of a threshold miss.
|
|
495
|
+
const revocation = new Map();
|
|
496
|
+
const pending = new Set(opts.nodeUrls.map((_, i) => i));
|
|
497
|
+
let done = false;
|
|
498
|
+
const failure = () => failures.size > 0 && [...failures.keys()].every(i => revocation.has(i))
|
|
499
|
+
? revocation.values().next().value
|
|
500
|
+
: threshold === undefined
|
|
501
|
+
? new Error(`requestIbeExtractionPartials: no node served an extraction — ${[...failures.values()].join('; ')}`)
|
|
502
|
+
: new ThresholdNotMetError({ got: partials.length, need: threshold, reasons: [...failures.values()] });
|
|
503
|
+
const finish = (error) => {
|
|
504
|
+
if (done)
|
|
505
|
+
return;
|
|
506
|
+
done = true;
|
|
507
|
+
clearTimeout(timer);
|
|
508
|
+
opts.signal?.removeEventListener('abort', cancelled);
|
|
509
|
+
// Abort first, including bodies/approval calls still awaiting a response. A
|
|
510
|
+
// transport ignoring abort may resolve later; that handler clears its partial.
|
|
511
|
+
controller.abort();
|
|
512
|
+
if (error !== undefined) {
|
|
513
|
+
for (const p of partials)
|
|
514
|
+
p.value.fill(0);
|
|
515
|
+
reject(error);
|
|
516
|
+
}
|
|
517
|
+
else
|
|
518
|
+
resolve(threshold === undefined ? [...accepted].sort(([a], [b]) => a - b).map(([, p]) => p) : partials);
|
|
519
|
+
};
|
|
520
|
+
const cancelled = () => finish(opts.signal ? opts.signal.reason : new DOMException('Aborted', 'AbortError'));
|
|
521
|
+
const timer = setTimeout(() => {
|
|
522
|
+
for (const i of pending)
|
|
523
|
+
failures.set(i, `${opts.nodeUrls[i]}: extraction deadline exceeded`);
|
|
524
|
+
finish(threshold === undefined && partials.length > 0 ? undefined : failure());
|
|
525
|
+
}, timeoutMs);
|
|
526
|
+
opts.signal?.addEventListener('abort', cancelled, { once: true });
|
|
527
|
+
// Registration follows the early check; this also closes a custom signal's race.
|
|
528
|
+
if (opts.signal?.aborted) {
|
|
529
|
+
cancelled();
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
for (const [i, url] of opts.nodeUrls.entries()) {
|
|
533
|
+
void ibeExtractOne(url, requests).then(p => {
|
|
534
|
+
if (done) {
|
|
535
|
+
p.value.fill(0);
|
|
536
|
+
return;
|
|
537
|
+
}
|
|
538
|
+
try {
|
|
539
|
+
if (ids.has(p.identifier))
|
|
540
|
+
throw new Error('Duplicate extraction identifier');
|
|
541
|
+
validate?.(p);
|
|
542
|
+
ids.add(p.identifier);
|
|
543
|
+
partials.push(p);
|
|
544
|
+
accepted.set(i, p);
|
|
545
|
+
if (threshold !== undefined && partials.length >= threshold)
|
|
546
|
+
finish();
|
|
547
|
+
}
|
|
548
|
+
catch (error) {
|
|
549
|
+
p.value.fill(0);
|
|
550
|
+
failures.set(i, `${url}: ${error instanceof Error ? error.message : String(error)}`);
|
|
551
|
+
}
|
|
552
|
+
}, (error) => {
|
|
553
|
+
if (error instanceof RevocationStatusError)
|
|
554
|
+
revocation.set(i, error);
|
|
555
|
+
failures.set(i, `${url}: ${error instanceof Error ? error.message : String(error)}`);
|
|
556
|
+
}).finally(() => {
|
|
557
|
+
pending.delete(i);
|
|
558
|
+
if (done)
|
|
559
|
+
return;
|
|
560
|
+
if (pending.size === 0)
|
|
561
|
+
finish(partials.length > 0 && threshold === undefined ? undefined : failure());
|
|
562
|
+
else if (threshold !== undefined && partials.length + pending.size < threshold)
|
|
563
|
+
finish(failure());
|
|
564
|
+
});
|
|
565
|
+
}
|
|
566
|
+
});
|
|
351
567
|
}
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import { type PaymentIntentWire } from './payment.js';
|
|
2
|
+
import type { CompoundTokenWire } from './token.js';
|
|
3
|
+
import type { VerifierProof } from './client.js';
|
|
4
|
+
/** `DOMAIN`: the statement's signed preimage is this prefix followed by its canonical JSON. */
|
|
5
|
+
export declare const DUAL_OPERATION_DOMAIN: Uint8Array<ArrayBuffer>;
|
|
6
|
+
/** `MAX_LIFETIME`: an approval statement is current for at most 300 seconds. */
|
|
7
|
+
export declare const DUAL_OPERATION_MAX_LIFETIME_SECS = 300;
|
|
8
|
+
/** The operation a statement approves (Rust `Operation`, kebab-case). */
|
|
9
|
+
export type DualOperationKind = 'frost-sign' | 'secp256k1-sign' | 'p256-sign' | 'kem-decrypt' | 'ibe-extract';
|
|
10
|
+
/** The Rust `Statement`, field for field, in its serialization order. Byte arrays are JSON number arrays. */
|
|
11
|
+
export interface DualOperationStatement {
|
|
12
|
+
/** Chain the final payment names. */
|
|
13
|
+
chain_id: number;
|
|
14
|
+
/** 32-byte slot ID as a JSON number array. */
|
|
15
|
+
slot: number[];
|
|
16
|
+
/** The approved operation. */
|
|
17
|
+
operation: DualOperationKind;
|
|
18
|
+
/** The slot's key epoch the final payment's keeper assignment names. */
|
|
19
|
+
epoch: number;
|
|
20
|
+
/** 32-byte payload digest of the final operation (SHA-256 of an ECDSA digest), as numbers. */
|
|
21
|
+
payload_digest: number[];
|
|
22
|
+
/** The final payment's request ID, 64 lowercase hex characters. */
|
|
23
|
+
request_id: string;
|
|
24
|
+
/** EIP-712 hash of the final payment intent, as numbers. */
|
|
25
|
+
payment_hash: number[];
|
|
26
|
+
/** Unix seconds the statement becomes current. */
|
|
27
|
+
issued_at: number;
|
|
28
|
+
/** Unix seconds it stops being current (at most 300 s after issue). */
|
|
29
|
+
expires_at: number;
|
|
30
|
+
/** IBE approvals cover a reusable identity capability, not a single ciphertext; null otherwise. */
|
|
31
|
+
identity: string | null;
|
|
32
|
+
}
|
|
33
|
+
/** One approver's signature over the statement (Rust `Approval`). */
|
|
34
|
+
export interface DualOperationApproval {
|
|
35
|
+
/** Approver's Ed25519 public key, hex. */
|
|
36
|
+
approver_pubkey: string;
|
|
37
|
+
/** Ed25519 signature over the statement's exact payload, hex. */
|
|
38
|
+
signature: string;
|
|
39
|
+
/** Membership proofs of a credentialed approver's grant (empty for a static approver). */
|
|
40
|
+
verifier_proofs: {
|
|
41
|
+
verifier_index: number;
|
|
42
|
+
operator: string;
|
|
43
|
+
pubkey: string;
|
|
44
|
+
proof: string[];
|
|
45
|
+
}[];
|
|
46
|
+
/** A credentialed approver's holder-bound dual-approve grant. */
|
|
47
|
+
committee_token?: CompoundTokenWire;
|
|
48
|
+
/** Sealed evidence ciphertext of that grant. */
|
|
49
|
+
evidence_ct?: string;
|
|
50
|
+
}
|
|
51
|
+
/** The `dual_control` field of an operation request (Rust `Proof`). */
|
|
52
|
+
export interface DualOperationProof {
|
|
53
|
+
/** The one statement every approval signs. */
|
|
54
|
+
statement: DualOperationStatement;
|
|
55
|
+
/** Distinct approvals of it. */
|
|
56
|
+
approvals: DualOperationApproval[];
|
|
57
|
+
}
|
|
58
|
+
/** A prepared statement and its exact signed bytes. */
|
|
59
|
+
export interface PreparedDualOperation {
|
|
60
|
+
/** The statement approvers sign. */
|
|
61
|
+
statement: DualOperationStatement;
|
|
62
|
+
/** Hex of the signed preimage (domain + canonical JSON). */
|
|
63
|
+
message_hex: string;
|
|
64
|
+
/** Hex SHA-256 of the preimage: the digest a credentialed approver's dual-approve grant binds. */
|
|
65
|
+
payload_digest: string;
|
|
66
|
+
/** The presentation action a credentialed approver's grant uses. */
|
|
67
|
+
action: 'dual-approve';
|
|
68
|
+
}
|
|
69
|
+
/** One approval with the statement it signs, as an approver hands it back. */
|
|
70
|
+
export interface DualOperationApprovalRecord {
|
|
71
|
+
/** The statement the approver signed. */
|
|
72
|
+
statement: DualOperationStatement;
|
|
73
|
+
/** Its signature (and grant). */
|
|
74
|
+
approval: DualOperationApproval;
|
|
75
|
+
}
|
|
76
|
+
/** An Ed25519 approver: its public key and a callback that signs the exact supplied bytes. */
|
|
77
|
+
export interface DualOperationApprover {
|
|
78
|
+
/** 32-byte Ed25519 public key. */
|
|
79
|
+
publicKey: Uint8Array;
|
|
80
|
+
/** Sign the exact supplied bytes; the SDK verifies the result. */
|
|
81
|
+
sign(payload: Uint8Array): Promise<Uint8Array>;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* `Statement::validate` plus the strict shape serde enforces (`deny_unknown_fields`, exact types).
|
|
85
|
+
* @param s - Candidate statement.
|
|
86
|
+
*/
|
|
87
|
+
export declare function validateDualOperationStatement(s: unknown): asserts s is DualOperationStatement;
|
|
88
|
+
/**
|
|
89
|
+
* `Statement::payload`: the domain followed by serde_json's compact serialization in field order.
|
|
90
|
+
* @param s - A valid statement.
|
|
91
|
+
*/
|
|
92
|
+
export declare function dualOperationPayload(s: DualOperationStatement): Uint8Array;
|
|
93
|
+
/**
|
|
94
|
+
* `Statement::from_payload`: parse signed bytes and refuse any non-canonical encoding.
|
|
95
|
+
* @param bytes - Domain-prefixed statement bytes.
|
|
96
|
+
*/
|
|
97
|
+
export declare function dualOperationFromPayload(bytes: Uint8Array): DualOperationStatement;
|
|
98
|
+
/**
|
|
99
|
+
* `Statement::require_current`: valid and `issued_at <= now < expires_at`.
|
|
100
|
+
* @param s - Statement.
|
|
101
|
+
* @param nowSecs - Clock, Unix seconds.
|
|
102
|
+
*/
|
|
103
|
+
export declare function requireCurrentDualOperation(s: DualOperationStatement, nowSecs?: number): void;
|
|
104
|
+
/**
|
|
105
|
+
* The CLI's `check_ticket`: the statement names exactly this final payment (either backing).
|
|
106
|
+
* @param s - Statement.
|
|
107
|
+
* @param payment - The final paid operation's payment (a debit voucher, if any, is not hashed).
|
|
108
|
+
*/
|
|
109
|
+
export declare function requireDualOperationPayment(s: DualOperationStatement, payment: PaymentIntentWire): void;
|
|
110
|
+
/**
|
|
111
|
+
* `dual-operation prepare`: an approval statement for the final paid operation. Sends nothing.
|
|
112
|
+
* @param input - Final payment, operation, the slot's key epoch, IBE identity, lifetime (≤ 300 s, capped at the payment's expiry).
|
|
113
|
+
*/
|
|
114
|
+
export declare function prepareDualOperation(input: {
|
|
115
|
+
payment: PaymentIntentWire;
|
|
116
|
+
operation: DualOperationKind;
|
|
117
|
+
epoch: number;
|
|
118
|
+
identity?: string;
|
|
119
|
+
ttlSecs?: number;
|
|
120
|
+
nowSecs?: number;
|
|
121
|
+
}): PreparedDualOperation;
|
|
122
|
+
/**
|
|
123
|
+
* `dual-operation approve`: check the statement against the final payment and the approver's own
|
|
124
|
+
* expectations, then sign its exact bytes. A credentialed approver adds its holder-bound
|
|
125
|
+
* dual-approve grant, which must bind this statement.
|
|
126
|
+
* @param input - Prepared statement, final payment, the expected slot and operation digest, the approver and its optional grant.
|
|
127
|
+
*/
|
|
128
|
+
export declare function approveDualOperation(input: {
|
|
129
|
+
prepared: PreparedDualOperation;
|
|
130
|
+
payment: PaymentIntentWire;
|
|
131
|
+
expectSlot: string;
|
|
132
|
+
expectPayloadDigest: string;
|
|
133
|
+
approver: DualOperationApprover;
|
|
134
|
+
authorization?: {
|
|
135
|
+
compound_token: CompoundTokenWire;
|
|
136
|
+
verifier_proofs: VerifierProof[];
|
|
137
|
+
evidence_ct?: string;
|
|
138
|
+
};
|
|
139
|
+
nowSecs?: number;
|
|
140
|
+
}): Promise<DualOperationApprovalRecord>;
|
|
141
|
+
/**
|
|
142
|
+
* `dual-operation assemble`: combine independent approvals of ONE statement into the `dual_control`
|
|
143
|
+
* bundle. Every approval names exactly that statement and verifies strictly over its bytes; the
|
|
144
|
+
* approver keys are distinct and at least `quorum` of them are present (the keeper re-checks them
|
|
145
|
+
* against the on-chain policy).
|
|
146
|
+
* @param input - Prepared statement, approval records and the slot policy's quorum.
|
|
147
|
+
*/
|
|
148
|
+
export declare function assembleDualOperation(input: {
|
|
149
|
+
prepared: PreparedDualOperation;
|
|
150
|
+
approvals: DualOperationApprovalRecord[];
|
|
151
|
+
quorum: number;
|
|
152
|
+
nowSecs?: number;
|
|
153
|
+
}): DualOperationProof;
|
|
154
|
+
/**
|
|
155
|
+
* The client-side half of the keeper gate, before a bundle travels in an operation body: current,
|
|
156
|
+
* the expected operation, and bound to this slot, payload digest and final payment.
|
|
157
|
+
* @param proof - Assembled bundle.
|
|
158
|
+
* @param expected - The operation, slot, SHA-256 of the operation's payload and the final payment.
|
|
159
|
+
*/
|
|
160
|
+
export declare function requireDualOperationProof(proof: DualOperationProof, expected: {
|
|
161
|
+
operation: DualOperationKind;
|
|
162
|
+
slot: Uint8Array;
|
|
163
|
+
payloadDigest: Uint8Array;
|
|
164
|
+
payment: PaymentIntentWire;
|
|
165
|
+
}): void;
|