Skip to content

Commit

Permalink
changing multisig secret naming
Browse files Browse the repository at this point in the history
  • Loading branch information
patnir committed Sep 12, 2024
1 parent e2fb66a commit b664ae9
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 25 deletions.
3 changes: 1 addition & 2 deletions ironfish/src/rpc/routes/wallet/multisig/dkg/round1.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'))
})

Expand Down
4 changes: 2 additions & 2 deletions ironfish/src/rpc/routes/wallet/multisig/dkg/round1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ routes.register<typeof DkgRound1RequestSchema, DkgRound1Response>(
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,
Expand All @@ -55,7 +55,7 @@ routes.register<typeof DkgRound1RequestSchema, DkgRound1Response>(
}

const participantIdentities = participants.map((p) => p.identity)
const selfIdentity = new multisig.ParticipantSecret(multisigSecret.secret)
const selfIdentity = new multisig.ParticipantSecret(multisigSecret)
.toIdentity()
.serialize()
.toString('hex')
Expand Down
4 changes: 2 additions & 2 deletions ironfish/src/rpc/routes/wallet/multisig/dkg/round2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ routes.register<typeof DkgRound2RequestSchema, DkgRound2Response>(
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,
RPC_ERROR_CODES.MULTISIG_SECRET_NOT_FOUND,
)
}

const secret = multisigSecret.secret.toString('hex')
const secret = multisigSecret.toString('hex')

const packages = multisig.dkgRound2(secret, round1SecretPackage, round1PublicPackages)

Expand Down
4 changes: 2 additions & 2 deletions ironfish/src/rpc/routes/wallet/multisig/dkg/round3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ routes.register<typeof DkgRound3RequestSchema, DkgRound3Response>(
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,
RPC_ERROR_CODES.MULTISIG_SECRET_NOT_FOUND,
)
}

const secret = new multisig.ParticipantSecret(multisigSecret.secret)
const secret = new multisig.ParticipantSecret(multisigSecret)
const identity = secret.toIdentity().serialize().toString('hex')

const {
Expand Down
2 changes: 1 addition & 1 deletion ironfish/src/rpc/routes/wallet/multisig/getIdentities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ routes.register<typeof GetIdentitiesRequestSchema, GetIdentitiesResponse>(
for await (const [
identity,
{ name },
] of context.wallet.walletDb.multisigSecrets.getAllIter()) {
] of context.wallet.walletDb.multisigIdentities.getAllIter()) {
identities.push({
name,
identity: identity.toString('hex'),
Expand Down
7 changes: 3 additions & 4 deletions ironfish/src/rpc/routes/wallet/multisig/getIdentity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,12 @@ routes.register<typeof GetIdentityRequestSchema, GetIdentityResponse>(

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') })
},
Expand Down
2 changes: 1 addition & 1 deletion ironfish/src/wallet/exporter/encryption.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion ironfish/src/wallet/walletdb/walletdb.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,7 @@ describe('WalletDB', () => {

const storedSecret = await walletDb.getMultisigSecretByName(name)
Assert.isNotUndefined(storedSecret)
expect(storedSecret.secret).toEqualBuffer(serializedSecret)
expect(storedSecret).toEqualBuffer(serializedSecret)
})
})

Expand Down
22 changes: 12 additions & 10 deletions ironfish/src/wallet/walletdb/walletdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export class WalletDB {
value: null
}>

multisigSecrets: IDatabaseStore<{
multisigIdentities: IDatabaseStore<{
key: Buffer
value: MultisigIdentityValue
}>
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -1425,31 +1425,31 @@ export class WalletDB {
value: MultisigIdentityValue,
tx?: IDatabaseTransaction,
): Promise<void> {
await this.multisigSecrets.put(identity, value, tx)
await this.multisigIdentities.put(identity, value, tx)
}

async getMultisigSecret(
identity: Buffer,
tx?: IDatabaseTransaction,
): Promise<MultisigIdentityValue | undefined> {
return this.multisigSecrets.get(identity, tx)
return this.multisigIdentities.get(identity, tx)
}

async hasMultisigSecret(identity: Buffer, tx?: IDatabaseTransaction): Promise<boolean> {
return (await this.getMultisigSecret(identity, tx)) !== undefined
}

async deleteMultisigSecret(identity: Buffer, tx?: IDatabaseTransaction): Promise<void> {
await this.multisigSecrets.del(identity, tx)
await this.multisigIdentities.del(identity, tx)
}

async getMultisigSecretByName(
name: string,
tx?: IDatabaseTransaction,
): Promise<MultisigIdentityValue | undefined> {
for await (const value of this.multisigSecrets.getAllValuesIter(tx)) {
): Promise<Buffer | undefined> {
for await (const value of this.multisigIdentities.getAllValuesIter(tx)) {
if (value.name === name) {
return value
return value.secret
}
}

Expand All @@ -1460,8 +1460,10 @@ export class WalletDB {
return (await this.getMultisigSecretByName(name, tx)) !== undefined
}

async *getMultisigSecrets(tx?: IDatabaseTransaction): AsyncGenerator<MultisigIdentityValue> {
for await (const value of this.multisigSecrets.getAllValuesIter(tx)) {
async *getMultisigIdentities(
tx?: IDatabaseTransaction,
): AsyncGenerator<MultisigIdentityValue> {
for await (const value of this.multisigIdentities.getAllValuesIter(tx)) {
yield value
}
}
Expand Down

0 comments on commit b664ae9

Please sign in to comment.