@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.
@@ -7068,6 +7068,15 @@ function parseArtifactVersionPath(path) {
7068
7068
 
7069
7069
  // src/share-network.ts
7070
7070
  import { sha256 as sha2565 } from "@noble/hashes/sha256";
7071
+
7072
+ // src/encryption-origin.ts
7073
+ var TEE_NODE_ORIGIN = "https://tee.node.tinycloud.xyz";
7074
+ var PRODUCTION_NODE_ORIGINS = /* @__PURE__ */ new Set(["https://node.tinycloud.xyz", TEE_NODE_ORIGIN]);
7075
+ function encryptionNodeOrigin(nodeOrigin) {
7076
+ return PRODUCTION_NODE_ORIGINS.has(nodeOrigin) ? TEE_NODE_ORIGIN : nodeOrigin;
7077
+ }
7078
+
7079
+ // src/share-network.ts
7071
7080
  var SHARE_NETWORK_NAME_PREFIX = "share-";
7072
7081
  var NETWORK_SAFE_SHARE_ID = /^[a-z0-9][a-z0-9-]{15,35}$/;
7073
7082
  var NETWORK_URN = /^urn:tinycloud:encryption:did:pkh:eip155:([1-9]\d*):(0x[0-9a-fA-F]{40}):([a-z0-9][a-z0-9-]*)$/;
@@ -7114,7 +7123,7 @@ async function nodeDidOf(nodeOrigin, fetchFn) {
7114
7123
  return nodeDid;
7115
7124
  }
7116
7125
  async function lookupShareNetwork(nodeOrigin, networkId, fetchFn) {
7117
- const response = await fetchFn(new URL(`/encryption/networks/${encodeURIComponent(networkId)}`, nodeOrigin), { redirect: "error" });
7126
+ const response = await fetchFn(new URL(`/encryption/networks/${encodeURIComponent(networkId)}`, encryptionNodeOrigin(nodeOrigin)), { redirect: "error" });
7118
7127
  if (response.status === 404) return { state: "absent" };
7119
7128
  if (!response.ok) throw new ShareRootError("node-refused", `share network lookup failed: HTTP ${response.status}`);
7120
7129
  let body;
@@ -7162,7 +7171,7 @@ async function sendNetworkAdmin(input) {
7162
7171
  sign: input.signer.sign
7163
7172
  });
7164
7173
  const path = input.action === NETWORK_CREATE_ABILITY ? "/encryption/networks" : `/encryption/networks/${encodeURIComponent(input.networkId)}/revoke`;
7165
- const response = await input.fetch(new URL(path, input.nodeOrigin), {
7174
+ const response = await input.fetch(new URL(path, encryptionNodeOrigin(input.nodeOrigin)), {
7166
7175
  method: "POST",
7167
7176
  redirect: "error",
7168
7177
  headers: { Authorization: invocation.authorization, ...input.action === NETWORK_CREATE_ABILITY ? { "content-type": "application/json" } : {} },
@@ -7376,7 +7385,7 @@ var ShareGrant = class _ShareGrant {
7376
7385
  const signer = this.#signer();
7377
7386
  const first = await lookupShareNetwork(this.nodeOrigin, this.networkId, this.#fetch);
7378
7387
  if (first.state === "absent") {
7379
- const nodeDid = await nodeDidOf(this.nodeOrigin, this.#fetch);
7388
+ const nodeDid = await nodeDidOf(encryptionNodeOrigin(this.nodeOrigin), this.#fetch);
7380
7389
  await sendNetworkAdmin({ nodeOrigin: this.nodeOrigin, nodeDid, networkId: this.networkId, action: NETWORK_CREATE_ABILITY, signer, proof: this.cid, fetch: this.#fetch, now: this.#now });
7381
7390
  return this.assertNetworkActive();
7382
7391
  }
@@ -7396,7 +7405,7 @@ var ShareGrant = class _ShareGrant {
7396
7405
  */
7397
7406
  async retireNetwork() {
7398
7407
  const signer = this.#signer();
7399
- const nodeDid = await nodeDidOf(this.nodeOrigin, this.#fetch);
7408
+ const nodeDid = await nodeDidOf(encryptionNodeOrigin(this.nodeOrigin), this.#fetch);
7400
7409
  return retireShareNetwork({ nodeOrigin: this.nodeOrigin, nodeDid, networkId: this.networkId, signer, proof: this.cid, fetch: this.#fetch, now: this.#now });
7401
7410
  }
7402
7411
  /** Step 4 check (I1): the stored object belongs to this share, on its exact key and network. */
@@ -7723,7 +7732,7 @@ async function runShareControlBatch(input) {
7723
7732
  const imported = await fetchFn(new URL("/delegate", nodeOrigin), { method: "POST", redirect: "error", headers: { Authorization: headerValue(bytes2) } });
7724
7733
  if (!imported.ok) throw new ShareRootError("node-refused", `owner control import failed: HTTP ${imported.status} ${(await imported.text()).slice(0, 120)}`);
7725
7734
  await imported.body?.cancel();
7726
- const nodeDid = await nodeDidOf(nodeOrigin, fetchFn);
7735
+ const nodeDid = await nodeDidOf(encryptionNodeOrigin(nodeOrigin), fetchFn);
7727
7736
  const signer = { did: key.did, sign: (data) => key.sign(data) };
7728
7737
  const networks = [];
7729
7738
  for (const target of batch.targets) {