Skip to content

Commit e599289

Browse files
authored
fix: Encode URI components in HttpTransport & Add secure-json-parse dependency (#469)
* fix: encode URI components in HttpTransport class * feat: add secure-json-parse dependency and update JSON parsing in HttpTransport class
1 parent d1a4f87 commit e599289

File tree

15 files changed

+54
-70
lines changed

15 files changed

+54
-70
lines changed

packages/connect-examples/electron-example/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "hardware-example",
33
"productName": "HardwareExample",
44
"executableName": "onekey-hardware-example",
5-
"version": "1.0.27-alpha.1",
5+
"version": "1.0.28",
66
"author": "OneKey",
77
"description": "End-to-end encrypted workspaces for teams",
88
"main": "dist/index.js",

packages/connect-examples/expo-example/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "expo-example",
3-
"version": "1.0.27-alpha.1",
3+
"version": "1.0.28",
44
"scripts": {
55
"start": "CONNECT_SRC=https://localhost:8087/ yarn expo start --dev-client",
66
"android": "yarn expo run:android",
@@ -19,10 +19,10 @@
1919
"@noble/ed25519": "^2.1.0",
2020
"@noble/hashes": "^1.3.3",
2121
"@noble/secp256k1": "^1.7.1",
22-
"@onekeyfe/hd-ble-sdk": "^1.0.27-alpha.1",
23-
"@onekeyfe/hd-common-connect-sdk": "^1.0.27-alpha.1",
24-
"@onekeyfe/hd-core": "^1.0.27-alpha.1",
25-
"@onekeyfe/hd-web-sdk": "^1.0.27-alpha.1",
22+
"@onekeyfe/hd-ble-sdk": "^1.0.28",
23+
"@onekeyfe/hd-common-connect-sdk": "^1.0.28",
24+
"@onekeyfe/hd-core": "^1.0.28",
25+
"@onekeyfe/hd-web-sdk": "^1.0.28",
2626
"@onekeyfe/react-native-ble-utils": "^0.1.3",
2727
"@polkadot/util-crypto": "13.1.1",
2828
"@react-native-async-storage/async-storage": "1.21.0",

packages/core/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@onekeyfe/hd-core",
3-
"version": "1.0.27-alpha.1",
3+
"version": "1.0.28",
44
"description": "> TODO: description",
55
"author": "OneKey",
66
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
@@ -25,8 +25,8 @@
2525
"url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
2626
},
2727
"dependencies": {
28-
"@onekeyfe/hd-shared": "^1.0.27-alpha.1",
29-
"@onekeyfe/hd-transport": "^1.0.27-alpha.1",
28+
"@onekeyfe/hd-shared": "^1.0.28",
29+
"@onekeyfe/hd-transport": "^1.0.28",
3030
"axios": "^0.27.2",
3131
"bignumber.js": "^9.0.2",
3232
"bytebuffer": "^5.0.1",

packages/hd-ble-sdk/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@onekeyfe/hd-ble-sdk",
3-
"version": "1.0.27-alpha.1",
3+
"version": "1.0.28",
44
"author": "OneKey",
55
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
66
"license": "ISC",
@@ -20,8 +20,8 @@
2020
"lint:fix": "eslint . --fix"
2121
},
2222
"dependencies": {
23-
"@onekeyfe/hd-core": "^1.0.27-alpha.1",
24-
"@onekeyfe/hd-shared": "^1.0.27-alpha.1",
25-
"@onekeyfe/hd-transport-react-native": "^1.0.27-alpha.1"
23+
"@onekeyfe/hd-core": "^1.0.28",
24+
"@onekeyfe/hd-shared": "^1.0.28",
25+
"@onekeyfe/hd-transport-react-native": "^1.0.28"
2626
}
2727
}

