Skip to content

Commit

Permalink
chore: linting
Browse files Browse the repository at this point in the history
  • Loading branch information
hugomrdias committed Sep 26, 2023
1 parent 3258a5e commit 85c5f39
Show file tree
Hide file tree
Showing 63 changed files with 701 additions and 448 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ kv-data

# Editor directories and files
.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
!.vscode/*.code-snippets
.idea
.DS_Store
*.suo
Expand Down
8 changes: 8 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"recommendations": [
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode",
"github.vscode-pull-request-github",
"yoavbls.pretty-ts-errors"
]
}
27 changes: 27 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true,
"source.organizeImports": false
},
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact",
"html",
"nunjucks",
"json",
"jsonc",
"json5",
"markdown",
"yaml",
"github-actions-workflow"
],
"javascript.format.enable": false,
"javascript.preferences.importModuleSpecifierEnding": "js",
"typescript.format.enable": false,
"typescript.preferences.importModuleSpecifierEnding": "auto",
"typescript.enablePromptUseWorkspaceTsdk": true
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
},
"devDependencies": {
"depcheck": "^1.4.6",
"hd-scripts": "^8.1.2",
"hd-scripts": "^9.0.3",
"lint-staged": "^14.0.1",
"prettier": "3.0.3",
"simple-git-hooks": "^2.9.0",
Expand All @@ -30,7 +30,7 @@
},
"lint-staged": {
"*.{js,ts,yml,json}": "prettier --write",
"*.js": "eslint --fix"
"*.{js}": "eslint --fix"
},
"prettier": "hd-scripts/prettier.config.js",
"engines": {
Expand Down
5 changes: 2 additions & 3 deletions packages/iso-base/bench.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable unicorn/no-abusive-eslint-disable */
/* eslint-disable */
/* eslint-disable no-console */
// @ts-nocheck
import bench from 'micro-bmark'

