lunesjs 1.5.9 → 1.5.12
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/client/transactions/BaseTransaction.d.ts +6 -0
- package/lib/client/transactions/BaseTransaction.js +2 -0
- package/{dist → lib}/client/transactions/transactions.types.d.ts +0 -0
- package/lib/client/transactions/transactions.types.js +27 -0
- package/lib/client/transactions/transfer/service.transfer.d.ts +21 -0
- package/lib/client/transactions/transfer/service.transfer.js +153 -0
- package/lib/client/transactions/transfer/transfer.types.d.ts +12 -0
- package/lib/client/transactions/transfer/transfer.types.js +2 -0
- package/lib/client/transactions/transfer/validator.d.ts +22 -0
- package/lib/client/transactions/transfer/validator.js +176 -0
- package/lib/client/wallet/constants.d.ts +8 -0
- package/{dist → lib}/client/wallet/constants.js +9 -9
- package/lib/client/wallet/service.account.d.ts +28 -0
- package/lib/client/wallet/service.account.js +83 -0
- package/lib/client/wallet/wallet.types.d.ts +21 -0
- package/lib/client/wallet/wallet.types.js +11 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.js +24 -0
- package/{dist → lib}/utils/crypto.d.ts +24 -12
- package/lib/utils/crypto.js +147 -0
- package/package.json +11 -11
- package/CHANGELOG.md +0 -3
- package/dist/client/transactions/BaseTransaction.d.ts +0 -6
- package/dist/client/transactions/BaseTransaction.js +0 -2
- package/dist/client/transactions/transactions.types.js +0 -17
- package/dist/client/transactions/transfer/service.transfer.d.ts +0 -12
- package/dist/client/transactions/transfer/service.transfer.js +0 -78
- package/dist/client/transactions/transfer/transfer.types.d.ts +0 -12
- package/dist/client/transactions/transfer/transfer.types.js +0 -2
- package/dist/client/transactions/transfer/validator.d.ts +0 -9
- package/dist/client/transactions/transfer/validator.js +0 -93
- package/dist/client/wallet/constants.d.ts +0 -8
- package/dist/client/wallet/service.account.d.ts +0 -20
- package/dist/client/wallet/service.account.js +0 -35
- package/dist/client/wallet/wallet.types.d.ts +0 -21
- package/dist/client/wallet/wallet.types.js +0 -11
- package/dist/index.d.ts +0 -5
- package/dist/index.js +0 -14
- package/dist/utils/crypto.js +0 -102
@@ -1,13 +1,25 @@
|
|
1
|
-
import { IAccount, WalletTypes } from "../client/wallet/wallet.types"
|
1
|
+
import { IAccount, WalletTypes } from "../client/wallet/wallet.types"
|
2
2
|
declare const cryptoUtils: {
|
3
|
-
fromExistingSeed: (
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
@@ -0,0 +1,147 @@
|
|
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
|
53
|
+
}
|
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 = {
|
63
|
+
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)
|
68
|
+
return {
|
69
|
+
nonce: nonce,
|
70
|
+
chain: chain,
|
71
|
+
seed: seed,
|
72
|
+
privateKey: wasm.arrayToBase58(privateKey),
|
73
|
+
publicKey: wasm.arrayToBase58(publicKey),
|
74
|
+
address: wasm.arrayToBase58(address)
|
75
|
+
}
|
76
|
+
},
|
77
|
+
fromPrivateKey: (privateKey, chain) => {
|
78
|
+
const publicKey = wasm.toPublicKey(wasm.base58ToArray(privateKey))
|
79
|
+
const address = wasm.toAddress(1, chain, publicKey)
|
80
|
+
return {
|
81
|
+
seed: "",
|
82
|
+
nonce: 0,
|
83
|
+
chain: chain,
|
84
|
+
privateKey: privateKey,
|
85
|
+
publicKey: wasm.arrayToBase58(publicKey),
|
86
|
+
address: wasm.arrayToBase58(address)
|
87
|
+
}
|
88
|
+
},
|
89
|
+
fromPublicKey: (publicKey, chain) => {
|
90
|
+
const address = wasm.toAddress(1, chain, wasm.base58ToArray(publicKey))
|
91
|
+
return {
|
92
|
+
seed: "",
|
93
|
+
nonce: 0,
|
94
|
+
privateKey: "",
|
95
|
+
chain: chain,
|
96
|
+
publicKey: publicKey,
|
97
|
+
address: wasm.arrayToBase58(address)
|
98
|
+
}
|
99
|
+
},
|
100
|
+
fromAddress: (address, chain) => {
|
101
|
+
return {
|
102
|
+
seed: "",
|
103
|
+
nonce: 0,
|
104
|
+
privateKey: "",
|
105
|
+
publicKey: "",
|
106
|
+
chain: chain,
|
107
|
+
address: address
|
108
|
+
}
|
109
|
+
},
|
110
|
+
fromNewSeed: (nWords, nonce, chain) => {
|
111
|
+
let seed = []
|
112
|
+
nWords = nWords != undefined ? Math.round(nWords / 3) : 4
|
113
|
+
for (let i = 0; i < nWords; i++) {
|
114
|
+
for (let n in wasm.randomTripleNumber()) {
|
115
|
+
seed.push(constants_1.default.wordsList[n])
|
116
|
+
}
|
117
|
+
}
|
118
|
+
return cryptoUtils.fromExistingSeed(seed.join(" "), nonce, chain)
|
119
|
+
},
|
120
|
+
validateAddress: (address, chain) => {
|
121
|
+
return wasm.validateAddress(chain, wasm.base58ToArray(address))
|
122
|
+
},
|
123
|
+
validateSignature: (publicKey, message, signature) => {
|
124
|
+
return wasm.validateSignature(
|
125
|
+
wasm.base58ToArray(publicKey),
|
126
|
+
wasm.base58ToArray(message),
|
127
|
+
wasm.base58ToArray(signature)
|
128
|
+
)
|
129
|
+
},
|
130
|
+
fastSignature: (privateKey, message) => {
|
131
|
+
return wasm.arrayToBase58(
|
132
|
+
wasm.fastSignature(
|
133
|
+
wasm.base58ToArray(privateKey),
|
134
|
+
wasm.base58ToArray(message)
|
135
|
+
)
|
136
|
+
)
|
137
|
+
},
|
138
|
+
fullSignature: (privateKey, message) => {
|
139
|
+
return wasm.arrayToBase58(
|
140
|
+
wasm.fullSignature(
|
141
|
+
wasm.base58ToArray(privateKey),
|
142
|
+
wasm.base58ToArray(message)
|
143
|
+
)
|
144
|
+
)
|
145
|
+
}
|
146
|
+
}
|
147
|
+
exports.default = cryptoUtils
|
package/package.json
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
{
|
2
2
|
"name": "lunesjs",
|
3
|
-
"version": "1.5.
|
4
|
-
"description": "
|
5
|
-
"main": "
|
6
|
-
"types": "
|
3
|
+
"version": "1.5.12",
|
4
|
+
"description": "Library for communication with nodes in mainnet or testnet of the lunes-blockchain network",
|
5
|
+
"main": "lib/index.js",
|
6
|
+
"types": "lib/index.d.ts",
|
7
7
|
"files": [
|
8
|
-
"/
|
8
|
+
"/lib",
|
9
9
|
"LICENSE",
|
10
10
|
"README.md",
|
11
11
|
"package.json"
|
12
12
|
],
|
13
|
-
"repository": "
|
13
|
+
"repository": "https://github.com/lunes-platform/lunesjs.git",
|
14
14
|
"keywords": [
|
15
15
|
"blockchain",
|
16
16
|
"lunes",
|
@@ -19,10 +19,10 @@
|
|
19
19
|
"author": "lunes-platform",
|
20
20
|
"license": "Apache-2.0",
|
21
21
|
"scripts": {
|
22
|
-
"build": "tsc --declaration",
|
23
|
-
"fmtc": "prettier -c",
|
24
22
|
"fmt": "prettier -w .",
|
25
|
-
"
|
23
|
+
"fmtc": "prettier -c",
|
24
|
+
"test": "yarn jest",
|
25
|
+
"build": "tsc"
|
26
26
|
},
|
27
27
|
"devDependencies": {
|
28
28
|
"@types/jest": "^27.0.3",
|
@@ -34,6 +34,6 @@
|
|
34
34
|
},
|
35
35
|
"dependencies": {
|
36
36
|
"axios": "^0.26.1",
|
37
|
-
"lunesrs": "1.8.
|
37
|
+
"lunesrs": "^1.8.2-web"
|
38
38
|
}
|
39
|
-
}
|
39
|
+
}
|
package/CHANGELOG.md
DELETED
@@ -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 = __importDefault(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.default.validateAddress(sender, chain) === true &&
|
67
|
-
crypto_1.default.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.default.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,35 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
-
};
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.accountFactory = void 0;
|
7
|
-
const crypto_1 = __importDefault(require("../../utils/crypto"));
|
8
|
-
class Account {
|
9
|
-
constructor(wallet) {
|
10
|
-
this.privateKey = wallet.privateKey;
|
11
|
-
this.publicKey = wallet.publicKey;
|
12
|
-
this.address = wallet.address;
|
13
|
-
this.chain = wallet.chain;
|
14
|
-
this.nonce = wallet.nonce;
|
15
|
-
this.seed = wallet.seed;
|
16
|
-
}
|
17
|
-
}
|
18
|
-
function accountFactory({ privateKey, publicKey, address, nWords, chain, nonce, seed } = {}) {
|
19
|
-
if (seed != undefined) {
|
20
|
-
return new Account(Object.assign({}, crypto_1.default.fromExistingSeed(seed, nonce != undefined ? nonce : 0, chain != undefined ? chain : 1)));
|
21
|
-
}
|
22
|
-
else if (privateKey != undefined) {
|
23
|
-
return new Account(Object.assign({}, crypto_1.default.fromPrivateKey(privateKey, chain != undefined ? chain : 1)));
|
24
|
-
}
|
25
|
-
else if (publicKey != undefined) {
|
26
|
-
return new Account(Object.assign({}, crypto_1.default.fromPublicKey(publicKey, chain != undefined ? chain : 1)));
|
27
|
-
}
|
28
|
-
else if (address != undefined) {
|
29
|
-
return new Account(Object.assign({}, crypto_1.default.fromAddress(address, chain != undefined ? chain : 0)));
|
30
|
-
}
|
31
|
-
else {
|
32
|
-
return new Account(Object.assign({}, crypto_1.default.fromNewSeed(nWords != undefined ? nWords : 12, nonce != undefined ? nonce : 0, chain != undefined ? chain : 1)));
|
33
|
-
}
|
34
|
-
}
|
35
|
-
exports.accountFactory = accountFactory;
|
@@ -1,21 +0,0 @@
|
|
1
|
-
export declare type empty = "";
|
2
|
-
export declare type zero = 0;
|
3
|
-
export declare namespace WalletTypes {
|
4
|
-
type Seed = string | empty;
|
5
|
-
type Nonce = number | zero;
|
6
|
-
enum Chain {
|
7
|
-
Mainnet = 1,
|
8
|
-
Testnet = 0
|
9
|
-
}
|
10
|
-
type PrivateKey = string | empty;
|
11
|
-
type PublicKey = string | empty;
|
12
|
-
type Address = string | empty;
|
13
|
-
}
|
14
|
-
export interface IAccount {
|
15
|
-
privateKey: WalletTypes.PrivateKey;
|
16
|
-
publicKey: WalletTypes.PublicKey;
|
17
|
-
address: WalletTypes.Address;
|
18
|
-
nonce: WalletTypes.Nonce;
|
19
|
-
chain: WalletTypes.Chain;
|
20
|
-
seed: WalletTypes.Seed;
|
21
|
-
}
|
@@ -1,11 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
-
exports.WalletTypes = void 0;
|
4
|
-
var WalletTypes;
|
5
|
-
(function (WalletTypes) {
|
6
|
-
let Chain;
|
7
|
-
(function (Chain) {
|
8
|
-
Chain[Chain["Mainnet"] = 1] = "Mainnet";
|
9
|
-
Chain[Chain["Testnet"] = 0] = "Testnet";
|
10
|
-
})(Chain = WalletTypes.Chain || (WalletTypes.Chain = {}));
|
11
|
-
})(WalletTypes = exports.WalletTypes || (exports.WalletTypes = {}));
|
package/dist/index.d.ts
DELETED
@@ -1,5 +0,0 @@
|
|
1
|
-
export { transferTokenFactory } from "./client/transactions/transfer/service.transfer";
|
2
|
-
export { accountFactory } from "./client/wallet/service.account";
|
3
|
-
export { WalletTypes } from "./client/wallet/wallet.types";
|
4
|
-
import cryptoUtils from "./utils/crypto";
|
5
|
-
export default cryptoUtils;
|
package/dist/index.js
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
4
|
-
};
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
6
|
-
exports.WalletTypes = exports.accountFactory = exports.transferTokenFactory = void 0;
|
7
|
-
var service_transfer_1 = require("./client/transactions/transfer/service.transfer");
|
8
|
-
Object.defineProperty(exports, "transferTokenFactory", { enumerable: true, get: function () { return service_transfer_1.transferTokenFactory; } });
|
9
|
-
var service_account_1 = require("./client/wallet/service.account");
|
10
|
-
Object.defineProperty(exports, "accountFactory", { enumerable: true, get: function () { return service_account_1.accountFactory; } });
|
11
|
-
var wallet_types_1 = require("./client/wallet/wallet.types");
|
12
|
-
Object.defineProperty(exports, "WalletTypes", { enumerable: true, get: function () { return wallet_types_1.WalletTypes; } });
|
13
|
-
const crypto_1 = __importDefault(require("./utils/crypto"));
|
14
|
-
exports.default = crypto_1.default;
|