lunesjs 1.5.12 → 1.5.14

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ # CHANGELOG
2
+
3
+ # [v0.0.0]
@@ -1,6 +1,6 @@
1
- import { WalletTypes } from "../wallet/wallet.types"
1
+ import { WalletTypes } from "../wallet/wallet.types";
2
2
  export interface BaseTransaction {
3
- sign(privateKey: WalletTypes.PrivateKey): object
4
- transaction(): object
5
- send(): object
3
+ sign(privateKey: WalletTypes.PrivateKey): object;
4
+ transaction(): object;
5
+ send(): object;
6
6
  }
@@ -1,2 +1,2 @@
1
- "use strict"
2
- Object.defineProperty(exports, "__esModule", { value: true })
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,27 +1,17 @@
1
- "use strict"
2
- Object.defineProperty(exports, "__esModule", { value: true })
3
- exports.TransactionsTypes = void 0
4
- var TransactionsTypes
5
- ;(function (TransactionsTypes) {
6
- let TransferToken
7
- ;(function (TransferToken) {
8
- TransferToken[(TransferToken["int"] = 4)] = "int"
9
- TransferToken[(TransferToken["fee"] = 1000000)] = "fee"
10
- })(
11
- (TransferToken =
12
- TransactionsTypes.TransferToken ||
13
- (TransactionsTypes.TransferToken = {}))
14
- )
15
- let IssueToken
16
- ;(function (IssueToken) {
17
- IssueToken[(IssueToken["int"] = 5)] = "int"
18
- IssueToken[(IssueToken["fee"] = 1000000000)] = "fee"
19
- })(
20
- (IssueToken =
21
- TransactionsTypes.IssueToken || (TransactionsTypes.IssueToken = {}))
22
- )
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TransactionsTypes = void 0;
4
+ var TransactionsTypes;
5
+ (function (TransactionsTypes) {
6
+ let TransferToken;
7
+ (function (TransferToken) {
8
+ TransferToken[TransferToken["int"] = 4] = "int";
9
+ TransferToken[TransferToken["fee"] = 1000000] = "fee";
10
+ })(TransferToken = TransactionsTypes.TransferToken || (TransactionsTypes.TransferToken = {}));
11
+ let IssueToken;
12
+ (function (IssueToken) {
13
+ IssueToken[IssueToken["int"] = 5] = "int";
14
+ IssueToken[IssueToken["fee"] = 1000000000] = "fee";
15
+ })(IssueToken = TransactionsTypes.IssueToken || (TransactionsTypes.IssueToken = {}));
23
16
  //...
24
- })(
25
- (TransactionsTypes =
26
- exports.TransactionsTypes || (exports.TransactionsTypes = {}))
27
- )
17
+ })(TransactionsTypes = exports.TransactionsTypes || (exports.TransactionsTypes = {}));
@@ -1,21 +1,12 @@
1
- import { WalletTypes } from "../../wallet/wallet.types"
2
- import { BaseTransaction } from "../BaseTransaction"
3
- import { ITransfer } from "./transfer.types"
1
+ import { WalletTypes } from "../../wallet/wallet.types";
2
+ import { BaseTransaction } from "../BaseTransaction";
3
+ import { ITransfer } from "./transfer.types";
4
4
  declare class TransferToken implements BaseTransaction {
5
- private tx
6
- constructor(tx: ITransfer)
7
- transaction(): ITransfer
8
- sign(privateKey: WalletTypes.PrivateKey): ITransfer
9
- send(): Promise<void>
5
+ private tx;
6
+ constructor(tx: ITransfer);
7
+ transaction(): ITransfer;
8
+ sign(privateKey: WalletTypes.PrivateKey): ITransfer;
9
+ send(): Promise<void>;
10
10
  }
11
- export declare function transferTokenFactory(
12
- senderPublicKey: string,
13
- recipient: string,
14
- amount: number,
15
- assetId?: string,
16
- chain?: WalletTypes.Chain,
17
- timestamp?: number,
18
- feeAsset?: string,
19
- fee?: number
20
- ): TransferToken
21
- export {}
11
+ export declare function transferTokenFactory(senderPublicKey: string, recipient: string, amount: number, assetId?: string, chain?: WalletTypes.Chain, timestamp?: number, feeAsset?: string, fee?: number): TransferToken;
12
+ export {};
@@ -1,153 +1,78 @@
1
- "use strict"
2
- var __createBinding =
3
- (this && this.__createBinding) ||
4
- (Object.create
5
- ? function (o, m, k, k2) {
6
- if (k2 === undefined) k2 = k
7
- var desc = Object.getOwnPropertyDescriptor(m, k)
8
- if (
9
- !desc ||
10
- ("get" in desc
11
- ? !m.__esModule
12
- : desc.writable || desc.configurable)
13
- ) {
14
- desc = {
15
- enumerable: true,
16
- get: function () {
17
- return m[k]
18
- }
19
- }
20
- }
21
- Object.defineProperty(o, k2, desc)
22
- }
23
- : function (o, m, k, k2) {
24
- if (k2 === undefined) k2 = k
25
- o[k2] = m[k]
26
- })
27
- var __setModuleDefault =
28
- (this && this.__setModuleDefault) ||
29
- (Object.create
30
- ? function (o, v) {
31
- Object.defineProperty(o, "default", {
32
- enumerable: true,
33
- value: v
34
- })
35
- }
36
- : function (o, v) {
37
- o["default"] = v
38
- })
39
- var __importStar =
40
- (this && this.__importStar) ||
41
- function (mod) {
42
- if (mod && mod.__esModule) return mod
43
- var result = {}
44
- if (mod != null)
45
- for (var k in mod)
46
- if (
47
- k !== "default" &&
48
- Object.prototype.hasOwnProperty.call(mod, k)
49
- )
50
- __createBinding(result, mod, k)
51
- __setModuleDefault(result, mod)
52
- return result
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]; } };
53
7
  }
