Skip to content

Commit f4dbb38

Browse files
authored
deletes multisig identity on account import (#5692)
since the identity will always be stored on the multisig identity we don't need to maintain the record of the identity separately in the multisigIdenitities store keeping identities in this store can be confusing for future use when generating new accounts deletes any existing identity that matches the identity on the imported account instead of adding an identity to the store if it is missing removes DuplicateIdentityNameError, which is no longer thrown removes tests that checked duplicate identity name logic on import
1 parent 2a64ece commit f4dbb38

File tree

4 files changed

+2
-217
lines changed

4 files changed

+2
-217
lines changed

ironfish/src/rpc/routes/wallet/importAccount.test.ts

Lines changed: 0 additions & 182 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import { generateKey, LanguageCode, multisig, spendingKeyToWords } from '@ironfish/rust-nodejs'
55
import fs from 'fs'
66
import path from 'path'
7-
import { Assert } from '../../../assert'
87
import { createTrustedDealerKeyPackages, useMinerBlockFixture } from '../../../testUtilities'
98
import { createRouteTest } from '../../../testUtilities/routeTest'
109
import { JsonEncoder } from '../../../wallet'
@@ -470,187 +469,6 @@ describe('Route wallet/importAccount', () => {
470469
expect.assertions(2)
471470
})
472471

473-
it('should not import multisig account with secret with the same identity name', async () => {
474-
const name = 'duplicateIdentityNameTest'
475-
476-
const {
477-
dealer: trustedDealerPackages,
478-
secrets,
479-
identities,
480-
} = createTrustedDealerKeyPackages()
481-
482-
await routeTest.node.wallet.walletDb.putMultisigIdentity(
483-
Buffer.from(identities[0], 'hex'),
484-
{
485-
secret: secrets[0].serialize(),
486-
name,
487-
},
488-
)
489-
490-
const indentityCountBefore = (await routeTest.client.wallet.multisig.getIdentities())
491-
.content.identities.length
492-
493-
const account: AccountImport = {
494-
version: 1,
495-
name,
496-
viewKey: trustedDealerPackages.viewKey,
497-
incomingViewKey: trustedDealerPackages.incomingViewKey,
498-
outgoingViewKey: trustedDealerPackages.outgoingViewKey,
499-
publicAddress: trustedDealerPackages.publicAddress,
500-
spendingKey: null,
501-
createdAt: null,
502-
proofAuthorizingKey: trustedDealerPackages.proofAuthorizingKey,
503-
multisigKeys: {
504-
publicKeyPackage: trustedDealerPackages.publicKeyPackage,
505-
keyPackage: trustedDealerPackages.keyPackages[1].keyPackage.toString(),
506-
secret: secrets[1].serialize().toString('hex'),
507-
},
508-
ledger: false,
509-
}
510-
511-
try {
512-
await routeTest.client.wallet.importAccount({
513-
account: new JsonEncoder().encode(account),
514-
name,
515-
rescan: false,
516-
})
517-
} catch (e: unknown) {
518-
if (!(e instanceof RpcRequestError)) {
519-
throw e
520-
}
521-
522-
/**
523-
* These assertions ensures that we cannot import multiple identities with the same name.
524-
* This is done by creating an identity, storing it and attempting to import another identity but give it the same name.
525-
*/
526-
expect(e.status).toBe(400)
527-
expect(e.code).toBe(RPC_ERROR_CODES.DUPLICATE_IDENTITY_NAME)
528-
}
529-
530-
if (account.multisigKeys && isMultisigSignerImport(account.multisigKeys)) {
531-
account.multisigKeys.secret = secrets[0].serialize().toString('hex')
532-
} else {
533-
throw new Error('Invalid multisig keys')
534-
}
535-
536-
const response = await routeTest.client.wallet.importAccount({
537-
account: new JsonEncoder().encode(account),
538-
name: 'account2',
539-
rescan: false,
540-
})
541-
542-
expect(response.status).toBe(200)
543-
expect(response.content.name).toEqual('account2')
544-
545-
const identitiesAfter = (await routeTest.client.wallet.multisig.getIdentities()).content
546-
.identities
547-
const newIdentity = identitiesAfter.find((identity) => identity.name === name)
548-
549-
/**
550-
* These assertions ensure that if we try to import an identity with the same secret but different name, it will pass.
551-
* However, the identity name will remain the same as the original identity that was imported first.
552-
*/
553-
expect(identitiesAfter.length).toBe(indentityCountBefore)
554-
expect(newIdentity).toBeDefined()
555-
expect(newIdentity?.name).toBe(name)
556-
557-
expect.assertions(7)
558-
})
559-
560-
it('should not import hardware multisig account with same identity name', async () => {
561-
const name = 'duplicateIdentityNameTest'
562-
563-
const {
564-
dealer: trustedDealerPackages,
565-
secrets,
566-
identities,
567-
} = createTrustedDealerKeyPackages()
568-
569-
const identity = identities[0]
570-
const nextIdentity = identities[1]
571-
572-
await routeTest.node.wallet.walletDb.putMultisigIdentity(Buffer.from(identity, 'hex'), {
573-
secret: secrets[0].serialize(),
574-
name,
575-
})
576-
577-
const account: AccountImport = {
578-
version: 1,
579-
name,
580-
viewKey: trustedDealerPackages.viewKey,
581-
incomingViewKey: trustedDealerPackages.incomingViewKey,
582-
outgoingViewKey: trustedDealerPackages.outgoingViewKey,
583-
publicAddress: trustedDealerPackages.publicAddress,
584-
proofAuthorizingKey: trustedDealerPackages.proofAuthorizingKey,
585-
spendingKey: null,
586-
createdAt: null,
587-
multisigKeys: {
588-
publicKeyPackage: trustedDealerPackages.publicKeyPackage,
589-
identity: nextIdentity,
590-
},
591-
ledger: false,
592-
}
593-
594-
try {
595-
await routeTest.client.wallet.importAccount({
596-
account: new JsonEncoder().encode(account),
597-
name,
598-
rescan: false,
599-
})
600-
} catch (e: unknown) {
601-
if (!(e instanceof RpcRequestError)) {
602-
throw e
603-
}
604-
605-
expect(e.status).toBe(400)
606-
expect(e.code).toBe(RPC_ERROR_CODES.DUPLICATE_IDENTITY_NAME)
607-
}
608-
609-
expect.assertions(2)
610-
})
611-
612-
it('should not modify existing identity if a new one is being imported with a different name', async () => {
613-
const { dealer: trustedDealerPackages, identities } = createTrustedDealerKeyPackages()
614-
615-
const identity = identities[0]
616-
617-
await routeTest.node.wallet.walletDb.putMultisigIdentity(Buffer.from(identity, 'hex'), {
618-
name: 'existingIdentity',
619-
})
620-
621-
const account: AccountImport = {
622-
version: 1,
623-
name: 'newIdentity',
624-
viewKey: trustedDealerPackages.viewKey,
625-
incomingViewKey: trustedDealerPackages.incomingViewKey,
626-
outgoingViewKey: trustedDealerPackages.outgoingViewKey,
627-
publicAddress: trustedDealerPackages.publicAddress,
628-
proofAuthorizingKey: trustedDealerPackages.proofAuthorizingKey,
629-
spendingKey: null,
630-
createdAt: null,
631-
multisigKeys: {
632-
publicKeyPackage: trustedDealerPackages.publicKeyPackage,
633-
identity: identity,
634-
},
635-
ledger: false,
636-
}
637-
638-
const response = await routeTest.client.wallet.importAccount({
639-
account: new JsonEncoder().encode(account),
640-
name: 'newIdentity',
641-
rescan: false,
642-
})
643-
644-
expect(response.status).toBe(200)
645-
expect(response.content.name).toEqual('newIdentity')
646-
647-
const existingIdentity = await routeTest.wallet.walletDb.getMultisigIdentity(
648-
Buffer.from(identity, 'hex'),
649-
)
650-
Assert.isNotUndefined(existingIdentity)
651-
expect(existingIdentity.name).toEqual('existingIdentity')
652-
})
653-
654472
describe('account format', () => {
655473
it('should decode an account import with the requested format', async () => {
656474
const name = 'mnemonic-format'

ironfish/src/rpc/routes/wallet/importAccount.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
44
import * as yup from 'yup'
55
import { DecodeInvalidName } from '../../../wallet'
6-
import { DuplicateAccountNameError, DuplicateIdentityNameError } from '../../../wallet/errors'
6+
import { DuplicateAccountNameError } from '../../../wallet/errors'
77
import { AccountFormat, decodeAccountImport } from '../../../wallet/exporter/account'
88
import { decryptEncodedAccount } from '../../../wallet/exporter/encryption'
99
import { RPC_ERROR_CODES, RpcValidationError } from '../../adapters'
@@ -75,9 +75,6 @@ routes.register<typeof ImportAccountRequestSchema, ImportResponse>(
7575
isDefaultAccount,
7676
})
7777
} catch (e) {
78-
if (e instanceof DuplicateIdentityNameError) {
79-
throw new RpcValidationError(e.message, 400, RPC_ERROR_CODES.DUPLICATE_IDENTITY_NAME)
80-
}
8178
if (e instanceof DuplicateAccountNameError) {
8279
throw new RpcValidationError(e.message, 400, RPC_ERROR_CODES.DUPLICATE_ACCOUNT_NAME)
8380
} else if (e instanceof DecodeInvalidName) {

ironfish/src/wallet/errors.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,6 @@ export class DuplicateAccountNameError extends Error {
5151
}
5252
}
5353

54-
export class DuplicateIdentityNameError extends Error {
55-
name = this.constructor.name
56-
57-
constructor(name: string) {
58-
super()
59-
this.message = `Multisig identity already exists with the name ${name}`
60-
}
61-
}
62-
6354
export class DuplicateIdentityError extends Error {
6455
name = this.constructor.name
6556

ironfish/src/wallet/wallet.ts

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ import { EncryptedAccount } from './account/encryptedAccount'
4848
import { AssetBalances } from './assetBalances'
4949
import {
5050
DuplicateAccountNameError,
51-
DuplicateIdentityNameError,
5251
DuplicateMultisigSecretNameError,
5352
DuplicateSpendingKeyError,
5453
MaxMemoLengthError,
@@ -1570,27 +1569,7 @@ export class Wallet {
15701569
}
15711570

15721571
if (identity) {
1573-
const existingIdentity = await this.walletDb.getMultisigIdentity(identity, tx)
1574-
1575-
if (!existingIdentity) {
1576-
const duplicateSecret = await this.walletDb.getMultisigSecretByName(
1577-
accountValue.name,
1578-
tx,
1579-
)
1580-
1581-
if (duplicateSecret) {
1582-
throw new DuplicateIdentityNameError(accountValue.name)
1583-
}
1584-
1585-
await this.walletDb.putMultisigIdentity(
1586-
identity,
1587-
{
1588-
name: account.name,
1589-
secret,
1590-
},
1591-
tx,
1592-
)
1593-
}
1572+
await this.walletDb.deleteMultisigIdentity(identity, tx)
15941573
}
15951574

15961575
const accountHead =

0 commit comments

Comments
 (0)