@snaha/swarm-id 0.0.1

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 (223) hide show
  1. package/README.md +431 -0
  2. package/dist/chunk/bmt.d.ts +17 -0
  3. package/dist/chunk/bmt.d.ts.map +1 -0
  4. package/dist/chunk/cac.d.ts +18 -0
  5. package/dist/chunk/cac.d.ts.map +1 -0
  6. package/dist/chunk/constants.d.ts +10 -0
  7. package/dist/chunk/constants.d.ts.map +1 -0
  8. package/dist/chunk/encrypted-cac.d.ts +48 -0
  9. package/dist/chunk/encrypted-cac.d.ts.map +1 -0
  10. package/dist/chunk/encryption.d.ts +86 -0
  11. package/dist/chunk/encryption.d.ts.map +1 -0
  12. package/dist/chunk/index.d.ts +6 -0
  13. package/dist/chunk/index.d.ts.map +1 -0
  14. package/dist/index.d.ts +46 -0
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/proxy/act/act.d.ts +78 -0
  17. package/dist/proxy/act/act.d.ts.map +1 -0
  18. package/dist/proxy/act/crypto.d.ts +44 -0
  19. package/dist/proxy/act/crypto.d.ts.map +1 -0
  20. package/dist/proxy/act/grantee-list.d.ts +82 -0
  21. package/dist/proxy/act/grantee-list.d.ts.map +1 -0
  22. package/dist/proxy/act/history.d.ts +183 -0
  23. package/dist/proxy/act/history.d.ts.map +1 -0
  24. package/dist/proxy/act/index.d.ts +104 -0
  25. package/dist/proxy/act/index.d.ts.map +1 -0
  26. package/dist/proxy/chunking-encrypted.d.ts +14 -0
  27. package/dist/proxy/chunking-encrypted.d.ts.map +1 -0
  28. package/dist/proxy/chunking.d.ts +15 -0
  29. package/dist/proxy/chunking.d.ts.map +1 -0
  30. package/dist/proxy/download-data.d.ts +16 -0
  31. package/dist/proxy/download-data.d.ts.map +1 -0
  32. package/dist/proxy/feed-manifest.d.ts +62 -0
  33. package/dist/proxy/feed-manifest.d.ts.map +1 -0
  34. package/dist/proxy/feeds/epochs/async-finder.d.ts +77 -0
  35. package/dist/proxy/feeds/epochs/async-finder.d.ts.map +1 -0
  36. package/dist/proxy/feeds/epochs/epoch.d.ts +88 -0
  37. package/dist/proxy/feeds/epochs/epoch.d.ts.map +1 -0
  38. package/dist/proxy/feeds/epochs/finder.d.ts +67 -0
  39. package/dist/proxy/feeds/epochs/finder.d.ts.map +1 -0
  40. package/dist/proxy/feeds/epochs/index.d.ts +35 -0
  41. package/dist/proxy/feeds/epochs/index.d.ts.map +1 -0
  42. package/dist/proxy/feeds/epochs/test-utils.d.ts +93 -0
  43. package/dist/proxy/feeds/epochs/test-utils.d.ts.map +1 -0
  44. package/dist/proxy/feeds/epochs/types.d.ts +109 -0
  45. package/dist/proxy/feeds/epochs/types.d.ts.map +1 -0
  46. package/dist/proxy/feeds/epochs/updater.d.ts +68 -0
  47. package/dist/proxy/feeds/epochs/updater.d.ts.map +1 -0
  48. package/dist/proxy/feeds/epochs/utils.d.ts +22 -0
  49. package/dist/proxy/feeds/epochs/utils.d.ts.map +1 -0
  50. package/dist/proxy/feeds/index.d.ts +5 -0
  51. package/dist/proxy/feeds/index.d.ts.map +1 -0
  52. package/dist/proxy/feeds/sequence/async-finder.d.ts +14 -0
  53. package/dist/proxy/feeds/sequence/async-finder.d.ts.map +1 -0
  54. package/dist/proxy/feeds/sequence/finder.d.ts +17 -0
  55. package/dist/proxy/feeds/sequence/finder.d.ts.map +1 -0
  56. package/dist/proxy/feeds/sequence/index.d.ts +23 -0
  57. package/dist/proxy/feeds/sequence/index.d.ts.map +1 -0
  58. package/dist/proxy/feeds/sequence/types.d.ts +80 -0
  59. package/dist/proxy/feeds/sequence/types.d.ts.map +1 -0
  60. package/dist/proxy/feeds/sequence/updater.d.ts +26 -0
  61. package/dist/proxy/feeds/sequence/updater.d.ts.map +1 -0
  62. package/dist/proxy/index.d.ts +6 -0
  63. package/dist/proxy/index.d.ts.map +1 -0
  64. package/dist/proxy/manifest-builder.d.ts +183 -0
  65. package/dist/proxy/manifest-builder.d.ts.map +1 -0
  66. package/dist/proxy/mantaray-encrypted.d.ts +27 -0
  67. package/dist/proxy/mantaray-encrypted.d.ts.map +1 -0
  68. package/dist/proxy/mantaray.d.ts +26 -0
  69. package/dist/proxy/mantaray.d.ts.map +1 -0
  70. package/dist/proxy/types.d.ts +29 -0
  71. package/dist/proxy/types.d.ts.map +1 -0
  72. package/dist/proxy/upload-data.d.ts +17 -0
  73. package/dist/proxy/upload-data.d.ts.map +1 -0
  74. package/dist/proxy/upload-encrypted-data.d.ts +103 -0
  75. package/dist/proxy/upload-encrypted-data.d.ts.map +1 -0
  76. package/dist/schemas.d.ts +240 -0
  77. package/dist/schemas.d.ts.map +1 -0
  78. package/dist/storage/debounced-uploader.d.ts +62 -0
  79. package/dist/storage/debounced-uploader.d.ts.map +1 -0
  80. package/dist/storage/utilization-store.d.ts +108 -0
  81. package/dist/storage/utilization-store.d.ts.map +1 -0
  82. package/dist/swarm-id-auth.d.ts +74 -0
  83. package/dist/swarm-id-auth.d.ts.map +1 -0
  84. package/dist/swarm-id-auth.js +2 -0
  85. package/dist/swarm-id-auth.js.map +1 -0
  86. package/dist/swarm-id-client.d.ts +878 -0
  87. package/dist/swarm-id-client.d.ts.map +1 -0
  88. package/dist/swarm-id-client.js +2 -0
  89. package/dist/swarm-id-client.js.map +1 -0
  90. package/dist/swarm-id-proxy.d.ts +236 -0
  91. package/dist/swarm-id-proxy.d.ts.map +1 -0
  92. package/dist/swarm-id-proxy.js +2 -0
  93. package/dist/swarm-id-proxy.js.map +1 -0
  94. package/dist/swarm-id.esm.js +2 -0
  95. package/dist/swarm-id.esm.js.map +1 -0
  96. package/dist/swarm-id.umd.js +2 -0
  97. package/dist/swarm-id.umd.js.map +1 -0
  98. package/dist/sync/index.d.ts +9 -0
  99. package/dist/sync/index.d.ts.map +1 -0
  100. package/dist/sync/key-derivation.d.ts +25 -0
  101. package/dist/sync/key-derivation.d.ts.map +1 -0
  102. package/dist/sync/restore-account.d.ts +28 -0
  103. package/dist/sync/restore-account.d.ts.map +1 -0
  104. package/dist/sync/serialization.d.ts +16 -0
  105. package/dist/sync/serialization.d.ts.map +1 -0
  106. package/dist/sync/store-interfaces.d.ts +53 -0
  107. package/dist/sync/store-interfaces.d.ts.map +1 -0
  108. package/dist/sync/sync-account.d.ts +44 -0
  109. package/dist/sync/sync-account.d.ts.map +1 -0
  110. package/dist/sync/types.d.ts +13 -0
  111. package/dist/sync/types.d.ts.map +1 -0
  112. package/dist/test-fixtures.d.ts +17 -0
  113. package/dist/test-fixtures.d.ts.map +1 -0
  114. package/dist/types-BD_VkNn0.js +2 -0
  115. package/dist/types-BD_VkNn0.js.map +1 -0
  116. package/dist/types-lJCaT-50.js +2 -0
  117. package/dist/types-lJCaT-50.js.map +1 -0
  118. package/dist/types.d.ts +2157 -0
  119. package/dist/types.d.ts.map +1 -0
  120. package/dist/utils/account-payload.d.ts +94 -0
  121. package/dist/utils/account-payload.d.ts.map +1 -0
  122. package/dist/utils/account-state-snapshot.d.ts +38 -0
  123. package/dist/utils/account-state-snapshot.d.ts.map +1 -0
  124. package/dist/utils/backup-encryption.d.ts +127 -0
  125. package/dist/utils/backup-encryption.d.ts.map +1 -0
  126. package/dist/utils/batch-utilization.d.ts +432 -0
  127. package/dist/utils/batch-utilization.d.ts.map +1 -0
  128. package/dist/utils/constants.d.ts +11 -0
  129. package/dist/utils/constants.d.ts.map +1 -0
  130. package/dist/utils/hex.d.ts +17 -0
  131. package/dist/utils/hex.d.ts.map +1 -0
  132. package/dist/utils/key-derivation.d.ts +92 -0
  133. package/dist/utils/key-derivation.d.ts.map +1 -0
  134. package/dist/utils/storage-managers.d.ts +65 -0
  135. package/dist/utils/storage-managers.d.ts.map +1 -0
  136. package/dist/utils/swarm-id-export.d.ts +24 -0
  137. package/dist/utils/swarm-id-export.d.ts.map +1 -0
  138. package/dist/utils/ttl.d.ts +49 -0
  139. package/dist/utils/ttl.d.ts.map +1 -0
  140. package/dist/utils/url.d.ts +41 -0
  141. package/dist/utils/url.d.ts.map +1 -0
  142. package/dist/utils/versioned-storage.d.ts +131 -0
  143. package/dist/utils/versioned-storage.d.ts.map +1 -0
  144. package/package.json +78 -0
  145. package/src/chunk/bmt.test.ts +217 -0
  146. package/src/chunk/bmt.ts +57 -0
  147. package/src/chunk/cac.test.ts +214 -0
  148. package/src/chunk/cac.ts +65 -0
  149. package/src/chunk/constants.ts +18 -0
  150. package/src/chunk/encrypted-cac.test.ts +385 -0
  151. package/src/chunk/encrypted-cac.ts +131 -0
  152. package/src/chunk/encryption.test.ts +352 -0
  153. package/src/chunk/encryption.ts +300 -0
  154. package/src/chunk/index.ts +47 -0
  155. package/src/index.ts +430 -0
  156. package/src/proxy/act/act.test.ts +278 -0
  157. package/src/proxy/act/act.ts +158 -0
  158. package/src/proxy/act/bee-compat.test.ts +948 -0
  159. package/src/proxy/act/crypto.test.ts +436 -0
  160. package/src/proxy/act/crypto.ts +376 -0
  161. package/src/proxy/act/grantee-list.test.ts +393 -0
  162. package/src/proxy/act/grantee-list.ts +239 -0
  163. package/src/proxy/act/history.test.ts +360 -0
  164. package/src/proxy/act/history.ts +413 -0
  165. package/src/proxy/act/index.test.ts +748 -0
  166. package/src/proxy/act/index.ts +853 -0
  167. package/src/proxy/chunking-encrypted.ts +95 -0
  168. package/src/proxy/chunking.ts +65 -0
  169. package/src/proxy/download-data.ts +448 -0
  170. package/src/proxy/feed-manifest.ts +174 -0
  171. package/src/proxy/feeds/epochs/async-finder.ts +372 -0
  172. package/src/proxy/feeds/epochs/epoch.test.ts +249 -0
  173. package/src/proxy/feeds/epochs/epoch.ts +181 -0
  174. package/src/proxy/feeds/epochs/finder.ts +282 -0
  175. package/src/proxy/feeds/epochs/index.ts +73 -0
  176. package/src/proxy/feeds/epochs/integration.test.ts +1336 -0
  177. package/src/proxy/feeds/epochs/test-utils.ts +274 -0
  178. package/src/proxy/feeds/epochs/types.ts +128 -0
  179. package/src/proxy/feeds/epochs/updater.ts +192 -0
  180. package/src/proxy/feeds/epochs/utils.ts +62 -0
  181. package/src/proxy/feeds/index.ts +5 -0
  182. package/src/proxy/feeds/sequence/async-finder.ts +31 -0
  183. package/src/proxy/feeds/sequence/finder.ts +73 -0
  184. package/src/proxy/feeds/sequence/index.ts +54 -0
  185. package/src/proxy/feeds/sequence/integration.test.ts +966 -0
  186. package/src/proxy/feeds/sequence/types.ts +103 -0
  187. package/src/proxy/feeds/sequence/updater.ts +71 -0
  188. package/src/proxy/index.ts +5 -0
  189. package/src/proxy/manifest-builder.test.ts +427 -0
  190. package/src/proxy/manifest-builder.ts +679 -0
  191. package/src/proxy/mantaray-encrypted.ts +78 -0
  192. package/src/proxy/mantaray.ts +104 -0
  193. package/src/proxy/types.ts +32 -0
  194. package/src/proxy/upload-data.ts +189 -0
  195. package/src/proxy/upload-encrypted-data.ts +658 -0
  196. package/src/schemas.ts +299 -0
  197. package/src/storage/debounced-uploader.ts +192 -0
  198. package/src/storage/utilization-store.ts +397 -0
  199. package/src/swarm-id-client.test.ts +99 -0
  200. package/src/swarm-id-client.ts +3095 -0
  201. package/src/swarm-id-proxy.ts +3891 -0
  202. package/src/sync/index.ts +28 -0
  203. package/src/sync/restore-account.ts +90 -0
  204. package/src/sync/serialization.ts +39 -0
  205. package/src/sync/store-interfaces.ts +62 -0
  206. package/src/sync/sync-account.test.ts +302 -0
  207. package/src/sync/sync-account.ts +396 -0
  208. package/src/sync/types.ts +11 -0
  209. package/src/test-fixtures.ts +109 -0
  210. package/src/types.ts +1651 -0
  211. package/src/utils/account-state-snapshot.test.ts +595 -0
  212. package/src/utils/account-state-snapshot.ts +94 -0
  213. package/src/utils/backup-encryption.test.ts +442 -0
  214. package/src/utils/backup-encryption.ts +352 -0
  215. package/src/utils/batch-utilization.ts +1309 -0
  216. package/src/utils/constants.ts +20 -0
  217. package/src/utils/hex.ts +27 -0
  218. package/src/utils/key-derivation.ts +197 -0
  219. package/src/utils/storage-managers.ts +365 -0
  220. package/src/utils/ttl.ts +129 -0
  221. package/src/utils/url.test.ts +136 -0
  222. package/src/utils/url.ts +71 -0
  223. package/src/utils/versioned-storage.ts +323 -0
