@rhinestone/1auth 0.4.0 → 0.6.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.
@@ -1,4 +1,4 @@
1
- import { O as OneAuthClient, F as CloseOnStatus, I as IntentSigner } from './client-DKuPEx83.js';
1
+ import { O as OneAuthClient, F as CloseOnStatus, I as IntentSigner } from './client-CHCVV9H3.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 PasskeyProvider as P, createPasskeyProvider as a, type OneAuthProviderOptions as b, createOneAuthProvider as c, type PasskeyProviderOptions as d };
27
+ export { type OneAuthProvider as O, type OneAuthProviderOptions as a, createOneAuthProvider as c };
@@ -1,4 +1,4 @@
1
- import { O as OneAuthClient, F as CloseOnStatus, I as IntentSigner } from './client-DKuPEx83.mjs';
1
+ import { O as OneAuthClient, F as CloseOnStatus, I as IntentSigner } from './client-CHCVV9H3.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 PasskeyProvider as P, createPasskeyProvider as a, type OneAuthProviderOptions as b, createOneAuthProvider as c, type PasskeyProviderOptions as d };
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, w as SendIntentOptions, S as SendIntentResult, F as CloseOnStatus, D as DeveloperSignedIntent } from './client-DKuPEx83.mjs';
3
+ import { O as OneAuthClient, w as SendIntentOptions, S as SendIntentResult, F as CloseOnStatus, D as DeveloperSignedIntent } from './client-CHCVV9H3.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, w as SendIntentOptions, S as SendIntentResult, F as CloseOnStatus, D as DeveloperSignedIntent } from './client-DKuPEx83.js';
3
+ import { O as OneAuthClient, w as SendIntentOptions, S as SendIntentResult, F as CloseOnStatus, D as DeveloperSignedIntent } from './client-CHCVV9H3.js';
4
4
 
