webpack bundle and changed requires to imports
This commit is contained in:
parent
5e1249f44e
commit
759492dcdf
10 changed files with 4374 additions and 38 deletions
|
|
@ -1,8 +1,10 @@
|
|||
.git/
|
||||
node_modules/
|
||||
test/
|
||||
src/
|
||||
.gitignore
|
||||
.editorconfig
|
||||
.travis.yml
|
||||
src
|
||||
tsconfig.json
|
||||
webpack.config.json
|
||||
tsconfig.json
|
||||
package-lock.json
|
||||
|
|
|
|||
|
|
@ -1,5 +1,7 @@
|
|||
# nanocurrency-web
|
||||
[](https://travis-ci.org/numsu/nanocurrency-web-js)
|
||||
[](https://github.com/numsu/nanocurrency-web-js/blob/master/LICENSE)
|
||||
[](https://badge.fury.io/js/nanocurrency-web)
|
||||
|
||||
Toolkit for Nano cryptocurrency client side offline implementations allowing you to build web- and mobile applications using Nano without compromising the user's keys by sending them out of their own device.
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { Convert } from './util/convert'
|
||||
|
||||
const CryptoJS = require('crypto-js')
|
||||
//@ts-ignore
|
||||
import { enc, algo } from 'crypto-js'
|
||||
|
||||
const ED25519_CURVE = 'ed25519 seed'
|
||||
const HARDENED_OFFSET = 0x80000000
|
||||
|
|
@ -30,8 +31,8 @@ export default class Bip32KeyDerivation {
|
|||
|
||||
private getKeyFromSeed = (): Chain => {
|
||||
return this.derive(
|
||||
CryptoJS.enc.Hex.parse(this.seed),
|
||||
CryptoJS.enc.Utf8.parse(ED25519_CURVE))
|
||||
enc.Hex.parse(this.seed),
|
||||
enc.Utf8.parse(ED25519_CURVE))
|
||||
}
|
||||
|
||||
private CKDPriv = ({ key, chainCode }: Chain, index: number) => {
|
||||
|
|
@ -43,12 +44,12 @@ export default class Bip32KeyDerivation {
|
|||
const data = '00' + key + Convert.ab2hex(new Uint8Array(ib).buffer)
|
||||
|
||||
return this.derive(
|
||||
CryptoJS.enc.Hex.parse(data),
|
||||
CryptoJS.enc.Hex.parse(chainCode))
|
||||
enc.Hex.parse(data),
|
||||
enc.Hex.parse(chainCode))
|
||||
}
|
||||
|
||||
private derive = (data: string, base: string): Chain => {
|
||||
const hmac = CryptoJS.algo.HMAC.create(CryptoJS.algo.SHA512, base)
|
||||
const hmac = algo.HMAC.create(algo.SHA512, base)
|
||||
const I = hmac.update(data).finalize().toString()
|
||||
const IL = I.slice(0, I.length / 2)
|
||||
const IR = I.slice(I.length / 2)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,8 @@ import words from './words'
|
|||
import { Util } from './util/util'
|
||||
import { Convert } from './util/convert'
|
||||
|
||||
const CryptoJS = require('crypto-js')
|
||||
//@ts-ignore
|
||||
import { algo, enc, lib, PBKDF2, SHA256 } from 'crypto-js'
|
||||
|
||||
export default class Bip39Mnemonic {
|
||||
|
||||
|
|
@ -82,23 +83,23 @@ export default class Bip39Mnemonic {
|
|||
const normalizedMnemonic = Util.normalizeUTF8(mnemonic)
|
||||
const normalizedPassword = 'mnemonic' + Util.normalizeUTF8(this.password)
|
||||
|
||||
return CryptoJS.PBKDF2(
|
||||
return PBKDF2(
|
||||
normalizedMnemonic,
|
||||
normalizedPassword,
|
||||
{
|
||||
keySize: 512 / 32,
|
||||
iterations: 2048,
|
||||
hasher: CryptoJS.algo.SHA512,
|
||||
hasher: algo.SHA512,
|
||||
})
|
||||
.toString(CryptoJS.enc.Hex)
|
||||
.toString(enc.Hex)
|
||||
}
|
||||
|
||||
private randomHex = (length: number): string => {
|
||||
return CryptoJS.lib.WordArray.random(length / 2).toString()
|
||||
return lib.WordArray.random(length / 2).toString()
|
||||
}
|
||||
|
||||
private calculateChecksum = (entropyHex: string): string => {
|
||||
const entropySha256 = CryptoJS.SHA256(CryptoJS.enc.Hex.parse(entropyHex)).toString()
|
||||
const entropySha256 = SHA256(enc.Hex.parse(entropyHex)).toString()
|
||||
return entropySha256.substr(0, entropySha256.length / 32)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,7 +4,8 @@ import { NanoAddress } from './nano-address'
|
|||
import NanoConverter from './nano-converter'
|
||||
import { Convert } from './util/convert'
|
||||
|
||||
const blake = require('blakejs')
|
||||
//@ts-ignore
|
||||
import { blake2b, blake2bInit, blake2bUpdate, blake2bFinal } from 'blakejs'
|
||||
|
||||
export default class BlockSigner {
|
||||
|
||||
|
|
@ -44,14 +45,14 @@ export default class BlockSigner {
|
|||
}
|
||||
|
||||
private generateHash(preamble: string, account: string, previous: string, representative: string, balance: string, link: string) {
|
||||
const ctx = blake.blake2bInit(32, undefined)
|
||||
blake.blake2bUpdate(ctx, Convert.hex2ab(preamble))
|
||||
blake.blake2bUpdate(ctx, Convert.hex2ab(account))
|
||||
blake.blake2bUpdate(ctx, Convert.hex2ab(previous))
|
||||
blake.blake2bUpdate(ctx, Convert.hex2ab(representative))
|
||||
blake.blake2bUpdate(ctx, Convert.hex2ab(balance))
|
||||
blake.blake2bUpdate(ctx, Convert.hex2ab(link))
|
||||
return blake.blake2bFinal(ctx)
|
||||
const ctx = blake2bInit(32, undefined)
|
||||
blake2bUpdate(ctx, Convert.hex2ab(preamble))
|
||||
blake2bUpdate(ctx, Convert.hex2ab(account))
|
||||
blake2bUpdate(ctx, Convert.hex2ab(previous))
|
||||
blake2bUpdate(ctx, Convert.hex2ab(representative))
|
||||
blake2bUpdate(ctx, Convert.hex2ab(balance))
|
||||
blake2bUpdate(ctx, Convert.hex2ab(link))
|
||||
return blake2bFinal(ctx)
|
||||
}
|
||||
|
||||
private nanoAddressToHexString(addr: string): string {
|
||||
|
|
@ -60,7 +61,7 @@ export default class BlockSigner {
|
|||
if (isValid) {
|
||||
const keyBytes = this.nanoAddress.decodeNanoBase32(addr.substring(0, 52))
|
||||
const hashBytes = this.nanoAddress.decodeNanoBase32(addr.substring(52, 60))
|
||||
const blakeHash = blake.blake2b(keyBytes, undefined, 5).reverse()
|
||||
const blakeHash = blake2b(keyBytes, undefined, 5).reverse()
|
||||
if (Convert.ab2hex(hashBytes) == Convert.ab2hex(blakeHash)) {
|
||||
const key = Convert.ab2hex(keyBytes).toUpperCase()
|
||||
return key
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
import { Convert } from './util/convert'
|
||||
import { Curve25519 } from './util/curve25519'
|
||||
|
||||
const blake = require('blakejs')
|
||||
//@ts-ignore
|
||||
import { blake2b } from 'blakejs'
|
||||
|
||||
export class Ed25519 {
|
||||
|
||||
|
|
@ -101,9 +102,7 @@ export class Ed25519 {
|
|||
generateKeys(seed: string): KeyPair {
|
||||
const pk = new Uint8Array(32)
|
||||
const p = [this.curve.gf(), this.curve.gf(), this.curve.gf(), this.curve.gf()]
|
||||
const h = blake
|
||||
.blake2b(Convert.hex2ab(seed), undefined, 64)
|
||||
.slice(0, 32)
|
||||
const h = blake2b(Convert.hex2ab(seed), undefined, 64).slice(0, 32)
|
||||
|
||||
h[0] &= 0xf8
|
||||
h[31] &= 0x7f
|
||||
|
|
@ -210,7 +209,7 @@ export class Ed25519 {
|
|||
input[i] = m[i]
|
||||
}
|
||||
|
||||
const hash = blake.blake2b(input)
|
||||
const hash = blake2b(input)
|
||||
for (let i = 0; i < 64; ++i) {
|
||||
out[i] = hash[i]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { Convert } from './util/convert'
|
||||
|
||||
const blake = require('blakejs')
|
||||
//@ts-ignore
|
||||
import { blake2b } from 'blakejs'
|
||||
|
||||
export class NanoAddress {
|
||||
|
||||
|
|
@ -9,10 +10,7 @@ export class NanoAddress {
|
|||
|
||||
deriveAddress = (publicKey: string): string => {
|
||||
const publicKeyBytes = Convert.hex2ab(publicKey)
|
||||
const checksum = blake
|
||||
.blake2b(publicKeyBytes, undefined, 5)
|
||||
.reverse()
|
||||
|
||||
const checksum = blake2b(publicKeyBytes, undefined, 5).reverse()
|
||||
const encoded = this.encodeNanoBase32(publicKeyBytes)
|
||||
const encodedChecksum = this.encodeNanoBase32(checksum)
|
||||
|
||||
|
|
|
|||
4300
package-lock.json
generated
4300
package-lock.json
generated
File diff suppressed because it is too large
Load diff
17
package.json
17
package.json
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "nanocurrency-web",
|
||||
"version": "1.0.1",
|
||||
"version": "1.0.2",
|
||||
"description": "Toolset for Nano cryptocurrency client side offline integrations",
|
||||
"author": "Miro Metsänheimo <miro@metsanheimo.fi>",
|
||||
"license": "MIT",
|
||||
|
|
@ -12,10 +12,18 @@
|
|||
"bugs": {
|
||||
"url": "https://github.com/numsu/nanocurrency-web-js/issues"
|
||||
},
|
||||
"keywords": [
|
||||
"nano",
|
||||
"currency",
|
||||
"mnemonic",
|
||||
"crypto"
|
||||
],
|
||||
"main": "dist/index.js",
|
||||
"types": "dist/index.d.ts",
|
||||
"unpkg": "dist/index.min.js",
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"build": "tsc && npm run build:webpack",
|
||||
"build:webpack": "webpack",
|
||||
"test": "mocha --reporter spec"
|
||||
},
|
||||
"dependencies": {
|
||||
|
|
@ -27,6 +35,9 @@
|
|||
"@types/node": "12.7.12",
|
||||
"chai": "4.2.0",
|
||||
"mocha": "6.2.1",
|
||||
"typescript": "3.6.3"
|
||||
"ts-loader": "6.2.0",
|
||||
"typescript": "3.6.3",
|
||||
"webpack": "4.41.1",
|
||||
"webpack-cli": "3.3.9"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
23
webpack.config.js
Normal file
23
webpack.config.js
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
const path = require('path')
|
||||
|
||||
module.exports = {
|
||||
entry: './index.ts',
|
||||
mode: 'production',
|
||||
module: {
|
||||
rules: [
|
||||
{
|
||||
test: /\.ts?$/,
|
||||
use: 'ts-loader',
|
||||
exclude: /node_modules/,
|
||||
},
|
||||
],
|
||||
},
|
||||
resolve: {
|
||||
extensions: ['.ts', '.js', '.json'],
|
||||
},
|
||||
output: {
|
||||
filename: 'index.min.js',
|
||||
path: path.resolve(__dirname, 'dist'),
|
||||
libraryTarget: 'commonjs2',
|
||||
},
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue