UNPKG

@crpdo/key

Version:

Streamlines key generation, derivation, and management through its simple and intuitive API

107 lines (91 loc) 3.22 kB
const HdKey = require('../lib/hd-key') const BaseKey = require('../lib/base-key') const seed = 'seed' const derivationPath = "m/44'/0'/0'/0'" const data = 'foo' const signature = '3a2Dap3sqcJDFHR3NuDJBKHNU9VvCoXjttVha1xyv4CWGm6v25Tv4zZSw9AmWA8sWT5gSNseCNMqAG9n7vq7STrF' describe('HdKey', () => { describe('#constructor()', () => { it('should create an HdKey object with valid seed', () => { const signKey = new HdKey(seed) expect(signKey).to.be.an('object') expect(signKey).to.be.an.instanceOf(HdKey) expect(signKey).to.be.an.instanceOf(BaseKey) }) it('should construct and use the methods properly', () => { const hdKey = new HdKey(seed) const derivedKey = hdKey.derive(derivationPath) const signedData = hdKey.sign(data) const isValidSignature = hdKey.verify(data, signedData) expect(isValidSignature).to.be.true }) }) describe('#derive()', () => { it('should derive a new HD key', () => { const hdKey = new HdKey(seed) const derivedKey = hdKey.derive(derivationPath) expect(derivedKey).to.be.an('object') expect(derivedKey).to.be.an.instanceOf(HdKey.HDKey) }) }) describe('#sign()', () => { it('should sign the data', () => { const signature = hdKey.sign(data) expect(signature).to.be.a('string') }) }) describe('#verify()', () => { it('should verify the signature', () => { const isValidSignature = hdKey.verify(data, signature, hdKey.publicKey) expect(isValidSignature).to.be.true }) }) const hdKey = new HdKey(seed) describe('#depth', () => { it('should get the depth', () => { const depth = hdKey.depth expect(depth).to.be.a('number') expect(depth).to.equal(0) }) }) describe('#publicKey', () => { it('should get the public key', () => { const publicKey = hdKey.publicKey expect(publicKey).to.be.a('string') }) }) describe('#privateKey', () => { it('should get the private key', () => { const privateKey = hdKey.privateKey expect(privateKey).to.be.a('string') }) }) describe('#publicExtendedKey', () => { it('should get the public extended key', () => { const publicExtendedKey = hdKey.publicExtendedKey expect(publicExtendedKey).to.be.a('string') }) }) describe('#privateExtendedKey', () => { it('should get the private extended key', () => { const privateExtendedKey = hdKey.privateExtendedKey expect(privateExtendedKey).to.be.a('string') }) }) const coinSymbol = 'BTC' const account = 0 const change = 0 const index = 0 describe('#deriveSoftened', () => { it('should derive a new key with softened parameters', () => { const derivedKey = hdKey.deriveSoftened(coinSymbol, account, change, index) expect(derivedKey).to.be.an('object') // replace with expected type }) }) describe('#deriveSoftenedPublicKey', () => { it('should derive a new public key with softened parameters', () => { const derivedPublicKey = hdKey.deriveSoftenedPublicKey(coinSymbol, account, change, index) expect(derivedPublicKey).to.be.a('string') // replace with expected type }) }) })