lunesjs 1.5.16-web → 1.7.0
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/README.md +12 -38
- package/lib/index.d.ts +9 -10
- package/lib/index.js +4 -4
- package/lib/tx/transfer/service.transfer.d.ts +38 -0
- package/lib/tx/transfer/service.transfer.js +84 -0
- package/lib/tx/transfer/utils.d.ts +3 -0
- package/lib/tx/transfer/utils.js +51 -0
- package/lib/utils/crypto.d.ts +7 -8
- package/lib/utils/crypto.js +17 -46
- package/lib/{client/wallet → wallet}/constants.d.ts +0 -0
- package/lib/{client/wallet → wallet}/constants.js +0 -0
- package/lib/wallet/wallet.service.d.ts +18 -0
- package/lib/wallet/wallet.service.js +27 -0
- package/package.json +3 -3
- package/lib/client/transactions/BaseTransaction.d.ts +0 -6
- package/lib/client/transactions/BaseTransaction.js +0 -2
- package/lib/client/transactions/transactions.types.d.ts +0 -10
- package/lib/client/transactions/transactions.types.js +0 -17
- package/lib/client/transactions/transfer/service.transfer.d.ts +0 -12
- package/lib/client/transactions/transfer/service.transfer.js +0 -78
- package/lib/client/transactions/transfer/transfer.types.d.ts +0 -12
- package/lib/client/transactions/transfer/transfer.types.js +0 -2
- package/lib/client/transactions/transfer/validator.d.ts +0 -9
- package/lib/client/transactions/transfer/validator.js +0 -93
- package/lib/client/wallet/service.account.d.ts +0 -20
- package/lib/client/wallet/service.account.js +0 -32
- package/lib/client/wallet/wallet.types.d.ts +0 -21
- package/lib/client/wallet/wallet.types.js +0 -11
package/README.md
CHANGED
@@ -1,48 +1,22 @@
|
|
1
|
-
<div align="center">
|
2
|
-
|
3
|
-
<a href="https://lunes.io">
|
4
|
-
<img alt="Lunes" src="static/img/jslogo.png" width="100" />
|
5
|
-
</a>
|
6
|
-
|
7
1
|
# LunesJS
|
8
2
|
|
9
|
-
|
3
|
+
📦 Build based in the WebAssembly by Rust using [LunesRs](https://github.com/lunes-platform/lunesrs) for communication with nodes on the mainnet or testnet of the lunes-blockchain network Allows automation of asset submission, final issuance of token reissue, leasing, registration and creation of a new wallet.
|
10
4
|
|
11
5
|
[](https://github.com/lunes-platform/lunesjs/actions/workflows/deploy.yml)
|
12
|
-
[](https://github.com/lunes-platform/lunesjs/actions/workflows/test.yml)
|
13
|
-
[](https://github.com/lunes-platform/lunesjs/watchers)
|
23
|
-
[](https://github.com/lunes-platform?tab=followers)
|
24
|
-
[](https://lunes.io)
|
25
|
-

|
26
|
-

|
27
|
-
[](https://github.com/lunes-platform)
|
28
|
-

|
29
|
-
|
30
|
-
<a href="https://twitter.com/LunesPlatform" target="_blank">
|
31
|
-
<img alt="Twitter: Lunes Platform" src="https://badgen.net/twitter/follow/lunesplatform?icon=twitter&label=follow @LunesPlatform&color=blue" />
|
32
|
-
</a>
|
33
|
-
<a href="https://t.me/LunesPlatformPT" target="_blank">
|
34
|
-
<img alt="Telegram" src="https://badgen.net/badge/icon/Lunes%20Platform?icon=telegram&label=Telegram&color=blue"/>
|
35
|
-
</a>
|
36
|
-
|
37
|
-
</div>
|
38
|
-
|
39
|
-
## Changelog
|
40
|
-
|
41
|
-
The changelog process for this project is described [here](CHANGELOG.md).
|
6
|
+
[](https://github.com/lunes-platform/lunesjs/actions/workflows/test.yml)
|
7
|
+
[](https://github.com/lunes-platform/lunesjs/actions/workflows/lint.yml)
|
8
|
+

|
9
|
+
|
10
|
+

|
11
|
+

|
12
|
+

|
13
|
+
|
14
|
+

|
15
|
+

|
42
16
|
|
43
17
|
## Documentation
|
44
18
|
|
45
|
-
The LunesJS documentations is hosted at [ Telescope ](https://
|
19
|
+
The `LunesJS` documentations is hosted at [ Telescope ](https://github.io/telescope/)
|
46
20
|
|
47
21
|
## Contributing
|
48
22
|
|
package/lib/index.d.ts
CHANGED
@@ -1,18 +1,17 @@
|
|
1
|
-
import { transferTokenFactory } from "./
|
2
|
-
import {
|
1
|
+
import { transferTokenFactory } from "./tx/transfer/service.transfer";
|
2
|
+
import { walletFactory } from "./wallet/wallet.service";
|
3
3
|
declare const _default: {
|
4
4
|
transferTokenFactory: typeof transferTokenFactory;
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
fromPrivateKey: (privateKey: string, chain:
|
9
|
-
|
10
|
-
|
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;
|
5
|
+
walletFactory: typeof walletFactory;
|
6
|
+
crypto: {
|
7
|
+
fromSeed: (seed: string, nonce: number, chain: number) => import("./wallet/wallet.service").Wallet;
|
8
|
+
fromPrivateKey: (privateKey: string, chain: number) => import("./wallet/wallet.service").Wallet;
|
9
|
+
fromNewSeed: (seedLen: number, nonce: number, chain: number) => import("./wallet/wallet.service").Wallet;
|
10
|
+
validateAddress: (address: string, chain: number) => boolean;
|
13
11
|
validateSignature: (publicKey: string, message: string, signature: string) => boolean;
|
14
12
|
fastSignature: (privateKey: string, message: string) => string;
|
15
13
|
fullSignature: (privateKey: string, message: string) => string;
|
14
|
+
sameChainAddress: (addr1: string, addr2: string) => boolean;
|
16
15
|
};
|
17
16
|
};
|
18
17
|
export default _default;
|
package/lib/index.js
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
const service_transfer_1 = require("./
|
4
|
-
const
|
3
|
+
const service_transfer_1 = require("./tx/transfer/service.transfer");
|
4
|
+
const wallet_service_1 = require("./wallet/wallet.service");
|
5
5
|
const crypto_1 = require("./utils/crypto");
|
6
6
|
exports.default = {
|
7
7
|
transferTokenFactory: service_transfer_1.transferTokenFactory,
|
8
|
-
|
9
|
-
|
8
|
+
walletFactory: wallet_service_1.walletFactory,
|
9
|
+
crypto: crypto_1.crypto
|
10
10
|
};
|
@@ -0,0 +1,38 @@
|
|
1
|
+
export declare class TransferToken {
|
2
|
+
senderPublicKey: string;
|
3
|
+
timestamp: number;
|
4
|
+
signature: string;
|
5
|
+
recipient: string;
|
6
|
+
feeAsset: string;
|
7
|
+
message: string;
|
8
|
+
assetId: string;
|
9
|
+
amount: number;
|
10
|
+
sender: string;
|
11
|
+
type: number;
|
12
|
+
fee: number;
|
13
|
+
constructor(senderPublicKey: string, timestamp: number, receiver: string, feeAsset: string, assetId: string, amount: number, sender: string, fee: number);
|
14
|
+
transaction(): {
|
15
|
+
senderPublicKey: string;
|
16
|
+
timestamp: number;
|
17
|
+
signature: string;
|
18
|
+
recipient: string;
|
19
|
+
feeAsset: string;
|
20
|
+
assetId: string;
|
21
|
+
amount: number;
|
22
|
+
sender: string;
|
23
|
+
fee: number;
|
24
|
+
};
|
25
|
+
sign(privateKey: string): TransferToken;
|
26
|
+
}
|
27
|
+
export declare type Transfer = {
|
28
|
+
senderPublicKey: string;
|
29
|
+
timestamp?: number;
|
30
|
+
feeAsset?: string;
|
31
|
+
receiver: string;
|
32
|
+
assetId?: string;
|
33
|
+
sender?: string;
|
34
|
+
chain?: number;
|
35
|
+
amount: number;
|
36
|
+
fee?: number;
|
37
|
+
};
|
38
|
+
export declare function transferTokenFactory(tx: Transfer): TransferToken;
|
@@ -0,0 +1,84 @@
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
26
|
+
exports.transferTokenFactory = exports.TransferToken = void 0;
|
27
|
+
const crypto_1 = require("../../utils/crypto");
|
28
|
+
const utils_1 = require("./utils");
|
29
|
+
const wasm = __importStar(require("lunesrs"));
|
30
|
+
class TransferToken {
|
31
|
+
constructor(senderPublicKey, timestamp, receiver, feeAsset, assetId, amount, sender, fee) {
|
32
|
+
this.senderPublicKey = senderPublicKey;
|
33
|
+
this.timestamp = timestamp;
|
34
|
+
this.signature = "";
|
35
|
+
this.recipient = receiver;
|
36
|
+
this.feeAsset = feeAsset;
|
37
|
+
this.message = "";
|
38
|
+
this.assetId = assetId;
|
39
|
+
this.amount = amount;
|
40
|
+
this.sender = sender;
|
41
|
+
this.type = 4;
|
42
|
+
this.fee = fee;
|
43
|
+
}
|
44
|
+
transaction() {
|
45
|
+
return {
|
46
|
+
senderPublicKey: this.senderPublicKey,
|
47
|
+
timestamp: this.timestamp,
|
48
|
+
signature: this.signature,
|
49
|
+
recipient: this.recipient,
|
50
|
+
feeAsset: this.feeAsset,
|
51
|
+
assetId: this.assetId,
|
52
|
+
amount: this.amount,
|
53
|
+
sender: this.sender,
|
54
|
+
fee: this.fee
|
55
|
+
};
|
56
|
+
}
|
57
|
+
sign(privateKey) {
|
58
|
+
this.signature = (0, utils_1.signTransfer)(privateKey, this);
|
59
|
+
return this;
|
60
|
+
}
|
61
|
+
}
|
62
|
+
exports.TransferToken = TransferToken;
|
63
|
+
function transferTokenFactory(tx) {
|
64
|
+
const timestamp = tx.timestamp != undefined ? tx.timestamp : Date.now();
|
65
|
+
const feeAsset = tx.feeAsset != undefined ? tx.feeAsset : "";
|
66
|
+
const assetId = tx.assetId != undefined ? tx.assetId : "";
|
67
|
+
const fee = tx.fee != undefined ? tx.fee : 100000;
|
68
|
+
const chain = tx.chain != undefined ? tx.chain : 1;
|
69
|
+
const sender = wasm.arrayToBase58(wasm.toAddress(1, chain, wasm.base58ToArray(tx.senderPublicKey)));
|
70
|
+
if (timestamp < 1483228800) {
|
71
|
+
throw new Error(`Timestamp should be greater than 1483228800, but ${timestamp}`);
|
72
|
+
}
|
73
|
+
if (tx.amount <= 0) {
|
74
|
+
throw new Error(`Amount should be greater than 0, but ${tx.amount}`);
|
75
|
+
}
|
76
|
+
if (fee < 100000) {
|
77
|
+
throw new Error(`Fee should be greater than 100000, but ${fee}`);
|
78
|
+
}
|
79
|
+
if (crypto_1.crypto.sameChainAddress(tx.receiver, sender) != true) {
|
80
|
+
throw new Error("Sender AND Receiver should be same chain");
|
81
|
+
}
|
82
|
+
return new TransferToken(tx.senderPublicKey, timestamp, tx.receiver, feeAsset, assetId, Math.floor(tx.amount * 10e7), sender, fee);
|
83
|
+
}
|
84
|
+
exports.transferTokenFactory = transferTokenFactory;
|
@@ -0,0 +1,51 @@
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
26
|
+
exports.signTransfer = exports.serializeTransfer = void 0;
|
27
|
+
const wasm = __importStar(require("lunesrs"));
|
28
|
+
function serializeTransfer(tx) {
|
29
|
+
const tokenId = tx.assetId != ""
|
30
|
+
? new Uint8Array([1, ...wasm.base58ToArray(tx.assetId)])
|
31
|
+
: new Uint8Array([0]);
|
32
|
+
const tokenFee = tx.feeAsset != ""
|
33
|
+
? new Uint8Array([1, ...wasm.base58ToArray(tx.feeAsset)])
|
34
|
+
: new Uint8Array([0]);
|
35
|
+
return new Uint8Array([
|
36
|
+
...[tx.type],
|
37
|
+
...wasm.base58ToArray(tx.senderPublicKey),
|
38
|
+
...tokenId,
|
39
|
+
...tokenFee,
|
40
|
+
...wasm.serializeUInteger(BigInt(tx.timestamp)),
|
41
|
+
...wasm.serializeUInteger(BigInt(tx.amount)),
|
42
|
+
...wasm.serializeUInteger(BigInt(tx.fee)),
|
43
|
+
...wasm.base58ToArray(tx.recipient)
|
44
|
+
]);
|
45
|
+
}
|
46
|
+
exports.serializeTransfer = serializeTransfer;
|
47
|
+
function signTransfer(senderPrivateKey, tx) {
|
48
|
+
tx.message = wasm.arrayToBase58(serializeTransfer(tx));
|
49
|
+
return wasm.arrayToBase58(wasm.fastSignature(wasm.base58ToArray(senderPrivateKey), wasm.base58ToArray(tx.message)));
|
50
|
+
}
|
51
|
+
exports.signTransfer = signTransfer;
|
package/lib/utils/crypto.d.ts
CHANGED
@@ -1,12 +1,11 @@
|
|
1
|
-
import {
|
2
|
-
export declare const
|
3
|
-
|
4
|
-
fromPrivateKey: (privateKey: string, chain:
|
5
|
-
|
6
|
-
|
7
|
-
fromNewSeed: (nWords: number, nonce: number, chain: WalletTypes.Chain) => IAccount;
|
8
|
-
validateAddress: (address: string, chain: WalletTypes.Chain) => boolean;
|
1
|
+
import { Wallet } from "../wallet/wallet.service";
|
2
|
+
export declare const crypto: {
|
3
|
+
fromSeed: (seed: string, nonce: number, chain: number) => Wallet;
|
4
|
+
fromPrivateKey: (privateKey: string, chain: number) => Wallet;
|
5
|
+
fromNewSeed: (seedLen: number, nonce: number, chain: number) => Wallet;
|
6
|
+
validateAddress: (address: string, chain: number) => boolean;
|
9
7
|
validateSignature: (publicKey: string, message: string, signature: string) => boolean;
|
10
8
|
fastSignature: (privateKey: string, message: string) => string;
|
11
9
|
fullSignature: (privateKey: string, message: string) => string;
|
10
|
+
sameChainAddress: (addr1: string, addr2: string) => boolean;
|
12
11
|
};
|
package/lib/utils/crypto.js
CHANGED
@@ -26,66 +26,32 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
27
27
|
};
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
29
|
-
exports.
|
30
|
-
const
|
29
|
+
exports.crypto = void 0;
|
30
|
+
const wallet_service_1 = require("../wallet/wallet.service");
|
31
|
+
const constants_1 = __importDefault(require("../wallet/constants"));
|
31
32
|
const wasm = __importStar(require("lunesrs"));
|
32
|
-
exports.
|
33
|
-
|
33
|
+
exports.crypto = {
|
34
|
+
fromSeed: (seed, nonce, chain) => {
|
34
35
|
const hidden_seed = wasm.hiddenSeed(nonce, seed);
|
35
36
|
const privateKey = wasm.toPrivateKey(hidden_seed);
|
36
37
|
const publicKey = wasm.toPublicKey(privateKey);
|
37
38
|
const address = wasm.toAddress(1, chain, publicKey);
|
38
|
-
return
|
39
|
-
nonce: nonce,
|
40
|
-
chain: chain,
|
41
|
-
seed: seed,
|
42
|
-
privateKey: wasm.arrayToBase58(privateKey),
|
43
|
-
publicKey: wasm.arrayToBase58(publicKey),
|
44
|
-
address: wasm.arrayToBase58(address)
|
45
|
-
};
|
39
|
+
return new wallet_service_1.Wallet(wasm.arrayToBase58(privateKey), wasm.arrayToBase58(publicKey), wasm.arrayToBase58(address), chain, nonce, seed);
|
46
40
|
},
|
47
41
|
fromPrivateKey: (privateKey, chain) => {
|
48
42
|
const publicKey = wasm.toPublicKey(wasm.base58ToArray(privateKey));
|
49
43
|
const address = wasm.toAddress(1, chain, publicKey);
|
50
|
-
return
|
51
|
-
seed: "",
|
52
|
-
nonce: 0,
|
53
|
-
chain: chain,
|
54
|
-
privateKey: privateKey,
|
55
|
-
publicKey: wasm.arrayToBase58(publicKey),
|
56
|
-
address: wasm.arrayToBase58(address)
|
57
|
-
};
|
44
|
+
return new wallet_service_1.Wallet(privateKey, wasm.arrayToBase58(publicKey), wasm.arrayToBase58(address), chain, 0, "");
|
58
45
|
},
|
59
|
-
|
60
|
-
const address = wasm.toAddress(1, chain, wasm.base58ToArray(publicKey));
|
61
|
-
return {
|
62
|
-
seed: "",
|
63
|
-
nonce: 0,
|
64
|
-
privateKey: "",
|
65
|
-
chain: chain,
|
66
|
-
publicKey: publicKey,
|
67
|
-
address: wasm.arrayToBase58(address)
|
68
|
-
};
|
69
|
-
},
|
70
|
-
fromAddress: (address, chain) => {
|
71
|
-
return {
|
72
|
-
seed: "",
|
73
|
-
nonce: 0,
|
74
|
-
privateKey: "",
|
75
|
-
publicKey: "",
|
76
|
-
chain: chain,
|
77
|
-
address: address
|
78
|
-
};
|
79
|
-
},
|
80
|
-
fromNewSeed: (nWords, nonce, chain) => {
|
46
|
+
fromNewSeed: (seedLen, nonce, chain) => {
|
81
47
|
let seed = [];
|
82
|
-
|
83
|
-
for (let i = 0; i <
|
84
|
-
for (let n
|
48
|
+
seedLen = seedLen != undefined ? Math.round(seedLen / 3) : 4;
|
49
|
+
for (let i = 0; i < seedLen; i++) {
|
50
|
+
for (let n of wasm.randomTripleNumber()) {
|
85
51
|
seed.push(constants_1.default.wordsList[n]);
|
86
52
|
}
|
87
53
|
}
|
88
|
-
return exports.
|
54
|
+
return exports.crypto.fromSeed(seed.join(" "), nonce, chain);
|
89
55
|
},
|
90
56
|
validateAddress: (address, chain) => {
|
91
57
|
return wasm.validateAddress(chain, wasm.base58ToArray(address));
|
@@ -98,5 +64,10 @@ exports.cryptoUtils = {
|
|
98
64
|
},
|
99
65
|
fullSignature: (privateKey, message) => {
|
100
66
|
return wasm.arrayToBase58(wasm.fullSignature(wasm.base58ToArray(privateKey), wasm.base58ToArray(message)));
|
67
|
+
},
|
68
|
+
sameChainAddress: (addr1, addr2) => {
|
69
|
+
const x = exports.crypto.validateAddress(addr1, 1) && exports.crypto.validateAddress(addr2, 1);
|
70
|
+
const y = exports.crypto.validateAddress(addr1, 0) && exports.crypto.validateAddress(addr2, 0);
|
71
|
+
return x || y;
|
101
72
|
}
|
102
73
|
};
|
File without changes
|
File without changes
|
@@ -0,0 +1,18 @@
|
|
1
|
+
export declare class Wallet {
|
2
|
+
privateKey: string;
|
3
|
+
publicKey: string;
|
4
|
+
address: string;
|
5
|
+
chain: number;
|
6
|
+
nonce: number;
|
7
|
+
seed: string;
|
8
|
+
constructor(privateKey: string, publicKey: string, address: string, chain: number, nonce: number, seed: string);
|
9
|
+
}
|
10
|
+
declare type TWallet = {
|
11
|
+
privateKey?: string;
|
12
|
+
seedLen?: number;
|
13
|
+
chain?: number;
|
14
|
+
nonce?: number;
|
15
|
+
seed?: string;
|
16
|
+
};
|
17
|
+
export declare function walletFactory(wallet: TWallet): Wallet;
|
18
|
+
export {};
|
@@ -0,0 +1,27 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.walletFactory = exports.Wallet = void 0;
|
4
|
+
const crypto_1 = require("../utils/crypto");
|
5
|
+
class Wallet {
|
6
|
+
constructor(privateKey, publicKey, address, chain, nonce, seed) {
|
7
|
+
this.privateKey = privateKey;
|
8
|
+
this.publicKey = publicKey;
|
9
|
+
this.address = address;
|
10
|
+
this.chain = chain;
|
11
|
+
this.nonce = nonce;
|
12
|
+
this.seed = seed;
|
13
|
+
}
|
14
|
+
}
|
15
|
+
exports.Wallet = Wallet;
|
16
|
+
function walletFactory(wallet) {
|
17
|
+
if (wallet.seed) {
|
18
|
+
return crypto_1.crypto.fromSeed(wallet.seed, wallet.nonce != undefined ? wallet.nonce : 0, wallet.chain != undefined ? wallet.chain : 1);
|
19
|
+
}
|
20
|
+
else if (wallet.privateKey) {
|
21
|
+
return crypto_1.crypto.fromPrivateKey(wallet.privateKey, wallet.chain != undefined ? wallet.chain : 1);
|
22
|
+
}
|
23
|
+
else {
|
24
|
+
return crypto_1.crypto.fromNewSeed(wallet.seedLen != undefined ? wallet.seedLen : 12, wallet.nonce != undefined ? wallet.nonce : 0, wallet.chain != undefined ? wallet.chain : 1);
|
25
|
+
}
|
26
|
+
}
|
27
|
+
exports.walletFactory = walletFactory;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "lunesjs",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.7.0",
|
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",
|
@@ -23,7 +23,7 @@
|
|
23
23
|
"fmt": "prettier -w .",
|
24
24
|
"fmtc": "prettier -c",
|
25
25
|
"t": "yarn jest",
|
26
|
-
"build": "
|
26
|
+
"build": "tsc"
|
27
27
|
},
|
28
28
|
"devDependencies": {
|
29
29
|
"@types/jest": "^27.0.3",
|
@@ -35,6 +35,6 @@
|
|
35
35
|
},
|
36
36
|
"dependencies": {
|
37
37
|
"axios": "^0.26.1",
|
38
|
-
"lunesrs": "^1.
|
38
|
+
"lunesrs": "^1.9.1"
|
39
39
|
}
|
40
40
|
}
|
@@ -1,17 +0,0 @@
|
|
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 = {}));
|
16
|
-
//...
|
17
|
-
})(TransactionsTypes = exports.TransactionsTypes || (exports.TransactionsTypes = {}));
|
@@ -1,12 +0,0 @@
|
|
1
|
-
import { WalletTypes } from "../../wallet/wallet.types";
|
2
|
-
import { BaseTransaction } from "../BaseTransaction";
|
3
|
-
import { ITransfer } from "./transfer.types";
|
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>;
|
10
|
-
}
|
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,78 +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 __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"));
|
43
|
-
class TransferToken {
|
44
|
-
constructor(tx) {
|
45
|
-
this.tx = tx;
|
46
|
-
}
|
47
|
-
transaction() {
|
48
|
-
return this.tx;
|
49
|
-
}
|
50
|
-
sign(privateKey) {
|
51
|
-
this.tx.signature = validator_1.default.sign(privateKey, this.tx);
|
52
|
-
return this.tx;
|
53
|
-
}
|
54
|
-
send() {
|
55
|
-
return __awaiter(this, void 0, void 0, function* () {
|
56
|
-
validator_1.default.send(this.tx);
|
57
|
-
});
|
58
|
-
}
|
59
|
-
}
|
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");
|
64
|
-
}
|
65
|
-
return new TransferToken({
|
66
|
-
senderPublicKey: senderPublicKey,
|
67
|
-
recipient: recipient,
|
68
|
-
amount: amount,
|
69
|
-
sender: wasm.arrayToBase58(wasm.toAddress(1, chain_id, wasm.base58ToArray(senderPublicKey))),
|
70
|
-
timestamp: timestamp != undefined ? timestamp : new Date().getTime(),
|
71
|
-
feeAsset: feeAsset != undefined ? feeAsset : "",
|
72
|
-
assetId: assetId != undefined ? assetId : "",
|
73
|
-
type: transactions_types_1.TransactionsTypes.TransferToken.int,
|
74
|
-
fee: fee != undefined ? fee : transactions_types_1.TransactionsTypes.TransferToken.fee,
|
75
|
-
signature: ""
|
76
|
-
});
|
77
|
-
}
|
78
|
-
exports.transferTokenFactory = transferTokenFactory;
|
@@ -1,9 +0,0 @@
|
|
1
|
-
import { WalletTypes } from "../../wallet/wallet.types";
|
2
|
-
import { ITransfer } from "./transfer.types";
|
3
|
-
declare const 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,93 +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 __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"));
|
42
|
-
const validator = {
|
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]);
|
50
|
-
return new Uint8Array([
|
51
|
-
...[transactions_types_1.TransactionsTypes.TransferToken.int],
|
52
|
-
...wasm.base58ToArray(senderPublicKey),
|
53
|
-
...tokenId,
|
54
|
-
...tokenFee,
|
55
|
-
...wasm.serializeUInteger(BigInt(timestamp)),
|
56
|
-
...wasm.serializeUInteger(BigInt(amount)),
|
57
|
-
...wasm.serializeUInteger(BigInt(fee)),
|
58
|
-
...wasm.base58ToArray(recipient)
|
59
|
-
]);
|
60
|
-
},
|
61
|
-
ready: (senderPublicKey, recipient, amount, chain) => {
|
62
|
-
const sender = wasm.arrayToBase58(wasm.toAddress(1, chain, wasm.base58ToArray(senderPublicKey)));
|
63
|
-
if (amount <= 0) {
|
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;
|
72
|
-
}
|
73
|
-
},
|
74
|
-
sign: (privateKey, tx) => {
|
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)));
|
77
|
-
},
|
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);
|
87
|
-
})
|
88
|
-
.catch((error) => {
|
89
|
-
console.error(error.response.data);
|
90
|
-
});
|
91
|
-
})
|
92
|
-
};
|
93
|
-
exports.default = validator;
|
@@ -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,32 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.accountFactory = void 0;
|
4
|
-
const crypto_1 = require("../../utils/crypto");
|
5
|
-
class Account {
|
6
|
-
constructor(wallet) {
|
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;
|
13
|
-
}
|
14
|
-
}
|
15
|
-
function accountFactory({ privateKey, publicKey, address, nWords, chain, nonce, seed } = {}) {
|
16
|
-
if (seed != undefined) {
|
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)));
|
30
|
-
}
|
31
|
-
}
|
32
|
-
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 = {}));
|