@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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { B as BaseService } from '../BaseService-D-29xShG.cjs';
|
|
2
2
|
import { c as IService, h as Result } from '../types-DAOyIbXu.cjs';
|
|
3
|
-
import { N as NetworkDescriptor, n as EncryptionError, I as InlineEncryptedEnvelope, D as DecryptCapabilityProof, j as DecryptResponseBody, E as EncryptionCrypto, h as DecryptInvocationSigner, p as ReceiverKeySigner, R as ReceiverKeyPair, i as DecryptRequestBody, g as DecryptInvocationFact, B as BuildDecryptInvocationInput, a as BuiltDecryptInvocation } from '../types-
|
|
4
|
-
export { C as CanonicalJson, b as DECRYPT_ACTION, c as DECRYPT_FACT_TYPE, d as DECRYPT_RESULT_TYPE, e as DEFAULT_ENCRYPTION_ALG, f as DEFAULT_KEY_VERSION, k as ENCRYPTION_SERVICE, l as ENCRYPTION_SERVICE_SHORT, m as ENVELOPE_VERSION, o as EncryptionErrorInput, J as Json, q as base64Decode, r as base64Encode, s as canonicalHashHex, t as canonicalize, u as encryptionError, v as hexDecode, w as hexEncode, x as utf8Decode, y as utf8Encode } from '../types-
|
|
3
|
+
import { N as NetworkDescriptor, n as EncryptionError, I as InlineEncryptedEnvelope, D as DecryptCapabilityProof, j as DecryptResponseBody, E as EncryptionCrypto, h as DecryptInvocationSigner, p as ReceiverKeySigner, R as ReceiverKeyPair, i as DecryptRequestBody, g as DecryptInvocationFact, B as BuildDecryptInvocationInput, a as BuiltDecryptInvocation } from '../types-B_rbS4XE.cjs';
|
|
4
|
+
export { C as CanonicalJson, b as DECRYPT_ACTION, c as DECRYPT_FACT_TYPE, d as DECRYPT_RESULT_TYPE, e as DEFAULT_ENCRYPTION_ALG, f as DEFAULT_KEY_VERSION, k as ENCRYPTION_SERVICE, l as ENCRYPTION_SERVICE_SHORT, m as ENVELOPE_VERSION, o as EncryptionErrorInput, J as Json, q as base64Decode, r as base64Encode, s as canonicalHashHex, t as canonicalize, u as encryptionError, v as hexDecode, w as hexEncode, x as utf8Decode, y as utf8Encode } from '../types-B_rbS4XE.cjs';
|
|
5
5
|
export { DecryptTransportResponseError } from '@tinycloud/sdk-services/internal/decrypt-transport-response-error';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -85,8 +85,6 @@ declare function ensureNetworkUsableForDecrypt(descriptor: NetworkDescriptor): {
|
|
|
85
85
|
*/
|
|
86
86
|
|
|
87
87
|
interface EncryptToNetworkOptions {
|
|
88
|
-
/** Exact named-key path to bind into the returned envelope. */
|
|
89
|
-
keyPath?: string;
|
|
90
88
|
/** Optional associated authenticated data (bytes). */
|
|
91
89
|
aad?: Uint8Array;
|
|
92
90
|
/** Ciphersuite override. Defaults to the network's alg. */
|
|
@@ -219,17 +217,6 @@ declare class NetworkIdError extends Error {
|
|
|
219
217
|
* malformed, or when the network name fails {@link NETWORK_NAME_RE}.
|
|
220
218
|
*/
|
|
221
219
|
declare function parseNetworkId(networkId: string): ParsedNetworkId;
|
|
222
|
-
interface ParsedEncryptionResource extends ParsedNetworkId {
|
|
223
|
-
/** Named-key path, if the resource is scoped below a network. */
|
|
224
|
-
keyPath?: string;
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* Parse a network-root or named-key encryption resource.
|
|
228
|
-
*
|
|
229
|
-
* A trailing slash on keyPath denotes a prefix grant; empty and traversal
|
|
230
|
-
* segments are rejected so resource matching cannot escape the named path.
|
|
231
|
-
*/
|
|
232
|
-
declare function parseEncryptionResource(resource: string): ParsedEncryptionResource;
|
|
233
220
|
/**
|
|
234
221
|
* Construct a network id URN from an owner DID and a network name.
|
|
235
222
|
* Validates inputs and throws {@link NetworkIdError} on bad shape.
|
|
@@ -267,8 +254,6 @@ declare const NETWORK_NAME_PATTERN: RegExp;
|
|
|
267
254
|
interface EncryptToNetworkInput {
|
|
268
255
|
/** Target network id URN. */
|
|
269
256
|
networkId: string;
|
|
270
|
-
/** Exact named-key path; omitted for a network-root key. */
|
|
271
|
-
keyPath?: string;
|
|
272
257
|
/** Network public key bytes (already discovered). */
|
|
273
258
|
networkPublicKey: Uint8Array;
|
|
274
259
|
/** Payload bytes to encrypt. Callers serialize objects to bytes themselves. */
|
|
@@ -411,10 +396,13 @@ interface BuildDecryptFactsInput {
|
|
|
411
396
|
*/
|
|
412
397
|
declare function buildDecryptFacts(input: BuildDecryptFactsInput): DecryptInvocationFact;
|
|
413
398
|
/**
|
|
414
|
-
*
|
|
415
|
-
*
|
|
399
|
+
* Recap-shaped attenuation for the decrypt invocation. The resource
|
|
400
|
+
* key is the networkId URN; the ability is the long-form
|
|
401
|
+
* `tinycloud.encryption/decrypt`. This is intentionally distinct from
|
|
402
|
+
* the existing space-shaped invocation map so callers cannot
|
|
403
|
+
* accidentally fake a space prefix.
|
|
416
404
|
*/
|
|
417
|
-
declare function buildDecryptAttenuation(networkId: string
|
|
405
|
+
declare function buildDecryptAttenuation(networkId: string): Record<string, Record<string, Record<string, never>>>;
|
|
418
406
|
/**
|
|
419
407
|
* Validate a {@link BuildDecryptInvocationInput} payload — the body
|
|
420
408
|
* shape, the facts bindings, and the audience contract — without
|
|
@@ -496,4 +484,4 @@ declare function verifyDecryptResponse(input: VerifyDecryptResponseInput): {
|
|
|
496
484
|
*/
|
|
497
485
|
declare function openWrappedKey(crypto: EncryptionCrypto, receiverPrivateKey: Uint8Array, response: DecryptResponseBody): Uint8Array;
|
|
498
486
|
|
|
499
|
-
export { type BuildCanonicalDecryptRequestInput, type BuildDecryptFactsInput, BuildDecryptInvocationInput, BuiltDecryptInvocation, type CanonicalDecryptRequest, DecryptCapabilityProof, type DecryptEnvelopeOptions, DecryptInvocationFact, DecryptInvocationSigner, DecryptRequestBody, DecryptResponseBody, type DecryptTransport, type DiscoverNetworkInput, type DiscoveredNetwork, type DiscoverySource, ENCRYPTION_NETWORK_URN_PREFIX, type EncryptToNetworkInput, type EncryptToNetworkOptions, type EncryptToNetworkResult, EncryptionCrypto, EncryptionError, EncryptionService, type EncryptionServiceConfig, type IEncryptionService, InlineEncryptedEnvelope, NETWORK_NAME_PATTERN, NetworkDescriptor, NetworkIdError, type NodeDescriptorFetcher, type
|
|
487
|
+
export { type BuildCanonicalDecryptRequestInput, type BuildDecryptFactsInput, BuildDecryptInvocationInput, BuiltDecryptInvocation, type CanonicalDecryptRequest, DecryptCapabilityProof, type DecryptEnvelopeOptions, DecryptInvocationFact, DecryptInvocationSigner, DecryptRequestBody, DecryptResponseBody, type DecryptTransport, type DiscoverNetworkInput, type DiscoveredNetwork, type DiscoverySource, ENCRYPTION_NETWORK_URN_PREFIX, type EncryptToNetworkInput, type EncryptToNetworkOptions, type EncryptToNetworkResult, EncryptionCrypto, EncryptionError, EncryptionService, type EncryptionServiceConfig, type IEncryptionService, InlineEncryptedEnvelope, NETWORK_NAME_PATTERN, NetworkDescriptor, NetworkIdError, type NodeDescriptorFetcher, type ParsedNetworkId, type RandomReceiverKeyInput, ReceiverKeyPair, ReceiverKeySigner, type SignedReceiverKeyInput, type VerifyDecryptResponseInput, type WellKnownDescriptorFetcher, buildCanonicalDecryptRequest, buildDecryptAttenuation, buildDecryptFacts, buildDecryptInvocation, buildNetworkId, canonicalSignedResponse, checkDecryptInvocationInput, decryptEnvelopeWithKey, deriveSignedReceiverKey, discoverNetwork, encryptToNetwork, ensureNetworkUsableForDecrypt, generateRandomReceiverKey, isNetworkId, networkDiscoveryKey, openWrappedKey, parseNetworkId, validateEnvelope, verifyDecryptResponse };
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { B as BaseService } from '../BaseService-DO7vZ67k.js';
|
|
2
2
|
import { c as IService, h as Result } from '../types-DAOyIbXu.js';
|
|
3
|
-
import { N as NetworkDescriptor, n as EncryptionError, I as InlineEncryptedEnvelope, D as DecryptCapabilityProof, j as DecryptResponseBody, E as EncryptionCrypto, h as DecryptInvocationSigner, p as ReceiverKeySigner, R as ReceiverKeyPair, i as DecryptRequestBody, g as DecryptInvocationFact, B as BuildDecryptInvocationInput, a as BuiltDecryptInvocation } from '../types-
|
|
4
|
-
export { C as CanonicalJson, b as DECRYPT_ACTION, c as DECRYPT_FACT_TYPE, d as DECRYPT_RESULT_TYPE, e as DEFAULT_ENCRYPTION_ALG, f as DEFAULT_KEY_VERSION, k as ENCRYPTION_SERVICE, l as ENCRYPTION_SERVICE_SHORT, m as ENVELOPE_VERSION, o as EncryptionErrorInput, J as Json, q as base64Decode, r as base64Encode, s as canonicalHashHex, t as canonicalize, u as encryptionError, v as hexDecode, w as hexEncode, x as utf8Decode, y as utf8Encode } from '../types-
|
|
3
|
+
import { N as NetworkDescriptor, n as EncryptionError, I as InlineEncryptedEnvelope, D as DecryptCapabilityProof, j as DecryptResponseBody, E as EncryptionCrypto, h as DecryptInvocationSigner, p as ReceiverKeySigner, R as ReceiverKeyPair, i as DecryptRequestBody, g as DecryptInvocationFact, B as BuildDecryptInvocationInput, a as BuiltDecryptInvocation } from '../types-BGRzS1ob.js';
|
|
4
|
+
export { C as CanonicalJson, b as DECRYPT_ACTION, c as DECRYPT_FACT_TYPE, d as DECRYPT_RESULT_TYPE, e as DEFAULT_ENCRYPTION_ALG, f as DEFAULT_KEY_VERSION, k as ENCRYPTION_SERVICE, l as ENCRYPTION_SERVICE_SHORT, m as ENVELOPE_VERSION, o as EncryptionErrorInput, J as Json, q as base64Decode, r as base64Encode, s as canonicalHashHex, t as canonicalize, u as encryptionError, v as hexDecode, w as hexEncode, x as utf8Decode, y as utf8Encode } from '../types-BGRzS1ob.js';
|
|
5
5
|
export { DecryptTransportResponseError } from '@tinycloud/sdk-services/internal/decrypt-transport-response-error';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -85,8 +85,6 @@ declare function ensureNetworkUsableForDecrypt(descriptor: NetworkDescriptor): {
|
|
|
85
85
|
*/
|
|
86
86
|
|
|
87
87
|
interface EncryptToNetworkOptions {
|
|
88
|
-
/** Exact named-key path to bind into the returned envelope. */
|
|
89
|
-
keyPath?: string;
|
|
90
88
|
/** Optional associated authenticated data (bytes). */
|
|
91
89
|
aad?: Uint8Array;
|
|
92
90
|
/** Ciphersuite override. Defaults to the network's alg. */
|
|
@@ -219,17 +217,6 @@ declare class NetworkIdError extends Error {
|
|
|
219
217
|
* malformed, or when the network name fails {@link NETWORK_NAME_RE}.
|
|
220
218
|
*/
|
|
221
219
|
declare function parseNetworkId(networkId: string): ParsedNetworkId;
|
|
222
|
-
interface ParsedEncryptionResource extends ParsedNetworkId {
|
|
223
|
-
/** Named-key path, if the resource is scoped below a network. */
|
|
224
|
-
keyPath?: string;
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* Parse a network-root or named-key encryption resource.
|
|
228
|
-
*
|
|
229
|
-
* A trailing slash on keyPath denotes a prefix grant; empty and traversal
|
|
230
|
-
* segments are rejected so resource matching cannot escape the named path.
|
|
231
|
-
*/
|
|
232
|
-
declare function parseEncryptionResource(resource: string): ParsedEncryptionResource;
|
|
233
220
|
/**
|
|
234
221
|
* Construct a network id URN from an owner DID and a network name.
|
|
235
222
|
* Validates inputs and throws {@link NetworkIdError} on bad shape.
|
|
@@ -267,8 +254,6 @@ declare const NETWORK_NAME_PATTERN: RegExp;
|
|
|
267
254
|
interface EncryptToNetworkInput {
|
|
268
255
|
/** Target network id URN. */
|
|
269
256
|
networkId: string;
|
|
270
|
-
/** Exact named-key path; omitted for a network-root key. */
|
|
271
|
-
keyPath?: string;
|
|
272
257
|
/** Network public key bytes (already discovered). */
|
|
273
258
|
networkPublicKey: Uint8Array;
|
|
274
259
|
/** Payload bytes to encrypt. Callers serialize objects to bytes themselves. */
|
|
@@ -411,10 +396,13 @@ interface BuildDecryptFactsInput {
|
|
|
411
396
|
*/
|
|
412
397
|
declare function buildDecryptFacts(input: BuildDecryptFactsInput): DecryptInvocationFact;
|
|
413
398
|
/**
|
|
414
|
-
*
|
|
415
|
-
*
|
|
399
|
+
* Recap-shaped attenuation for the decrypt invocation. The resource
|
|
400
|
+
* key is the networkId URN; the ability is the long-form
|
|
401
|
+
* `tinycloud.encryption/decrypt`. This is intentionally distinct from
|
|
402
|
+
* the existing space-shaped invocation map so callers cannot
|
|
403
|
+
* accidentally fake a space prefix.
|
|
416
404
|
*/
|
|
417
|
-
declare function buildDecryptAttenuation(networkId: string
|
|
405
|
+
declare function buildDecryptAttenuation(networkId: string): Record<string, Record<string, Record<string, never>>>;
|
|
418
406
|
/**
|
|
419
407
|
* Validate a {@link BuildDecryptInvocationInput} payload — the body
|
|
420
408
|
* shape, the facts bindings, and the audience contract — without
|
|
@@ -496,4 +484,4 @@ declare function verifyDecryptResponse(input: VerifyDecryptResponseInput): {
|
|
|
496
484
|
*/
|
|
497
485
|
declare function openWrappedKey(crypto: EncryptionCrypto, receiverPrivateKey: Uint8Array, response: DecryptResponseBody): Uint8Array;
|
|
498
486
|
|
|
499
|
-
export { type BuildCanonicalDecryptRequestInput, type BuildDecryptFactsInput, BuildDecryptInvocationInput, BuiltDecryptInvocation, type CanonicalDecryptRequest, DecryptCapabilityProof, type DecryptEnvelopeOptions, DecryptInvocationFact, DecryptInvocationSigner, DecryptRequestBody, DecryptResponseBody, type DecryptTransport, type DiscoverNetworkInput, type DiscoveredNetwork, type DiscoverySource, ENCRYPTION_NETWORK_URN_PREFIX, type EncryptToNetworkInput, type EncryptToNetworkOptions, type EncryptToNetworkResult, EncryptionCrypto, EncryptionError, EncryptionService, type EncryptionServiceConfig, type IEncryptionService, InlineEncryptedEnvelope, NETWORK_NAME_PATTERN, NetworkDescriptor, NetworkIdError, type NodeDescriptorFetcher, type
|
|
487
|
+
export { type BuildCanonicalDecryptRequestInput, type BuildDecryptFactsInput, BuildDecryptInvocationInput, BuiltDecryptInvocation, type CanonicalDecryptRequest, DecryptCapabilityProof, type DecryptEnvelopeOptions, DecryptInvocationFact, DecryptInvocationSigner, DecryptRequestBody, DecryptResponseBody, type DecryptTransport, type DiscoverNetworkInput, type DiscoveredNetwork, type DiscoverySource, ENCRYPTION_NETWORK_URN_PREFIX, type EncryptToNetworkInput, type EncryptToNetworkOptions, type EncryptToNetworkResult, EncryptionCrypto, EncryptionError, EncryptionService, type EncryptionServiceConfig, type IEncryptionService, InlineEncryptedEnvelope, NETWORK_NAME_PATTERN, NetworkDescriptor, NetworkIdError, type NodeDescriptorFetcher, type ParsedNetworkId, type RandomReceiverKeyInput, ReceiverKeyPair, ReceiverKeySigner, type SignedReceiverKeyInput, type VerifyDecryptResponseInput, type WellKnownDescriptorFetcher, buildCanonicalDecryptRequest, buildDecryptAttenuation, buildDecryptFacts, buildDecryptInvocation, buildNetworkId, canonicalSignedResponse, checkDecryptInvocationInput, decryptEnvelopeWithKey, deriveSignedReceiverKey, discoverNetwork, encryptToNetwork, ensureNetworkUsableForDecrypt, generateRandomReceiverKey, isNetworkId, networkDiscoveryKey, openWrappedKey, parseNetworkId, validateEnvelope, verifyDecryptResponse };
|
package/dist/encryption/index.js
CHANGED
|
@@ -135,26 +135,6 @@ function parseNetworkId(networkId) {
|
|
|
135
135
|
}
|
|
136
136
|
return { networkId, ownerDid, name };
|
|
137
137
|
}
|
|
138
|
-
function parseEncryptionResource(resource) {
|
|
139
|
-
const networkSeparator = resource.lastIndexOf(":");
|
|
140
|
-
const nameAndPath = resource.slice(networkSeparator + 1);
|
|
141
|
-
const pathSeparator = nameAndPath.indexOf("/");
|
|
142
|
-
const name = pathSeparator === -1 ? nameAndPath : nameAndPath.slice(0, pathSeparator);
|
|
143
|
-
const networkId = pathSeparator === -1 ? resource : `${resource.slice(0, networkSeparator + 1)}${name}`;
|
|
144
|
-
const parsed = parseNetworkId(networkId);
|
|
145
|
-
if (pathSeparator === -1) return parsed;
|
|
146
|
-
const keyPath = nameAndPath.slice(pathSeparator + 1);
|
|
147
|
-
const segments = keyPath.split("/");
|
|
148
|
-
const prefix = keyPath.endsWith("/");
|
|
149
|
-
if (keyPath.length === 0 || /[\u0000-\u001f\u007f\\]/.test(keyPath) || segments.some(
|
|
150
|
-
(segment, index) => segment === "." || segment === ".." || segment.length === 0 && !(prefix && index === segments.length - 1)
|
|
151
|
-
)) {
|
|
152
|
-
throw new NetworkIdError(
|
|
153
|
-
`encryption resource has an invalid keyPath (got ${JSON.stringify(resource)})`
|
|
154
|
-
);
|
|
155
|
-
}
|
|
156
|
-
return { ...parsed, keyPath };
|
|
157
|
-
}
|
|
158
138
|
function buildNetworkId(ownerDid, name) {
|
|
159
139
|
if (typeof ownerDid !== "string" || !ownerDid.startsWith("did:")) {
|
|
160
140
|
throw new NetworkIdError("ownerDid must be a DID");
|
|
@@ -867,12 +847,7 @@ function ensureNetworkUsableForDecrypt(descriptor) {
|
|
|
867
847
|
|
|
868
848
|
// src/encryption/envelope.ts
|
|
869
849
|
function encryptToNetwork(crypto, input) {
|
|
870
|
-
|
|
871
|
-
input.keyPath === void 0 ? input.networkId : `${input.networkId}/${input.keyPath}`
|
|
872
|
-
);
|
|
873
|
-
if (parsedResource.keyPath !== input.keyPath || input.keyPath?.endsWith("/")) {
|
|
874
|
-
throw new NetworkIdError("keyPath must name an exact encryption key");
|
|
875
|
-
}
|
|
850
|
+
parseNetworkId(input.networkId);
|
|
876
851
|
const alg = input.alg ?? DEFAULT_ENCRYPTION_ALG;
|
|
877
852
|
const keyVersion = input.keyVersion ?? DEFAULT_KEY_VERSION;
|
|
878
853
|
const symmetricKey = crypto.randomBytes(32);
|
|
@@ -886,7 +861,6 @@ function encryptToNetwork(crypto, input) {
|
|
|
886
861
|
const envelope = {
|
|
887
862
|
v: ENVELOPE_VERSION,
|
|
888
863
|
networkId: input.networkId,
|
|
889
|
-
...input.keyPath !== void 0 ? { keyPath: input.keyPath } : {},
|
|
890
864
|
alg,
|
|
891
865
|
keyVersion,
|
|
892
866
|
encryptedSymmetricKey,
|
|
@@ -918,24 +892,13 @@ function validateEnvelope(crypto, envelope) {
|
|
|
918
892
|
};
|
|
919
893
|
}
|
|
920
894
|
try {
|
|
921
|
-
|
|
922
|
-
throw new Error("networkId must identify the network root");
|
|
923
|
-
}
|
|
924
|
-
if (e.keyPath !== void 0) {
|
|
925
|
-
if (typeof e.keyPath !== "string") {
|
|
926
|
-
throw new Error("keyPath must be a string");
|
|
927
|
-
}
|
|
928
|
-
const parsed = parseEncryptionResource(`${e.networkId}/${e.keyPath}`);
|
|
929
|
-
if (parsed.keyPath !== e.keyPath || e.keyPath.endsWith("/")) {
|
|
930
|
-
throw new Error("keyPath must name an exact encryption key");
|
|
931
|
-
}
|
|
932
|
-
}
|
|
895
|
+
parseNetworkId(e.networkId);
|
|
933
896
|
} catch (err2) {
|
|
934
897
|
return {
|
|
935
898
|
ok: false,
|
|
936
899
|
error: encryptionError({
|
|
937
900
|
code: "INVALID_ENVELOPE",
|
|
938
|
-
message: `envelope
|
|
901
|
+
message: `envelope.networkId is malformed: ${err2 instanceof Error ? err2.message : String(err2)}`
|
|
939
902
|
})
|
|
940
903
|
};
|
|
941
904
|
}
|
|
@@ -1008,7 +971,6 @@ function buildDecryptFacts(input) {
|
|
|
1008
971
|
type: DECRYPT_FACT_TYPE,
|
|
1009
972
|
targetNode: input.body.targetNode,
|
|
1010
973
|
networkId: input.body.networkId,
|
|
1011
|
-
...input.body.keyPath !== void 0 ? { keyPath: input.body.keyPath } : {},
|
|
1012
974
|
bodyHash,
|
|
1013
975
|
encryptedSymmetricKeyHash: input.encryptedSymmetricKeyHash,
|
|
1014
976
|
receiverPublicKeyHash,
|
|
@@ -1016,14 +978,10 @@ function buildDecryptFacts(input) {
|
|
|
1016
978
|
keyVersion: input.body.keyVersion
|
|
1017
979
|
};
|
|
1018
980
|
}
|
|
1019
|
-
function buildDecryptAttenuation(networkId
|
|
1020
|
-
|
|
1021
|
-
const parsed = parseEncryptionResource(resource);
|
|
1022
|
-
if (parsed.networkId !== networkId || parsed.keyPath !== keyPath || keyPath?.endsWith("/")) {
|
|
1023
|
-
throw new NetworkIdError("keyPath must name an exact encryption key");
|
|
1024
|
-
}
|
|
981
|
+
function buildDecryptAttenuation(networkId) {
|
|
982
|
+
parseNetworkId(networkId);
|
|
1025
983
|
return {
|
|
1026
|
-
[
|
|
984
|
+
[networkId]: {
|
|
1027
985
|
[DECRYPT_ACTION]: {}
|
|
1028
986
|
}
|
|
1029
987
|
};
|
|
@@ -1083,15 +1041,6 @@ function checkDecryptInvocationInput(crypto, input) {
|
|
|
1083
1041
|
})
|
|
1084
1042
|
};
|
|
1085
1043
|
}
|
|
1086
|
-
if (input.facts.keyPath !== input.body.keyPath) {
|
|
1087
|
-
return {
|
|
1088
|
-
ok: false,
|
|
1089
|
-
error: encryptionError({
|
|
1090
|
-
code: "INVALID_INPUT",
|
|
1091
|
-
message: "facts.keyPath must equal body.keyPath"
|
|
1092
|
-
})
|
|
1093
|
-
};
|
|
1094
|
-
}
|
|
1095
1044
|
if (input.facts.alg !== input.body.alg) {
|
|
1096
1045
|
return {
|
|
1097
1046
|
ok: false,
|
|
@@ -1129,9 +1078,7 @@ function checkDecryptInvocationInput(crypto, input) {
|
|
|
1129
1078
|
};
|
|
1130
1079
|
}
|
|
1131
1080
|
try {
|
|
1132
|
-
|
|
1133
|
-
throw new NetworkIdError("networkId must identify the network root");
|
|
1134
|
-
}
|
|
1081
|
+
parseNetworkId(input.networkId);
|
|
1135
1082
|
} catch (err2) {
|
|
1136
1083
|
return {
|
|
1137
1084
|
ok: false,
|
|
@@ -1141,22 +1088,6 @@ function checkDecryptInvocationInput(crypto, input) {
|
|
|
1141
1088
|
})
|
|
1142
1089
|
};
|
|
1143
1090
|
}
|
|
1144
|
-
try {
|
|
1145
|
-
const resource = parseEncryptionResource(
|
|
1146
|
-
input.body.keyPath === void 0 ? input.body.networkId : `${input.body.networkId}/${input.body.keyPath}`
|
|
1147
|
-
);
|
|
1148
|
-
if (resource.keyPath !== input.body.keyPath || input.body.keyPath?.endsWith("/")) {
|
|
1149
|
-
throw new NetworkIdError("keyPath must name an exact encryption key");
|
|
1150
|
-
}
|
|
1151
|
-
} catch (err2) {
|
|
1152
|
-
return {
|
|
1153
|
-
ok: false,
|
|
1154
|
-
error: encryptionError({
|
|
1155
|
-
code: "INVALID_INPUT",
|
|
1156
|
-
message: err2 instanceof Error ? err2.message : String(err2)
|
|
1157
|
-
})
|
|
1158
|
-
};
|
|
1159
|
-
}
|
|
1160
1091
|
const canonicalBody = canonicalize(
|
|
1161
1092
|
input.body
|
|
1162
1093
|
);
|
|
@@ -1397,7 +1328,6 @@ var EncryptionService = class extends BaseService {
|
|
|
1397
1328
|
// that spelling in the envelope so a later response can be compared
|
|
1398
1329
|
// byte-for-byte (notably for checksummed did:pkh principals).
|
|
1399
1330
|
networkId: descriptor.networkId,
|
|
1400
|
-
...options?.keyPath !== void 0 ? { keyPath: options.keyPath } : {},
|
|
1401
1331
|
networkPublicKey,
|
|
1402
1332
|
plaintext,
|
|
1403
1333
|
...options?.aad !== void 0 ? { aad: options.aad } : {},
|
|
@@ -1457,7 +1387,6 @@ var EncryptionService = class extends BaseService {
|
|
|
1457
1387
|
type: DECRYPT_FACT_TYPE,
|
|
1458
1388
|
targetNode,
|
|
1459
1389
|
networkId: envelope.networkId,
|
|
1460
|
-
...envelope.keyPath !== void 0 ? { keyPath: envelope.keyPath } : {},
|
|
1461
1390
|
alg: envelope.alg,
|
|
1462
1391
|
keyVersion: envelope.keyVersion,
|
|
1463
1392
|
encryptedSymmetricKey: envelope.encryptedSymmetricKey,
|
|
@@ -1601,7 +1530,6 @@ export {
|
|
|
1601
1530
|
isNetworkId,
|
|
1602
1531
|
networkDiscoveryKey,
|
|
1603
1532
|
openWrappedKey,
|
|
1604
|
-
parseEncryptionResource,
|
|
1605
1533
|
parseNetworkId,
|
|
1606
1534
|
utf8Decode,
|
|
1607
1535
|
utf8Encode,
|