@defuse-protocol/intents-sdk 0.62.1 → 0.63.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.
- package/dist/src/bridges/omni-bridge/omni-bridge-utils.cjs +3 -2
- package/dist/src/bridges/omni-bridge/omni-bridge-utils.js +3 -2
- package/dist/src/bridges/omni-bridge/omni-bridge.cjs +4 -1
- package/dist/src/bridges/omni-bridge/omni-bridge.js +4 -1
- package/dist/src/lib/validateAddress.cjs +19 -1
- package/dist/src/lib/validateAddress.js +20 -2
- package/package.json +1 -1
|
@@ -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
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../../../_virtual/rolldown_runtime.cjs');
|
|
2
2
|
const require_errors = require('../../classes/errors.cjs');
|
|
3
3
|
const require_route_enum = require('../../constants/route-enum.cjs');
|
|
4
|
+
const require_caip2 = require('../../lib/caip2.cjs');
|
|
4
5
|
const require_estimate_fee = require('../../lib/estimate-fee.cjs');
|
|
5
6
|
const require_parse_defuse_asset_id = require('../../lib/parse-defuse-asset-id.cjs');
|
|
6
7
|
const require_validateAddress = require('../../lib/validateAddress.cjs');
|
|
@@ -139,9 +140,11 @@ var OmniBridge = class {
|
|
|
139
140
|
(0, _defuse_protocol_internal_utils.assert)(utxoProtocolFee !== void 0 && utxoProtocolFee > 0n, `Invalid Omni Bridge utxo protocol fee: expected > 0, got ${utxoProtocolFee}`);
|
|
140
141
|
amount += utxoMaxGasFee + utxoProtocolFee;
|
|
141
142
|
}
|
|
143
|
+
let destinationAddress = args.withdrawalParams.destinationAddress;
|
|
144
|
+
if (assetInfo.blockchain === require_caip2.Chains.Bitcoin && /^bc1/i.test(destinationAddress)) destinationAddress = destinationAddress.toLowerCase();
|
|
142
145
|
intents.push(...require_omni_bridge_utils.createWithdrawIntentsPrimitive({
|
|
143
146
|
assetId: args.withdrawalParams.assetId,
|
|
144
|
-
destinationAddress
|
|
147
|
+
destinationAddress,
|
|
145
148
|
amount,
|
|
146
149
|
omniChainKind,
|
|
147
150
|
intentsContract: this.envConfig.contractID,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { InvalidDestinationAddressForWithdrawalError, MinWithdrawalAmountError, UnsupportedAssetIdError } from "../../classes/errors.js";
|
|
2
2
|
import { RouteEnum } from "../../constants/route-enum.js";
|
|
3
|
+
import { Chains } from "../../lib/caip2.js";
|
|
3
4
|
import { getFeeQuote, getUnderlyingFee } from "../../lib/estimate-fee.js";
|
|
4
5
|
import { parseDefuseAssetId } from "../../lib/parse-defuse-asset-id.js";
|
|
5
6
|
import { validateAddress } from "../../lib/validateAddress.js";
|
|
@@ -137,9 +138,11 @@ var OmniBridge = class {
|
|
|
137
138
|
assert(utxoProtocolFee !== void 0 && utxoProtocolFee > 0n, `Invalid Omni Bridge utxo protocol fee: expected > 0, got ${utxoProtocolFee}`);
|
|
138
139
|
amount += utxoMaxGasFee + utxoProtocolFee;
|
|
139
140
|
}
|
|
141
|
+
let destinationAddress = args.withdrawalParams.destinationAddress;
|
|
142
|
+
if (assetInfo.blockchain === Chains.Bitcoin && /^bc1/i.test(destinationAddress)) destinationAddress = destinationAddress.toLowerCase();
|
|
140
143
|
intents.push(...createWithdrawIntentsPrimitive({
|
|
141
144
|
assetId: args.withdrawalParams.assetId,
|
|
142
|
-
destinationAddress
|
|
145
|
+
destinationAddress,
|
|
143
146
|
amount,
|
|
144
147
|
omniChainKind,
|
|
145
148
|
intentsContract: this.envConfig.contractID,
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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);
|