Skip to content

Commit

Permalink
feat: add dedicated OneKey keyring class
Browse files Browse the repository at this point in the history
  • Loading branch information
Akaryatrh committed Feb 7, 2025
1 parent b0715fb commit 2cad266
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/keyring-eth-trezor/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ module.exports = merge(baseConfig, {
coverageThreshold: {
global: {
branches: 48.27,
functions: 91.22,
lines: 89.94,
statements: 90.15,
functions: 91.37,
lines: 90.2,
statements: 90.4,
},
},
});
42 changes: 42 additions & 0 deletions packages/keyring-eth-trezor/src/onekey-keyring.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import HDKey from 'hdkey';
import * as sinon from 'sinon';

import { OneKeyKeyring } from './onekey-keyring';
import { TrezorBridge } from './trezor-bridge';
import { TrezorKeyring } from './trezor-keyring';

const fakeXPubKey =
'xpub6FnCn6nSzZAw5Tw7cgR9bi15UV96gLZhjDstkXXxvCLsUXBGXPdSnLFbdpq8p9HmGsApME5hQTZ3emM2rnY5agb9rXpVGyy3bdW6EEgAtqt';
const fakeHdKey = HDKey.fromExtendedKey(fakeXPubKey);

describe('TrezorKeyring', function () {
let keyring: OneKeyKeyring;
let bridge: TrezorBridge;

beforeEach(async function () {
bridge = {} as TrezorBridge;
keyring = new OneKeyKeyring({ bridge });
keyring.hdk = fakeHdKey;
});

afterEach(function () {
sinon.restore();
});

it('extends TrezorKeyring', () => {
expect(keyring).toBeInstanceOf(TrezorKeyring);
});

describe('Keyring.type', function () {
it('is a class property that returns the type string.', function () {
const { type } = TrezorKeyring;
expect(typeof type).toBe('string');
});

it('returns the correct value', function () {
const { type } = keyring;
const correct = OneKeyKeyring.type;
expect(type).toBe(correct);
});
});
});
9 changes: 9 additions & 0 deletions packages/keyring-eth-trezor/src/onekey-keyring.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { TrezorKeyring } from './trezor-keyring';

const oneKeyKeyringType = 'OneKey Hardware';

export class OneKeyKeyring extends TrezorKeyring {
static type: string = oneKeyKeyringType;

readonly type: string = oneKeyKeyringType;
}

0 comments on commit 2cad266

Please sign in to comment.