Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Match W3C VC WG repo. #122

Merged
merged 7 commits into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
/*
* Copyright 2024 Digital Bazaar, Inc.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

module.exports = {
root: true,
extends: [
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Node.js CI
name: Lint and Test

on: [push]

Expand Down
107 changes: 0 additions & 107 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,108 +1 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
lerna-debug.log*

# Diagnostic reports (https://nodejs.org/api/report.html)
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage
*.lcov

# nyc test coverage
.nyc_output

# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/
jspm_packages/

# TypeScript v1 declaration files
typings/

# TypeScript cache
*.tsbuildinfo

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
.env.test

# parcel-bundler cache (https://parceljs.org/)
.cache

# Next.js build output
.next

# Nuxt.js build / generate output
.nuxt
dist

# Gatsby files
.cache/
# Comment in the public line in if your project uses Gatsby and *not* Next.js
# https://nextjs.org/blog/next-9-1#public-directory-support
# public

# vuepress build output
.vuepress/dist

# Serverless directories
.serverless/

# FuseBox cache
.fusebox/

# DynamoDB Local files
.dynamodb/

# TernJS port file
.tern-port

# Editor files
*~
*.sw[nop]
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<!--
Copyright 2023 - 2024 Digital Bazaar, Inc.

SPDX-License-Identifier: BSD-3-Clause
-->

# vc-test-suite-implementations Changelog

## 4.0.0 - 2024-01-TBD
Expand Down
3 changes: 1 addition & 2 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
BSD 3-Clause License

Copyright (c) 2022, Digital Bazaar, Inc.
All rights reserved.
Copyright (c) 2023-2024, World Wide Web Consortium

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!--
Copyright 2025 Digital Bazaar, Inc.
Copyright 2024 Digital Bazaar, Inc.

SPDX-License-Identifier: BSD-3-Clause
-->
Expand Down
7 changes: 5 additions & 2 deletions lib/Endpoint.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/*!
* Copyright (c) 2022 Digital Bazaar, Inc. All rights reserved.
/*
* Copyright 2022-2024 Digital Bazaar, Inc.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

import {makeHttpsRequest, zcapRequest} from './requests.js';

/**
Expand Down
7 changes: 5 additions & 2 deletions lib/Implementation.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/*!
* Copyright (c) 2022 Digital Bazaar, Inc. All rights reserved.
/*
* Copyright 2022-2024 Digital Bazaar, Inc.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

import {Endpoint} from './Endpoint.js';

export class Implementation {
Expand Down
7 changes: 5 additions & 2 deletions lib/constants.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/*!
* Copyright (c) 2022 Digital Bazaar, Inc. All rights reserved.
/*
* Copyright 2022-2024 Digital Bazaar, Inc.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

import * as didKey from '@digitalbazaar/did-method-key';
import https from 'https';

Expand Down
23 changes: 14 additions & 9 deletions lib/main.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
/*!
* Copyright (c) 2022 Digital Bazaar, Inc. All rights reserved.
/*
* Copyright 2022-2024 Digital Bazaar, Inc.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

import {Implementation} from './Implementation.js';
import {implementerFiles} from '../implementations/index.js';
export {Endpoint} from './Endpoint.js';

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

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

Expand All @@ -22,9 +25,9 @@
* @param {Map} [options.implementations=allImplementations] - A Map of
* implementations.
* @param {Function<boolean>} options.filter - A function to
* filter the map's entries on that returns true or false.
* filter the map's entries, that returns true or false.
*
* @returns {{match: Map, nonMatch: Map}} Returns an object with matching
* @returns {Object<string, Map>} Returns an object with matching

Check warning on line 30 in lib/main.js

View workflow job for this annotation

GitHub Actions / lint (20.x)

Use object shorthand or index signatures instead of `Object`, e.g., `{[key: string]: string}`
* and non-matching maps.
*/
export const filterImplementations = ({
Expand All @@ -47,7 +50,7 @@
/**
* Filters implementations by tags on a property in the settings.
*
* @example filterByTag({property: 'issuers', tags: ['VC-HTTP-API']})
* @example filterByTag({property: 'issuers', tags: ['ecdsa-rdfc-2019']})
*
* @param {object} options - Options to use.
* @param {Map} [options.implementations=allImplementations] -
Expand All @@ -56,7 +59,7 @@
* @param {string} [options.property='issuers'] - The property to search for on
* an implementation.
*
* @returns {{match: Map, nonMatch: Map}} Returns an object with matching
* @returns {Object<string, Map>} Returns an object with matching

Check warning on line 62 in lib/main.js

View workflow job for this annotation

GitHub Actions / lint (20.x)

Use object shorthand or index signatures instead of `Object`, e.g., `{[key: string]: string}`
* and non-matching maps.
*/
export const filterByTag = ({
Expand Down Expand Up @@ -84,7 +87,7 @@
* @param {Map} [options.implementations=allImplementations] - A Map of
* implementations.
* @param {Function<boolean>} options.filter - A function to
* filter the map's entries that returns true or false.
* filter the map's entries, that returns true or false.
*
* @returns {{match: Map, nonMatch: Map}} Returns an object with matching
* and non-matching Maps with respective endpoints.
Expand All @@ -108,7 +111,9 @@
/**
* Filters endpoints by tags on a property in the settings.
*
* @example endpoints.filterByTag({property: 'issuers', tags: ['vc-api']})
* @example endpoints.filterByTag({
* property: 'issuers', tags: ['ecdsa-rdfc-2019']
* })
*
* @param {object} options - Options to use.
* @param {Map} [options.implementations=allImplementations] -
Expand Down
7 changes: 5 additions & 2 deletions lib/oauth2.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/*!
* Copyright (c) 2022 Digital Bazaar, Inc. All rights reserved.
/*
* Copyright 2022-2024 Digital Bazaar, Inc.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

import LruCache from 'lru-cache';
import {makeHttpsRequest} from './requests.js';

Expand Down
48 changes: 34 additions & 14 deletions lib/requests.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
/*!
* Copyright (c) 2022 Digital Bazaar, Inc. All rights reserved.
/*
* Copyright 2022-2024 Digital Bazaar, Inc.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

import {
agent,
defaultHeaders,
Expand Down Expand Up @@ -47,12 +50,12 @@ export async function makeHttpsRequest({
body, method, json, headers, agent, searchParams
});
} catch(e) {
error = _sanitizeErrorHeaders({error: e});
error = _sanitizeError({error: e});
}
const {data, statusCode} = _getDataAndStatus({result, error});
// if a result is returned sanitize it
if(result) {
result = _sanitizeResponseHeaders({response: result, data});
result = _sanitizeResponse({response: result, data});
}
return {result, error, data, statusCode};
}
Expand Down Expand Up @@ -88,12 +91,12 @@ export async function zcapRequest({
capability
});
} catch(e) {
error = _sanitizeErrorHeaders({error: e});
error = _sanitizeError({error: e});
}
const {data, statusCode} = _getDataAndStatus({result, error});
// if a result is returned sanitize it
if(result) {
result = _sanitizeResponseHeaders({response: result, data});
result = _sanitizeResponse({response: result, data});
}
return {result, error, data, statusCode};
}
Expand All @@ -111,7 +114,7 @@ async function _getZcapClient({secretKeySeed}) {

function _getDataAndStatus({result = {}, error = {}}) {
let data = result.data || error.data;
// FIXME remove this once VC-API returns from the issuer
// FIXME remove this once data returned from the issuers
// are finalized.
if(data && data.verifiableCredential) {
data = data.verifiableCredential;
Expand All @@ -120,22 +123,20 @@ function _getDataAndStatus({result = {}, error = {}}) {
return {data, statusCode};
}

function _sanitizeErrorHeaders({error}) {
function _sanitizeError({error}) {
if(error.response) {
error.response = _sanitizeResponseHeaders({
error.response = _sanitizeResponse({
response: error.response,
data: error.data
});
}
if(error.request) {
error.request = new global.Request(error.request, {
headers: _sanitizeHeaders({httpMessage: error.request})
});
error.request = _sanitizeRequest({request: error.request});
}
return error;
}

function _sanitizeResponseHeaders({response, data}) {
function _sanitizeResponse({response, data}) {
const newResponse = new global.Response(JSON.stringify(data), {
headers: _sanitizeHeaders({httpMessage: response}),
status: response.status,
Expand All @@ -149,6 +150,25 @@ function _sanitizeResponseHeaders({response, data}) {
return newResponse;
}

function _sanitizeRequest({request}) {
// get the url and the remaining properties from the request
const {url, ...props} = request;
// create an options object to pass to the new request
const options = {};
// do not copy these properties from the request
const skipKeys = new Set(['body', 'headers']);
for(const key in props) {
if(skipKeys.has(key)) {
continue;
}
options[key] = request[key];
}
return new global.Request(url, {
...options,
headers: _sanitizeHeaders({httpMessage: request})
});
}

/**
* Takes in either a response or request & sanitizes the headers.
*
Expand All @@ -171,7 +191,7 @@ function _sanitizeHeaders({httpMessage, headers = sanitizeHeaders}) {
for(const header of headers) {
// sanitize the headers to prevent
// authn tokens / information potentially in logs
newHeaders.set(header, '** SANITIZED TO PREVENT EXPOSING OF SECRETS ***');
newHeaders.set(header, 'sanitized to prevent exposure of secrets');
}
return newHeaders;
}
Loading