This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Event = require("events"); | |
const emitter = new Event(); | |
const eventName = Symbol(); | |
/** | |
* Echos given message to the callback function after a random amount of time | |
* @param {String} message - message that will be echoed back | |
* @param {Function} callback - function the echo will be passed to | |
*/ | |
function belatedEcho(message, callback) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//test suite for math-api.js module, which mocks the api.mathjs.org api responses | |
const | |
{test} = require("tape") | |
, proxyquire = require("proxyquire") | |
, mathjs = require("mathjs") | |
, {URL} = require("url") | |
, requestPromiseStub = { | |
//request-promise stub that tests the argument and mocks the api response | |
"request-promise"(u) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Converts a secp256k1 public key as returned by `GET https://api.tangany.com/v1/wallet/:wallet` to OpenSSL PEM format | |
* @param {string} publicKey - hexadecimal key to convert | |
* @return PEM-formatted representation of given public key | |
* @example | |
* const pem = convertPublicKeyToPEM("04f500418025ba3babca935e9f7617c438210ab72ae3ece0b25e5dff579c31ddd1549ab1ee4f0dcb53e51aacceb15147af6f4a1610040aa8e042a0f3e208496257"); | |
*/ | |
function convertPublicKeyToPEM (publicKey) { | |
let key = Buffer.from(publicKey, "hex"); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const {keccak256} = require("js-sha3"); | |
const assert = require("assert"); | |
/** | |
* Extract the Ethereum address from a secp256k1 public key as returned by `GET https://api.tangany.com/v1/wallet/:wallet` | |
* @param {string | Buffer} pub - secp256k1 public key of the wallet | |
* @return {string} - Ethereum address of the wallet | |
* @example | |
* convertPublicKeyToEthereumAddress("04150341ab9f7b9a3d0eafc6180eac39b65b34da30bddbd13cee1bbdabf4b420b79962342664902c31c3da7376eaf65adeb7dfffccba1de1e11fb6779b428a3c31")); | |
*/ |