@aster-rpc/aster 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 (233) hide show
  1. package/dist/capabilities.d.ts +26 -0
  2. package/dist/capabilities.d.ts.map +1 -0
  3. package/dist/capabilities.js +29 -0
  4. package/dist/capabilities.js.map +1 -0
  5. package/dist/client.d.ts +65 -0
  6. package/dist/client.d.ts.map +1 -0
  7. package/dist/client.js +108 -0
  8. package/dist/client.js.map +1 -0
  9. package/dist/codec.d.ts +156 -0
  10. package/dist/codec.d.ts.map +1 -0
  11. package/dist/codec.js +477 -0
  12. package/dist/codec.js.map +1 -0
  13. package/dist/config.d.ts +102 -0
  14. package/dist/config.d.ts.map +1 -0
  15. package/dist/config.js +454 -0
  16. package/dist/config.js.map +1 -0
  17. package/dist/contract/identity.d.ts +115 -0
  18. package/dist/contract/identity.d.ts.map +1 -0
  19. package/dist/contract/identity.js +188 -0
  20. package/dist/contract/identity.js.map +1 -0
  21. package/dist/contract/manifest.d.ts +77 -0
  22. package/dist/contract/manifest.d.ts.map +1 -0
  23. package/dist/contract/manifest.js +127 -0
  24. package/dist/contract/manifest.js.map +1 -0
  25. package/dist/contract/publication.d.ts +71 -0
  26. package/dist/contract/publication.d.ts.map +1 -0
  27. package/dist/contract/publication.js +85 -0
  28. package/dist/contract/publication.js.map +1 -0
  29. package/dist/decorators.d.ts +139 -0
  30. package/dist/decorators.d.ts.map +1 -0
  31. package/dist/decorators.js +175 -0
  32. package/dist/decorators.js.map +1 -0
  33. package/dist/dynamic.d.ts +61 -0
  34. package/dist/dynamic.d.ts.map +1 -0
  35. package/dist/dynamic.js +147 -0
  36. package/dist/dynamic.js.map +1 -0
  37. package/dist/framing.d.ts +74 -0
  38. package/dist/framing.d.ts.map +1 -0
  39. package/dist/framing.js +162 -0
  40. package/dist/framing.js.map +1 -0
  41. package/dist/health.d.ts +127 -0
  42. package/dist/health.d.ts.map +1 -0
  43. package/dist/health.js +236 -0
  44. package/dist/health.js.map +1 -0
  45. package/dist/index.d.ts +67 -0
  46. package/dist/index.d.ts.map +1 -0
  47. package/dist/index.js +101 -0
  48. package/dist/index.js.map +1 -0
  49. package/dist/interceptors/audit.d.ts +25 -0
  50. package/dist/interceptors/audit.d.ts.map +1 -0
  51. package/dist/interceptors/audit.js +46 -0
  52. package/dist/interceptors/audit.js.map +1 -0
  53. package/dist/interceptors/auth.d.ts +13 -0
  54. package/dist/interceptors/auth.d.ts.map +1 -0
  55. package/dist/interceptors/auth.js +34 -0
  56. package/dist/interceptors/auth.js.map +1 -0
  57. package/dist/interceptors/base.d.ts +74 -0
  58. package/dist/interceptors/base.d.ts.map +1 -0
  59. package/dist/interceptors/base.js +103 -0
  60. package/dist/interceptors/base.js.map +1 -0
  61. package/dist/interceptors/capability.d.ts +16 -0
  62. package/dist/interceptors/capability.d.ts.map +1 -0
  63. package/dist/interceptors/capability.js +63 -0
  64. package/dist/interceptors/capability.js.map +1 -0
  65. package/dist/interceptors/circuit-breaker.d.ts +40 -0
  66. package/dist/interceptors/circuit-breaker.d.ts.map +1 -0
  67. package/dist/interceptors/circuit-breaker.js +91 -0
  68. package/dist/interceptors/circuit-breaker.js.map +1 -0
  69. package/dist/interceptors/compression.d.ts +11 -0
  70. package/dist/interceptors/compression.d.ts.map +1 -0
  71. package/dist/interceptors/compression.js +12 -0
  72. package/dist/interceptors/compression.js.map +1 -0
  73. package/dist/interceptors/deadline.d.ts +12 -0
  74. package/dist/interceptors/deadline.d.ts.map +1 -0
  75. package/dist/interceptors/deadline.js +28 -0
  76. package/dist/interceptors/deadline.js.map +1 -0
  77. package/dist/interceptors/metrics.d.ts +43 -0
  78. package/dist/interceptors/metrics.d.ts.map +1 -0
  79. package/dist/interceptors/metrics.js +132 -0
  80. package/dist/interceptors/metrics.js.map +1 -0
  81. package/dist/interceptors/rate-limit.d.ts +24 -0
  82. package/dist/interceptors/rate-limit.d.ts.map +1 -0
  83. package/dist/interceptors/rate-limit.js +84 -0
  84. package/dist/interceptors/rate-limit.js.map +1 -0
  85. package/dist/interceptors/retry.d.ts +25 -0
  86. package/dist/interceptors/retry.d.ts.map +1 -0
  87. package/dist/interceptors/retry.js +55 -0
  88. package/dist/interceptors/retry.js.map +1 -0
  89. package/dist/limits.d.ts +77 -0
  90. package/dist/limits.d.ts.map +1 -0
  91. package/dist/limits.js +137 -0
  92. package/dist/limits.js.map +1 -0
  93. package/dist/logging.d.ts +40 -0
  94. package/dist/logging.d.ts.map +1 -0
  95. package/dist/logging.js +92 -0
  96. package/dist/logging.js.map +1 -0
  97. package/dist/metadata.d.ts +14 -0
  98. package/dist/metadata.d.ts.map +1 -0
  99. package/dist/metadata.js +68 -0
  100. package/dist/metadata.js.map +1 -0
  101. package/dist/metrics.d.ts +40 -0
  102. package/dist/metrics.d.ts.map +1 -0
  103. package/dist/metrics.js +92 -0
  104. package/dist/metrics.js.map +1 -0
  105. package/dist/peer-store.d.ts +53 -0
  106. package/dist/peer-store.d.ts.map +1 -0
  107. package/dist/peer-store.js +105 -0
  108. package/dist/peer-store.js.map +1 -0
  109. package/dist/protocol.d.ts +44 -0
  110. package/dist/protocol.d.ts.map +1 -0
  111. package/dist/protocol.js +59 -0
  112. package/dist/protocol.js.map +1 -0
  113. package/dist/registration.d.ts +81 -0
  114. package/dist/registration.d.ts.map +1 -0
  115. package/dist/registration.js +161 -0
  116. package/dist/registration.js.map +1 -0
  117. package/dist/registry/acl.d.ts +57 -0
  118. package/dist/registry/acl.d.ts.map +1 -0
  119. package/dist/registry/acl.js +104 -0
  120. package/dist/registry/acl.js.map +1 -0
  121. package/dist/registry/client.d.ts +70 -0
  122. package/dist/registry/client.d.ts.map +1 -0
  123. package/dist/registry/client.js +115 -0
  124. package/dist/registry/client.js.map +1 -0
  125. package/dist/registry/gossip.d.ts +43 -0
  126. package/dist/registry/gossip.d.ts.map +1 -0
  127. package/dist/registry/gossip.js +102 -0
  128. package/dist/registry/gossip.js.map +1 -0
  129. package/dist/registry/keys.d.ts +25 -0
  130. package/dist/registry/keys.d.ts.map +1 -0
  131. package/dist/registry/keys.js +47 -0
  132. package/dist/registry/keys.js.map +1 -0
  133. package/dist/registry/models.d.ts +80 -0
  134. package/dist/registry/models.d.ts.map +1 -0
  135. package/dist/registry/models.js +35 -0
  136. package/dist/registry/models.js.map +1 -0
  137. package/dist/registry/publisher.d.ts +65 -0
  138. package/dist/registry/publisher.d.ts.map +1 -0
  139. package/dist/registry/publisher.js +164 -0
  140. package/dist/registry/publisher.js.map +1 -0
  141. package/dist/runtime.d.ts +267 -0
  142. package/dist/runtime.d.ts.map +1 -0
  143. package/dist/runtime.js +1366 -0
  144. package/dist/runtime.js.map +1 -0
  145. package/dist/server.d.ts +100 -0
  146. package/dist/server.d.ts.map +1 -0
  147. package/dist/server.js +511 -0
  148. package/dist/server.js.map +1 -0
  149. package/dist/service.d.ts +72 -0
  150. package/dist/service.d.ts.map +1 -0
  151. package/dist/service.js +98 -0
  152. package/dist/service.js.map +1 -0
  153. package/dist/session.d.ts +64 -0
  154. package/dist/session.d.ts.map +1 -0
  155. package/dist/session.js +350 -0
  156. package/dist/session.js.map +1 -0
  157. package/dist/status.d.ts +113 -0
  158. package/dist/status.d.ts.map +1 -0
  159. package/dist/status.js +206 -0
  160. package/dist/status.js.map +1 -0
  161. package/dist/transport/base.d.ts +46 -0
  162. package/dist/transport/base.d.ts.map +1 -0
  163. package/dist/transport/base.js +10 -0
  164. package/dist/transport/base.js.map +1 -0
  165. package/dist/transport/iroh.d.ts +45 -0
  166. package/dist/transport/iroh.d.ts.map +1 -0
  167. package/dist/transport/iroh.js +225 -0
  168. package/dist/transport/iroh.js.map +1 -0
  169. package/dist/transport/local.d.ts +48 -0
  170. package/dist/transport/local.d.ts.map +1 -0
  171. package/dist/transport/local.js +139 -0
  172. package/dist/transport/local.js.map +1 -0
  173. package/dist/trust/admission.d.ts +60 -0
  174. package/dist/trust/admission.d.ts.map +1 -0
  175. package/dist/trust/admission.js +149 -0
  176. package/dist/trust/admission.js.map +1 -0
  177. package/dist/trust/bootstrap.d.ts +109 -0
  178. package/dist/trust/bootstrap.d.ts.map +1 -0
  179. package/dist/trust/bootstrap.js +311 -0
  180. package/dist/trust/bootstrap.js.map +1 -0
  181. package/dist/trust/clock.d.ts +93 -0
  182. package/dist/trust/clock.d.ts.map +1 -0
  183. package/dist/trust/clock.js +154 -0
  184. package/dist/trust/clock.js.map +1 -0
  185. package/dist/trust/consumer.d.ts +139 -0
  186. package/dist/trust/consumer.d.ts.map +1 -0
  187. package/dist/trust/consumer.js +323 -0
  188. package/dist/trust/consumer.js.map +1 -0
  189. package/dist/trust/credentials.d.ts +98 -0
  190. package/dist/trust/credentials.d.ts.map +1 -0
  191. package/dist/trust/credentials.js +250 -0
  192. package/dist/trust/credentials.js.map +1 -0
  193. package/dist/trust/delegated.d.ts +118 -0
  194. package/dist/trust/delegated.d.ts.map +1 -0
  195. package/dist/trust/delegated.js +292 -0
  196. package/dist/trust/delegated.js.map +1 -0
  197. package/dist/trust/gossip.d.ts +146 -0
  198. package/dist/trust/gossip.d.ts.map +1 -0
  199. package/dist/trust/gossip.js +334 -0
  200. package/dist/trust/gossip.js.map +1 -0
  201. package/dist/trust/hooks.d.ts +84 -0
  202. package/dist/trust/hooks.d.ts.map +1 -0
  203. package/dist/trust/hooks.js +125 -0
  204. package/dist/trust/hooks.js.map +1 -0
  205. package/dist/trust/iid.d.ts +65 -0
  206. package/dist/trust/iid.d.ts.map +1 -0
  207. package/dist/trust/iid.js +104 -0
  208. package/dist/trust/iid.js.map +1 -0
  209. package/dist/trust/mesh.d.ts +43 -0
  210. package/dist/trust/mesh.d.ts.map +1 -0
  211. package/dist/trust/mesh.js +105 -0
  212. package/dist/trust/mesh.js.map +1 -0
  213. package/dist/trust/nonce.d.ts +39 -0
  214. package/dist/trust/nonce.d.ts.map +1 -0
  215. package/dist/trust/nonce.js +46 -0
  216. package/dist/trust/nonce.js.map +1 -0
  217. package/dist/trust/producer.d.ts +80 -0
  218. package/dist/trust/producer.d.ts.map +1 -0
  219. package/dist/trust/producer.js +151 -0
  220. package/dist/trust/producer.js.map +1 -0
  221. package/dist/trust/rcan.d.ts +29 -0
  222. package/dist/trust/rcan.d.ts.map +1 -0
  223. package/dist/trust/rcan.js +57 -0
  224. package/dist/trust/rcan.js.map +1 -0
  225. package/dist/types.d.ts +57 -0
  226. package/dist/types.d.ts.map +1 -0
  227. package/dist/types.js +50 -0
  228. package/dist/types.js.map +1 -0
  229. package/dist/xlang.d.ts +26 -0
  230. package/dist/xlang.d.ts.map +1 -0
  231. package/dist/xlang.js +55 -0
  232. package/dist/xlang.js.map +1 -0
  233. package/package.json +59 -0
