@polymarket/clob-client-v2 1.0.4 → 1.0.5
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/dist/index.cjs +25 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +25 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -201,16 +201,31 @@ var buildClobEip712Signature = async (signer, chainId, timestamp, nonce, address
|
|
|
201
201
|
};
|
|
202
202
|
|
|
203
203
|
// src/signing/hmac.ts
|
|
204
|
+
var decodeBase64Secret = (secret) => {
|
|
205
|
+
const normalized = secret.replace(/-/g, "+").replace(/_/g, "/");
|
|
206
|
+
const padded = normalized + "=".repeat((4 - normalized.length % 4) % 4);
|
|
207
|
+
const binary = atob(padded);
|
|
208
|
+
const buffer = new ArrayBuffer(binary.length);
|
|
209
|
+
const bytes = new Uint8Array(buffer);
|
|
210
|
+
for (let i = 0; i < binary.length; i++) {
|
|
211
|
+
bytes[i] = binary.charCodeAt(i);
|
|
212
|
+
}
|
|
213
|
+
return bytes;
|
|
214
|
+
};
|
|
204
215
|
var buildPolyHmacSignature = async (secret, timestamp, method, requestPath, body) => {
|
|
216
|
+
if (!secret) {
|
|
217
|
+
throw new Error("buildPolyHmacSignature: secret is empty");
|
|
218
|
+
}
|
|
219
|
+
if (!globalThis.crypto?.subtle) {
|
|
220
|
+
throw new Error(
|
|
221
|
+
"buildPolyHmacSignature: globalThis.crypto.subtle is unavailable. Requires Node >=20 or a secure browser context (HTTPS or localhost)."
|
|
222
|
+
);
|
|
223
|
+
}
|
|
205
224
|
let message = timestamp + method + requestPath;
|
|
206
225
|
if (body !== void 0) {
|
|
207
226
|
message += body;
|
|
208
227
|
}
|
|
209
|
-
const
|
|
210
|
-
const keyBytes = new Uint8Array(binarySecret.length);
|
|
211
|
-
for (let i = 0; i < binarySecret.length; i++) {
|
|
212
|
-
keyBytes[i] = binarySecret.charCodeAt(i);
|
|
213
|
-
}
|
|
228
|
+
const keyBytes = decodeBase64Secret(secret);
|
|
214
229
|
const key = await globalThis.crypto.subtle.importKey(
|
|
215
230
|
"raw",
|
|
216
231
|
keyBytes,
|
|
@@ -1022,6 +1037,11 @@ var decimalPlaces = (num) => {
|
|
|
1022
1037
|
return arr[1].length;
|
|
1023
1038
|
};
|
|
1024
1039
|
var generateOrderBookSummaryHash = async (orderbook) => {
|
|
1040
|
+
if (!globalThis.crypto?.subtle) {
|
|
1041
|
+
throw new Error(
|
|
1042
|
+
"generateOrderBookSummaryHash: globalThis.crypto.subtle is unavailable. Requires Node >=20 or a secure browser context (HTTPS or localhost)."
|
|
1043
|
+
);
|
|
1044
|
+
}
|
|
1025
1045
|
orderbook.hash = "";
|
|
1026
1046
|
const data = new TextEncoder().encode(JSON.stringify(orderbook));
|
|
1027
1047
|
const hashBuffer = await globalThis.crypto.subtle.digest("SHA-1", data);
|