@ledgerhq/agent-intent-sdk 0.2.0 → 0.4.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.
- package/README.md +226 -28
- package/dist/enrollmentChannel.d.ts +34 -5
- package/dist/enrollmentChannel.d.ts.map +1 -1
- package/dist/enrollmentChannel.js +480 -133
- package/dist/enrollmentChannel.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/swapApproval.d.ts +6 -2
- package/dist/swapApproval.d.ts.map +1 -1
- package/dist/swapApproval.js +16 -7
- package/dist/swapApproval.js.map +1 -1
- package/dist/userAgent.js +1 -1
- package/package.json +7 -8
package/README.md
CHANGED
|
@@ -102,24 +102,26 @@ const deeplink = await client.createSwapIntent({
|
|
|
102
102
|
### Swap token approvals
|
|
103
103
|
|
|
104
104
|
`canApproveSwapQuote` decides whether the Agent Intent app can send the ERC-20
|
|
105
|
-
approval a Swap API quote needs,
|
|
105
|
+
approval a Swap API quote needs, and `canResetSwapAllowance` whether it can first
|
|
106
|
+
reset a USDT allowance left to 0, so that wallet-cli and the app apply the same
|
|
106
107
|
rules:
|
|
107
108
|
|
|
108
109
|
```ts
|
|
109
110
|
const approval = parseErc20Approval(tokenAllowanceData.approvalTransaction);
|
|
110
|
-
const
|
|
111
|
-
{
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
);
|
|
111
|
+
const quote = {
|
|
112
|
+
approvalRequired: isSwapApprovalRequired({
|
|
113
|
+
isApproved: tokenAllowanceData.isApproved,
|
|
114
|
+
isTokenApprovalRequired: tags.isTokenApprovalRequired,
|
|
115
|
+
}),
|
|
116
|
+
permitRequired,
|
|
117
|
+
allowanceSpender: approval?.spender,
|
|
118
|
+
allowanceToken: approval?.token,
|
|
119
|
+
allowanceAmount: parseBaseUnits(tokenAllowanceData.approvedAmount),
|
|
120
|
+
approvalAmount: approval?.amount,
|
|
121
|
+
};
|
|
122
|
+
const context = { network: "ethereum", swapsWithCalldata, soldTokenContract };
|
|
123
|
+
const approvable = canApproveSwapQuote(quote, context);
|
|
124
|
+
const resettable = canResetSwapAllowance(quote, context);
|
|
123
125
|
```
|
|
124
126
|
|
|
125
127
|
The caller computes three inputs:
|
|
@@ -136,10 +138,34 @@ The app can send the approval only when all of these hold:
|
|
|
136
138
|
- its provider swaps with calldata;
|
|
137
139
|
- the approval is an `approve` of the sold token, and its spender and token are
|
|
138
140
|
addresses, the spender not the zero address;
|
|
139
|
-
- for USDT, the allowance left is zero (`
|
|
140
|
-
|
|
141
|
+
- for USDT, the allowance left is zero (otherwise see `canResetSwapAllowance`).
|
|
142
|
+
|
|
143
|
+
USDT's `approve` reverts while an allowance is left. With a USDT allowance left, the
|
|
144
|
+
Velora quote observed so far carries the reset itself as its approval transaction,
|
|
145
|
+
`approve(spender, 0)`; other providers are not verified yet.
|
|
146
|
+
|
|
147
|
+
`canResetSwapAllowance` applies the rules above, with the USDT one replaced by:
|
|
148
|
+
|
|
149
|
+
- `needsAllowanceReset` holds;
|
|
150
|
+
- `approvalAmount` is exactly 0, so a quote with any other approval stays refused.
|
|
151
|
+
|
|
152
|
+
To send the reset:
|
|
141
153
|
|
|
142
|
-
`
|
|
154
|
+
- send the same `approvalTransaction` you parsed `approvalAmount` from, only its
|
|
155
|
+
`to` and `calldata`, with a value of 0; the wallet sets the gas;
|
|
156
|
+
- its spender is not checked against the swap's router: a reset to 0 grants
|
|
157
|
+
nothing, and the swap must still be checked against its router.
|
|
158
|
+
|
|
159
|
+
Once the reset confirms, a new quote reports an allowance of 0 and asks for the
|
|
160
|
+
usual approval.
|
|
161
|
+
|
|
162
|
+
`canApproveSwapQuote` narrows the quote's type, so its `false` branch is `never`
|
|
163
|
+
when your quote type declares `allowanceSpender` and `allowanceToken` as `string`:
|
|
164
|
+
call `canResetSwapAllowance` first, or keep both results as booleans, as the
|
|
165
|
+
snippet above does.
|
|
166
|
+
|
|
167
|
+
`parseErc20Approval` reads only exact `approve(address,uint256)` calldata, and
|
|
168
|
+
returns its spender, its token and its amount.
|
|
143
169
|
`parseBaseUnits` takes decimal digits or a safe integer only, so `"0x0"` is not a
|
|
144
170
|
zero allowance.
|
|
145
171
|
|
|
@@ -280,11 +306,14 @@ await host.waitForCompletion({
|
|
|
280
306
|
// Prove this agent key belongs to the claimed Trustchains. Throw on failure.
|
|
281
307
|
},
|
|
282
308
|
persist: async (completion) => {
|
|
283
|
-
// Persist completion.trustchainId and completion.accountAccess atomically.
|
|
309
|
+
// Persist completion.trustchainId and, on version 2, completion.accountAccess atomically.
|
|
284
310
|
},
|
|
285
311
|
});
|
|
286
312
|
```
|
|
287
313
|
|
|
314
|
+
The completion is version 1, without account access, or version 2, with
|
|
315
|
+
`accountAccess`: check `version` before reading it.
|
|
316
|
+
|
|
288
317
|
The browser validates the signed request, derives its trusted relay origin from
|
|
289
318
|
the signed environment, and uses `createAgentEnrollmentChannelCandidate()` to
|
|
290
319
|
deliver the serialized completion. The encrypted channel is the only delivery
|
|
@@ -305,9 +334,21 @@ await candidate.deliver(completion); // resolves after the host acknowledges
|
|
|
305
334
|
was lost (for example, the relay dropped the socket during device approval).
|
|
306
335
|
If a delivery fails, for example because `authenticate` rejected it or the
|
|
307
336
|
acknowledgement timed out, `deliver()` may be retried on the same candidate. Each
|
|
308
|
-
retry opens a fresh session with a new ephemeral key
|
|
309
|
-
|
|
310
|
-
|
|
337
|
+
retry opens a fresh session with a new ephemeral key. A retry fails once the host
|
|
338
|
+
has finished, closed, or timed out.
|
|
339
|
+
|
|
340
|
+
As observed (this is not a documented relay contract), the Trustchain relay runs
|
|
341
|
+
a channel as one host and one candidate: it refuses a third socket and, when
|
|
342
|
+
either side leaves, closes the other about a second later. Except while a
|
|
343
|
+
completion is being authenticated or persisted, the host then reopens its socket
|
|
344
|
+
on the same key, at once after the first drop and with a backoff after later
|
|
345
|
+
ones (see [Security and timeouts](#security-and-timeouts)), so a reviewer who
|
|
346
|
+
leaves the page can come back while the request is unexpired. A candidate that
|
|
347
|
+
connects before the host is back is rejected by the relay with "The enrollment
|
|
348
|
+
relay rejected the session."; a `connect()` or `deliver()` retry succeeds once
|
|
349
|
+
the host has reconnected. After repeated quick drops the host can be away for up
|
|
350
|
+
to 5 seconds of backoff plus the relay's close delay of about 1.5 seconds, so
|
|
351
|
+
retry for at least 7 seconds.
|
|
311
352
|
|
|
312
353
|
### Recovery
|
|
313
354
|
|
|
@@ -333,12 +374,143 @@ const completion = await host.waitForCompletion({ request, authenticate, persist
|
|
|
333
374
|
|
|
334
375
|
For a recovery request, the host accepts only a version-3 recovery completion
|
|
335
376
|
whose agent key, previous Trustchain, and request signature match the signed
|
|
336
|
-
request, and whose `trustchainId` equals `previousTrustchainId`. For
|
|
337
|
-
request it accepts
|
|
377
|
+
request, and whose `trustchainId` equals `previousTrustchainId`. For an enrollment
|
|
378
|
+
request it accepts a version-1 or a version-2 completion. `serializeAgentRecoveryCompletion`,
|
|
338
379
|
`parseAgentRecoveryCompletion`, and `validateAgentRecovery` are exported for the
|
|
339
380
|
frontend. The channel binding is optional and signed; an unbound recovery
|
|
340
381
|
request keeps its earlier canonical bytes.
|
|
341
382
|
|
|
383
|
+
### Rejection
|
|
384
|
+
|
|
385
|
+
When the user rejects an enrollment or recovery request, the frontend tells the
|
|
386
|
+
agent instead of leaving it to wait until the request expires:
|
|
387
|
+
|
|
388
|
+
```ts
|
|
389
|
+
await candidate.reject(); // resolves after the host acknowledges the rejection
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
On the host, `waitForCompletion` then rejects with
|
|
393
|
+
`AgentEnrollmentRejectedError`, whose `kind` is `"enrollment"` or `"recovery"`.
|
|
394
|
+
Nothing was authenticated or persisted. `isAgentEnrollmentRejectedError` checks
|
|
395
|
+
for an `Error` with that `name` and a valid `kind` rather than using
|
|
396
|
+
`instanceof`, so it also matches an error from another realm of the same process
|
|
397
|
+
or another copy of the SDK. An error that went through a structured clone, such
|
|
398
|
+
as `postMessage` to a worker, keeps neither its `name` nor its `kind`, so it no
|
|
399
|
+
longer matches:
|
|
400
|
+
|
|
401
|
+
```ts
|
|
402
|
+
try {
|
|
403
|
+
await host.waitForCompletion({ request, authenticate, persist });
|
|
404
|
+
} catch (error) {
|
|
405
|
+
if (!isAgentEnrollmentRejectedError(error)) throw error;
|
|
406
|
+
console.log(`The user rejected this ${error.kind} request.`);
|
|
407
|
+
}
|
|
408
|
+
```
|
|
409
|
+
|
|
410
|
+
`reject()` connects first when no session is open, completes the
|
|
411
|
+
key-confirmation handshake like `deliver()`, and waits for the acknowledgement.
|
|
412
|
+
The handshake is bounded by `handshakeTimeoutMs`, the acknowledgement by
|
|
413
|
+
`acknowledgementTimeoutMs`, and both by `completionTimeoutMs` and the request
|
|
414
|
+
expiry. Its promise reports its own errors, never a delivery's: "Enrollment
|
|
415
|
+
rejection acknowledgement timed out.", "Enrollment rejection timed out."
|
|
416
|
+
(`completionTimeoutMs` or the request expiry), "Enrollment relay closed before
|
|
417
|
+
the rejection was sent." (during the handshake), and "Enrollment relay closed
|
|
418
|
+
before the rejection was acknowledged.". Once the host acknowledges, the
|
|
419
|
+
candidate is done: `connect()`, `deliver()` and `reject()` throw "This
|
|
420
|
+
enrollment request has already been rejected.". Like `deliver()`, `reject()`
|
|
421
|
+
throws synchronously when the candidate was closed, a delivery or rejection is
|
|
422
|
+
already running, or the request has expired.
|
|
423
|
+
|
|
424
|
+
After any other failure, `reject()` may be retried on a fresh session, for
|
|
425
|
+
example after the relay refused a candidate that arrived before the host
|
|
426
|
+
reconnected. A failed `reject()` does not prove the host kept waiting: when the
|
|
427
|
+
relay drops the host just as the rejection arrives, the host still honors it but
|
|
428
|
+
its acknowledgement is lost, and a retry then finds no host. A host that never
|
|
429
|
+
got the rejection waits until its timeouts or the request expiry.
|
|
430
|
+
|
|
431
|
+
Never call `reject()` once the device has committed the enrollment to the
|
|
432
|
+
Trustchain (the AddMember step): a rejection cannot undo that commit. The SDK
|
|
433
|
+
cannot see the device step, so the caller must enforce this rule, and keep
|
|
434
|
+
enforcing it across page reloads: a new candidate does not know that an earlier
|
|
435
|
+
one committed. As a safety net, `reject()` throws once `deliver()` has been
|
|
436
|
+
called on that candidate, even if the delivery failed, and the host refuses a
|
|
437
|
+
rejection, from any candidate, once it has received a well-formed completion
|
|
438
|
+
for this request. A completion that never reached the host leaves it accepting
|
|
439
|
+
rejections. The host counts a completion as received once it parses, before
|
|
440
|
+
`authenticate` runs, so a completion that then fails authentication, even
|
|
441
|
+
transiently, still makes it refuse later rejections. Parsing does not prove the
|
|
442
|
+
device committed, since anyone holding the link can build a well-formed
|
|
443
|
+
completion, but the host cannot tell a forged completion from a committed one
|
|
444
|
+
that failed to authenticate. Refusing costs at most a wait until the request
|
|
445
|
+
expires; a rejection honored after a commit would leave a Trustchain member
|
|
446
|
+
that its agent treats as rejected. That refusal is final: `reject()` fails with "The
|
|
447
|
+
enrollment host already received a completion for this request; it can no
|
|
448
|
+
longer be rejected." and later calls throw the same error, so retries do not
|
|
449
|
+
keep making the relay drop the host, each drop delaying its next reopening.
|
|
450
|
+
|
|
451
|
+
The relay forwards only the messages of its own protocol, in the order that
|
|
452
|
+
protocol expects, and refuses anything else, so a rejection travels like a
|
|
453
|
+
completion: the candidate sends it as `TrustchainShareCredential` and the host
|
|
454
|
+
acknowledges it with `TrustchainAddedMember`. Both carry `{"encrypted":…}` and are bound to the
|
|
455
|
+
signed request like every other channel message. Only a rejection and its
|
|
456
|
+
acknowledgement carry a `reason`; a completion carries `completion`, and its
|
|
457
|
+
acknowledgement `acknowledged` and `digest`. Each side accepts only the body it
|
|
458
|
+
waits for, so neither takes a rejection for a completion or the reverse.
|
|
459
|
+
|
|
460
|
+
The host turns a rejection or a completion down with a `Failure`. The relay
|
|
461
|
+
reads a `Failure` as `{"type":…,"message":…}`, with a `type` from its own list,
|
|
462
|
+
so the host's `Failure` has the type `UNEXPECTED_SHARE_CREDENTIAL` and carries
|
|
463
|
+
its ciphertext in `message`, which the relay forwards untouched. As observed, the
|
|
464
|
+
relay then closes both sides, so nothing follows a `Failure` on that socket.
|
|
465
|
+
|
|
466
|
+
| Direction | Message | Payload | Encrypted body | Meaning |
|
|
467
|
+
| ---------------- | --------------------------- | --------------------------------------------------------- | ------------------------------------- | ------------------------------------------------------------------------------------- |
|
|
468
|
+
| candidate → host | `TrustchainShareCredential` | `{"encrypted":…}` | `{"reason":"user-rejected"}` | The user rejected the request. |
|
|
469
|
+
| host → candidate | `TrustchainAddedMember` | `{"encrypted":…}` | `{"reason":"rejection-acknowledged"}` | The host accepted the rejection and ended its session. |
|
|
470
|
+
| host → candidate | `Failure` | `{"type":"UNEXPECTED_SHARE_CREDENTIAL","message":…}` | `{"reason":"completion-received"}` | The host refused the rejection: it already received a completion. |
|
|
471
|
+
| host → candidate | `Failure` | `{"type":"UNEXPECTED_SHARE_CREDENTIAL","message":…}` | `{"reason":"reset"}` | The host turned down a completion or an unexpected frame, and dropped this candidate. |
|
|
472
|
+
| relay → either | `Failure` | `{"type":"…","message":"…"}`, from the all-zero publisher | none | The relay refused the session. |
|
|
473
|
+
|
|
474
|
+
The candidate reads a `Failure` as the host's only when it comes from the host
|
|
475
|
+
key, has the type `UNEXPECTED_SHARE_CREDENTIAL`, and decrypts. Any other
|
|
476
|
+
`Failure` is the relay's own and fails the session with "The enrollment relay
|
|
477
|
+
rejected the session.". Because the relay closes right after a `Failure`, the
|
|
478
|
+
candidate reads the frames it already received before it reports the close.
|
|
479
|
+
While rejecting, the candidate treats only `rejection-acknowledged` as success
|
|
480
|
+
and `completion-received` as the final refusal. Any other host `Failure`, such
|
|
481
|
+
as `reset`, makes `reject()` fail with "The enrollment host reset this
|
|
482
|
+
session.", which a retry on a fresh session may overcome.
|
|
483
|
+
|
|
484
|
+
A host whose SDK predates rejection reads the rejection as a malformed
|
|
485
|
+
completion and answers with a `Failure` the relay refuses, so `reject()` fails
|
|
486
|
+
with a relay error and that host keeps waiting within its usual
|
|
487
|
+
`candidateTimeoutMs`, `completionTimeoutMs` and the request expiry. Callers that
|
|
488
|
+
must not wait, such as a page the user is leaving, bound `reject()` themselves.
|
|
489
|
+
|
|
490
|
+
The host accepts a rejection only from the candidate that completed key
|
|
491
|
+
confirmation on its current socket, and only while it has received no
|
|
492
|
+
well-formed completion for this request. A rejection that does not decrypt,
|
|
493
|
+
comes from another key, arrives before key confirmation, carries another reason,
|
|
494
|
+
or carries anything besides its `reason` is handled like any unexpected frame:
|
|
495
|
+
it never ends the host session, but the host drops its current candidate, even a
|
|
496
|
+
confirmed one, and waits for another. So is any `Failure` the host receives,
|
|
497
|
+
which is always the relay's. A forged frame can therefore interrupt a reviewer,
|
|
498
|
+
who then rejects again on a fresh session, but cannot reject the request. A
|
|
499
|
+
rejection that arrives while a completion is being authenticated or persisted
|
|
500
|
+
waits behind it and has no effect. Frames from the confirmed candidate that the
|
|
501
|
+
host reads after the relay dropped its socket get no answer, but still count: a
|
|
502
|
+
rejection ends the session, and a well-formed completion, which the host then
|
|
503
|
+
neither authenticates nor persists, makes it refuse later rejections. After
|
|
504
|
+
accepting a rejection, the host acknowledges it, stops its timers and keepalive,
|
|
505
|
+
closes its socket, and does not reconnect; the relay closing the host afterwards
|
|
506
|
+
does not change the error.
|
|
507
|
+
|
|
508
|
+
Anyone who holds the signed link can complete the key-confirmation handshake, so
|
|
509
|
+
anyone who holds it can also reject the request, or send a well-formed
|
|
510
|
+
completion that makes the host refuse rejections. The link already grants that
|
|
511
|
+
much: it is what lets its holder reach the agent at all. The relay cannot forge
|
|
512
|
+
a rejection, because it never holds the channel key.
|
|
513
|
+
|
|
342
514
|
### Security and timeouts
|
|
343
515
|
|
|
344
516
|
The channel key and every encrypted envelope are bound to the exact signed
|
|
@@ -352,11 +524,37 @@ handshake and the delivered completion (device approval) is bounded only by
|
|
|
352
524
|
the candidate. Applications may override these with the `timeouts` option.
|
|
353
525
|
While a session is open, both sides send the relay a text `ping` every 60
|
|
354
526
|
seconds, because the Trustchain relay drops a client after 5 minutes without a
|
|
355
|
-
frame sent to it.
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
527
|
+
frame sent to it. The host also expects a frame back within 10 seconds of each
|
|
528
|
+
ping, normally the relay's `pong`; otherwise it treats the socket as dropped,
|
|
529
|
+
closes it, and reconnects as described below. A failed `authenticate` call
|
|
530
|
+
rejects only that delivery, so the same or a later candidate can complete the
|
|
531
|
+
same bounded host session. A persistence failure closes the session without
|
|
532
|
+
acknowledging. If enrollment was committed before delivery failed, re-enroll the
|
|
533
|
+
agent with a channel-bound recovery request.
|
|
534
|
+
|
|
535
|
+
The host does not limit how often it reopens its relay socket. It reopens at
|
|
536
|
+
once after the first drop, then after 1, 2 and 4 seconds, then every 5 seconds.
|
|
537
|
+
A reopened socket that fails before connecting, a handshake timeout, and a
|
|
538
|
+
missed ping reply follow the same backoff. A socket that stayed open for at
|
|
539
|
+
least 60 seconds before it was lost restarts the backoff; a missed ping reply is
|
|
540
|
+
detected at least 70 seconds after the socket opened, so the host reopens at
|
|
541
|
+
once after one. That window uses a monotonic clock, so a wall-clock change does
|
|
542
|
+
not move it. A candidate that does not finish the handshake within
|
|
543
|
+
`handshakeTimeoutMs` no longer fails the host: the host closes that socket and
|
|
544
|
+
reopens it like a relay drop, with a fresh wait for the next candidate.
|
|
545
|
+
Reconnecting never extends `completionTimeoutMs` or the request expiry. The host
|
|
546
|
+
stops and fails the session when:
|
|
547
|
+
|
|
548
|
+
- the request expires or `completionTimeoutMs` elapses;
|
|
549
|
+
- no candidate connects within `candidateTimeoutMs`, a wait that restarts on
|
|
550
|
+
each reconnect after a candidate had connected;
|
|
551
|
+
- `close()` is called;
|
|
552
|
+
- the initial socket fails before it opens;
|
|
553
|
+
- persistence fails, or a socket is lost while a completion is being
|
|
554
|
+
authenticated or persisted.
|
|
555
|
+
|
|
556
|
+
Before each reopen the host also checks the signed request expiry against the
|
|
557
|
+
wall clock, so it does not reconnect after a laptop slept past the expiry.
|
|
360
558
|
|
|
361
559
|
The channel sends only the agent public key, App-18 Trustchain ID, and safe
|
|
362
560
|
App-16 environment/root/path references. It must never carry a serialized
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AgentIntentSdkError } from "./bytes.ts";
|
|
2
|
+
import { type AgentEnrollmentCompletion } from "./completion.ts";
|
|
2
3
|
import { type AgentEnrollmentChannelBinding, type AgentEnrollmentRequestV2 } from "./enrollment.ts";
|
|
3
4
|
import { type AgentRecoveryChannelRequest, type AgentRecoveryCompletion, type AgentRecoveryRequest } from "./recovery.ts";
|
|
4
5
|
type RelayMessageName = "InitiateHandshake" | "HandshakeChallenge" | "CompleteHandshakeChallenge" | "HandshakeCompletionSucceeded" | "TrustchainShareCredential" | "TrustchainAddedMember" | "Failure";
|
|
@@ -36,7 +37,7 @@ export declare const AGENT_ENROLLMENT_CHANNEL_DEFAULT_TIMEOUTS: {
|
|
|
36
37
|
/** Signed requests whose completion can be delivered over the enrollment channel. */
|
|
37
38
|
export type AgentEnrollmentChannelRequest = AgentEnrollmentRequestV2 | AgentRecoveryChannelRequest;
|
|
38
39
|
/** Completion accepted by the host for a given channel request kind. */
|
|
39
|
-
export type AgentEnrollmentChannelCompletion<Request extends AgentEnrollmentChannelRequest = AgentEnrollmentChannelRequest> = Request extends AgentRecoveryRequest ? AgentRecoveryCompletion :
|
|
40
|
+
export type AgentEnrollmentChannelCompletion<Request extends AgentEnrollmentChannelRequest = AgentEnrollmentChannelRequest> = Request extends AgentRecoveryRequest ? AgentRecoveryCompletion : AgentEnrollmentCompletion;
|
|
40
41
|
export type AgentEnrollmentChannelHost = {
|
|
41
42
|
binding: AgentEnrollmentChannelBinding;
|
|
42
43
|
waitForCompletion<Request extends AgentEnrollmentChannelRequest>(input: {
|
|
@@ -50,17 +51,43 @@ export type AgentEnrollmentChannelCandidate = {
|
|
|
50
51
|
/**
|
|
51
52
|
* Opens the relay session and completes the key-confirmation handshake, then
|
|
52
53
|
* keeps the session open for a later `deliver()`. Resolves once the host is
|
|
53
|
-
* reachable. Repeated calls share the open session
|
|
54
|
+
* reachable. Repeated calls share the open session, and a call made while
|
|
55
|
+
* `deliver()` or `reject()` runs reports on that call's session.
|
|
54
56
|
*/
|
|
55
57
|
connect(): Promise<void>;
|
|
56
58
|
/**
|
|
57
59
|
* Sends the serialized completion and resolves once the host acknowledges it.
|
|
58
|
-
* Connects first when no session is open. After
|
|
59
|
-
* retry on a fresh session while the signed request is unexpired.
|
|
60
|
+
* Connects first when no session is open. After the host turns a delivery down
|
|
61
|
+
* the candidate may retry on a fresh session while the signed request is unexpired.
|
|
60
62
|
*/
|
|
61
63
|
deliver(completionPayload: string): Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* Tells the host that the user rejected the signed request and resolves once
|
|
66
|
+
* the host acknowledges it; the candidate is then unusable. Connects first
|
|
67
|
+
* when no session is open. Never call it once the device has committed the
|
|
68
|
+
* enrollment to the Trustchain: a rejection cannot undo that commit. The caller
|
|
69
|
+
* must remember that commit across page reloads, because a new candidate cannot
|
|
70
|
+
* know it. It throws once `deliver()` has been called, and fails for good once
|
|
71
|
+
* the host answers that it already received a completion for this request.
|
|
72
|
+
* After any other failure the host may still have honored the rejection, and
|
|
73
|
+
* `reject()` may be retried on a fresh session.
|
|
74
|
+
*/
|
|
75
|
+
reject(): Promise<void>;
|
|
62
76
|
close(): void;
|
|
63
77
|
};
|
|
78
|
+
/** The user rejected the signed enrollment or recovery request in the frontend. */
|
|
79
|
+
export declare class AgentEnrollmentRejectedError extends AgentIntentSdkError {
|
|
80
|
+
readonly kind: "enrollment" | "recovery";
|
|
81
|
+
constructor(kind: "enrollment" | "recovery");
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Checked by shape rather than `instanceof`, so an error from another copy of the SDK or another
|
|
85
|
+
* realm of the same process still matches. It must still be a real `Error`, which `Error.isError`
|
|
86
|
+
* tells across realms. Where it is missing, `Object.prototype.toString` stands in, which an object
|
|
87
|
+
* can fool through `Symbol.toStringTag`. A structured clone, such as `postMessage` to a worker,
|
|
88
|
+
* keeps neither the name nor `kind`, so a cloned error does not match.
|
|
89
|
+
*/
|
|
90
|
+
export declare function isAgentEnrollmentRejectedError(error: unknown): error is AgentEnrollmentRejectedError;
|
|
64
91
|
export declare function createAgentEnrollmentChannelHost(input: {
|
|
65
92
|
environment: AgentEnrollmentChannelBinding["environment"];
|
|
66
93
|
relayBaseUrl: string;
|
|
@@ -80,6 +107,8 @@ export declare const enrollmentChannelCryptoVectors: {
|
|
|
80
107
|
deriveKey: (sharedSecret: Uint8Array, request: AgentEnrollmentChannelRequest) => string;
|
|
81
108
|
aad: (request: AgentEnrollmentChannelRequest, envelope: Pick<RelayEnvelope, "version" | "publisher" | "message">) => string;
|
|
82
109
|
encrypt: (sharedSecret: Uint8Array, request: AgentEnrollmentChannelRequest, envelope: Pick<RelayEnvelope, "version" | "publisher" | "message">, payload: object, nonce: Uint8Array) => Promise<string>;
|
|
110
|
+
/** The whole relay frame, as the channel sends it. */
|
|
111
|
+
envelope: (sharedSecret: Uint8Array, request: AgentEnrollmentChannelRequest, envelope: Pick<RelayEnvelope, "version" | "publisher" | "message">, payload: object, nonce: Uint8Array) => Promise<string>;
|
|
83
112
|
};
|
|
84
113
|
export {};
|
|
85
114
|
//# sourceMappingURL=enrollmentChannel.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"enrollmentChannel.d.ts","sourceRoot":"","sources":["../src/enrollmentChannel.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"enrollmentChannel.d.ts","sourceRoot":"","sources":["../src/enrollmentChannel.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAuC,MAAM,YAAY,CAAC;AACtF,OAAO,EAAkC,KAAK,yBAAyB,EAAE,MAAM,iBAAiB,CAAC;AACjG,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