Skip to content

Commit

Permalink
feat(iso-signatures): initial commit for iso-signatures (#34)
Browse files Browse the repository at this point in the history
- fix(iso-did): extract signatures to a new package and export common.js from key.js
- feat(iso-signatures): initial commit for iso-signatures
  • Loading branch information
hugomrdias authored Jun 29, 2023
1 parent 7af05df commit a2e6265
Show file tree
Hide file tree
Showing 32 changed files with 440 additions and 154 deletions.
1 change: 1 addition & 0 deletions .github/release-please-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"packages": {
"packages/iso-base": {},
"packages/iso-did": {},
"packages/iso-signatures": {},
"packages/iso-filecoin": {},
"packages/iso-passkeys": {}
}
Expand Down
3 changes: 2 additions & 1 deletion .github/release-please-manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"packages/iso-base": "1.0.0",
"packages/iso-filecoin": "0.2.3",
"packages/iso-passkeys": "0.1.6",
"packages/iso-did": "1.2.0"
"packages/iso-did": "1.2.0",
"packages/iso-signatures": "0.0.1"
}
34 changes: 34 additions & 0 deletions .github/workflows/iso-signatures.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: iso-signatures
env:
CI: true
FORCE_COLOR: 1
on:
push:
branches:
- main
paths:
- 'packages/iso-signatures/**'
- '.github/workflows/iso-signatures.yml'
- 'pnpm-lock.yaml'
pull_request:
paths:
- 'packages/iso-signatures/**'
- '.github/workflows/iso-signatures.yml'
- 'pnpm-lock.yaml'
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: pnpm/action-setup@v2.2.4
with:
version: 8
- uses: actions/setup-node@v3
with:
node-version: 18
cache: 'pnpm'
- run: pnpm install
- run: pnpm run build
- run: pnpm -r --filter iso-signatures run lint
- run: pnpm -r --filter iso-signatures run test
- run: pnpm -r --filter iso-signatures exec depcheck
6 changes: 4 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ jobs:
contains(fromJson(needs.release.outputs.paths_released), 'packages/iso-base') ||
contains(fromJson(needs.release.outputs.paths_released), 'packages/iso-filecoin') ||
contains(fromJson(needs.release.outputs.paths_released), 'packages/iso-passkeys') ||
contains(fromJson(needs.release.outputs.paths_released), 'packages/iso-did')
contains(fromJson(needs.release.outputs.paths_released), 'packages/iso-did') ||
contains(fromJson(needs.release.outputs.paths_released), 'packages/iso-signatures')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
Expand All @@ -51,5 +52,6 @@ jobs:
contains(fromJson(needs.release.outputs.paths_released), 'packages/iso-base') ||
contains(fromJson(needs.release.outputs.paths_released), 'packages/iso-filecoin') ||
contains(fromJson(needs.release.outputs.paths_released), 'packages/iso-passkeys') ||
contains(fromJson(needs.release.outputs.paths_released), 'packages/iso-did')
contains(fromJson(needs.release.outputs.paths_released), 'packages/iso-did') ||
contains(fromJson(needs.release.outputs.paths_released), 'packages/iso-signatures')
uses: './.github/workflows/reusable-docs.yml'
4 changes: 3 additions & 1 deletion packages/iso-did/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
],
"key": [
"dist/src/key"
],
"types": [
"dist/src/types"
]
}
},
Expand All @@ -56,7 +59,6 @@
"test:browser": "playwright-test 'test/**/!(*.node).test.js'"
},
"dependencies": {
"@noble/ed25519": "^2.0.0",
"did-resolver": "^4.1.0",
"iso-base": "workspace:^",
"multiformats": "^12.0.1"
Expand Down
2 changes: 2 additions & 0 deletions packages/iso-did/src/key.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { base58btc } from 'multiformats/bases/base58'
import { CODE_KEY_TYPE, KEY_TYPE_CODE, keyTypeToAlg } from './common.js'
import { DIDCore } from './core.js'

export * from './common.js'

const DID_KEY_PREFIX = `did:key:`

/**
Expand Down
25 changes: 0 additions & 25 deletions packages/iso-did/src/signatures/signers/types.ts

This file was deleted.

23 changes: 0 additions & 23 deletions packages/iso-did/src/signatures/types.ts

This file was deleted.

27 changes: 0 additions & 27 deletions packages/iso-did/src/signatures/verifiers/types.ts

This file was deleted.

138 changes: 138 additions & 0 deletions packages/iso-signatures/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
{
"name": "iso-signatures",
"version": "0.0.1",
"description": "Signatures tooling.",
"author": "Hugo Dias <hugomrdias@gmail.com> (hugodias.me)",
"license": "MIT",
"repository": {
"url": "hugomrdias/iso-repo",
"directory": "packages/iso-signatures"
},
"homepage": "https://github.com/hugomrdias/iso-repo/tree/main/packages/iso-signatures",
"keywords": [
"elliptic",
"curve",
"cryptography",
"edwards",
"p256",
"p384",
"p521",
"secp256r1",
"secp256k1",
"ed25519",
"ecdsa",
"eddsa",
"rsa",
"signatures"
],
"type": "module",
"main": "src/index.js",
"types": "dist/src/index.d.ts",
"exports": {
".": {
"types": "./dist/src/index.d.ts",
"import": "./src/index.js"
},
"./signers/ecdsa": {
"types": "./dist/src/signers/ecdsa.d.ts",
"import": "./src/signers/ecdsa.js"
},
"./signers/eddsa": {
"types": "./dist/src/signers/eddsa.d.ts",
"import": "./src/signers/eddsa.js"
},
"./signers/rsa-old": {
"types": "./dist/src/signers/rsa-old.d.ts",
"import": "./src/signers/rsa-old.js"
},
"./signers/rsa": {
"types": "./dist/src/signers/rsa.d.ts",
"import": "./src/signers/rsa.js"
},
"./verifiers/ecdsa": {
"types": "./dist/src/verifiers/ecdsa.d.ts",
"import": "./src/verifiers/ecdsa.js"
},
"./verifiers/eddsa": {
"types": "./dist/src/verifiers/eddsa.d.ts",
"import": "./src/verifiers/eddsa.js"
},
"./verifiers/rsa-old": {
"types": "./dist/src/verifiers/rsa-old.d.ts",
"import": "./src/verifiers/rsa-old.js"
},
"./verifiers/rsa": {
"types": "./dist/src/verifiers/rsa.d.ts",
"import": "./src/verifiers/rsa.js"
},
"./verifiers/resolver": {
"types": "./dist/src/verifiers/resolver.d.ts",
"import": "./src/verifiers/resolver.js"
}
},
"typesVersions": {
"*": {
".": [
"dist/src/index"
],
"signers/*": [
"dist/src/signers/*"
],
"verifiers/*": [
"dist/src/verifiers/*"
]
}
},
"files": [
"src",
"dist/src/*.d.ts",
"dist/src/*.d.ts.map"
],
"scripts": {
"lint": "tsc --build && eslint '**/*.{js,ts}' && 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": {
"@noble/ed25519": "^2.0.0",
"iso-base": "workspace:^",
"iso-did": "workspace:^"
},
"devDependencies": {
"@types/assert": "^1.5.6",
"@types/mocha": "^10.0.1",
"@types/node": "^20.3.1",
"assert": "^2.0.0",
"hd-scripts": "^7.0.0",
"mocha": "^10.2.0",
"playwright-test": "^9.2.0",
"type-fest": "^3.12.0",
"typescript": "5.1.3"
},
"eslintConfig": {
"extends": [
"../../node_modules/hd-scripts/eslint/index.js"
],
"parserOptions": {
"project": "./tsconfig.json"
},
"env": {
"mocha": true
},
"ignorePatterns": [
"dist"
]
},
"depcheck": {
"specials": [
"bin"
],
"ignores": [
"@types/*",
"hd-scripts",
"assert",
"type-fest"
]
}
}
59 changes: 59 additions & 0 deletions packages/iso-signatures/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# iso-signatures [![NPM Version](https://img.shields.io/npm/v/iso-signatures.svg)](https://www.npmjs.com/package/iso-signatures) [![License](https://img.shields.io/npm/l/iso-signatures.svg)](https://github.com/hugomrdias/iso-repo/blob/main/license) [![iso-did](https://github.com/hugomrdias/iso-repo/actions/workflows/iso-signatures.yml/badge.svg)](https://github.com/hugomrdias/iso-repo/actions/workflows/iso-signatures.yml)

