Commit 766e3213 authored by Bitcoin Please's avatar Bitcoin Please

Completed support for remote, encrypted metadata.

parent 58d8fbce
......@@ -36,6 +36,7 @@ const updateMeta = async ({ commit, getters, rootGetters }, _meta) => {
/* Commit metadata. */
commit('setMeta', _meta)
/* Request master seed. */
const key = getters.getMasterSeed
/**
......@@ -43,12 +44,12 @@ const updateMeta = async ({ commit, getters, rootGetters }, _meta) => {
*
* For convenience reasons, all metadata is stored in the platform's
* data repository. For privacy reasons, ALL metadata is first encrypted
* with a key ONLY know to this profile.
* with a key ONLY known to this profile.
*/
const encrypted = _encrypt(JSON.stringify(_meta), key)
// console.log('UPDATE META (encrypted):', encrypted)
const signedPkg = getters.getSignedMessage(encrypted)
const signedPkg = getters.getSignedMessage(JSON.stringify(encrypted))
// console.log('SIGNED PACKAGE', signedPkg)
/* Retrieve API provider. */
......@@ -58,9 +59,10 @@ const updateMeta = async ({ commit, getters, rootGetters }, _meta) => {
const target = `${API_PROVIDER}/profiles`
/* Call api. */
await superagent
.post(target)
return await superagent
.put(target)
.send(signedPkg)
.catch(err => console.error(err)) // eslint-disable-line no-console
}
/* Export module. */
......@@ -75,9 +77,7 @@ export default updateMeta
* "comment": <string>,
* "lock": {
* "isActive": <boolean>,
* "label": <string>,
* "comment": <string>,
* "campaignid": <string>,
* "source": <string>, (source_code:source_id)
* "createdAt": <datetime>,
* "expiresAt": <datetime>
* }
......@@ -85,8 +85,6 @@ export default updateMeta
* }],
* }
*
* Metadata is used to store details about coins.
*
* {
* "coins": [{
* <coinid>: {
......@@ -94,25 +92,23 @@ export default updateMeta
* "comment": <string>,
* "cashfusion": {
* "isActive": <boolean>,
* "label": <string>,
* "comment": <string>,
* "rounds": <integer>,
* "sessionid": <string>,
* "phase": <string>,
* "generation": <integer>,
* "createdAt": <datetime>,
* "updatedAt": <datetime>
* },
* "cashshuffle": {
* "isActive": <boolean>,
* "label": <string>,
* "comment": <string>,
* "rounds": <integer>,
* "sessionid": <string>,
* "phase": <string>,
* "generation": <integer>,
* "createdAt": <datetime>,
* "updatedAt": <datetime>
* },
* "lock": {
* "isActive": <boolean>,
* "label": <string>,
* "comment": <string>,
* "campaignid": <string>,
* "source": <string>, (source_code:source_id)
* "createdAt": <datetime>,
* "expiresAt": <datetime>
* }
......
......@@ -13,12 +13,17 @@ function _decrypt(_encrypted, _key) {
/* Set initilization vector. */
const iv = Buffer.from(_encrypted.iv, 'hex')
/* Set encrypted text. */
const encryptedText = Buffer.from(_encrypted.body, 'hex')
const decipher = crypto.createDecipheriv('aes-256-cbc', Buffer.from(_key), iv)
/* Initialize decipher. */
const decipher = crypto
.createDecipheriv('aes-256-cbc', Buffer.from(_key), iv)
/* Update decipher with encrypted text. */
let decrypted = decipher.update(encryptedText)
/* Finalize decrypted message. */
decrypted = Buffer.concat([decrypted, decipher.final()])
/* Return decrypted string. */
......@@ -31,11 +36,8 @@ function _decrypt(_encrypted, _key) {
const getMeta = async (state, getters, rootState, rootGetters) => {
/* Validate state. */
if (!state || !state.meta) {
// TODO: Attempt to retrieve metadata from cloud.
/* Set profile index. */
const profileIndex = 0
// console.log('GET ADDRESS (profileIndex):', profileIndex)
/* Set chain. */
const chain = 0 // receiving account
......@@ -52,7 +54,6 @@ const getMeta = async (state, getters, rootState, rootGetters) => {
/* Set (profile) address. */
const address = Nito.Address.toCashAddress(childNode)
// console.log('GET SIGNED MESSAGE (address):', address)
/* Retrieve API provider. */
const API_PROVIDER = rootGetters.getApiProvider
......@@ -62,24 +63,36 @@ const getMeta = async (state, getters, rootState, rootGetters) => {
/* Set contract path. */
const response = await superagent.get(target)
// console.log('GET META', response)
// console.log('GET META (response):', response)
/* Validate resopnse. */
if (response && response.body && response.body.meta) {
// FIXME: This may be singleton OR not index-0
if (response && response.body && response.body[0].meta) {
/* Set (encrypted) metadata. */
const encrypted = response.body[0].meta // FIXME: This may be singleton OR not index-0
// console.log('GET META (encrypted):', encrypted)
/* Request decryption key. */
const key = getters.getMasterSeed
try {
/* Decrypt metadata. */
const meta = _decrypt(response.body.meta, key)
const decrypted = _decrypt(encrypted, key)
// console.log('GET META (decrypted):', decrypted)
const parsed = JSON.parse(decrypted)
// console.log('GET META (parsed):', parsed)
/* Return metadata. */
return meta
/* Return (parsed) metadata. */
return parsed
} catch (err) {
console.error(err) // eslint-disable-line no-console
}
return null
/* Return error message. */
return err
// return err.message
}
} else {
return null
}
......
......@@ -181,6 +181,7 @@ export default {
'getCoins',
'getDerivationPath',
'getHDNode',
'getIndices',
]),
/**
......@@ -215,13 +216,16 @@ export default {
},
methods: {
...mapActions('profile', [
'updateMeta',
]),
...mapActions('utils', [
'toast',
]),
...mapActions('wallet', [
'updateCoins',
'updateMeta',
]),
/**
......@@ -494,7 +498,7 @@ export default {
/* Request metadata. */
const meta = await this.getMeta
console.log('META', meta)
console.log('BACKING (meta):', meta)
const spendable = Object.keys(coins).filter(coinid => {
return coins[coinid].status === 'active'
......@@ -615,6 +619,9 @@ export default {
const comment = this.userPledge.data.comment
console.log('COMMENT:', comment)
const expires = this.userPledge.expires
console.log('EXPIRES:', expires)
if (!_coin.txid || !_coin.satoshis) {
return console.error('No UTXO available for pledge.')
}
......@@ -672,10 +679,16 @@ export default {
/* Initialize meta. */
const meta = await this.getMeta
console.log('META', meta)
console.log('BACKING (meta):', meta)
/* Set coin id. */
const coinid = `${_coin.txid}:${_coin.vout}`
// const coinid = `${_coin.txid}:${_coin.vout}`
/* Validate coins. */
// NOTE: Added to schema on 2020.7.27
if (!meta.addresses) {
meta.addresses = {}
}
/* Validate coins. */
// NOTE: Added to schema on 2020.7.27
......@@ -684,13 +697,15 @@ export default {
}
/* Update meta data. */
meta['coins'][coinid] = {
// meta['coins'][coinid] = {
meta['addresses'][this.campaignAddress] = {
label: alias,
comment,
lock: {
isActive: true,
label: alias,
comment,
campaignAddr: this.campaignAddress,
source: 'flipstarter',
createdAt: moment().unix(),
expiresAt: expires,
}
}
......@@ -698,7 +713,8 @@ export default {
this.updateMeta(meta)
/* Set message. */
const message = `Your coin has been locked!`
// const message = `Your coin has been locked!`
const message = `Your adddress has been locked!`
/* Display notification. */
this.toast(['Done!', message, 'success'])
......@@ -712,12 +728,30 @@ export default {
}
},
created: function () {
created: async function () {
/* Set owner slug. */
this.ownerSlug = this.$route.params.pathMatch.toLowerCase()
/* Initialize accepting flag. */
this.accepting = false
const meta = await this.getMeta
if (meta.message === 'unable to decrypt data') {
/* Set message. */
// const message = `Your coin has been locked!`
const message = `Your metadata could NOT be decrypted from the cloud`
/* Display notification. */
this.toast(['Oops!', message, 'error'])
}
console.log('BACKING (meta):', meta);
// this.getIndices
// const results = await this.updateMeta({
// hi: 'Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.',
// })
// console.log('UPDATE META RESULTS:', results);
},
}
</script>
......
......@@ -490,7 +490,6 @@ export default {
/* Set message. */
const message = `Your coins have been sent successfully!`
console.log('MESSAGE', message)
/* Display notification. */
this.toast(['Done!', message, 'success'])
......@@ -541,6 +540,7 @@ export default {
async unlock(_coinid) {
/* Request metadata. */
const meta = await this.getMeta
console.log('WALLET (meta):', meta)
/* Initialize coins. */
const coins = this.getCoins
......@@ -581,8 +581,8 @@ export default {
beforeDestroy() {
/* Validate blockchain. */
if (this.blockchain) {
/* Stop blockchain. */
this.blockchain.stop()
/* Unsubscribe from blockchain. */
this.blockchain.unsubscribe()
}
},
}
......
......@@ -41,7 +41,7 @@ export default {
/* Add partner. */
this.partners.push({
title: 'Bitcoin',
title: 'Bitcoin-1',
url: 'https://bitcoin.com/',
imageUrl: 'https://i.imgur.com/otYhXUP.png',
})
......@@ -69,7 +69,7 @@ export default {
/* Add partner. */
this.partners.push({
title: 'Bitcoin',
title: 'Bitcoin-2',
url: 'https://bitcoin.com/',
imageUrl: 'https://i.imgur.com/otYhXUP.png',
})
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment