@stryke-xyz/premarket-sdk 1.1.0 → 1.1.1

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.
@@ -104,6 +104,45 @@ function _iterable_to_array_limit(arr, i) {
104
104
  function _non_iterable_rest() {
105
105
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
106
106
  }
107
+ function _object_spread(target) {
108
+ for(var i = 1; i < arguments.length; i++){
109
+ var source = arguments[i] != null ? arguments[i] : {};
110
+ var ownKeys = Object.keys(source);
111
+ if (typeof Object.getOwnPropertySymbols === "function") {
112
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
113
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
114
+ }));
115
+ }
116
+ ownKeys.forEach(function(key) {
117
+ _define_property(target, key, source[key]);
118
+ });
119
+ }
120
+ return target;
121
+ }
122
+ function ownKeys(object, enumerableOnly) {
123
+ var keys = Object.keys(object);
124
+ if (Object.getOwnPropertySymbols) {
125
+ var symbols = Object.getOwnPropertySymbols(object);
126
+ if (enumerableOnly) {
127
+ symbols = symbols.filter(function(sym) {
128
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
129
+ });
130
+ }
131
+ keys.push.apply(keys, symbols);
132
+ }
133
+ return keys;
134
+ }
135
+ function _object_spread_props(target, source) {
136
+ source = source != null ? source : {};
137
+ if (Object.getOwnPropertyDescriptors) {
138
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
139
+ } else {
140
+ ownKeys(Object(source)).forEach(function(key) {
141
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
142
+ });
143
+ }
144
+ return target;
145
+ }
107
146
  function _sliced_to_array(arr, i) {
108
147
  return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
109
148
  }
@@ -222,6 +261,53 @@ function _ts_generator(thisArg, body) {
222
261
  // ORDERBOOK API CLIENT
223
262
  // ============================================================================
224
263
  // ============================================================================
264
+ // SIGNATURE NORMALIZATION
265
+ // ============================================================================
266
+ /**
267
+ * Wire shape expected by orderbook-pg: split EIP-2098 compact signature.
268
+ * `r` is the standard r component (32 bytes hex). `vs` packs s + recovery bit
269
+ * (v-27) into the most-significant bit, per EIP-2098.
270
+ */ /**
271
+ * Accepts either:
272
+ * - a 65-byte concatenated hex signature `0x{r:32}{s:32}{v:1}` (what
273
+ * `walletClient.signTypedData` and `signSimpleAccountOrder` return), or
274
+ * - an already-split `{ r, vs }` payload.
275
+ *
276
+ * Returns the EIP-2098 split form the backend's signature recovery expects.
277
+ */ function toCompactSignature(signature) {
278
+ if ((typeof signature === "undefined" ? "undefined" : _type_of(signature)) === "object" && signature !== null) {
279
+ return {
280
+ r: signature.r,
281
+ vs: signature.vs
282
+ };
283
+ }
284
+ var hex = signature.startsWith("0x") ? signature.slice(2) : signature;
285
+ if (hex.length !== 130) {
286
+ throw new Error("Invalid signature length: expected 65 bytes (130 hex chars), got ".concat(hex.length));
287
+ }
288
+ var r = "0x".concat(hex.slice(0, 64));
289
+ var sHex = hex.slice(64, 128);
290
+ var vByte = parseInt(hex.slice(128, 130), 16);
291
+ if (vByte !== 27 && vByte !== 28) {
292
+ throw new Error("Invalid signature v byte: expected 27 or 28, got ".concat(vByte));
293
+ }
294
+ var recoveryBit = vByte - 27;
295
+ // Pack recoveryBit into the high bit of s to form vs.
296
+ var sBytes = new Uint8Array(32);
297
+ for(var i = 0; i < 32; i++){
298
+ sBytes[i] = parseInt(sHex.slice(i * 2, i * 2 + 2), 16);
299
+ }
300
+ if (recoveryBit === 1) sBytes[0] |= 0x80;
301
+ var vs = "0x";
302
+ for(var i1 = 0; i1 < 32; i1++){
303
+ vs += sBytes[i1].toString(16).padStart(2, "0");
304
+ }
305
+ return {
306
+ r: r,
307
+ vs: vs
308
+ };
309
+ }
310
+ // ============================================================================
225
311
  // ORDERBOOK API CLASS
226
312
  // ============================================================================
227
313
  /**
@@ -419,9 +505,13 @@ function _ts_generator(thisArg, body) {
419
505
  * activity WS for the eventual fill.
420
506
  */ function createOrder(params, bearerToken) {
421
507
  return _async_to_generator(function() {
508
+ var wireParams;
422
509
  return _ts_generator(this, function(_state) {
423
510
  switch(_state.label){
424
511
  case 0:
512
+ wireParams = _object_spread_props(_object_spread({}, params), {
513
+ signature: toCompactSignature(params.signature)
514
+ });
425
515
  return [
426
516
  4,
427
517
  this.requestEnvelope("/orderbook/api/orders", {
@@ -430,7 +520,7 @@ function _ts_generator(thisArg, body) {
430
520
  "Content-Type": "application/json",
431
521
  Authorization: "Bearer ".concat(bearerToken)
432
522
  },
433
- body: JSON.stringify(params)
523
+ body: JSON.stringify(wireParams)
434
524
  }, "Failed to create order")
435
525
  ];
436
526
  case 1:
@@ -1 +1 @@
1
- {"name":"@stryke-xyz/premarket-sdk","version":"1.1.0","type":"commonjs"}
1
+ {"name":"@stryke-xyz/premarket-sdk","version":"1.1.1","type":"commonjs"}
@@ -12,6 +12,10 @@ Object.defineProperty(exports, "OrderStatus", {
12
12
  // ORDER TYPES
13
13
  // ============================================================================
14
14
  /**
15
+ * Wire-format split signature (EIP-2098 compact pair). Used internally when
16
+ * posting orders to orderbook-pg, which expects { r, vs } rather than the
17
+ * 65-byte concatenated hex returned by viem.
18
+ */ /**
15
19
  * Option parameters for legacy OptionTokenFactory
16
20
  * Used for calculating option token IDs
17
21
  */ var OrderStatus = /*#__PURE__*/ function(OrderStatus) {
@@ -94,6 +94,45 @@ function _iterable_to_array_limit(arr, i) {
94
94
  function _non_iterable_rest() {
95
95
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
96
96
  }
97
+ function _object_spread(target) {
98
+ for(var i = 1; i < arguments.length; i++){
99
+ var source = arguments[i] != null ? arguments[i] : {};
100
+ var ownKeys = Object.keys(source);
101
+ if (typeof Object.getOwnPropertySymbols === "function") {
102
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
103
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
104
+ }));
105
+ }
106
+ ownKeys.forEach(function(key) {
107
+ _define_property(target, key, source[key]);
108
+ });
109
+ }
110
+ return target;
111
+ }
112
+ function ownKeys(object, enumerableOnly) {
113
+ var keys = Object.keys(object);
114
+ if (Object.getOwnPropertySymbols) {
115
+ var symbols = Object.getOwnPropertySymbols(object);
116
+ if (enumerableOnly) {
117
+ symbols = symbols.filter(function(sym) {
118
+ return Object.getOwnPropertyDescriptor(object, sym).enumerable;
119
+ });
120
+ }
121
+ keys.push.apply(keys, symbols);
122
+ }
123
+ return keys;
124
+ }
125
+ function _object_spread_props(target, source) {
126
+ source = source != null ? source : {};
127
+ if (Object.getOwnPropertyDescriptors) {
128
+ Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
129
+ } else {
130
+ ownKeys(Object(source)).forEach(function(key) {
131
+ Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
132
+ });
133
+ }
134
+ return target;
135
+ }
97
136
  function _sliced_to_array(arr, i) {
98
137
  return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
99
138
  }
@@ -212,6 +251,53 @@ function _ts_generator(thisArg, body) {
212
251
  // ORDERBOOK API CLIENT
213
252
  // ============================================================================
214
253
  // ============================================================================
254
+ // SIGNATURE NORMALIZATION
255
+ // ============================================================================
256
+ /**
257
+ * Wire shape expected by orderbook-pg: split EIP-2098 compact signature.
258
+ * `r` is the standard r component (32 bytes hex). `vs` packs s + recovery bit
259
+ * (v-27) into the most-significant bit, per EIP-2098.
260
+ */ /**
261
+ * Accepts either:
262
+ * - a 65-byte concatenated hex signature `0x{r:32}{s:32}{v:1}` (what
263
+ * `walletClient.signTypedData` and `signSimpleAccountOrder` return), or
264
+ * - an already-split `{ r, vs }` payload.
265
+ *
266
+ * Returns the EIP-2098 split form the backend's signature recovery expects.
267
+ */ function toCompactSignature(signature) {
268
+ if ((typeof signature === "undefined" ? "undefined" : _type_of(signature)) === "object" && signature !== null) {
269
+ return {
270
+ r: signature.r,
271
+ vs: signature.vs
272
+ };
273
+ }
274
+ var hex = signature.startsWith("0x") ? signature.slice(2) : signature;
275
+ if (hex.length !== 130) {
276
+ throw new Error("Invalid signature length: expected 65 bytes (130 hex chars), got ".concat(hex.length));
277
+ }
278
+ var r = "0x".concat(hex.slice(0, 64));
279
+ var sHex = hex.slice(64, 128);
280
+ var vByte = parseInt(hex.slice(128, 130), 16);
281
+ if (vByte !== 27 && vByte !== 28) {
282
+ throw new Error("Invalid signature v byte: expected 27 or 28, got ".concat(vByte));
283
+ }
284
+ var recoveryBit = vByte - 27;
285
+ // Pack recoveryBit into the high bit of s to form vs.
286
+ var sBytes = new Uint8Array(32);
287
+ for(var i = 0; i < 32; i++){
288
+ sBytes[i] = parseInt(sHex.slice(i * 2, i * 2 + 2), 16);
289
+ }
290
+ if (recoveryBit === 1) sBytes[0] |= 0x80;
291
+ var vs = "0x";
292
+ for(var i1 = 0; i1 < 32; i1++){
293
+ vs += sBytes[i1].toString(16).padStart(2, "0");
294
+ }
295
+ return {
296
+ r: r,
297
+ vs: vs
298
+ };
299
+ }
300
+ // ============================================================================
215
301
  // ORDERBOOK API CLASS
216
302
  // ============================================================================
217
303
  /**
@@ -409,9 +495,13 @@ function _ts_generator(thisArg, body) {
409
495
  * activity WS for the eventual fill.
410
496
  */ function createOrder(params, bearerToken) {
411
497
  return _async_to_generator(function() {
498
+ var wireParams;
412
499
  return _ts_generator(this, function(_state) {
413
500
  switch(_state.label){
414
501
  case 0:
502
+ wireParams = _object_spread_props(_object_spread({}, params), {
503
+ signature: toCompactSignature(params.signature)
504
+ });
415
505
  return [
416
506
  4,
417
507
  this.requestEnvelope("/orderbook/api/orders", {
@@ -420,7 +510,7 @@ function _ts_generator(thisArg, body) {
420
510
  "Content-Type": "application/json",
421
511
  Authorization: "Bearer ".concat(bearerToken)
422
512
  },
423
- body: JSON.stringify(params)
513
+ body: JSON.stringify(wireParams)
424
514
  }, "Failed to create order")
425
515
  ];
426
516
  case 1:
@@ -1 +1 @@
1
- {"name":"@stryke-xyz/premarket-sdk","version":"1.1.0","type":"module"}
1
+ {"name":"@stryke-xyz/premarket-sdk","version":"1.1.1","type":"module"}
@@ -2,6 +2,10 @@
2
2
  // ORDER TYPES
3
3
  // ============================================================================
4
4
  /**
5
+ * Wire-format split signature (EIP-2098 compact pair). Used internally when
6
+ * posting orders to orderbook-pg, which expects { r, vs } rather than the
7
+ * 65-byte concatenated hex returned by viem.
8
+ */ /**
5
9
  * Option parameters for legacy OptionTokenFactory
6
10
  * Used for calculating option token IDs
7
11
  */ export var OrderStatus = /*#__PURE__*/ function(OrderStatus) {
@@ -13,6 +13,15 @@ export interface Order {
13
13
  tokenId: string;
14
14
  }
15
15
  export type OrderSignature = `0x${string}`;
16
+ /**
17
+ * Wire-format split signature (EIP-2098 compact pair). Used internally when
18
+ * posting orders to orderbook-pg, which expects { r, vs } rather than the
19
+ * 65-byte concatenated hex returned by viem.
20
+ */
21
+ export interface SplitOrderSignature {
22
+ r: string;
23
+ vs: string;
24
+ }
16
25
  /**
17
26
  * Option parameters for legacy OptionTokenFactory
18
27
  * Used for calculating option token IDs
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stryke-xyz/premarket-sdk",
3
- "version": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "type": "module",
5
5
  "module": "dist/esm/index.js",
6
6
  "main": "dist/cjs/index.js",