@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,492 @@
|
|
|
1
|
+
// OAuth policy envelopes (`kk_oauth`, ADR-0078): a Rego policy over the claims of an
|
|
2
|
+
// organization's own DPoP-bound access token, committed as a slot's rule.
|
|
3
|
+
//
|
|
4
|
+
// TWO HALVES, deliberately different:
|
|
5
|
+
//
|
|
6
|
+
// 1. `isOauthEnvelope` is pure TypeScript. It is the grammar dispatch the rule commitment
|
|
7
|
+
// needs (an envelope is committed in RFC 8785 canonical form, like an OID4VP query), so
|
|
8
|
+
// computing or checking a commitment never has to load WebAssembly. It mirrors
|
|
9
|
+
// `keykeeper_dcql::grammar` byte for byte: one JSON object whose ONLY member is
|
|
10
|
+
// `kk_oauth`, a duplicated `kk_oauth` is NOT an envelope, and a rule longer than
|
|
11
|
+
// MAX_RULE_LEN UTF-8 bytes never is.
|
|
12
|
+
//
|
|
13
|
+
// 2. Everything that reads INSIDE an envelope - pack, unpack, lint (schema + static gate),
|
|
14
|
+
// evaluate - runs the network's own `keykeeper-rego` crate compiled to WebAssembly. There
|
|
15
|
+
// is no TypeScript reimplementation of the gate or the evaluator: the SDK's verdict is the
|
|
16
|
+
// verdict the drawn verifiers and the accountants reach, because it is the same code at the
|
|
17
|
+
// same regorus pin. The shared corpus (test/rego-vectors.json) proves it.
|
|
18
|
+
//
|
|
19
|
+
// The .wasm (~1 MB) is loaded on first use only, from beside this module, and its SHA-256 is
|
|
20
|
+
// checked against the pinned build BEFORE it is instantiated. Nothing here sets a timer:
|
|
21
|
+
// regorus's execution timer panics on wasm32, and on the client the static gate's bounds are
|
|
22
|
+
// the whole bound (it is the caller's own CPU).
|
|
23
|
+
import { TasraError } from '../errors.js';
|
|
24
|
+
import { MAX_RULE_LEN } from './oid4vp.js';
|
|
25
|
+
/** The single top-level member that marks a rule as an OAuth policy envelope. */
|
|
26
|
+
export const OAUTH_ENVELOPE_KEY = 'kk_oauth';
|
|
27
|
+
/** Entrypoint the network's example policies use (`package tasra.slot`). */
|
|
28
|
+
export const DEFAULT_REGO_ENTRYPOINT = 'data.tasra.slot.allow';
|
|
29
|
+
/**
|
|
30
|
+
* The refusal text a holder sees when an envelope's policy denies. Deliberately generic: rule
|
|
31
|
+
* contents are confidential to the operator set, so a refusal never names a claim or clause.
|
|
32
|
+
*/
|
|
33
|
+
export const REGO_POLICY_REFUSED = 'kk_oauth policy refused';
|
|
34
|
+
/**
|
|
35
|
+
* SHA-256 of the vendored `keykeeper_rego_wasm_bg.wasm`, as recorded in its PINS.json.
|
|
36
|
+
* `scripts/check-rego-pins.mjs` asserts the two agree, so this constant cannot drift from the
|
|
37
|
+
* pinned build.
|
|
38
|
+
*/
|
|
39
|
+
export const REGO_WASM_SHA256 = '853cdecd788069b9c881904c67d4c7c2ec340386ae3a76054e0fdcfbfb112f88';
|
|
40
|
+
// ─── grammar dispatch (pure) ─────────────────────────────────────────────────
|
|
41
|
+
/**
|
|
42
|
+
* Whether `rule` is a `kk_oauth` policy envelope: a JSON object whose only member is
|
|
43
|
+
* `kk_oauth`. Structural only - the envelope's contents are not validated (use
|
|
44
|
+
* {@link lintEnvelope}). Total: never throws.
|
|
45
|
+
*
|
|
46
|
+
* Matches the network's grammar dispatch exactly, so the SDK commits an envelope the same way
|
|
47
|
+
* every keeper and verifier re-derives it. A duplicated `kk_oauth` member is not an envelope,
|
|
48
|
+
* and neither is anything longer than `MAX_RULE_LEN` UTF-8 bytes.
|
|
49
|
+
*
|
|
50
|
+
* @param rule - Clear rule text to classify.
|
|
51
|
+
*/
|
|
52
|
+
export function isOauthEnvelope(rule) {
|
|
53
|
+
if (typeof rule !== 'string' || utf8Length(rule) > MAX_RULE_LEN)
|
|
54
|
+
return false;
|
|
55
|
+
return new TopLevelScan(rule).onlyEnvelopeKey();
|
|
56
|
+
}
|
|
57
|
+
/** UTF-8 length of a JS string as `TextEncoder` would encode it (a lone surrogate is 3 bytes). */
|
|
58
|
+
function utf8Length(s) {
|
|
59
|
+
let n = 0;
|
|
60
|
+
for (let i = 0; i < s.length; i++) {
|
|
61
|
+
const c = s.charCodeAt(i);
|
|
62
|
+
if (c < 0x80)
|
|
63
|
+
n += 1;
|
|
64
|
+
else if (c < 0x800)
|
|
65
|
+
n += 2;
|
|
66
|
+
else if (c >= 0xd800 && c <= 0xdbff && i + 1 < s.length && isLowSurrogate(s.charCodeAt(i + 1))) {
|
|
67
|
+
n += 4;
|
|
68
|
+
i++;
|
|
69
|
+
}
|
|
70
|
+
else
|
|
71
|
+
n += 3;
|
|
72
|
+
}
|
|
73
|
+
return n;
|
|
74
|
+
}
|
|
75
|
+
function isLowSurrogate(c) {
|
|
76
|
+
return c >= 0xdc00 && c <= 0xdfff;
|
|
77
|
+
}
|
|
78
|
+
/** Thrown inside the scanner only; {@link isOauthEnvelope} turns it into `false`. */
|
|
79
|
+
class NotJson extends Error {
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* A strict RFC 8259 scanner that reads the top-level object's member NAMES and skips every
|
|
83
|
+
* value without materialising it - the same walk serde_json does for the network's check
|
|
84
|
+
* (`next_key::<Cow<str>>` + `IgnoredAny`). Two details are serde_json's, not JSON.parse's:
|
|
85
|
+
*
|
|
86
|
+
* - a top-level member name is decoded strictly: a `\u` escape naming an unpaired surrogate
|
|
87
|
+
* is an error there, while inside a VALUE any four hex digits are accepted;
|
|
88
|
+
* - values carry no depth limit (serde_json skips ignored values iteratively).
|
|
89
|
+
*/
|
|
90
|
+
class TopLevelScan {
|
|
91
|
+
s;
|
|
92
|
+
i = 0;
|
|
93
|
+
constructor(s) {
|
|
94
|
+
this.s = s;
|
|
95
|
+
}
|
|
96
|
+
onlyEnvelopeKey() {
|
|
97
|
+
try {
|
|
98
|
+
this.ws();
|
|
99
|
+
this.expect(0x7b); // {
|
|
100
|
+
this.ws();
|
|
101
|
+
let members = 0;
|
|
102
|
+
let onlyEnvelope = true;
|
|
103
|
+
if (this.peek() === 0x7d) {
|
|
104
|
+
this.i++;
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
for (;;) {
|
|
108
|
+
this.expect(0x22); // "
|
|
109
|
+
const key = this.string(true);
|
|
110
|
+
this.ws();
|
|
111
|
+
this.expect(0x3a); // :
|
|
112
|
+
this.value();
|
|
113
|
+
members++;
|
|
114
|
+
if (key !== OAUTH_ENVELOPE_KEY)
|
|
115
|
+
onlyEnvelope = false;
|
|
116
|
+
this.ws();
|
|
117
|
+
if (this.peek() === 0x2c) {
|
|
118
|
+
this.i++;
|
|
119
|
+
this.ws();
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
this.expect(0x7d);
|
|
123
|
+
break;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
this.ws();
|
|
127
|
+
if (this.i !== this.s.length)
|
|
128
|
+
return false;
|
|
129
|
+
return onlyEnvelope && members === 1;
|
|
130
|
+
}
|
|
131
|
+
catch (e) {
|
|
132
|
+
if (e instanceof NotJson)
|
|
133
|
+
return false;
|
|
134
|
+
throw e;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
peek() {
|
|
138
|
+
return this.i < this.s.length ? this.s.charCodeAt(this.i) : -1;
|
|
139
|
+
}
|
|
140
|
+
expect(c) {
|
|
141
|
+
if (this.peek() !== c)
|
|
142
|
+
throw new NotJson();
|
|
143
|
+
this.i++;
|
|
144
|
+
}
|
|
145
|
+
ws() {
|
|
146
|
+
for (;;) {
|
|
147
|
+
const c = this.peek();
|
|
148
|
+
if (c === 0x20 || c === 0x0a || c === 0x0d || c === 0x09)
|
|
149
|
+
this.i++;
|
|
150
|
+
else
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
hex4() {
|
|
155
|
+
if (this.i + 4 > this.s.length)
|
|
156
|
+
throw new NotJson();
|
|
157
|
+
const h = this.s.slice(this.i, this.i + 4);
|
|
158
|
+
if (!/^[0-9a-fA-F]{4}$/.test(h))
|
|
159
|
+
throw new NotJson();
|
|
160
|
+
this.i += 4;
|
|
161
|
+
return parseInt(h, 16);
|
|
162
|
+
}
|
|
163
|
+
/** After the opening quote. Returns the decoded text when `decode`, else ''. */
|
|
164
|
+
string(decode) {
|
|
165
|
+
let out = '';
|
|
166
|
+
for (;;) {
|
|
167
|
+
const c = this.peek();
|
|
168
|
+
if (c < 0)
|
|
169
|
+
throw new NotJson();
|
|
170
|
+
this.i++;
|
|
171
|
+
if (c === 0x22)
|
|
172
|
+
return out;
|
|
173
|
+
if (c < 0x20)
|
|
174
|
+
throw new NotJson();
|
|
175
|
+
if (c !== 0x5c) {
|
|
176
|
+
if (decode)
|
|
177
|
+
out += String.fromCharCode(c);
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
const e = this.peek();
|
|
181
|
+
this.i++;
|
|
182
|
+
switch (e) {
|
|
183
|
+
case 0x22:
|
|
184
|
+
out += decode ? '"' : '';
|
|
185
|
+
break;
|
|
186
|
+
case 0x5c:
|
|
187
|
+
out += decode ? '\\' : '';
|
|
188
|
+
break;
|
|
189
|
+
case 0x2f:
|
|
190
|
+
out += decode ? '/' : '';
|
|
191
|
+
break;
|
|
192
|
+
case 0x62:
|
|
193
|
+
out += decode ? '\b' : '';
|
|
194
|
+
break;
|
|
195
|
+
case 0x66:
|
|
196
|
+
out += decode ? '\f' : '';
|
|
197
|
+
break;
|
|
198
|
+
case 0x6e:
|
|
199
|
+
out += decode ? '\n' : '';
|
|
200
|
+
break;
|
|
201
|
+
case 0x72:
|
|
202
|
+
out += decode ? '\r' : '';
|
|
203
|
+
break;
|
|
204
|
+
case 0x74:
|
|
205
|
+
out += decode ? '\t' : '';
|
|
206
|
+
break;
|
|
207
|
+
case 0x75: {
|
|
208
|
+
const n = this.hex4();
|
|
209
|
+
if (!decode)
|
|
210
|
+
break;
|
|
211
|
+
if (isLowSurrogate(n))
|
|
212
|
+
throw new NotJson();
|
|
213
|
+
if (n >= 0xd800 && n <= 0xdbff) {
|
|
214
|
+
if (this.peek() !== 0x5c)
|
|
215
|
+
throw new NotJson();
|
|
216
|
+
this.i++;
|
|
217
|
+
if (this.peek() !== 0x75)
|
|
218
|
+
throw new NotJson();
|
|
219
|
+
this.i++;
|
|
220
|
+
const n2 = this.hex4();
|
|
221
|
+
if (!isLowSurrogate(n2))
|
|
222
|
+
throw new NotJson();
|
|
223
|
+
out += String.fromCharCode(n, n2);
|
|
224
|
+
}
|
|
225
|
+
else
|
|
226
|
+
out += String.fromCharCode(n);
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
default:
|
|
230
|
+
throw new NotJson();
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
digits() {
|
|
235
|
+
const start = this.i;
|
|
236
|
+
while (this.peek() >= 0x30 && this.peek() <= 0x39)
|
|
237
|
+
this.i++;
|
|
238
|
+
return this.i - start;
|
|
239
|
+
}
|
|
240
|
+
number() {
|
|
241
|
+
if (this.peek() === 0x2d)
|
|
242
|
+
this.i++;
|
|
243
|
+
const first = this.peek();
|
|
244
|
+
if (first === 0x30) {
|
|
245
|
+
this.i++;
|
|
246
|
+
}
|
|
247
|
+
else if (first >= 0x31 && first <= 0x39) {
|
|
248
|
+
this.digits();
|
|
249
|
+
}
|
|
250
|
+
else
|
|
251
|
+
throw new NotJson();
|
|
252
|
+
if (this.peek() === 0x2e) {
|
|
253
|
+
this.i++;
|
|
254
|
+
if (this.digits() === 0)
|
|
255
|
+
throw new NotJson();
|
|
256
|
+
}
|
|
257
|
+
if (this.peek() === 0x65 || this.peek() === 0x45) {
|
|
258
|
+
this.i++;
|
|
259
|
+
if (this.peek() === 0x2b || this.peek() === 0x2d)
|
|
260
|
+
this.i++;
|
|
261
|
+
if (this.digits() === 0)
|
|
262
|
+
throw new NotJson();
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
literal(text) {
|
|
266
|
+
if (this.s.startsWith(text, this.i))
|
|
267
|
+
this.i += text.length;
|
|
268
|
+
else
|
|
269
|
+
throw new NotJson();
|
|
270
|
+
}
|
|
271
|
+
/** Skip one value, iteratively (an explicit stack, so nesting depth costs no call stack). */
|
|
272
|
+
value() {
|
|
273
|
+
const stack = [];
|
|
274
|
+
for (;;) {
|
|
275
|
+
this.ws();
|
|
276
|
+
const c = this.peek();
|
|
277
|
+
let opened = false;
|
|
278
|
+
if (c === 0x7b || c === 0x5b) {
|
|
279
|
+
this.i++;
|
|
280
|
+
this.ws();
|
|
281
|
+
const close = c === 0x7b ? 0x7d : 0x5d;
|
|
282
|
+
if (this.peek() === close)
|
|
283
|
+
this.i++;
|
|
284
|
+
else {
|
|
285
|
+
stack.push(c);
|
|
286
|
+
opened = true;
|
|
287
|
+
if (c === 0x7b)
|
|
288
|
+
this.memberName();
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
else if (c === 0x22) {
|
|
292
|
+
this.i++;
|
|
293
|
+
this.string(false);
|
|
294
|
+
}
|
|
295
|
+
else if (c === 0x2d || (c >= 0x30 && c <= 0x39)) {
|
|
296
|
+
this.number();
|
|
297
|
+
}
|
|
298
|
+
else if (c === 0x74)
|
|
299
|
+
this.literal('true');
|
|
300
|
+
else if (c === 0x66)
|
|
301
|
+
this.literal('false');
|
|
302
|
+
else if (c === 0x6e)
|
|
303
|
+
this.literal('null');
|
|
304
|
+
else
|
|
305
|
+
throw new NotJson();
|
|
306
|
+
if (opened)
|
|
307
|
+
continue;
|
|
308
|
+
// A value just ended: close every container it completes.
|
|
309
|
+
for (;;) {
|
|
310
|
+
const top = stack[stack.length - 1];
|
|
311
|
+
if (top === undefined)
|
|
312
|
+
return;
|
|
313
|
+
this.ws();
|
|
314
|
+
const d = this.peek();
|
|
315
|
+
if (d === 0x2c) {
|
|
316
|
+
this.i++;
|
|
317
|
+
if (top === 0x7b) {
|
|
318
|
+
this.ws();
|
|
319
|
+
this.memberName();
|
|
320
|
+
}
|
|
321
|
+
break;
|
|
322
|
+
}
|
|
323
|
+
if (d === (top === 0x7b ? 0x7d : 0x5d)) {
|
|
324
|
+
this.i++;
|
|
325
|
+
stack.pop();
|
|
326
|
+
continue;
|
|
327
|
+
}
|
|
328
|
+
throw new NotJson();
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
/** A nested member name and its colon (names below the top level are not decoded). */
|
|
333
|
+
memberName() {
|
|
334
|
+
this.expect(0x22);
|
|
335
|
+
this.string(false);
|
|
336
|
+
this.ws();
|
|
337
|
+
this.expect(0x3a);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
/** A refused envelope operation: the rule or its authored parts are malformed. */
|
|
341
|
+
export class RegoEnvelopeError extends TasraError {
|
|
342
|
+
/** `malformed` for a schema or gate failure; `reject` never reaches this class. */
|
|
343
|
+
kind;
|
|
344
|
+
constructor(kind, message) {
|
|
345
|
+
super(message, { retryable: false });
|
|
346
|
+
this.kind = kind;
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
let engine;
|
|
350
|
+
/**
|
|
351
|
+
* Load the policy engine once and reuse it. The module's SHA-256 is verified before it is
|
|
352
|
+
* instantiated; a mismatch refuses to load. Concurrent callers share one load.
|
|
353
|
+
*
|
|
354
|
+
* In a bundler that does not emit assets referenced through `new URL(..., import.meta.url)`,
|
|
355
|
+
* pass `wasm` explicitly (bytes or a URL).
|
|
356
|
+
*
|
|
357
|
+
* @param opts - Optional module source and HTTP implementation.
|
|
358
|
+
*/
|
|
359
|
+
export function loadRego(opts = {}) {
|
|
360
|
+
if (engine)
|
|
361
|
+
return engine;
|
|
362
|
+
const loading = instantiate(opts);
|
|
363
|
+
engine = loading;
|
|
364
|
+
loading.catch(() => {
|
|
365
|
+
if (engine === loading)
|
|
366
|
+
engine = undefined;
|
|
367
|
+
});
|
|
368
|
+
return loading;
|
|
369
|
+
}
|
|
370
|
+
async function instantiate(opts) {
|
|
371
|
+
const bytes = await wasmBytes(opts);
|
|
372
|
+
const digest = new Uint8Array(await crypto.subtle.digest('SHA-256', bytes));
|
|
373
|
+
const hex = Array.from(digest, b => b.toString(16).padStart(2, '0')).join('');
|
|
374
|
+
if (hex !== REGO_WASM_SHA256) {
|
|
375
|
+
throw new TasraError(`rego wasm sha256 ${hex} differs from the pinned ${REGO_WASM_SHA256}; refusing to load it`);
|
|
376
|
+
}
|
|
377
|
+
const glue = (await import('./rego/wasm/keykeeper_rego_wasm.js'));
|
|
378
|
+
glue.initSync({ module: bytes });
|
|
379
|
+
return wrap(glue);
|
|
380
|
+
}
|
|
381
|
+
async function wasmBytes(opts) {
|
|
382
|
+
const src = opts.wasm;
|
|
383
|
+
if (src instanceof ArrayBuffer)
|
|
384
|
+
return new Uint8Array(src.slice(0));
|
|
385
|
+
if (ArrayBuffer.isView(src))
|
|
386
|
+
return new Uint8Array(src.buffer.slice(src.byteOffset, src.byteOffset + src.byteLength));
|
|
387
|
+
const url = src === undefined ? new URL('./rego/wasm/keykeeper_rego_wasm_bg.wasm', import.meta.url) : new URL(String(src));
|
|
388
|
+
if (url.protocol === 'file:') {
|
|
389
|
+
// Node reads its own install directly; `getBuiltinModule` keeps any `node:` import out of
|
|
390
|
+
// this module's graph, so browser bundles never see one.
|
|
391
|
+
const fs = globalThis.process?.getBuiltinModule?.('node:fs');
|
|
392
|
+
if (!fs)
|
|
393
|
+
throw new TasraError('loadRego: cannot read a file: URL here; pass `wasm` as bytes or an http(s) URL');
|
|
394
|
+
const b = fs.readFileSync(url);
|
|
395
|
+
return new Uint8Array(b.buffer.slice(b.byteOffset, b.byteOffset + b.byteLength));
|
|
396
|
+
}
|
|
397
|
+
const res = await (opts.fetchImpl ?? fetch)(url);
|
|
398
|
+
if (!res.ok)
|
|
399
|
+
throw new TasraError(`loadRego: fetching ${url.href} answered HTTP ${res.status}`, { retryable: res.status >= 500 });
|
|
400
|
+
return new Uint8Array(await res.arrayBuffer());
|
|
401
|
+
}
|
|
402
|
+
function wrap(glue) {
|
|
403
|
+
// A trap (a panic compiled with panic=abort) leaves the instance in an unknown state, so the
|
|
404
|
+
// cached engine is dropped and the next call loads a fresh one.
|
|
405
|
+
const call = (f) => {
|
|
406
|
+
let text;
|
|
407
|
+
try {
|
|
408
|
+
text = f();
|
|
409
|
+
}
|
|
410
|
+
catch (e) {
|
|
411
|
+
engine = undefined;
|
|
412
|
+
throw new TasraError(`rego engine trapped: ${e instanceof Error ? e.message : String(e)}`, { cause: e });
|
|
413
|
+
}
|
|
414
|
+
return JSON.parse(text);
|
|
415
|
+
};
|
|
416
|
+
const ok = (r) => {
|
|
417
|
+
if (!r.ok)
|
|
418
|
+
throw new RegoEnvelopeError(r.kind, r.message);
|
|
419
|
+
return r;
|
|
420
|
+
};
|
|
421
|
+
return {
|
|
422
|
+
pack(input) {
|
|
423
|
+
const tokens = typeof input.tokens === 'string' ? input.tokens : JSON.stringify(input.tokens);
|
|
424
|
+
return ok(call(() => glue.pack(input.policy, tokens, input.entrypoint ?? DEFAULT_REGO_ENTRYPOINT))).envelope;
|
|
425
|
+
},
|
|
426
|
+
unpack(envelope) {
|
|
427
|
+
const r = ok(call(() => glue.unpack(envelope)));
|
|
428
|
+
return { policy: r.source, tokens: r.tokens, entrypoint: r.entrypoint };
|
|
429
|
+
},
|
|
430
|
+
lint(envelope) {
|
|
431
|
+
const r = ok(call(() => glue.lint(envelope)));
|
|
432
|
+
const g = r.report;
|
|
433
|
+
return {
|
|
434
|
+
report: { package: g.package, rules: g.rules, functions: g.functions, builtins: g.builtins, tokensRead: g.tokens_read, maxIterDepth: g.max_iter_depth },
|
|
435
|
+
admissible: r.admissible === true,
|
|
436
|
+
...(typeof r.admission_error === 'string' ? { admissionError: r.admission_error } : {}),
|
|
437
|
+
};
|
|
438
|
+
},
|
|
439
|
+
evaluate(rule, presentation) {
|
|
440
|
+
const text = typeof presentation === 'string' ? presentation : JSON.stringify(presentation);
|
|
441
|
+
const r = call(() => glue.evaluate(rule, text));
|
|
442
|
+
return r.ok ? { allow: true } : { allow: false, kind: r.kind, message: r.message };
|
|
443
|
+
},
|
|
444
|
+
allowlistV1() {
|
|
445
|
+
return JSON.parse(glue.allowlistV1());
|
|
446
|
+
},
|
|
447
|
+
};
|
|
448
|
+
}
|
|
449
|
+
/**
|
|
450
|
+
* Pack a Rego policy and its token specifications into the canonical (RFC 8785) envelope a
|
|
451
|
+
* slot commits to. The policy source is committed byte for byte - reformatting it is an
|
|
452
|
+
* amendment. Refuses (with {@link RegoEnvelopeError}) anything the static gate refuses.
|
|
453
|
+
*
|
|
454
|
+
* @param policy - Rego v1 module source.
|
|
455
|
+
* @param tokens - Token specifications (object or JSON text). Duplicate keys in JSON text are refused.
|
|
456
|
+
* @param entrypoint - Rule to evaluate; defaults to {@link DEFAULT_REGO_ENTRYPOINT}.
|
|
457
|
+
* @returns The envelope string to pass as the slot's rule.
|
|
458
|
+
*/
|
|
459
|
+
export async function packEnvelope(policy, tokens, entrypoint) {
|
|
460
|
+
return (await loadRego()).pack({ policy, tokens, entrypoint });
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* Take an envelope apart into its exact policy source, tokens and entrypoint.
|
|
464
|
+
* `packEnvelope(unpacked.policy, unpacked.tokens, unpacked.entrypoint)` reproduces it.
|
|
465
|
+
*
|
|
466
|
+
* @param envelope - Envelope rule text.
|
|
467
|
+
*/
|
|
468
|
+
export async function unpackEnvelope(envelope) {
|
|
469
|
+
return (await loadRego()).unpack(envelope);
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Run the schema and static gate and report whether a keeper would store the envelope today.
|
|
473
|
+
* Throws {@link RegoEnvelopeError} when the envelope is malformed; an envelope valid in a later
|
|
474
|
+
* phase but not admissible now returns `admissible: false` with the reason.
|
|
475
|
+
*
|
|
476
|
+
* @param envelope - Envelope rule text.
|
|
477
|
+
*/
|
|
478
|
+
export async function lintEnvelope(envelope) {
|
|
479
|
+
return (await loadRego()).lint(envelope);
|
|
480
|
+
}
|
|
481
|
+
/**
|
|
482
|
+
* Evaluate an envelope against a presentation locally - the same gate and evaluator the
|
|
483
|
+
* network's verifiers run. Advisory: the network still verifies the token, its DPoP proof,
|
|
484
|
+
* its age and audience before any policy runs, which this does not.
|
|
485
|
+
*
|
|
486
|
+
* @param rule - Envelope rule text.
|
|
487
|
+
* @param presentation - Holder and the verified claims of each presented token, or its JSON
|
|
488
|
+
* text passed verbatim (keeps integers beyond 2^53 exact, as the network reads them).
|
|
489
|
+
*/
|
|
490
|
+
export async function evaluateEnvelope(rule, presentation) {
|
|
491
|
+
return (await loadRego()).evaluate(rule, presentation);
|
|
492
|
+
}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/** Verifier-issued bearer JWT with its holder identifier and expiry in Unix seconds. */
|
|
2
|
+
export interface IssuedToken {
|
|
3
|
+
/** The signed JWT (EdDSA) to present to keykeeper-nodes as a Bearer token. */
|
|
4
|
+
token: string;
|
|
5
|
+
/** Expiry, Unix seconds. */
|
|
6
|
+
exp: number;
|
|
7
|
+
/** Subject / holder the token was minted for. */
|
|
8
|
+
holder: string;
|
|
9
|
+
}
|
|
10
|
+
/** Long-lived renewal token, authenticated holder, expiry and authorized scopes. */
|
|
11
|
+
export interface RenewalGrant {
|
|
12
|
+
/** Long-lived token to exchange for fresh JWTs via redeemRenewalToken(). */
|
|
13
|
+
renewalToken: string;
|
|
14
|
+
/** Authenticated holder identifier. */
|
|
15
|
+
holder: string;
|
|
16
|
+
/** Expiry, Unix seconds. */
|
|
17
|
+
expiresAt: number;
|
|
18
|
+
/** Scopes authorized by the renewal grant. */
|
|
19
|
+
scopes: string[];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Create a long-lived renewal from a presentation. On the prod (signed) path,
|
|
23
|
+
* pass `credentials` (compact JWS JWT-VCs) - they're signature-verified and
|
|
24
|
+
* replace the presentation's credentials. `slot_ids` (if given) are rotated via
|
|
25
|
+
* a webhook when the renewal is revoked.
|
|
26
|
+
* POST {verifier}/v1/renewals
|
|
27
|
+
*
|
|
28
|
+
* @param verifierUrl - Verifier HTTP base URL.
|
|
29
|
+
* @param body - Policy, presentation and optional signed credentials or revocation-bound slots.
|
|
30
|
+
*/
|
|
31
|
+
export declare function createRenewal(verifierUrl: string, body: {
|
|
32
|
+
dcql_rule: string;
|
|
33
|
+
presentation: unknown;
|
|
34
|
+
credentials?: string[];
|
|
35
|
+
slot_ids?: string[];
|
|
36
|
+
}): Promise<RenewalGrant>;
|
|
37
|
+
/**
|
|
38
|
+
* Revoke a renewal token - future redeems are denied, and any bound slots get a
|
|
39
|
+
* rotation webhook. POST {verifier}/v1/renewals/revoke {renewal_token}
|
|
40
|
+
*
|
|
41
|
+
* @param verifierUrl - Verifier HTTP base URL.
|
|
42
|
+
* @param renewalToken - Renewal token to revoke.
|
|
43
|
+
*/
|
|
44
|
+
export declare function revokeRenewal(verifierUrl: string, renewalToken: string): Promise<void>;
|
|
45
|
+
/**
|
|
46
|
+
* Redeem a long-lived renewal token for a fresh JWT.
|
|
47
|
+
* POST {verifier}/v1/renewals/redeem {renewal_token}
|
|
48
|
+
*
|
|
49
|
+
* @param verifierUrl - Verifier HTTP base URL.
|
|
50
|
+
* @param renewalToken - Long-lived renewal token to redeem.
|
|
51
|
+
*/
|
|
52
|
+
export declare function redeemRenewalToken(verifierUrl: string, renewalToken: string): Promise<IssuedToken>;
|
|
53
|
+
/**
|
|
54
|
+
* Redeem an admin-issued, single-use credential/invite token for a JWT.
|
|
55
|
+
* POST {verifier}/v1/credentials/redeem {redemption_token, recipient_did}
|
|
56
|
+
*
|
|
57
|
+
* @param verifierUrl - Verifier HTTP base URL.
|
|
58
|
+
* @param redemptionToken - Single-use credential redemption token.
|
|
59
|
+
* @param recipientDid - DID of the recipient redeeming the token.
|
|
60
|
+
*/
|
|
61
|
+
export declare function redeemCredential(verifierUrl: string, redemptionToken: string, recipientDid: string): Promise<IssuedToken>;
|
|
62
|
+
/** Single-use credential redemption token and its expiry in Unix seconds. */
|
|
63
|
+
export interface RedemptionGrant {
|
|
64
|
+
/** Single-use token to exchange for a JWT via redeemCredential(). */
|
|
65
|
+
redemptionToken: string;
|
|
66
|
+
/** Expiry of the redemption token, Unix seconds. */
|
|
67
|
+
expiresAt: number;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Admin-mint a single-use credential (redemption token) for the given scopes.
|
|
71
|
+
* Requires the verifier's admin secret. Pair with redeemCredential() to get a
|
|
72
|
+
* JWT whose `sub` is the recipient DID you pass there.
|
|
73
|
+
* POST {verifier}/v1/admin/credentials/issue (header: X-Admin-Secret)
|
|
74
|
+
*
|
|
75
|
+
* @param verifierUrl - Verifier HTTP base URL.
|
|
76
|
+
* @param adminSecret - Verifier administrative secret; keep it out of browser code and logs.
|
|
77
|
+
* @param opts - Authorized scopes, optional slot bindings and lifetime.
|
|
78
|
+
*/
|
|
79
|
+
export declare function issueAdminCredential(verifierUrl: string, adminSecret: string, opts: {
|
|
80
|
+
scopes: string[];
|
|
81
|
+
slotIds?: string[];
|
|
82
|
+
ttlSecs?: number;
|
|
83
|
+
}): Promise<RedemptionGrant>;
|
|
84
|
+
/**
|
|
85
|
+
* Submit an administrative request to revoke a holder DID's slot access.
|
|
86
|
+
* Rotation is requested by default. A successful HTTP response confirms request
|
|
87
|
+
* acceptance only; callers must confirm the new slot key and epoch before relying
|
|
88
|
+
* on completed rotation. Resolve application handles to DIDs before calling.
|
|
89
|
+
*
|
|
90
|
+
* @param verifierUrl - Verifier HTTP base URL.
|
|
91
|
+
* @param adminSecret - Verifier administrative secret.
|
|
92
|
+
* @param opts - Slot, holder DID, optional rotation request and revocation reason.
|
|
93
|
+
*/
|
|
94
|
+
export declare function revokeSlotUser(verifierUrl: string, adminSecret: string, opts: {
|
|
95
|
+
slotId: string;
|
|
96
|
+
did: string;
|
|
97
|
+
rotate?: boolean;
|
|
98
|
+
reason?: string;
|
|
99
|
+
}): Promise<void>;
|
|
100
|
+
/**
|
|
101
|
+
* Present credentials directly for a JWT. The `body` shape is defined by the
|
|
102
|
+
* verifier (a DCQL rule + a presentation/credentials); we pass it through
|
|
103
|
+
* untouched so this stays agnostic to the credential format.
|
|
104
|
+
* POST {verifier}/v1/verify
|
|
105
|
+
*
|
|
106
|
+
* @param verifierUrl - Verifier HTTP base URL.
|
|
107
|
+
* @param body - Policy and credential presentation for verifier evaluation.
|
|
108
|
+
*/
|
|
109
|
+
export declare function verifyPresentation(verifierUrl: string, body: {
|
|
110
|
+
dcql_rule: string;
|
|
111
|
+
presentation: unknown;
|
|
112
|
+
credentials?: unknown;
|
|
113
|
+
}): Promise<IssuedToken>;
|
|
114
|
+
/**
|
|
115
|
+
* The PRODUCTION credential path: present signed JWT-VCs + holder proof for a
|
|
116
|
+
* DCQL-gated JWT. The verifier checks each credential's signature against its
|
|
117
|
+
* configured trust anchor (by `iss`), that each `sub` equals `holder`, that
|
|
118
|
+
* `holder_proof` proves live control of the holder DID authentication key, then
|
|
119
|
+
* evaluates the rule. `credentials` are compact JWS strings (e.g. from
|
|
120
|
+
* `tasra-cli vc issue`).
|
|
121
|
+
* POST {verifier}/v1/verify-vp-jwt
|
|
122
|
+
*
|
|
123
|
+
* @param verifierUrl - Verifier HTTP base URL.
|
|
124
|
+
* @param body - Policy, holder DID, signed credentials and proof of holder-key possession.
|
|
125
|
+
*/
|
|
126
|
+
export declare function verifyVpJwt(verifierUrl: string, body: {
|
|
127
|
+
dcql_rule: string;
|
|
128
|
+
holder: string;
|
|
129
|
+
credentials: string[];
|
|
130
|
+
holder_proof: string;
|
|
131
|
+
}): Promise<IssuedToken>;
|
|
132
|
+
/** Decoded JWT claims for local inspection. Their presence does not establish signature validity. */
|
|
133
|
+
export interface JwtClaims {
|
|
134
|
+
/** Unverified subject claim. */
|
|
135
|
+
sub?: string;
|
|
136
|
+
/** Unverified issuer claim. */
|
|
137
|
+
iss?: string;
|
|
138
|
+
/** Unverified audience claim. */
|
|
139
|
+
aud?: string;
|
|
140
|
+
/** Unverified expiration time in Unix seconds. */
|
|
141
|
+
exp?: number;
|
|
142
|
+
/** Unverified issue time in Unix seconds. */
|
|
143
|
+
iat?: number;
|
|
144
|
+
/** Unverified scope claim. */
|
|
145
|
+
scope?: string | string[];
|
|
146
|
+
[k: string]: unknown;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Decode JWT claims WITHOUT verifying the signature (for expiry/UX only).
|
|
150
|
+
*
|
|
151
|
+
* @param jwt - Compact JWT to decode without signature verification.
|
|
152
|
+
*/
|
|
153
|
+
export declare function decodeJwtClaims(jwt: string): JwtClaims | null;
|
|
154
|
+
/**
|
|
155
|
+
* Expiry as epoch-ms, or null if absent/unparseable.
|
|
156
|
+
*
|
|
157
|
+
* @param jwt - Compact JWT whose expiration claim will be inspected without verification.
|
|
158
|
+
*/
|
|
159
|
+
export declare function jwtExpMs(jwt: string): number | null;
|
|
160
|
+
/**
|
|
161
|
+
* True when the token is expired or within `skewMs` of expiring.
|
|
162
|
+
*
|
|
163
|
+
* @param jwt - Compact JWT to inspect without signature verification.
|
|
164
|
+
* @param skewMs - Refresh lead time in milliseconds.
|
|
165
|
+
*/
|
|
166
|
+
export declare function isJwtExpiringSoon(jwt: string, skewMs?: number): boolean;
|