Skip to content

Commit

Permalink
Multisig: do not include the multisig secret when exporting view-only…
Browse files Browse the repository at this point in the history
… account
  • Loading branch information
andiflabs committed Mar 14, 2024
1 parent 117b0c1 commit 665dac0
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
62 changes: 62 additions & 0 deletions ironfish/src/rpc/routes/wallet/exportAccount.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,66 @@ describe('Route wallet/exportAccount', () => {
},
})
})

it('should export an account with multisigKeys and without multisig secrets when view only account is requested', async () => {
const accountNames = Array.from(
{ length: 2 },
(_, index) => `another-test-account-${index}`,
)
const participants = await Promise.all(
accountNames.map(
async (name) =>
(
await routeTest.client
.request<CreateParticipantResponse>('wallet/multisig/createParticipant', { name })
.waitForEnd()
).content,
),
)

const multisigSecret = await routeTest.node.wallet.walletDb.getMultisigSecret(
Buffer.from(participants[0].identity, 'hex'),
)
Assert.isNotUndefined(multisigSecret)

// Initialize the group though TDK and import one of the accounts generated
const trustedDealerPackage = (
await routeTest.client.wallet.multisig.createTrustedDealerKeyPackage({
minSigners: 2,
participants,
})
).content

const importAccount = trustedDealerPackage.participantAccounts.find(
({ identity }) => identity === participants[0].identity,
)
expect(importAccount).toBeDefined()

await routeTest.client.wallet.importAccount({
name: accountNames[0],
account: importAccount!.account,
})

const response = await routeTest.client
.request<ExportAccountResponse>('wallet/exportAccount', {
account: accountNames[0],
viewOnly: true,
})
.waitForEnd()

expect(response.status).toBe(200)
expect(response.content).toMatchObject({
account: {
name: accountNames[0],
spendingKey: null,
viewKey: trustedDealerPackage.viewKey,
incomingViewKey: trustedDealerPackage.incomingViewKey,
outgoingViewKey: trustedDealerPackage.outgoingViewKey,
publicAddress: trustedDealerPackage.publicAddress,
multisigKeys: {
publicKeyPackage: trustedDealerPackage.publicKeyPackage,
},
},
})
})
})
5 changes: 5 additions & 0 deletions ironfish/src/rpc/routes/wallet/exportAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ routes.register<typeof ExportAccountRequestSchema, ExportAccountResponse>(
const { id: _, ...accountInfo } = account.serialize()
if (request.data.viewOnly) {
accountInfo.spendingKey = null
if (accountInfo.multisigKeys) {
accountInfo.multisigKeys = {
publicKeyPackage: accountInfo.multisigKeys.publicKeyPackage,
}
}
}

if (!request.data.format) {
Expand Down

0 comments on commit 665dac0

Please sign in to comment.