Skip to content

Commit 1f644c0

Browse files
author
Fabrice Bascoulergue
authored
Merge pull request #1 from lum-network/develop
Implement base abstraction for chain interactions
2 parents 65e3e7d + bae4b09 commit 1f644c0

File tree

98 files changed

+33863
-71
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

98 files changed

+33863
-71
lines changed

.eslintignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1+
build/
2+
docs/
13
node_modules/
2-
lib/
4+
proto/
5+
scripts/
6+
*.d.ts

.github/workflows/cd.yml

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,6 @@ jobs:
1414
strategy:
1515
matrix:
1616
node-version: [12.x]
17-
redis-version: [5]
18-
19-
env:
20-
CLOUDSDK_CORE_PROJECT: dev
2117

2218
steps:
2319
- name: Checkout code
@@ -41,12 +37,24 @@ jobs:
4137
- name: Run build lib, types and docs
4238
run: yarn build
4339
- name: Copy LICENSE
44-
run: cp LICENSE lib/LICENSE
40+
run: cp LICENSE build/LICENSE
4541
- name: Copy README
46-
run: cp README.md lib/README.md
42+
run: cp README.md build/README.md
4743
- name: Copy sanitized package.json
48-
run: cp package.json lib/package.json
44+
run: cp package.json build/package.json
45+
4946
- name: Publish package to NPM
5047
run: npm publish
5148
env:
5249
NODE_AUTH_TOKEN: ${{ secrets.NPM_PUBLISH_TOKEN }}
50+
51+
- name: Create Release
52+
id: create_release
53+
uses: actions/create-release@v1
54+
env:
55+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
56+
with:
57+
tag_name: ${{ github.ref }}
58+
release_name: Release ${{ github.ref }}
59+
draft: false
60+
prerelease: false

.github/workflows/ci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ jobs:
1414
strategy:
1515
matrix:
1616
node-version: [10.x, 12.x, 14.x, 15.x]
17-
redis-version: [4, 5, 6]
1817

1918
env:
2019
CLOUDSDK_CORE_PROJECT: dev

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,7 @@ dist
104104
.tern-port
105105

106106
# Build output
107-
/lib
108-
/typings
107+
/build
108+
109+
# Proto files
110+
/proto

.prettierignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
.github/workflows
2+
build
3+
docs
4+
node_modules
5+
proto

DOCUMENTATION.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

README.md

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,75 @@
22

33
This Javascript SDK enables browsers and NodeJS clients to interact with the Lum Network.
44

5+
## SDK Usage
6+
7+
### Node version
8+
9+
The library is tested using **NodeJS 10.x, 12.x, 14.x, 15.x**.
10+
11+
It should also work in all recent browsers.
12+
13+
### Installation
14+
15+
```bash
16+
yarn add @lum-network/sdk-javascript
17+
```
18+
19+
### Documentation
20+
21+
The SDK code should be documented enough for developers to explore and use it easily. Therefore the documentation might not cover all the capabilities of the SDK. Feel free to contribute if you wish to improve the code documentation and/or the provided samples.
22+
23+
The [Documentation](./docs/README.md) contains:
24+
25+
- Installation instructions
26+
- Basic usage
27+
- Code samples
28+
- Code auto-generated documentation
29+
530
## SDK Features
631

7-
This SDK basically provides an easy access to all the available Lum Network blockchain RPCs as well as the payload generation and the cryptographic features to properly consume those RPCs.
32+
This SDK provides an easy access to all the available Lum Network blockchain RPCs as well as the payload generation and the cryptographic features to properly consume those RPCs.
833

934
**Most commonly used features:**
1035

11-
- Core cryptographic tools and functions
36+
- Core cryptographic tools:
37+
- Seed, private key and encrypted mnemonic generation
38+
- Private and public keys management
39+
- Transaction payload generation
40+
- Transaction signature and verification
41+
- Wallets:
42+
- Unlock wallets from private keys, keystore and mnemonic
43+
- Sign transaction using unlocked wallets
1244
- Client service:
1345
- Connection to a blockchain node (http and socket mode)
46+
- Commonly used Tendermint and Cosmos RPCs
47+
- All Lum Network dedicated RPCs
1448
- Transaction broadcast
15-
- Blockchain RPCs
16-
- Accounts and wallets:
17-
- Accounts seed and encrypted mnemonic generation
18-
- Unlock accounts from private keys, keystore and mnemonic
19-
- Wallet balance
2049
- Transactions
2150
- Payload generation
2251
- Signature
52+
- Messages & Types:
53+
- Cosmos & Lum messages payload building
54+
- Typescript implementation of RPCs requests and responses
55+
- Other utils:
56+
- Encoding data from/to: Uint8Array, base64 and hex
57+
- Build Transaction search queries
58+
- Log & event parsing
2359

24-
## Documentation
60+
## Code structure
2561

