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

fix: fix repo to use new aegir #89

Merged
merged 24 commits into from
Feb 24, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ node_modules/
.nyc_output
lib
dist
docs

# Logs
logs
Expand Down
9 changes: 5 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,33 @@ jobs:
- stage: check
script:
- yarn aegir dep-check
- npx aegir ts -p check
- yarn run lint
- yarn run build

- stage: test
name: chrome
addons:
chrome: stable
script: npx aegir test -t browser -t webworker --node true --ts
script: npx aegir test -t browser -t webworker

- stage: test
name: firefox
addons:
firefox: latest
script: npx aegir test -t browser -t webworker --ts --node true -- --browsers FirefoxHeadless
script: npx aegir test -t browser -t webworker -- --browsers FirefoxHeadless

- stage: test
name: electron-main
os: osx
script:
- npx aegir test -t electron-main --bail --ts
- npx aegir test -t electron-main --bail

- stage: test
name: electron-renderer
os: osx
script:
- npx aegir test -t electron-renderer --node true --bail --ts
- npx aegir test -t electron-renderer --bail

notifications:
email: false
31 changes: 19 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,30 @@
"scripts": {
"bench": "node benchmarks/benchmark.js",
"clean": "rm -rf dist",
"copy-dts": "copyfiles -u 1 \"src/**/*.d.ts\" dist/src",
"build": "aegir build --ts",
"copy-dts": "copyup \"src/**/*.d.ts\" dist/src",
"build": "aegir build",
"postbuild": "yarn run copy-dts",
"lint": "aegir lint --ts",
"lint:fix": "aegir lint --ts --fix",
"test": "aegir test --ts --node true",
"test:node": "aegir test -t node --ts",
"test:browser": "aegir test -t browser --node true --ts",
"lint": "aegir lint",
"lint:fix": "aegir lint --fix",
"test": "aegir ts -p check && aegir test",
"test:node": "aegir test -t node",
"test:browser": "aegir test -t browser",
"docs": "aegir docs",
"proto:gen": "pbjs -t static-module -o ./src/proto/payload.js ./src/proto/payload.proto && pbts -o ./src/proto/payload.d.ts ./src/proto/payload.js && yarn run lint --fix"
},
"aegir" :{
"node": true,
"tsRepo": true,
"docs": {
"entryPoint": "src/index.ts"
}
},
"devDependencies": {
"@types/bl": "^2.1.0",
"@types/chai": "^4.2.4",
"@types/mocha": "^5.2.7",
"aegir": "28.2.0",
"aegir": "ipfs/aegir#feat/ts-repo-support",
"benchmark": "^2.1.4",
"chai": "^4.2.0",
"copyfiles": "^2.4.1",
"eslint-config-ipfs": "^0.1.0",
"karma-mocha-webworker": "^1.3.0",
"microtime": "^3.0.0",
"mocha": "^8.2.1",
Expand All @@ -65,7 +70,9 @@
"eslintConfig": {
"extends": "ipfs",
"rules": {
"@typescript-eslint/no-unused-vars": "error"
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/explicit-function-return-type": "warn",
"@typescript-eslint/strict-boolean-expressions": "off"
},
"ignorePatterns": [
"src/proto/payload.js"
Expand Down
12 changes: 6 additions & 6 deletions src/@types/basic.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {Buffer} from 'buffer';
import { Buffer } from 'buffer'

export type bytes = Buffer;
export type bytes32 = Buffer;
export type bytes16 = Buffer;
export type bytes = Buffer
export type bytes32 = Buffer
export type bytes16 = Buffer

export type uint32 = number;
export type uint64 = number;
export type uint32 = number
export type uint64 = number
16 changes: 8 additions & 8 deletions src/@types/handshake-interface.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {bytes} from "./basic";
import {NoiseSession} from "./handshake";
import PeerId from "peer-id";
import { bytes } from './basic'
import { NoiseSession } from './handshake'
import PeerId from 'peer-id'

export interface IHandshake {
session: NoiseSession;
remotePeer: PeerId;
remoteEarlyData: Buffer;
encrypt(plaintext: bytes, session: NoiseSession): bytes;
decrypt(ciphertext: bytes, session: NoiseSession): {plaintext: bytes; valid: boolean};
session: NoiseSession
remotePeer: PeerId
remoteEarlyData: Buffer
encrypt: (plaintext: bytes, session: NoiseSession) => bytes
decrypt: (ciphertext: bytes, session: NoiseSession) => {plaintext: bytes, valid: boolean}
}
62 changes: 31 additions & 31 deletions src/@types/handshake.d.ts
Original file line number Diff line number Diff line change
@@ -1,45 +1,45 @@
import {bytes, bytes32, uint32, uint64} from "./basic";
import {KeyPair} from "./libp2p";
import { bytes, bytes32, uint32, uint64 } from './basic'
import { KeyPair } from './libp2p'

export type Hkdf = [bytes, bytes, bytes];
export type Hkdf = [bytes, bytes, bytes]

export type MessageBuffer = {
ne: bytes32;
ns: bytes;
ciphertext: bytes;
export interface MessageBuffer {
ne: bytes32
ns: bytes
ciphertext: bytes
}

export type CipherState = {
k: bytes32;
n: uint32;
export interface CipherState {
k: bytes32
n: uint32
}

export type SymmetricState = {
cs: CipherState;
ck: bytes32; // chaining key
h: bytes32; // handshake hash
export interface SymmetricState {
cs: CipherState
ck: bytes32 // chaining key
h: bytes32 // handshake hash
}

export type HandshakeState = {
ss: SymmetricState;
s: KeyPair;
e?: KeyPair;
rs: bytes32;
re: bytes32;
psk: bytes32;
export interface HandshakeState {
ss: SymmetricState
s: KeyPair
e?: KeyPair
rs: bytes32
re: bytes32
psk: bytes32
}

export type NoiseSession = {
hs: HandshakeState;
h?: bytes32;
cs1?: CipherState;
cs2?: CipherState;
mc: uint64;
i: boolean;
export interface NoiseSession {
hs: HandshakeState
h?: bytes32
cs1?: CipherState
cs2?: CipherState
mc: uint64
i: boolean
}

export interface INoisePayload {
identityKey: bytes;
identitySig: bytes;
data: bytes;
identityKey: bytes
identitySig: bytes
data: bytes
}
30 changes: 15 additions & 15 deletions src/@types/it-length-prefixed/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,33 @@ declare module 'it-length-prefixed' {
import { Buffer } from 'buffer'

interface LengthDecoderFunction {
(data: Buffer | BufferList): number;
bytes: number;
(data: Buffer | BufferList): number
bytes: number
}

interface LengthEncoderFunction {
(value: number, target: Buffer, offset: number): number|Buffer;
bytes: number;
(value: number, target: Buffer, offset: number): number|Buffer
bytes: number
}

interface Encoder {
(options?: Partial<{lengthEncoder: LengthEncoderFunction}>): AsyncGenerator<BufferList, Buffer>;
single: (chunk: Buffer, options?: Partial<{lengthEncoder: LengthEncoderFunction}>) => BufferList;
MIN_POOL_SIZE: number;
DEFAULT_POOL_SIZE: number;
(options?: Partial<{lengthEncoder: LengthEncoderFunction}>): AsyncGenerator<BufferList, Buffer>
single: (chunk: Buffer, options?: Partial<{lengthEncoder: LengthEncoderFunction}>) => BufferList
MIN_POOL_SIZE: number
DEFAULT_POOL_SIZE: number
}

interface DecoderOptions {
lengthDecoder: LengthDecoderFunction;
maxLengthLength: number;
maxDataLength: number;
lengthDecoder: LengthDecoderFunction
maxLengthLength: number
maxDataLength: number
}

interface Decoder {
(options?: Partial<DecoderOptions>): AsyncGenerator<BufferList, BufferList>;
fromReader: (reader: any, options?: Partial<DecoderOptions>) => BufferList;
MAX_LENGTH_LENGTH: number;
MAX_DATA_LENGTH: number;
(options?: Partial<DecoderOptions>): AsyncGenerator<BufferList, BufferList>
fromReader: (reader: any, options?: Partial<DecoderOptions>) => BufferList
MAX_LENGTH_LENGTH: number
MAX_DATA_LENGTH: number
}

export const encode: Encoder
Expand Down
8 changes: 4 additions & 4 deletions src/@types/it-pair/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
declare module 'it-pair' {
export type Duplex = [Stream, Stream];
export type Duplex = [Stream, Stream]

type Stream = {
sink(source: Iterable<any>): void;
source: Record<string, any>;
interface Stream {
sink: (source: Iterable<any>) => void
source: Record<string, any>
}
}
25 changes: 12 additions & 13 deletions src/@types/libp2p.d.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import { bytes, bytes32 } from "./basic";
import PeerId from "peer-id";
import { bytes, bytes32 } from './basic'
import PeerId from 'peer-id'

export type KeyPair = {
publicKey: bytes32;
privateKey: bytes32;
export interface KeyPair {
publicKey: bytes32
privateKey: bytes32
}

export interface INoiseConnection {
remoteEarlyData?(): bytes;
secureOutbound(localPeer: PeerId, insecure: any, remotePeer: PeerId): Promise<SecureOutbound>;
secureInbound(localPeer: PeerId, insecure: any, remotePeer: PeerId): Promise<SecureOutbound>;
remoteEarlyData?: () => bytes
secureOutbound: (localPeer: PeerId, insecure: any, remotePeer: PeerId) => Promise<SecureOutbound>
secureInbound: (localPeer: PeerId, insecure: any, remotePeer: PeerId) => Promise<SecureOutbound>
}

export type SecureOutbound = {
conn: any;
remoteEarlyData: Buffer;
remotePeer: PeerId;
export interface SecureOutbound {
conn: any
remoteEarlyData: Buffer
remotePeer: PeerId
}

2 changes: 1 addition & 1 deletion src/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { IHandshake } from './@types/handshake-interface'
import { NOISE_MSG_MAX_LENGTH_BYTES, NOISE_MSG_MAX_LENGTH_BYTES_WITHOUT_TAG } from './constants'

interface IReturnEncryptionWrapper {
(source: Iterable<Uint8Array>): AsyncIterableIterator<Uint8Array>;
(source: Iterable<Uint8Array>): AsyncIterableIterator<Uint8Array>
}

// Returns generator that encrypts payload from the user
Expand Down
2 changes: 1 addition & 1 deletion src/errors.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import BufferList from 'bl'

export class FailedIKError extends Error {
public initialMsg: string|BufferList|Buffer;
public initialMsg: string|BufferList|Buffer

constructor (initialMsg: string|BufferList|Buffer, message?: string) {
super(message)
Expand Down
28 changes: 15 additions & 13 deletions src/handshake-ik.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ import {
import PeerId from 'peer-id'

export class IKHandshake implements IHandshake {
public isInitiator: boolean;
public session: NoiseSession;
public remotePeer!: PeerId;
public remoteEarlyData: Buffer;
public isInitiator: boolean
public session: NoiseSession
public remotePeer!: PeerId
public remoteEarlyData: Buffer

private payload: bytes;
private prologue: bytes32;
private staticKeypair: KeyPair;
private connection: WrappedConnection;
private ik: IK;
private readonly payload: bytes
private readonly prologue: bytes32
private readonly staticKeypair: KeyPair
private readonly connection: WrappedConnection
private readonly ik: IK

constructor (
isInitiator: boolean,
Expand All @@ -48,7 +48,7 @@ export class IKHandshake implements IHandshake {
if (remotePeer) {
this.remotePeer = remotePeer
}
this.ik = handshake || new IK()
this.ik = handshake ?? new IK()
this.session = this.ik.initSession(this.isInitiator, this.prologue, this.staticKeypair, remoteStaticKey)
this.remoteEarlyData = Buffer.alloc(0)
}
Expand Down Expand Up @@ -79,9 +79,10 @@ export class IKHandshake implements IHandshake {
logger('IK Stage 0 - Responder successfully verified payload!')
logRemoteEphemeralKey(this.session.hs.re)
} catch (e) {
const err = e as Error
logger('Responder breaking up with IK handshake in stage 0.')

throw new FailedIKError(receivedMsg, `Error occurred while verifying initiator's signed payload: ${e.message}`)
throw new FailedIKError(receivedMsg, `Error occurred while verifying initiator's signed payload: ${err.message}`)
}
}
}
Expand All @@ -104,8 +105,9 @@ export class IKHandshake implements IHandshake {
logger('IK Stage 1 - Initiator successfully verified payload!')
logRemoteEphemeralKey(this.session.hs.re)
} catch (e) {
const err = e as Error
logger('Initiator breaking up with IK handshake in stage 1.')
throw new FailedIKError(receivedMsg, `Error occurred while verifying responder's signed payload: ${e.message}`)
throw new FailedIKError(receivedMsg, `Error occurred while verifying responder's signed payload: ${err.message}`)
}
} else {
logger('IK Stage 1 - Responder sending message...')
Expand All @@ -117,7 +119,7 @@ export class IKHandshake implements IHandshake {
logCipherState(this.session)
}

public decrypt (ciphertext: bytes, session: NoiseSession): {plaintext: bytes; valid: boolean} {
public decrypt (ciphertext: bytes, session: NoiseSession): {plaintext: bytes, valid: boolean} {
const cs = this.getCS(session, false)
return this.ik.decryptWithAd(cs, Buffer.alloc(0), ciphertext)
}
Expand Down
Loading