@tinycloud/sdk-core 3.8.0-beta.9 → 3.8.1-beta.1
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-Cg1M9uyV.d.cts → credential-admission-B7_F6Yb3.d.cts} +1 -0
- package/dist/{credential-admission-7I_ymo-C.d.ts → credential-admission-DCJhDFFv.d.ts} +1 -0
- package/dist/delegations/index.cjs +64 -11
- package/dist/delegations/index.cjs.map +1 -1
- package/dist/delegations/index.d.cts +4 -2
- package/dist/delegations/index.d.ts +4 -2
- package/dist/delegations/index.js +56 -3
- package/dist/delegations/index.js.map +1 -1
- package/dist/delegations/issued.cjs +697 -0
- package/dist/delegations/issued.cjs.map +1 -0
- package/dist/delegations/issued.d.cts +54 -0
- package/dist/delegations/issued.d.ts +54 -0
- package/dist/delegations/issued.js +674 -0
- package/dist/delegations/issued.js.map +1 -0
- package/dist/index.cjs +406 -293
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -5
- package/dist/index.d.ts +15 -5
- package/dist/index.js +129 -16
- package/dist/index.js.map +1 -1
- package/dist/policy/index.cjs +4 -6
- 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 +4 -6
- package/dist/policy/index.js.map +1 -1
- package/dist/{recipient-types.schema-D7lM-5Jo.d.cts → recipient-types.schema-BIJcihno.d.cts} +32 -1739
- package/dist/{recipient-types.schema-D7lM-5Jo.d.ts → recipient-types.schema-Ebi5aliq.d.ts} +32 -1739
- package/dist/types.schema-BmN-OnCA.d.cts +1763 -0
- package/dist/types.schema-BmN-OnCA.d.ts +1763 -0
- package/package.json +9 -4
|
@@ -0,0 +1,697 @@
|
|
|
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 __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/delegations/issued.ts
|
|
21
|
+
var issued_exports = {};
|
|
22
|
+
__export(issued_exports, {
|
|
23
|
+
queryAllIssued: () => queryAllIssued,
|
|
24
|
+
queryIssued: () => queryIssued,
|
|
25
|
+
revokeIssued: () => revokeIssued
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(issued_exports);
|
|
28
|
+
|
|
29
|
+
// src/delegations/types.schema.ts
|
|
30
|
+
var import_zod = require("zod");
|
|
31
|
+
var JWKSchema = import_zod.z.object({
|
|
32
|
+
/** Key type (e.g., "EC", "RSA", "OKP") */
|
|
33
|
+
kty: import_zod.z.string(),
|
|
34
|
+
/** Curve for EC/OKP keys (e.g., "P-256", "Ed25519") */
|
|
35
|
+
crv: import_zod.z.string().optional(),
|
|
36
|
+
/** X coordinate for EC keys, public key for OKP */
|
|
37
|
+
x: import_zod.z.string().optional(),
|
|
38
|
+
/** Y coordinate for EC keys */
|
|
39
|
+
y: import_zod.z.string().optional(),
|
|
40
|
+
/** Private key value (d parameter) */
|
|
41
|
+
d: import_zod.z.string().optional(),
|
|
42
|
+
/** Public exponent for RSA keys */
|
|
43
|
+
e: import_zod.z.string().optional(),
|
|
44
|
+
/** Modulus for RSA keys */
|
|
45
|
+
n: import_zod.z.string().optional(),
|
|
46
|
+
/** Key ID */
|
|
47
|
+
kid: import_zod.z.string().optional(),
|
|
48
|
+
/** Algorithm */
|
|
49
|
+
alg: import_zod.z.string().optional(),
|
|
50
|
+
/** Key use (e.g., "sig", "enc") */
|
|
51
|
+
use: import_zod.z.string().optional(),
|
|
52
|
+
/** Key operations (e.g., ["sign", "verify"]) */
|
|
53
|
+
key_ops: import_zod.z.array(import_zod.z.string()).optional()
|
|
54
|
+
});
|
|
55
|
+
var KeyTypeSchema = import_zod.z.enum(["main", "session", "ingested"]);
|
|
56
|
+
var KeyInfoSchema = import_zod.z.object({
|
|
57
|
+
/** Unique identifier for this key */
|
|
58
|
+
id: import_zod.z.string(),
|
|
59
|
+
/** DID associated with this key */
|
|
60
|
+
did: import_zod.z.string(),
|
|
61
|
+
/** Type of key determining its authority level */
|
|
62
|
+
type: KeyTypeSchema,
|
|
63
|
+
/** Private key in JWK format */
|
|
64
|
+
jwk: JWKSchema.optional(),
|
|
65
|
+
/** Priority for key selection (lower = higher priority) */
|
|
66
|
+
priority: import_zod.z.number()
|
|
67
|
+
});
|
|
68
|
+
var DelegationErrorSchema = import_zod.z.object({
|
|
69
|
+
/** Error code for programmatic handling */
|
|
70
|
+
code: import_zod.z.string(),
|
|
71
|
+
/** Human-readable error message */
|
|
72
|
+
message: import_zod.z.string(),
|
|
73
|
+
/** The service that produced the error */
|
|
74
|
+
service: import_zod.z.literal("delegation"),
|
|
75
|
+
/** Original error if wrapping another error */
|
|
76
|
+
cause: import_zod.z.instanceof(Error).optional(),
|
|
77
|
+
/** Additional metadata about the error */
|
|
78
|
+
meta: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()).optional()
|
|
79
|
+
});
|
|
80
|
+
var DelegationErrorCodes = {
|
|
81
|
+
AUTH_REQUIRED: "AUTH_REQUIRED",
|
|
82
|
+
AUTH_UNAUTHORIZED: "AUTH_UNAUTHORIZED",
|
|
83
|
+
AUTH_EXPIRED: "AUTH_EXPIRED",
|
|
84
|
+
NOT_INITIALIZED: "NOT_INITIALIZED",
|
|
85
|
+
NOT_FOUND: "NOT_FOUND",
|
|
86
|
+
REVOKED: "REVOKED",
|
|
87
|
+
NETWORK_ERROR: "NETWORK_ERROR",
|
|
88
|
+
TIMEOUT: "TIMEOUT",
|
|
89
|
+
ABORTED: "ABORTED",
|
|
90
|
+
INVALID_INPUT: "INVALID_INPUT",
|
|
91
|
+
PERMISSION_DENIED: "PERMISSION_DENIED",
|
|
92
|
+
CREATION_FAILED: "CREATION_FAILED",
|
|
93
|
+
REVOCATION_FAILED: "REVOCATION_FAILED",
|
|
94
|
+
INVALID_TOKEN: "INVALID_TOKEN",
|
|
95
|
+
KV_SERVICE_UNAVAILABLE: "KV_SERVICE_UNAVAILABLE",
|
|
96
|
+
DATA_FETCH_FAILED: "DATA_FETCH_FAILED",
|
|
97
|
+
VALIDATION_ERROR: "VALIDATION_ERROR",
|
|
98
|
+
UNSUPPORTED_OPERATION: "UNSUPPORTED_OPERATION",
|
|
99
|
+
/** The node answered 503: the delegation chain is too deep to evaluate right now. Retry later. */
|
|
100
|
+
CHAIN_TOO_DEEP: "CHAIN_TOO_DEEP",
|
|
101
|
+
/** The node answered 400 "invalid delegation query cursor": malformed, foreign or from another filter. Start the listing again without it. */
|
|
102
|
+
INVALID_CURSOR: "INVALID_CURSOR"
|
|
103
|
+
};
|
|
104
|
+
var DelegationSchema = import_zod.z.object({
|
|
105
|
+
/** Content identifier (CID) of the delegation */
|
|
106
|
+
cid: import_zod.z.string(),
|
|
107
|
+
/** DID of the delegate (the party receiving the delegation) */
|
|
108
|
+
delegateDID: import_zod.z.string(),
|
|
109
|
+
/** Space ID this delegation applies to */
|
|
110
|
+
spaceId: import_zod.z.string(),
|
|
111
|
+
/** Resource path this delegation grants access to */
|
|
112
|
+
path: import_zod.z.string(),
|
|
113
|
+
/** Actions this delegation authorizes */
|
|
114
|
+
actions: import_zod.z.array(import_zod.z.string()),
|
|
115
|
+
/** Exact ReCap caveats that constrain every action in this scope. */
|
|
116
|
+
caveats: import_zod.z.array(import_zod.z.record(import_zod.z.string(), import_zod.z.unknown())).optional(),
|
|
117
|
+
/** When this delegation expires (accepts Date or ISO string from JSON) */
|
|
118
|
+
expiry: import_zod.z.coerce.date(),
|
|
119
|
+
/** Whether this delegation has been revoked */
|
|
120
|
+
isRevoked: import_zod.z.boolean(),
|
|
121
|
+
/** DID of the delegator (the party granting the delegation) */
|
|
122
|
+
delegatorDID: import_zod.z.string().optional(),
|
|
123
|
+
/** When this delegation was created (accepts Date or ISO string from JSON) */
|
|
124
|
+
createdAt: import_zod.z.coerce.date().optional(),
|
|
125
|
+
/** Parent delegation CID if this is a sub-delegation */
|
|
126
|
+
parentCid: import_zod.z.string().optional(),
|
|
127
|
+
/** Whether sub-delegation is allowed */
|
|
128
|
+
allowSubDelegation: import_zod.z.boolean().optional(),
|
|
129
|
+
/** Authorization header (UCAN bearer token) */
|
|
130
|
+
authHeader: import_zod.z.string().optional()
|
|
131
|
+
});
|
|
132
|
+
var DelegationStatusSchema = import_zod.z.object({
|
|
133
|
+
cid: import_zod.z.string().min(1),
|
|
134
|
+
status: import_zod.z.enum(["active", "revoked", "expired", "unavailable", "not_found"]),
|
|
135
|
+
exists: import_zod.z.boolean(),
|
|
136
|
+
active: import_zod.z.boolean(),
|
|
137
|
+
revoked: import_zod.z.boolean(),
|
|
138
|
+
expired: import_zod.z.boolean()
|
|
139
|
+
}).strict().superRefine((value, context) => {
|
|
140
|
+
const valid = value.status === "active" ? value.exists && value.active && !value.revoked && !value.expired : value.status === "revoked" ? value.exists && !value.active && value.revoked && !value.expired : value.status === "expired" ? value.exists && !value.active && !value.revoked && value.expired : value.status === "unavailable" ? value.exists && !value.active && !value.revoked && !value.expired : !value.exists && !value.active && !value.revoked && !value.expired;
|
|
141
|
+
if (!valid) {
|
|
142
|
+
context.addIssue({
|
|
143
|
+
code: import_zod.z.ZodIssueCode.custom,
|
|
144
|
+
message: "delegation status flags do not match status"
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
var DelegationRevocationReceiptSchema = import_zod.z.object({
|
|
149
|
+
revoked: import_zod.z.literal(true),
|
|
150
|
+
cid: import_zod.z.string().min(1)
|
|
151
|
+
}).strict();
|
|
152
|
+
var AccountDelegationResourceSchema = import_zod.z.object({
|
|
153
|
+
resource: import_zod.z.string().min(1),
|
|
154
|
+
actions: import_zod.z.array(import_zod.z.string()),
|
|
155
|
+
caveats: import_zod.z.array(import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()))
|
|
156
|
+
}).strict();
|
|
157
|
+
var AccountDelegationDateSchema = import_zod.z.string().datetime({ offset: true }).transform((value) => new Date(value));
|
|
158
|
+
var AccountDelegationRecordSchema = import_zod.z.object({
|
|
159
|
+
cid: import_zod.z.string().min(1),
|
|
160
|
+
direction: import_zod.z.enum(["granted", "received"]),
|
|
161
|
+
delegatorDid: import_zod.z.string().min(1),
|
|
162
|
+
delegateDid: import_zod.z.string().min(1),
|
|
163
|
+
resources: import_zod.z.array(AccountDelegationResourceSchema),
|
|
164
|
+
parents: import_zod.z.array(import_zod.z.string()),
|
|
165
|
+
issuedAt: AccountDelegationDateSchema.nullable(),
|
|
166
|
+
notBefore: AccountDelegationDateSchema.nullable(),
|
|
167
|
+
expiresAt: AccountDelegationDateSchema.nullable(),
|
|
168
|
+
status: import_zod.z.enum(["active", "pending", "expired", "revoked", "ancestor_revoked"]),
|
|
169
|
+
revokedAt: AccountDelegationDateSchema.nullable().optional(),
|
|
170
|
+
revokedBy: import_zod.z.string().optional(),
|
|
171
|
+
revokedAncestorCid: import_zod.z.string().optional()
|
|
172
|
+
}).strict();
|
|
173
|
+
var AccountDelegationPageSchema = import_zod.z.object({
|
|
174
|
+
schemaVersion: import_zod.z.literal(2),
|
|
175
|
+
items: import_zod.z.array(AccountDelegationRecordSchema),
|
|
176
|
+
nextCursor: import_zod.z.string().optional()
|
|
177
|
+
}).strict();
|
|
178
|
+
var AccountDelegationQueryOptionsSchema = import_zod.z.object({
|
|
179
|
+
direction: import_zod.z.enum(["granted", "received", "all", "issued"]).optional(),
|
|
180
|
+
status: import_zod.z.enum(["active", "pending", "expired", "revoked", "ancestor_revoked"]).optional(),
|
|
181
|
+
space: import_zod.z.string().trim().min(1).optional(),
|
|
182
|
+
limit: import_zod.z.number().int().min(1).max(100).optional(),
|
|
183
|
+
cursor: import_zod.z.string().min(1).optional()
|
|
184
|
+
}).strict();
|
|
185
|
+
var CapabilityEntrySchema = import_zod.z.object({
|
|
186
|
+
/** Resource URI this capability applies to */
|
|
187
|
+
resource: import_zod.z.string(),
|
|
188
|
+
/** Action this capability authorizes */
|
|
189
|
+
action: import_zod.z.string(),
|
|
190
|
+
/** Keys that can exercise this capability, ordered by priority */
|
|
191
|
+
keys: import_zod.z.array(KeyInfoSchema),
|
|
192
|
+
/** The delegation that grants this capability */
|
|
193
|
+
delegation: DelegationSchema,
|
|
194
|
+
/** When this capability expires (accepts Date or ISO string from JSON) */
|
|
195
|
+
expiresAt: import_zod.z.coerce.date().optional()
|
|
196
|
+
});
|
|
197
|
+
var DelegationRecordSchema = import_zod.z.object({
|
|
198
|
+
/** Content identifier (CID) of the delegation */
|
|
199
|
+
cid: import_zod.z.string(),
|
|
200
|
+
/** Space ID this delegation applies to */
|
|
201
|
+
spaceId: import_zod.z.string(),
|
|
202
|
+
/** DID of the delegator (grantor) */
|
|
203
|
+
delegator: import_zod.z.string(),
|
|
204
|
+
/** DID of the delegatee (recipient) */
|
|
205
|
+
delegatee: import_zod.z.string(),
|
|
206
|
+
/** Key ID used to sign/exercise this delegation */
|
|
207
|
+
keyId: import_zod.z.string().optional(),
|
|
208
|
+
/** Resource path pattern this delegation grants access to */
|
|
209
|
+
path: import_zod.z.string(),
|
|
210
|
+
/** Actions this delegation authorizes */
|
|
211
|
+
actions: import_zod.z.array(import_zod.z.string()),
|
|
212
|
+
/** When this delegation expires (accepts Date or ISO string from JSON) */
|
|
213
|
+
expiry: import_zod.z.coerce.date().optional(),
|
|
214
|
+
/** When this delegation becomes valid (not before) (accepts Date or ISO string) */
|
|
215
|
+
notBefore: import_zod.z.coerce.date().optional(),
|
|
216
|
+
/** Whether this delegation has been revoked */
|
|
217
|
+
isRevoked: import_zod.z.boolean(),
|
|
218
|
+
/** When this delegation was created (accepts Date or ISO string from JSON) */
|
|
219
|
+
createdAt: import_zod.z.coerce.date(),
|
|
220
|
+
/** Parent delegation CID if this is a sub-delegation */
|
|
221
|
+
parentCid: import_zod.z.string().optional()
|
|
222
|
+
});
|
|
223
|
+
var CreateDelegationParamsSchema = import_zod.z.object({
|
|
224
|
+
/** DID of the delegate (the party receiving the delegation) */
|
|
225
|
+
delegateDID: import_zod.z.string(),
|
|
226
|
+
/** Resource path this delegation grants access to */
|
|
227
|
+
path: import_zod.z.string(),
|
|
228
|
+
/** Actions to authorize */
|
|
229
|
+
actions: import_zod.z.array(import_zod.z.string()),
|
|
230
|
+
/** When this delegation expires (accepts Date or ISO string) */
|
|
231
|
+
expiry: import_zod.z.coerce.date().optional(),
|
|
232
|
+
/** Whether to disable sub-delegation */
|
|
233
|
+
disableSubDelegation: import_zod.z.boolean().optional(),
|
|
234
|
+
/** Optional statement for the SIWE message */
|
|
235
|
+
statement: import_zod.z.string().optional()
|
|
236
|
+
});
|
|
237
|
+
var DelegationChainSchema = import_zod.z.array(DelegationSchema);
|
|
238
|
+
var DelegationChainV2Schema = import_zod.z.object({
|
|
239
|
+
/** The root delegation from the original authority */
|
|
240
|
+
root: DelegationSchema,
|
|
241
|
+
/** Intermediate delegations in the chain (may be empty) */
|
|
242
|
+
chain: import_zod.z.array(DelegationSchema),
|
|
243
|
+
/** The final delegation to the current user */
|
|
244
|
+
leaf: DelegationSchema
|
|
245
|
+
});
|
|
246
|
+
var DelegationDirectionSchema = import_zod.z.enum(["granted", "received", "all"]);
|
|
247
|
+
var DelegationFiltersSchema = import_zod.z.object({
|
|
248
|
+
/** Filter by delegation direction */
|
|
249
|
+
direction: DelegationDirectionSchema.optional(),
|
|
250
|
+
/** Filter by resource path pattern */
|
|
251
|
+
path: import_zod.z.string().optional(),
|
|
252
|
+
/** Filter by required actions */
|
|
253
|
+
actions: import_zod.z.array(import_zod.z.string()).optional(),
|
|
254
|
+
/** Include revoked delegations */
|
|
255
|
+
includeRevoked: import_zod.z.boolean().optional(),
|
|
256
|
+
/** Filter by delegator DID */
|
|
257
|
+
delegator: import_zod.z.string().optional(),
|
|
258
|
+
/** Filter by delegatee DID */
|
|
259
|
+
delegatee: import_zod.z.string().optional(),
|
|
260
|
+
/** Only include delegations valid at this time */
|
|
261
|
+
validAt: import_zod.z.coerce.date().optional(),
|
|
262
|
+
/** Maximum number of results to return */
|
|
263
|
+
limit: import_zod.z.number().optional(),
|
|
264
|
+
/** Cursor for pagination */
|
|
265
|
+
cursor: import_zod.z.string().optional()
|
|
266
|
+
});
|
|
267
|
+
var SpaceOwnershipSchema = import_zod.z.enum(["owned", "delegated"]);
|
|
268
|
+
var SpaceInfoSchema = import_zod.z.object({
|
|
269
|
+
/** Space identifier */
|
|
270
|
+
id: import_zod.z.string(),
|
|
271
|
+
/** Human-readable name for the space */
|
|
272
|
+
name: import_zod.z.string().optional(),
|
|
273
|
+
/** DID of the space owner */
|
|
274
|
+
owner: import_zod.z.string(),
|
|
275
|
+
/** Whether user owns or has delegated access */
|
|
276
|
+
type: SpaceOwnershipSchema,
|
|
277
|
+
/** Permissions the user has in this space */
|
|
278
|
+
permissions: import_zod.z.array(import_zod.z.string()).optional(),
|
|
279
|
+
/** When the access expires (for delegated spaces) */
|
|
280
|
+
expiresAt: import_zod.z.coerce.date().optional()
|
|
281
|
+
});
|
|
282
|
+
var ShareSchemaSchema = import_zod.z.enum(["base64", "compact", "ipfs"]);
|
|
283
|
+
var ShareLinkSchema = import_zod.z.object({
|
|
284
|
+
/** Unique token identifying this share link */
|
|
285
|
+
token: import_zod.z.string(),
|
|
286
|
+
/** Full URL for sharing */
|
|
287
|
+
url: import_zod.z.string(),
|
|
288
|
+
/** The delegation this link grants access to */
|
|
289
|
+
delegation: DelegationSchema,
|
|
290
|
+
/** Encoding schema used for the link */
|
|
291
|
+
schema: ShareSchemaSchema,
|
|
292
|
+
/** When this share link expires */
|
|
293
|
+
expiresAt: import_zod.z.coerce.date().optional(),
|
|
294
|
+
/** Human-readable description of what is being shared */
|
|
295
|
+
description: import_zod.z.string().optional()
|
|
296
|
+
});
|
|
297
|
+
function createShareLinkDataSchema(dataSchema) {
|
|
298
|
+
return import_zod.z.object({
|
|
299
|
+
/** The retrieved data */
|
|
300
|
+
data: dataSchema,
|
|
301
|
+
/** The delegation that authorized this access */
|
|
302
|
+
delegation: DelegationSchema,
|
|
303
|
+
/** The space the data belongs to */
|
|
304
|
+
spaceId: import_zod.z.string(),
|
|
305
|
+
/** The resource path that was accessed */
|
|
306
|
+
path: import_zod.z.string()
|
|
307
|
+
});
|
|
308
|
+
}
|
|
309
|
+
var ShareLinkDataSchema = createShareLinkDataSchema(import_zod.z.unknown());
|
|
310
|
+
var IngestOptionsSchema = import_zod.z.object({
|
|
311
|
+
/** Whether to persist the delegation to storage */
|
|
312
|
+
persist: import_zod.z.boolean().optional(),
|
|
313
|
+
/** Whether to validate the full delegation chain */
|
|
314
|
+
validateChain: import_zod.z.boolean().optional(),
|
|
315
|
+
/** Name for the ingested key */
|
|
316
|
+
keyName: import_zod.z.string().optional(),
|
|
317
|
+
/** Whether to create a session key for this delegation */
|
|
318
|
+
createSessionKey: import_zod.z.boolean().optional(),
|
|
319
|
+
/** Override the priority for the ingested key */
|
|
320
|
+
priority: import_zod.z.number().optional()
|
|
321
|
+
});
|
|
322
|
+
var GenerateShareParamsSchema = import_zod.z.object({
|
|
323
|
+
/** Resource path to share */
|
|
324
|
+
path: import_zod.z.string(),
|
|
325
|
+
/** Actions to authorize */
|
|
326
|
+
actions: import_zod.z.array(import_zod.z.string()).optional(),
|
|
327
|
+
/** When the share link expires */
|
|
328
|
+
expiry: import_zod.z.coerce.date().optional(),
|
|
329
|
+
/** Encoding schema for the link */
|
|
330
|
+
schema: ShareSchemaSchema.optional(),
|
|
331
|
+
/** Human-readable description */
|
|
332
|
+
description: import_zod.z.string().optional(),
|
|
333
|
+
/** Base URL for the share link */
|
|
334
|
+
baseUrl: import_zod.z.string().optional(),
|
|
335
|
+
/**
|
|
336
|
+
* Whether the recipient may re-delegate the share. Default `true`.
|
|
337
|
+
* `false` issues a terminal delegation: the node refuses onward `/delegate`.
|
|
338
|
+
* Without a session-key delegation that covers the path, `false` fails with PERMISSION_DENIED.
|
|
339
|
+
* Receive such a share with `receive(link, { autoSubdelegate: false })`; the default auto-subdelegation is refused for it.
|
|
340
|
+
*/
|
|
341
|
+
allowSubDelegation: import_zod.z.boolean().optional()
|
|
342
|
+
});
|
|
343
|
+
var DelegationManagerConfigSchema = import_zod.z.object({
|
|
344
|
+
/** TinyCloud host URLs */
|
|
345
|
+
hosts: import_zod.z.array(import_zod.z.string()),
|
|
346
|
+
/** Account space used by account-wide delegation history queries */
|
|
347
|
+
accountSpaceId: import_zod.z.string().min(1).optional(),
|
|
348
|
+
/** Active session for authentication */
|
|
349
|
+
session: import_zod.z.unknown().refine(
|
|
350
|
+
(val) => val !== null && typeof val === "object",
|
|
351
|
+
{ message: "Expected a ServiceSession object" }
|
|
352
|
+
),
|
|
353
|
+
/** Platform-specific invoke function */
|
|
354
|
+
invoke: import_zod.z.unknown().refine(
|
|
355
|
+
(val) => typeof val === "function",
|
|
356
|
+
{ message: "Expected an invoke function" }
|
|
357
|
+
),
|
|
358
|
+
/** Platform-specific invoke function for raw resource URIs */
|
|
359
|
+
invokeAny: import_zod.z.unknown().refine(
|
|
360
|
+
(val) => val === void 0 || typeof val === "function",
|
|
361
|
+
{ message: "Expected an invokeAny function or undefined" }
|
|
362
|
+
).optional(),
|
|
363
|
+
/** Optional owner-signed authorization for direct CID revocation */
|
|
364
|
+
signOwnerRevocation: import_zod.z.custom().optional(),
|
|
365
|
+
/** Optional signer for proofless invocations by the session's own did:key (issued-delegation list and revoke) */
|
|
366
|
+
sessionInvocationSigner: import_zod.z.custom().optional(),
|
|
367
|
+
/** Optional custom fetch implementation */
|
|
368
|
+
fetch: import_zod.z.unknown().refine(
|
|
369
|
+
(val) => val === void 0 || typeof val === "function",
|
|
370
|
+
{ message: "Expected a fetch function or undefined" }
|
|
371
|
+
).optional()
|
|
372
|
+
});
|
|
373
|
+
var KeyProviderSchema = import_zod.z.object({
|
|
374
|
+
/** Generate a new session key, returns key ID */
|
|
375
|
+
createSessionKey: import_zod.z.unknown().refine(
|
|
376
|
+
(val) => typeof val === "function",
|
|
377
|
+
{ message: "Expected a function" }
|
|
378
|
+
),
|
|
379
|
+
/** Get JWK for a key */
|
|
380
|
+
getJWK: import_zod.z.unknown().refine(
|
|
381
|
+
(val) => typeof val === "function",
|
|
382
|
+
{ message: "Expected a function" }
|
|
383
|
+
),
|
|
384
|
+
/** Get DID for a key */
|
|
385
|
+
getDID: import_zod.z.unknown().refine(
|
|
386
|
+
(val) => typeof val === "function",
|
|
387
|
+
{ message: "Expected a function" }
|
|
388
|
+
)
|
|
389
|
+
});
|
|
390
|
+
var DelegationApiResponseSchema = import_zod.z.object({
|
|
391
|
+
/** SIWE message content */
|
|
392
|
+
siwe: import_zod.z.string(),
|
|
393
|
+
/** Signature of the SIWE message */
|
|
394
|
+
signature: import_zod.z.string(),
|
|
395
|
+
/** Delegation version */
|
|
396
|
+
version: import_zod.z.number(),
|
|
397
|
+
/** CID of the created delegation */
|
|
398
|
+
cid: import_zod.z.string().optional()
|
|
399
|
+
});
|
|
400
|
+
var DelegatedResourceSchema = import_zod.z.object({
|
|
401
|
+
/** Short-form service name, e.g. "kv", "sql", "duckdb", "capabilities", "hooks". */
|
|
402
|
+
service: import_zod.z.string(),
|
|
403
|
+
/** Full space id string, e.g. "tinycloud:pkh:eip155:1:0x....:default". */
|
|
404
|
+
space: import_zod.z.string(),
|
|
405
|
+
/** Resource path; empty string when the resource URI had no path segment. */
|
|
406
|
+
path: import_zod.z.string(),
|
|
407
|
+
/** Full-URN ability strings, e.g. ["tinycloud.kv/get", "tinycloud.kv/put"]. */
|
|
408
|
+
actions: import_zod.z.array(import_zod.z.string()),
|
|
409
|
+
/** Exact ReCap caveats that constrain every action in this scope. */
|
|
410
|
+
caveats: import_zod.z.array(import_zod.z.record(import_zod.z.string(), import_zod.z.unknown())).optional()
|
|
411
|
+
});
|
|
412
|
+
var CreateDelegationWasmParamsSchema = import_zod.z.object({
|
|
413
|
+
/** The session containing delegation credentials */
|
|
414
|
+
session: import_zod.z.unknown().refine(
|
|
415
|
+
(val) => val !== null && typeof val === "object",
|
|
416
|
+
{ message: "Expected a ServiceSession object" }
|
|
417
|
+
),
|
|
418
|
+
/** DID of the delegate */
|
|
419
|
+
delegateDID: import_zod.z.string(),
|
|
420
|
+
/** Space ID this delegation applies to */
|
|
421
|
+
spaceId: import_zod.z.string(),
|
|
422
|
+
/**
|
|
423
|
+
* Multi-resource abilities map: short-service → path → full-URN actions.
|
|
424
|
+
* Matches the shape accepted by `prepareSession`.
|
|
425
|
+
*
|
|
426
|
+
* Example:
|
|
427
|
+
* ```
|
|
428
|
+
* {
|
|
429
|
+
* kv: {
|
|
430
|
+
* "com.listen.app/": ["tinycloud.kv/get", "tinycloud.kv/put"]
|
|
431
|
+
* },
|
|
432
|
+
* sql: {
|
|
433
|
+
* "com.listen.app/data.sqlite": ["tinycloud.sql/read"]
|
|
434
|
+
* }
|
|
435
|
+
* }
|
|
436
|
+
* ```
|
|
437
|
+
*/
|
|
438
|
+
abilities: import_zod.z.record(import_zod.z.string(), import_zod.z.record(import_zod.z.string(), import_zod.z.array(import_zod.z.string()))),
|
|
439
|
+
/** Expiration time in seconds since Unix epoch */
|
|
440
|
+
expirationSecs: import_zod.z.number(),
|
|
441
|
+
/** Optional not-before time in seconds since Unix epoch */
|
|
442
|
+
notBeforeSecs: import_zod.z.number().optional(),
|
|
443
|
+
/** Issue a terminal delegation: the node refuses onward delegation. Default `false`. */
|
|
444
|
+
disableSubDelegation: import_zod.z.boolean().optional()
|
|
445
|
+
});
|
|
446
|
+
var CreateDelegationWasmResultSchema = import_zod.z.object({
|
|
447
|
+
/** Base64url-encoded UCAN delegation */
|
|
448
|
+
delegation: import_zod.z.string(),
|
|
449
|
+
/** CID of the delegation */
|
|
450
|
+
cid: import_zod.z.string(),
|
|
451
|
+
/** DID of the delegate */
|
|
452
|
+
delegateDID: import_zod.z.string(),
|
|
453
|
+
/** Expiration time */
|
|
454
|
+
expiry: import_zod.z.coerce.date(),
|
|
455
|
+
/**
|
|
456
|
+
* All (service, space, path, actions) entries granted by this delegation.
|
|
457
|
+
* Always non-empty on success.
|
|
458
|
+
*/
|
|
459
|
+
resources: import_zod.z.array(DelegatedResourceSchema)
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
// src/delegations/shared.ts
|
|
463
|
+
var DelegationAction = {
|
|
464
|
+
REVOKE: "tinycloud.delegation/revoke",
|
|
465
|
+
STATUS: "tinycloud.delegation/status",
|
|
466
|
+
LIST: "tinycloud.delegation/list",
|
|
467
|
+
GET: "tinycloud.delegation/get",
|
|
468
|
+
CHECK: "tinycloud.delegation/check"
|
|
469
|
+
};
|
|
470
|
+
function createError(code, message, cause, meta) {
|
|
471
|
+
return {
|
|
472
|
+
code,
|
|
473
|
+
message,
|
|
474
|
+
service: "delegation",
|
|
475
|
+
cause,
|
|
476
|
+
meta
|
|
477
|
+
};
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
// src/delegations/issued.ts
|
|
481
|
+
var ISSUED_QUERY_FEATURE = "delegation-issued-query-v1";
|
|
482
|
+
async function refusalText(response) {
|
|
483
|
+
const text = await response.text();
|
|
484
|
+
return text.replace(/[\u0000-\u001f\u007f]+/g, " ").trim().slice(0, 200);
|
|
485
|
+
}
|
|
486
|
+
async function issuedHttpError(response, what, meta) {
|
|
487
|
+
const text = await refusalText(response);
|
|
488
|
+
const details = { ...meta, status: response.status };
|
|
489
|
+
if (response.status === 401 || response.status === 403) {
|
|
490
|
+
return createError(
|
|
491
|
+
DelegationErrorCodes.PERMISSION_DENIED,
|
|
492
|
+
text === "" ? "The node refused the request" : text,
|
|
493
|
+
void 0,
|
|
494
|
+
details
|
|
495
|
+
);
|
|
496
|
+
}
|
|
497
|
+
if (response.status === 400 && text.includes("invalid delegation query cursor")) {
|
|
498
|
+
return createError(
|
|
499
|
+
DelegationErrorCodes.INVALID_CURSOR,
|
|
500
|
+
"The node rejected the page cursor; list again from the start",
|
|
501
|
+
void 0,
|
|
502
|
+
details
|
|
503
|
+
);
|
|
504
|
+
}
|
|
505
|
+
if (response.status === 503) {
|
|
506
|
+
return createError(
|
|
507
|
+
DelegationErrorCodes.CHAIN_TOO_DEEP,
|
|
508
|
+
"This delegation chain is too long for the node to check right now; try again later",
|
|
509
|
+
void 0,
|
|
510
|
+
{ ...details, retryable: true }
|
|
511
|
+
);
|
|
512
|
+
}
|
|
513
|
+
return createError(
|
|
514
|
+
DelegationErrorCodes.NETWORK_ERROR,
|
|
515
|
+
`${what}: ${response.status} - ${text}`,
|
|
516
|
+
void 0,
|
|
517
|
+
details
|
|
518
|
+
);
|
|
519
|
+
}
|
|
520
|
+
async function nodeListsIssued(ctx) {
|
|
521
|
+
if (ctx.state.issuedQuerySupported) return { ok: true, data: true };
|
|
522
|
+
const response = await ctx.fetchFn(`${ctx.host}/info`);
|
|
523
|
+
if (!response.ok) {
|
|
524
|
+
return {
|
|
525
|
+
ok: false,
|
|
526
|
+
error: createError(
|
|
527
|
+
DelegationErrorCodes.NETWORK_ERROR,
|
|
528
|
+
`Couldn't read the node's info: ${response.status}`,
|
|
529
|
+
void 0,
|
|
530
|
+
{ status: response.status }
|
|
531
|
+
)
|
|
532
|
+
};
|
|
533
|
+
}
|
|
534
|
+
const info = await response.json();
|
|
535
|
+
ctx.state.issuedQuerySupported = Array.isArray(info.features) && info.features.includes(ISSUED_QUERY_FEATURE);
|
|
536
|
+
return { ok: true, data: ctx.state.issuedQuerySupported };
|
|
537
|
+
}
|
|
538
|
+
async function queryIssued(ctx, options) {
|
|
539
|
+
const signer = ctx.sessionInvocationSigner;
|
|
540
|
+
if (!signer) {
|
|
541
|
+
return {
|
|
542
|
+
ok: false,
|
|
543
|
+
error: createError(
|
|
544
|
+
DelegationErrorCodes.NOT_INITIALIZED,
|
|
545
|
+
"Listing issued delegations needs a session key signer"
|
|
546
|
+
)
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
try {
|
|
550
|
+
const supported = await nodeListsIssued(ctx);
|
|
551
|
+
if (!supported.ok) return supported;
|
|
552
|
+
if (!supported.data) {
|
|
553
|
+
return {
|
|
554
|
+
ok: false,
|
|
555
|
+
error: createError(
|
|
556
|
+
DelegationErrorCodes.UNSUPPORTED_OPERATION,
|
|
557
|
+
"This node doesn't support listing issued delegations yet",
|
|
558
|
+
void 0,
|
|
559
|
+
{ feature: ISSUED_QUERY_FEATURE }
|
|
560
|
+
)
|
|
561
|
+
};
|
|
562
|
+
}
|
|
563
|
+
const authorization = await signer.sign({
|
|
564
|
+
[`${signer.did()}/delegation`]: { [DelegationAction.LIST]: [{}] }
|
|
565
|
+
});
|
|
566
|
+
const response = await ctx.fetchFn(`${ctx.host}/delegation/query`, {
|
|
567
|
+
method: "POST",
|
|
568
|
+
headers: { Authorization: authorization, "content-type": "application/json" },
|
|
569
|
+
body: JSON.stringify(options)
|
|
570
|
+
});
|
|
571
|
+
if (!response.ok) {
|
|
572
|
+
return {
|
|
573
|
+
ok: false,
|
|
574
|
+
error: await issuedHttpError(response, "Failed to query issued delegations", {})
|
|
575
|
+
};
|
|
576
|
+
}
|
|
577
|
+
const parsed = AccountDelegationPageSchema.safeParse(await response.json());
|
|
578
|
+
if (!parsed.success) {
|
|
579
|
+
return {
|
|
580
|
+
ok: false,
|
|
581
|
+
error: createError(
|
|
582
|
+
DelegationErrorCodes.INVALID_TOKEN,
|
|
583
|
+
"Node returned an invalid delegation query response"
|
|
584
|
+
)
|
|
585
|
+
};
|
|
586
|
+
}
|
|
587
|
+
return { ok: true, data: parsed.data };
|
|
588
|
+
} catch (error) {
|
|
589
|
+
return {
|
|
590
|
+
ok: false,
|
|
591
|
+
error: createError(
|
|
592
|
+
DelegationErrorCodes.NETWORK_ERROR,
|
|
593
|
+
`Network error during delegation query: ${String(error)}`,
|
|
594
|
+
error instanceof Error ? error : void 0
|
|
595
|
+
)
|
|
596
|
+
};
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
async function queryAllIssued(query, options) {
|
|
600
|
+
const { pageSize = 100, maxItems, untilCid, ...filters } = options;
|
|
601
|
+
if (maxItems !== void 0 && (!Number.isInteger(maxItems) || maxItems < 1)) {
|
|
602
|
+
return {
|
|
603
|
+
ok: false,
|
|
604
|
+
error: createError(DelegationErrorCodes.INVALID_INPUT, "maxItems must be a positive integer")
|
|
605
|
+
};
|
|
606
|
+
}
|
|
607
|
+
const items = [];
|
|
608
|
+
const seen = /* @__PURE__ */ new Set();
|
|
609
|
+
let cursor;
|
|
610
|
+
do {
|
|
611
|
+
const limit = Math.min(pageSize, maxItems === void 0 ? pageSize : maxItems - items.length);
|
|
612
|
+
const page = await query({
|
|
613
|
+
...filters,
|
|
614
|
+
direction: "issued",
|
|
615
|
+
limit,
|
|
616
|
+
...cursor === void 0 ? {} : { cursor }
|
|
617
|
+
});
|
|
618
|
+
if (!page.ok) return page;
|
|
619
|
+
items.push(...page.data.items);
|
|
620
|
+
cursor = page.data.nextCursor;
|
|
621
|
+
if (cursor !== void 0) {
|
|
622
|
+
if (seen.has(cursor)) {
|
|
623
|
+
return {
|
|
624
|
+
ok: false,
|
|
625
|
+
error: createError(
|
|
626
|
+
DelegationErrorCodes.INVALID_TOKEN,
|
|
627
|
+
"The node returned the same page cursor twice while listing issued delegations"
|
|
628
|
+
)
|
|
629
|
+
};
|
|
630
|
+
}
|
|
631
|
+
seen.add(cursor);
|
|
632
|
+
}
|
|
633
|
+
} while (cursor !== void 0 && (maxItems === void 0 || items.length < maxItems) && !(untilCid !== void 0 && items.some((item) => item.cid === untilCid)));
|
|
634
|
+
return { ok: true, data: maxItems === void 0 ? items : items.slice(0, maxItems) };
|
|
635
|
+
}
|
|
636
|
+
async function revokeIssued(ctx, cid) {
|
|
637
|
+
if (!cid) {
|
|
638
|
+
return {
|
|
639
|
+
ok: false,
|
|
640
|
+
error: createError(DelegationErrorCodes.INVALID_INPUT, "cid is required")
|
|
641
|
+
};
|
|
642
|
+
}
|
|
643
|
+
const signer = ctx.sessionInvocationSigner;
|
|
644
|
+
if (!signer) {
|
|
645
|
+
return {
|
|
646
|
+
ok: false,
|
|
647
|
+
error: createError(
|
|
648
|
+
DelegationErrorCodes.NOT_INITIALIZED,
|
|
649
|
+
"Revoking an issued delegation needs a session key signer"
|
|
650
|
+
)
|
|
651
|
+
};
|
|
652
|
+
}
|
|
653
|
+
try {
|
|
654
|
+
const authorization = await signer.sign({
|
|
655
|
+
[`urn:cid:${cid}`]: { [DelegationAction.REVOKE]: [{}] }
|
|
656
|
+
});
|
|
657
|
+
const response = await ctx.fetchFn(`${ctx.host}/revoke`, {
|
|
658
|
+
method: "POST",
|
|
659
|
+
headers: { Authorization: authorization }
|
|
660
|
+
});
|
|
661
|
+
if (!response.ok) {
|
|
662
|
+
if (response.status === 404) {
|
|
663
|
+
return {
|
|
664
|
+
ok: false,
|
|
665
|
+
error: createError(DelegationErrorCodes.NOT_FOUND, `Delegation not found: ${cid}`)
|
|
666
|
+
};
|
|
667
|
+
}
|
|
668
|
+
return {
|
|
669
|
+
ok: false,
|
|
670
|
+
error: await issuedHttpError(response, "Failed to revoke delegation", { cid })
|
|
671
|
+
};
|
|
672
|
+
}
|
|
673
|
+
const parsed = DelegationRevocationReceiptSchema.safeParse(await response.json());
|
|
674
|
+
if (!parsed.success || parsed.data.cid !== cid) {
|
|
675
|
+
return {
|
|
676
|
+
ok: false,
|
|
677
|
+
error: createError(
|
|
678
|
+
DelegationErrorCodes.REVOCATION_FAILED,
|
|
679
|
+
"Node returned an invalid delegation revocation receipt",
|
|
680
|
+
void 0,
|
|
681
|
+
{ cid }
|
|
682
|
+
)
|
|
683
|
+
};
|
|
684
|
+
}
|
|
685
|
+
return { ok: true, data: parsed.data };
|
|
686
|
+
} catch (error) {
|
|
687
|
+
return {
|
|
688
|
+
ok: false,
|
|
689
|
+
error: createError(
|
|
690
|
+
DelegationErrorCodes.NETWORK_ERROR,
|
|
691
|
+
`Network error during delegation revocation: ${String(error)}`,
|
|
692
|
+
error instanceof Error ? error : void 0
|
|
693
|
+
)
|
|
694
|
+
};
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
//# sourceMappingURL=issued.cjs.map
|