Skip to content

Commit 589dd29

Browse files
committed
fix: remove copy/pasta from sdk-hmac module
- update Dockerfile - update copied contents to reflect current module Ticket: CE-5010
1 parent 7466b99 commit 589dd29

File tree

5 files changed

+44
-27
lines changed

5 files changed

+44
-27
lines changed

Dockerfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ COPY --from=builder /tmp/bitgo/modules/abstract-lightning /var/modules/abstract-
5252
COPY --from=builder /tmp/bitgo/modules/abstract-utxo /var/modules/abstract-utxo/
5353
COPY --from=builder /tmp/bitgo/modules/blockapis /var/modules/blockapis/
5454
COPY --from=builder /tmp/bitgo/modules/sdk-api /var/modules/sdk-api/
55+
COPY --from=builder /tmp/bitgo/modules/sdk-hmac /var/modules/sdk-hmac/
5556
COPY --from=builder /tmp/bitgo/modules/unspents /var/modules/unspents/
5657
COPY --from=builder /tmp/bitgo/modules/account-lib /var/modules/account-lib/
5758
COPY --from=builder /tmp/bitgo/modules/sdk-coin-algo /var/modules/sdk-coin-algo/
@@ -126,6 +127,7 @@ cd /var/modules/abstract-lightning && yarn link && \
126127
cd /var/modules/abstract-utxo && yarn link && \
127128
cd /var/modules/blockapis && yarn link && \
128129
cd /var/modules/sdk-api && yarn link && \
130+
cd /var/modules/sdk-hmac && yarn link && \
129131
cd /var/modules/unspents && yarn link && \
130132
cd /var/modules/account-lib && yarn link && \
131133
cd /var/modules/sdk-coin-algo && yarn link && \
@@ -203,6 +205,7 @@ RUN cd /var/bitgo-express && \
203205
yarn link @bitgo/abstract-utxo && \
204206
yarn link @bitgo/blockapis && \
205207
yarn link @bitgo/sdk-api && \
208+
yarn link @bitgo/sdk-hmac && \
206209
yarn link @bitgo/unspents && \
207210
yarn link @bitgo/account-lib && \
208211
yarn link @bitgo/sdk-coin-algo && \

modules/sdk-hmac/.eslintignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
11
dist/
2-
src/opensslbytes.ts

modules/sdk-hmac/CHANGELOG.md

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,3 @@
22

33
All notable changes to this project will be documented in this file.
44
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5-
6-
# 2.0.0 (2024-08-20)
7-
8-
### Features
9-
10-
- move opensslbytes to own package ([e23c562](https://github.com/BitGo/BitGoJS/commit/e23c5627957916055e68329541dd1eb775704ca5))
11-
12-
### BREAKING CHANGES
13-
14-
- clients using challenge
15-
generation & TSS Recovery functions must now
16-
install @bitgo/sdk-opensslbytes separately &
17-
provide the openSSLBytes WASM themselves.
18-
19-
Ticket: CE-4329

modules/sdk-hmac/README.md

Lines changed: 39 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,50 @@
1-
# @bitgo/sdk-opensslbytes
1+
# @bitgo/sdk-sdk-hmac
22

3-
Isolated module for users of the BitGo SDK that need to generate range proofs or recover funds on a TSS wallet.
3+
Isolated module for performing hash-based message authentication (HMAC) on API requests.
44

55
## Installation
66

77
```shell
8-
npm i @bitgo/sdk-api @bitgo/sdk-lib-mpc @bitgo/sdk-opensslbytes
8+
npm i @bitgo/sdk-hmac
99
```
1010

11-
Import the `openSSLBytes` from this module & pass to related functions that expect it:
12-
1311
```javascript
14-
import { loadWebAssembly } from '@bitgo/sdk-opensslbytes';
15-
import { EcdsaRangeProof } from '@bitgo-beta/sdk-lib-mpc';
12+
import { calculateRequestHeaders, verifyResponse } from '@bitgo/sdk-hmac';
13+
14+
const bearerToken = 'v2x123...';
15+
const url = '/api/v2/wallets';
16+
17+
const { hmac, timestamp, tokenHash } = calculateRequestHeaders({
18+
url,
19+
token: bearerToken,
20+
timestamp: new Date().valueOf().toString(),
21+
// if making a POST/PUT request with a body, pass as text
22+
// text: JSON.stringify(request.body)
23+
// optional, can pass 2 or 3 for auth-version
24+
// authVersion: 3
25+
});
26+
27+
const response = await fetch(url, {
28+
method: 'GET',
29+
headers: {
30+
authorization: `Bearer ${tokenHash}`,
31+
hmac,
32+
'bitgo-auth-version': '2.0',
33+
'auth-timestamp': timestamp,
34+
},
35+
});
1636

17-
const openSSLBytes = loadWebAssembly().buffer;
37+
const verifiedResponse = verifyResponse({
38+
url,
39+
hmac: response.headers.get('hmac'),
40+
statusCode: response.status,
41+
text: response.text,
42+
timestamp: response.headers.get('timestamp'),
43+
token: bearerToken,
44+
method: 'get',
45+
});
1846

19-
const nTilde = await EcdsaRangeProof.generateNtilde(openSSLBytes, 3072);
47+
if (!verifiedResponse.isValid) {
48+
throw new Error('dont trust this response, possible MITM attack');
49+
}
2050
```

modules/sdk-hmac/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@bitgo/sdk-hmac",
33
"version": "1.0.0",
4-
"description": "Split package for WASM code needed by sdk-lib-mpc",
4+
"description": "HMAC module for the BitGo SDK",
55
"main": "./dist/src/index.js",
66
"types": "./dist/src/index.d.ts",
77
"scripts": {
@@ -27,7 +27,7 @@
2727
"repository": {
2828
"type": "git",
2929
"url": "https://github.com/BitGo/BitGoJS.git",
30-
"directory": "modules/sdk-opensslbytes"
30+
"directory": "modules/sdk-hmac"
3131
},
3232
"files": [
3333
"dist/src"

0 commit comments

Comments
 (0)