54
- var __awaiter =
55
- (this && this.__awaiter) ||
56
- function (thisArg, _arguments, P, generator) {
57
- function adopt(value) {
58
- return value instanceof P
59
- ? value
60
- : new P(function (resolve) {
61
- resolve(value)
62
- })
63
- }
64
- return new (P || (P = Promise))(function (resolve, reject) {
65
- function fulfilled(value) {
66
- try {
67
- step(generator.next(value))
68
- } catch (e) {
69
- reject(e)
70
- }
71
- }
72
- function rejected(value) {
73
- try {
74
- step(generator["throw"](value))
75
- } catch (e) {
76
- reject(e)
77
- }
78
- }
79
- function step(result) {
80
- result.done
81
- ? resolve(result.value)
82
- : adopt(result.value).then(fulfilled, rejected)
83
- }
84
- step(
85
- (generator = generator.apply(thisArg, _arguments || [])).next()
86
- )
87
- })
88
- }
89
- var __importDefault =
90
- (this && this.__importDefault) ||
91
- function (mod) {
92
- return mod && mod.__esModule ? mod : { default: mod }
93
- }
94
- Object.defineProperty(exports, "__esModule", { value: true })
95
- exports.transferTokenFactory = void 0
96
- const transactions_types_1 = require("../transactions.types")
97
- const wallet_types_1 = require("../../wallet/wallet.types")
98
- const validator_1 = __importDefault(require("./validator"))
99
- const wasm = __importStar(require("lunesrs"))
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ exports.transferTokenFactory = void 0;
39
+ const transactions_types_1 = require("../transactions.types");
40
+ const wallet_types_1 = require("../../wallet/wallet.types");
41
+ const validator_1 = __importDefault(require("./validator"));
42
+ const wasm = __importStar(require("lunesrs"));
100
43
  class TransferToken {
101
44
  constructor(tx) {
102
- this.tx = tx
45
+ this.tx = tx;
103
46
  }
104
47
  transaction() {
105
- return this.tx
48
+ return this.tx;
106
49
  }
107
50
  sign(privateKey) {
108
- this.tx.signature = validator_1.default.sign(privateKey, this.tx)
109
- return this.tx
51
+ this.tx.signature = validator_1.default.sign(privateKey, this.tx);
52
+ return this.tx;
110
53
  }
111
54
  send() {
112
55
  return __awaiter(this, void 0, void 0, function* () {
113
- validator_1.default.send(this.tx)
114
- })
56
+ validator_1.default.send(this.tx);
57
+ });
115
58
  }
116
59
  }
117
- function transferTokenFactory(
118
- senderPublicKey,
119
- recipient,
120
- amount,
121
- assetId,
122
- chain,
123
- timestamp,
124
- feeAsset,
125
- fee
126
- ) {
127
- const chain_id =
128
- chain != undefined ? chain : wallet_types_1.WalletTypes.Chain.Mainnet
129
- if (
130
- false ==
131
- validator_1.default.ready(senderPublicKey, recipient, amount, chain_id)
132
- ) {
133
- throw new Error("dados invalidos")
60
+ function transferTokenFactory(senderPublicKey, recipient, amount, assetId, chain, timestamp, feeAsset, fee) {
61
+ const chain_id = chain != undefined ? chain : wallet_types_1.WalletTypes.Chain.Mainnet;
62
+ if (false == validator_1.default.ready(senderPublicKey, recipient, amount, chain_id)) {
63
+ throw new Error("dados invalidos");
134
64
  }
135
65
  return new TransferToken({
136
66
  senderPublicKey: senderPublicKey,
137
67
  recipient: recipient,
138
68
  amount: amount,
139
- sender: wasm.arrayToBase58(
140
- wasm.toAddress(1, chain_id, wasm.base58ToArray(senderPublicKey))
141
- ),
69
+ sender: wasm.arrayToBase58(wasm.toAddress(1, chain_id, wasm.base58ToArray(senderPublicKey))),
142
70
  timestamp: timestamp != undefined ? timestamp : new Date().getTime(),
143
71
  feeAsset: feeAsset != undefined ? feeAsset : "",
144
72
  assetId: assetId != undefined ? assetId : "",
145
73
  type: transactions_types_1.TransactionsTypes.TransferToken.int,
146
- fee:
147
- fee != undefined
148
- ? fee
149
- : transactions_types_1.TransactionsTypes.TransferToken.fee,
74
+ fee: fee != undefined ? fee : transactions_types_1.TransactionsTypes.TransferToken.fee,
150
75
  signature: ""
151
- })
76
+ });
152
77
  }
