-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(root): implement Eddsa multisig derivation
Implemented Eddsa multisig derivation BREAKING CHANGE: wallet.getPrv() is now an async method, coin.generateKeyPair(), coin.deriveKeyWithSeed() and keychains.create() are deprecated, use their Async version instead. WP-1401 TICKET: WP-1401
- Loading branch information
Showing
29 changed files
with
447 additions
and
199 deletions.
There are no files selected for viewing
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,17 @@ | ||
export const data = { | ||
seed: { | ||
validSeed: | ||
'e3e670f488500f300790bee3fc2fb075d82d279459fa53024168664aec73054f2f5a0abfcd5889100604b0c22a430c4f9e1ac92b43675ca7cef0f9550acd2afa', | ||
expectedRootKeys: { | ||
prv: 'rprvb047f0d8b29083e1933102983d3c611cbf3364039cf3c985730e242488936070:2f5a0abfcd5889100604b0c22a430c4f9e1ac92b43675ca7cef0f9550acd2afa:049aa12f8beaf88eb1a404e4fc5a7ad290accd5b6bb37fa497f2e3bd56fa5990', | ||
pub: 'rpubf008e38df59581e2851939f035bebbb18755fcb9d3864eb2aaa22be060ede6:2f5a0abfcd5889100604b0c22a430c4f9e1ac92b43675ca7cef0f9550acd2afa', | ||
}, | ||
}, | ||
rootKeys1: { | ||
prv: 'rprvb00584090478b47d1d1bf45ee8bbd012ec3634ec5eb40fb944c22602daac8979:427b2e97eeab94519d08e651b48d3df9326e9b22615f7655ad8c256659ec45af:838b4de99dcaf2392cec3222b29146816b1d3dfc1a7cad0695959a53ec23fa77', | ||
pub: 'rpub6b0de9d546d71d95a04a9cfe0b6b8cd2f5da4961c6170ff5e8b7d27098e3a909:427b2e97eeab94519d08e651b48d3df9326e9b22615f7655ad8c256659ec45af', | ||
derivedPub: '8beba02ca52fcb799134bc5698ee7f2b9e4e254749ea6baa65d7ddfbab82e330', | ||
derivedPrv: | ||
'dd6122533efd21fece9248f54e82b812d16996b47726f8cadc2a20f1ddac89098beba02ca52fcb799134bc5698ee7f2b9e4e254749ea6baa65d7ddfbab82e330', | ||
}, | ||
}; |
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,74 @@ | ||
import assert from 'assert'; | ||
import { EddsaKeyDeriver } from '@bitgo/sdk-core'; | ||
import { data } from '../../resources/eddsaKeyDeriver'; | ||
|
||
describe('EddsaKeyDeriver', () => { | ||
describe('createRootKeys', () => { | ||
it('should create root keys without seed', async () => { | ||
const rootKeys = await EddsaKeyDeriver.createRootKeys(); | ||
|
||
assert.ok(rootKeys.prv); | ||
assert.equal(rootKeys.prv.length, data.rootKeys1.prv.length); | ||
assert.ok(rootKeys.prv.startsWith(EddsaKeyDeriver.ROOT_PRV_KEY_PREFIX)); | ||
assert.ok(rootKeys.pub); | ||
assert.equal(rootKeys.pub.length, data.rootKeys1.pub.length); | ||
assert.ok(rootKeys.pub.startsWith(EddsaKeyDeriver.ROOT_PUB_KEY_PREFIX)); | ||
}); | ||
|
||
it('should create root keys with seed', async () => { | ||
const seed = Buffer.from(data.seed.validSeed, 'hex'); | ||
const rootKeys = await EddsaKeyDeriver.createRootKeys(seed); | ||
|
||
assert.ok(rootKeys.prv); | ||
assert.equal(rootKeys.prv, data.seed.expectedRootKeys.prv); | ||
assert.ok(rootKeys.pub); | ||
assert.equal(rootKeys.pub, data.seed.expectedRootKeys.pub); | ||
}); | ||
|
||
it('should throw for invalid seed', async () => { | ||
const seed = Buffer.from('asdf12f1', 'hex'); | ||
|
||
assert.rejects( | ||
async () => { | ||
await EddsaKeyDeriver.createRootKeys(seed); | ||
}, | ||
{ message: 'Invalid seed' }, | ||
); | ||
}); | ||
}); | ||
|
||
describe('deriveKeyWithSeed', () => { | ||
const seed = 'seed123'; | ||
const expectedPath = 'm/999999/240510315/85914100'; | ||
it('should derive a pub key and path from for root public key with seed', async () => { | ||
const rootPubKey = data.rootKeys1.pub; | ||
|
||
const derivedKey = await EddsaKeyDeriver.deriveKeyWithSeed(rootPubKey, seed); | ||
|
||
assert.equal(derivedKey.key.length, 64); | ||
assert.equal(derivedKey.key, data.rootKeys1.derivedPub); | ||
assert.equal(derivedKey.derivationPath, expectedPath); | ||
}); | ||
|
||
it('should derive a private key and path from for root private key with seed', async () => { | ||
const rootPrvKey = data.rootKeys1.prv; | ||
|
||
const derivedKey = await EddsaKeyDeriver.deriveKeyWithSeed(rootPrvKey, seed); | ||
|
||
assert.equal(derivedKey.key.length, 128); | ||
assert.equal(derivedKey.key, data.rootKeys1.derivedPrv); | ||
assert.equal(derivedKey.derivationPath, expectedPath); | ||
}); | ||
|
||
it('should throw an error for invalid key format', async () => { | ||
const invalidKey = 'invalid:key:format'; | ||
|
||
await assert.rejects( | ||
async () => { | ||
await EddsaKeyDeriver.deriveKeyWithSeed(invalidKey, seed); | ||
}, | ||
{ message: 'Invalid key format' }, | ||
); | ||
}); | ||
}); | ||
}); |
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
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
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
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
Oops, something went wrong.