@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,284 @@
|
|
|
1
|
+
import { TasraHttpError } from '../errors.js';
|
|
2
|
+
import { type CompoundTokenWire, type TokenType } from './token.js';
|
|
3
|
+
import type { Ciphertext } from '../crypto/kem.js';
|
|
4
|
+
import type { FrostSignResult } from '../signing/frost.js';
|
|
5
|
+
import type { BlsPeer } from '../decryption/client.js';
|
|
6
|
+
import { type OperationReceipt } from './receipts.js';
|
|
7
|
+
/** Trustless verifier-set inclusion proof, passed to the keeper. */
|
|
8
|
+
export interface VerifierProof {
|
|
9
|
+
/** Zero-based verifier registry index. */
|
|
10
|
+
verifierIndex: number;
|
|
11
|
+
/** 20-byte operator address (hex). */
|
|
12
|
+
operator: string;
|
|
13
|
+
/** 32-byte ed25519 pubkey (hex). */
|
|
14
|
+
pubkey: string;
|
|
15
|
+
/** Sorted-pair keccak Merkle proof (each 32-byte hex). */
|
|
16
|
+
proof: string[];
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* A verifier refused to co-sign a committee token. Extends
|
|
20
|
+
* {@link TasraHttpError}, so `.status`, `.url`, `.body`, and `.retryable` are
|
|
21
|
+
* all available and `isAuthDenied()` recognises a 401/403 here too.
|
|
22
|
+
*
|
|
23
|
+
* Distinct from a generic HTTP error because the committee flow polls several
|
|
24
|
+
* verifiers and tolerates individual refusals as long as a quorum co-signs - see
|
|
25
|
+
* {@link ThresholdNotMetError} for the failure that means the quorum was missed.
|
|
26
|
+
*/
|
|
27
|
+
export declare class CommitteeAuthorizeError extends TasraHttpError {
|
|
28
|
+
constructor(status: number, message: string, opts?: {
|
|
29
|
+
url?: string;
|
|
30
|
+
body?: string;
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
/** Credential presentation and request context sent to one verifier for committee authorization. */
|
|
34
|
+
export interface CommitteeAuthorizeBody {
|
|
35
|
+
/** Holder DID (the credentials' subject). */
|
|
36
|
+
holder: string;
|
|
37
|
+
/** Compact-JWS verifiable credentials. */
|
|
38
|
+
credentials: string[];
|
|
39
|
+
/** F1/F4: holder proof-of-possession. Build via `createHolderProof`
|
|
40
|
+
* (bind it to `slotId`). Empty string means omitted from the wire, which only a
|
|
41
|
+
* verifier with `require_holder_binding = false` accepts. */
|
|
42
|
+
holderProof: string;
|
|
43
|
+
/** Compound authorization token category. */
|
|
44
|
+
tokenType: TokenType;
|
|
45
|
+
/** 32-byte on-chain beacon seed. */
|
|
46
|
+
seed: Uint8Array;
|
|
47
|
+
/** Beacon epoch used for the verifier committee draw. */
|
|
48
|
+
epoch: number | bigint;
|
|
49
|
+
/** 32-byte slot id. */
|
|
50
|
+
slotId: Uint8Array;
|
|
51
|
+
/** Active verifier-set size at `epoch`. */
|
|
52
|
+
registrySize: number;
|
|
53
|
+
/** The slot's verifierPolicy committee size. */
|
|
54
|
+
committee: number;
|
|
55
|
+
/** Issue time in Unix seconds. */
|
|
56
|
+
iat: number | bigint;
|
|
57
|
+
/** Expiration time in Unix seconds. */
|
|
58
|
+
exp: number | bigint;
|
|
59
|
+
/**
|
|
60
|
+
* The requested IBE identity, present **iff** the operation is
|
|
61
|
+
* identity-scoped. The committee evaluates the slot's scope binding against it and
|
|
62
|
+
* folds `keccak256(identity)` into the signed token - a quorum attests THIS identity
|
|
63
|
+
* and the token is unusable for any other. Omit for every other operation.
|
|
64
|
+
*/
|
|
65
|
+
identity?: string;
|
|
66
|
+
/**
|
|
67
|
+
* request binding: the preimage every drawn verifier re-derives `request_hash`
|
|
68
|
+
* and the KB-JWT nonce from. Send it whenever the keeper runs `require_request_binding`
|
|
69
|
+
* (production posture): the reply then carries `request_hash` + `binding`, which the
|
|
70
|
+
* gathered token must include or the keeper refuses it. Absent = legacy (unbound) path.
|
|
71
|
+
*/
|
|
72
|
+
binding?: RequestBindingPreimage;
|
|
73
|
+
}
|
|
74
|
+
/** The six fields the Verifier Agent fans out (`FanoutRequest`); `random` is the per-request nonce salt. */
|
|
75
|
+
export interface RequestBindingPreimage {
|
|
76
|
+
chainId: number | bigint;
|
|
77
|
+
action: 'sign' | 'decrypt' | 'ibe-extract' | 'dual-approve';
|
|
78
|
+
/** 32 bytes - the per-action digest (`payloadDigestFor`). */
|
|
79
|
+
payloadDigest: Uint8Array;
|
|
80
|
+
/** 32 random bytes; the KB-JWT nonce derives from (request_hash, random). */
|
|
81
|
+
random: Uint8Array;
|
|
82
|
+
/** The JAR `client_id` the KB-JWT's `aud` must equal. */
|
|
83
|
+
clientId: string;
|
|
84
|
+
description?: string;
|
|
85
|
+
}
|
|
86
|
+
/** Verifier signature, token hashes and committee metadata for an authorization request. */
|
|
87
|
+
export interface CommitteeAuthorizeReply {
|
|
88
|
+
/** Zero-based verifier registry index. */
|
|
89
|
+
verifierIndex: number;
|
|
90
|
+
/** 32-byte compound token hash. */
|
|
91
|
+
tokenHash: Uint8Array;
|
|
92
|
+
/** Hash of the credential presentation bound into the token. */
|
|
93
|
+
vpHash: Uint8Array;
|
|
94
|
+
/** `keccak256` of the holder this verifier authenticated - inside the signed bytes. */
|
|
95
|
+
holderHash: Uint8Array;
|
|
96
|
+
/** `keccak256` of the RAW rule this verifier evaluated (UNSALTED) - what the keeper
|
|
97
|
+
* binds against its own `keccak256(rule)`. */
|
|
98
|
+
ruleHash: Uint8Array;
|
|
99
|
+
/** the identity binding this verifier signed - present iff the request
|
|
100
|
+
* carried `identity`. Inside the signed bytes, like `holderHash`. */
|
|
101
|
+
identityHash?: Uint8Array;
|
|
102
|
+
/** This verifier's signature over the compound token hash. */
|
|
103
|
+
signature: Uint8Array;
|
|
104
|
+
/** The full ordered committee draw, so the caller knows whom else to ask. */
|
|
105
|
+
committeeIndexes: number[];
|
|
106
|
+
/**
|
|
107
|
+
* The slot's `ruleVersion` this authorization was evaluated against.
|
|
108
|
+
*
|
|
109
|
+
* Diagnostic, not a gate. The keeper binds `ruleHash` to its own rule hash,
|
|
110
|
+
* so a token minted under a superseded policy is refused there
|
|
111
|
+
* whatever this says. Its value is that it explains the refusal: without it, a
|
|
112
|
+
* token minted moments before an amendment activates is rejected with nothing
|
|
113
|
+
* to distinguish it from a genuinely unauthorized request.
|
|
114
|
+
*
|
|
115
|
+
* `undefined` from a verifier that predates rule versioning.
|
|
116
|
+
*/
|
|
117
|
+
ruleVersion?: number;
|
|
118
|
+
/** present when the request carried a binding preimage; inside the signed bytes. */
|
|
119
|
+
requestHash?: Uint8Array;
|
|
120
|
+
/** binding strength byte (`bindingFromWire`); `0x00` when the verifier declared none. */
|
|
121
|
+
binding: number;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Ask one verifier to authorize the request. Throws CommitteeAuthorizeError
|
|
125
|
+
* (with `.status`) on a non-2xx - notably 403 when this verifier wasn't drawn.
|
|
126
|
+
*
|
|
127
|
+
* @param verifierUrl - Verifier HTTP base URL.
|
|
128
|
+
* @param body - Credential presentation and operation context for this verifier.
|
|
129
|
+
*/
|
|
130
|
+
export declare function committeeAuthorize(verifierUrl: string, body: CommitteeAuthorizeBody): Promise<CommitteeAuthorizeReply>;
|
|
131
|
+
/** Verifier requests and quorum configuration for assembling a compound token. */
|
|
132
|
+
export interface GatherCommitteeTokenOpts {
|
|
133
|
+
/** Candidate verifiers to ask (index to base URL). Asking the whole registry is
|
|
134
|
+
* fine - non-drawn verifiers reply 403 and are skipped. */
|
|
135
|
+
verifiers: Array<{
|
|
136
|
+
index: number;
|
|
137
|
+
url: string;
|
|
138
|
+
}>;
|
|
139
|
+
/** Authorization input shared across requests to the selected verifiers. */
|
|
140
|
+
authorize: CommitteeAuthorizeBody;
|
|
141
|
+
/** The slot's verifierPolicy quorum (minimum distinct committee signatures). */
|
|
142
|
+
quorum: number;
|
|
143
|
+
/** Observe all replies and the reply used as the token payload reference. Useful when verifiers report different policy versions. */
|
|
144
|
+
onReplies?: (all: CommitteeAuthorizeReply[], reference: CommitteeAuthorizeReply) => void;
|
|
145
|
+
/** Mint a separate holder proof for each verifier, overriding authorize.holderProof. Called concurrently; a rejection excludes that verifier while other requests continue. */
|
|
146
|
+
holderProofFor?: (verifier: {
|
|
147
|
+
index: number;
|
|
148
|
+
url: string;
|
|
149
|
+
}) => Promise<string> | string;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Fan out to the candidate verifiers, collect signatures from the drawn committee
|
|
153
|
+
* until quorum, and assemble the compound token. Verifies that our locally
|
|
154
|
+
* recomputed canonical token hash equals the hash the verifiers signed (a built-in
|
|
155
|
+
* encoding cross-check). Returns the wire token to POST to the keeper.
|
|
156
|
+
*
|
|
157
|
+
* @param opts - Verifier requests, committee draw and required signature quorum.
|
|
158
|
+
*/
|
|
159
|
+
export declare function gatherCommitteeToken(opts: GatherCommitteeTokenOpts): Promise<CompoundTokenWire>;
|
|
160
|
+
/** Committee-authorized FROST signing request and optional verifier membership proofs. */
|
|
161
|
+
export interface CommitteeSignOpts {
|
|
162
|
+
/** Optional signal that cancels the request. */
|
|
163
|
+
signal?: AbortSignal;
|
|
164
|
+
/** HTTP transport override; defaults to the global fetch implementation. */
|
|
165
|
+
fetchImpl?: typeof fetch;
|
|
166
|
+
/** Keeper HTTP base URL. */
|
|
167
|
+
nodeUrl: string;
|
|
168
|
+
/** Compound token authorizing this operation. */
|
|
169
|
+
committeeToken: CompoundTokenWire;
|
|
170
|
+
/** Raw message bytes to sign. */
|
|
171
|
+
message: Uint8Array;
|
|
172
|
+
/** Optional threshold participant identifiers for the signing ceremony. */
|
|
173
|
+
signingSet?: number[];
|
|
174
|
+
/** Optional Ed25519 owner signature over the canonical operation request. */
|
|
175
|
+
userSignature?: Uint8Array;
|
|
176
|
+
/** Optional 20-byte operator address to pin the intended keeper. */
|
|
177
|
+
targetKeykeeper?: string;
|
|
178
|
+
/** Verifier membership proofs for the selected snapshot. */
|
|
179
|
+
verifierProofs?: VerifierProof[];
|
|
180
|
+
/** 32-byte Ed25519 client public key used to verify clientSignature over the slot and token hash; supply both fields together. */
|
|
181
|
+
clientPubkey?: Uint8Array;
|
|
182
|
+
/** Client signature over the slot and compound token binding. */
|
|
183
|
+
clientSignature?: Uint8Array;
|
|
184
|
+
/** the sealed presentation beside the token (`VerifierAgentResult.evidenceCt`),
|
|
185
|
+
* posted as `evidence_ct`. Required by a keeper with `require_committee_evidence`. */
|
|
186
|
+
evidenceCt?: string;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Sign via committee authorization. The slot id is taken from the token.
|
|
190
|
+
*
|
|
191
|
+
* @param opts - Keeper endpoint, compound authorization and message to sign.
|
|
192
|
+
*/
|
|
193
|
+
export declare function committeeSign(opts: CommitteeSignOpts): Promise<FrostSignResult>;
|
|
194
|
+
/** Committee-authorized group decryption request and optional verifier membership proofs. */
|
|
195
|
+
export interface CommitteeDecryptOpts {
|
|
196
|
+
/** Keeper HTTP base URL. */
|
|
197
|
+
nodeUrl: string;
|
|
198
|
+
/** Compound token authorizing this operation. */
|
|
199
|
+
committeeToken: CompoundTokenWire;
|
|
200
|
+
/** Ciphertext to decrypt. */
|
|
201
|
+
ciphertext: Ciphertext;
|
|
202
|
+
/** Original encryption associated data. */
|
|
203
|
+
identity: Uint8Array;
|
|
204
|
+
/** Threshold participant identifiers for the decryption ceremony. */
|
|
205
|
+
decryptingSet: number[];
|
|
206
|
+
/** Peer identifiers for the selected BLS participants. */
|
|
207
|
+
blsPeers: BlsPeer[];
|
|
208
|
+
/** Optional Ed25519 owner signature over the canonical operation request. */
|
|
209
|
+
userSignature?: Uint8Array;
|
|
210
|
+
/** Expected key epoch of the ciphertext; used to detect rotation. */
|
|
211
|
+
ciphertextEpoch?: number;
|
|
212
|
+
/** Optional 20-byte operator address to pin the intended keeper. */
|
|
213
|
+
targetKeykeeper?: string;
|
|
214
|
+
/** Verifier membership proofs for the selected snapshot. */
|
|
215
|
+
verifierProofs?: VerifierProof[];
|
|
216
|
+
/** 32-byte Ed25519 client public key used to verify clientSignature; supply both fields together. */
|
|
217
|
+
clientPubkey?: Uint8Array;
|
|
218
|
+
/** Client signature over the slot and compound token binding. */
|
|
219
|
+
clientSignature?: Uint8Array;
|
|
220
|
+
/** the sealed presentation beside the token (`VerifierAgentResult.evidenceCt`),
|
|
221
|
+
* posted as `evidence_ct`. Required by a keeper with `require_committee_evidence`. */
|
|
222
|
+
evidenceCt?: string;
|
|
223
|
+
/** HTTP transport override; defaults to the global fetch implementation. */
|
|
224
|
+
fetchImpl?: typeof fetch;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Decrypt via committee authorization. The slot id is taken from the token.
|
|
228
|
+
*
|
|
229
|
+
* @param opts - Keeper endpoint, compound authorization, ciphertext and associated data.
|
|
230
|
+
*/
|
|
231
|
+
export declare function committeeDecrypt(opts: CommitteeDecryptOpts): Promise<Uint8Array>;
|
|
232
|
+
/** One node's extraction partial, decoded from the wire. */
|
|
233
|
+
export interface IbeExtractionPartial {
|
|
234
|
+
/** Echoed slot, when supplied by the server. Required by the strict helper. */
|
|
235
|
+
keySlotId?: string;
|
|
236
|
+
/** Optional keeper attestation; presence alone does not establish validity. */
|
|
237
|
+
receipt?: OperationReceipt;
|
|
238
|
+
/** The node's BLS group identifier (1..n). */
|
|
239
|
+
identifier: number;
|
|
240
|
+
/** 48-byte compressed G1 partial `D_i = sk_i * Q_ID`. */
|
|
241
|
+
value: Uint8Array;
|
|
242
|
+
/** The node's 96-byte G2 verifying share (the dual-group reply's first half). */
|
|
243
|
+
verifyingShareG2: Uint8Array;
|
|
244
|
+
/** Slot epoch when served. */
|
|
245
|
+
epoch: number;
|
|
246
|
+
/** The node that served it (for identifiable-abort reporting). */
|
|
247
|
+
nodeUrl: string;
|
|
248
|
+
}
|
|
249
|
+
/** Committee authorization and keeper endpoints for extracting shares of one IBE identity key. */
|
|
250
|
+
export interface IbeExtractOpts {
|
|
251
|
+
/** Optional signal that cancels the request. */
|
|
252
|
+
signal?: AbortSignal;
|
|
253
|
+
/** HTTP transport override; defaults to the global fetch implementation. */
|
|
254
|
+
fetchImpl?: typeof fetch;
|
|
255
|
+
/** Base URLs of at least k keeper nodes holding the slot's BLS shards. */
|
|
256
|
+
nodeUrls: string[];
|
|
257
|
+
/** MUST be identity-scoped: the keeper enforces `identity_hash == keccak256(identity)`. */
|
|
258
|
+
committeeToken: CompoundTokenWire;
|
|
259
|
+
/** The requested IBE identity, in the clear (the node computes Q_ID from it). */
|
|
260
|
+
identity: string;
|
|
261
|
+
/** Owner signature over `keccak256("keykeeper:ibe-extract:v1" || identity)` when the
|
|
262
|
+
* slot has a registered `user_pubkey`. */
|
|
263
|
+
userSignature?: Uint8Array;
|
|
264
|
+
/** Expected key epoch of the ciphertext; used to detect rotation. */
|
|
265
|
+
ciphertextEpoch?: number;
|
|
266
|
+
/** Verifier membership proofs for the selected snapshot. */
|
|
267
|
+
verifierProofs?: VerifierProof[];
|
|
268
|
+
/** 32-byte Ed25519 client public key used to verify clientSignature; supply both fields together. */
|
|
269
|
+
clientPubkey?: Uint8Array;
|
|
270
|
+
/** Client signature over the slot and compound token binding. */
|
|
271
|
+
clientSignature?: Uint8Array;
|
|
272
|
+
/** the sealed presentation beside the token (`VerifierAgentResult.evidenceCt`),
|
|
273
|
+
* posted as `evidence_ct`. Required by a keeper with `require_committee_evidence`. */
|
|
274
|
+
evidenceCt?: string;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Fan out to the keeper nodes and collect extraction partials. Nodes that refuse or are
|
|
278
|
+
* down are skipped; throws - naming every node and its reason - only when NONE served.
|
|
279
|
+
* The caller combines with `ibeCombineDecrypt`/`ibeCombineExtract`, which pairing-verify
|
|
280
|
+
* each partial (identifiable abort names the node via the identifier).
|
|
281
|
+
*
|
|
282
|
+
* @param opts - Compound token, identity, keepers and optional expected epoch.
|
|
283
|
+
*/
|
|
284
|
+
export declare function requestIbeExtractionPartials(opts: IbeExtractOpts): Promise<IbeExtractionPartial[]>;
|
|
@@ -0,0 +1,351 @@
|
|
|
1
|
+
// Committee-mode HTTP orchestration - the glue around the pure token
|
|
2
|
+
// crypto in ./committee.ts. Three pieces:
|
|
3
|
+
// - committeeAuthorize() - POST a VP to ONE verifier's /v1/committee-authorize,
|
|
4
|
+
// which (if that verifier is in the per-request draw) returns its ed25519
|
|
5
|
+
// signature over the canonical token hash.
|
|
6
|
+
// - gatherCommitteeToken() - fan out to the candidate verifiers, collect a
|
|
7
|
+
// quorum of signatures, and assemble the compound token. Self-checks that our
|
|
8
|
+
// canonical hash equals the hash the verifiers signed.
|
|
9
|
+
// - committeeSign() / committeeDecrypt() - POST the assembled token (in the
|
|
10
|
+
// BODY, no auth header) to the keeper's /v1/committee/{sign,decrypt}.
|
|
11
|
+
import { hexToBytes, bytesToHex } from '../crypto/hex.js';
|
|
12
|
+
import { httpError, TasraHttpError, ThresholdNotMetError } from '../errors.js';
|
|
13
|
+
import { bytesToHex as bareHex } from '@noble/hashes/utils';
|
|
14
|
+
import { assembleCompoundToken, compoundTokenHash, bindingFromWire } from './token.js';
|
|
15
|
+
import { base64Encode, base64Decode } from '../crypto/envelope.js';
|
|
16
|
+
import { decodeOperationReceipt } from './receipts.js';
|
|
17
|
+
const strip0x = (s) => (s.startsWith('0x') ? s.slice(2) : s);
|
|
18
|
+
const base = (u) => u.replace(/\/$/, '');
|
|
19
|
+
function bytesEqual(a, b) {
|
|
20
|
+
return a.length === b.length && a.every((x, i) => x === b[i]);
|
|
21
|
+
}
|
|
22
|
+
function ctToWire(ct) {
|
|
23
|
+
return { u: base64Encode(ct.u), nonce: base64Encode(ct.nonce), aead_ct: base64Encode(ct.aeadCt) };
|
|
24
|
+
}
|
|
25
|
+
function proofsToWire(proofs) {
|
|
26
|
+
return proofs.map(p => ({
|
|
27
|
+
verifier_index: p.verifierIndex,
|
|
28
|
+
operator: strip0x(p.operator),
|
|
29
|
+
pubkey: strip0x(p.pubkey),
|
|
30
|
+
proof: p.proof.map(strip0x),
|
|
31
|
+
}));
|
|
32
|
+
}
|
|
33
|
+
// verifier: POST /v1/committee-authorize
|
|
34
|
+
/**
|
|
35
|
+
* A verifier refused to co-sign a committee token. Extends
|
|
36
|
+
* {@link TasraHttpError}, so `.status`, `.url`, `.body`, and `.retryable` are
|
|
37
|
+
* all available and `isAuthDenied()` recognises a 401/403 here too.
|
|
38
|
+
*
|
|
39
|
+
* Distinct from a generic HTTP error because the committee flow polls several
|
|
40
|
+
* verifiers and tolerates individual refusals as long as a quorum co-signs - see
|
|
41
|
+
* {@link ThresholdNotMetError} for the failure that means the quorum was missed.
|
|
42
|
+
*/
|
|
43
|
+
export class CommitteeAuthorizeError extends TasraHttpError {
|
|
44
|
+
constructor(status, message, opts) {
|
|
45
|
+
super({ status, url: opts?.url ?? '', body: opts?.body, message });
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function authorizeWire(b) {
|
|
49
|
+
return {
|
|
50
|
+
holder: b.holder,
|
|
51
|
+
credentials: b.credentials,
|
|
52
|
+
// Omit rather than send "": the server field is an Option, and an empty
|
|
53
|
+
// string is a value that fails parsing rather than an absent proof.
|
|
54
|
+
...(b.holderProof ? { holder_proof: b.holderProof } : {}),
|
|
55
|
+
token_type: b.tokenType,
|
|
56
|
+
seed: bytesToHex(b.seed),
|
|
57
|
+
epoch: Number(b.epoch),
|
|
58
|
+
slot_id: bytesToHex(b.slotId),
|
|
59
|
+
registry_size: b.registrySize,
|
|
60
|
+
committee: b.committee,
|
|
61
|
+
iat: Number(b.iat),
|
|
62
|
+
exp: Number(b.exp),
|
|
63
|
+
...(b.identity !== undefined ? { identity: b.identity } : {}),
|
|
64
|
+
...(b.binding
|
|
65
|
+
? {
|
|
66
|
+
chain_id: Number(b.binding.chainId),
|
|
67
|
+
action: b.binding.action,
|
|
68
|
+
payload_digest: bytesToHex(b.binding.payloadDigest),
|
|
69
|
+
random: bytesToHex(b.binding.random),
|
|
70
|
+
client_id: b.binding.clientId,
|
|
71
|
+
...(b.binding.description !== undefined ? { description: b.binding.description } : {}),
|
|
72
|
+
}
|
|
73
|
+
: {}),
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Ask one verifier to authorize the request. Throws CommitteeAuthorizeError
|
|
78
|
+
* (with `.status`) on a non-2xx - notably 403 when this verifier wasn't drawn.
|
|
79
|
+
*
|
|
80
|
+
* @param verifierUrl - Verifier HTTP base URL.
|
|
81
|
+
* @param body - Credential presentation and operation context for this verifier.
|
|
82
|
+
*/
|
|
83
|
+
export async function committeeAuthorize(verifierUrl, body) {
|
|
84
|
+
// A SECOND copy of this guard used to live here as well as in
|
|
85
|
+
// `requestCommitteeToken`, and relaxing only the outer one left the inner one
|
|
86
|
+
// refusing every request - the duplicated policy is why. The rule belongs at
|
|
87
|
+
// ONE layer: the caller decides (and states it), this function transmits.
|
|
88
|
+
//
|
|
89
|
+
// The server field is an `Option` and a verifier with
|
|
90
|
+
// `require_holder_binding = false` accepts the request without a proof, so a
|
|
91
|
+
// hard refusal here makes a valid deployment unreachable.
|
|
92
|
+
if (body.holderProof === undefined) {
|
|
93
|
+
throw new Error('committeeAuthorize: holderProof must be a string (pass "" only when the verifier runs ' +
|
|
94
|
+
'require_holder_binding = false)');
|
|
95
|
+
}
|
|
96
|
+
const url = `${base(verifierUrl)}/v1/committee-authorize`;
|
|
97
|
+
const res = await fetch(url, {
|
|
98
|
+
method: 'POST',
|
|
99
|
+
headers: { 'Content-Type': 'application/json' },
|
|
100
|
+
body: JSON.stringify(authorizeWire(body)),
|
|
101
|
+
});
|
|
102
|
+
if (!res.ok) {
|
|
103
|
+
const detail = (await res.text().catch(() => '')).slice(0, 200);
|
|
104
|
+
throw new CommitteeAuthorizeError(res.status, `committee-authorize → HTTP ${res.status}${detail ? `: ${detail}` : ''}`, { url, body: detail });
|
|
105
|
+
}
|
|
106
|
+
const d = (await res.json());
|
|
107
|
+
return {
|
|
108
|
+
verifierIndex: Number(d.verifier_index),
|
|
109
|
+
tokenHash: hexToBytes(d.token_hash),
|
|
110
|
+
vpHash: hexToBytes(d.vp_hash),
|
|
111
|
+
holderHash: hexToBytes(d.holder_hash),
|
|
112
|
+
ruleHash: hexToBytes(d.rule_hash),
|
|
113
|
+
...(typeof d.identity_hash === 'string' ? { identityHash: hexToBytes(d.identity_hash) } : {}),
|
|
114
|
+
...(typeof d.request_hash === 'string' ? { requestHash: hexToBytes(d.request_hash) } : {}),
|
|
115
|
+
binding: bindingFromWire(d.binding),
|
|
116
|
+
signature: hexToBytes(d.signature),
|
|
117
|
+
committeeIndexes: d.committee_indexes,
|
|
118
|
+
ruleVersion: typeof d.rule_version === 'number' ? d.rule_version : undefined,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Fan out to the candidate verifiers, collect signatures from the drawn committee
|
|
123
|
+
* until quorum, and assemble the compound token. Verifies that our locally
|
|
124
|
+
* recomputed canonical token hash equals the hash the verifiers signed (a built-in
|
|
125
|
+
* encoding cross-check). Returns the wire token to POST to the keeper.
|
|
126
|
+
*
|
|
127
|
+
* @param opts - Verifier requests, committee draw and required signature quorum.
|
|
128
|
+
*/
|
|
129
|
+
export async function gatherCommitteeToken(opts) {
|
|
130
|
+
const settled = await Promise.allSettled(opts.verifiers.map(async (v) => {
|
|
131
|
+
const body = opts.holderProofFor
|
|
132
|
+
? { ...opts.authorize, holderProof: await opts.holderProofFor(v) }
|
|
133
|
+
: opts.authorize;
|
|
134
|
+
return committeeAuthorize(v.url, body);
|
|
135
|
+
}));
|
|
136
|
+
const replies = settled
|
|
137
|
+
.filter((r) => r.status === 'fulfilled')
|
|
138
|
+
.map(r => r.value);
|
|
139
|
+
if (replies.length === 0) {
|
|
140
|
+
// Report WHY. "no verifier authorized the request" with the reasons
|
|
141
|
+
// discarded is the least actionable error this library can produce: every
|
|
142
|
+
// cause - a stale credential, an undrawn verifier, a seed/epoch mismatch,
|
|
143
|
+
// a verifier that is simply down - looks identical, and each has a
|
|
144
|
+
// completely different fix.
|
|
145
|
+
const why = settled
|
|
146
|
+
.map((r, i) => {
|
|
147
|
+
const who = opts.verifiers[i]?.url ?? `#${i}`;
|
|
148
|
+
if (r.status === 'fulfilled')
|
|
149
|
+
return null;
|
|
150
|
+
const e = r.reason;
|
|
151
|
+
return `${who}: ${e?.status ? `HTTP ${e.status} ` : ''}${e?.message ?? String(r.reason)}`;
|
|
152
|
+
})
|
|
153
|
+
.filter(Boolean)
|
|
154
|
+
.join('; ');
|
|
155
|
+
throw new Error(`gatherCommitteeToken: no verifier authorized the request — ${why}`);
|
|
156
|
+
}
|
|
157
|
+
const ref = replies[0];
|
|
158
|
+
opts.onReplies?.(replies, ref);
|
|
159
|
+
const committeeIndexes = ref.committeeIndexes;
|
|
160
|
+
const inCommittee = new Set(committeeIndexes);
|
|
161
|
+
// distinct signatures from drawn committee members
|
|
162
|
+
const sigByIndex = new Map();
|
|
163
|
+
for (const r of replies) {
|
|
164
|
+
if (inCommittee.has(r.verifierIndex)) {
|
|
165
|
+
sigByIndex.set(r.verifierIndex, { verifierIndex: r.verifierIndex, signature: r.signature });
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (sigByIndex.size < opts.quorum) {
|
|
169
|
+
// Typed, because this is exactly the failure `CommitteeAuthorizeError`'s doc points a caller at:
|
|
170
|
+
// individual refusals are tolerated, a missed quorum is not. Retryable - a verifier that was slow
|
|
171
|
+
// or restarting answers the next attempt, and the drawn committee is redrawn per request.
|
|
172
|
+
throw new ThresholdNotMetError({
|
|
173
|
+
got: sigByIndex.size,
|
|
174
|
+
need: opts.quorum,
|
|
175
|
+
reasons: replies
|
|
176
|
+
.filter(r => !inCommittee.has(r.verifierIndex))
|
|
177
|
+
.map(r => `verifier #${r.verifierIndex} answered but was not in the drawn committee`),
|
|
178
|
+
message: `gatherCommitteeToken: quorum not met (${sigByIndex.size}/${opts.quorum} from the drawn committee)`,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
const payload = {
|
|
182
|
+
tokenType: opts.authorize.tokenType,
|
|
183
|
+
seed: opts.authorize.seed,
|
|
184
|
+
epoch: opts.authorize.epoch,
|
|
185
|
+
slotId: opts.authorize.slotId,
|
|
186
|
+
vpHash: ref.vpHash,
|
|
187
|
+
holderHash: ref.holderHash,
|
|
188
|
+
ruleHash: ref.ruleHash,
|
|
189
|
+
// From the reference reply, like ruleHash - the hash cross-check below
|
|
190
|
+
// then proves the whole committee signed over the SAME identity binding.
|
|
191
|
+
...(ref.identityHash !== undefined ? { identityHash: ref.identityHash } : {}),
|
|
192
|
+
// The binding the reference verifier declared; the hash cross-check below proves
|
|
193
|
+
// every signer signed the SAME request_hash + binding byte.
|
|
194
|
+
...(ref.requestHash !== undefined ? { requestHash: ref.requestHash } : {}),
|
|
195
|
+
binding: ref.binding,
|
|
196
|
+
verifierIndexes: committeeIndexes,
|
|
197
|
+
iat: opts.authorize.iat,
|
|
198
|
+
exp: opts.authorize.exp,
|
|
199
|
+
};
|
|
200
|
+
if (!bytesEqual(compoundTokenHash(payload), ref.tokenHash)) {
|
|
201
|
+
throw new Error('gatherCommitteeToken: canonical token hash disagrees with the verifier (encoding mismatch)');
|
|
202
|
+
}
|
|
203
|
+
return assembleCompoundToken(payload, [...sigByIndex.values()]);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Sign via committee authorization. The slot id is taken from the token.
|
|
207
|
+
*
|
|
208
|
+
* @param opts - Keeper endpoint, compound authorization and message to sign.
|
|
209
|
+
*/
|
|
210
|
+
export async function committeeSign(opts) {
|
|
211
|
+
const body = {
|
|
212
|
+
committee_token: opts.committeeToken,
|
|
213
|
+
...(opts.evidenceCt !== undefined ? { evidence_ct: opts.evidenceCt } : {}),
|
|
214
|
+
message_hex: bareHex(opts.message),
|
|
215
|
+
};
|
|
216
|
+
if (opts.signingSet)
|
|
217
|
+
body.signing_set = opts.signingSet;
|
|
218
|
+
if (opts.userSignature)
|
|
219
|
+
body.user_signature = bareHex(opts.userSignature);
|
|
220
|
+
if (opts.targetKeykeeper)
|
|
221
|
+
body.target_keykeeper = strip0x(opts.targetKeykeeper);
|
|
222
|
+
if (opts.verifierProofs)
|
|
223
|
+
body.verifier_proofs = proofsToWire(opts.verifierProofs);
|
|
224
|
+
if (opts.clientPubkey && opts.clientSignature) {
|
|
225
|
+
body.client_pubkey = bareHex(opts.clientPubkey);
|
|
226
|
+
body.client_signature = bareHex(opts.clientSignature);
|
|
227
|
+
}
|
|
228
|
+
const url = `${base(opts.nodeUrl)}/v1/committee/sign`;
|
|
229
|
+
const res = await (opts.fetchImpl ?? fetch)(url, {
|
|
230
|
+
method: 'POST',
|
|
231
|
+
headers: { 'Content-Type': 'application/json' },
|
|
232
|
+
body: JSON.stringify(body),
|
|
233
|
+
signal: opts.signal,
|
|
234
|
+
});
|
|
235
|
+
if (!res.ok)
|
|
236
|
+
throw await httpError(res, url, 'committee/sign');
|
|
237
|
+
const d = (await res.json());
|
|
238
|
+
return {
|
|
239
|
+
...(decodeOperationReceipt(d) ? { receipt: decodeOperationReceipt(d) } : {}),
|
|
240
|
+
keySlotId: d.key_slot_id,
|
|
241
|
+
groupPublicKey: hexToBytes(d.group_public_key),
|
|
242
|
+
signature: { r: hexToBytes(d.signature_r), z: hexToBytes(d.signature_z) },
|
|
243
|
+
messageSha256: hexToBytes(d.message_sha256),
|
|
244
|
+
epoch: Number(d.epoch ?? 0),
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Decrypt via committee authorization. The slot id is taken from the token.
|
|
249
|
+
*
|
|
250
|
+
* @param opts - Keeper endpoint, compound authorization, ciphertext and associated data.
|
|
251
|
+
*/
|
|
252
|
+
export async function committeeDecrypt(opts) {
|
|
253
|
+
const body = {
|
|
254
|
+
committee_token: opts.committeeToken,
|
|
255
|
+
...(opts.evidenceCt !== undefined ? { evidence_ct: opts.evidenceCt } : {}),
|
|
256
|
+
ciphertext: ctToWire(opts.ciphertext),
|
|
257
|
+
identity: new TextDecoder().decode(opts.identity),
|
|
258
|
+
decrypting_set: opts.decryptingSet,
|
|
259
|
+
bls_peers: opts.blsPeers.map(p => ({ id: p.id, peer_id: p.peerId })),
|
|
260
|
+
};
|
|
261
|
+
if (opts.userSignature)
|
|
262
|
+
body.user_signature = bareHex(opts.userSignature);
|
|
263
|
+
if (opts.ciphertextEpoch !== undefined)
|
|
264
|
+
body.ciphertext_epoch = opts.ciphertextEpoch;
|
|
265
|
+
if (opts.targetKeykeeper)
|
|
266
|
+
body.target_keykeeper = strip0x(opts.targetKeykeeper);
|
|
267
|
+
if (opts.verifierProofs)
|
|
268
|
+
body.verifier_proofs = proofsToWire(opts.verifierProofs);
|
|
269
|
+
if (opts.clientPubkey && opts.clientSignature) {
|
|
270
|
+
body.client_pubkey = bareHex(opts.clientPubkey);
|
|
271
|
+
body.client_signature = bareHex(opts.clientSignature);
|
|
272
|
+
}
|
|
273
|
+
const url = `${base(opts.nodeUrl)}/v1/committee/decrypt`;
|
|
274
|
+
const res = await (opts.fetchImpl ?? fetch)(url, {
|
|
275
|
+
method: 'POST',
|
|
276
|
+
headers: { 'Content-Type': 'application/json' },
|
|
277
|
+
body: JSON.stringify(body),
|
|
278
|
+
});
|
|
279
|
+
if (!res.ok)
|
|
280
|
+
throw await httpError(res, url, 'committee/decrypt');
|
|
281
|
+
const d = (await res.json());
|
|
282
|
+
return base64Decode(d.plaintext);
|
|
283
|
+
}
|
|
284
|
+
async function ibeExtractOne(nodeUrl, opts) {
|
|
285
|
+
const body = {
|
|
286
|
+
committee_token: opts.committeeToken,
|
|
287
|
+
...(opts.evidenceCt !== undefined ? { evidence_ct: opts.evidenceCt } : {}),
|
|
288
|
+
identity: opts.identity,
|
|
289
|
+
};
|
|
290
|
+
if (opts.userSignature)
|
|
291
|
+
body.user_signature = bareHex(opts.userSignature);
|
|
292
|
+
if (opts.ciphertextEpoch !== undefined)
|
|
293
|
+
body.ciphertext_epoch = opts.ciphertextEpoch;
|
|
294
|
+
if (opts.verifierProofs)
|
|
295
|
+
body.verifier_proofs = proofsToWire(opts.verifierProofs);
|
|
296
|
+
if (opts.clientPubkey && opts.clientSignature) {
|
|
297
|
+
body.client_pubkey = bareHex(opts.clientPubkey);
|
|
298
|
+
body.client_signature = bareHex(opts.clientSignature);
|
|
299
|
+
}
|
|
300
|
+
const url = `${base(nodeUrl)}/v1/shards/ibe/extract`;
|
|
301
|
+
const res = await (opts.fetchImpl ?? fetch)(url, {
|
|
302
|
+
method: 'POST',
|
|
303
|
+
headers: { 'Content-Type': 'application/json' },
|
|
304
|
+
body: JSON.stringify(body),
|
|
305
|
+
signal: opts.signal,
|
|
306
|
+
});
|
|
307
|
+
if (!res.ok)
|
|
308
|
+
throw await httpError(res, url, 'shards/ibe/extract');
|
|
309
|
+
const d = (await res.json());
|
|
310
|
+
const vs = base64Decode(d.verifying_share);
|
|
311
|
+
return {
|
|
312
|
+
...(d.key_slot_id !== undefined ? { keySlotId: d.key_slot_id } : {}),
|
|
313
|
+
...(decodeOperationReceipt(d) ? { receipt: decodeOperationReceipt(d) } : {}),
|
|
314
|
+
identifier: Number(d.identifier),
|
|
315
|
+
value: base64Decode(d.extraction_share),
|
|
316
|
+
// The reply is the 144-byte dual-group encoding (96B G2 || 48B G1); the IBE pairing
|
|
317
|
+
// check needs the G2 half.
|
|
318
|
+
verifyingShareG2: vs.slice(0, 96),
|
|
319
|
+
epoch: Number(d.epoch),
|
|
320
|
+
nodeUrl,
|
|
321
|
+
};
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Fan out to the keeper nodes and collect extraction partials. Nodes that refuse or are
|
|
325
|
+
* down are skipped; throws - naming every node and its reason - only when NONE served.
|
|
326
|
+
* The caller combines with `ibeCombineDecrypt`/`ibeCombineExtract`, which pairing-verify
|
|
327
|
+
* each partial (identifiable abort names the node via the identifier).
|
|
328
|
+
*
|
|
329
|
+
* @param opts - Compound token, identity, keepers and optional expected epoch.
|
|
330
|
+
*/
|
|
331
|
+
export async function requestIbeExtractionPartials(opts) {
|
|
332
|
+
if (opts.nodeUrls.length === 0)
|
|
333
|
+
throw new Error('requestIbeExtractionPartials: no node URLs');
|
|
334
|
+
const settled = await Promise.allSettled(opts.nodeUrls.map(u => ibeExtractOne(u, opts)));
|
|
335
|
+
const partials = settled
|
|
336
|
+
.filter((r) => r.status === 'fulfilled')
|
|
337
|
+
.map(r => r.value);
|
|
338
|
+
if (partials.length === 0) {
|
|
339
|
+
const why = settled
|
|
340
|
+
.map((r, i) => {
|
|
341
|
+
if (r.status === 'fulfilled')
|
|
342
|
+
return null;
|
|
343
|
+
const e = r.reason;
|
|
344
|
+
return `${opts.nodeUrls[i]}: ${e?.message ?? String(r.reason)}`;
|
|
345
|
+
})
|
|
346
|
+
.filter(Boolean)
|
|
347
|
+
.join('; ');
|
|
348
|
+
throw new Error(`requestIbeExtractionPartials: no node served an extraction — ${why}`);
|
|
349
|
+
}
|
|
350
|
+
return partials;
|
|
351
|
+
}
|