From e0c07d154232ebd7206ead0d50486e9be1fc2867 Mon Sep 17 00:00:00 2001 From: Chris Troutner Date: Thu, 10 Mar 2022 16:45:27 -0800 Subject: [PATCH] feat(ipfs): Removing the ipfs pinning libraries and dependencies --- package-lock.json | 481 ++-------------------------------------------- package.json | 2 - src/bch-js.js | 2 - src/ipfs.js | 454 ------------------------------------------- test/unit/ipfs.js | 443 ------------------------------------------ 5 files changed, 15 insertions(+), 1367 deletions(-) delete mode 100644 src/ipfs.js delete mode 100644 test/unit/ipfs.js diff --git a/package-lock.json b/package-lock.json index ddfbd62..696f1a4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,8 +14,6 @@ "@psf/bitcoincash-ops": "2.0.0", "@psf/bitcoincashjs-lib": "4.0.2", "@psf/coininfo": "4.0.0", - "@uppy/core": "1.10.4", - "@uppy/tus": "1.5.12", "axios": "^0.21.4", "bc-bip68": "1.0.5", "bchaddrjs-slp": "0.2.5", @@ -1047,12 +1045,6 @@ "dev": true, "license": "MIT" }, - "node_modules/@types/tus-js-client": { - "version": "1.8.0", - "resolved": "http://94.130.170.209:4873/@types%2ftus-js-client/-/tus-js-client-1.8.0.tgz", - "integrity": "sha512-lWxu5+6qfyfwsW99GzUeJ9y9JeOSSLduKxgYMvaYM7sGTDKZsrIIHTUbHI2P016xhXtu9NxmUM3GrB4i14ie4A==", - "license": "MIT" - }, "node_modules/@ungap/promise-all-settled": { "version": "1.1.2", "resolved": "http://94.130.170.209:4873/@ungap%2fpromise-all-settled/-/promise-all-settled-1.1.2.tgz", @@ -1060,78 +1052,6 @@ "dev": true, "license": "ISC" }, - "node_modules/@uppy/companion-client": { - "version": "1.8.2", - "resolved": "https://registry.npmjs.org/@uppy/companion-client/-/companion-client-1.8.2.tgz", - "integrity": "sha512-FBjAJU3xaWRqYXDBlrMDQKlRBqi4Ng54Dmnoe3hGSggfgBQAl9RzRAg0WvrGjaK3QjCTZPhzSdTpBrqDP22Rng==", - "dependencies": { - "@uppy/utils": "^3.4.1", - "namespace-emitter": "^2.0.1", - "qs-stringify": "^1.1.0" - } - }, - "node_modules/@uppy/core": { - "version": "1.10.4", - "resolved": "http://94.130.170.209:4873/@uppy%2fcore/-/core-1.10.4.tgz", - "integrity": "sha512-mORSXL4JyXHGo98u6u0sMzv3wtdI5jjHsqyThQAXx3LvctWE0EBrxE7vJqrXue2z/m9lovsZVhuzP2L7Qkuebg==", - "license": "MIT", - "dependencies": { - "@uppy/store-default": "^1.2.1", - "@uppy/utils": "^2.4.4", - "cuid": "^2.1.1", - "lodash.throttle": "^4.1.1", - "mime-match": "^1.0.2", - "namespace-emitter": "^2.0.1", - "preact": "8.2.9" - } - }, - "node_modules/@uppy/core/node_modules/@uppy/utils": { - "version": "2.4.4", - "resolved": "http://94.130.170.209:4873/@uppy%2futils/-/utils-2.4.4.tgz", - "integrity": "sha512-7A0uwK5Rf8XcKqlpNUZ5L5LmkHT5c0/UWjDJGwmzeCxp2lECgzsMC+4vgA6kT4sFzPFbLtUtxHi7ecFwow3NQQ==", - "license": "MIT", - "dependencies": { - "lodash.throttle": "^4.1.1" - } - }, - "node_modules/@uppy/store-default": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/@uppy/store-default/-/store-default-1.2.5.tgz", - "integrity": "sha512-jnf0U8cfb8Bhgt6yh86YRJO9EEnCyG9BgXZ8dPWWLybgC9Expw3Ah/s3T21tcdChgv4zzdhSACd0JKxCQowyYg==" - }, - "node_modules/@uppy/tus": { - "version": "1.5.12", - "resolved": "http://94.130.170.209:4873/@uppy%2ftus/-/tus-1.5.12.tgz", - "integrity": "sha512-jDiwsTRHnMfb83ZB8JdDD0uA9DX0K/FqenGMYBGTOlkCjAcXD3sI59DzEHwq2TtY3ZH7iaL3fTNQ7ExBWkwrqw==", - "license": "MIT", - "dependencies": { - "@types/tus-js-client": "^1.8.0", - "@uppy/companion-client": "^1.4.4", - "@uppy/utils": "^2.4.4", - "tus-js-client": "^1.8.0" - }, - "peerDependencies": { - "@uppy/core": "^1.0.0" - } - }, - "node_modules/@uppy/tus/node_modules/@uppy/utils": { - "version": "2.4.4", - "resolved": "http://94.130.170.209:4873/@uppy%2futils/-/utils-2.4.4.tgz", - "integrity": "sha512-7A0uwK5Rf8XcKqlpNUZ5L5LmkHT5c0/UWjDJGwmzeCxp2lECgzsMC+4vgA6kT4sFzPFbLtUtxHi7ecFwow3NQQ==", - "license": "MIT", - "dependencies": { - "lodash.throttle": "^4.1.1" - } - }, - "node_modules/@uppy/utils": { - "version": "3.4.1", - "resolved": "https://registry.npmjs.org/@uppy/utils/-/utils-3.4.1.tgz", - "integrity": "sha512-9YVKjVRK/AmX3yV0GJsD5p/eHUzqn4+eXzsjv3wHahipKCo0o7Jwpw/7kl+bv12EHOOy5jPsATWkjn40aSWW8w==", - "dependencies": { - "abortcontroller-polyfill": "^1.4.0", - "lodash.throttle": "^4.1.1" - } - }, "node_modules/@webassemblyjs/ast": { "version": "1.11.1", "resolved": "http://94.130.170.209:4873/@webassemblyjs%2fast/-/ast-1.11.1.tgz", @@ -1353,11 +1273,6 @@ "dev": true, "license": "ISC" }, - "node_modules/abortcontroller-polyfill": { - "version": "1.7.1", - "resolved": "https://registry.npmjs.org/abortcontroller-polyfill/-/abortcontroller-polyfill-1.7.1.tgz", - "integrity": "sha512-yml9NiDEH4M4p0G4AcPkg8AAa4mF3nfYF28VQxaokpO67j9H7gWgmsVWJ/f1Rn+PzsnDYvzJzWIQzCqDKRvWlA==" - }, "node_modules/accepts": { "version": "1.3.7", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.7.tgz", @@ -2260,12 +2175,6 @@ "node": ">=0.10.0" } }, - "node_modules/buffer-from": { - "version": "0.1.2", - "resolved": "http://94.130.170.209:4873/buffer-from/-/buffer-from-0.1.2.tgz", - "integrity": "sha512-RiWIenusJsmI2KcvqQABB83tLxCByE3upSP8QU3rJDMVFGPWLvPQJt/O1Su9moRWeH7d+Q2HYb68f6+v+tw2vg==", - "license": "MIT" - }, "node_modules/buffer-xor": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/buffer-xor/-/buffer-xor-1.0.3.tgz", @@ -2659,15 +2568,6 @@ "text-hex": "1.0.x" } }, - "node_modules/combine-errors": { - "version": "3.0.3", - "resolved": "http://94.130.170.209:4873/combine-errors/-/combine-errors-3.0.3.tgz", - "integrity": "sha1-9N9nQAg+VwOjGBEQwrEFUfAD2oY=", - "dependencies": { - "custom-error-instance": "2.1.1", - "lodash.uniqby": "4.5.0" - } - }, "node_modules/combined-stream": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", @@ -2934,17 +2834,6 @@ "node": ">=8" } }, - "node_modules/cuid": { - "version": "2.1.8", - "resolved": "https://registry.npmjs.org/cuid/-/cuid-2.1.8.tgz", - "integrity": "sha512-xiEMER6E7TlTPnDxrM4eRiC6TRgjNX9xzEZ5U/Se2YJKr7Mq4pJn/2XEHjl3STcSh96GmkHPcBXLES8M29wyyg==" - }, - "node_modules/custom-error-instance": { - "version": "2.1.1", - "resolved": "http://94.130.170.209:4873/custom-error-instance/-/custom-error-instance-2.1.1.tgz", - "integrity": "sha1-PPY5FIemYppiR+sMoM4ACBt+Nho=", - "license": "ISC" - }, "node_modules/dashdash": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", @@ -4724,7 +4613,8 @@ "node_modules/extend": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz", - "integrity": "sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==" + "integrity": "sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==", + "dev": true }, "node_modules/extsprintf": { "version": "1.3.0", @@ -5327,6 +5217,7 @@ "version": "4.2.9", "resolved": "http://94.130.170.209:4873/graceful-fs/-/graceful-fs-4.2.9.tgz", "integrity": "sha512-NtNxqUcXgpW2iMrfqSfR73Glt39K+BLwWsPs94yR63v45T0Wbej7eRmL5cWfwEgqXnmjQp3zaJTshdRW/qC2ZQ==", + "dev": true, "license": "ISC" }, "node_modules/growl": { @@ -6631,12 +6522,6 @@ "dev": true, "license": "MIT" }, - "node_modules/js-base64": { - "version": "2.6.4", - "resolved": "http://94.130.170.209:4873/js-base64/-/js-base64-2.6.4.tgz", - "integrity": "sha512-pZe//GGmwJndub7ZghVHz7vjb2LgC1m8B07Au3eYqeqv9emhESByMXxaEgkUkEqJe87oBbSniGYoQNIBklc7IQ==", - "license": "BSD-3-Clause" - }, "node_modules/js-sha256": { "version": "0.9.0", "resolved": "https://registry.npmjs.org/js-sha256/-/js-sha256-0.9.0.tgz", @@ -6994,52 +6879,6 @@ "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", "dev": true }, - "node_modules/lodash._baseiteratee": { - "version": "4.7.0", - "resolved": "http://94.130.170.209:4873/lodash._baseiteratee/-/lodash._baseiteratee-4.7.0.tgz", - "integrity": "sha1-NKm1VDVycnw9sueO2uPA6eZr0QI=", - "license": "MIT", - "dependencies": { - "lodash._stringtopath": "~4.8.0" - } - }, - "node_modules/lodash._basetostring": { - "version": "4.12.0", - "resolved": "http://94.130.170.209:4873/lodash._basetostring/-/lodash._basetostring-4.12.0.tgz", - "integrity": "sha1-kyfJ3FFYhmt/pLnUL0Y45XZt2d8=", - "license": "MIT" - }, - "node_modules/lodash._baseuniq": { - "version": "4.6.0", - "resolved": "http://94.130.170.209:4873/lodash._baseuniq/-/lodash._baseuniq-4.6.0.tgz", - "integrity": "sha1-DrtE5FaBSveQXGIS+iybLVG4Qeg=", - "license": "MIT", - "dependencies": { - "lodash._createset": "~4.0.0", - "lodash._root": "~3.0.0" - } - }, - "node_modules/lodash._createset": { - "version": "4.0.3", - "resolved": "http://94.130.170.209:4873/lodash._createset/-/lodash._createset-4.0.3.tgz", - "integrity": "sha1-D0ZZ+7CddRlPqeK4imZE02PJ/iY=", - "license": "MIT" - }, - "node_modules/lodash._root": { - "version": "3.0.1", - "resolved": "http://94.130.170.209:4873/lodash._root/-/lodash._root-3.0.1.tgz", - "integrity": "sha1-+6HEUkwZ7ppfgTa0YJ8BfPTe1pI=", - "license": "MIT" - }, - "node_modules/lodash._stringtopath": { - "version": "4.8.0", - "resolved": "http://94.130.170.209:4873/lodash._stringtopath/-/lodash._stringtopath-4.8.0.tgz", - "integrity": "sha1-lBvPDmQmbl/B1m/tCmlZVExXaCQ=", - "license": "MIT", - "dependencies": { - "lodash._basetostring": "~4.12.0" - } - }, "node_modules/lodash.capitalize": { "version": "4.2.1", "resolved": "http://94.130.170.209:4873/lodash.capitalize/-/lodash.capitalize-4.2.1.tgz", @@ -7094,11 +6933,6 @@ "dev": true, "license": "MIT" }, - "node_modules/lodash.throttle": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/lodash.throttle/-/lodash.throttle-4.1.1.tgz", - "integrity": "sha1-wj6RtxAkKscMN/HhzaknTMOb8vQ=" - }, "node_modules/lodash.truncate": { "version": "4.4.2", "resolved": "http://94.130.170.209:4873/lodash.truncate/-/lodash.truncate-4.4.2.tgz", @@ -7106,16 +6940,6 @@ "dev": true, "license": "MIT" }, - "node_modules/lodash.uniqby": { - "version": "4.5.0", - "resolved": "http://94.130.170.209:4873/lodash.uniqby/-/lodash.uniqby-4.5.0.tgz", - "integrity": "sha1-o6F7v2LutiQPSRhG6XwcTipeHiE=", - "license": "MIT", - "dependencies": { - "lodash._baseiteratee": "~4.7.0", - "lodash._baseuniq": "~4.6.0" - } - }, "node_modules/log-driver": { "version": "1.2.7", "resolved": "https://registry.npmjs.org/log-driver/-/log-driver-1.2.7.tgz", @@ -7657,14 +7481,6 @@ "node": ">= 0.6" } }, - "node_modules/mime-match": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/mime-match/-/mime-match-1.0.2.tgz", - "integrity": "sha1-P4fDHprxpf1IX7nbE0Qosju7e6g=", - "dependencies": { - "wildcard": "^1.1.0" - } - }, "node_modules/mime-types": { "version": "2.1.28", "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.28.tgz", @@ -8092,11 +7908,6 @@ "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", "dev": true }, - "node_modules/namespace-emitter": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/namespace-emitter/-/namespace-emitter-2.0.1.tgz", - "integrity": "sha512-N/sMKHniSDJBjfrkbS/tpkPj4RAbvW3mr8UAzvlMHyun93XEm83IAvhWtJVHo+RHn/oO8Job5YN4b+wRjSVp5g==" - }, "node_modules/nan": { "version": "2.14.2", "resolved": "https://registry.npmjs.org/nan/-/nan-2.14.2.tgz", @@ -11568,11 +11379,6 @@ "semver-compare": "^1.0.0" } }, - "node_modules/preact": { - "version": "8.2.9", - "resolved": "https://registry.npmjs.org/preact/-/preact-8.2.9.tgz", - "integrity": "sha512-ThuGXBmJS3VsT+jIP+eQufD3L8pRw/PY3FoCys6O9Pu6aF12Pn9zAJDX99TfwRAFOCEKm/P0lwiPTbqKMJp0fA==" - }, "node_modules/prelude-ls": { "version": "1.2.1", "resolved": "http://94.130.170.209:4873/prelude-ls/-/prelude-ls-1.2.1.tgz", @@ -11668,19 +11474,6 @@ "react-is": "^16.8.1" } }, - "node_modules/proper-lockfile": { - "version": "2.0.1", - "resolved": "http://94.130.170.209:4873/proper-lockfile/-/proper-lockfile-2.0.1.tgz", - "integrity": "sha1-FZ+wYZPTIAP0s2kd0uwaY0qoDR0=", - "license": "MIT", - "dependencies": { - "graceful-fs": "^4.1.2", - "retry": "^0.10.0" - }, - "engines": { - "node": ">=4.0.0" - } - }, "node_modules/psl": { "version": "1.8.0", "resolved": "https://registry.npmjs.org/psl/-/psl-1.8.0.tgz", @@ -11745,15 +11538,11 @@ "node": ">=0.6" } }, - "node_modules/qs-stringify": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/qs-stringify/-/qs-stringify-1.2.1.tgz", - "integrity": "sha512-2N5xGLGZUxpgAYq1fD1LmBSCbxQVsXYt5JU0nU3FuPWO8PlCnKNFQwXkZgyB6mrTdg7IbexX4wxIR403dJw9pw==" - }, "node_modules/querystringify": { "version": "2.2.0", "resolved": "http://94.130.170.209:4873/querystringify/-/querystringify-2.2.0.tgz", "integrity": "sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==", + "dev": true, "license": "MIT" }, "node_modules/queue-microtask": { @@ -12135,6 +11924,7 @@ "version": "1.0.0", "resolved": "http://94.130.170.209:4873/requires-port/-/requires-port-1.0.0.tgz", "integrity": "sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8=", + "dev": true, "license": "MIT" }, "node_modules/resolve": { @@ -12186,15 +11976,6 @@ "through": "~2.3.4" } }, - "node_modules/retry": { - "version": "0.10.1", - "resolved": "http://94.130.170.209:4873/retry/-/retry-0.10.1.tgz", - "integrity": "sha1-52OI0heZLCUnUCQdPTlW/tmNj/Q=", - "license": "MIT", - "engines": { - "node": "*" - } - }, "node_modules/reusify": { "version": "1.0.4", "resolved": "http://94.130.170.209:4873/reusify/-/reusify-1.0.4.tgz", @@ -14140,21 +13921,6 @@ "node": "*" } }, - "node_modules/tus-js-client": { - "version": "1.8.0", - "resolved": "http://94.130.170.209:4873/tus-js-client/-/tus-js-client-1.8.0.tgz", - "integrity": "sha512-qPX3TywqzxocTxUZtcS8X7Aik72SVMa0jKi4hWyfvRV+s9raVzzYGaP4MoJGaF0yOgm2+b6jXaVEHogxcJ8LGw==", - "license": "MIT", - "dependencies": { - "buffer-from": "^0.1.1", - "combine-errors": "^3.0.3", - "extend": "^3.0.2", - "js-base64": "^2.4.9", - "lodash.throttle": "^4.1.1", - "proper-lockfile": "^2.0.1", - "url-parse": "^1.4.3" - } - }, "node_modules/tweetnacl": { "version": "0.14.5", "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz", @@ -14433,6 +14199,7 @@ "version": "1.5.10", "resolved": "http://94.130.170.209:4873/url-parse/-/url-parse-1.5.10.tgz", "integrity": "sha512-WypcfiRhfeUP9vvF0j6rw0J3hrWrw6iZv3+22h6iRMJ/8z1Tj6XfLP4DsUix5MhMPnXpiHDoKyoZ/bdCkwBCiQ==", + "dev": true, "license": "MIT", "dependencies": { "querystringify": "^2.1.1", @@ -14796,11 +14563,6 @@ "bs58check": "<3.0.0" } }, - "node_modules/wildcard": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/wildcard/-/wildcard-1.1.2.tgz", - "integrity": "sha1-pwIEUwhNjNLv5wup02liY94XEKU=" - }, "node_modules/winston": { "version": "3.3.3", "resolved": "https://registry.npmjs.org/winston/-/winston-3.3.3.tgz", @@ -15886,86 +15648,12 @@ "integrity": "sha512-xoDlM2S4ortawSWORYqsdU+2rxdh4LRW9ytc3zmT37RIKQh6IHyKwwtKhKis9ah8ol07DCkZxPt8BBvPjC6v4g==", "dev": true }, - "@types/tus-js-client": { - "version": "1.8.0", - "resolved": "http://94.130.170.209:4873/@types%2ftus-js-client/-/tus-js-client-1.8.0.tgz", - "integrity": "sha512-lWxu5+6qfyfwsW99GzUeJ9y9JeOSSLduKxgYMvaYM7sGTDKZsrIIHTUbHI2P016xhXtu9NxmUM3GrB4i14ie4A==" - }, "@ungap/promise-all-settled": { "version": "1.1.2", "resolved": "http://94.130.170.209:4873/@ungap%2fpromise-all-settled/-/promise-all-settled-1.1.2.tgz", "integrity": "sha512-sL/cEvJWAnClXw0wHk85/2L0G6Sj8UB0Ctc1TEMbKSsmpRosqhwj9gWgFRZSrBr2f9tiXISwNhCPmlfqUqyb9Q==", "dev": true }, - "@uppy/companion-client": { - "version": "1.8.2", - "resolved": "https://registry.npmjs.org/@uppy/companion-client/-/companion-client-1.8.2.tgz", - "integrity": "sha512-FBjAJU3xaWRqYXDBlrMDQKlRBqi4Ng54Dmnoe3hGSggfgBQAl9RzRAg0WvrGjaK3QjCTZPhzSdTpBrqDP22Rng==", - "requires": { - "@uppy/utils": "^3.4.1", - "namespace-emitter": "^2.0.1", - "qs-stringify": "^1.1.0" - } - }, - "@uppy/core": { - "version": "1.10.4", - "resolved": "http://94.130.170.209:4873/@uppy%2fcore/-/core-1.10.4.tgz", - "integrity": "sha512-mORSXL4JyXHGo98u6u0sMzv3wtdI5jjHsqyThQAXx3LvctWE0EBrxE7vJqrXue2z/m9lovsZVhuzP2L7Qkuebg==", - "requires": { - "@uppy/store-default": "^1.2.1", - "@uppy/utils": "^2.4.4", - "cuid": "^2.1.1", - "lodash.throttle": "^4.1.1", - "mime-match": "^1.0.2", - "namespace-emitter": "^2.0.1", - "preact": "8.2.9" - }, - "dependencies": { - "@uppy/utils": { - "version": "2.4.4", - "resolved": "http://94.130.170.209:4873/@uppy%2futils/-/utils-2.4.4.tgz", - "integrity": "sha512-7A0uwK5Rf8XcKqlpNUZ5L5LmkHT5c0/UWjDJGwmzeCxp2lECgzsMC+4vgA6kT4sFzPFbLtUtxHi7ecFwow3NQQ==", - "requires": { - "lodash.throttle": "^4.1.1" - } - } - } - }, - "@uppy/store-default": { - "version": "1.2.5", - "resolved": "https://registry.npmjs.org/@uppy/store-default/-/store-default-1.2.5.tgz", - "integrity": "sha512-jnf0U8cfb8Bhgt6yh86YRJO9EEnCyG9BgXZ8dPWWLybgC9Expw3Ah/s3T21tcdChgv4zzdhSACd0JKxCQowyYg==" - }, - "@uppy/tus": { - "version": "1.5.12", - "resolved": "http://94.130.170.209:4873/@uppy%2ftus/-/tus-1.5.12.tgz", - "integrity": "sha512-jDiwsTRHnMfb83ZB8JdDD0uA9DX0K/FqenGMYBGTOlkCjAcXD3sI59DzEHwq2TtY3ZH7iaL3fTNQ7ExBWkwrqw==", - "requires": { - "@types/tus-js-client": "^1.8.0", - "@uppy/companion-client": "^1.4.4", - "@uppy/utils": "^2.4.4", - "tus-js-client": "^1.8.0" - }, - "dependencies": { - "@uppy/utils": { - "version": "2.4.4", - "resolved": "http://94.130.170.209:4873/@uppy%2futils/-/utils-2.4.4.tgz", - "integrity": "sha512-7A0uwK5Rf8XcKqlpNUZ5L5LmkHT5c0/UWjDJGwmzeCxp2lECgzsMC+4vgA6kT4sFzPFbLtUtxHi7ecFwow3NQQ==", - "requires": { - "lodash.throttle": "^4.1.1" - } - } - } - }, - "@uppy/utils": { - "version": "3.4.1", - "resolved": "https://registry.npmjs.org/@uppy/utils/-/utils-3.4.1.tgz", - "integrity": "sha512-9YVKjVRK/AmX3yV0GJsD5p/eHUzqn4+eXzsjv3wHahipKCo0o7Jwpw/7kl+bv12EHOOy5jPsATWkjn40aSWW8w==", - "requires": { - "abortcontroller-polyfill": "^1.4.0", - "lodash.throttle": "^4.1.1" - } - }, "@webassemblyjs/ast": { "version": "1.11.1", "resolved": "http://94.130.170.209:4873/@webassemblyjs%2fast/-/ast-1.11.1.tgz", @@ -16153,11 +15841,6 @@ "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==", "dev": true }, - "abortcontroller-polyfill": { - "version": "1.7.1", - "resolved": "https://registry.npmjs.org/abortcontroller-polyfill/-/abortcontroller-polyfill-1.7.1.tgz", - "integrity": "sha512-yml9NiDEH4M4p0G4AcPkg8AAa4mF3nfYF28VQxaokpO67j9H7gWgmsVWJ/f1Rn+PzsnDYvzJzWIQzCqDKRvWlA==" - }, "accepts": { "version": "1.3.7", "resolved": "https://registry.npmjs.org/accepts/-/accepts-1.3.7.tgz", @@ -16825,11 +16508,6 @@ "resolved": "https://registry.npmjs.org/buffer-equals/-/buffer-equals-1.0.4.tgz", "integrity": "sha1-A1O1T9B/2VZBcGca5vZrnPENJ/U=" }, - "buffer-from": { - "version": "0.1.2", - "resolved": "http://94.130.170.209:4873/buffer-from/-/buffer-from-0.1.2.tgz", - "integrity": "sha512-RiWIenusJsmI2KcvqQABB83tLxCByE3upSP8QU3rJDMVFGPWLvPQJt/O1Su9moRWeH7d+Q2HYb68f6+v+tw2vg==" - }, "buffer-xor": { "version": "1.0.3", "resolved": "https://registry.npmjs.org/buffer-xor/-/buffer-xor-1.0.3.tgz", @@ -17130,15 +16808,6 @@ "text-hex": "1.0.x" } }, - "combine-errors": { - "version": "3.0.3", - "resolved": "http://94.130.170.209:4873/combine-errors/-/combine-errors-3.0.3.tgz", - "integrity": "sha1-9N9nQAg+VwOjGBEQwrEFUfAD2oY=", - "requires": { - "custom-error-instance": "2.1.1", - "lodash.uniqby": "4.5.0" - } - }, "combined-stream": { "version": "1.0.8", "resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz", @@ -17350,16 +17019,6 @@ "integrity": "sha512-v1plID3y9r/lPhviJ1wrXpLeyUIGAZ2SHNYTEapm7/8A9nLPoyvVp3RK/EPFqn5kEznyWgYZNsRtYYIWbuG8KA==", "dev": true }, - "cuid": { - "version": "2.1.8", - "resolved": "https://registry.npmjs.org/cuid/-/cuid-2.1.8.tgz", - "integrity": "sha512-xiEMER6E7TlTPnDxrM4eRiC6TRgjNX9xzEZ5U/Se2YJKr7Mq4pJn/2XEHjl3STcSh96GmkHPcBXLES8M29wyyg==" - }, - "custom-error-instance": { - "version": "2.1.1", - "resolved": "http://94.130.170.209:4873/custom-error-instance/-/custom-error-instance-2.1.1.tgz", - "integrity": "sha1-PPY5FIemYppiR+sMoM4ACBt+Nho=" - }, "dashdash": { "version": "1.14.1", "resolved": "https://registry.npmjs.org/dashdash/-/dashdash-1.14.1.tgz", @@ -18556,7 +18215,8 @@ "extend": { "version": "3.0.2", "resolved": "https://registry.npmjs.org/extend/-/extend-3.0.2.tgz", - "integrity": "sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==" + "integrity": "sha512-fjquC59cD7CyW6urNXK0FBufkZcoiGG80wTuPujX590cB5Ttln20E2UB4S/WARVqhXffZl2LNgS+gQdPIIim/g==", + "dev": true }, "extsprintf": { "version": "1.3.0", @@ -19018,7 +18678,8 @@ "graceful-fs": { "version": "4.2.9", "resolved": "http://94.130.170.209:4873/graceful-fs/-/graceful-fs-4.2.9.tgz", - "integrity": "sha512-NtNxqUcXgpW2iMrfqSfR73Glt39K+BLwWsPs94yR63v45T0Wbej7eRmL5cWfwEgqXnmjQp3zaJTshdRW/qC2ZQ==" + "integrity": "sha512-NtNxqUcXgpW2iMrfqSfR73Glt39K+BLwWsPs94yR63v45T0Wbej7eRmL5cWfwEgqXnmjQp3zaJTshdRW/qC2ZQ==", + "dev": true }, "growl": { "version": "1.10.5", @@ -19925,11 +19586,6 @@ "integrity": "sha512-JVzAR/AjBvVt2BmYhxRCSYysDsPcssdmTFnzyLEts9qNwmjmu4JTAMYubEfwVOSwpQ1I1sKKFcxhZCI2buerfw==", "dev": true }, - "js-base64": { - "version": "2.6.4", - "resolved": "http://94.130.170.209:4873/js-base64/-/js-base64-2.6.4.tgz", - "integrity": "sha512-pZe//GGmwJndub7ZghVHz7vjb2LgC1m8B07Au3eYqeqv9emhESByMXxaEgkUkEqJe87oBbSniGYoQNIBklc7IQ==" - }, "js-sha256": { "version": "0.9.0", "resolved": "https://registry.npmjs.org/js-sha256/-/js-sha256-0.9.0.tgz", @@ -20207,46 +19863,6 @@ "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", "dev": true }, - "lodash._baseiteratee": { - "version": "4.7.0", - "resolved": "http://94.130.170.209:4873/lodash._baseiteratee/-/lodash._baseiteratee-4.7.0.tgz", - "integrity": "sha1-NKm1VDVycnw9sueO2uPA6eZr0QI=", - "requires": { - "lodash._stringtopath": "~4.8.0" - } - }, - "lodash._basetostring": { - "version": "4.12.0", - "resolved": "http://94.130.170.209:4873/lodash._basetostring/-/lodash._basetostring-4.12.0.tgz", - "integrity": "sha1-kyfJ3FFYhmt/pLnUL0Y45XZt2d8=" - }, - "lodash._baseuniq": { - "version": "4.6.0", - "resolved": "http://94.130.170.209:4873/lodash._baseuniq/-/lodash._baseuniq-4.6.0.tgz", - "integrity": "sha1-DrtE5FaBSveQXGIS+iybLVG4Qeg=", - "requires": { - "lodash._createset": "~4.0.0", - "lodash._root": "~3.0.0" - } - }, - "lodash._createset": { - "version": "4.0.3", - "resolved": "http://94.130.170.209:4873/lodash._createset/-/lodash._createset-4.0.3.tgz", - "integrity": "sha1-D0ZZ+7CddRlPqeK4imZE02PJ/iY=" - }, - "lodash._root": { - "version": "3.0.1", - "resolved": "http://94.130.170.209:4873/lodash._root/-/lodash._root-3.0.1.tgz", - "integrity": "sha1-+6HEUkwZ7ppfgTa0YJ8BfPTe1pI=" - }, - "lodash._stringtopath": { - "version": "4.8.0", - "resolved": "http://94.130.170.209:4873/lodash._stringtopath/-/lodash._stringtopath-4.8.0.tgz", - "integrity": "sha1-lBvPDmQmbl/B1m/tCmlZVExXaCQ=", - "requires": { - "lodash._basetostring": "~4.12.0" - } - }, "lodash.capitalize": { "version": "4.2.1", "resolved": "http://94.130.170.209:4873/lodash.capitalize/-/lodash.capitalize-4.2.1.tgz", @@ -20295,26 +19911,12 @@ "integrity": "sha1-1SfftUVuynzJu5XV2ur4i6VKVFE=", "dev": true }, - "lodash.throttle": { - "version": "4.1.1", - "resolved": "https://registry.npmjs.org/lodash.throttle/-/lodash.throttle-4.1.1.tgz", - "integrity": "sha1-wj6RtxAkKscMN/HhzaknTMOb8vQ=" - }, "lodash.truncate": { "version": "4.4.2", "resolved": "http://94.130.170.209:4873/lodash.truncate/-/lodash.truncate-4.4.2.tgz", "integrity": "sha1-WjUNoLERO4N+z//VgSy+WNbq4ZM=", "dev": true }, - "lodash.uniqby": { - "version": "4.5.0", - "resolved": "http://94.130.170.209:4873/lodash.uniqby/-/lodash.uniqby-4.5.0.tgz", - "integrity": "sha1-o6F7v2LutiQPSRhG6XwcTipeHiE=", - "requires": { - "lodash._baseiteratee": "~4.7.0", - "lodash._baseuniq": "~4.6.0" - } - }, "log-driver": { "version": "1.2.7", "resolved": "https://registry.npmjs.org/log-driver/-/log-driver-1.2.7.tgz", @@ -20694,14 +20296,6 @@ "integrity": "sha512-CkqLUxUk15hofLoLyljJSrukZi8mAtgd+yE5uO4tqRZsdsAJKv0O+rFMhVDRJgozy+yG6md5KwuXhD4ocIoP+w==", "dev": true }, - "mime-match": { - "version": "1.0.2", - "resolved": "https://registry.npmjs.org/mime-match/-/mime-match-1.0.2.tgz", - "integrity": "sha1-P4fDHprxpf1IX7nbE0Qosju7e6g=", - "requires": { - "wildcard": "^1.1.0" - } - }, "mime-types": { "version": "2.1.28", "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.28.tgz", @@ -20990,11 +20584,6 @@ "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==", "dev": true }, - "namespace-emitter": { - "version": "2.0.1", - "resolved": "https://registry.npmjs.org/namespace-emitter/-/namespace-emitter-2.0.1.tgz", - "integrity": "sha512-N/sMKHniSDJBjfrkbS/tpkPj4RAbvW3mr8UAzvlMHyun93XEm83IAvhWtJVHo+RHn/oO8Job5YN4b+wRjSVp5g==" - }, "nan": { "version": "2.14.2", "resolved": "https://registry.npmjs.org/nan/-/nan-2.14.2.tgz", @@ -23465,11 +23054,6 @@ "semver-compare": "^1.0.0" } }, - "preact": { - "version": "8.2.9", - "resolved": "https://registry.npmjs.org/preact/-/preact-8.2.9.tgz", - "integrity": "sha512-ThuGXBmJS3VsT+jIP+eQufD3L8pRw/PY3FoCys6O9Pu6aF12Pn9zAJDX99TfwRAFOCEKm/P0lwiPTbqKMJp0fA==" - }, "prelude-ls": { "version": "1.2.1", "resolved": "http://94.130.170.209:4873/prelude-ls/-/prelude-ls-1.2.1.tgz", @@ -23536,15 +23120,6 @@ "react-is": "^16.8.1" } }, - "proper-lockfile": { - "version": "2.0.1", - "resolved": "http://94.130.170.209:4873/proper-lockfile/-/proper-lockfile-2.0.1.tgz", - "integrity": "sha1-FZ+wYZPTIAP0s2kd0uwaY0qoDR0=", - "requires": { - "graceful-fs": "^4.1.2", - "retry": "^0.10.0" - } - }, "psl": { "version": "1.8.0", "resolved": "https://registry.npmjs.org/psl/-/psl-1.8.0.tgz", @@ -23593,15 +23168,11 @@ "resolved": "https://registry.npmjs.org/qs/-/qs-6.9.6.tgz", "integrity": "sha512-TIRk4aqYLNoJUbd+g2lEdz5kLWIuTMRagAXxl78Q0RiVjAOugHmeKNGdd3cwo/ktpf9aL9epCfFqWDEKysUlLQ==" }, - "qs-stringify": { - "version": "1.2.1", - "resolved": "https://registry.npmjs.org/qs-stringify/-/qs-stringify-1.2.1.tgz", - "integrity": "sha512-2N5xGLGZUxpgAYq1fD1LmBSCbxQVsXYt5JU0nU3FuPWO8PlCnKNFQwXkZgyB6mrTdg7IbexX4wxIR403dJw9pw==" - }, "querystringify": { "version": "2.2.0", "resolved": "http://94.130.170.209:4873/querystringify/-/querystringify-2.2.0.tgz", - "integrity": "sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==" + "integrity": "sha512-FIqgj2EUvTa7R50u0rGsyTftzjYmv/a3hO345bZNrqabNqjtgiDMgmo4mkUjd+nzU5oF3dClKqFIPUKybUyqoQ==", + "dev": true }, "queue-microtask": { "version": "1.2.3", @@ -23875,7 +23446,8 @@ "requires-port": { "version": "1.0.0", "resolved": "http://94.130.170.209:4873/requires-port/-/requires-port-1.0.0.tgz", - "integrity": "sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8=" + "integrity": "sha1-kl0mAdOaxIXgkc8NpcbmlNw9yv8=", + "dev": true }, "resolve": { "version": "1.20.0", @@ -23918,11 +23490,6 @@ "through": "~2.3.4" } }, - "retry": { - "version": "0.10.1", - "resolved": "http://94.130.170.209:4873/retry/-/retry-0.10.1.tgz", - "integrity": "sha1-52OI0heZLCUnUCQdPTlW/tmNj/Q=" - }, "reusify": { "version": "1.0.4", "resolved": "http://94.130.170.209:4873/reusify/-/reusify-1.0.4.tgz", @@ -25381,20 +24948,6 @@ "safe-buffer": "^5.0.1" } }, - "tus-js-client": { - "version": "1.8.0", - "resolved": "http://94.130.170.209:4873/tus-js-client/-/tus-js-client-1.8.0.tgz", - "integrity": "sha512-qPX3TywqzxocTxUZtcS8X7Aik72SVMa0jKi4hWyfvRV+s9raVzzYGaP4MoJGaF0yOgm2+b6jXaVEHogxcJ8LGw==", - "requires": { - "buffer-from": "^0.1.1", - "combine-errors": "^3.0.3", - "extend": "^3.0.2", - "js-base64": "^2.4.9", - "lodash.throttle": "^4.1.1", - "proper-lockfile": "^2.0.1", - "url-parse": "^1.4.3" - } - }, "tweetnacl": { "version": "0.14.5", "resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz", @@ -25598,6 +25151,7 @@ "version": "1.5.10", "resolved": "http://94.130.170.209:4873/url-parse/-/url-parse-1.5.10.tgz", "integrity": "sha512-WypcfiRhfeUP9vvF0j6rw0J3hrWrw6iZv3+22h6iRMJ/8z1Tj6XfLP4DsUix5MhMPnXpiHDoKyoZ/bdCkwBCiQ==", + "dev": true, "requires": { "querystringify": "^2.1.1", "requires-port": "^1.0.0" @@ -25877,11 +25431,6 @@ "bs58check": "<3.0.0" } }, - "wildcard": { - "version": "1.1.2", - "resolved": "https://registry.npmjs.org/wildcard/-/wildcard-1.1.2.tgz", - "integrity": "sha1-pwIEUwhNjNLv5wup02liY94XEKU=" - }, "winston": { "version": "3.3.3", "resolved": "https://registry.npmjs.org/winston/-/winston-3.3.3.tgz", diff --git a/package.json b/package.json index 1449ad6..b779abe 100644 --- a/package.json +++ b/package.json @@ -42,8 +42,6 @@ "@psf/bitcoincash-ops": "2.0.0", "@psf/bitcoincashjs-lib": "4.0.2", "@psf/coininfo": "4.0.0", - "@uppy/core": "1.10.4", - "@uppy/tus": "1.5.12", "axios": "^0.21.4", "bc-bip68": "1.0.5", "bchaddrjs-slp": "0.2.5", diff --git a/src/bch-js.js b/src/bch-js.js index ce04a72..612c83e 100644 --- a/src/bch-js.js +++ b/src/bch-js.js @@ -28,7 +28,6 @@ const Script = require('./script') const Price = require('./price') const Schnorr = require('./schnorr') const SLP = require('./slp/slp') -const IPFS = require('./ipfs') const Encryption = require('./encryption') const Utxo = require('./utxo') const Transaction = require('./transaction') @@ -111,7 +110,6 @@ class BCHJS { this.SLP = new SLP(libConfig) this.SLP.HDNode = this.HDNode - this.IPFS = new IPFS() this.Utxo = new Utxo(libConfig) this.Transaction = new Transaction(libConfig) diff --git a/src/ipfs.js b/src/ipfs.js deleted file mode 100644 index 48285cb..0000000 --- a/src/ipfs.js +++ /dev/null @@ -1,454 +0,0 @@ -/* - This library interacts with the IPFS REST API at FullStack.cash for uploading - and downloading data from the IPFS network. -*/ - -const axios = require('axios') -const Uppy = require('@uppy/core') -const Tus = require('@uppy/tus') -const fs = require('fs') - -let _this - -class IPFS { - constructor (config) { - this.IPFS_API = process.env.IPFS_API - ? process.env.IPFS_API - : 'https://ipfs-file-upload.fullstackcash.nl' - // : `http://localhost:5001` - - // Default options when calling axios. - this.axiosOptions = { - headers: { - // authorization: `Token ${this.apiToken}`, - timeout: 15000 // Timeout if the server does not respond in time. - } - } - - _this = this - - _this.axios = axios - _this.fs = fs - - // Initialize Uppy - _this.uppy = _this.initUppy() - } - - // Initializes Uppy, which is used for file uploads. - initUppy () { - const uppy = Uppy({ - allowMultipleUploads: false, - meta: { test: 'avatar' }, - debug: false, - restrictions: { - maxFileSize: null, - maxNumberOfFiles: 1, - minNumberOfFiles: 1, - allowedFileTypes: null // type of files allowed to load - } - }) - uppy.use(Tus, { endpoint: `${_this.IPFS_API}/uppy-files` }) - - return uppy - } - - /** - * @api IPFS.createFileModelServer() createFileModelServer() - * @apiName createFileModelServer() - * @apiGroup IPFS - * @apiDescription Creates a new model on the server. If successful, will - * return an object with file data. That object contains a BCH address, - * payment amount, and _id required to be able to upload a file. - * - * @apiExample Example usage: - * (async () => { - * try { - * const path = `${__dirname}/ipfs.js` - * let fileData = await bchjs.IPFS.createFileModelServer(path); - * console.log(fileData); - * } catch(error) { - * console.error(error) - * } - * })() - * - * { - * "success": true, - * "hostingCostBCH": 0.00004197, - * "hostingCostUSD": 0.01, - * "file": { - * "payloadLink": "", - * "hasBeenPaid": false, - * "_id": "5ec562319bfacc745e8d8a52", - * "schemaVersion": 1, - * "size": 4458, - * "fileName": "ipfs.js", - * "fileExtension": "js", - * "createdTimestamp": "1589994033.655", - * "hostingCost": 4196, - * "walletIndex": 49, - * "bchAddr": "bchtest:qzrpkevu7h2ayfa4rjx08r5elvpfu72dg567x3mh3c", - * "__v": 0 - * } - */ - async createFileModelServer (path) { - try { - // Ensure the file exists. - if (!_this.fs.existsSync(path)) { - throw new Error(`Could not find this file: ${path}`) - } - - // Read in the file. - const fileBuf = _this.fs.readFileSync(path) - // console.log(`fileBuf: `, fileBuf) - - // console.log(`Buffer length: ${fileBuf.length}`) - - // Get the file name from the path. - const splitPath = path.split('/') - const fileName = splitPath[splitPath.length - 1] - - // Get the file extension. - const splitExt = fileName.split('.') - const fileExt = splitExt[splitExt.length - 1] - - const fileObj = { - schemaVersion: 1, - size: fileBuf.length, - fileName: fileName, - fileExtension: fileExt - } - // console.log(`fileObj: ${JSON.stringify(fileObj, null, 2)}`) - - const fileData = await _this.axios.post(`${this.IPFS_API}/files`, { - file: fileObj - }) - // console.log(`fileData.data: ${JSON.stringify(fileData.data, null, 2)}`) - - return fileData.data - } catch (err) { - console.error('Error in createFileModel()') - throw err - } - } - - /** - * @api IPFS.uploadFileServer() uploadFileServer() - * @apiName uploadFile() - * @apiGroup IPFS - * @apiDescription Upload a file to the FullStack.cash IPFS server. If - * successful, it will return an object with an ID, a BCH address, and an - * amount of BCH to pay. - * - * @apiExample Example usage: - * (async () => { - * try { - * const path = `${__dirname}/ipfs.js` - * let fileData = await bchjs.IPFS.uploadFileServer(path, "5ec562319bfacc745e8d8a52"); - * console.log(fileData); - * } catch(error) { - * console.error(error) - * } - * })() - * - * { - * "schemaVersion": 1, - * "size": 2374, - * "fileId": "5ec562319bfacc745e8d8a52", - * "fileName": "ipfs.js", - * "fileExtension": "js" - * } - */ - async uploadFileServer (path, modelId) { - try { - // Ensure the file exists. - if (!_this.fs.existsSync(path)) { - throw new Error(`Could not find this file: ${path}`) - } - - if (!modelId) { - throw new Error( - 'Must include a file model ID in order to upload a file.' - ) - } - - // Read in the file. - const fileBuf = _this.fs.readFileSync(path) - - // Get the file name from the path. - const splitPath = path.split('/') - const fileName = splitPath[splitPath.length - 1] - - // Prepare the upload object. Get a file ID from Uppy. - const id = _this.uppy.addFile({ - name: fileName, - data: fileBuf, - source: 'Local', - isRemote: false - }) - // console.log(`id: ${JSON.stringify(id, null, 2)}`) - - // Add the model ID, required to be allowed to upload the file. - _this.uppy.setFileMeta(id, { fileModelId: modelId }) - - // Upload the file to the server. - const upData = await _this.uppy.upload() - - if (upData.failed.length) { - throw new Error('The file could not be uploaded') - } - - if (upData.successful.length) { - delete upData.successful[0].data - // console.log(`upData: ${JSON.stringify(upData, null, 2)}`) - - const fileObj = { - schemaVersion: 1, - size: upData.successful[0].progress.bytesTotal, - fileId: upData.successful[0].meta.fileModelId, - fileName: upData.successful[0].name, - fileExtension: upData.successful[0].extension - } - // console.log(`fileObj: ${JSON.stringify(fileObj, null, 2)}`) - - return fileObj - // return true - } - - return false - } catch (err) { - console.error('Error in bch-js/src/ipfs.js/upload(): ') - throw err - } - } - - /** - * @api IPFS.getStatus() getStatus() - * @apiName getStatus() - * @apiGroup IPFS - * @apiDescription Gets the status of the uploaded file. Will return an object - * that indicates the payment status. If the file is paid, it should contain - * an IPFS hash. - * - * @apiExample Example usage: - * (async () => { - * try { - * const modelId = "5ec7392c2acfe57aa62e945a" - * let fileData = await bchjs.IPFS.getStatus(modelId) - * console.log(fileData) - * } catch(error) { - * console.error(error) - * } - * })() - * - * { - * "hasBeenPaid": true, - * "satCost": 4403, - * "bchAddr": "bchtest:qz5z82u0suqh80x5tfx4ht8kdrkkw664vcy44uz0wk", - * "ipfsHash": "QmRDHPhY5hCNVRMVQvS2H9uty8P1skdwgLaHpUAkEvsjcE", - * "fileId": "5ec7392c2acfe57aa62e945a", - * "fileName": "ipfs-e2e.js" - * } - */ - async getStatus (modelId) { - try { - if (!modelId) throw new Error('Must include a file model ID.') - - const fileData = await _this.axios.get( - `${this.IPFS_API}/files/${modelId}` - ) - // console.log(`fileData.data: ${JSON.stringify(fileData.data, null, 2)}`) - - const fileObj = { - hasBeenPaid: fileData.data.file.hasBeenPaid, - satCost: fileData.data.file.hostingCost, - bchAddr: fileData.data.file.bchAddr, - ipfsHash: fileData.data.file.payloadLink, - fileId: fileData.data.file._id, - fileName: fileData.data.file.fileName - } - - return fileObj - } catch (err) { - console.error('Error in getStatus()') - throw err - } - } - - /** - * @api IPFS.createFileModelWeb() createFileModelWeb() - * @apiName createFileModelWeb() - * @apiGroup IPFS - * @apiDescription Creates a new model on the server. If successful, will - * return an object with file data. That object contains a BCH address, - * payment amount, and _id required to be able to upload a file. - * - * @apiExample Example usage: - * (async () => { - * try { - * const content = ['PSF'] - * const name = 'psf.txt' // Content can be Array , ArrayBuffer , Blob - * const options = { type: "text/plain" } - * const file = new File(content,name,options) - * let fileData = await bchjs.IPFS.createFileModelWeb(file); - * console.log(fileData); - * } catch(error) { - * console.error(error) - * } - * })() - * - * { - * "success": true, - * "hostingCostBCH": 0.00004197, - * "hostingCostUSD": 0.01, - * "file": { - * "payloadLink": "", - * "hasBeenPaid": false, - * "_id": "5ec562319bfacc745e8d8a52", - * "schemaVersion": 1, - * "size": 4458, - * "fileName": "ipfs.js", - * "fileExtension": "js", - * "createdTimestamp": "1589994033.655", - * "hostingCost": 4196, - * "walletIndex": 49, - * "bchAddr": "bchtest:qzrpkevu7h2ayfa4rjx08r5elvpfu72dg567x3mh3c", - * "__v": 0 - * } - */ - async createFileModelWeb (file) { - try { - if (!file) throw new Error('File is required') - - const { name, size } = file - - if (!name || typeof name !== 'string') { - throw new Error("File should have the property 'name' of string type") - } - - if (!size || typeof size !== 'number') { - throw new Error("File should have the property 'size' of number type") - } - - // Get the file extension. - const splitExt = name.split('.') - const fileExt = splitExt[splitExt.length - 1] - - const fileObj = { - schemaVersion: 1, - size: size, - fileName: name, - fileExtension: fileExt - } - // console.log(`fileObj: ${JSON.stringify(fileObj, null, 2)}`) - - const fileData = await _this.axios.post(`${this.IPFS_API}/files`, { - file: fileObj - }) - // console.log(`fileData.data: ${JSON.stringify(fileData.data, null, 2)}`) - - return fileData.data - } catch (err) { - console.error('Error in createFileModelWeb()') - throw err - } - } - - /** - * @api IPFS.uploadFileWeb() uploadFileWeb() - * @apiName uploadFileWeb() - * @apiGroup IPFS - * @apiDescription Upload a file to the FullStack.cash IPFS server. If - * successful, it will return an object with an ID, a BCH address, and an - * amount of BCH to pay. - * - * @apiExample Example usage: - * (async () => { - * try { - * * const content = ['PSF'] - * const name = 'psf.txt' // Content can be Array , ArrayBuffer , Blob - * const options = { type: "text/plain" } - * const file = new File(content,name,options) - * let fileData = await bchjs.IPFS.uploadFile(file, "5ec562319bfacc745e8d8a52"); - * console.log(fileData); - * } catch(error) { - * console.error(error) - * } - * })() - * - * { - * "schemaVersion": 1, - * "size": 2374, - * "fileId": "5ec562319bfacc745e8d8a52", - * "fileName": "ipfs.js", - * "fileExtension": "js" - * } - */ - async uploadFileWeb (file, modelId) { - try { - if (!file) throw new Error('File is required') - - const { name, type, size } = file - - if (!name || typeof name !== 'string') { - throw new Error("File should have the property 'name' of string type") - } - - if (!type || typeof type !== 'string') { - throw new Error("File should have the property 'type' of string type") - } - - if (!size || typeof size !== 'number') { - throw new Error("File should have the property 'size' of number type") - } - - if (!modelId) { - throw new Error( - 'Must include a file model ID in order to upload a file.' - ) - } - - // Prepare the upload object. Get a file ID from Uppy. - const id = _this.uppy.addFile({ - name: name, - data: file, - source: 'Local', - isRemote: false - }) - // console.log(`id: ${JSON.stringify(id, null, 2)}`) - - // Add the model ID, required to be allowed to upload the file. - _this.uppy.setFileMeta(id, { fileModelId: modelId }) - - // Upload the file to the server. - const upData = await _this.uppy.upload() - - if (upData.failed.length) { - throw new Error('The file could not be uploaded') - } - - if (upData.successful.length) { - delete upData.successful[0].data - // console.log(`upData: ${JSON.stringify(upData, null, 2)}`) - - const fileObj = { - schemaVersion: 1, - size: upData.successful[0].progress.bytesTotal, - fileId: upData.successful[0].meta.fileModelId, - fileName: upData.successful[0].name, - fileExtension: upData.successful[0].extension - } - // console.log(`fileObj: ${JSON.stringify(fileObj, null, 2)}`) - - return fileObj - // return true - } - - return false - } catch (err) { - console.error('Error in bch-js/src/ipfs.js/uploadFileWeb(): ') - throw err - } - } -} - -module.exports = IPFS diff --git a/test/unit/ipfs.js b/test/unit/ipfs.js deleted file mode 100644 index 85f6b30..0000000 --- a/test/unit/ipfs.js +++ /dev/null @@ -1,443 +0,0 @@ -/* - Unit tests for the IPFS Class. -*/ - -const assert = require('chai').assert -const sinon = require('sinon') -const BCHJS = require('../../src/bch-js') -let bchjs - -const mockData = require('./fixtures/ipfs-mock') - -describe('#IPFS', () => { - let sandbox - - beforeEach(() => { - sandbox = sinon.createSandbox() - - bchjs = new BCHJS() - }) - - afterEach(() => sandbox.restore()) - - describe('#initUppy', () => { - it('should initialize uppy', () => { - bchjs.IPFS.initUppy() - }) - }) - - describe('#createFileModelServer', () => { - it('should throw an error if file does not exist', async () => { - try { - const path = '/non-existant-file' - - await bchjs.IPFS.createFileModelServer(path) - - assert.equal(true, false, 'Unexpected result') - } catch (err) { - // console.log(`err.message: ${err.message}`) - assert.include(err.message, 'Could not find this file') - } - }) - - it('should create a new file model', async () => { - const path = `${__dirname.toString()}/ipfs.js` - - sandbox - .stub(bchjs.IPFS.axios, 'post') - .resolves({ data: mockData.mockNewFileModel }) - - const result = await bchjs.IPFS.createFileModelServer(path) - // console.log(`result: ${JSON.stringify(result, null, 2)}`) - - assert.property(result, 'success') - assert.equal(result.success, true) - - assert.property(result, 'hostingCostBCH') - assert.property(result, 'hostingCostUSD') - assert.property(result, 'file') - - assert.property(result.file, 'payloadLink') - assert.property(result.file, 'hasBeenPaid') - assert.property(result.file, '_id') - assert.property(result.file, 'schemaVersion') - assert.property(result.file, 'size') - assert.property(result.file, 'fileName') - assert.property(result.file, 'fileExtension') - assert.property(result.file, 'createdTimestamp') - assert.property(result.file, 'hostingCost') - assert.property(result.file, 'walletIndex') - assert.property(result.file, 'bchAddr') - }) - }) - - describe('#uploadFileServer', () => { - it('should throw an error if file does not exist', async () => { - try { - const path = '/non-existant-file' - - await bchjs.IPFS.uploadFileServer(path) - - assert.equal(true, false, 'Unexpected result') - } catch (err) { - // console.log(`err.message: ${err.message}`) - assert.include(err.message, 'Could not find this file') - } - }) - - it('should throw an error if modelId is not included', async () => { - try { - const path = `${__dirname.toString()}/ipfs.js` - - await bchjs.IPFS.uploadFileServer(path) - - assert.equal(true, false, 'Unexpected result') - } catch (err) { - // console.log(`err.message: ${err.message}`) - assert.include(err.message, 'Must include a file model ID') - } - }) - - it('Should throw error if the file was not uploaded', async () => { - try { - const mock = { - successful: [], - failed: [ - { - id: 'file id' - } - ] - } - sandbox.stub(bchjs.IPFS.uppy, 'upload').resolves(mock) - - const path = `${__dirname.toString()}/ipfs.js` - await bchjs.IPFS.uploadFileServer(path, '5ec562319bfacc745e8d8a52') - - assert.equal(true, false, 'Unexpected result') - } catch (err) { - // console.log(err) - assert.include(err.message, 'The file could not be uploaded') - } - }) - - it('should return file object if the file is uploaded', async () => { - try { - sandbox.stub(bchjs.IPFS.uppy, 'upload').resolves(mockData.uploadData) - - const path = `${__dirname.toString()}/ipfs.js` - const result = await bchjs.IPFS.uploadFileServer( - path, - '5ec562319bfacc745e8d8a52' - ) - // console.log(`result: ${JSON.stringify(result, null, 2)}`) - - assert.property(result, 'schemaVersion') - assert.property(result, 'size') - assert.property(result, 'fileId') - assert.property(result, 'fileName') - assert.property(result, 'fileExtension') - } catch (err) { - // console.log(err) - assert.equal(true, false, 'Unexpected result') - } - }) - }) - - describe('#getStatus', () => { - it('should throw an error if modelId is not included', async () => { - try { - await bchjs.IPFS.getStatus() - - assert.equal(true, false, 'Unexpected result') - } catch (err) { - // console.log(`err.message: ${err.message}`) - assert.include(err.message, 'Must include a file model ID') - } - }) - - it('should get data on an unpaid file', async () => { - const modelId = '5ec7392c2acfe57aa62e945a' - - sandbox - .stub(bchjs.IPFS.axios, 'get') - .resolves({ data: mockData.unpaidFileData }) - - const result = await bchjs.IPFS.getStatus(modelId) - // console.log(`result: ${JSON.stringify(result, null, 2)}`) - - assert.property(result, 'hasBeenPaid') - assert.property(result, 'satCost') - assert.property(result, 'bchAddr') - assert.property(result, 'ipfsHash') - assert.property(result, 'fileId') - assert.property(result, 'fileName') - }) - - it('should get data on an unpaid file', async () => { - const modelId = '5ec7392c2acfe57aa62e945a' - - sandbox - .stub(bchjs.IPFS.axios, 'get') - .resolves({ data: mockData.paidFileData }) - - const result = await bchjs.IPFS.getStatus(modelId) - // console.log(`result: ${JSON.stringify(result, null, 2)}`) - - assert.property(result, 'hasBeenPaid') - assert.property(result, 'satCost') - assert.property(result, 'bchAddr') - assert.property(result, 'ipfsHash') - assert.property(result, 'fileId') - assert.property(result, 'fileName') - }) - }) - - describe('#createFileModelWeb', () => { - it('should throw an error if file is undefined', async () => { - try { - let file - - await bchjs.IPFS.createFileModelWeb(file) - - assert.equal(true, false, 'Unexpected result') - } catch (err) { - // console.log(`err.message: ${err.message}`) - assert.include(err.message, 'File is required') - } - }) - it('should throw an error if file is empty', async () => { - try { - const file = {} - - await bchjs.IPFS.createFileModelWeb(file) - - assert.equal(true, false, 'Unexpected result') - } catch (err) { - // console.log(`err.message: ${err.message}`) - assert.include( - err.message, - 'File should have the property \'name\' of string type' - ) - } - }) - it("should throw an error if 'name' property is not included", async () => { - try { - const file = { - size: 5000 - } - - await bchjs.IPFS.createFileModelWeb(file) - - assert.equal(true, false, 'Unexpected result') - } catch (err) { - // console.log(`err.message: ${err.message}`) - assert.include( - err.message, - 'File should have the property \'name\' of string type' - ) - } - }) - - it("should throw an error if 'size' property is not included", async () => { - try { - const file = { - name: 'ipfs.js' - } - - await bchjs.IPFS.createFileModelWeb(file) - - assert.equal(true, false, 'Unexpected result') - } catch (err) { - // console.log(`err.message: ${err.message}`) - assert.include( - err.message, - 'File should have the property \'size\' of number type' - ) - } - }) - - it('should create a new file model', async () => { - const file = { - name: 'ipfs.js', - size: 5000, - type: 'text/plain' - } - sandbox - .stub(bchjs.IPFS.axios, 'post') - .resolves({ data: mockData.mockNewFileModel }) - - const result = await bchjs.IPFS.createFileModelWeb(file) - // console.log(`result: ${JSON.stringify(result, null, 2)}`) - - assert.property(result, 'success') - assert.equal(result.success, true) - - assert.property(result, 'hostingCostBCH') - assert.property(result, 'hostingCostUSD') - assert.property(result, 'file') - - assert.property(result.file, 'payloadLink') - assert.property(result.file, 'hasBeenPaid') - assert.property(result.file, '_id') - assert.property(result.file, 'schemaVersion') - assert.property(result.file, 'size') - assert.property(result.file, 'fileName') - assert.property(result.file, 'fileExtension') - assert.property(result.file, 'createdTimestamp') - assert.property(result.file, 'hostingCost') - assert.property(result.file, 'walletIndex') - assert.property(result.file, 'bchAddr') - }) - }) - - describe('#uploadFileWeb', () => { - it('should throw an error if file is undefined', async () => { - try { - let file - - await bchjs.IPFS.uploadFileWeb(file) - - assert.equal(true, false, 'Unexpected result') - } catch (err) { - // console.log(`err.message: ${err.message}`) - assert.include(err.message, 'File is required') - } - }) - it('should throw an error if file is empty', async () => { - try { - const file = {} - - await bchjs.IPFS.uploadFileWeb(file) - - assert.equal(true, false, 'Unexpected result') - } catch (err) { - // console.log(`err.message: ${err.message}`) - assert.include( - err.message, - 'File should have the property \'name\' of string type' - ) - } - }) - it("should throw an error if 'name' property is not included", async () => { - try { - const file = { - size: 5000, - type: 'text/plain' - } - - await bchjs.IPFS.uploadFileWeb(file) - - assert.equal(true, false, 'Unexpected result') - } catch (err) { - // console.log(`err.message: ${err.message}`) - assert.include( - err.message, - 'File should have the property \'name\' of string type' - ) - } - }) - it("should throw an error if 'size' property is not included", async () => { - try { - const file = { - name: 'ipfs.js', - type: 'text/plain' - } - - await bchjs.IPFS.uploadFileWeb(file) - - assert.equal(true, false, 'Unexpected result') - } catch (err) { - // console.log(`err.message: ${err.message}`) - assert.include( - err.message, - 'File should have the property \'size\' of number type' - ) - } - }) - it("should throw an error if 'type' property is not included", async () => { - try { - const file = { - name: 'ipfs.js', - size: 5000 - } - - await bchjs.IPFS.uploadFileWeb(file) - - assert.equal(true, false, 'Unexpected result') - } catch (err) { - // console.log(`err.message: ${err.message}`) - assert.include( - err.message, - 'File should have the property \'type\' of string type' - ) - } - }) - it('should throw an error if modelId is not included', async () => { - try { - const file = { - name: 'ipfs.js', - size: 5000, - type: 'text/plain' - } - await bchjs.IPFS.uploadFileWeb(file) - - assert.equal(true, false, 'Unexpected result') - } catch (err) { - // console.log(`err.message: ${err.message}`) - assert.include(err.message, 'Must include a file model ID') - } - }) - - it('Should throw error if the file was not uploaded', async () => { - try { - const mock = { - successful: [], - failed: [ - { - id: 'file id' - } - ] - } - sandbox.stub(bchjs.IPFS.uppy, 'upload').resolves(mock) - - const file = { - name: 'ipfs.js', - size: 5000, - type: 'text/plain' - } - await bchjs.IPFS.uploadFileWeb(file, '5ec562319bfacc745e8d8a52') - - assert.equal(true, false, 'Unexpected result') - } catch (err) { - // console.log(err) - assert.include(err.message, 'The file could not be uploaded') - } - }) - - it('should return file object if the file is uploaded', async () => { - try { - sandbox.stub(bchjs.IPFS.uppy, 'upload').resolves(mockData.uploadData) - - const file = { - name: 'ipfs.js', - size: 5000, - type: 'text/plain' - } - const result = await bchjs.IPFS.uploadFileWeb( - file, - '5ec562319bfacc745e8d8a52' - ) - // console.log(`result: ${JSON.stringify(result, null, 2)}`) - - assert.property(result, 'schemaVersion') - assert.property(result, 'size') - assert.property(result, 'fileId') - assert.property(result, 'fileName') - assert.property(result, 'fileExtension') - } catch (err) { - // console.log(err) - assert.equal(true, false, 'Unexpected result') - } - }) - }) -})