Skip to content

Commit

Permalink
fix(js-runtime,cli,serverless): SubtleCrypto#importKey re-uses key …
Browse files Browse the repository at this point in the history
…data (#860)
  • Loading branch information
QuiiBz authored May 13, 2023
1 parent 859777e commit f3ee3c4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
7 changes: 7 additions & 0 deletions .changeset/gold-falcons-tie.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@lagon/cli': patch
'@lagon/serverless': patch
'@lagon/js-runtime': patch
---

`SubtleCrypto#importKey` re-use key data
13 changes: 10 additions & 3 deletions packages/js-runtime/src/runtime/global/crypto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
interface CryptoKey {
readonly keyValue: ArrayBuffer;
keyValue: ArrayBuffer;
}

/* eslint-disable @typescript-eslint/no-unused-vars */
Expand Down Expand Up @@ -132,7 +132,7 @@ interface CryptoKey {
readonly usages: KeyUsage[];

// Store the randomly generate key value here
readonly keyValue: ArrayBuffer;
keyValue: ArrayBuffer;

// Trick to make TypeScript happy, CryptoKey constructor is normally empty
// but we need to construct it at some point.
Expand Down Expand Up @@ -265,7 +265,14 @@ interface CryptoKey {
keyUsages: ReadonlyArray<KeyUsage> | Iterable<KeyUsage>,
): Promise<CryptoKey> {
// @ts-expect-error CryptoKey constructor is empty, but we know our implementation is not
return new CryptoKey(algorithm, extractable, 'secret', keyUsages);
const cryptoKey = new CryptoKey(algorithm, extractable, 'secret', keyUsages);

if (format === 'raw') {
// @ts-expect-error wrong format
cryptoKey.keyValue = keyData;
}

return cryptoKey;
}

async sign(
Expand Down

0 comments on commit f3ee3c4

Please sign in to comment.