Expand Down Expand Up @@ -54,7 +53,7 @@ const buffers = {

const main = () =>
bench.run(async () => {
for (let [k, libs] of Object.entries(codecs)) {
for (const [k, libs] of Object.entries(codecs)) {
console.log(`==== ${k} ====`)
for (const [size, [samples, buf]] of Object.entries(buffers)) {
// encode
Expand Down
30 changes: 15 additions & 15 deletions packages/iso-base/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"name": "iso-base",
"type": "module",
"version": "2.0.1",
"description": "Isomorphic Utils",
"author": "Hugo Dias <[email protected]> (hugodias.me)",
Expand All @@ -20,13 +21,6 @@
"base-x",
"isomorphic"
],
"type": "module",
"main": "src/index.js",
"types": "dist/src/index.d.ts",
"browser": {
"crypto": false,
"./src/crypto.js": "./src/crypto-browser.js"
},
"exports": {
".": {
"types": "./dist/src/index.d.ts",
Expand Down Expand Up @@ -67,6 +61,12 @@
"default": "./src/leb128.js"
}
},
"main": "src/index.js",
"types": "dist/src/index.d.ts",
"browser": {
"crypto": false,
"./src/crypto.js": "./src/crypto-browser.js"
},
"typesVersions": {
"*": {
"utils": [
Expand Down Expand Up @@ -101,20 +101,24 @@
"dist/src/*.d.ts.map"
],
"scripts": {
"lint": "tsc --build && eslint '**/*.{js,ts}' && prettier --check '**/*.{js,ts,yml,json}' --ignore-path ../../.gitignore",
"lint": "tsc --build && eslint . && prettier --check '**/*.{js,ts,yml,json}' --ignore-path ../../.gitignore",
"test": "tsc --build && pnpm run test:node && pnpm run test:browser",
"test:node": "mocha 'test/**/!(*.browser).test.js'",
"test:browser": "playwright-test 'test/**/!(*.node).test.js'"
},
"dependencies": {
"base-x": "^4.0.0",
"bigint-mod-arith": "^3.3.1"
},
"devDependencies": {
"@scure/base": "^1.1.3",
"@types/assert": "^1.5.6",
"@types/assert": "^1.5.7",
"@types/mocha": "^10.0.1",
"@types/node": "^20.6.2",
"@types/node": "^20.7.0",
"assert": "^2.1.0",
"micro-bmark": "^0.3.1",
"mocha": "^10.2.0",
"playwright-test": "^12.3.4",
"playwright-test": "^12.3.5",
"typescript": "5.2.2"
},
"publishConfig": {
Expand All @@ -140,9 +144,5 @@
"hd-scripts",
"assert"
]
},
"dependencies": {
"base-x": "^4.0.0",
"bigint-mod-arith": "^3.3.1"
}
}
1 change: 0 additions & 1 deletion packages/iso-base/src/ec-compression.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ export function decompress(comp, curve = 'P-256') {
yPadded.set(y, offset)

// concat coords & prepend compressed prefix
// eslint-disable-next-line unicorn/prefer-spread
const publicKey = concat([[0x04], x, yPadded])
return publicKey
}
38 changes: 21 additions & 17 deletions packages/iso-base/src/rfc4648.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
*
* @module
*/

/* eslint-disable unicorn/prefer-math-trunc */
/* eslint-disable unicorn/no-for-loop */

/** @typedef {import('./types').Codec} Codec */

import { utf8 } from './utf8.js'
import { isBufferSource, u8 } from './utils.js'

/**
* @param {string} string
* @param {string} alphabet
* @param {number} bitsPerChar
* @returns {Uint8Array}
* Decode
*
* @param {string} string - Encoded string
* @param {string} alphabet - Alphabet
* @param {number} bitsPerChar - Bits per character
* @returns {Uint8Array} - Decoded data
*/
const decode = (string, alphabet, bitsPerChar) => {
// Build the character lookup table:
Expand Down Expand Up @@ -64,21 +66,23 @@ const decode = (string, alphabet, bitsPerChar) => {
}

/**
* @param {Uint8Array} data
* @param {string} alphabet
* @param {number} bitsPerChar
* @param {boolean} pad
* @returns {string}
* Encode
*
* @param {Uint8Array} data - Data to encode
* @param {string} alphabet - Alphabet
* @param {number} bitsPerChar - Bits per character
* @param {boolean} pad - Pad
* @returns {string} - Encoded string
*/
const encode = (data, alphabet, bitsPerChar, pad) => {
const mask = (1 << bitsPerChar) - 1
let out = ''

let bits = 0 // Number of bits currently in the buffer
let buffer = 0 // Bits waiting to be written out, MSB first
for (let i = 0; i < data.length; ++i) {
for (const datum of data) {
// Slurp data into the buffer:
buffer = (buffer << 8) | data[i]
buffer = (buffer << 8) | datum
bits += 8

// Write out as much as we can:
Expand Down Expand Up @@ -124,10 +128,10 @@ const bases = {
/**
* RFC4648 Factory
*
* @param {string} base
* @param {boolean} [padding]
* @param {((str: string) => string)} [normalize]
* @returns {Codec}
* @param {string} base - Base
* @param {boolean} [padding] - Padding
* @param {((str: string) => string)} [normalize] - Normalize
* @returns {Codec} - Codec
*/
export function rfc4648(base, padding = false, normalize) {
const [bits, alphabet] = bases[base]
Expand Down
4 changes: 2 additions & 2 deletions packages/iso-base/src/varint.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const INT = Math.pow(2, 31)
/**
* @param {number} num
* @param {Uint8Array} out
* @param {number} [offset=0]
* @param {number} offset
*/
function encode(num, out, offset = 0) {
out = out || []
Expand Down Expand Up @@ -40,7 +40,7 @@ const REST$1 = 0x7f

/**
* @param {Uint8Array} buf
* @param {number} [offset=0]
* @param {number} [offset]
* @returns {[code: number, size: number]}
*/
function decode(buf, offset = 0) {
Expand Down
1 change: 1 addition & 0 deletions packages/iso-base/test/rfc4648.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import assert from 'assert'
import * as BASES from '../src/rfc4648.js'
import { utf8 } from '../src/utf8.js'

const VECTORS = [
['base16', '', ''],
['base16', utf8.encode(Uint8Array.from([0x01])), '01'],
Expand Down
5 changes: 2 additions & 3 deletions packages/iso-base/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"lib": ["ESNext", "DOM"],
"emitDeclarationOnly": true
"emitDeclarationOnly": true,
"outDir": "dist"
},
"include": ["src", "scripts", "test", "package.json"],
"exclude": ["node_modules", "dist", "out"],
Expand Down
16 changes: 8 additions & 8 deletions packages/iso-did/package.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
{
"name": "iso-did",
"type": "module",
"version": "1.3.3",
"description": "DID tooling.",
"author": "Hugo Dias <[email protected]> (hugodias.me)",
"license": "MIT",
"homepage": "https://github.com/hugomrdias/iso-repo/tree/main/packages/iso-did",
"repository": {
"url": "hugomrdias/iso-repo",
"directory": "packages/iso-did"
},
"homepage": "https://github.com/hugomrdias/iso-repo/tree/main/packages/iso-did",
"keywords": [
"did",
"did:key",
"did-core"
],
"type": "module",
"main": "src/index.js",
"types": "dist/src/index.d.ts",
"exports": {
".": {
"types": "./dist/src/index.d.ts",
Expand All @@ -34,6 +32,8 @@
"types": "./dist/src/types.d.ts"
}
},
"main": "src/index.js",
"types": "dist/src/index.d.ts",
"typesVersions": {
"*": {
".": [
Expand All @@ -56,7 +56,7 @@
"dist/src/*.d.ts.map"
],
"scripts": {
"lint": "tsc --build && eslint '**/*.{js,ts}' && prettier --check '**/*.{js,ts,yml,json}' --ignore-path ../../.gitignore",
"lint": "tsc --build && eslint . && prettier --check '**/*.{js,ts,yml,json}' --ignore-path ../../.gitignore",
"test": "tsc --build && pnpm run test:node && pnpm run test:browser",
"test:node": "mocha 'test/**/!(*.browser).test.js'",
"test:browser": "playwright-test 'test/**/!(*.node).test.js'"
Expand All @@ -67,12 +67,12 @@
"multiformats": "^12.1.1"
},
"devDependencies": {
"@types/assert": "^1.5.6",
"@types/assert": "^1.5.7",
"@types/mocha": "^10.0.1",
"@types/node": "^20.6.2",
"@types/node": "^20.7.0",
"assert": "^2.1.0",
"mocha": "^10.2.0",
"playwright-test": "^12.3.4",
"playwright-test": "^12.3.5",
"type-fest": "^4.3.1",
"typescript": "5.2.2"
},
Expand Down
14 changes: 7 additions & 7 deletions packages/iso-did/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@ const did = DID.fromString(
```js
import { DIDKey } from 'iso-did/key'

const did = DIDKey.fromString(
const did1 = DIDKey.fromString(
'did:key:z6MkiTBz1ymuepAQ4HEHYSF1H8quG5GLVVQR3djdX3mDooWp'
)

// did.key = Uint8Array([1, 2, 3, 4])
// did.code = 0xed
// did.type = 'ED25519'
// did1.key = Uint8Array([1, 2, 3, 4])
// did1.code = 0xed
// did1.type = 'ED25519'

const did = DIDKey.fromPublicKey('ED25519', publicKeyBytes)
const did2 = DIDKey.fromPublicKey('ED25519', publicKeyBytes)

// did.id = z6MkiTBz1ymuepAQ4HEHYSF1H8quG5GLVVQR3djdX3mDooWp
// did.did = did:key:z6MkiTBz1ymuepAQ4HEHYSF1H8quG5GLVVQR3djdX3mDooWp
// did2.id = z6MkiTBz1ymuepAQ4HEHYSF1H8quG5GLVVQR3djdX3mDooWp
// did2.did = did:key:z6MkiTBz1ymuepAQ4HEHYSF1H8quG5GLVVQR3djdX3mDooWp
```

## Docs
Expand Down
3 changes: 1 addition & 2 deletions packages/iso-did/src/key.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* eslint-disable complexity */
import * as EC from 'iso-base/ec-compression'
import { u8, equals, concat } from 'iso-base/utils'
import { concat, equals, u8 } from 'iso-base/utils'
import { tag, varint } from 'iso-base/varint'
import { base58btc } from 'multiformats/bases/base58'
import { CODE_KEY_TYPE, KEY_TYPE_CODE, keyTypeToAlg } from './common.js'
Expand Down
4 changes: 2 additions & 2 deletions packages/iso-did/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { ParsedDID } from 'did-resolver'
import type { Alg } from './common.js'
import type { Alg } from './common'

export interface DID extends ParsedDID {}

// https://www.iana.org/assignments/cose/cose.xhtml#algorithms
export type SignatureAlgorithm = Alg

export type { KeyType, PublicKeyCode } from './common.js'
export type { KeyType, PublicKeyCode } from './common'
2 changes: 1 addition & 1 deletion packages/iso-did/test/key.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import assert from 'assert'
import { DIDKey } from '../src/key.js'
import { base64pad } from 'iso-base/rfc4648'
import { DIDKey } from '../src/key.js'

/**
* @typedef {import('../src/types').KeyType} PublicKeyType
Expand Down
5 changes: 2 additions & 3 deletions packages/iso-did/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "dist",
"lib": ["ESNext", "DOM"],
"emitDeclarationOnly": true
"emitDeclarationOnly": true,
"outDir": "dist"
},
"references": [
{
Expand Down
Loading

0 comments on commit 85c5f39

Please sign in to comment.