@orbinum/sdk 0.7.4 → 0.7.5
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/index.js +13 -13
- package/dist/index.mjs +13 -13
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1699,10 +1699,7 @@ function isEvmAddress(addr) {
|
|
|
1699
1699
|
return /^0x[0-9a-fA-F]{40}$/.test(addr);
|
|
1700
1700
|
}
|
|
1701
1701
|
function evmAddressToAccountId(evmAddr) {
|
|
1702
|
-
const clean =
|
|
1703
|
-
if (clean.length !== 40) {
|
|
1704
|
-
throw new Error(`Expected 20-byte EVM address, got: ${evmAddr}`);
|
|
1705
|
-
}
|
|
1702
|
+
const clean = cleanEvmAddress(evmAddr);
|
|
1706
1703
|
const bytes = new Uint8Array(32);
|
|
1707
1704
|
for (let i = 0; i < 20; i++) {
|
|
1708
1705
|
bytes[i + 12] = parseInt(clean.slice(i * 2, i * 2 + 2), 16);
|
|
@@ -1710,10 +1707,7 @@ function evmAddressToAccountId(evmAddr) {
|
|
|
1710
1707
|
return bytes;
|
|
1711
1708
|
}
|
|
1712
1709
|
function evmToImplicitSubstrate(evmAddr) {
|
|
1713
|
-
const clean =
|
|
1714
|
-
if (clean.length !== 40) {
|
|
1715
|
-
throw new Error(`Expected 20-byte EVM address, got: ${evmAddr}`);
|
|
1716
|
-
}
|
|
1710
|
+
const clean = cleanEvmAddress(evmAddr);
|
|
1717
1711
|
return "0x" + clean.toLowerCase() + "0".repeat(24);
|
|
1718
1712
|
}
|
|
1719
1713
|
function evmToMappedAccountHex(address) {
|
|
@@ -1734,6 +1728,14 @@ function implicitSubstrateToEvm(accountHex) {
|
|
|
1734
1728
|
}
|
|
1735
1729
|
var ACCOUNT_ID_BYTES = 32;
|
|
1736
1730
|
var EVM_BYTES = 20;
|
|
1731
|
+
var EVM_HEX_RE = /^[0-9a-fA-F]{40}$/;
|
|
1732
|
+
function cleanEvmAddress(addr) {
|
|
1733
|
+
const clean = addr.startsWith("0x") ? addr.slice(2) : addr;
|
|
1734
|
+
if (!EVM_HEX_RE.test(clean)) {
|
|
1735
|
+
throw new Error(`Expected 20-byte EVM address, got: ${addr}`);
|
|
1736
|
+
}
|
|
1737
|
+
return clean;
|
|
1738
|
+
}
|
|
1737
1739
|
function isSubstrateAddress(addr) {
|
|
1738
1740
|
if (!addr || typeof addr !== "string" || isEvmAddress(addr)) return false;
|
|
1739
1741
|
if (addr.length < 40 || addr.length > 60) return false;
|
|
@@ -1768,10 +1770,8 @@ function substrateToEvm(addr) {
|
|
|
1768
1770
|
}
|
|
1769
1771
|
}
|
|
1770
1772
|
function evmToSubstrate(addr) {
|
|
1771
|
-
const
|
|
1772
|
-
if (!
|
|
1773
|
-
const hex = normalized.slice(2);
|
|
1774
|
-
if (hex.length !== 40) return null;
|
|
1773
|
+
const hex = addr.startsWith("0x") ? addr.slice(2) : addr;
|
|
1774
|
+
if (!EVM_HEX_RE.test(hex)) return null;
|
|
1775
1775
|
const mapped = new Uint8Array(ACCOUNT_ID_BYTES);
|
|
1776
1776
|
for (let i = 0; i < EVM_BYTES; i++) {
|
|
1777
1777
|
mapped[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
|
|
@@ -1809,7 +1809,7 @@ function substrateSs58ToAccountIdHex(addr) {
|
|
|
1809
1809
|
function addressToAccountIdHex(addr) {
|
|
1810
1810
|
if (!addr) return null;
|
|
1811
1811
|
if (isEvmAddress(addr)) {
|
|
1812
|
-
const hex =
|
|
1812
|
+
const hex = cleanEvmAddress(addr);
|
|
1813
1813
|
const mapped = new Uint8Array(ACCOUNT_ID_BYTES);
|
|
1814
1814
|
for (let i = 0; i < EVM_BYTES; i++) {
|
|
1815
1815
|
mapped[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
|
package/dist/index.mjs
CHANGED
|
@@ -1572,10 +1572,7 @@ function isEvmAddress(addr) {
|
|
|
1572
1572
|
return /^0x[0-9a-fA-F]{40}$/.test(addr);
|
|
1573
1573
|
}
|
|
1574
1574
|
function evmAddressToAccountId(evmAddr) {
|
|
1575
|
-
const clean =
|
|
1576
|
-
if (clean.length !== 40) {
|
|
1577
|
-
throw new Error(`Expected 20-byte EVM address, got: ${evmAddr}`);
|
|
1578
|
-
}
|
|
1575
|
+
const clean = cleanEvmAddress(evmAddr);
|
|
1579
1576
|
const bytes = new Uint8Array(32);
|
|
1580
1577
|
for (let i = 0; i < 20; i++) {
|
|
1581
1578
|
bytes[i + 12] = parseInt(clean.slice(i * 2, i * 2 + 2), 16);
|
|
@@ -1583,10 +1580,7 @@ function evmAddressToAccountId(evmAddr) {
|
|
|
1583
1580
|
return bytes;
|
|
1584
1581
|
}
|
|
1585
1582
|
function evmToImplicitSubstrate(evmAddr) {
|
|
1586
|
-
const clean =
|
|
1587
|
-
if (clean.length !== 40) {
|
|
1588
|
-
throw new Error(`Expected 20-byte EVM address, got: ${evmAddr}`);
|
|
1589
|
-
}
|
|
1583
|
+
const clean = cleanEvmAddress(evmAddr);
|
|
1590
1584
|
return "0x" + clean.toLowerCase() + "0".repeat(24);
|
|
1591
1585
|
}
|
|
1592
1586
|
function evmToMappedAccountHex(address) {
|
|
@@ -1607,6 +1601,14 @@ function implicitSubstrateToEvm(accountHex) {
|
|
|
1607
1601
|
}
|
|
1608
1602
|
var ACCOUNT_ID_BYTES = 32;
|
|
1609
1603
|
var EVM_BYTES = 20;
|
|
1604
|
+
var EVM_HEX_RE = /^[0-9a-fA-F]{40}$/;
|
|
1605
|
+
function cleanEvmAddress(addr) {
|
|
1606
|
+
const clean = addr.startsWith("0x") ? addr.slice(2) : addr;
|
|
1607
|
+
if (!EVM_HEX_RE.test(clean)) {
|
|
1608
|
+
throw new Error(`Expected 20-byte EVM address, got: ${addr}`);
|
|
1609
|
+
}
|
|
1610
|
+
return clean;
|
|
1611
|
+
}
|
|
1610
1612
|
function isSubstrateAddress(addr) {
|
|
1611
1613
|
if (!addr || typeof addr !== "string" || isEvmAddress(addr)) return false;
|
|
1612
1614
|
if (addr.length < 40 || addr.length > 60) return false;
|
|
@@ -1641,10 +1643,8 @@ function substrateToEvm(addr) {
|
|
|
1641
1643
|
}
|
|
1642
1644
|
}
|
|
1643
1645
|
function evmToSubstrate(addr) {
|
|
1644
|
-
const
|
|
1645
|
-
if (!
|
|
1646
|
-
const hex = normalized.slice(2);
|
|
1647
|
-
if (hex.length !== 40) return null;
|
|
1646
|
+
const hex = addr.startsWith("0x") ? addr.slice(2) : addr;
|
|
1647
|
+
if (!EVM_HEX_RE.test(hex)) return null;
|
|
1648
1648
|
const mapped = new Uint8Array(ACCOUNT_ID_BYTES);
|
|
1649
1649
|
for (let i = 0; i < EVM_BYTES; i++) {
|
|
1650
1650
|
mapped[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
|
|
@@ -1682,7 +1682,7 @@ function substrateSs58ToAccountIdHex(addr) {
|
|
|
1682
1682
|
function addressToAccountIdHex(addr) {
|
|
1683
1683
|
if (!addr) return null;
|
|
1684
1684
|
if (isEvmAddress(addr)) {
|
|
1685
|
-
const hex =
|
|
1685
|
+
const hex = cleanEvmAddress(addr);
|
|
1686
1686
|
const mapped = new Uint8Array(ACCOUNT_ID_BYTES);
|
|
1687
1687
|
for (let i = 0; i < EVM_BYTES; i++) {
|
|
1688
1688
|
mapped[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
|