Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: update multiformats, publish as ESM #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
runs-on: ${{ matrix.os }}
strategy:
matrix:
node: ['12.x', '14.x']
node: ['16.x', '18.x']
os: [ubuntu-latest, macOS-latest]

steps:
Expand Down
3 changes: 3 additions & 0 deletions babel.config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": [["@babel/preset-env", { "targets": { "node": 16 } }], "@babel/preset-typescript"]
}
24 changes: 7 additions & 17 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,8 @@
module.exports = {
globals: {
'ts-jest': {
tsConfigFile: 'tsconfig.json'
}
},
moduleFileExtensions: [
'ts',
'js'
],
transform: {
'^.+\\.(ts|tsx)$': './node_modules/ts-jest/preprocessor.js'
},
testMatch: [
'./**/**.test.(ts)'
],
testEnvironment: 'node'
export default {
testPathIgnorePatterns: ['.*__fixtures__.*'],
testEnvironment: 'node',
extensionsToTreatAsEsm: ['.ts'],
moduleNameMapper: {
'^(\\.{1,2}/.*)\\.js$': '$1'
}
}
55,813 changes: 18,533 additions & 37,280 deletions package-lock.json

Large diffs are not rendered by default.

28 changes: 18 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,20 +1,26 @@
{
"name": "did-key-creator",
"version" : "0.3.2",
"desciption" : "This is a library for converting public keys to the did:key format",
"source" : "src/index.ts",
"version": "0.3.2",
"desciption": "This is a library for converting public keys to the did:key format",
"source": "src/index.ts",
"typings": "lib/index.d.ts",
"main": "lib/index.js",
"type": "module",
"license": "(Apache-2.0 OR MIT)",
"files": [
"lib",
"src"
],
"exports": {
".": {
"types": "./lib/index.d.ts",
"import": "./lib/index.js"
}
},
"engines": {
"node": ">=12"
},
"scripts": {
"test": "jest --silent",
"test": "NODE_OPTIONS=--experimental-vm-modules npx jest",
"build": "tsc -p tsconfig.json",
"start": "tsdx watch",
"prepublishOnly": "npm run build",
Expand All @@ -28,21 +34,23 @@
},
"author": "Brent Shambaugh <[email protected]>",
"devDependencies": {
"@babel/core": "^7.14.3",
"@babel/preset-env": "^7.14.4",
"@babel/preset-typescript": "^7.13.0",
"@size-limit/preset-small-lib": "^4.10.1",
"@types/elliptic": "^6.4.12",
"@types/jest": "^29.1.2",
"eslint": "^7.21.0",
"eslint-config-3box": "^0.2.0",
"husky": "^4.3.8",
"jest": "^29.2.0",
"prettier": "^2.2.1",
"size-limit": "^4.10.1",
"tsdx": "^0.14.1",
"tslib": "^2.1.0",
"typescript": "^4.2.3"
},
"dependencies": {
"multiformats": "^9.6.5",
"multicodec": "^3.0.1",
"ts-jest": "^28.0.5",
"uint8arrays": "^2.1.4"
"multiformats": "^10.0.1",
"uint8arrays": "^4.0.2"
}
}
5 changes: 0 additions & 5 deletions src/declarations.d.ts

This file was deleted.

28 changes: 14 additions & 14 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { ECPointCompress,
compressedKeyInHexfromRaw,
uncompressedKeyInHexfromRaw,
rawKeyInHexfromUncompressed,
pubKeyHexToUint8Array,
didKeyIDtoPubKeyHex,
didKeyURLtoPubKeyHex } from './did_key_utils'
compressedKeyInHexfromRaw,
uncompressedKeyInHexfromRaw,
rawKeyInHexfromUncompressed,
pubKeyHexToUint8Array,
didKeyIDtoPubKeyHex,
didKeyURLtoPubKeyHex } from './did_key_utils.js'

import { encodeDIDfromHexString, encodeDIDfromBytes } from './encodeDIDkey'
import { encodeDIDfromHexString, encodeDIDfromBytes } from './encodeDIDkey.js'

export { ECPointCompress,
compressedKeyInHexfromRaw,
uncompressedKeyInHexfromRaw,
rawKeyInHexfromUncompressed,
pubKeyHexToUint8Array,
didKeyIDtoPubKeyHex,
compressedKeyInHexfromRaw,
uncompressedKeyInHexfromRaw,
rawKeyInHexfromUncompressed,
pubKeyHexToUint8Array,
didKeyIDtoPubKeyHex,
didKeyURLtoPubKeyHex,
encodeDIDfromHexString,
encodeDIDfromHexString,
encodeDIDfromBytes
}
}
3 changes: 0 additions & 3 deletions test/__SNAPSHOTS__/index.test.ts.snap

