@settlemint/dalp-sdk 3.1.33 → 3.2.0-rc.1
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/LICENSE +3 -157
- package/README.md +276 -169
- package/dist/auth/client.d.ts +114 -0
- package/dist/auth/invite-step-up.d.ts +2 -0
- package/dist/auth/live.d.ts +47 -0
- package/dist/auth/native-passkey.d.ts +8 -0
- package/dist/{auth-permissions.d.ts → auth/permissions.d.ts} +0 -8
- package/dist/auth/wallet-plugins.d.ts +196 -0
- package/dist/auth-surface.d.ts +2 -0
- package/dist/auth.d.ts +8 -115
- package/dist/auth.js +540 -0
- package/dist/chunk-6hckdbwt.js +600 -0
- package/dist/chunk-7mvx7xq8.js +4 -0
- package/dist/chunk-b03ycwb7.js +68 -0
- package/dist/chunk-crtb9edj.js +29 -0
- package/dist/chunk-g5j1xky8.js +99 -0
- package/dist/chunk-grdfnbwd.js +1529 -0
- package/dist/chunk-j43gfc9p.js +5 -0
- package/dist/chunk-k3ntysxx.js +57 -0
- package/dist/chunk-ptwkww6j.js +38 -0
- package/dist/chunk-qncpzave.js +185 -0
- package/dist/chunk-t8v94nvb.js +5 -0
- package/dist/chunk-xnarraj7.js +339 -0
- package/dist/client/conditional-request.d.ts +8 -0
- package/dist/client/factory.d.ts +4 -0
- package/dist/client/query-serializer.d.ts +1 -0
- package/dist/client/request-compression.d.ts +12 -0
- package/dist/client/ssr-fetch.d.ts +10 -0
- package/dist/client/step-up-challenge.d.ts +10 -0
- package/dist/effect.d.ts +39 -0
- package/dist/effect.js +110 -0
- package/dist/errors/api-error.d.ts +35 -0
- package/dist/errors/error-codes.d.ts +18 -0
- package/dist/errors/find-current-error.d.ts +2 -0
- package/dist/errors/public-error.d.ts +3 -0
- package/dist/errors/public-error.js +9 -0
- package/dist/errors/sdk-error.d.ts +52 -0
- package/dist/errors/sdk-error.js +8 -0
- package/dist/generated/api-types.d.ts +104535 -0
- package/dist/generated/api-types.ts +111921 -0
- package/dist/generated/console-routes.d.ts +12 -0
- package/dist/generated/error-catalog.d.ts +9 -0
- package/dist/generated/error-codes.d.ts +9 -0
- package/dist/generated/response-scalars.d.ts +9 -0
- package/dist/generated/response-schemas.d.ts +9 -0
- package/dist/generated/route-error-codes.d.ts +9 -0
- package/dist/generated/routes.d.ts +12 -0
- package/dist/index.d.ts +28 -45
- package/dist/index.js +159 -94522
- package/dist/proxy/builder.d.ts +17 -0
- package/dist/proxy/client-core.d.ts +36 -0
- package/dist/proxy/client.d.ts +5 -0
- package/dist/proxy/fetch-executor.d.ts +7 -0
- package/dist/proxy/flat-args.d.ts +24 -0
- package/dist/proxy/response-decode.d.ts +38 -0
- package/dist/proxy/sse.d.ts +11 -0
- package/dist/proxy/step-up-challenge.d.ts +4 -0
- package/dist/proxy/tanstack.d.ts +6 -0
- package/dist/proxy/transport.d.ts +76 -0
- package/dist/react-query.d.ts +2 -0
- package/dist/react-query.js +14 -0
- package/dist/routes/cli-command.d.ts +17 -0
- package/dist/routes/console.d.ts +14 -0
- package/dist/routes/console.js +27 -0
- package/dist/routes/index.d.ts +6 -0
- package/dist/routes/index.js +122 -0
- package/dist/routes/types.d.ts +73 -0
- package/dist/runtime-exports.d.ts +4 -0
- package/dist/runtime-exports.js +38 -0
- package/dist/runtime.d.ts +8 -0
- package/dist/scalars/big-decimal.d.ts +22 -0
- package/dist/scalars/big-int.d.ts +3 -0
- package/dist/scalars/dalp-scalars.d.ts +28 -0
- package/dist/scalars/ethereum-address.d.ts +3 -0
- package/dist/scalars/exchange-rates.d.ts +13 -0
- package/dist/scalars/index.d.ts +14 -0
- package/dist/scalars/index.js +236 -0
- package/dist/scalars/organization-id.d.ts +5 -0
- package/dist/scalars/token-decimals.d.ts +4 -0
- package/dist/secret.d.ts +12 -0
- package/dist/server-proxy.d.ts +39 -0
- package/dist/server-proxy.js +186 -0
- package/dist/sign-webhook-receipt.d.ts +16 -0
- package/dist/sign-webhook-receipt.js +26 -0
- package/dist/transport/cookie-store.d.ts +9 -0
- package/dist/transport/sse-lifecycle.d.ts +24 -0
- package/dist/types.d.ts +38 -114
- package/dist/url.d.ts +0 -1
- package/dist/verify-webhook.d.ts +18 -28
- package/dist/verify-webhook.js +8 -0
- package/dist/version.d.ts +0 -3
- package/dist/wait-for-transaction.d.ts +46 -86
- package/dist/wait-for-transaction.js +154 -0
- package/dist/webhook-events.d.ts +1360 -35
- package/package.json +176 -36
- package/dist/api-types.generated.d.ts +0 -14160
- package/dist/api-types.generated.d.ts.map +0 -1
- package/dist/auth-permissions.d.ts.map +0 -1
- package/dist/auth-wallet-plugins.d.ts +0 -86
- package/dist/auth-wallet-plugins.d.ts.map +0 -1
- package/dist/auth.d.ts.map +0 -1
- package/dist/bundler.d.ts +0 -217
- package/dist/bundler.d.ts.map +0 -1
- package/dist/client.d.ts +0 -19
- package/dist/client.d.ts.map +0 -1
- package/dist/contract-errors.d.ts +0 -4156
- package/dist/contract-errors.d.ts.map +0 -1
- package/dist/contract.d.ts +0 -22
- package/dist/contract.d.ts.map +0 -1
- package/dist/cookie-store.d.ts +0 -10
- package/dist/cookie-store.d.ts.map +0 -1
- package/dist/dapi-errors.d.ts +0 -656
- package/dist/dapi-errors.d.ts.map +0 -1
- package/dist/errors.d.ts +0 -639
- package/dist/errors.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/platform.d.ts +0 -41
- package/dist/platform.d.ts.map +0 -1
- package/dist/plugins/index.d.ts +0 -13
- package/dist/plugins/index.d.ts.map +0 -1
- package/dist/plugins/index.js +0 -8
- package/dist/sdk-error.d.ts +0 -74
- package/dist/sdk-error.d.ts.map +0 -1
- package/dist/serializers.d.ts +0 -41
- package/dist/serializers.d.ts.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/url.d.ts.map +0 -1
- package/dist/verify-webhook.d.ts.map +0 -1
- package/dist/version.d.ts.map +0 -1
- package/dist/version.generated.d.ts +0 -8
- package/dist/version.generated.d.ts.map +0 -1
- package/dist/wait-for-transaction.d.ts.map +0 -1
- package/dist/webhook-events.d.ts.map +0 -1
package/dist/auth.js
ADDED
|
@@ -0,0 +1,540 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createDalpSdkConfigurationError2
|
|
3
|
+
} from "./chunk-k3ntysxx.js";
|
|
4
|
+
import {
|
|
5
|
+
DALP_AUTH_SURFACE_HEADER2,
|
|
6
|
+
secret2,
|
|
7
|
+
unwrapSecret,
|
|
8
|
+
detectDalpRuntime,
|
|
9
|
+
refuseCrossOriginBrowserSession,
|
|
10
|
+
refuseBundledApiKey,
|
|
11
|
+
STEP_UP_CHALLENGE_HEADER,
|
|
12
|
+
STEP_UP_CHALLENGE_PATH,
|
|
13
|
+
carriesWalletProof,
|
|
14
|
+
stepUpChallengeRequest
|
|
15
|
+
} from "./chunk-6hckdbwt.js";
|
|
16
|
+
import {
|
|
17
|
+
makeCookieStore2,
|
|
18
|
+
createCookieStoreFetch2,
|
|
19
|
+
SDK_USER_AGENT2
|
|
20
|
+
} from "./chunk-xnarraj7.js";
|
|
21
|
+
import {
|
|
22
|
+
normalizeDalpBaseUrl
|
|
23
|
+
} from "./chunk-crtb9edj.js";
|
|
24
|
+
|
|
25
|
+
// src/auth/live.ts
|
|
26
|
+
import { apiKeyClient } from "@better-auth/api-key/client";
|
|
27
|
+
import { passkeyClient as passkeyClient2 } from "@better-auth/passkey/client";
|
|
28
|
+
import {
|
|
29
|
+
createAuthClient as createBetterAuthClient
|
|
30
|
+
} from "better-auth/client";
|
|
31
|
+
import {
|
|
32
|
+
adminClient,
|
|
33
|
+
customSessionClient,
|
|
34
|
+
deviceAuthorizationClient,
|
|
35
|
+
inferAdditionalFields,
|
|
36
|
+
organizationClient,
|
|
37
|
+
twoFactorClient
|
|
38
|
+
} from "better-auth/client/plugins";
|
|
39
|
+
|
|
40
|
+
// src/auth/client.ts
|
|
41
|
+
class AuthConfigError extends Error {
|
|
42
|
+
constructor(field, requirement) {
|
|
43
|
+
super(`\`${field}\` ${requirement}`);
|
|
44
|
+
this.name = "AuthConfigError";
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
function optionalText(value, field) {
|
|
48
|
+
if (value === undefined) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
if (typeof value !== "string") {
|
|
52
|
+
return handleNonString(field);
|
|
53
|
+
}
|
|
54
|
+
const trimmed = value.trim();
|
|
55
|
+
if (trimmed.length === 0) {
|
|
56
|
+
throw new AuthConfigError(field, "must not be blank");
|
|
57
|
+
}
|
|
58
|
+
return trimmed;
|
|
59
|
+
}
|
|
60
|
+
function handleNonString(field) {
|
|
61
|
+
throw new AuthConfigError(field, "must be a string");
|
|
62
|
+
}
|
|
63
|
+
function requiredUrl(value) {
|
|
64
|
+
if (typeof value !== "string") {
|
|
65
|
+
return handleNonString("url");
|
|
66
|
+
}
|
|
67
|
+
let parsed;
|
|
68
|
+
try {
|
|
69
|
+
parsed = new URL(value);
|
|
70
|
+
} catch {
|
|
71
|
+
throw new AuthConfigError("url", "must be a valid URL");
|
|
72
|
+
}
|
|
73
|
+
if (!["http:", "https:"].includes(parsed.protocol)) {
|
|
74
|
+
throw new AuthConfigError("url", "must use http or https");
|
|
75
|
+
}
|
|
76
|
+
return value;
|
|
77
|
+
}
|
|
78
|
+
function optionalHeaders(value) {
|
|
79
|
+
if (value === undefined) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
if (typeof value !== "object" || value === null || Array.isArray(value)) {
|
|
83
|
+
throw new AuthConfigError("headers", "must be an object of strings");
|
|
84
|
+
}
|
|
85
|
+
const headers = {};
|
|
86
|
+
for (const [name, header] of Object.entries(value)) {
|
|
87
|
+
if (typeof header !== "string") {
|
|
88
|
+
throw new AuthConfigError("headers", "must be an object of strings");
|
|
89
|
+
}
|
|
90
|
+
headers[name] = header;
|
|
91
|
+
}
|
|
92
|
+
return headers;
|
|
93
|
+
}
|
|
94
|
+
function optionalAuthSurface(value) {
|
|
95
|
+
if (value === undefined || value === "console" || value === "portal") {
|
|
96
|
+
return value;
|
|
97
|
+
}
|
|
98
|
+
throw new AuthConfigError("authSurface", 'must be "console" or "portal"');
|
|
99
|
+
}
|
|
100
|
+
function optionalFetch(value) {
|
|
101
|
+
if (value === undefined) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
if (typeof value !== "function") {
|
|
105
|
+
throw new AuthConfigError("fetch", "must be a function");
|
|
106
|
+
}
|
|
107
|
+
return value;
|
|
108
|
+
}
|
|
109
|
+
function optionalRuntime(value) {
|
|
110
|
+
if (value === undefined || value === "browser" || value === "server" || value === "react-native") {
|
|
111
|
+
return value;
|
|
112
|
+
}
|
|
113
|
+
throw new AuthConfigError("runtime", 'must be "browser", "server", or "react-native"');
|
|
114
|
+
}
|
|
115
|
+
function optionalPasskeyCeremony(value) {
|
|
116
|
+
if (value === undefined) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
if (typeof value !== "object" || value === null || typeof Reflect.get(value, "authenticate") !== "function" || typeof Reflect.get(value, "register") !== "function") {
|
|
120
|
+
throw new AuthConfigError("passkey", "must expose authenticate and register");
|
|
121
|
+
}
|
|
122
|
+
return value;
|
|
123
|
+
}
|
|
124
|
+
function optionalCookieStore(value) {
|
|
125
|
+
if (value === undefined) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const store = value;
|
|
129
|
+
if (typeof value !== "object" || value === null || typeof store.header !== "function" || typeof store.storeSetCookieHeaders !== "function") {
|
|
130
|
+
throw new AuthConfigError("cookieStore", "must expose header and storeSetCookieHeaders");
|
|
131
|
+
}
|
|
132
|
+
return store;
|
|
133
|
+
}
|
|
134
|
+
function decodeAuthConfig(input) {
|
|
135
|
+
const raw = input;
|
|
136
|
+
const apiKey = optionalText(raw.apiKey, "apiKey");
|
|
137
|
+
const cookie = optionalText(raw.cookie, "cookie");
|
|
138
|
+
if ([apiKey, cookie].filter((credential) => credential !== undefined).length > 1) {
|
|
139
|
+
throw new AuthConfigError("apiKey/cookie", "configure only one auth credential source");
|
|
140
|
+
}
|
|
141
|
+
const url = requiredUrl(raw.url);
|
|
142
|
+
const cookieStore = optionalCookieStore(raw.cookieStore);
|
|
143
|
+
const authSurface = optionalAuthSurface(raw.authSurface);
|
|
144
|
+
const headers = optionalHeaders(raw.headers);
|
|
145
|
+
const configuredFetch = optionalFetch(raw.fetch);
|
|
146
|
+
const runtime = optionalRuntime(raw.runtime);
|
|
147
|
+
const passkey = optionalPasskeyCeremony(raw.passkey);
|
|
148
|
+
return {
|
|
149
|
+
url,
|
|
150
|
+
...apiKey === undefined ? {} : { apiKey: secret2(apiKey) },
|
|
151
|
+
...cookie === undefined ? {} : { cookie: secret2(cookie) },
|
|
152
|
+
...cookieStore === undefined ? {} : { cookieStore },
|
|
153
|
+
...authSurface === undefined ? {} : { authSurface },
|
|
154
|
+
...headers === undefined ? {} : { headers },
|
|
155
|
+
...configuredFetch === undefined ? {} : { fetch: configuredFetch },
|
|
156
|
+
...runtime === undefined ? {} : { runtime },
|
|
157
|
+
...passkey === undefined ? {} : { passkey }
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
async function decodeDalpAuthClientConfig(input) {
|
|
161
|
+
try {
|
|
162
|
+
return decodeAuthConfig(input);
|
|
163
|
+
} catch (error) {
|
|
164
|
+
throw createDalpSdkConfigurationError2({
|
|
165
|
+
message: "DALP SDK: auth client configuration is invalid.",
|
|
166
|
+
why: "The auth client received a malformed URL, credential, header map, runtime, fetch seam, cookie store, or passkey ceremony.",
|
|
167
|
+
fix: "Pass one credential source, an HTTP(S) URL, a known runtime, and valid fetch, cookie-store, and passkey seams.",
|
|
168
|
+
cause: error
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
// src/auth/invite-step-up.ts
|
|
174
|
+
var INVITE_MEMBER_PATH = "/api/auth/organization/invite-member";
|
|
175
|
+
var INVITE_MEMBER_OPERATION = `POST ${INVITE_MEMBER_PATH}`;
|
|
176
|
+
function readChallengeId(payload) {
|
|
177
|
+
const data = payload !== null && typeof payload === "object" ? Reflect.get(payload, "data") : undefined;
|
|
178
|
+
const challengeId = data !== null && typeof data === "object" ? Reflect.get(data, "challengeId") : undefined;
|
|
179
|
+
return typeof challengeId === "string" ? challengeId : undefined;
|
|
180
|
+
}
|
|
181
|
+
function invitesWithWalletProof(input, init, baseUrl) {
|
|
182
|
+
const url = input instanceof Request ? input.url : String(input);
|
|
183
|
+
if ((init?.method ?? "GET").toUpperCase() !== "POST" || typeof init?.body !== "string" || new URL(url).pathname !== new URL(`${baseUrl}${INVITE_MEMBER_PATH}`).pathname) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
const body = JSON.parse(init.body);
|
|
187
|
+
return carriesWalletProof(body) ? body : undefined;
|
|
188
|
+
}
|
|
189
|
+
function withInviteStepUp(fetchImpl, baseUrl) {
|
|
190
|
+
return async (input, init) => {
|
|
191
|
+
const headers = new Headers(init?.headers);
|
|
192
|
+
const body = invitesWithWalletProof(input, init, baseUrl);
|
|
193
|
+
if (body === undefined || headers.has("x-api-key") || headers.has(STEP_UP_CHALLENGE_HEADER)) {
|
|
194
|
+
return fetchImpl(input, init);
|
|
195
|
+
}
|
|
196
|
+
const challengeHeaders = new Headers(headers);
|
|
197
|
+
challengeHeaders.set("Content-Type", "application/json");
|
|
198
|
+
const issued = await fetchImpl(`${baseUrl}${STEP_UP_CHALLENGE_PATH}`, {
|
|
199
|
+
method: "POST",
|
|
200
|
+
headers: challengeHeaders,
|
|
201
|
+
body: JSON.stringify(await stepUpChallengeRequest(INVITE_MEMBER_OPERATION, null, body)),
|
|
202
|
+
signal: init?.signal ?? null,
|
|
203
|
+
...init?.credentials === undefined ? {} : { credentials: init.credentials }
|
|
204
|
+
});
|
|
205
|
+
if (!issued.ok) {
|
|
206
|
+
return issued;
|
|
207
|
+
}
|
|
208
|
+
const challengeId = readChallengeId(await issued.json());
|
|
209
|
+
if (challengeId !== undefined) {
|
|
210
|
+
headers.set(STEP_UP_CHALLENGE_HEADER, challengeId);
|
|
211
|
+
}
|
|
212
|
+
return fetchImpl(input, { ...init, headers });
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// src/auth/native-passkey.ts
|
|
217
|
+
import {
|
|
218
|
+
passkeyClient
|
|
219
|
+
} from "@better-auth/passkey/client";
|
|
220
|
+
var ceremonyFailed = (code, error) => ({
|
|
221
|
+
data: null,
|
|
222
|
+
error: {
|
|
223
|
+
code,
|
|
224
|
+
message: error instanceof Error ? error.message : "The passkey ceremony did not complete.",
|
|
225
|
+
status: 400,
|
|
226
|
+
statusText: "BAD_REQUEST"
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
function withExtensions(options, extensions) {
|
|
230
|
+
return options.extensions === undefined && extensions === undefined ? options : { ...options, extensions: { ...options.extensions, ...extensions } };
|
|
231
|
+
}
|
|
232
|
+
function ceremonyPasskeyClient(ceremony) {
|
|
233
|
+
const plugin = passkeyClient();
|
|
234
|
+
return {
|
|
235
|
+
...plugin,
|
|
236
|
+
getActions: ($fetch, $store) => {
|
|
237
|
+
const signIn = async (opts, options) => {
|
|
238
|
+
const generated = await $fetch("/passkey/generate-authenticate-options", {
|
|
239
|
+
method: "GET",
|
|
240
|
+
throw: false
|
|
241
|
+
});
|
|
242
|
+
if (generated.data === null) {
|
|
243
|
+
return generated;
|
|
244
|
+
}
|
|
245
|
+
let response;
|
|
246
|
+
try {
|
|
247
|
+
response = await ceremony.authenticate(withExtensions(generated.data, opts?.extensions));
|
|
248
|
+
} catch (error) {
|
|
249
|
+
return ceremonyFailed("AUTH_CANCELLED", error);
|
|
250
|
+
}
|
|
251
|
+
const { clientExtensionResults, ...responseBody } = response;
|
|
252
|
+
try {
|
|
253
|
+
const verified = await $fetch("/passkey/verify-authentication", {
|
|
254
|
+
body: { response: responseBody },
|
|
255
|
+
...opts?.fetchOptions,
|
|
256
|
+
...options,
|
|
257
|
+
method: "POST",
|
|
258
|
+
throw: false
|
|
259
|
+
});
|
|
260
|
+
$store.notify("$listPasskeys");
|
|
261
|
+
$store.notify("$sessionSignal");
|
|
262
|
+
return opts?.returnWebAuthnResponse === true ? { ...verified, webauthn: { response, clientExtensionResults } } : verified;
|
|
263
|
+
} catch (error) {
|
|
264
|
+
return ceremonyFailed("AUTH_CANCELLED", error);
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
const addPasskey = async (opts, fetchOpts) => {
|
|
268
|
+
const generated = await $fetch("/passkey/generate-register-options", {
|
|
269
|
+
method: "GET",
|
|
270
|
+
query: {
|
|
271
|
+
...opts?.authenticatorAttachment === undefined ? {} : { authenticatorAttachment: opts.authenticatorAttachment },
|
|
272
|
+
...opts?.name === undefined || opts.name === "" ? {} : { name: opts.name },
|
|
273
|
+
...opts?.context === undefined || opts.context === null ? {} : { context: opts.context }
|
|
274
|
+
},
|
|
275
|
+
throw: false
|
|
276
|
+
});
|
|
277
|
+
if (generated.data === null) {
|
|
278
|
+
return generated;
|
|
279
|
+
}
|
|
280
|
+
let response;
|
|
281
|
+
try {
|
|
282
|
+
response = await ceremony.register(withExtensions(generated.data, opts?.extensions));
|
|
283
|
+
} catch (error) {
|
|
284
|
+
return ceremonyFailed("REGISTRATION_CANCELLED", error);
|
|
285
|
+
}
|
|
286
|
+
const { clientExtensionResults, ...responseBody } = response;
|
|
287
|
+
try {
|
|
288
|
+
const verified = await $fetch("/passkey/verify-registration", {
|
|
289
|
+
...opts?.fetchOptions,
|
|
290
|
+
...fetchOpts,
|
|
291
|
+
body: {
|
|
292
|
+
response: responseBody,
|
|
293
|
+
name: opts?.name,
|
|
294
|
+
...opts?.createSession === true ? { createSession: true } : {}
|
|
295
|
+
},
|
|
296
|
+
method: "POST",
|
|
297
|
+
throw: false
|
|
298
|
+
});
|
|
299
|
+
if (verified.data === null) {
|
|
300
|
+
return verified;
|
|
301
|
+
}
|
|
302
|
+
$store.notify("$listPasskeys");
|
|
303
|
+
if (verified.data.session !== undefined) {
|
|
304
|
+
$store.notify("$sessionSignal");
|
|
305
|
+
}
|
|
306
|
+
return opts?.returnWebAuthnResponse === true ? { ...verified, webauthn: { response, clientExtensionResults } } : verified;
|
|
307
|
+
} catch (error) {
|
|
308
|
+
return ceremonyFailed("UNKNOWN_ERROR", error);
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
return { signIn: { passkey: signIn }, passkey: { addPasskey }, $Infer: {} };
|
|
312
|
+
}
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// src/auth/permissions.ts
|
|
317
|
+
import { createAccessControl } from "better-auth/plugins/access";
|
|
318
|
+
import { adminAc, defaultStatements as adminDefaultStatements } from "better-auth/plugins/admin/access";
|
|
319
|
+
import {
|
|
320
|
+
memberAc,
|
|
321
|
+
defaultStatements as organizationDefaultStatements,
|
|
322
|
+
ownerAc
|
|
323
|
+
} from "better-auth/plugins/organization/access";
|
|
324
|
+
var dalPermissions = {
|
|
325
|
+
organization: ["update", "delete", "list"],
|
|
326
|
+
setting: ["read", "list", "upsert", "remove", "set-global-theme"],
|
|
327
|
+
system: ["read", "list", "create"],
|
|
328
|
+
exchangeRates: ["read", "list"],
|
|
329
|
+
corporateAction: ["approve"]
|
|
330
|
+
};
|
|
331
|
+
var customPermissions = {
|
|
332
|
+
...adminDefaultStatements,
|
|
333
|
+
...organizationDefaultStatements,
|
|
334
|
+
...dalPermissions
|
|
335
|
+
};
|
|
336
|
+
var narrowAccessControl = createAccessControl(customPermissions);
|
|
337
|
+
var accessControl = createAccessControl({
|
|
338
|
+
...adminDefaultStatements,
|
|
339
|
+
...organizationDefaultStatements,
|
|
340
|
+
...dalPermissions
|
|
341
|
+
});
|
|
342
|
+
var adminRole = narrowAccessControl.newRole({
|
|
343
|
+
...adminAc.statements,
|
|
344
|
+
...ownerAc.statements,
|
|
345
|
+
organization: ["update", "delete", "list"],
|
|
346
|
+
setting: ["read", "list", "upsert", "remove", "set-global-theme"],
|
|
347
|
+
system: ["read", "list", "create"],
|
|
348
|
+
exchangeRates: ["read", "list"],
|
|
349
|
+
corporateAction: ["approve"]
|
|
350
|
+
});
|
|
351
|
+
var ownerRole = narrowAccessControl.newRole({
|
|
352
|
+
...ownerAc.statements,
|
|
353
|
+
user: ["list", "get", "update"],
|
|
354
|
+
setting: ["read", "list", "upsert", "remove"],
|
|
355
|
+
system: ["read", "list", "create"],
|
|
356
|
+
exchangeRates: ["read", "list"],
|
|
357
|
+
corporateAction: ["approve"]
|
|
358
|
+
});
|
|
359
|
+
var memberRole = narrowAccessControl.newRole({
|
|
360
|
+
...memberAc.statements,
|
|
361
|
+
setting: ["read", "list"],
|
|
362
|
+
system: ["read", "list"],
|
|
363
|
+
exchangeRates: ["read", "list"]
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
// src/auth/wallet-plugins.ts
|
|
367
|
+
import { defineErrorCodes } from "better-auth";
|
|
368
|
+
var WALLET_VERIFICATION_ERROR_CODES = {
|
|
369
|
+
WALLET_VERIFICATION_INVALID_CODE: "Invalid wallet verification code",
|
|
370
|
+
WALLET_VERIFICATION_NOT_CONFIGURED: "The account holds no wallet verification method of that type",
|
|
371
|
+
WALLET_CREDENTIAL_LOCKED: "Wallet verification is locked after repeated failures. Retry after the wait.",
|
|
372
|
+
WALLET_VERIFICATION_UNAVAILABLE: "Wallet verification did not settle. Try again in a moment.",
|
|
373
|
+
WALLET_VERIFICATION_FACTOR_UNAVAILABLE: "The identity provider did not answer. Try again in a moment, or use another verification method."
|
|
374
|
+
};
|
|
375
|
+
var WALLET_PINCODE_ERROR_CODES = defineErrorCodes({
|
|
376
|
+
WALLET_PINCODE_ALREADY_SET: "Wallet pincode already set",
|
|
377
|
+
WALLET_PINCODE_ALREADY_REMOVED: "Wallet pincode already removed",
|
|
378
|
+
WALLET_PINCODE_PASSWORD_REQUIRED: "A current wallet verification code is required; the account password is not accepted",
|
|
379
|
+
WALLET_PINCODE_FRESH_SSO_REQUIRED: "Sign in through SSO again before recovering your wallet PIN",
|
|
380
|
+
WALLET_PINCODE_INVALID_RECOVERY_CODE: "Invalid recovery code",
|
|
381
|
+
WALLET_PINCODE_NO_RECOVERY_CODES_REMAINING: "No recovery codes remaining",
|
|
382
|
+
WALLET_PINCODE_RECOVERY_NOT_CONFIGURED: "Recovery codes are not configured",
|
|
383
|
+
WALLET_LAST_SIGNING_FACTOR: "Set up another way to approve transactions before you remove this one.",
|
|
384
|
+
...WALLET_VERIFICATION_ERROR_CODES
|
|
385
|
+
});
|
|
386
|
+
var WALLET_TWO_FACTOR_ERROR_CODES = defineErrorCodes({
|
|
387
|
+
WALLET_TWO_FACTOR_PASSWORD_REQUIRED: "A current wallet verification code is required; the account password is not accepted",
|
|
388
|
+
WALLET_TWO_FACTOR_INVALID_CODE: "Invalid two factor code",
|
|
389
|
+
WALLET_TWO_FACTOR_AUTHENTICATOR_PROOF_REQUIRED: "Changing or turning off the wallet authenticator needs a code from the authenticator or a recovery code",
|
|
390
|
+
WALLET_LAST_SIGNING_FACTOR: "Set up another way to approve transactions before you remove this one.",
|
|
391
|
+
...WALLET_VERIFICATION_ERROR_CODES
|
|
392
|
+
});
|
|
393
|
+
var WALLET_SECRET_CODES_ERROR_CODES = defineErrorCodes({
|
|
394
|
+
WALLET_SECRET_CODES_AUTHENTICATOR_PROOF_REQUIRED: "Regenerating recovery codes needs a code from the wallet authenticator or a recovery code",
|
|
395
|
+
WALLET_SECRET_CODES_PIN_PROOF_REQUIRED: "Regenerating recovery codes needs the wallet PIN or a recovery code",
|
|
396
|
+
WALLET_SECRET_CODES_VERIFICATION_MISMATCH: "Secret codes verification mismatch",
|
|
397
|
+
...WALLET_VERIFICATION_ERROR_CODES
|
|
398
|
+
});
|
|
399
|
+
var walletPincodeClient = () => ({
|
|
400
|
+
id: "wallet-pincode",
|
|
401
|
+
$InferServerPlugin: {
|
|
402
|
+
id: "wallet-pincode",
|
|
403
|
+
$ERROR_CODES: WALLET_PINCODE_ERROR_CODES,
|
|
404
|
+
endpoints: {}
|
|
405
|
+
},
|
|
406
|
+
$ERROR_CODES: WALLET_PINCODE_ERROR_CODES,
|
|
407
|
+
pathMethods: {
|
|
408
|
+
"/wallet/pincode/enable": "POST",
|
|
409
|
+
"/wallet/pincode/disable": "POST",
|
|
410
|
+
"/wallet/pincode/update": "POST",
|
|
411
|
+
"/wallet/pincode/recover": "POST",
|
|
412
|
+
"/wallet/pincode/reset": "POST"
|
|
413
|
+
},
|
|
414
|
+
atomListeners: [
|
|
415
|
+
{
|
|
416
|
+
matcher: (path) => path.startsWith("/wallet/pincode/"),
|
|
417
|
+
signal: "$sessionSignal"
|
|
418
|
+
}
|
|
419
|
+
]
|
|
420
|
+
});
|
|
421
|
+
var walletTwoFactorClient = () => ({
|
|
422
|
+
id: "wallet-two-factor",
|
|
423
|
+
$InferServerPlugin: {
|
|
424
|
+
id: "wallet-two-factor",
|
|
425
|
+
$ERROR_CODES: WALLET_TWO_FACTOR_ERROR_CODES,
|
|
426
|
+
endpoints: {}
|
|
427
|
+
},
|
|
428
|
+
$ERROR_CODES: WALLET_TWO_FACTOR_ERROR_CODES,
|
|
429
|
+
pathMethods: {
|
|
430
|
+
"/wallet/two-factor/enable": "POST",
|
|
431
|
+
"/wallet/two-factor/disable": "POST",
|
|
432
|
+
"/wallet/two-factor/verify": "POST"
|
|
433
|
+
},
|
|
434
|
+
atomListeners: [
|
|
435
|
+
{
|
|
436
|
+
matcher: (path) => path.startsWith("/wallet/two-factor/"),
|
|
437
|
+
signal: "$sessionSignal"
|
|
438
|
+
}
|
|
439
|
+
]
|
|
440
|
+
});
|
|
441
|
+
var walletSecretCodesClient = () => ({
|
|
442
|
+
id: "wallet-secret-codes",
|
|
443
|
+
$InferServerPlugin: {
|
|
444
|
+
id: "wallet-secret-codes",
|
|
445
|
+
$ERROR_CODES: WALLET_SECRET_CODES_ERROR_CODES,
|
|
446
|
+
endpoints: {}
|
|
447
|
+
},
|
|
448
|
+
$ERROR_CODES: WALLET_SECRET_CODES_ERROR_CODES,
|
|
449
|
+
pathMethods: {
|
|
450
|
+
"/wallet/secret-codes/generate": "POST",
|
|
451
|
+
"/wallet/secret-codes/confirm": "POST"
|
|
452
|
+
},
|
|
453
|
+
atomListeners: [
|
|
454
|
+
{
|
|
455
|
+
matcher: (path) => path.startsWith("/wallet/secret-codes/"),
|
|
456
|
+
signal: "$sessionSignal"
|
|
457
|
+
}
|
|
458
|
+
]
|
|
459
|
+
});
|
|
460
|
+
|
|
461
|
+
// src/auth/live.ts
|
|
462
|
+
var adminPluginOptions = {
|
|
463
|
+
ac: accessControl,
|
|
464
|
+
roles: { admin: adminRole, owner: ownerRole, member: memberRole }
|
|
465
|
+
};
|
|
466
|
+
var organizationPluginOptions = {
|
|
467
|
+
ac: accessControl,
|
|
468
|
+
roles: { owner: ownerRole, member: memberRole }
|
|
469
|
+
};
|
|
470
|
+
var reservedHeaders = new Set(["x-api-key", "authorization", "cookie"]);
|
|
471
|
+
function authHeaders(config, runtime, baseUrl) {
|
|
472
|
+
const headers = { "User-Agent": SDK_USER_AGENT2 };
|
|
473
|
+
if (runtime === "react-native") {
|
|
474
|
+
headers.origin = new URL(baseUrl).origin;
|
|
475
|
+
}
|
|
476
|
+
for (const [name, value] of Object.entries(config.headers ?? {})) {
|
|
477
|
+
if (!reservedHeaders.has(name.toLowerCase())) {
|
|
478
|
+
headers[name.toLowerCase() === "origin" ? "origin" : name] = value;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
if (config.apiKey !== undefined) {
|
|
482
|
+
headers["x-api-key"] = unwrapSecret(config.apiKey);
|
|
483
|
+
}
|
|
484
|
+
if (config.authSurface !== undefined) {
|
|
485
|
+
headers[DALP_AUTH_SURFACE_HEADER2] = config.authSurface;
|
|
486
|
+
}
|
|
487
|
+
return headers;
|
|
488
|
+
}
|
|
489
|
+
function createConfiguredBetterAuthClient(config, cookieStore) {
|
|
490
|
+
const plugins = [
|
|
491
|
+
customSessionClient(),
|
|
492
|
+
inferAdditionalFields(),
|
|
493
|
+
adminClient(adminPluginOptions),
|
|
494
|
+
apiKeyClient(),
|
|
495
|
+
config.passkey === undefined ? passkeyClient2() : ceremonyPasskeyClient(config.passkey),
|
|
496
|
+
walletPincodeClient(),
|
|
497
|
+
walletTwoFactorClient(),
|
|
498
|
+
walletSecretCodesClient(),
|
|
499
|
+
twoFactorClient({ onTwoFactorRedirect() {} }),
|
|
500
|
+
deviceAuthorizationClient(),
|
|
501
|
+
organizationClient(organizationPluginOptions)
|
|
502
|
+
];
|
|
503
|
+
const baseUrl = normalizeDalpBaseUrl(config.url);
|
|
504
|
+
const runtime = config.runtime ?? detectDalpRuntime();
|
|
505
|
+
refuseCrossOriginBrowserSession(runtime, baseUrl, config.apiKey !== undefined);
|
|
506
|
+
if (config.apiKey !== undefined) {
|
|
507
|
+
refuseBundledApiKey(runtime);
|
|
508
|
+
}
|
|
509
|
+
return createBetterAuthClient({
|
|
510
|
+
baseURL: `${baseUrl}/api/auth`,
|
|
511
|
+
fetchOptions: {
|
|
512
|
+
headers: authHeaders(config, runtime, baseUrl),
|
|
513
|
+
customFetchImpl: withInviteStepUp(createCookieStoreFetch2(cookieStore, config.fetch), baseUrl),
|
|
514
|
+
credentials: runtime === "react-native" ? "omit" : "include"
|
|
515
|
+
},
|
|
516
|
+
plugins
|
|
517
|
+
});
|
|
518
|
+
}
|
|
519
|
+
async function createDalpAuthClient(input) {
|
|
520
|
+
const config = await decodeDalpAuthClientConfig(input);
|
|
521
|
+
const cookieStore = config.cookieStore ?? makeCookieStore2();
|
|
522
|
+
if (config.cookie !== undefined) {
|
|
523
|
+
cookieStore.setCookieHeader(unwrapSecret(config.cookie));
|
|
524
|
+
}
|
|
525
|
+
const credentialCount = [config.apiKey, cookieStore.isEmpty() ? undefined : true].filter(Boolean).length;
|
|
526
|
+
if (credentialCount > 1) {
|
|
527
|
+
throw createDalpSdkConfigurationError2({
|
|
528
|
+
message: "DALP SDK: configure only one auth credential source.",
|
|
529
|
+
why: "The auth client received multiple credential types.",
|
|
530
|
+
fix: "Use an API key or a cookie store, not both."
|
|
531
|
+
});
|
|
532
|
+
}
|
|
533
|
+
return createConfiguredBetterAuthClient(config, cookieStore);
|
|
534
|
+
}
|
|
535
|
+
var makeDalpAuthClient = createDalpAuthClient;
|
|
536
|
+
export {
|
|
537
|
+
createDalpAuthClient,
|
|
538
|
+
decodeDalpAuthClientConfig,
|
|
539
|
+
makeDalpAuthClient
|
|
540
|
+
};
|