diff --git a/ironfish/src/rpc/routes/wallet/multisig/dkg/round1.test.ts b/ironfish/src/rpc/routes/wallet/multisig/dkg/round1.test.ts index c87753f5b0..6d19f58776 100644 --- a/ironfish/src/rpc/routes/wallet/multisig/dkg/round1.test.ts +++ b/ironfish/src/rpc/routes/wallet/multisig/dkg/round1.test.ts @@ -33,8 +33,7 @@ describe('Route multisig/dkg/round1', () => { participantName, ) Assert.isNotUndefined(secretValue) - Assert.isNotUndefined(secretValue.secret) - const secret = new multisig.ParticipantSecret(secretValue.secret) + const secret = new multisig.ParticipantSecret(secretValue) secret.decryptData(Buffer.from(response.content.round1SecretPackage, 'hex')) }) diff --git a/ironfish/src/rpc/routes/wallet/multisig/dkg/round1.ts b/ironfish/src/rpc/routes/wallet/multisig/dkg/round1.ts index 05685cda3e..bc407c3ccf 100644 --- a/ironfish/src/rpc/routes/wallet/multisig/dkg/round1.ts +++ b/ironfish/src/rpc/routes/wallet/multisig/dkg/round1.ts @@ -46,7 +46,7 @@ routes.register( const { participantName, minSigners, participants } = request.data const multisigSecret = await node.wallet.walletDb.getMultisigSecretByName(participantName) - if (!multisigSecret || !multisigSecret.secret) { + if (!multisigSecret) { throw new RpcValidationError( `Multisig secret with name '${participantName}' not found`, 400, @@ -55,7 +55,7 @@ routes.register( } const participantIdentities = participants.map((p) => p.identity) - const selfIdentity = new multisig.ParticipantSecret(multisigSecret.secret) + const selfIdentity = new multisig.ParticipantSecret(multisigSecret) .toIdentity() .serialize() .toString('hex') diff --git a/ironfish/src/rpc/routes/wallet/multisig/dkg/round2.ts b/ironfish/src/rpc/routes/wallet/multisig/dkg/round2.ts index 19369e8d03..54d444afe4 100644 --- a/ironfish/src/rpc/routes/wallet/multisig/dkg/round2.ts +++ b/ironfish/src/rpc/routes/wallet/multisig/dkg/round2.ts @@ -43,7 +43,7 @@ routes.register( const { participantName, round1SecretPackage, round1PublicPackages } = request.data const multisigSecret = await node.wallet.walletDb.getMultisigSecretByName(participantName) - if (!multisigSecret || !multisigSecret.secret) { + if (!multisigSecret) { throw new RpcValidationError( `Multisig secret with name '${participantName}' not found`, 400, @@ -51,7 +51,7 @@ routes.register( ) } - const secret = multisigSecret.secret.toString('hex') + const secret = multisigSecret.toString('hex') const packages = multisig.dkgRound2(secret, round1SecretPackage, round1PublicPackages) diff --git a/ironfish/src/rpc/routes/wallet/multisig/dkg/round3.ts b/ironfish/src/rpc/routes/wallet/multisig/dkg/round3.ts index 51095b42ee..0912b324db 100644 --- a/ironfish/src/rpc/routes/wallet/multisig/dkg/round3.ts +++ b/ironfish/src/rpc/routes/wallet/multisig/dkg/round3.ts @@ -49,7 +49,7 @@ routes.register( const { participantName } = request.data const multisigSecret = await node.wallet.walletDb.getMultisigSecretByName(participantName) - if (!multisigSecret || !multisigSecret.secret) { + if (!multisigSecret) { throw new RpcValidationError( `Multisig secret with name '${participantName}' not found`, 400, @@ -57,7 +57,7 @@ routes.register( ) } - const secret = new multisig.ParticipantSecret(multisigSecret.secret) + const secret = new multisig.ParticipantSecret(multisigSecret) const identity = secret.toIdentity().serialize().toString('hex') const { diff --git a/ironfish/src/rpc/routes/wallet/multisig/getIdentities.ts b/ironfish/src/rpc/routes/wallet/multisig/getIdentities.ts index ea7ba49f94..79a12af078 100644 --- a/ironfish/src/rpc/routes/wallet/multisig/getIdentities.ts +++ b/ironfish/src/rpc/routes/wallet/multisig/getIdentities.ts @@ -45,7 +45,7 @@ routes.register( for await (const [ identity, { name }, - ] of context.wallet.walletDb.multisigSecrets.getAllIter()) { + ] of context.wallet.walletDb.multisigIdentities.getAllIter()) { identities.push({ name, identity: identity.toString('hex'), diff --git a/ironfish/src/rpc/routes/wallet/multisig/getIdentity.ts b/ironfish/src/rpc/routes/wallet/multisig/getIdentity.ts index 9c582e71c7..bed99978fb 100644 --- a/ironfish/src/rpc/routes/wallet/multisig/getIdentity.ts +++ b/ironfish/src/rpc/routes/wallet/multisig/getIdentity.ts @@ -36,13 +36,12 @@ routes.register( const { name } = request.data - const record = await context.wallet.walletDb.getMultisigSecretByName(name) - if (record === undefined || record.secret === undefined) { + const secret = await context.wallet.walletDb.getMultisigSecretByName(name) + if (secret === undefined) { throw new RpcValidationError(`No identity found with name ${name}`, 404) } - const secret = new multisig.ParticipantSecret(record.secret) - const identity = secret.toIdentity() + const identity = new multisig.ParticipantSecret(secret).toIdentity() request.end({ identity: identity.serialize().toString('hex') }) }, diff --git a/ironfish/src/wallet/exporter/encryption.ts b/ironfish/src/wallet/exporter/encryption.ts index 8bd42240f1..eb6f0430d5 100644 --- a/ironfish/src/wallet/exporter/encryption.ts +++ b/ironfish/src/wallet/exporter/encryption.ts @@ -33,7 +33,7 @@ export async function decryptEncodedAccount( if (encrypted.startsWith(BASE64_JSON_MULTISIG_ENCRYPTED_ACCOUNT_PREFIX)) { const encoded = encrypted.slice(BASE64_JSON_MULTISIG_ENCRYPTED_ACCOUNT_PREFIX.length) - for await (const { secret: secretBuffer } of wallet.walletDb.getMultisigSecrets()) { + for await (const { secret: secretBuffer } of wallet.walletDb.getMultisigIdentities()) { if (secretBuffer === undefined) { continue } diff --git a/ironfish/src/wallet/walletdb/walletdb.test.ts b/ironfish/src/wallet/walletdb/walletdb.test.ts index d1bff95abc..f9f183b1c7 100644 --- a/ironfish/src/wallet/walletdb/walletdb.test.ts +++ b/ironfish/src/wallet/walletdb/walletdb.test.ts @@ -457,7 +457,7 @@ describe('WalletDB', () => { const storedSecret = await walletDb.getMultisigSecretByName(name) Assert.isNotUndefined(storedSecret) - expect(storedSecret.secret).toEqualBuffer(serializedSecret) + expect(storedSecret).toEqualBuffer(serializedSecret) }) }) diff --git a/ironfish/src/wallet/walletdb/walletdb.ts b/ironfish/src/wallet/walletdb/walletdb.ts index e4787e8177..ceae84d653 100644 --- a/ironfish/src/wallet/walletdb/walletdb.ts +++ b/ironfish/src/wallet/walletdb/walletdb.ts @@ -138,7 +138,7 @@ export class WalletDB { value: null }> - multisigSecrets: IDatabaseStore<{ + multisigIdentities: IDatabaseStore<{ key: Buffer value: MultisigIdentityValue }> @@ -298,7 +298,7 @@ export class WalletDB { valueEncoding: NULL_ENCODING, }) - this.multisigSecrets = this.db.addStore({ + this.multisigIdentities = this.db.addStore({ name: 'ms', keyEncoding: new BufferEncoding(), valueEncoding: new MultisigIdentityValueEncoder(), @@ -1425,14 +1425,14 @@ export class WalletDB { value: MultisigIdentityValue, tx?: IDatabaseTransaction, ): Promise { - await this.multisigSecrets.put(identity, value, tx) + await this.multisigIdentities.put(identity, value, tx) } async getMultisigSecret( identity: Buffer, tx?: IDatabaseTransaction, ): Promise { - return this.multisigSecrets.get(identity, tx) + return this.multisigIdentities.get(identity, tx) } async hasMultisigSecret(identity: Buffer, tx?: IDatabaseTransaction): Promise { @@ -1440,16 +1440,16 @@ export class WalletDB { } async deleteMultisigSecret(identity: Buffer, tx?: IDatabaseTransaction): Promise { - await this.multisigSecrets.del(identity, tx) + await this.multisigIdentities.del(identity, tx) } async getMultisigSecretByName( name: string, tx?: IDatabaseTransaction, - ): Promise { - for await (const value of this.multisigSecrets.getAllValuesIter(tx)) { + ): Promise { + for await (const value of this.multisigIdentities.getAllValuesIter(tx)) { if (value.name === name) { - return value + return value.secret } } @@ -1460,8 +1460,10 @@ export class WalletDB { return (await this.getMultisigSecretByName(name, tx)) !== undefined } - async *getMultisigSecrets(tx?: IDatabaseTransaction): AsyncGenerator { - for await (const value of this.multisigSecrets.getAllValuesIter(tx)) { + async *getMultisigIdentities( + tx?: IDatabaseTransaction, + ): AsyncGenerator { + for await (const value of this.multisigIdentities.getAllValuesIter(tx)) { yield value } }