@provian/mcp 0.0.0-stage → 1.2.0

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.
Files changed (101) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/LICENSE +21 -0
  3. package/README.md +264 -2
  4. package/bin/provian-mcp.mjs +18 -0
  5. package/dist/agent-wallet-registration.d.ts +34 -0
  6. package/dist/agent-wallet-registration.d.ts.map +1 -0
  7. package/dist/agent-wallet-registration.js +440 -0
  8. package/dist/agent-wallet-registration.js.map +1 -0
  9. package/dist/core/challenge.d.ts +187 -0
  10. package/dist/core/challenge.d.ts.map +1 -0
  11. package/dist/core/challenge.js +536 -0
  12. package/dist/core/challenge.js.map +1 -0
  13. package/dist/core/crypto.d.ts +44 -0
  14. package/dist/core/crypto.d.ts.map +1 -0
  15. package/dist/core/crypto.js +124 -0
  16. package/dist/core/crypto.js.map +1 -0
  17. package/dist/core/disclosure-request.d.ts +169 -0
  18. package/dist/core/disclosure-request.d.ts.map +1 -0
  19. package/dist/core/disclosure-request.js +400 -0
  20. package/dist/core/disclosure-request.js.map +1 -0
  21. package/dist/core/genesis-offer.d.ts +25 -0
  22. package/dist/core/genesis-offer.d.ts.map +1 -0
  23. package/dist/core/genesis-offer.js +34 -0
  24. package/dist/core/genesis-offer.js.map +1 -0
  25. package/dist/core/harness-tool-vocabulary.d.ts +55 -0
  26. package/dist/core/harness-tool-vocabulary.d.ts.map +1 -0
  27. package/dist/core/harness-tool-vocabulary.js +116 -0
  28. package/dist/core/harness-tool-vocabulary.js.map +1 -0
  29. package/dist/core/keccak256.d.ts +15 -0
  30. package/dist/core/keccak256.d.ts.map +1 -0
  31. package/dist/core/keccak256.js +111 -0
  32. package/dist/core/keccak256.js.map +1 -0
  33. package/dist/core/key-custody.d.ts +33 -0
  34. package/dist/core/key-custody.d.ts.map +1 -0
  35. package/dist/core/key-custody.js +59 -0
  36. package/dist/core/key-custody.js.map +1 -0
  37. package/dist/core/meter-hash.d.ts +2 -0
  38. package/dist/core/meter-hash.d.ts.map +1 -0
  39. package/dist/core/meter-hash.js +8 -0
  40. package/dist/core/meter-hash.js.map +1 -0
  41. package/dist/core/meter-wire.d.ts +193 -0
  42. package/dist/core/meter-wire.d.ts.map +1 -0
  43. package/dist/core/meter-wire.js +418 -0
  44. package/dist/core/meter-wire.js.map +1 -0
  45. package/dist/core/output-signature.d.ts +162 -0
  46. package/dist/core/output-signature.d.ts.map +1 -0
  47. package/dist/core/output-signature.js +367 -0
  48. package/dist/core/output-signature.js.map +1 -0
  49. package/dist/core/presentation.d.ts +141 -0
  50. package/dist/core/presentation.d.ts.map +1 -0
  51. package/dist/core/presentation.js +160 -0
  52. package/dist/core/presentation.js.map +1 -0
  53. package/dist/core/recovery-seal.d.ts +36 -0
  54. package/dist/core/recovery-seal.d.ts.map +1 -0
  55. package/dist/core/recovery-seal.js +122 -0
  56. package/dist/core/recovery-seal.js.map +1 -0
  57. package/dist/core/server.d.ts +38 -0
  58. package/dist/core/server.d.ts.map +1 -0
  59. package/dist/core/server.js +106 -0
  60. package/dist/core/server.js.map +1 -0
  61. package/dist/core/thread-reader.d.ts +8 -0
  62. package/dist/core/thread-reader.d.ts.map +1 -0
  63. package/dist/core/thread-reader.js +47 -0
  64. package/dist/core/thread-reader.js.map +1 -0
  65. package/dist/core/tool-set.d.ts +28 -0
  66. package/dist/core/tool-set.d.ts.map +1 -0
  67. package/dist/core/tool-set.js +71 -0
  68. package/dist/core/tool-set.js.map +1 -0
  69. package/dist/core/tools.d.ts +151 -0
  70. package/dist/core/tools.d.ts.map +1 -0
  71. package/dist/core/tools.js +3621 -0
  72. package/dist/core/tools.js.map +1 -0
  73. package/dist/core/types.d.ts +189 -0
  74. package/dist/core/types.d.ts.map +1 -0
  75. package/dist/core/types.js +17 -0
  76. package/dist/core/types.js.map +1 -0
  77. package/dist/credentials.d.ts +46 -0
  78. package/dist/credentials.d.ts.map +1 -0
  79. package/dist/credentials.js +213 -0
  80. package/dist/credentials.js.map +1 -0
  81. package/dist/device-credentials.d.ts +57 -0
  82. package/dist/device-credentials.d.ts.map +1 -0
  83. package/dist/device-credentials.js +403 -0
  84. package/dist/device-credentials.js.map +1 -0
  85. package/dist/eip191.d.ts +18 -0
  86. package/dist/eip191.d.ts.map +1 -0
  87. package/dist/eip191.js +41 -0
  88. package/dist/eip191.js.map +1 -0
  89. package/dist/index.d.ts +21 -0
  90. package/dist/index.d.ts.map +1 -0
  91. package/dist/index.js +48 -0
  92. package/dist/index.js.map +1 -0
  93. package/dist/runtime-env.d.ts +131 -0
  94. package/dist/runtime-env.d.ts.map +1 -0
  95. package/dist/runtime-env.js +328 -0
  96. package/dist/runtime-env.js.map +1 -0
  97. package/dist/stdio.d.ts +6 -0
  98. package/dist/stdio.d.ts.map +1 -0
  99. package/dist/stdio.js +136 -0
  100. package/dist/stdio.js.map +1 -0
  101. package/package.json +60 -4
