Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/keyring-api/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Add support for `base32` private key encoding in `exportAccount` ([#589](https://github.com/MetaMask/accounts/pull/589))

## [23.5.0]

### Added
Expand Down
13 changes: 13 additions & 0 deletions packages/keyring-api/src/v2/api/create-account/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,19 @@ describe('CreateAccountOptionsStruct', () => {
assert(validPrivateKey, CreateAccountOptionsStruct),
).not.toThrow();
});

it('validates PrivateKeyImport type with base32 encoding correctly', () => {
const validPrivateKey = {
type: AccountCreationType.PrivateKeyImport,
privateKey: 'JBSWY3DPEHPK3PXP',
encoding: 'base32',
};

expect(is(validPrivateKey, CreateAccountOptionsStruct)).toBe(true);
expect(() =>
assert(validPrivateKey, CreateAccountOptionsStruct),
).not.toThrow();
});
});

describe('invalid account creation types', () => {
Expand Down
26 changes: 26 additions & 0 deletions packages/keyring-api/src/v2/api/keyring.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ expectAssignable<ImportPrivateKeyFormat>({
type: 'eip155:eoa',
});

expectAssignable<ImportPrivateKeyFormat>({
encoding: 'base32',
});

expectAssignable<ImportPrivateKeyFormat>({
encoding: 'base32',
type: 'eip155:eoa',
});

expectNotAssignable<ImportPrivateKeyFormat>({
encoding: 'invalid',
});
Expand Down Expand Up @@ -133,6 +142,12 @@ expectAssignable<CreateAccountPrivateKeyOptions>({
accountType: 'bip122:p2wpkh',
});

expectAssignable<CreateAccountPrivateKeyOptions>({
type: AccountCreationType.PrivateKeyImport,
privateKey: 'JBSWY3DPEHPK3PXP',
encoding: 'base32',
});

// Test CreateAccountCustomOptions
expectAssignable<CreateAccountCustomOptions>({
type: AccountCreationType.Custom,
Expand Down Expand Up @@ -172,6 +187,11 @@ expectAssignable<ExportAccountOptions>({
encoding: 'base58',
});

expectAssignable<ExportAccountOptions>({
type: AccountExportType.PrivateKey,
encoding: 'base32',
});

// Test PrivateKeyExportedAccount
expectAssignable<PrivateKeyExportedAccount>({
type: AccountExportType.PrivateKey,
Expand All @@ -186,6 +206,12 @@ expectAssignable<ExportedAccount>({
encoding: 'base58',
});

expectAssignable<ExportedAccount>({
type: AccountExportType.PrivateKey,
privateKey: 'JBSWY3DPEHPK3PXP',
encoding: 'base32',
});

// Test Keyring interface
expectAssignable<Keyring['type']>(KeyringType.Hd);
expectAssignable<Keyring['capabilities']>({
Expand Down
6 changes: 6 additions & 0 deletions packages/keyring-api/src/v2/api/private-key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ export enum PrivateKeyEncoding {
* Base58 encoding format.
*/
Base58 = 'base58',

/**
* Base32 encoding format.
*/
Base32 = 'base32',
}

/**
Expand All @@ -24,6 +29,7 @@ export enum PrivateKeyEncoding {
export const PrivateKeyEncodingStruct = enums([
`${PrivateKeyEncoding.Hexadecimal}`,
`${PrivateKeyEncoding.Base58}`,
`${PrivateKeyEncoding.Base32}`,
]);

/**
Expand Down
Loading