Comparing version 1.2.96 to 1.2.97
"use strict"; | ||
exports.__esModule = true; | ||
exports.Login = exports.FetchChain = exports.ChainValidation = exports.TransactionHelper = exports.NumberUtils = exports.ObjectId = exports.EmitterInstance = exports.ChainTypes = exports.FetchChainObjects = exports.TransactionBuilder = exports.ChainStore = exports.ECSignature = exports.key = exports.hash = exports.brainKey = exports.Signature = exports.PublicKey = exports.PrivateKey = exports.Aes = exports.Address = exports.SerializerValidation = exports.template = exports.ops = exports.types = exports.fp = exports.Serializer = undefined; | ||
exports.Login = exports.FetchChain = exports.ChainValidation = exports.TransactionHelper = exports.NumberUtils = exports.ObjectId = exports.EmitterInstance = exports.ChainTypes = exports.FetchChainObjects = exports.TransactionBuilder = exports.ChainStore = exports.ECSignature = exports.key = exports.hash = exports.brainKey = exports.Signature = exports.PublicKey = exports.PrivateKey = exports.Aes = exports.Address = exports.string_to_name = exports.name_to_string = exports.SerializerValidation = exports.template = exports.ops = exports.types = exports.fp = exports.Serializer = undefined; | ||
@@ -14,3 +14,3 @@ var _serializer = require("./serializer/src/serializer"); | ||
var _types = require("./serializer/src/types"); | ||
var _types = require("./src/types"); | ||
@@ -107,2 +107,3 @@ var _types2 = _interopRequireDefault(_types); | ||
/* ECC */ | ||
/* Serializer */ | ||
@@ -115,5 +116,6 @@ exports.Serializer = _serializer2.default; | ||
exports.SerializerValidation = _SerializerValidation2.default; | ||
exports.name_to_string = _types.name_to_string; | ||
exports.string_to_name = _types.string_to_name; | ||
/* Chain */ | ||
/* ECC */ | ||
exports.Address = _address2.default; | ||
@@ -128,5 +130,2 @@ exports.Aes = _aes2.default; | ||
exports.ECSignature = _ecsignature2.default; | ||
/* Chain */ | ||
var FetchChainObjects = _ChainStore2.default.FetchChainObjects, | ||
@@ -133,0 +132,0 @@ FetchChain = _ChainStore2.default.FetchChain; |
"use strict"; | ||
exports.__esModule = true; | ||
exports.SerializerValidation = exports.template = exports.ops = exports.types = exports.fp = exports.Serializer = undefined; | ||
exports.object_id_type = exports.name_to_string = exports.string_to_name = exports.SerializerValidation = exports.template = exports.ops = exports.types = exports.fp = exports.Serializer = undefined; | ||
@@ -39,2 +39,5 @@ var _serializer = require("./src/serializer"); | ||
exports.template = _template2.default; | ||
exports.SerializerValidation = _SerializerValidation2.default; | ||
exports.SerializerValidation = _SerializerValidation2.default; | ||
exports.string_to_name = _types.string_to_name; | ||
exports.name_to_string = _types.name_to_string; | ||
exports.object_id_type = _types.object_id_type; |
'use strict'; | ||
exports.__esModule = true; | ||
exports.name_to_string = exports.string_to_name = undefined; | ||
exports.object_id_type = exports.name_to_string = exports.string_to_name = undefined; | ||
@@ -949,2 +949,14 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; // Low-level types that make up operations | ||
/** | ||
* convert 1.2.* to object_id_type, which will be used in smart contract | ||
* @param account_id_str | ||
* @returns {Long} | ||
*/ | ||
var object_id_type = exports.object_id_type = function object_id_type(account_id_str) { | ||
var account_id = account_id_str.split('.').map(function (i) { | ||
return _SerializerValidation2.default.to_long(i); | ||
}); | ||
return account_id[0].shiftLeft(56).or(account_id[1].shiftLeft(48)).or(account_id[2]); | ||
}; | ||
var strCmp = function strCmp(a, b) { | ||
@@ -951,0 +963,0 @@ return a > b ? 1 : a < b ? -1 : 0; |
/* Serializer */ | ||
import Serializer from "./serializer/src/serializer"; | ||
import fp from "./serializer/src/FastParser"; | ||
import types from "./serializer/src/types"; | ||
import types, { name_to_string, string_to_name } from "./src/types"; | ||
import * as ops from "./serializer/src/operations"; | ||
import template from "./serializer/src/template"; | ||
import SerializerValidation from "./serializer/src/SerializerValidation"; | ||
export { Serializer, fp, types, ops, template, SerializerValidation }; | ||
/* ECC */ | ||
@@ -21,5 +18,2 @@ import Address from "./ecc/src/address"; | ||
import key from "./ecc/src/KeyUtils"; | ||
export { Address, Aes, PrivateKey, PublicKey, Signature, brainKey, hash, key, ECSignature }; | ||
/* Chain */ | ||
@@ -36,2 +30,6 @@ import ChainStore from "./chain/src/ChainStore"; | ||
export { Serializer, fp, types, ops, template, SerializerValidation, name_to_string, string_to_name }; | ||
export { Address, Aes, PrivateKey, PublicKey, Signature, brainKey, hash, key, ECSignature }; | ||
var FetchChainObjects = ChainStore.FetchChainObjects, | ||
@@ -38,0 +36,0 @@ FetchChain = ChainStore.FetchChain; |
import Serializer from "./src/serializer"; | ||
import fp from "./src/FastParser"; | ||
import types from "./src/types"; | ||
import types, { name_to_string, object_id_type, string_to_name } from "./src/types"; | ||
import * as ops from "./src/operations"; | ||
@@ -8,2 +8,2 @@ import template from "./src/template"; | ||
export { Serializer, fp, types, ops, template, SerializerValidation }; | ||
export { Serializer, fp, types, ops, template, SerializerValidation, string_to_name, name_to_string, object_id_type }; |
@@ -933,2 +933,14 @@ var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; | ||
/** | ||
* convert 1.2.* to object_id_type, which will be used in smart contract | ||
* @param account_id_str | ||
* @returns {Long} | ||
*/ | ||
export var object_id_type = function object_id_type(account_id_str) { | ||
var account_id = account_id_str.split('.').map(function (i) { | ||
return v.to_long(i); | ||
}); | ||
return account_id[0].shiftLeft(56).or(account_id[1].shiftLeft(48)).or(account_id[2]); | ||
}; | ||
var strCmp = function strCmp(a, b) { | ||
@@ -935,0 +947,0 @@ return a > b ? 1 : a < b ? -1 : 0; |
@@ -1,50 +0,8 @@ | ||
import v from '../lib/serializer/src/SerializerValidation'; | ||
import {name_to_string, object_id_type, string_to_name} from "../lib/serializer"; | ||
const char_to_symbol = (c) => { | ||
let result = 0; | ||
if (c >= 'a'.charCodeAt(0) && c <= 'z'.charCodeAt(0)) | ||
result = (c - 'a'.charCodeAt(0)) + 6; | ||
if (c >= '1'.charCodeAt(0) && c <= '5'.charCodeAt(0)) | ||
result = (c - '1'.charCodeAt(0)) + 1; | ||
return result; | ||
}; | ||
const string_to_name = (str) => { | ||
var name = v.to_long(0).toUnsigned(); | ||
var i = 0; | ||
for (; str[i] && i < 12; ++i) { | ||
// NOTE: char_to_symbol() returns char type, and without this explicit | ||
// expansion to uint64 type, the compilation fails at the point of usage | ||
// of string_to_name(), where the usage requires constant (compile time) expression. | ||
let symbol = v.to_long(char_to_symbol(str[i].charCodeAt(0))).toUnsigned().and(0x1f); | ||
name = name.or(symbol.shiftLeft(64 - 5 * (i + 1))); | ||
} | ||
// The for-loop encoded up to 60 high bits into uint64 'name' variable, | ||
// if (strlen(str) > 12) then encode str[12] into the low (remaining) | ||
// 4 bits of 'name' | ||
if (i == 12) { | ||
let symbol = v.to_long(char_to_symbol(str[12].charCodeAt(0))).toUnsigned(); | ||
name = name.or(symbol.and(0x0F)); | ||
} | ||
return name; | ||
}; | ||
const name_to_string = (name) => { | ||
let charmap = ".12345abcdefghijklmnopqrstuvwxyz"; | ||
let str = []; | ||
let tmp = name; | ||
for (var i = 0; i <= 12; ++i) { | ||
let index = tmp.and(i == 0 ? 0x0f : 0x1f).toInt(); | ||
let c = charmap[index]; | ||
str.push(c); | ||
tmp = tmp.shiftRightUnsigned(i == 0 ? 4 : 5); | ||
} | ||
return str.reverse().join('').replace(/\.+$/g, ''); | ||
}; | ||
console.log(string_to_name('subbalance').toString()); | ||
console.log(name_to_string(string_to_name('subbalance'))); | ||
console.log(object_id_type("1.2.576").toString()); | ||
{ | ||
"name": "gxbjs", | ||
"version": "1.2.96", | ||
"version": "1.2.97", | ||
"description": "Pure JavaScript GXB library for node.js and browsers.", | ||
@@ -5,0 +5,0 @@ "browser": { |
585214
12728