@tinycloud/sdk-core 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. package/LICENSE.md +320 -0
  2. package/dist/TinyCloud.d.ts +206 -0
  3. package/dist/TinyCloud.d.ts.map +1 -0
  4. package/dist/TinyCloud.js +244 -0
  5. package/dist/TinyCloud.js.map +1 -0
  6. package/dist/TinyCloud.schema.d.ts +173 -0
  7. package/dist/TinyCloud.schema.d.ts.map +1 -0
  8. package/dist/TinyCloud.schema.js +136 -0
  9. package/dist/TinyCloud.schema.js.map +1 -0
  10. package/dist/TinyCloud.schema.test.d.ts +5 -0
  11. package/dist/TinyCloud.schema.test.d.ts.map +1 -0
  12. package/dist/TinyCloud.schema.test.js +286 -0
  13. package/dist/TinyCloud.schema.test.js.map +1 -0
  14. package/dist/authorization/CapabilityKeyRegistry.d.ts +317 -0
  15. package/dist/authorization/CapabilityKeyRegistry.d.ts.map +1 -0
  16. package/dist/authorization/CapabilityKeyRegistry.js +509 -0
  17. package/dist/authorization/CapabilityKeyRegistry.js.map +1 -0
  18. package/dist/authorization/authorization.schema.d.ts +233 -0
  19. package/dist/authorization/authorization.schema.d.ts.map +1 -0
  20. package/dist/authorization/authorization.schema.js +220 -0
  21. package/dist/authorization/authorization.schema.js.map +1 -0
  22. package/dist/authorization/authorization.schema.test.d.ts +5 -0
  23. package/dist/authorization/authorization.schema.test.d.ts.map +1 -0
  24. package/dist/authorization/authorization.schema.test.js +618 -0
  25. package/dist/authorization/authorization.schema.test.js.map +1 -0
  26. package/dist/authorization/index.d.ts +38 -0
  27. package/dist/authorization/index.d.ts.map +1 -0
  28. package/dist/authorization/index.js +52 -0
  29. package/dist/authorization/index.js.map +1 -0
  30. package/dist/authorization/spaceCreation.d.ts +96 -0
  31. package/dist/authorization/spaceCreation.d.ts.map +1 -0
  32. package/dist/authorization/spaceCreation.js +35 -0
  33. package/dist/authorization/spaceCreation.js.map +1 -0
  34. package/dist/authorization/spaceCreation.schema.d.ts +67 -0
  35. package/dist/authorization/spaceCreation.schema.d.ts.map +1 -0
  36. package/dist/authorization/spaceCreation.schema.js +95 -0
  37. package/dist/authorization/spaceCreation.schema.js.map +1 -0
  38. package/dist/authorization/spaceCreation.schema.test.d.ts +5 -0
  39. package/dist/authorization/spaceCreation.schema.test.d.ts.map +1 -0
  40. package/dist/authorization/spaceCreation.schema.test.js +168 -0
  41. package/dist/authorization/spaceCreation.schema.test.js.map +1 -0
  42. package/dist/authorization/strategies.d.ts +134 -0
  43. package/dist/authorization/strategies.d.ts.map +1 -0
  44. package/dist/authorization/strategies.js +15 -0
  45. package/dist/authorization/strategies.js.map +1 -0
  46. package/dist/authorization/strategies.schema.d.ts +185 -0
  47. package/dist/authorization/strategies.schema.d.ts.map +1 -0
  48. package/dist/authorization/strategies.schema.js +147 -0
  49. package/dist/authorization/strategies.schema.js.map +1 -0
  50. package/dist/authorization/strategies.schema.test.d.ts +5 -0
  51. package/dist/authorization/strategies.schema.test.d.ts.map +1 -0
  52. package/dist/authorization/strategies.schema.test.js +253 -0
  53. package/dist/authorization/strategies.schema.test.js.map +1 -0
  54. package/dist/delegations/DelegationManager.d.ts +164 -0
  55. package/dist/delegations/DelegationManager.d.ts.map +1 -0
  56. package/dist/delegations/DelegationManager.js +428 -0
  57. package/dist/delegations/DelegationManager.js.map +1 -0
  58. package/dist/delegations/SharingService.d.ts +279 -0
  59. package/dist/delegations/SharingService.d.ts.map +1 -0
  60. package/dist/delegations/SharingService.js +558 -0
  61. package/dist/delegations/SharingService.js.map +1 -0
  62. package/dist/delegations/SharingService.schema.d.ts +401 -0
  63. package/dist/delegations/SharingService.schema.d.ts.map +1 -0
  64. package/dist/delegations/SharingService.schema.js +211 -0
  65. package/dist/delegations/SharingService.schema.js.map +1 -0
  66. package/dist/delegations/index.d.ts +38 -0
  67. package/dist/delegations/index.d.ts.map +1 -0
  68. package/dist/delegations/index.js +42 -0
  69. package/dist/delegations/index.js.map +1 -0
  70. package/dist/delegations/types.d.ts +13 -0
  71. package/dist/delegations/types.d.ts.map +1 -0
  72. package/dist/delegations/types.js +42 -0
  73. package/dist/delegations/types.js.map +1 -0
  74. package/dist/delegations/types.schema.d.ts +1641 -0
  75. package/dist/delegations/types.schema.d.ts.map +1 -0
  76. package/dist/delegations/types.schema.js +535 -0
  77. package/dist/delegations/types.schema.js.map +1 -0
  78. package/dist/delegations/types.schema.test.d.ts +5 -0
  79. package/dist/delegations/types.schema.test.d.ts.map +1 -0
  80. package/dist/delegations/types.schema.test.js +627 -0
  81. package/dist/delegations/types.schema.test.js.map +1 -0
  82. package/dist/index.d.ts +22 -0
  83. package/dist/index.d.ts.map +1 -0
  84. package/dist/index.js +52 -0
  85. package/dist/index.js.map +1 -0
  86. package/dist/json-schema.d.ts +327 -0
  87. package/dist/json-schema.d.ts.map +1 -0
  88. package/dist/json-schema.js +703 -0
  89. package/dist/json-schema.js.map +1 -0
  90. package/dist/json-schema.test.d.ts +7 -0
  91. package/dist/json-schema.test.d.ts.map +1 -0
  92. package/dist/json-schema.test.js +365 -0
  93. package/dist/json-schema.test.js.map +1 -0
  94. package/dist/signer.d.ts +28 -0
  95. package/dist/signer.d.ts.map +1 -0
  96. package/dist/signer.js +2 -0
  97. package/dist/signer.js.map +1 -0
  98. package/dist/space.d.ts +53 -0
  99. package/dist/space.d.ts.map +1 -0
  100. package/dist/space.js +67 -0
  101. package/dist/space.js.map +1 -0
  102. package/dist/space.schema.d.ts +65 -0
  103. package/dist/space.schema.d.ts.map +1 -0
  104. package/dist/space.schema.js +65 -0
  105. package/dist/space.schema.js.map +1 -0
  106. package/dist/space.schema.test.d.ts +5 -0
  107. package/dist/space.schema.test.d.ts.map +1 -0
  108. package/dist/space.schema.test.js +148 -0
  109. package/dist/space.schema.test.js.map +1 -0
  110. package/dist/spaces/Space.d.ts +175 -0
  111. package/dist/spaces/Space.d.ts.map +1 -0
  112. package/dist/spaces/Space.js +84 -0
  113. package/dist/spaces/Space.js.map +1 -0
  114. package/dist/spaces/SpaceService.d.ts +271 -0
  115. package/dist/spaces/SpaceService.d.ts.map +1 -0
  116. package/dist/spaces/SpaceService.js +715 -0
  117. package/dist/spaces/SpaceService.js.map +1 -0
  118. package/dist/spaces/index.d.ts +11 -0
  119. package/dist/spaces/index.d.ts.map +1 -0
  120. package/dist/spaces/index.js +20 -0
  121. package/dist/spaces/index.js.map +1 -0
  122. package/dist/spaces/spaces.schema.d.ts +421 -0
  123. package/dist/spaces/spaces.schema.d.ts.map +1 -0
  124. package/dist/spaces/spaces.schema.js +342 -0
  125. package/dist/spaces/spaces.schema.js.map +1 -0
  126. package/dist/spaces/spaces.schema.test.d.ts +5 -0
  127. package/dist/spaces/spaces.schema.test.d.ts.map +1 -0
  128. package/dist/spaces/spaces.schema.test.js +471 -0
  129. package/dist/spaces/spaces.schema.test.js.map +1 -0
  130. package/dist/storage.d.ts +47 -0
  131. package/dist/storage.d.ts.map +1 -0
  132. package/dist/storage.js +14 -0
  133. package/dist/storage.js.map +1 -0
  134. package/dist/storage.schema.d.ts +277 -0
  135. package/dist/storage.schema.d.ts.map +1 -0
  136. package/dist/storage.schema.js +185 -0
  137. package/dist/storage.schema.js.map +1 -0
  138. package/dist/storage.schema.test.d.ts +5 -0
  139. package/dist/storage.schema.test.d.ts.map +1 -0
  140. package/dist/storage.schema.test.js +346 -0
  141. package/dist/storage.schema.test.js.map +1 -0
  142. package/dist/userAuthorization.d.ts +99 -0
  143. package/dist/userAuthorization.d.ts.map +1 -0
  144. package/dist/userAuthorization.js +3 -0
  145. package/dist/userAuthorization.js.map +1 -0
  146. package/dist/userAuthorization.schema.d.ts +259 -0
  147. package/dist/userAuthorization.schema.d.ts.map +1 -0
  148. package/dist/userAuthorization.schema.js +175 -0
  149. package/dist/userAuthorization.schema.js.map +1 -0
  150. package/dist/userAuthorization.schema.test.d.ts +5 -0
  151. package/dist/userAuthorization.schema.test.d.ts.map +1 -0
  152. package/dist/userAuthorization.schema.test.js +356 -0
  153. package/dist/userAuthorization.schema.test.js.map +1 -0
  154. package/dist/version.d.ts +30 -0
  155. package/dist/version.d.ts.map +1 -0
  156. package/dist/version.js +54 -0
  157. package/dist/version.js.map +1 -0
  158. package/dist/wasm-validation.d.ts +287 -0
  159. package/dist/wasm-validation.d.ts.map +1 -0
  160. package/dist/wasm-validation.js +219 -0
  161. package/dist/wasm-validation.js.map +1 -0
  162. package/dist/wasm-validation.test.d.ts +5 -0
  163. package/dist/wasm-validation.test.d.ts.map +1 -0
  164. package/dist/wasm-validation.test.js +233 -0
  165. package/dist/wasm-validation.test.js.map +1 -0
  166. package/package.json +40 -0
