@opendatalabs/vana-sdk 3.0.0 → 3.0.1-pr.147.a4abdb1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/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 +196 -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 +172 -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/web3-signed.cjs +28 -3
- package/dist/auth/web3-signed.cjs.map +1 -1
- package/dist/auth/web3-signed.js +28 -3
- package/dist/auth/web3-signed.js.map +1 -1
- package/dist/index.browser.d.ts +5 -0
- package/dist/index.browser.js +562 -16
- package/dist/index.browser.js.map +4 -4
- package/dist/index.node.cjs +580 -16
- package/dist/index.node.cjs.map +4 -4
- package/dist/index.node.d.ts +5 -0
- package/dist/index.node.js +562 -16
- package/dist/index.node.js.map +4 -4
- package/dist/protocol/eip712.cjs.map +1 -1
- package/dist/protocol/eip712.d.ts +1 -1
- package/dist/protocol/eip712.js.map +1 -1
- package/dist/protocol/grants.cjs +146 -0
- package/dist/protocol/grants.cjs.map +1 -0
- package/dist/protocol/grants.d.ts +31 -0
- package/dist/protocol/grants.js +123 -0
- package/dist/protocol/grants.js.map +1 -0
- package/dist/protocol/grants.test.d.ts +1 -0
- 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/index.cjs.map +1 -1
- package/dist/storage/index.d.ts +1 -1
- package/dist/storage/index.js.map +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 +1 -1
- package/dist/storage/providers/vana-storage.js.map +1 -1
- package/dist/types/ps-errors.cjs +37 -12
- package/dist/types/ps-errors.cjs.map +1 -1
- package/dist/types/ps-errors.d.ts +7 -6
- package/dist/types/ps-errors.js +37 -12
- package/dist/types/ps-errors.js.map +1 -1
- package/package.json +1 -1
package/dist/index.node.d.ts
CHANGED
|
@@ -35,6 +35,11 @@ export { MissingAuthError, InvalidSignatureError, ExpiredTokenError, } from "./a
|
|
|
35
35
|
export { generatePkceVerifier, computePkceChallenge, verifyPkceChallenge, assertValidPkceVerifier, PKCE_VERIFIER_PATTERN, PKCE_CHALLENGE_PATTERN, } from "./auth/pkce";
|
|
36
36
|
export { InMemoryTokenStore, type TokenStore, type TokenRecord, } from "./auth/token-store";
|
|
37
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 { 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";
|
|
39
|
+
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";
|
|
40
|
+
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";
|
|
41
|
+
export { AccountPersonalServerLiteOwnerBindingError, signPersonalServerLiteOwnerBindingWithAccountClient, type AccountPersonalServerLiteOwnerBindingClient, type SignPersonalServerLiteOwnerBindingWithAccountClientConfig, } from "./account/personal-server-lite-owner-binding";
|
|
42
|
+
export { isDataPortabilityGatewayConfig, parseGrantRegistrationPayload, verifyGrantRegistration, type DataPortabilityGrantPayload, type VerifyGrantRegistrationInput, type VerifyGrantRegistrationResult, } from "./protocol/grants";
|
|
38
43
|
export { ScopeSchema, parseScope, scopeToPathSegments, scopeMatchesPattern, scopeCoveredByGrant, type Scope, type ParsedScope, } from "./protocol/scopes";
|
|
39
44
|
export { DataFileEnvelopeSchema, createDataFileEnvelope, IngestResponseSchema, type DataFileEnvelope, type IngestResponse, } from "./protocol/data-file";
|
|
40
45
|
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";
|
package/dist/index.node.js
CHANGED
|
@@ -29015,7 +29015,7 @@ async function buildWeb3SignedHeader(params) {
|
|
|
29015
29015
|
}
|
|
29016
29016
|
|
|
29017
29017
|
// src/storage/providers/vana-storage.ts
|
|
29018
|
-
var DEFAULT_ENDPOINT = "https://storage.vana.
|
|
29018
|
+
var DEFAULT_ENDPOINT = "https://storage.vana.org";
|
|
29019
29019
|
var BLOB_PATH_PREFIX = "/v1/blobs";
|
|
29020
29020
|
var DEFAULT_TOKEN_TTL_SECONDS = 300;
|
|
29021
29021
|
var VanaStorage = class {
|
|
@@ -32078,6 +32078,30 @@ function base64urlDecode(input) {
|
|
|
32078
32078
|
base64 += "=".repeat(padLength);
|
|
32079
32079
|
return new TextDecoder().decode(fromBase64(base64));
|
|
32080
32080
|
}
|
|
32081
|
+
function isFiniteNumber(value) {
|
|
32082
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
32083
|
+
}
|
|
32084
|
+
function parsePayload(value) {
|
|
32085
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
32086
|
+
throw new InvalidSignatureError({ reason: "Invalid payload shape" });
|
|
32087
|
+
}
|
|
32088
|
+
const payload = value;
|
|
32089
|
+
if (typeof payload["aud"] !== "string" || typeof payload["method"] !== "string" || typeof payload["uri"] !== "string" || typeof payload["bodyHash"] !== "string" || !isFiniteNumber(payload["iat"]) || !isFiniteNumber(payload["exp"])) {
|
|
32090
|
+
throw new InvalidSignatureError({ reason: "Invalid payload claims" });
|
|
32091
|
+
}
|
|
32092
|
+
if (payload["grantId"] !== void 0 && typeof payload["grantId"] !== "string") {
|
|
32093
|
+
throw new InvalidSignatureError({ reason: "Invalid grantId claim" });
|
|
32094
|
+
}
|
|
32095
|
+
return {
|
|
32096
|
+
aud: payload["aud"],
|
|
32097
|
+
method: payload["method"],
|
|
32098
|
+
uri: payload["uri"],
|
|
32099
|
+
bodyHash: payload["bodyHash"],
|
|
32100
|
+
iat: payload["iat"],
|
|
32101
|
+
exp: payload["exp"],
|
|
32102
|
+
grantId: payload["grantId"]
|
|
32103
|
+
};
|
|
32104
|
+
}
|
|
32081
32105
|
function parseWeb3SignedHeader(headerValue) {
|
|
32082
32106
|
if (!headerValue) {
|
|
32083
32107
|
throw new MissingAuthError();
|
|
@@ -32098,8 +32122,9 @@ function parseWeb3SignedHeader(headerValue) {
|
|
|
32098
32122
|
let payload;
|
|
32099
32123
|
try {
|
|
32100
32124
|
const decoded = base64urlDecode(payloadBase64);
|
|
32101
|
-
payload = JSON.parse(decoded);
|
|
32102
|
-
} catch {
|
|
32125
|
+
payload = parsePayload(JSON.parse(decoded));
|
|
32126
|
+
} catch (err) {
|
|
32127
|
+
if (err instanceof InvalidSignatureError) throw err;
|
|
32103
32128
|
throw new InvalidSignatureError({ reason: "Invalid payload encoding" });
|
|
32104
32129
|
}
|
|
32105
32130
|
return {
|
|
@@ -32142,7 +32167,7 @@ async function verifyWeb3Signed(params) {
|
|
|
32142
32167
|
actual: payload.uri
|
|
32143
32168
|
});
|
|
32144
32169
|
}
|
|
32145
|
-
if (params.bodyBytes !== void 0
|
|
32170
|
+
if (params.bodyBytes !== void 0) {
|
|
32146
32171
|
const expectedBodyHash = computeBodyHash(params.bodyBytes);
|
|
32147
32172
|
if (payload.bodyHash !== expectedBodyHash) {
|
|
32148
32173
|
throw new InvalidSignatureError({
|
|
@@ -32338,6 +32363,480 @@ var BUILDER_REGISTRATION_TYPES = {
|
|
|
32338
32363
|
]
|
|
32339
32364
|
};
|
|
32340
32365
|
|
|
32366
|
+
// src/protocol/personal-server-registration.ts
|
|
32367
|
+
import {
|
|
32368
|
+
isAddress
|
|
32369
|
+
} from "viem";
|
|
32370
|
+
var PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID = 1480;
|
|
32371
|
+
var PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT = "0x1483B1F634DBA75AeaE60da7f01A679aabd5ee2c";
|
|
32372
|
+
function assertAddress(value, name) {
|
|
32373
|
+
if (!isAddress(value)) {
|
|
32374
|
+
throw new Error(`${name} must be a valid EVM address`);
|
|
32375
|
+
}
|
|
32376
|
+
}
|
|
32377
|
+
function getAccountAddress(account) {
|
|
32378
|
+
if (!account) {
|
|
32379
|
+
return void 0;
|
|
32380
|
+
}
|
|
32381
|
+
return typeof account === "string" ? account : account.address;
|
|
32382
|
+
}
|
|
32383
|
+
function isPersonalServerRegistrationSigner(source) {
|
|
32384
|
+
return "address" in source && typeof source.signTypedData === "function";
|
|
32385
|
+
}
|
|
32386
|
+
function createViemPersonalServerRegistrationSigner(source, options = {}) {
|
|
32387
|
+
if (isPersonalServerRegistrationSigner(source)) {
|
|
32388
|
+
return source;
|
|
32389
|
+
}
|
|
32390
|
+
const accountAddress = getAccountAddress(options.account) ?? getAccountAddress(source.account);
|
|
32391
|
+
if (accountAddress) {
|
|
32392
|
+
return {
|
|
32393
|
+
address: accountAddress,
|
|
32394
|
+
signTypedData: (typedData) => source.signTypedData({
|
|
32395
|
+
...typedData,
|
|
32396
|
+
account: options.account ?? source.account ?? accountAddress
|
|
32397
|
+
})
|
|
32398
|
+
};
|
|
32399
|
+
}
|
|
32400
|
+
throw new Error(
|
|
32401
|
+
"Viem wallet client requires an account option or account property"
|
|
32402
|
+
);
|
|
32403
|
+
}
|
|
32404
|
+
function personalServerRegistrationDomain(input = {}) {
|
|
32405
|
+
if (input.config) {
|
|
32406
|
+
return serverRegistrationDomain(input.config);
|
|
32407
|
+
}
|
|
32408
|
+
const verifyingContract = input.verifyingContract ?? PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT;
|
|
32409
|
+
assertAddress(verifyingContract, "verifyingContract");
|
|
32410
|
+
return {
|
|
32411
|
+
name: "Vana Data Portability",
|
|
32412
|
+
version: "1",
|
|
32413
|
+
chainId: input.chainId ?? PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,
|
|
32414
|
+
verifyingContract
|
|
32415
|
+
};
|
|
32416
|
+
}
|
|
32417
|
+
function buildPersonalServerRegistrationTypedData(input) {
|
|
32418
|
+
assertAddress(input.ownerAddress, "ownerAddress");
|
|
32419
|
+
assertAddress(input.serverAddress, "serverAddress");
|
|
32420
|
+
return {
|
|
32421
|
+
domain: personalServerRegistrationDomain(input),
|
|
32422
|
+
types: SERVER_REGISTRATION_TYPES,
|
|
32423
|
+
primaryType: "ServerRegistration",
|
|
32424
|
+
message: {
|
|
32425
|
+
ownerAddress: input.ownerAddress,
|
|
32426
|
+
serverAddress: input.serverAddress,
|
|
32427
|
+
publicKey: input.serverPublicKey,
|
|
32428
|
+
serverUrl: input.serverUrl
|
|
32429
|
+
}
|
|
32430
|
+
};
|
|
32431
|
+
}
|
|
32432
|
+
async function buildPersonalServerRegistrationSignature(input) {
|
|
32433
|
+
const typedData = buildPersonalServerRegistrationTypedData({
|
|
32434
|
+
ownerAddress: input.signer.address,
|
|
32435
|
+
serverAddress: input.serverAddress,
|
|
32436
|
+
serverPublicKey: input.serverPublicKey,
|
|
32437
|
+
serverUrl: input.serverUrl,
|
|
32438
|
+
config: input.config,
|
|
32439
|
+
chainId: input.chainId,
|
|
32440
|
+
verifyingContract: input.verifyingContract
|
|
32441
|
+
});
|
|
32442
|
+
const signature = await input.signer.signTypedData(typedData);
|
|
32443
|
+
return {
|
|
32444
|
+
signature,
|
|
32445
|
+
signerAddress: input.signer.address,
|
|
32446
|
+
typedData
|
|
32447
|
+
};
|
|
32448
|
+
}
|
|
32449
|
+
var registerPersonalServerSignature = buildPersonalServerRegistrationSignature;
|
|
32450
|
+
|
|
32451
|
+
// src/protocol/personal-server-lite-owner-binding.ts
|
|
32452
|
+
import {
|
|
32453
|
+
isAddress as isAddress2
|
|
32454
|
+
} from "viem";
|
|
32455
|
+
var PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION = "vana.account.v1";
|
|
32456
|
+
var PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE = "ps-lite-owner";
|
|
32457
|
+
var PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX = `${PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION}:${PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE}:`;
|
|
32458
|
+
function assertAddress2(value, name) {
|
|
32459
|
+
if (!isAddress2(value)) {
|
|
32460
|
+
throw new Error(`${name} must be a valid EVM address`);
|
|
32461
|
+
}
|
|
32462
|
+
}
|
|
32463
|
+
function getAccountAddress2(account) {
|
|
32464
|
+
if (!account) {
|
|
32465
|
+
return void 0;
|
|
32466
|
+
}
|
|
32467
|
+
return typeof account === "string" ? account : account.address;
|
|
32468
|
+
}
|
|
32469
|
+
function isPersonalServerLiteOwnerBindingSigner(source) {
|
|
32470
|
+
return "address" in source && typeof source.signMessage === "function";
|
|
32471
|
+
}
|
|
32472
|
+
function buildPersonalServerLiteOwnerBindingMessage(ownerAddress) {
|
|
32473
|
+
assertAddress2(ownerAddress, "ownerAddress");
|
|
32474
|
+
return `${PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX}${ownerAddress.toLowerCase()}`;
|
|
32475
|
+
}
|
|
32476
|
+
function createViemPersonalServerLiteOwnerBindingSigner(source, options = {}) {
|
|
32477
|
+
if (isPersonalServerLiteOwnerBindingSigner(source)) {
|
|
32478
|
+
return source;
|
|
32479
|
+
}
|
|
32480
|
+
const accountAddress = getAccountAddress2(options.account) ?? getAccountAddress2(source.account);
|
|
32481
|
+
if (accountAddress) {
|
|
32482
|
+
return {
|
|
32483
|
+
address: accountAddress,
|
|
32484
|
+
signMessage: ({ message }) => source.signMessage({
|
|
32485
|
+
account: options.account ?? source.account ?? accountAddress,
|
|
32486
|
+
message
|
|
32487
|
+
})
|
|
32488
|
+
};
|
|
32489
|
+
}
|
|
32490
|
+
throw new Error(
|
|
32491
|
+
"Viem wallet client requires an account option or account property"
|
|
32492
|
+
);
|
|
32493
|
+
}
|
|
32494
|
+
async function buildPersonalServerLiteOwnerBindingSignature(input) {
|
|
32495
|
+
const message = buildPersonalServerLiteOwnerBindingMessage(
|
|
32496
|
+
input.signer.address
|
|
32497
|
+
);
|
|
32498
|
+
const signature = await input.signer.signMessage({ message });
|
|
32499
|
+
return {
|
|
32500
|
+
signature,
|
|
32501
|
+
signerAddress: input.signer.address,
|
|
32502
|
+
message,
|
|
32503
|
+
purpose: PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE
|
|
32504
|
+
};
|
|
32505
|
+
}
|
|
32506
|
+
var signPersonalServerLiteOwnerBinding = buildPersonalServerLiteOwnerBindingSignature;
|
|
32507
|
+
|
|
32508
|
+
// src/account/personal-server-registration.ts
|
|
32509
|
+
import { isAddress as isAddress3 } from "viem";
|
|
32510
|
+
var ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT = "personal_server.server_registration.v1";
|
|
32511
|
+
var AccountPersonalServerRegistrationError = class extends Error {
|
|
32512
|
+
status;
|
|
32513
|
+
code;
|
|
32514
|
+
details;
|
|
32515
|
+
constructor(input) {
|
|
32516
|
+
super(input.message);
|
|
32517
|
+
this.name = "AccountPersonalServerRegistrationError";
|
|
32518
|
+
this.status = input.status;
|
|
32519
|
+
this.code = input.code;
|
|
32520
|
+
this.details = input.details;
|
|
32521
|
+
}
|
|
32522
|
+
};
|
|
32523
|
+
var DEFAULT_ACCOUNT_PS_REGISTRATION_PATH = "/api/v1/intents/personal-server-registration/sign";
|
|
32524
|
+
function trimTrailingSlash(value) {
|
|
32525
|
+
return value.replace(/\/+$/, "");
|
|
32526
|
+
}
|
|
32527
|
+
function assertAddress3(value, name) {
|
|
32528
|
+
if (!isAddress3(value)) {
|
|
32529
|
+
throw new Error(`${name} must be a valid EVM address`);
|
|
32530
|
+
}
|
|
32531
|
+
}
|
|
32532
|
+
async function parseAccountResponse(response) {
|
|
32533
|
+
const body = await response.json().catch(() => void 0);
|
|
32534
|
+
if (!response.ok) {
|
|
32535
|
+
throw new AccountPersonalServerRegistrationError({
|
|
32536
|
+
status: response.status,
|
|
32537
|
+
code: accountErrorCode(body),
|
|
32538
|
+
message: accountErrorMessage(response.status, body),
|
|
32539
|
+
details: body
|
|
32540
|
+
});
|
|
32541
|
+
}
|
|
32542
|
+
return body;
|
|
32543
|
+
}
|
|
32544
|
+
function accountErrorMessage(status, body) {
|
|
32545
|
+
const nestedMessage = nestedAccountErrorField(body, "message");
|
|
32546
|
+
if (nestedMessage) {
|
|
32547
|
+
return nestedMessage;
|
|
32548
|
+
}
|
|
32549
|
+
if (isRecord(body) && typeof body.message === "string") {
|
|
32550
|
+
return body.message;
|
|
32551
|
+
}
|
|
32552
|
+
const code = accountErrorCode(body);
|
|
32553
|
+
if (code) {
|
|
32554
|
+
return `Account PS registration signing failed: ${code}`;
|
|
32555
|
+
}
|
|
32556
|
+
return `Account PS registration signing failed: ${status}`;
|
|
32557
|
+
}
|
|
32558
|
+
function accountErrorCode(body) {
|
|
32559
|
+
const nestedCode = nestedAccountErrorField(body, "code");
|
|
32560
|
+
if (nestedCode) {
|
|
32561
|
+
return nestedCode;
|
|
32562
|
+
}
|
|
32563
|
+
if (isRecord(body)) {
|
|
32564
|
+
if (typeof body.code === "string") {
|
|
32565
|
+
return body.code;
|
|
32566
|
+
}
|
|
32567
|
+
if (typeof body.error === "string") {
|
|
32568
|
+
return body.error;
|
|
32569
|
+
}
|
|
32570
|
+
}
|
|
32571
|
+
return void 0;
|
|
32572
|
+
}
|
|
32573
|
+
function nestedAccountErrorField(body, field) {
|
|
32574
|
+
if (!isRecord(body) || !isRecord(body.error)) {
|
|
32575
|
+
return void 0;
|
|
32576
|
+
}
|
|
32577
|
+
const value = body.error[field];
|
|
32578
|
+
return typeof value === "string" ? value : void 0;
|
|
32579
|
+
}
|
|
32580
|
+
function isRecord(value) {
|
|
32581
|
+
return typeof value === "object" && value !== null;
|
|
32582
|
+
}
|
|
32583
|
+
function normalizeAccountResponse(response) {
|
|
32584
|
+
return {
|
|
32585
|
+
...response,
|
|
32586
|
+
status: response.status === "fallback_required" ? "confirmation_required" : response.status,
|
|
32587
|
+
signerAddress: response.signerAddress ?? response.signer?.address,
|
|
32588
|
+
typedData: response.typedData ?? response.typed_data
|
|
32589
|
+
};
|
|
32590
|
+
}
|
|
32591
|
+
function buildSignedResult(response, request) {
|
|
32592
|
+
assertAddress3(response.signerAddress, "signerAddress");
|
|
32593
|
+
return {
|
|
32594
|
+
signature: response.signature,
|
|
32595
|
+
signerAddress: response.signerAddress,
|
|
32596
|
+
typedData: response.typedData ?? buildPersonalServerRegistrationTypedData({
|
|
32597
|
+
ownerAddress: response.signerAddress,
|
|
32598
|
+
...request
|
|
32599
|
+
}),
|
|
32600
|
+
intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT
|
|
32601
|
+
};
|
|
32602
|
+
}
|
|
32603
|
+
async function signPersonalServerRegistrationWithAccount(config, request) {
|
|
32604
|
+
assertAddress3(request.serverAddress, "serverAddress");
|
|
32605
|
+
const fetchImpl = config.fetchImpl ?? globalThis.fetch.bind(globalThis);
|
|
32606
|
+
const endpoint = new URL(
|
|
32607
|
+
config.endpointPath ?? DEFAULT_ACCOUNT_PS_REGISTRATION_PATH,
|
|
32608
|
+
`${trimTrailingSlash(config.accountOrigin)}/`
|
|
32609
|
+
);
|
|
32610
|
+
const response = await fetchImpl(endpoint, {
|
|
32611
|
+
method: "POST",
|
|
32612
|
+
headers: { "content-type": "application/json" },
|
|
32613
|
+
credentials: "include",
|
|
32614
|
+
body: JSON.stringify({
|
|
32615
|
+
intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
|
|
32616
|
+
serverAddress: request.serverAddress,
|
|
32617
|
+
serverPublicKey: request.serverPublicKey,
|
|
32618
|
+
serverUrl: request.serverUrl,
|
|
32619
|
+
config: request.config,
|
|
32620
|
+
chainId: request.chainId,
|
|
32621
|
+
verifyingContract: request.verifyingContract
|
|
32622
|
+
})
|
|
32623
|
+
});
|
|
32624
|
+
const body = normalizeAccountResponse(await parseAccountResponse(response));
|
|
32625
|
+
if (body.status === "signed") {
|
|
32626
|
+
if (!body.signature || !body.signerAddress) {
|
|
32627
|
+
throw new Error(
|
|
32628
|
+
"Account signed response must include signature and signerAddress"
|
|
32629
|
+
);
|
|
32630
|
+
}
|
|
32631
|
+
return {
|
|
32632
|
+
status: "signed",
|
|
32633
|
+
result: buildSignedResult(
|
|
32634
|
+
{
|
|
32635
|
+
signature: body.signature,
|
|
32636
|
+
signerAddress: body.signerAddress,
|
|
32637
|
+
typedData: body.typedData
|
|
32638
|
+
},
|
|
32639
|
+
request
|
|
32640
|
+
)
|
|
32641
|
+
};
|
|
32642
|
+
}
|
|
32643
|
+
if (body.status === "confirmation_required") {
|
|
32644
|
+
if (!body.typedData) {
|
|
32645
|
+
throw new Error(
|
|
32646
|
+
"Account confirmation_required response must include typedData"
|
|
32647
|
+
);
|
|
32648
|
+
}
|
|
32649
|
+
if (!config.fallbackSigner) {
|
|
32650
|
+
return {
|
|
32651
|
+
status: "confirmation_required",
|
|
32652
|
+
typedData: body.typedData,
|
|
32653
|
+
signerAddress: body.signerAddress
|
|
32654
|
+
};
|
|
32655
|
+
}
|
|
32656
|
+
const signature = await config.fallbackSigner.signTypedData(body.typedData);
|
|
32657
|
+
return {
|
|
32658
|
+
status: "fallback_signed",
|
|
32659
|
+
accountStatus: "confirmation_required",
|
|
32660
|
+
result: {
|
|
32661
|
+
signature,
|
|
32662
|
+
signerAddress: config.fallbackSigner.address,
|
|
32663
|
+
typedData: body.typedData,
|
|
32664
|
+
intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT
|
|
32665
|
+
}
|
|
32666
|
+
};
|
|
32667
|
+
}
|
|
32668
|
+
throw new Error(
|
|
32669
|
+
`Unsupported Account PS registration signing status: ${String(body.status)}`
|
|
32670
|
+
);
|
|
32671
|
+
}
|
|
32672
|
+
|
|
32673
|
+
// src/account/personal-server-lite-owner-binding.ts
|
|
32674
|
+
var AccountPersonalServerLiteOwnerBindingError = class extends Error {
|
|
32675
|
+
code;
|
|
32676
|
+
details;
|
|
32677
|
+
constructor(input) {
|
|
32678
|
+
super(input.message);
|
|
32679
|
+
this.name = "AccountPersonalServerLiteOwnerBindingError";
|
|
32680
|
+
this.code = input.code;
|
|
32681
|
+
this.details = input.details;
|
|
32682
|
+
}
|
|
32683
|
+
};
|
|
32684
|
+
async function signPersonalServerLiteOwnerBindingWithAccountClient(config) {
|
|
32685
|
+
let address;
|
|
32686
|
+
try {
|
|
32687
|
+
address = await config.client.getAddress();
|
|
32688
|
+
} catch (error) {
|
|
32689
|
+
throw accountOwnerBindingError(error);
|
|
32690
|
+
}
|
|
32691
|
+
if (!address) {
|
|
32692
|
+
throw new AccountPersonalServerLiteOwnerBindingError({
|
|
32693
|
+
message: "Account did not return a wallet address",
|
|
32694
|
+
code: "account_address_required"
|
|
32695
|
+
});
|
|
32696
|
+
}
|
|
32697
|
+
const message = buildPersonalServerLiteOwnerBindingMessage(address);
|
|
32698
|
+
let signature;
|
|
32699
|
+
try {
|
|
32700
|
+
signature = await config.client.signMessage({ message });
|
|
32701
|
+
} catch (error) {
|
|
32702
|
+
throw accountOwnerBindingError(error);
|
|
32703
|
+
}
|
|
32704
|
+
return {
|
|
32705
|
+
signature,
|
|
32706
|
+
signerAddress: address,
|
|
32707
|
+
message,
|
|
32708
|
+
purpose: PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE
|
|
32709
|
+
};
|
|
32710
|
+
}
|
|
32711
|
+
function accountOwnerBindingError(error) {
|
|
32712
|
+
if (error instanceof AccountPersonalServerLiteOwnerBindingError) {
|
|
32713
|
+
return error;
|
|
32714
|
+
}
|
|
32715
|
+
const rpcError = error;
|
|
32716
|
+
const code = rpcError?.code;
|
|
32717
|
+
const message = typeof rpcError?.message === "string" && rpcError.message.length > 0 ? rpcError.message : "Account PS Lite owner-binding signature failed";
|
|
32718
|
+
return new AccountPersonalServerLiteOwnerBindingError({
|
|
32719
|
+
message,
|
|
32720
|
+
code,
|
|
32721
|
+
details: error
|
|
32722
|
+
});
|
|
32723
|
+
}
|
|
32724
|
+
|
|
32725
|
+
// src/protocol/grants.ts
|
|
32726
|
+
import { verifyTypedData } from "viem";
|
|
32727
|
+
function isHexString(value) {
|
|
32728
|
+
return typeof value === "string" && value.startsWith("0x");
|
|
32729
|
+
}
|
|
32730
|
+
function isDataPortabilityGatewayConfig(value) {
|
|
32731
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
32732
|
+
return false;
|
|
32733
|
+
}
|
|
32734
|
+
const config = value;
|
|
32735
|
+
const contracts = config["contracts"];
|
|
32736
|
+
if (typeof config["chainId"] !== "number" || !Number.isInteger(config["chainId"]) || config["chainId"] <= 0 || contracts === null || typeof contracts !== "object" || Array.isArray(contracts)) {
|
|
32737
|
+
return false;
|
|
32738
|
+
}
|
|
32739
|
+
const c = contracts;
|
|
32740
|
+
return isHexString(c["dataRegistry"]) && isHexString(c["dataPortabilityPermissions"]) && isHexString(c["dataPortabilityServer"]) && isHexString(c["dataPortabilityGrantees"]);
|
|
32741
|
+
}
|
|
32742
|
+
function parseGrantRegistrationPayload(grant) {
|
|
32743
|
+
let parsed;
|
|
32744
|
+
try {
|
|
32745
|
+
parsed = JSON.parse(grant);
|
|
32746
|
+
} catch {
|
|
32747
|
+
return null;
|
|
32748
|
+
}
|
|
32749
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
32750
|
+
return null;
|
|
32751
|
+
}
|
|
32752
|
+
const value = parsed;
|
|
32753
|
+
if (!Array.isArray(value["scopes"]) || value["scopes"].length === 0) {
|
|
32754
|
+
return null;
|
|
32755
|
+
}
|
|
32756
|
+
if (!value["scopes"].every((scope) => typeof scope === "string")) {
|
|
32757
|
+
return null;
|
|
32758
|
+
}
|
|
32759
|
+
if (typeof value["expiresAt"] !== "number" || !Number.isFinite(value["expiresAt"])) {
|
|
32760
|
+
return null;
|
|
32761
|
+
}
|
|
32762
|
+
if (value["user"] !== void 0 && !isHexString(value["user"])) {
|
|
32763
|
+
return null;
|
|
32764
|
+
}
|
|
32765
|
+
if (value["builder"] !== void 0 && !isHexString(value["builder"])) {
|
|
32766
|
+
return null;
|
|
32767
|
+
}
|
|
32768
|
+
if (value["nonce"] !== void 0 && (typeof value["nonce"] !== "number" || !Number.isFinite(value["nonce"]))) {
|
|
32769
|
+
return null;
|
|
32770
|
+
}
|
|
32771
|
+
return {
|
|
32772
|
+
user: value["user"],
|
|
32773
|
+
builder: value["builder"],
|
|
32774
|
+
scopes: value["scopes"],
|
|
32775
|
+
expiresAt: value["expiresAt"],
|
|
32776
|
+
nonce: value["nonce"]
|
|
32777
|
+
};
|
|
32778
|
+
}
|
|
32779
|
+
function parseFileIds(fileIds) {
|
|
32780
|
+
try {
|
|
32781
|
+
const values = (fileIds ?? []).map((fileId) => BigInt(fileId));
|
|
32782
|
+
return {
|
|
32783
|
+
values,
|
|
32784
|
+
display: values.map((fileId) => fileId.toString())
|
|
32785
|
+
};
|
|
32786
|
+
} catch {
|
|
32787
|
+
return null;
|
|
32788
|
+
}
|
|
32789
|
+
}
|
|
32790
|
+
async function verifyGrantRegistration(input) {
|
|
32791
|
+
const payload = parseGrantRegistrationPayload(input.grant);
|
|
32792
|
+
if (!payload) {
|
|
32793
|
+
return {
|
|
32794
|
+
valid: false,
|
|
32795
|
+
error: "Grant must be JSON with scopes and expiresAt"
|
|
32796
|
+
};
|
|
32797
|
+
}
|
|
32798
|
+
const fileIds = parseFileIds(input.fileIds);
|
|
32799
|
+
if (!fileIds) {
|
|
32800
|
+
return { valid: false, error: "fileIds must contain integer values" };
|
|
32801
|
+
}
|
|
32802
|
+
let valid;
|
|
32803
|
+
try {
|
|
32804
|
+
valid = await verifyTypedData({
|
|
32805
|
+
address: input.grantorAddress,
|
|
32806
|
+
domain: grantRegistrationDomain(input.gatewayConfig),
|
|
32807
|
+
types: GRANT_REGISTRATION_TYPES,
|
|
32808
|
+
primaryType: "GrantRegistration",
|
|
32809
|
+
message: {
|
|
32810
|
+
grantorAddress: input.grantorAddress,
|
|
32811
|
+
granteeId: input.granteeId,
|
|
32812
|
+
grant: input.grant,
|
|
32813
|
+
fileIds: fileIds.values
|
|
32814
|
+
},
|
|
32815
|
+
signature: input.signature
|
|
32816
|
+
});
|
|
32817
|
+
} catch {
|
|
32818
|
+
return { valid: false, error: "EIP-712 signature verification failed" };
|
|
32819
|
+
}
|
|
32820
|
+
if (!valid) {
|
|
32821
|
+
return { valid: false, error: "Grant signature does not match grantor" };
|
|
32822
|
+
}
|
|
32823
|
+
const nowSeconds = input.nowSeconds ?? Math.floor(Date.now() / 1e3);
|
|
32824
|
+
if (payload.expiresAt > 0 && payload.expiresAt < nowSeconds) {
|
|
32825
|
+
return { valid: false, error: "Grant has expired" };
|
|
32826
|
+
}
|
|
32827
|
+
if (payload.user !== void 0 && payload.user.toLowerCase() !== input.grantorAddress.toLowerCase()) {
|
|
32828
|
+
return { valid: false, error: "Grant user does not match grantorAddress" };
|
|
32829
|
+
}
|
|
32830
|
+
return {
|
|
32831
|
+
valid: true,
|
|
32832
|
+
grantorAddress: input.grantorAddress,
|
|
32833
|
+
granteeId: input.granteeId,
|
|
32834
|
+
grant: input.grant,
|
|
32835
|
+
payload,
|
|
32836
|
+
fileIds: fileIds.display
|
|
32837
|
+
};
|
|
32838
|
+
}
|
|
32839
|
+
|
|
32341
32840
|
// src/protocol/scopes.ts
|
|
32342
32841
|
import { z } from "zod";
|
|
32343
32842
|
var SEGMENT_RE = /^[a-z0-9][a-z0-9_]*$/;
|
|
@@ -32618,34 +33117,62 @@ var PSError = class extends Error {
|
|
|
32618
33117
|
code;
|
|
32619
33118
|
};
|
|
32620
33119
|
var KNOWN_CODES = /* @__PURE__ */ new Set([
|
|
33120
|
+
"missing_auth",
|
|
33121
|
+
"invalid_signature",
|
|
33122
|
+
"unregistered_builder",
|
|
33123
|
+
"not_owner",
|
|
33124
|
+
"expired_token",
|
|
32621
33125
|
"grant_invalid",
|
|
33126
|
+
"grant_required",
|
|
33127
|
+
"grant_expired",
|
|
32622
33128
|
"grant_revoked",
|
|
33129
|
+
"scope_mismatch",
|
|
32623
33130
|
"fee_required",
|
|
32624
|
-
"ps_unavailable"
|
|
33131
|
+
"ps_unavailable",
|
|
33132
|
+
"server_not_configured",
|
|
33133
|
+
"content_too_large"
|
|
32625
33134
|
]);
|
|
32626
|
-
|
|
32627
|
-
|
|
33135
|
+
function isRecord2(value) {
|
|
33136
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
33137
|
+
}
|
|
33138
|
+
function normalizeCode(value) {
|
|
33139
|
+
if (typeof value !== "string") {
|
|
32628
33140
|
return null;
|
|
32629
33141
|
}
|
|
32630
|
-
|
|
32631
|
-
|
|
32632
|
-
|
|
32633
|
-
|
|
33142
|
+
const code = value.toLowerCase();
|
|
33143
|
+
return KNOWN_CODES.has(code) ? code : null;
|
|
33144
|
+
}
|
|
33145
|
+
function extractPSErrorBody(body) {
|
|
33146
|
+
if (!isRecord2(body)) {
|
|
32634
33147
|
return null;
|
|
32635
33148
|
}
|
|
32636
|
-
|
|
33149
|
+
const nested = isRecord2(body.error) ? body.error : null;
|
|
33150
|
+
const code = normalizeCode(
|
|
33151
|
+
nested?.errorCode ?? nested?.code ?? body.errorCode ?? body.code
|
|
33152
|
+
);
|
|
33153
|
+
const message = nested?.message ?? body.message;
|
|
33154
|
+
if (!code || typeof message !== "string") {
|
|
32637
33155
|
return null;
|
|
32638
33156
|
}
|
|
32639
|
-
|
|
32640
|
-
|
|
33157
|
+
return { code, message };
|
|
33158
|
+
}
|
|
33159
|
+
async function parsePSError(response) {
|
|
33160
|
+
if (response.ok) {
|
|
32641
33161
|
return null;
|
|
32642
33162
|
}
|
|
32643
|
-
|
|
33163
|
+
let body;
|
|
33164
|
+
try {
|
|
33165
|
+
body = await response.json();
|
|
33166
|
+
} catch {
|
|
32644
33167
|
return null;
|
|
32645
33168
|
}
|
|
32646
|
-
|
|
33169
|
+
const errorBody = extractPSErrorBody(body);
|
|
33170
|
+
return errorBody ? new PSError(errorBody.code, errorBody.message) : null;
|
|
32647
33171
|
}
|
|
32648
33172
|
export {
|
|
33173
|
+
ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
|
|
33174
|
+
AccountPersonalServerLiteOwnerBindingError,
|
|
33175
|
+
AccountPersonalServerRegistrationError,
|
|
32649
33176
|
BUILDER_REGISTRATION_TYPES,
|
|
32650
33177
|
BlockchainError,
|
|
32651
33178
|
BrowserPlatformAdapter,
|
|
@@ -32672,6 +33199,11 @@ export {
|
|
|
32672
33199
|
NodeECIESUint8Provider as NodeECIESProvider,
|
|
32673
33200
|
NodePlatformAdapter,
|
|
32674
33201
|
NonceError,
|
|
33202
|
+
PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX,
|
|
33203
|
+
PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE,
|
|
33204
|
+
PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION,
|
|
33205
|
+
PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,
|
|
33206
|
+
PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT,
|
|
32675
33207
|
PKCE_CHALLENGE_PATTERN,
|
|
32676
33208
|
PKCE_VERIFIER_PATTERN,
|
|
32677
33209
|
PSError,
|
|
@@ -32693,6 +33225,10 @@ export {
|
|
|
32693
33225
|
VanaError,
|
|
32694
33226
|
VanaStorage,
|
|
32695
33227
|
assertValidPkceVerifier,
|
|
33228
|
+
buildPersonalServerLiteOwnerBindingMessage,
|
|
33229
|
+
buildPersonalServerLiteOwnerBindingSignature,
|
|
33230
|
+
buildPersonalServerRegistrationSignature,
|
|
33231
|
+
buildPersonalServerRegistrationTypedData,
|
|
32696
33232
|
buildWeb3SignedHeader,
|
|
32697
33233
|
builderRegistrationDomain,
|
|
32698
33234
|
chains,
|
|
@@ -32708,6 +33244,8 @@ export {
|
|
|
32708
33244
|
createPlatformAdapterFor,
|
|
32709
33245
|
createPlatformAdapterSafe,
|
|
32710
33246
|
createVanaStorageProvider,
|
|
33247
|
+
createViemPersonalServerLiteOwnerBindingSigner,
|
|
33248
|
+
createViemPersonalServerRegistrationSigner,
|
|
32711
33249
|
decryptWithPassword,
|
|
32712
33250
|
deriveMasterKey,
|
|
32713
33251
|
deriveScopeKey,
|
|
@@ -32726,22 +33264,30 @@ export {
|
|
|
32726
33264
|
getServiceEndpoints,
|
|
32727
33265
|
grantRegistrationDomain,
|
|
32728
33266
|
grantRevocationDomain,
|
|
33267
|
+
isDataPortabilityGatewayConfig,
|
|
32729
33268
|
isECIESEncrypted,
|
|
32730
33269
|
isPlatformSupported,
|
|
32731
33270
|
mainnetServices,
|
|
32732
33271
|
moksha,
|
|
32733
33272
|
mokshaServices,
|
|
32734
33273
|
mokshaTestnet2 as mokshaTestnet,
|
|
33274
|
+
parseGrantRegistrationPayload,
|
|
32735
33275
|
parsePSError,
|
|
32736
33276
|
parseScope,
|
|
32737
33277
|
parseWeb3SignedHeader,
|
|
33278
|
+
personalServerRegistrationDomain,
|
|
32738
33279
|
recoverServerOwner,
|
|
33280
|
+
registerPersonalServerSignature,
|
|
32739
33281
|
scopeCoveredByGrant,
|
|
32740
33282
|
scopeMatchesPattern,
|
|
32741
33283
|
scopeToPathSegments,
|
|
32742
33284
|
serializeECIES,
|
|
32743
33285
|
serverRegistrationDomain,
|
|
33286
|
+
signPersonalServerLiteOwnerBinding,
|
|
33287
|
+
signPersonalServerLiteOwnerBindingWithAccountClient,
|
|
33288
|
+
signPersonalServerRegistrationWithAccount,
|
|
32744
33289
|
vanaMainnet2 as vanaMainnet,
|
|
33290
|
+
verifyGrantRegistration,
|
|
32745
33291
|
verifyPkceChallenge,
|
|
32746
33292
|
verifyWeb3Signed
|
|
32747
33293
|
};
|