@rhinestone/1auth 0.1.2 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{chunk-TACK3LJN.mjs → chunk-X73ALCGW.mjs} +46 -20
- package/dist/chunk-X73ALCGW.mjs.map +1 -0
- package/dist/{client-DyYGKWj3.d.mts → client-DKuPEx83.d.mts} +164 -9
- package/dist/{client-DyYGKWj3.d.ts → client-DKuPEx83.d.ts} +164 -9
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +515 -125
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +471 -107
- package/dist/index.mjs.map +1 -1
- package/dist/{provider-Ctr7HQHR.d.mts → provider-CmJarV7y.d.mts} +2 -2
- package/dist/{provider-CNTZPPFz.d.ts → provider-Dj5l4bWn.d.ts} +2 -2
- package/dist/react.d.mts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +16 -9
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +16 -9
- package/dist/react.mjs.map +1 -1
- package/dist/wagmi.d.mts +2 -2
- package/dist/wagmi.d.ts +2 -2
- package/dist/wagmi.js +45 -19
- package/dist/wagmi.js.map +1 -1
- package/dist/wagmi.mjs +1 -1
- package/package.json +7 -6
- package/dist/chunk-TACK3LJN.mjs.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { O as OneAuthClient,
|
|
1
|
+
import { O as OneAuthClient, F as CloseOnStatus, I as IntentSigner } from './client-DKuPEx83.mjs';
|
|
2
2
|
|
|
3
3
|
type ProviderRequest = {
|
|
4
4
|
method: string;
|
|
@@ -30,4 +30,4 @@ declare function createOneAuthProvider(options: OneAuthProviderOptions): OneAuth
|
|
|
30
30
|
/** @deprecated Use createOneAuthProvider instead */
|
|
31
31
|
declare const createPasskeyProvider: typeof createOneAuthProvider;
|
|
32
32
|
|
|
33
|
-
export { type OneAuthProvider as O, type PasskeyProvider as P,
|
|
33
|
+
export { type OneAuthProvider as O, type PasskeyProvider as P, createPasskeyProvider as a, type OneAuthProviderOptions as b, createOneAuthProvider as c, type PasskeyProviderOptions as d };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { O as OneAuthClient,
|
|
1
|
+
import { O as OneAuthClient, F as CloseOnStatus, I as IntentSigner } from './client-DKuPEx83.js';
|
|
2
2
|
|
|
3
3
|
type ProviderRequest = {
|
|
4
4
|
method: string;
|
|
@@ -30,4 +30,4 @@ declare function createOneAuthProvider(options: OneAuthProviderOptions): OneAuth
|
|
|
30
30
|
/** @deprecated Use createOneAuthProvider instead */
|
|
31
31
|
declare const createPasskeyProvider: typeof createOneAuthProvider;
|
|
32
32
|
|
|
33
|
-
export { type OneAuthProvider as O, type PasskeyProvider as P,
|
|
33
|
+
export { type OneAuthProvider as O, type PasskeyProvider as P, createPasskeyProvider as a, type OneAuthProviderOptions as b, createOneAuthProvider as c, type PasskeyProviderOptions as d };
|
package/dist/react.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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, w as SendIntentOptions, S as SendIntentResult, F as CloseOnStatus, D as DeveloperSignedIntent } from './client-DKuPEx83.mjs';
|
|
4
4
|
|
|
5
5
|
interface PayButtonProps {
|
|
6
6
|
/** The OneAuthClient instance */
|
package/dist/react.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
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, w as SendIntentOptions, S as SendIntentResult, F as CloseOnStatus, D as DeveloperSignedIntent } from './client-DKuPEx83.js';
|
|
4
4
|
|
|
5
5
|
interface PayButtonProps {
|
|
6
6
|
/** The OneAuthClient instance */
|
package/dist/react.js
CHANGED
|
@@ -133,25 +133,28 @@ function PayButton({
|
|
|
133
133
|
};
|
|
134
134
|
const executePayment = async (forceReauth = false) => {
|
|
135
135
|
let username = null;
|
|
136
|
+
let accountAddress = null;
|
|
136
137
|
if (!forceReauth) {
|
|
137
138
|
const savedUser = localStorage.getItem("1auth-user");
|
|
138
139
|
if (savedUser) {
|
|
139
140
|
try {
|
|
140
141
|
const parsed = JSON.parse(savedUser);
|
|
141
|
-
username = parsed.username;
|
|
142
|
+
username = parsed.username || null;
|
|
143
|
+
accountAddress = parsed.address || null;
|
|
142
144
|
} catch {
|
|
143
145
|
localStorage.removeItem("1auth-user");
|
|
144
146
|
}
|
|
145
147
|
}
|
|
146
148
|
}
|
|
147
|
-
if (!username) {
|
|
149
|
+
if (!username && !accountAddress) {
|
|
148
150
|
const authResult = await client.authWithModal();
|
|
149
|
-
if (authResult.success && authResult.username) {
|
|
150
|
-
username = authResult.username;
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
);
|
|
151
|
+
if (authResult.success && (authResult.username || authResult.address)) {
|
|
152
|
+
username = authResult.username || null;
|
|
153
|
+
accountAddress = authResult.address || null;
|
|
154
|
+
const stored = {};
|
|
155
|
+
if (username) stored.username = username;
|
|
156
|
+
if (accountAddress) stored.address = accountAddress;
|
|
157
|
+
localStorage.setItem("1auth-user", JSON.stringify(stored));
|
|
155
158
|
} else {
|
|
156
159
|
return;
|
|
157
160
|
}
|
|
@@ -159,6 +162,9 @@ function PayButton({
|
|
|
159
162
|
let result;
|
|
160
163
|
try {
|
|
161
164
|
if (getSignedIntent) {
|
|
165
|
+
if (!username) {
|
|
166
|
+
throw new Error("Username required for signed intents. Set a username first.");
|
|
167
|
+
}
|
|
162
168
|
const signedIntent = await getSignedIntent({
|
|
163
169
|
username,
|
|
164
170
|
targetChain: intent.targetChain,
|
|
@@ -172,7 +178,8 @@ function PayButton({
|
|
|
172
178
|
} else {
|
|
173
179
|
result = await client.sendIntent({
|
|
174
180
|
...intent,
|
|
175
|
-
username,
|
|
181
|
+
username: username || void 0,
|
|
182
|
+
accountAddress: accountAddress || void 0,
|
|
176
183
|
closeOn
|
|
177
184
|
});
|
|
178
185
|
}
|
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 if (!forceReauth) {\n const savedUser = localStorage.getItem(\"1auth-user\");\n if (savedUser) {\n try {\n const parsed = JSON.parse(savedUser);\n username = parsed.username;\n } catch {\n localStorage.removeItem(\"1auth-user\");\n }\n }\n }\n\n // If no user (or forced reauth), authenticate first\n if (!username) {\n const authResult = await client.authWithModal();\n if (authResult.success && authResult.username) {\n username = authResult.username;\n localStorage.setItem(\n \"1auth-user\",\n JSON.stringify({ username })\n );\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 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,\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,GAAE,aAAY;AAAA,MACpB,4CAAC,UAAK,GAAE,gCAA+B;AAAA,MACvC,4CAAC,UAAK,GAAE,4CAA2C;AAAA,MACnD,4CAAC,UAAK,GAAE,iCAAgC;AAAA,MACxC,4CAAC,UAAK,GAAE,4BAA2B;AAAA;AAAA;AACrC;AAIF,IAAM,gBAAqC;AAAA,EACzC,SAAS;AAAA,EACT,YAAY;AAAA,EACZ,gBAAgB;AAAA,EAChB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B;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,4EACE;AAAA,oDAAC,aAAU,WAAU,mBAAkB;AAAA,QAAE;AAAA,SAE3C,IACE,eACF,kBAEA,4EACG;AAAA,SAAC,YAAY,4CAAC,mBAAgB,WAAU,mBAAkB;AAAA,QAC1D;AAAA,SACH;AAAA;AAAA,EAEJ;AAEJ;","names":[]}
|
|
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.username || authResult.address)) {\n username = authResult.username || null;\n accountAddress = authResult.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":";;;;;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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,4EACE;AAAA,oDAAC,aAAU,WAAU,mBAAkB;AAAA,QAAE;AAAA,SAE3C,IACE,eACF,kBAEA,4EACG;AAAA,SAAC,YAAY,4CAAC,mBAAgB,WAAU,mBAAkB;AAAA,QAC1D;AAAA,SACH;AAAA;AAAA,EAEJ;AAEJ;","names":[]}
|
package/dist/react.mjs
CHANGED
|
@@ -99,25 +99,28 @@ function PayButton({
|
|
|
99
99
|
};
|
|
100
100
|
const executePayment = async (forceReauth = false) => {
|
|
101
101
|
let username = null;
|
|
102
|
+
let accountAddress = null;
|
|
102
103
|
if (!forceReauth) {
|
|
103
104
|
const savedUser = localStorage.getItem("1auth-user");
|
|
104
105
|
if (savedUser) {
|
|
105
106
|
try {
|
|
106
107
|
const parsed = JSON.parse(savedUser);
|
|
107
|
-
username = parsed.username;
|
|
108
|
+
username = parsed.username || null;
|
|
109
|
+
accountAddress = parsed.address || null;
|
|
108
110
|
} catch {
|
|
109
111
|
localStorage.removeItem("1auth-user");
|
|
110
112
|
}
|
|
111
113
|
}
|
|
112
114
|
}
|
|
113
|
-
if (!username) {
|
|
115
|
+
if (!username && !accountAddress) {
|
|
114
116
|
const authResult = await client.authWithModal();
|
|
115
|
-
if (authResult.success && authResult.username) {
|
|
116
|
-
username = authResult.username;
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
);
|
|
117
|
+
if (authResult.success && (authResult.username || authResult.address)) {
|
|
118
|
+
username = authResult.username || null;
|
|
119
|
+
accountAddress = authResult.address || null;
|
|
120
|
+
const stored = {};
|
|
121
|
+
if (username) stored.username = username;
|
|
122
|
+
if (accountAddress) stored.address = accountAddress;
|
|
123
|
+
localStorage.setItem("1auth-user", JSON.stringify(stored));
|
|
121
124
|
} else {
|
|
122
125
|
return;
|
|
123
126
|
}
|
|
@@ -125,6 +128,9 @@ function PayButton({
|
|
|
125
128
|
let result;
|
|
126
129
|
try {
|
|
127
130
|
if (getSignedIntent) {
|
|
131
|
+
if (!username) {
|
|
132
|
+
throw new Error("Username required for signed intents. Set a username first.");
|
|
133
|
+
}
|
|
128
134
|
const signedIntent = await getSignedIntent({
|
|
129
135
|
username,
|
|
130
136
|
targetChain: intent.targetChain,
|
|
@@ -138,7 +144,8 @@ function PayButton({
|
|
|
138
144
|
} else {
|
|
139
145
|
result = await client.sendIntent({
|
|
140
146
|
...intent,
|
|
141
|
-
username,
|
|
147
|
+
username: username || void 0,
|
|
148
|
+
accountAddress: accountAddress || void 0,
|
|
142
149
|
closeOn
|
|
143
150
|
});
|
|
144
151
|
}
|
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 if (!forceReauth) {\n const savedUser = localStorage.getItem(\"1auth-user\");\n if (savedUser) {\n try {\n const parsed = JSON.parse(savedUser);\n username = parsed.username;\n } catch {\n localStorage.removeItem(\"1auth-user\");\n }\n }\n }\n\n // If no user (or forced reauth), authenticate first\n if (!username) {\n const authResult = await client.authWithModal();\n if (authResult.success && authResult.username) {\n username = authResult.username;\n localStorage.setItem(\n \"1auth-user\",\n JSON.stringify({ username })\n );\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 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,\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,SA0OM,UA/NJ,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,a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
+
{"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.username || authResult.address)) {\n username = authResult.username || null;\n accountAddress = authResult.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,KAA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AAG;AAClE,qBAAa,WAAW,YAAY;AACpC,eAAO,eAAe,IAAI;AAAA,MAC5B;AACA,YAAM;AAAA,IACR;AAEA,QAAI,OAAO,SAAS;AAClB,mBAAa,IAAI;AACjB,kBAAY,MAAM;AAAA,IACpB,OAAO;AAEL,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, I as IntentSigner } from './client-
|
|
2
|
+
import { O as OneAuthProvider } from './provider-CmJarV7y.mjs';
|
|
3
|
+
import { O as OneAuthClient, I as IntentSigner } from './client-DKuPEx83.mjs';
|
|
4
4
|
|
|
5
5
|
type OneAuthConnectorOptions = {
|
|
6
6
|
client: OneAuthClient;
|
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, I as IntentSigner } from './client-
|
|
2
|
+
import { O as OneAuthProvider } from './provider-Dj5l4bWn.js';
|
|
3
|
+
import { O as OneAuthClient, I as IntentSigner } from './client-DKuPEx83.js';
|
|
4
4
|
|
|
5
5
|
type OneAuthConnectorOptions = {
|
|
6
6
|
client: OneAuthClient;
|
package/dist/wagmi.js
CHANGED
|
@@ -44,12 +44,15 @@ var import_viem = require("viem");
|
|
|
44
44
|
var viemChains = __toESM(require("viem/chains"));
|
|
45
45
|
var import_sdk = require("@rhinestone/sdk");
|
|
46
46
|
var env = typeof process !== "undefined" ? process.env : {};
|
|
47
|
-
var
|
|
48
|
-
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
)
|
|
47
|
+
var VIEM_CHAIN_BY_ID = /* @__PURE__ */ new Map();
|
|
48
|
+
for (const value of Object.values(viemChains)) {
|
|
49
|
+
if (typeof value !== "object" || value === null || !("id" in value) || !("name" in value)) continue;
|
|
50
|
+
const chain = value;
|
|
51
|
+
const existing = VIEM_CHAIN_BY_ID.get(chain.id);
|
|
52
|
+
if (!existing || existing.testnet && !chain.testnet) {
|
|
53
|
+
VIEM_CHAIN_BY_ID.set(chain.id, chain);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
53
56
|
var SUPPORTED_CHAIN_IDS = new Set(
|
|
54
57
|
(0, import_sdk.getAllSupportedChainsAndTokens)().map((entry) => entry.chainId)
|
|
55
58
|
);
|
|
@@ -149,7 +152,7 @@ function createOneAuthProvider(options) {
|
|
|
149
152
|
const raw = localStorage.getItem(storageKey);
|
|
150
153
|
if (!raw) return null;
|
|
151
154
|
const parsed = JSON.parse(raw);
|
|
152
|
-
if (!parsed?.
|
|
155
|
+
if (!parsed?.address) return null;
|
|
153
156
|
return parsed;
|
|
154
157
|
} catch {
|
|
155
158
|
return null;
|
|
@@ -185,18 +188,26 @@ function createOneAuthProvider(options) {
|
|
|
185
188
|
}
|
|
186
189
|
const connectResult = await client.connectWithModal();
|
|
187
190
|
let username;
|
|
188
|
-
|
|
191
|
+
let address;
|
|
192
|
+
if (connectResult.success) {
|
|
189
193
|
username = connectResult.username;
|
|
194
|
+
address = connectResult.address;
|
|
190
195
|
} else if (connectResult.action === "switch") {
|
|
191
196
|
const authResult = await client.authWithModal();
|
|
192
|
-
if (!authResult.success
|
|
197
|
+
if (!authResult.success) {
|
|
193
198
|
throw new Error(authResult.error?.message || "Authentication failed");
|
|
194
199
|
}
|
|
195
200
|
username = authResult.username;
|
|
201
|
+
address = authResult.address;
|
|
196
202
|
} else {
|
|
197
203
|
throw new Error(connectResult.error?.message || "Connection cancelled");
|
|
198
204
|
}
|
|
199
|
-
|
|
205
|
+
if (!address && username) {
|
|
206
|
+
address = await resolveAccountAddress(username);
|
|
207
|
+
}
|
|
208
|
+
if (!address) {
|
|
209
|
+
throw new Error("No account address available");
|
|
210
|
+
}
|
|
200
211
|
setStoredUser({ username, address });
|
|
201
212
|
emit("accountsChanged", [address]);
|
|
202
213
|
emit("connect", { chainId: (0, import_viem3.numberToHex)(chainId) });
|
|
@@ -211,11 +222,11 @@ function createOneAuthProvider(options) {
|
|
|
211
222
|
const stored = getStoredUser();
|
|
212
223
|
if (stored) return stored;
|
|
213
224
|
const [address] = await connect();
|
|
214
|
-
|
|
215
|
-
if (!username || !address) {
|
|
225
|
+
if (!address) {
|
|
216
226
|
throw new Error("Failed to resolve user session");
|
|
217
227
|
}
|
|
218
|
-
|
|
228
|
+
const user = getStoredUser();
|
|
229
|
+
return user || { address };
|
|
219
230
|
};
|
|
220
231
|
const parseChainId = (value) => {
|
|
221
232
|
if (typeof value === "number") return value;
|
|
@@ -273,9 +284,13 @@ function createOneAuthProvider(options) {
|
|
|
273
284
|
}
|
|
274
285
|
};
|
|
275
286
|
const signMessage = async (message) => {
|
|
276
|
-
const
|
|
287
|
+
const user = await ensureUser();
|
|
288
|
+
if (!user.username && !user.address) {
|
|
289
|
+
throw new Error("Username or address required for signing.");
|
|
290
|
+
}
|
|
277
291
|
const result = await client.signMessage({
|
|
278
|
-
username,
|
|
292
|
+
username: user.username,
|
|
293
|
+
accountAddress: user.address,
|
|
279
294
|
message
|
|
280
295
|
});
|
|
281
296
|
if (!result.success || !result.signature) {
|
|
@@ -284,10 +299,14 @@ function createOneAuthProvider(options) {
|
|
|
284
299
|
return encodeWebAuthnSignature(result.signature);
|
|
285
300
|
};
|
|
286
301
|
const signTypedData = async (typedData) => {
|
|
287
|
-
const
|
|
302
|
+
const user = await ensureUser();
|
|
303
|
+
if (!user.username && !user.address) {
|
|
304
|
+
throw new Error("Username or address required for signing.");
|
|
305
|
+
}
|
|
288
306
|
const data = typeof typedData === "string" ? JSON.parse(typedData) : typedData;
|
|
289
307
|
const result = await client.signTypedData({
|
|
290
|
-
username,
|
|
308
|
+
username: user.username,
|
|
309
|
+
accountAddress: user.address,
|
|
291
310
|
domain: data.domain,
|
|
292
311
|
types: data.types,
|
|
293
312
|
primaryType: data.primaryType,
|
|
@@ -302,11 +321,15 @@ function createOneAuthProvider(options) {
|
|
|
302
321
|
if (!options.signIntent) {
|
|
303
322
|
return {
|
|
304
323
|
username: payload.username,
|
|
324
|
+
accountAddress: payload.accountAddress,
|
|
305
325
|
targetChain: payload.targetChain,
|
|
306
326
|
calls: payload.calls,
|
|
307
327
|
tokenRequests: payload.tokenRequests
|
|
308
328
|
};
|
|
309
329
|
}
|
|
330
|
+
if (!payload.username) {
|
|
331
|
+
throw new Error("Username required for signed intents. Set a username first.");
|
|
332
|
+
}
|
|
310
333
|
const signedIntent = await options.signIntent({
|
|
311
334
|
username: payload.username,
|
|
312
335
|
accountAddress: payload.accountAddress,
|
|
@@ -432,10 +455,13 @@ function createOneAuthProvider(options) {
|
|
|
432
455
|
return capabilities;
|
|
433
456
|
}
|
|
434
457
|
case "wallet_getAssets": {
|
|
435
|
-
const
|
|
458
|
+
const user = await ensureUser();
|
|
459
|
+
if (!user.username) {
|
|
460
|
+
throw new Error("Username required to fetch assets. Set a username first.");
|
|
461
|
+
}
|
|
436
462
|
const clientId = client.getClientId();
|
|
437
463
|
const response = await fetch(
|
|
438
|
-
`${client.getProviderUrl()}/api/users/${encodeURIComponent(username)}/portfolio`,
|
|
464
|
+
`${client.getProviderUrl()}/api/users/${encodeURIComponent(user.username)}/portfolio`,
|
|
439
465
|
{
|
|
440
466
|
headers: clientId ? { "x-client-id": clientId } : {}
|
|
441
467
|
}
|