@vizamodo/aws-sts-core 0.4.24 → 0.4.25

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 +42 -42
  2. package/package.json +1 -1
package/dist/sts/issue.js CHANGED
@@ -89,49 +89,49 @@ export async function issueAwsCredentials(input) {
89
89
  cachedCertSerialSource = normalizedCert;
90
90
  }
91
91
  const cacheKey = `${region}|${roleArn}|${profileArn}|${trustAnchorArn}|${certSerialDec}`;
92
- // ---- Build SigV4 request ----
93
- const { signingKey } = await getSigningMaterial({
94
- certBase64: normalizedCert,
95
- privateKeyPkcs8Base64,
96
- });
97
- const host = `${SERVICE}.${region}.amazonaws.com`;
98
- const iso = new Date().toISOString();
99
- const amzDate = isoToAmzDate(iso);
100
- const dateStamp = iso.slice(0, 4) + iso.slice(5, 7) + iso.slice(8, 10);
101
- const body = JSON.stringify({ trustAnchorArn, profileArn, roleArn, durationSeconds: sessionTtl });
102
- const payloadHash = await sha256Hex(body);
103
- const baseHeaders = {
104
- "content-type": "application/json",
105
- "host": host,
106
- "x-amz-date": amzDate,
107
- "x-amz-x509": normalizedCert,
108
- };
109
- const { canonicalHeaders, signedHeaders } = canonicalizeHeaders(baseHeaders);
110
- const credentialScope = `${dateStamp}/${region}/${SERVICE}/aws4_request`;
111
- const canonicalRequest = buildCanonicalRequest({
112
- method: "POST",
113
- canonicalUri: PATH,
114
- query: "",
115
- canonicalHeaders,
116
- signedHeaders,
117
- payloadHash,
118
- });
119
- const canonicalRequestHash = await sha256Hex(canonicalRequest);
120
- const stringToSign = buildStringToSign({
121
- algorithm: ALGORITHM,
122
- amzDate,
123
- credentialScope,
124
- canonicalRequestHash,
125
- });
126
- const signatureHex = await signStringToSign(stringToSign, signingKey);
127
- const finalHeaders = new Headers({
128
- "Content-Type": "application/json",
129
- "X-Amz-Date": amzDate,
130
- "X-Amz-X509": normalizedCert,
131
- "Authorization": `${ALGORITHM} Credential=${certSerialDec}/${credentialScope}, SignedHeaders=${signedHeaders}, Signature=${signatureHex}`,
132
- });
133
- const issuedAt = Date.now(); // snapshot before the network round-trip
134
92
  return getCachedOrFetch(cacheKey, async () => {
93
+ // ---- Build SigV4 request (moved inside fetcher) ----
94
+ const { signingKey } = await getSigningMaterial({
95
+ certBase64: normalizedCert,
96
+ privateKeyPkcs8Base64,
97
+ });
98
+ const host = `${SERVICE}.${region}.amazonaws.com`;
99
+ const iso = new Date().toISOString();
100
+ const amzDate = isoToAmzDate(iso);
101
+ const dateStamp = iso.slice(0, 4) + iso.slice(5, 7) + iso.slice(8, 10);
102
+ const body = JSON.stringify({ trustAnchorArn, profileArn, roleArn, durationSeconds: sessionTtl });
103
+ const payloadHash = await sha256Hex(body);
104
+ const baseHeaders = {
105
+ "content-type": "application/json",
106
+ "host": host,
107
+ "x-amz-date": amzDate,
108
+ "x-amz-x509": normalizedCert,
109
+ };
110
+ const { canonicalHeaders, signedHeaders } = canonicalizeHeaders(baseHeaders);
111
+ const credentialScope = `${dateStamp}/${region}/${SERVICE}/aws4_request`;
112
+ const canonicalRequest = buildCanonicalRequest({
113
+ method: "POST",
114
+ canonicalUri: PATH,
115
+ query: "",
116
+ canonicalHeaders,
117
+ signedHeaders,
118
+ payloadHash,
119
+ });
120
+ const canonicalRequestHash = await sha256Hex(canonicalRequest);
121
+ const stringToSign = buildStringToSign({
122
+ algorithm: ALGORITHM,
123
+ amzDate,
124
+ credentialScope,
125
+ canonicalRequestHash,
126
+ });
127
+ const signatureHex = await signStringToSign(stringToSign, signingKey);
128
+ const finalHeaders = new Headers({
129
+ "Content-Type": "application/json",
130
+ "X-Amz-Date": amzDate,
131
+ "X-Amz-X509": normalizedCert,
132
+ "Authorization": `${ALGORITHM} Credential=${certSerialDec}/${credentialScope}, SignedHeaders=${signedHeaders}, Signature=${signatureHex}`,
133
+ });
134
+ const issuedAt = Date.now();
135
135
  const res = await fetch(`https://${host}${PATH}`, {
136
136
  method: "POST",
137
137
  headers: finalHeaders,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizamodo/aws-sts-core",
3
- "version": "0.4.24",
3
+ "version": "0.4.25",
4
4
  "description": "Pure AWS STS + SigV4 (X509 Roles Anywhere) core logic",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",