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

Replace request with fetch (and fix other bugs) #86

Merged
merged 101 commits into from
Feb 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
101 commits
Select commit Hold shift + click to select a range
486cd9d
Replace request with cross-fetch
qgustavor Jan 16, 2022
73bebc4
Update Standard and fix related issues
qgustavor Jan 16, 2022
a5a7246
Replace rollup with esbuild and update ava
qgustavor Jan 16, 2022
bd3ea5f
Fix failing tests
qgustavor Jan 16, 2022
2ca44c2
Some fixes
qgustavor Jan 17, 2022
48248e2
Try to fix issues while downloading
qgustavor Jan 17, 2022
36e9fe2
I should have been commiting more often
qgustavor Jan 19, 2022
d3b3c81
Add note about MAC implementation
qgustavor Jan 20, 2022
17db83a
Separate authentication from encryption
qgustavor Jan 20, 2022
3bf81ff
Lock out, lock in
qgustavor Jan 20, 2022
4aec3be
Attempt to fix #83
qgustavor Jan 20, 2022
261d118
Fix the issue with Node 14
qgustavor Jan 20, 2022
b9b168b
Don't forget to fix files other than the reported one
qgustavor Jan 20, 2022
c1ebb33
Attempt to fix #54
qgustavor Jan 20, 2022
5afdac4
Attempt to fix #84
qgustavor Jan 20, 2022
2ce9485
Remember to use the linter
qgustavor Jan 20, 2022
e90184b
The fix for #84 is going to break some code
qgustavor Jan 20, 2022
76c35e7
Fix issue when source is not defined
qgustavor Jan 20, 2022
c10d130
Move test helper to a folder
qgustavor Jan 20, 2022
a85357c
Fix build and test built code
qgustavor Jan 20, 2022
df68697
Implement verify test
qgustavor Jan 20, 2022
01ff7f4
Implement browser version of the MAC class
qgustavor Jan 20, 2022
6832571
Do not set stream.mac if verification is disabled
qgustavor Jan 20, 2022
72024bd
Setup multiple runtime test environment
qgustavor Jan 21, 2022
6fb0b85
Fix tests
qgustavor Jan 21, 2022
443ebaf
Fix some issues found in Deno tests
qgustavor Jan 21, 2022
1286a25
Fix crypto stream test on Deno
qgustavor Jan 22, 2022
8153a3e
Fix tests
qgustavor Jan 22, 2022
595527a
Fix zero length file uploading and add tests
qgustavor Jan 22, 2022
e9345bc
Fix build by creating dist folder
qgustavor Jan 22, 2022
6dcbf1f
Fix dumb mistake
qgustavor Jan 22, 2022
146583e
Try to fix ENOENT errors in CI
qgustavor Jan 22, 2022
a352c89
Trying to solve test issues in CI again
qgustavor Jan 22, 2022
f2406a3
Trying to solve test issues in CI by the third time
qgustavor Jan 23, 2022
18cd48e
Trying to solve test issues in CI by the fourth time
qgustavor Jan 23, 2022
b47796a
Bundle abort-controller on test
qgustavor Jan 23, 2022
9c77606
Avoid mixing cjs and mjs to fix abort-controller issue
qgustavor Jan 23, 2022
ed069d6
Simplify entry name
qgustavor Jan 27, 2022
15366de
need help with some typings
ChampionBuffalo1 Feb 1, 2022
27758dd
Make error in test-runner.mjs more descriptive
qgustavor Feb 1, 2022
70ece83
Completed AES and almost Storage
ChampionBuffalo1 Feb 1, 2022
1f93edd
Added key property to AES & fixed error type
ChampionBuffalo1 Feb 1, 2022
8c636c3
Finished API class and added @types/node & @types/node-fetch
ChampionBuffalo1 Feb 1, 2022
830240e
Not sure about File & MutableFile
ChampionBuffalo1 Feb 1, 2022
670cfe1
Added comments on/before unsure types along with event typins on Muta…
ChampionBuffalo1 Feb 1, 2022
557ab9d
Somewhat finish with File class
ChampionBuffalo1 Feb 2, 2022
b928d6f
Finished most of the typings
ChampionBuffalo1 Feb 2, 2022
b8b36c1
Removed some random test I did
ChampionBuffalo1 Feb 2, 2022
1c46314
Removed ` | undefined` as it was redundant
ChampionBuffalo1 Feb 2, 2022
a5babca
Update Standard and fix lint errors
qgustavor Feb 3, 2022
89e5d05
Update readme
qgustavor Feb 3, 2022
d7ced10
Merge branch 'replacing-request' into replacing-request
qgustavor Feb 4, 2022
23081d6
Added missing types
ChampionBuffalo1 Feb 5, 2022
688c56b
Handle callback, API and sharing issues
qgustavor Feb 5, 2022
849dc73
Do not prepend undefined to the user-agent
qgustavor Feb 5, 2022
3470343
Merge branch 'qgustavor:replacing-request' into replacing-request
ChampionBuffalo1 Feb 6, 2022
e757775
Fixed the typings of Fileopts & APIOpts
ChampionBuffalo1 Feb 6, 2022
3c84246
Removed the extra whitespace
ChampionBuffalo1 Feb 6, 2022
6566698
Removed useless comments
ChampionBuffalo1 Feb 6, 2022
5366934
Overloading Storage#reload to keep force as first parameter and optional
ChampionBuffalo1 Feb 6, 2022
a5907d0
Fixing typings generated by tsc
ChampionBuffalo1 Feb 6, 2022
4696c9c
Add promise support and tests
qgustavor Feb 6, 2022
6c84c84
Simplify implementation
qgustavor Feb 6, 2022
602e436
Merge branch 'qgustavor:replacing-request' into replacing-request
ChampionBuffalo1 Feb 7, 2022
9908031
Added Promise type
ChampionBuffalo1 Feb 7, 2022
014cece
Do not leave the promise unhandled when using a callback
qgustavor Feb 7, 2022
743d84c
Made cb optional for Promise based methods
ChampionBuffalo1 Feb 8, 2022
e2a0c9b
Fixed wrong types
ChampionBuffalo1 Feb 11, 2022
734e1e1
File returned from mkdir cb wont be null
ChampionBuffalo1 Feb 11, 2022
7dce3b3
Merge branch 'qgustavor:replacing-request' into replacing-request
ChampionBuffalo1 Feb 11, 2022
244f143
Merge pull request #87 from ChampionBuffalo1/replacing-request
qgustavor Feb 11, 2022
4d75545
Finished implementing promises
qgustavor Feb 11, 2022
aec2760
1.0.0-alpha.0
qgustavor Feb 11, 2022
3f06b60
Switch to ts-standard
qgustavor Feb 11, 2022
428c73e
Refresh package-lock.json
qgustavor Feb 11, 2022
2e71fff
Attempt fix on Node 14
qgustavor Feb 11, 2022
66e99f1
Revert "Attempt fix on Node 14"
qgustavor Feb 11, 2022
03de0c2
Try to fix testing again
qgustavor Feb 11, 2022
b4cfff7
Publish types and fix readme.md
qgustavor Feb 12, 2022
439728b
1.0.0-alpha.1
qgustavor Feb 12, 2022
96bdff0
Fix typings
qgustavor Feb 12, 2022
6949e51
1.0.0-alpha.2
qgustavor Feb 12, 2022
2ca0933
Add ESM types and fix CJS types
qgustavor Feb 12, 2022
5b0cec6
1.0.0-alpha.3
qgustavor Feb 12, 2022
48c7b57
Fix issue with folder sharing
qgustavor Feb 13, 2022
a56b683
1.0.0-alpha.4
qgustavor Feb 13, 2022
52b72c9
Fixes and improvements
qgustavor Feb 13, 2022
17778a0
1.0.0-alpha.5
qgustavor Feb 13, 2022
afc8db5
Handle closing better
qgustavor Feb 13, 2022
33cd0eb
1.0.0-alpha.6
qgustavor Feb 13, 2022
bac52ce
Remove pauseStream
qgustavor Feb 14, 2022
f45fd5c
Attempt fixing upload and download errors
qgustavor Feb 14, 2022
8029bcb
Fix downloading
qgustavor Feb 14, 2022
3245255
1.0.0-alpha.7
qgustavor Feb 14, 2022
cfffe33
Fix types
qgustavor Feb 14, 2022
1d534af
1.0.0-alpha.8
qgustavor Feb 14, 2022
9b88cc8
Fix abort handling
qgustavor Feb 18, 2022
41bd26c
1.0.0-alpha.9
qgustavor Feb 18, 2022
d5bc057
Attempt fix for promise never resolving
qgustavor Feb 18, 2022
28dcae1
1.0.0-alpha.10
qgustavor Feb 18, 2022
f1a34fc
1.0.0
qgustavor Feb 19, 2022
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
18 changes: 0 additions & 18 deletions .babelrc

