From 22c443df83bae9c25e80f497cb1a3695c6da5707 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Suat=20=C3=96zg=C3=BCr?= Date: Mon, 17 Dec 2018 01:21:17 +0100 Subject: adding xlm stellar --- libs/stellar-util/package-lock.json | 64 ++++++++++++++++++++++++++++++++----- libs/stellar-util/package.json | 8 +++-- libs/stellar-util/stellar-util.js | 45 ++------------------------ 3 files changed, 64 insertions(+), 53 deletions(-) (limited to 'libs') diff --git a/libs/stellar-util/package-lock.json b/libs/stellar-util/package-lock.json index 0dd4288..5c428ee 100644 --- a/libs/stellar-util/package-lock.json +++ b/libs/stellar-util/package-lock.json @@ -127,6 +127,18 @@ "integrity": "sha512-i47mqjF9UbjxJhxGf+pZ6kSxrnI3wBLlnGI2ArWJ4r0VrvDS7ZYXkprq/pLaBWYq4GM0r4zdHY+NNRqEMU7uew==", "optional": true }, + "bip39": { + "version": "2.5.0", + "resolved": "https://registry.npmjs.org/bip39/-/bip39-2.5.0.tgz", + "integrity": "sha512-xwIx/8JKoT2+IPJpFEfXoWdYwP7UVAoUxxLNfGCfVowaJE7yg1Y5B1BVPqlUNsBq5/nGwmFkwRJ8xDW4sX8OdA==", + "requires": { + "create-hash": "^1.1.0", + "pbkdf2": "^3.0.9", + "randombytes": "^2.0.1", + "safe-buffer": "^5.0.1", + "unorm": "^1.3.3" + } + }, "bn.js": { "version": "4.11.8", "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.8.tgz", @@ -345,7 +357,6 @@ "version": "1.0.4", "resolved": "https://registry.npmjs.org/cipher-base/-/cipher-base-1.0.4.tgz", "integrity": "sha512-Kkht5ye6ZGmwv40uUDZztayT2ThLQGfnj/T71N/XzeZeo3nf8foyW7zGTsPYkEya3m5f3cAypH+qe7YOrM1U2Q==", - "dev": true, "requires": { "inherits": "^2.0.1", "safe-buffer": "^5.0.1" @@ -363,6 +374,12 @@ "source-map": "~0.5.3" } }, + "commander": { + "version": "2.13.0", + "resolved": "https://registry.npmjs.org/commander/-/commander-2.13.0.tgz", + "integrity": "sha512-MVuS359B+YzaWqjCL/c+22gfryv+mCBPHAv3zyVI2GN8EY6IRP8VwtasXn8jyyhvvq84R4ImN1OKRtcbIasjYA==", + "dev": true + }, "concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", @@ -427,7 +444,6 @@ "version": "1.2.0", "resolved": "http://registry.npmjs.org/create-hash/-/create-hash-1.2.0.tgz", "integrity": "sha512-z00bCGNHDG8mHAkP7CtT1qVu+bFQUPjYq/4Iv3C3kWjTFV10zIjfSoeqXo9Asws8gwSHDGj/hl2u4OGIjapeCg==", - "dev": true, "requires": { "cipher-base": "^1.0.1", "inherits": "^2.0.1", @@ -440,7 +456,6 @@ "version": "1.1.7", "resolved": "http://registry.npmjs.org/create-hmac/-/create-hmac-1.1.7.tgz", "integrity": "sha512-MJG9liiZ+ogc4TzUwuvbER1JRdgvUFSB5+VR/g5h82fGaIRWMWddtKBHi7/sVhfjQZ6SehlyhvQYrcYkaUIpLg==", - "dev": true, "requires": { "cipher-base": "^1.0.3", "create-hash": "^1.1.0", @@ -555,6 +570,16 @@ "nan": "^2.0.9" } }, + "ed25519-hd-key": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/ed25519-hd-key/-/ed25519-hd-key-1.0.0.tgz", + "integrity": "sha512-PbL2RemtcV6UzhJv9lCAFraa3V/M8mxlRJlJeqpaRDtFaHObt43x6nIm8/NMc0Wc70NHee4K9x4V9H5T+MM69Q==", + "requires": { + "bip39": "^2.4.0", + "create-hmac": "^1.1.6", + "js-nacl": "^1.2.2" + } + }, "elliptic": { "version": "6.4.1", "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.4.1.tgz", @@ -631,7 +656,6 @@ "version": "3.0.4", "resolved": "https://registry.npmjs.org/hash-base/-/hash-base-3.0.4.tgz", "integrity": "sha1-X8hoaEfs1zSZQDMZprCj8/auSRg=", - "dev": true, "requires": { "inherits": "^2.0.1", "safe-buffer": "^5.0.1" @@ -730,6 +754,11 @@ "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", "dev": true }, + "js-nacl": { + "version": "1.3.2", + "resolved": "https://registry.npmjs.org/js-nacl/-/js-nacl-1.3.2.tgz", + "integrity": "sha512-XEV2slQ60lLhtL8X+PfFYFfen3b0eg+IU3deWKXKF285nqAf/f24Z15LvlLkVogpAb/9eAxe7o1AtThhKGvQkg==" + }, "js-xdr": { "version": "1.0.5", "resolved": "https://registry.npmjs.org/js-xdr/-/js-xdr-1.0.5.tgz", @@ -800,7 +829,6 @@ "version": "1.3.5", "resolved": "https://registry.npmjs.org/md5.js/-/md5.js-1.3.5.tgz", "integrity": "sha512-xitP+WxNPcTTOgnTJcrhM0xvdPepipPSf3I8EIpGKeFLjt3PlJLIDG3u8EX53ZIubkb+5U2+3rELYpEhHhzdkg==", - "dev": true, "requires": { "hash-base": "^3.0.0", "inherits": "^2.0.1", @@ -961,7 +989,6 @@ "version": "3.0.17", "resolved": "https://registry.npmjs.org/pbkdf2/-/pbkdf2-3.0.17.tgz", "integrity": "sha512-U/il5MsrZp7mGg3mSQfn742na2T+1/vHDCG5/iTI3X9MKUuYUZVLQhyRsg06mCgDBTd57TxzgZt7P+fYfjRLtA==", - "dev": true, "requires": { "create-hash": "^1.1.2", "create-hmac": "^1.1.4", @@ -1018,7 +1045,6 @@ "version": "2.0.6", "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.0.6.tgz", "integrity": "sha512-CIQ5OFxf4Jou6uOKe9t1AOgqpeU5fd70A8NPdHSGeYXqXsPe6peOwI0cUl88RWZ6sP1vPMV3avd/R6cZ5/sP1A==", - "dev": true, "requires": { "safe-buffer": "^5.1.0" } @@ -1081,7 +1107,6 @@ "version": "2.0.2", "resolved": "https://registry.npmjs.org/ripemd160/-/ripemd160-2.0.2.tgz", "integrity": "sha512-ii4iagi25WusVoiC4B4lq7pbXfAp3D9v5CwfkY33vffw2+pkDjY1D8GaN7spsxvCSx8dkPqOZCEZyfxcmJG2IA==", - "dev": true, "requires": { "hash-base": "^3.0.0", "inherits": "^2.0.1" @@ -1268,6 +1293,24 @@ "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=", "dev": true }, + "uglify-es": { + "version": "3.3.9", + "resolved": "https://registry.npmjs.org/uglify-es/-/uglify-es-3.3.9.tgz", + "integrity": "sha512-r+MU0rfv4L/0eeW3xZrd16t4NZfK8Ld4SWVglYBb7ez5uXFWHuVRs6xCTrf1yirs9a4j4Y27nn7SRfO6v67XsQ==", + "dev": true, + "requires": { + "commander": "~2.13.0", + "source-map": "~0.6.1" + }, + "dependencies": { + "source-map": { + "version": "0.6.1", + "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz", + "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==", + "dev": true + } + } + }, "umd": { "version": "3.0.3", "resolved": "https://registry.npmjs.org/umd/-/umd-3.0.3.tgz", @@ -1286,6 +1329,11 @@ "xtend": "^4.0.1" } }, + "unorm": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/unorm/-/unorm-1.4.1.tgz", + "integrity": "sha1-NkIA1fE2RsqLzURJAnEzVhR5IwA=" + }, "url": { "version": "0.11.0", "resolved": "https://registry.npmjs.org/url/-/url-0.11.0.tgz", diff --git a/libs/stellar-util/package.json b/libs/stellar-util/package.json index 80bc8a4..676e084 100644 --- a/libs/stellar-util/package.json +++ b/libs/stellar-util/package.json @@ -1,13 +1,15 @@ { "name": "stellar-util", "version": "0.0.1", - "scripts" :{ - "build": "browserify stellar-util.js > ../../src/js/stellar-util.js" + "scripts": { + "build": "browserify stellar-util.js | uglifyjs -c -m > ../../src/js/stellar-util.js" }, "dependencies": { + "ed25519-hd-key": "^1.0.0", "stellar-base": "^0.10.0" }, "devDependencies": { - "browserify": "^16.2.3" + "browserify": "^16.2.3", + "uglify-es": "^3.3.9" } } diff --git a/libs/stellar-util/stellar-util.js b/libs/stellar-util/stellar-util.js index 1922d5c..a95d78d 100644 --- a/libs/stellar-util/stellar-util.js +++ b/libs/stellar-util/stellar-util.js @@ -1,48 +1,9 @@ -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, - }; - }, - - 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}); + getKeypair: function (path, seed) { + const result = edHd.derivePath(path, seed); return StellarBase.Keypair.fromRawEd25519Seed(result.key); } } -- cgit v1.2.3