@asseteragmbh/wallet-connector 0.2.0 → 0.2.1

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/dist/index.d.cts CHANGED
@@ -1,5 +1,18 @@
1
- export { CONNECT_PATH, DisconnectMessage, EventMessage, MESSAGE_PREFIX, ONBOARD_PATH, OnboardCancelledMessage, OnboardedMessage, PROTOCOL_VERSION, PartnerToWalletMessage, ReadyMessage, RequestMessage, ResponseMessage, RpcError, RpcErrorCode, SUPPORTED_METHODS, SupportedMethod, WalletToPartnerMessage, connectUrl, isCaip2EvmChain, isDisconnectMessage, isEventMessage, isOnboardCancelledMessage, isOnboardedMessage, isReadyMessage, isRequestMessage, isResponseMessage, isSupportedMethod, onboardUrl } from './protocol.cjs';
2
- export { A as AsseteraWalletProvider, a as AsseteraWalletProviderOptions, P as ProviderEvent, b as ProviderListener, c as ProviderRpcError, R as RequestArguments, d as createAsseteraWalletProvider } from './provider-BEIsX3q_.cjs';
1
+ import { SignInHint, WalletSecurityStatus } from './protocol.cjs';
2
+ export { CONNECT_PATH, DisconnectMessage, EventMessage, MANAGE_PATH, MESSAGE_PREFIX, ONBOARD_PATH, OnboardCancelledMessage, OnboardedMessage, PROTOCOL_VERSION, PartnerToWalletMessage, ReadyMessage, RequestMessage, ResponseMessage, RpcError, RpcErrorCode, SIGN_IN_HINTS, SUPPORTED_METHODS, SecurityMessage, SupportedMethod, WalletProtection, WalletToPartnerMessage, connectUrl, isCaip2EvmChain, isDisconnectMessage, isEventMessage, isOnboardCancelledMessage, isOnboardedMessage, isReadyMessage, isRequestMessage, isResponseMessage, isSecurityMessage, isSignInHint, isSupportedMethod, manageUrl, onboardUrl } from './protocol.cjs';
3
+ export { A as AsseteraWalletProvider, a as AsseteraWalletProviderOptions, P as ProviderEvent, b as ProviderListener, c as ProviderRpcError, R as RequestArguments, d as createAsseteraWalletProvider } from './provider-Cn9rPKZh.cjs';
4
+
5
+ /**
6
+ * Onboarding opener for the Assetera Wallet: the partner side of the `/onboard` wizard (AO-1274).
7
+ *
8
+ * A tied-agent bank site shows a "Create an Assetera wallet" button. On the click, this module opens the wallet
9
+ * pop-up in onboarding mode synchronously (so the browser treats it as part of the click) and waits for the
10
+ * wizard to post the new wallet address back. While the pop-up is open the partner page shows a dimming
11
+ * overlay; the overlay is plain DOM (no React, no CSS files) so any partner can drop this in.
12
+ *
13
+ * The wallet's `/onboard` page is the pop-up side and speaks the same protocol in `./protocol`, but it uses the
14
+ * message types and the `ONBOARD_PATH` from there, so the two sides cannot drift apart.
15
+ */
3
16
 
4
17
  /** Why {@link openAsseteraOnboarding} rejected. */
5
18
  type OnboardingErrorCode = "popup_blocked" | "closed" | "cancelled" | "refused" | "failed" | "invalid_options";
@@ -38,7 +51,7 @@ interface OverlayLabels {
38
51
  }
39
52
  /** Options for {@link openAsseteraOnboarding}. */
