lunesjs 1.5.7 → 1.5.10

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.
Files changed (44) hide show
  1. package/package.json +14 -8
  2. package/.devcontainer/devcontainer.json +0 -14
  3. package/.github/workflows/deploy.yml +0 -48
  4. package/.github/workflows/test.yml +0 -35
  5. package/.gitlab/.gitlab-ci.yml +0 -21
  6. package/.gitlab/issue_templates/bug.md +0 -13
  7. package/.gitlab/issue_templates/proposal.md +0 -5
  8. package/.gitlab/merge_request_templates/MR.md +0 -7
  9. package/.prettierrc.yml +0 -3
  10. package/CHANGELOG.md +0 -3
  11. package/CONTRIBUTING.md +0 -51
  12. package/Dockerfile +0 -6
  13. package/dist/client/transactions/BaseTransaction.d.ts +0 -6
  14. package/dist/client/transactions/BaseTransaction.js +0 -2
  15. package/dist/client/transactions/transactions.types.d.ts +0 -10
  16. package/dist/client/transactions/transactions.types.js +0 -17
  17. package/dist/client/transactions/transfer/service.transfer.d.ts +0 -12
  18. package/dist/client/transactions/transfer/service.transfer.js +0 -78
  19. package/dist/client/transactions/transfer/transfer.types.d.ts +0 -12
  20. package/dist/client/transactions/transfer/transfer.types.js +0 -2
  21. package/dist/client/transactions/transfer/validator.d.ts +0 -9
  22. package/dist/client/transactions/transfer/validator.js +0 -93
  23. package/dist/client/wallet/constants.d.ts +0 -8
  24. package/dist/client/wallet/constants.js +0 -2064
  25. package/dist/client/wallet/service.account.d.ts +0 -20
  26. package/dist/client/wallet/service.account.js +0 -35
  27. package/dist/client/wallet/wallet.types.d.ts +0 -21
  28. package/dist/client/wallet/wallet.types.js +0 -11
  29. package/dist/utils/crypto.d.ts +0 -13
  30. package/dist/utils/crypto.js +0 -102
  31. package/jest.config.js +0 -11
  32. package/src/client/transactions/BaseTransaction.ts +0 -7
  33. package/src/client/transactions/transactions.types.ts +0 -11
  34. package/src/client/transactions/transfer/service.transfer.ts +0 -58
  35. package/src/client/transactions/transfer/transfer.types.ts +0 -12
  36. package/src/client/transactions/transfer/validator.ts +0 -92
  37. package/src/client/wallet/constants.ts +0 -2065
  38. package/src/client/wallet/service.account.ts +0 -74
  39. package/src/client/wallet/wallet.types.ts +0 -23
  40. package/src/utils/crypto.ts +0 -109
  41. package/static/img/jslogo.png +0 -0
  42. package/test/client/transactions/transfer/transfer.token.test.ts +0 -97
  43. package/test/client/wallet/service.account.test.ts +0 -330
  44. package/tsconfig.json +0 -15
