UNPKG

@opendatalabs/vana-sdk

Version:

A TypeScript library for interacting with Vana Network smart contracts.

78 lines 2.65 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var scopes_exports = {}; __export(scopes_exports, { ScopeSchema: () => ScopeSchema, parseScope: () => parseScope, scopeCoveredByGrant: () => scopeCoveredByGrant, scopeMatchesPattern: () => scopeMatchesPattern, scopeToPathSegments: () => scopeToPathSegments }); module.exports = __toCommonJS(scopes_exports); var import_zod = require("zod"); const SEGMENT_RE = /^[a-z0-9][a-z0-9_]*$/; const ScopeSchema = import_zod.z.string().refine( (scope) => { const parts = scope.split("."); return parts.length >= 2 && parts.length <= 3 && parts.every((part) => SEGMENT_RE.test(part)); }, { message: "Scope must be {source}.{category}[.{subcategory}] with lowercase alphanumeric segments (may start with a letter or digit)" } ); function parseScope(scope) { const validated = ScopeSchema.parse(scope); const parts = validated.split("."); return { source: parts[0], category: parts[1], subcategory: parts[2], raw: validated }; } function scopeToPathSegments(scope) { const parsed = parseScope(scope); const segments = [parsed.source, parsed.category]; if (parsed.subcategory) { segments.push(parsed.subcategory); } return segments; } function scopeMatchesPattern(requestedScope, grantPattern) { if (grantPattern === "*") return true; if (grantPattern.endsWith(".*")) { const prefix = grantPattern.slice(0, -1); return requestedScope.startsWith(prefix); } return requestedScope === grantPattern; } function scopeCoveredByGrant(requestedScope, grantedScopes) { return grantedScopes.some( (pattern) => scopeMatchesPattern(requestedScope, pattern) ); } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { ScopeSchema, parseScope, scopeCoveredByGrant, scopeMatchesPattern, scopeToPathSegments }); //# sourceMappingURL=scopes.cjs.map