diff --git a/config/env/common.js b/config/env/common.js index e26ce4c..df4cc60 100644 --- a/config/env/common.js +++ b/config/env/common.js @@ -37,6 +37,9 @@ module.exports = { ? process.env.CONSUMER_URL : 'https://free-bch.fullstack.cash', + // P2WDB URL that will accept API calls from the p2wdb npm library. + p2wdbUrl: process.env.P2WDB_URL ? process.env.P2WDB_URL : 'https://p2wdb.fullstack.cash', + // FullStack.cash account information, used for automatic JWT handling. getJwtAtStartup: process.env.GET_JWT_AT_STARTUP ? true : false, authServer: process.env.AUTHSERVER @@ -67,8 +70,7 @@ module.exports = { name: ipfsCoordName, version, protocol: 'generic-service', - description: - 'This is a generic IPFS Serivice Provider that uses JSON RPC over IPFS to communicate with it. This instance has not been customized. Source code: https://github.com/Permissionless-Software-Foundation/ipfs-service-provider', + description: 'This is a generic IPFS Serivice Provider that uses JSON RPC over IPFS to communicate with it. This instance has not been customized. Source code: https://github.com/Permissionless-Software-Foundation/ipfs-service-provider', documentation: 'https://ipfs-service-provider.fullstack.cash/', provider: { '@type': 'Organization', diff --git a/config/env/development.js b/config/env/development.js index b73c3ba..9c03e11 100644 --- a/config/env/development.js +++ b/config/env/development.js @@ -7,6 +7,6 @@ module.exports = { session: 'secret-boilerplate-token', token: 'secret-jwt-token', - database: 'mongodb://localhost:27017/swap-service-dev', + database: 'mongodb://localhost:27017/bch-swap-service-dev', env: 'dev' } diff --git a/config/env/production.js b/config/env/production.js index 70afee4..ddbe88e 100644 --- a/config/env/production.js +++ b/config/env/production.js @@ -13,6 +13,6 @@ module.exports = { // database: 'mongodb://172.17.0.1:5555/ipfs-service-prod', database: process.env.DBURL ? process.env.DBURL - : 'mongodb://172.17.0.1:5555/swap-service-prod', + : 'mongodb://172.17.0.1:5555/bch-swap-service-prod', env: 'prod' } diff --git a/config/env/test.js b/config/env/test.js index 195f40b..0fe804b 100644 --- a/config/env/test.js +++ b/config/env/test.js @@ -7,6 +7,6 @@ module.exports = { session: 'secret-boilerplate-token', token: 'secret-jwt-token', - database: 'mongodb://localhost:27017/swap-service-test', + database: 'mongodb://localhost:27017/bch-swap-service-test', env: 'test' } diff --git a/package-lock.json b/package-lock.json index e385c7e..b5fb27c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "1.0.0", "license": "MIT", "dependencies": { - "@psf/bch-js": "5.3.2", + "@psf/bch-js": "../bch-js", "axios": "0.21.1", "bch-message-lib": "2.1.4", "bcryptjs": "2.4.3", @@ -37,6 +37,7 @@ "mongoose": "5.13.13", "node-fetch": "npm:@achingbrain/node-fetch@2.6.7", "nodemailer": "6.4.17", + "p2wdb": "../p2wdb", "passport-local": "1.0.0", "public-ip": "^4.0.4", "winston": "3.3.3", @@ -62,6 +63,58 @@ "uuid": "8.3.2" } }, + "../bch-js": { + "version": "5.0.0", + "license": "MIT", + "dependencies": { + "@chris.troutner/bip32-utils": "1.0.5", + "@psf/bip21": "2.0.1", + "@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", + "bigi": "1.4.2", + "bignumber.js": "9.0.0", + "bip-schnorr": "0.3.0", + "bip38": "2.0.2", + "bip39": "3.0.2", + "bip66": "1.1.5", + "bitcoinjs-message": "2.0.0", + "bs58": "4.0.1", + "ecashaddrjs": "1.0.7", + "ini": "1.3.8", + "randombytes": "2.0.6", + "safe-buffer": "5.1.2", + "satoshi-bitcoin": "1.0.4", + "slp-mdm": "0.0.6", + "slp-parser": "0.0.4", + "wif": "2.0.6" + }, + "devDependencies": { + "apidoc": "0.17.7", + "assert": "2.0.0", + "chai": "4.1.2", + "coveralls": "3.0.2", + "eslint": "7.17.0", + "eslint-config-prettier": "7.1.0", + "eslint-config-standard": "16.0.3", + "eslint-plugin-node": "11.1.0", + "eslint-plugin-prettier": "3.3.1", + "eslint-plugin-standard": "4.0.0", + "husky": "^4.3.8", + "lodash.clonedeep": "4.5.0", + "mocha": "9.1.3", + "node-mocks-http": "1.7.0", + "nyc": "15.1.0", + "semantic-release": "18.0.0", + "sinon": "9.2.2", + "standard": "^16.0.4" + } + }, "../minimal-slp-wallet": { "version": "4.0.0", "license": "MIT", @@ -92,6 +145,34 @@ "tinyify": "3.0.0" } }, + "../p2wdb": { + "version": "1.0.1", + "license": "MIT", + "dependencies": { + "apidoc": "0.25.0", + "axios": "0.24.0", + "minimal-slp-wallet": "3.5.2" + }, + "devDependencies": { + "browserify": "17.0.0", + "chai": "4.2.0", + "coveralls": "3.1.0", + "eslint": "7.17.0", + "eslint-config-prettier": "7.1.0", + "eslint-config-standard": "16.0.2", + "eslint-plugin-node": "11.1.0", + "eslint-plugin-prettier": "3.3.1", + "eslint-plugin-standard": "4.0.0", + "husky": "4.3.8", + "lodash.clonedeep": "4.5.0", + "mocha": "8.4.0", + "nyc": "15.1.0", + "semantic-release": "17.4.2", + "sinon": "9.2.2", + "standard": "16.0.4", + "tinyify": "3.0.0" + } + }, "node_modules/@ampproject/remapping": { "version": "2.1.2", "dev": true, @@ -533,17 +614,6 @@ "multiformats": "^9.4.2" } }, - "node_modules/@chris.troutner/bip32-utils": { - "version": "1.0.5", - "license": "MIT", - "dependencies": { - "keccak": "^3.0.1", - "tape": "*" - }, - "engines": { - "node": ">=10.15.1" - } - }, "node_modules/@colors/colors": { "version": "1.5.0", "license": "MIT", @@ -1517,103 +1587,8 @@ "license": "BSD-3-Clause" }, "node_modules/@psf/bch-js": { - "version": "5.3.2", - "license": "MIT", - "dependencies": { - "@chris.troutner/bip32-utils": "1.0.5", - "@psf/bip21": "2.0.1", - "@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", - "bigi": "1.4.2", - "bignumber.js": "9.0.0", - "bip-schnorr": "0.3.0", - "bip38": "2.0.2", - "bip39": "3.0.2", - "bip66": "1.1.5", - "bitcoinjs-message": "2.0.0", - "bs58": "4.0.1", - "ecashaddrjs": "1.0.7", - "ini": "1.3.8", - "randombytes": "2.0.6", - "safe-buffer": "5.1.2", - "satoshi-bitcoin": "1.0.4", - "slp-mdm": "0.0.6", - "slp-parser": "0.0.4", - "wif": "2.0.6" - } - }, - "node_modules/@psf/bch-js/node_modules/axios": { - "version": "0.21.4", - "license": "MIT", - "dependencies": { - "follow-redirects": "^1.14.0" - } - }, - "node_modules/@psf/bch-js/node_modules/randombytes": { - "version": "2.0.6", - "license": "MIT", - "dependencies": { - "safe-buffer": "^5.1.0" - } - }, - "node_modules/@psf/bch-js/node_modules/safe-buffer": { - "version": "5.1.2", - "license": "MIT" - }, - "node_modules/@psf/bip21": { - "version": "2.0.1", - "license": "ISC", - "dependencies": { - "qs": "^6.3.0" - } - }, - "node_modules/@psf/bitcoincash-ops": { - "version": "2.0.0", - "license": "MIT" - }, - "node_modules/@psf/bitcoincashjs-lib": { - "version": "4.0.2", - "license": "MIT", - "dependencies": { - "@psf/bitcoincash-ops": "^2.0.0", - "@psf/pushdata-bitcoin": "^1.2.2", - "bech32": "^1.1.2", - "bigi": "^1.4.0", - "bip66": "^1.1.0", - "bs58check": "^2.0.0", - "create-hash": "^1.1.0", - "create-hmac": "^1.1.3", - "ecurve": "^1.0.0", - "merkle-lib": "^2.0.10", - "randombytes": "^2.0.1", - "safe-buffer": "^5.0.1", - "typeforce": "^1.18.0", - "varuint-bitcoin": "^1.0.4", - "wif": "^2.0.1" - }, - "engines": { - "node": ">=10.15.1" - } - }, - "node_modules/@psf/coininfo": { - "version": "4.0.0", - "license": "MIT", - "dependencies": { - "safe-buffer": "^5.1.1" - } - }, - "node_modules/@psf/pushdata-bitcoin": { - "version": "1.2.2", - "license": "MIT", - "dependencies": { - "@psf/bitcoincash-ops": "^2.0.0" - } + "resolved": "../bch-js", + "link": true }, "node_modules/@semantic-release/commit-analyzer": { "version": "8.0.1", @@ -2013,70 +1988,11 @@ "version": "0.12.1", "license": "MIT" }, - "node_modules/@types/tus-js-client": { - "version": "1.8.0", - "license": "MIT" - }, "node_modules/@ungap/promise-all-settled": { "version": "1.1.2", "dev": true, "license": "ISC" }, - "node_modules/@uppy/companion-client": { - "version": "1.10.2", - "license": "MIT", - "dependencies": { - "@uppy/utils": "^3.6.2", - "namespace-emitter": "^2.0.1", - "qs-stringify": "^1.1.0", - "url-parse": "^1.4.7" - } - }, - "node_modules/@uppy/companion-client/node_modules/@uppy/utils": { - "version": "3.6.2", - "license": "MIT", - "dependencies": { - "abortcontroller-polyfill": "^1.4.0", - "lodash.throttle": "^4.1.1" - } - }, - "node_modules/@uppy/core": { - "version": "1.10.4", - "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/store-default": { - "version": "1.2.7", - "license": "MIT" - }, - "node_modules/@uppy/tus": { - "version": "1.5.12", - "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/utils": { - "version": "2.4.4", - "license": "MIT", - "dependencies": { - "lodash.throttle": "^4.1.1" - } - }, "node_modules/@vascosantos/moving-average": { "version": "1.1.0", "license": "MIT" @@ -2102,10 +2018,6 @@ "get-iterator": "^1.0.2" } }, - "node_modules/abortcontroller-polyfill": { - "version": "1.7.3", - "license": "MIT" - }, "node_modules/abstract-leveldown": { "version": "7.2.0", "license": "MIT", @@ -2513,22 +2425,6 @@ "node": ">=8" } }, - "node_modules/array.prototype.every": { - "version": "1.1.3", - "license": "MIT", - "dependencies": { - "call-bind": "^1.0.2", - "define-properties": "^1.1.3", - "es-abstract": "^1.19.0", - "is-string": "^1.0.7" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/array.prototype.flat": { "version": "1.2.5", "dev": true, @@ -2634,16 +2530,6 @@ "node": ">=8.0.0" } }, - "node_modules/available-typed-arrays": { - "version": "1.0.5", - "license": "MIT", - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/aws-sign2": { "version": "0.5.0", "dev": true, @@ -2696,13 +2582,6 @@ ], "license": "MIT" }, - "node_modules/bc-bip68": { - "version": "1.0.5", - "license": "ISC", - "engines": { - "node": ">=4.5.0" - } - }, "node_modules/bch-encrypt-lib": { "version": "2.0.0", "license": "MIT", @@ -2718,17 +2597,6 @@ "minimal-slp-wallet": "4.4.1" } }, - "node_modules/bchaddrjs-slp": { - "version": "0.2.5", - "license": "MIT", - "dependencies": { - "bs58check": "^2.1.2", - "cashaddrjs-slp": "^0.2.11" - }, - "engines": { - "node": ">= 6.0.0" - } - }, "node_modules/bcrypt-pbkdf": { "version": "1.0.2", "license": "BSD-3-Clause", @@ -2740,39 +2608,11 @@ "version": "2.4.3", "license": "MIT" }, - "node_modules/bech32": { - "version": "1.1.4", - "license": "MIT" - }, "node_modules/before-after-hook": { "version": "2.2.2", "dev": true, "license": "Apache-2.0" }, - "node_modules/big-integer": { - "version": "1.6.51", - "license": "Unlicense", - "engines": { - "node": ">=0.6" - } - }, - "node_modules/big.js": { - "version": "3.2.0", - "license": "MIT", - "engines": { - "node": "*" - } - }, - "node_modules/bigi": { - "version": "1.4.2" - }, - "node_modules/bignumber.js": { - "version": "9.0.0", - "license": "MIT", - "engines": { - "node": "*" - } - }, "node_modules/binary-extensions": { "version": "2.2.0", "dev": true, @@ -2792,41 +2632,6 @@ "version": "1.0.1", "optional": true }, - "node_modules/bip-schnorr": { - "version": "0.3.0", - "license": "MIT", - "dependencies": { - "ecurve": "^1.0.6", - "js-sha256": "^0.9.0", - "random-bytes": "^1.0.0", - "safe-buffer": "^5.0.1" - }, - "engines": { - "node": ">=8.0.0" - } - }, - "node_modules/bip38": { - "version": "2.0.2", - "dependencies": { - "bigi": "^1.2.0", - "browserify-aes": "^1.0.1", - "bs58check": "<3.0.0", - "buffer-xor": "^1.0.2", - "create-hash": "^1.1.1", - "ecurve": "^1.0.0", - "scryptsy": "^2.0.0" - } - }, - "node_modules/bip39": { - "version": "3.0.2", - "license": "ISC", - "dependencies": { - "@types/node": "11.11.6", - "create-hash": "^1.1.0", - "pbkdf2": "^3.0.9", - "randombytes": "^2.0.1" - } - }, "node_modules/bip66": { "version": "1.1.5", "license": "MIT", @@ -2834,20 +2639,6 @@ "safe-buffer": "^5.0.1" } }, - "node_modules/bitcoinjs-message": { - "version": "2.0.0", - "license": "MIT", - "dependencies": { - "bs58check": "^2.0.2", - "buffer-equals": "^1.0.3", - "create-hash": "^1.1.2", - "secp256k1": "^3.0.1", - "varuint-bitcoin": "^1.0.1" - }, - "engines": { - "node": ">=0.10" - } - }, "node_modules/bl": { "version": "5.0.0", "license": "MIT", @@ -3150,13 +2941,6 @@ "version": "1.0.1", "license": "BSD-3-Clause" }, - "node_modules/buffer-equals": { - "version": "1.0.4", - "license": "MIT", - "engines": { - "node": ">=0.10.0" - } - }, "node_modules/buffer-from": { "version": "1.1.2", "license": "MIT", @@ -3330,13 +3114,6 @@ "version": "0.12.0", "license": "Apache-2.0" }, - "node_modules/cashaddrjs-slp": { - "version": "0.2.12", - "license": "MIT", - "dependencies": { - "big-integer": "^1.6.34" - } - }, "node_modules/catering": { "version": "2.1.1", "license": "MIT", @@ -3647,21 +3424,6 @@ "text-hex": "1.0.x" } }, - "node_modules/combine-errors": { - "version": "3.0.3", - "dependencies": { - "custom-error-instance": "2.1.1", - "lodash.uniqby": "4.5.0" - } - }, - "node_modules/combine-errors/node_modules/lodash.uniqby": { - "version": "4.5.0", - "license": "MIT", - "dependencies": { - "lodash._baseiteratee": "~4.7.0", - "lodash._baseuniq": "~4.6.0" - } - }, "node_modules/combined-stream": { "version": "1.0.8", "license": "MIT", @@ -4044,14 +3806,6 @@ "node": ">= 0.4" } }, - "node_modules/cuid": { - "version": "2.1.8", - "license": "MIT" - }, - "node_modules/custom-error-instance": { - "version": "2.1.1", - "license": "ISC" - }, "node_modules/dashdash": { "version": "1.14.1", "license": "MIT", @@ -4172,34 +3926,6 @@ "node": ">=0.12" } }, - "node_modules/deep-equal": { - "version": "2.0.5", - "license": "MIT", - "dependencies": { - "call-bind": "^1.0.0", - "es-get-iterator": "^1.1.1", - "get-intrinsic": "^1.0.1", - "is-arguments": "^1.0.4", - "is-date-object": "^1.0.2", - "is-regex": "^1.1.1", - "isarray": "^2.0.5", - "object-is": "^1.1.4", - "object-keys": "^1.1.1", - "object.assign": "^4.1.2", - "regexp.prototype.flags": "^1.3.0", - "side-channel": "^1.0.3", - "which-boxed-primitive": "^1.0.1", - "which-collection": "^1.0.1", - "which-typed-array": "^1.1.2" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/deep-equal/node_modules/isarray": { - "version": "2.0.5", - "license": "MIT" - }, "node_modules/deep-extend": { "version": "0.6.0", "license": "MIT", @@ -4250,6 +3976,7 @@ }, "node_modules/define-properties": { "version": "1.1.3", + "dev": true, "license": "MIT", "dependencies": { "object-keys": "^1.0.12" @@ -4258,10 +3985,6 @@ "node": ">= 0.4" } }, - "node_modules/defined": { - "version": "1.0.0", - "license": "MIT" - }, "node_modules/del": { "version": "6.0.0", "dev": true, @@ -4424,16 +4147,6 @@ "node": ">=8" } }, - "node_modules/dotignore": { - "version": "0.1.2", - "license": "MIT", - "dependencies": { - "minimatch": "^3.0.4" - }, - "bin": { - "ignored": "bin/ignored" - } - }, "node_modules/dottie": { "version": "2.0.2", "license": "MIT" @@ -4462,20 +4175,6 @@ "version": "0.1.4", "license": "BSD-3-Clause" }, - "node_modules/ecashaddrjs": { - "version": "1.0.7", - "license": "MIT", - "dependencies": { - "big-integer": "1.6.36" - } - }, - "node_modules/ecashaddrjs/node_modules/big-integer": { - "version": "1.6.36", - "license": "Unlicense", - "engines": { - "node": ">=0.6" - } - }, "node_modules/ecc-jsbn": { "version": "0.1.2", "license": "MIT", @@ -4508,14 +4207,6 @@ "safe-buffer": "^5.0.1" } }, - "node_modules/ecurve": { - "version": "1.0.6", - "license": "MIT", - "dependencies": { - "bigi": "^1.1.0", - "safe-buffer": "^5.0.1" - } - }, "node_modules/ee-first": { "version": "1.1.1", "license": "MIT" @@ -4841,6 +4532,7 @@ }, "node_modules/es-abstract": { "version": "1.19.1", + "dev": true, "license": "MIT", "dependencies": { "call-bind": "^1.0.2", @@ -4871,29 +4563,9 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/es-get-iterator": { - "version": "1.1.2", - "license": "MIT", - "dependencies": { - "call-bind": "^1.0.2", - "get-intrinsic": "^1.1.0", - "has-symbols": "^1.0.1", - "is-arguments": "^1.1.0", - "is-map": "^2.0.2", - "is-set": "^2.0.2", - "is-string": "^1.0.5", - "isarray": "^2.0.5" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/es-get-iterator/node_modules/isarray": { - "version": "2.0.5", - "license": "MIT" - }, "node_modules/es-to-primitive": { "version": "1.2.1", + "dev": true, "license": "MIT", "dependencies": { "is-callable": "^1.1.4", @@ -6100,17 +5772,6 @@ } } }, - "node_modules/for-each": { - "version": "0.3.3", - "license": "MIT", - "dependencies": { - "is-callable": "^1.1.3" - } - }, - "node_modules/foreach": { - "version": "2.0.5", - "license": "MIT" - }, "node_modules/foreground-child": { "version": "2.0.0", "dev": true, @@ -7019,6 +6680,7 @@ }, "node_modules/get-package-type": { "version": "0.1.0", + "dev": true, "license": "MIT", "engines": { "node": ">=8.0.0" @@ -7047,6 +6709,7 @@ }, "node_modules/get-symbol-description": { "version": "1.0.0", + "dev": true, "license": "MIT", "dependencies": { "call-bind": "^1.0.2", @@ -7321,6 +6984,7 @@ }, "node_modules/has-bigints": { "version": "1.0.1", + "dev": true, "license": "MIT", "funding": { "url": "https://github.com/sponsors/ljharb" @@ -7330,17 +6994,6 @@ "version": "1.1.0", "license": "MIT" }, - "node_modules/has-dynamic-import": { - "version": "2.0.1", - "license": "MIT", - "dependencies": { - "call-bind": "^1.0.2", - "get-intrinsic": "^1.1.1" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/has-flag": { "version": "4.0.0", "license": "MIT", @@ -7788,6 +7441,7 @@ }, "node_modules/internal-slot": { "version": "1.0.3", + "dev": true, "license": "MIT", "dependencies": { "get-intrinsic": "^1.1.0", @@ -10119,20 +9773,6 @@ "node": ">=10" } }, - "node_modules/is-arguments": { - "version": "1.1.1", - "license": "MIT", - "dependencies": { - "call-bind": "^1.0.2", - "has-tostringtag": "^1.0.0" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/is-arrayish": { "version": "0.2.1", "dev": true, @@ -10140,6 +9780,7 @@ }, "node_modules/is-bigint": { "version": "1.0.4", + "dev": true, "license": "MIT", "dependencies": { "has-bigints": "^1.0.1" @@ -10168,6 +9809,7 @@ }, "node_modules/is-boolean-object": { "version": "1.1.2", + "dev": true, "license": "MIT", "dependencies": { "call-bind": "^1.0.2", @@ -10203,6 +9845,7 @@ }, "node_modules/is-callable": { "version": "1.2.4", + "dev": true, "license": "MIT", "engines": { "node": ">= 0.4" @@ -10223,6 +9866,7 @@ }, "node_modules/is-core-module": { "version": "2.6.0", + "dev": true, "license": "MIT", "dependencies": { "has": "^1.0.3" @@ -10233,6 +9877,7 @@ }, "node_modules/is-date-object": { "version": "1.0.5", + "dev": true, "license": "MIT", "dependencies": { "has-tostringtag": "^1.0.0" @@ -10323,15 +9968,9 @@ "version": "1.0.1", "license": "MIT" }, - "node_modules/is-map": { - "version": "2.0.2", - "license": "MIT", - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/is-negative-zero": { "version": "2.0.2", + "dev": true, "license": "MIT", "engines": { "node": ">= 0.4" @@ -10360,6 +9999,7 @@ }, "node_modules/is-number-object": { "version": "1.0.6", + "dev": true, "license": "MIT", "dependencies": { "has-tostringtag": "^1.0.0" @@ -10410,6 +10050,7 @@ }, "node_modules/is-regex": { "version": "1.1.4", + "dev": true, "license": "MIT", "dependencies": { "call-bind": "^1.0.2", @@ -10422,15 +10063,9 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/is-set": { - "version": "2.0.2", - "license": "MIT", - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/is-shared-array-buffer": { "version": "1.0.1", + "dev": true, "license": "MIT", "funding": { "url": "https://github.com/sponsors/ljharb" @@ -10448,6 +10083,7 @@ }, "node_modules/is-string": { "version": "1.0.7", + "dev": true, "license": "MIT", "dependencies": { "has-tostringtag": "^1.0.0" @@ -10461,6 +10097,7 @@ }, "node_modules/is-symbol": { "version": "1.0.4", + "dev": true, "license": "MIT", "dependencies": { "has-symbols": "^1.0.2" @@ -10483,36 +10120,13 @@ "node": ">=0.10.0" } }, - "node_modules/is-typed-array": { - "version": "1.1.8", - "license": "MIT", - "dependencies": { - "available-typed-arrays": "^1.0.5", - "call-bind": "^1.0.2", - "es-abstract": "^1.18.5", - "foreach": "^2.0.5", - "has-tostringtag": "^1.0.0" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/is-typedarray": { "version": "1.0.0", "license": "MIT" }, - "node_modules/is-weakmap": { - "version": "2.0.1", - "license": "MIT", - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/is-weakref": { "version": "1.0.2", + "dev": true, "license": "MIT", "dependencies": { "call-bind": "^1.0.2" @@ -10521,17 +10135,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/is-weakset": { - "version": "2.0.2", - "license": "MIT", - "dependencies": { - "call-bind": "^1.0.2", - "get-intrinsic": "^1.1.1" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/is-windows": { "version": "1.0.2", "dev": true, @@ -11067,14 +10670,6 @@ "node": ">=6" } }, - "node_modules/js-base64": { - "version": "2.6.4", - "license": "BSD-3-Clause" - }, - "node_modules/js-sha256": { - "version": "0.9.0", - "license": "MIT" - }, "node_modules/js-sha3": { "version": "0.8.0", "license": "MIT" @@ -11395,31 +10990,6 @@ "node": ">= 6.0.0" } }, - "node_modules/keccak": { - "version": "3.0.2", - "hasInstallScript": true, - "license": "MIT", - "dependencies": { - "node-addon-api": "^2.0.0", - "node-gyp-build": "^4.2.0", - "readable-stream": "^3.6.0" - }, - "engines": { - "node": ">=10.0.0" - } - }, - "node_modules/keccak/node_modules/readable-stream": { - "version": "3.6.0", - "license": "MIT", - "dependencies": { - "inherits": "^2.0.3", - "string_decoder": "^1.1.1", - "util-deprecate": "^1.0.1" - }, - "engines": { - "node": ">= 6" - } - }, "node_modules/keygrip": { "version": "1.1.0", "license": "MIT", @@ -12265,40 +11835,6 @@ "version": "4.17.21", "license": "MIT" }, - "node_modules/lodash._baseiteratee": { - "version": "4.7.0", - "license": "MIT", - "dependencies": { - "lodash._stringtopath": "~4.8.0" - } - }, - "node_modules/lodash._basetostring": { - "version": "4.12.0", - "license": "MIT" - }, - "node_modules/lodash._baseuniq": { - "version": "4.6.0", - "license": "MIT", - "dependencies": { - "lodash._createset": "~4.0.0", - "lodash._root": "~3.0.0" - } - }, - "node_modules/lodash._createset": { - "version": "4.0.3", - "license": "MIT" - }, - "node_modules/lodash._root": { - "version": "3.0.1", - "license": "MIT" - }, - "node_modules/lodash._stringtopath": { - "version": "4.8.0", - "license": "MIT", - "dependencies": { - "lodash._basetostring": "~4.12.0" - } - }, "node_modules/lodash.camelcase": { "version": "4.3.0", "license": "MIT" @@ -12605,10 +12141,6 @@ "node": ">= 8" } }, - "node_modules/merkle-lib": { - "version": "2.0.10", - "license": "MIT" - }, "node_modules/methods": { "version": "1.1.2", "license": "MIT", @@ -12640,13 +12172,6 @@ "node": ">= 0.6" } }, - "node_modules/mime-match": { - "version": "1.0.2", - "license": "ISC", - "dependencies": { - "wildcard": "^1.1.0" - } - }, "node_modules/mime-types": { "version": "2.1.34", "license": "MIT", @@ -13128,10 +12653,6 @@ "npm": ">=3.X.X" } }, - "node_modules/namespace-emitter": { - "version": "2.0.1", - "license": "MIT" - }, "node_modules/nan": { "version": "2.15.0", "license": "MIT" @@ -17139,22 +16660,9 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/object-is": { - "version": "1.1.5", - "license": "MIT", - "dependencies": { - "call-bind": "^1.0.2", - "define-properties": "^1.1.3" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/object-keys": { "version": "1.1.1", + "dev": true, "license": "MIT", "engines": { "node": ">= 0.4" @@ -17162,6 +16670,7 @@ }, "node_modules/object.assign": { "version": "4.1.2", + "dev": true, "license": "MIT", "dependencies": { "call-bind": "^1.0.0", @@ -17561,6 +17070,10 @@ "version": "1.0.1", "license": "MIT" }, + "node_modules/p2wdb": { + "resolved": "../p2wdb", + "link": true + }, "node_modules/package-hash": { "version": "4.0.0", "dev": true, @@ -17727,6 +17240,7 @@ }, "node_modules/path-parse": { "version": "1.0.7", + "dev": true, "license": "MIT" }, "node_modules/path-to-regexp": { @@ -18097,11 +17611,6 @@ "semver-compare": "^1.0.0" } }, - "node_modules/preact": { - "version": "8.2.9", - "hasInstallScript": true, - "license": "MIT" - }, "node_modules/prelude-ls": { "version": "1.2.1", "dev": true, @@ -18390,14 +17899,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/qs-stringify": { - "version": "1.2.1", - "license": "MIT" - }, - "node_modules/querystringify": { - "version": "2.2.0", - "license": "MIT" - }, "node_modules/queue-microtask": { "version": "1.2.3", "funding": [ @@ -18794,6 +18295,7 @@ }, "node_modules/regexp.prototype.flags": { "version": "1.3.1", + "dev": true, "license": "MIT", "dependencies": { "call-bind": "^1.0.2", @@ -18921,10 +18423,6 @@ "dev": true, "license": "ISC" }, - "node_modules/requires-port": { - "version": "1.0.0", - "license": "MIT" - }, "node_modules/resolve": { "version": "1.22.0", "dev": true, @@ -19006,13 +18504,6 @@ "lowercase-keys": "^1.0.0" } }, - "node_modules/resumer": { - "version": "0.0.0", - "license": "MIT", - "dependencies": { - "through": "~2.3.4" - } - }, "node_modules/retimer": { "version": "3.0.0", "license": "MIT" @@ -19155,21 +18646,10 @@ "node": ">=6" } }, - "node_modules/satoshi-bitcoin": { - "version": "1.0.4", - "license": "MIT", - "dependencies": { - "big.js": "^3.1.3" - } - }, "node_modules/sax": { "version": "1.2.4", "license": "ISC" }, - "node_modules/scryptsy": { - "version": "2.1.0", - "license": "MIT" - }, "node_modules/secp256k1": { "version": "3.8.0", "hasInstallScript": true, @@ -19577,20 +19057,6 @@ "version": "1.0.1", "license": "MIT" }, - "node_modules/slp-mdm": { - "version": "0.0.6", - "license": "MIT", - "dependencies": { - "bignumber.js": "^9.0.0" - } - }, - "node_modules/slp-parser": { - "version": "0.0.4", - "license": "MIT", - "dependencies": { - "bignumber.js": "^9.0.0" - } - }, "node_modules/snake-case": { "version": "3.0.4", "license": "MIT", @@ -20241,23 +19707,9 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/string.prototype.trim": { - "version": "1.2.5", - "license": "MIT", - "dependencies": { - "call-bind": "^1.0.2", - "define-properties": "^1.1.3", - "es-abstract": "^1.19.1" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/string.prototype.trimend": { "version": "1.0.4", + "dev": true, "license": "MIT", "dependencies": { "call-bind": "^1.0.2", @@ -20269,6 +19721,7 @@ }, "node_modules/string.prototype.trimstart": { "version": "1.0.4", + "dev": true, "license": "MIT", "dependencies": { "call-bind": "^1.0.2", @@ -20456,72 +19909,6 @@ "node": ">=8" } }, - "node_modules/tape": { - "version": "5.5.2", - "license": "MIT", - "dependencies": { - "array.prototype.every": "^1.1.3", - "call-bind": "^1.0.2", - "deep-equal": "^2.0.5", - "defined": "^1.0.0", - "dotignore": "^0.1.2", - "for-each": "^0.3.3", - "get-package-type": "^0.1.0", - "glob": "^7.2.0", - "has": "^1.0.3", - "has-dynamic-import": "^2.0.1", - "inherits": "^2.0.4", - "is-regex": "^1.1.4", - "minimist": "^1.2.5", - "object-inspect": "^1.12.0", - "object-is": "^1.1.5", - "object-keys": "^1.1.1", - "object.assign": "^4.1.2", - "resolve": "^2.0.0-next.3", - "resumer": "^0.0.0", - "string.prototype.trim": "^1.2.5", - "through": "^2.3.8" - }, - "bin": { - "tape": "bin/tape" - } - }, - "node_modules/tape/node_modules/glob": { - "version": "7.2.0", - "license": "ISC", - "dependencies": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.0.4", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" - }, - "engines": { - "node": "*" - }, - "funding": { - "url": "https://github.com/sponsors/isaacs" - } - }, - "node_modules/tape/node_modules/object-inspect": { - "version": "1.12.0", - "license": "MIT", - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, - "node_modules/tape/node_modules/resolve": { - "version": "2.0.0-next.3", - "license": "MIT", - "dependencies": { - "is-core-module": "^2.2.0", - "path-parse": "^1.0.6" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/tar": { "version": "6.1.11", "license": "ISC", @@ -20630,6 +20017,7 @@ }, "node_modules/through": { "version": "2.3.8", + "dev": true, "license": "MIT" }, "node_modules/through2": { @@ -20849,41 +20237,6 @@ "node": "*" } }, - "node_modules/tus-js-client": { - "version": "1.8.0", - "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/tus-js-client/node_modules/buffer-from": { - "version": "0.1.2", - "license": "MIT" - }, - "node_modules/tus-js-client/node_modules/proper-lockfile": { - "version": "2.0.1", - "license": "MIT", - "dependencies": { - "graceful-fs": "^4.1.2", - "retry": "^0.10.0" - }, - "engines": { - "node": ">=4.0.0" - } - }, - "node_modules/tus-js-client/node_modules/retry": { - "version": "0.10.1", - "license": "MIT", - "engines": { - "node": "*" - } - }, "node_modules/tweetnacl": { "version": "0.14.5", "license": "Unlicense" @@ -20938,10 +20291,6 @@ "is-typedarray": "^1.0.0" } }, - "node_modules/typeforce": { - "version": "1.18.0", - "license": "MIT" - }, "node_modules/uc.micro": { "version": "1.0.6", "dev": true, @@ -20978,6 +20327,7 @@ }, "node_modules/unbox-primitive": { "version": "1.0.1", + "dev": true, "license": "MIT", "dependencies": { "function-bind": "^1.1.1", @@ -21091,14 +20441,6 @@ "dev": true, "license": "MIT" }, - "node_modules/url-parse": { - "version": "1.5.10", - "license": "MIT", - "dependencies": { - "querystringify": "^2.1.1", - "requires-port": "^1.0.0" - } - }, "node_modules/url-parse-lax": { "version": "3.0.0", "license": "MIT", @@ -21176,13 +20518,6 @@ "version": "5.0.2", "license": "MIT" }, - "node_modules/varuint-bitcoin": { - "version": "1.1.2", - "license": "MIT", - "dependencies": { - "safe-buffer": "^5.1.1" - } - }, "node_modules/vary": { "version": "1.1.2", "license": "MIT", @@ -21238,6 +20573,7 @@ }, "node_modules/which-boxed-primitive": { "version": "1.0.2", + "dev": true, "license": "MIT", "dependencies": { "is-bigint": "^1.0.1", @@ -21250,19 +20586,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/which-collection": { - "version": "1.0.1", - "license": "MIT", - "dependencies": { - "is-map": "^2.0.1", - "is-set": "^2.0.1", - "is-weakmap": "^2.0.1", - "is-weakset": "^2.0.1" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/which-module": { "version": "2.0.0", "dev": true, @@ -21276,24 +20599,6 @@ "node": ">=4" } }, - "node_modules/which-typed-array": { - "version": "1.1.7", - "license": "MIT", - "dependencies": { - "available-typed-arrays": "^1.0.5", - "call-bind": "^1.0.2", - "es-abstract": "^1.18.5", - "foreach": "^2.0.5", - "has-tostringtag": "^1.0.0", - "is-typed-array": "^1.1.7" - }, - "engines": { - "node": ">= 0.4" - }, - "funding": { - "url": "https://github.com/sponsors/ljharb" - } - }, "node_modules/wide-align": { "version": "1.1.3", "devOptional": true, @@ -21338,10 +20643,6 @@ "bs58check": "<3.0.0" } }, - "node_modules/wildcard": { - "version": "1.1.2", - "license": "MIT" - }, "node_modules/winston": { "version": "3.3.3", "license": "MIT", @@ -22184,13 +21485,6 @@ } } }, - "@chris.troutner/bip32-utils": { - "version": "1.0.5", - "requires": { - "keccak": "^3.0.1", - "tape": "*" - } - }, "@colors/colors": { "version": "1.5.0" }, @@ -22902,7 +22196,7 @@ "version": "1.1.0" }, "@psf/bch-js": { - "version": "5.3.2", + "version": "file:../bch-js", "requires": { "@chris.troutner/bip32-utils": "1.0.5", "@psf/bip21": "2.0.1", @@ -22911,6 +22205,8 @@ "@psf/coininfo": "4.0.0", "@uppy/core": "1.10.4", "@uppy/tus": "1.5.12", + "apidoc": "0.17.7", + "assert": "2.0.0", "axios": "^0.21.4", "bc-bip68": "1.0.5", "bchaddrjs-slp": "0.2.5", @@ -22922,72 +22218,30 @@ "bip66": "1.1.5", "bitcoinjs-message": "2.0.0", "bs58": "4.0.1", + "chai": "4.1.2", + "coveralls": "3.0.2", "ecashaddrjs": "1.0.7", + "eslint": "7.17.0", + "eslint-config-prettier": "7.1.0", + "eslint-config-standard": "16.0.3", + "eslint-plugin-node": "11.1.0", + "eslint-plugin-prettier": "3.3.1", + "eslint-plugin-standard": "4.0.0", + "husky": "^4.3.8", "ini": "1.3.8", + "lodash.clonedeep": "4.5.0", + "mocha": "9.1.3", + "node-mocks-http": "1.7.0", + "nyc": "15.1.0", "randombytes": "2.0.6", "safe-buffer": "5.1.2", "satoshi-bitcoin": "1.0.4", + "semantic-release": "18.0.0", + "sinon": "9.2.2", "slp-mdm": "0.0.6", "slp-parser": "0.0.4", + "standard": "^16.0.4", "wif": "2.0.6" - }, - "dependencies": { - "axios": { - "version": "0.21.4", - "requires": { - "follow-redirects": "^1.14.0" - } - }, - "randombytes": { - "version": "2.0.6", - "requires": { - "safe-buffer": "^5.1.0" - } - }, - "safe-buffer": { - "version": "5.1.2" - } - } - }, - "@psf/bip21": { - "version": "2.0.1", - "requires": { - "qs": "^6.3.0" - } - }, - "@psf/bitcoincash-ops": { - "version": "2.0.0" - }, - "@psf/bitcoincashjs-lib": { - "version": "4.0.2", - "requires": { - "@psf/bitcoincash-ops": "^2.0.0", - "@psf/pushdata-bitcoin": "^1.2.2", - "bech32": "^1.1.2", - "bigi": "^1.4.0", - "bip66": "^1.1.0", - "bs58check": "^2.0.0", - "create-hash": "^1.1.0", - "create-hmac": "^1.1.3", - "ecurve": "^1.0.0", - "merkle-lib": "^2.0.10", - "randombytes": "^2.0.1", - "safe-buffer": "^5.0.1", - "typeforce": "^1.18.0", - "varuint-bitcoin": "^1.0.4", - "wif": "^2.0.1" - } - }, - "@psf/coininfo": { - "version": "4.0.0", - "requires": { - "safe-buffer": "^5.1.1" - } - }, - "@psf/pushdata-bitcoin": { - "version": "1.2.2", - "requires": { - "@psf/bitcoincash-ops": "^2.0.0" } }, "@semantic-release/commit-analyzer": { @@ -23295,61 +22549,10 @@ "@types/retry": { "version": "0.12.1" }, - "@types/tus-js-client": { - "version": "1.8.0" - }, "@ungap/promise-all-settled": { "version": "1.1.2", "dev": true }, - "@uppy/companion-client": { - "version": "1.10.2", - "requires": { - "@uppy/utils": "^3.6.2", - "namespace-emitter": "^2.0.1", - "qs-stringify": "^1.1.0", - "url-parse": "^1.4.7" - }, - "dependencies": { - "@uppy/utils": { - "version": "3.6.2", - "requires": { - "abortcontroller-polyfill": "^1.4.0", - "lodash.throttle": "^4.1.1" - } - } - } - }, - "@uppy/core": { - "version": "1.10.4", - "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" - } - }, - "@uppy/store-default": { - "version": "1.2.7" - }, - "@uppy/tus": { - "version": "1.5.12", - "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" - } - }, - "@uppy/utils": { - "version": "2.4.4", - "requires": { - "lodash.throttle": "^4.1.1" - } - }, "@vascosantos/moving-average": { "version": "1.1.0" }, @@ -23368,9 +22571,6 @@ "get-iterator": "^1.0.2" } }, - "abortcontroller-polyfill": { - "version": "1.7.3" - }, "abstract-leveldown": { "version": "7.2.0", "requires": { @@ -23632,15 +22832,6 @@ "version": "2.1.0", "dev": true }, - "array.prototype.every": { - "version": "1.1.3", - "requires": { - "call-bind": "^1.0.2", - "define-properties": "^1.1.3", - "es-abstract": "^1.19.0", - "is-string": "^1.0.7" - } - }, "array.prototype.flat": { "version": "1.2.5", "dev": true, @@ -23703,9 +22894,6 @@ "atomic-sleep": { "version": "1.0.0" }, - "available-typed-arrays": { - "version": "1.0.5" - }, "aws-sign2": { "version": "0.5.0", "dev": true, @@ -23735,9 +22923,6 @@ "base64-js": { "version": "1.5.1" }, - "bc-bip68": { - "version": "1.0.5" - }, "bch-encrypt-lib": { "version": "2.0.0", "requires": { @@ -23749,13 +22934,6 @@ "version": "2.1.4", "requires": {} }, - "bchaddrjs-slp": { - "version": "0.2.5", - "requires": { - "bs58check": "^2.1.2", - "cashaddrjs-slp": "^0.2.11" - } - }, "bcrypt-pbkdf": { "version": "1.0.2", "requires": { @@ -23765,25 +22943,10 @@ "bcryptjs": { "version": "2.4.3" }, - "bech32": { - "version": "1.1.4" - }, "before-after-hook": { "version": "2.2.2", "dev": true }, - "big-integer": { - "version": "1.6.51" - }, - "big.js": { - "version": "3.2.0" - }, - "bigi": { - "version": "1.4.2" - }, - "bignumber.js": { - "version": "9.0.0" - }, "binary-extensions": { "version": "2.2.0", "dev": true @@ -23798,52 +22961,12 @@ "version": "1.0.1", "optional": true }, - "bip-schnorr": { - "version": "0.3.0", - "requires": { - "ecurve": "^1.0.6", - "js-sha256": "^0.9.0", - "random-bytes": "^1.0.0", - "safe-buffer": "^5.0.1" - } - }, - "bip38": { - "version": "2.0.2", - "requires": { - "bigi": "^1.2.0", - "browserify-aes": "^1.0.1", - "bs58check": "<3.0.0", - "buffer-xor": "^1.0.2", - "create-hash": "^1.1.1", - "ecurve": "^1.0.0", - "scryptsy": "^2.0.0" - } - }, - "bip39": { - "version": "3.0.2", - "requires": { - "@types/node": "11.11.6", - "create-hash": "^1.1.0", - "pbkdf2": "^3.0.9", - "randombytes": "^2.0.1" - } - }, "bip66": { "version": "1.1.5", "requires": { "safe-buffer": "^5.0.1" } }, - "bitcoinjs-message": { - "version": "2.0.0", - "requires": { - "bs58check": "^2.0.2", - "buffer-equals": "^1.0.3", - "create-hash": "^1.1.2", - "secp256k1": "^3.0.1", - "varuint-bitcoin": "^1.0.1" - } - }, "bl": { "version": "5.0.0", "requires": { @@ -24058,9 +23181,6 @@ "buffer-equal-constant-time": { "version": "1.0.1" }, - "buffer-equals": { - "version": "1.0.4" - }, "buffer-from": { "version": "1.1.2", "optional": true @@ -24171,12 +23291,6 @@ "caseless": { "version": "0.12.0" }, - "cashaddrjs-slp": { - "version": "0.2.12", - "requires": { - "big-integer": "^1.6.34" - } - }, "catering": { "version": "2.1.1" }, @@ -24387,22 +23501,6 @@ "text-hex": "1.0.x" } }, - "combine-errors": { - "version": "3.0.3", - "requires": { - "custom-error-instance": "2.1.1", - "lodash.uniqby": "4.5.0" - }, - "dependencies": { - "lodash.uniqby": { - "version": "4.5.0", - "requires": { - "lodash._baseiteratee": "~4.7.0", - "lodash._baseuniq": "~4.6.0" - } - } - } - }, "combined-stream": { "version": "1.0.8", "requires": { @@ -24682,12 +23780,6 @@ "dev": true, "optional": true }, - "cuid": { - "version": "2.1.8" - }, - "custom-error-instance": { - "version": "2.1.1" - }, "dashdash": { "version": "1.14.1", "requires": { @@ -24759,31 +23851,6 @@ "type-detect": "^4.0.0" } }, - "deep-equal": { - "version": "2.0.5", - "requires": { - "call-bind": "^1.0.0", - "es-get-iterator": "^1.1.1", - "get-intrinsic": "^1.0.1", - "is-arguments": "^1.0.4", - "is-date-object": "^1.0.2", - "is-regex": "^1.1.1", - "isarray": "^2.0.5", - "object-is": "^1.1.4", - "object-keys": "^1.1.1", - "object.assign": "^4.1.2", - "regexp.prototype.flags": "^1.3.0", - "side-channel": "^1.0.3", - "which-boxed-primitive": "^1.0.1", - "which-collection": "^1.0.1", - "which-typed-array": "^1.1.2" - }, - "dependencies": { - "isarray": { - "version": "2.0.5" - } - } - }, "deep-extend": { "version": "0.6.0" }, @@ -24816,13 +23883,11 @@ }, "define-properties": { "version": "1.1.3", + "dev": true, "requires": { "object-keys": "^1.0.12" } }, - "defined": { - "version": "1.0.0" - }, "del": { "version": "6.0.0", "dev": true, @@ -24923,12 +23988,6 @@ "is-obj": "^2.0.0" } }, - "dotignore": { - "version": "0.1.2", - "requires": { - "minimatch": "^3.0.4" - } - }, "dottie": { "version": "2.0.2" }, @@ -24950,17 +24009,6 @@ "duplexer3": { "version": "0.1.4" }, - "ecashaddrjs": { - "version": "1.0.7", - "requires": { - "big-integer": "1.6.36" - }, - "dependencies": { - "big-integer": { - "version": "1.6.36" - } - } - }, "ecc-jsbn": { "version": "0.1.2", "requires": { @@ -24991,13 +24039,6 @@ "safe-buffer": "^5.0.1" } }, - "ecurve": { - "version": "1.0.6", - "requires": { - "bigi": "^1.1.0", - "safe-buffer": "^5.0.1" - } - }, "ee-first": { "version": "1.1.1" }, @@ -25241,6 +24282,7 @@ }, "es-abstract": { "version": "1.19.1", + "dev": true, "requires": { "call-bind": "^1.0.2", "es-to-primitive": "^1.2.1", @@ -25264,26 +24306,9 @@ "unbox-primitive": "^1.0.1" } }, - "es-get-iterator": { - "version": "1.1.2", - "requires": { - "call-bind": "^1.0.2", - "get-intrinsic": "^1.1.0", - "has-symbols": "^1.0.1", - "is-arguments": "^1.1.0", - "is-map": "^2.0.2", - "is-set": "^2.0.2", - "is-string": "^1.0.5", - "isarray": "^2.0.5" - }, - "dependencies": { - "isarray": { - "version": "2.0.5" - } - } - }, "es-to-primitive": { "version": "1.2.1", + "dev": true, "requires": { "is-callable": "^1.1.4", "is-date-object": "^1.0.1", @@ -26042,15 +25067,6 @@ "follow-redirects": { "version": "1.14.9" }, - "for-each": { - "version": "0.3.3", - "requires": { - "is-callable": "^1.1.3" - } - }, - "foreach": { - "version": "2.0.5" - }, "foreground-child": { "version": "2.0.0", "dev": true, @@ -26709,7 +25725,8 @@ "version": "1.0.2" }, "get-package-type": { - "version": "0.1.0" + "version": "0.1.0", + "dev": true }, "get-stdin": { "version": "8.0.0", @@ -26720,6 +25737,7 @@ }, "get-symbol-description": { "version": "1.0.0", + "dev": true, "requires": { "call-bind": "^1.0.2", "get-intrinsic": "^1.1.1" @@ -26901,18 +25919,12 @@ } }, "has-bigints": { - "version": "1.0.1" + "version": "1.0.1", + "dev": true }, "has-cors": { "version": "1.1.0" }, - "has-dynamic-import": { - "version": "2.0.1", - "requires": { - "call-bind": "^1.0.2", - "get-intrinsic": "^1.1.1" - } - }, "has-flag": { "version": "4.0.0" }, @@ -27192,6 +26204,7 @@ }, "internal-slot": { "version": "1.0.3", + "dev": true, "requires": { "get-intrinsic": "^1.1.0", "has": "^1.0.3", @@ -29198,19 +28211,13 @@ } } }, - "is-arguments": { - "version": "1.1.1", - "requires": { - "call-bind": "^1.0.2", - "has-tostringtag": "^1.0.0" - } - }, "is-arrayish": { "version": "0.2.1", "dev": true }, "is-bigint": { "version": "1.0.4", + "dev": true, "requires": { "has-bigints": "^1.0.1" } @@ -29227,6 +28234,7 @@ }, "is-boolean-object": { "version": "1.1.2", + "dev": true, "requires": { "call-bind": "^1.0.2", "has-tostringtag": "^1.0.0" @@ -29236,7 +28244,8 @@ "version": "2.0.5" }, "is-callable": { - "version": "1.2.4" + "version": "1.2.4", + "dev": true }, "is-ci": { "version": "2.0.0", @@ -29246,12 +28255,14 @@ }, "is-core-module": { "version": "2.6.0", + "dev": true, "requires": { "has": "^1.0.3" } }, "is-date-object": { "version": "1.0.5", + "dev": true, "requires": { "has-tostringtag": "^1.0.0" } @@ -29302,11 +28313,9 @@ "is-loopback-addr": { "version": "1.0.1" }, - "is-map": { - "version": "2.0.2" - }, "is-negative-zero": { - "version": "2.0.2" + "version": "2.0.2", + "dev": true }, "is-npm": { "version": "5.0.0" @@ -29317,6 +28326,7 @@ }, "is-number-object": { "version": "1.0.6", + "dev": true, "requires": { "has-tostringtag": "^1.0.0" } @@ -29340,28 +28350,29 @@ }, "is-regex": { "version": "1.1.4", + "dev": true, "requires": { "call-bind": "^1.0.2", "has-tostringtag": "^1.0.0" } }, - "is-set": { - "version": "2.0.2" - }, "is-shared-array-buffer": { - "version": "1.0.1" + "version": "1.0.1", + "dev": true }, "is-stream": { "version": "2.0.1" }, "is-string": { "version": "1.0.7", + "dev": true, "requires": { "has-tostringtag": "^1.0.0" } }, "is-symbol": { "version": "1.0.4", + "dev": true, "requires": { "has-symbols": "^1.0.2" } @@ -29373,35 +28384,16 @@ "text-extensions": "^1.0.0" } }, - "is-typed-array": { - "version": "1.1.8", - "requires": { - "available-typed-arrays": "^1.0.5", - "call-bind": "^1.0.2", - "es-abstract": "^1.18.5", - "foreach": "^2.0.5", - "has-tostringtag": "^1.0.0" - } - }, "is-typedarray": { "version": "1.0.0" }, - "is-weakmap": { - "version": "2.0.1" - }, "is-weakref": { "version": "1.0.2", + "dev": true, "requires": { "call-bind": "^1.0.2" } }, - "is-weakset": { - "version": "2.0.2", - "requires": { - "call-bind": "^1.0.2", - "get-intrinsic": "^1.1.1" - } - }, "is-windows": { "version": "1.0.2", "dev": true @@ -29791,12 +28783,6 @@ "joycon": { "version": "2.2.5" }, - "js-base64": { - "version": "2.6.4" - }, - "js-sha256": { - "version": "0.9.0" - }, "js-sha3": { "version": "0.8.0" }, @@ -30015,24 +29001,6 @@ "kcors": { "version": "2.2.2" }, - "keccak": { - "version": "3.0.2", - "requires": { - "node-addon-api": "^2.0.0", - "node-gyp-build": "^4.2.0", - "readable-stream": "^3.6.0" - }, - "dependencies": { - "readable-stream": { - "version": "3.6.0", - "requires": { - "inherits": "^2.0.3", - "string_decoder": "^1.1.1", - "util-deprecate": "^1.0.1" - } - } - } - }, "keygrip": { "version": "1.1.0", "requires": { @@ -30667,34 +29635,6 @@ "lodash": { "version": "4.17.21" }, - "lodash._baseiteratee": { - "version": "4.7.0", - "requires": { - "lodash._stringtopath": "~4.8.0" - } - }, - "lodash._basetostring": { - "version": "4.12.0" - }, - "lodash._baseuniq": { - "version": "4.6.0", - "requires": { - "lodash._createset": "~4.0.0", - "lodash._root": "~3.0.0" - } - }, - "lodash._createset": { - "version": "4.0.3" - }, - "lodash._root": { - "version": "3.0.1" - }, - "lodash._stringtopath": { - "version": "4.8.0", - "requires": { - "lodash._basetostring": "~4.12.0" - } - }, "lodash.camelcase": { "version": "4.3.0" }, @@ -30902,9 +29842,6 @@ "version": "1.4.1", "dev": true }, - "merkle-lib": { - "version": "2.0.10" - }, "methods": { "version": "1.1.2" }, @@ -30924,12 +29861,6 @@ "mime-db": { "version": "1.51.0" }, - "mime-match": { - "version": "1.0.2", - "requires": { - "wildcard": "^1.1.0" - } - }, "mime-types": { "version": "2.1.34", "requires": { @@ -31256,9 +30187,6 @@ "mutable-proxy": { "version": "1.0.0" }, - "namespace-emitter": { - "version": "2.0.1" - }, "nan": { "version": "2.15.0" }, @@ -34067,18 +32995,13 @@ "object-inspect": { "version": "1.11.0" }, - "object-is": { - "version": "1.1.5", - "requires": { - "call-bind": "^1.0.2", - "define-properties": "^1.1.3" - } - }, "object-keys": { - "version": "1.1.1" + "version": "1.1.1", + "dev": true }, "object.assign": { "version": "4.1.2", + "dev": true, "requires": { "call-bind": "^1.0.0", "define-properties": "^1.1.3", @@ -34310,6 +33233,31 @@ "p-try-each": { "version": "1.0.1" }, + "p2wdb": { + "version": "file:../p2wdb", + "requires": { + "apidoc": "0.25.0", + "axios": "0.24.0", + "browserify": "17.0.0", + "chai": "4.2.0", + "coveralls": "3.1.0", + "eslint": "7.17.0", + "eslint-config-prettier": "7.1.0", + "eslint-config-standard": "16.0.2", + "eslint-plugin-node": "11.1.0", + "eslint-plugin-prettier": "3.3.1", + "eslint-plugin-standard": "4.0.0", + "husky": "4.3.8", + "lodash.clonedeep": "4.5.0", + "minimal-slp-wallet": "3.5.2", + "mocha": "8.4.0", + "nyc": "15.1.0", + "semantic-release": "17.4.2", + "sinon": "9.2.2", + "standard": "16.0.4", + "tinyify": "3.0.0" + } + }, "package-hash": { "version": "4.0.0", "dev": true, @@ -34420,7 +33368,8 @@ "version": "3.1.1" }, "path-parse": { - "version": "1.0.7" + "version": "1.0.7", + "dev": true }, "path-to-regexp": { "version": "6.2.0" @@ -34662,9 +33611,6 @@ "semver-compare": "^1.0.0" } }, - "preact": { - "version": "8.2.9" - }, "prelude-ls": { "version": "1.2.1", "dev": true @@ -34862,12 +33808,6 @@ "side-channel": "^1.0.4" } }, - "qs-stringify": { - "version": "1.2.1" - }, - "querystringify": { - "version": "2.2.0" - }, "queue-microtask": { "version": "1.2.3" }, @@ -35132,6 +34072,7 @@ }, "regexp.prototype.flags": { "version": "1.3.1", + "dev": true, "requires": { "call-bind": "^1.0.2", "define-properties": "^1.1.3" @@ -35207,9 +34148,6 @@ "version": "2.0.0", "dev": true }, - "requires-port": { - "version": "1.0.0" - }, "resolve": { "version": "1.22.0", "dev": true, @@ -35265,12 +34203,6 @@ "lowercase-keys": "^1.0.0" } }, - "resumer": { - "version": "0.0.0", - "requires": { - "through": "~2.3.4" - } - }, "retimer": { "version": "3.0.0" }, @@ -35338,18 +34270,9 @@ "sparse-bitfield": "^3.0.3" } }, - "satoshi-bitcoin": { - "version": "1.0.4", - "requires": { - "big.js": "^3.1.3" - } - }, "sax": { "version": "1.2.4" }, - "scryptsy": { - "version": "2.1.0" - }, "secp256k1": { "version": "3.8.0", "requires": { @@ -35634,18 +34557,6 @@ "sliced": { "version": "1.0.1" }, - "slp-mdm": { - "version": "0.0.6", - "requires": { - "bignumber.js": "^9.0.0" - } - }, - "slp-parser": { - "version": "0.0.4", - "requires": { - "bignumber.js": "^9.0.0" - } - }, "snake-case": { "version": "3.0.4", "requires": { @@ -36067,16 +34978,9 @@ "side-channel": "^1.0.4" } }, - "string.prototype.trim": { - "version": "1.2.5", - "requires": { - "call-bind": "^1.0.2", - "define-properties": "^1.1.3", - "es-abstract": "^1.19.1" - } - }, "string.prototype.trimend": { "version": "1.0.4", + "dev": true, "requires": { "call-bind": "^1.0.2", "define-properties": "^1.1.3" @@ -36084,6 +34988,7 @@ }, "string.prototype.trimstart": { "version": "1.0.4", + "dev": true, "requires": { "call-bind": "^1.0.2", "define-properties": "^1.1.3" @@ -36203,55 +35108,6 @@ } } }, - "tape": { - "version": "5.5.2", - "requires": { - "array.prototype.every": "^1.1.3", - "call-bind": "^1.0.2", - "deep-equal": "^2.0.5", - "defined": "^1.0.0", - "dotignore": "^0.1.2", - "for-each": "^0.3.3", - "get-package-type": "^0.1.0", - "glob": "^7.2.0", - "has": "^1.0.3", - "has-dynamic-import": "^2.0.1", - "inherits": "^2.0.4", - "is-regex": "^1.1.4", - "minimist": "^1.2.5", - "object-inspect": "^1.12.0", - "object-is": "^1.1.5", - "object-keys": "^1.1.1", - "object.assign": "^4.1.2", - "resolve": "^2.0.0-next.3", - "resumer": "^0.0.0", - "string.prototype.trim": "^1.2.5", - "through": "^2.3.8" - }, - "dependencies": { - "glob": { - "version": "7.2.0", - "requires": { - "fs.realpath": "^1.0.0", - "inflight": "^1.0.4", - "inherits": "2", - "minimatch": "^3.0.4", - "once": "^1.3.0", - "path-is-absolute": "^1.0.0" - } - }, - "object-inspect": { - "version": "1.12.0" - }, - "resolve": { - "version": "2.0.0-next.3", - "requires": { - "is-core-module": "^2.2.0", - "path-parse": "^1.0.6" - } - } - } - }, "tar": { "version": "6.1.11", "requires": { @@ -36320,7 +35176,8 @@ "optional": true }, "through": { - "version": "2.3.8" + "version": "2.3.8", + "dev": true }, "through2": { "version": "2.0.5", @@ -36468,33 +35325,6 @@ "dev": true, "optional": true }, - "tus-js-client": { - "version": "1.8.0", - "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" - }, - "dependencies": { - "buffer-from": { - "version": "0.1.2" - }, - "proper-lockfile": { - "version": "2.0.1", - "requires": { - "graceful-fs": "^4.1.2", - "retry": "^0.10.0" - } - }, - "retry": { - "version": "0.10.1" - } - } - }, "tweetnacl": { "version": "0.14.5" }, @@ -36530,9 +35360,6 @@ "is-typedarray": "^1.0.0" } }, - "typeforce": { - "version": "1.18.0" - }, "uc.micro": { "version": "1.0.6", "dev": true @@ -36556,6 +35383,7 @@ }, "unbox-primitive": { "version": "1.0.1", + "dev": true, "requires": { "function-bind": "^1.1.1", "has-bigints": "^1.0.1", @@ -36636,13 +35464,6 @@ "version": "4.0.1", "dev": true }, - "url-parse": { - "version": "1.5.10", - "requires": { - "querystringify": "^2.1.1", - "requires-port": "^1.0.0" - } - }, "url-parse-lax": { "version": "3.0.0", "requires": { @@ -36694,12 +35515,6 @@ } } }, - "varuint-bitcoin": { - "version": "1.1.2", - "requires": { - "safe-buffer": "^5.1.1" - } - }, "vary": { "version": "1.1.2" }, @@ -36738,6 +35553,7 @@ }, "which-boxed-primitive": { "version": "1.0.2", + "dev": true, "requires": { "is-bigint": "^1.0.1", "is-boolean-object": "^1.1.0", @@ -36746,15 +35562,6 @@ "is-symbol": "^1.0.3" } }, - "which-collection": { - "version": "1.0.1", - "requires": { - "is-map": "^2.0.1", - "is-set": "^2.0.1", - "is-weakmap": "^2.0.1", - "is-weakset": "^2.0.1" - } - }, "which-module": { "version": "2.0.0", "dev": true @@ -36763,17 +35570,6 @@ "version": "1.1.0", "dev": true }, - "which-typed-array": { - "version": "1.1.7", - "requires": { - "available-typed-arrays": "^1.0.5", - "call-bind": "^1.0.2", - "es-abstract": "^1.18.5", - "foreach": "^2.0.5", - "has-tostringtag": "^1.0.0", - "is-typed-array": "^1.1.7" - } - }, "wide-align": { "version": "1.1.3", "devOptional": true, @@ -36806,9 +35602,6 @@ "bs58check": "<3.0.0" } }, - "wildcard": { - "version": "1.1.2" - }, "winston": { "version": "3.3.3", "requires": { diff --git a/package.json b/package.json index bd481cb..e207823 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,7 @@ }, "repository": "Permissionless-Software-Foundation/bch-dex", "dependencies": { - "@psf/bch-js": "5.3.2", + "@psf/bch-js": "../bch-js", "axios": "0.21.1", "bch-message-lib": "2.1.4", "bcryptjs": "2.4.3", @@ -55,6 +55,7 @@ "mongoose": "5.13.13", "node-fetch": "npm:@achingbrain/node-fetch@2.6.7", "nodemailer": "6.4.17", + "p2wdb": "../p2wdb", "passport-local": "1.0.0", "public-ip": "^4.0.4", "winston": "3.3.3", diff --git a/src/adapters/index.js b/src/adapters/index.js index ccc3fcb..0007287 100644 --- a/src/adapters/index.js +++ b/src/adapters/index.js @@ -18,7 +18,7 @@ const JSONFiles = require('./json-files') const FullStackJWT = require('./fullstack-jwt') const BCHAdapter = require('./bch') const WalletAdapter = require('./wallet') -const P2wdbAdapter = require('./p2wdb') +const P2wdbAdapter = require('./p2wdb-adapter') // // // Instantiate adapter libraries. @@ -52,10 +52,11 @@ class Adapters { this.nodemailer = new Nodemailer() this.jsonFiles = new JSONFiles() this.bchjs = new BCHJS() + localConfig.bchjs = this.bchjs this.bch = new BCHAdapter() this.config = config this.wallet = new WalletAdapter() - this.p2wdb = new P2wdbAdapter() + this.p2wdb = new P2wdbAdapter(localConfig) // Get a valid JWT API key and instance bch-js. this.fullStackJwt = new FullStackJWT(config) diff --git a/src/adapters/localdb/models/offer.js b/src/adapters/localdb/models/offer.js index e3b95f2..e0ac5aa 100644 --- a/src/adapters/localdb/models/offer.js +++ b/src/adapters/localdb/models/offer.js @@ -14,6 +14,7 @@ const Offer = new mongoose.Schema({ utxoTxid: { type: String }, utxoVout: { type: Number }, numTokens: { type: Number }, + hdIndex: { type: Number }, // HD index address holding the UTXO for this offer. // offerIpfsId: { type: String }, diff --git a/src/adapters/p2wdb-adapter.js b/src/adapters/p2wdb-adapter.js new file mode 100644 index 0000000..64158d0 --- /dev/null +++ b/src/adapters/p2wdb-adapter.js @@ -0,0 +1,107 @@ +/* + Adapter library for interacting with the P2WDB +*/ + +// Public npm libraries. +const axios = require('axios') +const { Write, Read } = require('p2wdb/index') + +// Local libraries +const config = require('../../config') + +class P2wdbAdapter { + constructor (localConfig = {}) { + // Dependency injection + this.bchjs = localConfig.bchjs + if (!this.bchjs) { + throw new Error('Must pass an instance of bch-js when instantiating p2wdb.js adapter.') + } + + // Encapsulate dependencies + this.axios = axios + this.config = config + this.Write = Write + this.Read = Read + + // Allow the localConfig to overwrite the config file values. + this.p2wdbURL = localConfig.p2wdbURL || config.p2wdbUrl + } + + // Write some data to the P2WDB + async write (inputObj = {}) { + try { + const { appId = 'test', data = {}, wif } = inputObj + + if (typeof wif !== 'string' || !wif) { + throw new Error('wif input must be a private key starting with the letter L or K') + } + + const p2write = this.instantiateWriteLib(wif) + + const result = await p2write.postEntry(data, appId) + + return result.hash + } catch (err) { + console.error('Error in p2wdb.js/write()') + throw err + } + } + + // Instantiate the Write library with a WIF, handling the various config + // settings. + instantiateWriteLib (wif) { + try { + // Object used to configure the Write library. + let configObj = {} + + if (this.config.useFullStackCash) { + // Use web 2 infrastructure. + // bch-js and FullStack.cash + + configObj = { + wif, + serverURL: this.p2wdbURL, + restURL: this.bchjs.restURL, + apiToken: this.bchjs.apiToken + } + } else { + // Use web 3 infrastructure. + // ipfs-bch-wallet-consumer and bch-consumer library + + configObj = { + wif, + serverURL: this.p2wdbURL, + interface: 'consumer-api', + restURL: this.config.consumerUrl + } + } + + const write = new this.Write(configObj) + + return write + } catch (err) { + console.error('Error in p2wdb-adapter.js/instantitateWriteLib()') + throw err + } + } + + // Returns a promise that resolves to true or false, to indicate if the + // WIF controls the required funds to write to the P2WDB. + async checkForSufficientFunds (wif) { + try { + if (typeof wif !== 'string' || !wif) { + throw new Error('invalid wif to check for funds') + } + + // Instatiate the Write library + const p2write = this.instantiateWriteLib(wif) + + return await p2write.checkForSufficientFunds() + } catch (err) { + console.error('Error in p2wdb.js/checkForSufficientFunds()') + throw err + } + } +} + +module.exports = P2wdbAdapter diff --git a/src/adapters/p2wdb.js b/src/adapters/p2wdb.js deleted file mode 100644 index bde7012..0000000 --- a/src/adapters/p2wdb.js +++ /dev/null @@ -1,57 +0,0 @@ -/* - Adapter library for interacting with the P2WDB -*/ - -// Public npm libraries. -const axios = require('axios') - -// Local libraries -const config = require('../../config') - -// Global constants -let P2WDB_SERVER = 'http://localhost:5001/entry/write' -// const P2WDB_SERVER = 'https://p2wdb.fullstack.cash/entry/write' - -class P2wdbAdapter { - constructor (localConfig = {}) { - // Encapsulate dependencies - this.axios = axios - this.config = config - - P2WDB_SERVER = `http://localhost:${config.p2wdbPort}/entry/write` - } - - async write (inputObj) { - try { - const { txid, signature, message, appId, data } = inputObj - - // TODO: Input validation - - const now = new Date() - - const dataObj = { - appId, - data, - timestamp: now.toISOString(), - localTimeStamp: now.toLocaleString() - } - - const bodyData = { - txid, - message, - signature, - data: JSON.stringify(dataObj) - } - - const result = await this.axios.post(P2WDB_SERVER, bodyData) - // console.log(`Response from API: ${JSON.stringify(result.data, null, 2)}`) - - return result.data.hash - } catch (err) { - console.error('Error in p2wdb.js/write()') - throw err - } - } -} - -module.exports = P2wdbAdapter diff --git a/test/integration/adapters/p2wdb-adapter-integration.js b/test/integration/adapters/p2wdb-adapter-integration.js new file mode 100644 index 0000000..f3b90ab --- /dev/null +++ b/test/integration/adapters/p2wdb-adapter-integration.js @@ -0,0 +1,54 @@ +/* + Integration tests for hte p2wdb-adapter.js library + + These integration tests may not necessarily pass. They require a WIF set + as an environment variable, and loaded with enough BCH and PSF to make + a write to the P2WDB. + + If these tests fail, it does not necessarily mean there is a problem with the + code. Check that the WIF envrionment variable meets the requirements. +*/ + +// Public npm libraries +const BCHJS = require('@psf/bch-js') + +// Local libraries +const P2wdbAdapter = require('../../../src/adapters/p2wdb-adapter') + +const wif = process.env.WIF +if (!wif) { + throw new Error('You must provide a BCH WIF private key as an environment variable to run this test.') +} + +describe('#p2wdb-adapter.js', () => { + let uut + + beforeEach(() => { + const bchjs = new BCHJS() + + uut = new P2wdbAdapter({ bchjs }) + }) + + describe('#checkForSufficientFunds', () => { + it('should check for sufficient funds', async () => { + const result = await uut.checkForSufficientFunds(wif) + + console.log('Provided WIF has funds for making a write: ', result) + }) + }) + + describe('#write', () => { + it('should write data to the P2WDB', async () => { + const inObj = { + appId: 'test234', + data: { + key: 'value' + }, + wif + } + + const result = await uut.write(inObj) + console.log('result: ', result) + }) + }) +}) diff --git a/test/integration/adapters/wallet.adapter.integration.js b/test/integration/adapters/wallet-adapter-integration.js similarity index 100% rename from test/integration/adapters/wallet.adapter.integration.js rename to test/integration/adapters/wallet-adapter-integration.js diff --git a/test/unit/adapters/p2wdb.adapter.unit.js b/test/unit/adapters/p2wdb.adapter.unit.js index 696e146..7736c77 100644 --- a/test/unit/adapters/p2wdb.adapter.unit.js +++ b/test/unit/adapters/p2wdb.adapter.unit.js @@ -5,48 +5,141 @@ // Public npm libraries. const assert = require('chai').assert const sinon = require('sinon') +const BCHJS = require('@psf/bch-js') // Local libraries. -const P2wdbAdapter = require('../../../src/adapters/p2wdb') +const P2wdbAdapter = require('../../../src/adapters/p2wdb-adapter') describe('#P2wdbAdapter', () => { let uut, sandbox beforeEach(() => { - uut = new P2wdbAdapter() + const bchjs = new BCHJS() + + uut = new P2wdbAdapter({ bchjs }) sandbox = sinon.createSandbox() }) afterEach(() => sandbox.restore()) - describe('#write', () => { - it('should write an offer to the P2WDB', async () => { - const inputObj = { - txid: 'testTxid', - signature: 'testSignature', - message: 'testMessage', - appId: 'testAppId', - data: { key: 'value' } + describe('#constructor', () => { + it('should throw error if bch-js is not passed in', () => { + try { + uut = new P2wdbAdapter() + + assert.fail('Unexpected coded path') + } catch (err) { + assert.include(err.message, 'Must pass an instance of bch-js when instantiating p2wdb.js adapter.') } + }) + }) - // Mock axios to prevent live network call - sandbox.stub(uut.axios, 'post').resolves({ data: { hash: 'testhash' } }) + describe('#instantiateWriteLib', () => { + it('should instantiate Write library using web 3 interface', async () => { + // Force code path + uut.config.useFullStackCash = false - const result = await uut.write(inputObj) + // Mock dependencies + uut.Write = + class Write { + constructor () { + this.interface = 'web3' + } + } + + const wif = 'L1tcvcqa5PztqqDH4ZEcUmHA9aSHhTau5E2Zwp1xEK5CrKBrjP3m' + + const result = uut.instantiateWriteLib(wif) // console.log('result: ', result) - assert.equal(result, 'testhash') + assert.equal(result.interface, 'web3') + }) + + it('should instantiate Write library using web 2 interface', async () => { + // Force code path + uut.config.useFullStackCash = true + + // Mock dependencies + uut.Write = + class Write { + constructor () { + this.interface = 'fullstack' + } + } + + const wif = 'L1tcvcqa5PztqqDH4ZEcUmHA9aSHhTau5E2Zwp1xEK5CrKBrjP3m' + + const result = uut.instantiateWriteLib(wif) + // console.log('result: ', result) + + assert.equal(result.interface, 'fullstack') }) it('should catch and throw errors', async () => { + try { + await uut.instantiateWriteLib() + + assert.fail('Unexpected code path') + } catch (err) { + // console.log(err) + assert.include(err.message, 'WIF private key required') + } + }) + }) + + describe('#checkForSufficientFunds', () => { + it('should throw error if WIF is not provided', async () => { + try { + await uut.checkForSufficientFunds() + + assert.fail('Unexpected code path') + } catch (err) { + // console.log(err) + assert.include(err.message, 'invalid wif to check for funds') + } + }) + + it('should return status of funds', async () => { + // Mock dependencies + sandbox.stub(uut, 'instantiateWriteLib').returns({ + checkForSufficientFunds: () => true + }) + + const wif = 'L1tcvcqa5PztqqDH4ZEcUmHA9aSHhTau5E2Zwp1xEK5CrKBrjP3m' + + const result = await uut.checkForSufficientFunds(wif) + + assert.equal(result, true) + }) + }) + + describe('#write', async () => { + it('should throw error if WIF is not provided', async () => { try { await uut.write() assert.fail('Unexpected code path') } catch (err) { // console.log(err) - assert.include(err.message, 'Cannot destructure property') + assert.include(err.message, 'wif input must be a private key starting with the letter L or K') } }) + + it('should write data to the P2WDB', async () => { + // Mock dependencies + sandbox.stub(uut, 'instantiateWriteLib').returns({ + postEntry: async () => { + return { hash: 'fake-hash' } + } + }) + + const wif = 'L1tcvcqa5PztqqDH4ZEcUmHA9aSHhTau5E2Zwp1xEK5CrKBrjP3m' + const inObj = { wif } + + const result = await uut.write(inObj) + // console.log('result: ', result) + + assert.equal(result, 'fake-hash') + }) }) })