Skip to content
Merged
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
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"extends": ["eslint-config-airbnb-base"],
"globals": {},
"rules": {
"indent": ["error", 2],
"function-paren-newline": "off",
"no-console": ["warn"],
"no-useless-escape": 0,
Expand Down
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@
"useTabs": false,
"printWidth": 120,
"endOfLine": "lf",
"arrowParens": "avoid"
"arrowParens": "avoid",
"tabWidth": 2
}
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ You can skip 2.2 as 2.1 is enough now.
In our dist directory, we supply two kinds of packages for different platforms, such as Node and Browser.

| packages | usage |
| ---------------- | ------------------------------------------------------------ |
|------------------| ------------------------------------------------------------ |
| dist/aelf.esm.js | built as an ES Module, optimized for modern bundlers and tree-shaking. Designed for use in modern JavaScript environments like webpack, Rollup, and Vite. |
| dist/aelf.cjs.js | built for node, remove node built-in modules such as crypto. |
| dist/aelf.umd.js | built for browser, add some node built-in modules by webpack |

Expand All @@ -70,6 +71,19 @@ if you want to use a bundle system such as webpack or rollup, and build your app

#### For browser usage and use UMD

ESM
```javascript
// ✅ Recommended: Use "exports" to enable Tree Shaking
import wallet from 'aelf-sdk/wallet';

// ✅ Also supported: Directly import from the "src" directory
import wallet from 'aelf-sdk/src/wallet/index.js';

// ✅ Backward compatibility: Traditional import method
import AElf from 'aelf-sdk';
const { wallet } = AElf;
```

Webpack:

