@t3foundry/tasra-sdk 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1067 -28
- package/README.md +15 -0
- package/dist/app/approvals.d.ts +66 -4
- package/dist/app/approvals.js +153 -16
- package/dist/app/authorization.d.ts +1 -1
- package/dist/app/authorization.js +1 -1
- package/dist/app/browser.d.ts +63 -0
- package/dist/app/browser.js +242 -0
- package/dist/app/client.d.ts +114 -13
- package/dist/app/client.js +302 -76
- package/dist/app/identity.js +21 -9
- package/dist/app/index.d.ts +28 -3
- package/dist/app/index.js +16 -1
- package/dist/app/memory-store.d.ts +7 -0
- package/dist/app/memory-store.js +55 -0
- package/dist/app/node.d.ts +34 -6
- package/dist/app/node.js +387 -64
- package/dist/app/paid-allowance.d.ts +325 -0
- package/dist/app/paid-allowance.js +1290 -0
- package/dist/app/paid-approval.d.ts +122 -0
- package/dist/app/paid-approval.js +379 -0
- package/dist/app/paid-journal.d.ts +51 -0
- package/dist/app/paid-journal.js +117 -0
- package/dist/app/paid-keys.d.ts +12 -0
- package/dist/app/paid-keys.js +20 -0
- package/dist/app/paid-operation.d.ts +821 -0
- package/dist/app/paid-operation.js +1720 -0
- package/dist/app/paid-reservation.d.ts +157 -0
- package/dist/app/paid-reservation.js +323 -0
- package/dist/app/paid-session.d.ts +147 -0
- package/dist/app/paid-session.js +578 -0
- package/dist/app/payer-queue.d.ts +11 -0
- package/dist/app/payer-queue.js +27 -0
- package/dist/app/policy-bootstrap.d.ts +342 -0
- package/dist/app/policy-bootstrap.js +365 -0
- package/dist/app/policy-operation.d.ts +47 -0
- package/dist/app/policy-operation.js +101 -0
- package/dist/app/ready-slot.d.ts +12 -0
- package/dist/app/ready-slot.js +5 -2
- package/dist/app/rotation-lock.d.ts +38 -0
- package/dist/app/rotation-lock.js +42 -0
- package/dist/app/session-decrypt.d.ts +135 -0
- package/dist/app/session-decrypt.js +335 -0
- package/dist/app/session-grants.d.ts +349 -0
- package/dist/app/session-grants.js +811 -0
- package/dist/app/signing-intents.d.ts +78 -0
- package/dist/app/signing-intents.js +95 -0
- package/dist/app/store-commit.d.ts +63 -0
- package/dist/app/store-commit.js +126 -0
- package/dist/app/store-errors.d.ts +8 -0
- package/dist/app/store-errors.js +11 -0
- package/dist/app/tasra-client.d.ts +2 -0
- package/dist/app/tasra-client.js +1 -1
- package/dist/app/wallet.js +4 -1
- package/dist/auth/holderProof.d.ts +3 -0
- package/dist/auth/holderProof.js +8 -7
- package/dist/auth/verifier.d.ts +4 -2
- package/dist/auth/verifier.js +5 -2
- package/dist/chain/abis/index.d.ts +6178 -4101
- package/dist/chain/abis/index.js +3 -0
- package/dist/chain/abis/keyRegistry.d.ts +256 -0
- package/dist/chain/abis/keyRegistry.js +333 -0
- package/dist/chain/abis/prepaidFaultOracle.d.ts +321 -0
- package/dist/chain/abis/prepaidFaultOracle.js +413 -0
- package/dist/chain/abis/settlement.d.ts +2203 -703
- package/dist/chain/abis/settlement.js +2685 -764
- package/dist/chain/allowance.d.ts +358 -0
- package/dist/chain/allowance.js +800 -0
- package/dist/chain/billing.d.ts +85 -0
- package/dist/chain/billing.js +197 -0
- package/dist/chain/chainId.d.ts +13 -0
- package/dist/chain/chainId.js +26 -0
- package/dist/chain/client.d.ts +15 -1
- package/dist/chain/client.js +57 -1
- package/dist/chain/commitmentRecovery.d.ts +51 -0
- package/dist/chain/commitmentRecovery.js +38 -0
- package/dist/chain/committeeClient.d.ts +17 -10
- package/dist/chain/committeeClient.js +64 -16
- package/dist/chain/committeeDraw.d.ts +12 -0
- package/dist/chain/committeeDraw.js +56 -0
- package/dist/chain/custodyHealth.d.ts +212 -0
- package/dist/chain/custodyHealth.js +365 -0
- package/dist/chain/deployments.js +2 -0
- package/dist/chain/events.js +2 -0
- package/dist/chain/headFollower.d.ts +77 -0
- package/dist/chain/headFollower.js +219 -0
- package/dist/chain/headPrefetch.d.ts +23 -0
- package/dist/chain/headPrefetch.js +67 -0
- package/dist/chain/index.d.ts +50 -8
- package/dist/chain/index.js +28 -3
- package/dist/chain/keeperExecution.d.ts +44 -0
- package/dist/chain/keeperExecution.js +127 -0
- package/dist/chain/keeperRecovery.d.ts +78 -0
- package/dist/chain/keeperRecovery.js +91 -0
- package/dist/chain/node.d.ts +24 -1
- package/dist/chain/node.js +88 -43
- package/dist/chain/offchain.d.ts +2 -0
- package/dist/chain/paidAgentTransport.d.ts +38 -0
- package/dist/chain/paidAgentTransport.js +1 -0
- package/dist/chain/paidEpoch.d.ts +66 -0
- package/dist/chain/paidEpoch.js +139 -0
- package/dist/chain/paidPacing.d.ts +81 -0
- package/dist/chain/paidPacing.js +136 -0
- package/dist/chain/pinnedReads.d.ts +49 -0
- package/dist/chain/pinnedReads.js +218 -0
- package/dist/chain/prepaid.d.ts +383 -0
- package/dist/chain/prepaid.js +1046 -0
- package/dist/chain/prepaidEscape.d.ts +274 -0
- package/dist/chain/prepaidEscape.js +432 -0
- package/dist/chain/prepaidFault.d.ts +94 -0
- package/dist/chain/prepaidFault.js +148 -0
- package/dist/chain/receipt.d.ts +24 -0
- package/dist/chain/receipt.js +82 -0
- package/dist/chain/registeredAgent.d.ts +68 -3
- package/dist/chain/registeredAgent.js +143 -42
- package/dist/chain/registeredOperation.d.ts +10 -1
- package/dist/chain/registeredOperation.js +18 -3
- package/dist/chain/registeredPaidAgent.d.ts +254 -0
- package/dist/chain/registeredPaidAgent.js +889 -0
- package/dist/chain/registeredRelay.d.ts +31 -1
- package/dist/chain/registeredRelay.js +164 -43
- package/dist/chain/relayVoucher.d.ts +64 -0
- package/dist/chain/relayVoucher.js +69 -0
- package/dist/chain/reservation.d.ts +239 -0
- package/dist/chain/reservation.js +746 -0
- package/dist/chain/reshareRoster.d.ts +64 -0
- package/dist/chain/reshareRoster.js +85 -0
- package/dist/chain/revertReason.d.ts +8 -0
- package/dist/chain/revertReason.js +2 -1
- package/dist/chain/rotationLock.d.ts +130 -0
- package/dist/chain/rotationLock.js +168 -0
- package/dist/chain/serviceRequestPolicy.d.ts +47 -0
- package/dist/chain/serviceRequestPolicy.js +86 -0
- package/dist/chain/services.d.ts +7 -0
- package/dist/chain/services.js +44 -4
- package/dist/chain/slotClient.js +11 -2
- package/dist/chain/slotHandoff.d.ts +81 -0
- package/dist/chain/slotHandoff.js +166 -0
- package/dist/chain/slotSeed.d.ts +47 -5
- package/dist/chain/slotSeed.js +173 -42
- package/dist/chain/verifierSnapshot.d.ts +36 -0
- package/dist/chain/verifierSnapshot.js +197 -0
- package/dist/chain/write.d.ts +111 -21
- package/dist/chain/write.js +378 -146
- package/dist/committee/blsSharing.d.ts +53 -0
- package/dist/committee/blsSharing.js +90 -0
- package/dist/committee/client.d.ts +62 -23
- package/dist/committee/client.js +288 -72
- package/dist/committee/dual-operation.d.ts +165 -0
- package/dist/committee/dual-operation.js +229 -0
- package/dist/committee/dual-sign.d.ts +26 -1
- package/dist/committee/dual-sign.js +85 -7
- package/dist/committee/ecdsa.d.ts +38 -0
- package/dist/committee/ecdsa.js +87 -15
- package/dist/committee/evidence.d.ts +30 -0
- package/dist/committee/evidence.js +65 -0
- package/dist/committee/execution.d.ts +414 -0
- package/dist/committee/execution.js +446 -0
- package/dist/committee/extraction.js +33 -26
- package/dist/committee/index.d.ts +30 -7
- package/dist/committee/index.js +18 -6
- package/dist/committee/keeperExecution.d.ts +37 -0
- package/dist/committee/keeperExecution.js +141 -0
- package/dist/committee/oauth.d.ts +14 -4
- package/dist/committee/oauth.js +17 -5
- package/dist/committee/payment.d.ts +369 -0
- package/dist/committee/payment.js +339 -0
- package/dist/committee/recovery.d.ts +136 -0
- package/dist/committee/recovery.js +204 -0
- package/dist/committee/recoveryJson.d.ts +2 -0
- package/dist/committee/recoveryJson.js +87 -0
- package/dist/committee/request.d.ts +63 -27
- package/dist/committee/request.js +77 -66
- package/dist/committee/session-grant.d.ts +320 -0
- package/dist/committee/session-grant.js +397 -0
- package/dist/committee/status-refresh.d.ts +257 -0
- package/dist/committee/status-refresh.js +619 -0
- package/dist/committee/token.d.ts +163 -15
- package/dist/committee/token.js +247 -10
- package/dist/crypto/bn254.d.ts +70 -0
- package/dist/crypto/bn254.js +222 -0
- package/dist/crypto/ibe.d.ts +32 -0
- package/dist/crypto/ibe.js +56 -8
- package/dist/crypto/index.d.ts +1 -1
- package/dist/crypto/index.js +1 -1
- package/dist/crypto/kem.d.ts +31 -0
- package/dist/crypto/kem.js +113 -7
- package/dist/crypto/recipient.d.ts +75 -0
- package/dist/crypto/recipient.js +107 -0
- package/dist/decryption/client.d.ts +10 -16
- package/dist/decryption/client.js +8 -76
- package/dist/decryption/index.d.ts +2 -0
- package/dist/decryption/index.js +2 -0
- package/dist/decryption/sealed.d.ts +72 -0
- package/dist/decryption/sealed.js +147 -0
- package/dist/decryption/session.d.ts +115 -0
- package/dist/decryption/session.js +358 -0
- package/dist/errors.d.ts +406 -1
- package/dist/errors.js +400 -5
- package/dist/index.d.ts +9 -2
- package/dist/index.js +6 -1
- package/dist/internal/bounded.d.ts +66 -0
- package/dist/internal/bounded.js +126 -0
- package/dist/internal/network.d.ts +4 -0
- package/dist/internal/network.js +40 -0
- package/dist/internal/retryAfter.d.ts +8 -0
- package/dist/internal/retryAfter.js +28 -0
- package/dist/internal/sleep.d.ts +6 -0
- package/dist/internal/sleep.js +15 -0
- package/dist/internal/typedData.d.ts +13 -0
- package/dist/internal/typedData.js +77 -0
- package/dist/internal/viemErrors.d.ts +26 -0
- package/dist/internal/viemErrors.js +49 -0
- package/dist/oid4vp/binding.d.ts +27 -1
- package/dist/oid4vp/binding.js +36 -1
- package/dist/oid4vp/jose.d.ts +4 -2
- package/dist/oid4vp/jose.js +39 -7
- package/dist/oid4vp/request-object.d.ts +61 -4
- package/dist/oid4vp/request-object.js +140 -5
- package/dist/oid4vp/verifier-agent.d.ts +18 -8
- package/dist/oid4vp/verifier-agent.js +48 -6
- package/dist/oid4vp/wallet.d.ts +2 -4
- package/dist/oid4vp/wallet.js +1 -0
- package/dist/retry.d.ts +78 -0
- package/dist/retry.js +137 -0
- package/dist/signing/frost.d.ts +1 -1
- package/dist/verifier-agent/index.d.ts +41 -5
- package/dist/verifier-agent/index.js +124 -9
- package/dist/verifier-agent/payment.d.ts +7 -0
- package/dist/verifier-agent/payment.js +17 -0
- package/docs/api.md +8 -2
- package/docs/application-api.md +25 -2
- package/docs/chain.md +155 -9
- package/docs/consumer-migrations.md +61 -0
- package/docs/encrypted-notes.md +3 -2
- package/docs/encryption.md +4 -2
- package/docs/errors.md +14 -1
- package/docs/flows.md +2 -2
- package/docs/funding.md +902 -0
- package/docs/native-approvals.md +63 -0
- package/docs/reference/README.md +9 -8
- package/docs/reference/app-browser.md +232 -0
- package/docs/reference/app-node.md +38 -8
- package/docs/reference/app.md +4621 -805
- package/docs/reference/chain-node.md +74 -16
- package/docs/reference/chain.md +6740 -1592
- package/docs/reference/committee.md +5630 -987
- package/docs/reference/main.md +1439 -140
- package/docs/reference/oid4vp.md +297 -144
- package/docs/reference/verifier-agent.md +77 -35
- package/docs/signing.md +6 -0
- package/examples/encrypted-notes.ts +21 -6
- package/examples/getting-started.ts +2 -7
- package/examples/live-config.ts +24 -17
- package/package.json +17 -5
package/dist/app/client.js
CHANGED
|
@@ -1,18 +1,44 @@
|
|
|
1
1
|
import { equalBytes } from '@noble/curves/utils.js';
|
|
2
2
|
import { sha256 } from '@noble/hashes/sha256';
|
|
3
|
+
import { decryptionBinding, kemContentDigest } from '../crypto/recipient.js';
|
|
4
|
+
import { decryptWithCommitteePartials } from '../decryption/sealed.js';
|
|
5
|
+
import { utf8ToBytes } from '@noble/hashes/utils';
|
|
3
6
|
import { recoverAddress, toHex } from 'viem';
|
|
4
7
|
import { createTasraChainClient } from '../chain/client.js';
|
|
5
8
|
import { addressFromEoaPubkey } from '../signing/ecdsa.js';
|
|
6
9
|
import { verify } from '../crypto/frost.js';
|
|
7
10
|
import { kemEncrypt } from '../crypto/envelope.js';
|
|
11
|
+
import { ibeEncrypt } from '../crypto/ibe.js';
|
|
12
|
+
import { decryptIdentityStrict, extractIdentityStrict } from '../committee/extraction.js';
|
|
8
13
|
import { TasraError } from '../errors.js';
|
|
9
|
-
import { committeeSign
|
|
10
|
-
import { committeeSignEoaDigest } from '../committee/ecdsa.js';
|
|
14
|
+
import { committeeSign } from '../committee/client.js';
|
|
15
|
+
import { committeeSignEoaDigest, committeeSignP256Digest } from '../committee/ecdsa.js';
|
|
16
|
+
import { keyRegistryAbi } from '../chain/abis/keyRegistry.js';
|
|
17
|
+
import { viemErrorChainHas } from '../internal/viemErrors.js';
|
|
18
|
+
import { requireIntentPayment, signingIntentCurve, signingIntentDigest } from './signing-intents.js';
|
|
19
|
+
import { dualOperationPayload, requireDualOperationProof } from '../committee/dual-operation.js';
|
|
20
|
+
import { ed25519 } from '@noble/curves/ed25519';
|
|
11
21
|
import { createDualSignClient } from '../committee/dual-sign.js';
|
|
12
22
|
import { auditOperationId, protocolHex, verifyOperationReceipt } from '../committee/receipts.js';
|
|
13
23
|
import { compoundTokenHash, decodeCompoundToken } from '../committee/token.js';
|
|
14
|
-
import { payloadDigestFor, requestHash
|
|
24
|
+
import { payloadDigestFor, requestHash } from '../oid4vp/binding.js';
|
|
15
25
|
import { defineDeployment } from './deployment.js';
|
|
26
|
+
import { paymentIntentHash } from '../committee/payment.js';
|
|
27
|
+
import { resolvePaidKeeperTarget } from '../chain/prepaid.js';
|
|
28
|
+
import { createKeeperExecutionApprover, createKeeperExecutionApproverWithTarget } from '../chain/keeperExecution.js';
|
|
29
|
+
import { resolveKeeperMembers, withNetworkDeadline } from '../internal/network.js';
|
|
30
|
+
import { SingleFlight } from '../internal/bounded.js';
|
|
31
|
+
import { chainIdOf } from '../chain/chainId.js';
|
|
32
|
+
/** Run independent reads together; on failure, surface the error of the first failing read in
|
|
33
|
+
* argument order, the one a sequential read would have reported. */
|
|
34
|
+
async function inOrder(first, second) {
|
|
35
|
+
const [a, b] = await Promise.allSettled([first, second]);
|
|
36
|
+
if (a.status === 'rejected')
|
|
37
|
+
throw a.reason;
|
|
38
|
+
if (b.status === 'rejected')
|
|
39
|
+
throw b.reason;
|
|
40
|
+
return [a.value, b.value];
|
|
41
|
+
}
|
|
16
42
|
/**
|
|
17
43
|
* An application operation rejected because its deployment, slot, authorization or result failed validation.
|
|
18
44
|
*/
|
|
@@ -38,8 +64,12 @@ export function createTasra(config) {
|
|
|
38
64
|
throw new TasraError(`Injected chain client uses a different ${name}`);
|
|
39
65
|
}
|
|
40
66
|
const route = config.keeperUrl ?? ((url) => url), fetchImpl = config.fetchImpl;
|
|
67
|
+
const allowLocalPaidHttp = config.allowLocalPaidHttp === true;
|
|
68
|
+
// Concurrent operations on one slot share an in-flight `latest` slot read; an answered read is
|
|
69
|
+
// never reused, so every later check (including the post-authorization recheck) reads again.
|
|
70
|
+
const slotReads = new SingleFlight(1024);
|
|
41
71
|
async function assertChain() {
|
|
42
|
-
if (await chain.client
|
|
72
|
+
if (await chainIdOf(chain.client) !== deployment.chainId)
|
|
43
73
|
throw new TasraApplicationError('CHAIN_MISMATCH', 'RPC chain does not match the application deployment');
|
|
44
74
|
}
|
|
45
75
|
/**
|
|
@@ -48,8 +78,7 @@ export function createTasra(config) {
|
|
|
48
78
|
*/
|
|
49
79
|
async function get(slotId) {
|
|
50
80
|
protocolHex(slotId, 32, 'slot id');
|
|
51
|
-
await assertChain();
|
|
52
|
-
const s = await chain.readers.keyRegistry.getKeySlot(slotId);
|
|
81
|
+
const [, s] = await inOrder(assertChain(), slotReads.run(slotId.toLowerCase(), () => chain.readers.keyRegistry.getKeySlot(slotId)));
|
|
53
82
|
if (!s.exists)
|
|
54
83
|
throw new TasraApplicationError('SLOT_NOT_FOUND', 'Slot does not exist on this deployment');
|
|
55
84
|
if (s.cancelled)
|
|
@@ -71,24 +100,101 @@ export function createTasra(config) {
|
|
|
71
100
|
throw new TasraApplicationError('SLOT_CHANGED', 'Slot changed while authorization was pending; authorize a new operation');
|
|
72
101
|
}
|
|
73
102
|
}
|
|
74
|
-
async function keepers(slotId) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
103
|
+
async function keepers(slotId, caller) {
|
|
104
|
+
return withNetworkDeadline(async (signal) => {
|
|
105
|
+
const assigned = await chain.readers.keyRegistry.assignedNodes(slotId);
|
|
106
|
+
const nodes = await resolveKeeperMembers(assigned, async (operator) => {
|
|
107
|
+
const [node, id] = await Promise.all([chain.readers.nodeRegistry.nodeOf(operator), chain.readers.nodeRegistry.operatorIdOf(operator)]);
|
|
108
|
+
return { operator, nodeUrl: route(node.url), publicKey: protocolHex(node.pubkey, 32, 'keeper identity key'), id };
|
|
109
|
+
}, signal);
|
|
110
|
+
if (!nodes.length)
|
|
111
|
+
throw new TasraError('Slot has no assigned keepers');
|
|
112
|
+
if (deployment.coordinator === 'lowest-operator-id')
|
|
113
|
+
nodes.sort((a, b) => a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
|
|
114
|
+
return nodes;
|
|
115
|
+
}, caller);
|
|
116
|
+
}
|
|
117
|
+
function paidNode(member) {
|
|
118
|
+
const url = new URL(route(member.url));
|
|
119
|
+
if (url.username || url.password || url.search || url.hash || (url.protocol !== 'https:'
|
|
120
|
+
&& !(allowLocalPaidHttp && deployment.chainId === 43112 && url.protocol === 'http:')))
|
|
121
|
+
throw new TasraApplicationError('INVALID_AUTHORIZATION', 'Mapped paid keeper endpoint violates transport policy');
|
|
122
|
+
return { operator: member.operator, nodeUrl: url.toString().replace(/\/$/, ''), publicKey: protocolHex(member.publicKey, 32, 'paid keeper identity') };
|
|
123
|
+
}
|
|
124
|
+
// A slot under a native approval policy refuses every signature without its bundle: refuse
|
|
125
|
+
// before any credential or keeper work. A KeyRegistry without the policy has none.
|
|
126
|
+
async function requireNoApprovalPolicy(slotId) {
|
|
127
|
+
let quorum;
|
|
128
|
+
try {
|
|
129
|
+
quorum = Number((await chain.client.readContract({ address: deployment.addresses.KeyRegistry, abi: keyRegistryAbi, functionName: 'dualControlPolicy', args: [slotId] }))[0]);
|
|
130
|
+
}
|
|
131
|
+
catch (error) {
|
|
132
|
+
if (viemErrorChainHas(error, ['ContractFunctionRevertedError', 'ContractFunctionZeroDataError']))
|
|
133
|
+
return;
|
|
134
|
+
throw error;
|
|
135
|
+
}
|
|
136
|
+
if (quorum > 0)
|
|
137
|
+
throw new TasraApplicationError('INVALID_AUTHORIZATION', `Slot requires ${quorum} native approvals for every signature; supply the assembled dualControl bundle`);
|
|
138
|
+
}
|
|
139
|
+
// The keeper's quorum rule, judged against the ON-CHAIN policy before any credential or keeper
|
|
140
|
+
// work: distinct approvers whose signatures verify over the statement, at least the quorum of
|
|
141
|
+
// them, and for a static policy every one in the approver set.
|
|
142
|
+
async function requireBundleMeetsPolicy(slotId, proof) {
|
|
143
|
+
const registry = deployment.addresses.KeyRegistry;
|
|
144
|
+
const [policy, approvers] = await Promise.all([
|
|
145
|
+
chain.client.readContract({ address: registry, abi: keyRegistryAbi, functionName: 'dualControlPolicy', args: [slotId] }),
|
|
146
|
+
chain.client.readContract({ address: registry, abi: keyRegistryAbi, functionName: 'dualControlApprovers', args: [slotId] }),
|
|
147
|
+
]);
|
|
148
|
+
const quorum = Number(policy[0]), staticSet = /^0x0{64}$/i.test(policy[1]) ? new Set(approvers.map(key => key.slice(2).toLowerCase())) : undefined;
|
|
149
|
+
if (quorum === 0)
|
|
150
|
+
throw new TasraApplicationError('INVALID_AUTHORIZATION', 'Slot has no native approval policy for a bundle to satisfy');
|
|
151
|
+
const payload = dualOperationPayload(proof.statement), seen = new Set();
|
|
152
|
+
for (const approval of proof.approvals) {
|
|
153
|
+
const key = String(approval?.approver_pubkey ?? '').replace(/^0x/, '').toLowerCase(), signature = String(approval?.signature ?? '').replace(/^0x/, '');
|
|
154
|
+
if (!/^[0-9a-f]{64}$/.test(key) || !/^[0-9a-fA-F]{128}$/.test(signature) || !ed25519.verify(signature, payload, key, { zip215: false })) {
|
|
155
|
+
throw new TasraApplicationError('INVALID_AUTHORIZATION', 'An approval does not verify over the statement');
|
|
156
|
+
}
|
|
157
|
+
if (seen.has(key))
|
|
158
|
+
throw new TasraApplicationError('INVALID_AUTHORIZATION', 'The bundle names one approver twice');
|
|
159
|
+
if (staticSet && !staticSet.has(key))
|
|
160
|
+
throw new TasraApplicationError('INVALID_AUTHORIZATION', 'An approver is not in the slot\'s approver set');
|
|
161
|
+
seen.add(key);
|
|
162
|
+
}
|
|
163
|
+
if (seen.size < quorum)
|
|
164
|
+
throw new TasraApplicationError('INVALID_AUTHORIZATION', `Slot requires ${quorum} distinct approvals; the bundle has ${seen.size}`);
|
|
85
165
|
}
|
|
86
166
|
async function authorize(s, action, payload, options) {
|
|
87
167
|
options.signal?.throwIfAborted();
|
|
88
|
-
const
|
|
168
|
+
const payment = options.payment && structuredClone(options.payment), random = options.random;
|
|
169
|
+
const execution = options.execution && { certificate: structuredClone(options.execution.certificate), signer: options.execution.signer };
|
|
170
|
+
if ((payment === undefined) !== (random === undefined) || (random !== undefined && (typeof random !== 'string' || !/^0x[0-9a-f]{64}$/i.test(random))))
|
|
171
|
+
throw new TasraApplicationError('INVALID_AUTHORIZATION', 'Payment and its fixed presentation random are required together');
|
|
172
|
+
if ((payment === undefined) !== (execution === undefined))
|
|
173
|
+
throw new TasraApplicationError('INVALID_AUTHORIZATION', 'Paid keeper work requires the original client execution certificate and signer');
|
|
174
|
+
const expectedDigest = payload.decryption ? payload.payloadDigest : payloadDigestFor(action, payload);
|
|
89
175
|
const expected = requestHash(deployment.chainId, protocolHex(s.slotId, 32, 'slot'), action, expectedDigest);
|
|
176
|
+
const paidTarget = async () => {
|
|
177
|
+
if (!payment)
|
|
178
|
+
return undefined;
|
|
179
|
+
const settlement = deployment.addresses.Settlement;
|
|
180
|
+
if (!settlement || action === 'dual-approve')
|
|
181
|
+
throw new TasraApplicationError('INVALID_AUTHORIZATION', 'Paid operation needs a pinned Settlement and a supported fee action');
|
|
182
|
+
const target = await resolvePaidKeeperTarget(chain.client, { chainId: deployment.chainId, settlement, keyRegistry: deployment.addresses.KeyRegistry }, payment, { slot: s.slotId, action: action === 'sign' && (s.mode === 2 || s.mode === 4) ? 'eoa-sign' : action, payloadDigest: toHex(expectedDigest) }, { allowLocalHttp: allowLocalPaidHttp });
|
|
183
|
+
if (target.mode !== s.mode || target.groupPublicKey.toLowerCase() !== s.publicKey.toLowerCase() || payment.keeper_assignment.key_epoch !== s.epoch)
|
|
184
|
+
throw new TasraApplicationError('SLOT_CHANGED', 'Paid slot changed before keeper execution');
|
|
185
|
+
paidNode(target);
|
|
186
|
+
target.contributors.forEach(paidNode);
|
|
187
|
+
return target;
|
|
188
|
+
};
|
|
189
|
+
// Refuse missing funding or changed assignments before asking for credentials. Re-read
|
|
190
|
+
// afterward too: authorization can take long enough for a rotation, expiry or settlement.
|
|
191
|
+
await paidTarget();
|
|
192
|
+
const nowSecs = Math.floor(Date.now() / 1000);
|
|
193
|
+
if (payment && payment.expires <= nowSecs)
|
|
194
|
+
throw new TasraApplicationError('INVALID_AUTHORIZATION', 'Reserved payment expired before authorization');
|
|
90
195
|
const grant = structuredClone(await options.authorize(Object.freeze({ chainId: deployment.chainId, keyRegistry: deployment.addresses.KeyRegistry, slotId: s.slotId,
|
|
91
196
|
action, ...payload, message: payload.message?.slice(), payloadDigest: payload.payloadDigest?.slice(),
|
|
197
|
+
...(payment ? { payment: structuredClone(payment), random, nowSecs, ttlSecs: payment.expires - nowSecs } : {}),
|
|
92
198
|
description: options.description ?? `Tasra ${action}`, signal: options.signal })));
|
|
93
199
|
options.signal?.throwIfAborted();
|
|
94
200
|
if (grant.token.binding !== 'holder_key' || !Number.isSafeInteger(grant.token.exp) || grant.token.exp * 1000 <= Date.now() ||
|
|
@@ -96,9 +202,25 @@ export function createTasra(config) {
|
|
|
96
202
|
!equalBytes(protocolHex(grant.token.request_hash, 32, 'request hash'), expected) || !grant.verifierProofs.length) {
|
|
97
203
|
throw new TasraApplicationError('INVALID_AUTHORIZATION', 'Grant must be fresh and holder-bound to this exact operation');
|
|
98
204
|
}
|
|
99
|
-
|
|
205
|
+
if (payment) {
|
|
206
|
+
const actual = decodeCompoundToken(grant.token).paymentHash;
|
|
207
|
+
if (!grant.token.payment || !actual || !equalBytes(actual, protocolHex(paymentIntentHash(payment), 32, 'payment commitment')) || grant.token.exp > payment.expires) {
|
|
208
|
+
throw new TasraApplicationError('INVALID_AUTHORIZATION', 'Grant changed or discarded the reserved payment');
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
else if (grant.token.payment != null || grant.token.payment_hash != null) {
|
|
212
|
+
throw new TasraApplicationError('INVALID_AUTHORIZATION', 'Grant introduced an unexpected payment');
|
|
213
|
+
}
|
|
214
|
+
// The slot recheck and the paid target re-read are independent; the target read here is the
|
|
215
|
+
// one every keeper approval of this operation then shares while it stays recent.
|
|
216
|
+
const [, target] = await inOrder(unchanged(s), paidTarget());
|
|
100
217
|
options.signal?.throwIfAborted();
|
|
101
|
-
|
|
218
|
+
const approverOptions = payment && execution && { client: chain.client,
|
|
219
|
+
deployment: { chainId: deployment.chainId, settlement: deployment.addresses.Settlement, keyRegistry: deployment.addresses.KeyRegistry },
|
|
220
|
+
payment, expected: { slot: s.slotId, action: action === 'sign' && (s.mode === 2 || s.mode === 4) ? 'eoa-sign' : action, payloadDigest: toHex(expectedDigest) },
|
|
221
|
+
...execution, transportPolicy: { allowLocalHttp: allowLocalPaidHttp }, keeperUrl: route };
|
|
222
|
+
const approveExecution = approverOptions ? target ? createKeeperExecutionApproverWithTarget(approverOptions, target) : createKeeperExecutionApprover(approverOptions) : undefined;
|
|
223
|
+
return { ...grant, paidTarget: target, approveExecution };
|
|
102
224
|
}
|
|
103
225
|
return {
|
|
104
226
|
/** Validated configuration for the selected deployment. */
|
|
@@ -123,7 +245,7 @@ export function createTasra(config) {
|
|
|
123
245
|
async ecdsa(slotId) {
|
|
124
246
|
await ready(slotId, 2);
|
|
125
247
|
const getAddress = async () => addressFromEoaPubkey(protocolHex((await ready(slotId, 2)).publicKey, 33, 'secp256k1 public key'));
|
|
126
|
-
|
|
248
|
+
const adapter = {
|
|
127
249
|
/** Identifier of the threshold ECDSA slot. */
|
|
128
250
|
slotId,
|
|
129
251
|
/** Recheck slot readiness and derive its Ethereum address from the current public key. */
|
|
@@ -136,17 +258,94 @@ export function createTasra(config) {
|
|
|
136
258
|
async signDigest(input, options) {
|
|
137
259
|
if (input.length !== 32)
|
|
138
260
|
throw new TasraError('Ethereum digest must be exactly 32 bytes');
|
|
261
|
+
const dualControl = options.dualControl && structuredClone(options.dualControl);
|
|
262
|
+
if (dualControl && !options.payment)
|
|
263
|
+
throw new TasraApplicationError('INVALID_AUTHORIZATION', 'Native approvals bind a final payment; supply it');
|
|
139
264
|
const digest = input.slice(), s = await ready(slotId, 2);
|
|
140
|
-
|
|
265
|
+
// Judged before any credential work: the bundle names this slot, digest and payment.
|
|
266
|
+
if (dualControl) {
|
|
267
|
+
requireDualOperationProof(dualControl, { operation: 'secp256k1-sign', slot: protocolHex(slotId, 32, 'slot'), payloadDigest: sha256(digest), payment: options.payment });
|
|
268
|
+
await requireBundleMeetsPolicy(slotId, dualControl);
|
|
269
|
+
}
|
|
270
|
+
else
|
|
271
|
+
await requireNoApprovalPolicy(slotId);
|
|
272
|
+
const grant = await authorize(s, 'sign', { message: digest }, options), node = grant.paidTarget ? paidNode(grant.paidTarget) : (await keepers(slotId, options.signal))[0];
|
|
141
273
|
options.signal?.throwIfAborted();
|
|
142
|
-
const result = await committeeSignEoaDigest({ nodeUrl: node.nodeUrl, committeeToken: grant.token, verifierProofs: grant.verifierProofs,
|
|
143
|
-
digest, userSignature: options.userSignature, targetKeykeeper: node.operator, signal: options.signal, fetchImpl
|
|
274
|
+
const result = await committeeSignEoaDigest({ nodeUrl: node.nodeUrl, committeeToken: grant.token, evidenceCt: grant.evidenceCt, verifierProofs: grant.verifierProofs,
|
|
275
|
+
digest, userSignature: options.userSignature, targetKeykeeper: node.operator, signal: options.signal, fetchImpl, approveExecution: grant.approveExecution,
|
|
276
|
+
...(dualControl ? { dualControl } : {}) });
|
|
144
277
|
const publicKey = protocolHex(s.publicKey, 33, 'secp256k1 public key');
|
|
145
278
|
const recovered = await recoverAddress({ hash: toHex(digest), signature: { r: toHex(result.r), s: toHex(result.s), yParity: result.yParity } });
|
|
146
279
|
if (!equalBytes(result.groupPublicKey, publicKey) || recovered.toLowerCase() !== addressFromEoaPubkey(publicKey).toLowerCase())
|
|
147
280
|
throw new TasraApplicationError('INVALID_RESULT', 'Signature does not match the anchored Ethereum account');
|
|
148
281
|
return result;
|
|
149
282
|
},
|
|
283
|
+
/**
|
|
284
|
+
* Sign a structured intent (a transaction, EIP-712 typed data or a personal message): the
|
|
285
|
+
* SDK derives the digest itself, then signs it like `signDigest`. With a payment, the
|
|
286
|
+
* payment must pay for exactly this intent.
|
|
287
|
+
* @param intent Structured intent; a transaction and typed data must name their chain.
|
|
288
|
+
* @param options Fresh operation authorization, the final payment for this intent and its approvals.
|
|
289
|
+
*/
|
|
290
|
+
async signIntent(intent, options) {
|
|
291
|
+
if (signingIntentCurve(intent) !== 'secp256k1')
|
|
292
|
+
throw new TasraApplicationError('WRONG_SLOT_MODE', 'A secp256k1 slot signs Ethereum intents only');
|
|
293
|
+
const digest = options.payment ? requireIntentPayment(options.payment, intent) : signingIntentDigest(intent);
|
|
294
|
+
return { ...await adapter.signDigest(digest, options), digest };
|
|
295
|
+
},
|
|
296
|
+
};
|
|
297
|
+
return adapter;
|
|
298
|
+
},
|
|
299
|
+
/**
|
|
300
|
+
* Open a ready threshold P-256 slot for verified P-256 signatures (not an Ethereum account).
|
|
301
|
+
* @param slotId Identifier of the P-256 slot.
|
|
302
|
+
*/
|
|
303
|
+
async p256(slotId) {
|
|
304
|
+
await ready(slotId, 4);
|
|
305
|
+
const getPublicKey = async () => protocolHex((await ready(slotId, 4)).publicKey, 33, 'P-256 public key');
|
|
306
|
+
const signDigest = async (input, options) => {
|
|
307
|
+
if (input.length !== 32)
|
|
308
|
+
throw new TasraError('P-256 digest must be exactly 32 bytes');
|
|
309
|
+
const dualControl = options.dualControl && structuredClone(options.dualControl);
|
|
310
|
+
if (dualControl && !options.payment)
|
|
311
|
+
throw new TasraApplicationError('INVALID_AUTHORIZATION', 'Native approvals bind a final payment; supply it');
|
|
312
|
+
const digest = input.slice(), s = await ready(slotId, 4);
|
|
313
|
+
if (dualControl) {
|
|
314
|
+
requireDualOperationProof(dualControl, { operation: 'p256-sign', slot: protocolHex(slotId, 32, 'slot'), payloadDigest: sha256(digest), payment: options.payment });
|
|
315
|
+
await requireBundleMeetsPolicy(slotId, dualControl);
|
|
316
|
+
}
|
|
317
|
+
else
|
|
318
|
+
await requireNoApprovalPolicy(slotId);
|
|
319
|
+
const grant = await authorize(s, 'sign', { message: digest }, options), node = grant.paidTarget ? paidNode(grant.paidTarget) : (await keepers(slotId, options.signal))[0];
|
|
320
|
+
options.signal?.throwIfAborted();
|
|
321
|
+
// Verifies the signature under the anchored key and refuses any other key.
|
|
322
|
+
return committeeSignP256Digest({ nodeUrl: node.nodeUrl, committeeToken: grant.token, evidenceCt: grant.evidenceCt, verifierProofs: grant.verifierProofs,
|
|
323
|
+
digest, groupPublicKey: protocolHex(s.publicKey, 33, 'P-256 public key'), userSignature: options.userSignature, targetKeykeeper: node.operator,
|
|
324
|
+
signal: options.signal, fetchImpl, approveExecution: grant.approveExecution, ...(dualControl ? { dualControl } : {}) });
|
|
325
|
+
};
|
|
326
|
+
return {
|
|
327
|
+
/** Identifier of the threshold P-256 slot. */
|
|
328
|
+
slotId,
|
|
329
|
+
/** Recheck slot readiness and return its compressed P-256 group public key. */
|
|
330
|
+
getPublicKey,
|
|
331
|
+
/**
|
|
332
|
+
* Authorize and sign an exact 32-byte digest, verified under the anchored P-256 key.
|
|
333
|
+
* @param input Exactly 32 digest bytes.
|
|
334
|
+
* @param options Fresh operation authorization, the final payment and its approvals.
|
|
335
|
+
*/
|
|
336
|
+
signDigest,
|
|
337
|
+
/**
|
|
338
|
+
* Sign the SHA-256 of exactly `intent.data`: the SDK derives the digest itself. With a
|
|
339
|
+
* payment, the payment must pay for exactly this intent.
|
|
340
|
+
* @param intent The bytes to sign.
|
|
341
|
+
* @param options Fresh operation authorization, the final payment for this intent and its approvals.
|
|
342
|
+
*/
|
|
343
|
+
async signIntent(intent, options) {
|
|
344
|
+
if (signingIntentCurve(intent) !== 'p256')
|
|
345
|
+
throw new TasraApplicationError('WRONG_SLOT_MODE', 'A P-256 slot signs sha256 intents only');
|
|
346
|
+
const digest = options.payment ? requireIntentPayment(options.payment, intent) : signingIntentDigest(intent);
|
|
347
|
+
return { ...await signDigest(digest, options), digest };
|
|
348
|
+
},
|
|
150
349
|
};
|
|
151
350
|
},
|
|
152
351
|
/**
|
|
@@ -165,10 +364,10 @@ export function createTasra(config) {
|
|
|
165
364
|
*/
|
|
166
365
|
async sign(input, options) {
|
|
167
366
|
const message = input.slice(), s = await ready(slotId, 0);
|
|
168
|
-
const grant = await authorize(s, 'sign', { message }, options), node = (await keepers(slotId))[0];
|
|
367
|
+
const grant = await authorize(s, 'sign', { message }, options), node = grant.paidTarget ? paidNode(grant.paidTarget) : (await keepers(slotId, options.signal))[0];
|
|
169
368
|
options.signal?.throwIfAborted();
|
|
170
|
-
const result = await committeeSign({ nodeUrl: node.nodeUrl, committeeToken: grant.token, message, verifierProofs: grant.verifierProofs,
|
|
171
|
-
targetKeykeeper: node.operator, userSignature: options.userSignature, signal: options.signal, fetchImpl });
|
|
369
|
+
const result = await committeeSign({ nodeUrl: node.nodeUrl, committeeToken: grant.token, evidenceCt: grant.evidenceCt, message, verifierProofs: grant.verifierProofs,
|
|
370
|
+
targetKeykeeper: node.operator, userSignature: options.userSignature, signal: options.signal, fetchImpl, approveExecution: grant.approveExecution });
|
|
172
371
|
const publicKey = protocolHex(s.publicKey, 32, 'FROST public key');
|
|
173
372
|
if (!equalBytes(result.groupPublicKey, publicKey) || !equalBytes(result.messageSha256, sha256(message)) || result.epoch !== s.epoch ||
|
|
174
373
|
!equalBytes(protocolHex(result.keySlotId, 32, 'result slot'), protocolHex(slotId, 32, 'slot')) || !verify(publicKey, message, result.signature)) {
|
|
@@ -183,8 +382,29 @@ export function createTasra(config) {
|
|
|
183
382
|
},
|
|
184
383
|
/** Quorum and approval mode must come from the application's independently pinned policy. */
|
|
185
384
|
async approvals(policy) {
|
|
186
|
-
const
|
|
187
|
-
|
|
385
|
+
const payment = policy.payment && structuredClone(policy.payment);
|
|
386
|
+
const execution = policy.execution && { certificate: structuredClone(policy.execution.certificate), signer: policy.execution.signer };
|
|
387
|
+
if ((payment === undefined) !== (execution === undefined))
|
|
388
|
+
throw new TasraApplicationError('INVALID_AUTHORIZATION', 'Paid dual creation requires its original client execution certificate and signer');
|
|
389
|
+
const s = await ready(slotId, 0);
|
|
390
|
+
let node;
|
|
391
|
+
if (payment) {
|
|
392
|
+
const settlement = deployment.addresses.Settlement;
|
|
393
|
+
if (!settlement)
|
|
394
|
+
throw new TasraApplicationError('INVALID_AUTHORIZATION', 'Paid dual-control needs a pinned Settlement');
|
|
395
|
+
const target = await resolvePaidKeeperTarget(chain.client, { chainId: deployment.chainId, settlement, keyRegistry: deployment.addresses.KeyRegistry }, payment, { slot: slotId, action: 'sign', payloadDigest: payment.payload_digest }, { allowLocalHttp: allowLocalPaidHttp });
|
|
396
|
+
if (target.mode !== s.mode || target.groupPublicKey.toLowerCase() !== s.publicKey.toLowerCase() || payment.keeper_assignment.key_epoch !== s.epoch)
|
|
397
|
+
throw new TasraApplicationError('SLOT_CHANGED', 'Paid dual-control sharing changed');
|
|
398
|
+
node = paidNode(target);
|
|
399
|
+
}
|
|
400
|
+
else
|
|
401
|
+
node = (await keepers(slotId))[0];
|
|
402
|
+
const approveExecution = payment && execution ? createKeeperExecutionApprover({ client: chain.client,
|
|
403
|
+
deployment: { chainId: deployment.chainId, settlement: deployment.addresses.Settlement, keyRegistry: deployment.addresses.KeyRegistry },
|
|
404
|
+
payment, expected: { slot: slotId, action: 'sign', payloadDigest: payment.payload_digest }, ...execution,
|
|
405
|
+
transportPolicy: { allowLocalHttp: allowLocalPaidHttp }, keeperUrl: route }) : undefined;
|
|
406
|
+
return createDualSignClient({ chainId: deployment.chainId, nodeUrl: node.nodeUrl, slotId, groupPublicKey: protocolHex(s.publicKey, 32, 'FROST public key'),
|
|
407
|
+
quorum: policy.quorum, credentialGated: policy.credentialGated, payment, fetchImpl, approveExecution });
|
|
188
408
|
},
|
|
189
409
|
};
|
|
190
410
|
},
|
|
@@ -199,6 +419,19 @@ export function createTasra(config) {
|
|
|
199
419
|
throw new TasraError('Invalid anchored BLS public key');
|
|
200
420
|
return protocolHex(s.publicKey, (s.publicKey.length - 2) / 2, 'BLS public key').slice(0, 96);
|
|
201
421
|
};
|
|
422
|
+
const extraction = async (identity, options) => {
|
|
423
|
+
options.signal?.throwIfAborted();
|
|
424
|
+
if (!options.recipient || !options.verifyingShares)
|
|
425
|
+
throw new TasraError('Client recipient and authenticated public sharing required before extraction authorization');
|
|
426
|
+
const s = await ready(slotId, 1);
|
|
427
|
+
const binding = decryptionBinding(sha256(utf8ToBytes(identity)), s.epoch, options.recipient);
|
|
428
|
+
const grant = await authorize(s, 'ibe-extract', { identity, ...binding }, options);
|
|
429
|
+
const opts = { chainId: deployment.chainId, slotId, threshold: s.threshold.k, epoch: s.epoch,
|
|
430
|
+
recipient: options.recipient, verifyingShares: options.verifyingShares,
|
|
431
|
+
groupPublicKey: groupKey(s), keepers: grant.paidTarget ? grant.paidTarget.contributors.map(paidNode) : await keepers(slotId, options.signal), shareTrust: 'anchored-group', committeeToken: grant.token, evidenceCt: grant.evidenceCt,
|
|
432
|
+
verifierProofs: grant.verifierProofs, identity, userSignature: options.userSignature, signal: options.signal, fetchImpl, requireReceipts: options.requireReceipts, approveExecution: grant.approveExecution, timeoutMs: options.timeoutMs };
|
|
433
|
+
return opts;
|
|
434
|
+
};
|
|
202
435
|
return {
|
|
203
436
|
/** Identifier of the BLS key-encryption slot. */
|
|
204
437
|
slotId,
|
|
@@ -211,59 +444,52 @@ export function createTasra(config) {
|
|
|
211
444
|
return kemEncrypt(groupKey(await ready(slotId, 1)), aad, dataKey);
|
|
212
445
|
},
|
|
213
446
|
/**
|
|
214
|
-
* Authorize and recover the KEM-wrapped symmetric key
|
|
447
|
+
* Authorize and recover the KEM-wrapped symmetric key from verified, recipient-sealed threshold shares.
|
|
215
448
|
* @param aad Original authenticated data from encryption.
|
|
216
449
|
* @param kemCt BLS KEM ciphertext wrapping the symmetric key.
|
|
217
450
|
* @param options Fresh authorization and optional verified-receipt requirement.
|
|
218
451
|
*/
|
|
219
452
|
async decrypt(aad, kemCt, options) {
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
453
|
+
// Recipient-bound partial decryption: keepers return sealed shares and the client verifies
|
|
454
|
+
// and combines them. Keeper-side custody decryption (`/v1/committee/decrypt`) is retired
|
|
455
|
+
// under the production runtime policy, so this path is the only one a production keeper serves.
|
|
223
456
|
options.signal?.throwIfAborted();
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
const
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
evidence: assigned.slice(0, 1).map(k => ({
|
|
261
|
-
operator: k.operator,
|
|
262
|
-
identifier: 0,
|
|
263
|
-
nodeUrl: k.nodeUrl,
|
|
264
|
-
receiptStatus: 'unverified',
|
|
265
|
-
})),
|
|
266
|
-
};
|
|
457
|
+
if (!options.recipient || !options.verifyingShares)
|
|
458
|
+
throw new TasraError('Client recipient and authenticated public sharing required before decryption authorization');
|
|
459
|
+
const s = await ready(slotId, 1);
|
|
460
|
+
const binding = decryptionBinding(kemContentDigest(kemCt, aad), s.epoch, options.recipient);
|
|
461
|
+
const grant = await authorize(s, 'decrypt', binding, options);
|
|
462
|
+
const nodes = grant.paidTarget ? grant.paidTarget.contributors.map(paidNode) : await keepers(slotId, options.signal);
|
|
463
|
+
const plaintext = await decryptWithCommitteePartials({ nodeUrls: nodes.map(k => k.nodeUrl), chainId: deployment.chainId,
|
|
464
|
+
committeeToken: grant.token, recipient: options.recipient, ciphertextEpoch: s.epoch, verifyingShares: options.verifyingShares,
|
|
465
|
+
threshold: s.threshold.k, verifierProofs: grant.verifierProofs, userSignature: options.userSignature, evidenceCt: grant.evidenceCt,
|
|
466
|
+
approveExecution: grant.approveExecution, signal: options.signal, fetchImpl, ciphertext: kemCt, identity: aad });
|
|
467
|
+
return { plaintext, shareTrust: 'anchored-group' };
|
|
468
|
+
},
|
|
469
|
+
/**
|
|
470
|
+
* Identity-based encryption (IBE) to an identity string, such as a patient or document id.
|
|
471
|
+
* Public-key encryption; no credential or network authorization is requested.
|
|
472
|
+
* @param identity Exact identity string the ciphertext is bound to.
|
|
473
|
+
* @param plaintext Bytes to encrypt.
|
|
474
|
+
*/
|
|
475
|
+
async encryptForIdentity(identity, plaintext) { return ibeEncrypt(groupKey(await ready(slotId, 1)), utf8ToBytes(identity), plaintext); },
|
|
476
|
+
/**
|
|
477
|
+
* Authorize identity-key extraction and decrypt an IBE ciphertext after verifying threshold shares.
|
|
478
|
+
* @param identity Exact encryption identity string.
|
|
479
|
+
* @param ciphertext Encrypted payload bound to that identity.
|
|
480
|
+
* @param options Fresh authorization and optional verified-receipt requirement.
|
|
481
|
+
*/
|
|
482
|
+
async decryptForIdentity(identity, ciphertext, options) {
|
|
483
|
+
return decryptIdentityStrict({ ...await extraction(identity, options), ciphertext });
|
|
484
|
+
},
|
|
485
|
+
/**
|
|
486
|
+
* Authorize and extract the identity's IBE private key.
|
|
487
|
+
* Explicit custody: the returned identity key persists independently of token expiry.
|
|
488
|
+
* @param identity Exact encryption identity string.
|
|
489
|
+
* @param options Fresh authorization and optional verified-receipt requirement.
|
|
490
|
+
*/
|
|
491
|
+
async extractIdentityKey(identity, options) {
|
|
492
|
+
return extractIdentityStrict(await extraction(identity, options));
|
|
267
493
|
},
|
|
268
494
|
};
|
|
269
495
|
},
|
package/dist/app/identity.js
CHANGED
|
@@ -18,15 +18,25 @@ export function createIdentity(options = {}) {
|
|
|
18
18
|
throw new Error('Unsupported identity algorithm');
|
|
19
19
|
if (options.seed !== undefined && (!(options.seed instanceof Uint8Array) || options.seed.length !== 32))
|
|
20
20
|
throw new Error('Identity seed must contain 32 bytes');
|
|
21
|
-
|
|
21
|
+
// The holder constructors take an owned COPY (Uint8Array.from, never slice(): Buffer#slice is a
|
|
22
|
+
// view), so a caller wiping its seed cannot zero this identity's key; the copy erases itself on
|
|
23
|
+
// failure. The fresh random seed is wiped here once copied.
|
|
22
24
|
let holder;
|
|
23
|
-
|
|
24
|
-
holder = algorithm === 'P-256' ? p256HolderKey(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
25
|
+
if (options.seed !== undefined)
|
|
26
|
+
holder = algorithm === 'P-256' ? p256HolderKey(options.seed) : ed25519HolderKey(options.seed);
|
|
27
|
+
else if (algorithm === 'P-256')
|
|
28
|
+
holder = randomHolderKey();
|
|
29
|
+
else {
|
|
30
|
+
const fresh = crypto.getRandomValues(new Uint8Array(32));
|
|
31
|
+
try {
|
|
32
|
+
holder = ed25519HolderKey(fresh);
|
|
33
|
+
}
|
|
34
|
+
finally {
|
|
35
|
+
fresh.fill(0);
|
|
36
|
+
}
|
|
29
37
|
}
|
|
38
|
+
// The single SDK-owned copy: destroy() zeroes the holder's key itself.
|
|
39
|
+
const secret = holder.privateKey;
|
|
30
40
|
Object.freeze(holder.publicJwk);
|
|
31
41
|
Object.freeze(holder);
|
|
32
42
|
const issuer = Object.freeze({ did: holder.did, kid: `${holder.did}#0`, signer: Object.freeze(holderSigner(holder)) });
|
|
@@ -37,7 +47,7 @@ export function createIdentity(options = {}) {
|
|
|
37
47
|
did: holder.did, algorithm,
|
|
38
48
|
get holder() { assertLive(); return holder; },
|
|
39
49
|
get issuer() { assertLive(); return issuer; },
|
|
40
|
-
exportPrivateKey() { assertLive(); return
|
|
50
|
+
exportPrivateKey() { assertLive(); return Uint8Array.from(secret); },
|
|
41
51
|
destroy() { secret.fill(0); destroyed = true; },
|
|
42
52
|
toJSON() { return { did: holder.did, algorithm }; },
|
|
43
53
|
});
|
|
@@ -265,9 +275,11 @@ export function credentialAuthorization(options) {
|
|
|
265
275
|
for (const credential of credentials)
|
|
266
276
|
verifyCredential(credential, { holder: options.identity });
|
|
267
277
|
const operation = { ...request, ...(request.message ? { message: request.message.slice() } : {}),
|
|
278
|
+
...(request.payment ? { payment: structuredClone(request.payment) } : {}),
|
|
268
279
|
...(request.payloadDigest ? { payloadDigest: request.payloadDigest.slice() } : {}),
|
|
269
280
|
slotId: typeof request.slotId === 'string' ? request.slotId : request.slotId.slice() };
|
|
270
281
|
const consent = { ...operation, ...(operation.message ? { message: operation.message.slice() } : {}),
|
|
282
|
+
...(operation.payment ? { payment: structuredClone(operation.payment) } : {}),
|
|
271
283
|
...(operation.payloadDigest ? { payloadDigest: operation.payloadDigest.slice() } : {}),
|
|
272
284
|
slotId: typeof operation.slotId === 'string' ? operation.slotId : operation.slotId.slice() };
|
|
273
285
|
if (options.approve && !await options.approve(Object.freeze(consent)))
|
|
@@ -282,6 +294,6 @@ export function credentialAuthorization(options) {
|
|
|
282
294
|
const result = await awaitVerifierAgentResult(session, { signal: request.signal, timeoutMs: options.timeoutMs, onPhase: options.onPhase });
|
|
283
295
|
if (!result.verifierProofs?.length)
|
|
284
296
|
throw new Error('Authorization did not include verifier membership proofs');
|
|
285
|
-
return { token: result.token, verifierProofs: result.verifierProofs };
|
|
297
|
+
return { token: result.token, verifierProofs: result.verifierProofs, ...(result.evidenceCt !== undefined ? { evidenceCt: result.evidenceCt } : {}) };
|
|
286
298
|
};
|
|
287
299
|
}
|
package/dist/app/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/** Application API. safe to import in browsers. */
|
|
2
2
|
export { createTasra, TasraApplicationError } from './client.js';
|
|
3
|
-
export type { TasraApplication, TasraApplicationConfig, ApplicationErrorCode, SlotMetadata, OperationGrant, AuthorizationRequest, OperationAuthorizer, AuthorizedOperationOptions, EcdsaSlot, FrostSlot, BlsSlot } from './client.js';
|
|
3
|
+
export type { TasraApplication, TasraApplicationConfig, ApplicationErrorCode, SlotMetadata, OperationGrant, AuthorizationRequest, OperationAuthorizer, AuthorizedOperationOptions, EcdsaSignOptions, IdentityExtractionOptions, EcdsaSlot, P256Slot, FrostSlot, BlsSlot } from './client.js';
|
|
4
4
|
export { defineDeployment } from './deployment.js';
|
|
5
5
|
export type { TasraDeployment } from './deployment.js';
|
|
6
6
|
export { toViemAccount } from './viem.js';
|
|
@@ -18,5 +18,30 @@ export { createIdentity, issueCredential, verifyCredential, credentialPolicy, cr
|
|
|
18
18
|
export type { TasraWallet, WalletTransactionInput, WalletTransactionJournal } from './wallet.js';
|
|
19
19
|
export type { TasraIdentity, IssueCredentialOptions, VerifyCredentialOptions, CredentialPolicyOptions, PresentCredentialsOptions, CredentialAuthorizationOptions } from './identity.js';
|
|
20
20
|
export type { ApplicationDeployment, ResolvedApplicationManifest } from './manifest.js';
|
|
21
|
-
export { setApprovalPolicy, identityApprover, approveWithCredential } from './approvals.js';
|
|
22
|
-
export type { ApprovalPolicy } from './approvals.js';
|
|
21
|
+
export { setApprovalPolicy, readApprovalPolicy, prepareOperationApproval, assembleOperationApproval, identityApprover, approveWithCredential } from './approvals.js';
|
|
22
|
+
export type { ApprovalPolicy, InstalledApprovalPolicy, ApprovalPolicyAlreadyInstalled } from './approvals.js';
|
|
23
|
+
export { lockKeyRotation } from './rotation-lock.js';
|
|
24
|
+
export type { RotationAlreadyLocked } from './rotation-lock.js';
|
|
25
|
+
export { approveDualOperation, requireDualOperationProof } from '../committee/dual-operation.js';
|
|
26
|
+
export type { DualOperationApprovalRecord, DualOperationApprover, DualOperationProof, PreparedDualOperation, DualOperationKind } from '../committee/dual-operation.js';
|
|
27
|
+
export { createPaidReservationJournal, loadPaidReservationJournal } from './paid-journal.js';
|
|
28
|
+
export type { PaidReservationJournal, PaidReservationSession, ApplicationReservationJournal } from './paid-journal.js';
|
|
29
|
+
export { reserveApplicationPayment, reconcileApplicationPayment, reconcileApplicationReservation, selectApplicationGasPayer, ApplicationPayerRecoveryError } from './paid-reservation.js';
|
|
30
|
+
export type { ApplicationReservationOptions, ApplicationReservationState, ApplicationReservationStatus, ReconcileApplicationReservationOptions, SelectApplicationGasPayerOptions } from './paid-reservation.js';
|
|
31
|
+
export { AllowanceRefusedError, AllowanceUnavailableError, AllowanceCapacityError, inspectAllowanceLanes, journaledAllowanceVoucher, allowanceLaneCount } from './paid-allowance.js';
|
|
32
|
+
export type { PaidAllowanceOptions } from './paid-allowance.js';
|
|
33
|
+
export { paidOperation, prepareAllowances, paidFinalSign, resumePaidFinalSign, paidSessionDecrypt, resumePaidSessionDecrypt, resumePaidOperation, reconcilePaidOperation, recoverPaidOperation, abandonPaidOperation, paidOperationPhase, listPaidOperations, PaidOperationRecoveryError, PaidOperationAbandonRefusedError, NewerVerifierEpoch } from './paid-operation.js';
|
|
34
|
+
export type { PaidOperation, PaidOperationConfig, PaidOperationRequest, PrepareAllowancesRequest, PreparedAllowances, PreparedAllowanceLane, PreparedAllowanceOutcome, PaidFinalSign, PaidFinalSignRequest, PaidSessionDecrypt, PaidSessionDecryptRequest, PaidOperationPhase, PaidOperationJournalPhase, PaidOperationStatus, PaidOperationNextStep, ResumePaidOperationOptions, PaidOperationErrorCode, PaidOperationSummary, ListPaidOperationsOptions, RecoverIbePartialsOptions, RecoveredIbePartial, RecoveredIbePartials, PaidOperationRecovery, AbandonPaidOperationOptions, AbandonedPaidOperation, RefreshPaidStatusOptions, PaidStatusRefresh } from './paid-operation.js';
|
|
35
|
+
export { SLOT_POLICY_DOMAIN_NAME, SLOT_POLICY_REQUEST_DOMAIN_NAME, SLOT_POLICY_MAX_LIFETIME_SECS, SLOT_POLICY_REQUEST_MAX_AGE_SECS, SlotPolicyError, PolicyOperationError, slotPolicyTypedData, slotPolicyHash, verifySlotPolicyBootstrap, issueSlotPolicyBootstrap, slotPolicyRequestTypedData, createSlotPolicyRequest, verifySlotPolicyRequest } from './policy-bootstrap.js';
|
|
36
|
+
export type { SlotPolicyStatement, SlotPolicyBootstrap, SlotPolicyRequest, SlotPolicyExpectation, SlotPolicyErrorCode, PolicyOperationErrorCode, IssueSlotPolicyInput } from './policy-bootstrap.js';
|
|
37
|
+
export { paidPolicyOperation, readPolicyOperation } from './policy-operation.js';
|
|
38
|
+
export type { PaidPolicyOperationRequest } from './policy-operation.js';
|
|
39
|
+
export { drivePaidSession, waitForPaidSnapshot, PaidSessionRecoveryError } from './paid-session.js';
|
|
40
|
+
export type { PaidSessionDriverOptions, PaidSessionHolder, PaidWalletPresentation, PaidSessionRequestLink, PaidOAuthContext, PaidOAuthCredential } from './paid-session.js';
|
|
41
|
+
export { createMemoryStore } from './memory-store.js';
|
|
42
|
+
export { createSessionKey, sessionGrantCreateFragment, acceptSessionGrant, loadGrantedSession, GrantedSession, SessionEndedError, SessionRefreshError, SESSION_REFUSAL_CODES, SESSION_RETRYABLE_CODES, SESSION_VERIFIER_BEHIND_RETRY_MS, SessionRevokeIncompleteError, SessionRevokeUnconfirmedError } from './session-grants.js';
|
|
43
|
+
export { decryptInSession, SessionMessageError, MAX_MESSAGE_DEBITS } from './session-decrypt.js';
|
|
44
|
+
export type { SessionMessageRequest, SessionMessageResult, SessionReopened } from './session-decrypt.js';
|
|
45
|
+
export type { SessionKeyHandle, SessionGrantParams, SessionGrantCreateFragment, SlotTrust, SessionTransport, GrantedSessionOptions } from './session-grants.js';
|
|
46
|
+
export { signingIntentDigest, signingIntentCurve, requireIntentPayment, approveSigningIntent, SIGNING_INTENT_MAX_BYTES } from './signing-intents.js';
|
|
47
|
+
export type { SigningIntent, EthereumSigningIntent, TransactionSigningIntent, TypedDataSigningIntent, MessageSigningIntent, P256SigningIntent } from './signing-intents.js';
|