@333eco/heartbank-api 0.1.0 → 0.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.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @333eco/heartbank-api
2
2
 
3
- The typed client for every HeartBank® API: **Log in with HeartBank®**, **Sign with HeartBank®**, **Thank with HeartBank®**, **Lookup** and **Verify**. Generated from the APIs' own OpenAPI descriptions, so it cannot drift from them.
3
+ The typed client for every HeartBank® API: **Log in with HeartBank®**, **Sign with HeartBank®**, **Confirm with HeartBank®**, **Thank with HeartBank®**, **Lookup** and **Verify**. Generated from the APIs' own OpenAPI descriptions, so it cannot drift from them.
4
4
 
5
5
  ```sh
6
6
  npm install @333eco/heartbank-api
@@ -44,6 +44,26 @@ if ("ticket" in ticket) {
44
44
  - The browser steps are links the client builds, never calls: `LoginClient#authorizeUrl`, `LoginClient#logOutUrl`, `SignClient#signPageUrl`.
45
45
  - Any answer outside 2xx throws an `ApiError` with the service's own `error` and `why`.
46
46
 
47
+ ## A human in the loop: Confirm with HeartBank®
48
+
49
+ A person's own passkey press for one action your app names, so you know a person, not a script, did it. They must have logged in to your app with Log in with HeartBank®; `sub` is your app's own ID for them.
50
+
51
+ ```js
52
+ import { ConfirmClient } from "@333eco/heartbank-api";
53
+
54
+ const confirm = new ConfirmClient({ assertion: async (aud) => signClientAssertion(aud) });
55
+
56
+ // 1. On upload: your server asks. `hash` is the file's SHA-256, `return_to` one of your registered redirect URLs.
57
+ const { ticket, url } = await confirm.request({ body: { sub, kind: "upload", hash, return_to: "https://yourapp.example/cb" } });
58
+ // 2. Send the person's browser there, with the ticket in the FRAGMENT:
59
+ const go = `${url}#${new URLSearchParams({ ticket, state })}`;
60
+ // 3. They come back with #confirm=<result>&state=… (or #declined=1&state=…). Your server redeems it, once:
61
+ const done = await confirm.redeem({ body: { result } });
62
+ if (done.sub !== sub || done.hash !== hash) throw new Error("not this person, or not this file");
63
+ ```
64
+
65
+ It proves presence, not personhood: never call a confirmed person "verified". For a file someone puts their name to, in public and for good, use Sign with HeartBank®.
66
+
47
67
  ## Docs
48
68
 
49
69
  The full docs open at developers.333.eco. Until then, this README and the types are the docs; every method links the page it will live on.
@@ -0,0 +1,43 @@
1
+ import { type ClientOptions } from "./runtime.js";
2
+ export type ErrorBody = {
3
+ error: string;
4
+ why?: string;
5
+ };
6
+ export type Ticket = {
7
+ /** Opaque to your app; put it in the page's address fragment, never a query. */ ticket: string;
8
+ /** https://sign.333.eco/confirm */ url: string;
9
+ /** Seconds the ticket lasts (600). */ expires_in: number;
10
+ };
11
+ export type Confirmed = {
12
+ confirmed: true;
13
+ /** Your app's own sub for the person who pressed: check it is the person you asked about. */ sub: string;
14
+ kind: "upload";
15
+ /** The SHA-256 you asked about: check it is the file you hold. */ hash?: string;
16
+ /** When they pressed (seconds since 1970). */ at: number;
17
+ };
18
+ /** Confirm with HeartBank®: A person's own passkey press for one action your app names: a human in the loop, so you know a person, not a script, did it. */
19
+ export declare class ConfirmClient {
20
+ private readonly o;
21
+ constructor(o?: ClientOptions);
22
+ /** Step 1: ask a person to confirm one action. @see https://developers.333.eco/confirm#request */
23
+ request(input: {
24
+ body: Omit<{
25
+ client_assertion_type: string;
26
+ client_assertion: string;
27
+ /** Your app's own sub for the person, from their Log in with HeartBank® ID token. */ sub: string;
28
+ /** What they are confirming, from a closed list: the page says it in its own words. */ kind: "upload";
29
+ /** Optional: the SHA-256 of the thing (a file being uploaded), 64 lowercase hex. The page shows its first eight. */ hash?: string;
30
+ /** One of your app's registered redirect URLs. */ return_to: string;
31
+ }, "client_assertion_type" | "client_assertion">;
32
+ }): Promise<Ticket>;
33
+ /** Step 2: the page where the person presses. @see https://developers.333.eco/confirm#page */
34
+ pageUrl(): string;
35
+ /** Step 3: redeem the result, once. @see https://developers.333.eco/confirm#redeem */
36
+ redeem(input: {
37
+ body: Omit<{
38
+ client_assertion_type: string;
39
+ client_assertion: string;
40
+ /** The `confirm` value the browser brought back. */ result: string;
41
+ }, "client_assertion_type" | "client_assertion">;
42
+ }): Promise<Confirmed>;
43
+ }
@@ -0,0 +1,45 @@
1
+ // Generated by scripts/gen-client.mjs from openapi/confirm.json. ⛔ Do not edit: change the description and run npm run client.
2
+ import { send, urlOf } from "./runtime.js";
3
+ /** Confirm with HeartBank®: A person's own passkey press for one action your app names: a human in the loop, so you know a person, not a script, did it. */
4
+ export class ConfirmClient {
5
+ o;
6
+ constructor(o = {}) {
7
+ this.o = o;
8
+ }
9
+ /** Step 1: ask a person to confirm one action. @see https://developers.333.eco/confirm#request */
10
+ request(input) {
11
+ return send(this.o, {
12
+ method: "POST",
13
+ base: "https://login.333.eco",
14
+ path: "/confirm/request",
15
+ pathParams: undefined,
16
+ query: undefined,
17
+ headers: undefined,
18
+ body: input.body,
19
+ contentType: "application/x-www-form-urlencoded",
20
+ security: "privateKeyJwt",
21
+ audience: "endpoint",
22
+ accept: "json",
23
+ });
24
+ }
25
+ /** Step 2: the page where the person presses. @see https://developers.333.eco/confirm#page */
26
+ pageUrl() {
27
+ return urlOf(this.o.baseUrl ?? "https://sign.333.eco", "/confirm", undefined, undefined);
28
+ }
29
+ /** Step 3: redeem the result, once. @see https://developers.333.eco/confirm#redeem */
30
+ redeem(input) {
31
+ return send(this.o, {
32
+ method: "POST",
33
+ base: "https://login.333.eco",
34
+ path: "/confirm/redeem",
35
+ pathParams: undefined,
36
+ query: undefined,
37
+ headers: undefined,
38
+ body: input.body,
39
+ contentType: "application/x-www-form-urlencoded",
40
+ security: "privateKeyJwt",
41
+ audience: "endpoint",
42
+ accept: "json",
43
+ });
44
+ }
45
+ }
package/dist/index.d.ts CHANGED
@@ -3,6 +3,8 @@ export { LoginClient } from "./login.js";
3
3
  export * as login from "./login.js";
4
4
  export { SignClient } from "./sign.js";
5
5
  export * as sign from "./sign.js";
6
+ export { ConfirmClient } from "./confirm.js";
7
+ export * as confirm from "./confirm.js";
6
8
  export { ThankClient } from "./thank.js";
7
9
  export * as thank from "./thank.js";
8
10
  export { LookupClient } from "./lookup.js";
package/dist/index.js CHANGED
@@ -4,6 +4,8 @@ export { LoginClient } from "./login.js";
4
4
  export * as login from "./login.js";
5
5
  export { SignClient } from "./sign.js";
6
6
  export * as sign from "./sign.js";
7
+ export { ConfirmClient } from "./confirm.js";
8
+ export * as confirm from "./confirm.js";
7
9
  export { ThankClient } from "./thank.js";
8
10
  export * as thank from "./thank.js";
9
11
  export { LookupClient } from "./lookup.js";
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@333eco/heartbank-api",
3
- "version": "0.1.0",
4
- "description": "The typed client for every HeartBank® API (Log in, Sign and Thank with HeartBank®, and Verify), generated from developers.333.eco's OpenAPI descriptions. For your server: it never holds a key.",
3
+ "version": "0.2.0",
4
+ "description": "The typed client for every HeartBank® API (Log in, Sign, Confirm and Thank with HeartBank®, Lookup and Verify), generated from developers.333.eco's OpenAPI descriptions. For your server: it never holds a key.",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",