26-
The SDK code should be documented enough for developers to explore and use it easily. Therefore the documentation might not cover all the capabilities of the SDK. Feel free to contribute if you wish to improve the code documentation and/or the provided samples.
62+
The SDK is based on the [CosmJS](https://github.com/cosmos/cosmjs) implementation and heavily relies on it.
2763

28-
The [Documentation](./DOCUMENTATION.md) contains:
64+
It is intented to be used standalone, without having to import specific CosmJS packages which can be tricky and messy.
2965

30-
- Installation instructions
31-
- Basic usage
32-
- Code samples
66+
Therefore all codecs, types, functions are features from the CosmJS SDK are either re-implemented by this SDK or re-exporter for simplicity purposes.
67+
68+
Directly importing the CosmJS SDK or other cryptographic library should be considered bad practice for most use cases.
69+
70+
Do not hesitate to contribute to this repository. This SDK is intended to be a one-stop-shop for all Lum Network javascript implementations and should definitely be improved over time by all its users.
3371

3472
## Contributing
3573

3674
Contributions are most welcome.
3775

3876
Please test your changes with a local client and add unit tests coverage for your code before submission.
39-
40-
## Special notes
41-
42-
Thanks to the Binance team for their work on the Binance Javascript SDK which inspired this project structure and development.

docs/README.md

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# Documentation
2+
3+
The code should be documented enough to make this library easy to use for anyone familiar with blockchain technology and especially the Tendermint engine and the Cosmos SDK.
4+
5+
You can find more details by browsing the [code documentation](./lib).
6+
7+
## Examples
8+
9+
A couple examples to help you get started.
10+
11+
### Imports
12+
13+
```typescript
14+
import {
15+
LumWallet,
16+
LumClient,
17+
LumTypes,
18+
LumUtils,
19+
LumConstants,
20+
LumMessages,
21+
} from '@lum-network/sdk-javascript'
22+
```
23+
24+
### Create a wallet
25+
26+
#### Mnemonic
27+
```typescript
28+
// Create a new cryptographically secure random mnemonic
29+
const mnemonic = LumUtils.generateMnemonic(12);
30+
31+
// Create a wallet instance based on this fresh mnemonic
32+
const wallet = await LumWallet.fromMnemonic(mnemonic);
33+
```
34+
35+
#### Private key
36+
```typescript
37+
// Create a new cryptographically secure random private key
38+
const privateKey = LumUtils.generatePrivateKey();
39+
40+
// Create a wallet instance based on this fresh private key
41+
const wallet = await LumWallet.fromPrivateKey(mnemonic);
42+
console.log(`Wallet address: ${wallet.address}`);
43+
44+
// Create a wallet instance based on an hexadecimal private key (ex: user input - 0x is optional)
45+
const hexPrivateKey = '0xb8e62c34928025cdd3aef6cbebc68694b5ad9209b2aff6d3891c8e61d22d3a3b';
46+
const existingWallet = await LumWallet.fromPrivateKey(LumUtils.keyFromHex(hexPrivateKey));
47+
console.log(`Existing wallet address: ${wallet.address}`);
48+
```
49+
50+
#### Keystore
51+
```typescript
52+
// Create a random private key for the sake of this example
53+
const privateKey = LumUtils.generatePrivateKey();
54+
// Create a keystore (or consume user input)
55+
const keystore = LumUtils.generateKeyStore(privateKey, 'some-password');
56+
const wallet = await LumWallet.fromKeyStore(keystore, 'some-password');
57+
console.log(`Wallet address: ${wallet.address}`);
58+
```
59+
60+
### Connect to the testnet
61+
62+
```typescript
63+
const testnetClient = await LumClient.connect('http://localhost:26657');
64+
```
65+
66+
### Account information & balance
67+
68+
#### Get account information
69+
```typescript
70+
const account = await testnetClient.getAccount(wallet.address);
71+
if (account === null) {
72+
console.log('Account: not found');
73+
} else {
74+
console.log(`Account: ${account.address}, ${account.accountNumber}, ${account.sequence}`);
75+
}
76+
```
77+
78+
#### Get account balances
79+
```typescript
80+
const balances = await testnetClient.getBalancesUnverified(wallet.address);
81+
if (balances.length === 0) {
82+
console.log('Balances: empty account');
83+
} else {
84+
console.log(
85+
`Balances: ${balances.map((coin) => {
86+
coin.denom + ': ' + coin.amount;
87+
})}`,
88+
);
89+
}
90+
```
91+
92+
### Transactions
93+
94+
#### Get account transactions (sent and received)
95+
```typescript
96+
// The client search feature supports multiple searches and merge+store the results
97+
const transactions = await testnetClient.searchTx([
98+
LumUtils.searchTxFrom(wallet.address),
99+
LumUtils.searchTxTo(wallet.address),
100+
]);
101+
console.log(`Transactions: ${transactions.map((tx) => tx.hash).join(', ')}`);
102+
```
103+
104+
#### Send transaction
105+
```typescript
106+
// Build transaction message (Send 100 LUM)
107+
const sendMsg = LumMessages.BuildMsgSend(
108+
wallet.address,
109+
toAddress,
110+
[{ denom: LumConstants.LumDenom, amount: '100' }],
111+
);
112+
// Define fees (1 LUM)
113+
const fee = {
114+
amount: [{ denom: LumConstants.LumDenom, amount: '1' }],
115+
gas: '100000',
116+
};
117+
// Sign and broadcast the transaction using the client
118+
const broadcastResult = await clt.signAndBroadcastTx(w1, [sendMsg], fee, 'hello memo!');
119+
// Verify the transaction was succesfully broadcasted and made it into a block
120+
console.log(`Broadcast success: ${LumUtils.broadcastTxCommitSuccess(broadcastResult)}`);
121+
```

docs/lib/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# @lum-network/sdk-javascript

jest.config.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module.exports = {
22
testMatch: ['**/*test.(ts|js)'],
3-
testPathIgnorePatterns: ['<rootDir>/node_modules/', '<rootDir>/lib/', '<rootDir>/typings'],
3+
testPathIgnorePatterns: ['<rootDir>/node_modules/', '<rootDir>/build/', '<rootDir>/typings'],
44
transform: {
55
'^.+\\.(ts|js)?$': 'ts-jest',
66
},
@@ -12,4 +12,5 @@ module.exports = {
1212
diagnostics: false,
1313
},
1414
},
15+
testTimeout: 10000,
1516
};

0 commit comments

Comments
 (0)