40
53
  interface OnboardingOptions {
41
- /** Base URL of the wallet origin, e.g. `https://wallet.playground.assetera.com`. */
54
+ /** Base URL of the wallet origin, e.g. `https://wallet.wallet-staging.assetera.com`. */
42
55
  walletUrl: string;
43
56
  /** CAIP-2 chain id the new wallet should be created on, e.g. `eip155:80002`. An invalid value rejects with `invalid_options`. */
44
57
  chain: string;
@@ -52,6 +65,8 @@ interface OnboardingOptions {
52
65
  partnerName?: string;
53
66
  /** Ask for one more wallet even when the client already has one ("Create another Assetera Wallet"). */
54
67
  addWallet?: boolean;
68
+ /** Sign-in hint passed as `signIn`, e.g. `"assetera-marketplace"`. Only a hint; the wallet may ignore it. */
69
+ signIn?: SignInHint;
55
70
  /** Injectable `window` for tests; defaults to `globalThis.window`. */
56
71
  window?: Window;
57
72
  }
@@ -70,4 +85,57 @@ interface OnboardingOptions {
70
85
  */
71
86
  declare function openAsseteraOnboarding(options: OnboardingOptions): Promise<OnboardingResult>;
72
87
 
73
- export { OnboardingError, type OnboardingErrorCode, type OnboardingOptions, type OnboardingResult, type OverlayLabels, openAsseteraOnboarding };
88
+ /**
89
+ * Manage-wallet opener for the Assetera Wallet: the partner side of the `/manage` pop-up (AO-1436).
90
+ *
91
+ * A partner page shows a "Manage wallet" button. On the click this module opens the wallet pop-up on the manage
92
+ * route synchronously (so the browser treats it as part of the click). The client sees the wallet accounts and
93
+ * the wallet security (passkeys, authenticator app, recovery codes) and can change them. The pop-up never
94
+ * answers `request` messages; it posts `security` messages while it is open.
95
+ */
96
+
97
+ /** Why {@link openAsseteraWalletManager} threw. */
98
+ type ManagerErrorCode = "popup_blocked" | "invalid_options";
99
+ /** Error thrown by {@link openAsseteraWalletManager}. `code` is stable and safe to branch on. */
100
+ declare class ManagerError extends Error {
101
+ readonly code: ManagerErrorCode;
102
+ constructor(code: ManagerErrorCode, message: string);
103
+ }
104
+ /** Options for {@link openAsseteraWalletManager}. */
105
+ interface WalletManagerOptions {
106
+ /** Base URL of the wallet origin, e.g. `https://wallet.wallet-staging.assetera.com`. */
107
+ walletUrl: string;
108
+ /** Sign-in hint passed as `signIn`, e.g. `"assetera-marketplace"`. Only a hint; the wallet may ignore it. */
109
+ signIn?: SignInHint;
110
+ /** Language passed as `lang`, e.g. `"en"` or `"de"`. */
111
+ locale?: string;
112
+ /** `window.open` feature string. Defaults to a centred `"popup,width=440,height=760,left=…,top=…"`. */
113
+ popupFeatures?: string;
114
+ /** Called for every `security` message from the pop-up. */
115
+ onSecurity?: (status: WalletSecurityStatus) => void;
116
+ /** Injectable `window` for tests; defaults to `globalThis.window`. */
117
+ window?: Window;
118
+ }
119
+ /** The open manage pop-up, controlled by the partner. */
120
+ interface WalletManager {
121
+ /** Close the pop-up and remove the listener and the close timer. Safe to call more than once. */
122
+ close: () => void;
123
+ /** Resolves when the pop-up is closed, by the partner or by the client. */
124
+ closed: Promise<void>;
125
+ /** The last security status the pop-up sent, or `undefined` when none arrived yet. */
126
+ lastSecurity: () => WalletSecurityStatus | undefined;
127
+ }
128
+ /**
129
+ * Open the manage-wallet pop-up for the Assetera Wallet and return a handle to it.
130
+ *
131
+ * Call this from a user click (a button handler). `window.open` runs synchronously inside the call, before any
132
+ * `await`, so the browser allows it; when the browser blocks the pop-up this throws `ManagerError` with code
133
+ * `popup_blocked`.
134
+ *
135
+ * The pop-up checks the `origin` query parameter against the wallet's partner list, posts `ready` to
136
+ * `window.opener` and then posts `security` messages. Messages are accepted only when they come from the wallet
137
+ * origin AND from the pop-up that was opened here. The pop-up does not answer `request` messages.
138
+ */
139
+ declare function openAsseteraWalletManager(options: WalletManagerOptions): WalletManager;
140
+
141
+ export { ManagerError, type ManagerErrorCode, OnboardingError, type OnboardingErrorCode, type OnboardingOptions, type OnboardingResult, type OverlayLabels, SignInHint, type WalletManager, type WalletManagerOptions, WalletSecurityStatus, openAsseteraOnboarding, openAsseteraWalletManager };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,18 @@
1
- export { CONNECT_PATH, DisconnectMessage, EventMessage, MESSAGE_PREFIX, ONBOARD_PATH, OnboardCancelledMessage, OnboardedMessage, PROTOCOL_VERSION, PartnerToWalletMessage, ReadyMessage, RequestMessage, ResponseMessage, RpcError, RpcErrorCode, SUPPORTED_METHODS, SupportedMethod, WalletToPartnerMessage, connectUrl, isCaip2EvmChain, isDisconnectMessage, isEventMessage, isOnboardCancelledMessage, isOnboardedMessage, isReadyMessage, isRequestMessage, isResponseMessage, isSupportedMethod, onboardUrl } from './protocol.js';
2
- export { A as AsseteraWalletProvider, a as AsseteraWalletProviderOptions, P as ProviderEvent, b as ProviderListener, c as ProviderRpcError, R as RequestArguments, d as createAsseteraWalletProvider } from './provider-BEIsX3q_.js';
1
+ import { SignInHint, WalletSecurityStatus } from './protocol.js';
2
+ export { CONNECT_PATH, DisconnectMessage, EventMessage, MANAGE_PATH, MESSAGE_PREFIX, ONBOARD_PATH, OnboardCancelledMessage, OnboardedMessage, PROTOCOL_VERSION, PartnerToWalletMessage, ReadyMessage, RequestMessage, ResponseMessage, RpcError, RpcErrorCode, SIGN_IN_HINTS, SUPPORTED_METHODS, SecurityMessage, SupportedMethod, WalletProtection, WalletToPartnerMessage, connectUrl, isCaip2EvmChain, isDisconnectMessage, isEventMessage, isOnboardCancelledMessage, isOnboardedMessage, isReadyMessage, isRequestMessage, isResponseMessage, isSecurityMessage, isSignInHint, isSupportedMethod, manageUrl, onboardUrl } from './protocol.js';
3
+ export { A as AsseteraWalletProvider, a as AsseteraWalletProviderOptions, P as ProviderEvent, b as ProviderListener, c as ProviderRpcError, R as RequestArguments, d as createAsseteraWalletProvider } from './provider-OStA8Fqx.js';
4
+
5
+ /**
6
+ * Onboarding opener for the Assetera Wallet: the partner side of the `/onboard` wizard (AO-1274).
7
+ *
8
+ * A tied-agent bank site shows a "Create an Assetera wallet" button. On the click, this module opens the wallet
9
+ * pop-up in onboarding mode synchronously (so the browser treats it as part of the click) and waits for the
10
+ * wizard to post the new wallet address back. While the pop-up is open the partner page shows a dimming
11
+ * overlay; the overlay is plain DOM (no React, no CSS files) so any partner can drop this in.
12
+ *
13
+ * The wallet's `/onboard` page is the pop-up side and speaks the same protocol in `./protocol`, but it uses the
14
+ * message types and the `ONBOARD_PATH` from there, so the two sides cannot drift apart.
15
+ */
3
16
 
4
17
  /** Why {@link openAsseteraOnboarding} rejected. */
5
18
  type OnboardingErrorCode = "popup_blocked" | "closed" | "cancelled" | "refused" | "failed" | "invalid_options";
@@ -38,7 +51,7 @@ interface OverlayLabels {
38
51
  }
39
52
  /** Options for {@link openAsseteraOnboarding}. */
40
53
  interface OnboardingOptions {
41
- /** Base URL of the wallet origin, e.g. `https://wallet.playground.assetera.com`. */
54
+ /** Base URL of the wallet origin, e.g. `https://wallet.wallet-staging.assetera.com`. */
42
55
  walletUrl: string;
43
56
  /** CAIP-2 chain id the new wallet should be created on, e.g. `eip155:80002`. An invalid value rejects with `invalid_options`. */
44
57
  chain: string;
@@ -52,6 +65,8 @@ interface OnboardingOptions {
52
65
  partnerName?: string;
53
66
  /** Ask for one more wallet even when the client already has one ("Create another Assetera Wallet"). */
54
67
  addWallet?: boolean;
68
+ /** Sign-in hint passed as `signIn`, e.g. `"assetera-marketplace"`. Only a hint; the wallet may ignore it. */
69
+ signIn?: SignInHint;
55
70
  /** Injectable `window` for tests; defaults to `globalThis.window`. */
56
71
  window?: Window;
57
72
  }
@@ -70,4 +85,57 @@ interface OnboardingOptions {
70
85
  */
71
86
  declare function openAsseteraOnboarding(options: OnboardingOptions): Promise<OnboardingResult>;
72
87
 
73
- export { OnboardingError, type OnboardingErrorCode, type OnboardingOptions, type OnboardingResult, type OverlayLabels, openAsseteraOnboarding };
88
+ /**
89
+ * Manage-wallet opener for the Assetera Wallet: the partner side of the `/manage` pop-up (AO-1436).
90
+ *
91
+ * A partner page shows a "Manage wallet" button. On the click this module opens the wallet pop-up on the manage
92
+ * route synchronously (so the browser treats it as part of the click). The client sees the wallet accounts and
93
+ * the wallet security (passkeys, authenticator app, recovery codes) and can change them. The pop-up never
94
+ * answers `request` messages; it posts `security` messages while it is open.
95
+ */
96
+
97
+ /** Why {@link openAsseteraWalletManager} threw. */
98
+ type ManagerErrorCode = "popup_blocked" | "invalid_options";
99
+ /** Error thrown by {@link openAsseteraWalletManager}. `code` is stable and safe to branch on. */
100
+ declare class ManagerError extends Error {
101
+ readonly code: ManagerErrorCode;
102
+ constructor(code: ManagerErrorCode, message: string);
103
+ }
104
+ /** Options for {@link openAsseteraWalletManager}. */
105
+ interface WalletManagerOptions {
106
+ /** Base URL of the wallet origin, e.g. `https://wallet.wallet-staging.assetera.com`. */
107
+ walletUrl: string;
108
+ /** Sign-in hint passed as `signIn`, e.g. `"assetera-marketplace"`. Only a hint; the wallet may ignore it. */
109
+ signIn?: SignInHint;
110
+ /** Language passed as `lang`, e.g. `"en"` or `"de"`. */
111
+ locale?: string;
112
+ /** `window.open` feature string. Defaults to a centred `"popup,width=440,height=760,left=…,top=…"`. */
113
+ popupFeatures?: string;
114
+ /** Called for every `security` message from the pop-up. */
115
+ onSecurity?: (status: WalletSecurityStatus) => void;
116
+ /** Injectable `window` for tests; defaults to `globalThis.window`. */
117
+ window?: Window;
118
+ }
119
+ /** The open manage pop-up, controlled by the partner. */
120
+ interface WalletManager {
121
+ /** Close the pop-up and remove the listener and the close timer. Safe to call more than once. */
122
+ close: () => void;
123
+ /** Resolves when the pop-up is closed, by the partner or by the client. */
124
+ closed: Promise<void>;
125
+ /** The last security status the pop-up sent, or `undefined` when none arrived yet. */
126
+ lastSecurity: () => WalletSecurityStatus | undefined;
127
+ }
128
+ /**
129
+ * Open the manage-wallet pop-up for the Assetera Wallet and return a handle to it.
130
+ *
131
+ * Call this from a user click (a button handler). `window.open` runs synchronously inside the call, before any
132
+ * `await`, so the browser allows it; when the browser blocks the pop-up this throws `ManagerError` with code
133
+ * `popup_blocked`.
134
+ *
135
+ * The pop-up checks the `origin` query parameter against the wallet's partner list, posts `ready` to
136
+ * `window.opener` and then posts `security` messages. Messages are accepted only when they come from the wallet
137
+ * origin AND from the pop-up that was opened here. The pop-up does not answer `request` messages.
138
+ */
139
+ declare function openAsseteraWalletManager(options: WalletManagerOptions): WalletManager;
140
+
141
+ export { ManagerError, type ManagerErrorCode, OnboardingError, type OnboardingErrorCode, type OnboardingOptions, type OnboardingResult, type OverlayLabels, SignInHint, type WalletManager, type WalletManagerOptions, WalletSecurityStatus, openAsseteraOnboarding, openAsseteraWalletManager };
package/dist/index.js CHANGED
@@ -1,6 +1,19 @@
1
- export { ProviderRpcError, createAsseteraWalletProvider } from './chunk-PD2FAZ7O.js';
2
- import { isCaip2EvmChain, onboardUrl, isOnboardedMessage, isOnboardCancelledMessage, isResponseMessage, RpcErrorCode, PROTOCOL_VERSION, MESSAGE_PREFIX } from './chunk-SU2ZKBZD.js';
3
- export { CONNECT_PATH, MESSAGE_PREFIX, ONBOARD_PATH, PROTOCOL_VERSION, RpcErrorCode, SUPPORTED_METHODS, connectUrl, isCaip2EvmChain, isDisconnectMessage, isEventMessage, isOnboardCancelledMessage, isOnboardedMessage, isReadyMessage, isRequestMessage, isResponseMessage, isSupportedMethod, onboardUrl } from './chunk-SU2ZKBZD.js';
1
+ export { ProviderRpcError, createAsseteraWalletProvider } from './chunk-YJHLKN7O.js';
2
+ import { isCaip2EvmChain, onboardUrl, manageUrl, isOnboardedMessage, isOnboardCancelledMessage, isSecurityMessage, isResponseMessage, RpcErrorCode, PROTOCOL_VERSION, MESSAGE_PREFIX } from './chunk-H7PEM735.js';
3
+ export { CONNECT_PATH, MANAGE_PATH, MESSAGE_PREFIX, ONBOARD_PATH, PROTOCOL_VERSION, RpcErrorCode, SIGN_IN_HINTS, SUPPORTED_METHODS, connectUrl, isCaip2EvmChain, isDisconnectMessage, isEventMessage, isOnboardCancelledMessage, isOnboardedMessage, isReadyMessage, isRequestMessage, isResponseMessage, isSecurityMessage, isSignInHint, isSupportedMethod, manageUrl, onboardUrl } from './chunk-H7PEM735.js';
4
+
5
+ // src/popup.ts
6
+ var POPUP_WIDTH = 440;
7
+ var POPUP_HEIGHT = 760;
8
+ function defaultPopupFeatures(win) {
9
+ const screenX = Number.isFinite(win.screenX) ? win.screenX : 0;
10
+ const screenY = Number.isFinite(win.screenY) ? win.screenY : 0;
11
+ const outerWidth = Number.isFinite(win.outerWidth) ? win.outerWidth : POPUP_WIDTH;
12
+ const outerHeight = Number.isFinite(win.outerHeight) ? win.outerHeight : POPUP_HEIGHT;
13
+ const left = Math.max(0, Math.round(screenX + (outerWidth - POPUP_WIDTH) / 2));
14
+ const top = Math.max(0, Math.round(screenY + (outerHeight - POPUP_HEIGHT) / 2));
15
+ return `popup,width=${POPUP_WIDTH},height=${POPUP_HEIGHT},left=${left},top=${top}`;
16
+ }
4
17
 
5
18
  // src/onboarding.ts
6
19
  var OnboardingError = class extends Error {
@@ -12,8 +25,6 @@ var OnboardingError = class extends Error {
12
25
  }
13
26
  };
14
27
  var POPUP_NAME = "assetera-wallet-onboarding";
15
- var POPUP_WIDTH = 440;
16
- var POPUP_HEIGHT = 760;
17
28
  var CLOSE_POLL_MS = 500;
18
29
  var OVERLAY_Z_INDEX = 2147483e3;
19
30
  var DEFAULT_LABELS = {
@@ -23,15 +34,6 @@ var DEFAULT_LABELS = {
23
34
  cancel: "Cancel",
24
35
  blocked: "Your browser blocked the Assetera Wallet window. Allow pop-ups for this site and try again."
25
36
  };
26
- function defaultPopupFeatures(win) {
27
- const screenX = Number.isFinite(win.screenX) ? win.screenX : 0;
28
- const screenY = Number.isFinite(win.screenY) ? win.screenY : 0;
29
- const outerWidth = Number.isFinite(win.outerWidth) ? win.outerWidth : POPUP_WIDTH;
30
- const outerHeight = Number.isFinite(win.outerHeight) ? win.outerHeight : POPUP_HEIGHT;
31
- const left = Math.max(0, Math.round(screenX + (outerWidth - POPUP_WIDTH) / 2));
32
- const top = Math.max(0, Math.round(screenY + (outerHeight - POPUP_HEIGHT) / 2));
33
- return `popup,width=${POPUP_WIDTH},height=${POPUP_HEIGHT},left=${left},top=${top}`;
34
- }
35
37
  function resolveLabels(options) {
36
38
  const overrides = typeof options.overlay === "object" && options.overlay !== null ? options.overlay : {};
37
39
  const partnerName = options.partnerName;
@@ -154,7 +156,8 @@ function openAsseteraOnboarding(options) {
154
156
  onboardUrl(options.walletUrl, targetWindow.location.origin, {
155
157
  chain: options.chain,
156
158
  ...options.locale === void 0 ? {} : { locale: options.locale },
157
- ...options.addWallet ? { add: true } : {}
159
+ ...options.addWallet ? { add: true } : {},
160
+ ...options.signIn === void 0 ? {} : { signIn: options.signIn }
158
161
  }),
159
162
  POPUP_NAME,
160
163
  options.popupFeatures ?? defaultPopupFeatures(targetWindow)
@@ -281,6 +284,89 @@ function openAsseteraOnboarding(options) {
281
284
  });
282
285
  }
283
286
 
284
- export { OnboardingError, openAsseteraOnboarding };
287
+ // src/manage.ts
288
+ var ManagerError = class extends Error {
289
+ code;
290
+ constructor(code, message) {
291
+ super(message);
292
+ this.name = "ManagerError";
293
+ this.code = code;
294
+ }
295
+ };
296
+ var POPUP_NAME2 = "assetera-wallet-manage";
297
+ var CLOSE_POLL_MS2 = 500;
298
+ function openAsseteraWalletManager(options) {
299
+ const requestedWindow = options.window ?? (typeof window === "undefined" ? void 0 : window);
300
+ if (!requestedWindow) {
301
+ throw new ManagerError("invalid_options", "The Assetera Wallet manager can only run in a browser.");
302
+ }
303
+ const targetWindow = requestedWindow;
304
+ let walletOrigin;
305
+ try {
306
+ walletOrigin = new URL(options.walletUrl).origin;
307
+ } catch {
308
+ throw new ManagerError("invalid_options", `"${options.walletUrl}" is not a valid wallet URL.`);
309
+ }
310
+ const popup = targetWindow.open(
311
+ manageUrl(options.walletUrl, targetWindow.location.origin, {
312
+ ...options.locale === void 0 ? {} : { locale: options.locale },
313
+ ...options.signIn === void 0 ? {} : { signIn: options.signIn }
314
+ }),
315
+ POPUP_NAME2,
316
+ options.popupFeatures ?? defaultPopupFeatures(targetWindow)
317
+ );
318
+ if (!popup) {
319
+ throw new ManagerError(
320
+ "popup_blocked",
321
+ "Your browser blocked the Assetera Wallet window. Allow pop-ups for this site and try again."
322
+ );
323
+ }
324
+ const activePopup = popup;
325
+ let finished = false;
326
+ let lastSecurity;
327
+ let closeTimer = null;
328
+ let resolveClosed;
329
+ const closed = new Promise((resolve) => {
330
+ resolveClosed = resolve;
331
+ });
332
+ function cleanup() {
333
+ if (finished) return;
334
+ finished = true;
335
+ targetWindow.removeEventListener("message", onMessage);
336
+ if (closeTimer !== null) {
337
+ clearInterval(closeTimer);
338
+ closeTimer = null;
339
+ }
340
+ resolveClosed();
341
+ }
342
+ function close() {
343
+ cleanup();
344
+ if (!activePopup.closed) activePopup.close();
345
+ }
346
+ function onMessage(event) {
347
+ if (event.origin !== walletOrigin) return;
348
+ if (event.source !== activePopup) return;
349
+ const data = event.data;
350
+ if (!isSecurityMessage(data)) return;
351
+ const status = {
352
+ protection: data.data.protection,
353
+ passkeys: data.data.passkeys,
354
+ authenticatorApps: data.data.authenticatorApps
355
+ };
356
+ lastSecurity = status;
357
+ options.onSecurity?.(status);
358
+ }
359
+ targetWindow.addEventListener("message", onMessage);
360
+ closeTimer = setInterval(() => {
361
+ if (activePopup.closed) cleanup();
362
+ }, CLOSE_POLL_MS2);
363
+ return {
364
+ close,
365
+ closed,
366
+ lastSecurity: () => lastSecurity
367
+ };
368
+ }
369
+
370
+ export { ManagerError, OnboardingError, openAsseteraOnboarding, openAsseteraWalletManager };
285
371
  //# sourceMappingURL=index.js.map
286
372
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/onboarding.ts"],"names":[],"mappings":";;;;;AA6BO,IAAM,eAAA,GAAN,cAA8B,KAAA,CAAM;AAAA,EAChC,IAAA;AAAA,EAET,WAAA,CAAY,MAA2B,OAAA,EAAiB;AACtD,IAAA,KAAA,CAAM,OAAO,CAAA;AACb,IAAA,IAAA,CAAK,IAAA,GAAO,iBAAA;AACZ,IAAA,IAAA,CAAK,IAAA,GAAO,IAAA;AAAA,EACd;AACF;AAoDA,IAAM,UAAA,GAAa,4BAAA;AACnB,IAAM,WAAA,GAAc,GAAA;AACpB,IAAM,YAAA,GAAe,GAAA;AACrB,IAAM,aAAA,GAAgB,GAAA;AACtB,IAAM,eAAA,GAAkB,SAAA;AAExB,IAAM,cAAA,GAA0C;AAAA,EAC9C,KAAA,EAAO,wCAAA;AAAA,EACP,IAAA,EAAM,mHAAA;AAAA,EACN,KAAA,EAAO,wBAAA;AAAA,EACP,MAAA,EAAQ,QAAA;AAAA,EACR,OAAA,EAAS;AACX,CAAA;AAOA,SAAS,qBAAqB,GAAA,EAAqB;AACjD,EAAA,MAAM,UAAU,MAAA,CAAO,QAAA,CAAS,IAAI,OAAO,CAAA,GAAI,IAAI,OAAA,GAAU,CAAA;AAC7D,EAAA,MAAM,UAAU,MAAA,CAAO,QAAA,CAAS,IAAI,OAAO,CAAA,GAAI,IAAI,OAAA,GAAU,CAAA;AAC7D,EAAA,MAAM,aAAa,MAAA,CAAO,QAAA,CAAS,IAAI,UAAU,CAAA,GAAI,IAAI,UAAA,GAAa,WAAA;AACtE,EAAA,MAAM,cAAc,MAAA,CAAO,QAAA,CAAS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,CAAQ,MAAA,CAAO,KAAK,EAAE,CAAA;AACtB,QAAA,IAAI,WAAW,IAAA,EAAM;AACnB,UAAA,KAAA,CAAM,MAAA;AAAA,YACJ,IAAI,eAAA;AAAA,cACF,IAAA,CAAK,KAAA,CAAM,IAAA,KAAS,YAAA,CAAa,eAAe,WAAA,GAAc,QAAA;AAAA,cAC9D,KAAK,KAAA,CAAM;AAAA;AACb,WACF;AAAA,QACF,CAAA,MAAA,IAAW,OAAO,IAAA,CAAK,MAAA,KAAW,YAAY,kBAAA,CAAmB,IAAA,CAAK,IAAA,CAAK,MAAM,CAAA,EAAG;AAClF,UAAA,KAAA,CAAM,OAAA,CAAQ,KAAK,MAAuB,CAAA;AAAA,QAC5C,CAAA,MAAO;AACL,UAAA,KAAA,CAAM,MAAA,CAAO,IAAI,eAAA,CAAgB,QAAA,EAAU,4CAA4C,CAAC,CAAA;AAAA,QAC1F;AAAA,MACF;AAAA,IACF;AAEA,IAAA,YAAA,CAAa,gBAAA,CAAiB,WAAW,SAAS,CAAA;AAClD,IAAA,UAAA,GAAa,YAAY,MAAM;AAC7B,MAAA,IAAI,CAAC,YAAY,MAAA,EAAQ;AACzB,MAAA,IAAI,SAAA,EAAW;AACb,QAAA,KAAA,EAAM;AACN,QAAA;AAAA,MACF;AACA,MAAA,IAAA;AAAA,QACE,IAAI,eAAA,CAAgB,QAAA,EAAU,mEAAmE;AAAA,OACnG;AAAA,IACF,GAAG,aAAa,CAAA;AAEhB,IAAA,IAAI,cAAA,EAAgB;AAClB,MAAA,OAAA,GAAU,WAAA,CAAY,cAAc,MAAA,EAAQ;AAAA,QAC1C,OAAA,EAAS,MAAM,WAAA,CAAY,KAAA,EAAM;AAAA,QACjC,QAAA,EAAU;AAAA,OACX,CAAA;AAAA,IACH;AAAA,EACF,CAAC,CAAA;AACH","file":"index.js","sourcesContent":["/**\n * Onboarding opener for the Assetera Wallet: the partner side of the `/onboard` wizard (AO-1274).\n *\n * A tied-agent bank site shows a \"Create an Assetera wallet\" button. On the click, this module opens the wallet\n * pop-up in onboarding mode synchronously (so the browser treats it as part of the click) and waits for the\n * wizard to post the new wallet address back. While the pop-up is open the partner page shows a dimming\n * overlay; the overlay is plain DOM (no React, no CSS files) so any partner can drop this in.\n *\n * The wallet's `/onboard` page is the pop-up side and speaks the same protocol in `./protocol`, but it uses the\n * message types and the `ONBOARD_PATH` from there, so the two sides cannot drift apart.\n */\nimport {\n MESSAGE_PREFIX,\n PROTOCOL_VERSION,\n RpcErrorCode,\n isCaip2EvmChain,\n isOnboardCancelledMessage,\n isOnboardedMessage,\n isResponseMessage,\n onboardUrl,\n type OnboardCancelledMessage,\n type RequestMessage,\n} from \"./protocol\";\n\n/** Why {@link openAsseteraOnboarding} rejected. */\nexport type OnboardingErrorCode =\n \"popup_blocked\" | \"closed\" | \"cancelled\" | \"refused\" | \"failed\" | \"invalid_options\";\n\n/** Error thrown (well, rejected) by {@link openAsseteraOnboarding}. `code` is stable and safe to branch on. */\nexport class OnboardingError extends Error {\n readonly code: OnboardingErrorCode;\n\n constructor(code: OnboardingErrorCode, message: string) {\n super(message);\n this.name = \"OnboardingError\";\n this.code = code;\n }\n}\n\n/**\n * The client's Assetera Wallet, with the pop-up still open.\n *\n * The wallet is NOT registered with any compliance service. A regulated partner registers it itself, like any\n * other wallet: fetch a challenge for `address`, pass it to `signMessage`, send the signature to its compliance\n * service, then call `close()`. Always call `close()`: it closes the pop-up and removes the overlay.\n */\nexport interface OnboardingResult {\n address: `0x${string}`;\n chain: string;\n /** `true` when the wallet was created in this run, `false` when the client's existing wallet was returned. */\n created: boolean;\n /**\n * Ask the client to sign `message` (EIP-191 `personal_sign`) with this wallet in the open pop-up. Rejects with\n * `OnboardingError(\"cancelled\")` when the client declines, `\"closed\"` when the pop-up is gone, else `\"failed\"`.\n */\n signMessage: (message: string) => Promise<`0x${string}`>;\n /** Close the pop-up and remove the overlay. Safe to call more than once. */\n close: () => void;\n}\n\n/** Text of the dimming overlay, all optional. Any key left out keeps its English default. */\nexport interface OverlayLabels {\n title?: string;\n body?: string;\n focus?: string;\n cancel?: string;\n blocked?: string;\n}\n\n/** Options for {@link openAsseteraOnboarding}. */\nexport interface OnboardingOptions {\n /** Base URL of the wallet origin, e.g. `https://wallet.playground.assetera.com`. */\n walletUrl: string;\n /** CAIP-2 chain id the new wallet should be created on, e.g. `eip155:80002`. An invalid value rejects with `invalid_options`. */\n chain: string;\n /** Wizard language passed as `lang`, e.g. `\"en\"` or `\"de\"`. */\n locale?: string;\n /** `window.open` feature string. Defaults to a centred `\"popup,width=440,height=760,left=…,top=…\"`. */\n popupFeatures?: string;\n /** `true` (default) shows the dimming overlay, `false` hides it, an object overrides its text. */\n overlay?: boolean | OverlayLabels;\n /** Only used in the overlay text, e.g. `\"Musterbank\"`. */\n partnerName?: string;\n /** Ask for one more wallet even when the client already has one (\"Create another Assetera Wallet\"). */\n addWallet?: boolean;\n /** Injectable `window` for tests; defaults to `globalThis.window`. */\n window?: Window;\n}\n\nconst POPUP_NAME = \"assetera-wallet-onboarding\";\nconst POPUP_WIDTH = 440;\nconst POPUP_HEIGHT = 760;\nconst CLOSE_POLL_MS = 500;\nconst OVERLAY_Z_INDEX = 2147483000;\n\nconst DEFAULT_LABELS: Required<OverlayLabels> = {\n title: \"Continue in the Assetera Wallet window\",\n body: \"A secure Assetera Wallet window is open. Follow the steps there. This page continues by itself when you are done.\",\n focus: \"Show the wallet window\",\n cancel: \"Cancel\",\n blocked: \"Your browser blocked the Assetera Wallet window. Allow pop-ups for this site and try again.\",\n};\n\ninterface OverlayHandlers {\n onFocus: () => void;\n onCancel: () => void;\n}\n\nfunction defaultPopupFeatures(win: Window): string {\n const screenX = Number.isFinite(win.screenX) ? win.screenX : 0;\n const screenY = Number.isFinite(win.screenY) ? win.screenY : 0;\n const outerWidth = Number.isFinite(win.outerWidth) ? win.outerWidth : POPUP_WIDTH;\n const outerHeight = Number.isFinite(win.outerHeight) ? win.outerHeight : POPUP_HEIGHT;\n const left = Math.max(0, Math.round(screenX + (outerWidth - POPUP_WIDTH) / 2));\n const top = Math.max(0, Math.round(screenY + (outerHeight - POPUP_HEIGHT) / 2));\n return `popup,width=${POPUP_WIDTH},height=${POPUP_HEIGHT},left=${left},top=${top}`;\n}\n\nfunction resolveLabels(options: OnboardingOptions): Required<OverlayLabels> {\n const overrides: OverlayLabels =\n typeof options.overlay === \"object\" && options.overlay !== null ? options.overlay : {};\n const partnerName = options.partnerName;\n const defaultBody = partnerName\n ? `A secure Assetera Wallet window is open for ${partnerName}. Follow the steps there. This page continues by itself when you are done.`\n : DEFAULT_LABELS.body;\n return {\n title: overrides.title ?? DEFAULT_LABELS.title,\n body: overrides.body ?? defaultBody,\n focus: overrides.focus ?? DEFAULT_LABELS.focus,\n cancel: overrides.cancel ?? DEFAULT_LABELS.cancel,\n blocked: overrides.blocked ?? DEFAULT_LABELS.blocked,\n };\n}\n\nfunction cancelCode(reason: OnboardCancelledMessage[\"reason\"]): OnboardingErrorCode {\n if (reason === \"user\") return \"cancelled\";\n if (reason === \"refused\") return \"refused\";\n return \"failed\";\n}\n\nfunction cancelMessage(reason: OnboardCancelledMessage[\"reason\"]): string {\n if (reason === \"user\") return \"The user cancelled the Assetera Wallet onboarding.\";\n if (reason === \"refused\") return \"The Assetera Wallet refused the onboarding.\";\n return \"The Assetera Wallet onboarding failed.\";\n}\n\n/**\n * Build the dimming overlay. Text is inserted with `textContent` only and every style is inline, so the\n * overlay cannot pick up partner CSS and cannot be scripted through an injected string.\n */\nfunction showOverlay(win: Window, labels: Required<OverlayLabels>, handlers: OverlayHandlers): HTMLElement {\n const doc = win.document;\n const root = doc.createElement(\"div\");\n root.setAttribute(\"role\", \"dialog\");\n root.setAttribute(\"aria-modal\", \"true\");\n root.setAttribute(\"data-assetera-onboarding-overlay\", \"\");\n root.style.cssText = [\n \"position: fixed\",\n \"inset: 0\",\n \"display: flex\",\n \"align-items: center\",\n \"justify-content: center\",\n \"padding: 24px\",\n \"box-sizing: border-box\",\n \"background: rgba(15,20,30,0.6)\",\n `z-index: ${OVERLAY_Z_INDEX}`,\n \"font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif\",\n ].join(\"; \");\n\n const card = doc.createElement(\"div\");\n card.style.cssText = [\n \"box-sizing: border-box\",\n \"width: 100%\",\n \"max-width: 420px\",\n \"border-radius: 16px\",\n \"padding: 24px\",\n \"background: #ffffff\",\n \"color: #101828\",\n \"box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35)\",\n ].join(\"; \");\n\n const title = doc.createElement(\"h2\");\n title.textContent = labels.title;\n title.style.cssText = \"margin: 0 0 10px; font-size: 18px; line-height: 1.3; font-weight: 600;\";\n\n const body = doc.createElement(\"p\");\n body.textContent = labels.body;\n body.style.cssText = \"margin: 0 0 20px; font-size: 14px; line-height: 1.5; color: #475467;\";\n\n const focus = doc.createElement(\"button\");\n focus.type = \"button\";\n focus.textContent = labels.focus;\n focus.style.cssText = [\n \"padding: 10px 16px\",\n \"border: 0\",\n \"border-radius: 10px\",\n \"background: #101828\",\n \"color: #ffffff\",\n \"font: inherit\",\n \"font-weight: 600\",\n \"cursor: pointer\",\n ].join(\"; \");\n focus.addEventListener(\"click\", handlers.onFocus);\n\n const cancel = doc.createElement(\"button\");\n cancel.type = \"button\";\n cancel.textContent = labels.cancel;\n cancel.style.cssText = [\n \"padding: 10px 16px\",\n \"border: 0\",\n \"border-radius: 10px\",\n \"background: transparent\",\n \"color: #475467\",\n \"font: inherit\",\n \"cursor: pointer\",\n ].join(\"; \");\n cancel.addEventListener(\"click\", handlers.onCancel);\n\n const actions = doc.createElement(\"div\");\n actions.style.cssText = \"display: flex; gap: 8px; align-items: center;\";\n actions.append(focus, cancel);\n\n card.append(title, body, actions);\n root.append(card);\n doc.body.append(root);\n return root;\n}\n\n/**\n * Open the Assetera Wallet onboarding wizard in a pop-up and resolve with the client's wallet, the pop-up still\n * open so the partner can ask for the ownership signature (see {@link OnboardingResult}).\n *\n * Call this from a user click (a button handler). `window.open` runs synchronously inside the call, before any\n * `await`, so the browser allows it; if the browser blocks the pop-up the promise rejects with\n * `OnboardingError(\"popup_blocked\")` and no overlay is shown.\n *\n * The promise rejects with `OnboardingError` and one of these codes: `invalid_options` (bad chain or wallet\n * URL), `popup_blocked`, `closed` (the pop-up was closed first), `cancelled` (the user cancelled in the wizard\n * or in the overlay), `refused` (the wallet refused the onboarding) or `failed` (anything else in the wallet).\n * After it resolved, the overlay stays until `close()`; closing the pop-up by hand also removes it.\n */\nexport function openAsseteraOnboarding(options: OnboardingOptions): Promise<OnboardingResult> {\n const requestedWindow = options.window ?? (typeof window === \"undefined\" ? undefined : window);\n if (!requestedWindow) {\n return Promise.reject(\n new OnboardingError(\"invalid_options\", \"The Assetera Wallet onboarding can only run in a browser.\"),\n );\n }\n // A non-optional alias so TypeScript keeps the narrowed type inside the callbacks below.\n const targetWindow: Window = requestedWindow;\n if (!isCaip2EvmChain(options.chain)) {\n return Promise.reject(\n new OnboardingError(\n \"invalid_options\",\n `\"${options.chain}\" is not a CAIP-2 EVM chain id (for example \"eip155:80002\").`,\n ),\n );\n }\n let walletOrigin: string;\n try {\n walletOrigin = new URL(options.walletUrl).origin;\n } catch {\n return Promise.reject(\n new OnboardingError(\"invalid_options\", `\"${options.walletUrl}\" is not a valid wallet URL.`),\n );\n }\n\n const labels = resolveLabels(options);\n const overlayEnabled = options.overlay !== false;\n\n // MUST stay synchronous, before the first await, so the pop-up runs inside the caller's user activation.\n const popup = targetWindow.open(\n onboardUrl(options.walletUrl, targetWindow.location.origin, {\n chain: options.chain,\n ...(options.locale === undefined ? {} : { locale: options.locale }),\n ...(options.addWallet ? { add: true } : {}),\n }),\n POPUP_NAME,\n options.popupFeatures ?? defaultPopupFeatures(targetWindow),\n );\n\n if (!popup) {\n // Nothing was opened, so there is nothing to wait for and no overlay: the partner page stays usable.\n return Promise.reject(new OnboardingError(\"popup_blocked\", labels.blocked));\n }\n // A non-optional alias so TypeScript keeps the narrowed type inside the callbacks below.\n const activePopup: Window = popup;\n\n return new Promise<OnboardingResult>((resolve, reject) => {\n // Phase 1 waits for `onboarded`; phase 2 (after it) keeps the pop-up for signature requests until `close()`.\n let onboarded = false;\n let finished = false;\n let closeTimer: ReturnType<typeof setInterval> | null = null;\n let overlay: HTMLElement | null = null;\n const pending = new Map<\n string,\n { resolve: (signature: `0x${string}`) => void; reject: (error: OnboardingError) => void }\n >();\n\n function cleanup(): void {\n finished = true;\n targetWindow.removeEventListener(\"message\", onMessage);\n if (closeTimer !== null) {\n clearInterval(closeTimer);\n closeTimer = null;\n }\n overlay?.remove();\n overlay = null;\n }\n\n function failPending(error: OnboardingError): void {\n for (const entry of pending.values()) entry.reject(error);\n pending.clear();\n }\n\n function close(): void {\n if (finished) return;\n failPending(new OnboardingError(\"closed\", \"The Assetera Wallet window was closed.\"));\n cleanup();\n if (!activePopup.closed) activePopup.close();\n }\n\n function fail(error: OnboardingError): void {\n if (onboarded || finished) return;\n cleanup();\n reject(error);\n }\n\n function cancel(): void {\n if (onboarded) {\n close();\n return;\n }\n activePopup.close();\n fail(new OnboardingError(\"cancelled\", \"The user cancelled the Assetera Wallet onboarding.\"));\n }\n\n function signMessage(message: string): Promise<`0x${string}`> {\n if (finished || activePopup.closed) {\n return Promise.reject(new OnboardingError(\"closed\", \"The Assetera Wallet window was closed.\"));\n }\n const id = globalThis.crypto.randomUUID();\n const request: RequestMessage = {\n type: `${MESSAGE_PREFIX}request`,\n v: PROTOCOL_VERSION,\n id,\n method: \"personal_sign\",\n params: [message, address as `0x${string}`],\n };\n return new Promise((resolveSign, rejectSign) => {\n pending.set(id, { resolve: resolveSign, reject: rejectSign });\n activePopup.focus();\n activePopup.postMessage(request, walletOrigin);\n });\n }\n\n // Set with `onboarded`; `signMessage` is only handed out after that.\n let address: `0x${string}` | undefined;\n\n function onMessage(event: MessageEvent): void {\n // Trust rule: accept only the wallet origin AND the exact pop-up we opened. Ignore everything else.\n if (event.origin !== walletOrigin) return;\n if ((event.source as unknown) !== activePopup) return;\n const data: unknown = event.data;\n if (!onboarded) {\n if (isOnboardedMessage(data)) {\n onboarded = true;\n address = data.address;\n resolve({\n address: data.address,\n chain: data.chain,\n created: data.created ?? true,\n signMessage,\n close,\n });\n return;\n }\n if (isOnboardCancelledMessage(data)) {\n fail(new OnboardingError(cancelCode(data.reason), data.message ?? cancelMessage(data.reason)));\n }\n return;\n }\n if (isResponseMessage(data)) {\n const entry = pending.get(data.id);\n if (!entry) return;\n pending.delete(data.id);\n if (\"error\" in data) {\n entry.reject(\n new OnboardingError(\n data.error.code === RpcErrorCode.UserRejected ? \"cancelled\" : \"failed\",\n data.error.message,\n ),\n );\n } else if (typeof data.result === \"string\" && /^0x[0-9a-fA-F]+$/.test(data.result)) {\n entry.resolve(data.result as `0x${string}`);\n } else {\n entry.reject(new OnboardingError(\"failed\", \"The Assetera Wallet returned no signature.\"));\n }\n }\n }\n\n targetWindow.addEventListener(\"message\", onMessage);\n closeTimer = setInterval(() => {\n if (!activePopup.closed) return;\n if (onboarded) {\n close();\n return;\n }\n fail(\n new OnboardingError(\"closed\", \"The Assetera Wallet window was closed before onboarding finished.\"),\n );\n }, CLOSE_POLL_MS);\n\n if (overlayEnabled) {\n overlay = showOverlay(targetWindow, labels, {\n onFocus: () => activePopup.focus(),\n onCancel: cancel,\n });\n }\n });\n}\n"]}
1
+ {"version":3,"sources":["../src/popup.ts","../src/onboarding.ts","../src/manage.ts"],"names":["POPUP_NAME","CLOSE_POLL_MS"],"mappings":";;;;;AAMO,IAAM,WAAA,GAAc,GAAA;AAGpB,IAAM,YAAA,GAAe,GAAA;AAMrB,SAAS,qBAAqB,GAAA,EAAqB;AACxD,EAAA,MAAM,UAAU,MAAA,CAAO,QAAA,CAAS,IAAI,OAAO,CAAA,GAAI,IAAI,OAAA,GAAU,CAAA;AAC7D,EAAA,MAAM,UAAU,MAAA,CAAO,QAAA,CAAS,IAAI,OAAO,CAAA,GAAI,IAAI,OAAA,GAAU,CAAA;AAC7D,EAAA,MAAM,aAAa,MAAA,CAAO,Q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AAW,SAAS,CAAA;AACrD,IAAA,IAAI,eAAe,IAAA,EAAM;AACvB,MAAA,aAAA,CAAc,UAAU,CAAA;AACxB,MAAA,UAAA,GAAa,IAAA;AAAA,IACf;AACA,IAAA,aAAA,EAAc;AAAA,EAChB;AAEA,EAAA,SAAS,KAAA,GAAc;AACrB,IAAA,OAAA,EAAQ;AACR,IAAA,IAAI,CAAC,WAAA,CAAY,MAAA,EAAQ,WAAA,CAAY,KAAA,EAAM;AAAA,EAC7C;AAEA,EAAA,SAAS,UAAU,KAAA,EAA2B;AAE5C,IAAA,IAAI,KAAA,CAAM,WAAW,YAAA,EAAc;AACnC,IAAA,IAAK,KAAA,CAAM,WAAuB,WAAA,EAAa;AAC/C,IAAA,MAAM,OAAgB,KAAA,CAAM,IAAA;AAC5B,IAAA,IAAI,CAAC,iBAAA,CAAkB,IAAI,CAAA,EAAG;AAC9B,IAAA,MAAM,MAAA,GAA+B;AAAA,MACnC,UAAA,EAAY,KAAK,IAAA,CAAK,UAAA;AAAA,MACtB,QAAA,EAAU,KAAK,IAAA,CAAK,QAAA;AAAA,MACpB,iBAAA,EAAmB,KAAK,IAAA,CAAK;AAAA,KAC/B;AACA,IAAA,YAAA,GAAe,MAAA;AACf,IAAA,OAAA,CAAQ,aAAa,MAAM,CAAA;AAAA,EAC7B;AAEA,EAAA,YAAA,CAAa,gBAAA,CAAiB,WAAW,SAAS,CAAA;AAClD,EAAA,UAAA,GAAa,YAAY,MAAM;AAC7B,IAAA,IAAI,WAAA,CAAY,QAAQ,OAAA,EAAQ;AAAA,EAClC,GAAGC,cAAa,CAAA;AAEhB,EAAA,OAAO;AAAA,IACL,KAAA;AAAA,IACA,MAAA;AAAA,IACA,cAAc,MAAM;AAAA,GACtB;AACF","file":"index.js","sourcesContent":["/**\n * Small helpers shared by the pop-up openers in this package. They are internal and are not part of the public\n * API through `index.ts`.\n */\n\n/** Default width, in pixels, of the onboarding and manage pop-ups. */\nexport const POPUP_WIDTH = 440;\n\n/** Default height, in pixels, of the onboarding and manage pop-ups. */\nexport const POPUP_HEIGHT = 760;\n\n/**\n * Build the centred `window.open` feature string for a pop-up of the default size. `win` is the opener window:\n * the pop-up is centred over it, and safe defaults are used when the browser does not expose the geometry.\n */\nexport function defaultPopupFeatures(win: Window): string {\n const screenX = Number.isFinite(win.screenX) ? win.screenX : 0;\n const screenY = Number.isFinite(win.screenY) ? win.screenY : 0;\n const outerWidth = Number.isFinite(win.outerWidth) ? win.outerWidth : POPUP_WIDTH;\n const outerHeight = Number.isFinite(win.outerHeight) ? win.outerHeight : POPUP_HEIGHT;\n const left = Math.max(0, Math.round(screenX + (outerWidth - POPUP_WIDTH) / 2));\n const top = Math.max(0, Math.round(screenY + (outerHeight - POPUP_HEIGHT) / 2));\n return `popup,width=${POPUP_WIDTH},height=${POPUP_HEIGHT},left=${left},top=${top}`;\n}\n","/**\n * Onboarding opener for the Assetera Wallet: the partner side of the `/onboard` wizard (AO-1274).\n *\n * A tied-agent bank site shows a \"Create an Assetera wallet\" button. On the click, this module opens the wallet\n * pop-up in onboarding mode synchronously (so the browser treats it as part of the click) and waits for the\n * wizard to post the new wallet address back. While the pop-up is open the partner page shows a dimming\n * overlay; the overlay is plain DOM (no React, no CSS files) so any partner can drop this in.\n *\n * The wallet's `/onboard` page is the pop-up side and speaks the same protocol in `./protocol`, but it uses the\n * message types and the `ONBOARD_PATH` from there, so the two sides cannot drift apart.\n */\nimport {\n MESSAGE_PREFIX,\n PROTOCOL_VERSION,\n RpcErrorCode,\n isCaip2EvmChain,\n isOnboardCancelledMessage,\n isOnboardedMessage,\n isResponseMessage,\n onboardUrl,\n type OnboardCancelledMessage,\n type RequestMessage,\n type SignInHint,\n} from \"./protocol\";\nimport { defaultPopupFeatures } from \"./popup\";\n\n/** Why {@link openAsseteraOnboarding} rejected. */\nexport type OnboardingErrorCode =\n \"popup_blocked\" | \"closed\" | \"cancelled\" | \"refused\" | \"failed\" | \"invalid_options\";\n\n/** Error thrown (well, rejected) by {@link openAsseteraOnboarding}. `code` is stable and safe to branch on. */\nexport class OnboardingError extends Error {\n readonly code: OnboardingErrorCode;\n\n constructor(code: OnboardingErrorCode, message: string) {\n super(message);\n this.name = \"OnboardingError\";\n this.code = code;\n }\n}\n\n/**\n * The client's Assetera Wallet, with the pop-up still open.\n *\n * The wallet is NOT registered with any compliance service. A regulated partner registers it itself, like any\n * other wallet: fetch a challenge for `address`, pass it to `signMessage`, send the signature to its compliance\n * service, then call `close()`. Always call `close()`: it closes the pop-up and removes the overlay.\n */\nexport interface OnboardingResult {\n address: `0x${string}`;\n chain: string;\n /** `true` when the wallet was created in this run, `false` when the client's existing wallet was returned. */\n created: boolean;\n /**\n * Ask the client to sign `message` (EIP-191 `personal_sign`) with this wallet in the open pop-up. Rejects with\n * `OnboardingError(\"cancelled\")` when the client declines, `\"closed\"` when the pop-up is gone, else `\"failed\"`.\n */\n signMessage: (message: string) => Promise<`0x${string}`>;\n /** Close the pop-up and remove the overlay. Safe to call more than once. */\n close: () => void;\n}\n\n/** Text of the dimming overlay, all optional. Any key left out keeps its English default. */\nexport interface OverlayLabels {\n title?: string;\n body?: string;\n focus?: string;\n cancel?: string;\n blocked?: string;\n}\n\n/** Options for {@link openAsseteraOnboarding}. */\nexport interface OnboardingOptions {\n /** Base URL of the wallet origin, e.g. `https://wallet.wallet-staging.assetera.com`. */\n walletUrl: string;\n /** CAIP-2 chain id the new wallet should be created on, e.g. `eip155:80002`. An invalid value rejects with `invalid_options`. */\n chain: string;\n /** Wizard language passed as `lang`, e.g. `\"en\"` or `\"de\"`. */\n locale?: string;\n /** `window.open` feature string. Defaults to a centred `\"popup,width=440,height=760,left=…,top=…\"`. */\n popupFeatures?: string;\n /** `true` (default) shows the dimming overlay, `false` hides it, an object overrides its text. */\n overlay?: boolean | OverlayLabels;\n /** Only used in the overlay text, e.g. `\"Musterbank\"`. */\n partnerName?: string;\n /** Ask for one more wallet even when the client already has one (\"Create another Assetera Wallet\"). */\n addWallet?: boolean;\n /** Sign-in hint passed as `signIn`, e.g. `\"assetera-marketplace\"`. Only a hint; the wallet may ignore it. */\n signIn?: SignInHint;\n /** Injectable `window` for tests; defaults to `globalThis.window`. */\n window?: Window;\n}\n\nconst POPUP_NAME = \"assetera-wallet-onboarding\";\nconst CLOSE_POLL_MS = 500;\nconst OVERLAY_Z_INDEX = 2147483000;\n\nconst DEFAULT_LABELS: Required<OverlayLabels> = {\n title: \"Continue in the Assetera Wallet window\",\n body: \"A secure Assetera Wallet window is open. Follow the steps there. This page continues by itself when you are done.\",\n focus: \"Show the wallet window\",\n cancel: \"Cancel\",\n blocked: \"Your browser blocked the Assetera Wallet window. Allow pop-ups for this site and try again.\",\n};\n\ninterface OverlayHandlers {\n onFocus: () => void;\n onCancel: () => void;\n}\n\nfunction resolveLabels(options: OnboardingOptions): Required<OverlayLabels> {\n const overrides: OverlayLabels =\n typeof options.overlay === \"object\" && options.overlay !== null ? options.overlay : {};\n const partnerName = options.partnerName;\n const defaultBody = partnerName\n ? `A secure Assetera Wallet window is open for ${partnerName}. Follow the steps there. This page continues by itself when you are done.`\n : DEFAULT_LABELS.body;\n return {\n title: overrides.title ?? DEFAULT_LABELS.title,\n body: overrides.body ?? defaultBody,\n focus: overrides.focus ?? DEFAULT_LABELS.focus,\n cancel: overrides.cancel ?? DEFAULT_LABELS.cancel,\n blocked: overrides.blocked ?? DEFAULT_LABELS.blocked,\n };\n}\n\nfunction cancelCode(reason: OnboardCancelledMessage[\"reason\"]): OnboardingErrorCode {\n if (reason === \"user\") return \"cancelled\";\n if (reason === \"refused\") return \"refused\";\n return \"failed\";\n}\n\nfunction cancelMessage(reason: OnboardCancelledMessage[\"reason\"]): string {\n if (reason === \"user\") return \"The user cancelled the Assetera Wallet onboarding.\";\n if (reason === \"refused\") return \"The Assetera Wallet refused the onboarding.\";\n return \"The Assetera Wallet onboarding failed.\";\n}\n\n/**\n * Build the dimming overlay. Text is inserted with `textContent` only and every style is inline, so the\n * overlay cannot pick up partner CSS and cannot be scripted through an injected string.\n */\nfunction showOverlay(win: Window, labels: Required<OverlayLabels>, handlers: OverlayHandlers): HTMLElement {\n const doc = win.document;\n const root = doc.createElement(\"div\");\n root.setAttribute(\"role\", \"dialog\");\n root.setAttribute(\"aria-modal\", \"true\");\n root.setAttribute(\"data-assetera-onboarding-overlay\", \"\");\n root.style.cssText = [\n \"position: fixed\",\n \"inset: 0\",\n \"display: flex\",\n \"align-items: center\",\n \"justify-content: center\",\n \"padding: 24px\",\n \"box-sizing: border-box\",\n \"background: rgba(15,20,30,0.6)\",\n `z-index: ${OVERLAY_Z_INDEX}`,\n \"font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif\",\n ].join(\"; \");\n\n const card = doc.createElement(\"div\");\n card.style.cssText = [\n \"box-sizing: border-box\",\n \"width: 100%\",\n \"max-width: 420px\",\n \"border-radius: 16px\",\n \"padding: 24px\",\n \"background: #ffffff\",\n \"color: #101828\",\n \"box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35)\",\n ].join(\"; \");\n\n const title = doc.createElement(\"h2\");\n title.textContent = labels.title;\n title.style.cssText = \"margin: 0 0 10px; font-size: 18px; line-height: 1.3; font-weight: 600;\";\n\n const body = doc.createElement(\"p\");\n body.textContent = labels.body;\n body.style.cssText = \"margin: 0 0 20px; font-size: 14px; line-height: 1.5; color: #475467;\";\n\n const focus = doc.createElement(\"button\");\n focus.type = \"button\";\n focus.textContent = labels.focus;\n focus.style.cssText = [\n \"padding: 10px 16px\",\n \"border: 0\",\n \"border-radius: 10px\",\n \"background: #101828\",\n \"color: #ffffff\",\n \"font: inherit\",\n \"font-weight: 600\",\n \"cursor: pointer\",\n ].join(\"; \");\n focus.addEventListener(\"click\", handlers.onFocus);\n\n const cancel = doc.createElement(\"button\");\n cancel.type = \"button\";\n cancel.textContent = labels.cancel;\n cancel.style.cssText = [\n \"padding: 10px 16px\",\n \"border: 0\",\n \"border-radius: 10px\",\n \"background: transparent\",\n \"color: #475467\",\n \"font: inherit\",\n \"cursor: pointer\",\n ].join(\"; \");\n cancel.addEventListener(\"click\", handlers.onCancel);\n\n const actions = doc.createElement(\"div\");\n actions.style.cssText = \"display: flex; gap: 8px; align-items: center;\";\n actions.append(focus, cancel);\n\n card.append(title, body, actions);\n root.append(card);\n doc.body.append(root);\n return root;\n}\n\n/**\n * Open the Assetera Wallet onboarding wizard in a pop-up and resolve with the client's wallet, the pop-up still\n * open so the partner can ask for the ownership signature (see {@link OnboardingResult}).\n *\n * Call this from a user click (a button handler). `window.open` runs synchronously inside the call, before any\n * `await`, so the browser allows it; if the browser blocks the pop-up the promise rejects with\n * `OnboardingError(\"popup_blocked\")` and no overlay is shown.\n *\n * The promise rejects with `OnboardingError` and one of these codes: `invalid_options` (bad chain or wallet\n * URL), `popup_blocked`, `closed` (the pop-up was closed first), `cancelled` (the user cancelled in the wizard\n * or in the overlay), `refused` (the wallet refused the onboarding) or `failed` (anything else in the wallet).\n * After it resolved, the overlay stays until `close()`; closing the pop-up by hand also removes it.\n */\nexport function openAsseteraOnboarding(options: OnboardingOptions): Promise<OnboardingResult> {\n const requestedWindow = options.window ?? (typeof window === \"undefined\" ? undefined : window);\n if (!requestedWindow) {\n return Promise.reject(\n new OnboardingError(\"invalid_options\", \"The Assetera Wallet onboarding can only run in a browser.\"),\n );\n }\n // A non-optional alias so TypeScript keeps the narrowed type inside the callbacks below.\n const targetWindow: Window = requestedWindow;\n if (!isCaip2EvmChain(options.chain)) {\n return Promise.reject(\n new OnboardingError(\n \"invalid_options\",\n `\"${options.chain}\" is not a CAIP-2 EVM chain id (for example \"eip155:80002\").`,\n ),\n );\n }\n let walletOrigin: string;\n try {\n walletOrigin = new URL(options.walletUrl).origin;\n } catch {\n return Promise.reject(\n new OnboardingError(\"invalid_options\", `\"${options.walletUrl}\" is not a valid wallet URL.`),\n );\n }\n\n const labels = resolveLabels(options);\n const overlayEnabled = options.overlay !== false;\n\n // MUST stay synchronous, before the first await, so the pop-up runs inside the caller's user activation.\n const popup = targetWindow.open(\n onboardUrl(options.walletUrl, targetWindow.location.origin, {\n chain: options.chain,\n ...(options.locale === undefined ? {} : { locale: options.locale }),\n ...(options.addWallet ? { add: true } : {}),\n ...(options.signIn === undefined ? {} : { signIn: options.signIn }),\n }),\n POPUP_NAME,\n options.popupFeatures ?? defaultPopupFeatures(targetWindow),\n );\n\n if (!popup) {\n // Nothing was opened, so there is nothing to wait for and no overlay: the partner page stays usable.\n return Promise.reject(new OnboardingError(\"popup_blocked\", labels.blocked));\n }\n // A non-optional alias so TypeScript keeps the narrowed type inside the callbacks below.\n const activePopup: Window = popup;\n\n return new Promise<OnboardingResult>((resolve, reject) => {\n // Phase 1 waits for `onboarded`; phase 2 (after it) keeps the pop-up for signature requests until `close()`.\n let onboarded = false;\n let finished = false;\n let closeTimer: ReturnType<typeof setInterval> | null = null;\n let overlay: HTMLElement | null = null;\n const pending = new Map<\n string,\n { resolve: (signature: `0x${string}`) => void; reject: (error: OnboardingError) => void }\n >();\n\n function cleanup(): void {\n finished = true;\n targetWindow.removeEventListener(\"message\", onMessage);\n if (closeTimer !== null) {\n clearInterval(closeTimer);\n closeTimer = null;\n }\n overlay?.remove();\n overlay = null;\n }\n\n function failPending(error: OnboardingError): void {\n for (const entry of pending.values()) entry.reject(error);\n pending.clear();\n }\n\n function close(): void {\n if (finished) return;\n failPending(new OnboardingError(\"closed\", \"The Assetera Wallet window was closed.\"));\n cleanup();\n if (!activePopup.closed) activePopup.close();\n }\n\n function fail(error: OnboardingError): void {\n if (onboarded || finished) return;\n cleanup();\n reject(error);\n }\n\n function cancel(): void {\n if (onboarded) {\n close();\n return;\n }\n activePopup.close();\n fail(new OnboardingError(\"cancelled\", \"The user cancelled the Assetera Wallet onboarding.\"));\n }\n\n function signMessage(message: string): Promise<`0x${string}`> {\n if (finished || activePopup.closed) {\n return Promise.reject(new OnboardingError(\"closed\", \"The Assetera Wallet window was closed.\"));\n }\n const id = globalThis.crypto.randomUUID();\n const request: RequestMessage = {\n type: `${MESSAGE_PREFIX}request`,\n v: PROTOCOL_VERSION,\n id,\n method: \"personal_sign\",\n params: [message, address as `0x${string}`],\n };\n return new Promise((resolveSign, rejectSign) => {\n pending.set(id, { resolve: resolveSign, reject: rejectSign });\n activePopup.focus();\n activePopup.postMessage(request, walletOrigin);\n });\n }\n\n // Set with `onboarded`; `signMessage` is only handed out after that.\n let address: `0x${string}` | undefined;\n\n function onMessage(event: MessageEvent): void {\n // Trust rule: accept only the wallet origin AND the exact pop-up we opened. Ignore everything else.\n if (event.origin !== walletOrigin) return;\n if ((event.source as unknown) !== activePopup) return;\n const data: unknown = event.data;\n if (!onboarded) {\n if (isOnboardedMessage(data)) {\n onboarded = true;\n address = data.address;\n resolve({\n address: data.address,\n chain: data.chain,\n created: data.created ?? true,\n signMessage,\n close,\n });\n return;\n }\n if (isOnboardCancelledMessage(data)) {\n fail(new OnboardingError(cancelCode(data.reason), data.message ?? cancelMessage(data.reason)));\n }\n return;\n }\n if (isResponseMessage(data)) {\n const entry = pending.get(data.id);\n if (!entry) return;\n pending.delete(data.id);\n if (\"error\" in data) {\n entry.reject(\n new OnboardingError(\n data.error.code === RpcErrorCode.UserRejected ? \"cancelled\" : \"failed\",\n data.error.message,\n ),\n );\n } else if (typeof data.result === \"string\" && /^0x[0-9a-fA-F]+$/.test(data.result)) {\n entry.resolve(data.result as `0x${string}`);\n } else {\n entry.reject(new OnboardingError(\"failed\", \"The Assetera Wallet returned no signature.\"));\n }\n }\n }\n\n targetWindow.addEventListener(\"message\", onMessage);\n closeTimer = setInterval(() => {\n if (!activePopup.closed) return;\n if (onboarded) {\n close();\n return;\n }\n fail(\n new OnboardingError(\"closed\", \"The Assetera Wallet window was closed before onboarding finished.\"),\n );\n }, CLOSE_POLL_MS);\n\n if (overlayEnabled) {\n overlay = showOverlay(targetWindow, labels, {\n onFocus: () => activePopup.focus(),\n onCancel: cancel,\n });\n }\n });\n}\n","/**\n * Manage-wallet opener for the Assetera Wallet: the partner side of the `/manage` pop-up (AO-1436).\n *\n * A partner page shows a \"Manage wallet\" button. On the click this module opens the wallet pop-up on the manage\n * route synchronously (so the browser treats it as part of the click). The client sees the wallet accounts and\n * the wallet security (passkeys, authenticator app, recovery codes) and can change them. The pop-up never\n * answers `request` messages; it posts `security` messages while it is open.\n */\nimport { isSecurityMessage, manageUrl, type SignInHint, type WalletSecurityStatus } from \"./protocol\";\nimport { defaultPopupFeatures } from \"./popup\";\n\n/** Why {@link openAsseteraWalletManager} threw. */\nexport type ManagerErrorCode = \"popup_blocked\" | \"invalid_options\";\n\n/** Error thrown by {@link openAsseteraWalletManager}. `code` is stable and safe to branch on. */\nexport class ManagerError extends Error {\n readonly code: ManagerErrorCode;\n\n constructor(code: ManagerErrorCode, message: string) {\n super(message);\n this.name = \"ManagerError\";\n this.code = code;\n }\n}\n\n/** Options for {@link openAsseteraWalletManager}. */\nexport interface WalletManagerOptions {\n /** Base URL of the wallet origin, e.g. `https://wallet.wallet-staging.assetera.com`. */\n walletUrl: string;\n /** Sign-in hint passed as `signIn`, e.g. `\"assetera-marketplace\"`. Only a hint; the wallet may ignore it. */\n signIn?: SignInHint;\n /** Language passed as `lang`, e.g. `\"en\"` or `\"de\"`. */\n locale?: string;\n /** `window.open` feature string. Defaults to a centred `\"popup,width=440,height=760,left=…,top=…\"`. */\n popupFeatures?: string;\n /** Called for every `security` message from the pop-up. */\n onSecurity?: (status: WalletSecurityStatus) => void;\n /** Injectable `window` for tests; defaults to `globalThis.window`. */\n window?: Window;\n}\n\n/** The open manage pop-up, controlled by the partner. */\nexport interface WalletManager {\n /** Close the pop-up and remove the listener and the close timer. Safe to call more than once. */\n close: () => void;\n /** Resolves when the pop-up is closed, by the partner or by the client. */\n closed: Promise<void>;\n /** The last security status the pop-up sent, or `undefined` when none arrived yet. */\n lastSecurity: () => WalletSecurityStatus | undefined;\n}\n\nconst POPUP_NAME = \"assetera-wallet-manage\";\nconst CLOSE_POLL_MS = 500;\n\n/**\n * Open the manage-wallet pop-up for the Assetera Wallet and return a handle to it.\n *\n * Call this from a user click (a button handler). `window.open` runs synchronously inside the call, before any\n * `await`, so the browser allows it; when the browser blocks the pop-up this throws `ManagerError` with code\n * `popup_blocked`.\n *\n * The pop-up checks the `origin` query parameter against the wallet's partner list, posts `ready` to\n * `window.opener` and then posts `security` messages. Messages are accepted only when they come from the wallet\n * origin AND from the pop-up that was opened here. The pop-up does not answer `request` messages.\n */\nexport function openAsseteraWalletManager(options: WalletManagerOptions): WalletManager {\n const requestedWindow = options.window ?? (typeof window === \"undefined\" ? undefined : window);\n if (!requestedWindow) {\n throw new ManagerError(\"invalid_options\", \"The Assetera Wallet manager can only run in a browser.\");\n }\n // A non-optional alias so TypeScript keeps the narrowed type inside the callbacks below.\n const targetWindow: Window = requestedWindow;\n let walletOrigin: string;\n try {\n walletOrigin = new URL(options.walletUrl).origin;\n } catch {\n throw new ManagerError(\"invalid_options\", `\"${options.walletUrl}\" is not a valid wallet URL.`);\n }\n\n // MUST stay synchronous, before any await, so the pop-up runs inside the caller's user activation.\n const popup = targetWindow.open(\n manageUrl(options.walletUrl, targetWindow.location.origin, {\n ...(options.locale === undefined ? {} : { locale: options.locale }),\n ...(options.signIn === undefined ? {} : { signIn: options.signIn }),\n }),\n POPUP_NAME,\n options.popupFeatures ?? defaultPopupFeatures(targetWindow),\n );\n\n if (!popup) {\n throw new ManagerError(\n \"popup_blocked\",\n \"Your browser blocked the Assetera Wallet window. Allow pop-ups for this site and try again.\",\n );\n }\n // A non-optional alias so TypeScript keeps the narrowed type inside the callbacks below.\n const activePopup: Window = popup;\n\n let finished = false;\n let lastSecurity: WalletSecurityStatus | undefined;\n let closeTimer: ReturnType<typeof setInterval> | null = null;\n let resolveClosed!: () => void;\n const closed = new Promise<void>((resolve) => {\n resolveClosed = resolve;\n });\n\n function cleanup(): void {\n if (finished) return;\n finished = true;\n targetWindow.removeEventListener(\"message\", onMessage);\n if (closeTimer !== null) {\n clearInterval(closeTimer);\n closeTimer = null;\n }\n resolveClosed();\n }\n\n function close(): void {\n cleanup();\n if (!activePopup.closed) activePopup.close();\n }\n\n function onMessage(event: MessageEvent): void {\n // Trust rule: accept only the wallet origin AND the exact pop-up we opened. Ignore everything else.\n if (event.origin !== walletOrigin) return;\n if ((event.source as unknown) !== activePopup) return;\n const data: unknown = event.data;\n if (!isSecurityMessage(data)) return;\n const status: WalletSecurityStatus = {\n protection: data.data.protection,\n passkeys: data.data.passkeys,\n authenticatorApps: data.data.authenticatorApps,\n };\n lastSecurity = status;\n options.onSecurity?.(status);\n }\n\n targetWindow.addEventListener(\"message\", onMessage);\n closeTimer = setInterval(() => {\n if (activePopup.closed) cleanup();\n }, CLOSE_POLL_MS);\n\n return {\n close,\n closed,\n lastSecurity: () => lastSecurity,\n };\n}\n"]}
package/dist/protocol.cjs CHANGED
@@ -4,6 +4,11 @@
4
4
  var PROTOCOL_VERSION = 1;
5
5
  var CONNECT_PATH = "/connect";
6
6
  var ONBOARD_PATH = "/onboard";
7
+ var MANAGE_PATH = "/manage";
8
+ var SIGN_IN_HINTS = ["assetera-marketplace"];
9
+ function isSignInHint(value) {
10
+ return SIGN_IN_HINTS.includes(value);
11
+ }
7
12
  var MESSAGE_PREFIX = "assetera-wallet:";
8
13
  var SUPPORTED_METHODS = [
9
14
  "eth_requestAccounts",
@@ -48,6 +53,21 @@ function isResponseMessage(value) {
48
53
  function isEventMessage(value) {
49
54
  return hasType(value, "event") && (value.event === "accountsChanged" || value.event === "chainChanged" || value.event === "disconnect");
50
55
  }
56
+ var WALLET_PROTECTIONS = [
57
+ "unknown",
58
+ "add-factor",
59
+ "save-codes",
60
+ "create-codes",
61
+ "protected"
62
+ ];
63
+ function isCount(value) {
64
+ return typeof value === "number" && Number.isInteger(value) && value >= 0;
65
+ }
66
+ function isSecurityMessage(value) {
67
+ if (!hasType(value, "security")) return false;
68
+ const data = value.data;
69
+ return isRecord(data) && typeof data.protection === "string" && WALLET_PROTECTIONS.includes(data.protection) && isCount(data.passkeys) && isCount(data.authenticatorApps);
70
+ }
51
71
  function isRequestMessage(value) {
52
72
  return hasType(value, "request") && typeof value.id === "string" && typeof value.method === "string";
53
73
  }
@@ -65,10 +85,11 @@ function isOnboardCancelledMessage(value) {
65
85
  function isCaip2EvmChain(value) {
66
86
  return /^eip155:\d{1,32}$/.test(value);
67
87
  }
68
- function connectUrl(walletUrl, partnerOrigin) {
88
+ function connectUrl(walletUrl, partnerOrigin, signIn) {
69
89
  const url = new URL(CONNECT_PATH, walletUrl);
70
90
  url.searchParams.set("origin", partnerOrigin);
71
91
  url.searchParams.set("v", String(PROTOCOL_VERSION));
92
+ if (signIn !== void 0) url.searchParams.set("signIn", signIn);
72
93
  return url.toString();
73
94
  }
74
95
  function onboardUrl(walletUrl, partnerOrigin, options) {
@@ -78,14 +99,25 @@ function onboardUrl(walletUrl, partnerOrigin, options) {
78
99
  url.searchParams.set("chain", options.chain);
79
100
  if (options.locale !== void 0) url.searchParams.set("lang", options.locale);
80
101
  if (options.add) url.searchParams.set("add", "1");
102
+ if (options.signIn !== void 0) url.searchParams.set("signIn", options.signIn);
103
+ return url.toString();
104
+ }
105
+ function manageUrl(walletUrl, partnerOrigin, options = {}) {
106
+ const url = new URL(MANAGE_PATH, walletUrl);
107
+ url.searchParams.set("origin", partnerOrigin);
108
+ url.searchParams.set("v", String(PROTOCOL_VERSION));
109
+ if (options.locale !== void 0) url.searchParams.set("lang", options.locale);
110
+ if (options.signIn !== void 0) url.searchParams.set("signIn", options.signIn);
81
111
  return url.toString();
82
112
  }
83
113
 
84
114
  exports.CONNECT_PATH = CONNECT_PATH;
115
+ exports.MANAGE_PATH = MANAGE_PATH;
85
116
  exports.MESSAGE_PREFIX = MESSAGE_PREFIX;
86
117
  exports.ONBOARD_PATH = ONBOARD_PATH;
87
118
  exports.PROTOCOL_VERSION = PROTOCOL_VERSION;
88
119
  exports.RpcErrorCode = RpcErrorCode;
120
+ exports.SIGN_IN_HINTS = SIGN_IN_HINTS;
89
121
  exports.SUPPORTED_METHODS = SUPPORTED_METHODS;
90
122
  exports.connectUrl = connectUrl;
91
123
  exports.isCaip2EvmChain = isCaip2EvmChain;
@@ -96,7 +128,10 @@ exports.isOnboardedMessage = isOnboardedMessage;
96
128
  exports.isReadyMessage = isReadyMessage;
97
129
  exports.isRequestMessage = isRequestMessage;
98
130
  exports.isResponseMessage = isResponseMessage;
131
+ exports.isSecurityMessage = isSecurityMessage;
132
+ exports.isSignInHint = isSignInHint;
99
133
  exports.isSupportedMethod = isSupportedMethod;
134
+ exports.manageUrl = manageUrl;
100
135
  exports.onboardUrl = onboardUrl;
101
136
  //# sourceMappingURL=protocol.cjs.map
102
137
  //# sourceMappingURL=protocol.cjs.map