wallet.ts
A collection of utilities for building cryptocurrency wallets, written in TypeScript.
Hierarchical Deterministic Wallets (BIP 32)
const { randomBytes } = require('crypto')
const { HDKey } = require('wallet.ts')
const seed = randomBytes(66)
const masterKey = HDKey.parseMasterSeed(seed)
const extendedPrivateKey = masterKey.derive("m/44'/60'/0'/0").extendedPrivateKey
const childKey = HDKey.parseExtendedKey(extendedPrivateKey)
const wallet = childKey.derive('0')
const walletPrivateKey = wallet.privateKey
const walletPublicKey = wallet.publicKey
View Source
Mnemonic code for generating deterministic keys (BIP 39)
const { randomBytes } = require('crypto')
const { Mnemonic } = require('wallet.ts')
const mnemonic = Mnemonic.generate(randomBytes(32))
const phrase = mnemonic.phrase
const words = mnemonic.words
const seed = mnemonic.toSeed()
View Source
Bitcoin Address
const { BitcoinAddress } = require('wallet.ts')
const publicKey = Buffer.from(
'0250863ad64a87ae8a2fe83c1af1a8403cb53f53e486d8511dad8a04887e5b2352',
'hex'
)
const address = BitcoinAddress.from(publicKey).address
const valid = BitcoinAddress.isValid(address)
View Source
Ethereum Address / EIP 55 checksum
const { EthereumAddress } = require('wallet.ts')
const publicKey = Buffer.from(
'028a8c59fa27d1e0f1643081ff80c3cf0392902acbf76ab0dc9c414b8d115b0ab3',
'hex'
)
const address = EthereumAddress.from(publicKey).address
const valid = EthereumAddress.isValid(address)
const checksumAddress = EthereumAddress.checksumAddress('0xd11a13f484e2f2bd22d93c3c3131f61c05e876a')
View Source
Copyright © 2017 Peter Jihoon Kim. This project is licensed under the ISC license.