Skip to content
This repository was archived by the owner on Jul 21, 2023. It is now read-only.

Commit 9d60e39

Browse files
maschadachingbrain
andauthored
deps(dev): upgrade aegir to 38.1.2 (#302)
Co-authored-by: Alex Potsides <[email protected]>
1 parent b66007c commit 9d60e39

32 files changed

+181
-146
lines changed

package.json

+4-6
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@
165165
"scripts": {
166166
"clean": "aegir clean",
167167
"lint": "aegir lint",
168-
"dep-check": "aegir dep-check",
168+
"dep-check": "aegir dep-check -i protons",
169169
"build": "aegir build",
170170
"test": "aegir test",
171171
"test:chrome": "aegir test -t browser",
@@ -186,16 +186,14 @@
186186
"multiformats": "^11.0.0",
187187
"node-forge": "^1.1.0",
188188
"protons-runtime": "^4.0.1",
189+
"uint8arraylist": "^2.4.3",
189190
"uint8arrays": "^4.0.2"
190191
},
191192
"devDependencies": {
192193
"@types/mocha": "^10.0.0",
193-
"aegir": "^37.0.12",
194+
"aegir": "^38.1.2",
194195
"benchmark": "^2.1.4",
195-
"protons": "^6.0.0",
196-
"sinon": "^15.0.0",
197-
"util": "^0.12.3",
198-
"wherearewe": "^2.0.1"
196+
"util": "^0.12.5"
199197
},
200198
"browser": {
201199
"./dist/src/aes/ciphers.js": "./dist/src/aes/ciphers-browser.js",

src/aes/cipher-mode.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const CIPHER_MODES = {
55
32: 'aes-256-ctr'
66
}
77

8-
export function cipherMode (key: Uint8Array) {
8+
export function cipherMode (key: Uint8Array): string {
99
if (key.length === 16 || key.length === 32) {
1010
return CIPHER_MODES[key.length]
1111
}

src/aes/ciphers-browser.ts

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@ import forge from 'node-forge/lib/forge.js'
55
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
66
import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
77

8-
export function createCipheriv (mode: any, key: Uint8Array, iv: Uint8Array) {
8+
export interface Cipher {
9+
update: (data: Uint8Array) => Uint8Array
10+
}
11+
12+
export function createCipheriv (mode: any, key: Uint8Array, iv: Uint8Array): Cipher {
913
const cipher2 = forge.cipher.createCipher('AES-CTR', uint8ArrayToString(key, 'ascii'))
1014
cipher2.start({ iv: uint8ArrayToString(iv, 'ascii') })
1115
return {
@@ -16,7 +20,7 @@ export function createCipheriv (mode: any, key: Uint8Array, iv: Uint8Array) {
1620
}
1721
}
1822

19-
export function createDecipheriv (mode: any, key: Uint8Array, iv: Uint8Array) {
23+
export function createDecipheriv (mode: any, key: Uint8Array, iv: Uint8Array): Cipher {
2024
const cipher2 = forge.cipher.createDecipher('AES-CTR', uint8ArrayToString(key, 'ascii'))
2125
cipher2.start({ iv: uint8ArrayToString(iv, 'ascii') })
2226
return {

src/aes/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export interface AESCipher {
66
decrypt: (data: Uint8Array) => Promise<Uint8Array>
77
}
88

9-
export async function create (key: Uint8Array, iv: Uint8Array) { // eslint-disable-line require-await
9+
export async function create (key: Uint8Array, iv: Uint8Array): Promise<AESCipher> { // eslint-disable-line require-await
1010
const mode = cipherMode(key)
1111
const cipher = ciphers.createCipheriv(mode, key, iv)
1212
const decipher = ciphers.createDecipheriv(mode, key, iv)

src/ciphers/aes-gcm.browser.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { CreateOptions, AESCipher } from './interface.js'
55

66
// Based off of code from https://github.com/luke-park/SecureCompatibleEncryptionExamples
77

8-
export function create (opts?: CreateOptions) {
8+
export function create (opts?: CreateOptions): AESCipher {
99
const algorithm = opts?.algorithm ?? 'AES-GCM'
1010
let keyLength = opts?.keyLength ?? 16
1111
const nonceLength = opts?.nonceLength ?? 12
@@ -20,7 +20,7 @@ export function create (opts?: CreateOptions) {
2020
* Uses the provided password to derive a pbkdf2 key. The key
2121
* will then be used to encrypt the data.
2222
*/
23-
async function encrypt (data: Uint8Array, password: string | Uint8Array) { // eslint-disable-line require-await
23+
async function encrypt (data: Uint8Array, password: string | Uint8Array): Promise<Uint8Array> { // eslint-disable-line require-await
2424
const salt = crypto.getRandomValues(new Uint8Array(saltLength))
2525
const nonce = crypto.getRandomValues(new Uint8Array(nonceLength))
2626
const aesGcm = { name: algorithm, iv: nonce }
@@ -45,7 +45,7 @@ export function create (opts?: CreateOptions) {
4545
* this decryption cipher must be the same as those used to create
4646
* the encryption cipher.
4747
*/
48-
async function decrypt (data: Uint8Array, password: string | Uint8Array) {
48+
async function decrypt (data: Uint8Array, password: string | Uint8Array): Promise<Uint8Array> {
4949
const salt = data.subarray(0, saltLength)
5050
const nonce = data.subarray(saltLength, saltLength + nonceLength)
5151
const ciphertext = data.subarray(saltLength + nonceLength)

src/ciphers/aes-gcm.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import type { CreateOptions, AESCipher } from './interface.js'
55

66
// Based off of code from https://github.com/luke-park/SecureCompatibleEncryptionExamples
77

8-
export function create (opts?: CreateOptions) {
8+
export function create (opts?: CreateOptions): AESCipher {
99
const algorithm = opts?.algorithm ?? 'aes-128-gcm'
1010
const keyLength = opts?.keyLength ?? 16
1111
const nonceLength = opts?.nonceLength ?? 12
@@ -14,7 +14,7 @@ export function create (opts?: CreateOptions) {
1414
const iterations = opts?.iterations ?? 32767
1515
const algorithmTagLength = opts?.algorithmTagLength ?? 16
1616

17-
async function encryptWithKey (data: Uint8Array, key: Uint8Array) { // eslint-disable-line require-await
17+
async function encryptWithKey (data: Uint8Array, key: Uint8Array): Promise<Uint8Array> { // eslint-disable-line require-await
1818
const nonce = crypto.randomBytes(nonceLength)
1919

2020
// Create the cipher instance.
@@ -31,7 +31,7 @@ export function create (opts?: CreateOptions) {
3131
* Uses the provided password to derive a pbkdf2 key. The key
3232
* will then be used to encrypt the data.
3333
*/
34-
async function encrypt (data: Uint8Array, password: string | Uint8Array) { // eslint-disable-line require-await
34+
async function encrypt (data: Uint8Array, password: string | Uint8Array): Promise<Uint8Array> { // eslint-disable-line require-await
3535
// Generate a 128-bit salt using a CSPRNG.
3636
const salt = crypto.randomBytes(saltLength)
3737

@@ -53,7 +53,7 @@ export function create (opts?: CreateOptions) {
5353
* this decryption cipher must be the same as those used to create
5454
* the encryption cipher.
5555
*/
56-
async function decryptWithKey (ciphertextAndNonce: Uint8Array, key: Uint8Array) { // eslint-disable-line require-await
56+
async function decryptWithKey (ciphertextAndNonce: Uint8Array, key: Uint8Array): Promise<Uint8Array> { // eslint-disable-line require-await
5757
// Create Uint8Arrays of nonce, ciphertext and tag.
5858
const nonce = ciphertextAndNonce.subarray(0, nonceLength)
5959
const ciphertext = ciphertextAndNonce.subarray(nonceLength, ciphertextAndNonce.length - algorithmTagLength)
@@ -77,7 +77,7 @@ export function create (opts?: CreateOptions) {
7777
* @param {Uint8Array} data - The data to decrypt
7878
* @param {string|Uint8Array} password - A plain password
7979
*/
80-
async function decrypt (data: Uint8Array, password: string | Uint8Array) { // eslint-disable-line require-await
80+
async function decrypt (data: Uint8Array, password: string | Uint8Array): Promise<Uint8Array> { // eslint-disable-line require-await
8181
// Create Uint8Arrays of salt and ciphertextAndNonce.
8282
const salt = data.subarray(0, saltLength)
8383
const ciphertextAndNonce = data.subarray(saltLength)

src/hmac/index-browser.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ const hashTypes = {
77
SHA512: 'SHA-512'
88
}
99

10-
const sign = async (key: CryptoKey, data: Uint8Array) => {
10+
const sign = async (key: CryptoKey, data: Uint8Array): Promise<Uint8Array> => {
1111
const buf = await webcrypto.get().subtle.sign({ name: 'HMAC' }, key, data)
1212
return new Uint8Array(buf, 0, buf.byteLength)
1313
}
1414

15-
export async function create (hashType: 'SHA1' | 'SHA256' | 'SHA512', secret: Uint8Array) {
15+
export async function create (hashType: 'SHA1' | 'SHA256' | 'SHA512', secret: Uint8Array): Promise<{ digest: (data: Uint8Array) => Promise<Uint8Array>, length: number }> {
1616
const hash = hashTypes[hashType]
1717

1818
const key = await webcrypto.get().subtle.importKey(

src/hmac/index.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import crypto from 'crypto'
22
import lengths from './lengths.js'
33

4-
export async function create (hash: 'SHA1' | 'SHA256' | 'SHA512', secret: Uint8Array) { // eslint-disable-line require-await
4+
export interface HMAC {
5+
digest: (data: Uint8Array) => Promise<Uint8Array>
6+
length: number
7+
}
8+
9+
export async function create (hash: 'SHA1' | 'SHA256' | 'SHA512', secret: Uint8Array): Promise<HMAC> {
510
const res = {
611
async digest (data: Uint8Array) { // eslint-disable-line require-await
712
const hmac = crypto.createHmac(hash.toLowerCase(), secret)

src/keys/ecdh-browser.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { base64urlToBuffer } from '../util.js'
44
import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
55
import { concat as uint8ArrayConcat } from 'uint8arrays/concat'
66
import { equals as uint8ArrayEquals } from 'uint8arrays/equals'
7-
import type { ECDHKey, ECDHKeyPair } from './interface.js'
7+
import type { ECDHKey, ECDHKeyPair, JWKEncodedPrivateKey, JWKEncodedPublicKey } from './interface.js'
88

99
const bits = {
1010
'P-256': 256,
@@ -15,7 +15,7 @@ const bits = {
1515
const curveTypes = Object.keys(bits)
1616
const names = curveTypes.join(' / ')
1717

18-
export async function generateEphmeralKeyPair (curve: string) {
18+
export async function generateEphmeralKeyPair (curve: string): Promise<ECDHKey> {
1919
if (curve !== 'P-256' && curve !== 'P-384' && curve !== 'P-521') {
2020
throw new CodeError(`Unknown curve: ${curve}. Must be ${names}`, 'ERR_INVALID_CURVE')
2121
}
@@ -30,7 +30,7 @@ export async function generateEphmeralKeyPair (curve: string) {
3030
)
3131

3232
// forcePrivate is used for testing only
33-
const genSharedKey = async (theirPub: Uint8Array, forcePrivate?: ECDHKeyPair) => {
33+
const genSharedKey = async (theirPub: Uint8Array, forcePrivate?: ECDHKeyPair): Promise<Uint8Array> => {
3434
let privateKey
3535

3636
if (forcePrivate != null) {
@@ -92,7 +92,7 @@ const curveLengths = {
9292
// Marshal converts a jwk encoded ECDH public key into the
9393
// form specified in section 4.3.6 of ANSI X9.62. (This is the format
9494
// go-ipfs uses)
95-
function marshalPublicKey (jwk: JsonWebKey) {
95+
function marshalPublicKey (jwk: JsonWebKey): Uint8Array {
9696
if (jwk.crv == null || jwk.x == null || jwk.y == null) {
9797
throw new CodeError('JWK was missing components', 'ERR_INVALID_PARAMETERS')
9898
}
@@ -111,7 +111,7 @@ function marshalPublicKey (jwk: JsonWebKey) {
111111
}
112112

113113
// Unmarshal converts a point, serialized by Marshal, into an jwk encoded key
114-
function unmarshalPublicKey (curve: string, key: Uint8Array) {
114+
function unmarshalPublicKey (curve: string, key: Uint8Array): JWKEncodedPublicKey {
115115
if (curve !== 'P-256' && curve !== 'P-384' && curve !== 'P-521') {
116116
throw new CodeError(`Unknown curve: ${curve}. Must be ${names}`, 'ERR_INVALID_CURVE')
117117
}
@@ -131,7 +131,7 @@ function unmarshalPublicKey (curve: string, key: Uint8Array) {
131131
}
132132
}
133133

134-
const unmarshalPrivateKey = (curve: string, key: ECDHKeyPair) => ({
134+
const unmarshalPrivateKey = (curve: string, key: ECDHKeyPair): JWKEncodedPrivateKey => ({
135135
...unmarshalPublicKey(curve, key.public),
136136
d: uint8ArrayToString(key.private, 'base64url')
137137
})

src/keys/ed25519-browser.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as ed from '@noble/ed25519'
2+
import type { Uint8ArrayKeyPair } from './interface'
23

34
const PUBLIC_KEY_BYTE_LENGTH = 32
45
const PRIVATE_KEY_BYTE_LENGTH = 64 // private key is actually 32 bytes but for historical reasons we concat private and public keys
@@ -7,7 +8,7 @@ const KEYS_BYTE_LENGTH = 32
78
export { PUBLIC_KEY_BYTE_LENGTH as publicKeyLength }
89
export { PRIVATE_KEY_BYTE_LENGTH as privateKeyLength }
910

10-
export async function generateKey () {
11+
export async function generateKey (): Promise<Uint8ArrayKeyPair> {
1112
// the actual private key (32 bytes)
1213
const privateKeyRaw = ed.utils.randomPrivateKey()
1314
const publicKey = await ed.getPublicKey(privateKeyRaw)
@@ -24,7 +25,7 @@ export async function generateKey () {
2425
/**
2526
* Generate keypair from a 32 byte uint8array
2627
*/
27-
export async function generateKeyFromSeed (seed: Uint8Array) {
28+
export async function generateKeyFromSeed (seed: Uint8Array): Promise<Uint8ArrayKeyPair> {
2829
if (seed.length !== KEYS_BYTE_LENGTH) {
2930
throw new TypeError('"seed" must be 32 bytes in length.')
3031
} else if (!(seed instanceof Uint8Array)) {
@@ -43,17 +44,17 @@ export async function generateKeyFromSeed (seed: Uint8Array) {
4344
}
4445
}
4546

46-
export async function hashAndSign (privateKey: Uint8Array, msg: Uint8Array) {
47+
export async function hashAndSign (privateKey: Uint8Array, msg: Uint8Array): Promise<Uint8Array> {
4748
const privateKeyRaw = privateKey.subarray(0, KEYS_BYTE_LENGTH)
4849

4950
return await ed.sign(msg, privateKeyRaw)
5051
}
5152

52-
export async function hashAndVerify (publicKey: Uint8Array, sig: Uint8Array, msg: Uint8Array) {
53+
export async function hashAndVerify (publicKey: Uint8Array, sig: Uint8Array, msg: Uint8Array): Promise<boolean> {
5354
return await ed.verify(sig, msg, publicKey)
5455
}
5556

56-
function concatKeys (privateKeyRaw: Uint8Array, publicKey: Uint8Array) {
57+
function concatKeys (privateKeyRaw: Uint8Array, publicKey: Uint8Array): Uint8Array {
5758
const privateKey = new Uint8Array(PRIVATE_KEY_BYTE_LENGTH)
5859
for (let i = 0; i < KEYS_BYTE_LENGTH; i++) {
5960
privateKey[i] = privateKeyRaw[i]

0 commit comments

Comments
 (0)