@astrale-os/sdk 0.1.0 → 0.1.2

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 (193) hide show
  1. package/dist/auth/authenticate.d.ts +24 -0
  2. package/dist/auth/authenticate.d.ts.map +1 -0
  3. package/dist/auth/authenticate.js +29 -0
  4. package/dist/auth/authenticate.js.map +1 -0
  5. package/dist/auth/check.d.ts +39 -0
  6. package/dist/auth/check.d.ts.map +1 -0
  7. package/dist/auth/check.js +54 -0
  8. package/dist/auth/check.js.map +1 -0
  9. package/dist/auth/compose.d.ts +22 -0
  10. package/dist/auth/compose.d.ts.map +1 -0
  11. package/dist/auth/compose.js +23 -0
  12. package/dist/auth/compose.js.map +1 -0
  13. package/dist/auth/errors.d.ts +16 -0
  14. package/dist/auth/errors.d.ts.map +1 -0
  15. package/dist/auth/errors.js +26 -0
  16. package/dist/auth/errors.js.map +1 -0
  17. package/dist/auth/identity.d.ts +16 -0
  18. package/dist/auth/identity.d.ts.map +1 -0
  19. package/dist/auth/identity.js +2 -0
  20. package/dist/auth/identity.js.map +1 -0
  21. package/dist/auth/index.d.ts +12 -0
  22. package/dist/auth/index.d.ts.map +1 -0
  23. package/dist/auth/index.js +9 -0
  24. package/dist/auth/index.js.map +1 -0
  25. package/dist/auth/kernel-client.d.ts +28 -0
  26. package/dist/auth/kernel-client.d.ts.map +1 -0
  27. package/dist/auth/kernel-client.js +84 -0
  28. package/dist/auth/kernel-client.js.map +1 -0
  29. package/dist/auth/resolve.d.ts +19 -0
  30. package/dist/auth/resolve.d.ts.map +1 -0
  31. package/dist/auth/resolve.js +43 -0
  32. package/dist/auth/resolve.js.map +1 -0
  33. package/dist/auth/sign.d.ts +15 -0
  34. package/dist/auth/sign.d.ts.map +1 -0
  35. package/dist/auth/sign.js +24 -0
  36. package/dist/auth/sign.js.map +1 -0
  37. package/dist/auth/verify.d.ts +26 -0
  38. package/dist/auth/verify.d.ts.map +1 -0
  39. package/dist/auth/verify.js +96 -0
  40. package/dist/auth/verify.js.map +1 -0
  41. package/dist/define/index.d.ts +5 -0
  42. package/dist/define/index.d.ts.map +1 -0
  43. package/dist/define/index.js +3 -0
  44. package/dist/define/index.js.map +1 -0
  45. package/dist/define/remote-function.d.ts +86 -0
  46. package/dist/define/remote-function.d.ts.map +1 -0
  47. package/dist/define/remote-function.js +25 -0
  48. package/dist/define/remote-function.js.map +1 -0
  49. package/dist/define/view.d.ts +86 -0
  50. package/dist/define/view.d.ts.map +1 -0
  51. package/dist/define/view.js +28 -0
  52. package/dist/define/view.js.map +1 -0
  53. package/dist/deploy/check.d.ts +30 -0
  54. package/dist/deploy/check.d.ts.map +1 -0
  55. package/dist/deploy/check.js +82 -0
  56. package/dist/deploy/check.js.map +1 -0
  57. package/dist/deploy/hash-spec.d.ts +9 -0
  58. package/dist/deploy/hash-spec.d.ts.map +1 -0
  59. package/dist/deploy/hash-spec.js +29 -0
  60. package/dist/deploy/hash-spec.js.map +1 -0
  61. package/dist/deploy/index.d.ts +4 -0
  62. package/dist/deploy/index.d.ts.map +1 -0
  63. package/dist/deploy/index.js +4 -0
  64. package/dist/deploy/index.js.map +1 -0
  65. package/dist/deploy/meta.d.ts +18 -0
  66. package/dist/deploy/meta.d.ts.map +1 -0
  67. package/dist/deploy/meta.js +22 -0
  68. package/dist/deploy/meta.js.map +1 -0
  69. package/dist/dispatch/authorize.d.ts +14 -0
  70. package/dist/dispatch/authorize.d.ts.map +1 -0
  71. package/dist/dispatch/authorize.js +24 -0
  72. package/dist/dispatch/authorize.js.map +1 -0
  73. package/dist/dispatch/call-remote.d.ts +35 -0
  74. package/dist/dispatch/call-remote.d.ts.map +1 -0
  75. package/dist/dispatch/call-remote.js +37 -0
  76. package/dist/dispatch/call-remote.js.map +1 -0
  77. package/dist/dispatch/dispatcher.d.ts +60 -0
  78. package/dist/dispatch/dispatcher.d.ts.map +1 -0
  79. package/dist/dispatch/dispatcher.js +177 -0
  80. package/dist/dispatch/dispatcher.js.map +1 -0
  81. package/dist/dispatch/errors.d.ts +47 -0
  82. package/dist/dispatch/errors.d.ts.map +1 -0
  83. package/dist/dispatch/errors.js +76 -0
  84. package/dist/dispatch/errors.js.map +1 -0
  85. package/dist/dispatch/execute.d.ts +33 -0
  86. package/dist/dispatch/execute.d.ts.map +1 -0
  87. package/dist/dispatch/execute.js +24 -0
  88. package/dist/dispatch/execute.js.map +1 -0
  89. package/dist/dispatch/identity.d.ts +73 -0
  90. package/dist/dispatch/identity.d.ts.map +1 -0
  91. package/dist/dispatch/identity.js +106 -0
  92. package/dist/dispatch/identity.js.map +1 -0
  93. package/dist/dispatch/index.d.ts +8 -0
  94. package/dist/dispatch/index.d.ts.map +1 -0
  95. package/dist/dispatch/index.js +8 -0
  96. package/dist/dispatch/index.js.map +1 -0
  97. package/dist/dispatch/resolve.d.ts +27 -0
  98. package/dist/dispatch/resolve.d.ts.map +1 -0
  99. package/dist/dispatch/resolve.js +65 -0
  100. package/dist/dispatch/resolve.js.map +1 -0
  101. package/dist/dispatch/self.d.ts +27 -0
  102. package/dist/dispatch/self.d.ts.map +1 -0
  103. package/dist/dispatch/self.js +25 -0
  104. package/dist/dispatch/self.js.map +1 -0
  105. package/dist/dispatch/validate.d.ts +35 -0
  106. package/dist/dispatch/validate.d.ts.map +1 -0
  107. package/dist/dispatch/validate.js +27 -0
  108. package/dist/dispatch/validate.js.map +1 -0
  109. package/dist/domain/build-spec.d.ts +37 -0
  110. package/dist/domain/build-spec.d.ts.map +1 -0
  111. package/dist/domain/build-spec.js +95 -0
  112. package/dist/domain/build-spec.js.map +1 -0
  113. package/dist/domain/contract.d.ts +17 -0
  114. package/dist/domain/contract.d.ts.map +1 -0
  115. package/dist/domain/contract.js +26 -0
  116. package/dist/domain/contract.js.map +1 -0
  117. package/dist/domain/define.d.ts +82 -0
  118. package/dist/domain/define.d.ts.map +1 -0
  119. package/dist/domain/define.js +99 -0
  120. package/dist/domain/define.js.map +1 -0
  121. package/dist/domain/extend-core.d.ts +49 -0
  122. package/dist/domain/extend-core.d.ts.map +1 -0
  123. package/dist/domain/extend-core.js +182 -0
  124. package/dist/domain/extend-core.js.map +1 -0
  125. package/dist/domain/index.d.ts +5 -0
  126. package/dist/domain/index.d.ts.map +1 -0
  127. package/dist/domain/index.js +4 -0
  128. package/dist/domain/index.js.map +1 -0
  129. package/dist/index.d.ts +19 -0
  130. package/dist/index.d.ts.map +1 -0
  131. package/dist/index.js +32 -0
  132. package/dist/index.js.map +1 -0
  133. package/dist/method/class.d.ts +70 -0
  134. package/dist/method/class.d.ts.map +1 -0
  135. package/dist/method/class.js +26 -0
  136. package/dist/method/class.js.map +1 -0
  137. package/dist/method/context.d.ts +43 -0
  138. package/dist/method/context.d.ts.map +1 -0
  139. package/dist/method/context.js +10 -0
  140. package/dist/method/context.js.map +1 -0
  141. package/dist/method/index.d.ts +6 -0
  142. package/dist/method/index.d.ts.map +1 -0
  143. package/dist/method/index.js +3 -0
  144. package/dist/method/index.js.map +1 -0
  145. package/dist/method/single.d.ts +88 -0
  146. package/dist/method/single.d.ts.map +1 -0
  147. package/dist/method/single.js +18 -0
  148. package/dist/method/single.js.map +1 -0
  149. package/dist/server/auxiliary-routes.d.ts +44 -0
  150. package/dist/server/auxiliary-routes.d.ts.map +1 -0
  151. package/dist/server/auxiliary-routes.js +237 -0
  152. package/dist/server/auxiliary-routes.js.map +1 -0
  153. package/dist/server/config.d.ts +83 -0
  154. package/dist/server/config.d.ts.map +1 -0
  155. package/dist/server/config.js +8 -0
  156. package/dist/server/config.js.map +1 -0
  157. package/dist/server/create.d.ts +21 -0
  158. package/dist/server/create.d.ts.map +1 -0
  159. package/dist/server/create.js +210 -0
  160. package/dist/server/create.js.map +1 -0
  161. package/dist/server/handle.d.ts +35 -0
  162. package/dist/server/handle.d.ts.map +1 -0
  163. package/dist/server/handle.js +9 -0
  164. package/dist/server/handle.js.map +1 -0
  165. package/dist/server/index.d.ts +11 -0
  166. package/dist/server/index.d.ts.map +1 -0
  167. package/dist/server/index.js +8 -0
  168. package/dist/server/index.js.map +1 -0
  169. package/dist/server/jwks.d.ts +11 -0
  170. package/dist/server/jwks.d.ts.map +1 -0
  171. package/dist/server/jwks.js +15 -0
  172. package/dist/server/jwks.js.map +1 -0
  173. package/dist/server/require-env.d.ts +15 -0
  174. package/dist/server/require-env.d.ts.map +1 -0
  175. package/dist/server/require-env.js +21 -0
  176. package/dist/server/require-env.js.map +1 -0
  177. package/dist/server/serving-url.d.ts +14 -0
  178. package/dist/server/serving-url.d.ts.map +1 -0
  179. package/dist/server/serving-url.js +28 -0
  180. package/dist/server/serving-url.js.map +1 -0
  181. package/dist/server/start.d.ts +11 -0
  182. package/dist/server/start.d.ts.map +1 -0
  183. package/dist/server/start.js +30 -0
  184. package/dist/server/start.js.map +1 -0
  185. package/dist/server/worker-entry.d.ts +60 -0
  186. package/dist/server/worker-entry.d.ts.map +1 -0
  187. package/dist/server/worker-entry.js +79 -0
  188. package/dist/server/worker-entry.js.map +1 -0
  189. package/dist/server/worker-meta.d.ts +6 -0
  190. package/dist/server/worker-meta.d.ts.map +1 -0
  191. package/dist/server/worker-meta.js +10 -0
  192. package/dist/server/worker-meta.js.map +1 -0
  193. package/package.json +2 -2
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Authentication orchestrator.
3
+ *
4
+ * Verifies an inbound credential, extracts the delegation it carries,
5
+ * and binds a `BoundClientSessionView` for outbound kernel calls. Delegates
6
+ * the real work to `verify`, `compose` + `sign` (inside `kernel-client`),
7
+ * and returns a generic `Authenticated` result plus the bound view.
8
+ */
9
+ import type { FnMap } from '@astrale-os/kernel-client';
10
+ import type { BoundClientSessionView } from '@astrale-os/kernel-client/session';
11
+ import type { Authenticated, CredentialInput } from '@astrale-os/kernel-core';
12
+ import type { RemoteIdentityConfig } from './identity';
13
+ export type AuthenticateResult = {
14
+ authenticated: Authenticated;
15
+ kernel: BoundClientSessionView<FnMap> | null;
16
+ };
17
+ /**
18
+ * Verifies an inbound credential and binds a call-back kernel view. The `sub`
19
+ * claim on the outbound credential is the function's own identity, taken from
20
+ * `config.subject` (the function node's path), so the kernel matches an
21
+ * existing function identity instead of provisioning a generic one.
22
+ */
23
+ export declare function authenticateRequest(credential: CredentialInput, config: RemoteIdentityConfig): Promise<AuthenticateResult>;
24
+ //# sourceMappingURL=authenticate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authenticate.d.ts","sourceRoot":"","sources":["../../src/auth/authenticate.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAA;AACtD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAA;AAC/E,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AAI7E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAKtD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,aAAa,EAAE,aAAa,CAAA;IAC5B,MAAM,EAAE,sBAAsB,CAAC,KAAK,CAAC,GAAG,IAAI,CAAA;CAC7C,CAAA;AAED;;;;;GAKG;AACH,wBAAsB,mBAAmB,CACvC,UAAU,EAAE,eAAe,EAC3B,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,kBAAkB,CAAC,CAgB7B"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Authentication orchestrator.
3
+ *
4
+ * Verifies an inbound credential, extracts the delegation it carries,
5
+ * and binds a `BoundClientSessionView` for outbound kernel calls. Delegates
6
+ * the real work to `verify`, `compose` + `sign` (inside `kernel-client`),
7
+ * and returns a generic `Authenticated` result plus the bound view.
8
+ */
9
+ import { IdentityId, selfGrant } from '@astrale-os/kernel-core';
10
+ import { bindKernel } from './kernel-client';
11
+ import { verifyInboundCredential } from './verify';
12
+ /**
13
+ * Verifies an inbound credential and binds a call-back kernel view. The `sub`
14
+ * claim on the outbound credential is the function's own identity, taken from
15
+ * `config.subject` (the function node's path), so the kernel matches an
16
+ * existing function identity instead of provisioning a generic one.
17
+ */
18
+ export async function authenticateRequest(credential, config) {
19
+ const { verified, issuer, attestation, delegation } = await verifyInboundCredential(credential, config);
20
+ const authenticated = {
21
+ credential: { raw: credential, verified },
22
+ grant: selfGrant(IdentityId(verified.sub)),
23
+ attestation,
24
+ delegation,
25
+ };
26
+ const kernel = await bindKernel(delegation, issuer, config);
27
+ return { authenticated, kernel };
28
+ }
29
+ //# sourceMappingURL=authenticate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authenticate.js","sourceRoot":"","sources":["../../src/auth/authenticate.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAA;AAI/D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAA;AAOlD;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,mBAAmB,CACvC,UAA2B,EAC3B,MAA4B;IAE5B,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,WAAW,EAAE,UAAU,EAAE,GAAG,MAAM,uBAAuB,CACjF,UAAU,EACV,MAAM,CACP,CAAA;IAED,MAAM,aAAa,GAAkB;QACnC,UAAU,EAAE,EAAE,GAAG,EAAE,UAAU,EAAE,QAAQ,EAAE;QACzC,KAAK,EAAE,SAAS,CAAC,UAAU,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;QAC1C,WAAW;QACX,UAAU;KACX,CAAA;IAED,MAAM,MAAM,GAAG,MAAM,UAAU,CAAC,UAAU,EAAE,MAAM,EAAE,MAAM,CAAC,CAAA;IAE3D,OAAO,EAAE,aAAa,EAAE,MAAM,EAAE,CAAA;AAClC,CAAC"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Permission-check helpers for `RemoteHandler.authorize` hooks.
3
+ *
4
+ * The kernel already enforces `has_perm` independently — these helpers just
5
+ * give worker authors a one-line ergonomic way to fail-fast in `authorize`
6
+ * (so the dispatch never even calls `execute`) instead of letting the
7
+ * downstream `kernel.call` raise a less specific error mid-flight.
8
+ *
9
+ * Pattern:
10
+ *
11
+ * ```ts
12
+ * remoteMethod(WorkerSchema, 'Project', 'addMember', {
13
+ * remoteUrl: BASE_URL,
14
+ * authorize: async ({ self, auth, kernel }) => {
15
+ * await assertPerm(kernel, self.path.raw, auth.principal, EDIT)
16
+ * },
17
+ * execute: async (ctx) => { ... },
18
+ * })
19
+ * ```
20
+ *
21
+ * Helpers throw `AuthorizationDeniedError` so the dispatch wrapper can
22
+ * surface them to the client as `PERMISSION_DENIED` cleanly.
23
+ */
24
+ import type { FnMap } from '@astrale-os/kernel-client';
25
+ import type { BoundClientSessionView } from '@astrale-os/kernel-client/session';
26
+ import type { IdentityId } from '@astrale-os/kernel-core';
27
+ export { ALL, EDIT, READ, SHARE, USE } from '@astrale-os/kernel-core';
28
+ /**
29
+ * Throws `AuthorizationDeniedError` if `principal` lacks `requiredBits` on
30
+ * `target`. `requiredBits` is a bitmask — pass `READ | EDIT` to require both.
31
+ *
32
+ * Implementation: calls `@<principal>::checkPerm` on the kernel (the
33
+ * `checkPerm` syscall lives on the Identity, not the target). Cheap; adds
34
+ * one round-trip to the dispatch path.
35
+ */
36
+ export declare function assertPerm(kernel: BoundClientSessionView<FnMap> | null, target: string, principal: IdentityId | null | undefined, requiredBits: number): Promise<void>;
37
+ /** Shortcut for "caller has SHARE bit on target" (the closest thing to "owns it"). */
38
+ export declare function requireOwnership(kernel: BoundClientSessionView<FnMap> | null, target: string, principal: IdentityId | null | undefined): Promise<void>;
39
+ //# sourceMappingURL=check.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check.d.ts","sourceRoot":"","sources":["../../src/auth/check.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAA;AACtD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mCAAmC,CAAA;AAC/E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAMzD,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,yBAAyB,CAAA;AAErE;;;;;;;GAOG;AACH,wBAAsB,UAAU,CAC9B,MAAM,EAAE,sBAAsB,CAAC,KAAK,CAAC,GAAG,IAAI,EAC5C,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,UAAU,GAAG,IAAI,GAAG,SAAS,EACxC,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,IAAI,CAAC,CAgBf;AAED,sFAAsF;AACtF,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,sBAAsB,CAAC,KAAK,CAAC,GAAG,IAAI,EAC5C,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,UAAU,GAAG,IAAI,GAAG,SAAS,GACvC,OAAO,CAAC,IAAI,CAAC,CAEf"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Permission-check helpers for `RemoteHandler.authorize` hooks.
3
+ *
4
+ * The kernel already enforces `has_perm` independently — these helpers just
5
+ * give worker authors a one-line ergonomic way to fail-fast in `authorize`
6
+ * (so the dispatch never even calls `execute`) instead of letting the
7
+ * downstream `kernel.call` raise a less specific error mid-flight.
8
+ *
9
+ * Pattern:
10
+ *
11
+ * ```ts
12
+ * remoteMethod(WorkerSchema, 'Project', 'addMember', {
13
+ * remoteUrl: BASE_URL,
14
+ * authorize: async ({ self, auth, kernel }) => {
15
+ * await assertPerm(kernel, self.path.raw, auth.principal, EDIT)
16
+ * },
17
+ * execute: async (ctx) => { ... },
18
+ * })
19
+ * ```
20
+ *
21
+ * Helpers throw `AuthorizationDeniedError` so the dispatch wrapper can
22
+ * surface them to the client as `PERMISSION_DENIED` cleanly.
23
+ */
24
+ import { SHARE } from '@astrale-os/kernel-core';
25
+ import { AuthorizationDeniedError } from '../dispatch/errors';
26
+ export { ALL, EDIT, READ, SHARE, USE } from '@astrale-os/kernel-core';
27
+ /**
28
+ * Throws `AuthorizationDeniedError` if `principal` lacks `requiredBits` on
29
+ * `target`. `requiredBits` is a bitmask — pass `READ | EDIT` to require both.
30
+ *
31
+ * Implementation: calls `@<principal>::checkPerm` on the kernel (the
32
+ * `checkPerm` syscall lives on the Identity, not the target). Cheap; adds
33
+ * one round-trip to the dispatch path.
34
+ */
35
+ export async function assertPerm(kernel, target, principal, requiredBits) {
36
+ if (!kernel) {
37
+ throw new AuthorizationDeniedError('No kernel client — cannot verify permissions');
38
+ }
39
+ if (!principal) {
40
+ throw new AuthorizationDeniedError('No authenticated principal');
41
+ }
42
+ const ok = (await kernel.call(`@${principal}::checkPerm`, {
43
+ node: target,
44
+ perms: requiredBits,
45
+ }));
46
+ if (!ok) {
47
+ throw new AuthorizationDeniedError(`Permission denied on "${target}" — required bits=${requiredBits} for principal "${principal}"`);
48
+ }
49
+ }
50
+ /** Shortcut for "caller has SHARE bit on target" (the closest thing to "owns it"). */
51
+ export async function requireOwnership(kernel, target, principal) {
52
+ await assertPerm(kernel, target, principal, SHARE);
53
+ }
54
+ //# sourceMappingURL=check.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"check.js","sourceRoot":"","sources":["../../src/auth/check.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAMH,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAA;AAE/C,OAAO,EAAE,wBAAwB,EAAE,MAAM,oBAAoB,CAAA;AAE7D,OAAO,EAAE,GAAG,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,yBAAyB,CAAA;AAErE;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAC9B,MAA4C,EAC5C,MAAc,EACd,SAAwC,EACxC,YAAoB;IAEpB,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,wBAAwB,CAAC,8CAA8C,CAAC,CAAA;IACpF,CAAC;IACD,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,MAAM,IAAI,wBAAwB,CAAC,4BAA4B,CAAC,CAAA;IAClE,CAAC;IACD,MAAM,EAAE,GAAG,CAAC,MAAM,MAAM,CAAC,IAAI,CAAC,IAAI,SAAS,aAAa,EAAE;QACxD,IAAI,EAAE,MAAM;QACZ,KAAK,EAAE,YAAY;KACpB,CAAC,CAAY,CAAA;IACd,IAAI,CAAC,EAAE,EAAE,CAAC;QACR,MAAM,IAAI,wBAAwB,CAChC,yBAAyB,MAAM,qBAAqB,YAAY,mBAAmB,SAAS,GAAG,CAChG,CAAA;IACH,CAAC;AACH,CAAC;AAED,sFAAsF;AACtF,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,MAA4C,EAC5C,MAAc,EACd,SAAwC;IAExC,MAAM,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,KAAK,CAAC,CAAA;AACpD,CAAC"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Outbound grant expression building.
3
+ *
4
+ * Builds a composed grant expression for kernel calls:
5
+ * grant = union(credential(delegationJWT), self)
6
+ *
7
+ * The kernel resolves this by verifying the delegation JWT (kernel-signed)
8
+ * to get the caller's scoped identity, and resolving self to the function's
9
+ * identity. Union means either identity's permissions work.
10
+ */
11
+ import type { Delegation } from '@astrale-os/kernel-core';
12
+ /**
13
+ * Build the grant expression that unions the caller's delegated access
14
+ * with the function's own identity.
15
+ *
16
+ * @param delegation - Delegation extracted from the inbound credential
17
+ * @returns The unresolved grant object with version and expression
18
+ */
19
+ export declare function buildComposedGrant(delegation: Delegation): {
20
+ grant: import("@astrale-os/kernel-core").UnresolvedGrant;
21
+ };
22
+ //# sourceMappingURL=compose.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compose.d.ts","sourceRoot":"","sources":["../../src/auth/compose.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AASzD;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,UAAU;IAE9C,KAAK;EACf"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Outbound grant expression building.
3
+ *
4
+ * Builds a composed grant expression for kernel calls:
5
+ * grant = union(credential(delegationJWT), self)
6
+ *
7
+ * The kernel resolves this by verifying the delegation JWT (kernel-signed)
8
+ * to get the caller's scoped identity, and resolving self to the function's
9
+ * identity. Union means either identity's permissions work.
10
+ */
11
+ import { createUnresolvedGrant, unresolvedCredential, unresolvedSelf, unresolvedUnion, } from '@astrale-os/kernel-core';
12
+ /**
13
+ * Build the grant expression that unions the caller's delegated access
14
+ * with the function's own identity.
15
+ *
16
+ * @param delegation - Delegation extracted from the inbound credential
17
+ * @returns The unresolved grant object with version and expression
18
+ */
19
+ export function buildComposedGrant(delegation) {
20
+ const expr = unresolvedUnion(unresolvedCredential(delegation.credential), unresolvedSelf());
21
+ return { grant: createUnresolvedGrant(expr) };
22
+ }
23
+ //# sourceMappingURL=compose.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compose.js","sourceRoot":"","sources":["../../src/auth/compose.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,EACL,qBAAqB,EACrB,oBAAoB,EACpB,cAAc,EACd,eAAe,GAChB,MAAM,yBAAyB,CAAA;AAEhC;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,UAAsB;IACvD,MAAM,IAAI,GAAG,eAAe,CAAC,oBAAoB,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,cAAc,EAAE,CAAC,CAAA;IAC3F,OAAO,EAAE,KAAK,EAAE,qBAAqB,CAAC,IAAI,CAAC,EAAE,CAAA;AAC/C,CAAC"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Errors thrown by the auth bridge.
3
+ *
4
+ * Each implements `KernelErrorClassifiable` so `kernel-api/dispatch` can
5
+ * convert them into typed `KernelErrorPayload` values automatically.
6
+ */
7
+ import type { KernelErrorPayload, KernelErrorClassifiable } from '@astrale-os/kernel-api';
8
+ export declare class AuthMissingError extends Error implements KernelErrorClassifiable {
9
+ constructor();
10
+ toKernelErrorPayload(): KernelErrorPayload;
11
+ }
12
+ export declare class AuthInvalidError extends Error implements KernelErrorClassifiable {
13
+ constructor(message: string, cause?: unknown);
14
+ toKernelErrorPayload(): KernelErrorPayload;
15
+ }
16
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/auth/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAA;AAIzF,qBAAa,gBAAiB,SAAQ,KAAM,YAAW,uBAAuB;IAC5E,cAGC;IAED,oBAAoB,IAAI,kBAAkB,CAEzC;CACF;AAED,qBAAa,gBAAiB,SAAQ,KAAM,YAAW,uBAAuB;IAC5E,YAAY,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,EAG3C;IAED,oBAAoB,IAAI,kBAAkB,CAEzC;CACF"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Errors thrown by the auth bridge.
3
+ *
4
+ * Each implements `KernelErrorClassifiable` so `kernel-api/dispatch` can
5
+ * convert them into typed `KernelErrorPayload` values automatically.
6
+ */
7
+ import { KERNEL_ERROR_CODES } from '@astrale-os/kernel-api';
8
+ export class AuthMissingError extends Error {
9
+ constructor() {
10
+ super('Missing credentials');
11
+ this.name = 'AuthMissingError';
12
+ }
13
+ toKernelErrorPayload() {
14
+ return { code: KERNEL_ERROR_CODES.AUTH_MISSING, message: this.message };
15
+ }
16
+ }
17
+ export class AuthInvalidError extends Error {
18
+ constructor(message, cause) {
19
+ super(message, { cause });
20
+ this.name = 'AuthInvalidError';
21
+ }
22
+ toKernelErrorPayload() {
23
+ return { code: KERNEL_ERROR_CODES.AUTH_INVALID, message: this.message };
24
+ }
25
+ }
26
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/auth/errors.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAA;AAE3D,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACzC;QACE,KAAK,CAAC,qBAAqB,CAAC,CAAA;QAC5B,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAA;IAChC,CAAC;IAED,oBAAoB;QAClB,OAAO,EAAE,IAAI,EAAE,kBAAkB,CAAC,YAAY,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAA;IACzE,CAAC;CACF;AAED,MAAM,OAAO,gBAAiB,SAAQ,KAAK;IACzC,YAAY,OAAe,EAAE,KAAe;QAC1C,KAAK,CAAC,OAAO,EAAE,EAAE,KAAK,EAAE,CAAC,CAAA;QACzB,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAA;IAChC,CAAC;IAED,oBAAoB;QAClB,OAAO,EAAE,IAAI,EAAE,kBAAkB,CAAC,YAAY,EAAE,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,CAAA;IACzE,CAAC;CACF"}
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Identity configuration for a remote domain server.
3
+ *
4
+ * The issuer must be reachable via JWKS at `<issuer>/.well-known/jwks.json`
5
+ * (or registered in the kernel's trust store). The private key is used to
6
+ * sign outbound composed credentials.
7
+ */
8
+ export type RemoteIdentityConfig = {
9
+ /** This service's issuer (URL where its JWKS is served, or a registered ID) */
10
+ issuer: string;
11
+ /** This service's subject identifier (e.g. "task-service") */
12
+ subject: string;
13
+ /** Private key for signing outbound credentials */
14
+ privateKey: JsonWebKey;
15
+ };
16
+ //# sourceMappingURL=identity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity.d.ts","sourceRoot":"","sources":["../../src/auth/identity.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AACH,MAAM,MAAM,oBAAoB,GAAG;IACjC,+EAA+E;IAC/E,MAAM,EAAE,MAAM,CAAA;IACd,8DAA8D;IAC9D,OAAO,EAAE,MAAM,CAAA;IACf,mDAAmD;IACnD,UAAU,EAAE,UAAU,CAAA;CACvB,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=identity.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"identity.js","sourceRoot":"","sources":["../../src/auth/identity.ts"],"names":[],"mappings":""}
@@ -0,0 +1,12 @@
1
+ export type { RemoteIdentityConfig } from './identity';
2
+ export type { VerifiedInbound } from './verify';
3
+ export type { AuthenticateResult } from './authenticate';
4
+ export { authenticateRequest } from './authenticate';
5
+ export { resolveInboundAuth, buildAuthContext, type ResolvedAuth } from './resolve';
6
+ export { verifyInboundCredential } from './verify';
7
+ export { buildComposedGrant } from './compose';
8
+ export { signCredential } from './sign';
9
+ export { bindKernel } from './kernel-client';
10
+ export { AuthMissingError, AuthInvalidError } from './errors';
11
+ export { assertPerm, requireOwnership, READ, EDIT, USE, SHARE, ALL } from './check';
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AACtD,YAAY,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAC/C,YAAY,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AACxD,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAE,KAAK,YAAY,EAAE,MAAM,WAAW,CAAA;AACnF,OAAO,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAA;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAA;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAA;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAC7D,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,SAAS,CAAA"}
@@ -0,0 +1,9 @@
1
+ export { authenticateRequest } from './authenticate';
2
+ export { resolveInboundAuth, buildAuthContext } from './resolve';
3
+ export { verifyInboundCredential } from './verify';
4
+ export { buildComposedGrant } from './compose';
5
+ export { signCredential } from './sign';
6
+ export { bindKernel } from './kernel-client';
7
+ export { AuthMissingError, AuthInvalidError } from './errors';
8
+ export { assertPerm, requireOwnership, READ, EDIT, USE, SHARE, ALL } from './check';
9
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AACpD,OAAO,EAAE,kBAAkB,EAAE,gBAAgB,EAAqB,MAAM,WAAW,CAAA;AACnF,OAAO,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAA;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAA;AAC9C,OAAO,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAA;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAA;AAC7D,OAAO,EAAE,UAAU,EAAE,gBAAgB,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,SAAS,CAAA"}
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Call-back kernel client.
3
+ *
4
+ * Every authenticated inbound request produces a `BoundClientSessionView` the
5
+ * handler uses to call back into the parent kernel. The view is bound to
6
+ * a composed credential (`union(delegation, self)`) so the kernel
7
+ * enforces both the caller's scoped identity and the function's own.
8
+ *
9
+ * The connection pool and schema registry are cached per kernel URL and reused
10
+ * across requests. The `ClientSession` itself is per-request: it carries a
11
+ * delegation mint bound to the calling function's own subject (`config.subject`)
12
+ * so a remote-bound call (one that redirects to another worker) mints a
13
+ * worker-scoped credential for the audience the kernel puts on the redirect
14
+ * (`CallRedirection.iss`) — the worker→worker dance, done reactively instead of
15
+ * the old proactive `lookupRemoteBinding` resolve-then-dial.
16
+ */
17
+ import type { Delegation } from '@astrale-os/kernel-core';
18
+ import { type FnMap } from '@astrale-os/kernel-client';
19
+ import { type BoundClientSessionView } from '@astrale-os/kernel-client/session';
20
+ import type { RemoteIdentityConfig } from './identity';
21
+ /**
22
+ * Build a `BoundClientSessionView` that signs outbound calls as the composed
23
+ * identity (the caller's delegation unioned with this function's own
24
+ * identity). Remote-bound calls auto-follow the kernel's redirect and mint a
25
+ * worker-scoped delegation via `@<subject>::mintDelegationCredential`.
26
+ */
27
+ export declare function bindKernel(delegation: Delegation, kernelUrl: string, config: RemoteIdentityConfig): Promise<BoundClientSessionView<FnMap>>;
28
+ //# sourceMappingURL=kernel-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kernel-client.d.ts","sourceRoot":"","sources":["../../src/auth/kernel-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAEzD,OAAO,EAAgC,KAAK,KAAK,EAAE,MAAM,2BAA2B,CAAA;AAEpF,OAAO,EAAiB,KAAK,sBAAsB,EAAE,MAAM,mCAAmC,CAAA;AAE9F,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAiCtD;;;;;GAKG;AACH,wBAAsB,UAAU,CAC9B,UAAU,EAAE,UAAU,EACtB,SAAS,EAAE,MAAM,EACjB,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,sBAAsB,CAAC,KAAK,CAAC,CAAC,CAwCxC"}
@@ -0,0 +1,84 @@
1
+ /**
2
+ * Call-back kernel client.
3
+ *
4
+ * Every authenticated inbound request produces a `BoundClientSessionView` the
5
+ * handler uses to call back into the parent kernel. The view is bound to
6
+ * a composed credential (`union(delegation, self)`) so the kernel
7
+ * enforces both the caller's scoped identity and the function's own.
8
+ *
9
+ * The connection pool and schema registry are cached per kernel URL and reused
10
+ * across requests. The `ClientSession` itself is per-request: it carries a
11
+ * delegation mint bound to the calling function's own subject (`config.subject`)
12
+ * so a remote-bound call (one that redirects to another worker) mints a
13
+ * worker-scoped credential for the audience the kernel puts on the redirect
14
+ * (`CallRedirection.iss`) — the worker→worker dance, done reactively instead of
15
+ * the old proactive `lookupRemoteBinding` resolve-then-dial.
16
+ */
17
+ import { KernelClient, SchemaRegistry } from '@astrale-os/kernel-client';
18
+ import { ClientPool } from '@astrale-os/kernel-client/pool';
19
+ import { ClientSession } from '@astrale-os/kernel-client/session';
20
+ import { buildComposedGrant } from './compose';
21
+ import { signCredential } from './sign';
22
+ const DELEGATION_TTL_SECONDS = 3600;
23
+ // Shared per kernel URL — the expensive, identity-agnostic state. Sessions are
24
+ // NOT shared (each binds a subject-specific delegation mint), but the pool
25
+ // (connections) and registry (learned schemas) are reused across them.
26
+ const pools = new Map();
27
+ const registries = new Map();
28
+ function getRegistry(url) {
29
+ let registry = registries.get(url);
30
+ if (!registry) {
31
+ registry = new SchemaRegistry();
32
+ registries.set(url, registry);
33
+ }
34
+ return registry;
35
+ }
36
+ function getPool(url) {
37
+ const cached = pools.get(url);
38
+ if (cached)
39
+ return cached;
40
+ const registry = getRegistry(url);
41
+ const pool = new ClientPool({
42
+ clientFactory: (u) => new KernelClient({ url: u, schema: registry }),
43
+ });
44
+ pools.set(url, pool);
45
+ return pool;
46
+ }
47
+ /**
48
+ * Build a `BoundClientSessionView` that signs outbound calls as the composed
49
+ * identity (the caller's delegation unioned with this function's own
50
+ * identity). Remote-bound calls auto-follow the kernel's redirect and mint a
51
+ * worker-scoped delegation via `@<subject>::mintDelegationCredential`.
52
+ */
53
+ export async function bindKernel(delegation, kernelUrl, config) {
54
+ const { grant } = buildComposedGrant(delegation);
55
+ const composed = await signCredential({ grant }, {
56
+ issuer: config.issuer,
57
+ subject: config.subject,
58
+ audience: kernelUrl,
59
+ privateKey: config.privateKey,
60
+ });
61
+ // Self-reference in the mint closure is lazy — it only fires on a delegation
62
+ // cache miss while following a redirect, long after construction.
63
+ const session = new ClientSession({
64
+ default: kernelUrl,
65
+ schema: getRegistry(kernelUrl),
66
+ pool: getPool(kernelUrl),
67
+ delegation: {
68
+ // `@<subject>::mintDelegationCredential` satisfies the syscall's
69
+ // `self.id === auth.principal` invariant (composed's subject IS the
70
+ // principal). `skipDelegation` keeps this mint from re-entering itself —
71
+ // it targets the kernel (same origin), so no delegation is needed.
72
+ mint: async (audience) => {
73
+ const envelope = await session.call(`@${config.subject}::mintDelegationCredential`, { audience, delegation: { kind: 'identity', self: true }, ttl: DELEGATION_TTL_SECONDS }, { credential: composed, skipDelegation: true });
74
+ if (typeof envelope !== 'string') {
75
+ throw new Error(`mintDelegationCredential returned ${typeof envelope}, expected a credential string`);
76
+ }
77
+ return { credential: envelope, ttl: DELEGATION_TTL_SECONDS };
78
+ },
79
+ ttl: DELEGATION_TTL_SECONDS,
80
+ },
81
+ });
82
+ return session.as(composed);
83
+ }
84
+ //# sourceMappingURL=kernel-client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kernel-client.js","sourceRoot":"","sources":["../../src/auth/kernel-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,OAAO,EAAE,YAAY,EAAE,cAAc,EAA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AC,QAAQ,CAAC,CAAA;AAC7B,CAAC"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Shared inbound-credential resolution.
3
+ *
4
+ * Consumed by both `SdkDispatcher` (kernel envelope) and `mountAuxiliaryRoutes`
5
+ * (View / RemoteFunction routes). Centralises the auth-policy three-way
6
+ * (`'required'` / `'optional'` / `'public'`) and the wrap of underlying
7
+ * verification errors into canonical `AuthMissingError` / `AuthInvalidError`.
8
+ */
9
+ import type { AuthPolicy } from '@astrale-os/kernel-api/routed';
10
+ import type { AuthContext, Authenticated, CredentialInput } from '@astrale-os/kernel-core';
11
+ import type { AuthenticateResult } from './authenticate';
12
+ import type { RemoteIdentityConfig } from './identity';
13
+ export type ResolvedAuth = {
14
+ auth: AuthContext | null;
15
+ kernel: AuthenticateResult['kernel'];
16
+ };
17
+ export declare function resolveInboundAuth(credential: CredentialInput, policy: AuthPolicy | undefined, identity: RemoteIdentityConfig): Promise<ResolvedAuth>;
18
+ export declare function buildAuthContext(authenticated: Authenticated): AuthContext;
19
+ //# sourceMappingURL=resolve.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"resolve.d.ts","sourceRoot":"","sources":["../../src/auth/resolve.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAA;AAC/D,OAAO,KAAK,EACV,WAAW,EACX,aAAa,EACb,eAAe,EAEhB,MAAM,yBAAyB,CAAA;AAIhC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,gBAAgB,CAAA;AACxD,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAKtD,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,WAAW,GAAG,IAAI,CAAA;IACxB,MAAM,EAAE,kBAAkB,CAAC,QAAQ,CAAC,CAAA;CACrC,CAAA;AAED,wBAAsB,kBAAkB,CACtC,UAAU,EAAE,eAAe,EAC3B,MAAM,EAAE,UAAU,GAAG,SAAS,EAC9B,QAAQ,EAAE,oBAAoB,GAC7B,OAAO,CAAC,YAAY,CAAC,CAkBvB;AAED,wBAAgB,gBAAgB,CAAC,aAAa,EAAE,aAAa,GAAG,WAAW,CAQ1E"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Shared inbound-credential resolution.
3
+ *
4
+ * Consumed by both `SdkDispatcher` (kernel envelope) and `mountAuxiliaryRoutes`
5
+ * (View / RemoteFunction routes). Centralises the auth-policy three-way
6
+ * (`'required'` / `'optional'` / `'public'`) and the wrap of underlying
7
+ * verification errors into canonical `AuthMissingError` / `AuthInvalidError`.
8
+ */
9
+ import { isKernelErrorClassifiable } from '@astrale-os/kernel-api';
10
+ import { authenticateRequest } from './authenticate';
11
+ import { AuthInvalidError, AuthMissingError } from './errors';
12
+ export async function resolveInboundAuth(credential, policy, identity) {
13
+ const effective = policy ?? 'required';
14
+ if (effective === 'public')
15
+ return { auth: null, kernel: null };
16
+ if (effective === 'optional' && !credential)
17
+ return { auth: null, kernel: null };
18
+ if (effective === 'required' && !credential)
19
+ throw new AuthMissingError();
20
+ try {
21
+ const result = await authenticateRequest(credential, identity);
22
+ return { auth: buildAuthContext(result.authenticated), kernel: result.kernel };
23
+ }
24
+ catch (err) {
25
+ // kernel-core auth errors (UntrustedIssuerError, TrustPolicyDeniedError, …)
26
+ // already self-classify with a discriminating `data.type`. Rethrow them
27
+ // unchanged so that classification survives to the wire; only wrap
28
+ // genuinely unclassified errors into the generic AuthInvalidError.
29
+ if (isKernelErrorClassifiable(err))
30
+ throw err;
31
+ throw new AuthInvalidError(err instanceof Error ? err.message : 'Authentication failed', err);
32
+ }
33
+ }
34
+ export function buildAuthContext(authenticated) {
35
+ return {
36
+ credential: authenticated.credential,
37
+ principal: authenticated.credential.verified.sub,
38
+ grant: authenticated.grant,
39
+ attestation: authenticated.attestation,
40
+ delegation: authenticated.delegation,
41
+ };
42
+ }
43
+ //# sourceMappingURL=resolve.js.map
@@ -0,0 +1 @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C;AACH,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,aAA4B;IAC3D,OAAO;QACL,UAAU,EAAE,aAAa,CAAC,UAAU;QACpC,SAAS,EAAE,aAAa,CAAC,UAAU,CAAC,QAAQ,CAAC,GAA4B;QACzE,KAAK,EAAE,aAAa,CAAC,KAAM;QAC3B,WAAW,EAAE,aAAa,CAAC,WAAW;QACtC,UAAU,EAAE,aAAa,CAAC,UAAU;KACrC,CAAA;AACH,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * JWT signing utilities for outbound composed credentials.
3
+ */
4
+ /**
5
+ * Sign a credential JWT with the given claims and identity config.
6
+ */
7
+ export declare function signCredential(claims: Record<string, unknown>, config: {
8
+ issuer: string;
9
+ subject: string;
10
+ audience: string;
11
+ privateKey: JsonWebKey;
12
+ /** JWT lifetime as a jose-compatible string (e.g. '60s', '5m', '1h'). Default: '60s'. */
13
+ ttl?: string;
14
+ }): Promise<string>;
15
+ //# sourceMappingURL=sign.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sign.d.ts","sourceRoot":"","sources":["../../src/auth/sign.ts"],"names":[],"mappings":"AAAA;;GAEG;AAKH;;GAEG;AACH,wBAAsB,cAAc,CAClC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC/B,MAAM,EAAE;IACN,MAAM,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,MAAM,CAAA;IAChB,UAAU,EAAE,UAAU,CAAA;IACtB,yFAAyF;IACzF,GAAG,CAAC,EAAE,MAAM,CAAA;CACb,GACA,OAAO,CAAC,MAAM,CAAC,CAejB"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * JWT signing utilities for outbound composed credentials.
3
+ */
4
+ import { deriveAllowedAlgorithms } from '@astrale-os/kernel-core';
5
+ import { SignJWT, importJWK } from 'jose';
6
+ /**
7
+ * Sign a credential JWT with the given claims and identity config.
8
+ */
9
+ export async function signCredential(claims, config) {
10
+ const alg = deriveAllowedAlgorithms(config.privateKey)[0];
11
+ if (!alg) {
12
+ throw new Error(`Cannot derive algorithm from JWK: kty=${config.privateKey.kty}`);
13
+ }
14
+ const key = await importJWK(config.privateKey, alg);
15
+ return new SignJWT(claims)
16
+ .setProtectedHeader({ alg })
17
+ .setIssuer(config.issuer)
18
+ .setSubject(config.subject)
19
+ .setAudience(config.audience)
20
+ .setIssuedAt()
21
+ .setExpirationTime(config.ttl ?? '60s')
22
+ .sign(key);
23
+ }
24
+ //# sourceMappingURL=sign.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sign.js","sourceRoot":"","sources":["../../src/auth/sign.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAA;AACjE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,MAAM,CAAA;AAEzC;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,MAA+B,EAC/B,MAOC;IAED,MAAM,GAAG,GAAG,uBAAuB,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAA;IACzD,IAAI,CAAC,GAAG,EAAE,CAAC;QACT,MAAM,IAAI,KAAK,CAAC,yCAAyC,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC,CAAA;IACnF,CAAC;IACD,MAAM,GAAG,GAAG,MAAM,SAAS,CAAC,MAAM,CAAC,UAAU,EAAE,GAAG,CAAC,CAAA;IAEnD,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC;SACvB,kBAAkB,CAAC,EAAE,GAAG,EAAE,CAAC;SAC3B,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC;SACxB,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC;SAC1B,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC;SAC5B,WAAW,EAAE;SACb,iBAAiB,CAAC,MAAM,CAAC,GAAG,IAAI,KAAK,CAAC;SACtC,IAAI,CAAC,GAAG,CAAC,CAAA;AACd,CAAC"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Inbound credential verification.
3
+ *
4
+ * Uses kernel-core's credential verification infrastructure
5
+ * (CredentialMethodResolver, MethodRegistry) instead of manual JWT handling.
6
+ * Not tied to JWT — supports any credential method kernel-core provides.
7
+ */
8
+ import type { Attestation, CredentialInput, Delegation, VerifiedCredential } from '@astrale-os/kernel-core';
9
+ import type { RemoteIdentityConfig } from './identity';
10
+ export type VerifiedInbound = {
11
+ /** The full verified credential (iss, sub, aud, claims) */
12
+ verified: VerifiedCredential;
13
+ /** Issuer URL (from credential's iss claim) */
14
+ issuer: string;
15
+ /** Attestation — proves caller can invoke this function */
16
+ attestation: Attestation;
17
+ /** Delegation — scoped caller permissions as kernel-signed credential */
18
+ delegation: Delegation;
19
+ };
20
+ /**
21
+ * Verify an inbound delegation credential using kernel-core's verification.
22
+ *
23
+ * @throws AuthenticationError subclasses from kernel-core on verification failure
24
+ */
25
+ export declare function verifyInboundCredential(credential: CredentialInput, config: RemoteIdentityConfig): Promise<VerifiedInbound>;
26
+ //# sourceMappingURL=verify.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verify.d.ts","sourceRoot":"","sources":["../../src/auth/verify.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EACV,WAAW,EACX,eAAe,EACf,UAAU,EAEV,kBAAkB,EACnB,MAAM,yBAAyB,CAAA;AAUhC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA;AAKtD,MAAM,MAAM,eAAe,GAAG;IAC5B,2DAA2D;IAC3D,QAAQ,EAAE,kBAAkB,CAAA;IAC5B,+CAA+C;IAC/C,MAAM,EAAE,MAAM,CAAA;IACd,2DAA2D;IAC3D,WAAW,EAAE,WAAW,CAAA;IACxB,yEAAyE;IACzE,UAAU,EAAE,UAAU,CAAA;CACvB,CAAA;AA4DD;;;;GAIG;AACH,wBAAsB,uBAAuB,CAC3C,UAAU,EAAE,eAAe,EAC3B,MAAM,EAAE,oBAAoB,GAC3B,OAAO,CAAC,eAAe,CAAC,CA+B1B"}