@ledgerhq/agent-intent-sdk 0.0.0-stage → 0.1.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 (59) hide show
  1. package/LICENSE +202 -0
  2. package/README.md +333 -2
  3. package/dist/auth.d.ts +35 -0
  4. package/dist/auth.d.ts.map +1 -0
  5. package/dist/auth.js +366 -0
  6. package/dist/auth.js.map +1 -0
  7. package/dist/bytes.d.ts +7 -0
  8. package/dist/bytes.d.ts.map +1 -0
  9. package/dist/bytes.js +26 -0
  10. package/dist/bytes.js.map +1 -0
  11. package/dist/client.d.ts +34 -0
  12. package/dist/client.d.ts.map +1 -0
  13. package/dist/client.js +149 -0
  14. package/dist/client.js.map +1 -0
  15. package/dist/completion.d.ts +29 -0
  16. package/dist/completion.d.ts.map +1 -0
  17. package/dist/completion.js +78 -0
  18. package/dist/completion.js.map +1 -0
  19. package/dist/enrollment.d.ts +54 -0
  20. package/dist/enrollment.d.ts.map +1 -0
  21. package/dist/enrollment.js +143 -0
  22. package/dist/enrollment.js.map +1 -0
  23. package/dist/enrollmentChannel.d.ts +85 -0
  24. package/dist/enrollmentChannel.d.ts.map +1 -0
  25. package/dist/enrollmentChannel.js +671 -0
  26. package/dist/enrollmentChannel.js.map +1 -0
  27. package/dist/fingerprint.d.ts +2 -0
  28. package/dist/fingerprint.d.ts.map +1 -0
  29. package/dist/fingerprint.js +36 -0
  30. package/dist/fingerprint.js.map +1 -0
  31. package/dist/identity.d.ts +13 -0
  32. package/dist/identity.d.ts.map +1 -0
  33. package/dist/identity.js +28 -0
  34. package/dist/identity.js.map +1 -0
  35. package/dist/index.d.ts +13 -0
  36. package/dist/index.d.ts.map +1 -0
  37. package/dist/index.js +13 -0
  38. package/dist/index.js.map +1 -0
  39. package/dist/intentPage.d.ts +71 -0
  40. package/dist/intentPage.d.ts.map +1 -0
  41. package/dist/intentPage.js +103 -0
  42. package/dist/intentPage.js.map +1 -0
  43. package/dist/intents.d.ts +93 -0
  44. package/dist/intents.d.ts.map +1 -0
  45. package/dist/intents.js +294 -0
  46. package/dist/intents.js.map +1 -0
  47. package/dist/recovery.d.ts +67 -0
  48. package/dist/recovery.d.ts.map +1 -0
  49. package/dist/recovery.js +188 -0
  50. package/dist/recovery.js.map +1 -0
  51. package/dist/requestFields.d.ts +64 -0
  52. package/dist/requestFields.d.ts.map +1 -0
  53. package/dist/requestFields.js +230 -0
  54. package/dist/requestFields.js.map +1 -0
  55. package/dist/userAgent.d.ts +16 -0
  56. package/dist/userAgent.d.ts.map +1 -0
  57. package/dist/userAgent.js +53 -0
  58. package/dist/userAgent.js.map +1 -0
  59. package/package.json +66 -3
