@tinycloud/sdk-core 2.4.0-beta.9 → 2.4.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.
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __copyProps = (to, from, except, desc) => {
7
+ if (from && typeof from === "object" || typeof from === "function") {
8
+ for (let key of __getOwnPropNames(from))
9
+ if (!__hasOwnProp.call(to, key) && key !== except)
10
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
+ }
12
+ return to;
13
+ };
14
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
+
17
+ // src/bootstrap/index.ts
18
+ var bootstrap_exports = {};
19
+ module.exports = __toCommonJS(bootstrap_exports);
20
+ __reExport(bootstrap_exports, require("@tinycloud/bootstrap"), module.exports);
21
+ // Annotate the CommonJS export names for ESM import in node:
22
+ 0 && (module.exports = {
23
+ ...require("@tinycloud/bootstrap")
24
+ });
25
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/bootstrap/index.ts"],"sourcesContent":["export * from \"@tinycloud/bootstrap\";\n"],"mappings":";;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA,8BAAc,iCAAd;","names":[]}
@@ -0,0 +1 @@
1
+ export * from '@tinycloud/bootstrap';
@@ -0,0 +1 @@
1
+ export * from '@tinycloud/bootstrap';
@@ -0,0 +1,3 @@
1
+ // src/bootstrap/index.ts
2
+ export * from "@tinycloud/bootstrap";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/bootstrap/index.ts"],"sourcesContent":["export * from \"@tinycloud/bootstrap\";\n"],"mappings":";AAAA,cAAc;","names":[]}
package/dist/index.cjs CHANGED
@@ -30,10 +30,21 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/index.ts
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
+ ACCOUNT_INDEX_SCHEMA: () => import_bootstrap2.ACCOUNT_INDEX_SCHEMA,
33
34
  ACCOUNT_REGISTRY_PATH: () => ACCOUNT_REGISTRY_PATH,
34
35
  ACCOUNT_REGISTRY_SPACE: () => ACCOUNT_REGISTRY_SPACE,
35
36
  AccountService: () => AccountService,
36
37
  AutoApproveSpaceCreationHandler: () => AutoApproveSpaceCreationHandler,
38
+ BOOTSTRAP_ALLOWLIST: () => import_bootstrap2.BOOTSTRAP_ALLOWLIST,
39
+ BOOTSTRAP_DEFAULT_SPACE: () => import_bootstrap2.BOOTSTRAP_DEFAULT_SPACE,
40
+ BOOTSTRAP_ENCRYPTION_NETWORK_NAME: () => import_bootstrap2.BOOTSTRAP_ENCRYPTION_NETWORK_NAME,
41
+ BOOTSTRAP_ENCRYPTION_NETWORK_RESOURCE_TEMPLATE: () => import_bootstrap2.BOOTSTRAP_ENCRYPTION_NETWORK_RESOURCE_TEMPLATE,
42
+ BOOTSTRAP_MANIFEST: () => import_bootstrap2.BOOTSTRAP_MANIFEST,
43
+ BOOTSTRAP_PERSISTED_APPLICATION_MANIFESTS: () => import_bootstrap2.BOOTSTRAP_PERSISTED_APPLICATION_MANIFESTS,
44
+ BOOTSTRAP_PUBLIC_SPACE: () => import_bootstrap2.BOOTSTRAP_PUBLIC_SPACE,
45
+ BOOTSTRAP_SESSION_REQUESTS: () => import_bootstrap2.BOOTSTRAP_SESSION_REQUESTS,
46
+ BOOTSTRAP_SPACE_MANIFESTS: () => import_bootstrap2.BOOTSTRAP_SPACE_MANIFESTS,
47
+ BOOTSTRAP_SPACE_NAMES: () => import_bootstrap2.BOOTSTRAP_SPACE_NAMES,
37
48
  CapabilityKeyRegistry: () => CapabilityKeyRegistry,
38
49
  CapabilityKeyRegistryErrorCodes: () => CapabilityKeyRegistryErrorCodes,
39
50
  ClientSessionSchema: () => ClientSessionSchema,
