Skip to content

Commit

Permalink
feat: v0.1.4 | Remove legacy method
Browse files Browse the repository at this point in the history
  • Loading branch information
li0ard committed Sep 27, 2024
1 parent 675a079 commit b45eee5
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 29 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Build package

on:
push:
branches: [ main ]
paths-ignore:
- '*.md' # ignore changes to readmes
- '*.js' # ignore js files
pull_request:
branches: [ main ]

permissions:
contents: read
pages: write
id-token: write

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: oven-sh/setup-bun@v2

- name: Install dependencies
run: bun i

- name: Build package
run: bun run build

- name: Commit JS files
run: |
set +e
git add dist/
git config user.name "$(git --no-pager log --format=format:'%an' -n 1)"
git config user.email "$(git --no-pager log --format=format:'%ae' -n 1)"
git commit -m "build: build package"
git push "https://$GITHUB_ACTOR:[email protected]/$GITHUB_REPOSITORY"
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,6 @@ dist
# Finder (MacOS) folder config
.DS_Store

docs
docs

dist/
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@li0ard/ecdsa_icao",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"version": "0.1.3",
"version": "0.1.4",
"type": "module",
"repository": {
"type": "git",
Expand Down
32 changes: 5 additions & 27 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,38 +1,17 @@
import { createCurve } from "@noble/curves/_shortw_utils";
import { Field } from "@noble/curves/abstract/modular";
import { type CurveFn } from "@noble/curves/abstract/weierstrass";
import { sha1 } from "@noble/hashes/sha1";
import { sha224, sha256 } from "@noble/hashes/sha256";
import { sha384, sha512 } from "@noble/hashes/sha512";
import { ECParameters } from "@peculiar/asn1-ecc";
import { type ECParameters } from "@peculiar/asn1-ecc";
import TLV from "node-tlv";

import { p256 } from "@noble/curves/p256"
import { p384 } from "@noble/curves/p384"
import { p521 } from "@noble/curves/p521"
import { secp256k1 } from "@noble/curves/secp256k1"
import { ed25519 } from "@noble/curves/ed25519"
import { ed448 } from "@noble/curves/ed448"

/**
* Identify curve by `p` field
* @param params Public key parameters
*/
export const identifyCurveByP = (params: ECParameters) => {
let curves = [p256, p384, p521, secp256k1, ed25519, ed448]
let curvesObj: {[key: string]: any} = {}

for(let i of curves) {
curvesObj[i.CURVE.p.toString()] = i
}
return curvesObj[BigInt(`0x${TLV.parse(Buffer.from(params.specifiedCurve?.fieldID.parameters as ArrayBuffer)).value}`).toString()]
}


/**
* Convert buffer to BigInt
* @param data Input buffer
*/
const bufToBigInt = (data: Buffer) => {
const bufToBigInt = (data: Buffer): bigint => {
return BigInt(`0x${data.toString("hex")}`)
}

Expand All @@ -41,12 +20,12 @@ const bufToBigInt = (data: Buffer) => {
* @param params Public key parameters
* @param lowS Low order
*/
export const curveFromECParams = (params: ECParameters, lowS: boolean = false) => {
export const curveFromECParams = (params: ECParameters, lowS: boolean = false): CurveFn => {
if(!params.specifiedCurve) throw new Error("Only explicit ECC parameters supported");
if(params.specifiedCurve.fieldID.fieldType != "1.2.840.10045.1.1") throw new Error("Only explicit [X9.62] schema supported");

let base = Buffer.from(params.specifiedCurve.base.buffer).subarray(1)

return createCurve({
a: bufToBigInt(Buffer.from(params.specifiedCurve.curve.a)),
b: bufToBigInt(Buffer.from(params.specifiedCurve.curve.b)),
Expand Down Expand Up @@ -74,4 +53,3 @@ export const hashFromECDSAOID = (oid: string): typeof sha1 | typeof sha256 | typ
}
return algorithms[oid]
}

0 comments on commit b45eee5

Please sign in to comment.