@atomiqlabs/chain-starknet 8.2.3 → 8.3.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.
@@ -231,4 +231,8 @@ export declare class StarknetSwapData extends SwapData {
231
231
  * @inheritDoc
232
232
  */
233
233
  hasSuccessAction(): boolean;
234
+ /**
235
+ * @inheritDoc
236
+ */
237
+ getEscrowStruct(): any;
234
238
  }
@@ -469,6 +469,12 @@ class StarknetSwapData extends base_1.SwapData {
469
469
  hasSuccessAction() {
470
470
  return this.successAction != null;
471
471
  }
472
+ /**
473
+ * @inheritDoc
474
+ */
475
+ getEscrowStruct() {
476
+ return (0, Utils_1.replaceBigInts)(this.toEscrowStruct());
477
+ }
472
478
  }
473
479
  exports.StarknetSwapData = StarknetSwapData;
474
480
  base_1.SwapData.deserializers["strk"] = StarknetSwapData;
@@ -74,4 +74,5 @@ export declare function serializeResourceBounds(resourceBounds: {
74
74
  };
75
75
  };
76
76
  export declare function deserializeResourceBounds(resourceBounds: ResourceBounds): ResourceBoundsBN;
77
+ export declare function replaceBigInts<T>(obj: T): ReplaceBigInt<T>;
77
78
  export {};
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.deserializeResourceBounds = exports.serializeResourceBounds = exports.deserializeSignature = exports.serializeSignature = exports.bigIntMax = exports.findLastIndex = exports.poseidonHashRange = exports.bufferToByteArray = exports.bufferToBytes31Span = exports.bytes31SpanToBuffer = exports.toBigInt = exports.bigNumberishToBuffer = exports.u32ReverseEndianness = exports.bufferToU32Array = exports.u32ArrayToBuffer = exports.calculateHash = exports.toHex = exports.tryWithRetries = exports.getLogger = exports.onceAsync = exports.timeoutPromise = exports.isUint256 = void 0;
3
+ exports.replaceBigInts = exports.deserializeResourceBounds = exports.serializeResourceBounds = exports.deserializeSignature = exports.serializeSignature = exports.bigIntMax = exports.findLastIndex = exports.poseidonHashRange = exports.bufferToByteArray = exports.bufferToBytes31Span = exports.bytes31SpanToBuffer = exports.toBigInt = exports.bigNumberishToBuffer = exports.u32ReverseEndianness = exports.bufferToU32Array = exports.u32ArrayToBuffer = exports.calculateHash = exports.toHex = exports.tryWithRetries = exports.getLogger = exports.onceAsync = exports.timeoutPromise = exports.isUint256 = void 0;
4
4
  const starknet_1 = require("starknet");
5
5
  const buffer_1 = require("buffer");
6
6
  function isUint256(val) {
@@ -302,3 +302,21 @@ function deserializeResourceBounds(resourceBounds) {
302
302
  };
303
303
  }
304
304
  exports.deserializeResourceBounds = deserializeResourceBounds;
305
+ function replaceBigInts(obj) {
306
+ const replace = (value) => {
307
+ if (typeof (value) === "bigint")
308
+ return "0x" + value.toString(16);
309
+ if (value == null || typeof (value) !== "object")
310
+ return value;
311
+ if (Array.isArray(value)) {
312
+ return value.map(replace);
313
+ }
314
+ const mapped = Object.create(Object.getPrototypeOf(value));
315
+ for (const key of Object.keys(value)) {
316
+ mapped[key] = replace(value[key]);
317
+ }
318
+ return mapped;
319
+ };
320
+ return replace(obj);
321
+ }
322
+ exports.replaceBigInts = replaceBigInts;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atomiqlabs/chain-starknet",
3
- "version": "8.2.3",
3
+ "version": "8.3.0",
4
4
  "description": "Starknet specific base implementation",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -31,7 +31,7 @@
31
31
  "url": "git+https://github.com/atomiqlabs/atomiq-chain-starknet.git"
32
32
  },
33
33
  "dependencies": {
34
- "@atomiqlabs/base": "^13.2.0",
34
+ "@atomiqlabs/base": "^13.3.0",
35
35
  "@noble/hashes": "^1.7.1",
36
36
  "@scure/btc-signer": "^1.6.0",
37
37
  "abi-wan-kanabi": "2.2.4",
@@ -1,7 +1,7 @@
1
1
  import {SwapData, ChainSwapType} from "@atomiqlabs/base";
2
2
  import {TimelockRefundHandler} from "./handlers/refund/TimelockRefundHandler";
3
3
  import {BigNumberish, cairo, CairoOption, CairoOptionVariant, hash} from "starknet";
4
- import {Serialized, toBigInt, toHex} from "../../utils/Utils";
4
+ import {replaceBigInts, Serialized, toBigInt, toHex} from "../../utils/Utils";
5
5
  import {
6
6
  StringToPrimitiveType
7
7
  } from "abi-wan-kanabi/dist/kanabi";
@@ -582,6 +582,13 @@ export class StarknetSwapData extends SwapData {
582
582
  return this.successAction != null;
583
583
  }
584
584
 
585
+ /**
586
+ * @inheritDoc
587
+ */
588
+ getEscrowStruct(): any {
589
+ return replaceBigInts(this.toEscrowStruct());
590
+ }
591
+
585
592
  }
586
593
 
587
594
  SwapData.deserializers["strk"] = StarknetSwapData;
@@ -341,3 +341,22 @@ export function deserializeResourceBounds(resourceBounds: ResourceBounds): Resou
341
341
  }
342
342
  };
343
343
  }
344
+
345
+ export function replaceBigInts<T>(obj: T): ReplaceBigInt<T> {
346
+ const replace = (value: any): any => {
347
+ if(typeof(value)==="bigint") return "0x"+value.toString(16);
348
+ if(value==null || typeof(value)!=="object") return value;
349
+
350
+ if(Array.isArray(value)) {
351
+ return value.map(replace);
352
+ }
353
+
354
+ const mapped: any = {};
355
+ for(const key of Object.keys(value)) {
356
+ mapped[key] = replace(value[key]);
357
+ }
358
+ return mapped;
359
+ };
360
+
361
+ return replace(obj);
362
+ }