This repository has been archived by the owner on Jul 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Converts this module to typescript with ESM-only publishing. Part of the wider effor to move libp2p to the bright new future of proper types and ESM: libp2p/js-libp2p#1021
- Loading branch information
1 parent
508c790
commit 7875906
Showing
98 changed files
with
1,885 additions
and
4,408 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,62 @@ | ||
{ | ||
"name": "libp2p-crypto", | ||
"name": "@libp2p/crypto", | ||
"version": "0.21.0", | ||
"description": "Crypto primitives for libp2p", | ||
"main": "src/index.js", | ||
"types": "src/index.d.ts", | ||
"leadMaintainer": "Jacob Heun <[email protected]>", | ||
"browser": { | ||
"./src/aes/ciphers.js": "./src/aes/ciphers-browser.js", | ||
"./src/ciphers/aes-gcm.js": "./src/ciphers/aes-gcm.browser.js", | ||
"./src/hmac/index.js": "./src/hmac/index-browser.js", | ||
"./src/keys/ecdh.js": "./src/keys/ecdh-browser.js", | ||
"./src/keys/rsa.js": "./src/keys/rsa-browser.js" | ||
"type": "module", | ||
"types": "./dist/src/index.d.ts", | ||
"exports": { | ||
".": { | ||
"import": "./dist/src/index.js" | ||
}, | ||
"./aes": { | ||
"import": "./dist/src/aes/index.js" | ||
}, | ||
"./ciphers": { | ||
"import": "./dist/src/ciphers/index.js" | ||
}, | ||
"./hmac": { | ||
"import": "./dist/src/hmac/index.js" | ||
}, | ||
"./keys": { | ||
"import": "./dist/src/keys/index.js" | ||
} | ||
}, | ||
"files": [ | ||
"src", | ||
"dist" | ||
"dist/src", | ||
"!**/*.tsbuildinfo" | ||
], | ||
"eslintConfig": { | ||
"extends": "ipfs", | ||
"parserOptions": { | ||
"sourceType": "module" | ||
}, | ||
"ignorePatterns": [ | ||
"src/*.d.ts" | ||
] | ||
}, | ||
"scripts": { | ||
"lint": "aegir lint", | ||
"dep-check": "aegir dep-check package.json dep-check src/**/*.js test/**/*.js", | ||
"build": "npm run build:proto && aegir build --no-types", | ||
"build:proto": "pbjs -t static-module -w commonjs -r libp2p-crypto-keys --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/keys/keys.js ./src/keys/keys.proto", | ||
"test": "aegir test", | ||
"test:node": "aegir test -t node", | ||
"test:browser": "aegir test -t browser -t webworker", | ||
"release": "aegir release", | ||
"release-minor": "aegir release --type minor", | ||
"release-major": "aegir release --type major", | ||
"coverage": "aegir coverage --ignore src/keys/keys.proto.js", | ||
"size": "aegir build --bundlesize --no-types", | ||
"test:types": "npx tsc" | ||
"pretest": "npm run build", | ||
"test": "aegir test -f ./dist/test/**/*.js", | ||
"test:browser": "aegir test -t browser -f ./dist/test/**/*.js", | ||
"test:node": "aegir test -t node -f ./dist/test/**/*.js", | ||
"test:electron": "aegir test -t electron-main -f ./dist/test/**/*.js", | ||
"lint": "aegir ts -p check && aegir lint", | ||
"release": "aegir release --docs", | ||
"release-minor": "aegir release --target node --type minor --docs", | ||
"release-major": "aegir release --type major --docs", | ||
"build": "tsc", | ||
"build:proto": "npm run build:proto:js && npm run build:proto:types", | ||
"build:proto:js": "pbjs -t static-module -w es6 --es6 -r libp2p-crypto-keys --force-number --no-verify --no-delimited --no-create --no-beautify --no-defaults --lint eslint-disable -o src/keys/keys.js ./src/keys/keys.proto", | ||
"build:proto:types": "pbts -o src/keys/keys.d.ts src/keys/keys.js", | ||
"dep-check": "aegir dep-check dist/src/**/*.js dist/test/**/*.js" | ||
}, | ||
"browser": { | ||
"./dist/src/aes/ciphers.js": "./dist/src/aes/ciphers-browser.js", | ||
"./dist/src/ciphers/aes-gcm.js": "./dist/src/ciphers/aes-gcm.browser.js", | ||
"./dist/src/hmac/index.js": "./dist/src/hmac/index-browser.js", | ||
"./dist/src/keys/ecdh.js": "./dist/src/keys/ecdh-browser.js", | ||
"./dist/src/keys/rsa.js": "./dist/src/keys/rsa-browser.js" | ||
}, | ||
"keywords": [ | ||
"IPFS", | ||
|
@@ -40,8 +67,8 @@ | |
], | ||
"license": "MIT", | ||
"dependencies": { | ||
"@noble/ed25519": "^1.3.0", | ||
"@noble/secp256k1": "^1.3.0", | ||
"@noble/ed25519": "^1.3.3", | ||
"@noble/secp256k1": "^1.3.4", | ||
"err-code": "^3.0.1", | ||
"iso-random-stream": "^2.0.0", | ||
"multiformats": "^9.4.5", | ||
|
@@ -54,21 +81,11 @@ | |
"aegir": "^36.0.2", | ||
"benchmark": "^2.1.4", | ||
"sinon": "^12.0.1", | ||
"util": "^0.12.3" | ||
}, | ||
"aegir": { | ||
"build": { | ||
"bundlesizeMax": "71kB" | ||
} | ||
"util": "^0.12.3", | ||
"wherearewe": "^1.0.0" | ||
}, | ||
"engines": { | ||
"node": ">=12.0.0" | ||
}, | ||
"eslintConfig": { | ||
"extends": "ipfs", | ||
"ignorePatterns": [ | ||
"src/*.d.ts" | ||
] | ||
"node": ">=15.0.0" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import errcode from 'err-code' | ||
|
||
const CIPHER_MODES = { | ||
16: 'aes-128-ctr', | ||
32: 'aes-256-ctr' | ||
} | ||
|
||
export function cipherMode (key: Uint8Array) { | ||
if (key.length === 16 || key.length === 32) { | ||
return CIPHER_MODES[key.length] | ||
} | ||
|
||
const modes = Object.entries(CIPHER_MODES).map(([k, v]) => `${k} (${v})`).join(' / ') | ||
throw errcode(new Error(`Invalid key length ${key.length} bytes. Must be ${modes}`), 'ERR_INVALID_KEY_LENGTH') | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
import 'node-forge/lib/aes.js' | ||
// @ts-expect-error types are missing | ||
import forge from 'node-forge/lib/forge.js' | ||
import { toString as uint8ArrayToString } from 'uint8arrays/to-string' | ||
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string' | ||
|
||
export function createCipheriv (mode: any, key: Uint8Array, iv: Uint8Array) { | ||
const cipher2 = forge.cipher.createCipher('AES-CTR', uint8ArrayToString(key, 'ascii')) | ||
cipher2.start({ iv: uint8ArrayToString(iv, 'ascii') }) | ||
return { | ||
update: (data: Uint8Array) => { | ||
cipher2.update(forge.util.createBuffer(uint8ArrayToString(data, 'ascii'))) | ||
return uint8ArrayFromString(cipher2.output.getBytes(), 'ascii') | ||
} | ||
} | ||
} | ||
|
||
export function createDecipheriv (mode: any, key: Uint8Array, iv: Uint8Array) { | ||
const cipher2 = forge.cipher.createDecipher('AES-CTR', uint8ArrayToString(key, 'ascii')) | ||
cipher2.start({ iv: uint8ArrayToString(iv, 'ascii') }) | ||
return { | ||
update: (data: Uint8Array) => { | ||
cipher2.update(forge.util.createBuffer(uint8ArrayToString(data, 'ascii'))) | ||
return uint8ArrayFromString(cipher2.output.getBytes(), 'ascii') | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import crypto from 'crypto' | ||
|
||
export const createCipheriv = crypto.createCipheriv | ||
export const createDecipheriv = crypto.createDecipheriv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.