@opendatalabs/vana-sdk 3.1.0 → 3.2.0-canary.255a8bf
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 +9 -3
- package/dist/index.browser.js +768 -72
- package/dist/index.browser.js.map +4 -4
- package/dist/index.node.cjs +798 -73
- package/dist/index.node.cjs.map +4 -4
- package/dist/index.node.d.ts +9 -3
- package/dist/index.node.js +768 -72
- package/dist/index.node.js.map +4 -4
- package/dist/node.js +1 -1
- package/dist/platform/browser-only.js +1 -1
- package/dist/platform/browser-safe.js +1 -1
- package/dist/platform/browser.js +6 -6
- package/dist/platform/index.js +4 -4
- package/dist/platform/node.js +8 -8
- package/dist/platform/utils.js +2 -2
- package/dist/platform.browser.js +3 -3
- package/dist/platform.js +4 -4
- package/dist/platform.node.js +4 -4
- package/dist/protocol/eip712.cjs +58 -3
- package/dist/protocol/eip712.cjs.map +1 -1
- package/dist/protocol/eip712.d.ts +99 -7
- package/dist/protocol/eip712.js +52 -3
- package/dist/protocol/eip712.js.map +1 -1
- package/dist/protocol/escrow-deposit.cjs +89 -0
- package/dist/protocol/escrow-deposit.cjs.map +1 -0
- package/dist/protocol/escrow-deposit.d.ts +47 -0
- package/dist/protocol/escrow-deposit.js +60 -0
- package/dist/protocol/escrow-deposit.js.map +1 -0
- package/dist/protocol/escrow-deposit.test.d.ts +1 -0
- package/dist/protocol/escrow-flow.test.d.ts +21 -0
- package/dist/protocol/fee-registry.cjs +89 -0
- package/dist/protocol/fee-registry.cjs.map +1 -0
- package/dist/protocol/fee-registry.d.ts +105 -0
- package/dist/protocol/fee-registry.js +63 -0
- package/dist/protocol/fee-registry.js.map +1 -0
- package/dist/protocol/fee-registry.test.d.ts +1 -0
- package/dist/protocol/gateway.cjs +124 -3
- package/dist/protocol/gateway.cjs.map +1 -1
- package/dist/protocol/gateway.d.ts +196 -16
- package/dist/protocol/gateway.js +124 -3
- package/dist/protocol/gateway.js.map +1 -1
- package/dist/protocol/grants.cjs +24 -64
- package/dist/protocol/grants.cjs.map +1 -1
- package/dist/protocol/grants.d.ts +6 -13
- package/dist/protocol/grants.js +25 -64
- package/dist/protocol/grants.js.map +1 -1
- package/dist/protocol/personal-server-lite-owner-binding.cjs +93 -0
- package/dist/protocol/personal-server-lite-owner-binding.cjs.map +1 -0
- package/dist/protocol/personal-server-lite-owner-binding.d.ts +44 -0
- package/dist/protocol/personal-server-lite-owner-binding.js +65 -0
- package/dist/protocol/personal-server-lite-owner-binding.js.map +1 -0
- package/dist/protocol/personal-server-lite-owner-binding.test.d.ts +1 -0
- package/dist/protocol/personal-server-registration.cjs +122 -0
- package/dist/protocol/personal-server-registration.cjs.map +1 -0
- package/dist/protocol/personal-server-registration.d.ts +62 -0
- package/dist/protocol/personal-server-registration.js +97 -0
- package/dist/protocol/personal-server-registration.js.map +1 -0
- package/dist/protocol/personal-server-registration.test.d.ts +1 -0
- package/dist/storage/default.js +1 -1
- package/dist/storage/index.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 +6 -3
package/dist/index.node.js
CHANGED
|
@@ -32509,6 +32509,7 @@ function formatOAuthError(body, status) {
|
|
|
32509
32509
|
// src/protocol/eip712.ts
|
|
32510
32510
|
var DOMAIN_NAME = "Vana Data Portability";
|
|
32511
32511
|
var DOMAIN_VERSION = "1";
|
|
32512
|
+
var NATIVE_VANA_ASSET = "0x0000000000000000000000000000000000000000";
|
|
32512
32513
|
function buildDomain(chainId, verifyingContract) {
|
|
32513
32514
|
return {
|
|
32514
32515
|
name: DOMAIN_NAME,
|
|
@@ -32523,6 +32524,12 @@ function fileRegistrationDomain(config) {
|
|
|
32523
32524
|
config.contracts.dataRegistry
|
|
32524
32525
|
);
|
|
32525
32526
|
}
|
|
32527
|
+
function dataRegistryDomain(config) {
|
|
32528
|
+
return buildDomain(
|
|
32529
|
+
config.chainId,
|
|
32530
|
+
config.contracts.dataRegistry
|
|
32531
|
+
);
|
|
32532
|
+
}
|
|
32526
32533
|
function grantRegistrationDomain(config) {
|
|
32527
32534
|
return buildDomain(
|
|
32528
32535
|
config.chainId,
|
|
@@ -32547,6 +32554,12 @@ function builderRegistrationDomain(config) {
|
|
|
32547
32554
|
config.contracts.dataPortabilityGrantees
|
|
32548
32555
|
);
|
|
32549
32556
|
}
|
|
32557
|
+
function escrowPaymentDomain(config) {
|
|
32558
|
+
return buildDomain(
|
|
32559
|
+
config.chainId,
|
|
32560
|
+
config.contracts.dataPortabilityEscrow
|
|
32561
|
+
);
|
|
32562
|
+
}
|
|
32550
32563
|
var FILE_REGISTRATION_TYPES = {
|
|
32551
32564
|
FileRegistration: [
|
|
32552
32565
|
{ name: "ownerAddress", type: "address" },
|
|
@@ -32558,14 +32571,16 @@ var GRANT_REGISTRATION_TYPES = {
|
|
|
32558
32571
|
GrantRegistration: [
|
|
32559
32572
|
{ name: "grantorAddress", type: "address" },
|
|
32560
32573
|
{ name: "granteeId", type: "bytes32" },
|
|
32561
|
-
{ name: "
|
|
32562
|
-
{ name: "
|
|
32574
|
+
{ name: "scopes", type: "string[]" },
|
|
32575
|
+
{ name: "grantVersion", type: "uint256" },
|
|
32576
|
+
{ name: "expiresAt", type: "uint256" }
|
|
32563
32577
|
]
|
|
32564
32578
|
};
|
|
32565
32579
|
var GRANT_REVOCATION_TYPES = {
|
|
32566
32580
|
GrantRevocation: [
|
|
32567
32581
|
{ name: "grantorAddress", type: "address" },
|
|
32568
|
-
{ name: "grantId", type: "bytes32" }
|
|
32582
|
+
{ name: "grantId", type: "bytes32" },
|
|
32583
|
+
{ name: "grantVersion", type: "uint256" }
|
|
32569
32584
|
]
|
|
32570
32585
|
};
|
|
32571
32586
|
var SERVER_REGISTRATION_TYPES = {
|
|
@@ -32584,83 +32599,500 @@ var BUILDER_REGISTRATION_TYPES = {
|
|
|
32584
32599
|
{ name: "appUrl", type: "string" }
|
|
32585
32600
|
]
|
|
32586
32601
|
};
|
|
32602
|
+
var GENERIC_PAYMENT_TYPES = {
|
|
32603
|
+
GenericPayment: [
|
|
32604
|
+
{ name: "payerAddress", type: "address" },
|
|
32605
|
+
{ name: "opType", type: "string" },
|
|
32606
|
+
{ name: "opId", type: "bytes32" },
|
|
32607
|
+
{ name: "asset", type: "address" },
|
|
32608
|
+
{ name: "amount", type: "uint256" },
|
|
32609
|
+
{ name: "paymentNonce", type: "uint256" }
|
|
32610
|
+
]
|
|
32611
|
+
};
|
|
32612
|
+
var ADD_DATA_TYPES = {
|
|
32613
|
+
AddData: [
|
|
32614
|
+
{ name: "ownerAddress", type: "address" },
|
|
32615
|
+
{ name: "scope", type: "string" },
|
|
32616
|
+
{ name: "dataHash", type: "bytes32" },
|
|
32617
|
+
{ name: "metadataHash", type: "bytes32" },
|
|
32618
|
+
{ name: "expectedVersion", type: "uint256" }
|
|
32619
|
+
]
|
|
32620
|
+
};
|
|
32621
|
+
var RECORD_DATA_ACCESS_TYPES = {
|
|
32622
|
+
RecordDataAccess: [
|
|
32623
|
+
{ name: "ownerAddress", type: "address" },
|
|
32624
|
+
{ name: "scope", type: "string" },
|
|
32625
|
+
{ name: "version", type: "uint256" },
|
|
32626
|
+
{ name: "accessor", type: "address" },
|
|
32627
|
+
{ name: "recordId", type: "bytes32" }
|
|
32628
|
+
]
|
|
32629
|
+
};
|
|
32587
32630
|
|
|
32588
|
-
// src/protocol/
|
|
32589
|
-
import {
|
|
32590
|
-
|
|
32591
|
-
|
|
32631
|
+
// src/protocol/personal-server-registration.ts
|
|
32632
|
+
import {
|
|
32633
|
+
isAddress
|
|
32634
|
+
} from "viem";
|
|
32635
|
+
var PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID = 1480;
|
|
32636
|
+
var PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT = "0x1483B1F634DBA75AeaE60da7f01A679aabd5ee2c";
|
|
32637
|
+
function assertAddress(value, name) {
|
|
32638
|
+
if (!isAddress(value)) {
|
|
32639
|
+
throw new Error(`${name} must be a valid EVM address`);
|
|
32640
|
+
}
|
|
32592
32641
|
}
|
|
32593
|
-
function
|
|
32594
|
-
if (
|
|
32595
|
-
return
|
|
32642
|
+
function getAccountAddress(account) {
|
|
32643
|
+
if (!account) {
|
|
32644
|
+
return void 0;
|
|
32596
32645
|
}
|
|
32597
|
-
|
|
32598
|
-
|
|
32599
|
-
|
|
32600
|
-
|
|
32646
|
+
return typeof account === "string" ? account : account.address;
|
|
32647
|
+
}
|
|
32648
|
+
function isPersonalServerRegistrationSigner(source) {
|
|
32649
|
+
return "address" in source && typeof source.signTypedData === "function";
|
|
32650
|
+
}
|
|
32651
|
+
function createViemPersonalServerRegistrationSigner(source, options = {}) {
|
|
32652
|
+
if (isPersonalServerRegistrationSigner(source)) {
|
|
32653
|
+
return source;
|
|
32601
32654
|
}
|
|
32602
|
-
const
|
|
32603
|
-
|
|
32655
|
+
const accountAddress = getAccountAddress(options.account) ?? getAccountAddress(source.account);
|
|
32656
|
+
if (accountAddress) {
|
|
32657
|
+
return {
|
|
32658
|
+
address: accountAddress,
|
|
32659
|
+
signTypedData: (typedData) => source.signTypedData({
|
|
32660
|
+
...typedData,
|
|
32661
|
+
account: options.account ?? source.account ?? accountAddress
|
|
32662
|
+
})
|
|
32663
|
+
};
|
|
32664
|
+
}
|
|
32665
|
+
throw new Error(
|
|
32666
|
+
"Viem wallet client requires an account option or account property"
|
|
32667
|
+
);
|
|
32604
32668
|
}
|
|
32605
|
-
function
|
|
32606
|
-
|
|
32607
|
-
|
|
32608
|
-
parsed = JSON.parse(grant);
|
|
32609
|
-
} catch {
|
|
32610
|
-
return null;
|
|
32669
|
+
function personalServerRegistrationDomain(input = {}) {
|
|
32670
|
+
if (input.config) {
|
|
32671
|
+
return serverRegistrationDomain(input.config);
|
|
32611
32672
|
}
|
|
32612
|
-
|
|
32613
|
-
|
|
32673
|
+
const verifyingContract = input.verifyingContract ?? PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT;
|
|
32674
|
+
assertAddress(verifyingContract, "verifyingContract");
|
|
32675
|
+
return {
|
|
32676
|
+
name: "Vana Data Portability",
|
|
32677
|
+
version: "1",
|
|
32678
|
+
chainId: input.chainId ?? PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,
|
|
32679
|
+
verifyingContract
|
|
32680
|
+
};
|
|
32681
|
+
}
|
|
32682
|
+
function buildPersonalServerRegistrationTypedData(input) {
|
|
32683
|
+
assertAddress(input.ownerAddress, "ownerAddress");
|
|
32684
|
+
assertAddress(input.serverAddress, "serverAddress");
|
|
32685
|
+
return {
|
|
32686
|
+
domain: personalServerRegistrationDomain(input),
|
|
32687
|
+
types: SERVER_REGISTRATION_TYPES,
|
|
32688
|
+
primaryType: "ServerRegistration",
|
|
32689
|
+
message: {
|
|
32690
|
+
ownerAddress: input.ownerAddress,
|
|
32691
|
+
serverAddress: input.serverAddress,
|
|
32692
|
+
publicKey: input.serverPublicKey,
|
|
32693
|
+
serverUrl: input.serverUrl
|
|
32694
|
+
}
|
|
32695
|
+
};
|
|
32696
|
+
}
|
|
32697
|
+
async function buildPersonalServerRegistrationSignature(input) {
|
|
32698
|
+
const typedData = buildPersonalServerRegistrationTypedData({
|
|
32699
|
+
ownerAddress: input.signer.address,
|
|
32700
|
+
serverAddress: input.serverAddress,
|
|
32701
|
+
serverPublicKey: input.serverPublicKey,
|
|
32702
|
+
serverUrl: input.serverUrl,
|
|
32703
|
+
config: input.config,
|
|
32704
|
+
chainId: input.chainId,
|
|
32705
|
+
verifyingContract: input.verifyingContract
|
|
32706
|
+
});
|
|
32707
|
+
const signature = await input.signer.signTypedData(typedData);
|
|
32708
|
+
return {
|
|
32709
|
+
signature,
|
|
32710
|
+
signerAddress: input.signer.address,
|
|
32711
|
+
typedData
|
|
32712
|
+
};
|
|
32713
|
+
}
|
|
32714
|
+
var registerPersonalServerSignature = buildPersonalServerRegistrationSignature;
|
|
32715
|
+
|
|
32716
|
+
// src/protocol/personal-server-lite-owner-binding.ts
|
|
32717
|
+
import {
|
|
32718
|
+
isAddress as isAddress2
|
|
32719
|
+
} from "viem";
|
|
32720
|
+
var PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION = "vana.account.v1";
|
|
32721
|
+
var PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE = "ps-lite-owner";
|
|
32722
|
+
var PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX = `${PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION}:${PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE}:`;
|
|
32723
|
+
function assertAddress2(value, name) {
|
|
32724
|
+
if (!isAddress2(value)) {
|
|
32725
|
+
throw new Error(`${name} must be a valid EVM address`);
|
|
32614
32726
|
}
|
|
32615
|
-
|
|
32616
|
-
|
|
32617
|
-
|
|
32727
|
+
}
|
|
32728
|
+
function getAccountAddress2(account) {
|
|
32729
|
+
if (!account) {
|
|
32730
|
+
return void 0;
|
|
32618
32731
|
}
|
|
32619
|
-
|
|
32620
|
-
|
|
32732
|
+
return typeof account === "string" ? account : account.address;
|
|
32733
|
+
}
|
|
32734
|
+
function isPersonalServerLiteOwnerBindingSigner(source) {
|
|
32735
|
+
return "address" in source && typeof source.signMessage === "function";
|
|
32736
|
+
}
|
|
32737
|
+
function buildPersonalServerLiteOwnerBindingMessage(ownerAddress) {
|
|
32738
|
+
assertAddress2(ownerAddress, "ownerAddress");
|
|
32739
|
+
return `${PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX}${ownerAddress.toLowerCase()}`;
|
|
32740
|
+
}
|
|
32741
|
+
function createViemPersonalServerLiteOwnerBindingSigner(source, options = {}) {
|
|
32742
|
+
if (isPersonalServerLiteOwnerBindingSigner(source)) {
|
|
32743
|
+
return source;
|
|
32621
32744
|
}
|
|
32622
|
-
|
|
32623
|
-
|
|
32745
|
+
const accountAddress = getAccountAddress2(options.account) ?? getAccountAddress2(source.account);
|
|
32746
|
+
if (accountAddress) {
|
|
32747
|
+
return {
|
|
32748
|
+
address: accountAddress,
|
|
32749
|
+
signMessage: ({ message }) => source.signMessage({
|
|
32750
|
+
account: options.account ?? source.account ?? accountAddress,
|
|
32751
|
+
message
|
|
32752
|
+
})
|
|
32753
|
+
};
|
|
32624
32754
|
}
|
|
32625
|
-
|
|
32626
|
-
|
|
32755
|
+
throw new Error(
|
|
32756
|
+
"Viem wallet client requires an account option or account property"
|
|
32757
|
+
);
|
|
32758
|
+
}
|
|
32759
|
+
async function buildPersonalServerLiteOwnerBindingSignature(input) {
|
|
32760
|
+
const message = buildPersonalServerLiteOwnerBindingMessage(
|
|
32761
|
+
input.signer.address
|
|
32762
|
+
);
|
|
32763
|
+
const signature = await input.signer.signMessage({ message });
|
|
32764
|
+
return {
|
|
32765
|
+
signature,
|
|
32766
|
+
signerAddress: input.signer.address,
|
|
32767
|
+
message,
|
|
32768
|
+
purpose: PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE
|
|
32769
|
+
};
|
|
32770
|
+
}
|
|
32771
|
+
var signPersonalServerLiteOwnerBinding = buildPersonalServerLiteOwnerBindingSignature;
|
|
32772
|
+
|
|
32773
|
+
// src/account/personal-server-registration.ts
|
|
32774
|
+
import { isAddress as isAddress3 } from "viem";
|
|
32775
|
+
var ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT = "personal_server.server_registration.v1";
|
|
32776
|
+
var AccountPersonalServerRegistrationError = class extends Error {
|
|
32777
|
+
status;
|
|
32778
|
+
code;
|
|
32779
|
+
details;
|
|
32780
|
+
constructor(input) {
|
|
32781
|
+
super(input.message);
|
|
32782
|
+
this.name = "AccountPersonalServerRegistrationError";
|
|
32783
|
+
this.status = input.status;
|
|
32784
|
+
this.code = input.code;
|
|
32785
|
+
this.details = input.details;
|
|
32627
32786
|
}
|
|
32628
|
-
|
|
32629
|
-
|
|
32787
|
+
};
|
|
32788
|
+
var DEFAULT_ACCOUNT_PS_REGISTRATION_PATH = "/api/v1/intents/personal-server-registration/sign";
|
|
32789
|
+
function trimTrailingSlash(value) {
|
|
32790
|
+
return value.replace(/\/+$/, "");
|
|
32791
|
+
}
|
|
32792
|
+
function assertAddress3(value, name) {
|
|
32793
|
+
if (!isAddress3(value)) {
|
|
32794
|
+
throw new Error(`${name} must be a valid EVM address`);
|
|
32630
32795
|
}
|
|
32631
|
-
|
|
32632
|
-
|
|
32796
|
+
}
|
|
32797
|
+
async function parseAccountResponse(response) {
|
|
32798
|
+
const body = await response.json().catch(() => void 0);
|
|
32799
|
+
if (!response.ok) {
|
|
32800
|
+
throw new AccountPersonalServerRegistrationError({
|
|
32801
|
+
status: response.status,
|
|
32802
|
+
code: accountErrorCode(body),
|
|
32803
|
+
message: accountErrorMessage(response.status, body),
|
|
32804
|
+
details: body
|
|
32805
|
+
});
|
|
32806
|
+
}
|
|
32807
|
+
return body;
|
|
32808
|
+
}
|
|
32809
|
+
function accountErrorMessage(status, body) {
|
|
32810
|
+
const nestedMessage = nestedAccountErrorField(body, "message");
|
|
32811
|
+
if (nestedMessage) {
|
|
32812
|
+
return nestedMessage;
|
|
32813
|
+
}
|
|
32814
|
+
if (isRecord(body) && typeof body.message === "string") {
|
|
32815
|
+
return body.message;
|
|
32816
|
+
}
|
|
32817
|
+
const code = accountErrorCode(body);
|
|
32818
|
+
if (code) {
|
|
32819
|
+
return `Account PS registration signing failed: ${code}`;
|
|
32820
|
+
}
|
|
32821
|
+
return `Account PS registration signing failed: ${status}`;
|
|
32822
|
+
}
|
|
32823
|
+
function accountErrorCode(body) {
|
|
32824
|
+
const nestedCode = nestedAccountErrorField(body, "code");
|
|
32825
|
+
if (nestedCode) {
|
|
32826
|
+
return nestedCode;
|
|
32827
|
+
}
|
|
32828
|
+
if (isRecord(body)) {
|
|
32829
|
+
if (typeof body.code === "string") {
|
|
32830
|
+
return body.code;
|
|
32831
|
+
}
|
|
32832
|
+
if (typeof body.error === "string") {
|
|
32833
|
+
return body.error;
|
|
32834
|
+
}
|
|
32835
|
+
}
|
|
32836
|
+
return void 0;
|
|
32837
|
+
}
|
|
32838
|
+
function nestedAccountErrorField(body, field) {
|
|
32839
|
+
if (!isRecord(body) || !isRecord(body.error)) {
|
|
32840
|
+
return void 0;
|
|
32841
|
+
}
|
|
32842
|
+
const value = body.error[field];
|
|
32843
|
+
return typeof value === "string" ? value : void 0;
|
|
32844
|
+
}
|
|
32845
|
+
function isRecord(value) {
|
|
32846
|
+
return typeof value === "object" && value !== null;
|
|
32847
|
+
}
|
|
32848
|
+
function normalizeAccountResponse(response) {
|
|
32849
|
+
return {
|
|
32850
|
+
...response,
|
|
32851
|
+
status: response.status === "fallback_required" ? "confirmation_required" : response.status,
|
|
32852
|
+
signerAddress: response.signerAddress ?? response.signer?.address,
|
|
32853
|
+
typedData: response.typedData ?? response.typed_data
|
|
32854
|
+
};
|
|
32855
|
+
}
|
|
32856
|
+
function buildSignedResult(response, request) {
|
|
32857
|
+
assertAddress3(response.signerAddress, "signerAddress");
|
|
32858
|
+
if (response.typedData) {
|
|
32859
|
+
assertTypedDataMatchesRequest(
|
|
32860
|
+
response.typedData,
|
|
32861
|
+
request,
|
|
32862
|
+
response.signerAddress
|
|
32863
|
+
);
|
|
32633
32864
|
}
|
|
32634
32865
|
return {
|
|
32635
|
-
|
|
32636
|
-
|
|
32637
|
-
|
|
32638
|
-
|
|
32639
|
-
|
|
32866
|
+
signature: response.signature,
|
|
32867
|
+
signerAddress: response.signerAddress,
|
|
32868
|
+
typedData: response.typedData ?? buildPersonalServerRegistrationTypedData({
|
|
32869
|
+
ownerAddress: response.signerAddress,
|
|
32870
|
+
...request
|
|
32871
|
+
}),
|
|
32872
|
+
intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT
|
|
32640
32873
|
};
|
|
32641
32874
|
}
|
|
32642
|
-
function
|
|
32643
|
-
|
|
32644
|
-
|
|
32875
|
+
function assertTypedDataMatchesRequest(typedData, request, expectedSignerAddress) {
|
|
32876
|
+
assertAddress3(
|
|
32877
|
+
typedData.message.ownerAddress,
|
|
32878
|
+
"typedData.message.ownerAddress"
|
|
32879
|
+
);
|
|
32880
|
+
assertAddress3(
|
|
32881
|
+
typedData.message.serverAddress,
|
|
32882
|
+
"typedData.message.serverAddress"
|
|
32883
|
+
);
|
|
32884
|
+
if (expectedSignerAddress && !sameAddress(typedData.message.ownerAddress, expectedSignerAddress)) {
|
|
32885
|
+
throw new Error(
|
|
32886
|
+
"Account typedData ownerAddress must match the expected signer address"
|
|
32887
|
+
);
|
|
32888
|
+
}
|
|
32889
|
+
if (!sameAddress(typedData.message.serverAddress, request.serverAddress)) {
|
|
32890
|
+
throw new Error(
|
|
32891
|
+
"Account typedData serverAddress must match the requested serverAddress"
|
|
32892
|
+
);
|
|
32893
|
+
}
|
|
32894
|
+
if (typedData.message.publicKey !== request.serverPublicKey) {
|
|
32895
|
+
throw new Error(
|
|
32896
|
+
"Account typedData publicKey must match the requested serverPublicKey"
|
|
32897
|
+
);
|
|
32898
|
+
}
|
|
32899
|
+
if (typedData.message.serverUrl !== request.serverUrl) {
|
|
32900
|
+
throw new Error(
|
|
32901
|
+
"Account typedData serverUrl must match the requested serverUrl"
|
|
32902
|
+
);
|
|
32903
|
+
}
|
|
32904
|
+
if (typedData.primaryType !== "ServerRegistration") {
|
|
32905
|
+
throw new Error("Account typedData primaryType must be ServerRegistration");
|
|
32906
|
+
}
|
|
32907
|
+
if (JSON.stringify(typedData.types) !== JSON.stringify(SERVER_REGISTRATION_TYPES)) {
|
|
32908
|
+
throw new Error("Account typedData types must be ServerRegistration types");
|
|
32909
|
+
}
|
|
32910
|
+
const expectedDomain = personalServerRegistrationDomain({
|
|
32911
|
+
config: request.config,
|
|
32912
|
+
chainId: request.chainId,
|
|
32913
|
+
verifyingContract: request.verifyingContract
|
|
32914
|
+
});
|
|
32915
|
+
if (!domainsEqual(typedData.domain, expectedDomain)) {
|
|
32916
|
+
throw new Error("Account typedData domain must match the requested domain");
|
|
32917
|
+
}
|
|
32918
|
+
}
|
|
32919
|
+
function sameAddress(a, b) {
|
|
32920
|
+
return a.toLowerCase() === b.toLowerCase();
|
|
32921
|
+
}
|
|
32922
|
+
function domainsEqual(a, b) {
|
|
32923
|
+
if (!a || !b) {
|
|
32924
|
+
return false;
|
|
32925
|
+
}
|
|
32926
|
+
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;
|
|
32927
|
+
}
|
|
32928
|
+
async function signPersonalServerRegistrationWithAccount(config, request) {
|
|
32929
|
+
assertAddress3(request.serverAddress, "serverAddress");
|
|
32930
|
+
const fetchImpl = config.fetchImpl ?? globalThis.fetch.bind(globalThis);
|
|
32931
|
+
const endpoint = new URL(
|
|
32932
|
+
config.endpointPath ?? DEFAULT_ACCOUNT_PS_REGISTRATION_PATH,
|
|
32933
|
+
`${trimTrailingSlash(config.accountOrigin)}/`
|
|
32934
|
+
);
|
|
32935
|
+
const response = await fetchImpl(endpoint, {
|
|
32936
|
+
method: "POST",
|
|
32937
|
+
headers: { "content-type": "application/json" },
|
|
32938
|
+
credentials: "include",
|
|
32939
|
+
body: JSON.stringify({
|
|
32940
|
+
intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
|
|
32941
|
+
serverAddress: request.serverAddress,
|
|
32942
|
+
serverPublicKey: request.serverPublicKey,
|
|
32943
|
+
serverUrl: request.serverUrl,
|
|
32944
|
+
config: request.config,
|
|
32945
|
+
chainId: request.chainId,
|
|
32946
|
+
verifyingContract: request.verifyingContract
|
|
32947
|
+
})
|
|
32948
|
+
});
|
|
32949
|
+
const body = normalizeAccountResponse(await parseAccountResponse(response));
|
|
32950
|
+
if (body.status === "signed") {
|
|
32951
|
+
if (!body.signature || !body.signerAddress) {
|
|
32952
|
+
throw new Error(
|
|
32953
|
+
"Account signed response must include signature and signerAddress"
|
|
32954
|
+
);
|
|
32955
|
+
}
|
|
32645
32956
|
return {
|
|
32646
|
-
|
|
32647
|
-
|
|
32957
|
+
status: "signed",
|
|
32958
|
+
result: buildSignedResult(
|
|
32959
|
+
{
|
|
32960
|
+
signature: body.signature,
|
|
32961
|
+
signerAddress: body.signerAddress,
|
|
32962
|
+
typedData: body.typedData
|
|
32963
|
+
},
|
|
32964
|
+
request
|
|
32965
|
+
)
|
|
32648
32966
|
};
|
|
32967
|
+
}
|
|
32968
|
+
if (body.status === "confirmation_required") {
|
|
32969
|
+
if (!body.typedData) {
|
|
32970
|
+
throw new Error(
|
|
32971
|
+
"Account confirmation_required response must include typedData"
|
|
32972
|
+
);
|
|
32973
|
+
}
|
|
32974
|
+
assertTypedDataMatchesRequest(body.typedData, request, body.signerAddress);
|
|
32975
|
+
if (!config.fallbackSigner) {
|
|
32976
|
+
return {
|
|
32977
|
+
status: "confirmation_required",
|
|
32978
|
+
typedData: body.typedData,
|
|
32979
|
+
signerAddress: body.signerAddress
|
|
32980
|
+
};
|
|
32981
|
+
}
|
|
32982
|
+
assertTypedDataMatchesRequest(
|
|
32983
|
+
body.typedData,
|
|
32984
|
+
request,
|
|
32985
|
+
config.fallbackSigner.address
|
|
32986
|
+
);
|
|
32987
|
+
const signature = await config.fallbackSigner.signTypedData(body.typedData);
|
|
32988
|
+
return {
|
|
32989
|
+
status: "fallback_signed",
|
|
32990
|
+
accountStatus: "confirmation_required",
|
|
32991
|
+
result: {
|
|
32992
|
+
signature,
|
|
32993
|
+
signerAddress: config.fallbackSigner.address,
|
|
32994
|
+
typedData: body.typedData,
|
|
32995
|
+
intent: ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT
|
|
32996
|
+
}
|
|
32997
|
+
};
|
|
32998
|
+
}
|
|
32999
|
+
throw new Error(
|
|
33000
|
+
`Unsupported Account PS registration signing status: ${String(body.status)}`
|
|
33001
|
+
);
|
|
33002
|
+
}
|
|
33003
|
+
|
|
33004
|
+
// src/account/personal-server-lite-owner-binding.ts
|
|
33005
|
+
var AccountPersonalServerLiteOwnerBindingError = class extends Error {
|
|
33006
|
+
code;
|
|
33007
|
+
details;
|
|
33008
|
+
constructor(input) {
|
|
33009
|
+
super(input.message);
|
|
33010
|
+
this.name = "AccountPersonalServerLiteOwnerBindingError";
|
|
33011
|
+
this.code = input.code;
|
|
33012
|
+
this.details = input.details;
|
|
33013
|
+
}
|
|
33014
|
+
};
|
|
33015
|
+
async function signPersonalServerLiteOwnerBindingWithAccountClient(config) {
|
|
33016
|
+
let address;
|
|
33017
|
+
try {
|
|
33018
|
+
address = await config.client.getAddress();
|
|
33019
|
+
} catch (error) {
|
|
33020
|
+
throw accountOwnerBindingError(error);
|
|
33021
|
+
}
|
|
33022
|
+
if (!address) {
|
|
33023
|
+
throw new AccountPersonalServerLiteOwnerBindingError({
|
|
33024
|
+
message: "Account did not return a wallet address",
|
|
33025
|
+
code: "account_address_required"
|
|
33026
|
+
});
|
|
33027
|
+
}
|
|
33028
|
+
const message = buildPersonalServerLiteOwnerBindingMessage(address);
|
|
33029
|
+
let signature;
|
|
33030
|
+
try {
|
|
33031
|
+
signature = await config.client.signMessage({ message });
|
|
33032
|
+
} catch (error) {
|
|
33033
|
+
throw accountOwnerBindingError(error);
|
|
33034
|
+
}
|
|
33035
|
+
return {
|
|
33036
|
+
signature,
|
|
33037
|
+
signerAddress: address,
|
|
33038
|
+
message,
|
|
33039
|
+
purpose: PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE
|
|
33040
|
+
};
|
|
33041
|
+
}
|
|
33042
|
+
function accountOwnerBindingError(error) {
|
|
33043
|
+
if (error instanceof AccountPersonalServerLiteOwnerBindingError) {
|
|
33044
|
+
return error;
|
|
33045
|
+
}
|
|
33046
|
+
const rpcError = error;
|
|
33047
|
+
const code = rpcError?.code;
|
|
33048
|
+
const message = typeof rpcError?.message === "string" && rpcError.message.length > 0 ? rpcError.message : "Account PS Lite owner-binding signature failed";
|
|
33049
|
+
return new AccountPersonalServerLiteOwnerBindingError({
|
|
33050
|
+
message,
|
|
33051
|
+
code,
|
|
33052
|
+
details: error
|
|
33053
|
+
});
|
|
33054
|
+
}
|
|
33055
|
+
|
|
33056
|
+
// src/protocol/grants.ts
|
|
33057
|
+
import { verifyTypedData } from "viem";
|
|
33058
|
+
function isHexString(value) {
|
|
33059
|
+
return typeof value === "string" && value.startsWith("0x");
|
|
33060
|
+
}
|
|
33061
|
+
function isDataPortabilityGatewayConfig(value) {
|
|
33062
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
33063
|
+
return false;
|
|
33064
|
+
}
|
|
33065
|
+
const config = value;
|
|
33066
|
+
const contracts = config["contracts"];
|
|
33067
|
+
if (typeof config["chainId"] !== "number" || !Number.isInteger(config["chainId"]) || config["chainId"] <= 0 || contracts === null || typeof contracts !== "object" || Array.isArray(contracts)) {
|
|
33068
|
+
return false;
|
|
33069
|
+
}
|
|
33070
|
+
const c = contracts;
|
|
33071
|
+
return isHexString(c["dataRegistry"]) && isHexString(c["dataPortabilityPermissions"]) && isHexString(c["dataPortabilityServer"]) && isHexString(c["dataPortabilityGrantees"]) && isHexString(c["dataPortabilityEscrow"]) && isHexString(c["feeRegistry"]);
|
|
33072
|
+
}
|
|
33073
|
+
function toUint256(value) {
|
|
33074
|
+
try {
|
|
33075
|
+
const big = typeof value === "bigint" ? value : BigInt(value);
|
|
33076
|
+
if (big < 0n) return null;
|
|
33077
|
+
return big;
|
|
32649
33078
|
} catch {
|
|
32650
33079
|
return null;
|
|
32651
33080
|
}
|
|
32652
33081
|
}
|
|
32653
33082
|
async function verifyGrantRegistration(input) {
|
|
32654
|
-
|
|
32655
|
-
|
|
32656
|
-
return {
|
|
32657
|
-
valid: false,
|
|
32658
|
-
error: "Grant must be JSON with scopes and expiresAt"
|
|
32659
|
-
};
|
|
33083
|
+
if (!Array.isArray(input.scopes) || input.scopes.length === 0) {
|
|
33084
|
+
return { valid: false, error: "scopes must be a non-empty array" };
|
|
32660
33085
|
}
|
|
32661
|
-
|
|
32662
|
-
|
|
32663
|
-
|
|
33086
|
+
if (!input.scopes.every((scope) => typeof scope === "string")) {
|
|
33087
|
+
return { valid: false, error: "scopes must contain only strings" };
|
|
33088
|
+
}
|
|
33089
|
+
const grantVersion = toUint256(input.grantVersion);
|
|
33090
|
+
if (grantVersion === null || grantVersion < 1n) {
|
|
33091
|
+
return { valid: false, error: "grantVersion must be a uint256 >= 1" };
|
|
33092
|
+
}
|
|
33093
|
+
const expiresAt = toUint256(input.expiresAt);
|
|
33094
|
+
if (expiresAt === null) {
|
|
33095
|
+
return { valid: false, error: "expiresAt must be a non-negative uint256" };
|
|
32664
33096
|
}
|
|
32665
33097
|
let valid;
|
|
32666
33098
|
try {
|
|
@@ -32672,8 +33104,9 @@ async function verifyGrantRegistration(input) {
|
|
|
32672
33104
|
message: {
|
|
32673
33105
|
grantorAddress: input.grantorAddress,
|
|
32674
33106
|
granteeId: input.granteeId,
|
|
32675
|
-
|
|
32676
|
-
|
|
33107
|
+
scopes: input.scopes,
|
|
33108
|
+
grantVersion,
|
|
33109
|
+
expiresAt
|
|
32677
33110
|
},
|
|
32678
33111
|
signature: input.signature
|
|
32679
33112
|
});
|
|
@@ -32684,19 +33117,128 @@ async function verifyGrantRegistration(input) {
|
|
|
32684
33117
|
return { valid: false, error: "Grant signature does not match grantor" };
|
|
32685
33118
|
}
|
|
32686
33119
|
const nowSeconds = input.nowSeconds ?? Math.floor(Date.now() / 1e3);
|
|
32687
|
-
if (
|
|
33120
|
+
if (expiresAt > 0n && expiresAt < BigInt(nowSeconds)) {
|
|
32688
33121
|
return { valid: false, error: "Grant has expired" };
|
|
32689
33122
|
}
|
|
32690
|
-
if (payload.user !== void 0 && payload.user.toLowerCase() !== input.grantorAddress.toLowerCase()) {
|
|
32691
|
-
return { valid: false, error: "Grant user does not match grantorAddress" };
|
|
32692
|
-
}
|
|
32693
33123
|
return {
|
|
32694
33124
|
valid: true,
|
|
32695
33125
|
grantorAddress: input.grantorAddress,
|
|
32696
33126
|
granteeId: input.granteeId,
|
|
32697
|
-
|
|
32698
|
-
|
|
32699
|
-
|
|
33127
|
+
scopes: input.scopes,
|
|
33128
|
+
grantVersion: grantVersion.toString(),
|
|
33129
|
+
expiresAt: expiresAt.toString()
|
|
33130
|
+
};
|
|
33131
|
+
}
|
|
33132
|
+
|
|
33133
|
+
// src/protocol/escrow-deposit.ts
|
|
33134
|
+
import { encodeFunctionData } from "viem";
|
|
33135
|
+
var ESCROW_DEPOSIT_ABI = [
|
|
33136
|
+
{
|
|
33137
|
+
type: "function",
|
|
33138
|
+
name: "depositNative",
|
|
33139
|
+
stateMutability: "payable",
|
|
33140
|
+
inputs: [{ name: "account", type: "address" }],
|
|
33141
|
+
outputs: []
|
|
33142
|
+
},
|
|
33143
|
+
{
|
|
33144
|
+
type: "function",
|
|
33145
|
+
name: "depositToken",
|
|
33146
|
+
stateMutability: "nonpayable",
|
|
33147
|
+
inputs: [
|
|
33148
|
+
{ name: "account", type: "address" },
|
|
33149
|
+
{ name: "token", type: "address" },
|
|
33150
|
+
{ name: "amount", type: "uint256" }
|
|
33151
|
+
],
|
|
33152
|
+
outputs: []
|
|
33153
|
+
}
|
|
33154
|
+
];
|
|
33155
|
+
function escrowContractAddress(config) {
|
|
33156
|
+
return config.contracts.dataPortabilityEscrow;
|
|
33157
|
+
}
|
|
33158
|
+
function encodeDepositNativeData(input) {
|
|
33159
|
+
return encodeFunctionData({
|
|
33160
|
+
abi: ESCROW_DEPOSIT_ABI,
|
|
33161
|
+
functionName: "depositNative",
|
|
33162
|
+
args: [input.account]
|
|
33163
|
+
});
|
|
33164
|
+
}
|
|
33165
|
+
function encodeDepositTokenData(input) {
|
|
33166
|
+
return encodeFunctionData({
|
|
33167
|
+
abi: ESCROW_DEPOSIT_ABI,
|
|
33168
|
+
functionName: "depositToken",
|
|
33169
|
+
args: [input.account, input.token, input.amount]
|
|
33170
|
+
});
|
|
33171
|
+
}
|
|
33172
|
+
function buildDepositNativeRequest(config, input) {
|
|
33173
|
+
return {
|
|
33174
|
+
to: escrowContractAddress(config),
|
|
33175
|
+
data: encodeDepositNativeData({ account: input.account }),
|
|
33176
|
+
value: input.amount
|
|
33177
|
+
};
|
|
33178
|
+
}
|
|
33179
|
+
function buildDepositTokenRequest(config, input) {
|
|
33180
|
+
return {
|
|
33181
|
+
to: escrowContractAddress(config),
|
|
33182
|
+
data: encodeDepositTokenData(input)
|
|
33183
|
+
};
|
|
33184
|
+
}
|
|
33185
|
+
|
|
33186
|
+
// src/protocol/fee-registry.ts
|
|
33187
|
+
import { parseAbi } from "viem";
|
|
33188
|
+
var FEE_REGISTRY_ABI = parseAbi([
|
|
33189
|
+
"struct Fee { uint256 amount; address asset; address payee; bool enabled; }",
|
|
33190
|
+
"function fees(bytes32 operation) view returns (Fee)",
|
|
33191
|
+
"function operationKey(string name) pure returns (bytes32)"
|
|
33192
|
+
]);
|
|
33193
|
+
function operationNameFor(kind, opts) {
|
|
33194
|
+
if (kind === "registration") {
|
|
33195
|
+
return opts?.registrationOpName ?? "registration";
|
|
33196
|
+
}
|
|
33197
|
+
return opts?.dataAccessOpName ?? "data_access";
|
|
33198
|
+
}
|
|
33199
|
+
async function getFee(client, config, kind, opts) {
|
|
33200
|
+
const address = config.contracts.feeRegistry;
|
|
33201
|
+
const opName = operationNameFor(kind, opts);
|
|
33202
|
+
const opKey = await client.readContract({
|
|
33203
|
+
address,
|
|
33204
|
+
abi: FEE_REGISTRY_ABI,
|
|
33205
|
+
functionName: "operationKey",
|
|
33206
|
+
args: [opName]
|
|
33207
|
+
});
|
|
33208
|
+
const fee = await client.readContract({
|
|
33209
|
+
address,
|
|
33210
|
+
abi: FEE_REGISTRY_ABI,
|
|
33211
|
+
functionName: "fees",
|
|
33212
|
+
args: [opKey]
|
|
33213
|
+
});
|
|
33214
|
+
if (!fee.enabled) {
|
|
33215
|
+
throw new Error(
|
|
33216
|
+
`FeeRegistry: operation "${opName}" (kind=${kind}) is not enabled \u2014 operator must call setFeeByName before payments will validate`
|
|
33217
|
+
);
|
|
33218
|
+
}
|
|
33219
|
+
if (fee.payee === "0x0000000000000000000000000000000000000000") {
|
|
33220
|
+
throw new Error(
|
|
33221
|
+
`FeeRegistry: operation "${opName}" has zero-address payee \u2014 contract pre-flight rejects payouts to 0x0`
|
|
33222
|
+
);
|
|
33223
|
+
}
|
|
33224
|
+
return fee;
|
|
33225
|
+
}
|
|
33226
|
+
async function getOpFee(client, config, opts) {
|
|
33227
|
+
const [registration, dataAccess] = await Promise.all([
|
|
33228
|
+
getFee(client, config, "registration", opts),
|
|
33229
|
+
getFee(client, config, "data_access", opts)
|
|
33230
|
+
]);
|
|
33231
|
+
if (registration.asset.toLowerCase() !== dataAccess.asset.toLowerCase()) {
|
|
33232
|
+
throw new Error(
|
|
33233
|
+
`FeeRegistry asset mismatch: registration=${registration.asset} vs data_access=${dataAccess.asset}. The gateway requires both fees to settle in the same asset.`
|
|
33234
|
+
);
|
|
33235
|
+
}
|
|
33236
|
+
return {
|
|
33237
|
+
asset: registration.asset,
|
|
33238
|
+
registrationFee: registration.amount,
|
|
33239
|
+
dataAccessFee: dataAccess.amount,
|
|
33240
|
+
registrationPayee: registration.payee,
|
|
33241
|
+
dataAccessPayee: dataAccess.payee
|
|
32700
33242
|
};
|
|
32701
33243
|
}
|
|
32702
33244
|
|
|
@@ -32896,6 +33438,68 @@ function createGatewayClient(baseUrl) {
|
|
|
32896
33438
|
alreadyRegistered: false
|
|
32897
33439
|
};
|
|
32898
33440
|
},
|
|
33441
|
+
async registerBuilder(params) {
|
|
33442
|
+
const res = await fetch(`${base}/v1/builders`, {
|
|
33443
|
+
method: "POST",
|
|
33444
|
+
headers: {
|
|
33445
|
+
"Content-Type": "application/json",
|
|
33446
|
+
Authorization: `Web3Signed ${params.signature}`
|
|
33447
|
+
},
|
|
33448
|
+
body: JSON.stringify({
|
|
33449
|
+
ownerAddress: params.ownerAddress,
|
|
33450
|
+
granteeAddress: params.granteeAddress,
|
|
33451
|
+
publicKey: params.publicKey,
|
|
33452
|
+
appUrl: params.appUrl
|
|
33453
|
+
})
|
|
33454
|
+
});
|
|
33455
|
+
if (res.status === 409) {
|
|
33456
|
+
const body2 = await res.json().catch(() => ({}));
|
|
33457
|
+
return {
|
|
33458
|
+
builderId: getMutationId(
|
|
33459
|
+
body2,
|
|
33460
|
+
"builderId"
|
|
33461
|
+
),
|
|
33462
|
+
alreadyRegistered: true
|
|
33463
|
+
};
|
|
33464
|
+
}
|
|
33465
|
+
if (!res.ok) {
|
|
33466
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33467
|
+
}
|
|
33468
|
+
const body = await res.json().catch(() => ({}));
|
|
33469
|
+
return {
|
|
33470
|
+
builderId: getMutationId(body, "builderId"),
|
|
33471
|
+
alreadyRegistered: false
|
|
33472
|
+
};
|
|
33473
|
+
},
|
|
33474
|
+
async registerDataPoint(params) {
|
|
33475
|
+
const res = await fetch(`${base}/v1/data`, {
|
|
33476
|
+
method: "POST",
|
|
33477
|
+
headers: {
|
|
33478
|
+
"Content-Type": "application/json",
|
|
33479
|
+
Authorization: `Web3Signed ${params.signature}`
|
|
33480
|
+
},
|
|
33481
|
+
body: JSON.stringify({
|
|
33482
|
+
ownerAddress: params.ownerAddress,
|
|
33483
|
+
scope: params.scope,
|
|
33484
|
+
dataHash: params.dataHash,
|
|
33485
|
+
metadataHash: params.metadataHash,
|
|
33486
|
+
expectedVersion: params.expectedVersion
|
|
33487
|
+
})
|
|
33488
|
+
});
|
|
33489
|
+
if (!res.ok) {
|
|
33490
|
+
const body2 = await res.json().catch(() => ({}));
|
|
33491
|
+
const detail = body2.error ?? res.statusText;
|
|
33492
|
+
throw new Error(`Gateway error: ${res.status} ${detail}`);
|
|
33493
|
+
}
|
|
33494
|
+
const body = await res.json().catch(() => ({}));
|
|
33495
|
+
return {
|
|
33496
|
+
dataPointId: getMutationId(
|
|
33497
|
+
body,
|
|
33498
|
+
"dataPointId"
|
|
33499
|
+
),
|
|
33500
|
+
expectedVersion: body.expectedVersion
|
|
33501
|
+
};
|
|
33502
|
+
},
|
|
32899
33503
|
async registerFile(params) {
|
|
32900
33504
|
const res = await fetch(`${base}/v1/files`, {
|
|
32901
33505
|
method: "POST",
|
|
@@ -32933,8 +33537,9 @@ function createGatewayClient(baseUrl) {
|
|
|
32933
33537
|
body: JSON.stringify({
|
|
32934
33538
|
grantorAddress: params.grantorAddress,
|
|
32935
33539
|
granteeId: params.granteeId,
|
|
32936
|
-
|
|
32937
|
-
|
|
33540
|
+
scopes: params.scopes,
|
|
33541
|
+
grantVersion: params.grantVersion,
|
|
33542
|
+
expiresAt: params.expiresAt
|
|
32938
33543
|
})
|
|
32939
33544
|
});
|
|
32940
33545
|
if (res.status === 409) {
|
|
@@ -32959,13 +33564,71 @@ function createGatewayClient(baseUrl) {
|
|
|
32959
33564
|
Authorization: `Web3Signed ${params.signature}`
|
|
32960
33565
|
},
|
|
32961
33566
|
body: JSON.stringify({
|
|
32962
|
-
grantorAddress: params.grantorAddress
|
|
33567
|
+
grantorAddress: params.grantorAddress,
|
|
33568
|
+
grantVersion: params.grantVersion
|
|
32963
33569
|
})
|
|
32964
33570
|
});
|
|
32965
33571
|
if (res.status === 409) return;
|
|
32966
33572
|
if (!res.ok) {
|
|
32967
33573
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
32968
33574
|
}
|
|
33575
|
+
},
|
|
33576
|
+
async getEscrowBalance(account) {
|
|
33577
|
+
const res = await fetch(`${base}/v1/escrow/balance?account=${account}`);
|
|
33578
|
+
if (!res.ok) {
|
|
33579
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33580
|
+
}
|
|
33581
|
+
return await res.json();
|
|
33582
|
+
},
|
|
33583
|
+
async submitEscrowDeposit(params) {
|
|
33584
|
+
const res = await fetch(`${base}/v1/escrow/deposit`, {
|
|
33585
|
+
method: "POST",
|
|
33586
|
+
headers: { "Content-Type": "application/json" },
|
|
33587
|
+
body: JSON.stringify({ txHash: params.txHash })
|
|
33588
|
+
});
|
|
33589
|
+
if (res.status !== 200 && res.status !== 202) {
|
|
33590
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33591
|
+
}
|
|
33592
|
+
return await res.json();
|
|
33593
|
+
},
|
|
33594
|
+
async payForOperation(params) {
|
|
33595
|
+
const body = {
|
|
33596
|
+
payerAddress: params.payerAddress,
|
|
33597
|
+
opType: params.opType,
|
|
33598
|
+
opId: params.opId,
|
|
33599
|
+
asset: params.asset,
|
|
33600
|
+
amount: params.amount,
|
|
33601
|
+
paymentNonce: params.paymentNonce
|
|
33602
|
+
};
|
|
33603
|
+
if (params.accessRecord) {
|
|
33604
|
+
body["accessRecord"] = params.accessRecord;
|
|
33605
|
+
}
|
|
33606
|
+
const res = await fetch(`${base}/v1/escrow/pay`, {
|
|
33607
|
+
method: "POST",
|
|
33608
|
+
headers: {
|
|
33609
|
+
"Content-Type": "application/json",
|
|
33610
|
+
Authorization: `Web3Signed ${params.signature}`
|
|
33611
|
+
},
|
|
33612
|
+
body: JSON.stringify(body)
|
|
33613
|
+
});
|
|
33614
|
+
if (!res.ok) {
|
|
33615
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33616
|
+
}
|
|
33617
|
+
return await res.json();
|
|
33618
|
+
},
|
|
33619
|
+
async settle(params) {
|
|
33620
|
+
const res = await fetch(`${base}/v1/settle`, {
|
|
33621
|
+
method: "POST",
|
|
33622
|
+
headers: { "Content-Type": "application/json" },
|
|
33623
|
+
// The gateway accepts an empty body; only `limit` is recognised.
|
|
33624
|
+
// Always send a JSON body so the gateway's req.body shape parse
|
|
33625
|
+
// doesn't have to deal with an undefined.
|
|
33626
|
+
body: JSON.stringify(params ?? {})
|
|
33627
|
+
});
|
|
33628
|
+
if (!res.ok) {
|
|
33629
|
+
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33630
|
+
}
|
|
33631
|
+
return await res.json();
|
|
32969
33632
|
}
|
|
32970
33633
|
};
|
|
32971
33634
|
}
|
|
@@ -32995,7 +33658,7 @@ var KNOWN_CODES = /* @__PURE__ */ new Set([
|
|
|
32995
33658
|
"server_not_configured",
|
|
32996
33659
|
"content_too_large"
|
|
32997
33660
|
]);
|
|
32998
|
-
function
|
|
33661
|
+
function isRecord2(value) {
|
|
32999
33662
|
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
33000
33663
|
}
|
|
33001
33664
|
function normalizeCode(value) {
|
|
@@ -33006,10 +33669,10 @@ function normalizeCode(value) {
|
|
|
33006
33669
|
return KNOWN_CODES.has(code) ? code : null;
|
|
33007
33670
|
}
|
|
33008
33671
|
function extractPSErrorBody(body) {
|
|
33009
|
-
if (!
|
|
33672
|
+
if (!isRecord2(body)) {
|
|
33010
33673
|
return null;
|
|
33011
33674
|
}
|
|
33012
|
-
const nested =
|
|
33675
|
+
const nested = isRecord2(body.error) ? body.error : null;
|
|
33013
33676
|
const code = normalizeCode(
|
|
33014
33677
|
nested?.errorCode ?? nested?.code ?? body.errorCode ?? body.code
|
|
33015
33678
|
);
|
|
@@ -33033,6 +33696,10 @@ async function parsePSError(response) {
|
|
|
33033
33696
|
return errorBody ? new PSError(errorBody.code, errorBody.message) : null;
|
|
33034
33697
|
}
|
|
33035
33698
|
export {
|
|
33699
|
+
ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT,
|
|
33700
|
+
ADD_DATA_TYPES,
|
|
33701
|
+
AccountPersonalServerLiteOwnerBindingError,
|
|
33702
|
+
AccountPersonalServerRegistrationError,
|
|
33036
33703
|
BUILDER_REGISTRATION_TYPES,
|
|
33037
33704
|
BlockchainError,
|
|
33038
33705
|
BrowserPlatformAdapter,
|
|
@@ -33043,8 +33710,11 @@ export {
|
|
|
33043
33710
|
DataFileEnvelopeSchema,
|
|
33044
33711
|
DropboxStorage,
|
|
33045
33712
|
ECIESError,
|
|
33713
|
+
ESCROW_DEPOSIT_ABI,
|
|
33046
33714
|
ExpiredTokenError,
|
|
33715
|
+
FEE_REGISTRY_ABI,
|
|
33047
33716
|
FILE_REGISTRATION_TYPES,
|
|
33717
|
+
GENERIC_PAYMENT_TYPES,
|
|
33048
33718
|
GRANT_REGISTRATION_TYPES,
|
|
33049
33719
|
GRANT_REVOCATION_TYPES,
|
|
33050
33720
|
GoogleDriveStorage,
|
|
@@ -33055,11 +33725,17 @@ export {
|
|
|
33055
33725
|
IpfsStorage,
|
|
33056
33726
|
MASTER_KEY_MESSAGE,
|
|
33057
33727
|
MissingAuthError,
|
|
33728
|
+
NATIVE_VANA_ASSET,
|
|
33058
33729
|
NetworkError,
|
|
33059
33730
|
NodeECIESUint8Provider as NodeECIESProvider,
|
|
33060
33731
|
NodePlatformAdapter,
|
|
33061
33732
|
NonceError,
|
|
33062
33733
|
OAuthClient,
|
|
33734
|
+
PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX,
|
|
33735
|
+
PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE,
|
|
33736
|
+
PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION,
|
|
33737
|
+
PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID,
|
|
33738
|
+
PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT,
|
|
33063
33739
|
PKCE_CHALLENGE_PATTERN,
|
|
33064
33740
|
PKCE_VERIFIER_PATTERN,
|
|
33065
33741
|
PSError,
|
|
@@ -33067,6 +33743,7 @@ export {
|
|
|
33067
33743
|
PersonalServerError,
|
|
33068
33744
|
PinataStorage,
|
|
33069
33745
|
R2Storage,
|
|
33746
|
+
RECORD_DATA_ACCESS_TYPES,
|
|
33070
33747
|
ReadOnlyError,
|
|
33071
33748
|
RelayerError,
|
|
33072
33749
|
SERVER_REGISTRATION_TYPES,
|
|
@@ -33081,6 +33758,12 @@ export {
|
|
|
33081
33758
|
VanaError,
|
|
33082
33759
|
VanaStorage,
|
|
33083
33760
|
assertValidPkceVerifier,
|
|
33761
|
+
buildDepositNativeRequest,
|
|
33762
|
+
buildDepositTokenRequest,
|
|
33763
|
+
buildPersonalServerLiteOwnerBindingMessage,
|
|
33764
|
+
buildPersonalServerLiteOwnerBindingSignature,
|
|
33765
|
+
buildPersonalServerRegistrationSignature,
|
|
33766
|
+
buildPersonalServerRegistrationTypedData,
|
|
33084
33767
|
buildWeb3SignedHeader,
|
|
33085
33768
|
builderRegistrationDomain,
|
|
33086
33769
|
chains,
|
|
@@ -33096,12 +33779,19 @@ export {
|
|
|
33096
33779
|
createPlatformAdapterFor,
|
|
33097
33780
|
createPlatformAdapterSafe,
|
|
33098
33781
|
createVanaStorageProvider,
|
|
33782
|
+
createViemPersonalServerLiteOwnerBindingSigner,
|
|
33783
|
+
createViemPersonalServerRegistrationSigner,
|
|
33784
|
+
dataRegistryDomain,
|
|
33099
33785
|
decryptWithPassword,
|
|
33100
33786
|
deriveMasterKey,
|
|
33101
33787
|
deriveScopeKey,
|
|
33102
33788
|
deserializeECIES,
|
|
33103
33789
|
detectPlatform,
|
|
33790
|
+
encodeDepositNativeData,
|
|
33791
|
+
encodeDepositTokenData,
|
|
33104
33792
|
encryptWithPassword,
|
|
33793
|
+
escrowContractAddress,
|
|
33794
|
+
escrowPaymentDomain,
|
|
33105
33795
|
fileRegistrationDomain,
|
|
33106
33796
|
generatePkceVerifier,
|
|
33107
33797
|
getAbi,
|
|
@@ -33110,6 +33800,8 @@ export {
|
|
|
33110
33800
|
getContractAddress,
|
|
33111
33801
|
getContractController,
|
|
33112
33802
|
getContractInfo,
|
|
33803
|
+
getFee,
|
|
33804
|
+
getOpFee,
|
|
33113
33805
|
getPlatformCapabilities,
|
|
33114
33806
|
getServiceEndpoints,
|
|
33115
33807
|
grantRegistrationDomain,
|
|
@@ -33121,16 +33813,20 @@ export {
|
|
|
33121
33813
|
moksha,
|
|
33122
33814
|
mokshaServices,
|
|
33123
33815
|
mokshaTestnet2 as mokshaTestnet,
|
|
33124
|
-
parseGrantRegistrationPayload,
|
|
33125
33816
|
parsePSError,
|
|
33126
33817
|
parseScope,
|
|
33127
33818
|
parseWeb3SignedHeader,
|
|
33819
|
+
personalServerRegistrationDomain,
|
|
33128
33820
|
recoverServerOwner,
|
|
33821
|
+
registerPersonalServerSignature,
|
|
33129
33822
|
scopeCoveredByGrant,
|
|
33130
33823
|
scopeMatchesPattern,
|
|
33131
33824
|
scopeToPathSegments,
|
|
33132
33825
|
serializeECIES,
|
|
33133
33826
|
serverRegistrationDomain,
|
|
33827
|
+
signPersonalServerLiteOwnerBinding,
|
|
33828
|
+
signPersonalServerLiteOwnerBindingWithAccountClient,
|
|
33829
|
+
signPersonalServerRegistrationWithAccount,
|
|
33134
33830
|
vanaMainnet2 as vanaMainnet,
|
|
33135
33831
|
verifyGrantRegistration,
|
|
33136
33832
|
verifyPkceChallenge,
|