diff --git a/docs/badge-coverage.svg b/docs/badge-coverage.svg index 3e9ec148..54786467 100644 --- a/docs/badge-coverage.svg +++ b/docs/badge-coverage.svg @@ -1 +1 @@ -Coverage: 51.29%Coverage51.29% \ No newline at end of file +Coverage: 52.5%Coverage52.5% \ No newline at end of file diff --git a/src/BlockFrostAPI.ts b/src/BlockFrostAPI.ts index d5fb6632..682592d6 100644 --- a/src/BlockFrostAPI.ts +++ b/src/BlockFrostAPI.ts @@ -1,6 +1,8 @@ import { API_URLS } from './config'; import { AxiosInstance } from 'axios'; +import { deriveAddress, getAccount } from './account'; + import { accounts, accountsDelegations, @@ -878,6 +880,24 @@ class BlockFrostAPI { * */ txSubmit = txSubmit; + + /** + * deriveAddress + * + * @param hash + * @returns xxx + * + */ + deriveAddress = deriveAddress; + + /** + * txSubmit + * + * @param hash + * @returns xxx + * + */ + getAccount = getAccount; } export { BlockFrostAPI }; diff --git a/src/account/index.ts b/src/account/index.ts index d600d73c..d7708606 100644 --- a/src/account/index.ts +++ b/src/account/index.ts @@ -11,7 +11,7 @@ import { ADDRESS_GAP_LIMIT } from '../config'; export const deriveAddress = ( publicKey: string, addressIndex: number, - type = 1 | 0, + type: 0 | 1, ): { address: string; path: string } => { const accountKey = Bip32PublicKey.from_bytes(Buffer.from(publicKey, 'hex')); const utxoPubKey = accountKey.derive(type).derive(addressIndex); diff --git a/test/fixtures/account/index.ts b/test/fixtures/account/index.ts new file mode 100644 index 00000000..ab1dcfb8 --- /dev/null +++ b/test/fixtures/account/index.ts @@ -0,0 +1,39 @@ +export const deriveAddressFixtures = [ + { + publicKey: + '6d17587575a3b4f0f86ebad3977e8f7e4981faa863eccf5c1467065c74fe3435943769446dd290d103fb3d360128e86de4b47faea73ffb0900c94c6a61ef9ea2', + index: 0, + type: 0, + response: { + address: + 'addr1q8u5ktsj5zsmhvwv0ep9zuhfu39x3wyt9wxjnsn3cagsyy59ckxhkvuc5xj49rw6zrp443wlygmhv8gwcu38jk6ms6usrmcafl', + path: "m/1852'/1815'/0'/0/0", + }, + }, + { + publicKey: + '6d17587575a3b4f0f86ebad3977e8f7e4981faa863eccf5c1467065c74fe3435943769446dd290d103fb3d360128e86de4b47faea73ffb0900c94c6a61ef9ea2', + index: 1, + type: 0, + response: { + address: + 'addr1qxnthyxq8x9lv95h74k5av3sy3yzljr56ttxu4lggv8qstv9ckxhkvuc5xj49rw6zrp443wlygmhv8gwcu38jk6ms6us8mueja', + path: "m/1852'/1815'/0'/0/1", + }, + }, +] as const; + +export const getAccountFixtures = [ + { + publicKey: + '6d17587575a3b4f0f86ebad3977e8f7e4981faa863eccf5c1467065c74fe3435943769446dd290d103fb3d360128e86de4b47faea73ffb0900c94c6a61ef9ea2', + type: 0, + response: '', + }, + { + publicKey: + '6d17587575a3b4f0f86ebad3977e8f7e4981faa863eccf5c1467065c74fe3435943769446dd290d103fb3d360128e86de4b47faea73ffb0900c94c6a61ef9ea2', + type: 1, + response: '', + }, +] as const; diff --git a/test/tests/account/index.ts b/test/tests/account/index.ts new file mode 100644 index 00000000..2f364eae --- /dev/null +++ b/test/tests/account/index.ts @@ -0,0 +1,25 @@ +import { SDK } from '../../utils'; +import { + deriveAddressFixtures, + // getAccountFixtures, +} from '../../fixtures/account'; + +describe('account', () => { + deriveAddressFixtures.forEach(fixture => { + test(fixture.toString(), () => { + const response = SDK.deriveAddress( + fixture.publicKey, + fixture.index, + fixture.type, + ); + expect(response).toMatchObject(fixture.response); + }); + }); + + // getAccountFixtures.forEach(fixture => { + // test(fixture.toString(), async () => { + // const response = await SDK.getAccount(fixture.publicKey, fixture.type); + // expect(response).toMatchObject(fixture.response); + // }); + // }); +});