Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Blockstack): register user for blockstack airdrop
- Loading branch information
Philip London
committed
Oct 29, 2019
1 parent
3e306b4
commit f9d0da6
Showing
16 changed files
with
147 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
packages/blockchain-wallet-v4/src/redux/data/stx/actionTypes.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export const GENERATE_ADDRESS = '@CORE.DATA.GENERATE_STX_ADDRESS' | ||
export const SET_ADDRESS = '@CORE.DATA.SET_STX_ADDRESS' |
11 changes: 11 additions & 0 deletions
11
packages/blockchain-wallet-v4/src/redux/data/stx/actions.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import * as AT from './actionTypes' | ||
|
||
export const generateAddress = password => ({ | ||
type: AT.GENERATE_ADDRESS, | ||
payload: { password } | ||
}) | ||
|
||
export const setAddress = address => ({ | ||
type: AT.SET_ADDRESS, | ||
payload: { address } | ||
}) |
15 changes: 15 additions & 0 deletions
15
packages/blockchain-wallet-v4/src/redux/data/stx/reducers.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { assoc } from 'ramda' | ||
import * as AT from './actionTypes' | ||
|
||
const INITIAL_STATE = { | ||
address: null | ||
} | ||
|
||
export default (state = INITIAL_STATE, action) => { | ||
const { type, payload } = action | ||
switch (type) { | ||
case AT.SET_ADDRESS: { | ||
return assoc('address', payload.address, state) | ||
} | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
packages/blockchain-wallet-v4/src/redux/data/stx/sagaRegister.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { takeLatest } from 'redux-saga/effects' | ||
import * as AT from './actionTypes' | ||
import sagas from './sagas' | ||
|
||
export default () => { | ||
const dataStxSagas = sagas() | ||
|
||
return function * coreDataXlmSaga () { | ||
yield takeLatest(AT.GENERATE_ADDRESS, dataStxSagas.generateAddress) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { put, select } from 'redux-saga/effects' | ||
import { getMnemonic } from '../../wallet/selectors' | ||
import { callTask } from '../../../utils/functional' | ||
import { deriveAddress } from '../../../utils/stx' | ||
import * as A from './actions' | ||
|
||
export default () => { | ||
const generateAddress = function * (action) { | ||
const { payload } = action | ||
const { password } = payload | ||
const mnemonicT = yield select(getMnemonic, password) | ||
const mnemonic = yield callTask(mnemonicT) | ||
const address = deriveAddress(mnemonic) | ||
yield put(A.setAddress(address)) | ||
} | ||
|
||
return { | ||
generateAddress | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import BIP39 from 'bip39' | ||
import Bitcoin from 'bitcoinjs-lib' | ||
|
||
export const deriveAddress = mnemonic => { | ||
const seed = BIP39.mnemonicToSeed(mnemonic) | ||
const address = Bitcoin.HDNode.fromSeedBuffer(seed) | ||
.deriveHardened(44) | ||
.deriveHardened(5757) | ||
.deriveHardened(0) | ||
.derive(0) | ||
.derive(0) | ||
.getAddress() | ||
|
||
return address | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { deriveAddress } from './stx' | ||
|
||
describe('deriveAddress', () => { | ||
it('should derive correct address', () => { | ||
expect( | ||
deriveAddress( | ||
'rubber recipe vote copper obtain negative erosion strong kingdom thank tomato void' | ||
) | ||
).toBe('1EaiavwwQY2eE2vff5JJGo89dRC13xRM7f') | ||
|
||
expect( | ||
deriveAddress( | ||
'one remember hint unlock finger reform utility acid speed cushion split client bitter myself protect actor frame forward rather better mercy clay card awesome' | ||
) | ||
).toBe('1LJepqGsKKLPxFumnzFndsWTWsaCfkSDTp') | ||
}) | ||
}) |