@defuse-protocol/intents-sdk 0.85.0 → 0.85.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.
|
@@ -204,7 +204,7 @@ function validateXrpAddress(address) {
|
|
|
204
204
|
* - Unified Orchard / Unified Addresses (UA)
|
|
205
205
|
*/
|
|
206
206
|
function validateZcashAddress(address) {
|
|
207
|
-
if (address.startsWith("t1") || address.startsWith("t3")) return
|
|
207
|
+
if (address.startsWith("t1") || address.startsWith("t3")) return validateZcashTransparentAddress(address);
|
|
208
208
|
const expectedHrp = "tex";
|
|
209
209
|
if (address.startsWith(`${expectedHrp}1`)) try {
|
|
210
210
|
const decoded = _scure_base.bech32m.decodeToBytes(address);
|
|
@@ -217,6 +217,34 @@ function validateZcashAddress(address) {
|
|
|
217
217
|
return false;
|
|
218
218
|
}
|
|
219
219
|
/**
|
|
220
|
+
* Validates Zcash transparent addresses (mainnet only).
|
|
221
|
+
*
|
|
222
|
+
* Mirrors zcash_address::ZcashAddress::from_str's Base58Check branch
|
|
223
|
+
* (components/zcash_address/src/encoding.rs in zcash/librustzcash):
|
|
224
|
+
* decode Base58Check, then match the 2-byte version prefix against the
|
|
225
|
+
* mainnet P2PKH/P2SH prefixes from zcash_protocol::constants::mainnet.
|
|
226
|
+
*
|
|
227
|
+
* B58_PUBKEY_ADDRESS_PREFIX = [0x1c, 0xb8] (t1...)
|
|
228
|
+
* B58_SCRIPT_ADDRESS_PREFIX = [0x1c, 0xbd] (t3...)
|
|
229
|
+
*/
|
|
230
|
+
function validateZcashTransparentAddress(address) {
|
|
231
|
+
try {
|
|
232
|
+
const decoded = _scure_base.base58.decode(address);
|
|
233
|
+
if (decoded.length !== 26) return false;
|
|
234
|
+
const version = decoded.subarray(0, 2);
|
|
235
|
+
const isP2pkh = version[0] === 28 && version[1] === 184;
|
|
236
|
+
const isP2sh = version[0] === 28 && version[1] === 189;
|
|
237
|
+
if (!isP2pkh && !isP2sh) return false;
|
|
238
|
+
const payload = decoded.subarray(0, 22);
|
|
239
|
+
const checksum = decoded.subarray(22, 26);
|
|
240
|
+
const expectedChecksum = (0, _noble_hashes_sha2.sha256)((0, _noble_hashes_sha2.sha256)(payload)).subarray(0, 4);
|
|
241
|
+
for (let i = 0; i < 4; i++) if (checksum[i] !== expectedChecksum[i]) return false;
|
|
242
|
+
return true;
|
|
243
|
+
} catch {
|
|
244
|
+
return false;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
220
248
|
* Validates Tron addresses
|
|
221
249
|
* Supports:
|
|
222
250
|
* - hex addresses
|
|
@@ -203,7 +203,7 @@ function validateXrpAddress(address) {
|
|
|
203
203
|
* - Unified Orchard / Unified Addresses (UA)
|
|
204
204
|
*/
|
|
205
205
|
function validateZcashAddress(address) {
|
|
206
|
-
if (address.startsWith("t1") || address.startsWith("t3")) return
|
|
206
|
+
if (address.startsWith("t1") || address.startsWith("t3")) return validateZcashTransparentAddress(address);
|
|
207
207
|
const expectedHrp = "tex";
|
|
208
208
|
if (address.startsWith(`${expectedHrp}1`)) try {
|
|
209
209
|
const decoded = bech32m.decodeToBytes(address);
|
|
@@ -216,6 +216,34 @@ function validateZcashAddress(address) {
|
|
|
216
216
|
return false;
|
|
217
217
|
}
|
|
218
218
|
/**
|
|
219
|
+
* Validates Zcash transparent addresses (mainnet only).
|
|
220
|
+
*
|
|
221
|
+
* Mirrors zcash_address::ZcashAddress::from_str's Base58Check branch
|
|
222
|
+
* (components/zcash_address/src/encoding.rs in zcash/librustzcash):
|
|
223
|
+
* decode Base58Check, then match the 2-byte version prefix against the
|
|
224
|
+
* mainnet P2PKH/P2SH prefixes from zcash_protocol::constants::mainnet.
|
|
225
|
+
*
|
|
226
|
+
* B58_PUBKEY_ADDRESS_PREFIX = [0x1c, 0xb8] (t1...)
|
|
227
|
+
* B58_SCRIPT_ADDRESS_PREFIX = [0x1c, 0xbd] (t3...)
|
|
228
|
+
*/
|
|
229
|
+
function validateZcashTransparentAddress(address) {
|
|
230
|
+
try {
|
|
231
|
+
const decoded = base58.decode(address);
|
|
232
|
+
if (decoded.length !== 26) return false;
|
|
233
|
+
const version = decoded.subarray(0, 2);
|
|
234
|
+
const isP2pkh = version[0] === 28 && version[1] === 184;
|
|
235
|
+
const isP2sh = version[0] === 28 && version[1] === 189;
|
|
236
|
+
if (!isP2pkh && !isP2sh) return false;
|
|
237
|
+
const payload = decoded.subarray(0, 22);
|
|
238
|
+
const checksum = decoded.subarray(22, 26);
|
|
239
|
+
const expectedChecksum = sha256(sha256(payload)).subarray(0, 4);
|
|
240
|
+
for (let i = 0; i < 4; i++) if (checksum[i] !== expectedChecksum[i]) return false;
|
|
241
|
+
return true;
|
|
242
|
+
} catch {
|
|
243
|
+
return false;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
/**
|
|
219
247
|
* Validates Tron addresses
|
|
220
248
|
* Supports:
|
|
221
249
|
* - hex addresses
|