153
- exports.transferTokenFactory = transferTokenFactory
78
+ exports.transferTokenFactory = transferTokenFactory;
@@ -1,12 +1,12 @@
1
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
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
12
  }
@@ -1,2 +1,2 @@
1
- "use strict"
2
- Object.defineProperty(exports, "__esModule", { value: true })
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,22 +1,9 @@
1
- import { WalletTypes } from "../../wallet/wallet.types"
2
- import { ITransfer } from "./transfer.types"
1
+ import { WalletTypes } from "../../wallet/wallet.types";
2
+ import { ITransfer } from "./transfer.types";
3
3
  declare const validator: {
4
- serialize: (
5
- senderPublicKey: string,
6
- assetId: string,
7
- feeAsset: string,
8
- timestamp: number,
9
- amount: number,
10
- fee: number,
11
- recipient: string
12
- ) => Uint8Array
13
- ready: (
14
- senderPublicKey: string,
15
- recipient: string,
16
- amount: number,
17
- chain: WalletTypes.Chain
18
- ) => boolean
19
- sign: (privateKey: WalletTypes.PrivateKey, tx: ITransfer) => string
20
- send: (tx: ITransfer) => Promise<void>
21
- }
22
- export default validator
4
+ serialize: (senderPublicKey: string, assetId: string, feeAsset: string, timestamp: number, amount: number, fee: number, recipient: string) => Uint8Array;
5
+ ready: (senderPublicKey: string, recipient: string, amount: number, chain: WalletTypes.Chain) => boolean;
6
+ sign: (privateKey: WalletTypes.PrivateKey, tx: ITransfer) => string;
7
+ send: (tx: ITransfer) => Promise<void>;
8
+ };
9
+ export default validator;
@@ -1,119 +1,52 @@
1
- "use strict"
2
- var __createBinding =
3
- (this && this.__createBinding) ||
4
- (Object.create
5
- ? function (o, m, k, k2) {
6
- if (k2 === undefined) k2 = k
7
- var desc = Object.getOwnPropertyDescriptor(m, k)
8
- if (
9
- !desc ||
10
- ("get" in desc
11
- ? !m.__esModule
12
- : desc.writable || desc.configurable)
13
- ) {
14
- desc = {
15
- enumerable: true,
16
- get: function () {
17
- return m[k]
18
- }
19
- }
20
- }
21
- Object.defineProperty(o, k2, desc)
22
- }
23
- : function (o, m, k, k2) {
24
- if (k2 === undefined) k2 = k
25
- o[k2] = m[k]
26
- })
27
- var __setModuleDefault =
28
- (this && this.__setModuleDefault) ||
29
- (Object.create
30
- ? function (o, v) {
31
- Object.defineProperty(o, "default", {
32
- enumerable: true,
33
- value: v
34
- })
35
- }
36
- : function (o, v) {
37
- o["default"] = v
38
- })
39
- var __importStar =
40
- (this && this.__importStar) ||
41
- function (mod) {
42
- if (mod && mod.__esModule) return mod
43
- var result = {}
44
- if (mod != null)
45
- for (var k in mod)
46
- if (
47
- k !== "default" &&
48
- Object.prototype.hasOwnProperty.call(mod, k)
49
- )
50
- __createBinding(result, mod, k)
51
- __setModuleDefault(result, mod)
52
- return result
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]; } };
53
7
  }
