agent-passport-system 4.1.1 → 4.2.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/dist/src/adapters/oauth-id-jag/import-v1.d.ts +74 -0
- package/dist/src/adapters/oauth-id-jag/import-v1.d.ts.map +1 -0
- package/dist/src/adapters/oauth-id-jag/import-v1.js +243 -0
- package/dist/src/adapters/oauth-id-jag/import-v1.js.map +1 -0
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +6 -0
- package/dist/src/index.js.map +1 -1
- package/dist/src/profiles/a2a/identity-v1.d.ts +44 -0
- package/dist/src/profiles/a2a/identity-v1.d.ts.map +1 -0
- package/dist/src/profiles/a2a/identity-v1.js +208 -0
- package/dist/src/profiles/a2a/identity-v1.js.map +1 -0
- package/dist/src/profiles/a2a/index.d.ts +2 -0
- package/dist/src/profiles/a2a/index.d.ts.map +1 -0
- package/dist/src/profiles/a2a/index.js +2 -0
- package/dist/src/profiles/a2a/index.js.map +1 -0
- package/dist/src/profiles/mcp/authorization-v1.d.ts +88 -0
- package/dist/src/profiles/mcp/authorization-v1.d.ts.map +1 -0
- package/dist/src/profiles/mcp/authorization-v1.js +215 -0
- package/dist/src/profiles/mcp/authorization-v1.js.map +1 -0
- package/dist/src/profiles/mcp/index.d.ts +2 -0
- package/dist/src/profiles/mcp/index.d.ts.map +1 -0
- package/dist/src/profiles/mcp/index.js +2 -0
- package/dist/src/profiles/mcp/index.js.map +1 -0
- package/dist/src/v2/action-reference/index.d.ts +2 -0
- package/dist/src/v2/action-reference/index.d.ts.map +1 -0
- package/dist/src/v2/action-reference/index.js +2 -0
- package/dist/src/v2/action-reference/index.js.map +1 -0
- package/dist/src/v2/action-reference/v2.d.ts +23 -0
- package/dist/src/v2/action-reference/v2.d.ts.map +1 -0
- package/dist/src/v2/action-reference/v2.js +57 -0
- package/dist/src/v2/action-reference/v2.js.map +1 -0
- package/dist/src/v2/authority-delegation/budget.d.ts +20 -0
- package/dist/src/v2/authority-delegation/budget.d.ts.map +1 -0
- package/dist/src/v2/authority-delegation/budget.js +141 -0
- package/dist/src/v2/authority-delegation/budget.js.map +1 -0
- package/dist/src/v2/authority-delegation/canonical.d.ts +12 -0
- package/dist/src/v2/authority-delegation/canonical.d.ts.map +1 -0
- package/dist/src/v2/authority-delegation/canonical.js +33 -0
- package/dist/src/v2/authority-delegation/canonical.js.map +1 -0
- package/dist/src/v2/authority-delegation/compare.d.ts +4 -0
- package/dist/src/v2/authority-delegation/compare.d.ts.map +1 -0
- package/dist/src/v2/authority-delegation/compare.js +67 -0
- package/dist/src/v2/authority-delegation/compare.js.map +1 -0
- package/dist/src/v2/authority-delegation/index.d.ts +10 -0
- package/dist/src/v2/authority-delegation/index.d.ts.map +1 -0
- package/dist/src/v2/authority-delegation/index.js +12 -0
- package/dist/src/v2/authority-delegation/index.js.map +1 -0
- package/dist/src/v2/authority-delegation/issue.d.ts +10 -0
- package/dist/src/v2/authority-delegation/issue.d.ts.map +1 -0
- package/dist/src/v2/authority-delegation/issue.js +52 -0
- package/dist/src/v2/authority-delegation/issue.js.map +1 -0
- package/dist/src/v2/authority-delegation/parse.d.ts +4 -0
- package/dist/src/v2/authority-delegation/parse.d.ts.map +1 -0
- package/dist/src/v2/authority-delegation/parse.js +96 -0
- package/dist/src/v2/authority-delegation/parse.js.map +1 -0
- package/dist/src/v2/authority-delegation/schema.d.ts +7 -0
- package/dist/src/v2/authority-delegation/schema.d.ts.map +1 -0
- package/dist/src/v2/authority-delegation/schema.js +177 -0
- package/dist/src/v2/authority-delegation/schema.js.map +1 -0
- package/dist/src/v2/authority-delegation/scope.d.ts +6 -0
- package/dist/src/v2/authority-delegation/scope.d.ts.map +1 -0
- package/dist/src/v2/authority-delegation/scope.js +50 -0
- package/dist/src/v2/authority-delegation/scope.js.map +1 -0
- package/dist/src/v2/authority-delegation/types.d.ts +98 -0
- package/dist/src/v2/authority-delegation/types.d.ts.map +1 -0
- package/dist/src/v2/authority-delegation/types.js +10 -0
- package/dist/src/v2/authority-delegation/types.js.map +1 -0
- package/dist/src/v2/authority-delegation/verify.d.ts +5 -0
- package/dist/src/v2/authority-delegation/verify.d.ts.map +1 -0
- package/dist/src/v2/authority-delegation/verify.js +124 -0
- package/dist/src/v2/authority-delegation/verify.js.map +1 -0
- package/dist/src/v2/identity-binding/did-aps.d.ts +12 -0
- package/dist/src/v2/identity-binding/did-aps.d.ts.map +1 -0
- package/dist/src/v2/identity-binding/did-aps.js +53 -0
- package/dist/src/v2/identity-binding/did-aps.js.map +1 -0
- package/dist/src/v2/identity-binding/index.d.ts +6 -0
- package/dist/src/v2/identity-binding/index.d.ts.map +1 -0
- package/dist/src/v2/identity-binding/index.js +6 -0
- package/dist/src/v2/identity-binding/index.js.map +1 -0
- package/dist/src/v2/identity-binding/passport.d.ts +18 -0
- package/dist/src/v2/identity-binding/passport.d.ts.map +1 -0
- package/dist/src/v2/identity-binding/passport.js +144 -0
- package/dist/src/v2/identity-binding/passport.js.map +1 -0
- package/dist/src/v2/identity-binding/principal-binding.d.ts +20 -0
- package/dist/src/v2/identity-binding/principal-binding.d.ts.map +1 -0
- package/dist/src/v2/identity-binding/principal-binding.js +128 -0
- package/dist/src/v2/identity-binding/principal-binding.js.map +1 -0
- package/dist/src/v2/identity-binding/revocation.d.ts +12 -0
- package/dist/src/v2/identity-binding/revocation.d.ts.map +1 -0
- package/dist/src/v2/identity-binding/revocation.js +97 -0
- package/dist/src/v2/identity-binding/revocation.js.map +1 -0
- package/dist/src/v2/identity-binding/types.d.ts +72 -0
- package/dist/src/v2/identity-binding/types.d.ts.map +1 -0
- package/dist/src/v2/identity-binding/types.js +4 -0
- package/dist/src/v2/identity-binding/types.js.map +1 -0
- package/dist/src/v2/identity-binding/validation.d.ts +9 -0
- package/dist/src/v2/identity-binding/validation.d.ts.map +1 -0
- package/dist/src/v2/identity-binding/validation.js +104 -0
- package/dist/src/v2/identity-binding/validation.js.map +1 -0
- package/dist/src/v2/receipt-core/decision-ref.d.ts +23 -0
- package/dist/src/v2/receipt-core/decision-ref.d.ts.map +1 -0
- package/dist/src/v2/receipt-core/decision-ref.js +75 -0
- package/dist/src/v2/receipt-core/decision-ref.js.map +1 -0
- package/dist/src/v2/receipt-core/jcs.d.ts +15 -0
- package/dist/src/v2/receipt-core/jcs.d.ts.map +1 -0
- package/dist/src/v2/receipt-core/jcs.js +198 -0
- package/dist/src/v2/receipt-core/jcs.js.map +1 -0
- package/dist/src/v2/receipt-core/receipt.d.ts +21 -0
- package/dist/src/v2/receipt-core/receipt.d.ts.map +1 -0
- package/dist/src/v2/receipt-core/receipt.js +132 -0
- package/dist/src/v2/receipt-core/receipt.js.map +1 -0
- package/dist/src/v2/receipt-core/supporting-record.d.ts +55 -0
- package/dist/src/v2/receipt-core/supporting-record.d.ts.map +1 -0
- package/dist/src/v2/receipt-core/supporting-record.js +243 -0
- package/dist/src/v2/receipt-core/supporting-record.js.map +1 -0
- package/dist/src/v2/receipt-core/types.d.ts +94 -0
- package/dist/src/v2/receipt-core/types.d.ts.map +1 -0
- package/dist/src/v2/receipt-core/types.js +4 -0
- package/dist/src/v2/receipt-core/types.js.map +1 -0
- package/package.json +5 -5
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/v2/action-reference/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export interface ActionReferenceInputV2 {
|
|
2
|
+
profile: 'aps-action-ref-v2';
|
|
3
|
+
agent_id: string;
|
|
4
|
+
action_type: string;
|
|
5
|
+
target: string;
|
|
6
|
+
payload_ref: string;
|
|
7
|
+
scope_required: string[];
|
|
8
|
+
issued_at: string;
|
|
9
|
+
nonce: string;
|
|
10
|
+
}
|
|
11
|
+
export declare function createActionReferenceInputV2(input: {
|
|
12
|
+
agent_id: string;
|
|
13
|
+
action_type: string;
|
|
14
|
+
target: string;
|
|
15
|
+
payload_ref: string;
|
|
16
|
+
scope_required: readonly string[];
|
|
17
|
+
issued_at: string;
|
|
18
|
+
nonce: string;
|
|
19
|
+
}): ActionReferenceInputV2;
|
|
20
|
+
export declare function computeActionRefV2(input: ActionReferenceInputV2): string;
|
|
21
|
+
export declare function computePayloadRefV1(payload: unknown): string;
|
|
22
|
+
export declare function validateActionReferenceInputV2(candidate: unknown): asserts candidate is ActionReferenceInputV2;
|
|
23
|
+
//# sourceMappingURL=v2.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v2.d.ts","sourceRoot":"","sources":["../../../../src/v2/action-reference/v2.ts"],"names":[],"mappings":"AAiBA,MAAM,WAAW,sBAAsB;IACrC,OAAO,EAAE,mBAAmB,CAAA;IAC5B,QAAQ,EAAE,MAAM,CAAA;IAChB,WAAW,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;IACd,WAAW,EAAE,MAAM,CAAA;IACnB,cAAc,EAAE,MAAM,EAAE,CAAA;IACxB,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,MAAM,CAAA;CACd;AAED,wBAAgB,4BAA4B,CAAC,KAAK,EAAE;IAClD,QAAQ,EAAE,MAAM,CAAA;IAChB,WAAW,EAAE,MAAM,CAAA;IACnB,MAAM,EAAE,MAAM,CAAA;IACd,WAAW,EAAE,MAAM,CAAA;IACnB,cAAc,EAAE,SAAS,MAAM,EAAE,CAAA;IACjC,SAAS,EAAE,MAAM,CAAA;IACjB,KAAK,EAAE,MAAM,CAAA;CACd,GAAG,sBAAsB,CAgBzB;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,sBAAsB,GAAG,MAAM,CAGxE;AAED,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAK5D;AAED,wBAAgB,8BAA8B,CAAC,SAAS,EAAE,OAAO,GAAG,OAAO,CAAC,SAAS,IAAI,sBAAsB,CAmB9G"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// Copyright (c) 2026 Tymofii Pidlisnyi
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { createHash } from 'node:crypto';
|
|
4
|
+
import { canonicalizeJCS } from '../../core/canonical-jcs.js';
|
|
5
|
+
import { assertExactKeys, assertHex, assertIJson, assertPlainRecord, assertSortedUnique, assertUtcMilliseconds, sortedUnique, } from '../identity-binding/validation.js';
|
|
6
|
+
const DOMAIN = 'APS-ACTION-REF-V2\0';
|
|
7
|
+
export function createActionReferenceInputV2(input) {
|
|
8
|
+
const value = {
|
|
9
|
+
profile: 'aps-action-ref-v2',
|
|
10
|
+
agent_id: input.agent_id,
|
|
11
|
+
action_type: input.action_type,
|
|
12
|
+
target: input.target,
|
|
13
|
+
payload_ref: input.payload_ref,
|
|
14
|
+
scope_required: sortedUnique(input.scope_required.map((scope) => scope.normalize('NFC')), 'scope_required'),
|
|
15
|
+
issued_at: input.issued_at,
|
|
16
|
+
nonce: input.nonce,
|
|
17
|
+
};
|
|
18
|
+
validateActionReferenceInputV2(value);
|
|
19
|
+
return value;
|
|
20
|
+
}
|
|
21
|
+
export function computeActionRefV2(input) {
|
|
22
|
+
validateActionReferenceInputV2(input);
|
|
23
|
+
return createHash('sha256').update(DOMAIN + canonicalizeJCS(input), 'utf8').digest('hex');
|
|
24
|
+
}
|
|
25
|
+
export function computePayloadRefV1(payload) {
|
|
26
|
+
assertIJson(payload);
|
|
27
|
+
return createHash('sha256')
|
|
28
|
+
.update('APS-ACTION-PAYLOAD-V1\0' + canonicalizeJCS(payload), 'utf8')
|
|
29
|
+
.digest('hex');
|
|
30
|
+
}
|
|
31
|
+
export function validateActionReferenceInputV2(candidate) {
|
|
32
|
+
assertPlainRecord(candidate, 'action reference');
|
|
33
|
+
assertExactKeys(candidate, [
|
|
34
|
+
'profile', 'agent_id', 'action_type', 'target', 'payload_ref',
|
|
35
|
+
'scope_required', 'issued_at', 'nonce',
|
|
36
|
+
], [], 'action reference');
|
|
37
|
+
assertIJson(candidate);
|
|
38
|
+
if (candidate.profile !== 'aps-action-ref-v2')
|
|
39
|
+
throw new Error('action reference profile');
|
|
40
|
+
if (typeof candidate.agent_id !== 'string' || candidate.agent_id.length === 0)
|
|
41
|
+
throw new Error('agent_id');
|
|
42
|
+
if (typeof candidate.action_type !== 'string' || candidate.action_type.length === 0)
|
|
43
|
+
throw new Error('action_type');
|
|
44
|
+
if (typeof candidate.target !== 'string' || candidate.target.length === 0)
|
|
45
|
+
throw new Error('target');
|
|
46
|
+
assertHex(String(candidate.payload_ref), 64, 'payload_ref');
|
|
47
|
+
if (!Array.isArray(candidate.scope_required))
|
|
48
|
+
throw new Error('scope_required');
|
|
49
|
+
assertSortedUnique(candidate.scope_required, 'scope_required');
|
|
50
|
+
for (const scope of candidate.scope_required) {
|
|
51
|
+
if (scope !== scope.normalize('NFC'))
|
|
52
|
+
throw new Error('scope_required: non-NFC value');
|
|
53
|
+
}
|
|
54
|
+
assertUtcMilliseconds(String(candidate.issued_at), 'issued_at');
|
|
55
|
+
assertHex(String(candidate.nonce), 32, 'nonce');
|
|
56
|
+
}
|
|
57
|
+
//# sourceMappingURL=v2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"v2.js","sourceRoot":"","sources":["../../../../src/v2/action-reference/v2.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,sCAAsC;AAEtC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAA;AAC7D,OAAO,EACL,eAAe,EACf,SAAS,EACT,WAAW,EACX,iBAAiB,EACjB,kBAAkB,EAClB,qBAAqB,EACrB,YAAY,GACb,MAAM,mCAAmC,CAAA;AAE1C,MAAM,MAAM,GAAG,qBAAqB,CAAA;AAapC,MAAM,UAAU,4BAA4B,CAAC,KAQ5C;IACC,MAAM,KAAK,GAA2B;QACpC,OAAO,EAAE,mBA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
1
|
+
import type { AuthorityDelegationV1, BudgetOperationResult } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Reference linearizable ledger for one JavaScript process. Each mutation is a
|
|
4
|
+
* single synchronous critical section. Distributed deployments must replace it
|
|
5
|
+
* with a store providing the same all-ancestors atomicity and idempotency.
|
|
6
|
+
*/
|
|
7
|
+
export declare class InMemoryAuthorityBudgetLedger {
|
|
8
|
+
private readonly counters;
|
|
9
|
+
private readonly reservations;
|
|
10
|
+
reserve(verifiedChain: readonly AuthorityDelegationV1[], actionRef: string, unit: string, amountString: string): BudgetOperationResult;
|
|
11
|
+
markDispatched(actionRef: string): BudgetOperationResult;
|
|
12
|
+
commit(actionRef: string): BudgetOperationResult;
|
|
13
|
+
/** Cancellation is allowed only before dispatch. */
|
|
14
|
+
cancel(actionRef: string): BudgetOperationResult;
|
|
15
|
+
counter(delegationId: string): {
|
|
16
|
+
reserved: string;
|
|
17
|
+
committed: string;
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=budget.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"budget.d.ts","sourceRoot":"","sources":["../../../../src/v2/authority-delegation/budget.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EACV,qBAAqB,EACrB,qBAAqB,EAEtB,MAAM,YAAY,CAAA;AAiBnB;;;;GAIG;AACH,qBAAa,6BAA6B;IACxC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAA6B;IACtD,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAiC;IAE9D,OAAO,CACL,aAAa,EAAE,SAAS,qBAAqB,EAAE,EAC/C,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,EACZ,YAAY,EAAE,MAAM,GACnB,qBAAqB,CA+DvB;IAED,cAAc,CAAC,SAAS,EAAE,MAAM,GAAG,qBAAqB,CAOvD;IAED,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,qBAAqB,CAoB/C;IAED,oDAAoD;IACpD,MAAM,CAAC,SAAS,EAAE,MAAM,GAAG,qBAAqB,CAgB/C;IAED,OAAO,CAAC,YAAY,EAAE,MAAM,GAAG;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,CAGrE;CACF"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// Copyright (c) 2026 Tymofii Pidlisnyi
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { isCanonicalQuantity, validateAuthorityDelegationShape } from './schema.js';
|
|
4
|
+
import { authorityDelegationBody, computeAuthorityDelegationId } from './canonical.js';
|
|
5
|
+
const ACTION_REF = /^[0-9a-f]{64}$/;
|
|
6
|
+
/**
|
|
7
|
+
* Reference linearizable ledger for one JavaScript process. Each mutation is a
|
|
8
|
+
* single synchronous critical section. Distributed deployments must replace it
|
|
9
|
+
* with a store providing the same all-ancestors atomicity and idempotency.
|
|
10
|
+
*/
|
|
11
|
+
export class InMemoryAuthorityBudgetLedger {
|
|
12
|
+
counters = new Map();
|
|
13
|
+
reservations = new Map();
|
|
14
|
+
reserve(verifiedChain, actionRef, unit, amountString) {
|
|
15
|
+
if (!ACTION_REF.test(actionRef) || !isCanonicalQuantity(amountString)) {
|
|
16
|
+
return { ok: false, code: 'CONFLICT' };
|
|
17
|
+
}
|
|
18
|
+
if (verifiedChain.length === 0 || verifiedChain.length > 256) {
|
|
19
|
+
return { ok: false, code: 'CONFLICT' };
|
|
20
|
+
}
|
|
21
|
+
const seen = new Set();
|
|
22
|
+
for (let i = 0; i < verifiedChain.length; i++) {
|
|
23
|
+
const current = verifiedChain[i];
|
|
24
|
+
if (validateAuthorityDelegationShape(current).length > 0 ||
|
|
25
|
+
computeAuthorityDelegationId(authorityDelegationBody(current)) !== current.delegation_id ||
|
|
26
|
+
seen.has(current.delegation_id)) {
|
|
27
|
+
return { ok: false, code: 'CONFLICT' };
|
|
28
|
+
}
|
|
29
|
+
seen.add(current.delegation_id);
|
|
30
|
+
if (i === 0) {
|
|
31
|
+
if (current.parent_delegation_id !== null)
|
|
32
|
+
return { ok: false, code: 'CONFLICT' };
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
const parent = verifiedChain[i - 1];
|
|
36
|
+
if (current.parent_delegation_id !== parent.delegation_id || current.issuer !== parent.subject) {
|
|
37
|
+
return { ok: false, code: 'CONFLICT' };
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
const amount = BigInt(amountString);
|
|
42
|
+
const bounded = verifiedChain.filter(item => item.authority.spend.mode === 'bounded');
|
|
43
|
+
const ids = bounded.map(item => item.delegation_id);
|
|
44
|
+
const prior = this.reservations.get(actionRef);
|
|
45
|
+
if (prior) {
|
|
46
|
+
const identical = prior.unit === unit && prior.amount === amount &&
|
|
47
|
+
prior.delegationIds.length === ids.length &&
|
|
48
|
+
prior.delegationIds.every((id, index) => id === ids[index]);
|
|
49
|
+
return identical
|
|
50
|
+
? { ok: true, code: 'IDEMPOTENT', state: prior.state }
|
|
51
|
+
: { ok: false, code: 'CONFLICT', state: prior.state };
|
|
52
|
+
}
|
|
53
|
+
for (const delegation of bounded) {
|
|
54
|
+
const spend = delegation.authority.spend;
|
|
55
|
+
if (spend.mode !== 'bounded')
|
|
56
|
+
continue;
|
|
57
|
+
if (spend.unit !== unit)
|
|
58
|
+
return { ok: false, code: 'UNIT_MISMATCH' };
|
|
59
|
+
if (amount > BigInt(spend.per_action))
|
|
60
|
+
return { ok: false, code: 'PER_ACTION_EXCEEDED' };
|
|
61
|
+
const counter = this.counters.get(delegation.delegation_id) ?? { reserved: 0n, committed: 0n };
|
|
62
|
+
if (counter.reserved + counter.committed + amount > BigInt(spend.cumulative)) {
|
|
63
|
+
return { ok: false, code: 'CUMULATIVE_EXCEEDED' };
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
// All checks completed before any counter is changed.
|
|
67
|
+
for (const delegation of bounded) {
|
|
68
|
+
const counter = this.counters.get(delegation.delegation_id) ?? { reserved: 0n, committed: 0n };
|
|
69
|
+
counter.reserved += amount;
|
|
70
|
+
this.counters.set(delegation.delegation_id, counter);
|
|
71
|
+
}
|
|
72
|
+
this.reservations.set(actionRef, {
|
|
73
|
+
actionRef,
|
|
74
|
+
unit,
|
|
75
|
+
amount,
|
|
76
|
+
delegationIds: ids,
|
|
77
|
+
state: 'reserved',
|
|
78
|
+
});
|
|
79
|
+
return { ok: true, code: 'RESERVED', state: 'reserved' };
|
|
80
|
+
}
|
|
81
|
+
markDispatched(actionRef) {
|
|
82
|
+
const reservation = this.reservations.get(actionRef);
|
|
83
|
+
if (!reservation)
|
|
84
|
+
return { ok: false, code: 'NOT_FOUND' };
|
|
85
|
+
if (reservation.state === 'dispatched')
|
|
86
|
+
return { ok: true, code: 'IDEMPOTENT', state: 'dispatched' };
|
|
87
|
+
if (reservation.state !== 'reserved')
|
|
88
|
+
return { ok: false, code: 'INVALID_STATE', state: reservation.state };
|
|
89
|
+
reservation.state = 'dispatched';
|
|
90
|
+
return { ok: true, code: 'DISPATCHED', state: 'dispatched' };
|
|
91
|
+
}
|
|
92
|
+
commit(actionRef) {
|
|
93
|
+
const reservation = this.reservations.get(actionRef);
|
|
94
|
+
if (!reservation)
|
|
95
|
+
return { ok: false, code: 'NOT_FOUND' };
|
|
96
|
+
if (reservation.state === 'committed')
|
|
97
|
+
return { ok: true, code: 'IDEMPOTENT', state: 'committed' };
|
|
98
|
+
if (reservation.state !== 'reserved' && reservation.state !== 'dispatched') {
|
|
99
|
+
return { ok: false, code: 'INVALID_STATE', state: reservation.state };
|
|
100
|
+
}
|
|
101
|
+
for (const id of reservation.delegationIds) {
|
|
102
|
+
const counter = this.counters.get(id);
|
|
103
|
+
if (!counter || counter.reserved < reservation.amount) {
|
|
104
|
+
return { ok: false, code: 'INVALID_STATE', state: reservation.state };
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
for (const id of reservation.delegationIds) {
|
|
108
|
+
const counter = this.counters.get(id);
|
|
109
|
+
counter.reserved -= reservation.amount;
|
|
110
|
+
counter.committed += reservation.amount;
|
|
111
|
+
}
|
|
112
|
+
reservation.state = 'committed';
|
|
113
|
+
return { ok: true, code: 'COMMITTED', state: 'committed' };
|
|
114
|
+
}
|
|
115
|
+
/** Cancellation is allowed only before dispatch. */
|
|
116
|
+
cancel(actionRef) {
|
|
117
|
+
const reservation = this.reservations.get(actionRef);
|
|
118
|
+
if (!reservation)
|
|
119
|
+
return { ok: false, code: 'NOT_FOUND' };
|
|
120
|
+
if (reservation.state === 'cancelled')
|
|
121
|
+
return { ok: true, code: 'IDEMPOTENT', state: 'cancelled' };
|
|
122
|
+
if (reservation.state !== 'reserved')
|
|
123
|
+
return { ok: false, code: 'INVALID_STATE', state: reservation.state };
|
|
124
|
+
for (const id of reservation.delegationIds) {
|
|
125
|
+
const counter = this.counters.get(id);
|
|
126
|
+
if (!counter || counter.reserved < reservation.amount) {
|
|
127
|
+
return { ok: false, code: 'INVALID_STATE', state: reservation.state };
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
for (const id of reservation.delegationIds) {
|
|
131
|
+
this.counters.get(id).reserved -= reservation.amount;
|
|
132
|
+
}
|
|
133
|
+
reservation.state = 'cancelled';
|
|
134
|
+
return { ok: true, code: 'CANCELLED', state: 'cancelled' };
|
|
135
|
+
}
|
|
136
|
+
counter(delegationId) {
|
|
137
|
+
const counter = this.counters.get(delegationId) ?? { reserved: 0n, committed: 0n };
|
|
138
|
+
return { reserved: counter.reserved.toString(), committed: counter.committed.toString() };
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=budget.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"budget.js","sourceRoot":"","sources":["../../../../src/v2/authority-delegation/budget.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,sCAAsC;AAEtC,OAAO,EAAE,mBAAmB,EAAE,gCAAgC,EAAE,MAAM,aAAa,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E,QAAQ,EAAE,OAAO,CAAC,QAAQ,CAAC,QAAQ,EAAE,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,CAAC,QAAQ,EAAE,EAAE,CAAA;IAC3F,CAAC;CACF"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AuthorityDelegationBodyV1, AuthorityDelegationV1 } from './types.js';
|
|
2
|
+
export declare const AUTHORITY_DELEGATION_ID_DOMAIN = "APS-AUTHORITY-DELEGATION-ID-V1\0";
|
|
3
|
+
export declare const AUTHORITY_DELEGATION_SIGNATURE_DOMAIN = "APS-AUTHORITY-DELEGATION-SIGNATURE-V1\0";
|
|
4
|
+
/** Exact RFC 8785 input used to derive delegation_id. */
|
|
5
|
+
export declare function authorityDelegationIdInput(body: AuthorityDelegationBodyV1): string;
|
|
6
|
+
export declare function computeAuthorityDelegationId(body: AuthorityDelegationBodyV1): string;
|
|
7
|
+
/** Exact Ed25519 input: domain plus JCS(record without signature). */
|
|
8
|
+
export declare function authorityDelegationSignatureInput(delegation: Omit<AuthorityDelegationV1, 'signature'>): string;
|
|
9
|
+
export declare function signAuthorityDelegation(delegation: Omit<AuthorityDelegationV1, 'signature'>, privateKey: string): string;
|
|
10
|
+
export declare function verifyAuthorityDelegationSignature(delegation: AuthorityDelegationV1, publicKey: string): boolean;
|
|
11
|
+
export declare function authorityDelegationBody(delegation: AuthorityDelegationV1): AuthorityDelegationBodyV1;
|
|
12
|
+
//# sourceMappingURL=canonical.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canonical.d.ts","sourceRoot":"","sources":["../../../../src/v2/authority-delegation/canonical.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,yBAAyB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAElF,eAAO,MAAM,8BAA8B,qCAAqC,CAAA;AAChF,eAAO,MAAM,qCAAqC,4CAA4C,CAAA;AAM9F,yDAAyD;AACzD,wBAAgB,0BAA0B,CAAC,IAAI,EAAE,yBAAyB,GAAG,MAAM,CAElF;AAED,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,yBAAyB,GAAG,MAAM,CAEpF;AAED,sEAAsE;AACtE,wBAAgB,iCAAiC,CAC/C,UAAU,EAAE,IAAI,CAAC,qBAAqB,EAAE,WAAW,CAAC,GACnD,MAAM,CAER;AAED,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,IAAI,CAAC,qBAAqB,EAAE,WAAW,CAAC,EACpD,UAAU,EAAE,MAAM,GACjB,MAAM,CAER;AAED,wBAAgB,kCAAkC,CAChD,UAAU,EAAE,qBAAqB,EACjC,SAAS,EAAE,MAAM,GAChB,OAAO,CAGT;AAED,wBAAgB,uBAAuB,CACrC,UAAU,EAAE,qBAAqB,GAChC,yBAAyB,CAG3B"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// Copyright (c) 2026 Tymofii Pidlisnyi
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { createHash } from 'node:crypto';
|
|
4
|
+
import { canonicalizeJCS } from '../../core/canonical-jcs.js';
|
|
5
|
+
import { sign, verify } from '../../crypto/keys.js';
|
|
6
|
+
export const AUTHORITY_DELEGATION_ID_DOMAIN = 'APS-AUTHORITY-DELEGATION-ID-V1\0';
|
|
7
|
+
export const AUTHORITY_DELEGATION_SIGNATURE_DOMAIN = 'APS-AUTHORITY-DELEGATION-SIGNATURE-V1\0';
|
|
8
|
+
function sha256Hex(value) {
|
|
9
|
+
return createHash('sha256').update(value, 'utf8').digest('hex');
|
|
10
|
+
}
|
|
11
|
+
/** Exact RFC 8785 input used to derive delegation_id. */
|
|
12
|
+
export function authorityDelegationIdInput(body) {
|
|
13
|
+
return AUTHORITY_DELEGATION_ID_DOMAIN + canonicalizeJCS(body);
|
|
14
|
+
}
|
|
15
|
+
export function computeAuthorityDelegationId(body) {
|
|
16
|
+
return `sha256:${sha256Hex(authorityDelegationIdInput(body))}`;
|
|
17
|
+
}
|
|
18
|
+
/** Exact Ed25519 input: domain plus JCS(record without signature). */
|
|
19
|
+
export function authorityDelegationSignatureInput(delegation) {
|
|
20
|
+
return AUTHORITY_DELEGATION_SIGNATURE_DOMAIN + canonicalizeJCS(delegation);
|
|
21
|
+
}
|
|
22
|
+
export function signAuthorityDelegation(delegation, privateKey) {
|
|
23
|
+
return sign(authorityDelegationSignatureInput(delegation), privateKey);
|
|
24
|
+
}
|
|
25
|
+
export function verifyAuthorityDelegationSignature(delegation, publicKey) {
|
|
26
|
+
const { signature, ...unsigned } = delegation;
|
|
27
|
+
return verify(authorityDelegationSignatureInput(unsigned), signature, publicKey);
|
|
28
|
+
}
|
|
29
|
+
export function authorityDelegationBody(delegation) {
|
|
30
|
+
const { delegation_id: _delegationId, signature: _signature, ...body } = delegation;
|
|
31
|
+
return body;
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=canonical.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"canonical.js","sourceRoot":"","sources":["../../../../src/v2/authority-delegation/canonical.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,sCAAsC;AAEtC,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAA;AAC7D,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAA;AAGnD,MAAM,CAAC,MAAM,8BAA8B,GAAG,kCAAkC,CAAA;AAChF,MAAM,CAAC,MAAM,qCAAqC,GAAG,yCAAyC,CAAA;AAE9F,SAAS,SAAS,CAAC,KAAa;IAC9B,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;AACjE,CAAC;AAED,yDAAyD;AACzD,MAAM,UAAU,0BAA0B,CAAC,IAA+B;IACxE,OAAO,8BAA8B,GAAG,eAAe,CAAC,IAAI,CAAC,CAAA;AAC/D,CAAC;AAED,MAAM,UAAU,4BAA4B,CAAC,IAA+B;IAC1E,OAAO,UAAU,SAAS,CAAC,0BAA0B,CAAC,IAAI,CAAC,CAAC,EAAE,CAAA;AAChE,CAAC;AAED,sEAAsE;AACtE,MAAM,UAAU,iCAAiC,CAC/C,UAAoD;IAEpD,OAAO,qCAAqC,GAAG,eAAe,CAAC,UAAU,CAAC,CAAA;AAC5E,CAAC;AAED,MAAM,UAAU,uBAAuB,CACrC,UAAoD,EACpD,UAAkB;IAElB,OAAO,IAAI,CAAC,iCAAiC,CAAC,UAAU,CAAC,EAAE,UAAU,CAAC,CAAA;AACxE,CAAC;AAED,MAAM,UAAU,kCAAkC,CAChD,UAAiC,EACjC,SAAiB;IAEjB,MAAM,EAAE,SAAS,EAAE,GAAG,QAAQ,EAAE,GAAG,UAAU,CAAA;IAC7C,OAAO,MAAM,CAAC,iCAAiC,CAAC,QAAQ,CAAC,EAAE,SAAS,EAAE,SAAS,CAAC,CAAA;AAClF,CAAC;AAED,MAAM,UAAU,uBAAuB,CACrC,UAAiC;IAEjC,MAAM,EAAE,aAAa,EAAE,aAAa,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,IAAI,EAAE,GAAG,UAAU,CAAA;IACnF,OAAO,IAAI,CAAA;AACb,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { AuthorityFailure, AuthorityVectorV1 } from './types.js';
|
|
2
|
+
/** Compare a child against its immediate parent in the seven-facet partial order. */
|
|
3
|
+
export declare function compareAuthority(parent: AuthorityVectorV1, child: AuthorityVectorV1): AuthorityFailure[];
|
|
4
|
+
//# sourceMappingURL=compare.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compare.d.ts","sourceRoot":"","sources":["../../../../src/v2/authority-delegation/compare.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAwB,MAAM,YAAY,CAAA;AAiB3F,qFAAqF;AACrF,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,iBAAiB,EACzB,KAAK,EAAE,iBAAiB,GACvB,gBAAgB,EAAE,CAsDpB"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// Copyright (c) 2026 Tymofii Pidlisnyi
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { scopeNarrows } from './scope.js';
|
|
4
|
+
const REVERSIBILITY_RANK = {
|
|
5
|
+
tentative: 0,
|
|
6
|
+
compensable: 1,
|
|
7
|
+
irreversible: 2,
|
|
8
|
+
};
|
|
9
|
+
function fail(failures, code, facet, message) {
|
|
10
|
+
failures.push({ code, facet, message });
|
|
11
|
+
}
|
|
12
|
+
/** Compare a child against its immediate parent in the seven-facet partial order. */
|
|
13
|
+
export function compareAuthority(parent, child) {
|
|
14
|
+
const failures = [];
|
|
15
|
+
if (child.scope.profile !== parent.scope.profile) {
|
|
16
|
+
fail(failures, 'UNSUPPORTED_PROFILE', 'scope', 'scope profile changes are incomparable');
|
|
17
|
+
}
|
|
18
|
+
else if (!scopeNarrows(parent.scope.grants, child.scope.grants)) {
|
|
19
|
+
fail(failures, 'SCOPE_WIDENING', 'scope', 'child scope is not covered by parent scope');
|
|
20
|
+
}
|
|
21
|
+
if (parent.spend.mode === 'bounded') {
|
|
22
|
+
if (child.spend.mode === 'unbounded') {
|
|
23
|
+
fail(failures, 'SPEND_WIDENING', 'spend', 'bounded parent cannot produce unbounded child');
|
|
24
|
+
}
|
|
25
|
+
else if (child.spend.unit !== parent.spend.unit) {
|
|
26
|
+
fail(failures, 'SPEND_UNIT_CHANGE', 'spend', 'bounded spend unit must remain exact');
|
|
27
|
+
}
|
|
28
|
+
else if (BigInt(child.spend.per_action) > BigInt(parent.spend.per_action) ||
|
|
29
|
+
BigInt(child.spend.cumulative) > BigInt(parent.spend.cumulative)) {
|
|
30
|
+
fail(failures, 'SPEND_WIDENING', 'spend', 'child spend limits exceed parent limits');
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (parent.depth.remaining === 0) {
|
|
34
|
+
fail(failures, 'DEPTH_EXHAUSTED', 'depth', 'parent has no remaining delegation hop');
|
|
35
|
+
}
|
|
36
|
+
else if (child.depth.remaining > parent.depth.remaining - 1) {
|
|
37
|
+
fail(failures, 'DEPTH_WIDENING', 'depth', 'child remaining depth must consume at least one hop');
|
|
38
|
+
}
|
|
39
|
+
if (Date.parse(child.time.not_before) < Date.parse(parent.time.not_before) ||
|
|
40
|
+
Date.parse(child.time.not_after) > Date.parse(parent.time.not_after)) {
|
|
41
|
+
fail(failures, 'TIME_WIDENING', 'time', 'child validity window is not contained in parent window');
|
|
42
|
+
}
|
|
43
|
+
if (child.reputation.profile !== parent.reputation.profile) {
|
|
44
|
+
fail(failures, 'UNSUPPORTED_PROFILE', 'reputation', 'reputation profile changes are incomparable');
|
|
45
|
+
}
|
|
46
|
+
else if (child.reputation.ceiling > parent.reputation.ceiling) {
|
|
47
|
+
fail(failures, 'REPUTATION_WIDENING', 'reputation', 'child reputation ceiling exceeds parent');
|
|
48
|
+
}
|
|
49
|
+
if (child.values.profile !== parent.values.profile) {
|
|
50
|
+
fail(failures, 'UNSUPPORTED_PROFILE', 'values', 'values profile changes are incomparable');
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
const childRequired = new Set(child.values.required);
|
|
54
|
+
if (parent.values.required.some(identifier => !childRequired.has(identifier))) {
|
|
55
|
+
fail(failures, 'VALUES_WEAKENING', 'values', 'child removed an ancestor-required value identifier');
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
if (child.reversibility.profile !== parent.reversibility.profile) {
|
|
59
|
+
fail(failures, 'UNSUPPORTED_PROFILE', 'reversibility', 'reversibility profile changes are incomparable');
|
|
60
|
+
}
|
|
61
|
+
else if (REVERSIBILITY_RANK[child.reversibility.ceiling] >
|
|
62
|
+
REVERSIBILITY_RANK[parent.reversibility.ceiling]) {
|
|
63
|
+
fail(failures, 'REVERSIBILITY_WIDENING', 'reversibility', 'child reversibility ceiling exceeds parent');
|
|
64
|
+
}
|
|
65
|
+
return failures;
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=compare.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compare.js","sourceRoot":"","sources":["../../../../src/v2/authority-delegation/compare.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,sCAAsC;AAEtC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAGzC,MAAM,kBAAkB,GAAyC;IAC/D,SAAS,EAAE,CAAC;IACZ,WAAW,EAAE,CAAC;IACd,YAAY,EAAE,CAAC;CAChB,CAAA;AAED,SAAS,IAAI,CACX,QAA4B,EAC5B,IAA8B,EAC9B,KAA8B,EAC9B,OAAe;IAEf,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC,CAAA;AACzC,CAAC;AAED,qFAAqF;AACrF,MAAM,UAAU,gBAAgB,CAC9B,MAAyB,EACzB,KAAwB;IAExB,MAAM,QAAQ,GAAuB,EAAE,CAAA;IAEvC,IAAI,KAAK,CAAC,KAAK,CAAC,OAAO,KAAK,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;QACjD,IAAI,CAAC,QAAQ,EAAE,qBAAqB,EAAE,OAAO,EAAE,wCAAwC,CAAC,CAAA;IAC1F,CAAC;SAAM,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,EAAE,CAAC;QAClE,IAAI,CAAC,QAAQ,EAAE,gBAAgB,EAAE,OAAO,EAAE,4CAA4C,CAAC,CAAA;IACzF,CAAC;IAED,IAAI,MAAM,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QACpC,IAAI,KAAK,CAAC,KAAK,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;YACrC,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kB,CAAC,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,CAAC;QAC5D,IAAI,CAAC,QAAQ,EAAE,wBAAwB,EAAE,eAAe,EAAE,4CAA4C,CAAC,CAAA;IACzG,CAAC;IAED,OAAO,QAAQ,CAAA;AACjB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from './types.js';
|
|
2
|
+
export * from './schema.js';
|
|
3
|
+
export * from './scope.js';
|
|
4
|
+
export * from './canonical.js';
|
|
5
|
+
export * from './compare.js';
|
|
6
|
+
export * from './issue.js';
|
|
7
|
+
export * from './parse.js';
|
|
8
|
+
export * from './verify.js';
|
|
9
|
+
export * from './budget.js';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/v2/authority-delegation/index.ts"],"names":[],"mappings":"AAGA,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
// Copyright (c) 2026 Tymofii Pidlisnyi
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
export * from './types.js';
|
|
4
|
+
export * from './schema.js';
|
|
5
|
+
export * from './scope.js';
|
|
6
|
+
export * from './canonical.js';
|
|
7
|
+
export * from './compare.js';
|
|
8
|
+
export * from './issue.js';
|
|
9
|
+
export * from './parse.js';
|
|
10
|
+
export * from './verify.js';
|
|
11
|
+
export * from './budget.js';
|
|
12
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/v2/authority-delegation/index.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,sCAAsC;AAEtC,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,cAAc,CAAA;AAC5B,cAAc,YAAY,CAAA;AAC1B,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { AuthorityDelegationBodyV1, AuthorityDelegationV1 } from './types.js';
|
|
2
|
+
/** Create a deterministic v1 record from explicit body fields and an Ed25519 key. */
|
|
3
|
+
export declare function issueAuthorityDelegation(body: AuthorityDelegationBodyV1, privateKey: string): AuthorityDelegationV1;
|
|
4
|
+
/**
|
|
5
|
+
* Issue a child after immediate-parent attenuation checks. The caller must first
|
|
6
|
+
* validate the complete parent chain and revocation state; this pure primitive
|
|
7
|
+
* cannot establish live ancestor status by itself.
|
|
8
|
+
*/
|
|
9
|
+
export declare function issueSubAuthorityDelegation(parent: AuthorityDelegationV1, body: AuthorityDelegationBodyV1, privateKey: string): AuthorityDelegationV1;
|
|
10
|
+
//# sourceMappingURL=issue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"issue.d.ts","sourceRoot":"","sources":["../../../../src/v2/authority-delegation/issue.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,yBAAyB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAclF,qFAAqF;AACrF,wBAAgB,wBAAwB,CACtC,IAAI,EAAE,yBAAyB,EAC/B,UAAU,EAAE,MAAM,GACjB,qBAAqB,CAKvB;AAED;;;;GAIG;AACH,wBAAgB,2BAA2B,CACzC,MAAM,EAAE,qBAAqB,EAC7B,IAAI,EAAE,yBAAyB,EAC/B,UAAU,EAAE,MAAM,GACjB,qBAAqB,CAsBvB"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
// Copyright (c) 2026 Tymofii Pidlisnyi
|
|
2
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
3
|
+
import { computeAuthorityDelegationId, signAuthorityDelegation, } from './canonical.js';
|
|
4
|
+
import { compareAuthority } from './compare.js';
|
|
5
|
+
import { validateAuthorityDelegationShape } from './schema.js';
|
|
6
|
+
function assertBody(body) {
|
|
7
|
+
const probe = {
|
|
8
|
+
...body,
|
|
9
|
+
delegation_id: `sha256:${'0'.repeat(64)}`,
|
|
10
|
+
signature: '0'.repeat(128),
|
|
11
|
+
};
|
|
12
|
+
const failures = validateAuthorityDelegationShape(probe);
|
|
13
|
+
if (failures.length > 0) {
|
|
14
|
+
throw new Error(`authority delegation body invalid: ${failures.map(item => `${item.code}: ${item.message}`).join('; ')}`);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
/** Create a deterministic v1 record from explicit body fields and an Ed25519 key. */
|
|
18
|
+
export function issueAuthorityDelegation(body, privateKey) {
|
|
19
|
+
assertBody(body);
|
|
20
|
+
const delegation_id = computeAuthorityDelegationId(body);
|
|
21
|
+
const unsigned = { ...body, delegation_id };
|
|
22
|
+
return { ...unsigned, signature: signAuthorityDelegation(unsigned, privateKey) };
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Issue a child after immediate-parent attenuation checks. The caller must first
|
|
26
|
+
* validate the complete parent chain and revocation state; this pure primitive
|
|
27
|
+
* cannot establish live ancestor status by itself.
|
|
28
|
+
*/
|
|
29
|
+
export function issueSubAuthorityDelegation(parent, body, privateKey) {
|
|
30
|
+
const parentFailures = validateAuthorityDelegationShape(parent);
|
|
31
|
+
if (parentFailures.length > 0) {
|
|
32
|
+
throw new Error(`authority delegation parent invalid: ${parentFailures.map(item => item.code).join(', ')}`);
|
|
33
|
+
}
|
|
34
|
+
assertBody(body);
|
|
35
|
+
if (body.parent_delegation_id !== parent.delegation_id) {
|
|
36
|
+
throw new Error('authority delegation parent mismatch');
|
|
37
|
+
}
|
|
38
|
+
if (body.issuer !== parent.subject) {
|
|
39
|
+
throw new Error('authority delegation chain continuity failure');
|
|
40
|
+
}
|
|
41
|
+
const issued = Date.parse(body.issued_at);
|
|
42
|
+
if (issued < Date.parse(parent.authority.time.not_before) ||
|
|
43
|
+
issued >= Date.parse(parent.authority.time.not_after)) {
|
|
44
|
+
throw new Error('authority delegation issued_at is outside parent validity');
|
|
45
|
+
}
|
|
46
|
+
const failures = compareAuthority(parent.authority, body.authority);
|
|
47
|
+
if (failures.length > 0) {
|
|
48
|
+
throw new Error(`authority delegation does not narrow: ${failures.map(item => item.code).join(', ')}`);
|
|
49
|
+
}
|
|
50
|
+
return issueAuthorityDelegation(body, privateKey);
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=issue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"issue.js","sourceRoot":"","sources":["../../../../src/v2/authority-delegation/issue.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,sCAAsC;AAEtC,OAAO,EACL,4BAA4B,EAC5B,uBAAuB,GACxB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,EAAE,gCAAgC,EAAE,MAAM,aAAa,CAAA;AAG9D,SAAS,UAAU,CAAC,IAA+B;IACjD,MAAM,KAAK,GAA0B;QACnC,GAAG,IAAI;QACP,aAAa,EAAE,UAAU,GAAG,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE;QACzC,SAAS,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC;KAC3B,CAAA;IACD,MAAM,QAAQ,GAAG,gCAAgC,CAAC,KAAK,CAAC,CAAA;IACxD,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,sCAAsC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,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AI,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC;QACrD,MAAM,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,SAAS,CAAC,EAAE,CAAC;QAC1D,MAAM,IAAI,KAAK,CAAC,2DAA2D,CAAC,CAAA;IAC9E,CAAC;IACD,MAAM,QAAQ,GAAG,gBAAgB,CAAC,MAAM,CAAC,SAAS,EAAE,IAAI,CAAC,SAAS,CAAC,CAAA;IACnE,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,yCAAyC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAA;IACxG,CAAC;IACD,OAAO,wBAAwB,CAAC,IAAI,EAAE,UAAU,CAAC,CAAA;AACnD,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { AuthorityDelegationV1 } from './types.js';
|
|
2
|
+
/** Strict untrusted-wire entry point: valid JSON, I-JSON names, and closed v1 schema. */
|
|
3
|
+
export declare function parseAuthorityDelegationJson(source: string): AuthorityDelegationV1;
|
|
4
|
+
//# sourceMappingURL=parse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../../../src/v2/authority-delegation/parse.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAA;AAsEvD,yFAAyF;AACzF,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,MAAM,GAAG,qBAAqB,CAWlF"}
|