lunesjs 1.5.10 → 1.5.13

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,28 @@
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({
12
+ privateKey,
13
+ publicKey,
14
+ address,
15
+ nWords,
16
+ chain,
17
+ nonce,
18
+ seed
19
+ }?: {
20
+ privateKey?: string
21
+ publicKey?: string
22
+ address?: string
23
+ nWords?: number
24
+ chain?: number
25
+ nonce?: number
26
+ seed?: string
27
+ }): Account
28
+ export {}
@@ -0,0 +1,83 @@
1
+ "use strict"
2
+ var __importDefault =
3
+ (this && this.__importDefault) ||
4
+ function (mod) {
5
+ return mod && mod.__esModule ? mod : { default: mod }
6
+ }
7
+ Object.defineProperty(exports, "__esModule", { value: true })
8
+ exports.accountFactory = void 0
9
+ const crypto_1 = __importDefault(require("../../utils/crypto"))
10
+ class Account {
11
+ constructor(wallet) {
12
+ this.privateKey = wallet.privateKey
13
+ this.publicKey = wallet.publicKey
14
+ this.address = wallet.address
15
+ this.chain = wallet.chain
16
+ this.nonce = wallet.nonce
17
+ this.seed = wallet.seed
18
+ }
19
+ }
20
+ function accountFactory({
21
+ privateKey,
22
+ publicKey,
23
+ address,
24
+ nWords,
25
+ chain,
26
+ nonce,
27
+ seed
28
+ } = {}) {
29
+ if (seed != undefined) {
30
+ return new Account(
31
+ Object.assign(
32
+ {},
33
+ crypto_1.default.fromExistingSeed(
34
+ seed,
35
+ nonce != undefined ? nonce : 0,
36
+ chain != undefined ? chain : 1
37
+ )
38
+ )
39
+ )
40
+ } else if (privateKey != undefined) {
41
+ return new Account(
42
+ Object.assign(
43
+ {},
44
+ crypto_1.default.fromPrivateKey(
45
+ privateKey,
46
+ chain != undefined ? chain : 1
47
+ )
48
+ )
49
+ )
50
+ } else if (publicKey != undefined) {
51
+ return new Account(
52
+ Object.assign(
53
+ {},
54
+ crypto_1.default.fromPublicKey(
55
+ publicKey,
56
+ chain != undefined ? chain : 1
57
+ )
58
+ )
59
+ )
60
+ } else if (address != undefined) {
61
+ return new Account(
62
+ Object.assign(
63
+ {},
64
+ crypto_1.default.fromAddress(
65
+ address,
66
+ chain != undefined ? chain : 0
67
+ )
68
+ )
69
+ )
70
+ } else {
71
+ return new Account(
72
+ Object.assign(
73
+ {},
74
+ crypto_1.default.fromNewSeed(
75
+ nWords != undefined ? nWords : 12,
76
+ nonce != undefined ? nonce : 0,
77
+ chain != undefined ? chain : 1
78
+ )
79
+ )
80
+ )
81
+ }
82
+ }
83
+ 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 = {})))
package/lib/index.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ export { transferTokenFactory } from "./client/transactions/transfer/service.transfer"
2
+ export { accountFactory } from "./client/wallet/service.account"
3
+ export { IAccount } from "./client/wallet/wallet.types"
4
+ import cryptoUtils from "./utils/crypto"
5
+ export default cryptoUtils
package/lib/index.js ADDED
@@ -0,0 +1,24 @@
1
+ "use strict"
2
+ var __importDefault =
3
+ (this && this.__importDefault) ||
4
+ function (mod) {
5
+ return mod && mod.__esModule ? mod : { default: mod }
6
+ }
7
+ Object.defineProperty(exports, "__esModule", { value: true })
8
+ exports.accountFactory = exports.transferTokenFactory = void 0
9
+ var service_transfer_1 = require("./client/transactions/transfer/service.transfer")
10
+ Object.defineProperty(exports, "transferTokenFactory", {
11
+ enumerable: true,
12
+ get: function () {
13
+ return service_transfer_1.transferTokenFactory
14
+ }
15
+ })
16
+ var service_account_1 = require("./client/wallet/service.account")
17
+ Object.defineProperty(exports, "accountFactory", {
18
+ enumerable: true,
19
+ get: function () {
20
+ return service_account_1.accountFactory
21
+ }
22
+ })
23
+ const crypto_1 = __importDefault(require("./utils/crypto"))
24
+ exports.default = crypto_1.default
@@ -0,0 +1,25 @@
1
+ import { IAccount, WalletTypes } from "../client/wallet/wallet.types"
2
+ declare const cryptoUtils: {
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,6 +1,6 @@
1
1
  {
2
2
  "name": "lunesjs",
3
- "version": "1.5.10",
3
+ "version": "1.5.13",
4
4
  "description": "Library for communication with nodes in mainnet or testnet of the lunes-blockchain network",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -10,7 +10,7 @@
10
10
  "README.md",
11
11
  "package.json"
12
12
  ],
13
- "repository": "git@git.lunes.io:blockchain/labs/lunesjs.git",
13
+ "repository": "https://github.com/lunes-platform/lunesjs.git",
14
14
  "keywords": [
15
15
  "blockchain",
16
16
  "lunes",
@@ -19,6 +19,7 @@
19
19
  "author": "lunes-platform",
20
20
  "license": "Apache-2.0",
21
21
  "scripts": {
22
+ "publish": "yarn build && yarn publish",
22
23
  "fmt": "prettier -w .",
23
24
  "fmtc": "prettier -c",
24
25
  "test": "yarn jest",
@@ -36,4 +37,4 @@
36
37
  "axios": "^0.26.1",
37
38
  "lunesrs": "^1.8.2-web"
38
39
  }
39
- }
40
+ }