generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* scaffold `credentials` package * scaffold `web5.vc`
- Loading branch information
Showing
16 changed files
with
6,862 additions
and
1,693 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"all": true, | ||
"cache": false, | ||
"extension": [ | ||
".js" | ||
], | ||
"include": [ | ||
"__tests__/src/**" | ||
], | ||
"exclude": [ | ||
"__tests__/src/main.js", | ||
"__tests__/types/**" | ||
], | ||
"reporter": [ | ||
"cobertura", | ||
"text" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"enable-source-maps": true, | ||
"exit": true, | ||
"spec": ["__tests__/**/*.spec.js"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import esbuild from 'esbuild'; | ||
import browserConfig from './esbuild-browser-config.cjs'; | ||
|
||
// cjs bundle for Electron apps. external dependencies bundled except LevelDB | ||
// Remove if/when the following PR is merged and this bundle is no longer needed by Electron apps | ||
// https://github.com/electron/electron/pull/37535 | ||
esbuild.buildSync({ | ||
platform : 'node', | ||
bundle : true, | ||
format : 'cjs', | ||
// packages: 'external', | ||
external : ['level'], | ||
sourcemap : true, | ||
entryPoints : ['./src/main.ts'], | ||
outfile : './dist/electron/main.cjs', | ||
allowOverwrite : true, | ||
}); | ||
|
||
// cjs bundle. external dependencies **not** bundled | ||
esbuild.buildSync({ | ||
platform : 'node', | ||
bundle : true, | ||
format : 'cjs', | ||
packages : 'external', | ||
sourcemap : true, | ||
entryPoints : ['./src/main.ts'], | ||
outfile : './dist/cjs/main.cjs', | ||
allowOverwrite : true, | ||
}); | ||
|
||
// esm bundle. external dependencies **not** bundled | ||
esbuild.buildSync({ | ||
platform : 'node', | ||
bundle : true, | ||
format : 'esm', | ||
packages : 'external', | ||
sourcemap : true, | ||
entryPoints : ['./src/main.ts'], | ||
outfile : './dist/esm/main.mjs', | ||
allowOverwrite : true, | ||
}); | ||
|
||
// esm polyfilled bundle for browser | ||
esbuild.build({ | ||
...browserConfig, | ||
outfile: 'dist/browser.mjs', | ||
}); | ||
|
||
// iife polyfilled bundle for browser | ||
esbuild.build({ | ||
...browserConfig, | ||
format : 'iife', | ||
globalName : 'Web5', | ||
outfile : 'dist/browser.js', | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
const polyfillProviderPlugin = require('node-stdlib-browser/helpers/esbuild/plugin'); | ||
const stdLibBrowser = require('node-stdlib-browser'); | ||
|
||
/** @type {import('esbuild').BuildOptions} */ | ||
module.exports = { | ||
entryPoints : ['./src/main.ts'], | ||
bundle : true, | ||
format : 'esm', | ||
sourcemap : true, | ||
minify : true, | ||
platform : 'browser', | ||
target : ['chrome101', 'firefox108', 'safari16'], | ||
inject : [require.resolve('node-stdlib-browser/helpers/esbuild/shim')], | ||
plugins : [polyfillProviderPlugin(stdLibBrowser)], | ||
define : { | ||
'global': 'globalThis', | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
// Karma is what we're using to run our tests in browser environments | ||
// Karma does not support .mjs | ||
|
||
// playwright acts as a safari executable on windows and mac | ||
const playwright = require('@playwright/test'); | ||
const esbuildBrowserConfig = require('./build/esbuild-browser-config.cjs'); | ||
|
||
// use playwright chrome exec path as run target for chromium tests | ||
process.env.CHROME_BIN = playwright.chromium.executablePath(); | ||
|
||
// use playwright webkit exec path as run target for safari tests | ||
process.env.WEBKIT_HEADLESS_BIN = playwright.webkit.executablePath(); | ||
|
||
// use playwright firefox exec path as run target for firefox tests | ||
process.env.FIREFOX_BIN = playwright.firefox.executablePath(); | ||
|
||
module.exports = function (config) { | ||
config.set({ | ||
plugins: [ | ||
'karma-chrome-launcher', | ||
'karma-firefox-launcher', | ||
'karma-webkit-launcher', | ||
'karma-esbuild', | ||
'karma-mocha', | ||
'karma-mocha-reporter', | ||
], | ||
|
||
// frameworks to use | ||
// available frameworks: https://www.npmjs.com/search?q=keywords:karma-adapter | ||
frameworks: ['mocha'], | ||
|
||
// Increase Mocha's default timeout of 2 seconds to prevent timeouts during GitHub CI runs. | ||
client: { | ||
mocha: { | ||
timeout: 10000 // 10 seconds | ||
} | ||
}, | ||
|
||
|
||
// list of files / patterns to load in the browser | ||
files: [ | ||
{ pattern: 'tests/**/*.spec.ts', watched: false }, | ||
], | ||
|
||
// preprocess matching files before serving them to the browser | ||
// available preprocessors: https://www.npmjs.com/search?q=keywords:karma-preprocessor | ||
preprocessors: { | ||
'tests/**/*.spec.ts': ['esbuild'], | ||
}, | ||
|
||
esbuild: esbuildBrowserConfig, | ||
|
||
// list of files / patterns to exclude | ||
exclude: [], | ||
|
||
// test results reporter to use | ||
// available reporters: https://www.npmjs.com/search?q=keywords:karma-reporter | ||
reporters: ['mocha'], | ||
|
||
// web server port | ||
port: 9876, | ||
|
||
// enable / disable colors in the output (reporters and logs) | ||
colors: true, | ||
|
||
// level of logging | ||
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || | ||
// config.LOG_INFO || config.LOG_DEBUG | ||
logLevel: config.LOG_INFO, | ||
|
||
concurrency: 1, | ||
|
||
// start these browsers | ||
// available browser launchers: https://www.npmjs.com/search?q=keywords:karma-launcher | ||
browsers: ['ChromeHeadless', 'FirefoxHeadless', 'WebkitHeadless'], | ||
|
||
// Continuous Integration mode | ||
// if true, Karma captures browsers, runs the tests and exits | ||
singleRun: true, | ||
|
||
// Increase browser timeouts to avoid DISCONNECTED messages during GitHub CI runs. | ||
browserDisconnectTimeout : 10000, // default 2000 | ||
browserDisconnectTolerance : 1, // default 0 | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
{ | ||
"name": "@tbd54566975/credentials", | ||
"version": "0.1.4", | ||
"description": "Verifiable Credentials", | ||
"type": "module", | ||
"main": "./dist/cjs/main.cjs", | ||
"module": "./dist/esm/main.mjs", | ||
"types": "./dist/types/main.d.ts", | ||
"scripts": { | ||
"build": "rimraf dist && node build/bundles.js && echo '{\"type\": \"commonjs\"}' > ./dist/cjs/package.json && tsc", | ||
"lint": "eslint . --ext .ts --max-warnings 0", | ||
"lint:fix": "eslint . --ext .ts --fix", | ||
"test:node": "rimraf __tests__ && tsc -p tsconfig.test.json && c8 mocha", | ||
"test:browser": "karma start karma.conf.cjs" | ||
}, | ||
"homepage": "https://github.com/TBD54566975/web5-js/tree/main/packages/credentials#readme", | ||
"bugs": "https://github.com/TBD54566975/web5-js/issues", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/TBD54566975/web5-js", | ||
"directory": "packages/credentials" | ||
}, | ||
"license": "Apache-2.0", | ||
"contributors": [ | ||
{ | ||
"name": "Daniel Buchner", | ||
"url": "https://github.com/csuwildcat" | ||
}, | ||
{ | ||
"name": "Frank Hinek", | ||
"url": "https://github.com/frankhinek" | ||
}, | ||
{ | ||
"name": "Moe Jangda", | ||
"url": "https://github.com/mistermoe" | ||
} | ||
], | ||
"files": [ | ||
"dist", | ||
"src" | ||
], | ||
"exports": { | ||
".": { | ||
"import": "./dist/esm/main.mjs", | ||
"require": "./dist/cjs/main.cjs", | ||
"types": "./dist/types/main.d.ts" | ||
}, | ||
"./browser": { | ||
"import": "./dist/browser.mjs", | ||
"require": "./dist/browser.js", | ||
"types": "./dist/types/main.d.ts" | ||
}, | ||
"./electron": { | ||
"import": "./dist/esm/main.mjs", | ||
"require": "./dist/electron/main.cjs", | ||
"types": "./dist/types/main.d.ts" | ||
} | ||
}, | ||
"browser": { | ||
"./dist/esm/main.mjs": "./dist/browser.mjs", | ||
"./dist/cjs/main.cjs": "./dist/browser.js", | ||
"types": "./dist/types/main.d.ts" | ||
}, | ||
"keywords": [ | ||
"decentralized", | ||
"decentralized-applications", | ||
"decentralized-identity", | ||
"decentralized-web", | ||
"vcs", | ||
"verifiable credentials", | ||
"web5" | ||
], | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"engines": { | ||
"node": ">=18.0.0" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"@types/chai": "4.3.0", | ||
"@types/eslint": "8.37.0", | ||
"@types/mocha": "10.0.1", | ||
"@typescript-eslint/eslint-plugin": "5.59.0", | ||
"@typescript-eslint/parser": "5.59.0", | ||
"c8": "7.14.0", | ||
"chai": "4.3.7", | ||
"esbuild": "0.16.7", | ||
"eslint": "8.39.0", | ||
"karma": "6.4.1", | ||
"karma-chai": "0.1.0", | ||
"karma-chrome-launcher": "3.1.1", | ||
"karma-esbuild": "2.2.5", | ||
"karma-firefox-launcher": "2.1.2", | ||
"karma-mocha": "2.0.1", | ||
"karma-mocha-reporter": "2.2.5", | ||
"karma-webkit-launcher": "2.1.0", | ||
"mocha": "10.2.0", | ||
"node-stdlib-browser": "1.2.0", | ||
"playwright": "1.31.2", | ||
"rimraf": "4.4.0", | ||
"typescript": "5.0.4" | ||
}, | ||
"overrides": { | ||
"socket.io-parser@>4.0.4 <4.2.3": "4.2.3" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './types.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
|
||
/** | ||
* @see {@link https://www.w3.org/TR/vc-data-model/#credentials | VC data model} | ||
*/ | ||
export type VerifiableCredential = { | ||
/** see {@link https://www.w3.org/TR/vc-data-model/#contexts | Contexts} */ | ||
'@context': ['https://www.w3.org/2018/credentials/v1', ...string[]]; | ||
credentialSubject: CredentialSubject | CredentialSubject[]; | ||
/** @see {@link https://www.w3.org/TR/vc-data-model/#identifiers | Identifiers} */ | ||
id?: string; | ||
/** @see {@link IssuerType} */ | ||
issuer: Issuer; | ||
/** @see {@link https://www.w3.org/TR/vc-data-model/#types | Types} */ | ||
type?: string[] | string; | ||
/** @see {@link https://www.w3.org/TR/vc-data-model/#issuance-date | Issuance Date} */ | ||
issuanceDate: string; | ||
/** @see {@link https://www.w3.org/TR/vc-data-model/#expiration | Expiration} */ | ||
expirationDate?: string; | ||
/** @see {@link CredentialStatusReference} */ | ||
credentialStatus?: CredentialStatusReference; | ||
[key: string]: any; | ||
} | ||
|
||
/** | ||
* The issuer of a {@link VerifiableCredential}. | ||
* The value of the issuer property must be either a URI or an object containing an `id` property. | ||
* It is _recommended_ that the URI in the issuer or its id be one which, if de-referenced, results in a document | ||
* containing machine-readable information about the issuer that can be used to verify the information expressed in the | ||
* credential. | ||
* | ||
* See {@link https://www.w3.org/TR/vc-data-model/#issuer | Issuer data model} | ||
*/ | ||
export type Issuer = { | ||
/** @see {@link https://www.w3.org/TR/vc-data-model/#identifiers | Identifiers} */ | ||
id: string; | ||
[key: string]: any; | ||
} | string | ||
|
||
/** | ||
* The value of the `credentialSubject` property is defined as a set of objects that contain one or more properties that | ||
* are each related to a subject of the verifiable credential. Each object MAY contain an id. | ||
* | ||
* See {@link https://www.w3.org/TR/vc-data-model/#credential-subject | Credential Subject} | ||
*/ | ||
export type CredentialSubject = { | ||
/** @see {@link https://www.w3.org/TR/vc-data-model/#identifiers | Identifiers} */ | ||
id?: string; | ||
[key: string]: any; | ||
} | ||
|
||
/** | ||
* Used for the discovery of information about the current status of a verifiable credential, such as whether it is | ||
* suspended or revoked. | ||
* The precise contents of the credential status information is determined by the specific `credentialStatus` type | ||
* definition, and varies depending on factors such as whether it is simple to implement or if it is privacy-enhancing. | ||
* | ||
* See {@link https://www.w3.org/TR/vc-data-model/#status | Credential Status} | ||
*/ | ||
export type CredentialStatusReference = { | ||
/** @see {@link https://www.w3.org/TR/vc-data-model/#identifiers | Identifiers} */ | ||
id: string; | ||
/** expresses the credential status type (also referred to as the credential status method). | ||
* It is expected that the value will provide enough information to determine the current status | ||
* of the credential and that machine readable information needs to be retrievable from the URI. | ||
* For example, the object could contain a link to an external document noting whether or not the credential | ||
* is suspended or revoked. | ||
*/ | ||
type: string; | ||
[key: string]: any; | ||
} | ||
|
||
/** | ||
* proof property of a {@link VerifiableCredential} | ||
*/ | ||
export type ProofType = { | ||
/** @see {@link https://www.w3.org/TR/vc-data-model/#types | Types} */ | ||
type?: string; | ||
[key: string]: any; | ||
} |
Oops, something went wrong.