Skip to content

Commit

Permalink
feat: Add workspace/lerna files and structures
Browse files Browse the repository at this point in the history
  • Loading branch information
nklomp committed Nov 22, 2021
1 parent e6e3cfb commit 2c2b112
Show file tree
Hide file tree
Showing 11 changed files with 9,677 additions and 51 deletions.
9 changes: 9 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"jsxBracketSameLine": false,
"trailingComma": "all",
"tabWidth": 2,
"printWidth": 150,
"singleQuote": true,
"semi": false,
"endOfLine": "auto"
}
39 changes: 39 additions & 0 deletions jest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"preset": "ts-jest",
"moduleFileExtensions": [
"ts",
"tsx",
"js",
"jsx"
],
"collectCoverage": true,
"collectCoverageFrom": [
"packages/**/src/**/*.ts",
"!**/examples/**",
"!packages/cli/**",
"!**/types/**",
"!**/dist/**",
"!**/node_modules/**"
],
"coverageReporters": [
"text",
"lcov",
"json"
],
"coverageDirectory": "./coverage",
"transform": {
"\\.jsx?$": "babel-jest",
"\\.tsx?$": "ts-jest"
},
"testMatch": [
"**/__tests__/**/*.test.*"
],
"globals": {
"ts-jest": {
"tsconfig": "./packages/tsconfig-base.json"
}
},
"testEnvironment": "node",
"automock": false,
"verbose": true
}
19 changes: 19 additions & 0 deletions lerna.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"packages": [
"packages/*"
],
"version": "0.0.1",
"npmClient": "yarn",
"command": {
"publish": {
"allowBranch": [
"main",
"master"
],
"conventionalCommits": true,
"gitRemote": "origin",
"message": "chore(release): %s"
}
},
"useWorkspaces": true
}
79 changes: 79 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"name": "SSI-SDK-workspace",
"private": true,
"version": "0.0.1",
"description": "Sphereon SSI Typescript SDK (Workspace)",
"repository": "git@github.com:Sphereon-Opensource/SSI-SDK.git",
"author": "Sphereon <dev@sphereon.com>",
"license": "Apache-2.0",
"scripts": {
"build": "lerna run build && yarn build:schema-api",
"build:schema-api": "lerna run extract-api && lerna run generate-plugin-schema",
"bootstrap": "lerna bootstrap",
"test:integration-build": "yarn test:integration-prepare && yarn test:integration-pretty",
"test:integration-prepare": "ts-node --project packages/tsconfig-base.json ./scripts/prepare-integration-tests.ts",
"test:integration": "yarn test:integration-build && yarn test:ci",
"test:ci": "jest --config=jest.json",
"test": "jest --verbose --config=jest.json --coverage=false",
"test:watch": "yarn test --watch --verbose",
"prettier": "prettier --write \"{packages,__tests__,!dist}/**/*.{ts,js,json,md,yml}\"",
"build-clean": "rimraf ./packages/*/dist ./packages/*/api ./packages/*/node_modules ./packages/*/tsconfig.tsbuildinfo && jest --clearCache",
"publish:latest": "lerna publish --conventional-commits --include-merged-tags --create-release github --yes --dist-tag latest --registry https://registry.npmjs.org/:_authToken=${NPM_TOKEN}",
"publish:next": "lerna publish --conventional-prerelease --force-publish --canary --no-git-tag-version --include-merged-tags --preid next --pre-dist-tag next --yes --registry https://registry.npmjs.org/:_authToken=${NPM_TOKEN}",
"publish:unstable": "lerna publish --conventional-prerelease --force-publish --canary --no-git-tag-version --include-merged-tags --preid unstable --pre-dist-tag unstable --yes --registry https://registry.npmjs.org/:_authToken=${NPM_TOKEN}"
},
"workspaces": {
"nohoist": [
"**disabled-repalce-by-package-names**"
],
"packages": [
"./packages/*"
]
},


"publishConfig": {
"access": "public"
},
"release": {
"branches": [
"master",
{
"name": "beta",
"prerelease": true
}
]
},
"devDependencies": {
"@microsoft/api-documenter": "^7.13.62",
"@microsoft/api-extractor": "^7.18.15",
"@microsoft/api-extractor-model": "^7.13.12",
"@types/jest": "^27.0.2",
"codecov": "^3.8.3",
"cross-fetch": "^3.1.4",
"jest": "^27.3.1",
"jest-fetch-mock": "^3.0.3",
"json-schema": "^0.4.0",
"lerna": "^4.0.0",
"lerna-changelog": "^2.2.0",
"oas-resolver": "^2.5.6",
"openapi-types": "^9.3.0",
"prettier": "^2.4.1",
"pretty-quick": "^3.1.1",
"rimraf": "^3.0.2",
"semantic-release": "^18.0.0",
"ts-jest": "^27.0.7",
"ts-json-schema-generator": "^0.96.0",
"ts-node": "^10.2.1",
"typescript": "^4.4.3"
},
"engines": {
"node": ">= 14.0.0"
},
"prettier": {
"endOfLine": "auto",
"semi": false,
"singleQuote": true,
"printWidth": 150
}
}
18 changes: 18 additions & 0 deletions packages/include/api-extractor-base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"$schema": "https://developer.microsoft.com/json-schemas/api-extractor/v7/api-extractor.schema.json",
"apiReport": {
"enabled": true,
"reportFolder": "./api",
"reportTempFolder": "./api"
},

