Skip to content

Commit

Permalink
address
Browse files Browse the repository at this point in the history
  • Loading branch information
lovelycs committed Sep 19, 2019
1 parent e10d7d0 commit 25ed637
Show file tree
Hide file tree
Showing 79 changed files with 1,568 additions and 470 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"@sisi/ed25519-blake2b-hd-key": "^1.0.2",
"@sisi/tweetnacl-blake2b": "^1.0.0",
"babel-loader": "^8.0.4",
"bip39": "^2.5.0",
"bip39": "^3.0.2",
"blake2b": "^2.1.3",
"blakejs": "^1.1.0",
"bn.js": "^4.11.8",
Expand Down
2 changes: 1 addition & 1 deletion src/HTTP/package.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"name":"@vite/vitejs-http","version":"2.2.11-alpha.0","main":"dist/index.node.js","browser":"dist/index.web.js","typings":"index.ts","repository":{"type":"git","url":"git+https://github.com/vitelabs/vite.js.git"},"license":"ISC","bugs":{"url":"https://github.com/vitelabs/vite.js/issues"},"homepage":"https://github.com/vitelabs/vite.js#readme","publishConfig":{"access":"public"}}
{"name":"@vite/vitejs-http","version":"2.2.11-alpha.0","main":"dist/index.node.js","browser":"dist/index.web.js","typings":"index.ts","repository":{"type":"git","url":"git+https://github.com/vitelabs/vite.js.git"},"license":"ISC","bugs":{"url":"https://github.com/vitelabs/vite.js/issues"},"homepage":"https://github.com/vitelabs/vite.js#readme","publishConfig":{"access":"public"}}
11 changes: 0 additions & 11 deletions src/HTTP/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,14 +539,3 @@ export declare interface RPCerror {
code: number;
message: string;
}

export enum LangList {
'english' = 'english',
'japanese' = 'japanese',
'chineseSimplified' = 'chinese_simplified',
'chineseTraditional' = 'chinese_traditional',
'french' = 'french',
'italian' = 'italian',
'korean' = 'korean',
'spanish' = 'spanish'
}
2 changes: 1 addition & 1 deletion src/IPC/package.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"name":"@vite/vitejs-ipc","version":"2.2.11-alpha.0","main":"dist/index.node.js","browser":"dist/index.web.js","typings":"index.ts","repository":{"type":"git","url":"git+https://github.com/vitelabs/vite.js.git"},"license":"ISC","bugs":{"url":"https://github.com/vitelabs/vite.js/issues"},"homepage":"https://github.com/vitelabs/vite.js#readme","publishConfig":{"access":"public"}}
{"name":"@vite/vitejs-ipc","version":"2.2.11-alpha.0","main":"dist/index.node.js","browser":"dist/index.web.js","typings":"index.ts","repository":{"type":"git","url":"git+https://github.com/vitelabs/vite.js.git"},"license":"ISC","bugs":{"url":"https://github.com/vitelabs/vite.js/issues"},"homepage":"https://github.com/vitelabs/vite.js#readme","publishConfig":{"access":"public"}}
11 changes: 0 additions & 11 deletions src/IPC/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,14 +539,3 @@ export declare interface RPCerror {
code: number;
message: string;
}

export enum LangList {
'english' = 'english',
'japanese' = 'japanese',
'chineseSimplified' = 'chinese_simplified',
'chineseTraditional' = 'chinese_traditional',
'french' = 'french',
'italian' = 'italian',
'korean' = 'korean',
'spanish' = 'spanish'
}
2 changes: 1 addition & 1 deletion src/WS/package.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"name":"@vite/vitejs-ws","version":"2.2.11-alpha.0","main":"dist/index.node.js","browser":"dist/index.web.js","typings":"index.ts","repository":{"type":"git","url":"git+https://github.com/vitelabs/vite.js.git"},"license":"ISC","bugs":{"url":"https://github.com/vitelabs/vite.js/issues"},"homepage":"https://github.com/vitelabs/vite.js#readme","publishConfig":{"access":"public"}}
{"name":"@vite/vitejs-ws","version":"2.2.11-alpha.0","main":"dist/index.node.js","browser":"dist/index.web.js","typings":"index.ts","repository":{"type":"git","url":"git+https://github.com/vitelabs/vite.js.git"},"license":"ISC","bugs":{"url":"https://github.com/vitelabs/vite.js/issues"},"homepage":"https://github.com/vitelabs/vite.js#readme","publishConfig":{"access":"public"}}
11 changes: 0 additions & 11 deletions src/WS/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,14 +539,3 @@ export declare interface RPCerror {
code: number;
message: string;
}

