lunesjs 1.5.0 → 1.5.4
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/.github/workflows/deploy.yml +47 -0
- package/.github/workflows/test.yml +31 -14
- package/.gitlab/.gitlab-ci.yml +1 -1
- package/.gitlab/issue_templates/bug.md +4 -4
- package/.gitlab/issue_templates/proposal.md +3 -3
- package/.gitlab/merge_request_templates/MR.md +3 -3
- package/.prettierrc.yml +1 -1
- package/CHANGELOG.md +1 -4
- package/CONTRIBUTING.md +20 -24
- package/Dockerfile +1 -4
- package/README.md +2 -2
- package/dist/client/transactions/BaseTransaction.d.ts +6 -0
- package/dist/client/transactions/BaseTransaction.js +2 -0
- package/dist/client/transactions/transactions.types.d.ts +10 -0
- package/dist/client/transactions/transactions.types.js +17 -0
- package/dist/client/transactions/transfer/service.transfer.d.ts +12 -0
- package/dist/client/transactions/transfer/service.transfer.js +78 -0
- package/dist/client/transactions/transfer/transfer.types.d.ts +12 -0
- package/dist/client/transactions/transfer/transfer.types.js +2 -0
- package/dist/client/transactions/transfer/validator.d.ts +9 -0
- package/dist/client/transactions/transfer/validator.js +93 -0
- package/dist/client/wallet/constants.d.ts +8 -0
- package/dist/client/wallet/constants.js +2064 -0
- package/dist/client/wallet/service.account.d.ts +20 -0
- package/dist/client/wallet/service.account.js +35 -0
- package/dist/client/wallet/wallet.types.d.ts +21 -0
- package/dist/client/wallet/wallet.types.js +11 -0
- package/dist/utils/crypto.d.ts +13 -0
- package/dist/utils/crypto.js +102 -0
- package/package.json +10 -45
- package/src/client/transactions/transfer/service.transfer.ts +15 -21
- package/src/client/transactions/transfer/validator.ts +18 -10
- package/src/client/wallet/service.account.ts +1 -1
- package/src/utils/crypto.ts +24 -28
- package/test/client/transactions/transfer/transfer.token.test.ts +14 -12
- package/test/client/wallet/service.account.test.ts +17 -7
- package/tsconfig.json +12 -89
- package/.github/workflows/build.yml +0 -18
- package/.husky/commit-msg +0 -4
- package/.prettierignore +0 -2
- package/commitlint.config.js +0 -10
- package/docker/runner/Dockerfile +0 -22
- package/src/client/transactions/transfer/validators.ts +0 -27
- package/src/server/blocks/block.types.ts +0 -13
- package/src/server/blocks/service.blocks.ts +0 -8
@@ -0,0 +1,20 @@
|
|
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 {};
|
@@ -0,0 +1,35 @@
|
|
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 : 0)));
|
21
|
+
}
|
22
|
+
else if (privateKey != undefined) {
|
23
|
+
return new Account(Object.assign({}, crypto_1.default.fromPrivateKey(privateKey, chain != undefined ? chain : 0)));
|
24
|
+
}
|
25
|
+
else if (publicKey != undefined) {
|
26
|
+
return new Account(Object.assign({}, crypto_1.default.fromPublicKey(publicKey, chain != undefined ? chain : 0)));
|
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;
|
@@ -0,0 +1,21 @@
|
|
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
|
+
}
|
@@ -0,0 +1,11 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.WalletTypes = void 0;
|
4
|
+
var WalletTypes;
|
5
|
+
(function (WalletTypes) {
|
6
|
+
let Chain;
|
7
|
+
(function (Chain) {
|
8
|
+
Chain[Chain["Mainnet"] = 1] = "Mainnet";
|
9
|
+
Chain[Chain["Testnet"] = 0] = "Testnet";
|
10
|
+
})(Chain = WalletTypes.Chain || (WalletTypes.Chain = {}));
|
11
|
+
})(WalletTypes = exports.WalletTypes || (exports.WalletTypes = {}));
|
@@ -0,0 +1,13 @@
|
|
1
|
+
import { IAccount, WalletTypes } from "../client/wallet/wallet.types";
|
2
|
+
declare const cryptoUtils: {
|
3
|
+
fromExistingSeed: (seed: string, nonce: number, chain: WalletTypes.Chain) => IAccount;
|
4
|
+
fromPrivateKey: (privateKey: string, chain: WalletTypes.Chain) => IAccount;
|
5
|
+
fromPublicKey: (publicKey: string, chain: WalletTypes.Chain) => IAccount;
|
6
|
+
fromAddress: (address: string, chain: WalletTypes.Chain) => IAccount;
|
7
|
+
fromNewSeed: (nWords: number, nonce: number, chain: WalletTypes.Chain) => IAccount;
|
8
|
+
validateAddress: (address: string, chain: WalletTypes.Chain) => boolean;
|
9
|
+
validateSignature: (publicKey: string, message: string, signature: string) => boolean;
|
10
|
+
fastSignature: (privateKey: string, message: string) => string;
|
11
|
+
fullSignature: (privateKey: string, message: string) => string;
|
12
|
+
};
|
13
|
+
export default cryptoUtils;
|
@@ -0,0 +1,102 @@
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
27
|
+
};
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
29
|
+
const constants_1 = __importDefault(require("../client/wallet/constants"));
|
30
|
+
const wasm = __importStar(require("lunesrs"));
|
31
|
+
const cryptoUtils = {
|
32
|
+
fromExistingSeed: (seed, nonce, chain) => {
|
33
|
+
const hidden_seed = wasm.hiddenSeed(nonce, seed);
|
34
|
+
const privateKey = wasm.toPrivateKey(hidden_seed);
|
35
|
+
const publicKey = wasm.toPublicKey(privateKey);
|
36
|
+
const address = wasm.toAddress(1, chain, publicKey);
|
37
|
+
return {
|
38
|
+
nonce: nonce,
|
39
|
+
chain: chain,
|
40
|
+
seed: seed,
|
41
|
+
privateKey: wasm.arrayToBase58(privateKey),
|
42
|
+
publicKey: wasm.arrayToBase58(publicKey),
|
43
|
+
address: wasm.arrayToBase58(address)
|
44
|
+
};
|
45
|
+
},
|
46
|
+
fromPrivateKey: (privateKey, chain) => {
|
47
|
+
const publicKey = wasm.toPublicKey(wasm.base58ToArray(privateKey));
|
48
|
+
const address = wasm.toAddress(1, chain, publicKey);
|
49
|
+
return {
|
50
|
+
seed: "",
|
51
|
+
nonce: 0,
|
52
|
+
chain: chain,
|
53
|
+
privateKey: privateKey,
|
54
|
+
publicKey: wasm.arrayToBase58(publicKey),
|
55
|
+
address: wasm.arrayToBase58(address)
|
56
|
+
};
|
57
|
+
},
|
58
|
+
fromPublicKey: (publicKey, chain) => {
|
59
|
+
const address = wasm.toAddress(1, chain, wasm.base58ToArray(publicKey));
|
60
|
+
return {
|
61
|
+
seed: "",
|
62
|
+
nonce: 0,
|
63
|
+
privateKey: "",
|
64
|
+
chain: chain,
|
65
|
+
publicKey: publicKey,
|
66
|
+
address: wasm.arrayToBase58(address)
|
67
|
+
};
|
68
|
+
},
|
69
|
+
fromAddress: (address, chain) => {
|
70
|
+
return {
|
71
|
+
seed: "",
|
72
|
+
nonce: 0,
|
73
|
+
privateKey: "",
|
74
|
+
publicKey: "",
|
75
|
+
chain: chain,
|
76
|
+
address: address
|
77
|
+
};
|
78
|
+
},
|
79
|
+
fromNewSeed: (nWords, nonce, chain) => {
|
80
|
+
let seed = [];
|
81
|
+
nWords = nWords != undefined ? Math.round(nWords / 3) : 4;
|
82
|
+
for (let i = 0; i < nWords; i++) {
|
83
|
+
for (let n in wasm.randomTripleNumber()) {
|
84
|
+
seed.push(constants_1.default.wordsList[n]);
|
85
|
+
}
|
86
|
+
}
|
87
|
+
return cryptoUtils.fromExistingSeed(seed.join(" "), nonce, chain);
|
88
|
+
},
|
89
|
+
validateAddress: (address, chain) => {
|
90
|
+
return wasm.validateAddress(chain, wasm.base58ToArray(address));
|
91
|
+
},
|
92
|
+
validateSignature: (publicKey, message, signature) => {
|
93
|
+
return wasm.validateSignature(wasm.base58ToArray(publicKey), wasm.base58ToArray(message), wasm.base58ToArray(signature));
|
94
|
+
},
|
95
|
+
fastSignature: (privateKey, message) => {
|
96
|
+
return wasm.arrayToBase58(wasm.fastSignature(wasm.base58ToArray(privateKey), wasm.base58ToArray(message)));
|
97
|
+
},
|
98
|
+
fullSignature: (privateKey, message) => {
|
99
|
+
return wasm.arrayToBase58(wasm.fullSignature(wasm.base58ToArray(privateKey), wasm.base58ToArray(message)));
|
100
|
+
}
|
101
|
+
};
|
102
|
+
exports.default = cryptoUtils;
|
package/package.json
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
{
|
2
2
|
"name": "lunesjs",
|
3
|
-
"version": "1.5.
|
3
|
+
"version": "1.5.4",
|
4
4
|
"description": "Library for communication with nodes in mainnet or testnet of the lunes-blockchain network",
|
5
|
-
"main": "
|
5
|
+
"main": "dist/*.js",
|
6
|
+
"types": "dist/*.d.ts",
|
6
7
|
"repository": "git@git.lunes.io:blockchain/labs/lunesjs.git",
|
7
8
|
"keywords": [
|
8
9
|
"blockchain",
|
@@ -12,57 +13,21 @@
|
|
12
13
|
"author": "lunes-platform",
|
13
14
|
"license": "SEE LICENSE IN ./LICENSE",
|
14
15
|
"scripts": {
|
15
|
-
"
|
16
|
-
"
|
16
|
+
"build": "tsc --declaration",
|
17
|
+
"fmtc": "prettier -c",
|
17
18
|
"fmt": "prettier -w .",
|
18
|
-
"test": "yarn jest"
|
19
|
-
"build": "tsc",
|
20
|
-
"commit": "cz"
|
19
|
+
"test": "yarn jest"
|
21
20
|
},
|
22
21
|
"devDependencies": {
|
23
|
-
"@commitlint/config-conventional": "^16.0.0",
|
24
|
-
"cz-conventional-changelog": "^3.3.0",
|
25
|
-
"@commitlint/cli": "^16.1.0",
|
26
22
|
"@types/jest": "^27.0.3",
|
23
|
+
"jest": "^27.4.5",
|
27
24
|
"jest-junit": "^13.0.0",
|
28
|
-
"
|
25
|
+
"prettier": "2.6.2",
|
29
26
|
"ts-jest": "^27.1.2",
|
30
|
-
"
|
31
|
-
"husky": "^7.0.4",
|
32
|
-
"jest": "^27.4.5"
|
27
|
+
"typescript": "^4.5.4"
|
33
28
|
},
|
34
29
|
"dependencies": {
|
35
30
|
"axios": "^0.26.1",
|
36
|
-
"lunesrs": "1.
|
37
|
-
},
|
38
|
-
"lint-staged": {
|
39
|
-
"**/*": "prettier --write"
|
40
|
-
},
|
41
|
-
"config": {
|
42
|
-
"commitizen": {
|
43
|
-
"path": "./node_modules/cz-conventional-changelog",
|
44
|
-
"types": {
|
45
|
-
"added": {
|
46
|
-
"description": "Add a new feature",
|
47
|
-
"title": "Added"
|
48
|
-
},
|
49
|
-
"merged": {
|
50
|
-
"description": "Resolves an issue and merge it to prod",
|
51
|
-
"title": "Merged"
|
52
|
-
},
|
53
|
-
"fixed": {
|
54
|
-
"description": "Fix a bug",
|
55
|
-
"title": "Fixed"
|
56
|
-
},
|
57
|
-
"refactored": {
|
58
|
-
"description": "Does not add a feature or fix a bug",
|
59
|
-
"title": "Refactored"
|
60
|
-
},
|
61
|
-
"deprecated": {
|
62
|
-
"description": "Breaks compatibility with an earlier version",
|
63
|
-
"title": "Deprecated"
|
64
|
-
}
|
65
|
-
}
|
66
|
-
}
|
31
|
+
"lunesrs": "1.8.1"
|
67
32
|
}
|
68
33
|
}
|
@@ -7,10 +7,8 @@ import * as wasm from "lunesrs"
|
|
7
7
|
|
8
8
|
class TransferToken implements BaseTransaction {
|
9
9
|
private tx: ITransfer
|
10
|
-
|
11
|
-
constructor(tx: ITransfer, chain: WalletTypes.Chain) {
|
10
|
+
constructor(tx: ITransfer) {
|
12
11
|
this.tx = tx
|
13
|
-
this.chain = chain
|
14
12
|
}
|
15
13
|
|
16
14
|
transaction(): ITransfer {
|
@@ -43,22 +41,18 @@ export function transferTokenFactory(
|
|
43
41
|
) {
|
44
42
|
throw new Error("dados invalidos")
|
45
43
|
}
|
46
|
-
return new TransferToken(
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
signature: ""
|
61
|
-
},
|
62
|
-
chain_id
|
63
|
-
)
|
44
|
+
return new TransferToken({
|
45
|
+
senderPublicKey: senderPublicKey,
|
46
|
+
recipient: recipient,
|
47
|
+
amount: amount,
|
48
|
+
sender: wasm.arrayToBase58(
|
49
|
+
wasm.toAddress(1, chain_id, wasm.base58ToArray(senderPublicKey))
|
50
|
+
),
|
51
|
+
timestamp: timestamp != undefined ? timestamp : new Date().getTime(),
|
52
|
+
feeAsset: feeAsset != undefined ? feeAsset : "",
|
53
|
+
assetId: assetId != undefined ? assetId : "",
|
54
|
+
type: TransactionsTypes.TransferToken.int,
|
55
|
+
fee: fee != undefined ? fee : TransactionsTypes.TransferToken.fee,
|
56
|
+
signature: ""
|
57
|
+
})
|
64
58
|
}
|
@@ -14,19 +14,26 @@ const validator = {
|
|
14
14
|
amount: number,
|
15
15
|
fee: number,
|
16
16
|
recipient: string
|
17
|
-
)
|
18
|
-
const tokenId =
|
19
|
-
|
20
|
-
|
17
|
+
) => {
|
18
|
+
const tokenId: Uint8Array =
|
19
|
+
assetId != ""
|
20
|
+
? new Uint8Array([1, ...wasm.base58ToArray(assetId)])
|
21
|
+
: new Uint8Array([0])
|
22
|
+
const tokenFee: Uint8Array =
|
23
|
+
feeAsset != ""
|
24
|
+
? new Uint8Array([1, ...wasm.base58ToArray(feeAsset)])
|
25
|
+
: new Uint8Array([0])
|
26
|
+
|
27
|
+
return new Uint8Array([
|
21
28
|
...[TransactionsTypes.TransferToken.int],
|
22
|
-
...wasm.
|
29
|
+
...wasm.base58ToArray(senderPublicKey),
|
23
30
|
...tokenId,
|
24
31
|
...tokenFee,
|
25
32
|
...wasm.serializeUInteger(BigInt(timestamp)),
|
26
33
|
...wasm.serializeUInteger(BigInt(amount)),
|
27
34
|
...wasm.serializeUInteger(BigInt(fee)),
|
28
|
-
...wasm.
|
29
|
-
]
|
35
|
+
...wasm.base58ToArray(recipient)
|
36
|
+
])
|
30
37
|
},
|
31
38
|
ready: (
|
32
39
|
senderPublicKey: string,
|
@@ -34,8 +41,8 @@ const validator = {
|
|
34
41
|
amount: number,
|
35
42
|
chain: WalletTypes.Chain
|
36
43
|
): boolean => {
|
37
|
-
const sender = wasm.
|
38
|
-
wasm.
|
44
|
+
const sender = wasm.arrayToBase58(
|
45
|
+
wasm.toAddress(1, chain, wasm.base58ToArray(senderPublicKey))
|
39
46
|
)
|
40
47
|
if (amount <= 0) {
|
41
48
|
return false
|
@@ -60,9 +67,10 @@ const validator = {
|
|
60
67
|
tx.fee,
|
61
68
|
tx.recipient
|
62
69
|
)
|
70
|
+
|
63
71
|
return cryptoUtils.fastSignature(
|
64
72
|
privateKey,
|
65
|
-
wasm.
|
73
|
+
wasm.arrayToBase58(new Uint8Array(message))
|
66
74
|
)
|
67
75
|
},
|
68
76
|
send: async (tx: ITransfer) => {
|
package/src/utils/crypto.ts
CHANGED
@@ -9,37 +9,37 @@ const cryptoUtils = {
|
|
9
9
|
chain: WalletTypes.Chain
|
10
10
|
): IAccount => {
|
11
11
|
const hidden_seed = wasm.hiddenSeed(nonce, seed)
|
12
|
-
const privateKey = wasm.
|
13
|
-
const publicKey = wasm.
|
14
|
-
const address = wasm.
|
12
|
+
const privateKey = wasm.toPrivateKey(hidden_seed)
|
13
|
+
const publicKey = wasm.toPublicKey(privateKey)
|
14
|
+
const address = wasm.toAddress(1, chain, publicKey)
|
15
15
|
|
16
16
|
return {
|
17
17
|
nonce: nonce,
|
18
18
|
chain: chain,
|
19
19
|
seed: seed,
|
20
|
-
privateKey: wasm.
|
21
|
-
publicKey: wasm.
|
22
|
-
address: wasm.
|
20
|
+
privateKey: wasm.arrayToBase58(privateKey),
|
21
|
+
publicKey: wasm.arrayToBase58(publicKey),
|
22
|
+
address: wasm.arrayToBase58(address)
|
23
23
|
}
|
24
24
|
},
|
25
25
|
fromPrivateKey: (
|
26
26
|
privateKey: string,
|
27
27
|
chain: WalletTypes.Chain
|
28
28
|
): IAccount => {
|
29
|
-
const publicKey = wasm.
|
30
|
-
const address = wasm.
|
29
|
+
const publicKey = wasm.toPublicKey(wasm.base58ToArray(privateKey))
|
30
|
+
const address = wasm.toAddress(1, chain, publicKey)
|
31
31
|
|
32
32
|
return {
|
33
33
|
seed: "",
|
34
34
|
nonce: 0,
|
35
35
|
chain: chain,
|
36
36
|
privateKey: privateKey,
|
37
|
-
publicKey: wasm.
|
38
|
-
address: wasm.
|
37
|
+
publicKey: wasm.arrayToBase58(publicKey),
|
38
|
+
address: wasm.arrayToBase58(address)
|
39
39
|
}
|
40
40
|
},
|
41
41
|
fromPublicKey: (publicKey: string, chain: WalletTypes.Chain): IAccount => {
|
42
|
-
const address = wasm.
|
42
|
+
const address = wasm.toAddress(1, chain, wasm.base58ToArray(publicKey))
|
43
43
|
|
44
44
|
return {
|
45
45
|
seed: "",
|
@@ -47,7 +47,7 @@ const cryptoUtils = {
|
|
47
47
|
privateKey: "",
|
48
48
|
chain: chain,
|
49
49
|
publicKey: publicKey,
|
50
|
-
address: wasm.
|
50
|
+
address: wasm.arrayToBase58(address)
|
51
51
|
}
|
52
52
|
},
|
53
53
|
fromAddress: (address: string, chain: WalletTypes.Chain): IAccount => {
|
@@ -75,7 +75,7 @@ const cryptoUtils = {
|
|
75
75
|
return cryptoUtils.fromExistingSeed(seed.join(" "), nonce, chain)
|
76
76
|
},
|
77
77
|
validateAddress: (address: string, chain: WalletTypes.Chain): boolean => {
|
78
|
-
return wasm.validateAddress(chain, wasm.
|
78
|
+
return wasm.validateAddress(chain, wasm.base58ToArray(address))
|
79
79
|
},
|
80
80
|
validateSignature: (
|
81
81
|
publicKey: string,
|
@@ -83,28 +83,24 @@ const cryptoUtils = {
|
|
83
83
|
signature: string
|
84
84
|
): boolean => {
|
85
85
|
return wasm.validateSignature(
|
86
|
-
wasm.
|
87
|
-
wasm.
|
88
|
-
wasm.
|
86
|
+
wasm.base58ToArray(publicKey),
|
87
|
+
wasm.base58ToArray(message),
|
88
|
+
wasm.base58ToArray(signature)
|
89
89
|
)
|
90
90
|
},
|
91
91
|
fastSignature: (privateKey: string, message: string) => {
|
92
|
-
return wasm.
|
93
|
-
wasm.
|
94
|
-
wasm.
|
95
|
-
|
96
|
-
wasm.toVecu32(wasm.b58ToVec(message))
|
97
|
-
)
|
92
|
+
return wasm.arrayToBase58(
|
93
|
+
wasm.fastSignature(
|
94
|
+
wasm.base58ToArray(privateKey),
|
95
|
+
wasm.base58ToArray(message)
|
98
96
|
)
|
99
97
|
)
|
100
98
|
},
|
101
99
|
fullSignature: (privateKey: string, message: string) => {
|
102
|
-
return wasm.
|
103
|
-
wasm.
|
104
|
-
wasm.
|
105
|
-
|
106
|
-
wasm.toVecu32(wasm.b58ToVec(message))
|
107
|
-
)
|
100
|
+
return wasm.arrayToBase58(
|
101
|
+
wasm.fullSignature(
|
102
|
+
wasm.base58ToArray(privateKey),
|
103
|
+
wasm.base58ToArray(message)
|
108
104
|
)
|
109
105
|
)
|
110
106
|
}
|
@@ -55,17 +55,19 @@ describe("Transfer Token Suite", () => {
|
|
55
55
|
})
|
56
56
|
|
57
57
|
it("Serialize Transfer Transaction ", () => {
|
58
|
-
expect(wasm.
|
58
|
+
expect(wasm.arrayToBase58(Uint8Array.from(message))).toEqual(
|
59
59
|
"2J2EfWqeqbH17PC5yfioAeQ5h27J76uduH5nafAUuJhKb8gHCSqpDFV4oGgWPwQkBgg9tfQjatWZu8eiYYe6NF67Sd5Hf7ieAsaZT5hZow9xgjefbfs5"
|
60
60
|
)
|
61
|
-
expect(message).toEqual(
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
61
|
+
expect(message).toEqual(
|
62
|
+
new Uint8Array([
|
63
|
+
4, 28, 26, 172, 20, 253, 115, 23, 6, 248, 59, 119, 129, 151,
|
64
|
+
144, 5, 252, 208, 116, 12, 81, 146, 227, 208, 88, 57, 27, 134,
|
65
|
+
143, 7, 76, 94, 8, 0, 0, 0, 0, 1, 127, 201, 78, 107, 19, 0, 0,
|
66
|
+
0, 23, 72, 118, 232, 0, 0, 0, 0, 0, 0, 15, 66, 64, 1, 49, 146,
|
67
|
+
80, 170, 11, 139, 27, 185, 41, 131, 242, 219, 45, 180, 199, 38,
|
68
|
+
41, 173, 240, 198, 30, 146, 73, 23, 128
|
69
|
+
])
|
70
|
+
)
|
69
71
|
expect(rawTx).toStrictEqual({
|
70
72
|
senderPublicKey: "2ti1GM7F7J78J347fqSWSVocueDV3RSCFkLSKqmhk35Z",
|
71
73
|
recipient: "37xRcbn1LiT1Az4REoLhjpca93jPG1gTEwq",
|
@@ -86,9 +88,9 @@ describe("Transfer Token Suite", () => {
|
|
86
88
|
expect(tx.transaction().signature).not.toBe("")
|
87
89
|
|
88
90
|
const result = wasm.validateSignature(
|
89
|
-
wasm.
|
90
|
-
new
|
91
|
-
wasm.
|
91
|
+
wasm.base58ToArray(senderAccount.publicKey),
|
92
|
+
new Uint8Array(message),
|
93
|
+
wasm.base58ToArray(sign)
|
92
94
|
)
|
93
95
|
expect(result).toBe(true)
|
94
96
|
})
|
@@ -252,16 +252,26 @@ describe("Create Signatures", () => {
|
|
252
252
|
})
|
253
253
|
}
|
254
254
|
const message = [
|
255
|
-
wasm.
|
256
|
-
wasm.
|
257
|
-
|
255
|
+
wasm.arrayToBase58(wasm.serializeString("Hello, Lunes Signature!")),
|
256
|
+
wasm.arrayToBase58(
|
257
|
+
wasm.serializeString(
|
258
|
+
"This is a new test for validate Signatures in Lunes Cryptography"
|
259
|
+
)
|
260
|
+
),
|
261
|
+
wasm.arrayToBase58(
|
262
|
+
wasm.serializeString("Let's do some more tests just in case")
|
258
263
|
),
|
259
|
-
wasm.
|
260
|
-
|
261
|
-
|
262
|
-
|
264
|
+
wasm.arrayToBase58(
|
265
|
+
wasm.serializeString(
|
266
|
+
"One more to see if everything is working well"
|
267
|
+
)
|
268
|
+
),
|
269
|
+
wasm.arrayToBase58(
|
270
|
+
wasm.serializeString(
|
271
|
+
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. \
|
263
272
|
Maecenas turpis felis, gravida eget dapibus quis, molestie at mi. \
|
264
273
|
Phasellus quis mollis nulla. Nam euismod nec diam in viverra."
|
274
|
+
)
|
265
275
|
)
|
266
276
|
]
|
267
277
|
|