@opendatalabs/vana-sdk 3.14.1 → 3.16.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +52 -5
- package/dist/direct/access-request-client.cjs +31 -3
- package/dist/direct/access-request-client.cjs.map +1 -1
- package/dist/direct/access-request-client.d.ts +12 -1
- package/dist/direct/access-request-client.js +31 -3
- package/dist/direct/access-request-client.js.map +1 -1
- package/dist/direct/connect-flow.cjs +63 -6
- package/dist/direct/connect-flow.cjs.map +1 -1
- package/dist/direct/connect-flow.d.ts +30 -4
- package/dist/direct/connect-flow.js +63 -6
- package/dist/direct/connect-flow.js.map +1 -1
- package/dist/direct/controller.cjs +4 -1
- package/dist/direct/controller.cjs.map +1 -1
- package/dist/direct/controller.d.ts +11 -3
- package/dist/direct/controller.js +4 -1
- package/dist/direct/controller.js.map +1 -1
- package/dist/direct/types.cjs +28 -2
- package/dist/direct/types.cjs.map +1 -1
- package/dist/direct/types.d.ts +51 -0
- package/dist/direct/types.js +26 -1
- package/dist/direct/types.js.map +1 -1
- package/dist/direct/use-direct-vana-connect.cjs +3 -0
- package/dist/direct/use-direct-vana-connect.cjs.map +1 -1
- package/dist/direct/use-direct-vana-connect.js +3 -0
- package/dist/direct/use-direct-vana-connect.js.map +1 -1
- package/dist/direct/use-direct-vana-connect.test.d.ts +1 -0
- package/dist/index.browser.d.ts +1 -0
- package/dist/index.browser.js +167 -2
- package/dist/index.browser.js.map +3 -3
- package/dist/index.node.cjs +175 -2
- package/dist/index.node.cjs.map +3 -3
- package/dist/index.node.d.ts +2 -1
- package/dist/index.node.js +167 -2
- package/dist/index.node.js.map +3 -3
- package/dist/protocol/gateway.cjs +16 -2
- package/dist/protocol/gateway.cjs.map +1 -1
- package/dist/protocol/gateway.d.ts +2 -0
- package/dist/protocol/gateway.js +16 -2
- package/dist/protocol/gateway.js.map +1 -1
- package/dist/protocol/scope-actions.cjs +185 -0
- package/dist/protocol/scope-actions.cjs.map +1 -0
- package/dist/protocol/scope-actions.d.ts +145 -0
- package/dist/protocol/scope-actions.js +154 -0
- package/dist/protocol/scope-actions.js.map +1 -0
- package/dist/protocol/scope-actions.test.d.ts +1 -0
- package/dist/react.cjs.map +1 -1
- package/dist/react.d.ts +9 -2
- package/dist/react.js.map +1 -1
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.ts +1 -1
- package/dist/server.js.map +1 -1
- package/package.json +1 -1
package/dist/index.node.d.ts
CHANGED
|
@@ -47,10 +47,11 @@ export { escrowContractAddress, encodeDepositNativeData, encodeDepositTokenData,
|
|
|
47
47
|
export { DATA_REGISTRY_STATUS_ABI, DataPointStatus, dataRegistryContractAddress, encodeSetDataPointStatusData, buildSetDataPointStatusRequest, buildMarkDataPointUnavailableRequest, type SetDataPointStatusInput, type DataPointStatusTransactionRequest, } from "./protocol/data-point-status.js";
|
|
48
48
|
export { personalServerDataReadPath, buildPersonalServerDataReadRequest, readPersonalServerData, type BuildPersonalServerDataReadRequestParams, type ReadPersonalServerDataParams, } from "./protocol/personal-server-data.js";
|
|
49
49
|
export { ScopeSchema, parseScope, scopeToPathSegments, scopeMatchesPattern, scopeCoveredByGrant, type Scope, type ParsedScope, } from "./protocol/scopes.js";
|
|
50
|
+
export { SCOPE_ACTIONS, InvalidScopeEntryError, parseScopeEntry, formatScopeEntry, grantPermissions, permissionsToScopes, tryGrantPermissions, hasAction, type ScopeAction, type ParsedScopeEntry, type GrantPermission, } from "./protocol/scope-actions.js";
|
|
50
51
|
export { DataFileEnvelopeSchema, createDataFileEnvelope, IngestResponseSchema, type DataFileEnvelope, type IngestResponse, } from "./protocol/data-file.js";
|
|
51
52
|
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
53
|
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
54
|
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
55
|
export { parsePersonalServerPaymentRequired, type FetchResponseLike, } from "./direct/personal-server-read.js";
|
|
55
|
-
export type { DirectPaymentResponseMetadata, PersonalServerDataAccessPaymentOperation, PersonalServerGrantPaymentOperation, PersonalServerPaymentOperation, PersonalServerPaymentRequired, } from "./direct/types.js";
|
|
56
|
+
export type { ForegroundDelivery, DirectPaymentResponseMetadata, PersonalServerDataAccessPaymentOperation, PersonalServerGrantPaymentOperation, PersonalServerPaymentOperation, PersonalServerPaymentRequired, } from "./direct/types.js";
|
|
56
57
|
export { PSError, parsePSError, type PSErrorCode } from "./types/ps-errors.js";
|
package/dist/index.node.js
CHANGED
|
@@ -33574,7 +33574,161 @@ function scopeCoveredByGrant(requestedScope, grantedScopes) {
|
|
|
33574
33574
|
);
|
|
33575
33575
|
}
|
|
33576
33576
|
|
|
33577
|
+
// src/protocol/scope-actions.ts
|
|
33578
|
+
var SCOPE_ACTIONS = ["read", "write"];
|
|
33579
|
+
var InvalidScopeEntryError = class extends Error {
|
|
33580
|
+
/** The offending entry, verbatim (unknown because it may not be a string). */
|
|
33581
|
+
entry;
|
|
33582
|
+
constructor(entry, reason) {
|
|
33583
|
+
super(`Invalid scope entry ${describeValue(entry)}: ${reason}`);
|
|
33584
|
+
this.name = "InvalidScopeEntryError";
|
|
33585
|
+
this.entry = entry;
|
|
33586
|
+
}
|
|
33587
|
+
};
|
|
33588
|
+
var OPERATION_SEPARATOR = ":";
|
|
33589
|
+
function describeValue(value) {
|
|
33590
|
+
if (typeof value === "string") return JSON.stringify(value);
|
|
33591
|
+
if (value === null) return "null";
|
|
33592
|
+
return `[${typeof value}]`;
|
|
33593
|
+
}
|
|
33594
|
+
var OPERATION_BY_PREFIX = {
|
|
33595
|
+
write: "write"
|
|
33596
|
+
};
|
|
33597
|
+
function assertScopePart(entry, scope) {
|
|
33598
|
+
if (scope.length === 0) {
|
|
33599
|
+
throw new InvalidScopeEntryError(entry, "scope part is empty");
|
|
33600
|
+
}
|
|
33601
|
+
if (scope.includes(OPERATION_SEPARATOR)) {
|
|
33602
|
+
throw new InvalidScopeEntryError(
|
|
33603
|
+
entry,
|
|
33604
|
+
`scope part must not contain "${OPERATION_SEPARATOR}"`
|
|
33605
|
+
);
|
|
33606
|
+
}
|
|
33607
|
+
}
|
|
33608
|
+
function parseScopeEntry(entry) {
|
|
33609
|
+
const raw = entry;
|
|
33610
|
+
if (typeof raw !== "string") {
|
|
33611
|
+
throw new InvalidScopeEntryError(raw, "entry must be a string");
|
|
33612
|
+
}
|
|
33613
|
+
const separatorIndex = entry.indexOf(OPERATION_SEPARATOR);
|
|
33614
|
+
if (separatorIndex === -1) {
|
|
33615
|
+
assertScopePart(entry, entry);
|
|
33616
|
+
return { scope: entry, action: "read" };
|
|
33617
|
+
}
|
|
33618
|
+
const prefix = entry.slice(0, separatorIndex);
|
|
33619
|
+
const scope = entry.slice(separatorIndex + 1);
|
|
33620
|
+
const action = Object.hasOwn(OPERATION_BY_PREFIX, prefix) ? OPERATION_BY_PREFIX[prefix] : void 0;
|
|
33621
|
+
if (action === void 0) {
|
|
33622
|
+
throw new InvalidScopeEntryError(
|
|
33623
|
+
entry,
|
|
33624
|
+
`unknown operation "${prefix}" (known: ${Object.keys(OPERATION_BY_PREFIX).join(", ")}; read has no prefix)`
|
|
33625
|
+
);
|
|
33626
|
+
}
|
|
33627
|
+
assertScopePart(entry, scope);
|
|
33628
|
+
return { scope, action };
|
|
33629
|
+
}
|
|
33630
|
+
function formatScopeEntry(parsed) {
|
|
33631
|
+
const { scope, action } = parsed;
|
|
33632
|
+
assertScopePart(scope, scope);
|
|
33633
|
+
if (action === "read") return scope;
|
|
33634
|
+
const prefix = Object.entries(OPERATION_BY_PREFIX).find(
|
|
33635
|
+
([, candidate]) => candidate === action
|
|
33636
|
+
)?.[0];
|
|
33637
|
+
if (prefix === void 0) {
|
|
33638
|
+
throw new InvalidScopeEntryError(
|
|
33639
|
+
scope,
|
|
33640
|
+
`unknown action ${describeValue(action)} (known: ${SCOPE_ACTIONS.join(", ")})`
|
|
33641
|
+
);
|
|
33642
|
+
}
|
|
33643
|
+
return `${prefix}${OPERATION_SEPARATOR}${scope}`;
|
|
33644
|
+
}
|
|
33645
|
+
function compareScopes(a, b) {
|
|
33646
|
+
if (a < b) return -1;
|
|
33647
|
+
if (a > b) return 1;
|
|
33648
|
+
return 0;
|
|
33649
|
+
}
|
|
33650
|
+
function sortActions(actions) {
|
|
33651
|
+
const present = new Set(actions);
|
|
33652
|
+
return SCOPE_ACTIONS.filter((action) => present.has(action));
|
|
33653
|
+
}
|
|
33654
|
+
function grantPermissions(scopes) {
|
|
33655
|
+
const byScope = /* @__PURE__ */ new Map();
|
|
33656
|
+
for (const entry of scopes) {
|
|
33657
|
+
const { scope, action } = parseScopeEntry(entry);
|
|
33658
|
+
let actions = byScope.get(scope);
|
|
33659
|
+
if (actions === void 0) {
|
|
33660
|
+
actions = /* @__PURE__ */ new Set();
|
|
33661
|
+
byScope.set(scope, actions);
|
|
33662
|
+
}
|
|
33663
|
+
actions.add(action);
|
|
33664
|
+
}
|
|
33665
|
+
return [...byScope.keys()].sort(compareScopes).map((scope) => ({
|
|
33666
|
+
scope,
|
|
33667
|
+
actions: sortActions(byScope.get(scope) ?? [])
|
|
33668
|
+
}));
|
|
33669
|
+
}
|
|
33670
|
+
function permissionsToScopes(permissions) {
|
|
33671
|
+
const byScope = /* @__PURE__ */ new Map();
|
|
33672
|
+
for (const { scope, actions } of permissions) {
|
|
33673
|
+
let merged = byScope.get(scope);
|
|
33674
|
+
if (merged === void 0) {
|
|
33675
|
+
merged = /* @__PURE__ */ new Set();
|
|
33676
|
+
byScope.set(scope, merged);
|
|
33677
|
+
}
|
|
33678
|
+
for (const action of actions) {
|
|
33679
|
+
if (!SCOPE_ACTIONS.includes(action)) {
|
|
33680
|
+
throw new InvalidScopeEntryError(
|
|
33681
|
+
scope,
|
|
33682
|
+
`unknown action ${describeValue(action)} (known: ${SCOPE_ACTIONS.join(", ")})`
|
|
33683
|
+
);
|
|
33684
|
+
}
|
|
33685
|
+
merged.add(action);
|
|
33686
|
+
}
|
|
33687
|
+
}
|
|
33688
|
+
const entries = [];
|
|
33689
|
+
for (const scope of [...byScope.keys()].sort(compareScopes)) {
|
|
33690
|
+
for (const action of sortActions(byScope.get(scope) ?? [])) {
|
|
33691
|
+
entries.push(formatScopeEntry({ scope, action }));
|
|
33692
|
+
}
|
|
33693
|
+
}
|
|
33694
|
+
return entries;
|
|
33695
|
+
}
|
|
33696
|
+
function hasAction(scopes, scope, action) {
|
|
33697
|
+
if (scope.includes(OPERATION_SEPARATOR)) return false;
|
|
33698
|
+
for (const entry of scopes) {
|
|
33699
|
+
let parsed;
|
|
33700
|
+
try {
|
|
33701
|
+
parsed = parseScopeEntry(entry);
|
|
33702
|
+
} catch (error) {
|
|
33703
|
+
if (error instanceof InvalidScopeEntryError) continue;
|
|
33704
|
+
throw error;
|
|
33705
|
+
}
|
|
33706
|
+
if (parsed.action === action && scopeMatchesPattern(scope, parsed.scope)) {
|
|
33707
|
+
return true;
|
|
33708
|
+
}
|
|
33709
|
+
}
|
|
33710
|
+
return false;
|
|
33711
|
+
}
|
|
33712
|
+
function tryGrantPermissions(scopes) {
|
|
33713
|
+
try {
|
|
33714
|
+
return grantPermissions(scopes);
|
|
33715
|
+
} catch (error) {
|
|
33716
|
+
if (error instanceof InvalidScopeEntryError) return void 0;
|
|
33717
|
+
throw error;
|
|
33718
|
+
}
|
|
33719
|
+
}
|
|
33720
|
+
|
|
33577
33721
|
// src/protocol/gateway.ts
|
|
33722
|
+
function withGrantPermissions(grant) {
|
|
33723
|
+
const stripped = { ...grant };
|
|
33724
|
+
delete stripped.permissions;
|
|
33725
|
+
const scopes = stripped.scopes;
|
|
33726
|
+
if (!Array.isArray(scopes)) {
|
|
33727
|
+
return stripped;
|
|
33728
|
+
}
|
|
33729
|
+
const permissions = tryGrantPermissions(scopes);
|
|
33730
|
+
return permissions === void 0 ? stripped : { ...stripped, permissions };
|
|
33731
|
+
}
|
|
33578
33732
|
function createGatewayClient(baseUrl) {
|
|
33579
33733
|
const base = baseUrl.replace(/\/+$/, "");
|
|
33580
33734
|
async function unwrapEnvelope(res) {
|
|
@@ -33604,7 +33758,9 @@ function createGatewayClient(baseUrl) {
|
|
|
33604
33758
|
if (!res.ok) {
|
|
33605
33759
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33606
33760
|
}
|
|
33607
|
-
return
|
|
33761
|
+
return withGrantPermissions(
|
|
33762
|
+
await unwrapEnvelope(res)
|
|
33763
|
+
);
|
|
33608
33764
|
},
|
|
33609
33765
|
async listGrantsByUser(userAddress) {
|
|
33610
33766
|
const res = await fetch(`${base}/v1/grants?user=${userAddress}`);
|
|
@@ -33612,7 +33768,8 @@ function createGatewayClient(baseUrl) {
|
|
|
33612
33768
|
if (!res.ok) {
|
|
33613
33769
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33614
33770
|
}
|
|
33615
|
-
|
|
33771
|
+
const grants = await unwrapEnvelope(res);
|
|
33772
|
+
return grants.map(withGrantPermissions);
|
|
33616
33773
|
},
|
|
33617
33774
|
async getSchemaForScope(scope) {
|
|
33618
33775
|
const res = await fetch(`${base}/v1/schemas?scope=${scope}`);
|
|
@@ -34547,6 +34704,7 @@ export {
|
|
|
34547
34704
|
InMemoryTokenStore,
|
|
34548
34705
|
IngestResponseSchema,
|
|
34549
34706
|
InvalidConfigurationError,
|
|
34707
|
+
InvalidScopeEntryError,
|
|
34550
34708
|
InvalidSignatureError,
|
|
34551
34709
|
IpfsStorage,
|
|
34552
34710
|
MASTER_KEY_MESSAGE,
|
|
@@ -34574,6 +34732,7 @@ export {
|
|
|
34574
34732
|
REGISTRATION_KIND_FOR_OP,
|
|
34575
34733
|
ReadOnlyError,
|
|
34576
34734
|
RelayerError,
|
|
34735
|
+
SCOPE_ACTIONS,
|
|
34577
34736
|
SERVER_REGISTRATION_TYPES,
|
|
34578
34737
|
ScopeSchema,
|
|
34579
34738
|
SerializationError,
|
|
@@ -34631,6 +34790,7 @@ export {
|
|
|
34631
34790
|
encryptWithPassword,
|
|
34632
34791
|
escrowContractAddress,
|
|
34633
34792
|
escrowPaymentDomain,
|
|
34793
|
+
formatScopeEntry,
|
|
34634
34794
|
generatePkceVerifier,
|
|
34635
34795
|
genericPaymentDomain,
|
|
34636
34796
|
getAbi,
|
|
@@ -34643,8 +34803,10 @@ export {
|
|
|
34643
34803
|
getOpFee,
|
|
34644
34804
|
getPlatformCapabilities,
|
|
34645
34805
|
getServiceEndpoints,
|
|
34806
|
+
grantPermissions,
|
|
34646
34807
|
grantRegistrationDomain,
|
|
34647
34808
|
grantRevocationDomain,
|
|
34809
|
+
hasAction,
|
|
34648
34810
|
isDataPortabilityGatewayConfig,
|
|
34649
34811
|
isECIESEncrypted,
|
|
34650
34812
|
isPlatformSupported,
|
|
@@ -34655,9 +34817,11 @@ export {
|
|
|
34655
34817
|
parsePSError,
|
|
34656
34818
|
parsePersonalServerPaymentRequired,
|
|
34657
34819
|
parseScope,
|
|
34820
|
+
parseScopeEntry,
|
|
34658
34821
|
parseWeb3SignedHeader,
|
|
34659
34822
|
paymentReceiptFromHeader,
|
|
34660
34823
|
paymentResponseMetadataFromHeader,
|
|
34824
|
+
permissionsToScopes,
|
|
34661
34825
|
personalServerDataReadPath,
|
|
34662
34826
|
personalServerRegistrationDomain,
|
|
34663
34827
|
readPersonalServerData,
|
|
@@ -34673,6 +34837,7 @@ export {
|
|
|
34673
34837
|
signPersonalServerRegistrationWithAccount,
|
|
34674
34838
|
toDirectFeeBreakdown,
|
|
34675
34839
|
toDirectPaymentReceipt,
|
|
34840
|
+
tryGrantPermissions,
|
|
34676
34841
|
vanaMainnet2 as vanaMainnet,
|
|
34677
34842
|
verifyGrantRegistration,
|
|
34678
34843
|
verifyPkceChallenge,
|