@tinycloudlabs/web-sdk 0.2.1 → 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 (69) hide show
  1. package/LICENSE.md +320 -0
  2. package/dist/625.index.js +1 -0
  3. package/dist/authorization/WebSpaceCreationHandler.d.ts +40 -0
  4. package/dist/authorization/WebSpaceCreationHandler.d.ts.map +1 -0
  5. package/dist/authorization/WebUserAuthorization.d.ts +295 -0
  6. package/dist/authorization/WebUserAuthorization.d.ts.map +1 -0
  7. package/dist/authorization/index.d.ts +12 -0
  8. package/dist/authorization/index.d.ts.map +1 -0
  9. package/dist/delegation.d.ts +85 -0
  10. package/dist/delegation.d.ts.map +1 -0
  11. package/dist/index.d.ts +12 -10
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +1 -1
  14. package/dist/modules/Storage/index.d.ts +1 -2
  15. package/dist/modules/Storage/index.d.ts.map +1 -1
  16. package/dist/modules/Storage/tinycloud/KVServiceAdapter.d.ts +24 -0
  17. package/dist/modules/Storage/tinycloud/KVServiceAdapter.d.ts.map +1 -0
  18. package/dist/modules/Storage/tinycloud/index.d.ts +1 -4
  19. package/dist/modules/Storage/tinycloud/index.d.ts.map +1 -1
  20. package/dist/modules/Storage/tinycloud/module.d.ts +1 -1
  21. package/dist/modules/Storage/tinycloud/types.d.ts +7 -9
  22. package/dist/modules/Storage/tinycloud/types.d.ts.map +1 -1
  23. package/dist/modules/Storage/tinycloud/types.schema.d.ts +159 -0
  24. package/dist/modules/Storage/tinycloud/types.schema.d.ts.map +1 -0
  25. package/dist/modules/UserAuthorization.d.ts +191 -58
  26. package/dist/modules/UserAuthorization.d.ts.map +1 -1
  27. package/dist/modules/WasmInitializer.d.ts +26 -0
  28. package/dist/modules/WasmInitializer.d.ts.map +1 -0
  29. package/dist/modules/index.d.ts +1 -0
  30. package/dist/modules/index.d.ts.map +1 -1
  31. package/dist/modules/keys/WasmKeyProvider.d.ts +126 -0
  32. package/dist/modules/keys/WasmKeyProvider.d.ts.map +1 -0
  33. package/dist/modules/keys/index.d.ts +7 -0
  34. package/dist/modules/keys/index.d.ts.map +1 -0
  35. package/dist/modules/registry/Registry.d.ts +59 -0
  36. package/dist/modules/registry/Registry.d.ts.map +1 -0
  37. package/dist/modules/tcw.d.ts +649 -53
  38. package/dist/modules/tcw.d.ts.map +1 -1
  39. package/dist/notifications/ModalManager.d.ts +6 -3
  40. package/dist/notifications/ModalManager.d.ts.map +1 -1
  41. package/dist/notifications/NodeSelectionModal.d.ts +29 -0
  42. package/dist/notifications/NodeSelectionModal.d.ts.map +1 -0
  43. package/dist/notifications/{OrbitCreationModal.d.ts → SpaceCreationModal.d.ts} +8 -8
  44. package/dist/notifications/{OrbitCreationModal.d.ts.map → SpaceCreationModal.d.ts.map} +1 -1
  45. package/dist/notifications/index.d.ts +3 -2
  46. package/dist/notifications/index.d.ts.map +1 -1
  47. package/dist/notifications/types.schema.d.ts +224 -0
  48. package/dist/notifications/types.schema.d.ts.map +1 -0
  49. package/dist/utils/debug.d.ts +9 -0
  50. package/dist/utils/debug.d.ts.map +1 -0
  51. package/dist/utils/multiaddr.d.ts +36 -0
  52. package/dist/utils/multiaddr.d.ts.map +1 -0
  53. package/package.json +14 -6
  54. package/dist/modules/Storage/TinyCloudStorage.d.ts +0 -182
  55. package/dist/modules/Storage/TinyCloudStorage.d.ts.map +0 -1
  56. package/dist/modules/Storage/interfaces.d.ts +0 -119
  57. package/dist/modules/Storage/interfaces.d.ts.map +0 -1
  58. package/dist/modules/Storage/tinycloud/authenticator.d.ts +0 -12
  59. package/dist/modules/Storage/tinycloud/authenticator.d.ts.map +0 -1
  60. package/dist/modules/Storage/tinycloud/capabilities.d.ts +0 -25
  61. package/dist/modules/Storage/tinycloud/capabilities.d.ts.map +0 -1
  62. package/dist/modules/Storage/tinycloud/kv.d.ts +0 -18
  63. package/dist/modules/Storage/tinycloud/kv.d.ts.map +0 -1
  64. package/dist/modules/Storage/tinycloud/orbit.d.ts +0 -167
  65. package/dist/modules/Storage/tinycloud/orbit.d.ts.map +0 -1
  66. package/dist/modules/Storage/tinycloud/tinycloud.d.ts +0 -43
  67. package/dist/modules/Storage/tinycloud/tinycloud.d.ts.map +0 -1
  68. package/dist/modules/Storage/tinycloud/walletProvider.d.ts +0 -19
  69. package/dist/modules/Storage/tinycloud/walletProvider.d.ts.map +0 -1