54
- var __awaiter =
55
- (this && this.__awaiter) ||
56
- function (thisArg, _arguments, P, generator) {
57
- function adopt(value) {
58
- return value instanceof P
59
- ? value
60
- : new P(function (resolve) {
61
- resolve(value)
62
- })
63
- }
64
- return new (P || (P = Promise))(function (resolve, reject) {
65
- function fulfilled(value) {
66
- try {
67
- step(generator.next(value))
68
- } catch (e) {
69
- reject(e)
70
- }
71
- }
72
- function rejected(value) {
73
- try {
74
- step(generator["throw"](value))
75
- } catch (e) {
76
- reject(e)
77
- }
78
- }
79
- function step(result) {
80
- result.done
81
- ? resolve(result.value)
82
- : adopt(result.value).then(fulfilled, rejected)
83
- }
84
- step(
85
- (generator = generator.apply(thisArg, _arguments || [])).next()
86
- )
87
- })
88
- }
89
- var __importDefault =
90
- (this && this.__importDefault) ||
91
- function (mod) {
92
- return mod && mod.__esModule ? mod : { default: mod }
93
- }
94
- Object.defineProperty(exports, "__esModule", { value: true })
95
- const transactions_types_1 = require("../transactions.types")
96
- const crypto_1 = __importDefault(require("../../../utils/crypto"))
97
- const wasm = __importStar(require("lunesrs"))
98
- const axios_1 = __importDefault(require("axios"))
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ const transactions_types_1 = require("../transactions.types");
39
+ const crypto_1 = require("../../../utils/crypto");
40
+ const wasm = __importStar(require("lunesrs"));
41
+ const axios_1 = __importDefault(require("axios"));
99
42
  const validator = {
100
- serialize: (
101
- senderPublicKey,
102
- assetId,
103
- feeAsset,
104
- timestamp,
105
- amount,
106
- fee,
107
- recipient
108
- ) => {
109
- const tokenId =
110
- assetId != ""
111
- ? new Uint8Array([1, ...wasm.base58ToArray(assetId)])
112
- : new Uint8Array([0])
113
- const tokenFee =
114
- feeAsset != ""
115
- ? new Uint8Array([1, ...wasm.base58ToArray(feeAsset)])
116
- : new Uint8Array([0])
43
+ serialize: (senderPublicKey, assetId, feeAsset, timestamp, amount, fee, recipient) => {
44
+ const tokenId = assetId != ""
45
+ ? new Uint8Array([1, ...wasm.base58ToArray(assetId)])
46
+ : new Uint8Array([0]);
47
+ const tokenFee = feeAsset != ""
48
+ ? new Uint8Array([1, ...wasm.base58ToArray(feeAsset)])
49
+ : new Uint8Array([0]);
117
50
  return new Uint8Array([
118
51
  ...[transactions_types_1.TransactionsTypes.TransferToken.int],
119
52
  ...wasm.base58ToArray(senderPublicKey),
@@ -123,54 +56,38 @@ const validator = {
123
56
  ...wasm.serializeUInteger(BigInt(amount)),
124
57
  ...wasm.serializeUInteger(BigInt(fee)),
125
58
  ...wasm.base58ToArray(recipient)
126
- ])
59
+ ]);
127
60
  },
128
61
  ready: (senderPublicKey, recipient, amount, chain) => {
129
- const sender = wasm.arrayToBase58(
130
- wasm.toAddress(1, chain, wasm.base58ToArray(senderPublicKey))
131
- )
62
+ const sender = wasm.arrayToBase58(wasm.toAddress(1, chain, wasm.base58ToArray(senderPublicKey)));
132
63
  if (amount <= 0) {
133
- return false
134
- } else if (
135
- !(
136
- crypto_1.default.validateAddress(sender, chain) === true &&
137
- crypto_1.default.validateAddress(recipient, chain) === true
138
- )
139
- ) {
140
- return false
141
- } else {
142
- return true
64
+ return false;
65
+ }
66
+ else if (!(crypto_1.cryptoUtils.validateAddress(sender, chain) === true &&
67
+ crypto_1.cryptoUtils.validateAddress(recipient, chain) === true)) {
68
+ return false;
69
+ }
70
+ else {
71
+ return true;
143
72
  }
144
73
  },
145
74
  sign: (privateKey, tx) => {
146
- const message = validator.serialize(
147
- tx.senderPublicKey,
148
- tx.assetId,
149
- tx.feeAsset,
150
- tx.timestamp,
151
- tx.amount,
152
- tx.fee,
153
- tx.recipient
154
- )
155
- return crypto_1.default.fastSignature(
156
- privateKey,
157
- wasm.arrayToBase58(new Uint8Array(message))
158
- )
75
+ const message = validator.serialize(tx.senderPublicKey, tx.assetId, tx.feeAsset, tx.timestamp, tx.amount, tx.fee, tx.recipient);
76
+ return crypto_1.cryptoUtils.fastSignature(privateKey, wasm.arrayToBase58(new Uint8Array(message)));
159
77
  },
160
- send: (tx) =>
161
- __awaiter(void 0, void 0, void 0, function* () {
162
- yield axios_1.default
163
- .request({
164
- url: "https://lunesnode.lunes.io/transactions/broadcast",
165
- method: "post",
166
- data: tx
167
- })
168
- .then((x) => {
169
- console.log(x)
170
- })
171
- .catch((error) => {
172
- console.error(error.response.data)
173
- })
78
+ send: (tx) => __awaiter(void 0, void 0, void 0, function* () {
79
+ yield axios_1.default
80
+ .request({
81
+ url: "https://lunesnode.lunes.io/transactions/broadcast",
82
+ method: "post",
83
+ data: tx
84
+ })
85
+ .then((x) => {
86
+ console.log(x);
174
87
  })
175
- }
176
- exports.default = validator
88
+ .catch((error) => {
89
+ console.error(error.response.data);
90
+ });
91
+ })
92
+ };
93
+ exports.default = validator;
@@ -1,8 +1,8 @@
1
1
  declare const walletConstants: {
2
- addressVersion: number
3
- addressChecksumLength: number
4
- addressHashLength: number
5
- addressLength: number
6
- wordsList: string[]
7
- }
8
- export default walletConstants
2
+ addressVersion: number;
3
+ addressChecksumLength: number;
4
+ addressHashLength: number;
5
+ addressLength: number;
6
+ wordsList: string[];
7
+ };
8
+ export default walletConstants;
@@ -1,9 +1,9 @@
1
- "use strict"
2
- Object.defineProperty(exports, "__esModule", { value: true })
3
- const addressVersion = 1
4
- const addressChecksumLength = 4
5
- const addressHashLength = 20
6
- const addressLength = 1 + 1 + addressChecksumLength + addressHashLength
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const addressVersion = 1;
4
+ const addressChecksumLength = 4;
5
+ const addressHashLength = 20;
6
+ const addressLength = 1 + 1 + addressChecksumLength + addressHashLength;
7
7
  const wordsList = [
8
8
  "abandon",
9
9
  "ability",
@@ -2053,12 +2053,12 @@ const wordsList = [
2053
2053
  "zero",
2054
2054
  "zone",
2055
2055
  "zoo"
2056
- ]
2056
+ ];
2057
2057
  const walletConstants = {
2058
2058
  addressVersion,
2059
2059
  addressChecksumLength,
2060
2060
  addressHashLength,
2061
2061
  addressLength,
2062
2062
  wordsList
2063
- }
2064
- exports.default = walletConstants
2063
+ };
2064
+ exports.default = walletConstants;
@@ -1,28 +1,20 @@
1
- import { IAccount } from "./wallet.types"
1
+ import { IAccount } from "./wallet.types";
2
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)
3
+ privateKey: string;
4
+ publicKey: string;
5
+ address: string;
6
+ chain: number;
7
+ nonce: number;
8
+ seed: string;
9
+ constructor(wallet: IAccount);
10
10
  }
