@octap/browser-sdk 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/CHANGELOG.md ADDED
@@ -0,0 +1,34 @@
1
+ # Changelog
2
+
3
+ ## 0.2.0
4
+
5
+ Breaking. Upgrade together with `@octap/sdk` 0.4, whose `verifyCustomer` takes the new customer
6
+ token, and against a Core with OCT-394.
7
+
8
+ ### Changed
9
+
10
+ - Customers sign in on OctaP's own page, in a popup (OCT-394). Your page no longer loads Google's
11
+ script and never sees Google's token.
12
+ - `createOctapAuth({ organizationId })`: `googleClientId` is gone, and `apiBaseUrl` is optional
13
+ (default `https://api.octap.biz`).
14
+ - Call `signIn()` from a click handler, or use `renderSignInButton()`: browsers block a popup opened
15
+ any other way.
16
+ - `getIdToken()` returns a customer token signed by OctaP for your organization only, valid up to an
17
+ hour. Check it on your backend with `@octap/sdk`'s `verifyCustomer`.
18
+ - Sessions saved by 0.1 are not restored: customers sign in again once after the upgrade.
19
+ - Error codes: `popup-blocked` is new, `nonce-mismatch` is gone.
20
+
21
+ ### Added
22
+
23
+ - `DEFAULT_API_BASE_URL`.
24
+ - `signIn({ signal })` can be aborted.
25
+
26
+ ### Setup
27
+
28
+ - Add your site's origin to your organization's sign-in origins in the console (`https://` only,
29
+ plus `http://localhost` while developing). OctaP delivers a sign-in to no other page.
30
+
31
+ ## 0.1.1
32
+
33
+ First published version. Google sign-in ran on the merchant's page, with the merchant's
34
+ `googleClientId`.
package/README.md CHANGED
@@ -6,31 +6,45 @@ Firebase Auth. You never handle OAuth nonces, ephemeral keys, ZK proofs or Enoki
6
6
  This package holds no merchant credential. Balance, history, voucher lists and claims need your API
7
7
  key, so they stay on your backend through `@octap/sdk`.
8
8
 
9
+ ```bash
10
+ npm install @octap/browser-sdk
11
+ ```
12
+
9
13
  ## Sign a customer in
10
14
 
11
15
  ```ts
12
16
  import { createOctapAuth } from '@octap/browser-sdk';
13
17
 
14
- const auth = createOctapAuth({ apiBaseUrl, organizationId, googleClientId });
18
+ const auth = createOctapAuth({ organizationId });
15
19
 
16
20
  auth.onAuthStateChanged((user) => {
17
21
  // { endUserId, memberId, suiAddress } or null. Also called once on load, after a reload restores.
18
22
  });
19
23
 
20
- await auth.renderGoogleButton(document.getElementById('sign-in'), {
24
+ auth.renderSignInButton(document.getElementById('sign-in'), {
21
25
  onError: (error) => showMessage(error.message),
22
26
  });
23
27
  ```
24
28
 
25
- Signing in also enrolls the customer in your organization. The button renders nothing while a
26
- customer is signed in, and returns after they sign out or their session expires. Google's token
27
- lasts about an hour: when `getIdToken` finds it expired, the customer is signed out, so listeners get
28
- `null` and the button returns.
29
+ The customer signs in with Google on OctaP's own page, in a popup. Signing in also enrolls them in
30
+ your organization. Google's token never reaches your page or your backend: your page gets the
31
+ customer, a signing key it keeps, and a customer token for your backend.
32
+
33
+ Before the first sign-in, add your site's origin (`https://shop.example`, and `http://localhost:3000`
34
+ while developing) to your organization's sign-in origins in the console. OctaP refuses to deliver a
35
+ sign-in to any other page. There is no Google client ID to configure.
36
+
37
+ To use your own button, call `auth.signIn()` from its click handler: browsers block a popup opened
38
+ any other way. The rendered button shows nothing while a customer is signed in, and returns after
39
+ they sign out or their session expires. `apiBaseUrl` defaults to `https://api.octap.biz`; set it only
40
+ for a Core running elsewhere, such as locally.
29
41
 
30
42
  ## Prove the customer to your backend
31
43
 
32
- Send the token to your backend, and check it there with `verifyCustomer` from `@octap/sdk`. Never
33
- trust a member ID your frontend sends on its own.
44
+ Send the customer token to your backend, and check it there with `verifyCustomer` from `@octap/sdk`.
45
+ Never trust a member ID your frontend sends on its own. The token is valid for your organization
46
+ only and lasts up to an hour: when `getIdToken` finds it expired, the customer is signed out, so
47
+ listeners get `null` and the button returns.
34
48
 
35
49
  ```ts
36
50
  const response = await fetch('/api/claim', {
@@ -59,6 +73,23 @@ Follow these rules, whatever your interface looks like:
59
73
  key. `status` and `body` carry what the server answered, if anything.
60
74
  - Use a new idempotency key only after the claim is CANCELLED.
61
75
 
76
+ ## Use a voucher
77
+
78
+ Your backend calls `prepareVoucherUse` from `@octap/sdk` and returns the result. Show the customer
79
+ which voucher they are using, then have their device sign it:
80
+
81
+ ```ts
82
+ const use = await response.json();
83
+ const used = await auth.signAndFinalizeVoucherUse(use);
84
+ // used.status is REDEEMED; deliver the benefit on the voucher.redeemed webhook.
85
+ ```
86
+
87
+ The signature is the only thing that can mark a customer's voucher used: your API key cannot.
88
+ `signAndFinalizeVoucherUse` never retries by itself. On `outcome-unknown`, read the voucher from your
89
+ backend before you try again.
90
+
91
+ ## Lower-level signing
92
+
62
93
  `auth.signTransaction(transactionBytes)` is the lower-level call: it returns the zkLogin signature
63
94
  and sends nothing. It refuses bytes whose sender is not the signed-in customer.
64
95
 
@@ -68,12 +99,12 @@ Every failure is an `OctapAuthError` with a `code`. API errors also have `status
68
99
 
69
100
  | Code | Meaning | What to do |
70
101
  | ---------------------- | ------------------------------------------------------- | -------------------------------- |
71
- | `sign-in-canceled` | The customer closed Google's window | Nothing; the button still works |
72
- | `nonce-mismatch` | Google's token was not issued for this attempt | Ask them to sign in again |
73
- | `provider-unavailable` | Google's script could not load | Check for blocked scripts |
102
+ | `sign-in-canceled` | The customer closed the sign-in window | Nothing; the button still works |
103
+ | `popup-blocked` | The browser blocked the sign-in window | Call `signIn()` from a click |
104
+ | `provider-unavailable` | The SDK ran outside a browser | Sign in from the browser |
74
105
  | `not-signed-in` | No customer is signed in | Show the button |
75
106
  | `session-expired` | The signing session passed `maxEpoch` | Ask them to sign in again |
76
- | `token-expired` | Google's token expired (after about an hour) | Ask them to sign in again |
107
+ | `token-expired` | The customer token expired (after up to an hour) | Ask them to sign in again |
77
108
  | `wrong-account` | The transaction belongs to a different customer | Ask them to use that account |
78
109
  | `invalid-claim` | The claim has nothing to sign, or its bytes are invalid | Check the claim's status |
79
110
  | `outcome-unknown` | Finalize may have reached the chain | Read the claim; do not re-create |
@@ -83,13 +114,13 @@ Every failure is an `OctapAuthError` with a `code`. API errors also have `status
83
114
  | `aborted` | Your `AbortSignal` fired | Nothing |
84
115
  | `invalid-response` | OctaP's response could not be read | Report it |
85
116
 
86
- `sign-in-canceled` is a best guess from the page regaining focus, because Google's button reports no
87
- cancellation itself. It can fire while the popup is still open if the customer clicks back to the
88
- page, and may not fire at all. Use it only to show a message.
117
+ A sign-in that OctaP refuses, such as from an origin that is not in your sign-in origins, is an
118
+ `api-error` with the status and message OctaP's page showed.
89
119
 
90
120
  ## Security
91
121
 
92
- The session holds the ephemeral signing key, the proof and the id_token until `maxEpoch` or sign-out.
122
+ The session holds the ephemeral signing key, the proof and the customer token until they expire or
123
+ sign-out.
93
124
 
94
125
  - By default these are in `sessionStorage`, so they survive a reload in this tab. Any script on your
95
126
  page can read them, so an XSS flaw lets an attacker sign as this customer until the session
@@ -98,11 +129,15 @@ The session holds the ephemeral signing key, the proof and the id_token until `m
98
129
  out.
