@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
package/dist/index.node.cjs
CHANGED
|
@@ -1173,6 +1173,10 @@ var init_browser2 = __esm({
|
|
|
1173
1173
|
// src/index.node.ts
|
|
1174
1174
|
var index_node_exports = {};
|
|
1175
1175
|
__export(index_node_exports, {
|
|
1176
|
+
ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT: () => ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
|
|
1177
|
+
ADD_DATA_TYPES: () => ADD_DATA_TYPES,
|
|
1178
|
+
AccountPersonalServerLiteOwnerBindingError: () => AccountPersonalServerLiteOwnerBindingError,
|
|
1179
|
+
AccountPersonalServerRegistrationError: () => AccountPersonalServerRegistrationError,
|
|
1176
1180
|
BUILDER_REGISTRATION_TYPES: () => BUILDER_REGISTRATION_TYPES,
|
|
1177
1181
|
BlockchainError: () => BlockchainError,
|
|
1178
1182
|
BrowserPlatformAdapter: () => BrowserPlatformAdapter,
|
|
@@ -1183,8 +1187,10 @@ __export(index_node_exports, {
|
|
|
1183
1187
|
DataFileEnvelopeSchema: () => DataFileEnvelopeSchema,
|
|
1184
1188
|
DropboxStorage: () => DropboxStorage,
|
|
1185
1189
|
ECIESError: () => ECIESError,
|
|
1190
|
+
ESCROW_DEPOSIT_ABI: () => ESCROW_DEPOSIT_ABI,
|
|
1186
1191
|
ExpiredTokenError: () => ExpiredTokenError,
|
|
1187
1192
|
FILE_REGISTRATION_TYPES: () => FILE_REGISTRATION_TYPES,
|
|
1193
|
+
GENERIC_PAYMENT_TYPES: () => GENERIC_PAYMENT_TYPES,
|
|
1188
1194
|
GRANT_REGISTRATION_TYPES: () => GRANT_REGISTRATION_TYPES,
|
|
1189
1195
|
GRANT_REVOCATION_TYPES: () => GRANT_REVOCATION_TYPES,
|
|
1190
1196
|
GoogleDriveStorage: () => GoogleDriveStorage,
|
|
@@ -1195,10 +1201,17 @@ __export(index_node_exports, {
|
|
|
1195
1201
|
IpfsStorage: () => IpfsStorage,
|
|
1196
1202
|
MASTER_KEY_MESSAGE: () => MASTER_KEY_MESSAGE,
|
|
1197
1203
|
MissingAuthError: () => MissingAuthError,
|
|
1204
|
+
NATIVE_VANA_ASSET: () => NATIVE_VANA_ASSET,
|
|
1198
1205
|
NetworkError: () => NetworkError,
|
|
1199
1206
|
NodeECIESProvider: () => NodeECIESUint8Provider,
|
|
1200
1207
|
NodePlatformAdapter: () => NodePlatformAdapter,
|
|
1201
1208
|
NonceError: () => NonceError,
|
|
1209
|
+
OAuthClient: () => OAuthClient,
|
|
1210
|
+
PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX: () => PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX,
|
|
1211
|
+
PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE: () => PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE,
|
|
1212
|
+
PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION: () => PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION,
|
|
1213
|
+
PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID: () => PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,
|
|
1214
|
+
PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT: () => PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT,
|
|
1202
1215
|
PKCE_CHALLENGE_PATTERN: () => PKCE_CHALLENGE_PATTERN,
|
|
1203
1216
|
PKCE_VERIFIER_PATTERN: () => PKCE_VERIFIER_PATTERN,
|
|
1204
1217
|
PSError: () => PSError,
|
|
@@ -1206,6 +1219,7 @@ __export(index_node_exports, {
|
|
|
1206
1219
|
PersonalServerError: () => PersonalServerError,
|
|
1207
1220
|
PinataStorage: () => PinataStorage,
|
|
1208
1221
|
R2Storage: () => R2Storage,
|
|
1222
|
+
RECORD_DATA_ACCESS_TYPES: () => RECORD_DATA_ACCESS_TYPES,
|
|
1209
1223
|
ReadOnlyError: () => ReadOnlyError,
|
|
1210
1224
|
RelayerError: () => RelayerError,
|
|
1211
1225
|
SERVER_REGISTRATION_TYPES: () => SERVER_REGISTRATION_TYPES,
|
|
@@ -1220,6 +1234,12 @@ __export(index_node_exports, {
|
|
|
1220
1234
|
VanaError: () => VanaError,
|
|
1221
1235
|
VanaStorage: () => VanaStorage,
|
|
1222
1236
|
assertValidPkceVerifier: () => assertValidPkceVerifier,
|
|
1237
|
+
buildDepositNativeRequest: () => buildDepositNativeRequest,
|
|
1238
|
+
buildDepositTokenRequest: () => buildDepositTokenRequest,
|
|
1239
|
+
buildPersonalServerLiteOwnerBindingMessage: () => buildPersonalServerLiteOwnerBindingMessage,
|
|
1240
|
+
buildPersonalServerLiteOwnerBindingSignature: () => buildPersonalServerLiteOwnerBindingSignature,
|
|
1241
|
+
buildPersonalServerRegistrationSignature: () => buildPersonalServerRegistrationSignature,
|
|
1242
|
+
buildPersonalServerRegistrationTypedData: () => buildPersonalServerRegistrationTypedData,
|
|
1223
1243
|
buildWeb3SignedHeader: () => buildWeb3SignedHeader,
|
|
1224
1244
|
builderRegistrationDomain: () => builderRegistrationDomain,
|
|
1225
1245
|
chains: () => chains,
|
|
@@ -1235,12 +1255,19 @@ __export(index_node_exports, {
|
|
|
1235
1255
|
createPlatformAdapterFor: () => createPlatformAdapterFor,
|
|
1236
1256
|
createPlatformAdapterSafe: () => createPlatformAdapterSafe,
|
|
1237
1257
|
createVanaStorageProvider: () => createVanaStorageProvider,
|
|
1258
|
+
createViemPersonalServerLiteOwnerBindingSigner: () => createViemPersonalServerLiteOwnerBindingSigner,
|
|
1259
|
+
createViemPersonalServerRegistrationSigner: () => createViemPersonalServerRegistrationSigner,
|
|
1260
|
+
dataRegistryDomain: () => dataRegistryDomain,
|
|
1238
1261
|
decryptWithPassword: () => decryptWithPassword,
|
|
1239
1262
|
deriveMasterKey: () => deriveMasterKey,
|
|
1240
1263
|
deriveScopeKey: () => deriveScopeKey,
|
|
1241
1264
|
deserializeECIES: () => deserializeECIES,
|
|
1242
1265
|
detectPlatform: () => detectPlatform,
|
|
1266
|
+
encodeDepositNativeData: () => encodeDepositNativeData,
|
|
1267
|
+
encodeDepositTokenData: () => encodeDepositTokenData,
|
|
1243
1268
|
encryptWithPassword: () => encryptWithPassword,
|
|
1269
|
+
escrowContractAddress: () => escrowContractAddress,
|
|
1270
|
+
escrowPaymentDomain: () => escrowPaymentDomain,
|
|
1244
1271
|
fileRegistrationDomain: () => fileRegistrationDomain,
|
|
1245
1272
|
generatePkceVerifier: () => generatePkceVerifier,
|
|
1246
1273
|
getAbi: () => getAbi,
|
|
@@ -1260,16 +1287,20 @@ __export(index_node_exports, {
|
|
|
1260
1287
|
moksha: () => moksha,
|
|
1261
1288
|
mokshaServices: () => mokshaServices,
|
|
1262
1289
|
mokshaTestnet: () => mokshaTestnet2,
|
|
1263
|
-
parseGrantRegistrationPayload: () => parseGrantRegistrationPayload,
|
|
1264
1290
|
parsePSError: () => parsePSError,
|
|
1265
1291
|
parseScope: () => parseScope,
|
|
1266
1292
|
parseWeb3SignedHeader: () => parseWeb3SignedHeader,
|
|
1293
|
+
personalServerRegistrationDomain: () => personalServerRegistrationDomain,
|
|
1267
1294
|
recoverServerOwner: () => recoverServerOwner,
|
|
1295
|
+
registerPersonalServerSignature: () => registerPersonalServerSignature,
|
|
1268
1296
|
scopeCoveredByGrant: () => scopeCoveredByGrant,
|
|
1269
1297
|
scopeMatchesPattern: () => scopeMatchesPattern,
|
|
1270
1298
|
scopeToPathSegments: () => scopeToPathSegments,
|
|
1271
1299
|
serializeECIES: () => serializeECIES,
|
|
1272
1300
|
serverRegistrationDomain: () => serverRegistrationDomain,
|
|
1301
|
+
signPersonalServerLiteOwnerBinding: () => signPersonalServerLiteOwnerBinding,
|
|
1302
|
+
signPersonalServerLiteOwnerBindingWithAccountClient: () => signPersonalServerLiteOwnerBindingWithAccountClient,
|
|
1303
|
+
signPersonalServerRegistrationWithAccount: () => signPersonalServerRegistrationWithAccount,
|
|
1273
1304
|
vanaMainnet: () => vanaMainnet2,
|
|
1274
1305
|
verifyGrantRegistration: () => verifyGrantRegistration,
|
|
1275
1306
|
verifyPkceChallenge: () => verifyPkceChallenge,
|
|
@@ -29139,7 +29170,7 @@ async function buildWeb3SignedHeader(params) {
|
|
|
29139
29170
|
}
|
|
29140
29171
|
|
|
29141
29172
|
// src/storage/providers/vana-storage.ts
|
|
29142
|
-
var DEFAULT_ENDPOINT = "https://storage.vana.
|
|
29173
|
+
var DEFAULT_ENDPOINT = "https://storage.vana.org";
|
|
29143
29174
|
var BLOB_PATH_PREFIX = "/v1/blobs";
|
|
29144
29175
|
var DEFAULT_TOKEN_TTL_SECONDS = 300;
|
|
29145
29176
|
var VanaStorage = class {
|
|
@@ -32402,9 +32433,232 @@ var InMemoryTokenStore = class {
|
|
|
32402
32433
|
}
|
|
32403
32434
|
};
|
|
32404
32435
|
|
|
32436
|
+
// src/auth/oauth-client.ts
|
|
32437
|
+
var VERIFIER_TTL_SECONDS = 600;
|
|
32438
|
+
var RESERVED_AUTHORIZE_PARAMS = /* @__PURE__ */ new Set([
|
|
32439
|
+
"response_type",
|
|
32440
|
+
"client_id",
|
|
32441
|
+
"redirect_uri",
|
|
32442
|
+
"scope",
|
|
32443
|
+
"state",
|
|
32444
|
+
"code_challenge",
|
|
32445
|
+
"code_challenge_method"
|
|
32446
|
+
]);
|
|
32447
|
+
var OAuthClient = class {
|
|
32448
|
+
#config;
|
|
32449
|
+
constructor(config) {
|
|
32450
|
+
const fetchImpl = config.fetchImpl ?? globalThis.fetch;
|
|
32451
|
+
if (typeof fetchImpl !== "function") {
|
|
32452
|
+
throw new TypeError(
|
|
32453
|
+
"OAuthClient requires a global `fetch` or an explicit `fetchImpl`"
|
|
32454
|
+
);
|
|
32455
|
+
}
|
|
32456
|
+
this.#config = {
|
|
32457
|
+
authorizationEndpoint: config.authorizationEndpoint,
|
|
32458
|
+
tokenEndpoint: config.tokenEndpoint,
|
|
32459
|
+
clientId: config.clientId,
|
|
32460
|
+
redirectUri: config.redirectUri,
|
|
32461
|
+
scope: config.scope,
|
|
32462
|
+
tokenStore: config.tokenStore ?? new InMemoryTokenStore(),
|
|
32463
|
+
fetchImpl,
|
|
32464
|
+
generateState: config.generateState ?? defaultGenerateState
|
|
32465
|
+
};
|
|
32466
|
+
}
|
|
32467
|
+
/** Build the authorize URL and persist the PKCE verifier keyed by `state`. */
|
|
32468
|
+
async buildAuthorizationUrl(opts = {}) {
|
|
32469
|
+
const state = opts.state ?? this.#config.generateState();
|
|
32470
|
+
const scope = opts.scope ?? this.#config.scope;
|
|
32471
|
+
const verifier = generatePkceVerifier();
|
|
32472
|
+
const challenge = await computePkceChallenge(verifier);
|
|
32473
|
+
await this.#config.tokenStore.set(this.#verifierKey(state), {
|
|
32474
|
+
token: verifier,
|
|
32475
|
+
expiresAt: Math.floor(Date.now() / 1e3) + VERIFIER_TTL_SECONDS
|
|
32476
|
+
});
|
|
32477
|
+
const params = new URLSearchParams();
|
|
32478
|
+
params.set("response_type", "code");
|
|
32479
|
+
params.set("client_id", this.#config.clientId);
|
|
32480
|
+
params.set("redirect_uri", this.#config.redirectUri);
|
|
32481
|
+
if (scope !== void 0 && scope.length > 0) {
|
|
32482
|
+
params.set("scope", scope);
|
|
32483
|
+
}
|
|
32484
|
+
params.set("state", state);
|
|
32485
|
+
params.set("code_challenge", challenge);
|
|
32486
|
+
params.set("code_challenge_method", "S256");
|
|
32487
|
+
if (opts.extraParams !== void 0) {
|
|
32488
|
+
for (const k of Object.keys(opts.extraParams)) {
|
|
32489
|
+
if (RESERVED_AUTHORIZE_PARAMS.has(k)) {
|
|
32490
|
+
throw new Error(
|
|
32491
|
+
`extraParams may not override the reserved OAuth/PKCE parameter "${k}"`
|
|
32492
|
+
);
|
|
32493
|
+
}
|
|
32494
|
+
}
|
|
32495
|
+
for (const [k, v] of Object.entries(opts.extraParams)) {
|
|
32496
|
+
params.set(k, v);
|
|
32497
|
+
}
|
|
32498
|
+
}
|
|
32499
|
+
const sep = this.#config.authorizationEndpoint.includes("?") ? "&" : "?";
|
|
32500
|
+
const url = `${this.#config.authorizationEndpoint}${sep}${params.toString()}`;
|
|
32501
|
+
return { url, state };
|
|
32502
|
+
}
|
|
32503
|
+
/**
|
|
32504
|
+
* Handle the redirect-callback URL. Validates `state`, retrieves the saved
|
|
32505
|
+
* verifier, exchanges the authorization code + verifier for tokens, and
|
|
32506
|
+
* persists them. Returns the access {@link TokenRecord}.
|
|
32507
|
+
*/
|
|
32508
|
+
async handleCallback(callbackUrl) {
|
|
32509
|
+
const parsed = new URL(callbackUrl);
|
|
32510
|
+
const params = parsed.searchParams;
|
|
32511
|
+
const errorCode = params.get("error");
|
|
32512
|
+
if (errorCode !== null) {
|
|
32513
|
+
throw new Error(
|
|
32514
|
+
formatOAuthError({
|
|
32515
|
+
error: errorCode,
|
|
32516
|
+
error_description: params.get("error_description") ?? void 0
|
|
32517
|
+
})
|
|
32518
|
+
);
|
|
32519
|
+
}
|
|
32520
|
+
const code = params.get("code");
|
|
32521
|
+
const state = params.get("state");
|
|
32522
|
+
if (code === null || state === null) {
|
|
32523
|
+
throw new Error("OAuth callback is missing `code` or `state`");
|
|
32524
|
+
}
|
|
32525
|
+
const verifierRecord = await this.#config.tokenStore.get(
|
|
32526
|
+
this.#verifierKey(state)
|
|
32527
|
+
);
|
|
32528
|
+
if (verifierRecord === null) {
|
|
32529
|
+
throw new Error(
|
|
32530
|
+
"OAuth callback state does not match any in-flight verifier (possible CSRF or expired flow)"
|
|
32531
|
+
);
|
|
32532
|
+
}
|
|
32533
|
+
const body = new URLSearchParams();
|
|
32534
|
+
body.set("grant_type", "authorization_code");
|
|
32535
|
+
body.set("code", code);
|
|
32536
|
+
body.set("redirect_uri", this.#config.redirectUri);
|
|
32537
|
+
body.set("client_id", this.#config.clientId);
|
|
32538
|
+
body.set("code_verifier", verifierRecord.token);
|
|
32539
|
+
let tokens;
|
|
32540
|
+
try {
|
|
32541
|
+
tokens = await this.#tokenRequest(body);
|
|
32542
|
+
} finally {
|
|
32543
|
+
await this.#config.tokenStore.delete(this.#verifierKey(state));
|
|
32544
|
+
}
|
|
32545
|
+
return this.#persistTokens(tokens);
|
|
32546
|
+
}
|
|
32547
|
+
/**
|
|
32548
|
+
* Exchange a stored refresh token for a fresh access token. Throws if no
|
|
32549
|
+
* refresh token is available.
|
|
32550
|
+
*/
|
|
32551
|
+
async refresh() {
|
|
32552
|
+
const refreshRecord = await this.#config.tokenStore.get(this.#refreshKey());
|
|
32553
|
+
if (refreshRecord === null) {
|
|
32554
|
+
throw new Error("OAuth refresh failed: no refresh token stored");
|
|
32555
|
+
}
|
|
32556
|
+
const body = new URLSearchParams();
|
|
32557
|
+
body.set("grant_type", "refresh_token");
|
|
32558
|
+
body.set("refresh_token", refreshRecord.token);
|
|
32559
|
+
body.set("client_id", this.#config.clientId);
|
|
32560
|
+
const tokens = await this.#tokenRequest(body);
|
|
32561
|
+
return this.#persistTokens(tokens, refreshRecord.token);
|
|
32562
|
+
}
|
|
32563
|
+
/**
|
|
32564
|
+
* Get the current access token if valid (refreshing first if expired and a
|
|
32565
|
+
* refresh token is available). Returns `null` when no usable token exists.
|
|
32566
|
+
*/
|
|
32567
|
+
async getAccessToken() {
|
|
32568
|
+
const stored = await this.#config.tokenStore.get(this.#accessKey());
|
|
32569
|
+
if (stored !== null) return stored.token;
|
|
32570
|
+
const refresh = await this.#config.tokenStore.get(this.#refreshKey());
|
|
32571
|
+
if (refresh === null) return null;
|
|
32572
|
+
try {
|
|
32573
|
+
const refreshed = await this.refresh();
|
|
32574
|
+
return refreshed.token;
|
|
32575
|
+
} catch {
|
|
32576
|
+
return null;
|
|
32577
|
+
}
|
|
32578
|
+
}
|
|
32579
|
+
/** Forget tokens (logout). Does NOT call any remote revocation endpoint. */
|
|
32580
|
+
async signOut() {
|
|
32581
|
+
await this.#config.tokenStore.delete(this.#accessKey());
|
|
32582
|
+
await this.#config.tokenStore.delete(this.#refreshKey());
|
|
32583
|
+
}
|
|
32584
|
+
#accessKey() {
|
|
32585
|
+
return `oauth:tokens:${this.#config.clientId}`;
|
|
32586
|
+
}
|
|
32587
|
+
#refreshKey() {
|
|
32588
|
+
return `oauth:refresh:${this.#config.clientId}`;
|
|
32589
|
+
}
|
|
32590
|
+
#verifierKey(state) {
|
|
32591
|
+
return `oauth:verifier:${state}`;
|
|
32592
|
+
}
|
|
32593
|
+
async #tokenRequest(body) {
|
|
32594
|
+
const response = await this.#config.fetchImpl(this.#config.tokenEndpoint, {
|
|
32595
|
+
method: "POST",
|
|
32596
|
+
headers: {
|
|
32597
|
+
"Content-Type": "application/x-www-form-urlencoded",
|
|
32598
|
+
Accept: "application/json"
|
|
32599
|
+
},
|
|
32600
|
+
body: body.toString()
|
|
32601
|
+
});
|
|
32602
|
+
const text = await response.text();
|
|
32603
|
+
const parsed = parseJsonBody(text);
|
|
32604
|
+
if (!response.ok) {
|
|
32605
|
+
throw new Error(formatOAuthError(parsed ?? {}, response.status));
|
|
32606
|
+
}
|
|
32607
|
+
if (parsed === null || typeof parsed !== "object" || typeof parsed.access_token !== "string") {
|
|
32608
|
+
throw new Error(
|
|
32609
|
+
"OAuth token endpoint returned a response without an `access_token` string"
|
|
32610
|
+
);
|
|
32611
|
+
}
|
|
32612
|
+
return parsed;
|
|
32613
|
+
}
|
|
32614
|
+
async #persistTokens(tokens, previousRefreshToken) {
|
|
32615
|
+
const record = { token: tokens.access_token };
|
|
32616
|
+
if (typeof tokens.expires_in === "number" && tokens.expires_in > 0) {
|
|
32617
|
+
record.expiresAt = Math.floor(Date.now() / 1e3) + tokens.expires_in;
|
|
32618
|
+
}
|
|
32619
|
+
await this.#config.tokenStore.set(this.#accessKey(), record);
|
|
32620
|
+
const newRefresh = tokens.refresh_token ?? previousRefreshToken;
|
|
32621
|
+
if (newRefresh !== void 0) {
|
|
32622
|
+
await this.#config.tokenStore.set(this.#refreshKey(), {
|
|
32623
|
+
token: newRefresh
|
|
32624
|
+
});
|
|
32625
|
+
}
|
|
32626
|
+
return record;
|
|
32627
|
+
}
|
|
32628
|
+
};
|
|
32629
|
+
function defaultGenerateState() {
|
|
32630
|
+
const bytes = new Uint8Array(24);
|
|
32631
|
+
crypto.getRandomValues(bytes);
|
|
32632
|
+
let binary = "";
|
|
32633
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
32634
|
+
binary += String.fromCharCode(bytes[i]);
|
|
32635
|
+
}
|
|
32636
|
+
return btoa(binary).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
32637
|
+
}
|
|
32638
|
+
function parseJsonBody(text) {
|
|
32639
|
+
if (text.length === 0) return null;
|
|
32640
|
+
try {
|
|
32641
|
+
return JSON.parse(text);
|
|
32642
|
+
} catch {
|
|
32643
|
+
return null;
|
|
32644
|
+
}
|
|
32645
|
+
}
|
|
32646
|
+
function formatOAuthError(body, status) {
|
|
32647
|
+
const parts = ["OAuth token request failed"];
|
|
32648
|
+
if (status !== void 0) parts.push(`(HTTP ${String(status)})`);
|
|
32649
|
+
if (body.error !== void 0 && body.error.length > 0) {
|
|
32650
|
+
parts.push(`: ${body.error}`);
|
|
32651
|
+
if (body.error_description !== void 0 && body.error_description.length > 0) {
|
|
32652
|
+
parts.push(`- ${body.error_description}`);
|
|
32653
|
+
}
|
|
32654
|
+
}
|
|
32655
|
+
return parts.join(" ").replace(" : ", ": ").replace(" - ", " - ");
|
|
32656
|
+
}
|
|
32657
|
+
|
|
32405
32658
|
// src/protocol/eip712.ts
|
|
32406
32659
|
var DOMAIN_NAME = "Vana Data Portability";
|
|
32407
32660
|
var DOMAIN_VERSION = "1";
|
|
32661
|
+
var NATIVE_VANA_ASSET = "0x0000000000000000000000000000000000000000";
|
|
32408
32662
|
function buildDomain(chainId, verifyingContract) {
|
|
32409
32663
|
return {
|
|
32410
32664
|
name: DOMAIN_NAME,
|
|
@@ -32419,6 +32673,12 @@ function fileRegistrationDomain(config) {
|
|
|
32419
32673
|
config.contracts.dataRegistry
|
|
32420
32674
|
);
|
|
32421
32675
|
}
|
|
32676
|
+
function dataRegistryDomain(config) {
|
|
32677
|
+
return buildDomain(
|
|
32678
|
+
config.chainId,
|
|
32679
|
+
config.contracts.dataRegistry
|
|
32680
|
+
);
|
|
32681
|
+
}
|
|
32422
32682
|
function grantRegistrationDomain(config) {
|
|
32423
32683
|
return buildDomain(
|
|
32424
32684
|
config.chainId,
|
|
@@ -32443,6 +32703,12 @@ function builderRegistrationDomain(config) {
|
|
|
32443
32703
|
config.contracts.dataPortabilityGrantees
|
|
32444
32704
|
);
|
|
32445
32705
|
}
|
|
32706
|
+
function escrowPaymentDomain(config) {
|
|
32707
|
+
return buildDomain(
|
|
32708
|
+
config.chainId,
|
|
32709
|
+
config.contracts.dataPortabilityEscrow
|
|
32710
|
+
);
|
|
32711
|
+
}
|
|
32446
32712
|
var FILE_REGISTRATION_TYPES = {
|
|
32447
32713
|
FileRegistration: [
|
|
32448
32714
|
{ name: "ownerAddress", type: "address" },
|
|
@@ -32454,14 +32720,16 @@ var GRANT_REGISTRATION_TYPES = {
|
|
|
32454
32720
|
GrantRegistration: [
|
|
32455
32721
|
{ name: "grantorAddress", type: "address" },
|
|
32456
32722
|
{ name: "granteeId", type: "bytes32" },
|
|
32457
|
-
{ name: "
|
|
32458
|
-
{ name: "
|
|
32723
|
+
{ name: "scopes", type: "string[]" },
|
|
32724
|
+
{ name: "grantVersion", type: "uint256" },
|
|
32725
|
+
{ name: "expiresAt", type: "uint256" }
|
|
32459
32726
|
]
|
|
32460
32727
|
};
|
|
32461
32728
|
var GRANT_REVOCATION_TYPES = {
|
|
32462
32729
|
GrantRevocation: [
|
|
32463
32730
|
{ name: "grantorAddress", type: "address" },
|
|
32464
|
-
{ name: "grantId", type: "bytes32" }
|
|
32731
|
+
{ name: "grantId", type: "bytes32" },
|
|
32732
|
+
{ name: "grantVersion", type: "uint256" }
|
|
32465
32733
|
]
|
|
32466
32734
|
};
|
|
32467
32735
|
var SERVER_REGISTRATION_TYPES = {
|
|
@@ -32480,87 +32748,500 @@ var BUILDER_REGISTRATION_TYPES = {
|
|
|
32480
32748
|
{ name: "appUrl", type: "string" }
|
|
32481
32749
|
]
|
|
32482
32750
|
};
|
|
32751
|
+
var GENERIC_PAYMENT_TYPES = {
|
|
32752
|
+
GenericPayment: [
|
|
32753
|
+
{ name: "payerAddress", type: "address" },
|
|
32754
|
+
{ name: "opType", type: "string" },
|
|
32755
|
+
{ name: "opId", type: "bytes32" },
|
|
32756
|
+
{ name: "asset", type: "address" },
|
|
32757
|
+
{ name: "amount", type: "uint256" },
|
|
32758
|
+
{ name: "paymentNonce", type: "uint256" }
|
|
32759
|
+
]
|
|
32760
|
+
};
|
|
32761
|
+
var ADD_DATA_TYPES = {
|
|
32762
|
+
AddData: [
|
|
32763
|
+
{ name: "ownerAddress", type: "address" },
|
|
32764
|
+
{ name: "scope", type: "string" },
|
|
32765
|
+
{ name: "dataHash", type: "bytes32" },
|
|
32766
|
+
{ name: "metadataHash", type: "bytes32" },
|
|
32767
|
+
{ name: "expectedVersion", type: "uint256" }
|
|
32768
|
+
]
|
|
32769
|
+
};
|
|
32770
|
+
var RECORD_DATA_ACCESS_TYPES = {
|
|
32771
|
+
RecordDataAccess: [
|
|
32772
|
+
{ name: "ownerAddress", type: "address" },
|
|
32773
|
+
{ name: "scope", type: "string" },
|
|
32774
|
+
{ name: "version", type: "uint256" },
|
|
32775
|
+
{ name: "accessor", type: "address" },
|
|
32776
|
+
{ name: "recordId", type: "bytes32" }
|
|
32777
|
+
]
|
|
32778
|
+
};
|
|
32483
32779
|
|
|
32484
|
-
// src/protocol/
|
|
32780
|
+
// src/protocol/personal-server-registration.ts
|
|
32485
32781
|
var import_viem14 = require("viem");
|
|
32486
|
-
|
|
32487
|
-
|
|
32782
|
+
var PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID = 1480;
|
|
32783
|
+
var PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT = "0x1483B1F634DBA75AeaE60da7f01A679aabd5ee2c";
|
|
32784
|
+
function assertAddress(value, name) {
|
|
32785
|
+
if (!(0, import_viem14.isAddress)(value)) {
|
|
32786
|
+
throw new Error(`${name} must be a valid EVM address`);
|
|
32787
|
+
}
|
|
32488
32788
|
}
|
|
32489
|
-
function
|
|
32490
|
-
if (
|
|
32491
|
-
return
|
|
32789
|
+
function getAccountAddress(account) {
|
|
32790
|
+
if (!account) {
|
|
32791
|
+
return void 0;
|
|
32492
32792
|
}
|
|
32493
|
-
|
|
32494
|
-
|
|
32495
|
-
|
|
32496
|
-
|
|
32793
|
+
return typeof account === "string" ? account : account.address;
|
|
32794
|
+
}
|
|
32795
|
+
function isPersonalServerRegistrationSigner(source) {
|
|
32796
|
+
return "address" in source && typeof source.signTypedData === "function";
|
|
32797
|
+
}
|
|
32798
|
+
function createViemPersonalServerRegistrationSigner(source, options = {}) {
|
|
32799
|
+
if (isPersonalServerRegistrationSigner(source)) {
|
|
32800
|
+
return source;
|
|
32497
32801
|
}
|
|
32498
|
-
const
|
|
32499
|
-
|
|
32802
|
+
const accountAddress = getAccountAddress(options.account) ?? getAccountAddress(source.account);
|
|
32803
|
+
if (accountAddress) {
|
|
32804
|
+
return {
|
|
32805
|
+
address: accountAddress,
|
|
32806
|
+
signTypedData: (typedData) => source.signTypedData({
|
|
32807
|
+
...typedData,
|
|
32808
|
+
account: options.account ?? source.account ?? accountAddress
|
|
32809
|
+
})
|
|
32810
|
+
};
|
|
32811
|
+
}
|
|
32812
|
+
throw new Error(
|
|
32813
|
+
"Viem wallet client requires an account option or account property"
|
|
32814
|
+
);
|
|
32500
32815
|
}
|
|
32501
|
-
function
|
|
32502
|
-
|
|
32503
|
-
|
|
32504
|
-
parsed = JSON.parse(grant);
|
|
32505
|
-
} catch {
|
|
32506
|
-
return null;
|
|
32816
|
+
function personalServerRegistrationDomain(input = {}) {
|
|
32817
|
+
if (input.config) {
|
|
32818
|
+
return serverRegistrationDomain(input.config);
|
|
32507
32819
|
}
|
|
32508
|
-
|
|
32509
|
-
|
|
32820
|
+
const verifyingContract = input.verifyingContract ?? PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT;
|
|
32821
|
+
assertAddress(verifyingContract, "verifyingContract");
|
|
32822
|
+
return {
|
|
32823
|
+
name: "Vana Data Portability",
|
|
32824
|
+
version: "1",
|
|
32825
|
+
chainId: input.chainId ?? PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,
|
|
32826
|
+
verifyingContract
|
|
32827
|
+
};
|
|
32828
|
+
}
|
|
32829
|
+
function buildPersonalServerRegistrationTypedData(input) {
|
|
32830
|
+
assertAddress(input.ownerAddress, "ownerAddress");
|
|
32831
|
+
assertAddress(input.serverAddress, "serverAddress");
|
|
32832
|
+
return {
|
|
32833
|
+
domain: personalServerRegistrationDomain(input),
|
|
32834
|
+
types: SERVER_REGISTRATION_TYPES,
|
|
32835
|
+
primaryType: "ServerRegistration",
|
|
32836
|
+
message: {
|
|
32837
|
+
ownerAddress: input.ownerAddress,
|
|
32838
|
+
serverAddress: input.serverAddress,
|
|
32839
|
+
publicKey: input.serverPublicKey,
|
|
32840
|
+
serverUrl: input.serverUrl
|
|
32841
|
+
}
|
|
32842
|
+
};
|
|
32843
|
+
}
|
|
32844
|
+
async function buildPersonalServerRegistrationSignature(input) {
|
|
32845
|
+
const typedData = buildPersonalServerRegistrationTypedData({
|
|
32846
|
+
ownerAddress: input.signer.address,
|
|
32847
|
+
serverAddress: input.serverAddress,
|
|
32848
|
+
serverPublicKey: input.serverPublicKey,
|
|
32849
|
+
serverUrl: input.serverUrl,
|
|
32850
|
+
config: input.config,
|
|
32851
|
+
chainId: input.chainId,
|
|
32852
|
+
verifyingContract: input.verifyingContract
|
|
32853
|
+
});
|
|
32854
|
+
const signature = await input.signer.signTypedData(typedData);
|
|
32855
|
+
return {
|
|
32856
|
+
signature,
|
|
32857
|
+
signerAddress: input.signer.address,
|
|
32858
|
+
typedData
|
|
32859
|
+
};
|
|
32860
|
+
}
|
|
32861
|
+
var registerPersonalServerSignature = buildPersonalServerRegistrationSignature;
|
|
32862
|
+
|
|
32863
|
+
// src/protocol/personal-server-lite-owner-binding.ts
|
|
32864
|
+
var import_viem15 = require("viem");
|
|
32865
|
+
var PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION = "vana.account.v1";
|
|
32866
|
+
var PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE = "ps-lite-owner";
|
|
32867
|
+
var PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX = `${PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION}:${PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE}:`;
|
|
32868
|
+
function assertAddress2(value, name) {
|
|
32869
|
+
if (!(0, import_viem15.isAddress)(value)) {
|
|
32870
|
+
throw new Error(`${name} must be a valid EVM address`);
|
|
32510
32871
|
}
|
|
32511
|
-
|
|
32512
|
-
|
|
32513
|
-
|
|
32872
|
+
}
|
|
32873
|
+
function getAccountAddress2(account) {
|
|
32874
|
+
if (!account) {
|
|
32875
|
+
return void 0;
|
|
32514
32876
|
}
|
|
32515
|
-
|
|
32516
|
-
|
|
32877
|
+
return typeof account === "string" ? account : account.address;
|
|
32878
|
+
}
|
|
32879
|
+
function isPersonalServerLiteOwnerBindingSigner(source) {
|
|
32880
|
+
return "address" in source && typeof source.signMessage === "function";
|
|
32881
|
+
}
|
|
32882
|
+
function buildPersonalServerLiteOwnerBindingMessage(ownerAddress) {
|
|
32883
|
+
assertAddress2(ownerAddress, "ownerAddress");
|
|
32884
|
+
return `${PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX}${ownerAddress.toLowerCase()}`;
|
|
32885
|
+
}
|
|
32886
|
+
function createViemPersonalServerLiteOwnerBindingSigner(source, options = {}) {
|
|
32887
|
+
if (isPersonalServerLiteOwnerBindingSigner(source)) {
|
|
32888
|
+
return source;
|
|
32517
32889
|
}
|
|
32518
|
-
|
|
32519
|
-
|
|
32890
|
+
const accountAddress = getAccountAddress2(options.account) ?? getAccountAddress2(source.account);
|
|
32891
|
+
if (accountAddress) {
|
|
32892
|
+
return {
|
|
32893
|
+
address: accountAddress,
|
|
32894
|
+
signMessage: ({ message }) => source.signMessage({
|
|
32895
|
+
account: options.account ?? source.account ?? accountAddress,
|
|
32896
|
+
message
|
|
32897
|
+
})
|
|
32898
|
+
};
|
|
32520
32899
|
}
|
|
32521
|
-
|
|
32522
|
-
|
|
32900
|
+
throw new Error(
|
|
32901
|
+
"Viem wallet client requires an account option or account property"
|
|
32902
|
+
);
|
|
32903
|
+
}
|
|
32904
|
+
async function buildPersonalServerLiteOwnerBindingSignature(input) {
|
|
32905
|
+
const message = buildPersonalServerLiteOwnerBindingMessage(
|
|
32906
|
+
input.signer.address
|
|
32907
|
+
);
|
|
32908
|
+
const signature = await input.signer.signMessage({ message });
|
|
32909
|
+
return {
|
|
32910
|
+
signature,
|
|
32911
|
+
signerAddress: input.signer.address,
|
|
32912
|
+
message,
|
|
32913
|
+
purpose: PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE
|
|
32914
|
+
};
|
|
32915
|
+
}
|
|
32916
|
+
var signPersonalServerLiteOwnerBinding = buildPersonalServerLiteOwnerBindingSignature;
|
|
32917
|
+
|
|
32918
|
+
// src/account/personal-server-registration.ts
|
|
32919
|
+
var import_viem16 = require("viem");
|
|
32920
|
+
var ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT = "personal_server.server_registration.v1";
|
|
32921
|
+
var AccountPersonalServerRegistrationError = class extends Error {
|
|
32922
|
+
status;
|
|
32923
|
+
code;
|
|
32924
|
+
details;
|
|
32925
|
+
constructor(input) {
|
|
32926
|
+
super(input.message);
|
|
32927
|
+
this.name = "AccountPersonalServerRegistrationError";
|
|
32928
|
+
this.status = input.status;
|
|
32929
|
+
this.code = input.code;
|
|
32930
|
+
this.details = input.details;
|
|
32523
32931
|
}
|
|
32524
|
-
|
|
32525
|
-
|
|
32932
|
+
};
|
|
32933
|
+
var DEFAULT_ACCOUNT_PS_REGISTRATION_PATH = "/api/v1/intents/personal-server-registration/sign";
|
|
32934
|
+
function trimTrailingSlash(value) {
|
|
32935
|
+
return value.replace(/\/+$/, "");
|
|
32936
|
+
}
|
|
32937
|
+
function assertAddress3(value, name) {
|
|
32938
|
+
if (!(0, import_viem16.isAddress)(value)) {
|
|
32939
|
+
throw new Error(`${name} must be a valid EVM address`);
|
|
32526
32940
|
}
|
|
32527
|
-
|
|
32528
|
-
|
|
32941
|
+
}
|
|
32942
|
+
async function parseAccountResponse(response) {
|
|
32943
|
+
const body = await response.json().catch(() => void 0);
|
|
32944
|
+
if (!response.ok) {
|
|
32945
|
+
throw new AccountPersonalServerRegistrationError({
|
|
32946
|
+
status: response.status,
|
|
32947
|
+
code: accountErrorCode(body),
|
|
32948
|
+
message: accountErrorMessage(response.status, body),
|
|
32949
|
+
details: body
|
|
32950
|
+
});
|
|
32951
|
+
}
|
|
32952
|
+
return body;
|
|
32953
|
+
}
|
|
32954
|
+
function accountErrorMessage(status, body) {
|
|
32955
|
+
const nestedMessage = nestedAccountErrorField(body, "message");
|
|
32956
|
+
if (nestedMessage) {
|
|
32957
|
+
return nestedMessage;
|
|
32958
|
+
}
|
|
32959
|
+
if (isRecord(body) && typeof body.message === "string") {
|
|
32960
|
+
return body.message;
|
|
32529
32961
|
}
|
|
32962
|
+
const code = accountErrorCode(body);
|
|
32963
|
+
if (code) {
|
|
32964
|
+
return `Account PS registration signing failed: ${code}`;
|
|
32965
|
+
}
|
|
32966
|
+
return `Account PS registration signing failed: ${status}`;
|
|
32967
|
+
}
|
|
32968
|
+
function accountErrorCode(body) {
|
|
32969
|
+
const nestedCode = nestedAccountErrorField(body, "code");
|
|
32970
|
+
if (nestedCode) {
|
|
32971
|
+
return nestedCode;
|
|
32972
|
+
}
|
|
32973
|
+
if (isRecord(body)) {
|
|
32974
|
+
if (typeof body.code === "string") {
|
|
32975
|
+
return body.code;
|
|
32976
|
+
}
|
|
32977
|
+
if (typeof body.error === "string") {
|
|
32978
|
+
return body.error;
|
|
32979
|
+
}
|
|
32980
|
+
}
|
|
32981
|
+
return void 0;
|
|
32982
|
+
}
|
|
32983
|
+
function nestedAccountErrorField(body, field) {
|
|
32984
|
+
if (!isRecord(body) || !isRecord(body.error)) {
|
|
32985
|
+
return void 0;
|
|
32986
|
+
}
|
|
32987
|
+
const value = body.error[field];
|
|
32988
|
+
return typeof value === "string" ? value : void 0;
|
|
32989
|
+
}
|
|
32990
|
+
function isRecord(value) {
|
|
32991
|
+
return typeof value === "object" && value !== null;
|
|
32992
|
+
}
|
|
32993
|
+
function normalizeAccountResponse(response) {
|
|
32530
32994
|
return {
|
|
32531
|
-
|
|
32532
|
-
|
|
32533
|
-
|
|
32534
|
-
|
|
32535
|
-
nonce: value["nonce"]
|
|
32995
|
+
...response,
|
|
32996
|
+
status: response.status === "fallback_required" ? "confirmation_required" : response.status,
|
|
32997
|
+
signerAddress: response.signerAddress ?? response.signer?.address,
|
|
32998
|
+
typedData: response.typedData ?? response.typed_data
|
|
32536
32999
|
};
|
|
32537
33000
|
}
|
|
32538
|
-
function
|
|
32539
|
-
|
|
32540
|
-
|
|
33001
|
+
function buildSignedResult(response, request) {
|
|
33002
|
+
assertAddress3(response.signerAddress, "signerAddress");
|
|
33003
|
+
if (response.typedData) {
|
|
33004
|
+
assertTypedDataMatchesRequest(
|
|
33005
|
+
response.typedData,
|
|
33006
|
+
request,
|
|
33007
|
+
response.signerAddress
|
|
33008
|
+
);
|
|
33009
|
+
}
|
|
33010
|
+
return {
|
|
33011
|
+
signature: response.signature,
|
|
33012
|
+
signerAddress: response.signerAddress,
|
|
33013
|
+
typedData: response.typedData ?? buildPersonalServerRegistrationTypedData({
|
|
33014
|
+
ownerAddress: response.signerAddress,
|
|
33015
|
+
...request
|
|
33016
|
+
}),
|
|
33017
|
+
intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT
|
|
33018
|
+
};
|
|
33019
|
+
}
|
|
33020
|
+
function assertTypedDataMatchesRequest(typedData, request, expectedSignerAddress) {
|
|
33021
|
+
assertAddress3(
|
|
33022
|
+
typedData.message.ownerAddress,
|
|
33023
|
+
"typedData.message.ownerAddress"
|
|
33024
|
+
);
|
|
33025
|
+
assertAddress3(
|
|
33026
|
+
typedData.message.serverAddress,
|
|
33027
|
+
"typedData.message.serverAddress"
|
|
33028
|
+
);
|
|
33029
|
+
if (expectedSignerAddress && !sameAddress(typedData.message.ownerAddress, expectedSignerAddress)) {
|
|
33030
|
+
throw new Error(
|
|
33031
|
+
"Account typedData ownerAddress must match the expected signer address"
|
|
33032
|
+
);
|
|
33033
|
+
}
|
|
33034
|
+
if (!sameAddress(typedData.message.serverAddress, request.serverAddress)) {
|
|
33035
|
+
throw new Error(
|
|
33036
|
+
"Account typedData serverAddress must match the requested serverAddress"
|
|
33037
|
+
);
|
|
33038
|
+
}
|
|
33039
|
+
if (typedData.message.publicKey !== request.serverPublicKey) {
|
|
33040
|
+
throw new Error(
|
|
33041
|
+
"Account typedData publicKey must match the requested serverPublicKey"
|
|
33042
|
+
);
|
|
33043
|
+
}
|
|
33044
|
+
if (typedData.message.serverUrl !== request.serverUrl) {
|
|
33045
|
+
throw new Error(
|
|
33046
|
+
"Account typedData serverUrl must match the requested serverUrl"
|
|
33047
|
+
);
|
|
33048
|
+
}
|
|
33049
|
+
if (typedData.primaryType !== "ServerRegistration") {
|
|
33050
|
+
throw new Error("Account typedData primaryType must be ServerRegistration");
|
|
33051
|
+
}
|
|
33052
|
+
if (JSON.stringify(typedData.types) !== JSON.stringify(SERVER_REGISTRATION_TYPES)) {
|
|
33053
|
+
throw new Error("Account typedData types must be ServerRegistration types");
|
|
33054
|
+
}
|
|
33055
|
+
const expectedDomain = personalServerRegistrationDomain({
|
|
33056
|
+
config: request.config,
|
|
33057
|
+
chainId: request.chainId,
|
|
33058
|
+
verifyingContract: request.verifyingContract
|
|
33059
|
+
});
|
|
33060
|
+
if (!domainsEqual(typedData.domain, expectedDomain)) {
|
|
33061
|
+
throw new Error("Account typedData domain must match the requested domain");
|
|
33062
|
+
}
|
|
33063
|
+
}
|
|
33064
|
+
function sameAddress(a, b) {
|
|
33065
|
+
return a.toLowerCase() === b.toLowerCase();
|
|
33066
|
+
}
|
|
33067
|
+
function domainsEqual(a, b) {
|
|
33068
|
+
if (!a || !b) {
|
|
33069
|
+
return false;
|
|
33070
|
+
}
|
|
33071
|
+
return a.name === b.name && a.version === b.version && Number(a.chainId) === Number(b.chainId) && String(a.verifyingContract ?? "").toLowerCase() === String(b.verifyingContract ?? "").toLowerCase() && a.salt === b.salt;
|
|
33072
|
+
}
|
|
33073
|
+
async function signPersonalServerRegistrationWithAccount(config, request) {
|
|
33074
|
+
assertAddress3(request.serverAddress, "serverAddress");
|
|
33075
|
+
const fetchImpl = config.fetchImpl ?? globalThis.fetch.bind(globalThis);
|
|
33076
|
+
const endpoint = new URL(
|
|
33077
|
+
config.endpointPath ?? DEFAULT_ACCOUNT_PS_REGISTRATION_PATH,
|
|
33078
|
+
`${trimTrailingSlash(config.accountOrigin)}/`
|
|
33079
|
+
);
|
|
33080
|
+
const response = await fetchImpl(endpoint, {
|
|
33081
|
+
method: "POST",
|
|
33082
|
+
headers: { "content-type": "application/json" },
|
|
33083
|
+
credentials: "include",
|
|
33084
|
+
body: JSON.stringify({
|
|
33085
|
+
intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
|
|
33086
|
+
serverAddress: request.serverAddress,
|
|
33087
|
+
serverPublicKey: request.serverPublicKey,
|
|
33088
|
+
serverUrl: request.serverUrl,
|
|
33089
|
+
config: request.config,
|
|
33090
|
+
chainId: request.chainId,
|
|
33091
|
+
verifyingContract: request.verifyingContract
|
|
33092
|
+
})
|
|
33093
|
+
});
|
|
33094
|
+
const body = normalizeAccountResponse(await parseAccountResponse(response));
|
|
33095
|
+
if (body.status === "signed") {
|
|
33096
|
+
if (!body.signature || !body.signerAddress) {
|
|
33097
|
+
throw new Error(
|
|
33098
|
+
"Account signed response must include signature and signerAddress"
|
|
33099
|
+
);
|
|
33100
|
+
}
|
|
33101
|
+
return {
|
|
33102
|
+
status: "signed",
|
|
33103
|
+
result: buildSignedResult(
|
|
33104
|
+
{
|
|
33105
|
+
signature: body.signature,
|
|
33106
|
+
signerAddress: body.signerAddress,
|
|
33107
|
+
typedData: body.typedData
|
|
33108
|
+
},
|
|
33109
|
+
request
|
|
33110
|
+
)
|
|
33111
|
+
};
|
|
33112
|
+
}
|
|
33113
|
+
if (body.status === "confirmation_required") {
|
|
33114
|
+
if (!body.typedData) {
|
|
33115
|
+
throw new Error(
|
|
33116
|
+
"Account confirmation_required response must include typedData"
|
|
33117
|
+
);
|
|
33118
|
+
}
|
|
33119
|
+
assertTypedDataMatchesRequest(body.typedData, request, body.signerAddress);
|
|
33120
|
+
if (!config.fallbackSigner) {
|
|
33121
|
+
return {
|
|
33122
|
+
status: "confirmation_required",
|
|
33123
|
+
typedData: body.typedData,
|
|
33124
|
+
signerAddress: body.signerAddress
|
|
33125
|
+
};
|
|
33126
|
+
}
|
|
33127
|
+
assertTypedDataMatchesRequest(
|
|
33128
|
+
body.typedData,
|
|
33129
|
+
request,
|
|
33130
|
+
config.fallbackSigner.address
|
|
33131
|
+
);
|
|
33132
|
+
const signature = await config.fallbackSigner.signTypedData(body.typedData);
|
|
32541
33133
|
return {
|
|
32542
|
-
|
|
32543
|
-
|
|
33134
|
+
status: "fallback_signed",
|
|
33135
|
+
accountStatus: "confirmation_required",
|
|
33136
|
+
result: {
|
|
33137
|
+
signature,
|
|
33138
|
+
signerAddress: config.fallbackSigner.address,
|
|
33139
|
+
typedData: body.typedData,
|
|
33140
|
+
intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT
|
|
33141
|
+
}
|
|
32544
33142
|
};
|
|
33143
|
+
}
|
|
33144
|
+
throw new Error(
|
|
33145
|
+
`Unsupported Account PS registration signing status: ${String(body.status)}`
|
|
33146
|
+
);
|
|
33147
|
+
}
|
|
33148
|
+
|
|
33149
|
+
// src/account/personal-server-lite-owner-binding.ts
|
|
33150
|
+
var AccountPersonalServerLiteOwnerBindingError = class extends Error {
|
|
33151
|
+
code;
|
|
33152
|
+
details;
|
|
33153
|
+
constructor(input) {
|
|
33154
|
+
super(input.message);
|
|
33155
|
+
this.name = "AccountPersonalServerLiteOwnerBindingError";
|
|
33156
|
+
this.code = input.code;
|
|
33157
|
+
this.details = input.details;
|
|
33158
|
+
}
|
|
33159
|
+
};
|
|
33160
|
+
async function signPersonalServerLiteOwnerBindingWithAccountClient(config) {
|
|
33161
|
+
let address;
|
|
33162
|
+
try {
|
|
33163
|
+
address = await config.client.getAddress();
|
|
33164
|
+
} catch (error) {
|
|
33165
|
+
throw accountOwnerBindingError(error);
|
|
33166
|
+
}
|
|
33167
|
+
if (!address) {
|
|
33168
|
+
throw new AccountPersonalServerLiteOwnerBindingError({
|
|
33169
|
+
message: "Account did not return a wallet address",
|
|
33170
|
+
code: "account_address_required"
|
|
33171
|
+
});
|
|
33172
|
+
}
|
|
33173
|
+
const message = buildPersonalServerLiteOwnerBindingMessage(address);
|
|
33174
|
+
let signature;
|
|
33175
|
+
try {
|
|
33176
|
+
signature = await config.client.signMessage({ message });
|
|
33177
|
+
} catch (error) {
|
|
33178
|
+
throw accountOwnerBindingError(error);
|
|
33179
|
+
}
|
|
33180
|
+
return {
|
|
33181
|
+
signature,
|
|
33182
|
+
signerAddress: address,
|
|
33183
|
+
message,
|
|
33184
|
+
purpose: PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE
|
|
33185
|
+
};
|
|
33186
|
+
}
|
|
33187
|
+
function accountOwnerBindingError(error) {
|
|
33188
|
+
if (error instanceof AccountPersonalServerLiteOwnerBindingError) {
|
|
33189
|
+
return error;
|
|
33190
|
+
}
|
|
33191
|
+
const rpcError = error;
|
|
33192
|
+
const code = rpcError?.code;
|
|
33193
|
+
const message = typeof rpcError?.message === "string" && rpcError.message.length > 0 ? rpcError.message : "Account PS Lite owner-binding signature failed";
|
|
33194
|
+
return new AccountPersonalServerLiteOwnerBindingError({
|
|
33195
|
+
message,
|
|
33196
|
+
code,
|
|
33197
|
+
details: error
|
|
33198
|
+
});
|
|
33199
|
+
}
|
|
33200
|
+
|
|
33201
|
+
// src/protocol/grants.ts
|
|
33202
|
+
var import_viem17 = require("viem");
|
|
33203
|
+
function isHexString(value) {
|
|
33204
|
+
return typeof value === "string" && value.startsWith("0x");
|
|
33205
|
+
}
|
|
33206
|
+
function isDataPortabilityGatewayConfig(value) {
|
|
33207
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
33208
|
+
return false;
|
|
33209
|
+
}
|
|
33210
|
+
const config = value;
|
|
33211
|
+
const contracts = config["contracts"];
|
|
33212
|
+
if (typeof config["chainId"] !== "number" || !Number.isInteger(config["chainId"]) || config["chainId"] <= 0 || contracts === null || typeof contracts !== "object" || Array.isArray(contracts)) {
|
|
33213
|
+
return false;
|
|
33214
|
+
}
|
|
33215
|
+
const c = contracts;
|
|
33216
|
+
return isHexString(c["dataRegistry"]) && isHexString(c["dataPortabilityPermissions"]) && isHexString(c["dataPortabilityServer"]) && isHexString(c["dataPortabilityGrantees"]) && isHexString(c["dataPortabilityEscrow"]);
|
|
33217
|
+
}
|
|
33218
|
+
function toUint256(value) {
|
|
33219
|
+
try {
|
|
33220
|
+
const big = typeof value === "bigint" ? value : BigInt(value);
|
|
33221
|
+
if (big < 0n) return null;
|
|
33222
|
+
return big;
|
|
32545
33223
|
} catch {
|
|
32546
33224
|
return null;
|
|
32547
33225
|
}
|
|
32548
33226
|
}
|
|
32549
33227
|
async function verifyGrantRegistration(input) {
|
|
32550
|
-
|
|
32551
|
-
|
|
32552
|
-
|
|
32553
|
-
|
|
32554
|
-
|
|
32555
|
-
|
|
33228
|
+
if (!Array.isArray(input.scopes) || input.scopes.length === 0) {
|
|
33229
|
+
return { valid: false, error: "scopes must be a non-empty array" };
|
|
33230
|
+
}
|
|
33231
|
+
if (!input.scopes.every((scope) => typeof scope === "string")) {
|
|
33232
|
+
return { valid: false, error: "scopes must contain only strings" };
|
|
33233
|
+
}
|
|
33234
|
+
const grantVersion = toUint256(input.grantVersion);
|
|
33235
|
+
if (grantVersion === null || grantVersion < 1n) {
|
|
33236
|
+
return { valid: false, error: "grantVersion must be a uint256 >= 1" };
|
|
32556
33237
|
}
|
|
32557
|
-
const
|
|
32558
|
-
if (
|
|
32559
|
-
return { valid: false, error: "
|
|
33238
|
+
const expiresAt = toUint256(input.expiresAt);
|
|
33239
|
+
if (expiresAt === null) {
|
|
33240
|
+
return { valid: false, error: "expiresAt must be a non-negative uint256" };
|
|
32560
33241
|
}
|
|
32561
33242
|
let valid;
|
|
32562
33243
|
try {
|
|
32563
|
-
valid = await (0,
|
|
33244
|
+
valid = await (0, import_viem17.verifyTypedData)({
|
|
32564
33245
|
address: input.grantorAddress,
|
|
32565
33246
|
domain: grantRegistrationDomain(input.gatewayConfig),
|
|
32566
33247
|
types: GRANT_REGISTRATION_TYPES,
|
|
@@ -32568,8 +33249,9 @@ async function verifyGrantRegistration(input) {
|
|
|
32568
33249
|
message: {
|
|
32569
33250
|
grantorAddress: input.grantorAddress,
|
|
32570
33251
|
granteeId: input.granteeId,
|
|
32571
|
-
|
|
32572
|
-
|
|
33252
|
+
scopes: input.scopes,
|
|
33253
|
+
grantVersion,
|
|
33254
|
+
expiresAt
|
|
32573
33255
|
},
|
|
32574
33256
|
signature: input.signature
|
|
32575
33257
|
});
|
|
@@ -32580,19 +33262,69 @@ async function verifyGrantRegistration(input) {
|
|
|
32580
33262
|
return { valid: false, error: "Grant signature does not match grantor" };
|
|
32581
33263
|
}
|
|
32582
33264
|
const nowSeconds = input.nowSeconds ?? Math.floor(Date.now() / 1e3);
|
|
32583
|
-
if (
|
|
33265
|
+
if (expiresAt > 0n && expiresAt < BigInt(nowSeconds)) {
|
|
32584
33266
|
return { valid: false, error: "Grant has expired" };
|
|
32585
33267
|
}
|
|
32586
|
-
if (payload.user !== void 0 && payload.user.toLowerCase() !== input.grantorAddress.toLowerCase()) {
|
|
32587
|
-
return { valid: false, error: "Grant user does not match grantorAddress" };
|
|
32588
|
-
}
|
|
32589
33268
|
return {
|
|
32590
33269
|
valid: true,
|
|
32591
33270
|
grantorAddress: input.grantorAddress,
|
|
32592
33271
|
granteeId: input.granteeId,
|
|
32593
|
-
|
|
32594
|
-
|
|
32595
|
-
|
|
33272
|
+
scopes: input.scopes,
|
|
33273
|
+
grantVersion: grantVersion.toString(),
|
|
33274
|
+
expiresAt: expiresAt.toString()
|
|
33275
|
+
};
|
|
33276
|
+
}
|
|
33277
|
+
|
|
33278
|
+
// src/protocol/escrow-deposit.ts
|
|
33279
|
+
var import_viem18 = require("viem");
|
|
33280
|
+
var ESCROW_DEPOSIT_ABI = [
|
|
33281
|
+
{
|
|
33282
|
+
type: "function",
|
|
33283
|
+
name: "depositNative",
|
|
33284
|
+
stateMutability: "payable",
|
|
33285
|
+
inputs: [{ name: "account", type: "address" }],
|
|
33286
|
+
outputs: []
|
|
33287
|
+
},
|
|
33288
|
+
{
|
|
33289
|
+
type: "function",
|
|
33290
|
+
name: "depositToken",
|
|
33291
|
+
stateMutability: "nonpayable",
|
|
33292
|
+
inputs: [
|
|
33293
|
+
{ name: "account", type: "address" },
|
|
33294
|
+
{ name: "token", type: "address" },
|
|
33295
|
+
{ name: "amount", type: "uint256" }
|
|
33296
|
+
],
|
|
33297
|
+
outputs: []
|
|
33298
|
+
}
|
|
33299
|
+
];
|
|
33300
|
+
function escrowContractAddress(config) {
|
|
33301
|
+
return config.contracts.dataPortabilityEscrow;
|
|
33302
|
+
}
|
|
33303
|
+
function encodeDepositNativeData(input) {
|
|
33304
|
+
return (0, import_viem18.encodeFunctionData)({
|
|
33305
|
+
abi: ESCROW_DEPOSIT_ABI,
|
|
33306
|
+
functionName: "depositNative",
|
|
33307
|
+
args: [input.account]
|
|
33308
|
+
});
|
|
33309
|
+
}
|
|
33310
|
+
function encodeDepositTokenData(input) {
|
|
33311
|
+
return (0, import_viem18.encodeFunctionData)({
|
|
33312
|
+
abi: ESCROW_DEPOSIT_ABI,
|
|
33313
|
+
functionName: "depositToken",
|
|
33314
|
+
args: [input.account, input.token, input.amount]
|
|
33315
|
+
});
|
|
33316
|
+
}
|
|
33317
|
+
function buildDepositNativeRequest(config, input) {
|
|
33318
|
+
return {
|
|
33319
|
+
to: escrowContractAddress(config),
|
|
33320
|
+
data: encodeDepositNativeData({ account: input.account }),
|
|
33321
|
+
value: input.amount
|
|
33322
|
+
};
|
|
33323
|
+
}
|
|
33324
|
+
function buildDepositTokenRequest(config, input) {
|
|
33325
|
+
return {
|
|
33326
|
+
to: escrowContractAddress(config),
|
|
33327
|
+
data: encodeDepositTokenData(input)
|
|
32596
33328
|
};
|
|
32597
33329
|
}
|
|
32598
33330
|
|
|
@@ -32792,6 +33524,68 @@ function createGatewayClient(baseUrl) {
|
|
|
32792
33524
|
alreadyRegistered: false
|
|
32793
33525
|
};
|
|
32794
33526
|
},
|
|
33527
|
+
async registerBuilder(params) {
|
|
33528
|
+
const res = await fetch(`${base}/v1/builders`, {
|
|
33529
|
+
method: "POST",
|
|
33530
|
+
headers: {
|
|
33531
|
+
"Content-Type": "application/json",
|
|
33532
|
+
Authorization: `Web3Signed ${params.signature}`
|
|
33533
|
+
},
|
|
33534
|
+
body: JSON.stringify({
|
|
33535
|
+
ownerAddress: params.ownerAddress,
|
|
33536
|
+
granteeAddress: params.granteeAddress,
|
|
33537
|
+
publicKey: params.publicKey,
|
|
33538
|
+
appUrl: params.appUrl
|
|
33539
|
+
})
|
|
33540
|
+
});
|
|
33541
|
+
if (res.status === 409) {
|
|
33542
|
+
const body2 = await res.json().catch(() => ({}));
|
|
33543
|
+
return {
|
|
33544
|
+
builderId: getMutationId(
|
|
33545
|
+
body2,
|
|
33546
|
+
"builderId"
|
|
33547
|
+
),
|
|
33548
|
+
alreadyRegistered: true
|
|
33549
|
+
};
|
|
33550
|
+
}
|
|
33551
|
+
if (!res.ok) {
|
|
33552
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33553
|
+
}
|
|
33554
|
+
const body = await res.json().catch(() => ({}));
|
|
33555
|
+
return {
|
|
33556
|
+
builderId: getMutationId(body, "builderId"),
|
|
33557
|
+
alreadyRegistered: false
|
|
33558
|
+
};
|
|
33559
|
+
},
|
|
33560
|
+
async registerDataPoint(params) {
|
|
33561
|
+
const res = await fetch(`${base}/v1/data`, {
|
|
33562
|
+
method: "POST",
|
|
33563
|
+
headers: {
|
|
33564
|
+
"Content-Type": "application/json",
|
|
33565
|
+
Authorization: `Web3Signed ${params.signature}`
|
|
33566
|
+
},
|
|
33567
|
+
body: JSON.stringify({
|
|
33568
|
+
ownerAddress: params.ownerAddress,
|
|
33569
|
+
scope: params.scope,
|
|
33570
|
+
dataHash: params.dataHash,
|
|
33571
|
+
metadataHash: params.metadataHash,
|
|
33572
|
+
expectedVersion: params.expectedVersion
|
|
33573
|
+
})
|
|
33574
|
+
});
|
|
33575
|
+
if (!res.ok) {
|
|
33576
|
+
const body2 = await res.json().catch(() => ({}));
|
|
33577
|
+
const detail = body2.error ?? res.statusText;
|
|
33578
|
+
throw new Error(`Gateway error: ${res.status} ${detail}`);
|
|
33579
|
+
}
|
|
33580
|
+
const body = await res.json().catch(() => ({}));
|
|
33581
|
+
return {
|
|
33582
|
+
dataPointId: getMutationId(
|
|
33583
|
+
body,
|
|
33584
|
+
"dataPointId"
|
|
33585
|
+
),
|
|
33586
|
+
expectedVersion: body.expectedVersion
|
|
33587
|
+
};
|
|
33588
|
+
},
|
|
32795
33589
|
async registerFile(params) {
|
|
32796
33590
|
const res = await fetch(`${base}/v1/files`, {
|
|
32797
33591
|
method: "POST",
|
|
@@ -32829,8 +33623,9 @@ function createGatewayClient(baseUrl) {
|
|
|
32829
33623
|
body: JSON.stringify({
|
|
32830
33624
|
grantorAddress: params.grantorAddress,
|
|
32831
33625
|
granteeId: params.granteeId,
|
|
32832
|
-
|
|
32833
|
-
|
|
33626
|
+
scopes: params.scopes,
|
|
33627
|
+
grantVersion: params.grantVersion,
|
|
33628
|
+
expiresAt: params.expiresAt
|
|
32834
33629
|
})
|
|
32835
33630
|
});
|
|
32836
33631
|
if (res.status === 409) {
|
|
@@ -32855,13 +33650,71 @@ function createGatewayClient(baseUrl) {
|
|
|
32855
33650
|
Authorization: `Web3Signed ${params.signature}`
|
|
32856
33651
|
},
|
|
32857
33652
|
body: JSON.stringify({
|
|
32858
|
-
grantorAddress: params.grantorAddress
|
|
33653
|
+
grantorAddress: params.grantorAddress,
|
|
33654
|
+
grantVersion: params.grantVersion
|
|
32859
33655
|
})
|
|
32860
33656
|
});
|
|
32861
33657
|
if (res.status === 409) return;
|
|
32862
33658
|
if (!res.ok) {
|
|
32863
33659
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
32864
33660
|
}
|
|
33661
|
+
},
|
|
33662
|
+
async getEscrowBalance(account) {
|
|
33663
|
+
const res = await fetch(`${base}/v1/escrow/balance?account=${account}`);
|
|
33664
|
+
if (!res.ok) {
|
|
33665
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33666
|
+
}
|
|
33667
|
+
return await res.json();
|
|
33668
|
+
},
|
|
33669
|
+
async submitEscrowDeposit(params) {
|
|
33670
|
+
const res = await fetch(`${base}/v1/escrow/deposit`, {
|
|
33671
|
+
method: "POST",
|
|
33672
|
+
headers: { "Content-Type": "application/json" },
|
|
33673
|
+
body: JSON.stringify({ txHash: params.txHash })
|
|
33674
|
+
});
|
|
33675
|
+
if (res.status !== 200 && res.status !== 202) {
|
|
33676
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33677
|
+
}
|
|
33678
|
+
return await res.json();
|
|
33679
|
+
},
|
|
33680
|
+
async payForOperation(params) {
|
|
33681
|
+
const body = {
|
|
33682
|
+
payerAddress: params.payerAddress,
|
|
33683
|
+
opType: params.opType,
|
|
33684
|
+
opId: params.opId,
|
|
33685
|
+
asset: params.asset,
|
|
33686
|
+
amount: params.amount,
|
|
33687
|
+
paymentNonce: params.paymentNonce
|
|
33688
|
+
};
|
|
33689
|
+
if (params.accessRecord) {
|
|
33690
|
+
body["accessRecord"] = params.accessRecord;
|
|
33691
|
+
}
|
|
33692
|
+
const res = await fetch(`${base}/v1/escrow/pay`, {
|
|
33693
|
+
method: "POST",
|
|
33694
|
+
headers: {
|
|
33695
|
+
"Content-Type": "application/json",
|
|
33696
|
+
Authorization: `Web3Signed ${params.signature}`
|
|
33697
|
+
},
|
|
33698
|
+
body: JSON.stringify(body)
|
|
33699
|
+
});
|
|
33700
|
+
if (!res.ok) {
|
|
33701
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33702
|
+
}
|
|
33703
|
+
return await res.json();
|
|
33704
|
+
},
|
|
33705
|
+
async settle(params) {
|
|
33706
|
+
const res = await fetch(`${base}/v1/settle`, {
|
|
33707
|
+
method: "POST",
|
|
33708
|
+
headers: { "Content-Type": "application/json" },
|
|
33709
|
+
// The gateway accepts an empty body; only `limit` is recognised.
|
|
33710
|
+
// Always send a JSON body so the gateway's req.body shape parse
|
|
33711
|
+
// doesn't have to deal with an undefined.
|
|
33712
|
+
body: JSON.stringify(params ?? {})
|
|
33713
|
+
});
|
|
33714
|
+
if (!res.ok) {
|
|
33715
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33716
|
+
}
|
|
33717
|
+
return await res.json();
|
|
32865
33718
|
}
|
|
32866
33719
|
};
|
|
32867
33720
|
}
|
|
@@ -32891,7 +33744,7 @@ var KNOWN_CODES = /* @__PURE__ */ new Set([
|
|
|
32891
33744
|
"server_not_configured",
|
|
32892
33745
|
"content_too_large"
|
|
32893
33746
|
]);
|
|
32894
|
-
function
|
|
33747
|
+
function isRecord2(value) {
|
|
32895
33748
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
32896
33749
|
}
|
|
32897
33750
|
function normalizeCode(value) {
|
|
@@ -32902,10 +33755,10 @@ function normalizeCode(value) {
|
|
|
32902
33755
|
return KNOWN_CODES.has(code) ? code : null;
|
|
32903
33756
|
}
|
|
32904
33757
|
function extractPSErrorBody(body) {
|
|
32905
|
-
if (!
|
|
33758
|
+
if (!isRecord2(body)) {
|
|
32906
33759
|
return null;
|
|
32907
33760
|
}
|
|
32908
|
-
const nested =
|
|
33761
|
+
const nested = isRecord2(body.error) ? body.error : null;
|
|
32909
33762
|
const code = normalizeCode(
|
|
32910
33763
|
nested?.errorCode ?? nested?.code ?? body.errorCode ?? body.code
|
|
32911
33764
|
);
|
|
@@ -32930,6 +33783,10 @@ async function parsePSError(response) {
|
|
|
32930
33783
|
}
|
|
32931
33784
|
// Annotate the CommonJS export names for ESM import in node:
|
|
32932
33785
|
0 && (module.exports = {
|
|
33786
|
+
ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
|
|
33787
|
+
ADD_DATA_TYPES,
|
|
33788
|
+
AccountPersonalServerLiteOwnerBindingError,
|
|
33789
|
+
AccountPersonalServerRegistrationError,
|
|
32933
33790
|
BUILDER_REGISTRATION_TYPES,
|
|
32934
33791
|
BlockchainError,
|
|
32935
33792
|
BrowserPlatformAdapter,
|
|
@@ -32940,8 +33797,10 @@ async function parsePSError(response) {
|
|
|
32940
33797
|
DataFileEnvelopeSchema,
|
|
32941
33798
|
DropboxStorage,
|
|
32942
33799
|
ECIESError,
|
|
33800
|
+
ESCROW_DEPOSIT_ABI,
|
|
32943
33801
|
ExpiredTokenError,
|
|
32944
33802
|
FILE_REGISTRATION_TYPES,
|
|
33803
|
+
GENERIC_PAYMENT_TYPES,
|
|
32945
33804
|
GRANT_REGISTRATION_TYPES,
|
|
32946
33805
|
GRANT_REVOCATION_TYPES,
|
|
32947
33806
|
GoogleDriveStorage,
|
|
@@ -32952,10 +33811,17 @@ async function parsePSError(response) {
|
|
|
32952
33811
|
IpfsStorage,
|
|
32953
33812
|
MASTER_KEY_MESSAGE,
|
|
32954
33813
|
MissingAuthError,
|
|
33814
|
+
NATIVE_VANA_ASSET,
|
|
32955
33815
|
NetworkError,
|
|
32956
33816
|
NodeECIESProvider,
|
|
32957
33817
|
NodePlatformAdapter,
|
|
32958
33818
|
NonceError,
|
|
33819
|
+
OAuthClient,
|
|
33820
|
+
PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX,
|
|
33821
|
+
PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE,
|
|
33822
|
+
PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION,
|
|
33823
|
+
PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,
|
|
33824
|
+
PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT,
|
|
32959
33825
|
PKCE_CHALLENGE_PATTERN,
|
|
32960
33826
|
PKCE_VERIFIER_PATTERN,
|
|
32961
33827
|
PSError,
|
|
@@ -32963,6 +33829,7 @@ async function parsePSError(response) {
|
|
|
32963
33829
|
PersonalServerError,
|
|
32964
33830
|
PinataStorage,
|
|
32965
33831
|
R2Storage,
|
|
33832
|
+
RECORD_DATA_ACCESS_TYPES,
|
|
32966
33833
|
ReadOnlyError,
|
|
32967
33834
|
RelayerError,
|
|
32968
33835
|
SERVER_REGISTRATION_TYPES,
|
|
@@ -32977,6 +33844,12 @@ async function parsePSError(response) {
|
|
|
32977
33844
|
VanaError,
|
|
32978
33845
|
VanaStorage,
|
|
32979
33846
|
assertValidPkceVerifier,
|
|
33847
|
+
buildDepositNativeRequest,
|
|
33848
|
+
buildDepositTokenRequest,
|
|
33849
|
+
buildPersonalServerLiteOwnerBindingMessage,
|
|
33850
|
+
buildPersonalServerLiteOwnerBindingSignature,
|
|
33851
|
+
buildPersonalServerRegistrationSignature,
|
|
33852
|
+
buildPersonalServerRegistrationTypedData,
|
|
32980
33853
|
buildWeb3SignedHeader,
|
|
32981
33854
|
builderRegistrationDomain,
|
|
32982
33855
|
chains,
|
|
@@ -32992,12 +33865,19 @@ async function parsePSError(response) {
|
|
|
32992
33865
|
createPlatformAdapterFor,
|
|
32993
33866
|
createPlatformAdapterSafe,
|
|
32994
33867
|
createVanaStorageProvider,
|
|
33868
|
+
createViemPersonalServerLiteOwnerBindingSigner,
|
|
33869
|
+
createViemPersonalServerRegistrationSigner,
|
|
33870
|
+
dataRegistryDomain,
|
|
32995
33871
|
decryptWithPassword,
|
|
32996
33872
|
deriveMasterKey,
|
|
32997
33873
|
deriveScopeKey,
|
|
32998
33874
|
deserializeECIES,
|
|
32999
33875
|
detectPlatform,
|
|
33876
|
+
encodeDepositNativeData,
|
|
33877
|
+
encodeDepositTokenData,
|
|
33000
33878
|
encryptWithPassword,
|
|
33879
|
+
escrowContractAddress,
|
|
33880
|
+
escrowPaymentDomain,
|
|
33001
33881
|
fileRegistrationDomain,
|
|
33002
33882
|
generatePkceVerifier,
|
|
33003
33883
|
getAbi,
|
|
@@ -33017,16 +33897,20 @@ async function parsePSError(response) {
|
|
|
33017
33897
|
moksha,
|
|
33018
33898
|
mokshaServices,
|
|
33019
33899
|
mokshaTestnet,
|
|
33020
|
-
parseGrantRegistrationPayload,
|
|
33021
33900
|
parsePSError,
|
|
33022
33901
|
parseScope,
|
|
33023
33902
|
parseWeb3SignedHeader,
|
|
33903
|
+
personalServerRegistrationDomain,
|
|
33024
33904
|
recoverServerOwner,
|
|
33905
|
+
registerPersonalServerSignature,
|
|
33025
33906
|
scopeCoveredByGrant,
|
|
33026
33907
|
scopeMatchesPattern,
|
|
33027
33908
|
scopeToPathSegments,
|
|
33028
33909
|
serializeECIES,
|
|
33029
33910
|
serverRegistrationDomain,
|
|
33911
|
+
signPersonalServerLiteOwnerBinding,
|
|
33912
|
+
signPersonalServerLiteOwnerBindingWithAccountClient,
|
|
33913
|
+
signPersonalServerRegistrationWithAccount,
|
|
33030
33914
|
vanaMainnet,
|
|
33031
33915
|
verifyGrantRegistration,
|
|
33032
33916
|
verifyPkceChallenge,
|