New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@waves/marshall

Package Overview
Dependencies
Maintainers
13
Versions
43
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@waves/marshall - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

coverage/lcov-report/src/jsonMethods.ts.html

25

coverage/coverage-summary.json

@@ -1,13 +0,14 @@

{"total": {"lines":{"total":486,"covered":456,"skipped":0,"pct":93.83},"statements":{"total":579,"covered":544,"skipped":0,"pct":93.96},"functions":{"total":107,"covered":102,"skipped":0,"pct":95.33},"branches":{"total":240,"covered":184,"skipped":0,"pct":76.67}}
,"/Users/siem/IdeaProjects/tx-parse-serialize/src/index.ts": {"lines":{"total":37,"covered":35,"skipped":0,"pct":94.59},"functions":{"total":10,"covered":10,"skipped":0,"pct":100},"statements":{"total":40,"covered":38,"skipped":0,"pct":95},"branches":{"total":14,"covered":12,"skipped":0,"pct":85.71}}
,"/Users/siem/IdeaProjects/tx-parse-serialize/src/parse.ts": {"lines":{"total":58,"covered":56,"skipped":0,"pct":96.55},"functions":{"total":6,"covered":6,"skipped":0,"pct":100},"statements":{"total":74,"covered":71,"skipped":0,"pct":95.95},"branches":{"total":36,"covered":32,"skipped":0,"pct":88.89}}
,"/Users/siem/IdeaProjects/tx-parse-serialize/src/parsePrimitives.ts": {"lines":{"total":68,"covered":62,"skipped":0,"pct":91.18},"functions":{"total":25,"covered":24,"skipped":0,"pct":96},"statements":{"total":97,"covered":90,"skipped":0,"pct":92.78},"branches":{"total":42,"covered":22,"skipped":0,"pct":52.38}}
,"/Users/siem/IdeaProjects/tx-parse-serialize/src/serialize.ts": {"lines":{"total":41,"covered":37,"skipped":0,"pct":90.24},"functions":{"total":6,"covered":6,"skipped":0,"pct":100},"statements":{"total":47,"covered":43,"skipped":0,"pct":91.49},"branches":{"total":32,"covered":27,"skipped":0,"pct":84.38}}
,"/Users/siem/IdeaProjects/tx-parse-serialize/src/serializePrimitives.ts": {"lines":{"total":39,"covered":39,"skipped":0,"pct":100},"functions":{"total":21,"covered":21,"skipped":0,"pct":100},"statements":{"total":53,"covered":53,"skipped":0,"pct":100},"branches":{"total":15,"covered":13,"skipped":0,"pct":86.67}}
,"/Users/siem/IdeaProjects/tx-parse-serialize/src/txSchemas.ts": {"lines":{"total":84,"covered":82,"skipped":0,"pct":97.62},"functions":{"total":20,"covered":16,"skipped":0,"pct":80},"statements":{"total":95,"covered":91,"skipped":0,"pct":95.79},"branches":{"total":18,"covered":14,"skipped":0,"pct":77.78}}
,"/Users/siem/IdeaProjects/tx-parse-serialize/src/txToJson.ts": {"lines":{"total":72,"covered":69,"skipped":0,"pct":95.83},"functions":{"total":9,"covered":9,"skipped":0,"pct":100},"statements":{"total":80,"covered":76,"skipped":0,"pct":95},"branches":{"total":59,"covered":52,"skipped":0,"pct":88.14}}
,"/Users/siem/IdeaProjects/tx-parse-serialize/src/libs/Utf8ArrayToStr.ts": {"lines":{"total":22,"covered":14,"skipped":0,"pct":63.64},"functions":{"total":2,"covered":2,"skipped":0,"pct":100},"statements":{"total":22,"covered":14,"skipped":0,"pct":63.64},"branches":{"total":12,"covered":4,"skipped":0,"pct":33.33}}
,"/Users/siem/IdeaProjects/tx-parse-serialize/src/libs/base58.ts": {"lines":{"total":43,"covered":40,"skipped":0,"pct":93.02},"functions":{"total":4,"covered":4,"skipped":0,"pct":100},"statements":{"total":45,"covered":42,"skipped":0,"pct":93.33},"branches":{"total":10,"covered":7,"skipped":0,"pct":70}}
,"/Users/siem/IdeaProjects/tx-parse-serialize/src/libs/utils.ts": {"lines":{"total":5,"covered":5,"skipped":0,"pct":100},"functions":{"total":4,"covered":4,"skipped":0,"pct":100},"statements":{"total":9,"covered":9,"skipped":0,"pct":100},"branches":{"total":2,"covered":1,"skipped":0,"pct":50}}
,"/Users/siem/IdeaProjects/tx-parse-serialize/test/exampleTxs.ts": {"lines":{"total":17,"covered":17,"skipped":0,"pct":100},"functions":{"total":0,"covered":0,"skipped":0,"pct":100},"statements":{"total":17,"covered":17,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}}
{"total": {"lines":{"total":499,"covered":467,"skipped":0,"pct":93.59},"statements":{"total":592,"covered":555,"skipped":0,"pct":93.75},"functions":{"total":105,"covered":100,"skipped":0,"pct":95.24},"branches":{"total":242,"covered":184,"skipped":0,"pct":76.03}}
,"/Users/siem/IdeaProjects/marshall/src/index.ts": {"lines":{"total":14,"covered":14,"skipped":0,"pct":100},"functions":{"total":1,"covered":1,"skipped":0,"pct":100},"statements":{"total":14,"covered":14,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}}
,"/Users/siem/IdeaProjects/marshall/src/jsonMethods.ts": {"lines":{"total":84,"covered":79,"skipped":0,"pct":94.05},"functions":{"total":11,"covered":11,"skipped":0,"pct":100},"statements":{"total":92,"covered":86,"skipped":0,"pct":93.48},"branches":{"total":67,"covered":58,"skipped":0,"pct":86.57}}
,"/Users/siem/IdeaProjects/marshall/src/parse.ts": {"lines":{"total":65,"covered":63,"skipped":0,"pct":96.92},"functions":{"total":8,"covered":8,"skipped":0,"pct":100},"statements":{"total":83,"covered":80,"skipped":0,"pct":96.39},"branches":{"total":36,"covered":32,"skipped":0,"pct":88.89}}
,"/Users/siem/IdeaProjects/marshall/src/parsePrimitives.ts": {"lines":{"total":68,"covered":62,"skipped":0,"pct":91.18},"functions":{"total":25,"covered":24,"skipped":0,"pct":96},"statements":{"total":97,"covered":90,"skipped":0,"pct":92.78},"branches":{"total":42,"covered":22,"skipped":0,"pct":52.38}}
,"/Users/siem/IdeaProjects/marshall/src/schemaTypes.ts": {"lines":{"total":5,"covered":5,"skipped":0,"pct":100},"functions":{"total":1,"covered":1,"skipped":0,"pct":100},"statements":{"total":5,"covered":5,"skipped":0,"pct":100},"branches":{"total":2,"covered":2,"skipped":0,"pct":100}}
,"/Users/siem/IdeaProjects/marshall/src/schemas.ts": {"lines":{"total":88,"covered":84,"skipped":0,"pct":95.45},"functions":{"total":20,"covered":16,"skipped":0,"pct":80},"statements":{"total":99,"covered":93,"skipped":0,"pct":93.94},"branches":{"total":22,"covered":16,"skipped":0,"pct":72.73}}
,"/Users/siem/IdeaProjects/marshall/src/serialize.ts": {"lines":{"total":49,"covered":45,"skipped":0,"pct":91.84},"functions":{"total":8,"covered":8,"skipped":0,"pct":100},"statements":{"total":56,"covered":52,"skipped":0,"pct":92.86},"branches":{"total":34,"covered":29,"skipped":0,"pct":85.29}}
,"/Users/siem/IdeaProjects/marshall/src/serializePrimitives.ts": {"lines":{"total":39,"covered":39,"skipped":0,"pct":100},"functions":{"total":21,"covered":21,"skipped":0,"pct":100},"statements":{"total":53,"covered":53,"skipped":0,"pct":100},"branches":{"total":15,"covered":13,"skipped":0,"pct":86.67}}
,"/Users/siem/IdeaProjects/marshall/src/libs/Utf8ArrayToStr.ts": {"lines":{"total":22,"covered":14,"skipped":0,"pct":63.64},"functions":{"total":2,"covered":2,"skipped":0,"pct":100},"statements":{"total":22,"covered":14,"skipped":0,"pct":63.64},"branches":{"total":12,"covered":4,"skipped":0,"pct":33.33}}
,"/Users/siem/IdeaProjects/marshall/src/libs/base58.ts": {"lines":{"total":43,"covered":40,"skipped":0,"pct":93.02},"functions":{"total":4,"covered":4,"skipped":0,"pct":100},"statements":{"total":45,"covered":42,"skipped":0,"pct":93.33},"branches":{"total":10,"covered":7,"skipped":0,"pct":70}}
,"/Users/siem/IdeaProjects/marshall/src/libs/utils.ts": {"lines":{"total":5,"covered":5,"skipped":0,"pct":100},"functions":{"total":4,"covered":4,"skipped":0,"pct":100},"statements":{"total":9,"covered":9,"skipped":0,"pct":100},"branches":{"total":2,"covered":1,"skipped":0,"pct":50}}
,"/Users/siem/IdeaProjects/marshall/test/exampleTxs.ts": {"lines":{"total":17,"covered":17,"skipped":0,"pct":100},"functions":{"total":0,"covered":0,"skipped":0,"pct":100},"statements":{"total":17,"covered":17,"skipped":0,"pct":100},"branches":{"total":0,"covered":0,"skipped":0,"pct":100}}
}

@@ -14,72 +14,25 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
var txSchemas_1 = require("./txSchemas");
var serialize_1 = require("./serialize");
var parse_1 = require("./parse");
var txToJson_1 = require("./txToJson");
var binary;
(function (binary) {
function serializeTx(tx, longFactory) {
var type = tx.type, version = tx.version;
var schema = getSchema(type, version);
return serialize_1.serializerFromSchema(schema, longFactory)(tx);
}
binary.serializeTx = serializeTx;
/**
* This function cannot transactions without version
*/
function parseTx(bytes, longFactory) {
var _a = parse_1.parseHeader(bytes), type = _a.type, version = _a.version;
var schema = getSchema(type, version);
return parse_1.parserFromSchema(schema, longFactory)(bytes).value;
}
binary.parseTx = parseTx;
function serializeOrder(ord, longFactory) {
var version = ord.version;
var schema = version == 2 ? txSchemas_1.orderSchemaV2 : txSchemas_1.orderSchemaV0;
return serialize_1.serializerFromSchema(schema, longFactory)(ord);
}
binary.serializeOrder = serializeOrder;
/**
* This function cannot parse OrderV1, which doesn't have version field
*/
function parseOrder(bytes, longFactory) {
return parse_1.parserFromSchema(txSchemas_1.orderSchemaV2, longFactory)(bytes).value;
}
binary.parseOrder = parseOrder;
})(binary = exports.binary || (exports.binary = {}));
var json;
(function (json) {
function parseTx(str, lf) {
var safeStr = str.replace(/(".+?"[ \t\n]*:[ \t\n]*)(\d{15,})/gm, '$1"$2"');
var tx = JSON.parse(safeStr);
//ToDo: rewrite. Now simply serializes and then parses with long factory to get right long types
return lf ? convert(tx, lf) : tx;
}
json.parseTx = parseTx;
function stringifyTx(tx) {
var txWithStrings = convert(tx);
//TODO: remove this when contract invocation tx is fixed
if (tx.type === 16) {
txWithStrings = tx;
}
return txToJson_1.txToJson(txWithStrings);
}
json.stringifyTx = stringifyTx;
})(json = exports.json || (exports.json = {}));
function convert(tx, toLf, fromLf) {
var json = require("./jsonMethods");
exports.json = json;
var serializePrimitives = require("./serializePrimitives");
exports.serializePrimitives = serializePrimitives;
var parsePrimitives = require("./parsePrimitives");
exports.parsePrimitives = parsePrimitives;
var schemas = require("./schemas");
exports.schemas = schemas;
var binary = {
serializerFromSchema: serialize_1.serializerFromSchema,
serializeTx: serialize_1.serializeTx,
serializeOrder: serialize_1.serializeOrder,
parserFromSchema: parse_1.parserFromSchema,
parseTx: parse_1.parseTx,
parseOrder: parse_1.parseOrder
};
exports.binary = binary;
function convertLongFields(tx, toLf, fromLf) {
return __assign({}, binary.parseTx(binary.serializeTx(tx, fromLf), toLf), { proofs: tx.proofs });
}
exports.convert = convert;
function getSchema(type, version) {
var schemas = txSchemas_1.schemasByTypeMap[type];
if (typeof schemas !== 'object') {
throw new Error("Incorrect tx type: " + type);
}
var schema = schemas[version || 0];
if (typeof schema !== 'object') {
throw new Error("Incorrect tx version: " + version);
}
return schema;
}
exports.getSchema = getSchema;
exports.convertLongFields = convertLongFields;
//# sourceMappingURL=index.js.map

@@ -26,3 +26,3 @@ "use strict";

else {
codePt = 63; // Cannot convert four byte code points, so use "?" instead
codePt = 63; // Cannot convertLongFields four byte code points, so use "?" instead
i += 3;

@@ -29,0 +29,0 @@ }

@@ -25,2 +25,3 @@ "use strict";

var utils_1 = require("./libs/utils");
var schemas_1 = require("./schemas");
exports.parserFromSchema = function (schema, lf) { return function (bytes, start) {

@@ -119,2 +120,18 @@ if (start === void 0) { start = 0; }

}); };
/**
* This function cannot parse transactions without version
*/
function parseTx(bytes, longFactory) {
var _a = exports.parseHeader(bytes), type = _a.type, version = _a.version;
var schema = schemas_1.getTransactionSchema(type, version);
return exports.parserFromSchema(schema, longFactory)(bytes).value;
}
exports.parseTx = parseTx;
/**
* This function cannot parse OrderV1, which doesn't have version field
*/
function parseOrder(bytes, longFactory) {
return exports.parserFromSchema(schemas_1.orderSchemaV2, longFactory)(bytes).value;
}
exports.parseOrder = parseOrder;
//# sourceMappingURL=parse.js.map

@@ -25,3 +25,3 @@ "use strict";

var utils_1 = require("./libs/utils");
var txSchemas_1 = require("./txSchemas");
var schemas_1 = require("./schemas");
// FixMe: currently longfactory does nothing. Maybe we should remove it altogether

@@ -67,3 +67,3 @@ exports.serializerFromSchema = function (schema, lf) { return function (obj) {

else if (schema.type === 'dataTxField') {
var keyBytes = txSchemas_1.txFields.stringField('').toBytes(obj.key);
var keyBytes = schemas_1.txFields.stringField('').toBytes(obj.key);
var type = obj.type;

@@ -83,2 +83,14 @@ var typeSchema_2 = schema.items.get(type);

}; };
function serializeTx(tx, longFactory) {
var type = tx.type, version = tx.version;
var schema = schemas_1.getTransactionSchema(type, version);
return exports.serializerFromSchema(schema, longFactory)(tx);
}
exports.serializeTx = serializeTx;
function serializeOrder(ord, longFactory) {
var version = ord.version;
var schema = version == 2 ? schemas_1.orderSchemaV2 : schemas_1.orderSchemaV0;
return exports.serializerFromSchema(schema, longFactory)(ord);
}
exports.serializeOrder = serializeOrder;
//# sourceMappingURL=serialize.js.map
{
"version": "0.1.0",
"version": "0.1.1",
"name": "@waves/marshall",
"main": "dist/index.js",
"types": "dist/index.d.ts",
"types": "src/index.ts",
"scripts": {

@@ -12,3 +12,6 @@ "test": "jest",

"contributors": [
"siemarell"
{
"name": "Sergey B",
"email": "siemarell@gmail.com"
}
],

@@ -15,0 +18,0 @@ "license": "MIT",

@@ -1,74 +0,30 @@

import {schemasByTypeMap, ILongFactory, orderSchemaV0, orderSchemaV2,} from "./txSchemas";
import {serializerFromSchema} from "./serialize";
import {parseHeader, parserFromSchema} from "./parse";
import {txToJson} from "./txToJson";
import {ILongFactory} from "./schemas";
import {serializeOrder, serializerFromSchema, serializeTx} from "./serialize";
import {parseOrder, parserFromSchema, parseTx} from "./parse";
import * as json from "./jsonMethods";
import * as serializePrimitives from './serializePrimitives'
import * as parsePrimitives from './parsePrimitives'
import * as schemas from './schemas'
export namespace binary {
export function serializeTx<LONG = string | number>(tx: any, longFactory?: ILongFactory<LONG>): Uint8Array {
const {type, version} = tx;
const schema = getSchema(type, version);
const binary = {
serializerFromSchema,
serializeTx,
serializeOrder,
parserFromSchema,
parseTx,
parseOrder
};
return serializerFromSchema(schema, longFactory)(tx);
}
/**
* This function cannot transactions without version
*/
export function parseTx<LONG = string>(bytes: Uint8Array, longFactory?: ILongFactory<LONG>) {
const {type, version} = parseHeader(bytes);
const schema = getSchema(type, version);
return parserFromSchema(schema, longFactory)(bytes).value;
}
export function serializeOrder<LONG = string | number>(ord: any, longFactory?: ILongFactory<LONG>): Uint8Array {
const { version } = ord;
const schema = version == 2 ? orderSchemaV2 : orderSchemaV0;
return serializerFromSchema(schema, longFactory)(ord);
}
/**
* This function cannot parse OrderV1, which doesn't have version field
*/
export function parseOrder<LONG = string>(bytes: Uint8Array, longFactory?: ILongFactory<LONG>) {
return parserFromSchema(orderSchemaV2, longFactory)(bytes).value;
}
export {
ILongFactory,
json,
binary,
schemas,
serializePrimitives,
parsePrimitives,
convertLongFields
}
export namespace json {
export function parseTx<LONG = string>(str: string, lf?: ILongFactory<LONG>) {
const safeStr = str.replace(/(".+?"[ \t\n]*:[ \t\n]*)(\d{15,})/gm, '$1"$2"');
let tx = JSON.parse(safeStr);
//ToDo: rewrite. Now simply serializes and then parses with long factory to get right long types
return lf ? convert(tx, lf) : tx
}
export function stringifyTx(tx: any): string {
let txWithStrings = convert(tx);
//TODO: remove this when contract invocation tx is fixed
if (tx.type === 16){
txWithStrings = tx
}
return txToJson(txWithStrings)
}
}
export function convert<T = string, R = string>(tx: any, toLf?: ILongFactory<T>, fromLf?: ILongFactory<R>) {
function convertLongFields<T = string, R = string>(tx: any, toLf?: ILongFactory<T>, fromLf?: ILongFactory<R>) {
return {...binary.parseTx(binary.serializeTx(tx, fromLf), toLf), proofs: tx.proofs}
}
export function getSchema(type: number, version?: number) {
const schemas = (<any>schemasByTypeMap)[type];
if (typeof schemas !== 'object') {
throw new Error(`Incorrect tx type: ${type}`)
}
const schema = schemas[version || 0];
if (typeof schema !== 'object') {
throw new Error(`Incorrect tx version: ${version}`)
}
return schema
}

@@ -24,3 +24,3 @@ var utf8ArrayToStr = (function () {

} else {
codePt = 63; // Cannot convert four byte code points, so use "?" instead
codePt = 63; // Cannot convertLongFields four byte code points, so use "?" instead
i += 3;

@@ -27,0 +27,0 @@ }

import {byteToStringWithLength, P_BYTE, P_LONG, P_SHORT, TParser} from "./parsePrimitives";
import {range} from "./libs/utils";
import {ILongFactory, TSchema} from "./txSchemas";
import {getTransactionSchema, ILongFactory, orderSchemaV2} from "./schemas";
import {TSchema} from "./schemaTypes";

@@ -103,1 +104,19 @@ export const parserFromSchema = <LONG = string>(schema: TSchema, lf?: ILongFactory<LONG>): TParser<any> => (bytes: Uint8Array, start = 0) => {

});
/**
* This function cannot parse transactions without version
*/
export function parseTx<LONG = string>(bytes: Uint8Array, longFactory?: ILongFactory<LONG>) {
const {type, version} = parseHeader(bytes);
const schema = getTransactionSchema(type, version);
return parserFromSchema(schema, longFactory)(bytes).value;
}
/**
* This function cannot parse OrderV1, which doesn't have version field
*/
export function parseOrder<LONG = string>(bytes: Uint8Array, longFactory?: ILongFactory<LONG>) {
return parserFromSchema(orderSchemaV2, longFactory)(bytes).value;
}
import {BYTE, LEN, SHORT, TSerializer} from "./serializePrimitives";
import {concat} from "./libs/utils";
import {ILongFactory, TSchema, txFields} from "./txSchemas";
import {ILongFactory, orderSchemaV0, orderSchemaV2, txFields, getTransactionSchema} from "./schemas";
import {TSchema} from "./schemaTypes";

@@ -20,3 +21,3 @@ // FixMe: currently longfactory does nothing. Maybe we should remove it altogether

if (schema.optional && obj == null){
if (schema.optional && obj == null) {
return Uint8Array.from([0])

@@ -65,2 +66,15 @@ }

};
};
export function serializeTx<LONG = string | number>(tx: any, longFactory?: ILongFactory<LONG>): Uint8Array {
const {type, version} = tx;
const schema = getTransactionSchema(type, version);
return serializerFromSchema(schema, longFactory)(tx);
}
export function serializeOrder<LONG = string | number>(ord: any, longFactory?: ILongFactory<LONG>): Uint8Array {
const {version} = ord;
const schema = version == 2 ? orderSchemaV2 : orderSchemaV0;
return serializerFromSchema(schema, longFactory)(ord);
}

@@ -10,3 +10,2 @@ {

"sourceMap": true,
"declaration": true,
"module": "commonjs",

@@ -13,0 +12,0 @@ "outDir": "dist",

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc