@vizamodo/aws-sts-core 0.4.11 → 0.4.12

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.
Files changed (2) hide show
  1. package/dist/sts/issue.js +20 -14
  2. package/package.json +1 -1
package/dist/sts/issue.js CHANGED
@@ -44,24 +44,30 @@ async function getSigningMaterial(certBase64, privateKeyPkcs8Base64) {
44
44
  cachedPrivateKeyBase64 === privateKeyPkcs8Base64) {
45
45
  return cachedSigningKey;
46
46
  }
47
- // FIX 2: cache vars updated inside .then() no race condition.
48
- signingKeyPromise = null;
49
- cachedSigningKey = null;
50
- cachedCertBase64 = null;
51
- cachedPrivateKeyBase64 = null;
52
- signingKeyPromise = crypto.subtle
53
- .importKey("pkcs8", base64ToBytes(privateKeyPkcs8Base64), { name: "ECDSA", namedCurve: "P-256" }, false, ["sign"])
54
- .then((key) => {
55
- cachedSigningKey = key;
47
+ // Material rotated discard the stale resolved key so we re-import.
48
+ if (cachedSigningKey) {
49
+ signingKeyPromise = null;
50
+ cachedSigningKey = null;
51
+ }
52
+ if (!signingKeyPromise) {
53
+ try {
54
+ const keyBuffer = base64ToBytes(privateKeyPkcs8Base64);
55
+ signingKeyPromise = crypto.subtle.importKey("pkcs8", keyBuffer, { name: "ECDSA", namedCurve: "P-256" }, false, ["sign"]);
56
+ }
57
+ catch {
58
+ throw new InternalError("invalid_signing_material");
59
+ }
60
+ }
61
+ try {
62
+ cachedSigningKey = await signingKeyPromise;
56
63
  cachedCertBase64 = certBase64;
57
64
  cachedPrivateKeyBase64 = privateKeyPkcs8Base64;
58
- return key;
59
- })
60
- .catch(() => {
65
+ return cachedSigningKey;
66
+ }
67
+ catch {
61
68
  signingKeyPromise = null;
62
69
  throw new InternalError("invalid_signing_material");
63
- });
64
- return signingKeyPromise;
70
+ }
65
71
  }
66
72
  // ── Session TTL ────────────────────────────────────────────────────────────
67
73
  function resolveSessionTtl(profile) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizamodo/aws-sts-core",
3
- "version": "0.4.11",
3
+ "version": "0.4.12",
4
4
  "description": "Pure AWS STS + SigV4 (X509 Roles Anywhere) core logic",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",