This file was deleted.

66 changes: 66 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# This workflow will do a clean install of node dependencies, cache/restore them, run tests across different versions of node and deno

name: Test library

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
pre_check:
runs-on: ubuntu-latest
outputs:
should_skip: ${{ steps.skip_check.outputs.should_skip }}
steps:
- id: skip_check
uses: fkirc/skip-duplicate-actions@master

test-node:
needs: pre_check
if: ${{ needs.pre_check.outputs.should_skip != 'true' }}
runs-on: ubuntu-latest

strategy:
matrix:
node-version: [14.x, 16.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
cache: 'npm'
- run: npm ci
- run: npm run build --if-present
- run: npm run lint-js
- run: npm run lint-ts
if: ${{ matrix.node-version != '14.x' }}
- run: npm run test-runner node

test-deno:
needs: pre_check
if: ${{ needs.pre_check.outputs.should_skip != 'true' }}
runs-on: ubuntu-latest

strategy:
matrix:
deno-version: [v1.x]

steps:
- uses: actions/checkout@v2
# Testing code still depends on Node
# (mostly because mega-mock: no plan to migrate it to Deno)
- uses: actions/setup-node@v2
with:
node-version: 16.x
cache: 'npm'
- name: Use Deno ${{ matrix.deno-version }}
uses: denoland/setup-deno@v1
with:
deno-version: ${{ matrix.deno-version }}
- run: npm ci
- run: npm run build --if-present
- run: npm test deno
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,3 @@ jspm_packages

# Dist files are available via NPM, in order to avoid git noise
dist

# Using package-lock.json introduces cross-platform issues
/package-lock.json
5 changes: 0 additions & 5 deletions .travis.yml

This file was deleted.

11 changes: 11 additions & 0 deletions ava.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export default {
files: [
'test/**/*.test.mjs'
],
timeout: '20s',
failFast: true,
extensions: {
js: true,
mjs: true
}
}
90 changes: 55 additions & 35 deletions browser/aes.js → browser/aes.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AES as SjclAES } from './sjcl'
import { AES as SjclAES } from './sjcl.mjs'

