@rhinestone/1auth 0.1.2 → 0.5.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-N4BLW5UR.mjs} +49 -25
- package/dist/chunk-N4BLW5UR.mjs.map +1 -0
- package/dist/{client-DyYGKWj3.d.mts → client-Di8SBnPO.d.mts} +242 -85
- package/dist/{client-DyYGKWj3.d.ts → client-Di8SBnPO.d.ts} +242 -85
- package/dist/index.d.mts +5 -9
- package/dist/index.d.ts +5 -9
- package/dist/index.js +559 -178
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +513 -155
- package/dist/index.mjs.map +1 -1
- package/dist/{provider-CNTZPPFz.d.ts → provider-8anOtc87.d.mts} +2 -8
- package/dist/{provider-Ctr7HQHR.d.mts → provider-CFnLQt5m.d.ts} +2 -8
- 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/server.d.mts +2 -5
- package/dist/server.d.ts +2 -5
- package/dist/server.js +2 -2
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +2 -2
- package/dist/server.mjs.map +1 -1
- package/dist/wagmi.d.mts +2 -2
- package/dist/wagmi.d.ts +2 -2
- package/dist/wagmi.js +48 -23
- package/dist/wagmi.js.map +1 -1
- package/dist/wagmi.mjs +3 -3
- package/dist/wagmi.mjs.map +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-Di8SBnPO.mjs';
|
|
2
2
|
|
|
3
3
|
type ProviderRequest = {
|
|
4
4
|
method: string;
|
|
@@ -11,8 +11,6 @@ type OneAuthProvider = {
|
|
|
11
11
|
removeListener: (event: string, listener: Listener) => void;
|
|
12
12
|
disconnect: () => Promise<void>;
|
|
13
13
|
};
|
|
14
|
-
/** @deprecated Use OneAuthProvider instead */
|
|
15
|
-
type PasskeyProvider = OneAuthProvider;
|
|
16
14
|
type OneAuthProviderOptions = {
|
|
17
15
|
client: OneAuthClient;
|
|
18
16
|
chainId: number;
|
|
@@ -24,10 +22,6 @@ type OneAuthProviderOptions = {
|
|
|
24
22
|
hashIntervalMs?: number;
|
|
25
23
|
signIntent?: IntentSigner;
|
|
26
24
|
};
|
|
27
|
-
/** @deprecated Use OneAuthProviderOptions instead */
|
|
28
|
-
type PasskeyProviderOptions = OneAuthProviderOptions;
|
|
29
25
|
declare function createOneAuthProvider(options: OneAuthProviderOptions): OneAuthProvider;
|
|
30
|
-
/** @deprecated Use createOneAuthProvider instead */
|
|
31
|
-
declare const createPasskeyProvider: typeof createOneAuthProvider;
|
|
32
26
|
|
|
33
|
-
export { type OneAuthProvider as O, type
|
|
27
|
+
export { type OneAuthProvider as O, type OneAuthProviderOptions as a, createOneAuthProvider as c };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { O as OneAuthClient,
|
|
1
|
+
import { O as OneAuthClient, F as CloseOnStatus, I as IntentSigner } from './client-Di8SBnPO.js';
|
|
2
2
|
|
|
3
3
|
type ProviderRequest = {
|
|
4
4
|
method: string;
|
|
@@ -11,8 +11,6 @@ type OneAuthProvider = {
|
|
|
11
11
|
removeListener: (event: string, listener: Listener) => void;
|
|
12
12
|
disconnect: () => Promise<void>;
|
|
13
13
|
};
|
|
14
|
-
/** @deprecated Use OneAuthProvider instead */
|
|
15
|
-
type PasskeyProvider = OneAuthProvider;
|
|
16
14
|
type OneAuthProviderOptions = {
|
|
17
15
|
client: OneAuthClient;
|
|
18
16
|
chainId: number;
|
|
@@ -24,10 +22,6 @@ type OneAuthProviderOptions = {
|
|
|
24
22
|
hashIntervalMs?: number;
|
|
25
23
|
signIntent?: IntentSigner;
|
|
26
24
|
};
|
|
27
|
-
/** @deprecated Use OneAuthProviderOptions instead */
|
|
28
|
-
type PasskeyProviderOptions = OneAuthProviderOptions;
|
|
29
25
|
declare function createOneAuthProvider(options: OneAuthProviderOptions): OneAuthProvider;
|
|
30
|
-
/** @deprecated Use createOneAuthProvider instead */
|
|
31
|
-
declare const createPasskeyProvider: typeof createOneAuthProvider;
|
|
32
26
|
|
|
33
|
-
export { type OneAuthProvider as O, type
|
|
27
|
+
export { type OneAuthProvider as O, type OneAuthProviderOptions as a, createOneAuthProvider as c };
|
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-Di8SBnPO.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-Di8SBnPO.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.
|
|
150
|
-
username = authResult.username;
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
);
|
|
151
|
+
if (authResult.success && authResult.user) {
|
|
152
|
+
username = authResult.user.username || null;
|
|
153
|
+
accountAddress = authResult.user.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,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,OAAO;AACT;AAEA,IAAM,wBAA6C;AAAA,EACjD,SAAS;AAAA,EACT,QAAQ;AACV;AAEA,IAAM,qBAA0C;AAAA,E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C;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.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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A,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.
|
|
116
|
-
username = authResult.username;
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
);
|
|
117
|
+
if (authResult.success && authResult.user) {
|
|
118
|
+
username = authResult.user.username || null;
|
|
119
|
+
accountAddress = authResult.user.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,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,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C5B;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":[]}
|
|
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,OAAO;AACT;AAEA,IAAM,wBAA6C;AAAA,EACjD,SAAS;AAAA,EACT,QAAQ;AACV;AAEA,IAAM,qBAA0C;AAAA,EAC9C,iBAAiB;AACnB;A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,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/server.d.mts
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
interface DeveloperConfig {
|
|
2
2
|
/** Developer/app ID (clientId from the dashboard) */
|
|
3
|
-
developerId
|
|
4
|
-
/** Deprecated alias for developerId */
|
|
5
|
-
merchantId?: string;
|
|
3
|
+
developerId: string;
|
|
6
4
|
/** Ed25519 private key (base64 encoded) */
|
|
7
5
|
privateKey: string;
|
|
8
6
|
/** Intent expiry time in ms (default: 5 minutes) */
|
|
9
7
|
expiryMs?: number;
|
|
10
8
|
}
|
|
11
|
-
type MerchantConfig = DeveloperConfig;
|
|
12
9
|
interface IntentCall {
|
|
13
10
|
to: string;
|
|
14
11
|
data?: string;
|
|
@@ -44,4 +41,4 @@ interface SignedIntent {
|
|
|
44
41
|
declare function signIntent(params: SignIntentParams, config: DeveloperConfig): SignedIntent;
|
|
45
42
|
declare function createSignIntentHandler(config: DeveloperConfig): (request: Request) => Promise<Response>;
|
|
46
43
|
|
|
47
|
-
export { type DeveloperConfig, type IntentCall, type
|
|
44
|
+
export { type DeveloperConfig, type IntentCall, type SignIntentParams, type SignedIntent, createSignIntentHandler, signIntent };
|
package/dist/server.d.ts
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
interface DeveloperConfig {
|
|
2
2
|
/** Developer/app ID (clientId from the dashboard) */
|
|
3
|
-
developerId
|
|
4
|
-
/** Deprecated alias for developerId */
|
|
5
|
-
merchantId?: string;
|
|
3
|
+
developerId: string;
|
|
6
4
|
/** Ed25519 private key (base64 encoded) */
|
|
7
5
|
privateKey: string;
|
|
8
6
|
/** Intent expiry time in ms (default: 5 minutes) */
|
|
9
7
|
expiryMs?: number;
|
|
10
8
|
}
|
|
11
|
-
type MerchantConfig = DeveloperConfig;
|
|
12
9
|
interface IntentCall {
|
|
13
10
|
to: string;
|
|
14
11
|
data?: string;
|
|
@@ -44,4 +41,4 @@ interface SignedIntent {
|
|
|
44
41
|
declare function signIntent(params: SignIntentParams, config: DeveloperConfig): SignedIntent;
|
|
45
42
|
declare function createSignIntentHandler(config: DeveloperConfig): (request: Request) => Promise<Response>;
|
|
46
43
|
|
|
47
|
-
export { type DeveloperConfig, type IntentCall, type
|
|
44
|
+
export { type DeveloperConfig, type IntentCall, type SignIntentParams, type SignedIntent, createSignIntentHandler, signIntent };
|
package/dist/server.js
CHANGED
|
@@ -54,7 +54,7 @@ function signMessage(message, privateKeyBase64) {
|
|
|
54
54
|
function signIntent(params, config) {
|
|
55
55
|
const { username, accountAddress, targetChain, calls, tokenRequests } = params;
|
|
56
56
|
const { privateKey, expiryMs = 5 * 60 * 1e3 } = config;
|
|
57
|
-
const developerId = config
|
|
57
|
+
const { developerId } = config;
|
|
58
58
|
if (!developerId || !privateKey) {
|
|
59
59
|
throw new Error("Missing developerId (clientId) or privateKey in config");
|
|
60
60
|
}
|
|
@@ -86,7 +86,7 @@ function signIntent(params, config) {
|
|
|
86
86
|
}
|
|
87
87
|
function createSignIntentHandler(config) {
|
|
88
88
|
return async function handler(request) {
|
|
89
|
-
const developerId = config
|
|
89
|
+
const { developerId } = config;
|
|
90
90
|
if (!developerId || !config.privateKey) {
|
|
91
91
|
console.error("Missing DEVELOPER_ID (clientId) or DEVELOPER_PRIVATE_KEY");
|
|
92
92
|
return Response.json(
|
package/dist/server.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/server.ts"],"sourcesContent":["import { sign } from \"crypto\";\n\nexport interface DeveloperConfig {\n /** Developer/app ID (clientId from the dashboard) */\n developerId
|
|
1
|
+
{"version":3,"sources":["../src/server.ts"],"sourcesContent":["import { sign } from \"crypto\";\n\nexport interface DeveloperConfig {\n /** Developer/app ID (clientId from the dashboard) */\n developerId: string;\n /** Ed25519 private key (base64 encoded) */\n privateKey: string;\n /** Intent expiry time in ms (default: 5 minutes) */\n expiryMs?: number;\n}\n\nexport interface IntentCall {\n to: string;\n data?: string;\n value?: string;\n label?: string;\n sublabel?: string;\n}\n\nexport interface SignIntentParams {\n username?: string;\n accountAddress?: string;\n targetChain: number;\n calls: IntentCall[];\n tokenRequests?: Array<{ token: string; amount: string }>;\n}\n\nexport interface SignedIntent {\n merchantId: string;\n developerId?: string;\n targetChain: number;\n calls: IntentCall[];\n username?: string;\n accountAddress?: string;\n nonce: string;\n expiresAt: number;\n signature: string;\n tokenRequests?: Array<{ token: string; amount: string }>;\n}\n\n/**\n * Create canonical message for signing.\n */\nfunction createCanonicalMessage(data: {\n merchantId: string;\n targetChain: number;\n calls: IntentCall[];\n username?: string;\n accountAddress?: string;\n nonce: string;\n expiresAt: number;\n}): string {\n return JSON.stringify({\n merchantId: data.merchantId,\n targetChain: data.targetChain,\n calls: data.calls.map((c) => ({\n to: c.to.toLowerCase(),\n data: (c.data || \"0x\").toLowerCase(),\n value: c.value || \"0\",\n label: c.label || \"\",\n sublabel: c.sublabel || \"\",\n })),\n username: data.username,\n accountAddress: data.accountAddress?.toLowerCase(),\n nonce: data.nonce,\n expiresAt: data.expiresAt,\n });\n}\n\nfunction signMessage(message: string, privateKeyBase64: string): string {\n const privateKeyBuffer = Buffer.from(privateKeyBase64, \"base64\");\n const signature = sign(null, Buffer.from(message), {\n key: privateKeyBuffer,\n format: \"der\",\n type: \"pkcs8\",\n });\n return signature.toString(\"base64\");\n}\n\nexport function signIntent(\n params: SignIntentParams,\n config: DeveloperConfig\n): SignedIntent {\n const { username, accountAddress, targetChain, calls, tokenRequests } = params;\n const { privateKey, expiryMs = 5 * 60 * 1000 } = config;\n const { developerId } = config;\n\n if (!developerId || !privateKey) {\n throw new Error(\"Missing developerId (clientId) or privateKey in config\");\n }\n\n if (!username && !accountAddress) {\n throw new Error(\"Either username or accountAddress is required\");\n }\n\n if (!targetChain || !calls?.length) {\n throw new Error(\"targetChain and calls are required\");\n }\n\n // Generate nonce and expiry\n const nonce = crypto.randomUUID();\n const expiresAt = Date.now() + expiryMs;\n\n // Create intent data\n const intentData = {\n merchantId: developerId,\n targetChain,\n calls,\n username,\n accountAddress,\n nonce,\n expiresAt,\n };\n\n // Create canonical message and sign\n const message = createCanonicalMessage(intentData);\n const signature = signMessage(message, privateKey);\n\n return {\n ...intentData,\n signature,\n developerId,\n tokenRequests,\n };\n}\n\nexport function createSignIntentHandler(config: DeveloperConfig) {\n return async function handler(request: Request): Promise<Response> {\n const { developerId } = config;\n if (!developerId || !config.privateKey) {\n console.error(\"Missing DEVELOPER_ID (clientId) or DEVELOPER_PRIVATE_KEY\");\n return Response.json(\n { error: \"Server misconfiguration: missing developer credentials\" },\n { status: 500 }\n );\n }\n\n try {\n const body = await request.json();\n\n // Validate required fields\n const { targetChain, calls, username, accountAddress, tokenRequests } = body;\n\n if (!targetChain || typeof targetChain !== \"number\") {\n return Response.json(\n { error: \"targetChain is required and must be a number\" },\n { status: 400 }\n );\n }\n\n if (!calls || !Array.isArray(calls) || calls.length === 0) {\n return Response.json(\n { error: \"calls is required and must be a non-empty array\" },\n { status: 400 }\n );\n }\n\n if (!username && !accountAddress) {\n return Response.json(\n { error: \"Either username or accountAddress is required\" },\n { status: 400 }\n );\n }\n\n // Validate each call has a valid address\n for (const call of calls) {\n if (!call.to || !/^0x[a-fA-F0-9]{40}$/.test(call.to)) {\n return Response.json(\n { error: \"Each call must have a valid 'to' address\" },\n { status: 400 }\n );\n }\n }\n\n // Sign the intent\n const signedIntent = signIntent(\n { username, accountAddress, targetChain, calls, tokenRequests },\n { ...config, developerId }\n );\n\n return Response.json(signedIntent);\n } catch (error) {\n console.error(\"Error signing intent:\", error);\n return Response.json(\n { error: \"Failed to sign intent\" },\n { status: 500 }\n );\n }\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAqB;AA2CrB,SAAS,uBAAuB,MAQrB;AACT,SAAO,KAAK,UAAU;AAAA,IACpB,YAAY,KAAK;AAAA,IACjB,aAAa,KAAK;AAAA,IAClB,OAAO,KAAK,MAAM,IAAI,CAAC,OAAO;AAAA,MAC5B,IAAI,EAAE,GAAG,YAAY;AAAA,MACrB,OAAO,EAAE,QAAQ,MAAM,YAAY;AAAA,MACnC,OAAO,EAAE,SAAS;AAAA,MAClB,OAAO,EAAE,SAAS;AAAA,MAClB,UAAU,EAAE,YAAY;AAAA,IAC1B,EAAE;AAAA,IACF,UAAU,KAAK;AAAA,IACf,gBAAgB,KAAK,gBAAgB,YAAY;AAAA,IACjD,OAAO,KAAK;AAAA,IACZ,WAAW,KAAK;AAAA,EAClB,CAAC;AACH;AAEA,SAAS,YAAY,SAAiB,kBAAkC;AACtE,QAAM,mBAAmB,OAAO,KAAK,kBAAkB,QAAQ;AAC/D,QAAM,gBAAY,oBAAK,MAAM,OAAO,KAAK,OAAO,GAAG;AAAA,IACjD,KAAK;AAAA,IACL,QAAQ;AAAA,IACR,MAAM;AAAA,EACR,CAAC;AACD,SAA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+CAA+C;AAAA,UACxD,EAAE,QAAQ,IAAI;AAAA,QAChB;AAAA,MACF;AAEA,UAAI,CAAC,SAAS,CAAC,MAAM,QAAQ,KAAK,KAAK,MAAM,WAAW,GAAG;AACzD,eAAO,SAAS;AAAA,UACd,EAAE,OAAO,kDAAkD;AAAA,UAC3D,EAAE,QAAQ,IAAI;AAAA,QAChB;AAAA,MACF;AAEA,UAAI,CAAC,YAAY,CAAC,gBAAgB;AAChC,eAAO,SAAS;AAAA,UACd,EAAE,OAAO,gDAAgD;AAAA,UACzD,EAAE,QAAQ,IAAI;AAAA,QAChB;AAAA,MACF;AAGA,iBAAW,QAAQ,OAAO;AACxB,YAAI,CAAC,KAAK,MAAM,CAAC,sBAAsB,KAAK,KAAK,EAAE,GAAG;AACpD,iBAAO,SAAS;AAAA,YACd,EAAE,OAAO,2CAA2C;AAAA,YACpD,EAAE,QAAQ,IAAI;AAAA,UAChB;AAAA,QACF;AAAA,MACF;AAGA,YAAM,eAAe;AAAA,QACnB,EAAE,UAAU,gBAAgB,aAAa,OAAO,cAAc;AAAA,QAC9D,EAAE,GAAG,QAAQ,YAAY;AAAA,MAC3B;AAEA,aAAO,SAAS,KAAK,YAAY;AAAA,IACnC,SAAS,OAAO;AACd,cAAQ,MAAM,yBAAyB,KAAK;AAC5C,aAAO,SAAS;AAAA,QACd,EAAE,OAAO,wBAAwB;AAAA,QACjC,EAAE,QAAQ,IAAI;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
|
package/dist/server.mjs
CHANGED
|
@@ -29,7 +29,7 @@ function signMessage(message, privateKeyBase64) {
|
|
|
29
29
|
function signIntent(params, config) {
|
|
30
30
|
const { username, accountAddress, targetChain, calls, tokenRequests } = params;
|
|
31
31
|
const { privateKey, expiryMs = 5 * 60 * 1e3 } = config;
|
|
32
|
-
const developerId = config
|
|
32
|
+
const { developerId } = config;
|
|
33
33
|
if (!developerId || !privateKey) {
|
|
34
34
|
throw new Error("Missing developerId (clientId) or privateKey in config");
|
|
35
35
|
}
|
|
@@ -61,7 +61,7 @@ function signIntent(params, config) {
|
|
|
61
61
|
}
|
|
62
62
|
function createSignIntentHandler(config) {
|
|
63
63
|
return async function handler(request) {
|
|
64
|
-
const developerId = config
|
|
64
|
+
const { developerId } = config;
|
|
65
65
|
if (!developerId || !config.privateKey) {
|
|
66
66
|
console.error("Missing DEVELOPER_ID (clientId) or DEVELOPER_PRIVATE_KEY");
|
|
67
67
|
return Response.json(
|
package/dist/server.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/server.ts"],"sourcesContent":["import { sign } from \"crypto\";\n\nexport interface DeveloperConfig {\n /** Developer/app ID (clientId from the dashboard) */\n developerId
|
|
1
|
+
{"version":3,"sources":["../src/server.ts"],"sourcesContent":["import { sign } from \"crypto\";\n\nexport interface DeveloperConfig {\n /** Developer/app ID (clientId from the dashboard) */\n developerId: string;\n /** Ed25519 private key (base64 encoded) */\n privateKey: string;\n /** Intent expiry time in ms (default: 5 minutes) */\n expiryMs?: number;\n}\n\nexport interface IntentCall {\n to: string;\n data?: string;\n value?: string;\n label?: string;\n sublabel?: string;\n}\n\nexport interface SignIntentParams {\n username?: string;\n accountAddress?: string;\n targetChain: number;\n calls: IntentCall[];\n tokenRequests?: Array<{ token: string; amount: string }>;\n}\n\nexport interface SignedIntent {\n merchantId: string;\n developerId?: string;\n targetChain: number;\n calls: IntentCall[];\n username?: string;\n accountAddress?: string;\n nonce: string;\n expiresAt: number;\n signature: string;\n tokenRequests?: Array<{ token: string; amount: string }>;\n}\n\n/**\n * Create canonical message for signing.\n */\nfunction createCanonicalMessage(data: {\n merchantId: string;\n targetChain: number;\n calls: IntentCall[];\n username?: string;\n accountAddress?: string;\n nonce: string;\n expiresAt: number;\n}): string {\n return JSON.stringify({\n merchantId: data.merchantId,\n targetChain: data.targetChain,\n calls: data.calls.map((c) => ({\n to: c.to.toLowerCase(),\n data: (c.data || \"0x\").toLowerCase(),\n value: c.value || \"0\",\n label: c.label || \"\",\n sublabel: c.sublabel || \"\",\n })),\n username: data.username,\n accountAddress: data.accountAddress?.toLowerCase(),\n nonce: data.nonce,\n expiresAt: data.expiresAt,\n });\n}\n\nfunction signMessage(message: string, privateKeyBase64: string): string {\n const privateKeyBuffer = Buffer.from(privateKeyBase64, \"base64\");\n const signature = sign(null, Buffer.from(message), {\n key: privateKeyBuffer,\n format: \"der\",\n type: \"pkcs8\",\n });\n return signature.toString(\"base64\");\n}\n\nexport function signIntent(\n params: SignIntentParams,\n config: DeveloperConfig\n): SignedIntent {\n const { username, accountAddress, targetChain, calls, tokenRequests } = params;\n const { privateKey, expiryMs = 5 * 60 * 1000 } = config;\n const { developerId } = config;\n\n if (!developerId || !privateKey) {\n throw new Error(\"Missing developerId (clientId) or privateKey in config\");\n }\n\n if (!username && !accountAddress) {\n throw new Error(\"Either username or accountAddress is required\");\n }\n\n if (!targetChain || !calls?.length) {\n throw new Error(\"targetChain and calls are required\");\n }\n\n // Generate nonce and expiry\n const nonce = crypto.randomUUID();\n const expiresAt = Date.now() + expiryMs;\n\n // Create intent data\n const intentData = {\n merchantId: developerId,\n targetChain,\n calls,\n username,\n accountAddress,\n nonce,\n expiresAt,\n };\n\n // Create canonical message and sign\n const message = createCanonicalMessage(intentData);\n const signature = signMessage(message, privateKey);\n\n return {\n ...intentData,\n signature,\n developerId,\n tokenRequests,\n };\n}\n\nexport function createSignIntentHandler(config: DeveloperConfig) {\n return async function handler(request: Request): Promise<Response> {\n const { developerId } = config;\n if (!developerId || !config.privateKey) {\n console.error(\"Missing DEVELOPER_ID (clientId) or DEVELOPER_PRIVATE_KEY\");\n return Response.json(\n { error: \"Server misconfiguration: missing developer credentials\" },\n { status: 500 }\n );\n }\n\n try {\n const body = await request.json();\n\n // Validate required fields\n const { targetChain, calls, username, accountAddress, tokenRequests } = body;\n\n if (!targetChain || typeof targetChain !== \"number\") {\n return Response.json(\n { error: \"targetChain is required and must be a number\" },\n { status: 400 }\n );\n }\n\n if (!calls || !Array.isArray(calls) || calls.length === 0) {\n return Response.json(\n { error: \"calls is required and must be a non-empty array\" },\n { status: 400 }\n );\n }\n\n if (!username && !accountAddress) {\n return Response.json(\n { error: \"Either username or accountAddress is required\" },\n { status: 400 }\n );\n }\n\n // Validate each call has a valid address\n for (const call of calls) {\n if (!call.to || !/^0x[a-fA-F0-9]{40}$/.test(call.to)) {\n return Response.json(\n { error: \"Each call must have a valid 'to' address\" },\n { status: 400 }\n );\n }\n }\n\n // Sign the intent\n const signedIntent = signIntent(\n { username, accountAddress, targetChain, calls, tokenRequests },\n { ...config, developerId }\n );\n\n return Response.json(signedIntent);\n } catch (error) {\n console.error(\"Error signing intent:\", error);\n return Response.json(\n { error: \"Failed to sign intent\" },\n { status: 500 }\n );\n }\n };\n}\n"],"mappings":";AAAA,SAAS,YAAY;AA2CrB,SAAS,uBAAuB,MAQrB;AACT,SAAO,KAAK,UAAU;AAAA,IACpB,YAAY,KAAK;AAAA,IACjB,aAAa,KAAK;AAAA,IAClB,OAAO,KAAK,MAAM,IAAI,CAAC,OAAO;AAAA,MAC5B,IAAI,EAAE,GAAG,YAAY;AAAA,MACrB,OAAO,EAAE,QAAQ,MAAM,YAAY;AAAA,MACnC,OAAO,EAAE,SAAS;AAAA,MAClB,OAAO,EAAE,SAAS;AAAA,MAClB,UAAU,EAAE,YAAY;AAAA,IAC1B,EAAE;AAAA,IACF,UAAU,KAAK;AAAA,IACf,gBAAgB,KAAK,gBAAgB,YAAY;AAAA,IACjD,OAAO,KAAK;AAAA,IACZ,WAAW,KAAK;AAAA,EAClB,CAAC;AACH;AAEA,SAAS,YAAY,SAAiB,kBAAkC;AACtE,QAAM,mBAAmB,OAAO,KAAK,kBAAkB,QAAQ;AAC/D,QAAM,YAAY,KAAK,MAAM,OAAO,KAAK,OAAO,GAAG;AAAA,IACjD,KAAK;AAAA,IACL,QAAQ;AAAA,IACR,MAAM;AAAA,EACR,CAAC;AACD,SAAO,UAAU,SAAS,QAAQ;AAC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E,QAAQ,IAAI;AAAA,QAChB;AAAA,MACF;AAEA,UAAI,CAAC,SAAS,CAAC,MAAM,QAAQ,KAAK,KAAK,MAAM,WAAW,GAAG;AACzD,eAAO,SAAS;AAAA,UACd,EAAE,OAAO,kDAAkD;AAAA,UAC3D,EAAE,QAAQ,IAAI;AAAA,QAChB;AAAA,MACF;AAEA,UAAI,CAAC,YAAY,CAAC,gBAAgB;AAChC,eAAO,SAAS;AAAA,UACd,EAAE,OAAO,gDAAgD;AAAA,UACzD,EAAE,QAAQ,IAAI;AAAA,QAChB;AAAA,MACF;AAGA,iBAAW,QAAQ,OAAO;AACxB,YAAI,CAAC,KAAK,MAAM,CAAC,sBAAsB,KAAK,KAAK,EAAE,GAAG;AACpD,iBAAO,SAAS;AAAA,YACd,EAAE,OAAO,2CAA2C;AAAA,YACpD,EAAE,QAAQ,IAAI;AAAA,UAChB;AAAA,QACF;AAAA,MACF;AAGA,YAAM,eAAe;AAAA,QACnB,EAAE,UAAU,gBAAgB,aAAa,OAAO,cAAc;AAAA,QAC9D,EAAE,GAAG,QAAQ,YAAY;AAAA,MAC3B;AAEA,aAAO,SAAS,KAAK,YAAY;AAAA,IACnC,SAAS,OAAO;AACd,cAAQ,MAAM,yBAAyB,KAAK;AAC5C,aAAO,SAAS;AAAA,QACd,EAAE,OAAO,wBAAwB;AAAA,QACjC,EAAE,QAAQ,IAAI;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AACF;","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-8anOtc87.mjs';
|
|
3
|
+
import { O as OneAuthClient, I as IntentSigner } from './client-Di8SBnPO.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-CFnLQt5m.js';
|
|
3
|
+
import { O as OneAuthClient, I as IntentSigner } from './client-Di8SBnPO.js';
|
|
4
4
|
|
|
5
5
|
type OneAuthConnectorOptions = {
|
|
6
6
|
client: OneAuthClient;
|