@agenticprimitives/vault-authority 0.0.0-alpha.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Agentic Trust Labs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,80 @@
1
+ # @agenticprimitives/vault-authority
2
+
3
+ Pure helpers for authority over vault-resident subjects.
4
+
5
+ This package bridges three existing primitives:
6
+
7
+ - `RoleAssignment` from `@agenticprimitives/organization`
8
+ - `VaultRecordScopeGrant` from `@agenticprimitives/delegation`
9
+ - owner-vault resource naming from `@agenticprimitives/vault`
10
+
11
+ It does not persist, sign, read chain state, call MCP/A2A, or verify entitlements. Callers pass already
12
+ verified facts into deterministic helpers.
13
+
14
+ ## What It Owns
15
+
16
+ - subject refs: the thing a vault role is about
17
+ - role definitions: capabilities plus vault-record-scope grant templates
18
+ - grant compilation: role definition + subject -> `VaultRecordScopeGrant[]`
19
+ - projection: role assignment + definition -> app-readable grant view
20
+ - authorization: active assignment + materializing authority + record scope -> allow/deny
21
+
22
+ ## Core Rule
23
+
24
+ RoleAssignment manages domain-subject responsibility. Delegation/caveats execute authority. Entitlements
25
+ prove access.
26
+
27
+ A role with no valid materializing authority authorizes nothing.
28
+
29
+ ## Minimal Example
30
+
31
+ ```ts
32
+ import {
33
+ authorizeVaultSubjectOperation,
34
+ compileVaultRecordScopeGrants,
35
+ type VaultAuthorityRoleDefinition,
36
+ } from '@agenticprimitives/vault-authority';
37
+
38
+ const definition: VaultAuthorityRoleDefinition = {
39
+ roleDefinitionId: 'roledef:example.manager@1',
40
+ name: 'manager',
41
+ version: '1',
42
+ allowedScopes: ['resource'],
43
+ capabilities: ['example.manage'],
44
+ grantTemplates: [
45
+ {
46
+ server: 'example-vault',
47
+ resources: ['vault:example.subject:{scopeRef}:*'],
48
+ ops: ['read', 'write'],
49
+ },
50
+ ],
51
+ };
52
+
53
+ const subject = {
54
+ vaultOwner: '0x0000000000000000000000000000000000000001',
55
+ scope: 'resource' as const,
56
+ scopeRef: 'subject:123',
57
+ };
58
+
59
+ const recordScopes = compileVaultRecordScopeGrants({ definition, subject });
60
+
61
+ const decision = authorizeVaultSubjectOperation({
62
+ assignment,
63
+ definition,
64
+ subject,
65
+ hasMaterializingAuthority: true,
66
+ recordScopes,
67
+ request: {
68
+ server: 'example-vault',
69
+ resource: 'vault:example.subject:subject:123:title',
70
+ op: 'write',
71
+ },
72
+ });
73
+ ```
74
+
75
+ ## Privacy
76
+
77
+ The package never creates a public registry of who manages which subject. Assignments, wires, and
78
+ entitlements live off-chain in vault/Home/runtime stores. Chain state remains hash/signature/revocation
79
+ verification.
80
+
@@ -0,0 +1,9 @@
1
+ import type { RoleAssignmentBody } from '@agenticprimitives/organization';
2
+ import type { AuthorizeVaultSubjectOperationInput, ProjectVaultSubjectRolePartsInput, ProjectVaultSubjectRoleInput, VaultAuthorityRoleDefinition, VaultSubjectAuthorityDecision, VaultSubjectRef, VaultSubjectRoleGrant } from './types.js';
3
+ export declare function isActiveVaultSubjectRole(assignment: RoleAssignmentBody | null, at?: string): boolean;
4
+ export declare function assignmentMatchesDefinition(assignment: RoleAssignmentBody, definition: VaultAuthorityRoleDefinition): boolean;
5
+ export declare function assignmentMatchesSubject(assignment: RoleAssignmentBody, subject: VaultSubjectRef): boolean;
6
+ export declare function projectVaultSubjectRoleGrant(input: ProjectVaultSubjectRoleInput): VaultSubjectRoleGrant;
7
+ export declare function projectVaultSubjectRoleGrantFromParts(input: ProjectVaultSubjectRolePartsInput): VaultSubjectRoleGrant;
8
+ export declare function authorizeVaultSubjectOperation(input: AuthorizeVaultSubjectOperationInput): VaultSubjectAuthorityDecision;
9
+ //# sourceMappingURL=authority.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authority.d.ts","sourceRoot":"","sources":["../src/authority.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAE1E,OAAO,KAAK,EACV,mCAAmC,EACnC,iCAAiC,EACjC,4BAA4B,EAC5B,4BAA4B,EAC5B,6BAA6B,EAC7B,eAAe,EACf,qBAAqB,EACtB,MAAM,YAAY,CAAC;AAEpB,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,kBAAkB,GAAG,IAAI,EAAE,EAAE,SAA2B,GAAG,OAAO,CAOtH;AAED,wBAAgB,2BAA2B,CACzC,UAAU,EAAE,kBAAkB,EAC9B,UAAU,EAAE,4BAA4B,GACvC,OAAO,CAET;AAED,wBAAgB,wBAAwB,CAAC,UAAU,EAAE,kBAAkB,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAK1G;AAED,wBAAgB,4BAA4B,CAAC,KAAK,EAAE,4BAA4B,GAAG,qBAAqB,CAYvG;AAED,wBAAgB,qCAAqC,CAAC,KAAK,EAAE,iCAAiC,GAAG,qBAAqB,CAYrH;AAED,wBAAgB,8BAA8B,CAAC,KAAK,EAAE,mCAAmC,GAAG,6BAA6B,CAkBxH"}
@@ -0,0 +1,68 @@
1
+ import { vaultRecordScopeAllows } from '@agenticprimitives/delegation';
2
+ export function isActiveVaultSubjectRole(assignment, at = new Date().toISOString()) {
3
+ if (!assignment)
4
+ return false;
5
+ return (assignment.status === 'active' &&
6
+ assignment.validFrom <= at &&
7
+ (assignment.validUntil == null || at < assignment.validUntil));
8
+ }
9
+ export function assignmentMatchesDefinition(assignment, definition) {
10
+ return assignment.roleDefinitionId === definition.roleDefinitionId;
11
+ }
12
+ export function assignmentMatchesSubject(assignment, subject) {
13
+ if (assignment.scope !== subject.scope)
14
+ return false;
15
+ const assignmentRef = assignment.scopeRef ?? null;
16
+ if (assignment.scope === 'organization')
17
+ return assignmentRef == null && subject.scopeRef == null;
18
+ return assignmentRef != null && assignmentRef === subject.scopeRef;
19
+ }
20
+ export function projectVaultSubjectRoleGrant(input) {
21
+ return projectVaultSubjectRoleGrantFromParts({
22
+ assignee: input.assignee,
23
+ roleDefinitionId: input.definition.roleDefinitionId,
24
+ roleName: input.definition.name,
25
+ scope: input.assignment.scope,
26
+ scopeRef: input.assignment.scopeRef ?? null,
27
+ status: input.assignment.status,
28
+ capabilities: [...input.definition.capabilities],
29
+ authorityRefs: [...(input.assignment.authorityRefs ?? [])],
30
+ entitlementRefs: [...(input.assignment.entitlementRefs ?? [])],
31
+ });
32
+ }
33
+ export function projectVaultSubjectRoleGrantFromParts(input) {
34
+ return {
35
+ subject: input.assignee,
36
+ roleDefinitionId: input.roleDefinitionId,
37
+ roleName: input.roleName,
38
+ scope: input.scope,
39
+ scopeRef: input.scopeRef,
40
+ status: input.status,
41
+ capabilities: [...input.capabilities],
42
+ authorityRefs: [...(input.authorityRefs ?? [])],
43
+ entitlementRefs: [...(input.entitlementRefs ?? [])],
44
+ };
45
+ }
46
+ export function authorizeVaultSubjectOperation(input) {
47
+ const assignment = input.assignment;
48
+ if (!assignment)
49
+ return { decision: 'deny', reason: 'missing-assignment' };
50
+ if (!isActiveVaultSubjectRole(assignment, input.at))
51
+ return { decision: 'deny', reason: 'inactive-assignment' };
52
+ if (!assignmentMatchesDefinition(assignment, input.definition)) {
53
+ return { decision: 'deny', reason: 'role-definition-mismatch' };
54
+ }
55
+ if (!input.definition.allowedScopes.includes(input.subject.scope)) {
56
+ return { decision: 'deny', reason: 'scope-not-allowed' };
57
+ }
58
+ if (!assignmentMatchesSubject(assignment, input.subject))
59
+ return { decision: 'deny', reason: 'subject-mismatch' };
60
+ if (!input.hasMaterializingAuthority) {
61
+ return { decision: 'deny', reason: 'missing-materializing-authority' };
62
+ }
63
+ if (!vaultRecordScopeAllows(input.recordScopes ? [...input.recordScopes] : undefined, input.request)) {
64
+ return { decision: 'deny', reason: 'record-scope-denied' };
65
+ }
66
+ return { decision: 'allow' };
67
+ }
68
+ //# sourceMappingURL=authority.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authority.js","sourceRoot":"","sources":["../src/authority.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,+BAA+B,CAAC;AAavE,MAAM,UAAU,wBAAwB,CAAC,UAAqC,EAAE,EAAE,GAAG,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE;IAC3G,IAAI,CAAC,UAAU;QAAE,OAAO,KAAK,CAAC;IAC9B,OAAO,CACL,UAAU,CAAC,MAAM,KAAK,QAAQ;QAC9B,UAAU,CAAC,SAAS,IAAI,EAAE;QAC1B,CAAC,UAAU,CAAC,UAAU,IAAI,IAAI,IAAI,EAAE,GAAG,UAAU,CAAC,UAAU,CAAC,CAC9D,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,2BAA2B,CACzC,UAA8B,EAC9B,UAAwC;IAExC,OAAO,UAAU,CAAC,gBAAgB,KAAK,UAAU,CAAC,gBAAgB,CAAC;AACrE,CAAC;AAED,MAAM,UAAU,wBAAwB,CAAC,UAA8B,EAA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AAE,iCAAiC,EAAE,CAAC;IACzE,CAAC;IACD,IAAI,CAAC,sBAAsB,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,SAAS,EAAE,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC;QACrG,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,EAAE,qBAAqB,EAAE,CAAC;IAC7D,CAAC;IACD,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC;AAC/B,CAAC"}
@@ -0,0 +1,7 @@
1
+ export declare const PACKAGE_NAME = "@agenticprimitives/vault-authority";
2
+ export declare const PACKAGE_STATUS: "w1-subject-authority";
3
+ export declare const SPEC_REF = "specs/343-vault-subject-authority.md";
4
+ export type { AuthorizeVaultSubjectOperationInput, CompileVaultRecordScopeInput, ProjectVaultSubjectRolePartsInput, ProjectVaultSubjectRoleInput, RoleAssignmentStatus, RoleScopeKind, VaultAuthorityOperation, VaultAuthorityRoleDefinition, VaultRecordScopeTemplate, VaultSubjectAuthorityDecision, VaultSubjectAuthorityDenyReason, VaultSubjectOperationRequest, VaultSubjectRef, VaultSubjectRoleGrant, } from './types.js';
5
+ export { compileVaultRecordScopeGrants } from './templates.js';
6
+ export { assignmentMatchesDefinition, assignmentMatchesSubject, authorizeVaultSubjectOperation, isActiveVaultSubjectRole, projectVaultSubjectRoleGrantFromParts, projectVaultSubjectRoleGrant, } from './authority.js';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,YAAY,uCAAuC,CAAC;AACjE,eAAO,MAAM,cAAc,EAAG,sBAA+B,CAAC;AAC9D,eAAO,MAAM,QAAQ,yCAAyC,CAAC;AAE/D,YAAY,EACV,mCAAmC,EACnC,4BAA4B,EAC5B,iCAAiC,EACjC,4BAA4B,EAC5B,oBAAoB,EACpB,aAAa,EACb,uBAAuB,EACvB,4BAA4B,EAC5B,wBAAwB,EACxB,6BAA6B,EAC7B,+BAA+B,EAC/B,4BAA4B,EAC5B,eAAe,EACf,qBAAqB,GACtB,MAAM,YAAY,CAAC;AAEpB,OAAO,EAAE,6BAA6B,EAAE,MAAM,gBAAgB,CAAC;AAE/D,OAAO,EACL,2BAA2B,EAC3B,wBAAwB,EACxB,8BAA8B,EAC9B,wBAAwB,EACxB,qCAAqC,EACrC,4BAA4B,GAC7B,MAAM,gBAAgB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ // @agenticprimitives/vault-authority — role-gated authority over vault-resident subjects.
2
+ export const PACKAGE_NAME = '@agenticprimitives/vault-authority';
3
+ export const PACKAGE_STATUS = 'w1-subject-authority';
4
+ export const SPEC_REF = 'specs/343-vault-subject-authority.md';
5
+ export { compileVaultRecordScopeGrants } from './templates.js';
6
+ export { assignmentMatchesDefinition, assignmentMatchesSubject, authorizeVaultSubjectOperation, isActiveVaultSubjectRole, projectVaultSubjectRoleGrantFromParts, projectVaultSubjectRoleGrant, } from './authority.js';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,0FAA0F;AAE1F,MAAM,CAAC,MAAM,YAAY,GAAG,oCAAoC,CAAC;AACjE,MAAM,CAAC,MAAM,cAAc,GAAG,sBAA+B,CAAC;AAC9D,MAAM,CAAC,MAAM,QAAQ,GAAG,sCAAsC,CAAC;AAmB/D,OAAO,EAAE,6BAA6B,EAAE,MAAM,gBAAgB,CAAC;AAE/D,OAAO,EACL,2BAA2B,EAC3B,wBAAwB,EACxB,8BAA8B,EAC9B,wBAAwB,EACxB,qCAAqC,EACrC,4BAA4B,GAC7B,MAAM,gBAAgB,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { VaultRecordScopeGrant } from '@agenticprimitives/delegation';
2
+ import type { CompileVaultRecordScopeInput } from './types.js';
3
+ export declare function compileVaultRecordScopeGrants(input: CompileVaultRecordScopeInput): VaultRecordScopeGrant[];
4
+ //# sourceMappingURL=templates.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"templates.d.ts","sourceRoot":"","sources":["../src/templates.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAE3E,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,YAAY,CAAC;AAoC/D,wBAAgB,6BAA6B,CAAC,KAAK,EAAE,4BAA4B,GAAG,qBAAqB,EAAE,CAmB1G"}
@@ -0,0 +1,56 @@
1
+ const PLACEHOLDER = /\{([A-Za-z0-9_]+)\}/g;
2
+ const HAS_PLACEHOLDER = /\{[A-Za-z0-9_]+\}/;
3
+ function values(input) {
4
+ return {
5
+ vaultOwner: input.subject.vaultOwner,
6
+ scope: input.subject.scope,
7
+ scopeRef: input.subject.scopeRef ?? '',
8
+ roleDefinitionId: input.definition.roleDefinitionId,
9
+ };
10
+ }
11
+ function expand(template, input) {
12
+ const v = values(input);
13
+ return template.replace(PLACEHOLDER, (_match, key) => {
14
+ const value = v[key];
15
+ if (value === undefined)
16
+ throw new Error(`unknown vault-authority template placeholder {${key}}`);
17
+ if (!value)
18
+ throw new Error(`empty vault-authority template placeholder {${key}}`);
19
+ return value;
20
+ });
21
+ }
22
+ function assertSafeResource(resource) {
23
+ if (!resource.startsWith('vault:')) {
24
+ throw new Error(`vault authority resource "${resource}" must be vault:-prefixed`);
25
+ }
26
+ if (resource === 'vault:' || resource === 'vault:*') {
27
+ throw new Error(`vault authority resource "${resource}" is too broad`);
28
+ }
29
+ if (HAS_PLACEHOLDER.test(resource)) {
30
+ throw new Error(`vault authority resource "${resource}" still contains a placeholder`);
31
+ }
32
+ }
33
+ export function compileVaultRecordScopeGrants(input) {
34
+ if (!input.definition.allowedScopes.includes(input.subject.scope)) {
35
+ throw new Error(`role ${input.definition.roleDefinitionId} is not assignable at ${input.subject.scope} scope`);
36
+ }
37
+ return input.definition.grantTemplates.map((template) => {
38
+ if (!template.server)
39
+ throw new Error('vault authority grant template requires server');
40
+ if (template.resources.length === 0)
41
+ throw new Error('vault authority grant template requires resources');
42
+ if (template.ops.length === 0)
43
+ throw new Error('vault authority grant template requires ops');
44
+ const resources = template.resources.map((r) => {
45
+ const resource = expand(r, input);
46
+ assertSafeResource(resource);
47
+ return resource;
48
+ });
49
+ return {
50
+ server: template.server,
51
+ resources,
52
+ ops: [...template.ops],
53
+ };
54
+ });
55
+ }
56
+ //# sourceMappingURL=templates.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"templates.js","sourceRoot":"","sources":["../src/templates.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW,GAAG,sBAAsB,CAAC;AAC3C,MAAM,eAAe,GAAG,mBAAmB,CAAC;AAE5C,SAAS,MAAM,CAAC,KAAmC;IACjD,OAAO;QACL,UAAU,EAAE,KAAK,CAAC,OAAO,CAAC,UAAU;QACpC,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC,KAAK;QAC1B,QAAQ,EAAE,KAAK,CAAC,OAAO,CAAC,QAAQ,IAAI,EAAE;QACtC,gBAAgB,EAAE,KAAK,CAAC,UAAU,CAAC,gBAAgB;KACpD,CAAC;AACJ,CAAC;AAED,SAAS,MAAM,CAAC,QAAgB,EAAE,KAAmC;IACnE,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IACxB,OAAO,QAAQ,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,MAAM,EAAE,GAAW,EAAE,EAAE;QAC3D,MAAM,KAAK,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;QACrB,IAAI,KAAK,KAAK,SAAS;YAAE,MAAM,IAAI,KAAK,CAAC,iDAAiD,GAAG,GAAG,CAAC,CAAC;QAClG,IAAI,CAAC,KAAK;YAAE,MAAM,IAAI,KAAK,CAAC,+CAA+C,G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AAC;QAC9F,MAAM,SAAS,GAAG,QAAQ,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;YAC7C,MAAM,QAAQ,GAAG,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;YAClC,kBAAkB,CAAC,QAAQ,CAAC,CAAC;YAC7B,OAAO,QAAQ,CAAC;QAClB,CAAC,CAAC,CAAC;QACH,OAAO;YACL,MAAM,EAAE,QAAQ,CAAC,MAAM;YACvB,SAAS;YACT,GAAG,EAAE,CAAC,GAAG,QAAQ,CAAC,GAAG,CAAC;SACvB,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,96 @@
1
+ import type { VaultRecordScopeGrant } from '@agenticprimitives/delegation';
2
+ import type { RoleAssignmentBody, RoleAssignmentStatus, RoleScopeKind } from '@agenticprimitives/organization';
3
+ import type { Address } from '@agenticprimitives/types';
4
+ export type { RoleAssignmentStatus, RoleScopeKind };
5
+ export type VaultAuthorityOperation = 'read' | 'write' | 'delete';
6
+ /**
7
+ * A vault-resident subject. The subject is not an agent and never delegates; it is the thing a
8
+ * RoleAssignment is about.
9
+ */
10
+ export interface VaultSubjectRef {
11
+ readonly vaultOwner: Address;
12
+ readonly scope: RoleScopeKind;
13
+ readonly scopeRef: string | null;
14
+ readonly subjectType?: string;
15
+ }
16
+ /**
17
+ * A `VaultRecordScopeGrant` template. Resources are `vault:`-prefixed strings with a small, fixed
18
+ * placeholder vocabulary expanded by `compileVaultRecordScopeGrants`.
19
+ */
20
+ export interface VaultRecordScopeTemplate {
21
+ readonly server: string;
22
+ readonly resources: readonly string[];
23
+ readonly ops: readonly VaultAuthorityOperation[];
24
+ }
25
+ /**
26
+ * Generic role definition for authority over vault-resident subjects.
27
+ *
28
+ * `capabilities` are projection labels for product UX. The executable authority is materialized by
29
+ * expanding `grantTemplates` into delegation caveats.
30
+ */
31
+ export interface VaultAuthorityRoleDefinition {
32
+ readonly roleDefinitionId: string;
33
+ readonly name: string;
34
+ readonly version: string;
35
+ readonly allowedScopes: readonly RoleScopeKind[];
36
+ readonly capabilities: readonly string[];
37
+ readonly grantTemplates: readonly VaultRecordScopeTemplate[];
38
+ readonly entitlementTemplateRefs?: readonly string[];
39
+ }
40
+ export interface VaultSubjectRoleGrant {
41
+ readonly subject: Address;
42
+ readonly roleDefinitionId: string;
43
+ readonly roleName: string;
44
+ readonly scope: RoleScopeKind;
45
+ readonly scopeRef: string | null;
46
+ readonly status: RoleAssignmentStatus;
47
+ readonly capabilities: readonly string[];
48
+ readonly authorityRefs: readonly string[];
49
+ readonly entitlementRefs: readonly string[];
50
+ }
51
+ export interface CompileVaultRecordScopeInput {
52
+ readonly definition: VaultAuthorityRoleDefinition;
53
+ readonly subject: VaultSubjectRef;
54
+ }
55
+ export interface ProjectVaultSubjectRoleInput {
56
+ readonly assignment: RoleAssignmentBody;
57
+ readonly assignee: Address;
58
+ readonly definition: VaultAuthorityRoleDefinition;
59
+ }
60
+ export interface ProjectVaultSubjectRolePartsInput {
61
+ readonly assignee: Address;
62
+ readonly roleDefinitionId: string;
63
+ readonly roleName: string;
64
+ readonly scope: RoleScopeKind;
65
+ readonly scopeRef: string | null;
66
+ readonly status: RoleAssignmentStatus;
67
+ readonly capabilities: readonly string[];
68
+ readonly authorityRefs?: readonly string[];
69
+ readonly entitlementRefs?: readonly string[];
70
+ }
71
+ export interface VaultSubjectOperationRequest {
72
+ readonly server: string;
73
+ readonly resource: string;
74
+ readonly op: VaultAuthorityOperation;
75
+ }
76
+ export interface AuthorizeVaultSubjectOperationInput {
77
+ readonly assignment: RoleAssignmentBody | null;
78
+ readonly definition: VaultAuthorityRoleDefinition;
79
+ readonly subject: VaultSubjectRef;
80
+ /**
81
+ * True only after the caller has verified the assignment's materializing delegation/entitlement.
82
+ * This package never verifies signatures or chain state.
83
+ */
84
+ readonly hasMaterializingAuthority: boolean;
85
+ readonly recordScopes?: readonly VaultRecordScopeGrant[];
86
+ readonly request: VaultSubjectOperationRequest;
87
+ readonly at?: string;
88
+ }
89
+ export type VaultSubjectAuthorityDenyReason = 'missing-assignment' | 'inactive-assignment' | 'role-definition-mismatch' | 'scope-not-allowed' | 'subject-mismatch' | 'missing-materializing-authority' | 'record-scope-denied';
90
+ export type VaultSubjectAuthorityDecision = {
91
+ readonly decision: 'allow';
92
+ } | {
93
+ readonly decision: 'deny';
94
+ readonly reason: VaultSubjectAuthorityDenyReason;
95
+ };
96
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAC3E,OAAO,KAAK,EAAE,kBAAkB,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAC/G,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,0BAA0B,CAAC;AAExD,YAAY,EAAE,oBAAoB,EAAE,aAAa,EAAE,CAAC;AAEpD,MAAM,MAAM,uBAAuB,GAAG,MAAM,GAAG,OAAO,GAAG,QAAQ,CAAC;AAElE;;;GAGG;AACH,MAAM,WAAW,eAAe;IAC9B,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;IAC9B,QAAQ,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,QAAQ,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC;CAC/B;AAED;;;GAGG;AACH,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;IACtC,QAAQ,CAAC,GAAG,EAAE,SAAS,uBAAuB,EAAE,CAAC;CAClD;AAED;;;;;GAKG;AACH,MAAM,WAAW,4BAA4B;IAC3C,QAAQ,CAAC,gBAAgB,EAAE,MAAM,C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AE,+BAA+B,CAAA;CAAE,CAAC"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@agenticprimitives/vault-authority",
3
+ "version": "0.0.0-alpha.1",
4
+ "description": "Vault subject authority primitives: role assignments scoped to vault-resident subjects, vault-record-scope grant compilation, and pure runtime decisions.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/agentictrustlabs/agenticprimitives.git",
9
+ "directory": "packages/vault-authority"
10
+ },
11
+ "homepage": "https://github.com/agentictrustlabs/agenticprimitives/tree/master/packages/vault-authority",
12
+ "bugs": {
13
+ "url": "https://github.com/agentictrustlabs/agenticprimitives/issues"
14
+ },
15
+ "type": "module",
16
+ "main": "./dist/index.js",
17
+ "types": "./dist/index.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./dist/index.d.ts",
21
+ "import": "./dist/index.js"
22
+ }
23
+ },
24
+ "files": [
25
+ "LICENSE",
26
+ "dist",
27
+ "spec.md",
28
+ "README.md"
29
+ ],
30
+ "publishConfig": {
31
+ "access": "public"
32
+ },
33
+ "dependencies": {
34
+ "@agenticprimitives/delegation": "1.0.0-alpha.21",
35
+ "@agenticprimitives/types": "1.0.0-alpha.21",
36
+ "@agenticprimitives/organization": "0.0.0-alpha.5"
37
+ },
38
+ "devDependencies": {
39
+ "vitest": "^4.1.8"
40
+ },
41
+ "keywords": [
42
+ "agentic",
43
+ "vault",
44
+ "authority",
45
+ "roles",
46
+ "delegation"
47
+ ],
48
+ "scripts": {
49
+ "build": "tsc -p tsconfig.build.json",
50
+ "typecheck": "tsc -p tsconfig.json --noEmit",
51
+ "test": "vitest run",
52
+ "test:unit": "vitest run test/unit --passWithNoTests",
53
+ "clean": "rm -rf dist"
54
+ }
55
+ }
package/spec.md ADDED
@@ -0,0 +1 @@
1
+ See [spec 343](../../specs/343-vault-subject-authority.md).