11
- export declare function accountFactory({
12
- privateKey,
13
- publicKey,
14
- address,
15
- nWords,
16
- chain,
17
- nonce,
18
- seed
19
- }?: {
20
- privateKey?: string
21
- publicKey?: string
22
- address?: string
23
- nWords?: number
24
- chain?: number
25
- nonce?: number
26
- seed?: string
27
- }): Account
28
- export {}
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,83 +1,32 @@
1
- "use strict"
2
- var __importDefault =
3
- (this && this.__importDefault) ||
4
- function (mod) {
5
- return mod && mod.__esModule ? mod : { default: mod }
6
- }
7
- Object.defineProperty(exports, "__esModule", { value: true })
8
- exports.accountFactory = void 0
9
- const crypto_1 = __importDefault(require("../../utils/crypto"))
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.accountFactory = void 0;
4
+ const crypto_1 = require("../../utils/crypto");
10
5
  class Account {
11
6
  constructor(wallet) {
12
- this.privateKey = wallet.privateKey
13
- this.publicKey = wallet.publicKey
14
- this.address = wallet.address
15
- this.chain = wallet.chain
16
- this.nonce = wallet.nonce
17
- this.seed = wallet.seed
7
+ this.privateKey = wallet.privateKey;
8
+ this.publicKey = wallet.publicKey;
9
+ this.address = wallet.address;
10
+ this.chain = wallet.chain;
11
+ this.nonce = wallet.nonce;
12
+ this.seed = wallet.seed;
18
13
  }
19
14
  }
