parent
ced82b14ec
commit
8a6f7022ea
@ -0,0 +1,25 @@ |
||||
const { task } = require('gulp'); |
||||
const del = require('del'); |
||||
|
||||
const packages = ['harmony-crypto']; |
||||
|
||||
task('cleanBrowser', async () => { |
||||
await packages.map((p) => { |
||||
const pathToLib = `packages/${p}/lib`; |
||||
return del.sync([pathToLib]); |
||||
}); |
||||
}); |
||||
|
||||
task('cleanServer', async () => { |
||||
await packages.map((p) => { |
||||
const pathToLib = `packages/${p}/node`; |
||||
return del.sync([pathToLib]); |
||||
}); |
||||
}); |
||||
|
||||
task('cleanDocs', async () => { |
||||
await packages.map((p) => { |
||||
const pathToLib = `packages/${p}/doc`; |
||||
return del.sync([pathToLib]); |
||||
}); |
||||
}); |
@ -0,0 +1 @@ |
||||
export { randomBytes } from './random'; |
@ -0,0 +1,29 @@ |
||||
/** |
||||
* @function randomBytes |
||||
* @description Uses JS-native CSPRNG to generate a specified number of bytes. |
||||
* NOTE: this method throws if no PRNG is available. |
||||
* @param {Number} bytes bytes number to generate |
||||
* @return {String} ramdom hex string |
||||
*/ |
||||
export const randomBytes = (bytes: number): string => { |
||||
let randBz: number[] | Uint8Array; |
||||
|
||||
if ( |
||||
typeof window !== 'undefined' && |
||||
window.crypto && |
||||
window.crypto.getRandomValues |
||||
) { |
||||
randBz = window.crypto.getRandomValues(new Uint8Array(bytes)); |
||||
} else if (typeof require !== 'undefined') { |
||||
randBz = require('crypto').randomBytes(bytes); |
||||
} else { |
||||
throw new Error('Unable to generate safe random numbers.'); |
||||
} |
||||
|
||||
let randStr = ''; |
||||
for (let i = 0; i < bytes; i += 1) { |
||||
randStr += `00${randBz[i].toString(16)}`.slice(-2); |
||||
} |
||||
|
||||
return randStr; |
||||
}; |
@ -0,0 +1,56 @@ |
||||
<!DOCTYPE html> |
||||
<html> |
||||
<head> |
||||
<meta charset="utf-8" /> |
||||
<meta name="apple-mobile-web-app-capable" content="yes" /> |
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black" /> |
||||
<meta name="format-detection" content="telephone=no" /> |
||||
<meta name="format-detection" content="email=no" /> |
||||
<meta |
||||
name="viewport" |
||||
content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no" |
||||
/> |
||||
<title></title> |
||||
</head> |
||||
<style> |
||||
#nodeUrl, |
||||
#address { |
||||
width: 250px; |
||||
height: 50px; |
||||
font-size: 16px; |
||||
} |
||||
|
||||
#setProviderButton, |
||||
#getBlanceButton { |
||||
width: 100px; |
||||
height: 50px; |
||||
margin-left: 16px; |
||||
background: rgba(0, 0, 0, 1); |
||||
color: #ffffff; |
||||
} |
||||
</style> |
||||
|
||||
<body> |
||||
<div id="root"> |
||||
<h1> |
||||
This is Laksa.js simple example, load this html in latest chrome please |
||||
</h1> |
||||
|
||||
<h3>Current Provider is:</h3> |
||||
<h4 id="currentProvider"></h4> |
||||
<input id="nodeUrl" type="text" value="https://api-scilla.zilliqa.com" /> |
||||
<button id="setProviderButton">Set Provider</button> |
||||
<h3>Input address, and get balance of it</h3> |
||||
<input id="address" type="text" /> |
||||
<button id="getBlanceButton">Get Balance</button> |
||||
<div> |
||||
<span>balance:</span><span id="balance"></span> <span>nonce:</span |
||||
><span id="nonce"></span> |
||||
</div> |
||||
<div id="code"></div> |
||||
</div> |
||||
<script src="../lib/index.js"></script> |
||||
|
||||
|
||||
</body> |
||||
</html> |
@ -0,0 +1,31 @@ |
||||
export default { |
||||
babelrc: false, |
||||
runtimeHelpers: true, |
||||
presets: [ |
||||
[ |
||||
'@babel/env', |
||||
{ |
||||
modules: false, |
||||
targets: { |
||||
browsers: ['>0.25%'] |
||||
}, |
||||
useBuiltIns: 'usage' |
||||
} |
||||
] |
||||
], |
||||
plugins: [ |
||||
['@babel/transform-runtime'], |
||||
'@babel/proposal-object-rest-spread', |
||||
'@babel/proposal-export-default-from', |
||||
'@babel/proposal-export-namespace-from', |
||||
[ |
||||
'@babel/plugin-proposal-decorators', |
||||
{ |
||||
legacy: true |
||||
} |
||||
], |
||||
'@babel/proposal-class-properties', |
||||
'add-module-exports' |
||||
], |
||||
exclude: 'packages/**/node_modules/**' |
||||
} |
@ -0,0 +1,31 @@ |
||||
export default { |
||||
babelrc: false, |
||||
// runtimeHelpers: true,
|
||||
presets: [ |
||||
[ |
||||
'@babel/env', |
||||
{ |
||||
modules: false, |
||||
targets: { |
||||
node: 'current' |
||||
} |
||||
} |
||||
] |
||||
], |
||||
|
||||
plugins: [ |
||||
// ['@babel/transform-runtime'],
|
||||
'@babel/proposal-object-rest-spread', |
||||
'@babel/proposal-export-default-from', |
||||
'@babel/proposal-export-namespace-from', |
||||
[ |
||||
'@babel/plugin-proposal-decorators', |
||||
{ |
||||
legacy: true |
||||
} |
||||
], |
||||
'@babel/proposal-class-properties', |
||||
'add-module-exports' |
||||
], |
||||
exclude: 'packages/**/node_modules/**' |
||||
} |
@ -0,0 +1,18 @@ |
||||
module.exports = { |
||||
babelrc: false, |
||||
presets: ['@babel/env'], |
||||
plugins: [ |
||||
['@babel/transform-runtime'], |
||||
'@babel/proposal-object-rest-spread', |
||||
'@babel/proposal-export-default-from', |
||||
'@babel/proposal-export-namespace-from', |
||||
[ |
||||
'@babel/plugin-proposal-decorators', |
||||
{ |
||||
legacy: true |
||||
} |
||||
], |
||||
'@babel/proposal-class-properties', |
||||
'add-module-exports' |
||||
] |
||||
} |
@ -0,0 +1,19 @@ |
||||
module.exports = { |
||||
babelrc: false, |
||||
presets: ['@babel/env'], |
||||
plugins: [ |
||||
['@babel/transform-runtime'], |
||||
'@babel/proposal-object-rest-spread', |
||||
'@babel/proposal-export-default-from', |
||||
'@babel/proposal-export-namespace-from', |
||||
[ |
||||
'@babel/plugin-proposal-decorators', |
||||
{ |
||||
legacy: true |
||||
} |
||||
], |
||||
'@babel/proposal-class-properties', |
||||
'add-module-exports' |
||||
], |
||||
sourceMaps: 'inline' |
||||
} |
@ -0,0 +1,35 @@ |
||||
const { readdirSync, statSync } = require('fs') |
||||
const { join } = require('path') |
||||
const baseConfig = require('./jest.src.config') |
||||
|
||||
// Find all folders in packages/* with package.json
|
||||
const packagesRoot = join(__dirname, '..', '..', 'packages') |
||||
const packages = readdirSync(packagesRoot).filter(dir => { |
||||
if (dir.charAt(0) === '.') { |
||||
return false |
||||
} |
||||
if (dir === 'events') { |
||||
// There's an actual Node package called "events"
|
||||
// that's used by jsdom so we don't want to alias that.
|
||||
return false |
||||
} |
||||
const packagePath = join(packagesRoot, dir, 'package.json') |
||||
return statSync(packagePath).isFile() |
||||
}) |
||||
// Create a module map to point packages to the build output
|
||||
const moduleNameMapper = {} |
||||
packages.forEach(name => { |
||||
// Root entry point
|
||||
moduleNameMapper[`^${name}$`] = `<rootDir>/packages/${name}/lib/index.js` |
||||
// Named entry points
|
||||
// moduleNameMapper[`^${name}/(.*)$`] = `<rootDir>/dist/node_modules/${name}/$1`
|
||||
}) |
||||
|
||||
module.exports = Object.assign({}, baseConfig, { |
||||
// Redirect imports to the compiled bundles
|
||||
moduleNameMapper, |
||||
// Don't run bundle tests on blacklisted -test.internal.* files
|
||||
testPathIgnorePatterns: ['/node_modules/', '-test.internal.js$'], |
||||
// Exclude the build output from transforms
|
||||
transformIgnorePatterns: ['/node_modules/', '<rootDir>/build/'] |
||||
}) |
@ -0,0 +1,4 @@ |
||||
const { matchersWithOptions } = require('jest-json-schema') |
||||
|
||||
expect.extend(matchersWithOptions({ allErrors: true })) |
||||
jest.setTimeout(180000) |
@ -0,0 +1,3 @@ |
||||
global.fetch = require('jest-fetch-mock') |
||||
|
||||
window.fetch = global.fetch |
@ -0,0 +1,50 @@ |
||||
const config = { |
||||
transform: { |
||||
'^.+\\.(t|j)s$': require.resolve('./transformer.js') |
||||
}, |
||||
testMatch: [ |
||||
'<rootDir>/packages/**/__test__/?(*.)+(spec|test).js' |
||||
// '<rootDir>/packages/laksa-account/__test__/?(*.)+(spec|test).js',
|
||||
// '<rootDir>/packages/laksa-blockchain/__test__/?(*.)+(spec|test).js',
|
||||
// '<rootDir>/packages/laksa-core/__test__/?(*.)+(spec|test).js'
|
||||
// '<rootDir>/packages/laksa-core-contract/__test__/?(*.)+(spec|test).js'
|
||||
// '<rootDir>/packages/laksa-core-crypto/__test__/?(*.)+(spec|test).js',
|
||||
// '<rootDir>/packages/laksa-core-messenger/__test__/?(*.)+(spec|test).js'
|
||||
// '<rootDir>/packages/laksa-core-provider/__test__/?(*.)+(spec|test).js',
|
||||
// '<rootDir>/packages/laksa-core-transaction/__test__/?(*.)+(spec|test).js',
|
||||
// '<rootDir>/packages/laksa-extend-keystore/__test__/?(*.)+(spec|test).js',
|
||||
// '<rootDir>/packages/laksa-providers-http/__test__/?(*.)+(spec|test).js',
|
||||
// '<rootDir>/packages/laksa-shared/__test__/?(*.)+(spec|test).js'
|
||||
// '<rootDir>/packages/laksa-utils/__test__/?(*.)+(spec|test).js',
|
||||
// '<rootDir>/packages/laksa-wallet/__test__/?(*.)+(spec|test).js'
|
||||
// '<rootDir>/packages/laksa/__test__/?(*.)+(spec|test).js'
|
||||
], |
||||
moduleDirectories: ['src', 'node_modules'], |
||||
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'], |
||||
moduleNameMapper: { |
||||
'cross-fetch': 'jest-fetch-mock' |
||||
}, |
||||
testURL: 'http://localhost', |
||||
coverageThreshold: { |
||||
global: { |
||||
branches: 80, |
||||
functions: 80, |
||||
lines: 80, |
||||
statements: 80 |
||||
} |
||||
}, |
||||
rootDir: process.cwd(), |
||||
roots: ['<rootDir>/packages', '<rootDir>/scripts'], |
||||
collectCoverageFrom: [ |
||||
'packages/!(laksa-hd-wallet)/src/**/*.js' |
||||
// 'packages/!(laksa-core-crypto)/src/*.js'
|
||||
], |
||||
timers: 'fake', |
||||
setupFiles: ['<rootDir>/scripts/jest/jest.setup.js'], |
||||
setupTestFrameworkScriptFile: '<rootDir>/scripts/jest/jest.framework-setup.js', |
||||
testEnvironment: process.env.NODE_ENV === 'development' ? 'node' : 'jsdom', |
||||
collectCoverage: true, |
||||
automock: false |
||||
} |
||||
|
||||
module.exports = config |
@ -0,0 +1,29 @@ |
||||
const path = require('path') |
||||
const babel = require('@babel/core') |
||||
const createCacheKeyFunction = require('fbjs-scripts/jest/createCacheKeyFunction') |
||||
const babelOptions = require('../babel/babel.test.config.js') |
||||
|
||||
// Use require.resolve to be resilient to file moves, npm updates, etc
|
||||
const pathToBabel = path.join(require.resolve('@babel/core'), '../', '../', 'package.json') |
||||
const pathToBabelrc = path.join(__dirname, '../babel/babel.test.config.js') |
||||
|
||||
module.exports = { |
||||
process(src, filePath) { |
||||
if (!filePath.match(/\/third_party\//)) { |
||||
const isTestFile = !!filePath.match(/\/__test__\//) |
||||
const concatOptions = Object.assign( |
||||
babelOptions, |
||||
{ filename: path.relative(process.cwd(), filePath) }, |
||||
isTestFile |
||||
? { |
||||
plugins: babelOptions.plugins |
||||
} |
||||
: {} |
||||
) |
||||
const result = babel.transformSync(src, concatOptions) |
||||
return result.code |
||||
} |
||||
return src |
||||
}, |
||||
getCacheKey: createCacheKeyFunction([__filename, pathToBabel, pathToBabelrc]) |
||||
} |
@ -0,0 +1,6 @@ |
||||
export default [ |
||||
// 'harmony-account,
|
||||
'harmony-crypto', |
||||
// 'harmony-network',
|
||||
// 'harmony-utils',
|
||||
]; |
@ -0,0 +1,9 @@ |
||||
module.exports = [ |
||||
// { name: 'LaksaUtil', dest: 'laksa-utils' },
|
||||
// { name: 'LaksaZil', dest: 'laksa-zil' },
|
||||
// { name: 'LaksaCrypto', dest: 'laksa-core-crypto' },
|
||||
// { name: 'LaksaWallet', dest: 'laksa-wallet' },
|
||||
// { name: 'LaksaHDWallet', dest: 'laksa-hd-wallet' },
|
||||
// { name: 'LaksaContract', dest: 'laksa-core-contract' },
|
||||
// { name: 'Laksa', dest: 'laksa' }
|
||||
]; |
@ -0,0 +1,49 @@ |
||||
import * as path from 'path'; |
||||
import camelCase from 'camelcase'; |
||||
import babel from 'rollup-plugin-babel'; |
||||
import commonjs from 'rollup-plugin-commonjs'; |
||||
import license from 'rollup-plugin-license'; |
||||
import json from 'rollup-plugin-json'; |
||||
import typescript2 from 'rollup-plugin-typescript2'; |
||||
import ts from 'typescript'; |
||||
import packages from '../packages'; |
||||
import browserConfig from '../babel/babel.browser.config.js'; |
||||
import { getKeys } from './getDependencies'; |
||||
|
||||
function bundles() { |
||||
return packages.map((p) => { |
||||
const external = getKeys(p); |
||||
const externalSetting = getKeys(p).length > 0 ? { external } : {}; |
||||
const normal = { |
||||
input: `packages/${p}/src/index.ts`, |
||||
output: { |
||||
file: `packages/${p}/lib/index.js`, |
||||
format: 'umd', |
||||
name: camelCase(p), |
||||
}, |
||||
plugins: [ |
||||
typescript2({ |
||||
typescript: ts, // ensure we're using the same typescript (3.x) for rollup as for regular builds etc
|
||||
tsconfigOverride: { |
||||
module: 'esnext', |
||||
stripInternal: true, |
||||
emitDeclarationOnly: false, |
||||
composite: false, |
||||
declaration: false, |
||||
declarationMap: false, |
||||
sourceMap: true, |
||||
}, |
||||
}), |
||||
babel(browserConfig), |
||||
commonjs(), |
||||
json(), |
||||
license({ |
||||
banner: `Test Banner`, |
||||
}), |
||||
], |
||||
}; |
||||
return Object.assign(normal, externalSetting); |
||||
}); |
||||
} |
||||
|
||||
export default bundles(); |
@ -0,0 +1,49 @@ |
||||
import babel from 'rollup-plugin-babel' |
||||
import json from 'rollup-plugin-json' |
||||
import license from 'rollup-plugin-license' |
||||
import vuedoc from 'vuepress-jsdoc/cmds/index' |
||||
import packages from '../packages' |
||||
import serverConfig from '../babel/babel.server.config.js' |
||||
import { getKeys } from './getDependencies' |
||||
|
||||
function bundles() { |
||||
return packages.map(p => { |
||||
const external = getKeys(p) |
||||
const externalSetting = getKeys(p).length > 0 ? { external } : {} |
||||
vuedoc.generate({ |
||||
source: `packages/${p}/src`, |
||||
dist: `packages/${p}`, |
||||
folder: 'doc', |
||||
readme: `packages/${p}/README.md` |
||||
}) |
||||
const normal = { |
||||
input: `packages/${p}/src/index.js`, |
||||
output: { |
||||
file: `packages/${p}/node/index.js`, |
||||
format: 'umd', |
||||
name: 'Laksa' |
||||
}, |
||||
plugins: [ |
||||
babel(serverConfig), |
||||
json(), |
||||
license({ |
||||
banner: `This source code is being disclosed to you solely for the purpose of your participation in
|
||||
testing Zilliqa and Laksa. You may view, compile and run the code for that purpose and pursuant to
|
||||
the protocols and algorithms that are programmed into, and intended by, the code. You may
|
||||
not do anything else with the code without express permission from Zilliqa Research Pte. Ltd.,
|
||||
including modifying or publishing the code (or any part of it), and developing or forming
|
||||
another public or private blockchain network. This source code is provided ‘as is’ and no
|
||||
warranties are given as to title or non-infringement, merchantability or fitness for purpose
|
||||
and, to the extent permitted by law, all liability for your use of the code is disclaimed.
|
||||
Some programs in this code are governed by the GNU General Public License v3.0 (available at
|
||||
https://www.gnu.org/licenses/gpl-3.0.en.html) (‘GPLv3’). The programs that are governed by
|
||||
GPLv3.0 are those programs that are located in the folders src/depends and tests/depends
|
||||
and which include a reference to GPLv3 in their program files.` |
||||
}) |
||||
] |
||||
} |
||||
return Object.assign(normal, externalSetting) |
||||
}) |
||||
} |
||||
|
||||
export default bundles() |
@ -0,0 +1,13 @@ |
||||
import fs from 'fs'; |
||||
|
||||
export function getKeys(p) { |
||||
const packageJsonFile = `${process.cwd()}/packages/${p}/package.json`; |
||||
const data = fs.readFileSync(packageJsonFile, 'utf-8'); |
||||
|
||||
const { dependencies } = JSON.parse(data); |
||||
|
||||
const keys = dependencies |
||||
? Object.keys(dependencies).filter((d) => !/harmony/.test(d)) |
||||
: []; |
||||
return keys; |
||||
} |
Loading…
Reference in new issue