Skip to content

Commit

Permalink
fix(hashicorp-vault-signing-manager): ignore non ed25519 keys to prev…
Browse files Browse the repository at this point in the history
…ent a runtime crash

filter non ed25519 keys so polkadot utils do not error when trying to parse the key as an ss58
address

DA-1103
  • Loading branch information
polymath-eric committed Apr 15, 2024
1 parent 9e7a845 commit 8c8c845
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,11 @@ describe('HashicorpVault class', () => {
keys: {
'1': {
public_key: 'cqWlP2oERZqOjtJmzASNt/jI0/qsAgT5ntWTQAutY2w=',
name: 'ed25519',
},
'2': {
public_key: '7CYkynab5bxXzSPw8djAag9orAalfgA1U2HUUACvfCg=',
name: 'ed25519',
},
},
},
Expand All @@ -67,6 +69,7 @@ describe('HashicorpVault class', () => {
keys: {
'1': {
public_key: 'GvM3BzqsB8JiK6OThUhQNBz/ES1dY4De8j7jI7DUiAI=',
name: 'ed25519',
},
},
},
Expand Down Expand Up @@ -114,9 +117,11 @@ describe('HashicorpVault class', () => {
/* eslint-disable @typescript-eslint/naming-convention */
'1': {
public_key: 'cqWlP2oERZqOjtJmzASNt/jI0/qsAgT5ntWTQAutY2w=',
name: 'ed25519',
},
'2': {
public_key: '7CYkynab5bxXzSPw8djAag9orAalfgA1U2HUUACvfCg=',
name: 'ed25519',
},
/* eslint-enable @typescript-eslint/naming-convention */
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { HexString } from '@polkadot/util/types';
import fetch from 'cross-fetch';
import { flatten, map } from 'lodash';

import {
GetKeyResponse,
Expand Down Expand Up @@ -55,7 +54,7 @@ export class HashicorpVault {

const allKeys = await Promise.all(keys.map(name => this.fetchKeysByName(name)));

return flatten(allKeys);
return allKeys.flat();
}

/**
Expand All @@ -77,15 +76,17 @@ export class HashicorpVault {
data: { keys },
}: GetKeyResponse = await response.json();

return map(keys, ({ public_key: publicKey }, version) => {
const hexKey = Buffer.from(publicKey, 'base64').toString('hex');

return {
publicKey: `0x${hexKey}`,
version: Number(version),
name,
};
});
return Object.entries(keys)
.filter(([, { name }]) => name === 'ed25519') // N.B response "name" is the encryption type
.map(([version, { public_key: publicKey }]) => {
const hexKey = Buffer.from(publicKey, 'base64').toString('hex');

return {
publicKey: `0x${hexKey}`,
version: Number(version),
name,
};
});
}

/**
Expand Down

0 comments on commit 8c8c845

Please sign in to comment.