99
130
  - The private key is never sent anywhere. Only its public half reaches OctaP.
100
131
 
101
- ## Google client ID
132
+ ## Why sign-in happens on OctaP's page
102
133
 
103
- Use the Google client ID OctaP gives you, and ask OctaP to add your site's origin to it. All merchants
104
- share this client for now, so moving to per-merchant clients later would change customer wallets.
134
+ Every customer's wallet address comes from OctaP's one Google client, so all merchants share it.
135
+ Signing in on OctaP's page keeps Google's token there: what your backend gets is a token OctaP signed
136
+ for your organization alone. A token a customer showed another merchant is refused here, and yours
137
+ is refused there. If your site sends `Cross-Origin-Opener-Policy: same-origin`, use
138
+ `same-origin-allow-popups`, or the sign-in window cannot report back.
105
139
 
106
140
  ## Local example
107
141
 
108
- See [the browser auth example](../../examples/README.md#browser-auth-example) for a runnable page.
142
+ See [the browser auth example](https://github.com/OctaPointees/octap-core/tree/dev/ts-sdks/examples/browser-auth)
143
+ in the octap-core repository for a runnable page.
package/dist/auth.d.ts CHANGED
@@ -1,24 +1,28 @@
1
1
  import { type RequestOptions } from './core-api.js';
2
2
  import { OctapAuthError } from './errors.js';
3
3
  import { type OctapUser, type Persistence } from './session-store.js';
4
+ /** OctaP's API. Set `apiBaseUrl` only to reach another Core, such as one running locally. */
5
+ export declare const DEFAULT_API_BASE_URL = "https://api.octap.biz";
4
6
  export interface OctapAuthOptions {
5
- apiBaseUrl: string;
6
7
  organizationId: string;
7
- googleClientId: string;
8
+ /** Defaults to `https://api.octap.biz`. */
9
+ apiBaseUrl?: string;
8
10
  /**
9
- * Where the signing key, proof and id_token are kept until `maxEpoch` or sign-out. `session` (the
10
- * default) survives a reload in this tab; `memory` does not. Any script running on your page can
11
- * read a `session` value, so an XSS flaw exposes it until it expires.
11
+ * Where the signing key, proof and customer token are kept until they expire or sign-out. `session`
12
+ * (the default) survives a reload in this tab; `memory` does not. Any script running on your page
13
+ * can read a `session` value, so an XSS flaw exposes it until it expires.
12
14
  */
13
15
  persistence?: Persistence;
14
16
  timeoutMs?: number;
15
17
  fetch?: typeof fetch;
16
18
  }
17
19
  export interface RenderOptions {
18
- /** Sign-in failures, including a customer closing Google's window. */
20
+ /** Sign-in failures, including a customer closing the sign-in window. */
19
21
  onError?: (error: OctapAuthError) => void;
20
- /** Passed through to Google's button, such as `theme`, `size`, `text` or `shape`. */
21
- button?: Record<string, unknown>;
22
+ /** The button's text. Defaults to "Sign in with Google". */
23
+ label?: string;
24
+ /** A class for the button, to style it like the rest of your page. */
25
+ className?: string;
22
26
  }
23
27
  /** The merchant backend's claim result, as `@octap/sdk`'s `claimVoucher` returns it. */
24
28
  export interface SignableClaim {
@@ -51,20 +55,25 @@ export interface FinalizedClaim {
51
55
  blockchainDigest: string;
52
56
  }
53
57
  export type AuthStateListener = (user: OctapUser | null) => void;
58
+ /**
59
+ * Customer sign-in and signing for one organization. Sign-in happens on OctaP's own page, in a
60
+ * popup: Google's token never reaches this page or your backend. What comes back is the customer, a
61
+ * proof for a signing key that never leaves this page, and a customer token your backend checks with
62
+ * `@octap/sdk`'s `verifyCustomer`. That token is valid for this organization only.
63
+ *
64
+ * Your page's origin must be one of the organization's sign-in origins (console, Developer settings).
65
+ */
54
66
  export declare class OctapAuth {
55
67
  private readonly api;
68
+ private readonly apiBaseUrl;
56
69
  private readonly store;
57
70
  private readonly organizationId;
58
- private readonly googleClientId;
59
71
  private readonly listeners;
60
72
  private session;
61
- private provider?;
62
73
  private button?;
63
- private signingIn;
74
+ private signingIn?;
64
75
  /** Changes when the session ends, so a sign-in still running cannot bring it back. */
65
76
  private signInGeneration;
66
- /** Changes on each new button, so only the latest nonce can be rendered or used. */
67
- private armGeneration;
68
77
  private expiryTimer?;
69
78
  constructor(options: OctapAuthOptions);
70
79
  /** The signed-in customer, restored synchronously after a reload. Null once the session expires. */
@@ -72,13 +81,21 @@ export declare class OctapAuth {
72
81
  /** Calls `listener` with the current customer soon after subscribing, then on every change. */
73
82
  onAuthStateChanged(listener: AuthStateListener): () => void;
74
83
  /**
75
- * Renders Google's button. Key, nonce, enrollment and proof are handled when the customer uses it.
76
- * While a customer is signed in it renders nothing, and appears once they sign out or expire.
84
+ * Opens OctaP's sign-in window and resolves with the customer once they have signed in. Call it
85
+ * from a click handler: browsers block a window opened any other way. Signing in the first time
86
+ * joins this organization's loyalty program. A call while a sign-in is open returns that sign-in.
77
87
  */
78
- renderGoogleButton(element: HTMLElement, options?: RenderOptions): Promise<void>;
88
+ signIn(options?: {
89
+ signal?: AbortSignal;
90
+ }): Promise<OctapUser>;
79
91
  /**
80
- * The id_token for your backend to check with `@octap/sdk`'s `verifyCustomer`. Google's token lasts
81
- * about an hour. When it has expired the customer is signed out, so the button returns for a new one.
92
+ * Renders a button into `element` that calls `signIn()`, reporting failures through `onError`.
93
+ * While a customer is signed in it renders nothing, and appears again once they sign out or expire.
94
+ */
95
+ renderSignInButton(element: HTMLElement, options?: RenderOptions): void;
96
+ /**
97
+ * The customer token for your backend to check with `@octap/sdk`'s `verifyCustomer`. It lasts up
98
+ * to an hour; once it has expired the customer is signed out, so the button returns.
82
99
  */
83
100
  getIdToken(): Promise<string>;
84
101
  /** Lower-level signing: returns the zkLogin signature over base64 transaction bytes. */
@@ -98,10 +115,9 @@ export declare class OctapAuth {
98
115
  */
99
116
  signAndFinalizeVoucherUse(use: SignableVoucherUse, options?: RequestOptions): Promise<FinalizedVoucherUse>;
100
117
  private submitSigned;
101
- /** Always ends the session. A button that cannot return is reported through `onError`. */
118
+ /** Ends the session on this page. */
102
119
  signOut(): Promise<void>;
103
120
  private requireSession;
104
- private expireSession;
105
121
  private endSession;
106
122
  /** Lets an open page notice expiry without waiting for a call to fail. Only runs in a browser. */
107
123
  private scheduleExpiry;
@@ -109,10 +125,7 @@ export declare class OctapAuth {
109
125
  /** One merchant listener's bug must not undo a sign-in, or stop the other listeners. */
110
126
  private call;
111
127
  private reportError;
112
- /** Puts a usable button back, if one was rendered, reporting rather than throwing a failure. */
113
- private rearm;
114
- /** Prepares a key and nonce and renders the button with them. A newer call replaces an older one. */
115
- private arm;
116
- private completeSignIn;
128
+ /** Shows the sign-in button while nobody is signed in, and nothing while someone is. */
129
+ private renderButton;
117
130
  }
118
131
  export declare function createOctapAuth(options: OctapAuthOptions): OctapAuth;
package/dist/auth.js CHANGED
@@ -1,36 +1,55 @@
1
+ import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
1
2
  import { CoreApi, normalizeBaseUrl } from './core-api.js';
2
3
  import { OctapAuthError } from './errors.js';
3
- import { createGoogleProvider } from './google-provider.js';
4
4
  import { createSessionStore, } from './session-store.js';
5
- import { PendingSignIn, idTokenExpiry, signWithZkLogin } from './zklogin-signer.js';
5
+ import { openSignInPopup } from './sign-in-popup.js';
6
+ import { isZkProof, signWithZkLogin, tokenExpiry } from './zklogin-signer.js';
7
+ /** OctaP's API. Set `apiBaseUrl` only to reach another Core, such as one running locally. */
8
+ export const DEFAULT_API_BASE_URL = 'https://api.octap.biz';
6
9
  const DEFAULT_TIMEOUT_MS = 35_000;
7
10
  /** Finalize waits for the chain's verdict, so it gets longer than an ordinary request. */
8
11
  const FINALIZE_TIMEOUT_MS = 90_000;
9
12
  /** Browsers run a longer `setTimeout` immediately. */
10
13
  const MAX_TIMER_MS = 2_147_483_647;
14
+ function isSignInResult(value) {
15
+ const result = value;
16
+ return (typeof result?.customerToken === 'string' &&
17
+ typeof result.user?.endUserId === 'string' &&
18
+ typeof result.user.memberId === 'string' &&
19
+ typeof result.user.suiAddress === 'string' &&
20
+ isZkProof(result.signer?.proof) &&
21
+ Number.isFinite(result.signer.maxEpoch) &&
22
+ Number.isFinite(result.signer.expiresAt));
23
+ }
24
+ /**
25
+ * Customer sign-in and signing for one organization. Sign-in happens on OctaP's own page, in a
26
+ * popup: Google's token never reaches this page or your backend. What comes back is the customer, a
27
+ * proof for a signing key that never leaves this page, and a customer token your backend checks with
28
+ * `@octap/sdk`'s `verifyCustomer`. That token is valid for this organization only.
29
+ *
30
+ * Your page's origin must be one of the organization's sign-in origins (console, Developer settings).
31
+ */
11
32
  export class OctapAuth {
12
33
  api;
34
+ apiBaseUrl;
13
35
  store;
14
36
  organizationId;
15
- googleClientId;
16
37
  listeners = new Set();
17
38
  session;
18
- provider;
19
39
  button;
20
- signingIn = false;
40
+ signingIn;
21
41
  /** Changes when the session ends, so a sign-in still running cannot bring it back. */
22
42
  signInGeneration = 0;
23
- /** Changes on each new button, so only the latest nonce can be rendered or used. */
24
- armGeneration = 0;
25
43
  expiryTimer;
26
44
  constructor(options) {
45
+ if (!options?.organizationId)
46
+ throw new TypeError('OctapAuth needs an organizationId.');
27
47
  const fetchFn = options.fetch ?? ((...args) => globalThis.fetch(...args));
28
- this.api = new CoreApi(options.apiBaseUrl, fetchFn, options.timeoutMs ?? DEFAULT_TIMEOUT_MS);
48
+ this.apiBaseUrl = normalizeBaseUrl(options.apiBaseUrl ?? DEFAULT_API_BASE_URL);
49
+ this.api = new CoreApi(this.apiBaseUrl, fetchFn, options.timeoutMs ?? DEFAULT_TIMEOUT_MS);
29
50
  this.organizationId = options.organizationId;
30
- this.googleClientId = options.googleClientId;
31
51
  this.store = createSessionStore(options.persistence ?? 'session', {
32
- apiBaseUrl: normalizeBaseUrl(options.apiBaseUrl),
33
- googleClientId: options.googleClientId,
52
+ apiBaseUrl: this.apiBaseUrl,
34
53
  organizationId: options.organizationId,
35
54
  });
36
55
  this.session = this.store.load();
@@ -56,27 +75,71 @@ export class OctapAuth {
56
75
  };
57
76
  }
58
77
  /**
59
- * Renders Google's button. Key, nonce, enrollment and proof are handled when the customer uses it.
60
- * While a customer is signed in it renders nothing, and appears once they sign out or expire.
78
+ * Opens OctaP's sign-in window and resolves with the customer once they have signed in. Call it
79
+ * from a click handler: browsers block a window opened any other way. Signing in the first time
80
+ * joins this organization's loyalty program. A call while a sign-in is open returns that sign-in.
81
+ */
82
+ signIn(options = {}) {
83
+ if (this.signingIn)
84
+ return this.signingIn;
85
+ const generation = this.signInGeneration;
86
+ const keypair = new Ed25519Keypair();
87
+ const url = new URL(`${this.apiBaseUrl}/v1/identity/sign-in`);
88
+ url.searchParams.set('organizationId', this.organizationId);
89
+ url.searchParams.set('origin', typeof location === 'undefined' ? '' : location.origin);
90
+ url.searchParams.set('ephemeralPublicKey', keypair.getPublicKey().toSuiPublicKey());
91
+ const attempt = openSignInPopup(url, options.signal)
92
+ .then((result) => {
93
+ if (!isSignInResult(result)) {
94
+ throw new OctapAuthError('invalid-response', 'OctaP returned an incomplete sign-in.', { body: result });
95
+ }
96
+ if (generation !== this.signInGeneration) {
97
+ throw new OctapAuthError('sign-in-canceled', 'The customer signed out while signing in.');
98
+ }
99
+ const session = {
100
+ user: { ...result.user },
101
+ token: result.customerToken,
102
+ signer: {
103
+ secretKey: keypair.getSecretKey(),
104
+ maxEpoch: result.signer.maxEpoch,
105
+ expiresAt: result.signer.expiresAt,
106
+ proof: result.signer.proof,
107
+ },
108
+ };
109
+ this.session = session;
110
+ this.store.save(session);
111
+ this.scheduleExpiry();
112
+ this.renderButton();
113
+ this.notify();
114
+ return session.user;
115
+ })
116
+ .finally(() => {
117
+ if (this.signingIn === attempt)
118
+ this.signingIn = undefined;
119
+ });
120
+ this.signingIn = attempt;
121
+ return attempt;
122
+ }
123
+ /**
124
+ * Renders a button into `element` that calls `signIn()`, reporting failures through `onError`.
125
+ * While a customer is signed in it renders nothing, and appears again once they sign out or expire.
61
126
  */
62
- async renderGoogleButton(element, options = {}) {
127
+ renderSignInButton(element, options = {}) {
63
128
  this.button = { element, options };
64
- this.provider = createGoogleProvider(this.googleClientId, options.button);
65
- if (!this.currentUser)
66
- await this.arm();
129
+ this.renderButton();
67
130
  }
68
131
  /**
69
- * The id_token for your backend to check with `@octap/sdk`'s `verifyCustomer`. Google's token lasts
70
- * about an hour. When it has expired the customer is signed out, so the button returns for a new one.
132
+ * The customer token for your backend to check with `@octap/sdk`'s `verifyCustomer`. It lasts up
133
+ * to an hour; once it has expired the customer is signed out, so the button returns.
71
134
  */
72
135
  async getIdToken() {
73
- const { idToken } = this.requireSession();
74
- const expiry = idTokenExpiry(idToken);
136
+ const { token } = this.requireSession();
137
+ const expiry = tokenExpiry(token);
75
138
  if (expiry !== undefined && Date.now() >= expiry * 1000) {
76
- this.expireSession();
77
- throw new OctapAuthError('token-expired', 'The sign-in token expired. Sign in again.');
139
+ this.endSession();
140
+ throw new OctapAuthError('token-expired', 'The sign-in expired. Sign in again.');
78
141
  }
79
- return idToken;
142
+ return token;
80
143
  }
81
144
  /** Lower-level signing: returns the zkLogin signature over base64 transaction bytes. */
82
145
  async signTransaction(transactionBytes) {
@@ -120,34 +183,27 @@ export class OctapAuth {
120
183
  : new OctapAuthError('outcome-unknown', 'The result of this transaction is not known yet. Check the claim before trying again.', err instanceof OctapAuthError ? { status: err.status, body: err.body } : {});
121
184
  }
122
185
  }
123
- /** Always ends the session. A button that cannot return is reported through `onError`. */
186
+ /** Ends the session on this page. */
124
187
  async signOut() {
125
- this.provider?.signOut();
126
188
  this.endSession();
127
- // The button's nonce belongs to a key this session may have used, so issue a fresh one.
128
- await this.rearm();
129
189
  }
130
190
  requireSession() {
131
191
  if (!this.session) {
132
192
  throw new OctapAuthError('not-signed-in', 'No customer is signed in.');
133
193
  }
134
194
  if (Date.now() >= this.session.signer.expiresAt) {
135
- this.expireSession();
195
+ this.endSession();
136
196
  throw new OctapAuthError('session-expired', 'The signing session expired. Sign in again.');
137
197
  }
138
198
  return this.session;
139
199
  }
140
- expireSession() {
141
- this.endSession();
142
- void this.rearm();
143
- }
144
200
  endSession() {
145
201
  const hadSession = this.session !== null;
146
202
  this.signInGeneration++;
147
- this.signingIn = false;
148
203
  this.store.clear();
149
204
  this.session = null;
150
205
  this.scheduleExpiry();
206
+ this.renderButton();
151
207
  if (hadSession)
152
208
  this.notify();
153
209
  }
@@ -161,7 +217,7 @@ export class OctapAuth {
161
217
  const remaining = this.session.signer.expiresAt - Date.now();
162
218
  this.expiryTimer = window.setTimeout(() => {
163
219
  if (this.session && Date.now() >= this.session.signer.expiresAt)
164
- this.expireSession();
220
+ this.endSession();
165
221
  else
166
222
  this.scheduleExpiry();
167
223
  }, Math.min(Math.max(remaining, 0), MAX_TIMER_MS));
@@ -182,7 +238,7 @@ export class OctapAuth {
182
238
  reportError(err) {
183
239
  const error = err instanceof OctapAuthError
184
240
  ? err
185
- : new OctapAuthError('provider-unavailable', err instanceof Error ? err.message : String(err));
241
+ : new OctapAuthError('api-error', err instanceof Error ? err.message : String(err));
186
242
  try {
187
243
  this.button?.options.onError?.(error);
188
244
  }
@@ -190,71 +246,24 @@ export class OctapAuth {
190
246
  console.error('The onError handler threw:', handlerError);
191
247
  }
192
248
  }
193
- /** Puts a usable button back, if one was rendered, reporting rather than throwing a failure. */
194
- async rearm() {
195
- if (!this.button)
249
+ /** Shows the sign-in button while nobody is signed in, and nothing while someone is. */
250
+ renderButton() {
251
+ if (!this.button || typeof document === 'undefined')
196
252
  return;
197
- await this.arm().catch((err) => this.reportError(err));
198
- }
199
- /** Prepares a key and nonce and renders the button with them. A newer call replaces an older one. */
200
- async arm() {
201
- const generation = ++this.armGeneration;
202
- const pending = await PendingSignIn.start(this.api);
203
- if (generation !== this.armGeneration)
253
+ const { element, options } = this.button;
254
+ if (this.currentUser) {
255
+ element.replaceChildren();
204
256
  return;
205
- await this.provider.render(this.button.element, pending.nonce, {
206
- onIdToken: (idToken) => {
207
- if (generation === this.armGeneration)
208
- void this.completeSignIn(pending, idToken);
209
- },
210
- onCanceled: () => {
211
- if (generation === this.armGeneration) {
212
- this.reportError(new OctapAuthError('sign-in-canceled', 'Google sign-in was canceled.'));
213
- }
214
- },
215
- });
216
- }
217
- async completeSignIn(pending, idToken) {
218
- if (this.signingIn)
219
- return;
220
- this.signingIn = true;
221
- const generation = this.signInGeneration;
222
- const superseded = () => generation !== this.signInGeneration;
223
- try {
224
- pending.assertIssuedForThisAttempt(idToken);
225
- const { suiAddress } = await this.api.post('/v1/identity/google-login', { idToken });
226
- if (superseded())
227
- return;
228
- const { endUserId, organizationEndUserId } = await this.api.post(`/v1/identity/organizations/${encodeURIComponent(this.organizationId)}/enroll`, { idToken });
229
- if (superseded())
230
- return;
231
- if (typeof suiAddress !== 'string' ||
232
- typeof endUserId !== 'string' ||
233
- typeof organizationEndUserId !== 'string') {
234
- throw new OctapAuthError('invalid-response', 'OctaP returned an incomplete customer.');
235
- }
236
- const signer = await pending.prove(this.api, idToken);
237
- if (superseded())
238
- return;
239
- this.session = { user: { endUserId, memberId: organizationEndUserId, suiAddress }, idToken, signer };
240
- this.store.save(this.session);
241
- this.scheduleExpiry();
242
- // A button armed for another attempt must not outlive this session's sign-in.
243
- this.armGeneration++;
244
- this.button?.element.replaceChildren();
245
- this.notify();
246
- }
247
- catch (err) {
248
- if (superseded())
249
- return;
250
- this.reportError(err);
251
- // A nonce is good for one attempt, so a failure must leave a usable button behind.
252
- await this.rearm();
253
- }
254
- finally {
255
- if (!superseded())
256
- this.signingIn = false;
257
257
  }
258
+ const button = document.createElement('button');
259
+ button.type = 'button';
260
+ button.textContent = options.label ?? 'Sign in with Google';
261
+ if (options.className)
262
+ button.className = options.className;
263
+ button.addEventListener('click', () => {
264
+ this.signIn().catch((err) => this.reportError(err));
265
+ });
266
+ element.replaceChildren(button);
258
267
  }
259
268
  }
260
269
  export function createOctapAuth(options) {
package/dist/auth.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"auth.js","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,gBAAgB,EAAuB,MAAM,eAAe,CAAC;AAC/E,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,oBAAoB,EAAwB,MAAM,sBAAsB,CAAC;AAClF,OAAO,EACL,kBAAkB,GAKnB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AA2DpF,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAClC,0FAA0F;AAC1F,MAAM,mBAAmB,GAAG,MAAM,CAAC;AACnC,sDAAsD;AACtD,MAAM,YAAY,GAAG,aAAa,CAAC;AAEnC,MAAM,OAAO,SAAS;IACH,GAAG,CAAU;IACb,KAAK,CAAe;IACpB,cAAc,CAAS;IACvB,cAAc,CAAS;IACvB,SAAS,GAAG,IAAI,GAAG,EAAqB,CAAC;IAClD,OAAO,CAAuB;IAC9B,QAAQ,CAAmB;IAC3B,MAAM,CAAoD;IAC1D,SAAS,GAAG,KAAK,CAAC;IAC1B,sFAAsF;IAC9E,gBAAgB,GAAG,CAAC,CAAC;IAC7B,oFAAoF;IAC5E,aAAa,GAAG,CAAC,CAAC;IAClB,WAAW,CAAU;IAE7B,YAAY,OAAyB;QACnC,MAAM,OAAO,GAAG,OAAO,CAAC,KAAK,IAAI,CAAC,CAAC,GAAG,IAA8B,EAAE,EAAE,CAAC,UAAU,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC;QACpG,IAAI,CAAC,GAAG,GAAG,IAAI,OAAO,CAAC,OAAO,CAAC,UAAU,EAAE,OAAO,EAAE,OAAO,CAAC,SAAS,IAAI,kBAAkB,CAAC,CAA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