@rhinestone/1auth 0.6.4 → 0.6.7
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/{chunk-IP2FG4WQ.mjs → chunk-SXISYG2P.mjs} +10 -24
- package/dist/chunk-SXISYG2P.mjs.map +1 -0
- package/dist/{client-hZxAAhcl.d.mts → client-BrMrhetG.d.mts} +407 -71
- package/dist/{client-hZxAAhcl.d.ts → client-BrMrhetG.d.ts} +407 -71
- package/dist/index.d.mts +114 -9
- package/dist/index.d.ts +114 -9
- package/dist/index.js +434 -122
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +426 -100
- package/dist/index.mjs.map +1 -1
- package/dist/provider-CDl9wYEc.d.mts +88 -0
- package/dist/provider-Dgv533YQ.d.ts +88 -0
- package/dist/react.d.mts +33 -15
- package/dist/react.d.ts +33 -15
- package/dist/react.js +6 -23
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +6 -23
- package/dist/react.mjs.map +1 -1
- package/dist/wagmi.d.mts +39 -3
- package/dist/wagmi.d.ts +39 -3
- package/dist/wagmi.js +107 -25
- package/dist/wagmi.js.map +1 -1
- package/dist/wagmi.mjs +99 -3
- package/dist/wagmi.mjs.map +1 -1
- package/package.json +1 -6
- package/dist/chunk-IP2FG4WQ.mjs.map +0 -1
- package/dist/provider-A89sCgGr.d.ts +0 -27
- package/dist/provider-B9GKBMC5.d.mts +0 -27
- package/dist/server.d.mts +0 -44
- package/dist/server.d.ts +0 -44
- package/dist/server.js +0 -145
- package/dist/server.js.map +0 -1
- package/dist/server.mjs +0 -119
- package/dist/server.mjs.map +0 -1
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { O as OneAuthClient, z as CloseOnStatus } from './client-BrMrhetG.mjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* EIP-1193 JSON-RPC provider factory for the 1auth passkey authentication system.
|
|
5
|
+
*
|
|
6
|
+
* Creates a browser-side provider object that implements the EIP-1193 standard so any
|
|
7
|
+
* Ethereum library (ethers, viem, wagmi) can use 1auth passkey signing and cross-chain
|
|
8
|
+
* intent execution without modification. All transaction signing is delegated to the
|
|
9
|
+
* passkey service rather than holding private keys in the browser.
|
|
10
|
+
*
|
|
11
|
+
* Supported RPC methods:
|
|
12
|
+
* - eth_chainId, eth_accounts, eth_requestAccounts
|
|
13
|
+
* - personal_sign, eth_sign, eth_signTypedData, eth_signTypedData_v4
|
|
14
|
+
* - eth_sendTransaction
|
|
15
|
+
* - wallet_connect, wallet_disconnect, wallet_switchEthereumChain
|
|
16
|
+
* - wallet_sendCalls, wallet_getCallsStatus, wallet_getCallsHistory (EIP-5792)
|
|
17
|
+
* - wallet_getCapabilities, wallet_getAssets
|
|
18
|
+
*
|
|
19
|
+
* @module
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
type ProviderRequest = {
|
|
23
|
+
method: string;
|
|
24
|
+
params?: unknown[] | Record<string, unknown>;
|
|
25
|
+
};
|
|
26
|
+
type Listener = (...args: unknown[]) => void;
|
|
27
|
+
type OneAuthProvider = {
|
|
28
|
+
request: (args: ProviderRequest) => Promise<unknown>;
|
|
29
|
+
on: (event: string, listener: Listener) => void;
|
|
30
|
+
removeListener: (event: string, listener: Listener) => void;
|
|
31
|
+
disconnect: () => Promise<void>;
|
|
32
|
+
};
|
|
33
|
+
type OneAuthProviderOptions = {
|
|
34
|
+
client: OneAuthClient;
|
|
35
|
+
chainId: number;
|
|
36
|
+
storageKey?: string;
|
|
37
|
+
/** When to close the dialog and return success. Defaults to "preconfirmed" */
|
|
38
|
+
closeOn?: CloseOnStatus;
|
|
39
|
+
waitForHash?: boolean;
|
|
40
|
+
hashTimeoutMs?: number;
|
|
41
|
+
hashIntervalMs?: number;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Creates an EIP-1193 compatible JSON-RPC provider backed by 1auth passkey authentication.
|
|
45
|
+
*
|
|
46
|
+
* The returned provider object can be used anywhere a standard Ethereum provider is
|
|
47
|
+
* accepted (e.g. passed to `createWalletClient` in viem, used as `window.ethereum`, or
|
|
48
|
+
* supplied to ethers.js `BrowserProvider`). Connection state (address + username) is
|
|
49
|
+
* persisted in `localStorage` under the configured `storageKey`.
|
|
50
|
+
*
|
|
51
|
+
* @param options - Provider configuration
|
|
52
|
+
* @param options.client - Configured `OneAuthClient` instance used to open auth/sign dialogs
|
|
53
|
+
* @param options.chainId - Default chain ID the provider reports via `eth_chainId`
|
|
54
|
+
* @param options.storageKey - localStorage key for persisting the connected user.
|
|
55
|
+
* Defaults to `"1auth-user"`. Override to support multiple concurrent connections.
|
|
56
|
+
* @param options.closeOn - Controls when the signing dialog closes and the promise resolves.
|
|
57
|
+
* `"preconfirmed"` resolves as soon as the intent is submitted to the orchestrator;
|
|
58
|
+
* `"completed"` waits for on-chain confirmation. Defaults to `"completed"` when
|
|
59
|
+
* `waitForHash` is true, otherwise `"preconfirmed"`.
|
|
60
|
+
* @param options.waitForHash - When true, polls the intent status until a transaction hash
|
|
61
|
+
* is available before resolving `eth_sendTransaction` / `wallet_sendCalls`. Defaults to true.
|
|
62
|
+
* @param options.hashTimeoutMs - Maximum milliseconds to wait for a transaction hash.
|
|
63
|
+
* Passed directly to the passkey service intent submission.
|
|
64
|
+
* @param options.hashIntervalMs - Polling interval in milliseconds when waiting for a hash.
|
|
65
|
+
* Passed directly to the passkey service intent submission.
|
|
66
|
+
* @returns An EIP-1193 provider with `request`, `on`, `removeListener`, and `disconnect`.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* import { OneAuthClient } from "@rhinestone/1auth";
|
|
71
|
+
* import { createOneAuthProvider } from "@rhinestone/1auth";
|
|
72
|
+
*
|
|
73
|
+
* const client = new OneAuthClient({ clientId: "my-app" });
|
|
74
|
+
* const provider = createOneAuthProvider({ client, chainId: 8453 }); // Base
|
|
75
|
+
*
|
|
76
|
+
* // Use with viem
|
|
77
|
+
* import { createWalletClient, custom } from "viem";
|
|
78
|
+
* import { base } from "viem/chains";
|
|
79
|
+
* const walletClient = createWalletClient({ chain: base, transport: custom(provider) });
|
|
80
|
+
*
|
|
81
|
+
* // Standard EIP-1193 usage
|
|
82
|
+
* const accounts = await provider.request({ method: "eth_requestAccounts" });
|
|
83
|
+
* provider.on("accountsChanged", (accounts) => console.log(accounts));
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
declare function createOneAuthProvider(options: OneAuthProviderOptions): OneAuthProvider;
|
|
87
|
+
|
|
88
|
+
export { type OneAuthProvider as O, type OneAuthProviderOptions as a, createOneAuthProvider as c };
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { O as OneAuthClient, z as CloseOnStatus } from './client-BrMrhetG.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* EIP-1193 JSON-RPC provider factory for the 1auth passkey authentication system.
|
|
5
|
+
*
|
|
6
|
+
* Creates a browser-side provider object that implements the EIP-1193 standard so any
|
|
7
|
+
* Ethereum library (ethers, viem, wagmi) can use 1auth passkey signing and cross-chain
|
|
8
|
+
* intent execution without modification. All transaction signing is delegated to the
|
|
9
|
+
* passkey service rather than holding private keys in the browser.
|
|
10
|
+
*
|
|
11
|
+
* Supported RPC methods:
|
|
12
|
+
* - eth_chainId, eth_accounts, eth_requestAccounts
|
|
13
|
+
* - personal_sign, eth_sign, eth_signTypedData, eth_signTypedData_v4
|
|
14
|
+
* - eth_sendTransaction
|
|
15
|
+
* - wallet_connect, wallet_disconnect, wallet_switchEthereumChain
|
|
16
|
+
* - wallet_sendCalls, wallet_getCallsStatus, wallet_getCallsHistory (EIP-5792)
|
|
17
|
+
* - wallet_getCapabilities, wallet_getAssets
|
|
18
|
+
*
|
|
19
|
+
* @module
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
type ProviderRequest = {
|
|
23
|
+
method: string;
|
|
24
|
+
params?: unknown[] | Record<string, unknown>;
|
|
25
|
+
};
|
|
26
|
+
type Listener = (...args: unknown[]) => void;
|
|
27
|
+
type OneAuthProvider = {
|
|
28
|
+
request: (args: ProviderRequest) => Promise<unknown>;
|
|
29
|
+
on: (event: string, listener: Listener) => void;
|
|
30
|
+
removeListener: (event: string, listener: Listener) => void;
|
|
31
|
+
disconnect: () => Promise<void>;
|
|
32
|
+
};
|
|
33
|
+
type OneAuthProviderOptions = {
|
|
34
|
+
client: OneAuthClient;
|
|
35
|
+
chainId: number;
|
|
36
|
+
storageKey?: string;
|
|
37
|
+
/** When to close the dialog and return success. Defaults to "preconfirmed" */
|
|
38
|
+
closeOn?: CloseOnStatus;
|
|
39
|
+
waitForHash?: boolean;
|
|
40
|
+
hashTimeoutMs?: number;
|
|
41
|
+
hashIntervalMs?: number;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Creates an EIP-1193 compatible JSON-RPC provider backed by 1auth passkey authentication.
|
|
45
|
+
*
|
|
46
|
+
* The returned provider object can be used anywhere a standard Ethereum provider is
|
|
47
|
+
* accepted (e.g. passed to `createWalletClient` in viem, used as `window.ethereum`, or
|
|
48
|
+
* supplied to ethers.js `BrowserProvider`). Connection state (address + username) is
|
|
49
|
+
* persisted in `localStorage` under the configured `storageKey`.
|
|
50
|
+
*
|
|
51
|
+
* @param options - Provider configuration
|
|
52
|
+
* @param options.client - Configured `OneAuthClient` instance used to open auth/sign dialogs
|
|
53
|
+
* @param options.chainId - Default chain ID the provider reports via `eth_chainId`
|
|
54
|
+
* @param options.storageKey - localStorage key for persisting the connected user.
|
|
55
|
+
* Defaults to `"1auth-user"`. Override to support multiple concurrent connections.
|
|
56
|
+
* @param options.closeOn - Controls when the signing dialog closes and the promise resolves.
|
|
57
|
+
* `"preconfirmed"` resolves as soon as the intent is submitted to the orchestrator;
|
|
58
|
+
* `"completed"` waits for on-chain confirmation. Defaults to `"completed"` when
|
|
59
|
+
* `waitForHash` is true, otherwise `"preconfirmed"`.
|
|
60
|
+
* @param options.waitForHash - When true, polls the intent status until a transaction hash
|
|
61
|
+
* is available before resolving `eth_sendTransaction` / `wallet_sendCalls`. Defaults to true.
|
|
62
|
+
* @param options.hashTimeoutMs - Maximum milliseconds to wait for a transaction hash.
|
|
63
|
+
* Passed directly to the passkey service intent submission.
|
|
64
|
+
* @param options.hashIntervalMs - Polling interval in milliseconds when waiting for a hash.
|
|
65
|
+
* Passed directly to the passkey service intent submission.
|
|
66
|
+
* @returns An EIP-1193 provider with `request`, `on`, `removeListener`, and `disconnect`.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* import { OneAuthClient } from "@rhinestone/1auth";
|
|
71
|
+
* import { createOneAuthProvider } from "@rhinestone/1auth";
|
|
72
|
+
*
|
|
73
|
+
* const client = new OneAuthClient({ clientId: "my-app" });
|
|
74
|
+
* const provider = createOneAuthProvider({ client, chainId: 8453 }); // Base
|
|
75
|
+
*
|
|
76
|
+
* // Use with viem
|
|
77
|
+
* import { createWalletClient, custom } from "viem";
|
|
78
|
+
* import { base } from "viem/chains";
|
|
79
|
+
* const walletClient = createWalletClient({ chain: base, transport: custom(provider) });
|
|
80
|
+
*
|
|
81
|
+
* // Standard EIP-1193 usage
|
|
82
|
+
* const accounts = await provider.request({ method: "eth_requestAccounts" });
|
|
83
|
+
* provider.on("accountsChanged", (accounts) => console.log(accounts));
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
declare function createOneAuthProvider(options: OneAuthProviderOptions): OneAuthProvider;
|
|
87
|
+
|
|
88
|
+
export { type OneAuthProvider as O, type OneAuthProviderOptions as a, createOneAuthProvider as c };
|
package/dist/react.d.mts
CHANGED
|
@@ -1,30 +1,18 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
import { O as OneAuthClient,
|
|
3
|
+
import { O as OneAuthClient, v as SendIntentOptions, S as SendIntentResult, z as CloseOnStatus } from './client-BrMrhetG.mjs';
|
|
4
4
|
|
|
5
5
|
interface PayButtonProps {
|
|
6
6
|
/** The OneAuthClient instance */
|
|
7
7
|
client: OneAuthClient;
|
|
8
8
|
/** Intent parameters (calls, targetChain, etc.) - username will be filled automatically */
|
|
9
|
-
intent: Omit<SendIntentOptions, "username" | "closeOn"
|
|
9
|
+
intent: Omit<SendIntentOptions, "username" | "closeOn">;
|
|
10
10
|
/** Called when payment succeeds */
|
|
11
11
|
onSuccess?: (result: SendIntentResult) => void;
|
|
12
12
|
/** Called when payment fails */
|
|
13
13
|
onError?: (error: Error) => void;
|
|
14
14
|
/** When to close the dialog and return success. Defaults to "preconfirmed" */
|
|
15
15
|
closeOn?: CloseOnStatus;
|
|
16
|
-
/**
|
|
17
|
-
* Optional callback to get a signed intent from your backend.
|
|
18
|
-
* Provides XSS protection by ensuring calls are constructed server-side.
|
|
19
|
-
* If provided, this will be called with the intent and username before sending.
|
|
20
|
-
* The returned signed intent will be used instead of the raw intent.
|
|
21
|
-
*/
|
|
22
|
-
getSignedIntent?: (params: {
|
|
23
|
-
username: string;
|
|
24
|
-
targetChain: number;
|
|
25
|
-
calls: SendIntentOptions["calls"];
|
|
26
|
-
tokenRequests?: SendIntentOptions["tokenRequests"];
|
|
27
|
-
}) => Promise<DeveloperSignedIntent>;
|
|
28
16
|
/** Button text - defaults to "Pay with 1auth" */
|
|
29
17
|
children?: React.ReactNode;
|
|
30
18
|
/** Custom class name */
|
|
@@ -36,6 +24,36 @@ interface PayButtonProps {
|
|
|
36
24
|
/** Hide the fingerprint icon */
|
|
37
25
|
hideIcon?: boolean;
|
|
38
26
|
}
|
|
39
|
-
|
|
27
|
+
/**
|
|
28
|
+
* A pre-built payment button that integrates 1auth passkey authentication
|
|
29
|
+
* and intent submission into a single interactive element.
|
|
30
|
+
*
|
|
31
|
+
* The button manages its own loading and success states. On first click it
|
|
32
|
+
* recovers the last authenticated user from `localStorage`; if none is found
|
|
33
|
+
* it opens the auth modal before submitting the intent. On subsequent clicks
|
|
34
|
+
* the stored session is reused so the user only needs to re-authenticate when
|
|
35
|
+
* their session has been invalidated server-side.
|
|
36
|
+
*
|
|
37
|
+
* @param props - See {@link PayButtonProps} for the full set of options.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```tsx
|
|
41
|
+
* import { PayButton } from "@rhinestone/1auth/react";
|
|
42
|
+
* import { client } from "./auth"; // your OneAuthClient instance
|
|
43
|
+
*
|
|
44
|
+
* <PayButton
|
|
45
|
+
* client={client}
|
|
46
|
+
* intent={{
|
|
47
|
+
* targetChain: 8453, // Base
|
|
48
|
+
* calls: [{ to: "0xRecipient", data: "0x", value: "1000000" }],
|
|
49
|
+
* }}
|
|
50
|
+
* onSuccess={(result) => console.log("tx:", result.transactionHash)}
|
|
51
|
+
* onError={(err) => console.error(err)}
|
|
52
|
+
* >
|
|
53
|
+
* Pay $5 USDC
|
|
54
|
+
* </PayButton>
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
declare function PayButton({ client, intent, onSuccess, onError, closeOn, children, className, style, disabled, hideIcon, }: PayButtonProps): react_jsx_runtime.JSX.Element;
|
|
40
58
|
|
|
41
59
|
export { CloseOnStatus, PayButton, type PayButtonProps, SendIntentOptions, SendIntentResult };
|
package/dist/react.d.ts
CHANGED
|
@@ -1,30 +1,18 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
import { O as OneAuthClient,
|
|
3
|
+
import { O as OneAuthClient, v as SendIntentOptions, S as SendIntentResult, z as CloseOnStatus } from './client-BrMrhetG.js';
|
|
4
4
|
|
|
5
5
|
interface PayButtonProps {
|
|
6
6
|
/** The OneAuthClient instance */
|
|
7
7
|
client: OneAuthClient;
|
|
8
8
|
/** Intent parameters (calls, targetChain, etc.) - username will be filled automatically */
|
|
9
|
-
intent: Omit<SendIntentOptions, "username" | "closeOn"
|
|
9
|
+
intent: Omit<SendIntentOptions, "username" | "closeOn">;
|
|
10
10
|
/** Called when payment succeeds */
|
|
11
11
|
onSuccess?: (result: SendIntentResult) => void;
|
|
12
12
|
/** Called when payment fails */
|
|
13
13
|
onError?: (error: Error) => void;
|
|
14
14
|
/** When to close the dialog and return success. Defaults to "preconfirmed" */
|
|
15
15
|
closeOn?: CloseOnStatus;
|
|
16
|
-
/**
|
|
17
|
-
* Optional callback to get a signed intent from your backend.
|
|
18
|
-
* Provides XSS protection by ensuring calls are constructed server-side.
|
|
19
|
-
* If provided, this will be called with the intent and username before sending.
|
|
20
|
-
* The returned signed intent will be used instead of the raw intent.
|
|
21
|
-
*/
|
|
22
|
-
getSignedIntent?: (params: {
|
|
23
|
-
username: string;
|
|
24
|
-
targetChain: number;
|
|
25
|
-
calls: SendIntentOptions["calls"];
|
|
26
|
-
tokenRequests?: SendIntentOptions["tokenRequests"];
|
|
27
|
-
}) => Promise<DeveloperSignedIntent>;
|
|
28
16
|
/** Button text - defaults to "Pay with 1auth" */
|
|
29
17
|
children?: React.ReactNode;
|
|
30
18
|
/** Custom class name */
|
|
@@ -36,6 +24,36 @@ interface PayButtonProps {
|
|
|
36
24
|
/** Hide the fingerprint icon */
|
|
37
25
|
hideIcon?: boolean;
|
|
38
26
|
}
|
|
39
|
-
|
|
27
|
+
/**
|
|
28
|
+
* A pre-built payment button that integrates 1auth passkey authentication
|
|
29
|
+
* and intent submission into a single interactive element.
|
|
30
|
+
*
|
|
31
|
+
* The button manages its own loading and success states. On first click it
|
|
32
|
+
* recovers the last authenticated user from `localStorage`; if none is found
|
|
33
|
+
* it opens the auth modal before submitting the intent. On subsequent clicks
|
|
34
|
+
* the stored session is reused so the user only needs to re-authenticate when
|
|
35
|
+
* their session has been invalidated server-side.
|
|
36
|
+
*
|
|
37
|
+
* @param props - See {@link PayButtonProps} for the full set of options.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```tsx
|
|
41
|
+
* import { PayButton } from "@rhinestone/1auth/react";
|
|
42
|
+
* import { client } from "./auth"; // your OneAuthClient instance
|
|
43
|
+
*
|
|
44
|
+
* <PayButton
|
|
45
|
+
* client={client}
|
|
46
|
+
* intent={{
|
|
47
|
+
* targetChain: 8453, // Base
|
|
48
|
+
* calls: [{ to: "0xRecipient", data: "0x", value: "1000000" }],
|
|
49
|
+
* }}
|
|
50
|
+
* onSuccess={(result) => console.log("tx:", result.transactionHash)}
|
|
51
|
+
* onError={(err) => console.error(err)}
|
|
52
|
+
* >
|
|
53
|
+
* Pay $5 USDC
|
|
54
|
+
* </PayButton>
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
declare function PayButton({ client, intent, onSuccess, onError, closeOn, children, className, style, disabled, hideIcon, }: PayButtonProps): react_jsx_runtime.JSX.Element;
|
|
40
58
|
|
|
41
59
|
export { CloseOnStatus, PayButton, type PayButtonProps, SendIntentOptions, SendIntentResult };
|
package/dist/react.js
CHANGED
|
@@ -108,7 +108,6 @@ function PayButton({
|
|
|
108
108
|
onSuccess,
|
|
109
109
|
onError,
|
|
110
110
|
closeOn = "preconfirmed",
|
|
111
|
-
getSignedIntent,
|
|
112
111
|
children = "Pay with 1auth",
|
|
113
112
|
className,
|
|
114
113
|
style,
|
|
@@ -161,28 +160,12 @@ function PayButton({
|
|
|
161
160
|
}
|
|
162
161
|
let result;
|
|
163
162
|
try {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
targetChain: intent.targetChain,
|
|
171
|
-
calls: intent.calls,
|
|
172
|
-
tokenRequests: intent.tokenRequests
|
|
173
|
-
});
|
|
174
|
-
result = await client.sendIntent({
|
|
175
|
-
signedIntent,
|
|
176
|
-
closeOn
|
|
177
|
-
});
|
|
178
|
-
} else {
|
|
179
|
-
result = await client.sendIntent({
|
|
180
|
-
...intent,
|
|
181
|
-
username: username || void 0,
|
|
182
|
-
accountAddress: accountAddress || void 0,
|
|
183
|
-
closeOn
|
|
184
|
-
});
|
|
185
|
-
}
|
|
163
|
+
result = await client.sendIntent({
|
|
164
|
+
...intent,
|
|
165
|
+
username: username || void 0,
|
|
166
|
+
accountAddress: accountAddress || void 0,
|
|
167
|
+
closeOn
|
|
168
|
+
});
|
|
186
169
|
} catch (err) {
|
|
187
170
|
if (err instanceof Error && err.message.includes("User not found")) {
|
|
188
171
|
localStorage.removeItem("1auth-user");
|
package/dist/react.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/react.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { OneAuthClient } from \"./client\";\nimport type { SendIntentOptions, SendIntentResult, CloseOnStatus, DeveloperSignedIntent } from \"./types\";\n\n// Fingerprint icon SVG\nconst FingerprintIcon = ({ className }: { className?: string }) => (\n <svg\n className={className}\n width=\"20\"\n height=\"20\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n >\n <path d=\"M12 10a2 2 0 0 0-2 2c0 1.02-.1 2.51-.26 4\" />\n <path d=\"M14 13.12c0 2.38 0 6.38-1 8.88\" />\n <path d=\"M17.29 21.02c.12-.6.43-2.3.5-3.02\" />\n <path d=\"M2 12a10 10 0 0 1 18-6\" />\n <path d=\"M2 16h.01\" />\n <path d=\"M21.8 16c.2-2 .131-5.354 0-6\" />\n <path d=\"M5 19.5C5.5 18 6 15 6 12a6 6 0 0 1 .34-2\" />\n <path d=\"M8.65 22c.21-.66.45-1.32.57-2\" />\n <path d=\"M9 6.8a6 6 0 0 1 9 5.2v2\" />\n </svg>\n);\n\n// Default styles\nconst defaultStyles: React.CSSProperties = {\n display: \"inline-flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n gap: \"8px\",\n padding: \"16px 32px\",\n fontSize: \"16px\",\n fontWeight: 500,\n color: \"#ffffff\",\n backgroundColor: \"#18181b\",\n border: \"none\",\n borderRadius: \"9999px\",\n cursor: \"pointer\",\n transition: \"background-color 0.2s\",\n width: \"100%\",\n};\n\nconst defaultDisabledStyles: React.CSSProperties = {\n opacity: 0.5,\n cursor: \"not-allowed\",\n};\n\nconst defaultHoverStyles: React.CSSProperties = {\n backgroundColor: \"#27272a\",\n};\n\nconst defaultSuccessStyles: React.CSSProperties = {\n backgroundColor: \"#16a34a\",\n cursor: \"default\",\n};\n\n// Checkmark icon SVG\nconst CheckIcon = ({ className }: { className?: string }) => (\n <svg\n className={className}\n width=\"20\"\n height=\"20\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2.5\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n >\n <path d=\"M20 6L9 17l-5-5\" />\n </svg>\n);\n\nexport interface PayButtonProps {\n /** The OneAuthClient instance */\n client: OneAuthClient;\n /** Intent parameters (calls, targetChain, etc.) - username will be filled automatically */\n intent: Omit<SendIntentOptions, \"username\" | \"closeOn\" | \"signedIntent\">;\n /** Called when payment succeeds */\n onSuccess?: (result: SendIntentResult) => void;\n /** Called when payment fails */\n onError?: (error: Error) => void;\n /** When to close the dialog and return success. Defaults to \"preconfirmed\" */\n closeOn?: CloseOnStatus;\n /**\n * Optional callback to get a signed intent from your backend.\n * Provides XSS protection by ensuring calls are constructed server-side.\n * If provided, this will be called with the intent and username before sending.\n * The returned signed intent will be used instead of the raw intent.\n */\n getSignedIntent?: (params: {\n username: string;\n targetChain: number;\n calls: SendIntentOptions[\"calls\"];\n tokenRequests?: SendIntentOptions[\"tokenRequests\"];\n }) => Promise<DeveloperSignedIntent>;\n /** Button text - defaults to \"Pay with 1auth\" */\n children?: React.ReactNode;\n /** Custom class name */\n className?: string;\n /** Custom inline styles (merged with defaults) */\n style?: React.CSSProperties;\n /** Disabled state */\n disabled?: boolean;\n /** Hide the fingerprint icon */\n hideIcon?: boolean;\n}\n\nexport function PayButton({\n client,\n intent,\n onSuccess,\n onError,\n closeOn = \"preconfirmed\",\n getSignedIntent,\n children = \"Pay with 1auth\",\n className,\n style,\n disabled,\n hideIcon,\n}: PayButtonProps) {\n const [isProcessing, setIsProcessing] = React.useState(false);\n const [isSuccess, setIsSuccess] = React.useState(false);\n const [isHovered, setIsHovered] = React.useState(false);\n\n const handleClick = async () => {\n if (disabled || isProcessing || isSuccess) return;\n\n setIsProcessing(true);\n\n try {\n await executePayment();\n } catch (err) {\n if (err instanceof Error && !err.message.includes(\"rejected\")) {\n onError?.(err);\n }\n } finally {\n setIsProcessing(false);\n }\n };\n\n const executePayment = async (forceReauth = false) => {\n // Try to get existing user from localStorage\n let username: string | null = null;\n let accountAddress: string | null = null;\n if (!forceReauth) {\n const savedUser = localStorage.getItem(\"1auth-user\");\n if (savedUser) {\n try {\n const parsed = JSON.parse(savedUser);\n username = parsed.username || null;\n accountAddress = parsed.address || null;\n } catch {\n localStorage.removeItem(\"1auth-user\");\n }\n }\n }\n\n // If no user (or forced reauth), authenticate first\n if (!username && !accountAddress) {\n const authResult = await client.authWithModal();\n if (authResult.success && authResult.user) {\n username = authResult.user.username || null;\n accountAddress = authResult.user.address || null;\n const stored: Record<string, string> = {};\n if (username) stored.username = username;\n if (accountAddress) stored.address = accountAddress;\n localStorage.setItem(\"1auth-user\", JSON.stringify(stored));\n } else {\n // Auth cancelled or failed\n return;\n }\n }\n\n // Send the intent\n // If getSignedIntent is provided, use signed intent flow (XSS protected)\n // Otherwise, use the raw intent (only works for first-party apps)\n let result: SendIntentResult;\n try {\n if (getSignedIntent) {\n if (!username) {\n throw new Error(\"Username required for signed intents. Set a username first.\");\n }\n const signedIntent = await getSignedIntent({\n username,\n targetChain: intent.targetChain!,\n calls: intent.calls,\n tokenRequests: intent.tokenRequests,\n });\n result = await client.sendIntent({\n signedIntent,\n closeOn,\n });\n } else {\n result = await client.sendIntent({\n ...intent,\n username: username || undefined,\n accountAddress: accountAddress || undefined,\n closeOn,\n });\n }\n } catch (err) {\n // If user not found, clear localStorage and force re-authentication\n if (err instanceof Error && err.message.includes(\"User not found\")) {\n localStorage.removeItem(\"1auth-user\");\n return executePayment(true);\n }\n throw err;\n }\n\n if (result.success) {\n setIsSuccess(true);\n onSuccess?.(result);\n } else {\n // If user not found error in result, clear localStorage and retry\n if (result.error?.message?.includes(\"User not found\")) {\n localStorage.removeItem(\"1auth-user\");\n return executePayment(true);\n }\n onError?.(new Error(result.error?.message || \"Payment failed\"));\n }\n };\n\n const combinedStyles: React.CSSProperties = {\n ...defaultStyles,\n ...(isSuccess ? defaultSuccessStyles : {}),\n ...(isHovered && !disabled && !isProcessing && !isSuccess ? defaultHoverStyles : {}),\n ...(disabled || isProcessing ? defaultDisabledStyles : {}),\n ...style,\n };\n\n return (\n <button\n type=\"button\"\n className={className}\n style={combinedStyles}\n onClick={handleClick}\n disabled={disabled || isProcessing || isSuccess}\n onMouseEnter={() => setIsHovered(true)}\n onMouseLeave={() => setIsHovered(false)}\n >\n {isSuccess ? (\n <>\n <CheckIcon className=\"pay-button-icon\" />\n Paid\n </>\n ) : isProcessing ? (\n \"Processing...\"\n ) : (\n <>\n {!hideIcon && <FingerprintIcon className=\"pay-button-icon\" />}\n {children}\n </>\n )}\n </button>\n );\n}\n\n// Re-export types for convenience\nexport type { SendIntentOptions, SendIntentResult, CloseOnStatus } from \"./types\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,YAAuB;AAMrB;AADF,IAAM,kBAAkB,CAAC,EAAE,UAAU,MACnC;AAAA,EAAC;AAAA;AAAA,IACC;AAAA,IACA,OAAM;AAAA,IACN,QAAO;AAAA,IACP,SAAQ;AAAA,IACR,MAAK;AAAA,IACL,QAAO;AAAA,IACP,aAAY;AAAA,IACZ,eAAc;AAAA,IACd,gBAAe;AAAA,IAEf;AAAA,kDAAC,UAAK,GAAE,6CAA4C;AAAA,MACpD,4CAAC,UAAK,GAAE,kCAAiC;AAAA,MACzC,4CAAC,UAAK,GAAE,qCAAoC;AAAA,MAC5C,4CAAC,UAAK,GAAE,0BAAyB;AAAA,MACjC,4CAAC,UAAK,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AAAA,SACH;AAAA;AAAA,EAEJ;AAEJ;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/react.tsx"],"sourcesContent":["/**\n * @file React integration for the 1auth SDK.\n *\n * Exports the {@link PayButton} component — a ready-to-use payment button that\n * handles authentication, session recovery, and intent submission without\n * requiring the consuming app to manage auth state directly.\n *\n * @module @rhinestone/1auth/react\n */\n\nimport * as React from \"react\";\nimport { OneAuthClient } from \"./client\";\nimport type { SendIntentOptions, SendIntentResult, CloseOnStatus } from \"./types\";\n\n// Fingerprint icon SVG\nconst FingerprintIcon = ({ className }: { className?: string }) => (\n <svg\n className={className}\n width=\"20\"\n height=\"20\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n >\n <path d=\"M12 10a2 2 0 0 0-2 2c0 1.02-.1 2.51-.26 4\" />\n <path d=\"M14 13.12c0 2.38 0 6.38-1 8.88\" />\n <path d=\"M17.29 21.02c.12-.6.43-2.3.5-3.02\" />\n <path d=\"M2 12a10 10 0 0 1 18-6\" />\n <path d=\"M2 16h.01\" />\n <path d=\"M21.8 16c.2-2 .131-5.354 0-6\" />\n <path d=\"M5 19.5C5.5 18 6 15 6 12a6 6 0 0 1 .34-2\" />\n <path d=\"M8.65 22c.21-.66.45-1.32.57-2\" />\n <path d=\"M9 6.8a6 6 0 0 1 9 5.2v2\" />\n </svg>\n);\n\n// Default styles\nconst defaultStyles: React.CSSProperties = {\n display: \"inline-flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n gap: \"8px\",\n padding: \"16px 32px\",\n fontSize: \"16px\",\n fontWeight: 500,\n color: \"#ffffff\",\n backgroundColor: \"#18181b\",\n border: \"none\",\n borderRadius: \"9999px\",\n cursor: \"pointer\",\n transition: \"background-color 0.2s\",\n width: \"100%\",\n};\n\nconst defaultDisabledStyles: React.CSSProperties = {\n opacity: 0.5,\n cursor: \"not-allowed\",\n};\n\nconst defaultHoverStyles: React.CSSProperties = {\n backgroundColor: \"#27272a\",\n};\n\nconst defaultSuccessStyles: React.CSSProperties = {\n backgroundColor: \"#16a34a\",\n cursor: \"default\",\n};\n\n// Checkmark icon SVG\nconst CheckIcon = ({ className }: { className?: string }) => (\n <svg\n className={className}\n width=\"20\"\n height=\"20\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2.5\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n >\n <path d=\"M20 6L9 17l-5-5\" />\n </svg>\n);\n\nexport interface PayButtonProps {\n /** The OneAuthClient instance */\n client: OneAuthClient;\n /** Intent parameters (calls, targetChain, etc.) - username will be filled automatically */\n intent: Omit<SendIntentOptions, \"username\" | \"closeOn\">;\n /** Called when payment succeeds */\n onSuccess?: (result: SendIntentResult) => void;\n /** Called when payment fails */\n onError?: (error: Error) => void;\n /** When to close the dialog and return success. Defaults to \"preconfirmed\" */\n closeOn?: CloseOnStatus;\n /** Button text - defaults to \"Pay with 1auth\" */\n children?: React.ReactNode;\n /** Custom class name */\n className?: string;\n /** Custom inline styles (merged with defaults) */\n style?: React.CSSProperties;\n /** Disabled state */\n disabled?: boolean;\n /** Hide the fingerprint icon */\n hideIcon?: boolean;\n}\n\n/**\n * A pre-built payment button that integrates 1auth passkey authentication\n * and intent submission into a single interactive element.\n *\n * The button manages its own loading and success states. On first click it\n * recovers the last authenticated user from `localStorage`; if none is found\n * it opens the auth modal before submitting the intent. On subsequent clicks\n * the stored session is reused so the user only needs to re-authenticate when\n * their session has been invalidated server-side.\n *\n * @param props - See {@link PayButtonProps} for the full set of options.\n *\n * @example\n * ```tsx\n * import { PayButton } from \"@rhinestone/1auth/react\";\n * import { client } from \"./auth\"; // your OneAuthClient instance\n *\n * <PayButton\n * client={client}\n * intent={{\n * targetChain: 8453, // Base\n * calls: [{ to: \"0xRecipient\", data: \"0x\", value: \"1000000\" }],\n * }}\n * onSuccess={(result) => console.log(\"tx:\", result.transactionHash)}\n * onError={(err) => console.error(err)}\n * >\n * Pay $5 USDC\n * </PayButton>\n * ```\n */\nexport function PayButton({\n client,\n intent,\n onSuccess,\n onError,\n closeOn = \"preconfirmed\",\n children = \"Pay with 1auth\",\n className,\n style,\n disabled,\n hideIcon,\n}: PayButtonProps) {\n const [isProcessing, setIsProcessing] = React.useState(false);\n const [isSuccess, setIsSuccess] = React.useState(false);\n const [isHovered, setIsHovered] = React.useState(false);\n\n const handleClick = async () => {\n if (disabled || isProcessing || isSuccess) return;\n\n setIsProcessing(true);\n\n try {\n await executePayment();\n } catch (err) {\n if (err instanceof Error && !err.message.includes(\"rejected\")) {\n onError?.(err);\n }\n } finally {\n setIsProcessing(false);\n }\n };\n\n /**\n * Core payment execution with built-in session recovery and re-auth retry.\n *\n * Flow:\n * 1. On first call (`forceReauth = false`), attempt to load a cached user\n * from `localStorage` under the key `\"1auth-user\"`. If the JSON is\n * malformed the cache entry is removed so the next call starts clean.\n * 2. If no cached user exists (or `forceReauth` is `true`), open the auth\n * modal. On success, persist `{ username, address }` to `localStorage`\n * so subsequent clicks skip authentication.\n * 3. Submit the intent. If the server responds with \"User not found\" — which\n * happens when a cached username/address no longer exists on the server —\n * clear `localStorage` and call `executePayment(true)` to force a fresh\n * authentication before retrying once.\n *\n * @param forceReauth - When `true`, skip the localStorage lookup and go\n * straight to the auth modal. Used internally on \"User not found\" errors\n * to recover from a stale cache without requiring a second user gesture.\n */\n const executePayment = async (forceReauth = false) => {\n // Try to get existing user from localStorage\n let username: string | null = null;\n let accountAddress: string | null = null;\n if (!forceReauth) {\n const savedUser = localStorage.getItem(\"1auth-user\");\n if (savedUser) {\n try {\n const parsed = JSON.parse(savedUser);\n username = parsed.username || null;\n accountAddress = parsed.address || null;\n } catch {\n localStorage.removeItem(\"1auth-user\");\n }\n }\n }\n\n // If no user (or forced reauth), authenticate first\n if (!username && !accountAddress) {\n const authResult = await client.authWithModal();\n if (authResult.success && authResult.user) {\n username = authResult.user.username || null;\n accountAddress = authResult.user.address || null;\n const stored: Record<string, string> = {};\n if (username) stored.username = username;\n if (accountAddress) stored.address = accountAddress;\n localStorage.setItem(\"1auth-user\", JSON.stringify(stored));\n } else {\n // Auth cancelled or failed\n return;\n }\n }\n\n // Send the intent\n let result: SendIntentResult;\n try {\n result = await client.sendIntent({\n ...intent,\n username: username || undefined,\n accountAddress: accountAddress || undefined,\n closeOn,\n });\n } catch (err) {\n // If user not found, clear localStorage and force re-authentication\n if (err instanceof Error && err.message.includes(\"User not found\")) {\n localStorage.removeItem(\"1auth-user\");\n return executePayment(true);\n }\n throw err;\n }\n\n if (result.success) {\n setIsSuccess(true);\n onSuccess?.(result);\n } else {\n // If user not found error in result, clear localStorage and retry\n if (result.error?.message?.includes(\"User not found\")) {\n localStorage.removeItem(\"1auth-user\");\n return executePayment(true);\n }\n onError?.(new Error(result.error?.message || \"Payment failed\"));\n }\n };\n\n const combinedStyles: React.CSSProperties = {\n ...defaultStyles,\n ...(isSuccess ? defaultSuccessStyles : {}),\n ...(isHovered && !disabled && !isProcessing && !isSuccess ? defaultHoverStyles : {}),\n ...(disabled || isProcessing ? defaultDisabledStyles : {}),\n ...style,\n };\n\n return (\n <button\n type=\"button\"\n className={className}\n style={combinedStyles}\n onClick={handleClick}\n disabled={disabled || isProcessing || isSuccess}\n onMouseEnter={() => setIsHovered(true)}\n onMouseLeave={() => setIsHovered(false)}\n >\n {isSuccess ? (\n <>\n <CheckIcon className=\"pay-button-icon\" />\n Paid\n </>\n ) : isProcessing ? (\n \"Processing...\"\n ) : (\n <>\n {!hideIcon && <FingerprintIcon className=\"pay-button-icon\" />}\n {children}\n </>\n )}\n </button>\n );\n}\n\n// Re-export types for convenience\nexport type { SendIntentOptions, SendIntentResult, CloseOnStatus } from \"./types\";\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAUA,YAAuB;AAMrB;AADF,IAAM,kBAAkB,CAAC,EAAE,UA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C,mBAAgB,WAAU,mBAAkB;AAAA,QAC1D;AAAA,SACH;AAAA;AAAA,EAEJ;AAEJ;","names":[]}
|
package/dist/react.mjs
CHANGED
|
@@ -74,7 +74,6 @@ function PayButton({
|
|
|
74
74
|
onSuccess,
|
|
75
75
|
onError,
|
|
76
76
|
closeOn = "preconfirmed",
|
|
77
|
-
getSignedIntent,
|
|
78
77
|
children = "Pay with 1auth",
|
|
79
78
|
className,
|
|
80
79
|
style,
|
|
@@ -127,28 +126,12 @@ function PayButton({
|
|
|
127
126
|
}
|
|
128
127
|
let result;
|
|
129
128
|
try {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
targetChain: intent.targetChain,
|
|
137
|
-
calls: intent.calls,
|
|
138
|
-
tokenRequests: intent.tokenRequests
|
|
139
|
-
});
|
|
140
|
-
result = await client.sendIntent({
|
|
141
|
-
signedIntent,
|
|
142
|
-
closeOn
|
|
143
|
-
});
|
|
144
|
-
} else {
|
|
145
|
-
result = await client.sendIntent({
|
|
146
|
-
...intent,
|
|
147
|
-
username: username || void 0,
|
|
148
|
-
accountAddress: accountAddress || void 0,
|
|
149
|
-
closeOn
|
|
150
|
-
});
|
|
151
|
-
}
|
|
129
|
+
result = await client.sendIntent({
|
|
130
|
+
...intent,
|
|
131
|
+
username: username || void 0,
|
|
132
|
+
accountAddress: accountAddress || void 0,
|
|
133
|
+
closeOn
|
|
134
|
+
});
|
|
152
135
|
} catch (err) {
|
|
153
136
|
if (err instanceof Error && err.message.includes("User not found")) {
|
|
154
137
|
localStorage.removeItem("1auth-user");
|
package/dist/react.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/react.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { OneAuthClient } from \"./client\";\nimport type { SendIntentOptions, SendIntentResult, CloseOnStatus, DeveloperSignedIntent } from \"./types\";\n\n// Fingerprint icon SVG\nconst FingerprintIcon = ({ className }: { className?: string }) => (\n <svg\n className={className}\n width=\"20\"\n height=\"20\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n >\n <path d=\"M12 10a2 2 0 0 0-2 2c0 1.02-.1 2.51-.26 4\" />\n <path d=\"M14 13.12c0 2.38 0 6.38-1 8.88\" />\n <path d=\"M17.29 21.02c.12-.6.43-2.3.5-3.02\" />\n <path d=\"M2 12a10 10 0 0 1 18-6\" />\n <path d=\"M2 16h.01\" />\n <path d=\"M21.8 16c.2-2 .131-5.354 0-6\" />\n <path d=\"M5 19.5C5.5 18 6 15 6 12a6 6 0 0 1 .34-2\" />\n <path d=\"M8.65 22c.21-.66.45-1.32.57-2\" />\n <path d=\"M9 6.8a6 6 0 0 1 9 5.2v2\" />\n </svg>\n);\n\n// Default styles\nconst defaultStyles: React.CSSProperties = {\n display: \"inline-flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n gap: \"8px\",\n padding: \"16px 32px\",\n fontSize: \"16px\",\n fontWeight: 500,\n color: \"#ffffff\",\n backgroundColor: \"#18181b\",\n border: \"none\",\n borderRadius: \"9999px\",\n cursor: \"pointer\",\n transition: \"background-color 0.2s\",\n width: \"100%\",\n};\n\nconst defaultDisabledStyles: React.CSSProperties = {\n opacity: 0.5,\n cursor: \"not-allowed\",\n};\n\nconst defaultHoverStyles: React.CSSProperties = {\n backgroundColor: \"#27272a\",\n};\n\nconst defaultSuccessStyles: React.CSSProperties = {\n backgroundColor: \"#16a34a\",\n cursor: \"default\",\n};\n\n// Checkmark icon SVG\nconst CheckIcon = ({ className }: { className?: string }) => (\n <svg\n className={className}\n width=\"20\"\n height=\"20\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2.5\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n >\n <path d=\"M20 6L9 17l-5-5\" />\n </svg>\n);\n\nexport interface PayButtonProps {\n /** The OneAuthClient instance */\n client: OneAuthClient;\n /** Intent parameters (calls, targetChain, etc.) - username will be filled automatically */\n intent: Omit<SendIntentOptions, \"username\" | \"closeOn\" | \"signedIntent\">;\n /** Called when payment succeeds */\n onSuccess?: (result: SendIntentResult) => void;\n /** Called when payment fails */\n onError?: (error: Error) => void;\n /** When to close the dialog and return success. Defaults to \"preconfirmed\" */\n closeOn?: CloseOnStatus;\n /**\n * Optional callback to get a signed intent from your backend.\n * Provides XSS protection by ensuring calls are constructed server-side.\n * If provided, this will be called with the intent and username before sending.\n * The returned signed intent will be used instead of the raw intent.\n */\n getSignedIntent?: (params: {\n username: string;\n targetChain: number;\n calls: SendIntentOptions[\"calls\"];\n tokenRequests?: SendIntentOptions[\"tokenRequests\"];\n }) => Promise<DeveloperSignedIntent>;\n /** Button text - defaults to \"Pay with 1auth\" */\n children?: React.ReactNode;\n /** Custom class name */\n className?: string;\n /** Custom inline styles (merged with defaults) */\n style?: React.CSSProperties;\n /** Disabled state */\n disabled?: boolean;\n /** Hide the fingerprint icon */\n hideIcon?: boolean;\n}\n\nexport function PayButton({\n client,\n intent,\n onSuccess,\n onError,\n closeOn = \"preconfirmed\",\n getSignedIntent,\n children = \"Pay with 1auth\",\n className,\n style,\n disabled,\n hideIcon,\n}: PayButtonProps) {\n const [isProcessing, setIsProcessing] = React.useState(false);\n const [isSuccess, setIsSuccess] = React.useState(false);\n const [isHovered, setIsHovered] = React.useState(false);\n\n const handleClick = async () => {\n if (disabled || isProcessing || isSuccess) return;\n\n setIsProcessing(true);\n\n try {\n await executePayment();\n } catch (err) {\n if (err instanceof Error && !err.message.includes(\"rejected\")) {\n onError?.(err);\n }\n } finally {\n setIsProcessing(false);\n }\n };\n\n const executePayment = async (forceReauth = false) => {\n // Try to get existing user from localStorage\n let username: string | null = null;\n let accountAddress: string | null = null;\n if (!forceReauth) {\n const savedUser = localStorage.getItem(\"1auth-user\");\n if (savedUser) {\n try {\n const parsed = JSON.parse(savedUser);\n username = parsed.username || null;\n accountAddress = parsed.address || null;\n } catch {\n localStorage.removeItem(\"1auth-user\");\n }\n }\n }\n\n // If no user (or forced reauth), authenticate first\n if (!username && !accountAddress) {\n const authResult = await client.authWithModal();\n if (authResult.success && authResult.user) {\n username = authResult.user.username || null;\n accountAddress = authResult.user.address || null;\n const stored: Record<string, string> = {};\n if (username) stored.username = username;\n if (accountAddress) stored.address = accountAddress;\n localStorage.setItem(\"1auth-user\", JSON.stringify(stored));\n } else {\n // Auth cancelled or failed\n return;\n }\n }\n\n // Send the intent\n // If getSignedIntent is provided, use signed intent flow (XSS protected)\n // Otherwise, use the raw intent (only works for first-party apps)\n let result: SendIntentResult;\n try {\n if (getSignedIntent) {\n if (!username) {\n throw new Error(\"Username required for signed intents. Set a username first.\");\n }\n const signedIntent = await getSignedIntent({\n username,\n targetChain: intent.targetChain!,\n calls: intent.calls,\n tokenRequests: intent.tokenRequests,\n });\n result = await client.sendIntent({\n signedIntent,\n closeOn,\n });\n } else {\n result = await client.sendIntent({\n ...intent,\n username: username || undefined,\n accountAddress: accountAddress || undefined,\n closeOn,\n });\n }\n } catch (err) {\n // If user not found, clear localStorage and force re-authentication\n if (err instanceof Error && err.message.includes(\"User not found\")) {\n localStorage.removeItem(\"1auth-user\");\n return executePayment(true);\n }\n throw err;\n }\n\n if (result.success) {\n setIsSuccess(true);\n onSuccess?.(result);\n } else {\n // If user not found error in result, clear localStorage and retry\n if (result.error?.message?.includes(\"User not found\")) {\n localStorage.removeItem(\"1auth-user\");\n return executePayment(true);\n }\n onError?.(new Error(result.error?.message || \"Payment failed\"));\n }\n };\n\n const combinedStyles: React.CSSProperties = {\n ...defaultStyles,\n ...(isSuccess ? defaultSuccessStyles : {}),\n ...(isHovered && !disabled && !isProcessing && !isSuccess ? defaultHoverStyles : {}),\n ...(disabled || isProcessing ? defaultDisabledStyles : {}),\n ...style,\n };\n\n return (\n <button\n type=\"button\"\n className={className}\n style={combinedStyles}\n onClick={handleClick}\n disabled={disabled || isProcessing || isSuccess}\n onMouseEnter={() => setIsHovered(true)}\n onMouseLeave={() => setIsHovered(false)}\n >\n {isSuccess ? (\n <>\n <CheckIcon className=\"pay-button-icon\" />\n Paid\n </>\n ) : isProcessing ? (\n \"Processing...\"\n ) : (\n <>\n {!hideIcon && <FingerprintIcon className=\"pay-button-icon\" />}\n {children}\n </>\n )}\n </button>\n );\n}\n\n// Re-export types for convenience\nexport type { SendIntentOptions, SendIntentResult, CloseOnStatus } from \"./types\";\n"],"mappings":";AAAA,YAAY,WAAW;AAMrB,SAiPM,UAtOJ,KAXF;AADF,IAAM,kBAAkB,CAAC,EAAE,UAAU,MACnC;AAAA,EAAC;AAAA;AAAA,IACC;AAAA,IACA,OAAM;AAAA,IACN,QAAO;AAAA,IACP,SAAQ;AAAA,IACR,MAAK;AAAA,IACL,QAAO;AAAA,IACP,aAAY;AAAA,IACZ,eAAc;AAAA,IACd,gBAAe;AAAA,IAEf;AAAA,0BAAC,UAAK,GAAE,6CAA4C;AAAA,MACpD,oBAAC,UAAK,GAAE,kCAAiC;AAAA,MACzC,oBAAC,UAAK,GAAE,qCAAoC;AAAA,MAC5C,oBAAC,UAAK,GAAE,0BAAyB;AAAA,MACjC,oBAAC,UAAK,GAAE,aAAY;AAAA,MACpB,oBAAC,UAAK,GAAE,gCAA+B;AAAA,MACvC,oBAAC,UAAK,GAAE,4CAA2C;AAAA,MACnD,oBAAC,UAAK,GAAE,iCAAgC;AAAA,MACxC,oBAAC,UAAK,GAAE,4BAA2B;AAAA;AAAA;AACrC;AAIF,IAAM,gBAAqC;AAAA,EACzC,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,gBAAgB;AAAA,EAChB,KAAK;AAAA,EACL,SAAS;AAAA,EACT,UAAU;AAAA,EACV,YAAY;AAAA,EACZ,OAAO;AAAA,EACP,iBAAiB;AAAA,EACjB,QAAQ;AAAA,EACR,cAAc;AAAA,EACd,QAAQ;AAAA,EACR,YAAY;AAAA,EACZ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AEL,UAAI,OAAO,OAAO,SAAS,SAAS,gBAAgB,GAAG;AACrD,qBAAa,WAAW,YAAY;AACpC,eAAO,eAAe,IAAI;AAAA,MAC5B;AACA,gBAAU,IAAI,MAAM,OAAO,OAAO,WAAW,gBAAgB,CAAC;AAAA,IAChE;AAAA,EACF;AAEA,QAAM,iBAAsC;AAAA,IAC1C,GAAG;AAAA,IACH,GAAI,YAAY,uBAAuB,CAAC;AAAA,IACxC,GAAI,aAAa,CAAC,YAAY,CAAC,gBAAgB,CAAC,YAAY,qBAAqB,CAAC;AAAA,IAClF,GAAI,YAAY,eAAe,wBAAwB,CAAC;AAAA,IACxD,GAAG;AAAA,EACL;AAEA,SACE;AAAA,IAAC;AAAA;AAAA,MACC,MAAK;AAAA,MACL;AAAA,MACA,OAAO;AAAA,MACP,SAAS;AAAA,MACT,UAAU,YAAY,gBAAgB;AAAA,MACtC,cAAc,MAAM,aAAa,IAAI;AAAA,MACrC,cAAc,MAAM,aAAa,KAAK;AAAA,MAErC,sBACC,iCACE;AAAA,4BAAC,aAAU,WAAU,mBAAkB;AAAA,QAAE;AAAA,SAE3C,IACE,eACF,kBAEA,iCACG;AAAA,SAAC,YAAY,oBAAC,mBAAgB,WAAU,mBAAkB;AAAA,QAC1D;AAAA,SACH;AAAA;AAAA,EAEJ;AAEJ;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/react.tsx"],"sourcesContent":["/**\n * @file React integration for the 1auth SDK.\n *\n * Exports the {@link PayButton} component — a ready-to-use payment button that\n * handles authentication, session recovery, and intent submission without\n * requiring the consuming app to manage auth state directly.\n *\n * @module @rhinestone/1auth/react\n */\n\nimport * as React from \"react\";\nimport { OneAuthClient } from \"./client\";\nimport type { SendIntentOptions, SendIntentResult, CloseOnStatus } from \"./types\";\n\n// Fingerprint icon SVG\nconst FingerprintIcon = ({ className }: { className?: string }) => (\n <svg\n className={className}\n width=\"20\"\n height=\"20\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n >\n <path d=\"M12 10a2 2 0 0 0-2 2c0 1.02-.1 2.51-.26 4\" />\n <path d=\"M14 13.12c0 2.38 0 6.38-1 8.88\" />\n <path d=\"M17.29 21.02c.12-.6.43-2.3.5-3.02\" />\n <path d=\"M2 12a10 10 0 0 1 18-6\" />\n <path d=\"M2 16h.01\" />\n <path d=\"M21.8 16c.2-2 .131-5.354 0-6\" />\n <path d=\"M5 19.5C5.5 18 6 15 6 12a6 6 0 0 1 .34-2\" />\n <path d=\"M8.65 22c.21-.66.45-1.32.57-2\" />\n <path d=\"M9 6.8a6 6 0 0 1 9 5.2v2\" />\n </svg>\n);\n\n// Default styles\nconst defaultStyles: React.CSSProperties = {\n display: \"inline-flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n gap: \"8px\",\n padding: \"16px 32px\",\n fontSize: \"16px\",\n fontWeight: 500,\n color: \"#ffffff\",\n backgroundColor: \"#18181b\",\n border: \"none\",\n borderRadius: \"9999px\",\n cursor: \"pointer\",\n transition: \"background-color 0.2s\",\n width: \"100%\",\n};\n\nconst defaultDisabledStyles: React.CSSProperties = {\n opacity: 0.5,\n cursor: \"not-allowed\",\n};\n\nconst defaultHoverStyles: React.CSSProperties = {\n backgroundColor: \"#27272a\",\n};\n\nconst defaultSuccessStyles: React.CSSProperties = {\n backgroundColor: \"#16a34a\",\n cursor: \"default\",\n};\n\n// Checkmark icon SVG\nconst CheckIcon = ({ className }: { className?: string }) => (\n <svg\n className={className}\n width=\"20\"\n height=\"20\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2.5\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n >\n <path d=\"M20 6L9 17l-5-5\" />\n </svg>\n);\n\nexport interface PayButtonProps {\n /** The OneAuthClient instance */\n client: OneAuthClient;\n /** Intent parameters (calls, targetChain, etc.) - username will be filled automatically */\n intent: Omit<SendIntentOptions, \"username\" | \"closeOn\">;\n /** Called when payment succeeds */\n onSuccess?: (result: SendIntentResult) => void;\n /** Called when payment fails */\n onError?: (error: Error) => void;\n /** When to close the dialog and return success. Defaults to \"preconfirmed\" */\n closeOn?: CloseOnStatus;\n /** Button text - defaults to \"Pay with 1auth\" */\n children?: React.ReactNode;\n /** Custom class name */\n className?: string;\n /** Custom inline styles (merged with defaults) */\n style?: React.CSSProperties;\n /** Disabled state */\n disabled?: boolean;\n /** Hide the fingerprint icon */\n hideIcon?: boolean;\n}\n\n/**\n * A pre-built payment button that integrates 1auth passkey authentication\n * and intent submission into a single interactive element.\n *\n * The button manages its own loading and success states. On first click it\n * recovers the last authenticated user from `localStorage`; if none is found\n * it opens the auth modal before submitting the intent. On subsequent clicks\n * the stored session is reused so the user only needs to re-authenticate when\n * their session has been invalidated server-side.\n *\n * @param props - See {@link PayButtonProps} for the full set of options.\n *\n * @example\n * ```tsx\n * import { PayButton } from \"@rhinestone/1auth/react\";\n * import { client } from \"./auth\"; // your OneAuthClient instance\n *\n * <PayButton\n * client={client}\n * intent={{\n * targetChain: 8453, // Base\n * calls: [{ to: \"0xRecipient\", data: \"0x\", value: \"1000000\" }],\n * }}\n * onSuccess={(result) => console.log(\"tx:\", result.transactionHash)}\n * onError={(err) => console.error(err)}\n * >\n * Pay $5 USDC\n * </PayButton>\n * ```\n */\nexport function PayButton({\n client,\n intent,\n onSuccess,\n onError,\n closeOn = \"preconfirmed\",\n children = \"Pay with 1auth\",\n className,\n style,\n disabled,\n hideIcon,\n}: PayButtonProps) {\n const [isProcessing, setIsProcessing] = React.useState(false);\n const [isSuccess, setIsSuccess] = React.useState(false);\n const [isHovered, setIsHovered] = React.useState(false);\n\n const handleClick = async () => {\n if (disabled || isProcessing || isSuccess) return;\n\n setIsProcessing(true);\n\n try {\n await executePayment();\n } catch (err) {\n if (err instanceof Error && !err.message.includes(\"rejected\")) {\n onError?.(err);\n }\n } finally {\n setIsProcessing(false);\n }\n };\n\n /**\n * Core payment execution with built-in session recovery and re-auth retry.\n *\n * Flow:\n * 1. On first call (`forceReauth = false`), attempt to load a cached user\n * from `localStorage` under the key `\"1auth-user\"`. If the JSON is\n * malformed the cache entry is removed so the next call starts clean.\n * 2. If no cached user exists (or `forceReauth` is `true`), open the auth\n * modal. On success, persist `{ username, address }` to `localStorage`\n * so subsequent clicks skip authentication.\n * 3. Submit the intent. If the server responds with \"User not found\" — which\n * happens when a cached username/address no longer exists on the server —\n * clear `localStorage` and call `executePayment(true)` to force a fresh\n * authentication before retrying once.\n *\n * @param forceReauth - When `true`, skip the localStorage lookup and go\n * straight to the auth modal. Used internally on \"User not found\" errors\n * to recover from a stale cache without requiring a second user gesture.\n */\n const executePayment = async (forceReauth = false) => {\n // Try to get existing user from localStorage\n let username: string | null = null;\n let accountAddress: string | null = null;\n if (!forceReauth) {\n const savedUser = localStorage.getItem(\"1auth-user\");\n if (savedUser) {\n try {\n const parsed = JSON.parse(savedUser);\n username = parsed.username || null;\n accountAddress = parsed.address || null;\n } catch {\n localStorage.removeItem(\"1auth-user\");\n }\n }\n }\n\n // If no user (or forced reauth), authenticate first\n if (!username && !accountAddress) {\n const authResult = await client.authWithModal();\n if (authResult.success && authResult.user) {\n username = authResult.user.username || null;\n accountAddress = authResult.user.address || null;\n const stored: Record<string, string> = {};\n if (username) stored.username = username;\n if (accountAddress) stored.address = accountAddress;\n localStorage.setItem(\"1auth-user\", JSON.stringify(stored));\n } else {\n // Auth cancelled or failed\n return;\n }\n }\n\n // Send the intent\n let result: SendIntentResult;\n try {\n result = await client.sendIntent({\n ...intent,\n username: username || undefined,\n accountAddress: accountAddress || undefined,\n closeOn,\n });\n } catch (err) {\n // If user not found, clear localStorage and force re-authentication\n if (err instanceof Error && err.message.includes(\"User not found\")) {\n localStorage.removeItem(\"1auth-user\");\n return executePayment(true);\n }\n throw err;\n }\n\n if (result.success) {\n setIsSuccess(true);\n onSuccess?.(result);\n } else {\n // If user not found error in result, clear localStorage and retry\n if (result.error?.message?.includes(\"User not found\")) {\n localStorage.removeItem(\"1auth-user\");\n return executePayment(true);\n }\n onError?.(new Error(result.error?.message || \"Payment failed\"));\n }\n };\n\n const combinedStyles: React.CSSProperties = {\n ...defaultStyles,\n ...(isSuccess ? defaultSuccessStyles : {}),\n ...(isHovered && !disabled && !isProcessing && !isSuccess ? defaultHoverStyles : {}),\n ...(disabled || isProcessing ? defaultDisabledStyles : {}),\n ...style,\n };\n\n return (\n <button\n type=\"button\"\n className={className}\n style={combinedStyles}\n onClick={handleClick}\n disabled={disabled || isProcessing || isSuccess}\n onMouseEnter={() => setIsHovered(true)}\n onMouseLeave={() => setIsHovered(false)}\n >\n {isSuccess ? (\n <>\n <CheckIcon className=\"pay-button-icon\" />\n Paid\n </>\n ) : isProcessing ? (\n \"Processing...\"\n ) : (\n <>\n {!hideIcon && <FingerprintIcon className=\"pay-button-icon\" />}\n {children}\n </>\n )}\n </button>\n );\n}\n\n// Re-export types for convenience\nexport type { SendIntentOptions, SendIntentResult, CloseOnStatus } from \"./types\";\n"],"mappings":";AAUA,YAAY,WAAW;AAMrB,SAmQM,UAxPJ,KAXF;AADF,IAAM,kBAAkB,CAAC,EAAE,UAAU,MACnC;AAAA,EAAC;AAAA;AAAA,IACC;AAAA,IACA,OAAM;AAAA,IACN,QAAO;AAAA,IACP,SAAQ;AAAA,IACR,MAAK;AAAA,IACL,QAAO;AAAA,IACP,aAAY;AAAA,IACZ,eAAc;AAAA,IACd,gBAAe;AAAA,IAEf;AAAA,0BAAC,UAAK,GAAE,6CAA4C;AAAA,MACpD,oBAAC,UAAK,GAAE,kCAAiC;AAAA,MACzC,oBAAC,UAAK,GAAE,qCAAoC;AAAA,MAC5C,oBAAC,UAAK,GAAE,0BAAyB;AAAA,MACjC,oBAAC,UAAK,GAAE,aAAY;AAAA,MACpB,oBAAC,UAAK,GAAE,gCAA+B;AAAA,MACvC,oBAAC,UAAK,GAAE,4CAA2C;AAAA,MACnD,oBAAC,UAAK,GAAE,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AEL,UAAI,OAAO,OAAO,SAAS,SAAS,gBAAgB,GAAG;AACrD,qBAAa,WAAW,YAAY;AACpC,eAAO,eAAe,IAAI;AAAA,MAC5B;AACA,gBAAU,IAAI,MAAM,OAAO,OAAO,WAAW,gBAAgB,CAAC;AAAA,IAChE;AAAA,EACF;AAEA,QAAM,iBAAsC;AAAA,IAC1C,GAAG;AAAA,IACH,GAAI,YAAY,uBAAuB,CAAC;AAAA,IACxC,GAAI,aAAa,CAAC,YAAY,CAAC,gBAAgB,CAAC,YAAY,qBAAqB,CAAC;AAAA,IAClF,GAAI,YAAY,eAAe,wBAAwB,CAAC;AAAA,IACxD,GAAG;AAAA,EACL;AAEA,SACE;AAAA,IAAC;AAAA;AAAA,MACC,MAAK;AAAA,MACL;AAAA,MACA,OAAO;AAAA,MACP,SAAS;AAAA,MACT,UAAU,YAAY,gBAAgB;AAAA,MACtC,cAAc,MAAM,aAAa,IAAI;AAAA,MACrC,cAAc,MAAM,aAAa,KAAK;AAAA,MAErC,sBACC,iCACE;AAAA,4BAAC,aAAU,WAAU,mBAAkB;AAAA,QAAE;AAAA,SAE3C,IACE,eACF,kBAEA,iCACG;AAAA,SAAC,YAAY,oBAAC,mBAAgB,WAAU,mBAAkB;AAAA,QAC1D;AAAA,SACH;AAAA;AAAA,EAEJ;AAEJ;","names":[]}
|
package/dist/wagmi.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _wagmi_core from '@wagmi/core';
|
|
2
|
-
import { O as OneAuthProvider } from './provider-
|
|
3
|
-
import { O as OneAuthClient
|
|
2
|
+
import { O as OneAuthProvider } from './provider-CDl9wYEc.mjs';
|
|
3
|
+
import { O as OneAuthClient } from './client-BrMrhetG.mjs';
|
|
4
4
|
|
|
5
5
|
type OneAuthConnectorOptions = {
|
|
6
6
|
client: OneAuthClient;
|
|
@@ -9,8 +9,44 @@ type OneAuthConnectorOptions = {
|
|
|
9
9
|
waitForHash?: boolean;
|
|
10
10
|
hashTimeoutMs?: number;
|
|
11
11
|
hashIntervalMs?: number;
|
|
12
|
-
signIntent?: IntentSigner;
|
|
13
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* Creates a wagmi connector backed by 1auth passkey authentication.
|
|
15
|
+
*
|
|
16
|
+
* The connector lazily instantiates a single `OneAuthProvider` on the first call to
|
|
17
|
+
* `getProvider()` and reuses it for the lifetime of the wagmi config. Event listeners
|
|
18
|
+
* (`accountsChanged`, `chainChanged`, `disconnect`) are attached on connect and torn
|
|
19
|
+
* down on disconnect to prevent memory leaks.
|
|
20
|
+
*
|
|
21
|
+
* @param options - Connector configuration
|
|
22
|
+
* @param options.client - Configured `OneAuthClient` instance
|
|
23
|
+
* @param options.chainId - Override the initial chain ID. When omitted the first chain
|
|
24
|
+
* in the wagmi config's `chains` array is used.
|
|
25
|
+
* @param options.storageKey - localStorage key for persisting the connected user.
|
|
26
|
+
* Forwarded to `createOneAuthProvider`. Defaults to `"1auth-user"`.
|
|
27
|
+
* @param options.waitForHash - When true, `sendTransaction` waits for a tx hash before
|
|
28
|
+
* resolving. Forwarded to `createOneAuthProvider`. Defaults to true.
|
|
29
|
+
* @param options.hashTimeoutMs - Maximum milliseconds to wait for a transaction hash.
|
|
30
|
+
* @param options.hashIntervalMs - Polling interval when waiting for a hash.
|
|
31
|
+
* @returns A wagmi connector factory function (pass directly to wagmi `createConfig`)
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* import { createConfig } from "wagmi";
|
|
36
|
+
* import { base, optimism } from "viem/chains";
|
|
37
|
+
* import { oneAuth } from "@rhinestone/1auth/wagmi";
|
|
38
|
+
* import { OneAuthClient } from "@rhinestone/1auth";
|
|
39
|
+
*
|
|
40
|
+
* const client = new OneAuthClient({ clientId: "my-app" });
|
|
41
|
+
*
|
|
42
|
+
* export const wagmiConfig = createConfig({
|
|
43
|
+
* chains: [base, optimism],
|
|
44
|
+
* connectors: [
|
|
45
|
+
* oneAuth({ client }),
|
|
46
|
+
* ],
|
|
47
|
+
* });
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
14
50
|
declare function oneAuth(options: OneAuthConnectorOptions): _wagmi_core.CreateConnectorFn<OneAuthProvider, Record<string, unknown>, Record<string, unknown>>;
|
|
15
51
|
|
|
16
52
|
export { type OneAuthConnectorOptions, oneAuth };
|
package/dist/wagmi.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _wagmi_core from '@wagmi/core';
|
|
2
|
-
import { O as OneAuthProvider } from './provider-
|
|
3
|
-
import { O as OneAuthClient
|
|
2
|
+
import { O as OneAuthProvider } from './provider-Dgv533YQ.js';
|
|
3
|
+
import { O as OneAuthClient } from './client-BrMrhetG.js';
|
|
4
4
|
|
|
5
5
|
type OneAuthConnectorOptions = {
|
|
6
6
|
client: OneAuthClient;
|
|
@@ -9,8 +9,44 @@ type OneAuthConnectorOptions = {
|
|
|
9
9
|
waitForHash?: boolean;
|
|
10
10
|
hashTimeoutMs?: number;
|
|
11
11
|
hashIntervalMs?: number;
|
|
12
|
-
signIntent?: IntentSigner;
|
|
13
12
|
};
|
|
13
|
+
/**
|
|
14
|
+
* Creates a wagmi connector backed by 1auth passkey authentication.
|
|
15
|
+
*
|
|
16
|
+
* The connector lazily instantiates a single `OneAuthProvider` on the first call to
|
|
17
|
+
* `getProvider()` and reuses it for the lifetime of the wagmi config. Event listeners
|
|
18
|
+
* (`accountsChanged`, `chainChanged`, `disconnect`) are attached on connect and torn
|
|
19
|
+
* down on disconnect to prevent memory leaks.
|
|
20
|
+
*
|
|
21
|
+
* @param options - Connector configuration
|
|
22
|
+
* @param options.client - Configured `OneAuthClient` instance
|
|
23
|
+
* @param options.chainId - Override the initial chain ID. When omitted the first chain
|
|
24
|
+
* in the wagmi config's `chains` array is used.
|
|
25
|
+
* @param options.storageKey - localStorage key for persisting the connected user.
|
|
26
|
+
* Forwarded to `createOneAuthProvider`. Defaults to `"1auth-user"`.
|
|
27
|
+
* @param options.waitForHash - When true, `sendTransaction` waits for a tx hash before
|
|
28
|
+
* resolving. Forwarded to `createOneAuthProvider`. Defaults to true.
|
|
29
|
+
* @param options.hashTimeoutMs - Maximum milliseconds to wait for a transaction hash.
|
|
30
|
+
* @param options.hashIntervalMs - Polling interval when waiting for a hash.
|
|
31
|
+
* @returns A wagmi connector factory function (pass directly to wagmi `createConfig`)
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```typescript
|
|
35
|
+
* import { createConfig } from "wagmi";
|
|
36
|
+
* import { base, optimism } from "viem/chains";
|
|
37
|
+
* import { oneAuth } from "@rhinestone/1auth/wagmi";
|
|
38
|
+
* import { OneAuthClient } from "@rhinestone/1auth";
|
|
39
|
+
*
|
|
40
|
+
* const client = new OneAuthClient({ clientId: "my-app" });
|
|
41
|
+
*
|
|
42
|
+
* export const wagmiConfig = createConfig({
|
|
43
|
+
* chains: [base, optimism],
|
|
44
|
+
* connectors: [
|
|
45
|
+
* oneAuth({ client }),
|
|
46
|
+
* ],
|
|
47
|
+
* });
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
14
50
|
declare function oneAuth(options: OneAuthConnectorOptions): _wagmi_core.CreateConnectorFn<OneAuthProvider, Record<string, unknown>, Record<string, unknown>>;
|
|
15
51
|
|
|
16
52
|
export { type OneAuthConnectorOptions, oneAuth };
|