20
- function accountFactory({
21
- privateKey,
22
- publicKey,
23
- address,
24
- nWords,
25
- chain,
26
- nonce,
27
- seed
28
- } = {}) {
15
+ function accountFactory({ privateKey, publicKey, address, nWords, chain, nonce, seed } = {}) {
29
16
  if (seed != undefined) {
30
- return new Account(
31
- Object.assign(
32
- {},
33
- crypto_1.default.fromExistingSeed(
34
- seed,
35
- nonce != undefined ? nonce : 0,
36
- chain != undefined ? chain : 1
37
- )
38
- )
39
- )
40
- } else if (privateKey != undefined) {
41
- return new Account(
42
- Object.assign(
43
- {},
44
- crypto_1.default.fromPrivateKey(
45
- privateKey,
46
- chain != undefined ? chain : 1
47
- )
48
- )
49
- )
50
- } else if (publicKey != undefined) {
51
- return new Account(
52
- Object.assign(
53
- {},
54
- crypto_1.default.fromPublicKey(
55
- publicKey,
56
- chain != undefined ? chain : 1
57
- )
58
- )
59
- )
60
- } else if (address != undefined) {
61
- return new Account(
62
- Object.assign(
63
- {},
64
- crypto_1.default.fromAddress(
65
- address,
66
- chain != undefined ? chain : 0
67
- )
68
- )
69
- )
70
- } else {
71
- return new Account(
72
- Object.assign(
73
- {},
74
- crypto_1.default.fromNewSeed(
75
- nWords != undefined ? nWords : 12,
76
- nonce != undefined ? nonce : 0,
77
- chain != undefined ? chain : 1
78
- )
79
- )
80
- )
17
+ return new Account(Object.assign({}, crypto_1.cryptoUtils.fromExistingSeed(seed, nonce != undefined ? nonce : 0, chain != undefined ? chain : 1)));
18
+ }
19
+ else if (privateKey != undefined) {
20
+ return new Account(Object.assign({}, crypto_1.cryptoUtils.fromPrivateKey(privateKey, chain != undefined ? chain : 1)));
21
+ }
22
+ else if (publicKey != undefined) {
23
+ return new Account(Object.assign({}, crypto_1.cryptoUtils.fromPublicKey(publicKey, chain != undefined ? chain : 1)));
24
+ }
25
+ else if (address != undefined) {
26
+ return new Account(Object.assign({}, crypto_1.cryptoUtils.fromAddress(address, chain != undefined ? chain : 0)));
27
+ }
28
+ else {
29
+ return new Account(Object.assign({}, crypto_1.cryptoUtils.fromNewSeed(nWords != undefined ? nWords : 12, nonce != undefined ? nonce : 0, chain != undefined ? chain : 1)));
81
30
  }
82
31
  }
83
- exports.accountFactory = accountFactory
32
+ exports.accountFactory = accountFactory;
@@ -1,21 +1,21 @@
1
- export declare type empty = ""
2
- export declare type zero = 0
1
+ export declare type empty = "";
2
+ export declare type zero = 0;
3
3
  export declare namespace WalletTypes {
4
- type Seed = string | empty
5
- type Nonce = number | zero
4
+ type Seed = string | empty;
5
+ type Nonce = number | zero;
6
6
  enum Chain {
7
7
  Mainnet = 1,
8
8
  Testnet = 0
9
9
  }
10
- type PrivateKey = string | empty
11
- type PublicKey = string | empty
12
- type Address = string | empty
10
+ type PrivateKey = string | empty;
11
+ type PublicKey = string | empty;
12
+ type Address = string | empty;
13
13
  }
14
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
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
21
  }
