Skip to content
This repository has been archived by the owner on Apr 30, 2024. It is now read-only.

Commit

Permalink
chore: unharden address index
Browse files Browse the repository at this point in the history
  • Loading branch information
staylorwr committed Apr 24, 2023
1 parent 383668d commit e7f79b4
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/views/Settings/SettingsExport.vue
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ const chunkIntoURLs = async (strs: string[], options: QRCodeOptions) : Promise<s
return r
}
const hardenedIncrement = 0x80000000
export default defineComponent({
components: {
ButtonSubmit,
Expand Down Expand Up @@ -210,11 +212,14 @@ export default defineComponent({
const accountSummary = (account: AccountT, isLocal: boolean): string => {
if (!account.hdPath) throw new Error('Account does not have an HD path')
if (account.hdPath.addressIndex.index < hardenedIncrement) throw new Error('Unhardened Address Index')
const name = accountNameFor(account.address)
completedExports.value = completedExports.value + 1
const localType = isLocal ? 'S' : 'H'
const compressedKey = compressPublicKeyToHex(account.publicKey.toString())
const addressIndex = account.hdPath.addressIndex.index
const addressIndex = account.hdPath.addressIndex.index - hardenedIncrement
return accountToExportPayload(localType, compressedKey, addressIndex, name)
}
Expand All @@ -224,7 +229,7 @@ export default defineComponent({
qrCodes.value = []
exportedSoftwareAccounts.value = []
completedExports.value = 0
const selectedLocalAccounts = localAccounts.value.filter((account) => selectedAccounts.value.includes(account.address.toString()))
const selectedLocalAccounts = localAccounts.value.filter((account) => selectedAccounts.value.includes(account.address.toString()) && account.hdPath)
totalSoftwareExports.value = selectedLocalAccounts.length
totalExports.value = selectedAccounts.value.length
exportedSoftwareAccounts.value = selectedLocalAccounts.map((account) => accountSummary(account, true))
Expand All @@ -245,7 +250,7 @@ export default defineComponent({
for (const address of device.addresses) {
setActiveAddress(address.address.toString())
const nextAccount = await activateAccount()
if (!nextAccount) throw new Error('Could not activate account')
if (!nextAccount || !nextAccount.hdPath) throw new Error('Could not activate account')
const summary = accountSummary(nextAccount, false)
deviceExports.push(summary)
exportedHardwareAccounts.value = [...exportedHardwareAccounts.value, summary]
Expand Down

0 comments on commit e7f79b4

Please sign in to comment.