webycash-sdk 0.1.1
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/dist/index.d.ts +21 -0
- package/dist/index.js +150 -0
- package/libwebycash_sdk.dylib +0 -0
- package/libwebycash_sdk.so +0 -0
- package/package.json +22 -0
- package/webycash_sdk.dll +0 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare class WebycashError extends Error {
|
|
2
|
+
code: number;
|
|
3
|
+
constructor(code: number, message: string);
|
|
4
|
+
}
|
|
5
|
+
export declare function version(): string;
|
|
6
|
+
export declare function amountParse(s: string): bigint;
|
|
7
|
+
export declare function amountFormat(wats: bigint): string;
|
|
8
|
+
export declare class Wallet {
|
|
9
|
+
private ptr;
|
|
10
|
+
constructor(dbPath: string, seed?: Buffer);
|
|
11
|
+
close(): void;
|
|
12
|
+
balance(): string;
|
|
13
|
+
insert(webcash: string): void;
|
|
14
|
+
pay(amount: string, memo?: string): string;
|
|
15
|
+
check(): void;
|
|
16
|
+
merge(maxOutputs?: number): string;
|
|
17
|
+
recover(masterSecretHex: string, gapLimit?: number): string;
|
|
18
|
+
stats(): string;
|
|
19
|
+
exportSnapshot(): string;
|
|
20
|
+
encryptSeed(password: string): void;
|
|
21
|
+
}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,150 @@
|
|
|
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.Wallet = exports.WebycashError = void 0;
|
|
7
|
+
exports.version = version;
|
|
8
|
+
exports.amountParse = amountParse;
|
|
9
|
+
exports.amountFormat = amountFormat;
|
|
10
|
+
const koffi_1 = __importDefault(require("koffi"));
|
|
11
|
+
const path_1 = __importDefault(require("path"));
|
|
12
|
+
const os_1 = __importDefault(require("os"));
|
|
13
|
+
const LIB_NAME = {
|
|
14
|
+
linux: "libwebycash_sdk.so",
|
|
15
|
+
darwin: "libwebycash_sdk.dylib",
|
|
16
|
+
win32: "webycash_sdk.dll",
|
|
17
|
+
};
|
|
18
|
+
function findLib() {
|
|
19
|
+
const name = LIB_NAME[os_1.default.platform()];
|
|
20
|
+
if (!name)
|
|
21
|
+
throw new Error(`Unsupported platform: ${os_1.default.platform()}`);
|
|
22
|
+
// Check next to this module first
|
|
23
|
+
const local = path_1.default.join(__dirname, "..", name);
|
|
24
|
+
try {
|
|
25
|
+
require("fs").accessSync(local);
|
|
26
|
+
return local;
|
|
27
|
+
}
|
|
28
|
+
catch { }
|
|
29
|
+
return name; // Fall back to system search
|
|
30
|
+
}
|
|
31
|
+
const lib = koffi_1.default.load(findLib());
|
|
32
|
+
// ── FFI declarations ────────────────────────────────────────────
|
|
33
|
+
const WebyWalletPtr = koffi_1.default.pointer("WebyWallet", koffi_1.default.opaque());
|
|
34
|
+
const WebyWalletPtrPtr = koffi_1.default.pointer(WebyWalletPtr);
|
|
35
|
+
const CharPtrPtr = koffi_1.default.pointer("char*", koffi_1.default.pointer(koffi_1.default.types.char));
|
|
36
|
+
const ffi = {
|
|
37
|
+
weby_wallet_open: lib.func("int32_t weby_wallet_open(const char*, _Out_ WebyWallet**)"),
|
|
38
|
+
weby_wallet_open_with_seed: lib.func("int32_t weby_wallet_open_with_seed(const char*, const uint8_t*, size_t, _Out_ WebyWallet**)"),
|
|
39
|
+
weby_wallet_free: lib.func("void weby_wallet_free(WebyWallet*)"),
|
|
40
|
+
weby_wallet_balance: lib.func("int32_t weby_wallet_balance(const WebyWallet*, _Out_ char**)"),
|
|
41
|
+
weby_wallet_insert: lib.func("int32_t weby_wallet_insert(const WebyWallet*, const char*)"),
|
|
42
|
+
weby_wallet_pay: lib.func("int32_t weby_wallet_pay(const WebyWallet*, const char*, const char*, _Out_ char**)"),
|
|
43
|
+
weby_wallet_check: lib.func("int32_t weby_wallet_check(const WebyWallet*)"),
|
|
44
|
+
weby_wallet_merge: lib.func("int32_t weby_wallet_merge(const WebyWallet*, uint32_t, _Out_ char**)"),
|
|
45
|
+
weby_wallet_recover: lib.func("int32_t weby_wallet_recover(const WebyWallet*, const char*, uint32_t, _Out_ char**)"),
|
|
46
|
+
weby_wallet_stats: lib.func("int32_t weby_wallet_stats(const WebyWallet*, _Out_ char**)"),
|
|
47
|
+
weby_wallet_export_snapshot: lib.func("int32_t weby_wallet_export_snapshot(const WebyWallet*, _Out_ char**)"),
|
|
48
|
+
weby_wallet_encrypt_seed: lib.func("int32_t weby_wallet_encrypt_seed(const WebyWallet*, const char*)"),
|
|
49
|
+
weby_version: lib.func("const char* weby_version()"),
|
|
50
|
+
weby_last_error_message: lib.func("const char* weby_last_error_message()"),
|
|
51
|
+
weby_amount_parse: lib.func("int32_t weby_amount_parse(const char*, _Out_ int64_t*)"),
|
|
52
|
+
weby_amount_format: lib.func("int32_t weby_amount_format(int64_t, _Out_ char**)"),
|
|
53
|
+
weby_free_string: lib.func("void weby_free_string(char*)"),
|
|
54
|
+
};
|
|
55
|
+
// ── Helpers ─────────────────────────────────────────────────────
|
|
56
|
+
class WebycashError extends Error {
|
|
57
|
+
constructor(code, message) {
|
|
58
|
+
super(message);
|
|
59
|
+
this.code = code;
|
|
60
|
+
this.name = "WebycashError";
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.WebycashError = WebycashError;
|
|
64
|
+
function check(rc) {
|
|
65
|
+
if (rc !== 0) {
|
|
66
|
+
const msg = ffi.weby_last_error_message();
|
|
67
|
+
throw new WebycashError(rc, msg ?? `Error code ${rc}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
function takeString(ptr) {
|
|
71
|
+
if (!ptr)
|
|
72
|
+
return "";
|
|
73
|
+
const s = koffi_1.default.decode(ptr, "char*");
|
|
74
|
+
ffi.weby_free_string(ptr);
|
|
75
|
+
return s;
|
|
76
|
+
}
|
|
77
|
+
// ── Public API ──────────────────────────────────────────────────
|
|
78
|
+
function version() {
|
|
79
|
+
return ffi.weby_version();
|
|
80
|
+
}
|
|
81
|
+
function amountParse(s) {
|
|
82
|
+
const out = [BigInt(0)];
|
|
83
|
+
check(ffi.weby_amount_parse(s, out));
|
|
84
|
+
return out[0];
|
|
85
|
+
}
|
|
86
|
+
function amountFormat(wats) {
|
|
87
|
+
const out = [null];
|
|
88
|
+
check(ffi.weby_amount_format(wats, out));
|
|
89
|
+
return takeString(out[0]);
|
|
90
|
+
}
|
|
91
|
+
class Wallet {
|
|
92
|
+
constructor(dbPath, seed) {
|
|
93
|
+
const out = [null];
|
|
94
|
+
if (seed) {
|
|
95
|
+
if (seed.length !== 32)
|
|
96
|
+
throw new Error("seed must be 32 bytes");
|
|
97
|
+
check(ffi.weby_wallet_open_with_seed(dbPath, seed, seed.length, out));
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
check(ffi.weby_wallet_open(dbPath, out));
|
|
101
|
+
}
|
|
102
|
+
this.ptr = out[0];
|
|
103
|
+
}
|
|
104
|
+
close() {
|
|
105
|
+
if (this.ptr) {
|
|
106
|
+
ffi.weby_wallet_free(this.ptr);
|
|
107
|
+
this.ptr = null;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
balance() {
|
|
111
|
+
const out = [null];
|
|
112
|
+
check(ffi.weby_wallet_balance(this.ptr, out));
|
|
113
|
+
return takeString(out[0]);
|
|
114
|
+
}
|
|
115
|
+
insert(webcash) {
|
|
116
|
+
check(ffi.weby_wallet_insert(this.ptr, webcash));
|
|
117
|
+
}
|
|
118
|
+
pay(amount, memo = "") {
|
|
119
|
+
const out = [null];
|
|
120
|
+
check(ffi.weby_wallet_pay(this.ptr, amount, memo, out));
|
|
121
|
+
return takeString(out[0]);
|
|
122
|
+
}
|
|
123
|
+
check() {
|
|
124
|
+
check(ffi.weby_wallet_check(this.ptr));
|
|
125
|
+
}
|
|
126
|
+
merge(maxOutputs = 20) {
|
|
127
|
+
const out = [null];
|
|
128
|
+
check(ffi.weby_wallet_merge(this.ptr, maxOutputs, out));
|
|
129
|
+
return takeString(out[0]);
|
|
130
|
+
}
|
|
131
|
+
recover(masterSecretHex, gapLimit = 20) {
|
|
132
|
+
const out = [null];
|
|
133
|
+
check(ffi.weby_wallet_recover(this.ptr, masterSecretHex, gapLimit, out));
|
|
134
|
+
return takeString(out[0]);
|
|
135
|
+
}
|
|
136
|
+
stats() {
|
|
137
|
+
const out = [null];
|
|
138
|
+
check(ffi.weby_wallet_stats(this.ptr, out));
|
|
139
|
+
return takeString(out[0]);
|
|
140
|
+
}
|
|
141
|
+
exportSnapshot() {
|
|
142
|
+
const out = [null];
|
|
143
|
+
check(ffi.weby_wallet_export_snapshot(this.ptr, out));
|
|
144
|
+
return takeString(out[0]);
|
|
145
|
+
}
|
|
146
|
+
encryptSeed(password) {
|
|
147
|
+
check(ffi.weby_wallet_encrypt_seed(this.ptr, password));
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
exports.Wallet = Wallet;
|
|
Binary file
|
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "webycash-sdk",
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Webcash cross-platform SDK — Node.js/TypeScript bindings",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"repository": "https://github.com/webycash/webycash-sdk",
|
|
9
|
+
"keywords": ["webcash", "wallet", "sdk", "payments"],
|
|
10
|
+
"files": ["dist", "*.so", "*.dylib", "*.dll"],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "tsc",
|
|
13
|
+
"prepublishOnly": "npm run build"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"koffi": "^2.9.0"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@types/node": "^20",
|
|
20
|
+
"typescript": "^5.4"
|
|
21
|
+
}
|
|
22
|
+
}
|
package/webycash_sdk.dll
ADDED
|
Binary file
|