@trezoa/buffer-layout-utils
Advanced tools
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.encodeDecode = void 0; | ||
| const encodeDecode = (layout) => { | ||
| const decode = layout.decode.bind(layout); | ||
| const encode = layout.encode.bind(layout); | ||
| return { decode, encode }; | ||
| }; | ||
| exports.encodeDecode = encodeDecode; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.u256be = exports.u256 = exports.u192be = exports.u192 = exports.u128be = exports.u128 = exports.u64be = exports.u64 = exports.bigIntBE = exports.bigInt = void 0; | ||
| const buffer_1 = require("buffer"); | ||
| const buffer_layout_1 = require("@trezoa/buffer-layout"); | ||
| const bigint_buffer_1 = require("bigint-buffer"); | ||
| const base_1 = require("./base"); | ||
| // https://github.com/no2chem/bigint-buffer/issues/59 | ||
| function assertValidBigInteger(untrustedInput) { | ||
| if (typeof untrustedInput !== 'bigint') { | ||
| throw new Error('Expected a `BigInt`'); | ||
| } | ||
| } | ||
| function bigInt_IMPL(littleEndian, length) { | ||
| return (property) => { | ||
| const layout = (0, buffer_layout_1.blob)(length, property); | ||
| const { encode, decode } = (0, base_1.encodeDecode)(layout); | ||
| const bigIntLayout = layout; | ||
| bigIntLayout.decode = (buffer, offset) => { | ||
| const src = decode(buffer, offset); | ||
| return littleEndian ? (0, bigint_buffer_1.toBigIntLE)(buffer_1.Buffer.from(src)) : (0, bigint_buffer_1.toBigIntBE)(buffer_1.Buffer.from(src)); | ||
| }; | ||
| bigIntLayout.encode = (bigInt, buffer, offset) => { | ||
| assertValidBigInteger(bigInt); | ||
| let src; | ||
| if (length === 0) { | ||
| // https://github.com/no2chem/bigint-buffer/issues/40 | ||
| // `toBuffer{BE|LE}` crashes when passed zero for the `length` argument. | ||
| src = buffer_1.Buffer.alloc(0); | ||
| } | ||
| else { | ||
| src = littleEndian ? (0, bigint_buffer_1.toBufferLE)(bigInt, length) : (0, bigint_buffer_1.toBufferBE)(bigInt, length); | ||
| } | ||
| return encode(src, buffer, offset); | ||
| }; | ||
| return bigIntLayout; | ||
| }; | ||
| } | ||
| exports.bigInt = bigInt_IMPL.bind(null, /* littleEndian */ true); | ||
| exports.bigIntBE = bigInt_IMPL.bind(null, /* littleEndian */ false); | ||
| exports.u64 = (0, exports.bigInt)(8); | ||
| exports.u64be = (0, exports.bigIntBE)(8); | ||
| exports.u128 = (0, exports.bigInt)(16); | ||
| exports.u128be = (0, exports.bigIntBE)(16); | ||
| exports.u192 = (0, exports.bigInt)(24); | ||
| exports.u192be = (0, exports.bigIntBE)(24); | ||
| exports.u256 = (0, exports.bigInt)(32); | ||
| exports.u256be = (0, exports.bigIntBE)(32); |
| "use strict"; | ||
| var __importDefault = (this && this.__importDefault) || function (mod) { | ||
| return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.decimal = exports.WAD = void 0; | ||
| const bignumber_js_1 = __importDefault(require("bignumber.js")); | ||
| const base_1 = require("./base"); | ||
| const bigint_1 = require("./bigint"); | ||
| exports.WAD = new bignumber_js_1.default('1e+18'); | ||
| const decimal = (property) => { | ||
| const layout = (0, bigint_1.u128)(property); | ||
| const { encode, decode } = (0, base_1.encodeDecode)(layout); | ||
| const decimalLayout = layout; | ||
| decimalLayout.decode = (buffer, offset) => { | ||
| const src = decode(buffer, offset).toString(); | ||
| return new bignumber_js_1.default(src).div(exports.WAD); | ||
| }; | ||
| decimalLayout.encode = (decimal, buffer, offset) => { | ||
| const src = BigInt(decimal.times(exports.WAD).integerValue().toString()); | ||
| return encode(src, buffer, offset); | ||
| }; | ||
| return decimalLayout; | ||
| }; | ||
| exports.decimal = decimal; |
| "use strict"; | ||
| var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| var desc = Object.getOwnPropertyDescriptor(m, k); | ||
| if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { | ||
| desc = { enumerable: true, get: function() { return m[k]; } }; | ||
| } | ||
| Object.defineProperty(o, k2, desc); | ||
| }) : (function(o, m, k, k2) { | ||
| if (k2 === undefined) k2 = k; | ||
| o[k2] = m[k]; | ||
| })); | ||
| var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
| for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p); | ||
| }; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| __exportStar(require("./base"), exports); | ||
| __exportStar(require("./bigint"), exports); | ||
| __exportStar(require("./decimal"), exports); | ||
| __exportStar(require("./native"), exports); | ||
| __exportStar(require("./web3"), exports); |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.bool = void 0; | ||
| const buffer_layout_1 = require("@trezoa/buffer-layout"); | ||
| const base_1 = require("./base"); | ||
| const bool = (property) => { | ||
| const layout = (0, buffer_layout_1.u8)(property); | ||
| const { encode, decode } = (0, base_1.encodeDecode)(layout); | ||
| const boolLayout = layout; | ||
| boolLayout.decode = (buffer, offset) => { | ||
| const src = decode(buffer, offset); | ||
| return !!src; | ||
| }; | ||
| boolLayout.encode = (bool, buffer, offset) => { | ||
| const src = Number(bool); | ||
| return encode(src, buffer, offset); | ||
| }; | ||
| return boolLayout; | ||
| }; | ||
| exports.bool = bool; |
| {"type":"commonjs"} |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.publicKey = void 0; | ||
| const buffer_layout_1 = require("@trezoa/buffer-layout"); | ||
| const web3_js_1 = require("@trezoa/web3.js"); | ||
| const base_1 = require("./base"); | ||
| const publicKey = (property) => { | ||
| const layout = (0, buffer_layout_1.blob)(32, property); | ||
| const { encode, decode } = (0, base_1.encodeDecode)(layout); | ||
| const publicKeyLayout = layout; | ||
| publicKeyLayout.decode = (buffer, offset) => { | ||
| const src = decode(buffer, offset); | ||
| return new web3_js_1.PublicKey(src); | ||
| }; | ||
| publicKeyLayout.encode = (publicKey, buffer, offset) => { | ||
| const src = publicKey.toBuffer(); | ||
| return encode(src, buffer, offset); | ||
| }; | ||
| return publicKeyLayout; | ||
| }; | ||
| exports.publicKey = publicKey; |
| export const encodeDecode = (layout) => { | ||
| const decode = layout.decode.bind(layout); | ||
| const encode = layout.encode.bind(layout); | ||
| return { decode, encode }; | ||
| }; |
| import { Buffer } from 'buffer'; | ||
| import { blob } from '@trezoa/buffer-layout'; | ||
| import { toBigIntBE, toBigIntLE, toBufferBE, toBufferLE } from 'bigint-buffer'; | ||
| import { encodeDecode } from './base.mjs'; | ||
| // https://github.com/no2chem/bigint-buffer/issues/59 | ||
| function assertValidBigInteger(untrustedInput) { | ||
| if (typeof untrustedInput !== 'bigint') { | ||
| throw new Error('Expected a `BigInt`'); | ||
| } | ||
| } | ||
| function bigInt_IMPL(littleEndian, length) { | ||
| return (property) => { | ||
| const layout = blob(length, property); | ||
| const { encode, decode } = encodeDecode(layout); | ||
| const bigIntLayout = layout; | ||
| bigIntLayout.decode = (buffer, offset) => { | ||
| const src = decode(buffer, offset); | ||
| return littleEndian ? toBigIntLE(Buffer.from(src)) : toBigIntBE(Buffer.from(src)); | ||
| }; | ||
| bigIntLayout.encode = (bigInt, buffer, offset) => { | ||
| assertValidBigInteger(bigInt); | ||
| let src; | ||
| if (length === 0) { | ||
| // https://github.com/no2chem/bigint-buffer/issues/40 | ||
| // `toBuffer{BE|LE}` crashes when passed zero for the `length` argument. | ||
| src = Buffer.alloc(0); | ||
| } | ||
| else { | ||
| src = littleEndian ? toBufferLE(bigInt, length) : toBufferBE(bigInt, length); | ||
| } | ||
| return encode(src, buffer, offset); | ||
| }; | ||
| return bigIntLayout; | ||
| }; | ||
| } | ||
| export const bigInt = /* @__PURE__ */ bigInt_IMPL.bind(null, /* littleEndian */ true); | ||
| export const bigIntBE = /* @__PURE__ */ bigInt_IMPL.bind(null, /* littleEndian */ false); | ||
| export const u64 = /* @__PURE__ */ bigInt(8); | ||
| export const u64be = /* @__PURE__ */ bigIntBE(8); | ||
| export const u128 = /* @__PURE__ */ bigInt(16); | ||
| export const u128be = /* @__PURE__ */ bigIntBE(16); | ||
| export const u192 = /* @__PURE__ */ bigInt(24); | ||
| export const u192be = /* @__PURE__ */ bigIntBE(24); | ||
| export const u256 = /* @__PURE__ */ bigInt(32); | ||
| export const u256be = /* @__PURE__ */ bigIntBE(32); |
| import BigNumber from 'bignumber.js'; | ||
| import { encodeDecode } from './base.mjs'; | ||
| import { u128 } from './bigint.mjs'; | ||
| export const WAD = new BigNumber('1e+18'); | ||
| export const decimal = (property) => { | ||
| const layout = u128(property); | ||
| const { encode, decode } = encodeDecode(layout); | ||
| const decimalLayout = layout; | ||
| decimalLayout.decode = (buffer, offset) => { | ||
| const src = decode(buffer, offset).toString(); | ||
| return new BigNumber(src).div(WAD); | ||
| }; | ||
| decimalLayout.encode = (decimal, buffer, offset) => { | ||
| const src = BigInt(decimal.times(WAD).integerValue().toString()); | ||
| return encode(src, buffer, offset); | ||
| }; | ||
| return decimalLayout; | ||
| }; |
| export * from './base.mjs'; | ||
| export * from './bigint.mjs'; | ||
| export * from './decimal.mjs'; | ||
| export * from './native.mjs'; | ||
| export * from './web3.mjs'; |
| import { u8 } from '@trezoa/buffer-layout'; | ||
| import { encodeDecode } from './base.mjs'; | ||
| export const bool = (property) => { | ||
| const layout = u8(property); | ||
| const { encode, decode } = encodeDecode(layout); | ||
| const boolLayout = layout; | ||
| boolLayout.decode = (buffer, offset) => { | ||
| const src = decode(buffer, offset); | ||
| return !!src; | ||
| }; | ||
| boolLayout.encode = (bool, buffer, offset) => { | ||
| const src = Number(bool); | ||
| return encode(src, buffer, offset); | ||
| }; | ||
| return boolLayout; | ||
| }; |
| {"type":"module"} |
| import { blob } from '@trezoa/buffer-layout'; | ||
| import { PublicKey } from '@trezoa/web3.js'; | ||
| import { encodeDecode } from './base.mjs'; | ||
| export const publicKey = (property) => { | ||
| const layout = blob(32, property); | ||
| const { encode, decode } = encodeDecode(layout); | ||
| const publicKeyLayout = layout; | ||
| publicKeyLayout.decode = (buffer, offset) => { | ||
| const src = decode(buffer, offset); | ||
| return new PublicKey(src); | ||
| }; | ||
| publicKeyLayout.encode = (publicKey, buffer, offset) => { | ||
| const src = publicKey.toBuffer(); | ||
| return encode(src, buffer, offset); | ||
| }; | ||
| return publicKeyLayout; | ||
| }; |
| import { Layout } from '@trezoa/buffer-layout'; | ||
| export interface EncodeDecode<T> { | ||
| decode(buffer: Buffer, offset?: number): T; | ||
| encode(src: T, buffer: Buffer, offset?: number): number; | ||
| } | ||
| export declare const encodeDecode: <T>(layout: Layout<T>) => EncodeDecode<T>; |
| import { Layout } from '@trezoa/buffer-layout'; | ||
| export declare const bigInt: (length: number) => (property?: string) => Layout<bigint>; | ||
| export declare const bigIntBE: (length: number) => (property?: string) => Layout<bigint>; | ||
| export declare const u64: (property?: string) => Layout<bigint>; | ||
| export declare const u64be: (property?: string) => Layout<bigint>; | ||
| export declare const u128: (property?: string) => Layout<bigint>; | ||
| export declare const u128be: (property?: string) => Layout<bigint>; | ||
| export declare const u192: (property?: string) => Layout<bigint>; | ||
| export declare const u192be: (property?: string) => Layout<bigint>; | ||
| export declare const u256: (property?: string) => Layout<bigint>; | ||
| export declare const u256be: (property?: string) => Layout<bigint>; |
| import { Layout } from '@trezoa/buffer-layout'; | ||
| import BigNumber from 'bignumber.js'; | ||
| export declare const WAD: BigNumber; | ||
| export declare const decimal: (property?: string) => Layout<BigNumber>; |
| export * from './base'; | ||
| export * from './bigint'; | ||
| export * from './decimal'; | ||
| export * from './native'; | ||
| export * from './web3'; |
| import { Layout } from '@trezoa/buffer-layout'; | ||
| export declare const bool: (property?: string) => Layout<boolean>; |
| import { Layout } from '@trezoa/buffer-layout'; | ||
| import { PublicKey } from '@trezoa/web3.js'; | ||
| export declare const publicKey: (property?: string) => Layout<PublicKey>; |
+1
-1
| { | ||
| "name": "@trezoa/buffer-layout-utils", | ||
| "version": "0.3.0", | ||
| "version": "0.3.1", | ||
| "author": "Trezoa Team <maintainers@trezoa.foundation>", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/trezoa-team/buffer-layout-utils", |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
30456
63.92%29
222.22%392
253.15%1
Infinity%