@tinycloud/sdk-core 2.2.0-beta.7 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +374 -60
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +115 -32
- package/dist/index.d.ts +115 -32
- package/dist/index.js +340 -34
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -728,6 +728,23 @@ function validateServerSpaceInfoResponse(data) {
|
|
|
728
728
|
return { ok: true, data: result.data };
|
|
729
729
|
}
|
|
730
730
|
|
|
731
|
+
// src/expiry.ts
|
|
732
|
+
var EPHEMERAL_MS = 60 * 60 * 1e3;
|
|
733
|
+
var SIGNED_READ_URL_MS = 5 * 60 * 1e3;
|
|
734
|
+
var SESSION_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
735
|
+
var SHARE_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
736
|
+
var APP_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
737
|
+
var MAX_MS = 10 * 365 * 24 * 60 * 60 * 1e3;
|
|
738
|
+
var EXPIRY = {
|
|
739
|
+
EPHEMERAL_MS,
|
|
740
|
+
SIGNED_READ_URL_MS,
|
|
741
|
+
SESSION_MS,
|
|
742
|
+
SHARE_MS,
|
|
743
|
+
APP_MS,
|
|
744
|
+
MAX_MS
|
|
745
|
+
};
|
|
746
|
+
var DEFAULT_SIGNED_READ_URL_EXPIRY_MS = EXPIRY.SIGNED_READ_URL_MS;
|
|
747
|
+
|
|
731
748
|
// src/spaces/SpaceService.ts
|
|
732
749
|
var SERVICE_NAME = "space";
|
|
733
750
|
var SpaceErrorCodes = {
|
|
@@ -804,7 +821,7 @@ function transformServerDelegations(validatedData, defaultSpaceId) {
|
|
|
804
821
|
spaceId,
|
|
805
822
|
path,
|
|
806
823
|
actions,
|
|
807
|
-
expiry: info.expiry ? new Date(info.expiry) : new Date(Date.now() +
|
|
824
|
+
expiry: info.expiry ? new Date(info.expiry) : new Date(Date.now() + EXPIRY.SHARE_MS),
|
|
808
825
|
isRevoked: false,
|
|
809
826
|
createdAt: info.issued_at ? new Date(info.issued_at) : void 0,
|
|
810
827
|
parentCid: firstStringParent
|
|
@@ -1664,6 +1681,22 @@ var TinyCloud = class _TinyCloud {
|
|
|
1664
1681
|
}
|
|
1665
1682
|
return service;
|
|
1666
1683
|
}
|
|
1684
|
+
/**
|
|
1685
|
+
* Get the Encryption service.
|
|
1686
|
+
* @throws Error if services are not initialized or encryption service is not registered
|
|
1687
|
+
*/
|
|
1688
|
+
get encryption() {
|
|
1689
|
+
if (!this._servicesInitialized) {
|
|
1690
|
+
throw new Error(
|
|
1691
|
+
"Services not initialized. Call initializeServices() first, or use TinyCloudWeb/TinyCloudNode which handles this automatically."
|
|
1692
|
+
);
|
|
1693
|
+
}
|
|
1694
|
+
const service = this._services.get("encryption");
|
|
1695
|
+
if (!service) {
|
|
1696
|
+
throw new Error("Encryption service is not registered.");
|
|
1697
|
+
}
|
|
1698
|
+
return service;
|
|
1699
|
+
}
|
|
1667
1700
|
/**
|
|
1668
1701
|
* Notify services of session change.
|
|
1669
1702
|
* Called internally after sign-in and sign-out.
|
|
@@ -2019,7 +2052,51 @@ import {
|
|
|
2019
2052
|
VaultHeaders,
|
|
2020
2053
|
VaultPublicSpaceKVActions,
|
|
2021
2054
|
createVaultCrypto,
|
|
2022
|
-
SecretsService
|
|
2055
|
+
SecretsService,
|
|
2056
|
+
SECRET_NAME_RE as SECRET_NAME_RE2,
|
|
2057
|
+
canonicalizeSecretScope,
|
|
2058
|
+
resolveSecretListPrefix,
|
|
2059
|
+
resolveSecretPath as resolveSecretPath2,
|
|
2060
|
+
EncryptionService,
|
|
2061
|
+
parseNetworkId,
|
|
2062
|
+
buildNetworkId,
|
|
2063
|
+
isNetworkId,
|
|
2064
|
+
networkDiscoveryKey,
|
|
2065
|
+
NetworkIdError,
|
|
2066
|
+
ENCRYPTION_NETWORK_URN_PREFIX,
|
|
2067
|
+
NETWORK_NAME_PATTERN,
|
|
2068
|
+
canonicalizeEncryptionJson,
|
|
2069
|
+
canonicalHashHex,
|
|
2070
|
+
hexEncode,
|
|
2071
|
+
hexDecode,
|
|
2072
|
+
base64Encode,
|
|
2073
|
+
base64Decode,
|
|
2074
|
+
utf8Encode,
|
|
2075
|
+
utf8Decode,
|
|
2076
|
+
encryptToNetwork,
|
|
2077
|
+
decryptEnvelopeWithKey,
|
|
2078
|
+
validateEnvelope,
|
|
2079
|
+
generateRandomReceiverKey,
|
|
2080
|
+
deriveSignedReceiverKey,
|
|
2081
|
+
buildCanonicalDecryptRequest,
|
|
2082
|
+
buildDecryptFacts,
|
|
2083
|
+
buildDecryptAttenuation,
|
|
2084
|
+
buildDecryptInvocation,
|
|
2085
|
+
checkDecryptInvocationInput,
|
|
2086
|
+
verifyDecryptResponse,
|
|
2087
|
+
canonicalSignedResponse,
|
|
2088
|
+
openWrappedKey,
|
|
2089
|
+
discoverNetwork,
|
|
2090
|
+
ensureNetworkUsableForDecrypt,
|
|
2091
|
+
DEFAULT_ENCRYPTION_ALG,
|
|
2092
|
+
ENVELOPE_VERSION,
|
|
2093
|
+
DEFAULT_KEY_VERSION,
|
|
2094
|
+
DECRYPT_FACT_TYPE,
|
|
2095
|
+
DECRYPT_RESULT_TYPE,
|
|
2096
|
+
DECRYPT_ACTION,
|
|
2097
|
+
ENCRYPTION_SERVICE,
|
|
2098
|
+
ENCRYPTION_SERVICE_SHORT,
|
|
2099
|
+
encryptionError
|
|
2023
2100
|
} from "@tinycloud/sdk-services";
|
|
2024
2101
|
|
|
2025
2102
|
// src/space.ts
|
|
@@ -2209,7 +2286,7 @@ var DelegationManager = class {
|
|
|
2209
2286
|
spaceId: this.session.spaceId,
|
|
2210
2287
|
path: params.path,
|
|
2211
2288
|
actions: params.actions,
|
|
2212
|
-
expiry: params.expiry ?? new Date(Date.now() +
|
|
2289
|
+
expiry: params.expiry ?? new Date(Date.now() + EXPIRY.SHARE_MS),
|
|
2213
2290
|
isRevoked: false,
|
|
2214
2291
|
allowSubDelegation: !(params.disableSubDelegation ?? false),
|
|
2215
2292
|
createdAt: /* @__PURE__ */ new Date()
|
|
@@ -2688,6 +2765,7 @@ function validateEncodedShareData(data) {
|
|
|
2688
2765
|
|
|
2689
2766
|
// src/manifest.ts
|
|
2690
2767
|
import ms from "ms";
|
|
2768
|
+
import { resolveSecretPath, SECRET_NAME_RE } from "@tinycloud/sdk-services";
|
|
2691
2769
|
var ManifestValidationError = class extends Error {
|
|
2692
2770
|
constructor(message) {
|
|
2693
2771
|
super(`Manifest validation failed: ${message}`);
|
|
@@ -2701,14 +2779,17 @@ var DEFAULT_MANIFEST_SPACE = "applications";
|
|
|
2701
2779
|
var ACCOUNT_REGISTRY_SPACE = "account";
|
|
2702
2780
|
var ACCOUNT_REGISTRY_PATH = "applications/";
|
|
2703
2781
|
var SECRETS_SPACE = "secrets";
|
|
2704
|
-
var
|
|
2782
|
+
var VAULT_PERMISSION_SERVICE = "tinycloud.vault";
|
|
2705
2783
|
var SERVICE_SHORT_TO_LONG = Object.freeze({
|
|
2706
2784
|
kv: "tinycloud.kv",
|
|
2707
2785
|
sql: "tinycloud.sql",
|
|
2708
2786
|
duckdb: "tinycloud.duckdb",
|
|
2709
2787
|
capabilities: "tinycloud.capabilities",
|
|
2710
|
-
hooks: "tinycloud.hooks"
|
|
2788
|
+
hooks: "tinycloud.hooks",
|
|
2789
|
+
encryption: "tinycloud.encryption"
|
|
2711
2790
|
});
|
|
2791
|
+
var ENCRYPTION_PERMISSION_SERVICE = "tinycloud.encryption";
|
|
2792
|
+
var ENCRYPTION_MANIFEST_SPACE = "encryption";
|
|
2712
2793
|
var SERVICE_LONG_TO_SHORT = Object.freeze(
|
|
2713
2794
|
Object.fromEntries(
|
|
2714
2795
|
Object.entries(SERVICE_SHORT_TO_LONG).map(([s, l]) => [l, s])
|
|
@@ -2784,6 +2865,72 @@ function expandActionShortNames(service, actions) {
|
|
|
2784
2865
|
return `${service}/${a}`;
|
|
2785
2866
|
});
|
|
2786
2867
|
}
|
|
2868
|
+
function expandPermissionEntry(entry) {
|
|
2869
|
+
if (entry.service === ENCRYPTION_PERMISSION_SERVICE) {
|
|
2870
|
+
return expandEncryptionPermissionEntry(entry);
|
|
2871
|
+
}
|
|
2872
|
+
if (entry.service !== VAULT_PERMISSION_SERVICE) {
|
|
2873
|
+
return [
|
|
2874
|
+
{
|
|
2875
|
+
...entry,
|
|
2876
|
+
actions: expandActionShortNames(entry.service, entry.actions)
|
|
2877
|
+
}
|
|
2878
|
+
];
|
|
2879
|
+
}
|
|
2880
|
+
return expandVaultPermissionEntry(entry);
|
|
2881
|
+
}
|
|
2882
|
+
function expandEncryptionPermissionEntry(entry) {
|
|
2883
|
+
if (typeof entry.path !== "string" || !entry.path.startsWith("urn:tinycloud:encryption:")) {
|
|
2884
|
+
throw new ManifestValidationError(
|
|
2885
|
+
`tinycloud.encryption entries require path to be a networkId URN (got ${JSON.stringify(entry.path)})`
|
|
2886
|
+
);
|
|
2887
|
+
}
|
|
2888
|
+
const normalizedActions = [];
|
|
2889
|
+
for (const action of entry.actions) {
|
|
2890
|
+
if (action === "decrypt" || action === "tinycloud.encryption/decrypt") {
|
|
2891
|
+
normalizedActions.push("tinycloud.encryption/decrypt");
|
|
2892
|
+
continue;
|
|
2893
|
+
}
|
|
2894
|
+
if (action === "network.create" || action === "tinycloud.encryption/network.create") {
|
|
2895
|
+
normalizedActions.push("tinycloud.encryption/network.create");
|
|
2896
|
+
continue;
|
|
2897
|
+
}
|
|
2898
|
+
if (action === "network.revoke" || action === "tinycloud.encryption/network.revoke") {
|
|
2899
|
+
normalizedActions.push("tinycloud.encryption/network.revoke");
|
|
2900
|
+
continue;
|
|
2901
|
+
}
|
|
2902
|
+
if (action.includes("/")) {
|
|
2903
|
+
throw new ManifestValidationError(
|
|
2904
|
+
`unknown encryption action ${JSON.stringify(action)}; expected decrypt, network.create, or network.revoke`
|
|
2905
|
+
);
|
|
2906
|
+
}
|
|
2907
|
+
throw new ManifestValidationError(
|
|
2908
|
+
`unknown encryption action ${JSON.stringify(action)}; expected decrypt, network.create, or network.revoke`
|
|
2909
|
+
);
|
|
2910
|
+
}
|
|
2911
|
+
const dedupedActions = [];
|
|
2912
|
+
const seen = /* @__PURE__ */ new Set();
|
|
2913
|
+
for (const a of normalizedActions) {
|
|
2914
|
+
if (!seen.has(a)) {
|
|
2915
|
+
dedupedActions.push(a);
|
|
2916
|
+
seen.add(a);
|
|
2917
|
+
}
|
|
2918
|
+
}
|
|
2919
|
+
return [
|
|
2920
|
+
{
|
|
2921
|
+
service: ENCRYPTION_PERMISSION_SERVICE,
|
|
2922
|
+
space: ENCRYPTION_MANIFEST_SPACE,
|
|
2923
|
+
path: entry.path,
|
|
2924
|
+
actions: dedupedActions,
|
|
2925
|
+
skipPrefix: true,
|
|
2926
|
+
...entry.expiry !== void 0 ? { expiry: entry.expiry } : {},
|
|
2927
|
+
...entry.description !== void 0 ? { description: entry.description } : {}
|
|
2928
|
+
}
|
|
2929
|
+
];
|
|
2930
|
+
}
|
|
2931
|
+
function expandPermissionEntries(entries) {
|
|
2932
|
+
return entries.flatMap(expandPermissionEntry);
|
|
2933
|
+
}
|
|
2787
2934
|
function applyPrefix(prefix, path, skipPrefix) {
|
|
2788
2935
|
if (skipPrefix) {
|
|
2789
2936
|
return path;
|
|
@@ -2870,6 +3017,16 @@ function validateManifestSecrets(secrets) {
|
|
|
2870
3017
|
`manifest.secrets.${name} must match ${SECRET_NAME_RE.source}`
|
|
2871
3018
|
);
|
|
2872
3019
|
}
|
|
3020
|
+
try {
|
|
3021
|
+
resolveSecretPath(
|
|
3022
|
+
secretNameFromSpec(name, spec),
|
|
3023
|
+
{ scope: secretScopeFromSpec(spec) }
|
|
3024
|
+
);
|
|
3025
|
+
} catch (error) {
|
|
3026
|
+
throw new ManifestValidationError(
|
|
3027
|
+
`manifest.secrets.${name}: ${error instanceof Error ? error.message : String(error)}`
|
|
3028
|
+
);
|
|
3029
|
+
}
|
|
2873
3030
|
const actions = secretActionsFromSpec(name, spec);
|
|
2874
3031
|
if (actions.length === 0) {
|
|
2875
3032
|
throw new ManifestValidationError(
|
|
@@ -2911,6 +3068,16 @@ function validatePermissionEntry(p, path) {
|
|
|
2911
3068
|
`${path}.actions must be a non-empty array`
|
|
2912
3069
|
);
|
|
2913
3070
|
}
|
|
3071
|
+
for (const action of entry.actions) {
|
|
3072
|
+
if (typeof action !== "string" || action.length === 0) {
|
|
3073
|
+
throw new ManifestValidationError(
|
|
3074
|
+
`${path}.actions must contain non-empty strings`
|
|
3075
|
+
);
|
|
3076
|
+
}
|
|
3077
|
+
if (entry.service === VAULT_PERMISSION_SERVICE) {
|
|
3078
|
+
vaultActionExpansion(action);
|
|
3079
|
+
}
|
|
3080
|
+
}
|
|
2914
3081
|
if (entry.expiry !== void 0) {
|
|
2915
3082
|
parseExpiry(entry.expiry);
|
|
2916
3083
|
}
|
|
@@ -2960,7 +3127,7 @@ function resolveManifest(input) {
|
|
|
2960
3127
|
...secretEntries
|
|
2961
3128
|
];
|
|
2962
3129
|
const resources = withCapabilitiesReadForSpaces(
|
|
2963
|
-
allEntries.
|
|
3130
|
+
allEntries.flatMap((entry) => resolveEntry(entry, prefix, expiryMs, space))
|
|
2964
3131
|
);
|
|
2965
3132
|
const additionalDelegates = manifest.did === void 0 ? [] : [
|
|
2966
3133
|
{
|
|
@@ -3016,6 +3183,18 @@ function normalizeSecretActions(actions) {
|
|
|
3016
3183
|
}
|
|
3017
3184
|
return out;
|
|
3018
3185
|
}
|
|
3186
|
+
function secretNameFromSpec(fallbackName, spec) {
|
|
3187
|
+
if (spec !== null && typeof spec === "object" && !Array.isArray(spec)) {
|
|
3188
|
+
return spec.name ?? fallbackName;
|
|
3189
|
+
}
|
|
3190
|
+
return fallbackName;
|
|
3191
|
+
}
|
|
3192
|
+
function secretScopeFromSpec(spec) {
|
|
3193
|
+
if (spec !== null && typeof spec === "object" && !Array.isArray(spec)) {
|
|
3194
|
+
return spec.scope;
|
|
3195
|
+
}
|
|
3196
|
+
return void 0;
|
|
3197
|
+
}
|
|
3019
3198
|
function secretActionsFromSpec(name, spec) {
|
|
3020
3199
|
if (spec === true) {
|
|
3021
3200
|
return ["read"];
|
|
@@ -3051,40 +3230,105 @@ function secretEntriesForManifest(secrets) {
|
|
|
3051
3230
|
const entries = [];
|
|
3052
3231
|
for (const [name, spec] of Object.entries(secrets)) {
|
|
3053
3232
|
const actions = secretActionsFromSpec(name, spec);
|
|
3233
|
+
const secretPath = resolveSecretPath(
|
|
3234
|
+
secretNameFromSpec(name, spec),
|
|
3235
|
+
{ scope: secretScopeFromSpec(spec) }
|
|
3236
|
+
);
|
|
3054
3237
|
const extra = spec !== true && typeof spec === "object" && !Array.isArray(spec) ? spec : {};
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
});
|
|
3065
|
-
}
|
|
3238
|
+
entries.push({
|
|
3239
|
+
service: VAULT_PERMISSION_SERVICE,
|
|
3240
|
+
space: SECRETS_SPACE,
|
|
3241
|
+
path: secretPath.vaultKey,
|
|
3242
|
+
actions: normalizeSecretActions(actions),
|
|
3243
|
+
skipPrefix: true,
|
|
3244
|
+
...extra.expiry !== void 0 ? { expiry: extra.expiry } : {},
|
|
3245
|
+
...extra.description !== void 0 ? { description: extra.description } : {}
|
|
3246
|
+
});
|
|
3066
3247
|
}
|
|
3067
3248
|
return entries;
|
|
3068
3249
|
}
|
|
3069
3250
|
function resolveEntry(entry, prefix, _inheritedExpiryMs, inheritedSpace) {
|
|
3070
|
-
const
|
|
3071
|
-
|
|
3072
|
-
entry.path,
|
|
3073
|
-
entry.skipPrefix === true
|
|
3074
|
-
);
|
|
3075
|
-
const resolvedActions = expandActionShortNames(entry.service, entry.actions);
|
|
3251
|
+
const skipPrefixForEntry = entry.skipPrefix === true || entry.service === ENCRYPTION_PERMISSION_SERVICE;
|
|
3252
|
+
const resolvedPath = applyPrefix(prefix, entry.path, skipPrefixForEntry);
|
|
3076
3253
|
const entryExpiryMs = entry.expiry !== void 0 ? parseExpiry(entry.expiry) : void 0;
|
|
3077
|
-
return {
|
|
3078
|
-
|
|
3254
|
+
return expandPermissionEntry({
|
|
3255
|
+
...entry,
|
|
3079
3256
|
space: entry.space ?? inheritedSpace,
|
|
3080
3257
|
path: resolvedPath,
|
|
3081
|
-
|
|
3258
|
+
skipPrefix: true
|
|
3259
|
+
}).map((expanded) => ({
|
|
3260
|
+
service: expanded.service,
|
|
3261
|
+
space: expanded.space ?? inheritedSpace,
|
|
3262
|
+
path: expanded.path,
|
|
3263
|
+
actions: expanded.actions,
|
|
3082
3264
|
// Only populate `expiryMs` when the entry had its own expiry override.
|
|
3083
3265
|
// When absent, callers use the parent (delegation or manifest) expiry
|
|
3084
3266
|
// which is carried on ResolvedDelegate.expiryMs / ResolvedCapabilities.expiryMs.
|
|
3085
3267
|
...entryExpiryMs !== void 0 ? { expiryMs: entryExpiryMs } : {},
|
|
3086
3268
|
...entry.description !== void 0 ? { description: entry.description } : {}
|
|
3087
|
-
};
|
|
3269
|
+
}));
|
|
3270
|
+
}
|
|
3271
|
+
function expandVaultPermissionEntry(entry) {
|
|
3272
|
+
const byBase = /* @__PURE__ */ new Map();
|
|
3273
|
+
for (const action of entry.actions) {
|
|
3274
|
+
const expansion = vaultActionExpansion(action);
|
|
3275
|
+
for (const base of expansion.bases) {
|
|
3276
|
+
const actions = byBase.get(base) ?? [];
|
|
3277
|
+
if (!actions.includes(expansion.action)) {
|
|
3278
|
+
actions.push(expansion.action);
|
|
3279
|
+
}
|
|
3280
|
+
byBase.set(base, actions);
|
|
3281
|
+
}
|
|
3282
|
+
}
|
|
3283
|
+
return [...byBase.entries()].map(([base, actions]) => ({
|
|
3284
|
+
...entry,
|
|
3285
|
+
service: "tinycloud.kv",
|
|
3286
|
+
path: vaultKVPath(base, entry.path),
|
|
3287
|
+
actions,
|
|
3288
|
+
skipPrefix: true
|
|
3289
|
+
}));
|
|
3290
|
+
}
|
|
3291
|
+
function vaultActionExpansion(action) {
|
|
3292
|
+
const normalized = normalizeVaultAction(action);
|
|
3293
|
+
if (normalized === "read" || normalized === "get") {
|
|
3294
|
+
return { bases: ["vault"], action: "tinycloud.kv/get" };
|
|
3295
|
+
}
|
|
3296
|
+
if (normalized === "write" || normalized === "put") {
|
|
3297
|
+
return { bases: ["vault"], action: "tinycloud.kv/put" };
|
|
3298
|
+
}
|
|
3299
|
+
if (normalized === "delete" || normalized === "del") {
|
|
3300
|
+
return { bases: ["vault"], action: "tinycloud.kv/del" };
|
|
3301
|
+
}
|
|
3302
|
+
if (normalized === "list") {
|
|
3303
|
+
return { bases: ["vault"], action: "tinycloud.kv/list" };
|
|
3304
|
+
}
|
|
3305
|
+
if (normalized === "head") {
|
|
3306
|
+
return { bases: ["vault"], action: "tinycloud.kv/get" };
|
|
3307
|
+
}
|
|
3308
|
+
if (normalized === "metadata") {
|
|
3309
|
+
return { bases: ["vault"], action: "tinycloud.kv/metadata" };
|
|
3310
|
+
}
|
|
3311
|
+
throw new ManifestValidationError(
|
|
3312
|
+
`unknown vault action ${JSON.stringify(action)}; expected read, write, delete, get, put, del, list, head, or metadata`
|
|
3313
|
+
);
|
|
3314
|
+
}
|
|
3315
|
+
function normalizeVaultAction(action) {
|
|
3316
|
+
if (action.startsWith(`${VAULT_PERMISSION_SERVICE}/`)) {
|
|
3317
|
+
return action.slice(`${VAULT_PERMISSION_SERVICE}/`.length);
|
|
3318
|
+
}
|
|
3319
|
+
if (action.startsWith("tinycloud.kv/")) {
|
|
3320
|
+
return action.slice("tinycloud.kv/".length);
|
|
3321
|
+
}
|
|
3322
|
+
if (action.includes("/")) {
|
|
3323
|
+
throw new ManifestValidationError(
|
|
3324
|
+
`unknown vault action ${JSON.stringify(action)}; expected a tinycloud.vault or tinycloud.kv action`
|
|
3325
|
+
);
|
|
3326
|
+
}
|
|
3327
|
+
return action;
|
|
3328
|
+
}
|
|
3329
|
+
function vaultKVPath(base, path) {
|
|
3330
|
+
const normalized = path.startsWith("/") ? path.slice(1) : path;
|
|
3331
|
+
return `${base}/${normalized}`;
|
|
3088
3332
|
}
|
|
3089
3333
|
function cloneResourceCapability(entry) {
|
|
3090
3334
|
return {
|
|
@@ -3141,7 +3385,9 @@ function withCapabilitiesReadForSpaces(resources) {
|
|
|
3141
3385
|
if (resources.length === 0) {
|
|
3142
3386
|
return [];
|
|
3143
3387
|
}
|
|
3144
|
-
const spaces = new Set(
|
|
3388
|
+
const spaces = new Set(
|
|
3389
|
+
resources.filter((resource) => resource.service !== ENCRYPTION_PERMISSION_SERVICE).map((resource) => resource.space)
|
|
3390
|
+
);
|
|
3145
3391
|
return dedupeResources([
|
|
3146
3392
|
...resources,
|
|
3147
3393
|
...[...spaces].map(capabilitiesReadPermission)
|
|
@@ -3273,7 +3519,7 @@ function inferShortServiceFromActionUrns(actions) {
|
|
|
3273
3519
|
return short;
|
|
3274
3520
|
}
|
|
3275
3521
|
var DEFAULT_READ_ACTIONS = ["tinycloud.kv/get", "tinycloud.kv/metadata"];
|
|
3276
|
-
var DEFAULT_EXPIRY_MS =
|
|
3522
|
+
var DEFAULT_EXPIRY_MS = EXPIRY.SHARE_MS;
|
|
3277
3523
|
var BASE64_PREFIX = "tc1:";
|
|
3278
3524
|
function createError2(code, message, cause, meta) {
|
|
3279
3525
|
return {
|
|
@@ -4402,6 +4648,7 @@ async function checkNodeInfo(host, sdkProtocol, fetchFn = globalThis.fetch.bind(
|
|
|
4402
4648
|
}
|
|
4403
4649
|
return {
|
|
4404
4650
|
features: data.features ?? [],
|
|
4651
|
+
nodeId: data.nodeId,
|
|
4405
4652
|
quotaUrl: data.quota_url
|
|
4406
4653
|
};
|
|
4407
4654
|
}
|
|
@@ -4738,6 +4985,10 @@ function verifyDidKeySignature(did, payload, signature) {
|
|
|
4738
4985
|
publicKey
|
|
4739
4986
|
);
|
|
4740
4987
|
}
|
|
4988
|
+
function verifyDidKeyEd25519Signature(did, payload, signature) {
|
|
4989
|
+
const publicKey = ed25519PublicKeyFromDidKey(did);
|
|
4990
|
+
return ed25519.verify(signature, payload, publicKey);
|
|
4991
|
+
}
|
|
4741
4992
|
function ed25519PublicKeyFromDidKey(did) {
|
|
4742
4993
|
const identifier = did.slice("did:key:".length);
|
|
4743
4994
|
if (!identifier.startsWith("z")) {
|
|
@@ -4746,12 +4997,15 @@ function ed25519PublicKeyFromDidKey(did) {
|
|
|
4746
4997
|
);
|
|
4747
4998
|
}
|
|
4748
4999
|
const bytes = bases.base58btc.decode(identifier);
|
|
4749
|
-
if (bytes.length
|
|
4750
|
-
|
|
4751
|
-
"did:key must be an Ed25519 public key"
|
|
4752
|
-
);
|
|
5000
|
+
if (bytes.length === 34 && bytes[0] === 237 && bytes[1] === 1) {
|
|
5001
|
+
return bytes.slice(2);
|
|
4753
5002
|
}
|
|
4754
|
-
|
|
5003
|
+
if (bytes.length === 33 && bytes[0] === 237) {
|
|
5004
|
+
return bytes.slice(1);
|
|
5005
|
+
}
|
|
5006
|
+
throw new LocationRecordValidationError(
|
|
5007
|
+
"did:key must be an Ed25519 public key"
|
|
5008
|
+
);
|
|
4755
5009
|
}
|
|
4756
5010
|
function base64UrlEncode2(bytes) {
|
|
4757
5011
|
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
@@ -4915,10 +5169,16 @@ export {
|
|
|
4915
5169
|
CapabilityKeyRegistryErrorCodes,
|
|
4916
5170
|
ClientSessionSchema,
|
|
4917
5171
|
CloudLocationResolutionError,
|
|
5172
|
+
DECRYPT_ACTION,
|
|
5173
|
+
DECRYPT_FACT_TYPE,
|
|
5174
|
+
DECRYPT_RESULT_TYPE,
|
|
4918
5175
|
DEFAULT_DEFAULTS,
|
|
5176
|
+
DEFAULT_ENCRYPTION_ALG,
|
|
4919
5177
|
DEFAULT_EXPIRY,
|
|
5178
|
+
DEFAULT_KEY_VERSION,
|
|
4920
5179
|
DEFAULT_MANIFEST_SPACE,
|
|
4921
5180
|
DEFAULT_MANIFEST_VERSION,
|
|
5181
|
+
DEFAULT_SIGNED_READ_URL_EXPIRY_MS,
|
|
4922
5182
|
DEFAULT_TINYCLOUD_FALLBACK_HOST,
|
|
4923
5183
|
DEFAULT_TINYCLOUD_LOCATION_REGISTRY_URL,
|
|
4924
5184
|
DataVaultService,
|
|
@@ -4928,15 +5188,26 @@ export {
|
|
|
4928
5188
|
DuckDbAction,
|
|
4929
5189
|
DuckDbDatabaseHandle,
|
|
4930
5190
|
DuckDbService2 as DuckDbService,
|
|
5191
|
+
ENCRYPTION_MANIFEST_SPACE,
|
|
5192
|
+
ENCRYPTION_NETWORK_URN_PREFIX,
|
|
5193
|
+
ENCRYPTION_PERMISSION_SERVICE,
|
|
5194
|
+
ENCRYPTION_SERVICE,
|
|
5195
|
+
ENCRYPTION_SERVICE_SHORT,
|
|
5196
|
+
ENVELOPE_VERSION,
|
|
5197
|
+
EXPIRY,
|
|
5198
|
+
EncryptionService,
|
|
4931
5199
|
EnsDataSchema,
|
|
4932
5200
|
ErrorCodes2 as ErrorCodes,
|
|
4933
5201
|
HooksService2 as HooksService,
|
|
4934
5202
|
KVService2 as KVService,
|
|
4935
5203
|
LocationRecordValidationError,
|
|
4936
5204
|
ManifestValidationError,
|
|
5205
|
+
NETWORK_NAME_PATTERN,
|
|
5206
|
+
NetworkIdError,
|
|
4937
5207
|
PermissionNotInManifestError,
|
|
4938
5208
|
PrefixedKVService,
|
|
4939
5209
|
ProtocolMismatchError,
|
|
5210
|
+
SECRET_NAME_RE2 as SECRET_NAME_RE,
|
|
4940
5211
|
SERVICE_LONG_TO_SHORT,
|
|
4941
5212
|
SERVICE_SHORT_TO_LONG,
|
|
4942
5213
|
SQLAction,
|
|
@@ -4953,40 +5224,72 @@ export {
|
|
|
4953
5224
|
SpaceService,
|
|
4954
5225
|
TinyCloud,
|
|
4955
5226
|
UnsupportedFeatureError,
|
|
5227
|
+
VAULT_PERMISSION_SERVICE,
|
|
4956
5228
|
VaultHeaders,
|
|
4957
5229
|
VaultPublicSpaceKVActions,
|
|
4958
5230
|
VersionCheckError,
|
|
4959
5231
|
activateSessionWithHost,
|
|
4960
5232
|
applyPrefix,
|
|
5233
|
+
buildCanonicalDecryptRequest,
|
|
5234
|
+
buildDecryptAttenuation,
|
|
5235
|
+
buildDecryptFacts,
|
|
5236
|
+
buildDecryptInvocation,
|
|
5237
|
+
buildNetworkId,
|
|
4961
5238
|
buildSpaceUri,
|
|
5239
|
+
canonicalHashHex,
|
|
4962
5240
|
canonicalLocationPayload,
|
|
5241
|
+
canonicalSignedResponse,
|
|
5242
|
+
canonicalizeEncryptionJson,
|
|
5243
|
+
canonicalizeSecretScope,
|
|
5244
|
+
checkDecryptInvocationInput,
|
|
4963
5245
|
checkNodeInfo,
|
|
4964
5246
|
composeManifestRequest,
|
|
4965
5247
|
createCapabilityKeyRegistry,
|
|
4966
5248
|
createSharingService,
|
|
4967
5249
|
createSpaceService,
|
|
4968
5250
|
createVaultCrypto,
|
|
5251
|
+
decryptEnvelopeWithKey,
|
|
4969
5252
|
defaultRetryPolicy2 as defaultRetryPolicy,
|
|
4970
5253
|
defaultSignStrategy,
|
|
4971
5254
|
defaultSpaceCreationHandler,
|
|
5255
|
+
deriveSignedReceiverKey,
|
|
5256
|
+
discoverNetwork,
|
|
5257
|
+
encryptToNetwork,
|
|
5258
|
+
base64Decode as encryptionBase64Decode,
|
|
5259
|
+
base64Encode as encryptionBase64Encode,
|
|
5260
|
+
encryptionError,
|
|
5261
|
+
utf8Decode as encryptionUtf8Decode,
|
|
5262
|
+
utf8Encode as encryptionUtf8Encode,
|
|
5263
|
+
ensureNetworkUsableForDecrypt,
|
|
4972
5264
|
err4 as err,
|
|
4973
5265
|
expandActionShortNames,
|
|
5266
|
+
expandPermissionEntries,
|
|
5267
|
+
expandPermissionEntry,
|
|
4974
5268
|
fetchLocationRecord,
|
|
4975
5269
|
fetchPeerId,
|
|
5270
|
+
generateRandomReceiverKey,
|
|
5271
|
+
hexDecode,
|
|
5272
|
+
hexEncode,
|
|
4976
5273
|
httpUrlToMultiaddr,
|
|
4977
5274
|
isCapabilitySubset,
|
|
5275
|
+
isNetworkId,
|
|
4978
5276
|
loadManifest,
|
|
4979
5277
|
locationPayloadForRecord,
|
|
4980
5278
|
makePublicSpaceId,
|
|
4981
5279
|
manifestAbilitiesUnion,
|
|
4982
5280
|
multiaddrToHttpUrl,
|
|
5281
|
+
networkDiscoveryKey,
|
|
4983
5282
|
normalizeDefaults,
|
|
4984
5283
|
ok4 as ok,
|
|
5284
|
+
openWrappedKey,
|
|
4985
5285
|
parseExpiry,
|
|
5286
|
+
parseNetworkId,
|
|
4986
5287
|
parseRecapCapabilities,
|
|
4987
5288
|
parseSpaceUri,
|
|
4988
5289
|
resolveCloudLocation,
|
|
4989
5290
|
resolveManifest,
|
|
5291
|
+
resolveSecretListPrefix,
|
|
5292
|
+
resolveSecretPath2 as resolveSecretPath,
|
|
4990
5293
|
resolveTinyCloudHosts,
|
|
4991
5294
|
resourceCapabilitiesToAbilitiesMap,
|
|
4992
5295
|
resourceCapabilitiesToSpaceAbilitiesMap,
|
|
@@ -4994,10 +5297,13 @@ export {
|
|
|
4994
5297
|
signLocationRecord,
|
|
4995
5298
|
submitHostDelegation,
|
|
4996
5299
|
validateClientSession,
|
|
5300
|
+
validateEnvelope,
|
|
4997
5301
|
validateLocationRecord,
|
|
4998
5302
|
validateLocationRecordPayload,
|
|
4999
5303
|
validateManifest,
|
|
5000
5304
|
validatePersistedSessionData,
|
|
5305
|
+
verifyDecryptResponse,
|
|
5306
|
+
verifyDidKeyEd25519Signature,
|
|
5001
5307
|
verifyLocationRecord
|
|
5002
5308
|
};
|
|
5003
5309
|
//# sourceMappingURL=index.js.map
|