bitauth / libauth

An ultra-lightweight, zero-dependency TypeScript library for Bitcoin Cash, Bitcoin, and Bitauth applications.

Home Page:https://libauth.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Simple node 12 example

mattcollier opened this issue · comments

The following works with node 12.14.0.

// index.mjs
import bitcoints from 'bitcoin-ts';
import crypto from 'crypto';

/*
import { instantiateSha256 } from 'bitcoin-ts';
produces error: 
import { instantiateSha256 } from 'bitcoin-ts';
         ^^^^^^^^^^^^^^^^^
SyntaxError: The requested module 'bitcoin-ts' does not provide an export named 'instantiateSha256'
*/

(async () => {
  const b = Buffer.from('hello');
  const bitcoinSha256 = await bitcoints.instantiateSha256();
  console.log('bitcoin-ts', Buffer.from(bitcoinSha256.hash(b)).toString('hex'));
  const nodeSha256 = crypto.createHash('sha256').update(b).digest('hex');
  console.log('nodecrypto', nodeSha256);
})();
node --experimental-modules index.mjs