lunesjs 1.5.8 → 1.5.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +5 -0
- package/dist/index.js +14 -0
- package/package.json +10 -4
- package/.devcontainer/devcontainer.json +0 -14
- package/.github/workflows/deploy.yml +0 -48
- package/.github/workflows/test.yml +0 -35
- package/.gitlab/.gitlab-ci.yml +0 -21
- package/.gitlab/issue_templates/bug.md +0 -13
- package/.gitlab/issue_templates/proposal.md +0 -5
- package/.gitlab/merge_request_templates/MR.md +0 -7
- package/.prettierignore +0 -1
- package/.prettierrc.yml +0 -3
- package/CONTRIBUTING.md +0 -51
- package/Dockerfile +0 -6
- package/jest.config.js +0 -11
- package/src/client/transactions/BaseTransaction.ts +0 -7
- package/src/client/transactions/transactions.types.ts +0 -11
- package/src/client/transactions/transfer/service.transfer.ts +0 -58
- package/src/client/transactions/transfer/transfer.types.ts +0 -12
- package/src/client/transactions/transfer/validator.ts +0 -92
- package/src/client/wallet/constants.ts +0 -2065
- package/src/client/wallet/service.account.ts +0 -74
- package/src/client/wallet/wallet.types.ts +0 -23
- package/src/utils/crypto.ts +0 -109
- package/static/img/jslogo.png +0 -0
- package/test/client/transactions/transfer/transfer.token.test.ts +0 -98
- package/test/client/wallet/service.account.test.ts +0 -330
- package/tsconfig.json +0 -15
package/dist/index.d.ts
ADDED
@@ -0,0 +1,5 @@
|
|
1
|
+
export { transferTokenFactory } from "./client/transactions/transfer/service.transfer";
|
2
|
+
export { accountFactory } from "./client/wallet/service.account";
|
3
|
+
export { WalletTypes } from "./client/wallet/wallet.types";
|
4
|
+
import cryptoUtils from "./utils/crypto";
|
5
|
+
export default cryptoUtils;
|
package/dist/index.js
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
+
};
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
+
exports.WalletTypes = exports.accountFactory = exports.transferTokenFactory = void 0;
|
7
|
+
var service_transfer_1 = require("./client/transactions/transfer/service.transfer");
|
8
|
+
Object.defineProperty(exports, "transferTokenFactory", { enumerable: true, get: function () { return service_transfer_1.transferTokenFactory; } });
|
9
|
+
var service_account_1 = require("./client/wallet/service.account");
|
10
|
+
Object.defineProperty(exports, "accountFactory", { enumerable: true, get: function () { return service_account_1.accountFactory; } });
|
11
|
+
var wallet_types_1 = require("./client/wallet/wallet.types");
|
12
|
+
Object.defineProperty(exports, "WalletTypes", { enumerable: true, get: function () { return wallet_types_1.WalletTypes; } });
|
13
|
+
const crypto_1 = __importDefault(require("./utils/crypto"));
|
14
|
+
exports.default = crypto_1.default;
|
package/package.json
CHANGED
@@ -1,9 +1,15 @@
|
|
1
1
|
{
|
2
2
|
"name": "lunesjs",
|
3
|
-
"version": "1.5.
|
4
|
-
"description": "
|
5
|
-
"main": "dist
|
6
|
-
"types": "dist
|
3
|
+
"version": "1.5.9",
|
4
|
+
"description": "Li™brary for communication with nodes in mainnet or testnet of the lunes-blockchain network",
|
5
|
+
"main": "dist/index.js",
|
6
|
+
"types": "dist/index.d.ts",
|
7
|
+
"files": [
|
8
|
+
"/dist",
|
9
|
+
"LICENSE",
|
10
|
+
"README.md",
|
11
|
+
"package.json"
|
12
|
+
],
|
7
13
|
"repository": "git@git.lunes.io:blockchain/labs/lunesjs.git",
|
8
14
|
"keywords": [
|
9
15
|
"blockchain",
|
@@ -1,14 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"name": "Existing Dockerfile",
|
3
|
-
"context": "..",
|
4
|
-
"dockerFile": "../Dockerfile",
|
5
|
-
"settings": {},
|
6
|
-
"extensions": [
|
7
|
-
"donjayamanne.githistory",
|
8
|
-
"esbenp.prettier-vscode",
|
9
|
-
"mhutchie.git-graph",
|
10
|
-
"Tyriar.sort-lines",
|
11
|
-
"eamodio.gitlens"
|
12
|
-
],
|
13
|
-
"postCreateCommand": "yarn install && yarn upgrade --latest"
|
14
|
-
}
|
@@ -1,48 +0,0 @@
|
|
1
|
-
name: Deploy
|
2
|
-
|
3
|
-
on:
|
4
|
-
push:
|
5
|
-
branches: [main]
|
6
|
-
|
7
|
-
jobs:
|
8
|
-
lint:
|
9
|
-
runs-on: ubuntu-latest
|
10
|
-
|
11
|
-
steps:
|
12
|
-
- uses: actions/checkout@v2
|
13
|
-
- uses: actions/setup-node@v3
|
14
|
-
|
15
|
-
- name: Install dependencies
|
16
|
-
run: yarn install -D
|
17
|
-
|
18
|
-
- name: Format Checker
|
19
|
-
run: yarn fmtc
|
20
|
-
|
21
|
-
test:
|
22
|
-
runs-on: ubuntu-latest
|
23
|
-
needs: lint
|
24
|
-
|
25
|
-
steps:
|
26
|
-
- uses: actions/checkout@v2
|
27
|
-
- uses: actions/setup-node@v3
|
28
|
-
|
29
|
-
- name: Install dependencies
|
30
|
-
run: yarn install -D
|
31
|
-
|
32
|
-
- name: Format Checker
|
33
|
-
run: yarn test
|
34
|
-
|
35
|
-
deploy-npm:
|
36
|
-
runs-on: ubuntu-latest
|
37
|
-
needs: [lint, test]
|
38
|
-
|
39
|
-
steps:
|
40
|
-
- uses: actions/checkout@v1
|
41
|
-
- uses: actions/setup-node@v1
|
42
|
-
with:
|
43
|
-
node-version: 14
|
44
|
-
- run: yarn install
|
45
|
-
- run: yarn build
|
46
|
-
- uses: JS-DevTools/npm-publish@v1
|
47
|
-
with:
|
48
|
-
token: ${{ secrets.NPM_TOKEN }}
|
@@ -1,35 +0,0 @@
|
|
1
|
-
name: Lint & Test
|
2
|
-
|
3
|
-
on:
|
4
|
-
push:
|
5
|
-
branches-ignore: [main]
|
6
|
-
pull_request:
|
7
|
-
branches: [main]
|
8
|
-
|
9
|
-
jobs:
|
10
|
-
lint:
|
11
|
-
runs-on: ubuntu-latest
|
12
|
-
|
13
|
-
steps:
|
14
|
-
- uses: actions/checkout@v2
|
15
|
-
- uses: actions/setup-node@v3
|
16
|
-
|
17
|
-
- name: Install dependencies
|
18
|
-
run: yarn install -D
|
19
|
-
|
20
|
-
- name: Format Checker
|
21
|
-
run: yarn fmtc
|
22
|
-
|
23
|
-
test:
|
24
|
-
runs-on: ubuntu-latest
|
25
|
-
needs: lint
|
26
|
-
|
27
|
-
steps:
|
28
|
-
- uses: actions/checkout@v2
|
29
|
-
- uses: actions/setup-node@v3
|
30
|
-
|
31
|
-
- name: Install dependencies
|
32
|
-
run: yarn install -D
|
33
|
-
|
34
|
-
- name: Format Checker
|
35
|
-
run: yarn test
|
package/.gitlab/.gitlab-ci.yml
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
image: node:14.18.2-alpine3.14
|
2
|
-
|
3
|
-
stages:
|
4
|
-
- test
|
5
|
-
|
6
|
-
before_script:
|
7
|
-
- yarn install
|
8
|
-
|
9
|
-
CreateReportTests:
|
10
|
-
stage: test
|
11
|
-
script:
|
12
|
-
- yarn test
|
13
|
-
artifacts:
|
14
|
-
when: always
|
15
|
-
reports:
|
16
|
-
junit: junit.xml
|
17
|
-
|
18
|
-
LintChecker:
|
19
|
-
stage: test
|
20
|
-
script:
|
21
|
-
- yarn fmt
|
package/.prettierignore
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
dist/*
|
package/.prettierrc.yml
DELETED
package/CONTRIBUTING.md
DELETED
@@ -1,51 +0,0 @@
|
|
1
|
-
# CONTRIBUTING
|
2
|
-
|
3
|
-
## What is the workflow?
|
4
|
-
|
5
|
-
1. Create and describe your **proposal/bug** in an _issue_.
|
6
|
-
2. Create a new **branch** and **merge request** with the pattern `1-my-feature`.
|
7
|
-
3. Commit your code to the commit convention.
|
8
|
-
|
9
|
-
---
|
10
|
-
|
11
|
-
## Convention of Commits and Semantic Version
|
12
|
-
|
13
|
-
### **Commit Structure**
|
14
|
-
|
15
|
-
```
|
16
|
-
type(escope): short description
|
17
|
-
|
18
|
-
What does the modification do?
|
19
|
-
why was it modified?
|
20
|
-
|
21
|
-
#issue
|
22
|
-
```
|
23
|
-
|
24
|
-
- **fix** Fix a bug
|
25
|
-
- **add** Add a new feature
|
26
|
-
- **remove** Remove a peace of code
|
27
|
-
- **deprecate** compatibility break
|
28
|
-
- **update** Update any thing. e.g. feature, piece, refact
|
29
|
-
|
30
|
-
### **Semantic Version**
|
31
|
-
|
32
|
-
- **deprecate** -> _Major_
|
33
|
-
- **add** -> _Minor_
|
34
|
-
- **fix** -> _Patch_
|
35
|
-
|
36
|
-
---
|
37
|
-
|
38
|
-
## References
|
39
|
-
|
40
|
-
- [Good Practices](https://bestpractices.coreinfrastructure.org/pt-BR)
|
41
|
-
- [Semantic Versioning](https://semver.org/lang/pt-BR/)
|
42
|
-
- [More about Versioning](http://www.modelcvs.org/versioning/)
|
43
|
-
- [Versioning Automate](https://bhuwanupadhyay.github.io/2020/04/applying-semantic-versioning-with-git-repository/)
|
44
|
-
- [Conventional Commit](https://www.conventionalcommits.org/en/v1.0.0-beta.2/#why-use-conventional-commits)
|
45
|
-
- [Default Angular Commit](https://github.com/angular/angular/blob/22b96b9/CONTRIBUTING.md#-commit-message-guidelines)
|
46
|
-
- [Global hook for repositories](https://docs.gitlab.com/ce/administration/server_hooks.html#set-a-global-server-hook-for-all-repositories)
|
47
|
-
- [More about Commits](https://chris.beams.io/posts/git-commit/)
|
48
|
-
- [Quick Actions for Commits](https://docs.gitlab.com/ee/user/project/quick_actions.html)
|
49
|
-
- [Commits examples](https://docs.google.com/document/d/1QrDFcIiPjSLDn3EL15IJygNPiHORgU1_OOAqWjiDU5Y/edit#)
|
50
|
-
- [Full Tutorial Add Convetional Commit as default](https://prahladyeri.com/blog/2019/06/how-to-enforce-conventional-commit-messages-using-git-hooks.html)
|
51
|
-
- [Create a global git commit hook](https://coderwall.com/p/jp7d5q/create-a-global-git-commit-hook)
|
package/Dockerfile
DELETED
package/jest.config.js
DELETED
@@ -1,11 +0,0 @@
|
|
1
|
-
/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */
|
2
|
-
const root = "./"
|
3
|
-
|
4
|
-
module.exports = {
|
5
|
-
reporters: ["default", "jest-junit"],
|
6
|
-
rootDir: root,
|
7
|
-
displayName: "based-tests",
|
8
|
-
testMatch: ["<rootDir>/test/**/*.test.ts"],
|
9
|
-
testEnvironment: "node",
|
10
|
-
preset: "ts-jest"
|
11
|
-
}
|
@@ -1,58 +0,0 @@
|
|
1
|
-
import { TransactionsTypes } from "../transactions.types"
|
2
|
-
import { WalletTypes } from "../../wallet/wallet.types"
|
3
|
-
import { BaseTransaction } from "../BaseTransaction"
|
4
|
-
import { ITransfer } from "./transfer.types"
|
5
|
-
import validator from "./validator"
|
6
|
-
import * as wasm from "lunesrs"
|
7
|
-
|
8
|
-
class TransferToken implements BaseTransaction {
|
9
|
-
private tx: ITransfer
|
10
|
-
constructor(tx: ITransfer) {
|
11
|
-
this.tx = tx
|
12
|
-
}
|
13
|
-
|
14
|
-
transaction(): ITransfer {
|
15
|
-
return this.tx
|
16
|
-
}
|
17
|
-
|
18
|
-
sign(privateKey: WalletTypes.PrivateKey): ITransfer {
|
19
|
-
this.tx.signature = validator.sign(privateKey, this.tx)
|
20
|
-
return this.tx
|
21
|
-
}
|
22
|
-
|
23
|
-
async send() {
|
24
|
-
validator.send(this.tx)
|
25
|
-
}
|
26
|
-
}
|
27
|
-
|
28
|
-
export function transferTokenFactory(
|
29
|
-
senderPublicKey: string,
|
30
|
-
recipient: string,
|
31
|
-
amount: number,
|
32
|
-
assetId?: string,
|
33
|
-
chain?: WalletTypes.Chain,
|
34
|
-
timestamp?: number,
|
35
|
-
feeAsset?: string,
|
36
|
-
fee?: number
|
37
|
-
): TransferToken {
|
38
|
-
const chain_id = chain != undefined ? chain : WalletTypes.Chain.Mainnet
|
39
|
-
if (
|
40
|
-
false == validator.ready(senderPublicKey, recipient, amount, chain_id)
|
41
|
-
) {
|
42
|
-
throw new Error("dados invalidos")
|
43
|
-
}
|
44
|
-
return new TransferToken({
|
45
|
-
senderPublicKey: senderPublicKey,
|
46
|
-
recipient: recipient,
|
47
|
-
amount: amount,
|
48
|
-
sender: wasm.arrayToBase58(
|
49
|
-
wasm.toAddress(1, chain_id, wasm.base58ToArray(senderPublicKey))
|
50
|
-
),
|
51
|
-
timestamp: timestamp != undefined ? timestamp : new Date().getTime(),
|
52
|
-
feeAsset: feeAsset != undefined ? feeAsset : "",
|
53
|
-
assetId: assetId != undefined ? assetId : "",
|
54
|
-
type: TransactionsTypes.TransferToken.int,
|
55
|
-
fee: fee != undefined ? fee : TransactionsTypes.TransferToken.fee,
|
56
|
-
signature: ""
|
57
|
-
})
|
58
|
-
}
|
@@ -1,92 +0,0 @@
|
|
1
|
-
import { WalletTypes } from "../../wallet/wallet.types"
|
2
|
-
import { TransactionsTypes } from "../transactions.types"
|
3
|
-
import cryptoUtils from "../../../utils/crypto"
|
4
|
-
import { ITransfer } from "./transfer.types"
|
5
|
-
import * as wasm from "lunesrs"
|
6
|
-
import axios from "axios"
|
7
|
-
|
8
|
-
const validator = {
|
9
|
-
serialize: (
|
10
|
-
senderPublicKey: string,
|
11
|
-
assetId: string,
|
12
|
-
feeAsset: string,
|
13
|
-
timestamp: number,
|
14
|
-
amount: number,
|
15
|
-
fee: number,
|
16
|
-
recipient: string
|
17
|
-
) => {
|
18
|
-
const tokenId: Uint8Array =
|
19
|
-
assetId != ""
|
20
|
-
? new Uint8Array([1, ...wasm.base58ToArray(assetId)])
|
21
|
-
: new Uint8Array([0])
|
22
|
-
const tokenFee: Uint8Array =
|
23
|
-
feeAsset != ""
|
24
|
-
? new Uint8Array([1, ...wasm.base58ToArray(feeAsset)])
|
25
|
-
: new Uint8Array([0])
|
26
|
-
|
27
|
-
return new Uint8Array([
|
28
|
-
...[TransactionsTypes.TransferToken.int],
|
29
|
-
...wasm.base58ToArray(senderPublicKey),
|
30
|
-
...tokenId,
|
31
|
-
...tokenFee,
|
32
|
-
...wasm.serializeUInteger(BigInt(timestamp)),
|
33
|
-
...wasm.serializeUInteger(BigInt(amount)),
|
34
|
-
...wasm.serializeUInteger(BigInt(fee)),
|
35
|
-
...wasm.base58ToArray(recipient)
|
36
|
-
])
|
37
|
-
},
|
38
|
-
ready: (
|
39
|
-
senderPublicKey: string,
|
40
|
-
recipient: string,
|
41
|
-
amount: number,
|
42
|
-
chain: WalletTypes.Chain
|
43
|
-
): boolean => {
|
44
|
-
const sender = wasm.arrayToBase58(
|
45
|
-
wasm.toAddress(1, chain, wasm.base58ToArray(senderPublicKey))
|
46
|
-
)
|
47
|
-
if (amount <= 0) {
|
48
|
-
return false
|
49
|
-
} else if (
|
50
|
-
!(
|
51
|
-
cryptoUtils.validateAddress(sender, chain) === true &&
|
52
|
-
cryptoUtils.validateAddress(recipient, chain) === true
|
53
|
-
)
|
54
|
-
) {
|
55
|
-
return false
|
56
|
-
} else {
|
57
|
-
return true
|
58
|
-
}
|
59
|
-
},
|
60
|
-
sign: (privateKey: WalletTypes.PrivateKey, tx: ITransfer): string => {
|
61
|
-
const message = validator.serialize(
|
62
|
-
tx.senderPublicKey,
|
63
|
-
tx.assetId,
|
64
|
-
tx.feeAsset,
|
65
|
-
tx.timestamp,
|
66
|
-
tx.amount,
|
67
|
-
tx.fee,
|
68
|
-
tx.recipient
|
69
|
-
)
|
70
|
-
|
71
|
-
return cryptoUtils.fastSignature(
|
72
|
-
privateKey,
|
73
|
-
wasm.arrayToBase58(new Uint8Array(message))
|
74
|
-
)
|
75
|
-
},
|
76
|
-
send: async (tx: ITransfer) => {
|
77
|
-
await axios
|
78
|
-
.request({
|
79
|
-
url: "https://lunesnode.lunes.io/transactions/broadcast",
|
80
|
-
method: "post",
|
81
|
-
data: tx
|
82
|
-
})
|
83
|
-
.then((x) => {
|
84
|
-
console.log(x)
|
85
|
-
})
|
86
|
-
.catch((error) => {
|
87
|
-
console.error(error.response.data)
|
88
|
-
})
|
89
|
-
}
|
90
|
-
}
|
91
|
-
|
92
|
-
export default validator
|