lunesjs 1.6.1 → 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/lib/index.d.ts +6 -5
- package/lib/index.js +1 -1
- package/lib/tx/transfer/service.transfer.d.ts +37 -11
- package/lib/tx/transfer/service.transfer.js +48 -42
- package/lib/tx/transfer/utils.d.ts +3 -0
- package/lib/tx/transfer/utils.js +51 -0
- package/lib/utils/crypto.d.ts +7 -6
- package/lib/utils/crypto.js +12 -20
- package/lib/wallet/wallet.service.d.ts +5 -5
- package/lib/wallet/wallet.service.js +16 -15
- package/package.json +1 -1
- package/lib/tx/BaseTransaction.d.ts +0 -6
- package/lib/tx/BaseTransaction.js +0 -2
- package/lib/tx/transactions.types.d.ts +0 -10
- package/lib/tx/transactions.types.js +0 -17
- package/lib/tx/transfer/transfer.types.d.ts +0 -12
- package/lib/tx/transfer/transfer.types.js +0 -2
- package/lib/tx/transfer/validator.d.ts +0 -9
- package/lib/tx/transfer/validator.js +0 -93
- package/lib/wallet/wallet.types.d.ts +0 -21
- package/lib/wallet/wallet.types.js +0 -11
package/lib/index.d.ts
CHANGED
@@ -3,14 +3,15 @@ import { walletFactory } from "./wallet/wallet.service";
|
|
3
3
|
declare const _default: {
|
4
4
|
transferTokenFactory: typeof transferTokenFactory;
|
5
5
|
walletFactory: typeof walletFactory;
|
6
|
-
|
7
|
-
|
8
|
-
fromPrivateKey: (privateKey: string, chain:
|
9
|
-
fromNewSeed: (seedLen: number, nonce: number, chain:
|
10
|
-
validateAddress: (address: string, chain:
|
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;
|
11
11
|
validateSignature: (publicKey: string, message: string, signature: string) => boolean;
|
12
12
|
fastSignature: (privateKey: string, message: string) => string;
|
13
13
|
fullSignature: (privateKey: string, message: string) => string;
|
14
|
+
sameChainAddress: (addr1: string, addr2: string) => boolean;
|
14
15
|
};
|
15
16
|
};
|
16
17
|
export default _default;
|
package/lib/index.js
CHANGED
@@ -1,12 +1,38 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
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;
|
10
26
|
}
|
11
|
-
export declare
|
12
|
-
|
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;
|
@@ -22,57 +22,63 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
22
22
|
__setModuleDefault(result, mod);
|
23
23
|
return result;
|
24
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
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
38
|
-
exports.transferTokenFactory = void 0;
|
39
|
-
const
|
40
|
-
const
|
41
|
-
const validator_1 = __importDefault(require("./validator"));
|
26
|
+
exports.transferTokenFactory = exports.TransferToken = void 0;
|
27
|
+
const crypto_1 = require("../../utils/crypto");
|
28
|
+
const utils_1 = require("./utils");
|
42
29
|
const wasm = __importStar(require("lunesrs"));
|
43
30
|
class TransferToken {
|
44
|
-
constructor(
|
45
|
-
this.
|
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;
|
46
43
|
}
|
47
44
|
transaction() {
|
48
|
-
return
|
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
|
+
};
|
49
56
|
}
|
50
57
|
sign(privateKey) {
|
51
|
-
this.
|
52
|
-
return this
|
53
|
-
}
|
54
|
-
send() {
|
55
|
-
return __awaiter(this, void 0, void 0, function* () {
|
56
|
-
validator_1.default.send(this.tx);
|
57
|
-
});
|
58
|
+
this.signature = (0, utils_1.signTransfer)(privateKey, this);
|
59
|
+
return this;
|
58
60
|
}
|
59
61
|
}
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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");
|
64
81
|
}
|
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
|
-
});
|
82
|
+
return new TransferToken(tx.senderPublicKey, timestamp, tx.receiver, feeAsset, assetId, Math.floor(tx.amount * 10e7), sender, fee);
|
77
83
|
}
|
78
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,10 +1,11 @@
|
|
1
|
-
import {
|
2
|
-
export declare const
|
3
|
-
|
4
|
-
fromPrivateKey: (privateKey: string, chain:
|
5
|
-
fromNewSeed: (seedLen: number, nonce: number, chain:
|
6
|
-
validateAddress: (address: string, chain:
|
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;
|
7
7
|
validateSignature: (publicKey: string, message: string, signature: string) => boolean;
|
8
8
|
fastSignature: (privateKey: string, message: string) => string;
|
9
9
|
fullSignature: (privateKey: string, message: string) => string;
|
10
|
+
sameChainAddress: (addr1: string, addr2: string) => boolean;
|
10
11
|
};
|
package/lib/utils/crypto.js
CHANGED
@@ -26,35 +26,22 @@ 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.
|
29
|
+
exports.crypto = void 0;
|
30
|
+
const wallet_service_1 = require("../wallet/wallet.service");
|
30
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
46
|
fromNewSeed: (seedLen, nonce, chain) => {
|
60
47
|
let seed = [];
|
@@ -64,7 +51,7 @@ exports.cryptoUtils = {
|
|
64
51
|
seed.push(constants_1.default.wordsList[n]);
|
65
52
|
}
|
66
53
|
}
|
67
|
-
return exports.
|
54
|
+
return exports.crypto.fromSeed(seed.join(" "), nonce, chain);
|
68
55
|
},
|
69
56
|
validateAddress: (address, chain) => {
|
70
57
|
return wasm.validateAddress(chain, wasm.base58ToArray(address));
|
@@ -77,5 +64,10 @@ exports.cryptoUtils = {
|
|
77
64
|
},
|
78
65
|
fullSignature: (privateKey, message) => {
|
79
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;
|
80
72
|
}
|
81
73
|
};
|
@@ -1,18 +1,18 @@
|
|
1
|
-
|
2
|
-
declare class Account implements IAccount {
|
1
|
+
export declare class Wallet {
|
3
2
|
privateKey: string;
|
4
3
|
publicKey: string;
|
5
4
|
address: string;
|
6
5
|
chain: number;
|
7
6
|
nonce: number;
|
8
7
|
seed: string;
|
9
|
-
constructor(
|
8
|
+
constructor(privateKey: string, publicKey: string, address: string, chain: number, nonce: number, seed: string);
|
10
9
|
}
|
11
|
-
|
10
|
+
declare type TWallet = {
|
12
11
|
privateKey?: string;
|
13
12
|
seedLen?: number;
|
14
13
|
chain?: number;
|
15
14
|
nonce?: number;
|
16
15
|
seed?: string;
|
17
|
-
}
|
16
|
+
};
|
17
|
+
export declare function walletFactory(wallet: TWallet): Wallet;
|
18
18
|
export {};
|
@@ -1,26 +1,27 @@
|
|
1
1
|
"use strict";
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.walletFactory = void 0;
|
3
|
+
exports.walletFactory = exports.Wallet = void 0;
|
4
4
|
const crypto_1 = require("../utils/crypto");
|
5
|
-
class
|
6
|
-
constructor(
|
7
|
-
this.privateKey =
|
8
|
-
this.publicKey =
|
9
|
-
this.address =
|
10
|
-
this.chain =
|
11
|
-
this.nonce =
|
12
|
-
this.seed =
|
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
13
|
}
|
14
14
|
}
|
15
|
-
|
16
|
-
|
17
|
-
|
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);
|
18
19
|
}
|
19
|
-
else if (privateKey
|
20
|
-
return
|
20
|
+
else if (wallet.privateKey) {
|
21
|
+
return crypto_1.crypto.fromPrivateKey(wallet.privateKey, wallet.chain != undefined ? wallet.chain : 1);
|
21
22
|
}
|
22
23
|
else {
|
23
|
-
return
|
24
|
+
return crypto_1.crypto.fromNewSeed(wallet.seedLen != undefined ? wallet.seedLen : 12, wallet.nonce != undefined ? wallet.nonce : 0, wallet.chain != undefined ? wallet.chain : 1);
|
24
25
|
}
|
25
26
|
}
|
26
27
|
exports.walletFactory = walletFactory;
|
package/package.json
CHANGED
@@ -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,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,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 = {}));
|