Add Account class
This commit is contained in:
parent
0f1f52e3e4
commit
5a0206bcfe
|
@ -8,9 +8,9 @@ script: npm run test
|
||||||
after_success: npm run coveralls
|
after_success: npm run coveralls
|
||||||
|
|
||||||
before_deploy:
|
before_deploy:
|
||||||
- cp -r doc solana_web3_api-$TRAVIS_BRANCH
|
- cp -r doc solanaWeb3Api-$TRAVIS_BRANCH
|
||||||
- tar zcf solana_web3_api-$TRAVIS_BRANCH.tgz solana_web3_api-$TRAVIS_BRANCH
|
- tar zcf solanaWeb3Api.tgz solanaWeb3Api-$TRAVIS_BRANCH
|
||||||
- cp lib/index.js solana_web3.min.js
|
- cp lib/index.js solanaWeb3.min.js
|
||||||
|
|
||||||
deploy:
|
deploy:
|
||||||
- provider: pages
|
- provider: pages
|
||||||
|
@ -23,8 +23,8 @@ deploy:
|
||||||
- provider: releases
|
- provider: releases
|
||||||
skip-cleanup: true
|
skip-cleanup: true
|
||||||
file:
|
file:
|
||||||
- solana_web3.min.js
|
- solanaWeb3.min.js
|
||||||
- solana_web3_api-$TRAVIS_BRANCH.tgz
|
- solanaWeb3Api.tgz
|
||||||
api_key: $GITHUB_TOKEN
|
api_key: $GITHUB_TOKEN
|
||||||
on:
|
on:
|
||||||
tags: true
|
tags: true
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
|
|
||||||
|
## Test framework
|
||||||
|
https://jestjs.io/
|
||||||
|
|
||||||
## API Documentation
|
## API Documentation
|
||||||
ESDoc is used to document the public API. See
|
ESDoc is used to document the public API. See
|
||||||
|
|
|
@ -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);
|
|
@ -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": {
|
"bcrypt-pbkdf": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/bcrypt-pbkdf/-/bcrypt-pbkdf-1.0.1.tgz",
|
||||||
|
@ -1755,6 +1763,15 @@
|
||||||
"optional": true,
|
"optional": true,
|
||||||
"requires": {
|
"requires": {
|
||||||
"tweetnacl": "0.14.5"
|
"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": {
|
"big-integer": {
|
||||||
|
@ -1858,6 +1875,14 @@
|
||||||
"electron-to-chromium": "1.3.42"
|
"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": {
|
"bser": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/bser/-/bser-2.0.0.tgz",
|
"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": {
|
"eslint-import-resolver-node": {
|
||||||
"version": "0.3.2",
|
"version": "0.3.2",
|
||||||
"resolved": "https://registry.npmjs.org/eslint-import-resolver-node/-/eslint-import-resolver-node-0.3.2.tgz",
|
"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": {
|
"eslint-scope": {
|
||||||
"version": "3.7.1",
|
"version": "3.7.1",
|
||||||
"resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-3.7.1.tgz",
|
"resolved": "https://registry.npmjs.org/eslint-scope/-/eslint-scope-3.7.1.tgz",
|
||||||
|
@ -8064,8 +8065,7 @@
|
||||||
"safe-buffer": {
|
"safe-buffer": {
|
||||||
"version": "5.1.1",
|
"version": "5.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz",
|
||||||
"integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg==",
|
"integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg=="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"safe-regex": {
|
"safe-regex": {
|
||||||
"version": "1.1.0",
|
"version": "1.1.0",
|
||||||
|
@ -8717,6 +8717,15 @@
|
||||||
"getpass": "0.1.7",
|
"getpass": "0.1.7",
|
||||||
"jsbn": "0.1.1",
|
"jsbn": "0.1.1",
|
||||||
"tweetnacl": "0.14.5"
|
"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": {
|
"stack-utils": {
|
||||||
|
@ -9414,11 +9423,9 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"tweetnacl": {
|
"tweetnacl": {
|
||||||
"version": "0.14.5",
|
"version": "1.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-0.14.5.tgz",
|
"resolved": "https://registry.npmjs.org/tweetnacl/-/tweetnacl-1.0.0.tgz",
|
||||||
"integrity": "sha1-WuaBd/GS1EViadEIr6k/+HQ/T2Q=",
|
"integrity": "sha1-cT2LgY2kIGh0C/aDhtBHnmb8ins="
|
||||||
"dev": true,
|
|
||||||
"optional": true
|
|
||||||
},
|
},
|
||||||
"type-check": {
|
"type-check": {
|
||||||
"version": "0.3.2",
|
"version": "0.3.2",
|
||||||
|
|
|
@ -36,7 +36,9 @@
|
||||||
"prepublish": "npm run clean && npm run test && npm run flow && npm run lint && npm run doc && npm run build"
|
"prepublish": "npm run clean && npm run test && npm run flow && npm run lint && npm run doc && npm run build"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"babel-runtime": "^6.26.0"
|
"babel-runtime": "^6.26.0",
|
||||||
|
"bs58": "^4.0.1",
|
||||||
|
"tweetnacl": "^1.0.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"babel-core": "6.26.0",
|
"babel-core": "6.26.0",
|
||||||
|
|
|
@ -1,17 +1,16 @@
|
||||||
import nodeResolve from 'rollup-plugin-node-resolve';
|
|
||||||
import babel from 'rollup-plugin-babel';
|
import babel from 'rollup-plugin-babel';
|
||||||
import replace from 'rollup-plugin-replace';
|
|
||||||
import commonjs from 'rollup-plugin-commonjs';
|
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';
|
import uglify from 'rollup-plugin-uglify';
|
||||||
|
|
||||||
const env = process.env.NODE_ENV;
|
const env = process.env.NODE_ENV;
|
||||||
|
|
||||||
const config = {
|
const config = {
|
||||||
input: 'src/index.js',
|
input: 'src/index.js',
|
||||||
external: ['react', 'react-dom'],
|
|
||||||
output: {
|
output: {
|
||||||
format: 'umd',
|
format: 'umd',
|
||||||
name: 'solana_web3',
|
name: 'solanaWeb3',
|
||||||
},
|
},
|
||||||
|
|
||||||
plugins: [
|
plugins: [
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
// @flow
|
|
||||||
|
|
||||||
export default (a: number, b: number): number => (a + b);
|
|
|
@ -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'
|
|
||||||
);
|
|
|
@ -1,5 +1 @@
|
||||||
import thankYou from 'examples/modern';
|
export {Account} from './account';
|
||||||
|
|
||||||
export const modern = thankYou;
|
|
||||||
|
|
||||||
console.log(thankYou());
|
|
||||||
|
|
|
@ -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');
|
||||||
|
});
|
|
@ -1,6 +0,0 @@
|
||||||
import flow from '../../src/examples/flow';
|
|
||||||
|
|
||||||
|
|
||||||
test('1 + 2 = 3', () => {
|
|
||||||
expect(flow(1, 2)).toBe(3);
|
|
||||||
});
|
|
|
@ -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);
|
|
||||||
});
|
|
Loading…
Reference in New Issue