@gloxx/nodejs 0.1.0

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/README.md ADDED
@@ -0,0 +1,80 @@
1
+ ## @gloxx/nodejs
2
+
3
+
4
+ This package provides native Node.js bindings for the Gloxx network, implemented in Rust. It offers a high-performance and secure way to interact with the core functionalities of the Gloxx ecosystem, such as wallet generation, directly from your Node.js applications.
5
+
6
+ You should use this package whenever you need to perform Gloxx-related operations in a Node.js environment. This is particularly useful for:
7
+
8
+ **Backend Services:** Create and manage wallets for users in your web applications.
9
+ Decentralized Applications (dApps): Integrate wallet functionalities into your dApp's backend.
10
+
11
+ **Command-Line Tools:** Build developer tools that require wallet generation or other cryptographic operations.
12
+
13
+ **Testing and Automation:** Create scripts for testing and automating tasks on the Gloxx network.
14
+ You can install the package using either npm or yarn:
15
+
16
+ ```bash
17
+ npm install @gloxx/nodejs
18
+ ```
19
+
20
+ or
21
+ ```bash
22
+ yarn add @gloxx/nodejs
23
+ ```
24
+
25
+ The package is structured with optionalDependencies, which means that npm or yarn will automatically download the correct binary for your operating system and architecture. There's no need for any manual compilation or extra build steps.
26
+
27
+ Using the package is straightforward. Here’s how you can generate a new Gloxx wallet:
28
+
29
+ ```javascript
30
+ const { generateWallet } = require('@gloxx/nodejs');
31
+
32
+ try {
33
+ const wallet = generateWallet();
34
+ console.log('Successfully generated wallet:');
35
+ console.log('Address:', wallet.address);
36
+ console.log('Mnemonic:', wallet.mnemonic);
37
+ } catch (error) {
38
+ console.error('Failed to generate wallet:', error);
39
+ }
40
+
41
+ ```
42
+ **Output:**
43
+ Successfully generated wallet:
44
+ Address: glx1......
45
+ Mnemonic: ...
46
+
47
+ **Description:** Generates a new Gloxx wallet, including a unique address and a 12-word mnemonic phrase for recovery.
48
+ Returns: An object with the following properties:
49
+ **address (string):** The public address of the new wallet.
50
+ **mnemonic (string):** The 12-word mnemonic phrase for wallet recovery.
51
+ **Throws:** An Error if the wallet generation fails.
52
+
53
+ This package is a N-API wrapper around the powerful and secure Rust codebase of the Gloxx network. By using native Rust code, it ensures high performance and memory safety, giving you a reliable foundation for your applications. The core logic is shared with other Gloxx packages, guaranteeing consistency across the ecosystem.
54
+
55
+ The @gloxx/nodejs package is designed to be cross-platform and supports the following targets:
56
+
57
+ Linux: x64 (glibc and musl) and ARM64
58
+ Windows: x64 (MSVC)
59
+ macOS: Universal (x64 and Apple Silicon)
60
+ Android: ARM64 and ARMv7
61
+
62
+
63
+ ## Development & Build
64
+
65
+ To work on this crate or build it from source, ensure you have napi-rs installed.
66
+
67
+ ### Build
68
+ ```sh
69
+ npx napi build --release
70
+ ```
71
+
72
+ If you have any issues or questions, please refer to the main Gloxx Network repository.
73
+
74
+ (@gloxx/nodejs)[https://github.com/gloxx-labs/gloxx-network]
75
+
76
+ ## License
77
+
78
+ MIT
79
+
80
+ © 2025 Gloxx Network
package/index.d.ts ADDED
@@ -0,0 +1,26 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /* auto-generated by NAPI-RS */
5
+
6
+ /** A simple object to represent the wallet in JavaScript */
7
+ export interface NativeWallet {
8
+ address: string
9
+ mnemonic: string
10
+ privateKey: string
11
+ publicKey: string
12
+ }
13
+ /** Generates a brand new Gloxx wallet */
14
+ export declare function generateWallet(): NativeWallet
15
+ /** Imports a wallet from a recovery phrase */
16
+ export declare function importWallet(phrase: string, passphrase?: string | undefined | null): NativeWallet
17
+ /** Signs a message using a hex-encoded private key */
18
+ export declare function signMessage(message: string | Buffer, privateKeyHex: string): string
19
+ /** Verifies a signature using a hex-encoded public key */
20
+ export declare function verifySignature(message: string | Buffer, signatureHex: string, publicKeyHex: string): boolean
21
+ /** Encrypts a private key and saves it to a keystore file */
22
+ export declare function saveKeystore(privateKeyHex: string, address: string, password: string, path: string): void
23
+ /** Loads and decrypts a private key from a keystore file */
24
+ export declare function loadKeystore(address: string, password: string, path: string): string
25
+ /** Signs a message using a key stored in a keystore file */
26
+ export declare function signMessageFromKeystore(message: string | Buffer, address: string, password: string, path: string): string
package/index.js ADDED
@@ -0,0 +1,292 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ /* prettier-ignore */
4
+
5
+ /* auto-generated by NAPI-RS */
6
+
7
+ const { existsSync, readFileSync } = require('fs')
8
+ const { join } = require('path')
9
+
10
+ const { platform, arch } = process
11
+
12
+ let nativeBinding = null
13
+ let localFileExisted = false
14
+ let loadError = null
15
+
16
+ function isMusl() {
17
+ // For Node 10
18
+ if (!process.report || typeof process.report.getReport !== 'function') {
19
+ try {
20
+ const lddPath = require('child_process').execSync('which ldd').toString().trim()
21
+ return readFileSync(lddPath, 'utf8').includes('musl')
22
+ } catch (e) {
23
+ return true
24
+ }
25
+ } else {
26
+ const { glibcVersionRuntime } = process.report.getReport().header
27
+ return !glibcVersionRuntime
28
+ }
29
+ }
30
+
31
+ switch (platform) {
32
+ case 'android':
33
+ switch (arch) {
34
+ case 'arm64':
35
+ localFileExisted = existsSync(join(__dirname, 'gloxx-nodejs.android-arm64.node'))
36
+ try {
37
+ if (localFileExisted) {
38
+ nativeBinding = require('./gloxx-nodejs.android-arm64.node')
39
+ } else {
40
+ nativeBinding = require('@gloxx/nodejs-android-arm64')
41
+ }
42
+ } catch (e) {
43
+ loadError = e
44
+ }
45
+ break
46
+ case 'arm':
47
+ localFileExisted = existsSync(join(__dirname, 'gloxx-nodejs.android-arm-eabi.node'))
48
+ try {
49
+ if (localFileExisted) {
50
+ nativeBinding = require('./gloxx-nodejs.android-arm-eabi.node')
51
+ } else {
52
+ nativeBinding = require('@gloxx/nodejs-android-arm-eabi')
53
+ }
54
+ } catch (e) {
55
+ loadError = e
56
+ }
57
+ break
58
+ default:
59
+ throw new Error(`Unsupported architecture on Android ${arch}`)
60
+ }
61
+ break
62
+ case 'win32':
63
+ switch (arch) {
64
+ case 'x64':
65
+ localFileExisted = existsSync(
66
+ join(__dirname, 'gloxx-nodejs.win32-x64-msvc.node')
67
+ )
68
+ try {
69
+ if (localFileExisted) {
70
+ nativeBinding = require('./gloxx-nodejs.win32-x64-msvc.node')
71
+ } else {
72
+ nativeBinding = require('@gloxx/nodejs-win32-x64-msvc')
73
+ }
74
+ } catch (e) {
75
+ loadError = e
76
+ }
77
+ break
78
+ case 'ia32':
79
+ localFileExisted = existsSync(
80
+ join(__dirname, 'gloxx-nodejs.win32-ia32-msvc.node')
81
+ )
82
+ try {
83
+ if (localFileExisted) {
84
+ nativeBinding = require('./gloxx-nodejs.win32-ia32-msvc.node')
85
+ } else {
86
+ nativeBinding = require('@gloxx/nodejs-win32-ia32-msvc')
87
+ }
88
+ } catch (e) {
89
+ loadError = e
90
+ }
91
+ break
92
+ case 'arm64':
93
+ localFileExisted = existsSync(
94
+ join(__dirname, 'gloxx-nodejs.win32-arm64-msvc.node')
95
+ )
96
+ try {
97
+ if (localFileExisted) {
98
+ nativeBinding = require('./gloxx-nodejs.win32-arm64-msvc.node')
99
+ } else {
100
+ nativeBinding = require('@gloxx/nodejs-win32-arm64-msvc')
101
+ }
102
+ } catch (e) {
103
+ loadError = e
104
+ }
105
+ break
106
+ default:
107
+ throw new Error(`Unsupported architecture on Windows: ${arch}`)
108
+ }
109
+ break
110
+ case 'darwin':
111
+ localFileExisted = existsSync(join(__dirname, 'gloxx-nodejs.darwin-universal.node'))
112
+ try {
113
+ if (localFileExisted) {
114
+ nativeBinding = require('./gloxx-nodejs.darwin-universal.node')
115
+ } else {
116
+ nativeBinding = require('@gloxx/nodejs-darwin-universal')
117
+ }
118
+ break
119
+ } catch {}
120
+ switch (arch) {
121
+ case 'x64':
122
+ localFileExisted = existsSync(join(__dirname, 'gloxx-nodejs.darwin-x64.node'))
123
+ try {
124
+ if (localFileExisted) {
125
+ nativeBinding = require('./gloxx-nodejs.darwin-x64.node')
126
+ } else {
127
+ nativeBinding = require('@gloxx/nodejs-darwin-x64')
128
+ }
129
+ } catch (e) {
130
+ loadError = e
131
+ }
132
+ break
133
+ case 'arm64':
134
+ localFileExisted = existsSync(
135
+ join(__dirname, 'gloxx-nodejs.darwin-arm64.node')
136
+ )
137
+ try {
138
+ if (localFileExisted) {
139
+ nativeBinding = require('./gloxx-nodejs.darwin-arm64.node')
140
+ } else {
141
+ nativeBinding = require('@gloxx/nodejs-darwin-arm64')
142
+ }
143
+ } catch (e) {
144
+ loadError = e
145
+ }
146
+ break
147
+ default:
148
+ throw new Error(`Unsupported architecture on macOS: ${arch}`)
149
+ }
150
+ break
151
+ case 'freebsd':
152
+ if (arch !== 'x64') {
153
+ throw new Error(`Unsupported architecture on FreeBSD: ${arch}`)
154
+ }
155
+ localFileExisted = existsSync(join(__dirname, 'gloxx-nodejs.freebsd-x64.node'))
156
+ try {
157
+ if (localFileExisted) {
158
+ nativeBinding = require('./gloxx-nodejs.freebsd-x64.node')
159
+ } else {
160
+ nativeBinding = require('@gloxx/nodejs-freebsd-x64')
161
+ }
162
+ } catch (e) {
163
+ loadError = e
164
+ }
165
+ break
166
+ case 'linux':
167
+ switch (arch) {
168
+ case 'x64':
169
+ if (isMusl()) {
170
+ localFileExisted = existsSync(
171
+ join(__dirname, 'gloxx-nodejs.linux-x64-musl.node')
172
+ )
173
+ try {
174
+ if (localFileExisted) {
175
+ nativeBinding = require('./gloxx-nodejs.linux-x64-musl.node')
176
+ } else {
177
+ nativeBinding = require('@gloxx/nodejs-linux-x64-musl')
178
+ }
179
+ } catch (e) {
180
+ loadError = e
181
+ }
182
+ } else {
183
+ localFileExisted = existsSync(
184
+ join(__dirname, 'gloxx-nodejs.linux-x64-gnu.node')
185
+ )
186
+ try {
187
+ if (localFileExisted) {
188
+ nativeBinding = require('./gloxx-nodejs.linux-x64-gnu.node')
189
+ } else {
190
+ nativeBinding = require('@gloxx/nodejs-linux-x64-gnu')
191
+ }
192
+ } catch (e) {
193
+ loadError = e
194
+ }
195
+ }
196
+ break
197
+ case 'arm64':
198
+ if (isMusl()) {
199
+ localFileExisted = existsSync(
200
+ join(__dirname, 'gloxx-nodejs.linux-arm64-musl.node')
201
+ )
202
+ try {
203
+ if (localFileExisted) {
204
+ nativeBinding = require('./gloxx-nodejs.linux-arm64-musl.node')
205
+ } else {
206
+ nativeBinding = require('@gloxx/nodejs-linux-arm64-musl')
207
+ }
208
+ } catch (e) {
209
+ loadError = e
210
+ }
211
+ } else {
212
+ localFileExisted = existsSync(
213
+ join(__dirname, 'gloxx-nodejs.linux-arm64-gnu.node')
214
+ )
215
+ try {
216
+ if (localFileExisted) {
217
+ nativeBinding = require('./gloxx-nodejs.linux-arm64-gnu.node')
218
+ } else {
219
+ nativeBinding = require('@gloxx/nodejs-linux-arm64-gnu')
220
+ }
221
+ } catch (e) {
222
+ loadError = e
223
+ }
224
+ }
225
+ break
226
+ case 'arm':
227
+ localFileExisted = existsSync(
228
+ join(__dirname, 'gloxx-nodejs.linux-arm-gnueabihf.node')
229
+ )
230
+ try {
231
+ if (localFileExisted) {
232
+ nativeBinding = require('./gloxx-nodejs.linux-arm-gnueabihf.node')
233
+ } else {
234
+ nativeBinding = require('@gloxx/nodejs-linux-arm-gnueabihf')
235
+ }
236
+ } catch (e) {
237
+ loadError = e
238
+ }
239
+ break
240
+ case 'riscv64':
241
+ if (isMusl()) {
242
+ localFileExisted = existsSync(
243
+ join(__dirname, 'gloxx-nodejs.linux-riscv64-musl.node')
244
+ )
245
+ try {
246
+ if (localFileExisted) {
247
+ nativeBinding = require('./gloxx-nodejs.linux-riscv64-musl.node')
248
+ } else {
249
+ nativeBinding = require('@gloxx/nodejs-linux-riscv64-musl')
250
+ }
251
+ } catch (e) {
252
+ loadError = e
253
+ }
254
+ } else {
255
+ localFileExisted = existsSync(
256
+ join(__dirname, 'gloxx-nodejs.linux-riscv64-gnu.node')
257
+ )
258
+ try {
259
+ if (localFileExisted) {
260
+ nativeBinding = require('./gloxx-nodejs.linux-riscv64-gnu.node')
261
+ } else {
262
+ nativeBinding = require('@gloxx/nodejs-linux-riscv64-gnu')
263
+ }
264
+ } catch (e) {
265
+ loadError = e
266
+ }
267
+ }
268
+ break
269
+ default:
270
+ throw new Error(`Unsupported architecture on Linux: ${arch}`)
271
+ }
272
+ break
273
+ default:
274
+ throw new Error(`Unsupported OS: ${platform}, architecture: ${arch}`)
275
+ }
276
+
277
+ if (!nativeBinding) {
278
+ if (loadError) {
279
+ throw loadError
280
+ }
281
+ throw new Error(`Failed to load native binding`)
282
+ }
283
+
284
+ const { generateWallet, importWallet, signMessage, verifySignature, saveKeystore, loadKeystore, signMessageFromKeystore } = nativeBinding
285
+
286
+ module.exports.generateWallet = generateWallet
287
+ module.exports.importWallet = importWallet
288
+ module.exports.signMessage = signMessage
289
+ module.exports.verifySignature = verifySignature
290
+ module.exports.saveKeystore = saveKeystore
291
+ module.exports.loadKeystore = loadKeystore
292
+ module.exports.signMessageFromKeystore = signMessageFromKeystore
@@ -0,0 +1,3 @@
1
+ # `@gloxx/nodejs-android-arm-eabi`
2
+
3
+ This is the **armv7-linux-androideabi** binary for `@gloxx/nodejs`
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "@gloxx/nodejs-android-arm-eabi",
3
+ "version": "0.1.0",
4
+ "cpu": [
5
+ "arm"
6
+ ],
7
+ "main": "gloxx-nodejs.android-arm-eabi.node",
8
+ "files": [
9
+ "gloxx-nodejs.android-arm-eabi.node"
10
+ ],
11
+ "description": "Native Rust bindings for the Gloxx Network wallet",
12
+ "license": "MIT",
13
+ "os": [
14
+ "android"
15
+ ]
16
+ }
@@ -0,0 +1,3 @@
1
+ # `@gloxx/nodejs-android-arm64`
2
+
3
+ This is the **aarch64-linux-android** binary for `@gloxx/nodejs`
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "@gloxx/nodejs-android-arm64",
3
+ "version": "0.1.0",
4
+ "cpu": [
5
+ "arm64"
6
+ ],
7
+ "main": "gloxx-nodejs.android-arm64.node",
8
+ "files": [
9
+ "gloxx-nodejs.android-arm64.node"
10
+ ],
11
+ "description": "Native Rust bindings for the Gloxx Network wallet",
12
+ "license": "MIT",
13
+ "os": [
14
+ "android"
15
+ ]
16
+ }
@@ -0,0 +1,3 @@
1
+ # `@gloxx/nodejs-darwin-arm64`
2
+
3
+ This is the **aarch64-apple-darwin** binary for `@gloxx/nodejs`
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "@gloxx/nodejs-darwin-arm64",
3
+ "version": "0.1.0",
4
+ "cpu": [
5
+ "arm64"
6
+ ],
7
+ "main": "gloxx-nodejs.darwin-arm64.node",
8
+ "files": [
9
+ "gloxx-nodejs.darwin-arm64.node"
10
+ ],
11
+ "description": "Native Rust bindings for the Gloxx Network wallet",
12
+ "license": "MIT",
13
+ "os": [
14
+ "darwin"
15
+ ]
16
+ }
@@ -0,0 +1,3 @@
1
+ # `@gloxx/nodejs-darwin-x64`
2
+
3
+ This is the **x86_64-apple-darwin** binary for `@gloxx/nodejs`
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "@gloxx/nodejs-darwin-x64",
3
+ "version": "0.1.0",
4
+ "cpu": [
5
+ "x64"
6
+ ],
7
+ "main": "gloxx-nodejs.darwin-x64.node",
8
+ "files": [
9
+ "gloxx-nodejs.darwin-x64.node"
10
+ ],
11
+ "description": "Native Rust bindings for the Gloxx Network wallet",
12
+ "license": "MIT",
13
+ "os": [
14
+ "darwin"
15
+ ]
16
+ }
@@ -0,0 +1,3 @@
1
+ # `@gloxx/nodejs-linux-x64-gnu`
2
+
3
+ This is the **x86_64-unknown-linux-gnu** binary for `@gloxx/nodejs`
@@ -0,0 +1,19 @@
1
+ {
2
+ "name": "@gloxx/nodejs-linux-x64-gnu",
3
+ "version": "0.1.0",
4
+ "cpu": [
5
+ "x64"
6
+ ],
7
+ "main": "gloxx-nodejs.linux-x64-gnu.node",
8
+ "files": [
9
+ "gloxx-nodejs.linux-x64-gnu.node"
10
+ ],
11
+ "description": "Native Rust bindings for the Gloxx Network wallet",
12
+ "license": "MIT",
13
+ "os": [
14
+ "linux"
15
+ ],
16
+ "libc": [
17
+ "glibc"
18
+ ]
19
+ }
@@ -0,0 +1,3 @@
1
+ # `@gloxx/nodejs-win32-x64-msvc`
2
+
3
+ This is the **x86_64-pc-windows-msvc** binary for `@gloxx/nodejs`
@@ -0,0 +1,16 @@
1
+ {
2
+ "name": "@gloxx/nodejs-win32-x64-msvc",
3
+ "version": "0.1.0",
4
+ "cpu": [
5
+ "x64"
6
+ ],
7
+ "main": "gloxx-nodejs.win32-x64-msvc.node",
8
+ "files": [
9
+ "gloxx-nodejs.win32-x64-msvc.node"
10
+ ],
11
+ "description": "Native Rust bindings for the Gloxx Network wallet",
12
+ "license": "MIT",
13
+ "os": [
14
+ "win32"
15
+ ]
16
+ }
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@gloxx/nodejs",
3
+ "version": "0.1.0",
4
+ "description": "Native Rust bindings for the Gloxx Network wallet",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "files": [
8
+ "index.js",
9
+ "*.d.ts",
10
+ "npm/**",
11
+ "README.md"
12
+ ],
13
+ "napi": {
14
+ "binaryName": "gloxx-nodejs",
15
+ "package": {
16
+ "name": "@gloxx/nodejs"
17
+ },
18
+ "targets": [
19
+ "aarch64-apple-darwin",
20
+ "x86_64-apple-darwin",
21
+ "x86_64-pc-windows-msvc",
22
+ "x86_64-unknown-linux-gnu",
23
+ "aarch64-linux-android",
24
+ "armv7-linux-androideabi"
25
+ ]
26
+
27
+ },
28
+
29
+ "license": "MIT",
30
+ "devDependencies": {
31
+ "@napi-rs/cli": "^2.18.0"
32
+ },
33
+ "optionalDependencies": {
34
+ "@gloxx/nodejs-android-arm64": "0.1.0",
35
+ "@gloxx/nodejs-android-arm-eabi": "0.1.0",
36
+ "@gloxx/nodejs-win32-x64-msvc": "0.1.0",
37
+ "@gloxx/nodejs-darwin-universal": "0.1.0",
38
+ "@gloxx/nodejs-linux-x64-gnu": "0.1.0",
39
+ "@gloxx/nodejs-linux-x64-musl": "0.1.0",
40
+ "@gloxx/nodejs-linux-arm64-gnu": "0.1.0",
41
+ "@gloxx/nodejs-linux-arm64-musl": "0.1.0"
42
+ }
43
+ }