Skip to content

Commit

Permalink
feat: 🎸 plugins & refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
SmilingXinyi committed Jul 17, 2020
1 parent 2d9c040 commit 92b0064
Show file tree
Hide file tree
Showing 25 changed files with 1,420 additions and 146 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module.exports = {
'@typescript-eslint/ban-ts-ignore': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/indent': ['error', 4],
'@typescript-eslint/camelcase': 'off',
'indent': ['error', 4],
'object-curly-spacing': 'off',
'comma-dangle': 'off',
Expand Down
12 changes: 6 additions & 6 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ const conf = {
module.exports = {
projects: [
{
displayName: 'Browser',
displayName: 'browser',
testEnvironment: './test/jest/custom-test-env.js',
...conf
},
{
displayName: 'Nodejs',
testEnvironment: 'node',
...conf
}
// {
// displayName: 'Nodejs',
// testEnvironment: 'node',
// ...conf
// }
]
};
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@xuperchain/xuper-sdk",
"version": "2.0.0-beta.0",
"version": "2.0.0",
"description": "A simple JS(TS) SDK for XuperOS",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down
10 changes: 5 additions & 5 deletions sdk-1.x/src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ import aesjs from 'aes-js';
import {ec as EC} from 'elliptic';
import {RIPEMD160} from 'ripemd160-min';
import {Cryptography, Language, Strength} from './constants';
import wordlist from './wordlist.json';
import {
AccountInerface, AccountModel, PrivateKeyModel, PublicKeyModel
} from './interfaces';
import {
isBrowser,
base58Decode,
base58Encode,
deepEqual,
isBrowser,
publicOrPrivateKeyToString,
stringToPublicOrPrivateKey,
arrayPadStart
} from './utils';
import wordlist from './wordlist.json';
import {
AccountInerface, AccountModel, PrivateKeyModel, PublicKeyModel
} from './interfaces';

/**
* Class Account
Expand Down
5 changes: 1 addition & 4 deletions sdk-1.x/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,6 @@ export default class XuperSDK implements XuperSDKInterface {
const bnSum = new BN(sum);

const data: any = {
// bcname: this.options.chain,
// address: this.accountModel.address,
// totalAmount: bnSum.toNumber(),
request: {
initiator: this.accountModel.address,
bcname: this.options.chain,
Expand Down Expand Up @@ -766,7 +763,7 @@ export default class XuperSDK implements XuperSDKInterface {

const invokeRequests: ContracRequesttModel[] = [{
module_name: 'xkernel',
method_name: 'Deploy',
method_name: 'Deploy', // Upgrade
args: contractArgs
}];

Expand Down
31 changes: 23 additions & 8 deletions src/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,17 @@ import sha256 from 'sha256';
import pbkdf2 from 'pbkdf2';
import {ec as EC} from 'elliptic';
import {RIPEMD160} from 'ripemd160-min';
import aesjs from 'aes-js';

import {PrivateKey, PublicKey, AccountModel} from './types';
import {Cryptography, Language, Strength} from './constants';
import {arrayPadStart, base58Decode, base58Encode, deepEqual, isBrowser} from './utils';
import {
arrayPadStart, base58Decode, base58Encode, deepEqual,
isBrowser, stringToPublicOrPrivateKey
} from './utils';

import * as Requests from './requests';

import wordlist from './wordlist.json';
import {publicOrPrivateKeyToString, stringToPublicOrPrivateKey} from 'utils';
import {PrivateKeyModel, PublicKeyModel} from 'interfaces';
import aesjs from '@types/aes-js';
// import XuperErrors, {XuperError} from './error';

export default class Account {
private last4BitsMask: BN = new BN(15);
Expand Down Expand Up @@ -114,6 +113,11 @@ export default class Account {
}
}

checkMnemonic(mnemonic: string, language: Language): boolean {
const words = wordlist[language];
return mnemonic.split(' ').every(w => words.indexOf(w) > -1);
}

getBalance(address: string, node: string, chain: string): Promise<any> {
const body = {
address: address,
Expand All @@ -125,18 +129,29 @@ export default class Account {
return Requests.getBalance(node, body);
}

getBalanceDetail(address: string, node: string, chain: string): Promise<any> {
const body = {
address: address,
tfds: [{
bcname: chain
}]
};

return Requests.getBalanceDetail(node, body);
}

import(password: string, privateKeyStr: string): AccountModel {
const decryptStr = this.decryptPrivateKey(password, privateKeyStr);
const privateKeyObj = stringToPublicOrPrivateKey(decryptStr);

const privateKey: PrivateKeyModel = {
const privateKey: PrivateKey = {
D: privateKeyObj.D,
X: privateKeyObj.X,
Y: privateKeyObj.Y,
Curvname: privateKeyObj.Curvname
};

const publicKey: PublicKeyModel = {
const publicKey: PublicKey = {
X: privateKey.X,
Y: privateKey.Y,
Curvname: privateKey.Curvname
Expand Down
3 changes: 2 additions & 1 deletion src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ export {

const Errors = {
ACCOUNT_NOT_EXIST: XuperError(6001, 'Account not exist'),
PARAMETER_ERROR: XuperError(6002, 'Parameter error')
PARAMETER_ERROR: XuperError(6002, 'Parameter error'),
UTXO_NOT_ENOUGH: XuperError(1001, 'Utxo is not enough')
};

export default Errors;
Loading

0 comments on commit 92b0064

Please sign in to comment.