@@ -0,0 +1,287 @@
1
+ /**
2
+ * Debug-only WASM output validation utilities.
3
+ *
4
+ * These utilities provide runtime validation for WASM function outputs
5
+ * in development builds only. In production, validation is skipped for
6
+ * performance since the Rust WASM layer already performs its own validation.
7
+ *
8
+ * @packageDocumentation
9
+ */
10
+ import { z } from "zod";
11
+ /**
12
+ * Validation result returned by debug validators.
13
+ */
14
+ export interface WasmValidationResult<T> {
15
+ /** The data (original or validated) */
16
+ data: T;
17
+ /** Whether validation was performed */
18
+ validated: boolean;
19
+ /** Validation issues if any (only populated in non-production) */
20
+ issues?: z.ZodIssue[];
21
+ }
22
+ /**
23
+ * Validates WASM function output against a Zod schema.
24
+ * Only validates in non-production environments for performance.
25
+ *
26
+ * In development:
27
+ * - Validates the output against the schema
28
+ * - Logs a warning if validation fails
29
+ * - Returns the original data (never throws)
30
+ *
31
+ * In production:
32
+ * - Skips validation entirely
33
+ * - Returns the data as-is
34
+ *
35
+ * @param schema - The Zod schema to validate against
36
+ * @param data - The WASM function output to validate
37
+ * @param fnName - Name of the WASM function (for logging)
38
+ * @returns The original data with validation metadata
39
+ *
40
+ * @example
41
+ * ```typescript
42
+ * import { validateWasmOutput, CreateDelegationWasmResultSchema } from "@tinycloud/sdk-core";
43
+ *
44
+ * const rawResult = wasmCreateDelegation(...args);
45
+ * const result = validateWasmOutput(
46
+ * CreateDelegationWasmResultSchema,
47
+ * rawResult,
48
+ * "createDelegation"
49
+ * );
50
+ * // In dev: logs warning if validation fails
51
+ * // In prod: returns immediately without validation
52
+ * ```
53
+ */
54
+ export declare function validateWasmOutput<T>(schema: z.ZodType<T>, data: unknown, fnName: string): WasmValidationResult<T>;
55
+ /**
56
+ * Schema for validating createDelegation WASM output.
57
+ *
58
+ * This is a relaxed version of CreateDelegationWasmResultSchema that
59
+ * accepts the raw WASM output format (expiry as number/string) before
60
+ * transformation to Date.
61
+ */
62
+ export declare const CreateDelegationWasmRawResultSchema: z.ZodObject<{
63
+ /** Base64url-encoded UCAN delegation */
64
+ delegation: z.ZodString;
65
+ /** CID of the delegation */
66
+ cid: z.ZodString;
67
+ /** DID of the delegate */
68
+ delegateDID: z.ZodString;
69
+ /** Resource path the delegation grants access to */
70
+ path: z.ZodString;
71
+ /** Actions the delegation authorizes */
72
+ actions: z.ZodArray<z.ZodString, "many">;
73
+ /** Expiration time (may be number, string, or Date from WASM) */
74
+ expiry: z.ZodUnion<[z.ZodNumber, z.ZodString, z.ZodDate]>;
75
+ }, "strip", z.ZodTypeAny, {
76
+ path: string;
77
+ delegation: string;
78
+ cid: string;
79
+ delegateDID: string;
80
+ actions: string[];
81
+ expiry: string | number | Date;
82
+ }, {
83
+ path: string;
84
+ delegation: string;
85
+ cid: string;
86
+ delegateDID: string;
87
+ actions: string[];
88
+ expiry: string | number | Date;
89
+ }>;
90
+ export type CreateDelegationWasmRawResult = z.infer<typeof CreateDelegationWasmRawResultSchema>;
91
+ /**
92
+ * Validates the output of the createDelegation WASM function.
93
+ *
94
+ * Uses the raw result schema which accepts expiry as number/string/Date
95
+ * to handle the raw WASM output before any TypeScript transformation.
96
+ *
97
+ * @param data - The raw output from WASM createDelegation
98
+ * @returns Validation result with the data
99
+ *
100
+ * @example
101
+ * ```typescript
102
+ * import { validateCreateDelegationWasmOutput } from "@tinycloud/sdk-core";
103
+ *
104
+ * const rawResult = wasmCreateDelegation(session, delegateDID, ...);
105
+ * const { data, issues } = validateCreateDelegationWasmOutput(rawResult);
106
+ * if (issues) {
107
+ * // Handle validation issues in development
108
+ * }
109
+ * ```
110
+ */
111
+ export declare function validateCreateDelegationWasmOutput(data: unknown): WasmValidationResult<CreateDelegationWasmRawResult>;
112
+ /**
113
+ * Schema for validating invoke WASM output.
114
+ *
115
+ * The invoke function returns an object with headers and body properties.
116
+ */
117
+ export declare const InvokeWasmResultSchema: z.ZodObject<{
118
+ /** HTTP headers from the invocation response */
119
+ headers: z.ZodRecord<z.ZodString, z.ZodString>;
120
+ /** Request body to send */
121
+ body: z.ZodString;
122
+ }, "strip", z.ZodTypeAny, {
123
+ body: string;
124
+ headers: Record<string, string>;
125
+ }, {
126
+ body: string;
127
+ headers: Record<string, string>;
128
+ }>;
129
+ export type InvokeWasmResult = z.infer<typeof InvokeWasmResultSchema>;
130
+ /**
131
+ * Validates the output of the invoke WASM function.
132
+ *
133
+ * @param data - The raw output from WASM invoke
134
+ * @returns Validation result with the data
135
+ */
136
+ export declare function validateInvokeWasmOutput(data: unknown): WasmValidationResult<InvokeWasmResult>;
137
+ /**
138
+ * Schema for validating prepareSession WASM output.
139
+ */
140
+ export declare const PrepareSessionWasmResultSchema: z.ZodObject<{
141
+ /** SIWE message to sign */
142
+ siweMessage: z.ZodString;
143
+ /** JWK for the session key */
144
+ jwk: z.ZodObject<{
145
+ kty: z.ZodString;
146
+ crv: z.ZodOptional<z.ZodString>;
147
+ x: z.ZodOptional<z.ZodString>;
148
+ d: z.ZodOptional<z.ZodString>;
149
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
150
+ kty: z.ZodString;
151
+ crv: z.ZodOptional<z.ZodString>;
152
+ x: z.ZodOptional<z.ZodString>;
153
+ d: z.ZodOptional<z.ZodString>;
154
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
155
+ kty: z.ZodString;
156
+ crv: z.ZodOptional<z.ZodString>;
157
+ x: z.ZodOptional<z.ZodString>;
158
+ d: z.ZodOptional<z.ZodString>;
159
+ }, z.ZodTypeAny, "passthrough">>;
160
+ /** Verification method */
161
+ verificationMethod: z.ZodString;
162
+ }, "strip", z.ZodTypeAny, {
163
+ jwk: {
164
+ kty: string;
165
+ crv?: string | undefined;
166
+ x?: string | undefined;
167
+ d?: string | undefined;
168
+ } & {
169
+ [k: string]: unknown;
170
+ };
171
+ verificationMethod: string;
172
+ siweMessage: string;
173
+ }, {
174
+ jwk: {
175
+ kty: string;
176
+ crv?: string | undefined;
177
+ x?: string | undefined;
178
+ d?: string | undefined;
179
+ } & {
180
+ [k: string]: unknown;
181
+ };
182
+ verificationMethod: string;
183
+ siweMessage: string;
184
+ }>;
185
+ export type PrepareSessionWasmResult = z.infer<typeof PrepareSessionWasmResultSchema>;
186
+ /**
187
+ * Validates the output of the prepareSession WASM function.
188
+ *
189
+ * @param data - The raw output from WASM prepareSession
190
+ * @returns Validation result with the data
191
+ */
192
+ export declare function validatePrepareSessionWasmOutput(data: unknown): WasmValidationResult<PrepareSessionWasmResult>;
193
+ /**
194
+ * Schema for validating completeSessionSetup WASM output (Session type).
195
+ */
196
+ export declare const SessionWasmResultSchema: z.ZodObject<{
197
+ /** Delegation header for authentication */
198
+ delegationHeader: z.ZodObject<{
199
+ Authorization: z.ZodString;
200
+ }, "strip", z.ZodTypeAny, {
201
+ Authorization: string;
202
+ }, {
203
+ Authorization: string;
204
+ }>;
205
+ /** CID of the delegation */
206
+ delegationCid: z.ZodString;
207
+ /** JWK for the session key */
208
+ jwk: z.ZodObject<{
209
+ kty: z.ZodString;
210
+ crv: z.ZodOptional<z.ZodString>;
211
+ x: z.ZodOptional<z.ZodString>;
212
+ d: z.ZodOptional<z.ZodString>;
213
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
214
+ kty: z.ZodString;
215
+ crv: z.ZodOptional<z.ZodString>;
216
+ x: z.ZodOptional<z.ZodString>;
217
+ d: z.ZodOptional<z.ZodString>;
218
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
219
+ kty: z.ZodString;
220
+ crv: z.ZodOptional<z.ZodString>;
221
+ x: z.ZodOptional<z.ZodString>;
222
+ d: z.ZodOptional<z.ZodString>;
223
+ }, z.ZodTypeAny, "passthrough">>;
224
+ /** Space ID */
225
+ spaceId: z.ZodString;
226
+ /** Verification method */
227
+ verificationMethod: z.ZodString;
228
+ }, "strip", z.ZodTypeAny, {
229
+ jwk: {
230
+ kty: string;
231
+ crv?: string | undefined;
232
+ x?: string | undefined;
233
+ d?: string | undefined;
234
+ } & {
235
+ [k: string]: unknown;
236
+ };
237
+ spaceId: string;
238
+ delegationHeader: {
239
+ Authorization: string;
240
+ };
241
+ delegationCid: string;
242
+ verificationMethod: string;
243
+ }, {
244
+ jwk: {
245
+ kty: string;
246
+ crv?: string | undefined;
247
+ x?: string | undefined;
248
+ d?: string | undefined;
249
+ } & {
250
+ [k: string]: unknown;
251
+ };
252
+ spaceId: string;
253
+ delegationHeader: {
254
+ Authorization: string;
255
+ };
256
+ delegationCid: string;
257
+ verificationMethod: string;
258
+ }>;
259
+ export type SessionWasmResult = z.infer<typeof SessionWasmResultSchema>;
260
+ /**
261
+ * Validates the output of the completeSessionSetup WASM function.
262
+ *
263
+ * @param data - The raw output from WASM completeSessionSetup
264
+ * @returns Validation result with the data
265
+ */
266
+ export declare function validateCompleteSessionSetupWasmOutput(data: unknown): WasmValidationResult<SessionWasmResult>;
267
+ /**
268
+ * Schema for validating siweToDelegationHeaders WASM output.
269
+ */
270
+ export declare const SiweToDelegationHeadersWasmResultSchema: z.ZodObject<{
271
+ /** Authorization header for the delegation */
272
+ Authorization: z.ZodString;
273
+ }, "strip", z.ZodTypeAny, {
274
+ Authorization: string;
275
+ }, {
276
+ Authorization: string;
277
+ }>;
278
+ export type SiweToDelegationHeadersWasmResult = z.infer<typeof SiweToDelegationHeadersWasmResultSchema>;
279
+ /**
280
+ * Validates the output of the siweToDelegationHeaders WASM function.
281
+ *
282
+ * @param data - The raw output from WASM siweToDelegationHeaders
283
+ * @returns Validation result with the data
284
+ */
285
+ export declare function validateSiweToDelegationHeadersWasmOutput(data: unknown): WasmValidationResult<SiweToDelegationHeadersWasmResult>;
286
+ export { CreateDelegationWasmResultSchema } from "./delegations/types.schema.js";
287
+ //# sourceMappingURL=wasm-validation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wasm-validation.d.ts","sourceRoot":"","sources":["../src/wasm-validation.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAoBxB;;GAEG;AACH,MAAM,WAAW,oBAAoB,CAAC,CAAC;IACrC,uCAAuC;IACvC,IAAI,EAAE,CAAC,CAAC;IACR,uCAAuC;IACvC,SAAS,EAAE,OAAO,CAAC;IACnB,kEAAkE;IAClE,MAAM,CAAC,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC;CACvB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,EAClC,MAAM,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,EACpB,IAAI,EAAE,OAAO,EACb,MAAM,EAAE,MAAM,GACb,oBAAoB,CAAC,CAAC,CAAC,CA4BzB;AAED;;;;;;GAMG;AACH,eAAO,MAAM,mCAAmC;IAC9C,wCAAwC;;IAExC,4BAA4B;;IAE5B,0BAA0B;;IAE1B,oDAAoD;;IAEpD,wCAAwC;;IAExC,iEAAiE;;;;;;;;;;;;;;;;EAEjE,CAAC;AAEH,MAAM,MAAM,6BAA6B,GAAG,CAAC,CAAC,KAAK,CACjD,OAAO,mCAAmC,CAC3C,CAAC;AAEF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,kCAAkC,CAChD,IAAI,EAAE,OAAO,GACZ,oBAAoB,CAAC,6BAA6B,CAAC,CAMrD;AAED;;;;GAIG;AACH,eAAO,MAAM,sBAAsB;IACjC,gDAAgD;;IAEhD,2BAA2B;;;;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}
@@ -0,0 +1,219 @@
1
+ /**
2
+ * Debug-only WASM output validation utilities.
3
+ *
4
+ * These utilities provide runtime validation for WASM function outputs
5
+ * in development builds only. In production, validation is skipped for
6
+ * performance since the Rust WASM layer already performs its own validation.
7
+ *
8
+ * @packageDocumentation
9
+ */
10
+ import { z } from "zod";
11
+ /**
12
+ * Check if we're running in a production environment.
13
+ * Checks both Node.js and browser bundler conventions.
14
+ */
15
+ function isProduction() {
16
+ // Node.js environment
17
+ if (typeof process !== "undefined" && process.env?.NODE_ENV === "production") {
18
+ return true;
19
+ }
20
+ // Browser bundler convention (Vite, webpack, etc.)
21
+ // @ts-ignore - import.meta.env may not exist in all environments
22
+ if (typeof import.meta !== "undefined" && import.meta.env?.PROD === true) {
23
+ return true;
24
+ }
25
+ return false;
26
+ }
27
+ /**
28
+ * Validates WASM function output against a Zod schema.
29
+ * Only validates in non-production environments for performance.
30
+ *
31
+ * In development:
32
+ * - Validates the output against the schema
33
+ * - Logs a warning if validation fails
34
+ * - Returns the original data (never throws)
35
+ *
36
+ * In production:
37
+ * - Skips validation entirely
38
+ * - Returns the data as-is
39
+ *
40
+ * @param schema - The Zod schema to validate against
41
+ * @param data - The WASM function output to validate
42
+ * @param fnName - Name of the WASM function (for logging)
43
+ * @returns The original data with validation metadata
44
+ *
45
+ * @example
46
+ * ```typescript
47
+ * import { validateWasmOutput, CreateDelegationWasmResultSchema } from "@tinycloud/sdk-core";
48
+ *
49
+ * const rawResult = wasmCreateDelegation(...args);
50
+ * const result = validateWasmOutput(
51
+ * CreateDelegationWasmResultSchema,
52
+ * rawResult,
53
+ * "createDelegation"
54
+ * );
55
+ * // In dev: logs warning if validation fails
56
+ * // In prod: returns immediately without validation
57
+ * ```
58
+ */
59
+ export function validateWasmOutput(schema, data, fnName) {
60
+ // Skip validation in production for performance
61
+ if (isProduction()) {
62
+ return {
63
+ data: data,
64
+ validated: false,
65
+ };
66
+ }
67
+ const result = schema.safeParse(data);
68
+ if (!result.success) {
69
+ console.warn(`[WASM Debug] ${fnName} output validation failed:`, result.error.issues, "\nReceived data:", data);
70
+ return {
71
+ data: data,
72
+ validated: true,
73
+ issues: result.error.issues,
74
+ };
75
+ }
76
+ return {
77
+ data: result.data,
78
+ validated: true,
79
+ };
80
+ }
81
+ /**
82
+ * Schema for validating createDelegation WASM output.
83
+ *
84
+ * This is a relaxed version of CreateDelegationWasmResultSchema that
85
+ * accepts the raw WASM output format (expiry as number/string) before
86
+ * transformation to Date.
87
+ */
88
+ export const CreateDelegationWasmRawResultSchema = z.object({
89
+ /** Base64url-encoded UCAN delegation */
90
+ delegation: z.string(),
91
+ /** CID of the delegation */
92
+ cid: z.string(),
93
+ /** DID of the delegate */
94
+ delegateDID: z.string(),
95
+ /** Resource path the delegation grants access to */
96
+ path: z.string(),
97
+ /** Actions the delegation authorizes */
98
+ actions: z.array(z.string()),
99
+ /** Expiration time (may be number, string, or Date from WASM) */
100
+ expiry: z.union([z.number(), z.string(), z.date()]),
101
+ });
102
+ /**
103
+ * Validates the output of the createDelegation WASM function.
104
+ *
105
+ * Uses the raw result schema which accepts expiry as number/string/Date
106
+ * to handle the raw WASM output before any TypeScript transformation.
107
+ *
108
+ * @param data - The raw output from WASM createDelegation
109
+ * @returns Validation result with the data
110
+ *
111
+ * @example
112
+ * ```typescript
113
+ * import { validateCreateDelegationWasmOutput } from "@tinycloud/sdk-core";
114
+ *
115
+ * const rawResult = wasmCreateDelegation(session, delegateDID, ...);
116
+ * const { data, issues } = validateCreateDelegationWasmOutput(rawResult);
117
+ * if (issues) {
118
+ * // Handle validation issues in development
119
+ * }
120
+ * ```
121
+ */
122
+ export function validateCreateDelegationWasmOutput(data) {
123
+ return validateWasmOutput(CreateDelegationWasmRawResultSchema, data, "createDelegation");
124
+ }
125
+ /**
126
+ * Schema for validating invoke WASM output.
127
+ *
128
+ * The invoke function returns an object with headers and body properties.
129
+ */
130
+ export const InvokeWasmResultSchema = z.object({
131
+ /** HTTP headers from the invocation response */
132
+ headers: z.record(z.string(), z.string()),
133
+ /** Request body to send */
134
+ body: z.string(),
135
+ });
136
+ /**
137
+ * Validates the output of the invoke WASM function.
138
+ *
139
+ * @param data - The raw output from WASM invoke
140
+ * @returns Validation result with the data
141
+ */
142
+ export function validateInvokeWasmOutput(data) {
143
+ return validateWasmOutput(InvokeWasmResultSchema, data, "invoke");
144
+ }
145
+ /**
146
+ * Schema for validating prepareSession WASM output.
147
+ */
148
+ export const PrepareSessionWasmResultSchema = z.object({
149
+ /** SIWE message to sign */
150
+ siweMessage: z.string(),
151
+ /** JWK for the session key */
152
+ jwk: z.object({
153
+ kty: z.string(),
154
+ crv: z.string().optional(),
155
+ x: z.string().optional(),
156
+ d: z.string().optional(),
157
+ }).passthrough(),
158
+ /** Verification method */
159
+ verificationMethod: z.string(),
160
+ });
161
+ /**
162
+ * Validates the output of the prepareSession WASM function.
163
+ *
164
+ * @param data - The raw output from WASM prepareSession
165
+ * @returns Validation result with the data
166
+ */
167
+ export function validatePrepareSessionWasmOutput(data) {
168
+ return validateWasmOutput(PrepareSessionWasmResultSchema, data, "prepareSession");
169
+ }
170
+ /**
171
+ * Schema for validating completeSessionSetup WASM output (Session type).
172
+ */
173
+ export const SessionWasmResultSchema = z.object({
174
+ /** Delegation header for authentication */
175
+ delegationHeader: z.object({
176
+ Authorization: z.string(),
177
+ }),
178
+ /** CID of the delegation */
179
+ delegationCid: z.string(),
180
+ /** JWK for the session key */
181
+ jwk: z.object({
182
+ kty: z.string(),
183
+ crv: z.string().optional(),
184
+ x: z.string().optional(),
185
+ d: z.string().optional(),
186
+ }).passthrough(),
187
+ /** Space ID */
188
+ spaceId: z.string(),
189
+ /** Verification method */
190
+ verificationMethod: z.string(),
191
+ });
192
+ /**
193
+ * Validates the output of the completeSessionSetup WASM function.
194
+ *
195
+ * @param data - The raw output from WASM completeSessionSetup
196
+ * @returns Validation result with the data
197
+ */
198
+ export function validateCompleteSessionSetupWasmOutput(data) {
199
+ return validateWasmOutput(SessionWasmResultSchema, data, "completeSessionSetup");
200
+ }
201
+ /**
202
+ * Schema for validating siweToDelegationHeaders WASM output.
203
+ */
204
+ export const SiweToDelegationHeadersWasmResultSchema = z.object({
205
+ /** Authorization header for the delegation */
206
+ Authorization: z.string(),
207
+ });
208
+ /**
209
+ * Validates the output of the siweToDelegationHeaders WASM function.
210
+ *
211
+ * @param data - The raw output from WASM siweToDelegationHeaders
212
+ * @returns Validation result with the data
213
+ */
214
+ export function validateSiweToDelegationHeadersWasmOutput(data) {
215
+ return validateWasmOutput(SiweToDelegationHeadersWasmResultSchema, data, "siweToDelegationHeaders");
216
+ }
217
+ // Re-export the strict schema for consumers who need it
218
+ export { CreateDelegationWasmResultSchema } from "./delegations/types.schema.js";
219
+ //# sourceMappingURL=wasm-validation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wasm-validation.js","sourceRoot":"","sources":["../src/wasm-validation.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB;;;GAGG;AACH,SAAS,YAAY;IACnB,sBAAsB;IACtB,IAAI,OAAO,OAAO,KAAK,WAAW,IAAI,OAAO,CAAC,GAAG,EAAE,QAAQ,KAAK,YAAY,EAAE,CAAC;QAC7E,OAAO,IAAI,CAAC;IACd,CAAC;IACD,mDAAmD;IACnD,iEAAiE;IACjE,IAAI,OAAO,MAAM,CAAC,IAAI,KAAK,WAAW,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,IAAI,KAAK,IAAI,EAAE,CAAC;QACzE,OAAO,IAAI,CAAC;IACd,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAcD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,UAAU,kBAAkB,CAChC,MAAoB,EACpB,IAAa,EACb,MAAc;IAEd,gDAAgD;IAChD,IAAI,YAAY,EAAE,EAAE,CAAC;QACnB,OAAO;YACL,IAAI,EAAE,IAAS;YACf,SAAS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,MAAM,EAAE;KAC1B,CAAC;IACF,4BAA4B;IAC5B,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE;IACzB,8BAA8B;IAC9B,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC;QACZ,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE;QACf,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;QAC1B,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;QACxB,CAAC,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;KACzB,CAAC,CAAC,WAAW,EAAE;IAChB,eAAe;IACf,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE;IACnB,0BAA0B;IAC1B,kBAAkB,EAAE,CAAC,CAAC,MAAM,EAAE;CAC/B,CAAC,CAAC;AAIH;;;;;GAKG;AACH,MAAM,UAAU,sCAAsC,CACpD,IAAa;IAEb,OAAO,kBAAkB,CAAC,uBAAuB,EAAE,IAAI,EAAE,sBAAsB,CAAC,CAAC;AACnF,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,MAAM,uCAAuC,GAAG,CAAC,CAAC,MAAM,CAAC;IAC9D,8CAA8C;IAC9C,aAAa,EAAE,CAAC,CAAC,MAAM,EAAE;CAC1B,CAAC,CAAC;AAMH;;;;;GAKG;AACH,MAAM,UAAU,yCAAyC,CACvD,IAAa;IAEb,OAAO,kBAAkB,CACvB,uCAAuC,EACvC,IAAI,EACJ,yBAAyB,CAC1B,CAAC;AACJ,CAAC;AAED,wDAAwD;AACxD,OAAO,EAAE,gCAAgC,EAAE,MAAM,+BAA+B,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Tests for WASM validation utilities.
3
+ */
4
+ export {};
5
+ //# sourceMappingURL=wasm-validation.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wasm-validation.test.d.ts","sourceRoot":"","sources":["../src/wasm-validation.test.ts"],"names":[],"mappings":"AAAA;;GAEG"}