@@ -1,3 +1,2 @@
1
- export * from './TinyCloudStorage';
2
- export * from './interfaces';
1
+ export * from './tinycloud';
3
2
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/modules/Storage/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/modules/Storage/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC"}
@@ -0,0 +1,24 @@
1
+ import { IKVService } from "@tinycloudlabs/sdk-core";
2
+ import { Session } from "./types";
3
+ /**
4
+ * Create a KVService instance from web-sdk Session.
5
+ *
6
+ * This adapter bridges the web-sdk Session type to the sdk-core KVService,
7
+ * allowing platform-agnostic code to use the shared KV service implementation.
8
+ *
9
+ * @param host - The TinyCloud host URL
10
+ * @param session - The web-sdk Session
11
+ * @returns An IKVService instance
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * const session = await tinycloud.space();
16
+ * const kvService = createKVService("https://tinycloud.example.com", session);
17
+ *
18
+ * // Use the KV service
19
+ * await kvService.put("key", { data: "value" });
20
+ * const result = await kvService.get("key");
21
+ * ```
22
+ */
23
+ export declare function createKVService(host: string, session: Session): IKVService;
24
+ //# sourceMappingURL=KVServiceAdapter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"KVServiceAdapter.d.ts","sourceRoot":"","sources":["../../../../src/modules/Storage/tinycloud/KVServiceAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,UAAU,EAAkB,MAAM,yBAAyB,CAAC;AAEhF,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAElC;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,UAAU,CAc1E"}
@@ -1,6 +1,3 @@
1
- export { TinyCloud, TinyCloudOptions } from './tinycloud';
2
- export { OrbitConnection, Request, Response, hostOrbit } from './orbit';
3
- export { Bytes, WalletProvider } from './walletProvider';
4
- export { activateSession } from './authenticator';
5
1
  export { SessionConfig, Session, HostConfig } from './types';
2
+ export { createKVService } from './KVServiceAdapter';
6
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/modules/Storage/tinycloud/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AACxE,OAAO,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/modules/Storage/tinycloud/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { tinycloud } from '@tinycloudlabs/web-sdk-wasm';
2
2
  type TinyCloudModule = typeof tinycloud;
3
- export declare const makeOrbitId: TinyCloudModule['makeOrbitId'];
3
+ export declare const makeSpaceId: TinyCloudModule['makeSpaceId'];
4
4
  export declare const prepareSession: TinyCloudModule['prepareSession'];
5
5
  export declare const completeSessionSetup: TinyCloudModule['completeSessionSetup'];
6
6
  export declare const invoke: TinyCloudModule['invoke'];
