Built production version with Base58 and NetBIOS operations. Closes #48.

This commit is contained in:
n1474335 2017-02-13 18:12:55 +00:00
parent 701ea5890d
commit 92bd2c921e
8 changed files with 51 additions and 53 deletions

View file

@ -165,7 +165,7 @@ var OperationConfig = {
]
},
"From Base58": {
description: "Base58 (similar to Base64) is a notation for encoding arbitrary byte data. It improves upon Base64 by removing easily misread characters (i.e. lI0O) to improve human readability.<br><br>This operation decodes data from an ASCII string (with an alphabet of your choosing, presets included) back into its raw form.<br><br>e.g. <code>StV1DL6CwTryKyV</code> becomes <code>hello world</code><br><br>Base58 is commonly used in cryptocurrencies (Bitcoin, Ripple, etc).",
description: "Base58 (similar to Base64) is a notation for encoding arbitrary byte data. It differs from Base64 by removing easily misread characters (i.e. l, I, 0 and O) to improve human readability.<br><br>This operation decodes data from an ASCII string (with an alphabet of your choosing, presets included) back into its raw form.<br><br>e.g. <code>StV1DL6CwTryKyV</code> becomes <code>hello world</code><br><br>Base58 is commonly used in cryptocurrencies (Bitcoin, Ripple, etc).",
run: Base58.runFrom,
inputType: "string",
outputType: "byteArray",
@ -183,7 +183,7 @@ var OperationConfig = {
]
},
"To Base58": {
description: "Base58 (similar to Base64) is a notation for encoding arbitrary byte data. It improves upon Base64 by removing easily misread characters (i.e. lI0O) to improve human readability.<br><br>This operation encodes data in an ASCII string (with an alphabet of your choosing, presets included).<br><br>e.g. <code>hello world</code> becomes <code>StV1DL6CwTryKyV</code><br><br>Base58 is commonly used in cryptocurrencies (Bitcoin, Ripple, etc).",
description: "Base58 (similar to Base64) is a notation for encoding arbitrary byte data. It differs from Base64 by removing easily misread characters (i.e. l, I, 0 and O) to improve human readability.<br><br>This operation encodes data in an ASCII string (with an alphabet of your choosing, presets included).<br><br>e.g. <code>hello world</code> becomes <code>StV1DL6CwTryKyV</code><br><br>Base58 is commonly used in cryptocurrencies (Bitcoin, Ripple, etc).",
run: Base58.runTo,
inputType: "byteArray",
outputType: "string",

View file

@ -9,7 +9,6 @@
*/
var Base58 = {
/**
* @constant
* @default
@ -24,15 +23,12 @@ var Base58 = {
value: "rpshnaf39wBUDNEGHJKLM4PQRST7VWXYZ2bcdeCg65jkm8oFqi1tuvAxyz",
},
],
/**
* @constant
* @default
*/
REMOVE_NON_ALPH_CHARS: true,
/**
* To Base58 operation.
*
@ -41,7 +37,10 @@ var Base58 = {
* @returns {string}
*/
runTo: function(input, args) {
var alphabet = args[0] || Base58.ALPHABET_OPTIONS[0].value;
var alphabet = args[0] || Base58.ALPHABET_OPTIONS[0].value,
result = [0];
alphabet = Utils.expandAlphRange(alphabet).join("");
if (alphabet.length !== 58 ||
[].unique.call(alphabet).length !== 58) {
@ -50,8 +49,6 @@ var Base58 = {
if (input.length === 0) return "";
var result = [0];
input.forEach(function(b) {
var carry = (result[0] << 8) + b;
result[0] = carry % 58;
@ -89,21 +86,19 @@ var Base58 = {
* @returns {byteArray}
*/
runFrom: function(input, args) {
var alphabet = args[0] || Base58.ALPHABET_OPTIONS[0].value;
var alphabet = args[0] || Base58.ALPHABET_OPTIONS[0].value,
removeNonAlphaChars = args[1] === undefined ? true : args[1],
result = [0];
alphabet = Utils.expandAlphRange(alphabet).join("");
if (alphabet.length !== 58 ||
[].unique.call(alphabet).length !== 58) {
throw ("Alphabet must be of length 58");
}
var removeNonAlphaChars = args[1];
if (removeNonAlphaChars === undefined)
removeNonAlphaChars = true;
if (input.length === 0) return [];
var result = [0];
[].forEach.call(input, function(c, charIndex) {
var index = alphabet.indexOf(c);
@ -111,7 +106,7 @@ var Base58 = {
if (removeNonAlphaChars) {
return;
} else {
throw ("Char " + c + " not in alphabet");
throw ("Char '" + c + "' at position " + charIndex + " not in alphabet");
}
}
@ -133,4 +128,5 @@ var Base58 = {
return result.reverse();
},
};