Skip to content

Instantly share code, notes, and snippets.

@yura415
Created November 15, 2015 03:25
Show Gist options
  • Save yura415/f8d321bc92f50de242d4 to your computer and use it in GitHub Desktop.
Save yura415/f8d321bc92f50de242d4 to your computer and use it in GitHub Desktop.
requirebin sketch
var bs58 = require('bs58')
var unencodedData = "003c176e659bea0f29a3e9bf7880c112b1b31b4dc826268187"
var out = bs58.encode(new Buffer(unencodedData, 'hex'))
console.log(out) // => 16UjcYNBG9GTK4uq2f7yYEbuifqCzoLMGS
require=function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s}({1:[function(require,module,exports){module.exports=function base(ALPHABET){var ALPHABET_MAP={};var BASE=ALPHABET.length;var LEADER=ALPHABET.charAt(0);for(var i=0;i<ALPHABET.length;i++){ALPHABET_MAP[ALPHABET.charAt(i)]=i}function encode(buffer){if(buffer.length===0)return"";var i,j;var digits=[0];for(i=0;i<buffer.length;i++){for(j=0;j<digits.length;j++)digits[j]<<=8;digits[0]+=buffer[i];var carry=0;for(j=0;j<digits.length;++j){digits[j]+=carry;carry=digits[j]/BASE|0;digits[j]%=BASE}while(carry){digits.push(carry%BASE);carry=carry/BASE|0}}for(i=0;buffer[i]===0&&i<buffer.length-1;i++){digits.push(0)}return digits.reverse().map(function(digit){return ALPHABET[digit]}).join("")}function decode(string){if(string.length===0)return[];var i,j;var bytes=[0];for(i=0;i<string.length;i++){var c=string[i];if(!(c in ALPHABET_MAP))throw new Error("Non-base"+BASE+" character");for(j=0;j<bytes.length;j++)bytes[j]*=BASE;bytes[0]+=ALPHABET_MAP[c];var carry=0;for(j=0;j<bytes.length;++j){bytes[j]+=carry;carry=bytes[j]>>8;bytes[j]&=255}while(carry){bytes.push(carry&255);carry>>=8}}for(i=0;string[i]===LEADER&&i<string.length-1;i++){bytes.push(0)}return bytes.reverse()}return{encode:encode,decode:decode}}},{}],bs58:[function(require,module,exports){var basex=require("base-x");var ALPHABET="123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";var base58=basex(ALPHABET);module.exports={encode:base58.encode,decode:base58.decode}},{"base-x":1}]},{},[]);var bs58=require("bs58");var unencodedData="003c176e659bea0f29a3e9bf7880c112b1b31b4dc826268187";var out=bs58.encode(new Buffer(unencodedData,"hex"));console.log(out);
{
"name": "requirebin-sketch",
"version": "1.0.0",
"dependencies": {
"bs58": "3.0.0"
}
}
<!-- contents of this file will be placed inside the <body> -->
<!-- contents of this file will be placed inside the <head> -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment