@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.cjs
CHANGED
|
@@ -257,16 +257,31 @@ var buildClobEip712Signature = async (signer, chainId, timestamp, nonce, address
|
|
|
257
257
|
};
|
|
258
258
|
|
|
259
259
|
// src/signing/hmac.ts
|
|
260
|
+
var decodeBase64Secret = (secret) => {
|
|
261
|
+
const normalized = secret.replace(/-/g, "+").replace(/_/g, "/");
|
|
262
|
+
const padded = normalized + "=".repeat((4 - normalized.length % 4) % 4);
|
|
263
|
+
const binary = atob(padded);
|
|
264
|
+
const buffer = new ArrayBuffer(binary.length);
|
|
265
|
+
const bytes = new Uint8Array(buffer);
|
|
266
|
+
for (let i = 0; i < binary.length; i++) {
|
|
267
|
+
bytes[i] = binary.charCodeAt(i);
|
|
268
|
+
}
|
|
269
|
+
return bytes;
|
|
270
|
+
};
|
|
260
271
|
var buildPolyHmacSignature = async (secret, timestamp, method, requestPath, body) => {
|
|
272
|
+
if (!secret) {
|
|
273
|
+
throw new Error("buildPolyHmacSignature: secret is empty");
|
|
274
|
+
}
|
|
275
|
+
if (!globalThis.crypto?.subtle) {
|
|
276
|
+
throw new Error(
|
|
277
|
+
"buildPolyHmacSignature: globalThis.crypto.subtle is unavailable. Requires Node >=20 or a secure browser context (HTTPS or localhost)."
|
|
278
|
+
);
|
|
279
|
+
}
|
|
261
280
|
let message = timestamp + method + requestPath;
|
|
262
281
|
if (body !== void 0) {
|
|
263
282
|
message += body;
|
|
264
283
|
}
|
|
265
|
-
const
|
|
266
|
-
const keyBytes = new Uint8Array(binarySecret.length);
|
|
267
|
-
for (let i = 0; i < binarySecret.length; i++) {
|
|
268
|
-
keyBytes[i] = binarySecret.charCodeAt(i);
|
|
269
|
-
}
|
|
284
|
+
const keyBytes = decodeBase64Secret(secret);
|
|
270
285
|
const key = await globalThis.crypto.subtle.importKey(
|
|
271
286
|
"raw",
|
|
272
287
|
keyBytes,
|
|
@@ -1078,6 +1093,11 @@ var decimalPlaces = (num) => {
|
|
|
1078
1093
|
return arr[1].length;
|
|
1079
1094
|
};
|
|
1080
1095
|
var generateOrderBookSummaryHash = async (orderbook) => {
|
|
1096
|
+
if (!globalThis.crypto?.subtle) {
|
|
1097
|
+
throw new Error(
|
|
1098
|
+
"generateOrderBookSummaryHash: globalThis.crypto.subtle is unavailable. Requires Node >=20 or a secure browser context (HTTPS or localhost)."
|
|
1099
|
+
);
|
|
1100
|
+
}
|
|
1081
1101
|
orderbook.hash = "";
|
|
1082
1102
|
const data = new TextEncoder().encode(JSON.stringify(orderbook));
|
|
1083
1103
|
const hashBuffer = await globalThis.crypto.subtle.digest("SHA-1", data);
|