@astrale-os/kernel-core 0.9.0-beta.39 → 0.9.0-beta.40

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.
Files changed (62) hide show
  1. package/dist/auth/index.d.ts +2 -2
  2. package/dist/auth/index.js +1 -1
  3. package/dist/auth/jwk/index.d.ts +1 -1
  4. package/dist/auth/jwk/index.js +1 -1
  5. package/dist/auth/jwk/thumbprint.d.ts +2 -0
  6. package/dist/auth/jwk/thumbprint.js +12 -6
  7. package/dist/auth/register/fingerprint/fingerprint.d.ts +25 -0
  8. package/dist/auth/register/fingerprint/fingerprint.js +31 -0
  9. package/dist/auth/register/fingerprint/index.d.ts +2 -0
  10. package/dist/auth/register/index.d.ts +5 -0
  11. package/dist/auth/register/request/admission.d.ts +3 -0
  12. package/dist/auth/register/request/admission.js +103 -0
  13. package/dist/auth/register/request/index.d.ts +3 -0
  14. package/dist/auth/register/request/limits.d.ts +6 -0
  15. package/dist/auth/register/request/limits.js +6 -0
  16. package/dist/auth/register/request/request.d.ts +19 -0
  17. package/dist/auth/{provision → register}/request/self-issuer.d.ts +1 -1
  18. package/dist/auth/{provision → register}/request/self-issuer.js +1 -1
  19. package/dist/auth/register/result/index.d.ts +1 -0
  20. package/dist/auth/register/result/result.d.ts +10 -0
  21. package/dist/schema/kernel/projection/project.js +4 -4
  22. package/dist/schema/kernel/schema.d.ts +40 -534
  23. package/dist/schema/kernel/schema.js +1 -1
  24. package/dist/schema/kernel/syscalls/contracts/index.d.ts +1 -1
  25. package/dist/schema/kernel/syscalls/contracts/index.js +1 -1
  26. package/dist/schema/kernel/syscalls/contracts/register.d.ts +20 -0
  27. package/dist/schema/kernel/syscalls/contracts/register.js +24 -0
  28. package/dist/schema/kernel/syscalls/declarations/index.d.ts +10 -257
  29. package/dist/schema/kernel/syscalls/declarations/index.js +2 -2
  30. package/dist/schema/kernel/syscalls/declarations/register.d.ts +23 -0
  31. package/dist/schema/kernel/syscalls/declarations/register.js +8 -0
  32. package/dist/schema/kernel/syscalls/descriptors/functions.d.ts +1 -1
  33. package/dist/schema/kernel/syscalls/descriptors/functions.js +1 -1
  34. package/dist/schema/kernel/syscalls/descriptors/index.d.ts +1 -1
  35. package/dist/schema/kernel/syscalls/descriptors/index.js +1 -1
  36. package/dist/schema/kernel/syscalls/index.d.ts +1 -1
  37. package/dist/schema/kernel/syscalls/index.js +1 -1
  38. package/dist/schema/kernel/syscalls/references/functions.d.ts +2 -2
  39. package/dist/schema/kernel/syscalls/references/functions.js +1 -1
  40. package/dist/schema/kernel/syscalls/references/index.d.ts +1 -1
  41. package/dist/schema/kernel/syscalls/references/index.js +1 -1
  42. package/package.json +1 -1
  43. package/dist/auth/provision/fingerprint/fingerprint.d.ts +0 -9
  44. package/dist/auth/provision/fingerprint/fingerprint.js +0 -30
  45. package/dist/auth/provision/fingerprint/index.d.ts +0 -2
  46. package/dist/auth/provision/index.d.ts +0 -5
  47. package/dist/auth/provision/request/admission.d.ts +0 -3
  48. package/dist/auth/provision/request/admission.js +0 -197
  49. package/dist/auth/provision/request/index.d.ts +0 -3
  50. package/dist/auth/provision/request/request.d.ts +0 -35
  51. package/dist/auth/provision/result/index.d.ts +0 -1
  52. package/dist/auth/provision/result/result.d.ts +0 -19
  53. package/dist/schema/kernel/syscalls/contracts/provision.d.ts +0 -301
  54. package/dist/schema/kernel/syscalls/contracts/provision.js +0 -28
  55. package/dist/schema/kernel/syscalls/declarations/provision.d.ts +0 -270
  56. package/dist/schema/kernel/syscalls/declarations/provision.js +0 -8
  57. /package/dist/auth/{provision → register}/fingerprint/index.js +0 -0
  58. /package/dist/auth/{provision → register}/index.js +0 -0
  59. /package/dist/auth/{provision → register}/request/index.js +0 -0
  60. /package/dist/auth/{provision → register}/request/request.js +0 -0
  61. /package/dist/auth/{provision → register}/result/index.js +0 -0
  62. /package/dist/auth/{provision → register}/result/result.js +0 -0