@@ -1,11 +1,11 @@
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
+ "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 = {}));
package/lib/index.d.ts CHANGED
@@ -1,5 +1,18 @@
1
- export { transferTokenFactory } from "./client/transactions/transfer/service.transfer"
2
- export { accountFactory } from "./client/wallet/service.account"
3
- export { IAccount } from "./client/wallet/wallet.types"
4
- import cryptoUtils from "./utils/crypto"
5
- export default cryptoUtils
1
+ import { transferTokenFactory } from "./client/transactions/transfer/service.transfer";
2
+ import { accountFactory } from "./client/wallet/service.account";
3
+ declare const _default: {
4
+ transferTokenFactory: typeof transferTokenFactory;
5
+ accountFactory: typeof accountFactory;
6
+ cryptoUtils: {
7
+ fromExistingSeed: (seed: string, nonce: number, chain: import("./client/wallet/wallet.types").WalletTypes.Chain) => import("./client/wallet/wallet.types").IAccount;
8
+ fromPrivateKey: (privateKey: string, chain: import("./client/wallet/wallet.types").WalletTypes.Chain) => import("./client/wallet/wallet.types").IAccount;
9
+ fromPublicKey: (publicKey: string, chain: import("./client/wallet/wallet.types").WalletTypes.Chain) => import("./client/wallet/wallet.types").IAccount;
10
+ fromAddress: (address: string, chain: import("./client/wallet/wallet.types").WalletTypes.Chain) => import("./client/wallet/wallet.types").IAccount;
11
+ fromNewSeed: (nWords: number, nonce: number, chain: import("./client/wallet/wallet.types").WalletTypes.Chain) => import("./client/wallet/wallet.types").IAccount;
12
+ validateAddress: (address: string, chain: import("./client/wallet/wallet.types").WalletTypes.Chain) => boolean;
13
+ validateSignature: (publicKey: string, message: string, signature: string) => boolean;
14
+ fastSignature: (privateKey: string, message: string) => string;
15
+ fullSignature: (privateKey: string, message: string) => string;
16
+ };
17
+ };
18
+ export default _default;
package/lib/index.js CHANGED
@@ -1,24 +1,10 @@
1
- "use strict"
2
- var __importDefault =
3
- (this && this.__importDefault) ||
4
- function (mod) {
5
- return mod && mod.__esModule ? mod : { default: mod }
6
- }
7
- Object.defineProperty(exports, "__esModule", { value: true })
8
- exports.accountFactory = exports.transferTokenFactory = void 0
9
- var service_transfer_1 = require("./client/transactions/transfer/service.transfer")
10
- Object.defineProperty(exports, "transferTokenFactory", {
11
- enumerable: true,
12
- get: function () {
13
- return service_transfer_1.transferTokenFactory
14
- }
15
- })
16
- var service_account_1 = require("./client/wallet/service.account")
17
- Object.defineProperty(exports, "accountFactory", {
18
- enumerable: true,
19
- get: function () {
20
- return service_account_1.accountFactory
21
- }
22
- })
23
- const crypto_1 = __importDefault(require("./utils/crypto"))
24
- exports.default = crypto_1.default
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const service_transfer_1 = require("./client/transactions/transfer/service.transfer");
4
+ const service_account_1 = require("./client/wallet/service.account");
5
+ const crypto_1 = require("./utils/crypto");
6
+ exports.default = {
7
+ transferTokenFactory: service_transfer_1.transferTokenFactory,
8
+ accountFactory: service_account_1.accountFactory,
9
+ cryptoUtils: crypto_1.cryptoUtils
10
+ };
@@ -1,25 +1,12 @@
1
- import { IAccount, WalletTypes } from "../client/wallet/wallet.types"
2
- declare const cryptoUtils: {
3
- fromExistingSeed: (
4
- seed: string,
5
- nonce: number,
6
- chain: WalletTypes.Chain
7
- ) => IAccount
8
- fromPrivateKey: (privateKey: string, chain: WalletTypes.Chain) => IAccount
9
- fromPublicKey: (publicKey: string, chain: WalletTypes.Chain) => IAccount
10
- fromAddress: (address: string, chain: WalletTypes.Chain) => IAccount
11
- fromNewSeed: (
12
- nWords: number,
13
- nonce: number,
14
- chain: WalletTypes.Chain
15
- ) => IAccount
16
- validateAddress: (address: string, chain: WalletTypes.Chain) => boolean
17
- validateSignature: (
18
- publicKey: string,
19
- message: string,
20
- signature: string
21
- ) => boolean
22
- fastSignature: (privateKey: string, message: string) => string
23
- fullSignature: (privateKey: string, message: string) => string
24
- }
25
- export default cryptoUtils
1
+ import { IAccount, WalletTypes } from "../client/wallet/wallet.types";
2
+ export 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
+ };
@@ -1,70 +1,40 @@
1
- "use strict"
2
- var __createBinding =
3
- (this && this.__createBinding) ||
4
- (Object.create
5
- ? function (o, m, k, k2) {
6
- if (k2 === undefined) k2 = k
7
- var desc = Object.getOwnPropertyDescriptor(m, k)
8
- if (
9
- !desc ||
10
- ("get" in desc
11
- ? !m.__esModule
12
- : desc.writable || desc.configurable)
13
- ) {
14
- desc = {
15
- enumerable: true,
16
- get: function () {
17
- return m[k]
18
- }
19
- }
20
- }
21
- Object.defineProperty(o, k2, desc)
22
- }
23
- : function (o, m, k, k2) {
24
- if (k2 === undefined) k2 = k
25
- o[k2] = m[k]
26
- })
27
- var __setModuleDefault =
28
- (this && this.__setModuleDefault) ||
29
- (Object.create
30
- ? function (o, v) {
31
- Object.defineProperty(o, "default", {
32
- enumerable: true,
33
- value: v
34
- })
35
- }
36
- : function (o, v) {
37
- o["default"] = v
38
- })
39
- var __importStar =
40
- (this && this.__importStar) ||
41
- function (mod) {
42
- if (mod && mod.__esModule) return mod
43
- var result = {}
44
- if (mod != null)
45
- for (var k in mod)
46
- if (
47
- k !== "default" &&
48
- Object.prototype.hasOwnProperty.call(mod, k)
49
- )
50
- __createBinding(result, mod, k)
51
- __setModuleDefault(result, mod)
52
- return result
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]; } };
53
7
  }
