X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=libs%2Fstellar-util%2Fstellar-util.js;h=008dfe614361a6fccb037a79c2660fa702f47252;hb=6c733477dbaeb521b8b9d25004ee01b74af1529f;hp=1922d5c32513f83f7d34dfd15aac219eea62d87e;hpb=8ffa333bc94699ce1945cf58b24838e73295b028;p=perso%2FImmae%2FProjets%2FCryptomonnaies%2FBIP39.git diff --git a/libs/stellar-util/stellar-util.js b/libs/stellar-util/stellar-util.js index 1922d5c..008dfe6 100644 --- a/libs/stellar-util/stellar-util.js +++ b/libs/stellar-util/stellar-util.js @@ -1,48 +1,16 @@ -const createHmac = require('create-hmac'); const StellarBase = require('stellar-base'); +const edHd = require('ed25519-hd-key'); 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, - }; + getKeypair: function (path, seed) { + const result = edHd.derivePath(path, seed); + return StellarBase.Keypair.fromRawEd25519Seed(result.key); }, - - 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, - }; + dummyNetwork: { + bip32: {public: 0, private: 0}, + messagePrefix: '', + pubKeyHash: 0, + scriptHash: 0, + wif: 0, }, - - 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); - } }