@tinycloud/share-sdk 1.5.0-beta.2 → 1.5.0-beta.4

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.
@@ -7114,6 +7114,15 @@ function parseArtifactVersionPath(path) {
7114
7114
 
7115
7115
  // src/share-network.ts
7116
7116
  var import_sha2564 = require("@noble/hashes/sha256");
7117
+
7118
+ // src/encryption-origin.ts
7119
+ var TEE_NODE_ORIGIN = "https://tee.node.tinycloud.xyz";
7120
+ var PRODUCTION_NODE_ORIGINS = /* @__PURE__ */ new Set(["https://node.tinycloud.xyz", TEE_NODE_ORIGIN]);
7121
+ function encryptionNodeOrigin(nodeOrigin) {
7122
+ return PRODUCTION_NODE_ORIGINS.has(nodeOrigin) ? TEE_NODE_ORIGIN : nodeOrigin;
7123
+ }
7124
+
7125
+ // src/share-network.ts
7117
7126
  var SHARE_NETWORK_NAME_PREFIX = "share-";
7118
7127
  var NETWORK_SAFE_SHARE_ID = /^[a-z0-9][a-z0-9-]{15,35}$/;
7119
7128
  var NETWORK_URN = /^urn:tinycloud:encryption:did:pkh:eip155:([1-9]\d*):(0x[0-9a-fA-F]{40}):([a-z0-9][a-z0-9-]*)$/;
@@ -7160,7 +7169,7 @@ async function nodeDidOf(nodeOrigin, fetchFn) {
7160
7169
  return nodeDid;
7161
7170
  }
7162
7171
  async function lookupShareNetwork(nodeOrigin, networkId, fetchFn) {
7163
- const response = await fetchFn(new URL(`/encryption/networks/${encodeURIComponent(networkId)}`, nodeOrigin), { redirect: "error" });
7172
+ const response = await fetchFn(new URL(`/encryption/networks/${encodeURIComponent(networkId)}`, encryptionNodeOrigin(nodeOrigin)), { redirect: "error" });
7164
7173
  if (response.status === 404) return { state: "absent" };
7165
7174
  if (!response.ok) throw new ShareRootError("node-refused", `share network lookup failed: HTTP ${response.status}`);
7166
7175
  let body;
@@ -7208,7 +7217,7 @@ async function sendNetworkAdmin(input) {
7208
7217
  sign: input.signer.sign
7209
7218
  });
7210
7219
  const path = input.action === NETWORK_CREATE_ABILITY ? "/encryption/networks" : `/encryption/networks/${encodeURIComponent(input.networkId)}/revoke`;
7211
- const response = await input.fetch(new URL(path, input.nodeOrigin), {
7220
+ const response = await input.fetch(new URL(path, encryptionNodeOrigin(input.nodeOrigin)), {
7212
7221
  method: "POST",
7213
7222
  redirect: "error",
7214
7223
  headers: { Authorization: invocation.authorization, ...input.action === NETWORK_CREATE_ABILITY ? { "content-type": "application/json" } : {} },
@@ -7422,7 +7431,7 @@ var ShareGrant = class _ShareGrant {
7422
7431
  const signer = this.#signer();
7423
7432
  const first = await lookupShareNetwork(this.nodeOrigin, this.networkId, this.#fetch);
7424
7433
  if (first.state === "absent") {
7425
- const nodeDid = await nodeDidOf(this.nodeOrigin, this.#fetch);
7434
+ const nodeDid = await nodeDidOf(encryptionNodeOrigin(this.nodeOrigin), this.#fetch);
7426
7435
  await sendNetworkAdmin({ nodeOrigin: this.nodeOrigin, nodeDid, networkId: this.networkId, action: NETWORK_CREATE_ABILITY, signer, proof: this.cid, fetch: this.#fetch, now: this.#now });
7427
7436
  return this.assertNetworkActive();
7428
7437
  }
@@ -7442,7 +7451,7 @@ var ShareGrant = class _ShareGrant {
7442
7451
  */
7443
7452
  async retireNetwork() {
7444
7453
  const signer = this.#signer();
7445
- const nodeDid = await nodeDidOf(this.nodeOrigin, this.#fetch);
7454
+ const nodeDid = await nodeDidOf(encryptionNodeOrigin(this.nodeOrigin), this.#fetch);
7446
7455
  return retireShareNetwork({ nodeOrigin: this.nodeOrigin, nodeDid, networkId: this.networkId, signer, proof: this.cid, fetch: this.#fetch, now: this.#now });
7447
7456
  }
7448
7457
  /** Step 4 check (I1): the stored object belongs to this share, on its exact key and network. */
@@ -7769,7 +7778,7 @@ async function runShareControlBatch(input) {
7769
7778
  const imported = await fetchFn(new URL("/delegate", nodeOrigin), { method: "POST", redirect: "error", headers: { Authorization: headerValue(bytes2) } });
7770
7779
  if (!imported.ok) throw new ShareRootError("node-refused", `owner control import failed: HTTP ${imported.status} ${(await imported.text()).slice(0, 120)}`);
7771
7780
  await imported.body?.cancel();
7772
- const nodeDid = await nodeDidOf(nodeOrigin, fetchFn);
7781
+ const nodeDid = await nodeDidOf(encryptionNodeOrigin(nodeOrigin), fetchFn);
7773
7782
  const signer = { did: key.did, sign: (data) => key.sign(data) };
7774
7783
  const networks = [];
7775
7784
  for (const target of batch.targets) {