"docModel": {
"enabled": true,
"apiJsonFilePath": "./api/<unscopedPackageName>.api.json"
},

"dtsRollup": {
"enabled": true
},
"mainEntryPointFilePath": "<projectFolder>/dist/index.d.ts"
}
3 changes: 2 additions & 1 deletion packages/ssi-sdk-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
},
"devDependencies": {
"@types/debug": "4.1.7",
"did-resolver": "3.1.0",
"did-resolver": "3.1.3",
"typescript": "4.4.3"
},
"files": [
"dist/**/*",
"src/**/*",
"plugin.schema.json",
"README.md",
"LICENSE"
Expand Down
51 changes: 25 additions & 26 deletions packages/ssi-sdk-core/src/utils/__tests__/encoding.test.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
import {hexToMultibase, MultibaseFormat, multibaseToHex} from "../encoding";

import { hexToMultibase, MultibaseFormat, multibaseToHex } from '../encoding'

describe('@sphereon/ssi-sdk-core:encoding', () => {
const BASE58_EXAMPLE = 'C3CPq7c8PY';
const MULTIBASE_EXAMPLE = `z${BASE58_EXAMPLE}`;
const HEX_EXAMPLE = '0123456789abcdef';
const BASE58_EXAMPLE = 'C3CPq7c8PY'
const MULTIBASE_EXAMPLE = `z${BASE58_EXAMPLE}`
const HEX_EXAMPLE = '0123456789abcdef'

// Hex to multibase
it('should encode hex to multibase base58', () => {
expect(hexToMultibase(HEX_EXAMPLE, MultibaseFormat.BASE58)).toEqual({value: BASE58_EXAMPLE, format: MultibaseFormat.BASE58})
expect(hexToMultibase(HEX_EXAMPLE.toUpperCase(), MultibaseFormat.BASE58)).toEqual({value: BASE58_EXAMPLE, format: MultibaseFormat.BASE58})
})
it('should not encode hex to not supported multibase format', () => {
expect(() => hexToMultibase(HEX_EXAMPLE, 'e' as never)).toThrowError()
})
it('should not encode hex to not multibase base58 with no input', () => {
expect(() => hexToMultibase(undefined as never, MultibaseFormat.BASE58)).toThrowError()
})
// Hex to multibase
it('should encode hex to multibase base58', () => {
expect(hexToMultibase(HEX_EXAMPLE, MultibaseFormat.BASE58)).toEqual({ value: BASE58_EXAMPLE, format: MultibaseFormat.BASE58 })
expect(hexToMultibase(HEX_EXAMPLE.toUpperCase(), MultibaseFormat.BASE58)).toEqual({ value: BASE58_EXAMPLE, format: MultibaseFormat.BASE58 })
})
it('should not encode hex to not supported multibase format', () => {
expect(() => hexToMultibase(HEX_EXAMPLE, 'e' as never)).toThrowError()
})
it('should not encode hex to not multibase base58 with no input', () => {
expect(() => hexToMultibase(undefined as never, MultibaseFormat.BASE58)).toThrowError()
})

// Multibase to hex
it('should encode multibase base58 to hex', () => {
expect(multibaseToHex(MULTIBASE_EXAMPLE)).toEqual({value: HEX_EXAMPLE, format: MultibaseFormat.BASE58})
})
it('should not encode unsupported multibase encoding to hex', () => {
expect(() => multibaseToHex(`e${BASE58_EXAMPLE}`)).toThrowError()
})
it('should not encode multibase base58 encoding to hex with no input', () => {
expect(() => multibaseToHex(undefined as never)).toThrowError()
})
// Multibase to hex
it('should encode multibase base58 to hex', () => {
expect(multibaseToHex(MULTIBASE_EXAMPLE)).toEqual({ value: HEX_EXAMPLE, format: MultibaseFormat.BASE58 })
})
it('should not encode unsupported multibase encoding to hex', () => {
expect(() => multibaseToHex(`e${BASE58_EXAMPLE}`)).toThrowError()
})
it('should not encode multibase base58 encoding to hex with no input', () => {
expect(() => multibaseToHex(undefined as never)).toThrowError()
})
})
47 changes: 23 additions & 24 deletions packages/ssi-sdk-core/src/utils/encoding.ts
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
import * as base58 from 'micro-base58'


export enum MultibaseFormat {
BASE58 = 'z'
BASE58 = 'z',
}

export function hexToMultibase(hex: string, format: MultibaseFormat): { value: string, format: MultibaseFormat } {
if (format !== MultibaseFormat.BASE58) {
throw new Error('Only base58 supported for now using multibase!')
}
return {value: base58.encode(hexToBytes(hex)), format}
export function hexToMultibase(hex: string, format: MultibaseFormat): { value: string; format: MultibaseFormat } {
if (format !== MultibaseFormat.BASE58) {
throw new Error('Only base58 supported for now using multibase!')
}
return { value: base58.encode(hexToBytes(hex)), format }

function hexToBytes(hex: string): Uint8Array {
let bytes: number[] = []
for (let c = 0; c < hex.length; c += 2) bytes.push(parseInt(hex.substr(c, 2), 16))
return Uint8Array.of(...bytes)
}
function hexToBytes(hex: string): Uint8Array {
let bytes: number[] = []
for (let c = 0; c < hex.length; c += 2) bytes.push(parseInt(hex.substr(c, 2), 16))
return Uint8Array.of(...bytes)
}
}

export function multibaseToHex(multibase: string): { value: string, format: MultibaseFormat } {
if (!multibase.startsWith(MultibaseFormat.BASE58)) {
throw new Error('Only base58 supported for now using multibase!')
}
return {value: bytesToHex(base58.decode(multibase.substr(1), 'btc')), format: MultibaseFormat.BASE58}
export function multibaseToHex(multibase: string): { value: string; format: MultibaseFormat } {
if (!multibase.startsWith(MultibaseFormat.BASE58)) {
throw new Error('Only base58 supported for now using multibase!')
}
return { value: bytesToHex(base58.decode(multibase.substr(1), 'btc')), format: MultibaseFormat.BASE58 }

function bytesToHex(uint8a: Uint8Array): string {
// pre-caching chars could speed this up 6x.
let hex = ''
for (let i = 0; i < uint8a.length; i++) {
hex += uint8a[i].toString(16).padStart(2, '0')
}
return hex
function bytesToHex(uint8a: Uint8Array): string {
// pre-caching chars could speed this up 6x.
let hex = ''
for (let i = 0; i < uint8a.length; i++) {
hex += uint8a[i].toString(16).padStart(2, '0')
}
return hex
}
}
69 changes: 69 additions & 0 deletions packages/tsconfig-base.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"$schema": "http://json.schemastore.org/tsconfig",
"compilerOptions": {
/* Basic Options */
"target": "ES6" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
/* "lib": [
"ES6",
"dom"
]*/ /* Specify library files to be included in the compilation. */
"allowJs": true /* Allow javascript files to be compiled. */,
// "checkJs": true, /* Report errors in .js files. */
// "jsx": "react-native" /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */,
"declaration": true /* Generates corresponding '.d.ts' file. */,
"sourceMap": true /* Generates corresponding '.map' file. */,
// "outFile": "./", /* Concatenate and emit output to single file. */
// "outDir": "./", /* Redirect output structure to the directory. */
// "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
// "removeComments": true, /* Do not emit comments to output. */
// "noEmit": true /* Do not emit outputs. */,
// "incremental": true, /* Enable incremental compilation */
// "importHelpers": true, /* Import emit helpers from 'tslib'. */
"downlevelIteration": true /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */,
// "isolatedModules": true /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */,

/* Strict Type-Checking Options */
"strict": true /* Enable all strict type-checking options. */,
// "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
// "strictNullChecks": true, /* Enable strict null checks. */
// "strictFunctionTypes": true, /* Enable strict checking of function types. */
// "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */
// "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */
// "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */

/* Additional Checks */
// "noUnusedLocals": true, /* Report errors on unused locals. */
// "noUnusedParameters": true, /* Report errors on unused parameters. */
// "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */
// "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */

/* Module Resolution Options */
"moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */,
// "baseUrl": "./", /* Base directory to resolve non-absolute module names. */
// "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */
// "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */
// "typeRoots": [], /* List of folders to include type definitions from. */
// "types": [], /* Type declaration files to be included in compilation. */
// "allowSyntheticDefaultImports": true /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */,
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,
// "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */
"skipLibCheck": true /* Skip type checking of declaration files. */,

/* Source Map Options */
// "sourceRoot": "./", /* Specify the location where debugger should locate TypeScript files instead of source locations. */
// "mapRoot": "./", /* Specify the location where debugger should locate map files instead of generated locations. */
// "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */
// "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */

"resolveJsonModule": true,
/* Experimental Options */
"experimentalDecorators": true /* Enables experimental support for ES7 decorators. */,
"emitDecoratorMetadata": true /* Enables experimental support for emitting type metadata for decorators. */,

"preserveConstEnums": true,
"declarationMap": true,
"composite": true
},
"exclude": ["**/__tests__/**/*", "**/dist/**/*"]
}
4 changes: 4 additions & 0 deletions packages/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"files": [],
"references": [{ "path": "ssi-sdk-core" }, { "path": "factom-did-provider" }, { "path": "lto-did-provider" }]
}
Loading

0 comments on commit 2c2b112

Please sign in to comment.