@@ -10,7 +10,7 @@ export type { Grant, UnresolvedGrant } from './grant/index.js';
10
10
  export type { Authentication, Identity, IdentityId, Subject } from './identity/index.js';
11
11
  export type { IssuerId } from './issuer/index.js';
12
12
  export type { JsonWebKey, KeyId } from './jwk/index.js';
13
- export type { AuthenticationProvision, IdentityProvision, ProvisionFingerprint, ProvisionRequest, ProvisionResult, ProvisionedIdentity, RequiredClaims, } from './provision/index.js';
13
+ export type { IdentityRegistration, RegisterFingerprint, RegisterFingerprintIdentity, RegisterFingerprintInput, RegisterRequest, RegisterResult, RegisteredIdentity, } from './register/index.js';
14
14
  export type { AuthenticationCandidate, AuthenticationTrust, StringPatternSet, TrustDecision, TrustRule, } from './trust/index.js';
15
15
  export * as attestation from './attestation/index.js';
16
16
  export * as authority from './authority/index.js';
@@ -22,5 +22,5 @@ export * as grant from './grant/index.js';
22
22
  export * as identity from './identity/index.js';
23
23
  export * as issuer from './issuer/index.js';
24
24
  export * as jwk from './jwk/index.js';
25
- export * as provision from './provision/index.js';
25
+ export * as register from './register/index.js';
26
26
  export * as trust from './trust/index.js';
@@ -9,5 +9,5 @@ export * as grant from './grant/index.js';
9
9
  export * as identity from './identity/index.js';
10
10
  export * as issuer from './issuer/index.js';
11
11
  export * as jwk from './jwk/index.js';
12
- export * as provision from './provision/index.js';
12
+ export * as register from './register/index.js';
13
13
  export * as trust from './trust/index.js';
@@ -1,3 +1,3 @@
1
1
  export { acceptPublic } from './public-key.js';
2
- export { thumbprint } from './thumbprint.js';
2
+ export { thumbprint, thumbprintMembers } from './thumbprint.js';
3
3
  export type { JsonWebKey, KeyId } from './public-key.js';
@@ -1,2 +1,2 @@
1
1
  export { acceptPublic } from './public-key.js';
2
- export { thumbprint } from './thumbprint.js';
2
+ export { thumbprint, thumbprintMembers } from './thumbprint.js';
@@ -1,3 +1,5 @@
1
1
  import type { JsonWebKey } from './public-key.js';
2
2
  /** Compute the RFC 7638 SHA-256 thumbprint of an admitted public key. */
3
3
  export declare function thumbprint(input: JsonWebKey): Promise<string>;
4
+ /** Return the exact RFC 7638 members that identify one public key's cryptographic material. */
5
+ export declare function thumbprintMembers(input: JsonWebKey): Readonly<Record<string, string>>;
@@ -1,19 +1,25 @@
1
1
  import { acceptPublic } from './public-key.js';
2
2
  /** Compute the RFC 7638 SHA-256 thumbprint of an admitted public key. */
