@ -0,0 +1,86 @@ |
|||||
|
import { |
||||
|
triggerToaster |
||||
|
} from '../actionCreators'; |
||||
|
import { |
||||
|
logGuiHttp, |
||||
|
guiLogState |
||||
|
} from './log'; |
||||
|
import Config from '../../config'; |
||||
|
|
||||
|
export function getListUnspent(coin) { |
||||
|
return new Promise((resolve, reject) => { |
||||
|
const payload = { |
||||
|
mode: null, |
||||
|
chain: coin, |
||||
|
cmd: 'listunspent', |
||||
|
}; |
||||
|
|
||||
|
const _fetchConfig = { |
||||
|
method: 'POST', |
||||
|
headers: { |
||||
|
'Content-Type': 'application/json', |
||||
|
}, |
||||
|
body: JSON.stringify({ 'payload': payload }), |
||||
|
}; |
||||
|
|
||||
|
fetch( |
||||
|
`http://127.0.0.1:${Config.agamaPort}/shepherd/cli`, |
||||
|
_fetchConfig |
||||
|
) |
||||
|
.catch(function(error) { |
||||
|
console.log(error); |
||||
|
dispatch( |
||||
|
triggerToaster( |
||||
|
'getListUnspent', |
||||
|
'Error', |
||||
|
'error' |
||||
|
) |
||||
|
); |
||||
|
}) |
||||
|
.then(response => response.json()) |
||||
|
.then(json => { |
||||
|
resolve(json.result ? json.result : json); |
||||
|
}) |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
export function getRawTransaction(coin, txid) { |
||||
|
return new Promise((resolve, reject) => { |
||||
|
const payload = { |
||||
|
mode: null, |
||||
|
chain: coin, |
||||
|
cmd: 'getrawtransaction', |
||||
|
params: [ |
||||
|
txid, |
||||
|
1 |
||||
|
], |
||||
|
}; |
||||
|
|
||||
|
const _fetchConfig = { |
||||
|
method: 'POST', |
||||
|
headers: { |
||||
|
'Content-Type': 'application/json', |
||||
|
}, |
||||
|
body: JSON.stringify({ 'payload': payload }), |
||||
|
}; |
||||
|
|
||||
|
fetch( |
||||
|
`http://127.0.0.1:${Config.agamaPort}/shepherd/cli`, |
||||
|
_fetchConfig |
||||
|
) |
||||
|
.catch(function(error) { |
||||
|
console.log(error); |
||||
|
dispatch( |
||||
|
triggerToaster( |
||||
|
'getTransaction', |
||||
|
'Error', |
||||
|
'error' |
||||
|
) |
||||
|
); |
||||
|
}) |
||||
|
.then(response => response.json()) |
||||
|
.then(json => { |
||||
|
resolve(json.result ? json.result : json); |
||||
|
}) |
||||
|
}); |
||||
|
} |
@ -0,0 +1,164 @@ |
|||||
|
import { |
||||
|
triggerToaster, |
||||
|
getNewKMDAddresses |
||||
|
} from '../actionCreators'; |
||||
|
import { |
||||
|
logGuiHttp, |
||||
|
guiLogState |
||||
|
} from './log'; |
||||
|
import Config from '../../config'; |
||||
|
|
||||
|
function getNewAddress(coin) { // TODO: remove(?)
|
||||
|
return new Promise((resolve, reject) => { |
||||
|
const payload = { |
||||
|
mode: null, |
||||
|
chain: coin, |
||||
|
cmd: 'getnewaddress' |
||||
|
}; |
||||
|
|
||||
|
const _fetchConfig = { |
||||
|
method: 'POST', |
||||
|
headers: { |
||||
|
'Content-Type': 'application/json', |
||||
|
}, |
||||
|
body: JSON.stringify({ 'payload': payload }), |
||||
|
}; |
||||
|
|
||||
|
fetch( |
||||
|
`http://127.0.0.1:${Config.agamaPort}/shepherd/cli`, |
||||
|
_fetchConfig |
||||
|
) |
||||
|
.catch(function(error) { |
||||
|
console.log(error); |
||||
|
dispatch( |
||||
|
triggerToaster( |
||||
|
'genJumblrAddress + getKMDAddressesNative', |
||||
|
'Error', |
||||
|
'error' |
||||
|
) |
||||
|
); |
||||
|
}) |
||||
|
.then(response => response.json()) |
||||
|
.then(json => { |
||||
|
resolve(json.result ? json.result : json); |
||||
|
}) |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
export function setJumblrAddress(coin, type, address) { |
||||
|
return new Promise((resolve, reject) => { |
||||
|
const payload = { |
||||
|
mode: null, |
||||
|
chain: coin, |
||||
|
cmd: type === 'deposit' ? 'jumblr_deposit' : 'jumblr_secret', |
||||
|
params: [address], |
||||
|
}; |
||||
|
|
||||
|
const _fetchConfig = { |
||||
|
method: 'POST', |
||||
|
headers: { |
||||
|
'Content-Type': 'application/json', |
||||
|
}, |
||||
|
body: JSON.stringify({ 'payload': payload }), |
||||
|
}; |
||||
|
|
||||
|
fetch( |
||||
|
`http://127.0.0.1:${Config.agamaPort}/shepherd/cli`, |
||||
|
_fetchConfig |
||||
|
) |
||||
|
.catch(function(error) { |
||||
|
console.log(error); |
||||
|
dispatch( |
||||
|
triggerToaster( |
||||
|
'setJumblrAddress', |
||||
|
'Error', |
||||
|
'error' |
||||
|
) |
||||
|
); |
||||
|
}) |
||||
|
.then(response => response.json()) |
||||
|
.then(json => { |
||||
|
resolve(json); |
||||
|
}); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
function dumpPrivkey(coin, key) { |
||||
|
return new Promise((resolve, reject) => { |
||||
|
const payload = { |
||||
|
mode: null, |
||||
|
chain: coin, |
||||
|
cmd: 'dumpprivkey', |
||||
|
params: [key], |
||||
|
}; |
||||
|
|
||||
|
const _fetchConfig = { |
||||
|
method: 'POST', |
||||
|
headers: { |
||||
|
'Content-Type': 'application/json', |
||||
|
}, |
||||
|
body: JSON.stringify({ 'payload': payload }), |
||||
|
}; |
||||
|
|
||||
|
fetch( |
||||
|
`http://127.0.0.1:${Config.agamaPort}/shepherd/cli`, |
||||
|
_fetchConfig |
||||
|
) |
||||
|
.catch(function(error) { |
||||
|
console.log(error); |
||||
|
dispatch( |
||||
|
triggerToaster( |
||||
|
'dumpPrivkey ', |
||||
|
'Error', |
||||
|
'error' |
||||
|
) |
||||
|
); |
||||
|
}) |
||||
|
.then(response => response.json()) |
||||
|
.then(json => { |
||||
|
resolve(json.result ? json.result : json); |
||||
|
}) |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
export function importPrivkey(coin, key) { |
||||
|
return new Promise((resolve, reject) => { |
||||
|
const payload = { |
||||
|
mode: null, |
||||
|
chain: coin, |
||||
|
cmd: 'importprivkey', |
||||
|
params: [ |
||||
|
key, |
||||
|
'', |
||||
|
false |
||||
|
], |
||||
|
}; |
||||
|
|
||||
|
const _fetchConfig = { |
||||
|
method: 'POST', |
||||
|
headers: { |
||||
|
'Content-Type': 'application/json', |
||||
|
}, |
||||
|
body: JSON.stringify({ 'payload': payload }), |
||||
|
}; |
||||
|
|
||||
|
fetch( |
||||
|
`http://127.0.0.1:${Config.agamaPort}/shepherd/cli`, |
||||
|
_fetchConfig |
||||
|
) |
||||
|
.catch(function(error) { |
||||
|
console.log(error); |
||||
|
dispatch( |
||||
|
triggerToaster( |
||||
|
'importPrivkey ', |
||||
|
'Error', |
||||
|
'error' |
||||
|
) |
||||
|
); |
||||
|
}) |
||||
|
.then(response => response.json()) |
||||
|
.then(json => { |
||||
|
resolve(json.result ? json.result : json); |
||||
|
}) |
||||
|
}); |
||||
|
} |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 3.4 KiB |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 3.8 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 4.3 KiB After Width: | Height: | Size: 4.3 KiB |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 5.6 KiB |
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 3.8 KiB |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 8.5 KiB After Width: | Height: | Size: 8.5 KiB |
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 14 KiB |
Before Width: | Height: | Size: 8.9 KiB After Width: | Height: | Size: 8.9 KiB |
Before Width: | Height: | Size: 3.6 KiB After Width: | Height: | Size: 3.6 KiB |
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 9.0 KiB After Width: | Height: | Size: 9.0 KiB |
Before Width: | Height: | Size: 3.6 KiB After Width: | Height: | Size: 3.6 KiB |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 3.7 KiB |
Before Width: | Height: | Size: 8.5 KiB After Width: | Height: | Size: 8.5 KiB |
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 3.8 KiB |
Before Width: | Height: | Size: 10 KiB After Width: | Height: | Size: 10 KiB |
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
Before Width: | Height: | Size: 9.9 KiB After Width: | Height: | Size: 9.9 KiB |
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 3.8 KiB |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 7.8 KiB After Width: | Height: | Size: 7.8 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 3.7 KiB |
Before Width: | Height: | Size: 3.6 KiB After Width: | Height: | Size: 3.6 KiB |
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 12 KiB After Width: | Height: | Size: 12 KiB |
Before Width: | Height: | Size: 16 KiB After Width: | Height: | Size: 16 KiB |
Before Width: | Height: | Size: 13 KiB After Width: | Height: | Size: 13 KiB |
@ -0,0 +1,136 @@ |
|||||
|
import React from 'react'; |
||||
|
import ReactDOM from 'react-dom'; |
||||
|
import Store from '../../../store'; |
||||
|
import { |
||||
|
toggleClaimInterestModal, |
||||
|
getListUnspent, |
||||
|
getRawTransaction, |
||||
|
copyString, |
||||
|
sendToAddressPromise, |
||||
|
triggerToaster |
||||
|
} from '../../../actions/actionCreators'; |
||||
|
import { translate } from '../../../translate/translate'; |
||||
|
import { |
||||
|
ClaimInterestModalRender, |
||||
|
_ClaimInterestTableRender |
||||
|
} from './claimInterestModal.render'; |
||||
|
|
||||
|
class ClaimInterestModal extends React.Component { |
||||
|
constructor(props) { |
||||
|
super(props); |
||||
|
this.state = { |
||||
|
open: false, |
||||
|
isLoading: true, |
||||
|
transactionsList: [], |
||||
|
showZeroInterest: true, |
||||
|
}; |
||||
|
this.claimInterestTableRender = this.claimInterestTableRender.bind(this); |
||||
|
this.toggleZeroInterest = this.toggleZeroInterest.bind(this); |
||||
|
this.loadListUnspent = this.loadListUnspent.bind(this); |
||||
|
this.checkTransactionsListLength = this.checkTransactionsListLength.bind(this); |
||||
|
} |
||||
|
|
||||
|
componentWillMount() { |
||||
|
this.loadListUnspent(); |
||||
|
} |
||||
|
|
||||
|
loadListUnspent() { |
||||
|
let _transactionsList = []; |
||||
|
|
||||
|
getListUnspent(this.props.ActiveCoin.coin) |
||||
|
.then((json) => { |
||||
|
if (json && |
||||
|
json.length) { |
||||
|
for (let i = 0; i < json.length; i++) { |
||||
|
getRawTransaction(this.props.ActiveCoin.coin, json[i].txid) |
||||
|
.then((_json) => { |
||||
|
_transactionsList.push({ |
||||
|
address: json[i].address, |
||||
|
locktime: _json.locktime, |
||||
|
amount: json[i].amount, |
||||
|
interest: json[i].interest, |
||||
|
txid: json[i].txid, |
||||
|
}); |
||||
|
|
||||
|
if (i === json.length - 1) { |
||||
|
this.setState({ |
||||
|
transactionsList: _transactionsList, |
||||
|
isLoading: false, |
||||
|
}); |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
claimInterest(address, amount) { |
||||
|
sendToAddressPromise(this.props.ActiveCoin.coin, this.state.transactionsList[0].address, this.props.ActiveCoin.balance.transparent) |
||||
|
.then((json) => { |
||||
|
if (json.error && |
||||
|
json.error.code) { |
||||
|
Store.dispatch( |
||||
|
triggerToaster( |
||||
|
json.error.message, |
||||
|
'Error', |
||||
|
'error' |
||||
|
) |
||||
|
); |
||||
|
} else if (json.result && json.result.length && json.result.length === 64) { |
||||
|
Store.dispatch( |
||||
|
triggerToaster( |
||||
|
`Your full balance is sent to address ${this.state.transactionsList[0].address}. Check back your new balance in a few minutes.`, |
||||
|
translate('TOASTR.WALLET_NOTIFICATION'), |
||||
|
'success', |
||||
|
false |
||||
|
) |
||||
|
); |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
checkTransactionsListLength() { |
||||
|
if (this.state.transactionsList && this.state.transactionsList.length) { |
||||
|
return true; |
||||
|
} else if (!this.state.transactionsList || !this.state.transactionsList.length) { |
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
toggleZeroInterest() { |
||||
|
this.setState({ |
||||
|
showZeroInterest: !this.state.showZeroInterest, |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
copyTxId(txid) { |
||||
|
Store.dispatch(copyString(txid, 'Transaction ID copied')); |
||||
|
} |
||||
|
|
||||
|
claimInterestTableRender() { |
||||
|
return _ClaimInterestTableRender.call(this); |
||||
|
} |
||||
|
|
||||
|
componentWillReceiveProps(props) { |
||||
|
if (props.Dashboard.displayClaimInterestModal !== this.state.open) { |
||||
|
this.setState({ |
||||
|
open: props.Dashboard.displayClaimInterestModal, |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
if (!this.state.open && |
||||
|
props.Dashboard.displayClaimInterestModal) { |
||||
|
this.loadListUnspent(); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
closeModal() { |
||||
|
Store.dispatch(toggleClaimInterestModal(false)); |
||||
|
} |
||||
|
|
||||
|
render() { |
||||
|
return ClaimInterestModalRender.call(this); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
export default ClaimInterestModal; |
@ -0,0 +1,132 @@ |
|||||
|
import React from 'react'; |
||||
|
import { translate } from '../../../translate/translate'; |
||||
|
|
||||
|
const MIN_INTEREST_THRESHOLD = 0.001; |
||||
|
|
||||
|
export const _ClaimInterestTableRender = function() { |
||||
|
const _transactionsList = this.state.transactionsList; |
||||
|
let _items = []; |
||||
|
|
||||
|
for (let i = 0; i < _transactionsList.length; i++) { |
||||
|
if ((_transactionsList[i].interest === 0 && this.state.showZeroInterest) || (_transactionsList[i].amount > 0 && _transactionsList[i].interest > 0)) { |
||||
|
_items.push( |
||||
|
<tr key={ `${_transactionsList[i].txid}${_transactionsList[i].address}` }> |
||||
|
<td> |
||||
|
<button |
||||
|
className="btn btn-default btn-xs clipboard-edexaddr copy-string-btn" |
||||
|
title={ translate('INDEX.COPY_TO_CLIPBOARD') } |
||||
|
onClick={ () => this.copyTxId(_transactionsList[i].txid) }> |
||||
|
<i className="icon wb-copy"></i> { translate('INDEX.COPY') } |
||||
|
</button> |
||||
|
</td> |
||||
|
<td>{ _transactionsList[i].address }</td> |
||||
|
<td className={ _transactionsList[i].amount > 10 ? 'green bold' : '' }>{ _transactionsList[i].amount }</td> |
||||
|
<td>{ _transactionsList[i].interest }</td> |
||||
|
<td className="locktime center"> |
||||
|
{ _transactionsList[i].locktime && |
||||
|
<i className="fa-check-circle green"></i> |
||||
|
} |
||||
|
{ !_transactionsList[i].locktime && |
||||
|
<i className="fa-exclamation-circle red"></i> |
||||
|
} |
||||
|
</td> |
||||
|
</tr> |
||||
|
); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return ( |
||||
|
<span> |
||||
|
<div className="padding-bottom-20"> |
||||
|
<strong>Requirements to accrue interest:</strong> locktime field is set and amount is greater than <strong>10 KMD</strong> |
||||
|
</div> |
||||
|
<div className="text-left padding-top-10 padding-bottom-10"> |
||||
|
<label className="switch"> |
||||
|
<input |
||||
|
type="checkbox" |
||||
|
checked={ this.state.showZeroInterest } /> |
||||
|
<div |
||||
|
className="slider" |
||||
|
onClick={ this.toggleZeroInterest }></div> |
||||
|
</label> |
||||
|
<div |
||||
|
className="toggle-label margin-right-15 pointer" |
||||
|
onClick={ this.toggleZeroInterest }> |
||||
|
Show zero interest |
||||
|
</div> |
||||
|
</div> |
||||
|
<button |
||||
|
type="button" |
||||
|
className="btn btn-success waves-effect waves-light claim-btn" |
||||
|
onClick={ () => this.claimInterest() }> |
||||
|
<i className="icon fa-dollar"></i> Claim interest |
||||
|
</button> |
||||
|
<div className="table-scroll"> |
||||
|
<table className="table table-hover dataTable table-striped"> |
||||
|
<thead> |
||||
|
<tr> |
||||
|
<th></th> |
||||
|
<th>Address</th> |
||||
|
<th>Amount</th> |
||||
|
<th>Interest</th> |
||||
|
<th>Locktime</th> |
||||
|
</tr> |
||||
|
</thead> |
||||
|
<tbody> |
||||
|
{ _items } |
||||
|
</tbody> |
||||
|
<tfoot> |
||||
|
<tr> |
||||
|
<th></th> |
||||
|
<th>Address</th> |
||||
|
<th>Amount</th> |
||||
|
<th>Interest</th> |
||||
|
<th>Locktime</th> |
||||
|
</tr> |
||||
|
</tfoot> |
||||
|
</table> |
||||
|
</div> |
||||
|
</span> |
||||
|
); |
||||
|
}; |
||||
|
|
||||
|
export const ClaimInterestModalRender = function() { |
||||
|
return ( |
||||
|
<span> |
||||
|
<div className={ 'modal modal-claim-interest modal-3d-sign ' + (this.state.open ? 'show in' : 'fade hide') }> |
||||
|
<div className="modal-dialog modal-center modal-sm"> |
||||
|
<div className="modal-content"> |
||||
|
<div className="modal-header bg-orange-a400 wallet-send-header"> |
||||
|
<button |
||||
|
type="button" |
||||
|
className="close white" |
||||
|
onClick={ this.closeModal }> |
||||
|
<span>×</span> |
||||
|
</button> |
||||
|
<h4 className="modal-title white text-left">Claim interest</h4> |
||||
|
</div> |
||||
|
<div className="modal-body"> |
||||
|
<i |
||||
|
className="icon fa-refresh pointer refresh-icon" |
||||
|
onClick={ this.loadListUnspent }></i> |
||||
|
<div className="animsition vertical-align fade-in"> |
||||
|
<div className="page-content vertical-align-middle full-width"> |
||||
|
{ this.state.isLoading && |
||||
|
<span>Loading interest data...</span> |
||||
|
} |
||||
|
{ !this.state.isLoading && this.checkTransactionsListLength() && |
||||
|
<div>{ this.claimInterestTableRender() }</div> |
||||
|
} |
||||
|
{ !this.state.isLoading && !this.checkTransactionsListLength() && |
||||
|
<div>No data</div> |
||||
|
} |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
</div> |
||||
|
<div className={ 'modal-backdrop ' + (this.state.open ? 'show in' : 'fade hide') }></div> |
||||
|
</span> |
||||
|
); |
||||
|
}; |
@ -0,0 +1,28 @@ |
|||||
|
import React from 'react'; |
||||
|
import WalletsNativeInfoRender from './walletsInfo.render'; |
||||
|
import { toggleClaimInterestModal } from '../../../actions/actionCreators'; |
||||
|
import Store from '../../../store'; |
||||
|
|
||||
|
class WalletsNativeInfo extends React.Component { |
||||
|
constructor(props) { |
||||
|
super(props); |
||||
|
this.openClaimInterestModal = this.openClaimInterestModal.bind(this); |
||||
|
} |
||||
|
|
||||
|
openClaimInterestModal() { |
||||
|
Store.dispatch(toggleClaimInterestModal(true)); |
||||
|
} |
||||
|
|
||||
|
render() { |
||||
|
if (this.props && |
||||
|
this.props.Dashboard && |
||||
|
this.props.Dashboard.progress && |
||||
|
this.props.ActiveCoin.activeSection === 'settings') { |
||||
|
return WalletsNativeInfoRender.call(this); |
||||
|
} |
||||
|
|
||||
|
return null; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
export default WalletsNativeInfo; |
@ -1,21 +0,0 @@ |
|||||
import React from 'react'; |
|
||||
import WalletsNativeInfoRender from './walletsNativeInfo.render'; |
|
||||
|
|
||||
class WalletsNativeInfo extends React.Component { |
|
||||
constructor(props) { |
|
||||
super(props); |
|
||||
} |
|
||||
|
|
||||
render() { |
|
||||
if (this.props && |
|
||||
this.props.Dashboard && |
|
||||
this.props.Dashboard.progress && |
|
||||
this.props.ActiveCoin.nativeActiveSection === 'settings') { |
|
||||
return WalletsNativeInfoRender.call(this); |
|
||||
} |
|
||||
|
|
||||
return null; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
export default WalletsNativeInfo; |
|
@ -0,0 +1,57 @@ |
|||||
|
// Array.prototype.map function is in the public domain.
|
||||
|
// Production steps of ECMA-262, Edition 5, 15.4.4.19
|
||||
|
// Reference: http://es5.github.com/#x15.4.4.19
|
||||
|
if (!Array.prototype.map) { |
||||
|
Array.prototype.map = function (callback, thisArg) { |
||||
|
var T, A, k; |
||||
|
if (this == null) { |
||||
|
throw new TypeError(" this is null or not defined"); |
||||
|
} |
||||
|
// 1. Let O be the result of calling ToObject passing the |this| value as the argument.
|
||||
|
var O = Object(this); |
||||
|
// 2. Let lenValue be the result of calling the Get internal method of O with the argument "length".
|
||||
|
// 3. Let len be ToUint32(lenValue).
|
||||
|
var len = O.length >>> 0; |
||||
|
// 4. If IsCallable(callback) is false, throw a TypeError exception.
|
||||
|
// See: http://es5.github.com/#x9.11
|
||||
|
if ({}.toString.call(callback) != "[object Function]") { |
||||
|
throw new TypeError(callback + " is not a function"); |
||||
|
} |
||||
|
// 5. If thisArg was supplied, let T be thisArg; else let T be undefined.
|
||||
|
if (thisArg) { |
||||
|
T = thisArg; |
||||
|
} |
||||
|
// 6. Let A be a new array created as if by the expression new Array(len) where Array is
|
||||
|
// the standard built-in constructor with that name and len is the value of len.
|
||||
|
A = new Array(len); |
||||
|
// 7. Let k be 0
|
||||
|
k = 0; |
||||
|
// 8. Repeat, while k < len
|
||||
|
while (k < len) { |
||||
|
var kValue, mappedValue; |
||||
|
// a. Let Pk be ToString(k).
|
||||
|
// This is implicit for LHS operands of the in operator
|
||||
|
// b. Let kPresent be the result of calling the HasProperty internal method of O with argument Pk.
|
||||
|
// This step can be combined with c
|
||||
|
// c. If kPresent is true, then
|
||||
|
if (k in O) { |
||||
|
// i. Let kValue be the result of calling the Get internal method of O with argument Pk.
|
||||
|
kValue = O[k]; |
||||
|
// ii. Let mappedValue be the result of calling the Call internal method of callback
|
||||
|
// with T as the this value and argument list containing kValue, k, and O.
|
||||
|
mappedValue = callback.call(T, kValue, k, O); |
||||
|
// iii. Call the DefineOwnProperty internal method of A with arguments
|
||||
|
// Pk, Property Descriptor {Value: mappedValue, Writable: true, Enumerable: true, Configurable: true},
|
||||
|
// and false.
|
||||
|
// In browsers that support Object.defineProperty, use the following:
|
||||
|
// Object.defineProperty(A, Pk, { value: mappedValue, writable: true, enumerable: true, configurable: true });
|
||||
|
// For best browser support, use the following:
|
||||
|
A[k] = mappedValue; |
||||
|
} |
||||
|
// d. Increase k by 1.
|
||||
|
k++; |
||||
|
} |
||||
|
// 9. return A
|
||||
|
return A; |
||||
|
}; |
||||
|
} |
@ -0,0 +1,295 @@ |
|||||
|
/* |
||||
|
* Copyright (c) 2010-2011 Intalio Pte, All Rights Reserved |
||||
|
* |
||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
||||
|
* of this software and associated documentation files (the "Software"), to deal |
||||
|
* in the Software without restriction, including without limitation the rights |
||||
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
||||
|
* copies of the Software, and to permit persons to whom the Software is |
||||
|
* furnished to do so, subject to the following conditions: |
||||
|
* |
||||
|
* The above copyright notice and this permission notice shall be included in |
||||
|
* all copies or substantial portions of the Software. |
||||
|
* |
||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
||||
|
* THE SOFTWARE. |
||||
|
*/ |
||||
|
// https://github.com/cheongwy/node-scrypt-js
|
||||
|
(function () { |
||||
|
|
||||
|
var MAX_VALUE = 2147483647; |
||||
|
var workerUrl = null; |
||||
|
|
||||
|
//function scrypt(byte[] passwd, byte[] salt, int N, int r, int p, int dkLen)
|
||||
|
/* |
||||
|
* N = Cpu cost |
||||
|
* r = Memory cost |
||||
|
* p = parallelization cost |
||||
|
* |
||||
|
*/ |
||||
|
window.Crypto_scrypt = function (passwd, salt, N, r, p, dkLen, callback) { |
||||
|
if (N == 0 || (N & (N - 1)) != 0) throw Error("N must be > 0 and a power of 2"); |
||||
|
|
||||
|
if (N > MAX_VALUE / 128 / r) throw Error("Parameter N is too large"); |
||||
|
if (r > MAX_VALUE / 128 / p) throw Error("Parameter r is too large"); |
||||
|
|
||||
|
var PBKDF2_opts = { iterations: 1, hasher: Crypto.SHA256, asBytes: true }; |
||||
|
|
||||
|
var B = Crypto.PBKDF2(passwd, salt, p * 128 * r, PBKDF2_opts); |
||||
|
|
||||
|
try { |
||||
|
var i = 0; |
||||
|
var worksDone = 0; |
||||
|
var makeWorker = function () { |
||||
|
if (!workerUrl) { |
||||
|
var code = '(' + scryptCore.toString() + ')()'; |
||||
|
var blob; |
||||
|
try { |
||||
|
blob = new Blob([code], { type: "text/javascript" }); |
||||
|
} catch (e) { |
||||
|
window.BlobBuilder = window.BlobBuilder || window.WebKitBlobBuilder || window.MozBlobBuilder || window.MSBlobBuilder; |
||||
|
blob = new BlobBuilder(); |
||||
|
blob.append(code); |
||||
|
blob = blob.getBlob("text/javascript"); |
||||
|
} |
||||
|
workerUrl = URL.createObjectURL(blob); |
||||
|
} |
||||
|
var worker = new Worker(workerUrl); |
||||
|
worker.onmessage = function (event) { |
||||
|
var Bi = event.data[0], Bslice = event.data[1]; |
||||
|
worksDone++; |
||||
|
|
||||
|
if (i < p) { |
||||
|
worker.postMessage([N, r, p, B, i++]); |
||||
|
} |
||||
|
|
||||
|
var length = Bslice.length, destPos = Bi * 128 * r, srcPos = 0; |
||||
|
while (length--) { |
||||
|
B[destPos++] = Bslice[srcPos++]; |
||||
|
} |
||||
|
|
||||
|
if (worksDone == p) { |
||||
|
callback(Crypto.PBKDF2(passwd, B, dkLen, PBKDF2_opts)); |
||||
|
} |
||||
|
}; |
||||
|
return worker; |
||||
|
}; |
||||
|
var workers = [makeWorker(), makeWorker()]; |
||||
|
workers[0].postMessage([N, r, p, B, i++]); |
||||
|
if (p > 1) { |
||||
|
workers[1].postMessage([N, r, p, B, i++]); |
||||
|
} |
||||
|
} catch (e) { |
||||
|
window.setTimeout(function () { |
||||
|
scryptCore(); |
||||
|
callback(Crypto.PBKDF2(passwd, B, dkLen, PBKDF2_opts)); |
||||
|
}, 0); |
||||
|
} |
||||
|
|
||||
|
// using this function to enclose everything needed to create a worker (but also invokable directly for synchronous use)
|
||||
|
function scryptCore() { |
||||
|
var XY = [], V = []; |
||||
|
|
||||
|
if (typeof B === 'undefined') { |
||||
|
onmessage = function (event) { |
||||
|
var data = event.data; |
||||
|
var N = data[0], r = data[1], p = data[2], B = data[3], i = data[4]; |
||||
|
|
||||
|
var Bslice = []; |
||||
|
arraycopy32(B, i * 128 * r, Bslice, 0, 128 * r); |
||||
|
smix(Bslice, 0, r, N, V, XY); |
||||
|
|
||||
|
postMessage([i, Bslice]); |
||||
|
}; |
||||
|
} else { |
||||
|
for (var i = 0; i < p; i++) { |
||||
|
smix(B, i * 128 * r, r, N, V, XY); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
function smix(B, Bi, r, N, V, XY) { |
||||
|
var Xi = 0; |
||||
|
var Yi = 128 * r; |
||||
|
var i; |
||||
|
|
||||
|
arraycopy32(B, Bi, XY, Xi, Yi); |
||||
|
|
||||
|
for (i = 0; i < N; i++) { |
||||
|
arraycopy32(XY, Xi, V, i * Yi, Yi); |
||||
|
blockmix_salsa8(XY, Xi, Yi, r); |
||||
|
} |
||||
|
|
||||
|
for (i = 0; i < N; i++) { |
||||
|
var j = integerify(XY, Xi, r) & (N - 1); |
||||
|
blockxor(V, j * Yi, XY, Xi, Yi); |
||||
|
blockmix_salsa8(XY, Xi, Yi, r); |
||||
|
} |
||||
|
|
||||
|
arraycopy32(XY, Xi, B, Bi, Yi); |
||||
|
} |
||||
|
|
||||
|
function blockmix_salsa8(BY, Bi, Yi, r) { |
||||
|
var X = []; |
||||
|
var i; |
||||
|
|
||||
|
arraycopy32(BY, Bi + (2 * r - 1) * 64, X, 0, 64); |
||||
|
|
||||
|
for (i = 0; i < 2 * r; i++) { |
||||
|
blockxor(BY, i * 64, X, 0, 64); |
||||
|
salsa20_8(X); |
||||
|
arraycopy32(X, 0, BY, Yi + (i * 64), 64); |
||||
|
} |
||||
|
|
||||
|
for (i = 0; i < r; i++) { |
||||
|
arraycopy32(BY, Yi + (i * 2) * 64, BY, Bi + (i * 64), 64); |
||||
|
} |
||||
|
|
||||
|
for (i = 0; i < r; i++) { |
||||
|
arraycopy32(BY, Yi + (i * 2 + 1) * 64, BY, Bi + (i + r) * 64, 64); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
function R(a, b) { |
||||
|
return (a << b) | (a >>> (32 - b)); |
||||
|
} |
||||
|
|
||||
|
function salsa20_8(B) { |
||||
|
var B32 = new Array(32); |
||||
|
var x = new Array(32); |
||||
|
var i; |
||||
|
|
||||
|
for (i = 0; i < 16; i++) { |
||||
|
B32[i] = (B[i * 4 + 0] & 0xff) << 0; |
||||
|
B32[i] |= (B[i * 4 + 1] & 0xff) << 8; |
||||
|
B32[i] |= (B[i * 4 + 2] & 0xff) << 16; |
||||
|
B32[i] |= (B[i * 4 + 3] & 0xff) << 24; |
||||
|
} |
||||
|
|
||||
|
arraycopy(B32, 0, x, 0, 16); |
||||
|
|
||||
|
for (i = 8; i > 0; i -= 2) { |
||||
|
x[4] ^= R(x[0] + x[12], 7); x[8] ^= R(x[4] + x[0], 9); |
||||
|
x[12] ^= R(x[8] + x[4], 13); x[0] ^= R(x[12] + x[8], 18); |
||||
|
x[9] ^= R(x[5] + x[1], 7); x[13] ^= R(x[9] + x[5], 9); |
||||
|
x[1] ^= R(x[13] + x[9], 13); x[5] ^= R(x[1] + x[13], 18); |
||||
|
x[14] ^= R(x[10] + x[6], 7); x[2] ^= R(x[14] + x[10], 9); |
||||
|
x[6] ^= R(x[2] + x[14], 13); x[10] ^= R(x[6] + x[2], 18); |
||||
|
x[3] ^= R(x[15] + x[11], 7); x[7] ^= R(x[3] + x[15], 9); |
||||
|
x[11] ^= R(x[7] + x[3], 13); x[15] ^= R(x[11] + x[7], 18); |
||||
|
x[1] ^= R(x[0] + x[3], 7); x[2] ^= R(x[1] + x[0], 9); |
||||
|
x[3] ^= R(x[2] + x[1], 13); x[0] ^= R(x[3] + x[2], 18); |
||||
|
x[6] ^= R(x[5] + x[4], 7); x[7] ^= R(x[6] + x[5], 9); |
||||
|
x[4] ^= R(x[7] + x[6], 13); x[5] ^= R(x[4] + x[7], 18); |
||||
|
x[11] ^= R(x[10] + x[9], 7); x[8] ^= R(x[11] + x[10], 9); |
||||
|
x[9] ^= R(x[8] + x[11], 13); x[10] ^= R(x[9] + x[8], 18); |
||||
|
x[12] ^= R(x[15] + x[14], 7); x[13] ^= R(x[12] + x[15], 9); |
||||
|
x[14] ^= R(x[13] + x[12], 13); x[15] ^= R(x[14] + x[13], 18); |
||||
|
} |
||||
|
|
||||
|
for (i = 0; i < 16; ++i) B32[i] = x[i] + B32[i]; |
||||
|
|
||||
|
for (i = 0; i < 16; i++) { |
||||
|
var bi = i * 4; |
||||
|
B[bi + 0] = (B32[i] >> 0 & 0xff); |
||||
|
B[bi + 1] = (B32[i] >> 8 & 0xff); |
||||
|
B[bi + 2] = (B32[i] >> 16 & 0xff); |
||||
|
B[bi + 3] = (B32[i] >> 24 & 0xff); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
function blockxor(S, Si, D, Di, len) { |
||||
|
var i = len >> 6; |
||||
|
while (i--) { |
||||
|
D[Di++] ^= S[Si++]; D[Di++] ^= S[Si++]; |
||||
|
D[Di++] ^= S[Si++]; D[Di++] ^= S[Si++]; |
||||
|
D[Di++] ^= S[Si++]; D[Di++] ^= S[Si++]; |
||||
|
D[Di++] ^= S[Si++]; D[Di++] ^= S[Si++]; |
||||
|
|
||||
|
D[Di++] ^= S[Si++]; D[Di++] ^= S[Si++]; |
||||
|
D[Di++] ^= S[Si++]; D[Di++] ^= S[Si++]; |
||||
|
D[Di++] ^= S[Si++]; D[Di++] ^= S[Si++]; |
||||
|
D[Di++] ^= S[Si++]; D[Di++] ^= S[Si++]; |
||||
|
|
||||
|
D[Di++] ^= S[Si++]; D[Di++] ^= S[Si++]; |
||||
|
D[Di++] ^= S[Si++]; D[Di++] ^= S[Si++]; |
||||
|
D[Di++] ^= S[Si++]; D[Di++] ^= S[Si++]; |
||||
|
D[Di++] ^= S[Si++]; D[Di++] ^= S[Si++]; |
||||
|
|
||||
|
D[Di++] ^= S[Si++]; D[Di++] ^= S[Si++]; |
||||
|
D[Di++] ^= S[Si++]; D[Di++] ^= S[Si++]; |
||||
|
D[Di++] ^= S[Si++]; D[Di++] ^= S[Si++]; |
||||
|
D[Di++] ^= S[Si++]; D[Di++] ^= S[Si++]; |
||||
|
|
||||
|
D[Di++] ^= S[Si++]; D[Di++] ^= S[Si++]; |
||||
|
D[Di++] ^= S[Si++]; D[Di++] ^= S[Si++]; |
||||
|
D[Di++] ^= S[Si++]; D[Di++] ^= S[Si++]; |
||||
|
D[Di++] ^= S[Si++]; D[Di++] ^= S[Si++]; |
||||
|
|
||||
|
D[Di++] ^= S[Si++]; D[Di++] ^= S[Si++]; |
||||
|
D[Di++] ^= S[Si++]; D[Di++] ^= S[Si++]; |
||||
|
D[Di++] ^= S[Si++]; D[Di++] ^= S[Si++]; |
||||
|
D[Di++] ^= S[Si++]; D[Di++] ^= S[Si++]; |
||||
|
|
||||
|
D[Di++] ^= S[Si++]; D[Di++] ^= S[Si++]; |
||||
|
D[Di++] ^= S[Si++]; D[Di++] ^= S[Si++]; |
||||
|
D[Di++] ^= S[Si++]; D[Di++] ^= S[Si++]; |
||||
|
D[Di++] ^= S[Si++]; D[Di++] ^= S[Si++]; |
||||
|
|
||||
|
D[Di++] ^= S[Si++]; D[Di++] ^= S[Si++]; |
||||
|
D[Di++] ^= S[Si++]; D[Di++] ^= S[Si++]; |
||||
|
D[Di++] ^= S[Si++]; D[Di++] ^= S[Si++]; |
||||
|
D[Di++] ^= S[Si++]; D[Di++] ^= S[Si++]; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
function integerify(B, bi, r) { |
||||
|
var n; |
||||
|
|
||||
|
bi += (2 * r - 1) * 64; |
||||
|
|
||||
|
n = (B[bi + 0] & 0xff) << 0; |
||||
|
n |= (B[bi + 1] & 0xff) << 8; |
||||
|
n |= (B[bi + 2] & 0xff) << 16; |
||||
|
n |= (B[bi + 3] & 0xff) << 24; |
||||
|
|
||||
|
return n; |
||||
|
} |
||||
|
|
||||
|
function arraycopy(src, srcPos, dest, destPos, length) { |
||||
|
while (length--) { |
||||
|
dest[destPos++] = src[srcPos++]; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
function arraycopy32(src, srcPos, dest, destPos, length) { |
||||
|
var i = length >> 5; |
||||
|
while (i--) { |
||||
|
dest[destPos++] = src[srcPos++]; dest[destPos++] = src[srcPos++]; |
||||
|
dest[destPos++] = src[srcPos++]; dest[destPos++] = src[srcPos++]; |
||||
|
dest[destPos++] = src[srcPos++]; dest[destPos++] = src[srcPos++]; |
||||
|
dest[destPos++] = src[srcPos++]; dest[destPos++] = src[srcPos++]; |
||||
|
|
||||
|
dest[destPos++] = src[srcPos++]; dest[destPos++] = src[srcPos++]; |
||||
|
dest[destPos++] = src[srcPos++]; dest[destPos++] = src[srcPos++]; |
||||
|
dest[destPos++] = src[srcPos++]; dest[destPos++] = src[srcPos++]; |
||||
|
dest[destPos++] = src[srcPos++]; dest[destPos++] = src[srcPos++]; |
||||
|
|
||||
|
dest[destPos++] = src[srcPos++]; dest[destPos++] = src[srcPos++]; |
||||
|
dest[destPos++] = src[srcPos++]; dest[destPos++] = src[srcPos++]; |
||||
|
dest[destPos++] = src[srcPos++]; dest[destPos++] = src[srcPos++]; |
||||
|
dest[destPos++] = src[srcPos++]; dest[destPos++] = src[srcPos++]; |
||||
|
|
||||
|
dest[destPos++] = src[srcPos++]; dest[destPos++] = src[srcPos++]; |
||||
|
dest[destPos++] = src[srcPos++]; dest[destPos++] = src[srcPos++]; |
||||
|
dest[destPos++] = src[srcPos++]; dest[destPos++] = src[srcPos++]; |
||||
|
dest[destPos++] = src[srcPos++]; dest[destPos++] = src[srcPos++]; |
||||
|
} |
||||
|
} |
||||
|
} // scryptCore
|
||||
|
}; // window.Crypto_scrypt
|
||||
|
})(); |
@ -0,0 +1,407 @@ |
|||||
|
/*! |
||||
|
* Crypto-JS v2.5.4 AES.js |
||||
|
* http://code.google.com/p/crypto-js/
|
||||
|
* Copyright (c) 2009-2013, Jeff Mott. All rights reserved. |
||||
|
* http://code.google.com/p/crypto-js/wiki/License
|
||||
|
*/ |
||||
|
(function () { |
||||
|
|
||||
|
// Shortcuts
|
||||
|
var C = Crypto, |
||||
|
util = C.util, |
||||
|
charenc = C.charenc, |
||||
|
UTF8 = charenc.UTF8; |
||||
|
|
||||
|
// Precomputed SBOX
|
||||
|
var SBOX = [0x63, 0x7c, 0x77, 0x7b, 0xf2, 0x6b, 0x6f, 0xc5, |
||||
|
0x30, 0x01, 0x67, 0x2b, 0xfe, 0xd7, 0xab, 0x76, |
||||
|
0xca, 0x82, 0xc9, 0x7d, 0xfa, 0x59, 0x47, 0xf0, |
||||
|
0xad, 0xd4, 0xa2, 0xaf, 0x9c, 0xa4, 0x72, 0xc0, |
||||
|
0xb7, 0xfd, 0x93, 0x26, 0x36, 0x3f, 0xf7, 0xcc, |
||||
|
0x34, 0xa5, 0xe5, 0xf1, 0x71, 0xd8, 0x31, 0x15, |
||||
|
0x04, 0xc7, 0x23, 0xc3, 0x18, 0x96, 0x05, 0x9a, |
||||
|
0x07, 0x12, 0x80, 0xe2, 0xeb, 0x27, 0xb2, 0x75, |
||||
|
0x09, 0x83, 0x2c, 0x1a, 0x1b, 0x6e, 0x5a, 0xa0, |
||||
|
0x52, 0x3b, 0xd6, 0xb3, 0x29, 0xe3, 0x2f, 0x84, |
||||
|
0x53, 0xd1, 0x00, 0xed, 0x20, 0xfc, 0xb1, 0x5b, |
||||
|
0x6a, 0xcb, 0xbe, 0x39, 0x4a, 0x4c, 0x58, 0xcf, |
||||
|
0xd0, 0xef, 0xaa, 0xfb, 0x43, 0x4d, 0x33, 0x85, |
||||
|
0x45, 0xf9, 0x02, 0x7f, 0x50, 0x3c, 0x9f, 0xa8, |
||||
|
0x51, 0xa3, 0x40, 0x8f, 0x92, 0x9d, 0x38, 0xf5, |
||||
|
0xbc, 0xb6, 0xda, 0x21, 0x10, 0xff, 0xf3, 0xd2, |
||||
|
0xcd, 0x0c, 0x13, 0xec, 0x5f, 0x97, 0x44, 0x17, |
||||
|
0xc4, 0xa7, 0x7e, 0x3d, 0x64, 0x5d, 0x19, 0x73, |
||||
|
0x60, 0x81, 0x4f, 0xdc, 0x22, 0x2a, 0x90, 0x88, |
||||
|
0x46, 0xee, 0xb8, 0x14, 0xde, 0x5e, 0x0b, 0xdb, |
||||
|
0xe0, 0x32, 0x3a, 0x0a, 0x49, 0x06, 0x24, 0x5c, |
||||
|
0xc2, 0xd3, 0xac, 0x62, 0x91, 0x95, 0xe4, 0x79, |
||||
|
0xe7, 0xc8, 0x37, 0x6d, 0x8d, 0xd5, 0x4e, 0xa9, |
||||
|
0x6c, 0x56, 0xf4, 0xea, 0x65, 0x7a, 0xae, 0x08, |
||||
|
0xba, 0x78, 0x25, 0x2e, 0x1c, 0xa6, 0xb4, 0xc6, |
||||
|
0xe8, 0xdd, 0x74, 0x1f, 0x4b, 0xbd, 0x8b, 0x8a, |
||||
|
0x70, 0x3e, 0xb5, 0x66, 0x48, 0x03, 0xf6, 0x0e, |
||||
|
0x61, 0x35, 0x57, 0xb9, 0x86, 0xc1, 0x1d, 0x9e, |
||||
|
0xe1, 0xf8, 0x98, 0x11, 0x69, 0xd9, 0x8e, 0x94, |
||||
|
0x9b, 0x1e, 0x87, 0xe9, 0xce, 0x55, 0x28, 0xdf, |
||||
|
0x8c, 0xa1, 0x89, 0x0d, 0xbf, 0xe6, 0x42, 0x68, |
||||
|
0x41, 0x99, 0x2d, 0x0f, 0xb0, 0x54, 0xbb, 0x16]; |
||||
|
|
||||
|
// Compute inverse SBOX lookup table
|
||||
|
for (var INVSBOX = [], i = 0; i < 256; i++) INVSBOX[SBOX[i]] = i; |
||||
|
|
||||
|
// Compute multiplication in GF(2^8) lookup tables
|
||||
|
var MULT2 = [], |
||||
|
MULT3 = [], |
||||
|
MULT9 = [], |
||||
|
MULTB = [], |
||||
|
MULTD = [], |
||||
|
MULTE = []; |
||||
|
|
||||
|
function xtime(a, b) { |
||||
|
for (var result = 0, i = 0; i < 8; i++) { |
||||
|
if (b & 1) result ^= a; |
||||
|
var hiBitSet = a & 0x80; |
||||
|
a = (a << 1) & 0xFF; |
||||
|
if (hiBitSet) a ^= 0x1b; |
||||
|
b >>>= 1; |
||||
|
} |
||||
|
return result; |
||||
|
} |
||||
|
|
||||
|
for (var i = 0; i < 256; i++) { |
||||
|
MULT2[i] = xtime(i, 2); |
||||
|
MULT3[i] = xtime(i, 3); |
||||
|
MULT9[i] = xtime(i, 9); |
||||
|
MULTB[i] = xtime(i, 0xB); |
||||
|
MULTD[i] = xtime(i, 0xD); |
||||
|
MULTE[i] = xtime(i, 0xE); |
||||
|
} |
||||
|
|
||||
|
// Precomputed RCon lookup
|
||||
|
var RCON = [0x00, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x1b, 0x36]; |
||||
|
|
||||
|
// Inner state
|
||||
|
var state = [[], [], [], []], |
||||
|
keylength, |
||||
|
nrounds, |
||||
|
keyschedule; |
||||
|
|
||||
|
var AES = C.AES = { |
||||
|
|
||||
|
/** |
||||
|
* Public API |
||||
|
*/ |
||||
|
|
||||
|
encrypt: function (message, password, options) { |
||||
|
|
||||
|
options = options || {}; |
||||
|
|
||||
|
// Determine mode
|
||||
|
var mode = options.mode || new C.mode.OFB; |
||||
|
|
||||
|
// Allow mode to override options
|
||||
|
if (mode.fixOptions) mode.fixOptions(options); |
||||
|
|
||||
|
var |
||||
|
|
||||
|
// Convert to bytes if message is a string
|
||||
|
m = ( |
||||
|
message.constructor == String ? |
||||
|
UTF8.stringToBytes(message) : |
||||
|
message |
||||
|
), |
||||
|
|
||||
|
// Generate random IV
|
||||
|
iv = options.iv || util.randomBytes(AES._blocksize * 4), |
||||
|
|
||||
|
// Generate key
|
||||
|
k = ( |
||||
|
password.constructor == String ? |
||||
|
// Derive key from pass-phrase
|
||||
|
C.PBKDF2(password, iv, 32, { asBytes: true }) : |
||||
|
// else, assume byte array representing cryptographic key
|
||||
|
password |
||||
|
); |
||||
|
|
||||
|
// Encrypt
|
||||
|
AES._init(k); |
||||
|
mode.encrypt(AES, m, iv); |
||||
|
|
||||
|
// Return ciphertext
|
||||
|
m = options.iv ? m : iv.concat(m); |
||||
|
return (options && options.asBytes) ? m : util.bytesToBase64(m); |
||||
|
|
||||
|
}, |
||||
|
|
||||
|
decrypt: function (ciphertext, password, options) { |
||||
|
|
||||
|
options = options || {}; |
||||
|
|
||||
|
// Determine mode
|
||||
|
var mode = options.mode || new C.mode.OFB; |
||||
|
|
||||
|
// Allow mode to override options
|
||||
|
if (mode.fixOptions) mode.fixOptions(options); |
||||
|
|
||||
|
var |
||||
|
|
||||
|
// Convert to bytes if ciphertext is a string
|
||||
|
c = ( |
||||
|
ciphertext.constructor == String ? |
||||
|
util.base64ToBytes(ciphertext) : |
||||
|
ciphertext |
||||
|
), |
||||
|
|
||||
|
// Separate IV and message
|
||||
|
iv = options.iv || c.splice(0, AES._blocksize * 4), |
||||
|
|
||||
|
// Generate key
|
||||
|
k = ( |
||||
|
password.constructor == String ? |
||||
|
// Derive key from pass-phrase
|
||||
|
C.PBKDF2(password, iv, 32, { asBytes: true }) : |
||||
|
// else, assume byte array representing cryptographic key
|
||||
|
password |
||||
|
); |
||||
|
|
||||
|
// Decrypt
|
||||
|
AES._init(k); |
||||
|
mode.decrypt(AES, c, iv); |
||||
|
|
||||
|
// Return plaintext
|
||||
|
return (options && options.asBytes) ? c : UTF8.bytesToString(c); |
||||
|
|
||||
|
}, |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Package private methods and properties |
||||
|
*/ |
||||
|
|
||||
|
_blocksize: 4, |
||||
|
|
||||
|
_encryptblock: function (m, offset) { |
||||
|
|
||||
|
// Set input
|
||||
|
for (var row = 0; row < AES._blocksize; row++) { |
||||
|
for (var col = 0; col < 4; col++) |
||||
|
state[row][col] = m[offset + col * 4 + row]; |
||||
|
} |
||||
|
|
||||
|
// Add round key
|
||||
|
for (var row = 0; row < 4; row++) { |
||||
|
for (var col = 0; col < 4; col++) |
||||
|
state[row][col] ^= keyschedule[col][row]; |
||||
|
} |
||||
|
|
||||
|
for (var round = 1; round < nrounds; round++) { |
||||
|
|
||||
|
// Sub bytes
|
||||
|
for (var row = 0; row < 4; row++) { |
||||
|
for (var col = 0; col < 4; col++) |
||||
|
state[row][col] = SBOX[state[row][col]]; |
||||
|
} |
||||
|
|
||||
|
// Shift rows
|
||||
|
state[1].push(state[1].shift()); |
||||
|
state[2].push(state[2].shift()); |
||||
|
state[2].push(state[2].shift()); |
||||
|
state[3].unshift(state[3].pop()); |
||||
|
|
||||
|
// Mix columns
|
||||
|
for (var col = 0; col < 4; col++) { |
||||
|
|
||||
|
var s0 = state[0][col], |
||||
|
s1 = state[1][col], |
||||
|
s2 = state[2][col], |
||||
|
s3 = state[3][col]; |
||||
|
|
||||
|
state[0][col] = MULT2[s0] ^ MULT3[s1] ^ s2 ^ s3; |
||||
|
state[1][col] = s0 ^ MULT2[s1] ^ MULT3[s2] ^ s3; |
||||
|
state[2][col] = s0 ^ s1 ^ MULT2[s2] ^ MULT3[s3]; |
||||
|
state[3][col] = MULT3[s0] ^ s1 ^ s2 ^ MULT2[s3]; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
// Add round key
|
||||
|
for (var row = 0; row < 4; row++) { |
||||
|
for (var col = 0; col < 4; col++) |
||||
|
state[row][col] ^= keyschedule[round * 4 + col][row]; |
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
// Sub bytes
|
||||
|
for (var row = 0; row < 4; row++) { |
||||
|
for (var col = 0; col < 4; col++) |
||||
|
state[row][col] = SBOX[state[row][col]]; |
||||
|
} |
||||
|
|
||||
|
// Shift rows
|
||||
|
state[1].push(state[1].shift()); |
||||
|
state[2].push(state[2].shift()); |
||||
|
state[2].push(state[2].shift()); |
||||
|
state[3].unshift(state[3].pop()); |
||||
|
|
||||
|
// Add round key
|
||||
|
for (var row = 0; row < 4; row++) { |
||||
|
for (var col = 0; col < 4; col++) |
||||
|
state[row][col] ^= keyschedule[nrounds * 4 + col][row]; |
||||
|
} |
||||
|
|
||||
|
// Set output
|
||||
|
for (var row = 0; row < AES._blocksize; row++) { |
||||
|
for (var col = 0; col < 4; col++) |
||||
|
m[offset + col * 4 + row] = state[row][col]; |
||||
|
} |
||||
|
|
||||
|
}, |
||||
|
|
||||
|
_decryptblock: function (c, offset) { |
||||
|
|
||||
|
// Set input
|
||||
|
for (var row = 0; row < AES._blocksize; row++) { |
||||
|
for (var col = 0; col < 4; col++) |
||||
|
state[row][col] = c[offset + col * 4 + row]; |
||||
|
} |
||||
|
|
||||
|
// Add round key
|
||||
|
for (var row = 0; row < 4; row++) { |
||||
|
for (var col = 0; col < 4; col++) |
||||
|
state[row][col] ^= keyschedule[nrounds * 4 + col][row]; |
||||
|
} |
||||
|
|
||||
|
for (var round = 1; round < nrounds; round++) { |
||||
|
|
||||
|
// Inv shift rows
|
||||
|
state[1].unshift(state[1].pop()); |
||||
|
state[2].push(state[2].shift()); |
||||
|
state[2].push(state[2].shift()); |
||||
|
state[3].push(state[3].shift()); |
||||
|
|
||||
|
// Inv sub bytes
|
||||
|
for (var row = 0; row < 4; row++) { |
||||
|
for (var col = 0; col < 4; col++) |
||||
|
state[row][col] = INVSBOX[state[row][col]]; |
||||
|
} |
||||
|
|
||||
|
// Add round key
|
||||
|
for (var row = 0; row < 4; row++) { |
||||
|
for (var col = 0; col < 4; col++) |
||||
|
state[row][col] ^= keyschedule[(nrounds - round) * 4 + col][row]; |
||||
|
} |
||||
|
|
||||
|
// Inv mix columns
|
||||
|
for (var col = 0; col < 4; col++) { |
||||
|
|
||||
|
var s0 = state[0][col], |
||||
|
s1 = state[1][col], |
||||
|
s2 = state[2][col], |
||||
|
s3 = state[3][col]; |
||||
|
|
||||
|
state[0][col] = MULTE[s0] ^ MULTB[s1] ^ MULTD[s2] ^ MULT9[s3]; |
||||
|
state[1][col] = MULT9[s0] ^ MULTE[s1] ^ MULTB[s2] ^ MULTD[s3]; |
||||
|
state[2][col] = MULTD[s0] ^ MULT9[s1] ^ MULTE[s2] ^ MULTB[s3]; |
||||
|
state[3][col] = MULTB[s0] ^ MULTD[s1] ^ MULT9[s2] ^ MULTE[s3]; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
// Inv shift rows
|
||||
|
state[1].unshift(state[1].pop()); |
||||
|
state[2].push(state[2].shift()); |
||||
|
state[2].push(state[2].shift()); |
||||
|
state[3].push(state[3].shift()); |
||||
|
|
||||
|
// Inv sub bytes
|
||||
|
for (var row = 0; row < 4; row++) { |
||||
|
for (var col = 0; col < 4; col++) |
||||
|
state[row][col] = INVSBOX[state[row][col]]; |
||||
|
} |
||||
|
|
||||
|
// Add round key
|
||||
|
for (var row = 0; row < 4; row++) { |
||||
|
for (var col = 0; col < 4; col++) |
||||
|
state[row][col] ^= keyschedule[col][row]; |
||||
|
} |
||||
|
|
||||
|
// Set output
|
||||
|
for (var row = 0; row < AES._blocksize; row++) { |
||||
|
for (var col = 0; col < 4; col++) |
||||
|
c[offset + col * 4 + row] = state[row][col]; |
||||
|
} |
||||
|
|
||||
|
}, |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Private methods |
||||
|
*/ |
||||
|
|
||||
|
_init: function (k) { |
||||
|
keylength = k.length / 4; |
||||
|
nrounds = keylength + 6; |
||||
|
AES._keyexpansion(k); |
||||
|
}, |
||||
|
|
||||
|
// Generate a key schedule
|
||||
|
_keyexpansion: function (k) { |
||||
|
|
||||
|
keyschedule = []; |
||||
|
|
||||
|
for (var row = 0; row < keylength; row++) { |
||||
|
keyschedule[row] = [ |
||||
|
k[row * 4], |
||||
|
k[row * 4 + 1], |
||||
|
k[row * 4 + 2], |
||||
|
k[row * 4 + 3] |
||||
|
]; |
||||
|
} |
||||
|
|
||||
|
for (var row = keylength; row < AES._blocksize * (nrounds + 1); row++) { |
||||
|
|
||||
|
var temp = [ |
||||
|
keyschedule[row - 1][0], |
||||
|
keyschedule[row - 1][1], |
||||
|
keyschedule[row - 1][2], |
||||
|
keyschedule[row - 1][3] |
||||
|
]; |
||||
|
|
||||
|
if (row % keylength == 0) { |
||||
|
|
||||
|
// Rot word
|
||||
|
temp.push(temp.shift()); |
||||
|
|
||||
|
// Sub word
|
||||
|
temp[0] = SBOX[temp[0]]; |
||||
|
temp[1] = SBOX[temp[1]]; |
||||
|
temp[2] = SBOX[temp[2]]; |
||||
|
temp[3] = SBOX[temp[3]]; |
||||
|
|
||||
|
temp[0] ^= RCON[row / keylength]; |
||||
|
|
||||
|
} else if (keylength > 6 && row % keylength == 4) { |
||||
|
|
||||
|
// Sub word
|
||||
|
temp[0] = SBOX[temp[0]]; |
||||
|
temp[1] = SBOX[temp[1]]; |
||||
|
temp[2] = SBOX[temp[2]]; |
||||
|
temp[3] = SBOX[temp[3]]; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
keyschedule[row] = [ |
||||
|
keyschedule[row - keylength][0] ^ temp[0], |
||||
|
keyschedule[row - keylength][1] ^ temp[1], |
||||
|
keyschedule[row - keylength][2] ^ temp[2], |
||||
|
keyschedule[row - keylength][3] ^ temp[3] |
||||
|
]; |
||||
|
|
||||
|
} |
||||
|
|
||||
|
} |
||||
|
|
||||
|
}; |
||||
|
|
||||
|
})(); |
@ -0,0 +1,410 @@ |
|||||
|
/*! |
||||
|
* Crypto-JS 2.5.4 BlockModes.js |
||||
|
* contribution from Simon Greatrix |
||||
|
*/ |
||||
|
|
||||
|
(function (C) { |
||||
|
|
||||
|
// Create pad namespace
|
||||
|
var C_pad = C.pad = {}; |
||||
|
|
||||
|
// Calculate the number of padding bytes required.
|
||||
|
function _requiredPadding(cipher, message) { |
||||
|
var blockSizeInBytes = cipher._blocksize * 4; |
||||
|
var reqd = blockSizeInBytes - message.length % blockSizeInBytes; |
||||
|
return reqd; |
||||
|
} |
||||
|
|
||||
|
// Remove padding when the final byte gives the number of padding bytes.
|
||||
|
var _unpadLength = function (cipher, message, alg, padding) { |
||||
|
var pad = message.pop(); |
||||
|
if (pad == 0) { |
||||
|
throw new Error("Invalid zero-length padding specified for " + alg |
||||
|
+ ". Wrong cipher specification or key used?"); |
||||
|
} |
||||
|
var maxPad = cipher._blocksize * 4; |
||||
|
if (pad > maxPad) { |
||||
|
throw new Error("Invalid padding length of " + pad |
||||
|
+ " specified for " + alg |
||||
|
+ ". Wrong cipher specification or key used?"); |
||||
|
} |
||||
|
for (var i = 1; i < pad; i++) { |
||||
|
var b = message.pop(); |
||||
|
if (padding != undefined && padding != b) { |
||||
|
throw new Error("Invalid padding byte of 0x" + b.toString(16) |
||||
|
+ " specified for " + alg |
||||
|
+ ". Wrong cipher specification or key used?"); |
||||
|
} |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
// No-operation padding, used for stream ciphers
|
||||
|
C_pad.NoPadding = { |
||||
|
pad: function (cipher, message) { }, |
||||
|
unpad: function (cipher, message) { } |
||||
|
}; |
||||
|
|
||||
|
// Zero Padding.
|
||||
|
//
|
||||
|
// If the message is not an exact number of blocks, the final block is
|
||||
|
// completed with 0x00 bytes. There is no unpadding.
|
||||
|
C_pad.ZeroPadding = { |
||||
|
pad: function (cipher, message) { |
||||
|
var blockSizeInBytes = cipher._blocksize * 4; |
||||
|
var reqd = message.length % blockSizeInBytes; |
||||
|
if (reqd != 0) { |
||||
|
for (reqd = blockSizeInBytes - reqd; reqd > 0; reqd--) { |
||||
|
message.push(0x00); |
||||
|
} |
||||
|
} |
||||
|
}, |
||||
|
|
||||
|
unpad: function (cipher, message) { |
||||
|
while (message[message.length - 1] == 0) { |
||||
|
message.pop(); |
||||
|
} |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
// ISO/IEC 7816-4 padding.
|
||||
|
//
|
||||
|
// Pads the plain text with an 0x80 byte followed by as many 0x00
|
||||
|
// bytes are required to complete the block.
|
||||
|
C_pad.iso7816 = { |
||||
|
pad: function (cipher, message) { |
||||
|
var reqd = _requiredPadding(cipher, message); |
||||
|
message.push(0x80); |
||||
|
for (; reqd > 1; reqd--) { |
||||
|
message.push(0x00); |
||||
|
} |
||||
|
}, |
||||
|
|
||||
|
unpad: function (cipher, message) { |
||||
|
var padLength; |
||||
|
for (padLength = cipher._blocksize * 4; padLength > 0; padLength--) { |
||||
|
var b = message.pop(); |
||||
|
if (b == 0x80) return; |
||||
|
if (b != 0x00) { |
||||
|
throw new Error("ISO-7816 padding byte must be 0, not 0x" + b.toString(16) + ". Wrong cipher specification or key used?"); |
||||
|
} |
||||
|
} |
||||
|
throw new Error("ISO-7816 padded beyond cipher block size. Wrong cipher specification or key used?"); |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
// ANSI X.923 padding
|
||||
|
//
|
||||
|
// The final block is padded with zeros except for the last byte of the
|
||||
|
// last block which contains the number of padding bytes.
|
||||
|
C_pad.ansix923 = { |
||||
|
pad: function (cipher, message) { |
||||
|
var reqd = _requiredPadding(cipher, message); |
||||
|
for (var i = 1; i < reqd; i++) { |
||||
|
message.push(0x00); |
||||
|
} |
||||
|
message.push(reqd); |
||||
|
}, |
||||
|
|
||||
|
unpad: function (cipher, message) { |
||||
|
_unpadLength(cipher, message, "ANSI X.923", 0); |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
// ISO 10126
|
||||
|
//
|
||||
|
// The final block is padded with random bytes except for the last
|
||||
|
// byte of the last block which contains the number of padding bytes.
|
||||
|
C_pad.iso10126 = { |
||||
|
pad: function (cipher, message) { |
||||
|
var reqd = _requiredPadding(cipher, message); |
||||
|
for (var i = 1; i < reqd; i++) { |
||||
|
message.push(Math.floor(Math.random() * 256)); |
||||
|
} |
||||
|
message.push(reqd); |
||||
|
}, |
||||
|
|
||||
|
unpad: function (cipher, message) { |
||||
|
_unpadLength(cipher, message, "ISO 10126", undefined); |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
// PKCS7 padding
|
||||
|
//
|
||||
|
// PKCS7 is described in RFC 5652. Padding is in whole bytes. The
|
||||
|
// value of each added byte is the number of bytes that are added,
|
||||
|
// i.e. N bytes, each of value N are added.
|
||||
|
C_pad.pkcs7 = { |
||||
|
pad: function (cipher, message) { |
||||
|
var reqd = _requiredPadding(cipher, message); |
||||
|
for (var i = 0; i < reqd; i++) { |
||||
|
message.push(reqd); |
||||
|
} |
||||
|
}, |
||||
|
|
||||
|
unpad: function (cipher, message) { |
||||
|
_unpadLength(cipher, message, "PKCS 7", message[message.length - 1]); |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
// Create mode namespace
|
||||
|
var C_mode = C.mode = {}; |
||||
|
|
||||
|
/** |
||||
|
* Mode base "class". |
||||
|
*/ |
||||
|
var Mode = C_mode.Mode = function (padding) { |
||||
|
if (padding) { |
||||
|
this._padding = padding; |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
Mode.prototype = { |
||||
|
encrypt: function (cipher, m, iv) { |
||||
|
this._padding.pad(cipher, m); |
||||
|
this._doEncrypt(cipher, m, iv); |
||||
|
}, |
||||
|
|
||||
|
decrypt: function (cipher, m, iv) { |
||||
|
this._doDecrypt(cipher, m, iv); |
||||
|
this._padding.unpad(cipher, m); |
||||
|
}, |
||||
|
|
||||
|
// Default padding
|
||||
|
_padding: C_pad.iso7816 |
||||
|
}; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Electronic Code Book mode. |
||||
|
* |
||||
|
* ECB applies the cipher directly against each block of the input. |
||||
|
* |
||||
|
* ECB does not require an initialization vector. |
||||
|
*/ |
||||
|
var ECB = C_mode.ECB = function () { |
||||
|
// Call parent constructor
|
||||
|
Mode.apply(this, arguments); |
||||
|
}; |
||||
|
|
||||
|
// Inherit from Mode
|
||||
|
var ECB_prototype = ECB.prototype = new Mode; |
||||
|
|
||||
|
// Concrete steps for Mode template
|
||||
|
ECB_prototype._doEncrypt = function (cipher, m, iv) { |
||||
|
var blockSizeInBytes = cipher._blocksize * 4; |
||||
|
// Encrypt each block
|
||||
|
for (var offset = 0; offset < m.length; offset += blockSizeInBytes) { |
||||
|
cipher._encryptblock(m, offset); |
||||
|
} |
||||
|
}; |
||||
|
ECB_prototype._doDecrypt = function (cipher, c, iv) { |
||||
|
var blockSizeInBytes = cipher._blocksize * 4; |
||||
|
// Decrypt each block
|
||||
|
for (var offset = 0; offset < c.length; offset += blockSizeInBytes) { |
||||
|
cipher._decryptblock(c, offset); |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
// ECB never uses an IV
|
||||
|
ECB_prototype.fixOptions = function (options) { |
||||
|
options.iv = []; |
||||
|
}; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Cipher block chaining |
||||
|
* |
||||
|
* The first block is XORed with the IV. Subsequent blocks are XOR with the |
||||
|
* previous cipher output. |
||||
|
*/ |
||||
|
var CBC = C_mode.CBC = function () { |
||||
|
// Call parent constructor
|
||||
|
Mode.apply(this, arguments); |
||||
|
}; |
||||
|
|
||||
|
// Inherit from Mode
|
||||
|
var CBC_prototype = CBC.prototype = new Mode; |
||||
|
|
||||
|
// Concrete steps for Mode template
|
||||
|
CBC_prototype._doEncrypt = function (cipher, m, iv) { |
||||
|
var blockSizeInBytes = cipher._blocksize * 4; |
||||
|
|
||||
|
// Encrypt each block
|
||||
|
for (var offset = 0; offset < m.length; offset += blockSizeInBytes) { |
||||
|
if (offset == 0) { |
||||
|
// XOR first block using IV
|
||||
|
for (var i = 0; i < blockSizeInBytes; i++) |
||||
|
m[i] ^= iv[i]; |
||||
|
} else { |
||||
|
// XOR this block using previous crypted block
|
||||
|
for (var i = 0; i < blockSizeInBytes; i++) |
||||
|
m[offset + i] ^= m[offset + i - blockSizeInBytes]; |
||||
|
} |
||||
|
// Encrypt block
|
||||
|
cipher._encryptblock(m, offset); |
||||
|
} |
||||
|
}; |
||||
|
CBC_prototype._doDecrypt = function (cipher, c, iv) { |
||||
|
var blockSizeInBytes = cipher._blocksize * 4; |
||||
|
|
||||
|
// At the start, the previously crypted block is the IV
|
||||
|
var prevCryptedBlock = iv; |
||||
|
|
||||
|
// Decrypt each block
|
||||
|
for (var offset = 0; offset < c.length; offset += blockSizeInBytes) { |
||||
|
// Save this crypted block
|
||||
|
var thisCryptedBlock = c.slice(offset, offset + blockSizeInBytes); |
||||
|
// Decrypt block
|
||||
|
cipher._decryptblock(c, offset); |
||||
|
// XOR decrypted block using previous crypted block
|
||||
|
for (var i = 0; i < blockSizeInBytes; i++) { |
||||
|
c[offset + i] ^= prevCryptedBlock[i]; |
||||
|
} |
||||
|
prevCryptedBlock = thisCryptedBlock; |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Cipher feed back |
||||
|
* |
||||
|
* The cipher output is XORed with the plain text to produce the cipher output, |
||||
|
* which is then fed back into the cipher to produce a bit pattern to XOR the |
||||
|
* next block with. |
||||
|
* |
||||
|
* This is a stream cipher mode and does not require padding. |
||||
|
*/ |
||||
|
var CFB = C_mode.CFB = function () { |
||||
|
// Call parent constructor
|
||||
|
Mode.apply(this, arguments); |
||||
|
}; |
||||
|
|
||||
|
// Inherit from Mode
|
||||
|
var CFB_prototype = CFB.prototype = new Mode; |
||||
|
|
||||
|
// Override padding
|
||||
|
CFB_prototype._padding = C_pad.NoPadding; |
||||
|
|
||||
|
// Concrete steps for Mode template
|
||||
|
CFB_prototype._doEncrypt = function (cipher, m, iv) { |
||||
|
var blockSizeInBytes = cipher._blocksize * 4, |
||||
|
keystream = iv.slice(0); |
||||
|
|
||||
|
// Encrypt each byte
|
||||
|
for (var i = 0; i < m.length; i++) { |
||||
|
|
||||
|
var j = i % blockSizeInBytes; |
||||
|
if (j == 0) cipher._encryptblock(keystream, 0); |
||||
|
|
||||
|
m[i] ^= keystream[j]; |
||||
|
keystream[j] = m[i]; |
||||
|
} |
||||
|
}; |
||||
|
CFB_prototype._doDecrypt = function (cipher, c, iv) { |
||||
|
var blockSizeInBytes = cipher._blocksize * 4, |
||||
|
keystream = iv.slice(0); |
||||
|
|
||||
|
// Encrypt each byte
|
||||
|
for (var i = 0; i < c.length; i++) { |
||||
|
|
||||
|
var j = i % blockSizeInBytes; |
||||
|
if (j == 0) cipher._encryptblock(keystream, 0); |
||||
|
|
||||
|
var b = c[i]; |
||||
|
c[i] ^= keystream[j]; |
||||
|
keystream[j] = b; |
||||
|
} |
||||
|
}; |
||||
|
|
||||
|
|
||||
|
/** |
||||
|
* Output feed back |
||||
|
* |
||||
|
* The cipher repeatedly encrypts its own output. The output is XORed with the |
||||
|
* plain text to produce the cipher text. |
||||
|
* |
||||
|
* This is a stream cipher mode and does not require padding. |
||||
|
*/ |
||||
|
var OFB = C_mode.OFB = function () { |
||||
|
// Call parent constructor
|
||||
|
Mode.apply(this, arguments); |
||||
|
}; |
||||
|
|
||||
|
// Inherit from Mode
|
||||
|
var OFB_prototype = OFB.prototype = new Mode; |
||||
|
|
||||
|
// Override padding
|
||||
|
OFB_prototype._padding = C_pad.NoPadding; |
||||
|
|
||||
|
// Concrete steps for Mode template
|
||||
|
OFB_prototype._doEncrypt = function (cipher, m, iv) { |
||||
|
|
||||
|
var blockSizeInBytes = cipher._blocksize * 4, |
||||
|
keystream = iv.slice(0); |
||||
|
|
||||
|
// Encrypt each byte
|
||||
|
for (var i = 0; i < m.length; i++) { |
||||
|
|
||||
|
// Generate keystream
|
||||
|
if (i % blockSizeInBytes == 0) |
||||
|
cipher._encryptblock(keystream, 0); |
||||
|
|
||||
|
// Encrypt byte
|
||||
|
m[i] ^= keystream[i % blockSizeInBytes]; |
||||
|
|
||||
|
} |
||||
|
}; |
||||
|
OFB_prototype._doDecrypt = OFB_prototype._doEncrypt; |
||||
|
|
||||
|
/** |
||||
|
* Counter |
||||
|
* @author Gergely Risko |
||||
|
* |
||||
|
* After every block the last 4 bytes of the IV is increased by one |
||||
|
* with carry and that IV is used for the next block. |
||||
|
* |
||||
|
* This is a stream cipher mode and does not require padding. |
||||
|
*/ |
||||
|
var CTR = C_mode.CTR = function () { |
||||
|
// Call parent constructor
|
||||
|
Mode.apply(this, arguments); |
||||
|
}; |
||||
|
|
||||
|
// Inherit from Mode
|
||||
|
var CTR_prototype = CTR.prototype = new Mode; |
||||
|
|
||||
|
// Override padding
|
||||
|
CTR_prototype._padding = C_pad.NoPadding; |
||||
|
|
||||
|
CTR_prototype._doEncrypt = function (cipher, m, iv) { |
||||
|
var blockSizeInBytes = cipher._blocksize * 4; |
||||
|
var counter = iv.slice(0); |
||||
|
|
||||
|
for (var i = 0; i < m.length; ) { |
||||
|
// do not lose iv
|
||||
|
var keystream = counter.slice(0); |
||||
|
|
||||
|
// Generate keystream for next block
|
||||
|
cipher._encryptblock(keystream, 0); |
||||
|
|
||||
|
// XOR keystream with block
|
||||
|
for (var j = 0; i < m.length && j < blockSizeInBytes; j++, i++) { |
||||
|
m[i] ^= keystream[j]; |
||||
|
} |
||||
|
|
||||
|
// Increase counter
|
||||
|
if (++(counter[blockSizeInBytes - 1]) == 256) { |
||||
|
counter[blockSizeInBytes - 1] = 0; |
||||
|
if (++(counter[blockSizeInBytes - 2]) == 256) { |
||||
|
counter[blockSizeInBytes - 2] = 0; |
||||
|
if (++(counter[blockSizeInBytes - 3]) == 256) { |
||||
|
counter[blockSizeInBytes - 3] = 0; |
||||
|
++(counter[blockSizeInBytes - 4]); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
}; |
||||
|
CTR_prototype._doDecrypt = CTR_prototype._doEncrypt; |
||||
|
|
||||
|
})(Crypto); |