@layerzerolabs/address-utils-ton 1.2.31 → 1.2.32
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 +2 -3
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Address } from '@ton/core';
|
|
2
|
-
import { bytesToHex, trim0x, hexToBigInt, isBase58, isHexString, bytesToBigInt, base58ToBytes, bytesToHexPrefixed, hexToBytes } from '@layerzerolabs/common-encoding-utils';
|
|
3
|
-
import { bigintToSizedBuffer } from '@layerzerolabs/ton-sdk-tools';
|
|
2
|
+
import { bytesToHex, trim0x, hexToBigInt, isBase58, isHexString, bytesToBigInt, base58ToBytes, bytesToHexPrefixed, hexToBytes, bigIntToBytes } from '@layerzerolabs/common-encoding-utils';
|
|
4
3
|
|
|
5
4
|
var __defProp = Object.defineProperty;
|
|
6
5
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
@@ -14,7 +13,7 @@ var to32ByteBuffer = /* @__PURE__ */ __name((value, maxIntermediateBufferSize =
|
|
|
14
13
|
if (value instanceof Uint8Array) {
|
|
15
14
|
value = bytesToBigInt(value);
|
|
16
15
|
}
|
|
17
|
-
const bf =
|
|
16
|
+
const bf = Buffer.from(bigIntToBytes(BigInt(value), maxIntermediateBufferSize));
|
|
18
17
|
return bf.subarray(-32);
|
|
19
18
|
}, "to32ByteBuffer");
|
|
20
19
|
var bigintToAddress = /* @__PURE__ */ __name((value) => {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":["to32ByteBuffer","value","maxIntermediateBufferSize","isHexString","Error","bytesToBigInt","hexToBytes","Uint8Array","bf","
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"names":["to32ByteBuffer","value","maxIntermediateBufferSize","isHexString","Error","bytesToBigInt","hexToBytes","Uint8Array","bf","Buffer","from","bigIntToBytes","BigInt","subarray","bigintToAddress","buf","Address","parse","bytesToHex","parseTonAddress","address","trim0x","startsWith","hexToBigInt","_isBase58","isBase58","_isHex","base58ToBytes","err","console","error","message","_addressToNotPaddedHex","bytesToHexPrefixed","hash","addressToHex","addressToBigInt","compareAddresses","addressA","addressB","equals","numberOfLeadingZeroBitsInAddress","toString","length"],"mappings":";;;;;AAkBA,IAAMA,cAAAA,mBAAiB,MAAA,CAAA,CACnBC,KAAAA,EACAC,yBAAAA,GAA4B,EAAA,KAAE;AAE9B,EAAA,IAAI,OAAOD,UAAU,QAAA,EAAU;AAC3B,IAAA,IAAI,CAACE,WAAAA,CAAYF,KAAAA,CAAAA,EAAQ;AACrB,MAAA,MAAM,IAAIG,MAAM,8BAAA,CAAA;AACpB,IAAA;AACAH,IAAAA,KAAAA,GAAQI,aAAAA,CAAcC,UAAAA,CAAWL,KAAAA,CAAAA,CAAAA;AACrC,EAAA;AACA,EAAA,IAAIA,iBAAiBM,UAAAA,EAAY;AAC7BN,IAAAA,KAAAA,GAAQI,cAAcJ,KAAAA,CAAAA;AAC1B,EAAA;AACA,EAAA,MAAMO,EAAAA,GAAKC,OAAOC,IAAAA,CAAKC,aAAAA,CAAcC,OAAOX,KAAAA,CAAAA,EAAQC,yBAAAA,CAAAA,CAAAA;AAEpD,EAAA,OAAOM,EAAAA,CAAGK,SAAS,GAAC,CAAA;AACxB,CAAA,EAhBuB,gBAAA,CAAA;AAkBhB,IAAMC,eAAAA,2BAAmBb,KAAAA,KAAAA;AAC5B,EAAA,MAAMc,GAAAA,GAAMf,eAAeC,KAAAA,CAAAA;AAC3B,EAAA,OAAOe,QAAQC,KAAAA,CAAM,CAAA,EAAA,EAAKC,UAAAA,CAAWH,GAAAA,CAAAA,CAAAA,CAAM,CAAA;AAC/C,CAAA,EAH+B,iBAAA;AAKxB,IAAMI,eAAAA,2BAAmBC,OAAAA,KAAAA;AAC5B,EAAA,IAAIA,mBAAmBJ,OAAAA,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KAC3B,CAAA;AACA,IAAA,MAAMA,GAAAA;AACV,EAAA;AACJ,CAAA,EAhD+B,iBAAA;AAkD/B,IAAMI,sBAAAA,2BAA0BZ,OAAAA,KAAAA;AAC5B,EAAA,OAAOa,kBAAAA,CAAmBd,eAAAA,CAAgBC,OAAAA,CAAAA,CAASc,IAAI,CAAA;AAC3D,CAAA,EAF+B,wBAAA,CAAA;AAIxB,IAAMC,YAAAA,2BAAgBf,OAAAA,KAAAA;AACzB,EAAA,OAAOa,kBAAAA,CAAmBjC,cAAAA,CAAegC,sBAAAA,CAAuBZ,OAAAA,CAAAA,CAAAA,CAAAA;AACpE,CAAA,EAF4B,cAAA;AAIrB,IAAMgB,eAAAA,2BAAmBhB,OAAAA,KAAAA;AAC5B,EAAA,OAAOR,MAAAA,CAAOoB,sBAAAA,CAAuBZ,OAAAA,CAAAA,CAAAA;AACzC,CAAA,EAF+B,iBAAA;AAIxB,IAAMiB,gBAAAA,mBAAmB,MAAA,CAAA,CAACC,QAAAA,EAA2BC,QAAAA,KAAAA;AACxD,EAAA,OAAOpB,gBAAgBmB,QAAAA,CAAAA,CAAUE,MAAAA,CAAOrB,eAAAA,CAAgBoB,QAAAA,CAAAA,CAAAA;AAC5D,CAAA,EAFgC,kBAAA;AAQzB,IAAME,gCAAAA,2BAAoCrB,OAAAA,KAAAA;AAC7C,EAAA,OAAO,KAAK,CAAA,GAAIgB,eAAAA,CAAgBhB,OAAAA,CAAAA,CAASsB,QAAAA,CAAS,CAAA,CAAA,CAAGC,MAAAA;AACzD,CAAA,EAFgD,kCAAA","file":"index.js","sourcesContent":["import { Address } from '@ton/core';\n\nimport type { HexString } from '@layerzerolabs/common-chain-model';\nimport {\n base58ToBytes,\n bigIntToBytes,\n bytesToBigInt,\n bytesToHex,\n bytesToHexPrefixed,\n hexToBigInt,\n hexToBytes,\n isBase58,\n isHexString,\n trim0x,\n} from '@layerzerolabs/common-encoding-utils';\n\nexport type AddressTypeLike = Address | string | bigint;\n\nconst to32ByteBuffer = (\n value: bigint | number | string | Uint8Array,\n maxIntermediateBufferSize = 66,\n): Buffer => {\n if (typeof value === 'string') {\n if (!isHexString(value)) {\n throw new Error('only hex string is supported');\n }\n value = bytesToBigInt(hexToBytes(value));\n }\n if (value instanceof Uint8Array) {\n value = bytesToBigInt(value);\n }\n const bf = Buffer.from(bigIntToBytes(BigInt(value), maxIntermediateBufferSize));\n // trim from the left, keep the right 32 bytes\n return bf.subarray(-32);\n};\n\nexport const bigintToAddress = (value: bigint): Address => {\n const buf = to32ByteBuffer(value);\n return Address.parse(`0:${bytesToHex(buf)}`);\n};\n\nexport const parseTonAddress = (address: AddressTypeLike): Address => {\n if (address instanceof Address) {\n return address;\n }\n\n try {\n if (typeof address === 'bigint' || typeof address === 'number') {\n return bigintToAddress(BigInt(address));\n }\n\n // An empty body ('' or '0x') is not a valid TON address; the hex/bigint helpers below would\n // otherwise decode it to the zero address, so reject it explicitly.\n if (trim0x(address) === '') {\n throw new Error('cannot parse an empty string as a TON address');\n }\n\n if (address.startsWith('0x')) {\n // If it's a hex address format it to ton format\n return bigintToAddress(hexToBigInt(address));\n }\n\n try {\n return Address.parse(address);\n } catch {\n //at this point, our address is either hex without a '0x', or base58\n const _isBase58 = isBase58(address);\n const _isHex = isHexString(address);\n\n //this includes the case where the address is both base58 and hex\n //but nearly every address generated this way is hex (only 1/(~5.5e12) are b58)\n if (_isHex) {\n return bigintToAddress(hexToBigInt(address));\n }\n\n if (_isBase58) {\n return bigintToAddress(bytesToBigInt(base58ToBytes(address)));\n }\n\n //this is the case where the address is invalid in any encoding\n throw new Error(`The address ${address} cannot be decoded as TON, hex, or base58`);\n }\n } catch (err: any) {\n console.error('Error parsing address', {\n address,\n error: err?.message ?? err,\n });\n throw err;\n }\n};\n\nconst _addressToNotPaddedHex = (address: AddressTypeLike) => {\n return bytesToHexPrefixed(parseTonAddress(address).hash);\n};\n\nexport const addressToHex = (address: AddressTypeLike): HexString => {\n return bytesToHexPrefixed(to32ByteBuffer(_addressToNotPaddedHex(address)));\n};\n\nexport const addressToBigInt = (address: AddressTypeLike) => {\n return BigInt(_addressToNotPaddedHex(address));\n};\n\nexport const compareAddresses = (addressA: AddressTypeLike, addressB: AddressTypeLike) => {\n return parseTonAddress(addressA).equals(parseTonAddress(addressB));\n};\n\n/**\n * Since toString(2) does not include leading zeros, we can calculate the leading zeros by subtracting\n * the total length of address in binary from the total length of addresses in TON in bits (32 bytes * 8)\n */\nexport const numberOfLeadingZeroBitsInAddress = (address: AddressTypeLike) => {\n return 32 * 8 - addressToBigInt(address).toString(2).length;\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@layerzerolabs/address-utils-ton",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.32",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -16,16 +16,15 @@
|
|
|
16
16
|
"dist/**/*"
|
|
17
17
|
],
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@layerzerolabs/ton-sdk-tools": "3.0.168",
|
|
20
19
|
"@ton/core": "^0.59.0",
|
|
21
|
-
"@layerzerolabs/common-
|
|
22
|
-
"@layerzerolabs/common-
|
|
20
|
+
"@layerzerolabs/common-encoding-utils": "1.2.32",
|
|
21
|
+
"@layerzerolabs/common-chain-model": "1.2.32"
|
|
23
22
|
},
|
|
24
23
|
"devDependencies": {
|
|
25
24
|
"tsup": "^8.4.0",
|
|
26
25
|
"vitest": "^4.1.10",
|
|
27
|
-
"@layerzerolabs/tsup-configuration": "1.2.
|
|
28
|
-
"@layerzerolabs/typescript-configuration": "1.2.
|
|
26
|
+
"@layerzerolabs/tsup-configuration": "1.2.32",
|
|
27
|
+
"@layerzerolabs/typescript-configuration": "1.2.32"
|
|
29
28
|
},
|
|
30
29
|
"publishConfig": {
|
|
31
30
|
"access": "public",
|
|
@@ -35,6 +34,7 @@
|
|
|
35
34
|
"targets": [
|
|
36
35
|
"console-pen-test",
|
|
37
36
|
"gasolina-audit",
|
|
37
|
+
"lz-labs-sidecar",
|
|
38
38
|
"onesig-client"
|
|
39
39
|
]
|
|
40
40
|
},
|