@flow-industries/id 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.
Files changed (54) hide show
  1. package/README.md +255 -0
  2. package/dist/sdk/chains.d.ts +2 -0
  3. package/dist/sdk/chains.js +2 -0
  4. package/dist/sdk/client/access-key.d.ts +37 -0
  5. package/dist/sdk/client/access-key.js +97 -0
  6. package/dist/sdk/client/create-flow.d.ts +41 -0
  7. package/dist/sdk/client/create-flow.js +259 -0
  8. package/dist/sdk/client/dialog-host.d.ts +19 -0
  9. package/dist/sdk/client/dialog-host.js +192 -0
  10. package/dist/sdk/client/idb.d.ts +5 -0
  11. package/dist/sdk/client/idb.js +47 -0
  12. package/dist/sdk/client/index.d.ts +4 -0
  13. package/dist/sdk/client/index.js +3 -0
  14. package/dist/sdk/client/methods.d.ts +9 -0
  15. package/dist/sdk/client/methods.js +9 -0
  16. package/dist/sdk/client/protocol.d.ts +97 -0
  17. package/dist/sdk/client/protocol.js +9 -0
  18. package/dist/sdk/client/session.d.ts +45 -0
  19. package/dist/sdk/client/session.js +90 -0
  20. package/dist/sdk/client/signing.d.ts +16 -0
  21. package/dist/sdk/client/signing.js +91 -0
  22. package/dist/sdk/client/store.d.ts +3 -0
  23. package/dist/sdk/client/store.js +41 -0
  24. package/dist/sdk/client/types.d.ts +35 -0
  25. package/dist/sdk/client/types.js +0 -0
  26. package/dist/sdk/dialog/remote/Messenger.d.ts +29 -0
  27. package/dist/sdk/dialog/remote/Messenger.js +146 -0
  28. package/dist/sdk/react/hooks.d.ts +33 -0
  29. package/dist/sdk/react/hooks.js +51 -0
  30. package/dist/sdk/react/index.d.ts +3 -0
  31. package/dist/sdk/react/index.js +2 -0
  32. package/dist/sdk/react/provider.d.ts +12 -0
  33. package/dist/sdk/react/provider.js +15 -0
  34. package/dist/sdk/types/auth.d.ts +45 -0
  35. package/dist/sdk/types/auth.js +0 -0
  36. package/dist/sdk/types/dialog.d.ts +55 -0
  37. package/dist/sdk/types/dialog.js +0 -0
  38. package/dist/sdk/types/index.d.ts +7 -0
  39. package/dist/sdk/types/index.js +1 -0
  40. package/dist/sdk/types/messenger.d.ts +162 -0
  41. package/dist/sdk/types/messenger.js +0 -0
  42. package/dist/sdk/types/protocol.d.ts +114 -0
  43. package/dist/sdk/types/protocol.js +17 -0
  44. package/dist/sdk/types/sdk.d.ts +166 -0
  45. package/dist/sdk/types/sdk.js +0 -0
  46. package/dist/sdk/types/tx.d.ts +35 -0
  47. package/dist/sdk/types/tx.js +0 -0
  48. package/dist/sdk/types.d.ts +32 -0
  49. package/dist/sdk/types.js +0 -0
  50. package/dist/sdk/verify.d.ts +15 -0
  51. package/dist/sdk/verify.js +30 -0
  52. package/dist/sdk/wagmi/index.d.ts +25 -0
  53. package/dist/sdk/wagmi/index.js +139 -0
  54. package/package.json +99 -0
