From 1f194e2cf4b2b8a1e33b7401676a33b09cf46ec9 Mon Sep 17 00:00:00 2001 From: Pengyu Chen Date: Wed, 20 Dec 2023 18:04:11 -0700 Subject: [PATCH 1/2] fix(sdk-api): fix proxy-agent usage We removed the superagent-proxy earlier to use proxy-agent. The change missed some old usage. Change the proxy-agent version to 5.0. This is the version that was used under the hood. The new version requires setting proxy url in the environment variable. It does not quite fit how we use the proxy-agent currently. Ticket: WP-1185 --- modules/sdk-api/package.json | 2 +- modules/sdk-api/src/bitgoAPI.ts | 10 +- yarn.lock | 212 +++++++++++++++++--------------- 3 files changed, 121 insertions(+), 103 deletions(-) diff --git a/modules/sdk-api/package.json b/modules/sdk-api/package.json index c5497b02e4..6886049ce3 100644 --- a/modules/sdk-api/package.json +++ b/modules/sdk-api/package.json @@ -62,7 +62,7 @@ "debug": "3.1.0", "eol": "^0.5.0", "lodash": "^4.17.15", - "proxy-agent": "6.3.1", + "proxy-agent": "5.0.0", "sanitize-html": "^2.11", "secp256k1": "^4.0.2", "secrets.js-grempe": "^1.1.0", diff --git a/modules/sdk-api/src/bitgoAPI.ts b/modules/sdk-api/src/bitgoAPI.ts index 7f5c68cc02..19d2d6d315 100644 --- a/modules/sdk-api/src/bitgoAPI.ts +++ b/modules/sdk-api/src/bitgoAPI.ts @@ -98,7 +98,7 @@ const TransactionBuilder = require('./v1/transactionBuilder'); let proxyAgent: any; if (!isBrowser && !isWebWorker) { debug('enabling proxy-agent'); - proxyAgent = require('proxy-agent').ProxyAgent; + proxyAgent = require('proxy-agent'); } const patchedRequestMethods = ['get', 'post', 'put', 'del', 'patch'] as const; @@ -574,7 +574,13 @@ export class BitGoAPI implements BitGoBase { // Proxy settings must still be respected however const resultPromise = this.getAgentRequest('get', this.url('/client/constants')); resultPromise.set('BitGo-SDK-Version', this._version); - const result = await (this._proxy ? resultPromise.proxy(this._proxy) : resultPromise); + if (this._proxy) { + const agent = new proxyAgent(this._proxy); + if (agent) { + resultPromise.agent(agent); + } + } + const result = await resultPromise; BitGoAPI._constants[env] = result.body.constants; if (result.body?.ttl && typeof result.body?.ttl === 'number') { diff --git a/yarn.lock b/yarn.lock index 0de27bf99f..eefe2902c7 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4678,16 +4678,16 @@ lz-string "^1.4.4" pretty-format "^27.0.2" +"@tootallnate/once@1": + version "1.1.2" + resolved "https://registry.yarnpkg.com/@tootallnate/once/-/once-1.1.2.tgz#ccb91445360179a04e7fe6aff78c00ffc1eeaf82" + integrity sha512-RbzJvlNzmRq5c3O09UipeuXno4tA1FE6ikOjxZK0tuxVv3412l64l5t1W5pj4+rJq9vpkm/kwiR07aZXnsKPxw== + "@tootallnate/once@2": version "2.0.0" resolved "https://registry.npmjs.org/@tootallnate/once/-/once-2.0.0.tgz" integrity sha512-XCuKFP5PS55gnMVu3dty8KPatLqUoy/ZYzDzAGCQ8JNFCkLXzmI7vNHCR+XpbZaMWQK/vQubr7PkYq8g470J/A== -"@tootallnate/quickjs-emscripten@^0.23.0": - version "0.23.0" - resolved "https://registry.npmjs.org/@tootallnate/quickjs-emscripten/-/quickjs-emscripten-0.23.0.tgz" - integrity sha512-C5Mc6rdnsaJDjO3UpGW/CQTHtCKaYlScZTly4JIu97Jxo/odCiH0ITnDXSJPTOrEKk/ycSZ0AOgTmkDtkOsvIA== - "@tronweb3/google-protobuf@^3.21.2": version "3.21.2" resolved "https://registry.npmjs.org/@tronweb3/google-protobuf/-/google-protobuf-3.21.2.tgz" @@ -5898,7 +5898,7 @@ agent-base@5: resolved "https://registry.npmjs.org/agent-base/-/agent-base-5.1.1.tgz" integrity sha512-TMeqbNl2fMW0nMjTEPOwe3J/PRFP4vqeoNuQMG0HlMrtm5QxKqdvAkZ1pRBQ/ulIyDD5Yq0nJ7YbdD8ey0TO3g== -agent-base@6, agent-base@^6.0.2: +agent-base@6, agent-base@^6.0.0, agent-base@^6.0.2: version "6.0.2" resolved "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz" integrity sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ== @@ -5912,13 +5912,6 @@ agent-base@^4.3.0: dependencies: es6-promisify "^5.0.0" -agent-base@^7.0.2, agent-base@^7.1.0: - version "7.1.0" - resolved "https://registry.npmjs.org/agent-base/-/agent-base-7.1.0.tgz" - integrity sha512-o/zjMZRhJxny7OyEF+Op8X+efiELC7k7yOjMzgfzVqOzXqkBkWI79YoTdOtsuWd5BWhAGAuOY/Xa6xpiaWXiNg== - dependencies: - debug "^4.3.4" - agentkeepalive@^4.2.1: version "4.3.0" resolved "https://registry.npmjs.org/agentkeepalive/-/agentkeepalive-4.3.0.tgz" @@ -6620,11 +6613,6 @@ basic-auth@~2.0.1: dependencies: safe-buffer "5.1.2" -basic-ftp@^5.0.2: - version "5.0.3" - resolved "https://registry.npmjs.org/basic-ftp/-/basic-ftp-5.0.3.tgz" - integrity sha512-QHX8HLlncOLpy54mh+k/sWIFd0ThmRqwe9ZjELybGZK+tZ8rUb9VO0saKJUROTbE+KhzDUT7xziGpGrW8Kmd+g== - batch@0.6.1: version "0.6.1" resolved "https://registry.npmjs.org/batch/-/batch-0.6.1.tgz" @@ -8573,16 +8561,16 @@ dashdash@^1.12.0: dependencies: assert-plus "^1.0.0" +data-uri-to-buffer@3: + version "3.0.1" + resolved "https://registry.yarnpkg.com/data-uri-to-buffer/-/data-uri-to-buffer-3.0.1.tgz#594b8973938c5bc2c33046535785341abc4f3636" + integrity sha512-WboRycPNsVw3B3TL559F7kuBUM4d8CgMEvk6xEJlOp7OBPjt6G7z8WMWlD2rOFZLk6OYfFIUGsCOWzcQH9K2og== + data-uri-to-buffer@^4.0.0: version "4.0.1" resolved "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz" integrity sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A== -data-uri-to-buffer@^5.0.1: - version "5.0.1" - resolved "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-5.0.1.tgz" - integrity sha512-a9l6T1qqDogvvnw0nKlfZzqsyikEBZBClF39V3TFoKhDtGBqHu2HkuomJc02j5zft8zrUaXEuoicLeW54RkzPg== - date-format@^4.0.14: version "4.0.14" resolved "https://registry.npmjs.org/date-format/-/date-format-4.0.14.tgz" @@ -8826,7 +8814,7 @@ defined@^1.0.0, defined@~1.0.1: resolved "https://registry.npmjs.org/defined/-/defined-1.0.1.tgz" integrity sha512-hsBd2qSVCRE+5PmNdHt1uzyrFu5d3RwmFDKzyNZMFq/EwDNJF7Ee5+D5oEKF0hU6LhtoUF1macFvOe4AskQC1Q== -degenerator@5.0.0, degenerator@^5.0.0: +degenerator@5.0.0, degenerator@^3.0.2: version "5.0.0" resolved "https://registry.yarnpkg.com/degenerator/-/degenerator-5.0.0.tgz#ccf1f07e95d81354398fbaf40c9d523202feb751" integrity sha512-pdRxyYVe0unlUE/eeXBxFdB8w8J7QNNf7hFE/BKOAlTCz0bkF9h1MC82ii0r1ypqB/PTKYDbg4K9SZT9yfd9Fg== @@ -10492,6 +10480,11 @@ file-uri-to-path@1.0.0: resolved "https://registry.npmjs.org/file-uri-to-path/-/file-uri-to-path-1.0.0.tgz" integrity sha512-0Zt+s3L7Vf1biwWZ29aARiVYLx7iMGnEUl9x33fbB/j3jR81u/O2LbqK+Bm1CDSNDKVtJ/YjwY7TUd5SkeLQLw== +file-uri-to-path@2: + version "2.0.0" + resolved "https://registry.yarnpkg.com/file-uri-to-path/-/file-uri-to-path-2.0.0.tgz#7b415aeba227d575851e0a5b0c640d7656403fba" + integrity sha512-hjPFI8oE/2iQPVe4gbrJ73Pp+Xfub2+WI2LlXDbsaJBwT5wuMh35WNWVYYTpnz895shtwfyutMFLFywpQAFdLg== + filelist@^1.0.1: version "1.0.4" resolved "https://registry.npmjs.org/filelist/-/filelist-1.0.4.tgz" @@ -10820,6 +10813,14 @@ fsevents@~2.3.2: resolved "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz" integrity sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA== +ftp@^0.3.10: + version "0.3.10" + resolved "https://registry.yarnpkg.com/ftp/-/ftp-0.3.10.tgz#9197d861ad8142f3e63d5a83bfe4c59f7330885d" + integrity sha512-faFVML1aBx2UoDStmLwv2Wptt4vw5x03xxX172nhA5Y5HBshW5JweqQ2W4xL4dezQTG8inJsuYcpPHHU3X5OTQ== + dependencies: + readable-stream "1.1.x" + xregexp "2.0.0" + function-bind@^1.1.1: version "1.1.1" resolved "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz" @@ -10940,15 +10941,17 @@ get-symbol-description@^1.0.0: call-bind "^1.0.2" get-intrinsic "^1.1.1" -get-uri@^6.0.1: - version "6.0.1" - resolved "https://registry.npmjs.org/get-uri/-/get-uri-6.0.1.tgz" - integrity sha512-7ZqONUVqaabogsYNWlYj0t3YZaL6dhuEueZXGF+/YVmf6dHmaFg8/6psJKqhx9QykIDKzpGcy2cn4oV4YC7V/Q== +get-uri@3: + version "3.0.2" + resolved "https://registry.yarnpkg.com/get-uri/-/get-uri-3.0.2.tgz#f0ef1356faabc70e1f9404fa3b66b2ba9bfc725c" + integrity sha512-+5s0SJbGoyiJTZZ2JTpFPLMPSch72KEqGOTvQsBqg0RBWvwhWUSYZFAtz3TPW0GXJuLBJPts1E241iHg+VRfhg== dependencies: - basic-ftp "^5.0.2" - data-uri-to-buffer "^5.0.1" - debug "^4.3.4" + "@tootallnate/once" "1" + data-uri-to-buffer "3" + debug "4" + file-uri-to-path "2" fs-extra "^8.1.0" + ftp "^0.3.10" get-value@^2.0.3, get-value@^2.0.6: version "2.0.6" @@ -11563,6 +11566,15 @@ http-parser-js@>=0.5.1: resolved "https://registry.npmjs.org/http-parser-js/-/http-parser-js-0.5.8.tgz" integrity sha512-SGeBX54F94Wgu5RH3X5jsDtf4eHyRogWX1XGT3b4HuW3tQPM4AaBzoUji/4AAJNXCEOWZ5O0DgZmJw1947gD5Q== +http-proxy-agent@^4.0.0, http-proxy-agent@^4.0.1: + version "4.0.1" + resolved "https://registry.yarnpkg.com/http-proxy-agent/-/http-proxy-agent-4.0.1.tgz#8a8c8ef7f5932ccf953c296ca8291b95aa74aa3a" + integrity sha512-k0zdNgqWTGA6aeIRVpvfVob4fL52dTfaehylg0Y4UvSySvOq/Y+BOyPrgpUrA7HylqvU8vIZGsRuXmspskV0Tg== + dependencies: + "@tootallnate/once" "1" + agent-base "6" + debug "4" + http-proxy-agent@^5.0.0: version "5.0.0" resolved "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-5.0.0.tgz" @@ -11572,14 +11584,6 @@ http-proxy-agent@^5.0.0: agent-base "6" debug "4" -http-proxy-agent@^7.0.0: - version "7.0.0" - resolved "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-7.0.0.tgz" - integrity sha512-+ZT+iBxVUQ1asugqnD6oWoRiS25AkjNfG085dKJGtGxkdwLQrMKU5wJr2bOOFAXzKcTuqq+7fZlTMgG3SRfIYQ== - dependencies: - agent-base "^7.1.0" - debug "^4.3.4" - http-proxy-middleware@^2.0.3: version "2.0.6" resolved "https://registry.npmjs.org/http-proxy-middleware/-/http-proxy-middleware-2.0.6.tgz" @@ -11631,6 +11635,14 @@ https-browserify@^1.0.0: resolved "https://registry.npmjs.org/https-browserify/-/https-browserify-1.0.0.tgz" integrity sha512-J+FkSdyD+0mA0N+81tMotaRMfSL9SGi+xpD3T6YApKsc3bGSXJlfXri3VyFOeYkfLRQisDk1W+jIFFKBeUBbBg== +https-proxy-agent@5, https-proxy-agent@^5.0.0: + version "5.0.1" + resolved "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz" + integrity sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA== + dependencies: + agent-base "6" + debug "4" + https-proxy-agent@^3.0.0: version "3.0.1" resolved "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-3.0.1.tgz" @@ -11647,22 +11659,6 @@ https-proxy-agent@^4.0.0: agent-base "5" debug "4" -https-proxy-agent@^5.0.0: - version "5.0.1" - resolved "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz" - integrity sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA== - dependencies: - agent-base "6" - debug "4" - -https-proxy-agent@^7.0.2: - version "7.0.2" - resolved "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-7.0.2.tgz" - integrity sha512-NmLNjm6ucYwtcUmL7JQC1ZQ57LmHP4lT15FQ8D61nak1rO6DH+fz5qNK2Ap5UN4ZapYICE3/0KodcLYSPsPbaA== - dependencies: - agent-base "^7.0.2" - debug "4" - human-signals@^1.1.1: version "1.1.1" resolved "https://registry.npmjs.org/human-signals/-/human-signals-1.1.1.tgz" @@ -11915,9 +11911,9 @@ io-ts@2.0.1, io-ts@2.2.20, io-ts@^2.2.20: resolved "https://registry.yarnpkg.com/io-ts/-/io-ts-2.2.20.tgz#be42b75f6668a2c44f706f72ee6e4c906777c7f5" integrity sha512-Rq2BsYmtwS5vVttie4rqrOCIfHCS9TgpRLFpKQCM1wZBBRY9nWVGmEvm2FnDbSE2un1UE39DvFpTR5UL47YDcA== -ip@^1.1.8: +ip@^1.1.5: version "1.1.8" - resolved "https://registry.npmjs.org/ip/-/ip-1.1.8.tgz" + resolved "https://registry.yarnpkg.com/ip/-/ip-1.1.8.tgz#ae05948f6b075435ed3307acce04629da8cdbf48" integrity sha512-PuExPYUiu6qMBQb4l06ecm6T6ujzhmh+MeJcW9wa89PoAz5pvd4zPgN5WJV104mb6S2T1AwNIAaB70JNrLQWhg== ip@^2.0.0: @@ -13406,7 +13402,7 @@ lru-cache@^6.0.0: dependencies: yallist "^4.0.0" -lru-cache@^7.14.1, lru-cache@^7.4.4, lru-cache@^7.5.1, lru-cache@^7.7.1: +lru-cache@^7.4.4, lru-cache@^7.5.1, lru-cache@^7.7.1: version "7.18.3" resolved "https://registry.npmjs.org/lru-cache/-/lru-cache-7.18.3.tgz" integrity sha512-jumlc0BIUrS3qJGgIkWZsyfAM7NCWiBcCDhnd+3NNM5KbBmLTgHVfWBcg6W+rLUsIpzpERPsvwUP7CckAQSOoA== @@ -14877,27 +14873,28 @@ p-waterfall@^2.1.1: dependencies: p-reduce "^2.0.0" -pac-proxy-agent@^7.0.1: - version "7.0.1" - resolved "https://registry.npmjs.org/pac-proxy-agent/-/pac-proxy-agent-7.0.1.tgz" - integrity sha512-ASV8yU4LLKBAjqIPMbrgtaKIvxQri/yh2OpI+S6hVa9JRkUI3Y3NPFbfngDtY7oFtSMD3w31Xns89mDa3Feo5A== +pac-proxy-agent@^5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/pac-proxy-agent/-/pac-proxy-agent-5.0.0.tgz#b718f76475a6a5415c2efbe256c1c971c84f635e" + integrity sha512-CcFG3ZtnxO8McDigozwE3AqAw15zDvGH+OjXO4kzf7IkEKkQ4gxQ+3sdF50WmhQ4P/bVusXcqNE2S3XrNURwzQ== dependencies: - "@tootallnate/quickjs-emscripten" "^0.23.0" - agent-base "^7.0.2" - debug "^4.3.4" - get-uri "^6.0.1" - http-proxy-agent "^7.0.0" - https-proxy-agent "^7.0.2" - pac-resolver "^7.0.0" - socks-proxy-agent "^8.0.2" - -pac-resolver@^7.0.0: - version "7.0.0" - resolved "https://registry.npmjs.org/pac-resolver/-/pac-resolver-7.0.0.tgz" - integrity sha512-Fd9lT9vJbHYRACT8OhCbZBbxr6KRSawSovFpy8nDGshaK99S/EBhVIHp9+crhxrsZOuvLpgL1n23iyPg6Rl2hg== + "@tootallnate/once" "1" + agent-base "6" + debug "4" + get-uri "3" + http-proxy-agent "^4.0.1" + https-proxy-agent "5" + pac-resolver "^5.0.0" + raw-body "^2.2.0" + socks-proxy-agent "5" + +pac-resolver@^5.0.0: + version "5.0.1" + resolved "https://registry.yarnpkg.com/pac-resolver/-/pac-resolver-5.0.1.tgz#c91efa3a9af9f669104fa2f51102839d01cde8e7" + integrity sha512-cy7u00ko2KVgBAjuhevqpPeHIkCIqPe1v24cydhWjmeuzaBfmUWFCZJ1iAh5TuVzVZoUzXIW7K8sMYOZ84uZ9Q== dependencies: - degenerator "^5.0.0" - ip "^1.1.8" + degenerator "^3.0.2" + ip "^1.1.5" netmask "^2.0.2" package-hash@^4.0.0: @@ -15771,19 +15768,19 @@ proxy-addr@~2.0.7: forwarded "0.2.0" ipaddr.js "1.9.1" -proxy-agent@6.3.1: - version "6.3.1" - resolved "https://registry.npmjs.org/proxy-agent/-/proxy-agent-6.3.1.tgz" - integrity sha512-Rb5RVBy1iyqOtNl15Cw/llpeLH8bsb37gM1FUfKQ+Wck6xHlbAhWGUFiTRHtkjqGTA5pSHz6+0hrPW/oECihPQ== +proxy-agent@5.0.0: + version "5.0.0" + resolved "https://registry.yarnpkg.com/proxy-agent/-/proxy-agent-5.0.0.tgz#d31405c10d6e8431fde96cba7a0c027ce01d633b" + integrity sha512-gkH7BkvLVkSfX9Dk27W6TyNOWWZWRilRfk1XxGNWOYJ2TuedAv1yFpCaU9QSBmBe716XOTNpYNOzhysyw8xn7g== dependencies: - agent-base "^7.0.2" - debug "^4.3.4" - http-proxy-agent "^7.0.0" - https-proxy-agent "^7.0.2" - lru-cache "^7.14.1" - pac-proxy-agent "^7.0.1" - proxy-from-env "^1.1.0" - socks-proxy-agent "^8.0.2" + agent-base "^6.0.0" + debug "4" + http-proxy-agent "^4.0.0" + https-proxy-agent "^5.0.0" + lru-cache "^5.1.1" + pac-proxy-agent "^5.0.0" + proxy-from-env "^1.0.0" + socks-proxy-agent "^5.0.0" proxy-from-env@1.0.0: version "1.0.0" @@ -16020,7 +16017,7 @@ raw-body@2.5.1: iconv-lite "0.4.24" unpipe "1.0.0" -raw-body@2.5.2: +raw-body@2.5.2, raw-body@^2.2.0: version "2.5.2" resolved "https://registry.npmjs.org/raw-body/-/raw-body-2.5.2.tgz" integrity sha512-8zGqypfENjCIqGhgXToC8aB2r7YrBX+AQAfIPs/Mlk+BtPTztOvTS01NRW/3Eh60J+a48lt8qsCzirQ6loCVfA== @@ -16186,6 +16183,16 @@ read@1, read@^1.0.7: dependencies: mute-stream "~0.0.4" +readable-stream@1.1.x: + version "1.1.14" + resolved "https://registry.yarnpkg.com/readable-stream/-/readable-stream-1.1.14.tgz#7cf4c54ef648e3813084c636dd2079e166c081d9" + integrity sha512-+MeVjFf4L44XUkhM1eYbD8fyEsxcV81pqMSR5gblfcLCHfZvbrqy4/qYHE+/R5HoBUT11WV5O08Cr1n3YXkWVQ== + dependencies: + core-util-is "~1.0.0" + inherits "~2.0.1" + isarray "0.0.1" + string_decoder "~0.10.x" + readable-stream@3, readable-stream@^3.0.0, readable-stream@^3.0.2, readable-stream@^3.0.6, readable-stream@^3.1.1, readable-stream@^3.4.0, readable-stream@^3.5.0, readable-stream@^3.6.0, readable-stream@^3.6.2: version "3.6.2" resolved "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz" @@ -17372,6 +17379,15 @@ sockjs@^0.3.24: uuid "^8.3.2" websocket-driver "^0.7.4" +socks-proxy-agent@5, socks-proxy-agent@^5.0.0: + version "5.0.1" + resolved "https://registry.yarnpkg.com/socks-proxy-agent/-/socks-proxy-agent-5.0.1.tgz#032fb583048a29ebffec2e6a73fca0761f48177e" + integrity sha512-vZdmnjb9a2Tz6WEQVIurybSwElwPxMZaIc7PzqbJTrezcKNznv6giT7J7tZDZ1BojVaa1jvO/UiUdhDVB0ACoQ== + dependencies: + agent-base "^6.0.2" + debug "4" + socks "^2.3.3" + socks-proxy-agent@^7.0.0: version "7.0.0" resolved "https://registry.npmjs.org/socks-proxy-agent/-/socks-proxy-agent-7.0.0.tgz" @@ -17381,16 +17397,7 @@ socks-proxy-agent@^7.0.0: debug "^4.3.3" socks "^2.6.2" -socks-proxy-agent@^8.0.2: - version "8.0.2" - resolved "https://registry.npmjs.org/socks-proxy-agent/-/socks-proxy-agent-8.0.2.tgz" - integrity sha512-8zuqoLv1aP/66PHF5TqwJ7Czm3Yv32urJQHrVyhD7mmA6d61Zv8cIXQYPTWwmg6qlupnPvs/QKDmfa4P/qct2g== - dependencies: - agent-base "^7.0.2" - debug "^4.3.4" - socks "^2.7.1" - -socks@^2.6.2, socks@^2.7.1: +socks@^2.3.3, socks@^2.6.2: version "2.7.1" resolved "https://registry.npmjs.org/socks/-/socks-2.7.1.tgz" integrity sha512-7maUZy1N7uo6+WVEX6psASxtNlKaNVMlGQKkG/63nEDdLOWNbiUMoLK7X4uYoLhQstau72mLgfEWcXcwsaHbYQ== @@ -19788,6 +19795,11 @@ xmlhttprequest-ssl@~1.6.2: resolved "https://registry.npmjs.org/xmlhttprequest-ssl/-/xmlhttprequest-ssl-1.6.3.tgz" integrity sha512-3XfeQE/wNkvrIktn2Kf0869fC0BN6UpydVasGIeSm2B1Llihf7/0UfZM+eCkOw3P7bP4+qPgqhm7ZoxuJtFU0Q== +xregexp@2.0.0: + version "2.0.0" + resolved "https://registry.yarnpkg.com/xregexp/-/xregexp-2.0.0.tgz#52a63e56ca0b84a7f3a5f3d61872f126ad7a5943" + integrity sha512-xl/50/Cf32VsGq/1R8jJE5ajH1yMCQkpmoS10QbFZWl2Oor4H0Me64Pu2yxvsRWK3m6soJbmGfzSR7BYmDcWAA== + xss@1.0.13: version "1.0.13" resolved "https://registry.npmjs.org/xss/-/xss-1.0.13.tgz" From b8e3e07b088413d5b2ef12a9829bce620bbd6a64 Mon Sep 17 00:00:00 2001 From: Pengyu Chen Date: Thu, 21 Dec 2023 15:40:55 -0700 Subject: [PATCH 2/2] test(sdk-api): a new example to show and test http proxy usage Ticket: WP-1185 --- examples/ts/http-proxy/README.md | 16 +++++++++++ examples/ts/http-proxy/create-wallet.ts | 38 +++++++++++++++++++++++++ examples/ts/http-proxy/package.json | 19 +++++++++++++ examples/ts/http-proxy/server.ts | 8 ++++++ examples/ts/http-proxy/tsconfig.json | 10 +++++++ examples/ts/proxy/README.md | 4 +++ 6 files changed, 95 insertions(+) create mode 100644 examples/ts/http-proxy/README.md create mode 100644 examples/ts/http-proxy/create-wallet.ts create mode 100644 examples/ts/http-proxy/package.json create mode 100644 examples/ts/http-proxy/server.ts create mode 100644 examples/ts/http-proxy/tsconfig.json diff --git a/examples/ts/http-proxy/README.md b/examples/ts/http-proxy/README.md new file mode 100644 index 0000000000..f359192aa1 --- /dev/null +++ b/examples/ts/http-proxy/README.md @@ -0,0 +1,16 @@ +This directory contains a very simple example and test for http proxy setup that allows +talking to BitGo's API backend through a http proxy. + +This is in contrast to the [BitGo Express module](https://github.com/BitGo/BitGoJS/tree/master/modules/express) which implements the SDK on the +server that you host in order to provide specific SDK logic before proxying requests +to BitGo APIs for your convenience. + +This is also different from the [proxy](../proxy) example, which allows developers to use local BitGo SDK methods with a non-BitGo back-end. +Please take the time to review your use case as you choose between these options. + +## Setup + Usage +- Acquire a test environment account, enterprise and access token +- Fill in the `TODO` sections with the relevant credentials +- `npm install` +- `ts-node server.ts` +- In a separate shell: `ts-node create-wallet.ts` diff --git a/examples/ts/http-proxy/create-wallet.ts b/examples/ts/http-proxy/create-wallet.ts new file mode 100644 index 0000000000..b282b851f4 --- /dev/null +++ b/examples/ts/http-proxy/create-wallet.ts @@ -0,0 +1,38 @@ +import { BitGoAPI } from '@bitgo/sdk-api'; +import { Tpolygon } from '@bitgo/sdk-coin-polygon'; // Replace with your given coin (e.g. Ltc, Tltc) + +// This script emulates a front-end using the BitGo SDK to BitGo backend via a proxy. +// Set up the BitGo connection object. +const bitgo = new BitGoAPI({ + // TODO: your developer access token to the BitGo platform API + accessToken: 'your-token', + // Set as prod/test as needed for whatever BitGo environment you want to use. + // This *must* match the BitGo platform API your proxy instance is using. + env: 'test', + // TODO: In your real setup this would be , where you host the proxy server. + proxy: 'http://localhost:3000', +}); +const coin = 'tpolygon'; +bitgo.register(coin, Tpolygon.createInstance); + +async function createTSSWalletSimple() { + const newWallet = await bitgo + .coin(coin) + .wallets() + .generateWallet({ + label: 'hot multisig wallet ' + Math.floor(Date.now() / 1000), + // TODO: your wallet password + passphrase: 'VerySecurePassword1234', + // TODO: your enterprise ID + enterprise: 'your-enterprise-id', + multisigType: 'tss', + walletVersion: 3, + }); + console.log(JSON.stringify(newWallet, undefined, 2)); +} + +async function main() { + await createTSSWalletSimple(); +} + +main(); diff --git a/examples/ts/http-proxy/package.json b/examples/ts/http-proxy/package.json new file mode 100644 index 0000000000..f77ff12592 --- /dev/null +++ b/examples/ts/http-proxy/package.json @@ -0,0 +1,19 @@ +{ + "name": "sdk-proxy-poc", + "version": "1.0.0", + "description": "", + "main": "server.ts", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "BitGo", + "license": "ISC", + "dependencies": { + "ts-node": "^10.8.1", + "typescript": "^4.7.3", + "typescript-cached-transpile": "^0.0.6", + "superagent": "4.1", + "proxy-agent": "^6.3.1", + "proxy": "2.1.1" + } +} diff --git a/examples/ts/http-proxy/server.ts b/examples/ts/http-proxy/server.ts new file mode 100644 index 0000000000..98e6489ef0 --- /dev/null +++ b/examples/ts/http-proxy/server.ts @@ -0,0 +1,8 @@ +import { createProxy } from 'proxy'; +import { AddressInfo } from 'net'; + +const proxy = createProxy(); +proxy.listen(3000, () => { + const port = (proxy.address() as AddressInfo).port; + console.log('HTTP(s) proxy server listening on port %d', port); +}); diff --git a/examples/ts/http-proxy/tsconfig.json b/examples/ts/http-proxy/tsconfig.json new file mode 100644 index 0000000000..d2702e156f --- /dev/null +++ b/examples/ts/http-proxy/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "../../../tsconfig.json", + "include": ["."], + "exclude": ["node_modules"], + "references": [ + { + "path": "../bitgo" + } + ] +} diff --git a/examples/ts/proxy/README.md b/examples/ts/proxy/README.md index 07f5ce7eb7..369003f4d2 100644 --- a/examples/ts/proxy/README.md +++ b/examples/ts/proxy/README.md @@ -1,5 +1,9 @@ This directory contains a very simple example proxy setup that allows developers to use local BitGo SDK methods with a non-BitGo back-end. + This is in contrast to the [BitGo Express module](https://github.com/BitGo/BitGoJS/tree/master/modules/express) which implements the SDK on the server that you host in order to provide specific SDK logic before proxying requests to BitGo APIs for your convenience. + +This is not an example for using the BitGo SDK with a http proxy. For that, see the [http-proxy](../http-proxy) example. + Please take the time to review your use case as you choose between these options. ## Setup + Usage