package/src/types.ts ADDED
@@ -0,0 +1,1651 @@
1
+ import { z } from "zod"
2
+ import type {
3
+ PrivateKey as BeePrivateKey,
4
+ Topic as BeeTopic,
5
+ } from "@ethersphere/bee-js"
6
+ import {
7
+ NetworkSettingsSchemaV1,
8
+ ReferenceSchema,
9
+ BatchIdSchema,
10
+ AddressSchema,
11
+ PrivateKeySchema,
12
+ EncryptionKeySchema,
13
+ IdentifierSchema,
14
+ SignatureSchema,
15
+ TimestampSchema,
16
+ FeedIndexSchema,
17
+ } from "./schemas"
18
+ import type {
19
+ Reference,
20
+ Address,
21
+ Identifier,
22
+ Signature,
23
+ Timestamp,
24
+ FeedIndex,
25
+ } from "./schemas"
26
+ export type {
27
+ Reference,
28
+ BatchId,
29
+ Address,
30
+ PrivateKey,
31
+ Identifier,
32
+ Signature,
33
+ Timestamp,
34
+ FeedIndex,
35
+ } from "./schemas"
36
+
37
+ // ============================================================================
38
+ // Constants
39
+ // ============================================================================
40
+
41
+ export const SWARM_SECRET_PREFIX = "swarm-secret-"
42
+
43
+ // Storage keys for versioned storage managers
44
+ export const STORAGE_KEY_ACCOUNTS = "swarm-id-accounts"
45
+ export const STORAGE_KEY_IDENTITIES = "swarm-id-identities"
46
+ export const STORAGE_KEY_CONNECTED_APPS = "swarm-id-connected-apps"
47
+ export const STORAGE_KEY_POSTAGE_STAMPS = "swarm-id-postage-stamps"
48
+ export const STORAGE_KEY_NETWORK_SETTINGS = "swarm-id-network-settings"
49
+ export const STORAGE_CHALLENGE_KEY = "swarm-storage-challenge"
50
+
51
+ // ============================================================================
52
+ // Upload/Download Options
53
+ // ============================================================================
54
+
55
+ const UploadOptionsObjectSchema = z.object({
56
+ pin: z.boolean().optional(),
57
+ encrypt: z.boolean().optional(),
58
+ encryptManifest: z.boolean().optional(),
59
+ tag: z.number().optional(),
60
+ deferred: z.boolean().optional(),
61
+ redundancyLevel: z.number().min(0).max(4).optional(),
62
+ })
63
+
64
+ export const UploadOptionsSchema = UploadOptionsObjectSchema.optional()
65
+
66
+ export const ActUploadOptionsSchema = UploadOptionsObjectSchema.extend({
67
+ beeCompatible: z.boolean().optional(),
68
+ }).optional()
69
+
70
+ export const RequestOptionsSchema = z
71
+ .object({
72
+ timeout: z.number().optional(),
73
+ headers: z.record(z.string(), z.string()).optional(),
74
+ endlesslyRetry: z.boolean().optional(),
75
+ })
76
+ .optional()
77
+
78
+ export const DownloadOptionsSchema = z
79
+ .object({
80
+ redundancyStrategy: z
81
+ .union([z.literal(0), z.literal(1), z.literal(2), z.literal(3)])
82
+ .optional(),
83
+ fallback: z.boolean().optional(),
84
+ timeoutMs: z.number().optional(),
85
+ actPublisher: z.union([z.instanceof(Uint8Array), z.string()]),
86
+ actHistoryAddress: z.union([z.instanceof(Uint8Array), z.string()]),
87
+ actTimestamp: z.union([z.number(), z.string()]),
88
+ })
89
+ .optional()
90
+
91
+ export interface UploadProgress {
92
+ total: number
93
+ processed: number
94
+ }
95
+
96
+ export interface UploadOptions {
97
+ pin?: boolean
98
+ encrypt?: boolean
99
+ encryptManifest?: boolean
100
+ tag?: number
101
+ deferred?: boolean
102
+ redundancyLevel?: number
103
+ onProgress?: (progress: UploadProgress) => void
104
+ }
105
+
106
+ export type RequestOptions = z.infer<typeof RequestOptionsSchema>
107
+ export type DownloadOptions = z.infer<typeof DownloadOptionsSchema>
108
+ export interface ActUploadOptions extends UploadOptions {
109
+ beeCompatible?: boolean
110
+ }
111
+
112
+ // ============================================================================
113
+ // Upload/Download Results
114
+ // ============================================================================
115
+
116
+ export const UploadResultSchema = z.object({
117
+ reference: ReferenceSchema,
118
+ tagUid: z.number().optional(),
119
+ })
120
+
121
+ export const SocUploadResultSchema = UploadResultSchema.extend({
122
+ encryptionKey: z.string(),
123
+ owner: AddressSchema,
124
+ })
125
+
126
+ export const SocRawUploadResultSchema = UploadResultSchema.extend({
127
+ encryptionKey: z.string().optional(),
128
+ owner: AddressSchema,
129
+ })
130
+
131
+ export const FileDataSchema = z.object({
132
+ name: z.string(),
133
+ data: z.instanceof(Uint8Array),
134
+ })
135
+
136
+ export const PostageBatchSchema = z.object({
137
+ batchID: BatchIdSchema,
138
+ utilization: z.number(),
139
+ usable: z.boolean(),
140
+ label: z.string(),
141
+ depth: z.number(),
142
+ amount: z.string(),
143
+ bucketDepth: z.number(),
144
+ blockNumber: z.number(),
145
+ immutableFlag: z.boolean(),
146
+ exists: z.boolean(),
147
+ batchTTL: z.number().optional(),
148
+ })
149
+
150
+ export type UploadResult = z.infer<typeof UploadResultSchema>
151
+ export type SocUploadResult = z.infer<typeof SocUploadResultSchema>
152
+ export type SocRawUploadResult = z.infer<typeof SocRawUploadResultSchema>
153
+ export type FileData = z.infer<typeof FileDataSchema>
154
+ export type PostageBatch = z.infer<typeof PostageBatchSchema>
155
+
156
+ // ============================================================================
157
+ // SOC Types
158
+ // ============================================================================
159
+
160
+ export interface SingleOwnerChunk {
161
+ data: Uint8Array
162
+ identifier: Identifier
163
+ signature: Signature
164
+ span: number
165
+ payload: Uint8Array
166
+ address: Reference
167
+ owner: Address
168
+ }
169
+
170
+ /**
171
+ * Interface for downloading single owner chunks (SOC).
172
+ *
173
+ * `download` expects an encryption key and returns decrypted content.
174
+ * `rawDownload` returns unencrypted SOC data.
175
+ */
176
+ export interface SOCReader {
177
+ /**
178
+ * Resolve SOC owner address. For SOCWriter without signer, this may be
179
+ * resolved via the proxy.
180
+ */
181
+ getOwner: () => Promise<Address>
182
+ /**
183
+ * Download an unencrypted SOC by identifier.
184
+ *
185
+ * @param identifier - SOC identifier (32-byte value)
186
+ */
187
+ rawDownload: (
188
+ identifier: Identifier | Uint8Array | string,
189
+ encryptionKey?: Uint8Array | string,
190
+ ) => Promise<SingleOwnerChunk>
191
+ /**
192
+ * Download and decrypt an encrypted SOC by identifier.
193
+ *
194
+ * @param identifier - SOC identifier (32-byte value)
195
+ * @param encryptionKey - 32-byte encryption key returned by upload
196
+ */
197
+ download: (
198
+ identifier: Identifier | Uint8Array | string,
199
+ encryptionKey: Uint8Array | string,
200
+ ) => Promise<SingleOwnerChunk>
201
+ }
202
+
203
+ /**
204
+ * Interface for downloading and uploading single owner chunks (SOC).
205
+ *
206
+ * `upload` creates an encrypted SOC by default.
207
+ * `rawUpload` creates an unencrypted SOC.
208
+ */
209
+ export interface SOCWriter extends SOCReader {
210
+ /**
211
+ * Upload an encrypted SOC.
212
+ *
213
+ * @param identifier - SOC identifier (32-byte value)
214
+ * @param data - SOC payload data (1-4096 bytes)
215
+ * @param options - Optional upload configuration
216
+ */
217
+ upload: (
218
+ identifier: Identifier | Uint8Array | string,
219
+ data: Uint8Array,
220
+ options?: UploadOptions,
221
+ ) => Promise<SocUploadResult>
222
+ /**
223
+ * Upload an unencrypted SOC.
224
+ *
225
+ * @param identifier - SOC identifier (32-byte value)
226
+ * @param data - SOC payload data (1-4096 bytes)
227
+ * @param options - Optional upload configuration
228
+ */
229
+ rawUpload: (
230
+ identifier: Identifier | Uint8Array | string,
231
+ data: Uint8Array,
232
+ options?: UploadOptions,
233
+ ) => Promise<SocRawUploadResult>
234
+ }
235
+
236
+ // ============================================================================
237
+ // Feed Types
238
+ // ============================================================================
239
+
240
+ /**
241
+ * Options for epoch feed reader creation.
242
+ */
243
+ export interface FeedReaderOptions {
244
+ /** Feed topic (32 bytes). */
245
+ topic: Identifier | Uint8Array | string | BeeTopic
246
+ /** Optional feed owner address (20 bytes). */
247
+ owner?: Address | Uint8Array | string
248
+ }
249
+
250
+ /**
251
+ * Options for epoch feed writer creation.
252
+ */
253
+ export interface FeedWriterOptions {
254
+ /** Feed topic (32 bytes). */
255
+ topic: Identifier | Uint8Array | string | BeeTopic
256
+ /** Optional signer private key (32 bytes). */
257
+ signer?: BeePrivateKey | Uint8Array | string
258
+ }
259
+
260
+ /**
261
+ * Epoch feed reader interface.
262
+ */
263
+ export interface EpochFeedDownloadOptions {
264
+ /** Unix timestamp (seconds). */
265
+ at?: bigint | number | string
266
+ /** Hint of latest known update timestamp. */
267
+ after?: bigint | number | string
268
+ /** Optional encryption key for encrypted feed updates. */
269
+ encryptionKey?: Uint8Array | string
270
+ }
271
+
272
+ export interface EpochFeedUploadOptions {
273
+ /** Unix timestamp (seconds). */
274
+ at?: bigint | number | string
275
+ /** Optional upload options for the payload upload. */
276
+ uploadOptions?: UploadOptions
277
+ /** Whether to encrypt payload uploads (defaults to true). */
278
+ encrypt?: boolean
279
+ /** Optional encryption key for encrypted feed updates. */
280
+ encryptionKey?: Uint8Array | string
281
+ /** Optional hints from previous update for stateless epoch calculation. */
282
+ hints?: {
283
+ lastEpoch?: { start: string; level: number }
284
+ lastTimestamp?: string
285
+ }
286
+ }
287
+
288
+ export interface EpochFeedDownloadPayloadResult {
289
+ /** Downloaded payload, if available. */
290
+ payload?: Uint8Array
291
+ /** Reference used to download the payload, if available. */
292
+ reference?: Reference
293
+ /** Encryption key (hex) if the reference is encrypted. */
294
+ encryptionKey?: string
295
+ }
296
+
297
+ export interface EpochFeedDownloadReferenceResult {
298
+ /** Swarm reference (hex), if found. */
299
+ reference?: Reference
300
+ /** Encryption key (hex) if the reference is encrypted. */
301
+ encryptionKey?: string
302
+ }
303
+
304
+ export interface EpochFeedUploadResult {
305
+ /** SOC address for the feed update. */
306
+ socAddress: Reference
307
+ /** Reference stored in the feed update. */
308
+ reference: Reference
309
+ /** Encryption key (hex) if the reference is encrypted. */
310
+ encryptionKey?: string
311
+ /** Epoch used for this update (for caller to store as hint) */
312
+ epoch: { start: string; level: number }
313
+ /** Timestamp used (stringified bigint) */
314
+ timestamp: string
315
+ }
316
+
317
+ /**
318
+ * Epoch feed reader interface.
319
+ */
320
+ export interface FeedReader {
321
+ /** Resolve feed owner address (20 bytes). */
322
+ getOwner: () => Promise<Address>
323
+ /** Download the reference for the given timestamp. */
324
+ downloadReference: (
325
+ options?: EpochFeedDownloadOptions,
326
+ ) => Promise<EpochFeedDownloadReferenceResult>
327
+ /** Download the payload for the given timestamp. */
328
+ downloadPayload: (
329
+ options?: EpochFeedDownloadOptions,
330
+ ) => Promise<EpochFeedDownloadPayloadResult>
331
+ /** Download unencrypted reference (for /bzz access). */
332
+ downloadRawReference: (
333
+ options?: Omit<EpochFeedDownloadOptions, "encryptionKey">,
334
+ ) => Promise<EpochFeedDownloadReferenceResult>
335
+ /** Download unencrypted payload (for /bzz access). */
336
+ downloadRawPayload: (
337
+ options?: Omit<EpochFeedDownloadOptions, "encryptionKey">,
338
+ ) => Promise<EpochFeedDownloadPayloadResult>
339
+ }
340
+
341
+ /**
342
+ * Epoch feed writer interface.
343
+ */
344
+ export interface FeedWriter extends FeedReader {
345
+ /** Upload payload data and update the feed. */
346
+ uploadPayload: (
347
+ data: Uint8Array | string,
348
+ options?: EpochFeedUploadOptions,
349
+ ) => Promise<EpochFeedUploadResult>
350
+ /** Update the feed with a reference. */
351
+ uploadReference: (
352
+ reference: Uint8Array | string,
353
+ options?: EpochFeedUploadOptions,
354
+ ) => Promise<EpochFeedUploadResult>
355
+ /** Upload unencrypted payload (for /bzz access). */
356
+ uploadRawPayload: (
357
+ data: Uint8Array | string,
358
+ options?: Omit<EpochFeedUploadOptions, "encryptionKey" | "encrypt">,
359
+ ) => Promise<EpochFeedUploadResult>
360
+ /** Upload unencrypted reference (for /bzz access). */
361
+ uploadRawReference: (
362
+ reference: Uint8Array | string,
363
+ options?: Omit<EpochFeedUploadOptions, "encryptionKey">,
364
+ ) => Promise<EpochFeedUploadResult>
365
+ }
366
+
367
+ // ============================================================================
368
+ // Sequential Feed Types
369
+ // ============================================================================
370
+
371
+ /**
372
+ * Options for sequential feed reader creation.
373
+ */
374
+ export interface SequentialFeedReaderOptions {
375
+ /** Feed topic (32 bytes). */
376
+ topic: Identifier | Uint8Array | string | BeeTopic
377
+ /** Optional feed owner address (20 bytes). */
378
+ owner?: Address | Uint8Array | string
379
+ }
380
+
381
+ /**
382
+ * Options for sequential feed writer creation.
383
+ */
384
+ export interface SequentialFeedWriterOptions {
385
+ /** Feed topic (32 bytes). */
386
+ topic: Identifier | Uint8Array | string | BeeTopic
387
+ /** Optional signer private key (32 bytes). */
388
+ signer?: BeePrivateKey | Uint8Array | string
389
+ }
390
+
391
+ /**
392
+ * Options for sequential feed lookups/updates.
393
+ */
394
+ export interface SequentialFeedUpdateOptions {
395
+ /** Specific feed index to read/write. */
396
+ index?: FeedIndex | bigint
397
+ /** Timestamp (seconds) used for lookup or payload timestamp. */
398
+ at?: Timestamp | bigint
399
+ /** Whether payload is prefixed with timestamp (default true). */
400
+ hasTimestamp?: boolean
401
+ /** Timeout (ms) for sequential index lookups (default 2000). */
402
+ lookupTimeoutMs?: number
403
+ }
404
+
405
+ /**
406
+ * Options for sequential feed uploads.
407
+ */
408
+ export interface SequentialFeedUploadOptions
409
+ extends UploadOptions, SequentialFeedUpdateOptions {}
410
+
411
+ /**
412
+ * Options for sequential feed raw download (encryptionKey in options).
413
+ */
414
+ export interface SequentialFeedDownloadRawOptions extends SequentialFeedUpdateOptions {
415
+ /** Optional encryption key for decrypting encrypted feed updates. */
416
+ encryptionKey?: Uint8Array | string
417
+ }
418
+
419
+ /**
420
+ * Options for sequential feed raw upload (encryptionKey in options).
421
+ */
422
+ export interface SequentialFeedUploadRawOptions extends SequentialFeedUploadOptions {
423
+ /** Optional encryption key for encrypting the payload. */
424
+ encryptionKey?: Uint8Array | string
425
+ }
426
+
427
+ /**
428
+ * Result from sequential payload download.
429
+ */
430
+ export interface SequentialFeedPayloadResult {
431
+ /** Payload bytes (timestamp removed if present). */
432
+ payload: Uint8Array
433
+ /** Timestamp extracted from payload, if present. */
434
+ timestamp?: number
435
+ /** Current feed index as a stringified uint64. */
436
+ feedIndex: string
437
+ /** Next feed index as a stringified uint64. */
438
+ feedIndexNext: string
439
+ }
440
+
441
+ /**
442
+ * Result from sequential reference download.
443
+ */
444
+ export interface SequentialFeedReferenceResult {
445
+ /** Swarm reference stored in the feed update. */
446
+ reference: string
447
+ /** Current feed index as a stringified uint64. */
448
+ feedIndex: string
449
+ /** Next feed index as a stringified uint64. */
450
+ feedIndexNext: string
451
+ }
452
+
453
+ /**
454
+ * Result from sequential feed upload.
455
+ */
456
+ export interface SequentialFeedUploadResult {
457
+ /** SOC address of the feed update. */
458
+ reference: string
459
+ /** Feed index used for the update (stringified uint64). */
460
+ feedIndex: string
461
+ /** Owner address for the feed update. */
462
+ owner: string
463
+ /** Encryption key for decrypting payload (if encrypted). */
464
+ encryptionKey?: string
465
+ /** Upload tag UID, if provided. */
466
+ tagUid?: number
467
+ }
468
+
469
+ /**
470
+ * Sequential feed reader interface.
471
+ */
472
+ export interface SequentialFeedReader {
473
+ /** Resolve feed owner address (20 bytes). */
474
+ getOwner: () => Promise<Address>
475
+ /**
476
+ * Download and decrypt payload (requires encryption key).
477
+ * @param encryptionKey - 32-byte encryption key.
478
+ */
479
+ downloadPayload: (
480
+ encryptionKey: Uint8Array | string,
481
+ options?: SequentialFeedUpdateOptions,
482
+ ) => Promise<SequentialFeedPayloadResult>
483
+ /**
484
+ * Download raw payload or decrypt if encryptionKey is provided in options.
485
+ */
486
+ downloadRawPayload: (
487
+ options?: SequentialFeedDownloadRawOptions,
488
+ ) => Promise<SequentialFeedPayloadResult>
489
+ /**
490
+ * Download and decrypt reference (requires encryption key).
491
+ * @param encryptionKey - 32-byte encryption key.
492
+ */
493
+ downloadReference: (
494
+ encryptionKey: Uint8Array | string,
495
+ options?: SequentialFeedUpdateOptions,
496
+ ) => Promise<SequentialFeedReferenceResult>
497
+ }
498
+
499
+ /**
500
+ * Sequential feed writer interface.
501
+ */
502
+ export interface SequentialFeedWriter extends SequentialFeedReader {
503
+ /**
504
+ * Upload encrypted payload.
505
+ */
506
+ uploadPayload: (
507
+ data: Uint8Array | string,
508
+ options?: SequentialFeedUploadOptions,
509
+ ) => Promise<SequentialFeedUploadResult>
510
+ /**
511
+ * Upload raw payload (or encrypted if encryptionKey provided in options).
512
+ */
513
+ uploadRawPayload: (
514
+ data: Uint8Array | string,
515
+ options?: SequentialFeedUploadRawOptions,
516
+ ) => Promise<SequentialFeedUploadResult>
517
+ /**
518
+ * Upload a reference payload (encrypted by default).
519
+ */
520
+ uploadReference: (
521
+ reference: Uint8Array | string,
522
+ options?: SequentialFeedUploadOptions,
523
+ ) => Promise<SequentialFeedUploadResult>
524
+ }
525
+
526
+ // ============================================================================
527
+ // Auth Status
528
+ // ============================================================================
529
+
530
+ export const AuthStatusSchema = z.object({
531
+ authenticated: z.boolean(),
532
+ origin: z.string().optional(),
533
+ })
534
+
535
+ export type AuthStatus = z.infer<typeof AuthStatusSchema>
536
+
537
+ // ============================================================================
538
+ // Connection Info
539
+ // ============================================================================
540
+
541
+ export const ConnectionInfoSchema = z.object({
542
+ /** Whether uploads are available (has postage stamp + signer key + not storage-partitioned) */
543
+ canUpload: z.boolean(),
544
+ /** Whether browser storage partitioning prevents access to stamps/signer keys (e.g. Safari ITP, strict privacy settings) */
545
+ storagePartitioned: z.boolean().optional(),
546
+ identity: z
547
+ .object({
548
+ id: z.string(),
549
+ name: z.string(),
550
+ address: AddressSchema,
551
+ })
552
+ .optional(),
553
+ })
554
+
555
+ export type ConnectionInfo = z.infer<typeof ConnectionInfoSchema>
556
+
557
+ // ============================================================================
558
+ // Button Styles
559
+ // ============================================================================
560
+
561
+ export const ButtonStylesSchema = z
562
+ .object({
563
+ backgroundColor: z.string().optional(),
564
+ color: z.string().optional(),
565
+ border: z.string().optional(),
566
+ borderRadius: z.string().optional(),
567
+ padding: z.string().optional(),
568
+ fontSize: z.string().optional(),
569
+ fontFamily: z.string().optional(),
570
+ fontWeight: z.string().optional(),
571
+ cursor: z.string().optional(),
572
+ width: z.string().optional(),
573
+ height: z.string().optional(),
574
+ })
575
+ .optional()
576
+
577
+ export type ButtonStyles = z.infer<typeof ButtonStylesSchema>
578
+
579
+ // ============================================================================
580
+ // App Metadata
581
+ // ============================================================================
582
+
583
+ export const AppMetadataSchema = z.object({
584
+ name: z.string().min(1).max(100),
585
+ description: z.string().max(500).optional(),
586
+ icon: z
587
+ .string()
588
+ .optional()
589
+ .refine(
590
+ (val) => {
591
+ if (!val) return true
592
+ if (!val.startsWith("data:image/")) return false
593
+ const mimeMatch = val.match(/^data:image\/(svg\+xml|png);/)
594
+ if (!mimeMatch) return false
595
+ const base64Match = val.match(/base64,(.+)$/)
596
+ if (base64Match) {
597
+ const approximateSize = (base64Match[1].length * 3) / 4
598
+ if (approximateSize > 4096) return false
599
+ }
600
+ return true
601
+ },
602
+ { message: "Icon must be a data URL with SVG or PNG mime type, max 4KB" },
603
+ ),
604
+ })
605
+
606
+ export type AppMetadata = z.infer<typeof AppMetadataSchema>
607
+
608
+ // ============================================================================
609
+ // Button Configuration
610
+ // ============================================================================
611
+
612
+ export const ButtonConfigSchema = z
613
+ .object({
614
+ connectText: z.string().optional(),
615
+ disconnectText: z.string().optional(),
616
+ loadingText: z.string().optional(),
617
+ backgroundColor: z.string().optional(),
618
+ color: z.string().optional(),
619
+ borderRadius: z.string().optional(),
620
+ })
621
+ .optional()
622
+
623
+ export interface ButtonConfig {
624
+ connectText?: string // Default: "🔐 Login with Swarm ID"
625
+ disconnectText?: string // Default: "🔓 Disconnect from Swarm ID"
626
+ loadingText?: string // Default: "⏳ Loading..."
627
+ backgroundColor?: string // Default: "#dd7200" (connect), "#666" (disconnect)
628
+ color?: string // Default: "white"
629
+ borderRadius?: string // Default: "0", applied to iframe
630
+ }
631
+
632
+ // ============================================================================
633
+ // Message Types: Parent → Iframe
634
+ // ============================================================================
635
+
636
+ export const ParentIdentifyMessageSchema = z.object({
637
+ type: z.literal("parentIdentify"),
638
+ beeApiUrl: z.string().url().optional(),
639
+ popupMode: z.enum(["popup", "window"]).optional(),
640
+ metadata: AppMetadataSchema,
641
+ buttonConfig: ButtonConfigSchema,
642
+ })
643
+
644
+ export const CheckAuthMessageSchema = z.object({
645
+ type: z.literal("checkAuth"),
646
+ requestId: z.string(),
647
+ })
648
+
649
+ export const DisconnectMessageSchema = z.object({
650
+ type: z.literal("disconnect"),
651
+ requestId: z.string(),
652
+ })
653
+
654
+ export const RequestAuthMessageSchema = z.object({
655
+ type: z.literal("requestAuth"),
656
+ styles: ButtonStylesSchema,
657
+ })
658
+
659
+ export const UploadDataMessageSchema = z.object({
660
+ type: z.literal("uploadData"),
661
+ requestId: z.string(),
662
+ data: z.instanceof(Uint8Array),
663
+ options: UploadOptionsSchema,
664
+ requestOptions: RequestOptionsSchema,
665
+ enableProgress: z.boolean().optional(),
666
+ })
667
+
668
+ export const DownloadDataMessageSchema = z.object({
669
+ type: z.literal("downloadData"),
670
+ requestId: z.string(),
671
+ reference: ReferenceSchema,
672
+ options: DownloadOptionsSchema,
673
+ requestOptions: RequestOptionsSchema,
674
+ })
675
+
676
+ export const UploadFileMessageSchema = z.object({
677
+ type: z.literal("uploadFile"),
678
+ requestId: z.string(),
679
+ data: z.instanceof(Uint8Array),
680
+ name: z.string().optional(),
681
+ options: UploadOptionsSchema,
682
+ requestOptions: RequestOptionsSchema,
683
+ })
684
+
685
+ export const DownloadFileMessageSchema = z.object({
686
+ type: z.literal("downloadFile"),
687
+ requestId: z.string(),
688
+ reference: ReferenceSchema,
689
+ path: z.string().optional(),
690
+ options: DownloadOptionsSchema,
691
+ requestOptions: RequestOptionsSchema,
692
+ })
693
+
694
+ export const UploadChunkMessageSchema = z.object({
695
+ type: z.literal("uploadChunk"),
696
+ requestId: z.string(),
697
+ data: z.instanceof(Uint8Array),
698
+ options: UploadOptionsSchema,
699
+ requestOptions: RequestOptionsSchema,
700
+ })
701
+
702
+ export const DownloadChunkMessageSchema = z.object({
703
+ type: z.literal("downloadChunk"),
704
+ requestId: z.string(),
705
+ reference: ReferenceSchema,
706
+ options: DownloadOptionsSchema,
707
+ requestOptions: RequestOptionsSchema,
708
+ })
709
+
710
+ export const GetConnectionInfoMessageSchema = z.object({
711
+ type: z.literal("getConnectionInfo"),
712
+ requestId: z.string(),
713
+ })
714
+
715
+ export const IsConnectedMessageSchema = z.object({
716
+ type: z.literal("isConnected"),
717
+ requestId: z.string(),
718
+ })
719
+
720
+ export const GetNodeInfoMessageSchema = z.object({
721
+ type: z.literal("getNodeInfo"),
722
+ requestId: z.string(),
723
+ })
724
+
725
+ export const GsocMineMessageSchema = z.object({
726
+ type: z.literal("gsocMine"),
727
+ requestId: z.string(),
728
+ targetOverlay: z.string(),
729
+ identifier: z.string(),
730
+ proximity: z.number().optional(),
731
+ })
732
+
733
+ export const GsocSendMessageSchema = z.object({
734
+ type: z.literal("gsocSend"),
735
+ requestId: z.string(),
736
+ signer: z.string(),
737
+ identifier: z.string(),
738
+ data: z.instanceof(Uint8Array),
739
+ options: UploadOptionsSchema,
740
+ requestOptions: RequestOptionsSchema,
741
+ })
742
+
743
+ // SOC (Single Owner Chunk) Message Schemas
744
+ export const SocUploadMessageSchema = z.object({
745
+ type: z.literal("socUpload"),
746
+ requestId: z.string(),
747
+ identifier: IdentifierSchema,
748
+ data: z.instanceof(Uint8Array),
749
+ signer: PrivateKeySchema.optional(),
750
+ options: UploadOptionsSchema,
751
+ requestOptions: RequestOptionsSchema,
752
+ })
753
+
754
+ export const SocRawUploadMessageSchema = z.object({
755
+ type: z.literal("socRawUpload"),
756
+ requestId: z.string(),
757
+ identifier: IdentifierSchema,
758
+ data: z.instanceof(Uint8Array),
759
+ signer: PrivateKeySchema.optional(),
760
+ options: UploadOptionsSchema,
761
+ requestOptions: RequestOptionsSchema,
762
+ })
763
+
764
+ export const SocDownloadMessageSchema = z.object({
765
+ type: z.literal("socDownload"),
766
+ requestId: z.string(),
767
+ owner: AddressSchema.optional(),
768
+ identifier: IdentifierSchema,
769
+ encryptionKey: EncryptionKeySchema,
770
+ requestOptions: RequestOptionsSchema,
771
+ })
772
+
773
+ export const SocRawDownloadMessageSchema = z.object({
774
+ type: z.literal("socRawDownload"),
775
+ requestId: z.string(),
776
+ owner: AddressSchema.optional(),
777
+ identifier: IdentifierSchema,
778
+ encryptionKey: EncryptionKeySchema.optional(),
779
+ requestOptions: RequestOptionsSchema,
780
+ })
781
+
782
+ export const SocGetOwnerMessageSchema = z.object({
783
+ type: z.literal("socGetOwner"),
784
+ requestId: z.string(),
785
+ })
786
+
787
+ export const EpochFeedDownloadReferenceMessageSchema = z.object({
788
+ type: z.literal("epochFeedDownloadReference"),
789
+ requestId: z.string(),
790
+ topic: IdentifierSchema,
791
+ owner: AddressSchema.optional(),
792
+ at: TimestampSchema,
793
+ after: TimestampSchema.optional(),
794
+ encryptionKey: EncryptionKeySchema.optional(),
795
+ requestOptions: RequestOptionsSchema,
796
+ })
797
+
798
+ // Schema for epoch hints (used for stateless epoch calculation)
799
+ export const EpochHintsSchema = z
800
+ .object({
801
+ lastEpoch: z
802
+ .object({
803
+ start: z.string(), // Stringified bigint
804
+ level: z.number(),
805
+ })
806
+ .optional(),
807
+ lastTimestamp: z.string().optional(), // Stringified bigint
808
+ })
809
+ .optional()
810
+
811
+ export const EpochFeedUploadReferenceMessageSchema = z.object({
812
+ type: z.literal("epochFeedUploadReference"),
813
+ requestId: z.string(),
814
+ topic: IdentifierSchema,
815
+ signer: PrivateKeySchema.optional(),
816
+ at: TimestampSchema,
817
+ reference: ReferenceSchema,
818
+ encryptionKey: EncryptionKeySchema.optional(),
819
+ hints: EpochHintsSchema,
820
+ requestOptions: RequestOptionsSchema,
821
+ })
822
+
823
+ export const FeedGetOwnerMessageSchema = z.object({
824
+ type: z.literal("feedGetOwner"),
825
+ requestId: z.string(),
826
+ })
827
+
828
+ export const SequentialFeedGetOwnerMessageSchema = z.object({
829
+ type: z.literal("seqFeedGetOwner"),
830
+ requestId: z.string(),
831
+ })
832
+
833
+ export const SequentialFeedDownloadPayloadMessageSchema = z.object({
834
+ type: z.literal("seqFeedDownloadPayload"),
835
+ requestId: z.string(),
836
+ topic: IdentifierSchema,
837
+ owner: AddressSchema.optional(),
838
+ index: FeedIndexSchema.optional(),
839
+ at: TimestampSchema.optional(),
840
+ hasTimestamp: z.boolean().optional(),
841
+ lookupTimeoutMs: z.number().optional(),
842
+ encryptionKey: EncryptionKeySchema,
843
+ requestOptions: RequestOptionsSchema,
844
+ })
845
+
846
+ export const SequentialFeedDownloadRawPayloadMessageSchema = z.object({
847
+ type: z.literal("seqFeedDownloadRawPayload"),
848
+ requestId: z.string(),
849
+ topic: IdentifierSchema,
850
+ owner: AddressSchema.optional(),
851
+ index: FeedIndexSchema.optional(),
852
+ at: TimestampSchema.optional(),
853
+ hasTimestamp: z.boolean().optional(),
854
+ lookupTimeoutMs: z.number().optional(),
855
+ encryptionKey: EncryptionKeySchema.optional(),
856
+ requestOptions: RequestOptionsSchema,
857
+ })
858
+
859
+ export const SequentialFeedDownloadReferenceMessageSchema = z.object({
860
+ type: z.literal("seqFeedDownloadReference"),
861
+ requestId: z.string(),
862
+ topic: IdentifierSchema,
863
+ owner: AddressSchema.optional(),
864
+ index: FeedIndexSchema.optional(),
865
+ at: TimestampSchema.optional(),
866
+ hasTimestamp: z.boolean().optional(),
867
+ lookupTimeoutMs: z.number().optional(),
868
+ encryptionKey: EncryptionKeySchema,
869
+ requestOptions: RequestOptionsSchema,
870
+ })
871
+
872
+ export const SequentialFeedUploadPayloadMessageSchema = z.object({
873
+ type: z.literal("seqFeedUploadPayload"),
874
+ requestId: z.string(),
875
+ topic: IdentifierSchema,
876
+ signer: PrivateKeySchema.optional(),
877
+ data: z.instanceof(Uint8Array),
878
+ index: FeedIndexSchema.optional(),
879
+ at: TimestampSchema.optional(),
880
+ hasTimestamp: z.boolean().optional(),
881
+ lookupTimeoutMs: z.number().optional(),
882
+ options: UploadOptionsSchema,
883
+ requestOptions: RequestOptionsSchema,
884
+ })
885
+
886
+ export const SequentialFeedUploadRawPayloadMessageSchema = z.object({
887
+ type: z.literal("seqFeedUploadRawPayload"),
888
+ requestId: z.string(),
889
+ topic: IdentifierSchema,
890
+ signer: PrivateKeySchema.optional(),
891
+ data: z.instanceof(Uint8Array),
892
+ index: FeedIndexSchema.optional(),
893
+ at: TimestampSchema.optional(),
894
+ hasTimestamp: z.boolean().optional(),
895
+ lookupTimeoutMs: z.number().optional(),
896
+ encryptionKey: EncryptionKeySchema.optional(),
897
+ options: UploadOptionsSchema,
898
+ requestOptions: RequestOptionsSchema,
899
+ })
900
+
901
+ export const SequentialFeedUploadReferenceMessageSchema = z.object({
902
+ type: z.literal("seqFeedUploadReference"),
903
+ requestId: z.string(),
904
+ topic: IdentifierSchema,
905
+ signer: PrivateKeySchema.optional(),
906
+ reference: ReferenceSchema,
907
+ index: FeedIndexSchema.optional(),
908
+ at: TimestampSchema.optional(),
909
+ hasTimestamp: z.boolean().optional(),
910
+ lookupTimeoutMs: z.number().optional(),
911
+ options: UploadOptionsSchema,
912
+ requestOptions: RequestOptionsSchema,
913
+ })
914
+
915
+ // Feed Manifest Message Schema
916
+ export const CreateFeedManifestMessageSchema = z.object({
917
+ type: z.literal("createFeedManifest"),
918
+ requestId: z.string(),
919
+ topic: IdentifierSchema,
920
+ owner: AddressSchema.optional(),
921
+ feedType: z.enum(["Sequence", "Epoch"]).optional(),
922
+ uploadOptions: UploadOptionsSchema,
923
+ requestOptions: RequestOptionsSchema,
924
+ })
925
+
926
+ // ACT (Access Control Tries) Message Schemas
927
+ export const ActUploadDataMessageSchema = z.object({
928
+ type: z.literal("actUploadData"),
929
+ requestId: z.string(),
930
+ data: z.instanceof(Uint8Array),
931
+ grantees: z.array(z.string()), // Compressed public keys (33 bytes = 66 hex chars)
932
+ options: ActUploadOptionsSchema,
933
+ requestOptions: RequestOptionsSchema,
934
+ enableProgress: z.boolean().optional(),
935
+ })
936
+
937
+ export const ActDownloadDataMessageSchema = z.object({
938
+ type: z.literal("actDownloadData"),
939
+ requestId: z.string(),
940
+ encryptedReference: ReferenceSchema,
941
+ historyReference: ReferenceSchema,
942
+ publisherPubKey: z.string(), // Compressed public key (33 bytes = 66 hex chars)
943
+ timestamp: z.number().optional(), // Optional: specific ACT version
944
+ requestOptions: RequestOptionsSchema,
945
+ })
946
+
947
+ export const ActAddGranteesMessageSchema = z.object({
948
+ type: z.literal("actAddGrantees"),
949
+ requestId: z.string(),
950
+ historyReference: ReferenceSchema,
951
+ grantees: z.array(z.string()), // Compressed public keys to add
952
+ requestOptions: RequestOptionsSchema,
953
+ })
954
+
955
+ export const ActRevokeGranteesMessageSchema = z.object({
956
+ type: z.literal("actRevokeGrantees"),
957
+ requestId: z.string(),
958
+ historyReference: ReferenceSchema,
959
+ encryptedReference: ReferenceSchema, // Needed for key rotation
960
+ revokeGrantees: z.array(z.string()), // Compressed public keys to revoke
961
+ requestOptions: RequestOptionsSchema,
962
+ })
963
+
964
+ export const ActGetGranteesMessageSchema = z.object({
965
+ type: z.literal("actGetGrantees"),
966
+ requestId: z.string(),
967
+ historyReference: ReferenceSchema,
968
+ requestOptions: RequestOptionsSchema,
969
+ })
970
+
971
+ export const GetPostageBatchMessageSchema = z.object({
972
+ type: z.literal("getPostageBatch"),
973
+ requestId: z.string(),
974
+ })
975
+
976
+ export const ConnectMessageSchema = z.object({
977
+ type: z.literal("connect"),
978
+ requestId: z.string(),
979
+ agent: z.boolean().optional(),
980
+ popupMode: z.enum(["popup", "window"]).optional(),
981
+ })
982
+
983
+ export const ParentToIframeMessageSchema = z.discriminatedUnion("type", [
984
+ ParentIdentifyMessageSchema,
985
+ CheckAuthMessageSchema,
986
+ DisconnectMessageSchema,
987
+ RequestAuthMessageSchema,
988
+ UploadDataMessageSchema,
989
+ DownloadDataMessageSchema,
990
+ UploadFileMessageSchema,
991
+ DownloadFileMessageSchema,
992
+ UploadChunkMessageSchema,
993
+ DownloadChunkMessageSchema,
994
+ GetConnectionInfoMessageSchema,
995
+ IsConnectedMessageSchema,
996
+ GetNodeInfoMessageSchema,
997
+ GsocMineMessageSchema,
998
+ GsocSendMessageSchema,
999
+ SocUploadMessageSchema,
1000
+ SocRawUploadMessageSchema,
1001
+ SocDownloadMessageSchema,
1002
+ SocRawDownloadMessageSchema,
1003
+ SocGetOwnerMessageSchema,
1004
+ EpochFeedDownloadReferenceMessageSchema,
1005
+ EpochFeedUploadReferenceMessageSchema,
1006
+ FeedGetOwnerMessageSchema,
1007
+ SequentialFeedGetOwnerMessageSchema,
1008
+ SequentialFeedDownloadPayloadMessageSchema,
1009
+ SequentialFeedDownloadRawPayloadMessageSchema,
1010
+ SequentialFeedDownloadReferenceMessageSchema,
1011
+ SequentialFeedUploadPayloadMessageSchema,
1012
+ SequentialFeedUploadRawPayloadMessageSchema,
1013
+ SequentialFeedUploadReferenceMessageSchema,
1014
+ CreateFeedManifestMessageSchema,
1015
+ ActUploadDataMessageSchema,
1016
+ ActDownloadDataMessageSchema,
1017
+ ActAddGranteesMessageSchema,
1018
+ ActRevokeGranteesMessageSchema,
1019
+ ActGetGranteesMessageSchema,
1020
+ GetPostageBatchMessageSchema,
1021
+ ConnectMessageSchema,
1022
+ ])
1023
+
1024
+ export type ParentIdentifyMessage = z.infer<typeof ParentIdentifyMessageSchema>
1025
+ export type CheckAuthMessage = z.infer<typeof CheckAuthMessageSchema>
1026
+ export type DisconnectMessage = z.infer<typeof DisconnectMessageSchema>
1027
+ export type RequestAuthMessage = z.infer<typeof RequestAuthMessageSchema>
1028
+ export type UploadDataMessage = z.infer<typeof UploadDataMessageSchema>
1029
+ export type DownloadDataMessage = z.infer<typeof DownloadDataMessageSchema>
1030
+ export type UploadFileMessage = z.infer<typeof UploadFileMessageSchema>
1031
+ export type DownloadFileMessage = z.infer<typeof DownloadFileMessageSchema>
1032
+ export type UploadChunkMessage = z.infer<typeof UploadChunkMessageSchema>
1033
+ export type DownloadChunkMessage = z.infer<typeof DownloadChunkMessageSchema>
1034
+ export type GetConnectionInfoMessage = z.infer<
1035
+ typeof GetConnectionInfoMessageSchema
1036
+ >
1037
+ export type IsConnectedMessage = z.infer<typeof IsConnectedMessageSchema>
1038
+ export type GetNodeInfoMessage = z.infer<typeof GetNodeInfoMessageSchema>
1039
+ export type GsocMineMessage = z.infer<typeof GsocMineMessageSchema>
1040
+ export type GsocSendMessage = z.infer<typeof GsocSendMessageSchema>
1041
+ export type SocUploadMessage = z.infer<typeof SocUploadMessageSchema>
1042
+ export type SocRawUploadMessage = z.infer<typeof SocRawUploadMessageSchema>
1043
+ export type SocDownloadMessage = z.infer<typeof SocDownloadMessageSchema>
1044
+ export type SocRawDownloadMessage = z.infer<typeof SocRawDownloadMessageSchema>
1045
+ export type SocGetOwnerMessage = z.infer<typeof SocGetOwnerMessageSchema>
1046
+ export type EpochFeedDownloadReferenceMessage = z.infer<
1047
+ typeof EpochFeedDownloadReferenceMessageSchema
1048
+ >
1049
+ export type EpochFeedUploadReferenceMessage = z.infer<
1050
+ typeof EpochFeedUploadReferenceMessageSchema
1051
+ >
1052
+ export type FeedGetOwnerMessage = z.infer<typeof FeedGetOwnerMessageSchema>
1053
+ export type SequentialFeedGetOwnerMessage = z.infer<
1054
+ typeof SequentialFeedGetOwnerMessageSchema
1055
+ >
1056
+ export type SequentialFeedDownloadPayloadMessage = z.infer<
1057
+ typeof SequentialFeedDownloadPayloadMessageSchema
1058
+ >
1059
+ export type SequentialFeedDownloadRawPayloadMessage = z.infer<
1060
+ typeof SequentialFeedDownloadRawPayloadMessageSchema
1061
+ >
1062
+ export type SequentialFeedDownloadReferenceMessage = z.infer<
1063
+ typeof SequentialFeedDownloadReferenceMessageSchema
1064
+ >
1065
+ export type SequentialFeedUploadPayloadMessage = z.infer<
1066
+ typeof SequentialFeedUploadPayloadMessageSchema
1067
+ >
1068
+ export type SequentialFeedUploadRawPayloadMessage = z.infer<
1069
+ typeof SequentialFeedUploadRawPayloadMessageSchema
1070
+ >
1071
+ export type SequentialFeedUploadReferenceMessage = z.infer<
1072
+ typeof SequentialFeedUploadReferenceMessageSchema
1073
+ >
1074
+ export type CreateFeedManifestMessage = z.infer<
1075
+ typeof CreateFeedManifestMessageSchema
1076
+ >
1077
+ export type ActUploadDataMessage = z.infer<typeof ActUploadDataMessageSchema>
1078
+ export type ActDownloadDataMessage = z.infer<
1079
+ typeof ActDownloadDataMessageSchema
1080
+ >
1081
+ export type ActAddGranteesMessage = z.infer<typeof ActAddGranteesMessageSchema>
1082
+ export type ActRevokeGranteesMessage = z.infer<
1083
+ typeof ActRevokeGranteesMessageSchema
1084
+ >
1085
+ export type ActGetGranteesMessage = z.infer<typeof ActGetGranteesMessageSchema>
1086
+ export type GetPostageBatchMessage = z.infer<
1087
+ typeof GetPostageBatchMessageSchema
1088
+ >
1089
+ export type ConnectMessage = z.infer<typeof ConnectMessageSchema>
1090
+ export type ParentToIframeMessage = z.infer<typeof ParentToIframeMessageSchema>
1091
+
1092
+ // ============================================================================
1093
+ // Message Types: Iframe → Parent
1094
+ // ============================================================================
1095
+
1096
+ export const ProxyReadyMessageSchema = z.object({
1097
+ type: z.literal("proxyReady"),
1098
+ authenticated: z.boolean(),
1099
+ parentOrigin: z.string(),
1100
+ })
1101
+
1102
+ export const InitErrorMessageSchema = z.object({
1103
+ type: z.literal("initError"),
1104
+ error: z.string(),
1105
+ })
1106
+
1107
+ export const AuthStatusResponseMessageSchema = z.object({
1108
+ type: z.literal("authStatusResponse"),
1109
+ requestId: z.string(),
1110
+ authenticated: z.boolean(),
1111
+ origin: z.string().optional(),
1112
+ })
1113
+
1114
+ export const DisconnectResponseMessageSchema = z.object({
1115
+ type: z.literal("disconnectResponse"),
1116
+ requestId: z.string(),
1117
+ success: z.boolean(),
1118
+ })
1119
+
1120
+ export const AuthSuccessMessageSchema = z.object({
1121
+ type: z.literal("authSuccess"),
1122
+ origin: z.string(),
1123
+ })
1124
+
1125
+ export const UploadDataResponseMessageSchema = z.object({
1126
+ type: z.literal("uploadDataResponse"),
1127
+ requestId: z.string(),
1128
+ reference: ReferenceSchema,
1129
+ tagUid: z.number().optional(),
1130
+ })
1131
+
1132
+ export const DownloadDataResponseMessageSchema = z.object({
1133
+ type: z.literal("downloadDataResponse"),
1134
+ requestId: z.string(),
1135
+ data: z.instanceof(Uint8Array),
1136
+ })
1137
+
1138
+ export const UploadFileResponseMessageSchema = z.object({
1139
+ type: z.literal("uploadFileResponse"),
1140
+ requestId: z.string(),
1141
+ reference: ReferenceSchema,
1142
+ tagUid: z.number().optional(),
1143
+ })
1144
+
1145
+ export const DownloadFileResponseMessageSchema = z.object({
1146
+ type: z.literal("downloadFileResponse"),
1147
+ requestId: z.string(),
1148
+ name: z.string(),
1149
+ data: z.instanceof(Uint8Array),
1150
+ })
1151
+
1152
+ export const UploadChunkResponseMessageSchema = z.object({
1153
+ type: z.literal("uploadChunkResponse"),
1154
+ requestId: z.string(),
1155
+ reference: ReferenceSchema,
1156
+ })
1157
+
1158
+ export const DownloadChunkResponseMessageSchema = z.object({
1159
+ type: z.literal("downloadChunkResponse"),
1160
+ requestId: z.string(),
1161
+ data: z.instanceof(Uint8Array),
1162
+ })
1163
+
1164
+ export const UploadProgressMessageSchema = z.object({
1165
+ type: z.literal("uploadProgress"),
1166
+ requestId: z.string(),
1167
+ total: z.number(),
1168
+ processed: z.number(),
1169
+ })
1170
+
1171
+ export const ErrorMessageSchema = z.object({
1172
+ type: z.literal("error"),
1173
+ requestId: z.string(),
1174
+ error: z.string(),
1175
+ })
1176
+
1177
+ export const ConnectionInfoResponseMessageSchema = z.object({
1178
+ type: z.literal("connectionInfoResponse"),
1179
+ requestId: z.string(),
1180
+ canUpload: z.boolean(),
1181
+ storagePartitioned: z.boolean().optional(),
1182
+ identity: z
1183
+ .object({
1184
+ id: z.string(),
1185
+ name: z.string(),
1186
+ address: AddressSchema,
1187
+ })
1188
+ .optional(),
1189
+ })
1190
+
1191
+ export const ConnectResponseMessageSchema = z.object({
1192
+ type: z.literal("connectResponse"),
1193
+ requestId: z.string(),
1194
+ success: z.boolean(),
1195
+ })
1196
+
1197
+ export const IsConnectedResponseMessageSchema = z.object({
1198
+ type: z.literal("isConnectedResponse"),
1199
+ requestId: z.string(),
1200
+ connected: z.boolean(),
1201
+ })
1202
+
1203
+ export const GetNodeInfoResponseMessageSchema = z.object({
1204
+ type: z.literal("getNodeInfoResponse"),
1205
+ requestId: z.string(),
1206
+ beeMode: z.string(),
1207
+ chequebookEnabled: z.boolean(),
1208
+ swapEnabled: z.boolean(),
1209
+ })
1210
+
1211
+ export const GsocMineResponseMessageSchema = z.object({
1212
+ type: z.literal("gsocMineResponse"),
1213
+ requestId: z.string(),
1214
+ signer: z.string(),
1215
+ })
1216
+
1217
+ export const GsocSendResponseMessageSchema = z.object({
1218
+ type: z.literal("gsocSendResponse"),
1219
+ requestId: z.string(),
1220
+ reference: ReferenceSchema,
1221
+ tagUid: z.number().optional(),
1222
+ })
1223
+
1224
+ export const SocUploadResponseMessageSchema = z.object({
1225
+ type: z.literal("socUploadResponse"),
1226
+ requestId: z.string(),
1227
+ reference: ReferenceSchema,
1228
+ tagUid: z.number().optional(),
1229
+ encryptionKey: z.string(),
1230
+ owner: AddressSchema,
1231
+ })
1232
+
1233
+ export const SocRawUploadResponseMessageSchema = z.object({
1234
+ type: z.literal("socRawUploadResponse"),
1235
+ requestId: z.string(),
1236
+ reference: ReferenceSchema,
1237
+ tagUid: z.number().optional(),
1238
+ encryptionKey: z.string().optional(),
1239
+ owner: AddressSchema,
1240
+ })
1241
+
1242
+ export const SocDownloadResponseMessageSchema = z.object({
1243
+ type: z.literal("socDownloadResponse"),
1244
+ requestId: z.string(),
1245
+ data: z.instanceof(Uint8Array),
1246
+ identifier: IdentifierSchema,
1247
+ signature: SignatureSchema,
1248
+ span: z.number(),
1249
+ payload: z.instanceof(Uint8Array),
1250
+ address: ReferenceSchema,
1251
+ owner: AddressSchema,
1252
+ })
1253
+
1254
+ export const SocRawDownloadResponseMessageSchema = z.object({
1255
+ type: z.literal("socRawDownloadResponse"),
1256
+ requestId: z.string(),
1257
+ data: z.instanceof(Uint8Array),
1258
+ identifier: IdentifierSchema,
1259
+ signature: SignatureSchema,
1260
+ span: z.number(),
1261
+ payload: z.instanceof(Uint8Array),
1262
+ address: ReferenceSchema,
1263
+ owner: AddressSchema,
1264
+ })
1265
+
1266
+ export const SocGetOwnerResponseMessageSchema = z.object({
1267
+ type: z.literal("socGetOwnerResponse"),
1268
+ requestId: z.string(),
1269
+ owner: AddressSchema,
1270
+ })
1271
+
1272
+ export const EpochFeedDownloadReferenceResponseMessageSchema = z.object({
1273
+ type: z.literal("epochFeedDownloadReferenceResponse"),
1274
+ requestId: z.string(),
1275
+ reference: ReferenceSchema.optional(),
1276
+ })
1277
+
1278
+ export const EpochFeedUploadReferenceResponseMessageSchema = z.object({
1279
+ type: z.literal("epochFeedUploadReferenceResponse"),
1280
+ requestId: z.string(),
1281
+ socAddress: ReferenceSchema,
1282
+ encryptionKey: EncryptionKeySchema.optional(),
1283
+ // Epoch info for next update (stateless hints)
1284
+ epoch: z.object({
1285
+ start: z.string(), // Stringified bigint
1286
+ level: z.number(),
1287
+ }),
1288
+ timestamp: z.string(), // Stringified bigint
1289
+ })
1290
+
1291
+ export const FeedGetOwnerResponseMessageSchema = z.object({
1292
+ type: z.literal("feedGetOwnerResponse"),
1293
+ requestId: z.string(),
1294
+ owner: AddressSchema,
1295
+ })
1296
+
1297
+ export const SequentialFeedGetOwnerResponseMessageSchema = z.object({
1298
+ type: z.literal("seqFeedGetOwnerResponse"),
1299
+ requestId: z.string(),
1300
+ owner: AddressSchema,
1301
+ })
1302
+
1303
+ export const SequentialFeedDownloadPayloadResponseMessageSchema = z.object({
1304
+ type: z.literal("seqFeedDownloadPayloadResponse"),
1305
+ requestId: z.string(),
1306
+ payload: z.instanceof(Uint8Array),
1307
+ timestamp: z.number().optional(),
1308
+ feedIndex: z.string(),
1309
+ feedIndexNext: z.string(),
1310
+ })
1311
+
1312
+ export const SequentialFeedDownloadRawPayloadResponseMessageSchema = z.object({
1313
+ type: z.literal("seqFeedDownloadRawPayloadResponse"),
1314
+ requestId: z.string(),
1315
+ payload: z.instanceof(Uint8Array),
1316
+ timestamp: z.number().optional(),
1317
+ feedIndex: z.string(),
1318
+ feedIndexNext: z.string(),
1319
+ })
1320
+
1321
+ export const SequentialFeedDownloadReferenceResponseMessageSchema = z.object({
1322
+ type: z.literal("seqFeedDownloadReferenceResponse"),
1323
+ requestId: z.string(),
1324
+ reference: ReferenceSchema,
1325
+ feedIndex: z.string(),
1326
+ feedIndexNext: z.string(),
1327
+ })
1328
+
1329
+ export const SequentialFeedUploadPayloadResponseMessageSchema = z.object({
1330
+ type: z.literal("seqFeedUploadPayloadResponse"),
1331
+ requestId: z.string(),
1332
+ reference: ReferenceSchema,
1333
+ feedIndex: z.string(),
1334
+ owner: AddressSchema,
1335
+ encryptionKey: z.string().optional(),
1336
+ tagUid: z.number().optional(),
1337
+ })
1338
+
1339
+ export const SequentialFeedUploadRawPayloadResponseMessageSchema = z.object({
1340
+ type: z.literal("seqFeedUploadRawPayloadResponse"),
1341
+ requestId: z.string(),
1342
+ reference: ReferenceSchema,
1343
+ feedIndex: z.string(),
1344
+ owner: AddressSchema,
1345
+ encryptionKey: z.string().optional(),
1346
+ tagUid: z.number().optional(),
1347
+ })
1348
+
1349
+ export const SequentialFeedUploadReferenceResponseMessageSchema = z.object({
1350
+ type: z.literal("seqFeedUploadReferenceResponse"),
1351
+ requestId: z.string(),
1352
+ reference: ReferenceSchema,
1353
+ feedIndex: z.string(),
1354
+ owner: AddressSchema,
1355
+ encryptionKey: z.string().optional(),
1356
+ tagUid: z.number().optional(),
1357
+ })
1358
+
1359
+ // Feed Manifest Response Schema
1360
+ export const CreateFeedManifestResponseMessageSchema = z.object({
1361
+ type: z.literal("createFeedManifestResponse"),
1362
+ requestId: z.string(),
1363
+ reference: ReferenceSchema,
1364
+ })
1365
+
1366
+ // ACT Response Message Schemas
1367
+ export const ActUploadDataResponseMessageSchema = z.object({
1368
+ type: z.literal("actUploadDataResponse"),
1369
+ requestId: z.string(),
1370
+ encryptedReference: ReferenceSchema,
1371
+ historyReference: ReferenceSchema,
1372
+ granteeListReference: ReferenceSchema,
1373
+ publisherPubKey: z.string(), // Compressed public key
1374
+ actReference: ReferenceSchema,
1375
+ tagUid: z.number().optional(),
1376
+ })
1377
+
1378
+ export const ActDownloadDataResponseMessageSchema = z.object({
1379
+ type: z.literal("actDownloadDataResponse"),
1380
+ requestId: z.string(),
1381
+ data: z.instanceof(Uint8Array),
1382
+ })
1383
+
1384
+ export const ActAddGranteesResponseMessageSchema = z.object({
1385
+ type: z.literal("actAddGranteesResponse"),
1386
+ requestId: z.string(),
1387
+ historyReference: ReferenceSchema,
1388
+ granteeListReference: ReferenceSchema,
1389
+ actReference: ReferenceSchema,
1390
+ })
1391
+
1392
+ export const ActRevokeGranteesResponseMessageSchema = z.object({
1393
+ type: z.literal("actRevokeGranteesResponse"),
1394
+ requestId: z.string(),
1395
+ encryptedReference: ReferenceSchema,
1396
+ historyReference: ReferenceSchema,
1397
+ granteeListReference: ReferenceSchema,
1398
+ actReference: ReferenceSchema,
1399
+ })
1400
+
1401
+ export const ActGetGranteesResponseMessageSchema = z.object({
1402
+ type: z.literal("actGetGranteesResponse"),
1403
+ requestId: z.string(),
1404
+ grantees: z.array(z.string()),
1405
+ })
1406
+
1407
+ export const GetPostageBatchResponseMessageSchema = z.object({
1408
+ type: z.literal("getPostageBatchResponse"),
1409
+ requestId: z.string(),
1410
+ postageBatch: PostageBatchSchema.optional(),
1411
+ error: z.string().optional(),
1412
+ })
1413
+
1414
+ export const IframeToParentMessageSchema = z.discriminatedUnion("type", [
1415
+ ProxyReadyMessageSchema,
1416
+ InitErrorMessageSchema,
1417
+ AuthStatusResponseMessageSchema,
1418
+ DisconnectResponseMessageSchema,
1419
+ AuthSuccessMessageSchema,
1420
+ UploadDataResponseMessageSchema,
1421
+ DownloadDataResponseMessageSchema,
1422
+ UploadFileResponseMessageSchema,
1423
+ DownloadFileResponseMessageSchema,
1424
+ UploadChunkResponseMessageSchema,
1425
+ DownloadChunkResponseMessageSchema,
1426
+ UploadProgressMessageSchema,
1427
+ ErrorMessageSchema,
1428
+ ConnectionInfoResponseMessageSchema,
1429
+ ConnectResponseMessageSchema,
1430
+ IsConnectedResponseMessageSchema,
1431
+ GetNodeInfoResponseMessageSchema,
1432
+ GsocMineResponseMessageSchema,
1433
+ GsocSendResponseMessageSchema,
1434
+ SocUploadResponseMessageSchema,
1435
+ SocRawUploadResponseMessageSchema,
1436
+ SocDownloadResponseMessageSchema,
1437
+ SocRawDownloadResponseMessageSchema,
1438
+ SocGetOwnerResponseMessageSchema,
1439
+ EpochFeedDownloadReferenceResponseMessageSchema,
1440
+ EpochFeedUploadReferenceResponseMessageSchema,
1441
+ FeedGetOwnerResponseMessageSchema,
1442
+ SequentialFeedGetOwnerResponseMessageSchema,
1443
+ SequentialFeedDownloadPayloadResponseMessageSchema,
1444
+ SequentialFeedDownloadRawPayloadResponseMessageSchema,
1445
+ SequentialFeedDownloadReferenceResponseMessageSchema,
1446
+ SequentialFeedUploadPayloadResponseMessageSchema,
1447
+ SequentialFeedUploadRawPayloadResponseMessageSchema,
1448
+ SequentialFeedUploadReferenceResponseMessageSchema,
1449
+ CreateFeedManifestResponseMessageSchema,
1450
+ ActUploadDataResponseMessageSchema,
1451
+ ActDownloadDataResponseMessageSchema,
1452
+ ActAddGranteesResponseMessageSchema,
1453
+ ActRevokeGranteesResponseMessageSchema,
1454
+ ActGetGranteesResponseMessageSchema,
1455
+ GetPostageBatchResponseMessageSchema,
1456
+ ])
1457
+
1458
+ export type ProxyReadyMessage = z.infer<typeof ProxyReadyMessageSchema>
1459
+ export type InitErrorMessage = z.infer<typeof InitErrorMessageSchema>
1460
+ export type AuthStatusResponseMessage = z.infer<
1461
+ typeof AuthStatusResponseMessageSchema
1462
+ >
1463
+ export type DisconnectResponseMessage = z.infer<
1464
+ typeof DisconnectResponseMessageSchema
1465
+ >
1466
+ export type AuthSuccessMessage = z.infer<typeof AuthSuccessMessageSchema>
1467
+ export type UploadDataResponseMessage = z.infer<
1468
+ typeof UploadDataResponseMessageSchema
1469
+ >
1470
+ export type DownloadDataResponseMessage = z.infer<
1471
+ typeof DownloadDataResponseMessageSchema
1472
+ >
1473
+ export type UploadFileResponseMessage = z.infer<
1474
+ typeof UploadFileResponseMessageSchema
1475
+ >
1476
+ export type DownloadFileResponseMessage = z.infer<
1477
+ typeof DownloadFileResponseMessageSchema
1478
+ >
1479
+ export type UploadChunkResponseMessage = z.infer<
1480
+ typeof UploadChunkResponseMessageSchema
1481
+ >
1482
+ export type DownloadChunkResponseMessage = z.infer<
1483
+ typeof DownloadChunkResponseMessageSchema
1484
+ >
1485
+ export type UploadProgressMessage = z.infer<typeof UploadProgressMessageSchema>
1486
+ export type ErrorMessage = z.infer<typeof ErrorMessageSchema>
1487
+ export type ConnectionInfoResponseMessage = z.infer<
1488
+ typeof ConnectionInfoResponseMessageSchema
1489
+ >
1490
+ export type ConnectResponseMessage = z.infer<
1491
+ typeof ConnectResponseMessageSchema
1492
+ >
1493
+ export type IsConnectedResponseMessage = z.infer<
1494
+ typeof IsConnectedResponseMessageSchema
1495
+ >
1496
+ export type GetNodeInfoResponseMessage = z.infer<
1497
+ typeof GetNodeInfoResponseMessageSchema
1498
+ >
1499
+ export type GsocMineResponseMessage = z.infer<
1500
+ typeof GsocMineResponseMessageSchema
1501
+ >
1502
+ export type GsocSendResponseMessage = z.infer<
1503
+ typeof GsocSendResponseMessageSchema
1504
+ >
1505
+ export type SocUploadResponseMessage = z.infer<
1506
+ typeof SocUploadResponseMessageSchema
1507
+ >
1508
+ export type SocRawUploadResponseMessage = z.infer<
1509
+ typeof SocRawUploadResponseMessageSchema
1510
+ >
1511
+ export type SocDownloadResponseMessage = z.infer<
1512
+ typeof SocDownloadResponseMessageSchema
1513
+ >
1514
+ export type SocRawDownloadResponseMessage = z.infer<
1515
+ typeof SocRawDownloadResponseMessageSchema
1516
+ >
1517
+ export type SocGetOwnerResponseMessage = z.infer<
1518
+ typeof SocGetOwnerResponseMessageSchema
1519
+ >
1520
+ export type EpochFeedDownloadReferenceResponseMessage = z.infer<
1521
+ typeof EpochFeedDownloadReferenceResponseMessageSchema
1522
+ >
1523
+ export type EpochFeedUploadReferenceResponseMessage = z.infer<
1524
+ typeof EpochFeedUploadReferenceResponseMessageSchema
1525
+ >
1526
+ export type FeedGetOwnerResponseMessage = z.infer<
1527
+ typeof FeedGetOwnerResponseMessageSchema
1528
+ >
1529
+ export type SequentialFeedGetOwnerResponseMessage = z.infer<
1530
+ typeof SequentialFeedGetOwnerResponseMessageSchema
1531
+ >
1532
+ export type SequentialFeedDownloadPayloadResponseMessage = z.infer<
1533
+ typeof SequentialFeedDownloadPayloadResponseMessageSchema
1534
+ >
1535
+ export type SequentialFeedDownloadRawPayloadResponseMessage = z.infer<
1536
+ typeof SequentialFeedDownloadRawPayloadResponseMessageSchema
1537
+ >
1538
+ export type SequentialFeedDownloadReferenceResponseMessage = z.infer<
1539
+ typeof SequentialFeedDownloadReferenceResponseMessageSchema
1540
+ >
1541
+ export type SequentialFeedUploadPayloadResponseMessage = z.infer<
1542
+ typeof SequentialFeedUploadPayloadResponseMessageSchema
1543
+ >
1544
+ export type SequentialFeedUploadRawPayloadResponseMessage = z.infer<
1545
+ typeof SequentialFeedUploadRawPayloadResponseMessageSchema
1546
+ >
1547
+ export type SequentialFeedUploadReferenceResponseMessage = z.infer<
1548
+ typeof SequentialFeedUploadReferenceResponseMessageSchema
1549
+ >
1550
+ export type CreateFeedManifestResponseMessage = z.infer<
1551
+ typeof CreateFeedManifestResponseMessageSchema
1552
+ >
1553
+ export type ActUploadDataResponseMessage = z.infer<
1554
+ typeof ActUploadDataResponseMessageSchema
1555
+ >
1556
+ export type ActDownloadDataResponseMessage = z.infer<
1557
+ typeof ActDownloadDataResponseMessageSchema
1558
+ >
1559
+ export type ActAddGranteesResponseMessage = z.infer<
1560
+ typeof ActAddGranteesResponseMessageSchema
1561
+ >
1562
+ export type ActRevokeGranteesResponseMessage = z.infer<
1563
+ typeof ActRevokeGranteesResponseMessageSchema
1564
+ >
1565
+ export type ActGetGranteesResponseMessage = z.infer<
1566
+ typeof ActGetGranteesResponseMessageSchema
1567
+ >
1568
+ export type GetPostageBatchResponseMessage = z.infer<
1569
+ typeof GetPostageBatchResponseMessageSchema
1570
+ >
1571
+ export type IframeToParentMessage = z.infer<typeof IframeToParentMessageSchema>
1572
+
1573
+ // ============================================================================
1574
+ // Message Types: Popup → Iframe
1575
+ // ============================================================================
1576
+
1577
+ export const AuthDataSchema = z.object({
1578
+ secret: z.string(),
1579
+ postageBatchId: BatchIdSchema.optional(),
1580
+ signerKey: PrivateKeySchema.optional(),
1581
+ networkSettings: NetworkSettingsSchemaV1.optional(),
1582
+ identityId: z.string().optional(),
1583
+ identityName: z.string().optional(),
1584
+ identityAddress: AddressSchema.optional(),
1585
+ })
1586
+
1587
+ export type AuthData = z.infer<typeof AuthDataSchema>
1588
+
1589
+ export const SetSecretMessageSchema = z.object({
1590
+ type: z.literal("setSecret"),
1591
+ appOrigin: z.string(),
1592
+ challenge: z.string(),
1593
+ data: AuthDataSchema,
1594
+ })
1595
+
1596
+ export const PopupToIframeMessageSchema = z.discriminatedUnion("type", [
1597
+ SetSecretMessageSchema,
1598
+ ])
1599
+
1600
+ export type SetSecretMessage = z.infer<typeof SetSecretMessageSchema>
1601
+ export type PopupToIframeMessage = z.infer<typeof PopupToIframeMessageSchema>
1602
+
1603
+ // ============================================================================
1604
+ // Client Configuration
1605
+ // ============================================================================
1606
+
1607
+ export interface ClientOptions {
1608
+ iframeOrigin: string
1609
+ iframePath?: string
1610
+ timeout?: number
1611
+ initializationTimeout?: number
1612
+ onAuthChange?: (authenticated: boolean) => void
1613
+ popupMode?: "popup" | "window" // Default: 'window'
1614
+ metadata: AppMetadata
1615
+ buttonConfig?: ButtonConfig
1616
+ containerId?: string // ID of container element to place iframe in (optional)
1617
+ }
1618
+
1619
+ export interface AuthOptions {
1620
+ masterKeyStorageKey?: string
1621
+ }
1622
+
1623
+ /**
1624
+ * Configuration options for the connect() method.
1625
+ */
1626
+ export interface ConnectOptions {
1627
+ /**
1628
+ * When true, shows the agent sign-up option on the connect page.
1629
+ * Agents are automated services that can perform operations on behalf of users.
1630
+ */
1631
+ agent?: boolean
1632
+ /**
1633
+ * Override popup mode for this connect call.
1634
+ * "popup" opens a sized popup window, "window" opens a full browser tab.
1635
+ */
1636
+ popupMode?: "popup" | "window"
1637
+ }
1638
+
1639
+ // ============================================================================
1640
+ // Entity Types (derived from Zod schemas for type safety)
1641
+ // ============================================================================
1642
+
1643
+ export type {
1644
+ PasskeyAccount,
1645
+ EthereumAccount,
1646
+ AgentAccount,
1647
+ Account,
1648
+ Identity,
1649
+ ConnectedApp,
1650
+ PostageStamp,
1651
+ } from "./schemas"