@@ -0,0 +1,41 @@
1
+ export function createStore(initial) {
2
+ let state = initial;
3
+ const listeners = new Set();
4
+ return {
5
+ getSnapshot() {
6
+ return state;
7
+ },
8
+ setState(partial) {
9
+ const next = { ...state, ...partial };
10
+ if (shallowEqual(state, next))
11
+ return;
12
+ state = next;
13
+ for (const l of listeners)
14
+ l(state);
15
+ },
16
+ subscribe(listener) {
17
+ listeners.add(listener);
18
+ return () => listeners.delete(listener);
19
+ },
20
+ };
21
+ }
22
+ export const initialFlowState = {
23
+ user: null,
24
+ jwt: null,
25
+ credential: null,
26
+ address: null,
27
+ };
28
+ function shallowEqual(a, b) {
29
+ if (a === b)
30
+ return true;
31
+ if (typeof a !== "object" || typeof b !== "object" || a === null || b === null) {
32
+ return false;
33
+ }
34
+ const ak = Object.keys(a);
35
+ if (Object.keys(b).length !== ak.length)
36
+ return false;
37
+ for (const k of ak)
38
+ if (a[k] !== b[k])
39
+ return false;
40
+ return true;
41
+ }
@@ -0,0 +1,35 @@
1
+ import type { Chain } from "viem";
2
+ import type { FlowCredential, FlowUser } from "../types";
3
+ export type { FlowUser, FlowCredential };
4
+ export type Address = `0x${string}`;
5
+ export type AccessKeyOptions = {
6
+ expiry?: number;
7
+ strict?: boolean;
8
+ };
9
+ export type CreateFlowOptions = {
10
+ host?: string;
11
+ rpId?: string;
12
+ chains?: readonly Chain[];
13
+ accessKey?: boolean | AccessKeyOptions;
14
+ /**
15
+ * If true (default), createFlow attempts a silent restore on startup —
16
+ * if the user has a valid Flow cookie session, state populates without UI.
17
+ */
18
+ autoRestore?: boolean;
19
+ };
20
+ export type FlowState = {
21
+ user: FlowUser | null;
22
+ jwt: string | null;
23
+ credential: FlowCredential | null;
24
+ address: Address | null;
25
+ };
26
+ export type LoginOptions = {
27
+ mode?: "iframe" | "popup";
28
+ signUp?: boolean;
29
+ };
30
+ export type Session = {
31
+ user: FlowUser;
32
+ jwt: string;
33
+ credential: FlowCredential;
34
+ address: Address;
35
+ };
File without changes
@@ -0,0 +1,29 @@
1
+ import type { Bridge, BridgeParameters, FromWindowOptions, Messenger } from "../../types";
2
+ export type { Bridge, BridgeParameters, FromWindowOptions, Messenger, Payload, QueuedRequest, ReadyOptions, Schema, Topic, WithReady, } from "../../types";
3
+ export type { MessageResponse as Response } from "../../types";
4
+ export declare function from(messenger: Messenger): Messenger;
5
+ /**
6
+ * Wraps a Window in the Messenger interface. Reads come from
7
+ * `addEventListener("message")` on this window; writes go through
8
+ * `postMessage` to the same (or another) window.
9
+ *
10
+ * `targetOrigin` (when set) acts as both an inbound filter (drop messages
11
+ * not from this origin) and a default for outbound `postMessage` calls —
12
+ * binding the channel to one origin instead of `*` is the cross-origin
13
+ * isolation that prevents arbitrary pages from injecting messages.
14
+ */
15
+ export declare function fromWindow(w: Window, options?: FromWindowOptions): Messenger;
16
+ /**
17
+ * Combines two Messengers into a bidirectional bridge: `from` is read-side
18
+ * (inbound messages), `to` is write-side (outbound). Adds a "ready"
19
+ * handshake — when `waitForReady: true`, sends queue until the peer
20
+ * announces it's listening, so messages dispatched during page load aren't
21
+ * dropped against an iframe that hasn't booted yet.
22
+ */
23
+ export declare function bridge(parameters: BridgeParameters): Bridge;
24
+ /**
25
+ * No-op bridge used in non-browser environments (SSR, tests, Node) where
26
+ * `window` doesn't exist. All sends resolve to undefined and never deliver.
27
+ * Lets the SDK be imported from anywhere without crashing on module load.
28
+ */
29
+ export declare function noop(): Bridge;
@@ -0,0 +1,146 @@
1
+ /**
2
+ * Recursively strips values that postMessage's structured-clone algorithm
3
+ * can't carry: functions become `undefined`, plain objects are walked, and
4
+ * exotic objects (class instances, DOM nodes, etc.) are passed through
5
+ * structuredClone or dropped if even that fails. Without this, sending an
6
+ * object with a method on it would throw a DataCloneError at runtime.
7
+ */
8
+ function normalizeValue(value) {
9
+ if (Array.isArray(value))
10
+ return value.map(normalizeValue);
11
+ if (typeof value === "function")
12
+ return undefined;
13
+ if (typeof value !== "object" || value === null)
14
+ return value;
15
+ if (Object.getPrototypeOf(value) !== Object.prototype)
16
+ try {
17
+ return structuredClone(value);
18
+ }
19
+ catch {
20
+ return undefined;
21
+ }
22
+ const normalized = {};
23
+ for (const [k, v] of Object.entries(value))
24
+ normalized[k] = normalizeValue(v);
25
+ return normalized;
26
+ }
27
+ export function from(messenger) {
28
+ return messenger;
29
+ }
30
+ /**
31
+ * Wraps a Window in the Messenger interface. Reads come from
32
+ * `addEventListener("message")` on this window; writes go through
33
+ * `postMessage` to the same (or another) window.
34
+ *
35
+ * `targetOrigin` (when set) acts as both an inbound filter (drop messages
36
+ * not from this origin) and a default for outbound `postMessage` calls —
37
+ * binding the channel to one origin instead of `*` is the cross-origin
38
+ * isolation that prevents arbitrary pages from injecting messages.
39
+ */
40
+ export function fromWindow(w, options = {}) {
41
+ const { targetOrigin } = options;
42
+ const listeners = new Map();
43
+ return from({
44
+ destroy() {
45
+ listeners.forEach((listener) => {
46
+ w.removeEventListener("message", listener);
47
+ });
48
+ },
49
+ on(topic, listener, id) {
50
+ function handler(event) {
51
+ if (event.data.topic !== topic)
52
+ return;
53
+ if (id && event.data.id !== id)
54
+ return;
55
+ if (targetOrigin && event.origin !== targetOrigin)
56
+ return;
57
+ listener(event.data.payload, event);
58
+ }
59
+ w.addEventListener("message", handler);
60
+ listeners.set(`${topic}:${id ?? ""}`, handler);
61
+ return () => w.removeEventListener("message", handler);
62
+ },
63
+ async send(topic, payload, target) {
64
+ const id = crypto.randomUUID();
65
+ w.postMessage(normalizeValue({ id, payload, topic }), target ?? targetOrigin ?? "*");
66
+ return { id, payload, topic };
67
+ },
68
+ async sendAsync(topic, payload, target) {
69
+ const { id } = await this.send(topic, payload, target);
70
+ return new Promise((resolve) => this.on(topic, resolve, id));
71
+ },
72
+ });
73
+ }
74
+ /**
75
+ * Combines two Messengers into a bidirectional bridge: `from` is read-side
76
+ * (inbound messages), `to` is write-side (outbound). Adds a "ready"
77
+ * handshake — when `waitForReady: true`, sends queue until the peer
78
+ * announces it's listening, so messages dispatched during page load aren't
79
+ * dropped against an iframe that hasn't booted yet.
80
+ */
81
+ export function bridge(parameters) {
82
+ const { from: from_, to, waitForReady = false } = parameters;
83
+ let pending = false;
84
+ let resolveReady;
85
+ let rejectReady;
86
+ const readyPromise = new Promise((resolve, reject) => {
87
+ resolveReady = resolve;
88
+ rejectReady = reject;
89
+ });
90
+ from_.on("ready", resolveReady);
91
+ const messenger = from({
92
+ destroy() {
93
+ from_.destroy();
94
+ to.destroy();
95
+ if (pending)
96
+ rejectReady();
97
+ },
98
+ on(topic, listener, id) {
99
+ return from_.on(topic, listener, id);
100
+ },
101
+ async send(topic, payload, targetOrigin) {
102
+ pending = true;
103
+ if (waitForReady)
104
+ await readyPromise.finally(() => (pending = false));
105
+ return to.send(topic, payload, targetOrigin);
106
+ },
107
+ async sendAsync(topic, payload, targetOrigin) {
108
+ pending = true;
109
+ if (waitForReady)
110
+ await readyPromise.finally(() => (pending = false));
111
+ return to.sendAsync(topic, payload, targetOrigin);
112
+ },
113
+ });
114
+ return {
115
+ ...messenger,
116
+ ready(options) {
117
+ void messenger.send("ready", options);
118
+ },
119
+ waitForReady() {
120
+ return readyPromise;
121
+ },
122
+ };
123
+ }
124
+ /**
125
+ * No-op bridge used in non-browser environments (SSR, tests, Node) where
126
+ * `window` doesn't exist. All sends resolve to undefined and never deliver.
127
+ * Lets the SDK be imported from anywhere without crashing on module load.
128
+ */
129
+ export function noop() {
130
+ return {
131
+ destroy() { },
132
+ on() {
133
+ return () => { };
134
+ },
135
+ ready() { },
136
+ send() {
137
+ return Promise.resolve(undefined);
138
+ },
139
+ sendAsync() {
140
+ return Promise.resolve(undefined);
141
+ },
142
+ waitForReady() {
143
+ return Promise.resolve(undefined);
144
+ },
145
+ };
146
+ }
@@ -0,0 +1,33 @@
1
+ import type { Flow, FlowState } from "../types";
2
+ /**
3
+ * Returns the Flow instance to use. Resolution order:
4
+ * 1. The instance from a `<FlowIdProvider>` ancestor (if any)
5
+ * 2. The singleton set by `createFlow()`
6
+ *
7
+ * Throws only if neither is available — i.e., the app forgot to call
8
+ * `createFlow()` and didn't supply a provider. The singleton fallback
9
+ * means most apps don't need a provider at all.
10
+ */
11
+ export declare function useFlow(): Flow;
12
+ /**
13
+ * Subscribes a component to the full Flow state. Re-renders on any state
14
+ * change; if you only need one field, prefer reading `useFlowId()` and
15
+ * destructuring, or memoize a selector around this.
16
+ */
17
+ export declare function useFlowState(): FlowState;
18
+ /**
19
+ * Convenience hook that returns the most commonly needed identity data and
20
+ * actions in one go: user/jwt/address plus `login`, `logout`, `restore`,
21
+ * and `refreshJwt`. The `isAuthenticated` boolean is derived from `user`
22
+ * being set so it tracks reactive state.
23
+ */
24
+ export declare function useFlowId(): {
25
+ user: import("../types").FlowUser | null;
26
+ jwt: string | null;
27
+ address: `0x${string}` | null;
28
+ isAuthenticated: boolean;
29
+ login: (options?: import("../types").LoginOptions) => Promise<import("../types").Session>;
30
+ logout: () => Promise<void>;
31
+ restore: () => Promise<boolean>;
32
+ refreshJwt: () => Promise<boolean>;
33
+ };
@@ -0,0 +1,51 @@
1
+ import { useContext, useSyncExternalStore } from "react";
2
+ import { getFlow as getSingletonFlow } from "../client/create-flow";
3
+ import { FlowContext } from "./provider";
4
+ /**
5
+ * Returns the Flow instance to use. Resolution order:
6
+ * 1. The instance from a `<FlowIdProvider>` ancestor (if any)
7
+ * 2. The singleton set by `createFlow()`
8
+ *
9
+ * Throws only if neither is available — i.e., the app forgot to call
10
+ * `createFlow()` and didn't supply a provider. The singleton fallback
11
+ * means most apps don't need a provider at all.
12
+ */
13
+ export function useFlow() {
14
+ const fromContext = useContext(FlowContext);
15
+ if (fromContext)
16
+ return fromContext;
17
+ const singleton = getSingletonFlow();
18
+ if (singleton)
19
+ return singleton;
20
+ throw new Error("useFlow could not find a Flow instance. Call createFlow() at app start, " +
21
+ "or wrap your tree in <FlowIdProvider flow={...}>.");
22
+ }
23
+ /**
24
+ * Subscribes a component to the full Flow state. Re-renders on any state
25
+ * change; if you only need one field, prefer reading `useFlowId()` and
26
+ * destructuring, or memoize a selector around this.
27
+ */
28
+ export function useFlowState() {
29
+ const flow = useFlow();
30
+ return useSyncExternalStore(flow.subscribe, flow.getState, flow.getState);
31
+ }
32
+ /**
33
+ * Convenience hook that returns the most commonly needed identity data and
34
+ * actions in one go: user/jwt/address plus `login`, `logout`, `restore`,
35
+ * and `refreshJwt`. The `isAuthenticated` boolean is derived from `user`
36
+ * being set so it tracks reactive state.
37
+ */
38
+ export function useFlowId() {
39
+ const flow = useFlow();
40
+ const state = useFlowState();
41
+ return {
42
+ user: state.user,
43
+ jwt: state.jwt,
44
+ address: state.address,
45
+ isAuthenticated: state.user !== null,
46
+ login: flow.login,
47
+ logout: flow.logout,
48
+ restore: flow.restore,
49
+ refreshJwt: flow.refreshJwt,
50
+ };
51
+ }
@@ -0,0 +1,3 @@
1
+ export { FlowIdProvider } from "./provider";
2
+ export { useFlow, useFlowId, useFlowState } from "./hooks";
3
+ export type { FlowIdProviderProps } from "../types";
@@ -0,0 +1,2 @@
1
+ export { FlowIdProvider } from "./provider";
2
+ export { useFlow, useFlowId, useFlowState } from "./hooks";
@@ -0,0 +1,12 @@
1
+ import type { Flow, FlowIdProviderProps } from "../types";
2
+ export declare const FlowContext: import("react").Context<Flow | null>;
3
+ /**
4
+ * Optional context provider for scoping a specific Flow instance to a
5
+ * subtree. Most apps don't need it: the React hooks fall back to the
6
+ * singleton set by `createFlow()`, so just calling `createFlow()` once at
7
+ * app start is enough.
8
+ *
9
+ * Wrap when you need multiple instances (tests, storybook) or want to make
10
+ * the dependency explicit at a particular boundary.
11
+ */
12
+ export declare function FlowIdProvider({ flow, children }: FlowIdProviderProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,15 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createContext } from "react";
3
+ export const FlowContext = createContext(null);
4
+ /**
5
+ * Optional context provider for scoping a specific Flow instance to a
6
+ * subtree. Most apps don't need it: the React hooks fall back to the
7
+ * singleton set by `createFlow()`, so just calling `createFlow()` once at
8
+ * app start is enough.
9
+ *
10
+ * Wrap when you need multiple instances (tests, storybook) or want to make
11
+ * the dependency explicit at a particular boundary.
12
+ */
13
+ export function FlowIdProvider({ flow, children }) {
14
+ return _jsx(FlowContext.Provider, { value: flow ?? null, children: children });
15
+ }
@@ -0,0 +1,45 @@
1
+ import type { JWTPayload } from "jose";
2
+ export type FlowUser = {
3
+ id: string;
4
+ username: string;
5
+ };
6
+ export type FlowCredential = {
7
+ id: string;
8
+ publicKey: string;
9
+ };
10
+ export type AuthResponse = {
11
+ jwt: string;
12
+ user: FlowUser;
13
+ credential: FlowCredential;
14
+ };
15
+ export type AuthConfig = {
16
+ rpId: string;
17
+ rpName: string;
18
+ };
19
+ export type WebAuthnSignature = {
20
+ signature: {
21
+ r: string;
22
+ s: string;
23
+ };
24
+ metadata: {
25
+ authenticatorData: string;
26
+ clientDataJSON: string;
27
+ challengeIndex: number;
28
+ typeIndex: number;
29
+ };
30
+ };
31
+ export type AuthResponseWithWebAuthn = AuthResponse & {
32
+ webauthn?: WebAuthnSignature;
33
+ };
34
+ export type PasskeyPluginOptions = {
35
+ rpId: string;
36
+ rpName?: string;
37
+ };
38
+ export type VerifyOptions = {
39
+ audience: string;
40
+ issuerUrl?: string;
41
+ };
42
+ export type VerifiedFlowJWT = JWTPayload & {
43
+ sub: string;
44
+ username?: string;
45
+ };
File without changes
@@ -0,0 +1,55 @@
1
+ export type DialogReferrer = {
2
+ icon?: string | {
3
+ light: string;
4
+ dark: string;
5
+ };
6
+ title: string;
7
+ origin: string;
8
+ url?: URL;
9
+ };
10
+ export type DialogError = {
11
+ action: "close" | "retry-in-popup";
12
+ title: string;
13
+ message: string;
14
+ name: string;
15
+ secondaryMessage?: string;
16
+ };
17
+ export type BoundaryError = {
18
+ type: "runtime" | "call";
19
+ title: string;
20
+ message: string;
21
+ };
22
+ export type DialogCustomFeatures = {
23
+ bugReporting?: boolean;
24
+ emailInput?: boolean;
25
+ signUpLink?: boolean;
26
+ createAccount?: boolean;
27
+ };
28
+ export type DialogCustomLabels = {
29
+ signInPrompt?: string;
30
+ signIn?: string;
31
+ signUp?: string;
32
+ createAccount?: string;
33
+ signInAlt?: string;
34
+ dialogTitle?: string;
35
+ exampleEmail?: string;
36
+ bugReportEmail?: string;
37
+ switchAccount?: string;
38
+ signUpLink?: string;
39
+ };
40
+ export type DialogState = {
41
+ mode: string;
42
+ display: "floating" | "drawer" | "full";
43
+ colorScheme: "light" | "dark" | "light dark";
44
+ referrer: DialogReferrer | null;
45
+ initialized: boolean;
46
+ origin: string | null;
47
+ trusted: boolean;
48
+ error: DialogError | null;
49
+ accountMetadata: Record<string, {
50
+ username?: string;
51
+ email?: string;
52
+ }>;
53
+ customFeatures?: DialogCustomFeatures;
54
+ customLabels?: DialogCustomLabels;
55
+ };
File without changes
@@ -0,0 +1,7 @@
1
+ export type { AuthConfig, AuthResponse, AuthResponseWithWebAuthn, FlowCredential, FlowUser, PasskeyPluginOptions, VerifiedFlowJWT, VerifyOptions, WebAuthnSignature, } from "./auth";
2
+ export type { AccessKeyOptions, AccessKeyPreparation, Address, CreateDialogHostOptions, CreateFlowOptions, DialogHost, DialogOpenOptions, FinalizeAccessKeyParams, Flow, FlowIdProviderProps, FlowConnectorParameters, FlowState, Listener, LoginOptions, ResolveAccountParams, ResolvedAccessKeyOptions, RootCredential, RunLoginParams, RunLoginResult, SendCallsArgs, SendTransactionArgs, Session, SignMessageArgs, SignTypedDataArgs, SigningContext, StoredAccessKey, Store, } from "./sdk";
3
+ export { isPersonalSignParams, isSendCallsParams, isSendTransactionParams, } from "./protocol";
4
+ export type { Call, ConnectCapabilities, ConnectRequest, ConnectResponse, MethodName, MethodParams, MethodResult, RestoreRequest, RestoreResponse, RpcRequest, SendCallsParams, SendCallsRequest, SendCallsResponse, SendTransactionParams, SendTransactionRequest, SendTransactionResponse, SignMessageRequest, SignMessageResponse, SignOutRequest, SignOutResponse, SignTypedDataRequest, SignTypedDataResponse, TransactionArgs, TypedData, TypedDataDomain, TypedDataField, } from "./protocol";
5
+ export type { Bridge, BridgeParameters, FlowAccount, FlowRemote, FlowRemoteConfig, FromWindowOptions, MessageResponse, Messenger, OneOf, Payload, QueuedRequest, ReadyOptions, RemoteFlowState, RemoteState, Schema, Storage, Topic, WithReady, } from "./messenger";
6
+ export type { BoundaryError, DialogCustomFeatures, DialogCustomLabels, DialogError, DialogReferrer, DialogState, } from "./dialog";
7
+ export type { CoinAsset, IdentifiedTx, TxApprove, TxConvert, TxSend, TxSwap, } from "./tx";
@@ -0,0 +1 @@
1
+ export { isPersonalSignParams, isSendCallsParams, isSendTransactionParams, } from "./protocol";
@@ -0,0 +1,162 @@
1
+ import type * as RpcRequestOx from "ox/RpcRequest";
2
+ import type * as RpcResponseOx from "ox/RpcResponse";
3
+ import type { StoreApi } from "zustand/vanilla";
4
+ export type ReadyOptions = {
5
+ chainIds?: readonly number[] | undefined;
6
+ };
7
+ export type QueuedRequest = {
8
+ request: RpcRequestOx.RpcRequest;
9
+ status?: "pending" | "fulfilled" | "rejected";
10
+ account?: {
11
+ address: string;
12
+ key?: {
13
+ credentialId?: string;
14
+ publicKey: string;
15
+ };
16
+ };
17
+ };
18
+ export type Schema = [
19
+ {
20
+ topic: "close";
21
+ payload: undefined;
22
+ response: undefined;
23
+ },
24
+ {
25
+ topic: "ready";
26
+ payload: ReadyOptions;
27
+ response: undefined;
28
+ },
29
+ {
30
+ topic: "rpc-requests";
31
+ payload: readonly QueuedRequest[];
32
+ response: undefined;
33
+ },
34
+ {
35
+ topic: "rpc-response";
36
+ payload: RpcResponseOx.RpcResponse & {
37
+ _request: RpcRequestOx.RpcRequest;
38
+ };
39
+ response: undefined;
40
+ },
41
+ {
42
+ topic: "account";
43
+ payload: {
44
+ account: {
45
+ address: string;
46
+ username?: string;
47
+ };
48
+ };
49
+ response: undefined;
50
+ },
51
+ {
52
+ topic: "__internal";
53
+ payload: {
54
+ type: "init";
55
+ mode: "iframe" | "popup" | "popup-standalone" | "page";
56
+ referrer: {
57
+ icon?: string | {
58
+ light: string;
59
+ dark: string;
60
+ };
61
+ title: string;
62
+ };
63
+ theme?: {
64
+ colorScheme?: string;
65
+ };
66
+ features?: Record<string, boolean>;
67
+ labels?: Record<string, string>;
68
+ } | {
69
+ type: "switch";
70
+ mode: "iframe" | "popup" | "popup-standalone" | "page";
71
+ } | {
72
+ type: "resize";
73
+ height?: number;
74
+ width?: number;
75
+ } | {
76
+ type: "set-theme";
77
+ theme: {
78
+ colorScheme?: string;
79
+ };
80
+ };
81
+ response: undefined;
82
+ }
83
+ ];
84
+ export type Topic = Schema[number]["topic"];
85
+ export type Payload<topic extends Topic> = Extract<Schema[number], {
86
+ topic: topic;
87
+ }>["payload"];
88
+ export type MessageResponse<topic extends Topic> = Extract<Schema[number], {
89
+ topic: topic;
90
+ }>["response"];
91
+ export type Messenger = {
92
+ destroy: () => void;
93
+ on: <const topic extends Topic>(topic: topic | Topic, listener: (payload: Payload<topic>, event: MessageEvent) => void, id?: string | undefined) => () => void;
94
+ send: <const topic extends Topic>(topic: topic | Topic, payload: Payload<topic>, targetOrigin?: string | undefined) => Promise<{
95
+ id: string;
96
+ topic: topic;
97
+ payload: Payload<topic>;
98
+ }>;
99
+ sendAsync: <const topic extends Topic>(topic: topic | Topic, payload: Payload<topic>, targetOrigin?: string | undefined) => Promise<MessageResponse<topic>>;
100
+ };
101
+ export type WithReady = Messenger & {
102
+ ready: (options: ReadyOptions) => void;
103
+ };
104
+ export type Bridge = WithReady & {
105
+ waitForReady: () => Promise<ReadyOptions>;
106
+ };
107
+ export type FromWindowOptions = {
108
+ targetOrigin?: string;
109
+ };
110
+ export type BridgeParameters = {
111
+ from: Messenger;
112
+ to: Messenger;
113
+ waitForReady?: boolean;
114
+ };
115
+ export type FlowAccount = {
116
+ address: string;
117
+ username?: string;
118
+ key?: {
119
+ credentialId?: string;
120
+ publicKey: string;
121
+ };
122
+ };
123
+ export type RemoteFlowState = {
124
+ accounts: FlowAccount[];
125
+ };
126
+ export type RemoteState = {
127
+ requests: readonly QueuedRequest[];
128
+ };
129
+ export type Storage = {
130
+ getItem: <value>(name: string) => Promise<value | null> | value | null;
131
+ removeItem: (name: string) => Promise<void> | void;
132
+ setItem: (name: string, value: unknown) => Promise<void> | void;
133
+ sizeLimit: number;
134
+ storages?: readonly Storage[];
135
+ };
136
+ export type FlowRemoteConfig = {
137
+ messenger?: Bridge | Messenger;
138
+ storage?: Storage;
139
+ storageKey?: string;
140
+ };
141
+ export type FlowRemote = {
142
+ messenger: OneOf<WithReady | Messenger>;
143
+ ready: () => Promise<void>;
144
+ _internal: {
145
+ store: StoreApi<RemoteFlowState> & {
146
+ persist: {
147
+ rehydrate: () => Promise<void>;
148
+ };
149
+ };
150
+ remoteStore: StoreApi<RemoteState>;
151
+ storage: Storage;
152
+ };
153
+ };
154
+ export type OneOf<union extends object, fallback extends object | undefined = undefined, keys extends keyof union = union extends union ? keyof union : never> = union extends infer item ? Pretty<{
155
+ [_key in keys as _key extends keyof item ? _key : never]: item[_key & keyof item];
156
+ } & {
157
+ [_key in Exclude<keys, keyof item>]?: never;
158
+ } & (fallback extends undefined ? {} : fallback)> : never;
159
+ type Pretty<type> = {
160
+ [key in keyof type]: type[key];
161
+ } & unknown;
162
+ export {};
File without changes