// convert user-supplied password array
export function prepareKey (password) {
Expand Down Expand Up @@ -39,7 +39,7 @@ export function prepareKeyV2 (password, info, cb) {
name: 'PBKDF2',
salt,
iterations,
hash: {name: digest}
hash: { name: digest }
}, key, 256)
}).then(result => {
cb(null, Buffer.from(result))
Expand All @@ -56,7 +56,7 @@ class AES {

encryptCBC (buffer) {
let iv = [0, 0, 0, 0]
let d = Array(4)
const d = Array(4)
let i, j

for (i = 0; i < buffer.length; i += 16) {
Expand Down Expand Up @@ -160,45 +160,21 @@ class CTR {
this.ctr = Buffer.alloc(16)
this.nonce.copy(this.ctr, 0)

this.mac = Buffer.alloc(16)
this.nonce.copy(this.mac, 0)
this.nonce.copy(this.mac, 8)
this.macs = []

this.incrementCTR(start / 16)
}

condensedMac () {
if (this.mac) {
this.macs.push(this.mac)
this.mac = undefined
}

let mac = Buffer.alloc(16)

for (let i = 0; i < this.macs.length; i++) {
for (let j = 0; j < 16; j++) mac[j] ^= this.macs[i][j]
this.aes.encryptECB(mac)
}

const macBuffer = Buffer.allocUnsafe(8)
macBuffer.writeInt32BE(mac.readInt32BE(0) ^ mac.readInt32BE(4), 0)
macBuffer.writeInt32BE(mac.readInt32BE(8) ^ mac.readInt32BE(12), 4)
return macBuffer
}

encrypt (buffer) {
for (let i = 0; i < buffer.length; i += 16) {
const enc = this.aes.encryptECB(Buffer.from(this.ctr))

for (let j = 0; j < 16; j++) {
this.mac[j] ^= buffer[i + j]
buffer[i + j] ^= enc[j]
}

this.aes.encryptECB(this.mac)
this.incrementCTR()
}

return buffer
}

decrypt (buffer) {
Expand All @@ -207,17 +183,15 @@ class CTR {

for (let j = 0; j < 16; j++) {
buffer[i + j] ^= enc[j]
this.mac[j] ^= buffer[i + j]
}

this.aes.encryptECB(this.mac)
this.incrementCTR()
}

return buffer
}

incrementCTR (cnt = 1) {
for (let i = 0; i < cnt; i++) this.checkMacBounding()

const buf = this.ctr
let i = 15
let mod
Expand All @@ -229,8 +203,54 @@ class CTR {
if (i < 0) i = 15
}
}
}

class MAC {
constructor (aes, nonce, start = 0) {
this.aes = aes

this.nonce = nonce.slice(0, 8)
this.increment = 131072 // 2**17
this.posNext = this.increment
this.pos = 0

this.mac = Buffer.alloc(16)
this.nonce.copy(this.mac, 0)
this.nonce.copy(this.mac, 8)
this.macs = []
}

condense () {
if (this.mac) {
this.macs.push(this.mac)
this.mac = undefined
}

const mac = Buffer.alloc(16)

for (let i = 0; i < this.macs.length; i++) {
for (let j = 0; j < 16; j++) mac[j] ^= this.macs[i][j]
this.aes.encryptECB(mac)
}

const macBuffer = Buffer.allocUnsafe(8)
macBuffer.writeInt32BE(mac.readInt32BE(0) ^ mac.readInt32BE(4), 0)
macBuffer.writeInt32BE(mac.readInt32BE(8) ^ mac.readInt32BE(12), 4)
return macBuffer
}

update (buffer) {
for (let i = 0; i < buffer.length; i += 16) {
for (let j = 0; j < 16; j++) {
this.mac[j] ^= buffer[i + j]
}

this.aes.encryptECB(this.mac)
this.checkBounding()
}
}

checkMacBounding () {
checkBounding () {
this.pos += 16
if (this.pos >= this.posNext) {
this.macs.push(Buffer.from(this.mac))
Expand All @@ -245,4 +265,4 @@ class CTR {
}
}

export {AES, CTR}
export { AES, CTR, MAC }
2 changes: 2 additions & 0 deletions browser/fetch.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const fetch = globalThis.fetch
export default fetch
2 changes: 2 additions & 0 deletions browser/noop.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const Agent = null
export default Agent
8 changes: 8 additions & 0 deletions browser/process-shim.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export { Buffer } from 'buffer'
export const process = {
env: {},
nextTick: (fn, ...argv) => {
globalThis.setTimeout(fn, 0, ...argv)
}
}
export const global = globalThis
Loading