Skip to content

Enroll a device

A device needs a device certificate (card) before it can do anything in a tenant. The tenant’s identity authority signs the card. Your application starts an enrollment, shows the person a six-digit code and waits. An approver’s device confirms the code and signs the approval. The SDK then verifies the card offline and returns a Client.

Ask for a card

Call enroll with the hostname the person entered and the tenant to join. If this device replaces a lost or retired one, add the RecipientId it replaces. Leave replaces out for a brand new device.

const enrollment = await sealdhealthcare.enroll({ hostname: 'records.example-health.com', tenantId });

Enrollment starts in state pending. It moves through the states below as the approver’s device does its part. Watch on('change') and show the code when it appears. Call wait() to get a Client once the SDK holds and has verified the card.

EnrollmentStateWhat is happening
pendingThe request was sent. No approver has opened it yet.
openedAn approver’s device opened the request.
revealedThis device revealed its secret. The code can now be read out.
approvedThe approver confirmed the code and signed.
enrolledThe SDK holds the card and verified it offline. wait() resolves with the Client.
rejectedThe approver declined, or confirmed the wrong caller. wait() rejects with enrollment-rejected.
lapsedNobody approved before the request’s lapsesAt. wait() rejects with enrollment-lapsed.
enrollment.on('change', () => enrollment.code && showCode(enrollment.code));
const client = await enrollment.wait(); // rejects with enrollment-rejected or enrollment-lapsed

The person reads the code out loud, or over the phone, to whoever is approving. If they change their mind before an approver signs, call cancel() to withdraw the request and discard the key it generated.

await enrollment.cancel();

Resume after a restart

If the application restarts while an enrollment is outstanding, do not start a second request. Call resumeEnrollment with the requestId you kept. Keep watching the same Enrollment.

const enrollment = await sealdhealthcare.resumeEnrollment(requestId);

What this device already holds

enrollments() returns one EnrollmentSummary for each tenant this device is enrolled in. Each summary carries the hostname it enrolled against and the card’s last known cardState. Use it to build a tenant picker, or to decide whether to enroll again or connect.

const summaries = await sealdhealthcare.enrollments();
const client = await sealdhealthcare.connect(tenantId); // unlocks the device key, with no session yet

To remove an enrollment from this device, call forget. The card itself stays active in the tenant until an Owner or Admin revokes it there. forget only removes this device’s local copy of the key.

await sealdhealthcare.forget(tenantId);

What the SDK does for you

  • Generates the device key and holds it nowhere but on this device.
  • Reveals the secret behind the code only once an approver’s device has opened the request.
  • Verifies the signed card offline, against the trust root built into the SDK, before it reports the device as enrolled.
  • Keeps a request alive across a restart. resumeEnrollment never starts a duplicate.

Decisions and errors you may see

Outcome or ErrorCodeWhenWhat to do
enrollment-rejectedAn approver declined the request, or did not recognize the caller.Tell the person to start a new enrollment and confirm who they are asking.
enrollment-lapsedNobody approved before lapsesAt.Start a fresh enroll call.

Next