export enum LangList {
'english' = 'english',
'japanese' = 'japanese',
'chineseSimplified' = 'chinese_simplified',
'chineseTraditional' = 'chinese_traditional',
'french' = 'french',
'italian' = 'italian',
'korean' = 'korean',
'spanish' = 'spanish'
}
17 changes: 3 additions & 14 deletions src/abi/coder/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const BigNumber = require('bn.js');

import { unsafeInteger, integerIllegal } from '~@vite/vitejs-error';
import { getHexAddrFromAddr, getAddrFromHexAddr } from '~@vite/vitejs-privtoaddr';
import { getAddressFromRealAddress, getRealAddressFromAddress } from '~@vite/vitejs-privtoaddr';
import { getRawTokenId, getTokenIdFromRaw, isSafeInteger } from '~@vite/vitejs-utils';


Expand Down Expand Up @@ -68,7 +68,7 @@ export function decode(typeObj, params) {
function getRawData({ type, typeStr, actualByteLen }, params, _params) {
switch (type) {
case 'address':
return showAddr(params);
return getAddressFromRealAddress(params);
case 'bool':
return showNumber(params ? '1' : '0', 'uint');
case 'number':
Expand Down Expand Up @@ -96,10 +96,7 @@ function getBytesData({ type, typeStr, actualByteLen }, params) {
}

function formatAddr(address) {
const addr = getAddrFromHexAddr(address);
if (!addr) {
throw new Error(`[Error] Illegal address. ${ address }`);
}
const addr = getRealAddressFromAddress(address);
return Buffer.from(addr, 'hex');
}

Expand Down Expand Up @@ -143,14 +140,6 @@ function fomatTokenId(tokenId) {
return Buffer.from(rawTokenId, 'hex');
}

function showAddr(address) {
const addr = getHexAddrFromAddr(address);
if (!addr) {
throw new Error(`[Error] Illegal address. ${ address }`);
}
return addr;
}

function showNumber(str, typeStr, actualByteLen?, _params?) {
let num = new BigNumber(str, 16);
let actualNum = new BigNumber(_params, 16);
Expand Down
2 changes: 1 addition & 1 deletion src/abi/package.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"name":"@vite/vitejs-abi","version":"2.2.11-alpha.0","main":"dist/index.node.js","browser":"dist/index.web.js","typings":"index.ts","repository":{"type":"git","url":"git+https://github.com/vitelabs/vite.js.git"},"license":"ISC","bugs":{"url":"https://github.com/vitelabs/vite.js/issues"},"homepage":"https://github.com/vitelabs/vite.js#readme","publishConfig":{"access":"public"}}
{"name":"@vite/vitejs-abi","version":"2.2.11-alpha.0","main":"dist/index.node.js","browser":"dist/index.web.js","typings":"index.ts","repository":{"type":"git","url":"git+https://github.com/vitelabs/vite.js.git"},"license":"ISC","bugs":{"url":"https://github.com/vitelabs/vite.js/issues"},"homepage":"https://github.com/vitelabs/vite.js#readme","publishConfig":{"access":"public"}}
11 changes: 0 additions & 11 deletions src/abi/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,14 +539,3 @@ export declare interface RPCerror {
code: number;
message: string;
}

export enum LangList {
'english' = 'english',
'japanese' = 'japanese',
'chineseSimplified' = 'chinese_simplified',
'chineseTraditional' = 'chinese_traditional',
'french' = 'french',
'italian' = 'italian',
'korean' = 'korean',
'spanish' = 'spanish'
}
4 changes: 2 additions & 2 deletions src/account/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class AccountClass extends addrAccount {
this.privateKey = null;
this.publicKey = null;
} else {
const { pubKey, privKey, hexAddr } = privToAddr.newHexAddr(privateKey);
const { pubKey, privKey, hexAddr } = privToAddr.createAddressByPrivateKey(privateKey);

if (privateKey && address && hexAddr !== address) {
throw new Error(`Private key does not match address ${ address }`);
Expand Down Expand Up @@ -66,7 +66,7 @@ class AccountClass extends addrAccount {
return;
}

const { pubKey, privKey, hexAddr } = privToAddr.newHexAddr(privateKey);
const { pubKey, privKey, hexAddr } = privToAddr.createAddressByPrivateKey(privateKey);
if (hexAddr !== this.address) {
throw new Error(`Private key does not match address ${ this.address }`);
}
Expand Down
2 changes: 1 addition & 1 deletion src/account/package.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"name":"@vite/vitejs-account","version":"2.2.11-alpha.0","main":"dist/index.node.js","browser":"dist/index.web.js","typings":"index.ts","repository":{"type":"git","url":"git+https://github.com/vitelabs/vite.js.git"},"license":"ISC","bugs":{"url":"https://github.com/vitelabs/vite.js/issues"},"homepage":"https://github.com/vitelabs/vite.js#readme","publishConfig":{"access":"public"}}
{"name":"@vite/vitejs-account","version":"2.2.11-alpha.0","main":"dist/index.node.js","browser":"dist/index.web.js","typings":"index.ts","repository":{"type":"git","url":"git+https://github.com/vitelabs/vite.js.git"},"license":"ISC","bugs":{"url":"https://github.com/vitelabs/vite.js/issues"},"homepage":"https://github.com/vitelabs/vite.js#readme","publishConfig":{"access":"public"}}
11 changes: 0 additions & 11 deletions src/account/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,14 +539,3 @@ export declare interface RPCerror {
code: number;
message: string;
}

export enum LangList {
'english' = 'english',
'japanese' = 'japanese',
'chineseSimplified' = 'chinese_simplified',
'chineseTraditional' = 'chinese_traditional',
'french' = 'french',
'italian' = 'italian',
'korean' = 'korean',
'spanish' = 'spanish'
}
23 changes: 23 additions & 0 deletions src/accountBlock/_index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// import { checkParams } from '~@vite/vitejs-utils';

// export function checkAccountBlockKeywords({ blockType, accountAddress, toAddress, amount }) {
// const err = checkParams({ blockType, accountAddress, toAddress, amount }, [], [ {
// name: 'accountAddress',
// func: isAddress
// }, {
// name: 'toAddress',
// func: isAddress
// }, {
// name: 'blockType',
// func: _b => BlockType[_b],
// msg: `Don\'t have blockType ${ blockType }`
// }, {
// name: 'amount',
// func: isNonNegativeInteger,
// msg: 'Amount must be an non-negative integer string.'
// } ]);

// if (err) {
// return err;
// }
// }
8 changes: 4 additions & 4 deletions src/accountBlock/builtin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const BigNumber = require('bn.js');

import { paramsMissing, paramsConflict, integerIllegal, unsafeInteger } from '~@vite/vitejs-error';
import { Vite_TokenId, Default_Hash, Delegate_Gid, BlockType } from '~@vite/vitejs-constant';
import { isValidHexAddr } from '~@vite/vitejs-privtoaddr';
import { isAddress } from '~@vite/vitejs-privtoaddr';
import { checkParams, isSafeInteger, isArray, isObject, isNonNegativeInteger } from '~@vite/vitejs-utils';
import { encodeParameters, encodeFunctionSignature } from '~@vite/vitejs-abi';

Expand Down Expand Up @@ -51,10 +51,10 @@ export function formatAccountBlock(accountBlock: formatBlock) {
export function isAccountBlock({ blockType, fromBlockHash, accountAddress, message, data, toAddress, amount }: formatBlock) {
const err = checkParams({ blockType, accountAddress, toAddress, amount }, [ 'accountAddress', 'blockType' ], [ {
name: 'accountAddress',
func: isValidHexAddr
func: isAddress
}, {
name: 'toAddress',
func: isValidHexAddr
func: isAddress
}, {
name: 'blockType',
func: _b => BlockType[_b],
Expand Down Expand Up @@ -150,7 +150,7 @@ export function getContractTxType(_contracts: Object) {

const err = checkParams(_c, [ 'contractAddr', 'abi' ], [{
name: 'contractAddr',
func: isValidHexAddr
func: isAddress
}]);
if (err) {
throw err;
Expand Down
10 changes: 5 additions & 5 deletions src/accountBlock/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const BigNumber = require('bn.js');

import { ed25519, bytesToHex, blake2b, blake2bHex, checkParams, getRawTokenId } from '~@vite/vitejs-utils';
import { getAddrFromHexAddr, isValidHexAddr } from '~@vite/vitejs-privtoaddr';
import { getRealAddressFromAddress, isAddress } from '~@vite/vitejs-privtoaddr';
import { paramsFormat } from '~@vite/vitejs-error';
import { Default_Hash, Contracts } from '~@vite/vitejs-constant';
import { encodeFunctionSignature, decodeLog } from '~@vite/vitejs-abi';
Expand Down Expand Up @@ -71,7 +71,7 @@ export function getTxType({ toAddress, data, blockType }, contractTxType?): {
} {
const err = checkParams({ blockType, toAddress }, [ 'blockType', 'toAddress' ], [ {
name: 'toAddress',
func: isValidHexAddr
func: isAddress
}, {
name: 'blockType',
func: _b => BlockType[_b],
Expand Down Expand Up @@ -113,10 +113,10 @@ export function getBlockHash(accountBlock: SignBlock) {
source += blockType;
source += accountBlock.prevHash || Default_Hash;
source += accountBlock.height ? bytesToHex(new BigNumber(accountBlock.height).toArray('big', 8)) : '';
source += accountBlock.accountAddress ? getAddrFromHexAddr(accountBlock.accountAddress) : '';
source += accountBlock.accountAddress ? getRealAddressFromAddress(accountBlock.accountAddress) : '';

if (accountBlock.toAddress) {
source += getAddrFromHexAddr(accountBlock.toAddress);
source += getRealAddressFromAddress(accountBlock.toAddress);
source += getNumberHex(accountBlock.amount);
source += accountBlock.tokenId ? getRawTokenId(accountBlock.tokenId) || '' : '';
} else {
Expand Down Expand Up @@ -170,7 +170,7 @@ export function decodeBlockByContract({ accountBlock, contractAddr, abi, topics
}) {
const err = checkParams({ accountBlock, contractAddr, abi }, [ 'accountBlock', 'contractAddr', 'abi' ], [{
name: 'contractAddr',
func: isValidHexAddr
func: isAddress
}]);
if (err) {
throw err;
Expand Down
2 changes: 1 addition & 1 deletion src/accountBlock/package.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"name":"@vite/vitejs-accountblock","version":"2.2.11-alpha.0","main":"dist/index.node.js","browser":"dist/index.web.js","typings":"index.ts","repository":{"type":"git","url":"git+https://github.com/vitelabs/vite.js.git"},"license":"ISC","bugs":{"url":"https://github.com/vitelabs/vite.js/issues"},"homepage":"https://github.com/vitelabs/vite.js#readme","publishConfig":{"access":"public"}}
{"name":"@vite/vitejs-accountblock","version":"2.2.11-alpha.0","main":"dist/index.node.js","browser":"dist/index.web.js","typings":"index.ts","repository":{"type":"git","url":"git+https://github.com/vitelabs/vite.js.git"},"license":"ISC","bugs":{"url":"https://github.com/vitelabs/vite.js/issues"},"homepage":"https://github.com/vitelabs/vite.js#readme","publishConfig":{"access":"public"}}
11 changes: 0 additions & 11 deletions src/accountBlock/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,14 +539,3 @@ export declare interface RPCerror {
code: number;
message: string;
}

export enum LangList {
'english' = 'english',
'japanese' = 'japanese',
'chineseSimplified' = 'chinese_simplified',
'chineseTraditional' = 'chinese_traditional',
'french' = 'french',
'italian' = 'italian',
'korean' = 'korean',
'spanish' = 'spanish'
}
4 changes: 2 additions & 2 deletions src/addrAccount/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ class AddrAccountClass {
constructor({ address, client }: {
address: Address; client: client;
} = { address: null, client: null }) {
if (!privToAddr.isValidHexAddr(address)) {
if (!privToAddr.isAddress(address)) {
throw new Error(`Illegal address ${ address }.`);
}

this.address = address;
this.realAddress = privToAddr.getAddrFromHexAddr(this.address);
this.realAddress = privToAddr.getRealAddressFromAddress(this.address);

this._client = client;
this.getBlock = {};
Expand Down
2 changes: 1 addition & 1 deletion src/addrAccount/package.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"name":"@vite/vitejs-addraccount","version":"2.2.11-alpha.0","main":"dist/index.node.js","browser":"dist/index.web.js","typings":"index.ts","repository":{"type":"git","url":"git+https://github.com/vitelabs/vite.js.git"},"license":"ISC","bugs":{"url":"https://github.com/vitelabs/vite.js/issues"},"homepage":"https://github.com/vitelabs/vite.js#readme","publishConfig":{"access":"public"}}
{"name":"@vite/vitejs-addraccount","version":"2.2.11-alpha.0","main":"dist/index.node.js","browser":"dist/index.web.js","typings":"index.ts","repository":{"type":"git","url":"git+https://github.com/vitelabs/vite.js.git"},"license":"ISC","bugs":{"url":"https://github.com/vitelabs/vite.js/issues"},"homepage":"https://github.com/vitelabs/vite.js#readme","publishConfig":{"access":"public"}}
11 changes: 0 additions & 11 deletions src/addrAccount/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,14 +539,3 @@ export declare interface RPCerror {
code: number;
message: string;
}

export enum LangList {
'english' = 'english',
'japanese' = 'japanese',
'chineseSimplified' = 'chinese_simplified',
'chineseTraditional' = 'chinese_traditional',
'french' = 'french',
'italian' = 'italian',
'korean' = 'korean',
'spanish' = 'spanish'
}
67 changes: 67 additions & 0 deletions src/address/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
const hd = require('@sisi/ed25519-blake2b-hd-key');
import { createAddressByPrivateKey, isAddress as _isAddress, getRealAddressFromAddress as _getRealAddressFromAddress } from '~@vite/vitejs-privtoaddr';
import { paramsFormat } from '~@vite/vitejs-error';
import { bytesToHex, blake2b } from '~@vite/vitejs-utils';

import { AddrObj, Hex } from './type';

const ROOT_PATH = 'm/44\'/666666\'';

export function createAddress(seed: string, isContract?: boolean): AddrObj {
const path = getPath(0);
return getAddrFromPath(path, seed, isContract);
}

export function getAddrFromMnemonic(seed, index = 0, isContract?: boolean): AddrObj {
if (index < 0) {
console.warn(`${ paramsFormat.message } Index must greater than 0.`);
index = 0;
}

const path = getPath(index);
return getAddrFromPath(path, seed, isContract);
}

export function getAddrsFromMnemonic(seed, start = 0, num = 10, isContract?: boolean): AddrObj[] {
if (start < 0) {
console.warn(`${ paramsFormat.message } Start must greater than 0 or equal to 0.`);
start = 0;
}

if (num <= 0) {
return [];
}

const addrs = [];
for (let i = start; i < start + num; i++) {
const currentPath = getPath(i);
const addr = getAddrFromPath(currentPath, seed, isContract);
addrs.push(addr);
}

return addrs;
}

export const getId = _getId;

export const getRealAddressFromAddress = _getRealAddressFromAddress;

export const isAddress = _isAddress;


function getAddrFromPath(path: string, seed: string, isContract?: boolean): AddrObj {
const { key } = hd.derivePath(path, seed);
const { privateKey } = hd.getPublicKey(key);
const priv = bytesToHex(privateKey);
return createAddressByPrivateKey(priv, isContract);
}

function getPath(index: number): string {
return `${ ROOT_PATH }/${ index }\'`;
}

function _getId(address: string): Hex {
const keyBuffer = Buffer.from(address);
const idByte = blake2b(keyBuffer, null, 32);
return Buffer.from(idByte).toString('hex');
}
11 changes: 0 additions & 11 deletions src/accountAdapter/type.ts → src/address/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,14 +539,3 @@ export declare interface RPCerror {
code: number;
message: string;
}

export enum LangList {
'english' = 'english',
'japanese' = 'japanese',
'chineseSimplified' = 'chinese_simplified',
'chineseTraditional' = 'chinese_traditional',
'french' = 'french',
'italian' = 'italian',
'korean' = 'korean',
'spanish' = 'spanish'
}
Loading

0 comments on commit 25ed637

Please sign in to comment.