Skip to content

Commit e743c35

Browse files
committed
test(sdk-api): a new example to show and test http proxy usage
Ticket: WP-1185
1 parent 1f194e2 commit e743c35

File tree

6 files changed

+95
-0
lines changed

6 files changed

+95
-0
lines changed

examples/ts/http-proxy/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
This directory contains a very simple example and test for http proxy setup that allows
2+
talking to BitGo's API backend through a http proxy.
3+
4+
This is in contrast to the [BitGo Express module](https://github.com/BitGo/BitGoJS/tree/master/modules/express) which implements the SDK on the
5+
server that you host in order to provide specific SDK logic before proxying requests
6+
to BitGo APIs for your convenience.
7+
8+
This is also different from the [proxy](../proxy) example, which allows developers to use local BitGo SDK methods with a non-BitGo back-end.
9+
Please take the time to review your use case as you choose between these options.
10+
11+
## Setup + Usage
12+
- Acquire a test environment account, enterprise and access token
13+
- Fill in the `TODO` sections with the relevant credentials
14+
- `npm install`
15+
- `ts-node server.ts`
16+
- In a separate shell: `ts-node get-me.ts`
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { BitGoAPI } from '@bitgo/sdk-api';
2+
import { Tpolygon } from '@bitgo/sdk-coin-polygon'; // Replace with your given coin (e.g. Ltc, Tltc)
3+
4+
// This script emulates a front-end using the BitGo SDK to BitGo backend via a proxy.
5+
// Set up the BitGo connection object.
6+
const bitgo = new BitGoAPI({
7+
// TODO: your developer access token to the BitGo platform API
8+
accessToken: 'your-token',
9+
// Set as prod/test as needed for whatever BitGo environment you want to use.
10+
// This *must* match the BitGo platform API your proxy instance is using.
11+
env: 'test',
12+
// TODO: In your real setup this would be <your.proxy.url>, where you host the proxy server.
13+
proxy: 'http://localhost:3000',
14+
});
15+
const coin = 'tpolygon';
16+
bitgo.register(coin, Tpolygon.createInstance);
17+
18+
async function createTSSWalletSimple() {
19+
const newWallet = await bitgo
20+
.coin(coin)
21+
.wallets()
22+
.generateWallet({
23+
label: 'hot multisig wallet ' + Math.floor(Date.now() / 1000),
24+
// TODO: your wallet password
25+
passphrase: 'VerySecurePassword1234',
26+
// TODO: your enterprise ID
27+
enterprise: 'your-enterprise-id',
28+
multisigType: 'tss',
29+
walletVersion: 3,
30+
});
31+
console.log(JSON.stringify(newWallet, undefined, 2));
32+
}
33+
34+
async function main() {
35+
await createTSSWalletSimple();
36+
}
37+
38+
main();
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
{
2+
"name": "sdk-proxy-poc",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "server.ts",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"author": "BitGo",
10+
"license": "ISC",
11+
"dependencies": {
12+
"ts-node": "^10.8.1",
13+
"typescript": "^4.7.3",
14+
"typescript-cached-transpile": "^0.0.6",
15+
"superagent": "4.1",
16+
"proxy-agent": "^6.3.1",
17+
"proxy": "2.1.1"
18+
}
19+
}

examples/ts/http-proxy/server.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { createProxy } from 'proxy';
2+
import { AddressInfo } from 'net';
3+
4+
const proxy = createProxy();
5+
proxy.listen(3000, () => {
6+
const port = (proxy.address() as AddressInfo).port;
7+
console.log('HTTP(s) proxy server listening on port %d', port);
8+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "../../../tsconfig.json",
3+
"include": ["."],
4+
"exclude": ["node_modules"],
5+
"references": [
6+
{
7+
"path": "../bitgo"
8+
}
9+
]
10+
}

examples/ts/proxy/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
This directory contains a very simple example proxy setup that allows developers to use local BitGo SDK methods with a non-BitGo back-end.
2+
23
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.
4+
5+
This is not an example for using the BitGo SDK with a http proxy. For that, see the [http-proxy](../http-proxy) example.
6+
37
Please take the time to review your use case as you choose between these options.
48

59
## Setup + Usage

0 commit comments

Comments
 (0)