@adastracomputing/ink 0.1.0-alpha.3 → 0.1.0-alpha.5

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 (61) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/dist/audit/inclusion-receipt.d.ts +142 -0
  3. package/dist/audit/inclusion-receipt.js +496 -0
  4. package/dist/crypto/ink.d.ts +178 -0
  5. package/dist/crypto/ink.js +915 -0
  6. package/dist/crypto/keys.d.ts +42 -0
  7. package/dist/crypto/keys.js +179 -0
  8. package/dist/crypto/multi-key-verify.d.ts +29 -0
  9. package/dist/crypto/multi-key-verify.js +153 -0
  10. package/dist/crypto/sign.d.ts +17 -0
  11. package/dist/crypto/sign.js +152 -0
  12. package/dist/crypto/verify.js +1 -0
  13. package/dist/discovery/agent-card.d.ts +83 -0
  14. package/dist/discovery/agent-card.js +545 -0
  15. package/dist/index.d.ts +12 -0
  16. package/dist/index.js +15 -0
  17. package/dist/ink/checkpoint.d.ts +19 -0
  18. package/dist/ink/checkpoint.js +69 -0
  19. package/dist/ink/discovery-gating.d.ts +237 -0
  20. package/dist/ink/discovery-gating.js +91 -0
  21. package/dist/ink/handshake-budget.d.ts +90 -0
  22. package/dist/ink/handshake-budget.js +397 -0
  23. package/dist/ink/receipts.d.ts +31 -0
  24. package/dist/ink/receipts.js +89 -0
  25. package/dist/ink/transport-auth.d.ts +47 -0
  26. package/dist/ink/transport-auth.js +77 -0
  27. package/dist/middleware/ink-auth.d.ts +68 -0
  28. package/dist/middleware/ink-auth.js +214 -0
  29. package/dist/models/agent-card.d.ts +154 -0
  30. package/dist/models/agent-card.js +59 -0
  31. package/dist/models/ink-audit.d.ts +344 -0
  32. package/dist/models/ink-audit.js +167 -0
  33. package/dist/models/ink-handshake.d.ts +129 -0
  34. package/dist/models/ink-handshake.js +89 -0
  35. package/dist/models/intent.d.ts +437 -0
  36. package/dist/models/intent.js +172 -0
  37. package/dist/models/key-entry.d.ts +60 -0
  38. package/dist/models/key-entry.js +13 -0
  39. package/dist/models/profile.d.ts +61 -0
  40. package/dist/models/profile.js +24 -0
  41. package/package.json +15 -11
  42. package/src/audit/inclusion-receipt.ts +0 -604
  43. package/src/crypto/ink.ts +0 -1046
  44. package/src/crypto/keys.ts +0 -210
  45. package/src/crypto/multi-key-verify.ts +0 -170
  46. package/src/crypto/sign.ts +0 -155
  47. package/src/discovery/agent-card.ts +0 -508
  48. package/src/index.ts +0 -73
  49. package/src/ink/checkpoint.ts +0 -75
  50. package/src/ink/discovery-gating.ts +0 -147
  51. package/src/ink/handshake-budget.ts +0 -413
  52. package/src/ink/receipts.ts +0 -114
  53. package/src/ink/transport-auth.ts +0 -96
  54. package/src/middleware/ink-auth.ts +0 -263
  55. package/src/models/agent-card.ts +0 -63
  56. package/src/models/ink-audit.ts +0 -205
  57. package/src/models/ink-handshake.ts +0 -123
  58. package/src/models/intent.ts +0 -201
  59. package/src/models/key-entry.ts +0 -52
  60. package/src/models/profile.ts +0 -31
  61. /package/{src/crypto/verify.ts → dist/crypto/verify.d.ts} +0 -0
