@rhinestone/1auth 0.6.8 → 0.6.9
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/README.md +171 -12
- package/dist/chunk-IHBVEU33.mjs +20 -0
- package/dist/chunk-IHBVEU33.mjs.map +1 -0
- package/dist/chunk-IIACVHR3.mjs +28 -0
- package/dist/chunk-IIACVHR3.mjs.map +1 -0
- package/dist/chunk-N6KE5CII.mjs +72 -0
- package/dist/chunk-N6KE5CII.mjs.map +1 -0
- package/dist/{chunk-SXISYG2P.mjs → chunk-VZYHCFEH.mjs} +195 -140
- package/dist/chunk-VZYHCFEH.mjs.map +1 -0
- package/dist/{client-BrMrhetG.d.mts → client-BNluVe4_.d.ts} +305 -849
- package/dist/{client-BrMrhetG.d.ts → client-CLCdahyj.d.mts} +305 -849
- package/dist/headless.d.mts +90 -0
- package/dist/headless.d.ts +90 -0
- package/dist/headless.js +327 -0
- package/dist/headless.js.map +1 -0
- package/dist/headless.mjs +280 -0
- package/dist/headless.mjs.map +1 -0
- package/dist/index.d.mts +96 -144
- package/dist/index.d.ts +96 -144
- package/dist/index.js +2984 -718
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2740 -627
- package/dist/index.mjs.map +1 -1
- package/dist/{provider-CDl9wYEc.d.mts → provider-BgD9PeDX.d.ts} +6 -5
- package/dist/{provider-Dgv533YQ.d.ts → provider-hxHGb6SX.d.mts} +6 -5
- package/dist/react.d.mts +42 -2
- package/dist/react.d.ts +42 -2
- package/dist/react.js +92 -2
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +66 -1
- package/dist/react.mjs.map +1 -1
- package/dist/server.d.mts +118 -0
- package/dist/server.d.ts +118 -0
- package/dist/server.js +356 -0
- package/dist/server.js.map +1 -0
- package/dist/server.mjs +282 -0
- package/dist/server.mjs.map +1 -0
- package/dist/types-1BMD1PSH.d.mts +1425 -0
- package/dist/types-1BMD1PSH.d.ts +1425 -0
- package/dist/verify-CZe-m_Vf.d.ts +150 -0
- package/dist/verify-D3FaLeAi.d.mts +150 -0
- package/dist/wagmi.d.mts +5 -2
- package/dist/wagmi.d.ts +5 -2
- package/dist/wagmi.js +138 -43
- package/dist/wagmi.js.map +1 -1
- package/dist/wagmi.mjs +2 -1
- package/dist/wagmi.mjs.map +1 -1
- package/package.json +15 -2
- package/dist/chunk-SXISYG2P.mjs.map +0 -1
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import {
|
|
2
|
+
tokenFetchError
|
|
3
|
+
} from "./chunk-IIACVHR3.mjs";
|
|
4
|
+
|
|
5
|
+
// src/headless-client.ts
|
|
6
|
+
var DEFAULT_PROVIDER_URL = "https://passkey.1auth.box";
|
|
7
|
+
var MISSING_APP_CREDENTIALS_MESSAGE = "No sponsorship configured on OneAuthHeadlessClient. Every user intent must carry the app's JWT \u2014 pass `sponsorship: { accessToken, getExtensionToken }` (or URL form) to the constructor.";
|
|
8
|
+
function normalizeSponsorship(config) {
|
|
9
|
+
if (!config) return null;
|
|
10
|
+
if ("accessToken" in config && "getExtensionToken" in config) {
|
|
11
|
+
return config;
|
|
12
|
+
}
|
|
13
|
+
const { accessTokenUrl, extensionTokenUrl } = config;
|
|
14
|
+
return {
|
|
15
|
+
accessToken: async () => {
|
|
16
|
+
const response = await fetch(accessTokenUrl, { credentials: "include" });
|
|
17
|
+
if (!response.ok) {
|
|
18
|
+
throw await tokenFetchError("access token", response);
|
|
19
|
+
}
|
|
20
|
+
const data = await response.json();
|
|
21
|
+
if (!data.token) {
|
|
22
|
+
throw new Error("Access token response missing `token` field");
|
|
23
|
+
}
|
|
24
|
+
return data.token;
|
|
25
|
+
},
|
|
26
|
+
getExtensionToken: async (intentOp) => {
|
|
27
|
+
const response = await fetch(extensionTokenUrl, {
|
|
28
|
+
method: "POST",
|
|
29
|
+
credentials: "include",
|
|
30
|
+
headers: { "Content-Type": "application/json" },
|
|
31
|
+
body: JSON.stringify({ intentOp })
|
|
32
|
+
});
|
|
33
|
+
if (!response.ok) {
|
|
34
|
+
throw await tokenFetchError("extension token", response);
|
|
35
|
+
}
|
|
36
|
+
const data = await response.json();
|
|
37
|
+
if (!data.token) {
|
|
38
|
+
throw new Error("Extension token response missing `token` field");
|
|
39
|
+
}
|
|
40
|
+
return data.token;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
var OneAuthHeadlessClient = class {
|
|
45
|
+
constructor(config) {
|
|
46
|
+
this.providerUrl = config.providerUrl || DEFAULT_PROVIDER_URL;
|
|
47
|
+
this.clientId = config.clientId;
|
|
48
|
+
this.sponsorship = normalizeSponsorship(config.sponsorship);
|
|
49
|
+
}
|
|
50
|
+
setSponsorship(sponsorship) {
|
|
51
|
+
this.sponsorship = normalizeSponsorship(sponsorship);
|
|
52
|
+
}
|
|
53
|
+
// ---------------------------------------------------------------------------
|
|
54
|
+
// Sponsorship JWT fetchers
|
|
55
|
+
// ---------------------------------------------------------------------------
|
|
56
|
+
async fetchAccessToken() {
|
|
57
|
+
if (!this.sponsorship) {
|
|
58
|
+
return {
|
|
59
|
+
ok: false,
|
|
60
|
+
code: "MISSING_APP_CREDENTIALS",
|
|
61
|
+
message: MISSING_APP_CREDENTIALS_MESSAGE
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
const accessToken = await this.sponsorship.accessToken();
|
|
66
|
+
return { ok: true, accessToken };
|
|
67
|
+
} catch (err) {
|
|
68
|
+
return {
|
|
69
|
+
ok: false,
|
|
70
|
+
message: err instanceof Error ? err.message : String(err)
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
async fetchExtensionToken(intentOp, sponsor) {
|
|
75
|
+
if (!sponsor) return { ok: true, extensionToken: void 0 };
|
|
76
|
+
if (!this.sponsorship) {
|
|
77
|
+
return { ok: false, message: MISSING_APP_CREDENTIALS_MESSAGE };
|
|
78
|
+
}
|
|
79
|
+
try {
|
|
80
|
+
const token = await this.sponsorship.getExtensionToken(intentOp);
|
|
81
|
+
return { ok: true, extensionToken: token };
|
|
82
|
+
} catch (err) {
|
|
83
|
+
return {
|
|
84
|
+
ok: false,
|
|
85
|
+
message: err instanceof Error ? err.message : String(err)
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
// ---------------------------------------------------------------------------
|
|
90
|
+
// Intent prepare / submit
|
|
91
|
+
// ---------------------------------------------------------------------------
|
|
92
|
+
/**
|
|
93
|
+
* Quote an intent without opening any dialog. Returns the orchestrator's
|
|
94
|
+
* `intentOp` plus the digest the caller must sign with their own
|
|
95
|
+
* validator (e.g. SmartSession). The caller is responsible for
|
|
96
|
+
* encoding signatures and submitting via {@link submitIntent}.
|
|
97
|
+
*/
|
|
98
|
+
async prepareIntent(options) {
|
|
99
|
+
if (!options.username && !options.accountAddress) {
|
|
100
|
+
throw new Error("prepareIntent requires either `username` or `accountAddress`");
|
|
101
|
+
}
|
|
102
|
+
const accessTokenResult = await this.fetchAccessToken();
|
|
103
|
+
if (!accessTokenResult.ok) {
|
|
104
|
+
throw new Error(`Sponsorship access token fetch failed: ${accessTokenResult.message}`);
|
|
105
|
+
}
|
|
106
|
+
const tokenRequests = options.tokenRequests?.map((tr) => ({
|
|
107
|
+
token: tr.token,
|
|
108
|
+
amount: tr.amount.toString()
|
|
109
|
+
}));
|
|
110
|
+
const body = {
|
|
111
|
+
username: options.username,
|
|
112
|
+
accountAddress: options.accountAddress,
|
|
113
|
+
targetChain: options.targetChain,
|
|
114
|
+
calls: options.calls,
|
|
115
|
+
tokenRequests,
|
|
116
|
+
sourceAssets: options.sourceAssets,
|
|
117
|
+
sourceChainId: options.sourceChainId,
|
|
118
|
+
sessionKeyHandle: options.sessionKeyHandle,
|
|
119
|
+
clientId: this.clientId,
|
|
120
|
+
signingMode: "headless",
|
|
121
|
+
auth: { accessToken: accessTokenResult.accessToken }
|
|
122
|
+
};
|
|
123
|
+
const response = await fetch(`${this.providerUrl}/api/intent/prepare`, {
|
|
124
|
+
method: "POST",
|
|
125
|
+
headers: { "Content-Type": "application/json" },
|
|
126
|
+
body: JSON.stringify(body)
|
|
127
|
+
});
|
|
128
|
+
if (!response.ok) {
|
|
129
|
+
const errorData = await response.json().catch(() => ({}));
|
|
130
|
+
throw new Error(errorData.error || `Prepare failed (${response.status})`);
|
|
131
|
+
}
|
|
132
|
+
return await response.json();
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Forward a pre-signed intent to the orchestrator. The caller has
|
|
136
|
+
* already encoded validator-prefixed origin + destination signatures
|
|
137
|
+
* (one origin signature per intent element); 1auth treats them as
|
|
138
|
+
* opaque bytes.
|
|
139
|
+
*
|
|
140
|
+
* If `sponsor` is omitted or `true`, an extension token is fetched
|
|
141
|
+
* just-in-time and bound to the intent. Pass `sponsor: false` for
|
|
142
|
+
* self-paying intents.
|
|
143
|
+
*/
|
|
144
|
+
async submitIntent(options) {
|
|
145
|
+
const sponsor = options.sponsor ?? true;
|
|
146
|
+
const accessTokenResult = await this.fetchAccessToken();
|
|
147
|
+
if (!accessTokenResult.ok) {
|
|
148
|
+
throw new Error(`Sponsorship access token fetch failed: ${accessTokenResult.message}`);
|
|
149
|
+
}
|
|
150
|
+
const extensionResult = await this.fetchExtensionToken(options.intentOp, sponsor);
|
|
151
|
+
if (!extensionResult.ok) {
|
|
152
|
+
throw new Error(`Sponsorship extension token fetch failed: ${extensionResult.message}`);
|
|
153
|
+
}
|
|
154
|
+
const body = {
|
|
155
|
+
intentOp: options.intentOp,
|
|
156
|
+
accountAddress: options.accountAddress,
|
|
157
|
+
targetChain: options.targetChain,
|
|
158
|
+
calls: options.calls,
|
|
159
|
+
expiresAt: options.expiresAt,
|
|
160
|
+
originSignatures: options.originSignatures,
|
|
161
|
+
destinationSignature: options.destinationSignature,
|
|
162
|
+
targetExecutionSignature: options.targetExecutionSignature,
|
|
163
|
+
auth: {
|
|
164
|
+
accessToken: accessTokenResult.accessToken,
|
|
165
|
+
...extensionResult.extensionToken && { extensionToken: extensionResult.extensionToken }
|
|
166
|
+
}
|
|
167
|
+
};
|
|
168
|
+
const response = await fetch(`${this.providerUrl}/api/intent/headless-execute`, {
|
|
169
|
+
method: "POST",
|
|
170
|
+
headers: { "Content-Type": "application/json" },
|
|
171
|
+
body: JSON.stringify(body)
|
|
172
|
+
});
|
|
173
|
+
if (!response.ok) {
|
|
174
|
+
const errorData = await response.json().catch(() => ({}));
|
|
175
|
+
throw new Error(errorData.error || `Headless execute failed (${response.status})`);
|
|
176
|
+
}
|
|
177
|
+
return await response.json();
|
|
178
|
+
}
|
|
179
|
+
// ---------------------------------------------------------------------------
|
|
180
|
+
// Status / wait — proxies to the existing routes (no headless variant needed).
|
|
181
|
+
// ---------------------------------------------------------------------------
|
|
182
|
+
/**
|
|
183
|
+
* Fetch the latest known status for a submitted headless intent.
|
|
184
|
+
* This is a non-blocking read and may return `pending` before a
|
|
185
|
+
* solver has produced a fill transaction hash.
|
|
186
|
+
*/
|
|
187
|
+
async getIntentStatus(intentId) {
|
|
188
|
+
const response = await fetch(`${this.providerUrl}/api/intent/status/${intentId}`);
|
|
189
|
+
if (!response.ok) {
|
|
190
|
+
throw new Error(`Status fetch failed (${response.status})`);
|
|
191
|
+
}
|
|
192
|
+
return await response.json();
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Wait for a submitted headless intent to produce a status update and,
|
|
196
|
+
* when available, the final fill transaction hash. The wait endpoint
|
|
197
|
+
* needs the opaque `transactionResult` returned by submit because 1auth
|
|
198
|
+
* does not persist that SDK object in its database.
|
|
199
|
+
*/
|
|
200
|
+
async waitForIntent(intentId, transactionResult) {
|
|
201
|
+
if (!transactionResult) {
|
|
202
|
+
throw new Error("waitForIntent requires submitResult.transactionResult");
|
|
203
|
+
}
|
|
204
|
+
const response = await fetch(`${this.providerUrl}/api/intent/wait/${intentId}`, {
|
|
205
|
+
method: "POST",
|
|
206
|
+
headers: { "Content-Type": "application/json" },
|
|
207
|
+
body: JSON.stringify({ transactionResult })
|
|
208
|
+
});
|
|
209
|
+
if (!response.ok) {
|
|
210
|
+
const errorData = await response.json().catch(() => ({}));
|
|
211
|
+
throw new Error(
|
|
212
|
+
errorData.details || errorData.error || `Wait fetch failed (${response.status})`
|
|
213
|
+
);
|
|
214
|
+
}
|
|
215
|
+
return await response.json();
|
|
216
|
+
}
|
|
217
|
+
// ---------------------------------------------------------------------------
|
|
218
|
+
// SmartSession install (one-time, passkey-signed)
|
|
219
|
+
// ---------------------------------------------------------------------------
|
|
220
|
+
/**
|
|
221
|
+
* Resolve the SmartSession install call(s) for `sessionKeyAddress`
|
|
222
|
+
* with the supplied `permissions`.
|
|
223
|
+
*
|
|
224
|
+
* Returns `{ install, sessionKeyHandle }`:
|
|
225
|
+
*
|
|
226
|
+
* - `install` is a `{ targetChain, calls }` pair the caller feeds
|
|
227
|
+
* straight into `OneAuthClient.sendIntent({ targetChain, calls })`
|
|
228
|
+
* so the user passkey-signs the install via the existing dialog.
|
|
229
|
+
* - `sessionKeyHandle` contains the deterministic `permissionId`
|
|
230
|
+
* plus metadata to persist in localStorage. Persist this BEFORE
|
|
231
|
+
* submitting the install so a refresh during signing doesn't
|
|
232
|
+
* lose the handle.
|
|
233
|
+
*
|
|
234
|
+
* If the validator is already installed on the user's account,
|
|
235
|
+
* `install.calls` is empty and `install.alreadyInstalled` is true.
|
|
236
|
+
* The caller should still persist `sessionKeyHandle` — the on-chain
|
|
237
|
+
* session enabling happens at first headless use via SmartSession's
|
|
238
|
+
* ENABLE-mode signature wrapping (see follow-up).
|
|
239
|
+
*/
|
|
240
|
+
async installSmartSession(options) {
|
|
241
|
+
if (!options.username && !options.accountAddress) {
|
|
242
|
+
throw new Error(
|
|
243
|
+
"installSmartSession requires either `username` or `accountAddress`"
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
const accessTokenResult = await this.fetchAccessToken();
|
|
247
|
+
if (!accessTokenResult.ok) {
|
|
248
|
+
throw new Error(
|
|
249
|
+
`Sponsorship access token fetch failed: ${accessTokenResult.message}`
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
const body = {
|
|
253
|
+
username: options.username,
|
|
254
|
+
accountAddress: options.accountAddress,
|
|
255
|
+
targetChain: options.targetChain,
|
|
256
|
+
sessionKeyAddress: options.sessionKeyAddress,
|
|
257
|
+
permissions: options.permissions,
|
|
258
|
+
validUntil: options.validUntil,
|
|
259
|
+
validAfter: options.validAfter,
|
|
260
|
+
maxUses: options.maxUses,
|
|
261
|
+
enableSessionSignature: options.enableSessionSignature,
|
|
262
|
+
label: options.label,
|
|
263
|
+
auth: { accessToken: accessTokenResult.accessToken }
|
|
264
|
+
};
|
|
265
|
+
const response = await fetch(`${this.providerUrl}/api/sessions/install`, {
|
|
266
|
+
method: "POST",
|
|
267
|
+
headers: { "Content-Type": "application/json" },
|
|
268
|
+
body: JSON.stringify(body)
|
|
269
|
+
});
|
|
270
|
+
if (!response.ok) {
|
|
271
|
+
const errorData = await response.json().catch(() => ({}));
|
|
272
|
+
throw new Error(errorData.error || `Install failed (${response.status})`);
|
|
273
|
+
}
|
|
274
|
+
return await response.json();
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
export {
|
|
278
|
+
OneAuthHeadlessClient
|
|
279
|
+
};
|
|
280
|
+
//# sourceMappingURL=headless.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/headless-client.ts"],"sourcesContent":["/**\n * Headless 1auth client.\n *\n * Used by integrators that hold their own ECDSA signer in localStorage\n * and produce signatures for an ERC-7579 validator other than the\n * passkey one (typically `@rhinestone/sdk` experimental SmartSession).\n *\n * Responsibilities:\n * - Fetch sponsorship JWTs from the app's own backend.\n * - Call `/api/intent/prepare?signingMode=headless` to get an\n * orchestrator-quoted `intentOp` + `digestResult`.\n * - Forward pre-encoded validator-prefixed signatures to the new\n * `/api/intent/headless-execute` route.\n * - Drive the existing passkey dialog (via {@link OneAuthClient}) for\n * the one-time SmartSession install ceremony.\n *\n * 1auth itself stays ignorant of session keys — the on-chain\n * SmartSession validator is the only authority over what a session key\n * may sign for. The host app persists `{ sessionKeyAddress, permissionId,\n * accountAddress, permissions }` in its own storage.\n */\n\nimport type {\n HeadlessIntentOptions,\n HeadlessIntentStatusResult,\n HeadlessPrepareResult,\n HeadlessSubmitOptions,\n HeadlessSubmitResult,\n InstallSmartSessionOptions,\n InstallSmartSessionResult,\n IntentTokenRequest,\n PasskeyProviderConfig,\n SponsorshipCallbackConfig,\n SponsorshipConfig,\n} from \"./types\";\nimport { tokenFetchError } from \"./sponsorship-fetch\";\n\nconst DEFAULT_PROVIDER_URL = \"https://passkey.1auth.box\";\n\nconst MISSING_APP_CREDENTIALS_MESSAGE =\n \"No sponsorship configured on OneAuthHeadlessClient. Every user intent must carry the app's JWT — pass `sponsorship: { accessToken, getExtensionToken }` (or URL form) to the constructor.\";\n\ntype AccessTokenFetchResult =\n | { ok: true; accessToken: string }\n | { ok: false; code?: \"MISSING_APP_CREDENTIALS\"; message: string };\n\ntype ExtensionTokenFetchResult =\n | { ok: true; extensionToken: string | undefined }\n | { ok: false; message: string };\n\n/**\n * Mirrors `normalizeSponsorship` in `client.ts`. Kept local so the\n * headless entry point doesn't pull in the whole OneAuthClient module\n * graph for callers that only need the headless surface.\n */\nfunction normalizeSponsorship(\n config: SponsorshipConfig | undefined,\n): SponsorshipCallbackConfig | null {\n if (!config) return null;\n if (\"accessToken\" in config && \"getExtensionToken\" in config) {\n return config;\n }\n const { accessTokenUrl, extensionTokenUrl } = config;\n return {\n accessToken: async () => {\n const response = await fetch(accessTokenUrl, { credentials: \"include\" });\n if (!response.ok) {\n throw await tokenFetchError(\"access token\", response);\n }\n const data = (await response.json()) as { token?: string };\n if (!data.token) {\n throw new Error(\"Access token response missing `token` field\");\n }\n return data.token;\n },\n getExtensionToken: async (intentOp: string) => {\n const response = await fetch(extensionTokenUrl, {\n method: \"POST\",\n credentials: \"include\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ intentOp }),\n });\n if (!response.ok) {\n throw await tokenFetchError(\"extension token\", response);\n }\n const data = (await response.json()) as { token?: string };\n if (!data.token) {\n throw new Error(\"Extension token response missing `token` field\");\n }\n return data.token;\n },\n };\n}\n\nexport class OneAuthHeadlessClient {\n private providerUrl: string;\n private clientId?: string;\n private sponsorship: SponsorshipCallbackConfig | null;\n\n constructor(config: PasskeyProviderConfig) {\n this.providerUrl = config.providerUrl || DEFAULT_PROVIDER_URL;\n this.clientId = config.clientId;\n this.sponsorship = normalizeSponsorship(config.sponsorship);\n }\n\n setSponsorship(sponsorship: SponsorshipConfig | undefined): void {\n this.sponsorship = normalizeSponsorship(sponsorship);\n }\n\n // ---------------------------------------------------------------------------\n // Sponsorship JWT fetchers\n // ---------------------------------------------------------------------------\n\n private async fetchAccessToken(): Promise<AccessTokenFetchResult> {\n if (!this.sponsorship) {\n return {\n ok: false,\n code: \"MISSING_APP_CREDENTIALS\",\n message: MISSING_APP_CREDENTIALS_MESSAGE,\n };\n }\n try {\n const accessToken = await this.sponsorship.accessToken();\n return { ok: true, accessToken };\n } catch (err) {\n return {\n ok: false,\n message: err instanceof Error ? err.message : String(err),\n };\n }\n }\n\n private async fetchExtensionToken(\n intentOp: string,\n sponsor: boolean,\n ): Promise<ExtensionTokenFetchResult> {\n if (!sponsor) return { ok: true, extensionToken: undefined };\n if (!this.sponsorship) {\n return { ok: false, message: MISSING_APP_CREDENTIALS_MESSAGE };\n }\n try {\n const token = await this.sponsorship.getExtensionToken(intentOp);\n return { ok: true, extensionToken: token };\n } catch (err) {\n return {\n ok: false,\n message: err instanceof Error ? err.message : String(err),\n };\n }\n }\n\n // ---------------------------------------------------------------------------\n // Intent prepare / submit\n // ---------------------------------------------------------------------------\n\n /**\n * Quote an intent without opening any dialog. Returns the orchestrator's\n * `intentOp` plus the digest the caller must sign with their own\n * validator (e.g. SmartSession). The caller is responsible for\n * encoding signatures and submitting via {@link submitIntent}.\n */\n async prepareIntent(options: HeadlessIntentOptions): Promise<HeadlessPrepareResult> {\n if (!options.username && !options.accountAddress) {\n throw new Error(\"prepareIntent requires either `username` or `accountAddress`\");\n }\n\n const accessTokenResult = await this.fetchAccessToken();\n if (!accessTokenResult.ok) {\n throw new Error(`Sponsorship access token fetch failed: ${accessTokenResult.message}`);\n }\n\n // bigint → string conversion for token requests; matches what the\n // dialog flow does before serializing requestBody.\n const tokenRequests = options.tokenRequests?.map((tr: IntentTokenRequest) => ({\n token: tr.token,\n amount: tr.amount.toString(),\n }));\n\n const body = {\n username: options.username,\n accountAddress: options.accountAddress,\n targetChain: options.targetChain,\n calls: options.calls,\n tokenRequests,\n sourceAssets: options.sourceAssets,\n sourceChainId: options.sourceChainId,\n sessionKeyHandle: options.sessionKeyHandle,\n clientId: this.clientId,\n signingMode: \"headless\" as const,\n auth: { accessToken: accessTokenResult.accessToken },\n };\n\n const response = await fetch(`${this.providerUrl}/api/intent/prepare`, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify(body),\n });\n\n if (!response.ok) {\n const errorData = (await response.json().catch(() => ({}))) as { error?: string };\n throw new Error(errorData.error || `Prepare failed (${response.status})`);\n }\n\n return (await response.json()) as HeadlessPrepareResult;\n }\n\n /**\n * Forward a pre-signed intent to the orchestrator. The caller has\n * already encoded validator-prefixed origin + destination signatures\n * (one origin signature per intent element); 1auth treats them as\n * opaque bytes.\n *\n * If `sponsor` is omitted or `true`, an extension token is fetched\n * just-in-time and bound to the intent. Pass `sponsor: false` for\n * self-paying intents.\n */\n async submitIntent(options: HeadlessSubmitOptions): Promise<HeadlessSubmitResult> {\n const sponsor = options.sponsor ?? true;\n const accessTokenResult = await this.fetchAccessToken();\n if (!accessTokenResult.ok) {\n throw new Error(`Sponsorship access token fetch failed: ${accessTokenResult.message}`);\n }\n\n const extensionResult = await this.fetchExtensionToken(options.intentOp, sponsor);\n if (!extensionResult.ok) {\n throw new Error(`Sponsorship extension token fetch failed: ${extensionResult.message}`);\n }\n\n const body = {\n intentOp: options.intentOp,\n accountAddress: options.accountAddress,\n targetChain: options.targetChain,\n calls: options.calls,\n expiresAt: options.expiresAt,\n originSignatures: options.originSignatures,\n destinationSignature: options.destinationSignature,\n targetExecutionSignature: options.targetExecutionSignature,\n auth: {\n accessToken: accessTokenResult.accessToken,\n ...(extensionResult.extensionToken && { extensionToken: extensionResult.extensionToken }),\n },\n };\n\n const response = await fetch(`${this.providerUrl}/api/intent/headless-execute`, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify(body),\n });\n\n if (!response.ok) {\n const errorData = (await response.json().catch(() => ({}))) as { error?: string };\n throw new Error(errorData.error || `Headless execute failed (${response.status})`);\n }\n\n return (await response.json()) as HeadlessSubmitResult;\n }\n\n // ---------------------------------------------------------------------------\n // Status / wait — proxies to the existing routes (no headless variant needed).\n // ---------------------------------------------------------------------------\n\n /**\n * Fetch the latest known status for a submitted headless intent.\n * This is a non-blocking read and may return `pending` before a\n * solver has produced a fill transaction hash.\n */\n async getIntentStatus(intentId: string): Promise<HeadlessIntentStatusResult> {\n const response = await fetch(`${this.providerUrl}/api/intent/status/${intentId}`);\n if (!response.ok) {\n throw new Error(`Status fetch failed (${response.status})`);\n }\n return (await response.json()) as HeadlessIntentStatusResult;\n }\n\n /**\n * Wait for a submitted headless intent to produce a status update and,\n * when available, the final fill transaction hash. The wait endpoint\n * needs the opaque `transactionResult` returned by submit because 1auth\n * does not persist that SDK object in its database.\n */\n async waitForIntent(\n intentId: string,\n transactionResult: unknown,\n ): Promise<HeadlessIntentStatusResult> {\n if (!transactionResult) {\n throw new Error(\"waitForIntent requires submitResult.transactionResult\");\n }\n\n const response = await fetch(`${this.providerUrl}/api/intent/wait/${intentId}`, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify({ transactionResult }),\n });\n if (!response.ok) {\n const errorData = (await response.json().catch(() => ({}))) as {\n error?: string;\n details?: string;\n };\n throw new Error(\n errorData.details || errorData.error || `Wait fetch failed (${response.status})`,\n );\n }\n return (await response.json()) as HeadlessIntentStatusResult;\n }\n\n // ---------------------------------------------------------------------------\n // SmartSession install (one-time, passkey-signed)\n // ---------------------------------------------------------------------------\n\n /**\n * Resolve the SmartSession install call(s) for `sessionKeyAddress`\n * with the supplied `permissions`.\n *\n * Returns `{ install, sessionKeyHandle }`:\n *\n * - `install` is a `{ targetChain, calls }` pair the caller feeds\n * straight into `OneAuthClient.sendIntent({ targetChain, calls })`\n * so the user passkey-signs the install via the existing dialog.\n * - `sessionKeyHandle` contains the deterministic `permissionId`\n * plus metadata to persist in localStorage. Persist this BEFORE\n * submitting the install so a refresh during signing doesn't\n * lose the handle.\n *\n * If the validator is already installed on the user's account,\n * `install.calls` is empty and `install.alreadyInstalled` is true.\n * The caller should still persist `sessionKeyHandle` — the on-chain\n * session enabling happens at first headless use via SmartSession's\n * ENABLE-mode signature wrapping (see follow-up).\n */\n async installSmartSession(\n options: InstallSmartSessionOptions,\n ): Promise<InstallSmartSessionResult> {\n if (!options.username && !options.accountAddress) {\n throw new Error(\n \"installSmartSession requires either `username` or `accountAddress`\",\n );\n }\n\n const accessTokenResult = await this.fetchAccessToken();\n if (!accessTokenResult.ok) {\n throw new Error(\n `Sponsorship access token fetch failed: ${accessTokenResult.message}`,\n );\n }\n\n const body = {\n username: options.username,\n accountAddress: options.accountAddress,\n targetChain: options.targetChain,\n sessionKeyAddress: options.sessionKeyAddress,\n permissions: options.permissions,\n validUntil: options.validUntil,\n validAfter: options.validAfter,\n maxUses: options.maxUses,\n enableSessionSignature: options.enableSessionSignature,\n label: options.label,\n auth: { accessToken: accessTokenResult.accessToken },\n };\n\n const response = await fetch(`${this.providerUrl}/api/sessions/install`, {\n method: \"POST\",\n headers: { \"Content-Type\": \"application/json\" },\n body: JSON.stringify(body),\n });\n\n if (!response.ok) {\n const errorData = (await response.json().catch(() => ({}))) as {\n error?: string;\n };\n throw new Error(errorData.error || `Install failed (${response.status})`);\n }\n\n return (await response.json()) as InstallSmartSessionResult;\n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,IAC3B,CAAC;AAED,QAAI,CAAC,SAAS,IAAI;AAChB,YAAM,YAAa,MAAM,SAAS,KAAK,EAAE,MAAM,OAAO,CAAC,EAAE;AAGzD,YAAM,IAAI,MAAM,UAAU,SAAS,mBAAmB,SAAS,MAAM,GAAG;AAAA,IAC1E;AAEA,WAAQ,MAAM,SAAS,KAAK;AAAA,EAC9B;AACF;","names":[]}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,10 +1,71 @@
|
|
|
1
|
-
import { O as OneAuthClient
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import { O as OneAuthClient } from './client-CLCdahyj.mjs';
|
|
2
|
+
import { Abi, Address, LocalAccount, WalletClient, Hash, Chain } from 'viem';
|
|
3
|
+
import { Permission } from '@rhinestone/sdk';
|
|
4
|
+
export { Permission } from '@rhinestone/sdk';
|
|
5
|
+
import { h as IntentCall, i as SendIntentResult } from './types-1BMD1PSH.mjs';
|
|
6
|
+
export { a7 as AssetBalance, a8 as AssetBalanceBucket, a9 as AssetsResponse, u as AuthFlow, A as AuthResult, v as AuthWithModalOptions, z as AuthenticateOptions, B as AuthenticateResult, R as BalanceRequirement, ap as BatchIntentItem, as as BatchIntentItemResult, ad as CheckConsentOptions, ae as CheckConsentResult, a0 as CloseOnStatus, y as ConnectResult, ac as ConsentData, ab as ConsentField, w as CreateAccountWithModalOptions, C as CreateCrossChainPermissionInput, r as CreateSigningRequestResponse, k as CrossChainPermit, l as CrossChainSettlementLayer, M as EIP712Domain, O as EIP712TypeField, N as EIP712Types, E as EmbedOptions, a2 as ExecuteIntentResponse, a6 as GetAssetsOptions, an as GrantPermissionContractMetadata, ah as GrantPermissionsOptions, ai as GrantPermissionsResult, a4 as IntentHistoryItem, a3 as IntentHistoryOptions, a5 as IntentHistoryResult, Z as IntentQuote, _ as IntentStatus, X as IntentTokenRequest, aj as ListSessionGrantsOptions, ak as ListSessionGrantsResult, L as LoginWithModalOptions, ax as OneAuthTelemetryAttributeValue, ay as OneAuthTelemetryAttributes, az as OneAuthTelemetryConfig, aA as OneAuthTelemetryEvent, aB as OneAuthTelemetryEventName, aC as OneAuthTelemetryFlow, aD as OneAuthTelemetryTraceContext, $ as OrchestratorStatus, t as PasskeyCredential, P as PasskeyProviderConfig, au as PrepareBatchIntentResponse, a1 as PrepareIntentResponse, at as PreparedBatchIntent, af as RequestConsentOptions, ag as RequestConsentResult, aq as SendBatchIntentOptions, ar as SendBatchIntentResult, Y as SendIntentOptions, am as SessionGrantChain, al as SessionGrantRecord, F as SignMessageOptions, G as SignMessageResult, J as SignTypedDataOptions, K as SignTypedDataResult, x as SignerType, p as SigningError, q as SigningErrorCode, m as SigningRequestOptions, s as SigningRequestStatus, n as SigningResult, D as SigningResultBase, o as SigningSuccess, ao as SmartSessionPolicy, av as SponsorshipCallbackConfig, S as SponsorshipConfig, aw as SponsorshipUrlConfig, aa as ThemeConfig, T as TransactionAction, V as TransactionDetails, Q as TransactionFees, U as UserPasskeysResponse, W as WebAuthnSignature, j as createCrossChainPermission } from './types-1BMD1PSH.mjs';
|
|
7
|
+
export { O as OneAuthProvider, a as OneAuthProviderOptions, c as createOneAuthProvider } from './provider-hxHGb6SX.mjs';
|
|
8
|
+
import { P as PasskeyWalletClientConfig, S as SendCallsParams } from './verify-D3FaLeAi.mjs';
|
|
9
|
+
export { E as ETHEREUM_MESSAGE_PREFIX, T as TransactionCall, e as encodeWebAuthnSignature, h as hashCalls, a as hashMessage, v as verifyMessageHash } from './verify-D3FaLeAi.mjs';
|
|
5
10
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
6
11
|
import * as React from 'react';
|
|
7
|
-
|
|
12
|
+
|
|
13
|
+
type DefinePermissionsConfig<TAbi extends Abi> = Permission<TAbi> & {
|
|
14
|
+
/** Optional human-readable name surfaced in the review UI. */
|
|
15
|
+
name?: string;
|
|
16
|
+
};
|
|
17
|
+
interface DefinedPermissions<TAbi extends Abi = Abi> {
|
|
18
|
+
/**
|
|
19
|
+
* v2 SmartSession permissions, ready to pass to
|
|
20
|
+
* `OneAuthClient.grantPermissions({ ...definePermissions(...) })`.
|
|
21
|
+
*
|
|
22
|
+
* Always a single-element array so the `...spread` pattern works cleanly
|
|
23
|
+
* with `grantPermissions`, which accepts `permissions: Permission[]`.
|
|
24
|
+
*
|
|
25
|
+
* Widened to `Permission<Abi>` (rather than `Permission<TAbi>`) so the
|
|
26
|
+
* spread composes with `GrantPermissionsOptions.permissions: Permission<Abi>[]`.
|
|
27
|
+
* The SDK's v2 `Permission<TAbi>` includes conditional `SpendingLimitField<TFn>` /
|
|
28
|
+
* `ValueLimitField<TFn>` types that break covariance over `TAbi`, so an inferred
|
|
29
|
+
* narrow `Permission<erc20Abi>` is no longer assignable to `Permission<Abi>`.
|
|
30
|
+
* We keep `TAbi` on the type parameter so `contracts[].abi` retains its
|
|
31
|
+
* narrow shape for the review UI.
|
|
32
|
+
*/
|
|
33
|
+
permissions: [Permission<Abi>];
|
|
34
|
+
/**
|
|
35
|
+
* Contract metadata for the permission review UI. The address and ABI
|
|
36
|
+
* here mirror the entry in `permissions[0]`; `name` is optional and
|
|
37
|
+
* purely cosmetic (it's never sent to a contract).
|
|
38
|
+
*/
|
|
39
|
+
contracts: Array<{
|
|
40
|
+
address: Address;
|
|
41
|
+
name?: string;
|
|
42
|
+
abi: TAbi;
|
|
43
|
+
}>;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Build a v2 SmartSession `Permission` from an ABI + function map.
|
|
47
|
+
*
|
|
48
|
+
* The Rhinestone SDK derives function selectors and universal-action
|
|
49
|
+
* calldata offsets from the ABI internally, so app code no longer needs
|
|
50
|
+
* to spell out raw 4-byte selectors or parameter indices. The accepted
|
|
51
|
+
* shape is the SDK's own `Permission<TAbi>` plus an optional `name` for
|
|
52
|
+
* the review UI.
|
|
53
|
+
*
|
|
54
|
+
* @example
|
|
55
|
+
* const permissions = definePermissions({
|
|
56
|
+
* address: USDC,
|
|
57
|
+
* abi: erc20Abi,
|
|
58
|
+
* name: "USDC",
|
|
59
|
+
* functions: {
|
|
60
|
+
* transfer: {
|
|
61
|
+
* params: { to: { condition: "equal", value: RECIPIENT } },
|
|
62
|
+
* },
|
|
63
|
+
* },
|
|
64
|
+
* });
|
|
65
|
+
*
|
|
66
|
+
* await oneAuth.grantPermissions({ ...permissions, sessionKeyAddress });
|
|
67
|
+
*/
|
|
68
|
+
declare function definePermissions<const TAbi extends Abi>(config: DefinePermissionsConfig<TAbi>): DefinedPermissions<TAbi>;
|
|
8
69
|
|
|
9
70
|
/**
|
|
10
71
|
* viem LocalAccount adapter for 1auth passkey-controlled smart accounts.
|
|
@@ -18,7 +79,10 @@ export { getTokenAddress, getTokenDecimals } from '@rhinestone/sdk';
|
|
|
18
79
|
*/
|
|
19
80
|
|
|
20
81
|
type PasskeyAccount = LocalAccount<"1auth"> & {
|
|
21
|
-
username
|
|
82
|
+
/** Optional username hint retained for legacy integrations. */
|
|
83
|
+
username?: string;
|
|
84
|
+
/** Smart account address used as the canonical signer identity. */
|
|
85
|
+
accountAddress: Address;
|
|
22
86
|
};
|
|
23
87
|
/**
|
|
24
88
|
* Creates a viem `LocalAccount` that delegates signing to the 1auth passkey service.
|
|
@@ -34,9 +98,8 @@ type PasskeyAccount = LocalAccount<"1auth"> & {
|
|
|
34
98
|
*
|
|
35
99
|
* @param client - A configured `OneAuthClient` instance
|
|
36
100
|
* @param params.address - The EVM address of the user's smart account
|
|
37
|
-
* @param params.username -
|
|
38
|
-
*
|
|
39
|
-
* @returns A `PasskeyAccount` extending `LocalAccount<"1auth">` with a `username` field
|
|
101
|
+
* @param params.username - Optional 1auth username hint for older accounts
|
|
102
|
+
* @returns A `PasskeyAccount` extending `LocalAccount<"1auth">`
|
|
40
103
|
*
|
|
41
104
|
* @example
|
|
42
105
|
* ```typescript
|
|
@@ -47,7 +110,6 @@ type PasskeyAccount = LocalAccount<"1auth"> & {
|
|
|
47
110
|
* const client = new OneAuthClient({ clientId: "my-app" });
|
|
48
111
|
* const account = createPasskeyAccount(client, {
|
|
49
112
|
* address: "0xYourSmartAccountAddress",
|
|
50
|
-
* username: "alice",
|
|
51
113
|
* });
|
|
52
114
|
*
|
|
53
115
|
* const walletClient = createWalletClient({
|
|
@@ -61,82 +123,8 @@ type PasskeyAccount = LocalAccount<"1auth"> & {
|
|
|
61
123
|
*/
|
|
62
124
|
declare function createPasskeyAccount(client: OneAuthClient, params: {
|
|
63
125
|
address: Address;
|
|
64
|
-
username: string;
|
|
65
|
-
}): PasskeyAccount;
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Configuration for creating a passkey-enabled WalletClient
|
|
69
|
-
*/
|
|
70
|
-
interface PasskeyWalletClientConfig {
|
|
71
|
-
/** User's smart account address */
|
|
72
|
-
accountAddress: Address;
|
|
73
|
-
/** Username for the passkey provider (defaults to accountAddress) */
|
|
74
126
|
username?: string;
|
|
75
|
-
|
|
76
|
-
providerUrl?: string;
|
|
77
|
-
/** Client identifier for this application */
|
|
78
|
-
clientId: string;
|
|
79
|
-
/** Optional URL of the dialog UI */
|
|
80
|
-
dialogUrl?: string;
|
|
81
|
-
/** Chain configuration */
|
|
82
|
-
chain: Chain;
|
|
83
|
-
/** Transport (e.g., http(), webSocket()) */
|
|
84
|
-
transport: Transport;
|
|
85
|
-
/** Wait for a transaction hash before resolving send calls. */
|
|
86
|
-
waitForHash?: boolean;
|
|
87
|
-
/** Maximum time to wait for a transaction hash in ms. */
|
|
88
|
-
hashTimeoutMs?: number;
|
|
89
|
-
/** Poll interval for transaction hash in ms. */
|
|
90
|
-
hashIntervalMs?: number;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* A single call in a batch transaction
|
|
94
|
-
*/
|
|
95
|
-
interface TransactionCall {
|
|
96
|
-
/** Target contract address */
|
|
97
|
-
to: Address;
|
|
98
|
-
/** Calldata to send */
|
|
99
|
-
data?: Hex;
|
|
100
|
-
/** Value in wei to send */
|
|
101
|
-
value?: bigint;
|
|
102
|
-
/** Optional label for the transaction review UI (e.g., "Swap ETH for USDC") */
|
|
103
|
-
label?: string;
|
|
104
|
-
/** Optional sublabel for additional context (e.g., "1 ETH → 2,500 USDC") */
|
|
105
|
-
sublabel?: string;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Parameters for sendCalls (batched transactions)
|
|
109
|
-
*/
|
|
110
|
-
interface SendCallsParams {
|
|
111
|
-
/** Array of calls to execute */
|
|
112
|
-
calls: TransactionCall[];
|
|
113
|
-
/** Optional chain id override */
|
|
114
|
-
chainId?: number;
|
|
115
|
-
/** Optional token requests for orchestrator output (what tokens/amounts to deliver) */
|
|
116
|
-
tokenRequests?: {
|
|
117
|
-
token: string;
|
|
118
|
-
amount: bigint;
|
|
119
|
-
}[];
|
|
120
|
-
/** Constrain which tokens the orchestrator can use as input/payment */
|
|
121
|
-
sourceAssets?: string[];
|
|
122
|
-
/** Which chain to look for source assets on */
|
|
123
|
-
sourceChainId?: number;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* Encode a WebAuthn signature for ERC-1271 verification on-chain
|
|
128
|
-
*
|
|
129
|
-
* @param sig - The WebAuthn signature from the passkey
|
|
130
|
-
* @returns ABI-encoded signature bytes
|
|
131
|
-
*/
|
|
132
|
-
declare function encodeWebAuthnSignature(sig: WebAuthnSignature): Hex;
|
|
133
|
-
/**
|
|
134
|
-
* Hash an array of transaction calls for signing
|
|
135
|
-
*
|
|
136
|
-
* @param calls - Array of transaction calls
|
|
137
|
-
* @returns keccak256 hash of the encoded calls
|
|
138
|
-
*/
|
|
139
|
-
declare function hashCalls(calls: TransactionCall[]): Hex;
|
|
127
|
+
}): PasskeyAccount;
|
|
140
128
|
|
|
141
129
|
/**
|
|
142
130
|
* @file viem WalletClient factory backed by passkey signing.
|
|
@@ -196,6 +184,13 @@ type PasskeyWalletClient = WalletClient & {
|
|
|
196
184
|
*/
|
|
197
185
|
declare function createPasskeyWalletClient(config: PasskeyWalletClientConfig): PasskeyWalletClient;
|
|
198
186
|
|
|
187
|
+
/** Identity used to sign a queued batch. Account address is the canonical path. */
|
|
188
|
+
interface BatchQueueIdentity {
|
|
189
|
+
/** Optional username hint for legacy accounts. */
|
|
190
|
+
username?: string;
|
|
191
|
+
/** Smart account address of the signer. */
|
|
192
|
+
accountAddress?: string;
|
|
193
|
+
}
|
|
199
194
|
/**
|
|
200
195
|
* A batched call in the queue
|
|
201
196
|
*/
|
|
@@ -228,7 +223,7 @@ interface BatchQueueContextValue {
|
|
|
228
223
|
/** Clear all calls from the batch */
|
|
229
224
|
clearBatch: () => void;
|
|
230
225
|
/** Sign and execute all batched calls */
|
|
231
|
-
signAll: (
|
|
226
|
+
signAll: (identity?: string | BatchQueueIdentity) => Promise<SendIntentResult>;
|
|
232
227
|
/** Whether the widget is expanded */
|
|
233
228
|
isExpanded: boolean;
|
|
234
229
|
/** Set widget expanded state */
|
|
@@ -245,15 +240,17 @@ declare function useBatchQueue(): BatchQueueContextValue;
|
|
|
245
240
|
interface BatchQueueProviderProps {
|
|
246
241
|
/** The OneAuthClient instance */
|
|
247
242
|
client: OneAuthClient;
|
|
248
|
-
/** Optional username for localStorage persistence
|
|
243
|
+
/** Optional username for legacy localStorage persistence and account lookup. */
|
|
249
244
|
username?: string;
|
|
245
|
+
/** Optional account address for address-only sessions and persistence. */
|
|
246
|
+
accountAddress?: string;
|
|
250
247
|
/** Children to render */
|
|
251
248
|
children: React.ReactNode;
|
|
252
249
|
}
|
|
253
250
|
/**
|
|
254
251
|
* Provider component for the batch queue
|
|
255
252
|
*/
|
|
256
|
-
declare function BatchQueueProvider({ client, username, children, }: BatchQueueProviderProps): react_jsx_runtime.JSX.Element;
|
|
253
|
+
declare function BatchQueueProvider({ client, username, accountAddress, children, }: BatchQueueProviderProps): react_jsx_runtime.JSX.Element;
|
|
257
254
|
|
|
258
255
|
/**
|
|
259
256
|
* @file Floating UI widget for the 1auth batch transaction queue.
|
|
@@ -268,7 +265,7 @@ declare function BatchQueueProvider({ client, username, children, }: BatchQueueP
|
|
|
268
265
|
* consumer's bundler.
|
|
269
266
|
*/
|
|
270
267
|
interface BatchQueueWidgetProps {
|
|
271
|
-
/** Callback when "Sign All" is clicked
|
|
268
|
+
/** Callback when "Sign All" is clicked. */
|
|
272
269
|
onSignAll: () => void;
|
|
273
270
|
}
|
|
274
271
|
/**
|
|
@@ -287,18 +284,19 @@ interface BatchQueueWidgetProps {
|
|
|
287
284
|
* Must be rendered inside a `BatchQueueProvider`.
|
|
288
285
|
*
|
|
289
286
|
* @param props.onSignAll - Called when the user clicks "Sign All". The
|
|
290
|
-
* implementor is responsible for resolving the
|
|
291
|
-
* `useBatchQueue().signAll(username)`.
|
|
287
|
+
* implementor is responsible for resolving the account identity and passing
|
|
288
|
+
* it to `useBatchQueue().signAll({ accountAddress, username })`.
|
|
292
289
|
*/
|
|
293
290
|
declare function BatchQueueWidget({ onSignAll }: BatchQueueWidgetProps): react_jsx_runtime.JSX.Element | null;
|
|
294
291
|
|
|
295
292
|
/**
|
|
296
293
|
* @file Chain and token registry for the 1auth SDK.
|
|
297
294
|
*
|
|
298
|
-
* Wraps `@rhinestone/
|
|
299
|
-
* definitions to expose a filtered, testnet-aware registry.
|
|
300
|
-
* look up supported chains and tokens, resolve token addresses
|
|
301
|
-
* retrieve chain metadata such as explorer URLs and default RPC
|
|
295
|
+
* Wraps `@rhinestone/shared-configs` chain/token data and combines it with
|
|
296
|
+
* viem's chain definitions to expose a filtered, testnet-aware registry.
|
|
297
|
+
* Consumers can look up supported chains and tokens, resolve token addresses
|
|
298
|
+
* by symbol, and retrieve chain metadata such as explorer URLs and default RPC
|
|
299
|
+
* endpoints.
|
|
302
300
|
*
|
|
303
301
|
* Testnet inclusion is controlled by the `includeTestnets` option on each
|
|
304
302
|
* function or, as a project-wide default, by the environment variables
|
|
@@ -309,8 +307,6 @@ type TokenConfig = {
|
|
|
309
307
|
symbol: string;
|
|
310
308
|
address: Address;
|
|
311
309
|
decimals: number;
|
|
312
|
-
supportsMultichain?: boolean;
|
|
313
|
-
[key: string]: unknown;
|
|
314
310
|
};
|
|
315
311
|
type ChainFilterOptions = {
|
|
316
312
|
includeTestnets?: boolean;
|
|
@@ -327,55 +323,11 @@ declare function getChainExplorerUrl(chainId: number): string | undefined;
|
|
|
327
323
|
declare function getChainRpcUrl(chainId: number): string | undefined;
|
|
328
324
|
declare function getSupportedTokens(chainId: number): TokenConfig[];
|
|
329
325
|
declare function getSupportedTokenSymbols(chainId: number): string[];
|
|
326
|
+
declare function getTokenAddress(symbolOrAddress: string, chainId: number): Address;
|
|
327
|
+
declare function getTokenDecimals(symbolOrAddress: string, chainId: number): number;
|
|
330
328
|
declare function resolveTokenAddress(token: string, chainId: number): Address;
|
|
331
329
|
declare function isTestnet(chainId: number): boolean;
|
|
332
330
|
declare function getTokenSymbol(tokenAddress: Address, chainId: number): string;
|
|
333
331
|
declare function isTokenAddressSupported(tokenAddress: Address, chainId: number): boolean;
|
|
334
332
|
|
|
335
|
-
|
|
336
|
-
* The EIP-191 prefix used for personal message signing.
|
|
337
|
-
* This is the standard Ethereum message prefix for `personal_sign`.
|
|
338
|
-
*/
|
|
339
|
-
declare const ETHEREUM_MESSAGE_PREFIX = "\u0019Ethereum Signed Message:\n";
|
|
340
|
-
/**
|
|
341
|
-
* Hash a message with the EIP-191 Ethereum prefix.
|
|
342
|
-
*
|
|
343
|
-
* This is the same hashing function used by the passkey sign dialog.
|
|
344
|
-
* Use this to verify that the `signedHash` returned from `signMessage()`
|
|
345
|
-
* matches your original message.
|
|
346
|
-
*
|
|
347
|
-
* Format: keccak256("\x19Ethereum Signed Message:\n" + len + message)
|
|
348
|
-
*
|
|
349
|
-
* @example
|
|
350
|
-
* ```typescript
|
|
351
|
-
* const message = "Sign in to MyApp\nTimestamp: 1234567890";
|
|
352
|
-
* const result = await client.signMessage({ username: 'alice', message });
|
|
353
|
-
*
|
|
354
|
-
* // Verify the hash matches
|
|
355
|
-
* const expectedHash = hashMessage(message);
|
|
356
|
-
* if (result.signedHash === expectedHash) {
|
|
357
|
-
* console.log('Hash matches - signature is for this message');
|
|
358
|
-
* }
|
|
359
|
-
* ```
|
|
360
|
-
*/
|
|
361
|
-
declare function hashMessage(message: string): `0x${string}`;
|
|
362
|
-
/**
|
|
363
|
-
* Verify that a signedHash matches the expected message.
|
|
364
|
-
*
|
|
365
|
-
* This is a convenience wrapper around `hashMessage()` that returns
|
|
366
|
-
* a boolean. For full cryptographic verification of the P256 signature,
|
|
367
|
-
* use on-chain verification via the WebAuthn.sol contract.
|
|
368
|
-
*
|
|
369
|
-
* @example
|
|
370
|
-
* ```typescript
|
|
371
|
-
* const result = await client.signMessage({ username: 'alice', message });
|
|
372
|
-
*
|
|
373
|
-
* if (result.success && verifyMessageHash(message, result.signedHash)) {
|
|
374
|
-
* // The signature is for this exact message
|
|
375
|
-
* // For full verification, verify the P256 signature on-chain or server-side
|
|
376
|
-
* }
|
|
377
|
-
* ```
|
|
378
|
-
*/
|
|
379
|
-
declare function verifyMessageHash(message: string, signedHash: string | undefined): boolean;
|
|
380
|
-
|
|
381
|
-
export { type BatchQueueContextValue, BatchQueueProvider, type BatchQueueProviderProps, BatchQueueWidget, type BatchQueueWidgetProps, type BatchedCall, type ChainFilterOptions, ETHEREUM_MESSAGE_PREFIX, IntentCall, OneAuthClient, type PasskeyAccount, type PasskeyWalletClient, type PasskeyWalletClientConfig, type SendCallsParams, SendIntentResult, type TokenConfig, type TransactionCall, WebAuthnSignature, createPasskeyAccount, createPasskeyWalletClient, encodeWebAuthnSignature, getAllSupportedChainsAndTokens, getChainById, getChainExplorerUrl, getChainName, getChainRpcUrl, getSupportedChainIds, getSupportedChains, getSupportedTokenSymbols, getSupportedTokens, getTokenSymbol, hashCalls, hashMessage, isTestnet, isTokenAddressSupported, resolveTokenAddress, useBatchQueue, verifyMessageHash };
|
|
333
|
+
export { type BatchQueueContextValue, type BatchQueueIdentity, BatchQueueProvider, type BatchQueueProviderProps, BatchQueueWidget, type BatchQueueWidgetProps, type BatchedCall, type ChainFilterOptions, type DefinePermissionsConfig, type DefinedPermissions, IntentCall, OneAuthClient, type PasskeyAccount, type PasskeyWalletClient, PasskeyWalletClientConfig, SendCallsParams, SendIntentResult, type TokenConfig, createPasskeyAccount, createPasskeyWalletClient, definePermissions, getAllSupportedChainsAndTokens, getChainById, getChainExplorerUrl, getChainName, getChainRpcUrl, getSupportedChainIds, getSupportedChains, getSupportedTokenSymbols, getSupportedTokens, getTokenAddress, getTokenDecimals, getTokenSymbol, isTestnet, isTokenAddressSupported, resolveTokenAddress, useBatchQueue };
|