-
Notifications
You must be signed in to change notification settings - Fork 274
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
example: a new example to show and test http proxy usage
Ticket: WP-1185
- Loading branch information
1 parent
1f194e2
commit 743c75d
Showing
6 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 get-me.ts` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <your.proxy.url>, 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(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"extends": "../../../tsconfig.json", | ||
"include": ["."], | ||
"exclude": ["node_modules"], | ||
"references": [ | ||
{ | ||
"path": "../bitgo" | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters