MCPcopy Create free account
hub / github.com/PageLeay/celestial-runtime / toBeArray

Function toBeArray

lib.commonjs/utils/maths.js:194–209  ·  view source on GitHub ↗

* Converts %%value%% to a Big Endian Uint8Array.

(_value)

Source from the content-addressed store, hash-verified

192 * Converts %%value%% to a Big Endian Uint8Array.
193 */
194function toBeArray(_value) {
195 const value = getUint(_value, "value");
196 if (value === BN_0) {
197 return new Uint8Array([]);
198 }
199 let hex = value.toString(16);
200 if (hex.length % 2) {
201 hex = "0" + hex;
202 }
203 const result = new Uint8Array(hex.length / 2);
204 for (let i = 0; i < result.length; i++) {
205 const offset = i * 2;
206 result[i] = parseInt(hex.substring(offset, offset + 2), 16);
207 }
208 return result;
209}
210exports.toBeArray = toBeArray;
211/**
212 * Returns a [[HexString]] for %%value%% safe to use as a //Quantity//.

Callers 1

toQuantityFunction · 0.70

Calls 2

getUintFunction · 0.70
toStringMethod · 0.45

Tested by

no test coverage detected