@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,134 @@
1
+ /**
2
+ * SignStrategy types for TinyCloud authorization.
3
+ *
4
+ * These types define how sign requests are handled across different
5
+ * SDK implementations (web-sdk, node-sdk). The pattern allows for
6
+ * automatic signing, rejection, callback-based approval, or event-driven
7
+ * workflows.
8
+ *
9
+ * @packageDocumentation
10
+ */
11
+ /**
12
+ * Sign request passed to callback or event handlers.
13
+ */
14
+ export interface SignRequest {
15
+ /** Ethereum address of the signer */
16
+ address: string;
17
+ /** Chain ID for the signing context */
18
+ chainId: number;
19
+ /** Message to be signed */
20
+ message: string;
21
+ /** Type of sign operation */
22
+ type: "siwe" | "message";
23
+ }
24
+ /**
25
+ * Sign response from callback or event handlers.
26
+ */
27
+ export interface SignResponse {
28
+ /** Whether the sign request was approved */
29
+ approved: boolean;
30
+ /** The signature if approved */
31
+ signature?: string;
32
+ /** Reason for rejection if not approved */
33
+ reason?: string;
34
+ }
35
+ /**
36
+ * Callback handler type for sign requests.
37
+ */
38
+ export type SignCallback = (request: SignRequest) => Promise<SignResponse>;
39
+ /**
40
+ * Auto-sign strategy: automatically signs all requests.
41
+ *
42
+ * Use cases:
43
+ * - Trusted backend services
44
+ * - Automated scripts
45
+ * - CI/CD pipelines
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * const strategy: AutoSignStrategy = { type: 'auto-sign' };
50
+ * ```
51
+ */
52
+ export interface AutoSignStrategy {
53
+ type: "auto-sign";
54
+ }
55
+ /**
56
+ * Auto-reject strategy: rejects all sign requests.
57
+ *
58
+ * Use cases:
59
+ * - Read-only applications
60
+ * - Testing rejection flows
61
+ *
62
+ * @example
63
+ * ```typescript
64
+ * const strategy: AutoRejectStrategy = { type: 'auto-reject' };
65
+ * ```
66
+ */
67
+ export interface AutoRejectStrategy {
68
+ type: "auto-reject";
69
+ }
70
+ /**
71
+ * Callback strategy: delegates sign decisions to a callback function.
72
+ *
73
+ * Use cases:
74
+ * - CLI applications with user prompts
75
+ * - Custom approval workflows
76
+ * - Interactive sign flows
77
+ *
78
+ * @example
79
+ * ```typescript
80
+ * const strategy: CallbackStrategy = {
81
+ * type: 'callback',
82
+ * handler: async (req) => {
83
+ * const approved = await promptUser(`Sign message for ${req.address}?`);
84
+ * return { approved, signature: approved ? await signer.sign(req.message) : undefined };
85
+ * }
86
+ * };
87
+ * ```
88
+ */
89
+ export interface CallbackStrategy {
90
+ type: "callback";
91
+ handler: SignCallback;
92
+ }
93
+ /**
94
+ * Event emitter strategy: emits sign requests as events.
95
+ *
96
+ * Uses EventTarget for cross-platform compatibility (browser + Node.js).
97
+ *
98
+ * Events emitted:
99
+ * - 'sign-request': When a sign request is received
100
+ *
101
+ * Use cases:
102
+ * - Async approval workflows
103
+ * - External signing services
104
+ * - Multi-step authorization flows
105
+ *
106
+ * @example
107
+ * ```typescript
108
+ * const emitter = new EventTarget();
109
+ * const strategy: EventEmitterStrategy = { type: 'event-emitter', emitter };
110
+ *
111
+ * emitter.addEventListener('sign-request', async (event) => {
112
+ * const { request, respond } = (event as CustomEvent).detail;
113
+ * const approved = await externalApprovalService.check(request);
114
+ * respond({ approved, signature: approved ? await sign(request.message) : undefined });
115
+ * });
116
+ * ```
117
+ */
118
+ export interface EventEmitterStrategy {
119
+ type: "event-emitter";
120
+ emitter: EventTarget;
121
+ /** Timeout in milliseconds for waiting on event response (default: 60000) */
122
+ timeout?: number;
123
+ }
124
+ /**
125
+ * Sign strategy union type.
126
+ *
127
+ * Determines how sign requests are handled in UserAuthorization implementations.
128
+ */
129
+ export type SignStrategy = AutoSignStrategy | AutoRejectStrategy | CallbackStrategy | EventEmitterStrategy;
130
+ /**
131
+ * Default sign strategy is auto-sign for convenience.
132
+ */
133
+ export declare const defaultSignStrategy: SignStrategy;
134
+ //# sourceMappingURL=strategies.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strategies.d.ts","sourceRoot":"","sources":["../../src/authorization/strategies.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,qCAAqC;IACrC,OAAO,EAAE,MAAM,CAAC;IAChB,uCAAuC;IACvC,OAAO,EAAE,MAAM,CAAC;IAChB,2BAA2B;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,6BAA6B;IAC7B,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1B;AAED;;GAEG;AACH,MAAM,WAAW,YAAY;IAC3B,4CAA4C;IAC5C,QAAQ,EAAE,OAAO,CAAC;IAClB,gCAAgC;IAChC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,2CAA2C;IAC3C,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,EAAE,WAAW,KAAK,OAAO,CAAC,YAAY,CAAC,CAAC;AAE3E;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,WAAW,CAAC;CACnB;AAED;;;;;;;;;;;GAWG;AACH,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,aAAa,CAAC;CACrB;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,UAAU,CAAC;IACjB,OAAO,EAAE,YAAY,CAAC;CACvB;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,WAAW,oBAAoB;IACnC,IAAI,EAAE,eAAe,CAAC;IACtB,OAAO,EAAE,WAAW,CAAC;IACrB,6EAA6E;IAC7E,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED;;;;GAIG;AACH,MAAM,MAAM,YAAY,GACpB,gBAAgB,GAChB,kBAAkB,GAClB,gBAAgB,GAChB,oBAAoB,CAAC;AAEzB;;GAEG;AACH,eAAO,MAAM,mBAAmB,EAAE,YAAoC,CAAC"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * SignStrategy types for TinyCloud authorization.
3
+ *
4
+ * These types define how sign requests are handled across different
5
+ * SDK implementations (web-sdk, node-sdk). The pattern allows for
6
+ * automatic signing, rejection, callback-based approval, or event-driven
7
+ * workflows.
8
+ *
9
+ * @packageDocumentation
10
+ */
11
+ /**
12
+ * Default sign strategy is auto-sign for convenience.
13
+ */
14
+ export const defaultSignStrategy = { type: "auto-sign" };
15
+ //# sourceMappingURL=strategies.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strategies.js","sourceRoot":"","sources":["../../src/authorization/strategies.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAqIH;;GAEG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAiB,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC"}
@@ -0,0 +1,185 @@
1
+ /**
2
+ * Zod schemas for SignStrategy types.
3
+ *
4
+ * These schemas provide runtime validation for sign strategy configuration.
5
+ * Types are derived from schemas using z.infer<>.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ import { z } from "zod";
10
+ /**
11
+ * Schema for sign request type.
12
+ */
13
+ export declare const SignRequestTypeSchema: z.ZodEnum<["siwe", "message"]>;
14
+ export type SignRequestType = z.infer<typeof SignRequestTypeSchema>;
15
+ /**
16
+ * Schema for sign request passed to callback or event handlers.
17
+ */
18
+ export declare const SignRequestSchema: z.ZodObject<{
19
+ /** Ethereum address of the signer */
20
+ address: z.ZodString;
21
+ /** Chain ID for the signing context */
22
+ chainId: z.ZodNumber;
23
+ /** Message to be signed */
24
+ message: z.ZodString;
25
+ /** Type of sign operation */
26
+ type: z.ZodEnum<["siwe", "message"]>;
27
+ }, "strip", z.ZodTypeAny, {
28
+ message: string;
29
+ type: "message" | "siwe";
30
+ address: string;
31
+ chainId: number;
32
+ }, {
33
+ message: string;
34
+ type: "message" | "siwe";
35
+ address: string;
36
+ chainId: number;
37
+ }>;
38
+ export type SignRequest = z.infer<typeof SignRequestSchema>;
39
+ /**
40
+ * Schema for sign response from callback or event handlers.
41
+ */
42
+ export declare const SignResponseSchema: z.ZodObject<{
43
+ /** Whether the sign request was approved */
44
+ approved: z.ZodBoolean;
45
+ /** The signature if approved */
46
+ signature: z.ZodOptional<z.ZodString>;
47
+ /** Reason for rejection if not approved */
48
+ reason: z.ZodOptional<z.ZodString>;
49
+ }, "strip", z.ZodTypeAny, {
50
+ approved: boolean;
51
+ signature?: string | undefined;
52
+ reason?: string | undefined;
53
+ }, {
54
+ approved: boolean;
55
+ signature?: string | undefined;
56
+ reason?: string | undefined;
57
+ }>;
58
+ export type SignResponse = z.infer<typeof SignResponseSchema>;
59
+ /**
60
+ * Callback handler type for sign requests.
61
+ * Note: z.function().args() not available in Zod 3, so we use function type annotation.
62
+ */
63
+ export type SignCallback = (request: SignRequest) => Promise<SignResponse>;
64
+ /**
65
+ * Schema for callback handler type (validated as function shape only).
66
+ */
67
+ export declare const SignCallbackSchema: z.ZodEffects<z.ZodUnknown, SignCallback, unknown>;
68
+ /**
69
+ * Schema for auto-sign strategy: automatically signs all requests.
70
+ */
71
+ export declare const AutoSignStrategySchema: z.ZodObject<{
72
+ type: z.ZodLiteral<"auto-sign">;
73
+ }, "strip", z.ZodTypeAny, {
74
+ type: "auto-sign";
75
+ }, {
76
+ type: "auto-sign";
77
+ }>;
78
+ export type AutoSignStrategy = z.infer<typeof AutoSignStrategySchema>;
79
+ /**
80
+ * Schema for auto-reject strategy: rejects all sign requests.
81
+ */
82
+ export declare const AutoRejectStrategySchema: z.ZodObject<{
83
+ type: z.ZodLiteral<"auto-reject">;
84
+ }, "strip", z.ZodTypeAny, {
85
+ type: "auto-reject";
86
+ }, {
87
+ type: "auto-reject";
88
+ }>;
89
+ export type AutoRejectStrategy = z.infer<typeof AutoRejectStrategySchema>;
90
+ /**
91
+ * Schema for callback strategy: delegates sign decisions to a callback function.
92
+ */
93
+ export declare const CallbackStrategySchema: z.ZodObject<{
94
+ type: z.ZodLiteral<"callback">;
95
+ /** Callback function that handles sign requests */
96
+ handler: z.ZodEffects<z.ZodUnknown, SignCallback, unknown>;
97
+ }, "strip", z.ZodTypeAny, {
98
+ type: "callback";
99
+ handler: SignCallback;
100
+ }, {
101
+ type: "callback";
102
+ handler?: unknown;
103
+ }>;
104
+ export type CallbackStrategy = z.infer<typeof CallbackStrategySchema>;
105
+ /**
106
+ * Schema for event emitter strategy: emits sign requests as events.
107
+ */
108
+ export declare const EventEmitterStrategySchema: z.ZodObject<{
109
+ type: z.ZodLiteral<"event-emitter">;
110
+ /** EventTarget for emitting sign-request events */
111
+ emitter: z.ZodEffects<z.ZodUnknown, EventTarget, unknown>;
112
+ /** Timeout in milliseconds for waiting on event response (default: 60000) */
113
+ timeout: z.ZodOptional<z.ZodNumber>;
114
+ }, "strip", z.ZodTypeAny, {
115
+ type: "event-emitter";
116
+ emitter: EventTarget;
117
+ timeout?: number | undefined;
118
+ }, {
119
+ type: "event-emitter";
120
+ emitter?: unknown;
121
+ timeout?: number | undefined;
122
+ }>;
123
+ export type EventEmitterStrategy = z.infer<typeof EventEmitterStrategySchema>;
124
+ /**
125
+ * Schema for sign strategy union type.
126
+ *
127
+ * Uses discriminatedUnion for efficient parsing based on the 'type' field.
128
+ */
129
+ export declare const SignStrategySchema: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
130
+ type: z.ZodLiteral<"auto-sign">;
131
+ }, "strip", z.ZodTypeAny, {
132
+ type: "auto-sign";
133
+ }, {
134
+ type: "auto-sign";
135
+ }>, z.ZodObject<{
136
+ type: z.ZodLiteral<"auto-reject">;
137
+ }, "strip", z.ZodTypeAny, {
138
+ type: "auto-reject";
139
+ }, {
140
+ type: "auto-reject";
141
+ }>, z.ZodObject<{
142
+ type: z.ZodLiteral<"callback">;
143
+ /** Callback function that handles sign requests */
144
+ handler: z.ZodEffects<z.ZodUnknown, SignCallback, unknown>;
145
+ }, "strip", z.ZodTypeAny, {
146
+ type: "callback";
147
+ handler: SignCallback;
148
+ }, {
149
+ type: "callback";
150
+ handler?: unknown;
151
+ }>, z.ZodObject<{
152
+ type: z.ZodLiteral<"event-emitter">;
153
+ /** EventTarget for emitting sign-request events */
154
+ emitter: z.ZodEffects<z.ZodUnknown, EventTarget, unknown>;
155
+ /** Timeout in milliseconds for waiting on event response (default: 60000) */
156
+ timeout: z.ZodOptional<z.ZodNumber>;
157
+ }, "strip", z.ZodTypeAny, {
158
+ type: "event-emitter";
159
+ emitter: EventTarget;
160
+ timeout?: number | undefined;
161
+ }, {
162
+ type: "event-emitter";
163
+ emitter?: unknown;
164
+ timeout?: number | undefined;
165
+ }>]>;
166
+ export type SignStrategy = z.infer<typeof SignStrategySchema>;
167
+ /**
168
+ * Default sign strategy is auto-sign for convenience.
169
+ */
170
+ export declare const defaultSignStrategy: SignStrategy;
171
+ import type { Result } from "../delegations/types.schema";
172
+ import type { ValidationError } from "../storage.schema";
173
+ /**
174
+ * Validates a SignStrategy object and returns a Result.
175
+ */
176
+ export declare function validateSignStrategy(data: unknown): Result<SignStrategy, ValidationError>;
177
+ /**
178
+ * Validates a SignRequest object and returns a Result.
179
+ */
180
+ export declare function validateSignRequest(data: unknown): Result<SignRequest, ValidationError>;
181
+ /**
182
+ * Validates a SignResponse object and returns a Result.
183
+ */
184
+ export declare function validateSignResponse(data: unknown): Result<SignResponse, ValidationError>;
185
+ //# sourceMappingURL=strategies.schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strategies.schema.d.ts","sourceRoot":"","sources":["../../src/authorization/strateg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C;AAEtE;;GAEG;AACH,eAAO,MAAM,0BAA0B;;IAErC,mDAAmD;;IAMnD,6EAA6E;;;;;;;;;;EAE7E,CAAC;AAEH,MAAM,MAAM,oBAAoB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,0BAA0B,CAAC,CAAC;AAE9E;;;;GAIG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;;;;;;;IA/B7B,mDAAmD;;;;;;;;;;IAcnD,mDAAmD;;IAMnD,6EAA6E;;;;;;;;;;IAgB7E,CAAC;AAEH,MAAM,MAAM,YAAY,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAE9D;;GAEG;AACH,eAAO,MAAM,mBAAmB,EAAE,YAAoC,CAAC;AAMvE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEzD;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,OAAO,GACZ,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,CAcvC;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,OAAO,GACZ,MAAM,CAAC,WAAW,EAAE,eAAe,CAAC,CActC;AAED;;GAEG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,OAAO,GACZ,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,CAcvC"}
@@ -0,0 +1,147 @@
1
+ /**
2
+ * Zod schemas for SignStrategy types.
3
+ *
4
+ * These schemas provide runtime validation for sign strategy configuration.
5
+ * Types are derived from schemas using z.infer<>.
6
+ *
7
+ * @packageDocumentation
8
+ */
9
+ import { z } from "zod";
10
+ // =============================================================================
11
+ // Sign Request/Response Schemas
12
+ // =============================================================================
13
+ /**
14
+ * Schema for sign request type.
15
+ */
16
+ export const SignRequestTypeSchema = z.enum(["siwe", "message"]);
17
+ /**
18
+ * Schema for sign request passed to callback or event handlers.
19
+ */
20
+ export const SignRequestSchema = z.object({
21
+ /** Ethereum address of the signer */
22
+ address: z.string(),
23
+ /** Chain ID for the signing context */
24
+ chainId: z.number(),
25
+ /** Message to be signed */
26
+ message: z.string(),
27
+ /** Type of sign operation */
28
+ type: SignRequestTypeSchema,
29
+ });
30
+ /**
31
+ * Schema for sign response from callback or event handlers.
32
+ */
33
+ export const SignResponseSchema = z.object({
34
+ /** Whether the sign request was approved */
35
+ approved: z.boolean(),
36
+ /** The signature if approved */
37
+ signature: z.string().optional(),
38
+ /** Reason for rejection if not approved */
39
+ reason: z.string().optional(),
40
+ });
41
+ /**
42
+ * Schema for callback handler type (validated as function shape only).
43
+ */
44
+ export const SignCallbackSchema = z.unknown().refine((val) => typeof val === "function", { message: "Expected a callback function" });
45
+ // =============================================================================
46
+ // Strategy Schemas
47
+ // =============================================================================
48
+ /**
49
+ * Schema for auto-sign strategy: automatically signs all requests.
50
+ */
51
+ export const AutoSignStrategySchema = z.object({
52
+ type: z.literal("auto-sign"),
53
+ });
54
+ /**
55
+ * Schema for auto-reject strategy: rejects all sign requests.
56
+ */
57
+ export const AutoRejectStrategySchema = z.object({
58
+ type: z.literal("auto-reject"),
59
+ });
60
+ /**
61
+ * Schema for callback strategy: delegates sign decisions to a callback function.
62
+ */
63
+ export const CallbackStrategySchema = z.object({
64
+ type: z.literal("callback"),
65
+ /** Callback function that handles sign requests */
66
+ handler: z.unknown().refine((val) => typeof val === "function", { message: "Expected a callback function" }),
67
+ });
68
+ /**
69
+ * Schema for event emitter strategy: emits sign requests as events.
70
+ */
71
+ export const EventEmitterStrategySchema = z.object({
72
+ type: z.literal("event-emitter"),
73
+ /** EventTarget for emitting sign-request events */
74
+ emitter: z.unknown().refine((val) => val !== null && typeof val === "object" && "addEventListener" in val, { message: "Expected an EventTarget" }),
75
+ /** Timeout in milliseconds for waiting on event response (default: 60000) */
76
+ timeout: z.number().optional(),
77
+ });
78
+ /**
79
+ * Schema for sign strategy union type.
80
+ *
81
+ * Uses discriminatedUnion for efficient parsing based on the 'type' field.
82
+ */
83
+ export const SignStrategySchema = z.discriminatedUnion("type", [
84
+ AutoSignStrategySchema,
85
+ AutoRejectStrategySchema,
86
+ CallbackStrategySchema,
87
+ EventEmitterStrategySchema,
88
+ ]);
89
+ /**
90
+ * Default sign strategy is auto-sign for convenience.
91
+ */
92
+ export const defaultSignStrategy = { type: "auto-sign" };
93
+ /**
94
+ * Validates a SignStrategy object and returns a Result.
95
+ */
96
+ export function validateSignStrategy(data) {
97
+ const result = SignStrategySchema.safeParse(data);
98
+ if (!result.success) {
99
+ return {
100
+ ok: false,
101
+ error: {
102
+ code: "VALIDATION_ERROR",
103
+ message: result.error.message,
104
+ service: "authorization",
105
+ meta: { issues: result.error.issues },
106
+ },
107
+ };
108
+ }
109
+ return { ok: true, data: result.data };
110
+ }
111
+ /**
112
+ * Validates a SignRequest object and returns a Result.
113
+ */
114
+ export function validateSignRequest(data) {
115
+ const result = SignRequestSchema.safeParse(data);
116
+ if (!result.success) {
117
+ return {
118
+ ok: false,
119
+ error: {
120
+ code: "VALIDATION_ERROR",
121
+ message: result.error.message,
122
+ service: "authorization",
123
+ meta: { issues: result.error.issues },
124
+ },
125
+ };
126
+ }
127
+ return { ok: true, data: result.data };
128
+ }
129
+ /**
130
+ * Validates a SignResponse object and returns a Result.
131
+ */
132
+ export function validateSignResponse(data) {
133
+ const result = SignResponseSchema.safeParse(data);
134
+ if (!result.success) {
135
+ return {
136
+ ok: false,
137
+ error: {
138
+ code: "VALIDATION_ERROR",
139
+ message: result.error.message,
140
+ service: "authorization",
141
+ meta: { issues: result.error.issues },
142
+ },
143
+ };
144
+ }
145
+ return { ok: true, data: result.data };
146
+ }
147
+ //# sourceMappingURL=strategies.schema.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strategies.schema.js","sourceRoot":"","sources":["../../src/authorization/strategies.schema.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,CAAC,EAAE,MAA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AC7B,OAAO,EAAE,eAAe;gBACxB,IAAI,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,KAAK,CAAC,MAAM,EAAE;aACtC;SACF,CAAC;IACJ,CAAC;IACD,OAAO,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,IAAI,EAAE,CAAC;AACzC,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Tests for SignStrategy schemas.
3
+ */
4
+ export {};
5
+ //# sourceMappingURL=strategies.schema.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"strategies.schema.test.d.ts","sourceRoot":"","sources":["../../src/authorization/strategies.schema.test.ts"],"names":[],"mappings":"AAAA;;GAEG"}