MCPcopy Create free account
hub / github.com/Kilo-Org/cloud / decryptKeyedEnvelope

Function decryptKeyedEnvelope

packages/encryption/src/keyed-envelope.ts:96–112  ·  view source on GitHub ↗
(
  serialized: string,
  scheme: Scheme,
  keys: EnvelopePrivateKeySlots,
  aad?: string
)

Source from the content-addressed store, hash-verified

94}
95
96export function decryptKeyedEnvelope<Scheme extends string>(
97 serialized: string,
98 scheme: Scheme,
99 keys: EnvelopePrivateKeySlots,
100 aad?: string
101): string {
102 const envelope = parseKeyedEnvelope(serialized, scheme);
103 const key = selectPrivateKey(envelope.keyId, keys);
104
105 if (!key.privateKeyPem) {
106 throw new EncryptionConfigurationError(
107 `Private key is not configured for keyed envelope key ID: ${envelope.keyId}`
108 );
109 }
110
111 return decryptWithPrivateKey(envelope.ciphertext, key.privateKeyPem, aad);
112}
113
114function selectPrivateKey(keyId: string, keys: EnvelopePrivateKeySlots): EnvelopePrivateKeySlot {
115 const decryptSlot = keys.decrypt?.find(slot => slot.keyId === keyId);

Callers 11

decryptSecretFunction · 0.90
handleProviderCallbackFunction · 0.90
decryptGrantFunction · 0.90
decryptConfigSecretFunction · 0.90
decryptProviderGrantFunction · 0.90
decryptMethod · 0.90
decryptCredentialMethod · 0.90
decryptCredentialMethod · 0.90

Calls 3

decryptWithPrivateKeyFunction · 0.90
parseKeyedEnvelopeFunction · 0.85
selectPrivateKeyFunction · 0.85

Tested by

no test coverage detected