@opendatalabs/vana-sdk 3.13.2 → 3.13.4-pr.184.80a4b1f
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.d.ts +1 -1
- package/dist/account/personal-server-registration.d.ts +1 -1
- package/dist/auth/errors.d.ts +1 -1
- package/dist/auth/oauth-client.d.ts +1 -1
- package/dist/browser.d.ts +1 -1
- package/dist/chains/index.d.ts +2 -2
- package/dist/chains.browser.d.ts +2 -2
- package/dist/chains.d.ts +2 -2
- package/dist/chains.node.d.ts +2 -2
- package/dist/contracts/contractController.d.ts +4 -4
- package/dist/core/client.d.ts +1 -1
- package/dist/crypto/ecies/base.d.ts +1 -1
- package/dist/crypto/ecies/browser.d.ts +1 -1
- package/dist/crypto/ecies/index.d.ts +2 -2
- package/dist/crypto/ecies/node.d.ts +1 -1
- package/dist/crypto/services/WalletKeyEncryptionService.d.ts +1 -1
- package/dist/direct/access-request-client.cjs +1 -0
- package/dist/direct/access-request-client.cjs.map +1 -1
- package/dist/direct/access-request-client.d.ts +2 -2
- package/dist/direct/access-request-client.js +1 -0
- package/dist/direct/access-request-client.js.map +1 -1
- package/dist/direct/connect-flow.cjs +1 -1
- package/dist/direct/connect-flow.cjs.map +1 -1
- package/dist/direct/connect-flow.d.ts +1 -1
- package/dist/direct/connect-flow.js +1 -1
- package/dist/direct/connect-flow.js.map +1 -1
- package/dist/direct/controller.cjs.map +1 -1
- package/dist/direct/controller.d.ts +8 -8
- package/dist/direct/controller.js.map +1 -1
- package/dist/direct/endpoints.d.ts +1 -1
- package/dist/direct/errors.d.ts +1 -1
- package/dist/direct/escrow-payment.cjs +142 -11
- package/dist/direct/escrow-payment.cjs.map +1 -1
- package/dist/direct/escrow-payment.d.ts +65 -12
- package/dist/direct/escrow-payment.js +138 -11
- package/dist/direct/escrow-payment.js.map +1 -1
- package/dist/direct/personal-server-read.cjs +156 -23
- package/dist/direct/personal-server-read.cjs.map +1 -1
- package/dist/direct/personal-server-read.d.ts +28 -18
- package/dist/direct/personal-server-read.js +159 -25
- package/dist/direct/personal-server-read.js.map +1 -1
- package/dist/direct/types.cjs.map +1 -1
- package/dist/direct/types.d.ts +61 -22
- package/dist/direct/types.js.map +1 -1
- package/dist/direct/use-direct-vana-connect.d.ts +1 -1
- package/dist/generated/abi/index.d.ts +25 -25
- package/dist/index.browser.d.ts +44 -44
- package/dist/index.browser.js.map +2 -2
- package/dist/index.node.cjs +480 -0
- package/dist/index.node.cjs.map +4 -4
- package/dist/index.node.d.ts +48 -45
- package/dist/index.node.js +468 -0
- package/dist/index.node.js.map +4 -4
- package/dist/node.d.ts +1 -1
- package/dist/platform/browser-only.d.ts +3 -3
- package/dist/platform/browser-safe.d.ts +3 -3
- package/dist/platform/browser.d.ts +1 -1
- package/dist/platform/index.d.ts +5 -5
- package/dist/platform/node.d.ts +1 -1
- package/dist/platform/ports/openpgp-port.d.ts +1 -1
- package/dist/platform/utils.d.ts +1 -1
- package/dist/platform.browser.d.ts +4 -4
- package/dist/platform.d.ts +5 -5
- package/dist/platform.node.d.ts +5 -5
- package/dist/protocol/data-point-status.d.ts +1 -1
- package/dist/protocol/eip712.cjs.map +1 -1
- package/dist/protocol/eip712.js.map +1 -1
- package/dist/protocol/escrow-deposit.d.ts +1 -1
- package/dist/protocol/escrow.cjs.map +1 -1
- package/dist/protocol/escrow.d.ts +11 -4
- package/dist/protocol/escrow.js.map +1 -1
- package/dist/protocol/fee-registry.d.ts +1 -1
- package/dist/protocol/gateway.cjs.map +1 -1
- package/dist/protocol/gateway.js.map +1 -1
- package/dist/protocol/grants.d.ts +1 -1
- package/dist/protocol/personal-server-data.d.ts +2 -2
- package/dist/protocol/personal-server-registration.d.ts +2 -2
- package/dist/react.d.ts +3 -3
- package/dist/server.cjs +10 -0
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.ts +8 -8
- package/dist/server.js +10 -0
- package/dist/server.js.map +1 -1
- package/dist/session-relay/client.d.ts +1 -1
- package/dist/session-relay/endpoints.d.ts +1 -1
- package/dist/session-relay/errors.d.ts +1 -1
- package/dist/session-relay/index.d.ts +5 -5
- package/dist/session-relay/signing.d.ts +1 -1
- package/dist/session-relay/types.d.ts +1 -1
- package/dist/session-relay.d.ts +5 -5
- package/dist/storage/default.d.ts +2 -2
- package/dist/storage/index.d.ts +16 -16
- package/dist/storage/manager.d.ts +1 -1
- package/dist/storage/providers/callback-storage.d.ts +2 -2
- package/dist/storage/providers/dropbox.d.ts +1 -1
- package/dist/storage/providers/google-drive.d.ts +1 -1
- package/dist/storage/providers/ipfs.d.ts +1 -1
- package/dist/storage/providers/pinata.d.ts +1 -1
- package/dist/storage/providers/r2.d.ts +1 -1
- package/dist/storage/providers/vana-storage.d.ts +3 -3
- package/dist/types/config.d.ts +1 -1
- package/dist/types/index.d.ts +6 -6
- package/dist/types.d.ts +1 -1
- package/package.json +13 -1
package/dist/index.node.d.ts
CHANGED
|
@@ -6,48 +6,51 @@
|
|
|
6
6
|
* Exposes the platform adapter, ECIES crypto, storage providers, smart-contract
|
|
7
7
|
* helpers, ABIs, addresses, chain configurations, and shared types.
|
|
8
8
|
*/
|
|
9
|
-
export type * from "./types";
|
|
10
|
-
export * from "./errors";
|
|
11
|
-
export * from "./contracts/contractController";
|
|
12
|
-
export { getAbi } from "./generated/abi";
|
|
13
|
-
export type { VanaContract, VanaContract as VanaContractAbi, } from "./generated/abi";
|
|
14
|
-
export { getContractAddress, CONTRACTS } from "./generated/addresses";
|
|
15
|
-
export type { VanaContractAddress } from "./generated/addresses";
|
|
16
|
-
export { vanaMainnet, mokshaTestnet, moksha, type VanaChainConfig, getChainConfig, getAllChains, } from "./chains";
|
|
17
|
-
export * from "./chains";
|
|
18
|
-
export { chains } from "./config/chains";
|
|
19
|
-
export { type ServiceEndpoints, mainnetServices, mokshaServices, getServiceEndpoints, } from "./config/default-services";
|
|
20
|
-
export * from "./storage/index";
|
|
21
|
-
export { createVanaStorageProvider } from "./storage/default";
|
|
22
|
-
export type { VanaStorageProviderOptions } from "./storage/default";
|
|
23
|
-
export { NodePlatformAdapter } from "./platform/node";
|
|
24
|
-
export { BrowserPlatformAdapter } from "./platform/browser";
|
|
25
|
-
export { NodeECIESUint8Provider as NodeECIESProvider } from "./crypto/ecies/node";
|
|
26
|
-
export type { VanaPlatformAdapter } from "./platform/interface";
|
|
27
|
-
export { ECIESError, isECIESEncrypted, serializeECIES, deserializeECIES, } from "./crypto/ecies";
|
|
28
|
-
export type { ECIESProvider, ECIESEncrypted, ECIESOptions, } from "./crypto/ecies";
|
|
29
|
-
export { detectPlatform, createPlatformAdapter, createPlatformAdapterFor, isPlatformSupported, getPlatformCapabilities, } from "./platform/utils";
|
|
30
|
-
export { createNodePlatformAdapter, createBrowserPlatformAdapter, createPlatformAdapterSafe, } from "./platform/browser-safe";
|
|
31
|
-
export { deriveMasterKey, deriveScopeKey, recoverServerOwner, MASTER_KEY_MESSAGE, } from "./crypto/keys/derive";
|
|
32
|
-
export { encryptWithPassword, decryptWithPassword, } from "./crypto/envelope/openpgp";
|
|
33
|
-
export { parseWeb3SignedHeader, verifyWeb3Signed, type Web3SignedPayload, type VerifiedAuth, } from "./auth/web3-signed";
|
|
34
|
-
export { buildWeb3SignedHeader, computeBodyHash, type Web3SignedSignFn, } from "./auth/web3-signed-builder";
|
|
35
|
-
export { MissingAuthError, InvalidSignatureError, ExpiredTokenError, } from "./auth/errors";
|
|
36
|
-
export { generatePkceVerifier, computePkceChallenge, verifyPkceChallenge, assertValidPkceVerifier, PKCE_VERIFIER_PATTERN, PKCE_CHALLENGE_PATTERN, } from "./auth/pkce";
|
|
37
|
-
export { InMemoryTokenStore, type TokenStore, type TokenRecord, } from "./auth/token-store";
|
|
38
|
-
export { OAuthClient, type OAuthClientConfig, type AuthorizationUrlResult, } from "./auth/oauth-client";
|
|
39
|
-
export { NATIVE_VANA_ASSET, dataRegistryDomain, grantRegistrationDomain, grantRevocationDomain, serverRegistrationDomain, builderRegistrationDomain, escrowPaymentDomain, GRANT_REGISTRATION_TYPES, GRANT_REVOCATION_TYPES, SERVER_REGISTRATION_TYPES, BUILDER_REGISTRATION_TYPES, ADD_DATA_TYPES, RECORD_DATA_ACCESS_TYPES, type DataPortabilityContracts, type DataPortabilityGatewayConfig, type GrantRegistrationMessage, type GrantRevocationMessage, type ServerRegistrationMessage, type BuilderRegistrationMessage, type AddDataMessage, type RecordDataAccessMessage, } from "./protocol/eip712";
|
|
40
|
-
export { PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID, PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT, personalServerRegistrationDomain, createViemPersonalServerRegistrationSigner, buildPersonalServerRegistrationTypedData, buildPersonalServerRegistrationSignature, registerPersonalServerSignature, type PersonalServerRegistrationTypedData, type PersonalServerRegistrationSigner, type PersonalServerRegistrationDomainInput, type ViemPersonalServerRegistrationWalletClient, type ViemPersonalServerRegistrationSignerSource, type BuildPersonalServerRegistrationTypedDataInput, type BuildPersonalServerRegistrationSignatureInput, type PersonalServerRegistrationSignature, } from "./protocol/personal-server-registration";
|
|
41
|
-
export { PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION, PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE, PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX, buildPersonalServerLiteOwnerBindingMessage, createViemPersonalServerLiteOwnerBindingSigner, buildPersonalServerLiteOwnerBindingSignature, signPersonalServerLiteOwnerBinding, type PersonalServerLiteOwnerBindingPurpose, type PersonalServerLiteOwnerBindingMessage, type PersonalServerLiteOwnerBindingSigner, type ViemPersonalServerLiteOwnerBindingWalletClient, type ViemPersonalServerLiteOwnerBindingSignerSource, type BuildPersonalServerLiteOwnerBindingSignatureInput, type PersonalServerLiteOwnerBindingSignature, } from "./personal-server-lite/owner-binding";
|
|
42
|
-
export { ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT, AccountPersonalServerRegistrationError, signPersonalServerRegistrationWithAccount, type AccountPersonalServerRegistrationIntent, type AccountPersonalServerRegistrationSignature, type AccountPersonalServerRegistrationStatus, type AccountPersonalServerRegistrationRequest, type AccountPersonalServerRegistrationConfig, type AccountSignedPersonalServerRegistration, type AccountConfirmationRequiredPersonalServerRegistration, type AccountFallbackSignedPersonalServerRegistration, type AccountPersonalServerRegistrationResult, } from "./account/personal-server-registration";
|
|
43
|
-
export { AccountPersonalServerLiteOwnerBindingError, signPersonalServerLiteOwnerBindingWithAccountClient, type AccountPersonalServerLiteOwnerBindingClient, type SignPersonalServerLiteOwnerBindingWithAccountClientConfig, } from "./account/personal-server-lite-owner-binding";
|
|
44
|
-
export { isDataPortabilityGatewayConfig, verifyGrantRegistration, type VerifyGrantRegistrationInput, type VerifyGrantRegistrationResult, } from "./protocol/grants";
|
|
45
|
-
export { FEE_REGISTRY_ABI, REGISTRATION_KIND_FOR_OP, getFee, getOpFee, type FeeKind, type FeeEntry, type OpFee, type FeeRegistryOptions, } from "./protocol/fee-registry";
|
|
46
|
-
export { escrowContractAddress, encodeDepositNativeData, encodeDepositTokenData, buildDepositNativeRequest, buildDepositTokenRequest, type DepositNativeInput, type DepositTokenInput, type DepositTransactionRequest, } from "./protocol/escrow-deposit";
|
|
47
|
-
export { DATA_REGISTRY_STATUS_ABI, DataPointStatus, dataRegistryContractAddress, encodeSetDataPointStatusData, buildSetDataPointStatusRequest, buildMarkDataPointUnavailableRequest, type SetDataPointStatusInput, type DataPointStatusTransactionRequest, } from "./protocol/data-point-status";
|
|
48
|
-
export { personalServerDataReadPath, buildPersonalServerDataReadRequest, readPersonalServerData, type BuildPersonalServerDataReadRequestParams, type ReadPersonalServerDataParams, } from "./protocol/personal-server-data";
|
|
49
|
-
export { ScopeSchema, parseScope, scopeToPathSegments, scopeMatchesPattern, scopeCoveredByGrant, type Scope, type ParsedScope, } from "./protocol/scopes";
|
|
50
|
-
export { DataFileEnvelopeSchema, createDataFileEnvelope, IngestResponseSchema, type DataFileEnvelope, type IngestResponse, } from "./protocol/data-file";
|
|
51
|
-
export { createGatewayClient, type GatewayEnvelope, type GatewayProof, type Builder, type Schema, type ServerInfo, type OwnerServerRecord, type OwnerServersResult, type GatewayGrantFee, type GatewayGrantStatus, type GatewayGrantResponse, type GrantListItem, type DataPointRecord, type DataPointListResult, type ListDataPointsOptions, type RegisterServerParams, type RegisterServerResult, type RegisterBuilderParams, type RegisterBuilderResult, type RegisterDataPointParams, type RegisterDataPointResult, type CreateGrantParams, type RevokeGrantParams, type AccessRecord, type PayForOperationParams, type PayForOperationResult, type SettleOpType, type SettleItem, type SettlePromoteResult, type SettleReconcileItem, type SettleParams, type SettleResult, type GatewayClient, } from "./protocol/gateway";
|
|
52
|
-
export { createEscrowGatewayClient, genericPaymentDomain, GENERIC_PAYMENT_TYPES, ESCROW_DEPOSIT_ABI, NATIVE_ASSET_ADDRESS, type GenericPaymentMessage, type EscrowBalanceEntry, type EscrowBalanceResult, type EscrowBalanceSyncResult, type DepositSubmissionResult, type PaymentBreakdown, type EscrowPayResult, type SubmitDepositParams, type PayForOpParams, type EscrowGatewayClient, type SubmittedDepositEntry, type FinalizedDepositEntry, type FailedDepositEntry, } from "./protocol/escrow";
|
|
53
|
-
export {
|
|
9
|
+
export type * from "./types.js";
|
|
10
|
+
export * from "./errors.js";
|
|
11
|
+
export * from "./contracts/contractController.js";
|
|
12
|
+
export { getAbi } from "./generated/abi/index.js";
|
|
13
|
+
export type { VanaContract, VanaContract as VanaContractAbi, } from "./generated/abi/index.js";
|
|
14
|
+
export { getContractAddress, CONTRACTS } from "./generated/addresses.js";
|
|
15
|
+
export type { VanaContractAddress } from "./generated/addresses.js";
|
|
16
|
+
export { vanaMainnet, mokshaTestnet, moksha, type VanaChainConfig, getChainConfig, getAllChains, } from "./chains.js";
|
|
17
|
+
export * from "./chains.js";
|
|
18
|
+
export { chains } from "./config/chains.js";
|
|
19
|
+
export { type ServiceEndpoints, mainnetServices, mokshaServices, getServiceEndpoints, } from "./config/default-services.js";
|
|
20
|
+
export * from "./storage/index.js";
|
|
21
|
+
export { createVanaStorageProvider } from "./storage/default.js";
|
|
22
|
+
export type { VanaStorageProviderOptions } from "./storage/default.js";
|
|
23
|
+
export { NodePlatformAdapter } from "./platform/node.js";
|
|
24
|
+
export { BrowserPlatformAdapter } from "./platform/browser.js";
|
|
25
|
+
export { NodeECIESUint8Provider as NodeECIESProvider } from "./crypto/ecies/node.js";
|
|
26
|
+
export type { VanaPlatformAdapter } from "./platform/interface.js";
|
|
27
|
+
export { ECIESError, isECIESEncrypted, serializeECIES, deserializeECIES, } from "./crypto/ecies/index.js";
|
|
28
|
+
export type { ECIESProvider, ECIESEncrypted, ECIESOptions, } from "./crypto/ecies/index.js";
|
|
29
|
+
export { detectPlatform, createPlatformAdapter, createPlatformAdapterFor, isPlatformSupported, getPlatformCapabilities, } from "./platform/utils.js";
|
|
30
|
+
export { createNodePlatformAdapter, createBrowserPlatformAdapter, createPlatformAdapterSafe, } from "./platform/browser-safe.js";
|
|
31
|
+
export { deriveMasterKey, deriveScopeKey, recoverServerOwner, MASTER_KEY_MESSAGE, } from "./crypto/keys/derive.js";
|
|
32
|
+
export { encryptWithPassword, decryptWithPassword, } from "./crypto/envelope/openpgp.js";
|
|
33
|
+
export { parseWeb3SignedHeader, verifyWeb3Signed, type Web3SignedPayload, type VerifiedAuth, } from "./auth/web3-signed.js";
|
|
34
|
+
export { buildWeb3SignedHeader, computeBodyHash, type Web3SignedSignFn, } from "./auth/web3-signed-builder.js";
|
|
35
|
+
export { MissingAuthError, InvalidSignatureError, ExpiredTokenError, } from "./auth/errors.js";
|
|
36
|
+
export { generatePkceVerifier, computePkceChallenge, verifyPkceChallenge, assertValidPkceVerifier, PKCE_VERIFIER_PATTERN, PKCE_CHALLENGE_PATTERN, } from "./auth/pkce.js";
|
|
37
|
+
export { InMemoryTokenStore, type TokenStore, type TokenRecord, } from "./auth/token-store.js";
|
|
38
|
+
export { OAuthClient, type OAuthClientConfig, type AuthorizationUrlResult, } from "./auth/oauth-client.js";
|
|
39
|
+
export { NATIVE_VANA_ASSET, dataRegistryDomain, grantRegistrationDomain, grantRevocationDomain, serverRegistrationDomain, builderRegistrationDomain, escrowPaymentDomain, GRANT_REGISTRATION_TYPES, GRANT_REVOCATION_TYPES, SERVER_REGISTRATION_TYPES, BUILDER_REGISTRATION_TYPES, ADD_DATA_TYPES, RECORD_DATA_ACCESS_TYPES, type DataPortabilityContracts, type DataPortabilityGatewayConfig, type GrantRegistrationMessage, type GrantRevocationMessage, type ServerRegistrationMessage, type BuilderRegistrationMessage, type AddDataMessage, type RecordDataAccessMessage, } from "./protocol/eip712.js";
|
|
40
|
+
export { PERSONAL_SERVER_REGISTRATION_DEFAULT_CHAIN_ID, PERSONAL_SERVER_REGISTRATION_DEFAULT_VERIFYING_CONTRACT, personalServerRegistrationDomain, createViemPersonalServerRegistrationSigner, buildPersonalServerRegistrationTypedData, buildPersonalServerRegistrationSignature, registerPersonalServerSignature, type PersonalServerRegistrationTypedData, type PersonalServerRegistrationSigner, type PersonalServerRegistrationDomainInput, type ViemPersonalServerRegistrationWalletClient, type ViemPersonalServerRegistrationSignerSource, type BuildPersonalServerRegistrationTypedDataInput, type BuildPersonalServerRegistrationSignatureInput, type PersonalServerRegistrationSignature, } from "./protocol/personal-server-registration.js";
|
|
41
|
+
export { PERSONAL_SERVER_LITE_OWNER_BINDING_VERSION, PERSONAL_SERVER_LITE_OWNER_BINDING_PURPOSE, PERSONAL_SERVER_LITE_OWNER_BINDING_PREFIX, buildPersonalServerLiteOwnerBindingMessage, createViemPersonalServerLiteOwnerBindingSigner, buildPersonalServerLiteOwnerBindingSignature, signPersonalServerLiteOwnerBinding, type PersonalServerLiteOwnerBindingPurpose, type PersonalServerLiteOwnerBindingMessage, type PersonalServerLiteOwnerBindingSigner, type ViemPersonalServerLiteOwnerBindingWalletClient, type ViemPersonalServerLiteOwnerBindingSignerSource, type BuildPersonalServerLiteOwnerBindingSignatureInput, type PersonalServerLiteOwnerBindingSignature, } from "./personal-server-lite/owner-binding.js";
|
|
42
|
+
export { ACCOUNT_PERSONAL_SERVER_REGISTRATION_INTENT, AccountPersonalServerRegistrationError, signPersonalServerRegistrationWithAccount, type AccountPersonalServerRegistrationIntent, type AccountPersonalServerRegistrationSignature, type AccountPersonalServerRegistrationStatus, type AccountPersonalServerRegistrationRequest, type AccountPersonalServerRegistrationConfig, type AccountSignedPersonalServerRegistration, type AccountConfirmationRequiredPersonalServerRegistration, type AccountFallbackSignedPersonalServerRegistration, type AccountPersonalServerRegistrationResult, } from "./account/personal-server-registration.js";
|
|
43
|
+
export { AccountPersonalServerLiteOwnerBindingError, signPersonalServerLiteOwnerBindingWithAccountClient, type AccountPersonalServerLiteOwnerBindingClient, type SignPersonalServerLiteOwnerBindingWithAccountClientConfig, } from "./account/personal-server-lite-owner-binding.js";
|
|
44
|
+
export { isDataPortabilityGatewayConfig, verifyGrantRegistration, type VerifyGrantRegistrationInput, type VerifyGrantRegistrationResult, } from "./protocol/grants.js";
|
|
45
|
+
export { FEE_REGISTRY_ABI, REGISTRATION_KIND_FOR_OP, getFee, getOpFee, type FeeKind, type FeeEntry, type OpFee, type FeeRegistryOptions, } from "./protocol/fee-registry.js";
|
|
46
|
+
export { escrowContractAddress, encodeDepositNativeData, encodeDepositTokenData, buildDepositNativeRequest, buildDepositTokenRequest, type DepositNativeInput, type DepositTokenInput, type DepositTransactionRequest, } from "./protocol/escrow-deposit.js";
|
|
47
|
+
export { DATA_REGISTRY_STATUS_ABI, DataPointStatus, dataRegistryContractAddress, encodeSetDataPointStatusData, buildSetDataPointStatusRequest, buildMarkDataPointUnavailableRequest, type SetDataPointStatusInput, type DataPointStatusTransactionRequest, } from "./protocol/data-point-status.js";
|
|
48
|
+
export { personalServerDataReadPath, buildPersonalServerDataReadRequest, readPersonalServerData, type BuildPersonalServerDataReadRequestParams, type ReadPersonalServerDataParams, } from "./protocol/personal-server-data.js";
|
|
49
|
+
export { ScopeSchema, parseScope, scopeToPathSegments, scopeMatchesPattern, scopeCoveredByGrant, type Scope, type ParsedScope, } from "./protocol/scopes.js";
|
|
50
|
+
export { DataFileEnvelopeSchema, createDataFileEnvelope, IngestResponseSchema, type DataFileEnvelope, type IngestResponse, } from "./protocol/data-file.js";
|
|
51
|
+
export { createGatewayClient, type GatewayEnvelope, type GatewayProof, type Builder, type Schema, type ServerInfo, type OwnerServerRecord, type OwnerServersResult, type GatewayGrantFee, type GatewayGrantStatus, type GatewayGrantResponse, type GrantListItem, type DataPointRecord, type DataPointListResult, type ListDataPointsOptions, type RegisterServerParams, type RegisterServerResult, type RegisterBuilderParams, type RegisterBuilderResult, type RegisterDataPointParams, type RegisterDataPointResult, type CreateGrantParams, type RevokeGrantParams, type AccessRecord, type PayForOperationParams, type PayForOperationResult, type SettleOpType, type SettleItem, type SettlePromoteResult, type SettleReconcileItem, type SettleParams, type SettleResult, type GatewayClient, } from "./protocol/gateway.js";
|
|
52
|
+
export { createEscrowGatewayClient, genericPaymentDomain, GENERIC_PAYMENT_TYPES, ESCROW_DEPOSIT_ABI, NATIVE_ASSET_ADDRESS, type GenericPaymentMessage, type EscrowBalanceEntry, type EscrowBalanceResult, type EscrowBalanceSyncResult, type DepositSubmissionResult, type PaymentBreakdown, type EscrowPayResult, type SubmitDepositParams, type PayForOpParams, type EscrowGatewayClient, type SubmittedDepositEntry, type FinalizedDepositEntry, type FailedDepositEntry, } from "./protocol/escrow.js";
|
|
53
|
+
export { authorizeEscrowPayment, authorizeGrantPayment, buildEscrowPaymentHeader, buildGrantPaymentHeader, createDefaultNonceSource, DATA_ACCESS_OP_TYPE, GRANT_OP_TYPE, paymentReceiptFromHeader, paymentResponseMetadataFromHeader, toDirectFeeBreakdown, toDirectPaymentReceipt, type EscrowPaymentConfig, type EscrowPaymentHeaderConfig, type PaymentNonceSource, type SignTypedDataFn, } from "./direct/escrow-payment.js";
|
|
54
|
+
export { parsePersonalServerPaymentRequired, type FetchResponseLike, } from "./direct/personal-server-read.js";
|
|
55
|
+
export type { DirectPaymentResponseMetadata, PersonalServerDataAccessPaymentOperation, PersonalServerGrantPaymentOperation, PersonalServerPaymentOperation, PersonalServerPaymentRequired, } from "./direct/types.js";
|
|
56
|
+
export { PSError, parsePSError, type PSErrorCode } from "./types/ps-errors.js";
|
package/dist/index.node.js
CHANGED
|
@@ -33988,6 +33988,462 @@ function createEscrowGatewayClient(baseUrl) {
|
|
|
33988
33988
|
};
|
|
33989
33989
|
}
|
|
33990
33990
|
|
|
33991
|
+
// src/direct/escrow-payment.ts
|
|
33992
|
+
var GRANT_OP_TYPE = "grant";
|
|
33993
|
+
var DATA_ACCESS_OP_TYPE = "data_access";
|
|
33994
|
+
function toDirectFeeBreakdown(breakdown) {
|
|
33995
|
+
return {
|
|
33996
|
+
registrationFee: breakdown.registrationFee,
|
|
33997
|
+
dataAccessFee: breakdown.dataAccessFee,
|
|
33998
|
+
registrationPaid: breakdown.registrationPaid
|
|
33999
|
+
};
|
|
34000
|
+
}
|
|
34001
|
+
function toDirectPaymentReceipt(result) {
|
|
34002
|
+
return {
|
|
34003
|
+
opType: result.opType,
|
|
34004
|
+
opId: result.opId,
|
|
34005
|
+
asset: result.asset,
|
|
34006
|
+
amount: result.amount,
|
|
34007
|
+
paymentNonce: result.paymentNonce,
|
|
34008
|
+
breakdown: toDirectFeeBreakdown(result.breakdown),
|
|
34009
|
+
paidAt: result.paidAt
|
|
34010
|
+
};
|
|
34011
|
+
}
|
|
34012
|
+
function createDefaultNonceSource() {
|
|
34013
|
+
const counters = /* @__PURE__ */ new Map();
|
|
34014
|
+
return (payerAddress) => {
|
|
34015
|
+
const key = payerAddress.toLowerCase();
|
|
34016
|
+
const next = (counters.get(key) ?? 0n) + 1n;
|
|
34017
|
+
counters.set(key, next);
|
|
34018
|
+
return next;
|
|
34019
|
+
};
|
|
34020
|
+
}
|
|
34021
|
+
var processLocalNonceSource = createDefaultNonceSource();
|
|
34022
|
+
var UINT256_MAX = (1n << 256n) - 1n;
|
|
34023
|
+
var ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/;
|
|
34024
|
+
var BYTES32_RE = /^0x[0-9a-fA-F]{64}$/;
|
|
34025
|
+
var SIGNATURE_RE = /^0x[0-9a-fA-F]{130}$/;
|
|
34026
|
+
function isUint256Decimal(value, allowZero) {
|
|
34027
|
+
const pattern = allowZero ? /^(0|[1-9]\d*)$/ : /^[1-9]\d*$/;
|
|
34028
|
+
return value.length <= UINT256_MAX.toString().length && pattern.test(value) && BigInt(value) <= UINT256_MAX;
|
|
34029
|
+
}
|
|
34030
|
+
function isValidAccessRecord(record) {
|
|
34031
|
+
return BYTES32_RE.test(record.dataPointId) && isUint256Decimal(record.version, false) && ADDRESS_RE.test(record.accessor) && BYTES32_RE.test(record.recordId) && SIGNATURE_RE.test(record.signature);
|
|
34032
|
+
}
|
|
34033
|
+
function validateSigningOperation(payerAddress, required) {
|
|
34034
|
+
if (!ADDRESS_RE.test(payerAddress)) {
|
|
34035
|
+
throw new Error("Payment payer must be a 20-byte EVM address");
|
|
34036
|
+
}
|
|
34037
|
+
if (!BYTES32_RE.test(required.opId)) {
|
|
34038
|
+
throw new Error("Payment operation id must be a 32-byte hex value");
|
|
34039
|
+
}
|
|
34040
|
+
if (!ADDRESS_RE.test(required.asset || NATIVE_ASSET_ADDRESS)) {
|
|
34041
|
+
throw new Error("Payment asset must be a 20-byte EVM address");
|
|
34042
|
+
}
|
|
34043
|
+
if (!isUint256Decimal(required.amount, true)) {
|
|
34044
|
+
throw new Error("Payment amount must be a canonical uint256 decimal");
|
|
34045
|
+
}
|
|
34046
|
+
if (required.paymentNonce !== void 0 && !isUint256Decimal(required.paymentNonce, false)) {
|
|
34047
|
+
throw new Error("Payment nonce must be a positive uint256 decimal");
|
|
34048
|
+
}
|
|
34049
|
+
const accessRecord = required.accessRecord;
|
|
34050
|
+
if (required.opType === DATA_ACCESS_OP_TYPE) {
|
|
34051
|
+
if (!accessRecord || !isValidAccessRecord(accessRecord)) {
|
|
34052
|
+
throw new Error("Data-access payment requires a valid access record");
|
|
34053
|
+
}
|
|
34054
|
+
if (required.opId.toLowerCase() !== accessRecord.recordId.toLowerCase()) {
|
|
34055
|
+
throw new Error(
|
|
34056
|
+
"Data-access payment operation id must equal the access record id"
|
|
34057
|
+
);
|
|
34058
|
+
}
|
|
34059
|
+
if (accessRecord.accessor.toLowerCase() !== payerAddress.toLowerCase()) {
|
|
34060
|
+
throw new Error(
|
|
34061
|
+
"Data-access payment accessor must equal the payment payer address"
|
|
34062
|
+
);
|
|
34063
|
+
}
|
|
34064
|
+
return;
|
|
34065
|
+
}
|
|
34066
|
+
if (required.amount === "0") {
|
|
34067
|
+
if (!accessRecord || !isValidAccessRecord(accessRecord) || accessRecord.accessor.toLowerCase() !== payerAddress.toLowerCase()) {
|
|
34068
|
+
throw new Error(
|
|
34069
|
+
"Zero-amount grant payments require a valid access record for the payer"
|
|
34070
|
+
);
|
|
34071
|
+
}
|
|
34072
|
+
}
|
|
34073
|
+
}
|
|
34074
|
+
function base64EncodeJson(value) {
|
|
34075
|
+
const bytes = new TextEncoder().encode(JSON.stringify(value));
|
|
34076
|
+
let binary = "";
|
|
34077
|
+
for (const byte of bytes) binary += String.fromCharCode(byte);
|
|
34078
|
+
return btoa(binary);
|
|
34079
|
+
}
|
|
34080
|
+
function base64DecodeJson(value) {
|
|
34081
|
+
const binary = atob(value);
|
|
34082
|
+
const bytes = Uint8Array.from(binary, (char) => char.charCodeAt(0));
|
|
34083
|
+
return JSON.parse(new TextDecoder().decode(bytes));
|
|
34084
|
+
}
|
|
34085
|
+
async function signEscrowPayment(params) {
|
|
34086
|
+
const { payerAddress, required, config } = params;
|
|
34087
|
+
validateSigningOperation(payerAddress, required);
|
|
34088
|
+
const nonceSource = config.nonceSource ?? processLocalNonceSource;
|
|
34089
|
+
const paymentNonce = BigInt(
|
|
34090
|
+
required.paymentNonce ?? await nonceSource(payerAddress)
|
|
34091
|
+
);
|
|
34092
|
+
const asset = required.asset || NATIVE_ASSET_ADDRESS;
|
|
34093
|
+
const opId = required.opId;
|
|
34094
|
+
const amount = BigInt(required.amount);
|
|
34095
|
+
if (amount < 0n || amount > UINT256_MAX) {
|
|
34096
|
+
throw new Error("Payment amount must be a uint256");
|
|
34097
|
+
}
|
|
34098
|
+
if (paymentNonce <= 0n || paymentNonce > UINT256_MAX) {
|
|
34099
|
+
throw new Error("Payment nonce must be a positive uint256");
|
|
34100
|
+
}
|
|
34101
|
+
const message = {
|
|
34102
|
+
payerAddress,
|
|
34103
|
+
opType: required.opType,
|
|
34104
|
+
opId,
|
|
34105
|
+
asset,
|
|
34106
|
+
amount,
|
|
34107
|
+
paymentNonce
|
|
34108
|
+
};
|
|
34109
|
+
const signature = await config.signTypedData({
|
|
34110
|
+
domain: genericPaymentDomain(config.chainId, config.escrowContract),
|
|
34111
|
+
types: GENERIC_PAYMENT_TYPES,
|
|
34112
|
+
primaryType: "GenericPayment",
|
|
34113
|
+
message
|
|
34114
|
+
});
|
|
34115
|
+
return {
|
|
34116
|
+
message: {
|
|
34117
|
+
...message,
|
|
34118
|
+
amount: amount.toString(),
|
|
34119
|
+
paymentNonce: paymentNonce.toString()
|
|
34120
|
+
},
|
|
34121
|
+
signature,
|
|
34122
|
+
...required.accessRecord ? { accessRecord: required.accessRecord } : {}
|
|
34123
|
+
};
|
|
34124
|
+
}
|
|
34125
|
+
async function buildEscrowPaymentHeader(params) {
|
|
34126
|
+
const signed = await signEscrowPayment(params);
|
|
34127
|
+
const payment = {
|
|
34128
|
+
x402Version: 1,
|
|
34129
|
+
scheme: "vana-escrow-grant",
|
|
34130
|
+
network: params.required.network ?? `vana:${params.config.chainId}`,
|
|
34131
|
+
payload: signed
|
|
34132
|
+
};
|
|
34133
|
+
return base64EncodeJson(payment);
|
|
34134
|
+
}
|
|
34135
|
+
async function buildGrantPaymentHeader(params) {
|
|
34136
|
+
return buildEscrowPaymentHeader({
|
|
34137
|
+
...params,
|
|
34138
|
+
required: {
|
|
34139
|
+
...params.required,
|
|
34140
|
+
opType: GRANT_OP_TYPE,
|
|
34141
|
+
opId: params.required.grantId
|
|
34142
|
+
}
|
|
34143
|
+
});
|
|
34144
|
+
}
|
|
34145
|
+
function asRecord(value) {
|
|
34146
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
34147
|
+
}
|
|
34148
|
+
function stringField(value, key) {
|
|
34149
|
+
const field = value?.[key];
|
|
34150
|
+
return typeof field === "string" ? field : void 0;
|
|
34151
|
+
}
|
|
34152
|
+
function isCanonicalIsoTimestamp(value) {
|
|
34153
|
+
try {
|
|
34154
|
+
return new Date(value).toISOString() === value;
|
|
34155
|
+
} catch {
|
|
34156
|
+
return false;
|
|
34157
|
+
}
|
|
34158
|
+
}
|
|
34159
|
+
function paymentResponseMetadataFromHeader(header) {
|
|
34160
|
+
if (!header) return void 0;
|
|
34161
|
+
try {
|
|
34162
|
+
const result = asRecord(base64DecodeJson(header));
|
|
34163
|
+
const breakdown = asRecord(result?.breakdown);
|
|
34164
|
+
const opType = stringField(result, "opType");
|
|
34165
|
+
const opId = stringField(result, "opId");
|
|
34166
|
+
const payerAddress = stringField(result, "payerAddress");
|
|
34167
|
+
const asset = stringField(result, "asset");
|
|
34168
|
+
const amount = stringField(result, "amount");
|
|
34169
|
+
const paymentNonce = stringField(result, "paymentNonce");
|
|
34170
|
+
const registrationFee = stringField(breakdown, "registrationFee");
|
|
34171
|
+
const dataAccessFee = stringField(breakdown, "dataAccessFee");
|
|
34172
|
+
const paidAt = stringField(result, "paidAt");
|
|
34173
|
+
if (result?.success !== true || !opType || !opId || !BYTES32_RE.test(opId) || !payerAddress || !ADDRESS_RE.test(payerAddress) || !asset || !ADDRESS_RE.test(asset) || !amount || !isUint256Decimal(amount, true) || !paymentNonce || !isUint256Decimal(paymentNonce, false) || !registrationFee || !isUint256Decimal(registrationFee, true) || !dataAccessFee || !isUint256Decimal(dataAccessFee, true) || typeof breakdown?.registrationPaid !== "boolean" || !paidAt || !isCanonicalIsoTimestamp(paidAt)) {
|
|
34174
|
+
return void 0;
|
|
34175
|
+
}
|
|
34176
|
+
return {
|
|
34177
|
+
opType,
|
|
34178
|
+
opId,
|
|
34179
|
+
asset,
|
|
34180
|
+
amount,
|
|
34181
|
+
paymentNonce,
|
|
34182
|
+
breakdown: {
|
|
34183
|
+
registrationFee,
|
|
34184
|
+
dataAccessFee,
|
|
34185
|
+
registrationPaid: breakdown.registrationPaid
|
|
34186
|
+
},
|
|
34187
|
+
paidAt
|
|
34188
|
+
};
|
|
34189
|
+
} catch {
|
|
34190
|
+
return void 0;
|
|
34191
|
+
}
|
|
34192
|
+
}
|
|
34193
|
+
function paymentReceiptFromHeader(header) {
|
|
34194
|
+
return paymentResponseMetadataFromHeader(header);
|
|
34195
|
+
}
|
|
34196
|
+
async function authorizeGrantPayment(params) {
|
|
34197
|
+
return authorizeEscrowPayment({
|
|
34198
|
+
...params,
|
|
34199
|
+
required: {
|
|
34200
|
+
...params.required,
|
|
34201
|
+
opType: GRANT_OP_TYPE,
|
|
34202
|
+
opId: params.required.grantId
|
|
34203
|
+
}
|
|
34204
|
+
});
|
|
34205
|
+
}
|
|
34206
|
+
async function authorizeEscrowPayment(params) {
|
|
34207
|
+
const { payerAddress, config } = params;
|
|
34208
|
+
const signed = await signEscrowPayment(params);
|
|
34209
|
+
const result = await config.client.payForOp({
|
|
34210
|
+
payerAddress,
|
|
34211
|
+
opType: signed.message.opType,
|
|
34212
|
+
opId: signed.message.opId,
|
|
34213
|
+
asset: signed.message.asset,
|
|
34214
|
+
amount: signed.message.amount,
|
|
34215
|
+
paymentNonce: signed.message.paymentNonce,
|
|
34216
|
+
signature: signed.signature,
|
|
34217
|
+
accessRecord: signed.accessRecord
|
|
34218
|
+
});
|
|
34219
|
+
return toDirectPaymentReceipt(result);
|
|
34220
|
+
}
|
|
34221
|
+
|
|
34222
|
+
// src/direct/errors.ts
|
|
34223
|
+
var PersonalServerReadError = class extends VanaError {
|
|
34224
|
+
constructor(message, status, details) {
|
|
34225
|
+
super(message, "DIRECT_PERSONAL_SERVER_READ_ERROR");
|
|
34226
|
+
this.status = status;
|
|
34227
|
+
this.details = details;
|
|
34228
|
+
}
|
|
34229
|
+
status;
|
|
34230
|
+
details;
|
|
34231
|
+
};
|
|
34232
|
+
|
|
34233
|
+
// src/direct/personal-server-read.ts
|
|
34234
|
+
function asRecord2(value) {
|
|
34235
|
+
return value && typeof value === "object" && !Array.isArray(value) ? value : void 0;
|
|
34236
|
+
}
|
|
34237
|
+
function stringField2(record, field) {
|
|
34238
|
+
const value = record?.[field];
|
|
34239
|
+
return typeof value === "string" ? value : void 0;
|
|
34240
|
+
}
|
|
34241
|
+
function parseAccessRecord(value) {
|
|
34242
|
+
const record = asRecord2(value);
|
|
34243
|
+
const dataPointId = stringField2(record, "dataPointId");
|
|
34244
|
+
const version = stringField2(record, "version");
|
|
34245
|
+
const accessor = stringField2(record, "accessor");
|
|
34246
|
+
const recordId = stringField2(record, "recordId");
|
|
34247
|
+
const signature = stringField2(record, "signature");
|
|
34248
|
+
if (!dataPointId || !version || !accessor || !recordId || !signature) {
|
|
34249
|
+
return void 0;
|
|
34250
|
+
}
|
|
34251
|
+
return {
|
|
34252
|
+
dataPointId,
|
|
34253
|
+
version,
|
|
34254
|
+
accessor,
|
|
34255
|
+
recordId,
|
|
34256
|
+
signature
|
|
34257
|
+
};
|
|
34258
|
+
}
|
|
34259
|
+
function isBytes32Hex(value) {
|
|
34260
|
+
return /^0x[0-9a-fA-F]{64}$/.test(value);
|
|
34261
|
+
}
|
|
34262
|
+
var UINT256_MAX2 = (1n << 256n) - 1n;
|
|
34263
|
+
function isAddressHex(value) {
|
|
34264
|
+
return /^0x[0-9a-fA-F]{40}$/.test(value);
|
|
34265
|
+
}
|
|
34266
|
+
function isUint256Decimal2(value, allowZero) {
|
|
34267
|
+
const pattern = allowZero ? /^(0|[1-9]\d*)$/ : /^[1-9]\d*$/;
|
|
34268
|
+
return value.length <= UINT256_MAX2.toString().length && pattern.test(value) && BigInt(value) <= UINT256_MAX2;
|
|
34269
|
+
}
|
|
34270
|
+
function isValidDataAccessRecord(record) {
|
|
34271
|
+
return isBytes32Hex(record.dataPointId) && isUint256Decimal2(record.version, false) && isAddressHex(record.accessor) && isBytes32Hex(record.recordId) && /^0x[0-9a-fA-F]{130}$/.test(record.signature);
|
|
34272
|
+
}
|
|
34273
|
+
function parseLegacyGrantOperation(params) {
|
|
34274
|
+
const { challengeGrantId, challengeOpId, challengeOpType, grantId } = params;
|
|
34275
|
+
const opType = challengeOpType ?? GRANT_OP_TYPE;
|
|
34276
|
+
if (opType !== GRANT_OP_TYPE) {
|
|
34277
|
+
throw new PersonalServerReadError(
|
|
34278
|
+
"Personal Server payment challenge used an unsupported escrow op type",
|
|
34279
|
+
402,
|
|
34280
|
+
{ opType: challengeOpType }
|
|
34281
|
+
);
|
|
34282
|
+
}
|
|
34283
|
+
const opId = challengeOpId ?? challengeGrantId ?? grantId;
|
|
34284
|
+
if (!opId || !isBytes32Hex(opId)) {
|
|
34285
|
+
throw new PersonalServerReadError(
|
|
34286
|
+
"Personal Server payment challenge used an invalid escrow op id",
|
|
34287
|
+
402,
|
|
34288
|
+
{ opId }
|
|
34289
|
+
);
|
|
34290
|
+
}
|
|
34291
|
+
if (opId.toLowerCase() !== grantId.toLowerCase()) {
|
|
34292
|
+
throw new PersonalServerReadError(
|
|
34293
|
+
"Personal Server payment challenge did not match the requested grant",
|
|
34294
|
+
402,
|
|
34295
|
+
{ opId, grantId }
|
|
34296
|
+
);
|
|
34297
|
+
}
|
|
34298
|
+
return { opType: GRANT_OP_TYPE, opId };
|
|
34299
|
+
}
|
|
34300
|
+
function hasDataAccessMarker(body) {
|
|
34301
|
+
if (stringField2(body, "opType") === DATA_ACCESS_OP_TYPE) return true;
|
|
34302
|
+
return Array.isArray(body.accepts) && body.accepts.some((value) => {
|
|
34303
|
+
const accept = asRecord2(value);
|
|
34304
|
+
return stringField2(asRecord2(accept?.message), "opType") === DATA_ACCESS_OP_TYPE;
|
|
34305
|
+
});
|
|
34306
|
+
}
|
|
34307
|
+
function parseCanonicalDataAccessAccept(value) {
|
|
34308
|
+
const accept = asRecord2(value);
|
|
34309
|
+
const message = asRecord2(accept?.message);
|
|
34310
|
+
if (stringField2(accept, "scheme") !== "vana-escrow-grant" || stringField2(message, "opType") !== DATA_ACCESS_OP_TYPE) {
|
|
34311
|
+
return null;
|
|
34312
|
+
}
|
|
34313
|
+
const network = stringField2(accept, "network");
|
|
34314
|
+
const payerAddress = stringField2(message, "payerAddress");
|
|
34315
|
+
const opId = stringField2(message, "opId");
|
|
34316
|
+
const asset = stringField2(message, "asset");
|
|
34317
|
+
const amount = stringField2(message, "amount");
|
|
34318
|
+
const paymentNonce = stringField2(message, "paymentNonce");
|
|
34319
|
+
const accessRecord = parseAccessRecord(accept?.accessRecord);
|
|
34320
|
+
const acceptAsset = stringField2(accept, "asset");
|
|
34321
|
+
const acceptAmount = stringField2(accept, "amount");
|
|
34322
|
+
if (!network || !payerAddress || !isAddressHex(payerAddress) || !opId || !isBytes32Hex(opId) || !asset || !isAddressHex(asset) || !amount || !isUint256Decimal2(amount, true) || !paymentNonce || !isUint256Decimal2(paymentNonce, false) || !accessRecord || !isValidDataAccessRecord(accessRecord) || payerAddress.toLowerCase() !== accessRecord.accessor.toLowerCase() || opId.toLowerCase() !== accessRecord.recordId.toLowerCase() || !acceptAsset || acceptAsset.toLowerCase() !== asset.toLowerCase() || acceptAmount !== amount) {
|
|
34323
|
+
return null;
|
|
34324
|
+
}
|
|
34325
|
+
return {
|
|
34326
|
+
opType: DATA_ACCESS_OP_TYPE,
|
|
34327
|
+
opId,
|
|
34328
|
+
network,
|
|
34329
|
+
paymentNonce,
|
|
34330
|
+
accessRecord,
|
|
34331
|
+
asset,
|
|
34332
|
+
amount
|
|
34333
|
+
};
|
|
34334
|
+
}
|
|
34335
|
+
function parseCanonicalDataAccessPayment(params) {
|
|
34336
|
+
const { body, grantId, raw } = params;
|
|
34337
|
+
if (body.x402Version !== 1 || body.error !== "PAYMENT_REQUIRED") {
|
|
34338
|
+
throw new PersonalServerReadError(
|
|
34339
|
+
"Personal Server data-access payment response was not a canonical x402 challenge",
|
|
34340
|
+
402
|
|
34341
|
+
);
|
|
34342
|
+
}
|
|
34343
|
+
const operation = Array.isArray(body.accepts) ? body.accepts.map(parseCanonicalDataAccessAccept).find((candidate) => candidate !== null) : void 0;
|
|
34344
|
+
if (!operation) {
|
|
34345
|
+
throw new PersonalServerReadError(
|
|
34346
|
+
"Personal Server data-access payment challenge was untrusted or incomplete",
|
|
34347
|
+
402
|
|
34348
|
+
);
|
|
34349
|
+
}
|
|
34350
|
+
return { grantId, raw, ...operation };
|
|
34351
|
+
}
|
|
34352
|
+
function preferredLegacyAccept(body) {
|
|
34353
|
+
if (!Array.isArray(body.accepts)) return void 0;
|
|
34354
|
+
return body.accepts.map(asRecord2).find((accept) => {
|
|
34355
|
+
const message = asRecord2(accept?.message);
|
|
34356
|
+
return stringField2(accept, "scheme") === "vana-escrow-grant" && stringField2(message, "opType") === GRANT_OP_TYPE;
|
|
34357
|
+
});
|
|
34358
|
+
}
|
|
34359
|
+
async function parsePersonalServerPaymentRequired(res, grantId) {
|
|
34360
|
+
let raw = void 0;
|
|
34361
|
+
try {
|
|
34362
|
+
raw = await res.json();
|
|
34363
|
+
} catch {
|
|
34364
|
+
raw = void 0;
|
|
34365
|
+
}
|
|
34366
|
+
const body = asRecord2(raw) ?? {};
|
|
34367
|
+
if (hasDataAccessMarker(body)) {
|
|
34368
|
+
return parseCanonicalDataAccessPayment({ body, grantId, raw });
|
|
34369
|
+
}
|
|
34370
|
+
const hasAcceptsEnvelope = Object.prototype.hasOwnProperty.call(
|
|
34371
|
+
body,
|
|
34372
|
+
"accepts"
|
|
34373
|
+
);
|
|
34374
|
+
if (hasAcceptsEnvelope && (body.x402Version !== 1 || body.error !== "PAYMENT_REQUIRED")) {
|
|
34375
|
+
throw new PersonalServerReadError(
|
|
34376
|
+
"Personal Server grant payment response was not a canonical x402 challenge",
|
|
34377
|
+
402
|
|
34378
|
+
);
|
|
34379
|
+
}
|
|
34380
|
+
const accept = preferredLegacyAccept(body);
|
|
34381
|
+
if (hasAcceptsEnvelope && !accept) {
|
|
34382
|
+
throw new PersonalServerReadError(
|
|
34383
|
+
"Personal Server grant payment challenge had no compatible escrow offer",
|
|
34384
|
+
402
|
|
34385
|
+
);
|
|
34386
|
+
}
|
|
34387
|
+
if (accept) {
|
|
34388
|
+
const message = asRecord2(accept.message);
|
|
34389
|
+
const network = stringField2(accept, "network");
|
|
34390
|
+
const payerAddress = stringField2(message, "payerAddress");
|
|
34391
|
+
const opId = stringField2(message, "opId");
|
|
34392
|
+
const asset = stringField2(message, "asset");
|
|
34393
|
+
const amount = stringField2(message, "amount");
|
|
34394
|
+
const paymentNonce = stringField2(message, "paymentNonce");
|
|
34395
|
+
const acceptAsset = stringField2(accept, "asset");
|
|
34396
|
+
const acceptAmount = stringField2(accept, "amount");
|
|
34397
|
+
const accessRecord2 = parseAccessRecord(accept.accessRecord);
|
|
34398
|
+
const hasAccessRecord = accept.accessRecord !== void 0;
|
|
34399
|
+
if (!network || !payerAddress || !isAddressHex(payerAddress) || !opId || !isBytes32Hex(opId) || !asset || !isAddressHex(asset) || !amount || !isUint256Decimal2(amount, true) || !paymentNonce || !isUint256Decimal2(paymentNonce, false) || !acceptAsset || acceptAsset.toLowerCase() !== asset.toLowerCase() || acceptAmount !== amount || hasAccessRecord && (!accessRecord2 || !isValidDataAccessRecord(accessRecord2) || accessRecord2.accessor.toLowerCase() !== payerAddress.toLowerCase()) || amount === "0" && !accessRecord2) {
|
|
34400
|
+
throw new PersonalServerReadError(
|
|
34401
|
+
"Personal Server grant payment challenge was untrusted or incomplete",
|
|
34402
|
+
402
|
|
34403
|
+
);
|
|
34404
|
+
}
|
|
34405
|
+
const operation2 = parseLegacyGrantOperation({
|
|
34406
|
+
challengeOpId: opId,
|
|
34407
|
+
challengeOpType: stringField2(message, "opType"),
|
|
34408
|
+
grantId
|
|
34409
|
+
});
|
|
34410
|
+
return {
|
|
34411
|
+
grantId,
|
|
34412
|
+
...operation2,
|
|
34413
|
+
network,
|
|
34414
|
+
paymentNonce,
|
|
34415
|
+
asset,
|
|
34416
|
+
amount,
|
|
34417
|
+
raw,
|
|
34418
|
+
...accessRecord2 ? { accessRecord: accessRecord2 } : {}
|
|
34419
|
+
};
|
|
34420
|
+
}
|
|
34421
|
+
const challengeGrantId = stringField2(body, "grantId");
|
|
34422
|
+
const challengeOpId = stringField2(body, "opId");
|
|
34423
|
+
const challengeOpType = stringField2(body, "opType");
|
|
34424
|
+
const accessRecord = parseAccessRecord(body.accessRecord);
|
|
34425
|
+
const operation = parseLegacyGrantOperation({
|
|
34426
|
+
challengeGrantId,
|
|
34427
|
+
challengeOpId,
|
|
34428
|
+
challengeOpType,
|
|
34429
|
+
grantId
|
|
34430
|
+
});
|
|
34431
|
+
const amountValue = stringField2(body, "amount") ?? stringField2(body, "maxAmountRequired") ?? "0";
|
|
34432
|
+
const payment = {
|
|
34433
|
+
grantId,
|
|
34434
|
+
network: stringField2(body, "network"),
|
|
34435
|
+
paymentNonce: stringField2(body, "paymentNonce"),
|
|
34436
|
+
asset: stringField2(body, "asset") ?? NATIVE_ASSET_ADDRESS,
|
|
34437
|
+
amount: amountValue,
|
|
34438
|
+
raw
|
|
34439
|
+
};
|
|
34440
|
+
return {
|
|
34441
|
+
...payment,
|
|
34442
|
+
...operation,
|
|
34443
|
+
...accessRecord ? { accessRecord } : {}
|
|
34444
|
+
};
|
|
34445
|
+
}
|
|
34446
|
+
|
|
33991
34447
|
// src/types/ps-errors.ts
|
|
33992
34448
|
var PSError = class extends Error {
|
|
33993
34449
|
constructor(code, message) {
|
|
@@ -34062,6 +34518,7 @@ export {
|
|
|
34062
34518
|
CallbackStorage,
|
|
34063
34519
|
ContractFactory,
|
|
34064
34520
|
ContractNotFoundError,
|
|
34521
|
+
DATA_ACCESS_OP_TYPE,
|
|
34065
34522
|
DATA_REGISTRY_STATUS_ABI,
|
|
34066
34523
|
DataFileEnvelopeSchema,
|
|
34067
34524
|
DataPointStatus,
|
|
@@ -34071,6 +34528,7 @@ export {
|
|
|
34071
34528
|
ExpiredTokenError,
|
|
34072
34529
|
FEE_REGISTRY_ABI,
|
|
34073
34530
|
GENERIC_PAYMENT_TYPES,
|
|
34531
|
+
GRANT_OP_TYPE,
|
|
34074
34532
|
GRANT_REGISTRATION_TYPES,
|
|
34075
34533
|
GRANT_REVOCATION_TYPES,
|
|
34076
34534
|
GoogleDriveStorage,
|
|
@@ -34116,8 +34574,12 @@ export {
|
|
|
34116
34574
|
VanaError,
|
|
34117
34575
|
VanaStorage,
|
|
34118
34576
|
assertValidPkceVerifier,
|
|
34577
|
+
authorizeEscrowPayment,
|
|
34578
|
+
authorizeGrantPayment,
|
|
34119
34579
|
buildDepositNativeRequest,
|
|
34120
34580
|
buildDepositTokenRequest,
|
|
34581
|
+
buildEscrowPaymentHeader,
|
|
34582
|
+
buildGrantPaymentHeader,
|
|
34121
34583
|
buildMarkDataPointUnavailableRequest,
|
|
34122
34584
|
buildPersonalServerDataReadRequest,
|
|
34123
34585
|
buildPersonalServerLiteOwnerBindingMessage,
|
|
@@ -34134,6 +34596,7 @@ export {
|
|
|
34134
34596
|
contractCacheForTesting,
|
|
34135
34597
|
createBrowserPlatformAdapter,
|
|
34136
34598
|
createDataFileEnvelope,
|
|
34599
|
+
createDefaultNonceSource,
|
|
34137
34600
|
createEscrowGatewayClient,
|
|
34138
34601
|
createGatewayClient,
|
|
34139
34602
|
createNodePlatformAdapter,
|
|
@@ -34178,8 +34641,11 @@ export {
|
|
|
34178
34641
|
mokshaServices,
|
|
34179
34642
|
mokshaTestnet2 as mokshaTestnet,
|
|
34180
34643
|
parsePSError,
|
|
34644
|
+
parsePersonalServerPaymentRequired,
|
|
34181
34645
|
parseScope,
|
|
34182
34646
|
parseWeb3SignedHeader,
|
|
34647
|
+
paymentReceiptFromHeader,
|
|
34648
|
+
paymentResponseMetadataFromHeader,
|
|
34183
34649
|
personalServerDataReadPath,
|
|
34184
34650
|
personalServerRegistrationDomain,
|
|
34185
34651
|
readPersonalServerData,
|
|
@@ -34193,6 +34659,8 @@ export {
|
|
|
34193
34659
|
signPersonalServerLiteOwnerBinding,
|
|
34194
34660
|
signPersonalServerLiteOwnerBindingWithAccountClient,
|
|
34195
34661
|
signPersonalServerRegistrationWithAccount,
|
|
34662
|
+
toDirectFeeBreakdown,
|
|
34663
|
+
toDirectPaymentReceipt,
|
|
34196
34664
|
vanaMainnet2 as vanaMainnet,
|
|
34197
34665
|
verifyGrantRegistration,
|
|
34198
34666
|
verifyPkceChallenge,
|