@t3foundry/tasra-sdk 0.0.0-stage → 0.3.1-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,211 @@
|
|
|
1
|
+
import { type ScopeNamespace } from '../auth/oid4vp.js';
|
|
2
|
+
import { type HolderKey } from '../oid4vp/jose.js';
|
|
3
|
+
import { type SdJwtIssuer } from '../oid4vp/sd-jwt.js';
|
|
4
|
+
import { type PresentOpts } from '../oid4vp/wallet.js';
|
|
5
|
+
import { type TypedDataSigner } from '../oid4vp/verifier-agent.js';
|
|
6
|
+
import type { PresentationDelegation, SessionPhase } from '../verifier-agent/index.js';
|
|
7
|
+
import type { AuthorizationRequest, OperationAuthorizer } from './client.js';
|
|
8
|
+
/**
|
|
9
|
+
* DID identity with holder and issuer adapters backed by one managed signing key.
|
|
10
|
+
*/
|
|
11
|
+
export interface TasraIdentity {
|
|
12
|
+
/**
|
|
13
|
+
* Self-certifying DID derived from the identity public key.
|
|
14
|
+
*/
|
|
15
|
+
readonly did: string;
|
|
16
|
+
/**
|
|
17
|
+
* Signing curve used by holder and issuer adapters.
|
|
18
|
+
*/
|
|
19
|
+
readonly algorithm: 'Ed25519' | 'P-256';
|
|
20
|
+
/** Advanced adapter access. Contains private key bytes; never log or serialize it. */
|
|
21
|
+
readonly holder: HolderKey;
|
|
22
|
+
/** Advanced issuer adapter. Contains private key bytes; never log or serialize it. */
|
|
23
|
+
readonly issuer: SdJwtIssuer;
|
|
24
|
+
/** Explicit backup. The caller must protect and eventually clear this independent copy. */
|
|
25
|
+
exportPrivateKey(): Uint8Array;
|
|
26
|
+
/** Clears SDK-owned key bytes. Cannot erase previously exported copies. */
|
|
27
|
+
destroy(): void;
|
|
28
|
+
/**
|
|
29
|
+
* Return public identity metadata without serializing private key bytes.
|
|
30
|
+
*/
|
|
31
|
+
toJSON(): {
|
|
32
|
+
did: string;
|
|
33
|
+
algorithm: 'Ed25519' | 'P-256';
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Create a fresh DID and its credential signing key without a separate crypto library.
|
|
38
|
+
* @param options Optional signing algorithm and 32-byte seed; defaults to a fresh Ed25519 key.
|
|
39
|
+
* @returns Identity with public DID metadata and explicitly managed private-key custody.
|
|
40
|
+
*/
|
|
41
|
+
export declare function createIdentity(options?: {
|
|
42
|
+
algorithm?: 'Ed25519' | 'P-256';
|
|
43
|
+
seed?: Uint8Array;
|
|
44
|
+
}): TasraIdentity;
|
|
45
|
+
/**
|
|
46
|
+
* Issuer, holder and claims for a signed, expiring SD-JWT credential.
|
|
47
|
+
*/
|
|
48
|
+
export interface IssueCredentialOptions {
|
|
49
|
+
/**
|
|
50
|
+
* Identity whose private key signs the credential.
|
|
51
|
+
*/
|
|
52
|
+
issuer: TasraIdentity;
|
|
53
|
+
/**
|
|
54
|
+
* Identity whose DID receives the credential key binding.
|
|
55
|
+
*/
|
|
56
|
+
holder: TasraIdentity;
|
|
57
|
+
/**
|
|
58
|
+
* Credential type written to the vct claim.
|
|
59
|
+
*/
|
|
60
|
+
type: string;
|
|
61
|
+
/**
|
|
62
|
+
* Application claims; reserved protocol claims are rejected.
|
|
63
|
+
*/
|
|
64
|
+
claims: Record<string, unknown>;
|
|
65
|
+
/** Defaults to the holder DID. Human/application subject DIDs are also supported. */
|
|
66
|
+
subject?: string;
|
|
67
|
+
/** Defaults to one hour. */
|
|
68
|
+
ttlSecs?: number;
|
|
69
|
+
/**
|
|
70
|
+
* Issuance time in Unix seconds; defaults to the current clock.
|
|
71
|
+
*/
|
|
72
|
+
nowSecs?: number;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Issue a holder-bound SD-JWT credential; protocol claims cannot be replaced by app claims.
|
|
76
|
+
* @param options Issuer, holder, credential type, application claims and lifetime.
|
|
77
|
+
* @returns Serialized holder-bound SD-JWT credential.
|
|
78
|
+
*/
|
|
79
|
+
export declare function issueCredential(options: IssueCredentialOptions): string;
|
|
80
|
+
/**
|
|
81
|
+
* Optional issuer, holder, type and subject pins applied during credential verification.
|
|
82
|
+
*/
|
|
83
|
+
export interface VerifyCredentialOptions {
|
|
84
|
+
/**
|
|
85
|
+
* Require this exact issuer DID when supplied.
|
|
86
|
+
*/
|
|
87
|
+
issuer?: string | Pick<TasraIdentity, 'did'>;
|
|
88
|
+
/**
|
|
89
|
+
* Require this holder DID to match the credential key binding.
|
|
90
|
+
*/
|
|
91
|
+
holder?: Pick<TasraIdentity, 'did'>;
|
|
92
|
+
/**
|
|
93
|
+
* Require this exact credential type.
|
|
94
|
+
*/
|
|
95
|
+
type?: string;
|
|
96
|
+
/**
|
|
97
|
+
* Require this exact subject claim.
|
|
98
|
+
*/
|
|
99
|
+
subject?: string;
|
|
100
|
+
/**
|
|
101
|
+
* Verification time in Unix seconds; defaults to the current clock.
|
|
102
|
+
*/
|
|
103
|
+
nowSecs?: number;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Verify an SD-JWT issued by a self-certifying did:jwk/did:key, its lifetime and optional pins.
|
|
107
|
+
* Signature verification proves key control; trust in that issuer must come from the app's policy.
|
|
108
|
+
* This does not perform revocation/status checks or resolve did:web issuers.
|
|
109
|
+
* @param credential Serialized SD-JWT credential.
|
|
110
|
+
* @param expected Optional trust pins and verification time.
|
|
111
|
+
* @returns Verified disclosed claims; issuer trust depends on the supplied application pins.
|
|
112
|
+
*/
|
|
113
|
+
export declare function verifyCredential(credential: string, expected?: VerifyCredentialOptions): Record<string, unknown>;
|
|
114
|
+
/**
|
|
115
|
+
* Trusted issuer and claim restrictions used to build a credential authorization rule.
|
|
116
|
+
*/
|
|
117
|
+
export interface CredentialPolicyOptions {
|
|
118
|
+
/**
|
|
119
|
+
* Issuer DID trusted by the generated rule.
|
|
120
|
+
*/
|
|
121
|
+
issuer: string | Pick<TasraIdentity, 'did'>;
|
|
122
|
+
/**
|
|
123
|
+
* Required credential type.
|
|
124
|
+
*/
|
|
125
|
+
type: string;
|
|
126
|
+
/**
|
|
127
|
+
* Allowed subject values; must be nonempty when supplied.
|
|
128
|
+
*/
|
|
129
|
+
subjects?: readonly string[];
|
|
130
|
+
/** Top-level claim names with an explicit, nonempty list of allowed values. */
|
|
131
|
+
claims?: Record<string, readonly unknown[]>;
|
|
132
|
+
/** Restrict decrypt/extract operations to scopes named in this credential claim. */
|
|
133
|
+
identityScope?: {
|
|
134
|
+
claim: string;
|
|
135
|
+
namespace?: ScopeNamespace;
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
/**
|
|
139
|
+
* Build and validate the policy committed to a slot, with issuer trust pinned explicitly.
|
|
140
|
+
* @param options Trusted issuer and required credential claims.
|
|
141
|
+
* @returns Validated DCQL rule suitable for slot creation.
|
|
142
|
+
*/
|
|
143
|
+
export declare function credentialPolicy(options: CredentialPolicyOptions): string;
|
|
144
|
+
/**
|
|
145
|
+
* Credential selection, request validation and cancellation controls for OID4VP presentation.
|
|
146
|
+
*/
|
|
147
|
+
export interface PresentCredentialsOptions extends PresentOpts {
|
|
148
|
+
/**
|
|
149
|
+
* Cancel pending wallet presentation work.
|
|
150
|
+
*/
|
|
151
|
+
signal?: AbortSignal;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Present selected, holder-bound credentials to a signed OID4VP request. Passing credentials is
|
|
155
|
+
* explicit consent to the default selection; provide `choose` to display a wallet consent screen.
|
|
156
|
+
* A local policy mismatch throws locally and is not evidence of a verifier rejection.
|
|
157
|
+
* @param requestUri Signed request URI or OID4VP launch URI supplied by the verifier agent.
|
|
158
|
+
* @param identity Live holder identity bound to the selected credentials.
|
|
159
|
+
* @param credentials Serialized SD-JWT credentials explicitly selected for this presentation.
|
|
160
|
+
* @param options Optional consent selection, request checks, transport and cancellation settings.
|
|
161
|
+
*/
|
|
162
|
+
export declare function presentCredentials(requestUri: string, identity: TasraIdentity, credentials: readonly string[], options?: PresentCredentialsOptions): Promise<{
|
|
163
|
+
ro: import("../oid4vp/request-object.js").VerifiedRequestObject;
|
|
164
|
+
plan: import("../oid4vp/wallet.js").PresentationPlan;
|
|
165
|
+
built: import("../oid4vp/wallet.js").BuiltResponse;
|
|
166
|
+
redirectUri?: string;
|
|
167
|
+
}>;
|
|
168
|
+
/**
|
|
169
|
+
* Approved verifier-agent endpoint, holder credentials and consent controls for operation authorization.
|
|
170
|
+
*/
|
|
171
|
+
export interface CredentialAuthorizationOptions {
|
|
172
|
+
/**
|
|
173
|
+
* Explicitly approved verifier-agent endpoint used for the session.
|
|
174
|
+
*/
|
|
175
|
+
verifierAgentUrl: string;
|
|
176
|
+
/**
|
|
177
|
+
* Creator or delegated EIP-712 signer authorizing the operation.
|
|
178
|
+
*/
|
|
179
|
+
signer: TypedDataSigner;
|
|
180
|
+
/**
|
|
181
|
+
* Live holder identity bound to the credentials.
|
|
182
|
+
*/
|
|
183
|
+
identity: TasraIdentity;
|
|
184
|
+
/**
|
|
185
|
+
* Serialized holder-bound credentials selected by the application.
|
|
186
|
+
*/
|
|
187
|
+
credentials: readonly string[];
|
|
188
|
+
/**
|
|
189
|
+
* Optional authorization delegating presentation to another signer.
|
|
190
|
+
*/
|
|
191
|
+
delegation?: PresentationDelegation;
|
|
192
|
+
/** Optional application consent screen, called before any session or credential disclosure. */
|
|
193
|
+
approve?: (request: AuthorizationRequest) => boolean | Promise<boolean>;
|
|
194
|
+
/**
|
|
195
|
+
* Wallet request validation and credential-selection options.
|
|
196
|
+
*/
|
|
197
|
+
presentation?: Omit<PresentCredentialsOptions, 'signal'>;
|
|
198
|
+
/**
|
|
199
|
+
* Observe verifier-agent session progress.
|
|
200
|
+
*/
|
|
201
|
+
onPhase?: (phase: SessionPhase) => void;
|
|
202
|
+
/**
|
|
203
|
+
* Maximum wait for the verifier-agent result in milliseconds.
|
|
204
|
+
*/
|
|
205
|
+
timeoutMs?: number;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Authorize one exact SDK operation: sign its request, present a credential, collect bound proofs.
|
|
209
|
+
* @param options Approved verifier-agent endpoint, signer, holder credentials and local consent controls.
|
|
210
|
+
*/
|
|
211
|
+
export declare function credentialAuthorization(options: CredentialAuthorizationOptions): OperationAuthorizer;
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import { ed25519 } from '@noble/curves/ed25519';
|
|
2
|
+
import { p256 } from '@noble/curves/p256';
|
|
3
|
+
import { equalBytes } from '@noble/curves/utils.js';
|
|
4
|
+
import { validate } from '../auth/oid4vp.js';
|
|
5
|
+
import { b64url, b64urlDecode, didJwk, ed25519HolderKey, holderSigner, jwkFromDid, p256HolderKey, randomHolderKey, verifyCompactJws } from '../oid4vp/jose.js';
|
|
6
|
+
import { holderCnf, issueSdJwtVc, parseSdJwt, sdJwtClaims } from '../oid4vp/sd-jwt.js';
|
|
7
|
+
import { parseOpenid4vpUri } from '../oid4vp/request-object.js';
|
|
8
|
+
import { presentToRequestUri } from '../oid4vp/wallet.js';
|
|
9
|
+
import { awaitVerifierAgentResult, openVerifierAgentSession } from '../oid4vp/verifier-agent.js';
|
|
10
|
+
/**
|
|
11
|
+
* Create a fresh DID and its credential signing key without a separate crypto library.
|
|
12
|
+
* @param options Optional signing algorithm and 32-byte seed; defaults to a fresh Ed25519 key.
|
|
13
|
+
* @returns Identity with public DID metadata and explicitly managed private-key custody.
|
|
14
|
+
*/
|
|
15
|
+
export function createIdentity(options = {}) {
|
|
16
|
+
const algorithm = options.algorithm ?? 'Ed25519';
|
|
17
|
+
if (algorithm !== 'Ed25519' && algorithm !== 'P-256')
|
|
18
|
+
throw new Error('Unsupported identity algorithm');
|
|
19
|
+
if (options.seed !== undefined && (!(options.seed instanceof Uint8Array) || options.seed.length !== 32))
|
|
20
|
+
throw new Error('Identity seed must contain 32 bytes');
|
|
21
|
+
const secret = options.seed?.slice() ?? (algorithm === 'P-256' ? randomHolderKey().privateKey : crypto.getRandomValues(new Uint8Array(32)));
|
|
22
|
+
let holder;
|
|
23
|
+
try {
|
|
24
|
+
holder = algorithm === 'P-256' ? p256HolderKey(secret) : ed25519HolderKey(secret);
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
secret.fill(0);
|
|
28
|
+
throw error;
|
|
29
|
+
}
|
|
30
|
+
Object.freeze(holder.publicJwk);
|
|
31
|
+
Object.freeze(holder);
|
|
32
|
+
const issuer = Object.freeze({ did: holder.did, kid: `${holder.did}#0`, signer: Object.freeze(holderSigner(holder)) });
|
|
33
|
+
let destroyed = false;
|
|
34
|
+
const assertLive = () => { if (destroyed)
|
|
35
|
+
throw new Error('Identity has been destroyed'); };
|
|
36
|
+
return Object.freeze({
|
|
37
|
+
did: holder.did, algorithm,
|
|
38
|
+
get holder() { assertLive(); return holder; },
|
|
39
|
+
get issuer() { assertLive(); return issuer; },
|
|
40
|
+
exportPrivateKey() { assertLive(); return secret.slice(); },
|
|
41
|
+
destroy() { secret.fill(0); destroyed = true; },
|
|
42
|
+
toJSON() { return { did: holder.did, algorithm }; },
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
const reservedClaims = new Set(['iss', 'sub', 'vct', 'cnf', 'iat', 'exp', 'nbf', '_sd', '_sd_alg', '...', '__proto__', 'constructor', 'prototype']);
|
|
46
|
+
function text(value, label) {
|
|
47
|
+
if (typeof value !== 'string' || value.trim().length === 0)
|
|
48
|
+
throw new Error(`${label} must be a nonempty string`);
|
|
49
|
+
}
|
|
50
|
+
function nonemptyArray(value, label) {
|
|
51
|
+
if (!Array.isArray(value) || !value.length)
|
|
52
|
+
throw new Error(`${label} must be a nonempty list`);
|
|
53
|
+
}
|
|
54
|
+
function jsonValue(value) {
|
|
55
|
+
JSON.stringify(value, (_key, item) => {
|
|
56
|
+
if (item === undefined || typeof item === 'function' || typeof item === 'symbol' || typeof item === 'bigint' || typeof item === 'number' && !Number.isFinite(item))
|
|
57
|
+
throw new Error('Claims must contain JSON values');
|
|
58
|
+
return item;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
function clock(nowSecs) {
|
|
62
|
+
const now = nowSecs ?? Math.floor(Date.now() / 1000);
|
|
63
|
+
if (!Number.isSafeInteger(now) || now < 0)
|
|
64
|
+
throw new Error('Credential time must be a nonnegative integer');
|
|
65
|
+
return now;
|
|
66
|
+
}
|
|
67
|
+
function issuerDid(issuer) {
|
|
68
|
+
const did = typeof issuer === 'string' ? issuer : issuer.did;
|
|
69
|
+
text(did, 'Issuer DID');
|
|
70
|
+
if (!/^did:[a-z0-9]+:[^\s#]+$/.test(did))
|
|
71
|
+
throw new Error('Issuer must be a DID without a fragment');
|
|
72
|
+
return did;
|
|
73
|
+
}
|
|
74
|
+
function validatePublicKey(key) {
|
|
75
|
+
function coordinate(encoded) {
|
|
76
|
+
if (typeof encoded !== 'string')
|
|
77
|
+
throw new Error('Invalid credential public key');
|
|
78
|
+
const bytes = b64urlDecode(encoded);
|
|
79
|
+
if (bytes.length !== 32 || b64url(bytes) !== encoded)
|
|
80
|
+
throw new Error('Invalid credential public key coordinate');
|
|
81
|
+
return bytes;
|
|
82
|
+
}
|
|
83
|
+
if (key.kty === 'OKP' && key.crv === 'Ed25519') {
|
|
84
|
+
const point = ed25519.ExtendedPoint.fromHex(coordinate(key.x));
|
|
85
|
+
if (point.isSmallOrder() || !point.isTorsionFree())
|
|
86
|
+
throw new Error('Invalid Ed25519 credential public key');
|
|
87
|
+
}
|
|
88
|
+
else if (key.kty === 'EC' && key.crv === 'P-256') {
|
|
89
|
+
p256.ProjectivePoint.fromHex(new Uint8Array([4, ...coordinate(key.x), ...coordinate(key.y)]));
|
|
90
|
+
}
|
|
91
|
+
else
|
|
92
|
+
throw new Error('Unsupported credential public key curve');
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Issue a holder-bound SD-JWT credential; protocol claims cannot be replaced by app claims.
|
|
96
|
+
* @param options Issuer, holder, credential type, application claims and lifetime.
|
|
97
|
+
* @returns Serialized holder-bound SD-JWT credential.
|
|
98
|
+
*/
|
|
99
|
+
export function issueCredential(options) {
|
|
100
|
+
text(options.type, 'Credential type');
|
|
101
|
+
if (!options.claims || typeof options.claims !== 'object' || Array.isArray(options.claims))
|
|
102
|
+
throw new Error('Claims must be an object');
|
|
103
|
+
for (const name of Object.keys(options.claims)) {
|
|
104
|
+
text(name, 'Claim name');
|
|
105
|
+
if (reservedClaims.has(name))
|
|
106
|
+
throw new Error(`Reserved credential claim: ${name}`);
|
|
107
|
+
}
|
|
108
|
+
jsonValue(options.claims);
|
|
109
|
+
const now = clock(options.nowSecs), ttl = options.ttlSecs ?? 3600;
|
|
110
|
+
if (!Number.isSafeInteger(ttl) || ttl <= 0 || !Number.isSafeInteger(now + ttl))
|
|
111
|
+
throw new Error('Credential ttlSecs must be a positive integer');
|
|
112
|
+
const subject = options.subject ?? options.holder.did;
|
|
113
|
+
text(subject, 'Credential subject');
|
|
114
|
+
// Reading the adapters checks that neither identity has already been destroyed.
|
|
115
|
+
return issueSdJwtVc({ issuer: options.issuer.issuer, cnf: holderCnf(options.holder.holder), vct: options.type,
|
|
116
|
+
sub: subject, claims: options.claims, nowSecs: now, ttlSecs: ttl });
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Verify an SD-JWT issued by a self-certifying did:jwk/did:key, its lifetime and optional pins.
|
|
120
|
+
* Signature verification proves key control; trust in that issuer must come from the app's policy.
|
|
121
|
+
* This does not perform revocation/status checks or resolve did:web issuers.
|
|
122
|
+
* @param credential Serialized SD-JWT credential.
|
|
123
|
+
* @param expected Optional trust pins and verification time.
|
|
124
|
+
* @returns Verified disclosed claims; issuer trust depends on the supplied application pins.
|
|
125
|
+
*/
|
|
126
|
+
export function verifyCredential(credential, expected = {}) {
|
|
127
|
+
text(credential, 'Credential');
|
|
128
|
+
const parsed = parseSdJwt(credential), payload = parsed.payload, did = issuerDid(payload.iss);
|
|
129
|
+
if (parsed.header.typ !== 'dc+sd-jwt')
|
|
130
|
+
throw new Error('Unsupported credential format');
|
|
131
|
+
if (typeof parsed.header.kid !== 'string' || !parsed.header.kid.startsWith(`${did}#`))
|
|
132
|
+
throw new Error('Credential signing key does not name its issuer');
|
|
133
|
+
const issuerKey = jwkFromDid(did);
|
|
134
|
+
validatePublicKey(issuerKey);
|
|
135
|
+
verifyCompactJws(parsed.issuerJwt, issuerKey);
|
|
136
|
+
if (expected.issuer !== undefined && did !== issuerDid(expected.issuer))
|
|
137
|
+
throw new Error('Credential issuer mismatch');
|
|
138
|
+
const now = clock(expected.nowSecs);
|
|
139
|
+
if (!Number.isSafeInteger(payload.exp) || payload.exp <= now)
|
|
140
|
+
throw new Error('Credential is expired or lacks a valid expiry');
|
|
141
|
+
if (!Number.isSafeInteger(payload.iat) || payload.iat > now || payload.iat < 0 || payload.exp <= payload.iat)
|
|
142
|
+
throw new Error('Credential issuance time is invalid');
|
|
143
|
+
if (payload.nbf !== undefined && (!Number.isSafeInteger(payload.nbf) || payload.nbf > now))
|
|
144
|
+
throw new Error('Credential is not yet valid');
|
|
145
|
+
text(payload.vct, 'Credential type');
|
|
146
|
+
const names = new Set(Object.keys(payload));
|
|
147
|
+
for (const disclosure of parsed.disclosures) {
|
|
148
|
+
if (reservedClaims.has(disclosure.name) || names.has(disclosure.name))
|
|
149
|
+
throw new Error('Credential contains a duplicate or reserved disclosure');
|
|
150
|
+
names.add(disclosure.name);
|
|
151
|
+
}
|
|
152
|
+
const cnf = payload.cnf;
|
|
153
|
+
if (!cnf || typeof cnf !== 'object' || typeof cnf.kid !== 'string' || !cnf.kid.endsWith('#0') || cnf.jwk !== undefined)
|
|
154
|
+
throw new Error('Credential must bind a holder DID with cnf.kid');
|
|
155
|
+
const holderDid = cnf.kid.slice(0, -2);
|
|
156
|
+
// Validate the key shape even when the caller has not pinned a holder.
|
|
157
|
+
const holderJwk = jwkFromDid(holderDid);
|
|
158
|
+
validatePublicKey(holderJwk);
|
|
159
|
+
if (didJwk(holderJwk) !== holderDid)
|
|
160
|
+
throw new Error('Credential holder must be a canonical did:jwk');
|
|
161
|
+
if (expected.holder !== undefined && expected.holder.did !== holderDid)
|
|
162
|
+
throw new Error('Credential holder mismatch');
|
|
163
|
+
if (expected.type !== undefined && payload.vct !== expected.type)
|
|
164
|
+
throw new Error('Credential type mismatch');
|
|
165
|
+
if (expected.subject !== undefined && payload.sub !== expected.subject)
|
|
166
|
+
throw new Error('Credential subject mismatch');
|
|
167
|
+
return sdJwtClaims(parsed);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Build and validate the policy committed to a slot, with issuer trust pinned explicitly.
|
|
171
|
+
* @param options Trusted issuer and required credential claims.
|
|
172
|
+
* @returns Validated DCQL rule suitable for slot creation.
|
|
173
|
+
*/
|
|
174
|
+
export function credentialPolicy(options) {
|
|
175
|
+
text(options.type, 'Credential type');
|
|
176
|
+
const claims = [{ path: ['iss'], values: [issuerDid(options.issuer)] }];
|
|
177
|
+
if (options.subjects !== undefined) {
|
|
178
|
+
nonemptyArray(options.subjects, 'Subjects');
|
|
179
|
+
for (const subject of options.subjects)
|
|
180
|
+
text(subject, 'Subject');
|
|
181
|
+
claims.push({ path: ['sub'], values: [...options.subjects] });
|
|
182
|
+
}
|
|
183
|
+
for (const [name, values] of Object.entries(options.claims ?? {})) {
|
|
184
|
+
text(name, 'Claim name');
|
|
185
|
+
if (reservedClaims.has(name))
|
|
186
|
+
throw new Error(`Reserved policy claim: ${name}`);
|
|
187
|
+
nonemptyArray(values, `Policy claim ${name} allowed values`);
|
|
188
|
+
jsonValue(values);
|
|
189
|
+
claims.push({ path: [name], values: [...values] });
|
|
190
|
+
}
|
|
191
|
+
const query = { id: 'access', format: 'dc+sd-jwt', meta: { vct_values: [options.type] }, claims };
|
|
192
|
+
if (options.identityScope !== undefined) {
|
|
193
|
+
const { claim, namespace = 'issuer' } = options.identityScope;
|
|
194
|
+
text(claim, 'Identity scope claim');
|
|
195
|
+
if (reservedClaims.has(claim))
|
|
196
|
+
throw new Error('Identity scope must use an application claim');
|
|
197
|
+
if (!claims.some(c => c.path[0] === claim))
|
|
198
|
+
claims.push({ path: [claim] });
|
|
199
|
+
query.kk_identity_scope_claim = [claim];
|
|
200
|
+
query.kk_scope_namespace = namespace;
|
|
201
|
+
}
|
|
202
|
+
const rule = JSON.stringify({ credentials: [query] });
|
|
203
|
+
validate(rule);
|
|
204
|
+
return rule;
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Present selected, holder-bound credentials to a signed OID4VP request. Passing credentials is
|
|
208
|
+
* explicit consent to the default selection; provide `choose` to display a wallet consent screen.
|
|
209
|
+
* A local policy mismatch throws locally and is not evidence of a verifier rejection.
|
|
210
|
+
* @param requestUri Signed request URI or OID4VP launch URI supplied by the verifier agent.
|
|
211
|
+
* @param identity Live holder identity bound to the selected credentials.
|
|
212
|
+
* @param credentials Serialized SD-JWT credentials explicitly selected for this presentation.
|
|
213
|
+
* @param options Optional consent selection, request checks, transport and cancellation settings.
|
|
214
|
+
*/
|
|
215
|
+
export async function presentCredentials(requestUri, identity, credentials, options = {}) {
|
|
216
|
+
options.signal?.throwIfAborted();
|
|
217
|
+
nonemptyArray(credentials, 'Credentials');
|
|
218
|
+
const holder = identity.holder;
|
|
219
|
+
for (const credential of credentials)
|
|
220
|
+
verifyCredential(credential, { holder: identity, nowSecs: options.nowSecs });
|
|
221
|
+
const transport = options.fetchImpl ?? fetch;
|
|
222
|
+
const fetchImpl = (input, init) => {
|
|
223
|
+
options.signal?.throwIfAborted();
|
|
224
|
+
const signals = [options.signal, init?.signal].filter((signal) => signal != null);
|
|
225
|
+
return transport(input, { ...init, ...(signals.length ? { signal: AbortSignal.any(signals) } : {}) });
|
|
226
|
+
};
|
|
227
|
+
const choose = async (plan) => {
|
|
228
|
+
options.signal?.throwIfAborted();
|
|
229
|
+
const candidate = options.choose ? await options.choose(plan) : plan.chosen;
|
|
230
|
+
options.signal?.throwIfAborted();
|
|
231
|
+
// A caller's consent picker may select only the offered matching candidates.
|
|
232
|
+
if (candidate && (!plan.satisfies || !plan.candidates.includes(candidate)))
|
|
233
|
+
throw new Error('Presentation choice does not satisfy the requested policy');
|
|
234
|
+
// Check liveness again after an asynchronous consent screen.
|
|
235
|
+
if (!equalBytes(identity.holder.privateKey, holder.privateKey))
|
|
236
|
+
throw new Error('Identity changed during presentation');
|
|
237
|
+
return candidate;
|
|
238
|
+
};
|
|
239
|
+
return presentToRequestUri(requestUri, credentials.map(sdJwt => ({ sdJwt })), holder, { ...options, fetchImpl, choose });
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* Authorize one exact SDK operation: sign its request, present a credential, collect bound proofs.
|
|
243
|
+
* @param options Approved verifier-agent endpoint, signer, holder credentials and local consent controls.
|
|
244
|
+
*/
|
|
245
|
+
export function credentialAuthorization(options) {
|
|
246
|
+
const endpoint = new URL(options.verifierAgentUrl);
|
|
247
|
+
if (endpoint.protocol !== 'https:' && !(endpoint.protocol === 'http:' && ['localhost', '127.0.0.1', '[::1]'].includes(endpoint.hostname)))
|
|
248
|
+
throw new Error('Verifier agent requires HTTPS (HTTP is allowed only on loopback)');
|
|
249
|
+
if (endpoint.username || endpoint.password || endpoint.search || endpoint.hash)
|
|
250
|
+
throw new Error('Verifier URL cannot contain credentials, a query or a fragment');
|
|
251
|
+
nonemptyArray(options.credentials, 'Credentials');
|
|
252
|
+
const credentials = [...options.credentials];
|
|
253
|
+
const assertOrigin = (input) => {
|
|
254
|
+
const url = new URL(input);
|
|
255
|
+
if (url.origin !== endpoint.origin || url.username || url.password)
|
|
256
|
+
throw new Error('Credential presentation must stay on the selected verifier origin');
|
|
257
|
+
};
|
|
258
|
+
const transport = options.presentation?.fetchImpl ?? fetch;
|
|
259
|
+
const fetchImpl = (input, init) => {
|
|
260
|
+
assertOrigin(input instanceof Request ? input.url : String(input));
|
|
261
|
+
return transport(input, { ...init, redirect: 'error' });
|
|
262
|
+
};
|
|
263
|
+
return async (request) => {
|
|
264
|
+
request.signal?.throwIfAborted();
|
|
265
|
+
for (const credential of credentials)
|
|
266
|
+
verifyCredential(credential, { holder: options.identity });
|
|
267
|
+
const operation = { ...request, ...(request.message ? { message: request.message.slice() } : {}),
|
|
268
|
+
...(request.payloadDigest ? { payloadDigest: request.payloadDigest.slice() } : {}),
|
|
269
|
+
slotId: typeof request.slotId === 'string' ? request.slotId : request.slotId.slice() };
|
|
270
|
+
const consent = { ...operation, ...(operation.message ? { message: operation.message.slice() } : {}),
|
|
271
|
+
...(operation.payloadDigest ? { payloadDigest: operation.payloadDigest.slice() } : {}),
|
|
272
|
+
slotId: typeof operation.slotId === 'string' ? operation.slotId : operation.slotId.slice() };
|
|
273
|
+
if (options.approve && !await options.approve(Object.freeze(consent)))
|
|
274
|
+
throw new Error('Credential authorization declined locally');
|
|
275
|
+
request.signal?.throwIfAborted();
|
|
276
|
+
// Opening is not retried automatically: the existing session remains the source of truth.
|
|
277
|
+
const session = await openVerifierAgentSession({ ...operation, verifierAgentUrl: endpoint.href.replace(/\/$/, ''), signer: options.signer, delegation: options.delegation });
|
|
278
|
+
request.signal?.throwIfAborted();
|
|
279
|
+
assertOrigin(session.qrPayload.startsWith('openid4vp://') ? parseOpenid4vpUri(session.qrPayload).requestUri : session.qrPayload);
|
|
280
|
+
await presentCredentials(session.qrPayload, options.identity, credentials, { ...options.presentation, fetchImpl, signal: request.signal });
|
|
281
|
+
request.signal?.throwIfAborted();
|
|
282
|
+
const result = await awaitVerifierAgentResult(session, { signal: request.signal, timeoutMs: options.timeoutMs, onPhase: options.onPhase });
|
|
283
|
+
if (!result.verifierProofs?.length)
|
|
284
|
+
throw new Error('Authorization did not include verifier membership proofs');
|
|
285
|
+
return { token: result.token, verifierProofs: result.verifierProofs };
|
|
286
|
+
};
|
|
287
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Application API. safe to import in browsers. */
|
|
2
|
+
export { createTasra, TasraApplicationError } from './client.js';
|
|
3
|
+
export type { TasraApplication, TasraApplicationConfig, ApplicationErrorCode, SlotMetadata, OperationGrant, AuthorizationRequest, OperationAuthorizer, AuthorizedOperationOptions, EcdsaSlot, FrostSlot, BlsSlot } from './client.js';
|
|
4
|
+
export { defineDeployment } from './deployment.js';
|
|
5
|
+
export type { TasraDeployment } from './deployment.js';
|
|
6
|
+
export { toViemAccount } from './viem.js';
|
|
7
|
+
export { registeredWalletAuthorization } from './authorization.js';
|
|
8
|
+
export { prepareSlot, createPreparedSlot, CreationReconciliationRequiredError } from './creation.js';
|
|
9
|
+
export type { SlotCreationJournal } from './creation.js';
|
|
10
|
+
export { TasraClient } from './tasra-client.js';
|
|
11
|
+
export type { TasraClientOptions, CreateSlotOptions } from './tasra-client.js';
|
|
12
|
+
export { resolveApplicationManifest, loadApplicationManifest } from './manifest.js';
|
|
13
|
+
export type { ApplicationManifest, ResolveApplicationManifestOptions, LoadApplicationManifestOptions } from './manifest.js';
|
|
14
|
+
export { createApplicationSlot, ApplicationSlotRecoveryError } from './ready-slot.js';
|
|
15
|
+
export type { ApplicationStore, CreateApplicationSlot, CreateApplicationSlotOptions, ReadySlotJournal, ApplicationSlotRecoveryCode, SlotCreationProgress } from './ready-slot.js';
|
|
16
|
+
export { createLocalWallet, connectWallet, createSlotWallet } from './wallet.js';
|
|
17
|
+
export { createIdentity, issueCredential, verifyCredential, credentialPolicy, credentialAuthorization, presentCredentials } from './identity.js';
|
|
18
|
+
export type { TasraWallet, WalletTransactionInput, WalletTransactionJournal } from './wallet.js';
|
|
19
|
+
export type { TasraIdentity, IssueCredentialOptions, VerifyCredentialOptions, CredentialPolicyOptions, PresentCredentialsOptions, CredentialAuthorizationOptions } from './identity.js';
|
|
20
|
+
export type { ApplicationDeployment, ResolvedApplicationManifest } from './manifest.js';
|
|
21
|
+
export { setApprovalPolicy, identityApprover, approveWithCredential } from './approvals.js';
|
|
22
|
+
export type { ApprovalPolicy } from './approvals.js';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** Application API. safe to import in browsers. */
|
|
2
|
+
export { createTasra, TasraApplicationError } from './client.js';
|
|
3
|
+
export { defineDeployment } from './deployment.js';
|
|
4
|
+
export { toViemAccount } from './viem.js';
|
|
5
|
+
export { registeredWalletAuthorization } from './authorization.js';
|
|
6
|
+
export { prepareSlot, createPreparedSlot, CreationReconciliationRequiredError } from './creation.js';
|
|
7
|
+
export { TasraClient } from './tasra-client.js';
|
|
8
|
+
export { resolveApplicationManifest, loadApplicationManifest } from './manifest.js';
|
|
9
|
+
export { createApplicationSlot, ApplicationSlotRecoveryError } from './ready-slot.js';
|
|
10
|
+
export { createLocalWallet, connectWallet, createSlotWallet } from './wallet.js';
|
|
11
|
+
export { createIdentity, issueCredential, verifyCredential, credentialPolicy, credentialAuthorization, presentCredentials } from './identity.js';
|
|
12
|
+
export { setApprovalPolicy, identityApprover, approveWithCredential } from './approvals.js';
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { type NetworkManifest } from '../chain/manifest.js';
|
|
2
|
+
import { type TasraDeployment } from './deployment.js';
|
|
3
|
+
/**
|
|
4
|
+
* Public application deployment settings with optional explicitly approved endpoint routing.
|
|
5
|
+
*/
|
|
6
|
+
export interface ApplicationDeployment extends TasraDeployment {
|
|
7
|
+
/**
|
|
8
|
+
* Explicitly approved verifier-agent endpoint.
|
|
9
|
+
*/
|
|
10
|
+
verifierAgentUrl?: string;
|
|
11
|
+
/** Exact registered URL to reachable URL mappings; never inferred from a hostname. */
|
|
12
|
+
keeperUrls?: Record<string, string>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* A network manifest downloaded from tasra-releases or an explicitly approved application deployment.
|
|
16
|
+
*/
|
|
17
|
+
export type ApplicationManifest = NetworkManifest | ApplicationDeployment;
|
|
18
|
+
/**
|
|
19
|
+
* Explicit RPC and coordinator choices applied when resolving a network manifest.
|
|
20
|
+
*/
|
|
21
|
+
export interface ResolveApplicationManifestOptions {
|
|
22
|
+
/**
|
|
23
|
+
* Explicit JSON-RPC endpoint override for the chosen network.
|
|
24
|
+
*/
|
|
25
|
+
rpcUrl?: string;
|
|
26
|
+
/** Required for release manifests, whose schema does not specify this convention. */
|
|
27
|
+
coordinator?: TasraDeployment['coordinator'];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Validated deployment settings and optional endpoint routing for an application client.
|
|
31
|
+
*/
|
|
32
|
+
export interface ResolvedApplicationManifest {
|
|
33
|
+
/**
|
|
34
|
+
* Validated network configuration suitable for an application client.
|
|
35
|
+
*/
|
|
36
|
+
deployment: Readonly<TasraDeployment>;
|
|
37
|
+
/**
|
|
38
|
+
* Verifier-agent endpoint advertised by the approved configuration.
|
|
39
|
+
*/
|
|
40
|
+
verifierAgentUrl?: string;
|
|
41
|
+
/**
|
|
42
|
+
* Explicit routing function for registered keeper endpoints, when configured.
|
|
43
|
+
*/
|
|
44
|
+
keeperUrl?: (registeredUrl: string) => string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Manifest download controls and an optional independently trusted SHA-256 pin.
|
|
48
|
+
*/
|
|
49
|
+
export interface LoadApplicationManifestOptions extends ResolveApplicationManifestOptions {
|
|
50
|
+
/** Lowercase SHA-256 of the downloaded bytes, obtained from a trusted source. */
|
|
51
|
+
sha256?: string;
|
|
52
|
+
/**
|
|
53
|
+
* HTTP implementation used to download manifest bytes.
|
|
54
|
+
*/
|
|
55
|
+
fetchImpl?: typeof fetch;
|
|
56
|
+
/**
|
|
57
|
+
* Cancel the manifest HTTP download.
|
|
58
|
+
*/
|
|
59
|
+
signal?: AbortSignal;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Validate caller-approved configuration without network I/O or readiness claims.
|
|
63
|
+
* @param input Downloaded network manifest or explicitly approved deployment settings.
|
|
64
|
+
* @returns Validated deployment and optional routing without a network request.
|
|
65
|
+
* @param options Explicit RPC and coordinator choices for the manifest.
|
|
66
|
+
*/
|
|
67
|
+
export declare function resolveApplicationManifest(input: ApplicationManifest, options?: ResolveApplicationManifestOptions): ResolvedApplicationManifest;
|
|
68
|
+
/**
|
|
69
|
+
* Fetch a public manifest; an optional trusted pin is checked before parsing any JSON.
|
|
70
|
+
* @param source HTTPS manifest URL. HTTP is allowed only for loopback or with an independently trusted digest pin.
|
|
71
|
+
* @returns Parsed deployment after any supplied digest pin has been verified.
|
|
72
|
+
* @param options Trusted digest pin, manifest resolution choices and HTTP controls.
|
|
73
|
+
*/
|
|
74
|
+
export declare function loadApplicationManifest(source: string | URL, options?: LoadApplicationManifestOptions): Promise<ResolvedApplicationManifest>;
|