```javascript
Expand Down
36 changes: 29 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aelf-sdk",
"version": "3.4.21",
"version": "3.5.0",
"description": "aelf-sdk js library",
"type": "module",
"main": "dist/aelf.cjs",
Expand All @@ -12,6 +12,34 @@
".": {
"import": "./dist/aelf.esm.js",
"require": "./dist/aelf.cjs"
},
"./src/*": {
"import": "./src/*",
"require": "./src/*"
},
"./wallet": {
"import": "./src/wallet/index.js",
"require": "./src/wallet/index.js"
},
"./utils": {
"import": "./src/util/utils.js",
"require": "./src/util/utils.js"
},
"./chain": {
"import": "./src/chain/index.js",
"require": "./src/chain/index.js"
},
"./sha256": {
"import": "./src/util/sha256.js",
"require": "./src/util/sha256.js"
},
"./keyStore": {
"import": "./src/util/keyStore.js",
"require": "./src/util/keyStore.js"
},
"./AElf": {
"import": "./src/AElf.js",
"require": "./src/AElf.js"
}
},
"scripts": {
Expand Down Expand Up @@ -50,9 +78,6 @@
],
"author": "hzz780",
"license": "MIT",
"devEngines": {
"node": "18.x || 20.x"
},
"engines": {
"node": ">=18.18.0"
},
Expand All @@ -64,7 +89,6 @@
"@babel/plugin-proposal-optional-chaining": "^7.21.0",
"@babel/runtime": "^7.4.5",
"@typescript-eslint/parser": "^5.47.1",
"assert": "^2.0.0",
"babel-plugin-rewire": "^1.2.0",
"bignumber.js": "^9.0.0",
"bip39": "^3.0.2",
Expand Down Expand Up @@ -138,9 +162,7 @@
"rimraf": "^5.0.0",
"size-limit": "^8.1.2",
"standard-version": "^9.5.0",
"unused-files-webpack-plugin": "^3.4.0",
"webpack": "^5.80.0",
"webpack-bundle-analyzer": "^4.8.0",
"webpack-cli": "^5.0.2",
"webpack-deadcode-plugin": "^0.1.17",
"webpack-merge": "^5.8.0"
Expand Down
76 changes: 76 additions & 0 deletions src/AElf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/**
* @file AElf-sdk index export
* @author atom-yang
*/
import * as protobuf from '@aelfqueen/protobufjs/light.js';
import * as bloom from './util/bloom.js';
import Chain from './chain/index.js';
import RequestManager from './util/requestManage.js';
import HttpProvider from './util/httpProvider.js';
import wallet from './wallet/index.js';
import * as utils from './util/utils.js';
import * as proto from './util/proto.js';
import * as transform from './util/transform.js';
import * as transaction from './util/transaction.js';
import Settings from './util/settings.js';
import sha256 from './util/sha256.js';

/* eslint-disable no-underscore-dangle */
export default class AElf {
constructor(provider) {
this._requestManager = new RequestManager(provider);
this.currentProvider = provider;
this.chain = new Chain(this._requestManager);
}

static version = process.env.SDK_VERSION;

static providers = {
HttpProvider
};

/**
* @type {protobuf} export protobufjs for developers
*/
static pbjs = protobuf;

static pbUtils = proto;

static wallet = wallet;

static utils = {
...utils,
...bloom,
...transaction,
sha256,
transform
};

providers = {
HttpProvider
};

settings = new Settings();

/**
* AElf-sdk version
* @type {{api: string}}
*/
version = {
api: process.env.SDK_VERSION
};

/**
* check the rpc node is work or not.
* @returns {boolean} whether can connect to the rpc.
*/
isConnected() {
return this.currentProvider && this.currentProvider.isConnected();
}

setProvider(provider) {
this._requestManager.setProvider(provider);
this.currentProvider = provider;
}
}
/* eslint-enable */
19 changes: 0 additions & 19 deletions src/common/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,22 +183,3 @@ export const CONGIG = {
contractZero: 'AELF',
defaultAccount: '0x04bb9c6c297ea90b1bc3e6af2c87d416583e'
};

export const KEY_STORE_ERRORS = {
INVALID_PASSWORD: {
error: 200001,
errorMessage: 'Password Error'
},
NOT_AELF_KEY_STORE: {
error: 200002,
errorMessage: 'Not a aelf key store'
},
WRONG_VERSION: {
error: 200004,
errorMessage: 'The version is incorrect'
},
WRONG_KEY_STORE_VERSION: {
error: 200005,
errorMessage: 'Not a V1 key store'
}
};
22 changes: 22 additions & 0 deletions src/common/keyStoreConstants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/**
* @file AElf-sdk constantsKeyStore
* @author hzz780
*/
export const KEY_STORE_ERRORS = {
INVALID_PASSWORD: {
error: 200001,
errorMessage: 'Password Error'
},
NOT_AELF_KEY_STORE: {
error: 200002,
errorMessage: 'Not a aelf key store'
},
WRONG_VERSION: {
error: 200004,
errorMessage: 'The version is incorrect'
},
WRONG_KEY_STORE_VERSION: {
error: 200005,
errorMessage: 'Not a V1 key store'
}
};
42 changes: 42 additions & 0 deletions src/common/unitConstants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* @file AElf-sdk constants
* @author atom-yang
*/

/**
* unsigned 256 int
*/
export const UNSIGNED_256_INT = 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff';

/**
* unit map
*/
export const UNIT_MAP = {
noether: '0',
wei: '1',
kwei: '1000',
Kwei: '1000',
babbage: '1000',
femtoether: '1000',
mwei: '1000000',
Mwei: '1000000',
lovelace: '1000000',
picoether: '1000000',
gwei: '1000000000',
Gwei: '1000000000',
shannon: '1000000000',
nanoether: '1000000000',
nano: '1000000000',
szabo: '1000000000000',
microether: '1000000000000',
micro: '1000000000000',
finney: '1000000000000000',
milliether: '1000000000000000',
milli: '1000000000000000',
ether: '1000000000000000000',
kether: '1000000000000000000000',
grand: '1000000000000000000000',
mether: '1000000000000000000000000',
gether: '1000000000000000000000000000',
tether: '1000000000000000000000000000000'
};
4 changes: 2 additions & 2 deletions src/contract/contractMethod.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
OUTPUT_TRANSFORMERS
} from '../util/transform.js';
import { isBoolean, isFunction, isNumber, noop, uint8ArrayToHex, unpackSpecifiedTypeData } from '../util/utils.js';
import wallet from '../wallet/index.js';
import { signTransaction } from '../util/transaction.js';

export default class ContractMethod {
constructor(chain, method, contractAddress, walletInstance, option) {
Expand Down Expand Up @@ -88,7 +88,7 @@ export default class ContractMethod {
handleTransaction(height, hash, encoded) {
const rawTx = this.getRawTx(height, hash, encoded);

let tx = wallet.signTransaction(rawTx, this._wallet.keyPair);
let tx = signTransaction(rawTx, this._wallet.keyPair);

tx = Transaction.encode(tx).finish();
// jest environment just go into Buffer branch
Expand Down
70 changes: 2 additions & 68 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,73 +2,7 @@
* @file AElf-sdk index export
* @author atom-yang
*/
import * as protobuf from '@aelfqueen/protobufjs/light.js';
import * as bloom from './util/bloom.js';
import Chain from './chain/index.js';
import RequestManager from './util/requestManage.js';
import HttpProvider from './util/httpProvider.js';
import wallet from './wallet/index.js';
import * as utils from './util/utils.js';
import * as proto from './util/proto.js';
import * as transform from './util/transform.js';
import Settings from './util/settings.js';
import sha256 from './util/sha256.js';

/* eslint-disable no-underscore-dangle */
export default class AElf {
constructor(provider) {
this._requestManager = new RequestManager(provider);
this.currentProvider = provider;
this.chain = new Chain(this._requestManager);
}
import AElf from './AElf.js';

static version = process.env.SDK_VERSION;

static providers = {
HttpProvider
};

/**
* @type {protobuf} export protobufjs for developers
*/
static pbjs = protobuf;

static pbUtils = proto;

static wallet = wallet;

static utils = {
...utils,
...bloom,
sha256,
transform
};

providers = {
HttpProvider
};

settings = new Settings();

/**
* AElf-sdk version
* @type {{api: string}}
*/
version = {
api: process.env.SDK_VERSION
};

/**
* check the rpc node is work or not.
* @returns {boolean} whether can connect to the rpc.
*/
isConnected() {
return this.currentProvider && this.currentProvider.isConnected();
}

setProvider(provider) {
this._requestManager.setProvider(provider);
this.currentProvider = provider;
}
}
/* eslint-enable */
export default AElf;
2 changes: 1 addition & 1 deletion src/util/keyStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import scrypt from 'scryptsy';
import { createCipheriv, createDecipheriv } from 'browserify-cipher';
import randomBytes from 'randombytes';
import { keccak256 } from './keccak.js';
import { KEY_STORE_ERRORS } from '../common/constants.js';
import { KEY_STORE_ERRORS } from '../common/keyStoreConstants.js';

const AES_MODES = {
'aes-128-ecb': {
Expand Down
Loading