@tinycloud/sdk-core 2.11.0-beta.10 → 2.11.0-beta.12
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/{capability-BjzXwtNw.d.cts → capability-BA49Uboq.d.cts} +1 -1
- package/dist/{capability-BjzXwtNw.d.ts → capability-BA49Uboq.d.ts} +1 -1
- package/dist/delegations/index.cjs +620 -221
- package/dist/delegations/index.cjs.map +1 -1
- package/dist/delegations/index.d.cts +8 -8
- package/dist/delegations/index.d.ts +8 -8
- package/dist/delegations/index.js +621 -222
- package/dist/delegations/index.js.map +1 -1
- package/dist/index.cjs +1576 -762
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -15
- package/dist/index.d.ts +15 -15
- package/dist/index.js +1548 -732
- package/dist/index.js.map +1 -1
- package/dist/policy/index.cjs +867 -175
- package/dist/policy/index.cjs.map +1 -1
- package/dist/policy/index.d.cts +5 -4
- package/dist/policy/index.d.ts +5 -4
- package/dist/policy/index.js +867 -175
- package/dist/policy/index.js.map +1 -1
- package/dist/{recipient-types.schema-D5pDlIqn.d.cts → recipient-types.schema-CuDpskPd.d.cts} +172 -115
- package/dist/{recipient-types.schema-D5pDlIqn.d.ts → recipient-types.schema-CuDpskPd.d.ts} +172 -115
- package/dist/requester/index.d.cts +1 -1
- package/dist/requester/index.d.ts +1 -1
- package/dist/unified-DbySI5wW.d.cts +429 -0
- package/dist/unified-tCGtc-Wx.d.ts +429 -0
- package/package.json +5 -5
- package/dist/signed-object-C6mWbTbB.d.ts +0 -149
- package/dist/signed-object-IMAm5a32.d.cts +0 -149
package/dist/index.cjs
CHANGED
|
@@ -39,23 +39,27 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
|
|
|
39
39
|
// src/index.ts
|
|
40
40
|
var index_exports = {};
|
|
41
41
|
__export(index_exports, {
|
|
42
|
-
ACCOUNT_INDEX_SCHEMA: () =>
|
|
42
|
+
ACCOUNT_INDEX_SCHEMA: () => import_bootstrap4.ACCOUNT_INDEX_SCHEMA,
|
|
43
|
+
ACCOUNT_MANIFEST_PERMISSIONS: () => import_bootstrap4.ACCOUNT_MANIFEST_PERMISSIONS,
|
|
43
44
|
ACCOUNT_REGISTRY_PATH: () => ACCOUNT_REGISTRY_PATH,
|
|
44
45
|
ACCOUNT_REGISTRY_SPACE: () => ACCOUNT_REGISTRY_SPACE,
|
|
46
|
+
ATTESTED_ENFORCER_BINDING_V2_SCHEMA: () => ATTESTED_ENFORCER_BINDING_V2_SCHEMA,
|
|
45
47
|
AccountService: () => AccountService,
|
|
46
48
|
AutoApproveSpaceCreationHandler: () => AutoApproveSpaceCreationHandler,
|
|
47
|
-
BOOTSTRAP_ALLOWLIST: () =>
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
49
|
+
BOOTSTRAP_ALLOWLIST: () => import_bootstrap4.BOOTSTRAP_ALLOWLIST,
|
|
50
|
+
BOOTSTRAP_DEFAULT_ONLY_SESSION_REQUEST: () => import_bootstrap4.BOOTSTRAP_DEFAULT_ONLY_SESSION_REQUEST,
|
|
51
|
+
BOOTSTRAP_DEFAULT_SPACE: () => import_bootstrap4.BOOTSTRAP_DEFAULT_SPACE,
|
|
52
|
+
BOOTSTRAP_ENCRYPTION_NETWORK_NAME: () => import_bootstrap4.BOOTSTRAP_ENCRYPTION_NETWORK_NAME,
|
|
53
|
+
BOOTSTRAP_ENCRYPTION_NETWORK_RESOURCE_TEMPLATE: () => import_bootstrap4.BOOTSTRAP_ENCRYPTION_NETWORK_RESOURCE_TEMPLATE,
|
|
54
|
+
BOOTSTRAP_MANIFEST: () => import_bootstrap4.BOOTSTRAP_MANIFEST,
|
|
55
|
+
BOOTSTRAP_PERSISTED_APPLICATION_MANIFESTS: () => import_bootstrap4.BOOTSTRAP_PERSISTED_APPLICATION_MANIFESTS,
|
|
56
|
+
BOOTSTRAP_PUBLIC_SPACE: () => import_bootstrap4.BOOTSTRAP_PUBLIC_SPACE,
|
|
57
|
+
BOOTSTRAP_SESSION_REQUESTS: () => import_bootstrap4.BOOTSTRAP_SESSION_REQUESTS,
|
|
58
|
+
BOOTSTRAP_SPACE_MANIFESTS: () => import_bootstrap4.BOOTSTRAP_SPACE_MANIFESTS,
|
|
59
|
+
BOOTSTRAP_SPACE_NAMES: () => import_bootstrap4.BOOTSTRAP_SPACE_NAMES,
|
|
60
|
+
CAPABILITIES: () => import_bootstrap4.CAPABILITIES,
|
|
61
|
+
CAPABILITY_REGISTRY: () => import_bootstrap4.CAPABILITY_REGISTRY,
|
|
62
|
+
CONTENT_SOURCE_V1_DOMAIN: () => CONTENT_SOURCE_V1_DOMAIN,
|
|
59
63
|
CapabilityKeyRegistry: () => CapabilityKeyRegistry,
|
|
60
64
|
CapabilityKeyRegistryErrorCodes: () => CapabilityKeyRegistryErrorCodes,
|
|
61
65
|
CaveatedDelegationUnsupportedError: () => CaveatedDelegationUnsupportedError,
|
|
@@ -76,7 +80,7 @@ __export(index_exports, {
|
|
|
76
80
|
DEFAULT_SIGNED_READ_URL_EXPIRY_MS: () => DEFAULT_SIGNED_READ_URL_EXPIRY_MS,
|
|
77
81
|
DEFAULT_TINYCLOUD_FALLBACK_HOST: () => DEFAULT_TINYCLOUD_FALLBACK_HOST,
|
|
78
82
|
DEFAULT_TINYCLOUD_LOCATION_REGISTRY_URL: () => DEFAULT_TINYCLOUD_LOCATION_REGISTRY_URL,
|
|
79
|
-
DUCKDB: () =>
|
|
83
|
+
DUCKDB: () => import_bootstrap4.DUCKDB,
|
|
80
84
|
DataVaultService: () => import_sdk_services8.DataVaultService,
|
|
81
85
|
DatabaseHandle: () => import_sdk_services8.DatabaseHandle,
|
|
82
86
|
DecryptTransportResponseError: () => import_sdk_services8.DecryptTransportResponseError,
|
|
@@ -87,7 +91,7 @@ __export(index_exports, {
|
|
|
87
91
|
DuckDbService: () => import_sdk_services8.DuckDbService,
|
|
88
92
|
ED25519_JCS_SIGNATURE_SUITE: () => ED25519_JCS_SIGNATURE_SUITE,
|
|
89
93
|
EIP191_JCS_SIGNATURE_SUITE: () => EIP191_JCS_SIGNATURE_SUITE,
|
|
90
|
-
ENCRYPTION: () =>
|
|
94
|
+
ENCRYPTION: () => import_bootstrap4.ENCRYPTION,
|
|
91
95
|
ENCRYPTION_MANIFEST_SPACE: () => ENCRYPTION_MANIFEST_SPACE,
|
|
92
96
|
ENCRYPTION_NETWORK_URN_PREFIX: () => import_sdk_services8.ENCRYPTION_NETWORK_URN_PREFIX,
|
|
93
97
|
ENCRYPTION_PERMISSION_SERVICE: () => ENCRYPTION_PERMISSION_SERVICE,
|
|
@@ -99,17 +103,20 @@ __export(index_exports, {
|
|
|
99
103
|
EnsDataSchema: () => EnsDataSchema,
|
|
100
104
|
ErrorCodes: () => import_sdk_services8.ErrorCodes,
|
|
101
105
|
HOLDER_KEY_BINDING_PRESENTATION_SCHEMA: () => HOLDER_KEY_BINDING_PRESENTATION_SCHEMA,
|
|
102
|
-
HOOKS: () =>
|
|
106
|
+
HOOKS: () => import_bootstrap4.HOOKS,
|
|
103
107
|
HooksService: () => import_sdk_services8.HooksService,
|
|
104
108
|
IdentityParseError: () => IdentityParseError,
|
|
105
|
-
KV: () =>
|
|
109
|
+
KV: () => import_bootstrap4.KV,
|
|
106
110
|
KVService: () => import_sdk_services8.KVService,
|
|
111
|
+
LAST_V2_CREATE_AT: () => LAST_V2_CREATE_AT,
|
|
112
|
+
LAST_V2_READ_AT: () => LAST_V2_READ_AT,
|
|
107
113
|
LISTEN_SQL_STATEMENT_CATALOG: () => LISTEN_SQL_STATEMENT_CATALOG,
|
|
108
114
|
LOCAL_LINK_HOST_SUFFIX: () => LOCAL_LINK_HOST_SUFFIX,
|
|
109
115
|
LOCAL_LINK_PROBE_TIMEOUT_MS: () => LOCAL_LINK_PROBE_TIMEOUT_MS,
|
|
110
116
|
LOCAL_LOOPBACK_PROBE_TIMEOUT_MS: () => LOCAL_LOOPBACK_PROBE_TIMEOUT_MS,
|
|
111
117
|
LocationRecordValidationError: () => LocationRecordValidationError,
|
|
112
118
|
MAX_CONTENT_BYTES: () => MAX_CONTENT_BYTES,
|
|
119
|
+
MAX_LEGACY_ENVELOPE_EXPIRES_AT: () => MAX_LEGACY_ENVELOPE_EXPIRES_AT,
|
|
113
120
|
MAX_SEALED_SHARE_CONTENT_BYTES: () => MAX_SEALED_SHARE_CONTENT_BYTES,
|
|
114
121
|
MAX_SHARE_ARTIFACT_BYTES: () => MAX_SHARE_ARTIFACT_BYTES,
|
|
115
122
|
MAX_SHARE_CONTENT_BYTES: () => MAX_SHARE_CONTENT_BYTES,
|
|
@@ -117,9 +124,13 @@ __export(index_exports, {
|
|
|
117
124
|
MemorySenderShareKeyStorage: () => MemorySenderShareKeyStorage,
|
|
118
125
|
MemorySenderShareRecordStorage: () => MemorySenderShareRecordStorage,
|
|
119
126
|
MemoryShareCache: () => MemoryShareCache,
|
|
127
|
+
NATIVE_PROJECTION_V1_DOMAIN: () => NATIVE_PROJECTION_V1_DOMAIN,
|
|
120
128
|
NETWORK_NAME_PATTERN: () => import_sdk_services8.NETWORK_NAME_PATTERN,
|
|
121
129
|
NetworkIdError: () => import_sdk_services8.NetworkIdError,
|
|
122
130
|
OPENKEY_ACTION_ID_SEPARATOR: () => OPENKEY_ACTION_ID_SEPARATOR,
|
|
131
|
+
POLICY_CAPABILITY_V1_DOMAIN: () => POLICY_CAPABILITY_V1_DOMAIN,
|
|
132
|
+
POLICY_CAPABILITY_V1_SCHEMA: () => POLICY_CAPABILITY_V1_SCHEMA,
|
|
133
|
+
POLICY_ENFORCEMENT_DELEGATION_V2_SCHEMA: () => POLICY_ENFORCEMENT_DELEGATION_V2_SCHEMA,
|
|
123
134
|
POLICY_ENGINE_CHALLENGE_REQUEST_SCHEMA: () => POLICY_ENGINE_CHALLENGE_REQUEST_SCHEMA,
|
|
124
135
|
POLICY_ENGINE_CHALLENGE_RESPONSE_SCHEMA: () => POLICY_ENGINE_CHALLENGE_RESPONSE_SCHEMA,
|
|
125
136
|
POLICY_ENGINE_DENIAL_SCHEMA: () => POLICY_ENGINE_DENIAL_SCHEMA,
|
|
@@ -127,7 +138,10 @@ __export(index_exports, {
|
|
|
127
138
|
POLICY_ENGINE_RECORD_SCHEMA: () => POLICY_ENGINE_RECORD_SCHEMA,
|
|
128
139
|
POLICY_ENGINE_RESOLVE_REQUEST_SCHEMA: () => POLICY_ENGINE_RESOLVE_REQUEST_SCHEMA,
|
|
129
140
|
POLICY_SCHEMA: () => POLICY_SCHEMA,
|
|
141
|
+
POLICY_SESSION_UCAN_V1_PROFILE: () => POLICY_SESSION_UCAN_V1_PROFILE,
|
|
130
142
|
POLICY_STATUS_SCHEMA: () => POLICY_STATUS_SCHEMA,
|
|
143
|
+
POLICY_V1_DOMAIN: () => POLICY_V1_DOMAIN,
|
|
144
|
+
POLICY_V1_SCHEMA: () => POLICY_V1_SCHEMA,
|
|
131
145
|
PORTABLE_DELEGATION_SCHEMA: () => PORTABLE_DELEGATION_SCHEMA,
|
|
132
146
|
PermissionNotInManifestError: () => PermissionNotInManifestError,
|
|
133
147
|
PrefixedKVService: () => import_sdk_services8.PrefixedKVService,
|
|
@@ -135,14 +149,19 @@ __export(index_exports, {
|
|
|
135
149
|
REQUESTER_ENGINE_RETRY_ATTEMPTS: () => REQUESTER_ENGINE_RETRY_ATTEMPTS,
|
|
136
150
|
REQUESTER_ENGINE_RETRY_MAX_DELAY_MS: () => REQUESTER_ENGINE_RETRY_MAX_DELAY_MS,
|
|
137
151
|
REQUESTER_NEAR_EXPIRY_SECONDS: () => REQUESTER_NEAR_EXPIRY_SECONDS,
|
|
152
|
+
ROOT_REVOCATION_V1_DOMAIN: () => ROOT_REVOCATION_V1_DOMAIN,
|
|
153
|
+
ROOT_REVOCATION_V1_SCHEMA: () => ROOT_REVOCATION_V1_SCHEMA,
|
|
154
|
+
ROOT_STATUS_CHECKPOINT_V1_SCHEMA: () => ROOT_STATUS_CHECKPOINT_V1_SCHEMA,
|
|
155
|
+
ROOT_STATUS_RENEWAL_V1_DOMAIN: () => ROOT_STATUS_RENEWAL_V1_DOMAIN,
|
|
156
|
+
ROOT_STATUS_V1_DOMAIN: () => ROOT_STATUS_V1_DOMAIN,
|
|
138
157
|
SECRETS_SPACE: () => SECRETS_SPACE,
|
|
139
158
|
SECRET_NAME_RE: () => import_sdk_services8.SECRET_NAME_RE,
|
|
140
|
-
SECRET_RECORDS_SCHEMA: () =>
|
|
159
|
+
SECRET_RECORDS_SCHEMA: () => import_bootstrap4.SECRET_RECORDS_SCHEMA,
|
|
141
160
|
SERVICE_LONG_TO_SHORT: () => SERVICE_LONG_TO_SHORT,
|
|
142
161
|
SERVICE_SHORT_TO_LONG: () => SERVICE_SHORT_TO_LONG,
|
|
143
162
|
SHARE_DELIVERY_AUTHORIZATION_DOMAIN: () => SHARE_DELIVERY_AUTHORIZATION_DOMAIN,
|
|
144
|
-
SPACE: () =>
|
|
145
|
-
SQL: () =>
|
|
163
|
+
SPACE: () => import_bootstrap4.SPACE,
|
|
164
|
+
SQL: () => import_bootstrap4.SQL,
|
|
146
165
|
SQLAction: () => import_sdk_services8.SQLAction,
|
|
147
166
|
SQLService: () => import_sdk_services8.SQLService,
|
|
148
167
|
SecretsService: () => import_sdk_services8.SecretsService,
|
|
@@ -172,11 +191,11 @@ __export(index_exports, {
|
|
|
172
191
|
Space: () => Space,
|
|
173
192
|
SpaceErrorCodes: () => SpaceErrorCodes,
|
|
174
193
|
SpaceService: () => SpaceService,
|
|
175
|
-
TINYCLOUD_ACCOUNT_SPACE_MANIFEST: () =>
|
|
176
|
-
TINYCLOUD_APPLICATIONS_SPACE_MANIFEST: () =>
|
|
177
|
-
TINYCLOUD_DEFAULT_SPACE_MANIFEST: () =>
|
|
178
|
-
TINYCLOUD_PUBLIC_SPACE_MANIFEST: () =>
|
|
179
|
-
TINYCLOUD_SECRETS_BOOTSTRAP_MANIFEST: () =>
|
|
194
|
+
TINYCLOUD_ACCOUNT_SPACE_MANIFEST: () => import_bootstrap4.TINYCLOUD_ACCOUNT_SPACE_MANIFEST,
|
|
195
|
+
TINYCLOUD_APPLICATIONS_SPACE_MANIFEST: () => import_bootstrap4.TINYCLOUD_APPLICATIONS_SPACE_MANIFEST,
|
|
196
|
+
TINYCLOUD_DEFAULT_SPACE_MANIFEST: () => import_bootstrap4.TINYCLOUD_DEFAULT_SPACE_MANIFEST,
|
|
197
|
+
TINYCLOUD_PUBLIC_SPACE_MANIFEST: () => import_bootstrap4.TINYCLOUD_PUBLIC_SPACE_MANIFEST,
|
|
198
|
+
TINYCLOUD_SECRETS_BOOTSTRAP_MANIFEST: () => import_bootstrap4.TINYCLOUD_SECRETS_BOOTSTRAP_MANIFEST,
|
|
180
199
|
TinyCloud: () => TinyCloud,
|
|
181
200
|
TinyCloudDebugLogger: () => import_sdk_services8.TinyCloudDebugLogger,
|
|
182
201
|
TranscriptRequester: () => TranscriptRequester,
|
|
@@ -191,9 +210,9 @@ __export(index_exports, {
|
|
|
191
210
|
activateSessionWithHost: () => activateSessionWithHost,
|
|
192
211
|
addressStorageKey: () => addressStorageKey,
|
|
193
212
|
applyPrefix: () => applyPrefix,
|
|
194
|
-
bootstrapEncryptionNetworkId: () =>
|
|
195
|
-
bootstrapSpaceId: () =>
|
|
196
|
-
bootstrapSteps: () =>
|
|
213
|
+
bootstrapEncryptionNetworkId: () => import_bootstrap4.bootstrapEncryptionNetworkId,
|
|
214
|
+
bootstrapSpaceId: () => import_bootstrap4.bootstrapSpaceId,
|
|
215
|
+
bootstrapSteps: () => import_bootstrap4.bootstrapSteps,
|
|
197
216
|
buildCanonicalDecryptRequest: () => import_sdk_services8.buildCanonicalDecryptRequest,
|
|
198
217
|
buildDecryptAttenuation: () => import_sdk_services8.buildDecryptAttenuation,
|
|
199
218
|
buildDecryptFacts: () => import_sdk_services8.buildDecryptFacts,
|
|
@@ -212,13 +231,16 @@ __export(index_exports, {
|
|
|
212
231
|
canonicalizeRecapCaveats: () => canonicalizeRecapCaveats,
|
|
213
232
|
canonicalizeSecretScope: () => import_sdk_services8.canonicalizeSecretScope,
|
|
214
233
|
canonicalizeSignedObjectUnsigned: () => canonicalizeSignedObjectUnsigned,
|
|
234
|
+
canonicalizeUnifiedPolicyCapability: () => canonicalizeUnifiedPolicyCapability,
|
|
215
235
|
checkDecryptInvocationInput: () => import_sdk_services8.checkDecryptInvocationInput,
|
|
216
236
|
checkNodeInfo: () => checkNodeInfo,
|
|
217
237
|
clearTinyCloudDebugLogs: () => import_sdk_services8.clearTinyCloudDebugLogs,
|
|
218
|
-
|
|
238
|
+
compactAttenuationContains: () => compactAttenuationContains,
|
|
239
|
+
composeBootstrapSpaceManifest: () => import_bootstrap4.composeBootstrapSpaceManifest,
|
|
219
240
|
composeManifestRequest: () => composeManifestRequest,
|
|
220
241
|
computeOwnerShareRegistrationCid: () => computeOwnerShareRegistrationCid,
|
|
221
242
|
computeShareCid: () => computeShareCid,
|
|
243
|
+
contentSourceDigestHex: () => contentSourceDigestHex,
|
|
222
244
|
createAndSignPolicy: () => createAndSignPolicy,
|
|
223
245
|
createAndSignPolicyEngineRecord: () => createAndSignPolicyEngineRecord,
|
|
224
246
|
createAndSignPolicyStatus: () => createAndSignPolicyStatus,
|
|
@@ -241,6 +263,7 @@ __export(index_exports, {
|
|
|
241
263
|
defaultRetryPolicy: () => import_sdk_services8.defaultRetryPolicy,
|
|
242
264
|
defaultSignStrategy: () => defaultSignStrategy,
|
|
243
265
|
defaultSpaceCreationHandler: () => defaultSpaceCreationHandler,
|
|
266
|
+
delegatePortablePolicySession: () => delegatePortablePolicySession,
|
|
244
267
|
deriveDelegationCid: () => deriveDelegationCid,
|
|
245
268
|
deriveSignedObjectMaterial: () => deriveSignedObjectMaterial,
|
|
246
269
|
deriveSignedReceiverKey: () => import_sdk_services8.deriveSignedReceiverKey,
|
|
@@ -272,10 +295,12 @@ __export(index_exports, {
|
|
|
272
295
|
fetchLocationRecord: () => fetchLocationRecord,
|
|
273
296
|
fetchPeerId: () => fetchPeerId,
|
|
274
297
|
generateRandomReceiverKey: () => import_sdk_services8.generateRandomReceiverKey,
|
|
298
|
+
getPolicyRootStatusV3: () => getPolicyRootStatusV3,
|
|
275
299
|
getTinyCloudDebugLogs: () => import_sdk_services8.getTinyCloudDebugLogs,
|
|
276
300
|
hexDecode: () => import_sdk_services8.hexDecode,
|
|
277
301
|
hexEncode: () => import_sdk_services8.hexEncode,
|
|
278
302
|
httpUrlToMultiaddr: () => httpUrlToMultiaddr,
|
|
303
|
+
importPortableDelegation: () => importPortableDelegation,
|
|
279
304
|
installTinyCloudDebugGlobals: () => import_sdk_services8.installTinyCloudDebugGlobals,
|
|
280
305
|
intersectShareCapabilities: () => intersectShareCapabilities,
|
|
281
306
|
isCapabilitySubset: () => isCapabilitySubset,
|
|
@@ -296,22 +321,32 @@ __export(index_exports, {
|
|
|
296
321
|
normalizeShareActions: () => normalizeShareActions,
|
|
297
322
|
normalizeShareRecipientTarget: () => normalizeShareRecipientTarget,
|
|
298
323
|
normalizeShareResource: () => normalizeShareResource,
|
|
324
|
+
normalizeUnifiedPolicyCapability: () => normalizeUnifiedPolicyCapability,
|
|
299
325
|
ok: () => import_sdk_services8.ok,
|
|
300
326
|
openWrappedKey: () => import_sdk_services8.openWrappedKey,
|
|
301
327
|
parseCanonicalNetworkId: () => parseCanonicalNetworkId,
|
|
302
328
|
parseCanonicalRecapResource: () => parseCanonicalRecapResource,
|
|
329
|
+
parseCompactUcanAuthorization: () => parseCompactUcanAuthorization,
|
|
303
330
|
parseExpiry: () => parseExpiry,
|
|
304
331
|
parseNetworkId: () => import_sdk_services8.parseNetworkId,
|
|
305
332
|
parseNodeNativePortableDelegation: () => parseNodeNativePortableDelegation,
|
|
306
333
|
parsePkhDid: () => parsePkhDid,
|
|
334
|
+
parsePolicySessionUcan: () => parsePolicySessionUcan,
|
|
335
|
+
parsePortableDelegation: () => parsePortableDelegation,
|
|
307
336
|
parseRecapCapabilities: () => parseRecapCapabilities,
|
|
308
337
|
parseShareArtifact: () => parseShareArtifact,
|
|
309
338
|
parseShareUrl: () => parseShareUrl,
|
|
310
339
|
parseSpaceUri: () => parseSpaceUri,
|
|
311
340
|
pkhDid: () => pkhDid,
|
|
341
|
+
policyCidFromCanonicalBytes: () => policyCidFromCanonicalBytes,
|
|
342
|
+
policyDigestHex: () => policyDigestHex,
|
|
343
|
+
policyIdForDigestHex: () => policyIdForDigestHex,
|
|
312
344
|
principalDid: () => principalDid,
|
|
313
345
|
principalDidEquals: () => principalDidEquals,
|
|
346
|
+
projectUnifiedPolicyCapabilities: () => projectUnifiedPolicyCapabilities,
|
|
347
|
+
projectUnifiedPolicyCapability: () => projectUnifiedPolicyCapability,
|
|
314
348
|
recapCaveatsEqual: () => recapCaveatsEqual,
|
|
349
|
+
renewPolicyRootStatusV3: () => renewPolicyRootStatusV3,
|
|
315
350
|
resolveCloudLocation: () => resolveCloudLocation,
|
|
316
351
|
resolveManifest: () => resolveManifest,
|
|
317
352
|
resolveManifestKnowledgeRoot: () => resolveManifestKnowledgeRoot,
|
|
@@ -321,10 +356,13 @@ __export(index_exports, {
|
|
|
321
356
|
resourceCapabilitiesToAbilitiesMap: () => resourceCapabilitiesToAbilitiesMap,
|
|
322
357
|
resourceCapabilitiesToSpaceAbilitiesMap: () => resourceCapabilitiesToSpaceAbilitiesMap,
|
|
323
358
|
restoreDelegatedShareKey: () => restoreDelegatedShareKey,
|
|
359
|
+
revokePolicyRootV3: () => revokePolicyRootV3,
|
|
324
360
|
serializeJcsJson: () => serialize,
|
|
361
|
+
serializePortableDelegation: () => serializePortableDelegation,
|
|
325
362
|
serviceError: () => import_sdk_services8.serviceError,
|
|
326
363
|
shareCapabilityAllows: () => shareCapabilityAllows,
|
|
327
364
|
shareDeliveryTrustedKid: () => shareDeliveryTrustedKid,
|
|
365
|
+
signCompactUcanAuthorization: () => signCompactUcanAuthorization,
|
|
328
366
|
signLocationRecord: () => signLocationRecord,
|
|
329
367
|
signShareEnvelope: () => signShareEnvelope,
|
|
330
368
|
signedObjectIdFor: () => signedObjectIdFor,
|
|
@@ -332,6 +370,10 @@ __export(index_exports, {
|
|
|
332
370
|
tinyCloudDebugLogger: () => import_sdk_services8.tinyCloudDebugLogger,
|
|
333
371
|
toSignedObjectError: () => toSignedObjectError,
|
|
334
372
|
unauthorizedRecapCapabilities: () => unauthorizedRecapCapabilities,
|
|
373
|
+
unifiedNativeProjectionHashHex: () => unifiedNativeProjectionHashHex,
|
|
374
|
+
unifiedPolicyCapabilityContains: () => unifiedPolicyCapabilityContains,
|
|
375
|
+
unifiedPolicyCapabilityDigestHex: () => unifiedPolicyCapabilityDigestHex,
|
|
376
|
+
unifiedPolicyCapabilityFromNative: () => unifiedPolicyCapabilityFromNative,
|
|
335
377
|
validateAuthorizationResultV1: () => validateAuthorizationResultV1,
|
|
336
378
|
validateClientSession: () => validateClientSession,
|
|
337
379
|
validateEnvelope: () => import_sdk_services8.validateEnvelope,
|
|
@@ -356,6 +398,8 @@ __export(index_exports, {
|
|
|
356
398
|
verifyLocationRecord: () => verifyLocationRecord,
|
|
357
399
|
verifyPolicy: () => verifyPolicy,
|
|
358
400
|
verifyPolicyEngineRecord: () => verifyPolicyEngineRecord,
|
|
401
|
+
verifyPolicyRootRevocationV3: () => verifyPolicyRootRevocationV3,
|
|
402
|
+
verifyPolicyRootStatusCheckpointV3: () => verifyPolicyRootStatusCheckpointV3,
|
|
359
403
|
verifyPolicyStatus: () => verifyPolicyStatus,
|
|
360
404
|
verifyShareCid: () => verifyShareCid,
|
|
361
405
|
verifyShareEnvelope: () => verifyShareEnvelope,
|
|
@@ -498,7 +542,7 @@ function makePkhSpaceId(address, chainId, name2) {
|
|
|
498
542
|
|
|
499
543
|
// src/requester/index.ts
|
|
500
544
|
var import_viem4 = require("viem");
|
|
501
|
-
var
|
|
545
|
+
var import_blake32 = require("@noble/hashes/blake3");
|
|
502
546
|
|
|
503
547
|
// ../../node_modules/multiformats/dist/src/bases/base32.js
|
|
504
548
|
var base32_exports = {};
|
|
@@ -1406,7 +1450,7 @@ function encodeCID(version, code3, multihash) {
|
|
|
1406
1450
|
var cidSymbol = /* @__PURE__ */ Symbol.for("@ipld/js-cid/CID");
|
|
1407
1451
|
|
|
1408
1452
|
// src/requester/index.ts
|
|
1409
|
-
var
|
|
1453
|
+
var import_zod3 = require("zod");
|
|
1410
1454
|
|
|
1411
1455
|
// src/policy/errors.ts
|
|
1412
1456
|
var SignedObjectProfileError = class extends Error {
|
|
@@ -1715,16 +1759,16 @@ function policyCapabilityContains(authority, request) {
|
|
|
1715
1759
|
return caveatsContain(auth.caveats, req.caveats);
|
|
1716
1760
|
}
|
|
1717
1761
|
function normalizePolicyCapabilityWithOptions(input, options2) {
|
|
1718
|
-
const
|
|
1719
|
-
assertExactKeys(
|
|
1720
|
-
const service = requiredString(
|
|
1762
|
+
const object2 = expectObject(input, "$");
|
|
1763
|
+
assertExactKeys(object2, ["service", "space", "path", "actions", "caveats"], "$");
|
|
1764
|
+
const service = requiredString(object2, "service", "$", "policy-capability-malformed-service");
|
|
1721
1765
|
if (!CEILING_SERVICES.has(service)) {
|
|
1722
1766
|
throw new PolicyCapabilityError(
|
|
1723
1767
|
"policy-capability-malformed-service",
|
|
1724
1768
|
"$.service is outside the frozen permissionsCeiling vocabulary"
|
|
1725
1769
|
);
|
|
1726
1770
|
}
|
|
1727
|
-
const space = requiredString(
|
|
1771
|
+
const space = requiredString(object2, "space", "$", "policy-capability-malformed-space");
|
|
1728
1772
|
validateConcreteSpace(space);
|
|
1729
1773
|
const canonicalSpace = space.normalize("NFC");
|
|
1730
1774
|
if (options2.requireCanonical && canonicalSpace !== space) {
|
|
@@ -1733,7 +1777,7 @@ function normalizePolicyCapabilityWithOptions(input, options2) {
|
|
|
1733
1777
|
"$.space must already be canonical NFC"
|
|
1734
1778
|
);
|
|
1735
1779
|
}
|
|
1736
|
-
const rawPath = requiredString(
|
|
1780
|
+
const rawPath = requiredString(object2, "path", "$", "policy-capability-malformed-path");
|
|
1737
1781
|
validateRawPath(rawPath, options2);
|
|
1738
1782
|
const path = normalizePath(rawPath);
|
|
1739
1783
|
if (options2.requireCanonical && path !== rawPath) {
|
|
@@ -1744,7 +1788,7 @@ function normalizePolicyCapabilityWithOptions(input, options2) {
|
|
|
1744
1788
|
}
|
|
1745
1789
|
validateRawPath(path, options2);
|
|
1746
1790
|
const actions = normalizeActions(
|
|
1747
|
-
requiredArray(
|
|
1791
|
+
requiredArray(object2, "actions", "$", "policy-capability-malformed-action"),
|
|
1748
1792
|
service,
|
|
1749
1793
|
options2
|
|
1750
1794
|
);
|
|
@@ -1753,9 +1797,9 @@ function normalizePolicyCapabilityWithOptions(input, options2) {
|
|
|
1753
1797
|
output.space = canonicalSpace;
|
|
1754
1798
|
output.path = path;
|
|
1755
1799
|
output.actions = actions;
|
|
1756
|
-
if (hasOwn(
|
|
1800
|
+
if (hasOwn(object2, "caveats")) {
|
|
1757
1801
|
output.caveats = validateCaveats(
|
|
1758
|
-
requiredValue(
|
|
1802
|
+
requiredValue(object2, "caveats", "$", "policy-capability-malformed-caveats"),
|
|
1759
1803
|
output.service
|
|
1760
1804
|
);
|
|
1761
1805
|
}
|
|
@@ -1778,9 +1822,9 @@ function expectObject(input, path) {
|
|
|
1778
1822
|
);
|
|
1779
1823
|
}
|
|
1780
1824
|
}
|
|
1781
|
-
function assertExactKeys(
|
|
1825
|
+
function assertExactKeys(object2, allowed, path) {
|
|
1782
1826
|
const allowedSet = new Set(allowed);
|
|
1783
|
-
for (const key of Object.keys(
|
|
1827
|
+
for (const key of Object.keys(object2)) {
|
|
1784
1828
|
if (!allowedSet.has(key)) {
|
|
1785
1829
|
throw new PolicyCapabilityError(
|
|
1786
1830
|
key === "id" || key === "scope" ? "policy-capability-malformed" : "policy-capability-unknown-key",
|
|
@@ -1789,21 +1833,21 @@ function assertExactKeys(object, allowed, path) {
|
|
|
1789
1833
|
}
|
|
1790
1834
|
}
|
|
1791
1835
|
}
|
|
1792
|
-
function requiredValue(
|
|
1793
|
-
if (!hasOwn(
|
|
1836
|
+
function requiredValue(object2, key, path, code3) {
|
|
1837
|
+
if (!hasOwn(object2, key)) {
|
|
1794
1838
|
throw new PolicyCapabilityError(code3, `${path}.${key} is required`);
|
|
1795
1839
|
}
|
|
1796
|
-
return
|
|
1840
|
+
return object2[key];
|
|
1797
1841
|
}
|
|
1798
|
-
function requiredString(
|
|
1799
|
-
const value = requiredValue(
|
|
1842
|
+
function requiredString(object2, key, path, code3) {
|
|
1843
|
+
const value = requiredValue(object2, key, path, code3);
|
|
1800
1844
|
if (typeof value !== "string" || value.length === 0) {
|
|
1801
1845
|
throw new PolicyCapabilityError(code3, `${path}.${key} must be a non-empty string`);
|
|
1802
1846
|
}
|
|
1803
1847
|
return value;
|
|
1804
1848
|
}
|
|
1805
|
-
function requiredArray(
|
|
1806
|
-
const value = requiredValue(
|
|
1849
|
+
function requiredArray(object2, key, path, code3) {
|
|
1850
|
+
const value = requiredValue(object2, key, path, code3);
|
|
1807
1851
|
if (!Array.isArray(value)) {
|
|
1808
1852
|
throw new PolicyCapabilityError(code3, `${path}.${key} must be an array`);
|
|
1809
1853
|
}
|
|
@@ -1948,11 +1992,11 @@ function validateSqlStatement(input, path) {
|
|
|
1948
1992
|
if (input === null || typeof input !== "object" || Array.isArray(input)) {
|
|
1949
1993
|
throw new PolicyCapabilityError("policy-capability-malformed-caveats", `${path} must be an object`);
|
|
1950
1994
|
}
|
|
1951
|
-
const
|
|
1952
|
-
assertCaveatKeys(
|
|
1953
|
-
caveatString(
|
|
1954
|
-
caveatString(
|
|
1955
|
-
const fixedParams = requiredCaveat(
|
|
1995
|
+
const object2 = input;
|
|
1996
|
+
assertCaveatKeys(object2, ["name", "sql", "fixedParams"], path);
|
|
1997
|
+
caveatString(object2, "name", path);
|
|
1998
|
+
caveatString(object2, "sql", path);
|
|
1999
|
+
const fixedParams = requiredCaveat(object2, "fixedParams", path);
|
|
1956
2000
|
if (!Array.isArray(fixedParams)) {
|
|
1957
2001
|
throw new PolicyCapabilityError(
|
|
1958
2002
|
"policy-capability-malformed-caveats",
|
|
@@ -1967,20 +2011,20 @@ function validateFixedParam(input, path) {
|
|
|
1967
2011
|
if (input === null || typeof input !== "object" || Array.isArray(input)) {
|
|
1968
2012
|
throw new PolicyCapabilityError("policy-capability-malformed-caveats", `${path} must be an object`);
|
|
1969
2013
|
}
|
|
1970
|
-
const
|
|
1971
|
-
assertCaveatKeys(
|
|
1972
|
-
const index = requiredCaveat(
|
|
2014
|
+
const object2 = input;
|
|
2015
|
+
assertCaveatKeys(object2, ["index", "value"], path);
|
|
2016
|
+
const index = requiredCaveat(object2, "index", path);
|
|
1973
2017
|
if (typeof index !== "number" || !Number.isSafeInteger(index) || index < 0) {
|
|
1974
2018
|
throw new PolicyCapabilityError(
|
|
1975
2019
|
"policy-capability-malformed-caveats",
|
|
1976
2020
|
`${path}.index must be a non-negative integer`
|
|
1977
2021
|
);
|
|
1978
2022
|
}
|
|
1979
|
-
requiredCaveat(
|
|
2023
|
+
requiredCaveat(object2, "value", path);
|
|
1980
2024
|
}
|
|
1981
|
-
function assertCaveatKeys(
|
|
2025
|
+
function assertCaveatKeys(object2, allowed, path) {
|
|
1982
2026
|
const allowedSet = new Set(allowed);
|
|
1983
|
-
for (const key of Object.keys(
|
|
2027
|
+
for (const key of Object.keys(object2)) {
|
|
1984
2028
|
if (!allowedSet.has(key)) {
|
|
1985
2029
|
throw new PolicyCapabilityError(
|
|
1986
2030
|
"policy-capability-malformed-caveats",
|
|
@@ -1989,17 +2033,17 @@ function assertCaveatKeys(object, allowed, path) {
|
|
|
1989
2033
|
}
|
|
1990
2034
|
}
|
|
1991
2035
|
}
|
|
1992
|
-
function requiredCaveat(
|
|
1993
|
-
if (!hasOwn(
|
|
2036
|
+
function requiredCaveat(object2, key, path) {
|
|
2037
|
+
if (!hasOwn(object2, key)) {
|
|
1994
2038
|
throw new PolicyCapabilityError(
|
|
1995
2039
|
"policy-capability-malformed-caveats",
|
|
1996
2040
|
`${path}.${key} is required`
|
|
1997
2041
|
);
|
|
1998
2042
|
}
|
|
1999
|
-
return
|
|
2043
|
+
return object2[key];
|
|
2000
2044
|
}
|
|
2001
|
-
function caveatString(
|
|
2002
|
-
const value = requiredCaveat(
|
|
2045
|
+
function caveatString(object2, key, path) {
|
|
2046
|
+
const value = requiredCaveat(object2, key, path);
|
|
2003
2047
|
if (typeof value !== "string" || value.length === 0) {
|
|
2004
2048
|
throw new PolicyCapabilityError(
|
|
2005
2049
|
"policy-capability-malformed-caveats",
|
|
@@ -2030,8 +2074,8 @@ function caveatsContain(authority, request) {
|
|
|
2030
2074
|
(statement) => authorityStatements.some((candidate) => jcsCanonicalize(candidate) === jcsCanonicalize(statement))
|
|
2031
2075
|
);
|
|
2032
2076
|
}
|
|
2033
|
-
function hasOwn(
|
|
2034
|
-
return objectHasOwn2(
|
|
2077
|
+
function hasOwn(object2, key) {
|
|
2078
|
+
return objectHasOwn2(object2, key);
|
|
2035
2079
|
}
|
|
2036
2080
|
|
|
2037
2081
|
// src/policy/signed-object.ts
|
|
@@ -2359,17 +2403,17 @@ async function createAndSignSignedObject(input, signer) {
|
|
|
2359
2403
|
}
|
|
2360
2404
|
function createAndSignPolicy(input, signer) {
|
|
2361
2405
|
return createAndSignSignedObject(input, signer).then(
|
|
2362
|
-
(
|
|
2406
|
+
(object2) => validatePolicySignedShape(object2)
|
|
2363
2407
|
);
|
|
2364
2408
|
}
|
|
2365
2409
|
function createAndSignPolicyStatus(input, signer) {
|
|
2366
2410
|
return createAndSignSignedObject(input, signer).then(
|
|
2367
|
-
(
|
|
2411
|
+
(object2) => validatePolicyStatusSignedShape(object2)
|
|
2368
2412
|
);
|
|
2369
2413
|
}
|
|
2370
2414
|
function createAndSignPolicyEngineRecord(input, signer) {
|
|
2371
2415
|
return createAndSignSignedObject(input, signer).then(
|
|
2372
|
-
(
|
|
2416
|
+
(object2) => validatePolicyEngineRecordSignedShape(object2)
|
|
2373
2417
|
);
|
|
2374
2418
|
}
|
|
2375
2419
|
async function verifySignedObject(input) {
|
|
@@ -2473,9 +2517,9 @@ function validateUnsignedForDescriptor(input, descriptor) {
|
|
|
2473
2517
|
}
|
|
2474
2518
|
}
|
|
2475
2519
|
function validatePolicyShape(input, signed) {
|
|
2476
|
-
const
|
|
2520
|
+
const object2 = expectJsonObject(normalizeJson(input), "$");
|
|
2477
2521
|
assertExactKeys2(
|
|
2478
|
-
|
|
2522
|
+
object2,
|
|
2479
2523
|
signed ? [
|
|
2480
2524
|
"schema",
|
|
2481
2525
|
"policyId",
|
|
@@ -2503,30 +2547,30 @@ function validatePolicyShape(input, signed) {
|
|
|
2503
2547
|
],
|
|
2504
2548
|
"$"
|
|
2505
2549
|
);
|
|
2506
|
-
expectConst(requiredString2(
|
|
2550
|
+
expectConst(requiredString2(object2, "schema", "$"), POLICY_SCHEMA, "$.schema");
|
|
2507
2551
|
if (signed) {
|
|
2508
|
-
requiredString2(
|
|
2509
|
-
validateSignature(requiredValue2(
|
|
2552
|
+
requiredString2(object2, "policyId", "$");
|
|
2553
|
+
validateSignature(requiredValue2(object2, "signature", "$"));
|
|
2510
2554
|
}
|
|
2511
|
-
requiredString2(
|
|
2512
|
-
requiredString2(
|
|
2513
|
-
requiredDateString(
|
|
2514
|
-
optionalDateString(
|
|
2515
|
-
validatePolicyResource(requiredValue2(
|
|
2516
|
-
validateExpression(requiredValue2(
|
|
2517
|
-
validateGrant(requiredValue2(
|
|
2518
|
-
if (hasOwn2(
|
|
2519
|
-
validateDisclosure(requiredValue2(
|
|
2555
|
+
requiredString2(object2, "ownerDid", "$");
|
|
2556
|
+
requiredString2(object2, "signingKeyDid", "$");
|
|
2557
|
+
requiredDateString(object2, "createdAt", "$");
|
|
2558
|
+
optionalDateString(object2, "expiresAt", "$");
|
|
2559
|
+
validatePolicyResource(requiredValue2(object2, "resource", "$"), "$.resource");
|
|
2560
|
+
validateExpression(requiredValue2(object2, "when", "$"), "$.when");
|
|
2561
|
+
validateGrant(requiredValue2(object2, "grant", "$"), "$.grant");
|
|
2562
|
+
if (hasOwn2(object2, "disclosure")) {
|
|
2563
|
+
validateDisclosure(requiredValue2(object2, "disclosure", "$"), "$.disclosure");
|
|
2520
2564
|
}
|
|
2521
|
-
if (hasOwn2(
|
|
2522
|
-
validateAudit(requiredValue2(
|
|
2565
|
+
if (hasOwn2(object2, "audit")) {
|
|
2566
|
+
validateAudit(requiredValue2(object2, "audit", "$"), "$.audit");
|
|
2523
2567
|
}
|
|
2524
|
-
return
|
|
2568
|
+
return object2;
|
|
2525
2569
|
}
|
|
2526
2570
|
function validatePolicyStatusShape(input, signed) {
|
|
2527
|
-
const
|
|
2571
|
+
const object2 = expectJsonObject(normalizeJson(input), "$");
|
|
2528
2572
|
assertExactKeys2(
|
|
2529
|
-
|
|
2573
|
+
object2,
|
|
2530
2574
|
signed ? [
|
|
2531
2575
|
"schema",
|
|
2532
2576
|
"statusId",
|
|
@@ -2550,28 +2594,28 @@ function validatePolicyStatusShape(input, signed) {
|
|
|
2550
2594
|
],
|
|
2551
2595
|
"$"
|
|
2552
2596
|
);
|
|
2553
|
-
expectConst(requiredString2(
|
|
2597
|
+
expectConst(requiredString2(object2, "schema", "$"), POLICY_STATUS_SCHEMA, "$.schema");
|
|
2554
2598
|
if (signed) {
|
|
2555
|
-
requiredString2(
|
|
2556
|
-
validateSignature(requiredValue2(
|
|
2599
|
+
requiredString2(object2, "statusId", "$");
|
|
2600
|
+
validateSignature(requiredValue2(object2, "signature", "$"));
|
|
2557
2601
|
}
|
|
2558
|
-
requiredString2(
|
|
2559
|
-
requiredString2(
|
|
2560
|
-
requiredInteger(
|
|
2561
|
-
expectOneOf(requiredString2(
|
|
2602
|
+
requiredString2(object2, "policyId", "$");
|
|
2603
|
+
requiredString2(object2, "ownerDid", "$");
|
|
2604
|
+
requiredInteger(object2, "sequence", "$", 0);
|
|
2605
|
+
expectOneOf(requiredString2(object2, "disposition", "$"), [
|
|
2562
2606
|
"active",
|
|
2563
2607
|
"suspended",
|
|
2564
2608
|
"revoked"
|
|
2565
2609
|
], "$.disposition");
|
|
2566
|
-
requiredDateString(
|
|
2567
|
-
optionalString(
|
|
2568
|
-
requiredString2(
|
|
2569
|
-
return
|
|
2610
|
+
requiredDateString(object2, "effectiveAt", "$");
|
|
2611
|
+
optionalString(object2, "reasonCode", "$");
|
|
2612
|
+
requiredString2(object2, "signingKeyDid", "$");
|
|
2613
|
+
return object2;
|
|
2570
2614
|
}
|
|
2571
2615
|
function validatePolicyEngineRecordShape(input, signed) {
|
|
2572
|
-
const
|
|
2616
|
+
const object2 = expectJsonObject(normalizeJson(input), "$");
|
|
2573
2617
|
assertExactKeys2(
|
|
2574
|
-
|
|
2618
|
+
object2,
|
|
2575
2619
|
signed ? [
|
|
2576
2620
|
"schema",
|
|
2577
2621
|
"engineRecordId",
|
|
@@ -2596,44 +2640,44 @@ function validatePolicyEngineRecordShape(input, signed) {
|
|
|
2596
2640
|
"$"
|
|
2597
2641
|
);
|
|
2598
2642
|
expectConst(
|
|
2599
|
-
requiredString2(
|
|
2643
|
+
requiredString2(object2, "schema", "$"),
|
|
2600
2644
|
POLICY_ENGINE_RECORD_SCHEMA,
|
|
2601
2645
|
"$.schema"
|
|
2602
2646
|
);
|
|
2603
2647
|
if (signed) {
|
|
2604
|
-
requiredString2(
|
|
2605
|
-
validateSignature(requiredValue2(
|
|
2648
|
+
requiredString2(object2, "engineRecordId", "$");
|
|
2649
|
+
validateSignature(requiredValue2(object2, "signature", "$"));
|
|
2606
2650
|
}
|
|
2607
|
-
requiredString2(
|
|
2608
|
-
requiredString2(
|
|
2609
|
-
requiredString2(
|
|
2651
|
+
requiredString2(object2, "ownerDid", "$");
|
|
2652
|
+
requiredString2(object2, "endpoint", "$");
|
|
2653
|
+
requiredString2(object2, "audience", "$");
|
|
2610
2654
|
requiredStringArray(
|
|
2611
|
-
|
|
2655
|
+
object2,
|
|
2612
2656
|
"supportedPolicyVersions",
|
|
2613
2657
|
"$",
|
|
2614
2658
|
(value, path) => expectConst(value, "v0", path)
|
|
2615
2659
|
);
|
|
2616
|
-
requiredStringArray(
|
|
2617
|
-
requiredString2(
|
|
2618
|
-
requiredDateString(
|
|
2619
|
-
return
|
|
2660
|
+
requiredStringArray(object2, "supportedEvidenceVerifiers", "$");
|
|
2661
|
+
requiredString2(object2, "grantIssuerDid", "$");
|
|
2662
|
+
requiredDateString(object2, "expiresAt", "$");
|
|
2663
|
+
return object2;
|
|
2620
2664
|
}
|
|
2621
2665
|
function validateSignature(input) {
|
|
2622
|
-
const
|
|
2623
|
-
assertExactKeys2(
|
|
2624
|
-
const suite = requiredString2(
|
|
2666
|
+
const object2 = expectJsonObject(input, "$.signature");
|
|
2667
|
+
assertExactKeys2(object2, ["suite", "signerDid", "value"], "$.signature");
|
|
2668
|
+
const suite = requiredString2(object2, "suite", "$.signature");
|
|
2625
2669
|
assertSupportedSignatureSuite(suite);
|
|
2626
|
-
const signerDid = requiredString2(
|
|
2627
|
-
const value = requiredString2(
|
|
2670
|
+
const signerDid = requiredString2(object2, "signerDid", "$.signature");
|
|
2671
|
+
const value = requiredString2(object2, "value", "$.signature");
|
|
2628
2672
|
decodeSignatureValue(value, suite);
|
|
2629
2673
|
return { suite, signerDid, value };
|
|
2630
2674
|
}
|
|
2631
2675
|
function validatePolicyResource(input, path) {
|
|
2632
|
-
const
|
|
2633
|
-
assertExactKeys2(
|
|
2634
|
-
requiredString2(
|
|
2635
|
-
requiredString2(
|
|
2636
|
-
const ceiling = requiredArray2(
|
|
2676
|
+
const object2 = expectJsonObject(input, path);
|
|
2677
|
+
assertExactKeys2(object2, ["resourceType", "resourceId", "permissionsCeiling"], path);
|
|
2678
|
+
requiredString2(object2, "resourceType", path);
|
|
2679
|
+
requiredString2(object2, "resourceId", path);
|
|
2680
|
+
const ceiling = requiredArray2(object2, "permissionsCeiling", path, 1);
|
|
2637
2681
|
for (let index = 0; index < ceiling.length; index++) {
|
|
2638
2682
|
validatePolicyCapability(ceiling[index], `${path}.permissionsCeiling[${index}]`);
|
|
2639
2683
|
}
|
|
@@ -2649,10 +2693,10 @@ function validatePolicyPermissionsCeilingForSigning(input) {
|
|
|
2649
2693
|
}
|
|
2650
2694
|
}
|
|
2651
2695
|
function validatePolicyCapability(input, path) {
|
|
2652
|
-
const
|
|
2696
|
+
const object2 = expectJsonObject(input, path);
|
|
2653
2697
|
try {
|
|
2654
|
-
const canonical = canonicalizePolicyCapability(
|
|
2655
|
-
if (jcsCanonicalize(
|
|
2698
|
+
const canonical = canonicalizePolicyCapability(object2);
|
|
2699
|
+
if (jcsCanonicalize(object2) !== jcsCanonicalize(canonical)) {
|
|
2656
2700
|
throw new SignedObjectSchemaError(`${path} must be canonical PolicyCapability JSON`);
|
|
2657
2701
|
}
|
|
2658
2702
|
} catch (error) {
|
|
@@ -2665,10 +2709,10 @@ function validatePolicyCapability(input, path) {
|
|
|
2665
2709
|
}
|
|
2666
2710
|
}
|
|
2667
2711
|
function validatePolicyCapabilityForSigning(input, path) {
|
|
2668
|
-
const
|
|
2712
|
+
const object2 = expectJsonObject(input, path);
|
|
2669
2713
|
try {
|
|
2670
|
-
const canonical = normalizePolicyCapability(
|
|
2671
|
-
if (jcsCanonicalize(
|
|
2714
|
+
const canonical = normalizePolicyCapability(object2);
|
|
2715
|
+
if (jcsCanonicalize(object2) !== jcsCanonicalize(canonical)) {
|
|
2672
2716
|
throw new SignedObjectSchemaError(`${path} must be strict canonical PolicyCapability JSON`);
|
|
2673
2717
|
}
|
|
2674
2718
|
} catch (error) {
|
|
@@ -2681,43 +2725,43 @@ function validatePolicyCapabilityForSigning(input, path) {
|
|
|
2681
2725
|
}
|
|
2682
2726
|
}
|
|
2683
2727
|
function validateExpression(input, path) {
|
|
2684
|
-
const
|
|
2685
|
-
const keys = Object.keys(
|
|
2728
|
+
const object2 = expectJsonObject(input, path);
|
|
2729
|
+
const keys = Object.keys(object2);
|
|
2686
2730
|
if (keys.length !== 1) {
|
|
2687
2731
|
throw new SignedObjectSchemaError(`${path} must have exactly one expression key`);
|
|
2688
2732
|
}
|
|
2689
2733
|
const key = keys[0];
|
|
2690
2734
|
if (key === "allOf" || key === "anyOf") {
|
|
2691
|
-
const values = requiredArray2(
|
|
2735
|
+
const values = requiredArray2(object2, key, path, 1);
|
|
2692
2736
|
for (let index = 0; index < values.length; index++) {
|
|
2693
2737
|
validateExpression(values[index], `${path}.${key}[${index}]`);
|
|
2694
2738
|
}
|
|
2695
2739
|
return;
|
|
2696
2740
|
}
|
|
2697
2741
|
if (key === "subject") {
|
|
2698
|
-
const subject = expectJsonObject(requiredValue2(
|
|
2742
|
+
const subject = expectJsonObject(requiredValue2(object2, "subject", path), `${path}.subject`);
|
|
2699
2743
|
assertExactKeys2(subject, ["did"], `${path}.subject`);
|
|
2700
2744
|
requiredString2(subject, "did", `${path}.subject`);
|
|
2701
2745
|
return;
|
|
2702
2746
|
}
|
|
2703
2747
|
if (key === "evidence") {
|
|
2704
|
-
validateEvidenceRequirement(requiredValue2(
|
|
2748
|
+
validateEvidenceRequirement(requiredValue2(object2, "evidence", path), `${path}.evidence`);
|
|
2705
2749
|
return;
|
|
2706
2750
|
}
|
|
2707
2751
|
throw new SignedObjectSchemaError(`${path} has unknown expression key ${key}`);
|
|
2708
2752
|
}
|
|
2709
2753
|
function validateEvidenceRequirement(input, path) {
|
|
2710
|
-
const
|
|
2754
|
+
const object2 = expectJsonObject(input, path);
|
|
2711
2755
|
assertExactKeys2(
|
|
2712
|
-
|
|
2756
|
+
object2,
|
|
2713
2757
|
["requirementId", "verifier", "requirements", "authority", "freshness"],
|
|
2714
2758
|
path
|
|
2715
2759
|
);
|
|
2716
|
-
requiredString2(
|
|
2717
|
-
requiredString2(
|
|
2718
|
-
requiredValue2(
|
|
2719
|
-
if (hasOwn2(
|
|
2720
|
-
const authority = expectJsonObject(requiredValue2(
|
|
2760
|
+
requiredString2(object2, "requirementId", path);
|
|
2761
|
+
requiredString2(object2, "verifier", path);
|
|
2762
|
+
requiredValue2(object2, "requirements", path);
|
|
2763
|
+
if (hasOwn2(object2, "authority")) {
|
|
2764
|
+
const authority = expectJsonObject(requiredValue2(object2, "authority", path), `${path}.authority`);
|
|
2721
2765
|
assertExactKeys2(
|
|
2722
2766
|
authority,
|
|
2723
2767
|
["profile", "acceptedIssuers", "allowOwnerAuthorizedIssuer"],
|
|
@@ -2729,35 +2773,35 @@ function validateEvidenceRequirement(input, path) {
|
|
|
2729
2773
|
}
|
|
2730
2774
|
optionalBoolean(authority, "allowOwnerAuthorizedIssuer", `${path}.authority`);
|
|
2731
2775
|
}
|
|
2732
|
-
if (hasOwn2(
|
|
2733
|
-
const freshness = expectJsonObject(requiredValue2(
|
|
2776
|
+
if (hasOwn2(object2, "freshness")) {
|
|
2777
|
+
const freshness = expectJsonObject(requiredValue2(object2, "freshness", path), `${path}.freshness`);
|
|
2734
2778
|
assertExactKeys2(freshness, ["maxStatusAgeSeconds"], `${path}.freshness`);
|
|
2735
2779
|
requiredInteger(freshness, "maxStatusAgeSeconds", `${path}.freshness`, 0);
|
|
2736
2780
|
}
|
|
2737
2781
|
}
|
|
2738
2782
|
function validateGrant(input, path) {
|
|
2739
|
-
const
|
|
2740
|
-
assertExactKeys2(
|
|
2741
|
-
expectConst(requiredString2(
|
|
2742
|
-
requiredInteger(
|
|
2743
|
-
expectOneOf(requiredString2(
|
|
2783
|
+
const object2 = expectJsonObject(input, path);
|
|
2784
|
+
assertExactKeys2(object2, ["output", "maxTtlSeconds", "delegationMode", "revocation"], path);
|
|
2785
|
+
expectConst(requiredString2(object2, "output", path), "portable-delegation", `${path}.output`);
|
|
2786
|
+
requiredInteger(object2, "maxTtlSeconds", path, 1);
|
|
2787
|
+
expectOneOf(requiredString2(object2, "delegationMode", path), [
|
|
2744
2788
|
"terminal",
|
|
2745
2789
|
"attenuable"
|
|
2746
2790
|
], `${path}.delegationMode`);
|
|
2747
|
-
expectOneOf(requiredString2(
|
|
2791
|
+
expectOneOf(requiredString2(object2, "revocation", path), [
|
|
2748
2792
|
"refresh_only",
|
|
2749
2793
|
"active_cutoff"
|
|
2750
2794
|
], `${path}.revocation`);
|
|
2751
2795
|
}
|
|
2752
2796
|
function validateDisclosure(input, path) {
|
|
2753
|
-
const
|
|
2754
|
-
assertExactKeys2(
|
|
2755
|
-
expectOneOf(requiredString2(
|
|
2797
|
+
const object2 = expectJsonObject(input, path);
|
|
2798
|
+
assertExactKeys2(object2, ["denial"], path);
|
|
2799
|
+
expectOneOf(requiredString2(object2, "denial", path), ["none", "code", "debug"], `${path}.denial`);
|
|
2756
2800
|
}
|
|
2757
2801
|
function validateAudit(input, path) {
|
|
2758
|
-
const
|
|
2759
|
-
assertExactKeys2(
|
|
2760
|
-
expectOneOf(requiredString2(
|
|
2802
|
+
const object2 = expectJsonObject(input, path);
|
|
2803
|
+
assertExactKeys2(object2, ["issuance"], path);
|
|
2804
|
+
expectOneOf(requiredString2(object2, "issuance", path), ["off", "security", "full"], `${path}.issuance`);
|
|
2761
2805
|
}
|
|
2762
2806
|
function materialForUnsigned(unsigned, descriptor) {
|
|
2763
2807
|
const jcs = jcsCanonicalize(unsigned);
|
|
@@ -2906,9 +2950,9 @@ function encodeSignatureValue(value, suite) {
|
|
|
2906
2950
|
decodeSignatureValue(encoded, suite);
|
|
2907
2951
|
return encoded;
|
|
2908
2952
|
}
|
|
2909
|
-
function stripOwnIdAndSignature(
|
|
2953
|
+
function stripOwnIdAndSignature(object2, descriptor) {
|
|
2910
2954
|
const output = /* @__PURE__ */ Object.create(null);
|
|
2911
|
-
for (const [key, value] of Object.entries(
|
|
2955
|
+
for (const [key, value] of Object.entries(object2)) {
|
|
2912
2956
|
if (key === descriptor.idField || key === "signature") {
|
|
2913
2957
|
continue;
|
|
2914
2958
|
}
|
|
@@ -2917,8 +2961,8 @@ function stripOwnIdAndSignature(object, descriptor) {
|
|
|
2917
2961
|
return output;
|
|
2918
2962
|
}
|
|
2919
2963
|
function descriptorForUnsigned(input) {
|
|
2920
|
-
const
|
|
2921
|
-
return descriptorForSchema(requiredString2(
|
|
2964
|
+
const object2 = expectJsonObject(normalizeJson(input), "$");
|
|
2965
|
+
return descriptorForSchema(requiredString2(object2, "schema", "$"));
|
|
2922
2966
|
}
|
|
2923
2967
|
function descriptorForSchema(schema) {
|
|
2924
2968
|
if (schema === POLICY_SCHEMA) return DESCRIPTORS.Policy;
|
|
@@ -2932,28 +2976,28 @@ function expectJsonObject(input, path) {
|
|
|
2932
2976
|
}
|
|
2933
2977
|
return input;
|
|
2934
2978
|
}
|
|
2935
|
-
function assertExactKeys2(
|
|
2979
|
+
function assertExactKeys2(object2, allowed, path) {
|
|
2936
2980
|
const allowedSet = new Set(allowed);
|
|
2937
|
-
for (const key of Object.keys(
|
|
2981
|
+
for (const key of Object.keys(object2)) {
|
|
2938
2982
|
if (!allowedSet.has(key)) {
|
|
2939
2983
|
throw new SignedObjectSchemaError(`${path} has unknown field ${key}`);
|
|
2940
2984
|
}
|
|
2941
2985
|
}
|
|
2942
2986
|
}
|
|
2943
|
-
function requiredValue2(
|
|
2944
|
-
if (!hasOwn2(
|
|
2987
|
+
function requiredValue2(object2, key, path) {
|
|
2988
|
+
if (!hasOwn2(object2, key)) {
|
|
2945
2989
|
throw new SignedObjectSchemaError(`${path}.${key} is required`);
|
|
2946
2990
|
}
|
|
2947
|
-
return
|
|
2991
|
+
return object2[key];
|
|
2948
2992
|
}
|
|
2949
|
-
function requiredString2(
|
|
2950
|
-
return requireStringType(requiredValue2(
|
|
2993
|
+
function requiredString2(object2, key, path) {
|
|
2994
|
+
return requireStringType(requiredValue2(object2, key, path), `${path}.${key}`);
|
|
2951
2995
|
}
|
|
2952
|
-
function optionalString(
|
|
2953
|
-
if (!hasOwn2(
|
|
2996
|
+
function optionalString(object2, key, path) {
|
|
2997
|
+
if (!hasOwn2(object2, key)) {
|
|
2954
2998
|
return;
|
|
2955
2999
|
}
|
|
2956
|
-
requireStringType(requiredValue2(
|
|
3000
|
+
requireStringType(requiredValue2(object2, key, path), `${path}.${key}`);
|
|
2957
3001
|
}
|
|
2958
3002
|
function requireStringType(value, path) {
|
|
2959
3003
|
if (typeof value !== "string" || value.length === 0) {
|
|
@@ -2961,16 +3005,16 @@ function requireStringType(value, path) {
|
|
|
2961
3005
|
}
|
|
2962
3006
|
return value;
|
|
2963
3007
|
}
|
|
2964
|
-
function optionalBoolean(
|
|
2965
|
-
if (!hasOwn2(
|
|
3008
|
+
function optionalBoolean(object2, key, path) {
|
|
3009
|
+
if (!hasOwn2(object2, key)) {
|
|
2966
3010
|
return;
|
|
2967
3011
|
}
|
|
2968
|
-
if (typeof requiredValue2(
|
|
3012
|
+
if (typeof requiredValue2(object2, key, path) !== "boolean") {
|
|
2969
3013
|
throw new SignedObjectSchemaError(`${path}.${key} must be a boolean`);
|
|
2970
3014
|
}
|
|
2971
3015
|
}
|
|
2972
|
-
function requiredInteger(
|
|
2973
|
-
const value = requiredValue2(
|
|
3016
|
+
function requiredInteger(object2, key, path, minimum) {
|
|
3017
|
+
const value = requiredValue2(object2, key, path);
|
|
2974
3018
|
if (typeof value !== "number" || !Number.isSafeInteger(value) || value < minimum) {
|
|
2975
3019
|
throw new SignedObjectSchemaError(
|
|
2976
3020
|
`${path}.${key} must be an integer >= ${minimum}`
|
|
@@ -2978,8 +3022,8 @@ function requiredInteger(object, key, path, minimum) {
|
|
|
2978
3022
|
}
|
|
2979
3023
|
return value;
|
|
2980
3024
|
}
|
|
2981
|
-
function requiredArray2(
|
|
2982
|
-
const value = requiredValue2(
|
|
3025
|
+
function requiredArray2(object2, key, path, minimum) {
|
|
3026
|
+
const value = requiredValue2(object2, key, path);
|
|
2983
3027
|
if (!Array.isArray(value) || value.length < minimum) {
|
|
2984
3028
|
throw new SignedObjectSchemaError(
|
|
2985
3029
|
`${path}.${key} must be an array with at least ${minimum} item(s)`
|
|
@@ -2987,22 +3031,22 @@ function requiredArray2(object, key, path, minimum) {
|
|
|
2987
3031
|
}
|
|
2988
3032
|
return value;
|
|
2989
3033
|
}
|
|
2990
|
-
function requiredStringArray(
|
|
2991
|
-
const values = requiredArray2(
|
|
3034
|
+
function requiredStringArray(object2, key, path, check) {
|
|
3035
|
+
const values = requiredArray2(object2, key, path, 0);
|
|
2992
3036
|
for (let index = 0; index < values.length; index++) {
|
|
2993
3037
|
const itemPath = `${path}.${key}[${index}]`;
|
|
2994
3038
|
const value = requireStringType(values[index], itemPath);
|
|
2995
3039
|
check?.(value, itemPath);
|
|
2996
3040
|
}
|
|
2997
3041
|
}
|
|
2998
|
-
function requiredDateString(
|
|
2999
|
-
assertRfc3339(requiredString2(
|
|
3042
|
+
function requiredDateString(object2, key, path) {
|
|
3043
|
+
assertRfc3339(requiredString2(object2, key, path), `${path}.${key}`);
|
|
3000
3044
|
}
|
|
3001
|
-
function optionalDateString(
|
|
3002
|
-
if (!hasOwn2(
|
|
3045
|
+
function optionalDateString(object2, key, path) {
|
|
3046
|
+
if (!hasOwn2(object2, key)) {
|
|
3003
3047
|
return;
|
|
3004
3048
|
}
|
|
3005
|
-
assertRfc3339(requiredString2(
|
|
3049
|
+
assertRfc3339(requiredString2(object2, key, path), `${path}.${key}`);
|
|
3006
3050
|
}
|
|
3007
3051
|
function assertRfc3339(value, path) {
|
|
3008
3052
|
const match = value.match(
|
|
@@ -3034,8 +3078,8 @@ function expectOneOf(actual, allowed, path) {
|
|
|
3034
3078
|
}
|
|
3035
3079
|
throw new SignedObjectSchemaError(`${path} has unsupported value ${actual}`);
|
|
3036
3080
|
}
|
|
3037
|
-
function hasOwn2(
|
|
3038
|
-
return objectHasOwn3(
|
|
3081
|
+
function hasOwn2(object2, key) {
|
|
3082
|
+
return objectHasOwn3(object2, key);
|
|
3039
3083
|
}
|
|
3040
3084
|
function assertSupportedSignatureSuite(suite) {
|
|
3041
3085
|
if (suite !== ED25519_JCS_SIGNATURE_SUITE && suite !== EIP191_JCS_SIGNATURE_SUITE) {
|
|
@@ -3114,13 +3158,13 @@ function base64UrlDecode(value) {
|
|
|
3114
3158
|
return decoded;
|
|
3115
3159
|
}
|
|
3116
3160
|
function hexToBytes(value) {
|
|
3117
|
-
const
|
|
3118
|
-
if (
|
|
3161
|
+
const hex2 = value.slice(2);
|
|
3162
|
+
if (hex2.length % 2 !== 0 || !/^[0-9a-fA-F]*$/.test(hex2)) {
|
|
3119
3163
|
throw new SignatureMaterialError("hex signature must have even length");
|
|
3120
3164
|
}
|
|
3121
|
-
const output = new Uint8Array(
|
|
3165
|
+
const output = new Uint8Array(hex2.length / 2);
|
|
3122
3166
|
for (let index = 0; index < output.length; index++) {
|
|
3123
|
-
output[index] = Number.parseInt(
|
|
3167
|
+
output[index] = Number.parseInt(hex2.slice(index * 2, index * 2 + 2), 16);
|
|
3124
3168
|
}
|
|
3125
3169
|
return output;
|
|
3126
3170
|
}
|
|
@@ -3262,9 +3306,9 @@ function expectObject2(input, path, code3) {
|
|
|
3262
3306
|
);
|
|
3263
3307
|
}
|
|
3264
3308
|
}
|
|
3265
|
-
function assertExactKeys3(
|
|
3309
|
+
function assertExactKeys3(object2, allowed, path) {
|
|
3266
3310
|
const allowedSet = new Set(allowed);
|
|
3267
|
-
for (const key of Object.keys(
|
|
3311
|
+
for (const key of Object.keys(object2)) {
|
|
3268
3312
|
if (!allowedSet.has(key)) {
|
|
3269
3313
|
throw new PolicyAuthoringError(
|
|
3270
3314
|
"policy-authoring-unknown-key",
|
|
@@ -3273,17 +3317,17 @@ function assertExactKeys3(object, allowed, path) {
|
|
|
3273
3317
|
}
|
|
3274
3318
|
}
|
|
3275
3319
|
}
|
|
3276
|
-
function requiredValue3(
|
|
3277
|
-
if (!hasOwn3(
|
|
3320
|
+
function requiredValue3(object2, key, path) {
|
|
3321
|
+
if (!hasOwn3(object2, key)) {
|
|
3278
3322
|
throw new PolicyAuthoringError(
|
|
3279
3323
|
"policy-authoring-malformed",
|
|
3280
3324
|
`${path}.${key} is required`
|
|
3281
3325
|
);
|
|
3282
3326
|
}
|
|
3283
|
-
return
|
|
3327
|
+
return object2[key];
|
|
3284
3328
|
}
|
|
3285
|
-
function requiredString3(
|
|
3286
|
-
const value = requiredValue3(
|
|
3329
|
+
function requiredString3(object2, key, path) {
|
|
3330
|
+
const value = requiredValue3(object2, key, path);
|
|
3287
3331
|
if (typeof value !== "string" || value.length === 0) {
|
|
3288
3332
|
throw new PolicyAuthoringError(
|
|
3289
3333
|
"policy-authoring-malformed",
|
|
@@ -3292,11 +3336,11 @@ function requiredString3(object, key, path) {
|
|
|
3292
3336
|
}
|
|
3293
3337
|
return value;
|
|
3294
3338
|
}
|
|
3295
|
-
function fieldString(
|
|
3296
|
-
if (!hasOwn3(
|
|
3339
|
+
function fieldString(object2, key, path, code3) {
|
|
3340
|
+
if (!hasOwn3(object2, key)) {
|
|
3297
3341
|
throw new PolicyAuthoringError(code3, `${path}.${key} is required`);
|
|
3298
3342
|
}
|
|
3299
|
-
const value =
|
|
3343
|
+
const value = object2[key];
|
|
3300
3344
|
if (typeof value !== "string" || value.length === 0) {
|
|
3301
3345
|
throw new PolicyAuthoringError(
|
|
3302
3346
|
code3,
|
|
@@ -3334,8 +3378,609 @@ function parseStrictRfc3339(value, path) {
|
|
|
3334
3378
|
var objectHasOwn4 = Object.hasOwn ?? Object.prototype.hasOwnProperty.call.bind(
|
|
3335
3379
|
Object.prototype.hasOwnProperty
|
|
3336
3380
|
);
|
|
3337
|
-
function hasOwn3(
|
|
3338
|
-
return objectHasOwn4(
|
|
3381
|
+
function hasOwn3(object2, key) {
|
|
3382
|
+
return objectHasOwn4(object2, key);
|
|
3383
|
+
}
|
|
3384
|
+
|
|
3385
|
+
// src/policy/unified.ts
|
|
3386
|
+
var import_sha256 = require("@noble/hashes/sha256");
|
|
3387
|
+
var import_blake3 = require("@noble/hashes/blake3");
|
|
3388
|
+
var import_ed255192 = require("@noble/curves/ed25519");
|
|
3389
|
+
var import_zod2 = require("zod");
|
|
3390
|
+
var POLICY_V1_SCHEMA = "xyz.tinycloud.policy/policy/v1";
|
|
3391
|
+
var POLICY_CAPABILITY_V1_SCHEMA = "xyz.tinycloud.policy/capability/v1";
|
|
3392
|
+
var POLICY_ENFORCEMENT_DELEGATION_V2_SCHEMA = "xyz.tinycloud.policy/enforcement-delegation/v2";
|
|
3393
|
+
var ATTESTED_ENFORCER_BINDING_V2_SCHEMA = "xyz.tinycloud.policy/attested-enforcer/v2";
|
|
3394
|
+
var ROOT_STATUS_CHECKPOINT_V1_SCHEMA = "xyz.tinycloud.policy/root-status/v1";
|
|
3395
|
+
var ROOT_REVOCATION_V1_SCHEMA = "xyz.tinycloud.policy/root-revocation/v1";
|
|
3396
|
+
var POLICY_SESSION_UCAN_V1_PROFILE = "policy-session-ucan/v1";
|
|
3397
|
+
var POLICY_V1_DOMAIN = "xyz.tinycloud.policy/policy/v1\0";
|
|
3398
|
+
var POLICY_CAPABILITY_V1_DOMAIN = "xyz.tinycloud.policy/PolicyCapability/v1\0";
|
|
3399
|
+
var CONTENT_SOURCE_V1_DOMAIN = "xyz.tinycloud.policy/ContentSource/v1\0";
|
|
3400
|
+
var NATIVE_PROJECTION_V1_DOMAIN = "xyz.tinycloud.policy/NativeProjection/v1\0";
|
|
3401
|
+
var ROOT_STATUS_V1_DOMAIN = "xyz.tinycloud.policy/RootStatusCheckpoint/v1\0";
|
|
3402
|
+
var ROOT_STATUS_RENEWAL_V1_DOMAIN = "xyz.tinycloud.policy/RootStatusRenewal/v1\0";
|
|
3403
|
+
var ROOT_REVOCATION_V1_DOMAIN = "xyz.tinycloud.policy/RootRevocation/v1\0";
|
|
3404
|
+
var LAST_V2_CREATE_AT = "2026-09-30T00:00:00Z";
|
|
3405
|
+
var MAX_LEGACY_ENVELOPE_EXPIRES_AT = "2026-12-29T00:00:00Z";
|
|
3406
|
+
var LAST_V2_READ_AT = "2027-01-05T00:00:00Z";
|
|
3407
|
+
function verifyPolicyRootStatusCheckpointV3(input) {
|
|
3408
|
+
const checkpoint = input.checkpoint;
|
|
3409
|
+
const allowed = /* @__PURE__ */ new Set(["schema", "targetCid", "targetRole", "ownerDid", "nodeAudience", "state", "sequence", "checkedAt", "freshUntil", "revokedAt", "revocationCid", "previousCheckpointDigestHex", "issuerDid", "signature"]);
|
|
3410
|
+
if (Object.keys(checkpoint).some((key) => !allowed.has(key)) || checkpoint.schema !== ROOT_STATUS_CHECKPOINT_V1_SCHEMA || checkpoint.targetCid !== input.rootCid || checkpoint.targetRole !== "policy-authority" && checkpoint.targetRole !== "policy-enforcement" || checkpoint.state !== "active" && checkpoint.state !== "revoked" || typeof checkpoint.ownerDid !== "string" || typeof checkpoint.nodeAudience !== "string" || checkpoint.issuerDid !== checkpoint.nodeAudience || input.expectedNodeAudience !== void 0 && checkpoint.nodeAudience !== input.expectedNodeAudience || !Number.isInteger(checkpoint.sequence) || checkpoint.sequence < 1 || typeof checkpoint.checkedAt !== "string" || typeof checkpoint.freshUntil !== "string") return false;
|
|
3411
|
+
const checkedAt = Date.parse(checkpoint.checkedAt);
|
|
3412
|
+
const freshUntil = Date.parse(checkpoint.freshUntil);
|
|
3413
|
+
const now = (input.now ?? /* @__PURE__ */ new Date()).getTime();
|
|
3414
|
+
if (!Number.isFinite(checkedAt) || !Number.isFinite(freshUntil) || freshUntil < now || freshUntil <= checkedAt || freshUntil - checkedAt > 3e5) return false;
|
|
3415
|
+
if (checkpoint.sequence === 1 !== (checkpoint.previousCheckpointDigestHex === void 0)) return false;
|
|
3416
|
+
if (checkpoint.sequence !== 1 && (typeof checkpoint.previousCheckpointDigestHex !== "string" || !/^[0-9a-f]{64}$/.test(checkpoint.previousCheckpointDigestHex))) return false;
|
|
3417
|
+
if (checkpoint.state === "active" && (checkpoint.revokedAt !== void 0 || checkpoint.revocationCid !== void 0)) return false;
|
|
3418
|
+
if (checkpoint.state === "revoked" && (typeof checkpoint.revokedAt !== "string" || typeof checkpoint.revocationCid !== "string")) return false;
|
|
3419
|
+
const signature = checkpoint.signature;
|
|
3420
|
+
if (!isRecordValue(signature) || Object.keys(signature).length !== 3 || signature.suite !== "Ed25519" || signature.signerDid !== checkpoint.issuerDid || typeof signature.value !== "string") return false;
|
|
3421
|
+
try {
|
|
3422
|
+
const principal = checkpoint.issuerDid.split("#", 1)[0];
|
|
3423
|
+
const didMaterial = principal.startsWith("did:key:") ? base58btc.decode(principal.slice("did:key:".length)) : new Uint8Array();
|
|
3424
|
+
if (didMaterial.length !== 34 || didMaterial[0] !== 237 || didMaterial[1] !== 1) return false;
|
|
3425
|
+
const unsigned = { ...checkpoint };
|
|
3426
|
+
delete unsigned.signature;
|
|
3427
|
+
return import_ed255192.ed25519.verify(
|
|
3428
|
+
decodeBase64Url(signature.value),
|
|
3429
|
+
(0, import_sha256.sha256)(new TextEncoder().encode(ROOT_STATUS_V1_DOMAIN + jcsCanonicalize(unsigned))),
|
|
3430
|
+
didMaterial.slice(2)
|
|
3431
|
+
);
|
|
3432
|
+
} catch {
|
|
3433
|
+
return false;
|
|
3434
|
+
}
|
|
3435
|
+
}
|
|
3436
|
+
async function getPolicyRootStatusV3(input) {
|
|
3437
|
+
const fetchFn = input.fetch ?? globalThis.fetch.bind(globalThis);
|
|
3438
|
+
const response = await fetchFn(new URL(`/share/v3/policy/status/${encodeURIComponent(input.rootCid)}`, input.nodeOrigin), {
|
|
3439
|
+
method: "GET",
|
|
3440
|
+
redirect: "error",
|
|
3441
|
+
headers: { accept: "application/json" }
|
|
3442
|
+
});
|
|
3443
|
+
if (!response.ok) throw new Error(`policy root status rejected (${response.status})`);
|
|
3444
|
+
const value = object(await response.json(), "policy root status");
|
|
3445
|
+
const checkpoint = object(value.checkpoint, "policy root checkpoint");
|
|
3446
|
+
if (value.rootCid !== input.rootCid || value.state !== "active" && value.state !== "revoked" || value.state !== checkpoint.state || !verifyPolicyRootStatusCheckpointV3({ rootCid: input.rootCid, checkpoint, expectedNodeAudience: input.expectedNodeAudience, now: input.now }))
|
|
3447
|
+
throw new Error("policy root status binding is invalid");
|
|
3448
|
+
const revocation = value.revocation === void 0 ? void 0 : object(value.revocation, "policy root revocation");
|
|
3449
|
+
if (value.state === "revoked" !== (revocation !== void 0) || revocation !== void 0 && !verifyPolicyRootRevocationV3({
|
|
3450
|
+
rootCid: input.rootCid,
|
|
3451
|
+
checkpoint,
|
|
3452
|
+
revocation,
|
|
3453
|
+
expectedEnforcerDid: input.expectedEnforcerDid
|
|
3454
|
+
})) throw new Error("policy root status revocation evidence is invalid");
|
|
3455
|
+
return { rootCid: input.rootCid, state: value.state, checkpoint, ...revocation === void 0 ? {} : { revocation } };
|
|
3456
|
+
}
|
|
3457
|
+
function verifyPolicyRootRevocationV3(input) {
|
|
3458
|
+
const value = input.revocation;
|
|
3459
|
+
const allowed = ["schema", "targetCid", "targetRole", "ownerDid", "nodeAudience", "revokedAt", "reason", "issuerDid", "signature"];
|
|
3460
|
+
if (Object.keys(value).length !== allowed.length || Object.keys(value).some((key) => !allowed.includes(key)) || value.schema !== ROOT_REVOCATION_V1_SCHEMA || value.targetCid !== input.rootCid || value.targetRole !== input.checkpoint.targetRole || value.ownerDid !== input.checkpoint.ownerDid || value.nodeAudience !== input.checkpoint.nodeAudience || value.revokedAt !== input.checkpoint.revokedAt || typeof value.reason !== "string" || value.reason.length === 0 || typeof value.issuerDid !== "string") return false;
|
|
3461
|
+
const authorized = value.issuerDid === value.ownerDid || value.targetRole === "policy-enforcement" && value.issuerDid === input.expectedEnforcerDid;
|
|
3462
|
+
if (!authorized) return false;
|
|
3463
|
+
const signature = value.signature;
|
|
3464
|
+
if (!isRecordValue(signature) || Object.keys(signature).length !== 3 || signature.suite !== "Ed25519" || signature.signerDid !== value.issuerDid || typeof signature.value !== "string") return false;
|
|
3465
|
+
try {
|
|
3466
|
+
const principal = value.issuerDid.split("#", 1)[0];
|
|
3467
|
+
const didMaterial = principal.startsWith("did:key:") ? base58btc.decode(principal.slice("did:key:".length)) : new Uint8Array();
|
|
3468
|
+
if (didMaterial.length !== 34 || didMaterial[0] !== 237 || didMaterial[1] !== 1) return false;
|
|
3469
|
+
const unsigned = { ...value };
|
|
3470
|
+
delete unsigned.signature;
|
|
3471
|
+
const digest4 = (0, import_sha256.sha256)(new TextEncoder().encode(ROOT_REVOCATION_V1_DOMAIN + jcsCanonicalize(unsigned)));
|
|
3472
|
+
return input.checkpoint.revocationCid === hex(digest4) && import_ed255192.ed25519.verify(decodeBase64Url(signature.value), digest4, didMaterial.slice(2));
|
|
3473
|
+
} catch {
|
|
3474
|
+
return false;
|
|
3475
|
+
}
|
|
3476
|
+
}
|
|
3477
|
+
async function renewPolicyRootStatusV3(input) {
|
|
3478
|
+
const fetchFn = input.fetch ?? globalThis.fetch.bind(globalThis);
|
|
3479
|
+
const current = await getPolicyRootStatusV3({ nodeOrigin: input.nodeOrigin, rootCid: input.rootCid, expectedNodeAudience: input.nodeAudience, now: input.now, fetch: fetchFn });
|
|
3480
|
+
if (current.state !== "active" || current.checkpoint.ownerDid !== input.ownerDid || current.checkpoint.nodeAudience !== input.nodeAudience || current.checkpoint.state !== "active" || !Number.isInteger(current.checkpoint.sequence))
|
|
3481
|
+
throw new Error("policy root status cannot be renewed");
|
|
3482
|
+
const currentUnsigned = { ...current.checkpoint };
|
|
3483
|
+
delete currentUnsigned.signature;
|
|
3484
|
+
const previousCheckpointDigestHex = hex((0, import_sha256.sha256)(new TextEncoder().encode(ROOT_STATUS_V1_DOMAIN + jcsCanonicalize(currentUnsigned))));
|
|
3485
|
+
const unsigned = {
|
|
3486
|
+
schema: "xyz.tinycloud.policy/root-status-renewal/v1",
|
|
3487
|
+
targetCid: input.rootCid,
|
|
3488
|
+
ownerDid: input.ownerDid,
|
|
3489
|
+
nodeAudience: input.nodeAudience,
|
|
3490
|
+
issuedAt: (input.now ?? /* @__PURE__ */ new Date()).toISOString(),
|
|
3491
|
+
nonce: input.nonce ?? encodeBase64Url(crypto.getRandomValues(new Uint8Array(16))),
|
|
3492
|
+
sequence: current.checkpoint.sequence + 1,
|
|
3493
|
+
previousCheckpointDigestHex
|
|
3494
|
+
};
|
|
3495
|
+
const signature = await input.sign((0, import_sha256.sha256)(new TextEncoder().encode(ROOT_STATUS_RENEWAL_V1_DOMAIN + jcsCanonicalize(unsigned))));
|
|
3496
|
+
if (signature.length !== 64) throw new Error("policy root renewal signature must be Ed25519");
|
|
3497
|
+
const response = await fetchFn(new URL("/share/v3/policy/status", input.nodeOrigin), {
|
|
3498
|
+
method: "POST",
|
|
3499
|
+
redirect: "error",
|
|
3500
|
+
headers: { accept: "application/json", "content-type": "application/json" },
|
|
3501
|
+
body: JSON.stringify({ rootCid: input.rootCid, renewal: { ...unsigned, signature: { suite: "Ed25519", signerDid: input.ownerDid, value: encodeBase64Url(signature) } } })
|
|
3502
|
+
});
|
|
3503
|
+
if (!response.ok) throw new Error(`policy root renewal rejected (${response.status})`);
|
|
3504
|
+
return object(await response.json(), "policy root renewal");
|
|
3505
|
+
}
|
|
3506
|
+
async function revokePolicyRootV3(input) {
|
|
3507
|
+
if (input.reason.length === 0) throw new Error("policy root revocation reason is required");
|
|
3508
|
+
const unsigned = {
|
|
3509
|
+
schema: ROOT_REVOCATION_V1_SCHEMA,
|
|
3510
|
+
targetCid: input.rootCid,
|
|
3511
|
+
targetRole: input.targetRole,
|
|
3512
|
+
ownerDid: input.ownerDid,
|
|
3513
|
+
nodeAudience: input.nodeAudience,
|
|
3514
|
+
revokedAt: (input.now ?? /* @__PURE__ */ new Date()).toISOString(),
|
|
3515
|
+
reason: input.reason,
|
|
3516
|
+
issuerDid: input.issuerDid
|
|
3517
|
+
};
|
|
3518
|
+
const signature = await input.sign((0, import_sha256.sha256)(new TextEncoder().encode(ROOT_REVOCATION_V1_DOMAIN + jcsCanonicalize(unsigned))));
|
|
3519
|
+
if (signature.length !== 64) throw new Error("policy root revocation signature must be Ed25519");
|
|
3520
|
+
const fetchFn = input.fetch ?? globalThis.fetch.bind(globalThis);
|
|
3521
|
+
const response = await fetchFn(new URL("/revoke", input.nodeOrigin), {
|
|
3522
|
+
method: "POST",
|
|
3523
|
+
redirect: "error",
|
|
3524
|
+
headers: { accept: "application/json", "content-type": "application/json" },
|
|
3525
|
+
body: JSON.stringify({ revocation: { ...unsigned, signature: { suite: "Ed25519", signerDid: input.issuerDid, value: encodeBase64Url(signature) } } })
|
|
3526
|
+
});
|
|
3527
|
+
if (!response.ok) throw new Error(`policy root revocation rejected (${response.status})`);
|
|
3528
|
+
return object(await response.json(), "policy root revocation");
|
|
3529
|
+
}
|
|
3530
|
+
var POLICY_SESSION_FACT_KEYS = [
|
|
3531
|
+
"profile",
|
|
3532
|
+
"ownerDid",
|
|
3533
|
+
"policyId",
|
|
3534
|
+
"policyDigestHex",
|
|
3535
|
+
"policyCid",
|
|
3536
|
+
"policyDelegationCid",
|
|
3537
|
+
"enforcementDelegationCid",
|
|
3538
|
+
"contentSourceDigestHex",
|
|
3539
|
+
"capabilityCeilingHashHex",
|
|
3540
|
+
"nativeProjectionHashHex",
|
|
3541
|
+
"enforcerDid",
|
|
3542
|
+
"nodeAudience",
|
|
3543
|
+
"recipientDid",
|
|
3544
|
+
"challengeId",
|
|
3545
|
+
"claimDigestHex",
|
|
3546
|
+
"claimJti",
|
|
3547
|
+
"vpDigestHex",
|
|
3548
|
+
"credentialEvidenceDigestHex",
|
|
3549
|
+
"decisionContextDigestHex",
|
|
3550
|
+
"issuanceAuditDigestHex",
|
|
3551
|
+
"remainingRedelegationDepth"
|
|
3552
|
+
];
|
|
3553
|
+
var KV_ACTIONS = /* @__PURE__ */ new Set([
|
|
3554
|
+
"tinycloud.kv/get",
|
|
3555
|
+
"tinycloud.kv/list",
|
|
3556
|
+
"tinycloud.kv/metadata",
|
|
3557
|
+
"tinycloud.kv/put"
|
|
3558
|
+
]);
|
|
3559
|
+
function object(value, label) {
|
|
3560
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
3561
|
+
throw new Error(`${label} must be an object`);
|
|
3562
|
+
}
|
|
3563
|
+
return value;
|
|
3564
|
+
}
|
|
3565
|
+
function exactKeys(value, allowed, label) {
|
|
3566
|
+
const keys = new Set(allowed);
|
|
3567
|
+
if (Object.keys(value).some((key) => !keys.has(key)))
|
|
3568
|
+
throw new Error(`${label} contains an unknown field`);
|
|
3569
|
+
}
|
|
3570
|
+
function nonEmptyString(value, label) {
|
|
3571
|
+
if (typeof value !== "string" || value.length === 0)
|
|
3572
|
+
throw new Error(`${label} must be a non-empty string`);
|
|
3573
|
+
return value;
|
|
3574
|
+
}
|
|
3575
|
+
function parseKvResource(resource) {
|
|
3576
|
+
const match = /^tinycloud:\/\/([^/]+)\/kv\/(.+)$/.exec(resource);
|
|
3577
|
+
if (!match || match[1].includes(":") || match[1].includes("?") || match[1].includes("#") || match[1].includes("%") || match[2].startsWith("/") || match[2].endsWith("/") || match[2].includes("//") || match[2].split("/").some((part) => part === "." || part === ".." || part.length === 0)) {
|
|
3578
|
+
throw new Error("KV resource is not canonical");
|
|
3579
|
+
}
|
|
3580
|
+
return { space: match[1], path: match[2] };
|
|
3581
|
+
}
|
|
3582
|
+
function parseEncryptionResource(resource) {
|
|
3583
|
+
if (!resource.startsWith("urn:tinycloud:encryption:")) throw new Error("encryption capability is invalid");
|
|
3584
|
+
const rest = resource.slice("urn:tinycloud:encryption:".length);
|
|
3585
|
+
const separator = rest.lastIndexOf(":");
|
|
3586
|
+
const ownerDid = separator < 0 ? "" : rest.slice(0, separator);
|
|
3587
|
+
const network = separator < 0 ? "" : rest.slice(separator + 1);
|
|
3588
|
+
if (!ownerDid.startsWith("did:") || network.length === 0 || network.includes(":") || network.includes("/") || network.includes("%") || network.includes("?") || network.includes("#")) {
|
|
3589
|
+
throw new Error("encryption capability is invalid");
|
|
3590
|
+
}
|
|
3591
|
+
}
|
|
3592
|
+
function normalizeUnifiedPolicyCapability(input) {
|
|
3593
|
+
const value = object(input, "capability");
|
|
3594
|
+
const kind = nonEmptyString(value.kind, "capability.kind");
|
|
3595
|
+
if (kind === "kv") {
|
|
3596
|
+
exactKeys(
|
|
3597
|
+
value,
|
|
3598
|
+
["kind", "resource", "selector", "actions"],
|
|
3599
|
+
"KV capability"
|
|
3600
|
+
);
|
|
3601
|
+
const resource = nonEmptyString(value.resource, "capability.resource");
|
|
3602
|
+
parseKvResource(resource);
|
|
3603
|
+
if (value.selector !== "exact" && value.selector !== "prefix")
|
|
3604
|
+
throw new Error("capability.selector is invalid");
|
|
3605
|
+
if (!Array.isArray(value.actions) || value.actions.length === 0)
|
|
3606
|
+
throw new Error("capability.actions is invalid");
|
|
3607
|
+
const actions = value.actions.map(
|
|
3608
|
+
(action) => nonEmptyString(action, "capability.actions[]")
|
|
3609
|
+
);
|
|
3610
|
+
if (new Set(actions).size !== actions.length || actions.some((action) => !KV_ACTIONS.has(action)))
|
|
3611
|
+
throw new Error("capability.actions is invalid");
|
|
3612
|
+
return {
|
|
3613
|
+
kind: "kv",
|
|
3614
|
+
resource,
|
|
3615
|
+
selector: value.selector,
|
|
3616
|
+
actions: [...actions].sort()
|
|
3617
|
+
};
|
|
3618
|
+
}
|
|
3619
|
+
if (kind === "encryption") {
|
|
3620
|
+
exactKeys(value, ["kind", "resource", "action"], "encryption capability");
|
|
3621
|
+
const resource = nonEmptyString(value.resource, "capability.resource");
|
|
3622
|
+
if (value.action !== "tinycloud.encryption/decrypt")
|
|
3623
|
+
throw new Error("encryption capability is invalid");
|
|
3624
|
+
parseEncryptionResource(resource);
|
|
3625
|
+
return {
|
|
3626
|
+
kind: "encryption",
|
|
3627
|
+
resource,
|
|
3628
|
+
action: "tinycloud.encryption/decrypt"
|
|
3629
|
+
};
|
|
3630
|
+
}
|
|
3631
|
+
throw new Error("capability.kind is invalid");
|
|
3632
|
+
}
|
|
3633
|
+
function canonicalizeUnifiedPolicyCapability(input) {
|
|
3634
|
+
return normalizeUnifiedPolicyCapability(input);
|
|
3635
|
+
}
|
|
3636
|
+
function unifiedPolicyCapabilityDigestHex(input) {
|
|
3637
|
+
return hex(
|
|
3638
|
+
(0, import_sha256.sha256)(
|
|
3639
|
+
new TextEncoder().encode(
|
|
3640
|
+
POLICY_CAPABILITY_V1_DOMAIN + jcsCanonicalize(normalizeUnifiedPolicyCapability(input))
|
|
3641
|
+
)
|
|
3642
|
+
)
|
|
3643
|
+
);
|
|
3644
|
+
}
|
|
3645
|
+
function unifiedPolicyCapabilityContains(authorityInput, requestedInput) {
|
|
3646
|
+
try {
|
|
3647
|
+
const authority = normalizeUnifiedPolicyCapability(authorityInput);
|
|
3648
|
+
const requested = normalizeUnifiedPolicyCapability(requestedInput);
|
|
3649
|
+
if (authority.kind !== requested.kind) return false;
|
|
3650
|
+
if (authority.kind === "encryption" && requested.kind === "encryption")
|
|
3651
|
+
return authority.resource === requested.resource && authority.action === requested.action;
|
|
3652
|
+
if (authority.kind !== "kv" || requested.kind !== "kv") return false;
|
|
3653
|
+
const { resource: authorized } = authority;
|
|
3654
|
+
const { resource: requestedResource } = requested;
|
|
3655
|
+
const pathContained = authority.selector === "exact" ? authorized === requestedResource : authorized === requestedResource || requestedResource.startsWith(`${authorized}/`);
|
|
3656
|
+
if (!pathContained || authority.selector === "exact" && requested.selector === "prefix")
|
|
3657
|
+
return false;
|
|
3658
|
+
return requested.actions.every(
|
|
3659
|
+
(action) => authority.actions.includes(action)
|
|
3660
|
+
);
|
|
3661
|
+
} catch {
|
|
3662
|
+
return false;
|
|
3663
|
+
}
|
|
3664
|
+
}
|
|
3665
|
+
function projectUnifiedPolicyCapability(input) {
|
|
3666
|
+
const capability = normalizeUnifiedPolicyCapability(input);
|
|
3667
|
+
if (capability.kind === "encryption") {
|
|
3668
|
+
return {
|
|
3669
|
+
service: "tinycloud.encryption",
|
|
3670
|
+
space: capability.resource,
|
|
3671
|
+
path: capability.resource,
|
|
3672
|
+
actions: [capability.action]
|
|
3673
|
+
};
|
|
3674
|
+
}
|
|
3675
|
+
const { space, path } = parseKvResource(capability.resource);
|
|
3676
|
+
return {
|
|
3677
|
+
service: "tinycloud.kv",
|
|
3678
|
+
space,
|
|
3679
|
+
path,
|
|
3680
|
+
actions: [...capability.actions],
|
|
3681
|
+
caveat: {
|
|
3682
|
+
type: "xyz.tinycloud.resource/selector",
|
|
3683
|
+
kind: capability.selector,
|
|
3684
|
+
value: capability.resource
|
|
3685
|
+
}
|
|
3686
|
+
};
|
|
3687
|
+
}
|
|
3688
|
+
function projectUnifiedPolicyCapabilities(input) {
|
|
3689
|
+
return input.map(projectUnifiedPolicyCapability).sort((left, right) => {
|
|
3690
|
+
const a = jcsCanonicalize(left);
|
|
3691
|
+
const b = jcsCanonicalize(right);
|
|
3692
|
+
return a < b ? -1 : a > b ? 1 : 0;
|
|
3693
|
+
});
|
|
3694
|
+
}
|
|
3695
|
+
function unifiedNativeProjectionHashHex(input) {
|
|
3696
|
+
return hex(
|
|
3697
|
+
(0, import_sha256.sha256)(
|
|
3698
|
+
new TextEncoder().encode(
|
|
3699
|
+
NATIVE_PROJECTION_V1_DOMAIN + jcsCanonicalize(projectUnifiedPolicyCapabilities(input))
|
|
3700
|
+
)
|
|
3701
|
+
)
|
|
3702
|
+
);
|
|
3703
|
+
}
|
|
3704
|
+
function unifiedPolicyCapabilityFromNative(input) {
|
|
3705
|
+
const value = object(input, "native capability");
|
|
3706
|
+
exactKeys(
|
|
3707
|
+
value,
|
|
3708
|
+
["service", "space", "path", "actions", "caveat"],
|
|
3709
|
+
"native capability"
|
|
3710
|
+
);
|
|
3711
|
+
const service = nonEmptyString(value.service, "native.service");
|
|
3712
|
+
const actions = value.actions;
|
|
3713
|
+
if (!Array.isArray(actions)) throw new Error("native.actions is invalid");
|
|
3714
|
+
if (service === "tinycloud.encryption" && value.caveat === void 0 && value.space === value.path && actions.length === 1 && actions[0] === "tinycloud.encryption/decrypt") {
|
|
3715
|
+
return normalizeUnifiedPolicyCapability({
|
|
3716
|
+
kind: "encryption",
|
|
3717
|
+
resource: value.space,
|
|
3718
|
+
action: actions[0]
|
|
3719
|
+
});
|
|
3720
|
+
}
|
|
3721
|
+
if (service !== "tinycloud.kv" || typeof value.space !== "string" || typeof value.path !== "string")
|
|
3722
|
+
throw new Error("native capability is not supported");
|
|
3723
|
+
const caveat = object(value.caveat, "native.caveat");
|
|
3724
|
+
exactKeys(caveat, ["type", "kind", "value"], "native selector caveat");
|
|
3725
|
+
if (caveat.type !== "xyz.tinycloud.resource/selector" || caveat.kind !== "exact" && caveat.kind !== "prefix" || caveat.value !== `tinycloud://${value.space}/kv/${value.path}`)
|
|
3726
|
+
throw new Error("native selector caveat does not match capability");
|
|
3727
|
+
return normalizeUnifiedPolicyCapability({
|
|
3728
|
+
kind: "kv",
|
|
3729
|
+
resource: caveat.value,
|
|
3730
|
+
selector: caveat.kind,
|
|
3731
|
+
actions
|
|
3732
|
+
});
|
|
3733
|
+
}
|
|
3734
|
+
function contentSourceDigestHex(input) {
|
|
3735
|
+
return hex(
|
|
3736
|
+
(0, import_sha256.sha256)(
|
|
3737
|
+
new TextEncoder().encode(
|
|
3738
|
+
CONTENT_SOURCE_V1_DOMAIN + jcsCanonicalize(input)
|
|
3739
|
+
)
|
|
3740
|
+
)
|
|
3741
|
+
);
|
|
3742
|
+
}
|
|
3743
|
+
function policyDigestHex(policy) {
|
|
3744
|
+
const canonicalPolicy = {
|
|
3745
|
+
...policy,
|
|
3746
|
+
capabilityCeiling: policy.capabilityCeiling.map(
|
|
3747
|
+
normalizeUnifiedPolicyCapability
|
|
3748
|
+
)
|
|
3749
|
+
};
|
|
3750
|
+
return hex(
|
|
3751
|
+
(0, import_sha256.sha256)(
|
|
3752
|
+
new TextEncoder().encode(
|
|
3753
|
+
POLICY_V1_DOMAIN + jcsCanonicalize(canonicalPolicy)
|
|
3754
|
+
)
|
|
3755
|
+
)
|
|
3756
|
+
);
|
|
3757
|
+
}
|
|
3758
|
+
function policyIdForDigestHex(digestHex) {
|
|
3759
|
+
const digest4 = Uint8Array.from(
|
|
3760
|
+
(digestHex.match(/.{2}/g) ?? []).map((byte) => Number.parseInt(byte, 16))
|
|
3761
|
+
);
|
|
3762
|
+
if (digest4.length !== 32) throw new Error("policy digest must be 32 bytes");
|
|
3763
|
+
return `pol_${base32Lower(digest4)}`;
|
|
3764
|
+
}
|
|
3765
|
+
function policyCidFromCanonicalBytes(bytes2) {
|
|
3766
|
+
return CID.createV1(85, create(18, (0, import_sha256.sha256)(bytes2))).toString();
|
|
3767
|
+
}
|
|
3768
|
+
var CompactHeaderSchema = import_zod2.z.object({
|
|
3769
|
+
alg: import_zod2.z.literal("EdDSA"),
|
|
3770
|
+
jwk: import_zod2.z.object({ alg: import_zod2.z.literal("EdDSA"), crv: import_zod2.z.literal("Ed25519"), kty: import_zod2.z.literal("OKP"), x: import_zod2.z.string().min(1) }).strict(),
|
|
3771
|
+
typ: import_zod2.z.literal("JWT"),
|
|
3772
|
+
ucv: import_zod2.z.literal("0.10.0")
|
|
3773
|
+
}).strict();
|
|
3774
|
+
var CompactPayloadSchema = import_zod2.z.object({
|
|
3775
|
+
att: import_zod2.z.record(import_zod2.z.record(import_zod2.z.array(import_zod2.z.unknown()).min(1))),
|
|
3776
|
+
aud: import_zod2.z.string().min(1),
|
|
3777
|
+
exp: import_zod2.z.number().int(),
|
|
3778
|
+
fct: import_zod2.z.array(import_zod2.z.record(import_zod2.z.unknown())).length(1),
|
|
3779
|
+
iss: import_zod2.z.string().min(1),
|
|
3780
|
+
nbf: import_zod2.z.number().int(),
|
|
3781
|
+
nnc: import_zod2.z.string().min(1),
|
|
3782
|
+
prf: import_zod2.z.array(import_zod2.z.string().min(1))
|
|
3783
|
+
}).strict();
|
|
3784
|
+
async function signCompactUcanAuthorization(input) {
|
|
3785
|
+
if (input.notBefore >= input.expiresAt || input.expiresAt - input.notBefore > 60)
|
|
3786
|
+
throw new Error("compact invocation lifetime must be between one and 60 seconds");
|
|
3787
|
+
const principal = input.issuerDid.split("#", 1)[0];
|
|
3788
|
+
const didMaterial = principal.startsWith("did:key:") ? base58btc.decode(principal.slice("did:key:".length)) : new Uint8Array();
|
|
3789
|
+
if (didMaterial.length !== 34 || didMaterial[0] !== 237 || didMaterial[1] !== 1)
|
|
3790
|
+
throw new Error("compact UCAN signer must be did:key Ed25519");
|
|
3791
|
+
const header = { alg: "EdDSA", jwk: { alg: "EdDSA", crv: "Ed25519", kty: "OKP", x: encodeBase64Url(didMaterial.slice(2)) }, typ: "JWT", ucv: "0.10.0" };
|
|
3792
|
+
const payload = {
|
|
3793
|
+
att: input.attenuation,
|
|
3794
|
+
aud: input.audienceDid,
|
|
3795
|
+
exp: input.expiresAt,
|
|
3796
|
+
fct: input.facts,
|
|
3797
|
+
iss: input.issuerDid.includes("#") ? input.issuerDid : `${principal}#${principal.slice("did:key:".length)}`,
|
|
3798
|
+
nbf: input.notBefore,
|
|
3799
|
+
nnc: input.nonce,
|
|
3800
|
+
prf: input.proofs
|
|
3801
|
+
};
|
|
3802
|
+
const protectedSegment = encodeBase64Url(new TextEncoder().encode(jcsCanonicalize(header)));
|
|
3803
|
+
const payloadSegment = encodeBase64Url(new TextEncoder().encode(jcsCanonicalize(payload)));
|
|
3804
|
+
const signature = await input.sign(new TextEncoder().encode(`${protectedSegment}.${payloadSegment}`));
|
|
3805
|
+
if (signature.length !== 64) throw new Error("compact Authorization signature must be Ed25519");
|
|
3806
|
+
return parseCompactUcanAuthorization(`${protectedSegment}.${payloadSegment}.${encodeBase64Url(signature)}`);
|
|
3807
|
+
}
|
|
3808
|
+
function createCompactPolicyInvocation(input) {
|
|
3809
|
+
const session = parsePolicySessionUcan(input.sessionAuthorization);
|
|
3810
|
+
if (session.cid !== input.sessionCid || session.aud !== input.recipientDid)
|
|
3811
|
+
throw new Error("policy session does not bind the recipient signer");
|
|
3812
|
+
const principal = input.recipientDid.split("#", 1)[0];
|
|
3813
|
+
const didMaterial = base58btc.decode(principal.slice("did:key:".length));
|
|
3814
|
+
if (didMaterial.length !== 34 || didMaterial[0] !== 237 || didMaterial[1] !== 1)
|
|
3815
|
+
throw new Error("policy invocation signer must be did:key Ed25519");
|
|
3816
|
+
const publicKey = import_ed255192.ed25519.getPublicKey(input.privateKey);
|
|
3817
|
+
if (!equalBytes(publicKey, didMaterial.slice(2)))
|
|
3818
|
+
throw new Error("policy invocation private key does not bind recipient DID");
|
|
3819
|
+
const now = input.now ?? Math.floor(Date.now() / 1e3);
|
|
3820
|
+
const exp = Math.min(now + 60, session.exp);
|
|
3821
|
+
if (exp <= now) throw new Error("policy session has expired");
|
|
3822
|
+
const header = { alg: "EdDSA", jwk: { alg: "EdDSA", crv: "Ed25519", kty: "OKP", x: encodeBase64Url(publicKey) }, typ: "JWT", ucv: "0.10.0" };
|
|
3823
|
+
const payload = {
|
|
3824
|
+
att: { [input.resource]: { [input.action]: [input.caveat ?? {}] } },
|
|
3825
|
+
aud: input.audienceDid,
|
|
3826
|
+
exp,
|
|
3827
|
+
fct: [input.facts ?? { type: "tinycloud.policy.invocation/v1", policyCid: session.fact.policyCid, sessionCid: session.cid }],
|
|
3828
|
+
iss: input.recipientDid.includes("#") ? input.recipientDid : `${principal}#${principal.slice("did:key:".length)}`,
|
|
3829
|
+
nbf: now,
|
|
3830
|
+
nnc: input.nonce ?? encodeBase64Url(crypto.getRandomValues(new Uint8Array(16))),
|
|
3831
|
+
prf: [session.cid]
|
|
3832
|
+
};
|
|
3833
|
+
const protectedSegment = encodeBase64Url(new TextEncoder().encode(jcsCanonicalize(header)));
|
|
3834
|
+
const payloadSegment = encodeBase64Url(new TextEncoder().encode(jcsCanonicalize(payload)));
|
|
3835
|
+
const signingInput = new TextEncoder().encode(`${protectedSegment}.${payloadSegment}`);
|
|
3836
|
+
const signature = import_ed255192.ed25519.sign(signingInput, input.privateKey);
|
|
3837
|
+
return parseCompactUcanAuthorization(`${protectedSegment}.${payloadSegment}.${encodeBase64Url(signature)}`);
|
|
3838
|
+
}
|
|
3839
|
+
function createCompactPolicyDescendant(input) {
|
|
3840
|
+
const parent = parseCompactUcanAuthorization(input.parentAuthorization, input.parentCid);
|
|
3841
|
+
if (parent.payload.aud !== input.issuerDid) throw new Error("policy descendant issuer is not the parent audience");
|
|
3842
|
+
const parentFact = parent.payload.fct[0];
|
|
3843
|
+
const depth = parentFact.remainingRedelegationDepth;
|
|
3844
|
+
if (!Number.isInteger(depth) || depth <= 0) throw new Error("policy descendant depth is exhausted");
|
|
3845
|
+
if (!compactAttenuationContains(parent.payload.att, input.attenuation))
|
|
3846
|
+
throw new Error("policy descendant exceeds the parent attenuation");
|
|
3847
|
+
const principal = input.issuerDid.split("#", 1)[0];
|
|
3848
|
+
const didMaterial = base58btc.decode(principal.slice("did:key:".length));
|
|
3849
|
+
const publicKey = import_ed255192.ed25519.getPublicKey(input.privateKey);
|
|
3850
|
+
if (didMaterial.length !== 34 || !equalBytes(publicKey, didMaterial.slice(2))) throw new Error("policy descendant signer does not bind issuer DID");
|
|
3851
|
+
const now = Math.max(input.now ?? Math.floor(Date.now() / 1e3), parent.payload.nbf + 1);
|
|
3852
|
+
const exp = Math.min(input.expiresAt ?? now + 60, now + 60, parent.payload.exp - 1);
|
|
3853
|
+
if (exp <= now) throw new Error("policy parent has no strictly narrower validity window");
|
|
3854
|
+
const header = { alg: "EdDSA", jwk: { alg: "EdDSA", crv: "Ed25519", kty: "OKP", x: encodeBase64Url(publicKey) }, typ: "JWT", ucv: "0.10.0" };
|
|
3855
|
+
const payload = {
|
|
3856
|
+
att: input.attenuation,
|
|
3857
|
+
aud: input.audienceDid,
|
|
3858
|
+
exp,
|
|
3859
|
+
fct: [{ ...parentFact, remainingRedelegationDepth: depth - 1 }],
|
|
3860
|
+
iss: input.issuerDid.includes("#") ? input.issuerDid : `${principal}#${principal.slice("did:key:".length)}`,
|
|
3861
|
+
nbf: now,
|
|
3862
|
+
nnc: input.nonce ?? encodeBase64Url(crypto.getRandomValues(new Uint8Array(16))),
|
|
3863
|
+
prf: [parent.cid]
|
|
3864
|
+
};
|
|
3865
|
+
const protectedSegment = encodeBase64Url(new TextEncoder().encode(jcsCanonicalize(header)));
|
|
3866
|
+
const payloadSegment = encodeBase64Url(new TextEncoder().encode(jcsCanonicalize(payload)));
|
|
3867
|
+
const signature = import_ed255192.ed25519.sign(new TextEncoder().encode(`${protectedSegment}.${payloadSegment}`), input.privateKey);
|
|
3868
|
+
return parseCompactUcanAuthorization(`${protectedSegment}.${payloadSegment}.${encodeBase64Url(signature)}`);
|
|
3869
|
+
}
|
|
3870
|
+
function compactAttenuationContains(parent, child) {
|
|
3871
|
+
const selector = (value) => {
|
|
3872
|
+
if (value.length !== 1 || !isRecordValue(value[0])) return void 0;
|
|
3873
|
+
const caveat = value[0];
|
|
3874
|
+
if (Object.keys(caveat).length !== 3 || caveat.type !== "xyz.tinycloud.resource/selector" || caveat.kind !== "exact" && caveat.kind !== "prefix" || typeof caveat.value !== "string") return void 0;
|
|
3875
|
+
return { kind: caveat.kind, value: caveat.value };
|
|
3876
|
+
};
|
|
3877
|
+
const equal = (left, right) => jcsCanonicalize(left) === jcsCanonicalize(right);
|
|
3878
|
+
return Object.entries(child).every(
|
|
3879
|
+
([childResource, childActions]) => Object.entries(childActions).every(
|
|
3880
|
+
([action, childCaveats]) => Object.entries(parent).some(([parentResource, parentActions]) => {
|
|
3881
|
+
const parentCaveats = parentActions[action];
|
|
3882
|
+
if (parentCaveats === void 0) return false;
|
|
3883
|
+
if (parentResource === childResource && equal(parentCaveats, childCaveats)) return true;
|
|
3884
|
+
const parentSelector = selector(parentCaveats);
|
|
3885
|
+
const childSelector = selector(childCaveats);
|
|
3886
|
+
return parentSelector?.kind === "prefix" && childSelector !== void 0 && parentSelector.value === parentResource && childSelector.value === childResource && (childResource === parentResource || childResource.startsWith(`${parentResource}/`));
|
|
3887
|
+
})
|
|
3888
|
+
)
|
|
3889
|
+
);
|
|
3890
|
+
}
|
|
3891
|
+
function isRecordValue(value) {
|
|
3892
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
3893
|
+
}
|
|
3894
|
+
function parseCompactUcanAuthorization(input, expectedCid) {
|
|
3895
|
+
if (typeof input !== "string" || /\s/.test(input))
|
|
3896
|
+
throw new Error("Authorization must be compact UCAN bytes");
|
|
3897
|
+
const segments = input.split(".");
|
|
3898
|
+
if (segments.length !== 3 || segments.some((segment) => segment.length === 0))
|
|
3899
|
+
throw new Error("Authorization must have three compact segments");
|
|
3900
|
+
const [headerSegment, payloadSegment, signatureSegment] = segments;
|
|
3901
|
+
const headerBytes = decodeBase64Url(headerSegment);
|
|
3902
|
+
const payloadBytes = decodeBase64Url(payloadSegment);
|
|
3903
|
+
const signature = decodeBase64Url(signatureSegment);
|
|
3904
|
+
const headerValue = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(headerBytes));
|
|
3905
|
+
const payloadValue = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(payloadBytes));
|
|
3906
|
+
if (jcsCanonicalize(headerValue) !== new TextDecoder().decode(headerBytes) || jcsCanonicalize(payloadValue) !== new TextDecoder().decode(payloadBytes))
|
|
3907
|
+
throw new Error("compact UCAN segments are not canonical JCS");
|
|
3908
|
+
const header = CompactHeaderSchema.parse(headerValue);
|
|
3909
|
+
const payload = CompactPayloadSchema.parse(payloadValue);
|
|
3910
|
+
if (payload.nbf >= payload.exp) throw new Error("compact UCAN validity is empty");
|
|
3911
|
+
const principal = payload.iss.split("#", 1)[0];
|
|
3912
|
+
const didMaterial = principal.startsWith("did:key:") ? base58btc.decode(principal.slice("did:key:".length)) : new Uint8Array();
|
|
3913
|
+
if (didMaterial.length !== 34 || didMaterial[0] !== 237 || didMaterial[1] !== 1)
|
|
3914
|
+
throw new Error("compact UCAN issuer must be did:key Ed25519");
|
|
3915
|
+
const publicKey = didMaterial.slice(2);
|
|
3916
|
+
if (!equalBytes(publicKey, decodeBase64Url(header.jwk.x)))
|
|
3917
|
+
throw new Error("compact UCAN JWK does not bind issuer");
|
|
3918
|
+
if (!import_ed255192.ed25519.verify(signature, new TextEncoder().encode(`${headerSegment}.${payloadSegment}`), publicKey))
|
|
3919
|
+
throw new Error("compact UCAN signature is invalid");
|
|
3920
|
+
const cid2 = CID.createV1(85, create(30, (0, import_blake3.blake3)(new TextEncoder().encode(input)))).toString();
|
|
3921
|
+
if (expectedCid !== void 0 && cid2 !== expectedCid)
|
|
3922
|
+
throw new Error("compact UCAN CID does not match exact Authorization bytes");
|
|
3923
|
+
return { authorization: input, cid: cid2, header, payload };
|
|
3924
|
+
}
|
|
3925
|
+
function parsePolicySessionUcan(authorization, expectedProofs) {
|
|
3926
|
+
const parsed = parseCompactUcanAuthorization(authorization);
|
|
3927
|
+
const fact = parsed.payload.fct[0];
|
|
3928
|
+
if (parsed.payload.prf.length !== 2 || parsed.payload.prf[0] === parsed.payload.prf[1])
|
|
3929
|
+
throw new Error("policy session UCAN requires two distinct ordered proofs");
|
|
3930
|
+
if (expectedProofs !== void 0 && (parsed.payload.prf[0] !== expectedProofs[0] || parsed.payload.prf[1] !== expectedProofs[1]))
|
|
3931
|
+
throw new Error("policy session UCAN ordered proofs do not match");
|
|
3932
|
+
const factKeys = Object.keys(fact);
|
|
3933
|
+
if (factKeys.length !== POLICY_SESSION_FACT_KEYS.length || factKeys.some((key) => !POLICY_SESSION_FACT_KEYS.includes(key)) || POLICY_SESSION_FACT_KEYS.some((key) => !(key in fact)))
|
|
3934
|
+
throw new Error("policy session UCAN fact is incomplete");
|
|
3935
|
+
if (fact.profile !== POLICY_SESSION_UCAN_V1_PROFILE || typeof fact.remainingRedelegationDepth !== "number" || !Number.isInteger(fact.remainingRedelegationDepth) || fact.remainingRedelegationDepth < 0 || fact.remainingRedelegationDepth > 8 || parsed.payload.exp - parsed.payload.nbf > 60 || parsed.payload.iss.split("#", 1)[0] !== fact.enforcerDid || parsed.payload.aud !== fact.recipientDid)
|
|
3936
|
+
throw new Error("policy session UCAN fact is invalid");
|
|
3937
|
+
return {
|
|
3938
|
+
authorization,
|
|
3939
|
+
cid: parsed.cid,
|
|
3940
|
+
iss: parsed.payload.iss,
|
|
3941
|
+
aud: parsed.payload.aud,
|
|
3942
|
+
prf: parsed.payload.prf,
|
|
3943
|
+
att: parsed.payload.att,
|
|
3944
|
+
nbf: parsed.payload.nbf,
|
|
3945
|
+
exp: parsed.payload.exp,
|
|
3946
|
+
nnc: parsed.payload.nnc,
|
|
3947
|
+
fact
|
|
3948
|
+
};
|
|
3949
|
+
}
|
|
3950
|
+
function decodeBase64Url(value) {
|
|
3951
|
+
if (!/^[A-Za-z0-9_-]+$/.test(value) || value.length % 4 === 1)
|
|
3952
|
+
throw new Error("value is not canonical base64url");
|
|
3953
|
+
const normalized = value.replace(/-/g, "+").replace(/_/g, "/");
|
|
3954
|
+
const binary = typeof Buffer !== "undefined" ? Buffer.from(normalized, "base64").toString("binary") : atob(normalized.padEnd(Math.ceil(normalized.length / 4) * 4, "="));
|
|
3955
|
+
const bytes2 = Uint8Array.from(binary, (character) => character.charCodeAt(0));
|
|
3956
|
+
const encoded = typeof Buffer !== "undefined" ? Buffer.from(bytes2).toString("base64url") : btoa(String.fromCharCode(...bytes2)).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
3957
|
+
if (encoded !== value) throw new Error("value is not canonical base64url");
|
|
3958
|
+
return bytes2;
|
|
3959
|
+
}
|
|
3960
|
+
function encodeBase64Url(value) {
|
|
3961
|
+
return typeof Buffer !== "undefined" ? Buffer.from(value).toString("base64url") : btoa(String.fromCharCode(...value)).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
3962
|
+
}
|
|
3963
|
+
function equalBytes(left, right) {
|
|
3964
|
+
return left.length === right.length && left.every((byte, index) => byte === right[index]);
|
|
3965
|
+
}
|
|
3966
|
+
function hex(bytes2) {
|
|
3967
|
+
return [...bytes2].map((byte) => byte.toString(16).padStart(2, "0")).join("");
|
|
3968
|
+
}
|
|
3969
|
+
function base32Lower(bytes2) {
|
|
3970
|
+
const alphabet2 = "abcdefghijklmnopqrstuvwxyz234567";
|
|
3971
|
+
let output = "";
|
|
3972
|
+
let buffer = 0;
|
|
3973
|
+
let bits = 0;
|
|
3974
|
+
for (const byte of bytes2) {
|
|
3975
|
+
buffer = buffer << 8 | byte;
|
|
3976
|
+
bits += 8;
|
|
3977
|
+
while (bits >= 5) {
|
|
3978
|
+
output += alphabet2[buffer >>> bits - 5 & 31];
|
|
3979
|
+
bits -= 5;
|
|
3980
|
+
}
|
|
3981
|
+
}
|
|
3982
|
+
if (bits > 0) output += alphabet2[buffer << 5 - bits & 31];
|
|
3983
|
+
return output;
|
|
3339
3984
|
}
|
|
3340
3985
|
|
|
3341
3986
|
// src/requester/index.ts
|
|
@@ -3414,109 +4059,109 @@ var TranscriptRequesterError = class extends Error {
|
|
|
3414
4059
|
this.status = status;
|
|
3415
4060
|
}
|
|
3416
4061
|
};
|
|
3417
|
-
var JsonValueSchema =
|
|
3418
|
-
() =>
|
|
3419
|
-
|
|
3420
|
-
|
|
3421
|
-
|
|
3422
|
-
|
|
3423
|
-
|
|
3424
|
-
|
|
4062
|
+
var JsonValueSchema = import_zod3.z.lazy(
|
|
4063
|
+
() => import_zod3.z.union([
|
|
4064
|
+
import_zod3.z.string(),
|
|
4065
|
+
import_zod3.z.number().finite(),
|
|
4066
|
+
import_zod3.z.boolean(),
|
|
4067
|
+
import_zod3.z.null(),
|
|
4068
|
+
import_zod3.z.array(JsonValueSchema),
|
|
4069
|
+
import_zod3.z.record(JsonValueSchema)
|
|
3425
4070
|
])
|
|
3426
4071
|
);
|
|
3427
|
-
var Rfc3339Schema =
|
|
4072
|
+
var Rfc3339Schema = import_zod3.z.string().refine((value) => parseStrictRfc33392(value) !== void 0, {
|
|
3428
4073
|
message: "must be strict RFC 3339 date-time with timezone"
|
|
3429
4074
|
});
|
|
3430
|
-
var SignedRecordSchema =
|
|
3431
|
-
schema:
|
|
3432
|
-
engineRecordId:
|
|
3433
|
-
ownerDid:
|
|
3434
|
-
endpoint:
|
|
3435
|
-
audience:
|
|
3436
|
-
supportedPolicyVersions:
|
|
3437
|
-
supportedEvidenceVerifiers:
|
|
3438
|
-
grantIssuerDid:
|
|
4075
|
+
var SignedRecordSchema = import_zod3.z.object({
|
|
4076
|
+
schema: import_zod3.z.string(),
|
|
4077
|
+
engineRecordId: import_zod3.z.string(),
|
|
4078
|
+
ownerDid: import_zod3.z.string(),
|
|
4079
|
+
endpoint: import_zod3.z.string(),
|
|
4080
|
+
audience: import_zod3.z.string(),
|
|
4081
|
+
supportedPolicyVersions: import_zod3.z.array(import_zod3.z.string()),
|
|
4082
|
+
supportedEvidenceVerifiers: import_zod3.z.array(import_zod3.z.string()),
|
|
4083
|
+
grantIssuerDid: import_zod3.z.string(),
|
|
3439
4084
|
expiresAt: Rfc3339Schema,
|
|
3440
|
-
signature:
|
|
3441
|
-
suite:
|
|
3442
|
-
signerDid:
|
|
3443
|
-
value:
|
|
4085
|
+
signature: import_zod3.z.object({
|
|
4086
|
+
suite: import_zod3.z.string(),
|
|
4087
|
+
signerDid: import_zod3.z.string(),
|
|
4088
|
+
value: import_zod3.z.string()
|
|
3444
4089
|
}).strict()
|
|
3445
4090
|
}).strict();
|
|
3446
|
-
var PolicyEngineSchema =
|
|
3447
|
-
endpoint:
|
|
3448
|
-
audience:
|
|
3449
|
-
supportedEvidenceVerifiers:
|
|
3450
|
-
|
|
4091
|
+
var PolicyEngineSchema = import_zod3.z.object({
|
|
4092
|
+
endpoint: import_zod3.z.string().url(),
|
|
4093
|
+
audience: import_zod3.z.string(),
|
|
4094
|
+
supportedEvidenceVerifiers: import_zod3.z.tuple([
|
|
4095
|
+
import_zod3.z.literal(W3C_VC_CREDENTIAL_VERIFIER)
|
|
3451
4096
|
]),
|
|
3452
4097
|
signedRecord: SignedRecordSchema
|
|
3453
4098
|
}).strict();
|
|
3454
|
-
var OwnerNodeSchema =
|
|
3455
|
-
schema:
|
|
3456
|
-
endpoint:
|
|
3457
|
-
spaceId:
|
|
4099
|
+
var OwnerNodeSchema = import_zod3.z.object({
|
|
4100
|
+
schema: import_zod3.z.literal(OWNER_NODE_ENDPOINT_SCHEMA),
|
|
4101
|
+
endpoint: import_zod3.z.string().url(),
|
|
4102
|
+
spaceId: import_zod3.z.string().min(1)
|
|
3458
4103
|
}).strict();
|
|
3459
|
-
var ResourceHintSchema =
|
|
3460
|
-
resourceType:
|
|
3461
|
-
resourceId:
|
|
3462
|
-
requestedCapabilities:
|
|
4104
|
+
var ResourceHintSchema = import_zod3.z.object({
|
|
4105
|
+
resourceType: import_zod3.z.string(),
|
|
4106
|
+
resourceId: import_zod3.z.string(),
|
|
4107
|
+
requestedCapabilities: import_zod3.z.array(JsonValueSchema).min(1)
|
|
3463
4108
|
}).strict();
|
|
3464
|
-
var BootstrapSchema =
|
|
3465
|
-
schema:
|
|
3466
|
-
policyId:
|
|
4109
|
+
var BootstrapSchema = import_zod3.z.object({
|
|
4110
|
+
schema: import_zod3.z.literal(TRANSCRIPT_SHARE_BOOTSTRAP_SCHEMA),
|
|
4111
|
+
policyId: import_zod3.z.string(),
|
|
3467
4112
|
policyEngine: PolicyEngineSchema,
|
|
3468
4113
|
ownerNode: OwnerNodeSchema,
|
|
3469
4114
|
resourceHint: ResourceHintSchema
|
|
3470
4115
|
}).strict();
|
|
3471
|
-
var SignatureSchema =
|
|
3472
|
-
suite:
|
|
3473
|
-
signerDid:
|
|
3474
|
-
value:
|
|
4116
|
+
var SignatureSchema = import_zod3.z.object({
|
|
4117
|
+
suite: import_zod3.z.string(),
|
|
4118
|
+
signerDid: import_zod3.z.string(),
|
|
4119
|
+
value: import_zod3.z.string()
|
|
3475
4120
|
}).strict();
|
|
3476
|
-
var ChallengeSchema =
|
|
3477
|
-
schema:
|
|
3478
|
-
challengeId:
|
|
3479
|
-
policyId:
|
|
3480
|
-
audience:
|
|
3481
|
-
nonce:
|
|
4121
|
+
var ChallengeSchema = import_zod3.z.object({
|
|
4122
|
+
schema: import_zod3.z.literal(POLICY_ENGINE_CHALLENGE_RESPONSE_SCHEMA),
|
|
4123
|
+
challengeId: import_zod3.z.string(),
|
|
4124
|
+
policyId: import_zod3.z.string(),
|
|
4125
|
+
audience: import_zod3.z.string(),
|
|
4126
|
+
nonce: import_zod3.z.string().min(16),
|
|
3482
4127
|
challengeExpiresAt: Rfc3339Schema,
|
|
3483
|
-
acceptedSuites:
|
|
3484
|
-
requestedCapabilitiesTemplate:
|
|
4128
|
+
acceptedSuites: import_zod3.z.array(import_zod3.z.string()).min(1),
|
|
4129
|
+
requestedCapabilitiesTemplate: import_zod3.z.array(JsonValueSchema).optional(),
|
|
3485
4130
|
signature: SignatureSchema
|
|
3486
4131
|
}).strict();
|
|
3487
|
-
var ChallengeResponseSchema =
|
|
3488
|
-
var DenialSchema =
|
|
3489
|
-
schema:
|
|
3490
|
-
code:
|
|
3491
|
-
message:
|
|
4132
|
+
var ChallengeResponseSchema = import_zod3.z.object({ challenge: ChallengeSchema }).strict();
|
|
4133
|
+
var DenialSchema = import_zod3.z.object({
|
|
4134
|
+
schema: import_zod3.z.literal(POLICY_ENGINE_DENIAL_SCHEMA),
|
|
4135
|
+
code: import_zod3.z.enum(POLICY_ENGINE_GRANT_PRESENTATION_DENIAL_CODES),
|
|
4136
|
+
message: import_zod3.z.string().optional()
|
|
3492
4137
|
}).strict();
|
|
3493
|
-
var ErrorEnvelopeDenialSchema =
|
|
3494
|
-
error:
|
|
3495
|
-
code:
|
|
3496
|
-
message:
|
|
4138
|
+
var ErrorEnvelopeDenialSchema = import_zod3.z.object({
|
|
4139
|
+
error: import_zod3.z.object({
|
|
4140
|
+
code: import_zod3.z.enum(POLICY_ENGINE_GRANT_PRESENTATION_DENIAL_CODES),
|
|
4141
|
+
message: import_zod3.z.string().optional()
|
|
3497
4142
|
}).strict()
|
|
3498
4143
|
}).strict();
|
|
3499
|
-
var WireDelegationSchema =
|
|
3500
|
-
delegationId:
|
|
3501
|
-
issuanceId:
|
|
3502
|
-
issuerDid:
|
|
3503
|
-
holderDid:
|
|
3504
|
-
policyId:
|
|
3505
|
-
capabilityHashHex:
|
|
3506
|
-
revocationMode:
|
|
4144
|
+
var WireDelegationSchema = import_zod3.z.object({
|
|
4145
|
+
delegationId: import_zod3.z.string(),
|
|
4146
|
+
issuanceId: import_zod3.z.string().min(1),
|
|
4147
|
+
issuerDid: import_zod3.z.string(),
|
|
4148
|
+
holderDid: import_zod3.z.string(),
|
|
4149
|
+
policyId: import_zod3.z.string(),
|
|
4150
|
+
capabilityHashHex: import_zod3.z.string().regex(/^[0-9a-f]{64}$/),
|
|
4151
|
+
revocationMode: import_zod3.z.literal("refresh_only"),
|
|
3507
4152
|
issuedAt: Rfc3339Schema,
|
|
3508
4153
|
expiresAt: Rfc3339Schema,
|
|
3509
|
-
terminal:
|
|
3510
|
-
encoded:
|
|
4154
|
+
terminal: import_zod3.z.boolean(),
|
|
4155
|
+
encoded: import_zod3.z.string()
|
|
3511
4156
|
}).strict();
|
|
3512
|
-
var ResolveResponseSchema =
|
|
3513
|
-
var DelegateReceiptSchema =
|
|
3514
|
-
cid:
|
|
3515
|
-
activated:
|
|
3516
|
-
skipped:
|
|
4157
|
+
var ResolveResponseSchema = import_zod3.z.object({ delegation: WireDelegationSchema }).strict();
|
|
4158
|
+
var DelegateReceiptSchema = import_zod3.z.object({
|
|
4159
|
+
cid: import_zod3.z.string().min(1),
|
|
4160
|
+
activated: import_zod3.z.array(import_zod3.z.string()),
|
|
4161
|
+
skipped: import_zod3.z.array(import_zod3.z.string())
|
|
3517
4162
|
}).strict();
|
|
3518
|
-
var SqlReadResponseSchema =
|
|
3519
|
-
var KvReadResponseSchema =
|
|
4163
|
+
var SqlReadResponseSchema = import_zod3.z.object({ rows: import_zod3.z.array(JsonValueSchema) }).strict();
|
|
4164
|
+
var KvReadResponseSchema = import_zod3.z.object({ value: JsonValueSchema }).strict();
|
|
3520
4165
|
var LISTEN_SQL_STATEMENT_CATALOG = [
|
|
3521
4166
|
{
|
|
3522
4167
|
name: "listen.getConversation",
|
|
@@ -4506,7 +5151,7 @@ function nodeErrorMessage(body) {
|
|
|
4506
5151
|
return "native node refusal";
|
|
4507
5152
|
}
|
|
4508
5153
|
function deriveDelegationCid(encoded) {
|
|
4509
|
-
const digest4 = create(30, (0,
|
|
5154
|
+
const digest4 = create(30, (0, import_blake32.blake3)(new TextEncoder().encode(encoded)));
|
|
4510
5155
|
return CID.createV1(85, digest4).toString();
|
|
4511
5156
|
}
|
|
4512
5157
|
function headersRecord(headers) {
|
|
@@ -4653,55 +5298,55 @@ function parseStrictRfc33392(value) {
|
|
|
4653
5298
|
}
|
|
4654
5299
|
|
|
4655
5300
|
// src/delegations/types.schema.ts
|
|
4656
|
-
var
|
|
4657
|
-
var JWKSchema =
|
|
5301
|
+
var import_zod4 = require("zod");
|
|
5302
|
+
var JWKSchema = import_zod4.z.object({
|
|
4658
5303
|
/** Key type (e.g., "EC", "RSA", "OKP") */
|
|
4659
|
-
kty:
|
|
5304
|
+
kty: import_zod4.z.string(),
|
|
4660
5305
|
/** Curve for EC/OKP keys (e.g., "P-256", "Ed25519") */
|
|
4661
|
-
crv:
|
|
5306
|
+
crv: import_zod4.z.string().optional(),
|
|
4662
5307
|
/** X coordinate for EC keys, public key for OKP */
|
|
4663
|
-
x:
|
|
5308
|
+
x: import_zod4.z.string().optional(),
|
|
4664
5309
|
/** Y coordinate for EC keys */
|
|
4665
|
-
y:
|
|
5310
|
+
y: import_zod4.z.string().optional(),
|
|
4666
5311
|
/** Private key value (d parameter) */
|
|
4667
|
-
d:
|
|
5312
|
+
d: import_zod4.z.string().optional(),
|
|
4668
5313
|
/** Public exponent for RSA keys */
|
|
4669
|
-
e:
|
|
5314
|
+
e: import_zod4.z.string().optional(),
|
|
4670
5315
|
/** Modulus for RSA keys */
|
|
4671
|
-
n:
|
|
5316
|
+
n: import_zod4.z.string().optional(),
|
|
4672
5317
|
/** Key ID */
|
|
4673
|
-
kid:
|
|
5318
|
+
kid: import_zod4.z.string().optional(),
|
|
4674
5319
|
/** Algorithm */
|
|
4675
|
-
alg:
|
|
5320
|
+
alg: import_zod4.z.string().optional(),
|
|
4676
5321
|
/** Key use (e.g., "sig", "enc") */
|
|
4677
|
-
use:
|
|
5322
|
+
use: import_zod4.z.string().optional(),
|
|
4678
5323
|
/** Key operations (e.g., ["sign", "verify"]) */
|
|
4679
|
-
key_ops:
|
|
5324
|
+
key_ops: import_zod4.z.array(import_zod4.z.string()).optional()
|
|
4680
5325
|
});
|
|
4681
|
-
var KeyTypeSchema =
|
|
4682
|
-
var KeyInfoSchema =
|
|
5326
|
+
var KeyTypeSchema = import_zod4.z.enum(["main", "session", "ingested"]);
|
|
5327
|
+
var KeyInfoSchema = import_zod4.z.object({
|
|
4683
5328
|
/** Unique identifier for this key */
|
|
4684
|
-
id:
|
|
5329
|
+
id: import_zod4.z.string(),
|
|
4685
5330
|
/** DID associated with this key */
|
|
4686
|
-
did:
|
|
5331
|
+
did: import_zod4.z.string(),
|
|
4687
5332
|
/** Type of key determining its authority level */
|
|
4688
5333
|
type: KeyTypeSchema,
|
|
4689
5334
|
/** Private key in JWK format */
|
|
4690
5335
|
jwk: JWKSchema.optional(),
|
|
4691
5336
|
/** Priority for key selection (lower = higher priority) */
|
|
4692
|
-
priority:
|
|
5337
|
+
priority: import_zod4.z.number()
|
|
4693
5338
|
});
|
|
4694
|
-
var DelegationErrorSchema =
|
|
5339
|
+
var DelegationErrorSchema = import_zod4.z.object({
|
|
4695
5340
|
/** Error code for programmatic handling */
|
|
4696
|
-
code:
|
|
5341
|
+
code: import_zod4.z.string(),
|
|
4697
5342
|
/** Human-readable error message */
|
|
4698
|
-
message:
|
|
5343
|
+
message: import_zod4.z.string(),
|
|
4699
5344
|
/** The service that produced the error */
|
|
4700
|
-
service:
|
|
5345
|
+
service: import_zod4.z.literal("delegation"),
|
|
4701
5346
|
/** Original error if wrapping another error */
|
|
4702
|
-
cause:
|
|
5347
|
+
cause: import_zod4.z.instanceof(Error).optional(),
|
|
4703
5348
|
/** Additional metadata about the error */
|
|
4704
|
-
meta:
|
|
5349
|
+
meta: import_zod4.z.record(import_zod4.z.string(), import_zod4.z.unknown()).optional()
|
|
4705
5350
|
});
|
|
4706
5351
|
var DelegationErrorCodes = {
|
|
4707
5352
|
AUTH_REQUIRED: "AUTH_REQUIRED",
|
|
@@ -4721,313 +5366,313 @@ var DelegationErrorCodes = {
|
|
|
4721
5366
|
DATA_FETCH_FAILED: "DATA_FETCH_FAILED",
|
|
4722
5367
|
VALIDATION_ERROR: "VALIDATION_ERROR"
|
|
4723
5368
|
};
|
|
4724
|
-
var DelegationSchema =
|
|
5369
|
+
var DelegationSchema = import_zod4.z.object({
|
|
4725
5370
|
/** Content identifier (CID) of the delegation */
|
|
4726
|
-
cid:
|
|
5371
|
+
cid: import_zod4.z.string(),
|
|
4727
5372
|
/** DID of the delegate (the party receiving the delegation) */
|
|
4728
|
-
delegateDID:
|
|
5373
|
+
delegateDID: import_zod4.z.string(),
|
|
4729
5374
|
/** Space ID this delegation applies to */
|
|
4730
|
-
spaceId:
|
|
5375
|
+
spaceId: import_zod4.z.string(),
|
|
4731
5376
|
/** Resource path this delegation grants access to */
|
|
4732
|
-
path:
|
|
5377
|
+
path: import_zod4.z.string(),
|
|
4733
5378
|
/** Actions this delegation authorizes */
|
|
4734
|
-
actions:
|
|
5379
|
+
actions: import_zod4.z.array(import_zod4.z.string()),
|
|
4735
5380
|
/** Exact ReCap caveats that constrain every action in this scope. */
|
|
4736
|
-
caveats:
|
|
5381
|
+
caveats: import_zod4.z.array(import_zod4.z.record(import_zod4.z.string(), import_zod4.z.unknown())).optional(),
|
|
4737
5382
|
/** When this delegation expires (accepts Date or ISO string from JSON) */
|
|
4738
|
-
expiry:
|
|
5383
|
+
expiry: import_zod4.z.coerce.date(),
|
|
4739
5384
|
/** Whether this delegation has been revoked */
|
|
4740
|
-
isRevoked:
|
|
5385
|
+
isRevoked: import_zod4.z.boolean(),
|
|
4741
5386
|
/** DID of the delegator (the party granting the delegation) */
|
|
4742
|
-
delegatorDID:
|
|
5387
|
+
delegatorDID: import_zod4.z.string().optional(),
|
|
4743
5388
|
/** When this delegation was created (accepts Date or ISO string from JSON) */
|
|
4744
|
-
createdAt:
|
|
5389
|
+
createdAt: import_zod4.z.coerce.date().optional(),
|
|
4745
5390
|
/** Parent delegation CID if this is a sub-delegation */
|
|
4746
|
-
parentCid:
|
|
5391
|
+
parentCid: import_zod4.z.string().optional(),
|
|
4747
5392
|
/** Whether sub-delegation is allowed */
|
|
4748
|
-
allowSubDelegation:
|
|
5393
|
+
allowSubDelegation: import_zod4.z.boolean().optional(),
|
|
4749
5394
|
/** Authorization header (UCAN bearer token) */
|
|
4750
|
-
authHeader:
|
|
5395
|
+
authHeader: import_zod4.z.string().optional()
|
|
4751
5396
|
});
|
|
4752
|
-
var DelegationStatusSchema =
|
|
4753
|
-
cid:
|
|
4754
|
-
status:
|
|
4755
|
-
exists:
|
|
4756
|
-
active:
|
|
4757
|
-
revoked:
|
|
4758
|
-
expired:
|
|
5397
|
+
var DelegationStatusSchema = import_zod4.z.object({
|
|
5398
|
+
cid: import_zod4.z.string().min(1),
|
|
5399
|
+
status: import_zod4.z.enum(["active", "revoked", "expired", "unavailable", "not_found"]),
|
|
5400
|
+
exists: import_zod4.z.boolean(),
|
|
5401
|
+
active: import_zod4.z.boolean(),
|
|
5402
|
+
revoked: import_zod4.z.boolean(),
|
|
5403
|
+
expired: import_zod4.z.boolean()
|
|
4759
5404
|
}).strict().superRefine((value, context) => {
|
|
4760
5405
|
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;
|
|
4761
5406
|
if (!valid) {
|
|
4762
5407
|
context.addIssue({
|
|
4763
|
-
code:
|
|
5408
|
+
code: import_zod4.z.ZodIssueCode.custom,
|
|
4764
5409
|
message: "delegation status flags do not match status"
|
|
4765
5410
|
});
|
|
4766
5411
|
}
|
|
4767
5412
|
});
|
|
4768
|
-
var DelegationRevocationReceiptSchema =
|
|
4769
|
-
revoked:
|
|
4770
|
-
cid:
|
|
5413
|
+
var DelegationRevocationReceiptSchema = import_zod4.z.object({
|
|
5414
|
+
revoked: import_zod4.z.literal(true),
|
|
5415
|
+
cid: import_zod4.z.string().min(1)
|
|
4771
5416
|
}).strict();
|
|
4772
|
-
var AccountDelegationResourceSchema =
|
|
4773
|
-
resource:
|
|
4774
|
-
actions:
|
|
4775
|
-
caveats:
|
|
5417
|
+
var AccountDelegationResourceSchema = import_zod4.z.object({
|
|
5418
|
+
resource: import_zod4.z.string().min(1),
|
|
5419
|
+
actions: import_zod4.z.array(import_zod4.z.string()),
|
|
5420
|
+
caveats: import_zod4.z.array(import_zod4.z.record(import_zod4.z.string(), import_zod4.z.unknown()))
|
|
4776
5421
|
}).strict();
|
|
4777
|
-
var AccountDelegationDateSchema =
|
|
4778
|
-
var AccountDelegationRecordSchema =
|
|
4779
|
-
cid:
|
|
4780
|
-
direction:
|
|
4781
|
-
delegatorDid:
|
|
4782
|
-
delegateDid:
|
|
4783
|
-
resources:
|
|
4784
|
-
parents:
|
|
5422
|
+
var AccountDelegationDateSchema = import_zod4.z.string().datetime({ offset: true }).transform((value) => new Date(value));
|
|
5423
|
+
var AccountDelegationRecordSchema = import_zod4.z.object({
|
|
5424
|
+
cid: import_zod4.z.string().min(1),
|
|
5425
|
+
direction: import_zod4.z.enum(["granted", "received"]),
|
|
5426
|
+
delegatorDid: import_zod4.z.string().min(1),
|
|
5427
|
+
delegateDid: import_zod4.z.string().min(1),
|
|
5428
|
+
resources: import_zod4.z.array(AccountDelegationResourceSchema),
|
|
5429
|
+
parents: import_zod4.z.array(import_zod4.z.string()),
|
|
4785
5430
|
issuedAt: AccountDelegationDateSchema.nullable(),
|
|
4786
5431
|
notBefore: AccountDelegationDateSchema.nullable(),
|
|
4787
5432
|
expiresAt: AccountDelegationDateSchema.nullable(),
|
|
4788
|
-
status:
|
|
5433
|
+
status: import_zod4.z.enum(["active", "pending", "expired", "revoked", "ancestor_revoked"]),
|
|
4789
5434
|
revokedAt: AccountDelegationDateSchema.nullable().optional(),
|
|
4790
|
-
revokedBy:
|
|
4791
|
-
revokedAncestorCid:
|
|
5435
|
+
revokedBy: import_zod4.z.string().optional(),
|
|
5436
|
+
revokedAncestorCid: import_zod4.z.string().optional()
|
|
4792
5437
|
}).strict();
|
|
4793
|
-
var AccountDelegationPageSchema =
|
|
4794
|
-
schemaVersion:
|
|
4795
|
-
items:
|
|
4796
|
-
nextCursor:
|
|
5438
|
+
var AccountDelegationPageSchema = import_zod4.z.object({
|
|
5439
|
+
schemaVersion: import_zod4.z.literal(2),
|
|
5440
|
+
items: import_zod4.z.array(AccountDelegationRecordSchema),
|
|
5441
|
+
nextCursor: import_zod4.z.string().optional()
|
|
4797
5442
|
}).strict();
|
|
4798
|
-
var AccountDelegationQueryOptionsSchema =
|
|
4799
|
-
direction:
|
|
4800
|
-
status:
|
|
4801
|
-
space:
|
|
4802
|
-
limit:
|
|
4803
|
-
cursor:
|
|
5443
|
+
var AccountDelegationQueryOptionsSchema = import_zod4.z.object({
|
|
5444
|
+
direction: import_zod4.z.enum(["granted", "received", "all"]).optional(),
|
|
5445
|
+
status: import_zod4.z.enum(["active", "pending", "expired", "revoked", "ancestor_revoked"]).optional(),
|
|
5446
|
+
space: import_zod4.z.string().trim().min(1).optional(),
|
|
5447
|
+
limit: import_zod4.z.number().int().min(1).max(100).optional(),
|
|
5448
|
+
cursor: import_zod4.z.string().min(1).optional()
|
|
4804
5449
|
}).strict();
|
|
4805
|
-
var CapabilityEntrySchema =
|
|
5450
|
+
var CapabilityEntrySchema = import_zod4.z.object({
|
|
4806
5451
|
/** Resource URI this capability applies to */
|
|
4807
|
-
resource:
|
|
5452
|
+
resource: import_zod4.z.string(),
|
|
4808
5453
|
/** Action this capability authorizes */
|
|
4809
|
-
action:
|
|
5454
|
+
action: import_zod4.z.string(),
|
|
4810
5455
|
/** Keys that can exercise this capability, ordered by priority */
|
|
4811
|
-
keys:
|
|
5456
|
+
keys: import_zod4.z.array(KeyInfoSchema),
|
|
4812
5457
|
/** The delegation that grants this capability */
|
|
4813
5458
|
delegation: DelegationSchema,
|
|
4814
5459
|
/** When this capability expires (accepts Date or ISO string from JSON) */
|
|
4815
|
-
expiresAt:
|
|
5460
|
+
expiresAt: import_zod4.z.coerce.date().optional()
|
|
4816
5461
|
});
|
|
4817
|
-
var DelegationRecordSchema =
|
|
5462
|
+
var DelegationRecordSchema = import_zod4.z.object({
|
|
4818
5463
|
/** Content identifier (CID) of the delegation */
|
|
4819
|
-
cid:
|
|
5464
|
+
cid: import_zod4.z.string(),
|
|
4820
5465
|
/** Space ID this delegation applies to */
|
|
4821
|
-
spaceId:
|
|
5466
|
+
spaceId: import_zod4.z.string(),
|
|
4822
5467
|
/** DID of the delegator (grantor) */
|
|
4823
|
-
delegator:
|
|
5468
|
+
delegator: import_zod4.z.string(),
|
|
4824
5469
|
/** DID of the delegatee (recipient) */
|
|
4825
|
-
delegatee:
|
|
5470
|
+
delegatee: import_zod4.z.string(),
|
|
4826
5471
|
/** Key ID used to sign/exercise this delegation */
|
|
4827
|
-
keyId:
|
|
5472
|
+
keyId: import_zod4.z.string().optional(),
|
|
4828
5473
|
/** Resource path pattern this delegation grants access to */
|
|
4829
|
-
path:
|
|
5474
|
+
path: import_zod4.z.string(),
|
|
4830
5475
|
/** Actions this delegation authorizes */
|
|
4831
|
-
actions:
|
|
5476
|
+
actions: import_zod4.z.array(import_zod4.z.string()),
|
|
4832
5477
|
/** When this delegation expires (accepts Date or ISO string from JSON) */
|
|
4833
|
-
expiry:
|
|
5478
|
+
expiry: import_zod4.z.coerce.date().optional(),
|
|
4834
5479
|
/** When this delegation becomes valid (not before) (accepts Date or ISO string) */
|
|
4835
|
-
notBefore:
|
|
5480
|
+
notBefore: import_zod4.z.coerce.date().optional(),
|
|
4836
5481
|
/** Whether this delegation has been revoked */
|
|
4837
|
-
isRevoked:
|
|
5482
|
+
isRevoked: import_zod4.z.boolean(),
|
|
4838
5483
|
/** When this delegation was created (accepts Date or ISO string from JSON) */
|
|
4839
|
-
createdAt:
|
|
5484
|
+
createdAt: import_zod4.z.coerce.date(),
|
|
4840
5485
|
/** Parent delegation CID if this is a sub-delegation */
|
|
4841
|
-
parentCid:
|
|
5486
|
+
parentCid: import_zod4.z.string().optional()
|
|
4842
5487
|
});
|
|
4843
|
-
var CreateDelegationParamsSchema =
|
|
5488
|
+
var CreateDelegationParamsSchema = import_zod4.z.object({
|
|
4844
5489
|
/** DID of the delegate (the party receiving the delegation) */
|
|
4845
|
-
delegateDID:
|
|
5490
|
+
delegateDID: import_zod4.z.string(),
|
|
4846
5491
|
/** Resource path this delegation grants access to */
|
|
4847
|
-
path:
|
|
5492
|
+
path: import_zod4.z.string(),
|
|
4848
5493
|
/** Actions to authorize */
|
|
4849
|
-
actions:
|
|
5494
|
+
actions: import_zod4.z.array(import_zod4.z.string()),
|
|
4850
5495
|
/** When this delegation expires (accepts Date or ISO string) */
|
|
4851
|
-
expiry:
|
|
5496
|
+
expiry: import_zod4.z.coerce.date().optional(),
|
|
4852
5497
|
/** Whether to disable sub-delegation */
|
|
4853
|
-
disableSubDelegation:
|
|
5498
|
+
disableSubDelegation: import_zod4.z.boolean().optional(),
|
|
4854
5499
|
/** Optional statement for the SIWE message */
|
|
4855
|
-
statement:
|
|
5500
|
+
statement: import_zod4.z.string().optional()
|
|
4856
5501
|
});
|
|
4857
|
-
var DelegationChainSchema =
|
|
4858
|
-
var DelegationChainV2Schema =
|
|
5502
|
+
var DelegationChainSchema = import_zod4.z.array(DelegationSchema);
|
|
5503
|
+
var DelegationChainV2Schema = import_zod4.z.object({
|
|
4859
5504
|
/** The root delegation from the original authority */
|
|
4860
5505
|
root: DelegationSchema,
|
|
4861
5506
|
/** Intermediate delegations in the chain (may be empty) */
|
|
4862
|
-
chain:
|
|
5507
|
+
chain: import_zod4.z.array(DelegationSchema),
|
|
4863
5508
|
/** The final delegation to the current user */
|
|
4864
5509
|
leaf: DelegationSchema
|
|
4865
5510
|
});
|
|
4866
|
-
var DelegationDirectionSchema =
|
|
4867
|
-
var DelegationFiltersSchema =
|
|
5511
|
+
var DelegationDirectionSchema = import_zod4.z.enum(["granted", "received", "all"]);
|
|
5512
|
+
var DelegationFiltersSchema = import_zod4.z.object({
|
|
4868
5513
|
/** Filter by delegation direction */
|
|
4869
5514
|
direction: DelegationDirectionSchema.optional(),
|
|
4870
5515
|
/** Filter by resource path pattern */
|
|
4871
|
-
path:
|
|
5516
|
+
path: import_zod4.z.string().optional(),
|
|
4872
5517
|
/** Filter by required actions */
|
|
4873
|
-
actions:
|
|
5518
|
+
actions: import_zod4.z.array(import_zod4.z.string()).optional(),
|
|
4874
5519
|
/** Include revoked delegations */
|
|
4875
|
-
includeRevoked:
|
|
5520
|
+
includeRevoked: import_zod4.z.boolean().optional(),
|
|
4876
5521
|
/** Filter by delegator DID */
|
|
4877
|
-
delegator:
|
|
5522
|
+
delegator: import_zod4.z.string().optional(),
|
|
4878
5523
|
/** Filter by delegatee DID */
|
|
4879
|
-
delegatee:
|
|
5524
|
+
delegatee: import_zod4.z.string().optional(),
|
|
4880
5525
|
/** Only include delegations valid at this time */
|
|
4881
|
-
validAt:
|
|
5526
|
+
validAt: import_zod4.z.coerce.date().optional(),
|
|
4882
5527
|
/** Maximum number of results to return */
|
|
4883
|
-
limit:
|
|
5528
|
+
limit: import_zod4.z.number().optional(),
|
|
4884
5529
|
/** Cursor for pagination */
|
|
4885
|
-
cursor:
|
|
5530
|
+
cursor: import_zod4.z.string().optional()
|
|
4886
5531
|
});
|
|
4887
|
-
var SpaceOwnershipSchema =
|
|
4888
|
-
var SpaceInfoSchema =
|
|
5532
|
+
var SpaceOwnershipSchema = import_zod4.z.enum(["owned", "delegated"]);
|
|
5533
|
+
var SpaceInfoSchema = import_zod4.z.object({
|
|
4889
5534
|
/** Space identifier */
|
|
4890
|
-
id:
|
|
5535
|
+
id: import_zod4.z.string(),
|
|
4891
5536
|
/** Human-readable name for the space */
|
|
4892
|
-
name:
|
|
5537
|
+
name: import_zod4.z.string().optional(),
|
|
4893
5538
|
/** DID of the space owner */
|
|
4894
|
-
owner:
|
|
5539
|
+
owner: import_zod4.z.string(),
|
|
4895
5540
|
/** Whether user owns or has delegated access */
|
|
4896
5541
|
type: SpaceOwnershipSchema,
|
|
4897
5542
|
/** Permissions the user has in this space */
|
|
4898
|
-
permissions:
|
|
5543
|
+
permissions: import_zod4.z.array(import_zod4.z.string()).optional(),
|
|
4899
5544
|
/** When the access expires (for delegated spaces) */
|
|
4900
|
-
expiresAt:
|
|
5545
|
+
expiresAt: import_zod4.z.coerce.date().optional()
|
|
4901
5546
|
});
|
|
4902
|
-
var ShareSchemaSchema =
|
|
4903
|
-
var ShareLinkSchema =
|
|
5547
|
+
var ShareSchemaSchema = import_zod4.z.enum(["base64", "compact", "ipfs"]);
|
|
5548
|
+
var ShareLinkSchema = import_zod4.z.object({
|
|
4904
5549
|
/** Unique token identifying this share link */
|
|
4905
|
-
token:
|
|
5550
|
+
token: import_zod4.z.string(),
|
|
4906
5551
|
/** Full URL for sharing */
|
|
4907
|
-
url:
|
|
5552
|
+
url: import_zod4.z.string(),
|
|
4908
5553
|
/** The delegation this link grants access to */
|
|
4909
5554
|
delegation: DelegationSchema,
|
|
4910
5555
|
/** Encoding schema used for the link */
|
|
4911
5556
|
schema: ShareSchemaSchema,
|
|
4912
5557
|
/** When this share link expires */
|
|
4913
|
-
expiresAt:
|
|
5558
|
+
expiresAt: import_zod4.z.coerce.date().optional(),
|
|
4914
5559
|
/** Human-readable description of what is being shared */
|
|
4915
|
-
description:
|
|
5560
|
+
description: import_zod4.z.string().optional()
|
|
4916
5561
|
});
|
|
4917
5562
|
function createShareLinkDataSchema(dataSchema) {
|
|
4918
|
-
return
|
|
5563
|
+
return import_zod4.z.object({
|
|
4919
5564
|
/** The retrieved data */
|
|
4920
5565
|
data: dataSchema,
|
|
4921
5566
|
/** The delegation that authorized this access */
|
|
4922
5567
|
delegation: DelegationSchema,
|
|
4923
5568
|
/** The space the data belongs to */
|
|
4924
|
-
spaceId:
|
|
5569
|
+
spaceId: import_zod4.z.string(),
|
|
4925
5570
|
/** The resource path that was accessed */
|
|
4926
|
-
path:
|
|
5571
|
+
path: import_zod4.z.string()
|
|
4927
5572
|
});
|
|
4928
5573
|
}
|
|
4929
|
-
var ShareLinkDataSchema = createShareLinkDataSchema(
|
|
4930
|
-
var IngestOptionsSchema =
|
|
5574
|
+
var ShareLinkDataSchema = createShareLinkDataSchema(import_zod4.z.unknown());
|
|
5575
|
+
var IngestOptionsSchema = import_zod4.z.object({
|
|
4931
5576
|
/** Whether to persist the delegation to storage */
|
|
4932
|
-
persist:
|
|
5577
|
+
persist: import_zod4.z.boolean().optional(),
|
|
4933
5578
|
/** Whether to validate the full delegation chain */
|
|
4934
|
-
validateChain:
|
|
5579
|
+
validateChain: import_zod4.z.boolean().optional(),
|
|
4935
5580
|
/** Name for the ingested key */
|
|
4936
|
-
keyName:
|
|
5581
|
+
keyName: import_zod4.z.string().optional(),
|
|
4937
5582
|
/** Whether to create a session key for this delegation */
|
|
4938
|
-
createSessionKey:
|
|
5583
|
+
createSessionKey: import_zod4.z.boolean().optional(),
|
|
4939
5584
|
/** Override the priority for the ingested key */
|
|
4940
|
-
priority:
|
|
5585
|
+
priority: import_zod4.z.number().optional()
|
|
4941
5586
|
});
|
|
4942
|
-
var GenerateShareParamsSchema =
|
|
5587
|
+
var GenerateShareParamsSchema = import_zod4.z.object({
|
|
4943
5588
|
/** Resource path to share */
|
|
4944
|
-
path:
|
|
5589
|
+
path: import_zod4.z.string(),
|
|
4945
5590
|
/** Actions to authorize */
|
|
4946
|
-
actions:
|
|
5591
|
+
actions: import_zod4.z.array(import_zod4.z.string()).optional(),
|
|
4947
5592
|
/** When the share link expires */
|
|
4948
|
-
expiry:
|
|
5593
|
+
expiry: import_zod4.z.coerce.date().optional(),
|
|
4949
5594
|
/** Encoding schema for the link */
|
|
4950
5595
|
schema: ShareSchemaSchema.optional(),
|
|
4951
5596
|
/** Human-readable description */
|
|
4952
|
-
description:
|
|
5597
|
+
description: import_zod4.z.string().optional(),
|
|
4953
5598
|
/** Base URL for the share link */
|
|
4954
|
-
baseUrl:
|
|
5599
|
+
baseUrl: import_zod4.z.string().optional()
|
|
4955
5600
|
});
|
|
4956
|
-
var DelegationManagerConfigSchema =
|
|
5601
|
+
var DelegationManagerConfigSchema = import_zod4.z.object({
|
|
4957
5602
|
/** TinyCloud host URLs */
|
|
4958
|
-
hosts:
|
|
5603
|
+
hosts: import_zod4.z.array(import_zod4.z.string()),
|
|
4959
5604
|
/** Account space used by account-wide delegation history queries */
|
|
4960
|
-
accountSpaceId:
|
|
5605
|
+
accountSpaceId: import_zod4.z.string().min(1).optional(),
|
|
4961
5606
|
/** Active session for authentication */
|
|
4962
|
-
session:
|
|
5607
|
+
session: import_zod4.z.unknown().refine(
|
|
4963
5608
|
(val) => val !== null && typeof val === "object",
|
|
4964
5609
|
{ message: "Expected a ServiceSession object" }
|
|
4965
5610
|
),
|
|
4966
5611
|
/** Platform-specific invoke function */
|
|
4967
|
-
invoke:
|
|
5612
|
+
invoke: import_zod4.z.unknown().refine(
|
|
4968
5613
|
(val) => typeof val === "function",
|
|
4969
5614
|
{ message: "Expected an invoke function" }
|
|
4970
5615
|
),
|
|
4971
5616
|
/** Platform-specific invoke function for raw resource URIs */
|
|
4972
|
-
invokeAny:
|
|
5617
|
+
invokeAny: import_zod4.z.unknown().refine(
|
|
4973
5618
|
(val) => val === void 0 || typeof val === "function",
|
|
4974
5619
|
{ message: "Expected an invokeAny function or undefined" }
|
|
4975
5620
|
).optional(),
|
|
4976
5621
|
/** Optional custom fetch implementation */
|
|
4977
|
-
fetch:
|
|
5622
|
+
fetch: import_zod4.z.unknown().refine(
|
|
4978
5623
|
(val) => val === void 0 || typeof val === "function",
|
|
4979
5624
|
{ message: "Expected a fetch function or undefined" }
|
|
4980
5625
|
).optional()
|
|
4981
5626
|
});
|
|
4982
|
-
var KeyProviderSchema =
|
|
5627
|
+
var KeyProviderSchema = import_zod4.z.object({
|
|
4983
5628
|
/** Generate a new session key, returns key ID */
|
|
4984
|
-
createSessionKey:
|
|
5629
|
+
createSessionKey: import_zod4.z.unknown().refine(
|
|
4985
5630
|
(val) => typeof val === "function",
|
|
4986
5631
|
{ message: "Expected a function" }
|
|
4987
5632
|
),
|
|
4988
5633
|
/** Get JWK for a key */
|
|
4989
|
-
getJWK:
|
|
5634
|
+
getJWK: import_zod4.z.unknown().refine(
|
|
4990
5635
|
(val) => typeof val === "function",
|
|
4991
5636
|
{ message: "Expected a function" }
|
|
4992
5637
|
),
|
|
4993
5638
|
/** Get DID for a key */
|
|
4994
|
-
getDID:
|
|
5639
|
+
getDID: import_zod4.z.unknown().refine(
|
|
4995
5640
|
(val) => typeof val === "function",
|
|
4996
5641
|
{ message: "Expected a function" }
|
|
4997
5642
|
)
|
|
4998
5643
|
});
|
|
4999
|
-
var DelegationApiResponseSchema =
|
|
5644
|
+
var DelegationApiResponseSchema = import_zod4.z.object({
|
|
5000
5645
|
/** SIWE message content */
|
|
5001
|
-
siwe:
|
|
5646
|
+
siwe: import_zod4.z.string(),
|
|
5002
5647
|
/** Signature of the SIWE message */
|
|
5003
|
-
signature:
|
|
5648
|
+
signature: import_zod4.z.string(),
|
|
5004
5649
|
/** Delegation version */
|
|
5005
|
-
version:
|
|
5650
|
+
version: import_zod4.z.number(),
|
|
5006
5651
|
/** CID of the created delegation */
|
|
5007
|
-
cid:
|
|
5652
|
+
cid: import_zod4.z.string().optional()
|
|
5008
5653
|
});
|
|
5009
|
-
var DelegatedResourceSchema =
|
|
5654
|
+
var DelegatedResourceSchema = import_zod4.z.object({
|
|
5010
5655
|
/** Short-form service name, e.g. "kv", "sql", "duckdb", "capabilities", "hooks". */
|
|
5011
|
-
service:
|
|
5656
|
+
service: import_zod4.z.string(),
|
|
5012
5657
|
/** Full space id string, e.g. "tinycloud:pkh:eip155:1:0x....:default". */
|
|
5013
|
-
space:
|
|
5658
|
+
space: import_zod4.z.string(),
|
|
5014
5659
|
/** Resource path; empty string when the resource URI had no path segment. */
|
|
5015
|
-
path:
|
|
5660
|
+
path: import_zod4.z.string(),
|
|
5016
5661
|
/** Full-URN ability strings, e.g. ["tinycloud.kv/get", "tinycloud.kv/put"]. */
|
|
5017
|
-
actions:
|
|
5662
|
+
actions: import_zod4.z.array(import_zod4.z.string()),
|
|
5018
5663
|
/** Exact ReCap caveats that constrain every action in this scope. */
|
|
5019
|
-
caveats:
|
|
5664
|
+
caveats: import_zod4.z.array(import_zod4.z.record(import_zod4.z.string(), import_zod4.z.unknown())).optional()
|
|
5020
5665
|
});
|
|
5021
|
-
var CreateDelegationWasmParamsSchema =
|
|
5666
|
+
var CreateDelegationWasmParamsSchema = import_zod4.z.object({
|
|
5022
5667
|
/** The session containing delegation credentials */
|
|
5023
|
-
session:
|
|
5668
|
+
session: import_zod4.z.unknown().refine(
|
|
5024
5669
|
(val) => val !== null && typeof val === "object",
|
|
5025
5670
|
{ message: "Expected a ServiceSession object" }
|
|
5026
5671
|
),
|
|
5027
5672
|
/** DID of the delegate */
|
|
5028
|
-
delegateDID:
|
|
5673
|
+
delegateDID: import_zod4.z.string(),
|
|
5029
5674
|
/** Space ID this delegation applies to */
|
|
5030
|
-
spaceId:
|
|
5675
|
+
spaceId: import_zod4.z.string(),
|
|
5031
5676
|
/**
|
|
5032
5677
|
* Multi-resource abilities map: short-service → path → full-URN actions.
|
|
5033
5678
|
* Matches the shape accepted by `prepareSession`.
|
|
@@ -5044,26 +5689,26 @@ var CreateDelegationWasmParamsSchema = import_zod3.z.object({
|
|
|
5044
5689
|
* }
|
|
5045
5690
|
* ```
|
|
5046
5691
|
*/
|
|
5047
|
-
abilities:
|
|
5692
|
+
abilities: import_zod4.z.record(import_zod4.z.string(), import_zod4.z.record(import_zod4.z.string(), import_zod4.z.array(import_zod4.z.string()))),
|
|
5048
5693
|
/** Expiration time in seconds since Unix epoch */
|
|
5049
|
-
expirationSecs:
|
|
5694
|
+
expirationSecs: import_zod4.z.number(),
|
|
5050
5695
|
/** Optional not-before time in seconds since Unix epoch */
|
|
5051
|
-
notBeforeSecs:
|
|
5696
|
+
notBeforeSecs: import_zod4.z.number().optional()
|
|
5052
5697
|
});
|
|
5053
|
-
var CreateDelegationWasmResultSchema =
|
|
5698
|
+
var CreateDelegationWasmResultSchema = import_zod4.z.object({
|
|
5054
5699
|
/** Base64url-encoded UCAN delegation */
|
|
5055
|
-
delegation:
|
|
5700
|
+
delegation: import_zod4.z.string(),
|
|
5056
5701
|
/** CID of the delegation */
|
|
5057
|
-
cid:
|
|
5702
|
+
cid: import_zod4.z.string(),
|
|
5058
5703
|
/** DID of the delegate */
|
|
5059
|
-
delegateDID:
|
|
5704
|
+
delegateDID: import_zod4.z.string(),
|
|
5060
5705
|
/** Expiration time */
|
|
5061
|
-
expiry:
|
|
5706
|
+
expiry: import_zod4.z.coerce.date(),
|
|
5062
5707
|
/**
|
|
5063
5708
|
* All (service, space, path, actions) entries granted by this delegation.
|
|
5064
5709
|
* Always non-empty on success.
|
|
5065
5710
|
*/
|
|
5066
|
-
resources:
|
|
5711
|
+
resources: import_zod4.z.array(DelegatedResourceSchema)
|
|
5067
5712
|
});
|
|
5068
5713
|
|
|
5069
5714
|
// src/expiry.ts
|
|
@@ -5758,66 +6403,66 @@ var DelegationManager = class {
|
|
|
5758
6403
|
};
|
|
5759
6404
|
|
|
5760
6405
|
// src/delegations/SharingService.schema.ts
|
|
5761
|
-
var
|
|
5762
|
-
var EncodedShareDataSchema =
|
|
6406
|
+
var import_zod5 = require("zod");
|
|
6407
|
+
var EncodedShareDataSchema = import_zod5.z.object({
|
|
5763
6408
|
/** Private key in JWK format (must include d parameter) */
|
|
5764
6409
|
key: JWKSchema.refine(
|
|
5765
6410
|
(jwk) => typeof jwk.d === "string" && jwk.d.length > 0,
|
|
5766
6411
|
{ message: "JWK must include private key (d parameter)" }
|
|
5767
6412
|
),
|
|
5768
6413
|
/** DID of the key */
|
|
5769
|
-
keyDid:
|
|
6414
|
+
keyDid: import_zod5.z.string().min(1, "keyDid is required"),
|
|
5770
6415
|
/** The delegation granting access */
|
|
5771
6416
|
delegation: DelegationSchema,
|
|
5772
6417
|
/** Resource path this link grants access to */
|
|
5773
|
-
path:
|
|
6418
|
+
path: import_zod5.z.string().min(1, "path is required"),
|
|
5774
6419
|
/** TinyCloud host URL */
|
|
5775
|
-
host:
|
|
6420
|
+
host: import_zod5.z.string().url("host must be a valid URL"),
|
|
5776
6421
|
/** Space ID */
|
|
5777
|
-
spaceId:
|
|
6422
|
+
spaceId: import_zod5.z.string().min(1, "spaceId is required"),
|
|
5778
6423
|
/** Schema version (must be 1) */
|
|
5779
|
-
version:
|
|
6424
|
+
version: import_zod5.z.literal(1)
|
|
5780
6425
|
});
|
|
5781
|
-
var ReceiveOptionsSchema =
|
|
6426
|
+
var ReceiveOptionsSchema = import_zod5.z.object({
|
|
5782
6427
|
/**
|
|
5783
6428
|
* Whether to automatically create a sub-delegation to the current session key.
|
|
5784
6429
|
* Default: true
|
|
5785
6430
|
*/
|
|
5786
|
-
autoSubdelegate:
|
|
6431
|
+
autoSubdelegate: import_zod5.z.boolean().optional(),
|
|
5787
6432
|
/**
|
|
5788
6433
|
* Whether to use the current session key for operations (requires autoSubdelegate).
|
|
5789
6434
|
* Default: true
|
|
5790
6435
|
*/
|
|
5791
|
-
useSessionKey:
|
|
6436
|
+
useSessionKey: import_zod5.z.boolean().optional(),
|
|
5792
6437
|
/**
|
|
5793
6438
|
* Ingestion options passed to CapabilityKeyRegistry.
|
|
5794
6439
|
*/
|
|
5795
6440
|
ingestOptions: IngestOptionsSchema.optional()
|
|
5796
6441
|
});
|
|
5797
|
-
var SharingServiceConfigSchema =
|
|
6442
|
+
var SharingServiceConfigSchema = import_zod5.z.object({
|
|
5798
6443
|
/** TinyCloud host URLs */
|
|
5799
|
-
hosts:
|
|
6444
|
+
hosts: import_zod5.z.array(import_zod5.z.string().url()).min(1, "At least one host URL is required"),
|
|
5800
6445
|
/**
|
|
5801
6446
|
* Active session for authentication.
|
|
5802
6447
|
* Required for generate(), optional for receive().
|
|
5803
6448
|
*/
|
|
5804
|
-
session:
|
|
6449
|
+
session: import_zod5.z.unknown().refine(
|
|
5805
6450
|
(val) => val === void 0 || val !== null && typeof val === "object",
|
|
5806
6451
|
{ message: "Expected a ServiceSession object or undefined" }
|
|
5807
6452
|
).optional(),
|
|
5808
6453
|
/** Platform-specific invoke function */
|
|
5809
|
-
invoke:
|
|
6454
|
+
invoke: import_zod5.z.unknown().refine((val) => typeof val === "function", {
|
|
5810
6455
|
message: "Expected an invoke function"
|
|
5811
6456
|
}),
|
|
5812
6457
|
/** Optional custom fetch implementation */
|
|
5813
|
-
fetch:
|
|
6458
|
+
fetch: import_zod5.z.unknown().refine(
|
|
5814
6459
|
(val) => val === void 0 || typeof val === "function",
|
|
5815
6460
|
{ message: "Expected a fetch function or undefined" }
|
|
5816
6461
|
).optional(),
|
|
5817
6462
|
/** Key provider for cryptographic operations */
|
|
5818
6463
|
keyProvider: KeyProviderSchema,
|
|
5819
6464
|
/** Capability key registry for key/delegation management */
|
|
5820
|
-
registry:
|
|
6465
|
+
registry: import_zod5.z.unknown().refine(
|
|
5821
6466
|
(val) => val !== null && typeof val === "object",
|
|
5822
6467
|
{ message: "Expected an ICapabilityKeyRegistry object" }
|
|
5823
6468
|
),
|
|
@@ -5825,47 +6470,47 @@ var SharingServiceConfigSchema = import_zod4.z.object({
|
|
|
5825
6470
|
* Delegation manager for creating delegations.
|
|
5826
6471
|
* Required for generate(), optional for receive().
|
|
5827
6472
|
*/
|
|
5828
|
-
delegationManager:
|
|
6473
|
+
delegationManager: import_zod5.z.unknown().refine(
|
|
5829
6474
|
(val) => val === void 0 || val !== null && typeof val === "object",
|
|
5830
6475
|
{ message: "Expected a DelegationManager object or undefined" }
|
|
5831
6476
|
).optional(),
|
|
5832
6477
|
/** Factory for creating KV service instances */
|
|
5833
|
-
createKVService:
|
|
6478
|
+
createKVService: import_zod5.z.unknown().refine(
|
|
5834
6479
|
(val) => typeof val === "function",
|
|
5835
6480
|
{ message: "Expected a createKVService factory function" }
|
|
5836
6481
|
),
|
|
5837
6482
|
/** Base URL for sharing links (e.g., "https://share.myapp.com") */
|
|
5838
|
-
baseUrl:
|
|
6483
|
+
baseUrl: import_zod5.z.string().optional(),
|
|
5839
6484
|
/**
|
|
5840
6485
|
* Custom delegation creation function.
|
|
5841
6486
|
*/
|
|
5842
|
-
createDelegation:
|
|
6487
|
+
createDelegation: import_zod5.z.unknown().refine((val) => val === void 0 || typeof val === "function", {
|
|
5843
6488
|
message: "Expected a createDelegation function or undefined"
|
|
5844
6489
|
}).optional(),
|
|
5845
6490
|
/**
|
|
5846
6491
|
* WASM function for client-side delegation creation.
|
|
5847
6492
|
*/
|
|
5848
|
-
createDelegationWasm:
|
|
6493
|
+
createDelegationWasm: import_zod5.z.unknown().refine((val) => val === void 0 || typeof val === "function", {
|
|
5849
6494
|
message: "Expected a createDelegationWasm function or undefined"
|
|
5850
6495
|
}).optional(),
|
|
5851
6496
|
/** CID computation used to verify transportable child delegations. */
|
|
5852
|
-
computeCid:
|
|
6497
|
+
computeCid: import_zod5.z.unknown().refine((val) => val === void 0 || typeof val === "function", {
|
|
5853
6498
|
message: "Expected a computeCid function or undefined"
|
|
5854
6499
|
}).optional(),
|
|
5855
6500
|
/**
|
|
5856
6501
|
* Path prefix for KV operations.
|
|
5857
6502
|
*/
|
|
5858
|
-
pathPrefix:
|
|
6503
|
+
pathPrefix: import_zod5.z.string().optional(),
|
|
5859
6504
|
/**
|
|
5860
6505
|
* Session expiry time.
|
|
5861
6506
|
*/
|
|
5862
|
-
sessionExpiry:
|
|
6507
|
+
sessionExpiry: import_zod5.z.date().optional(),
|
|
5863
6508
|
/**
|
|
5864
6509
|
* Callback to create a DIRECT delegation from wallet to share key.
|
|
5865
6510
|
* This is the preferred method for long-lived share links because it
|
|
5866
6511
|
* bypasses the session delegation chain entirely.
|
|
5867
6512
|
*/
|
|
5868
|
-
onRootDelegationNeeded:
|
|
6513
|
+
onRootDelegationNeeded: import_zod5.z.unknown().refine((val) => val === void 0 || typeof val === "function", {
|
|
5869
6514
|
message: "Expected an onRootDelegationNeeded function or undefined"
|
|
5870
6515
|
}).optional()
|
|
5871
6516
|
});
|
|
@@ -5887,6 +6532,7 @@ function validateEncodedShareData(data) {
|
|
|
5887
6532
|
|
|
5888
6533
|
// src/manifest.ts
|
|
5889
6534
|
var import_ms = __toESM(require("ms"), 1);
|
|
6535
|
+
var import_bootstrap2 = require("@tinycloud/bootstrap");
|
|
5890
6536
|
var import_sdk_services = require("@tinycloud/sdk-services");
|
|
5891
6537
|
var DEFAULT_KNOWLEDGE_ROOT = "knowledge/index.md";
|
|
5892
6538
|
var ManifestValidationError = class extends Error {
|
|
@@ -6545,30 +7191,6 @@ function withCapabilitiesReadForSpaces(resources) {
|
|
|
6545
7191
|
...[...spaces].map(capabilitiesReadPermission)
|
|
6546
7192
|
]);
|
|
6547
7193
|
}
|
|
6548
|
-
function accountRegistryPermissions() {
|
|
6549
|
-
return [
|
|
6550
|
-
...[ACCOUNT_REGISTRY_PATH, "spaces/"].map((path) => ({
|
|
6551
|
-
service: "tinycloud.kv",
|
|
6552
|
-
space: ACCOUNT_REGISTRY_SPACE,
|
|
6553
|
-
path,
|
|
6554
|
-
actions: ["tinycloud.kv/get", "tinycloud.kv/put", "tinycloud.kv/list"]
|
|
6555
|
-
})),
|
|
6556
|
-
{
|
|
6557
|
-
service: "tinycloud.delegation",
|
|
6558
|
-
space: ACCOUNT_REGISTRY_SPACE,
|
|
6559
|
-
path: "",
|
|
6560
|
-
actions: ["tinycloud.delegation/list"]
|
|
6561
|
-
}
|
|
6562
|
-
];
|
|
6563
|
-
}
|
|
6564
|
-
function accountRegistryIndexPermission() {
|
|
6565
|
-
return {
|
|
6566
|
-
service: "tinycloud.sql",
|
|
6567
|
-
space: ACCOUNT_REGISTRY_SPACE,
|
|
6568
|
-
path: "account",
|
|
6569
|
-
actions: ["tinycloud.sql/read", "tinycloud.sql/write", "tinycloud.sql/schema"]
|
|
6570
|
-
};
|
|
6571
|
-
}
|
|
6572
7194
|
function composeManifestRequest(inputs, options2 = {}) {
|
|
6573
7195
|
if (!Array.isArray(inputs) || inputs.length === 0) {
|
|
6574
7196
|
throw new ManifestValidationError(
|
|
@@ -6586,8 +7208,12 @@ function composeManifestRequest(inputs, options2 = {}) {
|
|
|
6586
7208
|
}))
|
|
6587
7209
|
);
|
|
6588
7210
|
if (includeAccountRegistryPermissions) {
|
|
6589
|
-
resources.push(
|
|
6590
|
-
|
|
7211
|
+
resources.push(
|
|
7212
|
+
...import_bootstrap2.ACCOUNT_MANIFEST_PERMISSIONS.map((resource) => ({
|
|
7213
|
+
...resource,
|
|
7214
|
+
actions: [...resource.actions]
|
|
7215
|
+
}))
|
|
7216
|
+
);
|
|
6591
7217
|
}
|
|
6592
7218
|
const resourcesWithImplicitCapabilities = withCapabilitiesReadForSpaces(resources);
|
|
6593
7219
|
const manifestsByAppId = /* @__PURE__ */ new Map();
|
|
@@ -6762,13 +7388,13 @@ function canonicalizeRecapCaveats(caveats) {
|
|
|
6762
7388
|
}
|
|
6763
7389
|
if (Array.isArray(value)) return `[${value.map(canonicalize).join(",")}]`;
|
|
6764
7390
|
if (typeof value === "object") {
|
|
6765
|
-
const
|
|
6766
|
-
const prototype = Object.getPrototypeOf(
|
|
7391
|
+
const object2 = value;
|
|
7392
|
+
const prototype = Object.getPrototypeOf(object2);
|
|
6767
7393
|
if (prototype !== Object.prototype && prototype !== null) {
|
|
6768
7394
|
throw new Error("ReCap caveats must contain only JSON values.");
|
|
6769
7395
|
}
|
|
6770
|
-
return `{${Object.keys(
|
|
6771
|
-
(key) => `${JSON.stringify(key)}:${canonicalize(
|
|
7396
|
+
return `{${Object.keys(object2).sort().map(
|
|
7397
|
+
(key) => `${JSON.stringify(key)}:${canonicalize(object2[key])}`
|
|
6772
7398
|
).join(",")}}`;
|
|
6773
7399
|
}
|
|
6774
7400
|
throw new Error("ReCap caveats must contain only JSON values.");
|
|
@@ -6840,17 +7466,17 @@ function parseRecapCapabilities(parseWasm, siwe) {
|
|
|
6840
7466
|
}
|
|
6841
7467
|
|
|
6842
7468
|
// src/delegations/SharingService.ts
|
|
6843
|
-
var
|
|
7469
|
+
var import_ed255195 = require("@noble/curves/ed25519");
|
|
6844
7470
|
|
|
6845
7471
|
// src/delegations/ShareRecipientClient.ts
|
|
6846
7472
|
var import_sdk_services2 = require("@tinycloud/sdk-services");
|
|
6847
|
-
var
|
|
6848
|
-
var
|
|
7473
|
+
var import_ed255194 = require("@noble/curves/ed25519");
|
|
7474
|
+
var import_sha2564 = require("@noble/hashes/sha256");
|
|
6849
7475
|
|
|
6850
7476
|
// src/delegations/share-envelope.ts
|
|
6851
|
-
var
|
|
6852
|
-
var
|
|
6853
|
-
var
|
|
7477
|
+
var import_ed255193 = require("@noble/curves/ed25519");
|
|
7478
|
+
var import_blake33 = require("@noble/hashes/blake3");
|
|
7479
|
+
var import_sha2562 = require("@noble/hashes/sha256");
|
|
6854
7480
|
var ENVELOPE_SCHEMA = "xyz.tinycloud.share/envelope";
|
|
6855
7481
|
var INLINE_PREFIX = "tc2:";
|
|
6856
7482
|
var RAW_CID_CODEC = 85;
|
|
@@ -6899,8 +7525,8 @@ function canonicalJson(value) {
|
|
|
6899
7525
|
}
|
|
6900
7526
|
if (Array.isArray(value)) return `[${value.map(canonicalJson).join(",")}]`;
|
|
6901
7527
|
if (typeof value === "object") {
|
|
6902
|
-
const
|
|
6903
|
-
return `{${Object.keys(
|
|
7528
|
+
const object2 = value;
|
|
7529
|
+
return `{${Object.keys(object2).sort().map((key) => `${JSON.stringify(key)}:${canonicalJson(object2[key])}`).join(",")}}`;
|
|
6904
7530
|
}
|
|
6905
7531
|
throw new ShareEnvelopeError("invalid-envelope", "unsupported JSON value");
|
|
6906
7532
|
}
|
|
@@ -7069,17 +7695,17 @@ function createSharePolicy(input) {
|
|
|
7069
7695
|
};
|
|
7070
7696
|
}
|
|
7071
7697
|
function contentDigest(bytes2) {
|
|
7072
|
-
return bytesToBase64Url((0,
|
|
7698
|
+
return bytesToBase64Url((0, import_sha2562.sha256)(bytes2));
|
|
7073
7699
|
}
|
|
7074
7700
|
function computeShareCid(bytes2) {
|
|
7075
|
-
const digest4 = create(BLAKE3_256_CODE, (0,
|
|
7701
|
+
const digest4 = create(BLAKE3_256_CODE, (0, import_blake33.blake3)(bytes2));
|
|
7076
7702
|
return CID.createV1(RAW_CID_CODEC, digest4).toString();
|
|
7077
7703
|
}
|
|
7078
7704
|
function verifyShareCid(cid2, bytes2) {
|
|
7079
7705
|
try {
|
|
7080
7706
|
const parsed = CID.parse(cid2);
|
|
7081
7707
|
if (parsed.toString() !== cid2 || parsed.multihash.code !== BLAKE3_256_CODE) return false;
|
|
7082
|
-
return parsed.equals(CID.createV1(parsed.code, create(parsed.multihash.code, (0,
|
|
7708
|
+
return parsed.equals(CID.createV1(parsed.code, create(parsed.multihash.code, (0, import_blake33.blake3)(bytes2))));
|
|
7083
7709
|
} catch {
|
|
7084
7710
|
return false;
|
|
7085
7711
|
}
|
|
@@ -7089,7 +7715,7 @@ function envelopeSigningBytes(envelope) {
|
|
|
7089
7715
|
}
|
|
7090
7716
|
function signShareEnvelope(input) {
|
|
7091
7717
|
if (input.signerPrivateKey.length !== 32) throw new ShareEnvelopeError("invalid-envelope", "Ed25519 private key must be 32 bytes");
|
|
7092
|
-
const publicKey =
|
|
7718
|
+
const publicKey = import_ed255193.ed25519.getPublicKey(input.signerPrivateKey);
|
|
7093
7719
|
const unsigned = {
|
|
7094
7720
|
schema: ENVELOPE_SCHEMA,
|
|
7095
7721
|
version: 2,
|
|
@@ -7104,7 +7730,7 @@ function signShareEnvelope(input) {
|
|
|
7104
7730
|
expiresAt: new Date(input.expiresAt).toISOString(),
|
|
7105
7731
|
signer: { did: input.signerDid, publicKey: bytesToBase64Url(publicKey) }
|
|
7106
7732
|
};
|
|
7107
|
-
return { ...unsigned, signature: bytesToBase64Url(
|
|
7733
|
+
return { ...unsigned, signature: bytesToBase64Url(import_ed255193.ed25519.sign(envelopeSigningBytes(unsigned), input.signerPrivateKey)) };
|
|
7108
7734
|
}
|
|
7109
7735
|
function verifyShareEnvelope(envelope, options2 = {}) {
|
|
7110
7736
|
try {
|
|
@@ -7136,7 +7762,7 @@ function verifyShareEnvelope(envelope, options2 = {}) {
|
|
|
7136
7762
|
const signature = base64UrlToBytes(envelope.signature);
|
|
7137
7763
|
const unsigned = { ...envelope };
|
|
7138
7764
|
delete unsigned.signature;
|
|
7139
|
-
if (publicKey.length !== 32 || signature.length !== 64 || !
|
|
7765
|
+
if (publicKey.length !== 32 || signature.length !== 64 || !import_ed255193.ed25519.verify(signature, envelopeSigningBytes(unsigned), publicKey)) throw new ShareEnvelopeError("signature-invalid", "share envelope signature is invalid");
|
|
7140
7766
|
if (options2.trustedSignerDids !== void 0 && envelope.recipientKind !== void 0 && !options2.trustedSignerDids.includes(envelope.signer.did)) throw new ShareEnvelopeError("signature-invalid", "share signer is not trusted");
|
|
7141
7767
|
return envelope;
|
|
7142
7768
|
} catch (error) {
|
|
@@ -7184,7 +7810,7 @@ function encodeInlineShareUrl(input) {
|
|
|
7184
7810
|
}
|
|
7185
7811
|
var PUBLISHED_AAD = new TextEncoder().encode("tinycloud-share-envelope-v1");
|
|
7186
7812
|
function publishedCid(bytes2) {
|
|
7187
|
-
return CID.create(1, code, create(sha2562.code, (0,
|
|
7813
|
+
return CID.create(1, code, create(sha2562.code, (0, import_sha2562.sha256)(bytes2))).toString();
|
|
7188
7814
|
}
|
|
7189
7815
|
function isPublishedCid(value) {
|
|
7190
7816
|
try {
|
|
@@ -7224,7 +7850,7 @@ function publishedArtifact(envelope, plaintext, policy) {
|
|
|
7224
7850
|
content: {
|
|
7225
7851
|
mimeType: "application/octet-stream",
|
|
7226
7852
|
size: plaintext.byteLength,
|
|
7227
|
-
digest: bytesToBase64Url((0,
|
|
7853
|
+
digest: bytesToBase64Url((0, import_sha2562.sha256)(plaintext))
|
|
7228
7854
|
},
|
|
7229
7855
|
// Addressed policy metadata is confidential even though this function
|
|
7230
7856
|
// is called after the outer envelope has been opened. Keep the
|
|
@@ -7328,9 +7954,9 @@ function parsePolicyMetadata(policyBytes, target, expectedExpiry) {
|
|
|
7328
7954
|
assertKeys(source, ["kind", "space", "database", "path", "statement", "arguments", "argumentsDigest", "action"], "published SQL content source");
|
|
7329
7955
|
if (typeof source.space !== "string" || typeof source.database !== "string" || typeof source.path !== "string" || typeof source.statement !== "string" || !source.arguments || typeof source.arguments !== "object" || Array.isArray(source.arguments) || typeof source.argumentsDigest !== "string" || source.action !== "tinycloud.sql/read") throw new ShareEnvelopeError("invalid-envelope", "published SQL content source is invalid");
|
|
7330
7956
|
for (const argument of Object.values(source.arguments)) if (!Number.isSafeInteger(argument)) throw new ShareEnvelopeError("invalid-envelope", "published SQL arguments are invalid");
|
|
7331
|
-
if (bytesToBase64Url((0,
|
|
7957
|
+
if (bytesToBase64Url((0, import_sha2562.sha256)(new TextEncoder().encode(canonicalJson(source.arguments)))) !== source.argumentsDigest) throw new ShareEnvelopeError("invalid-envelope", "published SQL argument digest is invalid");
|
|
7332
7958
|
} else throw new ShareEnvelopeError("invalid-envelope", "policy content source kind is invalid");
|
|
7333
|
-
if (typeof policy.contentSourceDigest !== "string" || bytesToBase64Url((0,
|
|
7959
|
+
if (typeof policy.contentSourceDigest !== "string" || bytesToBase64Url((0, import_sha2562.sha256)(new TextEncoder().encode(canonicalJson(source)))) !== policy.contentSourceDigest) throw new ShareEnvelopeError("invalid-envelope", "policy content source digest is invalid");
|
|
7334
7960
|
return { recipientKind, actions, resource };
|
|
7335
7961
|
}
|
|
7336
7962
|
function parseCanonicalPublishedV2(value, options2) {
|
|
@@ -7378,7 +8004,7 @@ function parseCanonicalPublishedV2(value, options2) {
|
|
|
7378
8004
|
const signingBytes = new Uint8Array(domain.length + body.length);
|
|
7379
8005
|
signingBytes.set(domain);
|
|
7380
8006
|
signingBytes.set(body, domain.length);
|
|
7381
|
-
if (signatureBytes.length !== 64 || !
|
|
8007
|
+
if (signatureBytes.length !== 64 || !import_ed255193.ed25519.verify(signatureBytes, signingBytes, signerKey)) throw new ShareEnvelopeError("signature-invalid", "published v2 envelope signature is invalid");
|
|
7382
8008
|
const content = options2.plaintext ?? new Uint8Array();
|
|
7383
8009
|
const normalized = {
|
|
7384
8010
|
schema: ENVELOPE_SCHEMA,
|
|
@@ -7388,7 +8014,7 @@ function parseCanonicalPublishedV2(value, options2) {
|
|
|
7388
8014
|
recipientKind: normalizedMatcher.kind,
|
|
7389
8015
|
resource,
|
|
7390
8016
|
actions,
|
|
7391
|
-
content: { mimeType: typeof contentSource.mimeType === "string" ? contentSource.mimeType : "application/octet-stream", size: content.byteLength, digest: bytesToBase64Url((0,
|
|
8017
|
+
content: { mimeType: typeof contentSource.mimeType === "string" ? contentSource.mimeType : "application/octet-stream", size: content.byteLength, digest: bytesToBase64Url((0, import_sha2562.sha256)(content)) },
|
|
7392
8018
|
encrypted: true,
|
|
7393
8019
|
expiresAt: value.expiry,
|
|
7394
8020
|
signer: { did: signature.signerDid, publicKey: bytesToBase64Url(signerKey) },
|
|
@@ -7487,7 +8113,7 @@ function parsePublishedShareEnvelope(bytes2, options2 = {}) {
|
|
|
7487
8113
|
if (envelope.authorizationTarget.kind !== "bearerKey" && (options2.trustedSignerDids === void 0 || !options2.trustedSignerDids.includes(envelope.signature.signerDid))) throw new ShareEnvelopeError("signature-invalid", "a trusted authority is required for addressed shares");
|
|
7488
8114
|
const signature = base64UrlToBytes(envelope.signature.value);
|
|
7489
8115
|
const publicKey = publishedPublicKey(envelope.signature.signerDid);
|
|
7490
|
-
if (signature.length !== 64 || !
|
|
8116
|
+
if (signature.length !== 64 || !import_ed255193.ed25519.verify(signature, publishedEnvelopeSigningBytes(envelope), publicKey)) throw new ShareEnvelopeError("signature-invalid", "published envelope signature is invalid");
|
|
7491
8117
|
return { envelope, artifact: publishedArtifact(envelope, options2.plaintext ?? new Uint8Array(), policy) };
|
|
7492
8118
|
}
|
|
7493
8119
|
function parseLegacyPublishedShareEnvelope(bytes2, options2 = {}) {
|
|
@@ -7526,7 +8152,7 @@ function parseLegacyPublishedShareEnvelope(bytes2, options2 = {}) {
|
|
|
7526
8152
|
const signingBytes = new Uint8Array(domain.length + body.length);
|
|
7527
8153
|
signingBytes.set(domain);
|
|
7528
8154
|
signingBytes.set(body, domain.length);
|
|
7529
|
-
if (signatureBytes.length !== 64 || !
|
|
8155
|
+
if (signatureBytes.length !== 64 || !import_ed255193.ed25519.verify(signatureBytes, signingBytes, signerKey)) throw new ShareEnvelopeError("signature-invalid", "published v1 envelope signature is invalid");
|
|
7530
8156
|
const content = options2.plaintext ?? new Uint8Array();
|
|
7531
8157
|
const artifact = {
|
|
7532
8158
|
envelope: {
|
|
@@ -7537,7 +8163,7 @@ function parseLegacyPublishedShareEnvelope(bytes2, options2 = {}) {
|
|
|
7537
8163
|
resource: { kind: resource.kind, path: resource.path },
|
|
7538
8164
|
recipientKind: authorizationTarget.kind === "bearer" ? "bearer" : authorizationTarget.kind === "exact-email" ? "exactEmail" : authorizationTarget.kind === "email-domain" ? "emailDomain" : void 0,
|
|
7539
8165
|
actions: ["read"],
|
|
7540
|
-
content: { mimeType: "application/octet-stream", size: content.byteLength, digest: bytesToBase64Url((0,
|
|
8166
|
+
content: { mimeType: "application/octet-stream", size: content.byteLength, digest: bytesToBase64Url((0, import_sha2562.sha256)(content)) },
|
|
7541
8167
|
encrypted: true,
|
|
7542
8168
|
expiresAt: envelope.expiry,
|
|
7543
8169
|
signer: { did: signature.signerDid, publicKey: bytesToBase64Url(signerKey) },
|
|
@@ -7724,15 +8350,15 @@ function shareCapabilityAllows(capability, action, path) {
|
|
|
7724
8350
|
}
|
|
7725
8351
|
|
|
7726
8352
|
// src/delegations/ShareCache.ts
|
|
7727
|
-
var
|
|
8353
|
+
var import_sha2563 = require("@noble/hashes/sha256");
|
|
7728
8354
|
function cacheKey(key) {
|
|
7729
8355
|
if (!key.cid || !key.expiresAt) throw new Error("share cache keys require CID and expiry");
|
|
7730
8356
|
return `${key.cid}\0${key.expiresAt}`;
|
|
7731
8357
|
}
|
|
7732
8358
|
function digest2(bytes2) {
|
|
7733
|
-
return (0,
|
|
8359
|
+
return (0, import_sha2563.sha256)(bytes2);
|
|
7734
8360
|
}
|
|
7735
|
-
function
|
|
8361
|
+
function equalBytes2(left, right) {
|
|
7736
8362
|
if (left.byteLength !== right.byteLength) return false;
|
|
7737
8363
|
return left.every((byte, index) => byte === right[index]);
|
|
7738
8364
|
}
|
|
@@ -7745,7 +8371,7 @@ var MemoryShareCache = class {
|
|
|
7745
8371
|
const mapKey = cacheKey(key);
|
|
7746
8372
|
const entry = this.entries.get(mapKey);
|
|
7747
8373
|
if (entry === void 0) return void 0;
|
|
7748
|
-
if (Date.parse(entry.key.expiresAt) <= now.getTime() || !
|
|
8374
|
+
if (Date.parse(entry.key.expiresAt) <= now.getTime() || !equalBytes2(entry.digest, digest2(entry.bytes))) {
|
|
7749
8375
|
this.entries.delete(mapKey);
|
|
7750
8376
|
return void 0;
|
|
7751
8377
|
}
|
|
@@ -7754,7 +8380,7 @@ var MemoryShareCache = class {
|
|
|
7754
8380
|
async getByCid(cid2, now = /* @__PURE__ */ new Date()) {
|
|
7755
8381
|
const entries = [...this.entries.values()].filter((entry) => entry.key.cid === cid2);
|
|
7756
8382
|
for (const entry of entries) {
|
|
7757
|
-
if (Date.parse(entry.key.expiresAt) <= now.getTime() || !
|
|
8383
|
+
if (Date.parse(entry.key.expiresAt) <= now.getTime() || !equalBytes2(entry.digest, digest2(entry.bytes))) {
|
|
7758
8384
|
this.entries.delete(cacheKey(entry.key));
|
|
7759
8385
|
continue;
|
|
7760
8386
|
}
|
|
@@ -7804,138 +8430,234 @@ var ShareAccessError = class extends Error {
|
|
|
7804
8430
|
};
|
|
7805
8431
|
|
|
7806
8432
|
// src/delegations/recipient-types.schema.ts
|
|
7807
|
-
var
|
|
7808
|
-
var ShareRecipientTargetSchema =
|
|
7809
|
-
|
|
7810
|
-
|
|
7811
|
-
|
|
7812
|
-
|
|
8433
|
+
var import_zod6 = require("zod");
|
|
8434
|
+
var ShareRecipientTargetSchema = import_zod6.z.discriminatedUnion("kind", [
|
|
8435
|
+
import_zod6.z.object({ kind: import_zod6.z.literal("exactEmail"), value: import_zod6.z.string().min(1) }).strict(),
|
|
8436
|
+
import_zod6.z.object({ kind: import_zod6.z.literal("emailDomain"), value: import_zod6.z.string().min(1) }).strict(),
|
|
8437
|
+
import_zod6.z.object({ kind: import_zod6.z.literal("recipientDid"), value: import_zod6.z.string().regex(/^did:[a-z0-9]+:.+$/) }).strict(),
|
|
8438
|
+
import_zod6.z.object({ kind: import_zod6.z.literal("bearer") }).strict()
|
|
7813
8439
|
]);
|
|
7814
|
-
var ShareResourceSchema =
|
|
7815
|
-
|
|
7816
|
-
|
|
8440
|
+
var ShareResourceSchema = import_zod6.z.discriminatedUnion("kind", [
|
|
8441
|
+
import_zod6.z.object({ kind: import_zod6.z.literal("exact"), path: import_zod6.z.string().min(1) }).strict(),
|
|
8442
|
+
import_zod6.z.object({ kind: import_zod6.z.literal("prefix"), path: import_zod6.z.string().min(1) }).strict()
|
|
7817
8443
|
]);
|
|
7818
|
-
var ShareActionSchema =
|
|
7819
|
-
var ShareRecipientPolicySchema =
|
|
8444
|
+
var ShareActionSchema = import_zod6.z.enum(["read", "list", "edit"]);
|
|
8445
|
+
var ShareRecipientPolicySchema = import_zod6.z.object({
|
|
7820
8446
|
recipientMatcher: ShareRecipientTargetSchema,
|
|
7821
|
-
spaceId:
|
|
8447
|
+
spaceId: import_zod6.z.string().min(1),
|
|
7822
8448
|
resource: ShareResourceSchema,
|
|
7823
|
-
actions:
|
|
7824
|
-
expiresAt:
|
|
8449
|
+
actions: import_zod6.z.array(ShareActionSchema).min(1),
|
|
8450
|
+
expiresAt: import_zod6.z.date()
|
|
7825
8451
|
}).strict();
|
|
7826
|
-
var ShareRecipientClientOptionsSchema =
|
|
7827
|
-
trustedOrigins:
|
|
7828
|
-
maxInlineBytes:
|
|
7829
|
-
maxArtifactBytes:
|
|
7830
|
-
maxContentBytes:
|
|
7831
|
-
maxSealedContentBytes:
|
|
8452
|
+
var ShareRecipientClientOptionsSchema = import_zod6.z.object({
|
|
8453
|
+
trustedOrigins: import_zod6.z.array(import_zod6.z.string().url()).min(1),
|
|
8454
|
+
maxInlineBytes: import_zod6.z.number().int().positive().optional(),
|
|
8455
|
+
maxArtifactBytes: import_zod6.z.number().int().positive().optional(),
|
|
8456
|
+
maxContentBytes: import_zod6.z.number().int().positive().optional(),
|
|
8457
|
+
maxSealedContentBytes: import_zod6.z.number().int().positive().optional()
|
|
7832
8458
|
}).strict();
|
|
7833
|
-
var ShareNativeActionSchema =
|
|
7834
|
-
var ShareWireActionSchema =
|
|
7835
|
-
var ShareContentSourceSchema =
|
|
7836
|
-
|
|
7837
|
-
kind:
|
|
8459
|
+
var ShareNativeActionSchema = import_zod6.z.enum(["tinycloud.kv/get", "tinycloud.kv/metadata", "tinycloud.kv/list", "tinycloud.kv/put"]);
|
|
8460
|
+
var ShareWireActionSchema = import_zod6.z.enum(["tinycloud.kv/get", "tinycloud.kv/metadata", "tinycloud.kv/list", "tinycloud.kv/put", "tinycloud.sql/read"]);
|
|
8461
|
+
var ShareContentSourceSchema = import_zod6.z.discriminatedUnion("kind", [
|
|
8462
|
+
import_zod6.z.object({
|
|
8463
|
+
kind: import_zod6.z.literal("kv"),
|
|
7838
8464
|
action: ShareNativeActionSchema,
|
|
7839
|
-
space:
|
|
7840
|
-
path:
|
|
8465
|
+
space: import_zod6.z.string().min(1),
|
|
8466
|
+
path: import_zod6.z.string().min(1)
|
|
7841
8467
|
}).strict(),
|
|
7842
|
-
|
|
7843
|
-
kind:
|
|
7844
|
-
action:
|
|
7845
|
-
space:
|
|
7846
|
-
database:
|
|
7847
|
-
path:
|
|
7848
|
-
statement:
|
|
7849
|
-
arguments:
|
|
7850
|
-
argumentsDigest:
|
|
8468
|
+
import_zod6.z.object({
|
|
8469
|
+
kind: import_zod6.z.literal("sql"),
|
|
8470
|
+
action: import_zod6.z.literal("tinycloud.sql/read"),
|
|
8471
|
+
space: import_zod6.z.string().min(1),
|
|
8472
|
+
database: import_zod6.z.string().min(1),
|
|
8473
|
+
path: import_zod6.z.string().min(1),
|
|
8474
|
+
statement: import_zod6.z.string().min(1),
|
|
8475
|
+
arguments: import_zod6.z.record(import_zod6.z.number().int().safe()),
|
|
8476
|
+
argumentsDigest: import_zod6.z.string().min(1)
|
|
7851
8477
|
}).strict()
|
|
7852
8478
|
]);
|
|
7853
|
-
var ShareAddressedRecipientSchema =
|
|
7854
|
-
|
|
7855
|
-
|
|
7856
|
-
|
|
8479
|
+
var ShareAddressedRecipientSchema = import_zod6.z.discriminatedUnion("kind", [
|
|
8480
|
+
import_zod6.z.object({ kind: import_zod6.z.literal("exactEmail"), value: import_zod6.z.string().min(1) }).strict(),
|
|
8481
|
+
import_zod6.z.object({ kind: import_zod6.z.literal("emailDomain"), value: import_zod6.z.string().min(1) }).strict(),
|
|
8482
|
+
import_zod6.z.object({ kind: import_zod6.z.literal("recipientDid"), value: import_zod6.z.string().regex(/^did:[a-z0-9]+:.+$/) }).strict()
|
|
7857
8483
|
]);
|
|
7858
|
-
var ShareAddressedDelegationRequestV2Schema =
|
|
7859
|
-
version:
|
|
7860
|
-
nonce:
|
|
7861
|
-
jti:
|
|
7862
|
-
senderDid:
|
|
8484
|
+
var ShareAddressedDelegationRequestV2Schema = import_zod6.z.object({
|
|
8485
|
+
version: import_zod6.z.literal(2),
|
|
8486
|
+
nonce: import_zod6.z.string().min(1),
|
|
8487
|
+
jti: import_zod6.z.string().min(1),
|
|
8488
|
+
senderDid: import_zod6.z.string().min(1),
|
|
7863
8489
|
recipientMatcher: ShareAddressedRecipientSchema,
|
|
7864
|
-
targetOrigin:
|
|
7865
|
-
nodeAudience:
|
|
7866
|
-
shareCid:
|
|
7867
|
-
shareId:
|
|
7868
|
-
delegationCid:
|
|
7869
|
-
authorityMaterialHandle:
|
|
7870
|
-
authorityMaterialDigest:
|
|
8490
|
+
targetOrigin: import_zod6.z.string().url(),
|
|
8491
|
+
nodeAudience: import_zod6.z.string().min(1),
|
|
8492
|
+
shareCid: import_zod6.z.string().min(1),
|
|
8493
|
+
shareId: import_zod6.z.string().min(1),
|
|
8494
|
+
delegationCid: import_zod6.z.string().min(1),
|
|
8495
|
+
authorityMaterialHandle: import_zod6.z.string().min(1),
|
|
8496
|
+
authorityMaterialDigest: import_zod6.z.string().min(1),
|
|
7871
8497
|
contentSource: ShareContentSourceSchema,
|
|
7872
|
-
contentSourceDigest:
|
|
7873
|
-
actions:
|
|
7874
|
-
resource:
|
|
7875
|
-
expiresAt:
|
|
7876
|
-
requestBodyDigest:
|
|
8498
|
+
contentSourceDigest: import_zod6.z.string().min(1),
|
|
8499
|
+
actions: import_zod6.z.array(ShareWireActionSchema).min(1).refine((actions) => new Set(actions).size === actions.length),
|
|
8500
|
+
resource: import_zod6.z.object({ kind: import_zod6.z.enum(["exact", "prefix"]), value: import_zod6.z.string().min(1) }).strict(),
|
|
8501
|
+
expiresAt: import_zod6.z.string().datetime({ offset: true }),
|
|
8502
|
+
requestBodyDigest: import_zod6.z.string().min(1)
|
|
7877
8503
|
}).strict();
|
|
7878
|
-
var ShareAddressedDelegationEnvelopeV2Schema =
|
|
8504
|
+
var ShareAddressedDelegationEnvelopeV2Schema = import_zod6.z.object({
|
|
7879
8505
|
request: ShareAddressedDelegationRequestV2Schema,
|
|
7880
|
-
proof:
|
|
8506
|
+
proof: import_zod6.z.object({ alg: import_zod6.z.literal("EdDSA"), kid: import_zod6.z.string().min(1), signature: import_zod6.z.string().min(1) }).strict()
|
|
7881
8507
|
}).strict();
|
|
7882
|
-
var ShareAddressedDelegationResponseV2Schema =
|
|
7883
|
-
type:
|
|
7884
|
-
version:
|
|
7885
|
-
nonce:
|
|
7886
|
-
jti:
|
|
7887
|
-
policyCid:
|
|
7888
|
-
policyBytes:
|
|
7889
|
-
policyDigest:
|
|
7890
|
-
delegationCid:
|
|
7891
|
-
delegationBytes:
|
|
7892
|
-
delegationDigest:
|
|
7893
|
-
authorityMaterialHandle:
|
|
7894
|
-
authorityMaterialDigest:
|
|
7895
|
-
actions:
|
|
7896
|
-
resource:
|
|
7897
|
-
expiresAt:
|
|
7898
|
-
proof:
|
|
8508
|
+
var ShareAddressedDelegationResponseV2Schema = import_zod6.z.object({
|
|
8509
|
+
type: import_zod6.z.literal("TinyCloudShareAddressedDelegation"),
|
|
8510
|
+
version: import_zod6.z.literal(2),
|
|
8511
|
+
nonce: import_zod6.z.string().min(1),
|
|
8512
|
+
jti: import_zod6.z.string().min(1),
|
|
8513
|
+
policyCid: import_zod6.z.string().min(1),
|
|
8514
|
+
policyBytes: import_zod6.z.string().min(1),
|
|
8515
|
+
policyDigest: import_zod6.z.string().min(1),
|
|
8516
|
+
delegationCid: import_zod6.z.string().min(1),
|
|
8517
|
+
delegationBytes: import_zod6.z.string().min(1),
|
|
8518
|
+
delegationDigest: import_zod6.z.string().min(1),
|
|
8519
|
+
authorityMaterialHandle: import_zod6.z.string().min(1),
|
|
8520
|
+
authorityMaterialDigest: import_zod6.z.string().min(1),
|
|
8521
|
+
actions: import_zod6.z.array(ShareWireActionSchema).min(1).refine((actions) => new Set(actions).size === actions.length),
|
|
8522
|
+
resource: import_zod6.z.object({ kind: import_zod6.z.enum(["exact", "prefix"]), value: import_zod6.z.string().min(1) }).strict(),
|
|
8523
|
+
expiresAt: import_zod6.z.string().datetime({ offset: true }),
|
|
8524
|
+
proof: import_zod6.z.object({ alg: import_zod6.z.literal("EdDSA"), kid: import_zod6.z.string().min(1), signature: import_zod6.z.string().min(1) }).strict()
|
|
7899
8525
|
}).strict();
|
|
7900
|
-
var ShareNativeResponseEntrySchema =
|
|
7901
|
-
path:
|
|
7902
|
-
kind:
|
|
8526
|
+
var ShareNativeResponseEntrySchema = import_zod6.z.object({
|
|
8527
|
+
path: import_zod6.z.string().min(1),
|
|
8528
|
+
kind: import_zod6.z.enum(["file", "folder"])
|
|
7903
8529
|
}).strict();
|
|
7904
8530
|
var ShareNativeResponseBase = {
|
|
7905
|
-
type:
|
|
7906
|
-
version:
|
|
7907
|
-
resource:
|
|
8531
|
+
type: import_zod6.z.literal("TinyCloudShareInvokeResponse"),
|
|
8532
|
+
version: import_zod6.z.literal(2),
|
|
8533
|
+
resource: import_zod6.z.string().min(1)
|
|
7908
8534
|
};
|
|
7909
|
-
var ShareNativeResponseSchema =
|
|
7910
|
-
|
|
8535
|
+
var ShareNativeResponseSchema = import_zod6.z.discriminatedUnion("action", [
|
|
8536
|
+
import_zod6.z.object({
|
|
7911
8537
|
...ShareNativeResponseBase,
|
|
7912
|
-
action:
|
|
7913
|
-
metadata:
|
|
7914
|
-
etag:
|
|
8538
|
+
action: import_zod6.z.literal("tinycloud.kv/metadata"),
|
|
8539
|
+
metadata: import_zod6.z.record(import_zod6.z.string()),
|
|
8540
|
+
etag: import_zod6.z.string().min(1).nullable()
|
|
7915
8541
|
}).strict(),
|
|
7916
|
-
|
|
8542
|
+
import_zod6.z.object({
|
|
7917
8543
|
...ShareNativeResponseBase,
|
|
7918
|
-
action:
|
|
7919
|
-
mediaType:
|
|
7920
|
-
content:
|
|
7921
|
-
bodyDigest:
|
|
7922
|
-
etag:
|
|
8544
|
+
action: import_zod6.z.literal("tinycloud.kv/get"),
|
|
8545
|
+
mediaType: import_zod6.z.string().min(1),
|
|
8546
|
+
content: import_zod6.z.string(),
|
|
8547
|
+
bodyDigest: import_zod6.z.string().min(1),
|
|
8548
|
+
etag: import_zod6.z.string().min(1).nullable()
|
|
7923
8549
|
}).strict(),
|
|
7924
|
-
|
|
8550
|
+
import_zod6.z.object({
|
|
7925
8551
|
...ShareNativeResponseBase,
|
|
7926
|
-
action:
|
|
7927
|
-
entries:
|
|
7928
|
-
nextCursor:
|
|
8552
|
+
action: import_zod6.z.literal("tinycloud.kv/list"),
|
|
8553
|
+
entries: import_zod6.z.array(ShareNativeResponseEntrySchema),
|
|
8554
|
+
nextCursor: import_zod6.z.string().min(1).nullable()
|
|
7929
8555
|
}).strict(),
|
|
7930
|
-
|
|
8556
|
+
import_zod6.z.object({
|
|
7931
8557
|
...ShareNativeResponseBase,
|
|
7932
|
-
action:
|
|
7933
|
-
etag:
|
|
7934
|
-
bodyDigest:
|
|
7935
|
-
contentType:
|
|
8558
|
+
action: import_zod6.z.literal("tinycloud.kv/put"),
|
|
8559
|
+
etag: import_zod6.z.string().min(1),
|
|
8560
|
+
bodyDigest: import_zod6.z.string().min(1),
|
|
8561
|
+
contentType: import_zod6.z.string().min(1)
|
|
7936
8562
|
}).strict()
|
|
7937
8563
|
]);
|
|
7938
8564
|
|
|
8565
|
+
// src/delegations/portable.ts
|
|
8566
|
+
var import_zod7 = require("zod");
|
|
8567
|
+
var ResourceSchema = import_zod7.z.object({
|
|
8568
|
+
service: import_zod7.z.string().min(1),
|
|
8569
|
+
space: import_zod7.z.string().min(1),
|
|
8570
|
+
path: import_zod7.z.string(),
|
|
8571
|
+
actions: import_zod7.z.array(import_zod7.z.string().min(1)).min(1),
|
|
8572
|
+
caveats: import_zod7.z.array(import_zod7.z.record(import_zod7.z.unknown())).optional()
|
|
8573
|
+
}).strict();
|
|
8574
|
+
var PortableDelegationSchema = import_zod7.z.object({
|
|
8575
|
+
cid: import_zod7.z.string().min(1),
|
|
8576
|
+
delegationHeader: import_zod7.z.object({ Authorization: import_zod7.z.string().min(1) }).strict(),
|
|
8577
|
+
ownerAddress: import_zod7.z.string().min(1),
|
|
8578
|
+
chainId: import_zod7.z.number().int().nonnegative(),
|
|
8579
|
+
host: import_zod7.z.string().url().optional(),
|
|
8580
|
+
spaceId: import_zod7.z.string().min(1),
|
|
8581
|
+
path: import_zod7.z.string(),
|
|
8582
|
+
actions: import_zod7.z.array(import_zod7.z.string().min(1)).min(1),
|
|
8583
|
+
caveats: import_zod7.z.array(import_zod7.z.record(import_zod7.z.unknown())).optional(),
|
|
8584
|
+
expiry: import_zod7.z.coerce.date(),
|
|
8585
|
+
delegateDID: import_zod7.z.string().min(1),
|
|
8586
|
+
delegatorDID: import_zod7.z.string().min(1).optional(),
|
|
8587
|
+
parentCid: import_zod7.z.string().min(1).optional(),
|
|
8588
|
+
disableSubDelegation: import_zod7.z.boolean().optional(),
|
|
8589
|
+
resources: import_zod7.z.array(ResourceSchema).min(1).optional()
|
|
8590
|
+
}).strict();
|
|
8591
|
+
function parsePortableDelegation(input) {
|
|
8592
|
+
const parsed = PortableDelegationSchema.parse(input);
|
|
8593
|
+
if (parsed.resources !== void 0 && parsed.resources.length === 0)
|
|
8594
|
+
throw new Error("portable delegation resources must not be empty");
|
|
8595
|
+
return parsed;
|
|
8596
|
+
}
|
|
8597
|
+
function serializePortableDelegation(delegation) {
|
|
8598
|
+
return JSON.stringify({
|
|
8599
|
+
...delegation,
|
|
8600
|
+
expiry: delegation.expiry.toISOString()
|
|
8601
|
+
});
|
|
8602
|
+
}
|
|
8603
|
+
async function importPortableDelegation(fetchFn, host, delegation) {
|
|
8604
|
+
const parsed = parsePortableDelegation(delegation);
|
|
8605
|
+
const response = await fetchFn(`${host.replace(/\/+$/, "")}/delegate`, {
|
|
8606
|
+
method: "POST",
|
|
8607
|
+
headers: { Authorization: parsed.delegationHeader.Authorization }
|
|
8608
|
+
});
|
|
8609
|
+
if (!response.ok)
|
|
8610
|
+
throw new Error(`node rejected delegation import (${response.status})`);
|
|
8611
|
+
const body = await response.json().catch(() => ({}));
|
|
8612
|
+
if (body === null || typeof body !== "object" || Array.isArray(body))
|
|
8613
|
+
return {};
|
|
8614
|
+
return body;
|
|
8615
|
+
}
|
|
8616
|
+
async function delegatePortablePolicySession(input) {
|
|
8617
|
+
const parent = parsePortableDelegation(input.parent);
|
|
8618
|
+
const descendant = createCompactPolicyDescendant({
|
|
8619
|
+
parentAuthorization: parent.delegationHeader.Authorization.replace(/^Bearer\s+/i, ""),
|
|
8620
|
+
parentCid: parent.cid,
|
|
8621
|
+
issuerDid: parent.delegateDID,
|
|
8622
|
+
audienceDid: input.delegateDID,
|
|
8623
|
+
attenuation: input.attenuation,
|
|
8624
|
+
privateKey: input.issuerPrivateKey,
|
|
8625
|
+
...input.now === void 0 ? {} : { now: input.now },
|
|
8626
|
+
...input.expiresAt === void 0 ? {} : { expiresAt: input.expiresAt },
|
|
8627
|
+
...input.nonce === void 0 ? {} : { nonce: input.nonce }
|
|
8628
|
+
});
|
|
8629
|
+
const resources = Object.entries(descendant.payload.att).map(([resource, abilities]) => {
|
|
8630
|
+
const actions = Object.keys(abilities);
|
|
8631
|
+
if (resource.startsWith("urn:tinycloud:encryption:")) {
|
|
8632
|
+
return { service: "encryption", space: "encryption", path: resource, actions };
|
|
8633
|
+
}
|
|
8634
|
+
const match = /^tinycloud:\/\/([^/]+)\/kv\/(.+)$/.exec(resource);
|
|
8635
|
+
if (match === null) throw new Error("policy descendant resource is invalid");
|
|
8636
|
+
const caveats = Object.values(abilities).flat().filter((value) => value !== null && typeof value === "object" && !Array.isArray(value));
|
|
8637
|
+
return { service: "kv", space: match[1], path: match[2], actions, ...caveats.length === 0 ? {} : { caveats } };
|
|
8638
|
+
});
|
|
8639
|
+
const primary = resources.find((resource) => resource.service === "kv") ?? resources[0];
|
|
8640
|
+
if (primary === void 0) throw new Error("policy descendant attenuation is empty");
|
|
8641
|
+
const portable = {
|
|
8642
|
+
cid: descendant.cid,
|
|
8643
|
+
delegationHeader: { Authorization: descendant.authorization },
|
|
8644
|
+
ownerAddress: parent.ownerAddress,
|
|
8645
|
+
chainId: parent.chainId,
|
|
8646
|
+
host: input.host,
|
|
8647
|
+
spaceId: primary.space,
|
|
8648
|
+
path: primary.path,
|
|
8649
|
+
actions: primary.actions,
|
|
8650
|
+
expiry: new Date(descendant.payload.exp * 1e3),
|
|
8651
|
+
delegateDID: input.delegateDID,
|
|
8652
|
+
delegatorDID: parent.delegateDID,
|
|
8653
|
+
parentCid: parent.cid,
|
|
8654
|
+
disableSubDelegation: descendant.payload.fct[0]?.remainingRedelegationDepth === 0,
|
|
8655
|
+
resources
|
|
8656
|
+
};
|
|
8657
|
+
await importPortableDelegation(input.fetch, input.host, portable);
|
|
8658
|
+
return portable;
|
|
8659
|
+
}
|
|
8660
|
+
|
|
7939
8661
|
// src/delegations/ShareRecipientClient.ts
|
|
7940
8662
|
var DEFAULT_MAX_ARTIFACT_BYTES2 = MAX_SHARE_ARTIFACT_BYTES;
|
|
7941
8663
|
var DEFAULT_MAX_CONTENT_BYTES = MAX_SHARE_CONTENT_BYTES;
|
|
@@ -7986,8 +8708,8 @@ function canonicalJsonForProof(value) {
|
|
|
7986
8708
|
}
|
|
7987
8709
|
if (Array.isArray(value)) return `[${value.map(canonicalJsonForProof).join(",")}]`;
|
|
7988
8710
|
if (typeof value === "object") {
|
|
7989
|
-
const
|
|
7990
|
-
return `{${Object.keys(
|
|
8711
|
+
const object2 = value;
|
|
8712
|
+
return `{${Object.keys(object2).sort().map((key) => `${JSON.stringify(key)}:${canonicalJsonForProof(object2[key])}`).join(",")}}`;
|
|
7991
8713
|
}
|
|
7992
8714
|
throw new ShareAccessError("SHARE_SESSION_INVALID");
|
|
7993
8715
|
}
|
|
@@ -8011,7 +8733,7 @@ function randomJti() {
|
|
|
8011
8733
|
return bytesToBase64Url2(bytes2);
|
|
8012
8734
|
}
|
|
8013
8735
|
function digestCanonical(value) {
|
|
8014
|
-
return bytesToBase64Url2((0,
|
|
8736
|
+
return bytesToBase64Url2((0, import_sha2564.sha256)(new TextEncoder().encode(canonicalJsonForProof(value))));
|
|
8015
8737
|
}
|
|
8016
8738
|
function actionWire(action) {
|
|
8017
8739
|
return action === "get" ? "tinycloud.kv/get" : action === "metadata" ? "tinycloud.kv/metadata" : action === "list" ? "tinycloud.kv/list" : "tinycloud.kv/put";
|
|
@@ -8123,9 +8845,31 @@ var ShareRecipientClient = class {
|
|
|
8123
8845
|
if (policy && this.options.bearerSession !== void 0) throw new ShareAccessError("SHARE_POLICY_BEARER_MISMATCH");
|
|
8124
8846
|
if (bearer && this.options.presentation !== void 0) throw new ShareAccessError("SHARE_BEARER_PRESENTATION_MISMATCH");
|
|
8125
8847
|
const session = bearer || legacyBearer ? this.options.bearerSession : recipientDidSession ? recipientDidSession : policy && this.options.establishPolicySession !== void 0 ? await this.options.establishPolicySession({ envelope, presentation: this.options.presentation }) : policy ? await this.establishPolicySession(envelope) : void 0;
|
|
8126
|
-
const kv = bearer || legacyBearer ? session === void 0 ? void 0 : this.createKV(envelope.origin, session) : void 0;
|
|
8127
8848
|
const policySession = policy ? session : void 0;
|
|
8128
8849
|
if (policySession !== void 0) this.assertProvidedPolicySession(policySession, envelope);
|
|
8850
|
+
const portableDelegation = policySession === void 0 ? void 0 : this.policySessionDelegation(policySession, envelope.origin);
|
|
8851
|
+
const portableInvoke = portableDelegation === void 0 ? void 0 : this.policyInvocationSigner(portableDelegation);
|
|
8852
|
+
if (portableDelegation !== void 0) {
|
|
8853
|
+
if (this.options.importDelegation === void 0) {
|
|
8854
|
+
await importPortableDelegation(this.fetchFn, envelope.origin, portableDelegation);
|
|
8855
|
+
} else {
|
|
8856
|
+
const imported = await this.options.importDelegation(portableDelegation);
|
|
8857
|
+
if (imported !== void 0) {
|
|
8858
|
+
const normalized = parsePortableDelegation(imported);
|
|
8859
|
+
if (normalized.delegationHeader.Authorization !== portableDelegation.delegationHeader.Authorization) {
|
|
8860
|
+
throw new ShareAccessError("SHARE_SESSION_INVALID", "delegation importer changed authorization bytes");
|
|
8861
|
+
}
|
|
8862
|
+
}
|
|
8863
|
+
}
|
|
8864
|
+
}
|
|
8865
|
+
const ordinarySession = portableDelegation === void 0 ? void 0 : {
|
|
8866
|
+
delegationHeader: portableDelegation.delegationHeader,
|
|
8867
|
+
delegationCid: portableDelegation.cid,
|
|
8868
|
+
spaceId: this.policySessionProjection(portableDelegation).spaceId,
|
|
8869
|
+
verificationMethod: portableDelegation.delegateDID,
|
|
8870
|
+
jwk: this.options.bearerSession?.jwk ?? {}
|
|
8871
|
+
};
|
|
8872
|
+
const kv = bearer || legacyBearer || ordinarySession !== void 0 ? session === void 0 && ordinarySession === void 0 ? void 0 : this.createKV(envelope.origin, ordinarySession ?? session, portableInvoke) : void 0;
|
|
8129
8873
|
const advertisedCapability = { spaceId: envelope.spaceId, resource: envelope.resource, actions: envelope.actions };
|
|
8130
8874
|
const capability = policySession?.capability === void 0 ? advertisedCapability : intersectShareCapabilities(advertisedCapability, policySession.capability);
|
|
8131
8875
|
if (capability === void 0) throw new ShareAccessError("SHARE_CAPABILITY_EMPTY");
|
|
@@ -8150,6 +8894,11 @@ var ShareRecipientClient = class {
|
|
|
8150
8894
|
const scope = normalizePath2(input.path ?? envelope.resource.path);
|
|
8151
8895
|
this.assertAllowed(capability, "list", scope);
|
|
8152
8896
|
if (kv === void 0 && policySession === void 0) throw new ShareAccessError("SHARE_SESSION_REQUIRED");
|
|
8897
|
+
if (portableDelegation !== void 0 && kv !== void 0) {
|
|
8898
|
+
const result2 = await kv.list({ path: scope, limit: input.limit, cursor: input.cursor });
|
|
8899
|
+
if (!result2.ok) throw result2.error;
|
|
8900
|
+
return { keys: result2.data.keys, truncated: result2.data.truncated, nextCursor: result2.data.nextCursor };
|
|
8901
|
+
}
|
|
8153
8902
|
if (policySession !== void 0) return this.nativeList(envelope, policySession, scope, input.limit, input.cursor);
|
|
8154
8903
|
const result = await kv.list({ path: scope, limit: input.limit, cursor: input.cursor });
|
|
8155
8904
|
if (!result.ok) throw result.error;
|
|
@@ -8163,6 +8912,14 @@ var ShareRecipientClient = class {
|
|
|
8163
8912
|
const resolvedPath = normalizePath2(path);
|
|
8164
8913
|
this.assertAllowed(capability, "save", resolvedPath);
|
|
8165
8914
|
if (kv === void 0 && policySession === void 0) throw new ShareAccessError("SHARE_SESSION_REQUIRED");
|
|
8915
|
+
if (portableDelegation !== void 0 && kv !== void 0) {
|
|
8916
|
+
const result2 = await kv.put(resolvedPath, bytes2, { contentType: input.contentType ?? envelope.content.mimeType, ifMatch: input.etag });
|
|
8917
|
+
if (!result2.ok) {
|
|
8918
|
+
if (result2.error.code === import_sdk_services2.ErrorCodes.KV_PRECONDITION_FAILED || result2.error.code === import_sdk_services2.ErrorCodes.KV_CONFLICT) throw new ShareConflict(resolvedPath, result2.error.meta?.etag);
|
|
8919
|
+
throw result2.error;
|
|
8920
|
+
}
|
|
8921
|
+
return { etag: result2.data.headers.etag };
|
|
8922
|
+
}
|
|
8166
8923
|
if (policySession !== void 0) return this.nativeSave(envelope, policySession, resolvedPath, bytes2, input);
|
|
8167
8924
|
const result = await kv.put(resolvedPath, bytes2, { contentType: input.contentType ?? envelope.content.mimeType, ifMatch: input.etag });
|
|
8168
8925
|
if (!result.ok) {
|
|
@@ -8178,22 +8935,79 @@ var ShareRecipientClient = class {
|
|
|
8178
8935
|
const metadata = async (path = envelope.resource.kind === "exact" ? envelope.resource.path : "") => {
|
|
8179
8936
|
const resolvedPath = normalizePath2(path);
|
|
8180
8937
|
this.assertAllowed(capability, "metadata", resolvedPath);
|
|
8938
|
+
if (portableDelegation !== void 0 && kv !== void 0) {
|
|
8939
|
+
const result2 = await kv.head(resolvedPath);
|
|
8940
|
+
if (!result2.ok) throw result2.error;
|
|
8941
|
+
return { metadata: { "content-type": result2.data.headers.contentType ?? "application/octet-stream", "content-length": String(result2.data.headers.contentLength ?? ""), ...result2.data.headers.lastModified === void 0 ? {} : { "last-modified": result2.data.headers.lastModified } }, etag: result2.data.headers.etag, contentType: result2.data.headers.contentType, size: result2.data.headers.contentLength };
|
|
8942
|
+
}
|
|
8181
8943
|
if (policySession !== void 0) return this.nativeMetadata(envelope, policySession, resolvedPath);
|
|
8182
8944
|
if (kv === void 0) throw new ShareAccessError("SHARE_SESSION_REQUIRED");
|
|
8183
8945
|
const result = await kv.head(resolvedPath);
|
|
8184
8946
|
if (!result.ok) throw result.error;
|
|
8185
8947
|
return { metadata: { "content-type": result.data.headers.contentType ?? "application/octet-stream", "content-length": String(result.data.headers.contentLength ?? ""), ...result.data.headers.lastModified === void 0 ? {} : { "last-modified": result.data.headers.lastModified } }, etag: result.data.headers.etag, contentType: result.data.headers.contentType, size: result.data.headers.contentLength };
|
|
8186
8948
|
};
|
|
8187
|
-
return { kind: "share-v2", envelope, location: { ...location, key: void 0 }, resource: envelope.resource, actions: envelope.actions, expiresAt: new Date(envelope.expiresAt), kv, get, listChildren, save, metadata };
|
|
8949
|
+
return { kind: "share-v2", envelope, location: { ...location, key: void 0 }, resource: envelope.resource, actions: envelope.actions, expiresAt: new Date(envelope.expiresAt), kv, portableDelegation, get, listChildren, save, metadata };
|
|
8188
8950
|
} catch (error) {
|
|
8189
8951
|
throw asError(error);
|
|
8190
8952
|
}
|
|
8191
8953
|
}
|
|
8192
|
-
|
|
8954
|
+
policySessionDelegation(session, origin) {
|
|
8955
|
+
if (session.runtimeDelegation === void 0) return void 0;
|
|
8956
|
+
const delegation = parsePortableDelegation(session.runtimeDelegation);
|
|
8957
|
+
if (delegation.host !== void 0 && delegation.host.replace(/\/+$/, "") !== origin.replace(/\/+$/, "")) throw new ShareAccessError("SHARE_ORIGIN_MISMATCH", "delegation host does not match the trusted share origin");
|
|
8958
|
+
return delegation;
|
|
8959
|
+
}
|
|
8960
|
+
policyInvocationSigner(delegation) {
|
|
8961
|
+
const privateKey = this.options.policySessionPrivateKey;
|
|
8962
|
+
if (privateKey === void 0) throw new ShareAccessError("SHARE_SESSION_SIGNER_REQUIRED");
|
|
8963
|
+
const session = parsePolicySessionUcan(delegation.delegationHeader.Authorization);
|
|
8964
|
+
if (session.cid !== delegation.cid || session.aud !== delegation.delegateDID)
|
|
8965
|
+
throw new ShareAccessError("SHARE_SESSION_INVALID");
|
|
8966
|
+
return (_serviceSession, service, path, action, facts) => {
|
|
8967
|
+
const serviceName = service.replace(/^tinycloud\./, "");
|
|
8968
|
+
const cleanPath = path.replace(/^\//, "").replace(/\/$/, "");
|
|
8969
|
+
const authority = Object.entries(session.att).find(([parentResource, abilities]) => {
|
|
8970
|
+
if (!(action in abilities)) return false;
|
|
8971
|
+
if (serviceName === "encryption") return parentResource.startsWith("urn:tinycloud:encryption:") && parentResource === cleanPath;
|
|
8972
|
+
const match = /^tinycloud:\/\/[^/]+\/kv\/(.+)$/.exec(parentResource);
|
|
8973
|
+
if (match === null) return false;
|
|
8974
|
+
const parentPath = match[1];
|
|
8975
|
+
const caveats = abilities[action] ?? [];
|
|
8976
|
+
const prefix = caveats.some((value) => isRecord(value) && value.kind === "prefix");
|
|
8977
|
+
return cleanPath === parentPath || prefix && cleanPath.startsWith(`${parentPath}/`);
|
|
8978
|
+
});
|
|
8979
|
+
if (authority === void 0) throw new ShareAccessError("SHARE_OUT_OF_SCOPE");
|
|
8980
|
+
const resource = serviceName === "encryption" ? authority[0] : `${authority[0].slice(0, authority[0].indexOf("/kv/") + 4)}${cleanPath}`;
|
|
8981
|
+
const caveat = serviceName === "encryption" ? {} : { type: "xyz.tinycloud.resource/selector", kind: "exact", value: resource };
|
|
8982
|
+
const invocation = createCompactPolicyInvocation({
|
|
8983
|
+
sessionAuthorization: delegation.delegationHeader.Authorization,
|
|
8984
|
+
sessionCid: delegation.cid,
|
|
8985
|
+
recipientDid: delegation.delegateDID,
|
|
8986
|
+
audienceDid: String(session.fact.nodeAudience),
|
|
8987
|
+
resource,
|
|
8988
|
+
action,
|
|
8989
|
+
caveat,
|
|
8990
|
+
...facts?.length === 1 ? { facts: facts[0] } : {},
|
|
8991
|
+
privateKey,
|
|
8992
|
+
now: Math.floor(this.now().getTime() / 1e3)
|
|
8993
|
+
});
|
|
8994
|
+
return { Authorization: invocation.authorization };
|
|
8995
|
+
};
|
|
8996
|
+
}
|
|
8997
|
+
policySessionProjection(delegation) {
|
|
8998
|
+
const session = parsePolicySessionUcan(delegation.delegationHeader.Authorization);
|
|
8999
|
+
if (session.cid !== delegation.cid || session.aud !== delegation.delegateDID) throw new ShareAccessError("SHARE_SESSION_INVALID");
|
|
9000
|
+
const kvResource = Object.keys(session.att).find((resource) => /^tinycloud:\/\/[^/]+\/kv\/.+$/.test(resource));
|
|
9001
|
+
const match = kvResource === void 0 ? void 0 : /^tinycloud:\/\/([^/]+)\/kv\/(.+)$/.exec(kvResource);
|
|
9002
|
+
if (match === void 0 || match === null) throw new ShareAccessError("SHARE_SESSION_INVALID");
|
|
9003
|
+
return { spaceId: match[1] };
|
|
9004
|
+
}
|
|
9005
|
+
createKV(origin, session, invokeOverride) {
|
|
9006
|
+
const invoke = invokeOverride ?? this.options.invoke ?? nativeInvoke;
|
|
8193
9007
|
if (this.options.createKVService !== void 0) {
|
|
8194
|
-
return this.options.createKVService({ hosts: [origin], session, invoke
|
|
9008
|
+
return this.options.createKVService({ hosts: [origin], session, invoke, fetch: this.fetchFn });
|
|
8195
9009
|
}
|
|
8196
|
-
const context = new import_sdk_services2.ServiceContext({ hosts: [origin], session, invoke
|
|
9010
|
+
const context = new import_sdk_services2.ServiceContext({ hosts: [origin], session, invoke, fetch: this.fetchFn });
|
|
8197
9011
|
const service = new import_sdk_services2.KVService({ prefix: "" });
|
|
8198
9012
|
context.registerService("kv", service);
|
|
8199
9013
|
service.initialize(context);
|
|
@@ -8236,7 +9050,7 @@ var ShareRecipientClient = class {
|
|
|
8236
9050
|
if (bytes2.byteLength > (this.options.maxContentBytes ?? DEFAULT_MAX_CONTENT_BYTES)) throw new ShareAccessError("SHARE_TOO_LARGE");
|
|
8237
9051
|
const contentType = input.contentType ?? envelope.content.mimeType;
|
|
8238
9052
|
if (contentType !== envelope.content.mimeType && !/^text\/(?:plain|markdown)(?:;|$)/i.test(contentType)) throw new ShareAccessError("SHARE_CONTENT_TYPE_INVALID");
|
|
8239
|
-
const result = await this.invokeNative({ envelope, session, action: "put", resource: path, body: bytes2, bodyDigest: bytesToBase64Url2((0,
|
|
9053
|
+
const result = await this.invokeNative({ envelope, session, action: "put", resource: path, body: bytes2, bodyDigest: bytesToBase64Url2((0, import_sha2564.sha256)(bytes2)), contentType, ifMatch: input.etag, mediaType: "application/vnd.tinycloud.share+json" });
|
|
8240
9054
|
if (result.status === 412 || result.status === 409) throw new ShareConflict(path, result.headers?.etag);
|
|
8241
9055
|
if (result.status === 401 || result.status === 403) throw new ShareAccessError("SHARE_DENIED");
|
|
8242
9056
|
if (result.status < 200 || result.status >= 300) throw new ShareAccessError("SHARE_WRITE_FAILED");
|
|
@@ -8358,7 +9172,7 @@ var ShareRecipientClient = class {
|
|
|
8358
9172
|
};
|
|
8359
9173
|
const signed = this.options.signNativeInvoke === void 0 ? void 0 : await this.options.signNativeInvoke({ envelope: input.envelope, session: input.session, request: body });
|
|
8360
9174
|
const transport = this.options.invoke !== void 0 || session.authorization !== void 0 || session.delegationHeader !== void 0 ? this.defaultNativeHeaders(session, input.action, input.resource, body) : void 0;
|
|
8361
|
-
const response = await this.fetchFn(
|
|
9175
|
+
const response = await this.fetchFn(`${base3}/invoke`, {
|
|
8362
9176
|
method: "POST",
|
|
8363
9177
|
headers: { ...headersRecord2(transport), ...headersRecord2(signed), "content-type": input.mediaType, accept: input.mediaType },
|
|
8364
9178
|
body: JSON.stringify(body),
|
|
@@ -8482,7 +9296,7 @@ var ShareRecipientClient = class {
|
|
|
8482
9296
|
}]);
|
|
8483
9297
|
}
|
|
8484
9298
|
digestMatches(value, bytes2) {
|
|
8485
|
-
const digest4 = bytesToBase64Url2((0,
|
|
9299
|
+
const digest4 = bytesToBase64Url2((0, import_sha2564.sha256)(bytes2));
|
|
8486
9300
|
return value === digest4 || value === `sha-256=:${digest4}:`;
|
|
8487
9301
|
}
|
|
8488
9302
|
assertNativeRequestBounds(envelope, session, operation, path, limit, cursor) {
|
|
@@ -8604,12 +9418,12 @@ var ShareRecipientClient = class {
|
|
|
8604
9418
|
this.assertDetachedProof(request.proof);
|
|
8605
9419
|
}
|
|
8606
9420
|
parseSessionCapability(value) {
|
|
8607
|
-
const
|
|
8608
|
-
if (typeof
|
|
8609
|
-
if (!Array.isArray(
|
|
8610
|
-
const resource = this.requireObject(
|
|
9421
|
+
const object2 = this.requireObject(value, "session capability");
|
|
9422
|
+
if (typeof object2.spaceId !== "string") throw new ShareAccessError("SHARE_SESSION_INVALID", "session capability space is invalid");
|
|
9423
|
+
if (!Array.isArray(object2.actions) || object2.actions.some((action) => !["read", "list", "edit"].includes(action))) throw new ShareAccessError("SHARE_SESSION_INVALID", "session capability actions are invalid");
|
|
9424
|
+
const resource = this.requireObject(object2.resource, "session capability resource");
|
|
8611
9425
|
if (resource.kind !== "exact" && resource.kind !== "prefix" || typeof resource.path !== "string") throw new ShareAccessError("SHARE_SESSION_INVALID", "session capability resource is invalid");
|
|
8612
|
-
return { spaceId:
|
|
9426
|
+
return { spaceId: object2.spaceId, actions: [...new Set(object2.actions)], resource: { kind: resource.kind, path: resource.path } };
|
|
8613
9427
|
}
|
|
8614
9428
|
assertProvidedPolicySession(session, envelope) {
|
|
8615
9429
|
const sessionExpiry = dateValue(session.expiresAt);
|
|
@@ -8700,7 +9514,7 @@ var ShareRecipientClient = class {
|
|
|
8700
9514
|
nodeAudience: binding.nodeAudience,
|
|
8701
9515
|
...isV2 ? {
|
|
8702
9516
|
enforcerDid: challenge.enforcerDid,
|
|
8703
|
-
credentialDigest: typeof presentation.credentialDigest === "string" ? presentation.credentialDigest : bytesToBase64Url2((0,
|
|
9517
|
+
credentialDigest: typeof presentation.credentialDigest === "string" ? presentation.credentialDigest : bytesToBase64Url2((0, import_sha2564.sha256)(new TextEncoder().encode(credential)))
|
|
8704
9518
|
} : {},
|
|
8705
9519
|
action,
|
|
8706
9520
|
...binding.actions === void 0 ? {} : { actions: [...binding.actions] },
|
|
@@ -8766,7 +9580,7 @@ var ShareRecipientClient = class {
|
|
|
8766
9580
|
}
|
|
8767
9581
|
if (isJwsProof && detached.kid !== `${signerDid}#${encoded}` || isEd25519Proof && detached.signerDid !== signerDid || signature.length !== 64) throw new ShareAccessError("SHARE_SESSION_INVALID", "Node proof binding is invalid");
|
|
8768
9582
|
const bytes2 = new TextEncoder().encode(`${domain}${canonicalJsonForProof(message)}`);
|
|
8769
|
-
if (!
|
|
9583
|
+
if (!import_ed255194.ed25519.verify(signature, bytes2, key)) throw new ShareAccessError("SHARE_SESSION_INVALID", "Node proof signature is invalid");
|
|
8770
9584
|
}
|
|
8771
9585
|
assertChallengeRequestBinding(request, challenge) {
|
|
8772
9586
|
const source = isRecord(request.body) ? request.body : request;
|
|
@@ -9970,7 +10784,7 @@ function shareKeyMatchesDid(key, didUrl) {
|
|
|
9970
10784
|
if (!publicKey) return false;
|
|
9971
10785
|
const jwkBytes = decodeBase64UrlBytes(key.x);
|
|
9972
10786
|
const privateKey = decodeBase64UrlBytes(key.d);
|
|
9973
|
-
const derivedPublicKey =
|
|
10787
|
+
const derivedPublicKey = import_ed255195.ed25519.getPublicKey(privateKey);
|
|
9974
10788
|
return privateKey.length === 32 && publicKey.length === jwkBytes.length && publicKey.every((byte, index) => byte === jwkBytes[index]) && derivedPublicKey.length === jwkBytes.length && derivedPublicKey.every((byte, index) => byte === jwkBytes[index]);
|
|
9975
10789
|
} catch {
|
|
9976
10790
|
return false;
|
|
@@ -10020,8 +10834,8 @@ function verifySignedChild(result, expected, computeCid) {
|
|
|
10020
10834
|
}
|
|
10021
10835
|
|
|
10022
10836
|
// src/delegations/owner-policy.ts
|
|
10023
|
-
var
|
|
10024
|
-
var
|
|
10837
|
+
var import_ed255196 = require("@noble/curves/ed25519");
|
|
10838
|
+
var import_sha2565 = require("@noble/hashes/sha256");
|
|
10025
10839
|
var MAX_CONTENT_BYTES = 100 * 1024 * 1024;
|
|
10026
10840
|
var ENFORCEMENT_DOMAIN = "xyz.tinycloud.share/policy-enforcement/v2\0";
|
|
10027
10841
|
var POLICY_DOMAIN = "xyz.tinycloud.share/policy/v2\0";
|
|
@@ -10048,10 +10862,10 @@ function fromB64(value) {
|
|
|
10048
10862
|
throw new Error("base64url decoding is unavailable");
|
|
10049
10863
|
}
|
|
10050
10864
|
function cid(bytesValue) {
|
|
10051
|
-
return CID.createV1(code, create(sha2562.code, (0,
|
|
10865
|
+
return CID.createV1(code, create(sha2562.code, (0, import_sha2565.sha256)(bytesValue))).toString(base32.encoder);
|
|
10052
10866
|
}
|
|
10053
10867
|
function digest3(bytesValue) {
|
|
10054
|
-
return b64((0,
|
|
10868
|
+
return b64((0, import_sha2565.sha256)(bytesValue));
|
|
10055
10869
|
}
|
|
10056
10870
|
function didKeyFromEd25519PublicKey(publicKey) {
|
|
10057
10871
|
if (publicKey.length !== 32) throw new Error("share key public key must be 32 bytes");
|
|
@@ -10236,7 +11050,7 @@ function validateOwnerSharePolicyRegistration(value, expected) {
|
|
|
10236
11050
|
const publicKey = encodedKid.length === 34 ? encodedKid.slice(2) : encodedKid;
|
|
10237
11051
|
const signatureBytes = fromB64(proof.signature);
|
|
10238
11052
|
const signedBytes = new TextEncoder().encode(`${OWNER_SHARE_REGISTRATION_DOMAIN}${canonicalizeSignedObjectUnsigned(registrationCore)}`);
|
|
10239
|
-
if (signatureBytes.length !== 64 || !
|
|
11053
|
+
if (signatureBytes.length !== 64 || !import_ed255196.ed25519.verify(signatureBytes, signedBytes, publicKey)) throw new Error("owner-share registration proof signature is invalid");
|
|
10240
11054
|
return { registration, proof };
|
|
10241
11055
|
}
|
|
10242
11056
|
function validateOwnerSharePolicyRegistrationBytes(bytesValue, expected) {
|
|
@@ -10250,7 +11064,7 @@ function validateOwnerSharePolicyRegistrationBytes(bytesValue, expected) {
|
|
|
10250
11064
|
}
|
|
10251
11065
|
|
|
10252
11066
|
// src/delegations/share-delivery.ts
|
|
10253
|
-
var
|
|
11067
|
+
var import_ed255197 = require("@noble/curves/ed25519");
|
|
10254
11068
|
var SHARE_DELIVERY_AUTHORIZATION_DOMAIN = "xyz.tinycloud.share/delivery-authorization/v2\0";
|
|
10255
11069
|
function isCanonicalHttpsOrigin(value) {
|
|
10256
11070
|
let url;
|
|
@@ -10338,7 +11152,7 @@ function validateShareDeliveryAuthorizationBytes(bytesValue, expected) {
|
|
|
10338
11152
|
if (publicKey.length !== 32) throw new Error("share delivery authorization proof key is invalid");
|
|
10339
11153
|
const signatureBytes = fromB642(proof.signature);
|
|
10340
11154
|
const signedBytes = new TextEncoder().encode(`${SHARE_DELIVERY_AUTHORIZATION_DOMAIN}${canonicalizeSignedObjectUnsigned(authorization)}`);
|
|
10341
|
-
if (signatureBytes.length !== 64 || !
|
|
11155
|
+
if (signatureBytes.length !== 64 || !import_ed255197.ed25519.verify(signatureBytes, signedBytes, publicKey)) throw new Error("share delivery authorization proof signature is invalid");
|
|
10342
11156
|
return { authorization, proof };
|
|
10343
11157
|
}
|
|
10344
11158
|
function shareDeliveryTrustedKid(publicKey) {
|
|
@@ -10474,47 +11288,47 @@ function parseCanonicalNetworkId(networkId) {
|
|
|
10474
11288
|
}
|
|
10475
11289
|
|
|
10476
11290
|
// src/storage.schema.ts
|
|
10477
|
-
var
|
|
11291
|
+
var import_zod8 = require("zod");
|
|
10478
11292
|
var ethereumAddressPattern = /^0x[a-fA-F0-9]{40}$/;
|
|
10479
|
-
var EnsDataSchema2 =
|
|
11293
|
+
var EnsDataSchema2 = import_zod8.z.object({
|
|
10480
11294
|
/** ENS name/domain. */
|
|
10481
|
-
domain:
|
|
11295
|
+
domain: import_zod8.z.string().nullable().optional(),
|
|
10482
11296
|
/** ENS avatar URL. */
|
|
10483
|
-
avatarUrl:
|
|
11297
|
+
avatarUrl: import_zod8.z.string().nullable().optional()
|
|
10484
11298
|
});
|
|
10485
|
-
var PersistedTinyCloudSessionSchema =
|
|
11299
|
+
var PersistedTinyCloudSessionSchema = import_zod8.z.object({
|
|
10486
11300
|
/** The delegation header containing the UCAN */
|
|
10487
|
-
delegationHeader:
|
|
10488
|
-
Authorization:
|
|
11301
|
+
delegationHeader: import_zod8.z.object({
|
|
11302
|
+
Authorization: import_zod8.z.string()
|
|
10489
11303
|
}),
|
|
10490
11304
|
/** The delegation CID */
|
|
10491
|
-
delegationCid:
|
|
11305
|
+
delegationCid: import_zod8.z.string(),
|
|
10492
11306
|
/** The space ID for this session */
|
|
10493
|
-
spaceId:
|
|
11307
|
+
spaceId: import_zod8.z.string(),
|
|
10494
11308
|
/** Additional spaces included in this session's capabilities. Key is logical name, value is full spaceId URI */
|
|
10495
|
-
spaces:
|
|
11309
|
+
spaces: import_zod8.z.record(import_zod8.z.string(), import_zod8.z.string()).optional(),
|
|
10496
11310
|
/** The verification method DID */
|
|
10497
|
-
verificationMethod:
|
|
11311
|
+
verificationMethod: import_zod8.z.string()
|
|
10498
11312
|
});
|
|
10499
|
-
var PersistedSessionDataSchema =
|
|
11313
|
+
var PersistedSessionDataSchema = import_zod8.z.object({
|
|
10500
11314
|
/** User's Ethereum address */
|
|
10501
|
-
address:
|
|
11315
|
+
address: import_zod8.z.string().regex(ethereumAddressPattern, "Invalid Ethereum address"),
|
|
10502
11316
|
/** EIP-155 Chain ID */
|
|
10503
|
-
chainId:
|
|
11317
|
+
chainId: import_zod8.z.number().int().positive(),
|
|
10504
11318
|
/** Session key in JWK format (stringified) */
|
|
10505
|
-
sessionKey:
|
|
11319
|
+
sessionKey: import_zod8.z.string(),
|
|
10506
11320
|
/** The signed SIWE message */
|
|
10507
|
-
siwe:
|
|
11321
|
+
siwe: import_zod8.z.string(),
|
|
10508
11322
|
/** User's signature of the SIWE message */
|
|
10509
|
-
signature:
|
|
11323
|
+
signature: import_zod8.z.string(),
|
|
10510
11324
|
/** TinyCloud delegation data if available */
|
|
10511
11325
|
tinycloudSession: PersistedTinyCloudSessionSchema.optional(),
|
|
10512
11326
|
/** Session expiration timestamp (ISO 8601 with timezone offset) */
|
|
10513
|
-
expiresAt:
|
|
11327
|
+
expiresAt: import_zod8.z.string().datetime({ offset: true }),
|
|
10514
11328
|
/** Session creation timestamp (ISO 8601 with timezone offset) */
|
|
10515
|
-
createdAt:
|
|
11329
|
+
createdAt: import_zod8.z.string().datetime({ offset: true }),
|
|
10516
11330
|
/** Schema version for migrations */
|
|
10517
|
-
version:
|
|
11331
|
+
version: import_zod8.z.string(),
|
|
10518
11332
|
/** Optional ENS data */
|
|
10519
11333
|
ens: EnsDataSchema2.optional(),
|
|
10520
11334
|
/**
|
|
@@ -10524,33 +11338,33 @@ var PersistedSessionDataSchema = import_zod6.z.object({
|
|
|
10524
11338
|
* for backward compatibility with sessions persisted before this field
|
|
10525
11339
|
* existed — those restore and lazily re-resolve their hosts.
|
|
10526
11340
|
*/
|
|
10527
|
-
tinycloudHosts:
|
|
11341
|
+
tinycloudHosts: import_zod8.z.array(import_zod8.z.string()).optional()
|
|
10528
11342
|
});
|
|
10529
|
-
var TinyCloudSessionSchema =
|
|
11343
|
+
var TinyCloudSessionSchema = import_zod8.z.object({
|
|
10530
11344
|
/** User's Ethereum address */
|
|
10531
|
-
address:
|
|
11345
|
+
address: import_zod8.z.string().regex(ethereumAddressPattern, "Invalid Ethereum address"),
|
|
10532
11346
|
/** EIP-155 Chain ID */
|
|
10533
|
-
chainId:
|
|
11347
|
+
chainId: import_zod8.z.number().int().positive(),
|
|
10534
11348
|
/** Session key ID */
|
|
10535
|
-
sessionKey:
|
|
11349
|
+
sessionKey: import_zod8.z.string(),
|
|
10536
11350
|
/** The space ID for this session */
|
|
10537
|
-
spaceId:
|
|
11351
|
+
spaceId: import_zod8.z.string(),
|
|
10538
11352
|
/** Additional spaces included in this session's capabilities. Key is logical name, value is full spaceId URI */
|
|
10539
|
-
spaces:
|
|
11353
|
+
spaces: import_zod8.z.record(import_zod8.z.string(), import_zod8.z.string()).optional(),
|
|
10540
11354
|
/** The delegation CID */
|
|
10541
|
-
delegationCid:
|
|
11355
|
+
delegationCid: import_zod8.z.string(),
|
|
10542
11356
|
/** The delegation header for API calls */
|
|
10543
|
-
delegationHeader:
|
|
10544
|
-
Authorization:
|
|
11357
|
+
delegationHeader: import_zod8.z.object({
|
|
11358
|
+
Authorization: import_zod8.z.string()
|
|
10545
11359
|
}),
|
|
10546
11360
|
/** The verification method DID */
|
|
10547
|
-
verificationMethod:
|
|
11361
|
+
verificationMethod: import_zod8.z.string(),
|
|
10548
11362
|
/** The session key JWK (required for invoke operations) */
|
|
10549
|
-
jwk:
|
|
11363
|
+
jwk: import_zod8.z.object({}).passthrough(),
|
|
10550
11364
|
/** The signed SIWE message */
|
|
10551
|
-
siwe:
|
|
11365
|
+
siwe: import_zod8.z.string(),
|
|
10552
11366
|
/** User's signature of the SIWE message */
|
|
10553
|
-
signature:
|
|
11367
|
+
signature: import_zod8.z.string()
|
|
10554
11368
|
});
|
|
10555
11369
|
function validatePersistedSessionData(data) {
|
|
10556
11370
|
const result = PersistedSessionDataSchema.safeParse(data);
|
|
@@ -10653,112 +11467,112 @@ var Space = class {
|
|
|
10653
11467
|
};
|
|
10654
11468
|
|
|
10655
11469
|
// src/spaces/spaces.schema.ts
|
|
10656
|
-
var
|
|
10657
|
-
var SpaceConfigSchema =
|
|
11470
|
+
var import_zod9 = require("zod");
|
|
11471
|
+
var SpaceConfigSchema = import_zod9.z.object({
|
|
10658
11472
|
/** The space identifier (full URI) */
|
|
10659
|
-
id:
|
|
11473
|
+
id: import_zod9.z.string(),
|
|
10660
11474
|
/** The short name of the space */
|
|
10661
|
-
name:
|
|
11475
|
+
name: import_zod9.z.string(),
|
|
10662
11476
|
/** Factory function to create a space-scoped KV service */
|
|
10663
|
-
createKV:
|
|
11477
|
+
createKV: import_zod9.z.function(),
|
|
10664
11478
|
/** Factory function to create a space-scoped Data Vault service */
|
|
10665
|
-
createVault:
|
|
11479
|
+
createVault: import_zod9.z.function(),
|
|
10666
11480
|
/** Optional factory function to create a space-scoped secrets service */
|
|
10667
|
-
createSecrets:
|
|
11481
|
+
createSecrets: import_zod9.z.function().optional(),
|
|
10668
11482
|
/** Factory function to create space-scoped delegations */
|
|
10669
|
-
createDelegations:
|
|
11483
|
+
createDelegations: import_zod9.z.function(),
|
|
10670
11484
|
/** Factory function to create space-scoped sharing */
|
|
10671
|
-
createSharing:
|
|
11485
|
+
createSharing: import_zod9.z.function(),
|
|
10672
11486
|
/** Function to get space info */
|
|
10673
|
-
getInfo:
|
|
11487
|
+
getInfo: import_zod9.z.function()
|
|
10674
11488
|
});
|
|
10675
|
-
var SpaceServiceConfigSchema =
|
|
11489
|
+
var SpaceServiceConfigSchema = import_zod9.z.object({
|
|
10676
11490
|
/** TinyCloud host URLs */
|
|
10677
|
-
hosts:
|
|
11491
|
+
hosts: import_zod9.z.array(import_zod9.z.string()),
|
|
10678
11492
|
/** Active session for authentication */
|
|
10679
|
-
session:
|
|
11493
|
+
session: import_zod9.z.unknown(),
|
|
10680
11494
|
/** Platform-specific invoke function */
|
|
10681
|
-
invoke:
|
|
11495
|
+
invoke: import_zod9.z.function(),
|
|
10682
11496
|
/** Optional custom fetch implementation */
|
|
10683
|
-
fetch:
|
|
11497
|
+
fetch: import_zod9.z.function().optional(),
|
|
10684
11498
|
/** Optional capability key registry for delegated space discovery */
|
|
10685
|
-
capabilityRegistry:
|
|
11499
|
+
capabilityRegistry: import_zod9.z.unknown().optional(),
|
|
10686
11500
|
/** Factory function to create a space-scoped KV service */
|
|
10687
|
-
createKVService:
|
|
11501
|
+
createKVService: import_zod9.z.function().optional(),
|
|
10688
11502
|
/** Factory function to create a space-scoped Data Vault service */
|
|
10689
|
-
createVaultService:
|
|
11503
|
+
createVaultService: import_zod9.z.function().optional(),
|
|
10690
11504
|
/** Factory function to create a space-scoped secrets service */
|
|
10691
|
-
createSecretsService:
|
|
11505
|
+
createSecretsService: import_zod9.z.function().optional(),
|
|
10692
11506
|
/** User's PKH DID (derived from address or provided explicitly) */
|
|
10693
|
-
userDid:
|
|
11507
|
+
userDid: import_zod9.z.string().optional(),
|
|
10694
11508
|
/** Optional SharingService for v2 sharing links (client-side) */
|
|
10695
|
-
sharingService:
|
|
11509
|
+
sharingService: import_zod9.z.unknown().optional(),
|
|
10696
11510
|
/** Factory function to create delegations using SIWE-based flow */
|
|
10697
|
-
createDelegation:
|
|
11511
|
+
createDelegation: import_zod9.z.function().optional()
|
|
10698
11512
|
});
|
|
10699
11513
|
var SpaceDelegationParamsSchema = CreateDelegationParamsSchema.extend({
|
|
10700
11514
|
/** The space ID to create the delegation for */
|
|
10701
|
-
spaceId:
|
|
11515
|
+
spaceId: import_zod9.z.string()
|
|
10702
11516
|
});
|
|
10703
|
-
var ServerDelegationInfoSchema =
|
|
11517
|
+
var ServerDelegationInfoSchema = import_zod9.z.object({
|
|
10704
11518
|
/** DID of the delegator */
|
|
10705
|
-
delegator:
|
|
11519
|
+
delegator: import_zod9.z.string(),
|
|
10706
11520
|
/** DID of the delegate */
|
|
10707
|
-
delegate:
|
|
11521
|
+
delegate: import_zod9.z.string(),
|
|
10708
11522
|
/** Parent delegation CIDs - accepts string or byte array format from server */
|
|
10709
|
-
parents:
|
|
11523
|
+
parents: import_zod9.z.array(import_zod9.z.union([import_zod9.z.string(), import_zod9.z.array(import_zod9.z.number())])),
|
|
10710
11524
|
/** Expiration time (ISO8601 string) */
|
|
10711
|
-
expiry:
|
|
11525
|
+
expiry: import_zod9.z.string().optional(),
|
|
10712
11526
|
/** Not-before time (ISO8601 string) */
|
|
10713
|
-
not_before:
|
|
11527
|
+
not_before: import_zod9.z.string().optional(),
|
|
10714
11528
|
/** Issued-at time (ISO8601 string) */
|
|
10715
|
-
issued_at:
|
|
11529
|
+
issued_at: import_zod9.z.string().optional(),
|
|
10716
11530
|
/** Capabilities granted by this delegation */
|
|
10717
|
-
capabilities:
|
|
10718
|
-
|
|
10719
|
-
resource:
|
|
10720
|
-
ability:
|
|
11531
|
+
capabilities: import_zod9.z.array(
|
|
11532
|
+
import_zod9.z.object({
|
|
11533
|
+
resource: import_zod9.z.string(),
|
|
11534
|
+
ability: import_zod9.z.string()
|
|
10721
11535
|
})
|
|
10722
11536
|
)
|
|
10723
11537
|
});
|
|
10724
|
-
var ServerDelegationsResponseSchema =
|
|
10725
|
-
|
|
11538
|
+
var ServerDelegationsResponseSchema = import_zod9.z.record(
|
|
11539
|
+
import_zod9.z.string(),
|
|
10726
11540
|
ServerDelegationInfoSchema
|
|
10727
11541
|
);
|
|
10728
|
-
var ServerOwnedSpaceSchema =
|
|
11542
|
+
var ServerOwnedSpaceSchema = import_zod9.z.object({
|
|
10729
11543
|
/** Space identifier */
|
|
10730
|
-
id:
|
|
11544
|
+
id: import_zod9.z.string(),
|
|
10731
11545
|
/** Space name (optional, can be derived from id) */
|
|
10732
|
-
name:
|
|
11546
|
+
name: import_zod9.z.string().optional(),
|
|
10733
11547
|
/** Owner DID */
|
|
10734
|
-
owner:
|
|
11548
|
+
owner: import_zod9.z.string(),
|
|
10735
11549
|
/** Creation timestamp */
|
|
10736
|
-
createdAt:
|
|
11550
|
+
createdAt: import_zod9.z.string().optional()
|
|
10737
11551
|
});
|
|
10738
|
-
var ServerOwnedSpacesResponseSchema =
|
|
10739
|
-
var ServerCreateSpaceResponseSchema =
|
|
11552
|
+
var ServerOwnedSpacesResponseSchema = import_zod9.z.array(ServerOwnedSpaceSchema);
|
|
11553
|
+
var ServerCreateSpaceResponseSchema = import_zod9.z.object({
|
|
10740
11554
|
/** Space identifier */
|
|
10741
|
-
id:
|
|
11555
|
+
id: import_zod9.z.string(),
|
|
10742
11556
|
/** Space name */
|
|
10743
|
-
name:
|
|
11557
|
+
name: import_zod9.z.string(),
|
|
10744
11558
|
/** Owner DID */
|
|
10745
|
-
owner:
|
|
11559
|
+
owner: import_zod9.z.string(),
|
|
10746
11560
|
/** Creation timestamp */
|
|
10747
|
-
createdAt:
|
|
11561
|
+
createdAt: import_zod9.z.string().optional()
|
|
10748
11562
|
});
|
|
10749
|
-
var ServerSpaceInfoResponseSchema =
|
|
11563
|
+
var ServerSpaceInfoResponseSchema = import_zod9.z.object({
|
|
10750
11564
|
/** Space identifier */
|
|
10751
|
-
id:
|
|
11565
|
+
id: import_zod9.z.string(),
|
|
10752
11566
|
/** Space name (optional) */
|
|
10753
|
-
name:
|
|
11567
|
+
name: import_zod9.z.string().optional(),
|
|
10754
11568
|
/** Owner DID */
|
|
10755
|
-
owner:
|
|
11569
|
+
owner: import_zod9.z.string(),
|
|
10756
11570
|
/** Ownership type */
|
|
10757
|
-
type:
|
|
11571
|
+
type: import_zod9.z.enum(["owned", "delegated"]).optional(),
|
|
10758
11572
|
/** Permissions the user has in this space */
|
|
10759
|
-
permissions:
|
|
11573
|
+
permissions: import_zod9.z.array(import_zod9.z.string()).optional(),
|
|
10760
11574
|
/** Expiration for delegated access */
|
|
10761
|
-
expiresAt:
|
|
11575
|
+
expiresAt: import_zod9.z.string().optional()
|
|
10762
11576
|
});
|
|
10763
11577
|
function validateServerDelegationsResponse(data) {
|
|
10764
11578
|
if (data === null || data === void 0) {
|
|
@@ -12168,7 +12982,7 @@ var TinyCloud = class _TinyCloud {
|
|
|
12168
12982
|
|
|
12169
12983
|
// src/account/AccountService.ts
|
|
12170
12984
|
var import_sdk_services6 = require("@tinycloud/sdk-services");
|
|
12171
|
-
var
|
|
12985
|
+
var import_bootstrap3 = require("@tinycloud/bootstrap");
|
|
12172
12986
|
var SERVICE_NAME2 = "account";
|
|
12173
12987
|
var ACCOUNT_INDEX_DB = "account";
|
|
12174
12988
|
var ACCOUNT_INDEX_NAMESPACE = "tinycloud.account.index";
|
|
@@ -12959,7 +13773,7 @@ var AccountService = class {
|
|
|
12959
13773
|
migrations: [
|
|
12960
13774
|
{
|
|
12961
13775
|
id: "001_initial",
|
|
12962
|
-
sql: [...
|
|
13776
|
+
sql: [...import_bootstrap3.ACCOUNT_INDEX_SCHEMA]
|
|
12963
13777
|
}
|
|
12964
13778
|
]
|
|
12965
13779
|
});
|
|
@@ -13070,8 +13884,8 @@ function stableJson(value) {
|
|
|
13070
13884
|
if (Array.isArray(value)) {
|
|
13071
13885
|
return `[${value.map(stableJson).join(",")}]`;
|
|
13072
13886
|
}
|
|
13073
|
-
const
|
|
13074
|
-
return `{${Object.keys(
|
|
13887
|
+
const object2 = value;
|
|
13888
|
+
return `{${Object.keys(object2).sort().map((key) => `${JSON.stringify(key)}:${stableJson(object2[key])}`).join(",")}}`;
|
|
13075
13889
|
}
|
|
13076
13890
|
function indexedDelegationFromRow(row) {
|
|
13077
13891
|
const [
|
|
@@ -14088,7 +14902,7 @@ async function checkNodeInfo(host, sdkProtocol, fetchFn = globalThis.fetch.bind(
|
|
|
14088
14902
|
}
|
|
14089
14903
|
|
|
14090
14904
|
// src/index.ts
|
|
14091
|
-
var
|
|
14905
|
+
var import_bootstrap4 = require("@tinycloud/bootstrap");
|
|
14092
14906
|
|
|
14093
14907
|
// ../../node_modules/uint8arrays/dist/src/equals.js
|
|
14094
14908
|
function equals3(a, b) {
|
|
@@ -15739,7 +16553,7 @@ function portForProtocol(protocol) {
|
|
|
15739
16553
|
}
|
|
15740
16554
|
|
|
15741
16555
|
// src/location.ts
|
|
15742
|
-
var
|
|
16556
|
+
var import_ed255198 = require("@noble/curves/ed25519");
|
|
15743
16557
|
var import_viem5 = require("viem");
|
|
15744
16558
|
var DEFAULT_TINYCLOUD_LOCATION_REGISTRY_URL = "https://registry.tinycloud.xyz";
|
|
15745
16559
|
var DEFAULT_TINYCLOUD_FALLBACK_HOST = "https://node.tinycloud.xyz";
|
|
@@ -16305,13 +17119,13 @@ async function verifyPkhSignature(did, payload, signature) {
|
|
|
16305
17119
|
}
|
|
16306
17120
|
function verifyDidKeySignature(did, payload, signature) {
|
|
16307
17121
|
const publicKey = ed25519PublicKeyFromDidKey2(did);
|
|
16308
|
-
const signatureBytes =
|
|
17122
|
+
const signatureBytes = decodeBase64Url2(signature);
|
|
16309
17123
|
if (signatureBytes.length !== 64) {
|
|
16310
17124
|
throw new LocationRecordValidationError(
|
|
16311
17125
|
"did:key signature must be a base64url Ed25519 signature"
|
|
16312
17126
|
);
|
|
16313
17127
|
}
|
|
16314
|
-
return
|
|
17128
|
+
return import_ed255198.ed25519.verify(
|
|
16315
17129
|
signatureBytes,
|
|
16316
17130
|
new TextEncoder().encode(payload),
|
|
16317
17131
|
publicKey
|
|
@@ -16319,7 +17133,7 @@ function verifyDidKeySignature(did, payload, signature) {
|
|
|
16319
17133
|
}
|
|
16320
17134
|
function verifyDidKeyEd25519Signature(did, payload, signature) {
|
|
16321
17135
|
const publicKey = ed25519PublicKeyFromDidKey2(did);
|
|
16322
|
-
return
|
|
17136
|
+
return import_ed255198.ed25519.verify(signature, payload, publicKey);
|
|
16323
17137
|
}
|
|
16324
17138
|
function ed25519PublicKeyFromDidKey2(did) {
|
|
16325
17139
|
const identifier = did.slice("did:key:".length);
|
|
@@ -16358,7 +17172,7 @@ function base64UrlEncode3(bytes2) {
|
|
|
16358
17172
|
}
|
|
16359
17173
|
return output;
|
|
16360
17174
|
}
|
|
16361
|
-
function
|
|
17175
|
+
function decodeBase64Url2(value) {
|
|
16362
17176
|
const alphabet2 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
16363
17177
|
const bytes2 = [];
|
|
16364
17178
|
let buffer = 0;
|