Skip to content

Commit

Permalink
sodium is now a peerDependency making it easier to use it in a browse…
Browse files Browse the repository at this point in the history
…r env without the need of installing also sodium
  • Loading branch information
vekexasia committed Dec 11, 2017
1 parent 8325407 commit cc2a354
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 6 deletions.
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@
"dependencies": {
"bignumber.js": "^4.0.4",
"bytebuffer": "^5.0.1",
"is-empty": "^1.2.0",
"sodium": "^2.0.1"
"is-empty": "^1.2.0"
},
"peerDependencies": {
"sodium": "^2.0.3"
},
"devDependencies": {
"@types/bytebuffer": "^5.0.33",
Expand All @@ -50,7 +52,6 @@
"chai": "^4.1.0",
"coveralls": "^3.0.0",
"empty-module": "0.0.2",
"js-nacl": "^1.2.2",
"karma": "^1.7.0",
"karma-chai": "^0.1.0",
"karma-chrome-launcher": "^2.2.0",
Expand Down
2 changes: 1 addition & 1 deletion src/trxTypes/BaseTx.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import BigNumber from 'bignumber.js';
import * as ByteBuffer from 'bytebuffer';
import * as empty from 'is-empty';
import {api as sodium} from 'sodium';
import {api as sodium} from '../utils/sodium';

import {bigNumberFromBuffer, bigNumberToBuffer} from '../utils/bignumber';
import {toSha256} from '../utils/sha256';
Expand Down
12 changes: 12 additions & 0 deletions src/utils/sodium.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
let toExport;
// tslint:disable no-var-requires
try {
toExport = require('sodium');
if (typeof(toExport) === 'undefined' || typeof(toExport.api) === 'undefined') {
throw new Error('switch to JS implementation');
}
} catch (err) {
// Sodium does not exist.
toExport = require('../browser/sodium');
}
export const api = toExport.api;
2 changes: 1 addition & 1 deletion src/wallet.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {api as sodium} from 'sodium';
import {toSha256} from './utils/sha256';
import {api as sodium} from './utils/sodium';
// tslint:disable-next-line no-var-requires
/**
* Generic Abstract Wallet.
Expand Down
2 changes: 1 addition & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const commonConfig = {
resolve: {
extensions: [".tsx", ".ts", ".js"],
alias : {
'sodium': path.resolve(__dirname, 'src/browser/sodium.ts'),
'sodium': 'empty-module',
'crypto': 'empty-module',
'./utils/sha256': path.resolve(__dirname, 'src/browser/sha256.ts'),
'../utils/sha256': path.resolve(__dirname, 'src/browser/sha256.ts'),
Expand Down

0 comments on commit cc2a354

Please sign in to comment.