@tinycloud/sdk-core 3.1.0-beta.9 → 3.2.0-beta.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.
- package/dist/{credential-admission-BxpkckU0.d.cts → credential-admission-1EOQgdzY.d.cts} +10 -1
- package/dist/{credential-admission-CO9WMtGs.d.ts → credential-admission-CJ1ZPqcx.d.ts} +10 -1
- package/dist/delegations/index.cjs +19 -12
- package/dist/delegations/index.cjs.map +1 -1
- package/dist/delegations/index.d.cts +2 -2
- package/dist/delegations/index.d.ts +2 -2
- package/dist/delegations/index.js +19 -12
- package/dist/delegations/index.js.map +1 -1
- package/dist/index.cjs +99 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -5
- package/dist/index.d.ts +11 -5
- package/dist/index.js +101 -12
- package/dist/index.js.map +1 -1
- package/dist/policy/index.cjs +29 -0
- package/dist/policy/index.cjs.map +1 -1
- package/dist/policy/index.d.cts +2 -2
- package/dist/policy/index.d.ts +2 -2
- package/dist/policy/index.js +29 -0
- package/dist/policy/index.js.map +1 -1
- package/dist/{recipient-types.schema-_JkBDZB6.d.cts → recipient-types.schema-D-IMys0b.d.cts} +4 -1
- package/dist/{recipient-types.schema-_JkBDZB6.d.ts → recipient-types.schema-D-IMys0b.d.ts} +4 -1
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -43,6 +43,7 @@ __export(index_exports, {
|
|
|
43
43
|
ACCOUNT_MANIFEST_PERMISSIONS: () => import_bootstrap4.ACCOUNT_MANIFEST_PERMISSIONS,
|
|
44
44
|
ACCOUNT_REGISTRY_PATH: () => ACCOUNT_REGISTRY_PATH,
|
|
45
45
|
ACCOUNT_REGISTRY_SPACE: () => ACCOUNT_REGISTRY_SPACE,
|
|
46
|
+
AGENTS_SPACE: () => import_bootstrap4.AGENTS_SPACE,
|
|
46
47
|
ATTESTED_ENFORCER_BINDING_V2_SCHEMA: () => ATTESTED_ENFORCER_BINDING_V2_SCHEMA,
|
|
47
48
|
AccountService: () => AccountService,
|
|
48
49
|
AutoApproveSpaceCreationHandler: () => AutoApproveSpaceCreationHandler,
|
|
@@ -215,6 +216,7 @@ __export(index_exports, {
|
|
|
215
216
|
SpaceErrorCodes: () => SpaceErrorCodes,
|
|
216
217
|
SpaceService: () => SpaceService,
|
|
217
218
|
TINYCLOUD_ACCOUNT_SPACE_MANIFEST: () => import_bootstrap4.TINYCLOUD_ACCOUNT_SPACE_MANIFEST,
|
|
219
|
+
TINYCLOUD_AGENTS_SPACE_MANIFEST: () => import_bootstrap4.TINYCLOUD_AGENTS_SPACE_MANIFEST,
|
|
218
220
|
TINYCLOUD_APPLICATIONS_SPACE_MANIFEST: () => import_bootstrap4.TINYCLOUD_APPLICATIONS_SPACE_MANIFEST,
|
|
219
221
|
TINYCLOUD_CANONICAL_IDENTITY_CLAIM: () => TINYCLOUD_CANONICAL_IDENTITY_CLAIM,
|
|
220
222
|
TINYCLOUD_DEFAULT_SPACE_MANIFEST: () => import_bootstrap4.TINYCLOUD_DEFAULT_SPACE_MANIFEST,
|
|
@@ -398,6 +400,7 @@ __export(index_exports, {
|
|
|
398
400
|
parseSecretCatalogKey: () => import_sdk_services9.parseSecretCatalogKey,
|
|
399
401
|
parseShareArtifact: () => parseShareArtifact,
|
|
400
402
|
parseShareUrl: () => parseShareUrl,
|
|
403
|
+
parseSignedCompactUcanAttenuation: () => parseSignedCompactUcanAttenuation,
|
|
401
404
|
parseSpaceUri: () => parseSpaceUri,
|
|
402
405
|
pkhDid: () => pkhDid,
|
|
403
406
|
policyCidFromCanonicalBytes: () => policyCidFromCanonicalBytes,
|
|
@@ -4680,6 +4683,34 @@ function parseCompactUcanAuthorization(input, expectedCid) {
|
|
|
4680
4683
|
throw new Error("compact UCAN CID does not match exact Authorization bytes");
|
|
4681
4684
|
return { authorization: input, cid: cid2, header, payload };
|
|
4682
4685
|
}
|
|
4686
|
+
var SignedCompactAttenuationSchema = import_zod2.z.record(import_zod2.z.record(import_zod2.z.array(import_zod2.z.unknown()).min(1)));
|
|
4687
|
+
function parseSignedCompactUcanAttenuation(input, expectedCid) {
|
|
4688
|
+
if (typeof input !== "string" || /\s/.test(input))
|
|
4689
|
+
throw new Error("Authorization must be compact UCAN bytes");
|
|
4690
|
+
const segments = input.split(".");
|
|
4691
|
+
if (segments.length !== 3 || segments.some((segment) => segment.length === 0))
|
|
4692
|
+
throw new Error("Authorization must have three compact segments");
|
|
4693
|
+
const [headerSegment, payloadSegment, signatureSegment] = segments;
|
|
4694
|
+
const headerValue = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(decodeBase64Url2(headerSegment)));
|
|
4695
|
+
const payloadValue = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(decodeBase64Url2(payloadSegment)));
|
|
4696
|
+
if (!isRecordValue(headerValue) || !isRecordValue(headerValue.jwk) || headerValue.alg !== "EdDSA" || headerValue.typ !== "JWT" || headerValue.ucv !== "0.10.0" || headerValue.jwk.kty !== "OKP" || headerValue.jwk.crv !== "Ed25519" || !isRecordValue(payloadValue) || typeof payloadValue.iss !== "string")
|
|
4697
|
+
throw new Error("Authorization has an invalid signed UCAN header or issuer");
|
|
4698
|
+
const att = SignedCompactAttenuationSchema.parse(payloadValue.att);
|
|
4699
|
+
const principal = payloadValue.iss.split("#", 1)[0];
|
|
4700
|
+
const didMaterial = principal.startsWith("did:key:") ? base58btc.decode(principal.slice("did:key:".length)) : new Uint8Array();
|
|
4701
|
+
const publicKey = didMaterial.length === 34 && didMaterial[0] === 237 && didMaterial[1] === 1 ? didMaterial.slice(2) : new Uint8Array();
|
|
4702
|
+
const jwkKey = typeof headerValue.jwk.x === "string" ? decodeBase64Url2(headerValue.jwk.x) : new Uint8Array();
|
|
4703
|
+
if (publicKey.length !== 32 || !equalBytes(publicKey, jwkKey))
|
|
4704
|
+
throw new Error("compact UCAN JWK does not bind issuer");
|
|
4705
|
+
const signature = decodeBase64Url2(signatureSegment);
|
|
4706
|
+
if (!import_ed255193.ed25519.verify(signature, new TextEncoder().encode(`${headerSegment}.${payloadSegment}`), publicKey))
|
|
4707
|
+
throw new Error("compact UCAN signature is invalid");
|
|
4708
|
+
if (typeof payloadValue.aud !== "string" || payloadValue.aud.length === 0)
|
|
4709
|
+
throw new Error("compact UCAN signed audience is missing");
|
|
4710
|
+
const cid2 = CID.createV1(85, create(30, (0, import_blake3.blake3)(new TextEncoder().encode(input)))).toString();
|
|
4711
|
+
if (expectedCid !== void 0 && cid2 !== expectedCid) throw new Error("compact UCAN CID does not match exact Authorization bytes");
|
|
4712
|
+
return { cid: cid2, payload: { att, aud: payloadValue.aud } };
|
|
4713
|
+
}
|
|
4683
4714
|
function parsePolicySessionUcan(authorization, expectedProofs) {
|
|
4684
4715
|
const parsed = parseCompactUcanAuthorization(authorization);
|
|
4685
4716
|
const fact = parsed.payload.fct[0];
|
|
@@ -7167,7 +7198,7 @@ var DelegationManager = class {
|
|
|
7167
7198
|
* }
|
|
7168
7199
|
* ```
|
|
7169
7200
|
*/
|
|
7170
|
-
async revoke(cid2) {
|
|
7201
|
+
async revoke(cid2, options2) {
|
|
7171
7202
|
if (!cid2) {
|
|
7172
7203
|
return {
|
|
7173
7204
|
ok: false,
|
|
@@ -7187,15 +7218,20 @@ var DelegationManager = class {
|
|
|
7187
7218
|
)
|
|
7188
7219
|
};
|
|
7189
7220
|
}
|
|
7190
|
-
const
|
|
7191
|
-
|
|
7192
|
-
|
|
7193
|
-
|
|
7194
|
-
|
|
7195
|
-
|
|
7196
|
-
|
|
7197
|
-
|
|
7198
|
-
|
|
7221
|
+
const entry = {
|
|
7222
|
+
resource: `urn:cid:${cid2}`,
|
|
7223
|
+
...options2?.targetSpaceId === void 0 ? {} : { spaceId: options2.targetSpaceId },
|
|
7224
|
+
service: "delegation",
|
|
7225
|
+
path: "",
|
|
7226
|
+
action: DelegationAction.REVOKE
|
|
7227
|
+
};
|
|
7228
|
+
if (options2?.authorityCid !== void 0) {
|
|
7229
|
+
Object.defineProperty(entry, "revokeAuthorityCid", {
|
|
7230
|
+
value: options2.authorityCid,
|
|
7231
|
+
enumerable: false
|
|
7232
|
+
});
|
|
7233
|
+
}
|
|
7234
|
+
const headers = this.invokeAny(this.session, [entry]);
|
|
7199
7235
|
const response = await this.fetchFn(`${this.host}/revoke`, {
|
|
7200
7236
|
method: "POST",
|
|
7201
7237
|
headers
|
|
@@ -7353,7 +7389,8 @@ var DelegationManager = class {
|
|
|
7353
7389
|
)
|
|
7354
7390
|
};
|
|
7355
7391
|
}
|
|
7356
|
-
|
|
7392
|
+
const accountSpaceId = this.accountSpaceId;
|
|
7393
|
+
if (!accountSpaceId) {
|
|
7357
7394
|
return {
|
|
7358
7395
|
ok: false,
|
|
7359
7396
|
error: createError(
|
|
@@ -7364,7 +7401,7 @@ var DelegationManager = class {
|
|
|
7364
7401
|
}
|
|
7365
7402
|
try {
|
|
7366
7403
|
const invocationHeaders = this.invokeAny(this.session, [{
|
|
7367
|
-
spaceId:
|
|
7404
|
+
spaceId: accountSpaceId,
|
|
7368
7405
|
service: "delegation",
|
|
7369
7406
|
path: "",
|
|
7370
7407
|
action: DelegationAction.LIST
|
|
@@ -14408,6 +14445,56 @@ var AccountService = class {
|
|
|
14408
14445
|
await this.upsertSpacesIndexQuietly(registered);
|
|
14409
14446
|
return (0, import_sdk_services7.ok)({ spaces: registered, recoveredFromBatchError: batchResult.error });
|
|
14410
14447
|
},
|
|
14448
|
+
/**
|
|
14449
|
+
* Register only spaces without a registry record (TC-800). Existing
|
|
14450
|
+
* records, including renamed or archived ones, are kept byte-for-byte.
|
|
14451
|
+
* Bootstrap repair uses this on populated accounts.
|
|
14452
|
+
*/
|
|
14453
|
+
registerMissing: async (spaces) => {
|
|
14454
|
+
if (spaces.length === 0) return (0, import_sdk_services7.ok)([]);
|
|
14455
|
+
await this.config.ensureAccountSpaceHosted?.();
|
|
14456
|
+
const kvResult = this.accountKV();
|
|
14457
|
+
if (!kvResult.ok) return kvResult;
|
|
14458
|
+
const kv = kvResult.data;
|
|
14459
|
+
const stored = spaces.map((space) => spaceRecordFromInput(space));
|
|
14460
|
+
const keys = stored.map((record2) => spaceKey(record2.space_id));
|
|
14461
|
+
const read2 = await kv.batchGet(keys);
|
|
14462
|
+
if (!read2.ok) return accountErr(read2.error);
|
|
14463
|
+
const byKey = new Map(read2.data.results.map((result) => [result.key, result.result]));
|
|
14464
|
+
const final = new Array(keys.length);
|
|
14465
|
+
const missing = [];
|
|
14466
|
+
for (let i = 0; i < keys.length; i++) {
|
|
14467
|
+
const key = keys[i];
|
|
14468
|
+
const result = byKey.get(key);
|
|
14469
|
+
if (!result) {
|
|
14470
|
+
return (0, import_sdk_services7.err)((0, import_sdk_services7.serviceError)(
|
|
14471
|
+
import_sdk_services7.ErrorCodes.NETWORK_ERROR,
|
|
14472
|
+
`KV batch read omitted requested key ${JSON.stringify(key)}`,
|
|
14473
|
+
SERVICE_NAME2
|
|
14474
|
+
));
|
|
14475
|
+
}
|
|
14476
|
+
if (result.ok) {
|
|
14477
|
+
final[i] = spaceFromRecord(key, result.data.data);
|
|
14478
|
+
} else if (result.error.code === import_sdk_services7.ErrorCodes.KV_NOT_FOUND) {
|
|
14479
|
+
missing.push({ index: i, key, record: stored[i] });
|
|
14480
|
+
} else {
|
|
14481
|
+
return accountErr(result.error);
|
|
14482
|
+
}
|
|
14483
|
+
}
|
|
14484
|
+
const creates = await Promise.all(missing.map(async ({ index, key, record: record2 }) => {
|
|
14485
|
+
const written = await kv.put(key, record2, { ifNoneMatch: "*" });
|
|
14486
|
+
if (written.ok) return { index, result: (0, import_sdk_services7.ok)(spaceFromRecord(key, record2)) };
|
|
14487
|
+
const raced = await kv.get(key);
|
|
14488
|
+
if (raced.ok) return { index, result: (0, import_sdk_services7.ok)(spaceFromRecord(key, raced.data.data)) };
|
|
14489
|
+
return { index, result: (0, import_sdk_services7.err)(written.error) };
|
|
14490
|
+
}));
|
|
14491
|
+
for (const { index, result } of creates) {
|
|
14492
|
+
if (!result.ok) return accountErr(result.error);
|
|
14493
|
+
final[index] = result.data;
|
|
14494
|
+
}
|
|
14495
|
+
await this.upsertSpacesIndexQuietly(final);
|
|
14496
|
+
return (0, import_sdk_services7.ok)(final);
|
|
14497
|
+
},
|
|
14411
14498
|
syncAccessible: async () => {
|
|
14412
14499
|
const synced = await this.syncAccessibleSpaces({ tolerateStorageFull: false });
|
|
14413
14500
|
return synced.ok ? (0, import_sdk_services7.ok)(synced.data.spaces) : synced;
|