5
5
  interface PayButtonProps {
6
6
  /** The OneAuthClient instance */
package/dist/react.js CHANGED
@@ -148,9 +148,9 @@ function PayButton({
148
148
  }
149
149
  if (!username && !accountAddress) {
150
150
  const authResult = await client.authWithModal();
151
- if (authResult.success && (authResult.username || authResult.address)) {
152
- username = authResult.username || null;
153
- accountAddress = authResult.address || null;
151
+ if (authResult.success && authResult.user) {
152
+ username = authResult.user.username || null;
153
+ accountAddress = authResult.user.address || null;
154
154
  const stored = {};
155
155
  if (username) stored.username = username;
156
156
  if (accountAddress) stored.address = accountAddress;
package/dist/react.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/react.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { OneAuthClient } from \"./client\";\nimport type { SendIntentOptions, SendIntentResult, CloseOnStatus, DeveloperSignedIntent } from \"./types\";\n\n// Fingerprint icon SVG\nconst FingerprintIcon = ({ className }: { className?: string }) => (\n <svg\n className={className}\n width=\"20\"\n height=\"20\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n >\n <path d=\"M12 10a2 2 0 0 0-2 2c0 1.02-.1 2.51-.26 4\" />\n <path d=\"M14 13.12c0 2.38 0 6.38-1 8.88\" />\n <path d=\"M17.29 21.02c.12-.6.43-2.3.5-3.02\" />\n <path d=\"M2 12a10 10 0 0 1 18-6\" />\n <path d=\"M2 16h.01\" />\n <path d=\"M21.8 16c.2-2 .131-5.354 0-6\" />\n <path d=\"M5 19.5C5.5 18 6 15 6 12a6 6 0 0 1 .34-2\" />\n <path d=\"M8.65 22c.21-.66.45-1.32.57-2\" />\n <path d=\"M9 6.8a6 6 0 0 1 9 5.2v2\" />\n </svg>\n);\n\n// Default styles\nconst defaultStyles: React.CSSProperties = {\n display: \"inline-flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n gap: \"8px\",\n padding: \"16px 32px\",\n fontSize: \"16px\",\n fontWeight: 500,\n color: \"#ffffff\",\n backgroundColor: \"#18181b\",\n border: \"none\",\n borderRadius: \"9999px\",\n cursor: \"pointer\",\n transition: \"background-color 0.2s\",\n width: \"100%\",\n};\n\nconst defaultDisabledStyles: React.CSSProperties = {\n opacity: 0.5,\n cursor: \"not-allowed\",\n};\n\nconst defaultHoverStyles: React.CSSProperties = {\n backgroundColor: \"#27272a\",\n};\n\nconst defaultSuccessStyles: React.CSSProperties = {\n backgroundColor: \"#16a34a\",\n cursor: \"default\",\n};\n\n// Checkmark icon SVG\nconst CheckIcon = ({ className }: { className?: string }) => (\n <svg\n className={className}\n width=\"20\"\n height=\"20\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2.5\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n >\n <path d=\"M20 6L9 17l-5-5\" />\n </svg>\n);\n\nexport interface PayButtonProps {\n /** The OneAuthClient instance */\n client: OneAuthClient;\n /** Intent parameters (calls, targetChain, etc.) - username will be filled automatically */\n intent: Omit<SendIntentOptions, \"username\" | \"closeOn\" | \"signedIntent\">;\n /** Called when payment succeeds */\n onSuccess?: (result: SendIntentResult) => void;\n /** Called when payment fails */\n onError?: (error: Error) => void;\n /** When to close the dialog and return success. Defaults to \"preconfirmed\" */\n closeOn?: CloseOnStatus;\n /**\n * Optional callback to get a signed intent from your backend.\n * Provides XSS protection by ensuring calls are constructed server-side.\n * If provided, this will be called with the intent and username before sending.\n * The returned signed intent will be used instead of the raw intent.\n */\n getSignedIntent?: (params: {\n username: string;\n targetChain: number;\n calls: SendIntentOptions[\"calls\"];\n tokenRequests?: SendIntentOptions[\"tokenRequests\"];\n }) => Promise<DeveloperSignedIntent>;\n /** Button text - defaults to \"Pay with 1auth\" */\n children?: React.ReactNode;\n /** Custom class name */\n className?: string;\n /** Custom inline styles (merged with defaults) */\n style?: React.CSSProperties;\n /** Disabled state */\n disabled?: boolean;\n /** Hide the fingerprint icon */\n hideIcon?: boolean;\n}\n\nexport function PayButton({\n client,\n intent,\n onSuccess,\n onError,\n closeOn = \"preconfirmed\",\n getSignedIntent,\n children = \"Pay with 1auth\",\n className,\n style,\n disabled,\n hideIcon,\n}: PayButtonProps) {\n const [isProcessing, setIsProcessing] = React.useState(false);\n const [isSuccess, setIsSuccess] = React.useState(false);\n const [isHovered, setIsHovered] = React.useState(false);\n\n const handleClick = async () => {\n if (disabled || isProcessing || isSuccess) return;\n\n setIsProcessing(true);\n\n try {\n await executePayment();\n } catch (err) {\n if (err instanceof Error && !err.message.includes(\"rejected\")) {\n onError?.(err);\n }\n } finally {\n setIsProcessing(false);\n }\n };\n\n const executePayment = async (forceReauth = false) => {\n // Try to get existing user from localStorage\n let username: string | null = null;\n let accountAddress: string | null = null;\n if (!forceReauth) {\n const savedUser = localStorage.getItem(\"1auth-user\");\n if (savedUser) {\n try {\n const parsed = JSON.parse(savedUser);\n username = parsed.username || null;\n accountAddress = parsed.address || null;\n } catch {\n localStorage.removeItem(\"1auth-user\");\n }\n }\n }\n\n // If no user (or forced reauth), authenticate first\n if (!username && !accountAddress) {\n const authResult = await client.authWithModal();\n if (authResult.success && (authResult.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;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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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,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,iC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AAU,YAAY;AAAA,UACtB,gBAAgB,kBAAkB;AAAA,UAClC;AAAA,QACF,CAAC;AAAA,MACH;AAAA,IACF,SAAS,KAAK;AAEZ,UAAI,eAAe,SAAS,IAAI,QAAQ,SAAS,gBAAgB,GAAG;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,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
@@ -114,9 +114,9 @@ function PayButton({
114
114
  }
115
115
  if (!username && !accountAddress) {
116
116
  const authResult = await client.authWithModal();
117
- if (authResult.success && (authResult.username || authResult.address)) {
118
- username = authResult.username || null;
119
- accountAddress = authResult.address || null;
117
+ if (authResult.success && authResult.user) {
118
+ username = authResult.user.username || null;
119
+ accountAddress = authResult.user.address || null;
120
120
  const stored = {};
121
121
  if (username) stored.username = username;
122
122
  if (accountAddress) stored.address = accountAddress;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/react.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { OneAuthClient } from \"./client\";\nimport type { SendIntentOptions, SendIntentResult, CloseOnStatus, DeveloperSignedIntent } from \"./types\";\n\n// Fingerprint icon SVG\nconst FingerprintIcon = ({ className }: { className?: string }) => (\n <svg\n className={className}\n width=\"20\"\n height=\"20\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n >\n <path d=\"M12 10a2 2 0 0 0-2 2c0 1.02-.1 2.51-.26 4\" />\n <path d=\"M14 13.12c0 2.38 0 6.38-1 8.88\" />\n <path d=\"M17.29 21.02c.12-.6.43-2.3.5-3.02\" />\n <path d=\"M2 12a10 10 0 0 1 18-6\" />\n <path d=\"M2 16h.01\" />\n <path d=\"M21.8 16c.2-2 .131-5.354 0-6\" />\n <path d=\"M5 19.5C5.5 18 6 15 6 12a6 6 0 0 1 .34-2\" />\n <path d=\"M8.65 22c.21-.66.45-1.32.57-2\" />\n <path d=\"M9 6.8a6 6 0 0 1 9 5.2v2\" />\n </svg>\n);\n\n// Default styles\nconst defaultStyles: React.CSSProperties = {\n display: \"inline-flex\",\n alignItems: \"center\",\n justifyContent: \"center\",\n gap: \"8px\",\n padding: \"16px 32px\",\n fontSize: \"16px\",\n fontWeight: 500,\n color: \"#ffffff\",\n backgroundColor: \"#18181b\",\n border: \"none\",\n borderRadius: \"9999px\",\n cursor: \"pointer\",\n transition: \"background-color 0.2s\",\n width: \"100%\",\n};\n\nconst defaultDisabledStyles: React.CSSProperties = {\n opacity: 0.5,\n cursor: \"not-allowed\",\n};\n\nconst defaultHoverStyles: React.CSSProperties = {\n backgroundColor: \"#27272a\",\n};\n\nconst defaultSuccessStyles: React.CSSProperties = {\n backgroundColor: \"#16a34a\",\n cursor: \"default\",\n};\n\n// Checkmark icon SVG\nconst CheckIcon = ({ className }: { className?: string }) => (\n <svg\n className={className}\n width=\"20\"\n height=\"20\"\n viewBox=\"0 0 24 24\"\n fill=\"none\"\n stroke=\"currentColor\"\n strokeWidth=\"2.5\"\n strokeLinecap=\"round\"\n strokeLinejoin=\"round\"\n >\n <path d=\"M20 6L9 17l-5-5\" />\n </svg>\n);\n\nexport interface PayButtonProps {\n /** The OneAuthClient instance */\n client: OneAuthClient;\n /** Intent parameters (calls, targetChain, etc.) - username will be filled automatically */\n intent: Omit<SendIntentOptions, \"username\" | \"closeOn\" | \"signedIntent\">;\n /** Called when payment succeeds */\n onSuccess?: (result: SendIntentResult) => void;\n /** Called when payment fails */\n onError?: (error: Error) => void;\n /** When to close the dialog and return success. Defaults to \"preconfirmed\" */\n closeOn?: CloseOnStatus;\n /**\n * Optional callback to get a signed intent from your backend.\n * Provides XSS protection by ensuring calls are constructed server-side.\n * If provided, this will be called with the intent and username before sending.\n * The returned signed intent will be used instead of the raw intent.\n */\n getSignedIntent?: (params: {\n username: string;\n targetChain: number;\n calls: SendIntentOptions[\"calls\"];\n tokenRequests?: SendIntentOptions[\"tokenRequests\"];\n }) => Promise<DeveloperSignedIntent>;\n /** Button text - defaults to \"Pay with 1auth\" */\n children?: React.ReactNode;\n /** Custom class name */\n className?: string;\n /** Custom inline styles (merged with defaults) */\n style?: React.CSSProperties;\n /** Disabled state */\n disabled?: boolean;\n /** Hide the fingerprint icon */\n hideIcon?: boolean;\n}\n\nexport function PayButton({\n client,\n intent,\n onSuccess,\n onError,\n closeOn = \"preconfirmed\",\n getSignedIntent,\n children = \"Pay with 1auth\",\n className,\n style,\n disabled,\n hideIcon,\n}: PayButtonProps) {\n const [isProcessing, setIsProcessing] = React.useState(false);\n const [isSuccess, setIsSuccess] = React.useState(false);\n const [isHovered, setIsHovered] = React.useState(false);\n\n const handleClick = async () => {\n if (disabled || isProcessing || isSuccess) return;\n\n setIsProcessing(true);\n\n try {\n await executePayment();\n } catch (err) {\n if (err instanceof Error && !err.message.includes(\"rejected\")) {\n onError?.(err);\n }\n } finally {\n setIsProcessing(false);\n }\n };\n\n const executePayment = async (forceReauth = false) => {\n // Try to get existing user from localStorage\n let username: string | null = null;\n let accountAddress: string | null = null;\n if (!forceReauth) {\n const savedUser = localStorage.getItem(\"1auth-user\");\n if (savedUser) {\n try {\n const parsed = JSON.parse(savedUser);\n username = parsed.username || null;\n accountAddress = parsed.address || null;\n } catch {\n localStorage.removeItem(\"1auth-user\");\n }\n }\n }\n\n // If no user (or forced reauth), authenticate first\n if (!username && !accountAddress) {\n const authResult = await client.authWithModal();\n if (authResult.success && (authResult.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,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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,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gB,GAAG;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/server.d.mts CHANGED
@@ -1,14 +1,11 @@
1
1
  interface DeveloperConfig {
2
2
  /** Developer/app ID (clientId from the dashboard) */
3
- developerId?: string;
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 MerchantConfig, type SignIntentParams, type SignedIntent, createSignIntentHandler, signIntent };
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?: string;
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 MerchantConfig, type SignIntentParams, type SignedIntent, createSignIntentHandler, signIntent };
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.developerId || config.merchantId;
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.developerId || config.merchantId;
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(
@@ -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?: string;\n /** Deprecated alias for developerId */\n merchantId?: 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 type MerchantConfig = DeveloperConfig;\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.developerId || config.merchantId;\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.developerId || config.merchantId;\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;AA+CrB,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,SAAO,UAAU,SAAS,QAAQ;AACpC;AAEO,SAAS,WACd,QACA,QACc;A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AA,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":[]}
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;AA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AAQ,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.developerId || config.merchantId;
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.developerId || config.merchantId;
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(
@@ -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?: string;\n /** Deprecated alias for developerId */\n merchantId?: 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 type MerchantConfig = DeveloperConfig;\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.developerId || config.merchantId;\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.developerId || config.merchantId;\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;AA+CrB,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,OAA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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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d,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-CmJarV7y.mjs';
3
- import { O as OneAuthClient, I as IntentSigner } from './client-DKuPEx83.mjs';
2
+ import { O as OneAuthProvider } from './provider-B5pLvKo_.mjs';
3
+ import { O as OneAuthClient, I as IntentSigner } from './client-CHCVV9H3.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-Dj5l4bWn.js';
3
- import { O as OneAuthClient, I as IntentSigner } from './client-DKuPEx83.js';
2
+ import { O as OneAuthProvider } from './provider-DzxXGyV8.js';
3
+ import { O as OneAuthClient, I as IntentSigner } from './client-CHCVV9H3.js';
4
4
 
5
5
  type OneAuthConnectorOptions = {
6
6
  client: OneAuthClient;
package/dist/wagmi.js CHANGED
@@ -190,15 +190,15 @@ function createOneAuthProvider(options) {
190
190
  let username;
191
191
  let address;
192
192
  if (connectResult.success) {
193
- username = connectResult.username;
194
- address = connectResult.address;
193
+ username = connectResult.user?.username;
194
+ address = connectResult.user?.address;
195
195
  } else if (connectResult.action === "switch") {
196
196
  const authResult = await client.authWithModal();
197
197
  if (!authResult.success) {
198
198
  throw new Error(authResult.error?.message || "Authentication failed");
199
199
  }
200
- username = authResult.username;
201
- address = authResult.address;
200
+ username = authResult.user?.username;
201
+ address = authResult.user?.address;
202
202
  } else {
203
203
  throw new Error(connectResult.error?.message || "Connection cancelled");
204
204
  }
@@ -571,7 +571,6 @@ function createOneAuthProvider(options) {
571
571
  disconnect
572
572
  };
573
573
  }
574
- var createPasskeyProvider = createOneAuthProvider;
575
574
 
576
575
  // src/wagmi.ts
577
576
  function oneAuth(options) {
@@ -668,7 +667,7 @@ function oneAuth(options) {
668
667
  if (!initialChainId) {
669
668
  throw new Error("No chain configured for 1auth connector");
670
669
  }
671
- provider = createPasskeyProvider({
670
+ provider = createOneAuthProvider({
672
671
  client: options.client,
673
672
  chainId: initialChainId,
674
673
  storageKey: options.storageKey,