-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: accounts * fix: remove unused types * fix: state
- Loading branch information
1 parent
fe3c61b
commit 8bc4492
Showing
7 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file added
BIN
+323 KB
.yarn/cache/@emurgo-cardano-serialization-lib-nodejs-npm-7.1.0-9dde1e6073-7ea9089cdd.zip
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters