Skip to content

Commit 32d9b59

Browse files
committed
Match upstream code from W3C VC WG repo.
Not much variation. Mostly comments. Key change is adding `localSettings` export.
1 parent b517a96 commit 32d9b59

File tree

2 files changed

+38
-19
lines changed

2 files changed

+38
-19
lines changed

lib/main.js

+9-7
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
import {Implementation} from './Implementation.js';
88
import {implementerFiles} from '../implementations/index.js';
9-
export {Endpoint} from './Endpoint.js';
109

1110
const keyValues = implementerFiles.map(
1211
implementation => [implementation.name, new Implementation(implementation)]);
1312

13+
export {localSettings} from '../implementations/index.js';
1414
export const implementations = new Map(keyValues);
1515
export const allImplementations = implementations;
1616

@@ -25,9 +25,9 @@ export const allImplementations = implementations;
2525
* @param {Map} [options.implementations=allImplementations] - A Map of
2626
* implementations.
2727
* @param {Function<boolean>} options.filter - A function to
28-
* filter the map's entries on that returns true or false.
28+
* filter the map's entries on that returns true or false.
2929
*
30-
* @returns {{match: Map, nonMatch: Map}} Returns an object with matching
30+
* @returns {Object<string, Map>} Returns an object with matching
3131
* and non-matching maps.
3232
*/
3333
export const filterImplementations = ({
@@ -50,7 +50,7 @@ export const filterImplementations = ({
5050
/**
5151
* Filters implementations by tags on a property in the settings.
5252
*
53-
* @example filterByTag({property: 'issuers', tags: ['VC-HTTP-API']})
53+
* @example filterByTag({property: 'issuers', tags: ['ecdsa-rdfc-2019']})
5454
*
5555
* @param {object} options - Options to use.
5656
* @param {Map} [options.implementations=allImplementations] -
@@ -59,7 +59,7 @@ export const filterImplementations = ({
5959
* @param {string} [options.property='issuers'] - The property to search for on
6060
* an implementation.
6161
*
62-
* @returns {{match: Map, nonMatch: Map}} Returns an object with matching
62+
* @returns {Object<string, Map>} Returns an object with matching
6363
* and non-matching maps.
6464
*/
6565
export const filterByTag = ({
@@ -87,7 +87,7 @@ export const endpoints = {
8787
* @param {Map} [options.implementations=allImplementations] - A Map of
8888
* implementations.
8989
* @param {Function<boolean>} options.filter - A function to
90-
* filter the map's entries that returns true or false.
90+
* filter the map's entries that returns true or false.
9191
*
9292
* @returns {{match: Map, nonMatch: Map}} Returns an object with matching
9393
* and non-matching Maps with respective endpoints.
@@ -111,7 +111,9 @@ export const endpoints = {
111111
/**
112112
* Filters endpoints by tags on a property in the settings.
113113
*
114-
* @example endpoints.filterByTag({property: 'issuers', tags: ['vc-api']})
114+
* @example endpoints.filterByTag({
115+
* property: 'issuers', tags: ['ecdsa-rdfc-2019']
116+
* })
115117
*
116118
* @param {object} options - Options to use.
117119
* @param {Map} [options.implementations=allImplementations] -

lib/requests.js

+29-12
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,12 @@ export async function makeHttpsRequest({
5050
body, method, json, headers, agent, searchParams
5151
});
5252
} catch(e) {
53-
error = _sanitizeErrorHeaders({error: e});
53+
error = _sanitizeError({error: e});
5454
}
5555
const {data, statusCode} = _getDataAndStatus({result, error});
5656
// if a result is returned sanitize it
5757
if(result) {
58-
result = _sanitizeResponseHeaders({response: result, data});
58+
result = _sanitizeResponse({response: result, data});
5959
}
6060
return {result, error, data, statusCode};
6161
}
@@ -91,12 +91,12 @@ export async function zcapRequest({
9191
capability
9292
});
9393
} catch(e) {
94-
error = _sanitizeErrorHeaders({error: e});
94+
error = _sanitizeError({error: e});
9595
}
9696
const {data, statusCode} = _getDataAndStatus({result, error});
9797
// if a result is returned sanitize it
9898
if(result) {
99-
result = _sanitizeResponseHeaders({response: result, data});
99+
result = _sanitizeResponse({response: result, data});
100100
}
101101
return {result, error, data, statusCode};
102102
}
@@ -114,7 +114,7 @@ async function _getZcapClient({secretKeySeed}) {
114114

115115
function _getDataAndStatus({result = {}, error = {}}) {
116116
let data = result.data || error.data;
117-
// FIXME remove this once VC-API returns from the issuer
117+
// FIXME remove this once data returned from the issuers
118118
// are finalized.
119119
if(data && data.verifiableCredential) {
120120
data = data.verifiableCredential;
@@ -123,22 +123,20 @@ function _getDataAndStatus({result = {}, error = {}}) {
123123
return {data, statusCode};
124124
}
125125

126-
function _sanitizeErrorHeaders({error}) {
126+
function _sanitizeError({error}) {
127127
if(error.response) {
128-
error.response = _sanitizeResponseHeaders({
128+
error.response = _sanitizeResponse({
129129
response: error.response,
130130
data: error.data
131131
});
132132
}
133133
if(error.request) {
134-
error.request = new global.Request(error.request, {
135-
headers: _sanitizeHeaders({httpMessage: error.request})
136-
});
134+
error.request = _sanitizeRequest({request: error.request});
137135
}
138136
return error;
139137
}
140138

141-
function _sanitizeResponseHeaders({response, data}) {
139+
function _sanitizeResponse({response, data}) {
142140
const newResponse = new global.Response(JSON.stringify(data), {
143141
headers: _sanitizeHeaders({httpMessage: response}),
144142
status: response.status,
@@ -152,6 +150,25 @@ function _sanitizeResponseHeaders({response, data}) {
152150
return newResponse;
153151
}
154152

153+
function _sanitizeRequest({request}) {
154+
// get the url and the remaining properties from the request
155+
const {url, ...props} = request;
156+
// create an options object to pass to the new request
157+
const options = {};
158+
// do not copy these properties from the request
159+
const skipKeys = new Set(['body', 'headers']);
160+
for(const key in props) {
161+
if(skipKeys.has(key)) {
162+
continue;
163+
}
164+
options[key] = request[key];
165+
}
166+
return new global.Request(url, {
167+
...options,
168+
headers: _sanitizeHeaders({httpMessage: request})
169+
});
170+
}
171+
155172
/**
156173
* Takes in either a response or request & sanitizes the headers.
157174
*
@@ -174,7 +191,7 @@ function _sanitizeHeaders({httpMessage, headers = sanitizeHeaders}) {
174191
for(const header of headers) {
175192
// sanitize the headers to prevent
176193
// authn tokens / information potentially in logs
177-
newHeaders.set(header, '** SANITIZED TO PREVENT EXPOSING OF SECRETS ***');
194+
newHeaders.set(header, 'sanitized to prevent exposure of secrets');
178195
}
179196
return newHeaders;
180197
}

0 commit comments

Comments
 (0)