lunesjs 1.5.7 → 1.5.10
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/package.json +14 -8
- package/.devcontainer/devcontainer.json +0 -14
- package/.github/workflows/deploy.yml +0 -48
- package/.github/workflows/test.yml +0 -35
- package/.gitlab/.gitlab-ci.yml +0 -21
- package/.gitlab/issue_templates/bug.md +0 -13
- package/.gitlab/issue_templates/proposal.md +0 -5
- package/.gitlab/merge_request_templates/MR.md +0 -7
- package/.prettierrc.yml +0 -3
- package/CHANGELOG.md +0 -3
- package/CONTRIBUTING.md +0 -51
- package/Dockerfile +0 -6
- package/dist/client/transactions/BaseTransaction.d.ts +0 -6
- package/dist/client/transactions/BaseTransaction.js +0 -2
- package/dist/client/transactions/transactions.types.d.ts +0 -10
- 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/constants.js +0 -2064
- 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/utils/crypto.d.ts +0 -13
- package/dist/utils/crypto.js +0 -102
- package/jest.config.js +0 -11
- package/src/client/transactions/BaseTransaction.ts +0 -7
- package/src/client/transactions/transactions.types.ts +0 -11
- package/src/client/transactions/transfer/service.transfer.ts +0 -58
- package/src/client/transactions/transfer/transfer.types.ts +0 -12
- package/src/client/transactions/transfer/validator.ts +0 -92
- package/src/client/wallet/constants.ts +0 -2065
- package/src/client/wallet/service.account.ts +0 -74
- package/src/client/wallet/wallet.types.ts +0 -23
- package/src/utils/crypto.ts +0 -109
- package/static/img/jslogo.png +0 -0
- package/test/client/transactions/transfer/transfer.token.test.ts +0 -97
- package/test/client/wallet/service.account.test.ts +0 -330
- package/tsconfig.json +0 -15
@@ -1,74 +0,0 @@
|
|
1
|
-
import { IAccount } from "./wallet.types"
|
2
|
-
import cryptoUtils from "../../utils/crypto"
|
3
|
-
|
4
|
-
class Account implements IAccount {
|
5
|
-
privateKey: string
|
6
|
-
publicKey: string
|
7
|
-
address: string
|
8
|
-
chain: number
|
9
|
-
nonce: number
|
10
|
-
seed: string
|
11
|
-
|
12
|
-
constructor(wallet: IAccount) {
|
13
|
-
this.privateKey = wallet.privateKey
|
14
|
-
this.publicKey = wallet.publicKey
|
15
|
-
this.address = wallet.address
|
16
|
-
this.chain = wallet.chain
|
17
|
-
this.nonce = wallet.nonce
|
18
|
-
this.seed = wallet.seed
|
19
|
-
}
|
20
|
-
}
|
21
|
-
|
22
|
-
export function accountFactory({
|
23
|
-
privateKey,
|
24
|
-
publicKey,
|
25
|
-
address,
|
26
|
-
nWords,
|
27
|
-
chain,
|
28
|
-
nonce,
|
29
|
-
seed
|
30
|
-
}: {
|
31
|
-
privateKey?: string
|
32
|
-
publicKey?: string
|
33
|
-
address?: string
|
34
|
-
nWords?: number
|
35
|
-
chain?: number
|
36
|
-
nonce?: number
|
37
|
-
seed?: string
|
38
|
-
} = {}): Account {
|
39
|
-
if (seed != undefined) {
|
40
|
-
return new Account({
|
41
|
-
...cryptoUtils.fromExistingSeed(
|
42
|
-
seed,
|
43
|
-
nonce != undefined ? nonce : 0,
|
44
|
-
chain != undefined ? chain : 1
|
45
|
-
)
|
46
|
-
})
|
47
|
-
} else if (privateKey != undefined) {
|
48
|
-
return new Account({
|
49
|
-
...cryptoUtils.fromPrivateKey(
|
50
|
-
privateKey,
|
51
|
-
chain != undefined ? chain : 1
|
52
|
-
)
|
53
|
-
})
|
54
|
-
} else if (publicKey != undefined) {
|
55
|
-
return new Account({
|
56
|
-
...cryptoUtils.fromPublicKey(
|
57
|
-
publicKey,
|
58
|
-
chain != undefined ? chain : 1
|
59
|
-
)
|
60
|
-
})
|
61
|
-
} else if (address != undefined) {
|
62
|
-
return new Account({
|
63
|
-
...cryptoUtils.fromAddress(address, chain != undefined ? chain : 0)
|
64
|
-
})
|
65
|
-
} else {
|
66
|
-
return new Account({
|
67
|
-
...cryptoUtils.fromNewSeed(
|
68
|
-
nWords != undefined ? nWords : 12,
|
69
|
-
nonce != undefined ? nonce : 0,
|
70
|
-
chain != undefined ? chain : 1
|
71
|
-
)
|
72
|
-
})
|
73
|
-
}
|
74
|
-
}
|
@@ -1,23 +0,0 @@
|
|
1
|
-
export type empty = ""
|
2
|
-
export type zero = 0
|
3
|
-
|
4
|
-
export namespace WalletTypes {
|
5
|
-
export type Seed = string | empty
|
6
|
-
export type Nonce = number | zero // 0 ... 4.294.967.295
|
7
|
-
export enum Chain {
|
8
|
-
Mainnet = 1,
|
9
|
-
Testnet = 0
|
10
|
-
}
|
11
|
-
export type PrivateKey = string | empty
|
12
|
-
export type PublicKey = string | empty
|
13
|
-
export type Address = string | empty
|
14
|
-
}
|
15
|
-
|
16
|
-
export interface IAccount {
|
17
|
-
privateKey: WalletTypes.PrivateKey
|
18
|
-
publicKey: WalletTypes.PublicKey
|
19
|
-
address: WalletTypes.Address
|
20
|
-
nonce: WalletTypes.Nonce
|
21
|
-
chain: WalletTypes.Chain
|
22
|
-
seed: WalletTypes.Seed
|
23
|
-
}
|
package/src/utils/crypto.ts
DELETED
@@ -1,109 +0,0 @@
|
|
1
|
-
import { IAccount, WalletTypes } from "../client/wallet/wallet.types"
|
2
|
-
import walletConstants from "../client/wallet/constants"
|
3
|
-
import * as wasm from "lunesrs"
|
4
|
-
|
5
|
-
const cryptoUtils = {
|
6
|
-
fromExistingSeed: (
|
7
|
-
seed: string,
|
8
|
-
nonce: number,
|
9
|
-
chain: WalletTypes.Chain
|
10
|
-
): IAccount => {
|
11
|
-
const hidden_seed = wasm.hiddenSeed(nonce, seed)
|
12
|
-
const privateKey = wasm.toPrivateKey(hidden_seed)
|
13
|
-
const publicKey = wasm.toPublicKey(privateKey)
|
14
|
-
const address = wasm.toAddress(1, chain, publicKey)
|
15
|
-
|
16
|
-
return {
|
17
|
-
nonce: nonce,
|
18
|
-
chain: chain,
|
19
|
-
seed: seed,
|
20
|
-
privateKey: wasm.arrayToBase58(privateKey),
|
21
|
-
publicKey: wasm.arrayToBase58(publicKey),
|
22
|
-
address: wasm.arrayToBase58(address)
|
23
|
-
}
|
24
|
-
},
|
25
|
-
fromPrivateKey: (
|
26
|
-
privateKey: string,
|
27
|
-
chain: WalletTypes.Chain
|
28
|
-
): IAccount => {
|
29
|
-
const publicKey = wasm.toPublicKey(wasm.base58ToArray(privateKey))
|
30
|
-
const address = wasm.toAddress(1, chain, publicKey)
|
31
|
-
|
32
|
-
return {
|
33
|
-
seed: "",
|
34
|
-
nonce: 0,
|
35
|
-
chain: chain,
|
36
|
-
privateKey: privateKey,
|
37
|
-
publicKey: wasm.arrayToBase58(publicKey),
|
38
|
-
address: wasm.arrayToBase58(address)
|
39
|
-
}
|
40
|
-
},
|
41
|
-
fromPublicKey: (publicKey: string, chain: WalletTypes.Chain): IAccount => {
|
42
|
-
const address = wasm.toAddress(1, chain, wasm.base58ToArray(publicKey))
|
43
|
-
|
44
|
-
return {
|
45
|
-
seed: "",
|
46
|
-
nonce: 0,
|
47
|
-
privateKey: "",
|
48
|
-
chain: chain,
|
49
|
-
publicKey: publicKey,
|
50
|
-
address: wasm.arrayToBase58(address)
|
51
|
-
}
|
52
|
-
},
|
53
|
-
fromAddress: (address: string, chain: WalletTypes.Chain): IAccount => {
|
54
|
-
return {
|
55
|
-
seed: "",
|
56
|
-
nonce: 0,
|
57
|
-
privateKey: "",
|
58
|
-
publicKey: "",
|
59
|
-
chain: chain,
|
60
|
-
address: address
|
61
|
-
}
|
62
|
-
},
|
63
|
-
fromNewSeed: (
|
64
|
-
nWords: number,
|
65
|
-
nonce: number,
|
66
|
-
chain: WalletTypes.Chain
|
67
|
-
): IAccount => {
|
68
|
-
let seed = []
|
69
|
-
nWords = nWords != undefined ? Math.round(nWords / 3) : 4
|
70
|
-
for (let i = 0; i < nWords; i++) {
|
71
|
-
for (let n in wasm.randomTripleNumber()) {
|
72
|
-
seed.push(walletConstants.wordsList[n])
|
73
|
-
}
|
74
|
-
}
|
75
|
-
return cryptoUtils.fromExistingSeed(seed.join(" "), nonce, chain)
|
76
|
-
},
|
77
|
-
validateAddress: (address: string, chain: WalletTypes.Chain): boolean => {
|
78
|
-
return wasm.validateAddress(chain, wasm.base58ToArray(address))
|
79
|
-
},
|
80
|
-
validateSignature: (
|
81
|
-
publicKey: string,
|
82
|
-
message: string,
|
83
|
-
signature: string
|
84
|
-
): boolean => {
|
85
|
-
return wasm.validateSignature(
|
86
|
-
wasm.base58ToArray(publicKey),
|
87
|
-
wasm.base58ToArray(message),
|
88
|
-
wasm.base58ToArray(signature)
|
89
|
-
)
|
90
|
-
},
|
91
|
-
fastSignature: (privateKey: string, message: string) => {
|
92
|
-
return wasm.arrayToBase58(
|
93
|
-
wasm.fastSignature(
|
94
|
-
wasm.base58ToArray(privateKey),
|
95
|
-
wasm.base58ToArray(message)
|
96
|
-
)
|
97
|
-
)
|
98
|
-
},
|
99
|
-
fullSignature: (privateKey: string, message: string) => {
|
100
|
-
return wasm.arrayToBase58(
|
101
|
-
wasm.fullSignature(
|
102
|
-
wasm.base58ToArray(privateKey),
|
103
|
-
wasm.base58ToArray(message)
|
104
|
-
)
|
105
|
-
)
|
106
|
-
}
|
107
|
-
}
|
108
|
-
|
109
|
-
export default cryptoUtils
|
package/static/img/jslogo.png
DELETED
Binary file
|
@@ -1,97 +0,0 @@
|
|
1
|
-
import { transferTokenFactory } from "../../../../src/client/transactions/transfer/service.transfer"
|
2
|
-
import { TransactionsTypes } from "../../../../src/client/transactions/transactions.types"
|
3
|
-
import { accountFactory } from "../../../../src/client/wallet/service.account"
|
4
|
-
import validator from "../../../../src/client/transactions/transfer/validator"
|
5
|
-
import { WalletTypes } from "../../../../src/client/wallet/wallet.types"
|
6
|
-
import * as wasm from "lunesrs"
|
7
|
-
|
8
|
-
describe("Transfer Token Suite", () => {
|
9
|
-
const senderAccount = accountFactory({
|
10
|
-
privateKey: "8YMbX5BCQdazwgdVfeUpKuoUJrmYpMyGVAGAsNaHVj1u",
|
11
|
-
chain: WalletTypes.Chain.Mainnet
|
12
|
-
})
|
13
|
-
|
14
|
-
const recipientAccount = accountFactory({
|
15
|
-
privateKey: "G6E2xNBWtsRG8XBDmeTQQxZNHHUa6K9dnc9KrYtKyGwM",
|
16
|
-
chain: WalletTypes.Chain.Mainnet
|
17
|
-
})
|
18
|
-
|
19
|
-
const rawTx = {
|
20
|
-
type: TransactionsTypes.TransferToken.int,
|
21
|
-
sender: senderAccount.address,
|
22
|
-
senderPublicKey: senderAccount.publicKey,
|
23
|
-
recipient: recipientAccount.address,
|
24
|
-
amount: 100000000000,
|
25
|
-
timestamp: 1648349834003,
|
26
|
-
fee: TransactionsTypes.TransferToken.fee,
|
27
|
-
signature: "",
|
28
|
-
assetId: "",
|
29
|
-
feeAsset: ""
|
30
|
-
}
|
31
|
-
|
32
|
-
const message = validator.serialize(
|
33
|
-
rawTx.senderPublicKey,
|
34
|
-
rawTx.assetId,
|
35
|
-
rawTx.feeAsset,
|
36
|
-
rawTx.timestamp,
|
37
|
-
rawTx.amount,
|
38
|
-
rawTx.fee,
|
39
|
-
rawTx.recipient
|
40
|
-
)
|
41
|
-
|
42
|
-
const tx = transferTokenFactory(
|
43
|
-
senderAccount.publicKey,
|
44
|
-
recipientAccount.address,
|
45
|
-
100000000000,
|
46
|
-
undefined,
|
47
|
-
1648349834003
|
48
|
-
)
|
49
|
-
|
50
|
-
it("Create a Transfer Transaction", () => {
|
51
|
-
expect(tx.transaction().recipient).toEqual(recipientAccount.address)
|
52
|
-
expect(tx.transaction().sender).toEqual(senderAccount.address)
|
53
|
-
expect(tx.transaction().amount).toEqual(100000000000)
|
54
|
-
expect(tx.transaction().type).toEqual(4)
|
55
|
-
})
|
56
|
-
|
57
|
-
it("Serialize Transfer Transaction ", () => {
|
58
|
-
expect(wasm.arrayToBase58(Uint8Array.from(message))).toEqual(
|
59
|
-
"2J2EfWqeqbH17PC5yfioAeQ5h27J76uduH5nafAUuJhKb8gHCSqpDFV4oGgWPwQkBgg9tfQjatWZu8eiYYe6NF67Sd5Hf7ieAsaZT5hZow9xgjefbfs5"
|
60
|
-
)
|
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
|
-
)
|
71
|
-
expect(rawTx).toStrictEqual({
|
72
|
-
senderPublicKey: "2ti1GM7F7J78J347fqSWSVocueDV3RSCFkLSKqmhk35Z",
|
73
|
-
recipient: "37xRcbn1LiT1Az4REoLhjpca93jPG1gTEwq",
|
74
|
-
sender: "37tQRv7x2RHd32Ss2i1EFTWSTSsqkwXcaBe",
|
75
|
-
timestamp: 1648349834003,
|
76
|
-
amount: 100000000000,
|
77
|
-
signature: "",
|
78
|
-
fee: 1000000,
|
79
|
-
feeAsset: "",
|
80
|
-
assetId: "",
|
81
|
-
type: 4
|
82
|
-
})
|
83
|
-
})
|
84
|
-
|
85
|
-
it("Signed a Transfer Transaction", () => {
|
86
|
-
expect(tx.transaction()).toEqual(rawTx)
|
87
|
-
const sign = tx.sign(senderAccount.privateKey).signature
|
88
|
-
expect(tx.transaction().signature).not.toBe("")
|
89
|
-
|
90
|
-
const result = wasm.validateSignature(
|
91
|
-
wasm.base58ToArray(senderAccount.publicKey),
|
92
|
-
new Uint8Array(message),
|
93
|
-
wasm.base58ToArray(sign)
|
94
|
-
)
|
95
|
-
expect(result).toBe(true)
|
96
|
-
})
|
97
|
-
})
|
@@ -1,330 +0,0 @@
|
|
1
|
-
import { accountFactory } from "../../../src/client/wallet/service.account"
|
2
|
-
import { WalletTypes } from "../../../src/client/wallet/wallet.types"
|
3
|
-
import cryptoUtils from "../../../src/utils/crypto"
|
4
|
-
import * as wasm from "lunesrs"
|
5
|
-
|
6
|
-
describe("Create Account from New Seed", () => {
|
7
|
-
const createMainnetAccountFromNewSeed = () => {
|
8
|
-
return accountFactory()
|
9
|
-
}
|
10
|
-
const createTestnetAccountFromNewSeed = () => {
|
11
|
-
return accountFactory({ chain: WalletTypes.Chain.Testnet })
|
12
|
-
}
|
13
|
-
|
14
|
-
it("Test Address of Mainnet Account from New Seed", () => {
|
15
|
-
const w = createMainnetAccountFromNewSeed()
|
16
|
-
expect(
|
17
|
-
cryptoUtils.validateAddress(
|
18
|
-
w.address != undefined ? w.address : "",
|
19
|
-
WalletTypes.Chain.Mainnet
|
20
|
-
)
|
21
|
-
).toEqual(true)
|
22
|
-
})
|
23
|
-
it("Test Address of Testnet Account from New Seed", () => {
|
24
|
-
const w = createTestnetAccountFromNewSeed()
|
25
|
-
expect(
|
26
|
-
cryptoUtils.validateAddress(
|
27
|
-
w.address != undefined ? w.address : "",
|
28
|
-
WalletTypes.Chain.Testnet
|
29
|
-
)
|
30
|
-
).toEqual(true)
|
31
|
-
})
|
32
|
-
})
|
33
|
-
|
34
|
-
describe("Create Account from Seed", () => {
|
35
|
-
const seed =
|
36
|
-
"scrub guard swim catch range upon dawn ensure segment alpha sentence spend effort bar benefit"
|
37
|
-
|
38
|
-
const createMainnetAccountFromSeed = (seed: string, nonce?: number) => {
|
39
|
-
return accountFactory({
|
40
|
-
seed: seed,
|
41
|
-
nonce: nonce != undefined ? nonce : 0,
|
42
|
-
chain: WalletTypes.Chain.Mainnet
|
43
|
-
})
|
44
|
-
}
|
45
|
-
|
46
|
-
const createTestnetAccountFromSeed = (seed: string, nonce?: number) => {
|
47
|
-
return accountFactory({
|
48
|
-
seed: seed,
|
49
|
-
nonce: nonce != undefined ? nonce : 0,
|
50
|
-
chain: WalletTypes.Chain.Testnet
|
51
|
-
})
|
52
|
-
}
|
53
|
-
|
54
|
-
it("Test Create Mainnet Account from seed", () => {
|
55
|
-
const prvk = "BnafXBSq1VDUdZ1nSjJoxhnQdBv2hk3o6dbV49TD1bzo"
|
56
|
-
const pubk = "2uuQVr3B5aGgvSJ5BMCw4Cd19tdYdnMGoYnji99aPde4"
|
57
|
-
const addr = "37o7aY3eZZTXmzrDa5e4Wj3Z4ZZuyV42Aaj"
|
58
|
-
const w = createMainnetAccountFromSeed(seed, 0)
|
59
|
-
expect(w.privateKey).toEqual(prvk)
|
60
|
-
expect(w.publicKey).toEqual(pubk)
|
61
|
-
expect(w.address).toEqual(addr)
|
62
|
-
})
|
63
|
-
|
64
|
-
it("Test Create Testnet Account from seed", () => {
|
65
|
-
const prvk = "BnafXBSq1VDUdZ1nSjJoxhnQdBv2hk3o6dbV49TD1bzo"
|
66
|
-
const pubk = "2uuQVr3B5aGgvSJ5BMCw4Cd19tdYdnMGoYnji99aPde4"
|
67
|
-
const addr = "37PmyYwMGrH4uBR5V4DjCEvHGw4f2pdXW5u"
|
68
|
-
const w = createTestnetAccountFromSeed(seed, 0)
|
69
|
-
expect(w.privateKey).toEqual(prvk)
|
70
|
-
expect(w.publicKey).toEqual(pubk)
|
71
|
-
expect(w.address).toEqual(addr)
|
72
|
-
})
|
73
|
-
|
74
|
-
const mainnetNonce12345Address: [number, string][] = [
|
75
|
-
[0, "37o7aY3eZZTXmzrDa5e4Wj3Z4ZZuyV42Aaj"],
|
76
|
-
[1, "37tD32367v1fiWgW8waw3QTdYTKKGrCV3zw"],
|
77
|
-
[2, "37qYK5eRJEr8a38hUXmxYv9aoQ8NpXH7Aqd"],
|
78
|
-
[3, "37w8stLd9JQwUKBrBUQr1VryJuhS3RWqEen"],
|
79
|
-
[4, "37vVbQVXEE4Lvs7X4wimsoxAvqBmoyHsWDJ"]
|
80
|
-
]
|
81
|
-
test.each(mainnetNonce12345Address)(
|
82
|
-
"Test Create Mainnet Account with range of nonces",
|
83
|
-
(nonce, address) => {
|
84
|
-
expect(createMainnetAccountFromSeed(seed, nonce).address).toEqual(
|
85
|
-
address
|
86
|
-
)
|
87
|
-
}
|
88
|
-
)
|
89
|
-
|
90
|
-
const testnetNonce12345Address: [number, string][] = [
|
91
|
-
[0, "37PmyYwMGrH4uBR5V4DjCEvHGw4f2pdXW5u"],
|
92
|
-
[1, "37UsS2vnqCqCqhFN3vAbivLMkpp4L8GMCyP"],
|
93
|
-
[2, "37SCi6Y81XffhDhZPWMdES2K1md7skK1mFu"],
|
94
|
-
[3, "37XoGuEKrbEUbVki6SzWh1jhXHCB6jnKFxS"],
|
95
|
-
[4, "37X9zRPDwWst43gNyvJSZKpu9CgWsHt1U8i"]
|
96
|
-
]
|
97
|
-
test.each(testnetNonce12345Address)(
|
98
|
-
"Test Create Testnet Account with range of nonces",
|
99
|
-
(nonce, address) => {
|
100
|
-
expect(createTestnetAccountFromSeed(seed, nonce).address).toEqual(
|
101
|
-
address
|
102
|
-
)
|
103
|
-
}
|
104
|
-
)
|
105
|
-
})
|
106
|
-
|
107
|
-
describe("Create Account from Private Key", () => {
|
108
|
-
const privateKey = "BnafXBSq1VDUdZ1nSjJoxhnQdBv2hk3o6dbV49TD1bzo"
|
109
|
-
const publicKey = "2uuQVr3B5aGgvSJ5BMCw4Cd19tdYdnMGoYnji99aPde4"
|
110
|
-
|
111
|
-
const createMainnetAccountFromPrivateKey = (privateKey: string) => {
|
112
|
-
return accountFactory({
|
113
|
-
privateKey: privateKey,
|
114
|
-
chain: WalletTypes.Chain.Mainnet
|
115
|
-
})
|
116
|
-
}
|
117
|
-
|
118
|
-
const createTestnetAccountFromPrivateKey = (privateKey: string) => {
|
119
|
-
return accountFactory({
|
120
|
-
privateKey: privateKey,
|
121
|
-
chain: WalletTypes.Chain.Testnet
|
122
|
-
})
|
123
|
-
}
|
124
|
-
|
125
|
-
it("Test Create Mainnet Account from Private Key", () => {
|
126
|
-
const w = createMainnetAccountFromPrivateKey(privateKey)
|
127
|
-
const addr = "37o7aY3eZZTXmzrDa5e4Wj3Z4ZZuyV42Aaj"
|
128
|
-
expect(w.privateKey).toEqual(privateKey)
|
129
|
-
expect(w.publicKey).toEqual(publicKey)
|
130
|
-
expect(w.address).toEqual(addr)
|
131
|
-
})
|
132
|
-
|
133
|
-
it("Test Create Testnet Account from Private Key", () => {
|
134
|
-
const w = createTestnetAccountFromPrivateKey(privateKey)
|
135
|
-
const addr = "37PmyYwMGrH4uBR5V4DjCEvHGw4f2pdXW5u"
|
136
|
-
expect(w.privateKey).toEqual(privateKey)
|
137
|
-
expect(w.publicKey).toEqual(publicKey)
|
138
|
-
expect(w.address).toEqual(addr)
|
139
|
-
})
|
140
|
-
})
|
141
|
-
|
142
|
-
describe("Create Account from Public Key", () => {
|
143
|
-
const publicKey = "2uuQVr3B5aGgvSJ5BMCw4Cd19tdYdnMGoYnji99aPde4"
|
144
|
-
|
145
|
-
const createMainnetAccountFromPublicKey = (publicKey: string) => {
|
146
|
-
return accountFactory({
|
147
|
-
publicKey: publicKey,
|
148
|
-
chain: WalletTypes.Chain.Mainnet
|
149
|
-
})
|
150
|
-
}
|
151
|
-
|
152
|
-
const createTestnetAccountFromPublicKey = (publicKey: string) => {
|
153
|
-
return accountFactory({
|
154
|
-
publicKey: publicKey,
|
155
|
-
chain: WalletTypes.Chain.Testnet
|
156
|
-
})
|
157
|
-
}
|
158
|
-
|
159
|
-
it("Test Create Mainnet Account From Public Key", () => {
|
160
|
-
expect(createMainnetAccountFromPublicKey(publicKey).address).toEqual(
|
161
|
-
"37o7aY3eZZTXmzrDa5e4Wj3Z4ZZuyV42Aaj"
|
162
|
-
)
|
163
|
-
})
|
164
|
-
|
165
|
-
it("Test Create Testnet Account From Public Key", () => {
|
166
|
-
expect(createTestnetAccountFromPublicKey(publicKey).address).toEqual(
|
167
|
-
"37PmyYwMGrH4uBR5V4DjCEvHGw4f2pdXW5u"
|
168
|
-
)
|
169
|
-
})
|
170
|
-
})
|
171
|
-
|
172
|
-
describe("Create Account from Address", () => {
|
173
|
-
const createMainnetAccountFromAdress = () => {
|
174
|
-
return accountFactory({
|
175
|
-
address: "37o7aY3eZZTXmzrDa5e4Wj3Z4ZZuyV42Aaj",
|
176
|
-
chain: WalletTypes.Chain.Mainnet
|
177
|
-
})
|
178
|
-
}
|
179
|
-
|
180
|
-
const createTestnetAccountFromAdress = () => {
|
181
|
-
return accountFactory({
|
182
|
-
address: "37PmyYwMGrH4uBR5V4DjCEvHGw4f2pdXW5u",
|
183
|
-
chain: WalletTypes.Chain.Mainnet
|
184
|
-
})
|
185
|
-
}
|
186
|
-
|
187
|
-
it("Test Create Mainnet Account from Address", () => {
|
188
|
-
expect(createMainnetAccountFromAdress().address).toEqual(
|
189
|
-
"37o7aY3eZZTXmzrDa5e4Wj3Z4ZZuyV42Aaj"
|
190
|
-
)
|
191
|
-
})
|
192
|
-
|
193
|
-
it("Test Create Testnet Account from Address", () => {
|
194
|
-
expect(createTestnetAccountFromAdress().address).toEqual(
|
195
|
-
"37PmyYwMGrH4uBR5V4DjCEvHGw4f2pdXW5u"
|
196
|
-
)
|
197
|
-
})
|
198
|
-
})
|
199
|
-
|
200
|
-
describe("Validate Account Address", () => {
|
201
|
-
const createMainnetAccount = () => {
|
202
|
-
return accountFactory({
|
203
|
-
chain: WalletTypes.Chain.Mainnet
|
204
|
-
}).address
|
205
|
-
}
|
206
|
-
|
207
|
-
const createTestnetAccount = () => {
|
208
|
-
return accountFactory({
|
209
|
-
chain: WalletTypes.Chain.Testnet
|
210
|
-
}).address
|
211
|
-
}
|
212
|
-
|
213
|
-
const addressMainnet = Array.from(new Array(20), () =>
|
214
|
-
createMainnetAccount()
|
215
|
-
)
|
216
|
-
|
217
|
-
const addressTestnet = Array.from(new Array(20), () =>
|
218
|
-
createTestnetAccount()
|
219
|
-
)
|
220
|
-
test.each(addressMainnet)(
|
221
|
-
"Test Validating Mainnet Account Address",
|
222
|
-
(addressMainnet) => {
|
223
|
-
const result = cryptoUtils.validateAddress(
|
224
|
-
addressMainnet,
|
225
|
-
WalletTypes.Chain.Mainnet
|
226
|
-
)
|
227
|
-
expect(result).toEqual(true)
|
228
|
-
}
|
229
|
-
)
|
230
|
-
|
231
|
-
test.each(addressTestnet)(
|
232
|
-
"Test Validating Testnet Account Address",
|
233
|
-
(addressTestnet) => {
|
234
|
-
const result = cryptoUtils.validateAddress(
|
235
|
-
addressTestnet,
|
236
|
-
WalletTypes.Chain.Mainnet
|
237
|
-
)
|
238
|
-
expect(result).toEqual(false)
|
239
|
-
}
|
240
|
-
)
|
241
|
-
})
|
242
|
-
|
243
|
-
describe("Create Signatures", () => {
|
244
|
-
const newAccountMainnet = () => {
|
245
|
-
return accountFactory({
|
246
|
-
chain: WalletTypes.Chain.Mainnet
|
247
|
-
})
|
248
|
-
}
|
249
|
-
const newAccountTestnet = () => {
|
250
|
-
return accountFactory({
|
251
|
-
chain: WalletTypes.Chain.Mainnet
|
252
|
-
})
|
253
|
-
}
|
254
|
-
const message = [
|
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")
|
263
|
-
),
|
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. \
|
272
|
-
Maecenas turpis felis, gravida eget dapibus quis, molestie at mi. \
|
273
|
-
Phasellus quis mollis nulla. Nam euismod nec diam in viverra."
|
274
|
-
)
|
275
|
-
)
|
276
|
-
]
|
277
|
-
|
278
|
-
test.each(message)(
|
279
|
-
"Test sign and validate signatures for Mainnet random Account with FastSignature function",
|
280
|
-
(message) => {
|
281
|
-
const w = newAccountMainnet()
|
282
|
-
const signature = cryptoUtils.fastSignature(w.privateKey, message)
|
283
|
-
const result = cryptoUtils.validateSignature(
|
284
|
-
w.publicKey,
|
285
|
-
message,
|
286
|
-
signature
|
287
|
-
)
|
288
|
-
expect(result).toEqual(true)
|
289
|
-
}
|
290
|
-
)
|
291
|
-
test.each(message)(
|
292
|
-
"Test sign and validate signatures for Testnet random Account with FastSignature function",
|
293
|
-
(message) => {
|
294
|
-
const w = newAccountTestnet()
|
295
|
-
const signature = cryptoUtils.fastSignature(w.privateKey, message)
|
296
|
-
const result = cryptoUtils.validateSignature(
|
297
|
-
w.publicKey,
|
298
|
-
message,
|
299
|
-
signature
|
300
|
-
)
|
301
|
-
expect(result).toEqual(true)
|
302
|
-
}
|
303
|
-
)
|
304
|
-
test.each(message)(
|
305
|
-
"Test sign and validate signatures for Mainnet random Account with FullSignature function",
|
306
|
-
(message) => {
|
307
|
-
const w = newAccountMainnet()
|
308
|
-
const signature = cryptoUtils.fullSignature(w.privateKey, message)
|
309
|
-
const result = cryptoUtils.validateSignature(
|
310
|
-
w.publicKey,
|
311
|
-
message,
|
312
|
-
signature
|
313
|
-
)
|
314
|
-
expect(result).toEqual(true)
|
315
|
-
}
|
316
|
-
)
|
317
|
-
test.each(message)(
|
318
|
-
"Test sign and validate signatures for Testnet random Account with FullSignature function",
|
319
|
-
(message) => {
|
320
|
-
const w = newAccountTestnet()
|
321
|
-
const signature = cryptoUtils.fullSignature(w.privateKey, message)
|
322
|
-
const result = cryptoUtils.validateSignature(
|
323
|
-
w.publicKey,
|
324
|
-
message,
|
325
|
-
signature
|
326
|
-
)
|
327
|
-
expect(result).toEqual(true)
|
328
|
-
}
|
329
|
-
)
|
330
|
-
})
|
package/tsconfig.json
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
{
|
2
|
-
"compilerOptions": {
|
3
|
-
"target": "es6",
|
4
|
-
"module": "commonjs",
|
5
|
-
"outDir": "./dist",
|
6
|
-
"strict": true,
|
7
|
-
"noUnusedLocals": true,
|
8
|
-
"noUnusedParameters": true,
|
9
|
-
"noImplicitReturns": true,
|
10
|
-
"noFallthroughCasesInSwitch": true,
|
11
|
-
"esModuleInterop": true
|
12
|
-
},
|
13
|
-
"include": ["src/**/*"],
|
14
|
-
"exclude": ["node_modules", "**/*.test.ts"]
|
15
|
-
}
|