@@ -16,8 +16,8 @@ export type SessionConfig = {
16
16
  domain: string;
17
17
  /** Current time for SIWE message. */
18
18
  issuedAt: string;
19
- /** The orbit that is the target resource of the delegation. */
20
- orbitId: string;
19
+ /** The space that is the target resource of the delegation. */
20
+ spaceId: string;
21
21
  /** The earliest time that the session will be valid from. */
22
22
  notBefore?: string;
23
23
  /** The latest time that the session will be valid until. */
@@ -39,15 +39,13 @@ export type Session = {
39
39
  delegationCid: string;
40
40
  /** The session key. */
41
41
  jwk: object;
42
- /** The namespace the orbit is in */
43
- namespace: string;
44
- /** The orbit that the session key is permitted to perform actions against. */
45
- orbitId: string;
42
+ /** The space that the session key is permitted to perform actions against. */
43
+ spaceId: string;
46
44
  /** The verification method of the session key. */
47
45
  verificationMethod: string;
48
46
  };
49
47
  /**
50
- * Configuration object for generating a Orbit Host Delegation SIWE message.
48
+ * Configuration object for generating a Space Host Delegation SIWE message.
51
49
  */
52
50
  export type HostConfig = {
53
51
  /** Ethereum address. */
@@ -58,8 +56,8 @@ export type HostConfig = {
58
56
  domain: string;
59
57
  /** Current time for SIWE message. */
60
58
  issuedAt: string;
61
- /** The orbit that is the target resource of the delegation. */
62
- orbitId: string;
59
+ /** The space that is the target resource of the delegation. */
60
+ spaceId: string;
63
61
  /** The peer that is the target/invoker in the delegation. */
64
62
  peerId: string;
65
63
  };
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/modules/Storage/tinycloud/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG;IAC1B,+FAA+F;IAC/F,OAAO,EAAE;QAAE,CAAC,OAAO,EAAE,MAAM,GAAG;YAAE,CAAC,GAAG,EAAE,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O,EAAE,MAAM,CAAC;IAChB,6DAA6D;IAC7D,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC"}
@@ -0,0 +1,159 @@
1
+ /**
2
+ * Zod schemas for TinyCloud storage session and configuration types.
3
+ *
4
+ * These schemas provide runtime validation for session configuration,
5
+ * active sessions, and host configuration. Types are derived from
6
+ * schemas using z.infer<>.
7
+ *
8
+ * @packageDocumentation
9
+ */
10
+ import { z } from "zod";
11
+ /**
12
+ * Configuration object for starting a TinyCloud session.
13
+ */
14
+ export declare const SessionConfigSchema: z.ZodObject<{
15
+ /** Actions that the session key will be permitted to perform, organized by service and path */
16
+ actions: z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString, "many">>>;
17
+ /** Ethereum address. */
18
+ address: z.ZodString;
19
+ /** Chain ID. */
20
+ chainId: z.ZodNumber;
21
+ /** Domain of the webpage. */
22
+ domain: z.ZodString;
23
+ /** Current time for SIWE message (ISO 8601 format). */
24
+ issuedAt: z.ZodString;
25
+ /** The space that is the target resource of the delegation. */
26
+ spaceId: z.ZodString;
27
+ /** The earliest time that the session will be valid from. */
28
+ notBefore: z.ZodOptional<z.ZodString>;
29
+ /** The latest time that the session will be valid until. */
30
+ expirationTime: z.ZodString;
31
+ /** Optional parent delegations to inherit and attenuate */
32
+ parents: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
33
+ /** Optional jwk to delegate to */
34
+ jwk: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
35
+ }, "strip", z.ZodTypeAny, {
36
+ spaceId?: string;
37
+ actions?: Record<string, Record<string, string[]>>;
38
+ address?: string;
39
+ chainId?: number;
40
+ domain?: string;
41
+ issuedAt?: string;
42
+ expirationTime?: string;
43
+ notBefore?: string;
44
+ jwk?: Record<string, unknown>;
45
+ parents?: string[];
46
+ }, {
47
+ spaceId?: string;
48
+ actions?: Record<string, Record<string, string[]>>;
49
+ address?: string;
50
+ chainId?: number;
51
+ domain?: string;
52
+ issuedAt?: string;
53
+ expirationTime?: string;
54
+ notBefore?: string;
55
+ jwk?: Record<string, unknown>;
56
+ parents?: string[];
57
+ }>;
58
+ export type SessionConfig = z.infer<typeof SessionConfigSchema>;
59
+ /**
60
+ * A TinyCloud session.
61
+ */
62
+ export declare const SessionSchema: z.ZodObject<{
63
+ /** The delegation from the user to the session key. */
64
+ delegationHeader: z.ZodObject<{
65
+ Authorization: z.ZodString;
66
+ }, "strip", z.ZodTypeAny, {
67
+ Authorization?: string;
68
+ }, {
69
+ Authorization?: string;
70
+ }>;
71
+ /** The delegation reference from the user to the session key. */
72
+ delegationCid: z.ZodString;
73
+ /** The session key (JWK format). */
74
+ jwk: z.ZodRecord<z.ZodString, z.ZodUnknown>;
75
+ /** The space that the session key is permitted to perform actions against. */
76
+ spaceId: z.ZodString;
77
+ /** The verification method of the session key. */
78
+ verificationMethod: z.ZodString;
79
+ }, "strip", z.ZodTypeAny, {
80
+ spaceId?: string;
81
+ delegationHeader?: {
82
+ Authorization?: string;
83
+ };
84
+ jwk?: Record<string, unknown>;
85
+ delegationCid?: string;
86
+ verificationMethod?: string;
87
+ }, {
88
+ spaceId?: string;
89
+ delegationHeader?: {
90
+ Authorization?: string;
91
+ };
92
+ jwk?: Record<string, unknown>;
93
+ delegationCid?: string;
94
+ verificationMethod?: string;
95
+ }>;
96
+ export type Session = z.infer<typeof SessionSchema>;
97
+ /**
98
+ * Configuration object for generating a Space Host Delegation SIWE message.
99
+ */
100
+ export declare const HostConfigSchema: z.ZodObject<{
101
+ /** Ethereum address. */
102
+ address: z.ZodString;
103
+ /** Chain ID. */
104
+ chainId: z.ZodNumber;
105
+ /** Domain of the webpage. */
106
+ domain: z.ZodString;
107
+ /** Current time for SIWE message (ISO 8601 format). */
108
+ issuedAt: z.ZodString;
109
+ /** The space that is the target resource of the delegation. */
110
+ spaceId: z.ZodString;
111
+ /** The peer that is the target/invoker in the delegation. */
112
+ peerId: z.ZodString;
113
+ }, "strip", z.ZodTypeAny, {
114
+ spaceId?: string;
115
+ address?: string;
116
+ chainId?: number;
117
+ domain?: string;
118
+ issuedAt?: string;
119
+ peerId?: string;
120
+ }, {
121
+ spaceId?: string;
122
+ address?: string;
123
+ chainId?: number;
124
+ domain?: string;
125
+ issuedAt?: string;
126
+ peerId?: string;
127
+ }>;
128
+ export type HostConfig = z.infer<typeof HostConfigSchema>;
129
+ /**
130
+ * Validation error type.
131
+ */
132
+ export interface ValidationError {
133
+ code: string;
134
+ message: string;
135
+ issues?: unknown[];
136
+ }
137
+ /**
138
+ * Result type for validation operations.
139
+ */
140
+ export type ValidationResult<T> = {
141
+ ok: true;
142
+ data: T;
143
+ } | {
144
+ ok: false;
145
+ error: ValidationError;
146
+ };
147
+ /**
148
+ * Validates SessionConfig.
149
+ */
150
+ export declare function validateSessionConfig(data: unknown): ValidationResult<SessionConfig>;
151
+ /**
152
+ * Validates Session.
153
+ */
154
+ export declare function validateSession(data: unknown): ValidationResult<Session>;
155
+ /**
156
+ * Validates HostConfig.
157
+ */
158
+ export declare function validateHostConfig(data: unknown): ValidationResult<HostConfig>;
159
+ //# sourceMappingURL=types.schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.schema.d.ts","sourceRoot":"","sources":["../../../../src/modules/Storage/tinycloud/types.schema.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAMxB;;GAEG;AACH,eAAO,MAAM,mBAAmB;IAC9B,+FAA+F;;IAE/F,wBAAwB;;IAExB,gBAAgB;;IAEhB,6BAA6B;;IAE7B,uDAAuD;;IAEvD,+DAA+D;;IAE/D,6DAA6D;;IAE7D,4DAA4D;;IAE5D,2DAA2D;;IAE3D,kCAAkC;;;;;;;;;;;;;;;;;;;;;;;;EAElC,CAAC;AAEH,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,mBAAmB,CAAC,CAAC;AAMhE;;GAEG;AACH,eAAO,MAAM,aAAa;IACxB,uDAAuD;;;;;;;;IAIvD,iEAAiE;;IAEjE,oCAAoC;;IAEpC,8EAA8E;;IAE9E,kDAAkD;;;;;;;;;;;;;;;;;;EAElD,CAAC;AAEH,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AAMpD;;GAEG;AACH,eAAO,MAAM,gBAAgB;IAC3B,wBAAwB;;IAExB,gBAAgB;;IAEhB,6BAA6B;;IAE7B,uDAAuD;;IAEvD,+DAA+D;;IAE/D,6DAA6D;;;;;;;;;;;;;;;;EAE7D,CAAC;AAEH,MAAM,MAAM,UAAU,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,gBAAgB,CAAC,CAAC;AAM1D;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,OAAO,EAAE,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,MAAM,gBAAgB,CAAC,CAAC,IAC1B;IAAE,EAAE,EAAE,IAAI,CAAC;IAAC,IAAI,EAAE,CAAC,CAAA;CAAE,GACrB;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,eAAe,CAAA;CAAE,CAAC;AAE1C;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,OAAO,GAAG,gBAAgB,CAAC,aAAa,CAAC,CAapF;AAED;;GAEG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,OAAO,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAaxE;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,OAAO,GAAG,gBAAgB,CAAC,UAAU,CAAC,CAa9E"}
@@ -1,21 +1,38 @@
1
- import { providers, Signer } from 'ethers';
2
- import { tcwSession } from '@tinycloudlabs/web-sdk-wasm';
3
- import { AxiosInstance } from 'axios';
4
- import { SiweMessage } from 'siwe';
5
- import { TCWEnsData } from '@tinycloudlabs/web-core';
6
- import { TCWClientSession, TCWClientConfig, ITCWConnected, TCWExtension } from '@tinycloudlabs/web-core/client';
1
+ import { providers, Signer } from "ethers";
2
+ import { tcwSession } from "@tinycloudlabs/web-sdk-wasm";
3
+ import { AxiosInstance } from "axios";
4
+ import { SiweMessage } from "siwe";
5
+ import { EnsData } from "@tinycloudlabs/web-core";
6
+ import type { ClientSession, ClientConfig, IConnected, Extension } from "@tinycloudlabs/web-core/client";
7
+ import { IUserAuthorization as ICoreUserAuthorization, PartialSiweMessage } from "@tinycloudlabs/sdk-core";
8
+ import { Session } from "./Storage/tinycloud";
9
+ /**
10
+ * Extended Client Config with TinyCloud options
11
+ */
12
+ declare module "@tinycloudlabs/web-core/client" {
13
+ interface ClientConfig {
14
+ /** Whether to automatically create space if it doesn't exist (default: true) */
15
+ autoCreateSpace?: boolean;
16
+ /** TinyCloud server endpoints (default: ["https://node.tinycloud.xyz"]) */
17
+ tinycloudHosts?: string[];
18
+ /** Space prefix for new sessions (default: "default") */
19
+ spacePrefix?: string;
20
+ }
21
+ }
7
22
  /**
8
23
  * Interface for tracking session state during SIWE message generation
9
24
  */
10
25
  interface PendingSession {
11
- /** Instance of TCWSessionManager */
12
- sessionManager: tcwSession.TCWSessionManager;
26
+ /** Instance of SessionManager (null if consumed by build()) */
27
+ sessionManager: tcwSession.TCWSessionManager | null;
28
+ /** Session key JWK string (stored before build() consumes sessionManager) */
29
+ sessionKey?: string;
13
30
  /** Ethereum address for the session */
14
31
  address: string;
15
32
  /** Timestamp when session was generated */
16
33
  generatedAt: number;
17
34
  /** Extensions that were applied to the session */
18
- extensions: TCWExtension[];
35
+ extensions: Extension[];
19
36
  }
20
37
  /** UserAuthorization Module
21
38
  *
@@ -29,19 +46,19 @@ interface PendingSession {
29
46
  */
30
47
  interface IUserAuthorization {
31
48
  provider: providers.Web3Provider;
32
- session?: TCWClientSession;
33
- extend: (extension: TCWExtension) => void;
49
+ session?: ClientSession;
50
+ extend: (extension: Extension) => void;
34
51
  connect(): Promise<any>;
35
52
  signIn(): Promise<any>;
36
53
  /**
37
- * ENS data supported by TCW.
54
+ * ENS data supported by the SDK.
38
55
  * @param address - User address.
39
56
  * @param resolveEnsOpts - Options to resolve ENS.
40
57
  * @returns Object containing ENS data.
41
58
  */
42
59
  resolveEns(
43
60
  /** User address */
44
- address: string): Promise<TCWEnsData>;
61
+ address: string): Promise<EnsData>;
45
62
  address(): string | undefined;
46
63
  chainId(): number | undefined;
47
64
  /**
@@ -54,41 +71,62 @@ interface IUserAuthorization {
54
71
  /**
55
72
  * Generates a SIWE message for authentication with session key capabilities.
56
73
  * @param address - Ethereum address performing the signing
57
- * @param partialSiweMessage - Optional partial SIWE message to override defaults
74
+ * @param partial - Optional partial SIWE message to override defaults
58
75
  * @returns SiweMessage object ready for signing
59
76
  */
60
- generateSiweMessage(address: string, partialSiweMessage?: Partial<SiweMessage>): Promise<SiweMessage>;
77
+ generateSiweMessage(address: string, partial?: PartialSiweMessage): Promise<SiweMessage>;
61
78
  /**
62
79
  * Sign in to the SDK using a pre-signed SIWE message.
63
80
  * @param siweMessage - The SIWE message that was generated
64
81
  * @param signature - The signature of the SIWE message
65
- * @returns Promise with the TCWClientSession object
82
+ * @returns Promise with the ClientSession object
83
+ */
84
+ signInWithSignature(siweMessage: SiweMessage, signature: string): Promise<ClientSession>;
85
+ /**
86
+ * Get the space ID for the current session.
87
+ * @returns Space ID or undefined if not available
66
88
  */
67
- signInWithSignature(siweMessage: SiweMessage, signature: string): Promise<TCWClientSession>;
89
+ getSpaceId(): string | undefined;
90
+ /**
91
+ * Get the configured TinyCloud host URLs.
92
+ * @returns Array of TinyCloud host URLs
93
+ */
94
+ getTinycloudHosts(): string[];
95
+ /**
96
+ * Ensure the user's space exists on the TinyCloud server.
97
+ * Creates the space if it doesn't exist (when autoCreateSpace is true).
98
+ */
99
+ ensureSpaceExists(): Promise<void>;
100
+ /**
101
+ * Get the active TinyCloud session.
102
+ * This provides access to the session for authenticated requests.
103
+ * @returns Session object or undefined if not signed in
104
+ */
105
+ getTinycloudSession(): Session | undefined;
68
106
  }
69
107
  declare class UserAuthorizationInit {
70
108
  private config?;
71
- /** Extensions for the TCWClientSession. */
72
- extensions: TCWExtension[];
109
+ /** Extensions for the session. */
110
+ extensions: Extension[];
73
111
  /** The session representation (once signed in). */
74
- session?: TCWClientSession;
75
- constructor(config?: TCWClientConfig);
76
- /** Extend the session with an TCW compatible extension. */
77
- extend(extension: TCWExtension): void;
112
+ session?: ClientSession;
113
+ constructor(config?: ClientConfig);
114
+ /** Extend the session with a compatible extension. */
115
+ extend(extension: Extension): void;
78
116
  /**
79
117
  * Connect to the signing account using the configured provider.
80
118
  * @returns UserAuthorizationConnected instance.
81
119
  */
82
120
  connect(): Promise<UserAuthorizationConnected>;
83
121
  }
84
- /** An intermediate TCW state: connected, but not signed-in. */
85
- declare class UserAuthorizationConnected implements ITCWConnected {
86
- /** Instance of TCWSessionManager */
122
+ /** An intermediate state: connected, but not signed-in. */
123
+ declare class UserAuthorizationConnected implements IConnected {
124
+ /** Instance of SessionManager */
87
125
  builder: tcwSession.TCWSessionManager;
88
- /** TCWConfig object. */
89
- config: TCWClientConfig;
126
+ /** Config object. */
127
+ config: ClientConfig;
90
128
  /** Enabled extensions. */
91
- extensions: TCWExtension[];
129
+ extensions: Extension[];
92
130
  /** EthersJS provider. */
93
131
  provider: providers.Web3Provider;
94
132
  /**
@@ -102,65 +140,99 @@ declare class UserAuthorizationConnected implements ITCWConnected {
102
140
  api?: AxiosInstance;
103
141
  /** Ethereum Provider */
104
142
  constructor(
105
- /** Instance of TCWSessionManager */
143
+ /** Instance of SessionManager */
106
144
  builder: tcwSession.TCWSessionManager,
107
- /** TCWConfig object. */
108
- config: TCWClientConfig,
145
+ /** Config object. */
146
+ config: ClientConfig,
109
147
  /** Enabled extensions. */
110
- extensions: TCWExtension[],
148
+ extensions: Extension[],
111
149
  /** EthersJS provider. */
112
150
  provider: providers.Web3Provider);
151
+ /**
152
+ * Default KV actions for TinyCloud services.
153
+ * These are added to every session to enable basic KV operations.
154
+ */
155
+ private static readonly DEFAULT_KV_ACTIONS;
156
+ /**
157
+ * Default capabilities actions (for reading user capabilities).
158
+ */
159
+ private static readonly DEFAULT_CAPABILITIES_ACTIONS;
113
160
  /** Applies the "afterConnect" methods and the delegated capabilities of the extensions. */
114
161
  applyExtensions(): Promise<void>;
162
+ /**
163
+ * Adds default KV capabilities for the given user address and chainId.
164
+ * Must be called after we have address/chainId but before build().
165
+ * @param address - User's Ethereum address
166
+ * @param chainId - Chain ID
167
+ * @param spacePrefix - Space prefix (default: "default")
168
+ * @param kvPrefix - KV path prefix for scoping access (default: "" for all paths)
169
+ */
170
+ addDefaultCapabilities(address: string, chainId: number, spacePrefix?: string, kvPrefix?: string): void;
115
171
  /**
116
172
  * Applies the "afterSignIn" methods of the extensions.
117
- * @param session - TCWClientSession object.
173
+ * @param session - ClientSession object.
118
174
  */
119
- afterSignIn(session: TCWClientSession): Promise<void>;
175
+ afterSignIn(session: ClientSession): Promise<void>;
120
176
  /**
121
177
  * Requests the user to sign in.
122
178
  * Generates the SIWE message for this session, requests the configured
123
179
  * Signer to sign the message, calls the "afterSignIn" methods of the
124
180
  * extensions.
125
- * @returns Promise with the TCWClientSession object.
181
+ * @returns Promise with the ClientSession object.
126
182
  */
127
- signIn(): Promise<TCWClientSession>;
183
+ signIn(): Promise<ClientSession>;
128
184
  /**
129
185
  * Requests the user to sign out.
130
- * @param session - TCWClientSession object.
186
+ * @param session - ClientSession object.
131
187
  */
132
- signOut(session: TCWClientSession): Promise<void>;
188
+ signOut(session: ClientSession): Promise<void>;
133
189
  }
134
- declare class UserAuthorization implements IUserAuthorization {
190
+ declare class UserAuthorization implements IUserAuthorization, ICoreUserAuthorization {
135
191
  private _config;
136
192
  /** The Ethereum provider */
137
193
  provider: providers.Web3Provider;
138
194
  /** The session representation (once signed in). */
139
- session?: TCWClientSession;
140
- /** TCWClientSession builder. */
195
+ session?: ClientSession;
196
+ /** Session builder. */
141
197
  private init;
142
- /** Current connection of TCW */
198
+ /** Current connection */
143
199
  private connection?;
144
- /** The TCWClientConfig object. */
200
+ /** The config object. */
145
201
  private config;
146
202
  /** Pending session state for signature-based initialization */
147
203
  private pendingSession?;
148
- constructor(_config?: TCWClientConfig);
204
+ /** Whether to automatically create space if it doesn't exist */
205
+ private autoCreateSpace;
206
+ /** TinyCloud server endpoints */
207
+ private tinycloudHosts;
208
+ /** Space prefix for new sessions */
209
+ private spacePrefix;
210
+ /** KV path prefix for scoping access */
211
+ private kvPrefix;
212
+ /** The space ID for the current session */
213
+ private _spaceId?;
214
+ /** Delegation header for the current session */
215
+ private _delegationHeader?;
216
+ /** The TinyCloud session containing delegation and space info */
217
+ private _tinycloudSession?;
218
+ /** The host where the user's space was found or created */
219
+ private _activeHost?;
220
+ constructor(_config?: ClientConfig);
149
221
  /**
150
- * Extends TCW with a functions that are called after connecting and signing in.
222
+ * Extends with functions that are called after connecting and signing in.
151
223
  */
152
- extend(extension: TCWExtension): void;
224
+ extend(extension: Extension): void;
153
225
  connect(): Promise<void>;
154
- signIn(): Promise<TCWClientSession>;
226
+ signIn(): Promise<ClientSession>;
155
227
  /**
156
- * ENS data supported by TCW.
228
+ * ENS data supported by the SDK.
157
229
  * @param address - User address.
158
230
  * @param resolveEnsOpts - Options to resolve ENS.
159
231
  * @returns Object containing ENS data.
160
232
  */
161
233
  resolveEns(
162
234
  /** User address */
163
- address: string): Promise<TCWEnsData>;
235
+ address: string): Promise<EnsData>;
164
236
  /**
165
237
  * Invalidates user's session.
166
238
  */
@@ -193,36 +265,97 @@ declare class UserAuthorization implements IUserAuthorization {
193
265
  getSigner(): Signer;
194
266
  /**
195
267
  * Generates a SIWE message for authentication with session key capabilities.
196
- * This method initializes a TCWSessionManager, generates a session key,
268
+ * This method initializes a SessionManager, generates a session key,
197
269
  * applies extension capabilities, and builds a SIWE message for signing.
198
270
  *
199
271
  * @param address - Ethereum address performing the signing
200
- * @param partialSiweMessage - Optional partial SIWE message to override defaults
272
+ * @param partial - Optional partial SIWE message to override defaults
201
273
  * @returns SiweMessage object ready for signing
202
274
  */
203
- generateSiweMessage(address: string, partialSiweMessage?: Partial<SiweMessage>): Promise<SiweMessage>;
275
+ generateSiweMessage(address: string, partial?: PartialSiweMessage): Promise<SiweMessage>;
204
276
  /**
205
277
  * Sign in to the SDK using a pre-signed SIWE message.
206
278
  * This method must be called after generateSiweMessage().
207
279
  * @param siweMessage - The SIWE message that was generated
208
280
  * @param signature - The signature of the SIWE message
209
- * @returns Promise with the TCWClientSession object
281
+ * @returns Promise with the ClientSession object
282
+ */
283
+ signInWithSignature(siweMessage: SiweMessage, signature: string): Promise<ClientSession>;
284
+ /**
285
+ * Default KV actions for TinyCloud services.
286
+ * These are added to every session to enable basic KV operations.
210
287
  */
211
- signInWithSignature(siweMessage: SiweMessage, signature: string): Promise<TCWClientSession>;
288
+ private static readonly DEFAULT_KV_ACTIONS;
289
+ /**
290
+ * Default capabilities actions (for reading user capabilities).
291
+ */
292
+ private static readonly DEFAULT_CAPABILITIES_ACTIONS;
212
293
  /**
213
294
  * Applies extension capabilities (defaultActions/targetedActions) to the session manager.
214
- * This method iterates through the extensions and adds their capabilities to the TCWSessionManager.
295
+ * This method also adds default KV and capabilities actions.
215
296
  *
216
297
  * @private
217
- * @param sessionManager - TCWSessionManager instance to apply capabilities to
298
+ * @param sessionManager - SessionManager instance to apply capabilities to
218
299
  * @param extensions - Array of extensions to apply
300
+ * @param address - User's Ethereum address (for building target URIs)
301
+ * @param chainId - Chain ID (for building target URIs)
302
+ * @param spacePrefix - Space prefix (default: "default")
303
+ * @param kvPrefix - KV path prefix for scoping access (default: "" for all paths)
219
304
  */
220
305
  private applyExtensionCapabilities;
306
+ /**
307
+ * Get the space ID for the current session.
308
+ * @returns Space ID or undefined if not available
309
+ */
310
+ getSpaceId(): string | undefined;
311
+ /**
312
+ * Get the configured TinyCloud host URLs.
313
+ * @returns Array of TinyCloud host URLs
314
+ */
315
+ getTinycloudHosts(): string[];
316
+ /**
317
+ * Get the active TinyCloud session.
318
+ * This provides access to the session for authenticated requests.
319
+ * @returns Session object or undefined if not signed in
320
+ */
321
+ getTinycloudSession(): Session | undefined;
322
+ /**
323
+ * Create the space on the TinyCloud server (host delegation).
324
+ * This registers the user as the owner of the space.
325
+ * Uses a modal to confirm with the user before creating.
326
+ * @param host - The host to create the space on
327
+ * @returns Promise resolving to true if space was created, false if user dismissed
328
+ */
329
+ private hostSpace;
330
+ /**
331
+ * Ensure the user's space exists on the TinyCloud server.
332
+ * Creates the space if it doesn't exist and autoCreateSpace is enabled.
333
+ *
334
+ * Strategy:
335
+ * 1. Try to activate the session on the first (primary) host.
336
+ * 2. If activation succeeds, set it as the `_activeHost` and return.
337
+ * 3. If the primary host returns 404, create the space there (don't skip
338
+ * because it might exist on other hosts - there is no replication).
339
+ * 4. If the primary host has a non-404 error, try remaining hosts.
340
+ *
341
+ * @throws Error if space creation fails or is disabled and space doesn't exist.
342
+ */
343
+ ensureSpaceExists(): Promise<void>;
344
+ /**
345
+ * Create the space on a specific host and activate the session there.
346
+ */
347
+ private createSpaceOnHost;
221
348
  /**
222
349
  * Apply extension afterSignIn hooks to the session.
223
- * @param session - The TCWClientSession object
350
+ * @param session - The ClientSession object
224
351
  */
225
352
  private applyAfterSignInHooks;
353
+ /**
354
+ * Generate space ID and delegation header for the current session.
355
+ * This sets up the internal state needed for ensureSpaceExists() and SpaceConnection.
356
+ * @param session - The ClientSession object
357
+ */
358
+ private setupSpaceSession;
226
359
  }
227
360
  export { IUserAuthorization, UserAuthorization, UserAuthorizationInit, UserAuthorizationConnected, PendingSession, };
228
361
  //# sourceMappingURL=UserAuthorization.d.ts.map