aboutsummaryrefslogtreecommitdiff
path: root/libs
diff options
context:
space:
mode:
authorSuat Özgür <s.oezguer@gmail.com>2018-12-17 01:21:17 +0100
committerSuat Özgür <s.oezguer@gmail.com>2018-12-17 01:21:17 +0100
commit22c443df83bae9c25e80f497cb1a3695c6da5707 (patch)
tree3ff4d3d537d06e7caa3bea6fd3829af88cd56428 /libs
parent8ffa333bc94699ce1945cf58b24838e73295b028 (diff)
downloadBIP39-22c443df83bae9c25e80f497cb1a3695c6da5707.tar.gz
BIP39-22c443df83bae9c25e80f497cb1a3695c6da5707.tar.zst
BIP39-22c443df83bae9c25e80f497cb1a3695c6da5707.zip
adding xlm stellar
Diffstat (limited to 'libs')
-rw-r--r--libs/stellar-util/package-lock.json64
-rw-r--r--libs/stellar-util/package.json8
-rw-r--r--libs/stellar-util/stellar-util.js45
3 files changed, 64 insertions, 53 deletions
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 @@
127 "integrity": "sha512-i47mqjF9UbjxJhxGf+pZ6kSxrnI3wBLlnGI2ArWJ4r0VrvDS7ZYXkprq/pLaBWYq4GM0r4zdHY+NNRqEMU7uew==", 127 "integrity": "sha512-i47mqjF9UbjxJhxGf+pZ6kSxrnI3wBLlnGI2ArWJ4r0VrvDS7ZYXkprq/pLaBWYq4GM0r4zdHY+NNRqEMU7uew==",
128 "optional": true 128 "optional": true
129 }, 129 },
130 "bip39": {
131 "version": "2.5.0",
132 "resolved": "https://registry.npmjs.org/bip39/-/bip39-2.5.0.tgz",
133 "integrity": "sha512-xwIx/8JKoT2+IPJpFEfXoWdYwP7UVAoUxxLNfGCfVowaJE7yg1Y5B1BVPqlUNsBq5/nGwmFkwRJ8xDW4sX8OdA==",
134 "requires": {
135 "create-hash": "^1.1.0",
136 "pbkdf2": "^3.0.9",
137 "randombytes": "^2.0.1",
138 "safe-buffer": "^5.0.1",
139 "unorm": "^1.3.3"
140 }
141 },
130 "bn.js": { 142 "bn.js": {
131 "version": "4.11.8", 143 "version": "4.11.8",
132 "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.8.tgz", 144 "resolved": "https://registry.npmjs.org/bn.js/-/bn.js-4.11.8.tgz",
@@ -345,7 +357,6 @@
345 "version": "1.0.4", 357 "version": "1.0.4",
346 "resolved": "https://registry.npmjs.org/cipher-base/-/cipher-base-1.0.4.tgz", 358 "resolved": "https://registry.npmjs.org/cipher-base/-/cipher-base-1.0.4.tgz",
347 "integrity": "sha512-Kkht5ye6ZGmwv40uUDZztayT2ThLQGfnj/T71N/XzeZeo3nf8foyW7zGTsPYkEya3m5f3cAypH+qe7YOrM1U2Q==", 359 "integrity": "sha512-Kkht5ye6ZGmwv40uUDZztayT2ThLQGfnj/T71N/XzeZeo3nf8foyW7zGTsPYkEya3m5f3cAypH+qe7YOrM1U2Q==",
348 "dev": true,
349 "requires": { 360 "requires": {
350 "inherits": "^2.0.1", 361 "inherits": "^2.0.1",
351 "safe-buffer": "^5.0.1" 362 "safe-buffer": "^5.0.1"
@@ -363,6 +374,12 @@
363 "source-map": "~0.5.3" 374 "source-map": "~0.5.3"
364 } 375 }
365 }, 376 },
377 "commander": {
378 "version": "2.13.0",
379 "resolved": "https://registry.npmjs.org/commander/-/commander-2.13.0.tgz",
380 "integrity": "sha512-MVuS359B+YzaWqjCL/c+22gfryv+mCBPHAv3zyVI2GN8EY6IRP8VwtasXn8jyyhvvq84R4ImN1OKRtcbIasjYA==",
381 "dev": true
382 },
366 "concat-map": { 383 "concat-map": {
367 "version": "0.0.1", 384 "version": "0.0.1",
368 "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", 385 "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
@@ -427,7 +444,6 @@
427 "version": "1.2.0", 444 "version": "1.2.0",
428 "resolved": "http://registry.npmjs.org/create-hash/-/create-hash-1.2.0.tgz", 445 "resolved": "http://registry.npmjs.org/create-hash/-/create-hash-1.2.0.tgz",
429 "integrity": "sha512-z00bCGNHDG8mHAkP7CtT1qVu+bFQUPjYq/4Iv3C3kWjTFV10zIjfSoeqXo9Asws8gwSHDGj/hl2u4OGIjapeCg==", 446 "integrity": "sha512-z00bCGNHDG8mHAkP7CtT1qVu+bFQUPjYq/4Iv3C3kWjTFV10zIjfSoeqXo9Asws8gwSHDGj/hl2u4OGIjapeCg==",
430 "dev": true,
431 "requires": { 447 "requires": {
432 "cipher-base": "^1.0.1", 448 "cipher-base": "^1.0.1",
433 "inherits": "^2.0.1", 449 "inherits": "^2.0.1",
@@ -440,7 +456,6 @@
440 "version": "1.1.7", 456 "version": "1.1.7",
441 "resolved": "http://registry.npmjs.org/create-hmac/-/create-hmac-1.1.7.tgz", 457 "resolved": "http://registry.npmjs.org/create-hmac/-/create-hmac-1.1.7.tgz",
442 "integrity": "sha512-MJG9liiZ+ogc4TzUwuvbER1JRdgvUFSB5+VR/g5h82fGaIRWMWddtKBHi7/sVhfjQZ6SehlyhvQYrcYkaUIpLg==", 458 "integrity": "sha512-MJG9liiZ+ogc4TzUwuvbER1JRdgvUFSB5+VR/g5h82fGaIRWMWddtKBHi7/sVhfjQZ6SehlyhvQYrcYkaUIpLg==",
443 "dev": true,
444 "requires": { 459 "requires": {
445 "cipher-base": "^1.0.3", 460 "cipher-base": "^1.0.3",
446 "create-hash": "^1.1.0", 461 "create-hash": "^1.1.0",
@@ -555,6 +570,16 @@
555 "nan": "^2.0.9" 570 "nan": "^2.0.9"
556 } 571 }
557 }, 572 },
573 "ed25519-hd-key": {
574 "version": "1.0.0",
575 "resolved": "https://registry.npmjs.org/ed25519-hd-key/-/ed25519-hd-key-1.0.0.tgz",
576 "integrity": "sha512-PbL2RemtcV6UzhJv9lCAFraa3V/M8mxlRJlJeqpaRDtFaHObt43x6nIm8/NMc0Wc70NHee4K9x4V9H5T+MM69Q==",
577 "requires": {
578 "bip39": "^2.4.0",
579 "create-hmac": "^1.1.6",
580 "js-nacl": "^1.2.2"
581 }
582 },
558 "elliptic": { 583 "elliptic": {
559 "version": "6.4.1", 584 "version": "6.4.1",
560 "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.4.1.tgz", 585 "resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.4.1.tgz",
@@ -631,7 +656,6 @@
631 "version": "3.0.4", 656 "version": "3.0.4",
632 "resolved": "https://registry.npmjs.org/hash-base/-/hash-base-3.0.4.tgz", 657 "resolved": "https://registry.npmjs.org/hash-base/-/hash-base-3.0.4.tgz",
633 "integrity": "sha1-X8hoaEfs1zSZQDMZprCj8/auSRg=", 658 "integrity": "sha1-X8hoaEfs1zSZQDMZprCj8/auSRg=",
634 "dev": true,
635 "requires": { 659 "requires": {
636 "inherits": "^2.0.1", 660 "inherits": "^2.0.1",
637 "safe-buffer": "^5.0.1" 661 "safe-buffer": "^5.0.1"
@@ -730,6 +754,11 @@
730 "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=", 754 "integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE=",
731 "dev": true 755 "dev": true
732 }, 756 },
757 "js-nacl": {
758 "version": "1.3.2",
759 "resolved": "https://registry.npmjs.org/js-nacl/-/js-nacl-1.3.2.tgz",
760 "integrity": "sha512-XEV2slQ60lLhtL8X+PfFYFfen3b0eg+IU3deWKXKF285nqAf/f24Z15LvlLkVogpAb/9eAxe7o1AtThhKGvQkg=="
761 },
733 "js-xdr": { 762 "js-xdr": {
734 "version": "1.0.5", 763 "version": "1.0.5",
735 "resolved": "https://registry.npmjs.org/js-xdr/-/js-xdr-1.0.5.tgz", 764 "resolved": "https://registry.npmjs.org/js-xdr/-/js-xdr-1.0.5.tgz",
@@ -800,7 +829,6 @@
800 "version": "1.3.5", 829 "version": "1.3.5",
801 "resolved": "https://registry.npmjs.org/md5.js/-/md5.js-1.3.5.tgz", 830 "resolved": "https://registry.npmjs.org/md5.js/-/md5.js-1.3.5.tgz",
802 "integrity": "sha512-xitP+WxNPcTTOgnTJcrhM0xvdPepipPSf3I8EIpGKeFLjt3PlJLIDG3u8EX53ZIubkb+5U2+3rELYpEhHhzdkg==", 831 "integrity": "sha512-xitP+WxNPcTTOgnTJcrhM0xvdPepipPSf3I8EIpGKeFLjt3PlJLIDG3u8EX53ZIubkb+5U2+3rELYpEhHhzdkg==",
803 "dev": true,
804 "requires": { 832 "requires": {
805 "hash-base": "^3.0.0", 833 "hash-base": "^3.0.0",
806 "inherits": "^2.0.1", 834 "inherits": "^2.0.1",
@@ -961,7 +989,6 @@
961 "version": "3.0.17", 989 "version": "3.0.17",
962 "resolved": "https://registry.npmjs.org/pbkdf2/-/pbkdf2-3.0.17.tgz", 990 "resolved": "https://registry.npmjs.org/pbkdf2/-/pbkdf2-3.0.17.tgz",
963 "integrity": "sha512-U/il5MsrZp7mGg3mSQfn742na2T+1/vHDCG5/iTI3X9MKUuYUZVLQhyRsg06mCgDBTd57TxzgZt7P+fYfjRLtA==", 991 "integrity": "sha512-U/il5MsrZp7mGg3mSQfn742na2T+1/vHDCG5/iTI3X9MKUuYUZVLQhyRsg06mCgDBTd57TxzgZt7P+fYfjRLtA==",
964 "dev": true,
965 "requires": { 992 "requires": {
966 "create-hash": "^1.1.2", 993 "create-hash": "^1.1.2",
967 "create-hmac": "^1.1.4", 994 "create-hmac": "^1.1.4",
@@ -1018,7 +1045,6 @@
1018 "version": "2.0.6", 1045 "version": "2.0.6",
1019 "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.0.6.tgz", 1046 "resolved": "https://registry.npmjs.org/randombytes/-/randombytes-2.0.6.tgz",
1020 "integrity": "sha512-CIQ5OFxf4Jou6uOKe9t1AOgqpeU5fd70A8NPdHSGeYXqXsPe6peOwI0cUl88RWZ6sP1vPMV3avd/R6cZ5/sP1A==", 1047 "integrity": "sha512-CIQ5OFxf4Jou6uOKe9t1AOgqpeU5fd70A8NPdHSGeYXqXsPe6peOwI0cUl88RWZ6sP1vPMV3avd/R6cZ5/sP1A==",
1021 "dev": true,
1022 "requires": { 1048 "requires": {
1023 "safe-buffer": "^5.1.0" 1049 "safe-buffer": "^5.1.0"
1024 } 1050 }
@@ -1081,7 +1107,6 @@
1081 "version": "2.0.2", 1107 "version": "2.0.2",
1082 "resolved": "https://registry.npmjs.org/ripemd160/-/ripemd160-2.0.2.tgz", 1108 "resolved": "https://registry.npmjs.org/ripemd160/-/ripemd160-2.0.2.tgz",
1083 "integrity": "sha512-ii4iagi25WusVoiC4B4lq7pbXfAp3D9v5CwfkY33vffw2+pkDjY1D8GaN7spsxvCSx8dkPqOZCEZyfxcmJG2IA==", 1109 "integrity": "sha512-ii4iagi25WusVoiC4B4lq7pbXfAp3D9v5CwfkY33vffw2+pkDjY1D8GaN7spsxvCSx8dkPqOZCEZyfxcmJG2IA==",
1084 "dev": true,
1085 "requires": { 1110 "requires": {
1086 "hash-base": "^3.0.0", 1111 "hash-base": "^3.0.0",
1087 "inherits": "^2.0.1" 1112 "inherits": "^2.0.1"
@@ -1268,6 +1293,24 @@
1268 "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=", 1293 "integrity": "sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c=",
1269 "dev": true 1294 "dev": true
1270 }, 1295 },
1296 "uglify-es": {
1297 "version": "3.3.9",
1298 "resolved": "https://registry.npmjs.org/uglify-es/-/uglify-es-3.3.9.tgz",
1299 "integrity": "sha512-r+MU0rfv4L/0eeW3xZrd16t4NZfK8Ld4SWVglYBb7ez5uXFWHuVRs6xCTrf1yirs9a4j4Y27nn7SRfO6v67XsQ==",
1300 "dev": true,
1301 "requires": {
1302 "commander": "~2.13.0",
1303 "source-map": "~0.6.1"
1304 },
1305 "dependencies": {
1306 "source-map": {
1307 "version": "0.6.1",
1308 "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.6.1.tgz",
1309 "integrity": "sha512-UjgapumWlbMhkBgzT7Ykc5YXUT46F0iKu8SGXq0bcwP5dz/h0Plj6enJqjz1Zbq2l5WaqYnrVbwWOWMyF3F47g==",
1310 "dev": true
1311 }
1312 }
1313 },
1271 "umd": { 1314 "umd": {
1272 "version": "3.0.3", 1315 "version": "3.0.3",
1273 "resolved": "https://registry.npmjs.org/umd/-/umd-3.0.3.tgz", 1316 "resolved": "https://registry.npmjs.org/umd/-/umd-3.0.3.tgz",
@@ -1286,6 +1329,11 @@
1286 "xtend": "^4.0.1" 1329 "xtend": "^4.0.1"
1287 } 1330 }
1288 }, 1331 },
1332 "unorm": {
1333 "version": "1.4.1",
1334 "resolved": "https://registry.npmjs.org/unorm/-/unorm-1.4.1.tgz",
1335 "integrity": "sha1-NkIA1fE2RsqLzURJAnEzVhR5IwA="
1336 },
1289 "url": { 1337 "url": {
1290 "version": "0.11.0", 1338 "version": "0.11.0",
1291 "resolved": "https://registry.npmjs.org/url/-/url-0.11.0.tgz", 1339 "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 @@
1{ 1{
2 "name": "stellar-util", 2 "name": "stellar-util",
3 "version": "0.0.1", 3 "version": "0.0.1",
4 "scripts" :{ 4 "scripts": {
5 "build": "browserify stellar-util.js > ../../src/js/stellar-util.js" 5 "build": "browserify stellar-util.js | uglifyjs -c -m > ../../src/js/stellar-util.js"
6 }, 6 },
7 "dependencies": { 7 "dependencies": {
8 "ed25519-hd-key": "^1.0.0",
8 "stellar-base": "^0.10.0" 9 "stellar-base": "^0.10.0"
9 }, 10 },
10 "devDependencies": { 11 "devDependencies": {
11 "browserify": "^16.2.3" 12 "browserify": "^16.2.3",
13 "uglify-es": "^3.3.9"
12 } 14 }
13} 15}
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 @@
1const createHmac = require('create-hmac');
2const StellarBase = require('stellar-base'); 1const StellarBase = require('stellar-base');
2const edHd = require('ed25519-hd-key');
3 3
4window.stellarUtil = { 4window.stellarUtil = {
5 5 getKeypair: function (path, seed) {
6 HARDENED_OFFSET: 0x80000000, 6 const result = edHd.derivePath(path, seed);
7 ED25519_CURVE: 'ed25519 seed',
8
9 replaceDerive: (val) => val.replace("'", ''),
10
11 getMasterKeyFromSeed: function (seed) {
12 const hmac = createHmac('sha512', this.ED25519_CURVE);
13 const I = hmac.update(Buffer.from(seed, 'hex')).digest();
14 const IL = I.slice(0, 32);
15 const IR = I.slice(32);
16 return {
17 key: IL,
18 chainCode: IR,
19 };
20 },
21
22 CKDPriv: ({key, chainCode}, index) => {
23 const indexBuffer = Buffer.allocUnsafe(4);
24 indexBuffer.writeUInt32BE(index, 0);
25 const data = Buffer.concat([Buffer.alloc(1, 0), key, indexBuffer]);
26 const I = createHmac('sha512', chainCode)
27 .update(data)
28 .digest();
29 const IL = I.slice(0, 32);
30 const IR = I.slice(32);
31 return {
32 key: IL,
33 chainCode: IR,
34 };
35 },
36
37 derivePath: function (path, seed) {
38
39 const {key, chainCode} = this.getMasterKeyFromSeed(seed);
40 const segments = path
41 .split('/')
42 .slice(1)
43 .map(this.replaceDerive)
44 .map(el => parseInt(el, 10));
45 const result = segments.reduce((parentKeys, segment) => this.CKDPriv(parentKeys, segment + this.HARDENED_OFFSET), {key, chainCode});
46 return StellarBase.Keypair.fromRawEd25519Seed(result.key); 7 return StellarBase.Keypair.fromRawEd25519Seed(result.key);
47 } 8 }
48} 9}