> Isomorphic signatures tooling
## Install

```bash
pnpm install iso-signatures
```

## Usage

```js
import { EdDSASigner } from 'iso-signatures/signers/eddsa'
import * as EdDSA from 'iso-signatures/verifiers/eddsa'

const message = new TextEncoder().encode('hello world')
const resolver = new Resolver({
...EdDSA.verifier,
})
const signer = await EdDSASigner.generate()
const signature = await signer.sign(message)
const verified = await resolver.verify({
signature,
message,
...signer,
})
```

```js
import { EdDSASigner } from 'iso-signatures/signers/eddsa'
import * as EdDSA from 'iso-signatures/verifiers/eddsa'
import * as ECDSA from 'iso-signatures/verifiers/ecdsa'
import * as RSA from 'iso-signatures/verifiers/rsa'

const message = new TextEncoder().encode('hello world')
const resolver = new Resolver(
{
...ECDSA.verifier,
...EdDSA.verifier,
},
{ cache: true }
)
const signer = await EdDSASigner.generate()
const signature = await signer.sign(message)
const verified = await resolver.verify({
signature,
message,
...signer.did, // Signer and DID both have `alg` property that the resolver uses to find the correct verifier
})
```

## Docs

Check <https://hugomrdias.github.io/iso-repo/modules/iso_signatures.html>

## License

MIT © [Hugo Dias](http://hugodias.me)
File renamed without changes.
1 change: 1 addition & 0 deletions packages/iso-signatures/src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
throw new Error('Incorrect "iso-signatures" usage. Import submodules instead')
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
/* eslint-disable unicorn/numeric-separators-style */
import { webcrypto } from 'iso-base/crypto'
import { u8 } from 'iso-base/utils'
import { DIDKey } from '../../key.js'
import { keyTypeToAlg } from '../../common.js'
import { DIDKey, keyTypeToAlg } from 'iso-did/key'
import { createEcdsaParams } from '../utils.js'

/**
* @typedef {import('./types.js').ISigner<CryptoKeyPair>} ISigner
* @typedef {Extract<import('../../types.js').SignatureAlgorithm, 'ES256' | 'ES384' | 'ES512'>} ECDSAAlg
* @typedef {import('../types.js').ISigner<CryptoKeyPair>} ISigner
* @typedef {Extract<import('iso-did/types').SignatureAlgorithm, 'ES256' | 'ES384' | 'ES512'>} ECDSAAlg
*/

/**
Expand Down
Loading

0 comments on commit a2e6265

Please sign in to comment.