@layerzerolabs/common-encoding-utils 0.2.90 → 0.2.91
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/package.json +6 -6
- package/dist/DSXMRHUH.cjs +0 -222
- package/dist/DSXMRHUH.cjs.map +0 -1
- package/dist/IDXW633A.cjs +0 -32
- package/dist/IDXW633A.cjs.map +0 -1
- package/dist/YJF4D23A.cjs +0 -8
- package/dist/YJF4D23A.cjs.map +0 -1
- package/dist/byte-codec.cjs +0 -13
- package/dist/byte-codec.cjs.map +0 -1
- package/dist/index.cjs +0 -178
- package/dist/index.cjs.map +0 -1
- package/dist/uuid.cjs +0 -13
- package/dist/uuid.cjs.map +0 -1
package/package.json
CHANGED
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@layerzerolabs/common-encoding-utils",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.91",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"exports": {
|
|
8
8
|
"types": "./dist/index.d.ts",
|
|
9
|
-
"require": "./dist/index.cjs",
|
|
10
9
|
"import": "./dist/index.js",
|
|
11
|
-
"default": "./dist/index.
|
|
10
|
+
"default": "./dist/index.js"
|
|
12
11
|
},
|
|
13
|
-
"main": "./dist/index.
|
|
12
|
+
"main": "./dist/index.js",
|
|
14
13
|
"module": "./dist/index.js",
|
|
15
14
|
"types": "./dist/index.d.ts",
|
|
16
15
|
"files": [
|
|
@@ -19,8 +18,8 @@
|
|
|
19
18
|
"devDependencies": {
|
|
20
19
|
"tsup": "^8.4.0",
|
|
21
20
|
"vitest": "^3.2.3",
|
|
22
|
-
"@layerzerolabs/tsup-configuration": "0.2.
|
|
23
|
-
"@layerzerolabs/typescript-configuration": "0.2.
|
|
21
|
+
"@layerzerolabs/tsup-configuration": "0.2.91",
|
|
22
|
+
"@layerzerolabs/typescript-configuration": "0.2.91"
|
|
24
23
|
},
|
|
25
24
|
"publishConfig": {
|
|
26
25
|
"access": "public",
|
|
@@ -28,6 +27,7 @@
|
|
|
28
27
|
},
|
|
29
28
|
"externalRepoConfig": {
|
|
30
29
|
"targets": [
|
|
30
|
+
"console-pen-test",
|
|
31
31
|
"onesig-client"
|
|
32
32
|
]
|
|
33
33
|
},
|
package/dist/DSXMRHUH.cjs
DELETED
|
@@ -1,222 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var YJF4D23A_cjs = require('./YJF4D23A.cjs');
|
|
4
|
-
|
|
5
|
-
// src/byte-codec.ts
|
|
6
|
-
function uMax(bits) {
|
|
7
|
-
if (!Number.isInteger(bits) || bits < 0) {
|
|
8
|
-
throw new RangeError(`ByteCodec: invalid bit width: ${bits}`);
|
|
9
|
-
}
|
|
10
|
-
return bits === 0 ? 0n : (1n << BigInt(bits)) - 1n;
|
|
11
|
-
}
|
|
12
|
-
YJF4D23A_cjs.__name(uMax, "uMax");
|
|
13
|
-
var ByteCodec = class _ByteCodec {
|
|
14
|
-
static {
|
|
15
|
-
YJF4D23A_cjs.__name(this, "ByteCodec");
|
|
16
|
-
}
|
|
17
|
-
// Start with a small-ish initial capacity to avoid frequent reallocations for
|
|
18
|
-
// common short payloads (e.g. function selector + a few fixed-width fields),
|
|
19
|
-
// while still staying tiny in memory terms. Buffer grows by doubling as needed.
|
|
20
|
-
#buf = new ArrayBuffer(128);
|
|
21
|
-
#view = new DataView(this.#buf);
|
|
22
|
-
#cursor = 0;
|
|
23
|
-
static #ZERO = 0n;
|
|
24
|
-
static #U8_MAX = uMax(8);
|
|
25
|
-
static #U16_MAX = uMax(16);
|
|
26
|
-
static #U32_MAX = uMax(32);
|
|
27
|
-
static #U64_MAX = uMax(64);
|
|
28
|
-
static #U128_MAX = uMax(128);
|
|
29
|
-
static #U256_MAX = uMax(256);
|
|
30
|
-
static #outOfRange(targetLength, value) {
|
|
31
|
-
return new RangeError(`ByteCodec: value out of range for u${targetLength * 8}: ${value}`);
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Read helpers (big-endian). These are intentionally small/low-level so other
|
|
35
|
-
* packages can share a single implementation for parsing encoded payloads.
|
|
36
|
-
*/
|
|
37
|
-
static readU16be(buf, offset) {
|
|
38
|
-
const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
39
|
-
return view.getUint16(offset, false);
|
|
40
|
-
}
|
|
41
|
-
static readU8(buf, offset) {
|
|
42
|
-
const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
43
|
-
return view.getUint8(offset);
|
|
44
|
-
}
|
|
45
|
-
static readU32be(buf, offset) {
|
|
46
|
-
const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
47
|
-
return view.getUint32(offset, false);
|
|
48
|
-
}
|
|
49
|
-
static readU128be(buf, offset) {
|
|
50
|
-
return _ByteCodec.readUNbe(buf, offset, 16);
|
|
51
|
-
}
|
|
52
|
-
static readUNbe(buf, offset, length) {
|
|
53
|
-
const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
54
|
-
let out = 0n;
|
|
55
|
-
const end = offset + length;
|
|
56
|
-
let cursor = offset;
|
|
57
|
-
while (cursor + 8 <= end) {
|
|
58
|
-
out = out << 64n | view.getBigUint64(cursor, false);
|
|
59
|
-
cursor += 8;
|
|
60
|
-
}
|
|
61
|
-
while (cursor < end) {
|
|
62
|
-
out = out << 8n | BigInt(view.getUint8(cursor));
|
|
63
|
-
cursor += 1;
|
|
64
|
-
}
|
|
65
|
-
return out;
|
|
66
|
-
}
|
|
67
|
-
static readBytes32(buf, offset) {
|
|
68
|
-
if (offset + 32 > buf.length) throw new RangeError(`ByteCodec: out of bounds at ${offset}`);
|
|
69
|
-
return buf.slice(offset, offset + 32);
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Left-pad `bytes` to `targetLength` using `padByte` (default 0x00).
|
|
73
|
-
*
|
|
74
|
-
* Commonly used to mimic Solidity's `bytes32(bytesN)`-style left zero padding.
|
|
75
|
-
*/
|
|
76
|
-
static leftPad(bytes, targetLength, padByte = 0) {
|
|
77
|
-
if (!Number.isInteger(targetLength) || targetLength < 0) {
|
|
78
|
-
throw new RangeError(`ByteCodec: invalid length: target=${targetLength}`);
|
|
79
|
-
}
|
|
80
|
-
if (!Number.isInteger(padByte) || padByte < 0 || padByte > 255) {
|
|
81
|
-
throw new RangeError(`ByteCodec: invalid pad byte: ${padByte}`);
|
|
82
|
-
}
|
|
83
|
-
if (bytes.length > targetLength) {
|
|
84
|
-
throw new RangeError(`ByteCodec: bytes length ${bytes.length} exceeds target ${targetLength}`);
|
|
85
|
-
}
|
|
86
|
-
const out = new Uint8Array(targetLength);
|
|
87
|
-
if (padByte !== 0) out.fill(padByte);
|
|
88
|
-
out.set(bytes, targetLength - bytes.length);
|
|
89
|
-
return out;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Cast an unsigned big-endian integer in `bytes` into a fixed-width uint (by bytes),
|
|
93
|
-
* reverting on overflow.
|
|
94
|
-
*
|
|
95
|
-
* This mirrors Solidity-style safe casts like `SafeCast.toUint128(uint256)`:
|
|
96
|
-
* - if `bytes.length > targetLength`, the high (bytes.length - targetLength) bytes must be all zero
|
|
97
|
-
* - returns the low `targetLength` bytes as the result
|
|
98
|
-
*
|
|
99
|
-
* Examples:
|
|
100
|
-
* - cast bytes32 -> u128: castUNbe(bytes32, 16)
|
|
101
|
-
* - cast bytesN -> u64: castUNbe(bytesN, 8)
|
|
102
|
-
*/
|
|
103
|
-
static castUNbe(bytes, targetLength) {
|
|
104
|
-
if (!Number.isInteger(targetLength) || targetLength < 0) {
|
|
105
|
-
throw new RangeError(`ByteCodec: invalid length: target=${targetLength}`);
|
|
106
|
-
}
|
|
107
|
-
const len = bytes.length;
|
|
108
|
-
if (len <= targetLength) return _ByteCodec.readUNbe(bytes, 0, len);
|
|
109
|
-
const excess = len - targetLength;
|
|
110
|
-
for (let i = 0; i < excess; i++) {
|
|
111
|
-
if (bytes[i] !== 0) throw _ByteCodec.#outOfRange(targetLength, _ByteCodec.readUNbe(bytes, 0, len));
|
|
112
|
-
}
|
|
113
|
-
return _ByteCodec.readUNbe(bytes, excess, targetLength);
|
|
114
|
-
}
|
|
115
|
-
static castU8be(bytes) {
|
|
116
|
-
return _ByteCodec.castUNbe(bytes, 1);
|
|
117
|
-
}
|
|
118
|
-
static castU16be(bytes) {
|
|
119
|
-
return _ByteCodec.castUNbe(bytes, 2);
|
|
120
|
-
}
|
|
121
|
-
static castU32be(bytes) {
|
|
122
|
-
return _ByteCodec.castUNbe(bytes, 4);
|
|
123
|
-
}
|
|
124
|
-
static castU64be(bytes) {
|
|
125
|
-
return _ByteCodec.castUNbe(bytes, 8);
|
|
126
|
-
}
|
|
127
|
-
static castU128be(bytes) {
|
|
128
|
-
return _ByteCodec.castUNbe(bytes, 16);
|
|
129
|
-
}
|
|
130
|
-
ensureCapacity(additionalBytes) {
|
|
131
|
-
const needed = this.#cursor + additionalBytes;
|
|
132
|
-
if (needed <= this.#buf.byteLength) return;
|
|
133
|
-
let nextCap = this.#buf.byteLength;
|
|
134
|
-
while (nextCap < needed) nextCap *= 2;
|
|
135
|
-
const next = new ArrayBuffer(nextCap);
|
|
136
|
-
new Uint8Array(next).set(new Uint8Array(this.#buf, 0, this.#cursor));
|
|
137
|
-
this.#buf = next;
|
|
138
|
-
this.#view = new DataView(this.#buf);
|
|
139
|
-
}
|
|
140
|
-
bytes(b) {
|
|
141
|
-
this.ensureCapacity(b.length);
|
|
142
|
-
new Uint8Array(this.#buf, this.#cursor, b.length).set(b);
|
|
143
|
-
this.#cursor += b.length;
|
|
144
|
-
return this;
|
|
145
|
-
}
|
|
146
|
-
bytes32(b) {
|
|
147
|
-
return this.bytes(_ByteCodec.leftPad(b, 32));
|
|
148
|
-
}
|
|
149
|
-
bool(b) {
|
|
150
|
-
return this.u8(b ? 1n : _ByteCodec.#ZERO);
|
|
151
|
-
}
|
|
152
|
-
u8(v) {
|
|
153
|
-
if (v < _ByteCodec.#ZERO || v > _ByteCodec.#U8_MAX) throw new RangeError(`ByteCodec: value out of range for u8: ${v}`);
|
|
154
|
-
this.ensureCapacity(1);
|
|
155
|
-
this.#view.setUint8(this.#cursor, Number(v));
|
|
156
|
-
this.#cursor += 1;
|
|
157
|
-
return this;
|
|
158
|
-
}
|
|
159
|
-
u16be(v) {
|
|
160
|
-
if (v < _ByteCodec.#ZERO || v > _ByteCodec.#U16_MAX) throw new RangeError(`ByteCodec: value out of range for u16: ${v}`);
|
|
161
|
-
this.ensureCapacity(2);
|
|
162
|
-
this.#view.setUint16(this.#cursor, Number(v), false);
|
|
163
|
-
this.#cursor += 2;
|
|
164
|
-
return this;
|
|
165
|
-
}
|
|
166
|
-
u32be(v) {
|
|
167
|
-
if (v < _ByteCodec.#ZERO || v > _ByteCodec.#U32_MAX) {
|
|
168
|
-
throw new RangeError(`ByteCodec: value out of range for u32: ${v}`);
|
|
169
|
-
}
|
|
170
|
-
this.ensureCapacity(4);
|
|
171
|
-
this.#view.setUint32(this.#cursor, Number(v), false);
|
|
172
|
-
this.#cursor += 4;
|
|
173
|
-
return this;
|
|
174
|
-
}
|
|
175
|
-
u64be(v) {
|
|
176
|
-
if (v < _ByteCodec.#ZERO || v > _ByteCodec.#U64_MAX) {
|
|
177
|
-
throw new RangeError(`ByteCodec: value out of range for u64: ${v}`);
|
|
178
|
-
}
|
|
179
|
-
this.ensureCapacity(8);
|
|
180
|
-
this.#view.setBigUint64(this.#cursor, v, false);
|
|
181
|
-
this.#cursor += 8;
|
|
182
|
-
return this;
|
|
183
|
-
}
|
|
184
|
-
u128be(v) {
|
|
185
|
-
if (v < _ByteCodec.#ZERO || v > _ByteCodec.#U128_MAX) {
|
|
186
|
-
throw new RangeError(`ByteCodec: value out of range for u128: ${v}`);
|
|
187
|
-
}
|
|
188
|
-
this.ensureCapacity(16);
|
|
189
|
-
const hi = v >> 64n & _ByteCodec.#U64_MAX;
|
|
190
|
-
const lo = v & _ByteCodec.#U64_MAX;
|
|
191
|
-
this.#view.setBigUint64(this.#cursor, hi, false);
|
|
192
|
-
this.#view.setBigUint64(this.#cursor + 8, lo, false);
|
|
193
|
-
this.#cursor += 16;
|
|
194
|
-
return this;
|
|
195
|
-
}
|
|
196
|
-
u256be(v) {
|
|
197
|
-
if (v < _ByteCodec.#ZERO || v > _ByteCodec.#U256_MAX) {
|
|
198
|
-
throw new RangeError(`ByteCodec: value out of range for u256: ${v}`);
|
|
199
|
-
}
|
|
200
|
-
this.ensureCapacity(32);
|
|
201
|
-
const w0 = v >> 192n & _ByteCodec.#U64_MAX;
|
|
202
|
-
const w1 = v >> 128n & _ByteCodec.#U64_MAX;
|
|
203
|
-
const w2 = v >> 64n & _ByteCodec.#U64_MAX;
|
|
204
|
-
const w3 = v & _ByteCodec.#U64_MAX;
|
|
205
|
-
this.#view.setBigUint64(this.#cursor, w0, false);
|
|
206
|
-
this.#view.setBigUint64(this.#cursor + 8, w1, false);
|
|
207
|
-
this.#view.setBigUint64(this.#cursor + 16, w2, false);
|
|
208
|
-
this.#view.setBigUint64(this.#cursor + 24, w3, false);
|
|
209
|
-
this.#cursor += 32;
|
|
210
|
-
return this;
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* Returns a copy of the accumulated bytes (no shared backing buffer).
|
|
214
|
-
*/
|
|
215
|
-
toBytes() {
|
|
216
|
-
return new Uint8Array(this.#buf, 0, this.#cursor).slice();
|
|
217
|
-
}
|
|
218
|
-
};
|
|
219
|
-
|
|
220
|
-
exports.ByteCodec = ByteCodec;
|
|
221
|
-
//# sourceMappingURL=DSXMRHUH.cjs.map
|
|
222
|
-
//# sourceMappingURL=DSXMRHUH.cjs.map
|
package/dist/DSXMRHUH.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/byte-codec.ts"],"names":["uMax","bits","Number","isInteger","RangeError","BigInt","ByteCodec","ArrayBuffer","DataView","targetLength","value","readU16be","buf","offset","view","buffer","byteOffset","byteLength","getUint16","readU8","getUint8","readU32be","getUint32","readU128be","readUNbe","length","out","end","cursor","getBigUint64","readBytes32","slice","leftPad","bytes","padByte","Uint8Array","fill","set","castUNbe","len","excess","i","castU8be","castU16be","castU32be","castU64be","castU128be","ensureCapacity","additionalBytes","needed","nextCap","next","b","bytes32","bool","u8","v","setUint8","u16be","setUint16","u32be","setUint32","u64be","setBigUint64","u128be","hi","lo","u256be","w0","w1","w2","w3","toBytes"],"mappings":";;;;;AAQA,SAASA,KAAKC,IAAAA,EAAY;AACtB,EAAA,IAAI,CAACC,MAAAA,CAAOC,SAAAA,CAAUF,IAAAA,CAAAA,IAASA,OAAO,CAAA,EAAG;AACrC,IAAA,MAAM,IAAIG,UAAAA,CAAW,CAAA,8BAAA,EAAiCH,IAAAA,CAAAA,CAAM,CAAA;AAChE,EAAA;AAEA,EAAA,OAAOA,SAAS,CAAA,GAAI,EAAA,GAAA,CAAM,EAAA,IAAMI,MAAAA,CAAOJ,IAAAA,CAAAA,IAAS,EAAA;AACpD;AANSD,mBAAAA,CAAAA,IAAAA,EAAAA,MAAAA,CAAAA;AASF,IAAMM,SAAAA,GAAN,MAAMA,UAAAA,CAAAA;EAjBb;;;;;;EAqBI,IAAA,GAAO,IAAIC,YAAY,GAAA,CAAA;EACvB,KAAA,GAAQ,IAAIC,QAAAA,CAAS,IAAA,CAAK,IAAI,CAAA;EAC9B,OAAA,GAAU,CAAA;AAEV,EAAA,OAAgB,KAAA,GAAQ,EAAA;EACxB,OAAgB,OAAA,GAAUR,KAAK,CAAA,CAAA;EAC/B,OAAgB,QAAA,GAAWA,KAAK,EAAA,CAAA;EAChC,OAAgB,QAAA,GAAWA,KAAK,EAAA,CAAA;EAChC,OAAgB,QAAA,GAAWA,KAAK,EAAA,CAAA;EAChC,OAAgB,SAAA,GAAYA,KAAK,GAAA,CAAA;EACjC,OAAgB,SAAA,GAAYA,KAAK,GAAA,CAAA;EA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;AAChD,MAAA,MAAM,IAAIF,UAAAA,CAAW,CAAA,wCAAA,EAA2CoD,CAAAA,CAAAA,CAAG,CAAA;AACvE,IAAA;AACA,IAAA,IAAA,CAAKT,eAAe,EAAA,CAAA;AACpB,IAAA,MAAMqB,EAAAA,GAAMZ,CAAAA,IAAK,IAAA,GAAQlD,UAAAA,CAAU,QAAA;AACnC,IAAA,MAAM+D,EAAAA,GAAMb,CAAAA,IAAK,IAAA,GAAQlD,UAAAA,CAAU,QAAA;AACnC,IAAA,MAAMgE,EAAAA,GAAMd,CAAAA,IAAK,GAAA,GAAOlD,UAAAA,CAAU,QAAA;AAClC,IAAA,MAAMiE,EAAAA,GAAKf,IAAIlD,UAAAA,CAAU,QAAA;AACzB,IAAA,IAAA,CAAK,KAAA,CAAMyD,YAAAA,CAAa,IAAA,CAAK,OAAA,EAASK,IAAI,KAAA,CAAA;AAC1C,IAAA,IAAA,CAAK,MAAML,YAAAA,CAAa,IAAA,CAAK,OAAA,GAAU,CAAA,EAAGM,IAAI,KAAA,CAAA;AAC9C,IAAA,IAAA,CAAK,MAAMN,YAAAA,CAAa,IAAA,CAAK,OAAA,GAAU,EAAA,EAAIO,IAAI,KAAA,CAAA;AAC/C,IAAA,IAAA,CAAK,MAAMP,YAAAA,CAAa,IAAA,CAAK,OAAA,GAAU,EAAA,EAAIQ,IAAI,KAAA,CAAA;AAC/C,IAAA,IAAA,CAAK,OAAA,IAAW,EAAA;AAChB,IAAA,OAAO,IAAA;AACX,EAAA;;;;EAIAC,OAAAA,GAAsB;AAClB,IAAA,OAAO,IAAIrC,WAAW,IAAA,CAAK,IAAA,EAAM,GAAG,IAAA,CAAK,OAAO,EAAEJ,KAAAA,EAAK;AAC3D,EAAA;AACJ","file":"DSXMRHUH.cjs","sourcesContent":["/**\n * Growable byte codec backed by `ArrayBuffer` + `DataView`.\n *\n * Low-level building block for constructing byte payloads deterministically.\n * Higher-level concerns (e.g. hashing, ABI encoding, function signatures) should\n * live in wrappers/subclasses.\n */\n\nfunction uMax(bits: number): bigint {\n if (!Number.isInteger(bits) || bits < 0) {\n throw new RangeError(`ByteCodec: invalid bit width: ${bits}`);\n }\n // (2^bits) - 1, as bigint\n return bits === 0 ? 0n : (1n << BigInt(bits)) - 1n;\n}\n\n// TODO: add tests for this class — currently has zero test coverage\nexport class ByteCodec {\n // Start with a small-ish initial capacity to avoid frequent reallocations for\n // common short payloads (e.g. function selector + a few fixed-width fields),\n // while still staying tiny in memory terms. Buffer grows by doubling as needed.\n #buf = new ArrayBuffer(128);\n #view = new DataView(this.#buf);\n #cursor = 0;\n\n static readonly #ZERO = 0n;\n static readonly #U8_MAX = uMax(8);\n static readonly #U16_MAX = uMax(16);\n static readonly #U32_MAX = uMax(32);\n static readonly #U64_MAX = uMax(64);\n static readonly #U128_MAX = uMax(128);\n static readonly #U256_MAX = uMax(256);\n\n static #outOfRange(targetLength: number, value: bigint): RangeError {\n return new RangeError(`ByteCodec: value out of range for u${targetLength * 8}: ${value}`);\n }\n\n /**\n * Read helpers (big-endian). These are intentionally small/low-level so other\n * packages can share a single implementation for parsing encoded payloads.\n */\n static readU16be(buf: Uint8Array, offset: number): number {\n const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);\n return view.getUint16(offset, false);\n }\n\n static readU8(buf: Uint8Array, offset: number): number {\n const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);\n return view.getUint8(offset);\n }\n\n static readU32be(buf: Uint8Array, offset: number): number {\n const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);\n return view.getUint32(offset, false);\n }\n\n static readU128be(buf: Uint8Array, offset: number): bigint {\n return ByteCodec.readUNbe(buf, offset, 16);\n }\n\n static readUNbe(buf: Uint8Array, offset: number, length: number): bigint {\n const view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);\n\n let out = 0n;\n const end = offset + length;\n\n // Fast path: read 8 bytes at a time\n let cursor = offset;\n while (cursor + 8 <= end) {\n out = (out << 64n) | view.getBigUint64(cursor, false);\n cursor += 8;\n }\n\n // Tail: 0..7 bytes\n while (cursor < end) {\n out = (out << 8n) | BigInt(view.getUint8(cursor));\n cursor += 1;\n }\n\n return out;\n }\n\n static readBytes32(buf: Uint8Array, offset: number): Uint8Array {\n if (offset + 32 > buf.length) throw new RangeError(`ByteCodec: out of bounds at ${offset}`);\n return buf.slice(offset, offset + 32);\n }\n\n /**\n * Left-pad `bytes` to `targetLength` using `padByte` (default 0x00).\n *\n * Commonly used to mimic Solidity's `bytes32(bytesN)`-style left zero padding.\n */\n static leftPad(bytes: Uint8Array, targetLength: number, padByte = 0): Uint8Array {\n if (!Number.isInteger(targetLength) || targetLength < 0) {\n throw new RangeError(`ByteCodec: invalid length: target=${targetLength}`);\n }\n if (!Number.isInteger(padByte) || padByte < 0 || padByte > 255) {\n throw new RangeError(`ByteCodec: invalid pad byte: ${padByte}`);\n }\n if (bytes.length > targetLength) {\n throw new RangeError(\n `ByteCodec: bytes length ${bytes.length} exceeds target ${targetLength}`,\n );\n }\n\n const out = new Uint8Array(targetLength);\n if (padByte !== 0) out.fill(padByte);\n out.set(bytes, targetLength - bytes.length);\n return out;\n }\n\n /**\n * Cast an unsigned big-endian integer in `bytes` into a fixed-width uint (by bytes),\n * reverting on overflow.\n *\n * This mirrors Solidity-style safe casts like `SafeCast.toUint128(uint256)`:\n * - if `bytes.length > targetLength`, the high (bytes.length - targetLength) bytes must be all zero\n * - returns the low `targetLength` bytes as the result\n *\n * Examples:\n * - cast bytes32 -> u128: castUNbe(bytes32, 16)\n * - cast bytesN -> u64: castUNbe(bytesN, 8)\n */\n static castUNbe(bytes: Uint8Array, targetLength: number): bigint {\n if (!Number.isInteger(targetLength) || targetLength < 0) {\n throw new RangeError(`ByteCodec: invalid length: target=${targetLength}`);\n }\n\n const len = bytes.length;\n if (len <= targetLength) return ByteCodec.readUNbe(bytes, 0, len);\n\n // Overflow check: any excess high bytes must be 0x00.\n const excess = len - targetLength;\n for (let i = 0; i < excess; i++) {\n if (bytes[i] !== 0)\n throw ByteCodec.#outOfRange(targetLength, ByteCodec.readUNbe(bytes, 0, len));\n }\n\n return ByteCodec.readUNbe(bytes, excess, targetLength);\n }\n\n static castU8be(bytes: Uint8Array): bigint {\n return ByteCodec.castUNbe(bytes, 1);\n }\n\n static castU16be(bytes: Uint8Array): bigint {\n return ByteCodec.castUNbe(bytes, 2);\n }\n\n static castU32be(bytes: Uint8Array): bigint {\n return ByteCodec.castUNbe(bytes, 4);\n }\n\n static castU64be(bytes: Uint8Array): bigint {\n return ByteCodec.castUNbe(bytes, 8);\n }\n\n static castU128be(bytes: Uint8Array): bigint {\n return ByteCodec.castUNbe(bytes, 16);\n }\n\n protected ensureCapacity(additionalBytes: number): void {\n const needed = this.#cursor + additionalBytes;\n if (needed <= this.#buf.byteLength) return;\n\n let nextCap = this.#buf.byteLength;\n while (nextCap < needed) nextCap *= 2;\n\n // Grow by allocating a new ArrayBuffer and copying the written prefix\n // [0..cursor) into it. We then swap the backing buffer+view.\n const next = new ArrayBuffer(nextCap);\n new Uint8Array(next).set(new Uint8Array(this.#buf, 0, this.#cursor));\n this.#buf = next;\n this.#view = new DataView(this.#buf);\n }\n\n bytes(b: Uint8Array): this {\n this.ensureCapacity(b.length);\n new Uint8Array(this.#buf, this.#cursor, b.length).set(b);\n this.#cursor += b.length;\n return this;\n }\n\n bytes32(b: Uint8Array): this {\n return this.bytes(ByteCodec.leftPad(b, 32));\n }\n\n bool(b: boolean): this {\n return this.u8(b ? 1n : ByteCodec.#ZERO);\n }\n\n u8(v: bigint): this {\n if (v < ByteCodec.#ZERO || v > ByteCodec.#U8_MAX)\n throw new RangeError(`ByteCodec: value out of range for u8: ${v}`);\n this.ensureCapacity(1);\n this.#view.setUint8(this.#cursor, Number(v));\n this.#cursor += 1;\n return this;\n }\n\n u16be(v: bigint): this {\n if (v < ByteCodec.#ZERO || v > ByteCodec.#U16_MAX)\n throw new RangeError(`ByteCodec: value out of range for u16: ${v}`);\n this.ensureCapacity(2);\n this.#view.setUint16(this.#cursor, Number(v), false);\n this.#cursor += 2;\n return this;\n }\n\n u32be(v: bigint): this {\n if (v < ByteCodec.#ZERO || v > ByteCodec.#U32_MAX) {\n throw new RangeError(`ByteCodec: value out of range for u32: ${v}`);\n }\n this.ensureCapacity(4);\n this.#view.setUint32(this.#cursor, Number(v), false);\n this.#cursor += 4;\n return this;\n }\n\n u64be(v: bigint): this {\n if (v < ByteCodec.#ZERO || v > ByteCodec.#U64_MAX) {\n throw new RangeError(`ByteCodec: value out of range for u64: ${v}`);\n }\n this.ensureCapacity(8);\n this.#view.setBigUint64(this.#cursor, v, false);\n this.#cursor += 8;\n return this;\n }\n\n u128be(v: bigint): this {\n if (v < ByteCodec.#ZERO || v > ByteCodec.#U128_MAX) {\n throw new RangeError(`ByteCodec: value out of range for u128: ${v}`);\n }\n this.ensureCapacity(16);\n const hi = (v >> 64n) & ByteCodec.#U64_MAX;\n const lo = v & ByteCodec.#U64_MAX;\n this.#view.setBigUint64(this.#cursor, hi, false);\n this.#view.setBigUint64(this.#cursor + 8, lo, false);\n this.#cursor += 16;\n return this;\n }\n\n u256be(v: bigint): this {\n if (v < ByteCodec.#ZERO || v > ByteCodec.#U256_MAX) {\n throw new RangeError(`ByteCodec: value out of range for u256: ${v}`);\n }\n this.ensureCapacity(32);\n const w0 = (v >> 192n) & ByteCodec.#U64_MAX;\n const w1 = (v >> 128n) & ByteCodec.#U64_MAX;\n const w2 = (v >> 64n) & ByteCodec.#U64_MAX;\n const w3 = v & ByteCodec.#U64_MAX;\n this.#view.setBigUint64(this.#cursor, w0, false);\n this.#view.setBigUint64(this.#cursor + 8, w1, false);\n this.#view.setBigUint64(this.#cursor + 16, w2, false);\n this.#view.setBigUint64(this.#cursor + 24, w3, false);\n this.#cursor += 32;\n return this;\n }\n /**\n * Returns a copy of the accumulated bytes (no shared backing buffer).\n */\n toBytes(): Uint8Array {\n return new Uint8Array(this.#buf, 0, this.#cursor).slice();\n }\n}\n"]}
|
package/dist/IDXW633A.cjs
DELETED
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var YJF4D23A_cjs = require('./YJF4D23A.cjs');
|
|
4
|
-
|
|
5
|
-
// src/uuid.ts
|
|
6
|
-
var UUID_BYTE_LENGTH = 16;
|
|
7
|
-
var prepareUuidBytes = /* @__PURE__ */ YJF4D23A_cjs.__name((bytes) => {
|
|
8
|
-
if (bytes.length === 0) {
|
|
9
|
-
throw new Error("uuid bytes must not be empty");
|
|
10
|
-
}
|
|
11
|
-
if (bytes.length === UUID_BYTE_LENGTH) {
|
|
12
|
-
return new Uint8Array(bytes);
|
|
13
|
-
}
|
|
14
|
-
if (bytes.length > UUID_BYTE_LENGTH) {
|
|
15
|
-
return Uint8Array.from(bytes.subarray(0, UUID_BYTE_LENGTH));
|
|
16
|
-
}
|
|
17
|
-
const padded = new Uint8Array(UUID_BYTE_LENGTH);
|
|
18
|
-
padded.set(bytes);
|
|
19
|
-
return padded;
|
|
20
|
-
}, "prepareUuidBytes");
|
|
21
|
-
var formatUuidFrom16Bytes = /* @__PURE__ */ YJF4D23A_cjs.__name((working, version) => {
|
|
22
|
-
const versionBits = version === 4 ? 64 : 80;
|
|
23
|
-
working[6] = working[6] & 15 | versionBits;
|
|
24
|
-
working[8] = working[8] & 63 | 128;
|
|
25
|
-
const hex = Array.from(working, (b) => b.toString(16).padStart(2, "0"));
|
|
26
|
-
return hex.slice(0, 4).join("") + "-" + hex.slice(4, 6).join("") + "-" + hex.slice(6, 8).join("") + "-" + hex.slice(8, 10).join("") + "-" + hex.slice(10, 16).join("");
|
|
27
|
-
}, "formatUuidFrom16Bytes");
|
|
28
|
-
var uuidFromBytes = /* @__PURE__ */ YJF4D23A_cjs.__name((bytes, version = 4) => formatUuidFrom16Bytes(prepareUuidBytes(bytes), version), "uuidFromBytes");
|
|
29
|
-
|
|
30
|
-
exports.uuidFromBytes = uuidFromBytes;
|
|
31
|
-
//# sourceMappingURL=IDXW633A.cjs.map
|
|
32
|
-
//# sourceMappingURL=IDXW633A.cjs.map
|
package/dist/IDXW633A.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/uuid.ts"],"names":["UUID_BYTE_LENGTH","prepareUuidBytes","bytes","length","Error","Uint8Array","from","subarray","padded","set","formatUuidFrom16Bytes","__name","working","version","versionBits","hex","Array","b","toString","padStart","slice","join","uuidFromBytes"],"mappings":";;;;;AAAA,IAAMA,gBAAAA,GAAmB,EAAA;AAIzB,IAAMC,gBAAAA,wCAAoBC,KAAAA,KAAAA;AACtB,EAAA,IAAIA,KAAAA,CAAMC,WAAW,CAAA,EAAG;AACpB,IAAA,MAAM,IAAIC,MAAM,8BAAA,CAAA;AACpB,EAAA;AAEA,EAAA,IAAIF,KAAAA,CAAMC,WAAWH,gBAAAA,EAAkB;AACnC,IAAA,OAAO,IAAIK,WAAWH,KAAAA,CAAAA;AAC1B,EAAA;AAEA,EAAA,IAAIA,KAAAA,CAAMC,SAASH,gBAAAA,EAAkB;AACjC,IAAA,OAAOK,WAAWC,IAAAA,CAAKJ,KAAAA,CAAMK,QAAAA,CAAS,CAAA,EAAGP,gBAAAA,CAAAA,CAAAA;AAC7C,EAAA;AAEA,EAAA,MAAMQ,MAAAA,GAAS,IAAIH,UAAAA,CAAWL,gBAAAA,CAAAA;AAC9BQ,EAAAA,MAAAA,CAAOC,IAAIP,KAAAA,CAAAA;AACX,EAAA,OAAOM,MAAAA;AACX,CAAA,EAhByB,kBAAA,CAAA;AAkBzB,IAAME,qBAAAA,mBAAwBC,mBAAA,CAAA,CAACC,OAAAA,EAAqBC,OAAAA,KAAAA;AAChD,EAAA,MAAMC,WAAAA,GAAcD,OAAAA,KAAY,CAAA,GAAI,EAAA,GAAO,EAAA;AAE3CD,EAAAA,OAAAA,CAAQ,CAAA,CAAA,GAAMA,OAAAA,CAAQ,CAAA,IAAM,EAAA,GAAQE,WAAAA;AACpCF,EAAAA,OAAAA,CAAQ,CAAA,CAAA,GAAMA,OAAAA,CAAQ,CAAA,IAAM,EAAA,GAAQ,GAAA;AAEpC,EAAA,MAAMG,GAAAA,GAAMC,KAAAA,CAAMV,IAAAA,CAAKM,OAAAA,EAAS,CAACK,CAAAA,KAAMA,CAAAA,CAAEC,QAAAA,CAAS,EAAA,CAAA,CAAIC,QAAAA,CAAS,CAAA,EAAG,GAAA,CAAA,CAAA;AAClE,EAAA,OACIJ,IAAIK,KAAAA,CAAM,CAAA,EAAG,CAAA,CAAA,CAAGC,IAAAA,CAAK,EAAA,CAAA,GACrB,GAAA,GACAN,IAAIK,KAAAA,CAAM,CAAA,EAAG,CAAA,CAAA,CAAGC,IAAAA,CAAK,EAAA,CAAA,GACrB,GAAA,GACAN,IAAIK,KAAAA,CAAM,CAAA,EAAG,CAAA,CAAA,CAAGC,KAAK,EAAA,CAAA,GACrB,MACAN,GAAAA,CAAIK,KAAAA,CAAM,GAAG,EAAA,CAAA,CAAIC,KAAK,EAAA,CAAA,GACtB,MACAN,GAAAA,CAAIK,KAAAA,CAAM,IAAI,EAAA,CAAA,CAAIC,KAAK,EAAA,CAAA;AAE/B,CAAA,EAlB8B,uBAAA,CAAA;AAyBvB,IAAMC,aAAAA,mBAAgBX,mBAAA,CAAA,CAACT,KAAAA,EAAmBW,OAAAA,GAAuB,CAAA,KACpEH,sBAAsBT,gBAAAA,CAAiBC,KAAAA,CAAAA,EAAQW,OAAAA,CAAAA,EADtB,eAAA","file":"IDXW633A.cjs","sourcesContent":["const UUID_BYTE_LENGTH = 16;\n\nexport type UuidVersion = 4 | 5;\n\nconst prepareUuidBytes = (bytes: Uint8Array): Uint8Array => {\n if (bytes.length === 0) {\n throw new Error('uuid bytes must not be empty');\n }\n\n if (bytes.length === UUID_BYTE_LENGTH) {\n return new Uint8Array(bytes);\n }\n\n if (bytes.length > UUID_BYTE_LENGTH) {\n return Uint8Array.from(bytes.subarray(0, UUID_BYTE_LENGTH));\n }\n\n const padded = new Uint8Array(UUID_BYTE_LENGTH);\n padded.set(bytes);\n return padded;\n};\n\nconst formatUuidFrom16Bytes = (working: Uint8Array, version: UuidVersion): string => {\n const versionBits = version === 4 ? 0x40 : 0x50;\n // Set version (4 or 5) and variant (10xx)\n working[6] = (working[6]! & 0x0f) | versionBits;\n working[8] = (working[8]! & 0x3f) | 0x80;\n\n const hex = Array.from(working, (b) => b.toString(16).padStart(2, '0'));\n return (\n hex.slice(0, 4).join('') +\n '-' +\n hex.slice(4, 6).join('') +\n '-' +\n hex.slice(6, 8).join('') +\n '-' +\n hex.slice(8, 10).join('') +\n '-' +\n hex.slice(10, 16).join('')\n );\n};\n\n/**\n * Converts bytes into an RFC 4122 UUID string. Inputs longer than 16 bytes use\n * the first 16; shorter inputs are zero-padded on the right. Empty input throws.\n * Default `version` is 4 (UUID v4); pass `5` for name-based hashes, etc.\n */\nexport const uuidFromBytes = (bytes: Uint8Array, version: UuidVersion = 4): string =>\n formatUuidFrom16Bytes(prepareUuidBytes(bytes), version);\n"]}
|
package/dist/YJF4D23A.cjs
DELETED
package/dist/YJF4D23A.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"YJF4D23A.cjs"}
|
package/dist/byte-codec.cjs
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var DSXMRHUH_cjs = require('./DSXMRHUH.cjs');
|
|
4
|
-
require('./YJF4D23A.cjs');
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Object.defineProperty(exports, "ByteCodec", {
|
|
9
|
-
enumerable: true,
|
|
10
|
-
get: function () { return DSXMRHUH_cjs.ByteCodec; }
|
|
11
|
-
});
|
|
12
|
-
//# sourceMappingURL=byte-codec.cjs.map
|
|
13
|
-
//# sourceMappingURL=byte-codec.cjs.map
|
package/dist/byte-codec.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"byte-codec.cjs"}
|
package/dist/index.cjs
DELETED
|
@@ -1,178 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var DSXMRHUH_cjs = require('./DSXMRHUH.cjs');
|
|
4
|
-
var IDXW633A_cjs = require('./IDXW633A.cjs');
|
|
5
|
-
var YJF4D23A_cjs = require('./YJF4D23A.cjs');
|
|
6
|
-
|
|
7
|
-
// src/index.ts
|
|
8
|
-
var base58regex = /^[A-HJ-NP-Za-km-z1-9]*$/;
|
|
9
|
-
var base64regex = /^[A-Za-z0-9+/]*={0,2}$/;
|
|
10
|
-
var hexStringRegex = /^(0x)?[0-9A-Fa-f]*$/;
|
|
11
|
-
function isBase58(address) {
|
|
12
|
-
return base58regex.test(address);
|
|
13
|
-
}
|
|
14
|
-
YJF4D23A_cjs.__name(isBase58, "isBase58");
|
|
15
|
-
function isBase64(address) {
|
|
16
|
-
return base64regex.test(address);
|
|
17
|
-
}
|
|
18
|
-
YJF4D23A_cjs.__name(isBase64, "isBase64");
|
|
19
|
-
function isHexString(value, length) {
|
|
20
|
-
if (typeof value !== "string" || !value.match(hexStringRegex)) {
|
|
21
|
-
return false;
|
|
22
|
-
}
|
|
23
|
-
if (length && value.length !== 2 + 2 * length) {
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
return true;
|
|
27
|
-
}
|
|
28
|
-
YJF4D23A_cjs.__name(isHexString, "isHexString");
|
|
29
|
-
function hexZeroPad(value, length) {
|
|
30
|
-
if (!isHexString(value)) {
|
|
31
|
-
throw new Error(`invalid hex string: ${value}`);
|
|
32
|
-
}
|
|
33
|
-
if (value.length > 2 * length + 2) {
|
|
34
|
-
throw new Error("value out of range");
|
|
35
|
-
}
|
|
36
|
-
return `0x${trim0x(value).padStart(2 * length, "0")}`;
|
|
37
|
-
}
|
|
38
|
-
YJF4D23A_cjs.__name(hexZeroPad, "hexZeroPad");
|
|
39
|
-
function trim0x(str) {
|
|
40
|
-
return str.replace(/^0x/, "");
|
|
41
|
-
}
|
|
42
|
-
YJF4D23A_cjs.__name(trim0x, "trim0x");
|
|
43
|
-
function ensure0xPrefixed(str) {
|
|
44
|
-
return `0x${trim0x(str)}`;
|
|
45
|
-
}
|
|
46
|
-
YJF4D23A_cjs.__name(ensure0xPrefixed, "ensure0xPrefixed");
|
|
47
|
-
function trimLeadingZeros(hexString) {
|
|
48
|
-
let withoutPrefix = trim0x(hexString);
|
|
49
|
-
withoutPrefix = withoutPrefix.replace(/^0+/, "");
|
|
50
|
-
return ensure0xPrefixed(withoutPrefix);
|
|
51
|
-
}
|
|
52
|
-
YJF4D23A_cjs.__name(trimLeadingZeros, "trimLeadingZeros");
|
|
53
|
-
function hexToUint8Array(hexString) {
|
|
54
|
-
return Uint8Array.from(Buffer.from(trim0x(hexString), "hex"));
|
|
55
|
-
}
|
|
56
|
-
YJF4D23A_cjs.__name(hexToUint8Array, "hexToUint8Array");
|
|
57
|
-
function hexToAscii(hex) {
|
|
58
|
-
if (!isHexString(hex)) {
|
|
59
|
-
throw new Error(`Invalid hex string ${hex}`);
|
|
60
|
-
}
|
|
61
|
-
let str = "";
|
|
62
|
-
let i = 0;
|
|
63
|
-
const l = hex.length;
|
|
64
|
-
if (hex.startsWith("0x")) {
|
|
65
|
-
i = 2;
|
|
66
|
-
}
|
|
67
|
-
for (; i < l; i += 2) {
|
|
68
|
-
const code = parseInt(hex.slice(i, i + 2), 16);
|
|
69
|
-
str += String.fromCharCode(code);
|
|
70
|
-
}
|
|
71
|
-
return str;
|
|
72
|
-
}
|
|
73
|
-
YJF4D23A_cjs.__name(hexToAscii, "hexToAscii");
|
|
74
|
-
function stringToUint8Array(str) {
|
|
75
|
-
const value = str.replace(/^0x/i, "");
|
|
76
|
-
const len = value.length + 1 - (value.length + 1) % 2;
|
|
77
|
-
return Uint8Array.from(Buffer.from(value.padStart(len, "0"), "hex"));
|
|
78
|
-
}
|
|
79
|
-
YJF4D23A_cjs.__name(stringToUint8Array, "stringToUint8Array");
|
|
80
|
-
function hexToBytes(hex) {
|
|
81
|
-
const value = hex.replace(/^0x/i, "");
|
|
82
|
-
const len = value.length + 1 - (value.length + 1) % 2;
|
|
83
|
-
return Uint8Array.from(Buffer.from(value.padStart(len, "0"), "hex"));
|
|
84
|
-
}
|
|
85
|
-
YJF4D23A_cjs.__name(hexToBytes, "hexToBytes");
|
|
86
|
-
function bytesToHex(bytes) {
|
|
87
|
-
return Buffer.from(bytes instanceof ArrayBuffer ? new Uint8Array(bytes) : bytes).toString("hex");
|
|
88
|
-
}
|
|
89
|
-
YJF4D23A_cjs.__name(bytesToHex, "bytesToHex");
|
|
90
|
-
function bytesToHexPrefixed(bytes) {
|
|
91
|
-
return ensure0xPrefixed(bytesToHex(bytes));
|
|
92
|
-
}
|
|
93
|
-
YJF4D23A_cjs.__name(bytesToHexPrefixed, "bytesToHexPrefixed");
|
|
94
|
-
function bytesToBase64(bytes) {
|
|
95
|
-
return Buffer.from(bytes instanceof ArrayBuffer ? new Uint8Array(bytes) : bytes).toString("base64");
|
|
96
|
-
}
|
|
97
|
-
YJF4D23A_cjs.__name(bytesToBase64, "bytesToBase64");
|
|
98
|
-
function base64ToBytes(base64) {
|
|
99
|
-
return Uint8Array.from(Buffer.from(base64, "base64"));
|
|
100
|
-
}
|
|
101
|
-
YJF4D23A_cjs.__name(base64ToBytes, "base64ToBytes");
|
|
102
|
-
function hexToBase64(hexString) {
|
|
103
|
-
const hex = trim0x(hexString);
|
|
104
|
-
if (!/^[0-9a-fA-F]+$/.test(hex)) {
|
|
105
|
-
throw new Error(`Invalid hex string: ${hexString}`);
|
|
106
|
-
}
|
|
107
|
-
if (hex.length % 2 !== 0) {
|
|
108
|
-
throw new Error("Hex string must have an even length");
|
|
109
|
-
}
|
|
110
|
-
const bytes = new Uint8Array(hex.length / 2);
|
|
111
|
-
for (let i = 0; i < hex.length; i += 2) {
|
|
112
|
-
bytes[i / 2] = parseInt(hex.substr(i, 2), 16);
|
|
113
|
-
}
|
|
114
|
-
const base64String = Buffer.from(bytes).toString("base64");
|
|
115
|
-
return base64String;
|
|
116
|
-
}
|
|
117
|
-
YJF4D23A_cjs.__name(hexToBase64, "hexToBase64");
|
|
118
|
-
function base64ToHex(base64String) {
|
|
119
|
-
if (!/^[A-Za-z0-9+/=]*$/.test(base64String)) {
|
|
120
|
-
throw new Error(`Invalid base64 string: ${base64String}`);
|
|
121
|
-
}
|
|
122
|
-
return `0x${Buffer.from(base64String, "base64").toString("hex")}`;
|
|
123
|
-
}
|
|
124
|
-
YJF4D23A_cjs.__name(base64ToHex, "base64ToHex");
|
|
125
|
-
function padString(str, length, left, padding = "0") {
|
|
126
|
-
const diff = length - str.length;
|
|
127
|
-
let result = str;
|
|
128
|
-
if (diff > 0) {
|
|
129
|
-
const pad = padding.repeat(diff);
|
|
130
|
-
result = left ? pad + str : str + pad;
|
|
131
|
-
}
|
|
132
|
-
return result;
|
|
133
|
-
}
|
|
134
|
-
YJF4D23A_cjs.__name(padString, "padString");
|
|
135
|
-
function padLeft(str, length, padding = "0") {
|
|
136
|
-
return padString(str, length, true, padding);
|
|
137
|
-
}
|
|
138
|
-
YJF4D23A_cjs.__name(padLeft, "padLeft");
|
|
139
|
-
function calcByteLength(str, byteSize = 8) {
|
|
140
|
-
const { length } = str;
|
|
141
|
-
const remainder = length % byteSize;
|
|
142
|
-
return remainder ? (length - remainder) / byteSize * byteSize + byteSize : length;
|
|
143
|
-
}
|
|
144
|
-
YJF4D23A_cjs.__name(calcByteLength, "calcByteLength");
|
|
145
|
-
function padAlignHex(str, byteSize = 8, padding = "0") {
|
|
146
|
-
const trimmed = trim0x(str);
|
|
147
|
-
return padLeft(trimmed, calcByteLength(trimmed, byteSize), padding);
|
|
148
|
-
}
|
|
149
|
-
YJF4D23A_cjs.__name(padAlignHex, "padAlignHex");
|
|
150
|
-
|
|
151
|
-
Object.defineProperty(exports, "ByteCodec", {
|
|
152
|
-
enumerable: true,
|
|
153
|
-
get: function () { return DSXMRHUH_cjs.ByteCodec; }
|
|
154
|
-
});
|
|
155
|
-
Object.defineProperty(exports, "uuidFromBytes", {
|
|
156
|
-
enumerable: true,
|
|
157
|
-
get: function () { return IDXW633A_cjs.uuidFromBytes; }
|
|
158
|
-
});
|
|
159
|
-
exports.base64ToBytes = base64ToBytes;
|
|
160
|
-
exports.base64ToHex = base64ToHex;
|
|
161
|
-
exports.bytesToBase64 = bytesToBase64;
|
|
162
|
-
exports.bytesToHex = bytesToHex;
|
|
163
|
-
exports.bytesToHexPrefixed = bytesToHexPrefixed;
|
|
164
|
-
exports.ensure0xPrefixed = ensure0xPrefixed;
|
|
165
|
-
exports.hexToAscii = hexToAscii;
|
|
166
|
-
exports.hexToBase64 = hexToBase64;
|
|
167
|
-
exports.hexToBytes = hexToBytes;
|
|
168
|
-
exports.hexToUint8Array = hexToUint8Array;
|
|
169
|
-
exports.hexZeroPad = hexZeroPad;
|
|
170
|
-
exports.isBase58 = isBase58;
|
|
171
|
-
exports.isBase64 = isBase64;
|
|
172
|
-
exports.isHexString = isHexString;
|
|
173
|
-
exports.padAlignHex = padAlignHex;
|
|
174
|
-
exports.stringToUint8Array = stringToUint8Array;
|
|
175
|
-
exports.trim0x = trim0x;
|
|
176
|
-
exports.trimLeadingZeros = trimLeadingZeros;
|
|
177
|
-
//# sourceMappingURL=index.cjs.map
|
|
178
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":["base58regex","base64regex","hexStringRegex","isBase58","address","test","isBase64","isHexString","value","length","match","hexZeroPad","Error","trim0x","padStart","str","replace","ensure0xPrefixed","trimLeadingZeros","hexString","withoutPrefix","hexToUint8Array","Uint8Array","from","Buffer","hexToAscii","hex","i","l","startsWith","code","parseInt","slice","String","fromCharCode","stringToUint8Array","len","hexToBytes","bytesToHex","bytes","ArrayBuffer","toString","bytesToHexPrefixed","bytesToBase64","base64ToBytes","base64","hexToBase64","substr","base64String","base64ToHex","padString","left","padding","diff","result","pad","repeat","padLeft","calcByteLength","byteSize","remainder","padAlignHex","trimmed"],"mappings":";;;;;;;AAKA,IAAMA,WAAAA,GAAc,yBAAA;AACpB,IAAMC,WAAAA,GAAc,wBAAA;AACpB,IAAMC,cAAAA,GAAiB,qBAAA;AAEhB,SAASC,SAASC,OAAAA,EAAe;AACpC,EAAA,OAAOJ,WAAAA,CAAYK,KAAKD,OAAAA,CAAAA;AAC5B;AAFgBD,mBAAAA,CAAAA,QAAAA,EAAAA,UAAAA,CAAAA;AAIT,SAASG,SAASF,OAAAA,EAAe;AACpC,EAAA,OAAOH,WAAAA,CAAYI,KAAKD,OAAAA,CAAAA;AAC5B;AAFgBE,mBAAAA,CAAAA,QAAAA,EAAAA,UAAAA,CAAAA;AAIT,SAASC,WAAAA,CAAYC,OAAYC,MAAAA,EAAe;AACnD,EAAA,IAAI,OAAOD,KAAAA,KAAU,QAAA,IAAY,CAACA,KAAAA,CAAME,KAAAA,CAAMR,cAAAA,CAAAA,EAAiB;AAC3D,IAAA,OAAO,KAAA;AACX,EAAA;AACA,EAAA,IAAIO,MAAAA,IAAUD,KAAAA,CAAMC,MAAAA,KAAW,CAAA,GAAI,IAAIA,MAAAA,EAAQ;AAC3C,IAAA,OAAO,KAAA;AACX,EAAA;AACA,EAAA,OAAO,IAAA;AACX;AARgBF,mBAAAA,CAAAA,WAAAA,EAAAA,aAAAA,CAAAA;AAUT,SAASI,UAAAA,CAAWH,OAAeC,MAAAA,EAAc;AACpD,EAAA,IAAI,CAACF,WAAAA,CAAYC,KAAAA,CAAAA,EAAQ;AACrB,IAAA,MAAM,IAAII,KAAAA,CAAM,CAAA,oBAAA,EAAuBJ,KAAAA,CAAAA,CAAO,CAAA;AAClD,EAAA;AAEA,EAAA,IAAIA,KAAAA,CAAMC,MAAAA,GAAS,CAAA,GAAIA,MAAAA,GAAS,CAAA,EAAG;AAC/B,IAAA,MAAM,IAAIG,MAAM,oBAAA,CAAA;AACpB,EAAA;AAEA,EA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,OAAO0C,QAAQK,OAAAA,EAASJ,cAAAA,CAAeI,OAAAA,EAASH,QAAAA,GAAWP,OAAAA,CAAAA;AAC/D;AAHgBS,mBAAAA,CAAAA,WAAAA,EAAAA,aAAAA,CAAAA","file":"index.cjs","sourcesContent":["export * from './byte-codec';\nexport * from './uuid';\n\nexport type HexString = `0x${string}`;\n\nconst base58regex = /^[A-HJ-NP-Za-km-z1-9]*$/;\nconst base64regex = /^[A-Za-z0-9+/]*={0,2}$/;\nconst hexStringRegex = /^(0x)?[0-9A-Fa-f]*$/;\n\nexport function isBase58(address: string): boolean {\n return base58regex.test(address);\n}\n\nexport function isBase64(address: string): boolean {\n return base64regex.test(address);\n}\n\nexport function isHexString(value: any, length?: number): value is HexString {\n if (typeof value !== 'string' || !value.match(hexStringRegex)) {\n return false;\n }\n if (length && value.length !== 2 + 2 * length) {\n return false;\n }\n return true;\n}\n\nexport function hexZeroPad(value: string, length: number): HexString {\n if (!isHexString(value)) {\n throw new Error(`invalid hex string: ${value}`);\n }\n\n if (value.length > 2 * length + 2) {\n throw new Error('value out of range');\n }\n\n return `0x${trim0x(value).padStart(2 * length, '0')}`;\n}\n\nexport function trim0x(str: string): string {\n return str.replace(/^0x/, '');\n}\n\nexport function ensure0xPrefixed(str: string): HexString {\n return `0x${trim0x(str)}`;\n}\n\nexport function trimLeadingZeros(hexString: string): HexString {\n // Remove the '0x' prefix\n let withoutPrefix = trim0x(hexString);\n\n // Trim leading zeros\n withoutPrefix = withoutPrefix.replace(/^0+/, '');\n\n // Add back the '0x' prefix\n return ensure0xPrefixed(withoutPrefix);\n}\n\nexport function hexToUint8Array(hexString: string): Uint8Array {\n return Uint8Array.from(Buffer.from(trim0x(hexString), 'hex'));\n}\n\nexport function hexToAscii(hex: string): string {\n if (!isHexString(hex)) {\n throw new Error(`Invalid hex string ${hex}`);\n }\n\n let str = '';\n let i = 0;\n const l = hex.length;\n if (hex.startsWith('0x')) {\n i = 2;\n }\n for (; i < l; i += 2) {\n const code = parseInt(hex.slice(i, i + 2), 16);\n str += String.fromCharCode(code);\n }\n\n return str;\n}\n\nexport function stringToUint8Array(str: string): Uint8Array {\n const value = str.replace(/^0x/i, '');\n const len = value.length + 1 - ((value.length + 1) % 2);\n return Uint8Array.from(Buffer.from(value.padStart(len, '0'), 'hex'));\n}\n\n/**\n * A function to convert hex string to Uint8Array (not prefixed)\n * @param hex hex string\n * @returns Uint8Array\n */\nexport function hexToBytes(hex: string): Uint8Array {\n const value = hex.replace(/^0x/i, '');\n const len = value.length + 1 - ((value.length + 1) % 2);\n return Uint8Array.from(Buffer.from(value.padStart(len, '0'), 'hex'));\n}\n\nexport function bytesToHex(bytes: Uint8Array | ArrayBuffer): string {\n return Buffer.from(bytes instanceof ArrayBuffer ? new Uint8Array(bytes) : bytes).toString(\n 'hex',\n );\n}\n\n/**\n * 0x prefixed hex string from Uint8Array\n * @param bytes\n */\nexport function bytesToHexPrefixed(bytes: Uint8Array | ArrayBuffer): HexString {\n return ensure0xPrefixed(bytesToHex(bytes));\n}\n\nexport function bytesToBase64(bytes: Uint8Array | ArrayBuffer): string {\n return Buffer.from(bytes instanceof ArrayBuffer ? new Uint8Array(bytes) : bytes).toString(\n 'base64',\n );\n}\n\nexport function base64ToBytes(base64: string): Uint8Array {\n return Uint8Array.from(Buffer.from(base64, 'base64'));\n}\n\nexport function hexToBase64(hexString: string): string {\n const hex = trim0x(hexString);\n // Validate that the input is a valid hex string\n if (!/^[0-9a-fA-F]+$/.test(hex)) {\n throw new Error(`Invalid hex string: ${hexString}`);\n }\n\n // Ensure the hex string has an even length\n if (hex.length % 2 !== 0) {\n throw new Error('Hex string must have an even length');\n }\n\n // Convert hex string to a byte array\n const bytes = new Uint8Array(hex.length / 2);\n for (let i = 0; i < hex.length; i += 2) {\n bytes[i / 2] = parseInt(hex.substr(i, 2), 16);\n }\n\n // Convert the byte array to a base64 string\n const base64String = Buffer.from(bytes).toString('base64');\n\n return base64String;\n}\n\nexport function base64ToHex(base64String: string): HexString {\n if (!/^[A-Za-z0-9+/=]*$/.test(base64String)) {\n throw new Error(`Invalid base64 string: ${base64String}`);\n }\n return `0x${Buffer.from(base64String, 'base64').toString('hex')}`;\n}\n\nfunction padString(str: string, length: number, left: boolean, padding = '0') {\n const diff = length - str.length;\n let result = str;\n if (diff > 0) {\n const pad = padding.repeat(diff);\n result = left ? pad + str : str + pad;\n }\n return result;\n}\n\nfunction padLeft(str: string, length: number, padding = '0') {\n return padString(str, length, true, padding);\n}\nfunction calcByteLength(str: string, byteSize = 8) {\n const { length } = str;\n const remainder = length % byteSize;\n return remainder ? ((length - remainder) / byteSize) * byteSize + byteSize : length;\n}\n\n/**\n * Pads a hex string on the left so its length is a multiple of `byteSize`.\n * Used to align hex strings.\n * @param str Hex string.\n * @param byteSize Group size to align to, in hex chars (default: 8).\n * @param padding Left-pad character (default: '0').\n * @returns Hex string left-padded to a multiple of `byteSize`.\n */\nexport function padAlignHex(str: string, byteSize = 8, padding = '0') {\n const trimmed = trim0x(str);\n return padLeft(trimmed, calcByteLength(trimmed, byteSize), padding);\n}\n"]}
|
package/dist/uuid.cjs
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var IDXW633A_cjs = require('./IDXW633A.cjs');
|
|
4
|
-
require('./YJF4D23A.cjs');
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
Object.defineProperty(exports, "uuidFromBytes", {
|
|
9
|
-
enumerable: true,
|
|
10
|
-
get: function () { return IDXW633A_cjs.uuidFromBytes; }
|
|
11
|
-
});
|
|
12
|
-
//# sourceMappingURL=uuid.cjs.map
|
|
13
|
-
//# sourceMappingURL=uuid.cjs.map
|
package/dist/uuid.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","file":"uuid.cjs"}
|