@@ -1,20 +0,0 @@
1
- import { IAccount } from "./wallet.types";
2
- declare class Account implements IAccount {
3
- privateKey: string;
4
- publicKey: string;
5
- address: string;
6
- chain: number;
7
- nonce: number;
8
- seed: string;
9
- constructor(wallet: IAccount);
10
- }
11
- export declare function accountFactory({ privateKey, publicKey, address, nWords, chain, nonce, seed }?: {
12
- privateKey?: string;
13
- publicKey?: string;
14
- address?: string;
15
- nWords?: number;
16
- chain?: number;
17
- nonce?: number;
18
- seed?: string;
19
- }): Account;
20
- export {};
@@ -1,35 +0,0 @@
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.accountFactory = void 0;
7
- const crypto_1 = __importDefault(require("../../utils/crypto"));
8
- class Account {
9
- constructor(wallet) {
10
- this.privateKey = wallet.privateKey;
11
- this.publicKey = wallet.publicKey;
12
- this.address = wallet.address;
13
- this.chain = wallet.chain;
14
- this.nonce = wallet.nonce;
15
- this.seed = wallet.seed;
16
- }
17
- }
18
- function accountFactory({ privateKey, publicKey, address, nWords, chain, nonce, seed } = {}) {
19
- if (seed != undefined) {
20
- return new Account(Object.assign({}, crypto_1.default.fromExistingSeed(seed, nonce != undefined ? nonce : 0, chain != undefined ? chain : 1)));
21
- }
22
- else if (privateKey != undefined) {
23
- return new Account(Object.assign({}, crypto_1.default.fromPrivateKey(privateKey, chain != undefined ? chain : 1)));
24
- }
25
- else if (publicKey != undefined) {
26
- return new Account(Object.assign({}, crypto_1.default.fromPublicKey(publicKey, chain != undefined ? chain : 1)));
27
- }
28
- else if (address != undefined) {
29
- return new Account(Object.assign({}, crypto_1.default.fromAddress(address, chain != undefined ? chain : 0)));
30
- }
31
- else {
32
- return new Account(Object.assign({}, crypto_1.default.fromNewSeed(nWords != undefined ? nWords : 12, nonce != undefined ? nonce : 0, chain != undefined ? chain : 1)));
33
- }
34
- }
35
- exports.accountFactory = accountFactory;
@@ -1,21 +0,0 @@
1
- export declare type empty = "";
2
- export declare type zero = 0;
3
- export declare namespace WalletTypes {
4
- type Seed = string | empty;
5
- type Nonce = number | zero;
6
- enum Chain {
7
- Mainnet = 1,
8
- Testnet = 0
9
- }
10
- type PrivateKey = string | empty;
11
- type PublicKey = string | empty;
12
- type Address = string | empty;
13
- }
14
- export interface IAccount {
15
- privateKey: WalletTypes.PrivateKey;
16
- publicKey: WalletTypes.PublicKey;
17
- address: WalletTypes.Address;
18
- nonce: WalletTypes.Nonce;
19
- chain: WalletTypes.Chain;
20
- seed: WalletTypes.Seed;
21
- }
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.WalletTypes = void 0;
4
- var WalletTypes;
5
- (function (WalletTypes) {
6
- let Chain;
7
- (function (Chain) {
8
- Chain[Chain["Mainnet"] = 1] = "Mainnet";
9
- Chain[Chain["Testnet"] = 0] = "Testnet";
10
- })(Chain = WalletTypes.Chain || (WalletTypes.Chain = {}));
11
- })(WalletTypes = exports.WalletTypes || (exports.WalletTypes = {}));
@@ -1,13 +0,0 @@
1
- import { IAccount, WalletTypes } from "../client/wallet/wallet.types";
2
- declare const cryptoUtils: {
3
- fromExistingSeed: (seed: string, nonce: number, chain: WalletTypes.Chain) => IAccount;
4
- fromPrivateKey: (privateKey: string, chain: WalletTypes.Chain) => IAccount;
5
- fromPublicKey: (publicKey: string, chain: WalletTypes.Chain) => IAccount;
6
- fromAddress: (address: string, chain: WalletTypes.Chain) => IAccount;
7
- fromNewSeed: (nWords: number, nonce: number, chain: WalletTypes.Chain) => IAccount;
8
- validateAddress: (address: string, chain: WalletTypes.Chain) => boolean;
9
- validateSignature: (publicKey: string, message: string, signature: string) => boolean;
10
- fastSignature: (privateKey: string, message: string) => string;
11
- fullSignature: (privateKey: string, message: string) => string;
12
- };
13
- export default cryptoUtils;
@@ -1,102 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- const constants_1 = __importDefault(require("../client/wallet/constants"));
30
- const wasm = __importStar(require("lunesrs"));
31
- const cryptoUtils = {
32
- fromExistingSeed: (seed, nonce, chain) => {
33
- const hidden_seed = wasm.hiddenSeed(nonce, seed);
34
- const privateKey = wasm.toPrivateKey(hidden_seed);
35
- const publicKey = wasm.toPublicKey(privateKey);
36
- const address = wasm.toAddress(1, chain, publicKey);
37
- return {
38
- nonce: nonce,
39
- chain: chain,
40
- seed: seed,
41
- privateKey: wasm.arrayToBase58(privateKey),
42
- publicKey: wasm.arrayToBase58(publicKey),
43
- address: wasm.arrayToBase58(address)
44
- };
45
- },
46
- fromPrivateKey: (privateKey, chain) => {
47
- const publicKey = wasm.toPublicKey(wasm.base58ToArray(privateKey));
48
- const address = wasm.toAddress(1, chain, publicKey);
49
- return {
50
- seed: "",
51
- nonce: 0,
52
- chain: chain,
53
- privateKey: privateKey,
54
- publicKey: wasm.arrayToBase58(publicKey),
55
- address: wasm.arrayToBase58(address)
56
- };
57
- },
58
- fromPublicKey: (publicKey, chain) => {
59
- const address = wasm.toAddress(1, chain, wasm.base58ToArray(publicKey));
60
- return {
61
- seed: "",
62
- nonce: 0,
63
- privateKey: "",
64
- chain: chain,
65
- publicKey: publicKey,
66
- address: wasm.arrayToBase58(address)
67
- };
68
- },
69
- fromAddress: (address, chain) => {
70
- return {
71
- seed: "",
72
- nonce: 0,
73
- privateKey: "",
74
- publicKey: "",
75
- chain: chain,
76
- address: address
77
- };
78
- },
79
- fromNewSeed: (nWords, nonce, chain) => {
80
- let seed = [];
81
- nWords = nWords != undefined ? Math.round(nWords / 3) : 4;
82
- for (let i = 0; i < nWords; i++) {
83
- for (let n in wasm.randomTripleNumber()) {
84
- seed.push(constants_1.default.wordsList[n]);
85
- }
86
- }
87
- return cryptoUtils.fromExistingSeed(seed.join(" "), nonce, chain);
88
- },
89
- validateAddress: (address, chain) => {
90
- return wasm.validateAddress(chain, wasm.base58ToArray(address));
91
- },
92
- validateSignature: (publicKey, message, signature) => {
93
- return wasm.validateSignature(wasm.base58ToArray(publicKey), wasm.base58ToArray(message), wasm.base58ToArray(signature));
94
- },
95
- fastSignature: (privateKey, message) => {
96
- return wasm.arrayToBase58(wasm.fastSignature(wasm.base58ToArray(privateKey), wasm.base58ToArray(message)));
97
- },
98
- fullSignature: (privateKey, message) => {
99
- return wasm.arrayToBase58(wasm.fullSignature(wasm.base58ToArray(privateKey), wasm.base58ToArray(message)));
100
- }
101
- };
102
- exports.default = cryptoUtils;
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,7 +0,0 @@
1
- import { WalletTypes } from "../wallet/wallet.types"
2
-
3
- export interface BaseTransaction {
4
- sign(privateKey: WalletTypes.PrivateKey): object
5
- transaction(): object
6
- send(): object
7
- }
@@ -1,11 +0,0 @@
1
- export namespace TransactionsTypes {
2
- export enum TransferToken {
3
- int = 4,
4
- fee = 1000000
5
- }
6
- export enum IssueToken {
7
- int = 5,
8
- fee = 1000000000
9
- }
10
- //...
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
- chain?: WalletTypes.Chain,
33
- timestamp?: number,
34
- feeAsset?: string,
35
- assetId?: 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,12 +0,0 @@
1
- export interface ITransfer {
2
- senderPublicKey: string
3
- timestamp: number
4
- signature: string
5
- recipient: string
6
- feeAsset: string
7
- assetId: string
8
- amount: number
9
- sender: string
10
- type: number
11
- fee: number
12
- }
@@ -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