@opendatalabs/vana-sdk 3.0.1 → 3.2.0-canary.88d802d
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 +2 -1
- package/dist/__tests__/interop-personal-server.test.d.ts +1 -0
- package/dist/account/personal-server-lite-owner-binding.cjs +81 -0
- package/dist/account/personal-server-lite-owner-binding.cjs.map +1 -0
- package/dist/account/personal-server-lite-owner-binding.d.ts +30 -0
- package/dist/account/personal-server-lite-owner-binding.js +59 -0
- package/dist/account/personal-server-lite-owner-binding.js.map +1 -0
- package/dist/account/personal-server-lite-owner-binding.test.d.ts +1 -0
- package/dist/account/personal-server-registration.cjs +263 -0
- package/dist/account/personal-server-registration.cjs.map +1 -0
- package/dist/account/personal-server-registration.d.ts +66 -0
- package/dist/account/personal-server-registration.js +240 -0
- package/dist/account/personal-server-registration.js.map +1 -0
- package/dist/account/personal-server-registration.test.d.ts +1 -0
- package/dist/auth/errors.js +1 -1
- package/dist/auth/oauth-client.cjs +250 -0
- package/dist/auth/oauth-client.cjs.map +1 -0
- package/dist/auth/oauth-client.d.ts +90 -0
- package/dist/auth/oauth-client.js +228 -0
- package/dist/auth/oauth-client.js.map +1 -0
- package/dist/auth/oauth-client.test.d.ts +1 -0
- package/dist/auth/web3-signed-builder.js +1 -1
- package/dist/auth/web3-signed.js +3 -3
- package/dist/browser.js +1 -1
- package/dist/chains/definitions.js +1 -1
- package/dist/chains/index.js +1 -1
- package/dist/chains.browser.js +1 -1
- package/dist/chains.js +1 -1
- package/dist/chains.node.js +1 -1
- package/dist/contracts/contractController.js +4 -4
- package/dist/core/client.js +1 -1
- package/dist/crypto/ecies/base.js +3 -3
- package/dist/crypto/ecies/browser.js +1 -1
- package/dist/crypto/ecies/index.js +1 -1
- package/dist/crypto/ecies/interface.js +1 -1
- package/dist/crypto/ecies/node.js +1 -1
- package/dist/crypto/services/WalletKeyEncryptionService.js +1 -1
- package/dist/generated/abi/index.js +26 -26
- package/dist/index.browser.d.ts +9 -3
- package/dist/index.browser.js +930 -73
- package/dist/index.browser.js.map +4 -4
- package/dist/index.node.cjs +958 -74
- package/dist/index.node.cjs.map +4 -4
- package/dist/index.node.d.ts +9 -3
- package/dist/index.node.js +930 -73
- package/dist/index.node.js.map +4 -4
- package/dist/node.js +1 -1
- package/dist/platform/browser-only.js +1 -1
- package/dist/platform/browser-safe.js +1 -1
- package/dist/platform/browser.js +6 -6
- package/dist/platform/index.js +4 -4
- package/dist/platform/node.js +8 -8
- package/dist/platform/utils.js +2 -2
- package/dist/platform.browser.js +3 -3
- package/dist/platform.js +4 -4
- package/dist/platform.node.js +4 -4
- package/dist/protocol/eip712.cjs +58 -3
- package/dist/protocol/eip712.cjs.map +1 -1
- package/dist/protocol/eip712.d.ts +98 -7
- package/dist/protocol/eip712.js +52 -3
- package/dist/protocol/eip712.js.map +1 -1
- package/dist/protocol/escrow-deposit.cjs +89 -0
- package/dist/protocol/escrow-deposit.cjs.map +1 -0
- package/dist/protocol/escrow-deposit.d.ts +47 -0
- package/dist/protocol/escrow-deposit.js +60 -0
- package/dist/protocol/escrow-deposit.js.map +1 -0
- package/dist/protocol/escrow-deposit.test.d.ts +1 -0
- package/dist/protocol/escrow-flow.test.d.ts +21 -0
- package/dist/protocol/gateway.cjs +124 -3
- package/dist/protocol/gateway.cjs.map +1 -1
- package/dist/protocol/gateway.d.ts +196 -16
- package/dist/protocol/gateway.js +124 -3
- package/dist/protocol/gateway.js.map +1 -1
- package/dist/protocol/grants.cjs +24 -64
- package/dist/protocol/grants.cjs.map +1 -1
- package/dist/protocol/grants.d.ts +6 -13
- package/dist/protocol/grants.js +25 -64
- package/dist/protocol/grants.js.map +1 -1
- package/dist/protocol/personal-server-lite-owner-binding.cjs +93 -0
- package/dist/protocol/personal-server-lite-owner-binding.cjs.map +1 -0
- package/dist/protocol/personal-server-lite-owner-binding.d.ts +44 -0
- package/dist/protocol/personal-server-lite-owner-binding.js +65 -0
- package/dist/protocol/personal-server-lite-owner-binding.js.map +1 -0
- package/dist/protocol/personal-server-lite-owner-binding.test.d.ts +1 -0
- package/dist/protocol/personal-server-registration.cjs +122 -0
- package/dist/protocol/personal-server-registration.cjs.map +1 -0
- package/dist/protocol/personal-server-registration.d.ts +62 -0
- package/dist/protocol/personal-server-registration.js +97 -0
- package/dist/protocol/personal-server-registration.js.map +1 -0
- package/dist/protocol/personal-server-registration.test.d.ts +1 -0
- package/dist/storage/default.js +1 -1
- package/dist/storage/index.cjs.map +1 -1
- package/dist/storage/index.d.ts +1 -1
- package/dist/storage/index.js +10 -10
- package/dist/storage/index.js.map +1 -1
- package/dist/storage/manager.js +1 -1
- package/dist/storage/providers/callback-storage.js +1 -1
- package/dist/storage/providers/dropbox.js +1 -1
- package/dist/storage/providers/google-drive.js +1 -1
- package/dist/storage/providers/ipfs.js +2 -2
- package/dist/storage/providers/pinata.js +1 -1
- package/dist/storage/providers/r2.js +1 -1
- package/dist/storage/providers/vana-storage.cjs +1 -1
- package/dist/storage/providers/vana-storage.cjs.map +1 -1
- package/dist/storage/providers/vana-storage.d.ts +2 -2
- package/dist/storage/providers/vana-storage.js +3 -3
- package/dist/storage/providers/vana-storage.js.map +1 -1
- package/dist/types/index.js +2 -2
- package/dist/types.js +1 -1
- package/package.json +7 -3
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
import { computePkceChallenge, generatePkceVerifier } from "./pkce.js";
|
|
2
|
+
import {
|
|
3
|
+
InMemoryTokenStore
|
|
4
|
+
} from "./token-store.js";
|
|
5
|
+
const VERIFIER_TTL_SECONDS = 600;
|
|
6
|
+
const RESERVED_AUTHORIZE_PARAMS = /* @__PURE__ */ new Set([
|
|
7
|
+
"response_type",
|
|
8
|
+
"client_id",
|
|
9
|
+
"redirect_uri",
|
|
10
|
+
"scope",
|
|
11
|
+
"state",
|
|
12
|
+
"code_challenge",
|
|
13
|
+
"code_challenge_method"
|
|
14
|
+
]);
|
|
15
|
+
class OAuthClient {
|
|
16
|
+
#config;
|
|
17
|
+
constructor(config) {
|
|
18
|
+
const fetchImpl = config.fetchImpl ?? globalThis.fetch;
|
|
19
|
+
if (typeof fetchImpl !== "function") {
|
|
20
|
+
throw new TypeError(
|
|
21
|
+
"OAuthClient requires a global `fetch` or an explicit `fetchImpl`"
|
|
22
|
+
);
|
|
23
|
+
}
|
|
24
|
+
this.#config = {
|
|
25
|
+
authorizationEndpoint: config.authorizationEndpoint,
|
|
26
|
+
tokenEndpoint: config.tokenEndpoint,
|
|
27
|
+
clientId: config.clientId,
|
|
28
|
+
redirectUri: config.redirectUri,
|
|
29
|
+
scope: config.scope,
|
|
30
|
+
tokenStore: config.tokenStore ?? new InMemoryTokenStore(),
|
|
31
|
+
fetchImpl,
|
|
32
|
+
generateState: config.generateState ?? defaultGenerateState
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/** Build the authorize URL and persist the PKCE verifier keyed by `state`. */
|
|
36
|
+
async buildAuthorizationUrl(opts = {}) {
|
|
37
|
+
const state = opts.state ?? this.#config.generateState();
|
|
38
|
+
const scope = opts.scope ?? this.#config.scope;
|
|
39
|
+
const verifier = generatePkceVerifier();
|
|
40
|
+
const challenge = await computePkceChallenge(verifier);
|
|
41
|
+
await this.#config.tokenStore.set(this.#verifierKey(state), {
|
|
42
|
+
token: verifier,
|
|
43
|
+
expiresAt: Math.floor(Date.now() / 1e3) + VERIFIER_TTL_SECONDS
|
|
44
|
+
});
|
|
45
|
+
const params = new URLSearchParams();
|
|
46
|
+
params.set("response_type", "code");
|
|
47
|
+
params.set("client_id", this.#config.clientId);
|
|
48
|
+
params.set("redirect_uri", this.#config.redirectUri);
|
|
49
|
+
if (scope !== void 0 && scope.length > 0) {
|
|
50
|
+
params.set("scope", scope);
|
|
51
|
+
}
|
|
52
|
+
params.set("state", state);
|
|
53
|
+
params.set("code_challenge", challenge);
|
|
54
|
+
params.set("code_challenge_method", "S256");
|
|
55
|
+
if (opts.extraParams !== void 0) {
|
|
56
|
+
for (const k of Object.keys(opts.extraParams)) {
|
|
57
|
+
if (RESERVED_AUTHORIZE_PARAMS.has(k)) {
|
|
58
|
+
throw new Error(
|
|
59
|
+
`extraParams may not override the reserved OAuth/PKCE parameter "${k}"`
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
for (const [k, v] of Object.entries(opts.extraParams)) {
|
|
64
|
+
params.set(k, v);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
const sep = this.#config.authorizationEndpoint.includes("?") ? "&" : "?";
|
|
68
|
+
const url = `${this.#config.authorizationEndpoint}${sep}${params.toString()}`;
|
|
69
|
+
return { url, state };
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Handle the redirect-callback URL. Validates `state`, retrieves the saved
|
|
73
|
+
* verifier, exchanges the authorization code + verifier for tokens, and
|
|
74
|
+
* persists them. Returns the access {@link TokenRecord}.
|
|
75
|
+
*/
|
|
76
|
+
async handleCallback(callbackUrl) {
|
|
77
|
+
const parsed = new URL(callbackUrl);
|
|
78
|
+
const params = parsed.searchParams;
|
|
79
|
+
const errorCode = params.get("error");
|
|
80
|
+
if (errorCode !== null) {
|
|
81
|
+
throw new Error(
|
|
82
|
+
formatOAuthError({
|
|
83
|
+
error: errorCode,
|
|
84
|
+
error_description: params.get("error_description") ?? void 0
|
|
85
|
+
})
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
const code = params.get("code");
|
|
89
|
+
const state = params.get("state");
|
|
90
|
+
if (code === null || state === null) {
|
|
91
|
+
throw new Error("OAuth callback is missing `code` or `state`");
|
|
92
|
+
}
|
|
93
|
+
const verifierRecord = await this.#config.tokenStore.get(
|
|
94
|
+
this.#verifierKey(state)
|
|
95
|
+
);
|
|
96
|
+
if (verifierRecord === null) {
|
|
97
|
+
throw new Error(
|
|
98
|
+
"OAuth callback state does not match any in-flight verifier (possible CSRF or expired flow)"
|
|
99
|
+
);
|
|
100
|
+
}
|
|
101
|
+
const body = new URLSearchParams();
|
|
102
|
+
body.set("grant_type", "authorization_code");
|
|
103
|
+
body.set("code", code);
|
|
104
|
+
body.set("redirect_uri", this.#config.redirectUri);
|
|
105
|
+
body.set("client_id", this.#config.clientId);
|
|
106
|
+
body.set("code_verifier", verifierRecord.token);
|
|
107
|
+
let tokens;
|
|
108
|
+
try {
|
|
109
|
+
tokens = await this.#tokenRequest(body);
|
|
110
|
+
} finally {
|
|
111
|
+
await this.#config.tokenStore.delete(this.#verifierKey(state));
|
|
112
|
+
}
|
|
113
|
+
return this.#persistTokens(tokens);
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* Exchange a stored refresh token for a fresh access token. Throws if no
|
|
117
|
+
* refresh token is available.
|
|
118
|
+
*/
|
|
119
|
+
async refresh() {
|
|
120
|
+
const refreshRecord = await this.#config.tokenStore.get(this.#refreshKey());
|
|
121
|
+
if (refreshRecord === null) {
|
|
122
|
+
throw new Error("OAuth refresh failed: no refresh token stored");
|
|
123
|
+
}
|
|
124
|
+
const body = new URLSearchParams();
|
|
125
|
+
body.set("grant_type", "refresh_token");
|
|
126
|
+
body.set("refresh_token", refreshRecord.token);
|
|
127
|
+
body.set("client_id", this.#config.clientId);
|
|
128
|
+
const tokens = await this.#tokenRequest(body);
|
|
129
|
+
return this.#persistTokens(tokens, refreshRecord.token);
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Get the current access token if valid (refreshing first if expired and a
|
|
133
|
+
* refresh token is available). Returns `null` when no usable token exists.
|
|
134
|
+
*/
|
|
135
|
+
async getAccessToken() {
|
|
136
|
+
const stored = await this.#config.tokenStore.get(this.#accessKey());
|
|
137
|
+
if (stored !== null) return stored.token;
|
|
138
|
+
const refresh = await this.#config.tokenStore.get(this.#refreshKey());
|
|
139
|
+
if (refresh === null) return null;
|
|
140
|
+
try {
|
|
141
|
+
const refreshed = await this.refresh();
|
|
142
|
+
return refreshed.token;
|
|
143
|
+
} catch {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
/** Forget tokens (logout). Does NOT call any remote revocation endpoint. */
|
|
148
|
+
async signOut() {
|
|
149
|
+
await this.#config.tokenStore.delete(this.#accessKey());
|
|
150
|
+
await this.#config.tokenStore.delete(this.#refreshKey());
|
|
151
|
+
}
|
|
152
|
+
#accessKey() {
|
|
153
|
+
return `oauth:tokens:${this.#config.clientId}`;
|
|
154
|
+
}
|
|
155
|
+
#refreshKey() {
|
|
156
|
+
return `oauth:refresh:${this.#config.clientId}`;
|
|
157
|
+
}
|
|
158
|
+
#verifierKey(state) {
|
|
159
|
+
return `oauth:verifier:${state}`;
|
|
160
|
+
}
|
|
161
|
+
async #tokenRequest(body) {
|
|
162
|
+
const response = await this.#config.fetchImpl(this.#config.tokenEndpoint, {
|
|
163
|
+
method: "POST",
|
|
164
|
+
headers: {
|
|
165
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
166
|
+
Accept: "application/json"
|
|
167
|
+
},
|
|
168
|
+
body: body.toString()
|
|
169
|
+
});
|
|
170
|
+
const text = await response.text();
|
|
171
|
+
const parsed = parseJsonBody(text);
|
|
172
|
+
if (!response.ok) {
|
|
173
|
+
throw new Error(formatOAuthError(parsed ?? {}, response.status));
|
|
174
|
+
}
|
|
175
|
+
if (parsed === null || typeof parsed !== "object" || typeof parsed.access_token !== "string") {
|
|
176
|
+
throw new Error(
|
|
177
|
+
"OAuth token endpoint returned a response without an `access_token` string"
|
|
178
|
+
);
|
|
179
|
+
}
|
|
180
|
+
return parsed;
|
|
181
|
+
}
|
|
182
|
+
async #persistTokens(tokens, previousRefreshToken) {
|
|
183
|
+
const record = { token: tokens.access_token };
|
|
184
|
+
if (typeof tokens.expires_in === "number" && tokens.expires_in > 0) {
|
|
185
|
+
record.expiresAt = Math.floor(Date.now() / 1e3) + tokens.expires_in;
|
|
186
|
+
}
|
|
187
|
+
await this.#config.tokenStore.set(this.#accessKey(), record);
|
|
188
|
+
const newRefresh = tokens.refresh_token ?? previousRefreshToken;
|
|
189
|
+
if (newRefresh !== void 0) {
|
|
190
|
+
await this.#config.tokenStore.set(this.#refreshKey(), {
|
|
191
|
+
token: newRefresh
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
return record;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
function defaultGenerateState() {
|
|
198
|
+
const bytes = new Uint8Array(24);
|
|
199
|
+
crypto.getRandomValues(bytes);
|
|
200
|
+
let binary = "";
|
|
201
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
202
|
+
binary += String.fromCharCode(bytes[i]);
|
|
203
|
+
}
|
|
204
|
+
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
205
|
+
}
|
|
206
|
+
function parseJsonBody(text) {
|
|
207
|
+
if (text.length === 0) return null;
|
|
208
|
+
try {
|
|
209
|
+
return JSON.parse(text);
|
|
210
|
+
} catch {
|
|
211
|
+
return null;
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
function formatOAuthError(body, status) {
|
|
215
|
+
const parts = ["OAuth token request failed"];
|
|
216
|
+
if (status !== void 0) parts.push(`(HTTP ${String(status)})`);
|
|
217
|
+
if (body.error !== void 0 && body.error.length > 0) {
|
|
218
|
+
parts.push(`: ${body.error}`);
|
|
219
|
+
if (body.error_description !== void 0 && body.error_description.length > 0) {
|
|
220
|
+
parts.push(`- ${body.error_description}`);
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
return parts.join(" ").replace(" : ", ": ").replace(" - ", " - ");
|
|
224
|
+
}
|
|
225
|
+
export {
|
|
226
|
+
OAuthClient
|
|
227
|
+
};
|
|
228
|
+
//# sourceMappingURL=oauth-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/auth/oauth-client.ts"],"sourcesContent":["/**\n * OAuth 2.0 Authorization Code + PKCE client orchestration.\n *\n * @remarks\n * Drives the full authorize → callback → token-exchange → refresh dance on top\n * of the {@link TokenStore} and PKCE primitives that ship with this package.\n * Implements RFC 6749 §4.1 with the RFC 7636 PKCE extension (S256 only).\n *\n * @category Auth\n * @module auth/oauth-client\n */\n\nimport { computePkceChallenge, generatePkceVerifier } from \"./pkce\";\nimport {\n InMemoryTokenStore,\n type TokenRecord,\n type TokenStore,\n} from \"./token-store\";\n\n/**\n * Constructor options for {@link OAuthClient}.\n */\nexport interface OAuthClientConfig {\n /** Authorization endpoint, e.g. `https://account.vana.org/oauth/authorize`. */\n authorizationEndpoint: string;\n /** Token endpoint, e.g. `https://account.vana.org/oauth/token`. */\n tokenEndpoint: string;\n /** OAuth `client_id` (public; PKCE protects the flow). */\n clientId: string;\n /** Redirect URI registered with the authorization server. */\n redirectUri: string;\n /** Default scope; can be overridden per call. */\n scope?: string;\n /**\n * Where to persist access + refresh tokens and the in-flight code verifier\n * between `authorize` → `callback`. Defaults to a fresh\n * {@link InMemoryTokenStore}. Use IndexedDB/localStorage-backed\n * implementations for browser apps where the user navigates away during the\n * dance.\n */\n tokenStore?: TokenStore;\n /** Override the global `fetch` (e.g. for tests). Defaults to `globalThis.fetch`. */\n fetchImpl?: typeof fetch;\n /**\n * Override the random-state generator (mostly for tests). Must return a\n * URL-safe string of >= 16 bytes of entropy.\n */\n generateState?: () => string;\n}\n\n/**\n * Result of {@link OAuthClient.buildAuthorizationUrl}.\n */\nexport interface AuthorizationUrlResult {\n /** The full authorize URL to redirect / `window.open` to. */\n url: string;\n /** The `state` value the auth server will echo back; used for CSRF check. */\n state: string;\n}\n\n/** TTL for the in-flight verifier record (seconds). */\nconst VERIFIER_TTL_SECONDS = 600;\n\n/** RFC 6749 spec-compliant OAuth error payload shape. */\ninterface OAuthErrorBody {\n error?: string;\n error_description?: string;\n error_uri?: string;\n}\n\n/** Successful token-endpoint response shape (RFC 6749 §5.1). */\ninterface TokenEndpointResponse {\n access_token: string;\n token_type?: string;\n expires_in?: number;\n refresh_token?: string;\n scope?: string;\n}\n\n/**\n * Authorize-URL parameters the client owns. Callers may NOT supply these\n * via `extraParams` — otherwise PKCE/CSRF protection can be silently\n * bypassed (e.g. `extraParams: { state: \"x\" }` would store the verifier\n * under the generated state but send `x` on the wire, breaking the\n * callback CSRF check; `code_challenge_method` could downgrade S256).\n */\nconst RESERVED_AUTHORIZE_PARAMS = new Set([\n \"response_type\",\n \"client_id\",\n \"redirect_uri\",\n \"scope\",\n \"state\",\n \"code_challenge\",\n \"code_challenge_method\",\n]);\n\n/**\n * OAuth 2.0 Authorization Code + PKCE client.\n *\n * @remarks\n * Storage layout under the supplied {@link TokenStore} (all keys namespaced):\n * - `oauth:tokens:{clientId}` → access token record\n * - `oauth:refresh:{clientId}` → refresh token record (no expiry)\n * - `oauth:verifier:{state}` → in-flight PKCE verifier (10 min TTL)\n *\n * @category Auth\n */\nexport class OAuthClient {\n readonly #config: Required<\n Omit<\n OAuthClientConfig,\n \"scope\" | \"tokenStore\" | \"fetchImpl\" | \"generateState\"\n >\n > & {\n scope?: string;\n tokenStore: TokenStore;\n fetchImpl: typeof fetch;\n generateState: () => string;\n };\n\n public constructor(config: OAuthClientConfig) {\n const fetchImpl = config.fetchImpl ?? globalThis.fetch;\n if (typeof fetchImpl !== \"function\") {\n throw new TypeError(\n \"OAuthClient requires a global `fetch` or an explicit `fetchImpl`\",\n );\n }\n\n this.#config = {\n authorizationEndpoint: config.authorizationEndpoint,\n tokenEndpoint: config.tokenEndpoint,\n clientId: config.clientId,\n redirectUri: config.redirectUri,\n scope: config.scope,\n tokenStore: config.tokenStore ?? new InMemoryTokenStore(),\n fetchImpl,\n generateState: config.generateState ?? defaultGenerateState,\n };\n }\n\n /** Build the authorize URL and persist the PKCE verifier keyed by `state`. */\n public async buildAuthorizationUrl(\n opts: {\n state?: string;\n scope?: string;\n extraParams?: Record<string, string>;\n } = {},\n ): Promise<AuthorizationUrlResult> {\n const state = opts.state ?? this.#config.generateState();\n const scope = opts.scope ?? this.#config.scope;\n\n const verifier = generatePkceVerifier();\n const challenge = await computePkceChallenge(verifier);\n\n await this.#config.tokenStore.set(this.#verifierKey(state), {\n token: verifier,\n expiresAt: Math.floor(Date.now() / 1000) + VERIFIER_TTL_SECONDS,\n });\n\n const params = new URLSearchParams();\n params.set(\"response_type\", \"code\");\n params.set(\"client_id\", this.#config.clientId);\n params.set(\"redirect_uri\", this.#config.redirectUri);\n if (scope !== undefined && scope.length > 0) {\n params.set(\"scope\", scope);\n }\n params.set(\"state\", state);\n params.set(\"code_challenge\", challenge);\n params.set(\"code_challenge_method\", \"S256\");\n if (opts.extraParams !== undefined) {\n for (const k of Object.keys(opts.extraParams)) {\n if (RESERVED_AUTHORIZE_PARAMS.has(k)) {\n throw new Error(\n `extraParams may not override the reserved OAuth/PKCE parameter \"${k}\"`,\n );\n }\n }\n for (const [k, v] of Object.entries(opts.extraParams)) {\n params.set(k, v);\n }\n }\n\n const sep = this.#config.authorizationEndpoint.includes(\"?\") ? \"&\" : \"?\";\n const url = `${this.#config.authorizationEndpoint}${sep}${params.toString()}`;\n\n return { url, state };\n }\n\n /**\n * Handle the redirect-callback URL. Validates `state`, retrieves the saved\n * verifier, exchanges the authorization code + verifier for tokens, and\n * persists them. Returns the access {@link TokenRecord}.\n */\n public async handleCallback(callbackUrl: string): Promise<TokenRecord> {\n const parsed = new URL(callbackUrl);\n const params = parsed.searchParams;\n\n const errorCode = params.get(\"error\");\n if (errorCode !== null) {\n throw new Error(\n formatOAuthError({\n error: errorCode,\n error_description: params.get(\"error_description\") ?? undefined,\n }),\n );\n }\n\n const code = params.get(\"code\");\n const state = params.get(\"state\");\n if (code === null || state === null) {\n throw new Error(\"OAuth callback is missing `code` or `state`\");\n }\n\n const verifierRecord = await this.#config.tokenStore.get(\n this.#verifierKey(state),\n );\n if (verifierRecord === null) {\n throw new Error(\n \"OAuth callback state does not match any in-flight verifier (possible CSRF or expired flow)\",\n );\n }\n\n const body = new URLSearchParams();\n body.set(\"grant_type\", \"authorization_code\");\n body.set(\"code\", code);\n body.set(\"redirect_uri\", this.#config.redirectUri);\n body.set(\"client_id\", this.#config.clientId);\n body.set(\"code_verifier\", verifierRecord.token);\n\n let tokens: TokenEndpointResponse;\n try {\n tokens = await this.#tokenRequest(body);\n } finally {\n // Always clear the one-shot verifier, even on a failed exchange.\n await this.#config.tokenStore.delete(this.#verifierKey(state));\n }\n\n return this.#persistTokens(tokens);\n }\n\n /**\n * Exchange a stored refresh token for a fresh access token. Throws if no\n * refresh token is available.\n */\n public async refresh(): Promise<TokenRecord> {\n const refreshRecord = await this.#config.tokenStore.get(this.#refreshKey());\n if (refreshRecord === null) {\n throw new Error(\"OAuth refresh failed: no refresh token stored\");\n }\n\n const body = new URLSearchParams();\n body.set(\"grant_type\", \"refresh_token\");\n body.set(\"refresh_token\", refreshRecord.token);\n body.set(\"client_id\", this.#config.clientId);\n\n const tokens = await this.#tokenRequest(body);\n return this.#persistTokens(tokens, refreshRecord.token);\n }\n\n /**\n * Get the current access token if valid (refreshing first if expired and a\n * refresh token is available). Returns `null` when no usable token exists.\n */\n public async getAccessToken(): Promise<string | null> {\n const stored = await this.#config.tokenStore.get(this.#accessKey());\n if (stored !== null) return stored.token;\n\n // Stored access token is missing or already evicted by the store's TTL.\n const refresh = await this.#config.tokenStore.get(this.#refreshKey());\n if (refresh === null) return null;\n\n try {\n const refreshed = await this.refresh();\n return refreshed.token;\n } catch {\n return null;\n }\n }\n\n /** Forget tokens (logout). Does NOT call any remote revocation endpoint. */\n public async signOut(): Promise<void> {\n await this.#config.tokenStore.delete(this.#accessKey());\n await this.#config.tokenStore.delete(this.#refreshKey());\n }\n\n #accessKey(): string {\n return `oauth:tokens:${this.#config.clientId}`;\n }\n\n #refreshKey(): string {\n return `oauth:refresh:${this.#config.clientId}`;\n }\n\n #verifierKey(state: string): string {\n return `oauth:verifier:${state}`;\n }\n\n async #tokenRequest(body: URLSearchParams): Promise<TokenEndpointResponse> {\n const response = await this.#config.fetchImpl(this.#config.tokenEndpoint, {\n method: \"POST\",\n headers: {\n \"Content-Type\": \"application/x-www-form-urlencoded\",\n Accept: \"application/json\",\n },\n body: body.toString(),\n });\n\n const text = await response.text();\n const parsed = parseJsonBody(text);\n\n if (!response.ok) {\n throw new Error(formatOAuthError(parsed ?? {}, response.status));\n }\n\n if (\n parsed === null ||\n typeof parsed !== \"object\" ||\n typeof (parsed as { access_token?: unknown }).access_token !== \"string\"\n ) {\n throw new Error(\n \"OAuth token endpoint returned a response without an `access_token` string\",\n );\n }\n\n return parsed as TokenEndpointResponse;\n }\n\n async #persistTokens(\n tokens: TokenEndpointResponse,\n previousRefreshToken?: string,\n ): Promise<TokenRecord> {\n const record: TokenRecord = { token: tokens.access_token };\n if (typeof tokens.expires_in === \"number\" && tokens.expires_in > 0) {\n record.expiresAt = Math.floor(Date.now() / 1000) + tokens.expires_in;\n }\n await this.#config.tokenStore.set(this.#accessKey(), record);\n\n const newRefresh = tokens.refresh_token ?? previousRefreshToken;\n if (newRefresh !== undefined) {\n await this.#config.tokenStore.set(this.#refreshKey(), {\n token: newRefresh,\n });\n }\n\n return record;\n }\n}\n\nfunction defaultGenerateState(): string {\n const bytes = new Uint8Array(24);\n crypto.getRandomValues(bytes);\n let binary = \"\";\n for (let i = 0; i < bytes.length; i++) {\n binary += String.fromCharCode(bytes[i] as number);\n }\n return btoa(binary)\n .replace(/\\+/g, \"-\")\n .replace(/\\//g, \"_\")\n .replace(/=+$/, \"\");\n}\n\nfunction parseJsonBody(text: string): unknown {\n if (text.length === 0) return null;\n try {\n return JSON.parse(text) as unknown;\n } catch {\n return null;\n }\n}\n\nfunction formatOAuthError(body: OAuthErrorBody, status?: number): string {\n const parts: string[] = [\"OAuth token request failed\"];\n if (status !== undefined) parts.push(`(HTTP ${String(status)})`);\n if (body.error !== undefined && body.error.length > 0) {\n parts.push(`: ${body.error}`);\n if (\n body.error_description !== undefined &&\n body.error_description.length > 0\n ) {\n parts.push(`- ${body.error_description}`);\n }\n }\n return parts.join(\" \").replace(\" : \", \": \").replace(\" - \", \" - \");\n}\n"],"mappings":"AAYA,SAAS,sBAAsB,4BAA4B;AAC3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;AAC5B,YAAM,KAAK,QAAQ,WAAW,IAAI,KAAK,YAAY,GAAG;AAAA,QACpD,OAAO;AAAA,MACT,CAAC;AAAA,IACH;AAEA,WAAO;AAAA,EACT;AACF;AAEA,SAAS,uBAA+B;AACtC,QAAM,QAAQ,IAAI,WAAW,EAAE;AAC/B,SAAO,gBAAgB,KAAK;AAC5B,MAAI,SAAS;AACb,WAAS,IAAI,GAAG,IAAI,MAAM,QAAQ,KAAK;AACrC,cAAU,OAAO,aAAa,MAAM,CAAC,CAAW;AAAA,EAClD;AACA,SAAO,KAAK,MAAM,EACf,QAAQ,OAAO,GAAG,EAClB,QAAQ,OAAO,GAAG,EAClB,QAAQ,OAAO,EAAE;AACtB;AAEA,SAAS,cAAc,MAAuB;AAC5C,MAAI,KAAK,WAAW,EAAG,QAAO;AAC9B,MAAI;AACF,WAAO,KAAK,MAAM,IAAI;AAAA,EACxB,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAEA,SAAS,iBAAiB,MAAsB,QAAyB;AACvE,QAAM,QAAkB,CAAC,4BAA4B;AACrD,MAAI,WAAW,OAAW,OAAM,KAAK,SAAS,OAAO,MAAM,CAAC,GAAG;AAC/D,MAAI,KAAK,UAAU,UAAa,KAAK,MAAM,SAAS,GAAG;AACrD,UAAM,KAAK,KAAK,KAAK,KAAK,EAAE;AAC5B,QACE,KAAK,sBAAsB,UAC3B,KAAK,kBAAkB,SAAS,GAChC;AACA,YAAM,KAAK,KAAK,KAAK,iBAAiB,EAAE;AAAA,IAC1C;AAAA,EACF;AACA,SAAO,MAAM,KAAK,GAAG,EAAE,QAAQ,OAAO,IAAI,EAAE,QAAQ,OAAO,KAAK;AAClE;","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { sha256 } from "@noble/hashes/sha2";
|
|
2
2
|
import { bytesToHex } from "viem";
|
|
3
|
-
import { toBase64 } from "../utils/encoding";
|
|
3
|
+
import { toBase64 } from "../utils/encoding.js";
|
|
4
4
|
const EMPTY_BODY_HASH = "sha256:e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855";
|
|
5
5
|
const DEFAULT_TTL_SECONDS = 300;
|
|
6
6
|
function base64urlEncode(input) {
|
package/dist/auth/web3-signed.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { recoverMessageAddress } from "viem";
|
|
2
|
-
import { fromBase64 } from "../utils/encoding";
|
|
2
|
+
import { fromBase64 } from "../utils/encoding.js";
|
|
3
3
|
import {
|
|
4
4
|
MissingAuthError,
|
|
5
5
|
InvalidSignatureError,
|
|
6
6
|
ExpiredTokenError
|
|
7
|
-
} from "./errors";
|
|
8
|
-
import { computeBodyHash } from "./web3-signed-builder";
|
|
7
|
+
} from "./errors.js";
|
|
8
|
+
import { computeBodyHash } from "./web3-signed-builder.js";
|
|
9
9
|
const WEB3_SIGNED_PREFIX = "Web3Signed ";
|
|
10
10
|
const CLOCK_SKEW_SECONDS = 60;
|
|
11
11
|
function base64urlDecode(input) {
|
package/dist/browser.js
CHANGED
package/dist/chains/index.js
CHANGED
package/dist/chains.browser.js
CHANGED
package/dist/chains.js
CHANGED
package/dist/chains.node.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
getContract
|
|
3
3
|
} from "viem";
|
|
4
|
-
import { getAbi } from "../generated/abi";
|
|
5
|
-
import { getContractAddress, CONTRACT_ADDRESSES } from "../generated/addresses";
|
|
6
|
-
import { createClient } from "../core/client";
|
|
7
|
-
import { vanaMainnet } from "../config/chains";
|
|
4
|
+
import { getAbi } from "../generated/abi/index.js";
|
|
5
|
+
import { getContractAddress, CONTRACT_ADDRESSES } from "../generated/addresses.js";
|
|
6
|
+
import { createClient } from "../core/client.js";
|
|
7
|
+
import { vanaMainnet } from "../config/chains.js";
|
|
8
8
|
const contractCache = /* @__PURE__ */ new Map();
|
|
9
9
|
const contractCacheForTesting = contractCache;
|
|
10
10
|
function createCacheKey(contract, chainId) {
|
package/dist/core/client.js
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
http,
|
|
4
4
|
createWalletClient as viemCreateWalletClient
|
|
5
5
|
} from "viem";
|
|
6
|
-
import { chains, mokshaTestnet } from "../config/chains";
|
|
6
|
+
import { chains, mokshaTestnet } from "../config/chains.js";
|
|
7
7
|
const defaultFromBlocks = {
|
|
8
8
|
14800: 732312n,
|
|
9
9
|
// Moksha Testnet - earliest contract deployment
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ECIESError, isECIESEncrypted } from "./interface";
|
|
2
|
-
import { CURVE, CIPHER, KDF } from "./constants";
|
|
3
|
-
import { constantTimeEqual } from "./utils";
|
|
1
|
+
import { ECIESError, isECIESEncrypted } from "./interface.js";
|
|
2
|
+
import { CURVE, CIPHER, KDF } from "./constants.js";
|
|
3
|
+
import { constantTimeEqual } from "./utils.js";
|
|
4
4
|
import { concat } from "viem";
|
|
5
5
|
class BaseECIESUint8 {
|
|
6
6
|
// Cache for validated public keys to avoid repeated validation
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as secp256k1 from "@noble/secp256k1";
|
|
2
|
-
import { BaseECIESUint8 } from "./base";
|
|
2
|
+
import { BaseECIESUint8 } from "./base.js";
|
|
3
3
|
import { toHex } from "viem";
|
|
4
4
|
import { hmac } from "@noble/hashes/hmac";
|
|
5
5
|
import { sha256, sha512 as nobleSha512 } from "@noble/hashes/sha2";
|
|
@@ -6,7 +6,7 @@ import {
|
|
|
6
6
|
createDecipheriv
|
|
7
7
|
} from "crypto";
|
|
8
8
|
import secp256k1Import from "secp256k1";
|
|
9
|
-
import { BaseECIESUint8 } from "./base";
|
|
9
|
+
import { BaseECIESUint8 } from "./base.js";
|
|
10
10
|
import { toHex } from "viem";
|
|
11
11
|
const secp256k1 = secp256k1Import;
|
|
12
12
|
class NodeECIESUint8Provider extends BaseECIESUint8 {
|
|
@@ -2,7 +2,7 @@ import {
|
|
|
2
2
|
processWalletPublicKey,
|
|
3
3
|
processWalletPrivateKey,
|
|
4
4
|
parseEncryptedDataBuffer
|
|
5
|
-
} from "../../utils/crypto-utils";
|
|
5
|
+
} from "../../utils/crypto-utils.js";
|
|
6
6
|
import { stringToBytes, bytesToString, toHex, fromHex, concat } from "viem";
|
|
7
7
|
class WalletKeyEncryptionService {
|
|
8
8
|
eciesProvider;
|
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import { ComputeEngineABI } from "./ComputeEngineImplementation";
|
|
2
|
-
import { DataRegistryABI } from "./DataRegistryImplementation";
|
|
3
|
-
import { TeePoolPhalaABI } from "./TeePoolPhalaImplementation";
|
|
4
|
-
import { DataPortabilityPermissionsABI } from "./DataPortabilityPermissionsImplementation";
|
|
5
|
-
import { DataPortabilityServersABI } from "./DataPortabilityServersImplementation";
|
|
6
|
-
import { DataPortabilityGranteesABI } from "./DataPortabilityGranteesImplementation";
|
|
7
|
-
import { DataRefinerRegistryABI } from "./DataRefinerRegistryImplementation";
|
|
8
|
-
import { QueryEngineABI } from "./QueryEngineImplementation";
|
|
9
|
-
import { ComputeInstructionRegistryABI } from "./ComputeInstructionRegistryImplementation";
|
|
10
|
-
import { TeePoolEphemeralStandardABI } from "./TeePoolEphemeralStandardImplementation";
|
|
11
|
-
import { TeePoolPersistentStandardABI } from "./TeePoolPersistentStandardImplementation";
|
|
12
|
-
import { TeePoolPersistentGpuABI } from "./TeePoolPersistentGpuImplementation";
|
|
13
|
-
import { TeePoolDedicatedStandardABI } from "./TeePoolDedicatedStandardImplementation";
|
|
14
|
-
import { TeePoolDedicatedGpuABI } from "./TeePoolDedicatedGpuImplementation";
|
|
15
|
-
import { VanaEpochABI } from "./VanaEpochImplementation";
|
|
16
|
-
import { DLPRegistryABI } from "./DLPRegistryImplementation";
|
|
17
|
-
import { DLPRegistryTreasuryABI } from "./DLPTreasuryImplementation";
|
|
18
|
-
import { VanaTreasuryABI } from "./VanaTreasuryImplementation";
|
|
19
|
-
import { DLPRegistryTreasuryABI as DLPRegistryTreasuryImplementationABI } from "./DLPRegistryTreasuryImplementation";
|
|
20
|
-
import { VanaPoolStakingABI } from "./VanaPoolStakingImplementation";
|
|
21
|
-
import { VanaPoolEntityABI } from "./VanaPoolEntityImplementation";
|
|
22
|
-
import { VanaPoolTreasuryABI } from "./VanaPoolTreasuryImplementation";
|
|
23
|
-
import { DATABI } from "./DATImplementation";
|
|
24
|
-
import { DATFactoryABI } from "./DATFactoryImplementation";
|
|
25
|
-
import { DATPausableABI } from "./DATPausableImplementation";
|
|
26
|
-
import { DATVotesABI } from "./DATVotesImplementation";
|
|
1
|
+
import { ComputeEngineABI } from "./ComputeEngineImplementation.js";
|
|
2
|
+
import { DataRegistryABI } from "./DataRegistryImplementation.js";
|
|
3
|
+
import { TeePoolPhalaABI } from "./TeePoolPhalaImplementation.js";
|
|
4
|
+
import { DataPortabilityPermissionsABI } from "./DataPortabilityPermissionsImplementation.js";
|
|
5
|
+
import { DataPortabilityServersABI } from "./DataPortabilityServersImplementation.js";
|
|
6
|
+
import { DataPortabilityGranteesABI } from "./DataPortabilityGranteesImplementation.js";
|
|
7
|
+
import { DataRefinerRegistryABI } from "./DataRefinerRegistryImplementation.js";
|
|
8
|
+
import { QueryEngineABI } from "./QueryEngineImplementation.js";
|
|
9
|
+
import { ComputeInstructionRegistryABI } from "./ComputeInstructionRegistryImplementation.js";
|
|
10
|
+
import { TeePoolEphemeralStandardABI } from "./TeePoolEphemeralStandardImplementation.js";
|
|
11
|
+
import { TeePoolPersistentStandardABI } from "./TeePoolPersistentStandardImplementation.js";
|
|
12
|
+
import { TeePoolPersistentGpuABI } from "./TeePoolPersistentGpuImplementation.js";
|
|
13
|
+
import { TeePoolDedicatedStandardABI } from "./TeePoolDedicatedStandardImplementation.js";
|
|
14
|
+
import { TeePoolDedicatedGpuABI } from "./TeePoolDedicatedGpuImplementation.js";
|
|
15
|
+
import { VanaEpochABI } from "./VanaEpochImplementation.js";
|
|
16
|
+
import { DLPRegistryABI } from "./DLPRegistryImplementation.js";
|
|
17
|
+
import { DLPRegistryTreasuryABI } from "./DLPTreasuryImplementation.js";
|
|
18
|
+
import { VanaTreasuryABI } from "./VanaTreasuryImplementation.js";
|
|
19
|
+
import { DLPRegistryTreasuryABI as DLPRegistryTreasuryImplementationABI } from "./DLPRegistryTreasuryImplementation.js";
|
|
20
|
+
import { VanaPoolStakingABI } from "./VanaPoolStakingImplementation.js";
|
|
21
|
+
import { VanaPoolEntityABI } from "./VanaPoolEntityImplementation.js";
|
|
22
|
+
import { VanaPoolTreasuryABI } from "./VanaPoolTreasuryImplementation.js";
|
|
23
|
+
import { DATABI } from "./DATImplementation.js";
|
|
24
|
+
import { DATFactoryABI } from "./DATFactoryImplementation.js";
|
|
25
|
+
import { DATPausableABI } from "./DATPausableImplementation.js";
|
|
26
|
+
import { DATVotesABI } from "./DATVotesImplementation.js";
|
|
27
27
|
const contractAbis = {
|
|
28
28
|
DataPortabilityPermissions: DataPortabilityPermissionsABI,
|
|
29
29
|
DataPortabilityServers: DataPortabilityServersABI,
|
package/dist/index.browser.d.ts
CHANGED
|
@@ -28,15 +28,21 @@ export type { ECIESProvider, ECIESEncrypted, ECIESOptions, } from "./crypto/ecie
|
|
|
28
28
|
export { createBrowserPlatformAdapter, createPlatformAdapterSafe, } from "./platform/browser-only";
|
|
29
29
|
export { generatePkceVerifier, computePkceChallenge, verifyPkceChallenge, assertValidPkceVerifier, PKCE_VERIFIER_PATTERN, PKCE_CHALLENGE_PATTERN, } from "./auth/pkce";
|
|
30
30
|
export { InMemoryTokenStore, type TokenStore, type TokenRecord, } from "./auth/token-store";
|
|
31
|
+
export { OAuthClient, type OAuthClientConfig, type AuthorizationUrlResult, } from "./auth/oauth-client";
|
|
31
32
|
export { detectPlatform, isPlatformSupported, getPlatformCapabilities, } from "./platform/utils";
|
|
32
33
|
export { deriveMasterKey, deriveScopeKey, recoverServerOwner, MASTER_KEY_MESSAGE, } from "./crypto/keys/derive";
|
|
33
34
|
export { encryptWithPassword, decryptWithPassword, } from "./crypto/envelope/openpgp";
|
|
34
35
|
export { parseWeb3SignedHeader, verifyWeb3Signed, type Web3SignedPayload, type VerifiedAuth, } from "./auth/web3-signed";
|
|
35
36
|
export { buildWeb3SignedHeader, computeBodyHash, type Web3SignedSignFn, } from "./auth/web3-signed-builder";
|
|
36
37
|
export { MissingAuthError, InvalidSignatureError, ExpiredTokenError, } from "./auth/errors";
|
|
37
|
-
export { fileRegistrationDomain, grantRegistrationDomain, grantRevocationDomain, serverRegistrationDomain, builderRegistrationDomain, FILE_REGISTRATION_TYPES, GRANT_REGISTRATION_TYPES, GRANT_REVOCATION_TYPES, SERVER_REGISTRATION_TYPES, BUILDER_REGISTRATION_TYPES, type DataPortabilityContracts, type DataPortabilityGatewayConfig, type FileRegistrationMessage, type GrantRegistrationMessage, type GrantRevocationMessage, type ServerRegistrationMessage, type BuilderRegistrationMessage, } from "./protocol/eip712";
|
|
38
|
-
export {
|
|
38
|
+
export { fileRegistrationDomain, grantRegistrationDomain, grantRevocationDomain, serverRegistrationDomain, builderRegistrationDomain, escrowPaymentDomain, dataRegistryDomain, FILE_REGISTRATION_TYPES, GRANT_REGISTRATION_TYPES, GRANT_REVOCATION_TYPES, SERVER_REGISTRATION_TYPES, BUILDER_REGISTRATION_TYPES, GENERIC_PAYMENT_TYPES, ADD_DATA_TYPES, RECORD_DATA_ACCESS_TYPES, NATIVE_VANA_ASSET, type DataPortabilityContracts, type DataPortabilityGatewayConfig, type FileRegistrationMessage, type GrantRegistrationMessage, type GrantRevocationMessage, type ServerRegistrationMessage, type BuilderRegistrationMessage, type GenericPaymentMessage, type AddDataMessage, type RecordDataAccessMessage, } from "./protocol/eip712";
|
|
39
|
+
export { PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID, PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT, personalServerRegistrationDomain, createViemPersonalServerRegistrationSigner, buildPersonalServerRegistrationTypedData, buildPersonalServerRegistrationSignature, registerPersonalServerSignature, type PersonalServerRegistrationTypedData, type PersonalServerRegistrationSigner, type PersonalServerRegistrationDomainInput, type ViemPersonalServerRegistrationWalletClient, type ViemPersonalServerRegistrationSignerSource, type BuildPersonalServerRegistrationTypedDataInput, type BuildPersonalServerRegistrationSignatureInput, type PersonalServerRegistrationSignature, } from "./protocol/personal-server-registration";
|
|
40
|
+
export { PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION, PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE, PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX, buildPersonalServerLiteOwnerBindingMessage, createViemPersonalServerLiteOwnerBindingSigner, buildPersonalServerLiteOwnerBindingSignature, signPersonalServerLiteOwnerBinding, type PersonalServerLiteOwnerBindingPurpose, type PersonalServerLiteOwnerBindingMessage, type PersonalServerLiteOwnerBindingSigner, type ViemPersonalServerLiteOwnerBindingWalletClient, type ViemPersonalServerLiteOwnerBindingSignerSource, type BuildPersonalServerLiteOwnerBindingSignatureInput, type PersonalServerLiteOwnerBindingSignature, } from "./protocol/personal-server-lite-owner-binding";
|
|
41
|
+
export { ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT, AccountPersonalServerRegistrationError, signPersonalServerRegistrationWithAccount, type AccountPersonalServerRegistrationIntent, type AccountPersonalServerRegistrationSignature, type AccountPersonalServerRegistrationStatus, type AccountPersonalServerRegistrationRequest, type AccountPersonalServerRegistrationConfig, type AccountSignedPersonalServerRegistration, type AccountConfirmationRequiredPersonalServerRegistration, type AccountFallbackSignedPersonalServerRegistration, type AccountPersonalServerRegistrationResult, } from "./account/personal-server-registration";
|
|
42
|
+
export { AccountPersonalServerLiteOwnerBindingError, signPersonalServerLiteOwnerBindingWithAccountClient, type AccountPersonalServerLiteOwnerBindingClient, type SignPersonalServerLiteOwnerBindingWithAccountClientConfig, } from "./account/personal-server-lite-owner-binding";
|
|
43
|
+
export { isDataPortabilityGatewayConfig, verifyGrantRegistration, type VerifyGrantRegistrationInput, type VerifyGrantRegistrationResult, } from "./protocol/grants";
|
|
44
|
+
export { ESCROW_DEPOSIT_ABI, escrowContractAddress, encodeDepositNativeData, encodeDepositTokenData, buildDepositNativeRequest, buildDepositTokenRequest, type DepositNativeInput, type DepositTokenInput, type DepositTransactionRequest, } from "./protocol/escrow-deposit";
|
|
39
45
|
export { ScopeSchema, parseScope, scopeToPathSegments, scopeMatchesPattern, scopeCoveredByGrant, type Scope, type ParsedScope, } from "./protocol/scopes";
|
|
40
46
|
export { DataFileEnvelopeSchema, createDataFileEnvelope, IngestResponseSchema, type DataFileEnvelope, type IngestResponse, } from "./protocol/data-file";
|
|
41
|
-
export { createGatewayClient, type GatewayEnvelope, type GatewayProof, type Builder, type Schema, type ServerInfo, type GatewayGrantResponse, type GrantListItem, type FileRecord, type FileListResult, type RegisterServerParams, type RegisterServerResult, type RegisterFileParams, type CreateGrantParams, type RevokeGrantParams, type GatewayClient, } from "./protocol/gateway";
|
|
47
|
+
export { createGatewayClient, type GatewayEnvelope, type GatewayProof, type Builder, type Schema, type ServerInfo, type GatewayGrantResponse, type GatewayGrantStatus, type GatewayGrantFee, type GrantListItem, type FileRecord, type FileListResult, type RegisterServerParams, type RegisterServerResult, type RegisterFileParams, type RegisterBuilderParams, type RegisterBuilderResult, type RegisterDataPointParams, type RegisterDataPointResult, type CreateGrantParams, type RevokeGrantParams, type PayForOperationParams, type PayForOperationResult, type AccessRecord, type SettleOpType, type SettleItem, type SettlePromoteResult, type SettleReconcileItem, type SettleParams, type SettleResult, type SubmitDepositParams, type DepositState, type EscrowBalance, type EscrowBalanceEntry, type EscrowDepositSubmitted, type EscrowDepositFinalized, type EscrowDepositFailed, type GatewayClient, } from "./protocol/gateway";
|
|
42
48
|
export { PSError, parsePSError, type PSErrorCode } from "./types/ps-errors";
|