Skip to content

Commit

Permalink
feat(hashicorp-vault-signing-manager): add method to expose vault key…
Browse files Browse the repository at this point in the history
… info

Adds getVaultKeys to HashicorpVaultSigningManager so a user is able to fetch Vault information of
the available signing keys
  • Loading branch information
polymath-eric committed Mar 14, 2022
1 parent 72effc1 commit d9c3913
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ describe('HashicorpVaultSigningManager Class', () => {
expect(signer instanceof VaultSigner).toBe(true);
});
});

describe('method: getVaultKeys', () => {
it('should return the vault keys', async () => {
const result = await signingManager.getVaultKeys();
expect(result).toEqual(accounts);
});
});
});

describe('class VaultSigner', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { hexToU8a, u8aToHex } from '@polkadot/util';
import { decodeAddress, encodeAddress } from '@polkadot/util-crypto';
import { PolkadotSigner, SigningManager } from '@polymathnetwork/signing-manager-types';

import { AddressedVaultKey } from '../types';
import { HashicorpVault, VaultKey } from './hashicorp-vault';

export class VaultSigner implements PolkadotSigner {
Expand Down Expand Up @@ -120,6 +121,7 @@ export class HashicorpVaultSigningManager implements SigningManager {
*/
public async getAccounts(): Promise<string[]> {
const ss58Format = this.getSs58Format('getAccounts');
this.getSs58Format('getAccounts');

const keys = await this.vault.fetchAllKeys();

Expand All @@ -133,6 +135,18 @@ export class HashicorpVaultSigningManager implements SigningManager {
return this.externalSigner;
}

/**
* Return the information about each key available to sign extrinsics with in the Hashicorp Vault.
*/
public async getVaultKeys(): Promise<AddressedVaultKey[]> {
const ss58Format = this.getSs58Format('getVaultKeys');
const keys = await this.vault.fetchAllKeys();
return keys.map(key => ({
...key,
address: encodeAddress(key.publicKey, ss58Format),
}));
}

/**
* @hidden
*
Expand Down
8 changes: 8 additions & 0 deletions packages/hashicorp-vault-signing-manager/src/types/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { VaultKey } from '../lib/hashicorp-vault/types';

export interface AddressedVaultKey extends VaultKey {
/**
* ss58 encoded version of the publicKey
*/
address: string;
}

0 comments on commit d9c3913

Please sign in to comment.