@tinycloud/sdk-core 2.2.0-beta.9 → 2.2.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +274 -57
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +98 -34
- package/dist/index.d.ts +98 -34
- package/dist/index.js +243 -31
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -37,34 +37,51 @@ __export(index_exports, {
|
|
|
37
37
|
CapabilityKeyRegistryErrorCodes: () => CapabilityKeyRegistryErrorCodes,
|
|
38
38
|
ClientSessionSchema: () => ClientSessionSchema,
|
|
39
39
|
CloudLocationResolutionError: () => CloudLocationResolutionError,
|
|
40
|
+
DECRYPT_ACTION: () => import_sdk_services5.DECRYPT_ACTION,
|
|
41
|
+
DECRYPT_FACT_TYPE: () => import_sdk_services5.DECRYPT_FACT_TYPE,
|
|
42
|
+
DECRYPT_RESULT_TYPE: () => import_sdk_services5.DECRYPT_RESULT_TYPE,
|
|
40
43
|
DEFAULT_DEFAULTS: () => DEFAULT_DEFAULTS,
|
|
44
|
+
DEFAULT_ENCRYPTION_ALG: () => import_sdk_services5.DEFAULT_ENCRYPTION_ALG,
|
|
41
45
|
DEFAULT_EXPIRY: () => DEFAULT_EXPIRY,
|
|
46
|
+
DEFAULT_KEY_VERSION: () => import_sdk_services5.DEFAULT_KEY_VERSION,
|
|
42
47
|
DEFAULT_MANIFEST_SPACE: () => DEFAULT_MANIFEST_SPACE,
|
|
43
48
|
DEFAULT_MANIFEST_VERSION: () => DEFAULT_MANIFEST_VERSION,
|
|
49
|
+
DEFAULT_SIGNED_READ_URL_EXPIRY_MS: () => DEFAULT_SIGNED_READ_URL_EXPIRY_MS,
|
|
44
50
|
DEFAULT_TINYCLOUD_FALLBACK_HOST: () => DEFAULT_TINYCLOUD_FALLBACK_HOST,
|
|
45
51
|
DEFAULT_TINYCLOUD_LOCATION_REGISTRY_URL: () => DEFAULT_TINYCLOUD_LOCATION_REGISTRY_URL,
|
|
46
|
-
DataVaultService: () =>
|
|
47
|
-
DatabaseHandle: () =>
|
|
52
|
+
DataVaultService: () => import_sdk_services5.DataVaultService,
|
|
53
|
+
DatabaseHandle: () => import_sdk_services5.DatabaseHandle,
|
|
48
54
|
DelegationErrorCodes: () => DelegationErrorCodes,
|
|
49
55
|
DelegationManager: () => DelegationManager,
|
|
50
|
-
DuckDbAction: () =>
|
|
51
|
-
DuckDbDatabaseHandle: () =>
|
|
52
|
-
DuckDbService: () =>
|
|
56
|
+
DuckDbAction: () => import_sdk_services5.DuckDbAction,
|
|
57
|
+
DuckDbDatabaseHandle: () => import_sdk_services5.DuckDbDatabaseHandle,
|
|
58
|
+
DuckDbService: () => import_sdk_services5.DuckDbService,
|
|
59
|
+
ENCRYPTION_MANIFEST_SPACE: () => ENCRYPTION_MANIFEST_SPACE,
|
|
60
|
+
ENCRYPTION_NETWORK_URN_PREFIX: () => import_sdk_services5.ENCRYPTION_NETWORK_URN_PREFIX,
|
|
61
|
+
ENCRYPTION_PERMISSION_SERVICE: () => ENCRYPTION_PERMISSION_SERVICE,
|
|
62
|
+
ENCRYPTION_SERVICE: () => import_sdk_services5.ENCRYPTION_SERVICE,
|
|
63
|
+
ENCRYPTION_SERVICE_SHORT: () => import_sdk_services5.ENCRYPTION_SERVICE_SHORT,
|
|
64
|
+
ENVELOPE_VERSION: () => import_sdk_services5.ENVELOPE_VERSION,
|
|
65
|
+
EXPIRY: () => EXPIRY,
|
|
66
|
+
EncryptionService: () => import_sdk_services5.EncryptionService,
|
|
53
67
|
EnsDataSchema: () => EnsDataSchema,
|
|
54
|
-
ErrorCodes: () =>
|
|
55
|
-
HooksService: () =>
|
|
56
|
-
KVService: () =>
|
|
68
|
+
ErrorCodes: () => import_sdk_services5.ErrorCodes,
|
|
69
|
+
HooksService: () => import_sdk_services5.HooksService,
|
|
70
|
+
KVService: () => import_sdk_services5.KVService,
|
|
57
71
|
LocationRecordValidationError: () => LocationRecordValidationError,
|
|
58
72
|
ManifestValidationError: () => ManifestValidationError,
|
|
73
|
+
NETWORK_NAME_PATTERN: () => import_sdk_services5.NETWORK_NAME_PATTERN,
|
|
74
|
+
NetworkIdError: () => import_sdk_services5.NetworkIdError,
|
|
59
75
|
PermissionNotInManifestError: () => PermissionNotInManifestError,
|
|
60
|
-
PrefixedKVService: () =>
|
|
76
|
+
PrefixedKVService: () => import_sdk_services5.PrefixedKVService,
|
|
61
77
|
ProtocolMismatchError: () => ProtocolMismatchError,
|
|
78
|
+
SECRET_NAME_RE: () => import_sdk_services5.SECRET_NAME_RE,
|
|
62
79
|
SERVICE_LONG_TO_SHORT: () => SERVICE_LONG_TO_SHORT,
|
|
63
80
|
SERVICE_SHORT_TO_LONG: () => SERVICE_SHORT_TO_LONG,
|
|
64
|
-
SQLAction: () =>
|
|
65
|
-
SQLService: () =>
|
|
66
|
-
SecretsService: () =>
|
|
67
|
-
ServiceContext: () =>
|
|
81
|
+
SQLAction: () => import_sdk_services5.SQLAction,
|
|
82
|
+
SQLService: () => import_sdk_services5.SQLService,
|
|
83
|
+
SecretsService: () => import_sdk_services5.SecretsService,
|
|
84
|
+
ServiceContext: () => import_sdk_services5.ServiceContext,
|
|
68
85
|
SessionExpiredError: () => SessionExpiredError,
|
|
69
86
|
SharingService: () => SharingService,
|
|
70
87
|
SilentNotificationHandler: () => SilentNotificationHandler,
|
|
@@ -76,53 +93,85 @@ __export(index_exports, {
|
|
|
76
93
|
TinyCloud: () => TinyCloud,
|
|
77
94
|
UnsupportedFeatureError: () => UnsupportedFeatureError,
|
|
78
95
|
VAULT_PERMISSION_SERVICE: () => VAULT_PERMISSION_SERVICE,
|
|
79
|
-
VaultHeaders: () =>
|
|
80
|
-
VaultPublicSpaceKVActions: () =>
|
|
96
|
+
VaultHeaders: () => import_sdk_services5.VaultHeaders,
|
|
97
|
+
VaultPublicSpaceKVActions: () => import_sdk_services5.VaultPublicSpaceKVActions,
|
|
81
98
|
VersionCheckError: () => VersionCheckError,
|
|
82
99
|
activateSessionWithHost: () => activateSessionWithHost,
|
|
83
100
|
applyPrefix: () => applyPrefix,
|
|
101
|
+
buildCanonicalDecryptRequest: () => import_sdk_services5.buildCanonicalDecryptRequest,
|
|
102
|
+
buildDecryptAttenuation: () => import_sdk_services5.buildDecryptAttenuation,
|
|
103
|
+
buildDecryptFacts: () => import_sdk_services5.buildDecryptFacts,
|
|
104
|
+
buildDecryptInvocation: () => import_sdk_services5.buildDecryptInvocation,
|
|
105
|
+
buildNetworkId: () => import_sdk_services5.buildNetworkId,
|
|
84
106
|
buildSpaceUri: () => buildSpaceUri,
|
|
107
|
+
canonicalHashHex: () => import_sdk_services5.canonicalHashHex,
|
|
85
108
|
canonicalLocationPayload: () => canonicalLocationPayload,
|
|
109
|
+
canonicalSignedResponse: () => import_sdk_services5.canonicalSignedResponse,
|
|
110
|
+
canonicalizeEncryptionJson: () => import_sdk_services5.canonicalizeEncryptionJson,
|
|
111
|
+
canonicalizeSecretScope: () => import_sdk_services5.canonicalizeSecretScope,
|
|
112
|
+
checkDecryptInvocationInput: () => import_sdk_services5.checkDecryptInvocationInput,
|
|
86
113
|
checkNodeInfo: () => checkNodeInfo,
|
|
87
114
|
composeManifestRequest: () => composeManifestRequest,
|
|
88
115
|
createCapabilityKeyRegistry: () => createCapabilityKeyRegistry,
|
|
89
116
|
createSharingService: () => createSharingService,
|
|
90
117
|
createSpaceService: () => createSpaceService,
|
|
91
|
-
createVaultCrypto: () =>
|
|
92
|
-
|
|
118
|
+
createVaultCrypto: () => import_sdk_services5.createVaultCrypto,
|
|
119
|
+
decryptEnvelopeWithKey: () => import_sdk_services5.decryptEnvelopeWithKey,
|
|
120
|
+
defaultRetryPolicy: () => import_sdk_services5.defaultRetryPolicy,
|
|
93
121
|
defaultSignStrategy: () => defaultSignStrategy,
|
|
94
122
|
defaultSpaceCreationHandler: () => defaultSpaceCreationHandler,
|
|
95
|
-
|
|
123
|
+
deriveSignedReceiverKey: () => import_sdk_services5.deriveSignedReceiverKey,
|
|
124
|
+
discoverNetwork: () => import_sdk_services5.discoverNetwork,
|
|
125
|
+
encryptToNetwork: () => import_sdk_services5.encryptToNetwork,
|
|
126
|
+
encryptionBase64Decode: () => import_sdk_services5.base64Decode,
|
|
127
|
+
encryptionBase64Encode: () => import_sdk_services5.base64Encode,
|
|
128
|
+
encryptionError: () => import_sdk_services5.encryptionError,
|
|
129
|
+
encryptionUtf8Decode: () => import_sdk_services5.utf8Decode,
|
|
130
|
+
encryptionUtf8Encode: () => import_sdk_services5.utf8Encode,
|
|
131
|
+
ensureNetworkUsableForDecrypt: () => import_sdk_services5.ensureNetworkUsableForDecrypt,
|
|
132
|
+
err: () => import_sdk_services5.err,
|
|
96
133
|
expandActionShortNames: () => expandActionShortNames,
|
|
97
134
|
expandPermissionEntries: () => expandPermissionEntries,
|
|
98
135
|
expandPermissionEntry: () => expandPermissionEntry,
|
|
99
136
|
fetchLocationRecord: () => fetchLocationRecord,
|
|
100
137
|
fetchPeerId: () => fetchPeerId,
|
|
138
|
+
generateRandomReceiverKey: () => import_sdk_services5.generateRandomReceiverKey,
|
|
139
|
+
hexDecode: () => import_sdk_services5.hexDecode,
|
|
140
|
+
hexEncode: () => import_sdk_services5.hexEncode,
|
|
101
141
|
httpUrlToMultiaddr: () => httpUrlToMultiaddr,
|
|
102
142
|
isCapabilitySubset: () => isCapabilitySubset,
|
|
143
|
+
isNetworkId: () => import_sdk_services5.isNetworkId,
|
|
103
144
|
loadManifest: () => loadManifest,
|
|
104
145
|
locationPayloadForRecord: () => locationPayloadForRecord,
|
|
105
146
|
makePublicSpaceId: () => makePublicSpaceId,
|
|
106
147
|
manifestAbilitiesUnion: () => manifestAbilitiesUnion,
|
|
107
148
|
multiaddrToHttpUrl: () => multiaddrToHttpUrl,
|
|
149
|
+
networkDiscoveryKey: () => import_sdk_services5.networkDiscoveryKey,
|
|
108
150
|
normalizeDefaults: () => normalizeDefaults,
|
|
109
|
-
ok: () =>
|
|
151
|
+
ok: () => import_sdk_services5.ok,
|
|
152
|
+
openWrappedKey: () => import_sdk_services5.openWrappedKey,
|
|
110
153
|
parseExpiry: () => parseExpiry,
|
|
154
|
+
parseNetworkId: () => import_sdk_services5.parseNetworkId,
|
|
111
155
|
parseRecapCapabilities: () => parseRecapCapabilities,
|
|
112
156
|
parseSpaceUri: () => parseSpaceUri,
|
|
113
157
|
resolveCloudLocation: () => resolveCloudLocation,
|
|
114
158
|
resolveManifest: () => resolveManifest,
|
|
159
|
+
resolveSecretListPrefix: () => import_sdk_services5.resolveSecretListPrefix,
|
|
160
|
+
resolveSecretPath: () => import_sdk_services5.resolveSecretPath,
|
|
115
161
|
resolveTinyCloudHosts: () => resolveTinyCloudHosts,
|
|
116
162
|
resourceCapabilitiesToAbilitiesMap: () => resourceCapabilitiesToAbilitiesMap,
|
|
117
163
|
resourceCapabilitiesToSpaceAbilitiesMap: () => resourceCapabilitiesToSpaceAbilitiesMap,
|
|
118
|
-
serviceError: () =>
|
|
164
|
+
serviceError: () => import_sdk_services5.serviceError,
|
|
119
165
|
signLocationRecord: () => signLocationRecord,
|
|
120
166
|
submitHostDelegation: () => submitHostDelegation,
|
|
121
167
|
validateClientSession: () => validateClientSession,
|
|
168
|
+
validateEnvelope: () => import_sdk_services5.validateEnvelope,
|
|
122
169
|
validateLocationRecord: () => validateLocationRecord,
|
|
123
170
|
validateLocationRecordPayload: () => validateLocationRecordPayload,
|
|
124
171
|
validateManifest: () => validateManifest,
|
|
125
172
|
validatePersistedSessionData: () => validatePersistedSessionData,
|
|
173
|
+
verifyDecryptResponse: () => import_sdk_services5.verifyDecryptResponse,
|
|
174
|
+
verifyDidKeyEd25519Signature: () => verifyDidKeyEd25519Signature,
|
|
126
175
|
verifyLocationRecord: () => verifyLocationRecord
|
|
127
176
|
});
|
|
128
177
|
module.exports = __toCommonJS(index_exports);
|
|
@@ -847,6 +896,23 @@ function validateServerSpaceInfoResponse(data) {
|
|
|
847
896
|
return { ok: true, data: result.data };
|
|
848
897
|
}
|
|
849
898
|
|
|
899
|
+
// src/expiry.ts
|
|
900
|
+
var EPHEMERAL_MS = 60 * 60 * 1e3;
|
|
901
|
+
var SIGNED_READ_URL_MS = 5 * 60 * 1e3;
|
|
902
|
+
var SESSION_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
903
|
+
var SHARE_MS = 7 * 24 * 60 * 60 * 1e3;
|
|
904
|
+
var APP_MS = 30 * 24 * 60 * 60 * 1e3;
|
|
905
|
+
var MAX_MS = 10 * 365 * 24 * 60 * 60 * 1e3;
|
|
906
|
+
var EXPIRY = {
|
|
907
|
+
EPHEMERAL_MS,
|
|
908
|
+
SIGNED_READ_URL_MS,
|
|
909
|
+
SESSION_MS,
|
|
910
|
+
SHARE_MS,
|
|
911
|
+
APP_MS,
|
|
912
|
+
MAX_MS
|
|
913
|
+
};
|
|
914
|
+
var DEFAULT_SIGNED_READ_URL_EXPIRY_MS = EXPIRY.SIGNED_READ_URL_MS;
|
|
915
|
+
|
|
850
916
|
// src/spaces/SpaceService.ts
|
|
851
917
|
var SERVICE_NAME = "space";
|
|
852
918
|
var SpaceErrorCodes = {
|
|
@@ -923,7 +989,7 @@ function transformServerDelegations(validatedData, defaultSpaceId) {
|
|
|
923
989
|
spaceId,
|
|
924
990
|
path,
|
|
925
991
|
actions,
|
|
926
|
-
expiry: info.expiry ? new Date(info.expiry) : new Date(Date.now() +
|
|
992
|
+
expiry: info.expiry ? new Date(info.expiry) : new Date(Date.now() + EXPIRY.SHARE_MS),
|
|
927
993
|
isRevoked: false,
|
|
928
994
|
createdAt: info.issued_at ? new Date(info.issued_at) : void 0,
|
|
929
995
|
parentCid: firstStringParent
|
|
@@ -1783,6 +1849,22 @@ var TinyCloud = class _TinyCloud {
|
|
|
1783
1849
|
}
|
|
1784
1850
|
return service;
|
|
1785
1851
|
}
|
|
1852
|
+
/**
|
|
1853
|
+
* Get the Encryption service.
|
|
1854
|
+
* @throws Error if services are not initialized or encryption service is not registered
|
|
1855
|
+
*/
|
|
1856
|
+
get encryption() {
|
|
1857
|
+
if (!this._servicesInitialized) {
|
|
1858
|
+
throw new Error(
|
|
1859
|
+
"Services not initialized. Call initializeServices() first, or use TinyCloudWeb/TinyCloudNode which handles this automatically."
|
|
1860
|
+
);
|
|
1861
|
+
}
|
|
1862
|
+
const service = this._services.get("encryption");
|
|
1863
|
+
if (!service) {
|
|
1864
|
+
throw new Error("Encryption service is not registered.");
|
|
1865
|
+
}
|
|
1866
|
+
return service;
|
|
1867
|
+
}
|
|
1786
1868
|
/**
|
|
1787
1869
|
* Notify services of session change.
|
|
1788
1870
|
* Called internally after sign-in and sign-out.
|
|
@@ -2118,7 +2200,7 @@ var TinyCloud = class _TinyCloud {
|
|
|
2118
2200
|
};
|
|
2119
2201
|
|
|
2120
2202
|
// src/index.ts
|
|
2121
|
-
var
|
|
2203
|
+
var import_sdk_services5 = require("@tinycloud/sdk-services");
|
|
2122
2204
|
|
|
2123
2205
|
// src/space.ts
|
|
2124
2206
|
async function fetchPeerId(host, spaceId) {
|
|
@@ -2307,7 +2389,7 @@ var DelegationManager = class {
|
|
|
2307
2389
|
spaceId: this.session.spaceId,
|
|
2308
2390
|
path: params.path,
|
|
2309
2391
|
actions: params.actions,
|
|
2310
|
-
expiry: params.expiry ?? new Date(Date.now() +
|
|
2392
|
+
expiry: params.expiry ?? new Date(Date.now() + EXPIRY.SHARE_MS),
|
|
2311
2393
|
isRevoked: false,
|
|
2312
2394
|
allowSubDelegation: !(params.disableSubDelegation ?? false),
|
|
2313
2395
|
createdAt: /* @__PURE__ */ new Date()
|
|
@@ -2786,6 +2868,7 @@ function validateEncodedShareData(data) {
|
|
|
2786
2868
|
|
|
2787
2869
|
// src/manifest.ts
|
|
2788
2870
|
var import_ms = __toESM(require("ms"), 1);
|
|
2871
|
+
var import_sdk_services3 = require("@tinycloud/sdk-services");
|
|
2789
2872
|
var ManifestValidationError = class extends Error {
|
|
2790
2873
|
constructor(message) {
|
|
2791
2874
|
super(`Manifest validation failed: ${message}`);
|
|
@@ -2799,15 +2882,17 @@ var DEFAULT_MANIFEST_SPACE = "applications";
|
|
|
2799
2882
|
var ACCOUNT_REGISTRY_SPACE = "account";
|
|
2800
2883
|
var ACCOUNT_REGISTRY_PATH = "applications/";
|
|
2801
2884
|
var SECRETS_SPACE = "secrets";
|
|
2802
|
-
var SECRET_NAME_RE = /^[A-Z][A-Z0-9_]*$/;
|
|
2803
2885
|
var VAULT_PERMISSION_SERVICE = "tinycloud.vault";
|
|
2804
2886
|
var SERVICE_SHORT_TO_LONG = Object.freeze({
|
|
2805
2887
|
kv: "tinycloud.kv",
|
|
2806
2888
|
sql: "tinycloud.sql",
|
|
2807
2889
|
duckdb: "tinycloud.duckdb",
|
|
2808
2890
|
capabilities: "tinycloud.capabilities",
|
|
2809
|
-
hooks: "tinycloud.hooks"
|
|
2891
|
+
hooks: "tinycloud.hooks",
|
|
2892
|
+
encryption: "tinycloud.encryption"
|
|
2810
2893
|
});
|
|
2894
|
+
var ENCRYPTION_PERMISSION_SERVICE = "tinycloud.encryption";
|
|
2895
|
+
var ENCRYPTION_MANIFEST_SPACE = "encryption";
|
|
2811
2896
|
var SERVICE_LONG_TO_SHORT = Object.freeze(
|
|
2812
2897
|
Object.fromEntries(
|
|
2813
2898
|
Object.entries(SERVICE_SHORT_TO_LONG).map(([s, l]) => [l, s])
|
|
@@ -2884,6 +2969,9 @@ function expandActionShortNames(service, actions) {
|
|
|
2884
2969
|
});
|
|
2885
2970
|
}
|
|
2886
2971
|
function expandPermissionEntry(entry) {
|
|
2972
|
+
if (entry.service === ENCRYPTION_PERMISSION_SERVICE) {
|
|
2973
|
+
return expandEncryptionPermissionEntry(entry);
|
|
2974
|
+
}
|
|
2887
2975
|
if (entry.service !== VAULT_PERMISSION_SERVICE) {
|
|
2888
2976
|
return [
|
|
2889
2977
|
{
|
|
@@ -2894,6 +2982,55 @@ function expandPermissionEntry(entry) {
|
|
|
2894
2982
|
}
|
|
2895
2983
|
return expandVaultPermissionEntry(entry);
|
|
2896
2984
|
}
|
|
2985
|
+
function expandEncryptionPermissionEntry(entry) {
|
|
2986
|
+
if (typeof entry.path !== "string" || !entry.path.startsWith("urn:tinycloud:encryption:")) {
|
|
2987
|
+
throw new ManifestValidationError(
|
|
2988
|
+
`tinycloud.encryption entries require path to be a networkId URN (got ${JSON.stringify(entry.path)})`
|
|
2989
|
+
);
|
|
2990
|
+
}
|
|
2991
|
+
const normalizedActions = [];
|
|
2992
|
+
for (const action of entry.actions) {
|
|
2993
|
+
if (action === "decrypt" || action === "tinycloud.encryption/decrypt") {
|
|
2994
|
+
normalizedActions.push("tinycloud.encryption/decrypt");
|
|
2995
|
+
continue;
|
|
2996
|
+
}
|
|
2997
|
+
if (action === "network.create" || action === "tinycloud.encryption/network.create") {
|
|
2998
|
+
normalizedActions.push("tinycloud.encryption/network.create");
|
|
2999
|
+
continue;
|
|
3000
|
+
}
|
|
3001
|
+
if (action === "network.revoke" || action === "tinycloud.encryption/network.revoke") {
|
|
3002
|
+
normalizedActions.push("tinycloud.encryption/network.revoke");
|
|
3003
|
+
continue;
|
|
3004
|
+
}
|
|
3005
|
+
if (action.includes("/")) {
|
|
3006
|
+
throw new ManifestValidationError(
|
|
3007
|
+
`unknown encryption action ${JSON.stringify(action)}; expected decrypt, network.create, or network.revoke`
|
|
3008
|
+
);
|
|
3009
|
+
}
|
|
3010
|
+
throw new ManifestValidationError(
|
|
3011
|
+
`unknown encryption action ${JSON.stringify(action)}; expected decrypt, network.create, or network.revoke`
|
|
3012
|
+
);
|
|
3013
|
+
}
|
|
3014
|
+
const dedupedActions = [];
|
|
3015
|
+
const seen = /* @__PURE__ */ new Set();
|
|
3016
|
+
for (const a of normalizedActions) {
|
|
3017
|
+
if (!seen.has(a)) {
|
|
3018
|
+
dedupedActions.push(a);
|
|
3019
|
+
seen.add(a);
|
|
3020
|
+
}
|
|
3021
|
+
}
|
|
3022
|
+
return [
|
|
3023
|
+
{
|
|
3024
|
+
service: ENCRYPTION_PERMISSION_SERVICE,
|
|
3025
|
+
space: ENCRYPTION_MANIFEST_SPACE,
|
|
3026
|
+
path: entry.path,
|
|
3027
|
+
actions: dedupedActions,
|
|
3028
|
+
skipPrefix: true,
|
|
3029
|
+
...entry.expiry !== void 0 ? { expiry: entry.expiry } : {},
|
|
3030
|
+
...entry.description !== void 0 ? { description: entry.description } : {}
|
|
3031
|
+
}
|
|
3032
|
+
];
|
|
3033
|
+
}
|
|
2897
3034
|
function expandPermissionEntries(entries) {
|
|
2898
3035
|
return entries.flatMap(expandPermissionEntry);
|
|
2899
3036
|
}
|
|
@@ -2978,9 +3115,19 @@ function validateManifestSecrets(secrets) {
|
|
|
2978
3115
|
throw new ManifestValidationError("manifest.secrets must be an object");
|
|
2979
3116
|
}
|
|
2980
3117
|
for (const [name, spec] of Object.entries(secrets)) {
|
|
2981
|
-
if (!SECRET_NAME_RE.test(name)) {
|
|
3118
|
+
if (!import_sdk_services3.SECRET_NAME_RE.test(name)) {
|
|
3119
|
+
throw new ManifestValidationError(
|
|
3120
|
+
`manifest.secrets.${name} must match ${import_sdk_services3.SECRET_NAME_RE.source}`
|
|
3121
|
+
);
|
|
3122
|
+
}
|
|
3123
|
+
try {
|
|
3124
|
+
(0, import_sdk_services3.resolveSecretPath)(
|
|
3125
|
+
secretNameFromSpec(name, spec),
|
|
3126
|
+
{ scope: secretScopeFromSpec(spec) }
|
|
3127
|
+
);
|
|
3128
|
+
} catch (error) {
|
|
2982
3129
|
throw new ManifestValidationError(
|
|
2983
|
-
`manifest.secrets.${name}
|
|
3130
|
+
`manifest.secrets.${name}: ${error instanceof Error ? error.message : String(error)}`
|
|
2984
3131
|
);
|
|
2985
3132
|
}
|
|
2986
3133
|
const actions = secretActionsFromSpec(name, spec);
|
|
@@ -3139,6 +3286,18 @@ function normalizeSecretActions(actions) {
|
|
|
3139
3286
|
}
|
|
3140
3287
|
return out;
|
|
3141
3288
|
}
|
|
3289
|
+
function secretNameFromSpec(fallbackName, spec) {
|
|
3290
|
+
if (spec !== null && typeof spec === "object" && !Array.isArray(spec)) {
|
|
3291
|
+
return spec.name ?? fallbackName;
|
|
3292
|
+
}
|
|
3293
|
+
return fallbackName;
|
|
3294
|
+
}
|
|
3295
|
+
function secretScopeFromSpec(spec) {
|
|
3296
|
+
if (spec !== null && typeof spec === "object" && !Array.isArray(spec)) {
|
|
3297
|
+
return spec.scope;
|
|
3298
|
+
}
|
|
3299
|
+
return void 0;
|
|
3300
|
+
}
|
|
3142
3301
|
function secretActionsFromSpec(name, spec) {
|
|
3143
3302
|
if (spec === true) {
|
|
3144
3303
|
return ["read"];
|
|
@@ -3174,27 +3333,26 @@ function secretEntriesForManifest(secrets) {
|
|
|
3174
3333
|
const entries = [];
|
|
3175
3334
|
for (const [name, spec] of Object.entries(secrets)) {
|
|
3176
3335
|
const actions = secretActionsFromSpec(name, spec);
|
|
3336
|
+
const secretPath = (0, import_sdk_services3.resolveSecretPath)(
|
|
3337
|
+
secretNameFromSpec(name, spec),
|
|
3338
|
+
{ scope: secretScopeFromSpec(spec) }
|
|
3339
|
+
);
|
|
3177
3340
|
const extra = spec !== true && typeof spec === "object" && !Array.isArray(spec) ? spec : {};
|
|
3178
|
-
|
|
3179
|
-
|
|
3180
|
-
|
|
3181
|
-
|
|
3182
|
-
|
|
3183
|
-
|
|
3184
|
-
|
|
3185
|
-
|
|
3186
|
-
|
|
3187
|
-
});
|
|
3188
|
-
}
|
|
3341
|
+
entries.push({
|
|
3342
|
+
service: VAULT_PERMISSION_SERVICE,
|
|
3343
|
+
space: SECRETS_SPACE,
|
|
3344
|
+
path: secretPath.vaultKey,
|
|
3345
|
+
actions: normalizeSecretActions(actions),
|
|
3346
|
+
skipPrefix: true,
|
|
3347
|
+
...extra.expiry !== void 0 ? { expiry: extra.expiry } : {},
|
|
3348
|
+
...extra.description !== void 0 ? { description: extra.description } : {}
|
|
3349
|
+
});
|
|
3189
3350
|
}
|
|
3190
3351
|
return entries;
|
|
3191
3352
|
}
|
|
3192
3353
|
function resolveEntry(entry, prefix, _inheritedExpiryMs, inheritedSpace) {
|
|
3193
|
-
const
|
|
3194
|
-
|
|
3195
|
-
entry.path,
|
|
3196
|
-
entry.skipPrefix === true
|
|
3197
|
-
);
|
|
3354
|
+
const skipPrefixForEntry = entry.skipPrefix === true || entry.service === ENCRYPTION_PERMISSION_SERVICE;
|
|
3355
|
+
const resolvedPath = applyPrefix(prefix, entry.path, skipPrefixForEntry);
|
|
3198
3356
|
const entryExpiryMs = entry.expiry !== void 0 ? parseExpiry(entry.expiry) : void 0;
|
|
3199
3357
|
return expandPermissionEntry({
|
|
3200
3358
|
...entry,
|
|
@@ -3236,13 +3394,13 @@ function expandVaultPermissionEntry(entry) {
|
|
|
3236
3394
|
function vaultActionExpansion(action) {
|
|
3237
3395
|
const normalized = normalizeVaultAction(action);
|
|
3238
3396
|
if (normalized === "read" || normalized === "get") {
|
|
3239
|
-
return { bases: ["
|
|
3397
|
+
return { bases: ["vault"], action: "tinycloud.kv/get" };
|
|
3240
3398
|
}
|
|
3241
3399
|
if (normalized === "write" || normalized === "put") {
|
|
3242
|
-
return { bases: ["
|
|
3400
|
+
return { bases: ["vault"], action: "tinycloud.kv/put" };
|
|
3243
3401
|
}
|
|
3244
3402
|
if (normalized === "delete" || normalized === "del") {
|
|
3245
|
-
return { bases: ["
|
|
3403
|
+
return { bases: ["vault"], action: "tinycloud.kv/del" };
|
|
3246
3404
|
}
|
|
3247
3405
|
if (normalized === "list") {
|
|
3248
3406
|
return { bases: ["vault"], action: "tinycloud.kv/list" };
|
|
@@ -3330,7 +3488,9 @@ function withCapabilitiesReadForSpaces(resources) {
|
|
|
3330
3488
|
if (resources.length === 0) {
|
|
3331
3489
|
return [];
|
|
3332
3490
|
}
|
|
3333
|
-
const spaces = new Set(
|
|
3491
|
+
const spaces = new Set(
|
|
3492
|
+
resources.filter((resource) => resource.service !== ENCRYPTION_PERMISSION_SERVICE).map((resource) => resource.space)
|
|
3493
|
+
);
|
|
3334
3494
|
return dedupeResources([
|
|
3335
3495
|
...resources,
|
|
3336
3496
|
...[...spaces].map(capabilitiesReadPermission)
|
|
@@ -3462,7 +3622,7 @@ function inferShortServiceFromActionUrns(actions) {
|
|
|
3462
3622
|
return short;
|
|
3463
3623
|
}
|
|
3464
3624
|
var DEFAULT_READ_ACTIONS = ["tinycloud.kv/get", "tinycloud.kv/metadata"];
|
|
3465
|
-
var DEFAULT_EXPIRY_MS =
|
|
3625
|
+
var DEFAULT_EXPIRY_MS = EXPIRY.SHARE_MS;
|
|
3466
3626
|
var BASE64_PREFIX = "tc1:";
|
|
3467
3627
|
function createError2(code, message, cause, meta) {
|
|
3468
3628
|
return {
|
|
@@ -4104,7 +4264,7 @@ function createSharingService(config) {
|
|
|
4104
4264
|
}
|
|
4105
4265
|
|
|
4106
4266
|
// src/authorization/CapabilityKeyRegistry.ts
|
|
4107
|
-
var
|
|
4267
|
+
var import_sdk_services4 = require("@tinycloud/sdk-services");
|
|
4108
4268
|
var SERVICE_NAME2 = "capability-key-registry";
|
|
4109
4269
|
var CapabilityKeyRegistryErrorCodes = {
|
|
4110
4270
|
/** Key not found in registry */
|
|
@@ -4322,8 +4482,8 @@ var CapabilityKeyRegistry = class {
|
|
|
4322
4482
|
revokeDelegation(cid) {
|
|
4323
4483
|
const stored = this.store.byCid.get(cid);
|
|
4324
4484
|
if (!stored) {
|
|
4325
|
-
return (0,
|
|
4326
|
-
(0,
|
|
4485
|
+
return (0, import_sdk_services4.err)(
|
|
4486
|
+
(0, import_sdk_services4.serviceError)(
|
|
4327
4487
|
CapabilityKeyRegistryErrorCodes.KEY_NOT_FOUND,
|
|
4328
4488
|
`Delegation not found: ${cid}`,
|
|
4329
4489
|
SERVICE_NAME2
|
|
@@ -4345,7 +4505,7 @@ var CapabilityKeyRegistry = class {
|
|
|
4345
4505
|
}
|
|
4346
4506
|
}
|
|
4347
4507
|
}
|
|
4348
|
-
return (0,
|
|
4508
|
+
return (0, import_sdk_services4.ok)(void 0);
|
|
4349
4509
|
}
|
|
4350
4510
|
// ===========================================================================
|
|
4351
4511
|
// Search
|
|
@@ -4591,6 +4751,7 @@ async function checkNodeInfo(host, sdkProtocol, fetchFn = globalThis.fetch.bind(
|
|
|
4591
4751
|
}
|
|
4592
4752
|
return {
|
|
4593
4753
|
features: data.features ?? [],
|
|
4754
|
+
nodeId: data.nodeId,
|
|
4594
4755
|
quotaUrl: data.quota_url
|
|
4595
4756
|
};
|
|
4596
4757
|
}
|
|
@@ -4927,6 +5088,10 @@ function verifyDidKeySignature(did, payload, signature) {
|
|
|
4927
5088
|
publicKey
|
|
4928
5089
|
);
|
|
4929
5090
|
}
|
|
5091
|
+
function verifyDidKeyEd25519Signature(did, payload, signature) {
|
|
5092
|
+
const publicKey = ed25519PublicKeyFromDidKey(did);
|
|
5093
|
+
return import_ed25519.ed25519.verify(signature, payload, publicKey);
|
|
5094
|
+
}
|
|
4930
5095
|
function ed25519PublicKeyFromDidKey(did) {
|
|
4931
5096
|
const identifier = did.slice("did:key:".length);
|
|
4932
5097
|
if (!identifier.startsWith("z")) {
|
|
@@ -4935,12 +5100,15 @@ function ed25519PublicKeyFromDidKey(did) {
|
|
|
4935
5100
|
);
|
|
4936
5101
|
}
|
|
4937
5102
|
const bytes = import_basics.bases.base58btc.decode(identifier);
|
|
4938
|
-
if (bytes.length
|
|
4939
|
-
|
|
4940
|
-
"did:key must be an Ed25519 public key"
|
|
4941
|
-
);
|
|
5103
|
+
if (bytes.length === 34 && bytes[0] === 237 && bytes[1] === 1) {
|
|
5104
|
+
return bytes.slice(2);
|
|
4942
5105
|
}
|
|
4943
|
-
|
|
5106
|
+
if (bytes.length === 33 && bytes[0] === 237) {
|
|
5107
|
+
return bytes.slice(1);
|
|
5108
|
+
}
|
|
5109
|
+
throw new LocationRecordValidationError(
|
|
5110
|
+
"did:key must be an Ed25519 public key"
|
|
5111
|
+
);
|
|
4944
5112
|
}
|
|
4945
5113
|
function base64UrlEncode2(bytes) {
|
|
4946
5114
|
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
|
|
@@ -5105,10 +5273,16 @@ function parseRecapCapabilities(parseWasm, siwe) {
|
|
|
5105
5273
|
CapabilityKeyRegistryErrorCodes,
|
|
5106
5274
|
ClientSessionSchema,
|
|
5107
5275
|
CloudLocationResolutionError,
|
|
5276
|
+
DECRYPT_ACTION,
|
|
5277
|
+
DECRYPT_FACT_TYPE,
|
|
5278
|
+
DECRYPT_RESULT_TYPE,
|
|
5108
5279
|
DEFAULT_DEFAULTS,
|
|
5280
|
+
DEFAULT_ENCRYPTION_ALG,
|
|
5109
5281
|
DEFAULT_EXPIRY,
|
|
5282
|
+
DEFAULT_KEY_VERSION,
|
|
5110
5283
|
DEFAULT_MANIFEST_SPACE,
|
|
5111
5284
|
DEFAULT_MANIFEST_VERSION,
|
|
5285
|
+
DEFAULT_SIGNED_READ_URL_EXPIRY_MS,
|
|
5112
5286
|
DEFAULT_TINYCLOUD_FALLBACK_HOST,
|
|
5113
5287
|
DEFAULT_TINYCLOUD_LOCATION_REGISTRY_URL,
|
|
5114
5288
|
DataVaultService,
|
|
@@ -5118,15 +5292,26 @@ function parseRecapCapabilities(parseWasm, siwe) {
|
|
|
5118
5292
|
DuckDbAction,
|
|
5119
5293
|
DuckDbDatabaseHandle,
|
|
5120
5294
|
DuckDbService,
|
|
5295
|
+
ENCRYPTION_MANIFEST_SPACE,
|
|
5296
|
+
ENCRYPTION_NETWORK_URN_PREFIX,
|
|
5297
|
+
ENCRYPTION_PERMISSION_SERVICE,
|
|
5298
|
+
ENCRYPTION_SERVICE,
|
|
5299
|
+
ENCRYPTION_SERVICE_SHORT,
|
|
5300
|
+
ENVELOPE_VERSION,
|
|
5301
|
+
EXPIRY,
|
|
5302
|
+
EncryptionService,
|
|
5121
5303
|
EnsDataSchema,
|
|
5122
5304
|
ErrorCodes,
|
|
5123
5305
|
HooksService,
|
|
5124
5306
|
KVService,
|
|
5125
5307
|
LocationRecordValidationError,
|
|
5126
5308
|
ManifestValidationError,
|
|
5309
|
+
NETWORK_NAME_PATTERN,
|
|
5310
|
+
NetworkIdError,
|
|
5127
5311
|
PermissionNotInManifestError,
|
|
5128
5312
|
PrefixedKVService,
|
|
5129
5313
|
ProtocolMismatchError,
|
|
5314
|
+
SECRET_NAME_RE,
|
|
5130
5315
|
SERVICE_LONG_TO_SHORT,
|
|
5131
5316
|
SERVICE_SHORT_TO_LONG,
|
|
5132
5317
|
SQLAction,
|
|
@@ -5149,37 +5334,66 @@ function parseRecapCapabilities(parseWasm, siwe) {
|
|
|
5149
5334
|
VersionCheckError,
|
|
5150
5335
|
activateSessionWithHost,
|
|
5151
5336
|
applyPrefix,
|
|
5337
|
+
buildCanonicalDecryptRequest,
|
|
5338
|
+
buildDecryptAttenuation,
|
|
5339
|
+
buildDecryptFacts,
|
|
5340
|
+
buildDecryptInvocation,
|
|
5341
|
+
buildNetworkId,
|
|
5152
5342
|
buildSpaceUri,
|
|
5343
|
+
canonicalHashHex,
|
|
5153
5344
|
canonicalLocationPayload,
|
|
5345
|
+
canonicalSignedResponse,
|
|
5346
|
+
canonicalizeEncryptionJson,
|
|
5347
|
+
canonicalizeSecretScope,
|
|
5348
|
+
checkDecryptInvocationInput,
|
|
5154
5349
|
checkNodeInfo,
|
|
5155
5350
|
composeManifestRequest,
|
|
5156
5351
|
createCapabilityKeyRegistry,
|
|
5157
5352
|
createSharingService,
|
|
5158
5353
|
createSpaceService,
|
|
5159
5354
|
createVaultCrypto,
|
|
5355
|
+
decryptEnvelopeWithKey,
|
|
5160
5356
|
defaultRetryPolicy,
|
|
5161
5357
|
defaultSignStrategy,
|
|
5162
5358
|
defaultSpaceCreationHandler,
|
|
5359
|
+
deriveSignedReceiverKey,
|
|
5360
|
+
discoverNetwork,
|
|
5361
|
+
encryptToNetwork,
|
|
5362
|
+
encryptionBase64Decode,
|
|
5363
|
+
encryptionBase64Encode,
|
|
5364
|
+
encryptionError,
|
|
5365
|
+
encryptionUtf8Decode,
|
|
5366
|
+
encryptionUtf8Encode,
|
|
5367
|
+
ensureNetworkUsableForDecrypt,
|
|
5163
5368
|
err,
|
|
5164
5369
|
expandActionShortNames,
|
|
5165
5370
|
expandPermissionEntries,
|
|
5166
5371
|
expandPermissionEntry,
|
|
5167
5372
|
fetchLocationRecord,
|
|
5168
5373
|
fetchPeerId,
|
|
5374
|
+
generateRandomReceiverKey,
|
|
5375
|
+
hexDecode,
|
|
5376
|
+
hexEncode,
|
|
5169
5377
|
httpUrlToMultiaddr,
|
|
5170
5378
|
isCapabilitySubset,
|
|
5379
|
+
isNetworkId,
|
|
5171
5380
|
loadManifest,
|
|
5172
5381
|
locationPayloadForRecord,
|
|
5173
5382
|
makePublicSpaceId,
|
|
5174
5383
|
manifestAbilitiesUnion,
|
|
5175
5384
|
multiaddrToHttpUrl,
|
|
5385
|
+
networkDiscoveryKey,
|
|
5176
5386
|
normalizeDefaults,
|
|
5177
5387
|
ok,
|
|
5388
|
+
openWrappedKey,
|
|
5178
5389
|
parseExpiry,
|
|
5390
|
+
parseNetworkId,
|
|
5179
5391
|
parseRecapCapabilities,
|
|
5180
5392
|
parseSpaceUri,
|
|
5181
5393
|
resolveCloudLocation,
|
|
5182
5394
|
resolveManifest,
|
|
5395
|
+
resolveSecretListPrefix,
|
|
5396
|
+
resolveSecretPath,
|
|
5183
5397
|
resolveTinyCloudHosts,
|
|
5184
5398
|
resourceCapabilitiesToAbilitiesMap,
|
|
5185
5399
|
resourceCapabilitiesToSpaceAbilitiesMap,
|
|
@@ -5187,10 +5401,13 @@ function parseRecapCapabilities(parseWasm, siwe) {
|
|
|
5187
5401
|
signLocationRecord,
|
|
5188
5402
|
submitHostDelegation,
|
|
5189
5403
|
validateClientSession,
|
|
5404
|
+
validateEnvelope,
|
|
5190
5405
|
validateLocationRecord,
|
|
5191
5406
|
validateLocationRecordPayload,
|
|
5192
5407
|
validateManifest,
|
|
5193
5408
|
validatePersistedSessionData,
|
|
5409
|
+
verifyDecryptResponse,
|
|
5410
|
+
verifyDidKeyEd25519Signature,
|
|
5194
5411
|
verifyLocationRecord
|
|
5195
5412
|
});
|
|
5196
5413
|
//# sourceMappingURL=index.cjs.map
|