@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.browser.js
CHANGED
|
@@ -29006,7 +29006,7 @@ async function buildWeb3SignedHeader(params) {
|
|
|
29006
29006
|
}
|
|
29007
29007
|
|
|
29008
29008
|
// src/storage/providers/vana-storage.ts
|
|
29009
|
-
var DEFAULT_ENDPOINT = "https://storage.vana.
|
|
29009
|
+
var DEFAULT_ENDPOINT = "https://storage.vana.org";
|
|
29010
29010
|
var BLOB_PATH_PREFIX = "/v1/blobs";
|
|
29011
29011
|
var DEFAULT_TOKEN_TTL_SECONDS = 300;
|
|
29012
29012
|
var VanaStorage = class {
|
|
@@ -31548,6 +31548,30 @@ function base64urlDecode(input) {
|
|
|
31548
31548
|
base64 += "=".repeat(padLength);
|
|
31549
31549
|
return new TextDecoder().decode(fromBase64(base64));
|
|
31550
31550
|
}
|
|
31551
|
+
function isFiniteNumber(value) {
|
|
31552
|
+
return typeof value === "number" && Number.isFinite(value);
|
|
31553
|
+
}
|
|
31554
|
+
function parsePayload(value) {
|
|
31555
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
31556
|
+
throw new InvalidSignatureError({ reason: "Invalid payload shape" });
|
|
31557
|
+
}
|
|
31558
|
+
const payload = value;
|
|
31559
|
+
if (typeof payload["aud"] !== "string" || typeof payload["method"] !== "string" || typeof payload["uri"] !== "string" || typeof payload["bodyHash"] !== "string" || !isFiniteNumber(payload["iat"]) || !isFiniteNumber(payload["exp"])) {
|
|
31560
|
+
throw new InvalidSignatureError({ reason: "Invalid payload claims" });
|
|
31561
|
+
}
|
|
31562
|
+
if (payload["grantId"] !== void 0 && typeof payload["grantId"] !== "string") {
|
|
31563
|
+
throw new InvalidSignatureError({ reason: "Invalid grantId claim" });
|
|
31564
|
+
}
|
|
31565
|
+
return {
|
|
31566
|
+
aud: payload["aud"],
|
|
31567
|
+
method: payload["method"],
|
|
31568
|
+
uri: payload["uri"],
|
|
31569
|
+
bodyHash: payload["bodyHash"],
|
|
31570
|
+
iat: payload["iat"],
|
|
31571
|
+
exp: payload["exp"],
|
|
31572
|
+
grantId: payload["grantId"]
|
|
31573
|
+
};
|
|
31574
|
+
}
|
|
31551
31575
|
function parseWeb3SignedHeader(headerValue) {
|
|
31552
31576
|
if (!headerValue) {
|
|
31553
31577
|
throw new MissingAuthError();
|
|
@@ -31568,8 +31592,9 @@ function parseWeb3SignedHeader(headerValue) {
|
|
|
31568
31592
|
let payload;
|
|
31569
31593
|
try {
|
|
31570
31594
|
const decoded = base64urlDecode(payloadBase64);
|
|
31571
|
-
payload = JSON.parse(decoded);
|
|
31572
|
-
} catch {
|
|
31595
|
+
payload = parsePayload(JSON.parse(decoded));
|
|
31596
|
+
} catch (err) {
|
|
31597
|
+
if (err instanceof InvalidSignatureError) throw err;
|
|
31573
31598
|
throw new InvalidSignatureError({ reason: "Invalid payload encoding" });
|
|
31574
31599
|
}
|
|
31575
31600
|
return {
|
|
@@ -31612,7 +31637,7 @@ async function verifyWeb3Signed(params) {
|
|
|
31612
31637
|
actual: payload.uri
|
|
31613
31638
|
});
|
|
31614
31639
|
}
|
|
31615
|
-
if (params.bodyBytes !== void 0
|
|
31640
|
+
if (params.bodyBytes !== void 0) {
|
|
31616
31641
|
const expectedBodyHash = computeBodyHash(params.bodyBytes);
|
|
31617
31642
|
if (payload.bodyHash !== expectedBodyHash) {
|
|
31618
31643
|
throw new InvalidSignatureError({
|
|
@@ -31711,6 +31736,480 @@ var BUILDER_REGISTRATION_TYPES = {
|
|
|
31711
31736
|
]
|
|
31712
31737
|
};
|
|
31713
31738
|
|
|
31739
|
+
// src/protocol/personal-server-registration.ts
|
|
31740
|
+
import {
|
|
31741
|
+
isAddress
|
|
31742
|
+
} from "viem";
|
|
31743
|
+
var PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID = 1480;
|
|
31744
|
+
var PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT = "0x1483B1F634DBA75AeaE60da7f01A679aabd5ee2c";
|
|
31745
|
+
function assertAddress(value, name) {
|
|
31746
|
+
if (!isAddress(value)) {
|
|
31747
|
+
throw new Error(`${name} must be a valid EVM address`);
|
|
31748
|
+
}
|
|
31749
|
+
}
|
|
31750
|
+
function getAccountAddress(account) {
|
|
31751
|
+
if (!account) {
|
|
31752
|
+
return void 0;
|
|
31753
|
+
}
|
|
31754
|
+
return typeof account === "string" ? account : account.address;
|
|
31755
|
+
}
|
|
31756
|
+
function isPersonalServerRegistrationSigner(source) {
|
|
31757
|
+
return "address" in source && typeof source.signTypedData === "function";
|
|
31758
|
+
}
|
|
31759
|
+
function createViemPersonalServerRegistrationSigner(source, options = {}) {
|
|
31760
|
+
if (isPersonalServerRegistrationSigner(source)) {
|
|
31761
|
+
return source;
|
|
31762
|
+
}
|
|
31763
|
+
const accountAddress = getAccountAddress(options.account) ?? getAccountAddress(source.account);
|
|
31764
|
+
if (accountAddress) {
|
|
31765
|
+
return {
|
|
31766
|
+
address: accountAddress,
|
|
31767
|
+
signTypedData: (typedData) => source.signTypedData({
|
|
31768
|
+
...typedData,
|
|
31769
|
+
account: options.account ?? source.account ?? accountAddress
|
|
31770
|
+
})
|
|
31771
|
+
};
|
|
31772
|
+
}
|
|
31773
|
+
throw new Error(
|
|
31774
|
+
"Viem wallet client requires an account option or account property"
|
|
31775
|
+
);
|
|
31776
|
+
}
|
|
31777
|
+
function personalServerRegistrationDomain(input = {}) {
|
|
31778
|
+
if (input.config) {
|
|
31779
|
+
return serverRegistrationDomain(input.config);
|
|
31780
|
+
}
|
|
31781
|
+
const verifyingContract = input.verifyingContract ?? PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT;
|
|
31782
|
+
assertAddress(verifyingContract, "verifyingContract");
|
|
31783
|
+
return {
|
|
31784
|
+
name: "Vana Data Portability",
|
|
31785
|
+
version: "1",
|
|
31786
|
+
chainId: input.chainId ?? PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,
|
|
31787
|
+
verifyingContract
|
|
31788
|
+
};
|
|
31789
|
+
}
|
|
31790
|
+
function buildPersonalServerRegistrationTypedData(input) {
|
|
31791
|
+
assertAddress(input.ownerAddress, "ownerAddress");
|
|
31792
|
+
assertAddress(input.serverAddress, "serverAddress");
|
|
31793
|
+
return {
|
|
31794
|
+
domain: personalServerRegistrationDomain(input),
|
|
31795
|
+
types: SERVER_REGISTRATION_TYPES,
|
|
31796
|
+
primaryType: "ServerRegistration",
|
|
31797
|
+
message: {
|
|
31798
|
+
ownerAddress: input.ownerAddress,
|
|
31799
|
+
serverAddress: input.serverAddress,
|
|
31800
|
+
publicKey: input.serverPublicKey,
|
|
31801
|
+
serverUrl: input.serverUrl
|
|
31802
|
+
}
|
|
31803
|
+
};
|
|
31804
|
+
}
|
|
31805
|
+
async function buildPersonalServerRegistrationSignature(input) {
|
|
31806
|
+
const typedData = buildPersonalServerRegistrationTypedData({
|
|
31807
|
+
ownerAddress: input.signer.address,
|
|
31808
|
+
serverAddress: input.serverAddress,
|
|
31809
|
+
serverPublicKey: input.serverPublicKey,
|
|
31810
|
+
serverUrl: input.serverUrl,
|
|
31811
|
+
config: input.config,
|
|
31812
|
+
chainId: input.chainId,
|
|
31813
|
+
verifyingContract: input.verifyingContract
|
|
31814
|
+
});
|
|
31815
|
+
const signature = await input.signer.signTypedData(typedData);
|
|
31816
|
+
return {
|
|
31817
|
+
signature,
|
|
31818
|
+
signerAddress: input.signer.address,
|
|
31819
|
+
typedData
|
|
31820
|
+
};
|
|
31821
|
+
}
|
|
31822
|
+
var registerPersonalServerSignature = buildPersonalServerRegistrationSignature;
|
|
31823
|
+
|
|
31824
|
+
// src/protocol/personal-server-lite-owner-binding.ts
|
|
31825
|
+
import {
|
|
31826
|
+
isAddress as isAddress2
|
|
31827
|
+
} from "viem";
|
|
31828
|
+
var PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION = "vana.account.v1";
|
|
31829
|
+
var PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE = "ps-lite-owner";
|
|
31830
|
+
var PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX = `${PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION}:${PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE}:`;
|
|
31831
|
+
function assertAddress2(value, name) {
|
|
31832
|
+
if (!isAddress2(value)) {
|
|
31833
|
+
throw new Error(`${name} must be a valid EVM address`);
|
|
31834
|
+
}
|
|
31835
|
+
}
|
|
31836
|
+
function getAccountAddress2(account) {
|
|
31837
|
+
if (!account) {
|
|
31838
|
+
return void 0;
|
|
31839
|
+
}
|
|
31840
|
+
return typeof account === "string" ? account : account.address;
|
|
31841
|
+
}
|
|
31842
|
+
function isPersonalServerLiteOwnerBindingSigner(source) {
|
|
31843
|
+
return "address" in source && typeof source.signMessage === "function";
|
|
31844
|
+
}
|
|
31845
|
+
function buildPersonalServerLiteOwnerBindingMessage(ownerAddress) {
|
|
31846
|
+
assertAddress2(ownerAddress, "ownerAddress");
|
|
31847
|
+
return `${PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX}${ownerAddress.toLowerCase()}`;
|
|
31848
|
+
}
|
|
31849
|
+
function createViemPersonalServerLiteOwnerBindingSigner(source, options = {}) {
|
|
31850
|
+
if (isPersonalServerLiteOwnerBindingSigner(source)) {
|
|
31851
|
+
return source;
|
|
31852
|
+
}
|
|
31853
|
+
const accountAddress = getAccountAddress2(options.account) ?? getAccountAddress2(source.account);
|
|
31854
|
+
if (accountAddress) {
|
|
31855
|
+
return {
|
|
31856
|
+
address: accountAddress,
|
|
31857
|
+
signMessage: ({ message }) => source.signMessage({
|
|
31858
|
+
account: options.account ?? source.account ?? accountAddress,
|
|
31859
|
+
message
|
|
31860
|
+
})
|
|
31861
|
+
};
|
|
31862
|
+
}
|
|
31863
|
+
throw new Error(
|
|
31864
|
+
"Viem wallet client requires an account option or account property"
|
|
31865
|
+
);
|
|
31866
|
+
}
|
|
31867
|
+
async function buildPersonalServerLiteOwnerBindingSignature(input) {
|
|
31868
|
+
const message = buildPersonalServerLiteOwnerBindingMessage(
|
|
31869
|
+
input.signer.address
|
|
31870
|
+
);
|
|
31871
|
+
const signature = await input.signer.signMessage({ message });
|
|
31872
|
+
return {
|
|
31873
|
+
signature,
|
|
31874
|
+
signerAddress: input.signer.address,
|
|
31875
|
+
message,
|
|
31876
|
+
purpose: PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE
|
|
31877
|
+
};
|
|
31878
|
+
}
|
|
31879
|
+
var signPersonalServerLiteOwnerBinding = buildPersonalServerLiteOwnerBindingSignature;
|
|
31880
|
+
|
|
31881
|
+
// src/account/personal-server-registration.ts
|
|
31882
|
+
import { isAddress as isAddress3 } from "viem";
|
|
31883
|
+
var ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT = "personal_server.server_registration.v1";
|
|
31884
|
+
var AccountPersonalServerRegistrationError = class extends Error {
|
|
31885
|
+
status;
|
|
31886
|
+
code;
|
|
31887
|
+
details;
|
|
31888
|
+
constructor(input) {
|
|
31889
|
+
super(input.message);
|
|
31890
|
+
this.name = "AccountPersonalServerRegistrationError";
|
|
31891
|
+
this.status = input.status;
|
|
31892
|
+
this.code = input.code;
|
|
31893
|
+
this.details = input.details;
|
|
31894
|
+
}
|
|
31895
|
+
};
|
|
31896
|
+
var DEFAULT_ACCOUNT_PS_REGISTRATION_PATH = "/api/v1/intents/personal-server-registration/sign";
|
|
31897
|
+
function trimTrailingSlash(value) {
|
|
31898
|
+
return value.replace(/\/+$/, "");
|
|
31899
|
+
}
|
|
31900
|
+
function assertAddress3(value, name) {
|
|
31901
|
+
if (!isAddress3(value)) {
|
|
31902
|
+
throw new Error(`${name} must be a valid EVM address`);
|
|
31903
|
+
}
|
|
31904
|
+
}
|
|
31905
|
+
async function parseAccountResponse(response) {
|
|
31906
|
+
const body = await response.json().catch(() => void 0);
|
|
31907
|
+
if (!response.ok) {
|
|
31908
|
+
throw new AccountPersonalServerRegistrationError({
|
|
31909
|
+
status: response.status,
|
|
31910
|
+
code: accountErrorCode(body),
|
|
31911
|
+
message: accountErrorMessage(response.status, body),
|
|
31912
|
+
details: body
|
|
31913
|
+
});
|
|
31914
|
+
}
|
|
31915
|
+
return body;
|
|
31916
|
+
}
|
|
31917
|
+
function accountErrorMessage(status, body) {
|
|
31918
|
+
const nestedMessage = nestedAccountErrorField(body, "message");
|
|
31919
|
+
if (nestedMessage) {
|
|
31920
|
+
return nestedMessage;
|
|
31921
|
+
}
|
|
31922
|
+
if (isRecord(body) && typeof body.message === "string") {
|
|
31923
|
+
return body.message;
|
|
31924
|
+
}
|
|
31925
|
+
const code = accountErrorCode(body);
|
|
31926
|
+
if (code) {
|
|
31927
|
+
return `Account PS registration signing failed: ${code}`;
|
|
31928
|
+
}
|
|
31929
|
+
return `Account PS registration signing failed: ${status}`;
|
|
31930
|
+
}
|
|
31931
|
+
function accountErrorCode(body) {
|
|
31932
|
+
const nestedCode = nestedAccountErrorField(body, "code");
|
|
31933
|
+
if (nestedCode) {
|
|
31934
|
+
return nestedCode;
|
|
31935
|
+
}
|
|
31936
|
+
if (isRecord(body)) {
|
|
31937
|
+
if (typeof body.code === "string") {
|
|
31938
|
+
return body.code;
|
|
31939
|
+
}
|
|
31940
|
+
if (typeof body.error === "string") {
|
|
31941
|
+
return body.error;
|
|
31942
|
+
}
|
|
31943
|
+
}
|
|
31944
|
+
return void 0;
|
|
31945
|
+
}
|
|
31946
|
+
function nestedAccountErrorField(body, field) {
|
|
31947
|
+
if (!isRecord(body) || !isRecord(body.error)) {
|
|
31948
|
+
return void 0;
|
|
31949
|
+
}
|
|
31950
|
+
const value = body.error[field];
|
|
31951
|
+
return typeof value === "string" ? value : void 0;
|
|
31952
|
+
}
|
|
31953
|
+
function isRecord(value) {
|
|
31954
|
+
return typeof value === "object" && value !== null;
|
|
31955
|
+
}
|
|
31956
|
+
function normalizeAccountResponse(response) {
|
|
31957
|
+
return {
|
|
31958
|
+
...response,
|
|
31959
|
+
status: response.status === "fallback_required" ? "confirmation_required" : response.status,
|
|
31960
|
+
signerAddress: response.signerAddress ?? response.signer?.address,
|
|
31961
|
+
typedData: response.typedData ?? response.typed_data
|
|
31962
|
+
};
|
|
31963
|
+
}
|
|
31964
|
+
function buildSignedResult(response, request) {
|
|
31965
|
+
assertAddress3(response.signerAddress, "signerAddress");
|
|
31966
|
+
return {
|
|
31967
|
+
signature: response.signature,
|
|
31968
|
+
signerAddress: response.signerAddress,
|
|
31969
|
+
typedData: response.typedData ?? buildPersonalServerRegistrationTypedData({
|
|
31970
|
+
ownerAddress: response.signerAddress,
|
|
31971
|
+
...request
|
|
31972
|
+
}),
|
|
31973
|
+
intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT
|
|
31974
|
+
};
|
|
31975
|
+
}
|
|
31976
|
+
async function signPersonalServerRegistrationWithAccount(config, request) {
|
|
31977
|
+
assertAddress3(request.serverAddress, "serverAddress");
|
|
31978
|
+
const fetchImpl = config.fetchImpl ?? globalThis.fetch.bind(globalThis);
|
|
31979
|
+
const endpoint = new URL(
|
|
31980
|
+
config.endpointPath ?? DEFAULT_ACCOUNT_PS_REGISTRATION_PATH,
|
|
31981
|
+
`${trimTrailingSlash(config.accountOrigin)}/`
|
|
31982
|
+
);
|
|
31983
|
+
const response = await fetchImpl(endpoint, {
|
|
31984
|
+
method: "POST",
|
|
31985
|
+
headers: { "content-type": "application/json" },
|
|
31986
|
+
credentials: "include",
|
|
31987
|
+
body: JSON.stringify({
|
|
31988
|
+
intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
|
|
31989
|
+
serverAddress: request.serverAddress,
|
|
31990
|
+
serverPublicKey: request.serverPublicKey,
|
|
31991
|
+
serverUrl: request.serverUrl,
|
|
31992
|
+
config: request.config,
|
|
31993
|
+
chainId: request.chainId,
|
|
31994
|
+
verifyingContract: request.verifyingContract
|
|
31995
|
+
})
|
|
31996
|
+
});
|
|
31997
|
+
const body = normalizeAccountResponse(await parseAccountResponse(response));
|
|
31998
|
+
if (body.status === "signed") {
|
|
31999
|
+
if (!body.signature || !body.signerAddress) {
|
|
32000
|
+
throw new Error(
|
|
32001
|
+
"Account signed response must include signature and signerAddress"
|
|
32002
|
+
);
|
|
32003
|
+
}
|
|
32004
|
+
return {
|
|
32005
|
+
status: "signed",
|
|
32006
|
+
result: buildSignedResult(
|
|
32007
|
+
{
|
|
32008
|
+
signature: body.signature,
|
|
32009
|
+
signerAddress: body.signerAddress,
|
|
32010
|
+
typedData: body.typedData
|
|
32011
|
+
},
|
|
32012
|
+
request
|
|
32013
|
+
)
|
|
32014
|
+
};
|
|
32015
|
+
}
|
|
32016
|
+
if (body.status === "confirmation_required") {
|
|
32017
|
+
if (!body.typedData) {
|
|
32018
|
+
throw new Error(
|
|
32019
|
+
"Account confirmation_required response must include typedData"
|
|
32020
|
+
);
|
|
32021
|
+
}
|
|
32022
|
+
if (!config.fallbackSigner) {
|
|
32023
|
+
return {
|
|
32024
|
+
status: "confirmation_required",
|
|
32025
|
+
typedData: body.typedData,
|
|
32026
|
+
signerAddress: body.signerAddress
|
|
32027
|
+
};
|
|
32028
|
+
}
|
|
32029
|
+
const signature = await config.fallbackSigner.signTypedData(body.typedData);
|
|
32030
|
+
return {
|
|
32031
|
+
status: "fallback_signed",
|
|
32032
|
+
accountStatus: "confirmation_required",
|
|
32033
|
+
result: {
|
|
32034
|
+
signature,
|
|
32035
|
+
signerAddress: config.fallbackSigner.address,
|
|
32036
|
+
typedData: body.typedData,
|
|
32037
|
+
intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT
|
|
32038
|
+
}
|
|
32039
|
+
};
|
|
32040
|
+
}
|
|
32041
|
+
throw new Error(
|
|
32042
|
+
`Unsupported Account PS registration signing status: ${String(body.status)}`
|
|
32043
|
+
);
|
|
32044
|
+
}
|
|
32045
|
+
|
|
32046
|
+
// src/account/personal-server-lite-owner-binding.ts
|
|
32047
|
+
var AccountPersonalServerLiteOwnerBindingError = class extends Error {
|
|
32048
|
+
code;
|
|
32049
|
+
details;
|
|
32050
|
+
constructor(input) {
|
|
32051
|
+
super(input.message);
|
|
32052
|
+
this.name = "AccountPersonalServerLiteOwnerBindingError";
|
|
32053
|
+
this.code = input.code;
|
|
32054
|
+
this.details = input.details;
|
|
32055
|
+
}
|
|
32056
|
+
};
|
|
32057
|
+
async function signPersonalServerLiteOwnerBindingWithAccountClient(config) {
|
|
32058
|
+
let address;
|
|
32059
|
+
try {
|
|
32060
|
+
address = await config.client.getAddress();
|
|
32061
|
+
} catch (error) {
|
|
32062
|
+
throw accountOwnerBindingError(error);
|
|
32063
|
+
}
|
|
32064
|
+
if (!address) {
|
|
32065
|
+
throw new AccountPersonalServerLiteOwnerBindingError({
|
|
32066
|
+
message: "Account did not return a wallet address",
|
|
32067
|
+
code: "account_address_required"
|
|
32068
|
+
});
|
|
32069
|
+
}
|
|
32070
|
+
const message = buildPersonalServerLiteOwnerBindingMessage(address);
|
|
32071
|
+
let signature;
|
|
32072
|
+
try {
|
|
32073
|
+
signature = await config.client.signMessage({ message });
|
|
32074
|
+
} catch (error) {
|
|
32075
|
+
throw accountOwnerBindingError(error);
|
|
32076
|
+
}
|
|
32077
|
+
return {
|
|
32078
|
+
signature,
|
|
32079
|
+
signerAddress: address,
|
|
32080
|
+
message,
|
|
32081
|
+
purpose: PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE
|
|
32082
|
+
};
|
|
32083
|
+
}
|
|
32084
|
+
function accountOwnerBindingError(error) {
|
|
32085
|
+
if (error instanceof AccountPersonalServerLiteOwnerBindingError) {
|
|
32086
|
+
return error;
|
|
32087
|
+
}
|
|
32088
|
+
const rpcError = error;
|
|
32089
|
+
const code = rpcError?.code;
|
|
32090
|
+
const message = typeof rpcError?.message === "string" && rpcError.message.length > 0 ? rpcError.message : "Account PS Lite owner-binding signature failed";
|
|
32091
|
+
return new AccountPersonalServerLiteOwnerBindingError({
|
|
32092
|
+
message,
|
|
32093
|
+
code,
|
|
32094
|
+
details: error
|
|
32095
|
+
});
|
|
32096
|
+
}
|
|
32097
|
+
|
|
32098
|
+
// src/protocol/grants.ts
|
|
32099
|
+
import { verifyTypedData } from "viem";
|
|
32100
|
+
function isHexString(value) {
|
|
32101
|
+
return typeof value === "string" && value.startsWith("0x");
|
|
32102
|
+
}
|
|
32103
|
+
function isDataPortabilityGatewayConfig(value) {
|
|
32104
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
32105
|
+
return false;
|
|
32106
|
+
}
|
|
32107
|
+
const config = value;
|
|
32108
|
+
const contracts = config["contracts"];
|
|
32109
|
+
if (typeof config["chainId"] !== "number" || !Number.isInteger(config["chainId"]) || config["chainId"] <= 0 || contracts === null || typeof contracts !== "object" || Array.isArray(contracts)) {
|
|
32110
|
+
return false;
|
|
32111
|
+
}
|
|
32112
|
+
const c = contracts;
|
|
32113
|
+
return isHexString(c["dataRegistry"]) && isHexString(c["dataPortabilityPermissions"]) && isHexString(c["dataPortabilityServer"]) && isHexString(c["dataPortabilityGrantees"]);
|
|
32114
|
+
}
|
|
32115
|
+
function parseGrantRegistrationPayload(grant) {
|
|
32116
|
+
let parsed;
|
|
32117
|
+
try {
|
|
32118
|
+
parsed = JSON.parse(grant);
|
|
32119
|
+
} catch {
|
|
32120
|
+
return null;
|
|
32121
|
+
}
|
|
32122
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
32123
|
+
return null;
|
|
32124
|
+
}
|
|
32125
|
+
const value = parsed;
|
|
32126
|
+
if (!Array.isArray(value["scopes"]) || value["scopes"].length === 0) {
|
|
32127
|
+
return null;
|
|
32128
|
+
}
|
|
32129
|
+
if (!value["scopes"].every((scope) => typeof scope === "string")) {
|
|
32130
|
+
return null;
|
|
32131
|
+
}
|
|
32132
|
+
if (typeof value["expiresAt"] !== "number" || !Number.isFinite(value["expiresAt"])) {
|
|
32133
|
+
return null;
|
|
32134
|
+
}
|
|
32135
|
+
if (value["user"] !== void 0 && !isHexString(value["user"])) {
|
|
32136
|
+
return null;
|
|
32137
|
+
}
|
|
32138
|
+
if (value["builder"] !== void 0 && !isHexString(value["builder"])) {
|
|
32139
|
+
return null;
|
|
32140
|
+
}
|
|
32141
|
+
if (value["nonce"] !== void 0 && (typeof value["nonce"] !== "number" || !Number.isFinite(value["nonce"]))) {
|
|
32142
|
+
return null;
|
|
32143
|
+
}
|
|
32144
|
+
return {
|
|
32145
|
+
user: value["user"],
|
|
32146
|
+
builder: value["builder"],
|
|
32147
|
+
scopes: value["scopes"],
|
|
32148
|
+
expiresAt: value["expiresAt"],
|
|
32149
|
+
nonce: value["nonce"]
|
|
32150
|
+
};
|
|
32151
|
+
}
|
|
32152
|
+
function parseFileIds(fileIds) {
|
|
32153
|
+
try {
|
|
32154
|
+
const values = (fileIds ?? []).map((fileId) => BigInt(fileId));
|
|
32155
|
+
return {
|
|
32156
|
+
values,
|
|
32157
|
+
display: values.map((fileId) => fileId.toString())
|
|
32158
|
+
};
|
|
32159
|
+
} catch {
|
|
32160
|
+
return null;
|
|
32161
|
+
}
|
|
32162
|
+
}
|
|
32163
|
+
async function verifyGrantRegistration(input) {
|
|
32164
|
+
const payload = parseGrantRegistrationPayload(input.grant);
|
|
32165
|
+
if (!payload) {
|
|
32166
|
+
return {
|
|
32167
|
+
valid: false,
|
|
32168
|
+
error: "Grant must be JSON with scopes and expiresAt"
|
|
32169
|
+
};
|
|
32170
|
+
}
|
|
32171
|
+
const fileIds = parseFileIds(input.fileIds);
|
|
32172
|
+
if (!fileIds) {
|
|
32173
|
+
return { valid: false, error: "fileIds must contain integer values" };
|
|
32174
|
+
}
|
|
32175
|
+
let valid;
|
|
32176
|
+
try {
|
|
32177
|
+
valid = await verifyTypedData({
|
|
32178
|
+
address: input.grantorAddress,
|
|
32179
|
+
domain: grantRegistrationDomain(input.gatewayConfig),
|
|
32180
|
+
types: GRANT_REGISTRATION_TYPES,
|
|
32181
|
+
primaryType: "GrantRegistration",
|
|
32182
|
+
message: {
|
|
32183
|
+
grantorAddress: input.grantorAddress,
|
|
32184
|
+
granteeId: input.granteeId,
|
|
32185
|
+
grant: input.grant,
|
|
32186
|
+
fileIds: fileIds.values
|
|
32187
|
+
},
|
|
32188
|
+
signature: input.signature
|
|
32189
|
+
});
|
|
32190
|
+
} catch {
|
|
32191
|
+
return { valid: false, error: "EIP-712 signature verification failed" };
|
|
32192
|
+
}
|
|
32193
|
+
if (!valid) {
|
|
32194
|
+
return { valid: false, error: "Grant signature does not match grantor" };
|
|
32195
|
+
}
|
|
32196
|
+
const nowSeconds = input.nowSeconds ?? Math.floor(Date.now() / 1e3);
|
|
32197
|
+
if (payload.expiresAt > 0 && payload.expiresAt < nowSeconds) {
|
|
32198
|
+
return { valid: false, error: "Grant has expired" };
|
|
32199
|
+
}
|
|
32200
|
+
if (payload.user !== void 0 && payload.user.toLowerCase() !== input.grantorAddress.toLowerCase()) {
|
|
32201
|
+
return { valid: false, error: "Grant user does not match grantorAddress" };
|
|
32202
|
+
}
|
|
32203
|
+
return {
|
|
32204
|
+
valid: true,
|
|
32205
|
+
grantorAddress: input.grantorAddress,
|
|
32206
|
+
granteeId: input.granteeId,
|
|
32207
|
+
grant: input.grant,
|
|
32208
|
+
payload,
|
|
32209
|
+
fileIds: fileIds.display
|
|
32210
|
+
};
|
|
32211
|
+
}
|
|
32212
|
+
|
|
31714
32213
|
// src/protocol/scopes.ts
|
|
31715
32214
|
import { z } from "zod";
|
|
31716
32215
|
var SEGMENT_RE = /^[a-z0-9][a-z0-9_]*$/;
|
|
@@ -31991,34 +32490,62 @@ var PSError = class extends Error {
|
|
|
31991
32490
|
code;
|
|
31992
32491
|
};
|
|
31993
32492
|
var KNOWN_CODES = /* @__PURE__ */ new Set([
|
|
32493
|
+
"missing_auth",
|
|
32494
|
+
"invalid_signature",
|
|
32495
|
+
"unregistered_builder",
|
|
32496
|
+
"not_owner",
|
|
32497
|
+
"expired_token",
|
|
31994
32498
|
"grant_invalid",
|
|
32499
|
+
"grant_required",
|
|
32500
|
+
"grant_expired",
|
|
31995
32501
|
"grant_revoked",
|
|
32502
|
+
"scope_mismatch",
|
|
31996
32503
|
"fee_required",
|
|
31997
|
-
"ps_unavailable"
|
|
32504
|
+
"ps_unavailable",
|
|
32505
|
+
"server_not_configured",
|
|
32506
|
+
"content_too_large"
|
|
31998
32507
|
]);
|
|
31999
|
-
|
|
32000
|
-
|
|
32508
|
+
function isRecord2(value) {
|
|
32509
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
32510
|
+
}
|
|
32511
|
+
function normalizeCode(value) {
|
|
32512
|
+
if (typeof value !== "string") {
|
|
32001
32513
|
return null;
|
|
32002
32514
|
}
|
|
32003
|
-
|
|
32004
|
-
|
|
32005
|
-
|
|
32006
|
-
|
|
32515
|
+
const code = value.toLowerCase();
|
|
32516
|
+
return KNOWN_CODES.has(code) ? code : null;
|
|
32517
|
+
}
|
|
32518
|
+
function extractPSErrorBody(body) {
|
|
32519
|
+
if (!isRecord2(body)) {
|
|
32007
32520
|
return null;
|
|
32008
32521
|
}
|
|
32009
|
-
|
|
32522
|
+
const nested = isRecord2(body.error) ? body.error : null;
|
|
32523
|
+
const code = normalizeCode(
|
|
32524
|
+
nested?.errorCode ?? nested?.code ?? body.errorCode ?? body.code
|
|
32525
|
+
);
|
|
32526
|
+
const message = nested?.message ?? body.message;
|
|
32527
|
+
if (!code || typeof message !== "string") {
|
|
32010
32528
|
return null;
|
|
32011
32529
|
}
|
|
32012
|
-
|
|
32013
|
-
|
|
32530
|
+
return { code, message };
|
|
32531
|
+
}
|
|
32532
|
+
async function parsePSError(response) {
|
|
32533
|
+
if (response.ok) {
|
|
32014
32534
|
return null;
|
|
32015
32535
|
}
|
|
32016
|
-
|
|
32536
|
+
let body;
|
|
32537
|
+
try {
|
|
32538
|
+
body = await response.json();
|
|
32539
|
+
} catch {
|
|
32017
32540
|
return null;
|
|
32018
32541
|
}
|
|
32019
|
-
|
|
32542
|
+
const errorBody = extractPSErrorBody(body);
|
|
32543
|
+
return errorBody ? new PSError(errorBody.code, errorBody.message) : null;
|
|
32020
32544
|
}
|
|
32021
32545
|
export {
|
|
32546
|
+
ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
|
|
32547
|
+
AccountPersonalServerLiteOwnerBindingError,
|
|
32548
|
+
AccountPersonalServerRegistrationError,
|
|
32022
32549
|
BUILDER_REGISTRATION_TYPES,
|
|
32023
32550
|
BlockchainError,
|
|
32024
32551
|
BrowserECIESUint8Provider as BrowserECIESProvider,
|
|
@@ -32044,6 +32571,11 @@ export {
|
|
|
32044
32571
|
MissingAuthError,
|
|
32045
32572
|
NetworkError,
|
|
32046
32573
|
NonceError,
|
|
32574
|
+
PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX,
|
|
32575
|
+
PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE,
|
|
32576
|
+
PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION,
|
|
32577
|
+
PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,
|
|
32578
|
+
PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT,
|
|
32047
32579
|
PKCE_CHALLENGE_PATTERN,
|
|
32048
32580
|
PKCE_VERIFIER_PATTERN,
|
|
32049
32581
|
PSError,
|
|
@@ -32065,6 +32597,10 @@ export {
|
|
|
32065
32597
|
VanaError,
|
|
32066
32598
|
VanaStorage,
|
|
32067
32599
|
assertValidPkceVerifier,
|
|
32600
|
+
buildPersonalServerLiteOwnerBindingMessage,
|
|
32601
|
+
buildPersonalServerLiteOwnerBindingSignature,
|
|
32602
|
+
buildPersonalServerRegistrationSignature,
|
|
32603
|
+
buildPersonalServerRegistrationTypedData,
|
|
32068
32604
|
buildWeb3SignedHeader,
|
|
32069
32605
|
builderRegistrationDomain,
|
|
32070
32606
|
chains,
|
|
@@ -32077,6 +32613,8 @@ export {
|
|
|
32077
32613
|
createGatewayClient,
|
|
32078
32614
|
createPlatformAdapterSafe,
|
|
32079
32615
|
createVanaStorageProvider,
|
|
32616
|
+
createViemPersonalServerLiteOwnerBindingSigner,
|
|
32617
|
+
createViemPersonalServerRegistrationSigner,
|
|
32080
32618
|
decryptWithPassword,
|
|
32081
32619
|
deriveMasterKey,
|
|
32082
32620
|
deriveScopeKey,
|
|
@@ -32095,22 +32633,30 @@ export {
|
|
|
32095
32633
|
getServiceEndpoints,
|
|
32096
32634
|
grantRegistrationDomain,
|
|
32097
32635
|
grantRevocationDomain,
|
|
32636
|
+
isDataPortabilityGatewayConfig,
|
|
32098
32637
|
isECIESEncrypted,
|
|
32099
32638
|
isPlatformSupported,
|
|
32100
32639
|
mainnetServices,
|
|
32101
32640
|
moksha,
|
|
32102
32641
|
mokshaServices,
|
|
32103
32642
|
mokshaTestnet2 as mokshaTestnet,
|
|
32643
|
+
parseGrantRegistrationPayload,
|
|
32104
32644
|
parsePSError,
|
|
32105
32645
|
parseScope,
|
|
32106
32646
|
parseWeb3SignedHeader,
|
|
32647
|
+
personalServerRegistrationDomain,
|
|
32107
32648
|
recoverServerOwner,
|
|
32649
|
+
registerPersonalServerSignature,
|
|
32108
32650
|
scopeCoveredByGrant,
|
|
32109
32651
|
scopeMatchesPattern,
|
|
32110
32652
|
scopeToPathSegments,
|
|
32111
32653
|
serializeECIES,
|
|
32112
32654
|
serverRegistrationDomain,
|
|
32655
|
+
signPersonalServerLiteOwnerBinding,
|
|
32656
|
+
signPersonalServerLiteOwnerBindingWithAccountClient,
|
|
32657
|
+
signPersonalServerRegistrationWithAccount,
|
|
32113
32658
|
vanaMainnet2 as vanaMainnet,
|
|
32659
|
+
verifyGrantRegistration,
|
|
32114
32660
|
verifyPkceChallenge,
|
|
32115
32661
|
verifyWeb3Signed
|
|
32116
32662
|
};
|