clutch-hub-sdk-js 1.3.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -6
- package/dist/sdk.d.ts +2 -0
- package/dist/sdk.js +11 -6
- package/package.json +4 -4
- package/src/sdk.ts +12 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,23 +1,30 @@
|
|
|
1
|
-
## [1.
|
|
1
|
+
## [1.4.0](https://github.com/clutchprotocol/clutch-hub-sdk-js/compare/v1.3.0...v1.4.0) (2026-03-16)
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
### Features
|
|
5
5
|
|
|
6
|
-
* **sdk:** add
|
|
6
|
+
* **sdk:** add stripHexPrefix utility function and refactor hex handling in transaction signing ([4365203](https://github.com/clutchprotocol/clutch-hub-sdk-js/commit/43652033701e963a85d2e4966402e02b5201617f))
|
|
7
|
+
|
|
8
|
+
## [1.3.0](https://github.com/clutchprotocol/clutch-hub-sdk-js/compare/v1.2.0...v1.3.0) (2025-08-23)
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Features
|
|
12
|
+
|
|
13
|
+
* **sdk:** add getPublicKey and isAuthenticated utility methods ([c0ac16e](https://github.com/clutchprotocol/clutch-hub-sdk-js/commit/c0ac16e1166cf9d6e4bcb5ae8cc37a17d6ae7028))
|
|
7
14
|
|
|
8
15
|
|
|
9
16
|
### Bug Fixes
|
|
10
17
|
|
|
11
|
-
* **auth:** add buffer time to prevent token expiration race conditions ([29b3b53](https://github.com/
|
|
18
|
+
* **auth:** add buffer time to prevent token expiration race conditions ([29b3b53](https://github.com/clutchprotocol/clutch-hub-sdk-js/commit/29b3b538dc260c34d80814da4723a5d13a140a48))
|
|
12
19
|
|
|
13
20
|
|
|
14
21
|
### Performance Improvements
|
|
15
22
|
|
|
16
|
-
* **sdk:** optimize float64ToUint64 conversion with cached buffers ([43a76b9](https://github.com/
|
|
23
|
+
* **sdk:** optimize float64ToUint64 conversion with cached buffers ([43a76b9](https://github.com/clutchprotocol/clutch-hub-sdk-js/commit/43a76b91cd05b737a5942a381653419816656fdd))
|
|
17
24
|
|
|
18
|
-
## [1.2.0](https://github.com/
|
|
25
|
+
## [1.2.0](https://github.com/clutchprotocol/clutch-hub-sdk-js/compare/v1.1.0...v1.2.0) (2025-08-23)
|
|
19
26
|
|
|
20
27
|
|
|
21
28
|
### Features
|
|
22
29
|
|
|
23
|
-
* **ci:** enable git commits back to repository in semantic-release ([66016ac](https://github.com/
|
|
30
|
+
* **ci:** enable git commits back to repository in semantic-release ([66016ac](https://github.com/clutchprotocol/clutch-hub-sdk-js/commit/66016aceb0418ef0506ab55c024eaa37d6b28bee))
|
package/dist/sdk.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { Buffer } from 'buffer';
|
|
2
2
|
import { RideRequestArgs, Signature } from './types';
|
|
3
|
+
/** Strip 0x/0X prefix - hex parsers (e.g. @noble/secp256k1) do not accept it. Exported for consumers. */
|
|
4
|
+
export declare function stripHexPrefix(hex: string): string;
|
|
3
5
|
declare global {
|
|
4
6
|
interface Window {
|
|
5
7
|
Buffer: typeof Buffer;
|
package/dist/sdk.js
CHANGED
|
@@ -3,6 +3,10 @@ import { Buffer } from 'buffer';
|
|
|
3
3
|
import { keccak_256 } from '@noble/hashes/sha3';
|
|
4
4
|
import * as rlp from 'rlp';
|
|
5
5
|
import * as secp from '@noble/secp256k1';
|
|
6
|
+
/** Strip 0x/0X prefix - hex parsers (e.g. @noble/secp256k1) do not accept it. Exported for consumers. */
|
|
7
|
+
export function stripHexPrefix(hex) {
|
|
8
|
+
return hex.replace(/^0x/i, '');
|
|
9
|
+
}
|
|
6
10
|
if (typeof window !== 'undefined' && !window.Buffer) {
|
|
7
11
|
window.Buffer = Buffer;
|
|
8
12
|
}
|
|
@@ -105,7 +109,7 @@ export class ClutchHubSdk {
|
|
|
105
109
|
const callDataArray = this.encodeFunctionCall(unsignedTx.data);
|
|
106
110
|
// RLP-encode unsigned transaction [from, nonce, data]
|
|
107
111
|
// Ensure from field is properly encoded as string (remove 0x prefix for consistency)
|
|
108
|
-
const fromForUnsigned = unsignedTx.from
|
|
112
|
+
const fromForUnsigned = stripHexPrefix(unsignedTx.from);
|
|
109
113
|
const unsignedPayload = rlp.encode([
|
|
110
114
|
fromForUnsigned,
|
|
111
115
|
unsignedTx.nonce,
|
|
@@ -115,11 +119,11 @@ export class ClutchHubSdk {
|
|
|
115
119
|
const rawHashHex = Buffer.from(hashBytes).toString('hex');
|
|
116
120
|
// Sign the transaction hash
|
|
117
121
|
const signature = await this.signHash(rawHashHex, privateKey);
|
|
118
|
-
const rNo0x = signature.r
|
|
119
|
-
const sNo0x = signature.s
|
|
122
|
+
const rNo0x = stripHexPrefix(signature.r);
|
|
123
|
+
const sNo0x = stripHexPrefix(signature.s);
|
|
120
124
|
// RLP-encode full signed transaction to match Rust: [from, nonce, r, s, v, hash, data]
|
|
121
125
|
// Ensure from field is properly encoded as string (remove 0x prefix for consistency)
|
|
122
|
-
const fromNo0x = unsignedTx.from
|
|
126
|
+
const fromNo0x = stripHexPrefix(unsignedTx.from);
|
|
123
127
|
const fullPayload = rlp.encode([
|
|
124
128
|
fromNo0x,
|
|
125
129
|
unsignedTx.nonce,
|
|
@@ -151,8 +155,9 @@ export class ClutchHubSdk {
|
|
|
151
155
|
* Signs a hex-encoded hash.
|
|
152
156
|
*/
|
|
153
157
|
async signHash(hashHex, privateKey) {
|
|
154
|
-
const hashBuffer = Buffer.from(hashHex
|
|
155
|
-
const
|
|
158
|
+
const hashBuffer = Buffer.from(stripHexPrefix(hashHex), 'hex');
|
|
159
|
+
const privKeyClean = stripHexPrefix(privateKey);
|
|
160
|
+
const sig = await secp.signAsync(hashBuffer, privKeyClean);
|
|
156
161
|
const r = sig.r.toString(16).padStart(64, '0');
|
|
157
162
|
const s = sig.s.toString(16).padStart(64, '0');
|
|
158
163
|
const v = (typeof sig.recovery === 'number' ? sig.recovery : 0) + 27;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clutch-hub-sdk-js",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "JavaScript SDK for interacting with the clutch-hub-api",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -19,12 +19,12 @@
|
|
|
19
19
|
"license": "MIT",
|
|
20
20
|
"repository": {
|
|
21
21
|
"type": "git",
|
|
22
|
-
"url": "https://github.com/
|
|
22
|
+
"url": "https://github.com/clutchprotocol/clutch-hub-sdk-js.git"
|
|
23
23
|
},
|
|
24
24
|
"bugs": {
|
|
25
|
-
"url": "https://github.com/
|
|
25
|
+
"url": "https://github.com/clutchprotocol/clutch-hub-sdk-js/issues"
|
|
26
26
|
},
|
|
27
|
-
"homepage": "https://github.com/
|
|
27
|
+
"homepage": "https://github.com/clutchprotocol/clutch-hub-sdk-js#readme",
|
|
28
28
|
"dependencies": {
|
|
29
29
|
"@noble/hashes": "^1.8.0",
|
|
30
30
|
"@noble/secp256k1": "^2.2.3",
|
package/src/sdk.ts
CHANGED
|
@@ -5,6 +5,11 @@ import * as rlp from 'rlp';
|
|
|
5
5
|
import * as secp from '@noble/secp256k1';
|
|
6
6
|
import { RideRequestArgs, Signature } from './types';
|
|
7
7
|
|
|
8
|
+
/** Strip 0x/0X prefix - hex parsers (e.g. @noble/secp256k1) do not accept it. Exported for consumers. */
|
|
9
|
+
export function stripHexPrefix(hex: string): string {
|
|
10
|
+
return hex.replace(/^0x/i, '');
|
|
11
|
+
}
|
|
12
|
+
|
|
8
13
|
// Expose Buffer to browser contexts
|
|
9
14
|
declare global {
|
|
10
15
|
interface Window { Buffer: typeof Buffer }
|
|
@@ -146,7 +151,7 @@ export class ClutchHubSdk {
|
|
|
146
151
|
|
|
147
152
|
// RLP-encode unsigned transaction [from, nonce, data]
|
|
148
153
|
// Ensure from field is properly encoded as string (remove 0x prefix for consistency)
|
|
149
|
-
const fromForUnsigned = unsignedTx.from
|
|
154
|
+
const fromForUnsigned = stripHexPrefix(unsignedTx.from);
|
|
150
155
|
const unsignedPayload = rlp.encode([
|
|
151
156
|
fromForUnsigned,
|
|
152
157
|
unsignedTx.nonce,
|
|
@@ -157,12 +162,12 @@ export class ClutchHubSdk {
|
|
|
157
162
|
|
|
158
163
|
// Sign the transaction hash
|
|
159
164
|
const signature = await this.signHash(rawHashHex, privateKey);
|
|
160
|
-
const rNo0x = signature.r
|
|
161
|
-
const sNo0x = signature.s
|
|
165
|
+
const rNo0x = stripHexPrefix(signature.r);
|
|
166
|
+
const sNo0x = stripHexPrefix(signature.s);
|
|
162
167
|
|
|
163
168
|
// RLP-encode full signed transaction to match Rust: [from, nonce, r, s, v, hash, data]
|
|
164
169
|
// Ensure from field is properly encoded as string (remove 0x prefix for consistency)
|
|
165
|
-
const fromNo0x = unsignedTx.from
|
|
170
|
+
const fromNo0x = stripHexPrefix(unsignedTx.from);
|
|
166
171
|
const fullPayload = rlp.encode([
|
|
167
172
|
fromNo0x,
|
|
168
173
|
unsignedTx.nonce,
|
|
@@ -204,8 +209,9 @@ export class ClutchHubSdk {
|
|
|
204
209
|
hashHex: string,
|
|
205
210
|
privateKey: string
|
|
206
211
|
): Promise<Signature> {
|
|
207
|
-
const hashBuffer = Buffer.from(hashHex
|
|
208
|
-
const
|
|
212
|
+
const hashBuffer = Buffer.from(stripHexPrefix(hashHex), 'hex');
|
|
213
|
+
const privKeyClean = stripHexPrefix(privateKey);
|
|
214
|
+
const sig = await secp.signAsync(hashBuffer, privKeyClean);
|
|
209
215
|
const r = sig.r.toString(16).padStart(64, '0');
|
|
210
216
|
const s = sig.s.toString(16).padStart(64, '0');
|
|
211
217
|
const v = (typeof sig.recovery === 'number' ? sig.recovery : 0) + 27;
|