Skip to content
This repository has been archived by the owner on Oct 30, 2024. It is now read-only.

Typescript rewrite #93

Merged
merged 7 commits into from
Aug 1, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
use module style exports to maintain the way JS imports the compiled …
…code
  • Loading branch information
the-jackalope committed Jun 28, 2019
commit 733e49b7e98c3496cec302e9b0b3d1e00f7b0895
5 changes: 0 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,6 @@ package-lock.json
# Optional REPL history
.node_repl_history

# Build folder
# Update 2018-08-07: currently build is done to / (before: dist/) due to
# backwards compatibility reasons, JS files from root and root test/ folder
# are excluded
/*.js

# IDE and text editor config files
.idea
Expand Down
1 change: 1 addition & 0 deletions prettier.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('@ethereumjs/config-prettier')
6 changes: 4 additions & 2 deletions src/hdkey.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Wallet } from './index'
import Wallet = require('./index')

const HDKey = require('hdkey')

export class EthereumHDKey {
class EthereumHDKey {
public static fromMasterSeed(seedBuffer: Buffer): EthereumHDKey {
return new EthereumHDKey(HDKey.fromMasterSeed(seedBuffer))
}
Expand Down Expand Up @@ -39,3 +39,5 @@ export class EthereumHDKey {
return Wallet.fromPublicKey(this._hdkey._publicKey, true)
}
}

export = EthereumHDKey
7 changes: 6 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ function stripUnusedKDFParamsForScrypt(params: KDFParams): Partial<KDFParams> {
return params
}

export class Wallet {
class Wallet {
// static methods

public static generate(icapDirect: boolean = false): Wallet {
Expand Down Expand Up @@ -309,6 +309,9 @@ export class Wallet {
throw new Error('Cannot supply both a private and a public key to the constructor')
}

if (!privateKey && !publicKey) {
the-jackalope marked this conversation as resolved.
Show resolved Hide resolved
}

if (privateKey && !ethUtil.isValidPrivate(privateKey)) {
throw new Error('Private key does not satisfy the curve requirements (ie. it is invalid)')
}
Expand Down Expand Up @@ -442,3 +445,5 @@ function runCipherBuffer(cipher: crypto.Cipher | crypto.Decipher, data: Buffer):
function keyExists(k: Buffer | undefined): k is Buffer {
return k !== undefined
the-jackalope marked this conversation as resolved.
Show resolved Hide resolved
}

export = Wallet
6 changes: 4 additions & 2 deletions src/provider-engine.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Wallet } from './index'
import Wallet = require('./index')

const HookedWalletEthTxSubprovider = require('web3-provider-engine/subproviders/hooked-wallet-ethtx')

export class WalletSubprovider extends HookedWalletEthTxSubprovider {
class WalletSubprovider extends HookedWalletEthTxSubprovider {
constructor(wallet: Wallet, opts?: any) {
if (!opts) {
opts = {}
Expand All @@ -20,3 +20,5 @@ export class WalletSubprovider extends HookedWalletEthTxSubprovider {
super(opts)
}
}

export = WalletSubprovider
6 changes: 4 additions & 2 deletions src/thirdparty.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as crypto from 'crypto'
import * as ethUtil from 'ethereumjs-util'

import { Wallet } from './index'
import Wallet = require('./index')

const scryptsy = require('scrypt.js')
const utf8 = require('utf8')
Expand Down Expand Up @@ -239,9 +239,11 @@ function fromQuorumWallet(passphrase: string, userid: string): Wallet {
return new Wallet(seed)
}

export const Thirdparty = {
const Thirdparty = {
fromEtherWallet,
fromEtherCamp,
fromKryptoKit,
fromQuorumWallet,
}

export = Thirdparty
2 changes: 1 addition & 1 deletion test/hdkey.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as assert from 'assert'
import { EthereumHDKey } from '../src/hdkey'
import EthereumHDKey = require('../src/hdkey')

// from BIP39 mnemonic: awake book subject inch gentle blur grant damage process float month clown
const fixtureseed = Buffer.from(
Expand Down
4 changes: 2 additions & 2 deletions test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
import * as assert from 'assert'
import * as ethUtil from 'ethereumjs-util'

import { Wallet } from '../src'
import { Thirdparty } from '../src/thirdparty'
import Wallet = require('../src')
import Thirdparty = require('../src/thirdparty')

const fixturePrivateKey = 'efca4cdd31923b50f4214af5d2ae10e7ac45a5019e9431cc195482d707485378'
const fixturePrivateKeyStr = '0x' + fixturePrivateKey
Expand Down