@tinycloud/sdk-services 3.8.0-beta.16 → 3.8.0-beta.9
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/encryption/index.cjs +7 -80
- package/dist/encryption/index.cjs.map +1 -1
- package/dist/encryption/index.d.cts +9 -21
- package/dist/encryption/index.d.ts +9 -21
- package/dist/encryption/index.js +7 -79
- package/dist/encryption/index.js.map +1 -1
- package/dist/encryption/named-keys.cjs.map +1 -1
- package/dist/encryption/named-keys.d.cts +1 -1
- package/dist/encryption/named-keys.d.ts +1 -1
- package/dist/encryption/named-keys.js.map +1 -1
- package/dist/encryption/resource.cjs.map +1 -1
- package/dist/encryption/resource.js.map +1 -1
- package/dist/index.cjs +7 -80
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +7 -79
- package/dist/index.js.map +1 -1
- package/dist/kv/index.cjs.map +1 -1
- package/dist/kv/index.js.map +1 -1
- package/dist/{types-DZBExWAf.d.ts → types-BGRzS1ob.d.ts} +1 -6
- package/dist/{types-CBKrdtP8.d.cts → types-B_rbS4XE.d.cts} +1 -6
- package/package.json +1 -1
|
@@ -56,7 +56,6 @@ __export(encryption_exports, {
|
|
|
56
56
|
isNetworkId: () => isNetworkId,
|
|
57
57
|
networkDiscoveryKey: () => networkDiscoveryKey,
|
|
58
58
|
openWrappedKey: () => openWrappedKey,
|
|
59
|
-
parseEncryptionResource: () => parseEncryptionResource,
|
|
60
59
|
parseNetworkId: () => parseNetworkId,
|
|
61
60
|
utf8Decode: () => utf8Decode,
|
|
62
61
|
utf8Encode: () => utf8Encode,
|
|
@@ -202,26 +201,6 @@ function parseNetworkId(networkId) {
|
|
|
202
201
|
}
|
|
203
202
|
return { networkId, ownerDid, name };
|
|
204
203
|
}
|
|
205
|
-
function parseEncryptionResource(resource) {
|
|
206
|
-
const networkSeparator = resource.lastIndexOf(":");
|
|
207
|
-
const nameAndPath = resource.slice(networkSeparator + 1);
|
|
208
|
-
const pathSeparator = nameAndPath.indexOf("/");
|
|
209
|
-
const name = pathSeparator === -1 ? nameAndPath : nameAndPath.slice(0, pathSeparator);
|
|
210
|
-
const networkId = pathSeparator === -1 ? resource : `${resource.slice(0, networkSeparator + 1)}${name}`;
|
|
211
|
-
const parsed = parseNetworkId(networkId);
|
|
212
|
-
if (pathSeparator === -1) return parsed;
|
|
213
|
-
const keyPath = nameAndPath.slice(pathSeparator + 1);
|
|
214
|
-
const segments = keyPath.split("/");
|
|
215
|
-
const prefix = keyPath.endsWith("/");
|
|
216
|
-
if (keyPath.length === 0 || /[\u0000-\u001f\u007f\\]/.test(keyPath) || segments.some(
|
|
217
|
-
(segment, index) => segment === "." || segment === ".." || segment.length === 0 && !(prefix && index === segments.length - 1)
|
|
218
|
-
)) {
|
|
219
|
-
throw new NetworkIdError(
|
|
220
|
-
`encryption resource has an invalid keyPath (got ${JSON.stringify(resource)})`
|
|
221
|
-
);
|
|
222
|
-
}
|
|
223
|
-
return { ...parsed, keyPath };
|
|
224
|
-
}
|
|
225
204
|
function buildNetworkId(ownerDid, name) {
|
|
226
205
|
if (typeof ownerDid !== "string" || !ownerDid.startsWith("did:")) {
|
|
227
206
|
throw new NetworkIdError("ownerDid must be a DID");
|
|
@@ -934,12 +913,7 @@ function ensureNetworkUsableForDecrypt(descriptor) {
|
|
|
934
913
|
|
|
935
914
|
// src/encryption/envelope.ts
|
|
936
915
|
function encryptToNetwork(crypto, input) {
|
|
937
|
-
|
|
938
|
-
input.keyPath === void 0 ? input.networkId : `${input.networkId}/${input.keyPath}`
|
|
939
|
-
);
|
|
940
|
-
if (parsedResource.keyPath !== input.keyPath || input.keyPath?.endsWith("/")) {
|
|
941
|
-
throw new NetworkIdError("keyPath must name an exact encryption key");
|
|
942
|
-
}
|
|
916
|
+
parseNetworkId(input.networkId);
|
|
943
917
|
const alg = input.alg ?? DEFAULT_ENCRYPTION_ALG;
|
|
944
918
|
const keyVersion = input.keyVersion ?? DEFAULT_KEY_VERSION;
|
|
945
919
|
const symmetricKey = crypto.randomBytes(32);
|
|
@@ -953,7 +927,6 @@ function encryptToNetwork(crypto, input) {
|
|
|
953
927
|
const envelope = {
|
|
954
928
|
v: ENVELOPE_VERSION,
|
|
955
929
|
networkId: input.networkId,
|
|
956
|
-
...input.keyPath !== void 0 ? { keyPath: input.keyPath } : {},
|
|
957
930
|
alg,
|
|
958
931
|
keyVersion,
|
|
959
932
|
encryptedSymmetricKey,
|
|
@@ -985,24 +958,13 @@ function validateEnvelope(crypto, envelope) {
|
|
|
985
958
|
};
|
|
986
959
|
}
|
|
987
960
|
try {
|
|
988
|
-
|
|
989
|
-
throw new Error("networkId must identify the network root");
|
|
990
|
-
}
|
|
991
|
-
if (e.keyPath !== void 0) {
|
|
992
|
-
if (typeof e.keyPath !== "string") {
|
|
993
|
-
throw new Error("keyPath must be a string");
|
|
994
|
-
}
|
|
995
|
-
const parsed = parseEncryptionResource(`${e.networkId}/${e.keyPath}`);
|
|
996
|
-
if (parsed.keyPath !== e.keyPath || e.keyPath.endsWith("/")) {
|
|
997
|
-
throw new Error("keyPath must name an exact encryption key");
|
|
998
|
-
}
|
|
999
|
-
}
|
|
961
|
+
parseNetworkId(e.networkId);
|
|
1000
962
|
} catch (err2) {
|
|
1001
963
|
return {
|
|
1002
964
|
ok: false,
|
|
1003
965
|
error: encryptionError({
|
|
1004
966
|
code: "INVALID_ENVELOPE",
|
|
1005
|
-
message: `envelope
|
|
967
|
+
message: `envelope.networkId is malformed: ${err2 instanceof Error ? err2.message : String(err2)}`
|
|
1006
968
|
})
|
|
1007
969
|
};
|
|
1008
970
|
}
|
|
@@ -1075,7 +1037,6 @@ function buildDecryptFacts(input) {
|
|
|
1075
1037
|
type: DECRYPT_FACT_TYPE,
|
|
1076
1038
|
targetNode: input.body.targetNode,
|
|
1077
1039
|
networkId: input.body.networkId,
|
|
1078
|
-
...input.body.keyPath !== void 0 ? { keyPath: input.body.keyPath } : {},
|
|
1079
1040
|
bodyHash,
|
|
1080
1041
|
encryptedSymmetricKeyHash: input.encryptedSymmetricKeyHash,
|
|
1081
1042
|
receiverPublicKeyHash,
|
|
@@ -1083,14 +1044,10 @@ function buildDecryptFacts(input) {
|
|
|
1083
1044
|
keyVersion: input.body.keyVersion
|
|
1084
1045
|
};
|
|
1085
1046
|
}
|
|
1086
|
-
function buildDecryptAttenuation(networkId
|
|
1087
|
-
|
|
1088
|
-
const parsed = parseEncryptionResource(resource);
|
|
1089
|
-
if (parsed.networkId !== networkId || parsed.keyPath !== keyPath || keyPath?.endsWith("/")) {
|
|
1090
|
-
throw new NetworkIdError("keyPath must name an exact encryption key");
|
|
1091
|
-
}
|
|
1047
|
+
function buildDecryptAttenuation(networkId) {
|
|
1048
|
+
parseNetworkId(networkId);
|
|
1092
1049
|
return {
|
|
1093
|
-
[
|
|
1050
|
+
[networkId]: {
|
|
1094
1051
|
[DECRYPT_ACTION]: {}
|
|
1095
1052
|
}
|
|
1096
1053
|
};
|
|
@@ -1150,15 +1107,6 @@ function checkDecryptInvocationInput(crypto, input) {
|
|
|
1150
1107
|
})
|
|
1151
1108
|
};
|
|
1152
1109
|
}
|
|
1153
|
-
if (input.facts.keyPath !== input.body.keyPath) {
|
|
1154
|
-
return {
|
|
1155
|
-
ok: false,
|
|
1156
|
-
error: encryptionError({
|
|
1157
|
-
code: "INVALID_INPUT",
|
|
1158
|
-
message: "facts.keyPath must equal body.keyPath"
|
|
1159
|
-
})
|
|
1160
|
-
};
|
|
1161
|
-
}
|
|
1162
1110
|
if (input.facts.alg !== input.body.alg) {
|
|
1163
1111
|
return {
|
|
1164
1112
|
ok: false,
|
|
@@ -1196,9 +1144,7 @@ function checkDecryptInvocationInput(crypto, input) {
|
|
|
1196
1144
|
};
|
|
1197
1145
|
}
|
|
1198
1146
|
try {
|
|
1199
|
-
|
|
1200
|
-
throw new NetworkIdError("networkId must identify the network root");
|
|
1201
|
-
}
|
|
1147
|
+
parseNetworkId(input.networkId);
|
|
1202
1148
|
} catch (err2) {
|
|
1203
1149
|
return {
|
|
1204
1150
|
ok: false,
|
|
@@ -1208,22 +1154,6 @@ function checkDecryptInvocationInput(crypto, input) {
|
|
|
1208
1154
|
})
|
|
1209
1155
|
};
|
|
1210
1156
|
}
|
|
1211
|
-
try {
|
|
1212
|
-
const resource = parseEncryptionResource(
|
|
1213
|
-
input.body.keyPath === void 0 ? input.body.networkId : `${input.body.networkId}/${input.body.keyPath}`
|
|
1214
|
-
);
|
|
1215
|
-
if (resource.keyPath !== input.body.keyPath || input.body.keyPath?.endsWith("/")) {
|
|
1216
|
-
throw new NetworkIdError("keyPath must name an exact encryption key");
|
|
1217
|
-
}
|
|
1218
|
-
} catch (err2) {
|
|
1219
|
-
return {
|
|
1220
|
-
ok: false,
|
|
1221
|
-
error: encryptionError({
|
|
1222
|
-
code: "INVALID_INPUT",
|
|
1223
|
-
message: err2 instanceof Error ? err2.message : String(err2)
|
|
1224
|
-
})
|
|
1225
|
-
};
|
|
1226
|
-
}
|
|
1227
1157
|
const canonicalBody = canonicalize(
|
|
1228
1158
|
input.body
|
|
1229
1159
|
);
|
|
@@ -1464,7 +1394,6 @@ var EncryptionService = class extends BaseService {
|
|
|
1464
1394
|
// that spelling in the envelope so a later response can be compared
|
|
1465
1395
|
// byte-for-byte (notably for checksummed did:pkh principals).
|
|
1466
1396
|
networkId: descriptor.networkId,
|
|
1467
|
-
...options?.keyPath !== void 0 ? { keyPath: options.keyPath } : {},
|
|
1468
1397
|
networkPublicKey,
|
|
1469
1398
|
plaintext,
|
|
1470
1399
|
...options?.aad !== void 0 ? { aad: options.aad } : {},
|
|
@@ -1524,7 +1453,6 @@ var EncryptionService = class extends BaseService {
|
|
|
1524
1453
|
type: DECRYPT_FACT_TYPE,
|
|
1525
1454
|
targetNode,
|
|
1526
1455
|
networkId: envelope.networkId,
|
|
1527
|
-
...envelope.keyPath !== void 0 ? { keyPath: envelope.keyPath } : {},
|
|
1528
1456
|
alg: envelope.alg,
|
|
1529
1457
|
keyVersion: envelope.keyVersion,
|
|
1530
1458
|
encryptedSymmetricKey: envelope.encryptedSymmetricKey,
|
|
@@ -1669,7 +1597,6 @@ var import_decrypt_transport_response_error3 = require("@tinycloud/sdk-services/
|
|
|
1669
1597
|
isNetworkId,
|
|
1670
1598
|
networkDiscoveryKey,
|
|
1671
1599
|
openWrappedKey,
|
|
1672
|
-
parseEncryptionResource,
|
|
1673
1600
|
parseNetworkId,
|
|
1674
1601
|
utf8Decode,
|
|
1675
1602
|
utf8Encode,
|