@rhinestone/1auth 0.1.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-UXYKIMGZ.mjs +482 -0
- package/dist/chunk-UXYKIMGZ.mjs.map +1 -0
- package/dist/client-C1inywuT.d.mts +777 -0
- package/dist/client-C1inywuT.d.ts +777 -0
- package/dist/index.d.mts +267 -0
- package/dist/index.d.ts +267 -0
- package/dist/index.js +2701 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +2213 -0
- package/dist/index.mjs.map +1 -0
- package/dist/provider-Dgh51NRc.d.mts +24 -0
- package/dist/provider-q7M728Mn.d.ts +24 -0
- package/dist/react.d.mts +41 -0
- package/dist/react.d.ts +41 -0
- package/dist/react.js +228 -0
- package/dist/react.js.map +1 -0
- package/dist/react.mjs +193 -0
- package/dist/react.mjs.map +1 -0
- package/dist/server.d.mts +81 -0
- package/dist/server.d.ts +81 -0
- package/dist/server.js +142 -0
- package/dist/server.js.map +1 -0
- package/dist/server.mjs +116 -0
- package/dist/server.mjs.map +1 -0
- package/dist/wagmi.d.mts +15 -0
- package/dist/wagmi.d.ts +15 -0
- package/dist/wagmi.js +569 -0
- package/dist/wagmi.js.map +1 -0
- package/dist/wagmi.mjs +176 -0
- package/dist/wagmi.mjs.map +1 -0
- package/package.json +61 -0
package/dist/react.js
ADDED
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/react.tsx
|
|
31
|
+
var react_exports = {};
|
|
32
|
+
__export(react_exports, {
|
|
33
|
+
PayButton: () => PayButton
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(react_exports);
|
|
36
|
+
var React = __toESM(require("react"));
|
|
37
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
38
|
+
var FingerprintIcon = ({ className }) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
|
|
39
|
+
"svg",
|
|
40
|
+
{
|
|
41
|
+
className,
|
|
42
|
+
width: "20",
|
|
43
|
+
height: "20",
|
|
44
|
+
viewBox: "0 0 24 24",
|
|
45
|
+
fill: "none",
|
|
46
|
+
stroke: "currentColor",
|
|
47
|
+
strokeWidth: "2",
|
|
48
|
+
strokeLinecap: "round",
|
|
49
|
+
strokeLinejoin: "round",
|
|
50
|
+
children: [
|
|
51
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M12 10a2 2 0 0 0-2 2c0 1.02-.1 2.51-.26 4" }),
|
|
52
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M14 13.12c0 2.38 0 6.38-1 8.88" }),
|
|
53
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M17.29 21.02c.12-.6.43-2.3.5-3.02" }),
|
|
54
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M2 12a10 10 0 0 1 18-6" }),
|
|
55
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M2 16h.01" }),
|
|
56
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M21.8 16c.2-2 .131-5.354 0-6" }),
|
|
57
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M5 19.5C5.5 18 6 15 6 12a6 6 0 0 1 .34-2" }),
|
|
58
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M8.65 22c.21-.66.45-1.32.57-2" }),
|
|
59
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M9 6.8a6 6 0 0 1 9 5.2v2" })
|
|
60
|
+
]
|
|
61
|
+
}
|
|
62
|
+
);
|
|
63
|
+
var defaultStyles = {
|
|
64
|
+
display: "inline-flex",
|
|
65
|
+
alignItems: "center",
|
|
66
|
+
justifyContent: "center",
|
|
67
|
+
gap: "8px",
|
|
68
|
+
padding: "16px 32px",
|
|
69
|
+
fontSize: "16px",
|
|
70
|
+
fontWeight: 500,
|
|
71
|
+
color: "#ffffff",
|
|
72
|
+
backgroundColor: "#18181b",
|
|
73
|
+
border: "none",
|
|
74
|
+
borderRadius: "9999px",
|
|
75
|
+
cursor: "pointer",
|
|
76
|
+
transition: "background-color 0.2s",
|
|
77
|
+
width: "100%"
|
|
78
|
+
};
|
|
79
|
+
var defaultDisabledStyles = {
|
|
80
|
+
opacity: 0.5,
|
|
81
|
+
cursor: "not-allowed"
|
|
82
|
+
};
|
|
83
|
+
var defaultHoverStyles = {
|
|
84
|
+
backgroundColor: "#27272a"
|
|
85
|
+
};
|
|
86
|
+
var defaultSuccessStyles = {
|
|
87
|
+
backgroundColor: "#16a34a",
|
|
88
|
+
cursor: "default"
|
|
89
|
+
};
|
|
90
|
+
var CheckIcon = ({ className }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
91
|
+
"svg",
|
|
92
|
+
{
|
|
93
|
+
className,
|
|
94
|
+
width: "20",
|
|
95
|
+
height: "20",
|
|
96
|
+
viewBox: "0 0 24 24",
|
|
97
|
+
fill: "none",
|
|
98
|
+
stroke: "currentColor",
|
|
99
|
+
strokeWidth: "2.5",
|
|
100
|
+
strokeLinecap: "round",
|
|
101
|
+
strokeLinejoin: "round",
|
|
102
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M20 6L9 17l-5-5" })
|
|
103
|
+
}
|
|
104
|
+
);
|
|
105
|
+
function PayButton({
|
|
106
|
+
client,
|
|
107
|
+
intent,
|
|
108
|
+
onSuccess,
|
|
109
|
+
onError,
|
|
110
|
+
closeOn = "preconfirmed",
|
|
111
|
+
getSignedIntent,
|
|
112
|
+
children = "Pay with 1auth",
|
|
113
|
+
className,
|
|
114
|
+
style,
|
|
115
|
+
disabled,
|
|
116
|
+
hideIcon
|
|
117
|
+
}) {
|
|
118
|
+
const [isProcessing, setIsProcessing] = React.useState(false);
|
|
119
|
+
const [isSuccess, setIsSuccess] = React.useState(false);
|
|
120
|
+
const [isHovered, setIsHovered] = React.useState(false);
|
|
121
|
+
const handleClick = async () => {
|
|
122
|
+
if (disabled || isProcessing || isSuccess) return;
|
|
123
|
+
setIsProcessing(true);
|
|
124
|
+
try {
|
|
125
|
+
await executePayment();
|
|
126
|
+
} catch (err) {
|
|
127
|
+
if (err instanceof Error && !err.message.includes("rejected")) {
|
|
128
|
+
onError?.(err);
|
|
129
|
+
}
|
|
130
|
+
} finally {
|
|
131
|
+
setIsProcessing(false);
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
const executePayment = async (forceReauth = false) => {
|
|
135
|
+
let username = null;
|
|
136
|
+
if (!forceReauth) {
|
|
137
|
+
const savedUser = localStorage.getItem("1auth-user");
|
|
138
|
+
if (savedUser) {
|
|
139
|
+
try {
|
|
140
|
+
const parsed = JSON.parse(savedUser);
|
|
141
|
+
username = parsed.username;
|
|
142
|
+
} catch {
|
|
143
|
+
localStorage.removeItem("1auth-user");
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
if (!username) {
|
|
148
|
+
const authResult = await client.authWithModal();
|
|
149
|
+
if (authResult.success && authResult.username) {
|
|
150
|
+
username = authResult.username;
|
|
151
|
+
localStorage.setItem(
|
|
152
|
+
"1auth-user",
|
|
153
|
+
JSON.stringify({ username })
|
|
154
|
+
);
|
|
155
|
+
} else {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
let result;
|
|
160
|
+
try {
|
|
161
|
+
if (getSignedIntent) {
|
|
162
|
+
const signedIntent = await getSignedIntent({
|
|
163
|
+
username,
|
|
164
|
+
targetChain: intent.targetChain,
|
|
165
|
+
calls: intent.calls,
|
|
166
|
+
tokenRequests: intent.tokenRequests
|
|
167
|
+
});
|
|
168
|
+
result = await client.sendIntent({
|
|
169
|
+
signedIntent,
|
|
170
|
+
closeOn
|
|
171
|
+
});
|
|
172
|
+
} else {
|
|
173
|
+
result = await client.sendIntent({
|
|
174
|
+
...intent,
|
|
175
|
+
username,
|
|
176
|
+
closeOn
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
} catch (err) {
|
|
180
|
+
if (err instanceof Error && err.message.includes("User not found")) {
|
|
181
|
+
localStorage.removeItem("1auth-user");
|
|
182
|
+
return executePayment(true);
|
|
183
|
+
}
|
|
184
|
+
throw err;
|
|
185
|
+
}
|
|
186
|
+
if (result.success) {
|
|
187
|
+
setIsSuccess(true);
|
|
188
|
+
onSuccess?.(result);
|
|
189
|
+
} else {
|
|
190
|
+
if (result.error?.message?.includes("User not found")) {
|
|
191
|
+
localStorage.removeItem("1auth-user");
|
|
192
|
+
return executePayment(true);
|
|
193
|
+
}
|
|
194
|
+
onError?.(new Error(result.error?.message || "Payment failed"));
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
const combinedStyles = {
|
|
198
|
+
...defaultStyles,
|
|
199
|
+
...isSuccess ? defaultSuccessStyles : {},
|
|
200
|
+
...isHovered && !disabled && !isProcessing && !isSuccess ? defaultHoverStyles : {},
|
|
201
|
+
...disabled || isProcessing ? defaultDisabledStyles : {},
|
|
202
|
+
...style
|
|
203
|
+
};
|
|
204
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
205
|
+
"button",
|
|
206
|
+
{
|
|
207
|
+
type: "button",
|
|
208
|
+
className,
|
|
209
|
+
style: combinedStyles,
|
|
210
|
+
onClick: handleClick,
|
|
211
|
+
disabled: disabled || isProcessing || isSuccess,
|
|
212
|
+
onMouseEnter: () => setIsHovered(true),
|
|
213
|
+
onMouseLeave: () => setIsHovered(false),
|
|
214
|
+
children: isSuccess ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
215
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(CheckIcon, { className: "pay-button-icon" }),
|
|
216
|
+
"Paid"
|
|
217
|
+
] }) : isProcessing ? "Processing..." : /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
218
|
+
!hideIcon && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(FingerprintIcon, { className: "pay-button-icon" }),
|
|
219
|
+
children
|
|
220
|
+
] })
|
|
221
|
+
}
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
225
|
+
0 && (module.exports = {
|
|
226
|
+
PayButton
|
|
227
|
+
});
|
|
228
|
+
//# sourceMappingURL=react.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/react.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { PasskeyProviderClient } from \"./client\";\nimport type { SendIntentOptions, SendIntentResult, CloseOnStatus, MerchantSignedIntent } 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 PasskeyProviderClient instance */\n client: PasskeyProviderClient;\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<MerchantSignedIntent>;\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,EAC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gB,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
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
// src/react.tsx
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
var FingerprintIcon = ({ className }) => /* @__PURE__ */ jsxs(
|
|
5
|
+
"svg",
|
|
6
|
+
{
|
|
7
|
+
className,
|
|
8
|
+
width: "20",
|
|
9
|
+
height: "20",
|
|
10
|
+
viewBox: "0 0 24 24",
|
|
11
|
+
fill: "none",
|
|
12
|
+
stroke: "currentColor",
|
|
13
|
+
strokeWidth: "2",
|
|
14
|
+
strokeLinecap: "round",
|
|
15
|
+
strokeLinejoin: "round",
|
|
16
|
+
children: [
|
|
17
|
+
/* @__PURE__ */ jsx("path", { d: "M12 10a2 2 0 0 0-2 2c0 1.02-.1 2.51-.26 4" }),
|
|
18
|
+
/* @__PURE__ */ jsx("path", { d: "M14 13.12c0 2.38 0 6.38-1 8.88" }),
|
|
19
|
+
/* @__PURE__ */ jsx("path", { d: "M17.29 21.02c.12-.6.43-2.3.5-3.02" }),
|
|
20
|
+
/* @__PURE__ */ jsx("path", { d: "M2 12a10 10 0 0 1 18-6" }),
|
|
21
|
+
/* @__PURE__ */ jsx("path", { d: "M2 16h.01" }),
|
|
22
|
+
/* @__PURE__ */ jsx("path", { d: "M21.8 16c.2-2 .131-5.354 0-6" }),
|
|
23
|
+
/* @__PURE__ */ jsx("path", { d: "M5 19.5C5.5 18 6 15 6 12a6 6 0 0 1 .34-2" }),
|
|
24
|
+
/* @__PURE__ */ jsx("path", { d: "M8.65 22c.21-.66.45-1.32.57-2" }),
|
|
25
|
+
/* @__PURE__ */ jsx("path", { d: "M9 6.8a6 6 0 0 1 9 5.2v2" })
|
|
26
|
+
]
|
|
27
|
+
}
|
|
28
|
+
);
|
|
29
|
+
var defaultStyles = {
|
|
30
|
+
display: "inline-flex",
|
|
31
|
+
alignItems: "center",
|
|
32
|
+
justifyContent: "center",
|
|
33
|
+
gap: "8px",
|
|
34
|
+
padding: "16px 32px",
|
|
35
|
+
fontSize: "16px",
|
|
36
|
+
fontWeight: 500,
|
|
37
|
+
color: "#ffffff",
|
|
38
|
+
backgroundColor: "#18181b",
|
|
39
|
+
border: "none",
|
|
40
|
+
borderRadius: "9999px",
|
|
41
|
+
cursor: "pointer",
|
|
42
|
+
transition: "background-color 0.2s",
|
|
43
|
+
width: "100%"
|
|
44
|
+
};
|
|
45
|
+
var defaultDisabledStyles = {
|
|
46
|
+
opacity: 0.5,
|
|
47
|
+
cursor: "not-allowed"
|
|
48
|
+
};
|
|
49
|
+
var defaultHoverStyles = {
|
|
50
|
+
backgroundColor: "#27272a"
|
|
51
|
+
};
|
|
52
|
+
var defaultSuccessStyles = {
|
|
53
|
+
backgroundColor: "#16a34a",
|
|
54
|
+
cursor: "default"
|
|
55
|
+
};
|
|
56
|
+
var CheckIcon = ({ className }) => /* @__PURE__ */ jsx(
|
|
57
|
+
"svg",
|
|
58
|
+
{
|
|
59
|
+
className,
|
|
60
|
+
width: "20",
|
|
61
|
+
height: "20",
|
|
62
|
+
viewBox: "0 0 24 24",
|
|
63
|
+
fill: "none",
|
|
64
|
+
stroke: "currentColor",
|
|
65
|
+
strokeWidth: "2.5",
|
|
66
|
+
strokeLinecap: "round",
|
|
67
|
+
strokeLinejoin: "round",
|
|
68
|
+
children: /* @__PURE__ */ jsx("path", { d: "M20 6L9 17l-5-5" })
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
function PayButton({
|
|
72
|
+
client,
|
|
73
|
+
intent,
|
|
74
|
+
onSuccess,
|
|
75
|
+
onError,
|
|
76
|
+
closeOn = "preconfirmed",
|
|
77
|
+
getSignedIntent,
|
|
78
|
+
children = "Pay with 1auth",
|
|
79
|
+
className,
|
|
80
|
+
style,
|
|
81
|
+
disabled,
|
|
82
|
+
hideIcon
|
|
83
|
+
}) {
|
|
84
|
+
const [isProcessing, setIsProcessing] = React.useState(false);
|
|
85
|
+
const [isSuccess, setIsSuccess] = React.useState(false);
|
|
86
|
+
const [isHovered, setIsHovered] = React.useState(false);
|
|
87
|
+
const handleClick = async () => {
|
|
88
|
+
if (disabled || isProcessing || isSuccess) return;
|
|
89
|
+
setIsProcessing(true);
|
|
90
|
+
try {
|
|
91
|
+
await executePayment();
|
|
92
|
+
} catch (err) {
|
|
93
|
+
if (err instanceof Error && !err.message.includes("rejected")) {
|
|
94
|
+
onError?.(err);
|
|
95
|
+
}
|
|
96
|
+
} finally {
|
|
97
|
+
setIsProcessing(false);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
const executePayment = async (forceReauth = false) => {
|
|
101
|
+
let username = null;
|
|
102
|
+
if (!forceReauth) {
|
|
103
|
+
const savedUser = localStorage.getItem("1auth-user");
|
|
104
|
+
if (savedUser) {
|
|
105
|
+
try {
|
|
106
|
+
const parsed = JSON.parse(savedUser);
|
|
107
|
+
username = parsed.username;
|
|
108
|
+
} catch {
|
|
109
|
+
localStorage.removeItem("1auth-user");
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (!username) {
|
|
114
|
+
const authResult = await client.authWithModal();
|
|
115
|
+
if (authResult.success && authResult.username) {
|
|
116
|
+
username = authResult.username;
|
|
117
|
+
localStorage.setItem(
|
|
118
|
+
"1auth-user",
|
|
119
|
+
JSON.stringify({ username })
|
|
120
|
+
);
|
|
121
|
+
} else {
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
let result;
|
|
126
|
+
try {
|
|
127
|
+
if (getSignedIntent) {
|
|
128
|
+
const signedIntent = await getSignedIntent({
|
|
129
|
+
username,
|
|
130
|
+
targetChain: intent.targetChain,
|
|
131
|
+
calls: intent.calls,
|
|
132
|
+
tokenRequests: intent.tokenRequests
|
|
133
|
+
});
|
|
134
|
+
result = await client.sendIntent({
|
|
135
|
+
signedIntent,
|
|
136
|
+
closeOn
|
|
137
|
+
});
|
|
138
|
+
} else {
|
|
139
|
+
result = await client.sendIntent({
|
|
140
|
+
...intent,
|
|
141
|
+
username,
|
|
142
|
+
closeOn
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
} catch (err) {
|
|
146
|
+
if (err instanceof Error && err.message.includes("User not found")) {
|
|
147
|
+
localStorage.removeItem("1auth-user");
|
|
148
|
+
return executePayment(true);
|
|
149
|
+
}
|
|
150
|
+
throw err;
|
|
151
|
+
}
|
|
152
|
+
if (result.success) {
|
|
153
|
+
setIsSuccess(true);
|
|
154
|
+
onSuccess?.(result);
|
|
155
|
+
} else {
|
|
156
|
+
if (result.error?.message?.includes("User not found")) {
|
|
157
|
+
localStorage.removeItem("1auth-user");
|
|
158
|
+
return executePayment(true);
|
|
159
|
+
}
|
|
160
|
+
onError?.(new Error(result.error?.message || "Payment failed"));
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
const combinedStyles = {
|
|
164
|
+
...defaultStyles,
|
|
165
|
+
...isSuccess ? defaultSuccessStyles : {},
|
|
166
|
+
...isHovered && !disabled && !isProcessing && !isSuccess ? defaultHoverStyles : {},
|
|
167
|
+
...disabled || isProcessing ? defaultDisabledStyles : {},
|
|
168
|
+
...style
|
|
169
|
+
};
|
|
170
|
+
return /* @__PURE__ */ jsx(
|
|
171
|
+
"button",
|
|
172
|
+
{
|
|
173
|
+
type: "button",
|
|
174
|
+
className,
|
|
175
|
+
style: combinedStyles,
|
|
176
|
+
onClick: handleClick,
|
|
177
|
+
disabled: disabled || isProcessing || isSuccess,
|
|
178
|
+
onMouseEnter: () => setIsHovered(true),
|
|
179
|
+
onMouseLeave: () => setIsHovered(false),
|
|
180
|
+
children: isSuccess ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
181
|
+
/* @__PURE__ */ jsx(CheckIcon, { className: "pay-button-icon" }),
|
|
182
|
+
"Paid"
|
|
183
|
+
] }) : isProcessing ? "Processing..." : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
184
|
+
!hideIcon && /* @__PURE__ */ jsx(FingerprintIcon, { className: "pay-button-icon" }),
|
|
185
|
+
children
|
|
186
|
+
] })
|
|
187
|
+
}
|
|
188
|
+
);
|
|
189
|
+
}
|
|
190
|
+
export {
|
|
191
|
+
PayButton
|
|
192
|
+
};
|
|
193
|
+
//# sourceMappingURL=react.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/react.tsx"],"sourcesContent":["import * as React from \"react\";\nimport { PasskeyProviderClient } from \"./client\";\nimport type { SendIntentOptions, SendIntentResult, CloseOnStatus, MerchantSignedIntent } 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 PasskeyProviderClient instance */\n client: PasskeyProviderClient;\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<MerchantSignedIntent>;\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,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AU,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":[]}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server-side utilities for 1auth SDK
|
|
3
|
+
* Use these in Next.js API routes or server actions
|
|
4
|
+
*/
|
|
5
|
+
interface MerchantConfig {
|
|
6
|
+
/** Merchant ID from registration */
|
|
7
|
+
merchantId: string;
|
|
8
|
+
/** Ed25519 private key (base64 encoded) */
|
|
9
|
+
privateKey: string;
|
|
10
|
+
/** Intent expiry time in ms (default: 5 minutes) */
|
|
11
|
+
expiryMs?: number;
|
|
12
|
+
}
|
|
13
|
+
interface IntentCall {
|
|
14
|
+
to: string;
|
|
15
|
+
data?: string;
|
|
16
|
+
value?: string;
|
|
17
|
+
label?: string;
|
|
18
|
+
sublabel?: string;
|
|
19
|
+
}
|
|
20
|
+
interface SignIntentParams {
|
|
21
|
+
username?: string;
|
|
22
|
+
accountAddress?: string;
|
|
23
|
+
targetChain: number;
|
|
24
|
+
calls: IntentCall[];
|
|
25
|
+
tokenRequests?: Array<{
|
|
26
|
+
token: string;
|
|
27
|
+
amount: string;
|
|
28
|
+
}>;
|
|
29
|
+
}
|
|
30
|
+
interface SignedIntent {
|
|
31
|
+
merchantId: string;
|
|
32
|
+
targetChain: number;
|
|
33
|
+
calls: IntentCall[];
|
|
34
|
+
username?: string;
|
|
35
|
+
accountAddress?: string;
|
|
36
|
+
nonce: string;
|
|
37
|
+
expiresAt: number;
|
|
38
|
+
signature: string;
|
|
39
|
+
tokenRequests?: Array<{
|
|
40
|
+
token: string;
|
|
41
|
+
amount: string;
|
|
42
|
+
}>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Sign an intent for submission to the passkey service
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* import { signIntent } from "@rhinestone/1auth/server";
|
|
50
|
+
*
|
|
51
|
+
* const signedIntent = signIntent(
|
|
52
|
+
* {
|
|
53
|
+
* username: "alice",
|
|
54
|
+
* targetChain: 8453,
|
|
55
|
+
* calls: [{ to: "0x...", data: "0x...", label: "Buy NFT" }],
|
|
56
|
+
* },
|
|
57
|
+
* {
|
|
58
|
+
* merchantId: process.env.MERCHANT_ID!,
|
|
59
|
+
* privateKey: process.env.MERCHANT_PRIVATE_KEY!,
|
|
60
|
+
* }
|
|
61
|
+
* );
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
declare function signIntent(params: SignIntentParams, config: MerchantConfig): SignedIntent;
|
|
65
|
+
/**
|
|
66
|
+
* Create a Next.js API route handler for signing intents
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* // app/api/sign-intent/route.ts
|
|
71
|
+
* import { createSignIntentHandler } from "@rhinestone/1auth/server";
|
|
72
|
+
*
|
|
73
|
+
* export const POST = createSignIntentHandler({
|
|
74
|
+
* merchantId: process.env.MERCHANT_ID!,
|
|
75
|
+
* privateKey: process.env.MERCHANT_PRIVATE_KEY!,
|
|
76
|
+
* });
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
declare function createSignIntentHandler(config: MerchantConfig): (request: Request) => Promise<Response>;
|
|
80
|
+
|
|
81
|
+
export { type IntentCall, type MerchantConfig, type SignIntentParams, type SignedIntent, createSignIntentHandler, signIntent };
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Server-side utilities for 1auth SDK
|
|
3
|
+
* Use these in Next.js API routes or server actions
|
|
4
|
+
*/
|
|
5
|
+
interface MerchantConfig {
|
|
6
|
+
/** Merchant ID from registration */
|
|
7
|
+
merchantId: string;
|
|
8
|
+
/** Ed25519 private key (base64 encoded) */
|
|
9
|
+
privateKey: string;
|
|
10
|
+
/** Intent expiry time in ms (default: 5 minutes) */
|
|
11
|
+
expiryMs?: number;
|
|
12
|
+
}
|
|
13
|
+
interface IntentCall {
|
|
14
|
+
to: string;
|
|
15
|
+
data?: string;
|
|
16
|
+
value?: string;
|
|
17
|
+
label?: string;
|
|
18
|
+
sublabel?: string;
|
|
19
|
+
}
|
|
20
|
+
interface SignIntentParams {
|
|
21
|
+
username?: string;
|
|
22
|
+
accountAddress?: string;
|
|
23
|
+
targetChain: number;
|
|
24
|
+
calls: IntentCall[];
|
|
25
|
+
tokenRequests?: Array<{
|
|
26
|
+
token: string;
|
|
27
|
+
amount: string;
|
|
28
|
+
}>;
|
|
29
|
+
}
|
|
30
|
+
interface SignedIntent {
|
|
31
|
+
merchantId: string;
|
|
32
|
+
targetChain: number;
|
|
33
|
+
calls: IntentCall[];
|
|
34
|
+
username?: string;
|
|
35
|
+
accountAddress?: string;
|
|
36
|
+
nonce: string;
|
|
37
|
+
expiresAt: number;
|
|
38
|
+
signature: string;
|
|
39
|
+
tokenRequests?: Array<{
|
|
40
|
+
token: string;
|
|
41
|
+
amount: string;
|
|
42
|
+
}>;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Sign an intent for submission to the passkey service
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* ```typescript
|
|
49
|
+
* import { signIntent } from "@rhinestone/1auth/server";
|
|
50
|
+
*
|
|
51
|
+
* const signedIntent = signIntent(
|
|
52
|
+
* {
|
|
53
|
+
* username: "alice",
|
|
54
|
+
* targetChain: 8453,
|
|
55
|
+
* calls: [{ to: "0x...", data: "0x...", label: "Buy NFT" }],
|
|
56
|
+
* },
|
|
57
|
+
* {
|
|
58
|
+
* merchantId: process.env.MERCHANT_ID!,
|
|
59
|
+
* privateKey: process.env.MERCHANT_PRIVATE_KEY!,
|
|
60
|
+
* }
|
|
61
|
+
* );
|
|
62
|
+
* ```
|
|
63
|
+
*/
|
|
64
|
+
declare function signIntent(params: SignIntentParams, config: MerchantConfig): SignedIntent;
|
|
65
|
+
/**
|
|
66
|
+
* Create a Next.js API route handler for signing intents
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* ```typescript
|
|
70
|
+
* // app/api/sign-intent/route.ts
|
|
71
|
+
* import { createSignIntentHandler } from "@rhinestone/1auth/server";
|
|
72
|
+
*
|
|
73
|
+
* export const POST = createSignIntentHandler({
|
|
74
|
+
* merchantId: process.env.MERCHANT_ID!,
|
|
75
|
+
* privateKey: process.env.MERCHANT_PRIVATE_KEY!,
|
|
76
|
+
* });
|
|
77
|
+
* ```
|
|
78
|
+
*/
|
|
79
|
+
declare function createSignIntentHandler(config: MerchantConfig): (request: Request) => Promise<Response>;
|
|
80
|
+
|
|
81
|
+
export { type IntentCall, type MerchantConfig, type SignIntentParams, type SignedIntent, createSignIntentHandler, signIntent };
|