@t3foundry/tasra-sdk 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1067 -28
- package/README.md +15 -0
- package/dist/app/approvals.d.ts +66 -4
- package/dist/app/approvals.js +153 -16
- package/dist/app/authorization.d.ts +1 -1
- package/dist/app/authorization.js +1 -1
- package/dist/app/browser.d.ts +63 -0
- package/dist/app/browser.js +242 -0
- package/dist/app/client.d.ts +114 -13
- package/dist/app/client.js +302 -76
- package/dist/app/identity.js +21 -9
- package/dist/app/index.d.ts +28 -3
- package/dist/app/index.js +16 -1
- package/dist/app/memory-store.d.ts +7 -0
- package/dist/app/memory-store.js +55 -0
- package/dist/app/node.d.ts +34 -6
- package/dist/app/node.js +387 -64
- package/dist/app/paid-allowance.d.ts +325 -0
- package/dist/app/paid-allowance.js +1290 -0
- package/dist/app/paid-approval.d.ts +122 -0
- package/dist/app/paid-approval.js +379 -0
- package/dist/app/paid-journal.d.ts +51 -0
- package/dist/app/paid-journal.js +117 -0
- package/dist/app/paid-keys.d.ts +12 -0
- package/dist/app/paid-keys.js +20 -0
- package/dist/app/paid-operation.d.ts +821 -0
- package/dist/app/paid-operation.js +1720 -0
- package/dist/app/paid-reservation.d.ts +157 -0
- package/dist/app/paid-reservation.js +323 -0
- package/dist/app/paid-session.d.ts +147 -0
- package/dist/app/paid-session.js +578 -0
- package/dist/app/payer-queue.d.ts +11 -0
- package/dist/app/payer-queue.js +27 -0
- package/dist/app/policy-bootstrap.d.ts +342 -0
- package/dist/app/policy-bootstrap.js +365 -0
- package/dist/app/policy-operation.d.ts +47 -0
- package/dist/app/policy-operation.js +101 -0
- package/dist/app/ready-slot.d.ts +12 -0
- package/dist/app/ready-slot.js +5 -2
- package/dist/app/rotation-lock.d.ts +38 -0
- package/dist/app/rotation-lock.js +42 -0
- package/dist/app/session-decrypt.d.ts +135 -0
- package/dist/app/session-decrypt.js +335 -0
- package/dist/app/session-grants.d.ts +349 -0
- package/dist/app/session-grants.js +811 -0
- package/dist/app/signing-intents.d.ts +78 -0
- package/dist/app/signing-intents.js +95 -0
- package/dist/app/store-commit.d.ts +63 -0
- package/dist/app/store-commit.js +126 -0
- package/dist/app/store-errors.d.ts +8 -0
- package/dist/app/store-errors.js +11 -0
- package/dist/app/tasra-client.d.ts +2 -0
- package/dist/app/tasra-client.js +1 -1
- package/dist/app/wallet.js +4 -1
- package/dist/auth/holderProof.d.ts +3 -0
- package/dist/auth/holderProof.js +8 -7
- package/dist/auth/verifier.d.ts +4 -2
- package/dist/auth/verifier.js +5 -2
- package/dist/chain/abis/index.d.ts +6178 -4101
- package/dist/chain/abis/index.js +3 -0
- package/dist/chain/abis/keyRegistry.d.ts +256 -0
- package/dist/chain/abis/keyRegistry.js +333 -0
- package/dist/chain/abis/prepaidFaultOracle.d.ts +321 -0
- package/dist/chain/abis/prepaidFaultOracle.js +413 -0
- package/dist/chain/abis/settlement.d.ts +2203 -703
- package/dist/chain/abis/settlement.js +2685 -764
- package/dist/chain/allowance.d.ts +358 -0
- package/dist/chain/allowance.js +800 -0
- package/dist/chain/billing.d.ts +85 -0
- package/dist/chain/billing.js +197 -0
- package/dist/chain/chainId.d.ts +13 -0
- package/dist/chain/chainId.js +26 -0
- package/dist/chain/client.d.ts +15 -1
- package/dist/chain/client.js +57 -1
- package/dist/chain/commitmentRecovery.d.ts +51 -0
- package/dist/chain/commitmentRecovery.js +38 -0
- package/dist/chain/committeeClient.d.ts +17 -10
- package/dist/chain/committeeClient.js +64 -16
- package/dist/chain/committeeDraw.d.ts +12 -0
- package/dist/chain/committeeDraw.js +56 -0
- package/dist/chain/custodyHealth.d.ts +212 -0
- package/dist/chain/custodyHealth.js +365 -0
- package/dist/chain/deployments.js +2 -0
- package/dist/chain/events.js +2 -0
- package/dist/chain/headFollower.d.ts +77 -0
- package/dist/chain/headFollower.js +219 -0
- package/dist/chain/headPrefetch.d.ts +23 -0
- package/dist/chain/headPrefetch.js +67 -0
- package/dist/chain/index.d.ts +50 -8
- package/dist/chain/index.js +28 -3
- package/dist/chain/keeperExecution.d.ts +44 -0
- package/dist/chain/keeperExecution.js +127 -0
- package/dist/chain/keeperRecovery.d.ts +78 -0
- package/dist/chain/keeperRecovery.js +91 -0
- package/dist/chain/node.d.ts +24 -1
- package/dist/chain/node.js +88 -43
- package/dist/chain/offchain.d.ts +2 -0
- package/dist/chain/paidAgentTransport.d.ts +38 -0
- package/dist/chain/paidAgentTransport.js +1 -0
- package/dist/chain/paidEpoch.d.ts +66 -0
- package/dist/chain/paidEpoch.js +139 -0
- package/dist/chain/paidPacing.d.ts +81 -0
- package/dist/chain/paidPacing.js +136 -0
- package/dist/chain/pinnedReads.d.ts +49 -0
- package/dist/chain/pinnedReads.js +218 -0
- package/dist/chain/prepaid.d.ts +383 -0
- package/dist/chain/prepaid.js +1046 -0
- package/dist/chain/prepaidEscape.d.ts +274 -0
- package/dist/chain/prepaidEscape.js +432 -0
- package/dist/chain/prepaidFault.d.ts +94 -0
- package/dist/chain/prepaidFault.js +148 -0
- package/dist/chain/receipt.d.ts +24 -0
- package/dist/chain/receipt.js +82 -0
- package/dist/chain/registeredAgent.d.ts +68 -3
- package/dist/chain/registeredAgent.js +143 -42
- package/dist/chain/registeredOperation.d.ts +10 -1
- package/dist/chain/registeredOperation.js +18 -3
- package/dist/chain/registeredPaidAgent.d.ts +254 -0
- package/dist/chain/registeredPaidAgent.js +889 -0
- package/dist/chain/registeredRelay.d.ts +31 -1
- package/dist/chain/registeredRelay.js +164 -43
- package/dist/chain/relayVoucher.d.ts +64 -0
- package/dist/chain/relayVoucher.js +69 -0
- package/dist/chain/reservation.d.ts +239 -0
- package/dist/chain/reservation.js +746 -0
- package/dist/chain/reshareRoster.d.ts +64 -0
- package/dist/chain/reshareRoster.js +85 -0
- package/dist/chain/revertReason.d.ts +8 -0
- package/dist/chain/revertReason.js +2 -1
- package/dist/chain/rotationLock.d.ts +130 -0
- package/dist/chain/rotationLock.js +168 -0
- package/dist/chain/serviceRequestPolicy.d.ts +47 -0
- package/dist/chain/serviceRequestPolicy.js +86 -0
- package/dist/chain/services.d.ts +7 -0
- package/dist/chain/services.js +44 -4
- package/dist/chain/slotClient.js +11 -2
- package/dist/chain/slotHandoff.d.ts +81 -0
- package/dist/chain/slotHandoff.js +166 -0
- package/dist/chain/slotSeed.d.ts +47 -5
- package/dist/chain/slotSeed.js +173 -42
- package/dist/chain/verifierSnapshot.d.ts +36 -0
- package/dist/chain/verifierSnapshot.js +197 -0
- package/dist/chain/write.d.ts +111 -21
- package/dist/chain/write.js +378 -146
- package/dist/committee/blsSharing.d.ts +53 -0
- package/dist/committee/blsSharing.js +90 -0
- package/dist/committee/client.d.ts +62 -23
- package/dist/committee/client.js +288 -72
- package/dist/committee/dual-operation.d.ts +165 -0
- package/dist/committee/dual-operation.js +229 -0
- package/dist/committee/dual-sign.d.ts +26 -1
- package/dist/committee/dual-sign.js +85 -7
- package/dist/committee/ecdsa.d.ts +38 -0
- package/dist/committee/ecdsa.js +87 -15
- package/dist/committee/evidence.d.ts +30 -0
- package/dist/committee/evidence.js +65 -0
- package/dist/committee/execution.d.ts +414 -0
- package/dist/committee/execution.js +446 -0
- package/dist/committee/extraction.js +33 -26
- package/dist/committee/index.d.ts +30 -7
- package/dist/committee/index.js +18 -6
- package/dist/committee/keeperExecution.d.ts +37 -0
- package/dist/committee/keeperExecution.js +141 -0
- package/dist/committee/oauth.d.ts +14 -4
- package/dist/committee/oauth.js +17 -5
- package/dist/committee/payment.d.ts +369 -0
- package/dist/committee/payment.js +339 -0
- package/dist/committee/recovery.d.ts +136 -0
- package/dist/committee/recovery.js +204 -0
- package/dist/committee/recoveryJson.d.ts +2 -0
- package/dist/committee/recoveryJson.js +87 -0
- package/dist/committee/request.d.ts +63 -27
- package/dist/committee/request.js +77 -66
- package/dist/committee/session-grant.d.ts +320 -0
- package/dist/committee/session-grant.js +397 -0
- package/dist/committee/status-refresh.d.ts +257 -0
- package/dist/committee/status-refresh.js +619 -0
- package/dist/committee/token.d.ts +163 -15
- package/dist/committee/token.js +247 -10
- package/dist/crypto/bn254.d.ts +70 -0
- package/dist/crypto/bn254.js +222 -0
- package/dist/crypto/ibe.d.ts +32 -0
- package/dist/crypto/ibe.js +56 -8
- package/dist/crypto/index.d.ts +1 -1
- package/dist/crypto/index.js +1 -1
- package/dist/crypto/kem.d.ts +31 -0
- package/dist/crypto/kem.js +113 -7
- package/dist/crypto/recipient.d.ts +75 -0
- package/dist/crypto/recipient.js +107 -0
- package/dist/decryption/client.d.ts +10 -16
- package/dist/decryption/client.js +8 -76
- package/dist/decryption/index.d.ts +2 -0
- package/dist/decryption/index.js +2 -0
- package/dist/decryption/sealed.d.ts +72 -0
- package/dist/decryption/sealed.js +147 -0
- package/dist/decryption/session.d.ts +115 -0
- package/dist/decryption/session.js +358 -0
- package/dist/errors.d.ts +406 -1
- package/dist/errors.js +400 -5
- package/dist/index.d.ts +9 -2
- package/dist/index.js +6 -1
- package/dist/internal/bounded.d.ts +66 -0
- package/dist/internal/bounded.js +126 -0
- package/dist/internal/network.d.ts +4 -0
- package/dist/internal/network.js +40 -0
- package/dist/internal/retryAfter.d.ts +8 -0
- package/dist/internal/retryAfter.js +28 -0
- package/dist/internal/sleep.d.ts +6 -0
- package/dist/internal/sleep.js +15 -0
- package/dist/internal/typedData.d.ts +13 -0
- package/dist/internal/typedData.js +77 -0
- package/dist/internal/viemErrors.d.ts +26 -0
- package/dist/internal/viemErrors.js +49 -0
- package/dist/oid4vp/binding.d.ts +27 -1
- package/dist/oid4vp/binding.js +36 -1
- package/dist/oid4vp/jose.d.ts +4 -2
- package/dist/oid4vp/jose.js +39 -7
- package/dist/oid4vp/request-object.d.ts +61 -4
- package/dist/oid4vp/request-object.js +140 -5
- package/dist/oid4vp/verifier-agent.d.ts +18 -8
- package/dist/oid4vp/verifier-agent.js +48 -6
- package/dist/oid4vp/wallet.d.ts +2 -4
- package/dist/oid4vp/wallet.js +1 -0
- package/dist/retry.d.ts +78 -0
- package/dist/retry.js +137 -0
- package/dist/signing/frost.d.ts +1 -1
- package/dist/verifier-agent/index.d.ts +41 -5
- package/dist/verifier-agent/index.js +124 -9
- package/dist/verifier-agent/payment.d.ts +7 -0
- package/dist/verifier-agent/payment.js +17 -0
- package/docs/api.md +8 -2
- package/docs/application-api.md +25 -2
- package/docs/chain.md +155 -9
- package/docs/consumer-migrations.md +61 -0
- package/docs/encrypted-notes.md +3 -2
- package/docs/encryption.md +4 -2
- package/docs/errors.md +14 -1
- package/docs/flows.md +2 -2
- package/docs/funding.md +902 -0
- package/docs/native-approvals.md +63 -0
- package/docs/reference/README.md +9 -8
- package/docs/reference/app-browser.md +232 -0
- package/docs/reference/app-node.md +38 -8
- package/docs/reference/app.md +4621 -805
- package/docs/reference/chain-node.md +74 -16
- package/docs/reference/chain.md +6740 -1592
- package/docs/reference/committee.md +5630 -987
- package/docs/reference/main.md +1439 -140
- package/docs/reference/oid4vp.md +297 -144
- package/docs/reference/verifier-agent.md +77 -35
- package/docs/signing.md +6 -0
- package/examples/encrypted-notes.ts +21 -6
- package/examples/getting-started.ts +2 -7
- package/examples/live-config.ts +24 -17
- package/package.json +17 -5
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
// Operation-specific dual-control approvals (keykeeper_committee::dual_operation): an offline
|
|
2
|
+
// statement bound to the final paid request, independent Ed25519 approvals over its exact bytes,
|
|
3
|
+
// and the assembled `dual_control` bundle the keeper's api/dual_operation.rs gate re-verifies.
|
|
4
|
+
// Ported from tasra-cli `dual-operation prepare|approve|assemble` with every check kept; the final
|
|
5
|
+
// payment may be either backing (a per-operation reservation or an ADR-0090 allowance voucher).
|
|
6
|
+
import { ed25519 } from '@noble/curves/ed25519';
|
|
7
|
+
import { sha256 } from '@noble/hashes/sha256';
|
|
8
|
+
import { equalBytes } from '@noble/curves/utils.js';
|
|
9
|
+
import { bytesToHex, hexToBytes } from '../crypto/hex.js';
|
|
10
|
+
import { TasraError } from '../errors.js';
|
|
11
|
+
import { requestHash } from '../oid4vp/binding.js';
|
|
12
|
+
import { assertPaymentIntentWire, paymentIntentHash, prepaidRequestId } from './payment.js';
|
|
13
|
+
/** `DOMAIN`: the statement's signed preimage is this prefix followed by its canonical JSON. */
|
|
14
|
+
export const DUAL_OPERATION_DOMAIN = new TextEncoder().encode('keykeeper:dual-operation:v1\0');
|
|
15
|
+
/** `MAX_LIFETIME`: an approval statement is current for at most 300 seconds. */
|
|
16
|
+
export const DUAL_OPERATION_MAX_LIFETIME_SECS = 300;
|
|
17
|
+
const MAX_APPROVALS = 64;
|
|
18
|
+
const MAX_PAYLOAD = 8192;
|
|
19
|
+
const KINDS = ['frost-sign', 'secp256k1-sign', 'p256-sign', 'kem-decrypt', 'ibe-extract'];
|
|
20
|
+
const ACTION = {
|
|
21
|
+
'frost-sign': 'sign', 'secp256k1-sign': 'eoa-sign', 'p256-sign': 'eoa-sign', 'kem-decrypt': 'decrypt', 'ibe-extract': 'ibe-extract',
|
|
22
|
+
};
|
|
23
|
+
const FIELDS = ['chain_id', 'slot', 'operation', 'epoch', 'payload_digest', 'request_id', 'payment_hash', 'issued_at', 'expires_at', 'identity'];
|
|
24
|
+
const now = () => Math.floor(Date.now() / 1000);
|
|
25
|
+
const u64 = (v) => Number.isSafeInteger(v) && v >= 0;
|
|
26
|
+
const bytes32 = (v) => Array.isArray(v) && v.length === 32 && v.every(b => Number.isInteger(b) && b >= 0 && b <= 255);
|
|
27
|
+
/** Bare lowercase hex, as the CLI writes these fields. */
|
|
28
|
+
const bare = (b) => bytesToHex(b).slice(2);
|
|
29
|
+
const hex32 = (h) => { const b = hexToBytes(h); if (b.length !== 32)
|
|
30
|
+
throw new TasraError('expected 32 bytes'); return b; };
|
|
31
|
+
/**
|
|
32
|
+
* `Statement::validate` plus the strict shape serde enforces (`deny_unknown_fields`, exact types).
|
|
33
|
+
* @param s - Candidate statement.
|
|
34
|
+
*/
|
|
35
|
+
export function validateDualOperationStatement(s) {
|
|
36
|
+
if (!s || typeof s !== 'object' || Array.isArray(s))
|
|
37
|
+
throw new TasraError('invalid dual-operation statement');
|
|
38
|
+
const keys = Object.keys(s);
|
|
39
|
+
if (keys.length !== FIELDS.length || FIELDS.some(k => !Object.hasOwn(s, k)))
|
|
40
|
+
throw new TasraError('invalid dual-operation statement fields');
|
|
41
|
+
const v = s;
|
|
42
|
+
if (!u64(v.chain_id) || !bytes32(v.slot) || !KINDS.includes(v.operation) || !Number.isSafeInteger(v.epoch) || !bytes32(v.payload_digest)
|
|
43
|
+
|| typeof v.request_id !== 'string' || !bytes32(v.payment_hash) || !u64(v.issued_at) || !u64(v.expires_at)
|
|
44
|
+
|| (v.identity !== null && typeof v.identity !== 'string'))
|
|
45
|
+
throw new TasraError('invalid dual-operation statement types');
|
|
46
|
+
if (v.epoch < 0 || !/^[0-9a-f]{64}$/.test(v.request_id) || v.expires_at <= v.issued_at || v.expires_at - v.issued_at > DUAL_OPERATION_MAX_LIFETIME_SECS) {
|
|
47
|
+
throw new TasraError('invalid dual-operation request, epoch or lifetime');
|
|
48
|
+
}
|
|
49
|
+
if (v.operation === 'ibe-extract') {
|
|
50
|
+
if (v.identity === null || v.identity.length === 0 || new TextEncoder().encode(v.identity).length > 1024 || v.identity.includes('\0')) {
|
|
51
|
+
throw new TasraError('IBE approval requires a bounded identity');
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
else if (v.identity !== null)
|
|
55
|
+
throw new TasraError('identity is only valid for IBE approval');
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* `Statement::payload`: the domain followed by serde_json's compact serialization in field order.
|
|
59
|
+
* @param s - A valid statement.
|
|
60
|
+
*/
|
|
61
|
+
export function dualOperationPayload(s) {
|
|
62
|
+
validateDualOperationStatement(s);
|
|
63
|
+
const ordered = Object.fromEntries(FIELDS.map(k => [k, s[k]]));
|
|
64
|
+
const json = new TextEncoder().encode(JSON.stringify(ordered));
|
|
65
|
+
const out = new Uint8Array(DUAL_OPERATION_DOMAIN.length + json.length);
|
|
66
|
+
out.set(DUAL_OPERATION_DOMAIN, 0);
|
|
67
|
+
out.set(json, DUAL_OPERATION_DOMAIN.length);
|
|
68
|
+
return out;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* `Statement::from_payload`: parse signed bytes and refuse any non-canonical encoding.
|
|
72
|
+
* @param bytes - Domain-prefixed statement bytes.
|
|
73
|
+
*/
|
|
74
|
+
export function dualOperationFromPayload(bytes) {
|
|
75
|
+
if (bytes.length > MAX_PAYLOAD)
|
|
76
|
+
throw new TasraError('dual-operation statement exceeds limit');
|
|
77
|
+
if (!equalBytes(bytes.subarray(0, DUAL_OPERATION_DOMAIN.length), DUAL_OPERATION_DOMAIN))
|
|
78
|
+
throw new TasraError('wrong dual-operation domain');
|
|
79
|
+
let value;
|
|
80
|
+
try {
|
|
81
|
+
value = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(bytes.subarray(DUAL_OPERATION_DOMAIN.length)));
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
throw new TasraError('invalid dual-operation statement encoding');
|
|
85
|
+
}
|
|
86
|
+
validateDualOperationStatement(value);
|
|
87
|
+
if (!equalBytes(dualOperationPayload(value), bytes))
|
|
88
|
+
throw new TasraError('noncanonical dual-operation statement');
|
|
89
|
+
return value;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* `Statement::require_current`: valid and `issued_at <= now < expires_at`.
|
|
93
|
+
* @param s - Statement.
|
|
94
|
+
* @param nowSecs - Clock, Unix seconds.
|
|
95
|
+
*/
|
|
96
|
+
export function requireCurrentDualOperation(s, nowSecs = now()) {
|
|
97
|
+
validateDualOperationStatement(s);
|
|
98
|
+
if (nowSecs < s.issued_at || nowSecs >= s.expires_at)
|
|
99
|
+
throw new TasraError('dual-operation approval is not current');
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* The CLI's `check_ticket`: the statement names exactly this final payment (either backing).
|
|
103
|
+
* @param s - Statement.
|
|
104
|
+
* @param payment - The final paid operation's payment (a debit voucher, if any, is not hashed).
|
|
105
|
+
*/
|
|
106
|
+
export function requireDualOperationPayment(s, payment) {
|
|
107
|
+
assertPaymentIntentWire(payment);
|
|
108
|
+
const { debit_voucher: _voucher, ...signed } = payment;
|
|
109
|
+
if (s.chain_id !== payment.chain_id || !equalBytes(Uint8Array.from(s.slot), hex32(payment.slot))
|
|
110
|
+
|| !equalBytes(Uint8Array.from(s.payload_digest), hex32(payment.payload_digest))
|
|
111
|
+
|| s.request_id !== prepaidRequestId(signed).slice(2).toLowerCase()
|
|
112
|
+
|| !equalBytes(Uint8Array.from(s.payment_hash), hex32(paymentIntentHash(signed))))
|
|
113
|
+
throw new TasraError('statement differs from final payment');
|
|
114
|
+
if (payment.action !== ACTION[s.operation] || s.epoch !== payment.keeper_assignment.key_epoch)
|
|
115
|
+
throw new TasraError('wrong action or key epoch');
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* `dual-operation prepare`: an approval statement for the final paid operation. Sends nothing.
|
|
119
|
+
* @param input - Final payment, operation, the slot's key epoch, IBE identity, lifetime (≤ 300 s, capped at the payment's expiry).
|
|
120
|
+
*/
|
|
121
|
+
export function prepareDualOperation(input) {
|
|
122
|
+
const { payment } = input;
|
|
123
|
+
assertPaymentIntentWire(payment);
|
|
124
|
+
const { debit_voucher: _voucher, ...signed } = payment;
|
|
125
|
+
const issued = input.nowSecs ?? now(), ttl = input.ttlSecs ?? DUAL_OPERATION_MAX_LIFETIME_SECS;
|
|
126
|
+
if (!u64(ttl) || ttl === 0)
|
|
127
|
+
throw new TasraError('invalid dual-operation lifetime');
|
|
128
|
+
const statement = { chain_id: payment.chain_id, slot: [...hex32(payment.slot)], operation: input.operation, epoch: input.epoch,
|
|
129
|
+
payload_digest: [...hex32(payment.payload_digest)], request_id: prepaidRequestId(signed).slice(2).toLowerCase(),
|
|
130
|
+
payment_hash: [...hex32(paymentIntentHash(signed))], issued_at: issued, expires_at: Math.min(issued + ttl, payment.expires), identity: input.identity ?? null };
|
|
131
|
+
requireDualOperationPayment(statement, payment);
|
|
132
|
+
const preimage = dualOperationPayload(statement);
|
|
133
|
+
return { statement, message_hex: bare(preimage), payload_digest: bare(sha256(preimage)), action: 'dual-approve' };
|
|
134
|
+
}
|
|
135
|
+
/** The CLI's `statement()` read: current, and its carried bytes are exactly the statement's. */
|
|
136
|
+
function preparedStatement(prepared, nowSecs) {
|
|
137
|
+
requireCurrentDualOperation(prepared.statement, nowSecs);
|
|
138
|
+
if (prepared.message_hex.replace(/^0x/, '').toLowerCase() !== bare(dualOperationPayload(prepared.statement))) {
|
|
139
|
+
throw new TasraError('prepared payload differs from statement');
|
|
140
|
+
}
|
|
141
|
+
return structuredClone(prepared.statement);
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* `dual-operation approve`: check the statement against the final payment and the approver's own
|
|
145
|
+
* expectations, then sign its exact bytes. A credentialed approver adds its holder-bound
|
|
146
|
+
* dual-approve grant, which must bind this statement.
|
|
147
|
+
* @param input - Prepared statement, final payment, the expected slot and operation digest, the approver and its optional grant.
|
|
148
|
+
*/
|
|
149
|
+
export async function approveDualOperation(input) {
|
|
150
|
+
const s = preparedStatement(input.prepared, input.nowSecs);
|
|
151
|
+
requireDualOperationPayment(s, input.payment);
|
|
152
|
+
if (!equalBytes(hex32(input.expectSlot), Uint8Array.from(s.slot)))
|
|
153
|
+
throw new TasraError('unexpected slot');
|
|
154
|
+
if (!equalBytes(hex32(input.expectPayloadDigest), Uint8Array.from(s.payload_digest)))
|
|
155
|
+
throw new TasraError('unexpected operation digest');
|
|
156
|
+
const payload = dualOperationPayload(s), publicKey = input.approver.publicKey.slice();
|
|
157
|
+
const signature = await input.approver.sign(payload.slice());
|
|
158
|
+
if (publicKey.length !== 32 || signature.length !== 64 || !ed25519.verify(signature, payload, publicKey, { zip215: false }))
|
|
159
|
+
throw new TasraError('Invalid local approval signature');
|
|
160
|
+
const approval = { approver_pubkey: bare(publicKey), signature: bare(signature), verifier_proofs: [] };
|
|
161
|
+
if (input.authorization) {
|
|
162
|
+
const token = input.authorization.compound_token;
|
|
163
|
+
const expected = requestHash(s.chain_id, Uint8Array.from(s.slot), 'dual-approve', sha256(payload));
|
|
164
|
+
if (typeof token?.request_hash !== 'string' || !equalBytes(hexToBytes(token.request_hash), expected))
|
|
165
|
+
throw new TasraError('grant authorizes another approval');
|
|
166
|
+
if (token.binding !== 'holder_key')
|
|
167
|
+
throw new TasraError('approval requires holder-bound grant');
|
|
168
|
+
approval.committee_token = structuredClone(token);
|
|
169
|
+
approval.verifier_proofs = input.authorization.verifier_proofs.map(p => ({ verifier_index: p.verifierIndex, operator: p.operator.replace(/^0x/, ''),
|
|
170
|
+
pubkey: p.pubkey.replace(/^0x/, ''), proof: p.proof.map(x => x.replace(/^0x/, '')) }));
|
|
171
|
+
if (input.authorization.evidence_ct !== undefined)
|
|
172
|
+
approval.evidence_ct = input.authorization.evidence_ct;
|
|
173
|
+
}
|
|
174
|
+
return { statement: s, approval };
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* `dual-operation assemble`: combine independent approvals of ONE statement into the `dual_control`
|
|
178
|
+
* bundle. Every approval names exactly that statement and verifies strictly over its bytes; the
|
|
179
|
+
* approver keys are distinct and at least `quorum` of them are present (the keeper re-checks them
|
|
180
|
+
* against the on-chain policy).
|
|
181
|
+
* @param input - Prepared statement, approval records and the slot policy's quorum.
|
|
182
|
+
*/
|
|
183
|
+
export function assembleDualOperation(input) {
|
|
184
|
+
const s = preparedStatement(input.prepared, input.nowSecs);
|
|
185
|
+
if (!Number.isSafeInteger(input.quorum) || input.quorum < 1 || input.quorum > MAX_APPROVALS)
|
|
186
|
+
throw new TasraError('invalid approval quorum');
|
|
187
|
+
if (input.approvals.length > MAX_APPROVALS)
|
|
188
|
+
throw new TasraError('at most 64 approvals');
|
|
189
|
+
const payload = dualOperationPayload(s), seen = new Set(), approvals = [];
|
|
190
|
+
for (const record of input.approvals) {
|
|
191
|
+
validateDualOperationStatement(record.statement);
|
|
192
|
+
if (!equalBytes(dualOperationPayload(record.statement), payload))
|
|
193
|
+
throw new TasraError('approvals name different operations');
|
|
194
|
+
const a = record.approval;
|
|
195
|
+
if (typeof a?.approver_pubkey !== 'string' || typeof a.signature !== 'string')
|
|
196
|
+
throw new TasraError('missing approver or signature');
|
|
197
|
+
const key = hexToBytes(a.approver_pubkey), signature = hexToBytes(a.signature);
|
|
198
|
+
if (key.length !== 32)
|
|
199
|
+
throw new TasraError('invalid key length');
|
|
200
|
+
if (signature.length !== 64)
|
|
201
|
+
throw new TasraError('invalid signature length');
|
|
202
|
+
if (!ed25519.verify(signature, payload, key, { zip215: false }))
|
|
203
|
+
throw new TasraError('approval signature does not verify over the statement');
|
|
204
|
+
const id = bare(key);
|
|
205
|
+
if (seen.has(id))
|
|
206
|
+
throw new TasraError('duplicate approver');
|
|
207
|
+
seen.add(id);
|
|
208
|
+
approvals.push(structuredClone(a));
|
|
209
|
+
}
|
|
210
|
+
if (approvals.length < input.quorum)
|
|
211
|
+
throw new TasraError(`dual-operation needs ${input.quorum} distinct approvals, has ${approvals.length}`);
|
|
212
|
+
return { statement: s, approvals };
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* The client-side half of the keeper gate, before a bundle travels in an operation body: current,
|
|
216
|
+
* the expected operation, and bound to this slot, payload digest and final payment.
|
|
217
|
+
* @param proof - Assembled bundle.
|
|
218
|
+
* @param expected - The operation, slot, SHA-256 of the operation's payload and the final payment.
|
|
219
|
+
*/
|
|
220
|
+
export function requireDualOperationProof(proof, expected) {
|
|
221
|
+
requireCurrentDualOperation(proof.statement);
|
|
222
|
+
const s = proof.statement;
|
|
223
|
+
if (s.operation !== expected.operation || !equalBytes(Uint8Array.from(s.slot), expected.slot) || !equalBytes(Uint8Array.from(s.payload_digest), expected.payloadDigest)) {
|
|
224
|
+
throw new TasraError('dual-operation approvals name another operation, slot or digest');
|
|
225
|
+
}
|
|
226
|
+
requireDualOperationPayment(s, expected.payment);
|
|
227
|
+
if (!Array.isArray(proof.approvals) || proof.approvals.length === 0 || proof.approvals.length > MAX_APPROVALS)
|
|
228
|
+
throw new TasraError('invalid dual-operation approvals');
|
|
229
|
+
}
|
|
@@ -2,6 +2,8 @@ import { TasraError } from '../errors.js';
|
|
|
2
2
|
import type { FrostSignResult } from '../signing/frost.js';
|
|
3
3
|
import type { CompoundTokenWire } from './token.js';
|
|
4
4
|
import type { VerifierProof } from './client.js';
|
|
5
|
+
import { type PaymentIntentWire } from './payment.js';
|
|
6
|
+
import { type KeeperExecutionApprover } from './keeperExecution.js';
|
|
5
7
|
/** A signing request may have been accepted despite a transport or response failure. Reconcile before resubmitting. */
|
|
6
8
|
export declare class OperationOutcomeUnknownError extends TasraError {
|
|
7
9
|
/** Request phase whose submission outcome must be reconciled. */
|
|
@@ -22,8 +24,22 @@ export declare class OperationOutcomeUnknownError extends TasraError {
|
|
|
22
24
|
* @param requestId - Existing native signing request identifier.
|
|
23
25
|
*/
|
|
24
26
|
export declare function dualSignApprovalPayload(slotId: string, message: Uint8Array, requestId: string): Uint8Array;
|
|
27
|
+
/**
|
|
28
|
+
* Paid approval bytes, binding the final keeper reservation independently of each
|
|
29
|
+
* credential approval's payment. Matches Rust canonical_paid_dual_sig_payload.
|
|
30
|
+
* @param chainId - Expected deployment chain.
|
|
31
|
+
* @param slotId - Expected slot identifier.
|
|
32
|
+
* @param message - Exact message to sign.
|
|
33
|
+
* @param requestId - Native dual-sign request identifier.
|
|
34
|
+
* @param payment - Final keeper Sign intent, already reserved independently.
|
|
35
|
+
*/
|
|
36
|
+
export declare function paidDualSignApprovalPayload(chainId: number, slotId: string, message: Uint8Array, requestId: string, payment: PaymentIntentWire): Uint8Array;
|
|
25
37
|
/** Trusted slot key, keeper endpoint and approver policy for a native signing request. */
|
|
26
38
|
export interface DualSignConfig {
|
|
39
|
+
/** Required for paid creation: original client's complete final-work approvals. */
|
|
40
|
+
approveExecution?: KeeperExecutionApprover;
|
|
41
|
+
/** Optional pinned final Sign payment for this coordinator; per-call replacements are refused. */
|
|
42
|
+
payment?: PaymentIntentWire;
|
|
27
43
|
/** EVM chain identifier. */
|
|
28
44
|
chainId: number;
|
|
29
45
|
/** Keeper HTTP base URL. */
|
|
@@ -57,6 +73,9 @@ export type DualSignStatus = {
|
|
|
57
73
|
} | {
|
|
58
74
|
/** Lifecycle state: pending or signing until the request is signed or fails. */
|
|
59
75
|
status: 'failed';
|
|
76
|
+
} | {
|
|
77
|
+
/** Work may have started, but its durable outcome is unavailable. Never retry the ceremony. */
|
|
78
|
+
status: 'uncertain';
|
|
60
79
|
};
|
|
61
80
|
/** Ed25519 approver public key and callback that signs canonical approval bytes. */
|
|
62
81
|
export interface DualSignApprover {
|
|
@@ -67,6 +86,8 @@ export interface DualSignApprover {
|
|
|
67
86
|
}
|
|
68
87
|
/** Handle for checking, approving and waiting for one native multi-approver signing request. */
|
|
69
88
|
export interface DualSignRequest {
|
|
89
|
+
/** Final keeper Sign intent; each access returns a copy. Credential approvals pay separately. */
|
|
90
|
+
readonly payment?: PaymentIntentWire;
|
|
70
91
|
/** Request identifier used to correlate or resume the operation. */
|
|
71
92
|
readonly requestId: string;
|
|
72
93
|
/** 32-byte slot identifier. */
|
|
@@ -84,6 +105,7 @@ export interface DualSignRequest {
|
|
|
84
105
|
authorization?: {
|
|
85
106
|
token: CompoundTokenWire;
|
|
86
107
|
verifierProofs: VerifierProof[];
|
|
108
|
+
evidenceCt?: string;
|
|
87
109
|
};
|
|
88
110
|
signal?: AbortSignal;
|
|
89
111
|
}): Promise<DualSignStatus>;
|
|
@@ -105,6 +127,9 @@ export interface DualSignRequest {
|
|
|
105
127
|
export declare function createDualSignClient(input: DualSignConfig): {
|
|
106
128
|
create(message: Uint8Array, options?: {
|
|
107
129
|
signal?: AbortSignal;
|
|
130
|
+
payment?: PaymentIntentWire;
|
|
108
131
|
}): Promise<DualSignRequest>;
|
|
109
|
-
resume(requestId: string, expectedMessage: Uint8Array
|
|
132
|
+
resume(requestId: string, expectedMessage: Uint8Array, options?: {
|
|
133
|
+
payment?: PaymentIntentWire;
|
|
134
|
+
}): DualSignRequest;
|
|
110
135
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { evidenceBody } from './evidence.js';
|
|
1
2
|
import { equalBytes } from '@noble/curves/utils.js';
|
|
2
3
|
import { ed25519 } from '@noble/curves/ed25519';
|
|
3
4
|
import { sha256 } from '@noble/hashes/sha256';
|
|
@@ -6,6 +7,8 @@ import { verify } from '../crypto/frost.js';
|
|
|
6
7
|
import { TasraError, httpError } from '../errors.js';
|
|
7
8
|
import { decodeOperationReceipt, protocolHex } from './receipts.js';
|
|
8
9
|
import { requestHash } from '../oid4vp/binding.js';
|
|
10
|
+
import { assertPaymentIntentWire, paymentIntentHash, prepaidRequestId } from './payment.js';
|
|
11
|
+
import { withKeeperExecutionApprovals } from './keeperExecution.js';
|
|
9
12
|
/** A signing request may have been accepted despite a transport or response failure. Reconcile before resubmitting. */
|
|
10
13
|
export class OperationOutcomeUnknownError extends TasraError {
|
|
11
14
|
operation;
|
|
@@ -40,6 +43,29 @@ export function dualSignApprovalPayload(slotId, message, requestId) {
|
|
|
40
43
|
return [size, value];
|
|
41
44
|
}));
|
|
42
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Paid approval bytes, binding the final keeper reservation independently of each
|
|
48
|
+
* credential approval's payment. Matches Rust canonical_paid_dual_sig_payload.
|
|
49
|
+
* @param chainId - Expected deployment chain.
|
|
50
|
+
* @param slotId - Expected slot identifier.
|
|
51
|
+
* @param message - Exact message to sign.
|
|
52
|
+
* @param requestId - Native dual-sign request identifier.
|
|
53
|
+
* @param payment - Final keeper Sign intent, already reserved independently.
|
|
54
|
+
*/
|
|
55
|
+
export function paidDualSignApprovalPayload(chainId, slotId, message, requestId, payment) {
|
|
56
|
+
requestIdentifier(requestId);
|
|
57
|
+
assertPaymentIntentWire(payment);
|
|
58
|
+
const slot = protocolHex(slotId, 32, 'slot id'), digest = sha256(message), rid = utf8ToBytes(requestId);
|
|
59
|
+
if (payment.chain_id !== chainId || payment.action !== 'sign' ||
|
|
60
|
+
!equalBytes(protocolHex(payment.slot, 32, 'payment slot'), slot) ||
|
|
61
|
+
!equalBytes(protocolHex(payment.payload_digest, 32, 'payment digest'), digest))
|
|
62
|
+
throw new TasraError('Dual-sign payment differs from chain, slot, message or action');
|
|
63
|
+
const chain = new Uint8Array(8), slotSize = new Uint8Array(8), ridSize = new Uint8Array(8);
|
|
64
|
+
new DataView(chain.buffer).setBigUint64(0, BigInt(chainId));
|
|
65
|
+
new DataView(slotSize.buffer).setBigUint64(0, BigInt(slot.length), true);
|
|
66
|
+
new DataView(ridSize.buffer).setBigUint64(0, BigInt(rid.length), true);
|
|
67
|
+
return concatBytes(utf8ToBytes('keykeeper:paid-dual-sig:v1'), chain, slotSize, slot, digest, ridSize, rid, protocolHex(paymentIntentHash(payment), 32, 'payment hash'));
|
|
68
|
+
}
|
|
43
69
|
/**
|
|
44
70
|
* Native multi-approver FROST lifecycle. Never falls back to a JWT route or creates
|
|
45
71
|
* a new request after an ambiguous POST. All approval and result checks use the
|
|
@@ -53,15 +79,25 @@ export function createDualSignClient(input) {
|
|
|
53
79
|
throw new TasraError('Invalid dual-sign chain, key or quorum');
|
|
54
80
|
const nodeUrl = input.nodeUrl.replace(/\/$/, ''), slotId = '0x' + bytesToHex(slot);
|
|
55
81
|
const quorum = input.quorum, chainId = input.chainId, credentialed = input.credentialGated, fetchImpl = input.fetchImpl ?? fetch;
|
|
82
|
+
const approveExecution = input.approveExecution;
|
|
56
83
|
const timeoutMs = input.timeoutMs ?? 30_000;
|
|
57
84
|
if (!Number.isSafeInteger(timeoutMs) || timeoutMs <= 0)
|
|
58
85
|
throw new TasraError('Invalid request timeout');
|
|
86
|
+
const pinnedPayment = input.payment && structuredClone(input.payment);
|
|
87
|
+
if (pinnedPayment)
|
|
88
|
+
assertPaymentIntentWire(pinnedPayment);
|
|
89
|
+
function selectedPayment(supplied) {
|
|
90
|
+
const payment = supplied && structuredClone(supplied);
|
|
91
|
+
if (payment && pinnedPayment && paymentIntentHash(payment) !== paymentIntentHash(pinnedPayment))
|
|
92
|
+
throw new TasraError('Cannot replace the pinned dual-sign payment');
|
|
93
|
+
return payment ?? (pinnedPayment && structuredClone(pinnedPayment));
|
|
94
|
+
}
|
|
59
95
|
async function http(path, signal, body, requestId) {
|
|
60
96
|
signal?.throwIfAborted();
|
|
61
97
|
const deadline = AbortSignal.timeout(timeoutMs);
|
|
62
98
|
let response;
|
|
63
99
|
try {
|
|
64
|
-
response = await fetchImpl(nodeUrl + path, { method: body === undefined ? 'GET' : 'POST',
|
|
100
|
+
response = await fetchImpl(nodeUrl + path, { method: body === undefined ? 'GET' : 'POST', redirect: 'error', credentials: 'omit',
|
|
65
101
|
signal: signal ? AbortSignal.any([signal, deadline]) : deadline,
|
|
66
102
|
headers: { 'Content-Type': 'application/json' }, body: body === undefined ? undefined : JSON.stringify(body) });
|
|
67
103
|
}
|
|
@@ -109,8 +145,14 @@ export function createDualSignClient(input) {
|
|
|
109
145
|
const receipt = decodeOperationReceipt(d);
|
|
110
146
|
return { keySlotId: slotId, groupPublicKey: publicKey, signature, messageSha256: sha256(message), epoch: Number(d.epoch), ...(receipt ? { receipt } : {}) };
|
|
111
147
|
}
|
|
112
|
-
function handle(requestId, message) {
|
|
148
|
+
function handle(requestId, message, options = {}) {
|
|
113
149
|
requestIdentifier(requestId);
|
|
150
|
+
const payment = selectedPayment(options.payment);
|
|
151
|
+
if (payment) {
|
|
152
|
+
paidDualSignApprovalPayload(chainId, slotId, message, requestId, payment);
|
|
153
|
+
if (requestId !== prepaidRequestId(payment).slice(2))
|
|
154
|
+
throw new TasraError('Dual-sign request differs from final payment');
|
|
155
|
+
}
|
|
114
156
|
const original = message.slice(), path = '/v1/dual-sign/' + requestId;
|
|
115
157
|
const status = async (options = {}) => {
|
|
116
158
|
const d = await http(path, options.signal);
|
|
@@ -118,12 +160,15 @@ export function createDualSignClient(input) {
|
|
|
118
160
|
return { status: 'signed', result: signed(d.reply, original) };
|
|
119
161
|
if (d.status === 'failed')
|
|
120
162
|
return { status: 'failed' };
|
|
163
|
+
if (d.status === 'uncertain')
|
|
164
|
+
return { status: 'uncertain' };
|
|
121
165
|
if (d.status !== 'pending' && d.status !== 'signing')
|
|
122
166
|
throw new TasraError('Invalid dual-sign status');
|
|
123
167
|
bound(d, original);
|
|
124
168
|
return { status: d.status, ...counts(d) };
|
|
125
169
|
};
|
|
126
170
|
return Object.freeze({ requestId, slotId, nodeUrl, status,
|
|
171
|
+
get payment() { return payment && structuredClone(payment); },
|
|
127
172
|
async approve(options) {
|
|
128
173
|
const before = await status({ signal: options.signal });
|
|
129
174
|
if (before.status !== 'pending')
|
|
@@ -131,19 +176,32 @@ export function createDualSignClient(input) {
|
|
|
131
176
|
if (credentialed !== Boolean(options.authorization))
|
|
132
177
|
throw new TasraError('Dual-sign approval authorization does not match the slot policy');
|
|
133
178
|
const publicKey = options.signer.publicKey.slice();
|
|
134
|
-
|
|
179
|
+
if (payment && payment.expires <= Math.floor(Date.now() / 1000))
|
|
180
|
+
throw new TasraError('Dual-sign payment expired');
|
|
181
|
+
const payload = payment ? paidDualSignApprovalPayload(chainId, slotId, original, requestId, payment)
|
|
182
|
+
: dualSignApprovalPayload(slotId, original, requestId);
|
|
135
183
|
const grant = options.authorization && structuredClone(options.authorization);
|
|
136
184
|
if (grant && (!equalBytes(protocolHex(grant.token.slot_id, 32, 'grant slot'), slot) || !grant.verifierProofs.length ||
|
|
137
185
|
grant.token.binding !== 'holder_key' || !Number.isSafeInteger(grant.token.exp) || grant.token.exp * 1000 <= Date.now() ||
|
|
138
186
|
!equalBytes(protocolHex(grant.token.request_hash, 32, 'approval request hash'), requestHash(chainId, slot, 'dual-approve', sha256(payload))))) {
|
|
139
187
|
throw new TasraError('Approval grant must bind this request and holder and include verifier proofs');
|
|
140
188
|
}
|
|
189
|
+
if (grant && payment) {
|
|
190
|
+
assertPaymentIntentWire(grant.token.payment);
|
|
191
|
+
const approval = grant.token.payment;
|
|
192
|
+
if (approval.action !== 'dual-approve' || approval.chain_id !== chainId || approval.expires <= Math.floor(Date.now() / 1000) ||
|
|
193
|
+
!equalBytes(protocolHex(approval.slot, 32, 'approval slot'), slot) ||
|
|
194
|
+
!equalBytes(protocolHex(approval.payload_digest, 32, 'approval digest'), sha256(payload)) ||
|
|
195
|
+
!equalBytes(protocolHex(grant.token.payment_hash, 32, 'approval payment hash'), protocolHex(paymentIntentHash(approval), 32, 'payment hash'))) {
|
|
196
|
+
throw new TasraError('Credential approval requires its own bound payment');
|
|
197
|
+
}
|
|
198
|
+
}
|
|
141
199
|
const signature = await options.signer.sign(payload.slice());
|
|
142
200
|
options.signal?.throwIfAborted();
|
|
143
201
|
if (publicKey.length !== 32 || signature.length !== 64 || !ed25519.verify(signature, payload, publicKey, { zip215: false }))
|
|
144
202
|
throw new TasraError('Invalid local approval signature');
|
|
145
203
|
const d = await http(path + '/approve', options.signal, { approver_pubkey: bytesToHex(publicKey), signature: bytesToHex(signature),
|
|
146
|
-
...(grant ? { committee_token: grant.token, verifier_proofs: grant.verifierProofs.map(p => ({ verifier_index: p.verifierIndex,
|
|
204
|
+
...(grant ? { ...evidenceBody(grant.token, grant.evidenceCt), committee_token: grant.token, verifier_proofs: grant.verifierProofs.map(p => ({ verifier_index: p.verifierIndex,
|
|
147
205
|
operator: p.operator.replace(/^0x/, ''), pubkey: p.pubkey.replace(/^0x/, ''), proof: p.proof.map(x => x.replace(/^0x/, '')) })) } : {}) }, requestId);
|
|
148
206
|
try {
|
|
149
207
|
const count = counts(d);
|
|
@@ -170,6 +228,8 @@ export function createDualSignClient(input) {
|
|
|
170
228
|
return current.result;
|
|
171
229
|
if (current.status === 'failed')
|
|
172
230
|
throw new TasraError('Native dual-sign request failed');
|
|
231
|
+
if (current.status === 'uncertain')
|
|
232
|
+
throw new OperationOutcomeUnknownError('dual-approve', requestId);
|
|
173
233
|
await new Promise((resolve, reject) => {
|
|
174
234
|
const done = () => { signal.removeEventListener('abort', abort); resolve(); };
|
|
175
235
|
const timer = setTimeout(done, interval);
|
|
@@ -185,16 +245,34 @@ export function createDualSignClient(input) {
|
|
|
185
245
|
return {
|
|
186
246
|
async create(message, options = {}) {
|
|
187
247
|
const original = message.slice();
|
|
188
|
-
const
|
|
248
|
+
const signal = options.signal;
|
|
249
|
+
const payment = selectedPayment(options.payment);
|
|
250
|
+
const expectedId = payment && prepaidRequestId(payment).slice(2);
|
|
251
|
+
const payload = payment && paidDualSignApprovalPayload(chainId, slotId, original, expectedId, payment);
|
|
252
|
+
if (payment && payment.expires <= Math.floor(Date.now() / 1000))
|
|
253
|
+
throw new TasraError('Dual-sign payment expired');
|
|
254
|
+
const creationBody = await withKeeperExecutionApprovals({ body: { key_slot_id: slotId, message_hex: bytesToHex(original), ...(payment ? { payment } : {}) },
|
|
255
|
+
kind: 'dual-sign', nodeUrl, payment, approveExecution, signal });
|
|
256
|
+
let d;
|
|
257
|
+
try {
|
|
258
|
+
d = await http('/v1/dual-sign', signal, creationBody);
|
|
259
|
+
}
|
|
260
|
+
catch (cause) {
|
|
261
|
+
if (cause instanceof OperationOutcomeUnknownError && expectedId)
|
|
262
|
+
throw new OperationOutcomeUnknownError('dual-create', expectedId, cause);
|
|
263
|
+
throw cause;
|
|
264
|
+
}
|
|
189
265
|
try {
|
|
190
266
|
bound(d, original);
|
|
191
267
|
counts(d);
|
|
192
268
|
if (d.have !== 0 || d.credential_gated !== credentialed || typeof d.request_id !== 'string')
|
|
193
269
|
throw new TasraError('Invalid dual-sign creation reply');
|
|
194
|
-
|
|
270
|
+
if (payment && (d.request_id !== expectedId || !equalBytes(protocolHex(d.approval_payload, payload.length, 'approval payload'), payload)))
|
|
271
|
+
throw new TasraError('Keeper changed paid approval binding');
|
|
272
|
+
return handle(d.request_id, original, { payment });
|
|
195
273
|
}
|
|
196
274
|
catch (cause) {
|
|
197
|
-
throw new OperationOutcomeUnknownError('dual-create', typeof d.request_id === 'string' ? d.request_id : undefined, cause);
|
|
275
|
+
throw new OperationOutcomeUnknownError('dual-create', expectedId ?? (typeof d.request_id === 'string' ? d.request_id : undefined), cause);
|
|
198
276
|
}
|
|
199
277
|
},
|
|
200
278
|
resume: handle,
|
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
import type { EoaSignature } from '../signing/ecdsa.js';
|
|
2
2
|
import type { CompoundTokenWire } from './token.js';
|
|
3
3
|
import type { VerifierProof } from './client.js';
|
|
4
|
+
import { type KeeperExecutionApprover } from './keeperExecution.js';
|
|
5
|
+
import { type DualOperationProof } from './dual-operation.js';
|
|
4
6
|
/** Compound authorization, keeper endpoint and digest for threshold ECDSA signing. */
|
|
5
7
|
export interface CommitteeEoaSignOpts {
|
|
8
|
+
/** Exact sealed presentation ciphertext returned with this authorization. */
|
|
9
|
+
evidenceCt?: string;
|
|
10
|
+
/** Required for a paid token: locally verify and approve the complete keeper body. */
|
|
11
|
+
approveExecution?: KeeperExecutionApprover;
|
|
6
12
|
/** HTTP transport override; defaults to the global fetch implementation. */
|
|
7
13
|
fetchImpl?: typeof fetch;
|
|
8
14
|
/** Keeper HTTP base URL. */
|
|
@@ -21,6 +27,12 @@ export interface CommitteeEoaSignOpts {
|
|
|
21
27
|
targetKeykeeper?: string;
|
|
22
28
|
/** Optional signal that cancels the request. */
|
|
23
29
|
signal?: AbortSignal;
|
|
30
|
+
/**
|
|
31
|
+
* Dual-control approvals for this exact operation (assembleDualOperation). Required by a slot
|
|
32
|
+
* under an operation dual-control policy; checked here against the token's slot, SHA-256 of the
|
|
33
|
+
* digest and the token's own payment, then carried inside the client-approved body.
|
|
34
|
+
*/
|
|
35
|
+
dualControl?: DualOperationProof;
|
|
24
36
|
}
|
|
25
37
|
/**
|
|
26
38
|
* Sign an Ethereum digest using credential-based committee authorization.
|
|
@@ -30,7 +42,33 @@ export interface CommitteeEoaSignOpts {
|
|
|
30
42
|
* @returns Ethereum signature components and the secp256k1 group public key.
|
|
31
43
|
* @throws On malformed input/response, network failure, or keeper rejection.
|
|
32
44
|
* HTTP 401/403 is an authorization denial; do not retry it as a network failure.
|
|
45
|
+
* Approvals, HTTP and response decoding have one 15-second deadline. A timeout
|
|
46
|
+
* requires reconciliation of the original operation, not a new paid attempt.
|
|
33
47
|
*
|
|
34
48
|
* @param opts - Compound authorization, keeper endpoint and 32-byte ECDSA digest.
|
|
35
49
|
*/
|
|
36
50
|
export declare function committeeSignEoaDigest(opts: CommitteeEoaSignOpts): Promise<EoaSignature>;
|
|
51
|
+
/** Threshold P-256 digest signature (a `tecdsa-p256` slot, mode 4). */
|
|
52
|
+
export interface P256DigestSignature {
|
|
53
|
+
/** The slot's P-256 group public key, as the keeper returned it (equal to the expected key). */
|
|
54
|
+
groupPublicKey: Uint8Array;
|
|
55
|
+
/** 32-byte big-endian r. */
|
|
56
|
+
r: Uint8Array;
|
|
57
|
+
/** 32-byte big-endian s. */
|
|
58
|
+
s: Uint8Array;
|
|
59
|
+
}
|
|
60
|
+
/** {@link committeeSignEoaDigest} options plus the slot key the signature must verify under. */
|
|
61
|
+
export interface CommitteeP256SignOpts extends CommitteeEoaSignOpts {
|
|
62
|
+
/** The slot's anchored P-256 group public key (33-byte compressed or 65-byte uncompressed SEC1). */
|
|
63
|
+
groupPublicKey: Uint8Array;
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Sign a 32-byte digest with a threshold P-256 (`tecdsa-p256`) slot through the same keeper route
|
|
67
|
+
* and authorization as {@link committeeSignEoaDigest}. The reply must name mode `tecdsa-p256`,
|
|
68
|
+
* carry the expected group key and verify as a P-256 signature over the digest (no prehash);
|
|
69
|
+
* anything else is refused.
|
|
70
|
+
* @param opts - Compound authorization, keeper endpoint, 32-byte digest and the slot's group key.
|
|
71
|
+
* @returns r, s and the group key.
|
|
72
|
+
* @throws On malformed input/response, a signature that does not verify, network failure or keeper rejection.
|
|
73
|
+
*/
|
|
74
|
+
export declare function committeeSignP256Digest(opts: CommitteeP256SignOpts): Promise<P256DigestSignature>;
|