3
3
  export async function thumbprint(input) {
4
- const key = acceptPublic(input);
5
- const canonical = JSON.stringify(members(key));
4
+ const canonical = JSON.stringify(thumbprintMembers(input));
6
5
  const digest = new Uint8Array(await crypto.subtle.digest('SHA-256', new TextEncoder().encode(canonical)));
7
6
  return base64url(digest);
8
7
  }
9
- function members(key) {
8
+ /** Return the exact RFC 7638 members that identify one public key's cryptographic material. */
9
+ export function thumbprintMembers(input) {
10
+ const key = acceptPublic(input);
10
11
  if (key.kty === 'EC') {
11
- return { crv: key.crv, kty: key.kty, x: key.x, y: key.y };
12
+ return Object.freeze({
13
+ crv: key.crv,
14
+ kty: key.kty,
15
+ x: key.x,
16
+ y: key.y,
17
+ });
12
18
  }
13
19
  if (key.kty === 'RSA') {
14
- return { e: key.e, kty: key.kty, n: key.n };
20
+ return Object.freeze({ e: key.e, kty: key.kty, n: key.n });
15
21
  }
16
- return { crv: key.crv, kty: key.kty, x: key.x };
22
+ return Object.freeze({ crv: key.crv, kty: key.kty, x: key.x });
17
23
  }
18
24
  function base64url(input) {
19
25
  let binary = '';
@@ -0,0 +1,25 @@
1
+ import type { Authentication, IdentityId } from '../../identity/index.js';
2
+ import type { JsonWebKey } from '../../jwk/index.js';
3
+ declare const REGISTER_FINGERPRINT: unique symbol;
4
+ /** Digest of the semantic request. Credential bytes and verifier evidence are excluded. */
5
+ export type RegisterFingerprint = `sha256:${string}` & {
6
+ readonly [REGISTER_FINGERPRINT]: true;
7
+ };
8
+ export type RegisterFingerprintIdentity = {
9
+ readonly id: IdentityId;
10
+ readonly mode: 'external';
11
+ readonly authentication: Authentication;
12
+ readonly publicKey?: never;
13
+ } | {
14
+ readonly id: IdentityId;
15
+ readonly mode: 'self';
16
+ readonly authentication: Authentication;
17
+ readonly publicKey: JsonWebKey;
18
+ };
19
+ export interface RegisterFingerprintInput {
20
+ readonly idempotencyKey: string;
21
+ readonly identities: readonly [RegisterFingerprintIdentity, ...RegisterFingerprintIdentity[]];
22
+ }
23
+ /** Compute a deterministic post-verification digest without retaining credential evidence. */
24
+ export declare function fingerprint(input: RegisterFingerprintInput): Promise<RegisterFingerprint>;
25
+ export {};
@@ -0,0 +1,31 @@
1
+ import * as portable from '@astrale-os/kernel-dsl/value';
2
+ import { thumbprint as jwkThumbprint } from '../../jwk/index.js';
3
+ /** Compute a deterministic post-verification digest without retaining credential evidence. */
4
+ export async function fingerprint(input) {
5
+ const identities = await Promise.all([...input.identities]
6
+ .sort((left, right) => compare(left.id, right.id))
7
+ .map(async (identity) => ({
8
+ id: identity.id,
9
+ mode: identity.mode,
10
+ iss: identity.authentication.iss,
11
+ sub: identity.authentication.sub,
12
+ ...(identity.mode === 'self' ? { publication: await publication(identity.publicKey) } : {}),
13
+ })));
14
+ const encoded = portable.json.encode(portable.accept({ version: 2, idempotencyKey: input.idempotencyKey, identities }));
15
+ const digest = await crypto.subtle.digest('SHA-256', Uint8Array.from(encoded).buffer);
16
+ return `sha256:${hex(new Uint8Array(digest))}`;
17
+ }
18
+ async function publication(publicKey) {
19
+ const thumbprint = await jwkThumbprint(publicKey);
20
+ return Object.freeze({
21
+ key: publicKey,
22
+ thumbprint,
23
+ slot: publicKey.kid === undefined ? `thumbprint:${thumbprint}` : `kid:${publicKey.kid}`,
24
+ });
25
+ }
26
+ function hex(input) {
27
+ return [...input].map((value) => value.toString(16).padStart(2, '0')).join('');
28
+ }
29
+ function compare(left, right) {
30
+ return left < right ? -1 : left > right ? 1 : 0;
31
+ }
@@ -0,0 +1,2 @@
1
+ export { fingerprint } from './fingerprint.js';
2
+ export type { RegisterFingerprint, RegisterFingerprintIdentity, RegisterFingerprintInput, } from './fingerprint.js';
@@ -0,0 +1,5 @@
1
+ export { fingerprint } from './fingerprint/index.js';
2
+ export type { RegisterFingerprint, RegisterFingerprintIdentity, RegisterFingerprintInput, } from './fingerprint/index.js';
3
+ export { accept, isSelfIssuer, selfIssuer } from './request/index.js';
4
+ export type { IdentityRegistration, RegisterRequest } from './request/index.js';
5
+ export type { RegisteredIdentity, RegisterResult } from './result/index.js';
@@ -0,0 +1,3 @@
1
+ import type { RegisterRequest } from './request.js';
2
+ /** Admit unknown input into the exact immutable existing-target Register language. */
3
+ export declare function accept(input: unknown): RegisterRequest;
@@ -0,0 +1,103 @@
1
+ import { NodeId } from '../../../graph/node/index.js';
2
+ import { AuthValueError } from '../../error.js';
3
+ import { acceptPublic } from '../../jwk/index.js';
4
+ import { REGISTER_REQUEST_LIMITS } from './limits.js';
5
+ const textEncoder = new TextEncoder();
6
+ /** Admit unknown input into the exact immutable existing-target Register language. */
7
+ export function accept(input) {
8
+ if (!isRecord(input))
9
+ invalid('', 'Expected a Register request object');
10
+ exact(input, ['idempotencyKey', 'identities'], '');
11
+ if (typeof input.idempotencyKey !== 'string' ||
12
+ input.idempotencyKey.length === 0 ||
13
+ input.idempotencyKey.length > REGISTER_REQUEST_LIMITS.idempotencyKeyCharacters ||
14
+ textEncoder.encode(input.idempotencyKey).byteLength >
15
+ REGISTER_REQUEST_LIMITS.idempotencyKeyBytes) {
16
+ invalid('/idempotencyKey', 'Expected a bounded non-empty idempotency key');
17
+ }
18
+ if (!Array.isArray(input.identities) ||
19
+ input.identities.length === 0 ||
20
+ input.identities.length > REGISTER_REQUEST_LIMITS.identities) {
21
+ invalid('/identities', 'Expected a bounded non-empty Identity register array');
22
+ }
23
+ const identities = input.identities
24
+ .map((candidate, index) => identityInput(candidate, `/identities/${index}`))
25
+ .sort((left, right) => compare(left.id, right.id));
26
+ for (let index = 1; index < identities.length; index += 1) {
27
+ if (identities[index - 1].id === identities[index].id) {
28
+ invalid(`/identities/${index}/id`, 'Duplicate Identity target');
29
+ }
30
+ }
31
+ return Object.freeze({
32
+ idempotencyKey: input.idempotencyKey,
33
+ identities: Object.freeze(identities),
34
+ });
35
+ }
36
+ function identityInput(input, path) {
37
+ if (!isRecord(input))
38
+ invalid(path, 'Expected an Identity register object');
39
+ if (input.mode !== 'external' && input.mode !== 'self') {
40
+ invalid(`${path}/mode`, 'Expected external or self');
41
+ }
42
+ exact(input, input.mode === 'self'
43
+ ? ['credential', 'id', 'mode', 'publicKey']
44
+ : ['credential', 'id', 'mode'], path);
45
+ let id;
46
+ try {
47
+ if (typeof input.id !== 'string')
48
+ throw new TypeError('IdentityId must be text.');
49
+ id = NodeId(input.id);
50
+ }
51
+ catch (cause) {
52
+ invalid(`${path}/id`, 'Expected an IdentityId', cause);
53
+ }
54
+ const credential = credentialInput(input.credential, `${path}/credential`);
55
+ if (input.mode === 'external') {
56
+ return Object.freeze({ id, mode: 'external', credential });
57
+ }
58
+ return Object.freeze({
59
+ id,
60
+ mode: 'self',
61
+ publicKey: publicJwk(input.publicKey, `${path}/publicKey`),
62
+ credential,
63
+ });
64
+ }
65
+ function credentialInput(input, path) {
66
+ if (typeof input === 'string') {
67
+ const bytes = textEncoder.encode(input).byteLength;
68
+ if (bytes === 0 || bytes > REGISTER_REQUEST_LIMITS.credentialBytes) {
69
+ invalid(path, `Credential must contain 1-${REGISTER_REQUEST_LIMITS.credentialBytes} bytes`);
70
+ }
71
+ return input;
72
+ }
73
+ if (!(input instanceof Uint8Array) ||
74
+ input.byteLength === 0 ||
75
+ input.byteLength > REGISTER_REQUEST_LIMITS.credentialBytes) {
76
+ invalid(path, `Credential must contain 1-${REGISTER_REQUEST_LIMITS.credentialBytes} bytes`);
77
+ }
78
+ return input.slice();
79
+ }
80
+ function publicJwk(input, path) {
81
+ try {
82
+ return acceptPublic(input);
83
+ }
84
+ catch (cause) {
85
+ invalid(path, 'Expected a thumbprintable public JWK', cause);
86
+ }
87
+ }
88
+ function exact(input, expected, path) {
89
+ const actual = Object.keys(input).sort(compare);
90
+ const wanted = [...expected].sort(compare);
91
+ if (actual.length !== wanted.length || actual.some((key, index) => key !== wanted[index])) {
92
+ invalid(path, `Expected exactly ${expected.join(', ')}`);
93
+ }
94
+ }
95
+ function isRecord(input) {
96
+ return input !== null && typeof input === 'object' && !Array.isArray(input);
97
+ }
98
+ function compare(left, right) {
99
+ return left < right ? -1 : left > right ? 1 : 0;
100
+ }
101
+ function invalid(path, message, cause) {
102
+ throw new AuthValueError('AUTH_REGISTER_REQUEST_INVALID', message, path, cause === undefined ? undefined : { cause });
103
+ }
@@ -0,0 +1,3 @@
1
+ export { accept } from './admission.js';
2
+ export { isSelfIssuer, selfIssuer } from './self-issuer.js';
3
+ export type { IdentityRegistration, RegisterRequest } from './request.js';
@@ -0,0 +1,6 @@
1
+ export declare const REGISTER_REQUEST_LIMITS: Readonly<{
2
+ credentialBytes: number;
3
+ idempotencyKeyBytes: 1024;
4
+ idempotencyKeyCharacters: 256;
5
+ identities: 256;
6
+ }>;
@@ -0,0 +1,6 @@
1
+ export const REGISTER_REQUEST_LIMITS = Object.freeze({
2
+ credentialBytes: 64 * 1024,
3
+ idempotencyKeyBytes: 1_024,
4
+ idempotencyKeyCharacters: 256,
5
+ identities: 256,
6
+ });
@@ -0,0 +1,19 @@
1
+ import type { CredentialInput } from '../../credential/input/index.js';
2
+ import type { IdentityId } from '../../identity/index.js';
3
+ import type { JsonWebKey } from '../../jwk/index.js';
4
+ export type IdentityRegistration = {
5
+ readonly id: IdentityId;
6
+ readonly mode: 'external';
7
+ readonly credential: CredentialInput;
8
+ readonly publicKey?: never;
9
+ } | {
10
+ readonly id: IdentityId;
11
+ readonly mode: 'self';
12
+ readonly publicKey: JsonWebKey;
13
+ readonly credential: CredentialInput;
14
+ };
15
+ /** Claim credential-evidenced Authentication for existing Identity-bearing Nodes. */
16
+ export interface RegisterRequest {
17
+ readonly idempotencyKey: string;
18
+ readonly identities: readonly [IdentityRegistration, ...IdentityRegistration[]];
19
+ }
@@ -1,6 +1,6 @@
1
1
  import type { IssuerId } from '../../issuer/index.js';
2
2
  import type { JsonWebKey } from '../../jwk/index.js';
3
- /** Build the hosted issuer controlled by one self-provisioned public key. */
3
+ /** Build the hosted issuer controlled by one self-registered public key. */
4
4
  export declare function selfIssuer(kernel: IssuerId, publicKey: JsonWebKey): Promise<IssuerId>;
5
5
  /** Whether an issuer is one exact key-bound issuer hosted by this Kernel. */
6
6
  export declare function isSelfIssuer(kernel: IssuerId, candidate: IssuerId): boolean;
@@ -1,6 +1,6 @@
1
1
  import { accept as acceptIssuer } from '../../issuer/index.js';
2
2
  import { thumbprint } from '../../jwk/index.js';
3
- /** Build the hosted issuer controlled by one self-provisioned public key. */
3
+ /** Build the hosted issuer controlled by one self-registered public key. */
4
4
  export async function selfIssuer(kernel, publicKey) {
5
5
  const base = String(kernel).replace(/\/+$/u, '');
6
6
  return acceptIssuer(`${base}/iss/${await thumbprint(publicKey)}`);
@@ -0,0 +1 @@
1
+ export type { RegisteredIdentity, RegisterResult } from './result.js';
@@ -0,0 +1,10 @@
1
+ import type { IdentityId, Subject } from '../../identity/index.js';
2
+ import type { IssuerId } from '../../issuer/index.js';
3
+ export interface RegisteredIdentity {
4
+ readonly id: IdentityId;
5
+ readonly iss: IssuerId;
6
+ readonly sub: Subject;
7
+ }
8
+ export interface RegisterResult {
9
+ readonly identities: readonly [RegisteredIdentity, ...RegisteredIdentity[]];
10
+ }
@@ -64,7 +64,7 @@ export function project(domain) {
64
64
  }));
65
65
  }