@@ -0,0 +1,151 @@
1
+ /**
2
+ * Producer admission — the server-side admission handshake.
3
+ *
4
+ * Spec reference: Aster-trust-spec.md S6
5
+ *
6
+ * When a producer wants to join a mesh, the accepting producer:
7
+ * 1. Accepts a connection on the producer admission ALPN
8
+ * 2. Reads an AdmissionRequest (credential JSON + optional IID token)
9
+ * 3. Validates the credential (signature, expiry, root pubkey)
10
+ * 4. Responds with AdmissionResponse (accepted/rejected + mesh state)
11
+ */
12
+ import { verifyProducerCredential } from './admission.js';
13
+ import { MAX_ADMISSION_PAYLOAD_SIZE } from '../limits.js';
14
+ /** ALPN for producer admission. */
15
+ export const PRODUCER_ADMISSION_ALPN = new TextEncoder().encode('aster.producer_admission');
16
+ /**
17
+ * Handle a single producer admission connection.
18
+ *
19
+ * Reads the credential, validates it, updates mesh state on success,
20
+ * and responds with the admission result.
21
+ */
22
+ export async function handleProducerAdmission(conn, opts) {
23
+ const peerNodeId = conn.remoteNodeId();
24
+ const log = opts.logger ?? console;
25
+ const bi = await conn.acceptBi();
26
+ const send = bi.takeSend();
27
+ const recv = bi.takeRecv();
28
+ try {
29
+ // Read request
30
+ const raw = await recv.readToEnd(MAX_ADMISSION_PAYLOAD_SIZE);
31
+ const text = new TextDecoder().decode(raw);
32
+ let request;
33
+ try {
34
+ request = JSON.parse(text);
35
+ }
36
+ catch {
37
+ const resp = buildDenied('malformed request');
38
+ await sendResponse(send, resp);
39
+ return resp;
40
+ }
41
+ // Parse credential
42
+ let cred;
43
+ try {
44
+ cred = JSON.parse(request.credentialJson);
45
+ }
46
+ catch {
47
+ const resp = buildDenied('malformed credential JSON');
48
+ await sendResponse(send, resp);
49
+ return resp;
50
+ }
51
+ // Verify root pubkey match
52
+ if (cred.rootPubkey !== opts.rootPubkey) {
53
+ log.warn?.('admission: root pubkey mismatch', {
54
+ peer: peerNodeId.slice(0, 8),
55
+ });
56
+ const resp = buildDenied('root pubkey mismatch');
57
+ await sendResponse(send, resp);
58
+ return resp;
59
+ }
60
+ // Verify credential (expiry, signature)
61
+ const result = await verifyProducerCredential(cred, opts.rootPubkey);
62
+ if (!result.admitted) {
63
+ log.warn?.('admission: denied', {
64
+ peer: peerNodeId.slice(0, 8),
65
+ reason: result.reason,
66
+ });
67
+ const resp = buildDenied(result.reason ?? 'denied');
68
+ await sendResponse(send, resp);
69
+ return resp;
70
+ }
71
+ // Verify endpoint ID binding
72
+ if (cred.endpointId && cred.endpointId !== peerNodeId) {
73
+ log.warn?.('admission: endpoint ID mismatch', {
74
+ peer: peerNodeId.slice(0, 8),
75
+ });
76
+ const resp = buildDenied('endpoint ID mismatch');
77
+ await sendResponse(send, resp);
78
+ return resp;
79
+ }
80
+ // Check nonce if OTT credential
81
+ if (opts.nonceStore && cred.signature) {
82
+ const nonceHex = cred.signature.slice(0, 64); // use signature prefix as nonce key
83
+ if (opts.nonceStore.has(nonceHex)) {
84
+ const resp = buildDenied('nonce already consumed');
85
+ await sendResponse(send, resp);
86
+ return resp;
87
+ }
88
+ opts.nonceStore.consume(nonceHex);
89
+ }
90
+ // Admission successful — update mesh state
91
+ opts.meshState.addPeer(peerNodeId);
92
+ log.info?.('admission: accepted producer', {
93
+ peer: peerNodeId.slice(0, 8),
94
+ });
95
+ const resp = {
96
+ accepted: true,
97
+ salt: '', // mesh salt (would be populated from mesh state)
98
+ acceptedProducers: opts.meshState.allPeers(),
99
+ reason: '', // never sent on wire
100
+ };
101
+ await sendResponse(send, resp);
102
+ return resp;
103
+ }
104
+ catch (e) {
105
+ log.error?.('admission: error', { error: String(e), peer: peerNodeId.slice(0, 8) });
106
+ const resp = buildDenied('internal error');
107
+ try {
108
+ await sendResponse(send, resp);
109
+ }
110
+ catch { /* best effort */ }
111
+ return resp;
112
+ }
113
+ }
114
+ /**
115
+ * Serve producer admission — accept loop that handles incoming
116
+ * producer admission connections until stopped.
117
+ */
118
+ export async function serveProducerAdmission(node, opts) {
119
+ const running = opts.running ?? { value: true };
120
+ const log = opts.logger ?? console;
121
+ while (running.value) {
122
+ try {
123
+ const conn = await node.acceptAster();
124
+ handleProducerAdmission(conn, opts).catch(e => {
125
+ log.error?.('admission connection error', { error: String(e) });
126
+ });
127
+ }
128
+ catch (e) {
129
+ if (!running.value)
130
+ break;
131
+ log.error?.('admission accept error', { error: String(e) });
132
+ }
133
+ }
134
+ }
135
+ // -- Helpers --
136
+ function buildDenied(reason) {
137
+ return {
138
+ accepted: false,
139
+ salt: '',
140
+ acceptedProducers: [],
141
+ reason, // internal only — wire response strips this
142
+ };
143
+ }
144
+ async function sendResponse(send, resp) {
145
+ // Never leak reason to peer (oracle protection)
146
+ const wireResp = { ...resp, reason: '' };
147
+ const bytes = new TextEncoder().encode(JSON.stringify(wireResp));
148
+ await send.writeAll(bytes);
149
+ await send.finish();
150
+ }
151
+ //# sourceMappingURL=producer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"producer.js","sourceRoot":"","sources":["../../src/trust/producer.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAC;AAE1D,OAAO,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAG1D,mCAAmC;AACnC,MAAM,CAAC,MAAM,uBAAuB,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,0BAA0B,CAAC,CAAC;AAi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AAK,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC,CAAC;IACjE,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC3B,MAAM,IAAI,CAAC,MAAM,EAAE,CAAC;AACtB,CAAC"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * RCAN (Role-based Capability Access control Network) validation.
3
+ *
4
+ * Spec reference: Aster-trust-spec.md
5
+ *
6
+ * Evaluates caller roles against capability requirements (ROLE, ANY_OF, ALL_OF).
7
+ * Also provides encode/decode for RCAN grant bytes (opaque until spec pins format).
8
+ */
9
+ import type { CapabilityRequirement } from '../service.js';
10
+ /** Extract caller roles from attributes (comma-separated aster.role). */
11
+ export declare function extractCallerRoles(attributes: Record<string, string>): Set<string>;
12
+ /**
13
+ * Evaluate a capability requirement against caller attributes.
14
+ *
15
+ * @returns true if the caller satisfies the requirement.
16
+ */
17
+ export declare function evaluateCapability(requirement: CapabilityRequirement, callerAttributes: Record<string, string>): boolean;
18
+ /**
19
+ * Validate an RCAN grant (opaque bytes).
20
+ * Currently a stub — non-empty grants accepted, empty bytes rejected.
21
+ *
22
+ * @returns [valid, reason]
23
+ */
24
+ export declare function validateRcan(rcanBytes: Uint8Array): [boolean, string | undefined];
25
+ /** Pass-through encoder for RCAN grant bytes. */
26
+ export declare function encodeRcan(data: Uint8Array): Uint8Array;
27
+ /** Pass-through decoder for RCAN grant bytes. */
28
+ export declare function decodeRcan(data: Uint8Array): Uint8Array;
29
+ //# sourceMappingURL=rcan.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rcan.d.ts","sourceRoot":"","sources":["../../src/trust/rcan.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAE3D,yEAAyE;AACzE,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,CAIlF;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,WAAW,EAAE,qBAAqB,EAClC,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACvC,OAAO,CAgBT;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,UAAU,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,CAAC,CAKjF;AAED,iDAAiD;AACjD,wBAAgB,UAAU,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAEvD;AAED,iDAAiD;AACjD,wBAAgB,UAAU,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAEvD"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * RCAN (Role-based Capability Access control Network) validation.
3
+ *
4
+ * Spec reference: Aster-trust-spec.md
5
+ *
6
+ * Evaluates caller roles against capability requirements (ROLE, ANY_OF, ALL_OF).
7
+ * Also provides encode/decode for RCAN grant bytes (opaque until spec pins format).
8
+ */
9
+ /** Extract caller roles from attributes (comma-separated aster.role). */
10
+ export function extractCallerRoles(attributes) {
11
+ const roleStr = attributes['aster.role'] ?? '';
12
+ if (!roleStr)
13
+ return new Set();
14
+ return new Set(roleStr.split(',').map(r => r.trim()).filter(Boolean));
15
+ }
16
+ /**
17
+ * Evaluate a capability requirement against caller attributes.
18
+ *
19
+ * @returns true if the caller satisfies the requirement.
20
+ */
21
+ export function evaluateCapability(requirement, callerAttributes) {
22
+ const roles = extractCallerRoles(callerAttributes);
23
+ switch (requirement.kind) {
24
+ case 'role':
25
+ // Must have the single required role
26
+ return requirement.roles.length > 0 && roles.has(requirement.roles[0]);
27
+ case 'any_of':
28
+ // Must have at least one of the listed roles
29
+ return requirement.roles.some(r => roles.has(r));
30
+ case 'all_of':
31
+ // Must have every listed role
32
+ return requirement.roles.every(r => roles.has(r));
33
+ default:
34
+ return false;
35
+ }
36
+ }
37
+ /**
38
+ * Validate an RCAN grant (opaque bytes).
39
+ * Currently a stub — non-empty grants accepted, empty bytes rejected.
40
+ *
41
+ * @returns [valid, reason]
42
+ */
43
+ export function validateRcan(rcanBytes) {
44
+ if (rcanBytes.length === 0) {
45
+ return [false, 'empty RCAN grant'];
46
+ }
47
+ return [true, undefined];
48
+ }
49
+ /** Pass-through encoder for RCAN grant bytes. */
50
+ export function encodeRcan(data) {
51
+ return data;
52
+ }
53
+ /** Pass-through decoder for RCAN grant bytes. */
54
+ export function decodeRcan(data) {
55
+ return data;
56
+ }
57
+ //# sourceMappingURL=rcan.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rcan.js","sourceRoot":"","sources":["../../src/trust/rcan.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,yEAAyE;AACzE,MAAM,UAAU,kBAAkB,CAAC,UAAkC;IACnE,MAAM,OAAO,GAAG,UAAU,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC;IAC/C,IAAI,CAAC,OAAO;QAAE,OAAO,IAAI,GAAG,EAAE,CAAC;IAC/B,OAAO,IAAI,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC;AACxE,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,kBAAkB,CAChC,WAAkC,EAClC,gBAAwC;IAExC,MAAM,KAAK,GAAG,kBAAkB,CAAC,gBAAgB,CAAC,CAAC;IAEnD,QAAQ,WAAW,CAAC,IAAI,EAAE,CAAC;QACzB,KAAK,MAAM;YACT,qCAAqC;YACrC,OAAO,WAAW,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC,CAAE,CAAC,CAAC;QAC1E,KAAK,QAAQ;YACX,6CAA6C;YAC7C,OAAO,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QACnD,KAAK,QAAQ;YACX,8BAA8B;YAC9B,OAAO,WAAW,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QACpD;YACE,OAAO,KAAK,CAAC;IACjB,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,SAAqB;IAChD,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC3B,OAAO,CAAC,KAAK,EAAE,kBAAkB,CAAC,CAAC;IACrC,CAAC;IACD,OAAO,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;AAC3B,CAAC;AAED,iDAAiD;AACjD,MAAM,UAAU,UAAU,CAAC,IAAgB;IACzC,OAAO,IAAI,CAAC;AACd,CAAC;AAED,iDAAiD;AACjD,MAAM,UAAU,UAAU,CAAC,IAAgB;IACzC,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Shared types and enums for the Aster RPC framework.
3
+ */
4
+ /** Serialization mode for Fory codec. */
5
+ export declare const SerializationMode: {
6
+ /** Cross-language (Fory XLANG). Default and recommended. */
7
+ readonly XLANG: 0;
8
+ /** Language-native. Only for LocalTransport (same trust domain). */
9
+ readonly NATIVE: 1;
10
+ /** Row-oriented. For random-access reads. */
11
+ readonly ROW: 2;
12
+ /** JSON over UTF-8. Cross-language fallback. The TypeScript binding
13
+ * uses this exclusively because Fory JS is not yet XLANG-compliant. */
14
+ readonly JSON: 3;
15
+ };
16
+ export type SerializationMode = (typeof SerializationMode)[keyof typeof SerializationMode];
17
+ /** RPC streaming pattern. */
18
+ export declare const RpcPattern: {
19
+ readonly UNARY: "unary";
20
+ readonly SERVER_STREAM: "server_stream";
21
+ readonly CLIENT_STREAM: "client_stream";
22
+ readonly BIDI_STREAM: "bidi_stream";
23
+ };
24
+ export type RpcPattern = (typeof RpcPattern)[keyof typeof RpcPattern];
25
+ /** Service dispatch scope.
26
+ *
27
+ * - SHARED: one service instance shared by all callers, fresh QUIC stream
28
+ * per RPC call. The default for stateless services.
29
+ * - SESSION: one service instance per client connection, all calls for that
30
+ * instance multiplexed onto a single bidirectional QUIC stream.
31
+ * Use this when the service needs per-peer state. The decorator
32
+ * still accepts the legacy alias `'stream'` on input.
33
+ */
34
+ export declare const RpcScope: {
35
+ readonly SHARED: "shared";
36
+ readonly SESSION: "session";
37
+ };
38
+ export type RpcScope = (typeof RpcScope)[keyof typeof RpcScope];
39
+ /** Exponential backoff configuration. */
40
+ export interface ExponentialBackoff {
41
+ initialMs: number;
42
+ maxMs: number;
43
+ multiplier: number;
44
+ jitter: number;
45
+ }
46
+ /** Default backoff: 100ms initial, 30s max, 2x multiplier, 10% jitter. */
47
+ export declare const DEFAULT_BACKOFF: ExponentialBackoff;
48
+ /** Retry policy configuration. */
49
+ export interface RetryPolicy {
50
+ maxAttempts: number;
51
+ backoff: ExponentialBackoff;
52
+ }
53
+ /** Default retry: 3 attempts with default backoff. */
54
+ export declare const DEFAULT_RETRY: RetryPolicy;
55
+ /** The ALPN protocol identifier for Aster RPC. */
56
+ export declare const RPC_ALPN: Uint8Array<ArrayBuffer>;
57
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,yCAAyC;AACzC,eAAO,MAAM,iBAAiB;IAC5B,4DAA4D;;IAE5D,oEAAoE;;IAEpE,6CAA6C;;IAE7C;4EACwE;;CAEhE,CAAC;AAEX,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,OAAO,iBAAiB,CAAC,CAAC;AAE3F,6BAA6B;AAC7B,eAAO,MAAM,UAAU;;;;;CAKb,CAAC;AAEX,MAAM,MAAM,UAAU,GAAG,CAAC,OAAO,UAAU,CAAC,CAAC,MAAM,OAAO,UAAU,CAAC,CAAC;AAEtE;;;;;;;;GAQG;AACH,eAAO,MAAM,QAAQ;;;CAGX,CAAC;AAEX,MAAM,MAAM,QAAQ,GAAG,CAAC,OAAO,QAAQ,CAAC,CAAC,MAAM,OAAO,QAAQ,CAAC,CAAC;AAEhE,yCAAyC;AACzC,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,0EAA0E;AAC1E,eAAO,MAAM,eAAe,EAAE,kBAK7B,CAAC;AAEF,kCAAkC;AAClC,MAAM,WAAW,WAAW;IAC1B,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,kBAAkB,CAAC;CAC7B;AAED,sDAAsD;AACtD,eAAO,MAAM,aAAa,EAAE,WAG3B,CAAC;AAEF,kDAAkD;AAClD,eAAO,MAAM,QAAQ,yBAAsC,CAAC"}
package/dist/types.js ADDED
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Shared types and enums for the Aster RPC framework.
3
+ */
4
+ /** Serialization mode for Fory codec. */
5
+ export const SerializationMode = {
6
+ /** Cross-language (Fory XLANG). Default and recommended. */
7
+ XLANG: 0,
8
+ /** Language-native. Only for LocalTransport (same trust domain). */
9
+ NATIVE: 1,
10
+ /** Row-oriented. For random-access reads. */
11
+ ROW: 2,
12
+ /** JSON over UTF-8. Cross-language fallback. The TypeScript binding
13
+ * uses this exclusively because Fory JS is not yet XLANG-compliant. */
14
+ JSON: 3,
15
+ };
16
+ /** RPC streaming pattern. */
17
+ export const RpcPattern = {
18
+ UNARY: 'unary',
19
+ SERVER_STREAM: 'server_stream',
20
+ CLIENT_STREAM: 'client_stream',
21
+ BIDI_STREAM: 'bidi_stream',
22
+ };
23
+ /** Service dispatch scope.
24
+ *
25
+ * - SHARED: one service instance shared by all callers, fresh QUIC stream
26
+ * per RPC call. The default for stateless services.
27
+ * - SESSION: one service instance per client connection, all calls for that
28
+ * instance multiplexed onto a single bidirectional QUIC stream.
29
+ * Use this when the service needs per-peer state. The decorator
30
+ * still accepts the legacy alias `'stream'` on input.
31
+ */
32
+ export const RpcScope = {
33
+ SHARED: 'shared',
34
+ SESSION: 'session',
35
+ };
36
+ /** Default backoff: 100ms initial, 30s max, 2x multiplier, 10% jitter. */
37
+ export const DEFAULT_BACKOFF = {
38
+ initialMs: 100,
39
+ maxMs: 30_000,
40
+ multiplier: 2.0,
41
+ jitter: 0.1,
42
+ };
43
+ /** Default retry: 3 attempts with default backoff. */
44
+ export const DEFAULT_RETRY = {
45
+ maxAttempts: 3,
46
+ backoff: DEFAULT_BACKOFF,
47
+ };
48
+ /** The ALPN protocol identifier for Aster RPC. */
49
+ export const RPC_ALPN = new TextEncoder().encode('aster/1');
50
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,yCAAyC;AACzC,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,4DAA4D;IAC5D,KAAK,EAAE,CAAC;IACR,oEAAoE;IACpE,MAAM,EAAE,CAAC;IACT,6CAA6C;IAC7C,GAAG,EAAE,CAAC;IACN;4EACwE;IACxE,IAAI,EAAE,CAAC;CACC,CAAC;AAIX,6BAA6B;AAC7B,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,KAAK,EAAE,OAAO;IACd,aAAa,EAAE,eAAe;IAC9B,aAAa,EAAE,eAAe;IAC9B,WAAW,EAAE,aAAa;CAClB,CAAC;AAIX;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG;IACtB,MAAM,EAAE,QAAQ;IAChB,OAAO,EAAE,SAAS;CACV,CAAC;AAYX,0EAA0E;AAC1E,MAAM,CAAC,MAAM,eAAe,GAAuB;IACjD,SAAS,EAAE,GAAG;IACd,KAAK,EAAE,MAAM;IACb,UAAU,EAAE,GAAG;IACf,MAAM,EAAE,GAAG;CACZ,CAAC;AAQF,sDAAsD;AACtD,MAAM,CAAC,MAAM,aAAa,GAAgB;IACxC,WAAW,EAAE,CAAC;IACd,OAAO,EAAE,eAAe;CACzB,CAAC;AAEF,kDAAkD;AAClD,MAAM,CAAC,MAAM,QAAQ,GAAG,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * xlang.ts -- XLANG codec factory for cross-language interop.
3
+ *
4
+ * Creates a ForyCodec pre-configured with the Aster protocol types
5
+ * (StreamHeader, RpcStatus) for cross-language communication with
6
+ * Python and other language bindings.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import { createXlangCodec } from '@aster-rpc/aster';
11
+ * const codec = createXlangCodec();
12
+ * const transport = new IrohTransport(connection, codec);
13
+ * ```
14
+ */
15
+ import { ForyCodec } from './codec.js';
16
+ /**
17
+ * Create a ForyCodec pre-configured for cross-language (XLANG) interop.
18
+ *
19
+ * Registers the Aster protocol types (StreamHeader, CallHeader, RpcStatus)
20
+ * so the transport can encode/decode the wire protocol. User-defined types
21
+ * are serialized dynamically by Fory's compatible mode.
22
+ *
23
+ * Requires `@apache-fory/core` to be installed.
24
+ */
25
+ export declare function createXlangCodec(): ForyCodec;
26
+ //# sourceMappingURL=xlang.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xlang.d.ts","sourceRoot":"","sources":["../src/xlang.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAGvC;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,IAAI,SAAS,CAkC5C"}
package/dist/xlang.js ADDED
@@ -0,0 +1,55 @@
1
+ /**
2
+ * xlang.ts -- XLANG codec factory for cross-language interop.
3
+ *
4
+ * Creates a ForyCodec pre-configured with the Aster protocol types
5
+ * (StreamHeader, RpcStatus) for cross-language communication with
6
+ * Python and other language bindings.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import { createXlangCodec } from '@aster-rpc/aster';
11
+ * const codec = createXlangCodec();
12
+ * const transport = new IrohTransport(connection, codec);
13
+ * ```
14
+ */
15
+ import { ForyCodec } from './codec.js';
16
+ import { StreamHeader, CallHeader, RpcStatus } from './protocol.js';
17
+ /**
18
+ * Create a ForyCodec pre-configured for cross-language (XLANG) interop.
19
+ *
20
+ * Registers the Aster protocol types (StreamHeader, CallHeader, RpcStatus)
21
+ * so the transport can encode/decode the wire protocol. User-defined types
22
+ * are serialized dynamically by Fory's compatible mode.
23
+ *
24
+ * Requires `@apache-fory/core` to be installed.
25
+ */
26
+ export function createXlangCodec() {
27
+ // Dynamic import to keep @apache-fory/core optional
28
+ let Fory;
29
+ try {
30
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
31
+ Fory = require('@apache-fory/core').default;
32
+ }
33
+ catch {
34
+ throw new Error('Cross-language (XLANG) codec requires @apache-fory/core. ' +
35
+ 'Install it with: bun add @apache-fory/core');
36
+ }
37
+ const fory = new Fory({ refTracking: false });
38
+ const codec = new ForyCodec(fory);
39
+ // Register protocol types with their wire tags
40
+ const protocolTypes = [StreamHeader, CallHeader, RpcStatus];
41
+ for (const cls of protocolTypes) {
42
+ const tag = cls.wireType;
43
+ if (tag) {
44
+ const [ns, name] = tag.includes('/') ? tag.split('/') : ['', tag];
45
+ // Build Fory type description from the class
46
+ codec.registerType(fory.classResolver.createTypeDescription({
47
+ type: cls,
48
+ namespace: ns,
49
+ typeName: name,
50
+ }));
51
+ }
52
+ }
53
+ return codec;
54
+ }
55
+ //# sourceMappingURL=xlang.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"xlang.js","sourceRoot":"","sources":["../src/xlang.ts"],"names":[],"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}
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@aster-rpc/aster",
3
+ "version": "0.1.2",
4
+ "description": "Aster RPC framework for TypeScript \u2014 P2P services with type safety, streaming, and trust",
5
+ "type": "module",
6
+ "main": "./dist/index.js",
7
+ "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.js",
11
+ "types": "./dist/index.d.ts"
12
+ }
13
+ },
14
+ "files": [
15
+ "dist",
16
+ "README.md",
17
+ "LICENSE"
18
+ ],
19
+ "scripts": {
20
+ "build": "tsc",
21
+ "typecheck": "tsc --noEmit",
22
+ "test": "vitest run",
23
+ "test:watch": "vitest"
24
+ },
25
+ "dependencies": {
26
+ "@aster-rpc/transport": "0.1.2"
27
+ },
28
+ "devDependencies": {
29
+ "@types/node": "^25.5.2",
30
+ "typescript": "^5.7.0",
31
+ "vitest": "^3.2.0"
32
+ },
33
+ "engines": {
34
+ "node": ">=20.0.0"
35
+ },
36
+ "license": "Apache-2.0",
37
+ "homepage": "https://github.com/aster-rpc/aster-rpc",
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "git+https://github.com/aster-rpc/aster-rpc.git",
41
+ "directory": "bindings/typescript/packages/aster"
42
+ },
43
+ "bugs": {
44
+ "url": "https://github.com/aster-rpc/aster-rpc/issues"
45
+ },
46
+ "keywords": [
47
+ "iroh",
48
+ "p2p",
49
+ "rpc",
50
+ "quic",
51
+ "aster",
52
+ "streaming",
53
+ "framework"
54
+ ],
55
+ "publishConfig": {
56
+ "access": "public",
57
+ "registry": "https://registry.npmjs.org/"
58
+ }
59
+ }