@t3foundry/tasra-sdk 0.0.0-stage → 0.3.0-next.1
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 +148 -0
- package/LICENSE +202 -0
- package/NOTICE +94 -0
- package/README.md +137 -2
- package/SECURITY.md +115 -0
- package/dist/app/approvals.d.ts +50 -0
- package/dist/app/approvals.js +90 -0
- package/dist/app/authorization.d.ts +19 -0
- package/dist/app/authorization.js +20 -0
- package/dist/app/client.d.ts +231 -0
- package/dist/app/client.js +272 -0
- package/dist/app/creation.d.ts +73 -0
- package/dist/app/creation.js +77 -0
- package/dist/app/deployment.d.ts +36 -0
- package/dist/app/deployment.js +18 -0
- package/dist/app/identity.d.ts +211 -0
- package/dist/app/identity.js +287 -0
- package/dist/app/index.d.ts +22 -0
- package/dist/app/index.js +12 -0
- package/dist/app/manifest.d.ts +74 -0
- package/dist/app/manifest.js +120 -0
- package/dist/app/node.d.ts +30 -0
- package/dist/app/node.js +159 -0
- package/dist/app/ready-slot.d.ts +157 -0
- package/dist/app/ready-slot.js +199 -0
- package/dist/app/tasra-client.d.ts +125 -0
- package/dist/app/tasra-client.js +79 -0
- package/dist/app/viem.d.ts +10 -0
- package/dist/app/viem.js +32 -0
- package/dist/app/wallet.d.ts +126 -0
- package/dist/app/wallet.js +137 -0
- package/dist/auth/dpop.d.ts +86 -0
- package/dist/auth/dpop.js +142 -0
- package/dist/auth/holderProof.d.ts +102 -0
- package/dist/auth/holderProof.js +161 -0
- package/dist/auth/identityScope.d.ts +19 -0
- package/dist/auth/identityScope.js +82 -0
- package/dist/auth/index.d.ts +11 -0
- package/dist/auth/index.js +13 -0
- package/dist/auth/oid4vp.d.ts +230 -0
- package/dist/auth/oid4vp.js +780 -0
- package/dist/auth/rego/wasm/PINS.json +11 -0
- package/dist/auth/rego/wasm/keykeeper_rego_wasm.d.ts +76 -0
- package/dist/auth/rego/wasm/keykeeper_rego_wasm.js +379 -0
- package/dist/auth/rego/wasm/keykeeper_rego_wasm_bg.wasm +0 -0
- package/dist/auth/rego.d.ts +192 -0
- package/dist/auth/rego.js +492 -0
- package/dist/auth/verifier.d.ts +166 -0
- package/dist/auth/verifier.js +211 -0
- package/dist/chain/abis/accountantSetRegistry.d.ts +441 -0
- package/dist/chain/abis/accountantSetRegistry.js +574 -0
- package/dist/chain/abis/accountantSlashing.d.ts +2071 -0
- package/dist/chain/abis/accountantSlashing.js +2670 -0
- package/dist/chain/abis/bondingCurve.d.ts +398 -0
- package/dist/chain/abis/bondingCurve.js +521 -0
- package/dist/chain/abis/equivocationSlasher.d.ts +292 -0
- package/dist/chain/abis/equivocationSlasher.js +379 -0
- package/dist/chain/abis/fixedTasraPriceOracle.d.ts +52 -0
- package/dist/chain/abis/fixedTasraPriceOracle.js +72 -0
- package/dist/chain/abis/index.d.ts +12801 -0
- package/dist/chain/abis/index.js +64 -0
- package/dist/chain/abis/keeperShareRegistry.d.ts +519 -0
- package/dist/chain/abis/keeperShareRegistry.js +675 -0
- package/dist/chain/abis/keyRegistry.d.ts +2421 -0
- package/dist/chain/abis/keyRegistry.js +3114 -0
- package/dist/chain/abis/livenessRegistry.d.ts +402 -0
- package/dist/chain/abis/livenessRegistry.js +524 -0
- package/dist/chain/abis/mockEurc.d.ts +210 -0
- package/dist/chain/abis/mockEurc.js +276 -0
- package/dist/chain/abis/nodeRegistry.d.ts +1630 -0
- package/dist/chain/abis/nodeRegistry.js +2113 -0
- package/dist/chain/abis/platformExecutor.d.ts +328 -0
- package/dist/chain/abis/platformExecutor.js +429 -0
- package/dist/chain/abis/prevrandaoSaltBeacon.d.ts +16 -0
- package/dist/chain/abis/prevrandaoSaltBeacon.js +24 -0
- package/dist/chain/abis/serviceRegistry.d.ts +556 -0
- package/dist/chain/abis/serviceRegistry.js +719 -0
- package/dist/chain/abis/settlement.d.ts +1624 -0
- package/dist/chain/abis/settlement.js +2096 -0
- package/dist/chain/abis/tasraSwapRouter.d.ts +92 -0
- package/dist/chain/abis/tasraSwapRouter.js +122 -0
- package/dist/chain/abis/tasraToken.d.ts +455 -0
- package/dist/chain/abis/tasraToken.js +599 -0
- package/dist/chain/abis/tasraVestingVault.d.ts +165 -0
- package/dist/chain/abis/tasraVestingVault.js +215 -0
- package/dist/chain/abis/thresholdRandomBeacon.d.ts +378 -0
- package/dist/chain/abis/thresholdRandomBeacon.js +494 -0
- package/dist/chain/abis/treasury.d.ts +301 -0
- package/dist/chain/abis/treasury.js +390 -0
- package/dist/chain/abis/verifierSetRegistry.d.ts +445 -0
- package/dist/chain/abis/verifierSetRegistry.js +579 -0
- package/dist/chain/client.d.ts +212 -0
- package/dist/chain/client.js +576 -0
- package/dist/chain/commitmentRecovery.d.ts +21 -0
- package/dist/chain/commitmentRecovery.js +44 -0
- package/dist/chain/committeeClient.d.ts +102 -0
- package/dist/chain/committeeClient.js +137 -0
- package/dist/chain/deployments.d.ts +56 -0
- package/dist/chain/deployments.js +269 -0
- package/dist/chain/discovery.d.ts +49 -0
- package/dist/chain/discovery.js +107 -0
- package/dist/chain/events.d.ts +58 -0
- package/dist/chain/events.js +125 -0
- package/dist/chain/format.d.ts +25 -0
- package/dist/chain/format.js +51 -0
- package/dist/chain/index.d.ts +41 -0
- package/dist/chain/index.js +56 -0
- package/dist/chain/manifest.d.ts +165 -0
- package/dist/chain/manifest.js +132 -0
- package/dist/chain/network-profiles.json +75 -0
- package/dist/chain/networks.d.ts +73 -0
- package/dist/chain/networks.js +62 -0
- package/dist/chain/node.d.ts +44 -0
- package/dist/chain/node.js +176 -0
- package/dist/chain/offchain.d.ts +149 -0
- package/dist/chain/offchain.js +73 -0
- package/dist/chain/provisionRule.d.ts +164 -0
- package/dist/chain/provisionRule.js +212 -0
- package/dist/chain/registeredAgent.d.ts +64 -0
- package/dist/chain/registeredAgent.js +140 -0
- package/dist/chain/registeredOperation.d.ts +49 -0
- package/dist/chain/registeredOperation.js +136 -0
- package/dist/chain/registeredRelay.d.ts +206 -0
- package/dist/chain/registeredRelay.js +312 -0
- package/dist/chain/revertReason.d.ts +14 -0
- package/dist/chain/revertReason.js +62 -0
- package/dist/chain/ruleAmendment.d.ts +80 -0
- package/dist/chain/ruleAmendment.js +195 -0
- package/dist/chain/ruleAmendmentCore.d.ts +129 -0
- package/dist/chain/ruleAmendmentCore.js +152 -0
- package/dist/chain/ruleInput.d.ts +10 -0
- package/dist/chain/ruleInput.js +13 -0
- package/dist/chain/serviceIdentity.d.ts +176 -0
- package/dist/chain/serviceIdentity.js +237 -0
- package/dist/chain/serviceProfiles.d.ts +39 -0
- package/dist/chain/serviceProfiles.js +74 -0
- package/dist/chain/services.d.ts +141 -0
- package/dist/chain/services.js +79 -0
- package/dist/chain/slotClient.d.ts +55 -0
- package/dist/chain/slotClient.js +62 -0
- package/dist/chain/slotSeed.d.ts +31 -0
- package/dist/chain/slotSeed.js +98 -0
- package/dist/chain/write.d.ts +431 -0
- package/dist/chain/write.js +958 -0
- package/dist/client/client.d.ts +112 -0
- package/dist/client/client.js +111 -0
- package/dist/client/index.d.ts +3 -0
- package/dist/client/index.js +2 -0
- package/dist/client/session.d.ts +67 -0
- package/dist/client/session.js +238 -0
- package/dist/committee/client.d.ts +284 -0
- package/dist/committee/client.js +351 -0
- package/dist/committee/dual-sign.d.ts +110 -0
- package/dist/committee/dual-sign.js +202 -0
- package/dist/committee/ecdsa.d.ts +36 -0
- package/dist/committee/ecdsa.js +45 -0
- package/dist/committee/extraction.d.ts +82 -0
- package/dist/committee/extraction.js +96 -0
- package/dist/committee/index.d.ts +19 -0
- package/dist/committee/index.js +13 -0
- package/dist/committee/oauth.d.ts +51 -0
- package/dist/committee/oauth.js +90 -0
- package/dist/committee/receipts.d.ts +51 -0
- package/dist/committee/receipts.js +59 -0
- package/dist/committee/request.d.ts +264 -0
- package/dist/committee/request.js +305 -0
- package/dist/committee/token.d.ts +274 -0
- package/dist/committee/token.js +418 -0
- package/dist/crypto/constants.d.ts +10 -0
- package/dist/crypto/constants.js +32 -0
- package/dist/crypto/detect.d.ts +20 -0
- package/dist/crypto/detect.js +44 -0
- package/dist/crypto/envelope.d.ts +60 -0
- package/dist/crypto/envelope.js +243 -0
- package/dist/crypto/frost.d.ts +49 -0
- package/dist/crypto/frost.js +152 -0
- package/dist/crypto/hex.d.ts +7 -0
- package/dist/crypto/hex.js +24 -0
- package/dist/crypto/ibe-blob.d.ts +114 -0
- package/dist/crypto/ibe-blob.js +208 -0
- package/dist/crypto/ibe.d.ts +88 -0
- package/dist/crypto/ibe.js +262 -0
- package/dist/crypto/index.d.ts +12 -0
- package/dist/crypto/index.js +12 -0
- package/dist/crypto/kem.d.ts +55 -0
- package/dist/crypto/kem.js +241 -0
- package/dist/decryption/client.d.ts +64 -0
- package/dist/decryption/client.js +82 -0
- package/dist/decryption/index.d.ts +2 -0
- package/dist/decryption/index.js +2 -0
- package/dist/errors.d.ts +124 -0
- package/dist/errors.js +167 -0
- package/dist/index.d.ts +43 -0
- package/dist/index.js +98 -0
- package/dist/keys/index.d.ts +1 -0
- package/dist/keys/index.js +4 -0
- package/dist/keys/node-client.d.ts +27 -0
- package/dist/keys/node-client.js +97 -0
- package/dist/oid4vp/binding.d.ts +76 -0
- package/dist/oid4vp/binding.js +118 -0
- package/dist/oid4vp/did-web.d.ts +49 -0
- package/dist/oid4vp/did-web.js +57 -0
- package/dist/oid4vp/index.d.ts +9 -0
- package/dist/oid4vp/index.js +10 -0
- package/dist/oid4vp/jose.d.ts +166 -0
- package/dist/oid4vp/jose.js +242 -0
- package/dist/oid4vp/jwe.d.ts +30 -0
- package/dist/oid4vp/jwe.js +93 -0
- package/dist/oid4vp/oid4vci.d.ts +84 -0
- package/dist/oid4vp/oid4vci.js +85 -0
- package/dist/oid4vp/request-object.d.ts +109 -0
- package/dist/oid4vp/request-object.js +96 -0
- package/dist/oid4vp/sd-jwt.d.ts +177 -0
- package/dist/oid4vp/sd-jwt.js +208 -0
- package/dist/oid4vp/verifier-agent.d.ts +161 -0
- package/dist/oid4vp/verifier-agent.js +132 -0
- package/dist/oid4vp/wallet.d.ts +116 -0
- package/dist/oid4vp/wallet.js +108 -0
- package/dist/recipient/store.d.ts +67 -0
- package/dist/recipient/store.js +98 -0
- package/dist/signing/ecdsa.d.ts +49 -0
- package/dist/signing/ecdsa.js +79 -0
- package/dist/signing/frost.d.ts +88 -0
- package/dist/signing/frost.js +145 -0
- package/dist/signing/index.d.ts +4 -0
- package/dist/signing/index.js +3 -0
- package/dist/slots/faucet.d.ts +23 -0
- package/dist/slots/faucet.js +35 -0
- package/dist/slots/index.d.ts +2 -0
- package/dist/slots/index.js +4 -0
- package/dist/verifier-agent/index.d.ts +241 -0
- package/dist/verifier-agent/index.js +411 -0
- package/docs/DEVELOPER-EXPERIENCE.md +62 -0
- package/docs/README.md +33 -0
- package/docs/access-control.md +76 -0
- package/docs/ai-development.md +292 -0
- package/docs/api.md +338 -0
- package/docs/application-api.md +335 -0
- package/docs/architecture.md +65 -0
- package/docs/basics.md +48 -0
- package/docs/capabilities.md +86 -0
- package/docs/chain.md +153 -0
- package/docs/compatibility.md +36 -0
- package/docs/consumer-migrations.md +80 -0
- package/docs/create-slot.md +104 -0
- package/docs/document-signing.md +243 -0
- package/docs/encrypted-notes.md +129 -0
- package/docs/encryption.md +100 -0
- package/docs/errors.md +76 -0
- package/docs/flows.md +289 -0
- package/docs/fuji.md +127 -0
- package/docs/funding.md +126 -0
- package/docs/getting-started.md +94 -0
- package/docs/glossary.md +44 -0
- package/docs/installation.md +132 -0
- package/docs/manage-slot.md +95 -0
- package/docs/native-approvals.md +124 -0
- package/docs/prerequisites.md +137 -0
- package/docs/read-slot.md +41 -0
- package/docs/reference/README.md +30 -0
- package/docs/reference/app-node.md +102 -0
- package/docs/reference/app.md +1737 -0
- package/docs/reference/chain-node.md +159 -0
- package/docs/reference/chain.md +3609 -0
- package/docs/reference/committee.md +2176 -0
- package/docs/reference/main.md +4068 -0
- package/docs/reference/oid4vp.md +2547 -0
- package/docs/reference/verifier-agent.md +498 -0
- package/docs/shared-account.md +168 -0
- package/docs/signing-and-encryption.md +52 -0
- package/docs/signing.md +172 -0
- package/examples/committee-slot.ts +16 -0
- package/examples/connect-fuji.ts +41 -0
- package/examples/connect-network.ts +14 -0
- package/examples/credential-approvals.ts +46 -0
- package/examples/document-signing/README.md +59 -0
- package/examples/document-signing/backend.ts +132 -0
- package/examples/document-signing/build.mjs +19 -0
- package/examples/document-signing/config.ts +34 -0
- package/examples/document-signing/gitignore.template +9 -0
- package/examples/document-signing/model.ts +140 -0
- package/examples/document-signing/network.ts +58 -0
- package/examples/document-signing/package.json +25 -0
- package/examples/document-signing/public/index.html +27 -0
- package/examples/document-signing/public/sample.pdf +31 -0
- package/examples/document-signing/public/styles.css +531 -0
- package/examples/document-signing/server.ts +358 -0
- package/examples/document-signing/setup.ts +111 -0
- package/examples/document-signing/store.ts +105 -0
- package/examples/document-signing/tsconfig.json +24 -0
- package/examples/document-signing/verify.ts +24 -0
- package/examples/document-signing/web/app.ts +312 -0
- package/examples/document-signing/web/preview.ts +67 -0
- package/examples/document-signing/web/wallet.ts +146 -0
- package/examples/document-signing/workflow.test.ts +228 -0
- package/examples/document-signing/workflow.ts +241 -0
- package/examples/document-signing.ts +96 -0
- package/examples/encrypted-notes.ts +86 -0
- package/examples/ethers-signer.ts +204 -0
- package/examples/fund-slot.ts +73 -0
- package/examples/getting-started.ts +25 -0
- package/examples/learning-authorize.ts +23 -0
- package/examples/learning-cancel-slot.ts +11 -0
- package/examples/learning-context.ts +28 -0
- package/examples/learning-create-slot.ts +25 -0
- package/examples/learning-read-slot.ts +8 -0
- package/examples/learning-renew-slot.ts +12 -0
- package/examples/learning-sign.ts +8 -0
- package/examples/live-config.ts +71 -0
- package/examples/minimal.ts +6 -0
- package/examples/native-approvals.ts +57 -0
- package/examples/network.ts +58 -0
- package/examples/offline.ts +16 -0
- package/examples/personal-vault.ts +20 -0
- package/examples/provision-slot.ts +47 -0
- package/examples/shared-account.ts +46 -0
- package/examples/slot-address.ts +13 -0
- package/examples/slot-creation.ts +9 -0
- package/examples/tutorial-negative.ts +26 -0
- package/examples/tutorial-support.ts +76 -0
- package/examples/viem-account.ts +203 -0
- package/package.json +303 -4
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
// High-level committee-authorization orchestration.
|
|
2
|
+
//
|
|
3
|
+
// The low-level pieces already exist: `gatherCommitteeToken` (fan out + assemble) and
|
|
4
|
+
// `committeeSign`/`committeeDecrypt` (submit) in ./client.ts, the committee math in ./token.ts,
|
|
5
|
+
// and the chain reads in ../chain/client.ts. This module is the glue that turns them into a
|
|
6
|
+
// one-call flow: read the per-request randomness + the slot's verifier-committee policy from
|
|
7
|
+
// chain, gather a quorum of attributable verifier signatures, assemble the compound token, and
|
|
8
|
+
// - when the full verifier set is known and an anchored snapshot matches - build the trustless
|
|
9
|
+
// verifier-set inclusion proofs the keeper checks against `VerifierSetRegistry`.
|
|
10
|
+
//
|
|
11
|
+
// The chain reads are injected (`CommitteeChainReads`) so this works with the SDK chain client
|
|
12
|
+
// or raw viem. Proofs are OPTIONAL: when the verifier directory lacks operator/pubkey or no
|
|
13
|
+
// snapshot is anchored, the token is submitted without proofs and the keeper falls back to its
|
|
14
|
+
// configured verifier set.
|
|
15
|
+
import { gatherCommitteeToken, committeeSign, committeeDecrypt, requestIbeExtractionPartials, } from './client.js';
|
|
16
|
+
import { ibeCombineDecrypt, ibeCombineExtract } from '../crypto/ibe.js';
|
|
17
|
+
import { merkleRoot, merkleProof, verifierLeaf, clientBindingHash, compoundTokenHash, decodeCompoundToken, } from './token.js';
|
|
18
|
+
import { hexToBytes, bytesToHex } from '../crypto/hex.js';
|
|
19
|
+
import { ed25519 } from '@noble/curves/ed25519';
|
|
20
|
+
import { createHolderProof } from '../auth/holderProof.js';
|
|
21
|
+
/**
|
|
22
|
+
* One holder proof-of-possession per drawn verifier: fetch THAT verifier's nonce, sign it
|
|
23
|
+
* with the holder key over the same credentials + slot, hand it back for that verifier only.
|
|
24
|
+
* Pass the result as `holderProof` to {@link requestCommitteeToken} (or the one-call
|
|
25
|
+
* helpers built on it).
|
|
26
|
+
*
|
|
27
|
+
* @param opts - Holder signer, credentials, audience and optional operation binding.
|
|
28
|
+
*/
|
|
29
|
+
export function holderProofPerVerifier(opts) {
|
|
30
|
+
return verifier => createHolderProof(verifier.url, {
|
|
31
|
+
signer: opts.signer,
|
|
32
|
+
audience: opts.audience,
|
|
33
|
+
credentials: opts.credentials,
|
|
34
|
+
slotId: opts.slotId,
|
|
35
|
+
action: opts.action,
|
|
36
|
+
ttlSecs: opts.ttlSecs,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* A {@link ClientSigner} from a 32-byte ed25519 secret key (the common `did:key` holder).
|
|
41
|
+
*
|
|
42
|
+
* @param secretKey - 32-byte Ed25519 secret seed used to sign client request bindings.
|
|
43
|
+
*/
|
|
44
|
+
export function ed25519ClientSigner(secretKey) {
|
|
45
|
+
return {
|
|
46
|
+
publicKey: ed25519.getPublicKey(secretKey),
|
|
47
|
+
sign: (bindingHash) => ed25519.sign(bindingHash, secretKey),
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function bytesEqual(a, b) {
|
|
51
|
+
return a.length === b.length && a.every((x, i) => x === b[i]);
|
|
52
|
+
}
|
|
53
|
+
function toBytes32(x) {
|
|
54
|
+
return typeof x === 'string' ? hexToBytes(x) : x;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Adapt the SDK chain client's `readers` into {@link CommitteeChainReads}.
|
|
58
|
+
*
|
|
59
|
+
* @param readers - Chain reader methods for the beacon, slot verifier policy and optional verifier snapshots.
|
|
60
|
+
*/
|
|
61
|
+
export function committeeChainReadsFromClient(readers) {
|
|
62
|
+
return {
|
|
63
|
+
seed: () => readers.beacon.seed(),
|
|
64
|
+
epoch: () => readers.beacon.epoch(),
|
|
65
|
+
...(readers.beacon.seedAt ? { seedAt: (epoch) => readers.beacon.seedAt(epoch) } : {}),
|
|
66
|
+
verifierPolicy: id => readers.keyRegistry.verifierPolicy(id),
|
|
67
|
+
...(readers.verifierSet
|
|
68
|
+
? {
|
|
69
|
+
snapshot: async (epoch) => {
|
|
70
|
+
const s = (await readers.verifierSet.snapshotAt(epoch));
|
|
71
|
+
const root = Array.isArray(s) ? s[0] : s.root;
|
|
72
|
+
const size = Number(Array.isArray(s) ? s[1] : s.size);
|
|
73
|
+
const zero = /^0x0{64}$/i.test(root);
|
|
74
|
+
return size > 0 && !zero ? { root: root, size } : null;
|
|
75
|
+
},
|
|
76
|
+
}
|
|
77
|
+
: {}),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Build snapshot-inclusion proofs for the token's `signerIndexes` from the full ordered verifier
|
|
82
|
+
* directory. Returns `undefined` (never a wrong proof) when the directory is incomplete, a key is
|
|
83
|
+
* missing, or the reconstructed root disagrees with the anchored `snapshotRoot` - so a mismatch
|
|
84
|
+
* degrades to the keeper's configured-set path rather than shipping a proof the keeper rejects.
|
|
85
|
+
*
|
|
86
|
+
* @param verifiers - Complete verifier directory including indices, operators and public keys.
|
|
87
|
+
* @param registrySize - Expected number of registry entries.
|
|
88
|
+
* @param signerIndexes - Verifier indices whose inclusion proofs are required.
|
|
89
|
+
* @param snapshotRoot - Optional independently anchored verifier snapshot root.
|
|
90
|
+
*/
|
|
91
|
+
export function buildVerifierProofs(verifiers, registrySize, signerIndexes, snapshotRoot) {
|
|
92
|
+
const byIndex = new Map(verifiers.map(v => [v.index, v]));
|
|
93
|
+
const leaves = [];
|
|
94
|
+
for (let i = 0; i < registrySize; i++) {
|
|
95
|
+
const v = byIndex.get(i);
|
|
96
|
+
if (!v || !v.operator || !v.pubkey)
|
|
97
|
+
return undefined;
|
|
98
|
+
leaves.push(verifierLeaf(i, hexToBytes(v.operator), hexToBytes(v.pubkey)));
|
|
99
|
+
}
|
|
100
|
+
const root = merkleRoot(leaves);
|
|
101
|
+
if (!root)
|
|
102
|
+
return undefined;
|
|
103
|
+
if (snapshotRoot && !bytesEqual(root, snapshotRoot))
|
|
104
|
+
return undefined;
|
|
105
|
+
const proofs = [];
|
|
106
|
+
for (const idx of signerIndexes) {
|
|
107
|
+
const v = byIndex.get(idx);
|
|
108
|
+
const p = merkleProof(leaves, idx);
|
|
109
|
+
if (!v || !v.operator || !v.pubkey || !p)
|
|
110
|
+
return undefined;
|
|
111
|
+
proofs.push({ verifierIndex: idx, operator: v.operator, pubkey: v.pubkey, proof: p.map(bytesToHex) });
|
|
112
|
+
}
|
|
113
|
+
return proofs;
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Resolve the per-request randomness + the slot's committee policy from chain, fan out to the
|
|
117
|
+
* drawn verifiers to gather a quorum of attributable signatures, and assemble the compound token
|
|
118
|
+
* (+ trustless verifier proofs when derivable). Throws if the slot has no verifierPolicy or a
|
|
119
|
+
* quorum can't be gathered.
|
|
120
|
+
*/
|
|
121
|
+
/**
|
|
122
|
+
* Which beacon epoch a draw is pinned to. Keepers and verifiers admit `{latest, latest - 1}`
|
|
123
|
+
* (the seed pin). The accountants anchor an epoch's verifier-set snapshot one settle
|
|
124
|
+
* tick after the epoch starts, so a token pinned to `latest` right after a flip is refused by
|
|
125
|
+
* the keeper ("no verifier-set snapshot anchored at epoch N") until then; `epochLag: 1` pins
|
|
126
|
+
* the draw to the previous epoch, which is always anchored - no wait, same security bound.
|
|
127
|
+
*/
|
|
128
|
+
export async function pinnedDraw(chain, latest, epochLag = 0) {
|
|
129
|
+
const lag = Math.max(0, Math.min(1, Math.floor(epochLag)));
|
|
130
|
+
const epoch = Math.max(0, latest - lag);
|
|
131
|
+
if (epoch === latest)
|
|
132
|
+
return { epoch, seed: toBytes32(await chain.seed()) };
|
|
133
|
+
if (!chain.seedAt)
|
|
134
|
+
throw new Error('epochLag needs chain.seedAt (ThresholdRandomBeacon.seedAt); adapt the chain reads with committeeChainReadsFromClient');
|
|
135
|
+
return { epoch, seed: toBytes32(await chain.seedAt(BigInt(epoch))) };
|
|
136
|
+
}
|
|
137
|
+
/**
|
|
138
|
+
* Read the verifier committee draw, request authorization and assemble the quorum token with available membership proofs.
|
|
139
|
+
*
|
|
140
|
+
* @param opts - Chain draw, verifier directory, credentials and holder authorization.
|
|
141
|
+
*/
|
|
142
|
+
export async function requestCommitteeToken(opts) {
|
|
143
|
+
const slotId = opts.slotId;
|
|
144
|
+
if (!opts.holderProof && !opts.allowNoHolderProof) {
|
|
145
|
+
throw new Error('requestCommitteeToken: holderProof is required to prove control of the holder DID. ' +
|
|
146
|
+
'A verifier with `require_holder_binding = false` will accept the request without one — ' +
|
|
147
|
+
'pass `allowNoHolderProof: true` to say so deliberately.');
|
|
148
|
+
}
|
|
149
|
+
const [epochRaw, policy] = await Promise.all([opts.chain.epoch(), opts.chain.verifierPolicy(slotId)]);
|
|
150
|
+
const { epoch, seed } = await pinnedDraw(opts.chain, Number(epochRaw), opts.epochLag);
|
|
151
|
+
const committee = Number(policy[0]);
|
|
152
|
+
const quorum = Number(policy[1]);
|
|
153
|
+
if (committee === 0) {
|
|
154
|
+
throw new Error(`slot ${slotId.slice(0, 10)}… has no verifierPolicy (committee path not wired); use the JWT path`);
|
|
155
|
+
}
|
|
156
|
+
// Registry size (the committee-draw modulus): the anchored snapshot's size when available -
|
|
157
|
+
// it's the value the verifier/keeper agree on - else the directory length.
|
|
158
|
+
let registrySize = opts.verifiers.length;
|
|
159
|
+
let snapshotRoot;
|
|
160
|
+
if (opts.chain.snapshot) {
|
|
161
|
+
const snap = await opts.chain.snapshot(BigInt(epoch)).catch(() => null);
|
|
162
|
+
if (snap && snap.size > 0) {
|
|
163
|
+
registrySize = snap.size;
|
|
164
|
+
snapshotRoot = toBytes32(snap.root);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
if (registrySize < committee) {
|
|
168
|
+
throw new Error(`active verifier set (${registrySize}) is smaller than the committee size (${committee})`);
|
|
169
|
+
}
|
|
170
|
+
const now = opts.nowSecs ?? Math.floor(Date.now() / 1000);
|
|
171
|
+
const iat = now - 5;
|
|
172
|
+
const exp = now + (opts.ttlSecs ?? 300);
|
|
173
|
+
// Taken from the REFERENCE reply - the one whose ruleHash built the
|
|
174
|
+
// token - so the version and the hash describe one evaluation. Verifiers that
|
|
175
|
+
// straddle an activation legitimately disagree, and pairing a version from one
|
|
176
|
+
// with a hash from another would describe a state that never existed.
|
|
177
|
+
let ruleVersion;
|
|
178
|
+
// A per-verifier proof function is resolved inside the gather, against each verifier's
|
|
179
|
+
// own URL; a string is the legacy single proof (fine when holder binding is off).
|
|
180
|
+
const byIndex = new Map(opts.verifiers.map(v => [v.index, v]));
|
|
181
|
+
const holderProofFor = typeof opts.holderProof === 'function'
|
|
182
|
+
? (v) => opts.holderProof(byIndex.get(v.index) ?? { index: v.index, url: v.url })
|
|
183
|
+
: undefined;
|
|
184
|
+
const token = await gatherCommitteeToken({
|
|
185
|
+
verifiers: opts.verifiers.map(v => ({ index: v.index, url: v.url })),
|
|
186
|
+
quorum,
|
|
187
|
+
holderProofFor,
|
|
188
|
+
onReplies: (_all, reference) => {
|
|
189
|
+
ruleVersion = reference.ruleVersion;
|
|
190
|
+
},
|
|
191
|
+
authorize: {
|
|
192
|
+
holder: opts.holder,
|
|
193
|
+
credentials: opts.credentials,
|
|
194
|
+
holderProof: typeof opts.holderProof === 'string' ? opts.holderProof : '',
|
|
195
|
+
tokenType: opts.tokenType ?? 'JWT',
|
|
196
|
+
seed,
|
|
197
|
+
epoch,
|
|
198
|
+
slotId: hexToBytes(slotId),
|
|
199
|
+
registrySize,
|
|
200
|
+
committee,
|
|
201
|
+
iat,
|
|
202
|
+
exp,
|
|
203
|
+
...(opts.scopedIdentity !== undefined ? { identity: opts.scopedIdentity } : {}),
|
|
204
|
+
},
|
|
205
|
+
});
|
|
206
|
+
const signerIndexes = token.signatures.map(s => s.verifier_index);
|
|
207
|
+
const verifierProofs = buildVerifierProofs(opts.verifiers, registrySize, signerIndexes, snapshotRoot);
|
|
208
|
+
// Sign the request bundle (bound to the token's canonical hash + the slot).
|
|
209
|
+
let clientPubkey;
|
|
210
|
+
let clientSignature;
|
|
211
|
+
if (opts.clientSigner) {
|
|
212
|
+
const tokenHash = compoundTokenHash(decodeCompoundToken(token));
|
|
213
|
+
const binding = clientBindingHash(hexToBytes(slotId), tokenHash);
|
|
214
|
+
clientSignature = await opts.clientSigner.sign(binding);
|
|
215
|
+
clientPubkey = opts.clientSigner.publicKey;
|
|
216
|
+
}
|
|
217
|
+
return { token, committee, quorum, registrySize, seed, epoch, verifierProofs, clientPubkey, clientSignature, ruleVersion };
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* One-call committee-authorized threshold sign: resolve token (+proofs) then POST to the keeper.
|
|
221
|
+
*
|
|
222
|
+
* @param opts - Token request settings, keeper endpoint and message to sign.
|
|
223
|
+
*/
|
|
224
|
+
export async function committeeSignRequest(opts) {
|
|
225
|
+
const { token, verifierProofs, clientPubkey, clientSignature } = await requestCommitteeToken(opts);
|
|
226
|
+
const signOpts = {
|
|
227
|
+
nodeUrl: opts.nodeUrl,
|
|
228
|
+
committeeToken: token,
|
|
229
|
+
message: opts.message,
|
|
230
|
+
signingSet: opts.signingSet,
|
|
231
|
+
userSignature: opts.userSignature,
|
|
232
|
+
targetKeykeeper: opts.targetKeykeeper,
|
|
233
|
+
verifierProofs,
|
|
234
|
+
clientPubkey,
|
|
235
|
+
clientSignature,
|
|
236
|
+
};
|
|
237
|
+
return committeeSign(signOpts);
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* One-call committee-authorized threshold decrypt.
|
|
241
|
+
*
|
|
242
|
+
* @param opts - Token request settings, keeper endpoint, ciphertext and associated data.
|
|
243
|
+
*/
|
|
244
|
+
export async function committeeDecryptRequest(opts) {
|
|
245
|
+
const { token, verifierProofs, clientPubkey, clientSignature } = await requestCommitteeToken(opts);
|
|
246
|
+
const decOpts = {
|
|
247
|
+
nodeUrl: opts.nodeUrl,
|
|
248
|
+
committeeToken: token,
|
|
249
|
+
ciphertext: opts.ciphertext,
|
|
250
|
+
identity: opts.identity,
|
|
251
|
+
decryptingSet: opts.decryptingSet,
|
|
252
|
+
blsPeers: opts.blsPeers,
|
|
253
|
+
userSignature: opts.userSignature,
|
|
254
|
+
ciphertextEpoch: opts.ciphertextEpoch,
|
|
255
|
+
targetKeykeeper: opts.targetKeykeeper,
|
|
256
|
+
verifierProofs,
|
|
257
|
+
clientPubkey,
|
|
258
|
+
clientSignature,
|
|
259
|
+
};
|
|
260
|
+
return committeeDecrypt(decOpts);
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Resolve an identity-scoped committee token, fan out for extraction partials, verify
|
|
264
|
+
* each (identifiable abort - the error names the node), and return `sk_ID` (48-byte
|
|
265
|
+
* compressed G1).
|
|
266
|
+
*
|
|
267
|
+
* CUSTODY OPT-IN: holding `sk_ID` is a durable capability over every past and future
|
|
268
|
+
* ciphertext to this identity. Prefer {@link ibeDecryptRequest}, which combines,
|
|
269
|
+
* decrypts and drops it. Zeroize the returned bytes when done.
|
|
270
|
+
*
|
|
271
|
+
* @param opts - Authorization context, keeper endpoints and requested identity.
|
|
272
|
+
*/
|
|
273
|
+
export async function ibeExtractRequest(opts) {
|
|
274
|
+
const { partials, identityBytes } = await gatherIbePartials(opts);
|
|
275
|
+
const vsMap = new Map(partials.map(p => [p.identifier, p.verifyingShareG2]));
|
|
276
|
+
return ibeCombineExtract(vsMap, partials.map(p => ({ identifier: p.identifier, value: p.value })), identityBytes);
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* One-call identity-scoped decrypt (the read path): token to extraction fan-out
|
|
280
|
+
* to verify each partial to combine to decrypt. The intermediate `sk_ID` never surfaces.
|
|
281
|
+
*
|
|
282
|
+
* @param opts - Authorization context, identity and IBE ciphertext to decrypt.
|
|
283
|
+
*/
|
|
284
|
+
export async function ibeDecryptRequest(opts) {
|
|
285
|
+
const { partials, identityBytes } = await gatherIbePartials(opts);
|
|
286
|
+
const vsMap = new Map(partials.map(p => [p.identifier, p.verifyingShareG2]));
|
|
287
|
+
return ibeCombineDecrypt(vsMap, partials.map(p => ({ identifier: p.identifier, value: p.value })), opts.ciphertext, identityBytes);
|
|
288
|
+
}
|
|
289
|
+
async function gatherIbePartials(opts) {
|
|
290
|
+
const { token, verifierProofs, clientPubkey, clientSignature } = await requestCommitteeToken({
|
|
291
|
+
...opts,
|
|
292
|
+
scopedIdentity: opts.identity,
|
|
293
|
+
});
|
|
294
|
+
const partials = await requestIbeExtractionPartials({
|
|
295
|
+
nodeUrls: opts.nodeUrls,
|
|
296
|
+
committeeToken: token,
|
|
297
|
+
identity: opts.identity,
|
|
298
|
+
userSignature: opts.userSignature,
|
|
299
|
+
ciphertextEpoch: opts.ciphertextEpoch,
|
|
300
|
+
verifierProofs,
|
|
301
|
+
clientPubkey,
|
|
302
|
+
clientSignature,
|
|
303
|
+
});
|
|
304
|
+
return { partials, identityBytes: new TextEncoder().encode(opts.identity) };
|
|
305
|
+
}
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
/** Compound authorization token category, used in the signed canonical encoding. */
|
|
2
|
+
export type TokenType = 'JWT' | 'refresh';
|
|
3
|
+
/**
|
|
4
|
+
* Deterministically select `count` distinct verifier indexes in `[0, registrySize)` for one
|
|
5
|
+
* request: `index = keccak256(SELECT_DOMAIN || slotId || epoch(u64 BE) || seed || iter(u64 BE)) mod registrySize`,
|
|
6
|
+
* skipping a repeat and incrementing `iter`. Identical, identically-ordered to what the
|
|
7
|
+
* verifier selects and the keeper reconstructs.
|
|
8
|
+
*
|
|
9
|
+
* @param slotId - 32-byte slot identifier.
|
|
10
|
+
* @param epoch - Beacon epoch for the committee draw.
|
|
11
|
+
* @param seed - 32-byte beacon seed for that epoch.
|
|
12
|
+
* @param registrySize - Number of entries in the verifier registry.
|
|
13
|
+
* @param count - Number of distinct verifier indices to select.
|
|
14
|
+
*/
|
|
15
|
+
export declare function selectVerifierCommittee(slotId: Uint8Array, epoch: number | bigint, seed: Uint8Array, registrySize: number, count: number): number[];
|
|
16
|
+
/** The data the quorum verifiers sign over. All byte fields are 32 bytes unless noted. */
|
|
17
|
+
export interface CompoundTokenPayload {
|
|
18
|
+
/** Compound authorization token category. */
|
|
19
|
+
tokenType: TokenType;
|
|
20
|
+
/** Beacon seed used for committee selection. */
|
|
21
|
+
seed: Uint8Array;
|
|
22
|
+
/** Beacon epoch used for the verifier committee draw. */
|
|
23
|
+
epoch: number | bigint;
|
|
24
|
+
/** 32-byte slot identifier. */
|
|
25
|
+
slotId: Uint8Array;
|
|
26
|
+
/** Hash of the credential presentation bound into the token. */
|
|
27
|
+
vpHash: Uint8Array;
|
|
28
|
+
/** Keccak-256 hash of the authenticated holder identifier. Stable across repeated presentations by the same holder and signed as part of the token. */
|
|
29
|
+
holderHash: Uint8Array;
|
|
30
|
+
/** Keccak-256 hash of the raw rule bytes, without salt. This differs from the salted on-chain ruleCommitment. */
|
|
31
|
+
ruleHash: Uint8Array;
|
|
32
|
+
/** Keccak-256 hash of the authorized IBE identity. Present only for identity-scoped operations and included in the signed encoding; identity-blind endpoints reject scoped tokens. */
|
|
33
|
+
identityHash?: Uint8Array;
|
|
34
|
+
/** Keccak-256 operation-binding hash. Required when keepers enforce request binding; absent only on authorization paths that do not derive it. */
|
|
35
|
+
requestHash?: Uint8Array;
|
|
36
|
+
/**
|
|
37
|
+
* How the holder's key possession was proved. `0x00` = Unbound (no proof),
|
|
38
|
+
* `0x01` = HolderKey (KB-JWT nonce verified), `0x02` = IssuerAsserted (reserved).
|
|
39
|
+
* Always present in the canonical bytes; defaults to `0x00` when omitted.
|
|
40
|
+
*/
|
|
41
|
+
binding?: number;
|
|
42
|
+
/** Indices of the selected verifier committee. */
|
|
43
|
+
verifierIndexes: number[];
|
|
44
|
+
/** Issue time in Unix seconds. */
|
|
45
|
+
iat: number | bigint;
|
|
46
|
+
/** Expiration time in Unix seconds. */
|
|
47
|
+
exp: number | bigint;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Canonical, domain-separated, length-prefixed byte encoding hashed for signing.
|
|
51
|
+
*
|
|
52
|
+
* @param p - Compound token payload, excluding signatures.
|
|
53
|
+
*/
|
|
54
|
+
export declare function compoundTokenCanonicalBytes(p: CompoundTokenPayload): Uint8Array;
|
|
55
|
+
/**
|
|
56
|
+
* `keccak256` of the canonical bytes - the value each quorum verifier signs.
|
|
57
|
+
*
|
|
58
|
+
* @param p - Compound token payload, excluding signatures.
|
|
59
|
+
*/
|
|
60
|
+
export declare function compoundTokenHash(p: CompoundTokenPayload): Uint8Array;
|
|
61
|
+
/**
|
|
62
|
+
* The hash a keeper signs to attest it served `opId` on `slotId` under the token `tokenHash`.
|
|
63
|
+
*
|
|
64
|
+
* @param chainId - EVM chain identifier.
|
|
65
|
+
* @param opId - 32-byte audit operation identifier.
|
|
66
|
+
* @param slotId - 32-byte slot identifier.
|
|
67
|
+
* @param tokenHash - 32-byte compound token hash.
|
|
68
|
+
*/
|
|
69
|
+
export declare function opAttestationHash(chainId: number | bigint, opId: Uint8Array, slotId: Uint8Array, tokenHash: Uint8Array): Uint8Array;
|
|
70
|
+
/**
|
|
71
|
+
* The 32-byte hash the client (== the credential holder) signs to attest it authorized this
|
|
72
|
+
* operation on `slotId` under the compound token whose canonical hash is `tokenHash`:
|
|
73
|
+
* `keccak256(DOMAIN || slotId || tokenHash)`. Byte-identical to the reference `client_binding_hash`, so
|
|
74
|
+
* the keeper (hot path) and accountant (audit) verify the client signature over the same bytes.
|
|
75
|
+
*
|
|
76
|
+
* @param slotId - 32-byte slot identifier.
|
|
77
|
+
* @param tokenHash - 32-byte compound token hash.
|
|
78
|
+
*/
|
|
79
|
+
export declare function clientBindingHash(slotId: Uint8Array, tokenHash: Uint8Array): Uint8Array;
|
|
80
|
+
/**
|
|
81
|
+
* `keccak256(DOMAIN || index(u32 BE) || operator(20) || keccak256(pubkey))` - matches the on-chain leaf.
|
|
82
|
+
*
|
|
83
|
+
* @param index - Zero-based verifier registry index.
|
|
84
|
+
* @param operator - 20-byte operator address.
|
|
85
|
+
* @param pubkey - 32-byte Ed25519 verifier public key.
|
|
86
|
+
*/
|
|
87
|
+
export declare function verifierLeaf(index: number, operator: Uint8Array, pubkey: Uint8Array): Uint8Array;
|
|
88
|
+
/**
|
|
89
|
+
* Verify a sorted-pair keccak Merkle inclusion proof (leaf to root).
|
|
90
|
+
*
|
|
91
|
+
* @param leaf - Leaf hash to prove.
|
|
92
|
+
* @param proof - Sibling hashes ordered from the leaf toward the root.
|
|
93
|
+
* @param root - Expected Merkle root.
|
|
94
|
+
*/
|
|
95
|
+
export declare function verifyMerkleProof(leaf: Uint8Array, proof: Uint8Array[], root: Uint8Array): boolean;
|
|
96
|
+
/**
|
|
97
|
+
* Build the Merkle root over `leaves` (sorted-pair; an odd node is promoted unchanged to the
|
|
98
|
+
* next level). `null` for an empty set. Byte-identical to the reference `merkle_root`, so a root
|
|
99
|
+
* built here matches the on-chain `VerifierSetRegistry`/`Settlement` anchored root.
|
|
100
|
+
*
|
|
101
|
+
* @param leaves - Ordered Merkle leaf hashes.
|
|
102
|
+
*/
|
|
103
|
+
export declare function merkleRoot(leaves: Uint8Array[]): Uint8Array | null;
|
|
104
|
+
/**
|
|
105
|
+
* The inclusion proof (sibling hashes, leaf to root) for `index` in `leaves`. `null` if `index`
|
|
106
|
+
* is out of range. Mirrors the reference `merkle_proof`; pairs with [`verifyMerkleProof`].
|
|
107
|
+
*
|
|
108
|
+
* @param leaves - Ordered Merkle leaf hashes.
|
|
109
|
+
* @param index - Zero-based index of the leaf to prove.
|
|
110
|
+
*/
|
|
111
|
+
export declare function merkleProof(leaves: Uint8Array[], index: number): Uint8Array[] | null;
|
|
112
|
+
/** One verifier's signature within a compound token. */
|
|
113
|
+
export interface CommitteeSignature {
|
|
114
|
+
/** Zero-based verifier registry index. */
|
|
115
|
+
verifierIndex: number;
|
|
116
|
+
/** Raw Ed25519 verifier signature. */
|
|
117
|
+
signature: Uint8Array;
|
|
118
|
+
}
|
|
119
|
+
/** The active verifier set: registry size + index to Ed25519 public key (32 bytes). */
|
|
120
|
+
export interface VerifierSet {
|
|
121
|
+
/** Number of entries in the verifier registry. */
|
|
122
|
+
registrySize: number;
|
|
123
|
+
/** Registry index to authenticated Ed25519 public key mapping. */
|
|
124
|
+
pubkeys: Map<number, Uint8Array>;
|
|
125
|
+
}
|
|
126
|
+
/** What a valid compound token attests. */
|
|
127
|
+
export interface VerifiedToken {
|
|
128
|
+
/** 32-byte slot identifier. */
|
|
129
|
+
slotId: Uint8Array;
|
|
130
|
+
/** Hash of the credential presentation bound into the token. */
|
|
131
|
+
vpHash: Uint8Array;
|
|
132
|
+
/** The holder a quorum attested - the value a distinctness rule keys on. */
|
|
133
|
+
holderHash: Uint8Array;
|
|
134
|
+
/** the quorum-attested identity binding - present iff the token is scoped. */
|
|
135
|
+
identityHash?: Uint8Array;
|
|
136
|
+
/** Beacon epoch used for the verifier committee draw. */
|
|
137
|
+
epoch: number | bigint;
|
|
138
|
+
/** Compound authorization token category. */
|
|
139
|
+
tokenType: TokenType;
|
|
140
|
+
/** Indices of the distinct verifier signatures that passed verification. */
|
|
141
|
+
verifiedSigners: number[];
|
|
142
|
+
}
|
|
143
|
+
/** Compound token, trusted verifier set, expected rule binding and freshness constraints. */
|
|
144
|
+
export interface VerifyCompoundTokenOptions {
|
|
145
|
+
/** The decoded token, signatures included (see `decodeCompoundToken`). */
|
|
146
|
+
token: CompoundTokenPayload & {
|
|
147
|
+
signatures: CommitteeSignature[];
|
|
148
|
+
};
|
|
149
|
+
/** The active verifier set to verify signatures against. */
|
|
150
|
+
set: VerifierSet;
|
|
151
|
+
/** Committee size - how many verifiers the on-chain draw selects. */
|
|
152
|
+
committee: number;
|
|
153
|
+
/** Minimum co-signatures required *from the drawn committee*. */
|
|
154
|
+
quorum: number;
|
|
155
|
+
/** Current time, UNIX **seconds**. */
|
|
156
|
+
now: number;
|
|
157
|
+
/** Clock-skew tolerance, **seconds**, applied to both `iat` and `exp`. */
|
|
158
|
+
leeway: number;
|
|
159
|
+
/** Expected Keccak-256 hash of the raw rule bytes, without salt. Do not supply the on-chain salted ruleCommitment. */
|
|
160
|
+
slotRuleHash: Uint8Array;
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Verify rule binding, committee selection, token lifetime, Ed25519 signatures and quorum against the supplied verifier set.
|
|
164
|
+
*
|
|
165
|
+
* @param opts - Decoded token and independently established verifier, rule and time constraints.
|
|
166
|
+
* @returns Fields attested by the verified committee token.
|
|
167
|
+
* @throws If any binding, freshness, signer or quorum check fails.
|
|
168
|
+
*/
|
|
169
|
+
export declare function verifyCompoundToken(opts: VerifyCompoundTokenOptions): VerifiedToken;
|
|
170
|
+
/** One verifier's signature on the wire (hex). */
|
|
171
|
+
export interface CommitteeSignatureWire {
|
|
172
|
+
/** Zero-based verifier registry index. */
|
|
173
|
+
verifier_index: number;
|
|
174
|
+
/** Hexadecimal Ed25519 verifier signature. */
|
|
175
|
+
signature: string;
|
|
176
|
+
}
|
|
177
|
+
/** The compound token JSON a client submits with `/v1/committee/{sign,decrypt}`. */
|
|
178
|
+
export interface CompoundTokenWire {
|
|
179
|
+
/** Compound authorization token category. */
|
|
180
|
+
token_type: TokenType;
|
|
181
|
+
/** Hexadecimal beacon seed. */
|
|
182
|
+
seed: string;
|
|
183
|
+
/** Beacon epoch used for the verifier committee draw. */
|
|
184
|
+
epoch: number;
|
|
185
|
+
/** Hexadecimal 32-byte slot identifier. */
|
|
186
|
+
slot_id: string;
|
|
187
|
+
/** Hexadecimal hash of the credential presentation. */
|
|
188
|
+
vp_hash: string;
|
|
189
|
+
/** Hexadecimal hash of the authenticated holder identifier. */
|
|
190
|
+
holder_hash: string;
|
|
191
|
+
/** `keccak256` of the RAW rule (UNSALTED) - the counterpart of `DualControlPolicy.ruleHash`,
|
|
192
|
+
* never the salted `KeySlot.ruleCommitment`. */
|
|
193
|
+
rule_hash: string;
|
|
194
|
+
/** `0x..` identity binding - present iff the token is identity-scoped. */
|
|
195
|
+
identity_hash?: string;
|
|
196
|
+
/** `0x..` request binding hash - present when minted via the verifier-agent flow. */
|
|
197
|
+
request_hash?: string;
|
|
198
|
+
/** `"unbound"` | `"holder_key"` | `"issuer_asserted"`. */
|
|
199
|
+
binding?: string;
|
|
200
|
+
/** Indices of the selected verifier committee. */
|
|
201
|
+
verifier_indexes: number[];
|
|
202
|
+
/** Issue time in Unix seconds. */
|
|
203
|
+
iat: number;
|
|
204
|
+
/** Expiration time in Unix seconds. */
|
|
205
|
+
exp: number;
|
|
206
|
+
/** Hexadecimal verifier signatures and their registry indices. */
|
|
207
|
+
signatures: CommitteeSignatureWire[];
|
|
208
|
+
/** `0x..` keccak256 of the sealed presentation the quorum evaluated (the
|
|
209
|
+
* ciphertext travels BESIDE the token as `evidence_ct`, never inside it). Present together
|
|
210
|
+
* with `evidence_key_id` and `evidence_signatures`, or not at all. NOT part of the signed
|
|
211
|
+
* canonical bytes — each signer's {@link evidenceBindingMessage} signature binds it. */
|
|
212
|
+
evidence_hash?: string;
|
|
213
|
+
/** `0x..` keccak256 of the accountant evidence key it is sealed to. */
|
|
214
|
+
evidence_key_id?: string;
|
|
215
|
+
/** each signer's ed25519 signature over {@link evidenceBindingMessage}. */
|
|
216
|
+
evidence_signatures?: CommitteeSignatureWire[];
|
|
217
|
+
}
|
|
218
|
+
/** `keccak256(DOMAIN ‖ tokenHash ‖ evidenceHash ‖ evidenceKeyId)` — the message each drawn
|
|
219
|
+
* verifier signs beside its token signature. Byte-identical to the Rust
|
|
220
|
+
* `keykeeper_committee::evidence_binding_message`.
|
|
221
|
+
*
|
|
222
|
+
* @param tokenHash - 32-byte compound-token signing hash.
|
|
223
|
+
* @param evidenceHash - 32-byte keccak256 of the sealed evidence ciphertext.
|
|
224
|
+
* @param evidenceKeyId - 32-byte keccak256 of the accountant evidence key it is sealed to.
|
|
225
|
+
*/
|
|
226
|
+
export declare function evidenceBindingMessage(tokenHash: Uint8Array, evidenceHash: Uint8Array, evidenceKeyId: Uint8Array): Uint8Array;
|
|
227
|
+
/** Inputs to {@link verifyEvidenceBinding}. */
|
|
228
|
+
export interface VerifyEvidenceBindingOptions {
|
|
229
|
+
/** 32-byte compound-token signing hash. */
|
|
230
|
+
tokenHash: Uint8Array;
|
|
231
|
+
/** 32-byte keccak256 of the sealed evidence ciphertext. */
|
|
232
|
+
evidenceHash: Uint8Array;
|
|
233
|
+
/** 32-byte keccak256 of the accountant evidence key it is sealed to. */
|
|
234
|
+
evidenceKeyId: Uint8Array;
|
|
235
|
+
/** Each signer's evidence-binding signature, by verifier index. */
|
|
236
|
+
signatures: CommitteeSignature[];
|
|
237
|
+
/** The anchored verifier set the signer keys are read from. */
|
|
238
|
+
set: VerifierSet;
|
|
239
|
+
/** The drawn committee (the token's `verifier_indexes`). */
|
|
240
|
+
drawn: number[];
|
|
241
|
+
/** How many distinct drawn signers must verify. */
|
|
242
|
+
quorum: number;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Mirror of the Rust `verify_evidence_binding`: every signature must come from a DRAWN
|
|
246
|
+
* verifier in `set` and verify over {@link evidenceBindingMessage}; distinct signers are
|
|
247
|
+
* counted once and must satisfy `quorum` of the drawn committee. Throws on any failure;
|
|
248
|
+
* returns the verified indexes.
|
|
249
|
+
*
|
|
250
|
+
* @param opts - Token and evidence hashes, the signatures, the verifier set, the drawn committee and the quorum.
|
|
251
|
+
*/
|
|
252
|
+
export declare function verifyEvidenceBinding(opts: VerifyEvidenceBindingOptions): number[];
|
|
253
|
+
/** Assemble the wire compound token from a payload + the gathered quorum signatures. */
|
|
254
|
+
/** binding strengths: `0x00` Unbound, `0x01` HolderKey (KB-JWT / holder proof verified), `0x02` IssuerAsserted. */
|
|
255
|
+
export declare const BINDING_UNBOUND = 0;
|
|
256
|
+
export declare const BINDING_HOLDER_KEY = 1;
|
|
257
|
+
export declare const BINDING_ISSUER_ASSERTED = 2;
|
|
258
|
+
export declare function bindingToWire(b: number | undefined): string | undefined;
|
|
259
|
+
export declare function bindingFromWire(s: string | undefined): number;
|
|
260
|
+
/**
|
|
261
|
+
* Encode a token payload and verifier signatures into the keeper JSON wire format. This does not verify signatures.
|
|
262
|
+
*
|
|
263
|
+
* @param p - Compound token payload, excluding signatures.
|
|
264
|
+
* @param signatures - Verifier signatures to include in the wire object.
|
|
265
|
+
*/
|
|
266
|
+
export declare function assembleCompoundToken(p: CompoundTokenPayload, signatures: CommitteeSignature[]): CompoundTokenWire;
|
|
267
|
+
/**
|
|
268
|
+
* Decode a wire compound token into the byte-level payload + signatures for verification.
|
|
269
|
+
*
|
|
270
|
+
* @param w - Keeper JSON token representation to decode into byte fields.
|
|
271
|
+
*/
|
|
272
|
+
export declare function decodeCompoundToken(w: CompoundTokenWire): CompoundTokenPayload & {
|
|
273
|
+
signatures: CommitteeSignature[];
|
|
274
|
+
};
|