lunesjs 1.8.0 → 1.9.0
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/index.d.ts +8 -0
- package/lib/index.js +8 -0
- package/lib/tx/stake/createStake.service.js +5 -9
- package/lib/tx/stake/withdrawStake.service.js +2 -4
- package/lib/tx/tokens/burnToken.service.d.ts +33 -0
- package/lib/tx/tokens/burnToken.service.js +64 -0
- package/lib/tx/tokens/issueToken.service.d.ts +50 -0
- package/lib/tx/tokens/issueToken.service.js +99 -0
- package/lib/tx/tokens/reissueToken.service.d.ts +36 -0
- package/lib/tx/tokens/reissueToken.service.js +76 -0
- package/lib/tx/tokens/utils.d.ts +6 -0
- package/lib/tx/tokens/utils.js +66 -0
- package/lib/tx/transfer/transfer.service.js +5 -9
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
@@ -2,10 +2,18 @@ import { transferTokenFactory } from "./tx/transfer/transfer.service";
|
|
2
2
|
import { withdrawStakeFactory } from "./tx/stake/withdrawStake.service";
|
3
3
|
import { createStakeFactory } from "./tx/stake/createStake.service";
|
4
4
|
import { walletFactory } from "./wallet/wallet.service";
|
5
|
+
import { issueTokenFactory } from "./tx/tokens/issueToken.service";
|
6
|
+
import { issueNFTFactory } from "./tx/tokens/issueToken.service";
|
7
|
+
import { reissueTokenFactory } from "./tx/tokens/reissueToken.service";
|
8
|
+
import { burnTokenFactory } from "./tx/tokens/burnToken.service";
|
5
9
|
declare const _default: {
|
6
10
|
transferTokenFactory: typeof transferTokenFactory;
|
7
11
|
withdrawStakeFactory: typeof withdrawStakeFactory;
|
12
|
+
reissueTokenFactory: typeof reissueTokenFactory;
|
8
13
|
createStakeFactory: typeof createStakeFactory;
|
14
|
+
issueTokenFactory: typeof issueTokenFactory;
|
15
|
+
burnTokenFactory: typeof burnTokenFactory;
|
16
|
+
issueNFTFactory: typeof issueNFTFactory;
|
9
17
|
walletFactory: typeof walletFactory;
|
10
18
|
crypto: {
|
11
19
|
fromSeed: (seed: string, nonce: number, chain: number) => import("./wallet/wallet.service").Wallet;
|
package/lib/index.js
CHANGED
@@ -5,10 +5,18 @@ const withdrawStake_service_1 = require("./tx/stake/withdrawStake.service");
|
|
5
5
|
const createStake_service_1 = require("./tx/stake/createStake.service");
|
6
6
|
const wallet_service_1 = require("./wallet/wallet.service");
|
7
7
|
const crypto_1 = require("./utils/crypto");
|
8
|
+
const issueToken_service_1 = require("./tx/tokens/issueToken.service");
|
9
|
+
const issueToken_service_2 = require("./tx/tokens/issueToken.service");
|
10
|
+
const reissueToken_service_1 = require("./tx/tokens/reissueToken.service");
|
11
|
+
const burnToken_service_1 = require("./tx/tokens/burnToken.service");
|
8
12
|
exports.default = {
|
9
13
|
transferTokenFactory: transfer_service_1.transferTokenFactory,
|
10
14
|
withdrawStakeFactory: withdrawStake_service_1.withdrawStakeFactory,
|
15
|
+
reissueTokenFactory: reissueToken_service_1.reissueTokenFactory,
|
11
16
|
createStakeFactory: createStake_service_1.createStakeFactory,
|
17
|
+
issueTokenFactory: issueToken_service_1.issueTokenFactory,
|
18
|
+
burnTokenFactory: burnToken_service_1.burnTokenFactory,
|
19
|
+
issueNFTFactory: issueToken_service_2.issueNFTFactory,
|
12
20
|
walletFactory: wallet_service_1.walletFactory,
|
13
21
|
crypto: crypto_1.crypto
|
14
22
|
};
|
@@ -80,18 +80,14 @@ function createStakeFactory(tx) {
|
|
80
80
|
const fee = tx.fee != undefined ? tx.fee : 100000;
|
81
81
|
const chain = tx.chain != undefined ? tx.chain : 1;
|
82
82
|
const sender = wasm.arrayToBase58(wasm.toAddress(1, chain, wasm.base58ToArray(tx.senderPublicKey)));
|
83
|
-
if (
|
83
|
+
if (crypto_1.crypto.sameChainAddress(tx.receiverAddress, sender) != true)
|
84
|
+
throw new Error("Sender AND Receiver should be same chain");
|
85
|
+
if (timestamp < 1483228800)
|
84
86
|
throw new Error(`Timestamp should be greater than 1483228800, but ${timestamp}`);
|
85
|
-
|
86
|
-
if (tx.amount <= 0) {
|
87
|
+
if (tx.amount <= 0)
|
87
88
|
throw new Error(`Amount should be greater than 0, but ${tx.amount}`);
|
88
|
-
|
89
|
-
if (fee < 100000) {
|
89
|
+
if (fee < 100000)
|
90
90
|
throw new Error(`Fee should be greater than 100000, but ${fee}`);
|
91
|
-
}
|
92
|
-
if (crypto_1.crypto.sameChainAddress(tx.receiverAddress, sender) != true) {
|
93
|
-
throw new Error("Sender AND Receiver should be same chain");
|
94
|
-
}
|
95
91
|
return new Stake(tx.senderPublicKey, timestamp, tx.receiverAddress, Math.floor(tx.amount * 10e7), fee);
|
96
92
|
}
|
97
93
|
exports.createStakeFactory = createStakeFactory;
|
@@ -51,12 +51,10 @@ exports.WithdrawStake = WithdrawStake;
|
|
51
51
|
function withdrawStakeFactory(tx) {
|
52
52
|
const timestamp = tx.timestamp != undefined ? tx.timestamp : Date.now();
|
53
53
|
const fee = tx.fee != undefined ? tx.fee : 100000;
|
54
|
-
if (timestamp < 1483228800)
|
54
|
+
if (timestamp < 1483228800)
|
55
55
|
throw new Error(`Timestamp should be greater than 1483228800, but ${timestamp}`);
|
56
|
-
|
57
|
-
if (fee < 100000) {
|
56
|
+
if (fee < 100000)
|
58
57
|
throw new Error(`Fee should be greater than 100000, but ${fee}`);
|
59
|
-
}
|
60
58
|
return new WithdrawStake(tx.senderPublicKey, timestamp, tx.id, fee);
|
61
59
|
}
|
62
60
|
exports.withdrawStakeFactory = withdrawStakeFactory;
|
@@ -0,0 +1,33 @@
|
|
1
|
+
export declare class BurnToken {
|
2
|
+
senderPublicKey: string;
|
3
|
+
timestamp: number;
|
4
|
+
signature: string;
|
5
|
+
quantity: number;
|
6
|
+
assetId: string;
|
7
|
+
message: string;
|
8
|
+
type: number;
|
9
|
+
fee: number;
|
10
|
+
constructor(senderPublicKey: string, timestamp: number, quantity: number, assetId: string, fee: number);
|
11
|
+
transaction(): {
|
12
|
+
senderPublicKey: string;
|
13
|
+
timestamp: number;
|
14
|
+
signature: string;
|
15
|
+
quantity: number;
|
16
|
+
assetId: string;
|
17
|
+
type: number;
|
18
|
+
fee: number;
|
19
|
+
};
|
20
|
+
sign(privateKey: string): BurnToken;
|
21
|
+
broadcast(node?: string): Promise<{
|
22
|
+
isSuccess: boolean;
|
23
|
+
response: object;
|
24
|
+
}>;
|
25
|
+
}
|
26
|
+
export declare type Reissue = {
|
27
|
+
senderPublicKey: string;
|
28
|
+
timestamp?: number;
|
29
|
+
quantity: number;
|
30
|
+
tokenId: string;
|
31
|
+
fee?: number;
|
32
|
+
};
|
33
|
+
export declare function burnTokenFactory(tx: Reissue): BurnToken;
|
@@ -0,0 +1,64 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
|
+
};
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
+
exports.burnTokenFactory = exports.BurnToken = void 0;
|
16
|
+
const utils_1 = require("./utils");
|
17
|
+
const broadcast_1 = __importDefault(require("../../utils/broadcast"));
|
18
|
+
const signer_1 = __importDefault(require("../../utils/signer"));
|
19
|
+
class BurnToken {
|
20
|
+
constructor(senderPublicKey, timestamp, quantity, assetId, fee) {
|
21
|
+
this.senderPublicKey = senderPublicKey;
|
22
|
+
this.timestamp = timestamp;
|
23
|
+
this.quantity = quantity;
|
24
|
+
this.assetId = assetId;
|
25
|
+
this.signature = "";
|
26
|
+
this.message = "";
|
27
|
+
this.fee = fee;
|
28
|
+
this.type = 5;
|
29
|
+
}
|
30
|
+
transaction() {
|
31
|
+
return {
|
32
|
+
senderPublicKey: this.senderPublicKey,
|
33
|
+
timestamp: this.timestamp,
|
34
|
+
signature: this.signature,
|
35
|
+
quantity: this.quantity,
|
36
|
+
assetId: this.assetId,
|
37
|
+
type: this.type,
|
38
|
+
fee: this.fee
|
39
|
+
};
|
40
|
+
}
|
41
|
+
sign(privateKey) {
|
42
|
+
;
|
43
|
+
[this.signature, this.message] = (0, signer_1.default)(privateKey, utils_1.serializeBurnToken, this);
|
44
|
+
return this;
|
45
|
+
}
|
46
|
+
broadcast(node) {
|
47
|
+
return __awaiter(this, void 0, void 0, function* () {
|
48
|
+
return yield (0, broadcast_1.default)(node != undefined ? node : "https://lunesnode.lunes.io", this.transaction());
|
49
|
+
});
|
50
|
+
}
|
51
|
+
}
|
52
|
+
exports.BurnToken = BurnToken;
|
53
|
+
function burnTokenFactory(tx) {
|
54
|
+
const timestamp = tx.timestamp != undefined ? tx.timestamp : Date.now();
|
55
|
+
const fee = tx.fee != undefined ? tx.fee : 100000;
|
56
|
+
if (timestamp < 1483228800)
|
57
|
+
throw new Error(`Timestamp should be greater than 1483228800, but ${timestamp}`);
|
58
|
+
if (tx.quantity <= 0)
|
59
|
+
throw new Error(`Amount should be greater than 0, but ${tx.quantity}`);
|
60
|
+
if (fee < 100000)
|
61
|
+
throw new Error(`Fee should be greater than 100000, but ${fee}`);
|
62
|
+
return new BurnToken(tx.senderPublicKey, timestamp, Math.floor(tx.quantity * 10e7), tx.tokenId, fee);
|
63
|
+
}
|
64
|
+
exports.burnTokenFactory = burnTokenFactory;
|
@@ -0,0 +1,50 @@
|
|
1
|
+
export declare class Token {
|
2
|
+
senderPublicKey: string;
|
3
|
+
description: string;
|
4
|
+
reissuable: number;
|
5
|
+
timestamp: number;
|
6
|
+
signature: string;
|
7
|
+
quantity: number;
|
8
|
+
decimals: number;
|
9
|
+
message: string;
|
10
|
+
name: string;
|
11
|
+
type: number;
|
12
|
+
fee: number;
|
13
|
+
constructor(senderPublicKey: string, description: string, reissuable: number, timestamp: number, quantity: number, decimals: number, name: string, fee: number);
|
14
|
+
transaction(): {
|
15
|
+
senderPublicKey: string;
|
16
|
+
description: string;
|
17
|
+
reissuable: number;
|
18
|
+
timestamp: number;
|
19
|
+
signature: string;
|
20
|
+
quantity: number;
|
21
|
+
decimals: number;
|
22
|
+
name: string;
|
23
|
+
type: number;
|
24
|
+
fee: number;
|
25
|
+
};
|
26
|
+
sign(privateKey: string): Token;
|
27
|
+
broadcast(node?: string): Promise<{
|
28
|
+
isSuccess: boolean;
|
29
|
+
response: object;
|
30
|
+
}>;
|
31
|
+
}
|
32
|
+
export declare type _Token = {
|
33
|
+
senderPublicKey: string;
|
34
|
+
description: string;
|
35
|
+
reissuable?: boolean;
|
36
|
+
timestamp?: number;
|
37
|
+
quantity: number;
|
38
|
+
decimals?: number;
|
39
|
+
name: string;
|
40
|
+
fee?: number;
|
41
|
+
};
|
42
|
+
export declare function issueTokenFactory(tx: _Token): Token;
|
43
|
+
export declare type NFT = {
|
44
|
+
senderPublicKey: string;
|
45
|
+
description: string;
|
46
|
+
timestamp?: number;
|
47
|
+
name: string;
|
48
|
+
fee?: number;
|
49
|
+
};
|
50
|
+
export declare function issueNFTFactory(tx: NFT): Token;
|
@@ -0,0 +1,99 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
|
+
};
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
+
exports.issueNFTFactory = exports.issueTokenFactory = exports.Token = void 0;
|
16
|
+
const utils_1 = require("./utils");
|
17
|
+
const broadcast_1 = __importDefault(require("../../utils/broadcast"));
|
18
|
+
const signer_1 = __importDefault(require("../../utils/signer"));
|
19
|
+
class Token {
|
20
|
+
constructor(senderPublicKey, description, reissuable, timestamp, quantity, decimals, name, fee) {
|
21
|
+
this.senderPublicKey = senderPublicKey;
|
22
|
+
this.description = description;
|
23
|
+
this.reissuable = reissuable;
|
24
|
+
this.timestamp = timestamp;
|
25
|
+
this.quantity = quantity;
|
26
|
+
this.decimals = decimals;
|
27
|
+
this.signature = "";
|
28
|
+
this.message = "";
|
29
|
+
this.name = name;
|
30
|
+
this.fee = fee;
|
31
|
+
this.type = 3;
|
32
|
+
}
|
33
|
+
transaction() {
|
34
|
+
return {
|
35
|
+
senderPublicKey: this.senderPublicKey,
|
36
|
+
description: this.description,
|
37
|
+
reissuable: this.reissuable,
|
38
|
+
timestamp: this.timestamp,
|
39
|
+
signature: this.signature,
|
40
|
+
quantity: this.quantity,
|
41
|
+
decimals: this.decimals,
|
42
|
+
name: this.name,
|
43
|
+
type: this.type,
|
44
|
+
fee: this.fee
|
45
|
+
};
|
46
|
+
}
|
47
|
+
sign(privateKey) {
|
48
|
+
;
|
49
|
+
[this.signature, this.message] = (0, signer_1.default)(privateKey, utils_1.serializeIssueToken, this);
|
50
|
+
return this;
|
51
|
+
}
|
52
|
+
broadcast(node) {
|
53
|
+
return __awaiter(this, void 0, void 0, function* () {
|
54
|
+
return yield (0, broadcast_1.default)(node != undefined ? node : "https://lunesnode.lunes.io", this.transaction());
|
55
|
+
});
|
56
|
+
}
|
57
|
+
}
|
58
|
+
exports.Token = Token;
|
59
|
+
function issueTokenFactory(tx) {
|
60
|
+
const timestamp = tx.timestamp != undefined ? tx.timestamp : Date.now();
|
61
|
+
const decimals = tx.decimals != undefined ? tx.decimals : 8;
|
62
|
+
const fee = tx.fee != undefined ? tx.fee : 100000;
|
63
|
+
const reissuable = () => {
|
64
|
+
if (tx.reissuable != undefined) {
|
65
|
+
return tx.reissuable == true ? 1 : 0;
|
66
|
+
}
|
67
|
+
else {
|
68
|
+
return 1;
|
69
|
+
}
|
70
|
+
};
|
71
|
+
if (tx.description.length > 1000)
|
72
|
+
throw new Error(`Description should be less than 1000, but ${tx.description.length}`);
|
73
|
+
if (timestamp < 1483228800)
|
74
|
+
throw new Error(`Timestamp should be greater than 1483228800, but ${timestamp}`);
|
75
|
+
if (tx.name.length > 16)
|
76
|
+
throw new Error(`Name should be less than 16 char, but ${tx.name.length}`);
|
77
|
+
if (tx.quantity <= 0)
|
78
|
+
throw new Error(`Amount should be greater than 0, but ${tx.quantity}`);
|
79
|
+
if (decimals > 8)
|
80
|
+
throw new Error(`Decimals should be less than 8, but ${decimals}`);
|
81
|
+
if (fee < 100000)
|
82
|
+
throw new Error(`Fee should be greater than 100000, but ${fee}`);
|
83
|
+
return new Token(tx.senderPublicKey, tx.description, reissuable(), timestamp, Math.floor(tx.quantity * 10e7), decimals, tx.name, fee);
|
84
|
+
}
|
85
|
+
exports.issueTokenFactory = issueTokenFactory;
|
86
|
+
function issueNFTFactory(tx) {
|
87
|
+
const timestamp = tx.timestamp != undefined ? tx.timestamp : Date.now();
|
88
|
+
const fee = tx.fee != undefined ? tx.fee : 100000;
|
89
|
+
if (tx.description.length > 1000)
|
90
|
+
throw new Error(`Description should be less than 1000, but ${tx.description.length}`);
|
91
|
+
if (timestamp < 1483228800)
|
92
|
+
throw new Error(`Timestamp should be greater than 1483228800, but ${timestamp}`);
|
93
|
+
if (tx.name.length > 16)
|
94
|
+
throw new Error(`Name should be less than 16 char, but ${tx.name.length}`);
|
95
|
+
if (fee < 100000)
|
96
|
+
throw new Error(`Fee should be greater than 100000, but ${fee}`);
|
97
|
+
return new Token(tx.senderPublicKey, tx.description, 0, timestamp, 1, 0, tx.name, fee);
|
98
|
+
}
|
99
|
+
exports.issueNFTFactory = issueNFTFactory;
|
@@ -0,0 +1,36 @@
|
|
1
|
+
export declare class ReissueToken {
|
2
|
+
senderPublicKey: string;
|
3
|
+
reissuable: number;
|
4
|
+
timestamp: number;
|
5
|
+
signature: string;
|
6
|
+
quantity: number;
|
7
|
+
assetId: string;
|
8
|
+
message: string;
|
9
|
+
type: number;
|
10
|
+
fee: number;
|
11
|
+
constructor(senderPublicKey: string, reissuable: number, timestamp: number, quantity: number, assetId: string, fee: number);
|
12
|
+
transaction(): {
|
13
|
+
senderPublicKey: string;
|
14
|
+
reissuable: number;
|
15
|
+
timestamp: number;
|
16
|
+
signature: string;
|
17
|
+
quantity: number;
|
18
|
+
assetId: string;
|
19
|
+
type: number;
|
20
|
+
fee: number;
|
21
|
+
};
|
22
|
+
sign(privateKey: string): ReissueToken;
|
23
|
+
broadcast(node?: string): Promise<{
|
24
|
+
isSuccess: boolean;
|
25
|
+
response: object;
|
26
|
+
}>;
|
27
|
+
}
|
28
|
+
export declare type Reissue = {
|
29
|
+
senderPublicKey: string;
|
30
|
+
reissuable?: boolean;
|
31
|
+
timestamp?: number;
|
32
|
+
quantity: number;
|
33
|
+
tokenId: string;
|
34
|
+
fee?: number;
|
35
|
+
};
|
36
|
+
export declare function reissueTokenFactory(tx: Reissue): ReissueToken;
|
@@ -0,0 +1,76 @@
|
|
1
|
+
"use strict";
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
9
|
+
});
|
10
|
+
};
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
13
|
+
};
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
15
|
+
exports.reissueTokenFactory = exports.ReissueToken = void 0;
|
16
|
+
const utils_1 = require("./utils");
|
17
|
+
const broadcast_1 = __importDefault(require("../../utils/broadcast"));
|
18
|
+
const signer_1 = __importDefault(require("../../utils/signer"));
|
19
|
+
class ReissueToken {
|
20
|
+
constructor(senderPublicKey, reissuable, timestamp, quantity, assetId, fee) {
|
21
|
+
this.senderPublicKey = senderPublicKey;
|
22
|
+
this.reissuable = reissuable;
|
23
|
+
this.timestamp = timestamp;
|
24
|
+
this.quantity = quantity;
|
25
|
+
(this.assetId = assetId), (this.signature = "");
|
26
|
+
this.message = "";
|
27
|
+
this.fee = fee;
|
28
|
+
this.type = 6;
|
29
|
+
}
|
30
|
+
transaction() {
|
31
|
+
return {
|
32
|
+
senderPublicKey: this.senderPublicKey,
|
33
|
+
reissuable: this.reissuable,
|
34
|
+
timestamp: this.timestamp,
|
35
|
+
signature: this.signature,
|
36
|
+
quantity: this.quantity,
|
37
|
+
assetId: this.assetId,
|
38
|
+
type: this.type,
|
39
|
+
fee: this.fee
|
40
|
+
};
|
41
|
+
}
|
42
|
+
sign(privateKey) {
|
43
|
+
;
|
44
|
+
[this.signature, this.message] = (0, signer_1.default)(privateKey, utils_1.serializeReissueToken, this);
|
45
|
+
return this;
|
46
|
+
}
|
47
|
+
broadcast(node) {
|
48
|
+
return __awaiter(this, void 0, void 0, function* () {
|
49
|
+
return yield (0, broadcast_1.default)(node != undefined ? node : "https://lunesnode.lunes.io", this.transaction());
|
50
|
+
});
|
51
|
+
}
|
52
|
+
}
|
53
|
+
exports.ReissueToken = ReissueToken;
|
54
|
+
function reissueTokenFactory(tx) {
|
55
|
+
const timestamp = tx.timestamp != undefined ? tx.timestamp : Date.now();
|
56
|
+
const fee = tx.fee != undefined ? tx.fee : 100000;
|
57
|
+
const reissuable = () => {
|
58
|
+
if (tx.reissuable != undefined) {
|
59
|
+
return tx.reissuable == true ? 1 : 0;
|
60
|
+
}
|
61
|
+
else {
|
62
|
+
return 1;
|
63
|
+
}
|
64
|
+
};
|
65
|
+
if (timestamp < 1483228800) {
|
66
|
+
throw new Error(`Timestamp should be greater than 1483228800, but ${timestamp}`);
|
67
|
+
}
|
68
|
+
if (tx.quantity <= 0) {
|
69
|
+
throw new Error(`Amount should be greater than 0, but ${tx.quantity}`);
|
70
|
+
}
|
71
|
+
if (fee < 100000) {
|
72
|
+
throw new Error(`Fee should be greater than 100000, but ${fee}`);
|
73
|
+
}
|
74
|
+
return new ReissueToken(tx.senderPublicKey, reissuable(), timestamp, Math.floor(tx.quantity * 10e7), tx.tokenId, fee);
|
75
|
+
}
|
76
|
+
exports.reissueTokenFactory = reissueTokenFactory;
|
@@ -0,0 +1,6 @@
|
|
1
|
+
import { Token } from "./issueToken.service";
|
2
|
+
import { ReissueToken } from "./reissueToken.service";
|
3
|
+
import { BurnToken } from "./burnToken.service";
|
4
|
+
export declare function serializeIssueToken(tx: Token): Uint8Array;
|
5
|
+
export declare function serializeReissueToken(tx: ReissueToken): Uint8Array;
|
6
|
+
export declare function serializeBurnToken(tx: BurnToken): Uint8Array;
|
@@ -0,0 +1,66 @@
|
|
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.serializeBurnToken = exports.serializeReissueToken = exports.serializeIssueToken = void 0;
|
27
|
+
const wasm = __importStar(require("lunesrs"));
|
28
|
+
function serializeIssueToken(tx) {
|
29
|
+
return new Uint8Array([
|
30
|
+
...[tx.type],
|
31
|
+
...wasm.base58ToArray(tx.senderPublicKey),
|
32
|
+
...wasm.serializeUInteger(BigInt(tx.name.length)),
|
33
|
+
...wasm.serializeString(tx.name),
|
34
|
+
...wasm.serializeString(tx.description),
|
35
|
+
...wasm.serializeString(tx.description),
|
36
|
+
...wasm.serializeUInteger(BigInt(tx.quantity)),
|
37
|
+
...wasm.serializeUInteger(BigInt(tx.decimals)),
|
38
|
+
...[tx.reissuable],
|
39
|
+
...wasm.serializeUInteger(BigInt(tx.fee)),
|
40
|
+
...wasm.serializeUInteger(BigInt(tx.timestamp))
|
41
|
+
]);
|
42
|
+
}
|
43
|
+
exports.serializeIssueToken = serializeIssueToken;
|
44
|
+
function serializeReissueToken(tx) {
|
45
|
+
return new Uint8Array([
|
46
|
+
...[tx.type],
|
47
|
+
...wasm.base58ToArray(tx.senderPublicKey),
|
48
|
+
...wasm.base58ToArray(tx.assetId),
|
49
|
+
...wasm.serializeUInteger(BigInt(tx.quantity)),
|
50
|
+
...wasm.serializeUInteger(BigInt(tx.reissuable)),
|
51
|
+
...wasm.serializeUInteger(BigInt(tx.fee)),
|
52
|
+
...wasm.serializeUInteger(BigInt(tx.timestamp))
|
53
|
+
]);
|
54
|
+
}
|
55
|
+
exports.serializeReissueToken = serializeReissueToken;
|
56
|
+
function serializeBurnToken(tx) {
|
57
|
+
return new Uint8Array([
|
58
|
+
...[tx.type],
|
59
|
+
...wasm.base58ToArray(tx.senderPublicKey),
|
60
|
+
...wasm.base58ToArray(tx.assetId),
|
61
|
+
...wasm.serializeUInteger(BigInt(tx.quantity)),
|
62
|
+
...wasm.serializeUInteger(BigInt(tx.fee)),
|
63
|
+
...wasm.serializeUInteger(BigInt(tx.timestamp))
|
64
|
+
]);
|
65
|
+
}
|
66
|
+
exports.serializeBurnToken = serializeBurnToken;
|
@@ -88,18 +88,14 @@ function transferTokenFactory(tx) {
|
|
88
88
|
const fee = tx.fee != undefined ? tx.fee : 100000;
|
89
89
|
const chain = tx.chain != undefined ? tx.chain : 1;
|
90
90
|
const sender = wasm.arrayToBase58(wasm.toAddress(1, chain, wasm.base58ToArray(tx.senderPublicKey)));
|
91
|
-
if (
|
91
|
+
if (crypto_1.crypto.sameChainAddress(tx.receiverAddress, sender) != true)
|
92
|
+
throw new Error("Sender AND Receiver should be same chain");
|
93
|
+
if (timestamp < 1483228800)
|
92
94
|
throw new Error(`Timestamp should be greater than 1483228800, but ${timestamp}`);
|
93
|
-
|
94
|
-
if (tx.amount <= 0) {
|
95
|
+
if (tx.amount <= 0)
|
95
96
|
throw new Error(`Amount should be greater than 0, but ${tx.amount}`);
|
96
|
-
|
97
|
-
if (fee < 100000) {
|
97
|
+
if (fee < 100000)
|
98
98
|
throw new Error(`Fee should be greater than 100000, but ${fee}`);
|
99
|
-
}
|
100
|
-
if (crypto_1.crypto.sameChainAddress(tx.receiverAddress, sender) != true) {
|
101
|
-
throw new Error("Sender AND Receiver should be same chain");
|
102
|
-
}
|
103
99
|
return new TransferToken(tx.senderPublicKey, timestamp, tx.receiverAddress, feeAsset, assetId, Math.floor(tx.amount * 10e7), sender, fee);
|
104
100
|
}
|
105
101
|
exports.transferTokenFactory = transferTokenFactory;
|