66
66
  for (const [slug, declaration] of Object.entries(domainSchema.core.nodes)) {
67
- assertIdentityAuthenticationPair(domain, declaration.class, declaration.properties, slug);
67
+ assertIdentityAuthenticationUnowned(domain, declaration.class, declaration.properties, slug);
68
68
  const path = PathValue.project({ origin: domain.origin, kind: 'core', name: slug }).raw;
69
69
  const created = addNode(coreNodes, path, ClassKeyValue.of(declaration.class), declaration.properties, coreLocations);
70
70
  addEdge(locators, created, persistedDomainEndpoint, K.classes.of_domain.ref, normalizeProperties({
@@ -94,7 +94,7 @@ export function project(domain) {
94
94
  }),
95
95
  });
96
96
  }
97
- function assertIdentityAuthenticationPair(domain, classRef, properties, slug) {
97
+ function assertIdentityAuthenticationUnowned(domain, classRef, properties, slug) {
98
98
  const definition = domain.definition(classRef);
99
99
  if (definition?.ref.kind !== 'class' ||
100
100
  definition.kind !== 'node' ||
@@ -103,8 +103,8 @@ function assertIdentityAuthenticationPair(domain, classRef, properties, slug) {
103
103
  }
104
104
  const hasIssuer = Object.hasOwn(properties, K.classes.Identity.properties.iss.key);
105
105
  const hasSubject = Object.hasOwn(properties, K.classes.Identity.properties.sub.key);
106
- if (hasIssuer !== hasSubject) {
107
- throw new ProjectionError('PROJECTION_INVALID', `Core Identity ${slug} must declare both iss and sub or neither.`);
106
+ if (hasIssuer || hasSubject) {
107
+ throw new ProjectionError('PROJECTION_INVALID', `Core Identity ${domain.origin}:core.${slug} cannot declare protected Authentication properties iss or sub.`);
108
108
  }
109
109
  }
110
110
  function projectionLocations(paths) {