Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: wallet typing #104

Open
wants to merge 2 commits into
base: feature/typescript-declaration
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"root": true,
"parser": "babel-eslint",
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2018,
"sourceType": "module",
Expand All @@ -15,13 +15,8 @@
"browser": true,
"jest": true
},
"plugins": [
"babel",
"import"
],
"extends": [
"eslint-config-airbnb-base"
],
"plugins": ["babel", "import"],
"extends": ["eslint-config-airbnb-base"],
"globals": {},
"rules": {
"no-console": ["warn"],
Expand All @@ -34,7 +29,7 @@
"no-underscore-dangle": "off",
"no-bitwise": "off",
"no-mixed-operators": "off",
"max-len": ["error", { "code": 120}],
"max-len": ["error", { "code": 120 }],
"class-methods-use-this": "off",
"no-plusplus": "off"
}
Expand Down
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "aelf-sdk",
"name": "aelf-web3",
"version": "3.2.41",
"description": "aelf-sdk js library",
"main": "dist/aelf.cjs.js",
Expand All @@ -24,7 +24,7 @@
"test:node:watch": "jest --config=jest.node.config.js --watch"
},
"keywords": [
"aelf-sdk"
"aelf-web3"
],
"files": [
"src",
Expand All @@ -41,10 +41,12 @@
"engines": {
"node": ">=10.5.0"
},
"types": "types",
"engineStrict": true,
"dependencies": {
"@aelfqueen/protobufjs": "^6.8.9",
"@babel/runtime": "^7.4.5",
"@typescript-eslint/parser": "^5.47.1",
"assert": "^2.0.0",
"bignumber.js": "^9.0.0",
"bip39": "^3.0.2",
Expand All @@ -65,6 +67,8 @@
"@babel/plugin-proposal-class-properties": "^7.4.4",
"@babel/plugin-transform-runtime": "^7.4.4",
"@babel/preset-env": "^7.4.5",
"@types/elliptic": "^6.4.14",
"@types/hdkey": "^2.0.1",
"babel-eslint": "^10.0.2",
"babel-loader": "^8.0.6",
"bundle-analyzer": "^0.0.6",
Expand Down
26 changes: 26 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"ts-node": {
"compilerOptions": {
"module": "commonjs"
}
},
"compilerOptions": {
"module": "esnext",
"lib": ["dom", "dom.iterable", "esnext"],
"target": "es5",
"moduleResolution": "node",
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"noEmit": true,
"allowJs": false,
"allowSyntheticDefaultImports": false,
"baseUrl": ".",
"paths": {
"aelf-web3": ["types"]
},
"esModuleInterop": true,
"declaration": true
}
}
7 changes: 7 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Wallet from "./wallet/index";

declare namespace AElf {}
export declare class AElf {
static wallet: Wallet;
}
export default AElf;
51 changes: 51 additions & 0 deletions types/util/keyStore.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { IWallet } from "../wallet";

interface IOptions {
dklen: number;
n: number;
r: number;
p: number;
cipher: string;
}
interface IKdfparams {
dklen: number;
n: number;
r: number;
p: number;
salt: string;
}
type TWalletInfo = IWallet & {
nickName?: string;
};
interface ICipherparams {
iv: string;
}
interface ICrypto {
cipher: string;
cipherparams: ICipherparams;
ciphertext: string;
kdf: string;
kdfparams: IKdfparams;
mac: string;
mnemonicEncrypted: string;
}
interface IkeyStore {
version: number;
type: string;
nickName?: string;
address: string;
crypto: ICrypto;
}
export declare function getKeystore(
walletInfoInput: TWalletInfo,
password: string,
option?: IOptions
): IkeyStore;
export declare function unlockKeystore(
keyStoreInput: IkeyStore,
password: string
): TWalletInfo;
export declare function checkPassword(
keyStoreInput: IkeyStore,
password: string
): boolean;
15 changes: 15 additions & 0 deletions types/util/proto.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export interface IAddress {
value: Uint8Array;
}
export interface ITransaction {
from: IAddress;
to: IAddress;
methodName: string;
params: string;
}
export function getTransaction(
from: string,
to: string,
methodName: string,
params: string
): ITransaction;
37 changes: 37 additions & 0 deletions types/wallet/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import HDNode = require("hdkey");
import * as Bip39 from "bip39";
import { ec, curve } from "elliptic";
import { ITransaction } from "../util/proto";
import * as KeyStore from "../util/keyStore";

export default Wallet;

interface ISignature {
signature: Uint8Array;
}
type TSignTransaction = ISignature & ITransaction;

export interface IWallet {
BIP44Path: string;
address: string;
childWallet: IWallet | string;
keyPair: ec.KeyPair;
mnemonic: string;
privateKey: string;
}

declare class Wallet {
ellipticEc: ec;
hdkey: HDNode;
bip39: typeof Bip39;
keyStore: typeof KeyStore;
AESEncrypt(input: string, password: string): string;
AESDescrypt(input: string, password: string): string;
getSignature(bytesToBeSign: string, keyPair: ec.KeyPair): Buffer;
getAddressFromPubKey(pubKey: curve.base.BasePoint): string;
createNewWallet(BIP44Path?: string): IWallet;
getWalletByMnemonic(mnemonic: string, BIP44Path: string): IWallet;
getWalletByPrivateKey(privateKey: string): IWallet;
signTransaction(rawTxn: ITransaction, keyPair: ec.KeyPair): TSignTransaction;
sign(hexString: string, keyPair: ec.KeyPair): Buffer;
}
Loading