This file was deleted.

22 changes: 11 additions & 11 deletions test/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as u8a from 'uint8arrays'

import { encodeDIDfromHexString, encodeDIDfromBytes } from '../src/encodeDIDkey'
import { compressedKeyInHexfromRaw, ECPointCompress, uncompressedKeyInHexfromRaw, rawKeyInHexfromUncompressed, pubKeyHexToUint8Array, didKeyIDtoPubKeyHex, didKeyURLtoPubKeyHex } from '../src/did_key_utils'
import { encodeDIDfromHexString, encodeDIDfromBytes } from '../src/encodeDIDkey.js'
import { compressedKeyInHexfromRaw, ECPointCompress, uncompressedKeyInHexfromRaw, rawKeyInHexfromUncompressed, pubKeyHexToUint8Array, didKeyIDtoPubKeyHex, didKeyURLtoPubKeyHex } from '../src/did_key_utils.js'

describe('did-key-creator-p256', () => {
test('encodeDIDfromBytes', () => {
Expand All @@ -26,7 +26,7 @@ describe('did-key-creator-p256', () => {
const compressedKey = compressedKeyInHexfromRaw(key);
expect(encodeDIDfromHexString(multicodecName,compressedKey)).toMatchSnapshot()
})

test('compressedKeyInHexfromRaw', () => {
const key = 'f9c36f8964623378bdc068d4bce07ed17c8fa486f9ac0c2613ca3c8c306d7bb61cd36717b8ac5e4fea8ad23dc8d0783c2318ee4ad7a80db6e0026ad0b072a24f';
expect(compressedKeyInHexfromRaw(key)).toMatchSnapshot()
Expand All @@ -36,7 +36,7 @@ describe('did-key-creator-p256', () => {
const publicKeyHex = 'f9c36f8964623378bdc068d4bce07ed17c8fa486f9ac0c2613ca3c8c306d7bb61cd36717b8ac5e4fea8ad23dc8d0783c2318ee4ad7a80db6e0026ad0b072a24f';
const xHex = publicKeyHex.slice(0,publicKeyHex.length/2);
const yHex = publicKeyHex.slice(publicKeyHex.length/2,publicKeyHex.length);

const xOctet = u8a.fromString(xHex,'base16')
const yOctet = u8a.fromString(yHex,'base16')
expect(ECPointCompress( xOctet , yOctet )).toMatchSnapshot()
Expand All @@ -51,7 +51,7 @@ describe('did-key-creator-p256', () => {
const key = '04f9c36f8964623378bdc068d4bce07ed17c8fa486f9ac0c2613ca3c8c306d7bb61cd36717b8ac5e4fea8ad23dc8d0783c2318ee4ad7a80db6e0026ad0b072a24f';
expect(rawKeyInHexfromUncompressed(key)).toMatchSnapshot()
})

test('pubKeyHexToUint8Array', () => {
const key = 'f9c36f8964623378bdc068d4bce07ed17c8fa486f9ac0c2613ca3c8c306d7bb61cd36717b8ac5e4fea8ad23dc8d0783c2318ee4ad7a80db6e0026ad0b072a24f';
expect(pubKeyHexToUint8Array(key)).toMatchSnapshot()
Expand Down Expand Up @@ -85,7 +85,7 @@ describe('did-key-creator-p384', () => {
const key = '9489d3c65f1f8cb2a9fd40abc48d160e495a862fbbfbfe896ed8878e246f32f85e76129574705f8b61c263cb7f409c9ccba375202fb6997c47ade113056ecade605cc34a86af70961c2b3eca5d3dc824112dcc9f1afed786a0278073aee7566f';
expect(encodeDIDfromHexString(multicodecName,key)).toMatchSnapshot()
})

test('compressedKeyInHexfromRaw', () => {
const key = '9489d3c65f1f8cb2a9fd40abc48d160e495a862fbbfbfe896ed8878e246f32f85e76129574705f8b61c263cb7f409c9ccba375202fb6997c47ade113056ecade605cc34a86af70961c2b3eca5d3dc824112dcc9f1afed786a0278073aee7566f';
expect(compressedKeyInHexfromRaw(key)).toMatchSnapshot()
Expand All @@ -103,7 +103,7 @@ describe('did-key-creator-p384', () => {
const publicKeyHex = '9489d3c65f1f8cb2a9fd40abc48d160e495a862fbbfbfe896ed8878e246f32f85e76129574705f8b61c263cb7f409c9ccba375202fb6997c47ade113056ecade605cc34a86af70961c2b3eca5d3dc824112dcc9f1afed786a0278073aee7566f';
const xHex = publicKeyHex.slice(0,publicKeyHex.length/2);
const yHex = publicKeyHex.slice(publicKeyHex.length/2,publicKeyHex.length);

const xOctet = u8a.fromString(xHex,'base16')
const yOctet = u8a.fromString(yHex,'base16')
expect(ECPointCompress( xOctet , yOctet )).toMatchSnapshot()
Expand All @@ -118,7 +118,7 @@ describe('did-key-creator-p384', () => {
const key = '049489d3c65f1f8cb2a9fd40abc48d160e495a862fbbfbfe896ed8878e246f32f85e76129574705f8b61c263cb7f409c9ccba375202fb6997c47ade113056ecade605cc34a86af70961c2b3eca5d3dc824112dcc9f1afed786a0278073aee7566f';
expect(rawKeyInHexfromUncompressed(key)).toMatchSnapshot()
})

test('pubKeyHexToUint8Array', () => {
const key = '9489d3c65f1f8cb2a9fd40abc48d160e495a862fbbfbfe896ed8878e246f32f85e76129574705f8b61c263cb7f409c9ccba375202fb6997c47ade113056ecade605cc34a86af70961c2b3eca5d3dc824112dcc9f1afed786a0278073aee7566f';
expect(pubKeyHexToUint8Array(key)).toMatchSnapshot()
Expand Down Expand Up @@ -152,7 +152,7 @@ describe('did-key-creator-p521', () => {
const key = '0125073ccca272143441b1d9f687cdc7f978cbb96e9dc9f97de28ba373a92769d26d9a02ee67dfa258f9bb2eece8a48a5c59a7356c46278d883ab8d9e3baaac2ac92016f738880b865041548d98b969e7dc982ab8d1634fd5a8ef86388610f6d6293eb68129496810877a708fefca70b3959599b56a6038cdc73e160481ac10ef4dd18c2';
expect(encodeDIDfromHexString(multicodecName,key)).toMatchSnapshot()
})

// this is the standard use case
test('encodeDIDfromHexStringtoCompressed', () => {
const multicodecName = 'p521-pub';
Expand All @@ -170,7 +170,7 @@ describe('did-key-creator-p521', () => {
const publicKeyHex = '0125073ccca272143441b1d9f687cdc7f978cbb96e9dc9f97de28ba373a92769d26d9a02ee67dfa258f9bb2eece8a48a5c59a7356c46278d883ab8d9e3baaac2ac92016f738880b865041548d98b969e7dc982ab8d1634fd5a8ef86388610f6d6293eb68129496810877a708fefca70b3959599b56a6038cdc73e160481ac10ef4dd18c2';
const xHex = publicKeyHex.slice(0,publicKeyHex.length/2);
const yHex = publicKeyHex.slice(publicKeyHex.length/2,publicKeyHex.length);

const xOctet = u8a.fromString(xHex,'base16')
const yOctet = u8a.fromString(yHex,'base16')
expect(ECPointCompress( xOctet , yOctet )).toMatchSnapshot()
Expand All @@ -185,7 +185,7 @@ describe('did-key-creator-p521', () => {
const key = '040125073ccca272143441b1d9f687cdc7f978cbb96e9dc9f97de28ba373a92769d26d9a02ee67dfa258f9bb2eece8a48a5c59a7356c46278d883ab8d9e3baaac2ac92016f738880b865041548d98b969e7dc982ab8d1634fd5a8ef86388610f6d6293eb68129496810877a708fefca70b3959599b56a6038cdc73e160481ac10ef4dd18c2';
expect(rawKeyInHexfromUncompressed(key)).toMatchSnapshot()
})

test('pubKeyHexToUint8Array', () => {
const key = '0125073ccca272143441b1d9f687cdc7f978cbb96e9dc9f97de28ba373a92769d26d9a02ee67dfa258f9bb2eece8a48a5c59a7356c46278d883ab8d9e3baaac2ac92016f738880b865041548d98b969e7dc982ab8d1634fd5a8ef86388610f6d6293eb68129496810877a708fefca70b3959599b56a6038cdc73e160481ac10ef4dd18c2';
expect(pubKeyHexToUint8Array(key)).toMatchSnapshot()
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.eslint.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"extends": "./tsconfig.json",
"include": ["src/declarations.d.ts", "test"]
"include": ["test"]
}
5 changes: 3 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"compilerOptions": {
"module": "commonjs",
"module": "ES2022",
"lib": ["es6", "dom", "esnext"],
"target": "ES2020",
"declaration": true,
Expand All @@ -16,7 +16,8 @@
"./types", "node_modules/@types"
],
"outDir":"lib",
"rootDir":"src"
"rootDir":"src",
"moduleResolution": "node"
},
"include": [
"./src/**/*"
Expand Down