@@ -45,6 +56,7 @@ __export(index_exports, {
45
56
  DEFAULT_ENCRYPTION_ALG: () => import_sdk_services7.DEFAULT_ENCRYPTION_ALG,
46
57
  DEFAULT_EXPIRY: () => DEFAULT_EXPIRY,
47
58
  DEFAULT_KEY_VERSION: () => import_sdk_services7.DEFAULT_KEY_VERSION,
59
+ DEFAULT_KNOWLEDGE_ROOT: () => DEFAULT_KNOWLEDGE_ROOT,
48
60
  DEFAULT_MANIFEST_SPACE: () => DEFAULT_MANIFEST_SPACE,
49
61
  DEFAULT_MANIFEST_VERSION: () => DEFAULT_MANIFEST_VERSION,
50
62
  DEFAULT_SIGNED_READ_URL_EXPIRY_MS: () => DEFAULT_SIGNED_READ_URL_EXPIRY_MS,
@@ -77,7 +89,9 @@ __export(index_exports, {
77
89
  PermissionNotInManifestError: () => PermissionNotInManifestError,
78
90
  PrefixedKVService: () => import_sdk_services7.PrefixedKVService,
79
91
  ProtocolMismatchError: () => ProtocolMismatchError,
92
+ SECRETS_SPACE: () => SECRETS_SPACE,
80
93
  SECRET_NAME_RE: () => import_sdk_services7.SECRET_NAME_RE,
94
+ SECRET_RECORDS_SCHEMA: () => import_bootstrap2.SECRET_RECORDS_SCHEMA,
81
95
  SERVICE_LONG_TO_SHORT: () => SERVICE_LONG_TO_SHORT,
82
96
  SERVICE_SHORT_TO_LONG: () => SERVICE_SHORT_TO_LONG,
83
97
  SQLAction: () => import_sdk_services7.SQLAction,
@@ -92,7 +106,13 @@ __export(index_exports, {
92
106
  Space: () => Space,
93
107
  SpaceErrorCodes: () => SpaceErrorCodes,
94
108
  SpaceService: () => SpaceService,
109
+ TINYCLOUD_ACCOUNT_SPACE_MANIFEST: () => import_bootstrap2.TINYCLOUD_ACCOUNT_SPACE_MANIFEST,
110
+ TINYCLOUD_APPLICATIONS_SPACE_MANIFEST: () => import_bootstrap2.TINYCLOUD_APPLICATIONS_SPACE_MANIFEST,
111
+ TINYCLOUD_DEFAULT_SPACE_MANIFEST: () => import_bootstrap2.TINYCLOUD_DEFAULT_SPACE_MANIFEST,
112
+ TINYCLOUD_PUBLIC_SPACE_MANIFEST: () => import_bootstrap2.TINYCLOUD_PUBLIC_SPACE_MANIFEST,
113
+ TINYCLOUD_SECRETS_BOOTSTRAP_MANIFEST: () => import_bootstrap2.TINYCLOUD_SECRETS_BOOTSTRAP_MANIFEST,
95
114
  TinyCloud: () => TinyCloud,
115
+ TinyCloudDebugLogger: () => import_sdk_services7.TinyCloudDebugLogger,
96
116
  UnsupportedFeatureError: () => UnsupportedFeatureError,
97
117
  VAULT_PERMISSION_SERVICE: () => VAULT_PERMISSION_SERVICE,
98
118
  VaultHeaders: () => import_sdk_services7.VaultHeaders,
@@ -101,6 +121,9 @@ __export(index_exports, {
101
121
  activateSessionWithHost: () => activateSessionWithHost,
102
122
  addressStorageKey: () => addressStorageKey,
103
123
  applyPrefix: () => applyPrefix,
124
+ bootstrapEncryptionNetworkId: () => import_bootstrap2.bootstrapEncryptionNetworkId,
125
+ bootstrapSpaceId: () => import_bootstrap2.bootstrapSpaceId,
126
+ bootstrapSteps: () => import_bootstrap2.bootstrapSteps,
104
127
  buildCanonicalDecryptRequest: () => import_sdk_services7.buildCanonicalDecryptRequest,
105
128
  buildDecryptAttenuation: () => import_sdk_services7.buildDecryptAttenuation,
106
129
  buildDecryptFacts: () => import_sdk_services7.buildDecryptFacts,
@@ -118,8 +141,11 @@ __export(index_exports, {
118
141
  canonicalizeSecretScope: () => import_sdk_services7.canonicalizeSecretScope,
119
142
  checkDecryptInvocationInput: () => import_sdk_services7.checkDecryptInvocationInput,
120
143
  checkNodeInfo: () => checkNodeInfo,
144
+ clearTinyCloudDebugLogs: () => import_sdk_services7.clearTinyCloudDebugLogs,
145
+ composeBootstrapSpaceManifest: () => import_bootstrap2.composeBootstrapSpaceManifest,
121
146
  composeManifestRequest: () => composeManifestRequest,
122
147
  createCapabilityKeyRegistry: () => createCapabilityKeyRegistry,
148
+ createOpenKeyCallbackSigningStrategy: () => createOpenKeyCallbackSigningStrategy,
123
149
  createSharingService: () => createSharingService,
124
150
  createSpaceService: () => createSpaceService,
125
151
  createVaultCrypto: () => import_sdk_services7.createVaultCrypto,
@@ -130,7 +156,9 @@ __export(index_exports, {
130
156
  deriveSignedReceiverKey: () => import_sdk_services7.deriveSignedReceiverKey,
131
157
  didCacheKey: () => didCacheKey,
132
158
  didEquals: () => didEquals,
159
+ disableTinyCloudDebug: () => import_sdk_services7.disableTinyCloudDebug,
133
160
  discoverNetwork: () => import_sdk_services7.discoverNetwork,
161
+ enableTinyCloudDebug: () => import_sdk_services7.enableTinyCloudDebug,
134
162
  encryptToNetwork: () => import_sdk_services7.encryptToNetwork,
135
163
  encryptionBase64Decode: () => import_sdk_services7.base64Decode,
136
164
  encryptionBase64Encode: () => import_sdk_services7.base64Encode,
@@ -145,9 +173,11 @@ __export(index_exports, {
145
173
  fetchLocationRecord: () => fetchLocationRecord,
146
174
  fetchPeerId: () => fetchPeerId,
147
175
  generateRandomReceiverKey: () => import_sdk_services7.generateRandomReceiverKey,
176
+ getTinyCloudDebugLogs: () => import_sdk_services7.getTinyCloudDebugLogs,
148
177
  hexDecode: () => import_sdk_services7.hexDecode,
149
178
  hexEncode: () => import_sdk_services7.hexEncode,
150
179
  httpUrlToMultiaddr: () => httpUrlToMultiaddr,
180
+ installTinyCloudDebugGlobals: () => import_sdk_services7.installTinyCloudDebugGlobals,
151
181
  isCapabilitySubset: () => isCapabilitySubset,
152
182
  isEvmAddress: () => isEvmAddress,
153
183
  isNetworkId: () => import_sdk_services7.isNetworkId,
@@ -172,6 +202,7 @@ __export(index_exports, {
172
202
  principalDidEquals: () => principalDidEquals,
173
203
  resolveCloudLocation: () => resolveCloudLocation,
174
204
  resolveManifest: () => resolveManifest,
205
+ resolveManifestKnowledgeRoot: () => resolveManifestKnowledgeRoot,
175
206
  resolveSecretListPrefix: () => import_sdk_services7.resolveSecretListPrefix,
176
207
  resolveSecretPath: () => import_sdk_services7.resolveSecretPath,
177
208
  resolveTinyCloudHosts: () => resolveTinyCloudHosts,
@@ -180,6 +211,7 @@ __export(index_exports, {
180
211
  serviceError: () => import_sdk_services7.serviceError,
181
212
  signLocationRecord: () => signLocationRecord,
182
213
  submitHostDelegation: () => submitHostDelegation,
214
+ tinyCloudDebugLogger: () => import_sdk_services7.tinyCloudDebugLogger,
183
215
  validateClientSession: () => validateClientSession,
184
216
  validateEnvelope: () => import_sdk_services7.validateEnvelope,
185
217
  validateLocationRecord: () => validateLocationRecord,
@@ -379,7 +411,15 @@ var PersistedSessionDataSchema = import_zod2.z.object({
379
411
  /** Schema version for migrations */
380
412
  version: import_zod2.z.string(),
381
413
  /** Optional ENS data */
382
- ens: EnsDataSchema2.optional()
414
+ ens: EnsDataSchema2.optional(),
415
+ /**
416
+ * TinyCloud hosts this session was created against. Persisted so a
417
+ * restored session resolves to the same node without re-running the
418
+ * registry/fallback resolution (or the wallet sign-in flow). Optional
419
+ * for backward compatibility with sessions persisted before this field
420
+ * existed — those restore and lazily re-resolve their hosts.
421
+ */
422
+ tinycloudHosts: import_zod2.z.array(import_zod2.z.string()).optional()
383
423
  });
384
424
  var TinyCloudSessionSchema = import_zod2.z.object({
385
425
  /** User's Ethereum address */
@@ -2349,6 +2389,7 @@ var import_sdk_services5 = require("@tinycloud/sdk-services");
2349
2389
  // src/manifest.ts
2350
2390
  var import_ms = __toESM(require("ms"), 1);
2351
2391
  var import_sdk_services4 = require("@tinycloud/sdk-services");
2392
+ var DEFAULT_KNOWLEDGE_ROOT = "knowledge/index.md";
2352
2393
  var ManifestValidationError = class extends Error {
2353
2394
  constructor(message) {
2354
2395
  super(`Manifest validation failed: ${message}`);
@@ -2403,7 +2444,7 @@ var DEFAULT_ADMIN_ENTRIES = [
2403
2444
  service: "tinycloud.sql",
2404
2445
  space: DEFAULT_MANIFEST_SPACE,
2405
2446
  path: "/",
2406
- actions: ["read", "write", "ddl"]
2447
+ actions: ["read", "write", "schema"]
2407
2448
  }
2408
2449
  ];
2409
2450
  var DEFAULT_ALL_ENTRIES = [
@@ -2417,7 +2458,7 @@ var DEFAULT_ALL_ENTRIES = [
2417
2458
  service: "tinycloud.sql",
2418
2459
  space: DEFAULT_MANIFEST_SPACE,
2419
2460
  path: "/",
2420
- actions: ["read", "write", "ddl"]
2461
+ actions: ["read", "write", "schema"]
2421
2462
  },
2422
2463
  {
2423
2464
  service: "tinycloud.duckdb",
@@ -2575,6 +2616,9 @@ function validateManifest(input) {
2575
2616
  if (m.expiry !== void 0) {
2576
2617
  parseExpiry(m.expiry);
2577
2618
  }
2619
+ if (m.knowledge !== void 0) {
2620
+ resolveManifestKnowledgeRoot(m.knowledge);
2621
+ }
2578
2622
  if (m.permissions !== void 0) {
2579
2623
  if (!Array.isArray(m.permissions)) {
2580
2624
  throw new ManifestValidationError(
@@ -2590,6 +2634,25 @@ function validateManifest(input) {
2590
2634
  }
2591
2635
  return m;
2592
2636
  }
2637
+ function resolveManifestKnowledgeRoot(knowledge) {
2638
+ if (knowledge === void 0) {
2639
+ return void 0;
2640
+ }
2641
+ if (knowledge === true) {
2642
+ return DEFAULT_KNOWLEDGE_ROOT;
2643
+ }
2644
+ if (typeof knowledge !== "string" || knowledge.length === 0) {
2645
+ throw new ManifestValidationError(
2646
+ "manifest.knowledge must be true or a knowledge/*.md root path"
2647
+ );
2648
+ }
2649
+ if (!/^knowledge\/.+\.md$/.test(knowledge)) {
2650
+ throw new ManifestValidationError(
2651
+ "manifest.knowledge must be true or a knowledge/*.md root path"
2652
+ );
2653
+ }
2654
+ return knowledge;
2655
+ }
2593
2656
  function validateManifestSecrets(secrets) {
2594
2657
  if (secrets === null || typeof secrets !== "object" || Array.isArray(secrets)) {
2595
2658
  throw new ManifestValidationError("manifest.secrets must be an object");
@@ -2989,7 +3052,7 @@ function accountRegistryIndexPermission() {
2989
3052
  service: "tinycloud.sql",
2990
3053
  space: ACCOUNT_REGISTRY_SPACE,
2991
3054
  path: "account",
2992
- actions: ["tinycloud.sql/read", "tinycloud.sql/write", "tinycloud.sql/ddl"]
3055
+ actions: ["tinycloud.sql/read", "tinycloud.sql/write", "tinycloud.sql/schema"]
2993
3056
  };
2994
3057
  }
2995
3058
  function composeManifestRequest(inputs, options = {}) {
@@ -3094,8 +3157,10 @@ function manifestAbilitiesUnion(resolved) {
3094
3157
  }
3095
3158
 
3096
3159
  // src/account/AccountService.ts
3160
+ var import_bootstrap = require("@tinycloud/bootstrap");
3097
3161
  var SERVICE_NAME2 = "account";
3098
3162
  var ACCOUNT_INDEX_DB = "account";
3163
+ var ACCOUNT_INDEX_NAMESPACE = "tinycloud.account.index";
3099
3164
  var ACCOUNT_SPACES_PATH = "spaces/";
3100
3165
  var AccountService = class {
3101
3166
  constructor(config) {
@@ -3290,6 +3355,13 @@ var AccountService = class {
3290
3355
  }
3291
3356
  };
3292
3357
  this.index = {
3358
+ ensure: async () => {
3359
+ const dbResult = this.accountDb();
3360
+ if (!dbResult.ok) return dbResult;
3361
+ const schema = await this.ensureAccountIndex(dbResult.data);
3362
+ if (!schema.ok) return schema;
3363
+ return (0, import_sdk_services5.ok)({ database: ACCOUNT_INDEX_DB });
3364
+ },
3293
3365
  rebuild: async () => {
3294
3366
  const dbResult = this.accountDb();
3295
3367
  if (!dbResult.ok) return dbResult;
@@ -3300,8 +3372,9 @@ var AccountService = class {
3300
3372
  const delegations = await this.delegations.list();
3301
3373
  if (!delegations.ok) return delegations;
3302
3374
  const syncedAt = (/* @__PURE__ */ new Date()).toISOString();
3375
+ const schema = await this.ensureAccountIndex(dbResult.data);
3376
+ if (!schema.ok) return schema;
3303
3377
  const statements = [
3304
- ...ACCOUNT_INDEX_SCHEMA.map((sql) => ({ sql })),
3305
3378
  { sql: "DELETE FROM applications" },
3306
3379
  { sql: "DELETE FROM application_state" },
3307
3380
  { sql: "DELETE FROM spaces" },
@@ -3498,7 +3571,7 @@ var AccountService = class {
3498
3571
  async indexHasApplicationHash(appId, manifestHash) {
3499
3572
  const dbResult = this.accountDb();
3500
3573
  if (!dbResult.ok) return false;
3501
- const schema = await dbResult.data.batch(ACCOUNT_INDEX_SCHEMA.map((sql) => ({ sql })));
3574
+ const schema = await this.ensureAccountIndex(dbResult.data);
3502
3575
  if (!schema.ok) return false;
3503
3576
  const queried = await dbResult.data.query(
3504
3577
  "SELECT 1 FROM application_state WHERE app_id = ? AND manifest_hash = ? LIMIT 1",
@@ -3512,10 +3585,11 @@ var AccountService = class {
3512
3585
  async upsertApplicationIndex(app) {
3513
3586
  const dbResult = this.accountDb();
3514
3587
  if (!dbResult.ok) return (0, import_sdk_services5.ok)(void 0);
3588
+ const schema = await this.ensureAccountIndex(dbResult.data);
3589
+ if (!schema.ok) return schema;
3515
3590
  const updatedAt = app.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString();
3516
3591
  const manifestHash = app.manifestHash ?? hashJson(app.manifests);
3517
3592
  const written = await dbResult.data.batch([
3518
- ...ACCOUNT_INDEX_SCHEMA.map((sql) => ({ sql })),
3519
3593
  {
3520
3594
  sql: "INSERT OR REPLACE INTO applications (app_id, name, description, updated_at, manifest_json) VALUES (?, ?, ?, ?, ?)",
3521
3595
  params: [
@@ -3540,8 +3614,9 @@ var AccountService = class {
3540
3614
  async deleteApplicationIndex(appId) {
3541
3615
  const dbResult = this.accountDb();
3542
3616
  if (!dbResult.ok) return (0, import_sdk_services5.ok)(void 0);
3617
+ const schema = await this.ensureAccountIndex(dbResult.data);
3618
+ if (!schema.ok) return schema;
3543
3619
  const deleted = await dbResult.data.batch([
3544
- ...ACCOUNT_INDEX_SCHEMA.map((sql) => ({ sql })),
3545
3620
  { sql: "DELETE FROM applications WHERE app_id = ?", params: [appId] },
3546
3621
  { sql: "DELETE FROM application_state WHERE app_id = ?", params: [appId] }
3547
3622
  ]);
@@ -3554,9 +3629,10 @@ var AccountService = class {
3554
3629
  async upsertSpaceIndex(space) {
3555
3630
  const dbResult = this.accountDb();
3556
3631
  if (!dbResult.ok) return (0, import_sdk_services5.ok)(void 0);
3632
+ const schema = await this.ensureAccountIndex(dbResult.data);
3633
+ if (!schema.ok) return schema;
3557
3634
  const updatedAt = space.updatedAt ?? (/* @__PURE__ */ new Date()).toISOString();
3558
3635
  const written = await dbResult.data.batch([
3559
- ...ACCOUNT_INDEX_SCHEMA.map((sql) => ({ sql })),
3560
3636
  {
3561
3637
  sql: "INSERT OR REPLACE INTO spaces (space_id, name, owner_did, type, permissions_json, status, registered_at, updated_at, expires_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
3562
3638
  params: [
@@ -3581,8 +3657,9 @@ var AccountService = class {
3581
3657
  async deleteSpaceIndex(spaceId) {
3582
3658
  const dbResult = this.accountDb();
3583
3659
  if (!dbResult.ok) return (0, import_sdk_services5.ok)(void 0);
3660
+ const schema = await this.ensureAccountIndex(dbResult.data);
3661
+ if (!schema.ok) return schema;
3584
3662
  const deleted = await dbResult.data.batch([
3585
- ...ACCOUNT_INDEX_SCHEMA.map((sql) => ({ sql })),
3586
3663
  { sql: "DELETE FROM spaces WHERE space_id = ?", params: [spaceId] }
3587
3664
  ]);
3588
3665
  if (!deleted.ok) return accountErr(deleted.error);
@@ -3604,8 +3681,9 @@ var AccountService = class {
3604
3681
  const dbResult = this.accountDb();
3605
3682
  if (!dbResult.ok) return;
3606
3683
  const syncedAt = (/* @__PURE__ */ new Date()).toISOString();
3684
+ const schema = await this.ensureAccountIndex(dbResult.data);
3685
+ if (!schema.ok) return;
3607
3686
  await dbResult.data.batch([
3608
- ...ACCOUNT_INDEX_SCHEMA.map((sql) => ({ sql })),
3609
3687
  { sql: "DELETE FROM applications" },
3610
3688
  { sql: "DELETE FROM application_state" },
3611
3689
  ...applications.map((app) => ({
@@ -3634,8 +3712,9 @@ var AccountService = class {
3634
3712
  const dbResult = this.accountDb();
3635
3713
  if (!dbResult.ok) return;
3636
3714
  const syncedAt = (/* @__PURE__ */ new Date()).toISOString();
3715
+ const schema = await this.ensureAccountIndex(dbResult.data);
3716
+ if (!schema.ok) return;
3637
3717
  await dbResult.data.batch([
3638
- ...ACCOUNT_INDEX_SCHEMA.map((sql) => ({ sql })),
3639
3718
  { sql: "DELETE FROM spaces" },
3640
3719
  ...spaces.map((space) => ({
3641
3720
  sql: "INSERT OR REPLACE INTO spaces (space_id, name, owner_did, type, permissions_json, status, registered_at, updated_at, expires_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
@@ -3663,8 +3742,9 @@ var AccountService = class {
3663
3742
  const dbResult = this.accountDb();
3664
3743
  if (!dbResult.ok) return;
3665
3744
  const syncedAt = (/* @__PURE__ */ new Date()).toISOString();
3745
+ const schema = await this.ensureAccountIndex(dbResult.data);
3746
+ if (!schema.ok) return;
3666
3747
  await dbResult.data.batch([
3667
- ...ACCOUNT_INDEX_SCHEMA.map((sql) => ({ sql })),
3668
3748
  { sql: "DELETE FROM delegations" },
3669
3749
  ...delegations.map((delegation) => ({
3670
3750
  sql: "INSERT OR REPLACE INTO delegations (cid, direction, space_id, space_name, counterparty_did, delegate_did, delegator_did, path, actions_json, expiry, status, created_at, updated_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
@@ -3691,57 +3771,20 @@ var AccountService = class {
3691
3771
  ]);
3692
3772
  });
3693
3773
  }
3774
+ async ensureAccountIndex(db) {
3775
+ const migrated = await db.migrations.apply({
3776
+ namespace: ACCOUNT_INDEX_NAMESPACE,
3777
+ migrations: [
3778
+ {
3779
+ id: "001_initial",
3780
+ sql: [...import_bootstrap.ACCOUNT_INDEX_SCHEMA]
3781
+ }
3782
+ ]
3783
+ });
3784
+ if (!migrated.ok) return accountErr(migrated.error);
3785
+ return (0, import_sdk_services5.ok)(void 0);
3786
+ }
3694
3787
  };
3695
- var ACCOUNT_INDEX_SCHEMA = [
3696
- `CREATE TABLE IF NOT EXISTS applications (
3697
- app_id TEXT PRIMARY KEY,
3698
- name TEXT,
3699
- description TEXT,
3700
- updated_at TEXT,
3701
- manifest_json TEXT NOT NULL
3702
- )`,
3703
- `CREATE TABLE IF NOT EXISTS application_state (
3704
- app_id TEXT PRIMARY KEY,
3705
- manifest_hash TEXT NOT NULL,
3706
- indexed_at TEXT NOT NULL
3707
- )`,
3708
- `CREATE TABLE IF NOT EXISTS spaces (
3709
- space_id TEXT PRIMARY KEY,
3710
- name TEXT NOT NULL,
3711
- owner_did TEXT NOT NULL,
3712
- type TEXT NOT NULL,
3713
- permissions_json TEXT NOT NULL,
3714
- status TEXT NOT NULL,
3715
- registered_at TEXT,
3716
- updated_at TEXT NOT NULL,
3717
- expires_at TEXT
3718
- )`,
3719
- `CREATE TABLE IF NOT EXISTS delegations (
3720
- cid TEXT PRIMARY KEY,
3721
- direction TEXT NOT NULL,
3722
- space_id TEXT NOT NULL,
3723
- space_name TEXT,
3724
- counterparty_did TEXT NOT NULL,
3725
- delegate_did TEXT NOT NULL,
3726
- delegator_did TEXT,
3727
- path TEXT NOT NULL,
3728
- actions_json TEXT NOT NULL,
3729
- expiry TEXT NOT NULL,
3730
- status TEXT NOT NULL,
3731
- created_at TEXT,
3732
- updated_at TEXT NOT NULL
3733
- )`,
3734
- `CREATE TABLE IF NOT EXISTS sync_state (
3735
- source TEXT PRIMARY KEY,
3736
- synced_at TEXT NOT NULL,
3737
- count INTEGER NOT NULL
3738
- )`,
3739
- "CREATE INDEX IF NOT EXISTS idx_delegations_direction ON delegations(direction)",
3740
- "CREATE INDEX IF NOT EXISTS idx_delegations_space ON delegations(space_id)",
3741
- "CREATE INDEX IF NOT EXISTS idx_delegations_counterparty ON delegations(counterparty_did)",
3742
- "CREATE INDEX IF NOT EXISTS idx_spaces_owner ON spaces(owner_did)",
3743
- "CREATE INDEX IF NOT EXISTS idx_spaces_type ON spaces(type)"
3744
- ];
3745
3788
  function applicationKey(appId) {
3746
3789
  return `${ACCOUNT_REGISTRY_PATH}${appId}`;
3747
3790
  }
@@ -5651,6 +5694,76 @@ function createCapabilityKeyRegistry() {
5651
5694
  }
5652
5695
 
5653
5696
  // src/authorization/strategies.ts
5697
+ async function resolveOpenKeyToken(token) {
5698
+ return typeof token === "function" ? token() : token;
5699
+ }
5700
+ async function resolveOpenKeyHeaders(headers) {
5701
+ return typeof headers === "function" ? headers() : headers ?? {};
5702
+ }
5703
+ function openKeyApprovalReason(body) {
5704
+ if (body.reason) return body.reason;
5705
+ if (body.error) return body.error;
5706
+ if (body.approvalUrl) {
5707
+ return `OpenKey explicit approval required: ${body.approvalUrl}`;
5708
+ }
5709
+ return "OpenKey explicit approval required";
5710
+ }
5711
+ function createOpenKeyCallbackSigningStrategy(options) {
5712
+ return {
5713
+ type: "callback",
5714
+ openKeyAutoSign: true,
5715
+ handler: async (request) => {
5716
+ const fetchImpl = options.fetch ?? globalThis.fetch;
5717
+ if (!fetchImpl) {
5718
+ throw new Error("OpenKey signing strategy requires a fetch implementation");
5719
+ }
5720
+ const token = await resolveOpenKeyToken(options.token);
5721
+ const extraHeaders = await resolveOpenKeyHeaders(options.headers);
5722
+ const body = {
5723
+ ...request,
5724
+ ...options.keyId ? { keyId: options.keyId } : {}
5725
+ };
5726
+ const response = await fetchImpl(options.endpoint, {
5727
+ method: "POST",
5728
+ credentials: options.credentials,
5729
+ headers: {
5730
+ "content-type": "application/json",
5731
+ ...token ? { authorization: `Bearer ${token}` } : {},
5732
+ ...extraHeaders
5733
+ },
5734
+ body: JSON.stringify(body)
5735
+ });
5736
+ let parsed;
5737
+ try {
5738
+ parsed = await response.json();
5739
+ } catch {
5740
+ parsed = void 0;
5741
+ }
5742
+ if (!response.ok) {
5743
+ return {
5744
+ approved: false,
5745
+ reason: parsed?.reason ?? parsed?.error ?? `OpenKey signing failed with HTTP ${response.status}`
5746
+ };
5747
+ }
5748
+ if (parsed?.needsApproval || parsed?.approved === false) {
5749
+ return {
5750
+ approved: false,
5751
+ reason: openKeyApprovalReason(parsed)
5752
+ };
5753
+ }
5754
+ if (typeof parsed?.signature === "string" && parsed.signature.length > 0) {
5755
+ return {
5756
+ approved: true,
5757
+ signature: parsed.signature
5758
+ };
5759
+ }
5760
+ return {
5761
+ approved: false,
5762
+ reason: "OpenKey signing response did not include a signature"
5763
+ };
5764
+ }
5765
+ };
5766
+ }
5654
5767
  var defaultSignStrategy = { type: "auto-sign" };
5655
5768
 
5656
5769
  // src/authorization/spaceCreation.ts
@@ -5726,6 +5839,9 @@ async function checkNodeInfo(host, sdkProtocol, fetchFn = globalThis.fetch.bind(
5726
5839
  };
5727
5840
  }
5728
5841
 
5842
+ // src/index.ts
5843
+ var import_bootstrap2 = require("@tinycloud/bootstrap");
5844
+
5729
5845
  // src/location.ts
5730
5846
  var import_multiaddr = require("@multiformats/multiaddr");
5731
5847
  var import_multiaddr_to_uri = require("@multiformats/multiaddr-to-uri");
@@ -6236,10 +6352,21 @@ function parseRecapCapabilities(parseWasm, siwe) {
6236
6352
  }
6237
6353
  // Annotate the CommonJS export names for ESM import in node:
6238
6354
  0 && (module.exports = {
6355
+ ACCOUNT_INDEX_SCHEMA,
6239
6356
  ACCOUNT_REGISTRY_PATH,
6240
6357
  ACCOUNT_REGISTRY_SPACE,
6241
6358
  AccountService,
6242
6359
  AutoApproveSpaceCreationHandler,
6360
+ BOOTSTRAP_ALLOWLIST,
6361
+ BOOTSTRAP_DEFAULT_SPACE,
6362
+ BOOTSTRAP_ENCRYPTION_NETWORK_NAME,
6363
+ BOOTSTRAP_ENCRYPTION_NETWORK_RESOURCE_TEMPLATE,
6364
+ BOOTSTRAP_MANIFEST,
6365
+ BOOTSTRAP_PERSISTED_APPLICATION_MANIFESTS,
6366
+ BOOTSTRAP_PUBLIC_SPACE,
6367
+ BOOTSTRAP_SESSION_REQUESTS,
6368
+ BOOTSTRAP_SPACE_MANIFESTS,
6369
+ BOOTSTRAP_SPACE_NAMES,
6243
6370
  CapabilityKeyRegistry,
6244
6371
  CapabilityKeyRegistryErrorCodes,
6245
6372
  ClientSessionSchema,
@@ -6251,6 +6378,7 @@ function parseRecapCapabilities(parseWasm, siwe) {
6251
6378
  DEFAULT_ENCRYPTION_ALG,
6252
6379
  DEFAULT_EXPIRY,
6253
6380
  DEFAULT_KEY_VERSION,
6381
+ DEFAULT_KNOWLEDGE_ROOT,
6254
6382
  DEFAULT_MANIFEST_SPACE,
6255
6383
  DEFAULT_MANIFEST_VERSION,
6256
6384
  DEFAULT_SIGNED_READ_URL_EXPIRY_MS,
@@ -6283,7 +6411,9 @@ function parseRecapCapabilities(parseWasm, siwe) {
6283
6411
  PermissionNotInManifestError,
6284
6412
  PrefixedKVService,
6285
6413
  ProtocolMismatchError,
6414
+ SECRETS_SPACE,
6286
6415
  SECRET_NAME_RE,
6416
+ SECRET_RECORDS_SCHEMA,
6287
6417
  SERVICE_LONG_TO_SHORT,
6288
6418
  SERVICE_SHORT_TO_LONG,
6289
6419
  SQLAction,
@@ -6298,7 +6428,13 @@ function parseRecapCapabilities(parseWasm, siwe) {
6298
6428
  Space,
6299
6429
  SpaceErrorCodes,
6300
6430
  SpaceService,
6431
+ TINYCLOUD_ACCOUNT_SPACE_MANIFEST,
6432
+ TINYCLOUD_APPLICATIONS_SPACE_MANIFEST,
6433
+ TINYCLOUD_DEFAULT_SPACE_MANIFEST,
6434
+ TINYCLOUD_PUBLIC_SPACE_MANIFEST,
6435
+ TINYCLOUD_SECRETS_BOOTSTRAP_MANIFEST,
6301
6436
  TinyCloud,
6437
+ TinyCloudDebugLogger,
6302
6438
  UnsupportedFeatureError,
6303
6439
  VAULT_PERMISSION_SERVICE,
6304
6440
  VaultHeaders,
@@ -6307,6 +6443,9 @@ function parseRecapCapabilities(parseWasm, siwe) {
6307
6443
  activateSessionWithHost,
6308
6444
  addressStorageKey,
6309
6445
  applyPrefix,
6446
+ bootstrapEncryptionNetworkId,
6447
+ bootstrapSpaceId,
6448
+ bootstrapSteps,
6310
6449
  buildCanonicalDecryptRequest,
6311
6450
  buildDecryptAttenuation,
6312
6451
  buildDecryptFacts,
@@ -6324,8 +6463,11 @@ function parseRecapCapabilities(parseWasm, siwe) {
6324
6463
  canonicalizeSecretScope,
6325
6464
  checkDecryptInvocationInput,
6326
6465
  checkNodeInfo,
6466
+ clearTinyCloudDebugLogs,
6467
+ composeBootstrapSpaceManifest,
6327
6468
  composeManifestRequest,
6328
6469
  createCapabilityKeyRegistry,
6470
+ createOpenKeyCallbackSigningStrategy,
6329
6471
  createSharingService,
6330
6472
  createSpaceService,
6331
6473
  createVaultCrypto,
@@ -6336,7 +6478,9 @@ function parseRecapCapabilities(parseWasm, siwe) {
6336
6478
  deriveSignedReceiverKey,
6337
6479
  didCacheKey,
6338
6480
  didEquals,
6481
+ disableTinyCloudDebug,
6339
6482
  discoverNetwork,
6483
+ enableTinyCloudDebug,
6340
6484
  encryptToNetwork,
6341
6485
  encryptionBase64Decode,
6342
6486
  encryptionBase64Encode,
@@ -6351,9 +6495,11 @@ function parseRecapCapabilities(parseWasm, siwe) {
6351
6495
  fetchLocationRecord,
6352
6496
  fetchPeerId,
6353
6497
  generateRandomReceiverKey,
6498
+ getTinyCloudDebugLogs,
6354
6499
  hexDecode,
6355
6500
  hexEncode,
6356
6501
  httpUrlToMultiaddr,
6502
+ installTinyCloudDebugGlobals,
6357
6503
  isCapabilitySubset,
6358
6504
  isEvmAddress,
6359
6505
  isNetworkId,
@@ -6378,6 +6524,7 @@ function parseRecapCapabilities(parseWasm, siwe) {
6378
6524
  principalDidEquals,
6379
6525
  resolveCloudLocation,
6380
6526
  resolveManifest,
6527
+ resolveManifestKnowledgeRoot,
6381
6528
  resolveSecretListPrefix,
6382
6529
  resolveSecretPath,
6383
6530
  resolveTinyCloudHosts,
@@ -6386,6 +6533,7 @@ function parseRecapCapabilities(parseWasm, siwe) {
6386
6533
  serviceError,
6387
6534
  signLocationRecord,
6388
6535
  submitHostDelegation,
6536
+ tinyCloudDebugLogger,
6389
6537
  validateClientSession,
6390
6538
  validateEnvelope,
6391
6539
  validateLocationRecord,