@defuse-protocol/intents-sdk 0.85.1 → 0.86.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/poa-bridge/poa-bridge-utils.cjs +4 -2
- package/dist/src/bridges/poa-bridge/poa-bridge-utils.js +4 -2
- package/dist/src/lib/caip2.cjs +2 -1
- package/dist/src/lib/caip2.d.cts +1 -0
- package/dist/src/lib/caip2.d.ts +1 -0
- package/dist/src/lib/caip2.js +2 -1
- package/dist/src/lib/compareAddresses.cjs +2 -1
- package/dist/src/lib/compareAddresses.js +2 -1
- package/dist/src/lib/validateAddress.cjs +49 -0
- package/dist/src/lib/validateAddress.js +49 -0
- package/dist/src/lib/zcash-unified-address.cjs +1 -1
- package/dist/src/lib/zcash-unified-address.js +1 -1
- package/package.json +2 -2
|
@@ -42,7 +42,8 @@ const caip2Mapping = {
|
|
|
42
42
|
[require_caip2.Chains.Dash]: "dash:mainnet",
|
|
43
43
|
[require_caip2.Chains.Plasma]: "eth:9745",
|
|
44
44
|
[require_caip2.Chains.Adi]: "eth:36900",
|
|
45
|
-
[require_caip2.Chains.Hood]: "eth:4663"
|
|
45
|
+
[require_caip2.Chains.Hood]: "eth:4663",
|
|
46
|
+
[require_caip2.Chains.Qtc]: "quantus:mainnet"
|
|
46
47
|
};
|
|
47
48
|
function toPoaNetwork(caip2) {
|
|
48
49
|
if (caip2Mapping[caip2] == null) throw new Error(`Unsupported POA Bridge chain = ${caip2}`);
|
|
@@ -67,7 +68,8 @@ const tokenPrefixMapping = {
|
|
|
67
68
|
dash: require_caip2.Chains.Dash,
|
|
68
69
|
plasma: require_caip2.Chains.Plasma,
|
|
69
70
|
adi: require_caip2.Chains.Adi,
|
|
70
|
-
hood: require_caip2.Chains.Hood
|
|
71
|
+
hood: require_caip2.Chains.Hood,
|
|
72
|
+
qtc: require_caip2.Chains.Qtc
|
|
71
73
|
};
|
|
72
74
|
function contractIdToCaip2(contractId) {
|
|
73
75
|
for (const [prefix, caip2] of Object.entries(tokenPrefixMapping)) if (contractId.startsWith(`${prefix}.`) || contractId.startsWith(`${prefix}-`)) return caip2;
|
|
@@ -41,7 +41,8 @@ const caip2Mapping = {
|
|
|
41
41
|
[Chains.Dash]: "dash:mainnet",
|
|
42
42
|
[Chains.Plasma]: "eth:9745",
|
|
43
43
|
[Chains.Adi]: "eth:36900",
|
|
44
|
-
[Chains.Hood]: "eth:4663"
|
|
44
|
+
[Chains.Hood]: "eth:4663",
|
|
45
|
+
[Chains.Qtc]: "quantus:mainnet"
|
|
45
46
|
};
|
|
46
47
|
function toPoaNetwork(caip2) {
|
|
47
48
|
if (caip2Mapping[caip2] == null) throw new Error(`Unsupported POA Bridge chain = ${caip2}`);
|
|
@@ -66,7 +67,8 @@ const tokenPrefixMapping = {
|
|
|
66
67
|
dash: Chains.Dash,
|
|
67
68
|
plasma: Chains.Plasma,
|
|
68
69
|
adi: Chains.Adi,
|
|
69
|
-
hood: Chains.Hood
|
|
70
|
+
hood: Chains.Hood,
|
|
71
|
+
qtc: Chains.Qtc
|
|
70
72
|
};
|
|
71
73
|
function contractIdToCaip2(contractId) {
|
|
72
74
|
for (const [prefix, caip2] of Object.entries(tokenPrefixMapping)) if (contractId.startsWith(`${prefix}.`) || contractId.startsWith(`${prefix}-`)) return caip2;
|
package/dist/src/lib/caip2.cjs
CHANGED
|
@@ -42,7 +42,8 @@ const Chains = {
|
|
|
42
42
|
Abstract: "eip155:2741",
|
|
43
43
|
HyperCore: "hlcore:mainnet",
|
|
44
44
|
HyperEvm: "eip155:999",
|
|
45
|
-
Hood: "eip155:4663"
|
|
45
|
+
Hood: "eip155:4663",
|
|
46
|
+
Qtc: "quantus:mainnet"
|
|
46
47
|
};
|
|
47
48
|
function getEIP155ChainId(chain) {
|
|
48
49
|
(0, _defuse_protocol_internal_utils.assert)(chain.startsWith("eip155:"), "Chain is not an EIP-155 chain");
|
package/dist/src/lib/caip2.d.cts
CHANGED
package/dist/src/lib/caip2.d.ts
CHANGED
package/dist/src/lib/caip2.js
CHANGED
|
@@ -41,7 +41,8 @@ const Chains = {
|
|
|
41
41
|
Abstract: "eip155:2741",
|
|
42
42
|
HyperCore: "hlcore:mainnet",
|
|
43
43
|
HyperEvm: "eip155:999",
|
|
44
|
-
Hood: "eip155:4663"
|
|
44
|
+
Hood: "eip155:4663",
|
|
45
|
+
Qtc: "quantus:mainnet"
|
|
45
46
|
};
|
|
46
47
|
function getEIP155ChainId(chain) {
|
|
47
48
|
assert(chain.startsWith("eip155:"), "Chain is not an EIP-155 chain");
|
|
@@ -50,7 +50,8 @@ function compareAddresses(a, b, blockchain) {
|
|
|
50
50
|
case require_caip2.Chains.XRPL:
|
|
51
51
|
case require_caip2.Chains.Cardano:
|
|
52
52
|
case require_caip2.Chains.Aleo:
|
|
53
|
-
case require_caip2.Chains.Dash:
|
|
53
|
+
case require_caip2.Chains.Dash:
|
|
54
|
+
case require_caip2.Chains.Qtc: return a === b;
|
|
54
55
|
default: return false;
|
|
55
56
|
}
|
|
56
57
|
} catch {
|
|
@@ -4,6 +4,7 @@ const require_ton_address = require('./ton-address.cjs');
|
|
|
4
4
|
const require_zcash_unified_address = require('./zcash-unified-address.cjs');
|
|
5
5
|
let _defuse_protocol_internal_utils = require("@defuse-protocol/internal-utils");
|
|
6
6
|
let viem = require("viem");
|
|
7
|
+
let _noble_hashes_blake2 = require("@noble/hashes/blake2");
|
|
7
8
|
let _noble_hashes_sha2 = require("@noble/hashes/sha2");
|
|
8
9
|
let _scure_base = require("@scure/base");
|
|
9
10
|
let ripple_address_codec = require("ripple-address-codec");
|
|
@@ -55,6 +56,7 @@ function validateAddress(address, blockchain) {
|
|
|
55
56
|
case require_caip2.Chains.Hood: return validateEthAddress(address);
|
|
56
57
|
case require_caip2.Chains.Aleo: return validateAleoAddress(address);
|
|
57
58
|
case require_caip2.Chains.Dash: return validateDashAddress(address);
|
|
59
|
+
case require_caip2.Chains.Qtc: return validateQuantusAddress(address);
|
|
58
60
|
default: return false;
|
|
59
61
|
}
|
|
60
62
|
}
|
|
@@ -537,6 +539,53 @@ function validateDashAddress(address) {
|
|
|
537
539
|
return false;
|
|
538
540
|
}
|
|
539
541
|
}
|
|
542
|
+
/** Substrate SS58 checksum domain separator: the ASCII bytes of "SS58PRE". */
|
|
543
|
+
const SS58_CHECKSUM_PREFIX = new Uint8Array([
|
|
544
|
+
83,
|
|
545
|
+
83,
|
|
546
|
+
53,
|
|
547
|
+
56,
|
|
548
|
+
80,
|
|
549
|
+
82,
|
|
550
|
+
69
|
|
551
|
+
]);
|
|
552
|
+
/**
|
|
553
|
+
* Network prefix 189 in its 2-byte SS58 encoding:
|
|
554
|
+
* b0 = ((prefix & 0x00fc) >> 2) | 0x40
|
|
555
|
+
* b1 = (prefix >> 8) | ((prefix & 0x0003) << 6)
|
|
556
|
+
*/
|
|
557
|
+
const QUANTUS_SS58_PREFIX_BYTES = [111, 64];
|
|
558
|
+
/**
|
|
559
|
+
* Validates Quantus addresses (SS58, mainnet only).
|
|
560
|
+
*
|
|
561
|
+
* Quantus is a Polkadot SDK chain, so addresses are standard SS58-encoded
|
|
562
|
+
* 32-byte account ids (Poseidon2 hash of an ML-DSA public key) with network
|
|
563
|
+
* prefix 189 — the `qz...` form.
|
|
564
|
+
*
|
|
565
|
+
* Mirrors `Ss58Codec::from_ss58check_with_version` in
|
|
566
|
+
* substrate/primitives/core/src/crypto.rs (paritytech/polkadot-sdk):
|
|
567
|
+
* base58-decode, read the 1- or 2-byte network prefix, then verify the
|
|
568
|
+
* 2-byte blake2b-512("SS58PRE" || prefix || account id) checksum.
|
|
569
|
+
*
|
|
570
|
+
* Prefix 189 is >= 64, so it uses the 2-byte encoding: [0x6f, 0x40].
|
|
571
|
+
*/
|
|
572
|
+
function validateQuantusAddress(address) {
|
|
573
|
+
try {
|
|
574
|
+
const decoded = _scure_base.base58.decode(address);
|
|
575
|
+
if (decoded.length !== 36) return false;
|
|
576
|
+
if (decoded[0] !== QUANTUS_SS58_PREFIX_BYTES[0]) return false;
|
|
577
|
+
if (decoded[1] !== QUANTUS_SS58_PREFIX_BYTES[1]) return false;
|
|
578
|
+
const payload = decoded.subarray(0, 34);
|
|
579
|
+
const checksum = decoded.subarray(34, 36);
|
|
580
|
+
const preimage = new Uint8Array(SS58_CHECKSUM_PREFIX.length + payload.length);
|
|
581
|
+
preimage.set(SS58_CHECKSUM_PREFIX);
|
|
582
|
+
preimage.set(payload, SS58_CHECKSUM_PREFIX.length);
|
|
583
|
+
const expectedChecksum = (0, _noble_hashes_blake2.blake2b)(preimage, { dkLen: 64 });
|
|
584
|
+
return checksum[0] === expectedChecksum[0] && checksum[1] === expectedChecksum[1];
|
|
585
|
+
} catch {
|
|
586
|
+
return false;
|
|
587
|
+
}
|
|
588
|
+
}
|
|
540
589
|
|
|
541
590
|
//#endregion
|
|
542
591
|
exports.validateAddress = validateAddress;
|
|
@@ -3,6 +3,7 @@ import { TON_ADDRESS_TAG_BOUNCEABLE_MAINNET, TON_ADDRESS_TAG_NON_BOUNCEABLE_MAIN
|
|
|
3
3
|
import { validateZcashUnifiedAddress } from "./zcash-unified-address.js";
|
|
4
4
|
import { utils } from "@defuse-protocol/internal-utils";
|
|
5
5
|
import { isAddress } from "viem";
|
|
6
|
+
import { blake2b } from "@noble/hashes/blake2";
|
|
6
7
|
import { sha256 } from "@noble/hashes/sha2";
|
|
7
8
|
import { base58, bech32, bech32m, hex } from "@scure/base";
|
|
8
9
|
import { isValidClassicAddress, isValidXAddress } from "ripple-address-codec";
|
|
@@ -54,6 +55,7 @@ function validateAddress(address, blockchain) {
|
|
|
54
55
|
case Chains.Hood: return validateEthAddress(address);
|
|
55
56
|
case Chains.Aleo: return validateAleoAddress(address);
|
|
56
57
|
case Chains.Dash: return validateDashAddress(address);
|
|
58
|
+
case Chains.Qtc: return validateQuantusAddress(address);
|
|
57
59
|
default: return false;
|
|
58
60
|
}
|
|
59
61
|
}
|
|
@@ -536,6 +538,53 @@ function validateDashAddress(address) {
|
|
|
536
538
|
return false;
|
|
537
539
|
}
|
|
538
540
|
}
|
|
541
|
+
/** Substrate SS58 checksum domain separator: the ASCII bytes of "SS58PRE". */
|
|
542
|
+
const SS58_CHECKSUM_PREFIX = new Uint8Array([
|
|
543
|
+
83,
|
|
544
|
+
83,
|
|
545
|
+
53,
|
|
546
|
+
56,
|
|
547
|
+
80,
|
|
548
|
+
82,
|
|
549
|
+
69
|
|
550
|
+
]);
|
|
551
|
+
/**
|
|
552
|
+
* Network prefix 189 in its 2-byte SS58 encoding:
|
|
553
|
+
* b0 = ((prefix & 0x00fc) >> 2) | 0x40
|
|
554
|
+
* b1 = (prefix >> 8) | ((prefix & 0x0003) << 6)
|
|
555
|
+
*/
|
|
556
|
+
const QUANTUS_SS58_PREFIX_BYTES = [111, 64];
|
|
557
|
+
/**
|
|
558
|
+
* Validates Quantus addresses (SS58, mainnet only).
|
|
559
|
+
*
|
|
560
|
+
* Quantus is a Polkadot SDK chain, so addresses are standard SS58-encoded
|
|
561
|
+
* 32-byte account ids (Poseidon2 hash of an ML-DSA public key) with network
|
|
562
|
+
* prefix 189 — the `qz...` form.
|
|
563
|
+
*
|
|
564
|
+
* Mirrors `Ss58Codec::from_ss58check_with_version` in
|
|
565
|
+
* substrate/primitives/core/src/crypto.rs (paritytech/polkadot-sdk):
|
|
566
|
+
* base58-decode, read the 1- or 2-byte network prefix, then verify the
|
|
567
|
+
* 2-byte blake2b-512("SS58PRE" || prefix || account id) checksum.
|
|
568
|
+
*
|
|
569
|
+
* Prefix 189 is >= 64, so it uses the 2-byte encoding: [0x6f, 0x40].
|
|
570
|
+
*/
|
|
571
|
+
function validateQuantusAddress(address) {
|
|
572
|
+
try {
|
|
573
|
+
const decoded = base58.decode(address);
|
|
574
|
+
if (decoded.length !== 36) return false;
|
|
575
|
+
if (decoded[0] !== QUANTUS_SS58_PREFIX_BYTES[0]) return false;
|
|
576
|
+
if (decoded[1] !== QUANTUS_SS58_PREFIX_BYTES[1]) return false;
|
|
577
|
+
const payload = decoded.subarray(0, 34);
|
|
578
|
+
const checksum = decoded.subarray(34, 36);
|
|
579
|
+
const preimage = new Uint8Array(SS58_CHECKSUM_PREFIX.length + payload.length);
|
|
580
|
+
preimage.set(SS58_CHECKSUM_PREFIX);
|
|
581
|
+
preimage.set(payload, SS58_CHECKSUM_PREFIX.length);
|
|
582
|
+
const expectedChecksum = blake2b(preimage, { dkLen: 64 });
|
|
583
|
+
return checksum[0] === expectedChecksum[0] && checksum[1] === expectedChecksum[1];
|
|
584
|
+
} catch {
|
|
585
|
+
return false;
|
|
586
|
+
}
|
|
587
|
+
}
|
|
539
588
|
|
|
540
589
|
//#endregion
|
|
541
590
|
export { validateAddress };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const require_rolldown_runtime = require('../../_virtual/rolldown_runtime.cjs');
|
|
2
|
-
let _scure_base = require("@scure/base");
|
|
3
2
|
let _noble_hashes_blake2 = require("@noble/hashes/blake2");
|
|
3
|
+
let _scure_base = require("@scure/base");
|
|
4
4
|
|
|
5
5
|
//#region src/lib/zcash-unified-address.ts
|
|
6
6
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defuse-protocol/intents-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.86.0",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"valibot": "^1.0.0",
|
|
60
60
|
"viem": "^2.0.0",
|
|
61
61
|
"@defuse-protocol/contract-types": "0.6.4",
|
|
62
|
-
"@defuse-protocol/internal-utils": "0.
|
|
62
|
+
"@defuse-protocol/internal-utils": "0.40.0"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
65
|
"@ton/core": "^0.60.0",
|