mirror of
https://github.com/OneKeyHQ/bip39.git
synced 2026-04-05 18:43:47 +00:00
adding xlm stellar
This commit is contained in:
1341
libs/stellar-util/package-lock.json
generated
Normal file
1341
libs/stellar-util/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
13
libs/stellar-util/package.json
Normal file
13
libs/stellar-util/package.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"name": "stellar-util",
|
||||
"version": "0.0.1",
|
||||
"scripts" :{
|
||||
"build": "browserify stellar-util.js > ../../src/js/stellar-util.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"stellar-base": "^0.10.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"browserify": "^16.2.3"
|
||||
}
|
||||
}
|
||||
48
libs/stellar-util/stellar-util.js
Normal file
48
libs/stellar-util/stellar-util.js
Normal file
@@ -0,0 +1,48 @@
|
||||
const createHmac = require('create-hmac');
|
||||
const StellarBase = require('stellar-base');
|
||||
|
||||
window.stellarUtil = {
|
||||
|
||||
HARDENED_OFFSET: 0x80000000,
|
||||
ED25519_CURVE: 'ed25519 seed',
|
||||
|
||||
replaceDerive: (val) => val.replace("'", ''),
|
||||
|
||||
getMasterKeyFromSeed: function (seed) {
|
||||
const hmac = createHmac('sha512', this.ED25519_CURVE);
|
||||
const I = hmac.update(Buffer.from(seed, 'hex')).digest();
|
||||
const IL = I.slice(0, 32);
|
||||
const IR = I.slice(32);
|
||||
return {
|
||||
key: IL,
|
||||
chainCode: IR,
|
||||
};
|
||||
},
|
||||
|
||||
CKDPriv: ({key, chainCode}, index) => {
|
||||
const indexBuffer = Buffer.allocUnsafe(4);
|
||||
indexBuffer.writeUInt32BE(index, 0);
|
||||
const data = Buffer.concat([Buffer.alloc(1, 0), key, indexBuffer]);
|
||||
const I = createHmac('sha512', chainCode)
|
||||
.update(data)
|
||||
.digest();
|
||||
const IL = I.slice(0, 32);
|
||||
const IR = I.slice(32);
|
||||
return {
|
||||
key: IL,
|
||||
chainCode: IR,
|
||||
};
|
||||
},
|
||||
|
||||
derivePath: function (path, seed) {
|
||||
|
||||
const {key, chainCode} = this.getMasterKeyFromSeed(seed);
|
||||
const segments = path
|
||||
.split('/')
|
||||
.slice(1)
|
||||
.map(this.replaceDerive)
|
||||
.map(el => parseInt(el, 10));
|
||||
const result = segments.reduce((parentKeys, segment) => this.CKDPriv(parentKeys, segment + this.HARDENED_OFFSET), {key, chainCode});
|
||||
return StellarBase.Keypair.fromRawEd25519Seed(result.key);
|
||||
}
|
||||
}
|
||||
@@ -888,6 +888,7 @@
|
||||
<script src="js/biginteger.js"></script>
|
||||
<script src="js/zxcvbn.js"></script>
|
||||
<script src="js/entropy.js"></script>
|
||||
<script src="js/stellar-util.js"></script>
|
||||
<script src="js/index.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -808,6 +808,14 @@
|
||||
privkey = ethUtil.addHexPrefix(privkey);
|
||||
pubkey = ethUtil.addHexPrefix(pubkey);
|
||||
}
|
||||
// Stellar is different
|
||||
if (networks[DOM.network.val()].name == "XLM - Stellar") {
|
||||
const path = "m/44'/148'/" + index + "'";
|
||||
const keypair = stellarUtil.derivePath(path, seed);
|
||||
indexText = path;
|
||||
privkey = keypair.secret();
|
||||
pubkey = address = keypair.publicKey();
|
||||
}
|
||||
// Ripple values are different
|
||||
if (networks[DOM.network.val()].name == "XRP - Ripple") {
|
||||
privkey = convertRipplePriv(privkey);
|
||||
@@ -1694,6 +1702,14 @@
|
||||
setHdCoin(1);
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "XLM - Stellar",
|
||||
onSelect: function() {
|
||||
segwitAvailable: false,
|
||||
network = null;
|
||||
setHdCoin(148);
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "XMY - Myriadcoin",
|
||||
segwitAvailable: false,
|
||||
|
||||
41520
src/js/stellar-util.js
Normal file
41520
src/js/stellar-util.js
Normal file
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user