Add Account class

This commit is contained in:
Michael Vines 2018-08-22 17:03:50 -07:00
parent 0f1f52e3e4
commit 5a0206bcfe
13 changed files with 109 additions and 85 deletions

View File

@ -8,9 +8,9 @@ script: npm run test
after_success: npm run coveralls
before_deploy:
- cp -r doc solana_web3_api-$TRAVIS_BRANCH
- tar zcf solana_web3_api-$TRAVIS_BRANCH.tgz solana_web3_api-$TRAVIS_BRANCH
- cp lib/index.js solana_web3.min.js
- cp -r doc solanaWeb3Api-$TRAVIS_BRANCH
- tar zcf solanaWeb3Api.tgz solanaWeb3Api-$TRAVIS_BRANCH
- cp lib/index.js solanaWeb3.min.js
deploy:
- provider: pages
@ -23,8 +23,8 @@ deploy:
- provider: releases
skip-cleanup: true
file:
- solana_web3.min.js
- solana_web3_api-$TRAVIS_BRANCH.tgz
- solanaWeb3.min.js
- solanaWeb3Api.tgz
api_key: $GITHUB_TOKEN
on:
tags: true

View File

@ -1,4 +1,6 @@
## Test framework
https://jestjs.io/
## API Documentation
ESDoc is used to document the public API. See

View File

@ -0,0 +1,16 @@
/*
Creating a new account
Usage:
$ npm run dev
$ node ./account.js
*/
//eslint-disable-next-line import/no-commonjs
const solanaWeb3 = require('..');
//const solanaWeb3 = require('@solana/web3.js');
const account = new solanaWeb3.Account();
console.log(account.publicKey);

View File

@ -1747,6 +1747,14 @@
}
}
},
"base-x": {
"version": "3.0.4",
"resolved": "https://registry.npmjs.org/base-x/-/base-x-3.0.4.tgz",
"integrity": "sha512-UYOadoSIkEI/VrRGSG6qp93rp2WdokiAiNYDfGW5qURAY8GiAQkvMbwNNSDYiVJopqv4gCna7xqf4rrNGp+5AA==",
"requires": {
"safe-buffer": "5.1.1"
}
},
"bcrypt-pbkdf": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.1.tgz",
@ -1755,6 +1763,15 @@
"optional": true,
"requires": {
"tweetnacl": "0.14.5"
},
"dependencies": {
"tweetnacl": {
"version": "0.14.5",
"resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz",
"integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=",
"dev": true,
"optional": true
}
}
},
"big-integer": {
@ -1858,6 +1875,14 @@
"electron-to-chromium": "1.3.42"
}
},
"bs58": {
"version": "4.0.1",
"resolved": "https://registry.npmjs.org/bs58/-/bs58-4.0.1.tgz",
"integrity": "sha1-vhYedsNU9veIrkBx9j806MTwpCo=",
"requires": {
"base-x": "3.0.4"
}
},
"bser": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/bser/-/bser-2.0.0.tgz",
@ -3129,24 +3154,6 @@
}
}
},
"eslint-config-airbnb": {
"version": "16.1.0",
"resolved": "https://registry.npmjs.org/eslint-config-airbnb/-/eslint-config-airbnb-16.1.0.tgz",
"integrity": "sha512-zLyOhVWhzB/jwbz7IPSbkUuj7X2ox4PHXTcZkEmDqTvd0baJmJyuxlFPDlZOE/Y5bC+HQRaEkT3FoHo9wIdRiw==",
"dev": true,
"requires": {
"eslint-config-airbnb-base": "12.1.0"
}
},
"eslint-config-airbnb-base": {
"version": "12.1.0",
"resolved": "https://registry.npmjs.org/eslint-config-airbnb-base/-/eslint-config-airbnb-base-12.1.0.tgz",
"integrity": "sha512-/vjm0Px5ZCpmJqnjIzcFb9TKZrKWz0gnuG/7Gfkt0Db1ELJR51xkZth+t14rYdqWgX836XbuxtArbIHlVhbLBA==",
"dev": true,
"requires": {
"eslint-restricted-globals": "0.1.1"
}
},
"eslint-import-resolver-node": {
"version": "0.3.2",
"resolved": "https://registry.npmjs.org/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.2.tgz",
@ -3297,12 +3304,6 @@
}
}
},
"eslint-restricted-globals": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/eslint-restricted-globals/-/eslint-restricted-globals-0.1.1.tgz",
"integrity": "sha1-NfDVy8ZMLj7WLpO0saevBbp+1Nc=",
"dev": true
},
"eslint-scope": {
"version": "3.7.1",
"resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-3.7.1.tgz",
@ -8064,8 +8065,7 @@
"safe-buffer": {
"version": "5.1.1",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz",
"integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg==",
"dev": true
"integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg=="
},
"safe-regex": {
"version": "1.1.0",
@ -8717,6 +8717,15 @@
"getpass": "0.1.7",
"jsbn": "0.1.1",
"tweetnacl": "0.14.5"
},
"dependencies": {
"tweetnacl": {
"version": "0.14.5",
"resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz",
"integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=",
"dev": true,
"optional": true
}
}
},
"stack-utils": {
@ -9414,11 +9423,9 @@
}
},
"tweetnacl": {
"version": "0.14.5",
"resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz",
"integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=",
"dev": true,
"optional": true
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.0.tgz",
"integrity": "sha1-cT2LgY2kIGh0C/aDhtBHnmb8ins="
},
"type-check": {
"version": "0.3.2",

View File

@ -36,7 +36,9 @@
"prepublish": "npm run clean && npm run test && npm run flow && npm run lint && npm run doc && npm run build"
},
"dependencies": {
"babel-runtime": "^6.26.0"
"babel-runtime": "^6.26.0",
"bs58": "^4.0.1",
"tweetnacl": "^1.0.0"
},
"devDependencies": {
"babel-core": "6.26.0",

View File

@ -1,17 +1,16 @@
import nodeResolve from 'rollup-plugin-node-resolve';
import babel from 'rollup-plugin-babel';
import replace from 'rollup-plugin-replace';
import commonjs from 'rollup-plugin-commonjs';
import nodeResolve from 'rollup-plugin-node-resolve';
import replace from 'rollup-plugin-replace';
import uglify from 'rollup-plugin-uglify';
const env = process.env.NODE_ENV;
const config = {
input: 'src/index.js',
external: ['react', 'react-dom'],
output: {
format: 'umd',
name: 'solana_web3',
name: 'solanaWeb3',
},
plugins: [

21
web3.js/src/account.js Normal file
View File

@ -0,0 +1,21 @@
import nacl from 'tweetnacl';
import bs58 from 'bs58';
export class Account {
constructor(secretKey: ?Buffer = null) {
if (secretKey) {
this._keypair = nacl.sign.keyPair.fromSecretKey(secretKey);
} else {
this._keypair = nacl.sign.keyPair();
}
}
get publicKey(): string {
return bs58.encode(this._keypair.publicKey);
}
get secretKey(): string {
return this._keypair.secretKey;
}
}

View File

@ -1,3 +0,0 @@
// @flow
export default (a: number, b: number): number => (a + b);

View File

@ -1,13 +0,0 @@
export default () => (
'\n' +
' \x1b[42m\x1b[30m \n\x1b[0m' +
' \x1b[42m\x1b[30m Thank you for using this boilerplate! \n\x1b[0m' +
' \x1b[42m\x1b[30m \n\x1b[0m' +
'\n' +
' Getting started\n\n' +
' 1. Clone the repo from github (https://github.com/eunikitin/modern-package-boilerplate.git)\n' +
' 2. Inside the repo directory run npm install && rm -r .git && git init\n' +
' 3. Update package.json with your information' +
'\n'
);

View File

@ -1,5 +1 @@
import thankYou from 'examples/modern';
export const modern = thankYou;
console.log(thankYou());
export {Account} from './account';

View File

@ -0,0 +1,20 @@
import {Account} from '../src/account';
test('generate new account', () => {
const account = new Account();
const len = account.publicKey.length;
expect(len === 43 || len === 44);
expect(account.secretKey).toHaveLength(64);
});
test('account from secret key', () => {
const secretKey = Buffer.from([
153, 218, 149, 89, 225, 94, 145, 62, 233, 171, 46, 83, 227,
223, 173, 87, 93, 163, 59, 73, 190, 17, 37, 187, 146, 46, 51,
73, 79, 73, 136, 40, 27, 47, 73, 9, 110, 62, 93, 189, 15, 207,
169, 192, 192, 205, 146, 217, 171, 59, 33, 84, 75, 52, 213, 221,
74, 101, 217, 139, 135, 139, 153, 34
]);
const account = new Account(secretKey);
expect(account.publicKey).toBe('2q7pyhPwAwZ3QMfZrnAbDhnh9mDUqycszcpf86VgQxhF');
});

View File

@ -1,6 +0,0 @@
import flow from '../../src/examples/flow';
test('1 + 2 = 3', () => {
expect(flow(1, 2)).toBe(3);
});

View File

@ -1,17 +0,0 @@
import modern from '../../src/examples/modern';
const message =
'\n' +
' \x1b[42m\x1b[30m \n\x1b[0m' +
' \x1b[42m\x1b[30m Thank you for using this boilerplate! \n\x1b[0m' +
' \x1b[42m\x1b[30m \n\x1b[0m' +
'\n' +
' Getting started\n\n' +
' 1. Clone the repo from github (https://github.com/eunikitin/modern-package-boilerplate.git)\n' +
' 2. Inside the repo directory run npm install && rm -r .git && git init\n' +
' 3. Update package.json with your information' +
'\n';
test('Message on package usage', () => {
expect(modern()).toBe(message);
});