@layerzerolabs/chain-utils 0.2.8 → 0.2.10
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/.turbo/turbo-build.log +14 -14
- package/.turbo/turbo-lint.log +1 -1
- package/.turbo/turbo-test.log +3 -3
- package/dist/{ICZYLYGP.cjs → 6ZQQF5PQ.cjs} +29 -29
- package/dist/6ZQQF5PQ.cjs.map +1 -0
- package/dist/{BG5XW4YA.js → TNQ4ZWJM.js} +3 -3
- package/dist/TNQ4ZWJM.js.map +1 -0
- package/dist/addressParser.cjs +9 -9
- package/dist/addressParser.js +1 -1
- package/dist/addressParser.test.cjs +26 -26
- package/dist/addressParser.test.cjs.map +1 -1
- package/dist/addressParser.test.js +2 -2
- package/dist/addressParser.test.js.map +1 -1
- package/dist/index.cjs +9 -9
- package/dist/index.js +1 -1
- package/package.json +9 -9
- package/src/addressParser.test.ts +1 -1
- package/src/addressParser.ts +2 -2
- package/dist/BG5XW4YA.js.map +0 -1
- package/dist/ICZYLYGP.cjs.map +0 -1
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _6ZQQF5PQ_cjs = require('./6ZQQF5PQ.cjs');
|
|
4
4
|
var KHVGLVR5_cjs = require('./KHVGLVR5.cjs');
|
|
5
5
|
var bs58 = require('bs58');
|
|
6
6
|
var tty = require('tty');
|
|
7
7
|
var commonChainModel = require('@layerzerolabs/common-chain-model');
|
|
8
|
-
var
|
|
8
|
+
var commonEncodingUtils = require('@layerzerolabs/common-encoding-utils');
|
|
9
9
|
var layerzeroDefinitions = require('@layerzerolabs/layerzero-definitions');
|
|
10
10
|
|
|
11
11
|
function _interopNamespace(e) {
|
|
@@ -18104,7 +18104,7 @@ var randomBytes = /* @__PURE__ */ KHVGLVR5_cjs.__name((length) => {
|
|
|
18104
18104
|
return bytes;
|
|
18105
18105
|
}, "randomBytes");
|
|
18106
18106
|
var randomHex = /* @__PURE__ */ KHVGLVR5_cjs.__name((byteLength) => {
|
|
18107
|
-
return commonChainModel.normalizeHex(
|
|
18107
|
+
return commonChainModel.normalizeHex(commonEncodingUtils.bytesToHexPrefixed(randomBytes(byteLength)));
|
|
18108
18108
|
}, "randomHex");
|
|
18109
18109
|
var runPropertyTest = /* @__PURE__ */ KHVGLVR5_cjs.__name((fn2, iterations = 100) => {
|
|
18110
18110
|
for (let i = 0; i < iterations; i++) {
|
|
@@ -18120,7 +18120,7 @@ describe("addressParser - hex/EVM chains", () => {
|
|
|
18120
18120
|
];
|
|
18121
18121
|
evmChains.forEach((chain) => {
|
|
18122
18122
|
describe(chain, () => {
|
|
18123
|
-
const parser =
|
|
18123
|
+
const parser = _6ZQQF5PQ_cjs.addressParser(chain);
|
|
18124
18124
|
it("maintains roundtrip invariant: hex -> native -> hex", () => {
|
|
18125
18125
|
runPropertyTest(() => {
|
|
18126
18126
|
const input = randomHex(20);
|
|
@@ -18133,7 +18133,7 @@ describe("addressParser - hex/EVM chains", () => {
|
|
|
18133
18133
|
runPropertyTest(() => {
|
|
18134
18134
|
const input = randomHex(20);
|
|
18135
18135
|
const nativeStr = parser.normalizedToNativeString(input);
|
|
18136
|
-
const bytesFromHex =
|
|
18136
|
+
const bytesFromHex = commonEncodingUtils.hexToBytes(nativeStr);
|
|
18137
18137
|
const nativeBytes = parser.nativeToBytes(nativeStr);
|
|
18138
18138
|
globalExpect(nativeBytes).toEqual(bytesFromHex);
|
|
18139
18139
|
});
|
|
@@ -18153,23 +18153,23 @@ describe("addressParser - hex/EVM chains", () => {
|
|
|
18153
18153
|
runPropertyTest(() => {
|
|
18154
18154
|
const byteLength = Math.floor(Math.random() * 32) + 1;
|
|
18155
18155
|
const input = randomHex(byteLength);
|
|
18156
|
-
const padded =
|
|
18156
|
+
const padded = _6ZQQF5PQ_cjs.addressParser.normalizedToBytes32Hex(input);
|
|
18157
18157
|
globalExpect(padded.length).toBe(66);
|
|
18158
|
-
globalExpect(padded).toBe(
|
|
18158
|
+
globalExpect(padded).toBe(commonEncodingUtils.hexZeroPad(input, 32));
|
|
18159
18159
|
});
|
|
18160
18160
|
});
|
|
18161
18161
|
it("handles edge cases", () => {
|
|
18162
|
-
const parser =
|
|
18162
|
+
const parser = _6ZQQF5PQ_cjs.addressParser(layerzeroDefinitions.ChainName.ETHEREUM);
|
|
18163
18163
|
const empty = commonChainModel.normalizeHex("0x");
|
|
18164
18164
|
globalExpect(parser.normalizedToNative(empty).nativeAddress.length).toBe(42);
|
|
18165
18165
|
const max = commonChainModel.normalizeHex("0x" + "ff".repeat(20));
|
|
18166
18166
|
globalExpect(parser.nativeToNormalized(parser.normalizedToNative(max))).toBe(max);
|
|
18167
18167
|
const single = commonChainModel.normalizeHex("0x01");
|
|
18168
|
-
globalExpect(parser.normalizedToNative(single).nativeAddress).toBe(
|
|
18168
|
+
globalExpect(parser.normalizedToNative(single).nativeAddress).toBe(commonEncodingUtils.hexZeroPad("0x01", 20));
|
|
18169
18169
|
});
|
|
18170
18170
|
});
|
|
18171
18171
|
describe("addressParser - base58 chains (Solana)", () => {
|
|
18172
|
-
const parser =
|
|
18172
|
+
const parser = _6ZQQF5PQ_cjs.addressParser(layerzeroDefinitions.ChainName.SOLANA);
|
|
18173
18173
|
it("maintains roundtrip invariant: hex -> base58 -> hex", () => {
|
|
18174
18174
|
runPropertyTest(() => {
|
|
18175
18175
|
const byteLength = Math.floor(Math.random() * 32) + 1;
|
|
@@ -18183,7 +18183,7 @@ describe("addressParser - base58 chains (Solana)", () => {
|
|
|
18183
18183
|
runPropertyTest(() => {
|
|
18184
18184
|
const input = randomHex(32);
|
|
18185
18185
|
const nativeStr = parser.normalizedToNativeString(input);
|
|
18186
|
-
const expectedBase58 = bs58__namespace.encode(
|
|
18186
|
+
const expectedBase58 = bs58__namespace.encode(commonEncodingUtils.hexToBytes(input));
|
|
18187
18187
|
globalExpect(nativeStr).toBe(expectedBase58);
|
|
18188
18188
|
const nativeBytes = parser.nativeToBytes(nativeStr);
|
|
18189
18189
|
globalExpect(nativeBytes).toEqual(bs58__namespace.decode(expectedBase58));
|
|
@@ -18196,7 +18196,7 @@ describe("addressParser - base58 chains (Solana)", () => {
|
|
|
18196
18196
|
const native = parser.normalizedToNativeString(input);
|
|
18197
18197
|
const padded = parser.nativeToBytes32Hex(native);
|
|
18198
18198
|
globalExpect(padded.length).toBe(66);
|
|
18199
|
-
globalExpect(parser.nativeToNormalized(native)).toBe(commonChainModel.normalizeHex(
|
|
18199
|
+
globalExpect(parser.nativeToNormalized(native)).toBe(commonChainModel.normalizeHex(commonEncodingUtils.bytesToHexPrefixed(commonEncodingUtils.hexToBytes(input))));
|
|
18200
18200
|
});
|
|
18201
18201
|
});
|
|
18202
18202
|
it("handles edge cases", () => {
|
|
@@ -18212,26 +18212,26 @@ describe("addressParser - base58 chains (Solana)", () => {
|
|
|
18212
18212
|
});
|
|
18213
18213
|
describe("addressParser - chain validation", () => {
|
|
18214
18214
|
it("validates chain names for nativeToBytes32Hex", () => {
|
|
18215
|
-
const evmParser =
|
|
18216
|
-
const solanaParser =
|
|
18215
|
+
const evmParser = _6ZQQF5PQ_cjs.addressParser(layerzeroDefinitions.ChainName.ETHEREUM);
|
|
18216
|
+
const solanaParser = _6ZQQF5PQ_cjs.addressParser(layerzeroDefinitions.ChainName.SOLANA);
|
|
18217
18217
|
const evmAddress = evmParser.normalizedToNative(randomHex(20));
|
|
18218
18218
|
const solanaAddress = solanaParser.normalizedToNative(randomHex(32));
|
|
18219
18219
|
globalExpect(() => solanaParser.nativeToBytes32Hex(evmAddress)).toThrow(/Cannot convert/);
|
|
18220
18220
|
globalExpect(() => evmParser.nativeToBytes32Hex(solanaAddress)).toThrow(/Cannot convert/);
|
|
18221
18221
|
});
|
|
18222
18222
|
it("accepts string addresses without validation", () => {
|
|
18223
|
-
const parser =
|
|
18223
|
+
const parser = _6ZQQF5PQ_cjs.addressParser(layerzeroDefinitions.ChainName.ETHEREUM);
|
|
18224
18224
|
const randomAddress = "0x" + "ab".repeat(20);
|
|
18225
18225
|
const result = parser.nativeToNormalized(randomAddress);
|
|
18226
18226
|
globalExpect(result).toBe(commonChainModel.normalizeHex(randomAddress));
|
|
18227
18227
|
const padded = parser.nativeToBytes32Hex(randomAddress);
|
|
18228
18228
|
globalExpect(padded.length).toBe(66);
|
|
18229
18229
|
const bytes = parser.nativeToBytes(randomAddress);
|
|
18230
|
-
globalExpect(bytes).toEqual(
|
|
18230
|
+
globalExpect(bytes).toEqual(commonEncodingUtils.hexToBytes(randomAddress));
|
|
18231
18231
|
});
|
|
18232
18232
|
});
|
|
18233
18233
|
describe("addressParser - TON", () => {
|
|
18234
|
-
const parser =
|
|
18234
|
+
const parser = _6ZQQF5PQ_cjs.addressParser(layerzeroDefinitions.ChainName.TON);
|
|
18235
18235
|
it("maintains roundtrip invariant: hex -> ton address -> hex", () => {
|
|
18236
18236
|
runPropertyTest(() => {
|
|
18237
18237
|
const byteLength = Math.floor(Math.random() * 32) + 1;
|
|
@@ -18292,7 +18292,7 @@ describe("addressParser - TON", () => {
|
|
|
18292
18292
|
});
|
|
18293
18293
|
});
|
|
18294
18294
|
describe("addressParser - Stellar", () => {
|
|
18295
|
-
const parser =
|
|
18295
|
+
const parser = _6ZQQF5PQ_cjs.addressParser(layerzeroDefinitions.ChainName.STELLAR);
|
|
18296
18296
|
const validTestAddresses = {
|
|
18297
18297
|
// Account address (G...)
|
|
18298
18298
|
account: "GA7QYNF7SOWQ3GLR2BGMZEHXAVIRZA4KVWLTJJFC7MGXUA74P7UJVSGZ",
|
|
@@ -18419,7 +18419,7 @@ describe("addressParser - Stellar", () => {
|
|
|
18419
18419
|
globalExpect(bytes32Hex.length).toBe(66);
|
|
18420
18420
|
globalExpect(bytes32Hex).toMatch(/^0x[0-9a-f]{64}$/);
|
|
18421
18421
|
globalExpect(bytes32.length).toBe(32);
|
|
18422
|
-
globalExpect(
|
|
18422
|
+
globalExpect(commonEncodingUtils.bytesToHexPrefixed(bytes32)).toBe(bytes32Hex);
|
|
18423
18423
|
});
|
|
18424
18424
|
it("decodes contract address (C...) to 32 bytes", () => {
|
|
18425
18425
|
const stellarAddress = validTestAddresses.contract;
|
|
@@ -18427,7 +18427,7 @@ describe("addressParser - Stellar", () => {
|
|
|
18427
18427
|
const bytes32 = parser.nativeToBytes32(stellarAddress);
|
|
18428
18428
|
globalExpect(bytes32Hex.length).toBe(66);
|
|
18429
18429
|
globalExpect(bytes32.length).toBe(32);
|
|
18430
|
-
globalExpect(
|
|
18430
|
+
globalExpect(commonEncodingUtils.bytesToHexPrefixed(bytes32)).toBe(bytes32Hex);
|
|
18431
18431
|
});
|
|
18432
18432
|
it("decodes liquidity pool address (L...) to 32 bytes", () => {
|
|
18433
18433
|
const stellarAddress = validTestAddresses.liquidityPool;
|
|
@@ -18435,7 +18435,7 @@ describe("addressParser - Stellar", () => {
|
|
|
18435
18435
|
const bytes32 = parser.nativeToBytes32(stellarAddress);
|
|
18436
18436
|
globalExpect(bytes32Hex.length).toBe(66);
|
|
18437
18437
|
globalExpect(bytes32.length).toBe(32);
|
|
18438
|
-
globalExpect(
|
|
18438
|
+
globalExpect(commonEncodingUtils.bytesToHexPrefixed(bytes32)).toBe(bytes32Hex);
|
|
18439
18439
|
});
|
|
18440
18440
|
it("decodes claimable balance address (B...) to 32 bytes (skipping version byte)", () => {
|
|
18441
18441
|
const stellarAddress = validTestAddresses.claimableBalance;
|
|
@@ -18444,7 +18444,7 @@ describe("addressParser - Stellar", () => {
|
|
|
18444
18444
|
globalExpect(bytes32Hex.length).toBe(66);
|
|
18445
18445
|
globalExpect(bytes32Hex).toMatch(/^0x[0-9a-f]{64}$/);
|
|
18446
18446
|
globalExpect(bytes32.length).toBe(32);
|
|
18447
|
-
globalExpect(
|
|
18447
|
+
globalExpect(commonEncodingUtils.bytesToHexPrefixed(bytes32)).toBe(bytes32Hex);
|
|
18448
18448
|
});
|
|
18449
18449
|
it("throws error for muxed address (M...) - not 32 bytes", () => {
|
|
18450
18450
|
const stellarAddress = validTestAddresses.muxed;
|
|
@@ -18473,10 +18473,10 @@ describe("addressParser - Stellar", () => {
|
|
|
18473
18473
|
const contractHex = parser.nativeToBytes32Hex(validTestAddresses.contract);
|
|
18474
18474
|
const poolHex = parser.nativeToBytes32Hex(validTestAddresses.liquidityPool);
|
|
18475
18475
|
const balanceHex = parser.nativeToBytes32Hex(validTestAddresses.claimableBalance);
|
|
18476
|
-
globalExpect(
|
|
18477
|
-
globalExpect(
|
|
18478
|
-
globalExpect(
|
|
18479
|
-
globalExpect(
|
|
18476
|
+
globalExpect(commonEncodingUtils.bytesToHexPrefixed(accountBytes)).toBe(accountHex);
|
|
18477
|
+
globalExpect(commonEncodingUtils.bytesToHexPrefixed(contractBytes)).toBe(contractHex);
|
|
18478
|
+
globalExpect(commonEncodingUtils.bytesToHexPrefixed(poolBytes)).toBe(poolHex);
|
|
18479
|
+
globalExpect(commonEncodingUtils.bytesToHexPrefixed(balanceBytes)).toBe(balanceHex);
|
|
18480
18480
|
});
|
|
18481
18481
|
it("handles ChainNativeAddress objects for bytes32 operations", () => {
|
|
18482
18482
|
const nativeObj = {
|