@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.cjs
CHANGED
|
@@ -1201,6 +1201,7 @@ __export(index_node_exports, {
|
|
|
1201
1201
|
InMemoryTokenStore: () => InMemoryTokenStore,
|
|
1202
1202
|
IngestResponseSchema: () => IngestResponseSchema,
|
|
1203
1203
|
InvalidConfigurationError: () => InvalidConfigurationError,
|
|
1204
|
+
InvalidScopeEntryError: () => InvalidScopeEntryError,
|
|
1204
1205
|
InvalidSignatureError: () => InvalidSignatureError,
|
|
1205
1206
|
IpfsStorage: () => IpfsStorage,
|
|
1206
1207
|
MASTER_KEY_MESSAGE: () => MASTER_KEY_MESSAGE,
|
|
@@ -1228,6 +1229,7 @@ __export(index_node_exports, {
|
|
|
1228
1229
|
REGISTRATION_KIND_FOR_OP: () => REGISTRATION_KIND_FOR_OP,
|
|
1229
1230
|
ReadOnlyError: () => ReadOnlyError,
|
|
1230
1231
|
RelayerError: () => RelayerError,
|
|
1232
|
+
SCOPE_ACTIONS: () => SCOPE_ACTIONS,
|
|
1231
1233
|
SERVER_REGISTRATION_TYPES: () => SERVER_REGISTRATION_TYPES,
|
|
1232
1234
|
ScopeSchema: () => ScopeSchema,
|
|
1233
1235
|
SerializationError: () => SerializationError,
|
|
@@ -1285,6 +1287,7 @@ __export(index_node_exports, {
|
|
|
1285
1287
|
encryptWithPassword: () => encryptWithPassword,
|
|
1286
1288
|
escrowContractAddress: () => escrowContractAddress,
|
|
1287
1289
|
escrowPaymentDomain: () => escrowPaymentDomain,
|
|
1290
|
+
formatScopeEntry: () => formatScopeEntry,
|
|
1288
1291
|
generatePkceVerifier: () => generatePkceVerifier,
|
|
1289
1292
|
genericPaymentDomain: () => genericPaymentDomain,
|
|
1290
1293
|
getAbi: () => getAbi,
|
|
@@ -1297,8 +1300,10 @@ __export(index_node_exports, {
|
|
|
1297
1300
|
getOpFee: () => getOpFee,
|
|
1298
1301
|
getPlatformCapabilities: () => getPlatformCapabilities,
|
|
1299
1302
|
getServiceEndpoints: () => getServiceEndpoints,
|
|
1303
|
+
grantPermissions: () => grantPermissions,
|
|
1300
1304
|
grantRegistrationDomain: () => grantRegistrationDomain,
|
|
1301
1305
|
grantRevocationDomain: () => grantRevocationDomain,
|
|
1306
|
+
hasAction: () => hasAction,
|
|
1302
1307
|
isDataPortabilityGatewayConfig: () => isDataPortabilityGatewayConfig,
|
|
1303
1308
|
isECIESEncrypted: () => isECIESEncrypted,
|
|
1304
1309
|
isPlatformSupported: () => isPlatformSupported,
|
|
@@ -1309,9 +1314,11 @@ __export(index_node_exports, {
|
|
|
1309
1314
|
parsePSError: () => parsePSError,
|
|
1310
1315
|
parsePersonalServerPaymentRequired: () => parsePersonalServerPaymentRequired,
|
|
1311
1316
|
parseScope: () => parseScope,
|
|
1317
|
+
parseScopeEntry: () => parseScopeEntry,
|
|
1312
1318
|
parseWeb3SignedHeader: () => parseWeb3SignedHeader,
|
|
1313
1319
|
paymentReceiptFromHeader: () => paymentReceiptFromHeader,
|
|
1314
1320
|
paymentResponseMetadataFromHeader: () => paymentResponseMetadataFromHeader,
|
|
1321
|
+
permissionsToScopes: () => permissionsToScopes,
|
|
1315
1322
|
personalServerDataReadPath: () => personalServerDataReadPath,
|
|
1316
1323
|
personalServerRegistrationDomain: () => personalServerRegistrationDomain,
|
|
1317
1324
|
readPersonalServerData: () => readPersonalServerData,
|
|
@@ -1327,6 +1334,7 @@ __export(index_node_exports, {
|
|
|
1327
1334
|
signPersonalServerRegistrationWithAccount: () => signPersonalServerRegistrationWithAccount,
|
|
1328
1335
|
toDirectFeeBreakdown: () => toDirectFeeBreakdown,
|
|
1329
1336
|
toDirectPaymentReceipt: () => toDirectPaymentReceipt,
|
|
1337
|
+
tryGrantPermissions: () => tryGrantPermissions,
|
|
1330
1338
|
vanaMainnet: () => vanaMainnet2,
|
|
1331
1339
|
verifyGrantRegistration: () => verifyGrantRegistration,
|
|
1332
1340
|
verifyPkceChallenge: () => verifyPkceChallenge,
|
|
@@ -33745,7 +33753,161 @@ function scopeCoveredByGrant(requestedScope, grantedScopes) {
|
|
|
33745
33753
|
);
|
|
33746
33754
|
}
|
|
33747
33755
|
|
|
33756
|
+
// src/protocol/scope-actions.ts
|
|
33757
|
+
var SCOPE_ACTIONS = ["read", "write"];
|
|
33758
|
+
var InvalidScopeEntryError = class extends Error {
|
|
33759
|
+
/** The offending entry, verbatim (unknown because it may not be a string). */
|
|
33760
|
+
entry;
|
|
33761
|
+
constructor(entry, reason) {
|
|
33762
|
+
super(`Invalid scope entry ${describeValue(entry)}: ${reason}`);
|
|
33763
|
+
this.name = "InvalidScopeEntryError";
|
|
33764
|
+
this.entry = entry;
|
|
33765
|
+
}
|
|
33766
|
+
};
|
|
33767
|
+
var OPERATION_SEPARATOR = ":";
|
|
33768
|
+
function describeValue(value) {
|
|
33769
|
+
if (typeof value === "string") return JSON.stringify(value);
|
|
33770
|
+
if (value === null) return "null";
|
|
33771
|
+
return `[${typeof value}]`;
|
|
33772
|
+
}
|
|
33773
|
+
var OPERATION_BY_PREFIX = {
|
|
33774
|
+
write: "write"
|
|
33775
|
+
};
|
|
33776
|
+
function assertScopePart(entry, scope) {
|
|
33777
|
+
if (scope.length === 0) {
|
|
33778
|
+
throw new InvalidScopeEntryError(entry, "scope part is empty");
|
|
33779
|
+
}
|
|
33780
|
+
if (scope.includes(OPERATION_SEPARATOR)) {
|
|
33781
|
+
throw new InvalidScopeEntryError(
|
|
33782
|
+
entry,
|
|
33783
|
+
`scope part must not contain "${OPERATION_SEPARATOR}"`
|
|
33784
|
+
);
|
|
33785
|
+
}
|
|
33786
|
+
}
|
|
33787
|
+
function parseScopeEntry(entry) {
|
|
33788
|
+
const raw = entry;
|
|
33789
|
+
if (typeof raw !== "string") {
|
|
33790
|
+
throw new InvalidScopeEntryError(raw, "entry must be a string");
|
|
33791
|
+
}
|
|
33792
|
+
const separatorIndex = entry.indexOf(OPERATION_SEPARATOR);
|
|
33793
|
+
if (separatorIndex === -1) {
|
|
33794
|
+
assertScopePart(entry, entry);
|
|
33795
|
+
return { scope: entry, action: "read" };
|
|
33796
|
+
}
|
|
33797
|
+
const prefix = entry.slice(0, separatorIndex);
|
|
33798
|
+
const scope = entry.slice(separatorIndex + 1);
|
|
33799
|
+
const action = Object.hasOwn(OPERATION_BY_PREFIX, prefix) ? OPERATION_BY_PREFIX[prefix] : void 0;
|
|
33800
|
+
if (action === void 0) {
|
|
33801
|
+
throw new InvalidScopeEntryError(
|
|
33802
|
+
entry,
|
|
33803
|
+
`unknown operation "${prefix}" (known: ${Object.keys(OPERATION_BY_PREFIX).join(", ")}; read has no prefix)`
|
|
33804
|
+
);
|
|
33805
|
+
}
|
|
33806
|
+
assertScopePart(entry, scope);
|
|
33807
|
+
return { scope, action };
|
|
33808
|
+
}
|
|
33809
|
+
function formatScopeEntry(parsed) {
|
|
33810
|
+
const { scope, action } = parsed;
|
|
33811
|
+
assertScopePart(scope, scope);
|
|
33812
|
+
if (action === "read") return scope;
|
|
33813
|
+
const prefix = Object.entries(OPERATION_BY_PREFIX).find(
|
|
33814
|
+
([, candidate]) => candidate === action
|
|
33815
|
+
)?.[0];
|
|
33816
|
+
if (prefix === void 0) {
|
|
33817
|
+
throw new InvalidScopeEntryError(
|
|
33818
|
+
scope,
|
|
33819
|
+
`unknown action ${describeValue(action)} (known: ${SCOPE_ACTIONS.join(", ")})`
|
|
33820
|
+
);
|
|
33821
|
+
}
|
|
33822
|
+
return `${prefix}${OPERATION_SEPARATOR}${scope}`;
|
|
33823
|
+
}
|
|
33824
|
+
function compareScopes(a, b) {
|
|
33825
|
+
if (a < b) return -1;
|
|
33826
|
+
if (a > b) return 1;
|
|
33827
|
+
return 0;
|
|
33828
|
+
}
|
|
33829
|
+
function sortActions(actions) {
|
|
33830
|
+
const present = new Set(actions);
|
|
33831
|
+
return SCOPE_ACTIONS.filter((action) => present.has(action));
|
|
33832
|
+
}
|
|
33833
|
+
function grantPermissions(scopes) {
|
|
33834
|
+
const byScope = /* @__PURE__ */ new Map();
|
|
33835
|
+
for (const entry of scopes) {
|
|
33836
|
+
const { scope, action } = parseScopeEntry(entry);
|
|
33837
|
+
let actions = byScope.get(scope);
|
|
33838
|
+
if (actions === void 0) {
|
|
33839
|
+
actions = /* @__PURE__ */ new Set();
|
|
33840
|
+
byScope.set(scope, actions);
|
|
33841
|
+
}
|
|
33842
|
+
actions.add(action);
|
|
33843
|
+
}
|
|
33844
|
+
return [...byScope.keys()].sort(compareScopes).map((scope) => ({
|
|
33845
|
+
scope,
|
|
33846
|
+
actions: sortActions(byScope.get(scope) ?? [])
|
|
33847
|
+
}));
|
|
33848
|
+
}
|
|
33849
|
+
function permissionsToScopes(permissions) {
|
|
33850
|
+
const byScope = /* @__PURE__ */ new Map();
|
|
33851
|
+
for (const { scope, actions } of permissions) {
|
|
33852
|
+
let merged = byScope.get(scope);
|
|
33853
|
+
if (merged === void 0) {
|
|
33854
|
+
merged = /* @__PURE__ */ new Set();
|
|
33855
|
+
byScope.set(scope, merged);
|
|
33856
|
+
}
|
|
33857
|
+
for (const action of actions) {
|
|
33858
|
+
if (!SCOPE_ACTIONS.includes(action)) {
|
|
33859
|
+
throw new InvalidScopeEntryError(
|
|
33860
|
+
scope,
|
|
33861
|
+
`unknown action ${describeValue(action)} (known: ${SCOPE_ACTIONS.join(", ")})`
|
|
33862
|
+
);
|
|
33863
|
+
}
|
|
33864
|
+
merged.add(action);
|
|
33865
|
+
}
|
|
33866
|
+
}
|
|
33867
|
+
const entries = [];
|
|
33868
|
+
for (const scope of [...byScope.keys()].sort(compareScopes)) {
|
|
33869
|
+
for (const action of sortActions(byScope.get(scope) ?? [])) {
|
|
33870
|
+
entries.push(formatScopeEntry({ scope, action }));
|
|
33871
|
+
}
|
|
33872
|
+
}
|
|
33873
|
+
return entries;
|
|
33874
|
+
}
|
|
33875
|
+
function hasAction(scopes, scope, action) {
|
|
33876
|
+
if (scope.includes(OPERATION_SEPARATOR)) return false;
|
|
33877
|
+
for (const entry of scopes) {
|
|
33878
|
+
let parsed;
|
|
33879
|
+
try {
|
|
33880
|
+
parsed = parseScopeEntry(entry);
|
|
33881
|
+
} catch (error) {
|
|
33882
|
+
if (error instanceof InvalidScopeEntryError) continue;
|
|
33883
|
+
throw error;
|
|
33884
|
+
}
|
|
33885
|
+
if (parsed.action === action && scopeMatchesPattern(scope, parsed.scope)) {
|
|
33886
|
+
return true;
|
|
33887
|
+
}
|
|
33888
|
+
}
|
|
33889
|
+
return false;
|
|
33890
|
+
}
|
|
33891
|
+
function tryGrantPermissions(scopes) {
|
|
33892
|
+
try {
|
|
33893
|
+
return grantPermissions(scopes);
|
|
33894
|
+
} catch (error) {
|
|
33895
|
+
if (error instanceof InvalidScopeEntryError) return void 0;
|
|
33896
|
+
throw error;
|
|
33897
|
+
}
|
|
33898
|
+
}
|
|
33899
|
+
|
|
33748
33900
|
// src/protocol/gateway.ts
|
|
33901
|
+
function withGrantPermissions(grant) {
|
|
33902
|
+
const stripped = { ...grant };
|
|
33903
|
+
delete stripped.permissions;
|
|
33904
|
+
const scopes = stripped.scopes;
|
|
33905
|
+
if (!Array.isArray(scopes)) {
|
|
33906
|
+
return stripped;
|
|
33907
|
+
}
|
|
33908
|
+
const permissions = tryGrantPermissions(scopes);
|
|
33909
|
+
return permissions === void 0 ? stripped : { ...stripped, permissions };
|
|
33910
|
+
}
|
|
33749
33911
|
function createGatewayClient(baseUrl) {
|
|
33750
33912
|
const base = baseUrl.replace(/\/+$/, "");
|
|
33751
33913
|
async function unwrapEnvelope(res) {
|
|
@@ -33775,7 +33937,9 @@ function createGatewayClient(baseUrl) {
|
|
|
33775
33937
|
if (!res.ok) {
|
|
33776
33938
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33777
33939
|
}
|
|
33778
|
-
return
|
|
33940
|
+
return withGrantPermissions(
|
|
33941
|
+
await unwrapEnvelope(res)
|
|
33942
|
+
);
|
|
33779
33943
|
},
|
|
33780
33944
|
async listGrantsByUser(userAddress) {
|
|
33781
33945
|
const res = await fetch(`${base}/v1/grants?user=${userAddress}`);
|
|
@@ -33783,7 +33947,8 @@ function createGatewayClient(baseUrl) {
|
|
|
33783
33947
|
if (!res.ok) {
|
|
33784
33948
|
throw new Error(`Gateway error: ${res.status} ${res.statusText}`);
|
|
33785
33949
|
}
|
|
33786
|
-
|
|
33950
|
+
const grants = await unwrapEnvelope(res);
|
|
33951
|
+
return grants.map(withGrantPermissions);
|
|
33787
33952
|
},
|
|
33788
33953
|
async getSchemaForScope(scope) {
|
|
33789
33954
|
const res = await fetch(`${base}/v1/schemas?scope=${scope}`);
|
|
@@ -34719,6 +34884,7 @@ async function parsePSError(response) {
|
|
|
34719
34884
|
InMemoryTokenStore,
|
|
34720
34885
|
IngestResponseSchema,
|
|
34721
34886
|
InvalidConfigurationError,
|
|
34887
|
+
InvalidScopeEntryError,
|
|
34722
34888
|
InvalidSignatureError,
|
|
34723
34889
|
IpfsStorage,
|
|
34724
34890
|
MASTER_KEY_MESSAGE,
|
|
@@ -34746,6 +34912,7 @@ async function parsePSError(response) {
|
|
|
34746
34912
|
REGISTRATION_KIND_FOR_OP,
|
|
34747
34913
|
ReadOnlyError,
|
|
34748
34914
|
RelayerError,
|
|
34915
|
+
SCOPE_ACTIONS,
|
|
34749
34916
|
SERVER_REGISTRATION_TYPES,
|
|
34750
34917
|
ScopeSchema,
|
|
34751
34918
|
SerializationError,
|
|
@@ -34803,6 +34970,7 @@ async function parsePSError(response) {
|
|
|
34803
34970
|
encryptWithPassword,
|
|
34804
34971
|
escrowContractAddress,
|
|
34805
34972
|
escrowPaymentDomain,
|
|
34973
|
+
formatScopeEntry,
|
|
34806
34974
|
generatePkceVerifier,
|
|
34807
34975
|
genericPaymentDomain,
|
|
34808
34976
|
getAbi,
|
|
@@ -34815,8 +34983,10 @@ async function parsePSError(response) {
|
|
|
34815
34983
|
getOpFee,
|
|
34816
34984
|
getPlatformCapabilities,
|
|
34817
34985
|
getServiceEndpoints,
|
|
34986
|
+
grantPermissions,
|
|
34818
34987
|
grantRegistrationDomain,
|
|
34819
34988
|
grantRevocationDomain,
|
|
34989
|
+
hasAction,
|
|
34820
34990
|
isDataPortabilityGatewayConfig,
|
|
34821
34991
|
isECIESEncrypted,
|
|
34822
34992
|
isPlatformSupported,
|
|
@@ -34827,9 +34997,11 @@ async function parsePSError(response) {
|
|
|
34827
34997
|
parsePSError,
|
|
34828
34998
|
parsePersonalServerPaymentRequired,
|
|
34829
34999
|
parseScope,
|
|
35000
|
+
parseScopeEntry,
|
|
34830
35001
|
parseWeb3SignedHeader,
|
|
34831
35002
|
paymentReceiptFromHeader,
|
|
34832
35003
|
paymentResponseMetadataFromHeader,
|
|
35004
|
+
permissionsToScopes,
|
|
34833
35005
|
personalServerDataReadPath,
|
|
34834
35006
|
personalServerRegistrationDomain,
|
|
34835
35007
|
readPersonalServerData,
|
|
@@ -34845,6 +35017,7 @@ async function parsePSError(response) {
|
|
|
34845
35017
|
signPersonalServerRegistrationWithAccount,
|
|
34846
35018
|
toDirectFeeBreakdown,
|
|
34847
35019
|
toDirectPaymentReceipt,
|
|
35020
|
+
tryGrantPermissions,
|
|
34848
35021
|
vanaMainnet,
|
|
34849
35022
|
verifyGrantRegistration,
|
|
34850
35023
|
verifyPkceChallenge,
|