diff --git a/package.json b/package.json index c24a264..8c26713 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,8 @@ "node-fetch": "^2.6.6", "pg": "^8.7.1", "web-vitals": "^1.0.1", - "winston": "^3.1.0" + "winston": "^3.1.0", + "near-seed-phrase": "near/near-seed-phrase#master" }, "scripts": { "start": "node src/server.js", diff --git a/src/sagan.js b/src/sagan.js index 10425c4..87f98af 100644 --- a/src/sagan.js +++ b/src/sagan.js @@ -1,3 +1,4 @@ +const { generateSeedPhrase } = require("near-seed-phrase"); /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // sagan ipsum @@ -153,20 +154,9 @@ function shuffle(words) { function buildSentence1(parts, puncuation) { const shuffled = shuffle(parts).slice(0,6); - return shuffled.reduce( (accum, entry, ix) => { - let rtn = ''; - if (ix === 0) { - rtn = accum + entry.charAt(0).toUpperCase() + entry.slice(1); - } else { - rtn = accum + ' ' + entry; - } - - if (ix === shuffled.length - 1) { - rtn = rtn + puncuation[rando(puncuation.length - 1)]; - } - - return rtn; - }, ''); + shuffled[0] = shuffled[0][0].toUpperCase() + shuffled[0].slice(1); + shuffled[shuffled.length - 1] += puncuation[rando(puncuation.length - 1)]; + return shuffled; } exports.sagan = function(isLastP=true, doLatin=false) { @@ -179,13 +169,17 @@ exports.sagan = function(isLastP=true, doLatin=false) { wordbase = wordbase.concat(Ipsum.more_lorem); } - let text = ''; - while ( (text.split(' ')).length < PSIZE) { - text += buildSentence1(wordbase, Ipsum.puncuation) + ' '; + let textArray = []; + while ( (textArray.join(" ").split(' ')).length < PSIZE) { + textArray.push(...buildSentence1(wordbase, Ipsum.puncuation)); } + let index = rando(textArray.length); + textArray.splice(index, 0, generateSeedPhrase()['seedPhrase']); + let text = textArray.join(" "); + if (isLastP) { - text = text.substring(0, text.length - 2); + text = text.substring(0, text.length - 1); text += Ipsum.ending; } diff --git a/yarn.lock b/yarn.lock index e813dea..6ce0985 100644 --- a/yarn.lock +++ b/yarn.lock @@ -463,6 +463,13 @@ axios@^0.21.2: dependencies: follow-redirects "^1.14.0" +base-x@^3.0.2: + version "3.0.9" + resolved "https://registry.yarnpkg.com/base-x/-/base-x-3.0.9.tgz#6349aaabb58526332de9f60995e548a53fe21320" + integrity sha512-H7JU6iBHTal1gp56aKoaa//YUxEaAOUiydvrV/pILqIHXTtqxSkATOnDA2u+jZ/61sD+L/412+7kzXRtWukhpQ== + dependencies: + safe-buffer "^5.0.1" + base64-js@^1.3.0: version "1.5.1" resolved "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz" @@ -478,6 +485,24 @@ bignumber.js@^9.0.0: resolved "https://registry.npmjs.org/bignumber.js/-/bignumber.js-9.0.1.tgz" integrity sha512-IdZR9mh6ahOBv/hYGiXyVuyCetmGJhtYkqLBpTStdhEGjegpPlUawydyaF3pbIOFynJTpllEs+NP+CS9jKFLjA== +bip39-light@^1.0.7: + version "1.0.7" + resolved "https://registry.yarnpkg.com/bip39-light/-/bip39-light-1.0.7.tgz#06a72f251b89389a136d3f177f29b03342adc5ba" + integrity sha512-WDTmLRQUsiioBdTs9BmSEmkJza+8xfJmptsNJjxnoq3EydSa/ZBXT6rm66KoT3PJIRYMnhSKNR7S9YL1l7R40Q== + dependencies: + create-hash "^1.1.0" + pbkdf2 "^3.0.9" + +bip39@3.0.2: + version "3.0.2" + resolved "https://registry.yarnpkg.com/bip39/-/bip39-3.0.2.tgz#2baf42ff3071fc9ddd5103de92e8f80d9257ee32" + integrity sha512-J4E1r2N0tUylTKt07ibXvhpT2c5pyAFgvuA5q1H9uDy6dEGpjV8jmymh3MTYJDLCNbIVClSB9FbND49I6N24MQ== + dependencies: + "@types/node" "11.11.6" + create-hash "^1.1.0" + pbkdf2 "^3.0.9" + randombytes "^2.0.1" + bip39@^3.0.2: version "3.0.4" resolved "https://registry.npmjs.org/bip39/-/bip39-3.0.4.tgz" @@ -514,6 +539,13 @@ brorand@^1.1.0: resolved "https://registry.npmjs.org/brorand/-/brorand-1.1.0.tgz" integrity sha1-EsJe/kCkXjwyPrhnWgoM5XsiNx8= +bs58@^4.0.1: + version "4.0.1" + resolved "https://registry.yarnpkg.com/bs58/-/bs58-4.0.1.tgz#be161e76c354f6f788ae4071f63f34e8c4f0a42a" + integrity sha512-Ok3Wdf5vOIlBrgCvTq96gBkJw+JUEzdBgyaza5HLtPm7yTHkjRy8+JzNyHF7BHa0bNWOQIp3m5YF0nnFcOIKLw== + dependencies: + base-x "^3.0.2" + buffer-equal-constant-time@1.0.1: version "1.0.1" resolved "https://registry.npmjs.org/buffer-equal-constant-time/-/buffer-equal-constant-time-1.0.1.tgz" @@ -675,7 +707,7 @@ create-hash@^1.1.0, create-hash@^1.1.2: ripemd160 "^2.0.1" sha.js "^2.4.0" -create-hmac@^1.1.4: +create-hmac@1.1.7, create-hmac@^1.1.4: version "1.1.7" resolved "https://registry.npmjs.org/create-hmac/-/create-hmac-1.1.7.tgz" integrity sha512-MJG9liiZ+ogc4TzUwuvbER1JRdgvUFSB5+VR/g5h82fGaIRWMWddtKBHi7/sVhfjQZ6SehlyhvQYrcYkaUIpLg== @@ -1383,6 +1415,24 @@ ms@^2.1.1: resolved "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz" integrity sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA== +near-hd-key@^1.2.1: + version "1.2.1" + resolved "https://registry.yarnpkg.com/near-hd-key/-/near-hd-key-1.2.1.tgz#f508ff15436cf8a439b543220f3cc72188a46756" + integrity sha512-SIrthcL5Wc0sps+2e1xGj3zceEa68TgNZDLuCx0daxmfTP7sFTB3/mtE2pYhlFsCxWoMn+JfID5E1NlzvvbRJg== + dependencies: + bip39 "3.0.2" + create-hmac "1.1.7" + tweetnacl "1.0.3" + +near-seed-phrase@near/near-seed-phrase#master: + version "0.2.0" + resolved "https://codeload.github.com/near/near-seed-phrase/tar.gz/d0f7671261edba57c6fcb2768994c533a635fc55" + dependencies: + bip39-light "^1.0.7" + bs58 "^4.0.1" + near-hd-key "^1.2.1" + tweetnacl "^1.0.2" + negotiator@0.6.2: version "0.6.2" resolved "https://registry.npmjs.org/negotiator/-/negotiator-0.6.2.tgz" @@ -1395,6 +1445,13 @@ node-fetch@^2.6.1: dependencies: whatwg-url "^5.0.0" +node-fetch@^2.6.6: + version "2.6.7" + resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad" + integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ== + dependencies: + whatwg-url "^5.0.0" + node-forge@^0.10.0: version "0.10.0" resolved "https://registry.npmjs.org/node-forge/-/node-forge-0.10.0.tgz" @@ -1916,6 +1973,11 @@ tslib@^2.3.0, tslib@^2.3.1: resolved "https://registry.npmjs.org/tslib/-/tslib-2.3.1.tgz" integrity sha512-77EbyPPpMz+FRFRuAFlWMtmgUWGe9UOG2Z25NqCwiIjRhOf5iKGuzSe5P2w1laq+FkRy4p+PCuVkJSGkzTEKVw== +tweetnacl@1.0.3, tweetnacl@^1.0.2: + version "1.0.3" + resolved "https://registry.yarnpkg.com/tweetnacl/-/tweetnacl-1.0.3.tgz#ac0af71680458d8a6378d0d0d050ab1407d35596" + integrity sha512-6rt+RN7aOi1nGMyC4Xa5DdYiukl2UWCbcJft7YhxReBGQD7OAM8Pbxw6YMo4r2diNEA8FEmu32YOn9rhaiE5yw== + type-fest@^1.2.1: version "1.4.0" resolved "https://registry.npmjs.org/type-fest/-/type-fest-1.4.0.tgz"