diff --git a/app/js/account/utils/blockstack-inc.js b/app/js/account/utils/blockstack-inc.js index 51e3caced..17f32963a 100644 --- a/app/js/account/utils/blockstack-inc.js +++ b/app/js/account/utils/blockstack-inc.js @@ -1,6 +1,6 @@ // @flow import log4js from 'log4js' -import { connectToGaiaHub, GaiaHubConfig } from 'blockstack' +import { connectToGaiaHub as bsConnectToGaiaHub, GaiaHubConfig, uploadToGaiaHub } from 'blockstack' const logger = log4js.getLogger(__filename) @@ -11,4 +11,6 @@ export function redirectToConnectToGaiaHub() { window.top.location.href = `http://${host}:${port}/account/storage#gaiahub` } -export { connectToGaiaHub, GaiaHubConfig } +const connectToGaiaHub = (hubUrl: string, key: string) => bsConnectToGaiaHub(hubUrl, key) + +export { connectToGaiaHub, GaiaHubConfig, uploadToGaiaHub } diff --git a/app/js/account/utils/index.js b/app/js/account/utils/index.js index c1dd6bad8..550432406 100644 --- a/app/js/account/utils/index.js +++ b/app/js/account/utils/index.js @@ -1,8 +1,8 @@ // @flow import { parseZoneFile } from 'zone-file' -import type { GaiaHubConfig } from 'blockstack' -import { connectToGaiaHub, uploadToGaiaHub } from 'blockstack' +import type { GaiaHubConfig } from './blockstack-inc' +import { connectToGaiaHub, uploadToGaiaHub } from './blockstack-inc' import { getTokenFileUrlFromZoneFile } from '@utils/zone-utils' @@ -88,8 +88,6 @@ export function uploadProfile( signedProfileTokenData: string ) { return connectToGaiaHub(api.gaiaHubUrl, identityKeyPair.key).then(identityHubConfig => { - const globalHubConfig = api.gaiaHubConfig - const urlToWrite = getProfileUploadLocation(identity, identityHubConfig) let uploadAttempt = tryUpload( @@ -102,7 +100,7 @@ export function uploadProfile( uploadAttempt = tryUpload( urlToWrite, signedProfileTokenData, - globalHubConfig, + identityHubConfig, 'application/json' ) } diff --git a/app/js/store/reducers.js b/app/js/store/reducers.js index 3c13d0419..ea1a0bba4 100644 --- a/app/js/store/reducers.js +++ b/app/js/store/reducers.js @@ -39,7 +39,7 @@ export function initializeStateVersion() { * and other state is regenerated. * @type {number} */ -export const CURRENT_VERSION: number = 16 +export const CURRENT_VERSION: number = 17 const AppReducer = combineReducers({ account: AccountReducer, diff --git a/app/js/update/index.js b/app/js/update/index.js index 57587f075..4e8360007 100644 --- a/app/js/update/index.js +++ b/app/js/update/index.js @@ -10,7 +10,8 @@ import { AppHomeWrapper, ShellParent } from '@blockstack/ui' import { selectAccountCreated, selectEncryptedBackupPhrase, - selectIdentityAddresses + selectIdentityAddresses, + selectIdentityKeypairs } from '@common/store/selectors/account' import { selectDefaultIdentity, @@ -28,7 +29,8 @@ import { hasLegacyCoreStateVersion, migrateLegacyCoreEndpoints } from '@utils/api-utils' -import { decrypt } from '@utils' +import { uploadProfile } from '../account/utils' +import { decrypt, signProfileForUpload } from '@utils' const VIEWS = { INITIAL: 0, SUCCESS: 1, @@ -43,7 +45,8 @@ const mapStateToProps = state => ({ localIdentities: selectLocalIdentities(state), defaultIdentityIndex: selectDefaultIdentity(state), accountCreated: selectAccountCreated(state), - identityAddresses: selectIdentityAddresses(state) + identityAddresses: selectIdentityAddresses(state), + identityKeypairs: selectIdentityKeypairs(state) }) const mapDispatchToProps = dispatch => @@ -137,51 +140,84 @@ class UpdatePage extends React.Component { const dataBuffer = new Buffer(encryptedBackupPhrase, 'hex') const { password } = this.state - return decrypt(dataBuffer, password) - .then(backupPhraseBuffer => { - this.setState( - { - upgradeInProgress: true - }, - () => - setTimeout(() => { - console.debug('decryptKeyAndResetState: correct password!') - const backupPhrase = backupPhraseBuffer.toString() - const numberOfIdentities = - localIdentities.length >= 1 ? localIdentities.length : 1 - this.setState({ - encryptedBackupPhrase, - backupPhrase, - defaultIdentityIndex, - numberOfIdentities - }) - if (hasLegacyCoreStateVersion()) { - const migratedApi = migrateLegacyCoreEndpoints(api) - this.props.migrateAPIEndpoints(migratedApi) - } - // clear our state - this.props.updateState() + const updateProfileUrls = localIdentities.map((identity, index) => + new Promise(async (resolve, reject) => { + try { + const signedProfileTokenData = signProfileForUpload( + identity.profile, + this.props.identityKeypairs[index], + this.props.api + ) + uploadProfile( + this.props.api, + identity, + this.props.identityKeypairs[index], + signedProfileTokenData + ).then(resolve).catch(reject) + } catch (error) { + reject(error) + } + + })) - // generate new account and IDs - this.createAccount().then(() => this.createNewIds()) - .then(() => this.props.refreshIdentities( - this.props.api, - this.props.identityAddresses - )) - }, 150) - ) - }) - .catch(error => { - console.error('decryptKeyAndResetState: invalid password', error) - this.setState({ - loading: false, - password: null, - errors: { - password: 'Incorrect Password' - }, - status: 'error' + return Promise.all(updateProfileUrls).then(() => { + console.log('updated profile URLs') + return decrypt(dataBuffer, password) + .then(backupPhraseBuffer => { + this.setState( + { + upgradeInProgress: true + }, + () => + setTimeout(() => { + console.debug('decryptKeyAndResetState: correct password!') + const backupPhrase = backupPhraseBuffer.toString() + const numberOfIdentities = + localIdentities.length >= 1 ? localIdentities.length : 1 + this.setState({ + encryptedBackupPhrase, + backupPhrase, + defaultIdentityIndex, + numberOfIdentities + }) + if (hasLegacyCoreStateVersion()) { + const migratedApi = migrateLegacyCoreEndpoints(api) + this.props.migrateAPIEndpoints(migratedApi) + } + // clear our state + this.props.updateState() + + // generate new account and IDs + this.createAccount().then(() => this.createNewIds()) + .then(() => this.props.refreshIdentities( + this.props.api, + this.props.identityAddresses + )) + }, 150) + ) }) + .catch(error => { + console.error('decryptKeyAndResetState: invalid password', error) + this.setState({ + loading: false, + password: null, + errors: { + password: 'Incorrect Password' + }, + status: 'error' + }) + }) + }).catch(error => { + console.error('upgradeBlockstackState: error updating profile', error) + this.setState({ + loading: false, + password: null, + errors: { + password: 'Unable to update profile' + }, + status: 'error' }) + }) } /** diff --git a/app/js/utils/profile-utils.js b/app/js/utils/profile-utils.js index c4cd6f95f..1e31efd90 100644 --- a/app/js/utils/profile-utils.js +++ b/app/js/utils/profile-utils.js @@ -171,11 +171,19 @@ export function signProfileForUpload(profile, keypair, api) { const privateKey = keypair.key const publicKey = keypair.keyID + if (profile.api && profile.api.gaiaHubConfig) { + profile.api.gaiaHubConfig = { + url_prefix: profile.api.gaiaHubConfig.url_prefix + } + } + if (api) { profile = { ...profile, api: { - gaiaHubConfig: api.gaiaHubConfig, + gaiaHubConfig: { + url_prefix: api.gaiaHubConfig.url_prefix + }, gaiaHubUrl: api.gaiaHubUrl } } diff --git a/native/macos/Blockstack/Blockstack/Info.plist b/native/macos/Blockstack/Blockstack/Info.plist index 3f0350ce5..6903d99ee 100644 --- a/native/macos/Blockstack/Blockstack/Info.plist +++ b/native/macos/Blockstack/Blockstack/Info.plist @@ -17,7 +17,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 0.35.2 + 0.35.3 CFBundleURLTypes @@ -30,7 +30,7 @@ CFBundleVersion - 114 + 115 LSApplicationCategoryType public.app-category.utilities LSMinimumSystemVersion diff --git a/native/macos/Blockstack/BlockstackLauncher/Info.plist b/native/macos/Blockstack/BlockstackLauncher/Info.plist index 130bcee60..8302ab036 100644 --- a/native/macos/Blockstack/BlockstackLauncher/Info.plist +++ b/native/macos/Blockstack/BlockstackLauncher/Info.plist @@ -17,9 +17,9 @@ CFBundlePackageType APPL CFBundleShortVersionString - 0.35.2 + 0.35.3 CFBundleVersion - 114 + 115 LSApplicationCategoryType public.app-category.utilities LSBackgroundOnly diff --git a/package.json b/package.json index 26d059794..3d76dad52 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "blockstack-browser", "description": "The Blockstack browser", - "version": "0.35.2", + "version": "0.35.3", "author": "Blockstack PBC ", "dependencies": { "bigi": "^1.4.2",