@@ -0,0 +1,178 @@
1
+ declare function base64urlEncode(bytes: Uint8Array): string;
2
+ declare function base64urlDecode(str: string): Uint8Array;
3
+ declare function hexToBytes(hex: string): Uint8Array;
4
+ declare function bytesToHex(bytes: Uint8Array): string;
5
+ declare function jcsCanonicalize(obj: unknown): string;
6
+ export interface InkSignInput {
7
+ method: string;
8
+ path: string;
9
+ recipientDid: string;
10
+ body: Record<string, unknown>;
11
+ timestamp: string;
12
+ }
13
+ export declare function buildSignatureBase(input: InkSignInput): string;
14
+ /**
15
+ * Sign an INK message. Returns the base64url-encoded Ed25519 signature.
16
+ */
17
+ export declare function signInkMessage(input: InkSignInput, privateKey: Uint8Array): Promise<string>;
18
+ /**
19
+ * Verify an INK message signature.
20
+ * Returns false (never throws) for malformed or wrong-length signatures.
21
+ */
22
+ export declare function verifyInkSignature(input: InkSignInput, signatureBase64url: string, publicKey: Uint8Array): Promise<boolean>;
23
+ /**
24
+ * Build the Authorization header value for an INK request.
25
+ * Optionally includes keyId for key-rotation-aware verification.
26
+ *
27
+ * Both values are validated against the same grammar the receiver uses so that
28
+ * invalid characters (including CR/LF that could cause header injection) are
29
+ * rejected before they reach the HTTP layer.
30
+ */
31
+ export declare function buildAuthHeader(signatureBase64url: string, keyId?: string): string;
32
+ export interface InkEncryptedEnvelope {
33
+ protocol: "ink/0.1";
34
+ type: "network.tulpa.encrypted";
35
+ from: string;
36
+ ephemeralKey: string;
37
+ nonce: string;
38
+ ciphertext: string;
39
+ timestamp: string;
40
+ messageNonce: string;
41
+ }
42
+ export interface InkEncryptResult {
43
+ envelope: InkEncryptedEnvelope;
44
+ ephemeralPublicKey: Uint8Array;
45
+ }
46
+ /**
47
+ * Encrypt an INK message payload using ECIES:
48
+ * 1. Generate ephemeral X25519 keypair (or accept one for deterministic tests)
49
+ * 2. ECDH with recipient's X25519 public key
50
+ * 3. HKDF-SHA256(sharedSecret, salt="ink/0.1", info="ink/0.1/encrypt") → 32-byte AES key
51
+ * 4. AES-256-GCM encrypt the JSON-serialized plaintext
52
+ * 5. Pack into outer envelope
53
+ */
54
+ export declare function encryptInkPayload(plaintext: Record<string, unknown>, senderDid: string, recipientEncryptionKeyHex: string, timestamp: string, messageNonce: string, options?: {
55
+ ephemeralPrivateKey?: Uint8Array;
56
+ aesNonce?: Uint8Array;
57
+ }): Promise<InkEncryptResult>;
58
+ /**
59
+ * Decrypt an INK encrypted envelope using the recipient's X25519 private key.
60
+ * Returns the decrypted inner envelope and verifies inner/outer consistency.
61
+ */
62
+ export declare function decryptInkPayload(envelope: InkEncryptedEnvelope, recipientEncryptionPrivateKeyHex: string, recipientDid?: string): Promise<Record<string, unknown>>;
63
+ export interface ReplayCheckInput {
64
+ messageTimestamp: string;
65
+ receiverClock: string;
66
+ nonce: string;
67
+ previouslySeenNonces: string[];
68
+ }
69
+ export interface ReplayCheckResult {
70
+ accepted: boolean;
71
+ errorCode?: "expired_message" | "duplicate_nonce";
72
+ }
73
+ export declare const MAX_TIMESTAMP_AGE_MS: number;
74
+ export declare const MAX_FUTURE_TIMESTAMP_MS: number;
75
+ /**
76
+ * Check whether an INK message should be accepted or rejected
77
+ * based on timestamp freshness and nonce deduplication (§3.5).
78
+ */
79
+ export declare function checkReplay(input: ReplayCheckInput): ReplayCheckResult;
80
+ /**
81
+ * Compute SHA-256 hash of JCS-canonicalized body. Returns hex string.
82
+ * Used for messageHash in receipts and previousEventHash in audit chains.
83
+ */
84
+ export declare function computeMessageHash(body: Record<string, unknown>): Promise<string>;
85
+ /**
86
+ * Sign an INK audit event. Returns base64url-encoded Ed25519 signature.
87
+ * Signs the JCS-canonicalized event with the agentSignature field excluded.
88
+ */
89
+ export declare function signAuditEvent(event: Record<string, unknown>, privateKey: Uint8Array): Promise<string>;
90
+ /**
91
+ * Verify an INK audit event signature.
92
+ * Returns false (never throws) for malformed or wrong-length signatures.
93
+ */
94
+ export declare function verifyAuditEventSignature(event: Record<string, unknown>, publicKey: Uint8Array): Promise<boolean>;
95
+ /**
96
+ * Compute the RFC 6962 Merkle leaf hash for an INK audit event:
97
+ *
98
+ * SHA-256(0x00 || JCS(event-without-agentSignature))
99
+ *
100
+ * This is the leaf-hashing rule a witness MUST use when building its
101
+ * transparency log (Auditability §7.3). It is distinct from
102
+ * `computeEventHash`, which omits the 0x00 prefix and is used only for
103
+ * `previousEventHash` chain linkage inside the agent's local audit log.
104
+ *
105
+ * Returns the lowercase-hex digest.
106
+ */
107
+ export declare function computeAuditMerkleLeafHash(event: Record<string, unknown>): Promise<string>;
108
+ /**
109
+ * Compute SHA-256 hash of JCS-canonicalized audit event (excluding agentSignature).
110
+ * Used for previousEventHash chain linkage. NOT the Merkle leaf hash:
111
+ * see `computeAuditMerkleLeafHash` for the RFC 6962 leaf-hash rule used
112
+ * by witness transparency logs.
113
+ */
114
+ export declare function computeEventHash(event: Record<string, unknown>): Promise<string>;
115
+ /**
116
+ * Sign an INK audit response. Returns base64url-encoded Ed25519 signature.
117
+ * Domain-separated: signs "ink/audit-response\n" + JCS(events) to prevent
118
+ * cross-protocol signature replay.
119
+ */
120
+ export declare function signAuditResponse(events: unknown[], privateKey: Uint8Array): Promise<string>;
121
+ /**
122
+ * Verify an INK audit response signature.
123
+ * Expects the domain-separated format: "ink/audit-response\n" + JCS(events).
124
+ * Returns false (never throws) for malformed or wrong-length signatures.
125
+ */
126
+ export declare function verifyAuditResponseSignature(events: unknown[], signature: string, publicKey: Uint8Array): Promise<boolean>;
127
+ /**
128
+ * Validate the internal continuity of an audit event chain. Distinct
129
+ * from verifyAuditResponseSignature, which only verifies the response
130
+ * wrapper signature. Callers fetching audit responses MUST call both:
131
+ * the signature gate proves the witness/agent attested to this slice,
132
+ * this gate proves the slice itself is contiguous and fork-free.
133
+ *
134
+ * Rules enforced:
135
+ * - input must be an array of non-null plain objects
136
+ * - each event must have integer sequence and string-or-null previousEventHash
137
+ * - sequences within the response must be strictly increasing by 1
138
+ * (a partial-window response anchored elsewhere is fine, but no internal gaps)
139
+ * - duplicate sequence numbers within the response are a fork
140
+ * - events[i].previousEventHash MUST equal computeEventHash(events[i-1]) for i >= 1
141
+ * - events[0].previousEventHash is NOT verified against any external
142
+ * anchor; callers that have one (a prior pinned event hash) must
143
+ * verify the boundary themselves
144
+ */
145
+ export declare function verifyAuditEventChain(events: unknown): Promise<{
146
+ valid: true;
147
+ } | {
148
+ valid: false;
149
+ error: "invalid_input" | "invalid_event" | "sequence_gap" | "sequence_fork" | "previous_hash_mismatch";
150
+ }>;
151
+ /**
152
+ * Sign an INK audit-query response from a witness. The signed bytes are:
153
+ *
154
+ * "ink/audit-query-response/v1\n" + JCS(response object minus serviceSignature)
155
+ *
156
+ * Callers pass the response object EXCLUDING `serviceSignature`. The
157
+ * canonical bytes bind every other field, including `protocol`, `type`,
158
+ * `messageId`, `events`, `proofs`, `treeSize`, `rootHash`, `serviceDid`,
159
+ * and `timestamp`, so verifiers cannot rebind a valid signature to a
160
+ * different witness/message/root.
161
+ */
162
+ export declare function signAuditQueryResponse(responseWithoutSignature: Record<string, unknown>, privateKey: Uint8Array): Promise<string>;
163
+ /**
164
+ * Verify the Ed25519 signature on an audit-query response. This is the
165
+ * LOW-LEVEL primitive. Most consumers should call
166
+ * `verifyAuditQueryResponse` (from `src/audit/inclusion-receipt.ts`)
167
+ * instead: it enforces envelope shape, requester binding, the
168
+ * events-to-proofs one-to-one mapping, and walks every Merkle proof.
169
+ *
170
+ * Calling this function alone does NOT prove the response is acceptable.
171
+ * A signed but malformed envelope (wrong type, wrong protocol, no
172
+ * proofs, wrong requester) can still pass here. Caller is responsible
173
+ * for pinning / resolving the witness public key out of band (e.g.
174
+ * via /.well-known/did.json). Returns false (never throws) for any
175
+ * malformed input.
176
+ */
177
+ export declare function verifyAuditQueryResponseSignature(responseWithoutSignature: Record<string, unknown>, signature: string, publicKey: Uint8Array): Promise<boolean>;
178
+ export { base64urlEncode, base64urlDecode, hexToBytes, bytesToHex, jcsCanonicalize };