@@ -0,0 +1,124 @@
1
+ "use strict";
2
+ /**
3
+ * Agent-key crypto for the MCP tool core.
4
+ *
5
+ * SHARED CORE — canonical in `provian-mcp/src/core/`, mirrored into
6
+ * `provian-backend/src/mcp/core/`. Edit only the canonical copy.
7
+ *
8
+ * Line-for-line ports of the SDK's key handling so the relay accepts
9
+ * signatures from either package interchangeably:
10
+ * - generateAgentKeyPair / signPoPChallenge ← provian-agent-sdk/src/wallet.ts
11
+ * (Node crypto secp256k1 keygen; PoP challenge signed with
12
+ * createSign('SHA256') → DER hex, exactly what
13
+ * POST /v1/agent/wallet/create verifies)
14
+ *
15
+ * Deliberately Node-crypto-only (zero npm deps beyond the vendored keccak):
16
+ * the mirror compiles inside the relay with no new dependencies. EIP-191
17
+ * signing (external-address one-shot linking, local mode only) is NOT here —
18
+ * it is injected by the local stdio server via ToolContext.signEip191; the
19
+ * remote endpoint refuses private-key material by design.
20
+ */
21
+ Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.generateAgentKeyPair = generateAgentKeyPair;
23
+ exports.signPoPChallenge = signPoPChallenge;
24
+ exports.deriveAddressFromPrivateKey = deriveAddressFromPrivateKey;
25
+ exports.derivePublicKeyFromPrivateKey = derivePublicKeyFromPrivateKey;
26
+ const crypto_1 = require("crypto");
27
+ const keccak256_1 = require("./keccak256");
28
+ /**
29
+ * Generate a new secp256k1 key pair using Node.js crypto and derive the
30
+ * EVM address (keccak256 of the raw public key, last 20 bytes).
31
+ */
32
+ function generateAgentKeyPair() {
33
+ const { privateKey, publicKey } = (0, crypto_1.generateKeyPairSync)('ec', {
34
+ namedCurve: 'secp256k1',
35
+ });
36
+ const privKeyDer = privateKey.export({ type: 'sec1', format: 'der' });
37
+ const pubKeyDer = publicKey.export({ type: 'spki', format: 'der' });
38
+ // SEC1 DER: private key OCTET STRING starts at offset 7 (30 xx 02 01 01 04 20)
39
+ const privKeyHex = privKeyDer.subarray(7, 7 + 32).toString('hex');
40
+ // Uncompressed public key = last 65 bytes of SPKI DER; skip the 04 prefix
41
+ const pubKeyRaw = pubKeyDer.subarray(pubKeyDer.length - 65);
42
+ const pubKeyHex = pubKeyRaw.subarray(1).toString('hex');
43
+ const addressHash = (0, keccak256_1.keccak256)(Buffer.from(pubKeyRaw.subarray(1)));
44
+ const address = toChecksumAddress('0x' + addressHash.subarray(12).toString('hex'));
45
+ return { privateKey: privKeyHex, publicKey: pubKeyHex, address };
46
+ }
47
+ /**
48
+ * Sign a wallet-create proof-of-possession challenge with the agent's
49
+ * private key. Plain ECDSA-SHA256 over the challenge string, DER-encoded
50
+ * hex — byte-identical to the SDK's `signMessage` and exactly what the
51
+ * relay's challenge verifier expects.
52
+ */
53
+ function signPoPChallenge(privateKeyHex, challenge) {
54
+ const privKeyBuf = Buffer.from(stripHexPrefix(privateKeyHex), 'hex');
55
+ const privKey = (0, crypto_1.createPrivateKey)({
56
+ key: buildSec1Der(privKeyBuf),
57
+ format: 'der',
58
+ type: 'sec1',
59
+ });
60
+ const signer = (0, crypto_1.createSign)('SHA256');
61
+ signer.update(challenge);
62
+ return signer.sign(privKey, 'hex');
63
+ }
64
+ /** Derive the EIP-55 checksummed EVM address for a hex private key. */
65
+ function deriveAddressFromPrivateKey(privateKeyHex) {
66
+ const pubKeyRaw = Buffer.concat([
67
+ Buffer.from([0x04]),
68
+ Buffer.from(derivePublicKeyFromPrivateKey(privateKeyHex), 'hex'),
69
+ ]);
70
+ const addressHash = (0, keccak256_1.keccak256)(Buffer.from(pubKeyRaw.subarray(1)));
71
+ return toChecksumAddress('0x' + addressHash.subarray(12).toString('hex'));
72
+ }
73
+ /** Derive the 64-byte uncompressed public key (without the 04 prefix). */
74
+ function derivePublicKeyFromPrivateKey(privateKeyHex) {
75
+ const clean = stripHexPrefix(privateKeyHex.trim().toLowerCase());
76
+ if (!/^[0-9a-f]{64}$/.test(clean)) {
77
+ throw new Error('Private key must be 32 bytes (64 hex chars)');
78
+ }
79
+ const privKeyBuf = Buffer.from(clean, 'hex');
80
+ const ecPrivKey = (0, crypto_1.createPrivateKey)({
81
+ key: buildSec1Der(privKeyBuf),
82
+ format: 'der',
83
+ type: 'sec1',
84
+ });
85
+ const ecPubKey = (0, crypto_1.createPublicKey)(ecPrivKey);
86
+ const pubKeyDer = ecPubKey.export({ type: 'spki', format: 'der' });
87
+ const pubKeyRaw = pubKeyDer.subarray(pubKeyDer.length - 65);
88
+ if (pubKeyRaw[0] !== 0x04) {
89
+ throw new Error('Unexpected public key format (expected uncompressed)');
90
+ }
91
+ return pubKeyRaw.subarray(1).toString('hex');
92
+ }
93
+ /** Build a SEC1 DER encoding for a secp256k1 private key. */
94
+ function buildSec1Der(privKeyBytes) {
95
+ // OID for secp256k1: 1.3.132.0.10
96
+ const oid = Buffer.from('06052b8104000a', 'hex');
97
+ const privKeyOctetString = Buffer.concat([
98
+ Buffer.from([0x04, privKeyBytes.length]),
99
+ privKeyBytes,
100
+ ]);
101
+ const oidWrapped = Buffer.concat([Buffer.from([0xa0, oid.length]), oid]);
102
+ const version = Buffer.from([0x02, 0x01, 0x01]);
103
+ const innerLength = version.length + privKeyOctetString.length + oidWrapped.length;
104
+ return Buffer.concat([
105
+ Buffer.from([0x30, innerLength]),
106
+ version,
107
+ privKeyOctetString,
108
+ oidWrapped,
109
+ ]);
110
+ }
111
+ /** EIP-55 checksum address encoding. */
112
+ function toChecksumAddress(address) {
113
+ const addr = address.toLowerCase().replace('0x', '');
114
+ const hash = (0, keccak256_1.keccak256)(Buffer.from(addr, 'utf8')).toString('hex');
115
+ let checksummed = '0x';
116
+ for (let i = 0; i < 40; i++) {
117
+ checksummed += parseInt(hash[i], 16) >= 8 ? addr[i].toUpperCase() : addr[i];
118
+ }
119
+ return checksummed;
120
+ }
121
+ function stripHexPrefix(hex) {
122
+ return hex.startsWith('0x') || hex.startsWith('0X') ? hex.slice(2) : hex;
123
+ }
124
+ //# sourceMappingURL=crypto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"crypto.js","sourceRoot":"","sources":["../../src/core/crypto.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;GAkBG;;AAkBH,oDAmBC;AAQD,4CAWC;AAGD,kEAOC;AAGD,sEAmBC;AAtFD,mCAA4F;AAC5F,2CAAwC;AAWxC;;;GAGG;AACH,SAAgB,oBAAoB;IAClC,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,IAAA,4BAAmB,EAAC,IAAI,EAAE;QAC1D,UAAU,EAAE,WAAW;KACxB,CAAC,CAAC;IAEH,MAAM,UAAU,GAAG,UAAU,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;IACtE,MAAM,SAAS,GAAG,SAAS,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,CAAC;IAEpE,+EAA+E;IAC/E,MAAM,UAAU,GAAG,UAAU,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;I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K,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC;QAC5B,WAAW,IAAI,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC9E,CAAC;IACD,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,SAAS,cAAc,CAAC,GAAW;IACjC,OAAO,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,GAAG,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;AAC3E,CAAC"}
@@ -0,0 +1,169 @@
1
+ /**
2
+ * REQUESTER-NAMED DISCLOSURE — the second part of a signed challenge.
3
+ *
4
+ * Beyond predicates, a signed challenge may NAME what it wants to see from the presenter's own
5
+ * record: a specific PE by one of its output digests (`kind: 'pe'`), or PEs witnessed by a named
6
+ * issuer or signer (`kind: 'witness'`); each request may name specific FIELDS of the record (dotted
7
+ * paths into the act's pricing projection) and elect CONTENT (`description`, `intent`,
8
+ * `artifacts`, `fact_tier`). The predicate grammar is frozen; disclosure requests are a distinct
9
+ * part of the challenge, committed by their own `disclosures=` line in the signing string ONLY
10
+ * when present, so every pre-existing challenge signs byte-identical bytes.
11
+ *
12
+ * The presenter ELECTS per request: `disclosed` (with the matching records it holds, proven to the
13
+ * anchored root) or `declined` (signed as declined). Nothing is disclosed without an election; the
14
+ * floor of every disclosed record is METADATA (pe id, hash, action type, time, the witness facts
15
+ * the relay verified at issuance); fields and content appear only when requested AND elected.
16
+ * Standing is always present (disclosures ride the reputation tier). Disclosures travel only inside
17
+ * the requester-bound presentation; the relay retains nothing; nothing surfaces in the Commons.
18
+ *
19
+ * This module is the single source of the shapes, the canonical forms and the digests. Mirrored
20
+ * byte-for-byte (modulo the hash primitive import) in the SDK (`src/disclosure-request.ts`), the
21
+ * MCP core and the app (`src/core/presentation/disclosureRequest.ts`); the fixed vectors in
22
+ * `disclosure-request.test.ts` are pinned identically in each package.
23
+ */
24
+ export declare const DISCLOSURE_REQUESTS_MAX = 16;
25
+ export declare const DISCLOSURE_FIELDS_MAX = 32;
26
+ export declare const DISCLOSURE_FIELD_PATH_MAX_DEPTH = 6;
27
+ export declare const DISCLOSURE_RECORDS_DEFAULT_LIMIT = 10;
28
+ export declare const DISCLOSURE_RECORDS_MAX_LIMIT = 50;
29
+ /** Every disclosed record of one presentation, across requests. */
30
+ export declare const DISCLOSURE_RECORDS_MAX_TOTAL = 50;
31
+ /** Canonical bytes of one disclosed record (fields + content), a hard cap against a data channel. */
32
+ export declare const DISCLOSURE_RECORD_MAX_BYTES: number;
33
+ export declare const DISCLOSURE_CONTENT_ELECTIONS: readonly ["description", "intent", "artifacts", "fact_tier"];
34
+ export type DisclosureContent = (typeof DISCLOSURE_CONTENT_ELECTIONS)[number];
35
+ export declare const DISCLOSURE_ELECTIONS: readonly ["disclosed", "declined"];
36
+ export type DisclosureElection = (typeof DISCLOSURE_ELECTIONS)[number];
37
+ /** A specific PE named by one of its output digests (or its own pe_hash). */
38
+ export interface PeDisclosureRequest {
39
+ readonly kind: 'pe';
40
+ readonly output_digest: string;
41
+ /** Optional: the witness issuer the record must carry (a credential by digest AND issuer). */
42
+ readonly issuer?: string;
43
+ readonly fields?: readonly string[];
44
+ readonly content?: readonly DisclosureContent[];
45
+ }
46
+ /** PEs witnessed by a named issuer (a pinned root fingerprint, `chain:base`, a forge host) or signer. */
47
+ export interface WitnessDisclosureRequest {
48
+ readonly kind: 'witness';
49
+ readonly issuer?: string;
50
+ readonly signer?: string;
51
+ /** The most records the presenter may disclose for this request (1..50, default 10). */
52
+ readonly limit?: number;
53
+ readonly fields?: readonly string[];
54
+ readonly content?: readonly DisclosureContent[];
55
+ }
56
+ export type DisclosureRequest = PeDisclosureRequest | WitnessDisclosureRequest;
57
+ /** Canonical (sorted, de-duplicated, lowercased) request — the form the signing string commits to. */
58
+ export type CanonicalDisclosureRequest = {
59
+ kind: 'pe';
60
+ output_digest: string;
61
+ issuer?: string;
62
+ fields?: string[];
63
+ content?: DisclosureContent[];
64
+ } | {
65
+ kind: 'witness';
66
+ issuer?: string;
67
+ signer?: string;
68
+ limit: number;
69
+ fields?: string[];
70
+ content?: DisclosureContent[];
71
+ };
72
+ /** The witness facts the relay verified at issuance for a disclosed record. */
73
+ export interface DisclosedWitness {
74
+ /** `hardware` (an admitted non-actor attestation), `chain` (a chain-verified transfer), `device` (the recording device's key). */
75
+ readonly kind: 'hardware' | 'chain' | 'device';
76
+ readonly scheme?: string;
77
+ /** hardware: the pinned root fingerprint reached. chain: `chain:<name>`. */
78
+ readonly issuer?: string;
79
+ /** hardware: sha256(SPKI) of the report signer. device: the device id of the anchored batch. */
80
+ readonly signer?: string;
81
+ /** hardware: the launch measurement / PCR digest. */
82
+ readonly measurement?: string;
83
+ readonly region?: string;
84
+ /** chain: the transaction hash. */
85
+ readonly ref?: string;
86
+ }
87
+ /** One disclosed record: the metadata floor, plus requested fields and elected content. */
88
+ export interface DisclosedRecord {
89
+ readonly pe_id: string;
90
+ readonly pe_hash: string;
91
+ readonly action_type: string;
92
+ readonly timestamp: number;
93
+ readonly witness: DisclosedWitness;
94
+ /** `kind: 'pe'` only: the output digest the request named, as carried by this record. */
95
+ readonly output_digest?: string;
96
+ /** The requested fields at their dotted paths (absent paths are reported as null). */
97
+ readonly fields?: Record<string, unknown>;
98
+ readonly content?: {
99
+ readonly description?: string | null;
100
+ readonly intent?: string | null;
101
+ readonly artifacts?: unknown[];
102
+ readonly fact_tier?: Record<string, unknown>;
103
+ };
104
+ }
105
+ export interface DisclosureAnswer {
106
+ readonly request: CanonicalDisclosureRequest;
107
+ readonly election: DisclosureElection;
108
+ /** Present only on `disclosed`. May be empty: the presenter elected but holds no matching record. */
109
+ readonly records?: readonly DisclosedRecord[];
110
+ }
111
+ /**
112
+ * Canonical JSON (sorted keys, no whitespace, undefined members dropped) — the same rule the meter
113
+ * wire uses, carried here so this module stays dependency-free in every package.
114
+ */
115
+ export declare function canonicalJson(value: unknown): string;
116
+ /** A dotted field path into the pricing projection: 1..6 segments of `[A-Za-z0-9_-]{1,64}`. */
117
+ export declare function isDisclosureFieldPath(path: unknown): path is string;
118
+ /**
119
+ * Parse ONE untrusted disclosure request into its canonical form, fail-closed (`null` on anything
120
+ * malformed: an unknown kind, a digest that is not 64 hex, a witness request naming neither issuer
121
+ * nor signer, a bad field path, an unknown content election, a limit outside 1..50).
122
+ */
123
+ export declare function canonicalDisclosureRequest(raw: unknown): CanonicalDisclosureRequest | null;
124
+ /** The order-independent identity of a request (its canonical JSON). */
125
+ export declare function disclosureRequestKey(req: CanonicalDisclosureRequest): string;
126
+ /**
127
+ * Parse an untrusted request list, fail-closed: `[]` for absent, `null` when it is not a list, is
128
+ * over the cap, carries a malformed entry, or names the same request twice.
129
+ */
130
+ export declare function normalizeDisclosureRequests(raw: unknown): CanonicalDisclosureRequest[] | null;
131
+ /** Two requests are the same when their canonical forms are byte-identical. */
132
+ export declare function disclosureRequestMatches(a: CanonicalDisclosureRequest, b: CanonicalDisclosureRequest): boolean;
133
+ /** sha256 hex of the canonical, sorted request list — the `disclosures=` signing-string commitment. */
134
+ export declare function challengeDisclosuresDigest(requests: readonly CanonicalDisclosureRequest[] | undefined): string;
135
+ /** The canonical, order-independent form of the answers — what the presenter's proof of possession
136
+ * and the Provian signature commit to (elections AND records). */
137
+ export declare function canonicalDisclosureAnswers(answers: readonly DisclosureAnswer[]): DisclosureAnswer[];
138
+ /** sha256 hex of the canonical answers — the `disclosures=` line of the claims digest. */
139
+ export declare function disclosureAnswersDigest(answers: readonly DisclosureAnswer[]): string;
140
+ /** Read a dotted path off a plain object; `null` when any segment is absent. */
141
+ export declare function readFieldPath(source: unknown, path: string): unknown;
142
+ /** Parse an untrusted answer list structurally (elections and record floors); `null` when malformed. */
143
+ export declare function parseDisclosureAnswers(raw: unknown): DisclosureAnswer[] | null;
144
+ /**
145
+ * Does a record satisfy the request it answers? `pe`: the record carries the named digest (and the
146
+ * issuer when named). `witness`: the record's witness carries the named issuer / signer.
147
+ */
148
+ export declare function recordMatchesRequest(record: DisclosedRecord, request: CanonicalDisclosureRequest): boolean;
149
+ /** The floor-only view of a record: no fields, no content — what a declined-content request yields. */
150
+ export declare function recordFloor(record: DisclosedRecord): DisclosedRecord;
151
+ /** The identity-only view of the answers: elections plus `{pe_id, pe_hash}` per disclosed record. */
152
+ export type DisclosureCommitment = {
153
+ request: CanonicalDisclosureRequest;
154
+ election: DisclosureElection;
155
+ records?: {
156
+ pe_id: string;
157
+ pe_hash: string;
158
+ }[];
159
+ };
160
+ /**
161
+ * The PRESENTER'S commitment: what it elected and WHICH records (by id + hash) it put forward —
162
+ * everything the presenter can know before the relay derives the witness facts. Its sha256 is the
163
+ * `disclosures=` line of the claims digest the proof of possession signs; the relay-derived facts,
164
+ * fields and content are covered by the Provian signature over the payload, and a verifier checks
165
+ * every field against the anchored act record itself.
166
+ */
167
+ export declare function disclosureCommitment(answers: readonly DisclosureAnswer[]): DisclosureCommitment[];
168
+ export declare function disclosureCommitmentDigest(answers: readonly DisclosureAnswer[]): string;
169
+ //# sourceMappingURL=disclosure-request.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"disclosure-request.d.ts","sourceRoot":"","sources":["../../src/core/disclosure-request.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAIH,eAAO,MAAM,uBAAuB,KAAK,CAAC;AAC1C,eAAO,MAAM,qBAAqB,KAAK,CAAC;AACxC,eAAO,MAAM,+BAA+B,IAAI,CAAC;AACjD,eAAO,MAAM,gCAAgC,KAAK,CAAC;AACnD,eAAO,MAAM,4BAA4B,KAAK,CAAC;AAC/C,mEAAmE;AACnE,eAAO,MAAM,4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