@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,161 @@
|
|
|
1
|
+
import type { CompoundTokenWire } from '../committee/token.js';
|
|
2
|
+
import type { VerifierProof } from '../committee/client.js';
|
|
3
|
+
import { type CreateSessionResult, type PresentationDelegation, type PresentationOperation, type WaitOpts, type SessionStatusResult } from '../verifier-agent/index.js';
|
|
4
|
+
import { type CommitteeAction } from './binding.js';
|
|
5
|
+
export { createOid4vpSession, pollOid4vpSession, waitForSession, payloadDigest, nextPollDelay, assertCompoundTokenWire, VerifierAgentSessionError } from '../verifier-agent/index.js';
|
|
6
|
+
export type { SessionPhase, VerifierAgentSessionErrorKind, WaitOpts } from '../verifier-agent/index.js';
|
|
7
|
+
export type { CreateSessionParams, CreateSessionResult, PresentationDelegation, PresentationOperation, SessionStatusResult } from '../verifier-agent/index.js';
|
|
8
|
+
/** EIP-712 domain name for creator-signed presentation operations. */
|
|
9
|
+
export declare const PRESENTATION_EIP712_NAME = "Keykeeper Presentation";
|
|
10
|
+
/** EIP-712 domain version for creator-signed presentation operations. */
|
|
11
|
+
export declare const PRESENTATION_EIP712_VERSION = "1";
|
|
12
|
+
/** The EIP-712 types mirrored from the reference presentation-auth types - do not reorder. */
|
|
13
|
+
export declare const PRESENTATION_OPERATION_TYPES: {
|
|
14
|
+
readonly PresentationOperation: readonly [{
|
|
15
|
+
readonly name: "chainId";
|
|
16
|
+
readonly type: "uint256";
|
|
17
|
+
}, {
|
|
18
|
+
readonly name: "slotId";
|
|
19
|
+
readonly type: "bytes32";
|
|
20
|
+
}, {
|
|
21
|
+
readonly name: "action";
|
|
22
|
+
readonly type: "string";
|
|
23
|
+
}, {
|
|
24
|
+
readonly name: "payloadDigest";
|
|
25
|
+
readonly type: "bytes32";
|
|
26
|
+
}, {
|
|
27
|
+
readonly name: "description";
|
|
28
|
+
readonly type: "string";
|
|
29
|
+
}, {
|
|
30
|
+
readonly name: "exp";
|
|
31
|
+
readonly type: "uint256";
|
|
32
|
+
}];
|
|
33
|
+
};
|
|
34
|
+
/** Anything that signs EIP-712 typed data for an address - a viem `LocalAccount` or `WalletClient`-bound account fits. */
|
|
35
|
+
export interface TypedDataSigner {
|
|
36
|
+
/** EVM address of the creator or delegated signing wallet. */
|
|
37
|
+
address: `0x${string}`;
|
|
38
|
+
/** Sign the operation EIP-712 payload using the wallet's key. */
|
|
39
|
+
signTypedData(args: {
|
|
40
|
+
domain: {
|
|
41
|
+
name: string;
|
|
42
|
+
version: string;
|
|
43
|
+
chainId: number;
|
|
44
|
+
verifyingContract: `0x${string}`;
|
|
45
|
+
};
|
|
46
|
+
types: typeof PRESENTATION_OPERATION_TYPES;
|
|
47
|
+
primaryType: 'PresentationOperation';
|
|
48
|
+
message: {
|
|
49
|
+
chainId: bigint;
|
|
50
|
+
slotId: `0x${string}`;
|
|
51
|
+
action: string;
|
|
52
|
+
payloadDigest: `0x${string}`;
|
|
53
|
+
description: string;
|
|
54
|
+
exp: bigint;
|
|
55
|
+
};
|
|
56
|
+
}): Promise<`0x${string}`>;
|
|
57
|
+
}
|
|
58
|
+
/** Slot operation, payload context and authorization lifetime used to construct EIP-712 typed data. */
|
|
59
|
+
export interface OperationInput {
|
|
60
|
+
/** EVM chain identifier. */
|
|
61
|
+
chainId: number;
|
|
62
|
+
/** The KeyRegistry address - the EIP-712 `verifyingContract`. */
|
|
63
|
+
keyRegistry: `0x${string}`;
|
|
64
|
+
/** 32-byte slot identifier. */
|
|
65
|
+
slotId: `0x${string}` | Uint8Array;
|
|
66
|
+
/** Operation whose payload and permission are being authorized. */
|
|
67
|
+
action: CommitteeAction;
|
|
68
|
+
/** `sign`: the message; `ibe-extract`: use `identity`; `decrypt`/`dual-approve`: use `payloadDigest`. */
|
|
69
|
+
message?: Uint8Array;
|
|
70
|
+
/** Exact identity string for an IBE extraction operation. */
|
|
71
|
+
identity?: string;
|
|
72
|
+
/** Precomputed 32-byte digest for decrypt or dual-approve. */
|
|
73
|
+
payloadDigest?: Uint8Array;
|
|
74
|
+
/** Shown by the wallet as the operation's purpose. */
|
|
75
|
+
description: string;
|
|
76
|
+
/** Seconds the authorization stays valid (default 600, the verifier-agent caps at 3600). */
|
|
77
|
+
ttlSecs?: number;
|
|
78
|
+
/** Current time override in Unix seconds. */
|
|
79
|
+
nowSecs?: number;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* The typed data a creator (or delegate) signs, plus the wire operation and the verifier-agent's `message_hex`.
|
|
83
|
+
*
|
|
84
|
+
* @param input - Network, slot, operation payload, description and authorization lifetime.
|
|
85
|
+
*/
|
|
86
|
+
export declare function presentationOperationTypedData(input: OperationInput): {
|
|
87
|
+
typedData: Parameters<TypedDataSigner['signTypedData']>[0];
|
|
88
|
+
operation: PresentationOperation;
|
|
89
|
+
messageHex: string;
|
|
90
|
+
payloadDigest: Uint8Array;
|
|
91
|
+
};
|
|
92
|
+
/** Operation, signing wallet and verifier-agent endpoint for opening a presentation session. */
|
|
93
|
+
export interface OpenVerifierAgentSessionOpts extends OperationInput {
|
|
94
|
+
/** Verifier-agent HTTP base URL for the selected network. */
|
|
95
|
+
verifierAgentUrl: string;
|
|
96
|
+
/** The slot creator's key, or a delegate's (with `delegation`). */
|
|
97
|
+
signer: TypedDataSigner;
|
|
98
|
+
/** Optional creator-signed delegation authorizing the signing wallet. */
|
|
99
|
+
delegation?: PresentationDelegation;
|
|
100
|
+
}
|
|
101
|
+
/** Opened wallet session with its signed operation and expected request-binding hash. */
|
|
102
|
+
export interface OpenedVerifierAgentSession extends CreateSessionResult {
|
|
103
|
+
/** Signed operation details presented for authorization. */
|
|
104
|
+
operation: PresentationOperation;
|
|
105
|
+
/** The binding hash the token will carry - compare with the token's `request_hash`. */
|
|
106
|
+
requestHash: Uint8Array;
|
|
107
|
+
/** Verifier-agent HTTP base URL for the selected network. */
|
|
108
|
+
verifierAgentUrl: string;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Sign the operation and open a session; hand `qrPayload` to the wallet.
|
|
112
|
+
*
|
|
113
|
+
* @param opts - Operation details, signing wallet and verifier-agent endpoint.
|
|
114
|
+
*/
|
|
115
|
+
export declare function openVerifierAgentSession(opts: OpenVerifierAgentSessionOpts): Promise<OpenedVerifierAgentSession>;
|
|
116
|
+
/** Compound committee token with optional request preimage and verifier membership proofs. */
|
|
117
|
+
export interface VerifierAgentResult {
|
|
118
|
+
/** Compound committee authorization token. */
|
|
119
|
+
token: CompoundTokenWire;
|
|
120
|
+
/** Operation context used to derive the request-binding hash. */
|
|
121
|
+
bindingPreimage?: Record<string, unknown>;
|
|
122
|
+
/**
|
|
123
|
+
* The drawn verifiers' snapshot membership proofs the verifier-agent built at session creation -
|
|
124
|
+
* hand them to every keeper call (`verifierProofs`): a keeper in snapshot-required mode
|
|
125
|
+
* (`api.require_verifier_proofs`) refuses a committee request without them.
|
|
126
|
+
*/
|
|
127
|
+
verifierProofs?: VerifierProof[];
|
|
128
|
+
/**
|
|
129
|
+
* the sealed presentation the token's `evidence_hash` binds, when the committee
|
|
130
|
+
* sealed one — hand it to every keeper call (`evidenceCt`); a keeper with
|
|
131
|
+
* `require_committee_evidence` refuses the token without it.
|
|
132
|
+
*/
|
|
133
|
+
evidenceCt?: string;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* The verifier-agent's `verifier_proofs` DTO (`{verifier_index, operator, pubkey, proof}`) to the SDK shape.
|
|
137
|
+
*
|
|
138
|
+
* @param raw - Verifier-agent verifier_proofs response value.
|
|
139
|
+
*/
|
|
140
|
+
export declare function verifierAgentVerifierProofs(raw: unknown): VerifierProof[] | undefined;
|
|
141
|
+
/**
|
|
142
|
+
* Poll until the wallet has presented and the committee answered. Rejects with an
|
|
143
|
+
* `VerifierAgentSessionError` whose `kind` the UI explains - `refused` (the verifier-agent's `error` names the
|
|
144
|
+
* refusing side), `timeout`, `unavailable`, `protocol`, `cancelled` - and whose
|
|
145
|
+
* `correlation` is the session id. A token that binds another request than this session
|
|
146
|
+
* opened, or one whose proofs are malformed, is a `protocol` refusal: nothing is built on it.
|
|
147
|
+
*
|
|
148
|
+
* @param session - Opened session credentials and expected request-binding hash.
|
|
149
|
+
* @param opts - Polling intervals, timeout, cancellation and progress callback.
|
|
150
|
+
*/
|
|
151
|
+
export declare function awaitVerifierAgentResult(session: Pick<OpenedVerifierAgentSession, 'verifierAgentUrl' | 'sessionId' | 'pollSecret' | 'requestHash'>, opts?: {
|
|
152
|
+
intervalMs?: number;
|
|
153
|
+
timeoutMs?: number;
|
|
154
|
+
} & WaitOpts): Promise<VerifierAgentResult>;
|
|
155
|
+
/**
|
|
156
|
+
* Validate request binding and proof encoding after either URL or registered-session polling.
|
|
157
|
+
*
|
|
158
|
+
* @param session - Session identifier and expected request-binding hash.
|
|
159
|
+
* @param r - Completed session status to validate and decode.
|
|
160
|
+
*/
|
|
161
|
+
export declare function verifierAgentResult(session: Pick<OpenedVerifierAgentSession, 'sessionId' | 'requestHash'>, r: SessionStatusResult): VerifierAgentResult;
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
// The RELYING PARTY half against the Verifier Agent: the app that wants an authorization
|
|
2
|
+
// signs the operation tuple with the slot creator's EVM key (EIP-712 `PresentationOperation`),
|
|
3
|
+
// opens a session, hands the `openid4vp://` payload to a wallet as a QR or deep link, and later
|
|
4
|
+
// collects the compound token. Nothing about the presentation ever comes back here.
|
|
5
|
+
//
|
|
6
|
+
// Adds EIP-712 operation signing and action-specific payload binding to the session client.
|
|
7
|
+
import { bytesToHex, hexToBytes } from '../crypto/hex.js';
|
|
8
|
+
import { VerifierAgentSessionError, createOid4vpSession, waitForSession } from '../verifier-agent/index.js';
|
|
9
|
+
import { payloadDigestFor, requestHash } from './binding.js';
|
|
10
|
+
import { utf8 } from './jose.js';
|
|
11
|
+
export { createOid4vpSession, pollOid4vpSession, waitForSession, payloadDigest, nextPollDelay, assertCompoundTokenWire, VerifierAgentSessionError } from '../verifier-agent/index.js';
|
|
12
|
+
/** EIP-712 domain name for creator-signed presentation operations. */
|
|
13
|
+
export const PRESENTATION_EIP712_NAME = 'Keykeeper Presentation';
|
|
14
|
+
/** EIP-712 domain version for creator-signed presentation operations. */
|
|
15
|
+
export const PRESENTATION_EIP712_VERSION = '1';
|
|
16
|
+
/** The EIP-712 types mirrored from the reference presentation-auth types - do not reorder. */
|
|
17
|
+
export const PRESENTATION_OPERATION_TYPES = {
|
|
18
|
+
PresentationOperation: [
|
|
19
|
+
{ name: 'chainId', type: 'uint256' },
|
|
20
|
+
{ name: 'slotId', type: 'bytes32' },
|
|
21
|
+
{ name: 'action', type: 'string' },
|
|
22
|
+
{ name: 'payloadDigest', type: 'bytes32' },
|
|
23
|
+
{ name: 'description', type: 'string' },
|
|
24
|
+
{ name: 'exp', type: 'uint256' },
|
|
25
|
+
],
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* The typed data a creator (or delegate) signs, plus the wire operation and the verifier-agent's `message_hex`.
|
|
29
|
+
*
|
|
30
|
+
* @param input - Network, slot, operation payload, description and authorization lifetime.
|
|
31
|
+
*/
|
|
32
|
+
export function presentationOperationTypedData(input) {
|
|
33
|
+
const slot = typeof input.slotId === 'string' ? hexToBytes(input.slotId) : input.slotId;
|
|
34
|
+
if (slot.length !== 32)
|
|
35
|
+
throw new Error('slotId must be 32 bytes');
|
|
36
|
+
const messageBytes = input.action === 'ibe-extract' ? (input.identity !== undefined ? utf8(input.identity) : undefined) : input.message;
|
|
37
|
+
const digest = payloadDigestFor(input.action, { message: input.message, identity: input.identity, payloadDigest: input.payloadDigest });
|
|
38
|
+
// The verifier-agent requires `message_hex` and, for sign / ibe-extract, derives the digest from it; for the
|
|
39
|
+
// other actions the digest is taken as signed, so the digest itself is the message it stores.
|
|
40
|
+
const messageHex = bytesToHex(messageBytes ?? digest);
|
|
41
|
+
const exp = (input.nowSecs ?? Math.floor(Date.now() / 1000)) + (input.ttlSecs ?? 600);
|
|
42
|
+
const operation = {
|
|
43
|
+
chain_id: input.chainId,
|
|
44
|
+
slot_id: bytesToHex(slot),
|
|
45
|
+
action: input.action,
|
|
46
|
+
payload_digest: bytesToHex(digest),
|
|
47
|
+
description: input.description,
|
|
48
|
+
exp,
|
|
49
|
+
};
|
|
50
|
+
return {
|
|
51
|
+
typedData: {
|
|
52
|
+
domain: { name: PRESENTATION_EIP712_NAME, version: PRESENTATION_EIP712_VERSION, chainId: input.chainId, verifyingContract: input.keyRegistry },
|
|
53
|
+
types: PRESENTATION_OPERATION_TYPES,
|
|
54
|
+
primaryType: 'PresentationOperation',
|
|
55
|
+
message: { chainId: BigInt(input.chainId), slotId: bytesToHex(slot), action: input.action, payloadDigest: bytesToHex(digest), description: input.description, exp: BigInt(exp) },
|
|
56
|
+
},
|
|
57
|
+
operation,
|
|
58
|
+
messageHex,
|
|
59
|
+
payloadDigest: digest,
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Sign the operation and open a session; hand `qrPayload` to the wallet.
|
|
64
|
+
*
|
|
65
|
+
* @param opts - Operation details, signing wallet and verifier-agent endpoint.
|
|
66
|
+
*/
|
|
67
|
+
export async function openVerifierAgentSession(opts) {
|
|
68
|
+
const { typedData, operation, messageHex, payloadDigest } = presentationOperationTypedData(opts);
|
|
69
|
+
const operationSig = await opts.signer.signTypedData(typedData);
|
|
70
|
+
const session = await createOid4vpSession(opts.verifierAgentUrl, { operation, operationSig, delegation: opts.delegation, messageHex });
|
|
71
|
+
const slot = typeof opts.slotId === 'string' ? hexToBytes(opts.slotId) : opts.slotId;
|
|
72
|
+
return { ...session, operation, requestHash: requestHash(opts.chainId, slot, opts.action, payloadDigest), verifierAgentUrl: opts.verifierAgentUrl };
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* The verifier-agent's `verifier_proofs` DTO (`{verifier_index, operator, pubkey, proof}`) to the SDK shape.
|
|
76
|
+
*
|
|
77
|
+
* @param raw - Verifier-agent verifier_proofs response value.
|
|
78
|
+
*/
|
|
79
|
+
export function verifierAgentVerifierProofs(raw) {
|
|
80
|
+
if (!Array.isArray(raw))
|
|
81
|
+
return undefined;
|
|
82
|
+
const out = [];
|
|
83
|
+
for (const p of raw) {
|
|
84
|
+
if (!p || typeof p !== 'object')
|
|
85
|
+
throw new Error('verifier_proofs: entry is not an object');
|
|
86
|
+
const e = p;
|
|
87
|
+
const index = e.verifier_index;
|
|
88
|
+
if (typeof index !== 'number' || typeof e.operator !== 'string' || typeof e.pubkey !== 'string' || !Array.isArray(e.proof) || !e.proof.every(h => typeof h === 'string')) {
|
|
89
|
+
throw new Error('verifier_proofs: entry is not {verifier_index, operator, pubkey, proof[]}');
|
|
90
|
+
}
|
|
91
|
+
out.push({ verifierIndex: index, operator: e.operator, pubkey: e.pubkey, proof: e.proof });
|
|
92
|
+
}
|
|
93
|
+
return out;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Poll until the wallet has presented and the committee answered. Rejects with an
|
|
97
|
+
* `VerifierAgentSessionError` whose `kind` the UI explains - `refused` (the verifier-agent's `error` names the
|
|
98
|
+
* refusing side), `timeout`, `unavailable`, `protocol`, `cancelled` - and whose
|
|
99
|
+
* `correlation` is the session id. A token that binds another request than this session
|
|
100
|
+
* opened, or one whose proofs are malformed, is a `protocol` refusal: nothing is built on it.
|
|
101
|
+
*
|
|
102
|
+
* @param session - Opened session credentials and expected request-binding hash.
|
|
103
|
+
* @param opts - Polling intervals, timeout, cancellation and progress callback.
|
|
104
|
+
*/
|
|
105
|
+
export async function awaitVerifierAgentResult(session, opts = {}) {
|
|
106
|
+
const { intervalMs, timeoutMs, ...wait } = opts;
|
|
107
|
+
const r = await waitForSession(session.verifierAgentUrl, session.sessionId, session.pollSecret, intervalMs, timeoutMs, wait);
|
|
108
|
+
return verifierAgentResult(session, r);
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Validate request binding and proof encoding after either URL or registered-session polling.
|
|
112
|
+
*
|
|
113
|
+
* @param session - Session identifier and expected request-binding hash.
|
|
114
|
+
* @param r - Completed session status to validate and decode.
|
|
115
|
+
*/
|
|
116
|
+
export function verifierAgentResult(session, r) {
|
|
117
|
+
if (r.status !== 'done' || !r.compoundToken)
|
|
118
|
+
throw new VerifierAgentSessionError('refused', session.sessionId, `presentation ${r.status}: ${r.error ?? 'no token'}`);
|
|
119
|
+
const token = r.compoundToken;
|
|
120
|
+
const rh = token.request_hash;
|
|
121
|
+
if (!rh || rh.replace(/^0x/, '').toLowerCase() !== bytesToHex(session.requestHash).replace(/^0x/, '').toLowerCase()) {
|
|
122
|
+
throw new VerifierAgentSessionError('protocol', session.sessionId, 'the token does not bind the request this session opened');
|
|
123
|
+
}
|
|
124
|
+
let verifierProofs;
|
|
125
|
+
try {
|
|
126
|
+
verifierProofs = verifierAgentVerifierProofs(r.verifierProofs);
|
|
127
|
+
}
|
|
128
|
+
catch (e) {
|
|
129
|
+
throw new VerifierAgentSessionError('protocol', session.sessionId, e instanceof Error ? e.message : String(e));
|
|
130
|
+
}
|
|
131
|
+
return { token, bindingPreimage: r.bindingPreimage, verifierProofs, ...(r.evidenceCt !== undefined ? { evidenceCt: r.evidenceCt } : {}) };
|
|
132
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import { type CredentialView, type Query } from '../auth/oid4vp.js';
|
|
2
|
+
import { type JweEnc } from './jwe.js';
|
|
3
|
+
import type { HolderKey } from './jose.js';
|
|
4
|
+
import { type VerifiedRequestObject, type VerifyRequestObjectOpts } from './request-object.js';
|
|
5
|
+
import { type ParsedSdJwt } from './sd-jwt.js';
|
|
6
|
+
/** A credential the wallet holds. */
|
|
7
|
+
export interface HeldSdJwt {
|
|
8
|
+
/** Compact SD-JWT credential stored by the wallet. */
|
|
9
|
+
sdJwt: string;
|
|
10
|
+
/** For the consent screen. */
|
|
11
|
+
label?: string;
|
|
12
|
+
}
|
|
13
|
+
/** Held credential that matches a named DCQL query during local selection. */
|
|
14
|
+
export interface PresentationCandidate {
|
|
15
|
+
/** Original held credential and its display label. */
|
|
16
|
+
held: HeldSdJwt;
|
|
17
|
+
/** Parsed SD-JWT credential with disclosure hashes checked. */
|
|
18
|
+
parsed: ParsedSdJwt;
|
|
19
|
+
/** Credential claims exposed for advisory DCQL matching. */
|
|
20
|
+
view: CredentialView;
|
|
21
|
+
/** The credential query id this credential answers. */
|
|
22
|
+
queryId: string;
|
|
23
|
+
}
|
|
24
|
+
/** Advisory credential selection, available candidates and unmatched query identifiers. */
|
|
25
|
+
export interface PresentationPlan {
|
|
26
|
+
/** Whether the local (advisory) selection found a credential that satisfies the request. */
|
|
27
|
+
satisfies: boolean;
|
|
28
|
+
/** Every held credential that answers some query - the choice to offer the user. */
|
|
29
|
+
candidates: PresentationCandidate[];
|
|
30
|
+
/** The default choice (the evaluator's pick), when satisfied. */
|
|
31
|
+
chosen?: PresentationCandidate;
|
|
32
|
+
/** Query ids nothing in the wallet answers. */
|
|
33
|
+
unmatched: string[];
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Match held SD-JWT VCs against the request's `dcql_query`. Expired credentials are skipped.
|
|
37
|
+
* Advisory: the drawn verifiers decide; a wrong local answer costs a wasted request, never access.
|
|
38
|
+
*
|
|
39
|
+
* @param ro - Verified request claims containing the DCQL query.
|
|
40
|
+
* @param held - Held SD-JWT credentials to consider.
|
|
41
|
+
* @param nowSecs - Current time in Unix seconds for excluding expired credentials.
|
|
42
|
+
*/
|
|
43
|
+
export declare function planPresentation(ro: Pick<VerifiedRequestObject, 'claims'>, held: readonly HeldSdJwt[], nowSecs?: number): PresentationPlan;
|
|
44
|
+
/**
|
|
45
|
+
* The top-level claim names a credential query asks to see.
|
|
46
|
+
*
|
|
47
|
+
* @param query - Parsed DCQL query.
|
|
48
|
+
* @param queryId - Identifier of the credential query to inspect.
|
|
49
|
+
*/
|
|
50
|
+
export declare function requestedClaimNames(query: Query, queryId: string): string[];
|
|
51
|
+
/** Verified request, selected credential, holder key and disclosure options for a wallet response. */
|
|
52
|
+
export interface BuildResponseOpts {
|
|
53
|
+
/** Verified request claims to bind the response to. */
|
|
54
|
+
ro: Pick<VerifiedRequestObject, 'claims'>;
|
|
55
|
+
/** Credential selected for this presentation. */
|
|
56
|
+
candidate: PresentationCandidate;
|
|
57
|
+
/** Holder key matching the selected credential binding. */
|
|
58
|
+
holder: HolderKey;
|
|
59
|
+
/** Override which disclosures to reveal (default: exactly the claims the query names). */
|
|
60
|
+
disclose?: 'all' | readonly string[];
|
|
61
|
+
/** Current time override in Unix seconds. */
|
|
62
|
+
nowSecs?: number;
|
|
63
|
+
/** Preferred content encryption when the verifier-agent lists several (default A256GCM). */
|
|
64
|
+
enc?: JweEnc;
|
|
65
|
+
}
|
|
66
|
+
/** Holder-bound presentation and form fields ready for submission to the verifier agent. */
|
|
67
|
+
export interface BuiltResponse {
|
|
68
|
+
/** The presentation `issuer~disclosures~kb-jwt` that went into `vp_token`. */
|
|
69
|
+
presentation: string;
|
|
70
|
+
/** The JARM payload `{vp_token: {<queryId>: [presentation]}, state}` as JSON. */
|
|
71
|
+
payload: string;
|
|
72
|
+
/** The form body to POST: `response=<JWE>` when the verifier-agent served an encryption key, else the plain fields. */
|
|
73
|
+
form: Record<string, string>;
|
|
74
|
+
/** Whether the form contains an encrypted JWE response. */
|
|
75
|
+
encrypted: boolean;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Bind the chosen credential to the request (KB-JWT) and wrap it as the verifier-agent expects it.
|
|
79
|
+
*
|
|
80
|
+
* @param opts - Verified request, chosen credential, holder key and disclosure settings.
|
|
81
|
+
*/
|
|
82
|
+
export declare function buildResponse(opts: BuildResponseOpts): BuiltResponse;
|
|
83
|
+
/**
|
|
84
|
+
* POST the built response to `response_uri`; returns the verifier-agent's `redirect_uri` when it gives one.
|
|
85
|
+
*
|
|
86
|
+
* @param ro - Verified request containing the response endpoint.
|
|
87
|
+
* @param built - Built form fields to submit.
|
|
88
|
+
* @param fetchImpl - HTTP transport; defaults to the global fetch implementation.
|
|
89
|
+
*/
|
|
90
|
+
export declare function submitResponse(ro: Pick<VerifiedRequestObject, 'claims'>, built: Pick<BuiltResponse, 'form'>, fetchImpl?: typeof fetch): Promise<{
|
|
91
|
+
redirectUri?: string;
|
|
92
|
+
}>;
|
|
93
|
+
/** Request verification, credential selection and disclosure options for a wallet presentation. */
|
|
94
|
+
export interface PresentOpts extends VerifyRequestObjectOpts {
|
|
95
|
+
/** HTTP transport override; defaults to the global fetch implementation. */
|
|
96
|
+
fetchImpl?: typeof fetch;
|
|
97
|
+
/** Pick among the candidates (default: the evaluator's choice). Return `undefined` to abort. */
|
|
98
|
+
choose?: (plan: PresentationPlan) => PresentationCandidate | undefined | Promise<PresentationCandidate | undefined>;
|
|
99
|
+
/** Claim names to disclose, or all; defaults to the selected query's requested claims. */
|
|
100
|
+
disclose?: 'all' | readonly string[];
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* The whole wallet flow for one QR / deep link: fetch + verify the JAR, plan, let the caller
|
|
104
|
+
* choose (consent screen), bind, encrypt, POST.
|
|
105
|
+
*
|
|
106
|
+
* @param requestUriOrOpenid4vp - Request-object URL or OpenID4VP deep link.
|
|
107
|
+
* @param held - Held SD-JWT credentials available for selection.
|
|
108
|
+
* @param holder - Holder key that matches the selected credential binding.
|
|
109
|
+
* @param opts - Verification, consent selection and disclosure settings.
|
|
110
|
+
*/
|
|
111
|
+
export declare function presentToRequestUri(requestUriOrOpenid4vp: string, held: readonly HeldSdJwt[], holder: HolderKey, opts?: PresentOpts): Promise<{
|
|
112
|
+
ro: VerifiedRequestObject;
|
|
113
|
+
plan: PresentationPlan;
|
|
114
|
+
built: BuiltResponse;
|
|
115
|
+
redirectUri?: string;
|
|
116
|
+
}>;
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
// OpenID4VP presentation using one selected SD-JWT credential, selective
|
|
2
|
+
// disclosure, holder-key binding and optional encrypted wallet responses.
|
|
3
|
+
import { select, credentialMatches, validate } from '../auth/oid4vp.js';
|
|
4
|
+
import { encryptJwe } from './jwe.js';
|
|
5
|
+
import { fetchRequestObject, parseOpenid4vpUri, responseEncryptionKey } from './request-object.js';
|
|
6
|
+
import { parseSdJwt, presentSdJwt, sdJwtCredentialView } from './sd-jwt.js';
|
|
7
|
+
/**
|
|
8
|
+
* Match held SD-JWT VCs against the request's `dcql_query`. Expired credentials are skipped.
|
|
9
|
+
* Advisory: the drawn verifiers decide; a wrong local answer costs a wasted request, never access.
|
|
10
|
+
*
|
|
11
|
+
* @param ro - Verified request claims containing the DCQL query.
|
|
12
|
+
* @param held - Held SD-JWT credentials to consider.
|
|
13
|
+
* @param nowSecs - Current time in Unix seconds for excluding expired credentials.
|
|
14
|
+
*/
|
|
15
|
+
export function planPresentation(ro, held, nowSecs = Math.floor(Date.now() / 1000)) {
|
|
16
|
+
// A wallet reads the rule as dispatched; the issuer-entry mandate is the platform's.
|
|
17
|
+
const query = validate(JSON.stringify(ro.claims.dcql_query), { requireIssuer: false });
|
|
18
|
+
const live = held.flatMap(h => {
|
|
19
|
+
try {
|
|
20
|
+
const parsed = parseSdJwt(h.sdJwt);
|
|
21
|
+
const exp = parsed.payload.exp;
|
|
22
|
+
if (typeof exp === 'number' && exp <= nowSecs)
|
|
23
|
+
return [];
|
|
24
|
+
return [{ held: h, parsed, view: sdJwtCredentialView(parsed) }];
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return [];
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
const candidates = [];
|
|
31
|
+
for (const q of query.credentials) {
|
|
32
|
+
for (const c of live) {
|
|
33
|
+
if (credentialMatches(q, c.view))
|
|
34
|
+
candidates.push({ ...c, queryId: q.id });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
const sel = select(JSON.stringify(ro.claims.dcql_query), live.map(c => c.view), { requireIssuer: false });
|
|
38
|
+
const chosenView = sel.credentials[0];
|
|
39
|
+
const chosen = chosenView ? candidates.find(c => c.view === chosenView) : undefined;
|
|
40
|
+
return { satisfies: sel.satisfied && sel.credentials.length === 1 && chosen !== undefined, candidates, chosen, unmatched: sel.unsatisfied };
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* The top-level claim names a credential query asks to see.
|
|
44
|
+
*
|
|
45
|
+
* @param query - Parsed DCQL query.
|
|
46
|
+
* @param queryId - Identifier of the credential query to inspect.
|
|
47
|
+
*/
|
|
48
|
+
export function requestedClaimNames(query, queryId) {
|
|
49
|
+
const q = query.credentials.find(c => c.id === queryId);
|
|
50
|
+
return [...new Set((q?.claims ?? []).map(c => c.path[0]).filter((n) => typeof n === 'string'))];
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Bind the chosen credential to the request (KB-JWT) and wrap it as the verifier-agent expects it.
|
|
54
|
+
*
|
|
55
|
+
* @param opts - Verified request, chosen credential, holder key and disclosure settings.
|
|
56
|
+
*/
|
|
57
|
+
export function buildResponse(opts) {
|
|
58
|
+
const claims = opts.ro.claims;
|
|
59
|
+
const disclose = opts.disclose ?? requestedClaimNames(validate(JSON.stringify(claims.dcql_query), { requireIssuer: false }), opts.candidate.queryId);
|
|
60
|
+
const presentation = presentSdJwt({ parsed: opts.candidate.parsed, disclose, holder: opts.holder, nonce: claims.nonce, aud: claims.client_id, nowSecs: opts.nowSecs });
|
|
61
|
+
const payloadObj = { vp_token: { [opts.candidate.queryId]: [presentation] }, state: claims.state };
|
|
62
|
+
const payload = JSON.stringify(payloadObj);
|
|
63
|
+
const key = responseEncryptionKey(opts.ro);
|
|
64
|
+
if (key) {
|
|
65
|
+
const offered = claims.client_metadata?.encrypted_response_enc_values_supported;
|
|
66
|
+
const enc = opts.enc ?? (offered && !offered.includes('A256GCM') && offered.includes('A128GCM') ? 'A128GCM' : 'A256GCM');
|
|
67
|
+
return { presentation, payload, form: { response: encryptJwe(payload, key, enc) }, encrypted: true };
|
|
68
|
+
}
|
|
69
|
+
return { presentation, payload, form: { vp_token: JSON.stringify(payloadObj.vp_token), state: claims.state }, encrypted: false };
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* POST the built response to `response_uri`; returns the verifier-agent's `redirect_uri` when it gives one.
|
|
73
|
+
*
|
|
74
|
+
* @param ro - Verified request containing the response endpoint.
|
|
75
|
+
* @param built - Built form fields to submit.
|
|
76
|
+
* @param fetchImpl - HTTP transport; defaults to the global fetch implementation.
|
|
77
|
+
*/
|
|
78
|
+
export async function submitResponse(ro, built, fetchImpl = fetch) {
|
|
79
|
+
const res = await fetchImpl(ro.claims.response_uri, {
|
|
80
|
+
method: 'POST',
|
|
81
|
+
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
|
82
|
+
body: new URLSearchParams(built.form).toString(),
|
|
83
|
+
});
|
|
84
|
+
if (!res.ok)
|
|
85
|
+
throw new Error(`response_uri → HTTP ${res.status}: ${(await res.text().catch(() => '')).slice(0, 200)}`);
|
|
86
|
+
const body = (await res.json().catch(() => ({})));
|
|
87
|
+
return { redirectUri: body.redirect_uri };
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* The whole wallet flow for one QR / deep link: fetch + verify the JAR, plan, let the caller
|
|
91
|
+
* choose (consent screen), bind, encrypt, POST.
|
|
92
|
+
*
|
|
93
|
+
* @param requestUriOrOpenid4vp - Request-object URL or OpenID4VP deep link.
|
|
94
|
+
* @param held - Held SD-JWT credentials available for selection.
|
|
95
|
+
* @param holder - Holder key that matches the selected credential binding.
|
|
96
|
+
* @param opts - Verification, consent selection and disclosure settings.
|
|
97
|
+
*/
|
|
98
|
+
export async function presentToRequestUri(requestUriOrOpenid4vp, held, holder, opts = {}) {
|
|
99
|
+
const requestUri = requestUriOrOpenid4vp.startsWith('openid4vp://') ? parseOpenid4vpUri(requestUriOrOpenid4vp).requestUri : requestUriOrOpenid4vp;
|
|
100
|
+
const ro = await fetchRequestObject(requestUri, opts);
|
|
101
|
+
const plan = planPresentation(ro, held, opts.nowSecs);
|
|
102
|
+
const candidate = opts.choose ? await opts.choose(plan) : plan.chosen;
|
|
103
|
+
if (!candidate)
|
|
104
|
+
throw new Error(plan.unmatched.length ? `no held credential answers: ${plan.unmatched.join(', ')}` : 'presentation declined');
|
|
105
|
+
const built = buildResponse({ ro, candidate, holder, disclose: opts.disclose, nowSecs: opts.nowSecs });
|
|
106
|
+
const { redirectUri } = await submitResponse(ro, built, opts.fetchImpl);
|
|
107
|
+
return { ro, plan, built, redirectUri };
|
|
108
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { type CredentialView } from '../auth/oid4vp.js';
|
|
2
|
+
/**
|
|
3
|
+
* One credential the recipient holds, described as a structured credential view.
|
|
4
|
+
* Build these from your own store of verifiable credentials / verifier JWTs.
|
|
5
|
+
*/
|
|
6
|
+
export interface HeldCredential {
|
|
7
|
+
/** The credential's format identifier (e.g. `"jwt_vc_json"`). */
|
|
8
|
+
format: string;
|
|
9
|
+
/** The credential's type list (for `jwt_vc_json`, its `type` array). */
|
|
10
|
+
types: readonly string[];
|
|
11
|
+
/** The parsed credential body (JSON object with claims). */
|
|
12
|
+
body: unknown;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A recipient's local credential store. Holds structured credentials and
|
|
16
|
+
* evaluates them against DCQL rules for advisory matching. It does not verify
|
|
17
|
+
* credential signatures or establish issuer trust.
|
|
18
|
+
*
|
|
19
|
+
* Everything here is in-memory and synchronous: deciding access reveals nothing
|
|
20
|
+
* to the platform.
|
|
21
|
+
*/
|
|
22
|
+
export declare class RecipientStore {
|
|
23
|
+
/** Held credential views used for local policy evaluation. */
|
|
24
|
+
private readonly credentials;
|
|
25
|
+
constructor(credentials?: (HeldCredential | CredentialView)[]);
|
|
26
|
+
/** Add a credential (returns `this` for chaining). */
|
|
27
|
+
add(credential: HeldCredential | CredentialView): this;
|
|
28
|
+
/** The credential views held in this store. */
|
|
29
|
+
views(): readonly CredentialView[];
|
|
30
|
+
/**
|
|
31
|
+
* Check whether held credential views match the DCQL rule without network access.
|
|
32
|
+
*
|
|
33
|
+
* @returns Whether the supplied credential views satisfy the rule; this is not network authorization.
|
|
34
|
+
* @throws {DcqlMalformedError} if the rule itself is broken (a slot-author
|
|
35
|
+
* bug - the same class the node returns as 400, not a 403 deny), or is a `kk_oauth`
|
|
36
|
+
* policy envelope, which held credentials cannot satisfy. Callers
|
|
37
|
+
* who want a never-throwing check should use {@link canAccess}.
|
|
38
|
+
*/
|
|
39
|
+
satisfies(rule: string): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Build a store from parsed JWT credential bodies.
|
|
42
|
+
* Each entry needs a `type` array and an `iss` field in the body at minimum.
|
|
43
|
+
*/
|
|
44
|
+
static fromJwtBodies(bodies: Array<{
|
|
45
|
+
type: string[];
|
|
46
|
+
iss: string;
|
|
47
|
+
[key: string]: unknown;
|
|
48
|
+
}>): RecipientStore;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Check whether held credential views match a DCQL rule without network access.
|
|
52
|
+
*
|
|
53
|
+
* Accepts a {@link RecipientStore} or a bare {@link HeldCredential} list.
|
|
54
|
+
* Unlike {@link RecipientStore.satisfies}, a malformed rule returns `false`
|
|
55
|
+
* (fail-closed) rather than throwing.
|
|
56
|
+
*
|
|
57
|
+
* @param rule - DCQL policy encoded as JSON text.
|
|
58
|
+
* @param store - Held credential views used for the local access decision.
|
|
59
|
+
*/
|
|
60
|
+
export declare function canAccess(rule: string, store: RecipientStore | HeldCredential[]): boolean;
|
|
61
|
+
/**
|
|
62
|
+
* Explicitly validate a slot's rule client-side: returns normally if well-formed,
|
|
63
|
+
* throws {@link DcqlMalformedError} otherwise.
|
|
64
|
+
*
|
|
65
|
+
* @param rule - DCQL policy encoded as JSON text.
|
|
66
|
+
*/
|
|
67
|
+
export declare function validateRule(rule: string): void;
|