@@ -0,0 +1,294 @@
1
+ import bs58 from "bs58";
2
+ import { AgentIntentSdkError, bytesToHex, concatBytes, hexToBytes } from "./bytes.js";
3
+ import { SIGNATURE_DER, sha256Digest } from "./identity.js";
4
+ /** EVM networks the Agent Intent service accepts a Swap on. */
5
+ export const SWAP_INTENT_NETWORKS = ["ethereum", "ethereum_sepolia", "arc_testnet"];
6
+ const textEncoder = new TextEncoder();
7
+ const U64_MAX = 2n ** 64n - 1n;
8
+ const SOLANA_ADDRESS_MAX_LENGTH = 44;
9
+ export function createNonce(randomBytes = defaultRandomBytes) {
10
+ const nonce = randomBytes(16);
11
+ if (nonce.length !== 16) {
12
+ throw new AgentIntentSdkError("random source must return exactly 16 nonce bytes.");
13
+ }
14
+ return bytesToHex(nonce);
15
+ }
16
+ export function isSolanaSendIntent(intent) {
17
+ return intent.network === "solana" || intent.network === "solana_devnet";
18
+ }
19
+ /**
20
+ * The canonical TLV an agent signs. A Solana send uses the same envelope and
21
+ * payload layout as an EVM one (agent-intent-service ADR-0002): its addresses
22
+ * are the 32 bytes their base58 denotes, it has no `0x15` fee strategy, and it
23
+ * may carry a `0x17` memo.
24
+ */
25
+ export function encodeSendIntentTlv(intent, nonce) {
26
+ return envelope(encodeSend(intent).payload, nonce);
27
+ }
28
+ export function signCreateIntent(identity, intent, nonce = createNonce()) {
29
+ const encoded = encodeSend(intent);
30
+ const tlvBytes = envelope(encoded.payload, nonce);
31
+ return {
32
+ issuer: identity.publicKey,
33
+ signature: bytesToHex(identity.signDigest(sha256Digest(tlvBytes), SIGNATURE_DER)),
34
+ nonce,
35
+ intent: encoded.intent,
36
+ };
37
+ }
38
+ function encodeSend(intent) {
39
+ switch (intent.network) {
40
+ case "ethereum":
41
+ return encodeEvmSend(intent);
42
+ case "solana":
43
+ case "solana_devnet":
44
+ return encodeSolanaSend(intent);
45
+ default: {
46
+ const unsupported = intent;
47
+ throw new AgentIntentSdkError(`unsupported network "${String(unsupported.network)}".`);
48
+ }
49
+ }
50
+ }
51
+ function encodeEvmSend(intent) {
52
+ // An EVM send has no memo; refuse one instead of putting it on the wire unsigned.
53
+ if (intent.memo !== undefined) {
54
+ throw new AgentIntentSdkError("an Ethereum send has no memo.");
55
+ }
56
+ const amount = normalizeAmount(intent.amount);
57
+ const payload = concatBytes(tlv(0x11, evmAddress(intent.sender, "sender")), tlv(0x12, evmAddress(intent.recipient, "recipient")), tlv(0x13, unsignedMinimal(amount)), tlv(0x14, encodeAsset(intent.asset)), tlv(0x15, Uint8Array.of(feeStrategyCode(intent.feeStrategy))), optionalText(0x16, intent.description, "description"), tlv(0x23, utf8(intent.network)));
58
+ return {
59
+ payload,
60
+ intent: {
61
+ ...intent,
62
+ sender: normalizeAddress(intent.sender),
63
+ recipient: normalizeAddress(intent.recipient),
64
+ amount: amount.toString(),
65
+ ...(isTokenAsset(intent.asset)
66
+ ? {
67
+ asset: {
68
+ ...intent.asset,
69
+ assetReference: normalizeAddress(intent.asset.assetReference),
70
+ ...(intent.asset.assetOwner === undefined
71
+ ? {}
72
+ : { assetOwner: normalizeAddress(intent.asset.assetOwner) }),
73
+ },
74
+ }
75
+ : { asset: { type: "native" } }),
76
+ },
77
+ };
78
+ }
79
+ function encodeSolanaSend(intent) {
80
+ if (intent.feeStrategy !== undefined) {
81
+ throw new AgentIntentSdkError("a Solana send has no fee strategy.");
82
+ }
83
+ const amount = normalizeAmount(intent.amount);
84
+ if (amount > U64_MAX)
85
+ throw new AgentIntentSdkError("amount must not exceed u64::MAX.");
86
+ const payload = concatBytes(tlv(0x11, solanaAddress(intent.sender, "sender")), tlv(0x12, solanaAddress(intent.recipient, "recipient")), tlv(0x13, unsignedMinimal(amount)), tlv(0x14, encodeSolanaAsset(intent.asset)), optionalText(0x16, intent.description, "description"), optionalText(0x17, intent.memo, "memo"), tlv(0x23, utf8(intent.network)));
87
+ return {
88
+ payload,
89
+ // The addresses decoded to 32 bytes above, so their spelling is already canonical.
90
+ intent: {
91
+ type: "send",
92
+ network: intent.network,
93
+ sender: intent.sender,
94
+ recipient: intent.recipient,
95
+ amount: amount.toString(),
96
+ asset: isTokenAsset(intent.asset)
97
+ ? { type: "spl-token", assetReference: intent.asset.assetReference }
98
+ : { type: "native" },
99
+ ...(intent.memo === undefined ? {} : { memo: intent.memo }),
100
+ ...(intent.description === undefined ? {} : { description: intent.description }),
101
+ },
102
+ };
103
+ }
104
+ function envelope(payload, nonce, intentType = 0x01) {
105
+ return tlv(0xc1, concatBytes(tlv(0x01, Uint8Array.of(0x01)), tlv(0x02, Uint8Array.of(intentType)), tlv(0x10, payload), tlv(0xda, exactHex(nonce, 16, "nonce"))));
106
+ }
107
+ export function normalizeSwapIntent(intent) {
108
+ if (intent.type !== "swap") {
109
+ throw new AgentIntentSdkError(`expected a swap intent, got type "${String(intent.type)}".`);
110
+ }
111
+ if (!SWAP_INTENT_NETWORKS.includes(intent.network)) {
112
+ throw new AgentIntentSdkError(`unsupported swap network "${String(intent.network)}"; use one of ${SWAP_INTENT_NETWORKS.join(", ")}.`);
113
+ }
114
+ return {
115
+ type: "swap",
116
+ network: intent.network,
117
+ sender: `0x${bytesToHex(evmAddress(intent.sender, "sender"))}`,
118
+ fromAsset: identifier(intent.fromAsset, "fromAsset"),
119
+ toAsset: identifier(intent.toAsset, "toAsset"),
120
+ fromAmount: naturalAmount(intent.fromAmount, "fromAmount"),
121
+ toAmount: naturalAmount(intent.toAmount, "toAmount"),
122
+ provider: identifier(intent.provider, "provider"),
123
+ ...(intent.description === undefined
124
+ ? {}
125
+ : { description: assertBoundedText(intent.description, "description") }),
126
+ };
127
+ }
128
+ export function encodeSwapIntentTlv(intent, nonce) {
129
+ return encodeNormalizedSwapIntentTlv(normalizeSwapIntent(intent), nonce);
130
+ }
131
+ function encodeNormalizedSwapIntentTlv(swap, nonce) {
132
+ const payload = concatBytes(tlv(0x11, evmAddress(swap.sender, "sender")), tlv(0x13, utf8(swap.fromAmount)), tlv(0x14, utf8(swap.fromAsset)), optionalText(0x16, swap.description, "description"), tlv(0x18, utf8(swap.toAsset)), tlv(0x19, utf8(swap.toAmount)), tlv(0x23, utf8(swap.network)), tlv(0x24, utf8(swap.provider)));
133
+ return envelope(payload, nonce, 0x02);
134
+ }
135
+ export function signSwapIntent(identity, intent, nonce = createNonce()) {
136
+ const normalizedIntent = normalizeSwapIntent(intent);
137
+ const tlvBytes = encodeNormalizedSwapIntentTlv(normalizedIntent, nonce);
138
+ return {
139
+ issuer: identity.publicKey,
140
+ signature: bytesToHex(identity.signDigest(sha256Digest(tlvBytes), SIGNATURE_DER)),
141
+ nonce,
142
+ intent: normalizedIntent,
143
+ };
144
+ }
145
+ /**
146
+ * JSON has arbitrary-size integer syntax, but JavaScript numbers do not. This
147
+ * serializer keeps the amount as exact integer digits on the wire.
148
+ */
149
+ export function serializeCreateIntent(request) {
150
+ const marker = "__AGENT_INTENT_EXACT_AMOUNT__";
151
+ const json = JSON.stringify({
152
+ ...request,
153
+ intent: { ...request.intent, amount: marker },
154
+ });
155
+ return json.replace(`"${marker}"`, request.intent.amount);
156
+ }
157
+ function encodeAsset(asset) {
158
+ if (!isTokenAsset(asset))
159
+ return tlv(0x20, utf8("native"));
160
+ if (!asset.type || asset.type === "native") {
161
+ throw new AgentIntentSdkError("token asset type must be non-empty and cannot be native.");
162
+ }
163
+ return concatBytes(tlv(0x20, utf8(asset.type)), tlv(0x21, evmAddress(asset.assetReference, "assetReference")), ...(asset.assetOwner === undefined
164
+ ? []
165
+ : [tlv(0x22, evmAddress(asset.assetOwner, "assetOwner"))]));
166
+ }
167
+ // The service also takes "spl-token-2022", but no client can send one yet.
168
+ function encodeSolanaAsset(asset) {
169
+ if (!isTokenAsset(asset))
170
+ return tlv(0x20, utf8("native"));
171
+ if (asset.type !== "spl-token") {
172
+ throw new AgentIntentSdkError(`a Solana send takes a native or "spl-token" asset, got "${String(asset.type)}".`);
173
+ }
174
+ if (asset.assetOwner !== undefined) {
175
+ throw new AgentIntentSdkError("an SPL token asset has no assetOwner.");
176
+ }
177
+ return concatBytes(tlv(0x20, utf8(asset.type)), tlv(0x21, solanaAddress(asset.assetReference, "assetReference")));
178
+ }
179
+ function isTokenAsset(asset) {
180
+ return asset.type !== "native";
181
+ }
182
+ function feeStrategyCode(strategy) {
183
+ switch (strategy) {
184
+ case "slow":
185
+ return 0x01;
186
+ case "medium":
187
+ return 0x02;
188
+ case "fast":
189
+ return 0x03;
190
+ }
191
+ }
192
+ function tlv(tag, value) {
193
+ return concatBytes(Uint8Array.of(tag), derLength(value.length), value);
194
+ }
195
+ function derLength(length) {
196
+ if (!Number.isSafeInteger(length) || length < 0) {
197
+ throw new AgentIntentSdkError("TLV length must be a non-negative safe integer.");
198
+ }
199
+ if (length < 0x80)
200
+ return Uint8Array.of(length);
201
+ const bytes = [];
202
+ for (let remaining = length; remaining > 0; remaining = Math.floor(remaining / 256)) {
203
+ bytes.unshift(remaining & 0xff);
204
+ }
205
+ if (bytes.length > 4)
206
+ throw new AgentIntentSdkError("TLV value is too long.");
207
+ return Uint8Array.of(0x80 | bytes.length, ...bytes);
208
+ }
209
+ function unsignedMinimal(value) {
210
+ if (value === 0n)
211
+ return Uint8Array.of(0);
212
+ let hex = value.toString(16);
213
+ if (hex.length % 2 !== 0)
214
+ hex = `0${hex}`;
215
+ return hexToBytes(hex);
216
+ }
217
+ /** The service's `Amount` is a positive integer on every network. */
218
+ function normalizeAmount(value) {
219
+ const text = typeof value === "bigint" ? value.toString() : value;
220
+ if (!/^[1-9][0-9]*$/.test(text)) {
221
+ throw new AgentIntentSdkError("amount must be a positive decimal integer.");
222
+ }
223
+ return BigInt(text);
224
+ }
225
+ function normalizeAddress(value) {
226
+ return bytesToHex(evmAddress(value, "address"));
227
+ }
228
+ /**
229
+ * The 32 bytes a Solana address denotes. Base58 maps text to bytes one to one
230
+ * (each leading `1` is a leading zero byte), so any text that decodes to exactly
231
+ * 32 bytes is the canonical spelling the service re-encodes and stores.
232
+ */
233
+ function solanaAddress(value, label) {
234
+ // 32 bytes take at most 44 base58 digits; longer text never reaches the slow decoder.
235
+ if (value.length > SOLANA_ADDRESS_MAX_LENGTH) {
236
+ throw new AgentIntentSdkError(`${label} must be a 32-byte base58 address.`);
237
+ }
238
+ let decoded;
239
+ try {
240
+ decoded = bs58.decode(value);
241
+ }
242
+ catch {
243
+ throw new AgentIntentSdkError(`${label} must be base58.`);
244
+ }
245
+ if (decoded.length !== 32) {
246
+ throw new AgentIntentSdkError(`${label} must be a 32-byte base58 address.`);
247
+ }
248
+ return decoded;
249
+ }
250
+ function evmAddress(value, label) {
251
+ return exactHex(value, 20, label);
252
+ }
253
+ function exactHex(value, bytes, label) {
254
+ const decoded = hexToBytes(value, label);
255
+ if (decoded.length !== bytes) {
256
+ throw new AgentIntentSdkError(`${label} must contain exactly ${bytes} bytes.`);
257
+ }
258
+ return decoded;
259
+ }
260
+ // The service's `NaturalAmount`: positive decimal text, no sign, exponent or leading zeros.
261
+ const NATURAL_AMOUNT = /^(?!0(?:\.0+)?$)(?:0|[1-9][0-9]*)(?:\.[0-9]+)?$/;
262
+ function naturalAmount(value, label) {
263
+ if (!NATURAL_AMOUNT.test(value)) {
264
+ throw new AgentIntentSdkError(`${label} must be a positive decimal such as 0.1 or 2000, with no sign, exponent or spaces.`);
265
+ }
266
+ return value;
267
+ }
268
+ /**
269
+ * The service bounds a description and a memo with `MaxLength[280]` on a JVM
270
+ * `String`, which counts UTF-16 code units, as `String.length` does here: a
271
+ * character outside the Basic Multilingual Plane (most emoji) counts twice.
272
+ */
273
+ function assertBoundedText(value, label) {
274
+ if (value.length < 1 || value.length > 280) {
275
+ throw new AgentIntentSdkError(`${label} must contain between 1 and 280 UTF-16 code units.`);
276
+ }
277
+ return value;
278
+ }
279
+ function optionalText(tag, value, label) {
280
+ return value === undefined ? new Uint8Array() : tlv(tag, utf8(assertBoundedText(value, label)));
281
+ }
282
+ function identifier(value, label) {
283
+ if (value.length === 0 || value !== value.trim()) {
284
+ throw new AgentIntentSdkError(`${label} must be non-empty with no surrounding whitespace.`);
285
+ }
286
+ return value;
287
+ }
288
+ function utf8(value) {
289
+ return textEncoder.encode(value.normalize("NFC"));
290
+ }
291
+ function defaultRandomBytes(length) {
292
+ return globalThis.crypto.getRandomValues(new Uint8Array(length));
293
+ }
294
+ //# sourceMappingURL=intents.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"intents.js","sourceRoot":"","sources":["../src/intents.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACtF,OAAO,EAAE,aAAa,EAAE,YAAY,EAAsB,MAAM,eAAe,CAAC;AA8DhF,+DAA+D;AAC/D,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,UAAU,EAAE,kBAAkB,EAAE,aAAa,CAAU,CAAC;AAuB7F,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAC;AACtC,MAAM,OAAO,GAAG,EAAE,IAAI,GAAG,GAAG,EAAE,CAAC;AAC/B,MAAM,yBAAyB,GAAG,EAAE,CAAC;AAErC,MAAM,UAAU,WAAW,CACzB,WAAW,GAAmC,kBAAkB;IAEhE,MAAM,KAAK,GAAG,WAAW,CAAC,EAAE,CAAC,CAAC;IAC9B,IAAI,KAAK,CAA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iBAAiB,CAAC,KAAa,EAAE,KAAa;IACrD,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,KAAK,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC;QAC3C,MAAM,IAAI,mBAAmB,CAAC,GAAG,KAAK,oDAAoD,CAAC,CAAC;IAC9F,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,YAAY,CAAC,GAAW,EAAE,KAAyB,EAAE,KAAa;IACzE,OAAO,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,UAAU,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,iBAAiB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;AAClG,CAAC;AAED,SAAS,UAAU,CAAC,KAAa,EAAE,KAAa;IAC9C,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,KAAK,KAAK,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC;QACjD,MAAM,IAAI,mBAAmB,CAAC,GAAG,KAAK,oDAAoD,CAAC,CAAC;IAC9F,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,SAAS,IAAI,CAAC,KAAa;IACzB,OAAO,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,CAAC;AACpD,CAAC;AAED,SAAS,kBAAkB,CAAC,MAAc;IACxC,OAAO,UAAU,CAAC,MAAM,CAAC,eAAe,CAAC,IAAI,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC;AACnE,CAAC"}
@@ -0,0 +1,67 @@
1
+ import { type AgentEnrollmentChannelBinding, type AgentEnrollmentRequest, type AgentEnrollmentValidation, type AgentSource } from "./enrollment.ts";
2
+ import { type AgentIdentity } from "./identity.ts";
3
+ export declare const AGENT_RECOVERY_VERSION = "3";
4
+ export declare const AGENT_RECOVERY_COMPLETION_VERSION = 3;
5
+ /**
6
+ * Agent sources that may re-enroll an existing identity into its previous App-18 Trustchain: every
7
+ * supported agent source. Recovery never depends on the source; it is only a signed field.
8
+ */
9
+ export declare const SUPPORTED_AGENT_RECOVERY_SOURCES: readonly ["openclaw", "hermes", "claude-code", "codex", "cursor", "muse", "grok-bot", "other"];
10
+ /** Agent source that may sign a recovery request. */
11
+ export type AgentRecoverySource = AgentSource;
12
+ /**
13
+ * Signed request to re-enroll an existing agent key into its previous App-18
14
+ * Trustchain. When `channel` is present it is covered by the signature and the
15
+ * completion is delivered over the encrypted enrollment channel.
16
+ */
17
+ export type AgentRecoveryRequest = {
18
+ version: typeof AGENT_RECOVERY_VERSION;
19
+ recovery: true;
20
+ publicKey: string;
21
+ name: string;
22
+ description: string;
23
+ source: AgentRecoverySource;
24
+ previousTrustchainId: string;
25
+ expiresAt: string;
26
+ channel?: AgentEnrollmentChannelBinding;
27
+ signature: string;
28
+ };
29
+ /** A recovery request whose signature binds an enrollment channel host. */
30
+ export type AgentRecoveryChannelRequest = AgentRecoveryRequest & {
31
+ channel: AgentEnrollmentChannelBinding;
32
+ };
33
+ export type AgentRecoveryRequestInput = {
34
+ name: string;
35
+ description: string;
36
+ source: AgentRecoverySource;
37
+ previousTrustchainId: string;
38
+ expiresAt: string;
39
+ channel?: AgentEnrollmentChannelBinding;
40
+ };
41
+ export type AgentRecoveryCompletion = {
42
+ version: typeof AGENT_RECOVERY_COMPLETION_VERSION;
43
+ recovery: true;
44
+ agentPubkey: string;
45
+ previousTrustchainId: string;
46
+ requestSignature: string;
47
+ trustchainId: string;
48
+ };
49
+ export type AgentRecoveryValidation = {
50
+ status: "valid";
51
+ request: AgentRecoveryRequest;
52
+ } | Extract<AgentEnrollmentValidation, {
53
+ status: "invalid";
54
+ }>;
55
+ export declare function isAgentRecoverySource(value: unknown): value is AgentRecoverySource;
56
+ export declare function isAgentRecoveryRequest(request: AgentEnrollmentRequest | AgentRecoveryRequest): request is AgentRecoveryRequest;
57
+ export declare function canonicalAgentRecoveryPayload(request: Omit<AgentRecoveryRequest, "signature">): Uint8Array;
58
+ export declare function createAgentRecoveryRequest(identity: AgentIdentity, input: AgentRecoveryRequestInput & {
59
+ channel: AgentEnrollmentChannelBinding;
60
+ }): AgentRecoveryChannelRequest;
61
+ export declare function createAgentRecoveryRequest(identity: AgentIdentity, input: AgentRecoveryRequestInput): AgentRecoveryRequest;
62
+ export declare function agentRecoverySearch(request: AgentRecoveryRequest): Record<string, string>;
63
+ export declare function createAgentRecoveryUrl(baseUrl: string, request: AgentRecoveryRequest): string;
64
+ export declare function validateAgentRecovery(search: Record<string, unknown>, now?: Date): AgentRecoveryValidation;
65
+ export declare function serializeAgentRecoveryCompletion(completion: Omit<AgentRecoveryCompletion, "version" | "recovery">): string;
66
+ export declare function parseAgentRecoveryCompletion(payload: string, expectedAgentPubkey: string, expectedPreviousTrustchainId: string, expectedRequestSignature: string): AgentRecoveryCompletion;
67
+ //# sourceMappingURL=recovery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recovery.d.ts","sourceRoot":"","sources":["../src/recovery.ts"],"names":[],"mappings":"AAEA,OAAO,EAGL,KAAK,6BAA6B,EAClC,KAAK,sBAAsB,EAC3B,KAAK,yBAAyB,EAC9B,KAAK,WAAW,EACjB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAmC,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAQpF,eAAO,MAAM,sBAAsB,MAAM,CAAC;AAC1C,eAAO,MAAM,iCAAiC,IAAI,CAAC;AACnD;;;GAGG;AACH,eAAO,MAAM,gCAAgC,gGAA0B,CAAC;AAExE,qDAAqD;AACrD,MAAM,MAAM,mBAAmB,GAAG,WAAW,CAAC;AAE9C;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,OAAO,EAAE,OAAO,sBAAsB,CAAC;IACvC,QAAQ,EAAE,IAAI,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAA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,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,aAAa,EACvB,KAAK,EAAE,yBAAyB,GAAG;IAAE,OAAO,EAAE,6BAA6B,CAAA;CAAE,GAC5E,2BAA2B,CAAC;AAC/B,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,aAAa,EACvB,KAAK,EAAE,yBAAyB,GAC/B,oBAAoB,CAAC;AAgCxB,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAkBzF;AAED,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,oBAAoB,GAAG,MAAM,CAI7F;AAED,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,GAAG,OAAa,GACf,uBAAuB,CA0CzB;AAED,wBAAgB,gCAAgC,CAC9C,UAAU,EAAE,IAAI,CAAC,uBAAuB,EAAE,SAAS,GAAG,UAAU,CAAC,GAChE,MAAM,CAcR;AAED,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,MAAM,EACf,mBAAmB,EAAE,MAAM,EAC3B,4BAA4B,EAAE,MAAM,EACpC,wBAAwB,EAAE,MAAM,GAC/B,uBAAuB,CA+CzB"}
@@ -0,0 +1,188 @@
1
+ import { secp256k1 } from "@noble/curves/secp256k1.js";
2
+ import { AgentIntentSdkError, bytesToHex, hexToBytes } from "./bytes.js";
3
+ import { isAgentSource, SUPPORTED_AGENT_SOURCES, } from "./enrollment.js";
4
+ import { SIGNATURE_COMPACT, sha256Digest } from "./identity.js";
5
+ import { checkRecoveryLink, malformedLink, malformedLinkMessage, } from "./requestFields.js";
6
+ export const AGENT_RECOVERY_VERSION = "3";
7
+ export const AGENT_RECOVERY_COMPLETION_VERSION = 3;
8
+ /**
9
+ * Agent sources that may re-enroll an existing identity into its previous App-18 Trustchain: every
10
+ * supported agent source. Recovery never depends on the source; it is only a signed field.
11
+ */
12
+ export const SUPPORTED_AGENT_RECOVERY_SOURCES = SUPPORTED_AGENT_SOURCES;
13
+ const encoder = new TextEncoder();
14
+ export function isAgentRecoverySource(value) {
15
+ return isAgentSource(value);
16
+ }
17
+ export function isAgentRecoveryRequest(request) {
18
+ return request.version === AGENT_RECOVERY_VERSION;
19
+ }
20
+ export function canonicalAgentRecoveryPayload(request) {
21
+ return encoder.encode(`agent-intent:agent-recovery:v2\n${JSON.stringify({
22
+ v: request.version,
23
+ recovery: true,
24
+ publicKey: request.publicKey.toLowerCase(),
25
+ name: request.name,
26
+ description: request.description,
27
+ source: request.source,
28
+ previousTrustchainId: request.previousTrustchainId,
29
+ expiresAt: request.expiresAt,
30
+ // Omitted from the JSON when absent so unbound recovery bytes stay unchanged.
31
+ channelEnvironment: request.channel?.environment,
32
+ channelHost: request.channel?.hostPublicKey.toLowerCase(),
33
+ })}`);
34
+ }
35
+ export function createAgentRecoveryRequest(identity, input) {
36
+ const unsigned = {
37
+ version: AGENT_RECOVERY_VERSION,
38
+ recovery: true,
39
+ publicKey: identity.publicKey.toLowerCase(),
40
+ name: input.name,
41
+ description: input.description,
42
+ source: input.source,
43
+ previousTrustchainId: input.previousTrustchainId,
44
+ expiresAt: input.expiresAt,
45
+ ...(input.channel === undefined
46
+ ? {}
47
+ : {
48
+ channel: {
49
+ environment: input.channel.environment,
50
+ hostPublicKey: input.channel.hostPublicKey.toLowerCase(),
51
+ },
52
+ }),
53
+ };
54
+ assertRecoveryFields(unsigned);
55
+ return {
56
+ ...unsigned,
57
+ signature: bytesToHex(identity.signDigest(sha256Digest(canonicalAgentRecoveryPayload(unsigned)), SIGNATURE_COMPACT)),
58
+ };
59
+ }
60
+ export function agentRecoverySearch(request) {
61
+ return {
62
+ v: request.version,
63
+ recovery: String(request.recovery),
64
+ publicKey: request.publicKey,
65
+ name: request.name,
66
+ description: request.description,
67
+ source: request.source,
68
+ previousTrustchainId: request.previousTrustchainId,
69
+ expiresAt: request.expiresAt,
70
+ ...(request.channel === undefined
71
+ ? {}
72
+ : {
73
+ channelEnvironment: request.channel.environment,
74
+ channelHost: request.channel.hostPublicKey,
75
+ }),
76
+ signature: request.signature,
77
+ };
78
+ }
79
+ export function createAgentRecoveryUrl(baseUrl, request) {
80
+ const url = new URL("/agents/new", baseUrl);
81
+ url.search = new URLSearchParams(agentRecoverySearch(request)).toString();
82
+ return url.toString();
83
+ }
84
+ export function validateAgentRecovery(search, now = new Date()) {
85
+ const checked = checkRecoveryLink(search, AGENT_RECOVERY_VERSION);
86
+ if ("issues" in checked) {
87
+ return malformedLink(malformedLinkMessage("agent recovery", checked.issues), checked.issues);
88
+ }
89
+ const unchecked = {
90
+ version: AGENT_RECOVERY_VERSION,
91
+ recovery: true,
92
+ ...checked.fields,
93
+ };
94
+ const { source } = unchecked;
95
+ if (!isAgentRecoverySource(source)) {
96
+ return invalid("unsupported-source", "This agent source is not supported.");
97
+ }
98
+ const request = { ...unchecked, source };
99
+ const expiration = Date.parse(request.expiresAt);
100
+ if (!Number.isFinite(expiration)) {
101
+ const issues = [{ field: "expiresAt", problem: "invalid-value" }];
102
+ return malformedLink(malformedLinkMessage("agent recovery", issues), issues);
103
+ }
104
+ if (expiration <= now.getTime()) {
105
+ return invalid("expired", "This agent recovery link has expired.");
106
+ }
107
+ try {
108
+ const verified = secp256k1.verify(hexToBytes(request.signature), canonicalAgentRecoveryPayload(request), hexToBytes(request.publicKey), { prehash: true, lowS: false, format: "compact" });
109
+ return verified
110
+ ? { status: "valid", request }
111
+ : invalid("invalid-signature", "This agent recovery link has been changed or is not authentic.");
112
+ }
113
+ catch {
114
+ return invalid("invalid-signature", "This agent recovery link has been changed or is not authentic.");
115
+ }
116
+ }
117
+ export function serializeAgentRecoveryCompletion(completion) {
118
+ assertCompletionFields(completion);
119
+ return JSON.stringify({
120
+ version: AGENT_RECOVERY_COMPLETION_VERSION,
121
+ recovery: true,
122
+ agentPubkey: completion.agentPubkey,
123
+ previousTrustchainId: completion.previousTrustchainId,
124
+ requestSignature: completion.requestSignature,
125
+ trustchainId: completion.trustchainId,
126
+ }, null, 2);
127
+ }
128
+ export function parseAgentRecoveryCompletion(payload, expectedAgentPubkey, expectedPreviousTrustchainId, expectedRequestSignature) {
129
+ let value;
130
+ try {
131
+ value = JSON.parse(payload);
132
+ }
133
+ catch {
134
+ throw new AgentIntentSdkError("Agent recovery completion must be valid JSON.");
135
+ }
136
+ if (typeof value !== "object" ||
137
+ value === null ||
138
+ Array.isArray(value) ||
139
+ Object.keys(value).sort().join(",") !==
140
+ "agentPubkey,previousTrustchainId,recovery,requestSignature,trustchainId,version") {
141
+ throw malformedCompletion();
142
+ }
143
+ const completion = value;
144
+ if (completion.version !== AGENT_RECOVERY_COMPLETION_VERSION ||
145
+ completion.recovery !== true ||
146
+ typeof completion.agentPubkey !== "string" ||
147
+ typeof completion.previousTrustchainId !== "string" ||
148
+ typeof completion.requestSignature !== "string" ||
149
+ typeof completion.trustchainId !== "string") {
150
+ throw malformedCompletion();
151
+ }
152
+ assertCompletionFields(completion);
153
+ if (completion.agentPubkey.toLowerCase() !== expectedAgentPubkey.toLowerCase()) {
154
+ throw new AgentIntentSdkError("Agent recovery completion does not match the existing agent identity.");
155
+ }
156
+ if (completion.previousTrustchainId !== expectedPreviousTrustchainId) {
157
+ throw new AgentIntentSdkError("Agent recovery completion does not match the profile's previous Trustchain.");
158
+ }
159
+ if (completion.trustchainId !== expectedPreviousTrustchainId) {
160
+ throw new AgentIntentSdkError("Agent recovery completion returned an unrelated Trustchain.");
161
+ }
162
+ if (completion.requestSignature.toLowerCase() !== expectedRequestSignature.toLowerCase()) {
163
+ throw new AgentIntentSdkError("Agent recovery completion does not match the pending signed recovery request.");
164
+ }
165
+ return completion;
166
+ }
167
+ function assertRecoveryFields(request) {
168
+ // Also rejects unsupported sources passed by untyped JavaScript callers.
169
+ const validation = validateAgentRecovery(agentRecoverySearch({ ...request, signature: "00".repeat(64) }));
170
+ if (validation.status === "invalid" && validation.reason !== "invalid-signature") {
171
+ throw new AgentIntentSdkError(validation.message);
172
+ }
173
+ }
174
+ function assertCompletionFields(completion) {
175
+ if (!completion.agentPubkey ||
176
+ !completion.previousTrustchainId ||
177
+ !completion.requestSignature ||
178
+ !completion.trustchainId) {
179
+ throw malformedCompletion();
180
+ }
181
+ }
182
+ function malformedCompletion() {
183
+ return new AgentIntentSdkError("Agent recovery completion is malformed.");
184
+ }
185
+ function invalid(reason, message) {
186
+ return { status: "invalid", reason, message };
187
+ }
188
+ //# sourceMappingURL=recovery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"recovery.js","sourceRoot":"","sources":["../src/recovery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AACzE,OAAO,EACL,aAAa,EACb,uBAAuB,GAKxB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAsB,MAAM,eAAe,CAAC;AACpF,OAAO,EACL,iBAAiB,EACjB,aAAa,EACb,oBAAoB,GAErB,MAAM,oBAAoB,CAAC;AAE5B,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAG,CAAC;AAC1C,MAAM,CAAC,MAAM,iCAAiC,GAAG,CAAC,CAAC;AACnD;;;GAGG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAAG,uBAAuB,CAAC;AAqDxE,MAAM,OAAO,GAAG,IAAI,WAAW,EAAE,CAAC;AAElC,MAAM,UAAU,qBAAqB,CAAC,KAAc;IAClD,OAAO,aAAa,CAAC,KAAK,CAAC,CAAC;AAC9B,CAAC;AAED,MAAM,UAAU,sBAAsB,CACpC,OAAsD;IAEtD,OAAO,OAAO,CAAC,OAAO,KAAK,sBAAsB,CAAC;AACpD,CAAC;AAED,MAAM,UAAU,6BAA6B,CAC3C,OAAgD;IAEhD,OAAO,OAAO,CAAC,MAAM,CACnB,mCAAmC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,MAAM,IAAI,mBAAmB,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IACpD,CAAC;AACH,CAAC;AAED,SAAS,sBAAsB,CAC7B,UAAiE;IAEjE,IACE,CAAC,UAAU,CAAC,WAAW;QACvB,CAAC,UAAU,CAAC,oBAAoB;QAChC,CAAC,UAAU,CAAC,gBAAgB;QAC5B,CAAC,UAAU,CAAC,YAAY,EACxB,CAAC;QACD,MAAM,mBAAmB,EAAE,CAAC;IAC9B,CAAC;AACH,CAAC;AAED,SAAS,mBAAmB;IAC1B,OAAO,IAAI,mBAAmB,CAAC,yCAAyC,CAAC,CAAC;AAC5E,CAAC;AAED,SAAS,OAAO,CACd,MAA+F,EAC/F,OAAe;IAEf,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC;AAChD,CAAC"}
@@ -0,0 +1,64 @@
1
+ export declare const AGENT_NAME_MAX_LENGTH = 80;
2
+ export declare const AGENT_DESCRIPTION_MAX_LENGTH = 280;
3
+ declare const AGENT_LINK_HEX_LENGTHS: {
4
+ readonly publicKey: readonly [66, 130];
5
+ readonly signature: readonly [128];
6
+ readonly channelHost: readonly [66];
7
+ };
8
+ declare const AGENT_LINK_FIELDS: readonly ["v", "recovery", "publicKey", "name", "description", "source", "previousTrustchainId", "expiresAt", "channelEnvironment", "channelHost", "signature"];
9
+ export type AgentLinkField = (typeof AGENT_LINK_FIELDS)[number];
10
+ type AgentLinkHexField = keyof typeof AGENT_LINK_HEX_LENGTHS;
11
+ export type AgentLinkIssue = {
12
+ field: AgentLinkField;
13
+ problem: "missing" | "repeated" | "empty" | "invalid-value";
14
+ } | {
15
+ field: AgentLinkHexField;
16
+ problem: "truncated" | "extra-characters";
17
+ expectedLength: number;
18
+ } | {
19
+ field: "name" | "description";
20
+ problem: "too-long";
21
+ limit: number;
22
+ } | {
23
+ field: "v";
24
+ problem: "unsupported-version";
25
+ } | {
26
+ problem: "unexpected";
27
+ parameter: string;
28
+ };
29
+ export type MalformedAgentLink = {
30
+ status: "invalid";
31
+ reason: "malformed";
32
+ message: string;
33
+ issues: AgentLinkIssues;
34
+ };
35
+ type AgentLinkIssues = [AgentLinkIssue, ...AgentLinkIssue[]];
36
+ type AgentLinkFields = {
37
+ publicKey: string;
38
+ name: string;
39
+ description: string;
40
+ source: string;
41
+ expiresAt: string;
42
+ signature: string;
43
+ channel?: {
44
+ environment: "staging" | "production";
45
+ hostPublicKey: string;
46
+ };
47
+ };
48
+ type AgentLinkCheck<Fields> = {
49
+ fields: Fields;
50
+ } | {
51
+ issues: AgentLinkIssues;
52
+ };
53
+ export declare function checkEnrollmentLink(search: Record<string, unknown>, versions: {
54
+ standard: string;
55
+ channel: string;
56
+ }): AgentLinkCheck<AgentLinkFields>;
57
+ export declare function checkRecoveryLink(search: Record<string, unknown>, version: string): AgentLinkCheck<AgentLinkFields & {
58
+ previousTrustchainId: string;
59
+ }>;
60
+ export declare function malformedLink(message: string, issues: AgentLinkIssues): MalformedAgentLink;
61
+ export declare function malformedLinkMessage(link: string, [issue]: AgentLinkIssues): string;
62
+ export declare function isEnrollmentEnvironment(value: unknown): value is "staging" | "production";
63
+ export {};
64
+ //# sourceMappingURL=requestFields.d.ts.map