Skip to content

Commit

Permalink
feat: accounts (#76)
Browse files Browse the repository at this point in the history
* feat: accounts

* fix: remove unused types

* fix: state
  • Loading branch information
vladimirvolek authored Jul 8, 2021
1 parent fe3c61b commit 8bc4492
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .pnp.cjs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file not shown.
Binary file modified .yarn/install-state.gz
Binary file not shown.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
},
"dependencies": {
"@blockfrost/openapi": "^0.1.22",
"@emurgo/cardano-serialization-lib-nodejs": "^7.1.0",
"@yarnpkg/pnpify": "3.0.0-rc.6",
"axios": "^0.21.1",
"dotenv": "^10.0.0",
Expand Down
26 changes: 26 additions & 0 deletions src/account/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {
Bip32PublicKey,
BaseAddress,
NetworkInfo,
StakeCredential,
} from '@emurgo/cardano-serialization-lib-nodejs';

export const deriveAddress = (
publicKey: string,
addressIndex: number,
type = 1 | 0,
): { address: string; path: string } => {
const accountKey = Bip32PublicKey.from_bytes(Buffer.from(publicKey, 'hex'));
const utxoPubKey = accountKey.derive(type).derive(addressIndex);
const stakeKey = accountKey.derive(2).derive(0);
const baseAddr = BaseAddress.new(
NetworkInfo.mainnet().network_id(),
StakeCredential.from_keyhash(utxoPubKey.to_raw_key().hash()),
StakeCredential.from_keyhash(stakeKey.to_raw_key().hash()),
);

return {
address: baseAddr.to_address().to_bech32(),
path: `m/1852'/1815'/0'/${type}/${addressIndex}`,
};
};
2 changes: 2 additions & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ export const DEFAULT_API_VERSION = 0;
export const DEFAULT_ORDER: 'asc' | 'desc' = 'asc';
export const DEFAULT_PAGINATION_PAGE_COUNT = 1;
export const DEFAULT_PAGINATION_PAGE_ITEMS_COUNT = 100;

export const ADDRESS_GAP_LIMIT = 20;
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,7 @@ __metadata:
resolution: "@blockfrost/blockfrost-js@workspace:."
dependencies:
"@blockfrost/openapi": ^0.1.22
"@emurgo/cardano-serialization-lib-nodejs": ^7.1.0
"@types/jest": ^26.0.23
"@types/node": ^15.12.4
"@types/url-join": ^4.0.0
Expand Down Expand Up @@ -720,6 +721,13 @@ __metadata:
languageName: node
linkType: hard

"@emurgo/cardano-serialization-lib-nodejs@npm:^7.1.0":
version: 7.1.0
resolution: "@emurgo/cardano-serialization-lib-nodejs@npm:7.1.0"
checksum: 7ea9089cdddc39a5a74c68229bed19cd7222682a6d5833e24b4c614e36a284e968a3517a7ea4cb2c792a121ba22fd419bde79c37cb6d7a3db26f7af410f7c0f5
languageName: node
linkType: hard

"@eslint/eslintrc@npm:^0.4.2":
version: 0.4.2
resolution: "@eslint/eslintrc@npm:0.4.2"
Expand Down

0 comments on commit 8bc4492

Please sign in to comment.