@opendatalabs/vana-sdk 3.1.0 → 3.2.0
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/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.js +2 -2
- 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 +4 -0
- package/dist/index.browser.js +447 -3
- package/dist/index.browser.js.map +4 -4
- package/dist/index.node.cjs +464 -5
- package/dist/index.node.cjs.map +4 -4
- package/dist/index.node.d.ts +4 -0
- package/dist/index.node.js +447 -3
- 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.map +1 -1
- package/dist/protocol/eip712.d.ts +1 -1
- package/dist/protocol/eip712.js.map +1 -1
- package/dist/protocol/grants.js +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.js +10 -10
- 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.js +2 -2
- package/dist/types/index.js +2 -2
- package/dist/types.js +1 -1
- package/package.json +4 -2
package/dist/index.node.cjs
CHANGED
|
@@ -1173,6 +1173,9 @@ 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
|
+
AccountPersonalServerLiteOwnerBindingError: () => AccountPersonalServerLiteOwnerBindingError,
|
|
1178
|
+
AccountPersonalServerRegistrationError: () => AccountPersonalServerRegistrationError,
|
|
1176
1179
|
BUILDER_REGISTRATION_TYPES: () => BUILDER_REGISTRATION_TYPES,
|
|
1177
1180
|
BlockchainError: () => BlockchainError,
|
|
1178
1181
|
BrowserPlatformAdapter: () => BrowserPlatformAdapter,
|
|
@@ -1200,6 +1203,11 @@ __export(index_node_exports, {
|
|
|
1200
1203
|
NodePlatformAdapter: () => NodePlatformAdapter,
|
|
1201
1204
|
NonceError: () => NonceError,
|
|
1202
1205
|
OAuthClient: () => OAuthClient,
|
|
1206
|
+
PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX: () => PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX,
|
|
1207
|
+
PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE: () => PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE,
|
|
1208
|
+
PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION: () => PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION,
|
|
1209
|
+
PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID: () => PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,
|
|
1210
|
+
PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT: () => PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT,
|
|
1203
1211
|
PKCE_CHALLENGE_PATTERN: () => PKCE_CHALLENGE_PATTERN,
|
|
1204
1212
|
PKCE_VERIFIER_PATTERN: () => PKCE_VERIFIER_PATTERN,
|
|
1205
1213
|
PSError: () => PSError,
|
|
@@ -1221,6 +1229,10 @@ __export(index_node_exports, {
|
|
|
1221
1229
|
VanaError: () => VanaError,
|
|
1222
1230
|
VanaStorage: () => VanaStorage,
|
|
1223
1231
|
assertValidPkceVerifier: () => assertValidPkceVerifier,
|
|
1232
|
+
buildPersonalServerLiteOwnerBindingMessage: () => buildPersonalServerLiteOwnerBindingMessage,
|
|
1233
|
+
buildPersonalServerLiteOwnerBindingSignature: () => buildPersonalServerLiteOwnerBindingSignature,
|
|
1234
|
+
buildPersonalServerRegistrationSignature: () => buildPersonalServerRegistrationSignature,
|
|
1235
|
+
buildPersonalServerRegistrationTypedData: () => buildPersonalServerRegistrationTypedData,
|
|
1224
1236
|
buildWeb3SignedHeader: () => buildWeb3SignedHeader,
|
|
1225
1237
|
builderRegistrationDomain: () => builderRegistrationDomain,
|
|
1226
1238
|
chains: () => chains,
|
|
@@ -1236,6 +1248,8 @@ __export(index_node_exports, {
|
|
|
1236
1248
|
createPlatformAdapterFor: () => createPlatformAdapterFor,
|
|
1237
1249
|
createPlatformAdapterSafe: () => createPlatformAdapterSafe,
|
|
1238
1250
|
createVanaStorageProvider: () => createVanaStorageProvider,
|
|
1251
|
+
createViemPersonalServerLiteOwnerBindingSigner: () => createViemPersonalServerLiteOwnerBindingSigner,
|
|
1252
|
+
createViemPersonalServerRegistrationSigner: () => createViemPersonalServerRegistrationSigner,
|
|
1239
1253
|
decryptWithPassword: () => decryptWithPassword,
|
|
1240
1254
|
deriveMasterKey: () => deriveMasterKey,
|
|
1241
1255
|
deriveScopeKey: () => deriveScopeKey,
|
|
@@ -1265,12 +1279,17 @@ __export(index_node_exports, {
|
|
|
1265
1279
|
parsePSError: () => parsePSError,
|
|
1266
1280
|
parseScope: () => parseScope,
|
|
1267
1281
|
parseWeb3SignedHeader: () => parseWeb3SignedHeader,
|
|
1282
|
+
personalServerRegistrationDomain: () => personalServerRegistrationDomain,
|
|
1268
1283
|
recoverServerOwner: () => recoverServerOwner,
|
|
1284
|
+
registerPersonalServerSignature: () => registerPersonalServerSignature,
|
|
1269
1285
|
scopeCoveredByGrant: () => scopeCoveredByGrant,
|
|
1270
1286
|
scopeMatchesPattern: () => scopeMatchesPattern,
|
|
1271
1287
|
scopeToPathSegments: () => scopeToPathSegments,
|
|
1272
1288
|
serializeECIES: () => serializeECIES,
|
|
1273
1289
|
serverRegistrationDomain: () => serverRegistrationDomain,
|
|
1290
|
+
signPersonalServerLiteOwnerBinding: () => signPersonalServerLiteOwnerBinding,
|
|
1291
|
+
signPersonalServerLiteOwnerBindingWithAccountClient: () => signPersonalServerLiteOwnerBindingWithAccountClient,
|
|
1292
|
+
signPersonalServerRegistrationWithAccount: () => signPersonalServerRegistrationWithAccount,
|
|
1274
1293
|
vanaMainnet: () => vanaMainnet2,
|
|
1275
1294
|
verifyGrantRegistration: () => verifyGrantRegistration,
|
|
1276
1295
|
verifyPkceChallenge: () => verifyPkceChallenge,
|
|
@@ -32704,8 +32723,429 @@ var BUILDER_REGISTRATION_TYPES = {
|
|
|
32704
32723
|
]
|
|
32705
32724
|
};
|
|
32706
32725
|
|
|
32707
|
-
// src/protocol/
|
|
32726
|
+
// src/protocol/personal-server-registration.ts
|
|
32708
32727
|
var import_viem14 = require("viem");
|
|
32728
|
+
var PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID = 1480;
|
|
32729
|
+
var PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT = "0x1483B1F634DBA75AeaE60da7f01A679aabd5ee2c";
|
|
32730
|
+
function assertAddress(value, name) {
|
|
32731
|
+
if (!(0, import_viem14.isAddress)(value)) {
|
|
32732
|
+
throw new Error(`${name} must be a valid EVM address`);
|
|
32733
|
+
}
|
|
32734
|
+
}
|
|
32735
|
+
function getAccountAddress(account) {
|
|
32736
|
+
if (!account) {
|
|
32737
|
+
return void 0;
|
|
32738
|
+
}
|
|
32739
|
+
return typeof account === "string" ? account : account.address;
|
|
32740
|
+
}
|
|
32741
|
+
function isPersonalServerRegistrationSigner(source) {
|
|
32742
|
+
return "address" in source && typeof source.signTypedData === "function";
|
|
32743
|
+
}
|
|
32744
|
+
function createViemPersonalServerRegistrationSigner(source, options = {}) {
|
|
32745
|
+
if (isPersonalServerRegistrationSigner(source)) {
|
|
32746
|
+
return source;
|
|
32747
|
+
}
|
|
32748
|
+
const accountAddress = getAccountAddress(options.account) ?? getAccountAddress(source.account);
|
|
32749
|
+
if (accountAddress) {
|
|
32750
|
+
return {
|
|
32751
|
+
address: accountAddress,
|
|
32752
|
+
signTypedData: (typedData) => source.signTypedData({
|
|
32753
|
+
...typedData,
|
|
32754
|
+
account: options.account ?? source.account ?? accountAddress
|
|
32755
|
+
})
|
|
32756
|
+
};
|
|
32757
|
+
}
|
|
32758
|
+
throw new Error(
|
|
32759
|
+
"Viem wallet client requires an account option or account property"
|
|
32760
|
+
);
|
|
32761
|
+
}
|
|
32762
|
+
function personalServerRegistrationDomain(input = {}) {
|
|
32763
|
+
if (input.config) {
|
|
32764
|
+
return serverRegistrationDomain(input.config);
|
|
32765
|
+
}
|
|
32766
|
+
const verifyingContract = input.verifyingContract ?? PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT;
|
|
32767
|
+
assertAddress(verifyingContract, "verifyingContract");
|
|
32768
|
+
return {
|
|
32769
|
+
name: "Vana Data Portability",
|
|
32770
|
+
version: "1",
|
|
32771
|
+
chainId: input.chainId ?? PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,
|
|
32772
|
+
verifyingContract
|
|
32773
|
+
};
|
|
32774
|
+
}
|
|
32775
|
+
function buildPersonalServerRegistrationTypedData(input) {
|
|
32776
|
+
assertAddress(input.ownerAddress, "ownerAddress");
|
|
32777
|
+
assertAddress(input.serverAddress, "serverAddress");
|
|
32778
|
+
return {
|
|
32779
|
+
domain: personalServerRegistrationDomain(input),
|
|
32780
|
+
types: SERVER_REGISTRATION_TYPES,
|
|
32781
|
+
primaryType: "ServerRegistration",
|
|
32782
|
+
message: {
|
|
32783
|
+
ownerAddress: input.ownerAddress,
|
|
32784
|
+
serverAddress: input.serverAddress,
|
|
32785
|
+
publicKey: input.serverPublicKey,
|
|
32786
|
+
serverUrl: input.serverUrl
|
|
32787
|
+
}
|
|
32788
|
+
};
|
|
32789
|
+
}
|
|
32790
|
+
async function buildPersonalServerRegistrationSignature(input) {
|
|
32791
|
+
const typedData = buildPersonalServerRegistrationTypedData({
|
|
32792
|
+
ownerAddress: input.signer.address,
|
|
32793
|
+
serverAddress: input.serverAddress,
|
|
32794
|
+
serverPublicKey: input.serverPublicKey,
|
|
32795
|
+
serverUrl: input.serverUrl,
|
|
32796
|
+
config: input.config,
|
|
32797
|
+
chainId: input.chainId,
|
|
32798
|
+
verifyingContract: input.verifyingContract
|
|
32799
|
+
});
|
|
32800
|
+
const signature = await input.signer.signTypedData(typedData);
|
|
32801
|
+
return {
|
|
32802
|
+
signature,
|
|
32803
|
+
signerAddress: input.signer.address,
|
|
32804
|
+
typedData
|
|
32805
|
+
};
|
|
32806
|
+
}
|
|
32807
|
+
var registerPersonalServerSignature = buildPersonalServerRegistrationSignature;
|
|
32808
|
+
|
|
32809
|
+
// src/protocol/personal-server-lite-owner-binding.ts
|
|
32810
|
+
var import_viem15 = require("viem");
|
|
32811
|
+
var PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION = "vana.account.v1";
|
|
32812
|
+
var PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE = "ps-lite-owner";
|
|
32813
|
+
var PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX = `${PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION}:${PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE}:`;
|
|
32814
|
+
function assertAddress2(value, name) {
|
|
32815
|
+
if (!(0, import_viem15.isAddress)(value)) {
|
|
32816
|
+
throw new Error(`${name} must be a valid EVM address`);
|
|
32817
|
+
}
|
|
32818
|
+
}
|
|
32819
|
+
function getAccountAddress2(account) {
|
|
32820
|
+
if (!account) {
|
|
32821
|
+
return void 0;
|
|
32822
|
+
}
|
|
32823
|
+
return typeof account === "string" ? account : account.address;
|
|
32824
|
+
}
|
|
32825
|
+
function isPersonalServerLiteOwnerBindingSigner(source) {
|
|
32826
|
+
return "address" in source && typeof source.signMessage === "function";
|
|
32827
|
+
}
|
|
32828
|
+
function buildPersonalServerLiteOwnerBindingMessage(ownerAddress) {
|
|
32829
|
+
assertAddress2(ownerAddress, "ownerAddress");
|
|
32830
|
+
return `${PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX}${ownerAddress.toLowerCase()}`;
|
|
32831
|
+
}
|
|
32832
|
+
function createViemPersonalServerLiteOwnerBindingSigner(source, options = {}) {
|
|
32833
|
+
if (isPersonalServerLiteOwnerBindingSigner(source)) {
|
|
32834
|
+
return source;
|
|
32835
|
+
}
|
|
32836
|
+
const accountAddress = getAccountAddress2(options.account) ?? getAccountAddress2(source.account);
|
|
32837
|
+
if (accountAddress) {
|
|
32838
|
+
return {
|
|
32839
|
+
address: accountAddress,
|
|
32840
|
+
signMessage: ({ message }) => source.signMessage({
|
|
32841
|
+
account: options.account ?? source.account ?? accountAddress,
|
|
32842
|
+
message
|
|
32843
|
+
})
|
|
32844
|
+
};
|
|
32845
|
+
}
|
|
32846
|
+
throw new Error(
|
|
32847
|
+
"Viem wallet client requires an account option or account property"
|
|
32848
|
+
);
|
|
32849
|
+
}
|
|
32850
|
+
async function buildPersonalServerLiteOwnerBindingSignature(input) {
|
|
32851
|
+
const message = buildPersonalServerLiteOwnerBindingMessage(
|
|
32852
|
+
input.signer.address
|
|
32853
|
+
);
|
|
32854
|
+
const signature = await input.signer.signMessage({ message });
|
|
32855
|
+
return {
|
|
32856
|
+
signature,
|
|
32857
|
+
signerAddress: input.signer.address,
|
|
32858
|
+
message,
|
|
32859
|
+
purpose: PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE
|
|
32860
|
+
};
|
|
32861
|
+
}
|
|
32862
|
+
var signPersonalServerLiteOwnerBinding = buildPersonalServerLiteOwnerBindingSignature;
|
|
32863
|
+
|
|
32864
|
+
// src/account/personal-server-registration.ts
|
|
32865
|
+
var import_viem16 = require("viem");
|
|
32866
|
+
var ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT = "personal_server.server_registration.v1";
|
|
32867
|
+
var AccountPersonalServerRegistrationError = class extends Error {
|
|
32868
|
+
status;
|
|
32869
|
+
code;
|
|
32870
|
+
details;
|
|
32871
|
+
constructor(input) {
|
|
32872
|
+
super(input.message);
|
|
32873
|
+
this.name = "AccountPersonalServerRegistrationError";
|
|
32874
|
+
this.status = input.status;
|
|
32875
|
+
this.code = input.code;
|
|
32876
|
+
this.details = input.details;
|
|
32877
|
+
}
|
|
32878
|
+
};
|
|
32879
|
+
var DEFAULT_ACCOUNT_PS_REGISTRATION_PATH = "/api/v1/intents/personal-server-registration/sign";
|
|
32880
|
+
function trimTrailingSlash(value) {
|
|
32881
|
+
return value.replace(/\/+$/, "");
|
|
32882
|
+
}
|
|
32883
|
+
function assertAddress3(value, name) {
|
|
32884
|
+
if (!(0, import_viem16.isAddress)(value)) {
|
|
32885
|
+
throw new Error(`${name} must be a valid EVM address`);
|
|
32886
|
+
}
|
|
32887
|
+
}
|
|
32888
|
+
async function parseAccountResponse(response) {
|
|
32889
|
+
const body = await response.json().catch(() => void 0);
|
|
32890
|
+
if (!response.ok) {
|
|
32891
|
+
throw new AccountPersonalServerRegistrationError({
|
|
32892
|
+
status: response.status,
|
|
32893
|
+
code: accountErrorCode(body),
|
|
32894
|
+
message: accountErrorMessage(response.status, body),
|
|
32895
|
+
details: body
|
|
32896
|
+
});
|
|
32897
|
+
}
|
|
32898
|
+
return body;
|
|
32899
|
+
}
|
|
32900
|
+
function accountErrorMessage(status, body) {
|
|
32901
|
+
const nestedMessage = nestedAccountErrorField(body, "message");
|
|
32902
|
+
if (nestedMessage) {
|
|
32903
|
+
return nestedMessage;
|
|
32904
|
+
}
|
|
32905
|
+
if (isRecord(body) && typeof body.message === "string") {
|
|
32906
|
+
return body.message;
|
|
32907
|
+
}
|
|
32908
|
+
const code = accountErrorCode(body);
|
|
32909
|
+
if (code) {
|
|
32910
|
+
return `Account PS registration signing failed: ${code}`;
|
|
32911
|
+
}
|
|
32912
|
+
return `Account PS registration signing failed: ${status}`;
|
|
32913
|
+
}
|
|
32914
|
+
function accountErrorCode(body) {
|
|
32915
|
+
const nestedCode = nestedAccountErrorField(body, "code");
|
|
32916
|
+
if (nestedCode) {
|
|
32917
|
+
return nestedCode;
|
|
32918
|
+
}
|
|
32919
|
+
if (isRecord(body)) {
|
|
32920
|
+
if (typeof body.code === "string") {
|
|
32921
|
+
return body.code;
|
|
32922
|
+
}
|
|
32923
|
+
if (typeof body.error === "string") {
|
|
32924
|
+
return body.error;
|
|
32925
|
+
}
|
|
32926
|
+
}
|
|
32927
|
+
return void 0;
|
|
32928
|
+
}
|
|
32929
|
+
function nestedAccountErrorField(body, field) {
|
|
32930
|
+
if (!isRecord(body) || !isRecord(body.error)) {
|
|
32931
|
+
return void 0;
|
|
32932
|
+
}
|
|
32933
|
+
const value = body.error[field];
|
|
32934
|
+
return typeof value === "string" ? value : void 0;
|
|
32935
|
+
}
|
|
32936
|
+
function isRecord(value) {
|
|
32937
|
+
return typeof value === "object" && value !== null;
|
|
32938
|
+
}
|
|
32939
|
+
function normalizeAccountResponse(response) {
|
|
32940
|
+
return {
|
|
32941
|
+
...response,
|
|
32942
|
+
status: response.status === "fallback_required" ? "confirmation_required" : response.status,
|
|
32943
|
+
signerAddress: response.signerAddress ?? response.signer?.address,
|
|
32944
|
+
typedData: response.typedData ?? response.typed_data
|
|
32945
|
+
};
|
|
32946
|
+
}
|
|
32947
|
+
function buildSignedResult(response, request) {
|
|
32948
|
+
assertAddress3(response.signerAddress, "signerAddress");
|
|
32949
|
+
if (response.typedData) {
|
|
32950
|
+
assertTypedDataMatchesRequest(
|
|
32951
|
+
response.typedData,
|
|
32952
|
+
request,
|
|
32953
|
+
response.signerAddress
|
|
32954
|
+
);
|
|
32955
|
+
}
|
|
32956
|
+
return {
|
|
32957
|
+
signature: response.signature,
|
|
32958
|
+
signerAddress: response.signerAddress,
|
|
32959
|
+
typedData: response.typedData ?? buildPersonalServerRegistrationTypedData({
|
|
32960
|
+
ownerAddress: response.signerAddress,
|
|
32961
|
+
...request
|
|
32962
|
+
}),
|
|
32963
|
+
intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT
|
|
32964
|
+
};
|
|
32965
|
+
}
|
|
32966
|
+
function assertTypedDataMatchesRequest(typedData, request, expectedSignerAddress) {
|
|
32967
|
+
assertAddress3(
|
|
32968
|
+
typedData.message.ownerAddress,
|
|
32969
|
+
"typedData.message.ownerAddress"
|
|
32970
|
+
);
|
|
32971
|
+
assertAddress3(
|
|
32972
|
+
typedData.message.serverAddress,
|
|
32973
|
+
"typedData.message.serverAddress"
|
|
32974
|
+
);
|
|
32975
|
+
if (expectedSignerAddress && !sameAddress(typedData.message.ownerAddress, expectedSignerAddress)) {
|
|
32976
|
+
throw new Error(
|
|
32977
|
+
"Account typedData ownerAddress must match the expected signer address"
|
|
32978
|
+
);
|
|
32979
|
+
}
|
|
32980
|
+
if (!sameAddress(typedData.message.serverAddress, request.serverAddress)) {
|
|
32981
|
+
throw new Error(
|
|
32982
|
+
"Account typedData serverAddress must match the requested serverAddress"
|
|
32983
|
+
);
|
|
32984
|
+
}
|
|
32985
|
+
if (typedData.message.publicKey !== request.serverPublicKey) {
|
|
32986
|
+
throw new Error(
|
|
32987
|
+
"Account typedData publicKey must match the requested serverPublicKey"
|
|
32988
|
+
);
|
|
32989
|
+
}
|
|
32990
|
+
if (typedData.message.serverUrl !== request.serverUrl) {
|
|
32991
|
+
throw new Error(
|
|
32992
|
+
"Account typedData serverUrl must match the requested serverUrl"
|
|
32993
|
+
);
|
|
32994
|
+
}
|
|
32995
|
+
if (typedData.primaryType !== "ServerRegistration") {
|
|
32996
|
+
throw new Error("Account typedData primaryType must be ServerRegistration");
|
|
32997
|
+
}
|
|
32998
|
+
if (JSON.stringify(typedData.types) !== JSON.stringify(SERVER_REGISTRATION_TYPES)) {
|
|
32999
|
+
throw new Error("Account typedData types must be ServerRegistration types");
|
|
33000
|
+
}
|
|
33001
|
+
const expectedDomain = personalServerRegistrationDomain({
|
|
33002
|
+
config: request.config,
|
|
33003
|
+
chainId: request.chainId,
|
|
33004
|
+
verifyingContract: request.verifyingContract
|
|
33005
|
+
});
|
|
33006
|
+
if (!domainsEqual(typedData.domain, expectedDomain)) {
|
|
33007
|
+
throw new Error("Account typedData domain must match the requested domain");
|
|
33008
|
+
}
|
|
33009
|
+
}
|
|
33010
|
+
function sameAddress(a, b) {
|
|
33011
|
+
return a.toLowerCase() === b.toLowerCase();
|
|
33012
|
+
}
|
|
33013
|
+
function domainsEqual(a, b) {
|
|
33014
|
+
if (!a || !b) {
|
|
33015
|
+
return false;
|
|
33016
|
+
}
|
|
33017
|
+
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;
|
|
33018
|
+
}
|
|
33019
|
+
async function signPersonalServerRegistrationWithAccount(config, request) {
|
|
33020
|
+
assertAddress3(request.serverAddress, "serverAddress");
|
|
33021
|
+
const fetchImpl = config.fetchImpl ?? globalThis.fetch.bind(globalThis);
|
|
33022
|
+
const endpoint = new URL(
|
|
33023
|
+
config.endpointPath ?? DEFAULT_ACCOUNT_PS_REGISTRATION_PATH,
|
|
33024
|
+
`${trimTrailingSlash(config.accountOrigin)}/`
|
|
33025
|
+
);
|
|
33026
|
+
const response = await fetchImpl(endpoint, {
|
|
33027
|
+
method: "POST",
|
|
33028
|
+
headers: { "content-type": "application/json" },
|
|
33029
|
+
credentials: "include",
|
|
33030
|
+
body: JSON.stringify({
|
|
33031
|
+
intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
|
|
33032
|
+
serverAddress: request.serverAddress,
|
|
33033
|
+
serverPublicKey: request.serverPublicKey,
|
|
33034
|
+
serverUrl: request.serverUrl,
|
|
33035
|
+
config: request.config,
|
|
33036
|
+
chainId: request.chainId,
|
|
33037
|
+
verifyingContract: request.verifyingContract
|
|
33038
|
+
})
|
|
33039
|
+
});
|
|
33040
|
+
const body = normalizeAccountResponse(await parseAccountResponse(response));
|
|
33041
|
+
if (body.status === "signed") {
|
|
33042
|
+
if (!body.signature || !body.signerAddress) {
|
|
33043
|
+
throw new Error(
|
|
33044
|
+
"Account signed response must include signature and signerAddress"
|
|
33045
|
+
);
|
|
33046
|
+
}
|
|
33047
|
+
return {
|
|
33048
|
+
status: "signed",
|
|
33049
|
+
result: buildSignedResult(
|
|
33050
|
+
{
|
|
33051
|
+
signature: body.signature,
|
|
33052
|
+
signerAddress: body.signerAddress,
|
|
33053
|
+
typedData: body.typedData
|
|
33054
|
+
},
|
|
33055
|
+
request
|
|
33056
|
+
)
|
|
33057
|
+
};
|
|
33058
|
+
}
|
|
33059
|
+
if (body.status === "confirmation_required") {
|
|
33060
|
+
if (!body.typedData) {
|
|
33061
|
+
throw new Error(
|
|
33062
|
+
"Account confirmation_required response must include typedData"
|
|
33063
|
+
);
|
|
33064
|
+
}
|
|
33065
|
+
assertTypedDataMatchesRequest(body.typedData, request, body.signerAddress);
|
|
33066
|
+
if (!config.fallbackSigner) {
|
|
33067
|
+
return {
|
|
33068
|
+
status: "confirmation_required",
|
|
33069
|
+
typedData: body.typedData,
|
|
33070
|
+
signerAddress: body.signerAddress
|
|
33071
|
+
};
|
|
33072
|
+
}
|
|
33073
|
+
assertTypedDataMatchesRequest(
|
|
33074
|
+
body.typedData,
|
|
33075
|
+
request,
|
|
33076
|
+
config.fallbackSigner.address
|
|
33077
|
+
);
|
|
33078
|
+
const signature = await config.fallbackSigner.signTypedData(body.typedData);
|
|
33079
|
+
return {
|
|
33080
|
+
status: "fallback_signed",
|
|
33081
|
+
accountStatus: "confirmation_required",
|
|
33082
|
+
result: {
|
|
33083
|
+
signature,
|
|
33084
|
+
signerAddress: config.fallbackSigner.address,
|
|
33085
|
+
typedData: body.typedData,
|
|
33086
|
+
intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT
|
|
33087
|
+
}
|
|
33088
|
+
};
|
|
33089
|
+
}
|
|
33090
|
+
throw new Error(
|
|
33091
|
+
`Unsupported Account PS registration signing status: ${String(body.status)}`
|
|
33092
|
+
);
|
|
33093
|
+
}
|
|
33094
|
+
|
|
33095
|
+
// src/account/personal-server-lite-owner-binding.ts
|
|
33096
|
+
var AccountPersonalServerLiteOwnerBindingError = class extends Error {
|
|
33097
|
+
code;
|
|
33098
|
+
details;
|
|
33099
|
+
constructor(input) {
|
|
33100
|
+
super(input.message);
|
|
33101
|
+
this.name = "AccountPersonalServerLiteOwnerBindingError";
|
|
33102
|
+
this.code = input.code;
|
|
33103
|
+
this.details = input.details;
|
|
33104
|
+
}
|
|
33105
|
+
};
|
|
33106
|
+
async function signPersonalServerLiteOwnerBindingWithAccountClient(config) {
|
|
33107
|
+
let address;
|
|
33108
|
+
try {
|
|
33109
|
+
address = await config.client.getAddress();
|
|
33110
|
+
} catch (error) {
|
|
33111
|
+
throw accountOwnerBindingError(error);
|
|
33112
|
+
}
|
|
33113
|
+
if (!address) {
|
|
33114
|
+
throw new AccountPersonalServerLiteOwnerBindingError({
|
|
33115
|
+
message: "Account did not return a wallet address",
|
|
33116
|
+
code: "account_address_required"
|
|
33117
|
+
});
|
|
33118
|
+
}
|
|
33119
|
+
const message = buildPersonalServerLiteOwnerBindingMessage(address);
|
|
33120
|
+
let signature;
|
|
33121
|
+
try {
|
|
33122
|
+
signature = await config.client.signMessage({ message });
|
|
33123
|
+
} catch (error) {
|
|
33124
|
+
throw accountOwnerBindingError(error);
|
|
33125
|
+
}
|
|
33126
|
+
return {
|
|
33127
|
+
signature,
|
|
33128
|
+
signerAddress: address,
|
|
33129
|
+
message,
|
|
33130
|
+
purpose: PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE
|
|
33131
|
+
};
|
|
33132
|
+
}
|
|
33133
|
+
function accountOwnerBindingError(error) {
|
|
33134
|
+
if (error instanceof AccountPersonalServerLiteOwnerBindingError) {
|
|
33135
|
+
return error;
|
|
33136
|
+
}
|
|
33137
|
+
const rpcError = error;
|
|
33138
|
+
const code = rpcError?.code;
|
|
33139
|
+
const message = typeof rpcError?.message === "string" && rpcError.message.length > 0 ? rpcError.message : "Account PS Lite owner-binding signature failed";
|
|
33140
|
+
return new AccountPersonalServerLiteOwnerBindingError({
|
|
33141
|
+
message,
|
|
33142
|
+
code,
|
|
33143
|
+
details: error
|
|
33144
|
+
});
|
|
33145
|
+
}
|
|
33146
|
+
|
|
33147
|
+
// src/protocol/grants.ts
|
|
33148
|
+
var import_viem17 = require("viem");
|
|
32709
33149
|
function isHexString(value) {
|
|
32710
33150
|
return typeof value === "string" && value.startsWith("0x");
|
|
32711
33151
|
}
|
|
@@ -32783,7 +33223,7 @@ async function verifyGrantRegistration(input) {
|
|
|
32783
33223
|
}
|
|
32784
33224
|
let valid;
|
|
32785
33225
|
try {
|
|
32786
|
-
valid = await (0,
|
|
33226
|
+
valid = await (0, import_viem17.verifyTypedData)({
|
|
32787
33227
|
address: input.grantorAddress,
|
|
32788
33228
|
domain: grantRegistrationDomain(input.gatewayConfig),
|
|
32789
33229
|
types: GRANT_REGISTRATION_TYPES,
|
|
@@ -33114,7 +33554,7 @@ var KNOWN_CODES = /* @__PURE__ */ new Set([
|
|
|
33114
33554
|
"server_not_configured",
|
|
33115
33555
|
"content_too_large"
|
|
33116
33556
|
]);
|
|
33117
|
-
function
|
|
33557
|
+
function isRecord2(value) {
|
|
33118
33558
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
33119
33559
|
}
|
|
33120
33560
|
function normalizeCode(value) {
|
|
@@ -33125,10 +33565,10 @@ function normalizeCode(value) {
|
|
|
33125
33565
|
return KNOWN_CODES.has(code) ? code : null;
|
|
33126
33566
|
}
|
|
33127
33567
|
function extractPSErrorBody(body) {
|
|
33128
|
-
if (!
|
|
33568
|
+
if (!isRecord2(body)) {
|
|
33129
33569
|
return null;
|
|
33130
33570
|
}
|
|
33131
|
-
const nested =
|
|
33571
|
+
const nested = isRecord2(body.error) ? body.error : null;
|
|
33132
33572
|
const code = normalizeCode(
|
|
33133
33573
|
nested?.errorCode ?? nested?.code ?? body.errorCode ?? body.code
|
|
33134
33574
|
);
|
|
@@ -33153,6 +33593,9 @@ async function parsePSError(response) {
|
|
|
33153
33593
|
}
|
|
33154
33594
|
// Annotate the CommonJS export names for ESM import in node:
|
|
33155
33595
|
0 && (module.exports = {
|
|
33596
|
+
ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
|
|
33597
|
+
AccountPersonalServerLiteOwnerBindingError,
|
|
33598
|
+
AccountPersonalServerRegistrationError,
|
|
33156
33599
|
BUILDER_REGISTRATION_TYPES,
|
|
33157
33600
|
BlockchainError,
|
|
33158
33601
|
BrowserPlatformAdapter,
|
|
@@ -33180,6 +33623,11 @@ async function parsePSError(response) {
|
|
|
33180
33623
|
NodePlatformAdapter,
|
|
33181
33624
|
NonceError,
|
|
33182
33625
|
OAuthClient,
|
|
33626
|
+
PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX,
|
|
33627
|
+
PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE,
|
|
33628
|
+
PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION,
|
|
33629
|
+
PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,
|
|
33630
|
+
PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT,
|
|
33183
33631
|
PKCE_CHALLENGE_PATTERN,
|
|
33184
33632
|
PKCE_VERIFIER_PATTERN,
|
|
33185
33633
|
PSError,
|
|
@@ -33201,6 +33649,10 @@ async function parsePSError(response) {
|
|
|
33201
33649
|
VanaError,
|
|
33202
33650
|
VanaStorage,
|
|
33203
33651
|
assertValidPkceVerifier,
|
|
33652
|
+
buildPersonalServerLiteOwnerBindingMessage,
|
|
33653
|
+
buildPersonalServerLiteOwnerBindingSignature,
|
|
33654
|
+
buildPersonalServerRegistrationSignature,
|
|
33655
|
+
buildPersonalServerRegistrationTypedData,
|
|
33204
33656
|
buildWeb3SignedHeader,
|
|
33205
33657
|
builderRegistrationDomain,
|
|
33206
33658
|
chains,
|
|
@@ -33216,6 +33668,8 @@ async function parsePSError(response) {
|
|
|
33216
33668
|
createPlatformAdapterFor,
|
|
33217
33669
|
createPlatformAdapterSafe,
|
|
33218
33670
|
createVanaStorageProvider,
|
|
33671
|
+
createViemPersonalServerLiteOwnerBindingSigner,
|
|
33672
|
+
createViemPersonalServerRegistrationSigner,
|
|
33219
33673
|
decryptWithPassword,
|
|
33220
33674
|
deriveMasterKey,
|
|
33221
33675
|
deriveScopeKey,
|
|
@@ -33245,12 +33699,17 @@ async function parsePSError(response) {
|
|
|
33245
33699
|
parsePSError,
|
|
33246
33700
|
parseScope,
|
|
33247
33701
|
parseWeb3SignedHeader,
|
|
33702
|
+
personalServerRegistrationDomain,
|
|
33248
33703
|
recoverServerOwner,
|
|
33704
|
+
registerPersonalServerSignature,
|
|
33249
33705
|
scopeCoveredByGrant,
|
|
33250
33706
|
scopeMatchesPattern,
|
|
33251
33707
|
scopeToPathSegments,
|
|
33252
33708
|
serializeECIES,
|
|
33253
33709
|
serverRegistrationDomain,
|
|
33710
|
+
signPersonalServerLiteOwnerBinding,
|
|
33711
|
+
signPersonalServerLiteOwnerBindingWithAccountClient,
|
|
33712
|
+
signPersonalServerRegistrationWithAccount,
|
|
33254
33713
|
vanaMainnet,
|
|
33255
33714
|
verifyGrantRegistration,
|
|
33256
33715
|
verifyPkceChallenge,
|