packages/hd-common-connect-sdk/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@onekeyfe/hd-common-connect-sdk",
3-
"version": "1.0.27-alpha.1",
3+
"version": "1.0.28",
44
"author": "OneKey",
55
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
66
"license": "ISC",
@@ -20,10 +20,10 @@
2020
"lint:fix": "eslint . --fix"
2121
},
2222
"dependencies": {
23-
"@onekeyfe/hd-core": "^1.0.27-alpha.1",
24-
"@onekeyfe/hd-shared": "^1.0.27-alpha.1",
25-
"@onekeyfe/hd-transport-http": "^1.0.27-alpha.1",
26-
"@onekeyfe/hd-transport-lowlevel": "^1.0.27-alpha.1",
27-
"@onekeyfe/hd-transport-webusb": "^1.0.27-alpha.1"
23+
"@onekeyfe/hd-core": "^1.0.28",
24+
"@onekeyfe/hd-shared": "^1.0.28",
25+
"@onekeyfe/hd-transport-http": "^1.0.28",
26+
"@onekeyfe/hd-transport-lowlevel": "^1.0.28",
27+
"@onekeyfe/hd-transport-webusb": "^1.0.28"
2828
}
2929
}

packages/hd-transport-http/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@onekeyfe/hd-transport-http",
3-
"version": "1.0.27-alpha.1",
3+
"version": "1.0.28",
44
"description": "hardware http transport",
55
"author": "OneKey",
66
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
@@ -24,8 +24,9 @@
2424
"url": "https://github.com/OneKeyHQ/hardware-js-sdk/issues"
2525
},
2626
"dependencies": {
27-
"@onekeyfe/hd-shared": "^1.0.27-alpha.1",
28-
"@onekeyfe/hd-transport": "^1.0.27-alpha.1",
29-
"axios": "^0.27.2"
27+
"@onekeyfe/hd-shared": "^1.0.28",
28+
"@onekeyfe/hd-transport": "^1.0.28",
29+
"axios": "^0.27.2",
30+
"secure-json-parse": "^4.0.0"
3031
}
3132
}

packages/hd-transport-http/src/http.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import axios, { AxiosRequestConfig } from 'axios';
22
import { HardwareError, HardwareErrorCode } from '@onekeyfe/hd-shared';
3+
import secureJSON from 'secure-json-parse';
34