54
- var __importDefault =
55
- (this && this.__importDefault) ||
56
- function (mod) {
57
- return mod && mod.__esModule ? mod : { default: mod }
58
- }
59
- Object.defineProperty(exports, "__esModule", { value: true })
60
- const constants_1 = __importDefault(require("../client/wallet/constants"))
61
- const wasm = __importStar(require("lunesrs"))
62
- const cryptoUtils = {
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
+ exports.cryptoUtils = void 0;
30
+ const constants_1 = __importDefault(require("../client/wallet/constants"));
31
+ const wasm = __importStar(require("lunesrs"));
32
+ exports.cryptoUtils = {
63
33
  fromExistingSeed: (seed, nonce, chain) => {
64
- const hidden_seed = wasm.hiddenSeed(nonce, seed)
65
- const privateKey = wasm.toPrivateKey(hidden_seed)
66
- const publicKey = wasm.toPublicKey(privateKey)
67
- const address = wasm.toAddress(1, chain, publicKey)
34
+ const hidden_seed = wasm.hiddenSeed(nonce, seed);
35
+ const privateKey = wasm.toPrivateKey(hidden_seed);
36
+ const publicKey = wasm.toPublicKey(privateKey);
37
+ const address = wasm.toAddress(1, chain, publicKey);
68
38
  return {
69
39
  nonce: nonce,
70
40
  chain: chain,
@@ -72,11 +42,11 @@ const cryptoUtils = {
72
42
  privateKey: wasm.arrayToBase58(privateKey),
73
43
  publicKey: wasm.arrayToBase58(publicKey),
74
44
  address: wasm.arrayToBase58(address)
75
- }
45
+ };
76
46
  },
77
47
  fromPrivateKey: (privateKey, chain) => {
78
- const publicKey = wasm.toPublicKey(wasm.base58ToArray(privateKey))
79
- const address = wasm.toAddress(1, chain, publicKey)
48
+ const publicKey = wasm.toPublicKey(wasm.base58ToArray(privateKey));
49
+ const address = wasm.toAddress(1, chain, publicKey);
80
50
  return {
81
51
  seed: "",
82
52
  nonce: 0,
@@ -84,10 +54,10 @@ const cryptoUtils = {
84
54
  privateKey: privateKey,
85
55
  publicKey: wasm.arrayToBase58(publicKey),
86
56
  address: wasm.arrayToBase58(address)
87
- }
57
+ };
88
58
  },
89
59
  fromPublicKey: (publicKey, chain) => {
90
- const address = wasm.toAddress(1, chain, wasm.base58ToArray(publicKey))
60
+ const address = wasm.toAddress(1, chain, wasm.base58ToArray(publicKey));
91
61
  return {
92
62
  seed: "",
93
63
  nonce: 0,
@@ -95,7 +65,7 @@ const cryptoUtils = {
95
65
  chain: chain,
96
66
  publicKey: publicKey,
97
67
  address: wasm.arrayToBase58(address)
98
- }
68
+ };
99
69
  },
100
70
  fromAddress: (address, chain) => {
101
71
  return {
@@ -105,43 +75,28 @@ const cryptoUtils = {
105
75
  publicKey: "",
106
76
  chain: chain,
107
77
  address: address
108
- }
78
+ };
109
79
  },
110
80
  fromNewSeed: (nWords, nonce, chain) => {
111
- let seed = []
112
- nWords = nWords != undefined ? Math.round(nWords / 3) : 4
81
+ let seed = [];
82
+ nWords = nWords != undefined ? Math.round(nWords / 3) : 4;
113
83
  for (let i = 0; i < nWords; i++) {
114
84
  for (let n in wasm.randomTripleNumber()) {
115
- seed.push(constants_1.default.wordsList[n])
85
+ seed.push(constants_1.default.wordsList[n]);
116
86
  }
117
87
  }
118
- return cryptoUtils.fromExistingSeed(seed.join(" "), nonce, chain)
88
+ return exports.cryptoUtils.fromExistingSeed(seed.join(" "), nonce, chain);
119
89
  },
120
90
  validateAddress: (address, chain) => {
121
- return wasm.validateAddress(chain, wasm.base58ToArray(address))
91
+ return wasm.validateAddress(chain, wasm.base58ToArray(address));
122
92
  },
123
93
  validateSignature: (publicKey, message, signature) => {
124
- return wasm.validateSignature(
125
- wasm.base58ToArray(publicKey),
126
- wasm.base58ToArray(message),
127
- wasm.base58ToArray(signature)
128
- )
94
+ return wasm.validateSignature(wasm.base58ToArray(publicKey), wasm.base58ToArray(message), wasm.base58ToArray(signature));
129
95
  },
130
96
  fastSignature: (privateKey, message) => {
131
- return wasm.arrayToBase58(
132
- wasm.fastSignature(
133
- wasm.base58ToArray(privateKey),
134
- wasm.base58ToArray(message)
135
- )
136
- )
97
+ return wasm.arrayToBase58(wasm.fastSignature(wasm.base58ToArray(privateKey), wasm.base58ToArray(message)));
137
98
  },
138
99
  fullSignature: (privateKey, message) => {
139
- return wasm.arrayToBase58(
140
- wasm.fullSignature(
141
- wasm.base58ToArray(privateKey),
142
- wasm.base58ToArray(message)
143
- )
144
- )
100
+ return wasm.arrayToBase58(wasm.fullSignature(wasm.base58ToArray(privateKey), wasm.base58ToArray(message)));
145
101
  }
146
- }
147
- exports.default = cryptoUtils
102
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lunesjs",
3
- "version": "1.5.12",
3
+ "version": "1.5.14",
4
4
  "description": "Library for communication with nodes in mainnet or testnet of the lunes-blockchain network",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -19,6 +19,7 @@
19
19
  "author": "lunes-platform",
20
20
  "license": "Apache-2.0",
21
21
  "scripts": {
22
+ "deploy": "yarn build && yarn publish",
22
23
  "fmt": "prettier -w .",
23
24
  "fmtc": "prettier -c",
24
25
  "test": "yarn jest",
@@ -36,4 +37,4 @@
36
37
  "axios": "^0.26.1",
37
38
  "lunesrs": "^1.8.2-web"
38
39
  }
39
- }
40
+ }