@defuse-protocol/intents-sdk 0.62.2 → 0.63.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.
@@ -63,7 +63,8 @@ const CHAIN_MAPPINGS = [
63
63
  [require_caip2.Chains.Solana, _omni_bridge_core.ChainKind.Sol],
64
64
  [require_caip2.Chains.BNB, _omni_bridge_core.ChainKind.Bnb],
65
65
  [require_caip2.Chains.Bitcoin, _omni_bridge_core.ChainKind.Btc],
66
- [require_caip2.Chains.Abstract, _omni_bridge_core.ChainKind.Abs]
66
+ [require_caip2.Chains.Abstract, _omni_bridge_core.ChainKind.Abs],
67
+ [require_caip2.Chains.Starknet, _omni_bridge_core.ChainKind.Strk]
67
68
  ];
68
69
  function caip2ToChainKind(network) {
69
70
  return CHAIN_MAPPINGS.find(([chain]) => chain === network)?.[1] ?? null;
@@ -95,7 +96,7 @@ async function getAccountOmniStorageBalance(nearProvider, accountId) {
95
96
  })])
96
97
  });
97
98
  }
98
- const OmniAddressSchema = valibot.custom((input) => typeof input === "string" && (input.startsWith("eth:") || input.startsWith("near:") || input.startsWith("sol:") || input.startsWith("arb:") || input.startsWith("base:") || input.startsWith("btc:") || input.startsWith("bnb:") || input.startsWith("abs:")), "Must comply with omni address schema");
99
+ const OmniAddressSchema = valibot.custom((input) => typeof input === "string" && (input.startsWith("eth:") || input.startsWith("near:") || input.startsWith("sol:") || input.startsWith("arb:") || input.startsWith("base:") || input.startsWith("btc:") || input.startsWith("bnb:") || input.startsWith("abs:") || input.startsWith("strk:")), "Must comply with omni address schema");
99
100
  /**
100
101
  * Converts a token address from one chain to its equivalent on another chain.
101
102
  * @param nearProvider Near provider used for querying the contract
@@ -61,7 +61,8 @@ const CHAIN_MAPPINGS = [
61
61
  [Chains.Solana, ChainKind.Sol],
62
62
  [Chains.BNB, ChainKind.Bnb],
63
63
  [Chains.Bitcoin, ChainKind.Btc],
64
- [Chains.Abstract, ChainKind.Abs]
64
+ [Chains.Abstract, ChainKind.Abs],
65
+ [Chains.Starknet, ChainKind.Strk]
65
66
  ];
66
67
  function caip2ToChainKind(network) {
67
68
  return CHAIN_MAPPINGS.find(([chain]) => chain === network)?.[1] ?? null;
@@ -93,7 +94,7 @@ async function getAccountOmniStorageBalance(nearProvider, accountId) {
93
94
  })])
94
95
  });
95
96
  }
96
- const OmniAddressSchema = v.custom((input) => typeof input === "string" && (input.startsWith("eth:") || input.startsWith("near:") || input.startsWith("sol:") || input.startsWith("arb:") || input.startsWith("base:") || input.startsWith("btc:") || input.startsWith("bnb:") || input.startsWith("abs:")), "Must comply with omni address schema");
97
+ const OmniAddressSchema = v.custom((input) => typeof input === "string" && (input.startsWith("eth:") || input.startsWith("near:") || input.startsWith("sol:") || input.startsWith("arb:") || input.startsWith("base:") || input.startsWith("btc:") || input.startsWith("bnb:") || input.startsWith("abs:") || input.startsWith("strk:")), "Must comply with omni address schema");
97
98
  /**
98
99
  * Converts a token address from one chain to its equivalent on another chain.
99
100
  * @param nearProvider Near provider used for querying the contract
@@ -243,8 +243,26 @@ function validateTronHexAddress(address) {
243
243
  return false;
244
244
  }
245
245
  }
246
+ function crc16ccitt(data) {
247
+ let crc = 0;
248
+ for (const byte of data) {
249
+ crc ^= byte << 8;
250
+ for (let i = 0; i < 8; i++) crc = crc & 32768 ? crc << 1 ^ 4129 : crc << 1;
251
+ crc &= 65535;
252
+ }
253
+ return [crc >> 8 & 255, crc & 255];
254
+ }
246
255
  function validateTonAddress(address) {
247
- return /^[EU]Q[0-9A-Za-z_-]{46}$/.test(address);
256
+ try {
257
+ const data = _scure_base.base64urlnopad.decode(address);
258
+ if (data.length !== 36) return false;
259
+ const tag = data[0];
260
+ if (tag !== 17 && tag !== 81) return false;
261
+ const [hi, lo] = crc16ccitt(data.subarray(0, 34));
262
+ return data[34] === hi && data[35] === lo;
263
+ } catch {
264
+ return false;
265
+ }
248
266
  }
249
267
  function validateSuiAddress(address) {
250
268
  return /^(?:0x)?[a-fA-F0-9]{64}$/.test(address);
@@ -2,7 +2,7 @@ import { Chains } from "./caip2.js";
2
2
  import { utils } from "@defuse-protocol/internal-utils";
3
3
  import { isAddress } from "viem";
4
4
  import { sha256 } from "@noble/hashes/sha2";
5
- import { base58, bech32, bech32m, hex } from "@scure/base";
5
+ import { base58, base64urlnopad, bech32, bech32m, hex } from "@scure/base";
6
6
  import { PublicKey } from "@solana/web3.js";
7
7
  import { isValidClassicAddress, isValidXAddress } from "ripple-address-codec";
8
8
 
@@ -242,8 +242,26 @@ function validateTronHexAddress(address) {
242
242
  return false;
243
243
  }
244
244
  }
245
+ function crc16ccitt(data) {
246
+ let crc = 0;
247
+ for (const byte of data) {
248
+ crc ^= byte << 8;
249
+ for (let i = 0; i < 8; i++) crc = crc & 32768 ? crc << 1 ^ 4129 : crc << 1;
250
+ crc &= 65535;
251
+ }
252
+ return [crc >> 8 & 255, crc & 255];
253
+ }
245
254
  function validateTonAddress(address) {
246
- return /^[EU]Q[0-9A-Za-z_-]{46}$/.test(address);
255
+ try {
256
+ const data = base64urlnopad.decode(address);
257
+ if (data.length !== 36) return false;
258
+ const tag = data[0];
259
+ if (tag !== 17 && tag !== 81) return false;
260
+ const [hi, lo] = crc16ccitt(data.subarray(0, 34));
261
+ return data[34] === hi && data[35] === lo;
262
+ } catch {
263
+ return false;
264
+ }
247
265
  }
248
266
  function validateSuiAddress(address) {
249
267
  return /^(?:0x)?[a-fA-F0-9]{64}$/.test(address);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defuse-protocol/intents-sdk",
3
- "version": "0.62.2",
3
+ "version": "0.63.1",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "repository": {
@@ -18,10 +18,14 @@
18
18
  "types": "./dist/index.d.ts",
19
19
  "exports": {
20
20
  ".": {
21
- "types": "./dist/index.d.ts",
22
- "import": "./dist/index.js",
23
- "require": "./dist/index.cjs",
24
- "default": "./dist/index.js"
21
+ "import": {
22
+ "types": "./dist/index.d.ts",
23
+ "default": "./dist/index.js"
24
+ },
25
+ "require": {
26
+ "types": "./dist/index.d.cts",
27
+ "default": "./dist/index.cjs"
28
+ }
25
29
  }
26
30
  },
27
31
  "files": [
@@ -45,8 +49,8 @@
45
49
  "ripple-address-codec": "^5.0.0",
46
50
  "valibot": "^1.0.0",
47
51
  "viem": "^2.0.0",
48
- "@defuse-protocol/contract-types": "0.6.3",
49
- "@defuse-protocol/internal-utils": "0.31.1"
52
+ "@defuse-protocol/contract-types": "0.6.4",
53
+ "@defuse-protocol/internal-utils": "0.31.2"
50
54
  },
51
55
  "devDependencies": {
52
56
  "tsdown": "0.19.0"