45
export type HttpRequestOptions = {
56
body?: Array<any> | Record<string, unknown> | string;
@@ -24,7 +25,7 @@ function wrapBody(body: any) {
2425

2526
function parseResult(text: string) {
2627
try {
27-
const result = JSON.parse(text);
28+
const result = secureJSON.parse(text);
2829
if (typeof result !== 'object') {
2930
throw new Error('Invalid response');
3031
}

packages/hd-transport-http/src/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,11 @@ export default class HttpTransport {
8181
}
8282

8383
_acquireMixed(input: AcquireInput) {
84-
const previousStr = input.previous == null ? 'null' : input.previous;
84+
const previousStr = input.previous == null ? 'null' : encodeURIComponent(input.previous);
85+
// @ts-expect-error
8586
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
86-
const url = `/acquire/${input.path}/${previousStr}`;
87+
const path = encodeURIComponent(input.path);
88+
const url = `/acquire/${path}/${previousStr}`;
8789
return this._post({ url });
8890
}
8991

packages/hd-transport-lowlevel/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@onekeyfe/hd-transport-lowlevel",
3-
"version": "1.0.27-alpha.1",
3+
"version": "1.0.28",
44
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
55
"license": "MIT",
66
"main": "dist/index.js",
@@ -19,7 +19,7 @@
1919
"lint:fix": "eslint . --fix"
2020
},
2121
"dependencies": {
22-
"@onekeyfe/hd-shared": "^1.0.27-alpha.1",
23-
"@onekeyfe/hd-transport": "^1.0.27-alpha.1"
22+
"@onekeyfe/hd-shared": "^1.0.28",
23+
"@onekeyfe/hd-transport": "^1.0.28"
2424
}
2525
}

packages/hd-transport-react-native/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@onekeyfe/hd-transport-react-native",
3-
"version": "1.0.27-alpha.1",
3+
"version": "1.0.28",
44
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
55
"license": "MIT",
66
"main": "dist/index.js",
@@ -19,8 +19,8 @@
1919
"lint:fix": "eslint . --fix"
2020
},
2121
"dependencies": {
22-
"@onekeyfe/hd-shared": "^1.0.27-alpha.1",
23-
"@onekeyfe/hd-transport": "^1.0.27-alpha.1",
22+
"@onekeyfe/hd-shared": "^1.0.28",
23+
"@onekeyfe/hd-transport": "^1.0.28",
2424
"@onekeyfe/react-native-ble-utils": "^0.1.4",
2525
"react-native-ble-plx": "3.5.0"
2626
}

packages/hd-transport-webusb/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@onekeyfe/hd-transport-webusb",
3-
"version": "1.0.27-alpha.1",
3+
"version": "1.0.28",
44
"author": "OneKey",
55
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
66
"license": "MIT",
@@ -20,8 +20,8 @@
2020
"lint:fix": "eslint . --fix"
2121
},
2222
"dependencies": {
23-
"@onekeyfe/hd-shared": "^1.0.27-alpha.1",
24-
"@onekeyfe/hd-transport": "^1.0.27-alpha.1"
23+
"@onekeyfe/hd-shared": "^1.0.28",
24+
"@onekeyfe/hd-transport": "^1.0.28"
2525
},
2626
"devDependencies": {
2727
"@types/w3c-web-usb": "^1.0.6",

packages/hd-transport/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@onekeyfe/hd-transport",
3-
"version": "1.0.27-alpha.1",
3+
"version": "1.0.28",
44
"description": "> TODO: description",
55
"author": "OneKey",
66
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",

packages/hd-web-sdk/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@onekeyfe/hd-web-sdk",
3-
"version": "1.0.27-alpha.1",
3+
"version": "1.0.28",
44
"author": "OneKey",
55
"homepage": "https://github.com/OneKeyHQ/hardware-js-sdk#readme",
66
"license": "ISC",
@@ -21,10 +21,10 @@
2121
},
2222
"dependencies": {
2323
"@onekeyfe/cross-inpage-provider-core": "^0.0.17",
24-
"@onekeyfe/hd-core": "^1.0.27-alpha.1",
25-
"@onekeyfe/hd-shared": "^1.0.27-alpha.1",
26-
"@onekeyfe/hd-transport-http": "^1.0.27-alpha.1",
27-
"@onekeyfe/hd-transport-webusb": "^1.0.27-alpha.1"
24+
"@onekeyfe/hd-core": "^1.0.28",
25+
"@onekeyfe/hd-shared": "^1.0.28",
26+
"@onekeyfe/hd-transport-http": "^1.0.28",
27+
"@onekeyfe/hd-transport-webusb": "^1.0.28"
2828
},
2929
"devDependencies": {
3030
"@babel/plugin-proposal-optional-chaining": "^7.17.12",

packages/shared/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@onekeyfe/hd-shared",
3-
"version": "1.0.27-alpha.1",
3+
"version": "1.0.28",
44
"description": "Hardware SDK's shared tool library",
55
"keywords": [
66
"Hardware-SDK",

yarn.lock

Lines changed: 8 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -17802,6 +17802,11 @@ [email protected]:
1780217802
resolved "https://registry.yarnpkg.com/scrypt-js/-/scrypt-js-3.0.1.tgz#d314a57c2aef69d1ad98a138a21fe9eafa9ee312"
1780317803
integrity sha512-cdwTTnqPu0Hyvf5in5asVdZocVDTNRmR7XEcJuIzMjJeSHybHl7vpB66AzwTaIg6CLSbtjcxc8fqcySfnTkccA==
1780417804

17805+
secure-json-parse@^4.0.0:
17806+
version "4.0.0"
17807+
resolved "https://registry.yarnpkg.com/secure-json-parse/-/secure-json-parse-4.0.0.tgz#2ee1b7581be38ab348bab5a3e49280ba80a89c85"
17808+
integrity sha512-dxtLJO6sc35jWidmLxo7ij+Eg48PM/kleBsxpC8QJE0qJICe+KawkDQmvCMZUr9u7WKVHgMW6vy3fQ7zMiFZMA==
17809+
1780517810
1780617811
version "1.2.6"
1780717812
resolved "https://registry.yarnpkg.com/secure-ls/-/secure-ls-1.2.6.tgz#0c54a4c7fa8317c3c101accbf6bb38d8d2072e46"
@@ -18429,7 +18434,7 @@ string-range@~1.2, string-range@~1.2.1:
1842918434
resolved "https://registry.yarnpkg.com/string-range/-/string-range-1.2.2.tgz#a893ed347e72299bc83befbbf2a692a8d239d5dd"
1843018435
integrity sha512-tYft6IFi8SjplJpxCUxyqisD3b+R2CSkomrtJYCkvuf1KuCAWgz7YXt4O0jip7efpfCemwHEzTEAO8EuOYgh3w==
1843118436

18432-
"string-width-cjs@npm:string-width@^4.2.0":
18437+
"string-width-cjs@npm:string-width@^4.2.0", "string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
1843318438
version "4.2.3"
1843418439
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
1843518440
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -18447,15 +18452,6 @@ string-width@^1.0.1:
1844718452
is-fullwidth-code-point "^1.0.0"
1844818453
strip-ansi "^3.0.0"
1844918454

18450-
"string-width@^1.0.2 || 2 || 3 || 4", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
18451-
version "4.2.3"
18452-
resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
18453-
integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
18454-
dependencies:
18455-
emoji-regex "^8.0.0"
18456-
is-fullwidth-code-point "^3.0.0"
18457-
strip-ansi "^6.0.1"
18458-
1845918455
string-width@^5.0.1, string-width@^5.1.2:
1846018456
version "5.1.2"
1846118457
resolved "https://registry.yarnpkg.com/string-width/-/string-width-5.1.2.tgz#14f8daec6d81e7221d2a357e668cab73bdbca794"
@@ -18535,7 +18531,7 @@ string_decoder@~1.1.1:
1853518531
dependencies:
1853618532
safe-buffer "~5.1.0"
1853718533

18538-
"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
18534+
"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
1853918535
version "6.0.1"
1854018536
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
1854118537
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
@@ -18556,13 +18552,6 @@ strip-ansi@^5.0.0, strip-ansi@^5.2.0:
1855618552
dependencies:
1855718553
ansi-regex "^4.1.0"
1855818554

18559-
strip-ansi@^6.0.0, strip-ansi@^6.0.1:
18560-
version "6.0.1"
18561-
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
18562-
integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
18563-
dependencies:
18564-
ansi-regex "^5.0.1"
18565-
1856618555
strip-ansi@^7.0.1, strip-ansi@^7.1.0:
1856718556
version "7.1.0"
1856818557
resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-7.1.0.tgz#d5b6568ca689d8561370b0707685d22434faff45"
@@ -20063,7 +20052,7 @@ wordwrap@^1.0.0:
2006320052
resolved "https://registry.yarnpkg.com/wordwrap/-/wordwrap-1.0.0.tgz#27584810891456a4171c8d0226441ade90cbcaeb"
2006420053
integrity sha1-J1hIEIkUVqQXHI0CJkQa3pDLyus=
2006520054

20066-
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
20055+
"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
2006720056
version "7.0.0"
2006820057
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
2006920058
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
@@ -20081,15 +20070,6 @@ wrap-ansi@^6.2.0:
2008120070
string-width "^4.1.0"
2008220071
strip-ansi "^6.0.0"
2008320072

20084-
wrap-ansi@^7.0.0:
20085-
version "7.0.0"
20086-
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
20087-
integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
20088-
dependencies:
20089-
ansi-styles "^4.0.0"
20090-
string-width "^4.1.0"
20091-
strip-ansi "^6.0.0"
20092-
2009320073
wrap-ansi@^8.1.0:
2009420074
version "8.1.0"
2009520075
resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-8.1.0.tgz#56dc22368ee570face1b49819975d9b9a5ead214"

0 commit comments

Comments
 (0)